mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Compare commits
48 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
fde724aa2d | ||
|
e411a3e6bf | ||
|
7db81649b0 | ||
|
08fe6f13f4 | ||
|
e11d159c81 | ||
|
dfd66be871 | ||
|
27f977b545 | ||
|
2ca6e789ca | ||
|
ff8f921ebc | ||
|
005b78227a | ||
|
b7a42a9d3d | ||
|
3d1e938cb6 | ||
|
8b98a7c1f6 | ||
|
dbf5acf5e8 | ||
|
5fe5ab1c4b | ||
|
e0cd9bb3db | ||
|
f0f6171354 | ||
|
94861cc6d2 | ||
|
286233e28f | ||
|
99ac7836aa | ||
|
6c0c8e0ef6 | ||
|
8aa5f140bf | ||
|
2fcb9a5995 | ||
|
8b018b697d | ||
|
0e269ecd67 | ||
|
a640bc4656 | ||
|
62a95499ef | ||
|
9e92d4a35a | ||
|
459c07b121 | ||
|
ada15fdabc | ||
|
d5de36841a | ||
|
cf419fb329 | ||
|
abf39b34b6 | ||
|
552252371f | ||
|
7570010a04 | ||
|
a9ee753dc6 | ||
|
ca5a81122a | ||
|
554cd97145 | ||
|
806606f284 | ||
|
7c0ebc5887 | ||
|
45665f94a7 | ||
|
cd736fdbd4 | ||
|
f753884008 | ||
|
1d9a4941ce | ||
|
5bde797ba4 | ||
|
ecba35fc26 | ||
|
a4f8f367c3 | ||
|
41b11ab785 |
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master ]
|
||||
schedule:
|
||||
- cron: '41 1 * * 6'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'cpp' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||
# Learn more:
|
||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -94,6 +94,7 @@ sample_rand
|
||||
tags
|
||||
terminal.h
|
||||
ver_calc
|
||||
win32/
|
||||
|
||||
# other commonly excluded patterns
|
||||
#
|
||||
|
340
CHANGES
340
CHANGES
@@ -1,4 +1,256 @@
|
||||
The following are the changes from calc version 2.13.0.1 to date:
|
||||
The following are the changes from calc version 2.14.0.9 to date:
|
||||
|
||||
Due to issues with clang and Apple Silicon, ARCH_CFLAGS is now,
|
||||
by default, empty:
|
||||
|
||||
ARCH_CFLAGS=
|
||||
|
||||
If you want to use, say, -march=native, then either change
|
||||
the Makefile or make with:
|
||||
|
||||
make all ARCH_CFLAGS='-march=native'
|
||||
|
||||
Added arch and hardware as GNU Makefile computed values.
|
||||
As with ${target}, ${arch} and ${hardware} is computed by uname:
|
||||
|
||||
target: uname -a
|
||||
arch: uname -p
|
||||
hardware: uname -m
|
||||
|
||||
Fixed compiling calc on Apple Silicon with homebrew. On Apple
|
||||
Silicon, HomeBrew installs on into a different location. The
|
||||
Makefile checks if ${hardware} is arm64 and adjusts the location
|
||||
of libraries such as readline and history accordingly.
|
||||
|
||||
|
||||
The following are the changes from calc version 2.14.0.7 to 2.14.0.8:
|
||||
|
||||
Fizzbin is a better word. :-)
|
||||
|
||||
The help and man builtin commands now return an error when a
|
||||
help file cannot be opened, such as when there is no help file.
|
||||
|
||||
Added palindrome.cal resource file. For example, to find the
|
||||
largest (highly probable) prime palindrome under 280 decimal
|
||||
digits (text tweet limit):
|
||||
|
||||
prevprimepal(1e280)
|
||||
|
||||
|
||||
The following are the changes from calc version 2.14.0.0 to 2.14.0.6:
|
||||
|
||||
The :-separated default CALCRC value has been reversed.
|
||||
The default CALCRC was:
|
||||
|
||||
${CALC_SHAREDIR}/startup:~/.calcrc:./.calcinit
|
||||
|
||||
The default CALCRC is now:
|
||||
|
||||
./.calcinit:~/.calcrc:${CALC_SHAREDIR}/startup
|
||||
|
||||
See "help environment" for details.
|
||||
|
||||
Added engineering mode as per a GitHub pull request from
|
||||
<GitHub user heitzmann>. Thank you! For example:
|
||||
|
||||
; config("mode","eng"),
|
||||
; 10^41
|
||||
100e39
|
||||
|
||||
or for example:
|
||||
|
||||
; base(1000),
|
||||
; 2^23209-1
|
||||
~402.87411577898877818187e6984
|
||||
|
||||
For more information see:
|
||||
|
||||
help base
|
||||
|
||||
Added regression test code for engineering mode. Improved and
|
||||
expanded regression test code related to the base() and base2()
|
||||
builtin functions.
|
||||
|
||||
Fixed a critical bug in the above mentioned pull request where
|
||||
a call to base2(1000) would make calc unstable and likely to
|
||||
dump core.
|
||||
|
||||
Added builtin functions to convert between degrees, radians
|
||||
and gradians:
|
||||
|
||||
d2r(deg) - given degrees returns radians
|
||||
g2r(grad) - given gradians returns radians
|
||||
|
||||
r2d(rad) - given radians returns degrees
|
||||
g2d(grad) - given gradians returns degrees
|
||||
|
||||
r2g(rad) - given radians returns gradians
|
||||
d2g(deg) - given degrees returns gradians
|
||||
|
||||
Add 6 functions take a 2nd optional epsilon argument.
|
||||
For d2r(deg, ep), r2d(rad, ep), the optional 2nd epsilon argument controls
|
||||
the precision of the internal constant pi/180.
|
||||
For g2r(grad, ep), r2g(rad, ep), the optional 2nd epsilon argument controls
|
||||
the precision of the internal constant pi/200.
|
||||
The optional 2nd argument is ignored by g2d(grad, ep) and d2g(deg, ep).
|
||||
|
||||
The clean and clobber makefile rules no longer list custom/Makefile
|
||||
as a dependecy.
|
||||
|
||||
Unfortunately due to the complex dependency issues between
|
||||
Makefile, Makefile.ship and custom/Makefile, parallel GNU make
|
||||
is NOT recommended. Sorry (tm Canada) :)
|
||||
|
||||
The clean and clobber makefile rules no longer list custom/Makefile
|
||||
as a dependency.
|
||||
|
||||
Unfortunately due to the complex dependency issues between
|
||||
Makefile, Makefile.ship and custom/Makefile, parallel GNU make
|
||||
is NOT recommended. Sorry (tm Canada) :)
|
||||
|
||||
Fixed a few typos in CHANGES.
|
||||
|
||||
As a side note: We stayed v2.13.x was kept for only a short time.
|
||||
The move to 2.14.x was motivated by non-compatible changes due to
|
||||
the default order of CALCRC, plus some new builtin functions.
|
||||
|
||||
More changes are likely, so we might see another v2.14.0.x release
|
||||
before things are declared "recommended stable".
|
||||
|
||||
Not that we want to discourage people from trying v2.14.0, you should
|
||||
try it. We just want things to become stable and well field tested
|
||||
before we reach the "recommended stable" release state.
|
||||
|
||||
Added builtin functions to convert between degrees and
|
||||
degrees, minutes and seconds under the config("mod")
|
||||
round rules:
|
||||
|
||||
d2dms(degs, d, m, s [,rnd]) - given degs, compute d, m, s
|
||||
d2dm(degs, d, m [,rnd]) - given degs, compute d, m
|
||||
|
||||
See help/d2dms and help/d2dm.
|
||||
|
||||
Example:
|
||||
|
||||
; print d2dms(360.321,deg=,min=,sec=), deg, min, sec;
|
||||
0.321 0 19 15.6
|
||||
|
||||
; print d2dm(360.321,deg=,min=), deg, min;
|
||||
0.321 0 19.26
|
||||
|
||||
Added builtin functions to convert between gradians and
|
||||
gradians, minutes and seconds under the config("mod")
|
||||
round rules:
|
||||
|
||||
g2gms(grads, g, m, s [,rnd]) - given grads, compute g, m, s
|
||||
g2gm(grads, g, m [,rnd]) - given grads, compute g, m
|
||||
|
||||
See help/g2gms and help/g2gm.
|
||||
|
||||
Example:
|
||||
|
||||
; print g2gms(400.321,grad=,min=,sec=), grad, min, sec;
|
||||
0.321 0 19 15.6
|
||||
|
||||
; print g2gm(400.321,grad=,min=), grad, min;
|
||||
0.321 0 19.26
|
||||
|
||||
Added builtin functions to convert between hours and
|
||||
hours, minutes and seconds under the config("mod")
|
||||
round rules:
|
||||
|
||||
h2hms(hours, h, m, s [,rnd]) - given hours, compute h, m, s
|
||||
h2hm(hours, h, m [,rnd]) - given hours, compute h, m
|
||||
|
||||
See help/h2hms and help/h2hm.
|
||||
|
||||
Example:
|
||||
|
||||
; print h2hms(24.321,hour=,min=,sec=), hour, min, sec;
|
||||
0.321 0 19 15.6
|
||||
|
||||
; print h2hm(24.321,hour=,min=), hour, min;
|
||||
0.321 0 19.26
|
||||
|
||||
Renumbered regression tests 3408 thru 3437, to 9102 thru 9131.
|
||||
|
||||
Updated Added hms.cal resource file to use h2hms() builtin.
|
||||
Updated Added dms.cal resource file to use d2dms() builtin.
|
||||
|
||||
Fix minor typo in help/mod SYNOPSIS.
|
||||
Fix minor typo in help/quo SYNOPSIS.
|
||||
|
||||
Added a few more examples to help/strcmp.
|
||||
|
||||
Added builtin functions to convert between degrees, minutes and
|
||||
seconds and degrees under the config("mod") round rules:
|
||||
|
||||
dms2d(d, m, s [,rnd]) - convert deg, min, and secs to deg
|
||||
dm2d(d, m [,rnd]) - convert deg, min to deg
|
||||
|
||||
See help/dms2d and help/dm2d.
|
||||
|
||||
Example:
|
||||
|
||||
; print dms2d(12, 20, 44.16);
|
||||
12.3456
|
||||
|
||||
; print dm2d(3601, -25.5594);
|
||||
0.57401
|
||||
|
||||
Added builtin functions to convert between gradians, minutes and
|
||||
seconds and gradians under the config("mod") round rules:
|
||||
|
||||
gms2g(g, m, s [,rnd]) - convert grad, min, and secs to grad
|
||||
gm2g(g, m [,rnd]) - convert grad and min to grad
|
||||
|
||||
See help/g2gms and help/g2gm.
|
||||
|
||||
Example:
|
||||
|
||||
; print gms2g(12, 20, 44.16);
|
||||
12.3456
|
||||
|
||||
; print gm2g(4001, -25.5594);
|
||||
0.57401
|
||||
|
||||
Added builtin functions to convert between hours, minutes and
|
||||
seconds and hours under the config("mod") round rules:
|
||||
|
||||
hms2h(h, m, s [,rnd]) - convert hours, min, and secs to hours
|
||||
hm2h(h, m [,rnd]) - convert hours, min to hours
|
||||
|
||||
See help/hms2h and help/hm2h.
|
||||
|
||||
Example:
|
||||
|
||||
; print hms2h(12, 20, 44.16);
|
||||
12.3456
|
||||
|
||||
; print hm2h(241, -25.5594);
|
||||
0.57401
|
||||
|
||||
Fixed typo in cal/statistics.cal thanks to a report by <GitHub user
|
||||
dennisaldea>.
|
||||
|
||||
Fixed an old Windoz pun in README.WINDOWS as requested by <GitHub
|
||||
user marcodegio>.
|
||||
|
||||
Fixed a really obscure bug in the internal initconstants()
|
||||
function of const.c that has been sitting for over 31 years!
|
||||
|
||||
We are amazed that nobody has encountered this bug before
|
||||
now. Nevertheless, our very extensive regression and
|
||||
multi-architecture testing found the bug. Now, after all
|
||||
those years, it is fixed.
|
||||
|
||||
Fixed issues identied by the default CodeUL GitHub security code scan:
|
||||
|
||||
Wrong type of arguments to printf in have_fpos_pos.c
|
||||
Multiplication result converted to larger type in zfunc.c
|
||||
|
||||
|
||||
The following are the changes from calc version 2.13.0.1 to 2.13.0.1:
|
||||
|
||||
Replaced /usr/local with the use of ${PREFIX} in calc Makefiles.
|
||||
|
||||
@@ -31,11 +283,11 @@ The following are the changes from calc version 2.13.0.1 to date:
|
||||
Updated HOWTO.INSTALL to mention Makefile.local.
|
||||
|
||||
|
||||
The following are the changes from calc version 2.13.0.0 to date:
|
||||
The following are the changes from calc version 2.13.0.0 to 2.13.0.0:
|
||||
|
||||
Fixed typo (missing quotes) in the env rule.
|
||||
|
||||
Fixed intendation problem in CHANGES.
|
||||
Fixed indentation problem in CHANGES.
|
||||
|
||||
Combined 2.12.9.1 changes into the 2.12.8.2 to 2.12.9.0
|
||||
range, and thus renamed the range to 2.12.8.2 to 2.12.9.1.
|
||||
@@ -71,7 +323,7 @@ The following are the changes from calc version 2.13.0.0 to date:
|
||||
#!/usr/local/bin/calc -f
|
||||
...
|
||||
|
||||
It is common that -q be usde with a calc script, so assuming the
|
||||
It is common that -q be used with a calc script, so assuming the
|
||||
same /usr/local/bin/calc path:
|
||||
|
||||
#!/usr/local/bin/calc -q -f
|
||||
@@ -615,7 +867,7 @@ The following are the changes from calc version 2.12.5.4 to 2.12.5.6:
|
||||
Rewrote gen_v1() in the lucas.cal resource file using the method
|
||||
based on a paper:
|
||||
|
||||
"A note on primality tests for N = h*2^n-1", by Oystein J. Rodseth,
|
||||
"A note on primality tests for N = h*2^n-1", by Oystein J. Rodseth,
|
||||
Department of Mathematics, University of Bergen, BIT Numerical
|
||||
Mathematics. 34 (3): pp 451-454.
|
||||
|
||||
@@ -674,13 +926,13 @@ The following are the changes from calc version 2.12.5.3 to 2.12.5.3:
|
||||
macOS (Darwin) users who installed calc version 2.12.5.2
|
||||
should, after installing version 2.12.5.3:
|
||||
|
||||
rm -rf /opt/calc
|
||||
rm -rf /opt/calc
|
||||
|
||||
|
||||
The following are the changes from calc version 2.12.5.1 to 2.12.5.2:
|
||||
|
||||
NOTE: calc version 2.12.5.2, for macOS (Darwin) users,
|
||||
installed under /opt/calc. We neglected to mention this
|
||||
installed under /opt/calc. We neglected to mention this
|
||||
AND /usr/local would have been a better choice. Sorry!
|
||||
Fixed in calc version 2.12.5.3.
|
||||
|
||||
@@ -753,7 +1005,7 @@ The following are the changes from calc version 2.12.4.14 to 2.12.5.0:
|
||||
|
||||
For Apple OS X / Darwin target:
|
||||
|
||||
MACOSX_DEPLOYMENT_TARGET is no longer defined
|
||||
MACOSX_DEPLOYMENT_TARGET is no longer defined
|
||||
using clang compiler
|
||||
|
||||
By default, -install-name is used when forming shared libs.
|
||||
@@ -797,9 +1049,9 @@ The following are the changes from calc version 2.12.4.14 to 2.12.5.0:
|
||||
for mul2, sq2, and pow2. However, it has been shown that this
|
||||
code is not correct. Suggestions for a replacement are welcome!
|
||||
|
||||
calc -u 'read alg_config; config("user_debug", 2),; best_mul2();'
|
||||
calc -u 'read alg_config; config("user_debug", 2),; best_sq2();'
|
||||
calc -u 'read alg_config; config("user_debug", 2),; best_pow2();'
|
||||
calc -u 'read alg_config; config("user_debug", 2),; best_mul2();'
|
||||
calc -u 'read alg_config; config("user_debug", 2),; best_sq2();'
|
||||
calc -u 'read alg_config; config("user_debug", 2),; best_pow2();'
|
||||
|
||||
Fixed a number of pedantic compiler warnings.
|
||||
|
||||
@@ -966,7 +1218,7 @@ The following are the changes from calc version 2.12.4.6 to version 2.12.4.10:
|
||||
With the exception of 3 source files, we became "picky" about
|
||||
line lengths and other issues reported by the picky tool:
|
||||
|
||||
cal/test8900.cal
|
||||
cal/test8900.cal
|
||||
cal/set8700.line
|
||||
help/errorcodes.sed
|
||||
|
||||
@@ -1022,7 +1274,7 @@ The following are the changes from calc version 2.12.4.0 to 2.12.4.2:
|
||||
Added prep makefile rule to make is easier to compile calc without
|
||||
an optimizer. By doing:
|
||||
|
||||
make clobber prep
|
||||
make clobber prep
|
||||
|
||||
one may build a calc binary that is easier to debug.
|
||||
|
||||
@@ -1179,7 +1431,7 @@ The following are the changes from calc version 2.12.1.1 to 2.12.2.2:
|
||||
what was calc-something.tar.gz is now calc-something.tar.bz2.
|
||||
To "uncompress" use:
|
||||
|
||||
bunzip2 calc-something.tar.bz2
|
||||
bunzip2 calc-something.tar.bz2
|
||||
|
||||
On some systems, one may untar directly by:
|
||||
|
||||
@@ -1244,7 +1496,7 @@ The following are the changes from calc version 2.12.1.10 to 2.12.2:
|
||||
Renamed the following variables related to calc error processing:
|
||||
|
||||
int calc_jmp ==> int calc_use_matherr_jmpbuf
|
||||
jmp_buf calc_jmp_buf ==> jmp_buf calc_matherr_jmpbuf
|
||||
jmp_buf calc_jmp_buf ==> jmp_buf calc_matherr_jmpbuf
|
||||
|
||||
int post_init ==> int calc_use_scanerr_jmpbuf
|
||||
jmp_buf jmpbuf ==> jmpbuf calc_scanerr_jmpbuf
|
||||
@@ -1259,7 +1511,7 @@ The following are the changes from calc version 2.12.1.10 to 2.12.2:
|
||||
Parse/scan errors will not be printed if calc_print_scanerr_msg
|
||||
is zero. By default:
|
||||
|
||||
int calc_print_scanerr_msg = 1;
|
||||
int calc_print_scanerr_msg = 1;
|
||||
|
||||
This variable is declared in the lib_calc.h include file. Storage
|
||||
comes from libcalc.
|
||||
@@ -1267,7 +1519,7 @@ The following are the changes from calc version 2.12.1.10 to 2.12.2:
|
||||
Parse/scan warnings will not be printed if calc_print_scanwarn_msg
|
||||
is zero. By default:
|
||||
|
||||
int calc_print_scanwarn_msg = 1;
|
||||
int calc_print_scanwarn_msg = 1;
|
||||
|
||||
This variable is declared in the lib_calc.h include file. Storage
|
||||
comes from libcalc.
|
||||
@@ -1303,13 +1555,13 @@ The following are the changes from calc version 2.12.1.10 to 2.12.2:
|
||||
Replaced the concept of compiler sets in the Makefile with
|
||||
host target section in the Makefile. Initial host targets are:
|
||||
|
||||
Linux
|
||||
Linux
|
||||
Darwin
|
||||
FreeBSD
|
||||
(default) <<== Target does not match any previous target name
|
||||
Simple
|
||||
|
||||
NOTE: If your target is not supported below and the default target
|
||||
NOTE: If your target is not supported below and the default target
|
||||
is not suitable for your needs, please send to the:
|
||||
|
||||
calc-contrib at asthe dot com
|
||||
@@ -1321,12 +1573,12 @@ The following are the changes from calc version 2.12.1.10 to 2.12.2:
|
||||
The custom/Makefile is now constructed from 3 parts: custom/Makefile.head,
|
||||
the host target section in Makefile, and the custom/Makefile.tail.
|
||||
|
||||
The top level Makefile and the custom/Makefile require a GNU Make
|
||||
The top level Makefile and the custom/Makefile require a GNU make
|
||||
(such as gmake) or an equivalently advanced make. On many targets,
|
||||
the default make is sufficient. On FreeBSD for example, one must
|
||||
use gmake instead of make.
|
||||
|
||||
If your target system does not have GNU Make (or equivalent), then
|
||||
If your target system does not have GNU make (or equivalent), then
|
||||
you should try using the Makefile.simple and custom/Makefile.simple
|
||||
files:
|
||||
|
||||
@@ -1457,7 +1709,7 @@ The following are the changes from calc version 2.12.1.8 to 2.12.1.9:
|
||||
comments. Improved calc comment documentation in "help unexpected"
|
||||
to help other avoid similar mistakes. Calc comments are of the form:
|
||||
|
||||
/* c style comments */
|
||||
/* c style comments */
|
||||
/*
|
||||
* multi-line
|
||||
* comments
|
||||
@@ -1471,7 +1723,7 @@ The following are the changes from calc version 2.12.1.8 to 2.12.1.9:
|
||||
|
||||
Documented these help commands in "help help":
|
||||
|
||||
help ->
|
||||
help ->
|
||||
help *
|
||||
help .
|
||||
help %
|
||||
@@ -1652,7 +1904,7 @@ The following are the changes from calc version 2.12.0 to 2.12.0.8:
|
||||
Added the builtin function fpathopen() to open a file while
|
||||
searching along a path:
|
||||
|
||||
; fd2 = fpathopen("tmp/date", "r", ".:~:~sc:/tmp:/var/tmp:/var")
|
||||
; fd2 = fpathopen("tmp/date", "r", ".:~:~sc:/tmp:/var/tmp:/var")
|
||||
; print fd2
|
||||
"/var/tmp/date"
|
||||
|
||||
@@ -1702,12 +1954,12 @@ The following are the changes from calc version 2.12.0 to 2.12.0.8:
|
||||
level. When comparing with older source, one may use the -b argument
|
||||
of the diff command to ignore changes in amount of white space:
|
||||
|
||||
diff -b -r -u calc-2.11.11 calc-2.12.0
|
||||
diff -b -r -u calc-2.11.11 calc-2.12.0
|
||||
|
||||
The read, write, and help commands use the value of global string
|
||||
variable if the symbol name starts with a $. For example:
|
||||
|
||||
global x = "lucas.cal";
|
||||
global x = "lucas.cal";
|
||||
read $x; /* same as read lucas.cal or read "lucas.cal" */
|
||||
|
||||
Added dotest.cal resource. Based on a design by Ernest Bowen
|
||||
@@ -1817,7 +2069,7 @@ The following are the changes from calc version 2.12.0 to 2.12.0.8:
|
||||
|
||||
Changed the default values for the following config() parameters:
|
||||
|
||||
config("mul2") == 1780
|
||||
config("mul2") == 1780
|
||||
config("sq2") == 3388
|
||||
config("pow2") == 176
|
||||
|
||||
@@ -1912,10 +2164,10 @@ The following are the changes from calc version 2.12.0 to 2.12.0.8:
|
||||
value is TRUE by default. Examples of variable name collisions
|
||||
include when:
|
||||
|
||||
* both local and static variables have the same name
|
||||
* both local and global variables have the same name
|
||||
* both function parameter and local variables have the same name
|
||||
* both function parameter and global variables have the same name
|
||||
* both local and static variables have the same name
|
||||
* both local and global variables have the same name
|
||||
* both function parameter and local variables have the same name
|
||||
* both function parameter and global variables have the same name
|
||||
|
||||
Fix of a bug which causes some static variables not to be correctly
|
||||
unscoped when their identifiers are used in a global declaration.
|
||||
@@ -1935,7 +2187,7 @@ The following are the changes from calc version 2.12.0 to 2.12.0.8:
|
||||
Changed the definition of the function ssq() to enable list arguments
|
||||
to be processed in the same way as in sum(). For example:
|
||||
|
||||
ssq(1,2, list(3,4,list(5,6)), list(), 7, 8)
|
||||
ssq(1,2, list(3,4,list(5,6)), list(), 7, 8)
|
||||
|
||||
returns the value of 1^2 + 2^2 + ... + 8^2 == 204.
|
||||
|
||||
@@ -1943,7 +2195,7 @@ The following are the changes from calc version 2.12.0 to 2.12.0.8:
|
||||
various ways of evaluating sums, sums of squares, etc, for large
|
||||
lists and matrices. For example:
|
||||
|
||||
read sumtimes
|
||||
read sumtimes
|
||||
doalltimes(1e6)
|
||||
|
||||
Calc now ignores carriage returns (\r), vertical tabs (\v), and
|
||||
@@ -1982,7 +2234,7 @@ The following are the changes from calc version 2.11.10.1 to 2.11.11:
|
||||
|
||||
Fixed a bug reported by the sourceforge user: cedars where:
|
||||
|
||||
ln(exp(6)) == 3 /* WRONG!!! */
|
||||
ln(exp(6)) == 3 /* WRONG!!! */
|
||||
|
||||
incorrectly returned 1. This bug was fixed by Ernest Bowen
|
||||
<ebowen at une dot edu dot au>. The regression test
|
||||
@@ -2087,7 +2339,7 @@ The following are the changes from calc version 2.11.10 to 2.11.10:
|
||||
|
||||
Fixed -d so that:
|
||||
|
||||
calc -d 2/3
|
||||
calc -d 2/3
|
||||
|
||||
will print 0.66666666666666666667 without the leading tilde as
|
||||
advertised in the man page.
|
||||
@@ -2107,7 +2359,7 @@ The following are the changes from calc version 2.11.10 to 2.11.10:
|
||||
|
||||
Added custom function:
|
||||
|
||||
custom("pmodm127", q)
|
||||
custom("pmodm127", q)
|
||||
|
||||
to compute 2^(2^127-1) mod q. While currently slower than just
|
||||
doing pmod(2,2^127-1,q), it is added to give an example of a
|
||||
@@ -2198,7 +2450,7 @@ The following are the changes from calc version 2.11.8.0 to 2.11.8.1:
|
||||
configuration (calc -n or config("all", "newstd")) is now the default
|
||||
calc configuration. The flag:
|
||||
|
||||
calc -O
|
||||
calc -O
|
||||
|
||||
was added to get the old classic calc configuration. The flag command
|
||||
line flag, -n, now does nothing. Use of -n is deprecated and may go
|
||||
@@ -2375,16 +2627,16 @@ The following are the changes from calc version 2.11.5.5 to 2.11.5.9:
|
||||
|
||||
Now using version numbers of one of these forms:
|
||||
|
||||
x.y.z.w
|
||||
x.y.z
|
||||
x.y
|
||||
x.y.z.w
|
||||
x.y.z
|
||||
x.y
|
||||
|
||||
Changed the READLINE_LIB Makefile variable to not link with -lreadline
|
||||
by default. If you do have readline, we recommend that you use it.
|
||||
If you can install the GNU readline:
|
||||
|
||||
http://freshmeat.net/projects/gnureadline/
|
||||
http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html
|
||||
http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html
|
||||
|
||||
we recommend it. But if not, you should set the USE_READLINE,
|
||||
READLINE_LIB, and READLINE_INCLUDE Makefile variables to empty.
|
||||
@@ -2456,7 +2708,7 @@ The following are the changes from calc version 2.11.5t4.1 to 2.11.5t4.4:
|
||||
Added subject requirements for the calc-tester-request and
|
||||
calc-bugs-mail Email aliases. See:
|
||||
|
||||
http://www.isthe.com/chongo/tech/comp/calc/email.html
|
||||
http://www.isthe.com/chongo/tech/comp/calc/email.html
|
||||
|
||||
for details.
|
||||
|
||||
@@ -2623,7 +2875,7 @@ The following are the changes from calc version 2.11.5t2 to 2.11.5t2.1:
|
||||
Applied a bug fix from Ernest Bowen <ernie at turing dot une dot
|
||||
edu dot au> dealing with one-line "static" declaration like:
|
||||
|
||||
static a = 1, b;
|
||||
static a = 1, b;
|
||||
|
||||
Added regression test 8310 to test for the static bug fix.
|
||||
|
||||
@@ -2736,7 +2988,7 @@ The following are the changes from calc version 2.11.5t0 to 2.11.5t1.1:
|
||||
Configuration values that used to return "true" or "false" now return
|
||||
1 (a true value) or 0 (a false value). Thus one can do:
|
||||
|
||||
if (config("tab")) { ... } else { ... }
|
||||
if (config("tab")) { ... } else { ... }
|
||||
|
||||
The configuration values that now return 1 or 0 are:
|
||||
|
||||
|
@@ -2,6 +2,14 @@
|
||||
IMPORTANT: Please see the section at the bottom of this file for
|
||||
some important information on Makefiles used in calc.
|
||||
|
||||
###################################################################
|
||||
# IMPORTANT: DO NOT run GNU make in parallel mode!!! #
|
||||
###################################################################
|
||||
# Unfortunately due to the complex dependency issues between #
|
||||
# Makefile, Makefile.ship and custom/Makefile, parallel GNU make #
|
||||
# is NOT recommended. Sorry (tm Canada) :) #
|
||||
###################################################################
|
||||
|
||||
Installing calc from the bzip2-ed tarball in 4 easy steps:
|
||||
|
||||
(0) If your platform supports i686 RPMs, you may want to go to:
|
||||
|
32
Makefile
32
Makefile
@@ -35,11 +35,23 @@
|
||||
# calculator by David I. Bell with help/mods from others
|
||||
# Makefile by Landon Curt Noll
|
||||
|
||||
# Unfortunately due to the complex dependency issues between
|
||||
# Makefile, Makefile.ship and custom/Makefile, parallel GNU make
|
||||
# is NOT recommended. Sorry.
|
||||
#
|
||||
.NOTPARALLEL:
|
||||
|
||||
# Try uname -s if the target was not already set on the make command line
|
||||
#
|
||||
ifeq ($(target),)
|
||||
target=$(shell uname -s 2>/dev/null)
|
||||
endif
|
||||
ifeq ($(arch),)
|
||||
arch=$(shell uname -p 2>/dev/null)
|
||||
endif
|
||||
ifeq ($(hardware),)
|
||||
hardware=$(shell uname -m 2>/dev/null)
|
||||
endif
|
||||
|
||||
# The shell used by this Makefile
|
||||
#
|
||||
@@ -129,15 +141,31 @@ USE_READLINE= -DUSE_READLINE
|
||||
#READLINE_LIB= -L/usr/gnu/lib -lreadline -lhistory -lncurses
|
||||
#READLINE_LIB= -L${PREFIX}/lib -lreadline -lhistory -lncurses
|
||||
ifeq ($(target),Darwin)
|
||||
# homebrew installs readline & history libs in ${PREFIX}/opt/readline/lib
|
||||
ifeq ($(hardware),arm64)
|
||||
# Darwin arm64 homebrew installs readline & history
|
||||
# libs in /opt/homebrew/opt/readline/lib
|
||||
READLINE_LIB= -L/opt/homebrew/opt/readline/lib -lreadline -lhistory -lncurses
|
||||
else
|
||||
# Assume Darwin non-arm64 is x86_64
|
||||
# Darwin x86_64 homebrew installs readline & history
|
||||
# libs in ${PREFIX}/opt/readline/lib
|
||||
READLINE_LIB= -L${PREFIX}/opt/readline/lib -lreadline -lhistory -lncurses
|
||||
endif
|
||||
else
|
||||
READLINE_LIB= -lreadline -lhistory -lncurses
|
||||
endif
|
||||
#
|
||||
ifeq ($(target),Darwin)
|
||||
# homebrew installs readline & history *.h under ${PREFIX}/opt/readline/include
|
||||
ifeq ($(hardware),arm64)
|
||||
# Darwin arm64 homebrew installs readline & history *.h
|
||||
# under /opt/homebrew/opt/readline/include
|
||||
READLINE_INCLUDE= -I${PREFIX}/opt/homebrew/opt/readline/include
|
||||
else
|
||||
# Assume Darwin non-arm64 is x86_64
|
||||
# Darwin x86_64 homebrew installs readline & history *.h
|
||||
# under ${PREFIX}/opt/readline/include
|
||||
READLINE_INCLUDE= -I${PREFIX}/opt/readline/include
|
||||
endif
|
||||
else
|
||||
READLINE_INCLUDE=
|
||||
endif
|
||||
|
@@ -59,6 +59,13 @@ SHELL= /bin/sh
|
||||
|
||||
|
||||
#if 0 /* start of skip for non-Gnu makefiles */
|
||||
|
||||
# Unfortunately due to the complex dependency issues between
|
||||
# Makefile, Makefile.ship and custom/Makefile, parallel GNU make
|
||||
# is NOT recommended. Sorry.
|
||||
#
|
||||
.NOTPARALLEL:
|
||||
|
||||
##############################################################################
|
||||
#-=-=-=-=-=-=-=-=- Identify the target machine, if possible -=-=-=-=-=-=-=-=-#
|
||||
##############################################################################
|
||||
@@ -72,6 +79,12 @@ SHELL= /bin/sh
|
||||
ifeq ($(target),)
|
||||
target=$(shell uname -s 2>/dev/null)
|
||||
endif
|
||||
ifeq ($(arch),)
|
||||
arch=$(shell uname -p 2>/dev/null)
|
||||
endif
|
||||
ifeq ($(hardware),)
|
||||
hardware=$(shell uname -m 2>/dev/null)
|
||||
endif
|
||||
#endif /* end of skip for non-Gnu makefiles */
|
||||
|
||||
##############################################################################
|
||||
@@ -1007,10 +1020,10 @@ endif
|
||||
# If the $CALCRC environment variable is not defined, then the following
|
||||
# path will be searched for calc resource files.
|
||||
#
|
||||
# Select CALCRC= ${CALC_SHAREDIR}/startup;~/.calcrc;./.calcinit for DJGPP.
|
||||
# Select CALCRC= ./.calcinit:~/.calcrc:${CALC_SHAREDIR}/startup for DJGPP.
|
||||
#
|
||||
CALCRC= ${CALC_SHAREDIR}/startup:~/.calcrc:./.calcinit
|
||||
#CALCRC= ${CALC_SHAREDIR}/startup;~/.calcrc;./.calcinit
|
||||
CALCRC= ./.calcinit:~/.calcrc:${CALC_SHAREDIR}/startup
|
||||
#CALCRC= ./.calcinit;~/.calcrc;${CALC_SHAREDIR}/startup
|
||||
|
||||
# Determine of the GNU-readline facility will be used instead of the
|
||||
# builtin calc binding method.
|
||||
@@ -1198,7 +1211,7 @@ EXT=
|
||||
|
||||
# The default calc versions
|
||||
#
|
||||
VERSION= 2.13.0.1
|
||||
VERSION= 2.14.0.9
|
||||
|
||||
# Names of shared libraries with versions
|
||||
#
|
||||
@@ -1273,8 +1286,8 @@ EXTRA_LDFLAGS=
|
||||
# The ARCH_CFLAGS are ${CC} when compiling C files. They follow
|
||||
# CCMISC and precede EXTRA_CFLAGS.
|
||||
#
|
||||
ARCH_CFLAGS= -march=native
|
||||
#ARCH_CFLAGS=
|
||||
ARCH_CFLAGS=
|
||||
#ARCH_CFLAGS= -march=native
|
||||
|
||||
# COMMON_CFLAGS are the common ${CC} flags used for all programs, both
|
||||
# intermediate and final calc and calc related programs
|
||||
@@ -1794,7 +1807,7 @@ CALCPATH= .;./cal;~/.cal;${T}${CALC_SHAREDIR};${T}${CUSTOMCALDIR}
|
||||
else
|
||||
CALCPATH= .;./cal;~/.cal;${T}${CALC_SHAREDIR}
|
||||
endif
|
||||
CALCRC= ${CALC_SHAREDIR}/startup;~/.calcrc;./.calcinit
|
||||
CALCRC= ./.calcinit;~/.calcrc;${CALC_SHAREDIR}/startup
|
||||
#
|
||||
BLD_TYPE= calc-static-only
|
||||
#
|
||||
@@ -4831,7 +4844,7 @@ tags: ${CALCSRC} ${LIBSRC} ${H_SRC} ${BUILD_H_SRC} ${MAKE_FILE}
|
||||
-${CTAGS} ${CALCSRC} ${LIBSRC} ${H_SRC} ${BUILD_H_SRC} 2>&1 | \
|
||||
${GREP} -v 'Duplicate entry|Second entry ignored'
|
||||
|
||||
clean: custom/Makefile
|
||||
clean:
|
||||
${V} echo '=-=-=-=-= ${MAKE_FILE} start of $@ rule =-=-=-=-='
|
||||
${RM} -f ${LIBOBJS}
|
||||
${RM} -f ${CALCOBJS}
|
||||
@@ -4852,6 +4865,7 @@ clean: custom/Makefile
|
||||
cd custom; ${MAKE} -f Makefile ${CUSTOM_PASSDOWN} clean
|
||||
${V} echo '=-=-=-=-= Back to the main Makefile for $@ rule =-=-=-=-='
|
||||
${V} echo '=-=-=-=-= Invoking $@ rule for cscript =-=-=-=-='
|
||||
${MAKE} custom/Makefile
|
||||
cd cscript; ${MAKE} -f Makefile ${CSCRIPT_PASSDOWN} clean
|
||||
${V} echo '=-=-=-=-= Back to the main Makefile for $@ rule =-=-=-=-='
|
||||
${Q} echo remove files that are obsolete
|
||||
@@ -4861,7 +4875,7 @@ clean: custom/Makefile
|
||||
${RM} -f win32dll.h have_malloc.h math_error.h string.h string.c
|
||||
${V} echo '=-=-=-=-= ${MAKE_FILE} end of $@ rule =-=-=-=-='
|
||||
|
||||
clobber: clean custom/Makefile
|
||||
clobber: clean
|
||||
${V} echo '=-=-=-=-= ${MAKE_FILE} start of $@ rule =-=-=-=-='
|
||||
${RM} -f ${SAMPLE_TARGETS}
|
||||
${RM} -f ${SAMPLE_STATIC_TARGETS}
|
||||
@@ -4898,6 +4912,7 @@ clobber: clean custom/Makefile
|
||||
${V} echo '=-=-=-=-= Back to the main Makefile for $@ rule =-=-=-=-='
|
||||
${V} echo '=-=-=-=-= Invoking $@ rule for custom =-=-=-=-='
|
||||
-${RM} -f custom/all; \
|
||||
${MAKE} custom/Makefile; \
|
||||
cd custom; ${MAKE} -f Makefile ${CUSTOM_PASSDOWN} $@
|
||||
${V} echo '=-=-=-=-= Back to the main Makefile for $@ rule =-=-=-=-='
|
||||
${V} echo '=-=-=-=-= Invoking $@ rule for cscript =-=-=-=-='
|
||||
|
@@ -1,4 +1,4 @@
|
||||
Dear calc user on a Windoz based system,
|
||||
Dear calc user on a Windows based system,
|
||||
|
||||
See the HOWTO.INSTALL file for information on how to build and install calc.
|
||||
See also the README file.
|
||||
@@ -126,7 +126,7 @@ recommends the following settings:
|
||||
CATDIR= /dev/env/DJDIR/man/cat1
|
||||
NROFF= groff
|
||||
CALCPATH= .;./cal;~/.cal;${CALC_SHAREDIR};${CUSTOMCALDIR}
|
||||
CALCRC= ${CALC_SHAREDIR}/startup;~/.calcrc;./.calcinit
|
||||
CALCRC= ./.calcinit;~/.calcrc;${CALC_SHAREDIR}/startup
|
||||
CALCPAGER= less.exe -ci
|
||||
DEBUG= -O2 -gstabs+ -DWINDOZ
|
||||
|
||||
|
21
SECURITY.md
Normal file
21
SECURITY.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Use this section to tell people about which versions of your project are
|
||||
currently being supported with security updates.
|
||||
|
||||
| Version | Supported |
|
||||
| ------- | ------------------ |
|
||||
| 5.1.x | :white_check_mark: |
|
||||
| 5.0.x | :x: |
|
||||
| 4.0.x | :white_check_mark: |
|
||||
| < 4.0 | :x: |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Use this section to tell people how to report a vulnerability.
|
||||
|
||||
Tell them where to go, how often they can expect to get an update on a
|
||||
reported vulnerability, what to expect if the vulnerability is accepted or
|
||||
declined, etc.
|
22
cal/Makefile
22
cal/Makefile
@@ -275,17 +275,17 @@ CALC_FILES= README alg_config.cal beer.cal bernoulli.cal \
|
||||
constants.cal deg.cal dms.cal dotest.cal ellip.cal factorial.cal \
|
||||
factorial2.cal gvec.cal hello.cal hms.cal infinities.cal intfile.cal \
|
||||
intnum.cal lambertw.cal linear.cal lnseries.cal lucas.cal \
|
||||
lucas_chk.cal mersenne.cal mfactor.cal mod.cal natnumset.cal pell.cal \
|
||||
pi.cal pix.cal pollard.cal poly.cal prompt.cal psqrt.cal qtime.cal \
|
||||
quat.cal randbitrun.cal randmprime.cal randombitrun.cal randomrun.cal \
|
||||
randrun.cal regress.cal repeat.cal screen.cal seedrandom.cal \
|
||||
set8700.cal set8700.line smallfactors.cal solve.cal \
|
||||
specialfunctions.cal statistics.cal strings.cal sumsq.cal sumtimes.cal \
|
||||
surd.cal test1700.cal test2300.cal test2600.cal test2700.cal \
|
||||
test3100.cal test3300.cal test3400.cal test3500.cal test4000.cal \
|
||||
test4100.cal test4600.cal test5100.cal test5200.cal test8400.cal \
|
||||
test8500.cal test8600.cal test8900.cal toomcook.cal unitfrac.cal \
|
||||
varargs.cal xx_print.cal zeta2.cal
|
||||
lucas_chk.cal mersenne.cal mfactor.cal mod.cal natnumset.cal \
|
||||
palindrome.cal pell.cal pi.cal pix.cal pollard.cal poly.cal prompt.cal \
|
||||
psqrt.cal qtime.cal quat.cal randbitrun.cal randmprime.cal \
|
||||
randombitrun.cal randomrun.cal randrun.cal regress.cal repeat.cal \
|
||||
screen.cal seedrandom.cal set8700.cal set8700.line smallfactors.cal \
|
||||
solve.cal specialfunctions.cal statistics.cal strings.cal sumsq.cal \
|
||||
sumtimes.cal surd.cal test1700.cal test2300.cal test2600.cal \
|
||||
test2700.cal test3100.cal test3300.cal test3400.cal test3500.cal \
|
||||
test4000.cal test4100.cal test4600.cal test5100.cal test5200.cal \
|
||||
test8400.cal test8500.cal test8600.cal test8900.cal toomcook.cal \
|
||||
unitfrac.cal varargs.cal xx_print.cal zeta2.cal
|
||||
|
||||
# These calc files are now obsolete and are removed by the install rule.
|
||||
#
|
||||
|
38
cal/README
38
cal/README
@@ -186,7 +186,7 @@ bernoulli.cal
|
||||
Calculate the nth Bernoulli number.
|
||||
|
||||
NOTE: There is now a bernoulli() builtin function. This file is
|
||||
left here for backward compatibility and now simply returns
|
||||
left here for backward compatibility and now simply returns
|
||||
the builtin function.
|
||||
|
||||
|
||||
@@ -767,7 +767,7 @@ lucas.cal
|
||||
prove that h*2^n-1 is prime or not prime.
|
||||
|
||||
NOTE: Some call this term u(0). The function gen_u0(h, n, v1)
|
||||
simply calls gen_u2(h, n, v1) for such people. :-)
|
||||
simply calls gen_u2(h, n, v1) for such people. :-)
|
||||
|
||||
gen_v1(h, v)
|
||||
|
||||
@@ -879,6 +879,38 @@ natnumset.cal
|
||||
user-specified bound.
|
||||
|
||||
|
||||
palindrome.cal
|
||||
|
||||
digitof(val,place)
|
||||
copalplace(d,place)
|
||||
upperhalf(val)
|
||||
mkpal(val)
|
||||
mkpalmiddigit(val,digit)
|
||||
ispal(val)
|
||||
nextpal(val)
|
||||
prevpal(val)
|
||||
nextprimepal(val)
|
||||
prevprimepal(val)
|
||||
|
||||
Functions to form and manipulate palendromes in base 10.
|
||||
|
||||
Important functions are:
|
||||
|
||||
Find the next / previous palindrome:
|
||||
|
||||
nextpal(val)
|
||||
prevpal(val)
|
||||
|
||||
Test if a value is a palindrome:
|
||||
|
||||
ispal(val)
|
||||
|
||||
Find the next / previous palindrome that is a (highly probable) prime:
|
||||
|
||||
nextprimepal(val)
|
||||
prevprimepal(val)
|
||||
|
||||
|
||||
pell.cal
|
||||
|
||||
pellx(D)
|
||||
@@ -1435,7 +1467,7 @@ sumtimes.cal
|
||||
the list or matrix to use. The doalltimes() function will run
|
||||
all of the sumtimes tests. For example:
|
||||
|
||||
doalltimes(1e6);
|
||||
doalltimes(1e6);
|
||||
|
||||
|
||||
surd.cal
|
||||
|
@@ -474,7 +474,7 @@ define best_mul2()
|
||||
*/
|
||||
while (low+1 < high) {
|
||||
|
||||
/* try the mid-point */
|
||||
/* try the mid-point */
|
||||
mid = int((low+high)/2);
|
||||
if (config("user_debug") > 0) {
|
||||
printf("testing multiply alg1/alg2 ratio for len = %d\n", mid);
|
||||
@@ -956,7 +956,7 @@ define best_sq2()
|
||||
*/
|
||||
while (low+1 < high) {
|
||||
|
||||
/* try the mid-point */
|
||||
/* try the mid-point */
|
||||
mid = int((low+high)/2);
|
||||
if (config("user_debug") > 0) {
|
||||
printf("testing square alg1/alg2 ratio for len = %d\n", mid);
|
||||
@@ -1455,7 +1455,7 @@ define best_pow2()
|
||||
*/
|
||||
while (low+1 < high) {
|
||||
|
||||
/* try the mid-point */
|
||||
/* try the mid-point */
|
||||
mid = int((low+high)/2);
|
||||
if (config("user_debug") > 0) {
|
||||
printf("testing pow2 alg1/alg2 ratio for len = %d\n", mid);
|
||||
|
@@ -40,7 +40,7 @@ define Z(x, eps_term)
|
||||
|
||||
/* obtain the error term */
|
||||
if (isnull(eps_term)) {
|
||||
eps = epsilon();
|
||||
eps = epsilon();
|
||||
} else {
|
||||
eps = eps_term;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ define P(x, eps_term)
|
||||
|
||||
/* obtain the error term */
|
||||
if (isnull(eps_term)) {
|
||||
eps = epsilon();
|
||||
eps = epsilon();
|
||||
} else {
|
||||
eps = eps_term;
|
||||
}
|
||||
|
22
cal/dms.cal
22
cal/dms.cal
@@ -188,7 +188,7 @@ define dms_abs(a)
|
||||
|
||||
/* firewall - just absolute value non dms objects */
|
||||
if (! istype(a, ans)) {
|
||||
return abs(a);
|
||||
return abs(a);
|
||||
}
|
||||
|
||||
/* compute degrees */
|
||||
@@ -352,24 +352,8 @@ define fixdms(a)
|
||||
quit "attempt to fix a non dms object";
|
||||
}
|
||||
|
||||
/* force minutes to be integral */
|
||||
a.min += frac(a.deg) * 60;
|
||||
a.deg = int(a.deg);
|
||||
|
||||
/* force degrees to be integral */
|
||||
a.sec += frac(a.min) * 60;
|
||||
a.min = int(a.min);
|
||||
|
||||
/* carry excess seconds into minutes */
|
||||
a.min += a.sec // 60;
|
||||
a.sec %= 60;
|
||||
|
||||
/* carry excess minutes into degrees */
|
||||
a.deg += a.min // 60;
|
||||
a.min %= 60;
|
||||
|
||||
/* round degrees :-) */
|
||||
a.deg %= 360;
|
||||
/* use builtin d2dms function */
|
||||
d2dms(a.deg + a.min/60 + a.sec/3600, a.deg, a.min, a.sec),;
|
||||
|
||||
/* return normalized result */
|
||||
return a;
|
||||
|
@@ -157,7 +157,7 @@ define dotest(dotest_file, dotest_code = 0, dotest_maxcond = -1)
|
||||
* test the close of the line file
|
||||
*/
|
||||
printf("%d-: detected %d error condition(s), many of which may be OK\n",
|
||||
dotest_code, dotest_old_errcount-dotest_errcnt);
|
||||
dotest_code, dotest_old_errcount-dotest_errcnt);
|
||||
printf("%d-: closing line file: %d\n", dotest_code, dotest_file);
|
||||
fclose(dotest_f_file);
|
||||
|
||||
|
@@ -56,7 +56,7 @@ define __CZ__factor_factorial(n,start){
|
||||
if(start){
|
||||
if(!isint(start) && start < 0 && start > n)
|
||||
return newerror("__CZ__factor_factorial(n,start): value of "
|
||||
"parameter 'start' out of range");
|
||||
"parameter 'start' out of range");
|
||||
if(start == n && isprime(n)){
|
||||
prime_list = mat[1 , 2];
|
||||
prime_list[0,0] = n;
|
||||
@@ -64,7 +64,7 @@ define __CZ__factor_factorial(n,start){
|
||||
}
|
||||
else if(!isprime(start) && nextprime(start) >n)
|
||||
return newerror("__CZ__factor_factorial(n,start): value of parameter "
|
||||
"'start' out of range");
|
||||
"'start' out of range");
|
||||
else{
|
||||
if(!isprime(start)) prime = nextprime(start);
|
||||
else prime = start;
|
||||
@@ -225,11 +225,11 @@ define __CZ__multiply_factored_factorial(matrix,stop){
|
||||
|
||||
if(!ismat(matrix))
|
||||
return newerror("__CZ__multiply_factored_factorial(matrix): "
|
||||
"argument matrix not a matrix ");
|
||||
"argument matrix not a matrix ");
|
||||
if(!matrix[0,0])
|
||||
return
|
||||
newerror("__CZ__multiply_factored_factorial(matrix): "
|
||||
"matrix[0,0] is null/0");
|
||||
"matrix[0,0] is null/0");
|
||||
|
||||
if(!isnull(stop))
|
||||
pix = stop;
|
||||
@@ -376,7 +376,7 @@ define bigcatalan(n){
|
||||
|
||||
/*
|
||||
df(-111) = -1/3472059605858239446587523014902616804783337112829102414124928
|
||||
7753332469144201839599609375
|
||||
7753332469144201839599609375
|
||||
|
||||
df(-3+1i) = 0.12532538977287649201-0.0502372106177184607i
|
||||
df(2n + 1) = (2*n)!/(n!*2^n)
|
||||
@@ -427,7 +427,7 @@ define doublefactorial(n){
|
||||
*/
|
||||
eps=epsilon(epsilon()*1e-2);
|
||||
ret = 2^(n/2-1/4 * cos(pi()* n)+1/4) * pi()^(1/4 *
|
||||
cos(pi()* n)-1/4)* gamma(n/2+1);
|
||||
cos(pi()* n)-1/4)* gamma(n/2+1);
|
||||
epsilon(eps);
|
||||
return ret;
|
||||
}
|
||||
|
22
cal/hms.cal
22
cal/hms.cal
@@ -188,7 +188,7 @@ define hms_abs(a)
|
||||
|
||||
/* firewall - just absolute value non hms objects */
|
||||
if (! istype(a, ans)) {
|
||||
return abs(a);
|
||||
return abs(a);
|
||||
}
|
||||
|
||||
/* compute hours */
|
||||
@@ -352,24 +352,8 @@ define fixhms(a)
|
||||
quit "attempt to fix a non hms object";
|
||||
}
|
||||
|
||||
/* force minutes to be integral */
|
||||
a.min += frac(a.hour) * 60;
|
||||
a.hour = int(a.hour);
|
||||
|
||||
/* force hours to be integral */
|
||||
a.sec += frac(a.min) * 60;
|
||||
a.min = int(a.min);
|
||||
|
||||
/* carry excess seconds into minutes */
|
||||
a.min += a.sec // 60;
|
||||
a.sec %= 60;
|
||||
|
||||
/* carry excess minutes into hours */
|
||||
a.hour += a.min // 60;
|
||||
a.min %= 60;
|
||||
|
||||
/* round hours by day */
|
||||
a.hour %= 24;
|
||||
/* use builtin h2hms function */
|
||||
h2hms(a.hour + a.min/60 + a.sec/3600, a.hour, a.min, a.sec),;
|
||||
|
||||
/* return normalized result */
|
||||
return a;
|
||||
|
@@ -156,7 +156,7 @@ define be2file(v, filename)
|
||||
*/
|
||||
octlen = int((highbit(v)+8) / 8);
|
||||
for (i=octlen-1; i >= 0; --i) {
|
||||
fputc(fd, char(v >> (i*8)));
|
||||
fputc(fd, char(v >> (i*8)));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -731,7 +731,7 @@ rodseth_xhn(x, h, n)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Check for jacobi(x-2, h*2^n-1) == 1 (Ref4, condition 1) part 1
|
||||
*/
|
||||
testval = h*2^n-1;
|
||||
@@ -739,7 +739,7 @@ rodseth_xhn(x, h, n)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Check for jacobi(x+2, h*2^n-1) == -1 (Ref4, condition 1) part 2
|
||||
*/
|
||||
if (jacobi(x+2, testval) != -1) {
|
||||
|
641
cal/palindrome.cal
Normal file
641
cal/palindrome.cal
Normal file
@@ -0,0 +1,641 @@
|
||||
/*
|
||||
* palindrome - palindrome utilities
|
||||
*
|
||||
* Copyright (C) 2021 Landon Curt Noll
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
* Public License for more details.
|
||||
*
|
||||
* A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
* distributed with calc under the filename COPYING-LGPL. You should have
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Under source code control: 2021/11/06 14:35:37
|
||||
* File existed as early as: 2021
|
||||
*
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* digitof - return the a digit of a value
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val value to find a digit of
|
||||
* place digit place
|
||||
*
|
||||
* returns:
|
||||
* value (>= 0 and < 10) that is the place-th digit of val
|
||||
* or 0 if place is not a digit of val
|
||||
*/
|
||||
define digitof(val, place)
|
||||
{
|
||||
local d; /* length of val in digits */
|
||||
|
||||
/* determine length */
|
||||
d = digits(val);
|
||||
|
||||
/* firewall - return 0 if digit place doesn't exist */
|
||||
if (place < 1 || place > d) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return the place-th digit of val as a single digit */
|
||||
return (val // (10^(place-1))) % 10;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* copalplace - determine the other place in a palindrome
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* d digits of a value
|
||||
* place digit place
|
||||
*
|
||||
* returns:
|
||||
* given palindrome val, the other digit paired with place
|
||||
* or 0 if place is not a digit of val
|
||||
*/
|
||||
define copalplace(d, place)
|
||||
{
|
||||
/* firewall - return 0 if digit place doesn't exist */
|
||||
if (d < 1 || place < 1 || place > d) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return digit coplace */
|
||||
return d+1 - place;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* upperhalf - return the upper half of a palindrome
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* NOTE: When the value has an odd number of digits, the upper half
|
||||
* includes the middle digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
*
|
||||
* returns:
|
||||
* the upper half digits of a value
|
||||
*/
|
||||
define upperhalf(val)
|
||||
{
|
||||
local d; /* length of val in digits */
|
||||
local halfd; /* length of upper hand of val */
|
||||
|
||||
/* determine length */
|
||||
d = digits(val);
|
||||
halfd = d // 2;
|
||||
|
||||
/* return upper half */
|
||||
return (val // 10^halfd);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* mkpal - make a value into a palindrome
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
*
|
||||
* returns:
|
||||
* val as a palindrome with lower half being reverse digits of val
|
||||
*/
|
||||
define mkpal(val)
|
||||
{
|
||||
local d; /* length of val in digits */
|
||||
local i; /* counter */
|
||||
local ret; /* palindrome being formed */
|
||||
|
||||
/* determine length */
|
||||
d = digits(val);
|
||||
|
||||
/* insert digits in reverse order at the bottom */
|
||||
ret = val;
|
||||
for (i=0; i < d; ++i) {
|
||||
ret = ret*10 + digit(val, i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* mkpalmiddigit - make a value into a palindrome with a middle digit
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
* digit the digit to put into the middle of the palindrome
|
||||
*
|
||||
* returns:
|
||||
* val as a palindrome with lower half being reverse digits of val
|
||||
* and digit as a middle digit
|
||||
*/
|
||||
define mkpalmiddigit(val, digit)
|
||||
{
|
||||
local d; /* length of val in digits */
|
||||
local i; /* counter */
|
||||
local ret; /* palindrome being formed */
|
||||
|
||||
/* determine length */
|
||||
d = digits(val);
|
||||
|
||||
/* insert digits in reverse order at the bottom */
|
||||
ret = val*10 + digit;
|
||||
for (i=0; i < d; ++i) {
|
||||
ret = ret*10 + digit(val, i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ispal - determine if a value is a palindrome
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
*
|
||||
* returns:
|
||||
* 1 ==> val is a palindrome
|
||||
* 0 ==> val is NOT a palindrome
|
||||
*/
|
||||
define ispal(val)
|
||||
{
|
||||
local half; /* upper half of digits of val */
|
||||
local digit; /* middle digit */
|
||||
|
||||
/* case: val has an even number of digits */
|
||||
if (iseven(digits(val))) {
|
||||
|
||||
/* test palindrome-ness */
|
||||
return (val == mkpal(upperhalf(val)));
|
||||
|
||||
/* case: val can an odd number of digits */
|
||||
} else {
|
||||
|
||||
/* test palindrome-ness */
|
||||
half = upperhalf(val);
|
||||
digit = half % 10;
|
||||
half //= 10;
|
||||
return (val == mkpalmiddigit(half, digit));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* palnextpal - return next palindrome from a known palindrome
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* pal a palindrome
|
||||
*
|
||||
* returns:
|
||||
* next palindrome > pal
|
||||
*/
|
||||
define palnextpal(pal)
|
||||
{
|
||||
local paldigits; /* digits in pal */
|
||||
local half; /* upper half of newval */
|
||||
local newhalf; /* half+1 */
|
||||
local newpal; /* new palindrome */
|
||||
|
||||
/* case: negative palindrome */
|
||||
if (pal < 0) {
|
||||
return -(palprevpal(-pal));
|
||||
}
|
||||
|
||||
/*
|
||||
* start with upper half
|
||||
*/
|
||||
half = upperhalf(pal);
|
||||
|
||||
/*
|
||||
* prep to find a larger palindrome
|
||||
*/
|
||||
newhalf = half+1;
|
||||
|
||||
/*
|
||||
* form palindrome from new upper half
|
||||
*
|
||||
* We need to watch for the corner case where changing the
|
||||
* half changes the number of digits as this will impact
|
||||
* or even/odd number of digits processing.
|
||||
*/
|
||||
paldigits = digits(pal);
|
||||
if (digits(newhalf) == digits(half)) {
|
||||
/* no change in half digits: process as normal */
|
||||
if (iseven(paldigits)) {
|
||||
newpal = mkpal(newhalf);
|
||||
} else {
|
||||
newpal = mkpalmiddigit(newhalf // 10, newhalf % 10);
|
||||
}
|
||||
} else {
|
||||
/* change in half digits: process as opposite */
|
||||
if (iseven(paldigits)) {
|
||||
newpal = mkpalmiddigit(newhalf // 10, newhalf % 10);
|
||||
} else {
|
||||
newpal = mkpal(newhalf);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* return the new palindrome
|
||||
*/
|
||||
return newpal;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nextpal - return next palindrome from a value
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
*
|
||||
* returns:
|
||||
* next palindrome > val
|
||||
*/
|
||||
define nextpal(val)
|
||||
{
|
||||
local newval; /* val+1 */
|
||||
local newvaldigits; /* digits in newval */
|
||||
local half; /* upper half of newval */
|
||||
local pal; /* palindrome test value */
|
||||
local newpal; /* new palindrome */
|
||||
|
||||
/* case: negative value */
|
||||
if (val < 0) {
|
||||
return -(prevpal(-val));
|
||||
}
|
||||
|
||||
/*
|
||||
* start looking from a larger value
|
||||
*/
|
||||
newval = val+1;
|
||||
newvaldigits = digits(newval);
|
||||
|
||||
/* case: single digit palindrome */
|
||||
if (newvaldigits < 2) {
|
||||
return newval;
|
||||
}
|
||||
|
||||
/*
|
||||
* start with next upper half
|
||||
*/
|
||||
half = upperhalf(newval);
|
||||
|
||||
/*
|
||||
* form palindrome from upper half
|
||||
*
|
||||
* We need to deal with even vs. odd digit counts
|
||||
* when forming a palindrome from a half as the
|
||||
* half may not or may include the middle digit.
|
||||
*/
|
||||
if (iseven(newvaldigits)) {
|
||||
pal = mkpal(half);
|
||||
} else {
|
||||
pal = mkpalmiddigit(half // 10, half % 10);
|
||||
}
|
||||
|
||||
/*
|
||||
* case: we found a larger palindrome, we are done
|
||||
*/
|
||||
if (pal > val) {
|
||||
return pal;
|
||||
}
|
||||
|
||||
/*
|
||||
* we need to find an even larger palindrome
|
||||
*/
|
||||
newpal = palnextpal(pal);
|
||||
|
||||
/*
|
||||
* return the new palindrome
|
||||
*/
|
||||
return newpal;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* palprevpal - return previous palindrome from a palindrome
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* pal a palindrome
|
||||
*
|
||||
* returns:
|
||||
* previous palindrome < pal
|
||||
*/
|
||||
define palprevpal(pal)
|
||||
{
|
||||
local paldigits; /* digits in pal */
|
||||
local half; /* upper half of newval */
|
||||
local newhalf; /* half+1 */
|
||||
local newpal; /* new palindrome */
|
||||
|
||||
/* case: negative value */
|
||||
if (pal < 0) {
|
||||
return -(palnextpal(-pal));
|
||||
}
|
||||
|
||||
/* case: single digit palindrome */
|
||||
if (pal < 10) {
|
||||
newpal = pal-1;
|
||||
return newpal;
|
||||
}
|
||||
|
||||
/* case: 10 or 11 */
|
||||
if (pal < 12) {
|
||||
newpal = 9;
|
||||
return newpal;
|
||||
}
|
||||
|
||||
/*
|
||||
* start with upper half
|
||||
*/
|
||||
half = upperhalf(pal);
|
||||
|
||||
/*
|
||||
* prep to find a smaller palindrome
|
||||
*/
|
||||
newhalf = half-1;
|
||||
|
||||
/*
|
||||
* form palindrome from new upper half
|
||||
*
|
||||
* We need to watch for the corner case where changing the
|
||||
* half changes the number of digits as this will impact
|
||||
* or even/odd number of digits processing.
|
||||
*/
|
||||
paldigits = digits(pal);
|
||||
if (digits(newhalf) == digits(half)) {
|
||||
/* no change in half digits: process as normal */
|
||||
if (iseven(paldigits)) {
|
||||
newpal = mkpal(newhalf);
|
||||
} else {
|
||||
newpal = mkpalmiddigit(newhalf // 10, newhalf % 10);
|
||||
}
|
||||
} else {
|
||||
/* change in half digits: process as opposite */
|
||||
if (iseven(paldigits)) {
|
||||
newpal = mkpalmiddigit(newhalf // 10, newhalf % 10);
|
||||
} else {
|
||||
newpal = mkpal(newhalf);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* return the new palindrome
|
||||
*/
|
||||
return newpal;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* prevpal - return previous palindrome from a value
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
*
|
||||
* returns:
|
||||
* previous palindrome < val
|
||||
*/
|
||||
define prevpal(val)
|
||||
{
|
||||
local newval; /* val-1 */
|
||||
local newvaldigits; /* digits in newval */
|
||||
local half; /* upper half of newval */
|
||||
local pal; /* palindrome test value */
|
||||
local newpal; /* new palindrome */
|
||||
|
||||
/* case: negative value */
|
||||
if (val < 0) {
|
||||
return -(nextpal(-val));
|
||||
}
|
||||
|
||||
/*
|
||||
* start looking from a smaller value
|
||||
*/
|
||||
newval = val-1;
|
||||
newvaldigits = digits(newval);
|
||||
|
||||
/* case: single digit palindrome */
|
||||
if (newvaldigits < 2) {
|
||||
return newval;
|
||||
}
|
||||
|
||||
/*
|
||||
* start with previous upper half
|
||||
*/
|
||||
half = upperhalf(newval);
|
||||
|
||||
/*
|
||||
* form palindrome from upper half
|
||||
*
|
||||
* We need to deal with even vs. odd digit counts
|
||||
* when forming a palindrome from a half as the
|
||||
* half may not or may include the middle digit.
|
||||
*/
|
||||
if (iseven(newvaldigits)) {
|
||||
pal = mkpal(half);
|
||||
} else {
|
||||
pal = mkpalmiddigit(half // 10, half % 10);
|
||||
}
|
||||
|
||||
/*
|
||||
* case: we found a smaller palindrome, we are done
|
||||
*/
|
||||
if (pal < val) {
|
||||
return pal;
|
||||
}
|
||||
|
||||
/*
|
||||
* we need to find an even smaller palindrome
|
||||
*/
|
||||
newpal = palprevpal(pal);
|
||||
|
||||
/*
|
||||
* return the new palindrome
|
||||
*/
|
||||
return newpal;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nextprimepal - return next palindrome that is a (highly probable) prime
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
*
|
||||
* returns:
|
||||
* next palindrome (highly probable) prime > val
|
||||
*/
|
||||
define nextprimepal(val)
|
||||
{
|
||||
local pal; /* palindrome test value */
|
||||
local dpal; /* digits in pal */
|
||||
|
||||
/*
|
||||
* pre-start under the next palindrome
|
||||
*/
|
||||
pal = nextpal(val-1);
|
||||
|
||||
/*
|
||||
* loop until we find a (highly probable) prime or 0
|
||||
*/
|
||||
do {
|
||||
|
||||
/* case: negative values and tiny values */
|
||||
if (pal < 2) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*
|
||||
* compute the next palindrome
|
||||
*/
|
||||
pal = palnextpal(pal);
|
||||
dpal = digits(pal);
|
||||
|
||||
/* case: 11 is the only prime palindrome with even digit count */
|
||||
if (pal == 11) {
|
||||
return 11;
|
||||
}
|
||||
|
||||
/* case: even number of digits and not 11 */
|
||||
if (iseven(dpal)) {
|
||||
|
||||
/*
|
||||
* Except for 11 (which is handled above already), there are
|
||||
* no prime palindrome with even digits. So we need to
|
||||
* increase the digit count and work with that larger palindrome.
|
||||
*/
|
||||
pal = nextpal(10^dpal);
|
||||
}
|
||||
|
||||
/* case: palindrome is even or ends in 5 */
|
||||
if (iseven(pal % 10) || (pal%10 == 10/2)) {
|
||||
|
||||
/*
|
||||
* we need to increase the bottom and top digits
|
||||
* so that we have a chance to be prime
|
||||
*/
|
||||
pal += (1 + 10^(dpal-1));
|
||||
}
|
||||
if (config("resource_debug") & 0x8) {
|
||||
print "DEBUG: nextprimepal:", pal;
|
||||
}
|
||||
} while (ptest(pal) == 0 && pal > 0);
|
||||
|
||||
/* return palindrome that his (highly probable) prime or 0 */
|
||||
return pal;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* prevprimepal - return prev palindrome that is a (highly probable) prime
|
||||
*
|
||||
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||
*
|
||||
* given:
|
||||
* val a value
|
||||
*
|
||||
* returns:
|
||||
* prev palindrome (highly probable) prime < val or 0
|
||||
*/
|
||||
define prevprimepal(val)
|
||||
{
|
||||
local pal; /* palindrome test value */
|
||||
local dpal; /* digits in pal */
|
||||
|
||||
/*
|
||||
* pre-start over the previous palindrome
|
||||
*/
|
||||
pal = prevpal(val+1);
|
||||
|
||||
/*
|
||||
* loop until we find a (highly probable) prime or 0
|
||||
*/
|
||||
do {
|
||||
|
||||
/*
|
||||
* case: single digit values are always palindromes
|
||||
*/
|
||||
if (val < 10) {
|
||||
/*
|
||||
* The prevcand() call will return 0 if there is no previous prime
|
||||
* such as the case when val < 2.
|
||||
*/
|
||||
return prevcand(pal);
|
||||
}
|
||||
|
||||
/*
|
||||
* compute the previous palindrome
|
||||
*/
|
||||
pal = palprevpal(pal);
|
||||
dpal = digits(pal);
|
||||
|
||||
/* case: 11 is the only prime palindrome with even digit count */
|
||||
if (pal == 11) {
|
||||
return 11;
|
||||
}
|
||||
|
||||
/* case: 2 digit palindrome and not 11 */
|
||||
if (dpal == 2) {
|
||||
return 7;
|
||||
}
|
||||
|
||||
/* case: even number of digits */
|
||||
if (iseven(dpal)) {
|
||||
|
||||
/*
|
||||
* Except for 11 (which is handled above already), there are
|
||||
* no prime palindrome with even digits. So we need to
|
||||
* decrease the digit count and work with that smaller palindrome.
|
||||
*/
|
||||
pal = prevpal(10^(dpal-1));
|
||||
}
|
||||
|
||||
/* case: palindrome is even or ends in 5 */
|
||||
if (iseven(pal % 10) || (pal%10 == 10/2)) {
|
||||
|
||||
/*
|
||||
* we need to decrease the bottom and top digits
|
||||
* so that we have a chance to be prime
|
||||
*/
|
||||
pal -= (1 + 10^(dpal-1));
|
||||
}
|
||||
if (config("resource_debug") & 0x8) {
|
||||
print "DEBUG: prevprimepal:", pal;
|
||||
}
|
||||
} while (ptest(pal) == 0 && pal > 0);
|
||||
|
||||
/* return palindrome that his (highly probable) prime or 0 */
|
||||
return pal;
|
||||
}
|
739
cal/regress.cal
739
cal/regress.cal
@@ -775,7 +775,9 @@ print '016: parsed test_bignums()';
|
||||
/*
|
||||
* Test many of the built-in functions.
|
||||
*
|
||||
* See test_functionss() starting at test 9000 for more built-in function tests.
|
||||
* See test_functions() (test 700 - 1238) for other built-in function tests.
|
||||
* See test_functions2() (test 9000 - 9063) for other built-in function tests.
|
||||
* See test_functions3() (test 9100 - 9214) for other built-in function tests.
|
||||
*/
|
||||
define test_functions()
|
||||
{
|
||||
@@ -1881,96 +1883,298 @@ define test_mode()
|
||||
vrfy(tmp == "octal", '1620: tmp == "octal"');
|
||||
vrfy(base() == 2, '1621: base() == 2');
|
||||
|
||||
tmp = config("mode", "real");
|
||||
print '1622: tmp = config("mode", "real")';
|
||||
tmp = config("mode", "eng");
|
||||
print '1622: tmp = config("mode", "eng")';
|
||||
vrfy(tmp == "binary", '1623: tmp == "binary"');
|
||||
vrfy(base() == 1000, '1624: base() == 1000');
|
||||
|
||||
tmp = config("mode", "real");
|
||||
print '1625: tmp = config("mode", "real")';
|
||||
vrfy(tmp == "engineering", '1626: tmp == "engineering"');
|
||||
|
||||
tmp = base(1/3);
|
||||
print '1624: tmp = base(1/3)';
|
||||
print '1627: tmp = base(1/3)';
|
||||
vrfy(config("mode") == "fraction",
|
||||
'1625: config("mode") == "fraction"');
|
||||
'1628: config("mode") == "fraction"');
|
||||
|
||||
tmp = base(-10);
|
||||
print '1626: tmp = base(-10)';
|
||||
print '1629: tmp = base(-10)';
|
||||
vrfy(config("mode") == "integer",
|
||||
'1627: config("mode") == "integer"');
|
||||
'1630: config("mode") == "integer"');
|
||||
|
||||
tmp = base(10);
|
||||
print '1628: tmp = base(10)';
|
||||
vrfy(config("mode") == "real", '1629: config("mode") == "real"');
|
||||
print '1631: tmp = base(10)';
|
||||
vrfy(config("mode") == "real", '1632: config("mode") == "real"');
|
||||
|
||||
tmp = base(1e20);
|
||||
print '1630: tmp = base(1e20)';
|
||||
print '1633: tmp = base(1e20)';
|
||||
vrfy(config("mode") == "scientific",
|
||||
'1631: config("mode") == "scientific"');
|
||||
'1634: config("mode") == "scientific"');
|
||||
|
||||
tmp = base(16);
|
||||
print '1632: tmp = base(16)';
|
||||
print '1635: tmp = base(16)';
|
||||
vrfy(config("mode") == "hexadecimal", \
|
||||
'1633: config("mode") == "hexadecimal"');
|
||||
'1636: config("mode") == "hexadecimal"');
|
||||
|
||||
tmp = base(8);
|
||||
print '1634: tmp = base(8)';
|
||||
vrfy(config("mode") == "octal", '1635: config("mode") == "octal"');
|
||||
print '1637: tmp = base(8)';
|
||||
vrfy(config("mode") == "octal", '1638: config("mode") == "octal"');
|
||||
|
||||
tmp = base(2);
|
||||
print '1636: tmp = base(2)';
|
||||
vrfy(config("mode") == "binary",'1637: config("mode") == "binary"');
|
||||
print '1639: tmp = base(2)';
|
||||
vrfy(config("mode") == "binary",'1640: config("mode") == "binary"');
|
||||
|
||||
tmp = base(1000);
|
||||
print '1641: tmp = base(1000)';
|
||||
vrfy(config("mode") == "engineering",
|
||||
'1642: config("mode") == "engineering"');
|
||||
|
||||
tmp = base(1/3);
|
||||
print '1643: tmp = base(1/3)';
|
||||
vrfy(str(0x80000000) == "2147483648", \
|
||||
'1644: str(0x8000000) == \"2147483648\"');
|
||||
vrfy(str(0xffffffff) == "4294967295", \
|
||||
'1645: str(0xffffffff) == \"4294967295\"');
|
||||
vrfy(str(3e9) == "3000000000", \
|
||||
'1646: str(3e9) == \"3000000000\"');
|
||||
vrfy(str(1/3) == "1/3", \
|
||||
'1647: str(1/3) == \"1/3\"');
|
||||
vrfy(str(2e8) == "200000000", \
|
||||
'1648: str(2e8) == \"200000000"');
|
||||
vrfy(str(200e6) == "200000000", \
|
||||
'1649: str(200e6) == \"200000000"');
|
||||
vrfy(str(0b100111) == "39", \
|
||||
'1650: str(0b100111) == \"39"');
|
||||
vrfy(str(07543) == "3939", \
|
||||
'1651: str(07543) == \"3939"');
|
||||
vrfy(str(7543) == "7543", \
|
||||
'1652: str(7543) == \"7543"');
|
||||
|
||||
tmp = base(8);
|
||||
print '1638: tmp = base(8)';
|
||||
print '1653: tmp = base(8)';
|
||||
vrfy(str(0x80000000) == "020000000000", \
|
||||
'1639: str(0x8000000) == \"020000000000\"');
|
||||
'1654: str(0x8000000) == \"020000000000\"');
|
||||
vrfy(str(0xffffffff) == "037777777777", \
|
||||
'1640: str(0xffffffff) == \"037777777777\"');
|
||||
'1655: str(0xffffffff) == \"037777777777\"');
|
||||
vrfy(str(3e9) == "026264057000", \
|
||||
'1641: str(3e9) == \"026264057000\"');
|
||||
'1656: str(3e9) == \"026264057000\"');
|
||||
vrfy(str(1/3) == "1/3", \
|
||||
'1657: str(1/3) == \"1/3\"');
|
||||
vrfy(str(2e8) == "01372741000", \
|
||||
'1658: str(2e8) == \"01372741000"');
|
||||
vrfy(str(200e6) == "01372741000", \
|
||||
'1659: str(200e6) == \"01372741000"');
|
||||
vrfy(str(0b100111) == "047", \
|
||||
'1660: str(0b100111) == \"047"');
|
||||
vrfy(str(07543) == "07543", \
|
||||
'1661: str(07543) == \"07543"');
|
||||
vrfy(str(7543) == "016567", \
|
||||
'1662: str(7543) == \"016567"');
|
||||
|
||||
tmp = base(16);
|
||||
print '1642: tmp = base(16)';
|
||||
print '1663: tmp = base(16)';
|
||||
vrfy(str(0x80000000) == "0x80000000", \
|
||||
'1643: str(0x8000000) == \"0x80000000\"');
|
||||
'1664: str(0x8000000) == \"0x80000000\"');
|
||||
vrfy(str(0xffffffff) == "0xffffffff", \
|
||||
'1644: str(0xffffffff) == \"0xffffffff\"');
|
||||
'1665: str(0xffffffff) == \"0xffffffff\"');
|
||||
vrfy(str(3e9) == "0xb2d05e00", \
|
||||
'1645: str(3e9) == \"0xb2d05e00\"');
|
||||
'1666: str(3e9) == \"0xb2d05e00\"');
|
||||
vrfy(str(1/3) == "1/3", \
|
||||
'1667: str(1/3) == \"1/3\"');
|
||||
vrfy(str(2e8) == "0xbebc200", \
|
||||
'1668: str(2e8) == \"0xbebc200"');
|
||||
vrfy(str(200e6) == "0xbebc200", \
|
||||
'1669: str(200e6) == \"0xbebc200"');
|
||||
vrfy(str(0b100111) == "0x27", \
|
||||
'1670: str(0b100111) == \"0x27"');
|
||||
vrfy(str(07543) == "0xf63", \
|
||||
'1671: str(07543) == \"0xf63"');
|
||||
vrfy(str(7543) == "0x1d77", \
|
||||
'1672: str(7543) == \"0x1d77"');
|
||||
|
||||
tmp = base(2);
|
||||
print '1673: tmp = base(2)';
|
||||
vrfy(str(0x80000000) == "0b10000000000000000000000000000000", \
|
||||
'1674: str(0x8000000) == \"0b10000000000000000000000000000000\"');
|
||||
vrfy(str(0xffffffff) == "0b11111111111111111111111111111111", \
|
||||
'1675: str(0xffffffff) == \"0b11111111111111111111111111111111\"');
|
||||
vrfy(str(3e9) == "0b10110010110100000101111000000000", \
|
||||
'1676: str(3e9) == \"0b10110010110100000101111000000000\"');
|
||||
vrfy(str(1/3) == "1/0b11", \
|
||||
'1677: str(1/3) == \"1/0b11\"');
|
||||
vrfy(str(2e8) == "0b1011111010111100001000000000", \
|
||||
'1678: str(2e8) == \"0b1011111010111100001000000000"');
|
||||
vrfy(str(200e6) == "0b1011111010111100001000000000", \
|
||||
'1679: str(200e6) == \"0b1011111010111100001000000000"');
|
||||
vrfy(str(0b100111) == "0b100111", \
|
||||
'1680: str(0b100111) == \"0b100111"');
|
||||
vrfy(str(07543) == "0b111101100011", \
|
||||
'1681: str(07543) == \"0b111101100011"');
|
||||
vrfy(str(7543) == "0b1110101110111", \
|
||||
'1682: str(7543) == \"0b1110101110111"');
|
||||
|
||||
tmp = base(1e20);
|
||||
print '1683: tmp = base(1e20)';
|
||||
vrfy(str(0x80000000) == "2.147483648e9", \
|
||||
'1684: str(0x8000000) == \"2.147483648e9\"');
|
||||
vrfy(str(0xffffffff) == "4.294967295e9", \
|
||||
'1685: str(0xffffffff) == \"4.294967295e9\"');
|
||||
vrfy(str(3e9) == "3e9", \
|
||||
'1686: str(3e9) == \"3e9\"');
|
||||
vrfy(str(1/3) == "~3.33333333333333333333e-1", \
|
||||
'1687: str(1/3) == \"~3.33333333333333333333e-1\"');
|
||||
vrfy(str(2e8) == "2e8", \
|
||||
'1688: str(2e8) == \"2e8"');
|
||||
vrfy(str(200e6) == "2e8", \
|
||||
'1689: str(200e6) == \"2e8"');
|
||||
vrfy(str(0b100111) == "3.9e1", \
|
||||
'1690: str(0b100111) == \"3.9e1"');
|
||||
vrfy(str(07543) == "3.939e3", \
|
||||
'1691: str(07543) == \"3.939e3"');
|
||||
vrfy(str(7543) == "7.543e3", \
|
||||
'1692: str(7543) == \"7.543e3"');
|
||||
|
||||
tmp = base(1000);
|
||||
print '1693: tmp = base(1000)';
|
||||
vrfy(str(0x80000000) == "2.147483648e9", \
|
||||
'1694: str(0x8000000) == \"2.147483648e9"');
|
||||
vrfy(str(0xffffffff) == "4.294967295e9", \
|
||||
'1695: str(0xffffffff) == \"4.294967295e9\"');
|
||||
vrfy(str(3e9) == "3e9", \
|
||||
'1696: str(3e9) == \"3e9\"');
|
||||
vrfy(str(1/3) == "~333.33333333333333333333e-3", \
|
||||
'1697: str(1/3) == \"~333.33333333333333333333e-3\"');
|
||||
vrfy(str(2e8) == "200e6", \
|
||||
'1698: str(2e8) == \"200e6"');
|
||||
vrfy(str(200e6) == "200e6", \
|
||||
'1699: str(200e6) == \"200e6"');
|
||||
vrfy(str(0b100111) == "39", \
|
||||
'1700: str(0b100111) == \"39"');
|
||||
vrfy(str(07543) == "3.939e3", \
|
||||
'1701: str(07543) == \"3.939e3"');
|
||||
vrfy(str(7543) == "7.543e3", \
|
||||
'1702: str(7543) == \"7.543e3"');
|
||||
|
||||
tmp = base(-10);
|
||||
print '1703: tmp = base(-10)';
|
||||
vrfy(str(0x80000000) == "2147483648", \
|
||||
'1704: str(0x8000000) == \"2147483648\"');
|
||||
vrfy(str(0xffffffff) == "4294967295", \
|
||||
'1705: str(0xffffffff) == \"4294967295\"');
|
||||
vrfy(str(3e9) == "3000000000", \
|
||||
'1706: str(3e9) == \"3000000000\"');
|
||||
vrfy(str(1/3) == "~0", \
|
||||
'1707: str(1/3) == \"~0\"');
|
||||
vrfy(str(2e8) == "200000000", \
|
||||
'1708: str(2e8) == \"200000000"');
|
||||
vrfy(str(200e6) == "200000000", \
|
||||
'1709: str(200e6) == \"200000000"');
|
||||
vrfy(str(0b100111) == "39", \
|
||||
'1710: str(0b100111) == \"39"');
|
||||
vrfy(str(07543) == "3939", \
|
||||
'1711: str(07543) == \"3939"');
|
||||
vrfy(str(7543) == "7543", \
|
||||
'1712: str(7543) == \"7543"');
|
||||
|
||||
tmp = base(10);
|
||||
print '1646: tmp = base(10)';
|
||||
vrfy(config("mode") == "real", \
|
||||
'1647: config("mode") == "real"');
|
||||
|
||||
print '1713: tmp = base(10)';
|
||||
vrfy(str(0x80000000) == "2147483648", \
|
||||
'1648: str(0x80000000) == \"2147483648\"');
|
||||
'1714: str(0x8000000) == \"2147483648\"');
|
||||
vrfy(str(0xffffffff) == "4294967295", \
|
||||
'1649: str(0xffffffff) == \"4294967295\"');
|
||||
'1715: str(0xffffffff) == \"4294967295\"');
|
||||
vrfy(str(3e9) == "3000000000", \
|
||||
'1650: str(3e9) == \"3000000000\"');
|
||||
'1716: str(3e9) == \"3000000000\"');
|
||||
vrfy(str(1/3) == "~0.33333333333333333333", \
|
||||
'1717: str(1/3) == \"~0.33333333333333333333"');
|
||||
vrfy(str(2e8) == "200000000", \
|
||||
'1718: str(2e8) == \"200000000"');
|
||||
vrfy(str(200e6) == "200000000", \
|
||||
'1719: str(200e6) == \"200000000"');
|
||||
vrfy(str(0b100111) == "39", \
|
||||
'1720: str(0b100111) == \"39"');
|
||||
vrfy(str(07543) == "3939", \
|
||||
'1721: str(07543) == \"3939"');
|
||||
vrfy(str(7543) == "7543", \
|
||||
'1722: str(7543) == \"7543"');
|
||||
|
||||
/* test base2() functionality */
|
||||
vrfy(base2() == 0, '1651: base2() == 0');
|
||||
vrfy(base2(0) == 0, '1652: base2(0) == 0');
|
||||
vrfy(base2() == 0, '1653: base2() == 0');
|
||||
vrfy(base2(16) == 0, '1654: base2(16) == 0');
|
||||
vrfy(base2() == 16, '1655: base2() == 16');
|
||||
vrfy(str(3e9) == "3000000000 /* 0xb2d05e00 */",
|
||||
'1656: str(3e9) == "3000000000 /* 0xb2d05e00 */"');
|
||||
vrfy(base2(1/3) == 16, '1657: base2(16) == 16');
|
||||
vrfy(str(23209) == "23209 /* 23209 */",
|
||||
'1658: str(23209) == "23209 /* 23209 */"');
|
||||
vrfy(str(3/2) == "1.5 /* 3/2 */",
|
||||
'1659: str(3/2) == "1.5 /* 3/2 */"');
|
||||
vrfy(base() == 10, '1660: base() == 10');
|
||||
vrfy(base2(0) == 1/3, '1661: base2(0) == 1/3');
|
||||
vrfy(base2() == 0, '1723: base2() == 0');
|
||||
vrfy(base2(0) == 0, '1724: base2(0) == 0');
|
||||
vrfy(base2() == 0, '1725: base2() == 0');
|
||||
|
||||
print '1662: Ending mode/base test';
|
||||
vrfy(base2(16) == 0, '1726: base2(16) == 0');
|
||||
vrfy(base2() == 16, '1727: base2() == 16');
|
||||
vrfy(str(3e9) == "3000000000 /* 0xb2d05e00 */",
|
||||
'1728: str(3e9) == "3000000000 /* 0xb2d05e00 */"');
|
||||
|
||||
vrfy(base2(1/3) == 16, '1728: base2(16) == 16');
|
||||
vrfy(base2() == 1/3, '1729: base2() == 1/3');
|
||||
vrfy(str(23209) == "23209 /* 23209 */",
|
||||
'1730: str(23209) == "23209 /* 23209 */"');
|
||||
vrfy(str(3/2) == "1.5 /* 3/2 */",
|
||||
'1731: str(3/2) == "1.5 /* 3/2 */"');
|
||||
|
||||
vrfy(base2(8) == 1/3, '1732: base2(8) == 1/3');
|
||||
vrfy(base2() == 8, '1733: base2() == 8');
|
||||
vrfy(str(23209) == "23209 /* 055251 */",
|
||||
'1734: str(23209) == "23209 /* 055251 */"');
|
||||
vrfy(str(3/2) == "1.5 /* 3/2 */",
|
||||
'1735: str(3/2) == "1.5 /* 3/2 */"');
|
||||
|
||||
vrfy(base2(2) == 8, '1736: base2(2) == 8');
|
||||
vrfy(base2() == 2, '1737: base2() == 2');
|
||||
vrfy(str(23209) == "23209 /* 0b101101010101001 */",
|
||||
'1738: str(23209) == "23209 /* 0b101101010101001 */"');
|
||||
vrfy(str(3/2) == "1.5 /* 0b11/0b10 */",
|
||||
'1739: str(3/2) == "1.5 /* 0b11/0b10 */"');
|
||||
|
||||
vrfy(base2(1e20) == 2, '1740: base2(1e20) == 2');
|
||||
vrfy(base2() == 1e20, '1741: base2() == 1e20');
|
||||
vrfy(str(23209) == "23209 /* 2.3209e4 */",
|
||||
'1742: str(23209) == "23209 /* 2.3209e4 */"');
|
||||
vrfy(str(3/2) == "1.5 /* 1.5 */",
|
||||
'1743: str(3/2) == "1.5 /* 1.5 */"');
|
||||
|
||||
vrfy(base2(-10) == 1e20, '1744: base2(-10) == 1e20');
|
||||
vrfy(base2() == -10, '1745: base2() == -10');
|
||||
vrfy(str(23209) == "23209 /* 23209 */",
|
||||
'1746: str(23209) == "23209 /* 23209 */"');
|
||||
vrfy(str(3/2) == "1.5 /* ~2 */",
|
||||
'1747: str(3/2) == "1.5 /* ~2 */"');
|
||||
|
||||
vrfy(base2(1000) == -10, '1748: base2(1000) == -1000');
|
||||
vrfy(base2() == 1000, '1749: base2() == 1000');
|
||||
vrfy(str(23209) == "23209 /* 23.209e3 */",
|
||||
'1750: str(23209) == "23209 /* 23.209e3 */"');
|
||||
vrfy(str(3/2) == "1.5 /* 1.5 */",
|
||||
'1751: str(3/2) == "1.5 /* 1.5 */"');
|
||||
|
||||
vrfy(base2(10) == 1000, '1752: base2(10) == 1000');
|
||||
vrfy(base2() == 10, '1753: base2() == 10');
|
||||
vrfy(str(23209) == "23209 /* 23209 */",
|
||||
'1754: str(23209) == "23209 /* 23209 */"');
|
||||
vrfy(str(3/2) == "1.5 /* 1.5 */",
|
||||
'1755: str(3/2) == "1.5 /* 1.5 */"');
|
||||
|
||||
vrfy(base2(0) == 10, '1756: base2(0) == 10');
|
||||
vrfy(base2() == 0, '1757: base2() == 0');
|
||||
vrfy(str(23209) == "23209",
|
||||
'1758: str(23209) == "23209"');
|
||||
vrfy(str(3/2) == "1.5",
|
||||
'1759: str(3/2) == "1.5"');
|
||||
|
||||
vrfy(base() == 10, '1760: base() == 10');
|
||||
vrfy(base2() == 0, '1761: base2() == 0');
|
||||
|
||||
print '1762: Ending mode/base test';
|
||||
}
|
||||
print '026: parsed test_mode()';
|
||||
|
||||
|
||||
/*
|
||||
* The 1700's contain tests for reading resource files. These tests are
|
||||
* done inline near the bottom.
|
||||
* The 1780's and 1790's contain tests for reading resource files.
|
||||
*
|
||||
* These tests are done inline near the bottom.
|
||||
*/
|
||||
|
||||
|
||||
@@ -3198,9 +3402,11 @@ define test_trig()
|
||||
|
||||
print '3400: Beginning test_trig';
|
||||
|
||||
/* test 3401-3407 */
|
||||
tnum = test3400(1, 3401);
|
||||
vrfy(tnum == 3407, '3407: tnum == 3407');
|
||||
|
||||
print tnum: ': Ending test_trig';
|
||||
print '3438: Ending test_trig';
|
||||
}
|
||||
print '051: parsed test_trig()';
|
||||
|
||||
@@ -7635,31 +7841,31 @@ print;
|
||||
return test_mode();
|
||||
print;
|
||||
|
||||
print '1700: Beginning read test';
|
||||
print '1780: Beginning read test';
|
||||
value = 0;
|
||||
vrfy(value == 0, '1701: value == 0');
|
||||
vrfy(value == 0, '1781: value == 0');
|
||||
read "test1700";
|
||||
print '1702: read "test1700";';
|
||||
vrfy(value == 1, '1703: value == 1');
|
||||
print '1782: read "test1700";';
|
||||
vrfy(value == 1, '1783: value == 1');
|
||||
read -once "test1700";
|
||||
print '1704: read -once "test1700";';
|
||||
vrfy(value == 1, '1705: value == 1');
|
||||
print '1784: read -once "test1700";';
|
||||
vrfy(value == 1, '1785: value == 1');
|
||||
read "test1700.cal";
|
||||
print '1706: read "test1700.cal";';
|
||||
vrfy(value == 2, '1707: value == 2');
|
||||
read -once "test1700.cal";
|
||||
print '1708: read -once "test1700.cal";';
|
||||
vrfy(value == 2, '1709: value == 2');
|
||||
print '1786: read "test1700.cal";';
|
||||
vrfy(value == 2, '1787: value == 2');
|
||||
read -once "test1700.cal"
|
||||
print '1788: read -once "test1700.cal";';
|
||||
vrfy(value == 2, '1789: value == 2');
|
||||
read "test1700.cal";
|
||||
print '1710: read "test1700.cal";';
|
||||
vrfy(value == 3, '1711: value == 3');
|
||||
print '1790: read "test1700.cal";';
|
||||
vrfy(value == 3, '1791: value == 3');
|
||||
{++value;} read "test1700.cal";
|
||||
print '1712: {++value;} read "test1700.cal";';
|
||||
vrfy(value == 5, '1713: value == 5');
|
||||
print '1792: {++value;} read "test1700.cal";';
|
||||
vrfy(value == 5, '1793: value == 5');
|
||||
{++value;} read -once "test1700.cal";
|
||||
print '1714: {++value;} read -once "test1700.cal";';
|
||||
vrfy(value == 6, '1715: value == 6');
|
||||
print '1716: Ending read test';
|
||||
print '1794: {++value;} read -once "test1700.cal";';
|
||||
vrfy(value == 6, '1795: value == 6');
|
||||
print '1796: Ending read test';
|
||||
|
||||
print;
|
||||
return test_obj();
|
||||
@@ -7963,6 +8169,8 @@ ecnt = 211;
|
||||
* Test more of the built-in functions.
|
||||
*
|
||||
* See test_functions() (test 700 - 1238) for other built-in function tests.
|
||||
* See test_functions2() (test 9000 - 9063) for other built-in function tests.
|
||||
* See test_functions3() (test 9100 - 9214) for other built-in function tests.
|
||||
*/
|
||||
define test_functions2()
|
||||
{
|
||||
@@ -8076,6 +8284,401 @@ print;
|
||||
return test_functions2();
|
||||
|
||||
|
||||
/*
|
||||
* Test even more of the built-in functions.
|
||||
*
|
||||
* See test_functions() (test 700 - 1238) for other built-in function tests.
|
||||
* See test_functions2() (test 9000 - 9063) for other built-in function tests.
|
||||
* See test_functions3() (test 9100 - 9214) for other built-in function tests.
|
||||
*/
|
||||
define test_functions3()
|
||||
{
|
||||
local d, m, s, g, h;
|
||||
|
||||
print '9101: Beginning test_functions3';
|
||||
|
||||
/* d2r & r2d */
|
||||
vrfy(d2r(180) == pi(),
|
||||
'9102: d2r(180) == pi()');
|
||||
vrfy(d2r(180, 1e-100) == pi(1e-100),
|
||||
'9103: d2r(180, 1e-100) == pi(1e-100)');
|
||||
vrfy(r2d(pi()/2) == 90,
|
||||
'9104: r2d(pi()/2) == 90');
|
||||
vrfy(r2d(pi(1e-15)/2) == 14137166941154068500000/157079632679489661923,
|
||||
'9105: r2d(pi(1e-15)/2) == ' +
|
||||
'14137166941154068500000/157079632679489661923');
|
||||
vrfy(r2d(d2r(40)) == 40,
|
||||
'9106: r2d(d2r(40)) == 40');
|
||||
vrfy(r2d(d2r(40,1e-90),1e-90) == 40,
|
||||
'9107: r2d(d2r(40,1e-90),1e-90) == 40');
|
||||
vrfy(d2r(180i) == 1i*pi(),
|
||||
'9108: d2r(1808) == 1i*pi()');
|
||||
vrfy(d2r(180i+90) == 1i*pi() + pi()/2,
|
||||
'9109: d2r(180i+90) == 1i*pi() + pi()/2');
|
||||
vrfy(r2d(d2r(40+40i)) == 40+40i,
|
||||
'9110: r2d(d2r(40+40i)) == 40+40i');
|
||||
vrfy(r2d(d2r(40+40i,1e-60),1e-60) == 40+40i,
|
||||
'9111: r2d(d2r(40+40i,1e-60),1e-60) == 40+40i');
|
||||
|
||||
/* g2r & r2g */
|
||||
vrfy(g2r(200) == pi(),
|
||||
'9112: g2r(200) == pi()');
|
||||
vrfy(g2r(200, 1e-100) == pi(1e-100),
|
||||
'9113: g2r(180, 1e-100) == pi(1e-100)');
|
||||
vrfy(r2g(pi()/2) == 100,
|
||||
'9114: r2g(pi()/2) == 100');
|
||||
vrfy(r2g(pi(1e-15)/2) == 15707963267948965000000/157079632679489661923,
|
||||
'9115: r2g(pi(1e-15)/2) == ' +
|
||||
'15707963267948965000000/157079632679489661923');
|
||||
vrfy(r2g(g2r(40)) == 40,
|
||||
'9116: r2g(g2r(40)) == 40');
|
||||
vrfy(r2g(g2r(40,1e-90),1e-90) == 40,
|
||||
'9117: r2g(g2r(40,1e-90),1e-90) == 40');
|
||||
vrfy(g2r(200i) == 1i*pi(),
|
||||
'9118: g2r(200i) == 1i*pi()');
|
||||
vrfy(g2r(200i+150) == pi()*0.75 + 1i*pi(),
|
||||
'9119: g2r(200i+150) == pi()*0.75 + 1i*pi()');
|
||||
vrfy(r2g(g2r(40+40i)) == 40+40i,
|
||||
'9120: r2g(g2r(40+40i)) == 40+40i');
|
||||
vrfy(r2g(g2r(40+40i,1e-60),1e-60) == 40+40i,
|
||||
'9121: r2g(g2r(40+40i,1e-60),1e-60) == 40+40i');
|
||||
|
||||
/* g2d & d2g */
|
||||
vrfy(g2d(200) == 180,
|
||||
'9122: g2d(200) == 180');
|
||||
vrfy(g2d(200, 1e-100) == 180,
|
||||
'9123: g2d(180, 1e-100) == 180');
|
||||
vrfy(d2g(81) == 90,
|
||||
'9124: d2g(81) == 90');
|
||||
vrfy(d2g(pi(1e-15)/2) == 3141592653589793/1800000000000000,
|
||||
'9125: d2g(pi(1e-15)/2) == 3141592653589793/1800000000000000');
|
||||
vrfy(d2g(g2d(40)) == 40,
|
||||
'9126: d2g(g2d(40)) == 40');
|
||||
vrfy(d2g(g2d(40,1e-90),1e-90) == 40,
|
||||
'9127: d2g(g2d(40,1e-90),1e-90) == 40');
|
||||
vrfy(g2d(200i) == 180i,
|
||||
'9128: g2d(200i) == 180i');
|
||||
vrfy(g2d(200i+47) == 42.3 + 180i,
|
||||
'9129: g2d(200i+47) == 42.3 + 180i');
|
||||
vrfy(d2g(g2d(40+40i)) == 40+40i,
|
||||
'9130: d2g(g2d(40+40i)) == 40+40i');
|
||||
vrfy(d2g(g2d(40+40i,1e-90),1e-90) == 40+40i,
|
||||
'9131: d2g(g2d(40+40i,1e-90),1e-90) == 40+40i');
|
||||
|
||||
/* d2dms */
|
||||
vrfy(d2dms(12.3456,d,m,s) == 12.3456,
|
||||
'9132: d2dms(12.3456,d,m,s) == 12.3456');
|
||||
vrfy(d == 12,
|
||||
'9133: d == 12');
|
||||
vrfy(m == 20,
|
||||
'9133: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9134: s == 44.16');
|
||||
|
||||
vrfy(d2dms(1234.5678,d,m,s) == 154.5678,
|
||||
'9135: d2dms(1234.5678,d,m,s) == 154.5678');
|
||||
vrfy(d == 154,
|
||||
'9136: d == 154');
|
||||
vrfy(m == 34,
|
||||
'9137: m == 34');
|
||||
vrfy(s == 4.08,
|
||||
'9138: s == 4.08');
|
||||
|
||||
vrfy(d2dms(-1234.5678,d,m,s) == 205.4322,
|
||||
'9139: d2dms(-1234.5678,d,m,s) == 205.4322');
|
||||
vrfy(d == 205,
|
||||
'9140: d == 205');
|
||||
vrfy(m == 25,
|
||||
'9141: m == 25');
|
||||
vrfy(s == 55.92,
|
||||
'9142: s == 55.92');
|
||||
|
||||
vrfy(d2dms(360.321,d,m,s,1) == -359.679,
|
||||
'9143: d2dms(360.321,d,m,s,1) == -359.679');
|
||||
vrfy(d == -359,
|
||||
'9144: d == -359');
|
||||
vrfy(m == -40,
|
||||
'9145: m == -40');
|
||||
vrfy(s == -44.4,
|
||||
'9146: s == -44.4');
|
||||
|
||||
/* d2dm */
|
||||
vrfy(d2dm(12.3456,d,m) == 12.3456,
|
||||
'9147: d2dm(12.3456,d,m) == 12.3456');
|
||||
vrfy(d == 12,
|
||||
'9148: d == 12');
|
||||
vrfy(m == 20.736,
|
||||
'9149: m == 20.736');
|
||||
|
||||
vrfy(d2dm(1234.5678,d,m) == 154.5678,
|
||||
'9150: d2dm(1234.5678,d,m) == 154.5678');
|
||||
vrfy(d == 154,
|
||||
'9151: d == 154');
|
||||
vrfy(m == 34.068,
|
||||
'9152: m == 34.068');
|
||||
|
||||
vrfy(d2dm(-1234.5678,d,m) == 205.4322,
|
||||
'9153: d2dm(-1234.5678,d,m) == 205.4322');
|
||||
vrfy(d == 205,
|
||||
'9154: d == 205');
|
||||
vrfy(m == 25.932,
|
||||
'9155: m == 25.932');
|
||||
|
||||
vrfy(d2dm(360.321,d,m,1) == -359.679,
|
||||
'9156: d2dm(360.321,d,m,1) == -359.679');
|
||||
vrfy(d == -359,
|
||||
'9167: d == -359');
|
||||
vrfy(m == -40.74,
|
||||
'9158: m == -40.74');
|
||||
|
||||
/* g2gms */
|
||||
vrfy(g2gms(12.3456,g,m,s) == 12.3456,
|
||||
'9159: g2gms(12.3456,g,m,s) == 12.3456');
|
||||
vrfy(g == 12,
|
||||
'9133: g == 12');
|
||||
vrfy(m == 20,
|
||||
'9160: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9161: s == 44.16');
|
||||
|
||||
vrfy(g2gms(1234.5678,g,m,s) == 34.5678,
|
||||
'9162: g2gms(1234.5678,g,m,s) == 34.5678');
|
||||
vrfy(g == 34,
|
||||
'9163: g == 34');
|
||||
vrfy(m == 34,
|
||||
'9164: m == 34');
|
||||
vrfy(s == 4.08,
|
||||
'9165: s == 4.08');
|
||||
|
||||
vrfy(g2gms(-1234.5678,g,m,s) == 365.4322,
|
||||
'9166: g2gms(-1234.5678,g,m,s) == 365.4322');
|
||||
vrfy(g == 365,
|
||||
'9167: g == 365');
|
||||
vrfy(m == 25,
|
||||
'9168: m == 25');
|
||||
vrfy(s == 55.92,
|
||||
'9169: s == 55.92');
|
||||
|
||||
vrfy(g2gms(400.321,g,m,s,1) == -399.679,
|
||||
'9170: g2gms(400.321,g,m,s,1) == -399.679');
|
||||
vrfy(g == -399,
|
||||
'9171: g == -399');
|
||||
vrfy(m == -40,
|
||||
'9172: m == -40');
|
||||
vrfy(s == -44.4,
|
||||
'9173: s == -44.4');
|
||||
|
||||
/* g2gm */
|
||||
vrfy(g2gm(12.3456,g,m) == 12.3456,
|
||||
'9174: g2gm(12.3456,g,m) == 12.3456');
|
||||
vrfy(g == 12,
|
||||
'9175: g == 12');
|
||||
vrfy(m == 20.736,
|
||||
'9176: m == 20.736');
|
||||
|
||||
vrfy(g2gm(1234.5678,g,m) == 34.5678,
|
||||
'9177: g2gm(1234.5678,g,m) == 34.5678');
|
||||
vrfy(g == 34,
|
||||
'9178: g == 34');
|
||||
vrfy(m == 34.068,
|
||||
'9179: m == 34.068');
|
||||
|
||||
vrfy(g2gm(-1234.5678,g,m) == 365.4322,
|
||||
'9180: g2gm(-1234.5678,g,m) == 365.4322');
|
||||
vrfy(g == 365,
|
||||
'9181: g == 365');
|
||||
vrfy(m == 25.932,
|
||||
'9182: m == 25.932');
|
||||
|
||||
vrfy(g2gm(400.321,g,m,1) == -399.679,
|
||||
'9183: g2gm(400.321,g,m,1) == -399.679');
|
||||
vrfy(g == -399,
|
||||
'9184: g == -399');
|
||||
vrfy(m == -40.74,
|
||||
'9185: m == -40.74');
|
||||
|
||||
/* h2hms */
|
||||
vrfy(h2hms(12.3456,h,m,s) == 12.3456,
|
||||
'9186: h2hms(12.3456,h,m,s) == 12.3456');
|
||||
vrfy(h == 12,
|
||||
'9187: h == 12');
|
||||
vrfy(m == 20,
|
||||
'9188: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9189: s == 44.16');
|
||||
|
||||
vrfy(h2hms(1234.5678,h,m,s) == 10.5678,
|
||||
'9190: h2hms(1234.5678,h,m,s) == 10.5678');
|
||||
vrfy(h == 10,
|
||||
'9191: h == 10');
|
||||
vrfy(m == 34,
|
||||
'9192: m == 34');
|
||||
vrfy(s == 4.08,
|
||||
'9193: s == 4.08');
|
||||
|
||||
vrfy(h2hms(-1234.5678,h,m,s) == 13.4322,
|
||||
'9194: h2hms(-1234.5678,h,m,s) == 13.4322');
|
||||
vrfy(h == 13,
|
||||
'9195: h == 13');
|
||||
vrfy(m == 25,
|
||||
'9196: m == 25');
|
||||
vrfy(s == 55.92,
|
||||
'9197: s == 55.92');
|
||||
|
||||
vrfy(h2hms(24.321,h,m,s,1) == -23.679,
|
||||
'9198: h2hms(24.321,h,m,s,1) == -23.679');
|
||||
vrfy(h == -23,
|
||||
'9199: h == -23');
|
||||
vrfy(m == -40,
|
||||
'9200: m == -40');
|
||||
vrfy(s == -44.4,
|
||||
'9201: s == -44.4');
|
||||
|
||||
/* h2hm */
|
||||
vrfy(h2hm(12.3456,h,m) == 12.3456,
|
||||
'9202: h2hm(12.3456,h,m) == 12.3456');
|
||||
vrfy(h == 12,
|
||||
'9203: h == 12');
|
||||
vrfy(m == 20.736,
|
||||
'9204: m == 20.736');
|
||||
|
||||
vrfy(h2hm(1234.5678,h,m) == 10.5678,
|
||||
'9205: h2hm(1234.5678,h,m) == 10.5678');
|
||||
vrfy(h == 10,
|
||||
'9206: h == 10');
|
||||
vrfy(m == 34.068,
|
||||
'9207: m == 34.068');
|
||||
|
||||
vrfy(h2hm(-1234.5678,h,m) == 13.4322,
|
||||
'9208: h2hm(-1234.5678,h,m) == 13.4322');
|
||||
vrfy(h == 13,
|
||||
'9209: h == 13');
|
||||
vrfy(m == 25.932,
|
||||
'9210: m == 25.932');
|
||||
|
||||
vrfy(h2hm(24.321,h,m,1) == -23.679,
|
||||
'9211: h2hm(24.321,h,m,1) == -23.679');
|
||||
vrfy(h == -23,
|
||||
'9212: h == -23');
|
||||
vrfy(m == -40.74,
|
||||
'9213: m == -40.74');
|
||||
|
||||
/* dm2d */
|
||||
vrfy(dm2d(203, 325.5594) == 208.42599,
|
||||
'9214: dm2d(203, 325.5594) == 208.42599');
|
||||
vrfy(dm2d(3601, -25.5594) == 0.57401,
|
||||
'9215: dm2d(3601, -25.5594) == 0.57401');
|
||||
vrfy(dm2d(-923, -25.5594) == 156.57401,
|
||||
'9216: dm2d(-923, -25.5594) == 156.57401');
|
||||
vrfy(dm2d(203, 325.5594, 1) == -151.57401,
|
||||
'9217: dm2d(203, 325.5594, 1) == -151.57401');
|
||||
|
||||
vrfy(d2dm(dm2d(12, 20.16),d,m) == 12.336,
|
||||
'9218: d2dm(dm2d(12, 20.16),d,m) == 12.336');
|
||||
vrfy(d == 12,
|
||||
'9219: d == 12');
|
||||
vrfy(m == 20.16,
|
||||
'9220: m == 20.16');
|
||||
|
||||
/* dms2d */
|
||||
vrfy(dms2d(12, 20, 44.16) == 12.3456,
|
||||
'9221: dms2d(12, 20, 44.16) == 12.3456');
|
||||
vrfy(dms2d(123.456, -345.68, 4.08) == 117.6958,
|
||||
'9222: dms2d(123.456, -345.68, 4.08) == 117.6958');
|
||||
vrfy(dms2d(-65, -40, -44.4) == 294.321,
|
||||
'9223: dms2d(-65, -40, -44.4) == 294.321');
|
||||
vrfy(dms2d(12, 20, 44.16, 1) == -347.6544,
|
||||
'9224: dms2d(12, 20, 44.16, 1) == -347.6544');
|
||||
|
||||
vrfy(d2dms(dms2d(13, 20, 44.16),d,m,s) == 13.3456,
|
||||
'9225: d2dms(dms2d(13, 20, 44.16),d,m,s) == 13.3456');
|
||||
vrfy(d == 13,
|
||||
'9226: d == 13');
|
||||
vrfy(m == 20,
|
||||
'9227: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9228: s == 44.16');
|
||||
|
||||
/* gm2g */
|
||||
vrfy(gm2g(203, 325.5594) == 208.42599,
|
||||
'9229: gm2g(203, 325.5594) == 208.42599');
|
||||
vrfy(gm2g(3601, -25.5594) == 0.57401,
|
||||
'9230: gm2g(3601, -25.5594) == 0.57401');
|
||||
vrfy(gm2g(-923, -25.5594) == 276.57401,
|
||||
'9231: gm2g(-923, -25.5594) == 276.57401');
|
||||
vrfy(gm2g(203, 325.5594, 1) == -191.57401,
|
||||
'9232: gm2g(203, 325.5594, 1) == -191.57401');
|
||||
|
||||
vrfy(g2gm(gm2g(12, 20.16),g,m) == 12.336,
|
||||
'9233: g2gm(gm2g(12, 20.16),g,m) == 12.336');
|
||||
vrfy(g == 12,
|
||||
'9234: g == 12');
|
||||
vrfy(m == 20.16,
|
||||
'9235: m == 20.16');
|
||||
|
||||
/* gms2g */
|
||||
vrfy(gms2g(12, 20, 44.16) == 12.3456,
|
||||
'9236: gms2g(12, 20, 44.16) == 12.3456');
|
||||
vrfy(gms2g(123.456, -345.68, 4.08) == 117.6958,
|
||||
'9237: gms2g(123.456, -345.68, 4.08) == 117.6958');
|
||||
vrfy(gms2g(-65, -40, -44.4) == 334.321,
|
||||
'9238: gms2g(-65, -40, -44.4) == 334.321');
|
||||
vrfy(gms2g(12, 20, 44.16, 1) == -387.6544,
|
||||
'9239: gms2g(12, 20, 44.16, 1) == -387.6544');
|
||||
|
||||
vrfy(g2gms(gms2g(14, 20, 44.16),g,m,s) == 14.3456,
|
||||
'9240: g2gms(gms2g(14, 20, 44.16),g,m,s) == 14.3456');
|
||||
vrfy(g == 14,
|
||||
'9241: g == 14');
|
||||
vrfy(m == 20,
|
||||
'9242: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9243: s == 44.16');
|
||||
|
||||
/* hm2h */
|
||||
vrfy(hm2h(203, 325.5594) == 16.42599,
|
||||
'9244: hm2h(203, 325.5594) == 16.42599');
|
||||
vrfy(hm2h(241, -25.5594) == 0.57401,
|
||||
'9245: hm2h(241, -25.5594) == 0.57401');
|
||||
vrfy(hm2h(-923, -25.5594) == 12.57401,
|
||||
'9246: hm2h(-923, -25.5594) == 12.57401');
|
||||
vrfy(hm2h(203, 325.5594, 1) == -7.57401,
|
||||
'9247: hm2h(203, 325.5594, 1) == -7.57401');
|
||||
|
||||
vrfy(h2hm(hm2h(12, 20.16),h,m) == 12.336,
|
||||
'9248: h2hm(hm2h(12, 20.16),h,m) == 12.336');
|
||||
vrfy(h == 12,
|
||||
'9249: h == 12');
|
||||
vrfy(m == 20.16,
|
||||
'9250: m == 20.16');
|
||||
|
||||
/* hms2h */
|
||||
vrfy(hms2h(12, 20, 44.16) == 12.3456,
|
||||
'9251: hms2h(12, 20, 44.16) == 12.3456');
|
||||
vrfy(hms2h(123.456, -345.68, 4.08) == 21.6958,
|
||||
'9252: hms2h(123.456, -345.68, 4.08) == 21.6958');
|
||||
vrfy(hms2h(-65, -40, -44.4) == 6.321,
|
||||
'9253: hms2h(-65, -40, -44.4) == 6.321');
|
||||
vrfy(hms2h(12, 20, 44.16, 1) == -11.6544,
|
||||
'9254: hms2h(12, 20, 44.16, 1) == -11.6544');
|
||||
|
||||
vrfy(h2hms(hms2h(15, 20, 44.16),h,m,s) == 15.3456,
|
||||
'9255: h2hms(hms2h(15, 20, 44.16),h,m,s) == 15.3456');
|
||||
vrfy(h == 15,
|
||||
'9256: h == 15');
|
||||
vrfy(m == 20,
|
||||
'9257: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9258: s == 44.16');
|
||||
|
||||
print '9259: Ending test_functions3';
|
||||
}
|
||||
print;
|
||||
print '9100: parsed test_functions3()';
|
||||
print;
|
||||
return test_functions3();
|
||||
|
||||
|
||||
/*
|
||||
* read various calc resource files
|
||||
*
|
||||
|
@@ -371,7 +371,7 @@ define normalcdf(x,mu,sigma){
|
||||
|
||||
define probit(p){
|
||||
if(p<0 || p > 1) return newerror("probit: p out of domain 0<=p<=1");
|
||||
return sqrt(2)*ervinv(2*p-1);
|
||||
return sqrt(2)*erfinv(2*p-1);
|
||||
}
|
||||
|
||||
define normalcdfinv(p,mu,sigma){
|
||||
|
@@ -336,7 +336,7 @@ define __CZ__produce_long_random_number(n)
|
||||
ret = 1;
|
||||
if(!isint(n) || n<1)
|
||||
return newerror("__CZ__produce_long_random_number(n): "
|
||||
"n is not an integer >=1");
|
||||
"n is not an integer >=1");
|
||||
for(k=0;k<n;k++){
|
||||
ret += random();
|
||||
ret = toomcook4square(ret);
|
||||
|
@@ -72,7 +72,7 @@ define hurwitzzeta(s,a){
|
||||
limit=(precision*ln(10)-re((s-.5)*result)+(1.*realpart_a)*ln(2.*pi()))/2;
|
||||
limit=max(2,ceil(max(limit,abs(s*1.)/2)));
|
||||
limit_function=ceil(sqrt((limit+realpart_a/2-.25)^2+(imagpart_s*1.)^2/4)/
|
||||
pi());
|
||||
pi());
|
||||
if (config("user_debug") > 0) {
|
||||
print "limit_function = " limit_function;
|
||||
print "limit = " limit;
|
||||
|
48
calcerr.tbl
48
calcerr.tbl
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# calcerr - error codes and messages
|
||||
#
|
||||
# Copyright (C) 1999-2006 Ernest Bowen
|
||||
# Copyright (C) 1999-2006,2021 Ernest Bowen
|
||||
#
|
||||
# Calc is open software; you can redistribute it and/or modify it under
|
||||
# the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
@@ -496,3 +496,49 @@ E_ATANH3 Invalid value for calculating atan
|
||||
E_ACOTH3 Invalid value for calculating acot
|
||||
E_ASECH3 Invalid value for calculating asec
|
||||
E_ACSCH3 Invalid value for calculating acsc
|
||||
E_D2R1 Bad epsilon for converting degrees to radians
|
||||
E_D2R2 Bad first argument converting degrees to radians
|
||||
E_R2D1 Bad epsilon for converting radians to degrees
|
||||
E_R2D2 Bad first argument converting radians to degrees
|
||||
E_G2R1 Bad epsilon for converting gradians to radians
|
||||
E_G2R2 Bad first argument converting gradians to radians
|
||||
E_R2G1 Bad epsilon for converting radians to gradians
|
||||
E_R2G2 Bad first argument converting radians to gradians
|
||||
E_D2G1 Bad first argument converting degrees to gradians
|
||||
E_G2D1 Bad first argument converting gradians to degrees
|
||||
E_D2DMS1 Non-lvalue arguments 2, 3 or 4 for d2dms
|
||||
E_D2DMS2 Non-real-number arg 1 for d2dms
|
||||
E_D2DMS3 No-assign-to argument 2, 3 or 4 for d2dms
|
||||
E_D2DMS4 Invalid rounding arg 5 for d2dms
|
||||
E_D2DM1 Non-lvalue arguments 2 or 3 for d2dm
|
||||
E_D2DM2 Non-real-number arg 1 for d2dm
|
||||
E_D2DM3 No-assign-to argument 2 or 3 for d2dm
|
||||
E_D2DM4 Invalid rounding arg 4 for d2dm
|
||||
E_G2GMS1 Non-lvalue arguments 2, 3 or 4 for g2gms
|
||||
E_G2GMS2 Non-real-number arg 1 for g2gms
|
||||
E_G2GMS3 No-assign-to argument 2 or 3 for g2gms
|
||||
E_G2GMS4 Invalid rounding arg 5 for g2gms
|
||||
E_G2GM1 Non-lvalue arguments 2 or 3 for g2gm
|
||||
E_G2GM2 Non-real-number arg 1 for g2gm
|
||||
E_G2GM3 No-assign-to argument 2, 3 or 4 for g2gm
|
||||
E_G2GM4 Invalid rounding arg 4 for g2gm
|
||||
E_H2HMS1 Non-lvalue arguments 2, 3 or 4 for h2hms
|
||||
E_H2HMS2 Non-real-number arg 1 for h2hms
|
||||
E_H2HMS3 No-assign-to argument 2, 3 or 4 for h2hms
|
||||
E_H2HMS4 Invalid rounding arg 5 for h2hms
|
||||
E_H2HM1 Non-lvalue arguments 2 or 3 for h2hm
|
||||
E_H2HM2 Non-real-number arg 1 for h2hm
|
||||
E_H2HM3 No-assign-to argument 2 or 3 for h2hm
|
||||
E_H2HM4 Invalid rounding arg 4 for h2hm
|
||||
E_DMS2D1 Non-real-number aarguments 1, 2 or 3 for dms2d
|
||||
E_DMS2D2 Invalid rounding arg 4 for dms2d
|
||||
E_DM2D1 Non-real-number aarguments 1 or 2 for dm2d
|
||||
E_DM2D2 Invalid rounding arg 4 for dm2d
|
||||
E_GMS2G1 Non-real-number aarguments 1, 2 or 3 for gms2g
|
||||
E_GMS2G2 Invalid rounding arg 4 for gms2g
|
||||
E_GM2G1 Non-real-number aarguments 1 or 2 for gm2g
|
||||
E_GM2G2 Invalid rounding arg 4 for gm2g
|
||||
E_HMS2H1 Non-real-number aarguments 1, 2 or 3 for hms2h
|
||||
E_HMS2H2 Invalid rounding arg 4 for hms2h
|
||||
E_HM2H1 Non-real-number aarguments 1 or 2 for hm2h
|
||||
E_HM2H2 Invalid rounding arg 4 for hm2h
|
||||
|
2
config.c
2
config.c
@@ -274,6 +274,8 @@ STATIC NAMETYPE modes[] = {
|
||||
{"scientific", MODE_EXP},
|
||||
{"sci", MODE_EXP},
|
||||
{"exp", MODE_EXP},
|
||||
{"engineering", MODE_ENG},
|
||||
{"eng", MODE_ENG},
|
||||
{"hexadecimal", MODE_HEX},
|
||||
{"hex", MODE_HEX},
|
||||
{"octal", MODE_OCTAL},
|
||||
|
13
const.c
13
const.c
@@ -44,16 +44,16 @@ initconstants(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
consttable = (NUMBER **) malloc(sizeof(NUMBER *) * CONSTALLOCSIZE);
|
||||
consttable = (NUMBER **) calloc(sizeof(NUMBER *), CONSTALLOCSIZE);
|
||||
if (consttable == NULL) {
|
||||
math_error("Unable to allocate constant table");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
for (i = 0; i < INITCONSTCOUNT; i++)
|
||||
for (i = 0; initnumbs[i] != NULL; i++) {
|
||||
consttable[i] = initnumbs[i];
|
||||
consttable[INITCONSTCOUNT] = NULL; /* firewall */
|
||||
constcount = INITCONSTCOUNT;
|
||||
constavail = CONSTALLOCSIZE - INITCONSTCOUNT;
|
||||
}
|
||||
constcount = i-1;
|
||||
constavail = CONSTALLOCSIZE - constcount;
|
||||
}
|
||||
|
||||
|
||||
@@ -123,6 +123,9 @@ addqconstant(NUMBER *q)
|
||||
tp = consttable;
|
||||
for (index = 0; index < constcount; index++, tp++) {
|
||||
t = *tp;
|
||||
if (t == NULL) { /* paranoia */
|
||||
break;
|
||||
}
|
||||
if (t->links == 0) {
|
||||
if (!havefirst) {
|
||||
havefirst = TRUE;
|
||||
|
@@ -374,12 +374,12 @@ Step 5: Write your custom function
|
||||
|
||||
One is able to set bit 8 by way of the calc command line:
|
||||
|
||||
calc -D 128
|
||||
calc -D 128
|
||||
|
||||
See the calc man page for details. One may also set that bit
|
||||
while running calc by way of the config() builtin function:
|
||||
|
||||
config("calc_debug", 128);
|
||||
config("calc_debug", 128);
|
||||
|
||||
See the help/config file for details on calc_debug.
|
||||
|
||||
|
@@ -145,6 +145,13 @@ CCBAN= -UUNBAN
|
||||
|
||||
|
||||
#if 0 /* start of skip for non-Gnu makefiles */
|
||||
|
||||
# Unfortunately due to the complex dependency issues between
|
||||
# Makefile, Makefile.ship and custom/Makefile, parallel GNU make
|
||||
# is NOT recommended. Sorry.
|
||||
#
|
||||
.NOTPARALLEL:
|
||||
|
||||
##############################################################################
|
||||
#-=-=-=-=-=-=-=-=- Identify the target machine, if possible -=-=-=-=-=-=-=-=-#
|
||||
##############################################################################
|
||||
@@ -489,7 +496,7 @@ EXT=
|
||||
|
||||
# The default calc versions
|
||||
#
|
||||
VERSION= 2.13.0.1
|
||||
VERSION= 2.14.0.9
|
||||
|
||||
# Names of shared libraries with versions
|
||||
#
|
||||
@@ -1077,7 +1084,7 @@ CALCPATH= .;./cal;~/.cal;${T}${CALC_SHAREDIR};${T}${CUSTOMCALDIR}
|
||||
else
|
||||
CALCPATH= .;./cal;~/.cal;${T}${CALC_SHAREDIR}
|
||||
endif
|
||||
CALCRC= ${CALC_SHAREDIR}/startup;~/.calcrc;./.calcinit
|
||||
CALCRC= ./.calcinit;~/.calcrc;${CALC_SHAREDIR}/startup
|
||||
#
|
||||
BLD_TYPE= calc-static-only
|
||||
#
|
||||
|
@@ -145,6 +145,13 @@ CCBAN= -UUNBAN
|
||||
|
||||
|
||||
#if 0 /* start of skip for non-Gnu makefiles */
|
||||
|
||||
# Unfortunately due to the complex dependency issues between
|
||||
# Makefile, Makefile.ship and custom/Makefile, parallel GNU make
|
||||
# is NOT recommended. Sorry.
|
||||
#
|
||||
.NOTPARALLEL:
|
||||
|
||||
##############################################################################
|
||||
#-=-=-=-=-=-=-=-=- Identify the target machine, if possible -=-=-=-=-=-=-=-=-#
|
||||
##############################################################################
|
||||
@@ -489,7 +496,7 @@ EXT=
|
||||
|
||||
# The default calc versions
|
||||
#
|
||||
VERSION= 2.13.0.1
|
||||
VERSION= 2.14.0.9
|
||||
|
||||
# Names of shared libraries with versions
|
||||
#
|
||||
|
@@ -13,7 +13,7 @@ DESCRIPTION
|
||||
|
||||
This custom function will return the value:
|
||||
|
||||
q mod 2^(2^127-1)
|
||||
q mod 2^(2^127-1)
|
||||
|
||||
This custom function serves as a demonstration of how to write
|
||||
a custom function. It performs the equivalent of:
|
||||
|
3
file.c
3
file.c
@@ -1048,6 +1048,9 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals)
|
||||
case 'e':
|
||||
newmode = MODE_EXP;
|
||||
break;
|
||||
case 'n':
|
||||
newmode = MODE_ENG;
|
||||
break;
|
||||
case 'g':
|
||||
newmode = MODE_REAL_AUTO;
|
||||
break;
|
||||
|
@@ -56,8 +56,8 @@ main(void)
|
||||
printf("#define FPOS_POS_BITS %d\n", FPOS_POS_BITS);
|
||||
printf("#define FPOS_POS_LEN %d\n", int(FPOS_POS_BITS/8));
|
||||
# else
|
||||
printf("#define FPOS_POS_BITS %d\n", sizeof(pos.__pos)*8);
|
||||
printf("#define FPOS_POS_LEN %d\n", sizeof(pos.__pos));
|
||||
printf("#define FPOS_POS_BITS %lu\n", sizeof(pos.__pos)*8);
|
||||
printf("#define FPOS_POS_LEN %lu\n", sizeof(pos.__pos));
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
59
help.c
59
help.c
@@ -29,6 +29,7 @@
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
#include "calc.h"
|
||||
#include "conf.h"
|
||||
@@ -83,6 +84,9 @@ STATIC struct help_alias {
|
||||
{"show", "command"},
|
||||
{"stdlib", "resource"},
|
||||
{"question", "questions"},
|
||||
{"dm2d", "dms2d"},
|
||||
{"gm2g", "gms2g"},
|
||||
{"hm2d", "hms2d"},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -259,6 +263,7 @@ givehelp(char *type)
|
||||
}
|
||||
snprintf(helppath, snprintf_len, "%s/%s", calc_helpdir, type);
|
||||
helppath[snprintf_len] = '\0'; /* paranoia */
|
||||
errno = 0;
|
||||
stream = fopen(helppath, "r");
|
||||
if (stream != NULL) {
|
||||
|
||||
@@ -273,30 +278,42 @@ givehelp(char *type)
|
||||
* open the helpfile (looking in CUSTOMHELPDIR last)
|
||||
*/
|
||||
} else {
|
||||
char *cust_helppath; /* path to the custom help file */
|
||||
size_t cust_snprintf_len; /* malloced custom snprintf buf len */
|
||||
char *cust_helppath; /* path to the custom help file */
|
||||
size_t cust_snprintf_len; /* malloced custom snprintf buf len */
|
||||
|
||||
cust_snprintf_len = strlen(calc_customhelpdir)+1+strlen(type) + 1;
|
||||
cust_helppath = (char *)malloc(cust_snprintf_len+1);
|
||||
if (cust_helppath == NULL) {
|
||||
fprintf(stderr, "malloc failure for givehelp #1\n");
|
||||
return;
|
||||
}
|
||||
snprintf(cust_helppath, cust_snprintf_len,
|
||||
"%s/%s", calc_customhelpdir, type);
|
||||
cust_helppath[cust_snprintf_len] = '\0'; /* paranoia */
|
||||
stream = fopen(cust_helppath, "r");
|
||||
if (stream != NULL) {
|
||||
cust_snprintf_len =
|
||||
strlen(calc_customhelpdir)+1+strlen(type) + 1;
|
||||
cust_helppath = (char *)malloc(cust_snprintf_len+1);
|
||||
if (cust_helppath == NULL) {
|
||||
fprintf(stderr, "malloc failure for givehelp #1\n");
|
||||
return;
|
||||
}
|
||||
snprintf(cust_helppath, cust_snprintf_len,
|
||||
"%s/%s", calc_customhelpdir, type);
|
||||
cust_helppath[cust_snprintf_len] = '\0'; /* paranoia */
|
||||
errno = 0;
|
||||
stream = fopen(cust_helppath, "r");
|
||||
if (stream != NULL) {
|
||||
|
||||
/*
|
||||
* we have the help file open, now display it
|
||||
*/
|
||||
page_file(stream);
|
||||
(void) fclose(stream);
|
||||
}
|
||||
free(cust_helppath);
|
||||
cust_helppath = NULL;
|
||||
/*
|
||||
* we have the help file open, now display it
|
||||
*/
|
||||
page_file(stream);
|
||||
(void) fclose(stream);
|
||||
|
||||
/* unable to open help file */
|
||||
} else {
|
||||
fprintf(stderr, "unable to open help file: %s - %s\n",
|
||||
type, strerror(errno));
|
||||
}
|
||||
free(cust_helppath);
|
||||
cust_helppath = NULL;
|
||||
|
||||
#else /* CUSTOM */
|
||||
/* unable to open help file */
|
||||
} else {
|
||||
fprintf(stderr, "unable to open help file: %s - %s\n",
|
||||
type, strerror(errno));
|
||||
#endif /* CUSTOM */
|
||||
}
|
||||
|
||||
|
@@ -356,7 +356,7 @@ BLT_HELP_FILES= ${BLT_HELP_FILES_3} ${BLT_HELP_FILES_5} \
|
||||
#
|
||||
# Please use:
|
||||
#
|
||||
# make detail_help_list
|
||||
# make clobber >/dev/null && make detail_help_list
|
||||
#
|
||||
# to keep this list in nice sorted order.
|
||||
#
|
||||
@@ -364,14 +364,15 @@ DETAIL_HELP= abs access acos acosh acot acoth acsc acsch address agd \
|
||||
append appr arg argv arrow asec asech asin asinh assign atan atan2 \
|
||||
atanh avg base base2 bernoulli bit blk blkcpy blkfree blocks bround \
|
||||
btrunc calc_tty calclevel calcpath catalan ceil cfappr cfsim char \
|
||||
cmdbuf cmp comb conj cos cosh cot coth count cp csc csch ctime delete \
|
||||
den dereference det digit digits display dp epsilon errcount errmax \
|
||||
errno error estr euler eval exp fact factor fclose fcnt feof ferror \
|
||||
fflush fgetc fgetfield fgetfile fgetline fgets fgetstr fib files floor \
|
||||
fopen forall fpathopen fprintf fputc fputs fputstr frac free \
|
||||
freebernoulli freeeuler freeglobals freeredc freestatics frem freopen \
|
||||
fscan fscanf fseek fsize ftell gcd gcdrem gd getenv hash head highbit \
|
||||
hmean hnrmod hypot ilog ilog10 ilog2 im indices inputlevel insert int \
|
||||
cmdbuf cmp comb conj cos cosh cot coth count cp csc csch ctime d2dm \
|
||||
d2dms d2g d2r delete den dereference det digit digits display dms2d dp \
|
||||
epsilon errcount errmax errno error estr euler eval exp fact factor \
|
||||
fclose fcnt feof ferror fflush fgetc fgetfield fgetfile fgetline fgets \
|
||||
fgetstr fib files floor fopen forall fpathopen fprintf fputc fputs \
|
||||
fputstr frac free freebernoulli freeeuler freeglobals freeredc \
|
||||
freestatics frem freopen fscan fscanf fseek fsize ftell g2d g2gm g2gms \
|
||||
g2r gcd gcdrem gd getenv gms2g h2hm h2hms hash head highbit hmean \
|
||||
hms2h hnrmod hypot ilog ilog10 ilog2 im indices inputlevel insert int \
|
||||
inverse iroot isalnum isalpha isassoc isatty isblk iscntrl isconfig \
|
||||
isdefined isdigit iserror iseven isfile isgraph ishash isident isint \
|
||||
islist islower ismat ismult isnull isnum isobj isobjtype isodd isprime \
|
||||
@@ -381,11 +382,11 @@ DETAIL_HELP= abs access acos acosh acot acoth acsc acsch address agd \
|
||||
matsum mattrace mattrans max memsize meq min minv mmin mne mod modify \
|
||||
name near newerror nextcand nextprime norm null num oldvalue ord param \
|
||||
perm pfact pi pix places pmod polar poly pop popcnt pound power \
|
||||
prevcand prevprime printf prompt protect ptest push putenv questions \
|
||||
quo quomod rand randbit random randombit randperm rcin rcmul rcout \
|
||||
rcpow rcsq re remove reverse rewind rm root round rsearch runtime \
|
||||
saveval scale scan scanf search sec sech seed segment select sgn sha1 \
|
||||
sin sinh size sizeof sleep sort sqrt srand srandom ssq stoponerror str \
|
||||
prevcand prevprime printf prompt protect ptest push putenv quo quomod \
|
||||
r2d r2g rand randbit random randombit randperm rcin rcmul rcout rcpow \
|
||||
rcsq re remove reverse rewind rm root round rsearch runtime saveval \
|
||||
scale scan scanf search sec sech seed segment select sgn sha1 sin sinh \
|
||||
size sizeof sleep sort sqrt srand srandom ssq stoponerror str \
|
||||
strcasecmp strcat strcmp strcpy strerror strlen strncasecmp strncmp \
|
||||
strncpy strpos strprintf strscan strscanf strtolower strtoupper substr \
|
||||
sum swap system systime tail tan tanh test time trunc usertime version \
|
||||
@@ -730,7 +731,7 @@ distlist: ${DISTLIST}
|
||||
if [ X"$$i" != X"/dev/null" ]; then \
|
||||
echo help/$$i; \
|
||||
fi; \
|
||||
done | LANG=C ${SORT}
|
||||
done | fgrep -v '.bak' | LANG=C ${SORT}
|
||||
|
||||
distdir:
|
||||
${Q} echo help
|
||||
|
@@ -44,6 +44,9 @@ DESCRIPTION
|
||||
"sci"
|
||||
"exp"
|
||||
|
||||
1000 "engineering" base 10 notation with exponent
|
||||
"eng" multiple of 3
|
||||
|
||||
For convenience, any non-integer value is assumed to mean base 10
|
||||
fractions and any integer >= 2^64 is assumed to mean base 10
|
||||
scientific notation.
|
||||
@@ -76,7 +79,7 @@ LINK LIBRARY
|
||||
int math_setmode(int newmode)
|
||||
|
||||
NOTE: newmode must be one of MODE_DEFAULT, MODE_FRAC, MODE_INT,
|
||||
MODE_REAL, MODE_EXP, MODE_HEX, MODE_OCTAL, MODE_BINARY
|
||||
MODE_REAL, MODE_EXP, MODE_ENG, MODE_HEX, MODE_OCTAL, MODE_BINARY
|
||||
|
||||
SEE ALSO
|
||||
base2, config, str
|
||||
|
@@ -50,6 +50,9 @@ DESCRIPTION
|
||||
"sci"
|
||||
"exp"
|
||||
|
||||
1000 "engineering" base 10 notation with exponent
|
||||
"eng" multiple of 3
|
||||
|
||||
0 "off" disable double base output
|
||||
|
||||
For convenience, any non-integer non-zero value is assumed to mean
|
||||
@@ -76,7 +79,7 @@ EXAMPLE
|
||||
10 /* 012 */
|
||||
; base2(16),
|
||||
; 131072
|
||||
131072 /* 0x20000 */
|
||||
131072 /* 0x20000 */
|
||||
; 2345
|
||||
2345 /* 0x929 */
|
||||
|
||||
@@ -87,13 +90,13 @@ LINK LIBRARY
|
||||
int math_setmode2(int newmode)
|
||||
|
||||
NOTE: newmode must be one of MODE_DEFAULT, MODE_FRAC, MODE_INT,
|
||||
MODE_REAL, MODE_EXP, MODE_HEX, MODE_OCTAL, MODE_BINARY,
|
||||
MODE_REAL, MODE_EXP, MODE_ENG, MODE_HEX, MODE_OCTAL, MODE_BINARY,
|
||||
MODE2_OFF
|
||||
|
||||
SEE ALSO
|
||||
base, config, str
|
||||
|
||||
## Copyright (C) 2002 Landon Curt Noll
|
||||
## Copyright (C) 2002,2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
|
17
help/config
17
help/config
@@ -165,8 +165,8 @@ DESCRIPTION
|
||||
config("display", int)
|
||||
|
||||
The "display" parameter specifies the maximum number of digits after
|
||||
the decimal point to be printed in real or exponential mode in
|
||||
normal unformatted printing (print, strprint, fprint) or in
|
||||
the decimal point to be printed in real, exponential or engineering
|
||||
mode in normal unformatted printing (print, strprint, fprint) or in
|
||||
formatted printing (printf, strprintf, fprintf) when precision is not
|
||||
specified. The initial value for oldstd is 20, for newstd 10.
|
||||
The parameter may be changed to the value d by either
|
||||
@@ -234,6 +234,9 @@ DESCRIPTION
|
||||
"sci"
|
||||
"exp"
|
||||
|
||||
"engineering" base 10 notation with exponent base(10e6)
|
||||
"eng" multiple of 3
|
||||
|
||||
Where multiple strings are given, the first string listed is what
|
||||
config("mode") will return.
|
||||
|
||||
@@ -863,10 +866,10 @@ DESCRIPTION
|
||||
when a variable name collides with an exist name of a higher scope.
|
||||
Examples of collisions are when:
|
||||
|
||||
* both local and static variables have the same name
|
||||
* both local and global variables have the same name
|
||||
* both function parameter and local variables have the same name
|
||||
* both function parameter and global variables have the same name
|
||||
* both local and static variables have the same name
|
||||
* both local and global variables have the same name
|
||||
* both function parameter and local variables have the same name
|
||||
* both function parameter and global variables have the same name
|
||||
|
||||
The initial "redecl_warn" value is 1.
|
||||
|
||||
@@ -892,7 +895,7 @@ EXAMPLE
|
||||
1
|
||||
|
||||
; config("version")
|
||||
"2.12.0"
|
||||
"2.12.0"
|
||||
|
||||
; config("all")
|
||||
mode "real"
|
||||
|
117
help/d2dm
Normal file
117
help/d2dm
Normal file
@@ -0,0 +1,117 @@
|
||||
NAME
|
||||
d2dm - convert degrees into degrees, and minutes
|
||||
|
||||
SYNOPSIS
|
||||
d2dm(degs, d, m [,rnd])
|
||||
|
||||
TYPES
|
||||
degs real
|
||||
d null-or-real-valued lvalue with assign-to permission
|
||||
m null-or-real-valued lvalue with assign-to permission
|
||||
rnd nonnegative integer, defaults to config("mod")
|
||||
|
||||
return mod(degs, 360, rnd)
|
||||
|
||||
DESCRIPTION
|
||||
Convert degs degrees into d degrees, and m minutes.
|
||||
|
||||
The return value is a normalized number of degrees, and is equivalent
|
||||
to the following:
|
||||
|
||||
return_value = mod(degs, 360, rnd);
|
||||
|
||||
The argument rnd, if not given, defaults to config("mod").
|
||||
For more information on the effects of rnd, see "help mod".
|
||||
|
||||
Depending on the rounding mode, the return could be a real value
|
||||
in the interval [0, 360) or a real value in the interval (-360, 0].
|
||||
For the default round mode, the return value is in the interval [0, 360).
|
||||
|
||||
The d argument will be an integer number of degrees.
|
||||
|
||||
The value d will be set as if the following were used:
|
||||
|
||||
d = int(return_value);
|
||||
|
||||
For some rounding modes, d will be an integer in the interval [0, 360).
|
||||
For other rounding modes, d will be an integer in the interval (-360, 0].
|
||||
For the default round mode, d is in the interval [0, 360).
|
||||
|
||||
The m argument will be a real number of minutes.
|
||||
|
||||
The value m will be set as if the following were used:
|
||||
|
||||
tmp = return_value - d;
|
||||
m = tmp * 60;
|
||||
free(tmp);
|
||||
|
||||
For some rounding modes, m will be a real value in the interval [0, 60).
|
||||
For other rounding modes, m will be a real value in the interval (-60, 0].
|
||||
For the default round mode, m will be in the interval [0, 60).
|
||||
|
||||
The following shows relationship between the return value and the resulting
|
||||
d, and m values:
|
||||
|
||||
return_value == d + m/60;
|
||||
|
||||
|
||||
EXAMPLE
|
||||
/* if args are undefined, pre-declare them or assign them as args */
|
||||
|
||||
; global d, m;
|
||||
|
||||
; print d2dm(12.3456,d,m), d, m;
|
||||
12.3456 12 20.736
|
||||
; print d2dm(1234.5678,d,m), d, m;
|
||||
154.5678 154 34.068
|
||||
; print d2dm(-1234.5678,d,m), d, m;
|
||||
205.4322 205 25.932
|
||||
|
||||
; print d2dm(654.321,deg=,min=), deg, min;
|
||||
294.321 294 19.26
|
||||
; print d2dm(-654.321,deg=,min=), deg, min;
|
||||
65.679 65 40.74
|
||||
; print d2dm(360.321,deg=,min=), deg, min;
|
||||
0.321 0 19.26
|
||||
|
||||
/* certain non-default rounding modes can return negative values */
|
||||
|
||||
; print d2dm(654.321,deg=,min=,1), deg, min;
|
||||
-65.679 -65 -40.74
|
||||
; print d2dm(-654.321,deg=,min=,1), deg, min;
|
||||
-294.321 -294 -19.26
|
||||
; print d2dm(360.321,deg=,min=,1), deg, min;
|
||||
-359.679 -359 -40.74
|
||||
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
config, d2dms, dm2d, dms2d, g2gm, g2gms, gm2g, gms2g,
|
||||
h2hm, h2hms, hm2d, hms2d, mod
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/25 17:24:51
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
132
help/d2dms
Normal file
132
help/d2dms
Normal file
@@ -0,0 +1,132 @@
|
||||
NAME
|
||||
d2dms - convert degrees into degrees, minutes, and seconds
|
||||
|
||||
SYNOPSIS
|
||||
d2dms(degs, d, m, s [,rnd])
|
||||
|
||||
TYPES
|
||||
degs real
|
||||
d null-or-real-valued lvalue with assign-to permission
|
||||
m null-or-real-valued lvalue with assign-to permission
|
||||
s null-or-real-valued lvalue with assign-to permission
|
||||
rnd nonnegative integer, defaults to config("mod")
|
||||
|
||||
return mod(degs, 360, rnd)
|
||||
|
||||
DESCRIPTION
|
||||
Convert degs degrees into d degrees, m minutes, and s seconds.
|
||||
|
||||
The return value is a normalized number of degrees, and is equivalent
|
||||
to the following:
|
||||
|
||||
return_value = mod(degs, 360, rnd);
|
||||
|
||||
The argument rnd, if not given, defaults to config("mod").
|
||||
For more information on the effects of rnd, see "help mod".
|
||||
|
||||
Depending on the rounding mode, the return could be a real value
|
||||
in the interval [0, 360) or a real value in the interval (-360, 0].
|
||||
For the default round mode, the return value is in the interval [0, 360).
|
||||
|
||||
The d argument will be an integer number of degrees.
|
||||
|
||||
The value d will be set as if the following were used:
|
||||
|
||||
d = int(return_value);
|
||||
|
||||
For some rounding modes, d will be an integer in the interval [0, 360).
|
||||
For other rounding modes, d will be an integer in the interval (-360, 0].
|
||||
For the default round mode, d is in the interval [0, 360).
|
||||
|
||||
The m argument will be an integer number of minutes.
|
||||
|
||||
The value m will be set as if the following were used:
|
||||
|
||||
tmp = return_value - d;
|
||||
tmp_m = tmp * 60;
|
||||
free(tmp);
|
||||
m = int(tmp_m);
|
||||
|
||||
For some rounding modes, m will be an integer in the interval [0, 60).
|
||||
For other rounding modes, m will be an integer in the interval (-60, 0].
|
||||
For the default round mode, m will be in the interval [0, 60).
|
||||
|
||||
The s argument will be a real number of seconds.
|
||||
|
||||
The value s will be set as if the following were used:
|
||||
|
||||
tmp = tmp_m - m;
|
||||
free(tmp_m);
|
||||
s = tmp * 60;
|
||||
free(tmp);
|
||||
|
||||
For some rounding modes, s will be a real value in the interval [0, 60).
|
||||
For other rounding modes, s will be a real value in the interval (-60, 0].
|
||||
For the default round mode, s will be in the interval [0, 60).
|
||||
|
||||
The following shows relationship between the return value and the resulting
|
||||
d, m, and s values:
|
||||
|
||||
return_value == d + m/60 + s/3600;
|
||||
|
||||
|
||||
EXAMPLE
|
||||
/* if args are undefined, pre-declare them or assign them as args */
|
||||
|
||||
; global d, m, s;
|
||||
|
||||
; print d2dms(12.3456,d,m,s), d, m, s;
|
||||
12.3456 12 20 44.16
|
||||
; print d2dms(1234.5678,d,m,s), d, m, s;
|
||||
154.5678 154 34 4.08
|
||||
; print d2dms(-1234.5678,d,m,s), d, m, s;
|
||||
205.4322 205 25 55.92
|
||||
|
||||
; print d2dms(654.321,deg=,min=,sec=), deg, min, sec;
|
||||
294.321, 294, 19, 15.6
|
||||
; print d2dms(-654.321,deg=,min=,sec=), deg, min, sec;
|
||||
65.679 65 40 44.4
|
||||
; print d2dms(360.321,deg=,min=,sec=), deg, min, sec;
|
||||
0.321 0 19 15.6
|
||||
|
||||
/* certain non-default rounding modes can return negative values */
|
||||
|
||||
; print d2dms(654.321,deg=,min=,sec=,1), deg, min, sec;
|
||||
-65.679 -65 -40 -44.4
|
||||
; print d2dms(-654.321,deg=,min=,sec=,1), deg, min, sec;
|
||||
-294.321 -294 -19 -15.6
|
||||
; print d2dms(360.321,deg=,min=,sec=,1), deg, min, sec;
|
||||
-359.679 -359 -40 -44.4
|
||||
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
config, d2dm, dm2d, dms2d, g2gm, g2gms, gm2g, gms2g,
|
||||
h2hm, h2hms, hm2d, hms2d, mod
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/25 17:24:51
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
55
help/d2g
Normal file
55
help/d2g
Normal file
@@ -0,0 +1,55 @@
|
||||
NAME
|
||||
d2g - convert degrees to gradians
|
||||
|
||||
SYNOPSIS
|
||||
d2g(x [,eps])
|
||||
|
||||
TYPES
|
||||
x number (real or complex)
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return number
|
||||
|
||||
DESCRIPTION
|
||||
Given x degrees, return the equivalent number of gradians.
|
||||
|
||||
The eps argument is ignored.
|
||||
|
||||
EXAMPLE
|
||||
; print d2g(45), d2g(180), d2g(30)
|
||||
50 200 ~33.33333333333333333333
|
||||
|
||||
; print d2g(3i+2)
|
||||
~2.22222222222222222222+~3.33333333333333333333i
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
d2r, r2d, g2r, r2g, g2d,
|
||||
sin, cos, tan, sec, csc, cot, epsilon
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/07 12:04:28
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
59
help/d2r
Normal file
59
help/d2r
Normal file
@@ -0,0 +1,59 @@
|
||||
NAME
|
||||
d2r - convert degrees to radians
|
||||
|
||||
SYNOPSIS
|
||||
d2r(x [,eps])
|
||||
|
||||
TYPES
|
||||
x number (real or complex)
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return number
|
||||
|
||||
DESCRIPTION
|
||||
Given x degrees, return the equivalent number of radians.
|
||||
|
||||
The eps controls the precision of the calculated internal
|
||||
constant pi / 180.
|
||||
|
||||
EXAMPLE
|
||||
; print d2r(45), d2r(180), d2r(30)
|
||||
~0.78539816339744830962 3.14159265358979323846 ~0.52359877559829887308
|
||||
|
||||
; print d2r(3i+2)
|
||||
~0.03490658503988659154+~0.05235987755982988731i
|
||||
|
||||
; print sin(d2r(30)), cos(d2r(60)), tan(d2r(45))
|
||||
0.5 0.5 1
|
||||
|
||||
LIMITS
|
||||
eps > 0
|
||||
|
||||
LINK LIBRARY
|
||||
NUMBER *qpidiv180(NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
r2d, g2r, r2g, d2g, g2d,
|
||||
sin, cos, tan, sec, csc, cot, epsilon
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/07 12:04:28
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
@@ -73,8 +73,8 @@ EXAMPLE
|
||||
; for (n = 6; n >= -6; n--) print digit(a, n, 256),; print
|
||||
0 0 0 0 1 226 64 201 251 231 108 139 67
|
||||
|
||||
; for (n = 1; n >= -12; n++) print digit(10/7, n),; print
|
||||
; 0 1 4 2 8 5 7 1 4 2 8 5 7 1
|
||||
; for (n = 1; n >= -12; n++) print digit(10/7, n),; print
|
||||
; 0 1 4 2 8 5 7 1 4 2 8 5 7 1
|
||||
|
||||
; print digit(10/7, -7e1000, 1e6)
|
||||
428571
|
||||
@@ -92,7 +92,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
bit
|
||||
|
||||
## Copyright (C) 1999-2006 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006,2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
|
@@ -21,7 +21,7 @@ DESCRIPTION
|
||||
|
||||
The builtin function:
|
||||
|
||||
display(d)
|
||||
display(d)
|
||||
display()
|
||||
|
||||
is an alias for:
|
||||
@@ -96,7 +96,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
config, epsilon, fprintf, printf, strprintf
|
||||
|
||||
## Copyright (C) 2004,2018 Landon Curt Noll
|
||||
## Copyright (C) 2004,2018,2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
|
84
help/dms2d
Normal file
84
help/dms2d
Normal file
@@ -0,0 +1,84 @@
|
||||
NAME
|
||||
dm2d, dms2d - convert degrees, minutes, and seconds to degrees
|
||||
|
||||
SYNOPSIS
|
||||
dm2d(d, m [,rnd])
|
||||
dms2d(d, m, s [,rnd])
|
||||
|
||||
TYPES
|
||||
d real
|
||||
m real
|
||||
s real (defauls to 0)
|
||||
rnd nonnegative integer, defaults to config("mod")
|
||||
|
||||
return degrees
|
||||
|
||||
DESCRIPTION
|
||||
Convert degrees, m minutes, and s seconds returning degrees.
|
||||
|
||||
The return value in degrees, is quivalent to the following:
|
||||
|
||||
mod(d + m/60 + s/3600, 360, rnd);
|
||||
|
||||
Depending on the rounding mode, the return could be a real value
|
||||
in the interval [0, 360) or a real value in the interval (-360, 0].
|
||||
For the default round mode, the return value is in the interval [0, 360).
|
||||
|
||||
A missing rnd defaults to config("mod").
|
||||
For more information on the effects of rnd, see "help mod".
|
||||
|
||||
The dm2d(d, m, rnd) builtin is an alias for dms2d(d, m, 0, rnd).
|
||||
|
||||
|
||||
EXAMPLE
|
||||
; print dm2d(203, 325.5594);
|
||||
208.42599
|
||||
; print dm2d(3601, -25.5594);
|
||||
0.57401
|
||||
; print dm2d(-923, -25.5594);
|
||||
156.57401
|
||||
|
||||
; print dms2d(12, 20, 44.16);
|
||||
12.3456
|
||||
; print dms2d(123.456, -345.68, 4.08);
|
||||
117.6958
|
||||
; print dms2d(-65, -40, -44.4);
|
||||
294.321
|
||||
|
||||
; print dm2d(203, 325.5594, 1);
|
||||
-151.57401
|
||||
; print dms2d(12, 20, 44.16, 1);
|
||||
-347.6544
|
||||
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
config, d2dm, d2dms, dm2d, dms2d, g2gm, g2gms, gm2g, gms2g,
|
||||
h2hm, h2hms, hm2d, hms2d, mod
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/25 17:24:51
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
@@ -38,7 +38,7 @@ DESCRIPTION
|
||||
|
||||
(*) NOTE on 'b' / binary/text mode:
|
||||
|
||||
The 'b' or fopen binary mode has no effect on POSIX / Linux
|
||||
The 'b' or fopen binary mode has no effect on POSIX / Linux
|
||||
/ Un*x-like systems. On those systems a text file is the
|
||||
same as a binary file (as it should be for any modern-day
|
||||
operating system). Adding 'b' to an fopen has no effect
|
||||
@@ -52,9 +52,9 @@ DESCRIPTION
|
||||
Names of files are subject to ~ expansion just like the C or
|
||||
Korn shell. For example, the file name:
|
||||
|
||||
~/lib/gleet
|
||||
~/lib/fizzbin
|
||||
|
||||
refers to the file 'gleet' under the directory lib located
|
||||
refers to the file 'fizzbin' under the directory lib located
|
||||
in your home directory. The file name:
|
||||
|
||||
~chongo/was_here
|
||||
@@ -107,7 +107,7 @@ SEE ALSO
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt,
|
||||
fpathopen, strerror
|
||||
|
||||
## Copyright (C) 1999-2006 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006,2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
|
@@ -21,7 +21,7 @@ DESCRIPTION
|
||||
Absolute filenames, and filenames with an implied path are files
|
||||
that begin with:
|
||||
|
||||
/ # absolute path
|
||||
/ # absolute path
|
||||
./ # implied path through the current working directory
|
||||
../ # implied path through the current working directory parent
|
||||
~ # absolute path going through a home directory
|
||||
@@ -29,12 +29,12 @@ DESCRIPTION
|
||||
A search path is a :-separated list of directories used to search for
|
||||
a filename. For example:
|
||||
|
||||
fpathopen("whey", "r", ".:/tmp:/var/tmp:~chongo/pub:~/tmp");
|
||||
fpathopen("whey", "r", ".:/tmp:/var/tmp:~chongo/pub:~/tmp");
|
||||
|
||||
will cause this function to open the first readable file it
|
||||
files while searching through these paths in order:
|
||||
|
||||
./whey
|
||||
./whey
|
||||
/tmp/whey
|
||||
/var/tmp/whey
|
||||
~chongo/pub/whey
|
||||
@@ -46,16 +46,16 @@ DESCRIPTION
|
||||
to open files under the given mode. If the mode allows for
|
||||
writing and a file can be created, then that file is returned.
|
||||
|
||||
This call open "./gleet" for writing if the current directory is
|
||||
writable, even if "./gleet" did not previously exist:
|
||||
This call open "./fizzbin" for writing if the current directory is
|
||||
writable, even if "./fizzbin" did not previously exist:
|
||||
|
||||
fpathopen("gleet", "r", ".:/tmp:/var/tmp:~chongo/pub:~/tmp");
|
||||
fpathopen("fizzbin", "r", ".:/tmp:/var/tmp:~chongo/pub:~/tmp");
|
||||
|
||||
This call will likely open (and create if needded) for appending,
|
||||
the file "/tmp/log" assuming that the user is not allowed to
|
||||
create files in the previous system directories:
|
||||
|
||||
fpathopen("log", "a", "/:/etc:/bin:/usr/bin:/tmp");
|
||||
fpathopen("log", "a", "/:/etc:/bin:/usr/bin:/tmp");
|
||||
|
||||
The CALCPATH search path is taken from the $CALCPATH environment
|
||||
variable or if no such variable exists, a compiled in default search
|
||||
@@ -92,7 +92,7 @@ DESCRIPTION
|
||||
|
||||
(*) NOTE on 'b' / binary/text mode:
|
||||
|
||||
The 'b' or fopen binary mode has no effect on POSIX / Linux
|
||||
The 'b' or fopen binary mode has no effect on POSIX / Linux
|
||||
/ Un*x-like systems. On those systems a text file is the
|
||||
same as a binary file (as it should be for any modern-day
|
||||
operating system). Adding 'b' to an fopen has no effect
|
||||
@@ -106,9 +106,9 @@ DESCRIPTION
|
||||
Names of files are subject to ~ expansion just like the C or
|
||||
Korn shell. For example, the file name:
|
||||
|
||||
~/lib/gleet
|
||||
~/lib/fizbin
|
||||
|
||||
refers to the file 'gleet' under the directory lib located
|
||||
refers to the file 'fizbin' under the directory lib located
|
||||
in your home directory. The file name:
|
||||
|
||||
~chongo/was_here
|
||||
@@ -180,7 +180,7 @@ SEE ALSO
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt,
|
||||
environment, calcpath
|
||||
|
||||
## Copyright (C) 2006 Landon Curt Noll
|
||||
## Copyright (C) 2006,2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
|
55
help/g2d
Normal file
55
help/g2d
Normal file
@@ -0,0 +1,55 @@
|
||||
NAME
|
||||
g2d - convert gradians to degrees
|
||||
|
||||
SYNOPSIS
|
||||
g2d(x [,eps])
|
||||
|
||||
TYPES
|
||||
x number (real or complex)
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return number
|
||||
|
||||
DESCRIPTION
|
||||
Given x gradians, return the equivalent number of degrees.
|
||||
|
||||
The eps argument is ignored.
|
||||
|
||||
EXAMPLE
|
||||
; print g2d(50), g2d(200), g2d(30)
|
||||
45 180 27
|
||||
|
||||
; print g2d(3i+2)
|
||||
1.8+2.7i
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
d2r, r2d, g2r, r2g, d2g,
|
||||
sin, cos, tan, sec, csc, cot, epsilon
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/07 12:04:28
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
117
help/g2gm
Normal file
117
help/g2gm
Normal file
@@ -0,0 +1,117 @@
|
||||
NAME
|
||||
g2gm - convert gradians into gradians, and minutes
|
||||
|
||||
SYNOPSIS
|
||||
g2gm(grads, g, m [,rnd])
|
||||
|
||||
TYPES
|
||||
grads real
|
||||
g null-or-real-valued lvalue with assign-to permission
|
||||
m null-or-real-valued lvalue with assign-to permission
|
||||
rnd nonnegative integer, defaults to config("mod")
|
||||
|
||||
return mod(grads, 400, rnd)
|
||||
|
||||
DESCRIPTION
|
||||
Convert grads gradians into g gradians, and m minutes.
|
||||
|
||||
The return value is a normalized number of gradians, and is equivalent
|
||||
to the following:
|
||||
|
||||
return_value = mod(grads, 400, rnd);
|
||||
|
||||
The argument rnd, if not given, defaults to config("mod").
|
||||
For more information on the effects of rnd, see "help mod".
|
||||
|
||||
Depending on the rounding mode, the return could be a real value
|
||||
in the interval [0, 400) or a real value in the interval (-400, 0].
|
||||
For the default round mode, the return value is in the interval [0, 400).
|
||||
|
||||
The g argument will be an integer number of gradians.
|
||||
|
||||
The value g will be set as if the following were used:
|
||||
|
||||
g = int(return_value);
|
||||
|
||||
For some rounding modes, g will be an integer in the interval [0, 400).
|
||||
For other rounding modes, g will be an integer in the interval (-400, 0].
|
||||
For the default round mode, g is in the interval [0, 400).
|
||||
|
||||
The m argument will be a real number of minutes.
|
||||
|
||||
The value m will be set as if the following were used:
|
||||
|
||||
tmp = return_value - g;
|
||||
m = tmp * 60;
|
||||
free(tmp);
|
||||
|
||||
For some rounding modes, m will be a real value in the interval [0, 60).
|
||||
For other rounding modes, m will be a real value in the interval (-60, 0].
|
||||
For the default round mode, m will be in the interval [0, 60).
|
||||
|
||||
The following shows relationship between the return value and the resulting
|
||||
g, and m values:
|
||||
|
||||
return_value == g + m/60;
|
||||
|
||||
|
||||
EXAMPLE
|
||||
/* if args are undefined, pre-declare them or assign them as args */
|
||||
|
||||
; global g, m;
|
||||
|
||||
; print g2gm(12.3456,g,m), g, m;
|
||||
12.3456 12 20.736
|
||||
; print g2gm(1234.5678,g,m), g, m;
|
||||
34.5678 34 34.068
|
||||
; print g2gm(-1234.5678,g,m), g, m;
|
||||
365.4322 365 25.932
|
||||
|
||||
; print g2gm(654.321,grad=,min=), grad, min;
|
||||
254.321 254 19.26
|
||||
; print g2gm(-654.321,grad=,min=), grad, min;
|
||||
145.679 145 40.74
|
||||
; print g2gm(400.321,grad=,min=), grad, min;
|
||||
0.321 0 19.26
|
||||
|
||||
/* certain non-default rounding modes can return negative values */
|
||||
|
||||
; print g2gm(654.321,grad=,min=,1), grad, min;
|
||||
-145.679 -145 -40.74
|
||||
; print g2gm(-654.321,grad=,min=,1), grad, min;
|
||||
-254.321 -254 -19.26
|
||||
; print g2gm(400.321,grad=,min=,1), grad, min;
|
||||
-399.679 -399 -40.74
|
||||
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
config, d2dm, d2dms, dm2d, dms2d, g2gms, gm2g, gms2g,
|
||||
h2hm, h2hms, hm2d, hms2d, mod
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/25 17:24:51
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
132
help/g2gms
Normal file
132
help/g2gms
Normal file
@@ -0,0 +1,132 @@
|
||||
NAME
|
||||
g2gms - convert gradians into gradians, minutes, and seconds
|
||||
|
||||
SYNOPSIS
|
||||
g2gms(grads, g, m, s [,rnd])
|
||||
|
||||
TYPES
|
||||
grads real
|
||||
g null-or-real-valued lvalue with assign-to permission
|
||||
m null-or-real-valued lvalue with assign-to permission
|
||||
s null-or-real-valued lvalue with assign-to permission
|
||||
rnd nonnegative integer, defaults to config("mod")
|
||||
|
||||
return mod(grads, 400, rnd)
|
||||
|
||||
DESCRIPTION
|
||||
Convert grads gradians into g gradians, m minutes, and s seconds.
|
||||
|
||||
The return value is a normalized number of gradians, and is equivalent
|
||||
to the following:
|
||||
|
||||
return_value = mod(grads, 400, rnd);
|
||||
|
||||
The argument rnd, if not given, defaults to config("mod").
|
||||
For more information on the effects of rnd, see "help mod".
|
||||
|
||||
Depending on the rounding mode, the return could be a real value
|
||||
in the interval [0, 400) or a real value in the interval (-400, 0].
|
||||
For the default round mode, the return value is in the interval [0, 400).
|
||||
|
||||
The g argument will be an integer number of gradians.
|
||||
|
||||
The value g will be set as if the following were used:
|
||||
|
||||
g = int(return_value);
|
||||
|
||||
For some rounding modes, g will be an integer in the interval [0, 400).
|
||||
For other rounding modes, g will be an integer in the interval (-400, 0].
|
||||
For the default round mode, g is in the interval [0, 400).
|
||||
|
||||
The m argument will be an integer number of minutes.
|
||||
|
||||
The value m will be set as if the following were used:
|
||||
|
||||
tmp = return_value - g;
|
||||
tmp_m = tmp * 60;
|
||||
free(tmp);
|
||||
m = int(tmp_m);
|
||||
|
||||
For some rounding modes, m will be an integer in the interval [0, 60).
|
||||
For other rounding modes, m will be an integer in the interval (-60, 0].
|
||||
For the default round mode, m will be in the interval [0, 60).
|
||||
|
||||
The s argument will be a real number of seconds.
|
||||
|
||||
The value s will be set as if the following were used:
|
||||
|
||||
tmp = tmp_m - m;
|
||||
free(tmp_m);
|
||||
s = tmp * 60;
|
||||
free(tmp);
|
||||
|
||||
For some rounding modes, s will be a real value in the interval [0, 60).
|
||||
For other rounding modes, s will be a real value in the interval (-60, 0].
|
||||
For the default round mode, s will be in the interval [0, 60).
|
||||
|
||||
The following shows relationship between the return value and the resulting
|
||||
g, m, and s values:
|
||||
|
||||
return_value == g + m/60 + s/3600;
|
||||
|
||||
|
||||
EXAMPLE
|
||||
/* if args are undefined, pre-declare them or assign them as args */
|
||||
|
||||
; global g, m, s;
|
||||
|
||||
; print g2gms(12.3456,g,m,s), g, m, s;
|
||||
12.3456 12 20 44.16
|
||||
; print g2gms(1234.5678,g,m,s), g, m, s;
|
||||
34.5678 34 34 4.08
|
||||
; print g2gms(-1234.5678,g,m,s), g, m, s;
|
||||
365.4322 365 25 55.92
|
||||
|
||||
; print g2gms(654.321,grad=,min=,sec=), grad, min, sec;
|
||||
254.321 254 19 15.6
|
||||
; print g2gms(-654.321,grad=,min=,sec=), grad, min, sec;
|
||||
145.679 145 40 44.4
|
||||
; print g2gms(400.321,grad=,min=,sec=), grad, min, sec;
|
||||
0.321 0 19 15.6
|
||||
|
||||
/* certain non-default rounding modes can return negative values */
|
||||
|
||||
; print g2gms(654.321,grad=,min=,sec=,1), grad, min, sec;
|
||||
-145.679 -145 -40 -44.4
|
||||
; print g2gms(-654.321,grad=,min=,sec=,1), grad, min, sec;
|
||||
-254.321 -254 -19 -15.6
|
||||
; print g2gms(400.321,grad=,min=,sec=,1), grad, min, sec;
|
||||
-399.679 -399 -40 -44.4
|
||||
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
config, d2dm, d2dms, dm2d, dms2d, g2gm, gm2g, gms2g,
|
||||
h2hm, h2hms, hm2d, hms2d, mod
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/25 17:24:51
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
59
help/g2r
Normal file
59
help/g2r
Normal file
@@ -0,0 +1,59 @@
|
||||
NAME
|
||||
g2r - convert gradians to radians
|
||||
|
||||
SYNOPSIS
|
||||
g2r(x [,eps])
|
||||
|
||||
TYPES
|
||||
x number (real or complex)
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return number
|
||||
|
||||
DESCRIPTION
|
||||
Given x gradians, return the equivalent number of radians.
|
||||
|
||||
The eps controls the precision of the calculated internal
|
||||
constant pi / 200.
|
||||
|
||||
EXAMPLE
|
||||
; print g2r(50), g2r(200), g2r(50)
|
||||
~0.78539816339744830962 3.14159265358979323846 ~0.78539816339744830962
|
||||
|
||||
; print g2r(3i+2)
|
||||
~0.03141592653589793238+~0.04712388980384689858i
|
||||
|
||||
; print sin(g2r(100/3)), cos(g2r(200/3)), tan(g2r(50))
|
||||
0.5 0.5 1
|
||||
|
||||
LIMITS
|
||||
eps > 0
|
||||
|
||||
LINK LIBRARY
|
||||
NUMBER *qpidiv200(NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
d2r, r2d, r2g, d2g, g2d,
|
||||
sin, cos, tan, sec, csc, cot, epsilon
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/07 12:04:28
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
84
help/gms2g
Normal file
84
help/gms2g
Normal file
@@ -0,0 +1,84 @@
|
||||
NAME
|
||||
gm2g, gms2g - convert gradians, minutes, and seconds to gradians
|
||||
|
||||
SYNOPSIS
|
||||
gm2g(d, m [,rnd])
|
||||
gms2g(d, m, s [,rnd])
|
||||
|
||||
TYPES
|
||||
d real
|
||||
m real
|
||||
s real (defauls to 0)
|
||||
rnd nonnegative integer, defaults to config("mod")
|
||||
|
||||
return gradians
|
||||
|
||||
DESCRIPTION
|
||||
Convert gradians, m minutes, and s seconds returning gradians.
|
||||
|
||||
The return value in gradians, is quivalent to the following:
|
||||
|
||||
mod(d + m/60 + s/4000, 400, rnd);
|
||||
|
||||
Depending on the rounding mode, the return could be a real value
|
||||
in the interval [0, 400) or a real value in the interval (-400, 0].
|
||||
For the default round mode, the return value is in the interval [0, 400).
|
||||
|
||||
A missing rnd defaults to config("mod").
|
||||
For more information on the effects of rnd, see "help mod".
|
||||
|
||||
The gm2g(d, m, rnd) builtin is an alias for gms2g(d, m, 0, rnd).
|
||||
|
||||
|
||||
EXAMPLE
|
||||
; print gm2g(203, 325.5594);
|
||||
208.42599
|
||||
; print gm2g(4001, -25.5594);
|
||||
0.57401
|
||||
; print gm2g(-923, -25.5594);
|
||||
276.57401
|
||||
|
||||
; print gms2g(12, 20, 44.16);
|
||||
12.3456
|
||||
; print gms2g(123.456, -345.68, 4.08);
|
||||
117.6958
|
||||
; print gms2g(-65, -40, -44.4);
|
||||
334.321
|
||||
|
||||
; print gm2g(203, 325.5594, 1);
|
||||
-191.57401
|
||||
; print gms2g(12, 20, 44.16, 1);
|
||||
-387.6544
|
||||
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
config, d2dm, d2dms, dm2d, dms2d, g2gm, g2gms, gm2g, gms2g,
|
||||
h2hm, h2hms, hm2d, hms2d, mod
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/25 17:24:51
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
117
help/h2hm
Normal file
117
help/h2hm
Normal file
@@ -0,0 +1,117 @@
|
||||
NAME
|
||||
h2hm - convert hours into hours, and minutes
|
||||
|
||||
SYNOPSIS
|
||||
h2hm(hours, h, m [,rnd])
|
||||
|
||||
TYPES
|
||||
hours real
|
||||
h null-or-real-valued lvalue with assign-to permission
|
||||
m null-or-real-valued lvalue with assign-to permission
|
||||
rnd nonnegative integer, defaults to config("mod")
|
||||
|
||||
return mod(hours, 24, rnd)
|
||||
|
||||
DESCRIPTION
|
||||
Convert hours hours into h hours, and m minutes.
|
||||
|
||||
The return value is a normalized number of hours, and is equivalent
|
||||
to the following:
|
||||
|
||||
return_value = mod(hours, 24, rnd);
|
||||
|
||||
The argument rnd, if not given, defaults to config("mod").
|
||||
For more information on the effects of rnd, see "help mod".
|
||||
|
||||
Depending on the rounding mode, the return could be a real value
|
||||
in the interval [0, 24) or a real value in the interval (-24, 0].
|
||||
For the default round mode, the return value is in the interval [0, 24).
|
||||
|
||||
The h argument will be an integer number of hours.
|
||||
|
||||
The value h will be set as if the following were used:
|
||||
|
||||
h = int(return_value);
|
||||
|
||||
For some rounding modes, h will be an integer in the interval [0, 24).
|
||||
For other rounding modes, h will be an integer in the interval (-24, 0].
|
||||
For the default round mode, h is in the interval [0, 24).
|
||||
|
||||
The m argument will be a real number of minutes.
|
||||
|
||||
The value m will be set as if the following were used:
|
||||
|
||||
tmp = return_value - h;
|
||||
m = tmp * 60;
|
||||
free(tmp);
|
||||
|
||||
For some rounding modes, m will be a real value in the interval [0, 60).
|
||||
For other rounding modes, m will be a real value in the interval (-60, 0].
|
||||
For the default round mode, m will be in the interval [0, 60).
|
||||
|
||||
The following shows relationship between the return value and the resulting
|
||||
h, and m values:
|
||||
|
||||
return_value == h + m/60;
|
||||
|
||||
|
||||
EXAMPLE
|
||||
/* if args are undefined, pre-declare them or assign them as args */
|
||||
|
||||
; global h, m;
|
||||
|
||||
; print h2hm(12.3456,h,m), h, m;
|
||||
12.3456 12 20.736
|
||||
; print h2hm(1234.5678,h,m), h, m;
|
||||
10.5678 10 34.068
|
||||
; print h2hm(-1234.5678,h,m), h, m;
|
||||
13.4322 13 25.932
|
||||
|
||||
; print h2hm(654.321,hour=,min=), hour, min;
|
||||
6.321 6 19.26
|
||||
; print h2hm(-654.321,hour=,min=), hour, min;
|
||||
17.679 17 40.74
|
||||
; print h2hm(24.321,hour=,min=), hour, min;
|
||||
0.321 0 19.26
|
||||
|
||||
/* certain non-default rounding modes can return negative values */
|
||||
|
||||
; print h2hm(654.321,hour=,min=,1), hour, min;
|
||||
-17.679 -17 -40.74
|
||||
; print h2hm(-654.321,hour=,min=,1), hour, min;
|
||||
-6.321 -6 -19.26
|
||||
; print h2hm(24.321,hour=,min=,1), hour, min;
|
||||
-23.679 -23 -40.7
|
||||
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
config, d2dm, d2dms, dm2d, dms2d, g2gm, g2gms, gm2g, gms2g,
|
||||
h2hms, hm2d, hms2d, mod
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/25 17:24:51
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
132
help/h2hms
Normal file
132
help/h2hms
Normal file
@@ -0,0 +1,132 @@
|
||||
NAME
|
||||
h2hms - convert hours into hours, minutes, and seconds
|
||||
|
||||
SYNOPSIS
|
||||
h2hms(hours, h, m, s [,rnd])
|
||||
|
||||
TYPES
|
||||
hours real
|
||||
h null-or-real-valued lvalue with assign-to permission
|
||||
m null-or-real-valued lvalue with assign-to permission
|
||||
s null-or-real-valued lvalue with assign-to permission
|
||||
rnd nonnegative integer, defaults to config("mod")
|
||||
|
||||
return mod(hours, 24, rnd)
|
||||
|
||||
DESCRIPTION
|
||||
Convert hours hours into h hours, m minutes, and s seconds.
|
||||
|
||||
The return value is a normalized number of hours, and is equivalent
|
||||
to the following:
|
||||
|
||||
return_value = mod(hours, 24, rnd);
|
||||
|
||||
The argument rnd, if not given, defaults to config("mod").
|
||||
For more information on the effects of rnd, see "help mod".
|
||||
|
||||
Depending on the rounding mode, the return could be a real value
|
||||
in the interval [0, 24) or a real value in the interval (-24, 0].
|
||||
For the default round mode, the return value is in the interval [0, 24).
|
||||
|
||||
The h argument will be an integer number of hours.
|
||||
|
||||
The value h will be set as if the following were used:
|
||||
|
||||
h = int(return_value);
|
||||
|
||||
For some rounding modes, h will be an integer in the interval [0, 24).
|
||||
For other rounding modes, h will be an integer in the interval (-24, 0].
|
||||
For the default round mode, h is in the interval [0, 24).
|
||||
|
||||
The m argument will be an integer number of minutes.
|
||||
|
||||
The value m will be set as if the following were used:
|
||||
|
||||
tmp = return_value - h;
|
||||
tmp_m = tmp * 60;
|
||||
free(tmp);
|
||||
m = int(tmp_m);
|
||||
|
||||
For some rounding modes, m will be an integer in the interval [0, 60).
|
||||
For other rounding modes, m will be an integer in the interval (-60, 0].
|
||||
For the default round mode, m will be in the interval [0, 60).
|
||||
|
||||
The s argument will be a real number of seconds.
|
||||
|
||||
The value s will be set as if the following were used:
|
||||
|
||||
tmp = tmp_m - m;
|
||||
free(tmp_m);
|
||||
s = tmp * 60;
|
||||
free(tmp);
|
||||
|
||||
For some rounding modes, s will be a real value in the interval [0, 60).
|
||||
For other rounding modes, s will be a real value in the interval (-60, 0].
|
||||
For the default round mode, s will be in the interval [0, 60).
|
||||
|
||||
The following shows relationship between the return value and the resulting
|
||||
h, m, and s values:
|
||||
|
||||
return_value == h + m/60 + s/3600;
|
||||
|
||||
|
||||
EXAMPLE
|
||||
/* if args are undefined, pre-declare them or assign them as args */
|
||||
|
||||
; global h, m, s;
|
||||
|
||||
; print h2hms(12.3456,h,m,s), h, m, s;
|
||||
12.3456 12 20 44.16
|
||||
; print h2hms(1234.5678,h,m,s), h, m, s;
|
||||
10.5678 10 34 4.08
|
||||
; print h2hms(-1234.5678,h,m,s), h, m, s;
|
||||
13.4322 13 25 55.92
|
||||
|
||||
; print h2hms(654.321,hour=,min=,sec=), hour, min, sec;
|
||||
6.321 6 19 15.6
|
||||
; print h2hms(-654.321,hour=,min=,sec=), hour, min, sec;
|
||||
17.679 17 40 44.4
|
||||
; print h2hms(24.321,hour=,min=,sec=), hour, min, sec;
|
||||
0.321 0 19 15.6
|
||||
|
||||
/* certain non-default rounding modes can return negative values */
|
||||
|
||||
; print h2hms(654.321,hour=,min=,sec=,1), hour, min, sec;
|
||||
-17.679 -17 -40 -44.4
|
||||
; print h2hms(-654.321,hour=,min=,sec=,1), hour, min, sec;
|
||||
-6.321 -6 -19 -15.6
|
||||
; print h2hms(24.321,hour=,min=,sec=,1), hour, min, sec;
|
||||
-23.679 -23 -40 -44.4
|
||||
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
config, d2dm, d2dms, dm2d, dms2d, g2gm, g2gms, gm2g, gms2g,
|
||||
h2hm, hm2d, hms2d, mod
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/25 17:24:51
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
@@ -18,7 +18,7 @@ DESCRIPTION
|
||||
takes into account more abstract concepts such as data types.
|
||||
|
||||
WARNING: Use of FNV-0 is NOT recommended for general purposes.
|
||||
Calc uses FNV-0 for internal objects such as associative
|
||||
Calc uses FNV-0 for internal objects such as associative
|
||||
arrays as well as other internal processes. Calc
|
||||
maintains the use of FNV-0 for backwards compatibility.
|
||||
|
||||
@@ -47,7 +47,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
ishash, fnv, sha1
|
||||
|
||||
## Copyright (C) 1999-2007,2014 Landon Curt Noll
|
||||
## Copyright (C) 1999-2007,2014,2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
|
84
help/hms2h
Normal file
84
help/hms2h
Normal file
@@ -0,0 +1,84 @@
|
||||
NAME
|
||||
hm2h, hms2h - convert hours, minutes, and seconds to hours
|
||||
|
||||
SYNOPSIS
|
||||
hm2h(h, m [,rnd])
|
||||
hms2h(h, m, s [,rnd])
|
||||
|
||||
TYPES
|
||||
h real
|
||||
m real
|
||||
s real (defauls to 0)
|
||||
rnd nonnegative integer, defaults to config("mod")
|
||||
|
||||
return hours
|
||||
|
||||
DESCRIPTION
|
||||
Convert hours, m minutes, and s seconds returning hours.
|
||||
|
||||
The return value in hours, is quivalent to the following:
|
||||
|
||||
mod(h + m/60 + s/3600, 24, rnd);
|
||||
|
||||
Depending on the rounding mode, the return could be a real value
|
||||
in the interval [0, 24) or a real value in the interval (-24, 0].
|
||||
For the default round mode, the return value is in the interval [0, 24).
|
||||
|
||||
A missing rnd defaults to config("mod").
|
||||
For more information on the effects of rnd, see "help mod".
|
||||
|
||||
The hm2h(h, m, rnd) builtin is an alias for hms2h(h, m, 0, rnd).
|
||||
|
||||
|
||||
EXAMPLE
|
||||
; print hm2h(203, 325.5594);
|
||||
16.42599
|
||||
; print hm2h(241, -25.5594);
|
||||
0.57401
|
||||
; print hm2h(-923, -25.5594);
|
||||
12.57401
|
||||
|
||||
; print hms2h(12, 20, 44.16);
|
||||
12.3456
|
||||
; print hms2h(123.456, -345.68, 4.08);
|
||||
21.6958
|
||||
; print hms2h(-65, -40, -44.4);
|
||||
6.321
|
||||
|
||||
; print hm2h(203, 325.5594, 1);
|
||||
-7.57401
|
||||
; print hms2h(12, 20, 44.16, 1);
|
||||
-11.6544
|
||||
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
config, d2dm, d2dms, dm2d, dms2d, g2gm, g2gms, gm2g, gms2g,
|
||||
h2hm, h2hms, hm2d, hms2d, mod
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/25 17:24:51
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
14
help/intro
14
help/intro
@@ -13,7 +13,7 @@ What is calc?
|
||||
|
||||
and the calculator will print:
|
||||
|
||||
15
|
||||
15
|
||||
|
||||
Calc has the usual collection of arithmetic operators +, -, /, *
|
||||
as well as ^ (exponentiation), % (modulus) and // (integer divide).
|
||||
@@ -27,7 +27,7 @@ What is calc?
|
||||
|
||||
Notice that calc values can be very large. For example:
|
||||
|
||||
2^23209-1
|
||||
2^23209-1
|
||||
|
||||
will print:
|
||||
|
||||
@@ -60,7 +60,7 @@ What is calc?
|
||||
|
||||
and the calculator prints:
|
||||
|
||||
13763753091226345046315979581580902400000000
|
||||
13763753091226345046315979581580902400000000
|
||||
|
||||
The calculator also knows about complex numbers, so that typing:
|
||||
|
||||
@@ -69,7 +69,7 @@ What is calc?
|
||||
|
||||
will print:
|
||||
|
||||
17+6i
|
||||
17+6i
|
||||
-55.50474777265624667147+193.9265235748927986537i
|
||||
|
||||
The calculator can calculate transcendental functions, and accept and
|
||||
@@ -81,19 +81,19 @@ What is calc?
|
||||
|
||||
prints:
|
||||
|
||||
0.8414709848078965066525023216302989996225630607983710656727517099919104
|
||||
0.8414709848078965066525023216302989996225630607983710656727517099919104
|
||||
|
||||
Calc can output values in terms of fractions, octal or hexadecimal.
|
||||
For example:
|
||||
|
||||
config("mode", "fraction"),
|
||||
config("mode", "fraction"),
|
||||
(17/19)^23
|
||||
base(16),
|
||||
(19/17)^29
|
||||
|
||||
will print:
|
||||
|
||||
19967568900859523802559065713/257829627945307727248226067259
|
||||
19967568900859523802559065713/257829627945307727248226067259
|
||||
0x9201e65bdbb801eaf403f657efcf863/0x5cd2e2a01291ffd73bee6aa7dcf7d1
|
||||
|
||||
All numbers are represented as fractions with arbitrarily large
|
||||
|
@@ -18,12 +18,12 @@ DESCRIPTION
|
||||
|
||||
Note that issq() works on rational values, so:
|
||||
|
||||
issq(25/16) == 1
|
||||
issq(25/16) == 1
|
||||
|
||||
If you want to test for prefect square integers, you need to exclude
|
||||
non-integer values before you test:
|
||||
|
||||
isint(curds) && issq(curds)
|
||||
isint(curds) && issq(curds)
|
||||
|
||||
EXAMPLE
|
||||
; print issq(25), issq(3), issq(0)
|
||||
@@ -45,7 +45,7 @@ SEE ALSO
|
||||
isobjtype, isodd, isprime, isrand, israndom, isreal, isrel,
|
||||
issimple, isstr, istype
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999,2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
|
@@ -17,8 +17,8 @@ DESCRIPTION
|
||||
If y is an odd prime, then the Legendre symbol (x/y) returns:
|
||||
|
||||
(x/y) == 0 x is divisible by y (0 == x % y)
|
||||
(x/y) == 1 if x is a quadratic residue modulo y
|
||||
(x/y) == -1 if x is not a quadratic residue modulo y
|
||||
(x/y) == 1 if x is a quadratic residue modulo y
|
||||
(x/y) == -1 if x is not a quadratic residue modulo y
|
||||
|
||||
Legendre symbol often denoted as (x/y) as if x/y were a fraction.
|
||||
|
||||
|
10
help/mod
10
help/mod
@@ -2,7 +2,7 @@ NAME
|
||||
mod - compute the remainder for an integer quotient
|
||||
|
||||
SYNOPSIS
|
||||
mod(x, y, rnd)
|
||||
mod(x, y [,rnd])
|
||||
x % y
|
||||
|
||||
TYPES
|
||||
@@ -25,11 +25,11 @@ TYPES
|
||||
DESCRIPTION
|
||||
The expression:
|
||||
|
||||
x % y
|
||||
x % y
|
||||
|
||||
is equivalent to call:
|
||||
|
||||
mod(x, y)
|
||||
mod(x, y)
|
||||
|
||||
The function:
|
||||
|
||||
@@ -37,7 +37,7 @@ DESCRIPTION
|
||||
|
||||
is equivalent to:
|
||||
|
||||
config("mod", rnd), x % y
|
||||
config("mod", rnd), x % y
|
||||
|
||||
except that the global config("mod") value does not change.
|
||||
|
||||
@@ -137,7 +137,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
quo, quomod, //, %
|
||||
|
||||
## Copyright (C) 1999-2006 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006,2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
|
@@ -85,7 +85,7 @@
|
||||
|
||||
The man command is an alias for the help command. Try:
|
||||
|
||||
man jacobi
|
||||
man jacobi
|
||||
|
||||
Only calc help files may be displayed by the help and man commands.
|
||||
|
||||
|
@@ -18,7 +18,7 @@ DESCRIPTION
|
||||
|
||||
As a unary operator:
|
||||
|
||||
# value
|
||||
# value
|
||||
|
||||
returns the number of 1 bits, or pop-count of the absolute value of
|
||||
the numerator (abs(num(value))). Therefore when x is a non-negative
|
||||
@@ -52,7 +52,7 @@ DESCRIPTION
|
||||
|
||||
For example, of an executable file contains:
|
||||
|
||||
#!/usr/local/src/bin/calc/calc -q -f
|
||||
#!/usr/local/src/bin/calc/calc -q -f
|
||||
/* NOTE: The #! above must start in column 1 of the 1st line */
|
||||
/* The 1st line must end with -f */
|
||||
## Single # shell comments don't work, use two or more
|
||||
|
2
help/quo
2
help/quo
@@ -2,7 +2,7 @@ NAME
|
||||
quo - compute integer quotient of a value by a real number
|
||||
|
||||
SYNOPSIS
|
||||
quo(x, y, rnd) or x // y
|
||||
quo(x, y [,rnd]) or x // y
|
||||
|
||||
TYPES
|
||||
If x is a matrix or list, the returned value is a matrix or list v of
|
||||
|
57
help/r2d
Normal file
57
help/r2d
Normal file
@@ -0,0 +1,57 @@
|
||||
NAME
|
||||
r2d - convert radians to degrees
|
||||
|
||||
SYNOPSIS
|
||||
r2d(x [,eps])
|
||||
|
||||
TYPES
|
||||
x number (real or complex)
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return number
|
||||
|
||||
DESCRIPTION
|
||||
Given x radians, return the equivalent number of degrees.
|
||||
|
||||
The eps controls the precision of the calculated internal
|
||||
constant pi / 180.
|
||||
|
||||
EXAMPLE
|
||||
; pi = pi(1e-20)
|
||||
; print r2d(pi), r2d(pi/3), r2d(2*pi)
|
||||
180 60 360
|
||||
|
||||
; print r2d(pi+4i), r2d(pi/3 + 1i*pi), r2d(pi/5 + 5i*pi)
|
||||
180+~229.18311805232928350739i 60+180, 36+900i
|
||||
|
||||
LIMITS
|
||||
eps > 0
|
||||
|
||||
LINK LIBRARY
|
||||
NUMBER *qpidiv180(NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
d2r, g2r, r2g, d2g, g2d,
|
||||
sin, cos, tan, sec, csc, cot, epsilon
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/07 12:04:28
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
57
help/r2g
Normal file
57
help/r2g
Normal file
@@ -0,0 +1,57 @@
|
||||
NAME
|
||||
r2g - convert radians to gradians
|
||||
|
||||
SYNOPSIS
|
||||
r2g(x [,eps])
|
||||
|
||||
TYPES
|
||||
x number (real or complex)
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return number
|
||||
|
||||
DESCRIPTION
|
||||
Given x radians, return the equivalent number of gradians.
|
||||
|
||||
The eps controls the precision of the calculated internal
|
||||
constant pi / 200.
|
||||
|
||||
EXAMPLE
|
||||
; pi = pi()
|
||||
; print r2g(pi), r2g(pi/3), r2g(2*pi)
|
||||
200 ~66.66666666666666666667 400
|
||||
|
||||
; print r2g(pi+4i), r2g(pi/4 + 1i*pi), r2g(pi/5 + 5i*pi)
|
||||
200+~254.64790894703253723043i 50+200i 40+1000i
|
||||
|
||||
LIMITS
|
||||
eps > 0
|
||||
|
||||
LINK LIBRARY
|
||||
NUMBER *qpidiv200(NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
d2r, r2d, g2r, d2g, g2d,
|
||||
sin, cos, tan, sec, csc, cot, epsilon
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
##
|
||||
## Under source code control: 2021/09/07 12:04:28
|
||||
## File existed as early as: 2021
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
@@ -14,7 +14,7 @@ DESCRIPTION
|
||||
Generate a pseudo-random number using an subtractive 100 shuffle generator.
|
||||
We return a pseudo-random number over the half closed interval:
|
||||
|
||||
[min,beyond) ((min <= return < beyond))
|
||||
[min,beyond) ((min <= return < beyond))
|
||||
|
||||
By default, min is 0 and beyond is 2^64.
|
||||
|
||||
|
@@ -14,7 +14,7 @@ DESCRIPTION
|
||||
Generate a pseudo-random number using a Blum-Blum-Shub generator.
|
||||
We return a pseudo-random number over the half closed interval:
|
||||
|
||||
[min,beyond) ((min <= return < beyond))
|
||||
[min,beyond) ((min <= return < beyond))
|
||||
|
||||
By default, min is 0 and beyond is 2^64.
|
||||
|
||||
@@ -159,7 +159,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
seed, srand, randbit, isrand, rand, srandom, israndom
|
||||
|
||||
## Copyright (C) 1999-2007 Landon Curt Noll
|
||||
## Copyright (C) 1999-2007,2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
|
@@ -302,7 +302,7 @@ Statements
|
||||
help round
|
||||
|
||||
See:
|
||||
help builtin
|
||||
help builtin
|
||||
|
||||
for a list of builtin functions.
|
||||
|
||||
@@ -321,11 +321,11 @@ Statements
|
||||
|
||||
The man command is an alias for the help command. For example:
|
||||
|
||||
man jacobi
|
||||
man jacobi
|
||||
|
||||
Only calc help files may be displayed by the help and man commands.
|
||||
|
||||
## Copyright (C) 1999-2007,2017 Landon Curt Noll
|
||||
## Copyright (C) 1999-2007,2017,2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
|
@@ -14,7 +14,7 @@ DESCRIPTION
|
||||
The stoponerror controls when or if calc stops based on the
|
||||
number of errors:
|
||||
|
||||
n == -1 do not stop
|
||||
n == -1 do not stop
|
||||
n == 0 stop on error unless calc was invoked with -c
|
||||
n > 0 stop when n errors are encountered
|
||||
|
||||
@@ -35,7 +35,7 @@ LINK LIBRARY
|
||||
SEE ALSO
|
||||
errcount, errmax, errorcodes, iserror, errno, strerror, newerror
|
||||
|
||||
## Copyright (C) 2006 Landon Curt Noll
|
||||
## Copyright (C) 2006,2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
|
@@ -26,6 +26,8 @@ EXAMPLE
|
||||
strcmp("abc", "abb") == 1
|
||||
strcmp("abc", "abc") == 0
|
||||
strcmp("abc", "abd") == -1
|
||||
strcmp("desk", "Shabisky") == 1
|
||||
strcmp("Shabisky", "desk") == -1
|
||||
strcmp("abc\0", "abc") == 1
|
||||
strcmp("a\0b", "a\0c") == -1
|
||||
|
||||
@@ -39,7 +41,7 @@ SEE ALSO
|
||||
strcat, strcpy, strerror, strlen, strncmp, strncpy, strpos,
|
||||
strprintf, strscan, strscanf, substr
|
||||
|
||||
## Copyright (C) 2006 Ernest Bowen
|
||||
## Copyright (C) 2006,2021 Ernest Bowen
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
|
@@ -18,7 +18,7 @@ DESCRIPTION
|
||||
|
||||
EXAMPLE
|
||||
; strtolower(" GNU Lesser General Public License");
|
||||
" gnu lesser general public license"
|
||||
" gnu lesser general public license"
|
||||
|
||||
LIMITS
|
||||
none.
|
||||
|
@@ -18,7 +18,7 @@ DESCRIPTION
|
||||
|
||||
EXAMPLE
|
||||
; strtoupper(" GNU Lesser General Public License");
|
||||
" GNU LESSER GENERAL PUBLIC LICENSE"
|
||||
" GNU LESSER GENERAL PUBLIC LICENSE"
|
||||
|
||||
LIMITS
|
||||
none.
|
||||
|
@@ -73,11 +73,11 @@ Unexpected
|
||||
|
||||
Be careful about the precedence of operators. Note that:
|
||||
|
||||
-1 ^ 0.5 == -1
|
||||
-1 ^ 0.5 == -1
|
||||
|
||||
whereas:
|
||||
|
||||
(-1) ^ 0.5 == 1i
|
||||
(-1) ^ 0.5 == 1i
|
||||
|
||||
because the above expression in parsed as:
|
||||
|
||||
@@ -85,7 +85,7 @@ Unexpected
|
||||
|
||||
whereas:
|
||||
|
||||
(-1) ^ 0.5 == 1i
|
||||
(-1) ^ 0.5 == 1i
|
||||
|
||||
|
||||
op= operators associate left to right
|
||||
@@ -228,7 +228,7 @@ Unexpected
|
||||
|
||||
1<<8/2
|
||||
|
||||
evalues to 128, not 16, because <<8 is performed before the /2.
|
||||
evaluates to 128, not 16, because <<8 is performed before the /2.
|
||||
|
||||
|
||||
&A[0] and A are different things in calc
|
||||
@@ -277,7 +277,7 @@ Unexpected
|
||||
A single # is an calc operator, not a comment. However two or more
|
||||
##'s in a row is a comment. See "help pound" for more information.
|
||||
|
||||
#!/usr/local/src/bin/calc/calc -q -f
|
||||
#!/usr/local/src/bin/calc/calc -q -f
|
||||
|
||||
/* a correct comment */
|
||||
## another correct comment
|
||||
@@ -289,7 +289,7 @@ Unexpected
|
||||
|
||||
This next example is WRONG:
|
||||
|
||||
#!/usr/local/src/bin/calc/calc -q -f
|
||||
#!/usr/local/src/bin/calc/calc -q -f
|
||||
|
||||
# This is not a calc calc comment because it has only a single #
|
||||
# You must to start comments with ## or /*
|
||||
@@ -350,7 +350,7 @@ Unexpected
|
||||
|
||||
In most interactive shells:
|
||||
|
||||
calc 2 * 3
|
||||
calc 2 * 3
|
||||
|
||||
will frequently produce a "Missing operator" error because the '*' is
|
||||
evaluated as a "shell glob". To avoid this you must quote or escape
|
||||
@@ -358,11 +358,11 @@ Unexpected
|
||||
|
||||
For example, bash / ksh / sh shell users should use:
|
||||
|
||||
calc '2 * 3'
|
||||
calc '2 * 3'
|
||||
|
||||
or:
|
||||
|
||||
calc 2 \* 3
|
||||
calc 2 \* 3
|
||||
|
||||
or some other form of shell meta-character escaping.
|
||||
|
||||
@@ -393,7 +393,7 @@ Unexpected
|
||||
|
||||
To avoid this problem, use:
|
||||
|
||||
seq 5 | while read i; do calc "($i+3)^2" </dev/null; done
|
||||
seq 5 | while read i; do calc "($i+3)^2" </dev/null; done
|
||||
|
||||
which produces the expected results:
|
||||
|
||||
@@ -529,6 +529,34 @@ Unexpected
|
||||
; help fclose
|
||||
|
||||
|
||||
trig functions use only radians
|
||||
===============================
|
||||
|
||||
Some might be surprised to discover that all of the trigonometric in calc:
|
||||
|
||||
sin, cos, tan, sec, csc, cot
|
||||
asin, acos, atan, asec, acsc, acot
|
||||
|
||||
work in only radians.
|
||||
|
||||
Calc as builtin functions to convert between degrees, radians and gradians:
|
||||
|
||||
d2r(deg) - given degrees returns radians
|
||||
g2r(grad) - given gradians returns radians
|
||||
|
||||
r2d(rad) - given radians returns degrees
|
||||
g2d(grad) - given gradians returns degrees
|
||||
|
||||
r2g(rad) - given radians returns gradians
|
||||
d2g(deg) - given degrees returns gradians
|
||||
|
||||
For example, if you want to take the sin of 30 degrees, convert
|
||||
the 30 degrees into radians and pass the result to sin():
|
||||
|
||||
; print sin(d2r(30))
|
||||
0.5
|
||||
|
||||
|
||||
## Copyright (C) 1999-2007,2014,2017,2021 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
|
@@ -12,16 +12,16 @@ DESCRIPTION
|
||||
|
||||
Calc version strings can be of the form:
|
||||
|
||||
x.y.z.w
|
||||
x.y.z
|
||||
x.y
|
||||
x.y.z.w
|
||||
x.y.z
|
||||
x.y
|
||||
|
||||
where x, y, z, w, v are integers (without leading 0's) and,
|
||||
t is the literal character 't'.
|
||||
|
||||
EXAMPLE
|
||||
; version()
|
||||
"2.11.5.4"
|
||||
"2.11.5.4"
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
2
input.c
2
input.c
@@ -1127,7 +1127,7 @@ addreadset(char *name, char *path, struct stat *sbuf)
|
||||
* like UNIX inodes. _fullpath also allocated the memory for
|
||||
* this new longer path name.
|
||||
*/
|
||||
{
|
||||
{
|
||||
readset[ret].path = _fullpath(NULL, path, MSDOS_MAX_PATH);
|
||||
if (readset[ret].path == NULL) {
|
||||
return -1;
|
||||
|
2
qfunc.c
2
qfunc.c
@@ -673,7 +673,7 @@ qdigit(NUMBER *q, ZVALUE dpos, ZVALUE base)
|
||||
/*
|
||||
* In the first stage, q is expressed as base^k * N/D where
|
||||
* gcd(D, base) = 1
|
||||
* K is k as a ZVALUE
|
||||
* K is k as a ZVALUE
|
||||
*/
|
||||
base.sign = 0;
|
||||
if (ziszero(base) || zisunit(base))
|
||||
|
31
qio.c
31
qio.c
@@ -247,6 +247,37 @@ qprintnum(NUMBER *q, int outmode, LEN outdigits)
|
||||
PRINTF1("e%ld", exp);
|
||||
break;
|
||||
|
||||
case MODE_ENG:
|
||||
if (qiszero(q)) {
|
||||
PUTCHAR('0');
|
||||
return;
|
||||
}
|
||||
tmpval = *q;
|
||||
tmpval.num.sign = 0;
|
||||
exp = qilog10(&tmpval);
|
||||
if (exp == 0) { /* in range to output as real */
|
||||
qprintnum(q, MODE_REAL, outdigits);
|
||||
return;
|
||||
}
|
||||
tmpval.num = _one_;
|
||||
tmpval.den = _one_;
|
||||
if (exp > 0) {
|
||||
exp -= exp % 3;
|
||||
ztenpow(exp, &tmpval.den);
|
||||
} else {
|
||||
long remainder = exp % 3;
|
||||
if (remainder)
|
||||
exp -= remainder + 3;
|
||||
ztenpow(-exp, &tmpval.num);
|
||||
}
|
||||
q = qmul(q, &tmpval);
|
||||
zfree(tmpval.num);
|
||||
zfree(tmpval.den);
|
||||
qprintnum(q, MODE_REAL, outdigits);
|
||||
qfree(q);
|
||||
if (exp) PRINTF1("e%ld", exp);
|
||||
break;
|
||||
|
||||
case MODE_REAL_AUTO:
|
||||
{
|
||||
const int P = conf->outdigits ? conf->outdigits : 1;
|
||||
|
18
qmath.c
18
qmath.c
@@ -44,9 +44,21 @@ NUMBER _qnegone_ = { { _oneval_, 1, 1 }, { _oneval_, 1, 0 }, 1, NULL };
|
||||
NUMBER _qonehalf_ = { { _oneval_, 1, 0 }, { _twoval_, 1, 0 }, 1, NULL };
|
||||
NUMBER _qneghalf_ = { { _oneval_, 1, 1 }, { _twoval_, 1, 0 }, 1, NULL };
|
||||
NUMBER _qonesqbase_ = { { _oneval_, 1, 0 }, { _sqbaseval_, 2, 0 }, 1, NULL };
|
||||
NUMBER _qtendivnine_ = { { _tenval_, 1, 0 }, { _nineval_, 1, 0 }, 1, NULL };
|
||||
NUMBER _qninedivten_ = { { _nineval_, 1, 0 }, { _tenval_, 1, 0 }, 1, NULL };
|
||||
NUMBER _qthreesixty = { { _threesixtyval_, 1, 0 },
|
||||
{ _oneval_, 1, 0 }, 1, NULL };
|
||||
NUMBER _qfourhundred = { { _fourhundredval_, 1, 0 },
|
||||
{ _oneval_, 1, 0 }, 1, NULL };
|
||||
NUMBER _qtwentyfour = { { _twentyfourval_, 1, 0 },
|
||||
{ _oneval_, 1, 0 }, 1, NULL };
|
||||
|
||||
NUMBER * initnumbs[INITCONSTCOUNT] = {&_qzero_, &_qone_, &_qtwo_, &_qthree_,
|
||||
&_qfour_, &_qten_, &_qnegone_, &_qonehalf_, &_qneghalf_};
|
||||
NUMBER * initnumbs[] = {&_qzero_, &_qone_, &_qtwo_, &_qthree_,
|
||||
&_qfour_, &_qten_, &_qnegone_, &_qonehalf_, &_qneghalf_,
|
||||
&_qonesqbase_, &_qtendivnine_, &_qninedivten_,
|
||||
&_qthreesixty, &_qfourhundred, &_qtwentyfour,
|
||||
NULL /* must be last */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
@@ -1478,7 +1490,7 @@ shownumbers(void)
|
||||
printf("Index Links Digits Value\n");
|
||||
printf("----- ----- ------ -----\n");
|
||||
|
||||
for (i = 0, k = 0; i < INITCONSTCOUNT; i++) {
|
||||
for (i = 0, k = 0; initnumbs[i] != NULL; i++) {
|
||||
count++;
|
||||
vp = initnumbs[i];
|
||||
printf("%6ld %4ld ", k++, vp->links);
|
||||
|
8
qmath.h
8
qmath.h
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* qmath - declarations for extended precision rational arithmetic
|
||||
*
|
||||
* Copyright (C) 1999-2007,2014 David I. Bell
|
||||
* Copyright (C) 1999-2007,2014,2021 David I. Bell
|
||||
*
|
||||
* Calc is open software; you can redistribute it and/or modify it under
|
||||
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
@@ -35,8 +35,6 @@
|
||||
#endif
|
||||
|
||||
|
||||
#define INITCONSTCOUNT 9 /* number of initnumbs[] pre-defined constants */
|
||||
|
||||
/*
|
||||
* Rational arithmetic definitions.
|
||||
*/
|
||||
@@ -213,6 +211,8 @@ E_FUNC NUMBER *qacsch(NUMBER *q, NUMBER *epsilon);
|
||||
E_FUNC NUMBER *qacoth(NUMBER *q, NUMBER *epsilon);
|
||||
E_FUNC NUMBER *qlegtoleg(NUMBER *q, NUMBER *epsilon, BOOL wantneg);
|
||||
E_FUNC NUMBER *qpi(NUMBER *epsilon);
|
||||
E_FUNC NUMBER *qpidiv180(NUMBER *epsilon);
|
||||
E_FUNC NUMBER *qpidiv200(NUMBER *epsilon);
|
||||
E_FUNC NUMBER *qcatalan(NUMBER *);
|
||||
E_FUNC NUMBER *qbern(ZVALUE z);
|
||||
E_FUNC void qfreebern(void);
|
||||
@@ -273,6 +273,8 @@ static inline NUMBER* qlink(NUMBER* q) { if(q) { (q)->links++; } return q; }
|
||||
*/
|
||||
EXTERN NUMBER _qzero_, _qone_, _qnegone_, _qonehalf_, _qneghalf_, _qonesqbase_;
|
||||
EXTERN NUMBER _qtwo_, _qthree_, _qfour_, _qten_;
|
||||
EXTERN NUMBER _qtendivnine_, _qninedivten_;
|
||||
EXTERN NUMBER _qthreesixty, _qfourhundred, _qtwentyfour;
|
||||
EXTERN NUMBER * initnumbs[];
|
||||
|
||||
|
||||
|
147
qtrans.c
147
qtrans.c
@@ -47,7 +47,40 @@ NUMBER _qlge_ = { { _qlgenum_, 1, 0 }, { _qlgeden_, 1, 0 }, 1, NULL };
|
||||
STATIC NUMBER *ln_10 = NULL;
|
||||
STATIC NUMBER *ln_10_epsilon = NULL;
|
||||
|
||||
STATIC NUMBER *pivalue[2];
|
||||
/*
|
||||
* cache pi
|
||||
*
|
||||
* pivalue[LAST_PI_EPSILON] - last epsilon used to calculate pi
|
||||
* pivalue[LAST_PI_VALUE] - last calculated pi
|
||||
* given pivalue[LAST_PI_EPSILON] epsilon
|
||||
* pivalue[LAST_PI_DIV_180_EPSILON] - last epsilon used to calculate pi/180
|
||||
* pivalue[LAST_PI_DIV_180_VALUE] - last calculated pi/180 given
|
||||
* pivalue[LAST_PI_DIV_180_EPSILON] epsilon
|
||||
* pivalue[LAST_PI_DIV_200_EPSILON] - last epsilon used to calculate pi/200
|
||||
* pivalue[LAST_PI_DIV_200_VALUE] - last calculated pi/200 given
|
||||
* pivalue[LAST_PI_DIV_200_EPSILON] epsilon
|
||||
*/
|
||||
enum pi_cache {
|
||||
LAST_PI_EPSILON = 0,
|
||||
LAST_PI_VALUE,
|
||||
LAST_PI_DIV_180_EPSILON,
|
||||
LAST_PI_DIV_180_VALUE,
|
||||
LAST_PI_DIV_200_EPSILON,
|
||||
LAST_PI_DIV_200_VALUE,
|
||||
PI_CACHE_LEN /* must be last */
|
||||
};
|
||||
STATIC NUMBER *pivalue[PI_CACHE_LEN] = {
|
||||
NULL, /* LAST_PI_EPSILON */
|
||||
NULL, /* LAST_PI_VALUE */
|
||||
NULL, /* LAST_PI_DIV_180_EPSILON */
|
||||
NULL, /* LAST_PI_DIV_180_VALUE */
|
||||
NULL, /* LAST_PI_DIV_200_EPSILON */
|
||||
NULL, /* LAST_PI_DIV_200_VALUE */
|
||||
};
|
||||
|
||||
/*
|
||||
* other static function decls
|
||||
*/
|
||||
STATIC NUMBER *qexprel(NUMBER *q, long bitnum);
|
||||
|
||||
/*
|
||||
@@ -725,16 +758,25 @@ qpi(NUMBER *epsilon)
|
||||
long bits; /* needed number of bits of precision */
|
||||
long t;
|
||||
|
||||
/* firewall */
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("zero epsilon value for pi");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
if (epsilon == pivalue[0])
|
||||
return qlink(pivalue[1]);
|
||||
if (pivalue[0]) {
|
||||
qfree(pivalue[0]);
|
||||
qfree(pivalue[1]);
|
||||
|
||||
/* use pi cache if epsilon marches, else flush if needed */
|
||||
if (pivalue[LAST_PI_EPSILON] != NULL &&
|
||||
pivalue[LAST_PI_VALUE] != NULL &&
|
||||
epsilon == pivalue[LAST_PI_EPSILON]) {
|
||||
return qlink(pivalue[LAST_PI_VALUE]);
|
||||
}
|
||||
if (pivalue[LAST_PI_EPSILON] != NULL) {
|
||||
qfree(pivalue[LAST_PI_EPSILON]);
|
||||
}
|
||||
if (pivalue[LAST_PI_VALUE] != NULL) {
|
||||
qfree(pivalue[LAST_PI_VALUE]);
|
||||
}
|
||||
|
||||
bits = -qilog2(epsilon) + 4;
|
||||
if (bits < 4)
|
||||
bits = 4;
|
||||
@@ -768,11 +810,100 @@ qpi(NUMBER *epsilon)
|
||||
zfree(sum);
|
||||
r = qmappr(t1, epsilon, 24L);
|
||||
qfree(t1);
|
||||
pivalue[0] = qlink(epsilon);
|
||||
pivalue[1] = qlink(r);
|
||||
pivalue[LAST_PI_EPSILON] = qlink(epsilon);
|
||||
pivalue[LAST_PI_VALUE] = qlink(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* qpidiv180 - calcucalte pi / 180
|
||||
*
|
||||
* This function returns pi/180 as used to covert between radians and degrees.
|
||||
*/
|
||||
NUMBER *
|
||||
qpidiv180(NUMBER *epsilon)
|
||||
{
|
||||
NUMBER *pi, *pidiv180;
|
||||
|
||||
/* firewall */
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("zero epsilon value for qpidiv180");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
/* use pi/180 cache if epsilon marches, else flush if needed */
|
||||
if (pivalue[LAST_PI_DIV_180_EPSILON] != NULL &&
|
||||
pivalue[LAST_PI_DIV_180_VALUE] != NULL &&
|
||||
epsilon == pivalue[LAST_PI_DIV_180_EPSILON]) {
|
||||
return qlink(pivalue[LAST_PI_DIV_180_VALUE]);
|
||||
}
|
||||
if (pivalue[LAST_PI_DIV_180_EPSILON] != NULL) {
|
||||
qfree(pivalue[LAST_PI_DIV_180_EPSILON]);
|
||||
}
|
||||
if (pivalue[LAST_PI_DIV_180_VALUE] != NULL) {
|
||||
qfree(pivalue[LAST_PI_DIV_180_VALUE]);
|
||||
}
|
||||
|
||||
/* let qpi() returned cached pi or calculate new as needed */
|
||||
pi = qpi(epsilon);
|
||||
|
||||
/* calculate pi/180 */
|
||||
pidiv180 = qdivi(pi, 180);
|
||||
|
||||
/* cache epsilon and pi/180 */
|
||||
pivalue[LAST_PI_DIV_180_EPSILON] = qlink(epsilon);
|
||||
pivalue[LAST_PI_DIV_180_VALUE] = qlink(pidiv180);
|
||||
|
||||
/* return pi/180 */
|
||||
return pidiv180;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* qpidiv200 - calcucalte pi / 200
|
||||
*
|
||||
* This function returns pi/200 as used to covert between radians and gradians.
|
||||
*/
|
||||
NUMBER *
|
||||
qpidiv200(NUMBER *epsilon)
|
||||
{
|
||||
NUMBER *pi, *pidiv200;
|
||||
|
||||
/* firewall */
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("zero epsilon value for qpidiv200");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
/* use pi/200 cache if epsilon marches, else flush if needed */
|
||||
if (pivalue[LAST_PI_DIV_200_EPSILON] != NULL &&
|
||||
pivalue[LAST_PI_DIV_200_VALUE] != NULL &&
|
||||
epsilon == pivalue[LAST_PI_DIV_200_EPSILON]) {
|
||||
return qlink(pivalue[LAST_PI_DIV_200_VALUE]);
|
||||
}
|
||||
if (pivalue[LAST_PI_DIV_200_EPSILON] != NULL) {
|
||||
qfree(pivalue[LAST_PI_DIV_200_EPSILON]);
|
||||
}
|
||||
if (pivalue[LAST_PI_DIV_200_VALUE] != NULL) {
|
||||
qfree(pivalue[LAST_PI_DIV_200_VALUE]);
|
||||
}
|
||||
|
||||
/* let qpi() returned cached pi or calculate new as needed */
|
||||
pi = qpi(epsilon);
|
||||
|
||||
/* calculate pi/200 */
|
||||
pidiv200 = qdivi(pi, 200);
|
||||
|
||||
/* cache epsilon and pi/200 */
|
||||
pivalue[LAST_PI_DIV_200_EPSILON] = qlink(epsilon);
|
||||
pivalue[LAST_PI_DIV_200_VALUE] = qlink(pidiv200);
|
||||
|
||||
/* return pi/200 */
|
||||
return pidiv200;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Calculate the exponential function to the nearest or next to nearest
|
||||
* multiple of the positive number epsilon.
|
||||
|
4
str.c
4
str.c
@@ -939,9 +939,9 @@ stringcaserel(STRING *s1, STRING *s2)
|
||||
c2++;
|
||||
}
|
||||
if ( (tolower(*c1)) > (tolower(*c2)))
|
||||
return 1;
|
||||
return 1;
|
||||
if ( (tolower(*c1)) < (tolower(*c2)))
|
||||
return -1;
|
||||
return -1;
|
||||
if (i1 < i2) return -1;
|
||||
return (i1 > i2);
|
||||
}
|
||||
|
@@ -52,9 +52,9 @@ static char *program;
|
||||
|
||||
|
||||
#define MAJOR_VER 2 /* major library version */
|
||||
#define MINOR_VER 13 /* minor library version */
|
||||
#define MINOR_VER 14 /* minor library version */
|
||||
#define MAJOR_PATCH 0 /* major software version level */
|
||||
#define MINOR_PATCH 1 /* minor software version level */
|
||||
#define MINOR_PATCH 9 /* minor software version level */
|
||||
|
||||
|
||||
/*
|
||||
@@ -79,7 +79,7 @@ char *Copyright = "\n"
|
||||
"calc - arbitrary precision calculator\n"
|
||||
"\n"
|
||||
"Copyright (C) 1999-2021 David I. Bell, Landon Curt Noll "
|
||||
"and Ernest Bowen\n"
|
||||
"and Ernest Bowen\n"
|
||||
"\n"
|
||||
"Initial author: David I. Bell\n"
|
||||
"\n"
|
||||
|
@@ -49,7 +49,7 @@ NROFF_ARG=
|
||||
MANMAKE=
|
||||
MANMODE=
|
||||
CALCPATH=./cal
|
||||
CALCRC='/lib/calc/startup:~/.calcrc:./.calcinit'
|
||||
CALCRC='./.calcinit:~/.calcrc:/lib/calc/startup'
|
||||
USE_READLINE=-DUSE_READLINE
|
||||
READLINE_LIB=
|
||||
READLINE_INCLUDE=
|
||||
|
4
zfunc.c
4
zfunc.c
@@ -1034,7 +1034,7 @@ zgcd(ZVALUE z1, ZVALUE z2, ZVALUE *res)
|
||||
}
|
||||
needw = FALSE;
|
||||
}
|
||||
g = *a0 * w;
|
||||
g = (FULL) (*a0 * w);
|
||||
if (h < BASEB) {
|
||||
g &= (1 << h) - 1;
|
||||
} else {
|
||||
@@ -1044,7 +1044,7 @@ zgcd(ZVALUE z1, ZVALUE z2, ZVALUE *res)
|
||||
g = 1;
|
||||
}
|
||||
} else {
|
||||
g = (HALF) *a0 * w;
|
||||
g = (FULL) (*a0 * w);
|
||||
}
|
||||
a = a0;
|
||||
b = b0;
|
||||
|
7
zmath.c
7
zmath.c
@@ -58,6 +58,9 @@ HALF _twentyval_[] = { 20 };
|
||||
HALF _sqbaseval_[] = { 0, 1 };
|
||||
HALF _pow4baseval_[] = { 0, 0, 1 };
|
||||
HALF _pow8baseval_[] = { 0, 0, 0, 0, 1 };
|
||||
HALF _threesixtyval_[] = { 360 };
|
||||
HALF _fourhundredval_[] = { 400 };
|
||||
HALF _twentyfourval_[] = { 24 };
|
||||
|
||||
ZVALUE zconst[] = {
|
||||
{ _zeroval_, 1, 0}, { _oneval_, 1, 0}, { _twoval_, 1, 0},
|
||||
@@ -66,7 +69,9 @@ ZVALUE zconst[] = {
|
||||
{ _nineval_, 1, 0}, { _tenval_, 1, 0}, { _elevenval_, 1, 0},
|
||||
{ _twelveval_, 1, 0}, { _thirteenval_, 1, 0}, { _fourteenval_, 1, 0},
|
||||
{ _fifteenval_, 1, 0}, { _sixteenval_, 1, 0}, { _seventeenval_, 1, 0},
|
||||
{ _eightteenval_, 1, 0}, { _nineteenval_, 1, 0}, { _twentyval_, 1, 0}
|
||||
{ _eightteenval_, 1, 0}, { _nineteenval_, 1, 0}, { _twentyval_, 1, 0},
|
||||
{ _threesixtyval_, 1, 0}, { _fourhundredval_, 1, 0},
|
||||
{ _twentyfourval_, 1, 0}
|
||||
};
|
||||
|
||||
ZVALUE _zero_ = { _zeroval_, 1, 0};
|
||||
|
4
zmath.h
4
zmath.h
@@ -594,7 +594,8 @@ E_FUNC void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res);
|
||||
#define MODE_OCTAL 6
|
||||
#define MODE_BINARY 7
|
||||
#define MODE_REAL_AUTO 8
|
||||
#define MODE_MAX 8
|
||||
#define MODE_ENG 9
|
||||
#define MODE_MAX 9
|
||||
#define MODE2_OFF (MODE_MAX+1)
|
||||
|
||||
/* XXX - perhaps we need the MODE_REAL_AUTO vs MODE_REAL as a config mode? */
|
||||
@@ -647,6 +648,7 @@ EXTERN HALF _tenval_[], _elevenval_[], _twelveval_[], _thirteenval_[];
|
||||
EXTERN HALF _fourteenval_[], _fifteenval_[];
|
||||
EXTERN HALF _sqbaseval_[];
|
||||
EXTERN HALF _fourthbaseval_[];
|
||||
EXTERN HALF _threesixtyval_[], _fourhundredval_[], _twentyfourval_[];
|
||||
|
||||
EXTERN ZVALUE zconst[]; /* ZVALUE integers from 0 thru 15 */
|
||||
|
||||
|
Reference in New Issue
Block a user