mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Compare commits
379 Commits
2.12.5.6
...
prod-2.14.
Author | SHA1 | Date | |
---|---|---|---|
|
28449fd187 | ||
|
d88b128b2d | ||
|
bc048bc029 | ||
|
4d32b138ed | ||
|
3cd8fd7053 | ||
|
b0f19c1011 | ||
|
fe520975cf | ||
|
f097dd7dc1 | ||
|
3a7e763b28 | ||
|
661e99829e | ||
|
faf3a4fab6 | ||
|
7d8d4cb5ea | ||
|
af9b052fe9 | ||
|
40f8654aa4 | ||
|
92c8d89ed1 | ||
|
1e2d02e449 | ||
|
e0df1646fc | ||
|
ee900ec6ec | ||
|
6ee34e709d | ||
|
f81d67b322 | ||
|
21ab25d1c9 | ||
|
06dcb3e51e | ||
|
6e0e48e17e | ||
|
f416973a31 | ||
|
b408b59d8d | ||
|
77405e1d84 | ||
|
da623e13cb | ||
|
f025dcf0d8 | ||
|
3bfcaae767 | ||
|
bf5b56d263 | ||
|
0b044ce972 | ||
|
e2686911ae | ||
|
544b873914 | ||
|
948d9e807b | ||
|
6d020b7fbe | ||
|
9fcdd80549 | ||
|
3148ce06a0 | ||
|
945977f1f4 | ||
|
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 | ||
|
ee70c12481 | ||
|
d4970d66ce | ||
|
c3ea3d28a4 | ||
|
3fa34dabfe | ||
|
ffd4422870 | ||
|
b5b2c3f812 | ||
|
f7dadbf1f8 | ||
|
22e123140c | ||
|
1242700601 | ||
|
5b7dfeaf11 | ||
|
b3c015d338 | ||
|
5985ad2f33 | ||
|
e401c9abf1 | ||
|
ad79b6384d | ||
|
862dbd6777 | ||
|
0d31eb6828 | ||
|
c0be37d4e3 | ||
|
4344532c28 | ||
|
0f6efb29bb | ||
|
39c0cba1ca | ||
|
a68e41248f | ||
|
e213cc5072 | ||
|
95ebb60619 | ||
|
e5c8f00adc | ||
|
265713778f | ||
|
4b08a896b0 | ||
|
44f3778af1 | ||
|
8db8f93ae0 | ||
|
e688c22c0e | ||
|
af72992ead | ||
|
9f3a7817d3 | ||
|
dd0610db0a | ||
|
177a5d00d1 | ||
|
a02f8aa9f9 | ||
|
b7d1fb096d | ||
|
48c4f3b948 | ||
|
2023175fcc | ||
|
c54e2648dc | ||
|
faf40b7149 | ||
|
4b2ae40c86 | ||
|
af57104e25 | ||
|
5ae3ca059a | ||
|
cc5fb9a45b | ||
|
5dcadad8b6 | ||
|
9c67ceeed8 | ||
|
7ffbaf922e | ||
|
f9464652fe | ||
|
b30c5c1855 | ||
|
7417f2e776 | ||
|
71138215a9 | ||
|
241f777d07 | ||
|
9d27f0aaa7 | ||
|
a28edba4e9 | ||
|
de47c960d3 | ||
|
c3a51f42e2 | ||
|
f5c5cea8b0 | ||
|
769ac51f8c | ||
|
cdda633369 | ||
|
50f349f4d7 | ||
|
ef00e00328 | ||
|
bb041098bc | ||
|
f794b8d859 | ||
|
bd990cef1f | ||
|
febb9d96b3 | ||
|
13ae9b804e | ||
|
56cc4897d6 | ||
|
eb940e0a21 | ||
|
f3adb35e36 | ||
|
d1d365d7ba | ||
|
af214b166d | ||
|
51b933dfff | ||
|
c4e5007587 | ||
|
c838798f04 | ||
|
23d49a41fe | ||
|
3d300acca1 | ||
|
8f449ba6d2 | ||
|
f4d754b47d | ||
|
fde724aa2d | ||
|
e411a3e6bf | ||
|
7db81649b0 | ||
|
08fe6f13f4 | ||
|
e11d159c81 | ||
|
dfd66be871 | ||
|
27f977b545 | ||
|
2ca6e789ca | ||
|
ff8f921ebc | ||
|
005b78227a | ||
|
b7a42a9d3d | ||
|
3d1e938cb6 | ||
|
8b98a7c1f6 | ||
|
dbf5acf5e8 | ||
|
5fe5ab1c4b | ||
|
e0cd9bb3db | ||
|
f0f6171354 | ||
|
94861cc6d2 | ||
|
286233e28f | ||
|
99ac7836aa | ||
|
6c0c8e0ef6 | ||
|
8aa5f140bf | ||
|
2fcb9a5995 | ||
|
8b018b697d | ||
|
0e269ecd67 | ||
|
a640bc4656 | ||
|
62a95499ef | ||
|
9e92d4a35a | ||
|
459c07b121 | ||
|
ada15fdabc | ||
|
d5de36841a | ||
|
cf419fb329 | ||
|
abf39b34b6 | ||
|
552252371f | ||
|
7570010a04 | ||
|
a9ee753dc6 | ||
|
ca5a81122a | ||
|
554cd97145 | ||
|
806606f284 | ||
|
7c0ebc5887 | ||
|
45665f94a7 | ||
|
cd736fdbd4 | ||
|
f753884008 | ||
|
1d9a4941ce | ||
|
5bde797ba4 | ||
|
ecba35fc26 | ||
|
a4f8f367c3 | ||
|
41b11ab785 | ||
|
3d33c6c6f4 | ||
|
dbd8926022 | ||
|
f7f110b686 | ||
|
ebf065dcb8 | ||
|
6bc0747a71 | ||
|
04861939fc | ||
|
ca0aaa0c3a | ||
|
f5d5319a51 | ||
|
263b8a78ef | ||
|
3c866367c6 | ||
|
09d7080547 | ||
|
f480c8c5df | ||
|
a230431a3b | ||
|
eaec46982d | ||
|
a86d629982 | ||
|
bcbc0cb766 | ||
|
ac0d84eef8 | ||
|
9b4580d861 | ||
|
2085361df1 | ||
|
bf4657c138 | ||
|
1b5636afed | ||
|
7eba99ac29 | ||
|
de6474bf28 | ||
|
55bc690cd1 | ||
|
6dc62c1ab7 | ||
|
0aca07d278 | ||
|
1ab3b2c313 | ||
|
64e2c6a262 | ||
|
eac02835ed | ||
|
33657bb2cc | ||
|
8af0b351ae | ||
|
3260f90a73 | ||
|
b7e15195f9 | ||
|
c02725f036 | ||
|
507fe026e5 | ||
|
486f4c5626 | ||
|
91991bb729 | ||
|
71a116ca6f | ||
|
8b7e01f426 | ||
|
229345ade8 | ||
|
0f902b95cf | ||
|
8684e1be9c | ||
|
ae3a6129b2 | ||
|
2c72570b8d | ||
|
41803b878e | ||
|
a8be58becb | ||
|
067afc140a | ||
|
41128fada9 | ||
|
f5fae012f9 | ||
|
3d25fb30cb | ||
|
8374586275 | ||
|
68c2edf610 | ||
|
d58a55a1ed | ||
|
ccfa797b68 | ||
|
0f030f0759 | ||
|
af59b9dab2 | ||
|
fa173cd9aa | ||
|
1f8269c0e2 | ||
|
51462b8612 | ||
|
9b69648921 | ||
|
c5e416c41f | ||
|
37ad43c7fd | ||
|
a877cb52c0 | ||
|
4bec694df3 | ||
|
4870a7a164 | ||
|
84ccb37bc3 | ||
|
29c6e9325f | ||
|
81a4a4f828 | ||
|
1cdb5172d8 | ||
|
54a7a3f7bc | ||
|
2ea77e6151 | ||
|
5cfa6199e5 | ||
|
da6ccc146f | ||
|
fcfe237375 | ||
|
5fb3db4558 | ||
|
c8705c1198 | ||
|
0558bafcb6 | ||
|
f58277f53d | ||
|
e555a718c0 | ||
|
b29fcf2dd5 | ||
|
4f86703843 | ||
|
07d8bf0f3e | ||
|
b4cd692bae | ||
|
83c898cc2b | ||
|
c585d7aa78 | ||
|
f42a003d04 | ||
|
8da0471f07 | ||
|
1c20261b93 | ||
|
aeb9a9d473 | ||
|
66883b390d | ||
|
ea533659ce | ||
|
9e81971f25 | ||
|
cbbd866535 | ||
|
bf23f82c29 | ||
|
ec5c584785 | ||
|
6bbb8c0e42 | ||
|
438554b0ed | ||
|
61ba4bc5c8 | ||
|
0145883396 | ||
|
f91bfaab70 | ||
|
36ab4fdc1b | ||
|
1cd89398ad | ||
|
bd3a381783 | ||
|
618f42c960 | ||
|
1363b58060 | ||
|
2c659f40ff | ||
|
4c243a69fe | ||
|
f80eee7a09 | ||
|
a044b9325b | ||
|
c028ea478f | ||
|
62bdba6d22 | ||
|
4d9511243c | ||
|
188fd372ea | ||
|
44ffb0eec9 | ||
|
beb13bf89f | ||
|
a31078bbec | ||
|
7ae4f4009c |
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.
|
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
# For most projects, this workflow file will not need changing; you simply need
|
||||||
|
# to commit it to your repository.
|
||||||
|
#
|
||||||
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
|
# or to provide custom queries or build logic.
|
||||||
|
#
|
||||||
|
# ******** NOTE ********
|
||||||
|
# We have attempted to detect the languages in your repository. Please check
|
||||||
|
# the `language` matrix defined below to confirm you have the correct set of
|
||||||
|
# supported CodeQL languages.
|
||||||
|
#
|
||||||
|
name: "CodeQL"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ master ]
|
||||||
|
schedule:
|
||||||
|
- cron: '41 1 * * 6'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: Analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: [ 'cpp' ]
|
||||||
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||||
|
# Learn more:
|
||||||
|
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v2
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
# By default, queries listed here will override any specified in a config file.
|
||||||
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
|
# 📚 https://git.io/JvXDl
|
||||||
|
|
||||||
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
|
# and modify them (or add more) to build your code if your project
|
||||||
|
# uses a compiled language
|
||||||
|
|
||||||
|
#- run: |
|
||||||
|
# make bootstrap
|
||||||
|
# make release
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@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"
|
122
.gitignore
vendored
Normal file
122
.gitignore
vendored
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
# files and directories created during the building of calc and other Makefile actions
|
||||||
|
#
|
||||||
|
# NOTE: While many of these might be part of a released calc tarball, they are
|
||||||
|
# not consider development source. Some other file(s) and/or programs
|
||||||
|
# generate these files.
|
||||||
|
#
|
||||||
|
.dynamic
|
||||||
|
.hsrc
|
||||||
|
.static
|
||||||
|
align32.h
|
||||||
|
args.h
|
||||||
|
cal/.all
|
||||||
|
calc
|
||||||
|
calc.1
|
||||||
|
calcerr.c
|
||||||
|
calcerr.h
|
||||||
|
calc.spec
|
||||||
|
calc-static
|
||||||
|
calc.usage
|
||||||
|
charbit.h
|
||||||
|
conf.h
|
||||||
|
cscript/4dsphere
|
||||||
|
cscript/.all
|
||||||
|
cscript/fproduct
|
||||||
|
cscript/mersenne
|
||||||
|
cscript/piforever
|
||||||
|
cscript/plus
|
||||||
|
cscript/powerterm
|
||||||
|
cscript/README
|
||||||
|
cscript/simple
|
||||||
|
cscript/square
|
||||||
|
custom/.all
|
||||||
|
custom/libcustcalc*
|
||||||
|
debug.out
|
||||||
|
endian
|
||||||
|
endian_calc.h
|
||||||
|
fposval.h
|
||||||
|
have_arc4random.h
|
||||||
|
have_ban_pragma.h
|
||||||
|
have_const.h
|
||||||
|
have_environ.h
|
||||||
|
have_fgetsetpos.h
|
||||||
|
have_fpos_pos.h
|
||||||
|
have_getpgid.h
|
||||||
|
have_getprid.h
|
||||||
|
have_getsid.h
|
||||||
|
have_gettime.h
|
||||||
|
have_limits.h
|
||||||
|
have_memmv.h
|
||||||
|
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
|
||||||
|
have_unused.h
|
||||||
|
have_urandom.h
|
||||||
|
have_ustat.h
|
||||||
|
help/.all
|
||||||
|
help/binding
|
||||||
|
help/bindings
|
||||||
|
help/bug
|
||||||
|
help/bugs
|
||||||
|
help/builtin
|
||||||
|
help/change
|
||||||
|
help/changes
|
||||||
|
help/contrib
|
||||||
|
help/copy
|
||||||
|
help/COPYING
|
||||||
|
help/COPYING-LGPL
|
||||||
|
help/cscript
|
||||||
|
help/custom_cal
|
||||||
|
help/errorcode
|
||||||
|
help/errorcodes
|
||||||
|
help/full
|
||||||
|
help/funclist
|
||||||
|
help/funclist.c
|
||||||
|
help/libcalc
|
||||||
|
help/man
|
||||||
|
help/new_custom
|
||||||
|
help/question
|
||||||
|
help/questions
|
||||||
|
help/releases
|
||||||
|
help/resource
|
||||||
|
help/type
|
||||||
|
help/usage
|
||||||
|
libcalc*
|
||||||
|
libcustcalc*
|
||||||
|
longbits
|
||||||
|
longbits.h
|
||||||
|
Makefile.our
|
||||||
|
NOTES
|
||||||
|
sample_many
|
||||||
|
sample_many-static
|
||||||
|
sample_rand
|
||||||
|
sample_rand-static
|
||||||
|
tags
|
||||||
|
terminal.h
|
||||||
|
ver_calc
|
||||||
|
win32/
|
||||||
|
|
||||||
|
# other commonly excluded patterns
|
||||||
|
#
|
||||||
|
*~
|
||||||
|
*.BAK
|
||||||
|
core*
|
||||||
|
.DS_Store
|
||||||
|
*.dSYM/
|
||||||
|
*.[oa]
|
||||||
|
.*.swp
|
||||||
|
*,v
|
183
BUGS
183
BUGS
@@ -1,12 +1,12 @@
|
|||||||
If you notice something wrong, strange or broken, try rereading:
|
If you notice something wrong, strange or broken, try rereading:
|
||||||
|
|
||||||
README.FIRST
|
README.FIRST
|
||||||
HOWTO.INSTALL
|
HOWTO.INSTALL
|
||||||
BUGS (this file)
|
BUGS (this file)
|
||||||
|
|
||||||
If that does not help, cd to the calc source directory and try:
|
If that does not help, cd to the calc source directory and try:
|
||||||
|
|
||||||
make check
|
make check
|
||||||
|
|
||||||
Look at the end of the output, it should say something like:
|
Look at the end of the output, it should say something like:
|
||||||
|
|
||||||
@@ -15,74 +15,97 @@ Look at the end of the output, it should say something like:
|
|||||||
|
|
||||||
If it does not, then something is really broken!
|
If it does not, then something is really broken!
|
||||||
|
|
||||||
|
To be sure that your version of calc is up to date.
|
||||||
|
Look for the latest release on GitHub:
|
||||||
|
|
||||||
|
https://github.com/lcn2/calc/releases
|
||||||
|
|
||||||
|
Just below latest GitHub release sectiop is something called:
|
||||||
|
|
||||||
|
> Assets
|
||||||
|
|
||||||
|
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
|
If you made and modifications to calc beyond the simple Makefile
|
||||||
configuration, try backing them out and see if things get better.
|
configuration, try backing those changes out and see if things get
|
||||||
|
better.
|
||||||
To be sure that your version of calc is up to date, check out:
|
|
||||||
|
|
||||||
http://www.isthe.com/chongo/tech/comp/calc/calc-download.html
|
|
||||||
|
|
||||||
The calc web site is located at:
|
|
||||||
|
|
||||||
http://www.isthe.com/chongo/tech/comp/calc/index.html
|
|
||||||
|
|
||||||
=-=
|
|
||||||
|
|
||||||
If you have tried all of the above and things still are not right,
|
If you have tried all of the above and things still are not right,
|
||||||
then it may be time to send in a bug report. You can send bug
|
then it may be time to send in a bug report.
|
||||||
and bug fixes reports to:
|
|
||||||
|
|
||||||
calc-bug-report at asthe dot com
|
|
||||||
|
|
||||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
|
||||||
|
|
||||||
This replaces the old calc-bugs at asthe dot com address.
|
|
||||||
|
|
||||||
To be sure we see your EMail reporting a calc bug, please use the
|
|
||||||
following phase in your EMail Subject line:
|
|
||||||
|
|
||||||
calc bug report
|
|
||||||
|
|
||||||
That phrase in your subject line will help ensure your request
|
|
||||||
will get past our anti-spam filters. You may have additional
|
|
||||||
words in your subject line.
|
|
||||||
|
|
||||||
However, you may find it more helpful to simply subscribe
|
|
||||||
to the calc-tester mailing list (see below) and then to
|
|
||||||
send your report to that mailing list as a wider set calc
|
|
||||||
testers may be able to help you.
|
|
||||||
|
|
||||||
When you send your report, please include the following information:
|
|
||||||
|
|
||||||
* a description of the problem
|
|
||||||
* the version of calc you are using (if you cannot get calc
|
|
||||||
to run, then send us the 4 #define lines from version.c)
|
|
||||||
* if you modified calc from an official patch, send me the mods you made
|
|
||||||
* the type of system you were using
|
|
||||||
* the type of compiler you were using
|
|
||||||
* any compiler warnings or errors that you saw
|
|
||||||
* cd to the calc source directory, and type:
|
|
||||||
|
|
||||||
make debug > debug.out 2>&1 (sh, ksh, bash users)
|
|
||||||
make debug >& debug.out (csh, tcsh users)
|
|
||||||
|
|
||||||
and send the contents of the 'debug.out' file.
|
|
||||||
|
|
||||||
Stack traces from core dumps are useful to send as well.
|
|
||||||
|
|
||||||
Fell free to use the above address to send in big fixes (in the form
|
|
||||||
of a context diff patch).
|
|
||||||
|
|
||||||
=-=
|
=-=
|
||||||
|
|
||||||
Known bugs:
|
If you encounter a warning or error in compiling, or if you
|
||||||
|
find a calc bug and you wish to send is a fix, we recommend
|
||||||
|
that you submit your change using the GitHub pull request:
|
||||||
|
|
||||||
|
https://github.com/lcn2/calc/pulls
|
||||||
|
|
||||||
|
=-=
|
||||||
|
|
||||||
|
If you just want to send us a bug report, we recommend
|
||||||
|
doing so via the GitHub issue process:
|
||||||
|
|
||||||
|
https://github.com/lcn2/calc/issues
|
||||||
|
|
||||||
|
If you see an existing issue that matches your problem, look
|
||||||
|
over the notes and if needed, add your own observation,
|
||||||
|
even if you just add to an existing issue:
|
||||||
|
|
||||||
|
I have this issue too
|
||||||
|
|
||||||
|
If you don't see your issue addressed, then on the above
|
||||||
|
GitHub web page, click on this button:
|
||||||
|
|
||||||
|
((New Issue))
|
||||||
|
|
||||||
|
Please include the following information in the new issue:
|
||||||
|
|
||||||
|
* A description of the problem
|
||||||
|
|
||||||
|
* Version of calc you are using
|
||||||
|
|
||||||
|
If you cannot compile calc, then look at version.c
|
||||||
|
and report the #define that start with:
|
||||||
|
|
||||||
|
#define MAJOR_VER
|
||||||
|
#define MINOR_VER
|
||||||
|
#define MAJOR_PATCH
|
||||||
|
#define MINOR_PATCH
|
||||||
|
|
||||||
|
* If you modified calc from an official patch,
|
||||||
|
send us the mods you made
|
||||||
|
|
||||||
|
* Type and version of the operating system
|
||||||
|
|
||||||
|
* Type and version of compiler
|
||||||
|
|
||||||
|
* Send us all compiler warnings or errors you find
|
||||||
|
|
||||||
|
* 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.txt produced by this command:
|
||||||
|
|
||||||
|
make debug
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
=-=
|
||||||
|
|
||||||
|
Known bugs in calc:
|
||||||
|
|
||||||
The output of the alg_config.cal resource file is bogus.
|
The output of the alg_config.cal resource file is bogus.
|
||||||
We would welcome a replacement for this code.
|
We would welcome a replacement for this code.
|
||||||
|
|
||||||
|
Calc may not compile natively under Windows 11. See README.WINDOWS.
|
||||||
|
|
||||||
We are sure some more bugs exist. When you find them, please let
|
We are sure some more bugs exist. When you find them, please let
|
||||||
us know! See the above for details on how to report and were to
|
us know! See the above for details on how to report and were to
|
||||||
EMail your bug reports and hopefully patches to fix them.
|
Email your bug reports and hopefully patches to fix them.
|
||||||
|
|
||||||
=-=
|
=-=
|
||||||
|
|
||||||
@@ -133,34 +156,18 @@ mis-features in calc:
|
|||||||
|
|
||||||
will not.
|
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.
|
||||||
|
|
||||||
|
|
||||||
=-=
|
=-=
|
||||||
|
|
||||||
To subscribe to the calc-tester mailing list, visit the following URL:
|
## Copyright (C) 1999-2014,2021,2023 Landon Curt Noll
|
||||||
|
|
||||||
http://www.isthe.com/chongo/tech/comp/calc/calc-tester.html
|
|
||||||
|
|
||||||
This is a low volume moderated mailing list.
|
|
||||||
|
|
||||||
This mailing list replaces calc-tester at asthe dot com list.
|
|
||||||
|
|
||||||
If you need a human to help you with your mailing list subscription,
|
|
||||||
please send EMail to our special:
|
|
||||||
|
|
||||||
calc-tester-maillist-help at asthe dot com
|
|
||||||
|
|
||||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
|
||||||
|
|
||||||
address. To be sure we see your EMail asking for help with your
|
|
||||||
mailing list subscription, please use the following phase in your
|
|
||||||
EMail Subject line:
|
|
||||||
|
|
||||||
calc tester mailing list help
|
|
||||||
|
|
||||||
That phrase in your subject line will help ensure your
|
|
||||||
request will get past our anti-spam filters. You may have
|
|
||||||
additional words in your subject line.
|
|
||||||
|
|
||||||
## Copyright (C) 1999-2014 Landon Curt Noll
|
|
||||||
##
|
##
|
||||||
## Calc is open software; you can redistribute it and/or modify it under
|
## 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
|
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -176,10 +183,6 @@ To subscribe to the calc-tester mailing list, visit the following URL:
|
|||||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
##
|
##
|
||||||
## @(#) $Revision: 30.5 $
|
|
||||||
## @(#) $Id: BUGS,v 30.5 2014/10/12 12:23:43 chongo Exp $
|
|
||||||
## @(#) $Source: /usr/local/src/bin/calc/RCS/BUGS,v $
|
|
||||||
##
|
|
||||||
## Under source code control: 1994/03/18 14:06:13
|
## Under source code control: 1994/03/18 14:06:13
|
||||||
## File existed as early as: 1994
|
## File existed as early as: 1994
|
||||||
##
|
##
|
||||||
|
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.
|
64
CONTRIB-CODE
Normal file
64
CONTRIB-CODE
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
Calc is open source. Contributions of code are welcome.
|
||||||
|
|
||||||
|
In order to consider integrating your contributions, we need:
|
||||||
|
|
||||||
|
* your changes applied agsinst the top of the calc master branch:
|
||||||
|
|
||||||
|
https://github.com/lcn2/calc/
|
||||||
|
|
||||||
|
* new help files or help file patches, if applicable (documentation)
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
|
The best way contribute to calc bug is to generate calc
|
||||||
|
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 under "The Unlicense":
|
||||||
|
|
||||||
|
https://unlicense.org
|
||||||
|
|
||||||
|
=-=
|
||||||
|
|
||||||
|
See also the calc wishlist by running the calc command:
|
||||||
|
|
||||||
|
; help wishlist
|
||||||
|
|
||||||
|
=-=
|
||||||
|
|
||||||
|
## 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
|
||||||
|
## 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: 1997/03/09 16:33:22
|
||||||
|
## File existed as early as: 1997
|
||||||
|
##
|
||||||
|
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||||
|
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
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.
|
118
COPYING
118
COPYING
@@ -1,21 +1,17 @@
|
|||||||
calc - arbitrary precision calculator
|
calc - arbitrary precision calculator
|
||||||
|
|
||||||
|
|
||||||
This file is Copyrighted
|
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:
|
This file is covered under the following Copyright:
|
||||||
|
|
||||||
Copyright (C) 1999-2014 Landon Curt Noll
|
Copyright (C) 1999-2023 Landon Curt Noll
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
# @(#) $Revision: 30.6 $
|
|
||||||
# @(#) $Id: COPYING,v 30.6 2014/10/12 12:23:43 chongo Exp $
|
|
||||||
# @(#) $Source: /usr/local/src/bin/calc/RCS/COPYING,v $
|
|
||||||
|
|
||||||
-=-
|
-=-
|
||||||
|
|
||||||
Calc is covered by the GNU Lesser General Public License
|
Calc is covered by the GNU Lesser General Public License
|
||||||
@@ -53,65 +49,6 @@ Calc is covered by the GNU Lesser General Public License
|
|||||||
Boston, MA 02110-1301
|
Boston, MA 02110-1301
|
||||||
USA
|
USA
|
||||||
|
|
||||||
To subscribe to the calc-tester mailing list, visit the following URL:
|
|
||||||
|
|
||||||
http://www.isthe.com/chongo/tech/comp/calc/calc-tester.html
|
|
||||||
|
|
||||||
This is a low volume moderated mailing list.
|
|
||||||
|
|
||||||
This mailing list replaces calc-tester at asthe dot com list.
|
|
||||||
|
|
||||||
If you need a human to help you with your mailing list subscription,
|
|
||||||
please send EMail to our special:
|
|
||||||
|
|
||||||
calc-tester-maillist-help at asthe dot com
|
|
||||||
|
|
||||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
|
||||||
|
|
||||||
address. To be sure we see your EMail asking for help with your
|
|
||||||
mailing list subscription, please use the following phase in your
|
|
||||||
EMail Subject line:
|
|
||||||
|
|
||||||
calc tester mailing list help
|
|
||||||
|
|
||||||
That phrase in your subject line will help ensure your
|
|
||||||
request will get past our anti-spam filters. You may have
|
|
||||||
additional words in your subject line.
|
|
||||||
|
|
||||||
-=-
|
|
||||||
|
|
||||||
Calc bug reports and calc bug fixes should be sent to:
|
|
||||||
|
|
||||||
calc-bug-report at asthe dot com
|
|
||||||
|
|
||||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
|
||||||
|
|
||||||
This replaces the old calc-bugs at asthe dot com address.
|
|
||||||
|
|
||||||
To be sure we see your EMail reporting a calc bug, please use the
|
|
||||||
following phase in your EMail Subject line:
|
|
||||||
|
|
||||||
calc bug report
|
|
||||||
|
|
||||||
That phrase in your subject line will help ensure your
|
|
||||||
request will get past our anti-spam filters. You may have
|
|
||||||
additional words in your subject line.
|
|
||||||
|
|
||||||
However, you may find it more helpful to simply subscribe
|
|
||||||
to the calc-tester mailing list (see above) and then to
|
|
||||||
send your report to that mailing list as a wider set calc
|
|
||||||
testers may be able to help you.
|
|
||||||
|
|
||||||
-=-
|
|
||||||
|
|
||||||
The calc web site is located at:
|
|
||||||
|
|
||||||
http://www.isthe.com/chongo/tech/comp/calc/
|
|
||||||
|
|
||||||
NOTE: The EMail address uses 'asthe', while the web site uses 'isthe'.
|
|
||||||
|
|
||||||
-=-
|
|
||||||
|
|
||||||
Calc's relationship to the GNU Lesser General Public License
|
Calc's relationship to the GNU Lesser General Public License
|
||||||
------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
|
|
||||||
@@ -138,8 +75,8 @@ Calc's relationship to the GNU Lesser General Public License
|
|||||||
Clearly all files that go into the creation of those binary link
|
Clearly all files that go into the creation of those binary link
|
||||||
libraries are covered under the License.
|
libraries are covered under the License.
|
||||||
|
|
||||||
The ``scripts used to control compilation and installation of the
|
The "scripts used to control compilation and installation of the
|
||||||
of the library'' include:
|
of the library" include:
|
||||||
|
|
||||||
* Makefiles
|
* Makefiles
|
||||||
* source files created by the Makefiles
|
* source files created by the Makefiles
|
||||||
@@ -147,7 +84,7 @@ Calc's relationship to the GNU Lesser General Public License
|
|||||||
|
|
||||||
All of those files are covered under the License.
|
All of those files are covered under the License.
|
||||||
|
|
||||||
The ``associated interface definition files'' are those files that:
|
The "associated interface definition files" are those files that:
|
||||||
|
|
||||||
* show how the calc binary link libraries are used
|
* show how the calc binary link libraries are used
|
||||||
* test the validity of the binary link libraries
|
* test the validity of the binary link libraries
|
||||||
@@ -162,9 +99,9 @@ Calc's relationship to the GNU Lesser General Public License
|
|||||||
* files under the lib sub-directory
|
* files under the lib sub-directory
|
||||||
* the main calc.c file
|
* the main calc.c file
|
||||||
|
|
||||||
The ``complete source code'' includes ALL files shipped with calc,
|
The "complete source code" includes ALL files shipped with calc,
|
||||||
except for the exception files explicitly listed in the ``Calc
|
except for the exception files explicitly listed in the "Calc
|
||||||
copyrights and exception files'' section below.
|
copyrights and exception files" section below.
|
||||||
|
|
||||||
-=-
|
-=-
|
||||||
|
|
||||||
@@ -183,11 +120,13 @@ Calc copyrights and exception files
|
|||||||
Copyright (C) year Ernest Bowen
|
Copyright (C) year Ernest Bowen
|
||||||
Copyright (C) year Petteri Kettunen and Landon Curt Noll
|
Copyright (C) year Petteri Kettunen and Landon Curt Noll
|
||||||
Copyright (C) year Christoph Zurnieden
|
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:
|
These files are not covered under one of the Copyrights listed above:
|
||||||
|
|
||||||
sha1.c sha1.h COPYING
|
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
|
The file COPYING-LGPL, which contains a copy of the version 2.1
|
||||||
GNU Lesser General Public License, is itself Copyrighted by the
|
GNU Lesser General Public License, is itself Copyrighted by the
|
||||||
@@ -199,8 +138,39 @@ Calc copyrights and exception files
|
|||||||
top of this file. It is important to note that you may distribute
|
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.
|
verbatim copies of this file but you may not modify this file.
|
||||||
|
|
||||||
Some of these exception files are in the public domain. Other files
|
These files are covered under "The Unlicense":
|
||||||
are under the LGPL but have different authors that those listed above.
|
|
||||||
|
sha1.c
|
||||||
|
sha1.h
|
||||||
|
cal/dotest.cal
|
||||||
|
cal/screen.cal
|
||||||
|
|
||||||
|
"The Unlicense" is as follows:
|
||||||
|
|
||||||
|
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/>
|
||||||
|
|
||||||
In all cases one may use and distribute these exception files freely.
|
In all cases one may use and distribute these exception files freely.
|
||||||
And because one may freely distribute the LGPL covered files, the
|
And because one may freely distribute the LGPL covered files, the
|
||||||
|
462
HOWTO.INSTALL
462
HOWTO.INSTALL
@@ -1,194 +1,390 @@
|
|||||||
Installing calc from the bzip2-ed tarball in 4 easy steps:
|
# Installing a pre-compiled calc from an RPM
|
||||||
|
|
||||||
0) If your platform supports i686 RPMs, you may want to go to:
|
If your platform supports RPMs, you may want to go to:
|
||||||
|
|
||||||
http://www.isthe.com/chongo/src/calc/
|
https://github.com/lcn2/calc/releases
|
||||||
|
|
||||||
and use these RPMs:
|
and see if there is a pre-compiled version of calc that you may install.
|
||||||
|
|
||||||
* calc*.i686.rpm
|
Open up the 'Assets' tag below a given release and download these RPMs:
|
||||||
- all that is needed if you just want to use calc
|
|
||||||
|
|
||||||
* calc-devel-*.i686.rpm
|
* calc*.rpm
|
||||||
- calc *.h header and *.a lib files for use in other programs
|
|
||||||
|
|
||||||
* calc.*.src.rpm
|
- all that is needed if you just want to use calc
|
||||||
- calc source in RPM package form
|
|
||||||
|
|
||||||
The following 4 steps apply to calc source tree that comes from either:
|
If your platform supports rpm and matches one of the "calc*.rpm" files, you
|
||||||
|
may just install that "calc*.rpm". For exammple on an x86_64 system:
|
||||||
|
|
||||||
bunzip2 -c calc-*.tar.bz2 | tar -xvf -
|
dnf install calc-x.y.z.cv-ww.x86_64.rpm
|
||||||
|
|
||||||
or from:
|
where "calc-x.y.z.cv-ww.x86_64.rpm" is the name of the calc RPM.
|
||||||
|
|
||||||
rpm -ivh calc-*.src.rpm
|
In addition, if your platform supports rpm and matches one of the
|
||||||
cd /var/tmp
|
"calc*.rpm" files, you may also install the calc *.h header and *.a lib
|
||||||
bunzip2 -c /usr/src/redhat/SOURCES/calc-*.tar.bz2 | tar -xvf -
|
files for use in other programs:
|
||||||
|
|
||||||
1) Look at the makefile, and adjust it to suit your needs.
|
* calc-devel-*.rpm
|
||||||
|
|
||||||
The top level Makefile and the custom/Makefile require a GNU
|
- calc *.h header and *.a lib files for use in other programs
|
||||||
Make (such as gmake) or an equivalently advanced make. On many
|
|
||||||
targets, the default make is sufficent. On FreeBSD for example,
|
|
||||||
one must use gmake instead of make.
|
|
||||||
|
|
||||||
If your target system does not have GNU Make (or equivalent), then
|
Alternately to the above github link, you might try looking at the RPMs under:
|
||||||
you should try using the Makefile.simple and custom/Makefile.simple
|
|
||||||
files:
|
|
||||||
|
|
||||||
mv Makefile Makefile.gmake
|
http://www.isthe.com/chongo/src/calc/
|
||||||
cp Makefile.simple Makefile
|
|
||||||
mv custom/Makefile custom/Makefile.gmake
|
|
||||||
cp custom/Makefile.simple custom/Makefile
|
|
||||||
|
|
||||||
The Makefile, as shipped, is suitable for installation under
|
|
||||||
Linux and Un*x-like environments. For the most part, the default
|
|
||||||
values should work. If in doubt, follow the 'When in doubt'
|
|
||||||
suggestion.
|
|
||||||
|
|
||||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
! If you are building under Windoz or a Windoz-like environment !
|
|
||||||
! (such as Cygwin or DJGPP), read the README.WINDOWS file. !
|
|
||||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
|
|
||||||
You should determine if these Makefile variables are reasonable:
|
# Building calc from a source tree
|
||||||
|
|
||||||
INCDIR Where the system include (.h) files are kept.
|
|
||||||
BINDIR Where to install calc binary files.
|
|
||||||
LIBDIR Where to install calc link library (*.a) files.
|
|
||||||
CALC_SHAREDIR Where to install calc help, .cal, startup, and
|
|
||||||
config files.
|
|
||||||
|
|
||||||
You may want to change the default installation locations for
|
|
||||||
these values, which are based on the 4 values listed above:
|
|
||||||
|
|
||||||
HELPDIR where the help directory is installed
|
## Step 0: Obtain the calc source tree
|
||||||
CALC_INCDIR where the calc include files are installed
|
|
||||||
CUSTOMCALDIR where custom *.cal files are installed
|
|
||||||
CUSTOMHELPDIR where custom help files are installed
|
|
||||||
CUSTOMINCDIR where custom .h files are installed
|
|
||||||
SCRIPTDIR where calc shell scripts are installed
|
|
||||||
|
|
||||||
If you want to install calc files under a top level directory,
|
Go to the site:
|
||||||
then set the T value:
|
|
||||||
|
|
||||||
The calc install is performed under ${T}, the calc build is
|
https://github.com/lcn2/calc/releases
|
||||||
performed under /. The purpose for ${T} is to allow someone
|
|
||||||
to install calc somewhere other than into the system area.
|
|
||||||
|
|
||||||
For example, if:
|
Look for release with a file of the form:
|
||||||
|
|
||||||
BINDIR= /usr/bin
|
calc-x.y.z.v.tar.bz2
|
||||||
LIBDIR= /usr/lib
|
|
||||||
CALC_SHAREDIR= /usr/share/calc
|
|
||||||
|
|
||||||
and if:
|
A release marked with a green "(Latest)" is a production release
|
||||||
|
that as undergone a fair amount of testing.
|
||||||
|
|
||||||
T= /var/tmp/testing
|
A release marked with an orange "(Pre-release)" is likly to be
|
||||||
|
more stable than the top of the master branch, as they do undergo
|
||||||
|
thru a reasonable level of regression testing, just not to
|
||||||
|
the level of a "(Latest)" production release.
|
||||||
|
|
||||||
Then the installation locations will be:
|
Use the followig command to uncompress the bzip2 compressed tarball:
|
||||||
|
|
||||||
calc binary files: /var/tmp/testing/usr/bin
|
bunzip2 -c calc-*.tar.bz2 | tar -xvf -
|
||||||
calc link library: /var/tmp/testing/usr/lib
|
|
||||||
calc help, .cal ...: /var/tmp/testing/usr/share/calc
|
|
||||||
... etc ... /var/tmp/testing/...
|
|
||||||
|
|
||||||
If ${T} is empty, calc is installed under /, which is the same
|
NOTE: An alternate location for calc bzip2 compressed tarballs is:
|
||||||
top of tree for which it was built. If ${T} is non-empty, then
|
|
||||||
calc is installed under ${T}, as if one had to chroot under
|
|
||||||
${T} for calc to operate.
|
|
||||||
|
|
||||||
Look for the section that starts:
|
http://www.isthe.com/chongo/src/calc/
|
||||||
|
|
||||||
################
|
|
||||||
# compiler set #
|
|
||||||
################
|
|
||||||
|
|
||||||
Select a compiler set by commenting in the appropriate set
|
|
||||||
of cc options. As shipped the Makefile assumes a gcc-like
|
|
||||||
environment such as Linux. If a more appropriate cc set if
|
|
||||||
found below, comment out the Linux set and comment in that
|
|
||||||
set or edit the gcc set or the common cc set as needed.
|
|
||||||
|
|
||||||
You may want to change these Makrfile variables from their defaults:
|
### Obtaining the experimental top of the master branch calc source
|
||||||
|
|
||||||
RANLIB
|
You may also fetch the top of the master branch of the GitHub repo
|
||||||
|
if you wish to see what the latest source code looks like:
|
||||||
|
|
||||||
You may or may not need RANLIB when building libraries.
|
git clone https://github.com/lcn2/calc.git
|
||||||
As shipped the Makefile assumes RANLIB is needed.
|
|
||||||
Comment the in/out the RANLIB value if ranlib does
|
|
||||||
not work or does not exist.
|
|
||||||
|
|
||||||
CALCPAGER
|
IMPORTANT:
|
||||||
|
|
||||||
You may want to change the default pager used by calc.
|
The latest source code may be "experimental in nature". You may be
|
||||||
As shipped the Makefile assumes 'more'. On your system
|
better off using a released bzip2 compressed tarball instead.
|
||||||
you may find 'less' to be a better pager.
|
Released bzip2 compressed tarballs tend to be more well tested
|
||||||
|
than the top of the master branch.
|
||||||
|
|
||||||
DEBUG
|
|
||||||
|
|
||||||
Some compilers (to put it mildly) have bugs. Sometimes the
|
|
||||||
DEBUG Makefile variable causes the compiler / optimizer to
|
|
||||||
produce bad code. Other compilers do just fine.
|
|
||||||
|
|
||||||
If possible try to use DEBUG=-O3 -g3 (maximum optimization
|
## Step 1: Makefile considerations
|
||||||
and debug symbols). If the calc test fails (see step 3),
|
|
||||||
try lowering either the -O value and/or the -g3. Also try
|
|
||||||
using -Osomething without -g.
|
|
||||||
|
|
||||||
Adjust other Makefile variables as needed.
|
|
||||||
|
|
||||||
2) build calc:
|
### IMPORTANT: Make support of conditional syntax required:
|
||||||
|
|
||||||
The top level Makefile and the custom/Makefile require a GNU
|
To compile calc, you must use a make that supports the use of
|
||||||
Make (such as gmake) or an equivalently advanced make. On many
|
"Conditional syntax". As nearly all modern make tools
|
||||||
targets, the default make is sufficent. On FreeBSD for example,
|
support "Conditional syntax", thus should not be a problem
|
||||||
one must use gmake instead of make.
|
for you. If for some reason your make tool does not support
|
||||||
|
"Conditional syntax", consider upgraded to a make that does,
|
||||||
|
such as the Gnu Make tool:
|
||||||
|
|
||||||
If your target system does not have GNU Make (or equivalent), then
|
https://www.gnu.org/software/make/
|
||||||
you should try using the Makefile.simple and custom/Makefile.simple
|
|
||||||
files:
|
|
||||||
|
|
||||||
mv Makefile Makefile.gmake
|
The Gnu Make is not required per-se, just a modern make tool
|
||||||
cp Makefile.simple Makefile
|
that supports "Conditional syntax".
|
||||||
mv custom/Makefile custom/Makefile.gmake
|
|
||||||
cp custom/Makefile.simple custom/Makefile
|
|
||||||
|
|
||||||
make all
|
|
||||||
|
|
||||||
==> We are interested in any compiler warnings (and errors) that
|
### Review Makefiles
|
||||||
you may find. See the BUGS file if you find any compiler
|
|
||||||
warning or errors.
|
|
||||||
|
|
||||||
NOTE: You can force calc to build with only static libs:
|
Review Makefile.config and Makefile.target.
|
||||||
|
|
||||||
make clobber
|
If you are curious, review Makefile as well, although
|
||||||
make calc-static-only BLD_TYPE=calc-static-only
|
there may be little in the main Makefile that you may
|
||||||
|
want to change.
|
||||||
|
|
||||||
or force calc to build with only dynamic libs:
|
Consider modifying Makefile.local by replace values or
|
||||||
|
appending values found in Makefile.config and Makefile.target.
|
||||||
|
|
||||||
make clobber
|
If you are adding custom functions, review custom/Makefile
|
||||||
make calc-dynamic-only BLD_TYPE=calc-dynamic-only
|
and modify custom/Makefile as needed.
|
||||||
|
|
||||||
3) test calc:
|
|
||||||
|
|
||||||
make check
|
|
||||||
|
|
||||||
==> If you run into problems, read the BUGS file and follow
|
### Suggestion: Modify Makefile.local
|
||||||
the instructions found in there.
|
|
||||||
|
|
||||||
NOTE: For a quiet check which only prints if something goes wrong:
|
All Makefiles include Makefile.local just before the
|
||||||
|
first and default all rule. So Makefile.local may be
|
||||||
|
used to modify, replace or append values to Makefile variables.
|
||||||
|
|
||||||
make chk
|
In most cases, to change the way that calc is made, consider
|
||||||
|
adding lines to Makefile.local instead of modifying other Makefiles.
|
||||||
|
|
||||||
4) install calc:
|
A recommended way to adjust it is to add lines to: Makefile.local
|
||||||
|
using the := syntax to replace values such as:
|
||||||
|
|
||||||
make install
|
DEBUG:= -O0 -g
|
||||||
|
|
||||||
We suggest that you might want to read the README file and look at
|
or by using the += syntax to append to values such as:
|
||||||
the calc help subsystem. See the README file for details.
|
|
||||||
|
|
||||||
## Copyright (C) 1999-2007 Landon Curt Noll
|
DEBUG+= -ipa
|
||||||
|
|
||||||
|
You can, of course, modify other Makefiles. We only
|
||||||
|
suggest using Makefile.local to minimize the number
|
||||||
|
of source files you modify.
|
||||||
|
|
||||||
|
And finally, you can always just add arguments to your
|
||||||
|
make command line instead of modifying a Makefile. For example:
|
||||||
|
|
||||||
|
make clobber all DEBUG="-O0 -g"
|
||||||
|
|
||||||
|
|
||||||
|
## readline package assumed by default:
|
||||||
|
|
||||||
|
By "readline package" we refer to the combination of the
|
||||||
|
readline library, the history library, and the ncurses library.
|
||||||
|
|
||||||
|
By default, calc assumes you have the readline package installed.
|
||||||
|
The readline package (-lreadline, -lhistory, -lncurses) used by and
|
||||||
|
linked into calc by default.
|
||||||
|
|
||||||
|
If your system (such as macOS) does NOT have those libaraies, then
|
||||||
|
you have two options:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Install the readline package:
|
||||||
|
|
||||||
|
We recommend that you 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/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Compile calc without readline:
|
||||||
|
|
||||||
|
Why do we not recommend this option 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 compile with:
|
||||||
|
|
||||||
|
make clobber all USE_READLINE= READLINE_EXTRAS= READLINE_INCLUDE= READLINE_LIB=
|
||||||
|
|
||||||
|
or add to Makefile.local, these lines:
|
||||||
|
|
||||||
|
USE_READLINE=
|
||||||
|
READLINE_EXTRAS=
|
||||||
|
READLINE_INCLUDE=
|
||||||
|
READLINE_LIB=
|
||||||
|
|
||||||
|
See the "Suggestion: Modify Makefile.local" section above for
|
||||||
|
information on the Makefile.local file.
|
||||||
|
|
||||||
|
|
||||||
|
### Windows or a Windows-like environments:
|
||||||
|
|
||||||
|
Currently Windows is not a well supported platform for calc. There are
|
||||||
|
people within Microsoft who plan to assist us in being able to allow
|
||||||
|
the standard Microsoft Windows developor environment to compile calc.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Makefile variables to consider:
|
||||||
|
|
||||||
|
You should determine if these Makefile variables are reasonable:
|
||||||
|
|
||||||
|
INCDIR Where the system include (.h) files are kept.
|
||||||
|
BINDIR Where to install calc binary files.
|
||||||
|
LIBDIR Where to install calc link library (*.a) files.
|
||||||
|
CALC_SHAREDIR Where to install calc help, .cal, startup, and config files.
|
||||||
|
|
||||||
|
You may want to change the default installation locations for
|
||||||
|
these values, which are based on the 4 values listed above:
|
||||||
|
|
||||||
|
HELPDIR where the help directory is installed
|
||||||
|
CALC_INCDIR where the calc include files are installed
|
||||||
|
CUSTOMCALDIR where custom *.cal files are installed
|
||||||
|
CUSTOMHELPDIR where custom help files are installed
|
||||||
|
CUSTOMINCDIR where custom .h files are installed
|
||||||
|
SCRIPTDIR where calc shell scripts are installed
|
||||||
|
|
||||||
|
If you want to install calc files under a top level directory, then set the T value:
|
||||||
|
|
||||||
|
The calc install is performed under ${T}, the calc build is
|
||||||
|
performed under /. The purpose for ${T} is to allow someone
|
||||||
|
to install calc somewhere other than into the system area.
|
||||||
|
|
||||||
|
For example, if:
|
||||||
|
|
||||||
|
BINDIR= /usr/bin
|
||||||
|
LIBDIR= /usr/lib
|
||||||
|
CALC_SHAREDIR= /usr/share/calc
|
||||||
|
|
||||||
|
and if:
|
||||||
|
|
||||||
|
T= /var/tmp/testing
|
||||||
|
|
||||||
|
Then the installation locations will be:
|
||||||
|
|
||||||
|
calc binary files: /var/tmp/testing/usr/bin
|
||||||
|
calc link library: /var/tmp/testing/usr/lib
|
||||||
|
calc help, .cal ...: /var/tmp/testing/usr/share/calc
|
||||||
|
... etc ... /var/tmp/testing/...
|
||||||
|
|
||||||
|
If ${T} is empty, calc is installed under /, which is the same
|
||||||
|
top of tree for which it was built. If ${T} is non-empty, then
|
||||||
|
calc is installed under ${T}, as if one had to chroot under
|
||||||
|
${T} for calc to operate.
|
||||||
|
|
||||||
|
Again, consider adding replacement lines or append linbes to
|
||||||
|
the Makefile.local file. See "Suggestion Modify Makefile.local
|
||||||
|
instead of Makefile" above. For example:
|
||||||
|
|
||||||
|
T:= /var/tmp/testing
|
||||||
|
|
||||||
|
See the "Suggestion: Modify Makefile.local" section above for
|
||||||
|
information on the Makefile.local file.
|
||||||
|
|
||||||
|
|
||||||
|
### platform target section
|
||||||
|
|
||||||
|
The file, Makefile.target, contains information about various platforms.
|
||||||
|
The current list of targets in Makefile.target are:
|
||||||
|
|
||||||
|
- Linux target
|
||||||
|
- Apple macOS / Darwin target
|
||||||
|
- FreeBSD target
|
||||||
|
- OpenBSD target
|
||||||
|
- Cygwin target
|
||||||
|
- simple target
|
||||||
|
- default target (when target is empty)
|
||||||
|
|
||||||
|
If you wish to modiy your target platform, consider doing
|
||||||
|
so via the Makefile.local file. See "Suggestion Modify Makefile.local
|
||||||
|
instead of Makefile" above.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Step 2: compile calc
|
||||||
|
|
||||||
|
Remove any previous compile attempts and compile by default:
|
||||||
|
|
||||||
|
make clobber all
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Force calc to build with only static libs:
|
||||||
|
|
||||||
|
You may force calc to build with only static libs:
|
||||||
|
|
||||||
|
make clobber calc-static-only BLD_TYPE=calc-static-only
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Force calc to build with only dynamic shared libs:
|
||||||
|
|
||||||
|
You may force calc to build with only dynamic libs:
|
||||||
|
|
||||||
|
make clobber calc-dynamic-only BLD_TYPE=calc-dynamic-only
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Reports of compiler warnings (and errors) as welcome
|
||||||
|
|
||||||
|
We are interested learning about any compiler warnings (and errors) that you may find.
|
||||||
|
See the BUGS file if you find any compiler warning or errors.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Step 3: test calc
|
||||||
|
|
||||||
|
You may run the calc regression test suite, after successfully compiling, by:
|
||||||
|
|
||||||
|
make check
|
||||||
|
|
||||||
|
For a more quiet check which only prints if something goes wrong, use:
|
||||||
|
|
||||||
|
make chk
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Step 4: install calc
|
||||||
|
|
||||||
|
Depending on permissions, you may need to become the super-user:
|
||||||
|
|
||||||
|
sudo -s
|
||||||
|
|
||||||
|
before you install:
|
||||||
|
|
||||||
|
make install
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Step n: calc help - getting started
|
||||||
|
|
||||||
|
Calc is distributed with an extensive collection of help files that
|
||||||
|
are accessible from the command line. The following assume that you
|
||||||
|
are running calc from the distribution directory or that you have
|
||||||
|
installed calc. In these examples, the "; " is the calc prompt, not
|
||||||
|
something that you type.
|
||||||
|
|
||||||
|
For list of help topics:
|
||||||
|
|
||||||
|
; help
|
||||||
|
|
||||||
|
For overview of calc overview:
|
||||||
|
|
||||||
|
; help intro
|
||||||
|
; help overview
|
||||||
|
; help command
|
||||||
|
; help define
|
||||||
|
; help statement
|
||||||
|
; help variable
|
||||||
|
; help usage
|
||||||
|
|
||||||
|
For list of builtin functions:
|
||||||
|
|
||||||
|
; help builtin
|
||||||
|
|
||||||
|
C programmers should note some unexpected differences with the calc syntax:
|
||||||
|
|
||||||
|
; help unexpected
|
||||||
|
|
||||||
|
Calc is shipped with a standard collection of calc resource files.
|
||||||
|
For a list of calc standard resource files see:
|
||||||
|
|
||||||
|
; help resource
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
In general, if you run into problems, read the BUGS file and follow the instructions.
|
||||||
|
|
||||||
|
# IMPORTANT: parallel make not supported
|
||||||
|
|
||||||
|
We do not support making calc using a parallel make as most parallel
|
||||||
|
make systems fail to understand the depedency relationships between
|
||||||
|
a numner of important make rules and thus fail to properly compile calc.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Copyright (C) 1999-2007,2021,2023 Landon Curt Noll
|
||||||
##
|
##
|
||||||
## Calc is open software; you can redistribute it and/or modify it under
|
## 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
|
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -204,10 +400,6 @@ the calc help subsystem. See the README file for details.
|
|||||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
##
|
##
|
||||||
## @(#) $Revision: 30.6 $
|
|
||||||
## @(#) $Id: HOWTO.INSTALL,v 30.6 2007/10/16 12:22:22 chongo Exp $
|
|
||||||
## @(#) $Source: /usr/local/src/bin/calc/RCS/HOWTO.INSTALL,v $
|
|
||||||
##
|
|
||||||
## Under source code control: 1999/09/27 20:48:44
|
## Under source code control: 1999/09/27 20:48:44
|
||||||
## File existed as early as: 1999
|
## File existed as early as: 1999
|
||||||
##
|
##
|
||||||
|
34
LIBRARY
34
LIBRARY
@@ -216,7 +216,7 @@ Your program must handle parse/scan errors in one of two ways:
|
|||||||
/* report the parse/scan */
|
/* report the parse/scan */
|
||||||
if (calc_use_scanerr_jmpbuf == 0) {
|
if (calc_use_scanerr_jmpbuf == 0) {
|
||||||
printf("parse error: %s\n", calc_err_msg);
|
printf("parse error: %s\n", calc_err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize calc after the longjmp */
|
/* initialize calc after the longjmp */
|
||||||
initialize();
|
initialize();
|
||||||
@@ -320,10 +320,10 @@ The arbitrary precision integer routines define a structure called a ZVALUE.
|
|||||||
This is defined in zmath.h. A ZVALUE contains a pointer to an array of
|
This is defined in zmath.h. A ZVALUE contains a pointer to an array of
|
||||||
integers, the length of the array, and a sign flag. The array is allocated
|
integers, the length of the array, and a sign flag. The array is allocated
|
||||||
using malloc, so you need to free this array when you are done with a
|
using malloc, so you need to free this array when you are done with a
|
||||||
ZVALUE. To do this, you should call zfree with the ZVALUE as an argument
|
ZVALUE. To do this, you should call zfree() with the ZVALUE as an argument
|
||||||
(or call freeh with the pointer as an argument) and never try to free the
|
and never try to free the array yourself using free(). The reason for this
|
||||||
array yourself using free. The reason for this is that sometimes the pointer
|
is that sometimes the pointer points to a statically allocated arrays which
|
||||||
points to one of two statically allocated arrays which should NOT be freed.
|
should NOT be freed.
|
||||||
|
|
||||||
The ZVALUE structures are passed to routines by value, and are returned
|
The ZVALUE structures are passed to routines by value, and are returned
|
||||||
through pointers. For example, to multiply two small integers together,
|
through pointers. For example, to multiply two small integers together,
|
||||||
@@ -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
|
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,
|
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,
|
represents a number into a ZVALUE. The string can be in decimal, octal,
|
||||||
hex, or binary according to the leading digits.
|
hex, or binary according to the leading digits.
|
||||||
|
|
||||||
@@ -357,7 +357,7 @@ over a long sequence of operations.
|
|||||||
ZVALUE z1, z2, z3;
|
ZVALUE z1, z2, z3;
|
||||||
|
|
||||||
z1 = _one_;
|
z1 = _one_;
|
||||||
atoz("12345678987654321", &z2);
|
str2z("12345678987654321", &z2);
|
||||||
zadd(z1, z2, &z3);
|
zadd(z1, z2, &z3);
|
||||||
zfree(z1);
|
zfree(z1);
|
||||||
zfree(z2);
|
zfree(z2);
|
||||||
@@ -446,10 +446,10 @@ to free them first. The following illustrates this:
|
|||||||
itoz(55L, &q->num);
|
itoz(55L, &q->num);
|
||||||
|
|
||||||
A better way to create NUMBERs with particular values is to use the itoq,
|
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
|
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
|
NUMBER (reducing them first if needed), and str2q converts a string representing
|
||||||
a number into the corresponding NUMBER. The atoq function accepts input in
|
a number into the corresponding NUMBER. The str2q function accepts input in
|
||||||
integral, fractional, real, or exponential formats. Examples of allocating
|
integral, fractional, real, or exponential formats. Examples of allocating
|
||||||
numbers are:
|
numbers are:
|
||||||
|
|
||||||
@@ -457,7 +457,7 @@ numbers are:
|
|||||||
|
|
||||||
q1 = itoq(66L);
|
q1 = itoq(66L);
|
||||||
q2 = iitoq(2L, 3L);
|
q2 = iitoq(2L, 3L);
|
||||||
q3 = atoq("456.78");
|
q3 = str2q("456.78");
|
||||||
|
|
||||||
Also unlike ZVALUEs, NUMBERs are quickly copied. This is because they contain
|
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
|
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;
|
NUMBER *q, *ans, *epsilon;
|
||||||
|
|
||||||
q = atoq("0.5");
|
q = str2q("0.5");
|
||||||
epsilon = atoq("1e-100");
|
epsilon = str2q("1e-100");
|
||||||
ans = qsin(q, epsilon);
|
ans = qsin(q, epsilon);
|
||||||
|
|
||||||
There are many convenience macros similar to the ones for ZVALUEs which can
|
There are many convenience macros similar to the ones for ZVALUEs which can
|
||||||
@@ -615,14 +615,14 @@ These have the values 0, 1, and i.
|
|||||||
LAST THINGS LAST
|
LAST THINGS LAST
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
If you wish, when you are all doen you can call libcalc_call_me_last()
|
If you wish, when you are all done you can call libcalc_call_me_last()
|
||||||
to free a small amount of storage associated with the libcalc_call_me_first()
|
to free a small amount of storage associated with the libcalc_call_me_first()
|
||||||
call. This is not required, but is does bring things to a closure.
|
call. This is not required, but is does bring things to a closure.
|
||||||
|
|
||||||
The function libcalc_call_me_last() takes no args and returns void. You
|
The function libcalc_call_me_last() takes no args and returns void. You
|
||||||
need call libcalc_call_me_last() only once.
|
need call libcalc_call_me_last() only once.
|
||||||
|
|
||||||
## Copyright (C) 1999 David I. Bell and Landon Curt Noll
|
## Copyright (C) 1999,2021 David I. Bell and Landon Curt Noll
|
||||||
##
|
##
|
||||||
## Calc is open software; you can redistribute it and/or modify it under
|
## 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
|
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -638,10 +638,6 @@ need call libcalc_call_me_last() only once.
|
|||||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
##
|
##
|
||||||
## @(#) $Revision: 30.1 $
|
|
||||||
## @(#) $Id: LIBRARY,v 30.1 2007/03/16 11:09:46 chongo Exp $
|
|
||||||
## @(#) $Source: /usr/local/src/bin/calc/RCS/LIBRARY,v $
|
|
||||||
##
|
|
||||||
## Under source code control: 1993/07/30 19:44:49
|
## Under source code control: 1993/07/30 19:44:49
|
||||||
## File existed as early as: 1993
|
## File existed as early as: 1993
|
||||||
##
|
##
|
||||||
|
1410
Makefile.config
Normal file
1410
Makefile.config
Normal file
File diff suppressed because it is too large
Load Diff
111
Makefile.local
Normal file
111
Makefile.local
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
#!/usr/bin/env make
|
||||||
|
#
|
||||||
|
# Makefile.local - modify, replace or append calc Makefile variables
|
||||||
|
#
|
||||||
|
# Copyright (C) 2023 Landon Curt Noll
|
||||||
|
#
|
||||||
|
# Suggestion: Read the HOWTO.INSTALL file.
|
||||||
|
#
|
||||||
|
# Calc is open software; you can redistribute it and/or modify it under
|
||||||
|
# the terms of 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.
|
||||||
|
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
#
|
||||||
|
# This calculator first developed by David I. Bell with help/mods from others.
|
||||||
|
#
|
||||||
|
# chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||||
|
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||||
|
|
||||||
|
####
|
||||||
|
# This file is included all calc Makefiles after the last Makefile variable
|
||||||
|
# is set and before the first make rule. This makes this file suitable to
|
||||||
|
# modify, replace or append Makefile variables.
|
||||||
|
#
|
||||||
|
# To replace a Makefile variable, use := symbols. For example:
|
||||||
|
#
|
||||||
|
# CCWERR:= -Werror
|
||||||
|
#
|
||||||
|
# You can append to an existing Makefile variable using '+=' symbols.
|
||||||
|
# For example:
|
||||||
|
#
|
||||||
|
# CFLAGS+= -Ofast
|
||||||
|
####
|
||||||
|
|
||||||
|
###################################################################
|
||||||
|
# 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. #
|
||||||
|
###################################################################
|
||||||
|
|
||||||
|
####
|
||||||
|
# RHEL Diagnosing memory, thread, and crash issues:
|
||||||
|
#
|
||||||
|
# For more info see: https://github.com/google/sanitizers/wiki/AddressSanitizer
|
||||||
|
#
|
||||||
|
# This comment block was tested under:
|
||||||
|
#
|
||||||
|
# RHEL9 gcc version 11.3.1 20221121 (Red Hat 11.3.1-4) (GCC)
|
||||||
|
#
|
||||||
|
# with:
|
||||||
|
#
|
||||||
|
# libasan-11.3.1-4.3.el9.x86_64 libubsan-11.3.1-4.3.el9.x86_64
|
||||||
|
#
|
||||||
|
# NOTE: With the above version, these are NOT supported:
|
||||||
|
#
|
||||||
|
# UNSUPPORTED_FSANITIZE:= -fsanitize=nullability-arg -fsanitize=nullability-assign
|
||||||
|
#
|
||||||
|
# Uncomment these lines:
|
||||||
|
#
|
||||||
|
# DEBUG:= -O0 -g
|
||||||
|
# FSANITIZE:= -fsanitize=undefined -fsanitize=address -fsanitize=bool -fsanitize=bounds
|
||||||
|
# FSANITIZE+= -fsanitize=enum -fsanitize=vptr -fsanitize=integer-divide-by-zero
|
||||||
|
# FSANITIZE+= -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow
|
||||||
|
# FSANITIZE+= -fsanitize=nonnull-attribute -fsanitize=returns-nonnull-attribute
|
||||||
|
# FSANITIZE+= -fsanitize=null -fsanitize=shift -fsanitize=signed-integer-overflow
|
||||||
|
# FSANITIZE+= -fsanitize=unreachable -fsanitize=vla-bound
|
||||||
|
# CFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer
|
||||||
|
# LDFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer
|
||||||
|
# CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1
|
||||||
|
####
|
||||||
|
|
||||||
|
####
|
||||||
|
# macOS Diagnosing memory, thread, and crash issues:
|
||||||
|
#
|
||||||
|
# For more info see: https://github.com/google/sanitizers/wiki/AddressSanitizer
|
||||||
|
#
|
||||||
|
# This comment block was tested under:
|
||||||
|
#
|
||||||
|
# macOS 13.5 with clang version 14.0.3 (clang-1403.0.22.14.1)
|
||||||
|
#
|
||||||
|
# For more info for clang to Diagnosing memory, thread, and crash issues early, see:
|
||||||
|
#
|
||||||
|
# https://developer.apple.com/documentation/xcode/diagnosing-memory-thread-and-crash-issues-early
|
||||||
|
#
|
||||||
|
# NOTE: With the above version, these are NOT supported:
|
||||||
|
#
|
||||||
|
# UNSUPPORTED_FSANITIZE:= -fsanitize-nullability-return
|
||||||
|
#
|
||||||
|
# Uncomment these lines:
|
||||||
|
#
|
||||||
|
# DEBUG:= -O0 -g
|
||||||
|
# FSANITIZE:= -fsanitize=undefined -fsanitize=address -fsanitize=bool -fsanitize=bounds
|
||||||
|
# FSANITIZE+= -fsanitize=enum -fsanitize=vptr -fsanitize=integer-divide-by-zero
|
||||||
|
# FSANITIZE+= -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow
|
||||||
|
# FSANITIZE+= -fsanitize=nonnull-attribute -fsanitize=nullability-arg
|
||||||
|
# FSANITIZE+= -fsanitize=nullability-assign -fsanitize=returns-nonnull-attribute
|
||||||
|
# FSANITIZE+= -fsanitize=null -fsanitize=object-size -fsanitize=shift
|
||||||
|
# FSANITIZE+= -fsanitize=signed-integer-overflow -fsanitize=unreachable -fsanitize=vla-bound
|
||||||
|
# CFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer
|
||||||
|
# LDFLAGS+= -Wno-invalid-command-line-argument ${FSANITIZE} -fno-omit-frame-pointer
|
||||||
|
# CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1
|
||||||
|
####
|
5582
Makefile.simple
5582
Makefile.simple
File diff suppressed because it is too large
Load Diff
432
Makefile.target
Normal file
432
Makefile.target
Normal file
@@ -0,0 +1,432 @@
|
|||||||
|
#!/usr/bin/env make
|
||||||
|
#
|
||||||
|
# Makefile.target - platform target section
|
||||||
|
#
|
||||||
|
# Copyright (C) 2023 Landon Curt Noll
|
||||||
|
#
|
||||||
|
# Suggestion: Read the HOWTO.INSTALL file.
|
||||||
|
#
|
||||||
|
# Calc is open software; you can redistribute it and/or modify it under
|
||||||
|
# the terms of 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.
|
||||||
|
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
#
|
||||||
|
# This calculator first developed by David I. Bell with help/mods from others.
|
||||||
|
#
|
||||||
|
# chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||||
|
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||||
|
|
||||||
|
|
||||||
|
# SUGGESTION: Instead of modifying this file, consider adding
|
||||||
|
# statements to modify, replace or append Makefile
|
||||||
|
# variables in the Makefile.local file.
|
||||||
|
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
# NOTE: These lines are included by both Makefile and custom/Makefile #
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
##################################################################################
|
||||||
|
#-=-=-=-=-=- platform target section - targets that override defaults -=-=-=-=-=-#
|
||||||
|
##################################################################################
|
||||||
|
|
||||||
|
# Common values set in targets
|
||||||
|
#
|
||||||
|
# BLD_TYPE determines if calc is built with static and/or dynamic libs.
|
||||||
|
# Set this value to one of:
|
||||||
|
#
|
||||||
|
# BLD_TYPE= calc-dynamic-only
|
||||||
|
# BLD_TYPE= calc-static-only
|
||||||
|
#
|
||||||
|
# CC_SHARE are flags given to ${CC} to build .o files suitable for shared libs
|
||||||
|
# DEFAULT_LIB_INSTALL_PATH is where calc programs look for calc shared libs
|
||||||
|
# LD_SHARE are common flags given to ${CC} to link with shared libraries
|
||||||
|
# LIBCALC_SHLIB are flags given to ${CC} to build libcalc shared libraries
|
||||||
|
# LIBCUSTCALC_SHLIB are flags given to ${CC} to build libcustcalc shared lib
|
||||||
|
#
|
||||||
|
# NOTE: The above 5 values are unused if BLD_TYPE= calc-static-only
|
||||||
|
#
|
||||||
|
# CC_STATIC are flags given to ${CC} to build .o files suitable for static libs
|
||||||
|
# LD_STATIC are common flags given to ${CC} to link with static libraries
|
||||||
|
# LIBCALC_STATIC are flags given to ${CC} to build libcalc static libraries
|
||||||
|
# LIBCUSTCALC_STATIC are flags given to ${CC} to build libcustcalc static lib
|
||||||
|
#
|
||||||
|
# NOTE: The above 4 values are unused if BLD_TYPE= calc-dynamic-only
|
||||||
|
#
|
||||||
|
# CCOPT are flags given to ${CC} for optimization
|
||||||
|
# CCWARN are flags given to ${CC} for warning message control
|
||||||
|
#
|
||||||
|
# The following are given to ${CC}:
|
||||||
|
#
|
||||||
|
# WNO_IMPLICT
|
||||||
|
# WNO_ERROR_LONG_LONG
|
||||||
|
# WNO_LONG_LONG
|
||||||
|
#
|
||||||
|
# when compiling special .o files that may need special compile options:
|
||||||
|
#
|
||||||
|
# NOTE: These flags simply turn off certain compiler warnings,
|
||||||
|
# which is useful only when CCWERR is set to -Werror.
|
||||||
|
#
|
||||||
|
# NOTE: If your compiler does not have these -Wno files, just
|
||||||
|
# set these variables to nothing as in:
|
||||||
|
#
|
||||||
|
# WNO_IMPLICT=
|
||||||
|
# WNO_ERROR_LONG_LONG=
|
||||||
|
# WNO_LONG_LONG=
|
||||||
|
#
|
||||||
|
# CCWERR are flags given to ${CC} to make warnings fatal errors
|
||||||
|
# NOTE: CCWERR is only set in development Makefiles and must only be
|
||||||
|
# used with ${CC}, not ${LCC}. If you do not want the compiler
|
||||||
|
# to abort on warnings, then leave CCWERR blank.
|
||||||
|
# CCMISC are misc flags given to ${CC}
|
||||||
|
#
|
||||||
|
# CCBAN is given to ${CC} in order to control if banned.h is in effect.
|
||||||
|
# NOTE: See where CCBAN is defined above for details.
|
||||||
|
#
|
||||||
|
# LCC is how the C compiler is invoked on locally executed intermediate programs
|
||||||
|
# CC is how the C compiler is invoked (with an optional Purify)
|
||||||
|
#
|
||||||
|
# Specific target overrides or modifications to default values
|
||||||
|
|
||||||
|
|
||||||
|
################
|
||||||
|
# Linux target #
|
||||||
|
################
|
||||||
|
|
||||||
|
ifeq ($(target),Linux)
|
||||||
|
|
||||||
|
# default build type for this target
|
||||||
|
#
|
||||||
|
BLD_TYPE= calc-dynamic-only
|
||||||
|
|
||||||
|
# target specific library parameters
|
||||||
|
#
|
||||||
|
CC_SHARE= -fPIC
|
||||||
|
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
|
||||||
|
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
|
||||||
|
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
|
||||||
|
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
|
||||||
|
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
|
||||||
|
|
||||||
|
# static library option
|
||||||
|
#
|
||||||
|
CC_STATIC=
|
||||||
|
LD_STATIC=
|
||||||
|
LIBCALC_STATIC=
|
||||||
|
LIBCUSTCALC_STATIC=
|
||||||
|
|
||||||
|
# common values set for this target
|
||||||
|
#
|
||||||
|
#CCWARN= -Wall
|
||||||
|
CCWARN= -Wall -Wextra -pedantic
|
||||||
|
WNO_IMPLICT= -Wno-implicit
|
||||||
|
WNO_ERROR_LONG_LONG= -Wno-error=long-long
|
||||||
|
WNO_LONG_LONG= -Wno-long-long
|
||||||
|
CCWERR=
|
||||||
|
CCOPT= ${DEBUG}
|
||||||
|
CCMISC=
|
||||||
|
LCC= gcc
|
||||||
|
CC= ${PURIFY} ${LCC} ${CCWERR}
|
||||||
|
|
||||||
|
endif # ($(target),Linux)
|
||||||
|
|
||||||
|
|
||||||
|
###############################
|
||||||
|
# Apple macOS / Darwin target #
|
||||||
|
###############################
|
||||||
|
|
||||||
|
ifeq ($(target),Darwin)
|
||||||
|
|
||||||
|
# default build type for this target
|
||||||
|
#
|
||||||
|
BLD_TYPE= calc-dynamic-only
|
||||||
|
|
||||||
|
# For old Apple Power PC systems, we need to add:
|
||||||
|
#
|
||||||
|
# -std=gnu99 -arch ppc
|
||||||
|
#
|
||||||
|
ifeq ($(arch),powerpc)
|
||||||
|
COMMON_ADD+= -std=gnu99
|
||||||
|
ARCH_CFLAGS+= -arch ppc
|
||||||
|
endif # ($(arch),powerpc)
|
||||||
|
|
||||||
|
# target specific library parameters
|
||||||
|
#
|
||||||
|
CC_SHARE= -fPIC
|
||||||
|
DEFAULT_LIB_INSTALL_PATH= ${PWD}:${LIBDIR}:${PREFIX}/lib
|
||||||
|
LD_SHARE= ${ARCH_CFLAGS}
|
||||||
|
LIBCALC_SHLIB= -dynamiclib -undefined dynamic_lookup \
|
||||||
|
-install_name ${LIBDIR}/libcalc${LIB_EXT_VERSION} \
|
||||||
|
-current_version ${VER} \
|
||||||
|
${ARCH_CFLAGS}
|
||||||
|
LIBCUSTCALC_SHLIB= -dynamiclib -undefined dynamic_lookup \
|
||||||
|
-install_name ${LIBDIR}/libcustcalc${LIB_EXT_VERSION} \
|
||||||
|
-current_version ${VER} \
|
||||||
|
${ARCH_CFLAGS}
|
||||||
|
|
||||||
|
# To reduce dependency chains under macOS, we remove functions and
|
||||||
|
# data that are unreachable by the entry point or exported symbols.
|
||||||
|
#
|
||||||
|
COMMON_LDFLAGS+= -Wl,-dead_strip
|
||||||
|
COMMON_LDFLAGS+= -Wl,-dead_strip_dylibs
|
||||||
|
|
||||||
|
# static library option
|
||||||
|
#
|
||||||
|
CC_STATIC=
|
||||||
|
LD_STATIC= ${ARCH_CFLAGS}
|
||||||
|
LIBCALC_STATIC=
|
||||||
|
LIBCUSTCALC_STATIC=
|
||||||
|
|
||||||
|
# common values set for this target
|
||||||
|
#
|
||||||
|
#CCWARN= -Wall
|
||||||
|
CCWARN= -Wall -Wextra -pedantic
|
||||||
|
WNO_IMPLICT= -Wno-implicit
|
||||||
|
WNO_ERROR_LONG_LONG= -Wno-error=long-long
|
||||||
|
WNO_LONG_LONG= -Wno-long-long
|
||||||
|
CCWERR=
|
||||||
|
CCOPT= ${DEBUG}
|
||||||
|
CCMISC= ${ARCH_CFLAGS}
|
||||||
|
LCC= cc
|
||||||
|
CC= ${PURIFY} ${LCC} ${CCWERR}
|
||||||
|
|
||||||
|
# Darwin dynamic shared lib filenames
|
||||||
|
#
|
||||||
|
LIB_EXT:= .dylib
|
||||||
|
LIB_EXT_VERSION:= .${VERSION}${LIB_EXT}
|
||||||
|
|
||||||
|
# LDCONFIG not required on this platform, so we redefine it to an empty string
|
||||||
|
#
|
||||||
|
LDCONFIG:=
|
||||||
|
|
||||||
|
endif # ($(target),Darwin)
|
||||||
|
|
||||||
|
|
||||||
|
##################
|
||||||
|
# FreeBSD target #
|
||||||
|
##################
|
||||||
|
|
||||||
|
ifeq ($(target),FreeBSD)
|
||||||
|
|
||||||
|
# default build type for this target
|
||||||
|
#
|
||||||
|
BLD_TYPE= calc-dynamic-only
|
||||||
|
|
||||||
|
# target specific library parameters
|
||||||
|
#
|
||||||
|
CC_SHARE= -fPIC
|
||||||
|
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
|
||||||
|
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
|
||||||
|
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
|
||||||
|
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
|
||||||
|
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
|
||||||
|
|
||||||
|
CC_STATIC=
|
||||||
|
LD_STATIC=
|
||||||
|
LIBCALC_STATIC=
|
||||||
|
LIBCUSTCALC_STATIC=
|
||||||
|
|
||||||
|
# common values set for this target
|
||||||
|
#
|
||||||
|
#CCWARN= -Wall
|
||||||
|
CCWARN= -Wall -Wextra -pedantic
|
||||||
|
WNO_IMPLICT= -Wno-implicit
|
||||||
|
WNO_ERROR_LONG_LONG= -Wno-error=long-long
|
||||||
|
WNO_LONG_LONG= -Wno-long-long
|
||||||
|
CCWERR=
|
||||||
|
CCOPT= ${DEBUG}
|
||||||
|
CCMISC=
|
||||||
|
LCC= gcc
|
||||||
|
CC= ${PURIFY} ${LCC} ${CCWERR}
|
||||||
|
|
||||||
|
# We must use gmake as the FreeBSD target because under some older
|
||||||
|
# releases of FreeBSD, make not support conditional syntax.
|
||||||
|
#
|
||||||
|
MAKE= gmake
|
||||||
|
|
||||||
|
endif # ($(target),FreeBSD)
|
||||||
|
|
||||||
|
|
||||||
|
##################
|
||||||
|
# OpenBSD target #
|
||||||
|
##################
|
||||||
|
|
||||||
|
ifeq ($(target),OpenBSD)
|
||||||
|
|
||||||
|
# default build type for this target
|
||||||
|
#
|
||||||
|
BLD_TYPE= calc-dynamic-only
|
||||||
|
|
||||||
|
# default build type for this target
|
||||||
|
#
|
||||||
|
CC_SHARE= -fPIC
|
||||||
|
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
|
||||||
|
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
|
||||||
|
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
|
||||||
|
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
|
||||||
|
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
|
||||||
|
|
||||||
|
# static library option
|
||||||
|
#
|
||||||
|
CC_STATIC=
|
||||||
|
LD_STATIC=
|
||||||
|
LIBCALC_STATIC=
|
||||||
|
LIBCUSTCALC_STATIC=
|
||||||
|
|
||||||
|
# common values set for this target
|
||||||
|
#
|
||||||
|
#CCWARN= -Wall
|
||||||
|
CCWARN= -Wall -Wextra -pedantic
|
||||||
|
WNO_IMPLICT= -Wno-implicit
|
||||||
|
WNO_ERROR_LONG_LONG= -Wno-error=long-long
|
||||||
|
WNO_LONG_LONG= -Wno-long-long
|
||||||
|
CCWERR=
|
||||||
|
CCOPT= ${DEBUG}
|
||||||
|
CCMISC=
|
||||||
|
#
|
||||||
|
LCC= gcc
|
||||||
|
CC= ${PURIFY} ${LCC} ${CCWERR}
|
||||||
|
#
|
||||||
|
MAKE= gmake
|
||||||
|
#
|
||||||
|
endif # ($(target),OpenBSD)
|
||||||
|
|
||||||
|
|
||||||
|
#################
|
||||||
|
# Cygwin target #
|
||||||
|
#################
|
||||||
|
|
||||||
|
ifeq ($(target),Cygwin)
|
||||||
|
|
||||||
|
BLD_TYPE= calc-static-only
|
||||||
|
|
||||||
|
# target specific library parameters
|
||||||
|
#
|
||||||
|
CC_SHARE= -fPIC
|
||||||
|
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
|
||||||
|
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
|
||||||
|
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
|
||||||
|
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
|
||||||
|
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
|
||||||
|
|
||||||
|
# static library option
|
||||||
|
#
|
||||||
|
CC_STATIC=
|
||||||
|
LIBCALC_STATIC=
|
||||||
|
LIBCUSTCALC_STATIC=
|
||||||
|
LD_STATIC=
|
||||||
|
|
||||||
|
# common values set for this target
|
||||||
|
#
|
||||||
|
#CCWARN= -Wall
|
||||||
|
CCWARN= -Wall -Wextra -pedantic
|
||||||
|
WNO_IMPLICT= -Wno-implicit
|
||||||
|
WNO_ERROR_LONG_LONG= -Wno-error=long-long
|
||||||
|
WNO_LONG_LONG= -Wno-long-long
|
||||||
|
CCWERR=
|
||||||
|
CCOPT= ${DEBUG}
|
||||||
|
CCMISC=
|
||||||
|
LCC= cc
|
||||||
|
CC= ${PURIFY} ${LCC} ${CCWERR}
|
||||||
|
|
||||||
|
endif # ($(target),Cygwin)
|
||||||
|
|
||||||
|
|
||||||
|
###########################################
|
||||||
|
# default target - (when target is empty) #
|
||||||
|
###########################################
|
||||||
|
|
||||||
|
# NOTE: This is the default generic host target. Used when no other
|
||||||
|
# host target matches.
|
||||||
|
|
||||||
|
ifeq ($(target),)
|
||||||
|
|
||||||
|
# default build type for this target
|
||||||
|
#
|
||||||
|
BLD_TYPE= calc-static-only
|
||||||
|
|
||||||
|
# target specific library parameters
|
||||||
|
#
|
||||||
|
CC_SHARE= -fPIC
|
||||||
|
DEFAULT_LIB_INSTALL_PATH= ${PWD}:/lib:/usr/lib:${LIBDIR}:${PREFIX}/lib
|
||||||
|
LD_SHARE= "-Wl,-rpath,${DEFAULT_LIB_INSTALL_PATH}" \
|
||||||
|
"-Wl,-rpath-link,${DEFAULT_LIB_INSTALL_PATH}"
|
||||||
|
LIBCALC_SHLIB= -shared "-Wl,-soname,libcalc${LIB_EXT_VERSION}"
|
||||||
|
LIBCUSTCALC_SHLIB= -shared "-Wl,-soname,libcustcalc${LIB_EXT_VERSION}"
|
||||||
|
|
||||||
|
# static library option
|
||||||
|
#
|
||||||
|
CC_STATIC=
|
||||||
|
LIBCALC_STATIC=
|
||||||
|
LIBCUSTCALC_STATIC=
|
||||||
|
LD_STATIC=
|
||||||
|
|
||||||
|
# common values set for this target
|
||||||
|
#
|
||||||
|
#CCWARN= -Wall
|
||||||
|
CCWARN= -Wall -Wextra -pedantic
|
||||||
|
WNO_IMPLICT= -Wno-implicit
|
||||||
|
WNO_ERROR_LONG_LONG= -Wno-error=long-long
|
||||||
|
WNO_LONG_LONG= -Wno-long-long
|
||||||
|
CCWERR=
|
||||||
|
CCOPT= ${DEBUG}
|
||||||
|
CCMISC=
|
||||||
|
LCC= gcc
|
||||||
|
CC= ${PURIFY} ${LCC} ${CCWERR}
|
||||||
|
|
||||||
|
endif # ($(target),)
|
||||||
|
|
||||||
|
|
||||||
|
###########################################
|
||||||
|
# Set the default compile flags for ${CC} #
|
||||||
|
###########################################
|
||||||
|
|
||||||
|
# If you want to add flags to all compiler and linker
|
||||||
|
# run (via ${COMMON_CFLAGS} and ${COMMON_LDFLAGS}),
|
||||||
|
# set ${COMMON_ADD}.
|
||||||
|
#
|
||||||
|
# For example to use gcc's -Werror to force warnings
|
||||||
|
# to become errors, call make with:
|
||||||
|
#
|
||||||
|
# make .. COMMON_ADD='-Werror'
|
||||||
|
#
|
||||||
|
# This facility requires a Gnu Makefile, or a make command
|
||||||
|
# that understands the += make operand.
|
||||||
|
#
|
||||||
|
COMMON_CFLAGS+= ${COMMON_ADD}
|
||||||
|
COMMON_LDFLAGS+= ${COMMON_ADD}
|
||||||
|
|
||||||
|
# Required flags to compile C files for calc
|
||||||
|
#
|
||||||
|
# ICFLAGS are given to ${CC} for intermediate programs used to help compile calc
|
||||||
|
# CFLAGS are given to ${CC} for calc programs other than intermediate programs
|
||||||
|
#
|
||||||
|
# NOTE: This does not work for: make-XYZ-only and BLD_TYPE != make-XYZ-only
|
||||||
|
#
|
||||||
|
ifeq ($(BLD_TYPE),calc-static-only)
|
||||||
|
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_STATIC}
|
||||||
|
else # ($(BLD_TYPE),calc-static-only)
|
||||||
|
ICFLAGS= ${COMMON_CFLAGS} ${CCBAN} ${CC_SHARE}
|
||||||
|
endif # ($(BLD_TYPE),calc-static-only)
|
||||||
|
CFLAGS= ${ICFLAGS} ${CCOPT}
|
||||||
|
|
||||||
|
# Required flags to link files for calc
|
||||||
|
#
|
||||||
|
# ILDFLAGS for ${CC} in linking intermediate programs used to help compile calc
|
||||||
|
# LDFLAGS for ${CC} in linking calc programs other than intermediate programs
|
||||||
|
#
|
||||||
|
ILDFLAGS= ${COMMON_LDFLAGS}
|
||||||
|
LDFLAGS= ${LD_DEBUG} ${ILDFLAGS}
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
#-=-=-=-=-=- end of target section - only make rules below -=-=-=-=-=-#
|
||||||
|
#######################################################################
|
45
QUESTIONS
Normal file
45
QUESTIONS
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
If you have a general question about calc, consider opening
|
||||||
|
a new Github discussion under:
|
||||||
|
|
||||||
|
https://github.com/lcn2/calc/discussions
|
||||||
|
|
||||||
|
Look over the existing discussions to see of your question fits
|
||||||
|
under one of those exiting discussions.
|
||||||
|
|
||||||
|
You may wish to add your question as a comment to an existing discussion.
|
||||||
|
Otherwise click on:
|
||||||
|
|
||||||
|
((New discussion))
|
||||||
|
|
||||||
|
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 general questions
|
||||||
|
about calc.
|
||||||
|
|
||||||
|
Please be patient as we cannot always respond to discussion messages quickly.
|
||||||
|
|
||||||
|
=-=
|
||||||
|
|
||||||
|
## 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
|
||||||
|
## as published by the Free Software Foundation.
|
||||||
|
##
|
||||||
|
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||||
|
## Public License for more details.
|
||||||
|
##
|
||||||
|
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||||
|
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||||
|
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
##
|
||||||
|
## Under source code control: 2021/02/10 00:15:05
|
||||||
|
## File existed as early as: 2021
|
||||||
|
##
|
||||||
|
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||||
|
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
@@ -27,35 +27,35 @@ If you run into problems, see the BUGS file.
|
|||||||
Calc is distributed with an extensive collection of help files that
|
Calc is distributed with an extensive collection of help files that
|
||||||
are accessible from the command line. The following assume that you
|
are accessible from the command line. The following assume that you
|
||||||
are running calc from the distribution directory or that you have
|
are running calc from the distribution directory or that you have
|
||||||
installed calc. In these examples, the ">" is the calc prompt, not
|
installed calc. In these examples, the "; " is the calc prompt, not
|
||||||
something that you type in.
|
something that you type in.
|
||||||
|
|
||||||
For list of help topics:
|
For list of help topics:
|
||||||
|
|
||||||
> help
|
; help
|
||||||
|
|
||||||
For overview of calc overview:
|
For overview of calc overview:
|
||||||
|
|
||||||
> help intro
|
; help intro
|
||||||
> help overview
|
; help overview
|
||||||
> help command
|
; help command
|
||||||
> help define
|
; help define
|
||||||
> help statement
|
; help statement
|
||||||
> help variable
|
; help variable
|
||||||
> help usage
|
; help usage
|
||||||
|
|
||||||
For list of builtin functions:
|
For list of builtin functions:
|
||||||
|
|
||||||
> help builtin
|
; help builtin
|
||||||
|
|
||||||
C programmers should note some unexpected differences in the calc syntax:
|
C programmers should note some unexpected differences with the calc syntax:
|
||||||
|
|
||||||
> help unexpected
|
; help unexpected
|
||||||
|
|
||||||
Calc is shipped with a standard collection of calc resource files.
|
Calc is shipped with a standard collection of calc resource files.
|
||||||
For a list of calc standard resource files see:
|
For a list of calc standard resource files see:
|
||||||
|
|
||||||
> help resource
|
; help resource
|
||||||
|
|
||||||
=-=
|
=-=
|
||||||
|
|
||||||
@@ -71,66 +71,33 @@ or run:
|
|||||||
|
|
||||||
for a wish/todo list. Code contributions are welcome.
|
for a wish/todo list. Code contributions are welcome.
|
||||||
|
|
||||||
=-=
|
-=-
|
||||||
|
|
||||||
To subscribe to the calc-tester mailing list, visit the following URL:
|
If you you notice something wrong, strange or broken, see the file:
|
||||||
|
|
||||||
http://www.isthe.com/chongo/tech/comp/calc/calc-tester.html
|
BUGS
|
||||||
|
|
||||||
This is a low volume moderated mailing list.
|
or run:
|
||||||
|
|
||||||
This mailing list replaces calc-tester at asthe dot com list.
|
calc help bugs
|
||||||
|
|
||||||
If you need a human to help you with your mailing list subscription,
|
for information about how to report a bug.
|
||||||
please send EMail to our special:
|
|
||||||
|
|
||||||
calc-tester-maillist-help at asthe dot com
|
|
||||||
|
|
||||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
|
||||||
|
|
||||||
address. To be sure we see your EMail asking for help with your
|
|
||||||
mailing list subscription, please use the following phase in your
|
|
||||||
EMail Subject line:
|
|
||||||
|
|
||||||
calc tester mailing list help
|
|
||||||
|
|
||||||
That phrase in your subject line will help ensure your
|
|
||||||
request will get past our anti-spam filters. You may have
|
|
||||||
additional words in your subject line.
|
|
||||||
|
|
||||||
-=-
|
-=-
|
||||||
|
|
||||||
Calc bug reports and calc bug fixes should be sent to:
|
If you have a general question about calc, see the file:
|
||||||
|
|
||||||
calc-bug-report at asthe dot com
|
QUESTIONS
|
||||||
|
|
||||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
or run:
|
||||||
|
|
||||||
This replaces the old calc-bugs at asthe dot com address.
|
calc help questions
|
||||||
|
|
||||||
To be sure we see your EMail reporting a calc bug, please use the
|
for information about how to ask a question.
|
||||||
following phase in your EMail Subject line:
|
|
||||||
|
|
||||||
calc bug report
|
|
||||||
|
|
||||||
That phrase in your subject line will help ensure your
|
|
||||||
request will get past our anti-spam filters. You may have
|
|
||||||
additional words in your subject line.
|
|
||||||
|
|
||||||
However, you may find it more helpful to simply subscribe
|
|
||||||
to the calc-tester mailing list (see above) and then to
|
|
||||||
send your report to that mailing list as a wider set calc
|
|
||||||
testers may be able to help you.
|
|
||||||
|
|
||||||
-=-
|
-=-
|
||||||
|
|
||||||
The calc web site is located at:
|
## Copyright (C) 1999,2014,2017,2021 Landon Curt Noll
|
||||||
|
|
||||||
http://www.isthe.com/chongo/tech/comp/calc/
|
|
||||||
|
|
||||||
NOTE: The EMail address uses 'asthe', while the web site uses 'isthe'.
|
|
||||||
|
|
||||||
## Copyright (C) 1999,2014 Landon Curt Noll
|
|
||||||
##
|
##
|
||||||
## Calc is open software; you can redistribute it and/or modify it under
|
## 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
|
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -146,10 +113,6 @@ NOTE: The EMail address uses 'asthe', while the web site uses 'isthe'.
|
|||||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
##
|
##
|
||||||
## @(#) $Revision: 30.3 $
|
|
||||||
## @(#) $Id: README,v 30.3 2014/10/12 12:23:43 chongo Exp $
|
|
||||||
## @(#) $Source: /usr/local/src/bin/calc/RCS/README,v $
|
|
||||||
##
|
|
||||||
## Under source code control: 1995/10/25 05:27:59
|
## Under source code control: 1995/10/25 05:27:59
|
||||||
## File existed as early as: 1995
|
## File existed as early as: 1995
|
||||||
##
|
##
|
117
README.RELEASE
Normal file
117
README.RELEASE
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
On calc versions and releases
|
||||||
|
|
||||||
|
Calc version numbers have 4 levels. For example:
|
||||||
|
|
||||||
|
++=== top 2 levels: calc builtin functions compatibility
|
||||||
|
||
|
||||||
|
vvvv
|
||||||
|
|
||||||
|
2.14.0.8
|
||||||
|
\\\\\\
|
||||||
|
^ \\\\----> top 3 levels: calc important code base change
|
||||||
|
|
|
||||||
|
+--- top version level: internal representation compatibility
|
||||||
|
|
||||||
|
The top version level (e.g., 2) refers to the internal representation
|
||||||
|
of values. Any library or hardware linked/built for calc 2 will be able
|
||||||
|
to use values from other 2.x.y.z versions.
|
||||||
|
|
||||||
|
The top 2 levels (e.g., 2.14) refers to a specific compatible set of
|
||||||
|
builtin functions. Calc interpreted code (such as calc resource files)
|
||||||
|
written for, say calc 2.14, will be able to use the same set of builtin
|
||||||
|
functions for any other 2.14.y.z version. Any new builtin functions or
|
||||||
|
significant changes to existing builtin functions would be introduced in
|
||||||
|
a later release such as version 2.15.y.z. While calc scripts written for
|
||||||
|
2.14.y.z will highly likely be able to run under version 2.15.y.z, any
|
||||||
|
new builtin functions added in calc 2.15 may collide with an identically
|
||||||
|
named used defined function.
|
||||||
|
|
||||||
|
The top 3 levels (e.g., 2.14.0) change to reflect an important change to
|
||||||
|
the code base such as a bug fix or performance improvement. There was
|
||||||
|
neither a change to the internal representation format (a top level
|
||||||
|
version change), nor were there new calc builtins introduced in such
|
||||||
|
a top 3 level release.
|
||||||
|
|
||||||
|
There are 3 classes of changes to the calc source tree:
|
||||||
|
|
||||||
|
alpha => untagged GitHub commit
|
||||||
|
|
||||||
|
Any untagged commit to the GitHub master branch should be
|
||||||
|
considered as alpha code that may make calc unstable.
|
||||||
|
|
||||||
|
While we try to avoid breaking the calc code with commits,
|
||||||
|
there is a risk that picking up such a change could
|
||||||
|
negatively impact the code.
|
||||||
|
|
||||||
|
tested => tagged GitHub pre-release commit
|
||||||
|
|
||||||
|
A new version of calc has been released and has recently passed
|
||||||
|
regression testing on at least to different platforms and chip
|
||||||
|
architectures.
|
||||||
|
|
||||||
|
The "tested" class was historically called "untested",
|
||||||
|
however this term was misleading as such releases ARE tested.
|
||||||
|
Since 2.14.0.13 we have used the term "tested".
|
||||||
|
|
||||||
|
All tested releases are tagged with a new version number.
|
||||||
|
Such releases have GitHub assets such as a source tarball,
|
||||||
|
zip file, source rpm, development rpm and binary rpm. See the
|
||||||
|
orange "Pre-release" GitHub releases under:
|
||||||
|
|
||||||
|
https://github.com/lcn2/calc/releases
|
||||||
|
|
||||||
|
At the bottom of a given release is a "> Assets" that may
|
||||||
|
be opened to reveal down-loadable files.
|
||||||
|
|
||||||
|
production => tagged GitHub release commit
|
||||||
|
|
||||||
|
A new version of calc has been released and has undergone
|
||||||
|
extensive testing over time over a number of platforms.
|
||||||
|
Sometimes a "tested" release that is found work well over
|
||||||
|
a period of time will be re-released with a new version
|
||||||
|
number as a "production" release.
|
||||||
|
|
||||||
|
The latest production GitHub release is marked with green
|
||||||
|
"Latest" label under:
|
||||||
|
|
||||||
|
https://github.com/lcn2/calc/releases
|
||||||
|
|
||||||
|
A release that has neither an orange "Pre-release" nor
|
||||||
|
a green "Latest" label is a prior production class release.
|
||||||
|
|
||||||
|
At the bottom of a given release is a "> Assets" that may
|
||||||
|
be opened to reveal down-loadable files.
|
||||||
|
|
||||||
|
Production class code where stability is critical should use a
|
||||||
|
"production" release.
|
||||||
|
|
||||||
|
A historical note and apology:
|
||||||
|
|
||||||
|
In the past, some version number changes were made that did not fully
|
||||||
|
reflect the above version number or change class. Moreover older terms
|
||||||
|
such as "stable" and "unstable" were misleading and did not properly
|
||||||
|
reflect the nature of the change. Sorry! The purpose of this document
|
||||||
|
is to try and bring a better level of conformity to source code updates,
|
||||||
|
tagged releases and version numbers.
|
||||||
|
|
||||||
|
## Copyright (C) 2021 Landon Curt Noll
|
||||||
|
##
|
||||||
|
## Calc is open software; you can redistribute it and/or modify it under
|
||||||
|
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
|
## as published by the Free Software Foundation.
|
||||||
|
##
|
||||||
|
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||||
|
## Public License for more details.
|
||||||
|
##
|
||||||
|
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||||
|
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||||
|
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
##
|
||||||
|
## Under source code control: 2021/12/12 19:36:26
|
||||||
|
## File existed as early as: 2021
|
||||||
|
##
|
||||||
|
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||||
|
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
168
README.WINDOWS
168
README.WINDOWS
@@ -1,48 +1,111 @@
|
|||||||
Dear calc user on a Windoz based system,
|
Dear calc user on a Windows based system,
|
||||||
|
|
||||||
See the HOWTO.INSTALL file for information on how to build and install calc.
|
See the HOWTO.INSTALL file for information on how to build and install calc.
|
||||||
See also the README file.
|
See also the README file.
|
||||||
|
|
||||||
NOTE: The main developers do not have access to a Windoz based platform.
|
Please also add notes to the 'Compiling calc under Windows 11'
|
||||||
While we will make an effort to not break calc Windoz based system,
|
and 'Compiling with Cygwin' section in README.WINDOWS file.
|
||||||
our lack of a Windoz test environment will mean we will make mistakes
|
|
||||||
from time to time. Hopefully Windowz users can overcome these mistakes.
|
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,
|
||||||
|
our lack of a Windows test environment will mean we will make mistakes
|
||||||
|
from time to time. Hopefully Windows users can overcome these mistakes.
|
||||||
Of course you are welcome to send us any patches that fix your
|
Of course you are welcome to send us any patches that fix your
|
||||||
Windoz build environment.
|
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 could use Cygwin:
|
||||||
|
|
||||||
|
https://cygwin.com/install.html
|
||||||
|
|
||||||
|
IMPORTANT: While installing Cygwin, and during Cygwin Setup, be sure to
|
||||||
|
select all the MinGW64 packages relating to gcc.
|
||||||
|
|
||||||
|
See the "Compiling with Cygwin" section below.
|
||||||
|
|
||||||
|
NOTE: Compiling calc under Windows 11 is work in progress. If you run into
|
||||||
|
problems, consider the "Compiling with Cygwin" section below.
|
||||||
|
|
||||||
|
|
||||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
=-= compiling with Cygwin =-=
|
=-= Compiling with Cygwin =-=
|
||||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
|
|
||||||
An effort is being made to allow windows users to compile calc using the
|
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
|
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
|
The major porting work for Cygwin was performed by Thomas Jones-Low
|
||||||
(tjoneslo at softstart dot com).
|
(tjoneslo at softstart dot com).
|
||||||
|
|
||||||
In March 2009, Michael Penk (mpenk at wuska dot com) reported success in
|
In December 2022, GitHub user @Leoongithub successfully compiled
|
||||||
installs under Cygwin:
|
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,
|
0. Install the latest version of cygwin (https://cygwin.com/install.html).
|
||||||
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.
|
|
||||||
|
|
||||||
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
|
NOTE: The addition of "target=Cygwin" to make commands below
|
||||||
make check
|
is done just in case the target is not set properly by make.
|
||||||
make install
|
|
||||||
|
|
||||||
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
|
NOTE: The make command assume you are at the top of the calc source directory.
|
||||||
one builds and installs calc.
|
|
||||||
|
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 =-=
|
=-= If all else fails, for Cygwin =-=
|
||||||
@@ -63,9 +126,13 @@ needs.
|
|||||||
|
|
||||||
In particular:
|
In particular:
|
||||||
|
|
||||||
Just copy the win32/*.[ch] files up into the top level calc
|
Just copy the win32/*.[ch] files up into the top level calc
|
||||||
source directory, edit them (if needed) and build using the
|
source directory, edit them (if needed) and build using the
|
||||||
Cygwin GCC compiler and Cygwin build environment.
|
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 =-=
|
=-= compiling under DJGPP =-=
|
||||||
@@ -111,9 +178,11 @@ recommends the following settings:
|
|||||||
CATDIR= /dev/env/DJDIR/man/cat1
|
CATDIR= /dev/env/DJDIR/man/cat1
|
||||||
NROFF= groff
|
NROFF= groff
|
||||||
CALCPATH= .;./cal;~/.cal;${CALC_SHAREDIR};${CUSTOMCALDIR}
|
CALCPATH= .;./cal;~/.cal;${CALC_SHAREDIR};${CUSTOMCALDIR}
|
||||||
CALCRC= ${CALC_SHAREDIR}/startup;~/.calcrc;./.calcinit
|
CALCRC= ./.calcinit;~/.calcrc;${CALC_SHAREDIR}/startup
|
||||||
CALCPAGER= less.exe -ci
|
CALCPAGER= less.exe -ci
|
||||||
DEBUG= -O2 -gstabs+ -DWINDOZ
|
DEBUG= -O2 -gstabs+ -D_WIN32
|
||||||
|
HAVE_ENVIRON=-DHAVE_NO_ENVIRON
|
||||||
|
HAVE_ARC4RANDOM=-DHAVE_NO_ARC4RANDOM
|
||||||
|
|
||||||
The 'Linux set' or 'gcc set' (see the Select your compiler type section)
|
The 'Linux set' or 'gcc set' (see the Select your compiler type section)
|
||||||
should work for DJGPP systems if you set the above Makefile variables.
|
should work for DJGPP systems if you set the above Makefile variables.
|
||||||
@@ -125,8 +194,43 @@ Look for Makefile comments of the form:
|
|||||||
Follow those recommendations. In cases where they conflict with
|
Follow those recommendations. In cases where they conflict with
|
||||||
the above Makefile list, follow the recommendation in the Makefile.
|
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 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
|
## 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
|
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -142,10 +246,6 @@ the above Makefile list, follow the recommendation in the Makefile.
|
|||||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
##
|
##
|
||||||
## @(#) $Revision: 30.2 $
|
|
||||||
## @(#) $Id: README.WINDOWS,v 30.2 2009/03/14 02:29:31 chongo Exp $
|
|
||||||
## @(#) $Source: /usr/local/src/bin/calc/RCS/README.WINDOWS,v $
|
|
||||||
##
|
|
||||||
## Under source code control: 2001/02/25 14:00:05
|
## Under source code control: 2001/02/25 14:00:05
|
||||||
## File existed as early as: 2001
|
## File existed as early as: 2001
|
||||||
##
|
##
|
||||||
|
285
README.md
Normal file
285
README.md
Normal file
@@ -0,0 +1,285 @@
|
|||||||
|
# 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
|
||||||
|
numeric calculations, but which also can be easily programmed
|
||||||
|
for difficult or long calculations. It can accept a command line
|
||||||
|
argument, in which case it executes that single command and exits.
|
||||||
|
Otherwise, it enters interactive mode. In this mode, it accepts
|
||||||
|
commands one at a time, processes them, and displays the answers.
|
||||||
|
In the simplest case, commands are simply expressions which are
|
||||||
|
evaluated. For example, the following line can be input:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
3 * (4 + 1)
|
||||||
|
```
|
||||||
|
|
||||||
|
and the calculator will print:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
15
|
||||||
|
```
|
||||||
|
|
||||||
|
Calc has the usual collection of arithmetic operators +, -, /, * as
|
||||||
|
well as ^ (exponentiation), % (modulus) and // (integer divide).
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
3 * 19^43 - 1
|
||||||
|
```
|
||||||
|
|
||||||
|
will produce:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
29075426613099201338473141505176993450849249622191102976
|
||||||
|
```
|
||||||
|
|
||||||
|
Notice that calc values can be very large. For example:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
2^23209-1
|
||||||
|
```
|
||||||
|
|
||||||
|
will print:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
402874115778988778181873329071 ... many digits ... 3779264511
|
||||||
|
```
|
||||||
|
|
||||||
|
The special '.' symbol (called dot), represents the result of the
|
||||||
|
last command expression, if any. This is of great use when a series
|
||||||
|
of partial results are calculated, or when the output mode is changed
|
||||||
|
and the last result needs to be redisplayed. For example, the above
|
||||||
|
result can be modified by typing:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
. % (2^127-1)
|
||||||
|
```
|
||||||
|
|
||||||
|
and the calculator will print:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
47385033654019111249345128555354223304
|
||||||
|
```
|
||||||
|
|
||||||
|
For more complex calculations, variables can be used to save the
|
||||||
|
intermediate results. For example, the result of adding 7 to the
|
||||||
|
previous result can be saved by typing:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
curds = 15
|
||||||
|
whey = 7 + 2*curds
|
||||||
|
```
|
||||||
|
|
||||||
|
Functions can be used in expressions. There are a great number of
|
||||||
|
pre-defined functions. For example, the following will calculate
|
||||||
|
the factorial of the value of 'whey':
|
||||||
|
|
||||||
|
```sh
|
||||||
|
fact(whey)
|
||||||
|
```
|
||||||
|
|
||||||
|
and the calculator prints:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
13763753091226345046315979581580902400000000
|
||||||
|
```
|
||||||
|
|
||||||
|
The calculator also knows about complex numbers, so that typing:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
(2+3i) * (4-3i)
|
||||||
|
cos(.)
|
||||||
|
```
|
||||||
|
|
||||||
|
will print:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
17+6i
|
||||||
|
-55.50474777265624667147+193.9265235748927986537i
|
||||||
|
```
|
||||||
|
|
||||||
|
The calculator can calculate transcendental functions, and accept and
|
||||||
|
display numbers in real or exponential format. For example, typing:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
config("display", 70),
|
||||||
|
epsilon(1e-70),
|
||||||
|
sin(1)
|
||||||
|
```
|
||||||
|
|
||||||
|
prints:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
0.8414709848078965066525023216302989996225630607983710656727517099919104
|
||||||
|
```
|
||||||
|
|
||||||
|
Calc can output values in terms of fractions, octal or hexadecimal.
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
config("mode", "fraction"),
|
||||||
|
(17/19)^23
|
||||||
|
print
|
||||||
|
base(16),
|
||||||
|
(19/17)^29
|
||||||
|
print
|
||||||
|
log(79.3i)
|
||||||
|
```
|
||||||
|
|
||||||
|
will print:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
19967568900859523802559065713/257829627945307727248226067259
|
||||||
|
|
||||||
|
0x9201e65bdbb801eaf403f657efcf863/0x5cd2e2a01291ffd73bee6aa7dcf7d1
|
||||||
|
|
||||||
|
0x17b5164ac24ee836bf/0xc7b7a8e3ef5fcf752+0x883eaf5adadd26be3/0xc7b7a8e3ef5fcf752i
|
||||||
|
```
|
||||||
|
|
||||||
|
All numbers are represented as fractions with arbitrarily large
|
||||||
|
numerators and denominators which are always reduced to lowest terms.
|
||||||
|
Real or exponential format numbers can be input and are converted
|
||||||
|
to the equivalent fraction. Hex, binary, or octal numbers can be
|
||||||
|
input by using numbers with leading '0x', '0b' or '0' characters.
|
||||||
|
Complex numbers can be input using a trailing 'i', as in '2+3i'.
|
||||||
|
Strings and characters are input by using single or double quotes.
|
||||||
|
|
||||||
|
Commands are statements in a C-like language, where each input
|
||||||
|
line is treated as the body of a procedure. Thus the command
|
||||||
|
line can contain variable declarations, expressions, labels,
|
||||||
|
conditional tests, and loops. Assignments to any variable name
|
||||||
|
will automatically define that name as a global variable. The
|
||||||
|
other important thing to know is that all non-assignment expressions
|
||||||
|
which are evaluated are automatically printed. Thus, you can evaluate
|
||||||
|
an expression's value by simply typing it in.
|
||||||
|
|
||||||
|
Many useful built-in mathematical functions are available. Use the:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
help builtin
|
||||||
|
```
|
||||||
|
|
||||||
|
command to list them.
|
||||||
|
|
||||||
|
You can also define your own functions by using the 'define' keyword,
|
||||||
|
followed by a function declaration very similar to C.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
define f2(n)
|
||||||
|
{
|
||||||
|
local ans;
|
||||||
|
|
||||||
|
ans = 1;
|
||||||
|
while (n > 1)
|
||||||
|
ans *= (n -= 2);
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Thus the input:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
f2(79)
|
||||||
|
```
|
||||||
|
|
||||||
|
will produce:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
1009847364737869270905302433221592504062302663202724609375
|
||||||
|
```
|
||||||
|
|
||||||
|
Functions which only need to return a simple expression can be defined
|
||||||
|
using an equals sign, as in the example:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
define sc(a,b) = a^3 + b^3
|
||||||
|
```
|
||||||
|
|
||||||
|
Thus the input:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sc(31, 61)
|
||||||
|
```
|
||||||
|
|
||||||
|
will produce:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
256772
|
||||||
|
```
|
||||||
|
|
||||||
|
Variables in functions can be defined as either 'global', 'local',
|
||||||
|
or 'static'. Global variables are common to all functions and the
|
||||||
|
command line, whereas local variables are unique to each function
|
||||||
|
level, and are destroyed when the function returns. Static variables
|
||||||
|
are scoped within single input files, or within functions, and are
|
||||||
|
never destroyed. Variables are not typed at definition time, but
|
||||||
|
dynamically change as they are used.
|
||||||
|
|
||||||
|
For more information about the calc language and features, try:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
help overview
|
||||||
|
```
|
||||||
|
|
||||||
|
Calc has a help command that will produce information about
|
||||||
|
every builtin function, command as well as a number of other
|
||||||
|
aspects of calc usage. Try the command:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
help help
|
||||||
|
```
|
||||||
|
|
||||||
|
for and overview of the help system. The command:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
help builtin
|
||||||
|
```
|
||||||
|
|
||||||
|
provides information on built-in mathematical functions, whereas:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
help asinh
|
||||||
|
```
|
||||||
|
|
||||||
|
will provides information a specific function. The following
|
||||||
|
help files:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
help command
|
||||||
|
help define
|
||||||
|
help operator
|
||||||
|
help statement
|
||||||
|
help variable
|
||||||
|
```
|
||||||
|
|
||||||
|
provide a good overview of the calc language. If you are familiar
|
||||||
|
with C, you should also try:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
help unexpected
|
||||||
|
```
|
||||||
|
|
||||||
|
It contains information about differences between C and calc
|
||||||
|
that may surprise C programmers.
|
19
SECURITY.md
Normal file
19
SECURITY.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
The most recent version of calc is supported with security updates.
|
||||||
|
|
||||||
|
If the most recent stable of calc is also supported with security updates.
|
||||||
|
|
||||||
|
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.
|
29
addop.c
29
addop.c
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* addop - add opcodes to a function being compiled
|
* addop - add opcodes to a function being compiled
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2007 David I. Bell and Ernest Bowen
|
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Ernest Bowen
|
||||||
*
|
*
|
||||||
* Primary author: David I. Bell
|
* Primary author: David I. Bell
|
||||||
*
|
*
|
||||||
@@ -19,10 +19,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: addop.c,v 30.1 2007/03/16 11:09:46 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/RCS/addop.c,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1990/02/15 01:48:10
|
* Under source code control: 1990/02/15 01:48:10
|
||||||
* File existed as early as: before 1990
|
* File existed as early as: before 1990
|
||||||
*
|
*
|
||||||
@@ -32,6 +28,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "calc.h"
|
#include "calc.h"
|
||||||
|
#include "alloc.h"
|
||||||
#include "opcodes.h"
|
#include "opcodes.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "func.h"
|
#include "func.h"
|
||||||
@@ -40,6 +37,10 @@
|
|||||||
#include "symbol.h"
|
#include "symbol.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "attribute.h"
|
||||||
|
#include "banned.h" /* include after system header <> includes */
|
||||||
|
|
||||||
|
|
||||||
#define FUNCALLOCSIZE 20 /* reallocate size for functions */
|
#define FUNCALLOCSIZE 20 /* reallocate size for functions */
|
||||||
#define OPCODEALLOCSIZE 100 /* reallocate size for opcodes in functions */
|
#define OPCODEALLOCSIZE 100 /* reallocate size for opcodes in functions */
|
||||||
|
|
||||||
@@ -68,12 +69,12 @@ initfunctions(void)
|
|||||||
functemplate = (FUNC *) malloc(funcsize(maxopcodes));
|
functemplate = (FUNC *) malloc(funcsize(maxopcodes));
|
||||||
if (functemplate == NULL) {
|
if (functemplate == NULL) {
|
||||||
math_error("Cannot allocate function template");
|
math_error("Cannot allocate function template");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
functions = (FUNC **) malloc(sizeof(FUNC *) * FUNCALLOCSIZE);
|
functions = (FUNC **) malloc(sizeof(FUNC *) * FUNCALLOCSIZE);
|
||||||
if (functions == NULL) {
|
if (functions == NULL) {
|
||||||
math_error("Cannot allocate function table");
|
math_error("Cannot allocate function table");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
funccount = 0;
|
funccount = 0;
|
||||||
funcavail = FUNCALLOCSIZE;
|
funcavail = FUNCALLOCSIZE;
|
||||||
@@ -155,7 +156,7 @@ beginfunc(char *name, BOOL newflag)
|
|||||||
fp = (FUNC *) malloc(funcsize(maxopcodes));
|
fp = (FUNC *) malloc(funcsize(maxopcodes));
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
math_error("Cannot allocate temporary function");
|
math_error("Cannot allocate temporary function");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fp->f_next = NULL;
|
fp->f_next = NULL;
|
||||||
@@ -203,7 +204,7 @@ endfunc(void)
|
|||||||
fp = (FUNC *) malloc(size);
|
fp = (FUNC *) malloc(size);
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
math_error("Cannot commit function");
|
math_error("Cannot commit function");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
memcpy((char *) fp, (char *) curfunc, size);
|
memcpy((char *) fp, (char *) curfunc, size);
|
||||||
if (curfunc != functemplate)
|
if (curfunc != functemplate)
|
||||||
@@ -257,13 +258,13 @@ adduserfunc(char *name)
|
|||||||
sizeof(FUNC *) * (funcavail + FUNCALLOCSIZE));
|
sizeof(FUNC *) * (funcavail + FUNCALLOCSIZE));
|
||||||
if (functions == NULL) {
|
if (functions == NULL) {
|
||||||
math_error("Failed to reallocate function table");
|
math_error("Failed to reallocate function table");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
funcavail += FUNCALLOCSIZE;
|
funcavail += FUNCALLOCSIZE;
|
||||||
}
|
}
|
||||||
if (addstr(&funcnames, name) == NULL) {
|
if (addstr(&funcnames, name) == NULL) {
|
||||||
math_error("Cannot save function name");
|
math_error("Cannot save function name");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
index = funccount++;
|
index = funccount++;
|
||||||
functions[index] = NULL;
|
functions[index] = NULL;
|
||||||
@@ -316,7 +317,7 @@ freefunc(FUNC *fp)
|
|||||||
}
|
}
|
||||||
if (index == funccount) {
|
if (index == funccount) {
|
||||||
math_error("Bad call to freefunc!!!");
|
math_error("Bad call to freefunc!!!");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) {
|
if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) {
|
||||||
@@ -386,7 +387,7 @@ findfunc(long index)
|
|||||||
{
|
{
|
||||||
if (index >= funccount) {
|
if (index >= funccount) {
|
||||||
math_error("Undefined function");
|
math_error("Undefined function");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
return functions[index];
|
return functions[index];
|
||||||
}
|
}
|
||||||
@@ -438,7 +439,7 @@ addop(long op)
|
|||||||
fp = (FUNC *) malloc(funcsize(maxopcodes));
|
fp = (FUNC *) malloc(funcsize(maxopcodes));
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
math_error("cannot malloc function");
|
math_error("cannot malloc function");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
memcpy((char *) fp, (char *) curfunc,
|
memcpy((char *) fp, (char *) curfunc,
|
||||||
funcsize(curfunc->f_opcodecount));
|
funcsize(curfunc->f_opcodecount));
|
||||||
|
23
align32.c
23
align32.c
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* align32 - determine if 32 bit accesses must be aligned
|
* align32 - determine if 32 bit accesses must be aligned
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 Landon Curt Noll
|
* Copyright (C) 1999,2021 Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: align32.c,v 30.1 2007/03/16 11:09:46 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/RCS/align32.c,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1995/11/23 05:18:06
|
* Under source code control: 1995/11/23 05:18:06
|
||||||
* File existed as early as: 1995
|
* File existed as early as: 1995
|
||||||
*
|
*
|
||||||
@@ -31,6 +27,11 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include "have_stdlib.h"
|
||||||
|
#if defined(HAVE_STDLIB_H)
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "longbits.h"
|
#include "longbits.h"
|
||||||
|
|
||||||
#include "have_unistd.h"
|
#include "have_unistd.h"
|
||||||
@@ -38,7 +39,13 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void buserr(void); /* catch alignment errors */
|
#include "have_unused.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "banned.h" /* include after system header <> includes */
|
||||||
|
|
||||||
|
|
||||||
|
static void buserr(int arg); /* catch alignment errors */
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -46,7 +53,7 @@ main(void)
|
|||||||
{
|
{
|
||||||
char byte[2*sizeof(USB32)]; /* mis-alignment buffer */
|
char byte[2*sizeof(USB32)]; /* mis-alignment buffer */
|
||||||
USB32 *p; /* mis-alignment pointer */
|
USB32 *p; /* mis-alignment pointer */
|
||||||
int i;
|
unsigned long i;
|
||||||
|
|
||||||
#if defined(MUST_ALIGN32)
|
#if defined(MUST_ALIGN32)
|
||||||
/* force alignment */
|
/* force alignment */
|
||||||
@@ -82,7 +89,7 @@ main(void)
|
|||||||
*/
|
*/
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
static void
|
static void
|
||||||
buserr(int arg)
|
buserr(int UNUSED(arg))
|
||||||
{
|
{
|
||||||
/* alignment is required */
|
/* alignment is required */
|
||||||
printf("#define MUST_ALIGN32\t%c* must align 32 bit values *%c\n",
|
printf("#define MUST_ALIGN32\t%c* must align 32 bit values *%c\n",
|
||||||
|
6
alloc.h
6
alloc.h
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.5 $
|
|
||||||
* @(#) $Id: alloc.h,v 30.5 2014/08/24 21:56:51 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/RCS/alloc.h,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1990/02/15 01:48:29
|
* Under source code control: 1990/02/15 01:48:29
|
||||||
* File existed as early as: before 1990
|
* File existed as early as: before 1990
|
||||||
*
|
*
|
||||||
@@ -46,9 +42,7 @@
|
|||||||
# include <string.h>
|
# include <string.h>
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#if defined(_WIN32) && defined(NOTCYGWIN)
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
# if defined(HAVE_NEWSTR)
|
# if defined(HAVE_NEWSTR)
|
||||||
E_FUNC void *memcpy();
|
E_FUNC void *memcpy();
|
||||||
|
30
assocfunc.c
30
assocfunc.c
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* assocfunc - association table routines
|
* assocfunc - association table routines
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2007 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
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.3 $
|
|
||||||
* @(#) $Id: assocfunc.c,v 30.3 2014/09/30 00:55:11 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/RCS/assocfunc.c,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1993/07/20 23:04:27
|
* Under source code control: 1993/07/20 23:04:27
|
||||||
* File existed as early as: 1993
|
* File existed as early as: 1993
|
||||||
*
|
*
|
||||||
@@ -40,6 +36,10 @@
|
|||||||
#include "value.h"
|
#include "value.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "attribute.h"
|
||||||
|
#include "banned.h" /* include after system header <> includes */
|
||||||
|
|
||||||
|
|
||||||
#define MINHASHSIZE 31 /* minimum size of hash tables */
|
#define MINHASHSIZE 31 /* minimum size of hash tables */
|
||||||
#define GROWHASHSIZE 50 /* approximate growth for hash tables */
|
#define GROWHASHSIZE 50 /* approximate growth for hash tables */
|
||||||
#define CHAINLENGTH 10 /* desired number of elements on a hash chain */
|
#define CHAINLENGTH 10 /* desired number of elements on a hash chain */
|
||||||
@@ -75,7 +75,7 @@ associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices)
|
|||||||
|
|
||||||
if (dim < 0) {
|
if (dim < 0) {
|
||||||
math_error("Negative dimension for indexing association");
|
math_error("Negative dimension for indexing association");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -113,7 +113,7 @@ associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices)
|
|||||||
ep = (ASSOCELEM *) malloc(ELEMSIZE(dim));
|
ep = (ASSOCELEM *) malloc(ELEMSIZE(dim));
|
||||||
if (ep == NULL) {
|
if (ep == NULL) {
|
||||||
math_error("Cannot allocate association element");
|
math_error("Cannot allocate association element");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
ep->e_dim = dim;
|
ep->e_dim = dim;
|
||||||
ep->e_hash = hash;
|
ep->e_hash = hash;
|
||||||
@@ -143,13 +143,13 @@ assocsearch(ASSOC *ap, VALUE *vp, long i, long j, ZVALUE *index)
|
|||||||
|
|
||||||
if (i < 0 || j > ap->a_count) {
|
if (i < 0 || j > ap->a_count) {
|
||||||
math_error("This should not happen in assocsearch");
|
math_error("This should not happen in assocsearch");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
while (i < j) {
|
while (i < j) {
|
||||||
ep = elemindex(ap, i);
|
ep = elemindex(ap, i);
|
||||||
if (ep == NULL) {
|
if (ep == NULL) {
|
||||||
math_error("This should not happen in assocsearch");
|
math_error("This should not happen in assocsearch");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
if (acceptvalue(&ep->e_value, vp)) {
|
if (acceptvalue(&ep->e_value, vp)) {
|
||||||
utoz(i, index);
|
utoz(i, index);
|
||||||
@@ -173,14 +173,14 @@ assocrsearch(ASSOC *ap, VALUE *vp, long i, long j, ZVALUE *index)
|
|||||||
|
|
||||||
if (i < 0 || j > ap->a_count) {
|
if (i < 0 || j > ap->a_count) {
|
||||||
math_error("This should not happen in assocsearch");
|
math_error("This should not happen in assocsearch");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
j--;
|
j--;
|
||||||
while (j >= i) {
|
while (j >= i) {
|
||||||
ep = elemindex(ap, j);
|
ep = elemindex(ap, j);
|
||||||
if (ep == NULL) {
|
if (ep == NULL) {
|
||||||
math_error("This should not happen in assocsearch");
|
math_error("This should not happen in assocsearch");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
if (acceptvalue(&ep->e_value, vp)) {
|
if (acceptvalue(&ep->e_value, vp)) {
|
||||||
utoz(j, index);
|
utoz(j, index);
|
||||||
@@ -334,7 +334,7 @@ assoccopy(ASSOC *oldap)
|
|||||||
if (ep == NULL) {
|
if (ep == NULL) {
|
||||||
math_error("Cannot allocate "
|
math_error("Cannot allocate "
|
||||||
"association element");
|
"association element");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
ep->e_dim = oldep->e_dim;
|
ep->e_dim = oldep->e_dim;
|
||||||
ep->e_hash = oldep->e_hash;
|
ep->e_hash = oldep->e_hash;
|
||||||
@@ -375,7 +375,7 @@ resize(ASSOC *ap, long newsize)
|
|||||||
newtable = (ASSOCELEM **) malloc(sizeof(ASSOCELEM *) * newsize);
|
newtable = (ASSOCELEM **) malloc(sizeof(ASSOCELEM *) * newsize);
|
||||||
if (newtable == NULL) {
|
if (newtable == NULL) {
|
||||||
math_error("No memory to grow association");
|
math_error("No memory to grow association");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
for (i = 0; i < newsize; i++)
|
for (i = 0; i < newsize; i++)
|
||||||
newtable[i] = NULL;
|
newtable[i] = NULL;
|
||||||
@@ -431,7 +431,7 @@ assocalloc(long initsize)
|
|||||||
ap = (ASSOC *) malloc(sizeof(ASSOC));
|
ap = (ASSOC *) malloc(sizeof(ASSOC));
|
||||||
if (ap == NULL) {
|
if (ap == NULL) {
|
||||||
math_error("No memory for association");
|
math_error("No memory for association");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
ap->a_count = 0;
|
ap->a_count = 0;
|
||||||
ap->a_size = initsize;
|
ap->a_size = initsize;
|
||||||
@@ -439,7 +439,7 @@ assocalloc(long initsize)
|
|||||||
if (ap->a_table == NULL) {
|
if (ap->a_table == NULL) {
|
||||||
free((char *) ap);
|
free((char *) ap);
|
||||||
math_error("No memory for association");
|
math_error("No memory for association");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
for (i = 0; i < initsize; i++)
|
for (i = 0; i < initsize; i++)
|
||||||
ap->a_table[i] = NULL;
|
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 */
|
180
banned.h
Normal file
180
banned.h
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
/*
|
||||||
|
* banned - optionally ban dangerous functions
|
||||||
|
*
|
||||||
|
* Unless UNBAN is defined, this file will turn the use
|
||||||
|
* of certain dangerous functions into syntax errors.
|
||||||
|
*
|
||||||
|
* In the case of calc, we are motivated in part by the desire for
|
||||||
|
* calc to correctly calculate: even during extremely long calculations.
|
||||||
|
*
|
||||||
|
* If UNBAN is NOT defined, then calling certain functions
|
||||||
|
* will result in a syntax error.
|
||||||
|
*
|
||||||
|
* If we define UNBAN, then the effect of this file is disabled.
|
||||||
|
*
|
||||||
|
* The banned.h attempts to ban the use of certain dangerous functions
|
||||||
|
* that, if improperly used, could compromise the computational integrity
|
||||||
|
* if calculations.
|
||||||
|
*
|
||||||
|
* In the case of calc, we are motivated in part by the desire for calc
|
||||||
|
* to correctly calculate: even during extremely long calculations.
|
||||||
|
*
|
||||||
|
* If UNBAN is NOT defined, then calling certain functions
|
||||||
|
* will result in a call to a non-existent function (link error).
|
||||||
|
*
|
||||||
|
* While we do NOT encourage defining UNBAN, there may be
|
||||||
|
* a system / compiler environment where re-defining a
|
||||||
|
* function may lead to a fatal compiler complication.
|
||||||
|
* If that happens, consider compiling as:
|
||||||
|
*
|
||||||
|
* make clobber all chk CCBAN=-DUNBAN
|
||||||
|
*
|
||||||
|
* as see if this is a work-a-round.
|
||||||
|
*
|
||||||
|
* If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us!
|
||||||
|
* Please send us a bug report. See the file:
|
||||||
|
*
|
||||||
|
* BUGS
|
||||||
|
*
|
||||||
|
* or the URL:
|
||||||
|
*
|
||||||
|
* http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
|
||||||
|
*
|
||||||
|
* for how to send us such a bug report.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 Landon Curt Noll
|
||||||
|
*
|
||||||
|
* Calc is open software; you can redistribute it and/or modify it under
|
||||||
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* A copy of version 2.1 of the GNU Lesser General Public License is
|
||||||
|
* distributed with calc under the filename COPYING-LGPL. You should have
|
||||||
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* Under source code control: 2021/03/06 21:07:31
|
||||||
|
* File existed as early as: 2021
|
||||||
|
*
|
||||||
|
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||||
|
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(PRE_HAVE_BAN_PRAGMA_H)
|
||||||
|
#include "have_ban_pragma.h"
|
||||||
|
#endif /* ! PRE_HAVE_BAN_PRAGMA_H */
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(INCLUDE_BANNED_H)
|
||||||
|
#define INCLUDE_BANNED_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we define UNBAN, then the effect of this file is disabled.
|
||||||
|
*/
|
||||||
|
#if !defined(UNBAN)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In the spirit of:
|
||||||
|
*
|
||||||
|
* https://github.com/git/git/blob/master/banned.h
|
||||||
|
*
|
||||||
|
* we will ban the use of certain unsafe functions by turning
|
||||||
|
* then into function calls that do not exist.
|
||||||
|
*
|
||||||
|
* In the case of calc, we are motivated in part by the desire
|
||||||
|
* for calc to correctly calculate: even during extremely long
|
||||||
|
* calculations.
|
||||||
|
*
|
||||||
|
* If UNBAN is NOT defined, then calling certain functions
|
||||||
|
* will result in a syntax error.
|
||||||
|
*
|
||||||
|
* Unlike the above URL, we suggest an alternative function.
|
||||||
|
* In many cases, additional logic is required to use the
|
||||||
|
* alternative function, we cannot simply replace one function
|
||||||
|
* with another.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If one is not careful, strcpy() can lead to buffer overflows.
|
||||||
|
* Use strlcpy() instead.
|
||||||
|
*/
|
||||||
|
#if defined(HAVE_PRAGMA_GCC_POSION)
|
||||||
|
#undef strcpy
|
||||||
|
#pragma GCC poison strcpy
|
||||||
|
#endif /* HAVE_PRAGMA_GCC_POSION */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If one is not careful, strcat() can lead to buffer overflows.
|
||||||
|
* Use strlcat() instead.
|
||||||
|
*/
|
||||||
|
#if defined(HAVE_PRAGMA_GCC_POSION)
|
||||||
|
#undef strcat
|
||||||
|
#pragma GCC poison strcat
|
||||||
|
#endif /* HAVE_PRAGMA_GCC_POSION */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If one is not careful, strncpy() can lead to buffer overflows.
|
||||||
|
* Use memccpy() instead.
|
||||||
|
*/
|
||||||
|
#if defined(HAVE_PRAGMA_GCC_POSION)
|
||||||
|
#undef strncpy
|
||||||
|
#pragma GCC poison strncpy
|
||||||
|
#endif /* HAVE_PRAGMA_GCC_POSION */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If one is not careful, strncat() can lead to buffer overflows.
|
||||||
|
* Use memccpy() instead.
|
||||||
|
*/
|
||||||
|
#if defined(HAVE_PRAGMA_GCC_POSION)
|
||||||
|
#undef strncat
|
||||||
|
#pragma GCC poison strncat
|
||||||
|
#endif /* HAVE_PRAGMA_GCC_POSION */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If one is not careful, sprintf() can lead to buffer overflows.
|
||||||
|
* Use snprintf() instead.
|
||||||
|
*/
|
||||||
|
#if defined(HAVE_PRAGMA_GCC_POSION)
|
||||||
|
#undef sprintf
|
||||||
|
#pragma GCC poison sprintf
|
||||||
|
#endif /* HAVE_PRAGMA_GCC_POSION */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If one is not careful, vsprintf() can lead to buffer overflows.
|
||||||
|
* Use vsnprintf() instead.
|
||||||
|
*/
|
||||||
|
#if defined(HAVE_PRAGMA_GCC_POSION)
|
||||||
|
#undef vsprintf
|
||||||
|
#pragma GCC poison vsprintf
|
||||||
|
#endif /* HAVE_PRAGMA_GCC_POSION */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXX - As of 2021, functions such as:
|
||||||
|
*
|
||||||
|
* gmtime_s
|
||||||
|
* localtime_s
|
||||||
|
* ctime_s
|
||||||
|
* asctime_s
|
||||||
|
*
|
||||||
|
* are not universal. We cannot yet ban the following
|
||||||
|
* functions because we do not have a portable AND
|
||||||
|
* widely available alternative. Therefore we just
|
||||||
|
* have to be extra careful when using:
|
||||||
|
*
|
||||||
|
* gmtime
|
||||||
|
* localtime
|
||||||
|
* ctime
|
||||||
|
* ctime_r
|
||||||
|
* asctime
|
||||||
|
* asctime_r
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* !UNBAN */
|
||||||
|
|
||||||
|
#endif /* !INCLUDE_BANNED_H */
|
39
blkcpy.c
39
blkcpy.c
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* blkcpy - general values and related routines used by the calculator
|
* blkcpy - general values and related routines used by the calculator
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2007 Landon Curt Noll and Ernest Bowen
|
* Copyright (C) 1999-2007,2021,2022 Landon Curt Noll and Ernest Bowen
|
||||||
*
|
*
|
||||||
* Primary author: Landon Curt Noll
|
* Primary author: Landon Curt Noll
|
||||||
*
|
*
|
||||||
@@ -19,10 +19,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.2 $
|
|
||||||
* @(#) $Id: blkcpy.c,v 30.2 2013/08/11 08:41:38 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/RCS/blkcpy.c,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1997/04/18 20:41:26
|
* Under source code control: 1997/04/18 20:41:26
|
||||||
* File existed as early as: 1997
|
* File existed as early as: 1997
|
||||||
*
|
*
|
||||||
@@ -33,12 +29,17 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "calc.h"
|
#include "calc.h"
|
||||||
|
#include "alloc.h"
|
||||||
#include "value.h"
|
#include "value.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "blkcpy.h"
|
#include "blkcpy.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "attribute.h"
|
||||||
|
#include "banned.h" /* include after system header <> includes */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* copystod - copy num indexed items from source value to destination value
|
* copystod - copy num indexed items from source value to destination value
|
||||||
*
|
*
|
||||||
@@ -298,7 +299,7 @@ copymat2mat(MATRIX *smat, long ssi, long num, MATRIX *dmat, long dsi)
|
|||||||
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
||||||
if (vtemp == NULL) {
|
if (vtemp == NULL) {
|
||||||
math_error("Out of memory for mat-to-mat copy");
|
math_error("Out of memory for mat-to-mat copy");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
vp = smat->m_table + ssi;
|
vp = smat->m_table + ssi;
|
||||||
vq = vtemp;
|
vq = vtemp;
|
||||||
@@ -347,7 +348,7 @@ copyblk2mat(BLOCK *blk, long ssi, long num, MATRIX *dmat, long dsi)
|
|||||||
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
||||||
if (vtemp == NULL) {
|
if (vtemp == NULL) {
|
||||||
math_error("Out of memory for block-to-matrix copy");
|
math_error("Out of memory for block-to-matrix copy");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
vp = vtemp;
|
vp = vtemp;
|
||||||
i = num;
|
i = num;
|
||||||
@@ -404,7 +405,7 @@ copymat2blk(MATRIX *smat, long ssi, long num, BLOCK *dblk, long dsi,
|
|||||||
newdata = (USB8*) realloc(dblk->data, newsize);
|
newdata = (USB8*) realloc(dblk->data, newsize);
|
||||||
if (newdata == NULL) {
|
if (newdata == NULL) {
|
||||||
math_error("Out of memory for matrix-to-block copy");
|
math_error("Out of memory for matrix-to-block copy");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
dblk->data = newdata;
|
dblk->data = newdata;
|
||||||
dblk->maxsize = newsize;
|
dblk->maxsize = newsize;
|
||||||
@@ -447,7 +448,7 @@ copymat2list(MATRIX *smat, long ssi, long num, LIST *lp, long dsi)
|
|||||||
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
||||||
if (vtemp == NULL) {
|
if (vtemp == NULL) {
|
||||||
math_error("Out of memory for matrix-to-list copy");
|
math_error("Out of memory for matrix-to-list copy");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
vp = smat->m_table + ssi;
|
vp = smat->m_table + ssi;
|
||||||
vq = vtemp;
|
vq = vtemp;
|
||||||
@@ -497,7 +498,7 @@ copylist2mat(LIST *lp, long ssi, long num, MATRIX *dmat, long dsi)
|
|||||||
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
||||||
if (vtemp == NULL) {
|
if (vtemp == NULL) {
|
||||||
math_error("Out of memory for list-to-matrix copy");
|
math_error("Out of memory for list-to-matrix copy");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
ep = listelement(lp, (long) ssi);
|
ep = listelement(lp, (long) ssi);
|
||||||
vp = vtemp;
|
vp = vtemp;
|
||||||
@@ -547,7 +548,7 @@ copylist2list(LIST *slp, long ssi, long num, LIST *dlp, long dsi)
|
|||||||
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
|
||||||
if (vtemp == NULL) {
|
if (vtemp == NULL) {
|
||||||
math_error("Out of memory for list-to-list copy");
|
math_error("Out of memory for list-to-list copy");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
sep = listelement(slp, (long) ssi);
|
sep = listelement(slp, (long) ssi);
|
||||||
vp = vtemp;
|
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);
|
newdata = (USB8*) realloc(dblk->data, newsize);
|
||||||
if (newdata == NULL) {
|
if (newdata == NULL) {
|
||||||
math_error("Out of memory for block-to-block copy");
|
math_error("Out of memory for block-to-block copy");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
dblk->data = newdata;
|
dblk->data = newdata;
|
||||||
dblk->maxsize = newsize;
|
dblk->maxsize = newsize;
|
||||||
@@ -748,7 +749,7 @@ copyblk2blk(BLOCK *sblk, long ssi, long num, BLOCK *dblk, long dsi,
|
|||||||
newdata = (USB8*) realloc(dblk->data, newsize);
|
newdata = (USB8*) realloc(dblk->data, newsize);
|
||||||
if (newdata == NULL) {
|
if (newdata == NULL) {
|
||||||
math_error("Out of memory for block-to-block copy");
|
math_error("Out of memory for block-to-block copy");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
dblk->data = newdata;
|
dblk->data = newdata;
|
||||||
dblk->maxsize = newsize;
|
dblk->maxsize = newsize;
|
||||||
@@ -792,7 +793,7 @@ copystr2blk(STRING *str, long ssi, long num, BLOCK *dblk, long dsi,
|
|||||||
newdata = (USB8*) realloc(dblk->data, newsize);
|
newdata = (USB8*) realloc(dblk->data, newsize);
|
||||||
if (newdata == NULL) {
|
if (newdata == NULL) {
|
||||||
math_error("Out of memory for string-to-block copy");
|
math_error("Out of memory for string-to-block copy");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
dblk->data = newdata;
|
dblk->data = newdata;
|
||||||
dblk->maxsize = newsize;
|
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);
|
newdata = (USB8*) realloc(dblk->data, newsize);
|
||||||
if (newdata == NULL) {
|
if (newdata == NULL) {
|
||||||
math_error("Out of memory for string-to-block copy");
|
math_error("Out of memory for string-to-block copy");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
dblk->data = newdata;
|
dblk->data = newdata;
|
||||||
dblk->maxsize = newsize;
|
dblk->maxsize = newsize;
|
||||||
@@ -945,7 +946,7 @@ memmove(void *s1, CONST void *s2, MEMMOVE_SIZE_T n)
|
|||||||
*/
|
*/
|
||||||
if (s1 == NULL || s2 == NULL) {
|
if (s1 == NULL || s2 == NULL) {
|
||||||
math_error("bogus memmove NULL ptr");
|
math_error("bogus memmove NULL ptr");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
/* neg or 0 count does nothing */
|
/* 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);
|
newdata = (USB8*) realloc(dblk->data, newsize);
|
||||||
if (newdata == NULL) {
|
if (newdata == NULL) {
|
||||||
math_error("Out of memory for num-to-block copy");
|
math_error("Out of memory for num-to-block copy");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
dblk->data = newdata;
|
dblk->data = newdata;
|
||||||
dblk->maxsize = newsize;
|
dblk->maxsize = newsize;
|
||||||
@@ -1044,7 +1045,7 @@ copyblk2num(BLOCK *sblk, long ssi, long num, NUMBER *dnum, long dsi,
|
|||||||
NUMBER *ret; /* cloned and modified numerator */
|
NUMBER *ret; /* cloned and modified numerator */
|
||||||
#if CALC_BYTE_ORDER == BIG_ENDIAN
|
#if CALC_BYTE_ORDER == BIG_ENDIAN
|
||||||
HALF *swapped; /* byte swapped input data */
|
HALF *swapped; /* byte swapped input data */
|
||||||
unsigned long halflen; /* length of the input ounded up to HALFs */
|
unsigned long halflen; /* length of the input rounded up to HALFs */
|
||||||
HALF *h; /* copy byteswap pointer */
|
HALF *h; /* copy byteswap pointer */
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
#endif
|
#endif
|
||||||
@@ -1086,7 +1087,7 @@ copyblk2num(BLOCK *sblk, long ssi, long num, NUMBER *dnum, long dsi,
|
|||||||
swapped = (HALF *)malloc(halflen * sizeof(HALF));
|
swapped = (HALF *)malloc(halflen * sizeof(HALF));
|
||||||
if (swapped == NULL) {
|
if (swapped == NULL) {
|
||||||
math_error("Out of memory for block-to-num copy");
|
math_error("Out of memory for block-to-num copy");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
/* ensure that any trailing octets will be zero filled */
|
/* ensure that any trailing octets will be zero filled */
|
||||||
swapped[halflen-1] = 0;
|
swapped[halflen-1] = 0;
|
||||||
|
4
blkcpy.h
4
blkcpy.h
@@ -19,10 +19,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.3 $
|
|
||||||
* @(#) $Id: blkcpy.h,v 30.3 2014/08/24 21:56:51 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/RCS/blkcpy.h,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1997/04/18 20:41:25
|
* Under source code control: 1997/04/18 20:41:25
|
||||||
* File existed as early as: 1997
|
* File existed as early as: 1997
|
||||||
*
|
*
|
||||||
|
56
block.c
56
block.c
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* block - fixed, dynamic, fifo and circular memory blocks
|
* block - fixed, dynamic, fifo and circular memory blocks
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2007 Landon Curt Noll and Ernest Bowen
|
* Copyright (C) 1999-2007,2021,2022 Landon Curt Noll and Ernest Bowen
|
||||||
*
|
*
|
||||||
* Primary author: Landon Curt Noll
|
* Primary author: Landon Curt Noll
|
||||||
*
|
*
|
||||||
@@ -19,10 +19,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: block.c,v 30.1 2007/03/16 11:09:46 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/RCS/block.c,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1997/02/27 00:29:40
|
* Under source code control: 1997/02/27 00:29:40
|
||||||
* File existed as early as: 1997
|
* File existed as early as: 1997
|
||||||
*
|
*
|
||||||
@@ -32,6 +28,11 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "have_string.h"
|
||||||
|
#ifdef HAVE_STRING_H
|
||||||
|
# include <string.h>
|
||||||
|
#endif
|
||||||
|
#include "alloc.h"
|
||||||
#include "value.h"
|
#include "value.h"
|
||||||
#include "zmath.h"
|
#include "zmath.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@@ -40,6 +41,11 @@
|
|||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "calcerr.h"
|
#include "calcerr.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "attribute.h"
|
||||||
|
#include "banned.h" /* include after system header <> includes */
|
||||||
|
|
||||||
|
|
||||||
#define NBLOCKCHUNK 16
|
#define NBLOCKCHUNK 16
|
||||||
|
|
||||||
STATIC long nblockcount = 0;
|
STATIC long nblockcount = 0;
|
||||||
@@ -82,7 +88,7 @@ blkalloc(int len, int chunk)
|
|||||||
nblk = (BLOCK *)malloc(sizeof(BLOCK));
|
nblk = (BLOCK *)malloc(sizeof(BLOCK));
|
||||||
if (nblk == NULL) {
|
if (nblk == NULL) {
|
||||||
math_error("cannot allocate block");
|
math_error("cannot allocate block");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -93,7 +99,7 @@ blkalloc(int len, int chunk)
|
|||||||
nblk->data = (USB8*)malloc(nblk->maxsize);
|
nblk->data = (USB8*)malloc(nblk->maxsize);
|
||||||
if (nblk->data == NULL) {
|
if (nblk->data == NULL) {
|
||||||
math_error("cannot allocate block data storage");
|
math_error("cannot allocate block data storage");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
memset(nblk->data, 0, nblk->maxsize);
|
memset(nblk->data, 0, nblk->maxsize);
|
||||||
nblk->datalen = len;
|
nblk->datalen = len;
|
||||||
@@ -151,7 +157,7 @@ blk_free(BLOCK *blk)
|
|||||||
* blk - the BLOCK to check
|
* blk - the BLOCK to check
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* if all is ok, otherwise math_error() is called and this
|
* if all is OK, otherwise math_error() is called and this
|
||||||
* function does not return
|
* function does not return
|
||||||
*/
|
*/
|
||||||
S_FUNC void
|
S_FUNC void
|
||||||
@@ -167,7 +173,7 @@ blkchk(BLOCK *blk)
|
|||||||
}
|
}
|
||||||
if (blk == NULL) {
|
if (blk == NULL) {
|
||||||
math_error("internal: blk ptr is NULL");
|
math_error("internal: blk ptr is NULL");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -175,7 +181,7 @@ blkchk(BLOCK *blk)
|
|||||||
*/
|
*/
|
||||||
if (blk->data == NULL) {
|
if (blk->data == NULL) {
|
||||||
math_error("internal: blk->data ptr is NULL");
|
math_error("internal: blk->data ptr is NULL");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -183,7 +189,7 @@ blkchk(BLOCK *blk)
|
|||||||
*/
|
*/
|
||||||
if (blk->datalen < 0) {
|
if (blk->datalen < 0) {
|
||||||
math_error("internal: blk->datalen < 0");
|
math_error("internal: blk->datalen < 0");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -191,7 +197,7 @@ blkchk(BLOCK *blk)
|
|||||||
*/
|
*/
|
||||||
if (blk->datalen < 0) {
|
if (blk->datalen < 0) {
|
||||||
math_error("internal: blk->datalen < 0");
|
math_error("internal: blk->datalen < 0");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -254,7 +260,7 @@ blkrealloc(BLOCK *blk, int newlen, int newchunk)
|
|||||||
nblk = (USB8*)realloc(blk->data, newmax);
|
nblk = (USB8*)realloc(blk->data, newmax);
|
||||||
if (nblk == NULL) {
|
if (nblk == NULL) {
|
||||||
math_error("cannot reallocate block storage");
|
math_error("cannot reallocate block storage");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear any new storage */
|
/* clear any new storage */
|
||||||
@@ -295,7 +301,7 @@ blkrealloc(BLOCK *blk, int newlen, int newchunk)
|
|||||||
* Set the data length
|
* Set the data length
|
||||||
*
|
*
|
||||||
* We also know that the new block is not empty since we have
|
* We also know that the new block is not empty since we have
|
||||||
* already dealth with that case above.
|
* already dealt with that case above.
|
||||||
*
|
*
|
||||||
* After this section of code, limit and datalen will be
|
* After this section of code, limit and datalen will be
|
||||||
* correct in terms of the new type.
|
* correct in terms of the new type.
|
||||||
@@ -362,7 +368,7 @@ blktrunc(BLOCK *blk)
|
|||||||
blk->data = (USB8*)malloc(1);
|
blk->data = (USB8*)malloc(1);
|
||||||
if (blk->data == NULL) {
|
if (blk->data == NULL) {
|
||||||
math_error("cannot allocate truncated block storage");
|
math_error("cannot allocate truncated block storage");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
blk->data[0] = (USB8)0;
|
blk->data[0] = (USB8)0;
|
||||||
if (conf->calc_debug & CALCDBG_BLOCK) {
|
if (conf->calc_debug & CALCDBG_BLOCK) {
|
||||||
@@ -392,7 +398,7 @@ blk_copy(BLOCK *blk)
|
|||||||
nblk = (BLOCK *)malloc(sizeof(BLOCK));
|
nblk = (BLOCK *)malloc(sizeof(BLOCK));
|
||||||
if (nblk == NULL) {
|
if (nblk == NULL) {
|
||||||
math_error("blk_copy: cannot malloc BLOCK");
|
math_error("blk_copy: cannot malloc BLOCK");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -406,7 +412,7 @@ blk_copy(BLOCK *blk)
|
|||||||
nblk->data = (USB8 *)malloc(blk->maxsize);
|
nblk->data = (USB8 *)malloc(blk->maxsize);
|
||||||
if (nblk->data == NULL) {
|
if (nblk->data == NULL) {
|
||||||
math_error("blk_copy: cannot duplicate block data");
|
math_error("blk_copy: cannot duplicate block data");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
memcpy(nblk->data, blk->data, blk->maxsize);
|
memcpy(nblk->data, blk->data, blk->maxsize);
|
||||||
return nblk;
|
return nblk;
|
||||||
@@ -534,7 +540,7 @@ reallocnblock(int id, int len, int chunk)
|
|||||||
/* Fire wall */
|
/* Fire wall */
|
||||||
if (id < 0 || id >= nblockcount) {
|
if (id < 0 || id >= nblockcount) {
|
||||||
math_error("Bad id in call to reallocnblock");
|
math_error("Bad id in call to reallocnblock");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
blk = nblocks[id]->blk;
|
blk = nblocks[id]->blk;
|
||||||
@@ -551,13 +557,13 @@ reallocnblock(int id, int len, int chunk)
|
|||||||
newdata = malloc(newsize);
|
newdata = malloc(newsize);
|
||||||
if (newdata == NULL) {
|
if (newdata == NULL) {
|
||||||
math_error("Allocation failed");
|
math_error("Allocation failed");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
} else if (newsize != oldsize) {
|
} else if (newsize != oldsize) {
|
||||||
newdata = realloc(blk->data, newsize);
|
newdata = realloc(blk->data, newsize);
|
||||||
if (newdata == NULL) {
|
if (newdata == NULL) {
|
||||||
math_error("Reallocation failed");
|
math_error("Reallocation failed");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memset(newdata + len, 0, newsize - len);
|
memset(newdata + len, 0, newsize - len);
|
||||||
@@ -588,7 +594,7 @@ createnblock(char *name, int len, int chunk)
|
|||||||
if (nblocks == NULL) {
|
if (nblocks == NULL) {
|
||||||
maxnblockcount = 0;
|
maxnblockcount = 0;
|
||||||
math_error("unable to malloc new named blocks");
|
math_error("unable to malloc new named blocks");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
maxnblockcount += NBLOCKCHUNK;
|
maxnblockcount += NBLOCKCHUNK;
|
||||||
@@ -597,7 +603,7 @@ createnblock(char *name, int len, int chunk)
|
|||||||
if (nblocks == NULL) {
|
if (nblocks == NULL) {
|
||||||
maxnblockcount = 0;
|
maxnblockcount = 0;
|
||||||
math_error("cannot malloc more named blocks");
|
math_error("cannot malloc more named blocks");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -605,18 +611,18 @@ createnblock(char *name, int len, int chunk)
|
|||||||
initstr(&nblocknames);
|
initstr(&nblocknames);
|
||||||
if (findstr(&nblocknames, name) >= 0) {
|
if (findstr(&nblocknames, name) >= 0) {
|
||||||
math_error("Named block already exists!!!");
|
math_error("Named block already exists!!!");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
newname = addstr(&nblocknames, name);
|
newname = addstr(&nblocknames, name);
|
||||||
if (newname == NULL) {
|
if (newname == NULL) {
|
||||||
math_error("Block name allocation failed");
|
math_error("Block name allocation failed");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
res = (NBLOCK *) malloc(sizeof(NBLOCK));
|
res = (NBLOCK *) malloc(sizeof(NBLOCK));
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
math_error("Named block allocation failed");
|
math_error("Named block allocation failed");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
nblocks[nblockcount] = res;
|
nblocks[nblockcount] = res;
|
||||||
|
14
block.h
14
block.h
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* block - fixed, dynamic, fifo and circular memory blocks
|
* block - fixed, dynamic, fifo and circular memory blocks
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2007,2014 Landon Curt Noll and Ernest Bowen
|
* Copyright (C) 1999-2007,2014,2021 Landon Curt Noll and Ernest Bowen
|
||||||
*
|
*
|
||||||
* Primary author: Landon Curt Noll
|
* Primary author: Landon Curt Noll
|
||||||
*
|
*
|
||||||
@@ -19,10 +19,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.3 $
|
|
||||||
* @(#) $Id: block.h,v 30.3 2014/08/24 21:56:51 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/RCS/block.h,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1997/02/21 05:03:39
|
* Under source code control: 1997/02/21 05:03:39
|
||||||
* File existed as early as: 1997
|
* File existed as early as: 1997
|
||||||
*
|
*
|
||||||
@@ -59,7 +55,7 @@
|
|||||||
* blkchunk defaults to BLK_CHUNKSIZE
|
* blkchunk defaults to BLK_CHUNKSIZE
|
||||||
*
|
*
|
||||||
* blkfree(x)
|
* blkfree(x)
|
||||||
* Reduce storage down to 0 octetes.
|
* Reduce storage down to 0 octets.
|
||||||
*
|
*
|
||||||
* size(x)
|
* size(x)
|
||||||
* The length of data stored in the block.
|
* The length of data stored in the block.
|
||||||
@@ -92,7 +88,7 @@
|
|||||||
* blkmove(dest, src, length [, dest_offset [, src_offset]])
|
* blkmove(dest, src, length [, dest_offset [, src_offset]])
|
||||||
* 0 <= length <= blksize(x)
|
* 0 <= length <= blksize(x)
|
||||||
* offset's are restricted in value by block type
|
* offset's are restricted in value by block type
|
||||||
* overlapping moves are handeled correctly
|
* overlapping moves are handled correctly
|
||||||
*
|
*
|
||||||
* blkccpy(dest, src, stopval, length [, dest_offset [, src_offset]])
|
* blkccpy(dest, src, stopval, length [, dest_offset [, src_offset]])
|
||||||
* 0 <= length <= blksize(x)
|
* 0 <= length <= blksize(x)
|
||||||
@@ -108,7 +104,7 @@
|
|||||||
* b = a*k for some integer k >= 1
|
* b = a*k for some integer k >= 1
|
||||||
*
|
*
|
||||||
* scatter(src, dest1, dest2 [, dest3 ] ...)
|
* scatter(src, dest1, dest2 [, dest3 ] ...)
|
||||||
* copy sucessive octets from src into dest1, dest2, ...
|
* copy successive octets from src into dest1, dest2, ...
|
||||||
* restarting with dest1 after end of list
|
* restarting with dest1 after end of list
|
||||||
* stops at end of src
|
* stops at end of src
|
||||||
*
|
*
|
||||||
@@ -188,7 +184,7 @@ EXTERN int blk_debug; /* 0 => debug off */
|
|||||||
/* length of data stored in a block */
|
/* length of data stored in a block */
|
||||||
#define blklen(blk) ((blk)->datalen)
|
#define blklen(blk) ((blk)->datalen)
|
||||||
|
|
||||||
/* block footpint in memory */
|
/* block footprint in memory */
|
||||||
#define blksizeof(blk) ((blk)->maxsize)
|
#define blksizeof(blk) ((blk)->maxsize)
|
||||||
|
|
||||||
/* block allocation chunk size */
|
/* block allocation chunk size */
|
||||||
|
142
byteswap.c
142
byteswap.c
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* byteswap - byte swapping routines
|
* byteswap - byte swapping routines
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 Landon Curt Noll
|
* Copyright (C) 1999,2021,2022 Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.2 $
|
|
||||||
* @(#) $Id: byteswap.c,v 30.2 2013/08/11 08:41:38 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/RCS/byteswap.c,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1995/10/11 04:44:01
|
* Under source code control: 1995/10/11 04:44:01
|
||||||
* File existed as early as: 1995
|
* File existed as early as: 1995
|
||||||
*
|
*
|
||||||
@@ -33,14 +29,18 @@
|
|||||||
#include "byteswap.h"
|
#include "byteswap.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "attribute.h"
|
||||||
|
#include "banned.h" /* include after system header <> includes */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* swap_b8_in_HALFs - swap 8 and if needed, 16 bits in an array of HALFs
|
* swap_b8_in_HALFs - swap 8 and if needed, 16 bits in an array of HALFs
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* dest - pointer to where the swapped src wil be put or
|
* dest - pointer to where the swapped src will be put or
|
||||||
* NULL to allocate the storage
|
* NULL to allocate the storage
|
||||||
* src - pointer to a HALF array to swap
|
* 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:
|
* returns:
|
||||||
* pointer to where the swapped src has been put
|
* pointer to where the swapped src has been put
|
||||||
@@ -77,11 +77,11 @@ swap_b8_in_HALFs(HALF *dest, HALF *src, LEN len)
|
|||||||
* swap_b8_in_ZVALUE - swap 8 and if needed, 16 bits in a ZVALUE
|
* swap_b8_in_ZVALUE - swap 8 and if needed, 16 bits in a ZVALUE
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* dest - pointer to where the swapped src wil be put or
|
* dest - pointer to where the swapped src will be put or
|
||||||
* NULL to allocate the storage
|
* NULL to allocate the storage
|
||||||
* src - pointer to a ZVALUE to swap
|
* src - pointer to a ZVALUE to swap
|
||||||
* all - TRUE => swap every element, FALSE => swap only the
|
* all - TRUE => swap every element, FALSE => swap only the
|
||||||
* multiprecision storage
|
* multi-precision storage
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* pointer to where the swapped src has been put
|
* pointer to where the swapped src has been put
|
||||||
@@ -104,7 +104,7 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
|||||||
if (dest == NULL) {
|
if (dest == NULL) {
|
||||||
math_error("swap_b8_in_ZVALUE: swap_b8_in_ZVALUE: "
|
math_error("swap_b8_in_ZVALUE: swap_b8_in_ZVALUE: "
|
||||||
"Not enough memory");
|
"Not enough memory");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -127,8 +127,8 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
|||||||
* swap or copy the rest of the ZVALUE elements
|
* swap or copy the rest of the ZVALUE elements
|
||||||
*/
|
*/
|
||||||
if (all) {
|
if (all) {
|
||||||
dest->len = (LEN)SWAP_B8_IN_LEN(&dest->len, &src->len);
|
SWAP_B8_IN_LEN(&dest->len, &src->len);
|
||||||
dest->sign = (BOOL)SWAP_B8_IN_BOOL(&dest->sign, &src->sign);
|
SWAP_B8_IN_BOOL(&dest->sign, &src->sign);
|
||||||
} else {
|
} else {
|
||||||
dest->len = src->len;
|
dest->len = src->len;
|
||||||
dest->sign = src->sign;
|
dest->sign = src->sign;
|
||||||
@@ -145,11 +145,11 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
|||||||
* swap_b8_in_NUMBER - swap 8 and if needed, 16 bits in a NUMBER
|
* swap_b8_in_NUMBER - swap 8 and if needed, 16 bits in a NUMBER
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* dest - pointer to where the swapped src wil be put or
|
* dest - pointer to where the swapped src will be put or
|
||||||
* NULL to allocate the storage
|
* NULL to allocate the storage
|
||||||
* src - pointer to a NUMBER to swap
|
* src - pointer to a NUMBER to swap
|
||||||
* all - TRUE => swap every element, FALSE => swap only the
|
* all - TRUE => swap every element, FALSE => swap only the
|
||||||
* multiprecision storage
|
* multi-precision storage
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* pointer to where the swapped src has been put
|
* pointer to where the swapped src has been put
|
||||||
@@ -171,7 +171,7 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
|||||||
dest = malloc(sizeof(NUMBER));
|
dest = malloc(sizeof(NUMBER));
|
||||||
if (dest == NULL) {
|
if (dest == NULL) {
|
||||||
math_error("swap_b8_in_NUMBER: Not enough memory");
|
math_error("swap_b8_in_NUMBER: Not enough memory");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -193,7 +193,7 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
|||||||
* swap or copy the rest of the NUMBER elements
|
* swap or copy the rest of the NUMBER elements
|
||||||
*/
|
*/
|
||||||
if (all) {
|
if (all) {
|
||||||
dest->links = (long)SWAP_B8_IN_LONG(&dest->links, &src->links);
|
SWAP_B8_IN_LONG(&dest->links, &src->links);
|
||||||
} else {
|
} else {
|
||||||
dest->links = src->links;
|
dest->links = src->links;
|
||||||
}
|
}
|
||||||
@@ -209,11 +209,11 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
|||||||
* swap_b8_in_COMPLEX - swap 8 and if needed, 16 bits in a COMPLEX
|
* swap_b8_in_COMPLEX - swap 8 and if needed, 16 bits in a COMPLEX
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* dest - pointer to where the swapped src wil be put or
|
* dest - pointer to where the swapped src will be put or
|
||||||
* NULL to allocate the storage
|
* NULL to allocate the storage
|
||||||
* src - pointer to a COMPLEX to swap
|
* src - pointer to a COMPLEX to swap
|
||||||
* all - TRUE => swap every element, FALSE => swap only the
|
* all - TRUE => swap every element, FALSE => swap only the
|
||||||
* multiprecision storage
|
* multi-precision storage
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* pointer to where the swapped src has been put
|
* pointer to where the swapped src has been put
|
||||||
@@ -235,7 +235,7 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
|||||||
dest = malloc(sizeof(COMPLEX));
|
dest = malloc(sizeof(COMPLEX));
|
||||||
if (dest == NULL) {
|
if (dest == NULL) {
|
||||||
math_error("swap_b8_in_COMPLEX: Not enough memory");
|
math_error("swap_b8_in_COMPLEX: Not enough memory");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -257,7 +257,7 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
|||||||
* swap or copy the rest of the NUMBER elements
|
* swap or copy the rest of the NUMBER elements
|
||||||
*/
|
*/
|
||||||
if (all) {
|
if (all) {
|
||||||
dest->links = (long)SWAP_B8_IN_LONG(&dest->links, &src->links);
|
SWAP_B8_IN_LONG(&dest->links, &src->links);
|
||||||
} else {
|
} else {
|
||||||
dest->links = src->links;
|
dest->links = src->links;
|
||||||
}
|
}
|
||||||
@@ -273,10 +273,10 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
|||||||
* swap_b16_in_HALFs - swap 16 bits in an array of HALFs
|
* swap_b16_in_HALFs - swap 16 bits in an array of HALFs
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* dest - pointer to where the swapped src wil be put or
|
* dest - pointer to where the swapped src will be put or
|
||||||
* NULL to allocate the storage
|
* NULL to allocate the storage
|
||||||
* src - pointer to a HALF array to swap
|
* 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:
|
* returns:
|
||||||
* pointer to where the swapped src has been put
|
* pointer to where the swapped src has been put
|
||||||
@@ -309,15 +309,59 @@ 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
|
* swap_b16_in_ZVALUE - swap 16 bits in a ZVALUE
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* dest - pointer to where the swapped src wil be put or
|
* dest - pointer to where the swapped src will be put or
|
||||||
* NULL to allocate the storage
|
* NULL to allocate the storage
|
||||||
* src - pointer to a ZVALUE to swap
|
* src - pointer to a ZVALUE to swap
|
||||||
* all - TRUE => swap every element, FALSE => swap only the
|
* all - TRUE => swap every element, FALSE => swap only the
|
||||||
* multiprecision storage
|
* multi-precision storage
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* pointer to where the swapped src has been put
|
* pointer to where the swapped src has been put
|
||||||
@@ -339,7 +383,7 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
|||||||
dest = malloc(sizeof(ZVALUE));
|
dest = malloc(sizeof(ZVALUE));
|
||||||
if (dest == NULL) {
|
if (dest == NULL) {
|
||||||
math_error("swap_b16_in_ZVALUE: Not enough memory");
|
math_error("swap_b16_in_ZVALUE: Not enough memory");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -362,8 +406,8 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
|||||||
* swap or copy the rest of the ZVALUE elements
|
* swap or copy the rest of the ZVALUE elements
|
||||||
*/
|
*/
|
||||||
if (all) {
|
if (all) {
|
||||||
dest->len = (LEN)SWAP_B16_IN_LEN(&dest->len, &src->len);
|
SWAP_B16_IN_LEN(&dest->len, &src->len);
|
||||||
dest->sign = (BOOL)SWAP_B16_IN_BOOL(&dest->sign, &src->sign);
|
SWAP_B16_IN_BOOL(&dest->sign, &src->sign);
|
||||||
} else {
|
} else {
|
||||||
dest->len = src->len;
|
dest->len = src->len;
|
||||||
dest->sign = src->sign;
|
dest->sign = src->sign;
|
||||||
@@ -380,11 +424,11 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
|||||||
* swap_b16_in_NUMBER - swap 16 bits in a NUMBER
|
* swap_b16_in_NUMBER - swap 16 bits in a NUMBER
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* dest - pointer to where the swapped src wil be put or
|
* dest - pointer to where the swapped src will be put or
|
||||||
* NULL to allocate the storage
|
* NULL to allocate the storage
|
||||||
* src - pointer to a NUMBER to swap
|
* src - pointer to a NUMBER to swap
|
||||||
* all - TRUE => swap every element, FALSE => swap only the
|
* all - TRUE => swap every element, FALSE => swap only the
|
||||||
* multiprecision storage
|
* multi-precision storage
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* pointer to where the swapped src has been put
|
* pointer to where the swapped src has been put
|
||||||
@@ -406,7 +450,7 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
|||||||
dest = malloc(sizeof(NUMBER));
|
dest = malloc(sizeof(NUMBER));
|
||||||
if (dest == NULL) {
|
if (dest == NULL) {
|
||||||
math_error("swap_b16_in_NUMBER: Not enough memory");
|
math_error("swap_b16_in_NUMBER: Not enough memory");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -428,7 +472,7 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
|||||||
* swap or copy the rest of the NUMBER elements
|
* swap or copy the rest of the NUMBER elements
|
||||||
*/
|
*/
|
||||||
if (all) {
|
if (all) {
|
||||||
dest->links = (long)SWAP_B16_IN_LONG(&dest->links, &src->links);
|
SWAP_B16_IN_LONG(&dest->links, &src->links);
|
||||||
} else {
|
} else {
|
||||||
dest->links = src->links;
|
dest->links = src->links;
|
||||||
}
|
}
|
||||||
@@ -444,11 +488,11 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
|||||||
* swap_b16_in_COMPLEX - swap 16 bits in a COMPLEX
|
* swap_b16_in_COMPLEX - swap 16 bits in a COMPLEX
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* dest - pointer to where the swapped src wil be put or
|
* dest - pointer to where the swapped src will be put or
|
||||||
* NULL to allocate the storage
|
* NULL to allocate the storage
|
||||||
* src - pointer to a COMPLEX to swap
|
* src - pointer to a COMPLEX to swap
|
||||||
* all - TRUE => swap every element, FALSE => swap only the
|
* all - TRUE => swap every element, FALSE => swap only the
|
||||||
* multiprecision storage
|
* multi-precision storage
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* pointer to where the swapped src has been put
|
* pointer to where the swapped src has been put
|
||||||
@@ -470,7 +514,7 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
|||||||
dest = malloc(sizeof(COMPLEX));
|
dest = malloc(sizeof(COMPLEX));
|
||||||
if (dest == NULL) {
|
if (dest == NULL) {
|
||||||
math_error("swap_b16_in_COMPLEX: Not enough memory");
|
math_error("swap_b16_in_COMPLEX: Not enough memory");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -492,7 +536,7 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
|||||||
* swap or copy the rest of the NUMBER elements
|
* swap or copy the rest of the NUMBER elements
|
||||||
*/
|
*/
|
||||||
if (all) {
|
if (all) {
|
||||||
dest->links = (long)SWAP_B16_IN_LONG(&dest->links, &src->links);
|
SWAP_B16_IN_LONG(&dest->links, &src->links);
|
||||||
} else {
|
} else {
|
||||||
dest->links = src->links;
|
dest->links = src->links;
|
||||||
}
|
}
|
||||||
@@ -508,11 +552,11 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
|||||||
* swap_HALF_in_ZVALUE - swap HALFs in a ZVALUE
|
* swap_HALF_in_ZVALUE - swap HALFs in a ZVALUE
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* dest - pointer to where the swapped src wil be put or
|
* dest - pointer to where the swapped src will be put or
|
||||||
* NULL to allocate the storage
|
* NULL to allocate the storage
|
||||||
* src - pointer to a ZVALUE to swap
|
* src - pointer to a ZVALUE to swap
|
||||||
* all - TRUE => swap every element, FALSE => swap only the
|
* all - TRUE => swap every element, FALSE => swap only the
|
||||||
* multiprecision storage
|
* multi-precision storage
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* pointer to where the swapped src has been put
|
* pointer to where the swapped src has been put
|
||||||
@@ -531,10 +575,10 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
|||||||
/*
|
/*
|
||||||
* allocate the storage
|
* allocate the storage
|
||||||
*/
|
*/
|
||||||
dest = malloc(sizeof(ZVALUE));
|
dest = calloc(1, sizeof(ZVALUE));
|
||||||
if (dest == NULL) {
|
if (dest == NULL) {
|
||||||
math_error("swap_HALF_in_ZVALUE: Not enough memory");
|
math_error("swap_HALF_in_ZVALUE: Not enough memory");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -558,8 +602,8 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
|||||||
* swap or copy the rest of the ZVALUE elements
|
* swap or copy the rest of the ZVALUE elements
|
||||||
*/
|
*/
|
||||||
if (all) {
|
if (all) {
|
||||||
dest->len = (LEN)SWAP_HALF_IN_LEN(&dest->len, &src->len);
|
SWAP_HALF_IN_LEN(&dest->len, &src->len);
|
||||||
dest->sign = (BOOL)SWAP_HALF_IN_BOOL(&dest->sign, &src->sign);
|
SWAP_HALF_IN_BOOL(&dest->sign, &src->sign);
|
||||||
} else {
|
} else {
|
||||||
dest->len = src->len;
|
dest->len = src->len;
|
||||||
dest->sign = src->sign;
|
dest->sign = src->sign;
|
||||||
@@ -576,11 +620,11 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
|
|||||||
* swap_HALF_in_NUMBER - swap HALFs in a NUMBER
|
* swap_HALF_in_NUMBER - swap HALFs in a NUMBER
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* dest - pointer to where the swapped src wil be put or
|
* dest - pointer to where the swapped src will be put or
|
||||||
* NULL to allocate the storage
|
* NULL to allocate the storage
|
||||||
* src - pointer to a NUMBER to swap
|
* src - pointer to a NUMBER to swap
|
||||||
* all - TRUE => swap every element, FALSE => swap only the
|
* all - TRUE => swap every element, FALSE => swap only the
|
||||||
* multiprecision storage
|
* multi-precision storage
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* pointer to where the swapped src has been put
|
* pointer to where the swapped src has been put
|
||||||
@@ -602,7 +646,7 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
|||||||
dest = malloc(sizeof(NUMBER));
|
dest = malloc(sizeof(NUMBER));
|
||||||
if (dest == NULL) {
|
if (dest == NULL) {
|
||||||
math_error("swap_HALF_in_NUMBER: Not enough memory");
|
math_error("swap_HALF_in_NUMBER: Not enough memory");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -624,7 +668,7 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
|||||||
* swap or copy the rest of the NUMBER elements
|
* swap or copy the rest of the NUMBER elements
|
||||||
*/
|
*/
|
||||||
if (all) {
|
if (all) {
|
||||||
dest->links = (long)SWAP_HALF_IN_LONG(&dest->links,&src->links);
|
SWAP_HALF_IN_LONG(&dest->links, &src->links);
|
||||||
} else {
|
} else {
|
||||||
dest->links = src->links;
|
dest->links = src->links;
|
||||||
}
|
}
|
||||||
@@ -640,11 +684,11 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
|
|||||||
* swap_HALF_in_COMPLEX - swap HALFs in a COMPLEX
|
* swap_HALF_in_COMPLEX - swap HALFs in a COMPLEX
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* dest - pointer to where the swapped src wil be put or
|
* dest - pointer to where the swapped src will be put or
|
||||||
* NULL to allocate the storage
|
* NULL to allocate the storage
|
||||||
* src - pointer to a COMPLEX to swap
|
* src - pointer to a COMPLEX to swap
|
||||||
* all - TRUE => swap every element, FALSE => swap only the
|
* all - TRUE => swap every element, FALSE => swap only the
|
||||||
* multiprecision storage
|
* multi-precision storage
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* pointer to where the swapped src has been put
|
* pointer to where the swapped src has been put
|
||||||
@@ -666,7 +710,7 @@ swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
|||||||
dest = malloc(sizeof(COMPLEX));
|
dest = malloc(sizeof(COMPLEX));
|
||||||
if (dest == NULL) {
|
if (dest == NULL) {
|
||||||
math_error("swap_HALF_in_COMPLEX: Not enough memory");
|
math_error("swap_HALF_in_COMPLEX: Not enough memory");
|
||||||
/*NOTREACHED*/
|
not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -688,7 +732,7 @@ swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
|
|||||||
* swap or copy the rest of the NUMBER elements
|
* swap or copy the rest of the NUMBER elements
|
||||||
*/
|
*/
|
||||||
if (all) {
|
if (all) {
|
||||||
dest->links = (long)SWAP_HALF_IN_LONG(&dest->links,&src->links);
|
SWAP_HALF_IN_LONG(&dest->links, &src->links);
|
||||||
} else {
|
} else {
|
||||||
dest->links = src->links;
|
dest->links = src->links;
|
||||||
}
|
}
|
||||||
|
24
byteswap.h
24
byteswap.h
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* byteswap - byte swapping macros
|
* byteswap - byte swapping macros
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999,2014 Landon Curt Noll
|
* Copyright (C) 1999,2014,2021 Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.3 $
|
|
||||||
* @(#) $Id: byteswap.h,v 30.3 2014/08/24 21:56:51 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/RCS/byteswap.h,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1995/10/11 04:44:01
|
* Under source code control: 1995/10/11 04:44:01
|
||||||
* File existed as early as: 1995
|
* File existed as early as: 1995
|
||||||
*
|
*
|
||||||
@@ -43,7 +39,7 @@
|
|||||||
/*
|
/*
|
||||||
* SWAP_B8_IN_B16 - swap 8 bits in 16 bits
|
* SWAP_B8_IN_B16 - swap 8 bits in 16 bits
|
||||||
*
|
*
|
||||||
* dest - pointer to where the swapped src wil be put
|
* dest - pointer to where the swapped src will be put
|
||||||
* src - pointer to a 16 bit value to swap
|
* src - pointer to a 16 bit value to swap
|
||||||
*
|
*
|
||||||
* This macro will either switch to the opposite byte sex (Big Endian vs.
|
* This macro will either switch to the opposite byte sex (Big Endian vs.
|
||||||
@@ -57,7 +53,7 @@
|
|||||||
/*
|
/*
|
||||||
* SWAP_B16_IN_B32 - swap 16 bits in 32 bits
|
* SWAP_B16_IN_B32 - swap 16 bits in 32 bits
|
||||||
*
|
*
|
||||||
* dest - pointer to where the swapped src wil be put
|
* dest - pointer to where the swapped src will be put
|
||||||
* src - pointer to a 32 bit value to swap
|
* src - pointer to a 32 bit value to swap
|
||||||
*/
|
*/
|
||||||
#define SWAP_B16_IN_B32(dest, src) ( \
|
#define SWAP_B16_IN_B32(dest, src) ( \
|
||||||
@@ -68,7 +64,7 @@
|
|||||||
/*
|
/*
|
||||||
* SWAP_B8_IN_B32 - swap 8 & 16 bits in 32 bits
|
* SWAP_B8_IN_B32 - swap 8 & 16 bits in 32 bits
|
||||||
*
|
*
|
||||||
* dest - pointer to where the swapped src wil be put
|
* dest - pointer to where the swapped src will be put
|
||||||
* src - pointer to a 32 bit value to swap
|
* src - pointer to a 32 bit value to swap
|
||||||
*
|
*
|
||||||
* This macro will either switch to the opposite byte sex (Big Endian vs.
|
* This macro will either switch to the opposite byte sex (Big Endian vs.
|
||||||
@@ -86,7 +82,7 @@
|
|||||||
/*
|
/*
|
||||||
* SWAP_B32_IN_B64 - swap 32 bits in 64 bits
|
* SWAP_B32_IN_B64 - swap 32 bits in 64 bits
|
||||||
*
|
*
|
||||||
* dest - pointer to where the swapped src wil be put
|
* dest - pointer to where the swapped src will be put
|
||||||
* src - pointer to a 64 bit value to swap
|
* src - pointer to a 64 bit value to swap
|
||||||
*/
|
*/
|
||||||
#define SWAP_B32_IN_B64(dest, src) ( \
|
#define SWAP_B32_IN_B64(dest, src) ( \
|
||||||
@@ -97,7 +93,7 @@
|
|||||||
/*
|
/*
|
||||||
* SWAP_B16_IN_B64 - swap 16 & 32 bits in 64 bits
|
* SWAP_B16_IN_B64 - swap 16 & 32 bits in 64 bits
|
||||||
*
|
*
|
||||||
* dest - pointer to where the swapped src wil be put
|
* dest - pointer to where the swapped src will be put
|
||||||
* src - pointer to a 64 bit value to swap
|
* src - pointer to a 64 bit value to swap
|
||||||
*/
|
*/
|
||||||
#define SWAP_B16_IN_B64(dest, src) ( \
|
#define SWAP_B16_IN_B64(dest, src) ( \
|
||||||
@@ -110,7 +106,7 @@
|
|||||||
/*
|
/*
|
||||||
* SWAP_B8_IN_B64 - swap 16 & 32 bits in 64 bits
|
* SWAP_B8_IN_B64 - swap 16 & 32 bits in 64 bits
|
||||||
*
|
*
|
||||||
* dest - pointer to where the swapped src wil be put
|
* dest - pointer to where the swapped src will be put
|
||||||
* src - pointer to a 64 bit value to swap
|
* src - pointer to a 64 bit value to swap
|
||||||
*
|
*
|
||||||
* This macro will either switch to the opposite byte sex (Big Endian vs.
|
* This macro will either switch to the opposite byte sex (Big Endian vs.
|
||||||
@@ -128,7 +124,7 @@
|
|||||||
/*
|
/*
|
||||||
* SWAP_B32_IN_B64 - swap 32 bits in 64 bits (simulated by 2 32 bit values)
|
* SWAP_B32_IN_B64 - swap 32 bits in 64 bits (simulated by 2 32 bit values)
|
||||||
*
|
*
|
||||||
* dest - pointer to where the swapped src wil be put
|
* dest - pointer to where the swapped src will be put
|
||||||
* src - pointer to a 64 bit value to swap
|
* src - pointer to a 64 bit value to swap
|
||||||
*/
|
*/
|
||||||
#define SWAP_B32_IN_B64(dest, src) ( \
|
#define SWAP_B32_IN_B64(dest, src) ( \
|
||||||
@@ -139,7 +135,7 @@
|
|||||||
/*
|
/*
|
||||||
* SWAP_B16_IN_B64 - swap 16 & 32 bits in 64 bits (simulated by 2 32 bit vals)
|
* SWAP_B16_IN_B64 - swap 16 & 32 bits in 64 bits (simulated by 2 32 bit vals)
|
||||||
*
|
*
|
||||||
* dest - pointer to where the swapped src wil be put
|
* dest - pointer to where the swapped src will be put
|
||||||
* src - pointer to a 64 bit value to swap
|
* src - pointer to a 64 bit value to swap
|
||||||
*/
|
*/
|
||||||
#define SWAP_B16_IN_B64(dest, src) ( \
|
#define SWAP_B16_IN_B64(dest, src) ( \
|
||||||
@@ -150,7 +146,7 @@
|
|||||||
/*
|
/*
|
||||||
* SWAP_B8_IN_B64 - swap 16 & 32 bits in 64 bits (simulated by 2 32 bit vals)
|
* SWAP_B8_IN_B64 - swap 16 & 32 bits in 64 bits (simulated by 2 32 bit vals)
|
||||||
*
|
*
|
||||||
* dest - pointer to where the swapped src wil be put
|
* dest - pointer to where the swapped src will be put
|
||||||
* src - pointer to a 64 bit value to swap
|
* src - pointer to a 64 bit value to swap
|
||||||
*
|
*
|
||||||
* This macro will either switch to the opposite byte sex (Big Endian vs.
|
* This macro will either switch to the opposite byte sex (Big Endian vs.
|
||||||
|
281
cal/Makefile
281
cal/Makefile
@@ -1,8 +1,10 @@
|
|||||||
#!/bin/make
|
#!/usr/bin/env make
|
||||||
#
|
#
|
||||||
# cal - makefile for calc standard resource files
|
# cal - makefile for calc standard resource files
|
||||||
#
|
#
|
||||||
# Copyright (C) 1999-2006,2017 Landon Curt Noll
|
# Copyright (C) 1999-2006,2017,2021-2023 Landon Curt Noll
|
||||||
|
#
|
||||||
|
# Suggestion: Read the ../HOWTO.INSTALL file.
|
||||||
#
|
#
|
||||||
# Calc is open software; you can redistribute it and/or modify it under
|
# 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
|
# the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -18,198 +20,127 @@
|
|||||||
# received a copy with calc; if not, write to Free Software Foundation, Inc.
|
# received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
# @(#) $Revision: 30.12 $
|
|
||||||
# @(#) $Id: Makefile,v 30.12 2017/05/19 16:09:14 chongo Exp $
|
|
||||||
# @(#) $Source: /usr/local/src/bin/calc-RHEL7/cal/RCS/Makefile,v $
|
|
||||||
#
|
|
||||||
# Under source code control: 1991/07/21 05:00:54
|
# Under source code control: 1991/07/21 05:00:54
|
||||||
# File existed as early as: 1991
|
# File existed as early as: 1991
|
||||||
#
|
#
|
||||||
|
# This calculator first developed by David I. Bell with help/mods from others.
|
||||||
|
#
|
||||||
# chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
# chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||||
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||||
#
|
|
||||||
# calculator by David I. Bell with help/mods from others
|
|
||||||
# Makefile by Landon Curt Noll
|
|
||||||
|
|
||||||
# required vars
|
|
||||||
#
|
|
||||||
SHELL= /bin/sh
|
|
||||||
|
|
||||||
####
|
# SUGGESTION: Instead of modifying this file, consider adding
|
||||||
# Normally, the upper level makefile will set these values. We provide
|
# statements to modify, replace or append Makefile
|
||||||
# a default here just in case you want to build from this directory.
|
# variables in the ../Makefile.local file.
|
||||||
####
|
|
||||||
|
|
||||||
|
###########################################
|
||||||
|
# Files used or included by this Makefile #
|
||||||
|
###########################################
|
||||||
|
|
||||||
# Normally certain files depend on the Makefile. If the Makefile is
|
# Normally certain files depend on the Makefile. If the Makefile is
|
||||||
# changed, then certain steps should be redone. If MAKE_FILE is
|
# changed, then certain steps should be redone. If MAKE_FILE is
|
||||||
# set to Makefile, then these files will depend on Makefile. If
|
# set to Makefile, then these files will depend on Makefile. If
|
||||||
# MAKE_FILE is empty, then they wont.
|
# MAKE_FILE is empty, then they won't.
|
||||||
#
|
#
|
||||||
# If in doubt, set MAKE_FILE to Makefile
|
# If in doubt, set MAKE_FILE to Makefile
|
||||||
#
|
#
|
||||||
MAKE_FILE= Makefile
|
MAKE_FILE= Makefile
|
||||||
|
|
||||||
# Controlling file makefile basename (without the path)
|
# Calc configuration and compile configuration values
|
||||||
#
|
#
|
||||||
# This is the basename same of the makefile that may/does/will drive
|
CONFIG_MKF= ../Makefile.config
|
||||||
# this makefile.
|
|
||||||
#
|
|
||||||
# If in doubt, set TOP_MAKE_FILE to Makefile
|
|
||||||
#
|
|
||||||
TOP_MAKE_FILE= Makefile
|
|
||||||
|
|
||||||
# Where the system include (.h) files are kept
|
# Host target information.
|
||||||
#
|
|
||||||
# For DJGPP, select:
|
|
||||||
#
|
|
||||||
# INCDIR= /dev/env/DJDIR/include
|
|
||||||
#
|
|
||||||
# If in doubt, set:
|
|
||||||
#
|
|
||||||
# INCDIR= /usr/include
|
|
||||||
#
|
#
|
||||||
|
TARGET_MKF= ../Makefile.target
|
||||||
|
|
||||||
#INCDIR= /usr/local/include
|
# Local file that is included just prior to the first rule,
|
||||||
#INCDIR= /dev/env/DJDIR/include
|
# that allows one to override any values set in this Makefile.
|
||||||
INCDIR= /usr/include
|
#
|
||||||
|
LOCAL_MKF= ../Makefile.local
|
||||||
|
|
||||||
# where to install calc realted things
|
# The set of Makefiles
|
||||||
#
|
#
|
||||||
# ${BINDIR} where to install calc binary files
|
MK_SET= ${MAKE_FILE} ${CONFIG_MKF} ${TARGET_MKF} ${LOCAL_MKF}
|
||||||
# ${LIBDIR} where calc link library (*.a) files are installed
|
|
||||||
# ${CALC_SHAREDIR} where to install calc help, .cal, startup, config files
|
|
||||||
#
|
|
||||||
# NOTE: The install rule prepends installation paths with ${T}, which
|
|
||||||
# by default is empty. If ${T} is non-empty, then installation
|
|
||||||
# locations will be relative to the ${T} directory.
|
|
||||||
#
|
|
||||||
# For DJGPP, select:
|
|
||||||
#
|
|
||||||
# BINDIR= /dev/env/DJDIR/bin
|
|
||||||
# LIBDIR= /dev/env/DJDIR/lib
|
|
||||||
# CALC_SHAREDIR= /dev/env/DJDIR/share/calc
|
|
||||||
#
|
|
||||||
# If in doubt, set:
|
|
||||||
#
|
|
||||||
# BINDIR= /usr/bin
|
|
||||||
# LIBDIR= /usr/lib
|
|
||||||
# CALC_SHAREDIR= /usr/share/calc
|
|
||||||
#
|
|
||||||
#BINDIR= /usr/local/bin
|
|
||||||
#BINDIR= /dev/env/DJDIR/bin
|
|
||||||
BINDIR= /usr/bin
|
|
||||||
|
|
||||||
#LIBDIR= /usr/local/lib
|
|
||||||
#LIBDIR= /dev/env/DJDIR/lib
|
|
||||||
LIBDIR= /usr/lib
|
|
||||||
|
|
||||||
#CALC_SHAREDIR= /usr/local/lib/calc
|
#######################################################
|
||||||
#CALC_SHAREDIR= /dev/env/DJDIR/share/calc
|
# Calc configuration and compile configuration values #
|
||||||
CALC_SHAREDIR= /usr/share/calc
|
#######################################################
|
||||||
|
include ${CONFIG_MKF}
|
||||||
|
|
||||||
# By default, these values are based CALC_SHAREDIR, INCDIR, BINDIR
|
|
||||||
# ---------------------------------------------------------------
|
|
||||||
# ${HELPDIR} where the help directory is installed
|
|
||||||
# ${CALC_INCDIR} where the calc include files are installed
|
|
||||||
# ${SCRIPTDIR} where calc shell scripts are installed
|
|
||||||
#
|
|
||||||
# NOTE: The install rule prepends installation paths with ${T}, which
|
|
||||||
# by default is empty. If ${T} is non-empty, then installation
|
|
||||||
# locations will be relative to the ${T} directory.
|
|
||||||
#
|
|
||||||
# If in doubt, set:
|
|
||||||
#
|
|
||||||
# HELPDIR= ${CALC_SHAREDIR}/help
|
|
||||||
# CALC_INCDIR= ${INCDIR}/calc
|
|
||||||
# SCRIPTDIR= ${BINDIR}/cscript
|
|
||||||
#
|
|
||||||
HELPDIR= ${CALC_SHAREDIR}/help
|
|
||||||
CALC_INCDIR= ${INCDIR}/calc
|
|
||||||
SCRIPTDIR= ${BINDIR}/cscript
|
|
||||||
|
|
||||||
# T - top level directory under which calc will be installed
|
###############################
|
||||||
#
|
# host target section include #
|
||||||
# The calc install is performed under ${T}, the calc build is
|
###############################
|
||||||
# performed under /. The purpose for ${T} is to allow someone
|
include ${TARGET_MKF}
|
||||||
# to install calc somewhere other than into the system area.
|
|
||||||
#
|
|
||||||
# For example, if:
|
##########################################################################
|
||||||
#
|
#=-=-=-=-=- Be careful if you change something below this line -=-=-=-=-=#
|
||||||
# BINDIR= /usr/bin
|
##########################################################################
|
||||||
# LIBDIR= /usr/lib
|
|
||||||
# CALC_SHAREDIR= /usr/share/calc
|
|
||||||
#
|
|
||||||
# and if:
|
|
||||||
#
|
|
||||||
# T= /var/tmp/testing
|
|
||||||
#
|
|
||||||
# Then the installation locations will be:
|
|
||||||
#
|
|
||||||
# calc binary files: /var/tmp/testing/usr/bin
|
|
||||||
# calc link library: /var/tmp/testing/usr/lib
|
|
||||||
# calc help, .cal ...: /var/tmp/testing/usr/share/calc
|
|
||||||
# ... etc ... /var/tmp/testing/...
|
|
||||||
#
|
|
||||||
# If ${T} is empty, calc is installed under /, which is the same
|
|
||||||
# top of tree for which it was built. If ${T} is non-empty, then
|
|
||||||
# calc is installed under ${T}, as if one had to chroot under
|
|
||||||
# ${T} for calc to operate.
|
|
||||||
#
|
|
||||||
# If in doubt, use T=
|
|
||||||
#
|
|
||||||
T=
|
|
||||||
|
|
||||||
# Makefile debug
|
# Makefile debug
|
||||||
#
|
#
|
||||||
# Q=@ do not echo internal makefile actions (quiet mode)
|
# Q=@ do not echo internal Makefile actions (quiet mode)
|
||||||
# Q= echo internal makefile actions (debug / verbose mode)
|
# Q= echo internal Makefile actions (debug / verbose mode)
|
||||||
|
#
|
||||||
|
# H=@: do not report hsrc file formation progress
|
||||||
|
# H=@ do echo hsrc file formation progress
|
||||||
|
#
|
||||||
|
# S= >/dev/null 2>&1 silence ${CC} output during hsrc file formation
|
||||||
|
# S= full ${CC} output during hsrc file formation
|
||||||
|
#
|
||||||
|
# E= 2>/dev/null silence command stderr during hsrc file formation
|
||||||
|
# E= full command stderr during hsrc file formation
|
||||||
|
#
|
||||||
|
# V=@: do not echo debug statements (quiet mode)
|
||||||
|
# V=@ do echo debug statements (debug / verbose mode)
|
||||||
#
|
#
|
||||||
#Q=
|
#Q=
|
||||||
Q=@
|
Q=@
|
||||||
|
|
||||||
# standard tools
|
|
||||||
#
|
#
|
||||||
CHMOD= chmod
|
S= >/dev/null 2>&1
|
||||||
CMP= cmp
|
#S=
|
||||||
RM= rm
|
#
|
||||||
MKDIR= mkdir
|
E= 2>/dev/null
|
||||||
RMDIR= rmdir
|
#E=
|
||||||
CP= cp
|
#
|
||||||
MV= mv
|
#H=@:
|
||||||
CO= co
|
H=@
|
||||||
TRUE= true
|
#
|
||||||
TOUCH= touch
|
V=@:
|
||||||
SED= sed
|
#V=@
|
||||||
SORT= sort
|
|
||||||
FMT= fmt
|
|
||||||
|
|
||||||
# The calc files to install
|
# The calc files to install
|
||||||
#
|
#
|
||||||
# This list is prodiced by the detaillist rule when no WARNINGS are detected.
|
# This list is produced by the detaillist rule when no WARNINGS are detected.
|
||||||
#
|
#
|
||||||
# Please use:
|
# Please use:
|
||||||
#
|
#
|
||||||
# make calc_files_list
|
# make calc_files_list
|
||||||
#
|
#
|
||||||
# to keep this list in nice sorted order and to check that these
|
# to keep this list in nice sorted order.
|
||||||
# deailed help files are under RCS control.
|
|
||||||
#
|
#
|
||||||
CALC_FILES= README alg_config.cal beer.cal bernoulli.cal \
|
CALC_FILES= README alg_config.cal beer.cal bernoulli.cal \
|
||||||
bernpoly.cal bigprime.cal bindings brentsolve.cal chi.cal chrem.cal \
|
bernpoly.cal bigprime.cal bindings brentsolve.cal chi.cal chrem.cal \
|
||||||
constants.cal deg.cal dms.cal dotest.cal ellip.cal factorial.cal \
|
comma.cal constants.cal deg.cal dms.cal dotest.cal ellip.cal \
|
||||||
factorial2.cal gvec.cal hello.cal hms.cal infinities.cal \
|
factorial.cal factorial2.cal fnv_tool.cal gvec.cal hello.cal hms.cal \
|
||||||
intfile.cal intnum.cal lambertw.cal linear.cal lnseries.cal \
|
infinities.cal intfile.cal intnum.cal lambertw.cal linear.cal \
|
||||||
lucas.cal lucas_chk.cal mersenne.cal mfactor.cal \
|
lnseries.cal lucas.cal lucas_chk.cal mersenne.cal mfactor.cal mod.cal \
|
||||||
mod.cal natnumset.cal pell.cal pi.cal pix.cal pollard.cal poly.cal \
|
natnumset.cal palindrome.cal pell.cal pi.cal pix.cal pollard.cal \
|
||||||
prompt.cal psqrt.cal qtime.cal quat.cal randbitrun.cal randmprime.cal \
|
poly.cal prompt.cal psqrt.cal qtime.cal quat.cal randbitrun.cal \
|
||||||
randombitrun.cal randomrun.cal randrun.cal regress.cal repeat.cal \
|
randmprime.cal randombitrun.cal randomrun.cal randrun.cal regress.cal \
|
||||||
screen.cal seedrandom.cal set8700.cal set8700.line smallfactors.cal \
|
repeat.cal screen.cal seedrandom.cal set8700.cal set8700.line \
|
||||||
solve.cal specialfunctions.cal statistics.cal strings.cal sumsq.cal \
|
smallfactors.cal solve.cal specialfunctions.cal splitbits.cal \
|
||||||
sumtimes.cal surd.cal test1700.cal test2300.cal test2600.cal \
|
statistics.cal strings.cal sumsq.cal sumtimes.cal surd.cal \
|
||||||
test2700.cal test3100.cal test3300.cal test3400.cal test3500.cal \
|
test1700.cal test2300.cal test2600.cal test2700.cal test3100.cal \
|
||||||
test4000.cal test4100.cal test4600.cal test5100.cal test5200.cal \
|
test3300.cal test3400.cal test3500.cal test4000.cal test4100.cal \
|
||||||
test8400.cal test8500.cal test8600.cal test8900.cal toomcook.cal \
|
test4600.cal test5100.cal test5200.cal test8400.cal test8500.cal \
|
||||||
unitfrac.cal varargs.cal xx_print.cal zeta2.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.
|
# These calc files are now obsolete and are removed by the install rule.
|
||||||
#
|
#
|
||||||
@@ -222,15 +153,37 @@ DISTLIST= ${CALC_FILES} ${MAKE_FILE}
|
|||||||
# These files are used to make (but not built) a calc .a link library
|
# These files are used to make (but not built) a calc .a link library
|
||||||
#
|
#
|
||||||
CALCLIBLIST=
|
CALCLIBLIST=
|
||||||
|
#
|
||||||
|
# rules that are not also names of files
|
||||||
|
#
|
||||||
|
PHONY= all clobber distlist install
|
||||||
|
|
||||||
|
|
||||||
|
############################################################
|
||||||
|
# Allow Makefile.local to change any of the above settings #
|
||||||
|
############################################################
|
||||||
|
include ${LOCAL_MKF}
|
||||||
|
|
||||||
|
|
||||||
|
###########################################
|
||||||
|
# all - First and default Makefile target #
|
||||||
|
###########################################
|
||||||
|
|
||||||
all: ${CALC_FILES} ${MAKE_FILE} .all
|
all: ${CALC_FILES} ${MAKE_FILE} .all
|
||||||
|
|
||||||
|
|
||||||
|
###############################
|
||||||
|
# additional Makefile targets #
|
||||||
|
###############################
|
||||||
|
|
||||||
# used by the upper level Makefile to determine of we have done all
|
# used by the upper level Makefile to determine of we have done all
|
||||||
#
|
#
|
||||||
.all:
|
.all:
|
||||||
${RM} -f .all
|
${RM} -f .all
|
||||||
${TOUCH} .all
|
${TOUCH} .all
|
||||||
|
|
||||||
|
.PHONY: ${PHONY}
|
||||||
|
|
||||||
##
|
##
|
||||||
#
|
#
|
||||||
# File list generation. You can ignore this section.
|
# File list generation. You can ignore this section.
|
||||||
@@ -240,7 +193,7 @@ all: ${CALC_FILES} ${MAKE_FILE} .all
|
|||||||
# sub-directory called calc/cal.
|
# sub-directory called calc/cal.
|
||||||
#
|
#
|
||||||
# NOTE: Due to bogus shells found on one common system we must have
|
# NOTE: Due to bogus shells found on one common system we must have
|
||||||
# an non-emoty else clause for every if condition. *sigh*
|
# an non-empty else clause for every if condition. *sigh*
|
||||||
#
|
#
|
||||||
##
|
##
|
||||||
|
|
||||||
@@ -265,19 +218,13 @@ calcliblist:
|
|||||||
#
|
#
|
||||||
calc_files_list:
|
calc_files_list:
|
||||||
${Q} -(find . -mindepth 1 -maxdepth 1 -type f -name '*.cal' -print | \
|
${Q} -(find . -mindepth 1 -maxdepth 1 -type f -name '*.cal' -print | \
|
||||||
while read i; do \
|
while read i; do \
|
||||||
if [ X"$$i" != X"/dev/null" ]; then \
|
echo $$i; \
|
||||||
if [ ! -f RCS/$$i,v ]; then \
|
done; \
|
||||||
echo "WARNING: $$i not under RCS control" 1>&2; \
|
echo '--first_line--'; \
|
||||||
else \
|
echo README; \
|
||||||
echo $$i; \
|
echo set8700.line; \
|
||||||
fi; \
|
echo bindings) | \
|
||||||
fi; \
|
|
||||||
done; \
|
|
||||||
echo '--first_line--'; \
|
|
||||||
echo README; \
|
|
||||||
echo set8700.line; \
|
|
||||||
echo bindings) | \
|
|
||||||
${SED} -e 's:^\./::' | LANG=C ${SORT} | ${FMT} -70 | \
|
${SED} -e 's:^\./::' | LANG=C ${SORT} | ${FMT} -70 | \
|
||||||
${SED} -e '1s/--first_line--/CALC_FILES=/' -e '2,$$s/^/ /' \
|
${SED} -e '1s/--first_line--/CALC_FILES=/' -e '2,$$s/^/ /' \
|
||||||
-e 's/$$/ \\/' -e '$$s/ \\$$//'
|
-e 's/$$/ \\/' -e '$$s/ \\$$//'
|
||||||
@@ -391,11 +338,11 @@ uninstall:
|
|||||||
continue; \
|
continue; \
|
||||||
fi; \
|
fi; \
|
||||||
if [ -f "${T}${CALC_SHAREDIR}/$$i" ]; then \
|
if [ -f "${T}${CALC_SHAREDIR}/$$i" ]; then \
|
||||||
${RM} -f "${T}${CALC_SHAREDIR}/$$i"; \
|
${RM} -f "${T}${CALC_SHAREDIR}/$$i"; \
|
||||||
if [ -f "${T}${CALC_SHAREDIR}/$$i" ]; then \
|
if [ -f "${T}${CALC_SHAREDIR}/$$i" ]; then \
|
||||||
echo "cannot uninstall ${T}${CALC_SHAREDIR}/$$i"; \
|
echo "cannot uninstall ${T}${CALC_SHAREDIR}/$$i"; \
|
||||||
else \
|
else \
|
||||||
echo "uninstalled ${T}${CALC_SHAREDIR}/$$i"; \
|
echo "un-installed ${T}${CALC_SHAREDIR}/$$i"; \
|
||||||
fi; \
|
fi; \
|
||||||
fi; \
|
fi; \
|
||||||
done
|
done
|
||||||
|
295
cal/README
295
cal/README
@@ -38,43 +38,6 @@ Calc resource file files are provided because they serve as examples of
|
|||||||
how use the calc language, and/or because the authors thought them to
|
how use the calc language, and/or because the authors thought them to
|
||||||
be useful!
|
be useful!
|
||||||
|
|
||||||
If you write something that you think is useful, please join the
|
|
||||||
low volume calc mailing list calc-tester. Then send your contribution
|
|
||||||
to the calc-tester mailing list.
|
|
||||||
|
|
||||||
To subscribe to the calc-tester mailing list, visit the following URL:
|
|
||||||
|
|
||||||
https://www.listbox.com/subscribe/?list_id=239342
|
|
||||||
|
|
||||||
To help determine you are a human and not just a spam bot,
|
|
||||||
you will be required to provide the following additional info:
|
|
||||||
|
|
||||||
Your Name
|
|
||||||
Calc Version
|
|
||||||
Operating System
|
|
||||||
The date 7 days ago
|
|
||||||
|
|
||||||
This is a low volume moderated mailing list.
|
|
||||||
|
|
||||||
This mailing list replaces calc-tester at asthe dot com list.
|
|
||||||
|
|
||||||
If you need a human to help you with your mailing list subscription,
|
|
||||||
please send EMail to our special:
|
|
||||||
|
|
||||||
calc-tester-maillist-help at asthe dot com
|
|
||||||
|
|
||||||
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
|
|
||||||
|
|
||||||
address. To be sure we see your EMail asking for help with your
|
|
||||||
mailing list subscription, please use the following phase in your
|
|
||||||
EMail Subject line:
|
|
||||||
|
|
||||||
calc tester mailing list help
|
|
||||||
|
|
||||||
That phrase in your subject line will help ensure your
|
|
||||||
request will get past our anti-spam filters. You may have
|
|
||||||
additional words in your subject line.
|
|
||||||
|
|
||||||
=-=
|
=-=
|
||||||
|
|
||||||
By convention, a resource file only defines and/or initializes functions,
|
By convention, a resource file only defines and/or initializes functions,
|
||||||
@@ -223,7 +186,7 @@ bernoulli.cal
|
|||||||
Calculate the nth Bernoulli number.
|
Calculate the nth Bernoulli number.
|
||||||
|
|
||||||
NOTE: There is now a bernoulli() builtin function. This file is
|
NOTE: There is now a bernoulli() builtin function. This file is
|
||||||
left here for backward compatibility and now simply returns
|
left here for backward compatibility and now simply returns
|
||||||
the builtin function.
|
the builtin function.
|
||||||
|
|
||||||
|
|
||||||
@@ -250,12 +213,12 @@ brentsolve.cal
|
|||||||
|
|
||||||
brentsolve(low, high,eps)
|
brentsolve(low, high,eps)
|
||||||
|
|
||||||
A root-finder implementwed with the Brent-Dekker trick.
|
A root-finder implemented with the Brent-Dekker trick.
|
||||||
|
|
||||||
brentsolve2(low, high,which,eps)
|
brentsolve2(low, high,which,eps)
|
||||||
|
|
||||||
The second function, brentsolve2(low, high,which,eps) has some lines
|
The second function, brentsolve2(low, high,which,eps) has some lines
|
||||||
added to make it easier to hardcode the name of the helper function
|
added to make it easier to hard-code the name of the helper function
|
||||||
different from the obligatory "f".
|
different from the obligatory "f".
|
||||||
|
|
||||||
See:
|
See:
|
||||||
@@ -300,6 +263,64 @@ chrem.cal
|
|||||||
Chinese remainder theorem/problem solver.
|
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.cal
|
||||||
|
|
||||||
deg(deg, min, sec)
|
deg(deg, min, sec)
|
||||||
@@ -367,6 +388,13 @@ dotest.cal
|
|||||||
dotest("set8700.line");
|
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.cal
|
||||||
|
|
||||||
factorial(n)
|
factorial(n)
|
||||||
@@ -429,7 +457,7 @@ factorial2.cal
|
|||||||
|
|
||||||
bigcatalan(n)
|
bigcatalan(n)
|
||||||
|
|
||||||
Calculates the n-th Catalan number for n large. It is usefull
|
Calculates the n-th Catalan number for n large. It is useful
|
||||||
above n~50,000 but defaults to the builtin function for smaller
|
above n~50,000 but defaults to the builtin function for smaller
|
||||||
values.Meant as a complete replacement for catalan(n) with only a
|
values.Meant as a complete replacement for catalan(n) with only a
|
||||||
very small overhead. See:
|
very small overhead. See:
|
||||||
@@ -470,9 +498,9 @@ factorial2.cal
|
|||||||
k = 0
|
k = 0
|
||||||
|
|
||||||
The other function stirling2caching(n,m) does it by way of the
|
The other function stirling2caching(n,m) does it by way of the
|
||||||
reccurence relation and keeps all earlier results. This function
|
re-occurrence relation and keeps all earlier results. This function
|
||||||
is much slower for computing a single value than stirling2(n,m) but
|
is much slower for computing a single value than stirling2(n,m) but
|
||||||
is very usefull if many Stirling numbers are needed, for example in
|
is very useful if many Stirling numbers are needed, for example in
|
||||||
a series. See:
|
a series. See:
|
||||||
|
|
||||||
http://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind
|
http://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind
|
||||||
@@ -527,12 +555,65 @@ factorial2.cal
|
|||||||
for information on falling factorials.
|
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
|
gvec.cal
|
||||||
|
|
||||||
@@ -583,7 +664,7 @@ infinities.cal
|
|||||||
pinf()
|
pinf()
|
||||||
|
|
||||||
The symbolic handling of infinities. Needed for intnum.cal but might be
|
The symbolic handling of infinities. Needed for intnum.cal but might be
|
||||||
usefull elsewhere, too.
|
useful elsewhere, too.
|
||||||
|
|
||||||
|
|
||||||
intfile.cal
|
intfile.cal
|
||||||
@@ -632,13 +713,13 @@ intnum.cal
|
|||||||
This file offers some methods for numerical integration. Implemented are
|
This file offers some methods for numerical integration. Implemented are
|
||||||
the Gauss-Legendre and the tanh-sinh quadrature.
|
the Gauss-Legendre and the tanh-sinh quadrature.
|
||||||
|
|
||||||
All functions are usefull to some extend but the main function for
|
All functions are useful to some extend but the main function for
|
||||||
quadrature is quad(), which is not much more than an abstraction layer.
|
quadrature is quad(), which is not much more than an abstraction layer.
|
||||||
|
|
||||||
The main workers are quadgl() for Gauss-legendre and quadts() for the
|
The main workers are quadgl() for Gauss-Legendre and quadts() for the
|
||||||
tanh-sinh quadrature. The limits of the integral can be anything in the
|
tanh-sinh quadrature. The limits of the integral can be anything in the
|
||||||
complex plane and the extended real line. The latter means that infinite
|
complex plane and the extended real line. The latter means that infinite
|
||||||
limits are supported by way of the smbolic infinities implemented in the
|
limits are supported by way of the symbolic infinities implemented in the
|
||||||
file infinities.cal (automatically linked in by intnum.cal).
|
file infinities.cal (automatically linked in by intnum.cal).
|
||||||
|
|
||||||
Integration in parts and contour is supported by the "points" argument
|
Integration in parts and contour is supported by the "points" argument
|
||||||
@@ -698,7 +779,7 @@ intnum.cal
|
|||||||
|
|
||||||
The quad*core functions do not offer anything fancy but the third parameter
|
The quad*core functions do not offer anything fancy but the third parameter
|
||||||
controls the so called "order" which is just the number of nodes computed.
|
controls the so called "order" which is just the number of nodes computed.
|
||||||
This can be quite usefull in some circumstances.
|
This can be quite useful in some circumstances.
|
||||||
|
|
||||||
; quadgldeletenodes()
|
; quadgldeletenodes()
|
||||||
; define f(x){ return exp(x);}
|
; define f(x){ return exp(x);}
|
||||||
@@ -760,7 +841,7 @@ lambertw.cal
|
|||||||
ProductLog[branch,z] with the tested values.
|
ProductLog[branch,z] with the tested values.
|
||||||
|
|
||||||
The series is only valid for the branches 0,-1, real z, converges
|
The series is only valid for the branches 0,-1, real z, converges
|
||||||
for values of z _very_ near the branchpoint -exp(-1) only, and must
|
for values of z _very_ near the branch-point -exp(-1) only, and must
|
||||||
be given the branches explicitly. See the code in lambertw.cal
|
be given the branches explicitly. See the code in lambertw.cal
|
||||||
for further information.
|
for further information.
|
||||||
|
|
||||||
@@ -783,7 +864,7 @@ lnseries.cal
|
|||||||
does so by computing the prime factorization of all of the number
|
does so by computing the prime factorization of all of the number
|
||||||
sequence 1,2,3...n, calculates the natural logarithms of the primes
|
sequence 1,2,3...n, calculates the natural logarithms of the primes
|
||||||
in 1,2,3...n and uses the above factorization to build the natural
|
in 1,2,3...n and uses the above factorization to build the natural
|
||||||
logarithms of the rest of the sequence by sadding the logarithms of
|
logarithms of the rest of the sequence by adding the logarithms of
|
||||||
the primes in the factorization. This is faster for high precision
|
the primes in the factorization. This is faster for high precision
|
||||||
of the logarithms and/or long sequences.
|
of the logarithms and/or long sequences.
|
||||||
|
|
||||||
@@ -804,7 +885,7 @@ lucas.cal
|
|||||||
prove that h*2^n-1 is prime or not prime.
|
prove that h*2^n-1 is prime or not prime.
|
||||||
|
|
||||||
NOTE: Some call this term u(0). The function gen_u0(h, n, v1)
|
NOTE: Some call this term u(0). The function gen_u0(h, n, v1)
|
||||||
simply calls gen_u2(h, n, v1) for such people. :-)
|
simply calls gen_u2(h, n, v1) for such people. :-)
|
||||||
|
|
||||||
gen_v1(h, v)
|
gen_v1(h, v)
|
||||||
|
|
||||||
@@ -843,7 +924,7 @@ mfactor.cal
|
|||||||
at 2*start_k*n+1. Skips values that are multiples of primes <= p_elim.
|
at 2*start_k*n+1. Skips values that are multiples of primes <= p_elim.
|
||||||
By default, start_k == 1, rept_loop = 10000 and p_elim = 17.
|
By default, start_k == 1, rept_loop = 10000 and p_elim = 17.
|
||||||
|
|
||||||
The p_elim == 17 overhead takes ~3 minutes on an 200 Mhz r4k CPU and
|
The p_elim == 17 overhead takes ~3 minutes on an 200 MHz r4k CPU and
|
||||||
requires about ~13 Megs of memory. The p_elim == 13 overhead
|
requires about ~13 Megs of memory. The p_elim == 13 overhead
|
||||||
takes about 3 seconds and requires ~1.5 Megs of memory.
|
takes about 3 seconds and requires ~1.5 Megs of memory.
|
||||||
|
|
||||||
@@ -916,6 +997,38 @@ natnumset.cal
|
|||||||
user-specified bound.
|
user-specified bound.
|
||||||
|
|
||||||
|
|
||||||
|
palindrome.cal
|
||||||
|
|
||||||
|
digitof(val,place)
|
||||||
|
copalplace(d,place)
|
||||||
|
upperhalf(val)
|
||||||
|
mkpal(val)
|
||||||
|
mkpalmiddigit(val,digit)
|
||||||
|
ispal(val)
|
||||||
|
nextpal(val)
|
||||||
|
prevpal(val)
|
||||||
|
nextprimepal(val)
|
||||||
|
prevprimepal(val)
|
||||||
|
|
||||||
|
Functions to form and manipulate palindromes in base 10.
|
||||||
|
|
||||||
|
Important functions are:
|
||||||
|
|
||||||
|
Find the next / previous palindrome:
|
||||||
|
|
||||||
|
nextpal(val)
|
||||||
|
prevpal(val)
|
||||||
|
|
||||||
|
Test if a value is a palindrome:
|
||||||
|
|
||||||
|
ispal(val)
|
||||||
|
|
||||||
|
Find the next / previous palindrome that is a (highly probable) prime:
|
||||||
|
|
||||||
|
nextprimepal(val)
|
||||||
|
prevprimepal(val)
|
||||||
|
|
||||||
|
|
||||||
pell.cal
|
pell.cal
|
||||||
|
|
||||||
pellx(D)
|
pellx(D)
|
||||||
@@ -937,7 +1050,7 @@ pi.cal
|
|||||||
as your free memory space and system up time allows.
|
as your free memory space and system up time allows.
|
||||||
|
|
||||||
The piforever() function (written by Klaus Alexander Seistrup
|
The piforever() function (written by Klaus Alexander Seistrup
|
||||||
<klaus@seistrup.dk>) was inspired by an algorithm conceived by
|
<klaus at seistrup dot dk>) was inspired by an algorithm conceived by
|
||||||
Lambert Meertens. See also the ABC Programmer's Handbook, by Geurts,
|
Lambert Meertens. See also the ABC Programmer's Handbook, by Geurts,
|
||||||
Meertens & Pemberton, published by Prentice-Hall (UK) Ltd., 1990.
|
Meertens & Pemberton, published by Prentice-Hall (UK) Ltd., 1990.
|
||||||
|
|
||||||
@@ -1354,7 +1467,7 @@ specialfunctions.cal
|
|||||||
http://en.wikipedia.org/wiki/Polygamma
|
http://en.wikipedia.org/wiki/Polygamma
|
||||||
http://dlmf.nist.gov/5
|
http://dlmf.nist.gov/5
|
||||||
|
|
||||||
for information on the n-th derivative ofthe Euler gamma function. This
|
for information on the n-th derivative of the Euler gamma function. This
|
||||||
function depends on the script zeta2.cal.
|
function depends on the script zeta2.cal.
|
||||||
|
|
||||||
|
|
||||||
@@ -1371,7 +1484,7 @@ specialfunctions.cal
|
|||||||
|
|
||||||
zeta(s)
|
zeta(s)
|
||||||
|
|
||||||
Calculates the value of the Rieman Zeta function at s. See:
|
Calculates the value of the Riemann Zeta function at s. See:
|
||||||
|
|
||||||
http://en.wikipedia.org/wiki/Riemann_zeta_function
|
http://en.wikipedia.org/wiki/Riemann_zeta_function
|
||||||
http://dlmf.nist.gov/25.2
|
http://dlmf.nist.gov/25.2
|
||||||
@@ -1380,6 +1493,60 @@ specialfunctions.cal
|
|||||||
on the script zeta2.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
|
statistics.cal
|
||||||
|
|
||||||
gammaincoctave(z,a)
|
gammaincoctave(z,a)
|
||||||
@@ -1390,7 +1557,7 @@ statistics.cal
|
|||||||
invbetainc(x,a,b)
|
invbetainc(x,a,b)
|
||||||
|
|
||||||
Computes the inverse of the regularized beta function. Does so the
|
Computes the inverse of the regularized beta function. Does so the
|
||||||
brute-force way wich makes it a bit slower.
|
brute-force way which makes it a bit slower.
|
||||||
|
|
||||||
betapdf(x,a,b)
|
betapdf(x,a,b)
|
||||||
betacdf(x,a,b)
|
betacdf(x,a,b)
|
||||||
@@ -1470,9 +1637,9 @@ sumtimes.cal
|
|||||||
Give the user CPU time for various ways of evaluating sums, sums of
|
Give the user CPU time for various ways of evaluating sums, sums of
|
||||||
squares, etc, for large lists and matrices. N is the size of
|
squares, etc, for large lists and matrices. N is the size of
|
||||||
the list or matrix to use. The doalltimes() function will run
|
the list or matrix to use. The doalltimes() function will run
|
||||||
all fo the sumtimes tests. For example:
|
all of the sumtimes tests. For example:
|
||||||
|
|
||||||
doalltimes(1e6);
|
doalltimes(1e6);
|
||||||
|
|
||||||
|
|
||||||
surd.cal
|
surd.cal
|
||||||
@@ -1816,7 +1983,7 @@ zeta2.cal
|
|||||||
for information on this special zeta function.
|
for information on this special zeta function.
|
||||||
|
|
||||||
|
|
||||||
## Copyright (C) 2000,2014,2017 David I. Bell and Landon Curt Noll
|
## Copyright (C) 2000,2014,2017,2021 David I. Bell and Landon Curt Noll
|
||||||
##
|
##
|
||||||
## Primary author: Landon Curt Noll
|
## Primary author: Landon Curt Noll
|
||||||
##
|
##
|
||||||
@@ -1834,10 +2001,6 @@ zeta2.cal
|
|||||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
##
|
##
|
||||||
## @(#) $Revision: 30.10 $
|
|
||||||
## @(#) $Id: README,v 30.10 2017/05/19 16:09:14 chongo Exp $
|
|
||||||
## @(#) $Source: /usr/local/src/bin/calc-RHEL7/cal/RCS/README,v $
|
|
||||||
##
|
|
||||||
## Under source code control: 1990/02/15 01:50:32
|
## Under source code control: 1990/02/15 01:50:32
|
||||||
## File existed as early as: before 1990
|
## File existed as early as: before 1990
|
||||||
##
|
##
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* alg_config - help determine optimal values for algorithm levels
|
* alg_config - help determine optimal values for algorithm levels
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006,2014 Landon Curt Noll
|
* Copyright (C) 2006,2014,2021 Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.12 $
|
|
||||||
* @(#) $Id: alg_config.cal,v 30.12 2016/02/06 08:38:56 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/alg_config.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2006/06/07 14:10:11
|
* Under source code control: 2006/06/07 14:10:11
|
||||||
* File existed as early as: 2006
|
* File existed as early as: 2006
|
||||||
*
|
*
|
||||||
@@ -37,7 +33,7 @@ static test_time; /* try for this many seconds in loop test */
|
|||||||
* given:
|
* given:
|
||||||
* ratio the ratio of time between two algorithms
|
* ratio the ratio of time between two algorithms
|
||||||
*
|
*
|
||||||
* retuns:
|
* returns:
|
||||||
* 1 When ratio is near 1.0
|
* 1 When ratio is near 1.0
|
||||||
* 0 otherwise
|
* 0 otherwise
|
||||||
*
|
*
|
||||||
@@ -358,7 +354,7 @@ define best_mul2()
|
|||||||
local high; /* high loop value tested */
|
local high; /* high loop value tested */
|
||||||
local mid; /* between low and high */
|
local mid; /* between low and high */
|
||||||
local best_val; /* value found with ratio closest to unity */
|
local best_val; /* value found with ratio closest to unity */
|
||||||
local best_ratio; /* cloest ratio found to unity */
|
local best_ratio; /* closest ratio found to unity */
|
||||||
local expand; /* how fast to expand the length */
|
local expand; /* how fast to expand the length */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -367,7 +363,7 @@ define best_mul2()
|
|||||||
printf("WARNING: This tool may not be computing the correct best value\n");
|
printf("WARNING: This tool may not be computing the correct best value\n");
|
||||||
test_time = 5.0;
|
test_time = 5.0;
|
||||||
printf("The best_mul2() function will take a LONG time to run!\n");
|
printf("The best_mul2() function will take a LONG time to run!\n");
|
||||||
printf("It is important that best_mul2() run on an othwewise idle host!\n");
|
printf("It is important that best_mul2() run on an otherwise idle host!\n");
|
||||||
if (config("user_debug") <= 0) {
|
if (config("user_debug") <= 0) {
|
||||||
printf("To monitor progress, set user_debug to 2: "
|
printf("To monitor progress, set user_debug to 2: "
|
||||||
"config(\"user_debug\", 2)\n");
|
"config(\"user_debug\", 2)\n");
|
||||||
@@ -396,7 +392,7 @@ define best_mul2()
|
|||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
/*
|
/*
|
||||||
* determine the paramters of the next ratio test
|
* determine the parameters of the next ratio test
|
||||||
*
|
*
|
||||||
* We will multiplicatively expand our test level until
|
* We will multiplicatively expand our test level until
|
||||||
* the ratio drops below 1.0.
|
* the ratio drops below 1.0.
|
||||||
@@ -423,7 +419,7 @@ define best_mul2()
|
|||||||
best_val = high;
|
best_val = high;
|
||||||
best_ratio = ratio;
|
best_ratio = ratio;
|
||||||
if (config("user_debug") > 1) {
|
if (config("user_debug") > 1) {
|
||||||
printf(" len %d has a new cloest ratio to unity: %.6f\n",
|
printf(" len %d has a new closest ratio to unity: %.6f\n",
|
||||||
best_val, best_ratio);
|
best_val, best_ratio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -446,7 +442,7 @@ define best_mul2()
|
|||||||
high /= 2;
|
high /= 2;
|
||||||
low = high / 2;
|
low = high / 2;
|
||||||
if (config("user_debug") > 0) {
|
if (config("user_debug") > 0) {
|
||||||
printf("retesting multiply alg1/alg2 ratio for len = %d\n",
|
printf("re-testing multiply alg1/alg2 ratio for len = %d\n",
|
||||||
high);
|
high);
|
||||||
}
|
}
|
||||||
ratio = mul_ratio(high);
|
ratio = mul_ratio(high);
|
||||||
@@ -454,7 +450,8 @@ define best_mul2()
|
|||||||
best_val = high;
|
best_val = high;
|
||||||
best_ratio = ratio;
|
best_ratio = ratio;
|
||||||
if (config("user_debug") > 1) {
|
if (config("user_debug") > 1) {
|
||||||
printf(" len %d has a new cloest ratio to unity: %.6f\n",
|
printf(" len %d has a new closest ratio "
|
||||||
|
"to unity: %.6f\n",
|
||||||
best_val, best_ratio);
|
best_val, best_ratio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -477,7 +474,7 @@ define best_mul2()
|
|||||||
*/
|
*/
|
||||||
while (low+1 < high) {
|
while (low+1 < high) {
|
||||||
|
|
||||||
/* try the mid-point */
|
/* try the mid-point */
|
||||||
mid = int((low+high)/2);
|
mid = int((low+high)/2);
|
||||||
if (config("user_debug") > 0) {
|
if (config("user_debug") > 0) {
|
||||||
printf("testing multiply alg1/alg2 ratio for len = %d\n", mid);
|
printf("testing multiply alg1/alg2 ratio for len = %d\n", mid);
|
||||||
@@ -487,7 +484,7 @@ define best_mul2()
|
|||||||
best_val = mid;
|
best_val = mid;
|
||||||
best_ratio = ratio;
|
best_ratio = ratio;
|
||||||
if (config("user_debug") > 1) {
|
if (config("user_debug") > 1) {
|
||||||
printf(" len %d has a new cloest ratio to unity: %.6f\n",
|
printf(" len %d has a new closest ratio to unity: %.6f\n",
|
||||||
best_val, best_ratio);
|
best_val, best_ratio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -500,7 +497,7 @@ define best_mul2()
|
|||||||
low = mid;
|
low = mid;
|
||||||
high = mid;
|
high = mid;
|
||||||
if (config("user_debug") > 0) {
|
if (config("user_debug") > 0) {
|
||||||
printf("\twe are close enough to unity ratio at: %d\n", mid);
|
printf("\twe are close enough to unity ratio at: %d\n", mid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -508,7 +505,7 @@ define best_mul2()
|
|||||||
/* bump lower range up if we went over */
|
/* bump lower range up if we went over */
|
||||||
if (ratio > 1.0) {
|
if (ratio > 1.0) {
|
||||||
if (config("user_debug") > 2) {
|
if (config("user_debug") > 2) {
|
||||||
printf("\tmove low from %d up to %d\n",
|
printf("\tmove low from %d up to %d\n",
|
||||||
low, mid);
|
low, mid);
|
||||||
}
|
}
|
||||||
low = mid;
|
low = mid;
|
||||||
@@ -516,7 +513,7 @@ define best_mul2()
|
|||||||
/* drop higher range down if we went under */
|
/* drop higher range down if we went under */
|
||||||
} else {
|
} else {
|
||||||
if (config("user_debug") > 2) {
|
if (config("user_debug") > 2) {
|
||||||
printf("\tmove high from %d down to %d\n",
|
printf("\tmove high from %d down to %d\n",
|
||||||
high, mid);
|
high, mid);
|
||||||
}
|
}
|
||||||
high = mid;
|
high = mid;
|
||||||
@@ -525,7 +522,7 @@ define best_mul2()
|
|||||||
/* report on test loop progress */
|
/* report on test loop progress */
|
||||||
if (config("user_debug") > 1) {
|
if (config("user_debug") > 1) {
|
||||||
printf("\tsetting low: %d high: %d diff: %d\n",
|
printf("\tsetting low: %d high: %d diff: %d\n",
|
||||||
low, high, high-low);
|
low, high, high-low);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -539,7 +536,7 @@ define best_mul2()
|
|||||||
printf("config(\"mul2\", %d),;\n", best_val);
|
printf("config(\"mul2\", %d),;\n", best_val);
|
||||||
printf("WARNING: It is believed that the output "
|
printf("WARNING: It is believed that the output "
|
||||||
"of this resource file is bogus!\n");
|
"of this resource file is bogus!\n");
|
||||||
printf("WARNING: You may NOT wish to follow the above suggeston.\n");
|
printf("WARNING: You may NOT wish to follow the above suggestion.\n");
|
||||||
}
|
}
|
||||||
return mid;
|
return mid;
|
||||||
}
|
}
|
||||||
@@ -839,7 +836,7 @@ define best_sq2()
|
|||||||
local high; /* high loop value tested */
|
local high; /* high loop value tested */
|
||||||
local mid; /* between low and high */
|
local mid; /* between low and high */
|
||||||
local best_val; /* value found with ratio closest to unity */
|
local best_val; /* value found with ratio closest to unity */
|
||||||
local best_ratio; /* cloest ratio found to unity */
|
local best_ratio; /* closest ratio found to unity */
|
||||||
local expand; /* how fast to expand the length */
|
local expand; /* how fast to expand the length */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -848,7 +845,7 @@ define best_sq2()
|
|||||||
printf("WARNING: This tool may not be computing the correct best value\n");
|
printf("WARNING: This tool may not be computing the correct best value\n");
|
||||||
test_time = 5.0;
|
test_time = 5.0;
|
||||||
printf("The best_sq2() function will take a LONG time to run!\n");
|
printf("The best_sq2() function will take a LONG time to run!\n");
|
||||||
printf("It is important that best_sq2() run on an othwewise idle host!\n");
|
printf("It is important that best_sq2() run on an otherwise idle host!\n");
|
||||||
if (config("user_debug") <= 0) {
|
if (config("user_debug") <= 0) {
|
||||||
printf("To monitor progress, set user_debug to 2: "
|
printf("To monitor progress, set user_debug to 2: "
|
||||||
"config(\"user_debug\", 2)\n");
|
"config(\"user_debug\", 2)\n");
|
||||||
@@ -877,7 +874,7 @@ define best_sq2()
|
|||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
/*
|
/*
|
||||||
* determine the paramters of the next ratio test
|
* determine the parameters of the next ratio test
|
||||||
*
|
*
|
||||||
* We will multiplicatively expand our test level until
|
* We will multiplicatively expand our test level until
|
||||||
* the ratio drops below 1.0.
|
* the ratio drops below 1.0.
|
||||||
@@ -887,7 +884,7 @@ define best_sq2()
|
|||||||
high *= expand;
|
high *= expand;
|
||||||
if (config("user_debug") > 1) {
|
if (config("user_debug") > 1) {
|
||||||
printf(" expand the next test range by a factor of %d\n",
|
printf(" expand the next test range by a factor of %d\n",
|
||||||
expand);
|
expand);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -904,7 +901,7 @@ define best_sq2()
|
|||||||
best_val = high;
|
best_val = high;
|
||||||
best_ratio = ratio;
|
best_ratio = ratio;
|
||||||
if (config("user_debug") > 1) {
|
if (config("user_debug") > 1) {
|
||||||
printf(" len %d has a new cloest ratio to unity: %.6f\n",
|
printf(" len %d has a new closest ratio to unity: %.6f\n",
|
||||||
best_val, best_ratio);
|
best_val, best_ratio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -927,7 +924,7 @@ define best_sq2()
|
|||||||
high /= 2;
|
high /= 2;
|
||||||
low = high / 2;
|
low = high / 2;
|
||||||
if (config("user_debug") > 0) {
|
if (config("user_debug") > 0) {
|
||||||
printf("retesting multiply alg1/alg2 ratio for len = %d\n",
|
printf("re-testing multiply alg1/alg2 ratio for len = %d\n",
|
||||||
high);
|
high);
|
||||||
}
|
}
|
||||||
ratio = mul_ratio(high);
|
ratio = mul_ratio(high);
|
||||||
@@ -935,7 +932,8 @@ define best_sq2()
|
|||||||
best_val = high;
|
best_val = high;
|
||||||
best_ratio = ratio;
|
best_ratio = ratio;
|
||||||
if (config("user_debug") > 1) {
|
if (config("user_debug") > 1) {
|
||||||
printf(" len %d has a new cloest ratio to unity: %.6f\n",
|
printf(" len %d has a new closest ratio "
|
||||||
|
"to unity: %.6f\n",
|
||||||
best_val, best_ratio);
|
best_val, best_ratio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -958,7 +956,7 @@ define best_sq2()
|
|||||||
*/
|
*/
|
||||||
while (low+1 < high) {
|
while (low+1 < high) {
|
||||||
|
|
||||||
/* try the mid-point */
|
/* try the mid-point */
|
||||||
mid = int((low+high)/2);
|
mid = int((low+high)/2);
|
||||||
if (config("user_debug") > 0) {
|
if (config("user_debug") > 0) {
|
||||||
printf("testing square alg1/alg2 ratio for len = %d\n", mid);
|
printf("testing square alg1/alg2 ratio for len = %d\n", mid);
|
||||||
@@ -968,7 +966,7 @@ define best_sq2()
|
|||||||
best_val = mid;
|
best_val = mid;
|
||||||
best_ratio = ratio;
|
best_ratio = ratio;
|
||||||
if (config("user_debug") > 1) {
|
if (config("user_debug") > 1) {
|
||||||
printf(" len %d has a new cloest ratio to unity: %.6f\n",
|
printf(" len %d has a new closest ratio to unity: %.6f\n",
|
||||||
best_val, best_ratio);
|
best_val, best_ratio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -981,7 +979,7 @@ define best_sq2()
|
|||||||
low = mid;
|
low = mid;
|
||||||
high = mid;
|
high = mid;
|
||||||
if (config("user_debug") > 0) {
|
if (config("user_debug") > 0) {
|
||||||
printf("\twe are close enough to unity ratio at: %d\n", mid);
|
printf("\twe are close enough to unity ratio at: %d\n", mid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -989,7 +987,7 @@ define best_sq2()
|
|||||||
/* bump lower range up if we went over */
|
/* bump lower range up if we went over */
|
||||||
if (ratio > 1.0) {
|
if (ratio > 1.0) {
|
||||||
if (config("user_debug") > 2) {
|
if (config("user_debug") > 2) {
|
||||||
printf("\tmove low from %d up to %d\n",
|
printf("\tmove low from %d up to %d\n",
|
||||||
low, mid);
|
low, mid);
|
||||||
}
|
}
|
||||||
low = mid;
|
low = mid;
|
||||||
@@ -997,7 +995,7 @@ define best_sq2()
|
|||||||
/* drop higher range down if we went under */
|
/* drop higher range down if we went under */
|
||||||
} else {
|
} else {
|
||||||
if (config("user_debug") > 2) {
|
if (config("user_debug") > 2) {
|
||||||
printf("\tmove high from %d down to %d\n",
|
printf("\tmove high from %d down to %d\n",
|
||||||
high, mid);
|
high, mid);
|
||||||
}
|
}
|
||||||
high = mid;
|
high = mid;
|
||||||
@@ -1006,7 +1004,7 @@ define best_sq2()
|
|||||||
/* report on test loop progress */
|
/* report on test loop progress */
|
||||||
if (config("user_debug") > 1) {
|
if (config("user_debug") > 1) {
|
||||||
printf("\tsetting low: %d high: %d diff: %d\n",
|
printf("\tsetting low: %d high: %d diff: %d\n",
|
||||||
low, high, high-low);
|
low, high, high-low);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1021,7 +1019,7 @@ define best_sq2()
|
|||||||
printf("config(\"sq2\", %d),;\n", best_val);
|
printf("config(\"sq2\", %d),;\n", best_val);
|
||||||
printf("WARNING: It is believed that the output "
|
printf("WARNING: It is believed that the output "
|
||||||
"of this resource file is bogus!\n");
|
"of this resource file is bogus!\n");
|
||||||
printf("WARNING: You may NOT wish to follow the above suggeston.\n");
|
printf("WARNING: You may NOT wish to follow the above suggestion.\n");
|
||||||
}
|
}
|
||||||
return mid;
|
return mid;
|
||||||
}
|
}
|
||||||
@@ -1341,7 +1339,7 @@ define best_pow2()
|
|||||||
local high; /* high loop value tested */
|
local high; /* high loop value tested */
|
||||||
local mid; /* between low and high */
|
local mid; /* between low and high */
|
||||||
local best_val; /* value found with ratio closest to unity */
|
local best_val; /* value found with ratio closest to unity */
|
||||||
local best_ratio; /* cloest ratio found to unity */
|
local best_ratio; /* closest ratio found to unity */
|
||||||
local expand; /* how fast to expand the length */
|
local expand; /* how fast to expand the length */
|
||||||
local looped; /* 1 ==> we have expanded lengths before */
|
local looped; /* 1 ==> we have expanded lengths before */
|
||||||
|
|
||||||
@@ -1351,7 +1349,7 @@ define best_pow2()
|
|||||||
printf("WARNING: This tool may not be computing the correct best value\n");
|
printf("WARNING: This tool may not be computing the correct best value\n");
|
||||||
test_time = 60.0;
|
test_time = 60.0;
|
||||||
printf("The best_pow2() function will take a LONG time to run!\n");
|
printf("The best_pow2() function will take a LONG time to run!\n");
|
||||||
printf("It is important that best_pow2() run on an othwewise idle host!\n");
|
printf("It is important that best_pow2() run on an otherwise idle host!\n");
|
||||||
if (config("user_debug") <= 0) {
|
if (config("user_debug") <= 0) {
|
||||||
printf("To monitor progress, set user_debug to 2: "
|
printf("To monitor progress, set user_debug to 2: "
|
||||||
"config(\"user_debug\", 2)\n");
|
"config(\"user_debug\", 2)\n");
|
||||||
@@ -1362,7 +1360,7 @@ define best_pow2()
|
|||||||
* firewall - must have a >1.02 ratio for the initial length
|
* firewall - must have a >1.02 ratio for the initial length
|
||||||
*
|
*
|
||||||
* We select 1.02 because of the precision of the CPU timing. We
|
* We select 1.02 because of the precision of the CPU timing. We
|
||||||
* want to firt move into an area where the 1st algoritm clearly
|
* want to first move into an area where the 1st algorithm clearly
|
||||||
* dominates.
|
* dominates.
|
||||||
*/
|
*/
|
||||||
low = 4;
|
low = 4;
|
||||||
@@ -1379,7 +1377,7 @@ define best_pow2()
|
|||||||
best_val = high;
|
best_val = high;
|
||||||
best_ratio = ratio;
|
best_ratio = ratio;
|
||||||
if (config("user_debug") > 1) {
|
if (config("user_debug") > 1) {
|
||||||
printf(" len %d has a new cloest ratio to unity: %.6f\n",
|
printf(" len %d has a new closest ratio to unity: %.6f\n",
|
||||||
best_val, best_ratio);
|
best_val, best_ratio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1387,7 +1385,7 @@ define best_pow2()
|
|||||||
printf(" pmod alg1/alg2 ratio = %.3f\n", ratio);
|
printf(" pmod alg1/alg2 ratio = %.3f\n", ratio);
|
||||||
if (ratio > 1.0 && ratio <= 1.02) {
|
if (ratio > 1.0 && ratio <= 1.02) {
|
||||||
printf(" while alg1 is slightly better than alg2, "
|
printf(" while alg1 is slightly better than alg2, "
|
||||||
"it is not clearly better\n");
|
"it is not clearly better\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (ratio <= 1.02);
|
} while (ratio <= 1.02);
|
||||||
@@ -1401,7 +1399,7 @@ define best_pow2()
|
|||||||
looped = 0;
|
looped = 0;
|
||||||
do {
|
do {
|
||||||
/*
|
/*
|
||||||
* determine the paramters of the next ratio test
|
* determine the parameters of the next ratio test
|
||||||
*
|
*
|
||||||
* We will multiplicatively expand our test level until
|
* We will multiplicatively expand our test level until
|
||||||
* the ratio drops below 1.0.
|
* the ratio drops below 1.0.
|
||||||
@@ -1422,7 +1420,7 @@ define best_pow2()
|
|||||||
high *= expand;
|
high *= expand;
|
||||||
if (config("user_debug") > 1) {
|
if (config("user_debug") > 1) {
|
||||||
printf(" expand the next test range by a factor of %d\n",
|
printf(" expand the next test range by a factor of %d\n",
|
||||||
expand);
|
expand);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1439,7 +1437,7 @@ define best_pow2()
|
|||||||
best_val = high;
|
best_val = high;
|
||||||
best_ratio = ratio;
|
best_ratio = ratio;
|
||||||
if (config("user_debug") > 1) {
|
if (config("user_debug") > 1) {
|
||||||
printf(" len %d has a new cloest ratio to unity: %.6f\n",
|
printf(" len %d has a new closest ratio to unity: %.6f\n",
|
||||||
best_val, best_ratio);
|
best_val, best_ratio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1457,7 +1455,7 @@ define best_pow2()
|
|||||||
*/
|
*/
|
||||||
while (low+1 < high) {
|
while (low+1 < high) {
|
||||||
|
|
||||||
/* try the mid-point */
|
/* try the mid-point */
|
||||||
mid = int((low+high)/2);
|
mid = int((low+high)/2);
|
||||||
if (config("user_debug") > 0) {
|
if (config("user_debug") > 0) {
|
||||||
printf("testing pow2 alg1/alg2 ratio for len = %d\n", mid);
|
printf("testing pow2 alg1/alg2 ratio for len = %d\n", mid);
|
||||||
@@ -1467,7 +1465,7 @@ define best_pow2()
|
|||||||
best_val = mid;
|
best_val = mid;
|
||||||
best_ratio = ratio;
|
best_ratio = ratio;
|
||||||
if (config("user_debug") > 1) {
|
if (config("user_debug") > 1) {
|
||||||
printf(" len %d has a new cloest ratio to unity: %.6f\n",
|
printf(" len %d has a new closest ratio to unity: %.6f\n",
|
||||||
best_val, best_ratio);
|
best_val, best_ratio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1480,7 +1478,7 @@ define best_pow2()
|
|||||||
low = mid;
|
low = mid;
|
||||||
high = mid;
|
high = mid;
|
||||||
if (config("user_debug") > 0) {
|
if (config("user_debug") > 0) {
|
||||||
printf("\twe are close enough to unity ratio at: %d\n", mid);
|
printf("\twe are close enough to unity ratio at: %d\n", mid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1488,7 +1486,7 @@ define best_pow2()
|
|||||||
/* bump lower range up if we went over */
|
/* bump lower range up if we went over */
|
||||||
if (ratio > 1.0) {
|
if (ratio > 1.0) {
|
||||||
if (config("user_debug") > 2) {
|
if (config("user_debug") > 2) {
|
||||||
printf("\tmove low from %d up to %d\n",
|
printf("\tmove low from %d up to %d\n",
|
||||||
low, mid);
|
low, mid);
|
||||||
}
|
}
|
||||||
low = mid;
|
low = mid;
|
||||||
@@ -1496,7 +1494,7 @@ define best_pow2()
|
|||||||
/* drop higher range down if we went under */
|
/* drop higher range down if we went under */
|
||||||
} else {
|
} else {
|
||||||
if (config("user_debug") > 2) {
|
if (config("user_debug") > 2) {
|
||||||
printf("\tmove high from %d down to %d\n",
|
printf("\tmove high from %d down to %d\n",
|
||||||
high, mid);
|
high, mid);
|
||||||
}
|
}
|
||||||
high = mid;
|
high = mid;
|
||||||
@@ -1505,7 +1503,7 @@ define best_pow2()
|
|||||||
/* report on test loop progress */
|
/* report on test loop progress */
|
||||||
if (config("user_debug") > 1) {
|
if (config("user_debug") > 1) {
|
||||||
printf("\tsetting low: %d high: %d diff: %d\n",
|
printf("\tsetting low: %d high: %d diff: %d\n",
|
||||||
low, high, high-low);
|
low, high, high-low);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1520,7 +1518,7 @@ define best_pow2()
|
|||||||
printf("config(\"pow2\", %d),;\n", best_val);
|
printf("config(\"pow2\", %d),;\n", best_val);
|
||||||
printf("WARNING: It is believed that the output "
|
printf("WARNING: It is believed that the output "
|
||||||
"of this resource file is bogus!\n");
|
"of this resource file is bogus!\n");
|
||||||
printf("WARNING: You may NOT wish to follow the above suggeston.\n");
|
printf("WARNING: You may NOT wish to follow the above suggestion.\n");
|
||||||
}
|
}
|
||||||
return mid;
|
return mid;
|
||||||
}
|
}
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: beer.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/beer.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1996/11/13 13:21:05
|
* Under source code control: 1996/11/13 13:21:05
|
||||||
* File existed as early as: 1996
|
* File existed as early as: 1996
|
||||||
*
|
*
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* bernoulli - clculate the Nth Bernoulli number B(n)
|
* bernoulli - calculate the Nth Bernoulli number B(n)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000 David I. Bell and Landon Curt Noll
|
* Copyright (C) 2000,2021 David I. Bell and Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: bernoulli.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/bernoulli.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1991/09/30 11:18:41
|
* Under source code control: 1991/09/30 11:18:41
|
||||||
* File existed as early as: 1991
|
* File existed as early as: 1991
|
||||||
*
|
*
|
||||||
@@ -30,9 +26,9 @@
|
|||||||
/*
|
/*
|
||||||
* Calculate the Nth Bernoulli number B(n).
|
* Calculate the Nth Bernoulli number B(n).
|
||||||
*
|
*
|
||||||
* NOTE: This is now a bulitin function.
|
* NOTE: This is now a builtin function.
|
||||||
*
|
*
|
||||||
* The non-buildin code used the following symbolic formula to calculate B(n):
|
* The non-builtin code used the following symbolic formula to calculate B(n):
|
||||||
*
|
*
|
||||||
* (b+1)^(n+1) - b^(n+1) = 0
|
* (b+1)^(n+1) - b^(n+1) = 0
|
||||||
*
|
*
|
||||||
@@ -46,7 +42,7 @@
|
|||||||
* B(3) = -(6*B(2) + 4*B(1) + 1) / 4
|
* B(3) = -(6*B(2) + 4*B(1) + 1) / 4
|
||||||
*
|
*
|
||||||
* The combinatorial factors in the expansion of the above formula are
|
* The combinatorial factors in the expansion of the above formula are
|
||||||
* calculated interatively, and we use the fact that B(2i+1) = 0 if i > 0.
|
* calculated interactively, and we use the fact that B(2i+1) = 0 if i > 0.
|
||||||
* Since all previous B(n)'s are needed to calculate a particular B(n), all
|
* Since all previous B(n)'s are needed to calculate a particular B(n), all
|
||||||
* values obtained are saved in an array for ease in repeated calculations.
|
* values obtained are saved in an array for ease in repeated calculations.
|
||||||
*/
|
*/
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* bernpoly - Bernoully polynomials B_n(z) for arbitrary n,z..
|
* bernpoly - Bernoulli polynomials B_n(z) for arbitrary n,z..
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Christoph Zurnieden
|
* Copyright (C) 2013,2021 Christoph Zurnieden
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.4 $
|
|
||||||
* @(#) $Id: bernpoly.cal,v 30.4 2013/08/18 20:01:53 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/bernpoly.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2013/08/11 01:31:28
|
* Under source code control: 2013/08/11 01:31:28
|
||||||
* File existed as early as: 2013
|
* File existed as early as: 2013
|
||||||
*/
|
*/
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: bigprime.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/bigprime.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1991/05/22 21:56:32
|
* Under source code control: 1991/05/22 21:56:32
|
||||||
* File existed as early as: 1991
|
* File existed as early as: 1991
|
||||||
*
|
*
|
||||||
|
@@ -16,10 +16,6 @@
|
|||||||
# received a copy with calc; if not, write to Free Software Foundation, Inc.
|
# received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
# @(#) $Revision: 30.1 $
|
|
||||||
# @(#) $Id: bindings,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
# @(#) $Source: /usr/local/src/bin/calc/cal/RCS/bindings,v $
|
|
||||||
#
|
|
||||||
# Under source code control: 1993/05/02 20:09:19
|
# Under source code control: 1993/05/02 20:09:19
|
||||||
# File existed as early as: 1993
|
# File existed as early as: 1993
|
||||||
#
|
#
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* brentsolve - Root finding with the Brent-Dekker trick
|
* brentsolve - Root finding with the Brent-Dekker trick
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Christoph Zurnieden
|
* Copyright (C) 2013,2021 Christoph Zurnieden
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.4 $
|
|
||||||
* @(#) $Id: brentsolve.cal,v 30.4 2013/08/18 20:01:53 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/brentsolve.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2013/08/11 01:31:28
|
* Under source code control: 2013/08/11 01:31:28
|
||||||
* File existed as early as: 2013
|
* File existed as early as: 2013
|
||||||
*/
|
*/
|
||||||
@@ -147,7 +143,7 @@ define brentsolve2(low, high,which,eps){
|
|||||||
|
|
||||||
switch(param(0)){
|
switch(param(0)){
|
||||||
case 0:
|
case 0:
|
||||||
case 1: return newerror("brentsolve2: not enough argments");
|
case 1: return newerror("brentsolve2: not enough arguments");
|
||||||
case 2: eps = epsilon(epsilon()*1e-2);
|
case 2: eps = epsilon(epsilon()*1e-2);
|
||||||
which = 0;break;
|
which = 0;break;
|
||||||
case 3: eps = epsilon(epsilon()*1e-2);break;
|
case 3: eps = epsilon(epsilon()*1e-2);break;
|
||||||
|
18
cal/chi.cal
18
cal/chi.cal
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* chi - chi^2 probabilities with degrees of freedom for null hypothesis
|
* chi - chi^2 probabilities with degrees of freedom for null hypothesis
|
||||||
*
|
*
|
||||||
* Copyright (C) 2001 Landon Curt Noll
|
* Copyright (C) 2001,2021 Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: chi.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/chi.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2001/03/27 14:10:11
|
* Under source code control: 2001/03/27 14:10:11
|
||||||
* File existed as early as: 2001
|
* File existed as early as: 2001
|
||||||
*
|
*
|
||||||
@@ -44,7 +40,7 @@ define Z(x, eps_term)
|
|||||||
|
|
||||||
/* obtain the error term */
|
/* obtain the error term */
|
||||||
if (isnull(eps_term)) {
|
if (isnull(eps_term)) {
|
||||||
eps = epsilon();
|
eps = epsilon();
|
||||||
} else {
|
} else {
|
||||||
eps = eps_term;
|
eps = eps_term;
|
||||||
}
|
}
|
||||||
@@ -55,7 +51,7 @@ define Z(x, eps_term)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* P(x[, eps]) asymtotic P(x) expansion for x>0 to an given epsilon error term
|
* P(x[, eps]) asymptotic P(x) expansion for x>0 to an given epsilon error term
|
||||||
*
|
*
|
||||||
* NOTE: If eps is omitted, the stored epsilon value is used.
|
* NOTE: If eps is omitted, the stored epsilon value is used.
|
||||||
*
|
*
|
||||||
@@ -85,7 +81,7 @@ define P(x, eps_term)
|
|||||||
|
|
||||||
/* obtain the error term */
|
/* obtain the error term */
|
||||||
if (isnull(eps_term)) {
|
if (isnull(eps_term)) {
|
||||||
eps = epsilon();
|
eps = epsilon();
|
||||||
} else {
|
} else {
|
||||||
eps = eps_term;
|
eps = eps_term;
|
||||||
}
|
}
|
||||||
@@ -103,7 +99,7 @@ define P(x, eps_term)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* aproximate sum(n=0; n < infinity){x^(2*n+1)/(1*3*5*...(2*n+1)}
|
* approximate sum(n=0; n < infinity){x^(2*n+1)/(1*3*5*...(2*n+1)}
|
||||||
*/
|
*/
|
||||||
x2 = x*x;
|
x2 = x*x;
|
||||||
x_term = x;
|
x_term = x;
|
||||||
@@ -134,7 +130,7 @@ define P(x, eps_term)
|
|||||||
*
|
*
|
||||||
* The chi_prob() function does not work well with odd degrees of freedom.
|
* The chi_prob() function does not work well with odd degrees of freedom.
|
||||||
* It is reasonable with even degrees of freedom, although one must give
|
* It is reasonable with even degrees of freedom, although one must give
|
||||||
* a sifficently small error term as the degress gets large (>100).
|
* a sufficiently small error term as the degrees gets large (>100).
|
||||||
*
|
*
|
||||||
* NOTE: This function does not work well with odd degrees of freedom.
|
* NOTE: This function does not work well with odd degrees of freedom.
|
||||||
* Can somebody help / find a bug / provide a better method of
|
* Can somebody help / find a bug / provide a better method of
|
||||||
@@ -190,7 +186,7 @@ define chi_prob(chi_sq, v, eps_term)
|
|||||||
local r; /* index in finite sum */
|
local r; /* index in finite sum */
|
||||||
local r_lim; /* limit value for r */
|
local r_lim; /* limit value for r */
|
||||||
local s; /* sum */
|
local s; /* sum */
|
||||||
local d; /* demoninator (2*4*6*... or 1*3*5...) */
|
local d; /* denominator (2*4*6*... or 1*3*5...) */
|
||||||
local chi_term; /* chi_sq^r */
|
local chi_term; /* chi_sq^r */
|
||||||
local ret; /* return value */
|
local ret; /* return value */
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* chrem - chinese remainder theorem/problem solver
|
* chrem - Chinese remainder theorem/problem solver
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
|
* Copyright (C) 1999,2021 Ernest Bowen and Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Primary author: Ernest Bowen
|
* Primary author: Ernest Bowen
|
||||||
*
|
*
|
||||||
@@ -19,10 +19,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: chrem.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/chrem.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1992/09/26 01:00:47
|
* Under source code control: 1992/09/26 01:00:47
|
||||||
* File existed as early as: 1992
|
* File existed as early as: 1992
|
||||||
*
|
*
|
||||||
@@ -30,7 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When possible, chrem finds solutions for x of a set of congruences
|
* When possible, chrem finds solutions for x of a set of congruence
|
||||||
* of the form:
|
* of the form:
|
||||||
*
|
*
|
||||||
* x = r1 (mod m1)
|
* x = r1 (mod m1)
|
||||||
@@ -39,7 +35,7 @@
|
|||||||
*
|
*
|
||||||
* where the residues r1, r2, ... and the moduli m1, m2, ... are
|
* where the residues r1, r2, ... and the moduli m1, m2, ... are
|
||||||
* given integers. The Chinese remainder theorem states that if
|
* given integers. The Chinese remainder theorem states that if
|
||||||
* m1, m2, ... are relatively prime in pairs, the above congruences
|
* m1, m2, ... are relatively prime in pairs, the above congruence
|
||||||
* have a unique solution modulo m1 * m2 * ... If m1, m2, ...
|
* have a unique solution modulo m1 * m2 * ... If m1, m2, ...
|
||||||
* are not relatively prime in pairs, it is possible that no solution
|
* are not relatively prime in pairs, it is possible that no solution
|
||||||
* exists. If solutions exist, the general solution is expressible as:
|
* exists. If solutions exist, the general solution is expressible as:
|
||||||
|
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;
|
||||||
|
}
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.4 $
|
|
||||||
* @(#) $Id: constants.cal,v 30.4 2013/08/18 20:01:53 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/constants.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2013/08/11 01:31:28
|
* Under source code control: 2013/08/11 01:31:28
|
||||||
* File existed as early as: 2013
|
* File existed as early as: 2013
|
||||||
*/
|
*/
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.2 $
|
|
||||||
* @(#) $Id: deg.cal,v 30.2 2010/09/02 06:01:14 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/deg.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1990/02/15 01:50:33
|
* Under source code control: 1990/02/15 01:50:33
|
||||||
* File existed as early as: before 1990
|
* File existed as early as: before 1990
|
||||||
*
|
*
|
||||||
|
32
cal/dms.cal
32
cal/dms.cal
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* dms - calculate in degrees, minutes, and seconds (based on deg)
|
* dms - calculate in degrees, minutes, and seconds (based on deg)
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999,2010 David I. Bell and Landon Curt Noll
|
* Copyright (C) 1999,2010,2021 David I. Bell and Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.2 $
|
|
||||||
* @(#) $Id: dms.cal,v 30.2 2010/09/02 06:14:16 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/dms.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1990/02/15 01:50:33
|
* Under source code control: 1990/02/15 01:50:33
|
||||||
* File existed as early as: before 1990
|
* File existed as early as: before 1990
|
||||||
*
|
*
|
||||||
@@ -57,7 +53,7 @@ define dms_add(a, b)
|
|||||||
{
|
{
|
||||||
local obj dms ans; /* return value */
|
local obj dms ans; /* return value */
|
||||||
|
|
||||||
/* initalize value to 1st arg */
|
/* initialize value to 1st arg */
|
||||||
if (istype(a, ans)) {
|
if (istype(a, ans)) {
|
||||||
/* 1st arg is dms object, load it */
|
/* 1st arg is dms object, load it */
|
||||||
ans.deg = a.deg;
|
ans.deg = a.deg;
|
||||||
@@ -114,7 +110,7 @@ define dms_sub(a, b)
|
|||||||
{
|
{
|
||||||
local obj dms ans; /* return value */
|
local obj dms ans; /* return value */
|
||||||
|
|
||||||
/* initalize value to 1st arg */
|
/* initialize value to 1st arg */
|
||||||
if (istype(a, ans)) {
|
if (istype(a, ans)) {
|
||||||
/* 1st arg is dms object, load it */
|
/* 1st arg is dms object, load it */
|
||||||
ans.deg = a.deg;
|
ans.deg = a.deg;
|
||||||
@@ -192,7 +188,7 @@ define dms_abs(a)
|
|||||||
|
|
||||||
/* firewall - just absolute value non dms objects */
|
/* firewall - just absolute value non dms objects */
|
||||||
if (! istype(a, ans)) {
|
if (! istype(a, ans)) {
|
||||||
return abs(a);
|
return abs(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compute degrees */
|
/* compute degrees */
|
||||||
@@ -356,24 +352,8 @@ define fixdms(a)
|
|||||||
quit "attempt to fix a non dms object";
|
quit "attempt to fix a non dms object";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* force minutes to be intergral */
|
/* use builtin d2dms function */
|
||||||
a.min += frac(a.deg) * 60;
|
d2dms(a.deg + a.min/60 + a.sec/3600, a.deg, a.min, a.sec),;
|
||||||
a.deg = int(a.deg);
|
|
||||||
|
|
||||||
/* force degrees to be intergral */
|
|
||||||
a.sec += frac(a.min) * 60;
|
|
||||||
a.min = int(a.min);
|
|
||||||
|
|
||||||
/* carry excess seconds into minutes */
|
|
||||||
a.min += a.sec // 60;
|
|
||||||
a.sec %= 60;
|
|
||||||
|
|
||||||
/* carry excess minutes into degrees */
|
|
||||||
a.deg += a.min // 60;
|
|
||||||
a.min %= 60;
|
|
||||||
|
|
||||||
/* round degrees :-) */
|
|
||||||
a.deg %= 360;
|
|
||||||
|
|
||||||
/* return normalized result */
|
/* return normalized result */
|
||||||
return a;
|
return a;
|
||||||
|
@@ -4,23 +4,37 @@
|
|||||||
* This file was created by Ernest Bowen <ebowen at une dot edu dot au>
|
* This file was created by Ernest Bowen <ebowen at une dot edu dot au>
|
||||||
* and modified by Landon Curt Noll.
|
* 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.
|
|
||||||
*
|
|
||||||
* @(#) $Revision: 30.2 $
|
|
||||||
* @(#) $Id: dotest.cal,v 30.2 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/dotest.cal,v $
|
|
||||||
*
|
|
||||||
* This file is not covered under version 2.1 of the GNU LGPL.
|
* 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
|
* Under source dotest_code control: 2006/03/08 05:54:09
|
||||||
* File existed as early as: 2006
|
* File existed as early as: 2006
|
||||||
@@ -161,7 +175,7 @@ define dotest(dotest_file, dotest_code = 0, dotest_maxcond = -1)
|
|||||||
* test the close of the line file
|
* test the close of the line file
|
||||||
*/
|
*/
|
||||||
printf("%d-: detected %d error condition(s), many of which may be OK\n",
|
printf("%d-: detected %d error condition(s), many of which may be OK\n",
|
||||||
dotest_code, dotest_old_errcount-dotest_errcnt);
|
dotest_code, dotest_old_errcount-dotest_errcnt);
|
||||||
printf("%d-: closing line file: %d\n", dotest_code, dotest_file);
|
printf("%d-: closing line file: %d\n", dotest_code, dotest_file);
|
||||||
fclose(dotest_f_file);
|
fclose(dotest_f_file);
|
||||||
|
|
||||||
@@ -177,7 +191,7 @@ define dotest(dotest_file, dotest_code = 0, dotest_maxcond = -1)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* preppare to return to the caller environment
|
* prepare to return to the caller environment
|
||||||
*
|
*
|
||||||
* We increase the caller's error count by the number
|
* We increase the caller's error count by the number
|
||||||
* of line tests that failed, not the number of internal
|
* of line tests that failed, not the number of internal
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: ellip.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/ellip.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1990/02/15 01:50:33
|
* Under source code control: 1990/02/15 01:50:33
|
||||||
* File existed as early as: before 1990
|
* File existed as early as: before 1990
|
||||||
*
|
*
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.4 $
|
|
||||||
* @(#) $Id: factorial.cal,v 30.4 2013/08/18 20:01:53 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/factorial.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2013/08/11 01:31:28
|
* Under source code control: 2013/08/11 01:31:28
|
||||||
* File existed as early as: 2013
|
* File existed as early as: 2013
|
||||||
*/
|
*/
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* factorial2 - implementation of different factorial related functions
|
* factorial2 - implementation of different factorial related functions
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Christoph Zurnieden
|
* Copyright (C) 2013,2021 Christoph Zurnieden
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.4 $
|
|
||||||
* @(#) $Id: factorial2.cal,v 30.4 2013/08/18 20:01:53 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/factorial2.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2013/08/11 01:31:28
|
* Under source code control: 2013/08/11 01:31:28
|
||||||
* File existed as early as: 2013
|
* File existed as early as: 2013
|
||||||
*/
|
*/
|
||||||
@@ -60,7 +56,7 @@ define __CZ__factor_factorial(n,start){
|
|||||||
if(start){
|
if(start){
|
||||||
if(!isint(start) && start < 0 && start > n)
|
if(!isint(start) && start < 0 && start > n)
|
||||||
return newerror("__CZ__factor_factorial(n,start): value of "
|
return newerror("__CZ__factor_factorial(n,start): value of "
|
||||||
"parameter 'start' out of range");
|
"parameter 'start' out of range");
|
||||||
if(start == n && isprime(n)){
|
if(start == n && isprime(n)){
|
||||||
prime_list = mat[1 , 2];
|
prime_list = mat[1 , 2];
|
||||||
prime_list[0,0] = n;
|
prime_list[0,0] = n;
|
||||||
@@ -68,7 +64,7 @@ define __CZ__factor_factorial(n,start){
|
|||||||
}
|
}
|
||||||
else if(!isprime(start) && nextprime(start) >n)
|
else if(!isprime(start) && nextprime(start) >n)
|
||||||
return newerror("__CZ__factor_factorial(n,start): value of parameter "
|
return newerror("__CZ__factor_factorial(n,start): value of parameter "
|
||||||
"'start' out of range");
|
"'start' out of range");
|
||||||
else{
|
else{
|
||||||
if(!isprime(start)) prime = nextprime(start);
|
if(!isprime(start)) prime = nextprime(start);
|
||||||
else prime = start;
|
else prime = start;
|
||||||
@@ -229,11 +225,11 @@ define __CZ__multiply_factored_factorial(matrix,stop){
|
|||||||
|
|
||||||
if(!ismat(matrix))
|
if(!ismat(matrix))
|
||||||
return newerror("__CZ__multiply_factored_factorial(matrix): "
|
return newerror("__CZ__multiply_factored_factorial(matrix): "
|
||||||
"argument matrix not a matrix ");
|
"argument matrix not a matrix ");
|
||||||
if(!matrix[0,0])
|
if(!matrix[0,0])
|
||||||
return
|
return
|
||||||
newerror("__CZ__multiply_factored_factorial(matrix): "
|
newerror("__CZ__multiply_factored_factorial(matrix): "
|
||||||
"matrix[0,0] is null/0");
|
"matrix[0,0] is null/0");
|
||||||
|
|
||||||
if(!isnull(stop))
|
if(!isnull(stop))
|
||||||
pix = stop;
|
pix = stop;
|
||||||
@@ -285,10 +281,10 @@ define __CZ__multiply_factored_factorial(matrix,stop){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Compute binomial coeficients n!/(k!(n-k)!)
|
Compute binomial coefficients n!/(k!(n-k)!)
|
||||||
|
|
||||||
One of the rare cases where a formula once meant to ease manual computation
|
One of the rare cases where a formula once meant to ease manual computation
|
||||||
is actually the (aymptotically) fastest way to do it (in July 2013) for
|
is actually the (asymptotically) fastest way to do it (in July 2013) for
|
||||||
the extreme case binomial(2N,N) but for a high price, the memory
|
the extreme case binomial(2N,N) but for a high price, the memory
|
||||||
needed is pi(N)--theoretically.
|
needed is pi(N)--theoretically.
|
||||||
*/
|
*/
|
||||||
@@ -380,7 +376,7 @@ define bigcatalan(n){
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
df(-111) = -1/3472059605858239446587523014902616804783337112829102414124928
|
df(-111) = -1/3472059605858239446587523014902616804783337112829102414124928
|
||||||
7753332469144201839599609375
|
7753332469144201839599609375
|
||||||
|
|
||||||
df(-3+1i) = 0.12532538977287649201-0.0502372106177184607i
|
df(-3+1i) = 0.12532538977287649201-0.0502372106177184607i
|
||||||
df(2n + 1) = (2*n)!/(n!*2^n)
|
df(2n + 1) = (2*n)!/(n!*2^n)
|
||||||
@@ -431,7 +427,7 @@ define doublefactorial(n){
|
|||||||
*/
|
*/
|
||||||
eps=epsilon(epsilon()*1e-2);
|
eps=epsilon(epsilon()*1e-2);
|
||||||
ret = 2^(n/2-1/4 * cos(pi()* n)+1/4) * pi()^(1/4 *
|
ret = 2^(n/2-1/4 * cos(pi()* n)+1/4) * pi()^(1/4 *
|
||||||
cos(pi()* n)-1/4)* gamma(n/2+1);
|
cos(pi()* n)-1/4)* gamma(n/2+1);
|
||||||
epsilon(eps);
|
epsilon(eps);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -630,7 +626,7 @@ define subfactorialrecursive(n){
|
|||||||
return n * subfactorialrecursive(n-1) + (-1)^n;
|
return n * subfactorialrecursive(n-1) + (-1)^n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is, quite amusingely, faster than the very same algorithm in
|
/* This is, quite amusingly, faster than the very same algorithm in
|
||||||
PARI/GP + GMP*/
|
PARI/GP + GMP*/
|
||||||
define subfactorialiterative(n){
|
define subfactorialiterative(n){
|
||||||
local k temp1 temp2 ret;
|
local k temp1 temp2 ret;
|
||||||
|
473
cal/fnv_tool.cal
Normal file
473
cal/fnv_tool.cal
Normal file
@@ -0,0 +1,473 @@
|
|||||||
|
/*
|
||||||
|
* 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 = powers of 2 >= 2048 and <= 1048576,
|
||||||
|
* there is NO FNV primes.
|
||||||
|
*
|
||||||
|
* 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 bit size powers of 2 > 1024 are extremely rare.";
|
||||||
|
print "# WARNING: There are no FNV primes for bit size powers of 2 >= 2048 and <= 1048576.";
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
@@ -8,10 +8,6 @@
|
|||||||
* operation "function" must be first; calc doesn't care how many more
|
* operation "function" must be first; calc doesn't care how many more
|
||||||
* arguments there actually are.
|
* arguments there actually are.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.3 $
|
|
||||||
* @(#) $Id: gvec.cal,v 30.3 2011/05/23 23:00:55 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/gvec.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2011/03/31 17:54:55
|
* Under source code control: 2011/03/31 17:54:55
|
||||||
* File existed as early as: 2010
|
* File existed as early as: 2010
|
||||||
*
|
*
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: hello.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/hello.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1996/11/13 13:25:43
|
* Under source code control: 1996/11/13 13:25:43
|
||||||
* File existed as early as: 1996
|
* File existed as early as: 1996
|
||||||
*
|
*
|
||||||
|
32
cal/hms.cal
32
cal/hms.cal
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* hms - calculate in hours, minutes, and seconds
|
* hms - calculate in hours, minutes, and seconds
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010 Landon Curt Noll
|
* Copyright (C) 2010,2021 Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.2 $
|
|
||||||
* @(#) $Id: hms.cal,v 30.2 2010/09/02 06:14:16 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/hms.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2010/09/01 17:14:55
|
* Under source code control: 2010/09/01 17:14:55
|
||||||
* File existed as early as: 2010
|
* File existed as early as: 2010
|
||||||
*
|
*
|
||||||
@@ -57,7 +53,7 @@ define hms_add(a, b)
|
|||||||
{
|
{
|
||||||
local obj hms ans; /* return value */
|
local obj hms ans; /* return value */
|
||||||
|
|
||||||
/* initalize value to 1st arg */
|
/* initialize value to 1st arg */
|
||||||
if (istype(a, ans)) {
|
if (istype(a, ans)) {
|
||||||
/* 1st arg is hms object, load it */
|
/* 1st arg is hms object, load it */
|
||||||
ans.hour = a.hour;
|
ans.hour = a.hour;
|
||||||
@@ -114,7 +110,7 @@ define hms_sub(a, b)
|
|||||||
{
|
{
|
||||||
local obj hms ans; /* return value */
|
local obj hms ans; /* return value */
|
||||||
|
|
||||||
/* initalize value to 1st arg */
|
/* initialize value to 1st arg */
|
||||||
if (istype(a, ans)) {
|
if (istype(a, ans)) {
|
||||||
/* 1st arg is hms object, load it */
|
/* 1st arg is hms object, load it */
|
||||||
ans.hour = a.hour;
|
ans.hour = a.hour;
|
||||||
@@ -192,7 +188,7 @@ define hms_abs(a)
|
|||||||
|
|
||||||
/* firewall - just absolute value non hms objects */
|
/* firewall - just absolute value non hms objects */
|
||||||
if (! istype(a, ans)) {
|
if (! istype(a, ans)) {
|
||||||
return abs(a);
|
return abs(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compute hours */
|
/* compute hours */
|
||||||
@@ -356,24 +352,8 @@ define fixhms(a)
|
|||||||
quit "attempt to fix a non hms object";
|
quit "attempt to fix a non hms object";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* force minutes to be intergral */
|
/* use builtin h2hms function */
|
||||||
a.min += frac(a.hour) * 60;
|
h2hms(a.hour + a.min/60 + a.sec/3600, a.hour, a.min, a.sec),;
|
||||||
a.hour = int(a.hour);
|
|
||||||
|
|
||||||
/* force hours to be intergral */
|
|
||||||
a.sec += frac(a.min) * 60;
|
|
||||||
a.min = int(a.min);
|
|
||||||
|
|
||||||
/* carry excess seconds into minutes */
|
|
||||||
a.min += a.sec // 60;
|
|
||||||
a.sec %= 60;
|
|
||||||
|
|
||||||
/* carry excess minutes into hours */
|
|
||||||
a.hour += a.min // 60;
|
|
||||||
a.min %= 60;
|
|
||||||
|
|
||||||
/* round hours by day */
|
|
||||||
a.hour %= 24;
|
|
||||||
|
|
||||||
/* return normalized result */
|
/* return normalized result */
|
||||||
return a;
|
return a;
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* intfile - integer to file and file to integer conversion
|
* intfile - integer to file and file to integer conversion
|
||||||
*
|
*
|
||||||
* Copyright (C) 2001 Landon Curt Noll
|
* Copyright (C) 2001,2021 Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: intfile.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/intfile.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2001/03/31 08:13:11
|
* Under source code control: 2001/03/31 08:13:11
|
||||||
* File existed as early as: 2001
|
* File existed as early as: 2001
|
||||||
*
|
*
|
||||||
@@ -31,20 +27,20 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE: Because leading HALF values are trimmed from integer, a file
|
* NOTE: Because leading HALF values are trimmed from integer, a file
|
||||||
* that begins with lots of 0 bits (in the case of big endian)
|
* that begins with lots of 0 bits (in the case of big Endian)
|
||||||
* or that ends with lots of 0 bits (in the case of little endian)
|
* or that ends with lots of 0 bits (in the case of little Endian)
|
||||||
* will be changed when the subsequent integer is written back.
|
* will be changed when the subsequent integer is written back.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* file2be - convert a file into an big endian integer
|
* file2be - convert a file into an big Endian integer
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* filename filename to read
|
* filename filename to read
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* integer read from its contents on big endian order
|
* integer read from its contents on big Endian order
|
||||||
*/
|
*/
|
||||||
define file2be(filename)
|
define file2be(filename)
|
||||||
{
|
{
|
||||||
@@ -79,13 +75,13 @@ define file2be(filename)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* file2le - convert a file into an little endian integer
|
* file2le - convert a file into an little Endian integer
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* filename filename to read
|
* filename filename to read
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* integer read from its contents on little endian order
|
* integer read from its contents on little Endian order
|
||||||
*/
|
*/
|
||||||
define file2le(filename)
|
define file2le(filename)
|
||||||
{
|
{
|
||||||
@@ -122,7 +118,7 @@ define file2le(filename)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* be2file - convert a big endian integer into a file
|
* be2file - convert a big Endian integer into a file
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* v integer to write to the file
|
* v integer to write to the file
|
||||||
@@ -160,7 +156,7 @@ define be2file(v, filename)
|
|||||||
*/
|
*/
|
||||||
octlen = int((highbit(v)+8) / 8);
|
octlen = int((highbit(v)+8) / 8);
|
||||||
for (i=octlen-1; i >= 0; --i) {
|
for (i=octlen-1; i >= 0; --i) {
|
||||||
fputc(fd, char(v >> (i*8)));
|
fputc(fd, char(v >> (i*8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -172,7 +168,7 @@ define be2file(v, filename)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* le2file - convert a little endian integer into a file
|
* le2file - convert a little Endian integer into a file
|
||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* v integer to write to the file
|
* v integer to write to the file
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* intnum - implementation of tanhsinh- and Gauss-Legendre quadrature
|
* intnum - implementation of tanhsinh- and Gauss-Legendre quadrature
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Christoph Zurnieden
|
* Copyright (C) 2013,2021 Christoph Zurnieden
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -295,7 +295,7 @@ define quadts(a, b, points)
|
|||||||
* as the number of equally spaced intervals on a straight line
|
* as the number of equally spaced intervals on a straight line
|
||||||
* connecting a and b. Computing the segments here is a bit
|
* connecting a and b. Computing the segments here is a bit
|
||||||
* more complicated but not much, it should have been taught in
|
* more complicated but not much, it should have been taught in
|
||||||
* highschool.
|
* high school.
|
||||||
* Other contours by way of a list of points */
|
* Other contours by way of a list of points */
|
||||||
slope = (im(b) - im(a)) / (re(b) - re(a));
|
slope = (im(b) - im(a)) / (re(b) - re(a));
|
||||||
C = (im(a) + slope) * re(a);
|
C = (im(a) + slope) * re(a);
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* lambertw - Lambert's W-function
|
* lambertw - Lambert's W-function
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Christoph Zurnieden
|
* Copyright (C) 2013,2021 Christoph Zurnieden
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.4 $
|
|
||||||
* @(#) $Id: lambertw.cal,v 30.4 2013/08/18 20:01:53 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/lambertw.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2013/08/11 01:31:28
|
* Under source code control: 2013/08/11 01:31:28
|
||||||
* File existed as early as: 2013
|
* File existed as early as: 2013
|
||||||
*/
|
*/
|
||||||
@@ -87,7 +83,7 @@ define __CZ__lambertw_m1(z,eps){
|
|||||||
or by using the function lambertw_series_print() after running
|
or by using the function lambertw_series_print() after running
|
||||||
lambertw_series(z,eps,branch,terms) at least once with the wanted number of
|
lambertw_series(z,eps,branch,terms) at least once with the wanted number of
|
||||||
terms and z = 1 (which might throw an error because the series will not
|
terms and z = 1 (which might throw an error because the series will not
|
||||||
converge in anybodies lifetime for something that far from the branchpoint).
|
converge in anybodies lifetime for something that far from the branch point).
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@@ -109,7 +105,7 @@ define lambertw_series_print(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The series is fast but only if _very_ close to the branchpoint
|
The series is fast but only if _very_ close to the branch point
|
||||||
The exact branch must be given explicitly, e.g.:
|
The exact branch must be given explicitly, e.g.:
|
||||||
|
|
||||||
; lambertw(-exp(-1)+.001)-lambertw_series(-exp(-1)+.001,epsilon()*1e-10,0)
|
; lambertw(-exp(-1)+.001)-lambertw_series(-exp(-1)+.001,epsilon()*1e-10,0)
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* linear - perform a simple two point 2D linear interpolation
|
* linear - perform a simple two point 2D linear interpolation
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005-2007 Landon Curt Noll
|
* Copyright (C) 2005-2007,2021 Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.2 $
|
|
||||||
* @(#) $Id: linear.cal,v 30.2 2007/03/17 05:57:42 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/linear.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2005/12/12 06:41:50
|
* Under source code control: 2005/12/12 06:41:50
|
||||||
* File existed as early as: 2005
|
* File existed as early as: 2005
|
||||||
*
|
*
|
||||||
@@ -33,7 +29,7 @@
|
|||||||
*
|
*
|
||||||
* given:
|
* given:
|
||||||
* x0, y0 first known point on the line
|
* x0, y0 first known point on the line
|
||||||
* x1, y1 second knonw point on the line
|
* x1, y1 second known point on the line
|
||||||
* x a given point to interpolate on
|
* x a given point to interpolate on
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.4 $
|
|
||||||
* @(#) $Id: lnseries.cal,v 30.4 2013/08/18 20:01:53 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/lnseries.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2013/08/11 01:31:28
|
* Under source code control: 2013/08/11 01:31:28
|
||||||
* File existed as early as: 2013
|
* File existed as early as: 2013
|
||||||
*/
|
*/
|
||||||
|
475
cal/lucas.cal
475
cal/lucas.cal
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* lucas - perform a Lucas primality test on h*2^n-1
|
* lucas - perform a Lucas primality test on h*2^n-1
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999,2017 Landon Curt Noll
|
* Copyright (C) 1999,2017,2018,2021 Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.4 $
|
|
||||||
* @(#) $Id: lucas.cal,v 30.4 2017/05/20 21:54:16 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc-RHEL7/cal/RCS/lucas.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1990/05/03 16:49:51
|
* Under source code control: 1990/05/03 16:49:51
|
||||||
* File existed as early as: 1990
|
* File existed as early as: 1990
|
||||||
*
|
*
|
||||||
@@ -32,6 +28,10 @@
|
|||||||
* For a general tutorial on how to find a new largest known prime, see:
|
* For a general tutorial on how to find a new largest known prime, see:
|
||||||
*
|
*
|
||||||
* http://www.isthe.com/chongo/tech/math/prime/prime-tutorial.pdf
|
* http://www.isthe.com/chongo/tech/math/prime/prime-tutorial.pdf
|
||||||
|
*
|
||||||
|
* Also see the reference code, available both C and go:
|
||||||
|
*
|
||||||
|
* https://github.com/arcetri/goprime
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -158,6 +158,12 @@
|
|||||||
*
|
*
|
||||||
* Finally, one should eliminate all values of 'h*2^n-1' where
|
* Finally, one should eliminate all values of 'h*2^n-1' where
|
||||||
* 'h*2^n+1' is divisible by a small primes.
|
* 'h*2^n+1' is divisible by a small primes.
|
||||||
|
*
|
||||||
|
* NOTE: Today, for world record sized h*2^n-1 primes, one might
|
||||||
|
* search for factors < 2^46 or more. By excluding h*2^n-1
|
||||||
|
* with prime factors < 2^46, where h*2^n-1 is a bit larger
|
||||||
|
* than the largest known prime, one may exclude about 96.5%
|
||||||
|
* of candidates that have "small" prime factors.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pprod256 = 0; /* product of "primes up to 256" / "primes up to 46" */
|
pprod256 = 0; /* product of "primes up to 256" / "primes up to 46" */
|
||||||
@@ -175,6 +181,11 @@ pprod256 = 0; /* product of "primes up to 256" / "primes up to 46" */
|
|||||||
* "Lucasian Criteria for the Primality of N=h*2^n-1", by Hans Riesel,
|
* "Lucasian Criteria for the Primality of N=h*2^n-1", by Hans Riesel,
|
||||||
* Mathematics of Computation, Vol 23 #108, pp. 869-875, Oct 1969
|
* Mathematics of Computation, Vol 23 #108, pp. 869-875, Oct 1969
|
||||||
*
|
*
|
||||||
|
* http://www.ams.org/journals/mcom/1969-23-108/S0025-5718-1969-0262163-1/
|
||||||
|
* S0025-5718-1969-0262163-1.pdf
|
||||||
|
*
|
||||||
|
* NOTE: Join the above two lines for the complete URL of the paper.
|
||||||
|
*
|
||||||
* The following book is also useful:
|
* The following book is also useful:
|
||||||
*
|
*
|
||||||
* Ref2:
|
* Ref2:
|
||||||
@@ -242,8 +253,8 @@ pprod256 = 0; /* product of "primes up to 256" / "primes up to 46" */
|
|||||||
* do make this so.
|
* do make this so.
|
||||||
*
|
*
|
||||||
* input:
|
* input:
|
||||||
* h the h as in h*2^n-1
|
* h h as in h*2^n-1 (must be >= 1)
|
||||||
* n the n as in h*2^n-1
|
* n n as in h*2^n-1 (must be >= 1)
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* 1 => h*2^n-1 is prime
|
* 1 => h*2^n-1 is prime
|
||||||
@@ -266,13 +277,17 @@ lucas(h, n)
|
|||||||
* check arg types
|
* check arg types
|
||||||
*/
|
*/
|
||||||
if (!isint(h)) {
|
if (!isint(h)) {
|
||||||
ldebug("lucas", "h is non-int");
|
|
||||||
quit "FATAL: bad args: h must be an integer";
|
quit "FATAL: bad args: h must be an integer";
|
||||||
}
|
}
|
||||||
|
if (h < 1) {
|
||||||
|
quit "FATAL: bad args: h must be an integer >= 1";
|
||||||
|
}
|
||||||
if (!isint(n)) {
|
if (!isint(n)) {
|
||||||
ldebug("lucas", "n is non-int");
|
|
||||||
quit "FATAL: bad args: n must be an integer";
|
quit "FATAL: bad args: n must be an integer";
|
||||||
}
|
}
|
||||||
|
if (n < 1) {
|
||||||
|
quit "FATAL: bad args: n must be an integer >= 1";
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* reduce h if even
|
* reduce h if even
|
||||||
@@ -358,41 +373,53 @@ lucas(h, n)
|
|||||||
return 1; /* 239 is prime */
|
return 1; /* 239 is prime */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Verify that h*2^n-1 is not a multiple of 3
|
||||||
|
*
|
||||||
|
* The case for h*2^n-1 == 3 is handled above.
|
||||||
|
*/
|
||||||
|
if (((h % 3 == 1) && (n % 2 == 0)) || ((h % 3 == 2) && (n % 2 == 1))) {
|
||||||
|
/* no need to test h*2^n-1, it is a multiple of 3 */
|
||||||
|
ldebug("lucas","not-prime: != 3 and is a multiple of 3");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Avoid any numbers divisible by small primes
|
* Avoid any numbers divisible by small primes
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* check for 3 <= prime factors < 29
|
* check for 5 <= prime factors < 31
|
||||||
* pfact(28)/2 = 111546435
|
* pfact(30)/6 = 1078282205
|
||||||
*/
|
*/
|
||||||
testval = h*2^n - 1;
|
testval = h*2^n - 1;
|
||||||
if (gcd(testval, 111546435) > 1) {
|
if (gcd(testval, 1078282205) > 1) {
|
||||||
/* a small 3 <= prime < 29 divides h*2^n-1 */
|
/* a small 5 <= prime < 31 divides h*2^n-1 */
|
||||||
ldebug("lucas","not-prime: 3<=prime<29 divides h*2^n-1");
|
ldebug("lucas",\
|
||||||
|
"not-prime: a small 5<=prime<31 divides h*2^n-1");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* check for 29 <= prime factors < 47
|
* check for 31 <= prime factors < 53
|
||||||
* pfact(46)/pfact(28) = 5864229
|
* pfact(52)/pfact(30) = 95041567
|
||||||
*/
|
*/
|
||||||
if (gcd(testval, 58642669) > 1) {
|
if (gcd(testval, 95041567) > 1) {
|
||||||
/* a small 29 <= prime < 47 divides h*2^n-1 */
|
/* a small 31 <= prime < 53 divides h*2^n-1 */
|
||||||
ldebug("lucas","not-prime: 29<=prime<47 divides h*2^n-1");
|
ldebug("lucas","not-prime: 31<=prime<53 divides h*2^n-1");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* check for prime 47 <= factors < 257, if h*2^n-1 is large
|
* check for prime 53 <= factors < 257, if h*2^n-1 is large
|
||||||
* 2^282 > pfact(256)/pfact(46) > 2^281
|
* 2^276 > pfact(256)/pfact(52) > 2^275
|
||||||
*/
|
*/
|
||||||
bits = highbit(testval);
|
bits = highbit(testval);
|
||||||
if (bits >= 281) {
|
if (bits >= 275) {
|
||||||
if (pprod256 <= 0) {
|
if (pprod256 <= 0) {
|
||||||
pprod256 = pfact(256)/pfact(46);
|
pprod256 = pfact(256)/pfact(52);
|
||||||
}
|
}
|
||||||
if (gcd(testval, pprod256) > 1) {
|
if (gcd(testval, pprod256) > 1) {
|
||||||
/* a small 47 <= prime < 257 divides h*2^n-1 */
|
/* a small 53 <= prime < 257 divides h*2^n-1 */
|
||||||
ldebug("lucas",\
|
ldebug("lucas",\
|
||||||
"not-prime: 47<=prime<257 divides h*2^n-1");
|
"not-prime: 53<=prime<257 divides h*2^n-1");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -408,7 +435,9 @@ lucas(h, n)
|
|||||||
* generate a test for h*2^n-1. The legacy function,
|
* generate a test for h*2^n-1. The legacy function,
|
||||||
* legacy_gen_v1() used by the Amdahl 6 could have returned
|
* legacy_gen_v1() used by the Amdahl 6 could have returned
|
||||||
* -1. The new gen_v1() based on the method outlined in Ref4
|
* -1. The new gen_v1() based on the method outlined in Ref4
|
||||||
* will never return -1.
|
* will never return -1 if h*2^n-1 is not a multiple of 3.
|
||||||
|
* Because the "multiple of 3" case is handled above, the
|
||||||
|
* call below to gen_v1() will never return -1.
|
||||||
*/
|
*/
|
||||||
v1 = gen_v1(h, n);
|
v1 = gen_v1(h, n);
|
||||||
if (v1 < 0) {
|
if (v1 < 0) {
|
||||||
@@ -483,9 +512,9 @@ lucas(h, n)
|
|||||||
* See the function gen_v1() for details on the value of v(1).
|
* See the function gen_v1() for details on the value of v(1).
|
||||||
*
|
*
|
||||||
* input:
|
* input:
|
||||||
* h - h as in h*2^n-1
|
* h - h as in h*2^n-1 (must be >= 1)
|
||||||
* n - n as in h*2^n-1
|
* n - n as in h*2^n-1 (must be >= 1)
|
||||||
* v1 - gen_v1(h,n) (see function below)
|
* v1 - gen_v1(h,n) (must be >= 3) (see function below)
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* u(2) - initial value for Lucas test on h*2^n-1
|
* u(2) - initial value for Lucas test on h*2^n-1
|
||||||
@@ -498,6 +527,8 @@ gen_u2(h, n, v1)
|
|||||||
local r; /* low value: v(n) */
|
local r; /* low value: v(n) */
|
||||||
local s; /* high value: v(n+1) */
|
local s; /* high value: v(n+1) */
|
||||||
local hbits; /* highest bit set in h */
|
local hbits; /* highest bit set in h */
|
||||||
|
local oldh; /* pre-reduced h */
|
||||||
|
local oldn; /* pre-reduced n */
|
||||||
local i;
|
local i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -506,24 +537,45 @@ gen_u2(h, n, v1)
|
|||||||
if (!isint(h)) {
|
if (!isint(h)) {
|
||||||
quit "bad args: h must be an integer";
|
quit "bad args: h must be an integer";
|
||||||
}
|
}
|
||||||
|
if (h < 0) {
|
||||||
|
quit "bad args: h must be an integer >= 1";
|
||||||
|
}
|
||||||
if (!isint(n)) {
|
if (!isint(n)) {
|
||||||
quit "bad args: n must be an integer";
|
quit "bad args: n must be an integer";
|
||||||
}
|
}
|
||||||
|
if (n < 1) {
|
||||||
|
quit "bad args: n must be an integer >= 1";
|
||||||
|
}
|
||||||
if (!isint(v1)) {
|
if (!isint(v1)) {
|
||||||
quit "bad args: v1 must be an integer";
|
quit "bad args: v1 must be an integer";
|
||||||
}
|
}
|
||||||
if (v1 <= 0) {
|
if (v1 < 3) {
|
||||||
quit "bogus arg: v1 is <= 0";
|
quit "bogus arg: v1 must be an integer >= 3";
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* reduce h if even
|
||||||
|
*
|
||||||
|
* we will force h to be odd by moving powers of two over to 2^n
|
||||||
|
*/
|
||||||
|
oldh = h;
|
||||||
|
oldn = n;
|
||||||
|
shiftdown = fcnt(h,2); /* h % 2^shiftdown == 0, max shiftdown */
|
||||||
|
if (shiftdown > 0) {
|
||||||
|
h >>= shiftdown;
|
||||||
|
n += shiftdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* enforce the h > 0 and n >= 2 rules
|
* enforce the h > 0 and n >= 2 rules
|
||||||
*/
|
*/
|
||||||
if (h <= 0 || n < 1) {
|
if (h <= 0 || n < 1) {
|
||||||
|
print " ERROR: h=":oldh, "n=":oldn, "reduced h=":h, "n=":n;
|
||||||
quit "reduced args violate the rule: 0 < h < 2^n";
|
quit "reduced args violate the rule: 0 < h < 2^n";
|
||||||
}
|
}
|
||||||
hbits = highbit(h);
|
hbits = highbit(h);
|
||||||
if (hbits >= n) {
|
if (hbits >= n) {
|
||||||
|
print " ERROR: h=":oldh, "n=":oldn, "reduced h=":h, "n=":n;
|
||||||
quit "reduced args violate the rule: 0 < h < 2^n";
|
quit "reduced args violate the rule: 0 < h < 2^n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -598,8 +650,8 @@ gen_u2(h, n, v1)
|
|||||||
* See the function gen_u2() for details.
|
* See the function gen_u2() for details.
|
||||||
*
|
*
|
||||||
* input:
|
* input:
|
||||||
* h - h as in h*2^n-1
|
* h - h as in h*2^n-1 (must be >= 1)
|
||||||
* n - n as in h*2^n-1
|
* n - n as in h*2^n-1 (must be >= 1)
|
||||||
* v1 - gen_v1(h,n) (see function below)
|
* v1 - gen_v1(h,n) (see function below)
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
@@ -637,9 +689,9 @@ gen_u0(h, n, v1)
|
|||||||
* x > 2
|
* x > 2
|
||||||
*
|
*
|
||||||
* input:
|
* input:
|
||||||
* x - potential v(1) value
|
* x potential v(1) value
|
||||||
* h - h as in h*2^n-1
|
* h h as in h*2^n-1 (h must be odd >= 1)
|
||||||
* n - n as in h*2^n-1
|
* n n as in h*2^n-1 (must be >= 1)
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* 1 if v(1) == x for h*2^n-1
|
* 1 if v(1) == x for h*2^n-1
|
||||||
@@ -656,9 +708,18 @@ rodseth_xhn(x, h, n)
|
|||||||
if (!isint(h)) {
|
if (!isint(h)) {
|
||||||
quit "bad args: h must be an integer";
|
quit "bad args: h must be an integer";
|
||||||
}
|
}
|
||||||
|
if (iseven(h)) {
|
||||||
|
quit "bad args: h must be an odd integer";
|
||||||
|
}
|
||||||
|
if (h < 1) {
|
||||||
|
quit "bad args: h must be an integer >= 1";
|
||||||
|
}
|
||||||
if (!isint(n)) {
|
if (!isint(n)) {
|
||||||
quit "bad args: n must be an integer";
|
quit "bad args: n must be an integer";
|
||||||
}
|
}
|
||||||
|
if (n < 1) {
|
||||||
|
quit "bad args: n must be an integer >= 1";
|
||||||
|
}
|
||||||
if (!isint(x)) {
|
if (!isint(x)) {
|
||||||
quit "bad args: x must be an integer";
|
quit "bad args: x must be an integer";
|
||||||
}
|
}
|
||||||
@@ -670,7 +731,7 @@ rodseth_xhn(x, h, n)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for jacobi(x-2, h*2^n-1) == 1 (Ref4, condition 1) part 1
|
* Check for jacobi(x-2, h*2^n-1) == 1 (Ref4, condition 1) part 1
|
||||||
*/
|
*/
|
||||||
testval = h*2^n-1;
|
testval = h*2^n-1;
|
||||||
@@ -678,7 +739,7 @@ rodseth_xhn(x, h, n)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for jacobi(x+2, h*2^n-1) == -1 (Ref4, condition 1) part 2
|
* Check for jacobi(x+2, h*2^n-1) == -1 (Ref4, condition 1) part 2
|
||||||
*/
|
*/
|
||||||
if (jacobi(x+2, testval) != -1) {
|
if (jacobi(x+2, testval) != -1) {
|
||||||
@@ -702,9 +763,9 @@ rodseth_xhn(x, h, n)
|
|||||||
* We can show that X > 2. See the comments in the rodseth_xhn(x,h,n) above.
|
* We can show that X > 2. See the comments in the rodseth_xhn(x,h,n) above.
|
||||||
*
|
*
|
||||||
* Some values of X satisfy more often than others. For example a large sample
|
* Some values of X satisfy more often than others. For example a large sample
|
||||||
* of odd h, h multiple of 3 and large n (some around 1e4, some near 1e6, others
|
* of h*2^n-1, h odd multiple of 3, and large n (some around 1e4, some near 1e6,
|
||||||
* near 3e7) where the sample size was 66 973 365, here is the count of the
|
* others near 3e7) where the sample size was 66 973 365, here is the count of
|
||||||
* smallest value of X that satisfies conditions in Ref4, condition 1:
|
* the smallest value of X that satisfies conditions in Ref4, condition 1:
|
||||||
*
|
*
|
||||||
* count X
|
* count X
|
||||||
* ----------
|
* ----------
|
||||||
@@ -762,45 +823,161 @@ rodseth_xhn(x, h, n)
|
|||||||
* 1 161
|
* 1 161
|
||||||
* 1 155
|
* 1 155
|
||||||
*
|
*
|
||||||
|
* It is important that we select the smallest possible v(1). While testing
|
||||||
|
* various values of X for V(1) is fast, using larger than necessary values
|
||||||
|
* of V(1) of can slow down calculating V(h).
|
||||||
|
*
|
||||||
* The above distribution was found to hold fairly well over many values of
|
* The above distribution was found to hold fairly well over many values of
|
||||||
* odd h that are a multiple of 3 and for many values of n where h < 2^n.
|
* odd h that are also a multiple of 3 and for many values of n where h < 2^n.
|
||||||
|
*
|
||||||
|
* For example for in a sample size of 1000000 numbers of the form h*2^n-1
|
||||||
|
* where h is an odd multiple of 3, 12996351 <= h <= 13002351,
|
||||||
|
* 4331116 <= n <= 4332116, these are the smallest v(1) values that were found:
|
||||||
|
*
|
||||||
|
* smallest percentage
|
||||||
|
* v(1) used
|
||||||
|
* -------- ---------
|
||||||
|
* 3 40.0000 %
|
||||||
|
* 5 25.6833 %
|
||||||
|
* 9 11.6924 %
|
||||||
|
* 11 10.4528 %
|
||||||
|
* 15 4.8048 %
|
||||||
|
* 17 2.3458 %
|
||||||
|
* 21 1.3734 %
|
||||||
|
* 29 1.0527 %
|
||||||
|
* 20 0.8595 %
|
||||||
|
* 27 0.5758 %
|
||||||
|
* 35 0.4420 %
|
||||||
|
* 36 0.2433 %
|
||||||
|
* 39 0.1779 %
|
||||||
|
* 41 0.0885 %
|
||||||
|
* 45 0.0571 %
|
||||||
|
* 32 0.0337 %
|
||||||
|
* 51 0.0289 %
|
||||||
|
* 44 0.0205 %
|
||||||
|
* 49 0.0176 %
|
||||||
|
* 56 0.0137 %
|
||||||
|
* 59 0.0108 %
|
||||||
|
* 57 0.0053 %
|
||||||
|
* 65 0.0047 %
|
||||||
|
* 55 0.0045 %
|
||||||
|
* 69 0.0031 %
|
||||||
|
* 71 0.0024 %
|
||||||
|
* 66 0.0011 %
|
||||||
|
* 95 0.0008 %
|
||||||
|
* 81 0.0008 %
|
||||||
|
* 77 0.0006 %
|
||||||
|
* 72 0.0005 %
|
||||||
|
* 99 0.0004 %
|
||||||
|
* 80 0.0003 %
|
||||||
|
* 74 0.0003 %
|
||||||
|
* 84 0.0002 %
|
||||||
|
* 67 0.0002 %
|
||||||
|
* 87 0.0001 %
|
||||||
|
* 104 0.0001 %
|
||||||
|
* 129 0.0001 %
|
||||||
|
*
|
||||||
|
* However, a case can be made for considering only odd values for v(1)
|
||||||
|
* candidates. When h * 2^n-1 is prime and h is an odd multiple of 3,
|
||||||
|
* a smallest v(1) that is even is extremely rate. Of the list of 146553
|
||||||
|
* known primes of the form h*2^n-1 when h is an odd a multiple of 3,
|
||||||
|
* none has an smallest v(1) that was even.
|
||||||
|
*
|
||||||
|
* See:
|
||||||
|
*
|
||||||
|
* https://github.com/arcetri/verified-prime
|
||||||
|
*
|
||||||
|
* for that list of 146553 known primes of the form h*2^n-1.
|
||||||
|
*
|
||||||
|
* That same example for in a sample size of 1000000 numbers of the
|
||||||
|
* form h*2^n-1 where h is an odd multiple of 3, 12996351 <= h <= 13002351,
|
||||||
|
* 4331116 <= n <= 4332116, these are the smallest odd v(1) values that were
|
||||||
|
* found:
|
||||||
|
*
|
||||||
|
* smallest percentage
|
||||||
|
* odd v(1) used
|
||||||
|
* -------- ---------
|
||||||
|
* 3 40.0000 %
|
||||||
|
* 5 25.6833 %
|
||||||
|
* 9 11.6924 %
|
||||||
|
* 11 10.4528 %
|
||||||
|
* 15 4.8048 %
|
||||||
|
* 17 2.3458 %
|
||||||
|
* 21 1.6568 %
|
||||||
|
* 29 1.6174 %
|
||||||
|
* 35 0.4529 %
|
||||||
|
* 27 0.3546 %
|
||||||
|
* 39 0.3470 %
|
||||||
|
* 41 0.2159 %
|
||||||
|
* 45 0.1173 %
|
||||||
|
* 31 0.0661 %
|
||||||
|
* 51 0.0619 %
|
||||||
|
* 55 0.0419 %
|
||||||
|
* 59 0.0250 %
|
||||||
|
* 49 0.0170 %
|
||||||
|
* 69 0.0110 %
|
||||||
|
* 65 0.0098 %
|
||||||
|
* 71 0.0078 %
|
||||||
|
* 85 0.0048 %
|
||||||
|
* 81 0.0044 %
|
||||||
|
* 95 0.0038 %
|
||||||
|
* 99 0.0021 %
|
||||||
|
* 125 0.0009 %
|
||||||
|
* 57 0.0007 %
|
||||||
|
* 111 0.0005 %
|
||||||
|
* 77 0.0003 %
|
||||||
|
* 165 0.0003 %
|
||||||
|
* 155 0.0002 %
|
||||||
|
* 129 0.0002 %
|
||||||
|
* 101 0.0002 %
|
||||||
|
* 53 0.0001 %
|
||||||
|
*
|
||||||
|
* Moreover when evaluating odd candidates for v(1), one may cache Jacobi
|
||||||
|
* symbol evaluations to reduce the number of Jacobi symbol evaluations to
|
||||||
|
* a minimum. For example, if one tests 5 and finds that the 2nd case fails:
|
||||||
|
*
|
||||||
|
* jacobi(5+2, h*2^n-1) != -1
|
||||||
|
*
|
||||||
|
* Then if one is later testing 9, the Jacobi symbol value for the first
|
||||||
|
* 1st case:
|
||||||
|
*
|
||||||
|
* jacobi(7-2, h*2^n-1)
|
||||||
|
*
|
||||||
|
* is already known.
|
||||||
|
*
|
||||||
|
* Without Jacobi symbol value caching, it requires on average
|
||||||
|
* 4.851377 Jacobi symbol evaluations. With Jacobi symbol value caching
|
||||||
|
* cacheing, an average of 4.348820 Jacobi symbol evaluations is needed.
|
||||||
*
|
*
|
||||||
* Given this information, when odd h is a multiple of 3 we try, in order,
|
* Given this information, when odd h is a multiple of 3 we try, in order,
|
||||||
* these values of X:
|
* these odd values of X:
|
||||||
*
|
*
|
||||||
* 3, 5, 9, 11, 15, 17, 21, 29, 20, 27, 35, 36, 39, 41, 45, 32, 51, 44,
|
* 3, 5, 9, 11, 15, 17, 21, 29, 27, 35, 39, 41, 31, 45, 51, 55, 49, 59,
|
||||||
* 56, 49, 59, 57, 65, 55, 69, 71, 77, 81, 66, 95, 80, 67, 84, 99, 72,
|
* 69, 65, 71, 57, 85, 81, 95, 99, 77, 53, 67, 125, 111, 105, 87, 129,
|
||||||
* 74, 87, 90, 104, 101, 105, 109, 116, 111, 92
|
* 101, 83, 165, 155, 149, 141, 121, 109
|
||||||
*
|
*
|
||||||
* And stop on the first value of X where:
|
* And stop on the first value of X where:
|
||||||
*
|
*
|
||||||
* jacobi(X-2, h*2^n-1) == 1
|
* jacobi(X-2, h*2^n-1) == 1
|
||||||
* jacobi(X+2, h*2^n-1) == -1
|
* jacobi(X+2, h*2^n-1) == -1
|
||||||
*
|
*
|
||||||
* If no value in that list works, we start simple search starting with X = 120
|
* Less than 1 case out of 1000000 will not be satisfied by the above list.
|
||||||
* and incrementing by 1 until a value of X is found.
|
* If no value in that list works, we start simple search starting with X = 167
|
||||||
|
* and incrementing by 2 until a value of X is found.
|
||||||
*
|
*
|
||||||
* The x_tbl[] matrix contains those common values of X to try in order.
|
* The x_tbl[] matrix contains those values of X to try in order.
|
||||||
* If all x_tbl_len fail to satisfy Ref4 condition 1, then we begin a
|
* If all x_tbl_len fail to satisfy Ref4 condition 1 (this happens less than
|
||||||
* linear search at next_x until we find a proper X value.
|
* 1 in 1000000 cases), then we begin a linear search of odd values starting at
|
||||||
*
|
* next_x until we find a proper X value.
|
||||||
* IMPORTANT NOTE: Using this table will not find the smallest possible v(1)
|
|
||||||
* for a given h and n. This is not a problem because using
|
|
||||||
* a larger value of v(1) does not impact the primality test.
|
|
||||||
* Furthermore after lucas(h, n) generates a few u(n) terms,
|
|
||||||
* the values will wrap (due to computing mod h*2^n-1).
|
|
||||||
* Finally on average, about 1/4 of the values of X work as
|
|
||||||
* v(1) for a given n when h is a multiple of 3. Skipping
|
|
||||||
* rarely used v(1) will not doom gen_v1() to a long search.
|
|
||||||
*/
|
*/
|
||||||
x_tbl_len = 45;
|
x_tbl_len = 42;
|
||||||
mat x_tbl[x_tbl_len];
|
mat x_tbl[x_tbl_len];
|
||||||
x_tbl = {
|
x_tbl = {
|
||||||
3, 5, 9, 11, 15, 17, 21, 29, 20, 27, 35, 36, 39, 41, 45, 32, 51, 44,
|
3, 5, 9, 11, 15, 17, 21, 29, 27, 35, 39, 41, 31, 45, 51, 55, 49, 59,
|
||||||
56, 49, 59, 57, 65, 55, 69, 71, 77, 81, 66, 95, 80, 67, 84, 99, 72,
|
69, 65, 71, 57, 85, 81, 95, 99, 77, 53, 67, 125, 111, 105, 87, 129,
|
||||||
74, 87, 90, 104, 101, 105, 109, 116, 111, 92
|
101, 83, 165, 155, 149, 141, 121, 109
|
||||||
};
|
};
|
||||||
next_x = 120;
|
next_x = 167; /* must be 2 more than the largest value in x_tbl[] */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* gen_v1 - compute the v(1) for a given h*2^n-1 if we can
|
* gen_v1 - compute the v(1) for a given h*2^n-1 if we can
|
||||||
@@ -840,7 +1017,13 @@ next_x = 120;
|
|||||||
* u(2) = alpha^h + alpha^(-h) (NOTE: some call this u(2))
|
* u(2) = alpha^h + alpha^(-h) (NOTE: some call this u(2))
|
||||||
* r = abs(2^2 - 1^2*3) = 1
|
* r = abs(2^2 - 1^2*3) = 1
|
||||||
*
|
*
|
||||||
* and the bottom of Ref1, page 872 states:
|
* where these values work for Case 1: (h mod 3 != 0)
|
||||||
|
*
|
||||||
|
* a = 1
|
||||||
|
* b = 2
|
||||||
|
* D = 1
|
||||||
|
*
|
||||||
|
* Now at the bottom of Ref1, page 872 states:
|
||||||
*
|
*
|
||||||
* v(x) = alpha^x + alpha^(-x)
|
* v(x) = alpha^x + alpha^(-x)
|
||||||
*
|
*
|
||||||
@@ -852,12 +1035,22 @@ next_x = 120;
|
|||||||
*
|
*
|
||||||
* u(2) = v(h) (NOTE: some call this u(2))
|
* u(2) = v(h) (NOTE: some call this u(2))
|
||||||
*
|
*
|
||||||
* so we simply return
|
* so we can always return
|
||||||
*
|
*
|
||||||
* v(1) = alpha^1 + alpha^(-1)
|
* v(1) = alpha^1 + alpha^(-1)
|
||||||
* = (2+sqrt(3)) + (2-sqrt(3))
|
* = (2+sqrt(3)) + (2-sqrt(3))
|
||||||
* = 4
|
* = 4
|
||||||
*
|
*
|
||||||
|
* In 40% of the cases when h is not a multiple of 3, 3 is a valid value
|
||||||
|
* for v(1). We can test if 3 is a valid value for v(1) in this case:
|
||||||
|
*
|
||||||
|
* if jacobi(1, h*2^n-1) == 1 and jacobi(5, h*2^n-1) == -1, then
|
||||||
|
* v(1) = 3
|
||||||
|
* else
|
||||||
|
* v(1) = 4
|
||||||
|
*
|
||||||
|
* NOTE: The above "if then else" works only of h is not a multiple of 3.
|
||||||
|
*
|
||||||
***
|
***
|
||||||
*
|
*
|
||||||
* Case 2: (h mod 3 == 0)
|
* Case 2: (h mod 3 == 0)
|
||||||
@@ -949,17 +1142,22 @@ next_x = 120;
|
|||||||
***
|
***
|
||||||
*
|
*
|
||||||
* input:
|
* input:
|
||||||
* h h as in h*2^n-1
|
* h h as in h*2^n-1 (h must be odd >= 1)
|
||||||
* n n as in h*2^n-1
|
* n n as in h*2^n-1 (must be >= 1)
|
||||||
*
|
*
|
||||||
* output:
|
* output:
|
||||||
* returns v(1), or -1 is there is no quick way
|
* returns v(1), or
|
||||||
|
* -1 when h*2^n-1 is a multiple of 3
|
||||||
*/
|
*/
|
||||||
define
|
define
|
||||||
gen_v1(h, n)
|
gen_v1(h, n)
|
||||||
{
|
{
|
||||||
local x; /* potential v(1) to test */
|
local x; /* potential v(1) to test */
|
||||||
local i; /* x_tbl index */
|
local i; /* x_tbl index */
|
||||||
|
local v1m2; /* X-2 1st case */
|
||||||
|
local v1p2; /* X+2 2nd case */
|
||||||
|
local testval; /* h*2^n-1 - value we are testing if prime */
|
||||||
|
local mat cached_v1[next_x]; /* cached Jacobi symbol values or 0 */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check arg types
|
* check arg types
|
||||||
@@ -967,58 +1165,131 @@ gen_v1(h, n)
|
|||||||
if (!isint(h)) {
|
if (!isint(h)) {
|
||||||
quit "bad args: h must be an integer";
|
quit "bad args: h must be an integer";
|
||||||
}
|
}
|
||||||
|
if (iseven(h)) {
|
||||||
|
quit "bad args: h must be an odd integer";
|
||||||
|
}
|
||||||
|
if (h < 1) {
|
||||||
|
quit "bad args: h must be an integer >= 1";
|
||||||
|
}
|
||||||
if (!isint(n)) {
|
if (!isint(n)) {
|
||||||
quit "bad args: n must be an integer";
|
quit "bad args: n must be an integer";
|
||||||
}
|
}
|
||||||
|
if (n < 1) {
|
||||||
|
quit "bad args: n must be an integer >= 1";
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pretest: Verify that h*2^n-1 is not a multiple of 3
|
||||||
|
*/
|
||||||
|
if (((h % 3 == 1) && (n % 2 == 0)) || ((h % 3 == 2) && (n % 2 == 1))) {
|
||||||
|
/* no need to test h*2^n-1, it is not prime */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Common Mersenne number case:
|
||||||
|
*
|
||||||
|
* For Mersenne numbers:
|
||||||
|
*
|
||||||
|
* 2^n-1
|
||||||
|
*
|
||||||
|
* we can use, 40% of the time, v(1) == 3. However nearly all code that
|
||||||
|
* implements the Lucas-Lehmer test uses v(1) == 4. Whenever for
|
||||||
|
* h != 0 mod 3, and particular the Mersenne number case of when h == 1:
|
||||||
|
*
|
||||||
|
* 1*2^n-1
|
||||||
|
*
|
||||||
|
* v(1) == 4 always works. For this reason, we return 4 when h == 1.
|
||||||
|
*/
|
||||||
|
if (h == 1) {
|
||||||
|
/* v(1) == 4 always works for the Mersenne number case */
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check for Case 1: (h mod 3 != 0)
|
* check for Case 1: (h mod 3 != 0)
|
||||||
*/
|
*/
|
||||||
if (h % 3 != 0) {
|
if (h % 3 != 0) {
|
||||||
/* v(1) is easy to compute */
|
if (rodseth_xhn(3, h, n) == 1) {
|
||||||
return 4;
|
/* 40% of the time, 3 works when h mod 3 != 0 */
|
||||||
|
return 3;
|
||||||
|
} else {
|
||||||
|
/* otherwise 4 always works when h mod 3 != 0 */
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* What follow is Case 2: (h mod 3 == 0)
|
* What follow is Case 2: (h mod 3 == 0)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* clear cache
|
||||||
|
*/
|
||||||
|
matfill(cached_v1, 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We will look for x that satisfies conditions in Ref4, condition 1:
|
* We will look for x that satisfies conditions in Ref4, condition 1:
|
||||||
*
|
*
|
||||||
* jacobi(X-2, h*2^n-1) == 1 part 1
|
* jacobi(X-2, h*2^n-1) == 1 part 1
|
||||||
* jacobi(X+2, h*2^n-1) == -1 part 2
|
* jacobi(X+2, h*2^n-1) == -1 part 2
|
||||||
|
*
|
||||||
|
* NOTE: If we wanted to be super optimal, we would cache
|
||||||
|
* jacobi(X+2, h*2^n-1) that that when we increment X
|
||||||
|
* to the next odd value, the now jacobi(X-2, h*2^n-1)
|
||||||
|
* does not need to be re-evaluated.
|
||||||
*/
|
*/
|
||||||
|
testval = h*2^n-1;
|
||||||
for (i=0; i < x_tbl_len; ++i) {
|
for (i=0; i < x_tbl_len; ++i) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* test Ref4 condition 1:
|
* obtain the next test candidate
|
||||||
*/
|
*/
|
||||||
x = x_tbl[i];
|
x = x_tbl[i];
|
||||||
if (rodseth_xhn(x, h, n) == 1) {
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* found a x that satisfies Ref4 condition 1
|
* Check x for condition 1 part 1
|
||||||
*/
|
*
|
||||||
ldebug("gen_v1", "h= " + str(h) + " n= " + str(n) +
|
* jacobi(x-2, h*2^n-1) == 1
|
||||||
" v1= " + str(x) + " using tbl[ " +
|
*/
|
||||||
str(i) + " ]");
|
v1m2 = x-2;
|
||||||
return x;
|
if (cached_v1[v1m2] == 0) {
|
||||||
|
cached_v1[v1m2] = jacobi(v1m2, testval);
|
||||||
}
|
}
|
||||||
|
if (cached_v1[v1m2] != 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check x for condition 1 part 2
|
||||||
|
*
|
||||||
|
* jacobi(x+2, h*2^n-1) == -1
|
||||||
|
*/
|
||||||
|
v1p2 = x+2;
|
||||||
|
if (cached_v1[v1p2] == 0) {
|
||||||
|
cached_v1[v1p2] = jacobi(v1p2, testval);
|
||||||
|
}
|
||||||
|
if (cached_v1[v1p2] != -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* found a x that satisfies Ref4 condition 1
|
||||||
|
*/
|
||||||
|
ldebug("gen_v1", "h= " + str(h) + " n= " + str(n) +
|
||||||
|
" v1= " + str(x) + " using tbl[ " +
|
||||||
|
str(i) + " ]");
|
||||||
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We are in that rare case (about 1 in 2 300 000) where none of the
|
* We are in that rare case (less than 1 in 1 000 000) where none of the
|
||||||
* common X values satisfy Ref4 condition 1. We start a linear search
|
* common X values satisfy Ref4 condition 1. We start a linear search
|
||||||
* at next_x from here on.
|
* of odd values at next_x from here on.
|
||||||
*
|
|
||||||
* However, we also need to keep in mind that when x+2 >= 257, we
|
|
||||||
* need to verify that gcd(x-2, h*2^n-1) == 1 and
|
|
||||||
* and to verify that gcd(x+2, h*2^n-1) == 1.
|
|
||||||
*/
|
*/
|
||||||
x = next_x;
|
x = next_x;
|
||||||
while (rodseth_xhn(x, h, n) != 1) {
|
while (rodseth_xhn(x, h, n) != 1) {
|
||||||
++x;
|
x += 2;
|
||||||
}
|
}
|
||||||
/* finally found a v(1) value */
|
/* finally found a v(1) value */
|
||||||
ldebug("gen_v1", "h= " + str(h) + " n= " + str(n) +
|
ldebug("gen_v1", "h= " + str(h) + " n= " + str(n) +
|
||||||
@@ -1143,7 +1414,13 @@ legacy_d_qval[7] = 19; legacy_v1_qval[7] = 74; /* a=38 b=1 r=2 */
|
|||||||
* u(2) = alpha^h + alpha^(-h)
|
* u(2) = alpha^h + alpha^(-h)
|
||||||
* r = abs(2^2 - 1^2*3) = 1
|
* r = abs(2^2 - 1^2*3) = 1
|
||||||
*
|
*
|
||||||
* and the bottom of Ref1, page 872 states:
|
* where these values work for Case 1: (h mod 3 != 0)
|
||||||
|
*
|
||||||
|
* a = 1
|
||||||
|
* b = 2
|
||||||
|
* D = 1
|
||||||
|
*
|
||||||
|
* Now at the bottom of Ref1, page 872 states:
|
||||||
*
|
*
|
||||||
* v(x) = alpha^x + alpha^(-x)
|
* v(x) = alpha^x + alpha^(-x)
|
||||||
*
|
*
|
||||||
@@ -1444,8 +1721,8 @@ legacy_d_qval[7] = 19; legacy_v1_qval[7] = 74; /* a=38 b=1 r=2 */
|
|||||||
***
|
***
|
||||||
*
|
*
|
||||||
* input:
|
* input:
|
||||||
* h h as in h*2^n-1
|
* h h as in h*2^n-1 (must be >= 1)
|
||||||
* n n as in h*2^n-1
|
* n n as in h*2^n-1 (must be >= 1)
|
||||||
*
|
*
|
||||||
* output:
|
* output:
|
||||||
* returns v(1), or -1 is there is no quick way
|
* returns v(1), or -1 is there is no quick way
|
||||||
@@ -1457,6 +1734,22 @@ legacy_gen_v1(h, n)
|
|||||||
local val_mod; /* h*2^n-1 mod 'D' */
|
local val_mod; /* h*2^n-1 mod 'D' */
|
||||||
local i;
|
local i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check arg types
|
||||||
|
*/
|
||||||
|
if (!isint(h)) {
|
||||||
|
quit "bad args: h must be an integer";
|
||||||
|
}
|
||||||
|
if (h < 1) {
|
||||||
|
quit "bad args: h must be an integer >= 1";
|
||||||
|
}
|
||||||
|
if (!isint(n)) {
|
||||||
|
quit "bad args: n must be an integer";
|
||||||
|
}
|
||||||
|
if (n < 1) {
|
||||||
|
quit "bad args: n must be an integer >= 1";
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check for case 1
|
* check for case 1
|
||||||
*/
|
*/
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* lucas_chk - test all primes of the form h*2^n-1, 1<=h<200 and n <= high_n
|
* lucas_chk - test all primes of the form h*2^n-1, 1<=h<200 and n <= high_n
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 Landon Curt Noll
|
* Copyright (C) 1999,2021 Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: lucas_chk.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/lucas_chk.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1991/01/11 05:41:43
|
* Under source code control: 1991/01/11 05:41:43
|
||||||
* File existed as early as: 1991
|
* File existed as early as: 1991
|
||||||
*
|
*
|
||||||
@@ -307,7 +303,7 @@ read -once "lucas.cal";
|
|||||||
* [quiet] if given and != 0, then do not print individual test results
|
* [quiet] if given and != 0, then do not print individual test results
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* 1 all is ok
|
* 1 all is OK
|
||||||
* 0 something went wrong
|
* 0 something went wrong
|
||||||
*/
|
*/
|
||||||
define
|
define
|
||||||
|
@@ -19,10 +19,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: mersenne.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/mersenne.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1991/05/22 21:56:36
|
* Under source code control: 1991/05/22 21:56:36
|
||||||
* File existed as early as: 1991
|
* File existed as early as: 1991
|
||||||
*
|
*
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* mfactor - return the lowest factor of 2^n-1, for n > 0
|
* mfactor - return the lowest factor of 2^n-1, for n > 0
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 Landon Curt Noll
|
* Copyright (C) 1999,2021 Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: mfactor.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/mfactor.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1996/07/06 06:09:40
|
* Under source code control: 1996/07/06 06:09:40
|
||||||
* File existed as early as: 1996
|
* File existed as early as: 1996
|
||||||
*
|
*
|
||||||
@@ -83,7 +79,7 @@
|
|||||||
* hindx = 0;
|
* hindx = 0;
|
||||||
* } while (test_factor < some_limit);
|
* } while (test_factor < some_limit);
|
||||||
*
|
*
|
||||||
* The test, mfactor(67, 1, 10000) took on an 200 Mhz r4k (user CPU seconds):
|
* The test, mfactor(67, 1, 10000) took on an 200 MHz r4k (user CPU seconds):
|
||||||
*
|
*
|
||||||
* 210.83 (prior to use of hset[])
|
* 210.83 (prior to use of hset[])
|
||||||
* 78.35 (hset[] for p_elim = 7)
|
* 78.35 (hset[] for p_elim = 7)
|
||||||
@@ -103,7 +99,7 @@
|
|||||||
* 57.78 (hset[] for p_elim = 17)
|
* 57.78 (hset[] for p_elim = 17)
|
||||||
* p_elim == 19 rejected because of memory size
|
* p_elim == 19 rejected because of memory size
|
||||||
*
|
*
|
||||||
* The p_elim == 17 overhead takes ~3 minutes on an 200 Mhz r4k CPU and
|
* The p_elim == 17 overhead takes ~3 minutes on an 200 MHz r4k CPU and
|
||||||
* requires about ~13 Megs of memory. The p_elim == 13 overhead
|
* requires about ~13 Megs of memory. The p_elim == 13 overhead
|
||||||
* takes about 3 seconds and requires ~1.5 Megs of memory.
|
* takes about 3 seconds and requires ~1.5 Megs of memory.
|
||||||
*
|
*
|
||||||
@@ -260,7 +256,7 @@ define mfactor(n, start_k, rept_loop, p_elim)
|
|||||||
return q;
|
return q;
|
||||||
} else {
|
} else {
|
||||||
/* report this loop */
|
/* report this loop */
|
||||||
printf("at 2*%d*%d+1, cpu: %f\n",
|
printf("at 2*%d*%d+1, CPU: %f\n",
|
||||||
(q-1)/(2*n), n, usertime());
|
(q-1)/(2*n), n, usertime());
|
||||||
fflush(files(1));
|
fflush(files(1));
|
||||||
loop = 0;
|
loop = 0;
|
||||||
@@ -273,14 +269,14 @@ define mfactor(n, start_k, rept_loop, p_elim)
|
|||||||
*/
|
*/
|
||||||
if (rept_loop <= ++loop) {
|
if (rept_loop <= ++loop) {
|
||||||
/* report this loop */
|
/* report this loop */
|
||||||
printf("at 2*%d*%d+1, cpu: %f\n",
|
printf("at 2*%d*%d+1, CPU: %f\n",
|
||||||
(q-1)/(2*n), n, usertime());
|
(q-1)/(2*n), n, usertime());
|
||||||
fflush(files(1));
|
fflush(files(1));
|
||||||
loop = 0;
|
loop = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* skip if divisable by a prime <= 449
|
* skip if divisible by a prime <= 449
|
||||||
*
|
*
|
||||||
* The value 281 was determined by timing loops
|
* The value 281 was determined by timing loops
|
||||||
* which found that 281 was at or near the
|
* which found that 281 was at or near the
|
||||||
@@ -289,7 +285,7 @@ define mfactor(n, start_k, rept_loop, p_elim)
|
|||||||
* The addition of the do { ... } while (factor(q, 449)>1);
|
* The addition of the do { ... } while (factor(q, 449)>1);
|
||||||
* loop reduced the factoring loop time (36504 k values with
|
* loop reduced the factoring loop time (36504 k values with
|
||||||
* the hset[] initialization time removed) from 25.69 sec to
|
* the hset[] initialization time removed) from 25.69 sec to
|
||||||
* 15.62 sec of CPU time on a 200Mhz r4k.
|
* 15.62 sec of CPU time on a 200MHz r4k.
|
||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
/*
|
/*
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: mod.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/mod.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1990/02/15 01:50:34
|
* Under source code control: 1990/02/15 01:50:34
|
||||||
* File existed as early as: before 1990
|
* File existed as early as: before 1990
|
||||||
*
|
*
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* natnumset - functions for sets of natural numbers not exceeding a fixed bound
|
* natnumset - functions for sets of natural numbers not exceeding a fixed bound
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 Ernest Bowen
|
* Copyright (C) 1999,2021 Ernest Bowen
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: natnumset.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/natnumset.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1997/09/07 23:53:51
|
* Under source code control: 1997/09/07 23:53:51
|
||||||
* File existed as early as: 1997
|
* File existed as early as: 1997
|
||||||
*
|
*
|
||||||
@@ -80,7 +76,7 @@
|
|||||||
* A \ B = set difference, integers in A but not in B
|
* A \ B = set difference, integers in A but not in B
|
||||||
*
|
*
|
||||||
* ~A = complement of A, integers not in A
|
* ~A = complement of A, integers not in A
|
||||||
* #A = number ofintegers in A
|
* #A = number of integers in A
|
||||||
* !A = 1 or 0 according as A is empty or not empty
|
* !A = 1 or 0 according as A is empty or not empty
|
||||||
* +A = sum of the members of A
|
* +A = sum of the members of A
|
||||||
*
|
*
|
||||||
@@ -104,7 +100,7 @@
|
|||||||
* A >= B = (B <= A)
|
* A >= B = (B <= A)
|
||||||
* A > B = (B < A)
|
* A > B = (B < A)
|
||||||
*
|
*
|
||||||
* Expresssions may be formed from the above "arithmetic" operations in
|
* Expressions may be formed from the above "arithmetic" operations in
|
||||||
* the usual way, with parentheses for variations from the usual precedence
|
* the usual way, with parentheses for variations from the usual precedence
|
||||||
* rules. For example
|
* rules. For example
|
||||||
*
|
*
|
||||||
|
641
cal/palindrome.cal
Normal file
641
cal/palindrome.cal
Normal file
@@ -0,0 +1,641 @@
|
|||||||
|
/*
|
||||||
|
* palindrome - palindrome utilities
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 Landon Curt Noll
|
||||||
|
*
|
||||||
|
* Calc is open software; you can redistribute it and/or modify it under
|
||||||
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* A copy of version 2.1 of the GNU Lesser General Public License is
|
||||||
|
* distributed with calc under the filename COPYING-LGPL. You should have
|
||||||
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* Under source code control: 2021/11/06 14:35:37
|
||||||
|
* File existed as early as: 2021
|
||||||
|
*
|
||||||
|
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* digitof - return the a digit of a value
|
||||||
|
*
|
||||||
|
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||||
|
*
|
||||||
|
* given:
|
||||||
|
* val value to find a digit of
|
||||||
|
* place digit place
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* value (>= 0 and < 10) that is the place-th digit of val
|
||||||
|
* or 0 if place is not a digit of val
|
||||||
|
*/
|
||||||
|
define digitof(val, place)
|
||||||
|
{
|
||||||
|
local d; /* length of val in digits */
|
||||||
|
|
||||||
|
/* determine length */
|
||||||
|
d = digits(val);
|
||||||
|
|
||||||
|
/* firewall - return 0 if digit place doesn't exist */
|
||||||
|
if (place < 1 || place > d) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* return the place-th digit of val as a single digit */
|
||||||
|
return (val // (10^(place-1))) % 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* copalplace - determine the other place in a palindrome
|
||||||
|
*
|
||||||
|
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||||
|
*
|
||||||
|
* given:
|
||||||
|
* d digits of a value
|
||||||
|
* place digit place
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* given palindrome val, the other digit paired with place
|
||||||
|
* or 0 if place is not a digit of val
|
||||||
|
*/
|
||||||
|
define copalplace(d, place)
|
||||||
|
{
|
||||||
|
/* firewall - return 0 if digit place doesn't exist */
|
||||||
|
if (d < 1 || place < 1 || place > d) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* return digit coplace */
|
||||||
|
return d+1 - place;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* upperhalf - return the upper half of a palindrome
|
||||||
|
*
|
||||||
|
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||||
|
*
|
||||||
|
* NOTE: When the value has an odd number of digits, the upper half
|
||||||
|
* includes the middle digit.
|
||||||
|
*
|
||||||
|
* given:
|
||||||
|
* val a value
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* the upper half digits of a value
|
||||||
|
*/
|
||||||
|
define upperhalf(val)
|
||||||
|
{
|
||||||
|
local d; /* length of val in digits */
|
||||||
|
local halfd; /* length of upper hand of val */
|
||||||
|
|
||||||
|
/* determine length */
|
||||||
|
d = digits(val);
|
||||||
|
halfd = d // 2;
|
||||||
|
|
||||||
|
/* return upper half */
|
||||||
|
return (val // 10^halfd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* mkpal - make a value into a palindrome
|
||||||
|
*
|
||||||
|
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||||
|
*
|
||||||
|
* given:
|
||||||
|
* val a value
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* val as a palindrome with lower half being reverse digits of val
|
||||||
|
*/
|
||||||
|
define mkpal(val)
|
||||||
|
{
|
||||||
|
local d; /* length of val in digits */
|
||||||
|
local i; /* counter */
|
||||||
|
local ret; /* palindrome being formed */
|
||||||
|
|
||||||
|
/* determine length */
|
||||||
|
d = digits(val);
|
||||||
|
|
||||||
|
/* insert digits in reverse order at the bottom */
|
||||||
|
ret = val;
|
||||||
|
for (i=0; i < d; ++i) {
|
||||||
|
ret = ret*10 + digit(val, i);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* mkpalmiddigit - make a value into a palindrome with a middle digit
|
||||||
|
*
|
||||||
|
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||||
|
*
|
||||||
|
* given:
|
||||||
|
* val a value
|
||||||
|
* digit the digit to put into the middle of the palindrome
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* val as a palindrome with lower half being reverse digits of val
|
||||||
|
* and digit as a middle digit
|
||||||
|
*/
|
||||||
|
define mkpalmiddigit(val, digit)
|
||||||
|
{
|
||||||
|
local d; /* length of val in digits */
|
||||||
|
local i; /* counter */
|
||||||
|
local ret; /* palindrome being formed */
|
||||||
|
|
||||||
|
/* determine length */
|
||||||
|
d = digits(val);
|
||||||
|
|
||||||
|
/* insert digits in reverse order at the bottom */
|
||||||
|
ret = val*10 + digit;
|
||||||
|
for (i=0; i < d; ++i) {
|
||||||
|
ret = ret*10 + digit(val, i);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ispal - determine if a value is a palindrome
|
||||||
|
*
|
||||||
|
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||||
|
*
|
||||||
|
* given:
|
||||||
|
* val a value
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* 1 ==> val is a palindrome
|
||||||
|
* 0 ==> val is NOT a palindrome
|
||||||
|
*/
|
||||||
|
define ispal(val)
|
||||||
|
{
|
||||||
|
local half; /* upper half of digits of val */
|
||||||
|
local digit; /* middle digit */
|
||||||
|
|
||||||
|
/* case: val has an even number of digits */
|
||||||
|
if (iseven(digits(val))) {
|
||||||
|
|
||||||
|
/* test palindrome-ness */
|
||||||
|
return (val == mkpal(upperhalf(val)));
|
||||||
|
|
||||||
|
/* case: val can an odd number of digits */
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/* test palindrome-ness */
|
||||||
|
half = upperhalf(val);
|
||||||
|
digit = half % 10;
|
||||||
|
half //= 10;
|
||||||
|
return (val == mkpalmiddigit(half, digit));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* palnextpal - return next palindrome from a known palindrome
|
||||||
|
*
|
||||||
|
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||||
|
*
|
||||||
|
* given:
|
||||||
|
* pal a palindrome
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* next palindrome > pal
|
||||||
|
*/
|
||||||
|
define palnextpal(pal)
|
||||||
|
{
|
||||||
|
local paldigits; /* digits in pal */
|
||||||
|
local half; /* upper half of newval */
|
||||||
|
local newhalf; /* half+1 */
|
||||||
|
local newpal; /* new palindrome */
|
||||||
|
|
||||||
|
/* case: negative palindrome */
|
||||||
|
if (pal < 0) {
|
||||||
|
return -(palprevpal(-pal));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* start with upper half
|
||||||
|
*/
|
||||||
|
half = upperhalf(pal);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prep to find a larger palindrome
|
||||||
|
*/
|
||||||
|
newhalf = half+1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* form palindrome from new upper half
|
||||||
|
*
|
||||||
|
* We need to watch for the corner case where changing the
|
||||||
|
* half changes the number of digits as this will impact
|
||||||
|
* or even/odd number of digits processing.
|
||||||
|
*/
|
||||||
|
paldigits = digits(pal);
|
||||||
|
if (digits(newhalf) == digits(half)) {
|
||||||
|
/* no change in half digits: process as normal */
|
||||||
|
if (iseven(paldigits)) {
|
||||||
|
newpal = mkpal(newhalf);
|
||||||
|
} else {
|
||||||
|
newpal = mkpalmiddigit(newhalf // 10, newhalf % 10);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* change in half digits: process as opposite */
|
||||||
|
if (iseven(paldigits)) {
|
||||||
|
newpal = mkpalmiddigit(newhalf // 10, newhalf % 10);
|
||||||
|
} else {
|
||||||
|
newpal = mkpal(newhalf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the new palindrome
|
||||||
|
*/
|
||||||
|
return newpal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nextpal - return next palindrome from a value
|
||||||
|
*
|
||||||
|
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||||
|
*
|
||||||
|
* given:
|
||||||
|
* val a value
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* next palindrome > val
|
||||||
|
*/
|
||||||
|
define nextpal(val)
|
||||||
|
{
|
||||||
|
local newval; /* val+1 */
|
||||||
|
local newvaldigits; /* digits in newval */
|
||||||
|
local half; /* upper half of newval */
|
||||||
|
local pal; /* palindrome test value */
|
||||||
|
local newpal; /* new palindrome */
|
||||||
|
|
||||||
|
/* case: negative value */
|
||||||
|
if (val < 0) {
|
||||||
|
return -(prevpal(-val));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* start looking from a larger value
|
||||||
|
*/
|
||||||
|
newval = val+1;
|
||||||
|
newvaldigits = digits(newval);
|
||||||
|
|
||||||
|
/* case: single digit palindrome */
|
||||||
|
if (newvaldigits < 2) {
|
||||||
|
return newval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* start with next upper half
|
||||||
|
*/
|
||||||
|
half = upperhalf(newval);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* form palindrome from upper half
|
||||||
|
*
|
||||||
|
* We need to deal with even vs. odd digit counts
|
||||||
|
* when forming a palindrome from a half as the
|
||||||
|
* half may not or may include the middle digit.
|
||||||
|
*/
|
||||||
|
if (iseven(newvaldigits)) {
|
||||||
|
pal = mkpal(half);
|
||||||
|
} else {
|
||||||
|
pal = mkpalmiddigit(half // 10, half % 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* case: we found a larger palindrome, we are done
|
||||||
|
*/
|
||||||
|
if (pal > val) {
|
||||||
|
return pal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* we need to find an even larger palindrome
|
||||||
|
*/
|
||||||
|
newpal = palnextpal(pal);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the new palindrome
|
||||||
|
*/
|
||||||
|
return newpal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* palprevpal - return previous palindrome from a palindrome
|
||||||
|
*
|
||||||
|
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||||
|
*
|
||||||
|
* given:
|
||||||
|
* pal a palindrome
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* previous palindrome < pal
|
||||||
|
*/
|
||||||
|
define palprevpal(pal)
|
||||||
|
{
|
||||||
|
local paldigits; /* digits in pal */
|
||||||
|
local half; /* upper half of newval */
|
||||||
|
local newhalf; /* half+1 */
|
||||||
|
local newpal; /* new palindrome */
|
||||||
|
|
||||||
|
/* case: negative value */
|
||||||
|
if (pal < 0) {
|
||||||
|
return -(palnextpal(-pal));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* case: single digit palindrome */
|
||||||
|
if (pal < 10) {
|
||||||
|
newpal = pal-1;
|
||||||
|
return newpal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* case: 10 or 11 */
|
||||||
|
if (pal < 12) {
|
||||||
|
newpal = 9;
|
||||||
|
return newpal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* start with upper half
|
||||||
|
*/
|
||||||
|
half = upperhalf(pal);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prep to find a smaller palindrome
|
||||||
|
*/
|
||||||
|
newhalf = half-1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* form palindrome from new upper half
|
||||||
|
*
|
||||||
|
* We need to watch for the corner case where changing the
|
||||||
|
* half changes the number of digits as this will impact
|
||||||
|
* or even/odd number of digits processing.
|
||||||
|
*/
|
||||||
|
paldigits = digits(pal);
|
||||||
|
if (digits(newhalf) == digits(half)) {
|
||||||
|
/* no change in half digits: process as normal */
|
||||||
|
if (iseven(paldigits)) {
|
||||||
|
newpal = mkpal(newhalf);
|
||||||
|
} else {
|
||||||
|
newpal = mkpalmiddigit(newhalf // 10, newhalf % 10);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* change in half digits: process as opposite */
|
||||||
|
if (iseven(paldigits)) {
|
||||||
|
newpal = mkpalmiddigit(newhalf // 10, newhalf % 10);
|
||||||
|
} else {
|
||||||
|
newpal = mkpal(newhalf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the new palindrome
|
||||||
|
*/
|
||||||
|
return newpal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prevpal - return previous palindrome from a value
|
||||||
|
*
|
||||||
|
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||||
|
*
|
||||||
|
* given:
|
||||||
|
* val a value
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* previous palindrome < val
|
||||||
|
*/
|
||||||
|
define prevpal(val)
|
||||||
|
{
|
||||||
|
local newval; /* val-1 */
|
||||||
|
local newvaldigits; /* digits in newval */
|
||||||
|
local half; /* upper half of newval */
|
||||||
|
local pal; /* palindrome test value */
|
||||||
|
local newpal; /* new palindrome */
|
||||||
|
|
||||||
|
/* case: negative value */
|
||||||
|
if (val < 0) {
|
||||||
|
return -(nextpal(-val));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* start looking from a smaller value
|
||||||
|
*/
|
||||||
|
newval = val-1;
|
||||||
|
newvaldigits = digits(newval);
|
||||||
|
|
||||||
|
/* case: single digit palindrome */
|
||||||
|
if (newvaldigits < 2) {
|
||||||
|
return newval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* start with previous upper half
|
||||||
|
*/
|
||||||
|
half = upperhalf(newval);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* form palindrome from upper half
|
||||||
|
*
|
||||||
|
* We need to deal with even vs. odd digit counts
|
||||||
|
* when forming a palindrome from a half as the
|
||||||
|
* half may not or may include the middle digit.
|
||||||
|
*/
|
||||||
|
if (iseven(newvaldigits)) {
|
||||||
|
pal = mkpal(half);
|
||||||
|
} else {
|
||||||
|
pal = mkpalmiddigit(half // 10, half % 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* case: we found a smaller palindrome, we are done
|
||||||
|
*/
|
||||||
|
if (pal < val) {
|
||||||
|
return pal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* we need to find an even smaller palindrome
|
||||||
|
*/
|
||||||
|
newpal = palprevpal(pal);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the new palindrome
|
||||||
|
*/
|
||||||
|
return newpal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nextprimepal - return next palindrome that is a (highly probable) prime
|
||||||
|
*
|
||||||
|
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||||
|
*
|
||||||
|
* given:
|
||||||
|
* val a value
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* next palindrome (highly probable) prime > val
|
||||||
|
*/
|
||||||
|
define nextprimepal(val)
|
||||||
|
{
|
||||||
|
local pal; /* palindrome test value */
|
||||||
|
local dpal; /* digits in pal */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pre-start under the next palindrome
|
||||||
|
*/
|
||||||
|
pal = nextpal(val-1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* loop until we find a (highly probable) prime or 0
|
||||||
|
*/
|
||||||
|
do {
|
||||||
|
|
||||||
|
/* case: negative values and tiny values */
|
||||||
|
if (pal < 2) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* compute the next palindrome
|
||||||
|
*/
|
||||||
|
pal = palnextpal(pal);
|
||||||
|
dpal = digits(pal);
|
||||||
|
|
||||||
|
/* case: 11 is the only prime palindrome with even digit count */
|
||||||
|
if (pal == 11) {
|
||||||
|
return 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* case: even number of digits and not 11 */
|
||||||
|
if (iseven(dpal)) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Except for 11 (which is handled above already), there are
|
||||||
|
* no prime palindrome with even digits. So we need to
|
||||||
|
* increase the digit count and work with that larger palindrome.
|
||||||
|
*/
|
||||||
|
pal = nextpal(10^dpal);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* case: palindrome is even or ends in 5 */
|
||||||
|
if (iseven(pal % 10) || (pal%10 == 10/2)) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* we need to increase the bottom and top digits
|
||||||
|
* so that we have a chance to be prime
|
||||||
|
*/
|
||||||
|
pal += (1 + 10^(dpal-1));
|
||||||
|
}
|
||||||
|
if (config("resource_debug") & 0x8) {
|
||||||
|
print "DEBUG: nextprimepal:", pal;
|
||||||
|
}
|
||||||
|
} while (ptest(pal) == 0 && pal > 0);
|
||||||
|
|
||||||
|
/* return palindrome that his (highly probable) prime or 0 */
|
||||||
|
return pal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prevprimepal - return prev palindrome that is a (highly probable) prime
|
||||||
|
*
|
||||||
|
* NOTE: We assume base 10 digits and place 1 is the units digit.
|
||||||
|
*
|
||||||
|
* given:
|
||||||
|
* val a value
|
||||||
|
*
|
||||||
|
* returns:
|
||||||
|
* prev palindrome (highly probable) prime < val or 0
|
||||||
|
*/
|
||||||
|
define prevprimepal(val)
|
||||||
|
{
|
||||||
|
local pal; /* palindrome test value */
|
||||||
|
local dpal; /* digits in pal */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pre-start over the previous palindrome
|
||||||
|
*/
|
||||||
|
pal = prevpal(val+1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* loop until we find a (highly probable) prime or 0
|
||||||
|
*/
|
||||||
|
do {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* case: single digit values are always palindromes
|
||||||
|
*/
|
||||||
|
if (val < 10) {
|
||||||
|
/*
|
||||||
|
* The prevcand() call will return 0 if there is no previous prime
|
||||||
|
* such as the case when val < 2.
|
||||||
|
*/
|
||||||
|
return prevcand(pal);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* compute the previous palindrome
|
||||||
|
*/
|
||||||
|
pal = palprevpal(pal);
|
||||||
|
dpal = digits(pal);
|
||||||
|
|
||||||
|
/* case: 11 is the only prime palindrome with even digit count */
|
||||||
|
if (pal == 11) {
|
||||||
|
return 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* case: 2 digit palindrome and not 11 */
|
||||||
|
if (dpal == 2) {
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* case: even number of digits */
|
||||||
|
if (iseven(dpal)) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Except for 11 (which is handled above already), there are
|
||||||
|
* no prime palindrome with even digits. So we need to
|
||||||
|
* decrease the digit count and work with that smaller palindrome.
|
||||||
|
*/
|
||||||
|
pal = prevpal(10^(dpal-1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* case: palindrome is even or ends in 5 */
|
||||||
|
if (iseven(pal % 10) || (pal%10 == 10/2)) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* we need to decrease the bottom and top digits
|
||||||
|
* so that we have a chance to be prime
|
||||||
|
*/
|
||||||
|
pal -= (1 + 10^(dpal-1));
|
||||||
|
}
|
||||||
|
if (config("resource_debug") & 0x8) {
|
||||||
|
print "DEBUG: prevprimepal:", pal;
|
||||||
|
}
|
||||||
|
} while (ptest(pal) == 0 && pal > 0);
|
||||||
|
|
||||||
|
/* return palindrome that his (highly probable) prime or 0 */
|
||||||
|
return pal;
|
||||||
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* pell - solve Pell's equation
|
* pell - solve Pell's equation
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 David I. Bell
|
* Copyright (C) 1999,2021 David I. Bell
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: pell.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/pell.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1990/02/15 01:50:34
|
* Under source code control: 1990/02/15 01:50:34
|
||||||
* File existed as early as: before 1990
|
* File existed as early as: before 1990
|
||||||
*
|
*
|
||||||
@@ -29,7 +25,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Solve Pell's equation; Returns the solution X to: X^2 - D * Y^2 = 1.
|
* Solve Pell's equation; Returns the solution X to: X^2 - D * Y^2 = 1.
|
||||||
* Type the solution to pells equation for a particular D.
|
* Type the solution to Pell's equation for a particular D.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* pi - various routines to calculate pi
|
* pi - various routines to calculate pi
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2004 David I. Bell
|
* Copyright (C) 1999-2004,2021 David I. Bell
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: pi.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/pi.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1991/05/22 21:56:37
|
* Under source code control: 1991/05/22 21:56:37
|
||||||
* File existed as early as: 1991
|
* File existed as early as: 1991
|
||||||
*
|
*
|
||||||
@@ -78,7 +74,7 @@ define qpi(epsilon)
|
|||||||
/*
|
/*
|
||||||
* Print digits of PI forever, neatly formatted, using calc.
|
* Print digits of PI forever, neatly formatted, using calc.
|
||||||
*
|
*
|
||||||
* Written by Klaus Alexander Seistrup <klaus@seistrup.dk>
|
* Written by Klaus Alexander Seistrup <klaus at seistrup dot dk>
|
||||||
* on a dull Friday evening in November 1999.
|
* on a dull Friday evening in November 1999.
|
||||||
*
|
*
|
||||||
* Inspired by an algorithm conceived by Lambert Meertens.
|
* Inspired by an algorithm conceived by Lambert Meertens.
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: pix.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/pix.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1996/07/09 03:14:14
|
* Under source code control: 1996/07/09 03:14:14
|
||||||
* File existed as early as: 1996
|
* File existed as early as: 1996
|
||||||
*
|
*
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: pollard.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/pollard.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1991/05/22 21:56:37
|
* Under source code control: 1991/05/22 21:56:37
|
||||||
* File existed as early as: 1991
|
* File existed as early as: 1991
|
||||||
*
|
*
|
||||||
|
10
cal/poly.cal
10
cal/poly.cal
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* poly - calculate with polynomials of one variable
|
* poly - calculate with polynomials of one variable
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 Ernest Bowen
|
* Copyright (C) 1999,2021 Ernest Bowen
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: poly.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/poly.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1990/02/15 01:50:35
|
* Under source code control: 1990/02/15 01:50:35
|
||||||
* File existed as early as: before 1990
|
* File existed as early as: before 1990
|
||||||
*
|
*
|
||||||
@@ -39,7 +35,7 @@
|
|||||||
* variable has only one name. For some purposes, a name like
|
* variable has only one name. For some purposes, a name like
|
||||||
* "sin(t)" or "(a + b)" or "\lambda" might be useful;
|
* "sin(t)" or "(a + b)" or "\lambda" might be useful;
|
||||||
* names like "*" or "-27" are legal but might give expressions
|
* names like "*" or "-27" are legal but might give expressions
|
||||||
* that are difficult to intepret.
|
* that are difficult to interpret.
|
||||||
*
|
*
|
||||||
* Polynomial expressions may be constructed from numbers and the
|
* Polynomial expressions may be constructed from numbers and the
|
||||||
* independent variable and other polynomials by the algebraic
|
* independent variable and other polynomials by the algebraic
|
||||||
@@ -47,7 +43,7 @@
|
|||||||
* The operations // and % are defined to have the quotient and
|
* The operations // and % are defined to have the quotient and
|
||||||
* remainder meanings as usually defined for polynomials.
|
* remainder meanings as usually defined for polynomials.
|
||||||
*
|
*
|
||||||
* When polynomials are assigned to idenfifiers, it is convenient to
|
* When polynomials are assigned to identifiers, it is convenient to
|
||||||
* think of the polynomials as values. For example, p = (x - 1)^2
|
* think of the polynomials as values. For example, p = (x - 1)^2
|
||||||
* assigns to p a polynomial value in the same way as q = (7 - 1)^2
|
* assigns to p a polynomial value in the same way as q = (7 - 1)^2
|
||||||
* would assign to q a number value. As with number expressions
|
* would assign to q a number value. As with number expressions
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* prompt - eemonstration of some uses of prompt() and eval()
|
* prompt - demonstration of some uses of prompt() and eval()
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 Ernest Bowen
|
* Copyright (C) 1999,2021 Ernest Bowen
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: prompt.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/prompt.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1995/12/18 04:43:25
|
* Under source code control: 1995/12/18 04:43:25
|
||||||
* File existed as early as: 1995
|
* File existed as early as: 1995
|
||||||
*
|
*
|
||||||
@@ -65,9 +61,9 @@
|
|||||||
* nothing to sum. The last line returns the value 3, i.e. the last
|
* nothing to sum. The last line returns the value 3, i.e. the last
|
||||||
* non-null value found for the expressions separated by semicolons,
|
* non-null value found for the expressions separated by semicolons,
|
||||||
* so sum will be increased by 3 after the "print sum^2;" command
|
* so sum will be increased by 3 after the "print sum^2;" command
|
||||||
* is executed. xxx The terminating semicolon is essential in the
|
* is executed. XXX The terminating semicolon is essential in the
|
||||||
* last two lines. A command like eval("print 7;") is acceptable to
|
* last two lines. A command like eval("print 7;") is acceptable to
|
||||||
* calc but eval("print 7") causes an exit from calc. xxx)
|
* calc but eval("print 7") causes an exit from calc. XXX)
|
||||||
*
|
*
|
||||||
* If the value returned is not a number (e.g. the name of a list or matrix,
|
* If the value returned is not a number (e.g. the name of a list or matrix,
|
||||||
* or if the string has syntax errors as in "2 + ", in which case the
|
* or if the string has syntax errors as in "2 + ", in which case the
|
||||||
@@ -79,7 +75,7 @@
|
|||||||
* "sin(x)", "x^2 + 3*x", "exp(x, 1e-5)".
|
* "sin(x)", "x^2 + 3*x", "exp(x, 1e-5)".
|
||||||
*
|
*
|
||||||
* Values of the function so defined are returned for values of x
|
* Values of the function so defined are returned for values of x
|
||||||
* entered in reponse to the ? prompt. Operation is terminated by
|
* entered in response to the ? prompt. Operation is terminated by
|
||||||
* entering "end", "exit" or "quit".
|
* entering "end", "exit" or "quit".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: psqrt.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/psqrt.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1990/02/15 01:50:35
|
* Under source code control: 1990/02/15 01:50:35
|
||||||
* File existed as early as: before 1990
|
* File existed as early as: before 1990
|
||||||
*
|
*
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* qtime - Display time as English sentence
|
* qtime - Display time as English sentence
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 Klaus Alexander Seistrup and Landon Curt Noll
|
* Copyright (C) 1999,2021 Klaus Alexander Seistrup and Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Written by: Klaus Alexander Seistrup <kseis@magnetic-ink.dk>
|
* Written by: Klaus Alexander Seistrup <kseis at magnetic-ink dot dk>
|
||||||
* With mods by: Landon Curt Noll <http://www.isthe.com/chongo/>
|
* With mods by: Landon Curt Noll <http://www.isthe.com/chongo/>
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* Calc is open software; you can redistribute it and/or modify it under
|
||||||
@@ -20,10 +20,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: qtime.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/qtime.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1999/10/13 04:10:33
|
* Under source code control: 1999/10/13 04:10:33
|
||||||
* File existed as early as: 1999
|
* File existed as early as: 1999
|
||||||
*
|
*
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* quat - alculate using quaternions of the form: a + bi + cj + dk
|
* quat - calculate using quaternions of the form: a + bi + cj + dk
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 David I. Bell
|
* Copyright (C) 1999,2021 David I. Bell
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.2 $
|
|
||||||
* @(#) $Id: quat.cal,v 30.2 2013/08/11 08:41:38 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/quat.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1990/02/15 01:50:35
|
* Under source code control: 1990/02/15 01:50:35
|
||||||
* File existed as early as: before 1990
|
* File existed as early as: before 1990
|
||||||
*
|
*
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: randbitrun.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/randbitrun.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1995/02/13 03:43:11
|
* Under source code control: 1995/02/13 03:43:11
|
||||||
* File existed as early as: 1995
|
* File existed as early as: 1995
|
||||||
*
|
*
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* randmprime - generate a random prime of the form h*2^n-1
|
* randmprime - generate a random prime of the form h*2^n-1
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 Landon Curt Noll
|
* Copyright (C) 1999,2021 Landon Curt Noll
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: randmprime.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/randmprime.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1994/03/14 23:11:21
|
* Under source code control: 1994/03/14 23:11:21
|
||||||
* File existed as early as: 1994
|
* File existed as early as: 1994
|
||||||
*
|
*
|
||||||
@@ -49,9 +45,9 @@ randmprime(bits, seed, dbg)
|
|||||||
local n; /* n as in h*2^n-1 */
|
local n; /* n as in h*2^n-1 */
|
||||||
local h; /* h as in h*2^n-1 */
|
local h; /* h as in h*2^n-1 */
|
||||||
local plush; /* value added to h since the beginning */
|
local plush; /* value added to h since the beginning */
|
||||||
local init; /* initial cpu time */
|
local init; /* initial CPU time */
|
||||||
local start; /* cpu time before last test */
|
local start; /* CPU time before last test */
|
||||||
local stop; /* cpu time afte last test */
|
local stop; /* CPU time after last test */
|
||||||
local tmp; /* just a tmp place holder value */
|
local tmp; /* just a tmp place holder value */
|
||||||
local ret; /* h*2^n-1 that is prime */
|
local ret; /* h*2^n-1 that is prime */
|
||||||
|
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: randombitrun.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/randombitrun.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1995/02/13 03:43:11
|
* Under source code control: 1995/02/13 03:43:11
|
||||||
* File existed as early as: 1995
|
* File existed as early as: 1995
|
||||||
*
|
*
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: randomrun.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/randomrun.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1997/02/19 03:35:59
|
* Under source code control: 1997/02/19 03:35:59
|
||||||
* File existed as early as: 1997
|
* File existed as early as: 1997
|
||||||
*
|
*
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: randrun.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/randrun.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1995/02/12 20:00:06
|
* Under source code control: 1995/02/12 20:00:06
|
||||||
* File existed as early as: 1995
|
* File existed as early as: 1995
|
||||||
*
|
*
|
||||||
|
948
cal/regress.cal
948
cal/regress.cal
File diff suppressed because it is too large
Load Diff
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: repeat.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/repeat.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2003/01/05 00:00:01
|
* Under source code control: 2003/01/05 00:00:01
|
||||||
* File existed as early as: 2003
|
* File existed as early as: 2003
|
||||||
*
|
*
|
||||||
|
@@ -3,23 +3,37 @@
|
|||||||
*
|
*
|
||||||
* This file was created by Ernest Bowen <ebowen at une dot edu dot au>.
|
* 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.
|
|
||||||
*
|
|
||||||
* @(#) $Revision: 30.2 $
|
|
||||||
* @(#) $Id: screen.cal,v 30.2 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/screen.cal,v $
|
|
||||||
*
|
|
||||||
* This file is not covered under version 2.1 of the GNU LGPL.
|
* 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
|
* Under source code control: 2006/03/08 05:54:09
|
||||||
* File existed as early as: 2006
|
* File existed as early as: 2006
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: seedrandom.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/seedrandom.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1996/01/01 08:21:00
|
* Under source code control: 1996/01/01 08:21:00
|
||||||
* File existed as early as: 1996
|
* File existed as early as: 1996
|
||||||
*
|
*
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: set8700.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/set8700.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2006/05/20 14:10:11
|
* Under source code control: 2006/05/20 14:10:11
|
||||||
* File existed as early as: 2006
|
* File existed as early as: 2006
|
||||||
*
|
*
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
##
|
##
|
||||||
## set8700 - dotest line tests for the 8700 set of regress.cal
|
## set8700 - dotest line tests for the 8700 set of regress.cal
|
||||||
##
|
##
|
||||||
## Copyright (C) 2006 Ernest Bowen and Landon Curt Noll
|
## Copyright (C) 2006,2021 Ernest Bowen and Landon Curt Noll
|
||||||
##
|
##
|
||||||
## Calc is open software; you can redistribute it and/or modify it under
|
## 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
|
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
##
|
##
|
||||||
## @(#) $Revision: 30.1 $
|
|
||||||
## @(#) $Id: set8700.line,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
## @(#) $Source: /usr/local/src/bin/calc/cal/RCS/set8700.line,v $
|
|
||||||
##
|
|
||||||
## Under source code control: 2006/05/20 14:10:11
|
## Under source code control: 2006/05/20 14:10:11
|
||||||
## File existed as early as: 2006
|
## File existed as early as: 2006
|
||||||
##
|
##
|
||||||
@@ -163,7 +159,7 @@ set8700_A = 42, protect(set8700_A,1024), set8700_B = set8700_A, protect(set8700_
|
|||||||
set8700_A = 6 * 7, protect(set8700_A) == 1024
|
set8700_A = 6 * 7, protect(set8700_A) == 1024
|
||||||
set8700_A == set8700_B
|
set8700_A == set8700_B
|
||||||
|
|
||||||
## Testing matrix protectioon
|
## Testing matrix protection
|
||||||
set8700_A = mat [3] = {1, 2, list(3,4)}; 1
|
set8700_A = mat [3] = {1, 2, list(3,4)}; 1
|
||||||
protect(set8700_A, 65, 1), protect(set8700_A) == 1089
|
protect(set8700_A, 65, 1), protect(set8700_A) == 1089
|
||||||
protect(set8700_A[0]) == 65
|
protect(set8700_A[0]) == 65
|
||||||
@@ -265,7 +261,7 @@ protect(set8700_L[0]) == 0
|
|||||||
protect(set8700_L[1]) == 512 ## protect(set8700_A) copied
|
protect(set8700_L[1]) == 512 ## protect(set8700_A) copied
|
||||||
protect(set8700_L[1][1]) == 1024 ## protect(set8700_A[1]) copied
|
protect(set8700_L[1][1]) == 1024 ## protect(set8700_A[1]) copied
|
||||||
|
|
||||||
## Testing list with "intialization"
|
## Testing list with "initialization"
|
||||||
set8700_L = list(1,2,3), protect(set8700_L) == 0
|
set8700_L = list(1,2,3), protect(set8700_L) == 0
|
||||||
protect(set8700_L[0]) | protect(set8700_L[1]) | protect(set8700_L[2]) == 0 ## All zero
|
protect(set8700_L[0]) | protect(set8700_L[1]) | protect(set8700_L[2]) == 0 ## All zero
|
||||||
set8700_L = {1,set8700_A}, set8700_L[1] == set8700_A
|
set8700_L = {1,set8700_A}, set8700_L[1] == set8700_A
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.3 $
|
|
||||||
* @(#) $Id: solve.cal,v 30.3 2013/08/11 08:41:38 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/solve.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1990/02/15 01:50:37
|
* Under source code control: 1990/02/15 01:50:37
|
||||||
* File existed as early as: before 1990
|
* File existed as early as: before 1990
|
||||||
*
|
*
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* specialfunctions - special functions (e.g.: gamma, zeta, psi)
|
* specialfunctions - special functions (e.g.: gamma, zeta, psi)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Christoph Zurnieden
|
* Copyright (C) 2013,2021 Christoph Zurnieden
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the version 2.1 of the GNU Lesser General Public
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.6 $
|
|
||||||
* @(#) $Id: specialfunctions.cal,v 30.6 2013/09/01 17:48:27 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/specialfunctions.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2013/08/11 01:31:28
|
* Under source code control: 2013/08/11 01:31:28
|
||||||
* File existed as early as: 2013
|
* File existed as early as: 2013
|
||||||
*/
|
*/
|
||||||
@@ -446,8 +442,8 @@ define lngamma(z)
|
|||||||
if (tmp2 < tmp) {
|
if (tmp2 < tmp) {
|
||||||
return
|
return
|
||||||
newerror(strcat
|
newerror(strcat
|
||||||
("lngamma(1): something happend that ",
|
("lngamma(1): something happened ",
|
||||||
"should not have happend"));
|
"that shouldn't have happened"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -523,8 +519,8 @@ define lngamma(z)
|
|||||||
if (tmp2 < tmp) {
|
if (tmp2 < tmp) {
|
||||||
return
|
return
|
||||||
newerror(strcat
|
newerror(strcat
|
||||||
("lngamma(1): something happend ",
|
("lngamma(1): something happened ",
|
||||||
"that should not have happend"));
|
"that should not have happened"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -580,8 +576,8 @@ define lngamma(z)
|
|||||||
if (tmp2 < tmp) {
|
if (tmp2 < tmp) {
|
||||||
return
|
return
|
||||||
newerror(strcat
|
newerror(strcat
|
||||||
("lngamma(1): something happend ",
|
("lngamma(1): something happened ",
|
||||||
"that should not have happend"));
|
"that should not have happened"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1051,7 +1047,7 @@ define __CZ__ibeta_cf_var_dm(a, b, z, max)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m > max) {
|
if (m > max) {
|
||||||
return newerror("ibeta: continous fraction does not converge");
|
return newerror("ibeta: continuous fraction does not converge");
|
||||||
}
|
}
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
@@ -1294,7 +1290,7 @@ define __CZ__erfinvapprox(x)
|
|||||||
- (2 / (pi() * a) + (ln(1 - x ^ 2)) / 2));
|
- (2 / (pi() * a) + (ln(1 - x ^ 2)) / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* complementary inverse errror function, faster at about x < 1-.91
|
/* complementary inverse error function, faster at about x < 1-.91
|
||||||
Henry E. Fettis. "A stable algorithm for computing the inverse error function
|
Henry E. Fettis. "A stable algorithm for computing the inverse error function
|
||||||
in the 'tail-end' region" Math. Comp., 28:585-587, 1974.
|
in the 'tail-end' region" Math. Comp., 28:585-587, 1974.
|
||||||
*/
|
*/
|
||||||
@@ -1328,7 +1324,7 @@ define __CZ__fettiscf(y, n)
|
|||||||
return t / (1 + r);
|
return t / (1 + r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* inverse errror function, faster at about x<=.91*/
|
/* inverse error function, faster at about x<=.91*/
|
||||||
define __CZ__inverfbin(x)
|
define __CZ__inverfbin(x)
|
||||||
{
|
{
|
||||||
local places approx flow fhigh eps high low mid fmid epsilon;
|
local places approx flow fhigh eps high low mid fmid epsilon;
|
||||||
@@ -1374,7 +1370,7 @@ define erfinv(x)
|
|||||||
x = -x;
|
x = -x;
|
||||||
flag = 1;
|
flag = 1;
|
||||||
}
|
}
|
||||||
/* No need for full pecision */
|
/* No need for full precision */
|
||||||
eps = epsilon(1e-20);
|
eps = epsilon(1e-20);
|
||||||
if (eps >= 1e-40) {
|
if (eps >= 1e-40) {
|
||||||
/* Winitzki, Sergei (6 February 2008). "A handy approximation for the
|
/* Winitzki, Sergei (6 February 2008). "A handy approximation for the
|
||||||
|
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;
|
||||||
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* statistics - Some assorted statistics functions.
|
* statistics - Some assorted statistics functions.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Christoph Zurnieden
|
* Copyright (C) 2013,2021 Christoph Zurnieden
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.4 $
|
|
||||||
* @(#) $Id: statistics.cal,v 30.4 2013/08/18 20:01:53 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/statistics.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2013/08/11 01:31:28
|
* Under source code control: 2013/08/11 01:31:28
|
||||||
* File existed as early as: 2013
|
* File existed as early as: 2013
|
||||||
*/
|
*/
|
||||||
@@ -110,7 +106,7 @@ define invbetainc_slow(x,a,b){
|
|||||||
GW Cran, KJ Martin, GE Thomas,
|
GW Cran, KJ Martin, GE Thomas,
|
||||||
Remark AS R19 and Algorithm AS 109:
|
Remark AS R19 and Algorithm AS 109:
|
||||||
A Remark on Algorithms AS 63: The Incomplete Beta Integral
|
A Remark on Algorithms AS 63: The Incomplete Beta Integral
|
||||||
and AS 64: Inverse of the Incomplete Beta Integeral,
|
and AS 64: Inverse of the Incomplete Beta integral,
|
||||||
Applied Statistics,
|
Applied Statistics,
|
||||||
Volume 26, Number 1, 1977, pages 111-114.
|
Volume 26, Number 1, 1977, pages 111-114.
|
||||||
|
|
||||||
@@ -375,7 +371,7 @@ define normalcdf(x,mu,sigma){
|
|||||||
|
|
||||||
define probit(p){
|
define probit(p){
|
||||||
if(p<0 || p > 1) return newerror("probit: p out of domain 0<=p<=1");
|
if(p<0 || p > 1) return newerror("probit: p out of domain 0<=p<=1");
|
||||||
return sqrt(2)*ervinv(2*p-1);
|
return sqrt(2)*erfinv(2*p-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
define normalcdfinv(p,mu,sigma){
|
define normalcdfinv(p,mu,sigma){
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: sumsq.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/sumsq.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1990/02/15 01:50:37
|
* Under source code control: 1990/02/15 01:50:37
|
||||||
* File existed as early as: before 1990
|
* File existed as early as: before 1990
|
||||||
*
|
*
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* sumtimes - runtimes evaluating sums & squares of large lists and mats
|
* sumtimes - runtime evaluating sums & squares of large lists and mats
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006 Ernest Bowen
|
* Copyright (C) 2006,2021 Ernest Bowen
|
||||||
*
|
*
|
||||||
* Calc is open software; you can redistribute it and/or modify it under
|
* 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
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: sumtimes.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/sumtimes.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 2006/06/22 17:29
|
* Under source code control: 2006/06/22 17:29
|
||||||
* File existed as early as: 2006
|
* File existed as early as: 2006
|
||||||
*
|
*
|
||||||
@@ -164,7 +160,7 @@ define timehmean(N, M = 10) {
|
|||||||
v2 = hmean(sumtimes_A);
|
v2 = hmean(sumtimes_A);
|
||||||
sumtimes_t2 = usertime();
|
sumtimes_t2 = usertime();
|
||||||
print v1, v2;
|
print v1, v2;
|
||||||
print "List harmonic meanruntimes";
|
print "List harmonic mean runtimes";
|
||||||
printf('\tStandard "for" loop:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
|
printf('\tStandard "for" loop:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
|
||||||
printf('\tUsing builtin "hmean":\t\t%.4f\n', sumtimes_t2 - sumtimes_t1);
|
printf('\tUsing builtin "hmean":\t\t%.4f\n', sumtimes_t2 - sumtimes_t1);
|
||||||
}
|
}
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: surd.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/surd.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1990/02/15 01:50:38
|
* Under source code control: 1990/02/15 01:50:38
|
||||||
* File existed as early as: before 1990
|
* File existed as early as: before 1990
|
||||||
*
|
*
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: test1700.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/test1700.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1994/03/14 23:12:51
|
* Under source code control: 1994/03/14 23:12:51
|
||||||
* File existed as early as: 1994
|
* File existed as early as: 1994
|
||||||
*
|
*
|
||||||
|
@@ -17,10 +17,6 @@
|
|||||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
* @(#) $Revision: 30.1 $
|
|
||||||
* @(#) $Id: test2300.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
|
|
||||||
* @(#) $Source: /usr/local/src/bin/calc/cal/RCS/test2300.cal,v $
|
|
||||||
*
|
|
||||||
* Under source code control: 1995/07/09 06:12:13
|
* Under source code control: 1995/07/09 06:12:13
|
||||||
* File existed as early as: 1995
|
* File existed as early as: 1995
|
||||||
*
|
*
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user