mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Compare commits
99 Commits
prod-2.14.
...
v2.14.2.2
Author | SHA1 | Date | |
---|---|---|---|
|
b03e71f0ce | ||
|
db799aac10 | ||
|
adecf7d76e | ||
|
94bf264088 | ||
|
80e841eded | ||
|
3f78fc20d7 | ||
|
c26460b255 | ||
|
3ec7b39366 | ||
|
49c599aec9 | ||
|
a582511002 | ||
|
e05d904821 | ||
|
ccd579ecda | ||
|
15be1dec4d | ||
|
f34c659877 | ||
|
2ad27e7909 | ||
|
a4d3c8ff9d | ||
|
bd64a6cc36 | ||
|
e2b2976d18 | ||
|
3ea51ea937 | ||
|
5fa732b869 | ||
|
6a54caf1c2 | ||
|
cce930987b | ||
|
7c806f13ea | ||
|
616bcd8d46 | ||
|
36a1a042f3 | ||
|
75159fcbc2 | ||
|
8ef7b5311e | ||
|
d5a11b3df4 | ||
|
74c299ad4e | ||
|
d89ea78104 | ||
|
644b348bcb | ||
|
11ddc30528 | ||
|
f5fc06fbd4 | ||
|
8a4c12d2be | ||
|
d2139064cb | ||
|
774060944b | ||
|
61c268f1c2 | ||
|
dcf360d688 | ||
|
fddd24d6c6 | ||
|
bcae90959e | ||
|
5b42c557b0 | ||
|
1b0e6c4462 | ||
|
f0396fccde | ||
|
21be7adb82 | ||
|
6317991f2b | ||
|
f4f19f21dc | ||
|
348f3ed427 | ||
|
542a263de6 | ||
|
17702a4799 | ||
|
7c6723db88 | ||
|
0d99ba54d8 | ||
|
83adfaa720 | ||
|
ef6a30c9c9 | ||
|
3aaad95443 | ||
|
74b833977b | ||
|
333f0c4332 | ||
|
d91ace6091 | ||
|
49c6a8218c | ||
|
def203f273 | ||
|
5b2983f421 | ||
|
e6fc1a92a9 | ||
|
3e084d9fb9 | ||
|
340c1990ce | ||
|
5acd67c704 | ||
|
083011c9e3 | ||
|
dce2c6f0ee | ||
|
827988c553 | ||
|
25dcd8cb80 | ||
|
3b3bfb3f74 | ||
|
3e4391e2af | ||
|
cfc6a6669c | ||
|
fa457db3cd | ||
|
d08b958a15 | ||
|
5f28e5b851 | ||
|
8dc52a532a | ||
|
6fc14730c0 | ||
|
b97093e58c | ||
|
923c36e475 | ||
|
741ea46853 | ||
|
56b6613da8 | ||
|
e9eef2dfa2 | ||
|
0dbf258696 | ||
|
f6d558783a | ||
|
6f27a32f79 | ||
|
d58f605866 | ||
|
b83c5be515 | ||
|
561928a45c | ||
|
7f89af37f5 | ||
|
4470f1f62e | ||
|
8217c49b94 | ||
|
d2cb03b4cc | ||
|
80f13a4e45 | ||
|
1658343227 | ||
|
3f177f2d81 | ||
|
dcd5a987af | ||
|
cb77888045 | ||
|
ce17b267be | ||
|
738dd0334e | ||
|
7ba1dbdc65 |
70
.github/ISSUE_TEMPLATE/calc-bug-report.md
vendored
Normal file
70
.github/ISSUE_TEMPLATE/calc-bug-report.md
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
---
|
||||
name: Calc bug report
|
||||
about: Create a report to help us improve
|
||||
title: 'Bug: XXX-change-this-part-XXX'
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Calc bug report template version: 1.3 2022-11-27
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
|
||||
0. How you started calc
|
||||
I.e., provide the command line you used to launch calc
|
||||
|
||||
1. Calc commands and their output
|
||||
Please provide any calc commands you entered on the terminal.
|
||||
Please provide the calc command line output inline as well.
|
||||
If the above is long, please attach a file.
|
||||
|
||||
Or if you cannot compile calc: The make command you used try and compile calc
|
||||
and all error and warning messages produced during that action. If long, consider
|
||||
attaching a file.
|
||||
|
||||
2. Indicate where the problem is
|
||||
Referring to the information for step 1 above, indicate where the problem is to be found
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Attach debug.out**
|
||||
IMPORTANT: Please run `make debug` and then attach the `debug.out` file.
|
||||
|
||||
**Screen shots**
|
||||
If applicable, attach screen shots to help explain your problem.
|
||||
|
||||
**Execution environment (please complete the following information):**
|
||||
- OS:
|
||||
E.g., macOS, FreeBSD, Linux, Windows 11, etc.
|
||||
|
||||
- OS version:
|
||||
E.g., Preferred: give the output of `uname -a`
|
||||
or if no uname command, a description of the OS version/release you are using
|
||||
|
||||
- OS distribution:
|
||||
E.g., macOS 13.0.1, contents of /etc/redhat-release, or /etc/os-release, etc.
|
||||
|
||||
- Calc Version
|
||||
E.g., output of calc -v
|
||||
or if you cannot compile calc, the version you downloaded and from where it came from
|
||||
|
||||
- Shell and shell version
|
||||
E.g., bash, zsh, power shell, etc.
|
||||
and the version of the shell you are using, if known
|
||||
|
||||
**Calc mods**
|
||||
If you have modified the calc source for some reason, please description what you modified.
|
||||
Please consider attaching a patch (diff -u) between an official calc release and the source
|
||||
you are using.
|
||||
|
||||
**Patch**
|
||||
If you have a recommended code patch to address the problem, please attach your file
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
6
.github/workflows/codeql-analysis.yml
vendored
6
.github/workflows/codeql-analysis.yml
vendored
@@ -43,7 +43,7 @@ jobs:
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
@@ -54,7 +54,7 @@ jobs:
|
||||
# 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
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@@ -68,4 +68,4 @@ jobs:
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
uses: github/codeql-action/analyze@v2
|
||||
|
12
.github/workflows/dependabot.yml
vendored
Normal file
12
.github/workflows/dependabot.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# Set update schedule for GitHub Actions
|
||||
#
|
||||
# See https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
# Check for updates to GitHub Actions every week
|
||||
interval: "weekly"
|
9
.gitignore
vendored
9
.gitignore
vendored
@@ -6,6 +6,7 @@
|
||||
#
|
||||
.dynamic
|
||||
.hsrc
|
||||
Makefile.our
|
||||
NOTES
|
||||
align32.h
|
||||
args.h
|
||||
@@ -29,6 +30,7 @@ cscript/simple
|
||||
cscript/square
|
||||
custom/.all
|
||||
custom/libcustcalc*
|
||||
debug.out
|
||||
endian
|
||||
endian_calc.h
|
||||
fposval.h
|
||||
@@ -36,7 +38,7 @@ have_arc4random.h
|
||||
have_ban_pragma.h
|
||||
have_const.h
|
||||
have_environ.h
|
||||
have_fpos.h
|
||||
have_fgetsetpos.h
|
||||
have_fpos_pos.h
|
||||
have_getpgid.h
|
||||
have_getprid.h
|
||||
@@ -48,12 +50,16 @@ have_newstr.h
|
||||
have_offscl.h
|
||||
have_posscl.h
|
||||
have_rusage.h
|
||||
have_statfs.h
|
||||
have_stdlib.h
|
||||
have_stdvs
|
||||
have_strdup.h
|
||||
have_string.h
|
||||
have_strlcat.h
|
||||
have_strlcpy.h
|
||||
have_sys_mount.h
|
||||
have_sys_param.h
|
||||
have_sys_vfs.h
|
||||
have_times.h
|
||||
have_uid_t.h
|
||||
have_unistd.h
|
||||
@@ -92,7 +98,6 @@ libcalc*
|
||||
libcustcalc*
|
||||
longbits
|
||||
longbits.h
|
||||
Makefile.our
|
||||
sample_many
|
||||
sample_rand
|
||||
tags
|
||||
|
61
BUGS
61
BUGS
@@ -28,7 +28,7 @@ Click in the triangle to open up the Assets then click on
|
||||
the approptiate package to download.
|
||||
|
||||
If you made and modifications to calc beyond the simple Makefile
|
||||
configuration, try backing those changges out and see if things get
|
||||
configuration, try backing those changes out and see if things get
|
||||
better.
|
||||
|
||||
If you have tried all of the above and things still are not right,
|
||||
@@ -60,44 +60,7 @@ GitHub web page, click on this button:
|
||||
|
||||
((New Issue))
|
||||
|
||||
=-=
|
||||
|
||||
If you prefer to not use GitHub, then you
|
||||
may send bug and bug fixes reports to:
|
||||
|
||||
calc-bugrept-mail at asthe dot com
|
||||
|
||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
||||
|
||||
NOTE: This replaces the old calc-bugs at asthe dot com address.
|
||||
|
||||
PLEASE put following the SPECIAL PHRASE somewhere in your Email Subject line:
|
||||
|
||||
calc bug report
|
||||
|
||||
You may add additional words to your subject line.
|
||||
|
||||
Suggestion:
|
||||
|
||||
From time to time, the Email address and Subject SPECIAL PHRASE
|
||||
may change so verify you have the current info by visiting:
|
||||
|
||||
http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
|
||||
|
||||
IMPORTANT:
|
||||
|
||||
PLEASE use the above SPECIAL PHRASE somewhere in the Subject line or
|
||||
the mail system won't deliver your Email message.
|
||||
|
||||
Keep in mind that the best way to report on a calc bug is
|
||||
via the above mentioned calc GitHub issue URL.
|
||||
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
|
||||
=-=
|
||||
|
||||
When you send your report, via the calc GitHub issue URL or Email,
|
||||
please include the following information:
|
||||
Please include the following information in the new issue:
|
||||
|
||||
* A description of the problem
|
||||
|
||||
@@ -123,12 +86,13 @@ please include the following information:
|
||||
* If calc dumped core, try to send us a core dump stack trace
|
||||
|
||||
* cd to the calc source directory, and send the contents
|
||||
of debug.out produced by this command:
|
||||
of debug.out.txt produced by this command:
|
||||
|
||||
make debug > debug.out 2>&1
|
||||
make debug > debug.out.txt 2>&1
|
||||
|
||||
Fell free to use the above address to send in bug fixes (in the form
|
||||
of a context diff patch).
|
||||
PLEASE attach the debug.out.txt file to your GitHub issue (bug report)!!
|
||||
|
||||
Please be patient as we cannot always respond to pull requests quickly.
|
||||
|
||||
=-=
|
||||
|
||||
@@ -192,9 +156,18 @@ mis-features in calc:
|
||||
|
||||
will not.
|
||||
|
||||
* The numerator is assumed
|
||||
|
||||
The numerator value of 1 appears to be assumed. In calc:
|
||||
|
||||
/ 2
|
||||
|
||||
will produce a value of 0.5 as if the numerator 1 was given.
|
||||
|
||||
|
||||
=-=
|
||||
|
||||
## Copyright (C) 1999-2014,2021 Landon Curt Noll
|
||||
## Copyright (C) 1999-2014,2021,2023 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
|
||||
|
488
CHANGES
488
CHANGES
@@ -1,4 +1,476 @@
|
||||
The following are the changes from calc version 2.14.0.14 to date:
|
||||
The following are the changes from calc version 2.14.2.1 to date:
|
||||
|
||||
Added cal/fnv_tool.cal, a calc resource file defining:
|
||||
|
||||
find_fnv_prime(bits)
|
||||
deprecated_fnv0(bits,fnv_prime,string)
|
||||
fnv_offset_basis(bits,fnv_prime)
|
||||
fnv1a_style_hash(bits,fnv_prime,prev_hash,string)
|
||||
|
||||
Fixed sorted order of cal/README.
|
||||
|
||||
Removed references to obsolete Email addresses.
|
||||
|
||||
macOS Darwin defaults LCC to "cc".
|
||||
|
||||
|
||||
The following are the changes from calc version 2.14.2.0 to 2.14.2.0:
|
||||
|
||||
Ported calc to the s390x IBM Mainframe running RHEL9.1.
|
||||
|
||||
Added cal/splitbits.cal:
|
||||
|
||||
splitbits(x, b)
|
||||
|
||||
Given an integer x, split the value into a list of integers,
|
||||
each of which is at most b bits long.
|
||||
|
||||
The value b must be an integer > 0.
|
||||
|
||||
The number of elements in the returned list is:
|
||||
|
||||
ceil((highbit(x) + 1) / b)
|
||||
|
||||
If x == 0, then a list of 1 element containing 0 is returned.
|
||||
|
||||
If x < 0, then the two's compliment of abs(x) is returned.
|
||||
Even though calc represents negative integers as positive values
|
||||
with sign bit, the bits returned by this function are as if
|
||||
the integer converted as if the integer was a two's compliment value.
|
||||
|
||||
See also the help command:
|
||||
|
||||
; help resource
|
||||
|
||||
|
||||
The following are the changes from calc version 2.14.1.5 to 2.14.1.6:
|
||||
|
||||
Fixed version numbers in two cases in CHANGES that referred
|
||||
to the 2.14.2.x instead of 2.14.1.x.
|
||||
|
||||
Rename MINGW Makefile variable (a holdover from MINGW32_NT-5.0)
|
||||
to OSNAME.
|
||||
|
||||
Fixed FUNCPTR typedef in hist.c to fix deprecated compiler warnings.
|
||||
|
||||
Fixed when USE_READLINE, READLINE_LIB, READLINE_EXTRAS, and
|
||||
READLINE_INCLUDE are set to empty (disable use of the GNU-readline
|
||||
facility).
|
||||
|
||||
Fix cases of spaces before tabs in Makefile and Makefile.simple.
|
||||
|
||||
Fixed obsolete references to the atoz() in LIBRARY to use the
|
||||
correct internal function name of str2z().
|
||||
|
||||
Fixed obsolete references to the atoq() in LIBRARY to use the
|
||||
correct internal function name of str2q().
|
||||
|
||||
Document in help/unexpected that * operator has has a higher
|
||||
precedence than << in calc, which differs from C. Thanks
|
||||
goes to GitHub user @inguin for pointing put this difference.
|
||||
|
||||
|
||||
The following are the changes from calc version 2.14.1.3 to 2.14.1.4:
|
||||
|
||||
Fixed missing <string.h include in have_fpos_pos.c.
|
||||
|
||||
Change calc version from 2.14.1.2 to 2.14.2.3 as part of a test to
|
||||
build calc RPMs on a reference RHEL8.7 platform (formerly a RHEL7.9
|
||||
platform).
|
||||
|
||||
Changes #! lines in Makefiles to "#!/usr/bin/env make".
|
||||
|
||||
Set SHELL in Makefiles to the basename of the shell.
|
||||
|
||||
Updated COPYING file to indicate that these files are now
|
||||
covered under "The Unlicense" (see https://unlicense.org):
|
||||
|
||||
sha1.c
|
||||
sha1.h
|
||||
cal/dotest.cal
|
||||
cal/screen.cal
|
||||
|
||||
Updated help/credit to match the above changes to COPYING.
|
||||
|
||||
Updated CONTRIB-CODE and calc.man to refer to using GitHub pull requests
|
||||
for contributing to calc (instead of using Email).
|
||||
|
||||
Updated BUGS and calc.man to refer to using GitHub issues
|
||||
for reporting calc bugs (instead of using Email).
|
||||
|
||||
Updated QUESTIONS and calc.man to refer to using GitHub issues
|
||||
for asking calc questions (instead of using Email).
|
||||
|
||||
Fixed Makefile.local command example to refer to overriding the
|
||||
Makefile variable DEBUG (instead of CDEBUG).
|
||||
|
||||
Fixed all make chk ASAN warnings under macOS 13.2.1 when calc is compiled
|
||||
with the following uncommented lines in Makefile.local:
|
||||
|
||||
DEBUG:= -O0 -g
|
||||
CFLAGS+= -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
|
||||
LDFLAGS+= -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
|
||||
CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1
|
||||
|
||||
Improved how pointers to functions are declared for the builtins
|
||||
array in func.c to avoid function declarations without a prototype
|
||||
that is now deprecated in C.
|
||||
|
||||
Improved how pointers to functions are declared for the opcodes
|
||||
array in opcodes.c to avoid function declarations without a prototype
|
||||
|
||||
Replaced use of egrep with grep -E in Makefiles.
|
||||
|
||||
Fixed cases where variables were set but not used in symbol.c, calc.c,
|
||||
and the main function in func.c as used by funclist.c.
|
||||
|
||||
Added rule name to "DO NOT EDIT -- generated by the Makefile" lines
|
||||
in constructed files.
|
||||
|
||||
Test if <sys/vfs.h> exists and set HAVE_SYS_VFS_H accordingly
|
||||
in have_sys_vfs.h. Added HAVE_SYS_VFS_H to allow one to force
|
||||
this value.
|
||||
|
||||
Test if <sys/param.h> exists and set HAVE_SYS_PARAM_H accordingly
|
||||
in have_sys_param.h. Added HAVE_SYS_PARAM_H to allow one to force
|
||||
this value.
|
||||
|
||||
Test if <sys/mount.h> exists and set HAVE_SYS_MOUNT_H accordingly
|
||||
in have_sys_mount.h. Added HAVE_SYS_MOUNT_H to allow one to force
|
||||
this value.
|
||||
|
||||
Test if the system as the statfs() system call and set HAVE_STATFS
|
||||
accordingly in have_statfs.h. Added HAVE_STATFS to allow one
|
||||
to force this value.
|
||||
|
||||
The pseudo_seed() function will also try to call statfs() if
|
||||
possible and permitted by the HAVE_STATFS value.
|
||||
|
||||
Test if makedepend command is available before trying to build
|
||||
the Makefile dependency list via "make depend".
|
||||
|
||||
|
||||
The following are the changes from calc version 2.14.1.0 to 2.14.1.2:
|
||||
|
||||
Attempted to address a paranoid compiler warning -Wmaybe-uninitialized
|
||||
in swap_HALF_in_ZVALUE() where the gcc compiler seems to ignore the
|
||||
fact that calling not_reached() above the call to zcopyval()
|
||||
should prevent dest from being NULL to the 1st zcopyval() call.
|
||||
Thanks to <GitHub user mattdm> for raising this potential concern.
|
||||
|
||||
Fixed a -Wuse-after-free warning that identified a call to realloc()
|
||||
in find_tty_state() could move the fd_setup array. Thanks goes to
|
||||
<GitHub user mattdm> for reporting this bug!
|
||||
|
||||
In find_tty_state(), we changed how we expand fd_orig as an original
|
||||
pre-modified copy of fd_setup. We realloc the fd_orig array and copy
|
||||
the fd_setup into it first, before touching the fd_setup array.
|
||||
|
||||
In pseudo_seed(), we removed a call to setjmp() that was only
|
||||
there to add more information to mix into the seed. For compilers
|
||||
such as gcc that used -Wclobbered, the call to setjmp() gave the
|
||||
impression that the hash_val might be clobbered by a longjmp().
|
||||
Where there is no longjmp() that would use the previous setjmp(),
|
||||
the gcc compiler has nil ways to notice that. So to avoid confusion
|
||||
we removed the setjmp() call. Thanks to <GitHub user mattdm> for
|
||||
raising this potential concern.
|
||||
|
||||
Added config("tilde_space", boolean). The "tilde_space" controls
|
||||
whether or not a space (' ') is printed after leading tilde ('~').
|
||||
By default, config("tilde_space") is false.
|
||||
|
||||
For example, with the default, config("tilde_space", 0):
|
||||
|
||||
; 1/3
|
||||
~0.33333333333333333333
|
||||
; sqrt(7 + 5i,1e-100)
|
||||
~2.79305614578749801863+~0.89507688693280053094i
|
||||
|
||||
With config("tilde_space", 1):
|
||||
|
||||
; 1/3
|
||||
~ 0.33333333333333333333
|
||||
; sqrt(7 + 5i,1e-100)
|
||||
~ 2.79305614578749801863+~ 0.89507688693280053094i
|
||||
|
||||
NOTE: Use of config("tilde_space", 1) can break printing and scanning
|
||||
of complex values via "%c".
|
||||
|
||||
To enable "tilde_space", use config("tilde_space", 1) on the
|
||||
command line and/or use config("tilde_space", 1),; in your ~/.calcrc.
|
||||
Thanks goes to <GitHub use ljramalho> for this suggestion.
|
||||
|
||||
Added config("tilde_space", boolean) to help/config, along with
|
||||
a few few minor text improvements. Updated cal/regress to test
|
||||
config("tilde_space").
|
||||
|
||||
For example, with the default, config("tilde_space", 0):
|
||||
|
||||
; pi(1e-50)
|
||||
~3.14159265358979323846
|
||||
|
||||
With config("tilde_space", 1):
|
||||
|
||||
; pi(1e-50)
|
||||
~ 3.14159265358979323846
|
||||
|
||||
Added config("fraction_space", boolean). The "fraction_space" controls
|
||||
whether or not a space (' ') is printed before and after fractions.
|
||||
By default, config("fraction_space") is false.
|
||||
|
||||
For example, with the default, config("fraction_space", 0):
|
||||
|
||||
; base(1/3),
|
||||
; 1/7
|
||||
1/7
|
||||
|
||||
With config("fraction_space", 1):
|
||||
|
||||
; base(1/3),
|
||||
; 1/7
|
||||
1 / 7
|
||||
|
||||
NOTE: Use of config("fraction_space", 1) can break printing and scanning
|
||||
of fractional values via "%r".
|
||||
|
||||
NOTE: Use of config("fraction_space", 1) can break printing and scanning
|
||||
of complex values via "%c".
|
||||
|
||||
Added config("fraction_space", boolean) to help/config, along with
|
||||
a few few minor text improvements. Updated cal/regress to test
|
||||
config("tilde_space").
|
||||
|
||||
Added config("complex_space", boolean). The "complex_space" controls
|
||||
whether or not a space (' ') is printed before and after the + or -
|
||||
in complex values.
|
||||
|
||||
By default, config("complex_space") is false.
|
||||
|
||||
For example, with the default, config("complex_space", 0):
|
||||
|
||||
; asin(2)
|
||||
1.57079632679489661923-1.31695789692481670863i
|
||||
|
||||
With config("complex_space", 1):
|
||||
|
||||
; asin(2)
|
||||
1.57079632679489661923 - 1.31695789692481670863i
|
||||
|
||||
NOTE: Use of config("complex_space", 1) can break printing and scanning
|
||||
of fractional values via "%r".
|
||||
|
||||
NOTE: Use of config("complex_space", 1) can break printing and scanning
|
||||
of complex values via "%c".
|
||||
|
||||
Added config("complex_space", boolean) to help/config, along with
|
||||
a few few minor text improvements. Updated cal/regress to test
|
||||
config("complex_space").
|
||||
|
||||
Clarify in the calc man page, the relationship between -q and
|
||||
calc start scripts such as the ~/.calcrc file.
|
||||
|
||||
Fixed in the calc man page, the issue of -f not implying -q.
|
||||
|
||||
|
||||
The following are the changes from calc version 2.14.1.2 to date:
|
||||
|
||||
Restored use of the #define FPOS_POS_LEN symbol. This refers to
|
||||
the length of the __pos element (if the __pos element exists),
|
||||
the fpos_t type (if that type exists).
|
||||
|
||||
Changed SWAP_HALF_IN_FILEPOS(dest, src) mato to use FILEPOS_LEN Little
|
||||
Endian when FILEPOS is a simple scalar type (i.e., HAVE_FILEPOS_SCALAR
|
||||
is defined).
|
||||
|
||||
Changed #define HAVE_FPOS to HAVE_FGETSETPOS.
|
||||
|
||||
Corrected comment in have_fpos_pos.h. The HAVE_FPOS_POS symbol was
|
||||
NOT related to fgetpos & fsetpos but rather if we we have an __pos
|
||||
element in FILEPOS.
|
||||
|
||||
Changed #define HAVE_NO_FPOS to HAVE_NO_FGETSETPOS.
|
||||
|
||||
Improved comments in have_fpos_pos.h to show why and how
|
||||
HAVE_FPOS_POS, FPOS_POS_BITS, and FPOS_POS_LEN were defined or undefed.
|
||||
|
||||
Changed showfiles builtin to print sizes cast to (long int) with
|
||||
the "%ld" printf format to avoid implementations that do not support
|
||||
the "%lld" printf format specifier.
|
||||
|
||||
Renamed have_fpos.h to have_fgetsetpos.h. Renamed CALC_HAVE_FPOS_H
|
||||
to CALC_HAVE_FGETSETPOS_H. The make install and the olduninstall
|
||||
rules remove the any old have_fpos.h that was previously installed.
|
||||
|
||||
Added swap_HALFs(dest, src, len) function to byteswap.c.
|
||||
|
||||
Calc can now handle Big Engian file position sizes that are a
|
||||
multiple of BASEB bits in length. Before handle Big Engian file
|
||||
positions could only be 32 and 64 bits in length. This will allow,
|
||||
for example, a Big Engian file position size of 128 (assuming that
|
||||
128/BASEB is is an integer).
|
||||
|
||||
Temporary workaround for musl libc systems such as gentoo Linux that
|
||||
allows them to compile calc and successfully run the regression test.
|
||||
|
||||
|
||||
The following are the changes from calc version 2.14.1.1 to 2.14.1.1:
|
||||
|
||||
Added a few remarks on calc version numbers to version.c.
|
||||
|
||||
Fixed how fposval.h is built. On a number of systems, the fposval.c
|
||||
file failed to compile incorrectly. This caused problems for systems in
|
||||
which fposval.h.def was not correct.
|
||||
|
||||
Fixed how have_memmv.h is built. On a number of systems, the have_memmv.c
|
||||
file failed to compile incorrectly, producing a potentially incorrect
|
||||
have_memmv.h file for such systems.
|
||||
|
||||
Fixed how align32.h is built. On a number of systems, the align32.c
|
||||
file failed to compile incorrectly, producing a potentially incorrect
|
||||
align32.h file for such systems.
|
||||
|
||||
Fixed how have_newstr.h is built. On a number of systems, the have_newstr.c
|
||||
failed to compile incorrectly, producing a potentially incorrect
|
||||
have_newstr.h file for such systems.
|
||||
|
||||
Fixed how have_strdup.h is built. On a number of systems, the have_strdup.c
|
||||
file failed to compile incorrectly, producing a potentially incorrect
|
||||
have_strdup.h file for such systems.
|
||||
|
||||
Fixed how have_strlcat.h is built. On a number of systems, the have_strlcat.c
|
||||
file failed to compile incorrectly, producing a potentially incorrect
|
||||
have_strlcat.h file for such systems.
|
||||
|
||||
Fixed how have_strlcpy.h is built. On a number of systems, the have_strlcpy.c
|
||||
file failed to compile incorrectly, producing a potentially incorrect
|
||||
have_strlcpy.h file for such systems.
|
||||
|
||||
Fixed how have_uid_t.h is built. On a number of systems, the have_uid_t.c
|
||||
file failed to compile incorrectly, producing a potentially incorrect
|
||||
have_uid_t.h file for such systems.
|
||||
|
||||
Fixed how have_uid_t.h is built. On a number of systems, the have_uid_t.c
|
||||
file failed to compile incorrectly, producing a potentially incorrect
|
||||
have_uid_t.h file for such systems.
|
||||
|
||||
Added full_debug rule to Makefile. This does the work of the
|
||||
old debug rule in a more verbose mode by using Q= H=@ S= E= V=@.
|
||||
|
||||
The debug rule in the Makefile now pre-removes debug.out and then
|
||||
runs make full_debug sending stdout and stderr to debug.out. It then
|
||||
prints a few instructions about filing a GitHub issue bug report.
|
||||
|
||||
The full_debug rule will no longer stop when one of the sub-tasks
|
||||
failed (exit non-zero).
|
||||
|
||||
|
||||
The following are the changes from calc version 2.14.1.0 to 2.14.1.0:
|
||||
|
||||
Fixed alignment of show item section of help command.
|
||||
|
||||
Bug fix: While 0^0 == 1, now for y > 0, 0^y == 0.
|
||||
Adjusted cal/test8900.cal to reflect this bug fix.
|
||||
Added tests to cal/regress.cal to help verify bug fix is fixed.
|
||||
|
||||
Fixed a \-escape bug in calc(1) man page.
|
||||
|
||||
Added cal/comma.cal:
|
||||
|
||||
Convert numbers into strings with 3-digit group and integer-fraction
|
||||
separators.
|
||||
|
||||
If the value is an integer, the integer-fraction separator is not used.
|
||||
|
||||
str_comma(x, [group, [decimal]])
|
||||
|
||||
Convert x into a string.
|
||||
|
||||
If group is given and is a string, group will be used as
|
||||
the 3-digit group separator, otherwise the default 3-digit
|
||||
group separator will be used.
|
||||
|
||||
If decimal is given and is a string, group will be used as
|
||||
the integer-fraction separator, otherwise the default
|
||||
integer-fraction separator will be used.
|
||||
|
||||
The decimal and group arguments are optional.
|
||||
|
||||
set_default_group_separator(group)
|
||||
|
||||
Change the default 3-digit group separator if group is a string,
|
||||
otherwise the default 3-digit group separator will not be
|
||||
changed. Return the old 3-digit group separator.
|
||||
|
||||
set_default_decimal_separator(decimal)
|
||||
|
||||
Change the default 3-digit group separator if decimal is a
|
||||
string, otherwise the default integer-fraction separator
|
||||
will not be changed. Return the old integer-fraction separator.
|
||||
|
||||
print_comma(x, [group, [decimal]])
|
||||
|
||||
Print the value produced by str_comma(x, [group, [decimal]])
|
||||
followed by a newline.
|
||||
|
||||
If the str_comma() does not return a string, nothing is printed.
|
||||
|
||||
The decimal and group arguments are optional.
|
||||
|
||||
The value produced by str_comma() is returned.
|
||||
|
||||
fprint_comma(fd, x, [group, [decimal]])
|
||||
|
||||
Print the value produced by str_comma(x, [group, [decimal]]),
|
||||
without a trailing newline, on file fd.
|
||||
|
||||
If the str_comma() does not return a string, nothing is printed.
|
||||
|
||||
If fd is not an open file, nothing is printed.
|
||||
|
||||
The decimal and group arguments are optional.
|
||||
|
||||
The value produced by str_comma() is returned.
|
||||
|
||||
|
||||
The following are the changes from calc version 2.14.0.15 to 2.14.0.15:
|
||||
|
||||
Changed Makefile to set shell before setting the SHELL Makefile
|
||||
variable.
|
||||
|
||||
Added text to HOWTO.INSTALL to help people with systems that
|
||||
lack the readline package.
|
||||
|
||||
Trimmed long line in the CONTRIBUTING.md file.
|
||||
|
||||
Expanded the globalsymbol string table size: from 1024 to 65536.
|
||||
|
||||
Expanded the how often to reallocate string table is performed:
|
||||
from 100 to 1024.
|
||||
|
||||
Expanded the number env_pool elements to allocate at a time:
|
||||
from 10 to 256.
|
||||
|
||||
Improve comments on Makefile.local and add a few more examples
|
||||
of how it might be used.
|
||||
|
||||
Changed /*NOTREACHED*/ to not_reached(); and use "attribute.h".
|
||||
|
||||
Added .PHONY rule, just after all rule, to Makefiles.
|
||||
|
||||
Made minor format update on help/commands.
|
||||
|
||||
Added ${WINGM} Makefile variable for users under Windows 11 who
|
||||
use Cygwin and the MinGW64 packages.
|
||||
|
||||
Updated README.WINDOWS for Windows 11 users based on advice
|
||||
form a Microsoft 11 developer.
|
||||
|
||||
Fixed missing quotes in the PASSDOWN makefile variables.
|
||||
|
||||
Disable use of gettime() under _WIN32 or _WIN64.
|
||||
|
||||
|
||||
The following are the changes from calc version 2.14.0.14 to 2.14.0.14:
|
||||
|
||||
Fixed typo in Makefile.local comment.
|
||||
|
||||
@@ -1136,9 +1608,9 @@ The following are the changes from calc version 2.12.5.0 to 2.12.5.1:
|
||||
|
||||
There is a new calc bug report Email address:
|
||||
|
||||
calc-bug-report at asthe dot com
|
||||
NOTE: calc-bug-report Email address no longer in use
|
||||
|
||||
This replaces the old calc-bugs at asthe dot com address.
|
||||
This replaces the old calc-bugs Email address.
|
||||
|
||||
To be sure we see your Email reporting a calc bug, please use the
|
||||
following phase in your Email Subject line:
|
||||
@@ -1732,7 +2204,7 @@ The following are the changes from calc version 2.12.1.10 to 2.12.2:
|
||||
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
|
||||
NOTE: calc-contrib Email address no longer in use
|
||||
|
||||
Email address an "ifeq ($(target),YOUR_TARGET_NAME)"
|
||||
... "endif" set of lines from the Makefile so that
|
||||
@@ -3455,9 +3927,9 @@ The following are the changes from calc version 2.11.2t0 to 2.11.2t1.0:
|
||||
www.isthe.com. NOTE: The Email address uses 'asthe' and the web
|
||||
site URL uses 'isthe'.
|
||||
|
||||
Using calc-bugs at asthe dot com for calc bug reports,
|
||||
calc-contrib at asthe dot com for calc contributions,
|
||||
calc-tester-request at asthe dot com for requests to join calc-tester and
|
||||
NOTE: calc-bugs Email address no longer in use
|
||||
NOTE: calc-contrib Email address no longer in use
|
||||
NOTE: calc-tester-request Email address no longer in use
|
||||
|
||||
Replaced explicit Email addresses found this file with the <user at
|
||||
site dot domain> notation to reduce the potential for those folks
|
||||
@@ -8197,7 +8669,7 @@ Following is a list of visible changes to calc from version 1.24.7 to 1.26.1:
|
||||
|
||||
A small bug in the library file regress.cal was fixed.
|
||||
|
||||
## Copyright (C) 2001-2017,2021 Landon Curt Noll
|
||||
## Copyright (C) 2001-2017,2021,2022 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
|
||||
|
128
CODE_OF_CONDUCT.md
Normal file
128
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,128 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
https://github.com/lcn2/calc/blob/master/QUESTIONS.
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.0, available at
|
||||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||
|
||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||
enforcement ladder](https://github.com/mozilla/diversity).
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
https://www.contributor-covenant.org/faq. Translations are available at
|
||||
https://www.contributor-covenant.org/translations.
|
72
CONTRIB-CODE
72
CONTRIB-CODE
@@ -1,73 +1,37 @@
|
||||
Calc is open source. Contributions of code are welcome.
|
||||
|
||||
We welcome and encourage you to send us:
|
||||
In order to consider integrating your contributions, we need:
|
||||
|
||||
* calc resource files (cal/*.cal files)
|
||||
* calc shell scripts (cscript/*.calc files)
|
||||
* builtin functions that you have modified or written, i.e.:
|
||||
assocfunc.c comfunc.c func.c func.h
|
||||
listfunc.c matfunc.c qfunc.c zfunc.c
|
||||
* custom functions that you have modified or written
|
||||
* help files modified or written (help/*)
|
||||
* Makefile improvements (Makefile, */Makefile)
|
||||
* other source code modifications (*.c, *.h)
|
||||
* etc. (* */* :) )
|
||||
* your changes applied agsinst the top of the calc master branch:
|
||||
|
||||
In order to consider integrating your code, we need:
|
||||
https://github.com/lcn2/calc/
|
||||
|
||||
* calc version you are working with (please try use the latest version)
|
||||
* new help files or help file patches, if applicable (documentation)
|
||||
* proposed text for the CHANGES file (brief description of what it does)
|
||||
* regress.cal test patch as needed
|
||||
* your source code and/or source code changes (:-))
|
||||
|
||||
If you add functionality to calc, please be sure to modify/patch/add
|
||||
* Update CHANGES file (brief description of what it does)
|
||||
|
||||
* regress.cal test patch as needed
|
||||
|
||||
If you add functionality to calc, please be sure to modify
|
||||
Makefiles, help files, cal/regress.cal test code as well.
|
||||
Regression test cases are vital to maintaining calc's level
|
||||
of correctness and helps us avoid code bug regression.
|
||||
|
||||
Please try to generate a patch against the most recent
|
||||
version of calc, and if you use GitHub, the top of the
|
||||
master branch:
|
||||
|
||||
https://github.com/lcn2/calc
|
||||
|
||||
The best way contribute to calc bug is to generate calc
|
||||
GitHub pull request:
|
||||
GitHub pull request against the calc GitHub repo:
|
||||
|
||||
https://github.com/lcn2/calc/pulls
|
||||
|
||||
Please be patient as we cannot always respond pull requests quickly.
|
||||
|
||||
=-=
|
||||
|
||||
IMPORTANT:
|
||||
|
||||
Your code needs to be contributed under either the 2.1 of the GNU
|
||||
Lesser General Public License (LGPL 2.1) or in the public domain.
|
||||
Lesser General Public License (LGPL 2.1) or under "The Unlicense":
|
||||
|
||||
If you do not want to use calc GitHub, then send Email to:
|
||||
|
||||
calc-contrib-mail at asthe dot com
|
||||
|
||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
||||
|
||||
You MUST use following SPECIAL PHRASE in your Email Subject line:
|
||||
|
||||
calc contribution
|
||||
|
||||
You may add additional words to your subject line.
|
||||
|
||||
Suggestion:
|
||||
|
||||
From time to time, the Email address and Subject SPECIAL PHRASE
|
||||
may change so verify you have the current info by visiting:
|
||||
|
||||
http://www.isthe.com/chongo/tech/comp/calc/calc-contrib.html
|
||||
|
||||
IMPORTANT: If your Email doesn't contain the above phrase,
|
||||
then we WILL NOT SEE your Email.
|
||||
|
||||
PLEASE BE SURE you have that SPECIAL PHRASE somewhere in the subject line!
|
||||
|
||||
Keep in mind that the best way to report on a calc bug is to use
|
||||
the above mentioned calc GitHub procedure.
|
||||
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
https://unlicense.org
|
||||
|
||||
=-=
|
||||
|
||||
@@ -77,7 +41,7 @@ See also the calc wishlist by running the calc command:
|
||||
|
||||
=-=
|
||||
|
||||
## Copyright (C) 1999,2014,2021 Landon Curt Noll
|
||||
## Copyright (C) 1999,2014,2021,2023 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
|
||||
|
7
CONTRIBUTING.md
Normal file
7
CONTRIBUTING.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# How to contribue code to calc
|
||||
|
||||
## CONTRIB-CODE
|
||||
|
||||
See the file
|
||||
<A HREF="https://github.com/lcn2/calc/blob/master/CONTRIB-CODE">CONTRIB-CODE</A>
|
||||
for how to contribue code to calc.
|
19
COPYING
19
COPYING
@@ -4,9 +4,10 @@
|
||||
This file is Copyrighted
|
||||
------------------------
|
||||
|
||||
This file is not covered under version 2.1 of the GNU LGPL.
|
||||
This file is covered under the following Copyright:
|
||||
|
||||
Copyright (C) 1999-2021 Landon Curt Noll
|
||||
Copyright (C) 1999-2023 Landon Curt Noll
|
||||
All rights reserved.
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
@@ -120,11 +121,13 @@ Calc copyrights and exception files
|
||||
Copyright (C) year Ernest Bowen
|
||||
Copyright (C) year Petteri Kettunen and Landon Curt Noll
|
||||
Copyright (C) year Christoph Zurnieden
|
||||
Copyright (C) year Landon Curt Noll and Thomas Jones-Low
|
||||
Copyright (C) year Klaus Alexander Seistrup and Landon Curt Noll
|
||||
|
||||
These files are not covered under one of the Copyrights listed above:
|
||||
|
||||
sha1.c sha1.h COPYING
|
||||
COPYING-LGPL cal/qtime.cal cal/screen.cal
|
||||
COPYING-LGPL cal/screen.cal
|
||||
|
||||
The file COPYING-LGPL, which contains a copy of the version 2.1
|
||||
GNU Lesser General Public License, is itself Copyrighted by the
|
||||
@@ -136,8 +139,16 @@ Calc copyrights and exception files
|
||||
top of this file. It is important to note that you may distribute
|
||||
verbatim copies of this file but you may not modify this file.
|
||||
|
||||
Some of these exception files are in the public domain. Other files
|
||||
are under the LGPL but have different authors that those listed above.
|
||||
These files are covered under "The Unlicense":
|
||||
|
||||
sha1.c
|
||||
sha1.h
|
||||
cal/dotest.cal
|
||||
cal/screen.cal
|
||||
|
||||
For more information on this license, see:
|
||||
|
||||
https://unlicense.org
|
||||
|
||||
In all cases one may use and distribute these exception files freely.
|
||||
And because one may freely distribute the LGPL covered files, the
|
||||
|
116
HOWTO.INSTALL
116
HOWTO.INSTALL
@@ -47,22 +47,114 @@ or from:
|
||||
|
||||
4 steps:
|
||||
|
||||
(1) Look at the makefile, and adjust it to suit your needs.
|
||||
(1) Look at the makefile, and adjust it to suit your needs.
|
||||
|
||||
The top level Makefile and the custom/Makefile require a modern
|
||||
Make (such as gmake) or an equivalently advanced make. On many
|
||||
targets, the default make is sufficient. On FreeBSD for example,
|
||||
probably want to use gmake instead of make.
|
||||
|
||||
Some report that under macOS, one has to declare the target
|
||||
to be Darwin. So for macOS, one might have to do:
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
! By default, calc assumes you have the readline package installed !
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
! macOS does not have readline, so mac users need to make a choice !
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
# for macOS users only, force the target to be Darwin
|
||||
#
|
||||
make target=Darwin clobber
|
||||
make target=Darwin all
|
||||
make target=Darwin chk
|
||||
make target=Darwin install
|
||||
The readline package (-lreadline, -lhistory, -lncurses) used by and
|
||||
linked into calc by default. If your system does NOT have those
|
||||
libaraies, then you have two options:
|
||||
|
||||
(1-with readline) Install the readline package <- Recommended
|
||||
|
||||
Install the readline package first, then compile calc.
|
||||
|
||||
For information on the readline package, see:
|
||||
|
||||
https://tiswww.case.edu/php/chet/readline/rltop.html
|
||||
|
||||
MacOS users can use MacPorts or HomeBrew to install readline:
|
||||
|
||||
https://www.macports.org
|
||||
https://brew.sh
|
||||
|
||||
Or compile from the readline.git repo:
|
||||
|
||||
http://git.savannah.gnu.org/cgit/readline.git/
|
||||
|
||||
(1-w/o readline) Compile calc without readline (not recommended)
|
||||
|
||||
Why do we not recommend (1b)? Because using calc with readline
|
||||
provides a beter user experience.
|
||||
|
||||
If you feel you must use calc without the readline package, then you
|
||||
will need to change your calc Makefile with this patch:
|
||||
|
||||
--- Makefile.old 2021-12-29 14:57:56.000000000 -0800
|
||||
+++ Makefile 2021-12-29 14:59:13.000000000 -0800
|
||||
@@ -1140,14 +1140,14 @@
|
||||
#
|
||||
# If in doubt, set USE_READLINE, READLINE_LIB and READLINE_INCLUDE to nothing.
|
||||
#
|
||||
-#USE_READLINE=
|
||||
-USE_READLINE= -DUSE_READLINE
|
||||
+USE_READLINE=
|
||||
+#USE_READLINE= -DUSE_READLINE
|
||||
#
|
||||
-#READLINE_LIB=
|
||||
-#READLINE_EXTRAS=
|
||||
+READLINE_LIB=
|
||||
+READLINE_EXTRAS=
|
||||
#
|
||||
-READLINE_LIB= -lreadline
|
||||
-READLINE_EXTRAS= -lhistory -lncurses
|
||||
+#READLINE_LIB= -lreadline
|
||||
+#READLINE_EXTRAS= -lhistory -lncurses
|
||||
#
|
||||
#READLINE_LIB= -L/usr/gnu/lib -lreadline
|
||||
#READLINE_EXTRAS= -lhistory -lncurses
|
||||
@@ -1181,8 +1181,8 @@
|
||||
# # and using the readline, history, and ncurses libraries.
|
||||
# #
|
||||
ifneq ($(HOMEBREW_PREFIX),)
|
||||
-READLINE_LIB:= -L${HOMEBREW_PREFIX}/opt/readline/lib -lreadline
|
||||
-READLINE_INCLUDE:= -I${HOMEBREW_PREFIX}/opt/readline/include
|
||||
+#READLINE_LIB:= -L${HOMEBREW_PREFIX}/opt/readline/lib -lreadline
|
||||
+#READLINE_INCLUDE:= -I${HOMEBREW_PREFIX}/opt/readline/include
|
||||
endif
|
||||
#
|
||||
#endif /* end of skip for non-Gnu makefiles */
|
||||
|
||||
If your target system does not have a modern Makefile
|
||||
(such as gmake), then you will need to change your
|
||||
Makefile.simple with this patch:
|
||||
|
||||
--- Makefile.simple.orig 2021-12-29 15:00:53.000000000 -0800
|
||||
+++ Makefile.simple 2021-12-29 15:01:00.000000000 -0800
|
||||
@@ -1005,14 +1005,14 @@
|
||||
#
|
||||
# If in doubt, set USE_READLINE, READLINE_LIB and READLINE_INCLUDE to nothing.
|
||||
#
|
||||
-#USE_READLINE=
|
||||
-USE_READLINE= -DUSE_READLINE
|
||||
+USE_READLINE=
|
||||
+#USE_READLINE= -DUSE_READLINE
|
||||
#
|
||||
-#READLINE_LIB=
|
||||
-#READLINE_EXTRAS=
|
||||
+READLINE_LIB=
|
||||
+READLINE_EXTRAS=
|
||||
#
|
||||
-READLINE_LIB= -lreadline
|
||||
-READLINE_EXTRAS= -lhistory -lncurses
|
||||
+#READLINE_LIB= -lreadline
|
||||
+#READLINE_EXTRAS= -lhistory -lncurses
|
||||
#
|
||||
#READLINE_LIB= -L/usr/gnu/lib -lreadline
|
||||
#READLINE_EXTRAS= -lhistory -lncurses
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
! By default, calc assumes you are using a modern gnu-like make tool !
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
If your target system does not have a modern Makefile (such as gmake),
|
||||
then you should try using the Makefile.simple and custom/Makefile.simple
|
||||
@@ -212,15 +304,15 @@ or from:
|
||||
|
||||
(3) test calc:
|
||||
|
||||
make check
|
||||
make check
|
||||
|
||||
NOTE: For a quiet check which only prints if something goes wrong:
|
||||
|
||||
make chk
|
||||
make chk
|
||||
|
||||
(4) install calc:
|
||||
|
||||
make install
|
||||
make install
|
||||
|
||||
We suggest that you might want to read the README.FIRST file and look at
|
||||
the calc help subsystem. See also the README.md file.
|
||||
|
16
LIBRARY
16
LIBRARY
@@ -344,7 +344,7 @@ values of 0 and 1 are so common that special checks are made for them.
|
||||
|
||||
For initial values besides 0 or 1, you need to call itoz to convert a long
|
||||
value into a ZVALUE, as shown in the above example. Or alternatively,
|
||||
for larger numbers you can use the atoz routine to convert a string which
|
||||
for larger numbers you can use the str2z routine to convert a string which
|
||||
represents a number into a ZVALUE. The string can be in decimal, octal,
|
||||
hex, or binary according to the leading digits.
|
||||
|
||||
@@ -357,7 +357,7 @@ over a long sequence of operations.
|
||||
ZVALUE z1, z2, z3;
|
||||
|
||||
z1 = _one_;
|
||||
atoz("12345678987654321", &z2);
|
||||
str2z("12345678987654321", &z2);
|
||||
zadd(z1, z2, &z3);
|
||||
zfree(z1);
|
||||
zfree(z2);
|
||||
@@ -446,10 +446,10 @@ to free them first. The following illustrates this:
|
||||
itoz(55L, &q->num);
|
||||
|
||||
A better way to create NUMBERs with particular values is to use the itoq,
|
||||
iitoq, or atoq functions. Using itoq makes a long value into a NUMBER,
|
||||
iitoq, or str2q functions. Using itoq makes a long value into a NUMBER,
|
||||
using iitoq makes a pair of longs into the numerator and denominator of a
|
||||
NUMBER (reducing them first if needed), and atoq converts a string representing
|
||||
a number into the corresponding NUMBER. The atoq function accepts input in
|
||||
NUMBER (reducing them first if needed), and str2q converts a string representing
|
||||
a number into the corresponding NUMBER. The str2q function accepts input in
|
||||
integral, fractional, real, or exponential formats. Examples of allocating
|
||||
numbers are:
|
||||
|
||||
@@ -457,7 +457,7 @@ numbers are:
|
||||
|
||||
q1 = itoq(66L);
|
||||
q2 = iitoq(2L, 3L);
|
||||
q3 = atoq("456.78");
|
||||
q3 = str2q("456.78");
|
||||
|
||||
Also unlike ZVALUEs, NUMBERs are quickly copied. This is because they contain
|
||||
a link count, which is the number of pointers there are to the NUMBER. The
|
||||
@@ -504,8 +504,8 @@ For example, to calculate sin(0.5) to 100 decimal places, you could do:
|
||||
|
||||
NUMBER *q, *ans, *epsilon;
|
||||
|
||||
q = atoq("0.5");
|
||||
epsilon = atoq("1e-100");
|
||||
q = str2q("0.5");
|
||||
epsilon = str2q("1e-100");
|
||||
ans = qsin(q, epsilon);
|
||||
|
||||
There are many convenience macros similar to the ones for ZVALUEs which can
|
||||
|
@@ -1,3 +1,4 @@
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# Makefile.local - local Makefile variables
|
||||
#
|
||||
@@ -8,11 +9,32 @@
|
||||
# To replace a Makefile variable, use := symbols. For example:
|
||||
#
|
||||
# CCWERR:= -Werror
|
||||
#
|
||||
# NOTE: You need to remove the leading '#<whitespaces>' to take effect.
|
||||
# Comments start with a #-character.
|
||||
#
|
||||
|
||||
###################################################################
|
||||
# NOTE: For this and other commended out examples in this file, #
|
||||
# you need to remove the leading '#<whitespaces>' to take effect. #
|
||||
# #
|
||||
# Comments start with a #-character. #
|
||||
###################################################################
|
||||
|
||||
# You can append to an existing Makefile variable using '+=' symbols.
|
||||
# For example:
|
||||
#
|
||||
# CFLAGS+= -Ofast
|
||||
|
||||
# For example, a AddressSanitizer. You do NOT want to do this by
|
||||
# by default! Do this only if you are debugging with libasan:
|
||||
#
|
||||
# For Linux gcc version 11.3.1 with libasan-11.3.1-2.1 you might try:
|
||||
#
|
||||
# DEBUG:= -O0 -g
|
||||
# CFLAGS+= -fsanitize=address -fno-omit-frame-pointer
|
||||
# LDFLAGS+= -fsanitize=address -fno-omit-frame-pointer
|
||||
# CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1
|
||||
#
|
||||
# For macOS 13.2.1 with clang version 14.0.0 (clang-1400.0.29.202) you might try:
|
||||
#
|
||||
# DEBUG:= -O0 -g
|
||||
# CFLAGS+= -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
|
||||
# LDFLAGS+= -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
|
||||
# CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1
|
||||
|
781
Makefile.simple
781
Makefile.simple
File diff suppressed because it is too large
Load Diff
33
QUESTIONS
33
QUESTIONS
@@ -1,37 +1,28 @@
|
||||
If you have a simple general question about calc, send Email to:
|
||||
If you have a general question about calc, consider opening
|
||||
a new Github discussion under:
|
||||
|
||||
calc-quest-mail at asthe dot com
|
||||
https://github.com/lcn2/calc/discussions
|
||||
|
||||
NOTE: Remove spaces and replace 'at' with @, and 'dot' with .
|
||||
Look over the existing discussions to see of your question fits
|
||||
under one of those exiting discussions.
|
||||
|
||||
PLEASE put following the SPECIAL PHRASE somewhere in your Email Subject line:
|
||||
You may wish to add your question as a comment to an existing discussion.
|
||||
Otherwise click on:
|
||||
|
||||
calc question
|
||||
((New discussion))
|
||||
|
||||
You may add additional words to your subject line.
|
||||
|
||||
IMPORTANT: If your Email doesn't contain the above phrase,
|
||||
then we WILL NOT SEE your Email.
|
||||
|
||||
PLEASE BE SURE you have that SPECIAL PHRASE somewhere in the subject line!
|
||||
|
||||
Suggestion:
|
||||
|
||||
From time to time, the Email address and Subject SPECIAL PHRASE
|
||||
may change so verify you have the current info by visiting:
|
||||
|
||||
http://www.isthe.com/chongo/tech/comp/calc/calc-question.html
|
||||
and ask your question in that new discussion.
|
||||
|
||||
Please limit your questions to general questions about calc. We
|
||||
cannot go into great detail in our answers, nor can we do your
|
||||
homework, nor can we do much more than answer short general questions
|
||||
homework, nor can we do much more than answer general questions
|
||||
about calc.
|
||||
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
Please be patient as we cannot always respond to discussion messages quickly.
|
||||
|
||||
=-=
|
||||
|
||||
## Copyright (C) 2021 Landon Curt Noll
|
||||
## Copyright (C) 2021,2023 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
|
||||
|
165
README.WINDOWS
165
README.WINDOWS
@@ -3,16 +3,8 @@ 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.
|
||||
|
||||
BTW: While we are unable to use Windows 11, we welcome
|
||||
Windows 11 developers to try compiling calc natively
|
||||
(instead of via a Linux virtual machine). If you are
|
||||
able to compile Windows 11 natively, we would welcome
|
||||
GitHub pull requests showing any needed modifications:
|
||||
|
||||
https://github.com/lcn2/calc/pulls
|
||||
|
||||
Please also add notes to the 'Compiling calc under Windows 11'
|
||||
section in README.WINDOWS file.
|
||||
and 'Compiling with Cygwin' section in README.WINDOWS file.
|
||||
|
||||
NOTE: The main developers do not have access to a Windows based platform.
|
||||
While we will make an effort to not break calc Windows based system,
|
||||
@@ -21,81 +13,99 @@ NOTE: The main developers do not have access to a Windows based platform.
|
||||
Of course you are welcome to send us any patches that fix your
|
||||
Windows build environment.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= Compiling calc under Windows 11 =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
BTW: While we are unable to use Windows 11, we welcome Windows 11
|
||||
developers to try compiling calc natively (instead of via a Linux
|
||||
virtual machine). If you are able to compile Windows 11 natively,
|
||||
we would welcome GitHub pull requests showing any needed modifications:
|
||||
|
||||
https://github.com/lcn2/calc/pulls
|
||||
|
||||
We were given this advice from a Windows 11 developer:
|
||||
|
||||
Windows 11 users should try:
|
||||
Windows 11 users could use Cygwin:
|
||||
|
||||
https://git-scm.com/downloads
|
||||
https://cygwin.com/install.html
|
||||
|
||||
When you run the installer wizard, make sure you choose/check
|
||||
the git bash installer option.
|
||||
IMPORTANT: While installing Cygwin, and during Cygwin Setup, be sure to
|
||||
select all the MinGW64 packages relating to gcc.
|
||||
|
||||
https://www.mingw-w64.org/
|
||||
See the "Compiling with Cygwin" section below.
|
||||
|
||||
Runtime environment for GCC & LLVM for 32 and 64 bit Windows
|
||||
NOTE: Compiling calc under Windows 11 is work in progress. If you run into
|
||||
problems, consider the "Compiling with Cygwin" section below.
|
||||
|
||||
We suggest Windows 11 users consider using MINGW64.
|
||||
|
||||
We would prefer a Windows 11 solution that does not require a Windows 11
|
||||
developer to install a Linux virtual machine. Nevertheless, a Windows 11
|
||||
user might want to use the Microsoft Windows Subsystem (WSL) for Linux:
|
||||
|
||||
https://docs.microsoft.com/en-us/windows/wsl/
|
||||
|
||||
We have been told that you will need to turn on virtualization
|
||||
to use this WSL subsystem.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= Compiling calc under Windows 10 via Windows Subsystem for Linux (WSL) =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
It has been reported that calc version 2.12.6.4 has been successfully
|
||||
compiled, installed and running on Windows 10 on 2018 Jan 21.
|
||||
|
||||
We were told:
|
||||
|
||||
"The Windows Subsystem for Linux (WSL) is a new Windows 10 feature that
|
||||
enables you to run native Linux command-line tools directly on Windows"
|
||||
|
||||
https://docs.microsoft.com/cs-cz/windows/wsl/about
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= compiling with Cygwin =-=
|
||||
=-= Compiling with Cygwin =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
An effort is being made to allow windows users to compile calc using the
|
||||
Cygwin project (http://sources.redhat.com/cygwin/) with the GCC compiler
|
||||
and Un*x tools for Windows.
|
||||
and Unix tools for Windows.
|
||||
|
||||
The major porting work for Cygwin was performed by Thomas Jones-Low
|
||||
(tjoneslo at softstart dot com).
|
||||
|
||||
In March 2009, Michael Penk (mpenk at wuska dot com) reported success in
|
||||
installs under Cygwin:
|
||||
In December 2022, GitHub user @Leoongithub successfully compiled
|
||||
calc-2.14.1.2 under cygwin 2.924 (64 bit). The following are the
|
||||
compilation steps that GitHub user @Leoongithub recommends:
|
||||
|
||||
On my fairly complete Cygwin installs, everything compiles,
|
||||
checks, and installs correctly. My Cygwin is configured
|
||||
in a very standard way (out of the box, using all of Cygwin's
|
||||
defaults). The install worked on 5 different machines with
|
||||
Cygwin on them: one XP home, one XP professional, and three
|
||||
Vista professionals.
|
||||
0. Install the latest version of cygwin (https://cygwin.com/install.html).
|
||||
|
||||
Using the calc Makefile, he did the following:
|
||||
NOTE: In addition to the default packages, you also need to check these
|
||||
three packages: gcc-core, make, and libreadline-devel. The version
|
||||
of these packages does not matter. Just choose the latest version.
|
||||
|
||||
make all target=Cygwin
|
||||
make check
|
||||
make install
|
||||
NOTE: The addition of "target=Cygwin" to make commands below
|
||||
is done just in case the target is not set properly by make.
|
||||
|
||||
He also reports:
|
||||
1. Change (cd) into the top of the source code directory of calc.
|
||||
|
||||
Of course, one should be logged in as an Administrator when
|
||||
one builds and installs calc.
|
||||
NOTE: The make command assume you are at the top of the calc source directory.
|
||||
|
||||
2. make clobber target=Cygwin
|
||||
|
||||
NOTE: This helps ensure that you are starting from a so-called "clean slate",
|
||||
and that you have nothing hanging around from previous attempts to compile.
|
||||
|
||||
3. make all target=Cygwin
|
||||
|
||||
NOTE: If successful, you should have a calc executable. However that executable
|
||||
may not be working properly. Advance to step (4) to test.
|
||||
|
||||
4. make chk target=Cygwin
|
||||
|
||||
NOTE: If you want this command be be verbose, try:
|
||||
|
||||
make check target=Cygwin
|
||||
|
||||
NOTE: This will run calc with the regress.cal regression suite. This step could take
|
||||
for a while to run, depending on the speed/performance of your machine.
|
||||
If all is well (all regression tests pass), you will see at the end:
|
||||
|
||||
chk OK
|
||||
|
||||
Otherwise you may see calc exit non-zero after it prints some lines with '****'
|
||||
error messages followed by a line including a final error count of the form:
|
||||
|
||||
**** 2 error(s) found \/++\/
|
||||
|
||||
If you see some errors that may relate to files and I/O, all may not be lost.
|
||||
It could simply mean that your Windows environment is not conforming to standard
|
||||
I/O and file operations. The calc mathematical engine may be just fine. On the
|
||||
other hand if you see mathematical related regression test failures, this is
|
||||
bad sign that your calc executable under Windows is not usable.
|
||||
|
||||
5. make install target=Cygwin
|
||||
|
||||
NOTE: This step is optional. While calc is usable at the top of the source code directory
|
||||
of calc, installing calc may be of benefit so you can use calc elsewhere on your system.
|
||||
|
||||
He was compiling calc 2.12.4.0 with Cygwin version 1.5.25-15.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= If all else fails, for Cygwin =-=
|
||||
@@ -120,6 +130,10 @@ In particular:
|
||||
source directory, edit them (if needed) and build using the
|
||||
Cygwin GCC compiler and Cygwin build environment.
|
||||
|
||||
NOTE: The use of win32_hsrc and this method has been deprecated.
|
||||
It may go away once the Windows 11 methods are stable.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= compiling under DJGPP =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
@@ -180,8 +194,43 @@ Look for Makefile comments of the form:
|
||||
Follow those recommendations. In cases where they conflict with
|
||||
the above Makefile list, follow the recommendation in the Makefile.
|
||||
|
||||
NOTE: The use of DJGPP and this method has been deprecated.
|
||||
It may go away once the Windows 11 methods are stable.
|
||||
|
||||
## Copyright (C) 2002-2009,2021 Landon Curt Noll and Thomas Jones-Low
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= Compiling calc via virtual machine under Windows 11 =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
We would prefer a Windows 11 solution that does not require a Windows 11
|
||||
developer to install a Linux virtual machine. Nevertheless, a Windows 11
|
||||
user might want to use the Microsoft Windows Subsystem (WSL) for Linux:
|
||||
|
||||
https://docs.microsoft.com/en-us/windows/wsl/
|
||||
|
||||
We have been told that you will need to turn on virtualization
|
||||
to use this WSL subsystem.
|
||||
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
=-= Compiling calc under Windows 10 via Windows Subsystem for Linux (WSL) =-=
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
It has been reported that calc version 2.12.6.4 has been successfully
|
||||
compiled, installed and running on Windows 10 on 2018 Jan 21.
|
||||
|
||||
We were told:
|
||||
|
||||
"The Windows Subsystem for Linux (WSL) is a new Windows 10 feature that
|
||||
enables you to run native Linux command-line tools directly on Windows"
|
||||
|
||||
https://docs.microsoft.com/cs-cz/windows/wsl/about
|
||||
|
||||
NOTE: The use of calc under Windows 10 has been deprecated in favor of one
|
||||
of the Windows 11 methods above.
|
||||
|
||||
|
||||
## Copyright (C) 2002-2009,2021,2022 Landon Curt Noll and Thomas Jones-Low
|
||||
##
|
||||
## 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
|
||||
|
22
README.md
22
README.md
@@ -1,3 +1,25 @@
|
||||
# TL;DR Try calc
|
||||
|
||||
## TL;DR Install calc
|
||||
|
||||
```
|
||||
misc linux: sudo yum install calc
|
||||
on Debian: sudo apt install calc
|
||||
on RHEL: sudo dnf install calc
|
||||
on Ubuntu: sudo apt install calc
|
||||
via Termux: apt install calc
|
||||
via src: sudo make clobber all chk instsll
|
||||
```
|
||||
|
||||
## TL;DR Run calc
|
||||
|
||||
```
|
||||
misc shell: calc
|
||||
via bash: calc
|
||||
via misc app: launch calc via Termux
|
||||
via zsh: calc
|
||||
```
|
||||
|
||||
# What is calc?
|
||||
|
||||
Calc is an interactive calculator which provides for easy large
|
||||
|
13
SECURITY.md
13
SECURITY.md
@@ -6,9 +6,14 @@ The most recent version of calc is supported with security updates.
|
||||
|
||||
If the most recent stable of calc is also supported with security updates.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
To report a vulnerability, please review the BUGS file, or enter
|
||||
the calc command:
|
||||
FYI: please review the BUGS file, or enter the calc command:
|
||||
|
||||
; help BUGS
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please create a calc GitHub repo issue:
|
||||
|
||||
https://github.com/lcn2/calc/issues
|
||||
|
||||
Click on ((New issue)) and follow the issue template.
|
||||
|
21
addop.c
21
addop.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* addop - add opcodes to a function being compiled
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
|
||||
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
*
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "symbol.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -68,12 +69,12 @@ initfunctions(void)
|
||||
functemplate = (FUNC *) malloc(funcsize(maxopcodes));
|
||||
if (functemplate == NULL) {
|
||||
math_error("Cannot allocate function template");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
functions = (FUNC **) malloc(sizeof(FUNC *) * FUNCALLOCSIZE);
|
||||
if (functions == NULL) {
|
||||
math_error("Cannot allocate function table");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
funccount = 0;
|
||||
funcavail = FUNCALLOCSIZE;
|
||||
@@ -155,7 +156,7 @@ beginfunc(char *name, BOOL newflag)
|
||||
fp = (FUNC *) malloc(funcsize(maxopcodes));
|
||||
if (fp == NULL) {
|
||||
math_error("Cannot allocate temporary function");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
fp->f_next = NULL;
|
||||
@@ -203,7 +204,7 @@ endfunc(void)
|
||||
fp = (FUNC *) malloc(size);
|
||||
if (fp == NULL) {
|
||||
math_error("Cannot commit function");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
memcpy((char *) fp, (char *) curfunc, size);
|
||||
if (curfunc != functemplate)
|
||||
@@ -257,13 +258,13 @@ adduserfunc(char *name)
|
||||
sizeof(FUNC *) * (funcavail + FUNCALLOCSIZE));
|
||||
if (functions == NULL) {
|
||||
math_error("Failed to reallocate function table");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
funcavail += FUNCALLOCSIZE;
|
||||
}
|
||||
if (addstr(&funcnames, name) == NULL) {
|
||||
math_error("Cannot save function name");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
index = funccount++;
|
||||
functions[index] = NULL;
|
||||
@@ -316,7 +317,7 @@ freefunc(FUNC *fp)
|
||||
}
|
||||
if (index == funccount) {
|
||||
math_error("Bad call to freefunc!!!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) {
|
||||
@@ -386,7 +387,7 @@ findfunc(long index)
|
||||
{
|
||||
if (index >= funccount) {
|
||||
math_error("Undefined function");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return functions[index];
|
||||
}
|
||||
@@ -438,7 +439,7 @@ addop(long op)
|
||||
fp = (FUNC *) malloc(funcsize(maxopcodes));
|
||||
if (fp == NULL) {
|
||||
math_error("cannot malloc function");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
memcpy((char *) fp, (char *) curfunc,
|
||||
funcsize(curfunc->f_opcodecount));
|
||||
|
13
align32.c
13
align32.c
@@ -27,6 +27,11 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include "have_stdlib.h"
|
||||
#if defined(HAVE_STDLIB_H)
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "longbits.h"
|
||||
|
||||
#include "have_unistd.h"
|
||||
@@ -34,11 +39,13 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
static void buserr(void); /* catch alignment errors */
|
||||
static void buserr(int arg); /* catch alignment errors */
|
||||
|
||||
|
||||
int
|
||||
@@ -46,7 +53,7 @@ main(void)
|
||||
{
|
||||
char byte[2*sizeof(USB32)]; /* mis-alignment buffer */
|
||||
USB32 *p; /* mis-alignment pointer */
|
||||
int i;
|
||||
unsigned long i;
|
||||
|
||||
#if defined(MUST_ALIGN32)
|
||||
/* force alignment */
|
||||
@@ -82,7 +89,7 @@ main(void)
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
static void
|
||||
buserr(int arg)
|
||||
buserr(int UNUSED(arg))
|
||||
{
|
||||
/* alignment is required */
|
||||
printf("#define MUST_ALIGN32\t%c* must align 32 bit values *%c\n",
|
||||
|
23
assocfunc.c
23
assocfunc.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* assocfunc - association table routines
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell
|
||||
* Copyright (C) 1999-2007,2021,2022 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
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "value.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -74,7 +75,7 @@ associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices)
|
||||
|
||||
if (dim < 0) {
|
||||
math_error("Negative dimension for indexing association");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -112,7 +113,7 @@ associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices)
|
||||
ep = (ASSOCELEM *) malloc(ELEMSIZE(dim));
|
||||
if (ep == NULL) {
|
||||
math_error("Cannot allocate association element");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
ep->e_dim = dim;
|
||||
ep->e_hash = hash;
|
||||
@@ -142,13 +143,13 @@ assocsearch(ASSOC *ap, VALUE *vp, long i, long j, ZVALUE *index)
|
||||
|
||||
if (i < 0 || j > ap->a_count) {
|
||||
math_error("This should not happen in assocsearch");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
while (i < j) {
|
||||
ep = elemindex(ap, i);
|
||||
if (ep == NULL) {
|
||||
math_error("This should not happen in assocsearch");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (acceptvalue(&ep->e_value, vp)) {
|
||||
utoz(i, index);
|
||||
@@ -172,14 +173,14 @@ assocrsearch(ASSOC *ap, VALUE *vp, long i, long j, ZVALUE *index)
|
||||
|
||||
if (i < 0 || j > ap->a_count) {
|
||||
math_error("This should not happen in assocsearch");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
j--;
|
||||
while (j >= i) {
|
||||
ep = elemindex(ap, j);
|
||||
if (ep == NULL) {
|
||||
math_error("This should not happen in assocsearch");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (acceptvalue(&ep->e_value, vp)) {
|
||||
utoz(j, index);
|
||||
@@ -333,7 +334,7 @@ assoccopy(ASSOC *oldap)
|
||||
if (ep == NULL) {
|
||||
math_error("Cannot allocate "
|
||||
"association element");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
ep->e_dim = oldep->e_dim;
|
||||
ep->e_hash = oldep->e_hash;
|
||||
@@ -374,7 +375,7 @@ resize(ASSOC *ap, long newsize)
|
||||
newtable = (ASSOCELEM **) malloc(sizeof(ASSOCELEM *) * newsize);
|
||||
if (newtable == NULL) {
|
||||
math_error("No memory to grow association");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
for (i = 0; i < newsize; i++)
|
||||
newtable[i] = NULL;
|
||||
@@ -430,7 +431,7 @@ assocalloc(long initsize)
|
||||
ap = (ASSOC *) malloc(sizeof(ASSOC));
|
||||
if (ap == NULL) {
|
||||
math_error("No memory for association");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
ap->a_count = 0;
|
||||
ap->a_size = initsize;
|
||||
@@ -438,7 +439,7 @@ assocalloc(long initsize)
|
||||
if (ap->a_table == NULL) {
|
||||
free((char *) ap);
|
||||
math_error("No memory for association");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
for (i = 0; i < initsize; i++)
|
||||
ap->a_table[i] = NULL;
|
||||
|
69
attribute.h
Normal file
69
attribute.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* attribute - control use of attributes in a backward compatible way
|
||||
*
|
||||
* Copyright (C) 2022 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: 2022/01/21 22:51:25
|
||||
* File existed as early as: 2022
|
||||
*
|
||||
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
|
||||
#if !defined(INCLUDE_ATTRIBUTE_H)
|
||||
#define INCLUDE_ATTRIBUTE_H
|
||||
|
||||
|
||||
/*
|
||||
* backward compatibility
|
||||
*
|
||||
* Not all compilers support __attribute__ nor do they suuport __has_builtin.
|
||||
* For example, MSVC, TenDRAm and Little C Compiler doesn't support __attribute__.
|
||||
* Early gcc does not support __attribute__.
|
||||
*
|
||||
* Not all compiles have __has_builtin
|
||||
*/
|
||||
#if !defined(__attribute__) && \
|
||||
(defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
|
||||
# define __attribute__(A)
|
||||
#endif
|
||||
#if !defined __has_builtin
|
||||
# define __has_builtin(x) 0
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* not_reached
|
||||
*
|
||||
* In the old days of lint, one could give lint and friends a hint by
|
||||
* placing the token NOTREACHED immediately between opening and closing
|
||||
* comments. Modern compilers do not honor such commented tokens
|
||||
* and instead rely on features such as __builtin_unreachable
|
||||
* and __attribute__((noreturn)).
|
||||
*
|
||||
* The not_reached will either yield a __builtin_unreachable() feature call,
|
||||
* or it will call abort from stdlib.
|
||||
*/
|
||||
#if __has_builtin(__builtin_unreachable)
|
||||
# define not_reached() __builtin_unreachable()
|
||||
#else
|
||||
# define not_reached() abort()
|
||||
#endif /* __has_builtin(__builtin_unreachable) */
|
||||
|
||||
|
||||
#endif /* !INCLUDE_ATTRIBUTE_H */
|
29
blkcpy.c
29
blkcpy.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* blkcpy - general values and related routines used by the calculator
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 Landon Curt Noll and Ernest Bowen
|
||||
* Copyright (C) 1999-2007,2021,2022 Landon Curt Noll and Ernest Bowen
|
||||
*
|
||||
* Primary author: Landon Curt Noll
|
||||
*
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "str.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -298,7 +299,7 @@ copymat2mat(MATRIX *smat, long ssi, long num, MATRIX *dmat, long dsi)
|
||||
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
||||
if (vtemp == NULL) {
|
||||
math_error("Out of memory for mat-to-mat copy");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
vp = smat->m_table + ssi;
|
||||
vq = vtemp;
|
||||
@@ -347,7 +348,7 @@ copyblk2mat(BLOCK *blk, long ssi, long num, MATRIX *dmat, long dsi)
|
||||
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
||||
if (vtemp == NULL) {
|
||||
math_error("Out of memory for block-to-matrix copy");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
vp = vtemp;
|
||||
i = num;
|
||||
@@ -404,7 +405,7 @@ copymat2blk(MATRIX *smat, long ssi, long num, BLOCK *dblk, long dsi,
|
||||
newdata = (USB8*) realloc(dblk->data, newsize);
|
||||
if (newdata == NULL) {
|
||||
math_error("Out of memory for matrix-to-block copy");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
dblk->data = newdata;
|
||||
dblk->maxsize = newsize;
|
||||
@@ -447,7 +448,7 @@ copymat2list(MATRIX *smat, long ssi, long num, LIST *lp, long dsi)
|
||||
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
||||
if (vtemp == NULL) {
|
||||
math_error("Out of memory for matrix-to-list copy");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
vp = smat->m_table + ssi;
|
||||
vq = vtemp;
|
||||
@@ -497,7 +498,7 @@ copylist2mat(LIST *lp, long ssi, long num, MATRIX *dmat, long dsi)
|
||||
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
||||
if (vtemp == NULL) {
|
||||
math_error("Out of memory for list-to-matrix copy");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
ep = listelement(lp, (long) ssi);
|
||||
vp = vtemp;
|
||||
@@ -547,7 +548,7 @@ copylist2list(LIST *slp, long ssi, long num, LIST *dlp, long dsi)
|
||||
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
||||
if (vtemp == NULL) {
|
||||
math_error("Out of memory for list-to-list copy");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
sep = listelement(slp, (long) ssi);
|
||||
vp = vtemp;
|
||||
@@ -662,7 +663,7 @@ copyfile2blk(FILEID id, long ssi, long num, BLOCK *dblk, long dsi, BOOL noreloc)
|
||||
newdata = (USB8*) realloc(dblk->data, newsize);
|
||||
if (newdata == NULL) {
|
||||
math_error("Out of memory for block-to-block copy");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
dblk->data = newdata;
|
||||
dblk->maxsize = newsize;
|
||||
@@ -748,7 +749,7 @@ copyblk2blk(BLOCK *sblk, long ssi, long num, BLOCK *dblk, long dsi,
|
||||
newdata = (USB8*) realloc(dblk->data, newsize);
|
||||
if (newdata == NULL) {
|
||||
math_error("Out of memory for block-to-block copy");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
dblk->data = newdata;
|
||||
dblk->maxsize = newsize;
|
||||
@@ -792,7 +793,7 @@ copystr2blk(STRING *str, long ssi, long num, BLOCK *dblk, long dsi,
|
||||
newdata = (USB8*) realloc(dblk->data, newsize);
|
||||
if (newdata == NULL) {
|
||||
math_error("Out of memory for string-to-block copy");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
dblk->data = newdata;
|
||||
dblk->maxsize = newsize;
|
||||
@@ -913,7 +914,7 @@ copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,BOOL noreloc)
|
||||
newdata = (USB8*) realloc(dblk->data, newsize);
|
||||
if (newdata == NULL) {
|
||||
math_error("Out of memory for string-to-block copy");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
dblk->data = newdata;
|
||||
dblk->maxsize = newsize;
|
||||
@@ -945,7 +946,7 @@ memmove(void *s1, CONST void *s2, MEMMOVE_SIZE_T n)
|
||||
*/
|
||||
if (s1 == NULL || s2 == NULL) {
|
||||
math_error("bogus memmove NULL ptr");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (n <= 0) {
|
||||
/* neg or 0 count does nothing */
|
||||
@@ -1015,7 +1016,7 @@ copynum2blk(NUMBER *snum, long ssi, long num, BLOCK *dblk, long dsi,
|
||||
newdata = (USB8*) realloc(dblk->data, newsize);
|
||||
if (newdata == NULL) {
|
||||
math_error("Out of memory for num-to-block copy");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
dblk->data = newdata;
|
||||
dblk->maxsize = newsize;
|
||||
@@ -1086,7 +1087,7 @@ copyblk2num(BLOCK *sblk, long ssi, long num, NUMBER *dnum, long dsi,
|
||||
swapped = (HALF *)malloc(halflen * sizeof(HALF));
|
||||
if (swapped == NULL) {
|
||||
math_error("Out of memory for block-to-num copy");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
/* ensure that any trailing octets will be zero filled */
|
||||
swapped[halflen-1] = 0;
|
||||
|
39
block.c
39
block.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* block - fixed, dynamic, fifo and circular memory blocks
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 Landon Curt Noll and Ernest Bowen
|
||||
* Copyright (C) 1999-2007,2021,2022 Landon Curt Noll and Ernest Bowen
|
||||
*
|
||||
* Primary author: Landon Curt Noll
|
||||
*
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "calcerr.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -87,7 +88,7 @@ blkalloc(int len, int chunk)
|
||||
nblk = (BLOCK *)malloc(sizeof(BLOCK));
|
||||
if (nblk == NULL) {
|
||||
math_error("cannot allocate block");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -98,7 +99,7 @@ blkalloc(int len, int chunk)
|
||||
nblk->data = (USB8*)malloc(nblk->maxsize);
|
||||
if (nblk->data == NULL) {
|
||||
math_error("cannot allocate block data storage");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
memset(nblk->data, 0, nblk->maxsize);
|
||||
nblk->datalen = len;
|
||||
@@ -172,7 +173,7 @@ blkchk(BLOCK *blk)
|
||||
}
|
||||
if (blk == NULL) {
|
||||
math_error("internal: blk ptr is NULL");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -180,7 +181,7 @@ blkchk(BLOCK *blk)
|
||||
*/
|
||||
if (blk->data == NULL) {
|
||||
math_error("internal: blk->data ptr is NULL");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -188,7 +189,7 @@ blkchk(BLOCK *blk)
|
||||
*/
|
||||
if (blk->datalen < 0) {
|
||||
math_error("internal: blk->datalen < 0");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -196,7 +197,7 @@ blkchk(BLOCK *blk)
|
||||
*/
|
||||
if (blk->datalen < 0) {
|
||||
math_error("internal: blk->datalen < 0");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -259,7 +260,7 @@ blkrealloc(BLOCK *blk, int newlen, int newchunk)
|
||||
nblk = (USB8*)realloc(blk->data, newmax);
|
||||
if (nblk == NULL) {
|
||||
math_error("cannot reallocate block storage");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/* clear any new storage */
|
||||
@@ -367,7 +368,7 @@ blktrunc(BLOCK *blk)
|
||||
blk->data = (USB8*)malloc(1);
|
||||
if (blk->data == NULL) {
|
||||
math_error("cannot allocate truncated block storage");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
blk->data[0] = (USB8)0;
|
||||
if (conf->calc_debug & CALCDBG_BLOCK) {
|
||||
@@ -397,7 +398,7 @@ blk_copy(BLOCK *blk)
|
||||
nblk = (BLOCK *)malloc(sizeof(BLOCK));
|
||||
if (nblk == NULL) {
|
||||
math_error("blk_copy: cannot malloc BLOCK");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -411,7 +412,7 @@ blk_copy(BLOCK *blk)
|
||||
nblk->data = (USB8 *)malloc(blk->maxsize);
|
||||
if (nblk->data == NULL) {
|
||||
math_error("blk_copy: cannot duplicate block data");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
memcpy(nblk->data, blk->data, blk->maxsize);
|
||||
return nblk;
|
||||
@@ -539,7 +540,7 @@ reallocnblock(int id, int len, int chunk)
|
||||
/* Fire wall */
|
||||
if (id < 0 || id >= nblockcount) {
|
||||
math_error("Bad id in call to reallocnblock");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
blk = nblocks[id]->blk;
|
||||
@@ -556,13 +557,13 @@ reallocnblock(int id, int len, int chunk)
|
||||
newdata = malloc(newsize);
|
||||
if (newdata == NULL) {
|
||||
math_error("Allocation failed");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
} else if (newsize != oldsize) {
|
||||
newdata = realloc(blk->data, newsize);
|
||||
if (newdata == NULL) {
|
||||
math_error("Reallocation failed");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
memset(newdata + len, 0, newsize - len);
|
||||
@@ -593,7 +594,7 @@ createnblock(char *name, int len, int chunk)
|
||||
if (nblocks == NULL) {
|
||||
maxnblockcount = 0;
|
||||
math_error("unable to malloc new named blocks");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
} else {
|
||||
maxnblockcount += NBLOCKCHUNK;
|
||||
@@ -602,7 +603,7 @@ createnblock(char *name, int len, int chunk)
|
||||
if (nblocks == NULL) {
|
||||
maxnblockcount = 0;
|
||||
math_error("cannot malloc more named blocks");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -610,18 +611,18 @@ createnblock(char *name, int len, int chunk)
|
||||
initstr(&nblocknames);
|
||||
if (findstr(&nblocknames, name) >= 0) {
|
||||
math_error("Named block already exists!!!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
newname = addstr(&nblocknames, name);
|
||||
if (newname == NULL) {
|
||||
math_error("Block name allocation failed");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
res = (NBLOCK *) malloc(sizeof(NBLOCK));
|
||||
if (res == NULL) {
|
||||
math_error("Named block allocation failed");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
nblocks[nblockcount] = res;
|
||||
|
71
byteswap.c
71
byteswap.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* byteswap - byte swapping routines
|
||||
*
|
||||
* Copyright (C) 1999,2021 Landon Curt Noll
|
||||
* Copyright (C) 1999,2021,2022 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
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "byteswap.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -39,7 +40,7 @@
|
||||
* dest - pointer to where the swapped src will be put or
|
||||
* NULL to allocate the storage
|
||||
* src - pointer to a HALF array to swap
|
||||
* len - length of the src HALF array
|
||||
* len - length of the src HALF array in HALFs
|
||||
*
|
||||
* returns:
|
||||
* pointer to where the swapped src has been put
|
||||
@@ -103,7 +104,7 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
if (dest == NULL) {
|
||||
math_error("swap_b8_in_ZVALUE: swap_b8_in_ZVALUE: "
|
||||
"Not enough memory");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -170,7 +171,7 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
dest = malloc(sizeof(NUMBER));
|
||||
if (dest == NULL) {
|
||||
math_error("swap_b8_in_NUMBER: Not enough memory");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -234,7 +235,7 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
||||
dest = malloc(sizeof(COMPLEX));
|
||||
if (dest == NULL) {
|
||||
math_error("swap_b8_in_COMPLEX: Not enough memory");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -275,7 +276,7 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
||||
* dest - pointer to where the swapped src will be put or
|
||||
* NULL to allocate the storage
|
||||
* src - pointer to a HALF array to swap
|
||||
* len - length of the src HALF array
|
||||
* len - length of the src HALF array in HALFs
|
||||
*
|
||||
* returns:
|
||||
* pointer to where the swapped src has been put
|
||||
@@ -308,6 +309,50 @@ swap_b16_in_HALFs(HALF *dest, HALF *src, LEN len)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* swap_HALFs - swap HALFs in an array of HALFs
|
||||
*
|
||||
* given:
|
||||
* dest - pointer to where the swapped src will be put or
|
||||
* NULL to allocate the storage
|
||||
* src - pointer to a HALF array to swap
|
||||
* len - length of the src HALF array in HALFs
|
||||
*
|
||||
* returns:
|
||||
* pointer to where the swapped src has been put
|
||||
*/
|
||||
HALF *
|
||||
swap_HALFs(HALF *dest, HALF *src, LEN len)
|
||||
{
|
||||
HALF *s; /* src swap pointer */
|
||||
HALF *d; /* dest swap pointer */
|
||||
HALF *ret;
|
||||
LEN i;
|
||||
|
||||
/*
|
||||
* allocate storage if needed
|
||||
*/
|
||||
if (dest == NULL) {
|
||||
dest = alloc(len);
|
||||
}
|
||||
ret = dest;
|
||||
|
||||
/*
|
||||
* swap HALFs in the array
|
||||
*/
|
||||
s = src;
|
||||
d = &dest[len-1];
|
||||
for (i=0; i < len; ++i, --d, ++s) {
|
||||
*d = *s;
|
||||
}
|
||||
|
||||
/*
|
||||
* return the result
|
||||
*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* swap_b16_in_ZVALUE - swap 16 bits in a ZVALUE
|
||||
*
|
||||
@@ -338,7 +383,7 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
dest = malloc(sizeof(ZVALUE));
|
||||
if (dest == NULL) {
|
||||
math_error("swap_b16_in_ZVALUE: Not enough memory");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -405,7 +450,7 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
dest = malloc(sizeof(NUMBER));
|
||||
if (dest == NULL) {
|
||||
math_error("swap_b16_in_NUMBER: Not enough memory");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -469,7 +514,7 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
||||
dest = malloc(sizeof(COMPLEX));
|
||||
if (dest == NULL) {
|
||||
math_error("swap_b16_in_COMPLEX: Not enough memory");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -530,10 +575,10 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
||||
/*
|
||||
* allocate the storage
|
||||
*/
|
||||
dest = malloc(sizeof(ZVALUE));
|
||||
dest = calloc(1, sizeof(ZVALUE));
|
||||
if (dest == NULL) {
|
||||
math_error("swap_HALF_in_ZVALUE: Not enough memory");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -601,7 +646,7 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
||||
dest = malloc(sizeof(NUMBER));
|
||||
if (dest == NULL) {
|
||||
math_error("swap_HALF_in_NUMBER: Not enough memory");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -665,7 +710,7 @@ swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
||||
dest = malloc(sizeof(COMPLEX));
|
||||
if (dest == NULL) {
|
||||
math_error("swap_HALF_in_COMPLEX: Not enough memory");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
|
50
cal/Makefile
50
cal/Makefile
@@ -1,8 +1,8 @@
|
||||
#!/bin/make
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# cal - makefile for calc standard resource files
|
||||
#
|
||||
# Copyright (C) 1999-2006,2017,2021 Landon Curt Noll
|
||||
# Copyright (C) 1999-2006,2017,2021-2023 Landon Curt Noll
|
||||
#
|
||||
# SRC: cal/Makefile
|
||||
#
|
||||
@@ -44,20 +44,21 @@
|
||||
# If your system has a up to date, bash shell, then
|
||||
# you may wish to use:
|
||||
#
|
||||
# SHELL= /bin/bash
|
||||
# SHELL= bash
|
||||
#
|
||||
# On some systems such as macOS, the bash shell is very
|
||||
# far behind to the point where is cannot be depended on.
|
||||
# On such systems, the sh may be a much better alternative
|
||||
# shell for this Makefile to use:
|
||||
#
|
||||
# SHELL= /bin/sh
|
||||
# SHELL= sh
|
||||
#
|
||||
SHELL= /bin/bash
|
||||
#SHELL= /bin/sh
|
||||
SHELL= bash
|
||||
#SHELL= sh
|
||||
#if 0 /* start of skip for non-Gnu makefiles */
|
||||
#
|
||||
ifeq ($(target),Darwin)
|
||||
SHELL:= /bin/zsh
|
||||
SHELL:= /bin/sh
|
||||
endif
|
||||
#endif /* end of skip for non-Gnu makefiles */
|
||||
|
||||
@@ -267,20 +268,21 @@ TRUE= true
|
||||
#
|
||||
CALC_FILES= README alg_config.cal beer.cal bernoulli.cal \
|
||||
bernpoly.cal bigprime.cal bindings brentsolve.cal chi.cal chrem.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 \
|
||||
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
|
||||
comma.cal constants.cal deg.cal dms.cal dotest.cal ellip.cal \
|
||||
factorial.cal factorial2.cal fnv_tool.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 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 splitbits.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.
|
||||
#
|
||||
@@ -293,6 +295,10 @@ DISTLIST= ${CALC_FILES} ${MAKE_FILE}
|
||||
# These files are used to make (but not built) a calc .a link library
|
||||
#
|
||||
CALCLIBLIST=
|
||||
#
|
||||
# rules that are not also names of files
|
||||
#
|
||||
PHONY= all clobber distlist install
|
||||
|
||||
all: ${CALC_FILES} ${MAKE_FILE} .all
|
||||
|
||||
@@ -302,6 +308,8 @@ all: ${CALC_FILES} ${MAKE_FILE} .all
|
||||
${RM} -f .all
|
||||
${TOUCH} .all
|
||||
|
||||
.PHONY: ${PHONY}
|
||||
|
||||
##
|
||||
#
|
||||
# File list generation. You can ignore this section.
|
||||
|
178
cal/README
178
cal/README
@@ -263,6 +263,64 @@ chrem.cal
|
||||
Chinese remainder theorem/problem solver.
|
||||
|
||||
|
||||
comma.cal
|
||||
|
||||
Convert numbers into strings with 3-digit group and integer-fraction
|
||||
separators.
|
||||
|
||||
If the value is an integer, the integer-fraction separator is not used.
|
||||
|
||||
str_comma(x, [group, [decimal]])
|
||||
|
||||
Convert x into a string.
|
||||
|
||||
If group is given and is a string, group will be used as
|
||||
the 3-digit group separator, otherwise the default 3-digit
|
||||
group separator will be used.
|
||||
|
||||
If decimal is given and is a string, group will be used as
|
||||
the integer-fraction separator, otherwise the default
|
||||
integer-fraction separator will be used.
|
||||
|
||||
The decimal and group arguments are optional.
|
||||
|
||||
set_default_group_separator(group)
|
||||
|
||||
Change the default 3-digit group separator if group is a string,
|
||||
otherwise the default 3-digit group separator will not be
|
||||
changed. Return the old 3-digit group separator.
|
||||
|
||||
set_default_decimal_separator(decimal)
|
||||
|
||||
Change the default 3-digit group separator if decimal is a
|
||||
string, otherwise the default integer-fraction separator
|
||||
will not be changed. Return the old integer-fraction separator.
|
||||
|
||||
print_comma(x, [group, [decimal]])
|
||||
|
||||
Print the value produced by str_comma(x, [group, [decimal]])
|
||||
followed by a newline.
|
||||
|
||||
If the str_comma() does not return a string, nothing is printed.
|
||||
|
||||
The decimal and group arguments are optional.
|
||||
|
||||
The value produced by str_comma() is returned.
|
||||
|
||||
fprint_comma(fd, x, [group, [decimal]])
|
||||
|
||||
Print the value produced by str_comma(x, [group, [decimal]]),
|
||||
without a trailing newline, on file fd.
|
||||
|
||||
If the str_comma() does not return a string, nothing is printed.
|
||||
|
||||
If fd is not an open file, nothing is printed.
|
||||
|
||||
The decimal and group arguments are optional.
|
||||
|
||||
The value produced by str_comma() is returned.
|
||||
|
||||
|
||||
deg.cal
|
||||
|
||||
deg(deg, min, sec)
|
||||
@@ -330,6 +388,13 @@ dotest.cal
|
||||
dotest("set8700.line");
|
||||
|
||||
|
||||
ellip.cal
|
||||
|
||||
efactor(iN, ia, B, force)
|
||||
|
||||
Attempt to factor using the elliptic functions: y^2 = x^3 + a*x + b.
|
||||
|
||||
|
||||
factorial.cal
|
||||
|
||||
factorial(n)
|
||||
@@ -490,12 +555,65 @@ factorial2.cal
|
||||
for information on falling factorials.
|
||||
|
||||
|
||||
ellip.cal
|
||||
fnv_util.cal
|
||||
|
||||
efactor(iN, ia, B, force)
|
||||
Utility tools for FNV hash and "FNV-style" hash operations.
|
||||
|
||||
Attempt to factor using the elliptic functions: y^2 = x^3 + a*x + b.
|
||||
These functions, if given non-standard values, will produce bogus results.
|
||||
In some cases, such as specifying the number of bits in the hash,
|
||||
using a non-power of 2 bit will produce a result that may work,
|
||||
but the hash will be only an "FNV-style" hash and not a true FNV hash.
|
||||
|
||||
find_fnv_prime(bits)
|
||||
|
||||
If bits == null(), this function will attempt to prompt stdin
|
||||
for a value and provide commends on the value of bits.
|
||||
|
||||
given:
|
||||
bits number of bits in the hash, null() ==> prompt for value
|
||||
|
||||
returns:
|
||||
0 ==> no FNV prime found
|
||||
>0 ==> FNV prime
|
||||
|
||||
deprecated_fnv0(bits, fnv_prime, string)
|
||||
|
||||
If fnv_prime == null(), this function will try to compute the FNV prime
|
||||
for a hash of size bits.
|
||||
|
||||
given:
|
||||
bits number of bits in FNV hash
|
||||
fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible
|
||||
string string to hash
|
||||
|
||||
returns:
|
||||
FNV-0 hash, for size bytes, of string
|
||||
|
||||
NOTE: This function does NOT attempt to determine that fnv_prime is prime.
|
||||
|
||||
fnv_offset_basis(bits, fnv_prime)
|
||||
|
||||
given:
|
||||
bits number of bits in FNV hash
|
||||
fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible
|
||||
|
||||
returns:
|
||||
FNV offset basis for a hash size of bits and an FNV prime of fnv_prime
|
||||
|
||||
NOTE: This function does NOT attempt to determine that fnv_prime is prime.
|
||||
|
||||
fnv1a_style_hash(bits, fnv_prime, prev_hash, string)
|
||||
|
||||
given:
|
||||
bits number of bits in FNV hash
|
||||
fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible
|
||||
prev_hash previous hash value, null() ==> generate FNV offset basis
|
||||
string string to hash
|
||||
|
||||
returns:
|
||||
"FNV-style" hash of bits
|
||||
|
||||
NOTE: This function does NOT attempt to determine that fnv_prime is prime.
|
||||
|
||||
gvec.cal
|
||||
|
||||
@@ -1375,6 +1493,60 @@ specialfunctions.cal
|
||||
on the script zeta2.cal.
|
||||
|
||||
|
||||
splitbits.cal
|
||||
|
||||
splitbits(x, b)
|
||||
|
||||
Given an integer x, split the value into a list of integers,
|
||||
each of which is at most b bits long.
|
||||
|
||||
The value b must be an integer > 0.
|
||||
|
||||
The number of elements in the returned list is:
|
||||
|
||||
ceil((highbit(x) + 1) / b)
|
||||
|
||||
If x == 0, then a list of 1 element containing 0 is returned.
|
||||
|
||||
If x < 0, then the two's compliment of abs(x) is returned.
|
||||
Even though calc represents negative integers as positive values
|
||||
with sign bit, the bits returned by this function are as if
|
||||
the integer converted as if the integer was a two's compliment
|
||||
value. For example:
|
||||
|
||||
; L = splitbits(-1, 8);
|
||||
; print L[[0]]
|
||||
255
|
||||
|
||||
; L = splitbits(-2, 8);
|
||||
; print L[[0]]
|
||||
254
|
||||
|
||||
; L = splitbits(-3, 8);
|
||||
; print L[[0]]
|
||||
253
|
||||
|
||||
The first element of the list contains the lowest order bits
|
||||
of x. The last element of the list contains the highest number
|
||||
bits of x.
|
||||
|
||||
For example:
|
||||
|
||||
; x = 2^23209-1
|
||||
; L = splitbits(x, 16);
|
||||
; print size(L), L[[0]]
|
||||
|
||||
; print istype(2, 3i), istype(2, "2"), istype(2, null())
|
||||
0 0 0
|
||||
|
||||
; mat a[2]
|
||||
; b = list(1,2,3)
|
||||
; c = assoc()
|
||||
; obj chongo {was, here} d;
|
||||
; print istype(a,b), istype(b,c), istype(c,d)
|
||||
0 0 0
|
||||
|
||||
|
||||
statistics.cal
|
||||
|
||||
gammaincoctave(z,a)
|
||||
|
437
cal/comma.cal
Normal file
437
cal/comma.cal
Normal file
@@ -0,0 +1,437 @@
|
||||
/*
|
||||
* comma - convert numbers into strings with 3-digit group and integer-fraction separators
|
||||
*
|
||||
* Convert numbers into strings with 3-digit group and integer-fraction separators.
|
||||
*
|
||||
* If the value is an integer, the integer-fraction separator is not used.
|
||||
*
|
||||
* str_comma(x, [group, [decimal]])
|
||||
*
|
||||
* Convert x into a string.
|
||||
*
|
||||
* If group is given and is a string, group will be used as
|
||||
* the 3-digit group separator, otherwise the default 3-digit
|
||||
* group separator will be used.
|
||||
*
|
||||
* If decimal is given and is a string, group will be used as
|
||||
* the integer-fraction separator, otherwise the default
|
||||
* integer-fraction separator will be used.
|
||||
*
|
||||
* The decimal and group arguments are optional.
|
||||
*
|
||||
* set_default_group_separator(group)
|
||||
*
|
||||
* Change the default 3-digit group separator if group is a string,
|
||||
* otherwise the default 3-digit group separator will not be
|
||||
* changed. Return the old 3-digit group separator.
|
||||
*
|
||||
* set_default_decimal_separator(decimal)
|
||||
*
|
||||
* Change the default 3-digit group separator if decimal is a
|
||||
* string, otherwise the default integer-fraction separator
|
||||
* will not be changed. Return the old integer-fraction separator.
|
||||
*
|
||||
* print_comma(x, [group, [decimal]])
|
||||
*
|
||||
* Print the value produced by str_comma(x, [group, [decimal]])
|
||||
* followed by a newline.
|
||||
*
|
||||
* If the str_comma() does not return a string, nothing is printed.
|
||||
*
|
||||
* The decimal and group arguments are optional.
|
||||
*
|
||||
* The value produced by str_comma() is returned.
|
||||
*
|
||||
* fprint_comma(fd, x, [group, [decimal]])
|
||||
*
|
||||
* Print the value produced by str_comma(x, [group, [decimal]]),
|
||||
* without a trailing newline, on file fd.
|
||||
*
|
||||
* If the str_comma() does not return a string, nothing is printed.
|
||||
*
|
||||
* If fd is not an open file, nothing is printed.
|
||||
*
|
||||
* The decimal and group arguments are optional.
|
||||
*
|
||||
* The value produced by str_comma() is returned.
|
||||
*
|
||||
* Copyright (C) 2022 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: 2022/06/20 15:51:49
|
||||
* File existed as early as: 2022
|
||||
*
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
|
||||
static default_group_separator = ","; /* default 3-digit group separator */
|
||||
static default_decimal_separator = "."; /* default integer-fraction separator */
|
||||
|
||||
|
||||
/*
|
||||
* str_comma - convert number into base 10 string with 3-digit groups and integer-fraction separator
|
||||
*
|
||||
*
|
||||
* This function converts a real number into a base 10 string, where
|
||||
* groups of 3 digits are separated by a 3-digit group separator and
|
||||
* a integer-fraction separator is printed between integer and decimal fraction.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* string = str_comma(x);
|
||||
* string = str_comma(x), " ", ".");
|
||||
* string = str_comma(x), ".", ",");
|
||||
*
|
||||
* Internally the function calls:
|
||||
*
|
||||
* strprintf("%f", x);
|
||||
*
|
||||
* and thus the number of decimal fraction digits is subject to
|
||||
* the display() or config("display") value. See:
|
||||
*
|
||||
* man display
|
||||
*
|
||||
* for details.
|
||||
*
|
||||
* given:
|
||||
*
|
||||
* x number to convert
|
||||
*
|
||||
* optional args:
|
||||
*
|
||||
* group use this 3-digit group separator
|
||||
* decimal use this integer-fraction separator
|
||||
*
|
||||
* returns:
|
||||
*
|
||||
* string containing the base 10 digits with group and decimal separators, OR
|
||||
* null() if x is not a number, OR
|
||||
* null() if group is neither null() (not given) nor a string, OR
|
||||
* null() if group is null() (not given) AND default_group_separator is not a string, OR
|
||||
* null() if decimal is neither null() (not given) nor a string, OR
|
||||
* null() if decimal is null() (not given) AND default_decimal_separator is not a string.
|
||||
*/
|
||||
define str_comma(x, group, decimal)
|
||||
{
|
||||
local group_separator; /* 3-digit group separator */
|
||||
local decimal_separator; /* separator between decimal integer and decimal fraction */
|
||||
local sign_str; /* leading - if x < 0 or empty if x >= 0 */
|
||||
local integer; /* integer part of absolute value of x */
|
||||
local int_str; /* integer as a string */
|
||||
local int_len; /* number of digits in int_str */
|
||||
local first_group_len; /* length of 1st group before the 1st 3-digit group separator */
|
||||
local fraction; /* factional part of absolute value of x */
|
||||
local frac_str; /* fraction as a string */
|
||||
local frac_len; /* number of digits in frac_str including leading 0. */
|
||||
local ret; /* string to return */
|
||||
local config_leadzero; /* config("leadzero") to restore */
|
||||
local config_tilde; /* config("tilde") to restore */
|
||||
local i;
|
||||
|
||||
/*
|
||||
* parse args - return null if args are bogus
|
||||
*
|
||||
* Return null() if args or conditions are bogus.
|
||||
*/
|
||||
if (!isreal(x)) {
|
||||
return null();
|
||||
}
|
||||
group_separator = isnull(group) ? default_group_separator : group;
|
||||
decimal_separator = isnull(decimal) ? default_decimal_separator : decimal;
|
||||
if (!isstr(group_separator)) {
|
||||
return null();
|
||||
}
|
||||
if (!isstr(decimal_separator)) {
|
||||
return null();
|
||||
}
|
||||
|
||||
/*
|
||||
* split number
|
||||
*/
|
||||
if (x < 0) {
|
||||
sign_str = "-";
|
||||
integer = int(-x);
|
||||
fraction = frac(-x);
|
||||
} else {
|
||||
sign_str = "";
|
||||
integer = int(x);
|
||||
fraction = frac(x);
|
||||
}
|
||||
ret = sign_str;
|
||||
|
||||
/*
|
||||
* convert digits
|
||||
*
|
||||
* Avoid printing ~ and leading zeros for factional part.
|
||||
*/
|
||||
int_str = strprintf("%d", integer);
|
||||
config_leadzero = config("leadzero", 0);
|
||||
config_tilde = config("tilde", 0);
|
||||
frac_str = strprintf("%d", fraction);
|
||||
config("leadzero", config_leadzero),;
|
||||
config("tilde", config_tilde),;
|
||||
|
||||
/*
|
||||
* determine number of digits in the integer part
|
||||
*/
|
||||
int_len = strlen(int_str);
|
||||
frac_len = strlen(frac_str);
|
||||
|
||||
/*
|
||||
* form integer part with group separators as needed
|
||||
*/
|
||||
|
||||
/*
|
||||
* case: integer is 3 or fewer digits
|
||||
*/
|
||||
if (integer < 1000) {
|
||||
ret += int_str;
|
||||
|
||||
/*
|
||||
* case: integer is 4 or more digits
|
||||
*/
|
||||
} else {
|
||||
|
||||
/*
|
||||
* form a decimal string using group separators
|
||||
*/
|
||||
|
||||
/*
|
||||
* form the initial leading digits before 1st group separator
|
||||
*/
|
||||
first_group_len = int_len % 3;
|
||||
if (first_group_len == 0) {
|
||||
first_group_len = 3;
|
||||
}
|
||||
ret += substr(int_str, 1, first_group_len);
|
||||
|
||||
/*
|
||||
* until end of digits, print group separator followed by 3 more digits
|
||||
*/
|
||||
for (i = first_group_len+1; i < int_len; i += 3) {
|
||||
ret += group_separator + substr(int_str, i, 3);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* form fractional part using decimal separator as needed
|
||||
*/
|
||||
|
||||
/*
|
||||
* case: x is an integer
|
||||
*/
|
||||
if (fraction == 0) {
|
||||
|
||||
/* no fraction, nothing more to do */
|
||||
|
||||
/*
|
||||
* case: x is not an integer
|
||||
*/
|
||||
} else {
|
||||
|
||||
/*
|
||||
* add integer-fraction separator
|
||||
*/
|
||||
ret += decimal_separator;
|
||||
|
||||
/*
|
||||
* add remaining digits
|
||||
*
|
||||
* Skip over the leading 0. in frac_str
|
||||
*/
|
||||
ret += substr(frac_str, 2, frac_len-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* All Done!!! -- Jessica Noll, Age 2
|
||||
*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* set_default_group_separator - change the default 3-digit group separator
|
||||
*
|
||||
* If group is not a string, then the default 3-digit group separator
|
||||
* is not changed. Thus, this will only return the default 3-digit group separator:
|
||||
*
|
||||
* set_default_group_separator(null());
|
||||
*
|
||||
* given:
|
||||
*
|
||||
* group 3-digit group separator
|
||||
*
|
||||
* returns:
|
||||
*
|
||||
* previous 3-digit group separator value
|
||||
*/
|
||||
define set_default_group_separator(group)
|
||||
{
|
||||
local old_default_group_separator; /* previous default 3-digit group separator to return */
|
||||
|
||||
/*
|
||||
* save current 3-digit group separator
|
||||
*/
|
||||
old_default_group_separator = default_group_separator;
|
||||
|
||||
/*
|
||||
* change 3-digit group separator if group is a string
|
||||
*/
|
||||
if (isstr(group)) {
|
||||
default_group_separator = group;
|
||||
}
|
||||
return old_default_group_separator;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* set_default_decimal_separator - change the default integer-fraction separator
|
||||
*
|
||||
* If decimal is not a string, then the default integer-fraction separator
|
||||
* is not changed. Thus, this will only return the integer-fraction separator:
|
||||
*
|
||||
* set_default_decimal_separator(null());
|
||||
*
|
||||
* given:
|
||||
*
|
||||
* decimal separator between decimal integer and decimal fraction (def: ".")
|
||||
*
|
||||
* returns:
|
||||
*
|
||||
* previous integer-fraction separator value
|
||||
*/
|
||||
define set_default_decimal_separator(decimal)
|
||||
{
|
||||
local old_default_decimal_separator; /* previous default integer-fraction separator */
|
||||
|
||||
/*
|
||||
* save current integer-fraction separator
|
||||
*/
|
||||
old_default_decimal_separator = default_decimal_separator;
|
||||
|
||||
/*
|
||||
* change 3-digit decimal integer-fraction if decimal is a string
|
||||
*/
|
||||
if (isstr(decimal)) {
|
||||
default_decimal_separator = decimal;
|
||||
}
|
||||
return old_default_decimal_separator;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* print_comma - print base 10 string with 3-digit group separators & integer-fraction separator + newline
|
||||
*
|
||||
* This function prints the result of str_comma(x, group, decimal) followed by a newline.
|
||||
* For example:
|
||||
*
|
||||
* print_comma(x);
|
||||
* print_comma(x), " ", ".");
|
||||
* print_comma(x), ".", ",");
|
||||
*
|
||||
* If str_comma() does not return a string, this function prints nothing.
|
||||
*
|
||||
* NOTE: To print without a newline, use fprint_comma(fd, x, group, decimal).
|
||||
*
|
||||
* given:
|
||||
* x number to convert
|
||||
*
|
||||
* optional args:
|
||||
*
|
||||
* group use this 3-digit group separator
|
||||
* decimal use this integer-fraction separator
|
||||
*
|
||||
* returns:
|
||||
*
|
||||
* string containing the base 10 digits with group and decimal separators, OR
|
||||
* null() if x is not a number, OR
|
||||
* null() if group is neither null() (not given) nor a string, OR
|
||||
* null() if group is null() (not given) AND default_group_separator is not a string, OR
|
||||
* null() if decimal is neither null() (not given) nor a string, OR
|
||||
* null() if decimal is null() (not given) AND default_decimal_separator is not a string.
|
||||
*/
|
||||
define print_comma(x, group, decimal)
|
||||
{
|
||||
local ret; /* base 10 string with 3-digit group and integer-fraction separators */
|
||||
|
||||
/*
|
||||
* convert to string
|
||||
*/
|
||||
ret = str_comma(x, group, decimal);
|
||||
|
||||
/*
|
||||
* print converted string
|
||||
*/
|
||||
if (isstr(ret)) {
|
||||
printf("%s\n", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fprint_comma - print base 10 string with 3-digit group separators & integer-fraction separator w/o newline
|
||||
*
|
||||
* This function prints the result of str_comma(x, group, decimal) on an open file, without a trailing newline.
|
||||
* For example:
|
||||
*
|
||||
* fprint_comma(files(1), x);
|
||||
* fprint_comma(fd, x), " ", ".");
|
||||
* fprint_comma(files(2), x), ".", ",");
|
||||
*
|
||||
* If str_comma() does not return a string, this function prints nothing.
|
||||
*
|
||||
* This function flushes output to the open file before returning.
|
||||
*
|
||||
* NOTE: To print with a newline, use print_comma(x, group, decimal).
|
||||
*
|
||||
* given:
|
||||
* fd open file
|
||||
* x number to convert
|
||||
*
|
||||
* optional args:
|
||||
*
|
||||
* group use this 3-digit group separator
|
||||
* decimal use this integer-fraction separator
|
||||
*
|
||||
* returns:
|
||||
*
|
||||
* string containing the base 10 digits with group and integer-fraction separators, OR
|
||||
* null() if x is not a number, OR
|
||||
* null() if group is neither null() (not given) nor a string, OR
|
||||
* null() if group is null() (not given) AND default_group_separator is not a string, OR
|
||||
* null() if decimal is neither null() (not given) nor a string, OR
|
||||
* null() if decimal is null() (not given) AND default_decimal_separator is not a string.
|
||||
*/
|
||||
define fprint_comma(fd, x, group, decimal)
|
||||
{
|
||||
local ret; /* base 10 string with 3-digit group and integer-fraction separators */
|
||||
|
||||
/*
|
||||
* convert to string
|
||||
*/
|
||||
ret = str_comma(x, group, decimal);
|
||||
|
||||
/*
|
||||
* print converted string
|
||||
*/
|
||||
if (isstr(ret) && isfile(fd)) {
|
||||
fprintf(fd, "%s", ret);
|
||||
fflush(fd);
|
||||
}
|
||||
return ret;
|
||||
}
|
@@ -4,19 +4,37 @@
|
||||
* This file was created by Ernest Bowen <ebowen at une dot edu dot au>
|
||||
* and modified by Landon Curt Noll.
|
||||
*
|
||||
* This dotest_code has been placed in the public domain. Please do not
|
||||
* copyright this dotest_code.
|
||||
*
|
||||
* ERNEST BOWEN AND LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER-
|
||||
* CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT
|
||||
* NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* This file is not covered under version 2.1 of the GNU LGPL.
|
||||
* This file is covered under "The unlicense":
|
||||
*
|
||||
* https://unlicense.org
|
||||
*
|
||||
* In particular:
|
||||
*
|
||||
* This is free and unencumbered software released into the public domain.
|
||||
*
|
||||
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
* distribute this software, either in source code form or as a compiled
|
||||
* binary, for any purpose, commercial or non-commercial, and by any
|
||||
* means.
|
||||
*
|
||||
* In jurisdictions that recognize copyright laws, the author or authors
|
||||
* of this software dedicate any and all copyright interest in the
|
||||
* software to the public domain. We make this dedication for the benefit
|
||||
* of the public at large and to the detriment of our heirs and
|
||||
* successors. We intend this dedication to be an overt act of
|
||||
* relinquishment in perpetuity of all present and future rights to this
|
||||
* software under copyright law.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* For more information, please refer to <http://unlicense.org/>
|
||||
*
|
||||
* Under source dotest_code control: 2006/03/08 05:54:09
|
||||
* File existed as early as: 2006
|
||||
|
474
cal/fnv_tool.cal
Normal file
474
cal/fnv_tool.cal
Normal file
@@ -0,0 +1,474 @@
|
||||
/*
|
||||
* fnv_util - utility tools for FNV hash and "FNV-style" hash operations
|
||||
*
|
||||
* This file provides the following functions:
|
||||
*
|
||||
* find_fnv_prime(bits)
|
||||
* deprecated_fnv0(bits, fnv_prime, string)
|
||||
* fnv_offset_basis(bits, fnv_prime)
|
||||
* fnv1a_style_hash(bits, fnv_prime, prev_hash, string)
|
||||
*
|
||||
* See the individual function for details on args and return value.
|
||||
*
|
||||
* If no args are given to find_fnv_prime() and stdin is associated
|
||||
* with a tty (i.e., an interactive terminal), then bits will be
|
||||
* prompted for and commentary will be printed to stdout as well.
|
||||
*
|
||||
* If fnv_prime == null(), then an attempt to compute the FNV prime
|
||||
* for a hash if size bits is attempted..
|
||||
*
|
||||
* If prev_hash == null(), then the FNV offset basis for
|
||||
* for a hash if size bits is computed.
|
||||
*
|
||||
* For more information on the FNV hash see:
|
||||
*
|
||||
* https://en.wikipedia.org/wiki/Fowler-Noll-Vo_hash_function
|
||||
* http://www.isthe.com/chongo/tech/comp/fnv/index.html
|
||||
*
|
||||
* IMPORTANT NOTE:
|
||||
*
|
||||
* These functions, if given non-standard values, will produce bogus results.
|
||||
* In some cases, such as specifying the number of bits in the hash,
|
||||
* using a non-power of 2 bit will produce a result that may work,
|
||||
* but the hash will be only an "FNV-style" hash and not a true FNV hash.
|
||||
*
|
||||
* We say "FNV-style" because the result hash is not a "true FNV-like" hash.
|
||||
*
|
||||
* Let integer n > 0 be the number if bits in the FNV hash. Then:
|
||||
*
|
||||
* t = floor((5+n)/12)
|
||||
*
|
||||
* The FNV prime, for the given n bits is the smallest prime of the form:
|
||||
*
|
||||
* p = 256^t + 2^8 + b
|
||||
*
|
||||
* such that:
|
||||
*
|
||||
* 0 < b < 2^8
|
||||
* The number of one-bits in b must be 4 or 5
|
||||
* p mod (2^40 - 2^24 - 1) > (2^24 + 2^8 + 2^7)
|
||||
*
|
||||
* If you force n to not be a power of 2, for example:
|
||||
*
|
||||
* n = 44
|
||||
*
|
||||
* you will find that the FNV prime for 44 bits is:
|
||||
*
|
||||
* p44 = 4294967597
|
||||
* = 0x10000012d
|
||||
* = 0b100000000000000000000000100101101
|
||||
* = 2^32 + 301 = 2^32 + 2^8 + 2^5 + 2^3 + 2^2 + 2^0
|
||||
*
|
||||
* However a hash size of 44 bits is not a true FNV hash, it is only a "FNV-style" hash.
|
||||
*
|
||||
* NOTE: We disallow n <= 31 because there are no FNV primes that small.
|
||||
*
|
||||
* NOTE: For n that is a power of 2 and n > 1024, you will find that
|
||||
* that FNV primes become so rare that that one may not find a suitable
|
||||
* FNV prime. For n = 2048, 4096, 8192, 16384, 32768, 65536, 131072
|
||||
* 262144, and 524288, there is NO suitable FNV prime.
|
||||
*
|
||||
* As for as hashing goes, large values of n, even if an
|
||||
* FNV hash may be found, are unlikely to be truly useful. :-)
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2023 by Landon Curt Noll. All Rights Reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose and without fee is hereby granted,
|
||||
* provided that the above copyright, this permission notice and text
|
||||
* this comment, and the disclaimer below appear in all of the following:
|
||||
*
|
||||
* supporting documentation
|
||||
* source copies
|
||||
* source works derived from this source
|
||||
* binaries derived from this source or from derived source
|
||||
*
|
||||
* LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
||||
* EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* chongo (Landon Curt Noll, http://www.isthe.com/chongo/index.html) /\oo/\
|
||||
*
|
||||
* Share and enjoy! :-)
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* find_fnv_prime - try to find a FNV prime given the number of bits
|
||||
*
|
||||
* If bits == null(), this function will attempt to prompt stdin
|
||||
* for a value and provide commends on the value of bits.
|
||||
*
|
||||
* given:
|
||||
* bits number of bits in the hash, null() ==> prompt for value
|
||||
*
|
||||
* returns:
|
||||
* 0 ==> no FNV prime found
|
||||
* >0 ==> FNV prime
|
||||
*/
|
||||
define find_fnv_prime(bits)
|
||||
{
|
||||
local b; /* lower octet of the potential FNV prime: [1,255] */
|
||||
local p; /* value to test as an FNV prime */
|
||||
local t; /* power of 256 part of the FNV prime */
|
||||
local one_bits; /* number of 1 bits in b */
|
||||
local p_minus_b; /* potential FNV prime less b */
|
||||
local interactive; /* true ==> interactive mode and print commentary */
|
||||
|
||||
/*
|
||||
* case: no arg, prompt for bits and print commentary
|
||||
*/
|
||||
interactive = 0; /* assume non-interactive mode */
|
||||
if (isnull(bits)) {
|
||||
|
||||
/*
|
||||
* must be attached to an interactive terminal
|
||||
*/
|
||||
if (!isatty(files(0))) {
|
||||
print "# FATAL: stdin is not a tty: not attached to an interactive terminal";
|
||||
return 0;
|
||||
}
|
||||
interactive = 1; /* set interactive mode */
|
||||
|
||||
/*
|
||||
* prompt for the number of bits
|
||||
*/
|
||||
do {
|
||||
local strscanf_ret; /* return from strscanf_ret */
|
||||
local input; /* value read after prompt */
|
||||
|
||||
/*
|
||||
* prompt and obtain the input
|
||||
*/
|
||||
input = prompt("Enter hash size in bits: ");
|
||||
strscanf_ret = strscanf(input, "%i", bits);
|
||||
print "input =", input;
|
||||
print "bits =", bits;
|
||||
if (!isint(bits) || bits <= 0) {
|
||||
print;
|
||||
print "# NOTE: must enter a integer > 0, try again";
|
||||
print;
|
||||
}
|
||||
} while (!isint(bits) || bits <= 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* firewall - bits must be non-negative integer
|
||||
*/
|
||||
if (!isint(bits) || bits < 0) {
|
||||
if (interactive) {
|
||||
print "# FATAL: bits must be non-negative integer";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* provide commentary on the choice of bits if we are interactive
|
||||
*/
|
||||
if (interactive) {
|
||||
if (popcnt(bits) == 1) {
|
||||
if (bits > 1024) {
|
||||
print "# WARNING: FNV primes for powers of 2 > 1024 are extremely rare.";
|
||||
print "# WARNING: There are no FNV primes for 2048, 4096, 8192, 16384, 327678, 65536, 131072, 262144, nor 524288.";
|
||||
}
|
||||
print "# NOTE: bits a power of 2 and bits >= 32: bits is suitable for a true FNV hash";
|
||||
print "n =", bits;
|
||||
} else {
|
||||
if (bits < 32) {
|
||||
print "# WARNING: bits < 32 is not recommended because there isn't enough bits to be worth hashing";
|
||||
}
|
||||
print "# WARNING: because bits is not a power of 2, we can only form an \"FNV-style hash\": not a true FNV hash.";
|
||||
print "# WARNING: A \"FNV-style hash\" may not have the desired hash properties of a true FNV hash.";
|
||||
print "n =", bits;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* search setup
|
||||
*/
|
||||
t = floor((5+bits)/12);
|
||||
p_minus_b = 256^t + 2^8;
|
||||
|
||||
/*
|
||||
* search for a b that forms a suitable FNV prime
|
||||
*/
|
||||
for (b=1; b < 256; ++b) {
|
||||
|
||||
/*
|
||||
* reject b unless the of one-bits in bottom octet of p is 4 or 5
|
||||
*/
|
||||
one_bits = popcnt(b);
|
||||
if (one_bits != 4 && one_bits != 5) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* reject p if p mod (2^40 - 2^24 - 1) <= (2^24 + 2^8 + 2^7)
|
||||
*/
|
||||
p = p_minus_b + b;
|
||||
if ((p % (2^40 - 2^24 - 1)) <= (2^24 + 2^8 + 2^7)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* accept potential p value that is prime
|
||||
*/
|
||||
if (ptest(p) == 1) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* case: did not find an FNV prime
|
||||
*/
|
||||
if (b >= 256) {
|
||||
|
||||
/*
|
||||
* examine results if interactive
|
||||
*/
|
||||
if (interactive) {
|
||||
print "# FATAL: There is no a suitable FNV prime for bits =", bits;
|
||||
quit "find_fnv_prime: FATAL: FNV prime search failed";
|
||||
}
|
||||
|
||||
/*
|
||||
* return 0 to indicate no FNV prime found
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* provide FNV commentary if interactive
|
||||
*/
|
||||
if (interactive) {
|
||||
print "t =", t;
|
||||
print "b =", b;
|
||||
print "# NOTE: p = 256^":t, "+ 2^8 +", b;
|
||||
print;
|
||||
print "p =", p;
|
||||
}
|
||||
|
||||
/*
|
||||
* return FNV prime
|
||||
*/
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* deprecated_fnv0 - FNV-0 hash that should only be used to generate an FNV offset basis
|
||||
*
|
||||
* If fnv_prime == null(), this function will try to compute the FNV prime
|
||||
* for a hash of size bits.
|
||||
*
|
||||
* given:
|
||||
* bits number of bits in FNV hash
|
||||
* fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible
|
||||
* string string to hash
|
||||
*
|
||||
* returns:
|
||||
* FNV-0 hash, for size bytes, of string
|
||||
*
|
||||
* NOTE: This function does NOT attempt to determine that fnv_prime is prime.
|
||||
*/
|
||||
define deprecated_fnv0(bits, fnv_prime, string)
|
||||
{
|
||||
local hash; /* FNV hash value */
|
||||
local len; /* length of string */
|
||||
local base; /* base of FNV hash: 2^bits */
|
||||
local i;
|
||||
|
||||
/*
|
||||
* firewall
|
||||
*/
|
||||
if (!isint(bits) || bits <= 0) {
|
||||
quit "deprecated_fnv0: FATAL: bits arg must be an integer > 0";
|
||||
}
|
||||
if (!isstr(string)) {
|
||||
quit "deprecated_fnv0: FATAL: string arg must be a string";
|
||||
}
|
||||
|
||||
/*
|
||||
* fnv_prime == null() means to try and generate the FNV prime
|
||||
*/
|
||||
if (isnull(fnv_prime)) {
|
||||
/* try to generate an FNV prime */
|
||||
fnv_prime = find_fnv_prime(bits);
|
||||
if (fnv_prime == 0) {
|
||||
quit "deprecated_fnv0: FATAL: no FNV prime exists for the given hash size in bits";
|
||||
}
|
||||
}
|
||||
if (!isint(fnv_prime) || fnv_prime <= 0) {
|
||||
quit "deprecated_fnv0: FATAL: fnv_prime arg must be an integer > 0 and should be prime";
|
||||
}
|
||||
|
||||
/*
|
||||
* FNV-0 hash each character
|
||||
*/
|
||||
len = strlen(string);
|
||||
base = 2^bits;
|
||||
hash = 0;
|
||||
for (i=0; i < len; ++i) {
|
||||
hash = xor((hash * fnv_prime) % base, ord(string[i]));
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fnv_offset_basis - generate and FNV offset basis
|
||||
*
|
||||
* given:
|
||||
* bits number of bits in FNV hash
|
||||
* fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible
|
||||
*
|
||||
* returns:
|
||||
* FNV offset basis for a hash size of bits and an FNV prime of fnv_prime
|
||||
*
|
||||
* NOTE: This function does NOT attempt to determine that fnv_prime is prime.
|
||||
*/
|
||||
define
|
||||
fnv_offset_basis(bits, fnv_prime)
|
||||
{
|
||||
local fnv0_hash = 0; /* FNV-0 hash value */
|
||||
|
||||
/* string to generate a FNV offset basis - do not change this value */
|
||||
static chongo_was_here = "chongo <Landon Curt Noll> /\\../\\";
|
||||
|
||||
/*
|
||||
* firewall
|
||||
*/
|
||||
if (!isint(bits) || bits <= 0) {
|
||||
quit "fnv_offset_basis: FATAL: bits arg must be an integer > 0";
|
||||
}
|
||||
|
||||
/*
|
||||
* fnv_prime == null() means to try and generate the FNV prime
|
||||
*/
|
||||
if (isnull(fnv_prime)) {
|
||||
/* try to generate an FNV prime */
|
||||
fnv_prime = find_fnv_prime(bits);
|
||||
if (fnv_prime == 0) {
|
||||
quit "fnv_offset_basis: FATAL: no FNV prime exists for the given hash size in bits";
|
||||
}
|
||||
}
|
||||
if (!isint(fnv_prime) || fnv_prime <= 0) {
|
||||
quit "fnv_offset_basis: FATAL: fnv_prime arg must be an integer > 0 and should be prime";
|
||||
}
|
||||
|
||||
/*
|
||||
* return the FNV-0 hash of fnv_offset_basis as the FNV offset basis
|
||||
*/
|
||||
fnv0_hash = deprecated_fnv0(bits, fnv_prime, chongo_was_here);
|
||||
return fnv0_hash;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* fnv_style_hash - compute an "FNV-1a-style" hash
|
||||
*
|
||||
* These functions, if given non-standard values, will produce bogus results.
|
||||
* To produce a true FNV-1a hash:
|
||||
*
|
||||
* bits must be a power of 2
|
||||
* 32 <= bits
|
||||
* fnv_prime == find_fnv_prime(bits) OR fnv_prime == null()
|
||||
* prev_hash == previous FNV hash OR prev_hash == null()
|
||||
*
|
||||
* If fnv_prime == null(), this function will try to compute the FNV prime
|
||||
* for a hash of size bits.
|
||||
*
|
||||
* If prev_hash == null(), this function will try to compute the FNV offset basis
|
||||
* for a hash of size bits.
|
||||
*
|
||||
* One may chain "FNV-style" hashes by replacing the offset_basis with
|
||||
* the hash state of the previous hash. For the first hash:
|
||||
*
|
||||
* fnv_prime = find_fnv_prime(bits)
|
||||
* hash_val = fnv_style_hash(bits, fnv_prime, null(), string_a);
|
||||
*
|
||||
* then:
|
||||
*
|
||||
* hash_val = fnv_style_hash(bits, fnv_prime, hash_val, string_b);
|
||||
*
|
||||
* This will produce the same as the string_a concatenated with string_b:
|
||||
*
|
||||
* hash_val = fnv_style_hash(bits, null(), null(), string_a + string_b);
|
||||
*
|
||||
* NOTE: Because string_a and string_b are strings, the expression:
|
||||
*
|
||||
* string_a + string_b
|
||||
*
|
||||
* is string_a concatenated with string_b.
|
||||
*
|
||||
* given:
|
||||
* bits number of bits in FNV hash
|
||||
* fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible
|
||||
* prev_hash previous hash value, null() ==> generate FNV offset basis
|
||||
* string string to hash
|
||||
*
|
||||
* returns:
|
||||
* "FNV-style" hash of bits
|
||||
*
|
||||
* NOTE: This function does NOT attempt to determine that fnv_prime is prime.
|
||||
*/
|
||||
define
|
||||
fnv1a_style_hash(bits, fnv_prime, prev_hash, string)
|
||||
{
|
||||
local hash = 0; /* FNV hash value */
|
||||
local len; /* length of string */
|
||||
local base; /* base of FNV hash: 2^bits */
|
||||
local i;
|
||||
|
||||
/*
|
||||
* firewall
|
||||
*/
|
||||
if (!isint(bits) || bits <= 0) {
|
||||
quit "fnv1a_style_hash: FATAL: bits arg must be an integer > 0";
|
||||
}
|
||||
if (!isstr(string)) {
|
||||
quit "fnv1a_style_hash: FATAL: string arg must be a string";
|
||||
}
|
||||
|
||||
/*
|
||||
* fnv_prime == null() means to try and generate the FNV prime
|
||||
*/
|
||||
if (isnull(fnv_prime)) {
|
||||
/* try to generate an FNV prime */
|
||||
fnv_prime = find_fnv_prime(bits);
|
||||
if (fnv_prime == 0) {
|
||||
quit "fnv1a_style_hash: FATAL: no FNV prime exists for the given hash size in bits";
|
||||
}
|
||||
}
|
||||
if (!isint(fnv_prime) || fnv_prime <= 0) {
|
||||
quit "fnv1a_style_hash: FATAL: fnv_prime arg must be an integer > 0 and should be prime";
|
||||
}
|
||||
|
||||
/*
|
||||
* prev_hash == null() means to generate the FNV offset basis
|
||||
*/
|
||||
if (isnull(prev_hash)) {
|
||||
|
||||
/* generate the FNV offset basis for a hash of size bits */
|
||||
prev_hash = fnv_offset_basis(bits, fnv_prime);
|
||||
}
|
||||
if (!isint(prev_hash) || prev_hash < 0) {
|
||||
quit "fnv1a_style_hash: FATAL: prev_hash arg must be an integer => 0";
|
||||
}
|
||||
|
||||
/*
|
||||
* FNV-1a hash each character
|
||||
*/
|
||||
len = strlen(string);
|
||||
base = 2^bits;
|
||||
hash = prev_hash;
|
||||
for (i=0; i < len; ++i) {
|
||||
hash = xor((hash * fnv_prime) % base, ord(string[i]));
|
||||
}
|
||||
return hash;
|
||||
}
|
138
cal/regress.cal
138
cal/regress.cal
@@ -305,6 +305,8 @@ print '008: parsed test_variables()';
|
||||
*/
|
||||
define test_arithmetic()
|
||||
{
|
||||
local x;
|
||||
|
||||
print '400: Beginning test_arithmetic';
|
||||
|
||||
vrfy(3+4==7, '401: 3 + 4 == 7');
|
||||
@@ -366,8 +368,18 @@ define test_arithmetic()
|
||||
vrfy((2^23209-1)^(2-2) == 1, '457: (2^23209-1)^(2-2) == 1');
|
||||
vrfy((2^23209-1)^((2^23209-1)-(2^23209-1)) == 1,
|
||||
'458: (2^23209-1)^((2^23209-1)-(2^23209-1)) == 1');
|
||||
vrfy(0^2 == 0, '459: 0^2 == 0');
|
||||
vrfy(0^3 == 0, '460: 0^3 == 0');
|
||||
vrfy(0^12 == 0, '461: 0^12 == 0');
|
||||
vrfy(0^13 == 0, '462: 0^13 == 0');
|
||||
x = 0;
|
||||
vrfy(x == 0, '463: x == 0');
|
||||
vrfy(0^2 == 0, '464: 0^2 == 0');
|
||||
vrfy(0^3 == 0, '465: 0^3 == 0');
|
||||
vrfy(0^12 == 0, '466: 0^12 == 0');
|
||||
vrfy(x^13 == 0, '467: x^13 == 0');
|
||||
|
||||
print '459: Ending test_arithmetic';
|
||||
print '462: Ending test_arithmetic';
|
||||
}
|
||||
print '009: parsed test_arithmetic()';
|
||||
|
||||
@@ -529,7 +541,16 @@ define test_config()
|
||||
vrfy(issimple(config("dupvar_warn")),
|
||||
'562: issimple(config("rdupvar_warn"))');
|
||||
|
||||
print '563: Ending test_config';
|
||||
|
||||
/* test new space modes */
|
||||
vrfy(config("tilde_space") == 0,
|
||||
'563: config("tilde_space") == 0');
|
||||
vrfy(config("fraction_space") == 0,
|
||||
'564: config("fraction_space") == 0');
|
||||
vrfy(config("complex_space") == 0,
|
||||
'565: config("complex_space") == 0');
|
||||
|
||||
print '566: Ending test_config';
|
||||
}
|
||||
print '010: parsed test_config()';
|
||||
|
||||
@@ -3912,7 +3933,7 @@ define test_fileops()
|
||||
vrfy(!iserror(p=fopen("tmp4200","r")),
|
||||
'4274: !iserror(p=fopen("tmp4200","r"))');
|
||||
vrfy(!iserror(s=fgetline(p)), '4275: !iserror(s=fgetline(p))');
|
||||
vrfy(strcmp(s,"chongo") == 0, '4276: strcmp(s,"chongo") == 0');
|
||||
vrfy(strcmp(s,"chongo") == 0, '4276: strcmp(s,"chongo") == 0');
|
||||
vrfy(!iserror(s=fgetfile(p)), '4277: !iserror(s=fgetfile(p))');
|
||||
vrfy(strcmp(s,"w\0a\0s\nhere\n") == 0,
|
||||
'4278: strcmp(s,"w\0a\0s\nhere\n") == 0');
|
||||
@@ -4284,84 +4305,119 @@ define test_strprintf()
|
||||
print '4804: c = config("display", 2)';
|
||||
c = config("tilde", 0);
|
||||
print '4805: c = config("tilde", 0)';
|
||||
c = config("tilde_space", 1);
|
||||
print '4806: c = config("tilde_space", 1)';
|
||||
c = config("leadzero", 0);
|
||||
print '4806: c = config("leadzero", 0)';
|
||||
print '4807: c = config("leadzero", 0)';
|
||||
c = config("fullzero", 0);
|
||||
print '4807: c = config("fullzero", 0)';
|
||||
print '4808: c = config("fullzero", 0)';
|
||||
|
||||
/* tests with tilde == 0 */
|
||||
vrfy(strprintf("%d%d", 27, 29) == "2729",
|
||||
'4808: strprintf("%d%d", 27, 29) == "2729"');
|
||||
'4809: strprintf("%d%d", 27, 29) == "2729"');
|
||||
vrfy(strprintf("%5d%3d", 27, 29) == " 27 29",
|
||||
'4809: strprintf("%5d%3d", 27, 29) == " 27 29"; ');
|
||||
'4810: strprintf("%5d%3d", 27, 29) == " 27 29"; ');
|
||||
vrfy(strprintf("%-5d%-3d", 27, 29) == "27 29 ",
|
||||
'4810: strprintf("%-5d%-3d", 27, 29) == "27 29 "');
|
||||
'4811: strprintf("%-5d%-3d", 27, 29) == "27 29 "');
|
||||
vrfy(strprintf("%f", 1.375) == "1.38",
|
||||
'4811: strprintf("%f", 1.375) == "1.38"');
|
||||
'4812: strprintf("%f", 1.375) == "1.38"');
|
||||
vrfy(strprintf("%f", 1.385) == "1.38",
|
||||
'4812: strprintf("%f", 1.385) == "1.38"');
|
||||
'4813: strprintf("%f", 1.385) == "1.38"');
|
||||
vrfy(strprintf("%f", .375) == ".38",
|
||||
'4813: strprintf("%f", .375) == ".38"');
|
||||
'4814: strprintf("%f", .375) == ".38"');
|
||||
vrfy(strprintf("%f", .385) == ".38",
|
||||
'4814: strprintf("%f", .385) == ".38"');
|
||||
'4815: strprintf("%f", .385) == ".38"');
|
||||
|
||||
/* tests with tilde == 1 */
|
||||
c = config("tilde", 1);
|
||||
print '4815: c = config("tilde", 1)';
|
||||
vrfy(strprintf("%f", 1.375) == "~1.38",
|
||||
'4816: strprintf("%f", 1.375) == "~1.38"');
|
||||
vrfy(strprintf("%f", 27/29) == "~.93",
|
||||
'4817: strprintf("%f", 27/29) == "~.93"');
|
||||
print '4816: c = config("tilde", 1)';
|
||||
vrfy(strprintf("%f", 1.375) == "~ 1.38",
|
||||
'4817: strprintf("%f", 1.375) == "~ 1.38"');
|
||||
vrfy(strprintf("%f", 27/29) == "~ .93",
|
||||
'4818: strprintf("%f", 27/29) == "~ .93"');
|
||||
vrfy(strprintf("%r", 27/29) == "27/29",
|
||||
'4818: strprintf("%r", 27/29) == "27/29"');
|
||||
'4819: strprintf("%r", 27/29) == "27/29"');
|
||||
vrfy(strprintf("%o", 27/29) == "033/035",
|
||||
'4819: strprintf("%o", 27/29) == "033/035"');
|
||||
'4820: strprintf("%o", 27/29) == "033/035"');
|
||||
vrfy(strprintf("%x", 27/29) == "0x1b/0x1d",
|
||||
'4820: strprintf("%x", 27/29) == "0x1b/0x1d"');
|
||||
'4821: strprintf("%x", 27/29) == "0x1b/0x1d"');
|
||||
vrfy(strprintf("%b", 27/29) == "0b11011/0b11101",
|
||||
'4821: strprintf("%b", 27/29) == "0b11011/0b11101"');
|
||||
'4822: strprintf("%b", 27/29) == "0b11011/0b11101"');
|
||||
vrfy(strprintf("%e", 12345) == "~ 1.23e4",
|
||||
'4823: strprintf("%e", 12345) == "~ 1.23e4"');
|
||||
vrfy(strprintf("%g", .385) == "~ .38",
|
||||
'4824: strprintf("%g", .385) == "~ .38"');
|
||||
vrfy(strprintf("%g", 385) == "~ 3.8e2",
|
||||
'4825: strprintf("%g", 385) == "~ 3.8e2"');
|
||||
|
||||
/* tests with tilde == 1 and tilde_space == 0 */
|
||||
c = config("tilde_space", 0);
|
||||
print '4826: c = config("tilde_space", 0)';
|
||||
vrfy(strprintf("%f", 1.375) == "~1.38",
|
||||
'4827: strprintf("%f", 1.375) == "~1.38"');
|
||||
vrfy(strprintf("%f", 27/29) == "~.93",
|
||||
'4828: strprintf("%f", 27/29) == "~.93"');
|
||||
vrfy(strprintf("%e", 12345) == "~1.23e4",
|
||||
'4822: strprintf("%e", 12345) == "~1.23e4"');
|
||||
'4829: strprintf("%e", 12345) == "~1.23e4"');
|
||||
vrfy(strprintf("%g", .385) == "~.38",
|
||||
'4823: strprintf("%g", .385) == "~.38"');
|
||||
'4830: strprintf("%g", .385) == "~.38"');
|
||||
vrfy(strprintf("%g", 385) == "~3.8e2",
|
||||
'4824: strprintf("%g", 385) == "~3.8e2"');
|
||||
'4831: strprintf("%g", 385) == "~3.8e2"');
|
||||
|
||||
/* tests with tilde_space == 0 */
|
||||
c = config("tilde_space", 1);
|
||||
print '4832: c = config("tilde_space", 1)';
|
||||
vrfy(strprintf("%f", 1.375) == "~ 1.38",
|
||||
'4833: strprintf("%f", 1.375) == "~ 1.38"');
|
||||
vrfy(strprintf("%f", 27/29) == "~ .93",
|
||||
'4834: strprintf("%f", 27/29) == "~ .93"');
|
||||
vrfy(strprintf("%e", 12345) == "~ 1.23e4",
|
||||
'4835: strprintf("%e", 12345) == "~ 1.23e4"');
|
||||
vrfy(strprintf("%g", .385) == "~ .38",
|
||||
'4836: strprintf("%g", .385) == "~ .38"');
|
||||
vrfy(strprintf("%g", 385) == "~ 3.8e2",
|
||||
'4837: strprintf("%g", 385) == "~ 3.8e2"');
|
||||
|
||||
/* mode tests with tilde == 0 */
|
||||
c = config("tilde", 0);
|
||||
print '4825: c = config("tilde", 0)';
|
||||
print '4838: c = config("tilde", 0)';
|
||||
vrfy(strprintf("%e", 12345) == "1.23e4",
|
||||
'4826: strprintf("%e", 12345) == "1.23e4"');
|
||||
'4839: strprintf("%e", 12345) == "1.23e4"');
|
||||
vrfy(strprintf("%.3e", 12345) == "1.234e4",
|
||||
'4827: strprintf("%.3e", 12345) == "1.234e4"');
|
||||
'4840: strprintf("%.3e", 12345) == "1.234e4"');
|
||||
vrfy(strprintf("%e", .00012345) == "1.23e-4",
|
||||
'4828: strprintf("%e", .00012345) == "1.23e-4"');
|
||||
'4841: strprintf("%e", .00012345) == "1.23e-4"');
|
||||
vrfy(strprintf("%d %d", 27) == "27 ",
|
||||
'4829: strprintf("%d %d", 27) == "27 "');
|
||||
'4842: strprintf("%d %d", 27) == "27 "');
|
||||
vrfy(strprintf("%d", 27, 29) == "27",
|
||||
'4830: strprintf("%d", 27, 29) == "27"');
|
||||
'4843: strprintf("%d", 27, 29) == "27"');
|
||||
vrfy(strprintf("%r = %f", 27/29, 27/29) == "27/29 = .93",
|
||||
'4831: strprintf("%r = %f", 27/29, 27/29) == "27/29 = .93"');
|
||||
'4844: strprintf("%r = %f", 27/29, 27/29) == "27/29 = .93"');
|
||||
vrfy(strprintf("%s", "abc") == "abc",
|
||||
'4832: strprintf("%s", "abc") == "abc"');
|
||||
'4845: strprintf("%s", "abc") == "abc"');
|
||||
vrfy(strprintf("%f", "abc") == "abc",
|
||||
'4833: strprintf("%f", "abc") == "abc"');
|
||||
'4846: strprintf("%f", "abc") == "abc"');
|
||||
vrfy(strprintf("%e", "abc") == "abc",
|
||||
'4834: strprintf("%e", "abc") == "abc"');
|
||||
'4847: strprintf("%e", "abc") == "abc"');
|
||||
vrfy(strprintf("%5s", "abc") == " abc",
|
||||
'4835: strprintf("%5s", "abc") == " abc"');
|
||||
'4848: strprintf("%5s", "abc") == " abc"');
|
||||
vrfy(strprintf("%-5s", "abc") == "abc ",
|
||||
'4836: strprintf("%-5s", "abc") == "abc "');
|
||||
'4849: strprintf("%-5s", "abc") == "abc "');
|
||||
vrfy(strprintf("%g", .385) == ".38",
|
||||
'4837: strprintf("%g", .385) == ".38"');
|
||||
'4850: strprintf("%g", .385) == ".38"');
|
||||
vrfy(strprintf("%g", 385) == "3.8e2",
|
||||
'4838: strprintf("%g", 385) == "3.8e2"');
|
||||
'4851: strprintf("%g", 385) == "3.8e2"');
|
||||
|
||||
c = config("fraction_space", 1);
|
||||
print '4852: c = config("fraction_space", 1)';
|
||||
vrfy(strprintf("%r = %f", 27/29, 27/29) == "27 / 29 = .93",
|
||||
'4853: strprintf("%r = %f", 27/29, 27/29) == "27 / 29 = .93"');
|
||||
|
||||
/* restore config */
|
||||
c = config("all", callcfg);
|
||||
print '4839: c = config("all", callcfg)';
|
||||
print '4854: c = config("all", callcfg)';
|
||||
|
||||
print '4840: Ending test_strprintf';
|
||||
print '4855: Ending test_strprintf';
|
||||
}
|
||||
print '088: parsed test_fileop()';
|
||||
|
||||
@@ -8117,7 +8173,7 @@ vrfy(config("redecl_warn",0), '8651: config("redecl_warn",0)');
|
||||
vrfy(config("dupvar_warn",0), '8652: config("dupvar_warn",0)');
|
||||
vrfy(u_glob == 6, '8653: u_glob == 6');
|
||||
global u_glob = 555;
|
||||
print '8654: declare u_glob';
|
||||
print '8654: declare u_glob';
|
||||
vrfy(u_glob == 555, '8655: u_glob == 555');
|
||||
define func_8650(u_glob) { local u_glob; return u_glob; }
|
||||
print '8656: u_glob as both local and parameter';
|
||||
|
@@ -3,19 +3,37 @@
|
||||
*
|
||||
* This file was created by Ernest Bowen <ebowen at une dot edu dot au>.
|
||||
*
|
||||
* This code has been placed in the public domain. Please do not
|
||||
* copyright this code.
|
||||
*
|
||||
* ERNEST BOWEN DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER-
|
||||
* CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT
|
||||
* NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* This file is not covered under version 2.1 of the GNU LGPL.
|
||||
* This file is covered under "The unlicense":
|
||||
*
|
||||
* https://unlicense.org
|
||||
*
|
||||
* In particular:
|
||||
*
|
||||
* This is free and unencumbered software released into the public domain.
|
||||
*
|
||||
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
* distribute this software, either in source code form or as a compiled
|
||||
* binary, for any purpose, commercial or non-commercial, and by any
|
||||
* means.
|
||||
*
|
||||
* In jurisdictions that recognize copyright laws, the author or authors
|
||||
* of this software dedicate any and all copyright interest in the
|
||||
* software to the public domain. We make this dedication for the benefit
|
||||
* of the public at large and to the detriment of our heirs and
|
||||
* successors. We intend this dedication to be an overt act of
|
||||
* relinquishment in perpetuity of all present and future rights to this
|
||||
* software under copyright law.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* For more information, please refer to <http://unlicense.org/>
|
||||
*
|
||||
* Under source code control: 2006/03/08 05:54:09
|
||||
* File existed as early as: 2006
|
||||
|
83
cal/splitbits.cal
Normal file
83
cal/splitbits.cal
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* splitbits - split an integer into list on bit boundardies of a fixed size
|
||||
*
|
||||
* Copyright (C) 2018,2023 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: 2006/06/07 14:10:11
|
||||
* File existed as early as: 2006
|
||||
*
|
||||
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* setup splitbits errors
|
||||
*/
|
||||
static E_SPLITBITS_1, E_SPLITBITS_2, E_SPLITBITS_3;
|
||||
if (! iserror(E_SPLITBITS_1)) E_SPLITBITS_1 = newerror("1st argument to splitbits must be an integer");
|
||||
if (! iserror(E_SPLITBITS_2)) E_SPLITBITS_2 = newerror("2nd argument to splitbits must be an integer");
|
||||
if (! iserror(E_SPLITBITS_3)) E_SPLITBITS_3 = newerror("2nd argument must be an integer > 0");
|
||||
|
||||
|
||||
/*
|
||||
* define splitbits function
|
||||
*/
|
||||
define splitbits(x, b)
|
||||
{
|
||||
local ret; /* list to return */
|
||||
local mask; /* 2^b-1 */
|
||||
local x_is_reg = 0; /* true if x < 0 */
|
||||
|
||||
/* firewall */
|
||||
if (! isint(x)) {
|
||||
return error(E_SPLITBITS_1);
|
||||
}
|
||||
if (! isint(b)) {
|
||||
return error(E_SPLITBITS_2);
|
||||
}
|
||||
if (b <= 0) {
|
||||
return error(E_SPLITBITS_3);
|
||||
}
|
||||
|
||||
/* special case: x == 0 */
|
||||
if (x == 0) {
|
||||
return list(0);
|
||||
}
|
||||
|
||||
/* setup for splitting x */
|
||||
ret = list();
|
||||
mask = 2^b-1;
|
||||
if (x < 0) {
|
||||
x_is_reg = 1;
|
||||
x = abs(x);
|
||||
}
|
||||
|
||||
/* split x */
|
||||
while (x > 0) {
|
||||
printf("%d %x\n", size(ret), x);
|
||||
if (x_is_reg) {
|
||||
append(ret, xor(x & mask, mask));
|
||||
} else {
|
||||
append(ret, x & mask);
|
||||
}
|
||||
x >>= b;
|
||||
}
|
||||
|
||||
/* return list */
|
||||
return ret;
|
||||
}
|
@@ -2058,11 +2058,17 @@ define t010()
|
||||
return 5;
|
||||
}
|
||||
/*
|
||||
* Once, when an expression such as 0^(6-6) returned 0,
|
||||
* When an expression such as 0^(6-6) returned 0,
|
||||
* then stirling2(10, 5) == 42525. However when we made9
|
||||
* 0^(6-6) == 0^0 == 1, then stirling2(10, 5) == 5102999/120.
|
||||
* 0^(6-6) == 0^0 == 1, then stirling2(10, 5) == 5102999/120
|
||||
* as in:
|
||||
*
|
||||
* if ((stirling2(10, 5) - (5102999/120)) != 0) {
|
||||
* epsilon(eps);
|
||||
* return 6;
|
||||
* }
|
||||
*/
|
||||
if ((stirling2(10, 5) - (5102999/120)) != 0) {
|
||||
if ((stirling2(10, 5) - 42525) != 0) {
|
||||
epsilon(eps);
|
||||
return 6;
|
||||
}
|
||||
|
21
calc.c
21
calc.c
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
* calc - arbitrary precision calculator
|
||||
*
|
||||
* Copyright (C) 1999-2013,2021 David I. Bell, Landon Curt Noll
|
||||
* and Ernest Bowen
|
||||
* Copyright (C) 1999-2013,2021,2022 David I. Bell, Landon Curt Noll and Ernest Bowen
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
*
|
||||
@@ -85,6 +84,7 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -108,8 +108,6 @@ main(int argc, char **argv)
|
||||
int c; /* option */
|
||||
int index;
|
||||
int maxindex;
|
||||
/* fix gcc warning bug */
|
||||
int unusedint = 0;
|
||||
char *cp;
|
||||
char *endcp;
|
||||
char *bp;
|
||||
@@ -289,9 +287,7 @@ main(int argc, char **argv)
|
||||
exit(6);
|
||||
}
|
||||
calc_debug = cp;
|
||||
/* fix gcc warning bug */
|
||||
unusedint =
|
||||
strtol(cp, &endcp, 10);
|
||||
(void) strtol(cp, &endcp, 10);
|
||||
cp = endcp;
|
||||
if (*cp != '\0' &&
|
||||
*cp != ' ' && *cp != ':') {
|
||||
@@ -323,9 +319,7 @@ main(int argc, char **argv)
|
||||
exit(9);
|
||||
}
|
||||
resource_debug = cp;
|
||||
/* fix gcc warning bug */
|
||||
unusedint =
|
||||
strtol(cp, &endcp, 10);
|
||||
(void) strtol(cp, &endcp, 10);
|
||||
cp = endcp;
|
||||
if (*cp != '\0' &&
|
||||
*cp != ' ' && *cp != ':') {
|
||||
@@ -355,8 +349,7 @@ main(int argc, char **argv)
|
||||
exit(12);
|
||||
}
|
||||
user_debug = cp;
|
||||
/* unusedint avoids gcc warning bug */
|
||||
unusedint = strtol(cp, &endcp, 10);
|
||||
(void) strtol(cp, &endcp, 10);
|
||||
cp = endcp;
|
||||
if (*cp != '\0' && *cp != ' ') {
|
||||
fprintf(stderr, "Bad syntax in"
|
||||
@@ -765,8 +758,6 @@ main(int argc, char **argv)
|
||||
/*
|
||||
* All done! - Jessica Noll, Age 2
|
||||
*/
|
||||
/* fix gcc warning bug */
|
||||
unusedint++;
|
||||
libcalc_call_me_last();
|
||||
return (run_state == RUN_EXIT_WITH_ERROR ||
|
||||
run_state == RUN_ZERO) ? 1 : 0;
|
||||
@@ -786,7 +777,7 @@ intint(int UNUSED(arg))
|
||||
(void) signal(SIGINT, intint);
|
||||
if (inputwait || (++abortlevel >= ABORT_NOW)) {
|
||||
calc_interrupt("\nABORT");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (abortlevel >= ABORT_MATH)
|
||||
_math_abort_ = TRUE;
|
||||
|
350
calc.man
350
calc.man
@@ -251,9 +251,6 @@ For example:
|
||||
\fI#!${BINDIR}/calc\fP \fB\-q\fP \fB\-f\fP
|
||||
.fi
|
||||
.in -5n
|
||||
.sp 1
|
||||
This allows the script to run independently of
|
||||
startup scripts.
|
||||
|
||||
.sp 1
|
||||
See
|
||||
@@ -294,6 +291,24 @@ This will cause calc to process lines in
|
||||
in
|
||||
.BR "shell script mode" .
|
||||
|
||||
.sp 1
|
||||
.B NOTE:
|
||||
The use of
|
||||
.BR \-f
|
||||
does
|
||||
.B NOT
|
||||
imply
|
||||
.BR \-q
|
||||
and thus one would need to use
|
||||
.sp 1
|
||||
.in +5n
|
||||
.nf
|
||||
\fIcalc\fP\ [optional_other_flags\ \&...] \fB\-q\fP \fB\-f\fP filename
|
||||
.fi
|
||||
.in -5n
|
||||
.sp 1
|
||||
to disable the use of calc startup files as well.
|
||||
|
||||
.sp 1
|
||||
The use of
|
||||
.B \-f
|
||||
@@ -458,6 +473,13 @@ flag overrides
|
||||
.TP
|
||||
.B \-q
|
||||
Disable the reading of the startup scripts.
|
||||
.sp 1
|
||||
This allows the script to run independently of
|
||||
startup scripts such those managed by the
|
||||
.B $CALCRC
|
||||
environment variable.
|
||||
For example, this will disable the use of the common calcrc file
|
||||
(usually ~/.calcrc).
|
||||
|
||||
.TP
|
||||
.B \-s
|
||||
@@ -596,7 +618,7 @@ may have to be replaced by:
|
||||
.sp 1
|
||||
.in +5n
|
||||
.nf
|
||||
print 27! ^2 or print 27\!^2
|
||||
print 27! ^2 or print 27\\!^2
|
||||
.fi
|
||||
.in -5n
|
||||
|
||||
@@ -813,6 +835,23 @@ are automatically set if
|
||||
.B \-i
|
||||
is not given.
|
||||
.sp 1
|
||||
.B NOTE:
|
||||
The use of
|
||||
.BR \-f
|
||||
does
|
||||
.B NOT
|
||||
imply
|
||||
.BR \-q
|
||||
and thus one would need to use
|
||||
.sp 1
|
||||
.in +5n
|
||||
.nf
|
||||
\fIcalc\fP\ [optional_other_flags\ \&...] \fB\-q\fP \fB\-f\fP filename
|
||||
.fi
|
||||
.in -5n
|
||||
.sp 1
|
||||
to disable the use of calc startup files as well.
|
||||
.sp 1
|
||||
For example, if
|
||||
the file
|
||||
.BR /tmp/mersenne :
|
||||
@@ -1186,6 +1225,7 @@ The calc commands:
|
||||
help copyright
|
||||
help copying
|
||||
help copying-lgpl
|
||||
help credit
|
||||
.fi
|
||||
.in -0.5i
|
||||
.sp
|
||||
@@ -1220,6 +1260,10 @@ Copyright (C) year David I. Bell, Landon Curt Noll and Ernest Bowen
|
||||
Copyright (C) year Landon Curt Noll
|
||||
Copyright (C) year Ernest Bowen and Landon Curt Noll
|
||||
Copyright (C) year Ernest Bowen
|
||||
Copyright (C) year Petteri Kettunen and Landon Curt Noll
|
||||
Copyright (C) year Christoph Zurnieden
|
||||
Copyright (C) year Landon Curt Noll and Thomas Jones-Low
|
||||
Copyright (C) year Klaus Alexander Seistrup and Landon Curt Noll
|
||||
.fi
|
||||
.in -0.5i
|
||||
.sp
|
||||
@@ -1227,12 +1271,22 @@ This man page is:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
Copyright (C) 1999-2021 Landon Curt Noll
|
||||
Copyright (C) 1999-2023 Landon Curt Noll
|
||||
.fi
|
||||
.in -0.5i
|
||||
.sp
|
||||
and is covered under version 2.1 GNU Lesser General
|
||||
Public License.
|
||||
.sp
|
||||
A few files in calc are covered under "The Unlicense".
|
||||
For more information on this license, see:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
https://unlicense.org
|
||||
.fi
|
||||
.in -0.5i
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
@@ -1240,61 +1294,38 @@ Public License.
|
||||
|
||||
.PP
|
||||
|
||||
If you have a simple general question about calc, send Email to:
|
||||
.sp
|
||||
.in +0.5i
|
||||
calc-quest-mail at asthe dot com
|
||||
.sp
|
||||
NOTE: Remove spaces and replace 'at' with @, and 'dot' with .
|
||||
.in -0.5i
|
||||
.sp
|
||||
.in +0.5i
|
||||
NOTE: Yes, the Email address uses 'asthe',
|
||||
while the web site uses 'isthe'.
|
||||
.in -0.5i
|
||||
.sp
|
||||
.B PLEASE
|
||||
put following the
|
||||
.B SPECIAL PHRASE
|
||||
somewhere in your Email Subject line:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.B calc question
|
||||
.in -0.5i
|
||||
.sp
|
||||
You may add additional words to your subject line.
|
||||
.sp
|
||||
.B IMPORTANT:
|
||||
If your Email doesn't contain the above phrase,
|
||||
then we
|
||||
.B WILL NOT SEE
|
||||
your Email.
|
||||
.sp
|
||||
.B PLEASE BE SURE
|
||||
you have that
|
||||
.B SPECIAL PHRASE
|
||||
somewhere in the subject line!
|
||||
.sp
|
||||
.B Suggestion:
|
||||
.sp
|
||||
.in +0.5i
|
||||
From time to time, the Email address and Subject
|
||||
.B SPECIAL PHRASE
|
||||
may change so verify you have the current info by visiting:
|
||||
To ask the calc maintainers a general question about calc,
|
||||
see the output of the following calc command:
|
||||
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
http://www.isthe.com/chongo/tech/comp/calc/calc-question.html
|
||||
; help question
|
||||
.fi
|
||||
.in -0.5i
|
||||
.in -0.5i
|
||||
.in +0.5i
|
||||
.sp
|
||||
Please limit your questions to general questions about calc.
|
||||
We cannot go into great detail in our answers,
|
||||
nor can we do your homework, nor can
|
||||
we do much more than answer short general questions about calc.
|
||||
.PP
|
||||
|
||||
or read the source file:
|
||||
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
QUESTIONS
|
||||
.fi
|
||||
.in +0.5i
|
||||
.sp
|
||||
|
||||
.PP
|
||||
|
||||
or visit the following URL:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
https://github.com/lcn2/calc/blob/master/QUESTIONS
|
||||
.fi
|
||||
.in +0.5i
|
||||
.sp
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
|
||||
.PP
|
||||
|
||||
@@ -1302,71 +1333,37 @@ Please be patient as we cannot always respond to Email messages quickly.
|
||||
|
||||
.PP
|
||||
|
||||
Send bug reports and bug fixes to:
|
||||
To inform the calc maintainers about a bug, or to submit a bug fix,
|
||||
see the output of the following calc command:
|
||||
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
calc-bugrept at asthe dot com
|
||||
; help bugs
|
||||
.fi
|
||||
.sp
|
||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
||||
.sp
|
||||
NOTE: Yes, the Email address uses 'asthe',
|
||||
while the web site uses 'isthe'.
|
||||
.in -0.5i
|
||||
.sp
|
||||
You
|
||||
.B MUST
|
||||
use following
|
||||
.B SPECIAL PHRASE
|
||||
in your Email Subject line:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.B calc bug report
|
||||
.in -0.5i
|
||||
.sp
|
||||
You may add additional words to your subject line.
|
||||
.sp
|
||||
.B Suggestion:
|
||||
.sp
|
||||
.in +0.5i
|
||||
From time to time, the Email address and Subject
|
||||
.B SPECIAL PHRASE
|
||||
may change so verify you have the current info by visiting:
|
||||
.PP
|
||||
|
||||
or read the source file:
|
||||
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
|
||||
BUGS
|
||||
.fi
|
||||
.in -0.5i
|
||||
.in -0.5i
|
||||
.in +0.5i
|
||||
.sp
|
||||
.B IMPORTANT:
|
||||
If your Email doesn't contain the above phrase,
|
||||
then we
|
||||
.B WILL NOT SEE
|
||||
your Email.
|
||||
.sp
|
||||
.B PLEASE BE SURE
|
||||
you have that
|
||||
.B SPECIAL PHRASE
|
||||
somewhere in the subject line!
|
||||
.sp
|
||||
See the
|
||||
.I BUGS
|
||||
source file or use the
|
||||
.I calc
|
||||
command:
|
||||
.PP
|
||||
|
||||
or visit the following URL:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
help bugs
|
||||
https://github.com/lcn2/calc/blob/master/BUGS
|
||||
.fi
|
||||
.in -0.5i
|
||||
.in +0.5i
|
||||
.sp
|
||||
for more information about bug reporting.
|
||||
.sp
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
|
||||
.PP
|
||||
|
||||
@@ -1376,126 +1373,40 @@ Please be patient as we cannot always respond to Email messages quickly.
|
||||
|
||||
.I Calc
|
||||
is open source.
|
||||
Contributions of code are welcome.
|
||||
.sp
|
||||
We welcome and encourage you to send us:
|
||||
You are welcome to contribute code to calc, or submit bug fixes to to calc.
|
||||
.sp
|
||||
To contribute code to calc, please see see the output of
|
||||
the following calc command:
|
||||
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
* calc resource files (cal/*.cal)
|
||||
* calc shell scripts (cscript/*.calc)
|
||||
* builtin functions that you have modified or written, i.e.:
|
||||
assocfunc.c comfunc.c func.c func.h
|
||||
listfunc.c matfunc.c qfunc.c zfunc.c
|
||||
* custom functions that you have modified or written (custom/*)
|
||||
* help files modified or written (help/*)
|
||||
* brief description of you added, fixed, improved in CHANGES
|
||||
* regression test cases (cal/regress.cal)
|
||||
* Makefile improvements (Makefile, */Makefile)
|
||||
* other source code modifications (*.c, *.h)
|
||||
* etc. (* */* :) )
|
||||
; help contrib
|
||||
.fi
|
||||
.in -0.5i
|
||||
.sp
|
||||
If you add functionality to calc, please be sure to modify/patch/add
|
||||
Makefiles, help files, cal/regress.cal test code as well.
|
||||
Regression test cases are vital to maintaining calc's level
|
||||
of correctness and helps us avoid code bug regression.
|
||||
.sp
|
||||
In order to consider integrating your code, we need:
|
||||
.sp
|
||||
.nf
|
||||
.in +0.5i
|
||||
* calc version you are working with (please try use the latest version)
|
||||
* new help files or help file patches, if applicable (documentation)
|
||||
* proposed text for the CHANGES file (brief description of what it does)
|
||||
* regress.cal test patch as needed
|
||||
* your source code and/or source code changes (:-))
|
||||
.in -0.5i
|
||||
.fi
|
||||
.sp
|
||||
The best way to send us new code, if your changes are small, is
|
||||
via a patch (diff -c from the latest alpha code to your code).
|
||||
If your change is large, you should send entire files (either
|
||||
as a diff -c /dev/null your-file patch, or as a uuencoded and
|
||||
gziped (or compressed) tar file).
|
||||
.sp
|
||||
Please try to generate a patch against the most recent
|
||||
version of calc, and if you use GitHub, the top of the
|
||||
master branch:
|
||||
.sp
|
||||
.nf
|
||||
.in +0.5i
|
||||
https://github.com/lcn2/calc
|
||||
.in -0.5i
|
||||
.fi
|
||||
.sp
|
||||
.sp
|
||||
The best way contribute to calc bug is to generate calc
|
||||
GitHub pull request:
|
||||
.sp
|
||||
.nf
|
||||
.in +0.5i
|
||||
https://github.com/lcn2/calc/pulls
|
||||
.in -0.5i
|
||||
.fi
|
||||
.sp
|
||||
Your code needs to be contributed under either the 2.1 of the
|
||||
.B GNU Lesser General Public License (LGPL 2.1)
|
||||
or be in the public domain.
|
||||
.sp
|
||||
If you do not want to use calc GitHub, then send Email to:
|
||||
|
||||
.PP
|
||||
|
||||
or read the source file:
|
||||
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
calc-contrib at asthe dot com
|
||||
CONTRIB-CODE
|
||||
.fi
|
||||
.sp
|
||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
||||
.sp
|
||||
NOTE: Yes, the Email address uses 'asthe',
|
||||
while the web site uses 'isthe'.
|
||||
.in -0.5i
|
||||
.sp
|
||||
You
|
||||
.B MUST
|
||||
use following
|
||||
.B SPECIAL PHRASE
|
||||
in your Email Subject line:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.B calc contribution
|
||||
.in -0.5i
|
||||
.sp
|
||||
You may add additional words to your subject line.
|
||||
.sp
|
||||
.B Suggestion:
|
||||
.sp
|
||||
.in +0.5i
|
||||
From time to time, the Email address and Subject
|
||||
.B SPECIAL PHRASE
|
||||
may change so verify you have the current info by visiting:
|
||||
|
||||
.PP
|
||||
|
||||
or visit the following URL:
|
||||
.sp
|
||||
.in +0.5i
|
||||
.nf
|
||||
http://www.isthe.com/chongo/tech/comp/calc/calc-contrib.html
|
||||
https://github.com/lcn2/calc/blob/master/CONTRIB-CODE
|
||||
.fi
|
||||
.in -0.5i
|
||||
.in -0.5i
|
||||
.in +0.5i
|
||||
.sp
|
||||
.B IMPORTANT:
|
||||
If your Email doesn't contain the above phrase,
|
||||
then we
|
||||
.B WILL NOT SEE
|
||||
your Email.
|
||||
.sp
|
||||
.B PLEASE BE SURE
|
||||
you have that
|
||||
.B SPECIAL PHRASE
|
||||
somewhere in the subject line!
|
||||
.sp
|
||||
Please be patient as we cannot always respond to Email messages quickly.
|
||||
|
||||
.PP
|
||||
|
||||
@@ -1510,5 +1421,30 @@ web site is located at:
|
||||
.in +0.5i
|
||||
www.isthe.com/chongo/tech/comp/calc/
|
||||
.in -0.5i
|
||||
|
||||
.SH "CALC SOURCE CODE"
|
||||
|
||||
The latest version of calc source code may be obtained at
|
||||
the following GitHub repo:
|
||||
.sp
|
||||
Share and Enjoy! :\-)
|
||||
.in +0.5i
|
||||
https://github.com/lcn2/calc
|
||||
.in -0.5i
|
||||
.sp
|
||||
The very latest calc souece is found at the top master branch.
|
||||
|
||||
.PP
|
||||
|
||||
You may download the calc releases from:
|
||||
.sp
|
||||
.in +0.5i
|
||||
https://github.com/lcn2/calc/releases
|
||||
.in -0.5i
|
||||
.sp
|
||||
The releases marked
|
||||
.B ((Pre-release))
|
||||
are beta releases.
|
||||
.sp
|
||||
The most recent release that is NOT marked
|
||||
.B ((Pre-release))
|
||||
is the recommended stable release.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* codegen - module to generate opcodes from the input tokens
|
||||
*
|
||||
* Copyright (C) 1999-2007,2017,2021 David I. Bell and Ernest Bowen
|
||||
* Copyright (C) 1999-2007,2017,2021,2022 David I. Bell and Ernest Bowen
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
*
|
||||
@@ -51,6 +51,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -2383,16 +2384,16 @@ getfilename(char *name, size_t namelen, BOOL *once)
|
||||
if (symstr == NULL) {
|
||||
math_error(
|
||||
"string value pointer is NULL!!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
} else {
|
||||
math_error(
|
||||
"a filename variable must be a string");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
} else {
|
||||
math_error("no such global variable");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
|
37
comfunc.c
37
comfunc.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* comfunc - extended precision complex arithmetic non-primitive routines
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
|
||||
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
*
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "cmath.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -60,16 +61,16 @@ c_powi(COMPLEX *c, NUMBER *q)
|
||||
|
||||
if (qisfrac(q)) {
|
||||
math_error("Raising number to non-integral power");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (zge31b(q->num)) {
|
||||
math_error("Raising number to very large power");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
power = ztolong(q->num);
|
||||
if (ciszero(c) && (power == 0)) {
|
||||
math_error("Raising zero to zeroth power");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
sign = 1;
|
||||
if (qisneg(q))
|
||||
@@ -381,7 +382,7 @@ c_root(COMPLEX *c, NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qisneg(q) || qiszero(q) || qisfrac(q)) {
|
||||
math_error("Taking bad root of complex number");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (cisone(c) || qisone(q))
|
||||
return clink(c);
|
||||
@@ -446,7 +447,7 @@ c_exp(COMPLEX *c, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon for cexp");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (cisreal(c)) {
|
||||
tmp1 = qexp(c->real, epsilon);
|
||||
@@ -502,7 +503,7 @@ c_ln(COMPLEX *c, NUMBER *epsilon)
|
||||
|
||||
if (ciszero(c)) {
|
||||
math_error("logarithm of zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (cisone(c))
|
||||
return clink(&_czero_);
|
||||
@@ -599,7 +600,7 @@ c_cos(COMPLEX *c, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon for ccos");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
n = qilog2(epsilon);
|
||||
ctmp1 = comalloc();
|
||||
@@ -649,7 +650,7 @@ c_sin(COMPLEX *c, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon for csin");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (ciszero(c))
|
||||
return clink(&_czero_);
|
||||
@@ -1072,7 +1073,7 @@ c_polar(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon for cpolar");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q1))
|
||||
return clink(&_czero_);
|
||||
@@ -1114,12 +1115,12 @@ c_power(COMPLEX *c1, COMPLEX *c2, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon for cpower");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (ciszero(c1)) {
|
||||
if (cisreal(c2) && qisneg(c2->real)) {
|
||||
math_error ("Non-positive real exponent of zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return clink(&_czero_);
|
||||
}
|
||||
@@ -1190,12 +1191,18 @@ comprint(COMPLEX *c)
|
||||
qtmp = c->imag[0];
|
||||
if (qiszero(&qtmp))
|
||||
return;
|
||||
if (conf->complex_space) {
|
||||
math_chr(' ');
|
||||
}
|
||||
if (!qiszero(c->real) && !qisneg(&qtmp))
|
||||
math_chr('+');
|
||||
if (qisneg(&qtmp)) {
|
||||
math_chr('-');
|
||||
qtmp.num.sign = 0;
|
||||
}
|
||||
if (conf->complex_space) {
|
||||
math_chr(' ');
|
||||
}
|
||||
qprintnum(&qtmp, MODE_DEFAULT, conf->outdigits);
|
||||
math_chr('i');
|
||||
}
|
||||
@@ -1222,7 +1229,13 @@ cprintfr(COMPLEX *c)
|
||||
zprintval(i->num, 0L, 0L);
|
||||
math_chr('i');
|
||||
if (qisfrac(i)) {
|
||||
if (conf->fraction_space) {
|
||||
math_chr(' ');
|
||||
}
|
||||
math_chr('/');
|
||||
if (conf->fraction_space) {
|
||||
math_chr(' ');
|
||||
}
|
||||
zprintval(i->den, 0L, 0L);
|
||||
}
|
||||
}
|
||||
|
11
commath.c
11
commath.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* commath - extended precision complex arithmetic primitive routines
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell
|
||||
* Copyright (C) 1999-2007,2021,2022 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
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "cmath.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -189,7 +190,7 @@ c_div(COMPLEX *c1, COMPLEX *c2)
|
||||
|
||||
if (ciszero(c2)) {
|
||||
math_error("Division by zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if ((c1->real == c2->real) && (c1->imag == c2->imag))
|
||||
return clink(&_cone_);
|
||||
@@ -260,7 +261,7 @@ c_inv(COMPLEX *c)
|
||||
|
||||
if (ciszero(c)) {
|
||||
math_error("Inverting zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
r = comalloc();
|
||||
if (cisreal(c)) {
|
||||
@@ -522,7 +523,7 @@ c_divq(COMPLEX *c, NUMBER *q)
|
||||
|
||||
if (qiszero(q)) {
|
||||
math_error("Division by zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisone(q))
|
||||
return clink(c);
|
||||
@@ -605,7 +606,7 @@ comalloc(void)
|
||||
r = (COMPLEX *) malloc(sizeof(COMPLEX));
|
||||
if (r == NULL) {
|
||||
math_error("Cannot allocate complex number");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
r->links = 1;
|
||||
r->real = qlink(&_qzero_);
|
||||
|
289
config.c
289
config.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* config - configuration routines
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell and Landon Curt Noll
|
||||
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Landon Curt Noll
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
*
|
||||
@@ -62,6 +62,7 @@
|
||||
#endif /* HAVE_STRDUP */
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -92,6 +93,9 @@ NAMETYPE configs[] = {
|
||||
{"pow2", CONFIG_POW2},
|
||||
{"redc2", CONFIG_REDC2},
|
||||
{"tilde", CONFIG_TILDE},
|
||||
{"tilde_space", CONFIG_TILDE_SPACE},
|
||||
{"fraction_space", CONFIG_FRACTION_SPACE},
|
||||
{"complex_space", CONFIG_COMPLEX_SPACE},
|
||||
{"tab", CONFIG_TAB},
|
||||
{"quomod", CONFIG_QUOMOD},
|
||||
{"quo", CONFIG_QUO},
|
||||
@@ -149,8 +153,11 @@ CONFIG oldstd = { /* backward compatible standard configuration */
|
||||
SQ_ALG2, /* size of number to use square alg 2 */
|
||||
POW_ALG2, /* size of modulus to use REDC for powers */
|
||||
REDC_ALG2, /* size of modulus to use REDC algorithm 2 */
|
||||
TRUE, /* OK to print a tilde on approximations */
|
||||
TRUE, /* OK to print tab before numeric values */
|
||||
TRUE, /* TRUE ==> print a tilde on approximations */
|
||||
FALSE, /* TRUE ==> print a space after tilde on approximations */
|
||||
FALSE, /* TRUE ==> print spaces around / in fractions */
|
||||
FALSE, /* TRUE ==> print spaces around + or - in complex values */
|
||||
TRUE, /* TRUE ==> print tab before numeric values */
|
||||
0, /* quomod() default rounding mode */
|
||||
2, /* quotient // default rounding mode */
|
||||
0, /* mod % default rounding mode */
|
||||
@@ -160,8 +167,8 @@ CONFIG oldstd = { /* backward compatible standard configuration */
|
||||
8, /* cfsim() default rounding mode */
|
||||
2, /* output default rounding mode */
|
||||
24, /* round()/bround() default rounding mode */
|
||||
FALSE, /* OK to print leading 0 before decimal pt */
|
||||
0, /* OK to print trailing 0's */
|
||||
FALSE, /* TRUE ==> print leading 0 before decimal pt */
|
||||
0, /* TRUE ==> print trailing 0's */
|
||||
MAXSCANCOUNT, /* max scan errors before abort */
|
||||
PROMPT1, /* normal prompt */
|
||||
PROMPT2, /* prompt when inside multi-line input */
|
||||
@@ -172,30 +179,30 @@ CONFIG oldstd = { /* backward compatible standard configuration */
|
||||
0, /* internal calc debug level */
|
||||
3, /* calc resource file debug level */
|
||||
0, /* user defined debug level */
|
||||
FALSE, /* print Quit or abort executed messages */
|
||||
FALSE, /* TRUE ==> print Quit or abort executed messages */
|
||||
CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */
|
||||
NULL, /* our name */
|
||||
NULL, /* basename of our name */
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
TRUE, /* running under windows */
|
||||
TRUE, /* TRUE ==> running under windows */
|
||||
#else
|
||||
FALSE, /* not using windows */
|
||||
FALSE, /* FALSE ==> not using windows */
|
||||
#endif
|
||||
#if defined(__CYGWIN__)
|
||||
TRUE, /* compiled under cygwin */
|
||||
TRUE, /* TRUE ==> compiled under cygwin */
|
||||
#else
|
||||
FALSE, /* not compiled with cygwin */
|
||||
FALSE, /* FALSE ==> not compiled with cygwin */
|
||||
#endif
|
||||
#if defined(CUSTOM)
|
||||
TRUE, /* compiled with -DCUSTOM */
|
||||
TRUE, /* TRUE ==> compiled with -DCUSTOM */
|
||||
#else
|
||||
FALSE, /* compiled without -DCUSTOM */
|
||||
FALSE, /* FALSE ==> compiled without -DCUSTOM */
|
||||
#endif
|
||||
&allow_custom, /* *TRUE=> custom functions are enabled */
|
||||
NULL, /* version */
|
||||
BASEB, /* base for calculations */
|
||||
TRUE, /* warn when redeclaring */
|
||||
TRUE, /* warn when variable names collide */
|
||||
TRUE, /* TRUE ==> warn when redeclaring */
|
||||
TRUE, /* TRUE ==> warn when variable names collide */
|
||||
};
|
||||
CONFIG newstd = { /* new non-backward compatible configuration */
|
||||
MODE_INITIAL, /* current output mode */
|
||||
@@ -209,8 +216,11 @@ CONFIG newstd = { /* new non-backward compatible configuration */
|
||||
SQ_ALG2, /* size of number to use square alg 2 */
|
||||
POW_ALG2, /* size of modulus to use REDC for powers */
|
||||
REDC_ALG2, /* size of modulus to use REDC algorithm 2 */
|
||||
TRUE, /* OK to print a tilde on approximations */
|
||||
TRUE, /* OK to print tab before numeric values */
|
||||
TRUE, /* TRUE ==> print a tilde on approximations */
|
||||
FALSE, /* TRUE ==> print spaces around / in fractions */
|
||||
FALSE, /* TRUE ==> print a space after tilde on approximations */
|
||||
FALSE, /* TRUE ==> print spaces around + or - in complex values */
|
||||
TRUE, /* TRUE ==> print tab before numeric values */
|
||||
0, /* quomod() default rounding mode */
|
||||
2, /* quotient // default rounding mode */
|
||||
0, /* mod % default rounding mode */
|
||||
@@ -220,8 +230,8 @@ CONFIG newstd = { /* new non-backward compatible configuration */
|
||||
8, /* cfsim() default rounding mode */
|
||||
24, /* output default rounding mode */
|
||||
24, /* round()/bround() default rounding mode */
|
||||
TRUE, /* OK to print leading 0 before decimal pt */
|
||||
0, /* OK to print trailing 0's */
|
||||
TRUE, /* TRUE ==> print leading 0 before decimal pt */
|
||||
0, /* TRUE ==> print trailing 0's */
|
||||
MAXSCANCOUNT, /* max scan errors before abort */
|
||||
"; ", /* normal prompt */
|
||||
";; ", /* prompt when inside multi-line input */
|
||||
@@ -232,30 +242,30 @@ CONFIG newstd = { /* new non-backward compatible configuration */
|
||||
0, /* internal calc debug level */
|
||||
3, /* calc resource file debug level */
|
||||
0, /* user defined debug level */
|
||||
FALSE, /* print Quit or abort executed messages */
|
||||
FALSE, /* TRUE ==> print Quit or abort executed messages */
|
||||
CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */
|
||||
NULL, /* our name */
|
||||
NULL, /* basename of our name */
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
TRUE, /* running under windows */
|
||||
TRUE, /* TRUE ==> running under windows */
|
||||
#else
|
||||
FALSE, /* not using windows */
|
||||
FALSE, /* FALSE ==> not using windows */
|
||||
#endif
|
||||
#if defined(__CYGWIN__)
|
||||
TRUE, /* compiled under cygwin */
|
||||
TRUE, /* TRUE ==> compiled under cygwin */
|
||||
#else
|
||||
FALSE, /* not compiled with cygwin */
|
||||
FALSE, /* FALSE ==> not compiled with cygwin */
|
||||
#endif
|
||||
#if defined(CUSTOM)
|
||||
TRUE, /* compiled with -DCUSTOM */
|
||||
TRUE, /* TRUE ==> compiled with -DCUSTOM */
|
||||
#else
|
||||
FALSE, /* compiled without -DCUSTOM */
|
||||
FALSE, /* FALSE ==> compiled without -DCUSTOM */
|
||||
#endif
|
||||
&allow_custom, /* *TRUE=> custom functions are enabled */
|
||||
&allow_custom, /* *TRUE ==> custom functions are enabled */
|
||||
NULL, /* version */
|
||||
BASEB, /* base for calculations */
|
||||
TRUE, /* warn when redeclaring */
|
||||
TRUE, /* warn when variable names collide */
|
||||
TRUE, /* TRUE ==> warn when redeclaring */
|
||||
TRUE, /* TRUE ==> warn when variable names collide */
|
||||
};
|
||||
CONFIG *conf = NULL; /* loaded in at startup - current configuration */
|
||||
|
||||
@@ -488,11 +498,11 @@ setconfig(int type, VALUE *vp)
|
||||
newconf = &newstd;
|
||||
} else {
|
||||
math_error("CONFIG alias not oldstd or newstd");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
} else if (vp->v_type != V_CONFIG) {
|
||||
math_error("non-CONFIG for all");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
} else {
|
||||
newconf = vp->v_config;
|
||||
}
|
||||
@@ -507,14 +517,14 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_TRACE:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non-numeric for trace");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || !zistiny(q->num) ||
|
||||
((unsigned long) temp > TRACE_MAX)) {
|
||||
math_error("Bad trace value");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->traceflags = (FLAG)temp;
|
||||
break;
|
||||
@@ -522,7 +532,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_DISPLAY:
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Bad value for display");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
math_setdigits(len);
|
||||
break;
|
||||
@@ -530,12 +540,12 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_MODE:
|
||||
if (vp->v_type != V_STR) {
|
||||
math_error("Non-string for mode");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
temp = lookup_long(modes, vp->v_str->s_str);
|
||||
if (temp < 0) {
|
||||
math_error("Unknown mode \"%s\"", vp->v_str->s_str);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
math_setmode((int) temp);
|
||||
break;
|
||||
@@ -543,12 +553,12 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_MODE2:
|
||||
if (vp->v_type != V_STR) {
|
||||
math_error("Non-string for mode");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
temp = lookup_long(modes, vp->v_str->s_str);
|
||||
if (temp < 0) {
|
||||
math_error("Unknown mode \"%s\"", vp->v_str->s_str);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
math_setmode2((int) temp);
|
||||
break;
|
||||
@@ -556,7 +566,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_EPSILON:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non-numeric for epsilon");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
setepsilon(vp->v_num);
|
||||
break;
|
||||
@@ -564,7 +574,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_MAXPRINT:
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Bad value for maxprint");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->maxprint = len;
|
||||
break;
|
||||
@@ -572,7 +582,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_MUL2:
|
||||
if (getlen(vp, &len) || len < 0 || len == 1) {
|
||||
math_error("Bad value for mul2");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (len == 0)
|
||||
len = MUL_ALG2;
|
||||
@@ -582,7 +592,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_SQ2:
|
||||
if (getlen(vp, &len) || len < 0 || len == 1) {
|
||||
math_error("Bad value for sq2");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (len == 0)
|
||||
len = SQ_ALG2;
|
||||
@@ -592,7 +602,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_POW2:
|
||||
if (getlen(vp, &len) || len < 0 || len == 1) {
|
||||
math_error("Bad value for pow2");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (len == 0)
|
||||
len = POW_ALG2;
|
||||
@@ -602,7 +612,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_REDC2:
|
||||
if (getlen(vp, &len) || len < 0 || len == 1) {
|
||||
math_error("Bad value for redc2");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (len == 0)
|
||||
len = REDC_ALG2;
|
||||
@@ -617,12 +627,54 @@ setconfig(int type, VALUE *vp)
|
||||
temp = lookup_long(truth, vp->v_str->s_str);
|
||||
if (temp < 0) {
|
||||
math_error("Illegal truth value for tilde");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->tilde_ok = (int)temp;
|
||||
}
|
||||
break;
|
||||
|
||||
case CONFIG_TILDE_SPACE:
|
||||
if (vp->v_type == V_NUM) {
|
||||
q = vp->v_num;
|
||||
conf->tilde_space = !qiszero(q);
|
||||
} else if (vp->v_type == V_STR) {
|
||||
temp = lookup_long(truth, vp->v_str->s_str);
|
||||
if (temp < 0) {
|
||||
math_error("Illegal truth value for tilde_space");
|
||||
not_reached();
|
||||
}
|
||||
conf->tilde_space = (int)temp;
|
||||
}
|
||||
break;
|
||||
|
||||
case CONFIG_FRACTION_SPACE:
|
||||
if (vp->v_type == V_NUM) {
|
||||
q = vp->v_num;
|
||||
conf->fraction_space = !qiszero(q);
|
||||
} else if (vp->v_type == V_STR) {
|
||||
temp = lookup_long(truth, vp->v_str->s_str);
|
||||
if (temp < 0) {
|
||||
math_error("Illegal truth value for fraction_space");
|
||||
not_reached();
|
||||
}
|
||||
conf->fraction_space = (int)temp;
|
||||
}
|
||||
break;
|
||||
|
||||
case CONFIG_COMPLEX_SPACE:
|
||||
if (vp->v_type == V_NUM) {
|
||||
q = vp->v_num;
|
||||
conf->complex_space = !qiszero(q);
|
||||
} else if (vp->v_type == V_STR) {
|
||||
temp = lookup_long(truth, vp->v_str->s_str);
|
||||
if (temp < 0) {
|
||||
math_error("Illegal truth value for complex_space");
|
||||
not_reached();
|
||||
}
|
||||
conf->complex_space = (int)temp;
|
||||
}
|
||||
break;
|
||||
|
||||
case CONFIG_TAB:
|
||||
if (vp->v_type == V_NUM) {
|
||||
q = vp->v_num;
|
||||
@@ -631,7 +683,7 @@ setconfig(int type, VALUE *vp)
|
||||
temp = lookup_long(truth, vp->v_str->s_str);
|
||||
if (temp < 0) {
|
||||
math_error("Illegal truth value for tab");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->tab_ok = (int)temp;
|
||||
}
|
||||
@@ -640,7 +692,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_QUOMOD:
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for quomod");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->quomod = len;
|
||||
break;
|
||||
@@ -648,7 +700,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_QUO:
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for quo");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->quo = len;
|
||||
break;
|
||||
@@ -656,7 +708,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_MOD:
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for mod");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->mod = len;
|
||||
break;
|
||||
@@ -664,7 +716,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_SQRT:
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for sqrt");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->sqrt = len;
|
||||
break;
|
||||
@@ -672,7 +724,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_APPR:
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for appr");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->appr = len;
|
||||
break;
|
||||
@@ -680,7 +732,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_CFAPPR:
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for cfappr");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->cfappr = len;
|
||||
break;
|
||||
@@ -688,7 +740,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_CFSIM:
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for cfsim");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->cfsim = len;
|
||||
break;
|
||||
@@ -696,7 +748,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_OUTROUND:
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for outround");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->outround = len;
|
||||
break;
|
||||
@@ -704,7 +756,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_ROUND:
|
||||
if (getlen(vp, &len)) {
|
||||
math_error("Illegal value for round");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->round = len;
|
||||
break;
|
||||
@@ -715,10 +767,9 @@ setconfig(int type, VALUE *vp)
|
||||
conf->leadzero = !qiszero(q);
|
||||
} else if (vp->v_type == V_STR) {
|
||||
temp = lookup_long(truth, vp->v_str->s_str);
|
||||
if (temp < 0) { {
|
||||
if (temp < 0) {
|
||||
math_error("Illegal truth value for leadzero");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
not_reached();
|
||||
}
|
||||
conf->leadzero = (int)temp;
|
||||
}
|
||||
@@ -732,7 +783,7 @@ setconfig(int type, VALUE *vp)
|
||||
temp = lookup_long(truth, vp->v_str->s_str);
|
||||
if (temp < 0) { {
|
||||
math_error("Illegal truth value for fullzero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
conf->fullzero = (int)temp;
|
||||
@@ -742,7 +793,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_MAXSCAN:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non-numeric for maxscancount");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
@@ -750,7 +801,7 @@ setconfig(int type, VALUE *vp)
|
||||
temp = -1;
|
||||
if (temp < 0) {
|
||||
math_error("Maxscan value is out of range");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->maxscancount = temp;
|
||||
break;
|
||||
@@ -758,12 +809,12 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_PROMPT:
|
||||
if (vp->v_type != V_STR) {
|
||||
math_error("Non-string for prompt");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
p = (char *)malloc(vp->v_str->s_len + 1);
|
||||
if (p == NULL) {
|
||||
math_error("Cannot duplicate new prompt");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
|
||||
free(conf->prompt1);
|
||||
@@ -773,12 +824,12 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_MORE:
|
||||
if (vp->v_type != V_STR) {
|
||||
math_error("Non-string for more prompt");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
p = (char *)malloc(vp->v_str->s_len + 1);
|
||||
if (p == NULL) {
|
||||
math_error("Cannot duplicate new more prompt");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
|
||||
free(conf->prompt2);
|
||||
@@ -788,7 +839,7 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_BLKMAXPRINT:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non-numeric for blkmaxprint");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
@@ -796,7 +847,7 @@ setconfig(int type, VALUE *vp)
|
||||
temp = -1;
|
||||
if (temp < 0) {
|
||||
math_error("Blkmaxprint value is out of range");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->blkmaxprint = temp;
|
||||
break;
|
||||
@@ -809,7 +860,7 @@ setconfig(int type, VALUE *vp)
|
||||
temp = lookup_long(truth, vp->v_str->s_str);
|
||||
if (temp < 0) {
|
||||
math_error("Illegal truth value for blkverbose");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->blkverbose = (int)temp;
|
||||
}
|
||||
@@ -818,13 +869,13 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_BLKBASE:
|
||||
if (vp->v_type != V_STR) {
|
||||
math_error("Non-string for blkbase");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
temp = lookup_long(blk_base, vp->v_str->s_str);
|
||||
if (temp < 0) {
|
||||
math_error("Unknown mode \"%s\" for blkbase",
|
||||
vp->v_str->s_str);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->blkbase = temp;
|
||||
break;
|
||||
@@ -832,13 +883,13 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_BLKFMT:
|
||||
if (vp->v_type != V_STR) {
|
||||
math_error("Non-string for blkfmt");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
temp = lookup_long(blk_fmt, vp->v_str->s_str);
|
||||
if (temp < 0) {
|
||||
math_error("Unknown mode \"%s\" for blkfmt",
|
||||
vp->v_str->s_str);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->blkfmt = temp;
|
||||
break;
|
||||
@@ -846,13 +897,13 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_CALC_DEBUG:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for calc_debug");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || !zistiny(q->num)) {
|
||||
math_error("Illegal calc_debug parameter value");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->calc_debug = temp;
|
||||
break;
|
||||
@@ -860,13 +911,13 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_RESOURCE_DEBUG:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for resource_debug");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || !zistiny(q->num)) {
|
||||
math_error("Illegal resource_debug parameter value");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->resource_debug = temp;
|
||||
break;
|
||||
@@ -874,13 +925,13 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_USER_DEBUG:
|
||||
if (vp->v_type != V_NUM) {
|
||||
math_error("Non numeric for user_debug");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
q = vp->v_num;
|
||||
temp = qtoi(q);
|
||||
if (qisfrac(q) || !zistiny(q->num)) {
|
||||
math_error("Illegal user_debug parameter value");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->user_debug = temp;
|
||||
break;
|
||||
@@ -894,7 +945,7 @@ setconfig(int type, VALUE *vp)
|
||||
if (temp < 0) {
|
||||
math_error("Illegal truth value "
|
||||
"for verbose_quit");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->verbose_quit = (int)temp;
|
||||
}
|
||||
@@ -903,56 +954,56 @@ setconfig(int type, VALUE *vp)
|
||||
case CONFIG_CTRL_D:
|
||||
if (vp->v_type != V_STR) {
|
||||
math_error("Non-string for ctrl_d");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
temp = lookup_long(ctrl_d, vp->v_str->s_str);
|
||||
if (temp < 0) {
|
||||
math_error("Unknown mode \"%s\" for ctrl_d",
|
||||
vp->v_str->s_str);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->ctrl_d = temp;
|
||||
break;
|
||||
|
||||
case CONFIG_PROGRAM:
|
||||
math_error("The program config parameter is read-only");
|
||||
/*NOTREACHED*/
|
||||
abort();
|
||||
not_reached();
|
||||
break;
|
||||
|
||||
case CONFIG_BASENAME:
|
||||
math_error("The basename config parameter is read-only");
|
||||
/*NOTREACHED*/
|
||||
abort();
|
||||
not_reached();
|
||||
break;
|
||||
|
||||
case CONFIG_WINDOWS:
|
||||
math_error("The windows config parameter is read-only");
|
||||
/*NOTREACHED*/
|
||||
abort();
|
||||
not_reached();
|
||||
break;
|
||||
|
||||
case CONFIG_CYGWIN:
|
||||
math_error("The cygwin config parameter is read-only");
|
||||
/*NOTREACHED*/
|
||||
abort();
|
||||
not_reached();
|
||||
break;
|
||||
|
||||
case CONFIG_COMPILE_CUSTOM:
|
||||
math_error("The custom config parameter is read-only");
|
||||
/*NOTREACHED*/
|
||||
abort();
|
||||
not_reached();
|
||||
break;
|
||||
|
||||
case CONFIG_ALLOW_CUSTOM:
|
||||
math_error("The allow_custom config parameter is read-only");
|
||||
/*NOTREACHED*/
|
||||
abort();
|
||||
not_reached();
|
||||
break;
|
||||
|
||||
case CONFIG_VERSION:
|
||||
math_error("The version config parameter is read-only");
|
||||
/*NOTREACHED*/
|
||||
abort();
|
||||
not_reached();
|
||||
break;
|
||||
|
||||
case CONFIG_BASEB:
|
||||
math_error("The baseb config parameter is read-only");
|
||||
/*NOTREACHED*/
|
||||
abort();
|
||||
not_reached();
|
||||
break;
|
||||
|
||||
case CONFIG_REDECL_WARN:
|
||||
if (vp->v_type == V_NUM) {
|
||||
@@ -963,7 +1014,7 @@ setconfig(int type, VALUE *vp)
|
||||
if (temp < 0) {
|
||||
math_error("Illegal truth value for "
|
||||
"redecl_warn");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->redecl_warn = (int)temp;
|
||||
}
|
||||
@@ -978,7 +1029,7 @@ setconfig(int type, VALUE *vp)
|
||||
if (temp < 0) {
|
||||
math_error("Illegal truth value for "
|
||||
"dupvar_warn");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
conf->dupvar_warn = (int)temp;
|
||||
}
|
||||
@@ -986,13 +1037,13 @@ setconfig(int type, VALUE *vp)
|
||||
|
||||
case CONFIG_HZ:
|
||||
math_error("The clock tick rate config parameter is read-only");
|
||||
/*NOTREACHED*/
|
||||
abort();
|
||||
not_reached();
|
||||
break;
|
||||
|
||||
default:
|
||||
math_error("Setting illegal config parameter");
|
||||
/*NOTREACHED*/
|
||||
abort();
|
||||
not_reached();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1017,7 +1068,7 @@ config_copy(CONFIG *src)
|
||||
if (src == NULL || src->epsilon == NULL || src->prompt1 == NULL ||
|
||||
src->prompt2 == NULL) {
|
||||
math_error("bad CONFIG value");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1026,7 +1077,7 @@ config_copy(CONFIG *src)
|
||||
dest = (CONFIG *)malloc(sizeof(CONFIG));
|
||||
if (dest == NULL) {
|
||||
math_error("malloc of CONFIG failed");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1134,7 +1185,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
|
||||
if (cfg == NULL || cfg->epsilon == NULL || cfg->prompt1 == NULL ||
|
||||
cfg->prompt2 == NULL) {
|
||||
math_error("bad CONFIG value");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1161,7 +1212,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
|
||||
p = lookup_name(modes, cfg->outmode);
|
||||
if (p == NULL) {
|
||||
math_error("invalid output mode: %d", cfg->outmode);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
vp->v_str = makenewstring(p);
|
||||
return;
|
||||
@@ -1172,7 +1223,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
|
||||
if (p == NULL) {
|
||||
math_error("invalid secondary output mode: %d",
|
||||
cfg->outmode2);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
vp->v_str = makenewstring(p);
|
||||
return;
|
||||
@@ -1205,6 +1256,18 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
|
||||
i = (cfg->tilde_ok ? 1 : 0);
|
||||
break;
|
||||
|
||||
case CONFIG_TILDE_SPACE:
|
||||
i = (cfg->tilde_space ? 1 : 0);
|
||||
break;
|
||||
|
||||
case CONFIG_FRACTION_SPACE:
|
||||
i = (cfg->fraction_space ? 1 : 0);
|
||||
break;
|
||||
|
||||
case CONFIG_COMPLEX_SPACE:
|
||||
i = (cfg->complex_space ? 1 : 0);
|
||||
break;
|
||||
|
||||
case CONFIG_TAB:
|
||||
i = (cfg->tab_ok ? 1 : 0);
|
||||
break;
|
||||
@@ -1280,7 +1343,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
|
||||
p = lookup_name(blk_base, cfg->blkbase);
|
||||
if (p == NULL) {
|
||||
math_error("invalid block base: %d", cfg->blkbase);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
vp->v_str = makenewstring(p);
|
||||
return;
|
||||
@@ -1290,7 +1353,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
|
||||
p = lookup_name(blk_fmt, cfg->blkfmt);
|
||||
if (p == NULL) {
|
||||
math_error("invalid block format: %d", cfg->blkfmt);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
vp->v_str = makenewstring(p);
|
||||
return;
|
||||
@@ -1316,7 +1379,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
|
||||
p = lookup_name(ctrl_d, cfg->ctrl_d);
|
||||
if (p == NULL) {
|
||||
math_error("invalid Control-D: %d", cfg->ctrl_d);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
vp->v_str = makenewstring(p);
|
||||
return;
|
||||
@@ -1386,7 +1449,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
|
||||
|
||||
default:
|
||||
math_error("Getting illegal CONFIG element");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1416,12 +1479,12 @@ config_cmp(CONFIG *cfg1, CONFIG *cfg2)
|
||||
if (cfg1 == NULL || cfg1->epsilon == NULL || cfg1->prompt1 == NULL ||
|
||||
cfg1->prompt2 == NULL) {
|
||||
math_error("CONFIG #1 value is invalid");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (cfg2 == NULL || cfg2->epsilon == NULL || cfg2->prompt1 == NULL ||
|
||||
cfg2->prompt2 == NULL) {
|
||||
math_error("CONFIG #2 value is invalid");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
|
8
config.h
8
config.h
@@ -94,6 +94,9 @@
|
||||
#define CONFIG_REDECL_WARN 44
|
||||
#define CONFIG_DUPVAR_WARN 45
|
||||
#define CONFIG_HZ 46
|
||||
#define CONFIG_TILDE_SPACE 47
|
||||
#define CONFIG_FRACTION_SPACE 48
|
||||
#define CONFIG_COMPLEX_SPACE 49
|
||||
|
||||
|
||||
/*
|
||||
@@ -123,7 +126,7 @@ struct config {
|
||||
int outmode2; /* current secondary output mode */
|
||||
LEN outdigits; /* current output digits for float or exp */
|
||||
NUMBER *epsilon; /* default error for real functions */
|
||||
long epsilonprec; /* epsilon binary precision (tied to epsilon) */
|
||||
long epsilonprec; /* epsilon binary precision (tied to epsilon) */
|
||||
FLAG traceflags; /* tracing flags */
|
||||
LEN maxprint; /* number of elements to print */
|
||||
LEN mul2; /* size of number to use multiply algorithm 2 */
|
||||
@@ -131,6 +134,9 @@ struct config {
|
||||
LEN pow2; /* size of modulus to use REDC for powers */
|
||||
LEN redc2; /* size of modulus to use REDC algorithm 2 */
|
||||
BOOL tilde_ok; /* OK to print a tilde on approximations */
|
||||
BOOL tilde_space; /* print space after tilde on approximations */
|
||||
BOOL fraction_space; /* TRUE => print spaces around / in fractions */
|
||||
BOOL complex_space; /* TRUE => print spaces around + or - in complex values */
|
||||
BOOL tab_ok; /* OK to print tab before numeric values */
|
||||
LEN quomod; /* quomod() default rounding mode */
|
||||
LEN quo; /* quotient // default rounding mode */
|
||||
|
15
const.c
15
const.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* const - constant number storage module
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell
|
||||
* Copyright (C) 1999-2007,2021,2022 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
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "qmath.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -47,7 +48,7 @@ initconstants(void)
|
||||
consttable = (NUMBER **) calloc(sizeof(NUMBER *), CONSTALLOCSIZE);
|
||||
if (consttable == NULL) {
|
||||
math_error("Unable to allocate constant table");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
for (i = 0; initnumbs[i] != NULL; i++) {
|
||||
consttable[i] = initnumbs[i];
|
||||
@@ -108,7 +109,7 @@ addqconstant(NUMBER *q)
|
||||
sizeof(NUMBER *) * (constcount + CONSTALLOCSIZE));
|
||||
if (tp == NULL) {
|
||||
math_error("Unable to reallocate const table");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
consttable = tp;
|
||||
constavail = CONSTALLOCSIZE;
|
||||
@@ -179,11 +180,11 @@ constvalue(unsigned long index)
|
||||
{
|
||||
if (index >= constcount) {
|
||||
math_error("Bad index value for constvalue");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (consttable[index]->links == 0) {
|
||||
math_error("Constvalue has been freed!!!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return consttable[index];
|
||||
}
|
||||
@@ -196,12 +197,12 @@ freeconstant(unsigned long index)
|
||||
|
||||
if (index >= constcount) {
|
||||
math_error("Bad index value for freeconst");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
q = consttable[index];
|
||||
if (q->links == 0) {
|
||||
math_error("Attempting to free freed const location");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
qfree(q);
|
||||
if (index == constcount - 1) {
|
||||
|
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# cscript - makefile for calc shell script files
|
||||
#
|
||||
# Copyright (C) 1999-2006,2014,2017,2021 Landon Curt Noll
|
||||
# Copyright (C) 1999-2006,2014,2017,2021-2023 Landon Curt Noll
|
||||
#
|
||||
# SRC: cscript/Makefile
|
||||
#
|
||||
@@ -43,20 +44,21 @@
|
||||
# If your system has a up to date, bash shell, then
|
||||
# you may wish to use:
|
||||
#
|
||||
# SHELL= /bin/bash
|
||||
# SHELL= bash
|
||||
#
|
||||
# On some systems such as macOS, the bash shell is very
|
||||
# far behind to the point where is cannot be depended on.
|
||||
# On such systems, the sh may be a much better alternative
|
||||
# shell for this Makefile to use:
|
||||
#
|
||||
# SHELL= /bin/sh
|
||||
# SHELL= sh
|
||||
#
|
||||
SHELL= /bin/bash
|
||||
#SHELL= /bin/sh
|
||||
SHELL= bash
|
||||
#SHELL= sh
|
||||
#if 0 /* start of skip for non-Gnu makefiles */
|
||||
#
|
||||
ifeq ($(target),Darwin)
|
||||
SHELL:= /bin/zsh
|
||||
SHELL:= /bin/sh
|
||||
endif
|
||||
#endif /* end of skip for non-Gnu makefiles */
|
||||
|
||||
@@ -297,11 +299,17 @@ CALCLIBLIST=
|
||||
#
|
||||
CSCRIPT_TARGETS= ${SCRIPT}
|
||||
TARGETS= ${CSCRIPT_TARGETS} README
|
||||
#
|
||||
# rules that are not also names of files
|
||||
#
|
||||
PHONY= all clobber distlist install
|
||||
|
||||
# The reason for this Makefile
|
||||
#
|
||||
all: ${TARGETS} .all
|
||||
|
||||
.PHONY: ${PHONY}
|
||||
|
||||
README: README.src
|
||||
@${RM} -f $@
|
||||
@${SED} -e "s:#!/usr/local/src/bin/calc/calc:#!${BINDIR}/calc:" $?>$@
|
||||
|
9
custom.c
9
custom.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* custom - interface for custom software and hardware interfaces
|
||||
*
|
||||
* Copyright (C) 1999-2006,2018,2021 Landon Curt Noll
|
||||
* Copyright (C) 1999-2006,2018,2021,2022 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
|
||||
@@ -48,6 +48,7 @@
|
||||
#endif /* CUSTOM */
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -77,12 +78,12 @@ custom(char *name, int count, VALUE **vals)
|
||||
if (count < p->minargs) {
|
||||
math_error("Too few arguments for custom "
|
||||
"function \"%s\"", p->name);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (count > p->maxargs) {
|
||||
math_error("Too many arguments for custom "
|
||||
"function \"%s\"", p->name);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/* call the custom function */
|
||||
@@ -200,7 +201,7 @@ customhelp(char *name)
|
||||
customname = (char *)malloc(snprintf_len+1);
|
||||
if (customname == NULL) {
|
||||
math_error("bad malloc of customname");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
snprintf(customname, snprintf_len, "custhelp/%s", name);
|
||||
customname[snprintf_len] = '\0'; /* paranoia */
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#!/bin/make
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# custom - makefile for calc custom routines
|
||||
#
|
||||
# Copyright (C) 1999-2006,2014,2017-2018,2021 Landon Curt Noll
|
||||
# Copyright (C) 1999-2006,2014,2017-2018,2021,2023 Landon Curt Noll
|
||||
#
|
||||
# SRC: custom/Makefile
|
||||
#
|
||||
@@ -44,20 +44,21 @@
|
||||
# If your system has a up to date, bash shell, then
|
||||
# you may wish to use:
|
||||
#
|
||||
# SHELL= /bin/bash
|
||||
# SHELL= bash
|
||||
#
|
||||
# On some systems such as macOS, the bash shell is very
|
||||
# far behind to the point where is cannot be depended on.
|
||||
# On such systems, the zsh may be a much better alternative
|
||||
# On such systems, the sh may be a much better alternative
|
||||
# shell for this Makefile to use:
|
||||
#
|
||||
# SHELL= /bin/zsh
|
||||
# SHELL= sh
|
||||
#
|
||||
SHELL= /bin/bash
|
||||
#SHELL= /bin/sh
|
||||
SHELL= bash
|
||||
#SHELL= sh
|
||||
#if 0 /* start of skip for non-Gnu makefiles */
|
||||
#
|
||||
ifeq ($(target),Darwin)
|
||||
SHELL:= /bin/zsh
|
||||
SHELL:= /bin/sh
|
||||
endif
|
||||
#endif /* end of skip for non-Gnu makefiles */
|
||||
|
||||
@@ -474,7 +475,7 @@ EXT=
|
||||
|
||||
# The default calc versions
|
||||
#
|
||||
VERSION= 2.14.0.14
|
||||
VERSION= 2.14.2.2
|
||||
|
||||
# Names of shared libraries with versions
|
||||
#
|
||||
@@ -491,7 +492,7 @@ CO= co
|
||||
CP= cp
|
||||
DIFF= diff
|
||||
FMT= fmt
|
||||
GREP= egrep
|
||||
GREP= grep
|
||||
LN= ln
|
||||
LS= ls
|
||||
MAKE= make
|
||||
@@ -801,11 +802,17 @@ Makefile.simple: Makefile ../Makefile
|
||||
|
||||
depend:
|
||||
${Q} if [ -f ${MAKE_FILE}.bak ]; then \
|
||||
echo "custom/${MAKE_FILE}.bak exists, remove or move it"; \
|
||||
echo "custom/${MAKE_FILE}.bak exists, remove or move it" 1>&2; \
|
||||
exit 1; \
|
||||
else \
|
||||
${TRUE}; \
|
||||
fi
|
||||
${Q} if type -f ${MAKEDEPEND}; then \
|
||||
${TRUE}; \
|
||||
else \
|
||||
echo "make depend failed: cannot find makedepend command: ${MAKEDEPEND}" 1>&2; \
|
||||
exit 1; \
|
||||
fi
|
||||
${Q} echo forming custom/skel
|
||||
${Q} ${RM} -rf skel
|
||||
${Q} ${MKDIR} -p skel
|
||||
@@ -826,7 +833,7 @@ depend:
|
||||
echo '#endif /* '"$$tag"' */' >> "skel/custom/$$i"; \
|
||||
done
|
||||
${Q} (cd ..; ${MAKE} -f ${MAKE_FILE} hsrc)
|
||||
${MAKE} -f ../${MAKE_FILE} h_list 2>/dev/null | \
|
||||
(cd ..; ${MAKE} -f ${MAKE_FILE} h_list 2>/dev/null) | \
|
||||
while read i; do \
|
||||
if [ ! -f "../$$i" ]; then continue; fi; \
|
||||
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
|
||||
@@ -840,13 +847,13 @@ depend:
|
||||
${Q} echo custom/skel formed
|
||||
${Q} echo forming custom dependency list
|
||||
${Q} :> skel/custom/makedep.out
|
||||
${Q} cd skel/custom; ${MAKEDEPEND} \
|
||||
-${Q} cd skel/custom; ${MAKEDEPEND} \
|
||||
-I../../.. -w 1 -f makedep.out -- \
|
||||
${CFLAGS} -- \
|
||||
${C_SRC} 2>/dev/null
|
||||
${Q} ${CP} -f skel/custom/makedep.out skel/custom/makedep.in
|
||||
${Q} ${SED} -e 's|: ../../|: |' -E < skel/custom/makedep.in | \
|
||||
${GREP} -v /usr/include > skel/custom/makedep.out
|
||||
${GREP} -E -v /usr/include > skel/custom/makedep.out
|
||||
-${Q} for i in ${C_SRC} /dev/null; do \
|
||||
if [ X"$$i" != X"/dev/null" ]; then \
|
||||
echo "$$i" | ${SED} 's/^\(.*\)\.c/\1.o: \1.c/'; \
|
||||
@@ -860,7 +867,7 @@ depend:
|
||||
${Q} ${MV} ${MAKE_FILE} ${MAKE_FILE}.bak
|
||||
${Q} ${SED} -n '1,/^# DO NOT DELETE THIS LINE/p' \
|
||||
${MAKE_FILE}.bak > ${MAKE_FILE}
|
||||
${Q} ${GREP} -v '^#' skel/custom/makedep.out >> ${MAKE_FILE}
|
||||
${Q} ${GREP} -E -v '^#' skel/custom/makedep.out >> ${MAKE_FILE}
|
||||
${Q} echo removing skel
|
||||
${Q} ${RM} -rf skel
|
||||
-${Q} if ${CMP} -s ${MAKE_FILE}.bak ${MAKE_FILE}; then \
|
||||
@@ -1161,6 +1168,7 @@ uninstall:
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
c_argv.o: ../alloc.h
|
||||
c_argv.o: ../attribute.h
|
||||
c_argv.o: ../banned.h
|
||||
c_argv.o: ../block.h
|
||||
c_argv.o: ../byteswap.h
|
||||
@@ -1188,6 +1196,7 @@ c_argv.o: ../value.h
|
||||
c_argv.o: ../zmath.h
|
||||
c_argv.o: c_argv.c
|
||||
c_devnull.o: ../alloc.h
|
||||
c_devnull.o: ../attribute.h
|
||||
c_devnull.o: ../banned.h
|
||||
c_devnull.o: ../block.h
|
||||
c_devnull.o: ../byteswap.h
|
||||
@@ -1215,6 +1224,7 @@ c_devnull.o: ../value.h
|
||||
c_devnull.o: ../zmath.h
|
||||
c_devnull.o: c_devnull.c
|
||||
c_help.o: ../alloc.h
|
||||
c_help.o: ../attribute.h
|
||||
c_help.o: ../banned.h
|
||||
c_help.o: ../block.h
|
||||
c_help.o: ../byteswap.h
|
||||
@@ -1242,6 +1252,7 @@ c_help.o: ../value.h
|
||||
c_help.o: ../zmath.h
|
||||
c_help.o: c_help.c
|
||||
c_pmodm127.o: ../alloc.h
|
||||
c_pmodm127.o: ../attribute.h
|
||||
c_pmodm127.o: ../banned.h
|
||||
c_pmodm127.o: ../block.h
|
||||
c_pmodm127.o: ../byteswap.h
|
||||
@@ -1268,6 +1279,7 @@ c_pmodm127.o: ../value.h
|
||||
c_pmodm127.o: ../zmath.h
|
||||
c_pmodm127.o: c_pmodm127.c
|
||||
c_pzasusb8.o: ../alloc.h
|
||||
c_pzasusb8.o: ../attribute.h
|
||||
c_pzasusb8.o: ../banned.h
|
||||
c_pzasusb8.o: ../block.h
|
||||
c_pzasusb8.o: ../byteswap.h
|
||||
@@ -1294,6 +1306,7 @@ c_pzasusb8.o: ../value.h
|
||||
c_pzasusb8.o: ../zmath.h
|
||||
c_pzasusb8.o: c_pzasusb8.c
|
||||
c_register.o: ../alloc.h
|
||||
c_register.o: ../attribute.h
|
||||
c_register.o: ../banned.h
|
||||
c_register.o: ../block.h
|
||||
c_register.o: ../byteswap.h
|
||||
@@ -1321,6 +1334,7 @@ c_register.o: ../value.h
|
||||
c_register.o: ../zmath.h
|
||||
c_register.o: c_register.c
|
||||
c_sysinfo.o: ../alloc.h
|
||||
c_sysinfo.o: ../attribute.h
|
||||
c_sysinfo.o: ../banned.h
|
||||
c_sysinfo.o: ../block.h
|
||||
c_sysinfo.o: ../byteswap.h
|
||||
@@ -1355,6 +1369,7 @@ c_sysinfo.o: ../zrand.h
|
||||
c_sysinfo.o: ../zrandom.h
|
||||
c_sysinfo.o: c_sysinfo.c
|
||||
custtbl.o: ../alloc.h
|
||||
custtbl.o: ../attribute.h
|
||||
custtbl.o: ../banned.h
|
||||
custtbl.o: ../block.h
|
||||
custtbl.o: ../byteswap.h
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#!/bin/make
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# custom - makefile for calc custom routines
|
||||
#
|
||||
# Copyright (C) 1999-2006,2014,2017-2018,2021 Landon Curt Noll
|
||||
# Copyright (C) 1999-2006,2014,2017-2018,2021,2023 Landon Curt Noll
|
||||
#
|
||||
# SRC: custom/Makefile.simple - non-GNU version
|
||||
#
|
||||
@@ -44,17 +44,17 @@
|
||||
# If your system has a up to date, bash shell, then
|
||||
# you may wish to use:
|
||||
#
|
||||
# SHELL= /bin/bash
|
||||
# SHELL= bash
|
||||
#
|
||||
# On some systems such as macOS, the bash shell is very
|
||||
# far behind to the point where is cannot be depended on.
|
||||
# On such systems, the zsh may be a much better alternative
|
||||
# On such systems, the sh may be a much better alternative
|
||||
# shell for this Makefile to use:
|
||||
#
|
||||
# SHELL= /bin/zsh
|
||||
# SHELL= sh
|
||||
#
|
||||
SHELL= /bin/bash
|
||||
#SHELL= /bin/sh
|
||||
SHELL= bash
|
||||
#SHELL= sh
|
||||
|
||||
|
||||
# PREFIX - Top level location for calc
|
||||
@@ -445,7 +445,7 @@ EXT=
|
||||
|
||||
# The default calc versions
|
||||
#
|
||||
VERSION= 2.14.0.14
|
||||
VERSION= 2.14.2.2
|
||||
|
||||
# Names of shared libraries with versions
|
||||
#
|
||||
@@ -462,7 +462,7 @@ CO= co
|
||||
CP= cp
|
||||
DIFF= diff
|
||||
FMT= fmt
|
||||
GREP= egrep
|
||||
GREP= grep
|
||||
LN= ln
|
||||
LS= ls
|
||||
MAKE= make
|
||||
@@ -586,16 +586,6 @@ COMMON_LDFLAGS= ${EXTRA_LDFLAGS}
|
||||
#
|
||||
# Specific target overrides or modifications to default values
|
||||
|
||||
##########################################################################
|
||||
# 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 #
|
||||
# #
|
||||
# Email address an "ifeq ($(target),YOUR_TARGET_NAME)" ... "endif" #
|
||||
# set of lines so that we can consider them for the next release. #
|
||||
##########################################################################
|
||||
|
||||
#
|
||||
BLD_TYPE= calc-static-only
|
||||
#
|
||||
@@ -806,11 +796,17 @@ calcliblist: ${CALCLIBLIST}
|
||||
|
||||
depend:
|
||||
${Q} if [ -f ${MAKE_FILE}.bak ]; then \
|
||||
echo "custom/${MAKE_FILE}.bak exists, remove or move it"; \
|
||||
echo "custom/${MAKE_FILE}.bak exists, remove or move it" 1>&2; \
|
||||
exit 1; \
|
||||
else \
|
||||
${TRUE}; \
|
||||
fi
|
||||
${Q} if type -f ${MAKEDEPEND}; then \
|
||||
${TRUE}; \
|
||||
else \
|
||||
echo "make depend failed: cannot find makedepend command: ${MAKEDEPEND}" 1>&2; \
|
||||
exit 1; \
|
||||
fi
|
||||
${Q} echo forming custom/skel
|
||||
${Q} ${RM} -rf skel
|
||||
${Q} ${MKDIR} -p skel
|
||||
@@ -831,7 +827,7 @@ depend:
|
||||
echo '#endif /* '"$$tag"' */' >> "skel/custom/$$i"; \
|
||||
done
|
||||
${Q} (cd ..; ${MAKE} -f ${MAKE_FILE} hsrc)
|
||||
${MAKE} -f ../${MAKE_FILE} h_list 2>/dev/null | \
|
||||
(cd ..; ${MAKE} -f ${MAKE_FILE} h_list 2>/dev/null) | \
|
||||
while read i; do \
|
||||
if [ ! -f "../$$i" ]; then continue; fi; \
|
||||
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
|
||||
@@ -845,13 +841,13 @@ depend:
|
||||
${Q} echo custom/skel formed
|
||||
${Q} echo forming custom dependency list
|
||||
${Q} :> skel/custom/makedep.out
|
||||
${Q} cd skel/custom; ${MAKEDEPEND} \
|
||||
-${Q} cd skel/custom; ${MAKEDEPEND} \
|
||||
-I../../.. -w 1 -f makedep.out -- \
|
||||
${CFLAGS} -- \
|
||||
${C_SRC} 2>/dev/null
|
||||
${Q} ${CP} -f skel/custom/makedep.out skel/custom/makedep.in
|
||||
${Q} ${SED} -e 's|: ../../|: |' -E < skel/custom/makedep.in | \
|
||||
${GREP} -v /usr/include > skel/custom/makedep.out
|
||||
${GREP} -E -v /usr/include > skel/custom/makedep.out
|
||||
-${Q} for i in ${C_SRC} /dev/null; do \
|
||||
if [ X"$$i" != X"/dev/null" ]; then \
|
||||
echo "$$i" | ${SED} 's/^\(.*\)\.c/\1.o: \1.c/'; \
|
||||
@@ -865,7 +861,7 @@ depend:
|
||||
${Q} ${MV} ${MAKE_FILE} ${MAKE_FILE}.bak
|
||||
${Q} ${SED} -n '1,/^# DO NOT DELETE THIS LINE/p' \
|
||||
${MAKE_FILE}.bak > ${MAKE_FILE}
|
||||
${Q} ${GREP} -v '^#' skel/custom/makedep.out >> ${MAKE_FILE}
|
||||
${Q} ${GREP} -E -v '^#' skel/custom/makedep.out >> ${MAKE_FILE}
|
||||
${Q} echo removing skel
|
||||
${Q} ${RM} -rf skel
|
||||
-${Q} if ${CMP} -s ${MAKE_FILE}.bak ${MAKE_FILE}; then \
|
||||
@@ -1166,6 +1162,7 @@ uninstall:
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
c_argv.o: ../alloc.h
|
||||
c_argv.o: ../attribute.h
|
||||
c_argv.o: ../banned.h
|
||||
c_argv.o: ../block.h
|
||||
c_argv.o: ../byteswap.h
|
||||
@@ -1193,6 +1190,7 @@ c_argv.o: ../value.h
|
||||
c_argv.o: ../zmath.h
|
||||
c_argv.o: c_argv.c
|
||||
c_devnull.o: ../alloc.h
|
||||
c_devnull.o: ../attribute.h
|
||||
c_devnull.o: ../banned.h
|
||||
c_devnull.o: ../block.h
|
||||
c_devnull.o: ../byteswap.h
|
||||
@@ -1220,6 +1218,7 @@ c_devnull.o: ../value.h
|
||||
c_devnull.o: ../zmath.h
|
||||
c_devnull.o: c_devnull.c
|
||||
c_help.o: ../alloc.h
|
||||
c_help.o: ../attribute.h
|
||||
c_help.o: ../banned.h
|
||||
c_help.o: ../block.h
|
||||
c_help.o: ../byteswap.h
|
||||
@@ -1247,6 +1246,7 @@ c_help.o: ../value.h
|
||||
c_help.o: ../zmath.h
|
||||
c_help.o: c_help.c
|
||||
c_pmodm127.o: ../alloc.h
|
||||
c_pmodm127.o: ../attribute.h
|
||||
c_pmodm127.o: ../banned.h
|
||||
c_pmodm127.o: ../block.h
|
||||
c_pmodm127.o: ../byteswap.h
|
||||
@@ -1273,6 +1273,7 @@ c_pmodm127.o: ../value.h
|
||||
c_pmodm127.o: ../zmath.h
|
||||
c_pmodm127.o: c_pmodm127.c
|
||||
c_pzasusb8.o: ../alloc.h
|
||||
c_pzasusb8.o: ../attribute.h
|
||||
c_pzasusb8.o: ../banned.h
|
||||
c_pzasusb8.o: ../block.h
|
||||
c_pzasusb8.o: ../byteswap.h
|
||||
@@ -1299,6 +1300,7 @@ c_pzasusb8.o: ../value.h
|
||||
c_pzasusb8.o: ../zmath.h
|
||||
c_pzasusb8.o: c_pzasusb8.c
|
||||
c_register.o: ../alloc.h
|
||||
c_register.o: ../attribute.h
|
||||
c_register.o: ../banned.h
|
||||
c_register.o: ../block.h
|
||||
c_register.o: ../byteswap.h
|
||||
@@ -1326,6 +1328,7 @@ c_register.o: ../value.h
|
||||
c_register.o: ../zmath.h
|
||||
c_register.o: c_register.c
|
||||
c_sysinfo.o: ../alloc.h
|
||||
c_sysinfo.o: ../attribute.h
|
||||
c_sysinfo.o: ../banned.h
|
||||
c_sysinfo.o: ../block.h
|
||||
c_sysinfo.o: ../byteswap.h
|
||||
@@ -1360,6 +1363,7 @@ c_sysinfo.o: ../zrand.h
|
||||
c_sysinfo.o: ../zrandom.h
|
||||
c_sysinfo.o: c_sysinfo.c
|
||||
custtbl.o: ../alloc.h
|
||||
custtbl.o: ../attribute.h
|
||||
custtbl.o: ../banned.h
|
||||
custtbl.o: ../block.h
|
||||
custtbl.o: ../byteswap.h
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* c_help - custom help function
|
||||
*
|
||||
* Copyright (C) 1999-2004,2021 Landon Curt Noll
|
||||
* Copyright (C) 1999-2004,2021,2022 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
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -70,7 +71,7 @@ c_help(char *UNUSED(name), int UNUSED(count), VALUE **vals)
|
||||
*/
|
||||
if (vals[0]->v_type != V_STR) {
|
||||
math_error("custom help arg 1 must be a string");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* c_pmodm127 - calculate q mod 2^(2^127-1)
|
||||
*
|
||||
* Copyright (C) 2004-2007,2021 Landon Curt Noll
|
||||
* Copyright (C) 2004-2007,2021,2022 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
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -88,15 +89,15 @@ c_pmodm127(char *UNUSED(name), int UNUSED(count), VALUE **vals)
|
||||
result.v_type = V_NULL;
|
||||
if (vals[0]->v_type != V_NUM) {
|
||||
math_error("Non-numeric argument for pmodm127");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisfrac(vals[0]->v_num)) {
|
||||
math_error("Non-integer argument for pmodm127");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisneg(vals[0]->v_num) || qiszero(vals[0]->v_num)) {
|
||||
math_error("argument for pmodm127 <= 0");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -250,7 +251,7 @@ zmod5_or_zmod(ZVALUE *zp)
|
||||
subcount++;
|
||||
if (subcount > 2) {
|
||||
math_error("Too many subtractions in zmod5_or_zmod");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
j = modlen;
|
||||
a = zp->v;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* c_pzasusb8 - print numerator as a string of USB8s
|
||||
*
|
||||
* Copyright (C) 1999-2004,2021 Ernest Bowen
|
||||
* Copyright (C) 1999-2004,2021,2022 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
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -67,7 +68,7 @@ c_pzasusb8(char *UNUSED(name), int UNUSED(count), VALUE **vals)
|
||||
result.v_type = V_NULL;
|
||||
if (vals[0]->v_type != V_NUM) {
|
||||
math_error("Non-real argument for pzasusb8");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* c_register - set or print a custom register value
|
||||
*
|
||||
* Copyright (C) 2007,2021 Landon Curt Noll
|
||||
* Copyright (C) 2007,2021,2022 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
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -90,24 +91,24 @@ c_register(char *UNUSED(name), int count, VALUE **vals)
|
||||
result.v_type = V_NULL;
|
||||
if (vals[0]->v_type != V_NUM) {
|
||||
math_error("Non-numeric register number");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisfrac(vals[0]->v_num)) {
|
||||
math_error("Non-integer register number");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisneg(vals[0]->v_num)) {
|
||||
math_error("register number < 0");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (! qistiny(vals[0]->v_num)) {
|
||||
math_error("register is huge");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
reg = qtoi(vals[0]->v_num);
|
||||
if (reg > CUSTOM_REG_MAX) {
|
||||
math_error("register is larger than CUSTOM_REG_MAX");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* c_sysinfo - names and values of selected #defines
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 Landon Curt Noll
|
||||
* Copyright (C) 1999-2007,2021,2022 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
|
||||
@@ -57,6 +57,7 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -301,7 +302,7 @@ c_sysinfo(char *UNUSED(name), int count, VALUE **vals)
|
||||
qisfrac(vals[0]->v_num) ||
|
||||
zge31b(vals[0]->v_num->num)) {
|
||||
math_error("sysinfo: arg must be string, 0, 1 or 2");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -319,7 +320,7 @@ c_sysinfo(char *UNUSED(name), int count, VALUE **vals)
|
||||
break;
|
||||
default:
|
||||
math_error("sysinfo: arg must be string, 0, 1 or 2");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -368,7 +369,7 @@ c_sysinfo(char *UNUSED(name), int count, VALUE **vals)
|
||||
*/
|
||||
} else {
|
||||
math_error("sysinfo: arg must be string, 0, 1 or 2");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
|
7
decl.h
7
decl.h
@@ -94,12 +94,5 @@
|
||||
|
||||
#endif
|
||||
|
||||
/* Perform printf-style argument type checking for known compilers */
|
||||
#ifdef __GNUC__
|
||||
# define PRINTF_FORMAT(fmt_idx, arg_idx) __attribute__ \
|
||||
((format (printf, fmt_idx, arg_idx)))
|
||||
#else
|
||||
# define PRINTF_FORMAT(fmt_idx, arg_idx)
|
||||
#endif
|
||||
|
||||
#endif /* !INCLUDE_DECL_H */
|
||||
|
43
file.c
43
file.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* file - file I/O routines callable by users
|
||||
*
|
||||
* Copyright (C) 1999-2007,2018,2021 David I. Bell and Landon Curt Noll
|
||||
* Copyright (C) 1999-2007,2018,2021,2022 David I. Bell and Landon Curt Noll
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
*
|
||||
@@ -39,7 +39,7 @@
|
||||
#include "calc.h"
|
||||
#include "alloc.h"
|
||||
#include "longbits.h"
|
||||
#include "have_fpos.h"
|
||||
#include "have_fgetsetpos.h"
|
||||
#include "have_fpos_pos.h"
|
||||
#include "fposval.h"
|
||||
#include "file.h"
|
||||
@@ -51,6 +51,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -179,7 +180,7 @@ file_init(void)
|
||||
tname = (char *)malloc(snprintf_len+1);
|
||||
if (tname == NULL) {
|
||||
math_error("Out of memory for init_file");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
snprintf(tname, snprintf_len, "descriptor[%d]", i);
|
||||
tname[snprintf_len] = '\0'; /* paranoia */
|
||||
@@ -231,7 +232,7 @@ init_fileio(FILEIO *fiop, char *name, char *mode,
|
||||
fiop->name = (char *)malloc(namelen + 1);
|
||||
if (fiop->name == NULL) {
|
||||
math_error("No memory for filename");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,7 +368,7 @@ openid(char *name, char *mode)
|
||||
}
|
||||
if (fstat(fileno(fp), &sbuf) < 0) {
|
||||
math_error("bad fstat");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/* get a new FILEID */
|
||||
@@ -436,12 +437,12 @@ openpathid(char *name, char *mode, char *pathlist)
|
||||
free(openpath);
|
||||
}
|
||||
math_error("bad fstat");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (openpath == NULL) {
|
||||
fclose(fp);
|
||||
math_error("bad openpath");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/* get a new FILEID */
|
||||
@@ -482,7 +483,7 @@ reopenid(FILEID id, char *mode, char *name)
|
||||
if ((id == FILEID_STDIN) || (id == FILEID_STDOUT) ||
|
||||
(id == FILEID_STDERR)) {
|
||||
math_error("Cannot freopen stdin, stdout, or stderr");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/* reopen the file */
|
||||
@@ -507,7 +508,7 @@ reopenid(FILEID id, char *mode, char *name)
|
||||
}
|
||||
if (i >= MAXFILES) {
|
||||
math_error("This should not happen in reopenid");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
fp = f_open(name, mode);
|
||||
if (fp == NULL) {
|
||||
@@ -532,7 +533,7 @@ reopenid(FILEID id, char *mode, char *name)
|
||||
}
|
||||
if (fstat(fileno(fp), &sbuf) < 0) {
|
||||
math_error("bad fstat");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/* initialize FILEIO structure */
|
||||
@@ -632,7 +633,7 @@ closeid(FILEID id)
|
||||
if ((id == FILEID_STDIN) || (id == FILEID_STDOUT) ||
|
||||
(id == FILEID_STDERR)) {
|
||||
math_error("Cannot close stdin, stdout, or stderr");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/* get file structure */
|
||||
@@ -832,7 +833,7 @@ readid(FILEID id, int flags, STRING **retstr)
|
||||
str = (char *)malloc(n + 1);
|
||||
if (str == NULL) {
|
||||
math_error("Out of memory for readid");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (n > 0)
|
||||
memcpy(&str[totlen], buf, n);
|
||||
@@ -1458,7 +1459,7 @@ z2filepos(ZVALUE zpos)
|
||||
if (zpos.len >= FILEPOS_BITS/BASEB) {
|
||||
/* copy the lower FILEPOS_BITS of the ZVALUE */
|
||||
memset(&tmp, 0, sizeof(tmp)); /* FILEPOS could be non-scalar */
|
||||
memcpy(&tmp, zpos.v, MIN(sizeof(tmp), FILEPOS_LEN);
|
||||
memcpy(&tmp, zpos.v, MIN(sizeof(tmp), FILEPOS_LEN));
|
||||
} else {
|
||||
/* copy what bits we can into the temp value */
|
||||
memset(&tmp, 0, sizeof(tmp)); /* FILEPOS could be non-scalar */
|
||||
@@ -1536,7 +1537,7 @@ getloc(FILEID id, ZVALUE *res)
|
||||
fp = fiop->fp;
|
||||
if (fp == NULL) {
|
||||
math_error("Bogus internal file pointer!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1695,7 +1696,7 @@ setloc(FILEID id, ZVALUE zpos)
|
||||
if ((id == FILEID_STDIN) || (id == FILEID_STDOUT) ||
|
||||
(id == FILEID_STDERR)) {
|
||||
math_error("Cannot fseek stdin, stdout, or stderr");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1709,7 +1710,7 @@ setloc(FILEID id, ZVALUE zpos)
|
||||
fp = fiop->fp;
|
||||
if (fp == NULL) {
|
||||
math_error("Bogus internal file pointer!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
fiop->action = 0;
|
||||
@@ -1960,7 +1961,7 @@ filesize(FILEIO *fiop)
|
||||
/* return length */
|
||||
if (fstat(fileno(fiop->fp), &sbuf) < 0) {
|
||||
math_error("bad fstat");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return sbuf.st_size;
|
||||
}
|
||||
@@ -2021,7 +2022,7 @@ showfiles(void)
|
||||
math_chr('\n');
|
||||
continue;
|
||||
}
|
||||
printf(" size = %lld\n", (long long int)sizes[i]);
|
||||
printf(" size = %ld\n", (long int)sizes[i]);
|
||||
for (j = i + 1; j < idnum; j++) {
|
||||
if (listed[j] || sizes[j] == -1)
|
||||
continue;
|
||||
@@ -2099,7 +2100,7 @@ getscanfield(FILE *fp, BOOL skip, unsigned int width, int scannum,
|
||||
str = (char *) malloc(len + 1);
|
||||
if (str == NULL) {
|
||||
math_error("Out of memory for scanning");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (len)
|
||||
memcpy(&str[totlen], buf, len);
|
||||
@@ -2177,7 +2178,7 @@ getscanwhite(FILE *fp, BOOL skip, unsigned int width, int scannum,
|
||||
str = (char *) malloc(len + 1);
|
||||
if (str == NULL) {
|
||||
math_error("Out of memory for scanning");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (len)
|
||||
memcpy(&str[totlen], buf, len);
|
||||
@@ -2721,7 +2722,7 @@ fsearch(FILEID id, char *str, ZVALUE start, ZVALUE end, ZVALUE *res)
|
||||
while (k < tmp.len && tmp.v[k] == 0);
|
||||
if (k == tmp.len) {
|
||||
math_error("This should not happen");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
tmp.v[k]--;
|
||||
if (tmp.v[tmp.len - 1] == 0)
|
||||
|
6
file.h
6
file.h
@@ -32,9 +32,9 @@
|
||||
|
||||
|
||||
#if defined(CALC_SRC) /* if we are building from the calc source tree */
|
||||
# include "have_fpos.h"
|
||||
# include "have_fgetsetpos.h"
|
||||
#else
|
||||
# include <calc/have_fpos.h>
|
||||
# include <calc/have_fgetsetpos.h>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ typedef struct {
|
||||
* Some obscure systems without fgetpos/fsetpos may not have a simple
|
||||
* scalar type. In these cases the f_tell macro below will fail.
|
||||
*/
|
||||
#if defined(HAVE_FPOS)
|
||||
#if defined(HAVE_FGETSETPOS)
|
||||
|
||||
#define f_seek_set(stream, loc) fsetpos((FILE*)(stream), (FILEPOS*)(loc))
|
||||
#define f_tell(stream, loc) fgetpos((FILE*)(stream), (FILEPOS*)(loc))
|
||||
|
39
fposval.c
39
fposval.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* fposval - Determine information about the file position type
|
||||
*
|
||||
* Copyright (C) 1999,2021 Landon Curt Noll
|
||||
* Copyright (C) 1999,2021,2023 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
|
||||
@@ -59,12 +59,20 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "have_fpos.h"
|
||||
#include "have_string.h"
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
#include "decl.h"
|
||||
#include "have_fgetsetpos.h"
|
||||
#include "endian_calc.h"
|
||||
#include "have_offscl.h"
|
||||
#include "have_posscl.h"
|
||||
#include "have_fpos_pos.h"
|
||||
#include "alloc.h"
|
||||
#include "have_unused.h"
|
||||
#include "have_memmv.h"
|
||||
#include "zmath.h"
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
@@ -73,7 +81,7 @@
|
||||
char *program; /* our name */
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int UNUSED(argc), char **argv)
|
||||
{
|
||||
int stsizelen; /* bit length of st_size in buf */
|
||||
int fileposlen; /* bit length of FILEPOS */
|
||||
@@ -89,7 +97,7 @@ main(int argc, char **argv)
|
||||
/*
|
||||
* print the file position information
|
||||
*/
|
||||
#if defined(HAVE_FPOS_POS)
|
||||
#if defined(HAVE_FPOS_POS) && defined(FPOS_POS_BITS)
|
||||
fileposlen = FPOS_POS_BITS;
|
||||
#else /* ! HAVE_FPOS_POS */
|
||||
# if defined(FPOS_BITS)
|
||||
@@ -107,13 +115,17 @@ main(int argc, char **argv)
|
||||
* Big Endian
|
||||
*/
|
||||
if (fileposlen == 64) {
|
||||
printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t\t%s\n",
|
||||
"SWAP_HALF_IN_B64(dest, src)");
|
||||
printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n"
|
||||
"\tSWAP_HALF_IN_B64(dest, src)\n");
|
||||
} else if (fileposlen == 32) {
|
||||
printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t\t%s\n",
|
||||
"SWAP_HALF_IN_B32(dest, src)");
|
||||
printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n"
|
||||
"\tSWAP_HALF_IN_B32(dest, src)\n");
|
||||
} else if (fileposlen%BASEB == 0) {
|
||||
printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n"
|
||||
"\tswap_HALFs(dest, src, %d)\n",
|
||||
fileposlen/BASEB);
|
||||
} else {
|
||||
fprintf(stderr, "%s: unexpected FILEPOS bit size: %d\n",
|
||||
fprintf(stderr, "%s: unexpected BIG_ENDIAN FILEPOS bit size: %d\n",
|
||||
program, fileposlen);
|
||||
exit(1);
|
||||
}
|
||||
@@ -122,16 +134,15 @@ main(int argc, char **argv)
|
||||
* Little Endian
|
||||
*/
|
||||
#if defined(HAVE_FILEPOS_SCALAR)
|
||||
printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t\t%s\n",
|
||||
"(*(dest) = *(src))");
|
||||
printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n"
|
||||
"\t(*(dest) = *(src))\n");
|
||||
#else /* HAVE_FILEPOS_SCALAR */
|
||||
/*
|
||||
* Normally a "(*(dest) = *(src))" would do, but on some
|
||||
* systems a FILEPOS is not a scalar hence we must memcpy.
|
||||
*/
|
||||
printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t%s\n",
|
||||
"\\\n\tmemcpy((void *)(dest), (void *)(src), "
|
||||
"sizeof(FPOS_POS_LEN))");
|
||||
printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n"
|
||||
"\tmemcpy((void *)(dest), (void *)(src), FILEPOS_LEN)\n");
|
||||
#endif /* HAVE_FILEPOS_SCALAR */
|
||||
#endif /* CALC_BYTE_ORDER == BIG_ENDIAN */
|
||||
putchar('\n');
|
||||
|
13
hash.c
13
hash.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* hash - one-way hash routines
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 Landon Curt Noll
|
||||
* Copyright (C) 1999-2007,2021,2022 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
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "hash.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -94,7 +95,7 @@ hash_init(int type, HASH *state)
|
||||
state = (HASH *)malloc(sizeof(HASH));
|
||||
if (state == NULL) {
|
||||
math_error("hash_init: cannot malloc HASH");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +120,7 @@ hash_init(int type, HASH *state)
|
||||
if (state->chunksize > MAX_CHUNKSIZE) {
|
||||
math_error(
|
||||
"internal error: MAX_CHUNKSIZE is too small");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return state;
|
||||
}
|
||||
@@ -174,7 +175,7 @@ hash_copy(HASH *state)
|
||||
hnew = (HASH *)malloc(sizeof(HASH));
|
||||
if (hnew == NULL) {
|
||||
math_error("hash_init: cannot malloc HASH");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -955,6 +956,7 @@ hash_value(int type, void *v, HASH *state)
|
||||
state = hash_len(type, value->v_config->pow2, state);
|
||||
state = hash_len(type, value->v_config->redc2, state);
|
||||
state = hash_bool(type, value->v_config->tilde_ok, state);
|
||||
state = hash_bool(type, value->v_config->tilde_space, state);
|
||||
state = hash_bool(type, value->v_config->tab_ok, state);
|
||||
state = hash_long(type, (long)value->v_config->quomod, state);
|
||||
state = hash_long(type, (long)value->v_config->quo, state);
|
||||
@@ -1000,6 +1002,7 @@ hash_value(int type, void *v, HASH *state)
|
||||
state = hash_int(type, value->v_config->baseb, state);
|
||||
state = hash_bool(type, value->v_config->redecl_warn, state);
|
||||
state = hash_bool(type, value->v_config->dupvar_warn, state);
|
||||
state = hash_bool(type, value->v_config->fraction_space, state);
|
||||
break;
|
||||
|
||||
case V_HASH:
|
||||
@@ -1048,7 +1051,7 @@ hash_value(int type, void *v, HASH *state)
|
||||
|
||||
default:
|
||||
math_error("hashing an unknown value");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* have_fpos - Determine if have fgetpos and fsetpos functions
|
||||
*
|
||||
* Copyright (C) 1999,2021 Landon Curt Noll
|
||||
* Copyright (C) 1999,2021,2022 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
|
||||
@@ -25,10 +25,10 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* If the symbol HAVE_NO_FPOS is defined, we will output nothing.
|
||||
* If the symbol HAVE_NO_FGETSETPOS is defined, we will output nothing.
|
||||
* If we are able to compile this program, then we must have the
|
||||
* fgetpos and fsetpos functions and we will output the
|
||||
* appropriate have_fpos.h file body.
|
||||
* appropriate have_fgetsetpos.h file body.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -40,7 +40,7 @@
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
#if !defined(HAVE_NO_FPOS)
|
||||
#if !defined(HAVE_NO_FGETSETPOS)
|
||||
fpos_t pos; /* file position */
|
||||
|
||||
/* get the current position */
|
||||
@@ -49,9 +49,9 @@ main(void)
|
||||
/* set the current position */
|
||||
(void) fsetpos(stdin, &pos);
|
||||
|
||||
/* print a have_fpos.h body that says we have the functions */
|
||||
printf("#undef HAVE_FPOS\n");
|
||||
printf("#define HAVE_FPOS 1 /* yes */\n\n");
|
||||
/* print a have_fgetsetpos.h body that says we have the functions */
|
||||
printf("#undef HAVE_FGETSETPOS\n");
|
||||
printf("#define HAVE_FGETSETPOS 1 /* yes */\n\n");
|
||||
printf("typedef fpos_t FILEPOS;\n");
|
||||
#endif
|
||||
/* exit(0); */
|
@@ -24,16 +24,14 @@
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
/*
|
||||
* If the symbol HAVE_NO_FPOS is defined, we will output nothing.
|
||||
* If the HAVE_FILEPOS_SCALAR is defined, we will output nothing.
|
||||
* If we are able to compile this program, then we must have the
|
||||
* __pos element in a non-scalar FILEPOS.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "have_fpos.h"
|
||||
#include "have_fgetsetpos.h"
|
||||
#include "have_posscl.h"
|
||||
#include "have_string.h"
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
@@ -42,29 +40,43 @@
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
#if !defined(HAVE_NO_FPOS) && !defined(HAVE_FILEPOS_SCALAR)
|
||||
fpos_t pos; /* file position */
|
||||
#if defined(HAVE_FILEPOS_SCALAR)
|
||||
|
||||
/* print a __pos element in fpos_t */
|
||||
printf("#undef HAVE_FPOS_POS\n");
|
||||
printf("#define HAVE_FPOS_POS 1 /* yes */\n\n");
|
||||
|
||||
/* determine __pos element size */
|
||||
printf("#undef FPOS_POS_BITS\n");
|
||||
printf("#undef FPOS_POS_LEN\n");
|
||||
# if defined(FPOS_POS_BITS)
|
||||
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 %lu\n", sizeof(pos.__pos)*8);
|
||||
printf("#define FPOS_POS_LEN %lu\n", sizeof(pos.__pos));
|
||||
# endif
|
||||
|
||||
#else
|
||||
/* we have no __pos element */
|
||||
printf("/* HAVE_FILEPOS_SCALAR is defined, we assume FILEPOS is scalar */\n");
|
||||
printf("/* we assume we have no __pos in FILEPOS */\n");
|
||||
printf("#undef HAVE_FPOS_POS\t/* no */\n");
|
||||
printf("#undef FPOS_POS_BITS\n");
|
||||
printf("#undef FPOS_POS_LEN\n");
|
||||
|
||||
#else
|
||||
|
||||
printf("/* HAVE_FILEPOS_SCALAR is undefined, we assume FILEPOS is not scalar */\n");
|
||||
# if defined(HAVE_NO_FPOS_POS)
|
||||
printf("/* HAVE_NO_FPOS_POS defiled, we assume we have no __pos in FILEPOS */\n");
|
||||
printf("#undef HAVE_FPOS_POS\t/* no */\n");
|
||||
printf("#undef FPOS_POS_BITS\n");
|
||||
printf("#undef FPOS_POS_LEN\n");
|
||||
|
||||
# elif defined(FPOS_POS_BITS)
|
||||
printf("/* FPOS_POS_BITS defiled, assume we have __pos in FILEPOS */\n");
|
||||
printf("#undef HAVE_FPOS_POS\n");
|
||||
printf("#define HAVE_FPOS_POS 1 /* yes */\n");
|
||||
printf("#undef FPOS_POS_BITS\n");
|
||||
printf("#define FPOS_POS_BITS %d\n", FPOS_POS_BITS);
|
||||
printf("#undef FPOS_POS_LEN\n");
|
||||
printf("#define FPOS_POS_LEN %d\n", int(FPOS_POS_BITS/8));
|
||||
# else
|
||||
fpos_t pos; /* file position */
|
||||
|
||||
memset(&pos, 0, sizeof(pos)); /* zeroize pos to "set it" */
|
||||
printf("/* we successfully compiled with a fpos_t type wit an __pos element */\n");
|
||||
printf("#undef HAVE_FPOS_POS\n");
|
||||
printf("#define HAVE_FPOS_POS 1 /* yes */\n");
|
||||
printf("#undef FPOS_POS_BITS\n");
|
||||
printf("#define FPOS_POS_BITS %lu\n", sizeof(pos.__pos)*8);
|
||||
printf("#undef FPOS_POS_LEN\n");
|
||||
printf("#define FPOS_POS_LEN %lu\n", sizeof(pos.__pos));
|
||||
# endif
|
||||
#endif
|
||||
/* exit(0); */
|
||||
return 0;
|
||||
|
@@ -49,7 +49,7 @@
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
#if defined(HAVE_NO_GETTIME)
|
||||
#if defined(HAVE_NO_GETTIME) || defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
printf("#undef HAVE_GETTIME /* no */\n");
|
||||
|
||||
|
@@ -48,7 +48,7 @@
|
||||
#if defined(HAVE_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "have_fpos.h"
|
||||
#include "have_fgetsetpos.h"
|
||||
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
82
have_statfs.c
Normal file
82
have_statfs.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* have_statfs - Determine if we have statfs()
|
||||
*
|
||||
* Copyright (C) 2023 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: 2023/03/06 00:51:53
|
||||
* File existed as early as: 2023
|
||||
*
|
||||
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage:
|
||||
* have_statfs
|
||||
*
|
||||
* Not all systems have the statfs() function, so this may not
|
||||
* compile on your system.
|
||||
*
|
||||
* This prog outputs several defines:
|
||||
*
|
||||
* HAVE_STATFS
|
||||
* defined ==> use statfs()
|
||||
* undefined ==> do not call or cannot call statfs()
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "have_sys_vfs.h"
|
||||
#if defined(HAVE_SYS_VFS_H)
|
||||
# include <sys/vfs.h>
|
||||
#endif /* HAVE_SYS_VFS_H */
|
||||
|
||||
#include "have_sys_param.h"
|
||||
#if defined(HAVE_SYS_PARAM_H)
|
||||
# include <sys/param.h>
|
||||
#endif /* HAVE_SYS_PARAM_H */
|
||||
|
||||
#include "have_sys_mount.h"
|
||||
#if defined(HAVE_SYS_MOUNT_H)
|
||||
# include <sys/mount.h>
|
||||
#endif /* HAVE_SYS_MOUNT_H */
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
#if defined(HAVE_NO_STATFS)
|
||||
|
||||
printf("#undef HAVE_STATFS /* no */\n");
|
||||
|
||||
#else /* HAVE_NO_STATFS */
|
||||
|
||||
struct statfs statfs_dot; /* usage stat of "." */
|
||||
|
||||
(void) statfs(".", &statfs_dot);
|
||||
|
||||
printf("#define HAVE_STATFS /* yes */\n");
|
||||
|
||||
#endif /* HAVE_NO_STATFS */
|
||||
|
||||
/* exit(0); */
|
||||
return 0;
|
||||
}
|
@@ -65,6 +65,8 @@ main(void)
|
||||
extern uid_t geteuid();
|
||||
|
||||
curds = geteuid();
|
||||
/* force curds to be used, but do not print much info about our UID */
|
||||
printf("/* geteuid() mod 2 == %ld */\n", ((long)curds) & 0x1);
|
||||
|
||||
printf("#define HAVE_UID_T /* yes */\n");
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#!/bin/make
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# help - makefile for calc help files
|
||||
#
|
||||
# Copyright (C) 1999-2006,2017,2021 Landon Curt Noll
|
||||
# Copyright (C) 1999-2006,2017,2021-2023 Landon Curt Noll
|
||||
#
|
||||
# SRC: help/Makefile
|
||||
#
|
||||
@@ -44,20 +44,21 @@
|
||||
# If your system has a up to date, bash shell, then
|
||||
# you may wish to use:
|
||||
#
|
||||
# SHELL= /bin/bash
|
||||
# SHELL= bash
|
||||
#
|
||||
# On some systems such as macOS, the bash shell is very
|
||||
# far behind to the point where is cannot be depended on.
|
||||
# On such systems, the sh may be a much better alternative
|
||||
# shell for this Makefile to use:
|
||||
#
|
||||
# SHELL= /bin/sh
|
||||
# SHELL= sh
|
||||
#
|
||||
SHELL= /bin/bash
|
||||
#SHELL= /bin/sh
|
||||
SHELL= bash
|
||||
#SHELL= sh
|
||||
#if 0 /* start of skip for non-Gnu makefiles */
|
||||
#
|
||||
ifeq ($(target),Darwin)
|
||||
SHELL:= /bin/zsh
|
||||
SHELL:= /bin/sh
|
||||
endif
|
||||
#endif /* end of skip for non-Gnu makefiles */
|
||||
|
||||
@@ -246,7 +247,7 @@ CHMOD= chmod
|
||||
CMP= cmp
|
||||
CP= cp
|
||||
FMT= fmt
|
||||
GREP= egrep
|
||||
GREP= grep
|
||||
ICFLAGS=
|
||||
ILDFLAGS=
|
||||
LCC= cc
|
||||
@@ -408,6 +409,10 @@ DISTLIST= ${STD_HELP_FILES} ${DETAIL_HELP} ${MAKE_FILE} \
|
||||
# These files are used to make (but not built) a calc .a link library
|
||||
#
|
||||
CALCLIBLIST=
|
||||
#
|
||||
# rules that are not also names of files
|
||||
#
|
||||
PHONY= all clobber distlist install
|
||||
|
||||
all: ${FULL_HELP_FILES} full ${DETAIL_HELP} ${DETAIL_CLONE} \
|
||||
${SINGULAR_FILES} .all
|
||||
@@ -421,6 +426,8 @@ all: ${FULL_HELP_FILES} full ${DETAIL_HELP} ${DETAIL_CLONE} \
|
||||
${RM} -f .all
|
||||
${TOUCH} .all
|
||||
|
||||
.PHONY: ${PHONY}
|
||||
|
||||
bindings: ../cal/bindings
|
||||
${RM} -f $@
|
||||
${CP} ../cal/bindings $@
|
||||
@@ -710,7 +717,7 @@ builtin: builtin.top builtin.end ../func.c funclist.sed
|
||||
-I.. funclist.c -c ${S}
|
||||
${Q} ${LCC} ${ILDFLAGS} funclist.o -o funclist${EXT} ${S}
|
||||
${Q} ${RM} -f builtin
|
||||
${Q} ${GREP} -v '^#' builtin.top > builtin
|
||||
${Q} ${GREP} -E -v '^#' builtin.top > builtin
|
||||
${Q} ./funclist${EXT} | \
|
||||
${SED} -e 's/^/ /' -e 's/[ ][ ]*$$//' >> builtin
|
||||
${Q} ${CAT} builtin.end >> builtin
|
||||
@@ -750,14 +757,6 @@ calcliblist:
|
||||
fi; \
|
||||
done
|
||||
|
||||
# The BSDI cdrom makefile expects all help files to be pre-built. This rule
|
||||
# creates these files so that the release can be shipped off to BSDI. You can
|
||||
# ignore this rule.
|
||||
#
|
||||
bsdi: all
|
||||
${RM} -f obj
|
||||
${CP} obj.file obj
|
||||
|
||||
# These next rule help form the ${DETAIL_HELP} makefile variables above.
|
||||
#
|
||||
# NOTE: The ${DETAIL_HELP} list does not include special help files.
|
||||
|
16
help/command
16
help/command
@@ -215,22 +215,22 @@ Command sequence
|
||||
blocks unfreed named blocks
|
||||
builtin built in functions
|
||||
config config parameters and values
|
||||
constants cache of numeric constants
|
||||
constants cache of numeric constants
|
||||
custom custom functions if calc -C was used
|
||||
errors new error-values created
|
||||
files open files, file position and sizes
|
||||
function user-defined functions
|
||||
globaltypes global variables
|
||||
function user-defined functions
|
||||
globaltypes global variables
|
||||
objfunctions possible object functions
|
||||
objtypes defined objects
|
||||
opcodes func internal opcodes for function `func'
|
||||
objtypes defined objects
|
||||
opcodes internal opcodes for function `func'
|
||||
sizes size in octets of calc value types
|
||||
realglobals numeric global variables
|
||||
realglobals numeric global variables
|
||||
statics un-scoped static variables
|
||||
numbers calc number cache
|
||||
redcdata REDC data defined
|
||||
redcdata REDC data defined
|
||||
strings calc string cache
|
||||
literals calc literal cache
|
||||
literals calc literal cache
|
||||
|
||||
Only the first 4 characters of item are examined, so:
|
||||
|
||||
|
48
help/config
48
help/config
@@ -34,6 +34,7 @@ DESCRIPTION
|
||||
"pow2" sets size for alternate powering.
|
||||
"redc2" sets size for alternate REDC.
|
||||
"tilde" enable/disable printing of the roundoff '~'
|
||||
"tilde_space" enable/disable printing space after roundoff tilde '~ '
|
||||
"tab" enable/disable printing of leading tabs
|
||||
"quomod" sets rounding mode for quomod
|
||||
"quo" sets rounding mode for //, default for quo
|
||||
@@ -134,6 +135,7 @@ DESCRIPTION
|
||||
config("display", 50); 50 digits of output
|
||||
epsilon(epsilon() / 8); 3 bits more accuracy
|
||||
config("tilde", 0) disable roundoff tilde printing
|
||||
config("tilde_space", 1) enable printing space after roundoff tilde
|
||||
config("tab", "off") disable leading tab printing
|
||||
|
||||
=-=
|
||||
@@ -264,7 +266,7 @@ DESCRIPTION
|
||||
config("mul2", int)
|
||||
config("sq2", int)
|
||||
|
||||
Mul2 and sq2 specify the sizes of numbers at which calc switches
|
||||
Both "mul2" and "sq2" specify the sizes of numbers at which calc switches
|
||||
from its first to its second algorithm for multiplying and squaring.
|
||||
The first algorithm is the usual method of cross multiplying, which
|
||||
runs in a time of O(N^2). The second method is a recursive and
|
||||
@@ -305,7 +307,7 @@ DESCRIPTION
|
||||
|
||||
config("pow2", int)
|
||||
|
||||
Pow2 specifies the sizes of numbers at which calc switches from
|
||||
The "pow2" specifies the sizes of numbers at which calc switches from
|
||||
its first to its second algorithm for calculating powers modulo
|
||||
another number. The first algorithm for calculating modular powers
|
||||
is by repeated squaring and multiplying and dividing by the modulus.
|
||||
@@ -334,7 +336,7 @@ DESCRIPTION
|
||||
|
||||
config("redc2", int)
|
||||
|
||||
Redc2 specifies the sizes of numbers at which calc switches from
|
||||
The "redc2" specifies the sizes of numbers at which calc switches from
|
||||
its first to its second algorithm when using the REDC algorithm.
|
||||
The first algorithm performs a multiply and a modular reduction
|
||||
together in one loop which runs in O(N^2). The second algorithm
|
||||
@@ -363,16 +365,48 @@ DESCRIPTION
|
||||
|
||||
config("tilde", boolean)
|
||||
|
||||
Config("tilde") controls whether or not a leading tilde ('~') is
|
||||
The "tilde" controls whether or not a leading tilde ('~') is
|
||||
printed to indicate that a number has not been printed exactly
|
||||
because the number of decimal digits required would exceed the
|
||||
specified maximum number. The initial "tilde" value is 1.
|
||||
specified maximum number.
|
||||
|
||||
If config("tilde") is false, then config("tilde_space") has no effect.
|
||||
|
||||
The initial "tilde" value is 1 (on).
|
||||
|
||||
=-=
|
||||
|
||||
config("tilde_space", boolean)
|
||||
|
||||
The "tilde_space" controls whether or not a space (' ') is
|
||||
printed after leading tilde ('~'). See config("tilde") above.
|
||||
If config("tilde") is false, then config("tilde_space") has no effect.
|
||||
|
||||
NOTE: Use of config("tilde_space", 1) can break printing and scanning
|
||||
of complex values via "%c".
|
||||
|
||||
The initial "tilde_space" value is 0 (off)
|
||||
|
||||
=-=
|
||||
|
||||
config("fraction_space", boolean)
|
||||
|
||||
The "fraction_space" controls whether or not a space (' ') is
|
||||
printed both before and after '/' when printing a fraction.
|
||||
|
||||
NOTE: Use of config("fraction_space", 1) can break printing and scanning
|
||||
of fractional values via "%r".
|
||||
|
||||
NOTE: Use of config("fraction_space", 1) can break printing and scanning
|
||||
of complex values via "%c".
|
||||
|
||||
The initial "fraction_space" value is 0 (off).
|
||||
|
||||
=-=
|
||||
|
||||
config("tab", boolean)
|
||||
|
||||
Config ("tab") controls the printing of a tab before results
|
||||
config("tab") controls the printing of a tab before results
|
||||
automatically displayed when working interactively. It does not
|
||||
affect the printing by the functions print, printf, etc. The initial
|
||||
"tab" value is 1.
|
||||
@@ -908,6 +942,7 @@ EXAMPLE
|
||||
pow2 40
|
||||
redc2 50
|
||||
tilde 1
|
||||
tilde_space 0
|
||||
tab 1
|
||||
quomod 0
|
||||
quo 2
|
||||
@@ -944,6 +979,7 @@ EXAMPLE
|
||||
redecl_warn 1
|
||||
dupvar_warn 1
|
||||
hz 100
|
||||
fraction_space 0
|
||||
|
||||
; display()
|
||||
20
|
||||
|
31
help/credit
31
help/credit
@@ -26,13 +26,22 @@ Credits
|
||||
|
||||
Most of this source and binary has one of the following copyrights:
|
||||
|
||||
Copyright (C) year David I. Bell
|
||||
Copyright (C) year David I. Bell and Landon Curt Noll
|
||||
Copyright (C) year David I. Bell and Ernest Bowen
|
||||
Copyright (C) year David I. Bell, Landon Curt Noll and Ernest Bowen
|
||||
Copyright (C) year Landon Curt Noll
|
||||
Copyright (C) year Ernest Bowen and Landon Curt Noll
|
||||
Copyright (C) year Ernest Bowen
|
||||
Copyright (C) year David I. Bell
|
||||
Copyright (C) year David I. Bell and Landon Curt Noll
|
||||
Copyright (C) year David I. Bell and Ernest Bowen
|
||||
Copyright (C) year David I. Bell, Landon Curt Noll and Ernest Bowen
|
||||
Copyright (C) year Landon Curt Noll
|
||||
Copyright (C) year Ernest Bowen and Landon Curt Noll
|
||||
Copyright (C) year Ernest Bowen
|
||||
Copyright (C) year Petteri Kettunen and Landon Curt Noll
|
||||
Copyright (C) year Christoph Zurnieden
|
||||
Copyright (C) year Landon Curt Noll and Thomas Jones-Low
|
||||
Copyright (C) year Klaus Alexander Seistrup and Landon Curt Noll
|
||||
|
||||
A few files in calc are covered under "The Unlicense". For more
|
||||
information on this license, see:
|
||||
|
||||
https://unlicense.org
|
||||
|
||||
|
||||
Copying / Calc GNU Lesser General Public License
|
||||
@@ -61,11 +70,11 @@ Copying / Calc GNU Lesser General Public License
|
||||
|
||||
See also:
|
||||
|
||||
help copyright
|
||||
help copying
|
||||
help copying-lgpl
|
||||
help copyright
|
||||
help copying
|
||||
help copying-lgpl
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999,2023 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
|
||||
|
@@ -2,11 +2,11 @@ s/VALUE/int/
|
||||
s/NUMBER[ ]*\*/int /
|
||||
s/NUMBER/int/
|
||||
s/STRINGHEAD/int/
|
||||
s/\(".*",.*,.*\),.*,.*,.*,.*,/\1, 0, 0, 0, 0,/
|
||||
s/\(".*",.*,.*\),.*,.*,.*,.*,/\1, 0, 0, {.null = NULL}, {.null = NULL},/
|
||||
s/[ ][ ]*$//
|
||||
p
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999,2023 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
|
||||
|
@@ -101,11 +101,11 @@ Low priority items:
|
||||
|
||||
Calc bug reports and calc bug fixes should be sent to:
|
||||
|
||||
calc-bug-report at asthe dot com
|
||||
NOTE: calc-bug-report Email address no longer in use
|
||||
|
||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
||||
|
||||
This replaces the old calc-bugs at asthe dot com address.
|
||||
This replaces the old calc-bugs Email address.
|
||||
|
||||
To be sure we see your Email reporting a calc bug, please use the
|
||||
following phase in your Email Subject line:
|
||||
|
@@ -556,8 +556,14 @@ Unexpected
|
||||
; print sin(d2r(30))
|
||||
0.5
|
||||
|
||||
* operator has has a higher precedence than <<
|
||||
==============================================
|
||||
|
||||
## Copyright (C) 1999-2007,2014,2017,2021 Landon Curt Noll
|
||||
The * operator has has a higher precedence than <<, which differs from the C language.
|
||||
So 3 << 2*5 evaluates to 3072 in C, whereas 3 << 2*5 evaluates to 60 in calc.
|
||||
|
||||
|
||||
## Copyright (C) 1999-2007,2014,2017,2021,2023 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
|
||||
|
@@ -187,11 +187,11 @@ Please read CONTRIB-CODE or run the following calc command:
|
||||
|
||||
Calc bug reports and calc bug fixes should be sent to:
|
||||
|
||||
calc-bug-report at asthe dot com
|
||||
NOTE: calc-bug-report Email address no longer in use
|
||||
|
||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
||||
|
||||
This replaces the old calc-bugs at asthe dot com address.
|
||||
This replaces the old calc-bugs Email address.
|
||||
|
||||
To be sure we see your Email reporting a calc bug, please use the
|
||||
following phase in your Email Subject line:
|
||||
|
170
hist.c
170
hist.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* hist - interactive readline module
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell
|
||||
* Copyright (C) 1999-2007,2021,2022 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
|
||||
@@ -69,6 +69,7 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -97,7 +98,7 @@ STATIC struct {
|
||||
} HS;
|
||||
|
||||
|
||||
typedef void (*FUNCPTR)();
|
||||
typedef void (*FUNCPTR)(int);
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
@@ -105,38 +106,38 @@ typedef struct {
|
||||
} FUNC;
|
||||
|
||||
/* declare binding functions */
|
||||
S_FUNC void flush_input(void);
|
||||
S_FUNC void start_of_line(void);
|
||||
S_FUNC void end_of_line(void);
|
||||
S_FUNC void forward_char(void);
|
||||
S_FUNC void backward_char(void);
|
||||
S_FUNC void forward_word(void);
|
||||
S_FUNC void backward_word(void);
|
||||
S_FUNC void delete_char(void);
|
||||
S_FUNC void forward_kill_char(void);
|
||||
S_FUNC void backward_kill_char(void);
|
||||
S_FUNC void forward_kill_word(void);
|
||||
S_FUNC void kill_line(void);
|
||||
S_FUNC void new_line(void);
|
||||
S_FUNC void save_line(void);
|
||||
S_FUNC void forward_history(void);
|
||||
S_FUNC void backward_history(void);
|
||||
S_FUNC void flush_input(int key);
|
||||
S_FUNC void start_of_line(int key);
|
||||
S_FUNC void end_of_line(int key);
|
||||
S_FUNC void forward_char(int key);
|
||||
S_FUNC void backward_char(int key);
|
||||
S_FUNC void forward_word(int key);
|
||||
S_FUNC void backward_word(int key);
|
||||
S_FUNC void delete_char(int key);
|
||||
S_FUNC void forward_kill_char(int key);
|
||||
S_FUNC void backward_kill_char(int key);
|
||||
S_FUNC void forward_kill_word(int key);
|
||||
S_FUNC void kill_line(int key);
|
||||
S_FUNC void new_line(int key);
|
||||
S_FUNC void save_line(int key);
|
||||
S_FUNC void forward_history(int key);
|
||||
S_FUNC void backward_history(int key);
|
||||
S_FUNC void insert_char(int key);
|
||||
S_FUNC void goto_line(void);
|
||||
S_FUNC void list_history(void);
|
||||
S_FUNC void refresh_line(void);
|
||||
S_FUNC void swap_chars(void);
|
||||
S_FUNC void set_mark(void);
|
||||
S_FUNC void yank(void);
|
||||
S_FUNC void save_region(void);
|
||||
S_FUNC void kill_region(void);
|
||||
S_FUNC void reverse_search(void);
|
||||
S_FUNC void quote_char(void);
|
||||
S_FUNC void uppercase_word(void);
|
||||
S_FUNC void lowercase_word(void);
|
||||
S_FUNC void ignore_char(void);
|
||||
S_FUNC void arrow_key(void);
|
||||
S_FUNC void quit_calc(void);
|
||||
S_FUNC void goto_line(int key);
|
||||
S_FUNC void list_history(int key);
|
||||
S_FUNC void refresh_line(int key);
|
||||
S_FUNC void swap_chars(int key);
|
||||
S_FUNC void set_mark(int key);
|
||||
S_FUNC void yank(int key);
|
||||
S_FUNC void save_region(int key);
|
||||
S_FUNC void kill_region(int key);
|
||||
S_FUNC void reverse_search(int key);
|
||||
S_FUNC void quote_char(int key);
|
||||
S_FUNC void uppercase_word(int key);
|
||||
S_FUNC void lowercase_word(int key);
|
||||
S_FUNC void ignore_char(int key);
|
||||
S_FUNC void arrow_key(int key);
|
||||
S_FUNC void quit_calc(int key) __attribute__((noreturn));
|
||||
|
||||
|
||||
STATIC FUNC funcs[] =
|
||||
@@ -216,8 +217,8 @@ STATIC int save_len;
|
||||
STATIC KEY_MAP *cur_map;
|
||||
STATIC KEY_MAP *base_map;
|
||||
STATIC KEY_ENT key_table[MAX_KEYS];
|
||||
STATIC HIST* hist_first = NULL;
|
||||
STATIC HIST* hist_last = NULL;
|
||||
STATIC HIST* hist_first = NULL;
|
||||
STATIC HIST* hist_last = NULL;
|
||||
STATIC char save_buffer[SAVE_SIZE];
|
||||
|
||||
/* declare other static functions */
|
||||
@@ -649,12 +650,11 @@ read_key(void)
|
||||
ent = &cur_map->default_ent;
|
||||
if (ent->next)
|
||||
cur_map = ent->next;
|
||||
if (ent->func)
|
||||
/* ignore Saber-C warning #65 - has 1 arg, expecting 0 */
|
||||
/* OK to ignore in proc read_key */
|
||||
if (ent->func != NULL) {
|
||||
(*ent->func)(key);
|
||||
else
|
||||
} else {
|
||||
insert_char(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -796,20 +796,20 @@ find_func(char *name)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
arrow_key(void)
|
||||
arrow_key(int UNUSED(key))
|
||||
{
|
||||
switch (fgetc(stdin)) {
|
||||
case 'A':
|
||||
backward_history();
|
||||
backward_history(0);
|
||||
break;
|
||||
case 'B':
|
||||
forward_history();
|
||||
forward_history(0);
|
||||
break;
|
||||
case 'C':
|
||||
forward_char();
|
||||
forward_char(0);
|
||||
break;
|
||||
case 'D':
|
||||
backward_char();
|
||||
backward_char(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -866,13 +866,13 @@ decrement_end(int n)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
ignore_char(void)
|
||||
ignore_char(int UNUSED(key))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
S_FUNC void
|
||||
flush_input(void)
|
||||
flush_input(int UNUSED(key))
|
||||
{
|
||||
echo_rest_of_line();
|
||||
while (HS.end > HS.buf)
|
||||
@@ -883,21 +883,21 @@ flush_input(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
start_of_line(void)
|
||||
start_of_line(int UNUSED(key))
|
||||
{
|
||||
goto_start_of_line();
|
||||
}
|
||||
|
||||
|
||||
S_FUNC void
|
||||
end_of_line(void)
|
||||
end_of_line(int UNUSED(key))
|
||||
{
|
||||
goto_end_of_line();
|
||||
}
|
||||
|
||||
|
||||
S_FUNC void
|
||||
forward_char(void)
|
||||
forward_char(int UNUSED(key))
|
||||
{
|
||||
if (HS.pos < HS.end)
|
||||
echo_char(*HS.pos++);
|
||||
@@ -905,7 +905,7 @@ forward_char(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
backward_char(void)
|
||||
backward_char(int UNUSED(key))
|
||||
{
|
||||
if (HS.pos > HS.buf)
|
||||
back_over_char((int)(*--HS.pos));
|
||||
@@ -913,7 +913,7 @@ backward_char(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
uppercase_word(void)
|
||||
uppercase_word(int UNUSED(key))
|
||||
{
|
||||
while ((HS.pos < HS.end) && !in_word((int)(*HS.pos)))
|
||||
echo_char(*HS.pos++);
|
||||
@@ -926,7 +926,7 @@ uppercase_word(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
lowercase_word(void)
|
||||
lowercase_word(int UNUSED(key))
|
||||
{
|
||||
while ((HS.pos < HS.end) && !in_word((int)(*HS.pos)))
|
||||
echo_char(*HS.pos++);
|
||||
@@ -939,7 +939,7 @@ lowercase_word(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
forward_word(void)
|
||||
forward_word(int UNUSED(key))
|
||||
{
|
||||
while ((HS.pos < HS.end) && !in_word((int)(*HS.pos)))
|
||||
echo_char(*HS.pos++);
|
||||
@@ -949,7 +949,7 @@ forward_word(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
backward_word(void)
|
||||
backward_word(int UNUSED(key))
|
||||
{
|
||||
if ((HS.pos > HS.buf) && in_word((int)(*HS.pos)))
|
||||
back_over_char((int)(*--HS.pos));
|
||||
@@ -963,7 +963,7 @@ backward_word(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
forward_kill_char(void)
|
||||
forward_kill_char(int UNUSED(key))
|
||||
{
|
||||
int rest;
|
||||
char ch;
|
||||
@@ -985,7 +985,7 @@ forward_kill_char(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
delete_char(void)
|
||||
delete_char(int UNUSED(key))
|
||||
{
|
||||
/*
|
||||
* quit delete_char (usually ^D) is at start of line and we are allowed
|
||||
@@ -996,30 +996,30 @@ delete_char(void)
|
||||
if ((HS.end == HS.buf) &&
|
||||
(conf->ctrl_d == CTRL_D_EMPTY_EOF ||
|
||||
(conf->ctrl_d == CTRL_D_VIRGIN_EOF && HS.virgin_line == TRUE))) {
|
||||
quit_calc();
|
||||
quit_calc(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* normal case: just forward_kill_char
|
||||
*/
|
||||
if (HS.end > HS.buf)
|
||||
forward_kill_char();
|
||||
forward_kill_char(0);
|
||||
}
|
||||
|
||||
|
||||
S_FUNC void
|
||||
backward_kill_char(void)
|
||||
backward_kill_char(int UNUSED(key))
|
||||
{
|
||||
if (HS.pos > HS.buf) {
|
||||
HS.pos--;
|
||||
back_over_char((int)(*HS.pos));
|
||||
forward_kill_char();
|
||||
forward_kill_char(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
S_FUNC void
|
||||
forward_kill_word(void)
|
||||
forward_kill_word(int UNUSED(key))
|
||||
{
|
||||
char *cp;
|
||||
|
||||
@@ -1043,7 +1043,7 @@ forward_kill_word(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
kill_line(void)
|
||||
kill_line(int UNUSED(key))
|
||||
{
|
||||
if (HS.end <= HS.pos)
|
||||
return;
|
||||
@@ -1062,7 +1062,7 @@ kill_line(void)
|
||||
* decide whether or not this should be done.
|
||||
*/
|
||||
S_FUNC void
|
||||
new_line(void)
|
||||
new_line(int UNUSED(key))
|
||||
{
|
||||
int len;
|
||||
|
||||
@@ -1086,21 +1086,21 @@ new_line(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
save_line(void)
|
||||
save_line(int UNUSED(key))
|
||||
{
|
||||
int len;
|
||||
|
||||
len = HS.end - HS.buf;
|
||||
if (len > 0) {
|
||||
hist_saveline(HS.buf, len);
|
||||
flush_input();
|
||||
flush_input(0);
|
||||
}
|
||||
HS.curhist = HS.histcount;
|
||||
}
|
||||
|
||||
|
||||
S_FUNC void
|
||||
goto_line(void)
|
||||
goto_line(int UNUSED(key))
|
||||
{
|
||||
int num;
|
||||
char *cp;
|
||||
@@ -1114,7 +1114,7 @@ goto_line(void)
|
||||
beep();
|
||||
return;
|
||||
}
|
||||
flush_input();
|
||||
flush_input(0);
|
||||
HS.curhist = HS.histcount - num;
|
||||
hp = get_event(HS.curhist);
|
||||
memcpy(HS.buf, hp->data, hp->len);
|
||||
@@ -1124,11 +1124,11 @@ goto_line(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
forward_history(void)
|
||||
forward_history(int UNUSED(key))
|
||||
{
|
||||
HIST *hp;
|
||||
|
||||
flush_input();
|
||||
flush_input(0);
|
||||
if (++HS.curhist >= HS.histcount)
|
||||
HS.curhist = 0;
|
||||
hp = get_event(HS.curhist);
|
||||
@@ -1141,11 +1141,11 @@ forward_history(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
backward_history(void)
|
||||
backward_history(int UNUSED(key))
|
||||
{
|
||||
HIST *hp;
|
||||
|
||||
flush_input();
|
||||
flush_input(0);
|
||||
if (--HS.curhist < 0)
|
||||
HS.curhist = HS.histcount - 1;
|
||||
hp = get_event(HS.curhist);
|
||||
@@ -1207,7 +1207,7 @@ insert_string(char *str, int len)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
list_history(void)
|
||||
list_history(int UNUSED(key))
|
||||
{
|
||||
HIST *hp;
|
||||
int hnum;
|
||||
@@ -1217,12 +1217,12 @@ list_history(void)
|
||||
printf("\n%3d: ", HS.histcount - hnum);
|
||||
echo_string(hp->data, hp->len);
|
||||
}
|
||||
refresh_line();
|
||||
refresh_line(0);
|
||||
}
|
||||
|
||||
|
||||
S_FUNC void
|
||||
refresh_line(void)
|
||||
refresh_line(int UNUSED(key))
|
||||
{
|
||||
char *cp;
|
||||
|
||||
@@ -1238,7 +1238,7 @@ refresh_line(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
swap_chars(void)
|
||||
swap_chars(int UNUSED(key))
|
||||
{
|
||||
char ch1;
|
||||
char ch2;
|
||||
@@ -1257,14 +1257,14 @@ swap_chars(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
set_mark(void)
|
||||
set_mark(int UNUSED(key))
|
||||
{
|
||||
HS.mark = HS.pos;
|
||||
}
|
||||
|
||||
|
||||
S_FUNC void
|
||||
save_region(void)
|
||||
save_region(int UNUSED(key))
|
||||
{
|
||||
int len;
|
||||
|
||||
@@ -1279,7 +1279,7 @@ save_region(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
kill_region(void)
|
||||
kill_region(int UNUSED(key))
|
||||
{
|
||||
char *cp;
|
||||
char *left;
|
||||
@@ -1311,14 +1311,14 @@ kill_region(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
yank(void)
|
||||
yank(int UNUSED(key))
|
||||
{
|
||||
insert_string(save_buffer, save_len);
|
||||
}
|
||||
|
||||
|
||||
S_FUNC void
|
||||
reverse_search(void)
|
||||
reverse_search(int UNUSED(key))
|
||||
{
|
||||
int len;
|
||||
int count;
|
||||
@@ -1344,7 +1344,7 @@ reverse_search(void)
|
||||
|
||||
HS.curhist = testhist;
|
||||
save_pos = HS.pos;
|
||||
flush_input();
|
||||
flush_input(0);
|
||||
memcpy(HS.buf, hp->data, hp->len);
|
||||
HS.end = &HS.buf[hp->len];
|
||||
goto_end_of_line();
|
||||
@@ -1354,7 +1354,7 @@ reverse_search(void)
|
||||
|
||||
|
||||
S_FUNC void
|
||||
quote_char(void)
|
||||
quote_char(int UNUSED(key))
|
||||
{
|
||||
int ch;
|
||||
|
||||
@@ -1450,7 +1450,7 @@ memrcpy(char *dest, char *src, int len)
|
||||
#endif /* !USE_READLINE */
|
||||
|
||||
S_FUNC void
|
||||
quit_calc(void)
|
||||
quit_calc(int UNUSED(ch))
|
||||
{
|
||||
hist_term();
|
||||
putchar('\n');
|
||||
@@ -1492,8 +1492,8 @@ hist_getline(char *prompt, char *buf, size_t len)
|
||||
case CTRL_D_VIRGIN_EOF:
|
||||
case CTRL_D_EMPTY_EOF:
|
||||
default:
|
||||
quit_calc();
|
||||
/*NOTREACHED*/
|
||||
quit_calc(0);
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
strlcpy(buf, line, len);
|
||||
|
19
input.c
19
input.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* input - nested input source file reader
|
||||
*
|
||||
* Copyright (C) 1999-2007,2014,2018,2021 David I. Bell
|
||||
* Copyright (C) 1999-2007,2014,2018,2021,2022 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
|
||||
@@ -55,6 +55,7 @@
|
||||
#include "strl.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -148,7 +149,7 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once)
|
||||
/* firewall */
|
||||
if (name == NULL) {
|
||||
math_error("NULL name given to opensearchfile");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -190,7 +191,7 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once)
|
||||
path = malloc(path_alloc+1);
|
||||
if (path == NULL) {
|
||||
math_error("Cannot allocate filename path buffer");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
path[0] = '\0'; /* paranoia */
|
||||
path[path_alloc] = '\0'; /* paranoia */
|
||||
@@ -304,11 +305,11 @@ f_pathopen(char *name, char *mode, char *pathlist, char **openpath)
|
||||
/* firewall */
|
||||
if (name == NULL) {
|
||||
math_error("NULL name given to f_pathopen");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (mode == NULL) {
|
||||
math_error("NULL mode given to f_pathopen");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -342,7 +343,7 @@ f_pathopen(char *name, char *mode, char *pathlist, char **openpath)
|
||||
path = malloc(pathlen+1 + 1 + namelen+1 + 1 + 1);
|
||||
if (path == NULL) {
|
||||
math_error("Cannot allocate f_pathopen buffer");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -375,7 +376,7 @@ f_pathopen(char *name, char *mode, char *pathlist, char **openpath)
|
||||
}
|
||||
fclose(ret);
|
||||
math_error("cannot malloc return openpath buffer");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
free(path);
|
||||
@@ -756,7 +757,7 @@ nextline(void)
|
||||
cp = (char *)malloc(TTYSIZE + 1);
|
||||
if (cp == NULL) {
|
||||
math_error("Cannot allocate line buffer");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
linebuf = cp;
|
||||
linesize = TTYSIZE;
|
||||
@@ -776,7 +777,7 @@ nextline(void)
|
||||
cp = (char *)realloc(cp, linesize + TTYSIZE + 1);
|
||||
if (cp == NULL) {
|
||||
math_error("Cannot realloc line buffer");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
linebuf = cp;
|
||||
linesize += TTYSIZE;
|
||||
|
37
lib_calc.c
37
lib_calc.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* lib_calc - calc link library initialization and shutdown routines
|
||||
*
|
||||
* Copyright (C) 1999-2007,2018,2021 Landon Curt Noll
|
||||
* Copyright (C) 1999-2007,2018,2021,2022 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
|
||||
@@ -94,6 +94,7 @@ typedef struct {int fd;} ttystruct;
|
||||
#endif /* Windows */
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -320,6 +321,7 @@ libcalc_call_me_first(void)
|
||||
if (d_flag) {
|
||||
conf->resource_debug = 0;
|
||||
conf->tilde_ok = 0;
|
||||
conf->tilde_space = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -500,7 +502,7 @@ initenv(void)
|
||||
if (strlen(calcrc) > MAX_CALCRC) {
|
||||
math_error("The $CALCRC variable is longer than %d chars",
|
||||
MAX_CALCRC);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/* determine the $CALCBINDINGS value */
|
||||
@@ -542,7 +544,7 @@ initenv(void)
|
||||
/* paranoia */
|
||||
if (home == NULL) {
|
||||
math_error("Unable to allocate string for $HOME");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/* determine the $PAGER value */
|
||||
@@ -692,7 +694,7 @@ calc_strdup(CONST char *s1)
|
||||
#else /* HAVE_STRDUP */
|
||||
|
||||
char *ret; /* return string */
|
||||
size_t s1_len; /* length of string to duplicate */
|
||||
size_t s1_len; /* length of string to duplicate */
|
||||
|
||||
/*
|
||||
* firewall
|
||||
@@ -736,7 +738,7 @@ S_FUNC int
|
||||
find_tty_state(int fd)
|
||||
{
|
||||
int *new_fd_setup; /* new fd_setup array */
|
||||
ttystruct *new_fd_orig; /* new fd_orig array */
|
||||
ttystruct *new_fd_orig; /* new fd_orig array */
|
||||
ttystruct *new_fd_cur; /* new fd_cur array */
|
||||
int i;
|
||||
|
||||
@@ -763,7 +765,7 @@ find_tty_state(int fd)
|
||||
if (fd_orig == NULL) {
|
||||
return -1;
|
||||
}
|
||||
fd_cur = (ttystruct *)malloc(sizeof(fd_orig[0]));
|
||||
fd_cur = (ttystruct *)malloc(sizeof(fd_cur[0]));
|
||||
if (fd_cur == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@@ -795,26 +797,35 @@ find_tty_state(int fd)
|
||||
/*
|
||||
* no empty slots exist, realloc another slot
|
||||
*/
|
||||
/* expand fd_orig as an original pre-modified copy of fd_setup */
|
||||
new_fd_orig = (ttystruct *)realloc(fd_orig, sizeof(fd_orig[0]) *
|
||||
(fd_setup_len+1));
|
||||
if (new_fd_orig == NULL) {
|
||||
return -1;
|
||||
}
|
||||
fd_orig = new_fd_orig;
|
||||
memcpy(fd_orig, fd_setup, sizeof(fd_orig[0]) * (fd_setup_len+1));
|
||||
|
||||
/* expand fd_setup */
|
||||
new_fd_setup = (int *)realloc(fd_setup, sizeof(fd_setup[0]) *
|
||||
(fd_setup_len+1));
|
||||
if (new_fd_setup == NULL) {
|
||||
return -1;
|
||||
}
|
||||
fd_setup = new_fd_setup;
|
||||
new_fd_setup[fd_setup_len] = -1;
|
||||
new_fd_orig = (ttystruct *)realloc(fd_setup, sizeof(fd_orig[0]) *
|
||||
(fd_setup_len+1));
|
||||
if (new_fd_orig == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* expand fd_cur */
|
||||
new_fd_cur = (ttystruct *)realloc(fd_cur, sizeof(fd_cur[0]) *
|
||||
(fd_setup_len+1));
|
||||
if (new_fd_cur == NULL) {
|
||||
return -1;
|
||||
}
|
||||
fd_setup = new_fd_setup;
|
||||
fd_orig = new_fd_orig;
|
||||
fd_cur = new_fd_cur;
|
||||
|
||||
/* expand fd setup length */
|
||||
++fd_setup_len;
|
||||
|
||||
/* return the new slot */
|
||||
return fd_setup_len-1;
|
||||
}
|
||||
|
11
lib_util.c
11
lib_util.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* lib_util - calc library utility routines
|
||||
*
|
||||
* Copyright (C) 1999-2006,2021 Landon Curt Noll
|
||||
* Copyright (C) 1999-2006,2021,2022 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
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "lib_util.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -151,7 +152,7 @@ convstr2z(char *str)
|
||||
v = (HALF *)malloc(len * sizeof(HALF));
|
||||
if (v == NULL) {
|
||||
math_error("convstr2z bad malloc");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
v[len-1] = 0; /* deal with possible partial end of string HALF */
|
||||
|
||||
@@ -222,7 +223,7 @@ convhex2z(char *hex)
|
||||
v = (HALF *)malloc(len * sizeof(HALF));
|
||||
if (v == NULL) {
|
||||
math_error("convhex2z bad malloc");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
v[len-1] = 0; /* deal with possible partial end of string HALF */
|
||||
|
||||
@@ -313,7 +314,7 @@ convz2hex(ZVALUE z)
|
||||
ret = (char *)malloc(sizeof("0"));
|
||||
if (ret == NULL) {
|
||||
math_error("convz2hex bad malloc of 0 value");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
ret[0] = '0';
|
||||
ret[1] = '\0';
|
||||
@@ -327,7 +328,7 @@ convz2hex(ZVALUE z)
|
||||
ret = (char *)calloc(slen+1+1, sizeof(char));
|
||||
if (ret == NULL) {
|
||||
math_error("convz2hex bad malloc of string");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
|
21
listfunc.c
21
listfunc.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* listfunc - list handling routines
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell
|
||||
* Copyright (C) 1999-2007,2021,2022 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
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "zrand.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -129,7 +130,7 @@ insertlistmiddle(LIST *lp, long index, VALUE *vp)
|
||||
oldep = listelement(lp, index);
|
||||
if (oldep == NULL) {
|
||||
math_error("Index out of bounds for list insertion");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
ep = elemalloc();
|
||||
copyvalue(vp, &ep->e_value);
|
||||
@@ -207,7 +208,7 @@ removelistmiddle(LIST *lp, long index, VALUE *vp)
|
||||
ep = listelement(lp, index);
|
||||
if (ep == NULL) {
|
||||
math_error("Index out of bounds for list deletion");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
*vp = ep->e_value;
|
||||
ep->e_value.v_type = V_NULL;
|
||||
@@ -297,14 +298,14 @@ listsearch(LIST *lp, VALUE *vp, long i, long j, ZVALUE *index)
|
||||
|
||||
if (i < 0 || j > lp->l_count) {
|
||||
math_error("This should not happen in call to listsearch");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
ep = listelement(lp, i);
|
||||
while (i < j) {
|
||||
if (!ep) {
|
||||
math_error("This should not happen in listsearch");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (acceptvalue(&ep->e_value, vp)) {
|
||||
lp->l_cache = ep;
|
||||
@@ -331,14 +332,14 @@ listrsearch(LIST *lp, VALUE *vp, long i, long j, ZVALUE *index)
|
||||
|
||||
if (i < 0 || j > lp->l_count) {
|
||||
math_error("This should not happen in call to listrsearch");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
ep = listelement(lp, --j);
|
||||
while (j >= i) {
|
||||
if (!ep) {
|
||||
math_error("This should not happen in listsearch");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (acceptvalue(&ep->e_value, vp)) {
|
||||
lp->l_cache = ep;
|
||||
@@ -771,7 +772,7 @@ listsort(LIST *lp)
|
||||
if (k >= LONG_BITS) {
|
||||
/* this should never happen */
|
||||
math_error("impossible k overflow in listsort!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
lp->l_first = start->e_next;
|
||||
lp->l_first->e_prev = NULL;
|
||||
@@ -812,7 +813,7 @@ elemalloc(void)
|
||||
ep = (LISTELEM *) malloc(sizeof(LISTELEM));
|
||||
if (ep == NULL) {
|
||||
math_error("Cannot allocate list element");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
ep->e_next = NULL;
|
||||
ep->e_prev = NULL;
|
||||
@@ -845,7 +846,7 @@ listalloc(void)
|
||||
lp = (LIST *) malloc(sizeof(LIST));
|
||||
if (lp == NULL) {
|
||||
math_error("Cannot allocate list header");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
lp->l_first = NULL;
|
||||
lp->l_last = NULL;
|
||||
|
71
matfunc.c
71
matfunc.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* matfunc - extended precision rational arithmetic matrix functions
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell
|
||||
* Copyright (C) 1999-2007,2021,2022 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
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -63,7 +64,7 @@ matadd(MATRIX *m1, MATRIX *m2)
|
||||
|
||||
if (m1->m_dim != m2->m_dim) {
|
||||
math_error("Incompatible matrix dimensions for add");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
tmp.m_dim = m1->m_dim;
|
||||
tmp.m_size = m1->m_size;
|
||||
@@ -75,7 +76,7 @@ matadd(MATRIX *m1, MATRIX *m2)
|
||||
if ((min1 && min2 && (min1 != min2)) ||
|
||||
((max1-min1) != (max2-min2))) {
|
||||
math_error("Incompatible matrix bounds for add");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
tmp.m_min[dim] = (min1 ? min1 : min2);
|
||||
tmp.m_max[dim] = tmp.m_min[dim] + (max1 - min1);
|
||||
@@ -105,7 +106,7 @@ matsub(MATRIX *m1, MATRIX *m2)
|
||||
|
||||
if (m1->m_dim != m2->m_dim) {
|
||||
math_error("Incompatible matrix dimensions for sub");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
tmp.m_dim = m1->m_dim;
|
||||
tmp.m_size = m1->m_size;
|
||||
@@ -117,7 +118,7 @@ matsub(MATRIX *m1, MATRIX *m2)
|
||||
if ((min1 && min2 && (min1 != min2)) ||
|
||||
((max1-min1) != (max2-min2))) {
|
||||
math_error("Incompatible matrix bounds for sub");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
tmp.m_min[dim] = (min1 ? min1 : min2);
|
||||
tmp.m_max[dim] = tmp.m_min[dim] + (max1 - min1);
|
||||
@@ -187,7 +188,7 @@ matmul(MATRIX *m1, MATRIX *m2)
|
||||
if (m1->m_dim == 1 && m2->m_dim == 1) {
|
||||
if (m1->m_max[0]-m1->m_min[0] != m2->m_max[0]-m2->m_min[0]) {
|
||||
math_error("Incompatible bounds for 1D * 1D matmul");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
res = matalloc(m1->m_size);
|
||||
*res = *m1;
|
||||
@@ -201,7 +202,7 @@ matmul(MATRIX *m1, MATRIX *m2)
|
||||
if (m1->m_dim == 1 && m2->m_dim == 2) {
|
||||
if (m1->m_max[0]-m1->m_min[0] != m2->m_max[0]-m2->m_min[0]) {
|
||||
math_error("Incompatible bounds for 1D * 2D matmul");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
res = matalloc(m2->m_size);
|
||||
*res = *m2;
|
||||
@@ -221,7 +222,7 @@ matmul(MATRIX *m1, MATRIX *m2)
|
||||
if (m1->m_dim == 2 && m2->m_dim == 1) {
|
||||
if (m1->m_max[1]-m1->m_min[1] != m2->m_max[0]-m2->m_min[0]) {
|
||||
math_error("Incompatible bounds for 2D * 1D matmul");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
res = matalloc(m1->m_size);
|
||||
*res = *m1;
|
||||
@@ -240,11 +241,11 @@ matmul(MATRIX *m1, MATRIX *m2)
|
||||
|
||||
if ((m1->m_dim != 2) || (m2->m_dim != 2)) {
|
||||
math_error("Matrix dimensions not compatible for mul");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if ((m1->m_max[1]-m1->m_min[1]) != (m2->m_max[0]-m2->m_min[0])) {
|
||||
math_error("Incompatible bounds for 2D * 2D matrix mul");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
max1 = (m1->m_max[0] - m1->m_min[0] + 1);
|
||||
max2 = (m2->m_max[1] - m2->m_min[1] + 1);
|
||||
@@ -301,11 +302,11 @@ matsquare(MATRIX *m)
|
||||
}
|
||||
if (m->m_dim != 2) {
|
||||
math_error("Matrix dimension exceeds two for square");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1])) {
|
||||
math_error("Squaring non-square matrix");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
max = (m->m_max[0] - m->m_min[0] + 1);
|
||||
res = matalloc(max * max);
|
||||
@@ -357,20 +358,20 @@ matpowi(MATRIX *m, NUMBER *q)
|
||||
|
||||
if (m->m_dim > 2) {
|
||||
math_error("Matrix dimension greater than 2 for power");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (m->m_dim == 2 && (m->m_max[0] - m->m_min[0] !=
|
||||
m->m_max[1] - m->m_min[1])) {
|
||||
math_error("Raising non-square 2D matrix to a power");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisfrac(q)) {
|
||||
math_error("Raising matrix to non-integral power");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (zge31b(q->num)) {
|
||||
math_error("Raising matrix to very large power");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
power = ztolong(q->num);
|
||||
if (qisneg(q))
|
||||
@@ -610,7 +611,7 @@ matquoval(MATRIX *m, VALUE *vp, VALUE *v3)
|
||||
|
||||
if ((vp->v_type == V_NUM) && qiszero(vp->v_num)) {
|
||||
math_error("Division by zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
res = matalloc(m->m_size);
|
||||
*res = *m;
|
||||
@@ -640,7 +641,7 @@ matmodval(MATRIX *m, VALUE *vp, VALUE *v3)
|
||||
|
||||
if ((vp->v_type == V_NUM) && qiszero(vp->v_num)) {
|
||||
math_error("Division by zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
res = matalloc(m->m_size);
|
||||
*res = *m;
|
||||
@@ -866,31 +867,31 @@ matindex(MATRIX *mp, BOOL UNUSED(create), long dim, VALUE *indices)
|
||||
|
||||
if (dim < 0) {
|
||||
math_error("Negative dimension %ld for matrix", dim);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
for (;;) {
|
||||
if (dim < mp->m_dim) {
|
||||
math_error(
|
||||
"Indexing a %ldd matrix as a %ldd matrix",
|
||||
mp->m_dim, dim);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
offset = 0;
|
||||
for (i = 0; i < mp->m_dim; i++) {
|
||||
if (indices->v_type != V_NUM) {
|
||||
math_error("Non-numeric index for matrix");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
q = indices->v_num;
|
||||
if (qisfrac(q)) {
|
||||
math_error("Non-integral index for matrix");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
index = qtoi(q);
|
||||
if (zge31b(q->num) || (index < mp->m_min[i]) ||
|
||||
(index > mp->m_max[i])) {
|
||||
math_error("Index out of bounds for matrix");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
offset *= (mp->m_max[i] - mp->m_min[i] + 1);
|
||||
offset += (index - mp->m_min[i]);
|
||||
@@ -902,7 +903,7 @@ matindex(MATRIX *mp, BOOL UNUSED(create), long dim, VALUE *indices)
|
||||
break;
|
||||
if (vp->v_type != V_MAT) {
|
||||
math_error("Non-matrix argument for matindex");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
mp = vp->v_mat;
|
||||
}
|
||||
@@ -953,7 +954,7 @@ matsearch(MATRIX *m, VALUE *vp, long i, long j, ZVALUE *index)
|
||||
val = &m->m_table[i];
|
||||
if (i < 0 || j > m->m_size) {
|
||||
math_error("This should not happen in call to matsearch");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
while (i < j) {
|
||||
if (acceptvalue(val++, vp)) {
|
||||
@@ -978,7 +979,7 @@ matrsearch(MATRIX *m, VALUE *vp, long i, long j, ZVALUE *index)
|
||||
|
||||
if (i < 0 || j > m->m_size) {
|
||||
math_error("This should not happen in call to matrsearch");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
val = &m->m_table[--j];
|
||||
while (j >= i) {
|
||||
@@ -1056,11 +1057,11 @@ matident(MATRIX *m)
|
||||
if (m->m_dim != 2) {
|
||||
math_error(
|
||||
"Matrix dimension must be two for setting to identity");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1])) {
|
||||
math_error("Matrix must be square for setting to identity");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
res = matalloc(m->m_size);
|
||||
*res = *m;
|
||||
@@ -1108,11 +1109,11 @@ matinv(MATRIX *m)
|
||||
}
|
||||
if (m->m_dim != 2) {
|
||||
math_error("Matrix dimension exceeds two for inverse");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1])) {
|
||||
math_error("Inverting non-square matrix");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
/*
|
||||
* Begin by creating the identity matrix with the same attributes.
|
||||
@@ -1154,7 +1155,7 @@ matinv(MATRIX *m)
|
||||
matfree(m);
|
||||
matfree(res);
|
||||
math_error("Matrix is not invertible");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
val += rows;
|
||||
}
|
||||
@@ -1447,7 +1448,7 @@ matinit(MATRIX *m, VALUE *v1, VALUE *v2)
|
||||
((res->m_max[0] - res->m_min[0]) !=
|
||||
(res->m_max[1] - res->m_min[1])))) {
|
||||
math_error("Filling diagonals of non-square matrix");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1489,7 +1490,7 @@ matalloc(long size)
|
||||
if (m == NULL) {
|
||||
math_error("Cannot get memory to allocate matrix of size %ld",
|
||||
size);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
m->m_size = size;
|
||||
for (i = size, vp = m->m_table; i > 0; i--, vp++)
|
||||
@@ -1617,7 +1618,7 @@ matsort(MATRIX *m)
|
||||
buf = (VALUE *) malloc(m->m_size * sizeof(VALUE));
|
||||
if (buf == NULL) {
|
||||
math_error("Not enough memory for matsort");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
next = m->m_table;
|
||||
end = next + m->m_size;
|
||||
@@ -1672,7 +1673,7 @@ matsort(MATRIX *m)
|
||||
if (k >= LONG_BITS) {
|
||||
/* this should never happen */
|
||||
math_error("impossible k overflow in matsort!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
|
41
obj.c
41
obj.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* obj - object handling primitives
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell
|
||||
* Copyright (C) 1999-2007,2021,2022 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
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "strl.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -223,7 +224,7 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
|
||||
|
||||
if ((unsigned)action > OBJ_MAXFUNC) {
|
||||
math_error("Illegal action for object call");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
oip = &objectinfo[action];
|
||||
if (v1->v_type == V_OBJ) {
|
||||
@@ -232,20 +233,20 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
|
||||
oap = v2->v_obj->o_actions;
|
||||
} else {
|
||||
math_error("Object routine called with non-object");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
index = oap->oa_indices[action];
|
||||
if (index < 0) {
|
||||
namestr_ret = namestr(&objectnames, oap->oa_index);
|
||||
if (namestr_ret == NULL) {
|
||||
math_error("namestr returned NULL!!!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
namestr_len = strlen(namestr_ret);
|
||||
opi_name_len = strlen(oip->name);
|
||||
if (namestr_len > (size_t)SYMBOLSIZE-1-opi_name_len) {
|
||||
math_error("namestr returned a strong too long!!!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
name[0] = '\0';
|
||||
strlcpy(name, namestr_ret, namestr_len+1);
|
||||
@@ -278,7 +279,7 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
|
||||
case ERR_POW:
|
||||
if (v2->v_type != V_NUM) {
|
||||
math_error("Non-real power");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
val = objpowi(v1, v2->v_num);
|
||||
break;
|
||||
@@ -312,7 +313,7 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
|
||||
default:
|
||||
math_error("Function \"%s\" is undefined",
|
||||
namefunc(index));
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return val;
|
||||
}
|
||||
@@ -345,7 +346,7 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
|
||||
break;
|
||||
default:
|
||||
math_error("Bad number of args to calculate");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
calculate(fp, oip->args);
|
||||
switch (oip->retval) {
|
||||
@@ -358,7 +359,7 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
|
||||
case A_INT:
|
||||
if ((stack->v_type != V_NUM) || qisfrac(stack->v_num)) {
|
||||
math_error("Integer return value required");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
index = qtoi(stack->v_num);
|
||||
qfree(stack->v_num);
|
||||
@@ -368,7 +369,7 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
|
||||
break;
|
||||
default:
|
||||
math_error("Bad object return");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return val;
|
||||
}
|
||||
@@ -457,11 +458,11 @@ objpowi(VALUE *vp, NUMBER *q)
|
||||
|
||||
if (qisfrac(q)) {
|
||||
math_error("Raising object to non-integral power");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (zge31b(q->num)) {
|
||||
math_error("Raising object to very large power");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
power = ztolong(q->num);
|
||||
if (qisneg(q))
|
||||
@@ -572,7 +573,7 @@ defineobject(char *name, int indices[], int count)
|
||||
}
|
||||
if (newobjects == NULL) {
|
||||
math_error("Allocation failure for new object type");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
objects = newobjects;
|
||||
}
|
||||
@@ -580,12 +581,12 @@ defineobject(char *name, int indices[], int count)
|
||||
oap = (OBJECTACTIONS *) malloc(objectactionsize(count));
|
||||
if (oap == NULL) {
|
||||
math_error("Cannot allocate object type #0");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
name = addstr(hp, name);
|
||||
if (name == NULL) {
|
||||
math_error("Cannot allocate object type #1");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
oap->oa_count = count;
|
||||
for (index = OBJ_MAXFUNC; index >= 0; index--)
|
||||
@@ -634,7 +635,7 @@ addelement(char *name)
|
||||
return index;
|
||||
if (addstr(hp, name) == NULL) {
|
||||
math_error("Cannot allocate element name");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return findstr(hp, name);
|
||||
}
|
||||
@@ -699,12 +700,12 @@ objalloc(long index)
|
||||
|
||||
if (index < 0 || index > maxobjcount) {
|
||||
math_error("Allocating bad object index");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
oap = objects[index];
|
||||
if (oap == NULL) {
|
||||
math_error("Object type not defined");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
i = oap->oa_count;
|
||||
if (i < USUAL_ELEMENTS)
|
||||
@@ -715,7 +716,7 @@ objalloc(long index)
|
||||
op = (OBJECT *) malloc(objectsize(i));
|
||||
if (op == NULL) {
|
||||
math_error("Cannot allocate object");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
op->o_actions = oap;
|
||||
vp = op->o_table;
|
||||
@@ -771,7 +772,7 @@ objcopy(OBJECT *op)
|
||||
np = (OBJECT *) malloc(objectsize(i));
|
||||
if (np == NULL) {
|
||||
math_error("Cannot allocate object");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
np->o_actions = op->o_actions;
|
||||
v1 = op->o_table;
|
||||
|
65
qfunc.c
65
qfunc.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* qfunc - extended precision rational arithmetic non-primitive functions
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
|
||||
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
*
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "prime.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -56,7 +57,7 @@ setepsilon(NUMBER *q)
|
||||
|
||||
if (qisneg(q) || qiszero(q)) {
|
||||
math_error("Epsilon value must be greater than zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
old = conf->epsilon;
|
||||
conf->epsilonprec = qprecision(q);
|
||||
@@ -82,7 +83,7 @@ qminv(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
if (qisfrac(q1) || qisfrac(q2)) {
|
||||
math_error("Non-integers for minv");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q2)) {
|
||||
if (qisunit(q1))
|
||||
@@ -135,11 +136,11 @@ qpowermod(NUMBER *q1, NUMBER *q2, NUMBER *q3)
|
||||
|
||||
if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3)) {
|
||||
math_error("Non-integers for pmod");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisneg(q2)) {
|
||||
math_error("Negative power for pmod");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q3))
|
||||
return qpowi(q1, q2);
|
||||
@@ -191,7 +192,7 @@ qpowi(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
if (qisfrac(q2)) {
|
||||
math_error("Raising number to fractional power");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
num = q1->num;
|
||||
zden = q1->den;
|
||||
@@ -206,7 +207,7 @@ qpowi(NUMBER *q1, NUMBER *q2)
|
||||
if (ziszero(num) && !ziszero(z2)) { /* zero raised to a power */
|
||||
if (invert) {
|
||||
math_error("Zero raised to negative power");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return qlink(&_qzero_);
|
||||
}
|
||||
@@ -251,7 +252,7 @@ qhypot(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for hypot");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q1))
|
||||
return qqabs(q2);
|
||||
@@ -281,7 +282,7 @@ qlegtoleg(NUMBER *q, NUMBER *epsilon, BOOL wantneg)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for legtoleg");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisunit(q))
|
||||
return qlink(&_qzero_);
|
||||
@@ -294,7 +295,7 @@ qlegtoleg(NUMBER *q, NUMBER *epsilon, BOOL wantneg)
|
||||
num.sign = 0;
|
||||
if (zrel(num, q->den) >= 0) {
|
||||
math_error("Leg too large in legtoleg");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
qtmp1 = qsquare(q);
|
||||
qtmp2 = qsub(&_qone_, qtmp1);
|
||||
@@ -329,14 +330,14 @@ qsqrt(NUMBER *q1, NUMBER *epsilon, long rnd)
|
||||
|
||||
if (qisneg(q1)) {
|
||||
math_error("Square root of negative number");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q1))
|
||||
return qlink(&_qzero_);
|
||||
sign = (rnd & 64) != 0;
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon for qsqrt");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
etemp = *epsilon;
|
||||
@@ -435,7 +436,7 @@ qisqrt(NUMBER *q)
|
||||
|
||||
if (qisneg(q)) {
|
||||
math_error("Square root of negative number");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q))
|
||||
return qlink(&_qzero_);
|
||||
@@ -477,7 +478,7 @@ qiroot(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
if (qisneg(q2) || qiszero(q2) || qisfrac(q2)) {
|
||||
math_error("Taking number to bad root value");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q1))
|
||||
return qlink(&_qzero_);
|
||||
@@ -514,7 +515,7 @@ qilog2(NUMBER *q)
|
||||
|
||||
if (qiszero(q)) {
|
||||
math_error("Zero argument for ilog2");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisint(q))
|
||||
return zhighbit(q->num);
|
||||
@@ -554,7 +555,7 @@ qilog10(NUMBER *q)
|
||||
|
||||
if (qiszero(q)) {
|
||||
math_error("Zero argument for ilog10");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
tmp1 = q->num;
|
||||
tmp1.sign = 0;
|
||||
@@ -810,7 +811,7 @@ qfact(NUMBER *q)
|
||||
|
||||
if (qisfrac(q)) {
|
||||
math_error("Non-integral factorial");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q) || zisone(q->num))
|
||||
return qlink(&_qone_);
|
||||
@@ -831,7 +832,7 @@ qpfact(NUMBER *q)
|
||||
|
||||
if (qisfrac(q)) {
|
||||
math_error("Non-integral factorial");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
r = qalloc();
|
||||
zpfact(q->num, &r->num);
|
||||
@@ -850,7 +851,7 @@ qlcmfact(NUMBER *q)
|
||||
|
||||
if (qisfrac(q)) {
|
||||
math_error("Non-integral lcmfact");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
r = qalloc();
|
||||
zlcmfact(q->num, &r->num);
|
||||
@@ -870,7 +871,7 @@ qperm(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
if (qisfrac(q2)) {
|
||||
math_error("Non-integral second arg for permutation");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q2))
|
||||
return qlink(&_qone_);
|
||||
@@ -887,7 +888,7 @@ qperm(NUMBER *q1, NUMBER *q2)
|
||||
}
|
||||
if (zge31b(q2->num)) {
|
||||
math_error("Too large arg2 for permutation");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
i = qtoi(q2);
|
||||
if (i > 0) {
|
||||
@@ -934,7 +935,7 @@ qcomb(NUMBER *q, NUMBER *n)
|
||||
|
||||
if (!qisint(n) || qisneg(n)) {
|
||||
math_error("Bad second arg in call to qcomb!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisint(q)) {
|
||||
switch (zcomb(q->num, n->num, &z)) {
|
||||
@@ -1181,7 +1182,7 @@ qjacobi(NUMBER *q1, NUMBER *q2)
|
||||
{
|
||||
if (qisfrac(q1) || qisfrac(q2)) {
|
||||
math_error("Non-integral arguments for jacobi");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return itoq((long) zjacobi(q1->num, q2->num));
|
||||
}
|
||||
@@ -1197,7 +1198,7 @@ qfib(NUMBER *q)
|
||||
|
||||
if (qisfrac(q)) {
|
||||
math_error("Non-integral Fibonacci number");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
r = qalloc();
|
||||
zfib(q->num, &r->num);
|
||||
@@ -1216,7 +1217,7 @@ qtrunc(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
if (qisfrac(q2) || !zistiny(q2->num)) {
|
||||
math_error("Bad number of places for qtrunc");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
places = qtoi(q2);
|
||||
e = qtenpow(-places);
|
||||
@@ -1240,7 +1241,7 @@ qbtrunc(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
if (qisfrac(q2) || !zistiny(q2->num)) {
|
||||
math_error("Bad number of places for qtrunc");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
places = qtoi(q2);
|
||||
e = qbitvalue(-places);
|
||||
@@ -1678,7 +1679,7 @@ qfacrem(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
if (qisfrac(q1) || qisfrac(q2)) {
|
||||
math_error("Non-integers for factor removal");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q2))
|
||||
return qqabs(q1);
|
||||
@@ -1711,7 +1712,7 @@ qgcdrem(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
if (qisfrac(q1) || qisfrac(q2)) {
|
||||
math_error("Non-integers for gcdrem");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q2))
|
||||
return qlink(&_qone_);
|
||||
@@ -1745,12 +1746,12 @@ qlowfactor(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
if (qisfrac(q1) || qisfrac(q2)) {
|
||||
math_error("Non-integers for lowfactor");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
count = ztoi(q2->num);
|
||||
if (count > PIX_32B) {
|
||||
math_error("lowfactor count is too large");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return utoq(zlowfactor(q1->num, count));
|
||||
}
|
||||
@@ -1840,11 +1841,11 @@ qprimetest(NUMBER *q1, NUMBER *q2, NUMBER *q3)
|
||||
{
|
||||
if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3)) {
|
||||
math_error("Bad arguments for ptest");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (zge24b(q2->num)) {
|
||||
math_error("ptest count >= 2^24");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return zprimetest(q1->num, ztoi(q2->num), q3->num);
|
||||
}
|
||||
|
49
qio.c
49
qio.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* qio - scanf and printf routines for arbitrary precision rational numbers
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell
|
||||
* Copyright (C) 1999-2007,2021,2022 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
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "have_unused.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -200,16 +201,24 @@ qprintnum(NUMBER *q, int outmode, LEN outdigits)
|
||||
}
|
||||
switch (outmode) {
|
||||
case MODE_INT:
|
||||
if (conf->tilde_ok && qisfrac(q))
|
||||
if (conf->tilde_ok && qisfrac(q)) {
|
||||
PUTCHAR('~');
|
||||
if (conf->tilde_space && qisfrac(q)) {
|
||||
PUTCHAR(' ');
|
||||
}
|
||||
}
|
||||
qprintfd(q, 0L);
|
||||
break;
|
||||
|
||||
case MODE_REAL:
|
||||
prec = qdecplaces(q);
|
||||
if ((prec < 0) || (prec > outdigits)) {
|
||||
if (conf->tilde_ok)
|
||||
if (conf->tilde_ok) {
|
||||
PUTCHAR('~');
|
||||
if (conf->tilde_space) {
|
||||
PUTCHAR(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (conf->fullzero || (prec < 0) ||
|
||||
(prec > outdigits))
|
||||
@@ -306,7 +315,7 @@ qprintnum(NUMBER *q, int outmode, LEN outdigits)
|
||||
|
||||
default:
|
||||
math_error("Bad mode for print");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
if (outmode2 != MODE2_OFF) {
|
||||
@@ -411,7 +420,13 @@ qprintfr(NUMBER *q, long width, BOOL force)
|
||||
{
|
||||
zprintval(q->num, 0L, width);
|
||||
if (force || qisfrac(q)) {
|
||||
if (conf->fraction_space) {
|
||||
PUTCHAR(' ');
|
||||
}
|
||||
PUTCHAR('/');
|
||||
if (conf->fraction_space) {
|
||||
PUTCHAR(' ');
|
||||
}
|
||||
zprintval(q->den, 0L, width);
|
||||
}
|
||||
}
|
||||
@@ -445,7 +460,13 @@ qprintfx(NUMBER *q, long width)
|
||||
{
|
||||
zprintx(q->num, width);
|
||||
if (qisfrac(q)) {
|
||||
if (conf->fraction_space) {
|
||||
PUTCHAR(' ');
|
||||
}
|
||||
PUTCHAR('/');
|
||||
if (conf->fraction_space) {
|
||||
PUTCHAR(' ');
|
||||
}
|
||||
zprintx(q->den, 0L);
|
||||
}
|
||||
}
|
||||
@@ -460,7 +481,13 @@ qprintfb(NUMBER *q, long width)
|
||||
{
|
||||
zprintb(q->num, width);
|
||||
if (qisfrac(q)) {
|
||||
if (conf->fraction_space) {
|
||||
PUTCHAR(' ');
|
||||
}
|
||||
PUTCHAR('/');
|
||||
if (conf->fraction_space) {
|
||||
PUTCHAR(' ');
|
||||
}
|
||||
zprintb(q->den, 0L);
|
||||
}
|
||||
}
|
||||
@@ -475,7 +502,13 @@ qprintfo(NUMBER *q, long width)
|
||||
{
|
||||
zprinto(q->num, width);
|
||||
if (qisfrac(q)) {
|
||||
if (conf->fraction_space) {
|
||||
PUTCHAR(' ');
|
||||
}
|
||||
PUTCHAR('/');
|
||||
if (conf->fraction_space) {
|
||||
PUTCHAR(' ');
|
||||
}
|
||||
zprinto(q->den, 0L);
|
||||
}
|
||||
}
|
||||
@@ -536,7 +569,7 @@ str2q(char *s)
|
||||
exp = (exp * 10) + *t++ - '0';
|
||||
if (exp > (MAXLONG/10L)) {
|
||||
math_error("Exponent too large");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -748,6 +781,12 @@ fitprint(NUMBER *q, long width)
|
||||
width1 = width - width2;
|
||||
}
|
||||
fitzprint(q->num, numdigits, width1);
|
||||
if (conf->fraction_space) {
|
||||
PUTCHAR(' ');
|
||||
}
|
||||
PUTCHAR('/');
|
||||
if (conf->fraction_space) {
|
||||
PUTCHAR(' ');
|
||||
}
|
||||
fitzprint(q->den, dendigits, width2);
|
||||
}
|
||||
|
35
qmath.c
35
qmath.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* qmath - extended precision rational arithmetic primitive routines
|
||||
*
|
||||
* Copyright (C) 1999-2007,2014,2021 David I. Bell and Ernest Bowen
|
||||
* Copyright (C) 1999-2007,2014,2021,2022 David I. Bell and Ernest Bowen
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
*
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "config.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -224,7 +225,7 @@ uutoq(FULL inum, FULL iden)
|
||||
|
||||
if (iden == 0) {
|
||||
math_error("Division by zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (inum == 0)
|
||||
return qlink(&_qzero_);
|
||||
@@ -256,7 +257,7 @@ iitoq(long inum, long iden)
|
||||
|
||||
if (iden == 0) {
|
||||
math_error("Division by zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (inum == 0)
|
||||
return qlink(&_qzero_);
|
||||
@@ -504,7 +505,7 @@ qmul(NUMBER *q1, NUMBER *q2)
|
||||
d2 = q2->den;
|
||||
if (ziszero(d1) || ziszero(d2)) {
|
||||
math_error("Division by zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (ziszero(n1) || ziszero(n2))
|
||||
return qlink(&_qzero_);
|
||||
@@ -583,7 +584,7 @@ qqdiv(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
if (qiszero(q2)) {
|
||||
math_error("Division by zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if ((q1 == q2) || !qcmp(q1, q2))
|
||||
return qlink(&_qone_);
|
||||
@@ -611,7 +612,7 @@ qdivi(NUMBER *q, long n)
|
||||
|
||||
if (n == 0) {
|
||||
math_error("Division by zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if ((n == 1) || qiszero(q))
|
||||
return qlink(q);
|
||||
@@ -734,7 +735,7 @@ qinv(NUMBER *q)
|
||||
}
|
||||
if (qiszero(q)) {
|
||||
math_error("Division by zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
r = qalloc();
|
||||
if (!zisunit(q->num))
|
||||
@@ -861,7 +862,7 @@ qshift(NUMBER *q, long n)
|
||||
|
||||
if (qisfrac(q)) {
|
||||
math_error("Shift of non-integer");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q) || (n == 0))
|
||||
return qlink(q);
|
||||
@@ -954,7 +955,7 @@ qor(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
if (qisfrac(q1) || qisfrac(q2)) {
|
||||
math_error("Non-integers for bitwise or");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qcmp(q1,q2) == 0 || qiszero(q2))
|
||||
return qlink(q1);
|
||||
@@ -1003,7 +1004,7 @@ qand(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
if (qisfrac(q1) || qisfrac(q2)) {
|
||||
math_error("Non-integers for bitwise and");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qcmp(q1, q2) == 0)
|
||||
return qlink(q1);
|
||||
@@ -1053,7 +1054,7 @@ qxor(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
if (qisfrac(q1) || qisfrac(q2)) {
|
||||
math_error("Non-integers for bitwise xor");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qcmp(q1,q2) == 0)
|
||||
return qlink(&_qzero_);
|
||||
@@ -1106,7 +1107,7 @@ qandnot(NUMBER *q1, NUMBER *q2)
|
||||
|
||||
if (qisfrac(q1) || qisfrac(q2)) {
|
||||
math_error("Non-integers for bitwise xor");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qcmp(q1,q2) == 0 || qiszero(q1))
|
||||
return qlink(&_qzero_);
|
||||
@@ -1213,7 +1214,7 @@ qprecision(NUMBER *q)
|
||||
|
||||
if (qiszero(q) || qisneg(q)) {
|
||||
math_error("Non-positive number for precision");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
r = - qilog2(q);
|
||||
return (r < 0 ? 0 : r);
|
||||
@@ -1408,7 +1409,7 @@ qalloc(void)
|
||||
freeNum = (NUMBER *) malloc(sizeof (NUMBER) * NNALLOC);
|
||||
if (freeNum == NULL) {
|
||||
math_error("Not enough memory");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
freeNum[NNALLOC - 1].next = NULL;
|
||||
freeNum[NNALLOC - 1].links = 0;
|
||||
@@ -1438,7 +1439,7 @@ qalloc(void)
|
||||
}
|
||||
if (newfn == NULL) {
|
||||
math_error("Cannot allocate new number block");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
firstNums = newfn;
|
||||
firstNums[blockcount - 1] = freeNum;
|
||||
@@ -1457,11 +1458,11 @@ qfreenum(NUMBER *q)
|
||||
{
|
||||
if (q == NULL) {
|
||||
math_error("Calling qfreenum with null argument!!!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (q->links != 0) {
|
||||
math_error("Calling qfreenum with non-zero links!!!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
zfree(q->num);
|
||||
zfree(q->den);
|
||||
|
5
qmod.c
5
qmod.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* qmod - modular arithmetic routines for normal numbers and REDC numbers
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
|
||||
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
*
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "config.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -371,7 +372,7 @@ qfindredc(NUMBER *q)
|
||||
*/
|
||||
if (qisfrac(q) || qisneg(q)) {
|
||||
math_error("REDC modulus must be positive odd integer");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
bestrcp = NULL;
|
||||
|
73
qtrans.c
73
qtrans.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* qtrans - transcendental functions for real numbers
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
|
||||
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
*
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "qmath.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -209,7 +210,7 @@ qcos(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for cosine");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q))
|
||||
return qlink(&_qone_);
|
||||
@@ -236,7 +237,7 @@ qsin(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for sine");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
n = -qilog2(epsilon);
|
||||
if (qiszero(q) || n < 0)
|
||||
@@ -260,7 +261,7 @@ qtan(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for tangent");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q))
|
||||
return qlink(q);
|
||||
@@ -301,11 +302,11 @@ qcot(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for cotangent");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q)) {
|
||||
math_error("Zero argument for cotangent");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
k = -qilog2(q);
|
||||
n = qilog2(epsilon);
|
||||
@@ -347,7 +348,7 @@ qsec(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for secant");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q))
|
||||
return qlink(&_qone_);
|
||||
@@ -386,11 +387,11 @@ qcsc(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for cosecant");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q)) {
|
||||
math_error("Zero argument for cosecant");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
k = -qilog2(q);
|
||||
n = qilog2(epsilon);
|
||||
@@ -431,7 +432,7 @@ qasin(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for asin");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q))
|
||||
return qlink(&_qzero_);
|
||||
@@ -480,7 +481,7 @@ qacos(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for acos");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisone(q))
|
||||
return qlink(&_qzero_);
|
||||
@@ -526,7 +527,7 @@ qatan(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for arctangent");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q))
|
||||
return qlink(&_qzero_);
|
||||
@@ -569,7 +570,7 @@ qatan(NUMBER *q, NUMBER *epsilon)
|
||||
for (;;) {
|
||||
if (d > BASE) {
|
||||
math_error("Too many terms required for atan");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
zmul(X, mul, &ztmp1);
|
||||
zfree(X);
|
||||
@@ -644,7 +645,7 @@ qacot(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon for acot");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q)) {
|
||||
epsilon1 = qscale(epsilon, 1L);
|
||||
@@ -687,7 +688,7 @@ qatan2(NUMBER *qy, NUMBER *qx, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for atan2");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(qy) && qiszero(qx)) {
|
||||
/* conform to 4.3BSD ANSI/IEEE 754-1985 math lib */
|
||||
@@ -761,7 +762,7 @@ qpi(NUMBER *epsilon)
|
||||
/* firewall */
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("zero epsilon value for pi");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/* use pi cache if epsilon marches, else flush if needed */
|
||||
@@ -829,7 +830,7 @@ qpidiv180(NUMBER *epsilon)
|
||||
/* firewall */
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("zero epsilon value for qpidiv180");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/* use pi/180 cache if epsilon marches, else flush if needed */
|
||||
@@ -873,7 +874,7 @@ qpidiv200(NUMBER *epsilon)
|
||||
/* firewall */
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("zero epsilon value for qpidiv200");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/* use pi/200 cache if epsilon marches, else flush if needed */
|
||||
@@ -916,7 +917,7 @@ qexp(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for exp");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q))
|
||||
return qlink(&_qone_);
|
||||
@@ -1048,7 +1049,7 @@ qln(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(q) || qiszero(epsilon)) {
|
||||
math_error("logarithm of 0");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisunit(q))
|
||||
return qlink(&_qzero_);
|
||||
@@ -1160,7 +1161,7 @@ qlog(NUMBER *q, NUMBER *epsilon)
|
||||
/* firewall */
|
||||
if (qiszero(q) || qiszero(epsilon)) {
|
||||
math_error("logarithm of 0");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1236,11 +1237,11 @@ qpower(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon for power");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q1) && qisneg(q2)) {
|
||||
math_error("Negative power of zero");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q2) || qisone(q1))
|
||||
return qlink(&_qone_);
|
||||
@@ -1248,7 +1249,7 @@ qpower(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
|
||||
return qlink(&_qzero_);
|
||||
if (qisneg(q1)) {
|
||||
math_error("Negative base for qpower");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisone(q2))
|
||||
return qmappr(q1, epsilon, 24);
|
||||
@@ -1353,11 +1354,11 @@ qroot(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon for root");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisneg(q2) || qiszero(q2) || qisfrac(q2)) {
|
||||
math_error("Taking bad root of number");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q1) || qisone(q1) || qisone(q2))
|
||||
return qlink(q1);
|
||||
@@ -1367,7 +1368,7 @@ qroot(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
|
||||
if (neg) {
|
||||
if (ziseven(q2->num)) {
|
||||
math_error("Taking even root of negative number");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
q1 = qqabs(q1);
|
||||
}
|
||||
@@ -1510,11 +1511,11 @@ qcoth(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for coth");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q)) {
|
||||
math_error("Zero argument for coth");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
tmp1 = qscale(q, 1);
|
||||
tmp2 = qqabs(tmp1);
|
||||
@@ -1537,7 +1538,7 @@ qcoth(NUMBER *q, NUMBER *epsilon)
|
||||
qfree(tmp1);
|
||||
if (qiszero(tmp2)) {
|
||||
math_error("This should not happen ????");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
tmp1 = qinv(tmp2);
|
||||
qfree(tmp2);
|
||||
@@ -1564,7 +1565,7 @@ qsech(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for sech");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q))
|
||||
return qlink(&_qone_);
|
||||
@@ -1605,11 +1606,11 @@ qcsch(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for csch");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q)) {
|
||||
math_error("Zero argument for csch");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
n = qilog2(epsilon);
|
||||
@@ -1657,7 +1658,7 @@ qacosh(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for acosh");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qisone(q))
|
||||
return qlink(&_qzero_);
|
||||
@@ -1695,7 +1696,7 @@ qasinh(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for asinh");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q))
|
||||
return qlink(&_qzero_);
|
||||
@@ -1737,7 +1738,7 @@ qatanh(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for atanh");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (qiszero(q))
|
||||
return qlink(&_qzero_);
|
||||
|
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* http://www.isthe.com/chongo/tech/comp/fnv/index.html
|
||||
*
|
||||
* Copyright (C) 1999-2007,2014,2021 Landon Curt Noll
|
||||
* Copyright (C) 1999-2007,2014,2021,2022 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
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "zrandom.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -231,7 +232,7 @@ hashvalue(VALUE *vp, QCKHASH val)
|
||||
return blk_hash(vp->v_nblock->blk, val);
|
||||
default:
|
||||
math_error("Hashing unknown value");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return (QCKHASH)0;
|
||||
}
|
||||
@@ -438,6 +439,7 @@ config_hash(CONFIG *cfg, QCKHASH val)
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->pow2);
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->redc2);
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->tilde_ok);
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->tilde_space);
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->tab_ok);
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->quomod);
|
||||
value = (((value>>5) | (value<<27)) ^ (USB32)cfg->quo);
|
||||
|
16
rpm.mk
16
rpm.mk
@@ -1,9 +1,8 @@
|
||||
#!/bin/make
|
||||
#****h* calc/rpm.mk
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# rpm.mk - Makefile for building rpm packages for calc
|
||||
#
|
||||
# Copyright (C) 2003,2014,2021 Petteri Kettunen and Landon Curt Noll
|
||||
# Copyright (C) 2003,2014,2021,2023 Petteri Kettunen and 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
|
||||
@@ -63,7 +62,7 @@
|
||||
|
||||
# setup
|
||||
#
|
||||
SHELL= /bin/sh
|
||||
SHELL= bash
|
||||
RPMBUILD_TOOL= rpmbuild
|
||||
TARCH= x86_64
|
||||
RPMBUILD_OPTION= -ba --target=$(TARCH) --buildroot=${RPM_BUILD_ROOT}
|
||||
@@ -76,7 +75,6 @@ RM= rm
|
||||
LS= ls
|
||||
CPIO= cpio
|
||||
CP= cp
|
||||
EGREP= egrep
|
||||
MKDIR= mkdir
|
||||
GREP= grep
|
||||
SORT= sort
|
||||
@@ -172,8 +170,8 @@ srcpkg: make_rhdir
|
||||
${V} echo PROJECT_RELEASE="${PROJECT_RELEASE}"
|
||||
${RM} -rf "$(TMPDIR)/$(PROJECT)"
|
||||
${FIND} . -depth -print | \
|
||||
${EGREP} -v '/RCS|/CVS|/NOTES|/\.|\.out$$|\.safe$$\.tar\.bz2$$' | \
|
||||
${EGREP} -v '/old[._-]|\.old$$|\.tar\.gz$$|/ver_calc$$' | \
|
||||
${GREP} -E -v '/RCS|/CVS|/NOTES|/\.|\.out$$|\.safe$$\.tar\.bz2$$' | \
|
||||
${GREP} -E -v '/old[._-]|\.old$$|\.tar\.gz$$|/ver_calc$$' | \
|
||||
LANG=C ${SORT} | \
|
||||
${CPIO} -dumpv "$(TMPDIR)/$(PROJECT)"
|
||||
${RM} -f "$(TMPDIR)/$(PROJECT)/Makefile"
|
||||
@@ -278,8 +276,8 @@ chkpkg:
|
||||
.PHONY: chksys
|
||||
chksys:
|
||||
${V} echo '=-=-=-=-= rpm.mk start of $@ rule =-=-=-=-='
|
||||
${RPM_TOOL} -qa | ${GREP} "$(PROJECT_NAME)"
|
||||
${RPM_TOOL} -qa | ${GREP} "$(PROJECT_NAME)-devel"
|
||||
${RPM_TOOL} -qa | ${GREP} -E "$(PROJECT_NAME)"
|
||||
${RPM_TOOL} -qa | ${GREP} -E "$(PROJECT_NAME)-devel"
|
||||
${V} echo '=-=-=-=-= rpm.mk end of $@ rule =-=-=-=-='
|
||||
|
||||
.PHONY: test
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* sample_many - generate many random values via random number generator
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 Landon Curt Noll
|
||||
* Copyright (C) 1999-2007,2021,2022 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
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "lib_util.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -106,7 +107,7 @@ main(int argc, char **argv)
|
||||
prev_state = zsrandom2(seed, _one_);
|
||||
if (prev_state == NULL) {
|
||||
math_error("previous random state is NULL");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
randomfree(prev_state);
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* sample_rand - test the libcalc random number generator
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 Landon Curt Noll
|
||||
* Copyright (C) 1999-2007,2021,2022 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
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "lib_util.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -96,7 +97,7 @@ main(int argc, char **argv)
|
||||
prev_state = zsrandom2(seed, _ten_);
|
||||
if (prev_state == NULL) {
|
||||
math_error("previous random state is NULL");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
|
73
seed.c
73
seed.c
@@ -66,24 +66,30 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "have_times.h"
|
||||
|
||||
#if defined(HAVE_TIME_H)
|
||||
#include <time.h>
|
||||
#endif
|
||||
#endif /* HAVE_TIME_H */
|
||||
|
||||
#if defined(HAVE_SYS_TIME_H)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#endif /* HAVE_SYS_TIME_H */
|
||||
|
||||
#if defined(HAVE_SYS_TIMES_H)
|
||||
#include <sys/times.h>
|
||||
#endif
|
||||
#endif /* HAVE_SYS_TIMES_H */
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
# include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_STDLIB_H)
|
||||
# include <stdlib.h>
|
||||
/* NOTE: RANDOM_CNT should remain 32 to circular shift 31-bit returns */
|
||||
# define RANDOM_CNT (32) /* random() call repeat and circular shift */
|
||||
# define INITSTATE_SIZE (256) /* initstate pool size */
|
||||
#endif
|
||||
#endif /* HAVE_STDLIB_H */
|
||||
|
||||
#include <setjmp.h>
|
||||
#include "alloc.h"
|
||||
#include "qmath.h"
|
||||
@@ -98,15 +104,33 @@
|
||||
#include "have_uid_t.h"
|
||||
#include "have_environ.h"
|
||||
#include "have_arc4random.h"
|
||||
|
||||
#if defined(HAVE_USTAT)
|
||||
# include <ustat.h>
|
||||
#endif
|
||||
#endif /* HAVE_USTAT */
|
||||
|
||||
#if defined(HAVE_URANDOM)
|
||||
# include <fcntl.h>
|
||||
# define DEV_URANDOM "/dev/urandom"
|
||||
# define DEV_URANDOM_POOL (16)
|
||||
#endif
|
||||
#endif /* HAVE_URANDOM */
|
||||
|
||||
#include "have_sys_vfs.h"
|
||||
#if defined(HAVE_SYS_VFS_H)
|
||||
# include <sys/vfs.h>
|
||||
#endif /* HAVE_SYS_VFS_H */
|
||||
|
||||
#include "have_sys_param.h"
|
||||
#if defined(HAVE_SYS_PARAM_H)
|
||||
# include <sys/param.h>
|
||||
#endif /* HAVE_SYS_PARAM_H */
|
||||
|
||||
#include "have_sys_mount.h"
|
||||
#if defined(HAVE_SYS_MOUNT_H)
|
||||
# include <sys/mount.h>
|
||||
#endif /* HAVE_SYS_MOUNT_H */
|
||||
|
||||
#include "have_statfs.h"
|
||||
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
@@ -417,6 +441,25 @@ pseudo_seed(void)
|
||||
/* usage stat of "/var/log/messages" */
|
||||
struct ustat ustat_messages;
|
||||
#endif
|
||||
#if defined(HAVE_STATFS)
|
||||
struct statfs statfs_dot; /* filesystem stat of "." */
|
||||
struct statfs statfs_dotdot; /* filesystem stat of ".." */
|
||||
struct statfs statfs_tmp; /* filesystem stat of "/tmp" */
|
||||
struct statfs statfs_root; /* filesystem stat of "/" */
|
||||
struct statfs statfs_tty; /* filesystem stat of "/dev/tty" */
|
||||
struct statfs statfs_console; /* filesystem stat of "/dev/console" */
|
||||
struct statfs statfs_stdin; /* filesystem stat of stdin */
|
||||
struct statfs statfs_stdout; /* filesystem stat of stdout */
|
||||
struct statfs statfs_stderr; /* filesystem stat of stderr */
|
||||
struct statfs statfs_zero; /* filesystem stat of "/dev/zero" */
|
||||
struct statfs statfs_null; /* filesystem stat of "/dev/null" */
|
||||
struct statfs statfs_sh; /* filesystem stat of "/bin/sh" */
|
||||
struct statfs statfs_ls; /* filesystem stat of "/bin/ls" */
|
||||
/* filesystem stat of "/var/log/system.log" */
|
||||
struct statfs statfs_system;
|
||||
/* filesystem stat of "/var/log/messages" */
|
||||
struct statfs statfs_messages;
|
||||
#endif
|
||||
#if defined(HAVE_GETSID)
|
||||
pid_t getsid; /* session ID */
|
||||
#endif
|
||||
@@ -559,6 +602,23 @@ pseudo_seed(void)
|
||||
(void) ustat(sdata.stat_system.st_dev, &sdata.ustat_system);
|
||||
(void) ustat(sdata.stat_messages.st_dev, &sdata.ustat_messages);
|
||||
#endif
|
||||
#if defined(HAVE_STATFS)
|
||||
(void) statfs("..", &sdata.statfs_dot);
|
||||
(void) statfs(".", &sdata.statfs_dotdot);
|
||||
(void) statfs("/tmp", &sdata.statfs_tmp);
|
||||
(void) statfs("/", &sdata.statfs_root);
|
||||
(void) statfs("/dev/tty", &sdata.statfs_tty);
|
||||
(void) statfs("/dev/console", &sdata.statfs_console);
|
||||
(void) statfs(".dev/stdin", &sdata.statfs_stdin);
|
||||
(void) statfs("/dev/stdout", &sdata.statfs_stdout);
|
||||
(void) statfs("/dev/stderr", &sdata.statfs_stderr);
|
||||
(void) statfs("/dev/zero", &sdata.statfs_zero);
|
||||
(void) statfs("/dev/null", &sdata.statfs_null);
|
||||
(void) statfs("/bin/sh", &sdata.statfs_sh);
|
||||
(void) statfs("/dev/ls", &sdata.statfs_ls);
|
||||
(void) statfs("/var/log/system.log", &sdata.statfs_system);
|
||||
(void) statfs("/var/log/messages", &sdata.statfs_messages);
|
||||
#endif
|
||||
#if defined(HAVE_GETSID)
|
||||
sdata.getsid = getsid((pid_t)0);
|
||||
#endif
|
||||
@@ -592,7 +652,6 @@ pseudo_seed(void)
|
||||
sdata.size = sizeof(sdata);
|
||||
sdata.prev_hash64_copy = prev_hash64; /* load previous hash */
|
||||
sdata.call_count_copy = ++call_count; /* update call count */
|
||||
(void) setjmp(sdata.env);
|
||||
#if defined(HAVE_ENVIRON)
|
||||
sdata.environ_copy = environ;
|
||||
#endif /* HAVE_ENVIRON */
|
||||
|
54
sha1.c
54
sha1.c
@@ -3,26 +3,37 @@
|
||||
*
|
||||
* Written 2 September 1992, Peter C. Gutmann.
|
||||
*
|
||||
* This file has been extensively modified by:
|
||||
*
|
||||
* Landon Curt Noll
|
||||
* http://www.isthe.com/chongo/
|
||||
*
|
||||
* chongo <was here> /\../\
|
||||
*
|
||||
* This code has been placed in the public domain. Please do not
|
||||
* copyright this code.
|
||||
*
|
||||
* LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER-
|
||||
* CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT
|
||||
* NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* This file is not covered under version 2.1 of the GNU LGPL.
|
||||
* This file is covered under "The unlicense":
|
||||
*
|
||||
* https://unlicense.org
|
||||
*
|
||||
* In particular:
|
||||
*
|
||||
* This is free and unencumbered software released into the public domain.
|
||||
*
|
||||
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
* distribute this software, either in source code form or as a compiled
|
||||
* binary, for any purpose, commercial or non-commercial, and by any
|
||||
* means.
|
||||
*
|
||||
* In jurisdictions that recognize copyright laws, the author or authors
|
||||
* of this software dedicate any and all copyright interest in the
|
||||
* software to the public domain. We make this dedication for the benefit
|
||||
* of the public at large and to the detriment of our heirs and
|
||||
* successors. We intend this dedication to be an overt act of
|
||||
* relinquishment in perpetuity of all present and future rights to this
|
||||
* software under copyright law.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* For more information, please refer to <http://unlicense.org/>
|
||||
*/
|
||||
|
||||
|
||||
@@ -36,6 +47,7 @@
|
||||
#include "sha1.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -367,7 +379,7 @@ sha1Final(HASH *state)
|
||||
} else {
|
||||
if (count % 4) {
|
||||
math_error("This should not happen in sha1Final");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
data[count + 3] = 0x80;
|
||||
}
|
||||
@@ -563,7 +575,7 @@ sha1_final_state(HASH *state)
|
||||
state = (HASH *)malloc(sizeof(HASH));
|
||||
if (state == NULL) {
|
||||
math_error("cannot malloc HASH");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
sha1_init_state(state);
|
||||
}
|
||||
|
49
sha1.h
49
sha1.h
@@ -3,26 +3,37 @@
|
||||
*
|
||||
* Written 2 September 1992, Peter C. Gutmann.
|
||||
*
|
||||
* This file and been extensively modified by:
|
||||
*
|
||||
* Landon Curt Noll
|
||||
* http://www.isthe.com/chongo/
|
||||
*
|
||||
* chongo <was here> /\../\
|
||||
*
|
||||
* This code has been placed in the public domain. Please do not
|
||||
* copyright this code.
|
||||
*
|
||||
* LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER-
|
||||
* CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT
|
||||
* NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* This file is not covered under version 2.1 of the GNU LGPL.
|
||||
* This file is covered under "The unlicense":
|
||||
*
|
||||
* https://unlicense.org
|
||||
*
|
||||
* In particular:
|
||||
*
|
||||
* This is free and unencumbered software released into the public domain.
|
||||
*
|
||||
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
* distribute this software, either in source code form or as a compiled
|
||||
* binary, for any purpose, commercial or non-commercial, and by any
|
||||
* means.
|
||||
*
|
||||
* In jurisdictions that recognize copyright laws, the author or authors
|
||||
* of this software dedicate any and all copyright interest in the
|
||||
* software to the public domain. We make this dedication for the benefit
|
||||
* of the public at large and to the detriment of our heirs and
|
||||
* successors. We intend this dedication to be an overt act of
|
||||
* relinquishment in perpetuity of all present and future rights to this
|
||||
* software under copyright law.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* For more information, please refer to <http://unlicense.org/>
|
||||
*/
|
||||
|
||||
|
||||
|
7
size.c
7
size.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* size - size and sizeof functions are implemented here
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell
|
||||
* Copyright (C) 1999-2007,2021,2022 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
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "block.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -316,7 +317,7 @@ lsizeof(VALUE *vp)
|
||||
break;
|
||||
default:
|
||||
math_error("sizeof not defined for value type");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
return s;
|
||||
@@ -436,7 +437,7 @@ memsize(VALUE *vp)
|
||||
break;
|
||||
default:
|
||||
math_error("memsize not defined for value type");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
return s;
|
||||
|
39
str.c
39
str.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* str - string list routines
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
|
||||
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
*
|
||||
@@ -38,11 +38,12 @@
|
||||
#include "strl.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
#define STR_TABLECHUNK 100 /* how often to reallocate string table */
|
||||
#define STR_CHUNK (1<<11) /* size of string storage allocation */
|
||||
#define STR_TABLECHUNK (1<<10) /* how often to reallocate string table */
|
||||
#define STR_CHUNK (1<<16) /* size of string storage allocation */
|
||||
#define OCTET_VALUES 256 /* number of different values in a OCTET */
|
||||
#define STR_UNIQUE (1<<7) /* size of string to allocate separately */
|
||||
|
||||
@@ -73,7 +74,7 @@ initstr(STRINGHEAD *hp)
|
||||
hp->h_list = (char *)malloc(STR_CHUNK + 1);
|
||||
if (hp->h_list == NULL) {
|
||||
math_error("Cannot allocate string header");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
hp->h_list[STR_CHUNK] = '\0'; /* guard paranoia */
|
||||
hp->h_avail = STR_CHUNK;
|
||||
@@ -144,7 +145,7 @@ charstr(int ch)
|
||||
cp = (char *)malloc((OCTET_VALUES + 1)*2);
|
||||
if (cp == NULL) {
|
||||
math_error("Cannot allocate character table");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
for (i = 0; i < OCTET_VALUES; i++) {
|
||||
*cp++ = (char)i;
|
||||
@@ -295,7 +296,7 @@ addliteral(char *str)
|
||||
}
|
||||
if (table == NULL) {
|
||||
math_error("Cannot allocate string literal table");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
literals.l_table = table;
|
||||
literals.l_maxcount = count;
|
||||
@@ -314,7 +315,7 @@ addliteral(char *str)
|
||||
newstr = (char *)malloc(len + 1);
|
||||
if (newstr == NULL) {
|
||||
math_error("Cannot allocate large literal string");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
newstr[len] = '\0'; /* guard paranoia */
|
||||
strlcpy(newstr, str, len);
|
||||
@@ -330,7 +331,7 @@ addliteral(char *str)
|
||||
newstr = (char *)malloc(STR_CHUNK + 1);
|
||||
if (newstr == NULL) {
|
||||
math_error("Cannot allocate new literal string");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
newstr[STR_CHUNK] = '\0'; /* guard paranoia */
|
||||
literals.l_alloc = newstr;
|
||||
@@ -1128,7 +1129,7 @@ stralloc(void)
|
||||
freeStr = (STRING *) malloc(sizeof (STRING) * (STRALLOC + 1));
|
||||
if (freeStr == NULL) {
|
||||
math_error("Unable to allocate memory for stralloc");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
/* guard paranoia */
|
||||
memset(freeStr+STRALLOC, 0, sizeof(STRING));
|
||||
@@ -1166,7 +1167,7 @@ stralloc(void)
|
||||
}
|
||||
if (newfn == NULL) {
|
||||
math_error("Cannot allocate new string block");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
firstStrs = newfn;
|
||||
firstStrs[blockcount - 1] = freeStr;
|
||||
@@ -1204,7 +1205,7 @@ charstring(int ch)
|
||||
c = (char *) malloc(2);
|
||||
if (c == NULL) {
|
||||
math_error("Allocation failure for charstring");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
s = stralloc();
|
||||
s->s_len = 1;
|
||||
@@ -1232,7 +1233,7 @@ makenewstring(char *str)
|
||||
c = (char *) malloc(len + 1);
|
||||
if (c == NULL) {
|
||||
math_error("malloc for makenewstring failed");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
s = stralloc();
|
||||
s->s_str = c;
|
||||
@@ -1256,7 +1257,7 @@ stringcopy (STRING *s1)
|
||||
c = malloc(len + 1);
|
||||
if (c == NULL) {
|
||||
math_error("Malloc failed for stringcopy");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
s = stralloc();
|
||||
s->s_len = len;
|
||||
@@ -1272,7 +1273,7 @@ slink(STRING *s)
|
||||
{
|
||||
if (s->s_links <= 0) {
|
||||
math_error("Argument for slink has non-positive links!!!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
++s->s_links;
|
||||
return s;
|
||||
@@ -1284,7 +1285,7 @@ sfree(STRING *s)
|
||||
{
|
||||
if (s->s_links <= 0) {
|
||||
math_error("Argument for sfree has non-positive links!!!");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
if (--s->s_links > 0 || s->s_len == 0)
|
||||
return;
|
||||
@@ -1306,7 +1307,7 @@ initstrings(void)
|
||||
malloc(sizeof(STRING *) * (STRCONSTALLOC + 1));
|
||||
if (stringconsttable == NULL) {
|
||||
math_error("Unable to allocate constant table");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
stringconsttable[STRCONSTALLOC] = NULL; /* guard paranoia */
|
||||
stringconsttable[0] = &_nullstring_;
|
||||
@@ -1343,7 +1344,7 @@ addstring(char *str, size_t len)
|
||||
if (sp == NULL) {
|
||||
math_error("Unable to reallocate string "
|
||||
"const table");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
/* guard paranoia */
|
||||
sp[stringconstcount + STRCONSTALLOC] = NULL;
|
||||
@@ -1373,7 +1374,7 @@ addstring(char *str, size_t len)
|
||||
c = (char *) malloc(len + 1);
|
||||
if (c == NULL) {
|
||||
math_error("Unable to allocate string constant memory");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
s->s_str = c;
|
||||
s->s_len = len;
|
||||
@@ -1393,7 +1394,7 @@ findstring(long index)
|
||||
{
|
||||
if (index < 0 || index >= stringconstcount) {
|
||||
math_error("Bad index for findstring");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return stringconsttable[index];
|
||||
}
|
||||
|
9
symbol.c
9
symbol.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* symbol - global and local symbol routines
|
||||
*
|
||||
* Copyright (C) 1999-2007,2021 David I. Bell and Ernest Bowen
|
||||
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
*
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "func.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -372,7 +373,6 @@ freeglobals(void)
|
||||
{
|
||||
GLOBAL **hp; /* hash table head address */
|
||||
GLOBAL *sp; /* current global symbol pointer */
|
||||
long count; /* number of global variables freed */
|
||||
|
||||
/*
|
||||
* We prevent the hp pointer from walking behind globalhash
|
||||
@@ -383,12 +383,10 @@ freeglobals(void)
|
||||
* short and running the loop one last time manually helps make
|
||||
* code checkers such as insure happy.
|
||||
*/
|
||||
count = 0;
|
||||
for (hp = &globalhash[HASHSIZE-1]; hp > globalhash; hp--) {
|
||||
for (sp = *hp; sp; sp = sp->g_next) {
|
||||
if (sp->g_value.v_type != V_NULL) {
|
||||
freevalue(&sp->g_value);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -396,7 +394,6 @@ freeglobals(void)
|
||||
for (sp = *hp; sp; sp = sp->g_next) {
|
||||
if (sp->g_value.v_type != V_NULL) {
|
||||
freevalue(&sp->g_value);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -539,7 +536,7 @@ addstatic(GLOBAL *sp)
|
||||
(20 + staticcount) * sizeof(GLOBAL *));
|
||||
if (stp == NULL) {
|
||||
math_error("Cannot allocate static-variable table");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
statictable = stp;
|
||||
staticavail = 20;
|
||||
|
11
token.c
11
token.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* token - read input file characters into tokens
|
||||
*
|
||||
* Copyright (C) 1999-2007,2017,2021 David I. Bell and Ernest Bowen
|
||||
* Copyright (C) 1999-2007,2017,2021,2022 David I. Bell and Ernest Bowen
|
||||
*
|
||||
* Primary author: David I. Bell
|
||||
*
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "lib_calc.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -537,7 +538,7 @@ eatstring(int quotechar)
|
||||
str = (char *) malloc(len);
|
||||
if (str == NULL) {
|
||||
math_error("Out of memory for reading tokens");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
memcpy(str + totlen, buf, len);
|
||||
totlen += len;
|
||||
@@ -628,7 +629,7 @@ eatnumber(void)
|
||||
cp = (char *)realloc(numbuf, numbufsize + 1001);
|
||||
if (cp == NULL) {
|
||||
math_error("Cannot reallocate number buffer");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
numbuf = cp;
|
||||
numbufsize += 1000;
|
||||
@@ -745,7 +746,7 @@ scanerror(int skip, char *fmt, ...)
|
||||
if ((!c_flag && !stoponerror) || stoponerror > 0) {
|
||||
if (calc_use_scanerr_jmpbuf != 0) {
|
||||
longjmp(calc_scanerr_jmpbuf, 60);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"calc_scanerr_jmpbuf not setup, exiting code 60\n");
|
||||
@@ -759,7 +760,7 @@ scanerror(int skip, char *fmt, ...)
|
||||
fprintf(stderr, "Too many scan errors, compilation aborted.\n");
|
||||
if (calc_use_scanerr_jmpbuf != 0) {
|
||||
longjmp(calc_scanerr_jmpbuf, 61);
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"calc_scanerr_jmpbuf not ready: exit 61\n");
|
||||
|
4
token.h
4
token.h
@@ -175,8 +175,8 @@ E_FUNC void inittokens(void);
|
||||
E_FUNC int tokenmode(int flag);
|
||||
E_FUNC int gettoken(void);
|
||||
E_FUNC void rescantoken(void);
|
||||
E_FUNC void scanerror(int, char *, ...) PRINTF_FORMAT(2, 3);
|
||||
E_FUNC void warning(char *, ...) PRINTF_FORMAT(1, 2);
|
||||
E_FUNC void scanerror(int, char *, ...) __attribute__((format(printf, 2, 3)));
|
||||
E_FUNC void warning(char *, ...) __attribute__((format(printf, 1, 2)));
|
||||
|
||||
|
||||
#endif /* !INCLUDE_TOKEN_H */
|
||||
|
74
value.c
74
value.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* value - generic value manipulation routines
|
||||
*
|
||||
* Copyright (C) 1999-2007,2014,2017,2021 David I. Bell
|
||||
* Copyright (C) 1999-2007,2014,2017,2021,2022 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
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "config.h"
|
||||
|
||||
|
||||
#include "attribute.h"
|
||||
#include "banned.h" /* include after system header <> includes */
|
||||
|
||||
|
||||
@@ -109,7 +110,7 @@ freevalue(VALUE *vp)
|
||||
break;
|
||||
default:
|
||||
math_error("Freeing unknown value type");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +243,7 @@ copyvalue(VALUE *oldvp, VALUE *newvp)
|
||||
break;
|
||||
default:
|
||||
math_error("Copying unknown value type");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
newvp->v_subtype = oldvp->v_subtype;
|
||||
@@ -376,6 +377,7 @@ negvalue(VALUE *vp, VALUE *vres)
|
||||
void
|
||||
addvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
{
|
||||
unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */
|
||||
COMPLEX *c;
|
||||
VALUE tmp;
|
||||
NUMBER *q;
|
||||
@@ -402,7 +404,8 @@ addvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
return;
|
||||
}
|
||||
vres->v_type = v1->v_type;
|
||||
switch (TWOVAL(v1->v_type, v2->v_type)) {
|
||||
twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type);
|
||||
switch (twoval_as_uint) {
|
||||
case TWOVAL(V_NUM, V_NUM):
|
||||
vres->v_num = qqadd(v1->v_num, v2->v_num);
|
||||
return;
|
||||
@@ -434,7 +437,7 @@ addvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
q = v2->v_num;
|
||||
if (qisfrac(q)) {
|
||||
math_error("Adding non-integer to address");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
i = qtoi(q);
|
||||
vres->v_addr = v1->v_addr + i;
|
||||
@@ -444,7 +447,7 @@ addvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
q = v2->v_num;
|
||||
if (qisfrac(q)) {
|
||||
math_error("Adding non-integer to address");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
i = qtoi(q);
|
||||
vres->v_octet = v1->v_octet + i;
|
||||
@@ -473,13 +476,15 @@ addvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
void
|
||||
subvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
{
|
||||
unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */
|
||||
COMPLEX *c;
|
||||
NUMBER *q;
|
||||
int i;
|
||||
|
||||
vres->v_type = v1->v_type;
|
||||
vres->v_subtype = V_NOSUBTYPE;
|
||||
switch (TWOVAL(v1->v_type, v2->v_type)) {
|
||||
twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type);
|
||||
switch (twoval_as_uint) {
|
||||
case TWOVAL(V_NUM, V_NUM):
|
||||
vres->v_num = qsub(v1->v_num, v2->v_num);
|
||||
return;
|
||||
@@ -513,7 +518,7 @@ subvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
q = v2->v_num;
|
||||
if (qisfrac(q)) {
|
||||
math_error("Subtracting non-integer from address");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
i = qtoi(q);
|
||||
vres->v_addr = v1->v_addr - i;
|
||||
@@ -523,7 +528,7 @@ subvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
q = v2->v_num;
|
||||
if (qisfrac(q)) {
|
||||
math_error("Adding non-integer to address");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
i = qtoi(q);
|
||||
vres->v_octet = v1->v_octet - i;
|
||||
@@ -561,11 +566,13 @@ subvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
void
|
||||
mulvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
{
|
||||
unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */
|
||||
COMPLEX *c;
|
||||
|
||||
vres->v_type = v1->v_type;
|
||||
vres->v_subtype = V_NOSUBTYPE;
|
||||
switch (TWOVAL(v1->v_type, v2->v_type)) {
|
||||
twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type);
|
||||
switch (twoval_as_uint) {
|
||||
case TWOVAL(V_NUM, V_NUM):
|
||||
vres->v_num = qmul(v1->v_num, v2->v_num);
|
||||
return;
|
||||
@@ -726,6 +733,8 @@ invertvalue(VALUE *vp, VALUE *vres)
|
||||
void
|
||||
andvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
{
|
||||
unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */
|
||||
|
||||
vres->v_subtype = V_NOSUBTYPE;
|
||||
if (v1->v_type == V_NULL) {
|
||||
copyvalue(v2, vres);
|
||||
@@ -736,7 +745,8 @@ andvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
return;
|
||||
}
|
||||
vres->v_type = v1->v_type;
|
||||
switch (TWOVAL(v1->v_type, v2->v_type)) {
|
||||
twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type);
|
||||
switch (twoval_as_uint) {
|
||||
case TWOVAL(V_NUM, V_NUM):
|
||||
vres->v_num = qand(v1->v_num, v2->v_num);
|
||||
return;
|
||||
@@ -782,6 +792,8 @@ andvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
void
|
||||
orvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
{
|
||||
unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */
|
||||
|
||||
if (v1->v_type == V_NULL) {
|
||||
copyvalue(v2, vres);
|
||||
return;
|
||||
@@ -792,7 +804,8 @@ orvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
}
|
||||
vres->v_type = v1->v_type;
|
||||
vres->v_subtype = V_NOSUBTYPE;
|
||||
switch (TWOVAL(v1->v_type, v2->v_type)) {
|
||||
twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type);
|
||||
switch (twoval_as_uint) {
|
||||
case TWOVAL(V_NUM, V_NUM):
|
||||
vres->v_num = qor(v1->v_num, v2->v_num);
|
||||
return;
|
||||
@@ -839,9 +852,12 @@ orvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
void
|
||||
xorvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
{
|
||||
unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */
|
||||
|
||||
vres->v_type = v1->v_type;
|
||||
vres->v_subtype = V_NOSUBTYPE;
|
||||
switch (TWOVAL(v1->v_type, v2->v_type)) {
|
||||
twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type);
|
||||
switch (twoval_as_uint) {
|
||||
case (TWOVAL(V_NUM, V_NUM)):
|
||||
vres->v_num = qxor(v1->v_num, v2->v_num);
|
||||
return;
|
||||
@@ -885,11 +901,13 @@ xorvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
void
|
||||
hashopvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
{
|
||||
unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */
|
||||
NUMBER *q;
|
||||
|
||||
vres->v_type = v1->v_type;
|
||||
vres->v_subtype = V_NOSUBTYPE;
|
||||
switch (TWOVAL(v1->v_type, v2->v_type)) {
|
||||
twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type);
|
||||
switch (twoval_as_uint) {
|
||||
case TWOVAL(V_NUM, V_NUM):
|
||||
q = qsub(v1->v_num, v2->v_num);
|
||||
vres->v_num = qqabs(q);
|
||||
@@ -951,9 +969,12 @@ backslashvalue(VALUE *vp, VALUE *vres)
|
||||
void
|
||||
setminusvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
{
|
||||
unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */
|
||||
|
||||
vres->v_type = v1->v_type;
|
||||
vres->v_subtype = V_NOSUBTYPE;
|
||||
switch (TWOVAL(v1->v_type, v2->v_type)) {
|
||||
twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type);
|
||||
switch (twoval_as_uint) {
|
||||
case TWOVAL(V_NUM, V_NUM):
|
||||
vres->v_num = qandnot(v1->v_num, v2->v_num);
|
||||
return;
|
||||
@@ -1883,9 +1904,14 @@ powvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
*vres = error_value(E_1OVER0);
|
||||
break;
|
||||
}
|
||||
/* 0 ^ non-neg is 1, including 0^0 */
|
||||
vres->v_type = V_NUM;
|
||||
vres->v_num = qlink(&_qone_);
|
||||
if (qiszero(v2->v_num)) {
|
||||
/* 0 ^ 0 is 1 */
|
||||
vres->v_num = qlink(&_qone_);
|
||||
} else {
|
||||
/* 0 ^ (exp>0) is 0 */
|
||||
vres->v_num = qlink(&_qzero_);
|
||||
}
|
||||
} else if (qisint(real_v2)) {
|
||||
vres->v_num = qpowi(v1->v_num, real_v2);
|
||||
} else {
|
||||
@@ -2004,6 +2030,7 @@ powvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
void
|
||||
powervalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres)
|
||||
{
|
||||
unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */
|
||||
NUMBER *epsilon;
|
||||
COMPLEX *c, ctmp1, ctmp2;
|
||||
|
||||
@@ -2036,7 +2063,8 @@ powervalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres)
|
||||
return;
|
||||
}
|
||||
|
||||
switch (TWOVAL(v1->v_type, v2->v_type)) {
|
||||
twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type);
|
||||
switch (twoval_as_uint) {
|
||||
case TWOVAL(V_NUM, V_NUM):
|
||||
if (qisneg(v1->v_num)) {
|
||||
ctmp1.real = v1->v_num;
|
||||
@@ -2092,6 +2120,7 @@ powervalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres)
|
||||
void
|
||||
divvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
{
|
||||
unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */
|
||||
COMPLEX *c;
|
||||
COMPLEX ctmp;
|
||||
NUMBER *q;
|
||||
@@ -2118,7 +2147,8 @@ divvalue(VALUE *v1, VALUE *v2, VALUE *vres)
|
||||
return;
|
||||
}
|
||||
vres->v_type = v1->v_type;
|
||||
switch (TWOVAL(v1->v_type, v2->v_type)) {
|
||||
twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type);
|
||||
switch (twoval_as_uint) {
|
||||
case TWOVAL(V_NUM, V_NUM):
|
||||
vres->v_num = qqdiv(v1->v_num, v2->v_num);
|
||||
return;
|
||||
@@ -2474,7 +2504,7 @@ comparevalue(VALUE *v1, VALUE *v2)
|
||||
return (v1->v_num != v2->v_num);
|
||||
default:
|
||||
math_error("Illegal values for comparevalue");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
return (r != 0);
|
||||
}
|
||||
@@ -2859,7 +2889,7 @@ printvalue(VALUE *vp, int flags)
|
||||
break;
|
||||
default:
|
||||
math_error("Printing unrecognized type of value");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2996,7 +3026,7 @@ config_print(CONFIG *cfg)
|
||||
if (cfg == NULL || cfg->epsilon == NULL || cfg->prompt1 == NULL ||
|
||||
cfg->prompt2 == NULL) {
|
||||
math_error("CONFIG value is invalid");
|
||||
/*NOTREACHED*/
|
||||
not_reached();
|
||||
}
|
||||
|
||||
/*
|
||||
|
44
value.h
44
value.h
@@ -167,7 +167,8 @@ struct value {
|
||||
#define V_OPTR 19 /* octet address as pointer */
|
||||
#define V_SPTR 20 /* string address as pointer */
|
||||
#define V_NPTR 21 /* number address as pointer */
|
||||
#define V_MAX 21 /* highest legal value */
|
||||
|
||||
#define V_MAX V_NPTR /* highest legal value - must be last and match highest V_something value */
|
||||
|
||||
#define V_NOSUBTYPE 0 /* subtype has no meaning */
|
||||
#define V_NOASSIGNTO 1 /* protection status 1 */
|
||||
@@ -189,7 +190,46 @@ struct value {
|
||||
*/
|
||||
|
||||
|
||||
#define TWOVAL(a,b) ((a) << 5 | (b)) /* for switch of two values */
|
||||
/*
|
||||
* NOTE: The shift of 8 in TWOVAL() macro below assumes V_MAX < 1<<8
|
||||
*
|
||||
* The macro TWOVAL_ARGS_OK(a,b) will return true if both a and b are in range,
|
||||
* otherwise it will return false.
|
||||
*
|
||||
* The TWOVAL_INVALID is a value that TWOVAL_ARGS_OK(a,b) is true,
|
||||
* will never match a TWOVAL(a,b) value (i.e., using V_something defined values).
|
||||
*
|
||||
* The TWOVAL_AS_UINT(a,b) may be assigned to a unsigned int value so that
|
||||
* with one switches on that unsigned int, cases with a and/or b being
|
||||
* out of range will fall into the default (non-matching) case.
|
||||
*
|
||||
* unsigned int twoval_as_uint;
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* twoval_as_uint = TWOVAL_AS_UINT(a,b);
|
||||
* switch (twoval_as_uint) {
|
||||
* case TWOVAL(V_INT,V_INT):
|
||||
* ...
|
||||
* break;
|
||||
* case TWOVAL(V_INT,V_NUM):
|
||||
* ...
|
||||
* break;
|
||||
* default:
|
||||
* ...
|
||||
* break;
|
||||
* }
|
||||
*
|
||||
* If a is NOT 0 <= a <= V_MAX or if b is NOT 0 <= b <= V_MAX,
|
||||
* when () macro returns -1 (all bits set) in order to
|
||||
* not match and true TWOVAL() macro combination that uses
|
||||
* uses a V_something defined value above.
|
||||
*/
|
||||
|
||||
#define TWOVAL(a,b) ((unsigned int)(((a) << 8) | (b))) /* logical OR for switch of two V_something values */
|
||||
#define TWOVAL_ARGS_OK(a,b) (((a) >= 0) && ((a) <= V_MAX) && ((b) >= 0) && ((b) <= V_MAX))
|
||||
#define TWOVAL_INVALID ((unsigned int)(-1)) /* never a valid TWOVAL(a,b) value when a and b are in range */
|
||||
#define TWOVAL_AS_UINT(a,b) (TWOVAL_ARGS_OK(a,b) ? TWOVAL(a,b) : TWOVAL_INVALID)
|
||||
|
||||
#define NULL_VALUE ((VALUE *) 0)
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user