Compare commits

..

246 Commits

Author SHA1 Message Date
Landon Curt Noll
741ea46853 Release v2.14.1.0
The following are the changes from calc version 2.14.1.0 to date:

    Fixed alignment of show item section of help command.

    Bug fix: While 0^0 == 1, now for y > 0, 0^y == 0.
    Adjusted cal/test8900.cal to reflect this bug fix.
    Added tests to cal/regress.cal to help verify bug fix is fixed.
2022-04-08 00:02:44 -07:00
Landon Curt Noll
56b6613da8 Fixed 0^y for y > 0
While 0^0 == 1, now for y > 0, 0^y == 0.

Adjusted cal/test8900.cal to reflect the this bug fix.

Added tests to cal/regress.cal to help verify bug fix is fixed.
2022-04-07 23:54:06 -07:00
Landon Curt Noll
e9eef2dfa2 Merge branch 'master' of github.com:lcn2/calc 2022-04-07 23:44:38 -07:00
Landon Curt Noll
0dbf258696 Fixed alignment of show item section of help command 2022-04-07 23:44:05 -07:00
Landon Curt Noll
f6d558783a Improved security issue template
create a calc GitHub repo issue for a security issue
2022-02-24 13:58:56 -08:00
Landon Curt Noll
6f27a32f79 Calc bug report template version: 1.2 2022-02-24
Added template version and made a minor edit
2022-02-24 12:42:32 -08:00
Landon Curt Noll
d58f605866 Update issue templates
Updated calc Bug report
2022-02-24 12:30:36 -08:00
Landon Curt Noll
b83c5be515 Update issue templates
Add default GitHub Bug and Feature templates
2022-02-15 13:35:46 -08:00
Landon Curt Noll
561928a45c Checkpint disbale use of gettime() under _WIN32 or _WIN64 2022-02-12 13:52:06 -08:00
Landon Curt Noll
7f89af37f5 Checkpoint more Windows 11 Cygwin MINGW64 changes 2022-02-12 13:41:16 -08:00
Landon Curt Noll
4470f1f62e Checkpoint - Windows 11 with Cygwin and MinGW64 packages. 2022-02-12 12:44:32 -08:00
Landon Curt Noll
8217c49b94 Fix lack of quotes in PASSDOWN variables 2022-02-12 11:37:53 -08:00
Landon Curt Noll
d2cb03b4cc Add ${MSYS} to Makefile for Windows 11 MINGW64_NT users 2022-02-12 11:18:49 -08:00
Landon Curt Noll
80f13a4e45 Changed Makefiles as per make depend 2022-01-22 02:52:02 -08:00
Landon Curt Noll
1658343227 Changes to use attributes for noreturn and printf-like functions 2022-01-22 02:48:50 -08:00
Landon Curt Noll
3f177f2d81 Improved source code flow
Changed /*NOTREACHED*/ to not_reached(); and use "attribute.h".

Added .PHONY rule, just after all rule, to Makefiles.

Fixed an improper indentation issue.
2022-01-22 01:16:07 -08:00
Landon Curt Noll
dcd5a987af Added better examples of asan debugging use with gcc and clang 2022-01-13 11:11:32 -08:00
Landon Curt Noll
cb77888045 Expand certain table sizes, add comments to Makefile.local
Expanded the globalsymbol string table size: from 1024 to 65536.

    Expanded the how often to reallocate string table is performed:
    from 100 to 1024.

    Expanded the number env_pool elements to allocate at a time:
    from 10 to 256.

    Improve comments on Makefile.local and add a few more examples
    of how it might be used.
2022-01-02 18:01:21 -08:00
Landon Curt Noll
ce17b267be Minor changes to Makefile, HOWTO.INSTALL, CONTRIBUTING.md
Changed Makefile to set shell before setting the SHELL Makefile
    variable.

    Added text to HOWTO.INSTALL to help people with systems that
    lack the readline package.

    Trimmed long line in the CONTRIBUTING.md file.
2021-12-29 15:16:40 -08:00
Landon Curt Noll
738dd0334e Create CONTRIBUTING.md
Create initial CONTRIBUTING.md file.
2021-12-27 20:01:26 -08:00
Landon Curt Noll
7ba1dbdc65 Create CODE_OF_CONDUCT.md
Initial release of CODE_OF_CONDUCT.md
2021-12-27 19:56:02 -08:00
Landon Curt Noll
ee70c12481 Release v2.14.0.14
The following are the changes in this release:

    Fixed typo in Makefile.local comment.

    Established a tagging procedure for a production release.
    Production git tags will be of the form:

	prod-2.x.y.z
2021-12-27 19:10:56 -08:00
Landon Curt Noll
d4970d66ce Merge branch 'master' of github.com:lcn2/calc 2021-12-27 19:04:53 -08:00
Landon Curt Noll
c3ea3d28a4 Added 2.14.0.14 CHANGES 2021-12-27 19:04:08 -08:00
Landon Curt Noll
3fa34dabfe Fixed typo in comment for Makefile.local 2021-12-13 22:12:03 -08:00
Landon Curt Noll
ffd4422870 Release v2.14.0.13
We apologize for the calc v2.14.0.12 source tarball that was missing
critical files.  While the executable was well tested, our release
process was deficient.

We are improved our release process and added tests during the release
procedure to help verify that we are not regressing in to the
"v2.14.0.12 source tarball" issue, among other things.

Depending on how things do, you might is several releases come out over
a short period of time.  The core of calc isn't changing, so the calc
executable will be the same as we focus on the Makefiles, our release
procedure, and related documentation / help files.

Removed constructed help file that incorrectly added as a src file.

=-=

The following are the changes in this release:

    Made major changes to our release process in order to avoid
    missing critical files that happened in calc v2.4.0.12.

    Minor tweak to seed() builtin.  Updated help/srand and help/srandom.

    Moved Makefile.ship into Makefile.

    Removed custom/Makefile.head and custom/Makefile.tail.

    The custom/Makefile is now part of source and includes Makefile.
    In particular, custom/Makefile makes use of the 'middle' of
    the new top level Makefile where calc's top level Makefile
    variables are defined.

    Makefile.simple and custom/Makefile.simple are now part of the source
    and are constructed from Makefile and custom/Makefile respectively.
    The Makefile.simple and custom/Makefile.simple avoid using GNU
    conditionals. They may be used with older/classic make commands.

    Makefile.local will include comments about how to better use
    it. Between releases, Makefile.local at the top of the master branch
    will contain how we typically build calc and test calc (FYI: we
    normally enable things such as -Werror -Wextra -pedantic).  When we
    push out a release, Makefile.local will be stripped of non-comment
    lines.  Thus, releases of calc, and, released "calc*.src.rpm"
    files and the source tarballs, will have a Makefile.local with
    only comments.

    The "README.*" files and "HOWTO.INSTALL" file have been updated.

    By default, compiler warnings have been turned up.  The Makefile
    variable ${CCWARN} now defaults to:

	CCWARN= -Wall -Wextra -pedantic

    The previous level of compiler warnings can be easily restored by
    adding to Makefile.local:

	CCWARN:= -Wall

    The readline, history and ncurses libraries are now default.
    The Makefile variables ${USE_READLINE}, ${READLINE_LIB}, and
    ${READLINE_EXTRAS} now default to:

	USE_READLINE= -DUSE_READLINE
	READLINE_LIB= -lreadline
	READLINE_EXTRAS= -lhistory -lncurses

    The previous mode where readline, history and ncurses libraries
    were not compiled in by default can be easily restored by
    adding to Makefile.local:

	USE_READLINE:=
	READLINE_LIB:=
	READLINE_EXTRAS:=

    We have renamed "stable" as "production".
    We have renamed "unstable" as "tested".

    On the web site:

	http://www.isthe.com/chongo/src/calc/

    these files has been renamed:

	2.x.y.z_IS_LATEST_STABLE   ==> 2.x.y.z_IS_LATEST_PRODUCTION
	2.x.y.z_IS_LATEST_UNSTABLE ==> 2.x.y.z_IS_LATEST_TESTED

    The terms 'stable' and 'unstable' were both misleading and
    inaccurate.  For details see the new documention file:

	README.RELEASE

    See also the help command:

	; help release

    Fixed bug impacting how have_ustat.h was formed.

    Updated help/archive, BUGS, HOWTO.INSTALL to reflect GitHub use.
2021-12-13 17:41:35 -08:00
Landon Curt Noll
b5b2c3f812 Updated CHANGES to reflect recent commits 2021-12-13 17:00:01 -08:00
Landon Curt Noll
f7dadbf1f8 Improve how Makefiles are formed, updated related doc 2021-12-13 16:54:45 -08:00
Landon Curt Noll
22e123140c Fix to add missing Makefiles to distlist
The output of the distlist rule was used to form the source tarball.
2021-12-13 16:27:37 -08:00
Landon Curt Noll
1242700601 Fix how Makefile.simple and custom/Makefile.simple are formed 2021-12-13 16:11:38 -08:00
Landon Curt Noll
5b7dfeaf11 Release v2.14.0.13
We apologize for the calc v2.14.0.12 source tarball that was missing
critical files.  While the executable was well tested, our release
process was deficient.

We are improved our release process and added tests during the release
procedure to help verify that we are not regressing in to the "v2.14.0.12
source tarball" issue, among other things.

Depending on how things do, you might is several releases come out over
a short period of time.  The core of calc isn't changing, so the calc
executable will be the same as we focus on the Makefiles, our release
procedure, and related documentation / help files.

Removed constructed help file that incorrectly added as a src file.

=-=

The following are the changes in this release:

    Minor tweak to seed() builtin.  Updated help/srand and help/srandom.

    Moved Makefile.ship into Makefile.

    Removed custom/Makefile.head and custom/Makefile.tail.

    The custom/Makefile is now part of source and includes Makefile.
    In particular, custom/Makefile makes use of the 'middle' of
    the new top level Makefile where calc's top level Makefile
    variables are defined.

    Makefile.simple and custom/Makefile.simple are now part of the source
    and are constructed from Makefile and custom/Makefile respectively.
    The Makefile.simple and custom/Makefile.simple avoid using GNU
    conditionals. They may be used with older/classic make commands.

    Makefile.local will include comments about how to better use
    it. Between releases, Makefile.local at the top of the master branch
    will contain how we typically build calc and test calc (FYI: we
    normally enable things such as -Werror -Wextra -pedantic).  When we
    push out a release, Makefile.local will be stripped of non-comment
    lines.  Thus, releases of calc, and, released "calc*.src.rpm"
    files and the source tarballs, will have a Makefile.local with
    only comments.

    The "README.*" files and "HOWTO.INSTALL" file have been updated.

    By default, compiler warnings have been turned up.  The Makefile
    variable ${CCWARN} now defaults to:

	CCWARN= -Wall -Wextra -pedantic

    The previous level of compiler warnings can be easily restored by
    adding to Makefile.local:

	CCWARN:= -Wall

    The readline, history and ncurses libraries are now default.
    The Makefile variables ${USE_READLINE}, ${READLINE_LIB}, and
    ${READLINE_EXTRAS} now default to:

	USE_READLINE= -DUSE_READLINE
	READLINE_LIB= -lreadline
	READLINE_EXTRAS= -lhistory -lncurses

    The previous mode where readline, history and ncurses libraries
    were not compiled in by default can be easily restored by
    adding to Makefile.local:

	USE_READLINE:=
	READLINE_LIB:=
	READLINE_EXTRAS:=

    We have renamed "stable" as "production".
    We have renamed "unstable" as "tested".

    On the web site:

	http://www.isthe.com/chongo/src/calc/

    these files has been renamed:

	2.x.y.z_IS_LATEST_STABLE   ==> 2.x.y.z_IS_LATEST_PRODUCTION
	2.x.y.z_IS_LATEST_UNSTABLE ==> 2.x.y.z_IS_LATEST_TESTED

    The terms 'stable' and 'unstable' were both misleading and
    inaccurate.  For details see the new documention file:

	README.RELEASE

    See also the help command:

	; help release

    Fixed bug impacting how have_ustat.h was formed.

    Updated help/archive to reflect GitHub use.
2021-12-13 14:43:37 -08:00
Landon Curt Noll
b3c015d338 Release v2.14.0.13
We apologize for the calc v2.14.0.12 source tarball that was missing
critical files.  While the executable was well tested, our release
process was deficient.

We are improved our release process and added tests during the release
procedure to help verify that we are not regressing in to the "v2.14.0.12
source tarball" issue, among other things.

Depending on how things do, you might is several releases come out over
a short period of time.  The core of calc isn't changing, so the calc
executable will be the same as we focus on the Makefiles, our release
procedure, and related documentation / help files.

=-=

The following are the changes in this release:

    Minor tweak to seed() builtin.  Updated help/srand and help/srandom.

    Moved Makefile.ship into Makefile.

    Removed custom/Makefile.head and custom/Makefile.tail.

    The custom/Makefile is now part of source and includes Makefile.
    In particular, custom/Makefile makes use of the 'middle' of
    the new top level Makefile where calc's top level Makefile
    variables are defined.

    Makefile.simple and custom/Makefile.simple are now part of the source
    and are constructed from Makefile and custom/Makefile respectively.
    The Makefile.simple and custom/Makefile.simple avoid using GNU
    conditionals. They may be used with older/classic make commands.

    Makefile.local will include comments about how to better use
    it. Between releases, Makefile.local at the top of the master branch
    will contain how we typically build calc and test calc (FYI: we
    normally enable things such as -Werror -Wextra -pedantic).  When we
    push out a release, Makefile.local will be stripped of non-comment
    lines.  Thus, releases of calc, and, released "calc*.src.rpm"
    files and the source tarballs, will have a Makefile.local with
    only comments.

    The "README.*" files and "HOWTO.INSTALL" file have been updated.

    By default, compiler warnings have been turned up.  The Makefile
    variable ${CCWARN} now defaults to:

	CCWARN= -Wall -Wextra -pedantic

    The previous level of compiler warnings can be easily restored by
    adding to Makefile.local:

	CCWARN:= -Wall

    The readline, history and ncurses libraries are now default.
    The Makefile variables ${USE_READLINE}, ${READLINE_LIB}, and
    ${READLINE_EXTRAS} now default to:

	USE_READLINE= -DUSE_READLINE
	READLINE_LIB= -lreadline
	READLINE_EXTRAS= -lhistory -lncurses

    The previous mode where readline, history and ncurses libraries
    were not compiled in by default can be easily restored by
    adding to Makefile.local:

	USE_READLINE:=
	READLINE_LIB:=
	READLINE_EXTRAS:=

    We have renamed "stable" as "production".
    We have renamed "unstable" as "tested".

    On the web site:

	http://www.isthe.com/chongo/src/calc/

    these files has been renamed:

	2.x.y.z_IS_LATEST_STABLE   ==> 2.x.y.z_IS_LATEST_PRODUCTION
	2.x.y.z_IS_LATEST_UNSTABLE ==> 2.x.y.z_IS_LATEST_TESTED

    The terms 'stable' and 'unstable' were both misleading and
    inaccurate.  For details see the new documention file:

	README.RELEASE

    See also the help command:

	; help release

    Fixed bug impacting how have_ustat.h was formed.

    Updated help/archive to reflect GitHub use.
2021-12-13 14:23:47 -08:00
Landon Curt Noll
5985ad2f33 Updated Makefile.simple due to recent changes in Makefile 2021-12-13 14:16:02 -08:00
Landon Curt Noll
e401c9abf1 Added code to handle HomeBrew macOS libs, added a few #'s 2021-12-13 14:07:51 -08:00
Landon Curt Noll
ad79b6384d Remove leading spaces before a tab in CHANGES 2021-12-13 12:33:35 -08:00
Landon Curt Noll
862dbd6777 Improve the calc build and release process
We apologize for the calc v2.14.0.12 source tarball that was missing
critical files.  While the executable was well tested, our release
process was deficient.

We are improved our release process and added tests during the release
procedure to help verify that we are not regressing in to the "v2.14.0.12
source tarball" issue, among other things.

Depending on how things do, you might is several releases come out over
a short period of time.  The core of calc isn't changing, so the calc
executable will be the same as we focus on the Makefiles, our release
procedure, and related documentation / help files.

We made several changes to the Makefiles.  We also added a new
README.RELEASE document (see "help release") that is a work in
progress. Along the way we discovered a few things that needed to be
updated in documentation.

See the CHANGES file for details.
2021-12-13 12:17:51 -08:00
Landon Curt Noll
0d31eb6828 Recommend calling srand() or srandom() with seed() 2021-12-09 01:34:58 -08:00
Landon Curt Noll
c0be37d4e3 Added paranoia size limited code for seed() builtin.
Just to be padanticly sure, we prevent seed() from
ever returning a value >= 2^64.
2021-12-09 01:12:44 -08:00
Landon Curt Noll
4344532c28 Improve how a seed is loaded into ZVALUE 2021-12-09 00:49:16 -08:00
Landon Curt Noll
0f6efb29bb Release v2.14.0.12
The following are the changes in this release:

    Fixed a number of typos.

    Drop support for SunOS, IRIX and MINGW32_NT-5.0 targets.
    Drop support for CLOCK_SGI_CYCLE.  Drop testing for __MSDOS__.

    Minor improvement of various help files.  Made format of help
    files more consistent.

    Corrected a few comments in zrandom.c, including a case where
    the comment referred to 1007 when it should have used 2^32.

    Improved seed() generation.  Improved some comments in seed.c.
    Added have_environ.c to build have_environ.h in order to
    determine if:

	extern char **environ;	/* user environment */

    is an valid external symbol.

    Fixed documentation that referred to the old additive 55
    generator.  We have been using the subtractive 100 in place
    of the additive 55 generator for a while now.

    Fixed depend rule for custom/Makefile.

    Fixed how Makefile variable SHELL is set on macOS vs. Linux.
    Using /bin/sh on macOS due to how zsh treats globs by default.

    Added charbit.h to define CALC_CHARBIT which is either CHAR_BIT
    from <limits.h> or 8 or a value set by the Makefile variable
    CALC_CHARBIT.  Added have_limits.h to determine if <limits.h>
    is a system include file.

    Compiling now tests for _WIN64 as well when testing for _WIN32.

    Now assuming that <stdio.h> is available under _WIN32 and _WIN64.

    Added some preliminary notes about attempts to compile 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

	     Please also add notes to the 'Compiling calc under Windows 11'
	     section in README.WINDOWS file.

    We added Makefile.simple as part of the master branch source
    to help those who may be using a make tool that does not support
    GNU Make-like features such as "ifeq" and ":=".

    Fixed incorrect ustat_dev member ref in seed() builtin that
    was part of the unreleased calc v2.12.0.11.
2021-12-08 16:04:40 -08:00
Landon Curt Noll
39c0cba1ca Release v2.14.0.12
The following are the changes in this release:

    Fixed a number of typos.

    Drop support for SunOS, IRIX and MINGW32_NT-5.0 targets.
    Drop support for CLOCK_SGI_CYCLE.  Drop testing for __MSDOS__.

    Minor improvement of various help files.  Made format of help
    files more consistent.

    Corrected a few comments in zrandom.c, including a case where
    the comment referred to 1007 when it should have used 2^32.

    Improved seed() generation.  Improved some comments in seed.c.
    Added have_environ.c to build have_environ.h in order to
    determine if:

	extern char **environ;	/* user environment */

    is an valid external symbol.

    Fixed documentation that referred to the old additive 55
    generator.  We have been using the subtractive 100 in place
    of the additive 55 generator for a while now.

    Fixed depend rule for custom/Makefile.

    Fixed how Makefile variable SHELL is set on macOS vs. Linux.
    Using /bin/sh on macOS due to how zsh treats globs by default.

    Added charbit.h to define CALC_CHARBIT which is either CHAR_BIT
    from <limits.h> or 8 or a value set by the Makefile variable
    CALC_CHARBIT.  Added have_limits.h to determine if <limits.h>
    is a system include file.

    Compiling now tests for _WIN64 as well when testing for _WIN32.

    Now assuming that <stdio.h> is available under _WIN32 and _WIN64.

    Added some preliminary notes about attempts to compile 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

	     Please also add notes to the 'Compiling calc under Windows 11'
	     section in README.WINDOWS file.

    We added Makefile.simple as part of the master branch source
    to help those who may be using a make tool that does not support
    GNU Make-like features such as "ifeq" and ":=".

    Fixed incorrect ustat_dev member ref in seed() builtin that
    was part of the unreleased calc v2.12.0.11.
2021-12-08 15:52:34 -08:00
Landon Curt Noll
a68e41248f Fixed incorrect ustat_dev member ref in seed() 2021-12-08 15:43:27 -08:00
Landon Curt Noll
e213cc5072 Release v2.14.0.11
The following are the changes in this release:

    Fixed a number of typos.

    Drop support for SunOS, IRIX and MINGW32_NT-5.0 targets.
    Drop support for CLOCK_SGI_CYCLE.  Drop testing for __MSDOS__.

    Minor improvement of various help files.  Made format of help
    files more consistent.

    Corrected a few comments in zrandom.c, including a case where
    the comment referred to 1007 when it should have used 2^32.

    Improved seed() generation.  Improved some comments in seed.c.
    Added have_environ.c to build have_environ.h in order to
    determine if:

	extern char **environ;	/* user environment */

    is an valid external symbol.

    Fixed documentation that referred to the old additive 55
    generator.  We have been using the subtractive 100 in place
    of the additive 55 generator for a while now.

    Fixed depend rule for custom/Makefile.

    Fixed how Makefile variable SHELL is set on macOS vs. Linux.
    Using /bin/sh on macOS due to how zsh treats globs by default.

    Added charbit.h to define CALC_CHARBIT which is either CHAR_BIT
    from <limits.h> or 8 or a value set by the Makefile variable
    CALC_CHARBIT.  Added have_limits.h to determine if <limits.h>
    is a system include file.

    Compiling now tests for _WIN64 as well when testing for _WIN32.

    Now assuming that <stdio.h> is available under _WIN32 and _WIN64.

    Added some preliminary notes about attempts to compile 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

	     Please also add notes to the 'Compiling calc under Windows 11'
	     section in README.WINDOWS file.

    We added Makefile.simple as part of the master branch source
    to help those who may be using a make tool that does not support
    GNU Make-like features such as "ifeq" and ":=".
2021-12-08 15:30:08 -08:00
Landon Curt Noll
95ebb60619 Remove old MSDOS code in favor of _WIN32 & _WIN64 2021-12-08 15:02:36 -08:00
Landon Curt Noll
e5c8f00adc Ship with Makefile.simple & custom/Makefile.simple 2021-12-08 14:55:23 -08:00
Landon Curt Noll
265713778f Improved top level documentation 2021-12-08 14:12:23 -08:00
Landon Curt Noll
4b08a896b0 Fix comments about _WIN64 2021-12-08 12:51:10 -08:00
Landon Curt Noll
44f3778af1 More DJGPP cleanup 2021-12-08 12:33:46 -08:00
Landon Curt Noll
8db8f93ae0 Change -DWINDOZ to -D_WIN32 for DJGPP 2021-12-08 12:25:16 -08:00
Landon Curt Noll
e688c22c0e Add missing have_limits.h rule for Makefile 2021-12-08 12:18:23 -08:00
Landon Curt Noll
af72992ead Added testing for _WIN64 when testing for _WIN32 2021-12-08 12:04:13 -08:00
Landon Curt Noll
9f3a7817d3 Improve seed()
Do not rehash the hash.
2021-12-07 22:05:47 -08:00
Landon Curt Noll
dd0610db0a Improve seed()
xor-fold FNV hashes as seeds.
2021-12-07 22:01:23 -08:00
Landon Curt Noll
177a5d00d1 Improve seed()
Added charbit.h to define CALC_CHARBIT which is either CHAR_BIT
from <limits.h> or 8 or a value set by the Makefile variable
CALC_CHARBIT.  Added have_limits.h to determine if <limits.h>
is a system include file.
2021-12-07 21:41:28 -08:00
Landon Curt Noll
a02f8aa9f9 Improve seed() builtin
Increase size of random() data used by seed().
2021-12-07 13:47:00 -08:00
Landon Curt Noll
b7d1fb096d Improve the seed() builtin
Set seed() use of arc4random to same level as /dev/urandom.
Restore state size for initstated random().
2021-12-07 13:42:03 -08:00
Landon Curt Noll
48c4f3b948 Improve seed() builtin 2021-12-07 13:39:07 -08:00
Landon Curt Noll
2023175fcc Change how SHELL is set for all calc Makefiles
Using /bin/sh on macOS due to how zsh treats globs by default.
2021-12-07 04:45:23 -08:00
Landon Curt Noll
c54e2648dc Set SHELL=/bin/sh for macOS in Makefiles 2021-12-07 04:35:42 -08:00
Landon Curt Noll
faf40b7149 Fixed how SHELL is set in Makefiles, fix make depend on linux 2021-12-07 04:18:39 -08:00
Landon Curt Noll
4b2ae40c86 Fixed make depend on linux 2021-12-07 04:00:36 -08:00
Landon Curt Noll
af57104e25 Fixed depend rule for custom/Makefile 2021-12-07 03:01:46 -08:00
Landon Curt Noll
5ae3ca059a Fixed old references additive 55
Fixed documentation that referred to the old additive 55
generator.  We have been using the subtractive 100 in place
of the additive 55 generator for a while now.
2021-12-07 02:24:50 -08:00
Landon Curt Noll
cc5fb9a45b Improve the seed() function 2021-12-07 01:56:46 -08:00
Landon Curt Noll
5dcadad8b6 Fix long line in have_arc4random.c 2021-12-07 01:54:55 -08:00
Landon Curt Noll
9c67ceeed8 Fix have_arc4random.h generation 2021-12-07 00:48:28 -08:00
Landon Curt Noll
7ffbaf922e Improve seed() function 2021-12-07 00:44:57 -08:00
Landon Curt Noll
f9464652fe Improve seed() even more 2021-12-06 23:30:52 -08:00
Landon Curt Noll
b30c5c1855 Improved seed() generation
Drop support for CLOCK_SGI_CYCLE.

Improved seed() generation.  Improved some comments in seed.c.
Added have_environ.c to build have_environ.h in order to
determine if:

    extern char **environ;	/* user environment */

is an valid external symbol.
2021-12-06 21:16:08 -08:00
Landon Curt Noll
7417f2e776 Remove excess blank line from calc.c 2021-12-06 21:13:53 -08:00
Landon Curt Noll
71138215a9 Noted changes to zrandom.c comments 2021-12-05 23:38:28 -08:00
Landon Curt Noll
241f777d07 Minor updates to comments
We also corrected a comment mistake where 1007 should have been 2^32.
2021-12-05 23:36:05 -08:00
Landon Curt Noll
9d27f0aaa7 Update security policy. 2021-12-05 23:12:24 -08:00
Landon Curt Noll
a28edba4e9 Improve help files
Minor improvement of various help files.  Made format of help
files more consistent.
2021-12-05 23:02:12 -08:00
Landon Curt Noll
de47c960d3 Change remaining Email addresses to use at and dot 2021-12-05 21:29:46 -08:00
Landon Curt Noll
c3a51f42e2 Drop support for SunOS, IRIX and MINGW32_NT-5.0 targets 2021-12-05 19:02:09 -08:00
Landon Curt Noll
f5c5cea8b0 Correct typos 2021-12-05 18:23:27 -08:00
Landon Curt Noll
769ac51f8c Release v2.14.0.10 2021-12-01 23:38:56 -08:00
Landon Curt Noll
cdda633369 Update CHANGES file to note previous 2 commits 2021-12-01 23:34:40 -08:00
Landon Curt Noll
50f349f4d7 Update copyright dates to account for 2021 mods 2021-12-01 23:28:59 -08:00
Landon Curt Noll
ef00e00328 Remove unnecessary spaces inbetween or next to tabs 2021-12-01 23:25:49 -08:00
Landon Curt Noll
bb041098bc Reduce the length of long lines 2021-12-01 23:15:06 -08:00
Landon Curt Noll
f794b8d859 Reduce global status constants
The constants:

	9, 9/10, 10/9, 24, 360, 400

are used by func.c only, so there were moved
from {q,z}math.{c,h} to func.c.

The constants:

	3, 4

are used by zrandom.c only, so there were moved
from {q,z}math.{c,h} to zrandom.c.
2021-12-01 22:50:52 -08:00
Landon Curt Noll
bd990cef1f Added freeglobals() to libcalc_call_me_last() 2021-12-01 21:56:01 -08:00
Landon Curt Noll
febb9d96b3 Convert freeh() call to zfree() call 2021-12-01 21:55:18 -08:00
Landon Curt Noll
13ae9b804e Add missing blank lines 2021-12-01 21:53:46 -08:00
Landon Curt Noll
56cc4897d6 Reapply memory leak fixes to zmod.c
Revert previously applied zmod.c mods and
then apply better mods to fix zmod memory leaks.
2021-12-01 21:48:13 -08:00
Landon Curt Noll
eb940e0a21 Fix paranoia guard in literal string alloc 2021-11-30 03:44:38 -08:00
Landon Curt Noll
f3adb35e36 Add string and symbol guard allocation paranoia 2021-11-30 03:40:40 -08:00
Landon Curt Noll
d1d365d7ba Added initialization paranoia 2021-11-30 03:37:20 -08:00
Landon Curt Noll
af214b166d Reorder zfree ops to assign NULL to ptr after free 2021-11-30 03:36:22 -08:00
Landon Curt Noll
51b933dfff Add initialization paranoia 2021-11-30 03:35:09 -08:00
Landon Curt Noll
c4e5007587 Clarify strlcpy size check 2021-11-30 03:33:48 -08:00
Landon Curt Noll
c838798f04 Fix more memory leaks, improve zfree() action 2021-11-29 01:55:53 -08:00
Landon Curt Noll
23d49a41fe Remove references to externals that are no longer used 2021-11-28 20:52:03 -08:00
Landon Curt Noll
3d300acca1 Improve internal pre-defined constant handling
Improved the way that internal pre-defined constants are managed.
Removed unused internal pre-defined constants.  Added code to
prevent an internal pre-defined constant (that was never
allocated) from being freed.
2021-11-28 20:47:52 -08:00
Landon Curt Noll
8f449ba6d2 Revert local test mistake in Makefile.local 2021-11-27 00:23:54 -08:00
Landon Curt Noll
f4d754b47d Checkpoint in valgrind work 2021-11-27 00:05:28 -08:00
Landon Curt Noll
fde724aa2d Release v2.14.0.9
The following are the changes in this release:

    Due to issues with clang and Apple Silicon, ARCH_CFLAGS is now,
    by default, empty:

	ARCH_CFLAGS=

    If you want to use, say, -march=native, then either change
    the Makefile or make with:

	make all ARCH_CFLAGS='-march=native'

    Added arch and hardware as GNU Makefile computed values.
    As with ${target}, ${arch} and ${hardware} is computed by uname:

	target: uname -a
	arch: uname -p
	hardware: uname -m

    Fixed compiling calc on Apple Silicon with homebrew.  On Apple
    Silicon, HomeBrew installs on into a different location.  The
    Makefile checks if ${hardware} is arm64 and adjusts the location
    of libraries such as readline and history accordingly.
2021-11-24 01:35:01 -08:00
Landon Curt Noll
e411a3e6bf Trim long lines in Makefile 2021-11-24 01:33:00 -08:00
Landon Curt Noll
7db81649b0 Fixed compiling for Apple Silicon arm64 w/HomeBrew 2021-11-24 01:25:49 -08:00
Landon Curt Noll
08fe6f13f4 Release v2.14.0.8
The following are the changes in this release:

    Identical to v2.14.0.7: now declared a stable release.
2021-11-23 00:04:09 -08:00
Landon Curt Noll
e11d159c81 Release v2.14.0.7
The following are the changes in this release:

    Fizzbin is a better word. :-)

    The help and man builtin commands now return an error when a
    help file cannot be opened, such as when there is no help file.

    Added palindrome.cal resource file.  For example, to find the
    largest (highly probable) prime palindrome under 280 decimal
    digits (text tweet limit):

	prevprimepal(1e280)
2021-11-07 20:36:07 -08:00
Landon Curt Noll
dfd66be871 Adjusted calc in prep for 2.14.0.7 release 2021-11-07 20:30:23 -08:00
Landon Curt Noll
27f977b545 Remove unnecessary leading line whitespace before a tab 2021-11-07 20:14:28 -08:00
Landon Curt Noll
2ca6e789ca Add ignore win32 to .gitignore 2021-11-07 20:11:21 -08:00
Landon Curt Noll
ff8f921ebc Fix CHANGES note for palindrome.cal 2021-11-07 18:39:43 -08:00
Landon Curt Noll
005b78227a Minor comment changes to palindrome.cal 2021-11-07 18:36:06 -08:00
Landon Curt Noll
b7a42a9d3d Optimize palindrome.cal
In cal/palindrome.cal:

Improved the performace of nextpal() and nextprimepal()
by adding and using palnextpal().

Improved the performace of prevpal() and prevprimepal()
by adding and using palprevpal().

Test showed that runs that took 0.0530 cpu seconds can
now be done in as little as 0.0327 cpu seconds.
2021-11-07 14:15:19 -08:00
Landon Curt Noll
3d1e938cb6 Remove user_debug references in palindrome.cal 2021-11-07 13:34:58 -08:00
Landon Curt Noll
8b98a7c1f6 Add cal/palindrome.cal resource file 2021-11-06 14:48:45 -07:00
Landon Curt Noll
dbf5acf5e8 Improved help error messages
The help and man commands now issue an error message when
the help file cannot be opened: say because there is a
help command typo and there is no such help file.
2021-11-06 12:47:19 -07:00
Landon Curt Noll
5fe5ab1c4b Minor help improvement
Fizzbin is better than gleet.
2021-11-06 12:44:16 -07:00
Landon Curt Noll
e0cd9bb3db Release v2.14.0.6
The following are the changes in this release:

    Fixed typo in cal/statistics.cal thanks to a report by <GitHub user
    dennisaldea>.

    Fixed an old Windoz pun in README.WINDOWS as requested by <GitHub
    user marcodegio>.

    Fixed a really obscure bug in the internal initconstants()
    function of const.c that has been sitting for over 31 years!

	We are amazed that nobody has encountered this bug before
	now.  Nevertheless, our very extensive regression and
	multi-architecture testing found the bug.  Now, after all
	those years, it is fixed.

    Fixed issues identied by the default CodeUL GitHub security code scan:

	Wrong type of arguments to printf in have_fpos_pos.c
	Multiplication result converted to larger type in zfunc.c
2021-10-22 03:36:40 -07:00
Landon Curt Noll
f0f6171354 Release v2.14.0.5
Fixed a really obscure bug in the internal initconstants()
function of const.c that has been sitting for over 31 years!

    We are amazed that nobody has encountered this bug before
    now.  Nevertheless, our very extensive regression and
    multi-architecture testing found the bug.  Now, after all
    those years, it is fixed.

Fixed issues identied by the default CodeUL GitHub security code
scan:

    Wrong type of arguments to printf in have_fpos_pos.c
    Multiplication result converted to larger type in zfunc.c
2021-10-22 03:20:58 -07:00
Landon Curt Noll
94861cc6d2 Improved an internal allocation
Improved the way that the internal array,
consttable, is allocated.
2021-10-22 03:09:08 -07:00
Landon Curt Noll
286233e28f Fixed internal code bugs
Fixed a really obscure bug in the internal initconstants()
function of const.c that has been sitting for over 31 years!

    We are amazed that nobody has encountered this bug before
    now.  Nevertheless, our very extensive regression and
    multi-architecture testing found the bug.  Now, after all
    those years, it is fixed.

Fixed issues identied by the default CodeUL GitHub security code scan:

    Wrong type of arguments to printf in have_fpos_pos.c
    Multiplication result converted to larger type in zfunc.c
2021-10-22 03:05:12 -07:00
Landon Curt Noll
99ac7836aa Create SECURITY.md 2021-10-22 01:46:12 -07:00
Landon Curt Noll
6c0c8e0ef6 Fixed issues noted by default GitHub code scan 2021-10-22 01:39:07 -07:00
Landon Curt Noll
8aa5f140bf Release v2.12.0.4 2021-10-22 01:26:25 -07:00
Landon Curt Noll
2fcb9a5995 Create codeql-analysis.yml 2021-10-22 01:25:16 -07:00
Landon Curt Noll
8b018b697d Updated CHANGES as per GitHub pull request #35 2021-10-21 12:21:10 -07:00
Landon Curt Noll
0e269ecd67 Merge pull request #35 from marcodegio/patch-1
Update README.WINDOWS
2021-10-21 12:15:56 -07:00
Landon Curt Noll
a640bc4656 Fixed typo in cal/statistics.cal
Thanks to a report by <GitHub user dennisaldea>.
2021-10-21 12:12:31 -07:00
Marco Degiovanni
62a95499ef Update README.WINDOWS
i changed the first line from Windoz to Windows
2021-10-21 20:05:11 +02:00
Landon Curt Noll
9e92d4a35a Change initnumbs[] to be NULL terminated 2021-09-28 22:32:06 -07:00
Landon Curt Noll
459c07b121 Release v2.14.0.3
The following are the changes in this release:

    Added builtin functions to convert between degrees and
    degrees, minutes and seconds under the config("mod")
    round rules:

	d2dms(degs, d, m, s [,rnd]) - given degs, compute d, m, s
	d2dm(degs, d, m [,rnd]) - given degs, compute d, m

	See help/d2dms and help/d2dm.

    Example:

	; print d2dms(360.321,deg=,min=,sec=), deg, min, sec;
	0.321 0 19 15.6

	; print d2dm(360.321,deg=,min=), deg, min;
	0.321 0 19.26

    Added builtin functions to convert between gradians and
    gradians, minutes and seconds under the config("mod")
    round rules:

	g2gms(grads, g, m, s [,rnd]) - given grads, compute g, m, s
	g2gm(grads, g, m [,rnd]) - given grads, compute g, m

	See help/g2gms and help/g2gm.

    Example:

	; print g2gms(400.321,grad=,min=,sec=), grad, min, sec;
	0.321 0 19 15.6

	; print g2gm(400.321,grad=,min=), grad, min;
	0.321 0 19.26

    Added builtin functions to convert between hours and
    hours, minutes and seconds under the config("mod")
    round rules:

	h2hms(hours, h, m, s [,rnd]) - given hours, compute h, m, s
	h2hm(hours, h, m [,rnd]) - given hours, compute h, m

	See help/h2hms and help/h2hm.

    Example:

	; print h2hms(24.321,hour=,min=,sec=), hour, min, sec;
	0.321 0 19 15.6

	; print h2hm(24.321,hour=,min=), hour, min;
	0.321 0 19.26

    Renumbered regression tests 3408 thru 3437, to 9102 thru 9131.

    Updated Added hms.cal resource file to use h2hms() builtin.
    Updated Added dms.cal resource file to use d2dms() builtin.

    Fix minor typo in help/mod SYNOPSIS.
    Fix minor typo in help/quo SYNOPSIS.

    Added a few more examples to help/strcmp.

    Added builtin functions to convert between degrees, minutes and
    seconds and degrees under the config("mod") round rules:

	dms2d(d, m, s [,rnd]) - convert deg, min, and secs to deg
	dm2d(d, m [,rnd]) - convert deg, min to deg

	See help/dms2d and help/dm2d.

    Example:

	; print dms2d(12, 20, 44.16);
	12.3456

	; print dm2d(3601, -25.5594);
	0.57401

    Added builtin functions to convert between gradians, minutes and
    seconds and gradians under the config("mod") round rules:

	gms2g(g, m, s [,rnd]) - convert grad, min, and secs to grad
	gm2g(g, m [,rnd]) - convert grad and min to grad

	See help/g2gms and help/g2gm.

    Example:

	; print gms2g(12, 20, 44.16);
	12.3456

	; print gm2g(4001, -25.5594);
	0.57401

    Added builtin functions to convert between hours, minutes and
    seconds and hours under the config("mod") round rules:

	hms2h(h, m, s [,rnd]) - convert hours, min, and secs to hours
	hm2h(h, m [,rnd]) - convert hours, min to hours

	See help/hms2h and help/hm2h.

    Example:

	; print hms2h(12, 20, 44.16);
	12.3456

	; print hm2h(241, -25.5594);
	0.57401
2021-09-27 02:49:06 -07:00
Landon Curt Noll
ada15fdabc Added more builtin inverse conversion functions
Added builtin functions to convert between degrees, minutes and
    seconds and degrees under the config("mod") round rules:

	dms2d(d, m, s [,rnd]) - convert deg, min, and secs to deg
	dm2d(d, m [,rnd]) - convert deg, min to deg

	See help/dms2d and help/dm2d.

    Example:

	; print dms2d(12, 20, 44.16);
	12.3456

	; print dm2d(3601, -25.5594);
	0.57401

    Added builtin functions to convert between gradians, minutes and
    seconds and gradians under the config("mod") round rules:

	gms2g(g, m, s [,rnd]) - convert grad, min, and secs to grad
	gm2g(g, m [,rnd]) - convert grad and min to grad

	See help/g2gms and help/g2gm.

    Example:

	; print gms2g(12, 20, 44.16);
	12.3456

	; print gm2g(4001, -25.5594);
	0.57401

    Added builtin functions to convert between hours, minutes and
    seconds and hours under the config("mod") round rules:

	hms2h(h, m, s [,rnd]) - convert hours, min, and secs to hours
	hm2h(h, m [,rnd]) - convert hours, min to hours

	See help/hms2h and help/hm2h.

    Example:

	; print hms2h(12, 20, 44.16);
	12.3456

	; print hm2h(241, -25.5594);
	0.57401
2021-09-27 02:14:18 -07:00
Landon Curt Noll
d5de36841a Improve error codes for some invalid rounding args 2021-09-26 23:50:45 -07:00
Landon Curt Noll
cf419fb329 Added several conversion funcions, plus minor updates
Added several conversion functions:

    Added builtin functions to convert between degrees and
    degrees, minutes and seconds under the config("mod")
    round rules:

	d2dms(degs, d, m, s [,rnd]) - given degs, compute d, m, s
	d2dm(degs, d, m [,rnd]) - given degs, compute d, m

	See help/d2dms and help/d2dm.

    Example:

	; print d2dms(360.321,deg=,min=,sec=), deg, min, sec;
	0.321 0 19 15.6

	; print d2dm(360.321,deg=,min=), deg, min;
	0.321 0 19.26

    Added builtin functions to convert between gradians and
    gradians, minutes and seconds under the config("mod")
    round rules:

	g2gms(grads, g, m, s [,rnd]) - given grads, compute g, m, s
	g2gm(grads, g, m [,rnd]) - given grads, compute g, m

	See help/g2gms and help/g2gm.

    Example:

	; print g2gms(400.321,grad=,min=,sec=), grad, min, sec;
	0.321 0 19 15.6

	; print g2gm(400.321,grad=,min=), grad, min;
	0.321 0 19.26

    Added builtin functions to convert between hours and
    hours, minutes and seconds under the config("mod")
    round rules:

	h2hms(hours, h, m, s [,rnd]) - given hours, compute h, m, s
	h2hm(hours, h, m [,rnd]) - given hours, compute h, m

	See help/h2hms and help/h2hm.

    Example:

	; print h2hms(24.321,hour=,min=,sec=), hour, min, sec;
	0.321 0 19 15.6

	; print h2hm(24.321,hour=,min=), hour, min;
	0.321 0 19.26

In addtion:

    Renumbered regression tests 3408 thru 3437, to 9102 thru 9131.

    Updated Added hms.cal resource file to use h2hms() builtin.
    Updated Added dms.cal resource file to use d2dms() builtin.

    Fix minor typo in help/mod SYNOPSIS.
    Fix minor typo in help/quo SYNOPSIS.

    Added a few more examples to help/strcmp.
2021-09-26 04:38:09 -07:00
Landon Curt Noll
abf39b34b6 Release v2.14.0.2
The clean and clobber makefile rules no longer list custom/Makefile
as a dependency.

Unfortunately due to the complex dependency issues between
Makefile, Makefile.ship and custom/Makefile, parallel GNU make
is NOT recommended.  Sorry (tm Canada) :)

Fixed a few typos in CHANGES.

As a side note: We stayed v2.13.x was kept for only a short time.
The move to 2.14.x was motivated by non-compatible changes due to
the default order of CALCRC, plus some new builtin functions.

More changes are likely, so we might see another v2.14.0.x release
before things are declared "recommended stable".

Not that we wan to discourage people from trying v2.14.0, you should
try it.  We just want things to become stable and well field tested
before we reach the "recommended stable" release state.
2021-09-08 14:38:20 -07:00
Landon Curt Noll
552252371f Disable parallel GNU make for now
Unfortunately due to the complex dependency issues between
Makefile, Makefile.ship and custom/Makefile, parallel GNU make
is NOT recommended.  Sorry (tm Canada) :)
2021-09-07 16:35:45 -07:00
Landon Curt Noll
7570010a04 Removed custom/Makefile dependency on clean & clobber rules 2021-09-07 15:51:30 -07:00
Landon Curt Noll
a9ee753dc6 Fixed help detail_help_list rule and DETAIL_HELP
A .bak file was accicently put into the DETAIL_HELP list.
That bogus help file was removed.

Modified the help/Makefile detail_help_list rule to remove .bak files
when forming DETAIL_HELP.
2021-09-07 13:40:19 -07:00
Landon Curt Noll
ca5a81122a Completed degree, radian, gradian builtin conversions
Updated CHANGES.

Updated help/unexpected.

Added help files for d2g(), d2r(), g2d(), g2r(), r2d(), r2g().

Added regression test code for the same functions.

Fixed a few minor typos.
2021-09-07 13:28:03 -07:00
Landon Curt Noll
554cd97145 Initial code for g2d() & d2g() builtins
We still need to add:

    help files for g2d & d2g
    regression tests for g2d & d2g
    notes in related trig help files
    note in unexpected help file
    note in CHANGES
2021-09-07 07:59:51 -07:00
Landon Curt Noll
806606f284 Initial code for g2r() & r2g() builtins
We still need to add:

    help files for g2r & r2g
    regression tests for g2r & r2g
    notes in related trig help files
    note in unexpected help file
    note in CHANGES
2021-09-07 06:58:54 -07:00
Landon Curt Noll
7c0ebc5887 Improve pi cache
Explicitly initialize static pi cache.
Use enums to identify pi cache elements.
Verify pi cache elements used have useful values.
2021-09-07 06:30:21 -07:00
Landon Curt Noll
45665f94a7 Added initial code for d2r() & r2d() builtins
We still need to add:

    help files for d2r & r2d
    regression tests for d2r & r2d
    notes in related trig help files
    note in unexpected help file
    note in CHANGES
2021-09-07 04:49:54 -07:00
Landon Curt Noll
cd736fdbd4 Release v2.14.0.0
The :-separated default CALCRC value has been reversed.
The default CALCRC was:

    ${CALC_SHAREDIR}/startup:~/.calcrc:./.calcinit

The default CALCRC is now:

    ./.calcinit:~/.calcrc:${CALC_SHAREDIR}/startup

See "help environment" for details.

Added engineering mode as per a GitHub pull request from
<GitHub user heitzmann>.  Thank you!  For example:

    ; config("mode","eng"),
    ; 10^41
	    100e39

or for example:

    ; base(1000),
    ; 2^23209-1
	    ~402.87411577898877818187e6984

For more information see:

    help base

Added regression test code for engineering mode.  Improved and
expanded regression test code related to the base() and base2()
builtin functions.

Fixed a critical bug in the above mentioned pull request where
a call to base2(1000) would make calc unstable and likely to
dump core.
2021-09-06 23:30:06 -07:00
Landon Curt Noll
f753884008 Expanded regression test code for base() and base2()
Added regression test code for engineering mode.  Improved and
expanded regression test code related to the base() and base2()
builtin functions.
2021-09-06 19:22:57 -07:00
Landon Curt Noll
1d9a4941ce Fixed critical bug in base2(1000)
Pull request #31 introduced a critical bug that caused
calc to become unstable when base2(1000) was called.

This patch fixes that bug.
2021-09-06 19:08:05 -07:00
Landon Curt Noll
5bde797ba4 Merge pull request #31 from heitzmann/engineering_mode
Add engineering output mode
2021-09-06 16:54:47 -07:00
Landon Curt Noll
ecba35fc26 Reverse default CALCRC :-order
The :-separated default CALCRC value has been reversed.
The default CALCRC was:

    ${CALC_SHAREDIR}/startup:~/.calcrc:./.calcinit

The default CALCRC is now:

    ./.calcinit:~/.calcrc:${CALC_SHAREDIR}/startup

See "help environment" for details.
2021-09-06 16:52:03 -07:00
Lucas Heitzmann Gabrielli
a4f8f367c3 Skip printing exponent when 0. 2021-06-09 13:09:33 -03:00
Lucas Heitzmann Gabrielli
41b11ab785 Add engineering output mode
Similar to scientific mode, engineering mode also displays numbers in
base 10 exponential notation, with the difference that exponents are
always multiples of 3, to facilitate the interpretation in terms of
SI prefixes.

The mode is activated in config thru "engineering" or "eng. For base
and base2, it uses the special value 1000.
2021-06-07 14:11:07 -03:00
Landon Curt Noll
3d33c6c6f4 Fix typos on CHANGES 2021-04-16 23:49:00 -07:00
Landon Curt Noll
dbd8926022 Release v2.13.0.1
Replaced /usr/local with the use of ${PREFIX} in calc Makefiles.

The ${PREFIX} is not the same as ${T}.  The ${T} specifies
a top level directory under which calc installs things.
While usally ${T} is empty, it can be specific path
as if calc where "chrooted" during an install.
The ${PREFIX} value, during install, is a path between
the top level ${T} install directory and the object
such as an include file.

Corrected a few more typos in Makefile comments.

Added Makefile.local, a file with a single comment.  The main
Makefile includes Makefile.local just before the first all rule.
One may overtide any Makefile setting by modifying Makefile.local.
For example, Makefile.local could force BLD_TYPE:

    HAVE_STRING_H:= YES
    HAVE_TIMES_H:= YES
    SED:= /usr/local/bin/nsed

Added ${LOC_MKF} to specify the make of the file that is
included just before the all file.  So one could place
the above override lines into a different file and call
make changing the ${LOC_MKF} value.  For example:

    make LOC_MKF=Makefile.private clobber all chk

Updated HOWTO.INSTALL to mention Makefile.local.
2021-04-16 23:26:12 -07:00
Landon Curt Noll
f7f110b686 Added make include of Makefile.local
Added Makefile.local, a file with a single comment.  The main
    Makefile includes Makefile.local just before the first all rule.
    One may overtide any Makefile setting by modifying Makefile.local.
    For example, Makefile.local could force BLD_TYPE:

        HAVE_STRING_H:= YES
        HAVE_TIMES_H:= YES
        SED:= /usr/local/bin/nsed

    Added ${LOC_MKF} to specify the make of the file that is
    included just before the all file.  So one could place
    the above override lines into a different file and call
    make changing the ${LOC_MKF} value.  For example:

        make LOC_MKF=Makefile.private clobber all chk
2021-04-11 03:43:37 -07:00
Landon Curt Noll
ebf065dcb8 Prepare for calc version 2.13.0.1
Replaced /usr/local with the use of ${PREFIX} in calc Makefiles.

    The ${PREFIX} is not the same as ${T}.  The ${T} specifies
    a top level directory under which calc installs things.
    While usally ${T} is empty, it can be specific path
    as if calc where "chrooted" during an install.
    The ${PREFIX} value, during install, is a path between
    the top level ${T} install directory and the object
    such as an include file.

    Corrected a few more typos in Makefile comments.
2021-04-09 12:40:51 -07:00
Landon Curt Noll
6bc0747a71 Removed bug report that was fixed in 2.13.0.0 2021-03-27 06:05:55 -07:00
Landon Curt Noll
04861939fc Release v2.13.0.0
The following are the changes in this release:

    Fixed typo (missing quotes) in the env rule.

    Fixed intendation problem in CHANGES.

    Combined 2.12.9.1 changes into the 2.12.8.2 to 2.12.9.0
    range, and thus renamed the range to 2.12.8.2 to 2.12.9.1.

    Fixed issues related to building Makefile.simple.

    Fixed how the Makefile variable MANPATH is set for macOS.

    Added a bunch of information to the near bottom of HOWTO.INSTALL
    on calc Makefiles.  This information discusses the various
    Makefiles found in the calc source.

    Added comments in various calc Makefiles about their origin.
    In particular, for Makefiles that are constructed such as
    Makefile.simple, custom/Makefile and custom/Makefile.simple
    there are comments about how they were made.

    For all calc Makefiles, including those in sub-directories,
    near the top there is now a line of the form:

	# SRC: ... some message about the origin ...

    Fixed how the calc(1) man page is installed under macOS.

    Fixed how calc man page in ${CATDIR} is formed.

    Fixed how Makefile.simple is formed.

    Fixed the #! calc script argument processing.  The initial #!
    line must end in a -f.  For example, if calc is in /usr/local/bin/calc,
    then the following would be the first line of a calc script:

	#!/usr/local/bin/calc -f
	...

    It is common that -q be usde with a calc script, so assuming the
    same /usr/local/bin/calc path:

	#!/usr/local/bin/calc -q -f
	...

    Use of -s in the #! first line of a calc script is not needed
    since -f implies -f.

    The argv() will now return values more typical of C's main().
    Before it returned one less than the number of arguments.  Now,
    for example, when calc is given 2 args, argv() will return 3.

    The value of argv(0) will be the path to calc, or in the
    case of a #! calc cscript, it will return the name of the script.

    Updated the calc man page and help/argv to reflect the
    above changes.

    Improved the formatting of the calc man page.

    Fixed the formation of the win32 sub-directory via the win32_hsrc
    Makefile rule.

    Due to incompatible changes to the argv() function, and #! calc
    scripts, we are setting the version to the next minor number:

	2.13.0
2021-03-27 05:55:50 -07:00
Landon Curt Noll
ca0aaa0c3a Fixed how Makefile.simple is formed 2021-03-26 23:27:46 -07:00
Landon Curt Noll
f5d5319a51 Fix typos 2021-03-26 22:47:55 -07:00
Landon Curt Noll
263b8a78ef Fix how calc(1) cat page, if needed, is formed 2021-03-26 22:30:19 -07:00
Landon Curt Noll
3c866367c6 Fix calc(1) man page install uncer macOS 2021-03-26 21:43:41 -07:00
Landon Curt Noll
09d7080547 Added comments in calc Makefiles
Added a bunch of information to the near bottom of HOWTO.INSTALL
    on calc Makefiles.  This information discusses the various
    Makefiles found in the calc source.

    Added comments in various calc Makefiles about their origin.
    In particular, for Makefiles that are constructed such as
    Makefile.simple, custom/Makefile and custom/Makefile.simple
    there are comments about how they were made.

    For all calc Makefiles, including those in sub-directories,
    near the top there is now a line of the form:

	# SRC: ... some message about the origin ...
2021-03-26 16:52:32 -07:00
Landon Curt Noll
f480c8c5df Cleanup CHANGES
Fixed intendation problem in CHANGES.

    Combined 2.12.9.1 changes into the 2.12.8.2 to 2.12.9.0
    range, and thus renamed the range to 2.12.8.2 to 2.12.9.1.
2021-03-26 12:04:25 -07:00
Landon Curt Noll
a230431a3b Fix missing quotes in env rule 2021-03-26 11:59:15 -07:00
Landon Curt Noll
eaec46982d Release v2.12.9.1
The following are the changes in this release:

    Fixed a typo typo in help/Makefile that caused the build of
    2.12.9.0 to fail in a number of cases.  Thanks to a report by
    <GitHub user balducci>.

    Pass form Makefile variables ${Q}, ${S}, ${E}, ${H} and ${V} down
    to all sub-directory Makefiles from the top level Makefile.
2021-03-26 09:31:36 -07:00
Landon Curt Noll
a86d629982 Fixed a typo in help/Makefile
Fixed a typo typo in help/Makefile that caused the build of
2.12.9.0 to fail in a number of cases.  Thanks to a report by
<GitHub user balducci>.
2021-03-12 11:31:21 -08:00
Landon Curt Noll
bcbc0cb766 Merge pull request #25 from atsampson/doubleassign
Remove redundant assignments when byteswapping
2021-03-11 03:14:14 -08:00
Landon Curt Noll
ac0d84eef8 Release v2.12.9.0
Added notes to help/unexpected about:

    display() will limit the number of digits printed after decimal point

    %d will format after the decimal point for non-integer numeric values

    %x will format as fractions for non-integer numeric values

    fprintf(fd, "%d\n", huge_value) may need fflush(fd) to finish

Fixed Makefile dependencies for the args.h rule.

Fixed Makefile cases where echo with -n is used.  On some systems,
/bin/sh does not use -n, so we must call /bin/echo -n instead
via the ${ECHON} Makefile variable.

Add missing standard tools to sub-Makefiles to make them
easier to invoke directly.

Sort lists of standard tool Makefile variables and remove duplicates.

Declare the SHELL at the top of Makefiles.

Fixed the depend rule in the custom Makefile.

Improved the messages produced by the depend in the Makefiles.

Changed the UNUSED define in have_unused.h to be a macro with
a parameter.  Changed all use of UNUSED in *.c to be UNUSED(x).

Removed need for HAVE_UNUSED in building the have_unused.h file.

 CCBAN is given to ${CC} in order to control if banned.h is in effect.

 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.

 Added the building of have_ban_pragma.h, which will determine
 if "#pragma GCC poison func_name" is supported.  If it is not,
 or of HAVE_PRAGMA_GCC_POSION=-DHAVE_NO_PRAGMA_GCC_POSION, then
 banned.h will have no effect.

 Fixed building of the have_getpgid.h file.
 Fixed building of the have_getprid.h file.
 Fixed building of the have_getsid.h file.
 Fixed building of the have_gettime.h file.
 Fixed building of the have_strdup.h file.
 Fixed building of the have_ustat.h file.
 Fixed building of the have_rusage.h file.

 Added HAVE_NO_STRLCPY to control if we want to test if
 the system has a strlcpy() function.  This in turn produces
 the have_strlcpy.h file wherein the symbol HAVE_STRLCPY will
 be defined, or not depending if the system comes with a
 strlcpy() function.

 If the system does not have a strlcpy() function, we
 compile our own strlcpy() function.  See strl.c for details.

 Added HAVE_NO_STRLCAT to control if we want to test if
 the system has a strlcat() function.  This in turn produces
 the have_strlcat.h file wherein the symbol HAVE_STRLCAT will
 be defined, or not depending if the system comes with a
 strlcat() function.

 If the system does not have a strlcat() function, we
 compile our own strlcat() function.  See strl.c for details.

 Fixed places were <string.h>, using #ifdef HAVE_STRING_H
 for legacy systems that do not have that include file.

 Added ${H} Makefile symbol to control the announcement
 of forming and having formed hsrc related files.  By default
 H=@ (announce hsrc file formation) vs. H=@: to silence hsrc
 related file formation.

 Explicitly turn off quiet mode (set Makefile variable ${Q} to
 be empty) when building rpms.

 Improved and fixed the hsrc build process.

 Forming rpms is performed in verbose mode to assist debugging
 to the rpm build process.

 Compile custom code, if needed, after main code is compiled.
2021-03-11 01:54:28 -08:00
Landon Curt Noll
9b4580d861 Fix typo in make depend messages 2021-03-07 02:37:59 -08:00
Landon Curt Noll
2085361df1 Fix make depend plus make depend Makefile changes 2021-03-07 02:03:28 -08:00
Landon Curt Noll
bf4657c138 Cleanup of Makefiles
Fixed Makefile dependenies for the args.h rule.

Fixed Makefile cases where echo with -n is used.  On some systems,
/bin/sh does not use -n, so we must call /bin/echo -n instead
via the ${ECHON} Makefile variable.

Add missing standard tools to sub-Makefiles to make them
easier to invoke directly.

Sort lists of standard tool Makefile variables and remove duplicates.

Declare the SHELL at the top of Makefiles.

Fixed the depend rule in the custom Makefile.
2021-03-07 01:26:40 -08:00
Landon Curt Noll
1b5636afed Use ${ECHON} for when /bin/echo -n is needed 2021-03-06 22:21:36 -08:00
Landon Curt Noll
7eba99ac29 Add notes about unexpeded things in using calc 2021-03-06 22:12:14 -08:00
Landon Curt Noll
de6474bf28 Declare SHELL at makefile top, sort and fix standard tool list in Makefiles 2021-03-06 22:09:10 -08:00
Landon Curt Noll
55bc690cd1 Fix dependencies for args.h 2021-03-06 21:00:45 -08:00
Adam Sampson
6dc62c1ab7 Remove redundant assignments when byteswapping.
The SWAP_ macros already write the result to their destination arg, so
there's no need for an extra assignment -- and this is undefined
behaviour because there are two assignments to the same variable without
an intervening sequence point (as GCC 10 correctly warns).
2021-03-06 01:46:04 +00:00
Landon Curt Noll
0aca07d278 Release 2.12.8.2
The following are the changes in this release:

    Calc can now correctly compile without CUSTOM being defined,
    thanks to a report by <GitHub user barsnick>.
2021-02-20 09:27:50 -08:00
Landon Curt Noll
1ab3b2c313 Restore ability to compile calc without -DCUSTOM 2021-02-20 09:25:48 -08:00
Landon Curt Noll
64e2c6a262 Release 2.12.8.1
Fixed how the *.tar.bz2 are formed.  The calc-2.12.8.0.tar.bz2 file
    that was formed for calc version 2.12.8.0 was missing most files.

    Expanded 'make chk' to also verify that 'make distchk' and 'make
    distlist' execute successfully.  This will help check a regression
    of the bug that produced the bogus calc-2.12.8.0.tar.bz2 file.

    Added additional regression tests related 0^(zero_expression)==1.
2021-02-15 22:53:22 -08:00
Landon Curt Noll
eac02835ed Test pre-release of 2.12.8.1 2021-02-15 22:33:13 -08:00
Landon Curt Noll
33657bb2cc Test pre-release of 2.12.8.1 2021-02-15 22:32:27 -08:00
Landon Curt Noll
8af0b351ae Release 2.12.8.1
Fixed how the *.tar.bz2 are formed.  The calc-2.12.8.0.tar.bz2 file
    that was formed for calc version 2.12.8.0 was missing most files.

    Expanded 'make chk' to also verify that 'make distchk' and 'make
    distlist' execute successfully.  This will help check a regression
    of the bug that produced the bogus calc-2.12.8.0.tar.bz2 file.

    Added additional regression tests related 0^(zero_expression)==1.
2021-02-15 22:21:02 -08:00
Landon Curt Noll
3260f90a73 Changed default MANDIR to make it easier to install on macOS 11 2021-02-12 23:16:26 -08:00
Landon Curt Noll
b7e15195f9 Release 2.12.8.0
Fixed a mistake in "help intro" where some inserted text changed
    the value of "." and thus made the next result incorrect.

    Clarified in "help factor" that 1 is returned if no
    factor below the limit was found.

    Removed Makefile variable ${MAKEFILE_REV}.

    The missing cscript/square.calc file has been restored.

    Fixed compiler errors and warnings related to GCC.  In particular,
    gcc/9.3.1 and gcc/10.2.1 now compile calc without any compiler
    errors or warnings, even with -Werror -Wextra -pedantic.

    To print out information about the calc compilation
    environment, we added the following make rule:

        make calcinfo

    Improved how 'make debug' operates.

    Moved help/contrib to CONTRIB-CODE.  The help/contrib file
    is now build from a copy of CONTRIB-CODE.

    Created a new calc bug report Email address.  Created a new
    calc question Email address.  Created a new calc contribution
    Email address.  See the BUGS file for details.

    Added "help questions" to print the QUESTIONS help file.

    If the environment variable $CALCHELP is defined and is non-empty,
    then calc help files will be in the directory by the $CALCHISTFILE
    environment variable.

    If the environment variable $CALCCUSTOMHELP is defined and is
    non-empty, then custom calc help files will be in the directory
    by the $CALCCUSTOMHELP environment variable.

    Fixed a number of typos in text and in source code comments.

    The calc-tester mailing list has been retired.  See:

        * How to submit a calc bug report:

            http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html

        * How to contribute code to calc:

            http://www.isthe.com/chongo/tech/comp/calc/calc-contrib.html

        * How to submit a question about calc:

            http://www.isthe.com/chongo/tech/comp/calc/calc-question.html
2021-02-12 22:35:46 -08:00
Landon Curt Noll
c02725f036 Update copyright date to 2021 for all prev typo fixes 2021-02-12 22:27:51 -08:00
Landon Curt Noll
507fe026e5 Fix many spelling errors 2021-02-12 22:09:47 -08:00
Landon Curt Noll
486f4c5626 Update a few copyright years to 2021 2021-02-12 16:07:00 -08:00
Landon Curt Noll
91991bb729 Checkpoint on calc version 2.12.8.0
Fixed a mistake in "help intro" where some inserted text
    changed the value of "." and thus made the next result
    incorrect.

    Clarified in "help factor" that 1 is returned if no
    factor below the limit was found.

    Removed Makefile variable ${MAKEFILE_REV}.

    The missing cscript/square.calc file has been restored.

    Fixed compiler errors and warnings related to GCC.
    In particular, gcc/9.3.1 and gcc/10.2.1 now compile
    calc without any compiler errors or warnings,
    even with -Werror -Wextra -pedantic.

    To print out information about the calc compliation
    environment, we added the following make rule:

	make calcinfo

    Improved how 'make debug' operates.

    Moved help/contrib to CONTRIB-CODE.  The help/contrib file
    is now build from a copy of CONTRIB-CODE.

    Created a new calc bug report Email address.  Created a new calc
    question Email address.  Created a new calc contribution Email
    address.  See the BUGS file for details.

    Added "help questions" to print the QUESIONS help file.

    If the environment variable $CALCHELP is defined and is non-empty,
    then calc help files will be in the direcgory by the $CALCHISTFILE
    environment variable.

    If the environment variable $CALCCUSTOMHELP is defined and is
    non-empty, then custom calc help files will be in the direcgory
    by the $CALCCUSTOMHELP environment variable.

    The calc-tester mailing list has been retired.  See:

	* How to submit a calc bug report:

	    http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html

	* How to contribute code to calc:

	    http://www.isthe.com/chongo/tech/comp/calc/calc-contrib.html

	* How to submit a question about calc:

	    http://www.isthe.com/chongo/tech/comp/calc/calc-question.html
2021-02-12 15:50:39 -08:00
Landon Curt Noll
71a116ca6f Fix gcc/9.3.1 and gcc/10.2.1 errors and warnings 2021-02-04 17:20:20 -08:00
Landon Curt Noll
8b7e01f426 Added missing malloc failure checks 2021-02-04 15:28:51 -08:00
Landon Curt Noll
229345ade8 Release 2.12.7.6
The following are the changes in this release:

    The missing cscript/square.calc file has been restored.
2021-02-03 13:03:50 -08:00
Landon Curt Noll
0f902b95cf Clarify when factor() builtin returns 1
Clarify that the factor() builtin return 1
if it does not find a factor below the limit.
2021-02-03 12:45:10 -08:00
Landon Curt Noll
8684e1be9c Fix for missing cscript/simple.calc in tarball 2021-02-03 12:44:11 -08:00
Landon Curt Noll
ae3a6129b2 Release 2.12.7.5
Final cleanup for the calc version 2.12.7.5 release.
2021-02-03 03:24:47 -08:00
Landon Curt Noll
2c72570b8d Fixed 0^(0) and 0^(6-6) to return 1
Calc as defined 0^0 as 1.  However in the past, 0 raised to
an expression that evaluted to zero returned 1.  The result
was that 0^0 was different than 0^(6-6) or even 0^(0).
Now, calc will return 1 for 0^(0) and 0^zero when zero == 0.
2021-02-03 01:44:17 -08:00
Landon Curt Noll
41803b878e Added use of $CALCHISTFILE and start of 2.12.7.5
By default, the calc history file is located in ~/.calc_history.
Now, if the environment variable $CALCHISTFILE is defined
and is non-empty, then calc history file will be defined
by the $CALCHISTFILE environment variable.
2021-02-03 00:51:56 -08:00
Landon Curt Noll
a8be58becb Merge pull request #8 from jcul/master
Fix compilation with GCC 7+
2021-02-02 23:45:34 -08:00
Landon Curt Noll
067afc140a Merge pull request #7 from thegithubr/patch-1
Little fix
2021-02-02 23:42:05 -08:00
Landon Curt Noll
41128fada9 Merge pull request #12 from guilhermgonzaga/master
Fix typos; Insert missing lines in README.md
2021-02-02 23:41:22 -08:00
Landon Curt Noll
f5fae012f9 Release 2.12.7.4 2021-02-02 23:03:37 -08:00
Landon Curt Noll
3d25fb30cb Release 2.12.7.4 2021-02-02 23:03:10 -08:00
Landon Curt Noll
8374586275 Merge branch 'master' of https://github.com/lcn2/calc 2021-02-02 23:02:24 -08:00
Landon Curt Noll
68c2edf610 Release 2.12.7.4
These changes are per calc version 2.12.7.3:

Requiring calc shell scripts to use -s -f at the end of the
initial #! line.

Fixed /tmp/mersenne example in calc(1) man page.

Added make variable ${ARCH_CFLAGS}.  The ${ARCH_CFLAGS} is
added after ${CCMISC} and before ${EXTRA_CFLAGS} when building
the ${CFLAGS} for compiling C code.  are ${CC} when compiling
C files.  The default value is:

ARCH_CFLAGS= -march=native

which directs C compiler to compile for the native machine.
To disable use of '-march=native', set ARCH_CFLAGS to the empty
string as in:

make all ARCH_CFLAGS=

To make calc RPMs more portable, they are compiled with an
empty ARCH_CFLAGS.

These changes are per calc version 2.12.7.4:

Fixed issues relating to compiling on macOS.  Fixed issues
where <unistd.h> is needed.
2021-02-02 23:01:11 -08:00
Landon Curt Noll
d58a55a1ed Release 2.12.7.3
Requiring calc shell scripts to use -s -f at the end of the
initial #! line.

Fixed /tmp/mersenne example in calc(1) man page.

Added make variable ${ARCH_CFLAGS}.  The ${ARCH_CFLAGS} is
added after ${CCMISC} and before ${EXTRA_CFLAGS} when building
the ${CFLAGS} for compiling C code.  are ${CC} when compiling
C files.  The default value is:

ARCH_CFLAGS= -march=native

which directs C compiler to compile for the native machine.
To disable use of '-march=native', set ARCH_CFLAGS to the empty
string as in:

make all ARCH_CFLAGS=

To make calc RPMs more portable, they are compiled with an
empty ARCH_CFLAGS.

Fixed issues relating to compiling on macOS.  Fixed issues
where <unistd.h> is needed.
2021-02-02 22:54:51 -08:00
Landon Curt Noll
ccfa797b68 Changes as per calc 2.12.7.3 2021-02-02 20:33:59 -08:00
Guilherme Gonzaga de Andrade
0f030f0759 Fix typos; Insert missing lines in README.md
Fixed typos in help/intro and README.md;
Copied missing description lines from help/intro to README.md "What is calc?"
section.
2020-03-03 11:27:23 -04:00
Jack Culhane
af59b9dab2 One FALLTHRU comment was inconsistent with others 2019-05-17 17:31:02 +01:00
Jack Culhane
fa173cd9aa Fix spaces vs tabs and use FALLTHRU as it's used elsewhere 2019-05-17 17:18:07 +01:00
Jack Culhane
1f8269c0e2 Comment fallthrough case statements so compilation succeeds with GCC 7.
GCC 7 Added a warning for implicit fallthroughs in switch cases.
It's enabled by -Wextra, and treated as an error due to -Werror so
compilation fails on GCC 7 and higher.
See -Wimplicit-fallthrough in the GCC manual.
2019-05-17 17:00:48 +01:00
thegithubr
51462b8612 Little fix
A little fix
2019-02-22 13:49:25 +01:00
Landon Curt Noll
9b69648921 Fix long lines in lib_calc.c 2018-11-28 12:33:10 -08:00
Landon Curt Noll
c5e416c41f Release calc 2.12.7.2
Fixed a segfault when getpwuid() returned NULL during initialization.
Thanks goes to baratharon GitHub user for reporting this issue.
2018-11-28 12:27:04 -08:00
Landon Curt Noll
37ad43c7fd Release calc 2.12.7.1
Corrected CHANGES notes that were mixed up for TAB, VT, CR &
NL.  The code in 2.12.7.0 is correct.  The CHANGE notes should
have read:

The following is a partial list of escape sequences recognized
in strings and in printf formats:

    \a	audible bell	byte 0x07 in ASCII encoding
    \b	backspace	byte 0x08 in ASCII encoding
    \f	form feed	byte 0x0c in ASCII encoding
    \n	newline		byte 0x0a in ASCII encoding
    \r	return		byte 0x0d in ASCII encoding
    \t	tab		byte 0x09 in ASCII encoding
    \v	vertical tab	byte 0x0b in ASCII encoding

Sorry!
2018-11-05 08:02:09 -08:00
Landon Curt Noll
a877cb52c0 Corrected CHANGES notes
Corrected CHANGES notes that were mixed up for TAB, VT, CR & NL.
The core in 2.12.7.0 is correct.  The CHANGE notes were mixed up.
Sorry!
2018-11-05 07:33:40 -08:00
Landon Curt Noll
4bec694df3 Release calc version 2.12.7.0
The following are the changes from calc version 2.12.7.0 to date:

    Added a patch to replaces the manual search for include files
    in $(INCDIR) in the have_*.h targets with compiler invocations.
    Thanks goes to Helmut Grohne (helmut at subdivi dot de) who
    implemented the patch and posted it to the Debian bug tracker
    and Martin Buck (m at rtin-buck dor de) for forwarding it to us.

    The check_include make rule was fixed to not assume /usr/include.

    The qprintnum() function now takes outdigits as a 3rd argument.
    Most of the time, this 3rd argument is just conf->outdigits.
    But when it comes to the experimental '%g', this value can
    change.  This avoids having to modify conf->outdigits.

    Fixed a problem where gcc complains about E_FUNC not being defined
    for Linux systems as reported by Martin Buck (m at rtin-buck dor de).

    Updated the help files help/config, help/display, help/epsilon,
    help/fprint, help/printf, and help/strprintf to give more
    examples of how display digits and epsilon precision interact
    with displaying values.

    Added more information about %g in the help file help/printf.

    The '\a' is now recognized in a printf format string as the
    single byte audible bell character (byte 0x07 in ASCII encoding).

    The following is a partial list of escape sequences recognized
    in strings and in printf formats:

        \a      audible bell    byte 0x07 in ASCII encoding
        \b      backspace       byte 0x08 in ASCII encoding
        \f      form feed       byte 0x0c in ASCII encoding
        \n      newline         byte 0x0b in ASCII encoding
        \r      return          byte 0x0a in ASCII encoding
        \t      tab             byte 0x0d in ASCII encoding
        \v      vertical tab    byte 0x09 in ASCII encoding
2018-11-04 17:11:31 -08:00
Landon Curt Noll
4870a7a164 Sync check_include rule with Makefile.ship 2018-11-04 17:10:46 -08:00
Landon Curt Noll
84ccb37bc3 Regualrize escape characters
Regularized the case statements in qio.c, str.c, and token.c
that relate to escape characters.

The '\a' is now recognized in a printf format string as the
single byte audible bell character (byte 0x07 in ASCII encoding).

The following is a partial list of escape sequences recognized
in strings and in printf formats:

    \a      audible bell    byte 0x07 in ASCII encoding
    \b      backspace       byte 0x08 in ASCII encoding
    \f      form feed       byte 0x0c in ASCII encoding
    \n      newline         byte 0x0b in ASCII encoding
    \r      return          byte 0x0a in ASCII encoding
    \t      tab             byte 0x0d in ASCII encoding
    \v      vertical tab    byte 0x09 in ASCII encoding
2018-11-04 17:08:11 -08:00
Landon Curt Noll
29c6e9325f Fix issue with E_FUNC under linux
Fixed a problem where gcc complains about E_FUNC not being defined
for Linux systems as reported by Martin Buck (m at rtin-buck dor de).
2018-11-04 17:01:24 -08:00
Landon Curt Noll
81a4a4f828 Improve string and printing documentation
Updated the help files help/config, help/display, help/epsilon,
help/fprint, help/printf, and help/strprintf to give more
examples of how display digits and epsilon precision interact
with displaying values.

Added more information about %g in the help file help/printf.

The '\a' is now recognized in a printf format string as the
single byte audible bell character (byte 0x07 in ASCII encoding).

The following is a partial list of escape sequences recognized
in strings and in printf formats:

    \a      audible bell    byte 0x07 in ASCII encoding
    \b      backspace       byte 0x08 in ASCII encoding
    \f      form feed       byte 0x0c in ASCII encoding
    \n      newline         byte 0x0b in ASCII encoding
    \r      return          byte 0x0a in ASCII encoding
    \t      tab             byte 0x0d in ASCII encoding
    \v      vertical tab    byte 0x09 in ASCII encoding
2018-11-04 17:00:15 -08:00
Landon Curt Noll
1cdb5172d8 Fix Makefile lines that picky complains about 2018-10-19 19:41:58 -07:00
Landon Curt Noll
54a7a3f7bc Release 2.12.6.10
Added a patch to replaces the manual search for include files
    in $(INCDIR) in the have_*.h targets with compiler invocations.
    Thanks goes to Helmut Grohne <helmut at subdivi dot de> who
    implemented the patch and posted it to the Debian bug tracker
    and Martin Buck (m at rtin-buck dor de) for forwarding it to us.

    The check_include make rule was fixed to not assume /usr/include.

    The qprintnum() function now takes outdigits as a 3rd argument.
    Most of the time, this 3rd argument is just conf->outdigits.
    But when it comes to the experimental '%g', this value can
    change.  This avoids having to modify conf->outdigits.
2018-10-19 19:33:57 -07:00
Landon Curt Noll
2ea77e6151 Release 2.12.6.9
Experimental changes for macOS builds.
2018-10-15 19:37:48 -07:00
Landon Curt Noll
5cfa6199e5 Merge branch '10110111-master' 2018-09-30 16:11:23 -07:00
Landon Curt Noll
da6ccc146f Improvements to %g pull request
This code %g is preliminary.

Fixed some code style issues to match the current code style.

Added regression tests and help file updates to printf and strprintf.

Fixed use of magic number -4: using -P instead.

Noted two problem areas with XXX comments in qio.c:

    1) need a qprintfg function
    2) re-write to not modify conf->outdigits
2018-09-30 16:06:28 -07:00
Landon Curt Noll
fcfe237375 Merge branch 'master' of https://github.com/10110111/calc into 10110111-master 2018-09-30 14:22:41 -07:00
Landon Curt Noll
5fb3db4558 Fixed trigonometric and hyperbolic core dumps 2018-09-30 14:08:20 -07:00
Landon Curt Noll
c8705c1198 Release calc 2.12.6.8
The following are the changes in this release:

    For historical purposes, in lucas.cal, gen_v1(1, n) always returns 4.

    Fixed some compiler warnings, thanks to a report by Mike
    <michael dot d dot ince at gmail dot com>.

    Added work around for a gcc warning bug, thanks to a report by Mike
    <michael dot d dot ince at gmail dot com>.

    Fixed errors in various help files such as:

	mat randbit seed srandom types

    Removed the MAXSTRING symbol because it was no longer used by calc.

    Increased HIST_SIZE (depth of the history stack) from 10k to 32k.

    Increased TTYSIZE (reallocation size for terminal buffers) from 100 to 8191.

    Increased MAXDEPTH (maximum depth of input stack) from 10 to 255.

    Increased interactive input buffer size from 1024 to 256k.  This has the
    effect of increasing the maximum length of an input line from a tty.
    This helps with an interactive bug that was reported by Ruslan Kabatsayev
    (b7 dot 10110111 at gmail dot com).

    The calc man page indicates that -d also disables the printing of the
    leading tilde.

    Added information to "help command" about how to silence messages
    while reading calc resource files.

    Fixed an error message buffer overflow thanks to a report by
    Frank Peters <nlp at northernlightsphoto dot biz>.

    Replaced all use of the C funcion sprintf() with snprintf().
    Replaced all use of the C funcion vsprintf() with vsnprintf().
    Replaced all DONT_HAVE_VSPRINTF with DONT_HAVE_VSNPRINTF.
    Replaced all Makefile var ${HAVE_VSPRINTF} with ${HAVE_VSNPRINTF}.
2018-09-30 10:25:18 -07:00
Ruslan Kabatsayev
0558bafcb6 Use MODE_REAL_AUTO by default instead of MODE_REAL
This will save the user from embarrassment due to getting
~0.00000000000000000000 as the result instead of e.g. 1.23e-53.
2018-06-30 18:44:14 +03:00
Ruslan Kabatsayev
f58277f53d Implement %g format for printf 2018-06-30 18:35:35 +03:00
Landon Curt Noll
e555a718c0 Released calc 2.12.6.7 with help and input fixes
Fixed errors in various help files such as:

	mat randbit seed srandom types

    Removed the MAXSTRING symbol because it was no longer used by calc.

    Increased HIST_SIZE (depth of the history stack) from 10k to 32k.

    Increased TTYSIZE (reallocation size for terminal buffers) from 100 to 8191.

    Increased MAXDEPTH (maximum depth of input stack) from 10 to 255.

    Increased interactive input buffer size from 1024 to 256k.  This has the
    effect of increasing the maximum length of an input line from a tty.
    This helps with an interactive bug that was reported by Ruslan Kabatsayev
    (b7 dot 10110111 at gmail dot com).
k
2018-03-04 11:09:09 -08:00
Landon Curt Noll
b29fcf2dd5 Fixed errors in various help files 2018-02-27 18:21:46 -08:00
Landon Curt Noll
4f86703843 Fix long lines 2018-02-27 16:16:06 -08:00
Landon Curt Noll
07d8bf0f3e Version 2.12.6.6 2018-02-21 12:38:39 -08:00
Landon Curt Noll
b4cd692bae Fixed compiler warnings
Fixed some compiler warnings.
Added work around for a gcc warning bug.
2018-02-21 12:37:46 -08:00
Landon Curt Noll
83c898cc2b Improved how lucas.cal pre-verifies numbers 2018-02-21 12:36:21 -08:00
Landon Curt Noll
c585d7aa78 Release calc version 2.12.6.5 2018-01-28 18:26:08 -08:00
Landon Curt Noll
f42a003d04 Improve formatting of comments in cal/lucas.cal 2018-01-16 15:33:00 -08:00
Landon Curt Noll
8da0471f07 Release calc version 2.12.6.4
Fixed a man page warning about ./myfile where the leading dot
was mistook for an nroff macro.  Thanks goes to David Haller
<dnh at opensuse dot org> for providing the patch.

Improved gen_v1(h,n) in lucas.cal for cases where h is not a
multiple of 3. Optimized the search for v(1) when h is a
multiple of 3.

Fixed a Makefile problem, reported by Doug Hays <doughays6 at gmail
dot com>, where if a macOS user set BINDIR, LIBDIR, CALC_SHAREDIR
or INCDIR in the top section, their values will be overwritten by
the Darwin specific section.
2018-01-16 15:27:13 -08:00
Landon Curt Noll
1c20261b93 Fixed macro warning about ./myfile 2017-09-07 14:28:54 -07:00
Landon Curt Noll
aeb9a9d473 Prepare for calc version 2.12.6.3 2017-09-06 18:20:35 -07:00
Landon Curt Noll
66883b390d Fixed CHANGES typo 2017-09-06 18:11:35 -07:00
Landon Curt Noll
ea533659ce Release calc version 2.12.6.2 2017-09-06 17:42:41 -07:00
Landon Curt Noll
9e81971f25 Verify that h*2^n-1 is not a multiple of 3 2017-09-06 17:41:56 -07:00
Landon Curt Noll
cbbd866535 Fixed a misleading indent reported by Thomas Walter 2017-09-06 17:40:49 -07:00
Landon Curt Noll
bf23f82c29 Correct comments relating to v(1) search table 2017-06-18 08:11:43 -07:00
Landon Curt Noll
ec5c584785 Fixed typo in lucas.cal comment 2017-06-18 04:11:44 -07:00
Landon Curt Noll
6bbb8c0e42 Update v(1) stats with full 1000000 test sample 2017-06-18 03:50:28 -07:00
Landon Curt Noll
438554b0ed Make a minor speedup to gen_v1(h,n) in lucas.cal 2017-06-14 16:50:58 -07:00
Landon Curt Noll
61ba4bc5c8 Improve lucas.cal v(1) search method & remarks 2017-06-14 16:30:42 -07:00
Landon Curt Noll
0145883396 Improved lucas.cal vt tables and arg checking 2017-06-09 15:44:48 -07:00
Landon Curt Noll
f91bfaab70 Prep for calc version 2.12.6.1 2017-06-05 21:05:25 -07:00
359 changed files with 24457 additions and 8315 deletions

View 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.2 2022-02-24
**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 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 make debug output**
IMPORTANT: Please attach the output from `make debug`.
**Screenshots**
If applicable, attach screenshots 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 Monterey, contents of /etc/redhat-releaseor /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.

View 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
View File

@@ -0,0 +1,71 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '41 1 * * 6'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'cpp' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

16
.gitignore vendored
View File

@@ -6,7 +6,6 @@
#
.dynamic
.hsrc
Makefile.simple
NOTES
align32.h
args.h
@@ -16,6 +15,7 @@ calc.1
calc.usage
calcerr.c
calcerr.h
charbit.h
conf.h
cscript/.all
cscript/4dsphere
@@ -28,18 +28,21 @@ cscript/powerterm
cscript/simple
cscript/square
custom/.all
custom/Makefile.simple
custom/libcustcalc*
endian
endian_calc.h
fposval.h
have_arc4random.h
have_ban_pragma.h
have_const.h
have_environ.h
have_fpos.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
@@ -49,6 +52,8 @@ have_stdlib.h
have_stdvs
have_strdup.h
have_string.h
have_strlcat.h
have_strlcpy.h
have_times.h
have_uid_t.h
have_unistd.h
@@ -65,6 +70,7 @@ help/bugs
help/builtin
help/change
help/changes
help/contrib
help/copy
help/cscript
help/custom_cal
@@ -76,6 +82,9 @@ help/funclist.c
help/libcalc
help/man
help/new_custom
help/question
help/questions
help/releases
help/resource
help/type
help/usage
@@ -83,10 +92,13 @@ libcalc*
libcustcalc*
longbits
longbits.h
Makefile.our
sample_many
sample_rand
tags
terminal.h
ver_calc
win32/
# other commonly excluded patterns
#

174
BUGS
View File

@@ -1,12 +1,12 @@
If you notice something wrong, strange or broken, try rereading:
README.FIRST
HOWTO.INSTALL
BUGS (this file)
README.FIRST
HOWTO.INSTALL
BUGS (this file)
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:
@@ -15,74 +15,133 @@ Look at the end of the output, it should say something like:
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
configuration, try backing them out and see if things get better.
configuration, try backing those changges 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,
then it may be time to send in a bug report.
=-=
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
and bug fixes reports to:
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:
calc-bug-report at asthe dot com
https://github.com/lcn2/calc/pulls
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
=-=
This replaces the old calc-bugs at asthe dot com address.
If you just want to send us a bug report, we recommend
doing so via the GitHub issue process:
To be sure we see your EMail reporting a calc bug, please use the
following phase in your EMail Subject line:
https://github.com/lcn2/calc/issues
calc bug report
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:
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.
I have this issue too
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.
If you don't see your issue addressed, then on the above
GitHub web page, click on this button:
When you send your report, please include the following information:
((New Issue))
* 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)
If you prefer to not use GitHub, then you
may send bug and bug fixes reports to:
and send the contents of the 'debug.out' file.
calc-bugrept-mail at asthe dot com
Stack traces from core dumps are useful to send as well.
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
Fell free to use the above address to send in big fixes (in the form
NOTE: This replaces the old calc-bugs at asthe dot com address.
PLEASE put following the SPECIAL PHRASE somewhere in your Email Subject line:
calc bug report
You may add additional words to your subject line.
Suggestion:
From time to time, the Email address and Subject SPECIAL PHRASE
may change so verify you have the current info by visiting:
http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
IMPORTANT:
PLEASE use the above SPECIAL PHRASE somewhere in the Subject line or
the mail system won't deliver your Email message.
Keep in mind that the best way to report on a calc bug is
via the above mentioned calc GitHub issue URL.
Please be patient as we cannot always respond to Email messages quickly.
=-=
When you send your report, via the calc GitHub issue URL or Email,
please include the following information:
* 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 produced by this command:
make debug > debug.out 2>&1
Fell free to use the above address to send in bug fixes (in the form
of a context diff patch).
=-=
Known bugs:
Known bugs in calc:
The output of the alg_config.cal resource file is bogus.
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
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.
=-=
@@ -135,32 +194,7 @@ mis-features in calc:
=-=
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.
## 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
## the terms of the version 2.1 of the GNU Lesser General Public License

1148
CHANGES

File diff suppressed because it is too large Load Diff

128
CODE_OF_CONDUCT.md Normal file
View 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.

100
CONTRIB-CODE Normal file
View File

@@ -0,0 +1,100 @@
Calc is open source. Contributions of code are welcome.
We welcome and encourage you to send us:
* calc resource files (cal/*.cal files)
* calc shell scripts (cscript/*.calc files)
* builtin functions that you have modified or written, i.e.:
assocfunc.c comfunc.c func.c func.h
listfunc.c matfunc.c qfunc.c zfunc.c
* custom functions that you have modified or written
* help files modified or written (help/*)
* Makefile improvements (Makefile, */Makefile)
* other source code modifications (*.c, *.h)
* etc. (* */* :) )
In order to consider integrating your code, we need:
* calc version you are working with (please try use the latest version)
* new help files or help file patches, if applicable (documentation)
* proposed text for the CHANGES file (brief description of what it does)
* regress.cal test patch as needed
* your source code and/or source code changes (:-))
If you add functionality to calc, please be sure to modify/patch/add
Makefiles, help files, cal/regress.cal test code as well.
Regression test cases are vital to maintaining calc's level
of correctness and helps us avoid code bug regression.
Please try to generate a patch against the most recent
version of calc, and if you use GitHub, the top of the
master branch:
https://github.com/lcn2/calc
The best way contribute to calc bug is to generate calc
GitHub pull request:
https://github.com/lcn2/calc/pulls
Your code needs to be contributed under either the 2.1 of the GNU
Lesser General Public License (LGPL 2.1) or in the public domain.
If you do not want to use calc GitHub, then send Email to:
calc-contrib-mail at asthe dot com
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
You MUST use following SPECIAL PHRASE in your Email Subject line:
calc contribution
You may add additional words to your subject line.
Suggestion:
From time to time, the Email address and Subject SPECIAL PHRASE
may change so verify you have the current info by visiting:
http://www.isthe.com/chongo/tech/comp/calc/calc-contrib.html
IMPORTANT: If your Email doesn't contain the above phrase,
then we WILL NOT SEE your Email.
PLEASE BE SURE you have that SPECIAL PHRASE somewhere in the subject line!
Keep in mind that the best way to report on a calc bug is to use
the above mentioned calc GitHub procedure.
Please be patient as we cannot always respond to Email messages quickly.
=-=
See also the calc wishlist by running the calc command:
; help wishlist
=-=
## Copyright (C) 1999,2014,2021 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License
## 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
View 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.

61
COPYING
View File

@@ -6,7 +6,7 @@ This file is Copyrighted
This file is covered under the following Copyright:
Copyright (C) 1999-2014 Landon Curt Noll
Copyright (C) 1999-2021 Landon Curt Noll
All rights reserved.
Everyone is permitted to copy and distribute verbatim copies
@@ -49,65 +49,6 @@ Calc is covered by the GNU Lesser General Public License
Boston, MA 02110-1301
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
------------------------------------------------------------

View File

@@ -1,10 +1,23 @@
Installing calc from the bzip2-ed tarball in 4 easy steps:
0) If your platform supports i686 RPMs, you may want to go to:
IMPORTANT: Please see the section at the bottom of this file for
some important information on Makefiles used in calc.
http://www.isthe.com/chongo/src/calc/
###################################################################
# IMPORTANT: DO NOT use make in parallel mode!!! #
###################################################################
# Unfortunately due to the complex dependency issues between #
# Makefile, Makefile.ship and custom/Makefile, parallel make #
# is NOT recommended. Sorry (tm Canada) :) #
###################################################################
and use these RPMs:
Installing calc from the bzip2-ed tarball: 4 easy steps:
(0) If your platform supports i686 RPMs, you may want to go to:
https://github.com/lcn2/calc/releases
Open up the 'Assets' tag below a given release and
download these RPMs:
* calc*.i686.rpm
- all that is needed if you just want to use calc
@@ -13,27 +26,138 @@ Installing calc from the bzip2-ed tarball in 4 easy steps:
- calc *.h header and *.a lib files for use in other programs
* calc.*.src.rpm
- calc source in RPM package form
- calc source via a SRPM package
The following 4 steps apply to calc source tree that comes from either:
Alternately to the above github link, you might try looking at
the RPMs under:
bunzip2 -c calc-*.tar.bz2 | tar -xvf -
http://www.isthe.com/chongo/src/calc/
or from:
=-=
rpm -ivh calc-*.src.rpm
cd /var/tmp
bunzip2 -c /usr/src/redhat/SOURCES/calc-*.tar.bz2 | tar -xvf -
The following 4 steps apply to calc source tree that comes from either:
1) Look at the makefile, and adjust it to suit your needs.
bunzip2 -c calc-*.tar.bz2 | tar -xvf -
The top level Makefile and the custom/Makefile require a GNU
or from:
rpm -ivh calc-*.src.rpm
cd /var/tmp
bunzip2 -c /usr/src/redhat/SOURCES/calc-*.tar.bz2 | tar -xvf -
4 steps:
(1) Look at the makefile, and adjust it to suit your needs.
The top level Makefile and the custom/Makefile require a modern
Make (such as gmake) or an equivalently advanced make. On many
targets, the default make is sufficent. On FreeBSD for example,
one must use gmake instead of make.
targets, the default make is sufficient. On FreeBSD for example,
probably want to use gmake instead of make.
If your target system does not have GNU Make (or equivalent), then
you should try using the Makefile.simple and custom/Makefile.simple
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! By default, calc assumes you have the readline package installed !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! macOS does not have readline, so mac users need to make a choice !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
The readline package (-lreadline, -lhistory, -lncurses) used by and
linked into calc by default. If your system does NOT have those
libaraies, then you have two options:
(1-with readline) Install the readline package <- Recommended
Install the readline package first, then compile calc.
For information on the readline package, see:
https://tiswww.case.edu/php/chet/readline/rltop.html
MacOS users can use MacPorts or HomeBrew to install readline:
https://www.macports.org
https://brew.sh
Or compile from the readline.git repo:
http://git.savannah.gnu.org/cgit/readline.git/
(1-w/o readline) Compile calc without readline (not recommended)
Why do we not recommend (1b)? Because using calc with readline
provides a beter user experience.
If you feel you must use calc without the readline package, then you
will need to change your calc Makefile with this patch:
--- Makefile.old 2021-12-29 14:57:56.000000000 -0800
+++ Makefile 2021-12-29 14:59:13.000000000 -0800
@@ -1140,14 +1140,14 @@
#
# If in doubt, set USE_READLINE, READLINE_LIB and READLINE_INCLUDE to nothing.
#
-#USE_READLINE=
-USE_READLINE= -DUSE_READLINE
+USE_READLINE=
+#USE_READLINE= -DUSE_READLINE
#
-#READLINE_LIB=
-#READLINE_EXTRAS=
+READLINE_LIB=
+READLINE_EXTRAS=
#
-READLINE_LIB= -lreadline
-READLINE_EXTRAS= -lhistory -lncurses
+#READLINE_LIB= -lreadline
+#READLINE_EXTRAS= -lhistory -lncurses
#
#READLINE_LIB= -L/usr/gnu/lib -lreadline
#READLINE_EXTRAS= -lhistory -lncurses
@@ -1181,8 +1181,8 @@
# # and using the readline, history, and ncurses libraries.
# #
ifneq ($(HOMEBREW_PREFIX),)
-READLINE_LIB:= -L${HOMEBREW_PREFIX}/opt/readline/lib -lreadline
-READLINE_INCLUDE:= -I${HOMEBREW_PREFIX}/opt/readline/include
+#READLINE_LIB:= -L${HOMEBREW_PREFIX}/opt/readline/lib -lreadline
+#READLINE_INCLUDE:= -I${HOMEBREW_PREFIX}/opt/readline/include
endif
#
#endif /* end of skip for non-Gnu makefiles */
If your target system does not have a modern Makefile
(such as gmake), then you will need to change your
Makefile.simple with this patch:
--- Makefile.simple.orig 2021-12-29 15:00:53.000000000 -0800
+++ Makefile.simple 2021-12-29 15:01:00.000000000 -0800
@@ -1005,14 +1005,14 @@
#
# If in doubt, set USE_READLINE, READLINE_LIB and READLINE_INCLUDE to nothing.
#
-#USE_READLINE=
-USE_READLINE= -DUSE_READLINE
+USE_READLINE=
+#USE_READLINE= -DUSE_READLINE
#
-#READLINE_LIB=
-#READLINE_EXTRAS=
+READLINE_LIB=
+READLINE_EXTRAS=
#
-READLINE_LIB= -lreadline
-READLINE_EXTRAS= -lhistory -lncurses
+#READLINE_LIB= -lreadline
+#READLINE_EXTRAS= -lhistory -lncurses
#
#READLINE_LIB= -L/usr/gnu/lib -lreadline
#READLINE_EXTRAS= -lhistory -lncurses
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! By default, calc assumes you are using a modern gnu-like make tool !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
If your target system does not have a modern Makefile (such as gmake),
then you should try using the Makefile.simple and custom/Makefile.simple
files:
mv Makefile Makefile.gmake
@@ -46,10 +170,18 @@ Installing calc from the bzip2-ed tarball in 4 easy steps:
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. !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
If you are using a modern make (such as gmake), you may override
any values set in the Makefile by adding them to Makefile.local
using the := directive. For example:
HAVE_STRING_H:= YES
HAVE_TIMES_H:= YES
SED:= /usr/local/bin/nsed
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! If you are building under Windows or a Windows-like environment !
! (such as Cygwin or DJGPP), read the README.WINDOWS file. !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
You should determine if these Makefile variables are reasonable:
@@ -57,7 +189,7 @@ Installing calc from the bzip2-ed tarball in 4 easy steps:
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.
config files.
You may want to change the default installation locations for
these values, which are based on the 4 values listed above:
@@ -78,13 +210,13 @@ Installing calc from the bzip2-ed tarball in 4 easy steps:
For example, if:
BINDIR= /usr/bin
BINDIR= /usr/bin
LIBDIR= /usr/lib
CALC_SHAREDIR= /usr/share/calc
and if:
T= /var/tmp/testing
T= /var/tmp/testing
Then the installation locations will be:
@@ -110,7 +242,7 @@ Installing calc from the bzip2-ed tarball in 4 easy steps:
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:
You may want to change these Makefile variables from their defaults:
RANLIB
@@ -138,11 +270,11 @@ Installing calc from the bzip2-ed tarball in 4 easy steps:
Adjust other Makefile variables as needed.
2) build calc:
(2) build calc:
The top level Makefile and the custom/Makefile require a GNU
Make (such as gmake) or an equivalently advanced make. On many
targets, the default make is sufficent. On FreeBSD for example,
targets, the default make is sufficient. On FreeBSD for example,
one must use gmake instead of make.
If your target system does not have GNU Make (or equivalent), then
@@ -170,25 +302,194 @@ Installing calc from the bzip2-ed tarball in 4 easy steps:
make clobber
make calc-dynamic-only BLD_TYPE=calc-dynamic-only
3) test calc:
(3) test calc:
make check
==> If you run into problems, read the BUGS file and follow
the instructions found in there.
make check
NOTE: For a quiet check which only prints if something goes wrong:
make chk
make chk
4) install calc:
(4) install calc:
make install
make install
We suggest that you might want to read the README.FIRST file and look at
the calc help subsystem. See also the README.md file.
## Copyright (C) 1999-2007 Landon Curt Noll
In general, if you run into problems, read the BUGS file and follow
the instructions.
=-=
On calc Makefiles:
How to tell the origin of of a Makefile:
The "# SRC: ... - ..." comment line near the top
of the file indicates the origin of this file.
In each segment below, we indicate what the SRC
comment like will read.
SHELL= ...
On some systems, /bin/sh is a rather reduced shell with
deprecated behavior.
If your system has a up to date, bash shell, then
you may wish to edit the Makefile to use:
SHELL= /bin/bash
On some systems such as macOS, the bash shell is very
far behind to the point where is cannot be depended on.
On such systems, the sh may be a much better alternative
shell for this Makefile to use:
SHELL= /bin/sh
Makefile.local
# SRC: Makefile.local - tweaks to the top level Makefile
Between releases, Makefile.local at the top of the master branch
will contain how we typically build calc and test calc (FYI: we
normally enable things such as -Werror -Wextra -pedantic). When we
push out a release, Makefile.local will be stripped of non-comment
lines. Thus, releases of calc, and, released "calc*.src.rpm"
files and the source tarballs, will have a Makefile.local with
only comments.
If the Makefile is not suitable for you (say because you fetch it
from the top of the master branch between releases), then you may
wish to remove all non-comment lines. I.e., lines that do not start
with the # character.
This Makefile.local assumes you have a modern make command such as
the GNU make. See Makefile.simple comment below if you do not
have such a modern make command.
In the calc GitHub repo, Makefile is the calc build environment
and Makefile.ship is the top level Makefile:
https://github.com/lcn2/calc
Makefile
# SRC: Makefile.ship - top level Makefile
This is the main top level Makefile.
In calc packages such as RPMs, and the tar.bz2 source tarball,
Makefile.ship has been moved into Makefile.
In the calc GitHub repo, Makefile is the calc build environment
and Makefile.ship is the top level Makefile:
https://github.com/lcn2/calc
The Makefile.simple rule of Makefile.ship, when forming the
Makefile.simple file, removes lines from Makefile.ship between
pairs of '#if 0' AND '#endif':
#if 0
lines removed when forming Makefile.simple
...
lines removed when forming Makefile.simple
#endif
The '#if 0' AND '#endif' MUST be at the start of the line.
Any text after the '#if 0' OR '#endif' is ignored.
While they may look like a CPP directives, they are not. The
inline awk script of the Makefile.simple rule does NOT allow
them to nest:
#if 0 /* DO NOT DO THIS */
lines removed when forming Makefile.simple
...
#if 0 /* DO NOT DO THIS */
...
#endif /* DO NOT DO THIS */
...
#endif /* DO NOT DO THIS */
Makefile.simple
# SRC: Makefile.simple - non-GNU version
This is a non-GNU or simple Makefile designed for environments
that do not have a modern make command.
If you have a Makefile.simple file, use these commands to
form a Makefile:
if [ -f Makefile ]; then mv -f Makefile Makefile.orig; fi
cp Makefile.simple Makefile
The Makefile.simple rule from Makefile.ship is used to construct
this file from the contents of Makefile.ship.
In calc packages such as RPMs, and the tar.bz2 source the
Makefile.simple exists. In the calc GitHub repo:
https://github.com/lcn2/calc
this file does NOT exist and must be made via the Makefile.simple
make rule. Therefore, non-GNU and simple make commands are NOT
supported by the calc GitHub repo master branch. Instead, you
need to extract Makefile.simple from one of the calc tar.bz2
source tarball source from a calc source mirror:
http://www.isthe.com/chongo/tech/comp/calc/calc-mirror.html
custom/Makefile
# SRC: Makefile via make -f Makefile custom/Makefile
This is the custom directory Makefile.
custom/Makefile.simple
# SRC: custom/Makefile.simple - non-GNU version
This is a non-GNU or simple Makefile for the custom directory
that is designed for environments that do not have a modern make
command.
In calc packages such as RPMs, and the tar.bz2 source the
Makefile.simple exists. In the calc GitHub repo:
https://github.com/lcn2/calc
this file does NOT exist and must be made via the
custom/Makefile.simple make rule. Therefore, non-GNU and simple
make commands are NOT supported by the calc GitHub repo master
branch. Instead, you need to extract custom/Makefile.simple
from one of the calc tar.bz2 source tarball source from a calc
source mirror:
http://www.isthe.com/chongo/tech/comp/calc/calc-mirror.html
cal/Makefile
# SRC: cal/Makefile
The Makefile for the cal sub-directory.
cscript/Makefile
# SRC: cscript/Makefile
The Makefile for the cscript sub-directory.
help/Makefile
# SRC: help/Makefile
The Makefile for the help sub-directory.
## Copyright (C) 1999-2007,2021 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

14
LIBRARY
View File

@@ -216,7 +216,7 @@ Your program must handle parse/scan errors in one of two ways:
/* report the parse/scan */
if (calc_use_scanerr_jmpbuf == 0) {
printf("parse error: %s\n", calc_err_msg);
}
}
/* initialize calc after the longjmp */
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
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
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
array yourself using free. The reason for this is that sometimes the pointer
points to one of two statically allocated arrays which should NOT be freed.
ZVALUE. To do this, you should call zfree() with the ZVALUE as an argument
and never try to free the array yourself using free(). The reason for this
is that sometimes the pointer points to a statically allocated arrays which
should NOT be freed.
The ZVALUE structures are passed to routines by value, and are returned
through pointers. For example, to multiply two small integers together,
@@ -615,14 +615,14 @@ These have the values 0, 1, and i.
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()
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
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
## the terms of the version 2.1 of the GNU Lesser General Public License

7664
Makefile

File diff suppressed because it is too large Load Diff

39
Makefile.local Normal file
View File

@@ -0,0 +1,39 @@
#
# Makefile.local - local Makefile variables
#
# This file is included by Makefile after the last Makefile is set and
# before the first make rule. This makes this file suitable to override
# Makefile variables.
#
# To replace a Makefile variable, use := symbols. For example:
#
# CCWERR:= -Werror
###################################################################
# NOTE: For this and other commended out examples in this file, #
# you need to remove the leading '#<whitespaces>' to take effect. #
# #
# Comments start with a #-character. #
###################################################################
# You can append to an existing Makefile variable using '+=' symbols.
# For example:
#
# CFLAGS+= -Ofast
# For example, a AddressSanitizer. You do NOT want to do this by
# by default! Do this only if you are debugging with libasan:
#
# For Linux gcc version 4.8.5 with libasan-4.8.5-4 you might try:
#
# CDEBUG:= -O0 -g
# CFLAGS+= -fsanitize=address -fno-omit-frame-pointer
# LDFLAGS+= -fsanitize=address -fno-omit-frame-pointer
# CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1
#
# For macOS 12.1 with clang version 13.0.0 (clang-1300.0.29.30) you might try:
#
# CDEBUG:= -O0 -g
# CFLAGS+= -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
# LDFLAGS+= -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
# CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1

File diff suppressed because it is too large Load Diff

54
QUESTIONS Normal file
View File

@@ -0,0 +1,54 @@
If you have a simple general question about calc, send Email to:
calc-quest-mail at asthe dot com
NOTE: Remove spaces and replace 'at' with @, and 'dot' with .
PLEASE put following the SPECIAL PHRASE somewhere in your Email Subject line:
calc question
You may add additional words to your subject line.
IMPORTANT: If your Email doesn't contain the above phrase,
then we WILL NOT SEE your Email.
PLEASE BE SURE you have that SPECIAL PHRASE somewhere in the subject line!
Suggestion:
From time to time, the Email address and Subject SPECIAL PHRASE
may change so verify you have the current info by visiting:
http://www.isthe.com/chongo/tech/comp/calc/calc-question.html
Please limit your questions to general questions about calc. We
cannot go into great detail in our answers, nor can we do your
homework, nor can we do much more than answer short general questions
about calc.
Please be patient as we cannot always respond to Email messages quickly.
=-=
## 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/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/

View File

@@ -32,30 +32,30 @@ something that you type in.
For list of help topics:
> help
; help
For overview of calc overview:
> help intro
> help overview
> help command
> help define
> help statement
> help variable
> help usage
; help intro
; help overview
; help command
; help define
; help statement
; help variable
; help usage
For list of builtin functions:
> help builtin
; help builtin
C programmers should note some unexpected differences in the calc syntax:
> help unexpected
; help unexpected
Calc is shipped with a standard collection of calc resource files.
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.
=-=
-=-
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,
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.
for information about how to report a bug.
-=-
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
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.
for information about how to ask a question.
-=-
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'.
## Copyright (C) 1999,2014,2017 Landon Curt Noll
## Copyright (C) 1999,2014,2017,2021 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

117
README.RELEASE Normal file
View 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/

View File

@@ -1,14 +1,65 @@
Dear calc user on a Windoz based system,
Dear calc user on a Windows based system,
See the HOWTO.INSTALL file for information on how to build and install calc.
See also the README file.
NOTE: The main developers do not have access to a Windoz based platform.
While we will make an effort to not break calc Windoz based system,
our lack of a Windoz test environment will mean we will make mistakes
from time to time. Hopefully Windowz users can overcome these mistakes.
BTW: While we are unable to use Windows 11, we welcome
Windows 11 developers to try compiling calc natively
(instead of via a Linux virtual machine). If you are
able to compile Windows 11 natively, we would welcome
GitHub pull requests showing any needed modifications:
https://github.com/lcn2/calc/pulls
Please also add notes to the 'Compiling calc under Windows 11'
section in README.WINDOWS file.
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
Windoz build environment.
Windows build environment.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-= Compiling calc under Windows 11 =-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-= 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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-= compiling with Cygwin =-=
@@ -63,9 +114,9 @@ needs.
In particular:
Just copy the win32/*.[ch] files up into the top level calc
source directory, edit them (if needed) and build using the
Cygwin GCC compiler and Cygwin build environment.
Just copy the win32/*.[ch] files up into the top level calc
source directory, edit them (if needed) and build using the
Cygwin GCC compiler and Cygwin build environment.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-= compiling under DJGPP =-=
@@ -111,9 +162,11 @@ recommends the following settings:
CATDIR= /dev/env/DJDIR/man/cat1
NROFF= groff
CALCPATH= .;./cal;~/.cal;${CALC_SHAREDIR};${CUSTOMCALDIR}
CALCRC= ${CALC_SHAREDIR}/startup;~/.calcrc;./.calcinit
CALCRC= ./.calcinit;~/.calcrc;${CALC_SHAREDIR}/startup
CALCPAGER= less.exe -ci
DEBUG= -O2 -gstabs+ -DWINDOZ
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)
should work for DJGPP systems if you set the above Makefile variables.
@@ -126,7 +179,7 @@ Follow those recommendations. In cases where they conflict with
the above Makefile list, follow the recommendation in the Makefile.
## Copyright (C) 2002-2009 Landon Curt Noll and Thomas Jones-Low
## Copyright (C) 2002-2009,2021 Landon Curt Noll and Thomas Jones-Low
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -1,6 +1,9 @@
# 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
@@ -16,7 +19,7 @@ and the calculator will print:
15
```
Calc as the usual collection of arithmetic operators +, -, /, * as
Calc has the usual collection of arithmetic operators +, -, /, * as
well as ^ (exponentiation), % (modulus) and // (integer divide).
For example:
@@ -257,4 +260,4 @@ help unexpected
```
It contains information about differences between C and calc
that may surprize C programmers.
that may surprise C programmers.

19
SECURITY.md Normal file
View 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.

25
addop.c
View File

@@ -1,7 +1,7 @@
/*
* 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
*
@@ -28,6 +28,7 @@
#include <stdio.h>
#include "calc.h"
#include "alloc.h"
#include "opcodes.h"
#include "str.h"
#include "func.h"
@@ -36,6 +37,10 @@
#include "symbol.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
#define FUNCALLOCSIZE 20 /* reallocate size for functions */
#define OPCODEALLOCSIZE 100 /* reallocate size for opcodes in functions */
@@ -64,12 +69,12 @@ initfunctions(void)
functemplate = (FUNC *) malloc(funcsize(maxopcodes));
if (functemplate == NULL) {
math_error("Cannot allocate function template");
/*NOTREACHED*/
not_reached();
}
functions = (FUNC **) malloc(sizeof(FUNC *) * FUNCALLOCSIZE);
if (functions == NULL) {
math_error("Cannot allocate function table");
/*NOTREACHED*/
not_reached();
}
funccount = 0;
funcavail = FUNCALLOCSIZE;
@@ -151,7 +156,7 @@ beginfunc(char *name, BOOL newflag)
fp = (FUNC *) malloc(funcsize(maxopcodes));
if (fp == NULL) {
math_error("Cannot allocate temporary function");
/*NOTREACHED*/
not_reached();
}
}
fp->f_next = NULL;
@@ -199,7 +204,7 @@ endfunc(void)
fp = (FUNC *) malloc(size);
if (fp == NULL) {
math_error("Cannot commit function");
/*NOTREACHED*/
not_reached();
}
memcpy((char *) fp, (char *) curfunc, size);
if (curfunc != functemplate)
@@ -253,13 +258,13 @@ adduserfunc(char *name)
sizeof(FUNC *) * (funcavail + FUNCALLOCSIZE));
if (functions == NULL) {
math_error("Failed to reallocate function table");
/*NOTREACHED*/
not_reached();
}
funcavail += FUNCALLOCSIZE;
}
if (addstr(&funcnames, name) == NULL) {
math_error("Cannot save function name");
/*NOTREACHED*/
not_reached();
}
index = funccount++;
functions[index] = NULL;
@@ -312,7 +317,7 @@ freefunc(FUNC *fp)
}
if (index == funccount) {
math_error("Bad call to freefunc!!!");
/*NOTREACHED*/
not_reached();
}
}
if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) {
@@ -382,7 +387,7 @@ findfunc(long index)
{
if (index >= funccount) {
math_error("Undefined function");
/*NOTREACHED*/
not_reached();
}
return functions[index];
}
@@ -434,7 +439,7 @@ addop(long op)
fp = (FUNC *) malloc(funcsize(maxopcodes));
if (fp == NULL) {
math_error("cannot malloc function");
/*NOTREACHED*/
not_reached();
}
memcpy((char *) fp, (char *) curfunc,
funcsize(curfunc->f_opcodecount));

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -34,6 +34,10 @@
#include <unistd.h>
#endif
#include "banned.h" /* include after system header <> includes */
static void buserr(void); /* catch alignment errors */

View File

@@ -42,9 +42,7 @@
# include <string.h>
#else
#if defined(_WIN32) && defined(NOTCYGWIN)
#include <stdio.h>
#endif
# if defined(HAVE_NEWSTR)
E_FUNC void *memcpy();

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -36,6 +36,10 @@
#include "value.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
#define MINHASHSIZE 31 /* minimum size of hash tables */
#define GROWHASHSIZE 50 /* approximate growth for hash tables */
#define CHAINLENGTH 10 /* desired number of elements on a hash chain */
@@ -71,7 +75,7 @@ associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices)
if (dim < 0) {
math_error("Negative dimension for indexing association");
/*NOTREACHED*/
not_reached();
}
/*
@@ -109,7 +113,7 @@ associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices)
ep = (ASSOCELEM *) malloc(ELEMSIZE(dim));
if (ep == NULL) {
math_error("Cannot allocate association element");
/*NOTREACHED*/
not_reached();
}
ep->e_dim = dim;
ep->e_hash = hash;
@@ -139,13 +143,13 @@ assocsearch(ASSOC *ap, VALUE *vp, long i, long j, ZVALUE *index)
if (i < 0 || j > ap->a_count) {
math_error("This should not happen in assocsearch");
/*NOTREACHED*/
not_reached();
}
while (i < j) {
ep = elemindex(ap, i);
if (ep == NULL) {
math_error("This should not happen in assocsearch");
/*NOTREACHED*/
not_reached();
}
if (acceptvalue(&ep->e_value, vp)) {
utoz(i, index);
@@ -169,14 +173,14 @@ assocrsearch(ASSOC *ap, VALUE *vp, long i, long j, ZVALUE *index)
if (i < 0 || j > ap->a_count) {
math_error("This should not happen in assocsearch");
/*NOTREACHED*/
not_reached();
}
j--;
while (j >= i) {
ep = elemindex(ap, j);
if (ep == NULL) {
math_error("This should not happen in assocsearch");
/*NOTREACHED*/
not_reached();
}
if (acceptvalue(&ep->e_value, vp)) {
utoz(j, index);
@@ -330,7 +334,7 @@ assoccopy(ASSOC *oldap)
if (ep == NULL) {
math_error("Cannot allocate "
"association element");
/*NOTREACHED*/
not_reached();
}
ep->e_dim = oldep->e_dim;
ep->e_hash = oldep->e_hash;
@@ -371,7 +375,7 @@ resize(ASSOC *ap, long newsize)
newtable = (ASSOCELEM **) malloc(sizeof(ASSOCELEM *) * newsize);
if (newtable == NULL) {
math_error("No memory to grow association");
/*NOTREACHED*/
not_reached();
}
for (i = 0; i < newsize; i++)
newtable[i] = NULL;
@@ -427,7 +431,7 @@ assocalloc(long initsize)
ap = (ASSOC *) malloc(sizeof(ASSOC));
if (ap == NULL) {
math_error("No memory for association");
/*NOTREACHED*/
not_reached();
}
ap->a_count = 0;
ap->a_size = initsize;
@@ -435,7 +439,7 @@ assocalloc(long initsize)
if (ap->a_table == NULL) {
free((char *) ap);
math_error("No memory for association");
/*NOTREACHED*/
not_reached();
}
for (i = 0; i < initsize; i++)
ap->a_table[i] = NULL;

69
attribute.h Normal file
View 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
View 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 */

View File

@@ -1,7 +1,7 @@
/*
* 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
*
@@ -29,12 +29,17 @@
#include <stdio.h>
#include <sys/types.h>
#include "calc.h"
#include "alloc.h"
#include "value.h"
#include "file.h"
#include "blkcpy.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
*
@@ -294,7 +299,7 @@ copymat2mat(MATRIX *smat, long ssi, long num, MATRIX *dmat, long dsi)
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
if (vtemp == NULL) {
math_error("Out of memory for mat-to-mat copy");
/*NOTREACHED*/
not_reached();
}
vp = smat->m_table + ssi;
vq = vtemp;
@@ -343,7 +348,7 @@ copyblk2mat(BLOCK *blk, long ssi, long num, MATRIX *dmat, long dsi)
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
if (vtemp == NULL) {
math_error("Out of memory for block-to-matrix copy");
/*NOTREACHED*/
not_reached();
}
vp = vtemp;
i = num;
@@ -400,7 +405,7 @@ copymat2blk(MATRIX *smat, long ssi, long num, BLOCK *dblk, long dsi,
newdata = (USB8*) realloc(dblk->data, newsize);
if (newdata == NULL) {
math_error("Out of memory for matrix-to-block copy");
/*NOTREACHED*/
not_reached();
}
dblk->data = newdata;
dblk->maxsize = newsize;
@@ -443,7 +448,7 @@ copymat2list(MATRIX *smat, long ssi, long num, LIST *lp, long dsi)
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
if (vtemp == NULL) {
math_error("Out of memory for matrix-to-list copy");
/*NOTREACHED*/
not_reached();
}
vp = smat->m_table + ssi;
vq = vtemp;
@@ -493,7 +498,7 @@ copylist2mat(LIST *lp, long ssi, long num, MATRIX *dmat, long dsi)
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
if (vtemp == NULL) {
math_error("Out of memory for list-to-matrix copy");
/*NOTREACHED*/
not_reached();
}
ep = listelement(lp, (long) ssi);
vp = vtemp;
@@ -543,7 +548,7 @@ copylist2list(LIST *slp, long ssi, long num, LIST *dlp, long dsi)
vtemp = (VALUE *) malloc(num * sizeof(VALUE));
if (vtemp == NULL) {
math_error("Out of memory for list-to-list copy");
/*NOTREACHED*/
not_reached();
}
sep = listelement(slp, (long) ssi);
vp = vtemp;
@@ -658,7 +663,7 @@ copyfile2blk(FILEID id, long ssi, long num, BLOCK *dblk, long dsi, BOOL noreloc)
newdata = (USB8*) realloc(dblk->data, newsize);
if (newdata == NULL) {
math_error("Out of memory for block-to-block copy");
/*NOTREACHED*/
not_reached();
}
dblk->data = newdata;
dblk->maxsize = newsize;
@@ -744,7 +749,7 @@ copyblk2blk(BLOCK *sblk, long ssi, long num, BLOCK *dblk, long dsi,
newdata = (USB8*) realloc(dblk->data, newsize);
if (newdata == NULL) {
math_error("Out of memory for block-to-block copy");
/*NOTREACHED*/
not_reached();
}
dblk->data = newdata;
dblk->maxsize = newsize;
@@ -788,7 +793,7 @@ copystr2blk(STRING *str, long ssi, long num, BLOCK *dblk, long dsi,
newdata = (USB8*) realloc(dblk->data, newsize);
if (newdata == NULL) {
math_error("Out of memory for string-to-block copy");
/*NOTREACHED*/
not_reached();
}
dblk->data = newdata;
dblk->maxsize = newsize;
@@ -909,7 +914,7 @@ copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,BOOL noreloc)
newdata = (USB8*) realloc(dblk->data, newsize);
if (newdata == NULL) {
math_error("Out of memory for string-to-block copy");
/*NOTREACHED*/
not_reached();
}
dblk->data = newdata;
dblk->maxsize = newsize;
@@ -941,7 +946,7 @@ memmove(void *s1, CONST void *s2, MEMMOVE_SIZE_T n)
*/
if (s1 == NULL || s2 == NULL) {
math_error("bogus memmove NULL ptr");
/*NOTREACHED*/
not_reached();
}
if (n <= 0) {
/* neg or 0 count does nothing */
@@ -1011,7 +1016,7 @@ copynum2blk(NUMBER *snum, long ssi, long num, BLOCK *dblk, long dsi,
newdata = (USB8*) realloc(dblk->data, newsize);
if (newdata == NULL) {
math_error("Out of memory for num-to-block copy");
/*NOTREACHED*/
not_reached();
}
dblk->data = newdata;
dblk->maxsize = newsize;
@@ -1040,7 +1045,7 @@ copyblk2num(BLOCK *sblk, long ssi, long num, NUMBER *dnum, long dsi,
NUMBER *ret; /* cloned and modified numerator */
#if CALC_BYTE_ORDER == BIG_ENDIAN
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 */
unsigned long i;
#endif
@@ -1082,7 +1087,7 @@ copyblk2num(BLOCK *sblk, long ssi, long num, NUMBER *dnum, long dsi,
swapped = (HALF *)malloc(halflen * sizeof(HALF));
if (swapped == NULL) {
math_error("Out of memory for block-to-num copy");
/*NOTREACHED*/
not_reached();
}
/* ensure that any trailing octets will be zero filled */
swapped[halflen-1] = 0;

52
block.c
View File

@@ -1,7 +1,7 @@
/*
* 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
*
@@ -28,6 +28,11 @@
#include <stdio.h>
#include "have_string.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include "alloc.h"
#include "value.h"
#include "zmath.h"
#include "config.h"
@@ -36,6 +41,11 @@
#include "str.h"
#include "calcerr.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
#define NBLOCKCHUNK 16
STATIC long nblockcount = 0;
@@ -78,7 +88,7 @@ blkalloc(int len, int chunk)
nblk = (BLOCK *)malloc(sizeof(BLOCK));
if (nblk == NULL) {
math_error("cannot allocate block");
/*NOTREACHED*/
not_reached();
}
/*
@@ -89,7 +99,7 @@ blkalloc(int len, int chunk)
nblk->data = (USB8*)malloc(nblk->maxsize);
if (nblk->data == NULL) {
math_error("cannot allocate block data storage");
/*NOTREACHED*/
not_reached();
}
memset(nblk->data, 0, nblk->maxsize);
nblk->datalen = len;
@@ -147,7 +157,7 @@ blk_free(BLOCK *blk)
* blk - the BLOCK to check
*
* 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
*/
S_FUNC void
@@ -163,7 +173,7 @@ blkchk(BLOCK *blk)
}
if (blk == NULL) {
math_error("internal: blk ptr is NULL");
/*NOTREACHED*/
not_reached();
}
/*
@@ -171,7 +181,7 @@ blkchk(BLOCK *blk)
*/
if (blk->data == NULL) {
math_error("internal: blk->data ptr is NULL");
/*NOTREACHED*/
not_reached();
}
/*
@@ -179,7 +189,7 @@ blkchk(BLOCK *blk)
*/
if (blk->datalen < 0) {
math_error("internal: blk->datalen < 0");
/*NOTREACHED*/
not_reached();
}
/*
@@ -187,7 +197,7 @@ blkchk(BLOCK *blk)
*/
if (blk->datalen < 0) {
math_error("internal: blk->datalen < 0");
/*NOTREACHED*/
not_reached();
}
return;
}
@@ -250,7 +260,7 @@ blkrealloc(BLOCK *blk, int newlen, int newchunk)
nblk = (USB8*)realloc(blk->data, newmax);
if (nblk == NULL) {
math_error("cannot reallocate block storage");
/*NOTREACHED*/
not_reached();
}
/* clear any new storage */
@@ -291,7 +301,7 @@ blkrealloc(BLOCK *blk, int newlen, int newchunk)
* Set the data length
*
* 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
* correct in terms of the new type.
@@ -358,7 +368,7 @@ blktrunc(BLOCK *blk)
blk->data = (USB8*)malloc(1);
if (blk->data == NULL) {
math_error("cannot allocate truncated block storage");
/*NOTREACHED*/
not_reached();
}
blk->data[0] = (USB8)0;
if (conf->calc_debug & CALCDBG_BLOCK) {
@@ -388,7 +398,7 @@ blk_copy(BLOCK *blk)
nblk = (BLOCK *)malloc(sizeof(BLOCK));
if (nblk == NULL) {
math_error("blk_copy: cannot malloc BLOCK");
/*NOTREACHED*/
not_reached();
}
/*
@@ -402,7 +412,7 @@ blk_copy(BLOCK *blk)
nblk->data = (USB8 *)malloc(blk->maxsize);
if (nblk->data == NULL) {
math_error("blk_copy: cannot duplicate block data");
/*NOTREACHED*/
not_reached();
}
memcpy(nblk->data, blk->data, blk->maxsize);
return nblk;
@@ -530,7 +540,7 @@ reallocnblock(int id, int len, int chunk)
/* Fire wall */
if (id < 0 || id >= nblockcount) {
math_error("Bad id in call to reallocnblock");
/*NOTREACHED*/
not_reached();
}
blk = nblocks[id]->blk;
@@ -547,13 +557,13 @@ reallocnblock(int id, int len, int chunk)
newdata = malloc(newsize);
if (newdata == NULL) {
math_error("Allocation failed");
/*NOTREACHED*/
not_reached();
}
} else if (newsize != oldsize) {
newdata = realloc(blk->data, newsize);
if (newdata == NULL) {
math_error("Reallocation failed");
/*NOTREACHED*/
not_reached();
}
}
memset(newdata + len, 0, newsize - len);
@@ -584,7 +594,7 @@ createnblock(char *name, int len, int chunk)
if (nblocks == NULL) {
maxnblockcount = 0;
math_error("unable to malloc new named blocks");
/*NOTREACHED*/
not_reached();
}
} else {
maxnblockcount += NBLOCKCHUNK;
@@ -593,7 +603,7 @@ createnblock(char *name, int len, int chunk)
if (nblocks == NULL) {
maxnblockcount = 0;
math_error("cannot malloc more named blocks");
/*NOTREACHED*/
not_reached();
}
}
}
@@ -601,18 +611,18 @@ createnblock(char *name, int len, int chunk)
initstr(&nblocknames);
if (findstr(&nblocknames, name) >= 0) {
math_error("Named block already exists!!!");
/*NOTREACHED*/
not_reached();
}
newname = addstr(&nblocknames, name);
if (newname == NULL) {
math_error("Block name allocation failed");
/*NOTREACHED*/
not_reached();
}
res = (NBLOCK *) malloc(sizeof(NBLOCK));
if (res == NULL) {
math_error("Named block allocation failed");
/*NOTREACHED*/
not_reached();
}
nblocks[nblockcount] = res;

10
block.h
View File

@@ -1,7 +1,7 @@
/*
* 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
*
@@ -55,7 +55,7 @@
* blkchunk defaults to BLK_CHUNKSIZE
*
* blkfree(x)
* Reduce storage down to 0 octetes.
* Reduce storage down to 0 octets.
*
* size(x)
* The length of data stored in the block.
@@ -88,7 +88,7 @@
* blkmove(dest, src, length [, dest_offset [, src_offset]])
* 0 <= length <= blksize(x)
* 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]])
* 0 <= length <= blksize(x)
@@ -104,7 +104,7 @@
* b = a*k for some integer k >= 1
*
* 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
* stops at end of src
*
@@ -184,7 +184,7 @@ EXTERN int blk_debug; /* 0 => debug off */
/* length of data stored in a block */
#define blklen(blk) ((blk)->datalen)
/* block footpint in memory */
/* block footprint in memory */
#define blksizeof(blk) ((blk)->maxsize)
/* block allocation chunk size */

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -29,11 +29,15 @@
#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
*
* 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
* src - pointer to a HALF array to swap
* len - length of the src HALF array
@@ -73,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
*
* 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
* src - pointer to a ZVALUE to swap
* all - TRUE => swap every element, FALSE => swap only the
* multiprecision storage
* multi-precision storage
*
* returns:
* pointer to where the swapped src has been put
@@ -100,7 +104,7 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
if (dest == NULL) {
math_error("swap_b8_in_ZVALUE: swap_b8_in_ZVALUE: "
"Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -123,8 +127,8 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
* swap or copy the rest of the ZVALUE elements
*/
if (all) {
dest->len = (LEN)SWAP_B8_IN_LEN(&dest->len, &src->len);
dest->sign = (BOOL)SWAP_B8_IN_BOOL(&dest->sign, &src->sign);
SWAP_B8_IN_LEN(&dest->len, &src->len);
SWAP_B8_IN_BOOL(&dest->sign, &src->sign);
} else {
dest->len = src->len;
dest->sign = src->sign;
@@ -141,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
*
* 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
* src - pointer to a NUMBER to swap
* all - TRUE => swap every element, FALSE => swap only the
* multiprecision storage
* multi-precision storage
*
* returns:
* pointer to where the swapped src has been put
@@ -167,7 +171,7 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
dest = malloc(sizeof(NUMBER));
if (dest == NULL) {
math_error("swap_b8_in_NUMBER: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -189,7 +193,7 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
* swap or copy the rest of the NUMBER elements
*/
if (all) {
dest->links = (long)SWAP_B8_IN_LONG(&dest->links, &src->links);
SWAP_B8_IN_LONG(&dest->links, &src->links);
} else {
dest->links = src->links;
}
@@ -205,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
*
* 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
* src - pointer to a COMPLEX to swap
* all - TRUE => swap every element, FALSE => swap only the
* multiprecision storage
* multi-precision storage
*
* returns:
* pointer to where the swapped src has been put
@@ -231,7 +235,7 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
dest = malloc(sizeof(COMPLEX));
if (dest == NULL) {
math_error("swap_b8_in_COMPLEX: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -253,7 +257,7 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
* swap or copy the rest of the NUMBER elements
*/
if (all) {
dest->links = (long)SWAP_B8_IN_LONG(&dest->links, &src->links);
SWAP_B8_IN_LONG(&dest->links, &src->links);
} else {
dest->links = src->links;
}
@@ -269,7 +273,7 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
* swap_b16_in_HALFs - swap 16 bits in an array of HALFs
*
* 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
* src - pointer to a HALF array to swap
* len - length of the src HALF array
@@ -309,11 +313,11 @@ swap_b16_in_HALFs(HALF *dest, HALF *src, LEN len)
* swap_b16_in_ZVALUE - swap 16 bits in a ZVALUE
*
* 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
* src - pointer to a ZVALUE to swap
* all - TRUE => swap every element, FALSE => swap only the
* multiprecision storage
* multi-precision storage
*
* returns:
* pointer to where the swapped src has been put
@@ -335,7 +339,7 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
dest = malloc(sizeof(ZVALUE));
if (dest == NULL) {
math_error("swap_b16_in_ZVALUE: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -358,8 +362,8 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
* swap or copy the rest of the ZVALUE elements
*/
if (all) {
dest->len = (LEN)SWAP_B16_IN_LEN(&dest->len, &src->len);
dest->sign = (BOOL)SWAP_B16_IN_BOOL(&dest->sign, &src->sign);
SWAP_B16_IN_LEN(&dest->len, &src->len);
SWAP_B16_IN_BOOL(&dest->sign, &src->sign);
} else {
dest->len = src->len;
dest->sign = src->sign;
@@ -376,11 +380,11 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
* swap_b16_in_NUMBER - swap 16 bits in a NUMBER
*
* 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
* src - pointer to a NUMBER to swap
* all - TRUE => swap every element, FALSE => swap only the
* multiprecision storage
* multi-precision storage
*
* returns:
* pointer to where the swapped src has been put
@@ -402,7 +406,7 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
dest = malloc(sizeof(NUMBER));
if (dest == NULL) {
math_error("swap_b16_in_NUMBER: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -424,7 +428,7 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
* swap or copy the rest of the NUMBER elements
*/
if (all) {
dest->links = (long)SWAP_B16_IN_LONG(&dest->links, &src->links);
SWAP_B16_IN_LONG(&dest->links, &src->links);
} else {
dest->links = src->links;
}
@@ -440,11 +444,11 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
* swap_b16_in_COMPLEX - swap 16 bits in a COMPLEX
*
* 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
* src - pointer to a COMPLEX to swap
* all - TRUE => swap every element, FALSE => swap only the
* multiprecision storage
* multi-precision storage
*
* returns:
* pointer to where the swapped src has been put
@@ -466,7 +470,7 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
dest = malloc(sizeof(COMPLEX));
if (dest == NULL) {
math_error("swap_b16_in_COMPLEX: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -488,7 +492,7 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
* swap or copy the rest of the NUMBER elements
*/
if (all) {
dest->links = (long)SWAP_B16_IN_LONG(&dest->links, &src->links);
SWAP_B16_IN_LONG(&dest->links, &src->links);
} else {
dest->links = src->links;
}
@@ -504,11 +508,11 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
* swap_HALF_in_ZVALUE - swap HALFs in a ZVALUE
*
* 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
* src - pointer to a ZVALUE to swap
* all - TRUE => swap every element, FALSE => swap only the
* multiprecision storage
* multi-precision storage
*
* returns:
* pointer to where the swapped src has been put
@@ -530,7 +534,7 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
dest = malloc(sizeof(ZVALUE));
if (dest == NULL) {
math_error("swap_HALF_in_ZVALUE: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -554,8 +558,8 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
* swap or copy the rest of the ZVALUE elements
*/
if (all) {
dest->len = (LEN)SWAP_HALF_IN_LEN(&dest->len, &src->len);
dest->sign = (BOOL)SWAP_HALF_IN_BOOL(&dest->sign, &src->sign);
SWAP_HALF_IN_LEN(&dest->len, &src->len);
SWAP_HALF_IN_BOOL(&dest->sign, &src->sign);
} else {
dest->len = src->len;
dest->sign = src->sign;
@@ -572,11 +576,11 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, BOOL all)
* swap_HALF_in_NUMBER - swap HALFs in a NUMBER
*
* 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
* src - pointer to a NUMBER to swap
* all - TRUE => swap every element, FALSE => swap only the
* multiprecision storage
* multi-precision storage
*
* returns:
* pointer to where the swapped src has been put
@@ -598,7 +602,7 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
dest = malloc(sizeof(NUMBER));
if (dest == NULL) {
math_error("swap_HALF_in_NUMBER: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -620,7 +624,7 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
* swap or copy the rest of the NUMBER elements
*/
if (all) {
dest->links = (long)SWAP_HALF_IN_LONG(&dest->links,&src->links);
SWAP_HALF_IN_LONG(&dest->links, &src->links);
} else {
dest->links = src->links;
}
@@ -636,11 +640,11 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all)
* swap_HALF_in_COMPLEX - swap HALFs in a COMPLEX
*
* 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
* src - pointer to a COMPLEX to swap
* all - TRUE => swap every element, FALSE => swap only the
* multiprecision storage
* multi-precision storage
*
* returns:
* pointer to where the swapped src has been put
@@ -662,7 +666,7 @@ swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
dest = malloc(sizeof(COMPLEX));
if (dest == NULL) {
math_error("swap_HALF_in_COMPLEX: Not enough memory");
/*NOTREACHED*/
not_reached();
}
/*
@@ -684,7 +688,7 @@ swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, BOOL all)
* swap or copy the rest of the NUMBER elements
*/
if (all) {
dest->links = (long)SWAP_HALF_IN_LONG(&dest->links,&src->links);
SWAP_HALF_IN_LONG(&dest->links, &src->links);
} else {
dest->links = src->links;
}

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -39,7 +39,7 @@
/*
* 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
*
* This macro will either switch to the opposite byte sex (Big Endian vs.
@@ -53,7 +53,7 @@
/*
* 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
*/
#define SWAP_B16_IN_B32(dest, src) ( \
@@ -64,7 +64,7 @@
/*
* 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
*
* This macro will either switch to the opposite byte sex (Big Endian vs.
@@ -82,7 +82,7 @@
/*
* 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
*/
#define SWAP_B32_IN_B64(dest, src) ( \
@@ -93,7 +93,7 @@
/*
* 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
*/
#define SWAP_B16_IN_B64(dest, src) ( \
@@ -106,7 +106,7 @@
/*
* 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
*
* This macro will either switch to the opposite byte sex (Big Endian vs.
@@ -124,7 +124,7 @@
/*
* 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
*/
#define SWAP_B32_IN_B64(dest, src) ( \
@@ -135,7 +135,7 @@
/*
* 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
*/
#define SWAP_B16_IN_B64(dest, src) ( \
@@ -146,7 +146,7 @@
/*
* 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
*
* This macro will either switch to the opposite byte sex (Big Endian vs.

View File

@@ -2,7 +2,15 @@
#
# cal - makefile for calc standard resource files
#
# Copyright (C) 1999-2006,2017 Landon Curt Noll
# Copyright (C) 1999-2006,2017,2021,2022 Landon Curt Noll
#
# SRC: cal/Makefile
#
# The "# SRC: ... - ..." comment line above indicates
# the origin of this file.
#
# IMPORTANT: Please see the section on Makefiles near the
# bottom of the HOWTO.INSTALL file.
#
# Calc is open software; you can redistribute it and/or modify it under
# the terms of the version 2.1 of the GNU Lesser General Public License
@@ -27,15 +35,68 @@
# calculator by David I. Bell with help/mods from others
# Makefile by Landon Curt Noll
# required vars
# The shell used by this Makefile
#
SHELL= /bin/sh
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavior.
#
# If your system has a up to date, bash shell, then
# you may wish to use:
#
# SHELL= /bin/bash
#
# On some systems such as macOS, the bash shell is very
# far behind to the point where is cannot be depended on.
# On such systems, the sh may be a much better alternative
# shell for this Makefile to use:
#
# SHELL= /bin/sh
#
SHELL= /bin/bash
#SHELL= /bin/sh
#if 0 /* start of skip for non-Gnu makefiles */
ifeq ($(target),Darwin)
SHELL:= /bin/zsh
endif
#endif /* end of skip for non-Gnu makefiles */
####
# Normally, the upper level makefile will set these values. We provide
# a default here just in case you want to build from this directory.
####
# PREFIX - Top level location for calc
#
# The PREFIX is often prepended to paths within calc and calc Makefiles.
#
# Starting with calc v2.13.0.1, nearly all Makefile places that used
# /usr/local now use ${PREFIX}. An exception is the olduninstall rule
# and, of course, this section. :-)
#
# NOTE: The ${PREFIX} is not the same as ${T}. The ${T} specifies
# a top level directory under which calc installs things.
# While usually ${T} is empty, it can be specific path
# as if calc where "chrooted" during an install.
# The ${PREFIX} value, during install, is a path between
# the top level ${T} install directory and the object
# such as an include file.
#
# NOTE: See also, ${T}, below.
#
# There are some paths that do NOT call under ${PREFIX}, such as
# ${CALCPATH}, that include paths not under ${PREFIX}, but those
# too are exceptions to this general rule.
#
# When in doubt, try:
#
# PREFIX= /usr/local
#
PREFIX= /usr/local
#PREFIX= /usr
#PREFIX= /usr/global
# Normally certain files depend on the Makefile. If the Makefile is
# changed, then certain steps should be redone. If MAKE_FILE is
# set to Makefile, then these files will depend on Makefile. If
@@ -45,15 +106,6 @@ SHELL= /bin/sh
#
MAKE_FILE= Makefile
# Controlling file makefile basename (without the path)
#
# This is the basename same of the makefile that may/does/will drive
# this makefile.
#
# If in doubt, set TOP_MAKE_FILE to Makefile
#
TOP_MAKE_FILE= Makefile
# Where the system include (.h) files are kept
#
# For DJGPP, select:
@@ -65,11 +117,11 @@ TOP_MAKE_FILE= Makefile
# INCDIR= /usr/include
#
#INCDIR= /usr/local/include
#INCDIR= ${PREFIX}/include
#INCDIR= /dev/env/DJDIR/include
INCDIR= /usr/include
# where to install calc realted things
# where to install calc related things
#
# ${BINDIR} where to install calc binary files
# ${LIBDIR} where calc link library (*.a) files are installed
@@ -91,15 +143,15 @@ INCDIR= /usr/include
# LIBDIR= /usr/lib
# CALC_SHAREDIR= /usr/share/calc
#
#BINDIR= /usr/local/bin
#BINDIR= ${PREFIX}/bin
#BINDIR= /dev/env/DJDIR/bin
BINDIR= /usr/bin
#LIBDIR= /usr/local/lib
#LIBDIR= ${PREFIX}/lib
#LIBDIR= /dev/env/DJDIR/lib
LIBDIR= /usr/lib
#CALC_SHAREDIR= /usr/local/lib/calc
#CALC_SHAREDIR= ${PREFIX}/lib/calc
#CALC_SHAREDIR= /dev/env/DJDIR/share/calc
CALC_SHAREDIR= /usr/share/calc
@@ -157,47 +209,70 @@ T=
# Makefile debug
#
# Q=@ do not echo internal makefile actions (quiet mode)
# Q= echo internal makefile actions (debug / verbose mode)
# Q=@ do not echo internal Makefile actions (quiet 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=@
#
S= >/dev/null 2>&1
#S=
#
E= 2>/dev/null
#E=
#
#H=@:
H=@
#
V=@:
#V=@
# standard tools
#
CHMOD= chmod
CMP= cmp
RM= rm
MKDIR= mkdir
RMDIR= rmdir
CP= cp
MV= mv
CO= co
TRUE= true
TOUCH= touch
CP= cp
FMT= fmt
MKDIR= mkdir
MV= mv
RM= rm
RMDIR= rmdir
SED= sed
SORT= sort
FMT= fmt
TOUCH= touch
TRUE= true
# 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:
#
# make calc_files_list
#
# to keep this list in nice sorted order and to check that these
# deailed help files are under RCS control.
# to keep this list in nice sorted order.
#
CALC_FILES= README alg_config.cal beer.cal bernoulli.cal \
bernpoly.cal bigprime.cal bindings brentsolve.cal chi.cal chrem.cal \
constants.cal deg.cal dms.cal dotest.cal ellip.cal factorial.cal \
factorial2.cal gvec.cal hello.cal hms.cal infinities.cal \
intfile.cal intnum.cal lambertw.cal linear.cal lnseries.cal \
lucas.cal lucas_chk.cal mersenne.cal mfactor.cal \
mod.cal natnumset.cal pell.cal pi.cal pix.cal pollard.cal poly.cal \
prompt.cal psqrt.cal qtime.cal quat.cal randbitrun.cal randmprime.cal \
factorial2.cal gvec.cal hello.cal hms.cal infinities.cal intfile.cal \
intnum.cal lambertw.cal linear.cal lnseries.cal lucas.cal \
lucas_chk.cal mersenne.cal mfactor.cal mod.cal natnumset.cal \
palindrome.cal pell.cal pi.cal pix.cal pollard.cal poly.cal prompt.cal \
psqrt.cal qtime.cal quat.cal randbitrun.cal randmprime.cal \
randombitrun.cal randomrun.cal randrun.cal regress.cal repeat.cal \
screen.cal seedrandom.cal set8700.cal set8700.line smallfactors.cal \
solve.cal specialfunctions.cal statistics.cal strings.cal sumsq.cal \
@@ -218,6 +293,10 @@ DISTLIST= ${CALC_FILES} ${MAKE_FILE}
# These files are used to make (but not built) a calc .a link library
#
CALCLIBLIST=
#
# rules that are not also names of files
#
PHONY= all clobber distlist install
all: ${CALC_FILES} ${MAKE_FILE} .all
@@ -227,6 +306,8 @@ all: ${CALC_FILES} ${MAKE_FILE} .all
${RM} -f .all
${TOUCH} .all
.PHONY: ${PHONY}
##
#
# File list generation. You can ignore this section.
@@ -236,7 +317,7 @@ all: ${CALC_FILES} ${MAKE_FILE} .all
# sub-directory called calc/cal.
#
# 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*
#
##
@@ -261,19 +342,13 @@ calcliblist:
#
calc_files_list:
${Q} -(find . -mindepth 1 -maxdepth 1 -type f -name '*.cal' -print | \
while read i; do \
if [ X"$$i" != X"/dev/null" ]; then \
if [ ! -f RCS/$$i,v ]; then \
echo "WARNING: $$i not under RCS control" 1>&2; \
else \
echo $$i; \
fi; \
fi; \
done; \
echo '--first_line--'; \
echo README; \
echo set8700.line; \
echo bindings) | \
while read i; do \
echo $$i; \
done; \
echo '--first_line--'; \
echo README; \
echo set8700.line; \
echo bindings) | \
${SED} -e 's:^\./::' | LANG=C ${SORT} | ${FMT} -70 | \
${SED} -e '1s/--first_line--/CALC_FILES=/' -e '2,$$s/^/ /' \
-e 's/$$/ \\/' -e '$$s/ \\$$//'
@@ -387,11 +462,11 @@ uninstall:
continue; \
fi; \
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 \
echo "cannot uninstall ${T}${CALC_SHAREDIR}/$$i"; \
else \
echo "uninstalled ${T}${CALC_SHAREDIR}/$$i"; \
echo "un-installed ${T}${CALC_SHAREDIR}/$$i"; \
fi; \
fi; \
done

View File

@@ -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
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,
@@ -223,7 +186,7 @@ bernoulli.cal
Calculate the nth Bernoulli number.
NOTE: There is now a bernoulli() builtin function. This file is
left here for backward compatibility and now simply returns
left here for backward compatibility and now simply returns
the builtin function.
@@ -250,12 +213,12 @@ brentsolve.cal
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)
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".
See:
@@ -429,7 +392,7 @@ factorial2.cal
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
values.Meant as a complete replacement for catalan(n) with only a
very small overhead. See:
@@ -470,9 +433,9 @@ factorial2.cal
k = 0
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 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:
http://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind
@@ -583,7 +546,7 @@ infinities.cal
pinf()
The symbolic handling of infinities. Needed for intnum.cal but might be
usefull elsewhere, too.
useful elsewhere, too.
intfile.cal
@@ -632,13 +595,13 @@ intnum.cal
This file offers some methods for numerical integration. Implemented are
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.
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
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).
Integration in parts and contour is supported by the "points" argument
@@ -698,7 +661,7 @@ intnum.cal
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.
This can be quite usefull in some circumstances.
This can be quite useful in some circumstances.
; quadgldeletenodes()
; define f(x){ return exp(x);}
@@ -760,7 +723,7 @@ lambertw.cal
ProductLog[branch,z] with the tested values.
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
for further information.
@@ -783,7 +746,7 @@ lnseries.cal
does so by computing the prime factorization of all of the number
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
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
of the logarithms and/or long sequences.
@@ -804,7 +767,7 @@ lucas.cal
prove that h*2^n-1 is prime or not prime.
NOTE: Some call this term u(0). The function gen_u0(h, n, v1)
simply calls gen_u2(h, n, v1) for such people. :-)
simply calls gen_u2(h, n, v1) for such people. :-)
gen_v1(h, v)
@@ -843,7 +806,7 @@ mfactor.cal
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.
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
takes about 3 seconds and requires ~1.5 Megs of memory.
@@ -916,6 +879,38 @@ natnumset.cal
user-specified bound.
palindrome.cal
digitof(val,place)
copalplace(d,place)
upperhalf(val)
mkpal(val)
mkpalmiddigit(val,digit)
ispal(val)
nextpal(val)
prevpal(val)
nextprimepal(val)
prevprimepal(val)
Functions to form and manipulate 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
pellx(D)
@@ -937,7 +932,7 @@ pi.cal
as your free memory space and system up time allows.
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,
Meertens & Pemberton, published by Prentice-Hall (UK) Ltd., 1990.
@@ -1354,7 +1349,7 @@ specialfunctions.cal
http://en.wikipedia.org/wiki/Polygamma
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.
@@ -1371,7 +1366,7 @@ specialfunctions.cal
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://dlmf.nist.gov/25.2
@@ -1390,7 +1385,7 @@ statistics.cal
invbetainc(x,a,b)
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)
betacdf(x,a,b)
@@ -1470,9 +1465,9 @@ sumtimes.cal
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
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
@@ -1816,7 +1811,7 @@ zeta2.cal
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
##

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -33,7 +33,7 @@ static test_time; /* try for this many seconds in loop test */
* given:
* ratio the ratio of time between two algorithms
*
* retuns:
* returns:
* 1 When ratio is near 1.0
* 0 otherwise
*
@@ -354,7 +354,7 @@ define best_mul2()
local high; /* high loop value tested */
local mid; /* between low and high */
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 */
/*
@@ -363,7 +363,7 @@ define best_mul2()
printf("WARNING: This tool may not be computing the correct best value\n");
test_time = 5.0;
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) {
printf("To monitor progress, set user_debug to 2: "
"config(\"user_debug\", 2)\n");
@@ -392,7 +392,7 @@ define best_mul2()
*/
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
* the ratio drops below 1.0.
@@ -419,7 +419,7 @@ define best_mul2()
best_val = high;
best_ratio = ratio;
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);
}
}
@@ -442,7 +442,7 @@ define best_mul2()
high /= 2;
low = high / 2;
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);
}
ratio = mul_ratio(high);
@@ -450,7 +450,8 @@ define best_mul2()
best_val = high;
best_ratio = ratio;
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);
}
}
@@ -473,7 +474,7 @@ define best_mul2()
*/
while (low+1 < high) {
/* try the mid-point */
/* try the mid-point */
mid = int((low+high)/2);
if (config("user_debug") > 0) {
printf("testing multiply alg1/alg2 ratio for len = %d\n", mid);
@@ -483,7 +484,7 @@ define best_mul2()
best_val = mid;
best_ratio = ratio;
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);
}
}
@@ -496,7 +497,7 @@ define best_mul2()
low = mid;
high = mid;
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;
}
@@ -504,7 +505,7 @@ define best_mul2()
/* bump lower range up if we went over */
if (ratio > 1.0) {
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;
@@ -512,7 +513,7 @@ define best_mul2()
/* drop higher range down if we went under */
} else {
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;
@@ -521,7 +522,7 @@ define best_mul2()
/* report on test loop progress */
if (config("user_debug") > 1) {
printf("\tsetting low: %d high: %d diff: %d\n",
low, high, high-low);
low, high, high-low);
}
}
@@ -535,7 +536,7 @@ define best_mul2()
printf("config(\"mul2\", %d),;\n", best_val);
printf("WARNING: It is believed that the output "
"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;
}
@@ -835,7 +836,7 @@ define best_sq2()
local high; /* high loop value tested */
local mid; /* between low and high */
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 */
/*
@@ -844,7 +845,7 @@ define best_sq2()
printf("WARNING: This tool may not be computing the correct best value\n");
test_time = 5.0;
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) {
printf("To monitor progress, set user_debug to 2: "
"config(\"user_debug\", 2)\n");
@@ -873,7 +874,7 @@ define best_sq2()
*/
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
* the ratio drops below 1.0.
@@ -883,7 +884,7 @@ define best_sq2()
high *= expand;
if (config("user_debug") > 1) {
printf(" expand the next test range by a factor of %d\n",
expand);
expand);
}
/*
@@ -900,7 +901,7 @@ define best_sq2()
best_val = high;
best_ratio = ratio;
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);
}
}
@@ -923,7 +924,7 @@ define best_sq2()
high /= 2;
low = high / 2;
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);
}
ratio = mul_ratio(high);
@@ -931,7 +932,8 @@ define best_sq2()
best_val = high;
best_ratio = ratio;
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);
}
}
@@ -954,7 +956,7 @@ define best_sq2()
*/
while (low+1 < high) {
/* try the mid-point */
/* try the mid-point */
mid = int((low+high)/2);
if (config("user_debug") > 0) {
printf("testing square alg1/alg2 ratio for len = %d\n", mid);
@@ -964,7 +966,7 @@ define best_sq2()
best_val = mid;
best_ratio = ratio;
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);
}
}
@@ -977,7 +979,7 @@ define best_sq2()
low = mid;
high = mid;
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;
}
@@ -985,7 +987,7 @@ define best_sq2()
/* bump lower range up if we went over */
if (ratio > 1.0) {
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;
@@ -993,7 +995,7 @@ define best_sq2()
/* drop higher range down if we went under */
} else {
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;
@@ -1002,7 +1004,7 @@ define best_sq2()
/* report on test loop progress */
if (config("user_debug") > 1) {
printf("\tsetting low: %d high: %d diff: %d\n",
low, high, high-low);
low, high, high-low);
}
}
@@ -1017,7 +1019,7 @@ define best_sq2()
printf("config(\"sq2\", %d),;\n", best_val);
printf("WARNING: It is believed that the output "
"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;
}
@@ -1337,7 +1339,7 @@ define best_pow2()
local high; /* high loop value tested */
local mid; /* between low and high */
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 looped; /* 1 ==> we have expanded lengths before */
@@ -1347,7 +1349,7 @@ define best_pow2()
printf("WARNING: This tool may not be computing the correct best value\n");
test_time = 60.0;
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) {
printf("To monitor progress, set user_debug to 2: "
"config(\"user_debug\", 2)\n");
@@ -1358,7 +1360,7 @@ define best_pow2()
* firewall - must have a >1.02 ratio for the initial length
*
* 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.
*/
low = 4;
@@ -1375,7 +1377,7 @@ define best_pow2()
best_val = high;
best_ratio = ratio;
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);
}
}
@@ -1383,7 +1385,7 @@ define best_pow2()
printf(" pmod alg1/alg2 ratio = %.3f\n", ratio);
if (ratio > 1.0 && ratio <= 1.02) {
printf(" while alg1 is slightly better than alg2, "
"it is not clearly better\n");
"it is not clearly better\n");
}
}
} while (ratio <= 1.02);
@@ -1397,7 +1399,7 @@ define best_pow2()
looped = 0;
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
* the ratio drops below 1.0.
@@ -1418,7 +1420,7 @@ define best_pow2()
high *= expand;
if (config("user_debug") > 1) {
printf(" expand the next test range by a factor of %d\n",
expand);
expand);
}
/*
@@ -1435,7 +1437,7 @@ define best_pow2()
best_val = high;
best_ratio = ratio;
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);
}
}
@@ -1453,7 +1455,7 @@ define best_pow2()
*/
while (low+1 < high) {
/* try the mid-point */
/* try the mid-point */
mid = int((low+high)/2);
if (config("user_debug") > 0) {
printf("testing pow2 alg1/alg2 ratio for len = %d\n", mid);
@@ -1463,7 +1465,7 @@ define best_pow2()
best_val = mid;
best_ratio = ratio;
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);
}
}
@@ -1476,7 +1478,7 @@ define best_pow2()
low = mid;
high = mid;
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;
}
@@ -1484,7 +1486,7 @@ define best_pow2()
/* bump lower range up if we went over */
if (ratio > 1.0) {
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;
@@ -1492,7 +1494,7 @@ define best_pow2()
/* drop higher range down if we went under */
} else {
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;
@@ -1501,7 +1503,7 @@ define best_pow2()
/* report on test loop progress */
if (config("user_debug") > 1) {
printf("\tsetting low: %d high: %d diff: %d\n",
low, high, high-low);
low, high, high-low);
}
}
@@ -1516,7 +1518,7 @@ define best_pow2()
printf("config(\"pow2\", %d),;\n", best_val);
printf("WARNING: It is believed that the output "
"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;
}

View File

@@ -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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -26,9 +26,9 @@
/*
* 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
*
@@ -42,7 +42,7 @@
* B(3) = -(6*B(2) + 4*B(1) + 1) / 4
*
* 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
* values obtained are saved in an array for ease in repeated calculations.
*/

View File

@@ -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
* the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -143,7 +143,7 @@ define brentsolve2(low, high,which,eps){
switch(param(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);
which = 0;break;
case 3: eps = epsilon(epsilon()*1e-2);break;

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -40,7 +40,7 @@ define Z(x, eps_term)
/* obtain the error term */
if (isnull(eps_term)) {
eps = epsilon();
eps = epsilon();
} else {
eps = eps_term;
}
@@ -51,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.
*
@@ -81,7 +81,7 @@ define P(x, eps_term)
/* obtain the error term */
if (isnull(eps_term)) {
eps = epsilon();
eps = epsilon();
} else {
eps = eps_term;
}
@@ -99,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;
x_term = x;
@@ -130,7 +130,7 @@ define P(x, eps_term)
*
* 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
* 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.
* Can somebody help / find a bug / provide a better method of
@@ -186,7 +186,7 @@ define chi_prob(chi_sq, v, eps_term)
local r; /* index in finite sum */
local r_lim; /* limit value for r */
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 ret; /* return value */

View File

@@ -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
*
@@ -26,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:
*
* x = r1 (mod m1)
@@ -35,7 +35,7 @@
*
* where the residues r1, r2, ... and the moduli m1, m2, ... are
* 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, ...
* are not relatively prime in pairs, it is possible that no solution
* exists. If solutions exist, the general solution is expressible as:

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -53,7 +53,7 @@ define dms_add(a, b)
{
local obj dms ans; /* return value */
/* initalize value to 1st arg */
/* initialize value to 1st arg */
if (istype(a, ans)) {
/* 1st arg is dms object, load it */
ans.deg = a.deg;
@@ -110,7 +110,7 @@ define dms_sub(a, b)
{
local obj dms ans; /* return value */
/* initalize value to 1st arg */
/* initialize value to 1st arg */
if (istype(a, ans)) {
/* 1st arg is dms object, load it */
ans.deg = a.deg;
@@ -188,7 +188,7 @@ define dms_abs(a)
/* firewall - just absolute value non dms objects */
if (! istype(a, ans)) {
return abs(a);
return abs(a);
}
/* compute degrees */
@@ -352,24 +352,8 @@ define fixdms(a)
quit "attempt to fix a non dms object";
}
/* force minutes to be intergral */
a.min += frac(a.deg) * 60;
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;
/* use builtin d2dms function */
d2dms(a.deg + a.min/60 + a.sec/3600, a.deg, a.min, a.sec),;
/* return normalized result */
return a;

View File

@@ -8,8 +8,8 @@
* 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
* 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,
@@ -157,7 +157,7 @@ define dotest(dotest_file, dotest_code = 0, dotest_maxcond = -1)
* test the close of the line file
*/
printf("%d-: detected %d error condition(s), many of which may be OK\n",
dotest_code, dotest_old_errcount-dotest_errcnt);
dotest_code, dotest_old_errcount-dotest_errcnt);
printf("%d-: closing line file: %d\n", dotest_code, dotest_file);
fclose(dotest_f_file);
@@ -173,7 +173,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
* of line tests that failed, not the number of internal

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -56,7 +56,7 @@ define __CZ__factor_factorial(n,start){
if(start){
if(!isint(start) && start < 0 && start > n)
return newerror("__CZ__factor_factorial(n,start): value of "
"parameter 'start' out of range");
"parameter 'start' out of range");
if(start == n && isprime(n)){
prime_list = mat[1 , 2];
prime_list[0,0] = n;
@@ -64,7 +64,7 @@ define __CZ__factor_factorial(n,start){
}
else if(!isprime(start) && nextprime(start) >n)
return newerror("__CZ__factor_factorial(n,start): value of parameter "
"'start' out of range");
"'start' out of range");
else{
if(!isprime(start)) prime = nextprime(start);
else prime = start;
@@ -225,11 +225,11 @@ define __CZ__multiply_factored_factorial(matrix,stop){
if(!ismat(matrix))
return newerror("__CZ__multiply_factored_factorial(matrix): "
"argument matrix not a matrix ");
"argument matrix not a matrix ");
if(!matrix[0,0])
return
newerror("__CZ__multiply_factored_factorial(matrix): "
"matrix[0,0] is null/0");
"matrix[0,0] is null/0");
if(!isnull(stop))
pix = stop;
@@ -281,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
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
needed is pi(N)--theoretically.
*/
@@ -376,7 +376,7 @@ define bigcatalan(n){
/*
df(-111) = -1/3472059605858239446587523014902616804783337112829102414124928
7753332469144201839599609375
7753332469144201839599609375
df(-3+1i) = 0.12532538977287649201-0.0502372106177184607i
df(2n + 1) = (2*n)!/(n!*2^n)
@@ -427,7 +427,7 @@ define doublefactorial(n){
*/
eps=epsilon(epsilon()*1e-2);
ret = 2^(n/2-1/4 * cos(pi()* n)+1/4) * pi()^(1/4 *
cos(pi()* n)-1/4)* gamma(n/2+1);
cos(pi()* n)-1/4)* gamma(n/2+1);
epsilon(eps);
return ret;
}
@@ -626,7 +626,7 @@ define subfactorialrecursive(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*/
define subfactorialiterative(n){
local k temp1 temp2 ret;

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -53,7 +53,7 @@ define hms_add(a, b)
{
local obj hms ans; /* return value */
/* initalize value to 1st arg */
/* initialize value to 1st arg */
if (istype(a, ans)) {
/* 1st arg is hms object, load it */
ans.hour = a.hour;
@@ -110,7 +110,7 @@ define hms_sub(a, b)
{
local obj hms ans; /* return value */
/* initalize value to 1st arg */
/* initialize value to 1st arg */
if (istype(a, ans)) {
/* 1st arg is hms object, load it */
ans.hour = a.hour;
@@ -188,7 +188,7 @@ define hms_abs(a)
/* firewall - just absolute value non hms objects */
if (! istype(a, ans)) {
return abs(a);
return abs(a);
}
/* compute hours */
@@ -352,24 +352,8 @@ define fixhms(a)
quit "attempt to fix a non hms object";
}
/* force minutes to be intergral */
a.min += frac(a.hour) * 60;
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;
/* use builtin h2hms function */
h2hms(a.hour + a.min/60 + a.sec/3600, a.hour, a.min, a.sec),;
/* return normalized result */
return a;

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -27,20 +27,20 @@
/*
* NOTE: Because leading HALF values are trimmed from integer, a file
* 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)
* 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)
* 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:
* filename filename to read
*
* returns:
* integer read from its contents on big endian order
* integer read from its contents on big Endian order
*/
define file2be(filename)
{
@@ -75,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:
* filename filename to read
*
* returns:
* integer read from its contents on little endian order
* integer read from its contents on little Endian order
*/
define file2le(filename)
{
@@ -118,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:
* v integer to write to the file
@@ -156,7 +156,7 @@ define be2file(v, filename)
*/
octlen = int((highbit(v)+8) / 8);
for (i=octlen-1; i >= 0; --i) {
fputc(fd, char(v >> (i*8)));
fputc(fd, char(v >> (i*8)));
}
/*
@@ -168,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:
* v integer to write to the file

View File

@@ -1,7 +1,7 @@
/*
* 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
* 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
* connecting a and b. Computing the segments here is a bit
* more complicated but not much, it should have been taught in
* highschool.
* high school.
* Other contours by way of a list of points */
slope = (im(b) - im(a)) / (re(b) - re(a));
C = (im(a) + slope) * re(a);

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -83,7 +83,7 @@ define __CZ__lambertw_m1(z,eps){
or by using the function lambertw_series_print() after running
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
converge in anybodies lifetime for something that far from the branchpoint).
converge in anybodies lifetime for something that far from the branch point).
*/
@@ -105,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.:
; lambertw(-exp(-1)+.001)-lambertw_series(-exp(-1)+.001,epsilon()*1e-10,0)

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -29,7 +29,7 @@
*
* given:
* 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
*
* returns:

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -28,6 +28,10 @@
* 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
*
* Also see the reference code, available both C and go:
*
* https://github.com/arcetri/goprime
*/
/*
@@ -154,6 +158,12 @@
*
* Finally, one should eliminate all values of 'h*2^n-1' where
* '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" */
@@ -243,8 +253,8 @@ pprod256 = 0; /* product of "primes up to 256" / "primes up to 46" */
* do make this so.
*
* input:
* h the h as in h*2^n-1
* n the n 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 (must be >= 1)
*
* returns:
* 1 => h*2^n-1 is prime
@@ -267,13 +277,17 @@ lucas(h, n)
* check arg types
*/
if (!isint(h)) {
ldebug("lucas", "h is non-int");
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)) {
ldebug("lucas", "n is non-int");
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
@@ -359,41 +373,53 @@ lucas(h, n)
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
*/
/*
* check for 3 <= prime factors < 29
* pfact(28)/2 = 111546435
* check for 5 <= prime factors < 31
* pfact(30)/6 = 1078282205
*/
testval = h*2^n - 1;
if (gcd(testval, 111546435) > 1) {
/* a small 3 <= prime < 29 divides h*2^n-1 */
ldebug("lucas","not-prime: 3<=prime<29 divides h*2^n-1");
if (gcd(testval, 1078282205) > 1) {
/* a small 5 <= prime < 31 divides h*2^n-1 */
ldebug("lucas",\
"not-prime: a small 5<=prime<31 divides h*2^n-1");
return 0;
}
/*
* check for 29 <= prime factors < 47
* pfact(46)/pfact(28) = 5864229
* check for 31 <= prime factors < 53
* pfact(52)/pfact(30) = 95041567
*/
if (gcd(testval, 58642669) > 1) {
/* a small 29 <= prime < 47 divides h*2^n-1 */
ldebug("lucas","not-prime: 29<=prime<47 divides h*2^n-1");
if (gcd(testval, 95041567) > 1) {
/* a small 31 <= prime < 53 divides h*2^n-1 */
ldebug("lucas","not-prime: 31<=prime<53 divides h*2^n-1");
return 0;
}
/*
* check for prime 47 <= factors < 257, if h*2^n-1 is large
* 2^282 > pfact(256)/pfact(46) > 2^281
* check for prime 53 <= factors < 257, if h*2^n-1 is large
* 2^276 > pfact(256)/pfact(52) > 2^275
*/
bits = highbit(testval);
if (bits >= 281) {
if (bits >= 275) {
if (pprod256 <= 0) {
pprod256 = pfact(256)/pfact(46);
pprod256 = pfact(256)/pfact(52);
}
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",\
"not-prime: 47<=prime<257 divides h*2^n-1");
"not-prime: 53<=prime<257 divides h*2^n-1");
return 0;
}
}
@@ -409,7 +435,9 @@ lucas(h, n)
* generate a test for h*2^n-1. The legacy function,
* legacy_gen_v1() used by the Amdahl 6 could have returned
* -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);
if (v1 < 0) {
@@ -484,9 +512,9 @@ lucas(h, n)
* See the function gen_v1() for details on the value of v(1).
*
* input:
* h - h as in h*2^n-1
* n - n as in h*2^n-1
* v1 - gen_v1(h,n) (see function below)
* h - h as in h*2^n-1 (must be >= 1)
* n - n as in h*2^n-1 (must be >= 1)
* v1 - gen_v1(h,n) (must be >= 3) (see function below)
*
* returns:
* u(2) - initial value for Lucas test on h*2^n-1
@@ -499,6 +527,8 @@ gen_u2(h, n, v1)
local r; /* low value: v(n) */
local s; /* high value: v(n+1) */
local hbits; /* highest bit set in h */
local oldh; /* pre-reduced h */
local oldn; /* pre-reduced n */
local i;
/*
@@ -507,24 +537,45 @@ gen_u2(h, n, v1)
if (!isint(h)) {
quit "bad args: h must be an integer";
}
if (h < 0) {
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";
}
if (!isint(v1)) {
quit "bad args: v1 must be an integer";
}
if (v1 <= 0) {
quit "bogus arg: v1 is <= 0";
if (v1 < 3) {
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
*/
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";
}
hbits = highbit(h);
if (hbits >= n) {
print " ERROR: h=":oldh, "n=":oldn, "reduced h=":h, "n=":n;
quit "reduced args violate the rule: 0 < h < 2^n";
}
@@ -599,8 +650,8 @@ gen_u2(h, n, v1)
* See the function gen_u2() for details.
*
* input:
* h - h as in h*2^n-1
* n - n 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 (must be >= 1)
* v1 - gen_v1(h,n) (see function below)
*
* returns:
@@ -638,9 +689,9 @@ gen_u0(h, n, v1)
* x > 2
*
* input:
* x - potential v(1) value
* h - h as in h*2^n-1
* n - n as in h*2^n-1
* x potential v(1) value
* h h as in h*2^n-1 (h must be odd >= 1)
* n n as in h*2^n-1 (must be >= 1)
*
* returns:
* 1 if v(1) == x for h*2^n-1
@@ -657,9 +708,18 @@ rodseth_xhn(x, h, n)
if (!isint(h)) {
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)) {
quit "bad args: n must be an integer";
}
if (n < 1) {
quit "bad args: n must be an integer >= 1";
}
if (!isint(x)) {
quit "bad args: x must be an integer";
}
@@ -671,7 +731,7 @@ rodseth_xhn(x, h, n)
return 0;
}
/*
/*
* Check for jacobi(x-2, h*2^n-1) == 1 (Ref4, condition 1) part 1
*/
testval = h*2^n-1;
@@ -679,7 +739,7 @@ rodseth_xhn(x, h, n)
return 0;
}
/*
/*
* Check for jacobi(x+2, h*2^n-1) == -1 (Ref4, condition 1) part 2
*/
if (jacobi(x+2, testval) != -1) {
@@ -703,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.
*
* 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
* near 3e7) where the sample size was 66 973 365, here is the count of the
* smallest value of X that satisfies conditions in Ref4, condition 1:
* of h*2^n-1, h odd multiple of 3, and large n (some around 1e4, some near 1e6,
* others near 3e7) where the sample size was 66 973 365, here is the count of
* the smallest value of X that satisfies conditions in Ref4, condition 1:
*
* count X
* ----------
@@ -763,45 +823,161 @@ rodseth_xhn(x, h, n)
* 1 161
* 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
* 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,
* 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,
* 56, 49, 59, 57, 65, 55, 69, 71, 77, 81, 66, 95, 80, 67, 84, 99, 72,
* 74, 87, 90, 104, 101, 105, 109, 116, 111, 92
* 3, 5, 9, 11, 15, 17, 21, 29, 27, 35, 39, 41, 31, 45, 51, 55, 49, 59,
* 69, 65, 71, 57, 85, 81, 95, 99, 77, 53, 67, 125, 111, 105, 87, 129,
* 101, 83, 165, 155, 149, 141, 121, 109
*
* 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
*
* If no value in that list works, we start simple search starting with X = 120
* and incrementing by 1 until a value of X is found.
* Less than 1 case out of 1000000 will not be satisfied by the above list.
* 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.
* If all x_tbl_len fail to satisfy Ref4 condition 1, then we begin a
* linear search 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.
* The x_tbl[] matrix contains those values of X to try in order.
* If all x_tbl_len fail to satisfy Ref4 condition 1 (this happens less than
* 1 in 1000000 cases), then we begin a linear search of odd values starting at
* next_x until we find a proper X value.
*/
x_tbl_len = 45;
x_tbl_len = 42;
mat x_tbl[x_tbl_len];
x_tbl = {
3, 5, 9, 11, 15, 17, 21, 29, 20, 27, 35, 36, 39, 41, 45, 32, 51, 44,
56, 49, 59, 57, 65, 55, 69, 71, 77, 81, 66, 95, 80, 67, 84, 99, 72,
74, 87, 90, 104, 101, 105, 109, 116, 111, 92
3, 5, 9, 11, 15, 17, 21, 29, 27, 35, 39, 41, 31, 45, 51, 55, 49, 59,
69, 65, 71, 57, 85, 81, 95, 99, 77, 53, 67, 125, 111, 105, 87, 129,
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
@@ -859,12 +1035,22 @@ next_x = 120;
*
* 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)
* = (2+sqrt(3)) + (2-sqrt(3))
* = 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)
@@ -956,17 +1142,22 @@ next_x = 120;
***
*
* input:
* h h as in h*2^n-1
* n n 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 (must be >= 1)
*
* 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
gen_v1(h, n)
{
local x; /* potential v(1) to test */
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
@@ -974,58 +1165,131 @@ gen_v1(h, n)
if (!isint(h)) {
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)) {
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)
*/
if (h % 3 != 0) {
/* v(1) is easy to compute */
return 4;
if (rodseth_xhn(3, h, n) == 1) {
/* 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)
*/
/*
* clear cache
*/
matfill(cached_v1, 0);
/*
* 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 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) {
/*
* test Ref4 condition 1:
* obtain the next test candidate
*/
x = x_tbl[i];
if (rodseth_xhn(x, h, n) == 1) {
/*
* 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;
/*
* Check x for condition 1 part 1
*
* jacobi(x-2, h*2^n-1) == 1
*/
v1m2 = x-2;
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
* 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.
* of odd values at next_x from here on.
*/
x = next_x;
while (rodseth_xhn(x, h, n) != 1) {
++x;
x += 2;
}
/* finally found a v(1) value */
ldebug("gen_v1", "h= " + str(h) + " n= " + str(n) +
@@ -1457,8 +1721,8 @@ legacy_d_qval[7] = 19; legacy_v1_qval[7] = 74; /* a=38 b=1 r=2 */
***
*
* input:
* h h as in h*2^n-1
* n n 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 (must be >= 1)
*
* output:
* returns v(1), or -1 is there is no quick way
@@ -1470,6 +1734,22 @@ legacy_gen_v1(h, n)
local val_mod; /* h*2^n-1 mod 'D' */
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
*/

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -303,7 +303,7 @@ read -once "lucas.cal";
* [quiet] if given and != 0, then do not print individual test results
*
* returns:
* 1 all is ok
* 1 all is OK
* 0 something went wrong
*/
define

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -79,7 +79,7 @@
* hindx = 0;
* } 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[])
* 78.35 (hset[] for p_elim = 7)
@@ -99,7 +99,7 @@
* 57.78 (hset[] for p_elim = 17)
* 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
* takes about 3 seconds and requires ~1.5 Megs of memory.
*
@@ -256,7 +256,7 @@ define mfactor(n, start_k, rept_loop, p_elim)
return q;
} else {
/* 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());
fflush(files(1));
loop = 0;
@@ -269,14 +269,14 @@ define mfactor(n, start_k, rept_loop, p_elim)
*/
if (rept_loop <= ++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());
fflush(files(1));
loop = 0;
}
/*
* skip if divisable by a prime <= 449
* skip if divisible by a prime <= 449
*
* The value 281 was determined by timing loops
* which found that 281 was at or near the
@@ -285,7 +285,7 @@ define mfactor(n, start_k, rept_loop, p_elim)
* The addition of the do { ... } while (factor(q, 449)>1);
* loop reduced the factoring loop time (36504 k values with
* 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 {
/*

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -76,7 +76,7 @@
* A \ B = set difference, integers in A but not in B
*
* ~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 = sum of the members of A
*
@@ -100,7 +100,7 @@
* 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
* rules. For example
*

641
cal/palindrome.cal Normal file
View 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;
}

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -25,7 +25,7 @@
/*
* 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.
*/

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -74,7 +74,7 @@ define qpi(epsilon)
/*
* 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.
*
* Inspired by an algorithm conceived by Lambert Meertens.

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -35,7 +35,7 @@
* variable has only one name. For some purposes, a name like
* "sin(t)" or "(a + b)" or "\lambda" might be useful;
* 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
* independent variable and other polynomials by the algebraic
@@ -43,7 +43,7 @@
* The operations // and % are defined to have the quotient and
* 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
* 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

View File

@@ -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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -61,9 +61,9 @@
* nothing to sum. The last line returns the value 3, i.e. the last
* non-null value found for the expressions separated by semicolons,
* 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
* 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,
* or if the string has syntax errors as in "2 + ", in which case the
@@ -75,7 +75,7 @@
* "sin(x)", "x^2 + 3*x", "exp(x, 1e-5)".
*
* 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".
*/

View File

@@ -1,9 +1,9 @@
/*
* 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/>
*
* Calc is open software; you can redistribute it and/or modify it under

View File

@@ -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
* the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -45,9 +45,9 @@ randmprime(bits, seed, dbg)
local n; /* n 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 init; /* initial cpu time */
local start; /* cpu time before last test */
local stop; /* cpu time afte last test */
local init; /* initial CPU time */
local start; /* CPU time before last test */
local stop; /* CPU time after last test */
local tmp; /* just a tmp place holder value */
local ret; /* h*2^n-1 that is prime */

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
##
## 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
## the terms of the version 2.1 of the GNU Lesser General Public License
@@ -159,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 == set8700_B
## Testing matrix protectioon
## Testing matrix protection
set8700_A = mat [3] = {1, 2, list(3,4)}; 1
protect(set8700_A, 65, 1), protect(set8700_A) == 1089
protect(set8700_A[0]) == 65
@@ -261,7 +261,7 @@ protect(set8700_L[0]) == 0
protect(set8700_L[1]) == 512 ## protect(set8700_A) 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
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

View File

@@ -1,7 +1,7 @@
/*
* 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
* it under the terms of the version 2.1 of the GNU Lesser General Public
@@ -442,8 +442,8 @@ define lngamma(z)
if (tmp2 < tmp) {
return
newerror(strcat
("lngamma(1): something happend that ",
"should not have happend"));
("lngamma(1): something happened ",
"that shouldn't have happened"));
}
}
}
@@ -519,8 +519,8 @@ define lngamma(z)
if (tmp2 < tmp) {
return
newerror(strcat
("lngamma(1): something happend ",
"that should not have happend"));
("lngamma(1): something happened ",
"that should not have happened"));
}
}
}
@@ -576,8 +576,8 @@ define lngamma(z)
if (tmp2 < tmp) {
return
newerror(strcat
("lngamma(1): something happend ",
"that should not have happend"));
("lngamma(1): something happened ",
"that should not have happened"));
}
}
}
@@ -1047,7 +1047,7 @@ define __CZ__ibeta_cf_var_dm(a, b, z, max)
}
}
if (m > max) {
return newerror("ibeta: continous fraction does not converge");
return newerror("ibeta: continuous fraction does not converge");
}
return f;
}
@@ -1290,7 +1290,7 @@ define __CZ__erfinvapprox(x)
- (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
in the 'tail-end' region" Math. Comp., 28:585-587, 1974.
*/
@@ -1324,7 +1324,7 @@ define __CZ__fettiscf(y, n)
return t / (1 + r);
}
/* inverse errror function, faster at about x<=.91*/
/* inverse error function, faster at about x<=.91*/
define __CZ__inverfbin(x)
{
local places approx flow fhigh eps high low mid fmid epsilon;
@@ -1370,7 +1370,7 @@ define erfinv(x)
x = -x;
flag = 1;
}
/* No need for full pecision */
/* No need for full precision */
eps = epsilon(1e-20);
if (eps >= 1e-40) {
/* Winitzki, Sergei (6 February 2008). "A handy approximation for the

View File

@@ -1,7 +1,7 @@
/*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -106,7 +106,7 @@ define invbetainc_slow(x,a,b){
GW Cran, KJ Martin, GE Thomas,
Remark AS R19 and Algorithm AS 109:
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,
Volume 26, Number 1, 1977, pages 111-114.
@@ -371,7 +371,7 @@ define normalcdf(x,mu,sigma){
define probit(p){
if(p<0 || p > 1) return newerror("probit: p out of domain 0<=p<=1");
return sqrt(2)*ervinv(2*p-1);
return sqrt(2)*erfinv(2*p-1);
}
define normalcdfinv(p,mu,sigma){

View File

@@ -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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -160,7 +160,7 @@ define timehmean(N, M = 10) {
v2 = hmean(sumtimes_A);
sumtimes_t2 = usertime();
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('\tUsing builtin "hmean":\t\t%.4f\n', sumtimes_t2 - sumtimes_t1);
}

View File

@@ -1,7 +1,7 @@
/*
* test2600 - 2600 series of the regress.cal test suite
*
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
* Copyright (C) 1999,2021 Ernest Bowen and Landon Curt Noll
*
* Primary author: Ernest Bowen
*
@@ -50,7 +50,7 @@
* of b in power(a, b, eps) is large, the computation required for
* a test may be very heavy.
*
* Test funcations are called as:
* Test functions are called as:
*
* testabc(str, ..., verbose)
*

View File

@@ -1,7 +1,7 @@
/*
* test2700 - 2700 series of the regress.cal test suite
*
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
* Copyright (C) 1999,2021 Ernest Bowen and Landon Curt Noll
*
* Primary author: Ernest Bowen
*
@@ -84,7 +84,7 @@ define mkfrac() = rand(2) ? mkposfrac() : -mkposfrac();
define mksquarereal() = mknonnegreal()^2;
/*
* We might be able to do better than the following. For nonsquare
* We might be able to do better than the following. For non-square
* positive integer less than 1e6, could use:
* x = rand(1, 1000);
* return rand(x^2 + 1, (x + 1)^2);

View File

@@ -1,7 +1,7 @@
/*
* test5100 - 5100 series of the regress.cal test suite
*
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
* Copyright (C) 1999,2021 Ernest Bowen and Landon Curt Noll
*
* Primary author: Ernest Bowen
*
@@ -35,7 +35,7 @@ defaultverbose = 1; /* default verbose value */
* with zero value, when the definition is read.
*
* The variable a5100 is initialized with the value x if and when this
* function is first called with a positive even x. The varable b5100
* function is first called with a positive even x. The variable b5100
* is similarly initialized if and when this function is first called positive
* odd x.
*

View File

@@ -1,7 +1,7 @@
/*
* test8500 - 8500 series of the regress.cal test suite
*
* Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
* Copyright (C) 1999,2021 Ernest Bowen and Landon Curt Noll
*
* Primary author: Ernest Bowen
*
@@ -169,7 +169,7 @@ define divmod_8500(N = 10, M1 = 2^128, M2 = 2^64, testnum = 0)
}
/*
* seelect one of the 32 rounding modes at random
* select one of the 32 rounding modes at random
*/
rnd = rand(32);

View File

@@ -1,7 +1,7 @@
/*
* test8900 - 8900 series of the regress.cal test suite
*
* Copyright (C) 2013 Christoph Zurnieden
* Copyright (C) 2013,2021 Christoph Zurnieden
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -26,7 +26,7 @@ static __CZ__eps = 1e-20;
/*
* load once, the calc resource functions contribued by Christoph Zurnieden
* load once, the calc resource functions contributed by Christoph Zurnieden
*/
read -once bernpoly.cal;
read -once brentsolve.cal;
@@ -45,7 +45,7 @@ read -once intnum.cal;
/*
* tests of correctness of the functions implemented by the above listed
* author. All values tested against have been computed with at least two
* independant algorithms where possible (indicated if not).
* independent algorithms where possible (indicated if not).
*/
define t01()
{
@@ -1649,7 +1649,7 @@ define t03()
/* test 04 tests polygamma(m,z) for the following values (m==0 gets computed
* by psi()).
* Values tested against were computed with Mathematica(TM) only
* (z in the left complex halfplane does not get computed yet)
* (z in the left complex half plane does not get computed yet)
*/
define t04()
{
@@ -2057,7 +2057,18 @@ define t010()
epsilon(eps);
return 5;
}
if ((stirling2(10, 5) - (42525)) != 0) {
/*
* When an expression such as 0^(6-6) returned 0,
* then stirling2(10, 5) == 42525. However when we made9
* 0^(6-6) == 0^0 == 1, then stirling2(10, 5) == 5102999/120
* as in:
*
* if ((stirling2(10, 5) - (5102999/120)) != 0) {
* epsilon(eps);
* return 6;
* }
*/
if ((stirling2(10, 5) - 42525) != 0) {
epsilon(eps);
return 6;
}
@@ -2862,7 +2873,7 @@ define t035()
epsilon(eps);
return 6;
}
/* Percentiles. Numbers shamlessly stolen from a question at stackoverflow*/
/* Percentiles. Numbers shamelessly stolen from a question at stackoverflow */
if (abs
(invbetainc(0.025, 10008, 151744) -
0.060703546312525377697082321820950758320207425674954679415395) >
@@ -3076,7 +3087,7 @@ define test8900(verbose = 0, tnum, testnum = 8903)
return tnum;
}
/* We will cause erors intentionally. A lot of them. */
/* We will cause errors intentionally. A lot of them. */
old_errmax = errmax(-1);
/*

View File

@@ -1,7 +1,7 @@
/*
* toomcook - implementation of Toom-Cook(3,4) multiplication algorithm
*
* Copyright (C) 2013 Christoph Zurnieden
* Copyright (C) 2013,2021 Christoph Zurnieden
*
* 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
@@ -320,23 +320,23 @@ define toomcook4square(a){
}
/*
TODO: Implement the asymmetric variations
*/
* TODO: Implement the asymmetric variations
*/
/*
produce_long_random_number(n) returns large pseudorandom numbers. Really large
numbers, e.g.:
produce_long_random_number(16)
is ca 4,128,561 bits (ca 1,242,821 dec. digits) large. Exact length is not
predeterminable because of the chaotic output of the function random().
*/
* produce_long_random_number(n) returns large pseudo-random numbers.
* Really large numbers, e.g.:
* produce_long_random_number(16)
* is ca 4,128,561 bits (ca 1,242,821 dec. digits) large. Exact length is not
* pre-determinable because of the chaotic output of the function random().
*/
define __CZ__produce_long_random_number(n)
{
local ret k;
ret = 1;
if(!isint(n) || n<1)
return newerror("__CZ__produce_long_random_number(n): "
"n is not an integer >=1");
"n is not an integer >=1");
for(k=0;k<n;k++){
ret += random();
ret = toomcook4square(ret);

View File

@@ -1,7 +1,7 @@
/*
* unixfrac - represent a fraction as a sum of distince unit fractions
* unixfrac - represent a fraction as a sum of distance unit fractions
*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -34,7 +34,7 @@ define hurwitzzeta(s,a){
/*
According to Linas Vepstas' "An efficient algorithm for accelerating
the convergence of oscillatory series, useful for computing the
polylogarithm and Hurwitz zeta functions" the Euler-Maclaurin series
poly-logarithm and Hurwitz zeta functions" the Euler-Maclaurin series
is the fastest in most cases.
With a lot of help of the PARI/GP implementation by Prof. Henri Cohen,
@@ -72,13 +72,13 @@ define hurwitzzeta(s,a){
limit=(precision*ln(10)-re((s-.5)*result)+(1.*realpart_a)*ln(2.*pi()))/2;
limit=max(2,ceil(max(limit,abs(s*1.)/2)));
limit_function=ceil(sqrt((limit+realpart_a/2-.25)^2+(imagpart_s*1.)^2/4)/
pi());
pi());
if (config("user_debug") > 0) {
print "limit_function = " limit_function;
print "limit = " limit;
print "prec = " precision;
}
/* Full precison plus 5 digits angstzuschlag*/
/* Full precision plus 5 digits angstzuschlag*/
epsilon( (10^(-precision)) * 1e-5);
tmp3=(a+limit_function+0.)^(-s);
sum3 = tmp3/2;

150
calc.c
View File

@@ -1,7 +1,7 @@
/*
* calc - arbitrary precision calculator
*
* Copyright (C) 1999-2013 David I. Bell, Landon Curt Noll and Ernest Bowen
* Copyright (C) 1999-2013,2021,2022 David I. Bell, Landon Curt Noll and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -25,18 +25,17 @@
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
#include <stdio.h>
#include <signal.h>
#if !defined (_WIN32)
#if !defined(_WIN32) && !defined(_WIN64)
# include <pwd.h>
#endif
#include <sys/types.h>
#include <ctype.h>
#if defined(_WIN32)
#if defined(_WIN32) || defined(_WIN64)
# include <io.h>
# if !defined(NOTCYGWIN)
/*
@@ -49,7 +48,7 @@
# endif
# define strdup _strdup
# define isatty _isatty
#endif /* Windoz */
#endif /* Windows */
#define CALC_C
#include "calc.h"
@@ -65,6 +64,7 @@
#include "lib_calc.h"
#include "args.h"
#include "zmath.h"
#include "strl.h"
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
@@ -84,6 +84,10 @@
#include "have_unused.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
/*
* S_FUNC definitions and functions
*/
@@ -104,6 +108,8 @@ main(int argc, char **argv)
int c; /* option */
int index;
int maxindex;
/* fix gcc warning bug */
int unusedint = 0;
char *cp;
char *endcp;
char *bp;
@@ -117,6 +123,11 @@ main(int argc, char **argv)
* parse args
*/
program = argv[0];
script_name = strdup(argv[0]);
if (script_name == NULL) {
fprintf(stderr, "%s: failed to strdup(argv[0])\n", program);
exit(1);
}
cmdbuf[0] = '\0';
cmdlen = 0;
@@ -266,30 +277,32 @@ main(int argc, char **argv)
if (nextcp(&cp, &index, argc, argv,
FALSE)) {
fprintf(stderr,
"-D expects argument\n");
"-D expects argument\n");
exit(5);
}
havearg = TRUE;
if (*cp != ':') {
if (*cp < '0' || *cp > '9') {
fprintf(stderr,
"-D expects"
"-D expects"
" integer\n");
exit(6);
}
calc_debug = cp;
(void) strtol(cp, &endcp, 10);
/* fix gcc warning bug */
unusedint =
strtol(cp, &endcp, 10);
cp = endcp;
if (*cp != '\0' &&
*cp != ' ' && *cp != ':') {
fprintf(stderr,
"Bad syntax im -D"
"Bad syntax im -D"
" arg\n");
exit(7);
}
if (*cp != ':') {
if (nextcp(&cp, &index,
argc, argv,
argc, argv,
FALSE)
|| *cp != ':')
break;
@@ -305,23 +318,25 @@ main(int argc, char **argv)
if (*cp != ':') {
if (*cp < '0' || *cp > '9') {
fprintf(stderr,
"-D : expects"
"-D : expects"
" integer\n");
exit(9);
}
resource_debug = cp;
(void) strtol(cp, &endcp, 10);
/* fix gcc warning bug */
unusedint =
strtol(cp, &endcp, 10);
cp = endcp;
if (*cp != '\0' &&
*cp != ' ' && *cp != ':') {
fprintf(stderr,
"Bad syntax im -D"
"Bad syntax im -D"
" : arg\n");
exit(10);
}
if (*cp != ':') {
if (nextcp(&cp, &index,
argc, argv,
argc, argv,
FALSE)
|| *cp != ':') {
break;
@@ -331,16 +346,17 @@ main(int argc, char **argv)
if (nextcp(&cp, &index, argc, argv,
FALSE)) {
fprintf(stderr, "-D : : expects"
" argument\n");
" argument\n");
exit(11);
}
if (*cp < '0' || *cp > '9') {
fprintf(stderr, "-D :: expects"
" integer\n");
" integer\n");
exit(12);
}
user_debug = cp;
(void) strtol(cp, &endcp, 10);
/* unusedint avoids gcc warning bug */
unusedint = strtol(cp, &endcp, 10);
cp = endcp;
if (*cp != '\0' && *cp != ' ') {
fprintf(stderr, "Bad syntax in"
@@ -365,40 +381,62 @@ main(int argc, char **argv)
havearg = TRUE;
if (cmdlen > 0)
cmdbuf[cmdlen++] = ' ';
strcpy(cmdbuf + cmdlen, "read ");
cmdlen += 5;
if (strncmp(cp, "-once", 5) == 0 &&
(cp[5] == '\0' || cp[5] == ' ')) {
cp += 5;
strlcpy(cmdbuf + cmdlen, "read ",
sizeof("read "));
cmdlen += sizeof("read ")-1;
cmdbuf[cmdlen] = '\0';
if (strncmp(cp, "-once",
sizeof("-once")) == 0 &&
(cp[sizeof("-once")-1] == '\0' ||
cp[sizeof("-once")-1] == ' ')) {
cp += sizeof("-once")-1;
haveendstr = (*cp == '\0');
strcpy(cmdbuf+cmdlen, "-once ");
cmdlen += 6;
strlcpy(cmdbuf+cmdlen, "-once ",
sizeof("-once "));
cmdlen += sizeof("-once ")-1;
cmdbuf[cmdlen] = '\0';
if (nextcp(&cp, &index, argc,
argv, haveendstr)) {
fprintf(stderr, "-f -once"
" expects"
" expects"
" filename\n");
exit(16);
}
}
bp = cmdbuf + cmdlen;
/*
* duplicate -f filename arg
* as a new script_name value
*/
if (script_name != NULL) {
free(script_name);
}
script_name = NULL;
script_name = strdup(cp);
if (script_name == NULL) {
fprintf(stderr,
"strdup(-f argument)"
"failed\n");
exit(17);
}
/* process -f filename arg */
if (haveendstr) {
len = strlen(cp);
if (len == 0) {
fprintf(stderr,
"Null"
" filename!");
exit(17);
" filename!\n");
exit(18);
}
if (cmdlen + len + 2 > MAXCMD) {
fprintf(stderr,
"Commands too"
" long");
exit(18);
" long\n");
exit(19);
}
/* XXX What if *cp = '\''? */
/* XXX - what if *cp = '\''? */
*bp++ = '\'';
strncpy(bp, cp, len+1);
strlcpy(bp, cp, len+1);
bp += len;
*bp++ = '\'';
cp += len;
@@ -406,10 +444,10 @@ main(int argc, char **argv)
} else {
do {
if (cmdlen > MAXCMD) {
fprintf(stderr,
"Commands"
" too long");
exit(19);
fprintf(stderr,
"Commands"
" too long\n");
exit(20);
}
*bp++ = *cp++;
cmdlen++;
@@ -420,8 +458,12 @@ main(int argc, char **argv)
if (*cp == ';')
cp++;
*bp++ = ';';
*bp = '\0';
cmdlen++;
s_flag = TRUE; /* -f implies -s */
/* -f implies -s */
s_flag = TRUE;
maxindex = index + 1;
break;
case 's':
@@ -442,9 +484,9 @@ main(int argc, char **argv)
"\t[-O] [-p] [-q] [-s] [-u] [-v] "
"[--] [calc_cmd ...]\n"
"usage: %s ... -f filename\n"
"1st cscript line: #/path/to/calc ... -f\n",
"1st cscript line: #/path/to/calc ... -s -f\n",
program, program);
exit(20);
exit(21);
}
if (havearg)
break;
@@ -470,9 +512,10 @@ main(int argc, char **argv)
fprintf(stderr,
"%s: commands too long\n",
program);
exit(21);
exit(22);
}
strncpy(cmdbuf + cmdlen, cp, cplen+1);
strlcpy(cmdbuf + cmdlen, cp, cplen+1);
cmdbuf[newcmdlen] = '\0';
cmdlen = newcmdlen;
index++;
if (index < maxindex)
@@ -492,7 +535,7 @@ main(int argc, char **argv)
}
}
argc_value = argc - maxindex;
argc_value = argc - maxindex + 1;
argv_value = argv + maxindex;
/*
@@ -505,7 +548,6 @@ main(int argc, char **argv)
setbuf(stdout, NULL);
}
/*
* initialize
*/
@@ -662,18 +704,18 @@ main(int argc, char **argv)
if (!p_flag && i_flag && !stdin_tty) {
closeinput();
if(!freopen("/dev/tty", "r", stdin)) {
#if defined (_WIN32)
#if defined(_WIN32) || defined(_WIN64)
fprintf(stderr,
"/dev/tty does not exist on "
"this operating system. "
"Change operating systems\n"
"or don't use this calc mode "
"in the future, sorry!\n");
#else /* Windoz free systems */
#else /* Windows free systems */
fprintf(stderr,
"Unable to associate stdin"
" with /dev/tty");
#endif /* Windoz free systems */
#endif /* Windows free systems */
set_run_state(RUN_EXIT_WITH_ERROR);
break;
}
@@ -692,18 +734,18 @@ main(int argc, char **argv)
!p_flag && (!havecommands||i_flag)) {
closeinput();
if(!freopen("/dev/tty", "r", stdin)) {
#if defined (_WIN32)
#if defined(_WIN32) || defined(_WIN64)
fprintf(stderr,
"/dev/tty does not exist on "
"this operating system. "
"Change operating systems\n"
"or don't use this calc mode "
"in the future, sorry!\n");
#else /* Windoz free systems */
#else /* Windows free systems */
fprintf(stderr,
"Unable to associate stdin"
" with /dev/tty");
#endif /* Windoz free systems */
#endif /* Windows free systems */
set_run_state(RUN_EXIT_WITH_ERROR);
break;
}
@@ -721,8 +763,10 @@ main(int argc, char **argv)
printf("main: run_state = %s\n", run_state_name(run_state));
/*
* all done
* All done! - Jessica Noll, Age 2
*/
/* fix gcc warning bug */
unusedint++;
libcalc_call_me_last();
return (run_state == RUN_EXIT_WITH_ERROR ||
run_state == RUN_ZERO) ? 1 : 0;
@@ -737,12 +781,12 @@ main(int argc, char **argv)
*/
/*ARGSUSED*/
S_FUNC void
intint(int UNUSED arg)
intint(int UNUSED(arg))
{
(void) signal(SIGINT, intint);
if (inputwait || (++abortlevel >= ABORT_NOW)) {
calc_interrupt("\nABORT");
/*NOTREACHED*/
not_reached();
}
if (abortlevel >= ABORT_MATH)
_math_abort_ = TRUE;
@@ -766,7 +810,7 @@ calc_interrupt(char *fmt, ...)
va_start(ap, fmt);
vsnprintf(calc_err_msg, MAXERROR, fmt, ap);
va_end(ap);
calc_err_msg[MAXERROR] = '\0';
calc_err_msg[MAXERROR] = '\0'; /* paranoia */
fprintf(stderr, "%s\n\n", calc_err_msg);
funcname = NULL;
if (calc_use_scanerr_jmpbuf != 0) {
@@ -778,7 +822,7 @@ calc_interrupt(char *fmt, ...)
* don't call libcalc_call_me_last() -- we might loop
* and besides ... this is an unusual internal error case
*/
exit(22);
exit(24);
}
}

17
calc.h
View File

@@ -1,7 +1,7 @@
/*
* calc - definitions for calculator program
*
* Copyright (C) 1999-2007,2014 David I. Bell
* Copyright (C) 1999-2007,2014,2021 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -48,6 +48,9 @@
#define HOME "HOME" /* environment variable for home dir */
#define PAGER "PAGER" /* environment variable for help */
#define SHELL "SHELL" /* environment variable for shell */
#define CALCHISTFILE "CALCHISTFILE" /* history file environment variable */
#define CALCHELP "CALCHELP" /* help directory env variable */
#define CALCCUSTOMHELP "CALCCUSTOMHELP"/* custom help directory env variable */
#define DEFAULTCALCBINDINGS "bindings" /* default calc bindings file */
#define DEFAULTCALCHELP "help" /* help file that -h prints */
#define DEFAULTSHELL "sh" /* default shell to use */
@@ -56,7 +59,7 @@
#define HOMECHAR '~' /* char which indicates home directory */
#define DOTCHAR '.' /* char which indicates current directory */
#define PATHCHAR '/' /* char which separates path components */
#if defined(__MSDOS__) || defined(__WIN32)
#if defined(_WIN32) || defined(_WIN64)
#define LISTCHAR ';' /* char which separates paths in a list */
#else
#define LISTCHAR ':' /* char which separates paths in a list */
@@ -65,7 +68,6 @@
#define SYMBOLSIZE 256 /* maximum symbol name size */
#define MAXLABELS 100 /* maximum number of user labels in function */
#define MAXSTRING 1024 /* maximum size of string constant */
#define MAXSTACK 2048 /* maximum depth of evaluation stack */
#define MAXFILES 20 /* maximum number of opened files */
#define PROMPT1 "> " /* default normal prompt*/
@@ -121,7 +123,7 @@ E_FUNC int get_inode(FILEID id, ZVALUE *ino);
E_FUNC FILEID reopenid(FILEID id, char *mode, char *name);
E_FUNC int closeall(void);
#if !defined(_WIN32)
#if !defined(_WIN32) && !defined(_WIN64)
E_FUNC int flushall(void);
#endif
@@ -184,7 +186,7 @@ E_FUNC char *calc_strdup(CONST char *);
*/
E_FUNC void initialize(void);
E_FUNC void reinitialize(void);
#if !defined (_WIN32)
#if !defined(_WIN32) && !defined(_WIN64)
E_FUNC int isatty(int tty); /* TRUE if fd is a tty */
#endif
E_FUNC char *version(void); /* return version string */
@@ -214,6 +216,7 @@ EXTERN int havecommands; /* TRUE if have cmd args) */
EXTERN char *program; /* our name */
EXTERN char *base_name; /* basename of our name */
EXTERN char cmdbuf[]; /* command line expression */
EXTERN char *script_name; /* program name or -f filename arg or NULL */
EXTERN int abortlevel; /* current level of aborts */
EXTERN BOOL inputwait; /* TRUE if in a terminal input wait */
@@ -230,8 +233,8 @@ EXTERN int no_env; /* TRUE (-e) => ignore env vars on startup */
EXTERN long errmax; /* if >= 0, error when errcount exceeds errmax */
EXTERN int use_old_std; /* TRUE (-O) => use classic configuration */
EXTERN int allow_read; /* FALSE => dont open any files for reading */
EXTERN int allow_write; /* FALSE => dont open any files for writing */
EXTERN int allow_read; /* FALSE => don't open any files for reading */
EXTERN int allow_write; /* FALSE => don't open any files for writing */
EXTERN int allow_exec; /* FALSE => may not execute any commands */
/*

568
calc.man
View File

@@ -1,5 +1,5 @@
.\"
.\" Copyright (C) 1999-2007,2014 Landon Curt Noll
.\" Copyright (C) 1999-2007,2014,2018,2021 Landon Curt Noll
.\"
.\" Calc is open software; you can redistribute it and/or modify it under
.\" the terms of the version 2.1 of the GNU Lesser General Public License
@@ -24,7 +24,7 @@
.\" calculator by David I. Bell
.\" man page by Landon Noll
.\"
.TH calc 1 "^..^" "2007-02-06"
.TH calc 1 "^..^" "Share and enjoy! :-)"
.SH NAME
calc \- arbitrary precision calculator
.SH SYNOPSIS
@@ -37,6 +37,7 @@ calc \- arbitrary precision calculator
.RB [ -D\ \&calc_debug[:resource_debug[:user_debug]] ]
.br
.RB [ \-e ]
.RB [ \-f\ \&filename ]
.RB [ \-h ]
.RB [ \-i ]
.RB [ \-m\ \&mode ]
@@ -50,11 +51,12 @@ calc \- arbitrary precision calculator
.RB [ [\-\-]\ calc_cmd\ \&.\|.\|. ]
.in -5n
.sp
\fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-f\fP
\fI#!${BINDIR}/calc\fP\ [optional_other_flags\ \&...] \fB\-f\fP
.PP
.SH DESCRIPTION
\&
.br
CALC OPTIONS
.PP
.TP
@@ -138,7 +140,7 @@ calc -d "read qtime; qtime(2)"
.fi
.in -5n
.sp 1
will just say:
will just print:
.sp 1
.in +5n
.nf
@@ -148,6 +150,41 @@ It's nearly ten past six.
.sp 1
This flag disables the reporting of missing calc
startup resource files.
.sp 1
This flag also disables the printing the leading tilde. For example:
.sp 1
.in +5n
.nf
calc 2/3
.fi
.in -5n
.sp 1
will print:
.sp 1
.in +5n
.nf
~0.66666666666666666667
.fi
.in -5n
.sp 1
.sp 1
whereas:
.sp 1
.in +5n
.nf
calc -d 2/3
.fi
.in -5n
.sp 1
will just print:
.sp 1
.in +5n
.nf
0.66666666666666666667
.fi
.in -5n
.sp 1
.TP
.BR -D " calc_debug[:resource_debug[:user_debug]]"
@@ -183,43 +220,55 @@ Ignore any environment variables on startup.
The getenv() builtin will still return values, however.
.TP
.B \-f
.BR \-f " filename"
This flag is normally only with calc shell scripts.
.sp 1
This flag is required when using calc in
.BR "shell script mode" .
It must be at the end of the initial
.B #!
line of the script.
.sp 1
This flag is normally only at the end of a calc shell script.
If the first line of an executable file begins
.B #!
followed by the absolute pathname of the
.B calc
program and the flag
.B \-f
as in:
line of the script, as in:
.sp 1
.in +5n
.nf
\fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-f\fP
\fI#!${BINDIR}/calc\fP\ [optional_other_flags\ \&...] \fB\-f\fP
.fi
.in -5n
.sp 1
the rest of the file will be processed in
.BR "shell script mode" .
.sp 1
A common flag to use, prior to the
.B \-f
on the #! line is the
.B \-q
flag.
For example:
.sp 1
.in +5n
.nf
\fI#!${BINDIR}/calc\fP \fB\-q\fP \fB\-f\fP
.fi
.in -5n
.sp 1
This allows the script to run independently of
startup scripts.
.sp 1
See
.B "SHELL SCRIPT MODE"
section of this man page
below for details.
.sp 1
The actual form of this flag is:
While the actual form of this flag is:
.sp 1
.in +5n
.B \-f
.BR \-f
filename
.in -5n
.sp 1
On systems that treat an executable that begins with
for systems that treat an executable that begins with
.B #!
as a script, the path of the executable is appended by the kernel
as the final argument to the exec() system call.
@@ -230,12 +279,13 @@ flag at the very end of the
line.
.sp 1
It is possible use
.B \-f\ filename
.B \-f
filename
on the command line:
.sp 1
.in +5n
.nf
\fIcalc\fP\ [other_flags\ \&...] \fB\-f\fP filename
\fIcalc\fP\ [optional_other_flags\ \&...] \fB\-f\fP filename
.fi
.in -5n
.sp 1
@@ -243,18 +293,14 @@ This will cause calc to process lines in
.B filename
in
.BR "shell script mode" .
.sp 1
Use of
The use of
.B \-f
implies
.BR \-s .
In addition,
.B \-d
and
.B \-p
are implied if
.B \-i
is not given.
filename
implies the
.B \-s
flag.
.TP
.B \-h
@@ -441,16 +487,16 @@ This is useful when entering negative values on the command line as in:
.in +5n
.nf
calc \-p \-\- \-1 - -7
.sp 1
.fi
.in -5n
.sp 1
.PP
\&
.br
CALC COMMAND LINE
.SH CALC COMMAND LINE
.PP
With no
.I calc_cmd
arguments,
@@ -588,10 +634,10 @@ to parse interactive commands, flushes data on standard input.
.PP
\&
.br
CALC STARTUP FILES
.SH CALC STARTUP FILES
.PP
Normally on startup,
if the environment variable
.B $CALCRC
@@ -628,10 +674,12 @@ files is also disabled as if
.B \-q
was given.
\&
.br
CALC FILE SEARCH PATH
.PP
.SH CALC FILE SEARCH PATH
.PP
If the environment variable
.B $CALCPATH
is undefined, or if it
@@ -657,8 +705,8 @@ searches in succession:
.sp 1
.in +5n
.nf
./myfile
./myfile.cal
\a./myfile
\a./myfile.cal
${LIBDIR}/myfile
${LIBDIR}/myfile.cal
${CUSTOMCALDIR}/myfile
@@ -708,36 +756,39 @@ help config
.fi
.in -5n
.sp 1
.PP
\&
.br
SHELL SCRIPT MODE
.SH SHELL SCRIPT MODE
.PP
If the first line of an executable file begins
.B #!
followed by the absolute pathname of the
.B calc
program and the flag
program and the first line ends with the flag
.B \-f
as in:
.sp 1
.in +5n
.nf
\fI#!${BINDIR}/calc\fP\ [other_flags\ \&...] \fB\-f\fP
\fI#!${BINDIR}/calc\fP\ [optional_other_flags\ \&...] \fB\-f\fP
.fi
.in -5n
.sp 1
the rest of the file will be processed in
.BR "shell script mode" .
Note that
.B \-s
.B \-f
must at the end of the initial ``#!'' line.
Any other optional
.B "other_flags"
.B "optional_other_flags"
must come before
the
.BR \-f .
.B \-f
flag.
.sp 1
In
.B "shell script mode"
@@ -746,7 +797,7 @@ executed as if they were in a file being processed by a read
command, except that a "command" beginning with '#' followed by
whitespace and ending at the next newline is treated as a comment.
Any optional
.B "other_flags"
.B "optional_other_flags"
will be parsed first followed by
the later lines within the script itself.
.sp 1
@@ -769,17 +820,25 @@ the file
.in +5n
.nf
\fI#!${BINDIR}/calc\fP\ \&\fB\-q\fP \fB\-f\fP
#
# mersenne - an example of a calc \fBshell script file\fP
/* setup */
argc = argv();
program = argv(0);
stderr = files(2);
/* parse args */
if (argv() != 1) {
fprintf(files(2), "usage: %s exp\\n", config("program"));
if (argc != 2) {
fprintf(stderr, "usage: %s exp\n", program);
abort "must give one exponent arg";
}
exp = eval(argv(1));
if (!isint(exp) || exp < 0) {
fprintf(stderr, "%s: exp must be non-negative integer\n", program);
abort "must give one exponent arg";
}
/* print the mersenne number */
print "2^": argv(0) : "-1 =", 2^eval(argv(0))-1;
print "2^": exp : "-1 =", 2^exp-1;
.fi
.in -5n
.sp 1
@@ -809,9 +868,9 @@ will print:
.sp 1
Note that because
.B \-s
is assumed in
is required in
.B "shell script mode"
and non-dashed args are made available as
non-dashed args are made available as
strings via the
.BR argv ()
builtin function.
@@ -819,26 +878,27 @@ Therefore:
.sp 1
.in +5n
.nf
2^eval(argv(0))-1
2^eval(argv(1))-1
.fi
.in -5n
.sp 1
will print the decimal value of 2^n-1
but
whereas
.sp 1
.in +5n
.nf
2^argv(0)-1
2^argv(1)-1
.fi
.in -5n
.sp 1
will not.
.PP
\&
.br
DATA TYPES
.SH DATA TYPES
.PP
Fundamental builtin data types include integers, real numbers,
rational numbers, complex numbers and strings.
.PP
@@ -861,12 +921,13 @@ help obj
.br
show objfuncs
.in -1.0i
.PP
\&
.br
VARIABLES
.SH VARIABLES
.PP
Variables in \fIcalc\fP are typeless.
In other words, the fundamental type of a variable is determined by its content.
Before a variable is assigned a value it has the value of zero.
@@ -889,12 +950,13 @@ help list
.br
show globals
.in -1.0i
.PP
\&
.br
INPUT/OUTPUT
.SH INPUT/OUTPUT
.PP
A leading ``0x'' implies a hexadecimal value,
a leading ``0b'' implies a binary value,
and a ``0'' followed by a digit implies an octal value.
@@ -924,12 +986,13 @@ command:
.in 1.0i
help file
.in -1.0i
.PP
\&
.br
CALC LANGUAGE
.SH CALC LANGUAGE
.PP
The \fIcalc\fP language is a C-like language.
The language includes commands such as variable declarations,
expressions, tests, labels, loops, file operations, function calls.
@@ -956,10 +1019,13 @@ help operator
.br
help config
.in -1.0i
.PP
.SH FILES
\&
.br
.PP
.PD 0
.TP 5
${BINDIR}/calc
@@ -1001,9 +1067,13 @@ custom resource files
${CUSTOMHELPDIR}/*
custom help files
.sp 1
.PP
.SH ENVIRONMENT
\&
.br
.PP
.PD 0
.TP 5
CALCPATH
@@ -1042,16 +1112,40 @@ Default value: binding
This variable is not used if calc was compiled with GNU-readline support.
In that case, the standard readline mechanisms (see readline(3)) are used.
.sp
.TP 5
CALCHISTFILE
Location of the calc history file.
.sp
Default value: ~/.calc_history
.sp
This variable is not used if calc was compiled with GNU-readline support.
.sp
.TP 5
CALCHELP
Location of the calc help directory.
.sp
Default value: ${HELPDIR}
.sp
.TP 5
CALCCUSTOMHELP
Location of the calc custom help directory.
.sp
Default value: ${CUSTOMHELPDIR}
.sp
.PP
.SH CREDIT
\&
.br
.PP
The main chunk of
.B calc
was written by David I. Bell.
.sp
The
.B calc
primary mirror, calc mailing list and calc bug report
primary mirror, and calc bug report
processing is performed by Landon Curt Noll.
.sp
Landon Curt Noll maintains the master reference source, performs
@@ -1073,10 +1167,13 @@ public domain arbitrarily precision routines which was posted
to the net around 1984.
By now, there is almost no recognizable
code left from that original source.
.sp
.PP
.SH "COPYING / CALC GNU LESSER GENERAL PUBLIC LICENSE"
\&
.sp
.PP
Calc is open software, and is
covered under version 2.1 of the GNU Lesser General Public License.
You are
@@ -1130,107 +1227,130 @@ This man page is:
.sp
.in +0.5i
.nf
Copyright (C) 1999 Landon Curt Noll
Copyright (C) 1999-2021 Landon Curt Noll
.fi
.in -0.5i
.sp
and is covered under version 2.1 GNU Lesser General
Public License.
.PP
.SH "CALC QUESTIONS"
.PP
If you have a simple general question about calc, send Email to:
.sp
.SH "CALC MAILING LIST / CALC UPDATES / ENHANCEMENTS"
\&
.br
.in +0.5i
calc-quest-mail at asthe dot com
.sp
To contribute comments, suggestions, enhancements
and interesting
.B calc
resource files, and
shell scripts please join the calc-tester
low volume moderated calc mailing list.
NOTE: Remove spaces and replace 'at' with @, and 'dot' with .
.in -0.5i
.sp
To the calc-tester mailing list, visit the following URL:
.in +0.5i
NOTE: Yes, the Email address uses 'asthe',
while the web site uses 'isthe'.
.in -0.5i
.sp
.B PLEASE
put following the
.B SPECIAL PHRASE
somewhere in your Email Subject line:
.sp
.in +0.5i
.B calc question
.in -0.5i
.sp
You may add additional words to your subject line.
.sp
.B IMPORTANT:
If your Email doesn't contain the above phrase,
then we
.B WILL NOT SEE
your Email.
.sp
.B PLEASE BE SURE
you have that
.B SPECIAL PHRASE
somewhere in the subject line!
.sp
.B Suggestion:
.sp
.in +0.5i
From time to time, the Email address and Subject
.B SPECIAL PHRASE
may change so verify you have the current info by visiting:
.sp
.in +0.5i
.nf
https://www.listbox.com/subscribe/?list_id=239342
http://www.isthe.com/chongo/tech/comp/calc/calc-question.html
.fi
.in -0.5i
.sp
To help determine you are a human and not just a spam bot,
you will be required to provide the following additional information:
.sp
.in +0.5i
.nf
Your Name
Calc Version
For example, the current version is: ${VERSION}
Operating System
If you don't know your operating system, enter: unknown
The date 7 days ago
Consult a calendar :-)
.fi
.in -0.5i
.sp
If you need a human to help you with your mailing list subscription,
or if you have problems with the above procedure, please
send EMail to our special address:
Please limit your questions to general questions about calc.
We cannot go into great detail in our answers,
nor can we do your homework, nor can
we do much more than answer short general questions about calc.
.sp
.in +0.5i
.nf
calc-tester-maillist-help at asthe dot com
Please be patient as we cannot always respond to Email messages quickly.
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
.PP
NOTE: Yes, the EMail address uses 'asthe',
while the web site uses 'isthe'.
.fi
.in -0.5i
.sp
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
your subject must contain the words:
.sp
.in +0.5i
.nf
calc tester mailing list help
.fi
.in -0.5i
.sp
You may have additional words in your subject line.
.sp
.SH "BUG REPORTS / BUG FIXES"
\&
.br
.sp
.PP
Send bug reports and bug fixes to:
.sp
.in +0.5i
.nf
calc-bug-report at asthe dot com
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
NOTE: Yes, the EMail address uses 'asthe',
while the web site uses 'isthe'.
calc-bugrept at asthe dot com
.fi
.sp
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
.sp
NOTE: Yes, the Email address uses 'asthe',
while the web site uses 'isthe'.
.in -0.5i
.sp
Your subject must contain the words:
You
.B MUST
use following
.B SPECIAL PHRASE
in your Email Subject line:
.sp
.in +0.5i
.B calc bug report
.in -0.5i
.sp
You may add additional words to your subject line.
.sp
.B Suggestion:
.sp
.in +0.5i
From time to time, the Email address and Subject
.B SPECIAL PHRASE
may change so verify you have the current info by visiting:
.sp
.in +0.5i
.nf
calc bug report
http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html
.fi
.in -0.5i
.in -0.5i
.sp
You may have additional words in your subject line.
.in
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.
.B IMPORTANT:
If your Email doesn't contain the above phrase,
then we
.B WILL NOT SEE
your Email.
.sp
.B PLEASE BE SURE
you have that
.B SPECIAL PHRASE
somewhere in the subject line!
.sp
See the
.I BUGS
@@ -1246,9 +1366,143 @@ help bugs
.sp
for more information about bug reporting.
.sp
Please be patient as we cannot always respond to Email messages quickly.
.PP
.SH "CONTRIBUTING CODE TO CALC"
.PP
.I Calc
is open source.
Contributions of code are welcome.
.sp
We welcome and encourage you to send us:
.sp
.sp
.in +0.5i
.nf
* calc resource files (cal/*.cal)
* calc shell scripts (cscript/*.calc)
* builtin functions that you have modified or written, i.e.:
assocfunc.c comfunc.c func.c func.h
listfunc.c matfunc.c qfunc.c zfunc.c
* custom functions that you have modified or written (custom/*)
* help files modified or written (help/*)
* brief description of you added, fixed, improved in CHANGES
* regression test cases (cal/regress.cal)
* Makefile improvements (Makefile, */Makefile)
* other source code modifications (*.c, *.h)
* etc. (* */* :) )
.fi
.in -0.5i
.sp
If you add functionality to calc, please be sure to modify/patch/add
Makefiles, help files, cal/regress.cal test code as well.
Regression test cases are vital to maintaining calc's level
of correctness and helps us avoid code bug regression.
.sp
In order to consider integrating your code, we need:
.sp
.nf
.in +0.5i
* calc version you are working with (please try use the latest version)
* new help files or help file patches, if applicable (documentation)
* proposed text for the CHANGES file (brief description of what it does)
* regress.cal test patch as needed
* your source code and/or source code changes (:-))
.in -0.5i
.fi
.sp
The best way to send us new code, if your changes are small, is
via a patch (diff -c from the latest alpha code to your code).
If your change is large, you should send entire files (either
as a diff -c /dev/null your-file patch, or as a uuencoded and
gziped (or compressed) tar file).
.sp
Please try to generate a patch against the most recent
version of calc, and if you use GitHub, the top of the
master branch:
.sp
.nf
.in +0.5i
https://github.com/lcn2/calc
.in -0.5i
.fi
.sp
.sp
The best way contribute to calc bug is to generate calc
GitHub pull request:
.sp
.nf
.in +0.5i
https://github.com/lcn2/calc/pulls
.in -0.5i
.fi
.sp
Your code needs to be contributed under either the 2.1 of the
.B GNU Lesser General Public License (LGPL 2.1)
or be in the public domain.
.sp
If you do not want to use calc GitHub, then send Email to:
.sp
.in +0.5i
.nf
calc-contrib at asthe dot com
.fi
.sp
NOTE: Remove spaces and replace 'at' with @, 'dot' with .
.sp
NOTE: Yes, the Email address uses 'asthe',
while the web site uses 'isthe'.
.in -0.5i
.sp
You
.B MUST
use following
.B SPECIAL PHRASE
in your Email Subject line:
.sp
.in +0.5i
.B calc contribution
.in -0.5i
.sp
You may add additional words to your subject line.
.sp
.B Suggestion:
.sp
.in +0.5i
From time to time, the Email address and Subject
.B SPECIAL PHRASE
may change so verify you have the current info by visiting:
.sp
.in +0.5i
.nf
http://www.isthe.com/chongo/tech/comp/calc/calc-contrib.html
.fi
.in -0.5i
.in -0.5i
.sp
.B IMPORTANT:
If your Email doesn't contain the above phrase,
then we
.B WILL NOT SEE
your Email.
.sp
.B PLEASE BE SURE
you have that
.B SPECIAL PHRASE
somewhere in the subject line!
.sp
Please be patient as we cannot always respond to Email messages quickly.
.PP
.SH "CALC WEB SITE"
\&
.br
.PP
Landon Noll maintains the
.B calc
web site is located at:

View File

@@ -1,7 +1,7 @@
#
# calc.spec.in - template specfile for calc
#
# Copyright (C) 2003-2014 Petteri Kettunen and Landon Curt Noll
# Copyright (C) 2003-2014,2021 Petteri Kettunen and Landon Curt Noll
#
# Calc is open software; you can redistribute it and/or modify it under
# the terms of the version 2.1 of the GNU Lesser General Public License
@@ -32,7 +32,7 @@
Summary: Arbitrary precision calculator.
Name: calc
Version: <<<PROJECT_VERSION>>>
Release: 12
Release: 13
License: LGPL
Group: Applications/Engineering
Source: http://www.isthe.com/chongo/src/calc/%{name}-%{version}.tar.bz2
@@ -49,7 +49,7 @@ BuildRoot: %{_tmppath}/build-root
Calc is arbitrary precision C-like arithmetic system that is a
calculator, an algorithm prototype and mathematical research
tool. Calc comes with a rich set of builtin mathematical and
programmatic functions.
programming functions.
For the latest calc release, see the calc project home page:
@@ -76,48 +76,48 @@ For the latest calc release, see the project home page:
%build
echo '-=- calc.spec beginning make clobber -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ clobber
echo '-=- calc.spec ending make clobber -=-'
echo '-=- calc.spec beginning make calc-static-only -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ calc-static-only BLD_TYPE=calc-static-only
echo '-=- calc.spec ending make calc-static-only -=-'
echo '-=- calc.spec beginning make rpm-hide-static -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ rpm-hide-static
echo '-=- calc.spec ending make rpm-hide-static -=-'
echo '-=- calc.spec beginning make clobber (again) -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ clobber
echo '-=- calc.spec ending make clobber (again) -=-'
echo '-=- calc.spec beginning make calc-dynamic-only -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ calc-dynamic-only \
BLD_TYPE=calc-dynamic-only LD_SHARE=
echo '-=- calc.spec ending make calc-dynamic-only -=-'
echo '-=- calc.spec beginning make chk -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ chk
echo '-=- calc.spec ending make chk -=-'
echo '-=- calc.spec beginning make rpm-unhide-static -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ rpm-unhide-static
echo '-=- calc.spec ending make rpm-unhide-static -=-'
echo '-=- calc.spec beginning make rpm-clean-static -=-'
make -j1 BINDIR=%{_bindir} LIBDIR=%{_libdir} \
make -j1 BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ rpm-clean-static
echo '-=- calc.spec ending make rpm-clean-static -=-'
echo '-=- calc.spec beginning make rpm-chk-static -=-'
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ rpm-chk-static
echo '-=- calc.spec ending make rpm-chk-static -=-'
@@ -125,7 +125,7 @@ echo '-=- calc.spec ending make rpm-chk-static -=-'
%install
echo '-=- calc.spec beginning make install -=-'
mkdir -p %{_buildroot}
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} \
make -j1 T=%{_buildroot} BINDIR=%{_bindir} LIBDIR=%{_libdir} ARCH_CFLAGS= \
CALC_SHAREDIR=%{_datadir}/%{name} CALC_INCDIR=%{_includedir}/calc \
MANDIR=%{_mandir}/man1 EXT= V=@ install
echo '-=- calc.spec ending make install -=-'
@@ -165,6 +165,12 @@ echo '-=- calc.spec beginning make clean -=-'
%attr(644, root, root) %{_libdir}/libcustcalc.a
%changelog
* Sun Mar 24 2019 Landon Curt Noll http://www.isthe.com/chongo
- Release: 13
- Disable compiling with the default ARCH_CFLAGS= -march=native
by clearing the ARCH_CFLAGS value in order to maximize
the RPM binary portability.
* Mon Sep 01 2014 Landon Curt Noll http://www.isthe.com/chongo
- Release: 12
- Removed use of %{?_smp_mflags}. On Ubuntu 14.04, the -j2
@@ -172,7 +178,7 @@ echo '-=- calc.spec beginning make clean -=-'
use -j1 while building these RPMs to avoid this make bug.
This only impacts the speed of building the rpms.
- Stopped removing %{_buildroot} at the beginning of install
as this, acording to a number of sources, was asking for trouble.
as this, according to a number of sources, was asking for trouble.
- Clean removes tmp, BUILD, SPEC, and BUILDROOT dirs under topdir.
- Fixed the building of the calc-debuginfo rpm.
- Eliminated rpmbuild "bogus date" warnings due to inconsistent weekday,

View File

@@ -1,7 +1,7 @@
#
# calcerr - error codes and messages
#
# Copyright (C) 1999-2006 Ernest Bowen
# Copyright (C) 1999-2006,2021 Ernest Bowen
#
# Calc is open software; you can redistribute it and/or modify it under
# the terms of the version 2.1 of the GNU Lesser General Public License
@@ -259,7 +259,7 @@ E_COPY6 Non-integer or negative destination index for copy
E_COPY7 Destination index too large for copy
E_COPY8 Freed block source for copy
E_COPY9 Unsuitable source type for copy
E_COPY10 Freed block destinction for copy
E_COPY10 Freed block destination for copy
E_COPY11 Unsuitable destination type for copy
E_COPY12 Incompatible source and destination for copy
E_COPY13 No-copy-from source variable
@@ -451,6 +451,7 @@ E_FPATHOPEN1 Non-string arguments for fpathopen
E_FPATHOPEN2 Unrecognized mode for fpathopen
E_LOG1 Bad epsilon argument for log
E_LOG2 Non-numeric first argument for log
E_LOG3 Cannot calculate log for this value
E_FGETFILE1 Non-file argument for fgetfile
E_FGETFILE2 File argument for fgetfile not open for reading
E_FGETFILE3 Unable to set file position in fgetfile
@@ -471,3 +472,73 @@ E_ISSPACE Bad argument for isspace
E_ISXDIGIT Bad argument for isxdigit
E_STRTOUPPER Bad argument type for strtoupper
E_STRTOLOWER Bad argument type for strtolower
E_TAN3 Invalid value for calculating the sin numerator for tan
E_TAN4 Invalid value for calculating the cos denominator for tan
E_COT3 Invalid value for calculating the sin numerator for cot
E_COT4 Invalid value for calculating the cos denominator for cot
E_SEC3 Invalid value for calculating the cos reciprocal for sec
E_CSC3 Invalid value for calculating the sin reciprocal for csc
E_TANH3 Invalid value for calculating the sinh numerator for tanh
E_TANH4 Invalid value for calculating the cosh denominator for tanh
E_COTH3 Invalid value for calculating the sinh numerator for coth
E_COTH4 Invalid value for calculating the cosh denominator for coth
E_SECH3 Invalid value for calculating the cosh reciprocal for sech
E_CSCH3 Invalid value for calculating the sinh reciprocal for csch
E_ASIN3 Invalid value for calculating asin
E_ACOS3 Invalid value for calculating acos
E_ASINH3 Invalid value for calculating asinh
E_ACOSH3 Invalid value for calculating acosn
E_ATAN3 Invalid value for calculating atan
E_ACOT3 Invalid value for calculating acot
E_ASEC3 Invalid value for calculating asec
E_ACSC3 Invalid value for calculating acsc
E_ATANH3 Invalid value for calculating atan
E_ACOTH3 Invalid value for calculating acot
E_ASECH3 Invalid value for calculating asec
E_ACSCH3 Invalid value for calculating acsc
E_D2R1 Bad epsilon for converting degrees to radians
E_D2R2 Bad first argument converting degrees to radians
E_R2D1 Bad epsilon for converting radians to degrees
E_R2D2 Bad first argument converting radians to degrees
E_G2R1 Bad epsilon for converting gradians to radians
E_G2R2 Bad first argument converting gradians to radians
E_R2G1 Bad epsilon for converting radians to gradians
E_R2G2 Bad first argument converting radians to gradians
E_D2G1 Bad first argument converting degrees to gradians
E_G2D1 Bad first argument converting gradians to degrees
E_D2DMS1 Non-lvalue arguments 2, 3 or 4 for d2dms
E_D2DMS2 Non-real-number arg 1 for d2dms
E_D2DMS3 No-assign-to argument 2, 3 or 4 for d2dms
E_D2DMS4 Invalid rounding arg 5 for d2dms
E_D2DM1 Non-lvalue arguments 2 or 3 for d2dm
E_D2DM2 Non-real-number arg 1 for d2dm
E_D2DM3 No-assign-to argument 2 or 3 for d2dm
E_D2DM4 Invalid rounding arg 4 for d2dm
E_G2GMS1 Non-lvalue arguments 2, 3 or 4 for g2gms
E_G2GMS2 Non-real-number arg 1 for g2gms
E_G2GMS3 No-assign-to argument 2 or 3 for g2gms
E_G2GMS4 Invalid rounding arg 5 for g2gms
E_G2GM1 Non-lvalue arguments 2 or 3 for g2gm
E_G2GM2 Non-real-number arg 1 for g2gm
E_G2GM3 No-assign-to argument 2, 3 or 4 for g2gm
E_G2GM4 Invalid rounding arg 4 for g2gm
E_H2HMS1 Non-lvalue arguments 2, 3 or 4 for h2hms
E_H2HMS2 Non-real-number arg 1 for h2hms
E_H2HMS3 No-assign-to argument 2, 3 or 4 for h2hms
E_H2HMS4 Invalid rounding arg 5 for h2hms
E_H2HM1 Non-lvalue arguments 2 or 3 for h2hm
E_H2HM2 Non-real-number arg 1 for h2hm
E_H2HM3 No-assign-to argument 2 or 3 for h2hm
E_H2HM4 Invalid rounding arg 4 for h2hm
E_DMS2D1 Non-real-number arguments 1, 2 or 3 for dms2d
E_DMS2D2 Invalid rounding arg 4 for dms2d
E_DM2D1 Non-real-number arguments 1 or 2 for dm2d
E_DM2D2 Invalid rounding arg 4 for dm2d
E_GMS2G1 Non-real-number arguments 1, 2 or 3 for gms2g
E_GMS2G2 Invalid rounding arg 4 for gms2g
E_GM2G1 Non-real-number arguments 1 or 2 for gm2g
E_GM2G2 Invalid rounding arg 4 for gm2g
E_HMS2H1 Non-real-number arguments 1, 2 or 3 for hms2h
E_HMS2H2 Invalid rounding arg 4 for hms2h
E_HM2H1 Non-real-number arguments 1 or 2 for hm2h
E_HM2H2 Invalid rounding arg 4 for hm2h

View File

@@ -28,6 +28,8 @@ BEGIN {
printf("#include <stdio.h>\n");
printf("#include \"calcerr.h\"\n\n");
printf("#include \"have_const.h\"\n\n");
printf("#include \"banned.h\"\t");
printf("/* include after system header <> includes */\n\n");
printf("/*\n");
printf(" * names of calc error values\n");
printf(" */\n");

67
charbit.c Normal file
View File

@@ -0,0 +1,67 @@
/*
* charbit - determine what CHAR_BIT is and define CALC_CHARBIT
*
* 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/07 20:57:50
* 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/
*/
/*
* usage:
* charbit
*
* This prog outputs several defines:
*
* CALC_CHARBIT
* after including have_limits.h and perhaps <limits.h>,
* output CALC_CHARBIT as CHAR_BIT (from <limits.h>, or as 8.
*/
#include <stdio.h>
#include "have_limits.h"
#if defined(HAVE_LIMITS_H)
#include <limits.h>
#endif
#include "banned.h" /* include after system header <> includes */
int
main(void)
{
printf("#include \"have_limits.h\"\n");
printf("#if defined(HAVE_LIMITS_H)\n");
printf("#include <limits.h>\n");
printf("#endif\n\n");
#if defined(CHAR_BIT)
printf("#define CALC_CHARBIT (CHAR_BIT) /* from <limits.h> */\n");
#else /* CHAR_BIT */
printf("#define CALC_CHARBIT (8) /* no CHAR_BIT, assume 8 */\n");
#endif /* CHAR_BIT */
/* exit(0); */
return 0;
}

View File

@@ -1,7 +1,7 @@
/*
* codegen - module to generate opcodes from the input tokens
*
* Copyright (C) 1999-2007,2017 David I. Bell and Ernest Bowen
* Copyright (C) 1999-2007,2017,2021,2022 David I. Bell and Ernest Bowen
*
* Primary author: David I. Bell
*
@@ -34,6 +34,7 @@
#include "lib_calc.h"
#include "calc.h"
#include "alloc.h"
#include "token.h"
#include "symbol.h"
#include "label.h"
@@ -41,10 +42,18 @@
#include "str.h"
#include "func.h"
#include "conf.h"
#include "strl.h"
#if defined(_WIN32) && !defined(__CYGWIN__)
#if defined(_WIN32) || defined(_WIN64)
#if !defined(__CYGWIN__)
# include <direct.h>
#endif
#endif
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
STATIC BOOL rdonce; /* TRUE => do not reread this file */
@@ -144,11 +153,9 @@ getcommands(BOOL toplevel)
case 1:
case -1:
if(i == 1) {
strncpy(name,
strlcpy(name,
DEFAULTCALCHELP,
MAXCMD);
/* paranoia */
name[MAXCMD] = '\0';
MAXCMD+1);
givehelp(name);
}
break;
@@ -447,7 +454,7 @@ getsimplebody(void)
/*
* Get the body of a function, or a subbody of a function.
* Get the body of a function, or a sub-body of a function.
* body = '{' [ declarations ] ... [ statement ] ... '}'
* | [ declarations ] ... [statement ] ... '\n'
*/
@@ -1021,7 +1028,7 @@ getstatement(LABEL *contlabel, LABEL *breaklabel,
return;
}
reread();
/* fall into default case */
/*FALLTHRU*/
default:
rescantoken();
@@ -1384,6 +1391,7 @@ creatematrix(void)
switch (gettoken()) {
case T_RIGHTBRACKET:
rescantoken();
/*FALLTHRU*/
case T_COMMA:
addop(OP_ONE);
addop(OP_SUB);
@@ -1394,6 +1402,7 @@ creatematrix(void)
switch(gettoken()) {
case T_RIGHTBRACKET:
rescantoken();
/*FALLTHRU*/
case T_COMMA:
continue;
}
@@ -1510,7 +1519,7 @@ getexprlist(void)
/*
* Get an opassignment or possibly just an assignment or expression.
* Get an op-assignment or possibly just an assignment or expression.
* Returns flags describing the type of assignment or expression found.
* assignment = lvalue '=' assignment
* | lvalue '+=' assignment
@@ -2211,6 +2220,7 @@ getterm(void)
scanerror(T_NULL,
"Function calls not allowed "
"as expressions");
/*FALLTHRU*/
default:
rescantoken();
return type;
@@ -2248,7 +2258,7 @@ getidexpr(BOOL okmat, int autodef)
if (autodef != T_GLOBAL && autodef != T_LOCAL &&
autodef != T_STATIC)
autodef = 1;
/* fall into default case */
/*FALLTHRU*/
default:
rescantoken();
usesymbol(name, autodef);
@@ -2277,6 +2287,7 @@ getidexpr(BOOL okmat, int autodef)
scanerror(T_NULL,
"Function calls not allowed "
"as expressions");
/*FALLTHRU*/
default:
rescantoken();
return type;
@@ -2350,8 +2361,7 @@ getfilename(char *name, size_t namelen, BOOL *once)
/* use the value of the literal string */
s = findstring(tokenstring());
strncpy(name, s->s_str, namelen-1);
name[namelen-1] = '\0';
strlcpy(name, s->s_str, namelen);
sfree(s);
break;
@@ -2374,22 +2384,21 @@ getfilename(char *name, size_t namelen, BOOL *once)
if (symstr == NULL) {
math_error(
"string value pointer is NULL!!");
/*NOTREACHED*/
not_reached();
}
} else {
math_error(
"a filename variable must be a string");
/*NOTREACHED*/
not_reached();
}
} else {
math_error("no such global variable");
/*NOTREACHED*/
not_reached();
}
}
/* return symbol name or value of global var string */
strncpy(name, symstr, namelen-1);
name[namelen-1] = '\0';
strlcpy(name, symstr, namelen);
break;
case T_NEWLINE:
@@ -2427,7 +2436,7 @@ getshowstatement(void)
switch (gettoken()) {
case T_SYMBOL:
strncpy(name, tokensymbol(), 4);
strlcpy(name, tokensymbol(), sizeof(name));
name[4] = '\0';
/* Yuck! */
arg = stringindex("buil\000"
@@ -2591,8 +2600,7 @@ getid(char *buf)
*buf = '\0';
return FALSE;
}
strncpy(buf, tokensymbol(), SYMBOLSIZE);
buf[SYMBOLSIZE] = '\0';
strlcpy(buf, tokensymbol(), SYMBOLSIZE+1);
return TRUE;
}
@@ -2603,7 +2611,7 @@ getid(char *buf)
* global or if symtype is static and the old variable is at the same
* level. Warnings are issued when a global or local variable is
* redeclared and when in the same body the variable will be accessible only
^ with the appropriate specfier.
^ with the appropriate specifier.
*/
S_FUNC void
definesymbol(char *name, int symtype)

View File

@@ -1,7 +1,7 @@
/*
* comfunc - extended precision complex arithmetic non-primitive routines
*
* 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
*
@@ -29,6 +29,11 @@
#include "config.h"
#include "cmath.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
/*
* cache the natural logarithm of 10
*/
@@ -56,16 +61,16 @@ c_powi(COMPLEX *c, NUMBER *q)
if (qisfrac(q)) {
math_error("Raising number to non-integral power");
/*NOTREACHED*/
not_reached();
}
if (zge31b(q->num)) {
math_error("Raising number to very large power");
/*NOTREACHED*/
not_reached();
}
power = ztolong(q->num);
if (ciszero(c) && (power == 0)) {
math_error("Raising zero to zeroth power");
/*NOTREACHED*/
not_reached();
}
sign = 1;
if (qisneg(q))
@@ -377,7 +382,7 @@ c_root(COMPLEX *c, NUMBER *q, NUMBER *epsilon)
if (qisneg(q) || qiszero(q) || qisfrac(q)) {
math_error("Taking bad root of complex number");
/*NOTREACHED*/
not_reached();
}
if (cisone(c) || qisone(q))
return clink(c);
@@ -442,7 +447,7 @@ c_exp(COMPLEX *c, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon for cexp");
/*NOTREACHED*/
not_reached();
}
if (cisreal(c)) {
tmp1 = qexp(c->real, epsilon);
@@ -498,7 +503,7 @@ c_ln(COMPLEX *c, NUMBER *epsilon)
if (ciszero(c)) {
math_error("logarithm of zero");
/*NOTREACHED*/
not_reached();
}
if (cisone(c))
return clink(&_czero_);
@@ -553,7 +558,7 @@ c_log(COMPLEX *c, NUMBER *epsilon)
/* first time call */
cln_10_epsilon = qcopy(epsilon);
} else if (qcmp(cln_10_epsilon, epsilon) == TRUE) {
/* replaced cacheed value with epsilon arg */
/* replaced cached value with epsilon arg */
qfree(cln_10_epsilon);
cln_10_epsilon = qcopy(epsilon);
} else if (cln_10 != NULL) {
@@ -595,7 +600,7 @@ c_cos(COMPLEX *c, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon for ccos");
/*NOTREACHED*/
not_reached();
}
n = qilog2(epsilon);
ctmp1 = comalloc();
@@ -645,7 +650,7 @@ c_sin(COMPLEX *c, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon for csin");
/*NOTREACHED*/
not_reached();
}
if (ciszero(c))
return clink(&_czero_);
@@ -1068,7 +1073,7 @@ c_polar(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon for cpolar");
/*NOTREACHED*/
not_reached();
}
if (qiszero(q1))
return clink(&_czero_);
@@ -1110,12 +1115,12 @@ c_power(COMPLEX *c1, COMPLEX *c2, NUMBER *epsilon)
if (qiszero(epsilon)) {
math_error("Zero epsilon for cpower");
/*NOTREACHED*/
not_reached();
}
if (ciszero(c1)) {
if (cisreal(c2) && qisneg(c2->real)) {
math_error ("Non-positive real exponent of zero");
/*NOTREACHED*/
not_reached();
}
return clink(&_czero_);
}
@@ -1182,7 +1187,7 @@ comprint(COMPLEX *c)
return;
}
if (!qiszero(c->real) || qiszero(c->imag))
qprintnum(c->real, MODE_DEFAULT);
qprintnum(c->real, MODE_DEFAULT, conf->outdigits);
qtmp = c->imag[0];
if (qiszero(&qtmp))
return;
@@ -1192,7 +1197,7 @@ comprint(COMPLEX *c)
math_chr('-');
qtmp.num.sign = 0;
}
qprintnum(&qtmp, MODE_DEFAULT);
qprintnum(&qtmp, MODE_DEFAULT, conf->outdigits);
math_chr('i');
}

View File

@@ -1,7 +1,7 @@
/*
* commath - extended precision complex arithmetic primitive 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -27,6 +27,10 @@
#include "cmath.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
COMPLEX _czero_ = { &_qzero_, &_qzero_, 1 };
COMPLEX _cone_ = { &_qone_, &_qzero_, 1 };
COMPLEX _conei_ = { &_qzero_, &_qone_, 1 };
@@ -186,7 +190,7 @@ c_div(COMPLEX *c1, COMPLEX *c2)
if (ciszero(c2)) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
if ((c1->real == c2->real) && (c1->imag == c2->imag))
return clink(&_cone_);
@@ -257,7 +261,7 @@ c_inv(COMPLEX *c)
if (ciszero(c)) {
math_error("Inverting zero");
/*NOTREACHED*/
not_reached();
}
r = comalloc();
if (cisreal(c)) {
@@ -519,7 +523,7 @@ c_divq(COMPLEX *c, NUMBER *q)
if (qiszero(q)) {
math_error("Division by zero");
/*NOTREACHED*/
not_reached();
}
if (qisone(q))
return clink(c);
@@ -602,7 +606,7 @@ comalloc(void)
r = (COMPLEX *) malloc(sizeof(COMPLEX));
if (r == NULL) {
math_error("Cannot allocate complex number");
/*NOTREACHED*/
not_reached();
}
r->links = 1;
r->real = qlink(&_qzero_);

199
config.c
View File

@@ -1,7 +1,7 @@
/*
* config - configuration routines
*
* Copyright (C) 1999-2007 David I. Bell and Landon Curt Noll
* Copyright (C) 1999-2007,2021,2022 David I. Bell and Landon Curt Noll
*
* Primary author: David I. Bell
*
@@ -46,6 +46,7 @@
#endif
#include "calc.h"
#include "alloc.h"
#include "token.h"
#include "zrand.h"
#include "block.h"
@@ -53,12 +54,18 @@
#include "config.h"
#include "str.h"
#include "custom.h"
#include "strl.h"
#include "have_strdup.h"
#if !defined(HAVE_STRDUP)
# define strdup(x) calc_strdup((CONST char *)(x))
#endif /* HAVE_STRDUP */
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
/*
* deal with systems that lack a defined CLK_TCK
*/
@@ -143,8 +150,8 @@ CONFIG oldstd = { /* backward compatible standard configuration */
SQ_ALG2, /* size of number to use square alg 2 */
POW_ALG2, /* size of modulus to use REDC for powers */
REDC_ALG2, /* size of modulus to use REDC algorithm 2 */
TRUE, /* ok to print a tilde on approximations */
TRUE, /* ok to print tab before numeric values */
TRUE, /* OK to print a tilde on approximations */
TRUE, /* OK to print tab before numeric values */
0, /* quomod() default rounding mode */
2, /* quotient // default rounding mode */
0, /* mod % default rounding mode */
@@ -154,8 +161,8 @@ CONFIG oldstd = { /* backward compatible standard configuration */
8, /* cfsim() default rounding mode */
2, /* output default rounding mode */
24, /* round()/bround() default rounding mode */
FALSE, /* ok to print leading 0 before decimal pt */
0, /* ok to print trailing 0's */
FALSE, /* OK to print leading 0 before decimal pt */
0, /* OK to print trailing 0's */
MAXSCANCOUNT, /* max scan errors before abort */
PROMPT1, /* normal prompt */
PROMPT2, /* prompt when inside multi-line input */
@@ -170,10 +177,10 @@ CONFIG oldstd = { /* backward compatible standard configuration */
CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */
NULL, /* our name */
NULL, /* basename of our name */
#if defined(_WIN32)
#if defined(_WIN32) || defined(_WIN64)
TRUE, /* running under windows */
#else
FALSE, /* congrats, you are not using windows */
FALSE, /* not using windows */
#endif
#if defined(__CYGWIN__)
TRUE, /* compiled under cygwin */
@@ -203,8 +210,8 @@ CONFIG newstd = { /* new non-backward compatible configuration */
SQ_ALG2, /* size of number to use square alg 2 */
POW_ALG2, /* size of modulus to use REDC for powers */
REDC_ALG2, /* size of modulus to use REDC algorithm 2 */
TRUE, /* ok to print a tilde on approximations */
TRUE, /* ok to print tab before numeric values */
TRUE, /* OK to print a tilde on approximations */
TRUE, /* OK to print tab before numeric values */
0, /* quomod() default rounding mode */
2, /* quotient // default rounding mode */
0, /* mod % default rounding mode */
@@ -214,8 +221,8 @@ CONFIG newstd = { /* new non-backward compatible configuration */
8, /* cfsim() default rounding mode */
24, /* output default rounding mode */
24, /* round()/bround() default rounding mode */
TRUE, /* ok to print leading 0 before decimal pt */
0, /* ok to print trailing 0's */
TRUE, /* OK to print leading 0 before decimal pt */
0, /* OK to print trailing 0's */
MAXSCANCOUNT, /* max scan errors before abort */
"; ", /* normal prompt */
";; ", /* prompt when inside multi-line input */
@@ -230,10 +237,10 @@ CONFIG newstd = { /* new non-backward compatible configuration */
CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */
NULL, /* our name */
NULL, /* basename of our name */
#if defined(_WIN32)
#if defined(_WIN32) || defined(_WIN64)
TRUE, /* running under windows */
#else
FALSE, /* congrats, you are not using windows */
FALSE, /* not using windows */
#endif
#if defined(__CYGWIN__)
TRUE, /* compiled under cygwin */
@@ -268,12 +275,15 @@ STATIC NAMETYPE modes[] = {
{"scientific", MODE_EXP},
{"sci", MODE_EXP},
{"exp", MODE_EXP},
{"engineering", MODE_ENG},
{"eng", MODE_ENG},
{"hexadecimal", MODE_HEX},
{"hex", MODE_HEX},
{"octal", MODE_OCTAL},
{"oct", MODE_OCTAL},
{"binary", MODE_BINARY},
{"bin", MODE_BINARY},
{"float-auto", MODE_REAL_AUTO},
{"off", MODE2_OFF},
{NULL, 0}
};
@@ -479,11 +489,11 @@ setconfig(int type, VALUE *vp)
newconf = &newstd;
} else {
math_error("CONFIG alias not oldstd or newstd");
/*NOTREACHED*/
not_reached();
}
} else if (vp->v_type != V_CONFIG) {
math_error("non-CONFIG for all");
/*NOTREACHED*/
not_reached();
} else {
newconf = vp->v_config;
}
@@ -498,14 +508,14 @@ setconfig(int type, VALUE *vp)
case CONFIG_TRACE:
if (vp->v_type != V_NUM) {
math_error("Non-numeric for trace");
/*NOTREACHED*/
not_reached();
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || !zistiny(q->num) ||
((unsigned long) temp > TRACE_MAX)) {
math_error("Bad trace value");
/*NOTREACHED*/
not_reached();
}
conf->traceflags = (FLAG)temp;
break;
@@ -513,7 +523,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_DISPLAY:
if (getlen(vp, &len)) {
math_error("Bad value for display");
/*NOTREACHED*/
not_reached();
}
math_setdigits(len);
break;
@@ -521,12 +531,12 @@ setconfig(int type, VALUE *vp)
case CONFIG_MODE:
if (vp->v_type != V_STR) {
math_error("Non-string for mode");
/*NOTREACHED*/
not_reached();
}
temp = lookup_long(modes, vp->v_str->s_str);
if (temp < 0) {
math_error("Unknown mode \"%s\"", vp->v_str->s_str);
/*NOTREACHED*/
not_reached();
}
math_setmode((int) temp);
break;
@@ -534,12 +544,12 @@ setconfig(int type, VALUE *vp)
case CONFIG_MODE2:
if (vp->v_type != V_STR) {
math_error("Non-string for mode");
/*NOTREACHED*/
not_reached();
}
temp = lookup_long(modes, vp->v_str->s_str);
if (temp < 0) {
math_error("Unknown mode \"%s\"", vp->v_str->s_str);
/*NOTREACHED*/
not_reached();
}
math_setmode2((int) temp);
break;
@@ -547,7 +557,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_EPSILON:
if (vp->v_type != V_NUM) {
math_error("Non-numeric for epsilon");
/*NOTREACHED*/
not_reached();
}
setepsilon(vp->v_num);
break;
@@ -555,7 +565,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_MAXPRINT:
if (getlen(vp, &len)) {
math_error("Bad value for maxprint");
/*NOTREACHED*/
not_reached();
}
conf->maxprint = len;
break;
@@ -563,7 +573,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_MUL2:
if (getlen(vp, &len) || len < 0 || len == 1) {
math_error("Bad value for mul2");
/*NOTREACHED*/
not_reached();
}
if (len == 0)
len = MUL_ALG2;
@@ -573,7 +583,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_SQ2:
if (getlen(vp, &len) || len < 0 || len == 1) {
math_error("Bad value for sq2");
/*NOTREACHED*/
not_reached();
}
if (len == 0)
len = SQ_ALG2;
@@ -583,7 +593,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_POW2:
if (getlen(vp, &len) || len < 0 || len == 1) {
math_error("Bad value for pow2");
/*NOTREACHED*/
not_reached();
}
if (len == 0)
len = POW_ALG2;
@@ -593,7 +603,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_REDC2:
if (getlen(vp, &len) || len < 0 || len == 1) {
math_error("Bad value for redc2");
/*NOTREACHED*/
not_reached();
}
if (len == 0)
len = REDC_ALG2;
@@ -608,7 +618,7 @@ setconfig(int type, VALUE *vp)
temp = lookup_long(truth, vp->v_str->s_str);
if (temp < 0) {
math_error("Illegal truth value for tilde");
/*NOTREACHED*/
not_reached();
}
conf->tilde_ok = (int)temp;
}
@@ -622,7 +632,7 @@ setconfig(int type, VALUE *vp)
temp = lookup_long(truth, vp->v_str->s_str);
if (temp < 0) {
math_error("Illegal truth value for tab");
/*NOTREACHED*/
not_reached();
}
conf->tab_ok = (int)temp;
}
@@ -631,7 +641,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_QUOMOD:
if (getlen(vp, &len)) {
math_error("Illegal value for quomod");
/*NOTREACHED*/
not_reached();
}
conf->quomod = len;
break;
@@ -639,7 +649,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_QUO:
if (getlen(vp, &len)) {
math_error("Illegal value for quo");
/*NOTREACHED*/
not_reached();
}
conf->quo = len;
break;
@@ -647,7 +657,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_MOD:
if (getlen(vp, &len)) {
math_error("Illegal value for mod");
/*NOTREACHED*/
not_reached();
}
conf->mod = len;
break;
@@ -655,7 +665,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_SQRT:
if (getlen(vp, &len)) {
math_error("Illegal value for sqrt");
/*NOTREACHED*/
not_reached();
}
conf->sqrt = len;
break;
@@ -663,7 +673,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_APPR:
if (getlen(vp, &len)) {
math_error("Illegal value for appr");
/*NOTREACHED*/
not_reached();
}
conf->appr = len;
break;
@@ -671,7 +681,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_CFAPPR:
if (getlen(vp, &len)) {
math_error("Illegal value for cfappr");
/*NOTREACHED*/
not_reached();
}
conf->cfappr = len;
break;
@@ -679,7 +689,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_CFSIM:
if (getlen(vp, &len)) {
math_error("Illegal value for cfsim");
/*NOTREACHED*/
not_reached();
}
conf->cfsim = len;
break;
@@ -687,7 +697,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_OUTROUND:
if (getlen(vp, &len)) {
math_error("Illegal value for outround");
/*NOTREACHED*/
not_reached();
}
conf->outround = len;
break;
@@ -695,7 +705,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_ROUND:
if (getlen(vp, &len)) {
math_error("Illegal value for round");
/*NOTREACHED*/
not_reached();
}
conf->round = len;
break;
@@ -706,10 +716,9 @@ setconfig(int type, VALUE *vp)
conf->leadzero = !qiszero(q);
} else if (vp->v_type == V_STR) {
temp = lookup_long(truth, vp->v_str->s_str);
if (temp < 0) { {
if (temp < 0) {
math_error("Illegal truth value for leadzero");
/*NOTREACHED*/
}
not_reached();
}
conf->leadzero = (int)temp;
}
@@ -723,7 +732,7 @@ setconfig(int type, VALUE *vp)
temp = lookup_long(truth, vp->v_str->s_str);
if (temp < 0) { {
math_error("Illegal truth value for fullzero");
/*NOTREACHED*/
not_reached();
}
}
conf->fullzero = (int)temp;
@@ -733,7 +742,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_MAXSCAN:
if (vp->v_type != V_NUM) {
math_error("Non-numeric for maxscancount");
/*NOTREACHED*/
not_reached();
}
q = vp->v_num;
temp = qtoi(q);
@@ -741,7 +750,7 @@ setconfig(int type, VALUE *vp)
temp = -1;
if (temp < 0) {
math_error("Maxscan value is out of range");
/*NOTREACHED*/
not_reached();
}
conf->maxscancount = temp;
break;
@@ -749,14 +758,14 @@ setconfig(int type, VALUE *vp)
case CONFIG_PROMPT:
if (vp->v_type != V_STR) {
math_error("Non-string for prompt");
/*NOTREACHED*/
not_reached();
}
p = (char *)malloc(vp->v_str->s_len + 1);
if (p == NULL) {
math_error("Cannot duplicate new prompt");
/*NOTREACHED*/
not_reached();
}
strncpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
free(conf->prompt1);
conf->prompt1 = p;
break;
@@ -764,14 +773,14 @@ setconfig(int type, VALUE *vp)
case CONFIG_MORE:
if (vp->v_type != V_STR) {
math_error("Non-string for more prompt");
/*NOTREACHED*/
not_reached();
}
p = (char *)malloc(vp->v_str->s_len + 1);
if (p == NULL) {
math_error("Cannot duplicate new more prompt");
/*NOTREACHED*/
not_reached();
}
strncpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1);
free(conf->prompt2);
conf->prompt2 = p;
break;
@@ -779,7 +788,7 @@ setconfig(int type, VALUE *vp)
case CONFIG_BLKMAXPRINT:
if (vp->v_type != V_NUM) {
math_error("Non-numeric for blkmaxprint");
/*NOTREACHED*/
not_reached();
}
q = vp->v_num;
temp = qtoi(q);
@@ -787,7 +796,7 @@ setconfig(int type, VALUE *vp)
temp = -1;
if (temp < 0) {
math_error("Blkmaxprint value is out of range");
/*NOTREACHED*/
not_reached();
}
conf->blkmaxprint = temp;
break;
@@ -800,7 +809,7 @@ setconfig(int type, VALUE *vp)
temp = lookup_long(truth, vp->v_str->s_str);
if (temp < 0) {
math_error("Illegal truth value for blkverbose");
/*NOTREACHED*/
not_reached();
}
conf->blkverbose = (int)temp;
}
@@ -809,13 +818,13 @@ setconfig(int type, VALUE *vp)
case CONFIG_BLKBASE:
if (vp->v_type != V_STR) {
math_error("Non-string for blkbase");
/*NOTREACHED*/
not_reached();
}
temp = lookup_long(blk_base, vp->v_str->s_str);
if (temp < 0) {
math_error("Unknown mode \"%s\" for blkbase",
vp->v_str->s_str);
/*NOTREACHED*/
not_reached();
}
conf->blkbase = temp;
break;
@@ -823,13 +832,13 @@ setconfig(int type, VALUE *vp)
case CONFIG_BLKFMT:
if (vp->v_type != V_STR) {
math_error("Non-string for blkfmt");
/*NOTREACHED*/
not_reached();
}
temp = lookup_long(blk_fmt, vp->v_str->s_str);
if (temp < 0) {
math_error("Unknown mode \"%s\" for blkfmt",
vp->v_str->s_str);
/*NOTREACHED*/
not_reached();
}
conf->blkfmt = temp;
break;
@@ -837,13 +846,13 @@ setconfig(int type, VALUE *vp)
case CONFIG_CALC_DEBUG:
if (vp->v_type != V_NUM) {
math_error("Non numeric for calc_debug");
/*NOTREACHED*/
not_reached();
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || !zistiny(q->num)) {
math_error("Illegal calc_debug parameter value");
/*NOTREACHED*/
not_reached();
}
conf->calc_debug = temp;
break;
@@ -851,13 +860,13 @@ setconfig(int type, VALUE *vp)
case CONFIG_RESOURCE_DEBUG:
if (vp->v_type != V_NUM) {
math_error("Non numeric for resource_debug");
/*NOTREACHED*/
not_reached();
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || !zistiny(q->num)) {
math_error("Illegal resource_debug parameter value");
/*NOTREACHED*/
not_reached();
}
conf->resource_debug = temp;
break;
@@ -865,13 +874,13 @@ setconfig(int type, VALUE *vp)
case CONFIG_USER_DEBUG:
if (vp->v_type != V_NUM) {
math_error("Non numeric for user_debug");
/*NOTREACHED*/
not_reached();
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || !zistiny(q->num)) {
math_error("Illegal user_debug parameter value");
/*NOTREACHED*/
not_reached();
}
conf->user_debug = temp;
break;
@@ -885,7 +894,7 @@ setconfig(int type, VALUE *vp)
if (temp < 0) {
math_error("Illegal truth value "
"for verbose_quit");
/*NOTREACHED*/
not_reached();
}
conf->verbose_quit = (int)temp;
}
@@ -894,48 +903,56 @@ setconfig(int type, VALUE *vp)
case CONFIG_CTRL_D:
if (vp->v_type != V_STR) {
math_error("Non-string for ctrl_d");
/*NOTREACHED*/
not_reached();
}
temp = lookup_long(ctrl_d, vp->v_str->s_str);
if (temp < 0) {
math_error("Unknown mode \"%s\" for ctrl_d",
vp->v_str->s_str);
/*NOTREACHED*/
not_reached();
}
conf->ctrl_d = temp;
break;
case CONFIG_PROGRAM:
math_error("The program config parameter is read-only");
/*NOTREACHED*/
not_reached();
break;
case CONFIG_BASENAME:
math_error("The basename config parameter is read-only");
/*NOTREACHED*/
not_reached();
break;
case CONFIG_WINDOWS:
math_error("The windows config parameter is read-only");
/*NOTREACHED*/
not_reached();
break;
case CONFIG_CYGWIN:
math_error("The cygwin config parameter is read-only");
/*NOTREACHED*/
not_reached();
break;
case CONFIG_COMPILE_CUSTOM:
math_error("The custom config parameter is read-only");
/*NOTREACHED*/
not_reached();
break;
case CONFIG_ALLOW_CUSTOM:
math_error("The allow_custom config parameter is read-only");
/*NOTREACHED*/
not_reached();
break;
case CONFIG_VERSION:
math_error("The version config parameter is read-only");
/*NOTREACHED*/
not_reached();
break;
case CONFIG_BASEB:
math_error("The baseb config parameter is read-only");
/*NOTREACHED*/
not_reached();
break;
case CONFIG_REDECL_WARN:
if (vp->v_type == V_NUM) {
@@ -946,7 +963,7 @@ setconfig(int type, VALUE *vp)
if (temp < 0) {
math_error("Illegal truth value for "
"redecl_warn");
/*NOTREACHED*/
not_reached();
}
conf->redecl_warn = (int)temp;
}
@@ -961,7 +978,7 @@ setconfig(int type, VALUE *vp)
if (temp < 0) {
math_error("Illegal truth value for "
"dupvar_warn");
/*NOTREACHED*/
not_reached();
}
conf->dupvar_warn = (int)temp;
}
@@ -969,11 +986,13 @@ setconfig(int type, VALUE *vp)
case CONFIG_HZ:
math_error("The clock tick rate config parameter is read-only");
/*NOTREACHED*/
not_reached();
break;
default:
math_error("Setting illegal config parameter");
/*NOTREACHED*/
not_reached();
break;
}
}
@@ -998,7 +1017,7 @@ config_copy(CONFIG *src)
if (src == NULL || src->epsilon == NULL || src->prompt1 == NULL ||
src->prompt2 == NULL) {
math_error("bad CONFIG value");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1007,7 +1026,7 @@ config_copy(CONFIG *src)
dest = (CONFIG *)malloc(sizeof(CONFIG));
if (dest == NULL) {
math_error("malloc of CONFIG failed");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1115,7 +1134,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
if (cfg == NULL || cfg->epsilon == NULL || cfg->prompt1 == NULL ||
cfg->prompt2 == NULL) {
math_error("bad CONFIG value");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1142,7 +1161,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
p = lookup_name(modes, cfg->outmode);
if (p == NULL) {
math_error("invalid output mode: %d", cfg->outmode);
/*NOTREACHED*/
not_reached();
}
vp->v_str = makenewstring(p);
return;
@@ -1153,7 +1172,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
if (p == NULL) {
math_error("invalid secondary output mode: %d",
cfg->outmode2);
/*NOTREACHED*/
not_reached();
}
vp->v_str = makenewstring(p);
return;
@@ -1261,7 +1280,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
p = lookup_name(blk_base, cfg->blkbase);
if (p == NULL) {
math_error("invalid block base: %d", cfg->blkbase);
/*NOTREACHED*/
not_reached();
}
vp->v_str = makenewstring(p);
return;
@@ -1271,7 +1290,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
p = lookup_name(blk_fmt, cfg->blkfmt);
if (p == NULL) {
math_error("invalid block format: %d", cfg->blkfmt);
/*NOTREACHED*/
not_reached();
}
vp->v_str = makenewstring(p);
return;
@@ -1297,7 +1316,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
p = lookup_name(ctrl_d, cfg->ctrl_d);
if (p == NULL) {
math_error("invalid Control-D: %d", cfg->ctrl_d);
/*NOTREACHED*/
not_reached();
}
vp->v_str = makenewstring(p);
return;
@@ -1367,7 +1386,7 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
default:
math_error("Getting illegal CONFIG element");
/*NOTREACHED*/
not_reached();
}
/*
@@ -1397,12 +1416,12 @@ config_cmp(CONFIG *cfg1, CONFIG *cfg2)
if (cfg1 == NULL || cfg1->epsilon == NULL || cfg1->prompt1 == NULL ||
cfg1->prompt2 == NULL) {
math_error("CONFIG #1 value is invalid");
/*NOTREACHED*/
not_reached();
}
if (cfg2 == NULL || cfg2->epsilon == NULL || cfg2->prompt1 == NULL ||
cfg2->prompt2 == NULL) {
math_error("CONFIG #2 value is invalid");
/*NOTREACHED*/
not_reached();
}
/*

View File

@@ -1,7 +1,7 @@
/*
* config - configuration routines
*
* Copyright (C) 1999-2007,2014 Landon Curt Noll and David I. Bell
* Copyright (C) 1999-2007,2014,2021 Landon Curt Noll and David I. Bell
*
* Primary author: Landon Curt Noll
*
@@ -130,8 +130,8 @@ struct config {
LEN sq2; /* size of number to use square algorithm 2 */
LEN pow2; /* size of modulus to use REDC for powers */
LEN redc2; /* size of modulus to use REDC algorithm 2 */
BOOL tilde_ok; /* ok to print a tilde on aproximations */
BOOL tab_ok; /* ok to print tab before numeric values */
BOOL tilde_ok; /* OK to print a tilde on approximations */
BOOL tab_ok; /* OK to print tab before numeric values */
LEN quomod; /* quomod() default rounding mode */
LEN quo; /* quotient // default rounding mode */
LEN mod; /* mod % default rounding mode */
@@ -141,8 +141,8 @@ struct config {
LEN cfsim; /* cfsim() default rounding mode */
LEN outround; /* output default rounding mode */
LEN round; /* round()/bround() default rounding mode */
BOOL leadzero; /* ok to print leading 0 before decimal pt */
BOOL fullzero; /* ok to print trailing 0's */
BOOL leadzero; /* OK to print leading 0 before decimal pt */
BOOL fullzero; /* OK to print trailing 0's */
long maxscancount; /* max scan errors before abort */
char *prompt1; /* normal prompt */
char *prompt2; /* prompt when inside multi-line input */
@@ -163,7 +163,7 @@ struct config {
BOOL *allow_custom; /* ptr to if custom functions are allowed */
char *version; /* calc version string */
int baseb; /* base for calculations */
BOOL redecl_warn; /* TRUE => warn of redeclating variables */
BOOL redecl_warn; /* TRUE => warn of redeclaring variables */
BOOL dupvar_warn; /* TRUE => warn of var name collisions */
};
typedef struct config CONFIG;

32
const.c
View File

@@ -1,7 +1,7 @@
/*
* const - constant number storage module
*
* 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
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -28,6 +28,11 @@
#include "calc.h"
#include "qmath.h"
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
#define CONSTALLOCSIZE 400 /* number of constants to allocate */
STATIC unsigned long constcount;/* number of constants defined */
@@ -40,16 +45,16 @@ initconstants(void)
{
int i;
consttable = (NUMBER **) malloc(sizeof(NUMBER *) * CONSTALLOCSIZE);
consttable = (NUMBER **) calloc(sizeof(NUMBER *), CONSTALLOCSIZE);
if (consttable == NULL) {
math_error("Unable to allocate constant table");
/*NOTREACHED*/
not_reached();
}
for (i = 0; i < INITCONSTCOUNT; i++)
for (i = 0; initnumbs[i] != NULL; i++) {
consttable[i] = initnumbs[i];
consttable[INITCONSTCOUNT] = NULL; /* firewall */
constcount = INITCONSTCOUNT;
constavail = CONSTALLOCSIZE - INITCONSTCOUNT;
}
constcount = i-1;
constavail = CONSTALLOCSIZE - constcount;
}
@@ -104,7 +109,7 @@ addqconstant(NUMBER *q)
sizeof(NUMBER *) * (constcount + CONSTALLOCSIZE));
if (tp == NULL) {
math_error("Unable to reallocate const table");
/*NOTREACHED*/
not_reached();
}
consttable = tp;
constavail = CONSTALLOCSIZE;
@@ -119,6 +124,9 @@ addqconstant(NUMBER *q)
tp = consttable;
for (index = 0; index < constcount; index++, tp++) {
t = *tp;
if (t == NULL) { /* paranoia */
break;
}
if (t->links == 0) {
if (!havefirst) {
havefirst = TRUE;
@@ -172,11 +180,11 @@ constvalue(unsigned long index)
{
if (index >= constcount) {
math_error("Bad index value for constvalue");
/*NOTREACHED*/
not_reached();
}
if (consttable[index]->links == 0) {
math_error("Constvalue has been freed!!!");
/*NOTREACHED*/
not_reached();
}
return consttable[index];
}
@@ -189,12 +197,12 @@ freeconstant(unsigned long index)
if (index >= constcount) {
math_error("Bad index value for freeconst");
/*NOTREACHED*/
not_reached();
}
q = consttable[index];
if (q->links == 0) {
math_error("Attempting to free freed const location");
/*NOTREACHED*/
not_reached();
}
qfree(q);
if (index == constcount - 1) {

View File

@@ -1,7 +1,9 @@
#!/usr/local/src/bin/calc/calc -q -s -f
#!/usr/local/src/bin/calc/calc -q -f
/*
* 4dsphere - determine if 6 points lie on the surface of a sphere in R^4
*
* Copyright (C) 2001,2014,2019,2021 Landon Curt Noll
*
* usage:
* 4dsphere x0 y0 z0 w0 x1 y1 z1 w1 ... x5 y5 z5 w5
*
@@ -10,8 +12,6 @@
* ... ...
* x5 y5 z5 w5 point 5 in R^4
*
* Copyright (C) 2001,2014 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.
@@ -37,9 +37,11 @@
* parse args
*/
argc = argv();
if (argc != 25) {
fprintf(files(2), "usage: %s x0 y0 z0 w0 x1 y1 z1 w1 ... x5 y5 z5 w5\n",
argv(0));
stderr = files(2);
program = argv(0);
if (argc != 24) {
fprintf(stderr, "usage: %s x0 y0 z0 w0 x1 y1 z1 w1 ... x5 y5 z5 w5\n",
program);
exit;
}
x0 = eval(argv(1));

View File

@@ -1,7 +1,15 @@
#
# cscript - makefile for calc shell script files
#
# Copyright (C) 1999-2006,2014,2017 Landon Curt Noll
# Copyright (C) 1999-2006,2014,2017,2021,2022 Landon Curt Noll
#
# SRC: cscript/Makefile
#
# The "# SRC: ... - ..." comment line above indicates
# the origin of this file.
#
# IMPORTANT: Please see the section on Makefiles near the
# bottom of the HOWTO.INSTALL file.
#
# Calc is open software; you can redistribute it and/or modify it under
# the terms of the version 2.1 of the GNU Lesser General Public License
@@ -27,15 +35,67 @@
# Makefile by Landon Curt Noll
# required vars
# The shell used by this Makefile
#
SHELL= /bin/sh
# On some systems, /bin/sh is a rather reduced shell with
# deprecated behavior.
#
# If your system has a up to date, bash shell, then
# you may wish to use:
#
# SHELL= /bin/bash
#
# On some systems such as macOS, the bash shell is very
# far behind to the point where is cannot be depended on.
# On such systems, the sh may be a much better alternative
# shell for this Makefile to use:
#
# SHELL= /bin/sh
#
SHELL= /bin/bash
#SHELL= /bin/sh
#if 0 /* start of skip for non-Gnu makefiles */
ifeq ($(target),Darwin)
SHELL:= /bin/zsh
endif
#endif /* end of skip for non-Gnu makefiles */
####
# Normally, the upper level makefile will set these values. We provide
# a default here just in case you want to build from this directory.
####
# PREFIX - Top level location for calc
#
# The PREFIX is often prepended to paths within calc and calc Makefiles.
#
# Starting with calc v2.13.0.1, nearly all Makefile places that used
# /usr/local now use ${PREFIX}. An exception is the olduninstall rule
# and, of course, this section. :-)
#
# NOTE: The ${PREFIX} is not the same as ${T}. The ${T} specifies
# a top level directory under which calc installs things.
# While usually ${T} is empty, it can be specific path
# as if calc where "chrooted" during an install.
# The ${PREFIX} value, during install, is a path between
# the top level ${T} install directory and the object
# such as an include file.
#
# NOTE: See also, ${T}, below.
#
# There are some paths that do NOT call under ${PREFIX}, such as
# ${CALCPATH}, that include paths not under ${PREFIX}, but those
# too are exceptions to this general rule.
#
# When in doubt, try:
#
# PREFIX= /usr/local
#
PREFIX= /usr/local
#PREFIX= /usr
#PREFIX= /usr/global
# Normally certain files depend on the Makefile. If the Makefile is
# changed, then certain steps should be redone. If MAKE_FILE is
# set to Makefile, then these files will depend on Makefile. If
@@ -45,15 +105,6 @@ SHELL= /bin/sh
#
MAKE_FILE= Makefile
# Controlling file makefile basename (without the path)
#
# This is the basename same of the makefile that may/does/will drive
# this makefile.
#
# If in doubt, set TOP_MAKE_FILE to Makefile
#
TOP_MAKE_FILE= Makefile
# Where the system include (.h) files are kept
#
# For DJGPP, select:
@@ -65,11 +116,11 @@ TOP_MAKE_FILE= Makefile
# INCDIR= /usr/include
#
#INCDIR= /usr/local/include
#INCDIR= ${PREFIX}/include
#INCDIR= /dev/env/DJDIR/include
INCDIR= /usr/include
# where to install calc realted things
# where to install calc related things
#
# ${BINDIR} where to install calc binary files
# ${LIBDIR} where calc link library (*.a) files are installed
@@ -91,15 +142,15 @@ INCDIR= /usr/include
# LIBDIR= /usr/lib
# CALC_SHAREDIR= /usr/share/calc
#
#BINDIR= /usr/local/bin
#BINDIR= ${PREFIX}/bin
#BINDIR= /dev/env/DJDIR/bin
BINDIR= /usr/bin
#LIBDIR= /usr/local/lib
#LIBDIR= ${PREFIX}/lib
#LIBDIR= /dev/env/DJDIR/lib
LIBDIR= /usr/lib
#CALC_SHAREDIR= /usr/local/lib/calc
#CALC_SHAREDIR= ${PREFIX}/lib/calc
#CALC_SHAREDIR= /dev/env/DJDIR/share/calc
CALC_SHAREDIR= /usr/share/calc
@@ -157,28 +208,59 @@ T=
# Makefile debug
#
# Q=@ do not echo internal makefile actions (quiet mode)
# Q= echo internal makefile actions (debug / verbose mode)
# Q=@ do not echo internal Makefile actions (quiet 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=@
#
S= >/dev/null 2>&1
#S=
#
E= 2>/dev/null
#E=
#
#H=@:
H=@
#
V=@:
#V=@
# standard tools
#
CAT= cat
CHMOD= chmod
CMP= cmp
CO= co
CP= cp
FMT= fmt
MKDIR= mkdir
MV= mv
RM= rm
RMDIR= rmdir
SED= sed
SORT= sort
FMT= fmt
CMP= cmp
MKDIR= mkdir
RMDIR= rmdir
RM= rm
TOUCH= touch
MV= mv
CP= cp
CO= co
TRUE= true
# NOTE: On some shells, echo is a builtin that does
# not understand -n, so we call /bin/echo -n
# directly to get around such shells.
#
ECHON= /bin/echo -n
# The ${SCRIPT} list is the list of calc shell script files (without the .calc
# extension) which will be installed.
#
@@ -188,18 +270,17 @@ TRUE= true
# To add a script:
#
# 1) Name the file with a .calc filename extension
# 2) Place that file under RCS control
# 3) Add the name, without the .calc extension to the ${SCRIPT} below
# 4) Write out this Makefile
# 5) Replace the ${SCRIPT} and ${SCRIPT_SRC} lines with the output of:
# 2) Add the name, without the .calc extension to the ${SCRIPT} below
# 3) Write out this Makefile
# 4) Replace the SCRIPT= and SCRIPT_SRC= lines with the output of:
#
# make detaillist
#
SCRIPT= 4dsphere fproduct mersenne piforever plus powerterm \
simple square
SCRIPT= 4dsphere fproduct mersenne piforever plus powerterm simple \
square
SCRIPT_SRC= 4dsphere.calc fproduct.calc mersenne.calc \
piforever.calc plus.calc powerterm.calc simple.calc square.calc
SCRIPT_SRC= 4dsphere.calc fproduct.calc mersenne.calc piforever.calc \
plus.calc powerterm.calc simple.calc square.calc
# These files are found (but not built) in the distribution
#
@@ -216,11 +297,17 @@ CALCLIBLIST=
#
CSCRIPT_TARGETS= ${SCRIPT}
TARGETS= ${CSCRIPT_TARGETS} README
#
# rules that are not also names of files
#
PHONY= all clobber distlist install
# The reason for this Makefile
#
all: ${TARGETS} .all
.PHONY: ${PHONY}
README: README.src
@${RM} -f $@
@${SED} -e "s:#!/usr/local/src/bin/calc/calc:#!${BINDIR}/calc:" $?>$@
@@ -263,11 +350,7 @@ detaillist:
${Q} -(echo "xxxxxxx"; \
for i in ${SCRIPT} /dev/null; do \
if [ X"$$i" != X"/dev/null" ]; then \
if [ ! -f RCS/$$i.calc,v ]; then \
echo "WARNING: $$i.calc not under RCS control" 1>&2; \
else \
echo $$i; \
fi; \
echo $$i; \
fi; \
done | LANG=C ${SORT}) | ${FMT} -70 | \
${SED} -e '1s/xxxxxxx/SCRIPT=/' -e '2,$$s/^/ /' \
@@ -276,11 +359,7 @@ detaillist:
${Q} -(echo "xxxxxxxxxxx"; \
for i in ${SCRIPT} /dev/null; do \
if [ X"$$i" != X"/dev/null" ]; then \
if [ ! -f RCS/$$i.calc,v ]; then \
echo "WARNING: $$i.calc not under RCS control" 1>&2; \
else \
echo $$i.calc; \
fi; \
echo $$i.calc; \
fi; \
done | LANG=C ${SORT}) | ${FMT} -70 | \
${SED} -e '1s/xxxxxxxxxxx/SCRIPT_SRC=/' -e '2,$$s/^/ /' \
@@ -291,7 +370,7 @@ detaillist:
# Home grown make dependency rules. Your system make not support
# or have the needed tools. You can ignore this section.
#
# We will form a skelaton tree of *.c files containing only #include "foo.h"
# We will form a skeleton tree of *.c files containing only #include "foo.h"
# lines and .h files containing the same lines surrounded by multiple include
# prevention lines. This allows us to build a static depend list that will
# satisfy all possible cpp symbol definition combinations.
@@ -311,7 +390,7 @@ depend:
if [ X"$$i" != X"/dev/null" ]; then \
echo "$$i: $$i.calc"; \
echo ' @$${RM} -f $$@'; \
echo -n ' @$${SED} -e "1s:^#!/usr/local/src/bin/'; \
${ECHON} ' @$${SED} -e "1s:^#!/usr/local/src/bin/'; \
echo 'calc/calc:#!$${BINDIR}/calc:" $$?>$$@'; \
echo ' @$${CHMOD} +x $$@'; \
fi; \
@@ -326,20 +405,13 @@ depend:
${Q} ${CAT} makedep.out >> ${MAKE_FILE}
${Q} ${RM} -f makedep.out
-${Q} if ${CMP} -s ${MAKE_FILE}.bak ${MAKE_FILE}; then \
echo 'sample ${MAKE_FILE} was already up to date'; \
echo 'cscript/${MAKE_FILE} was already up to date'; \
echo 'restoring original cscript/${MAKE_FILE}'; \
${MV} -f ${MAKE_FILE}.bak ${MAKE_FILE}; \
else \
${RM} -f ${MAKE_FILE}.tmp; \
${MV} ${MAKE_FILE} ${MAKE_FILE}.tmp; \
if [ -d RCS -a ! -w "${MAKE_FILE}" ]; then \
${CO} -l ${MAKE_FILE}; \
fi; \
${MV} ${MAKE_FILE}.tmp ${MAKE_FILE}; \
if [ -d RCS ]; then \
echo '******************************************************'; \
echo 'new cscript ${MAKE_FILE} formed -- need to check it in'; \
echo '******************************************************'; \
fi; \
echo 'old cscript/${MAKE_FILE} is now cscript/${MAKE_FILE}.bak'; \
echo 'new cscript/${MAKE_FILE} formed'; \
echo 'try: diff -u cscript/${MAKE_FILE}.bak cscript/${MAKE_FILE}'; \
fi
##
@@ -426,7 +498,7 @@ uninstall:
continue; \
fi; \
if [ -f "${T}${SCRIPTDIR}/$$i" ]; then \
${RM} -f "${T}${SCRIPTDIR}/$$i"; \
${RM} -f "${T}${SCRIPTDIR}/$$i"; \
if [ -f "${T}${SCRIPTDIR}/$$i" ]; then \
echo "cannot uninstall ${T}${SCRIPTDIR}/$$i"; \
else \

View File

@@ -52,37 +52,6 @@ For more info, see:
#####
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:
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.
=-=
4dsphere
Determine if 6 points lie on the surface of a 4-dimensional sphere in R^4.
@@ -107,7 +76,7 @@ mersenne exp
piforever
Print the value of pi forever, or as long as you cpu / memory allows.
Print the value of pi forever, or as long as you CPU / memory allows.
plus arg ...
@@ -125,7 +94,7 @@ simple
A trivial example of a calc shell script.
## 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
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -1,15 +1,15 @@
#!/usr/local/src/bin/calc/calc -q -s -f
#!/usr/local/src/bin/calc/calc -q -f
/*
* fproduct - write the big Endian product of terms to a file
*
* Copyright (C) 2001,2014,2019,2021 Landon Curt Noll
*
* usage:
* fproduct filename term [term ...]
*
* filename where to write the product, use - for stdout
* term ... terms to multiply
*
* Copyright (C) 2001,2014 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.
@@ -35,8 +35,10 @@
* parse args
*/
argc = argv();
stderr = files(2);
program = argv(0);
if (argc < 2) {
fprintf(files(2), "usage: %s term [term ...]\n", argv(0));
fprintf(stderr, "usage: %s term [term ...]\n", program);
exit;
}
filename = argv(1);

View File

@@ -1,8 +1,8 @@
#!/usr/local/src/bin/calc/calc -q -s -f
#!/usr/local/src/bin/calc/calc -q -f
/*
* mersenne - print the value of a mersenne number
*
* Copyright (C) 1999-2007,2014 Landon Curt Noll
* Copyright (C) 1999-2007,2014,2019,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
@@ -32,16 +32,19 @@
/*
* parse args
*/
if (argv() != 2) {
/* we include the name of this script in the error message */
fprintf(files(2), "usage: %s exp\n", config("program"));
abort "wrong number of args";
argc = argv();
stderr = files(2);
program = argv(0);
if (argc != 2) {
/* we include the name of this script in the error message */
fprintf(stderr, "usage: %s exp\n", program);
abort "wrong number of args";
}
global n = eval(argv(1));
n = eval(argv(1));
if (!isint(n) || n <= 0) {
quit "Argument to be a positive integer";
quit "Argument to be a positive integer";
}
/*

View File

@@ -1,8 +1,8 @@
#!/usr/local/src/bin/calc/calc -q -f
/*
* piforever - print digits of pi forever (or as long as your mem/cpu allow)
* piforever - print digits of pi forever (or as long as your mem/CPU allow)
*
* Copyright (C) 1999-2007,2014 Landon Curt Noll
* Copyright (C) 1999-2007,2014,2019,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

View File

@@ -2,7 +2,7 @@
/*
* plus - add two or more arguments together
*
* Copyright (C) 1999-2007,2014 Landon Curt Noll
* Copyright (C) 1999-2007,2014,2019,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
@@ -32,10 +32,13 @@
/*
* parse args
*/
if (argv() < 2) {
/* we include the name of this script in the error message */
fprintf(files(2), "usage: %s value ...\n", config("program"));
abort "not enough args";
argc = argv();
stderr = files(2);
program = argv(0);
if (argc < 2) {
/* we include the name of this script in the error message */
fprintf(stderr, "usage: %s value ...\n", program);
abort "not enough args";
}
/*
@@ -44,7 +47,7 @@ if (argv() < 2) {
* Since args are strings, we must eval them before using them numerically.
*/
sum = 0;
for (i=1; i < argv(); ++i) {
sum += eval(argv(i));
for (i=1; i < argc; ++i) {
sum += eval(argv(i));
}
print sum;

View File

@@ -1,14 +1,22 @@
#!/usr/local/src/bin/calc/calc -q -s -f
#!/usr/local/src/bin/calc/calc -q -f
/*
* powerterm - print the argument as a sum of powers of integers
*
* Copyright (C) 2001,2014,2019,2021 Landon Curt Noll
*
* usage:
* powerterm [base_limit] value
*
* base_limit largest base we will consider (def: 10000)
* value value to convert into sums of powers of integers
*
* Copyright (C) 2001,2014 Landon Curt Noll
* Example:
*
* powerterm 5 1000000
*
* prints:
*
* 4^10 - 3^10 + 5^6 - 4^6 - 4^5 - 2^5
*
* Calc is open software; you can redistribute it and/or modify it under
* the powerterm of the version 2.1 of the GNU Lesser General Public License
@@ -35,28 +43,31 @@
/*
* parse args
*/
argc = argv();
stderr = files(2);
program = argv(0);
config("verbose_quit", 0),;
base_lim = 10000; /* default: highest base we will consider */
if (argv() < 2 || argv() > 3) {
fprintf(files(2), "usage: %s [base_limit] value\n", argv(0));
if (argc < 2 || argc > 3) {
fprintf(stderr, "usage: %s [base_limit] value\n", program);
exit;
}
if (argv() == 3) {
if (argc == 3) {
x = eval(argv(2));
base_lim = eval(argv(1));
} else {
x = eval(argv(1));
}
if (! isint(x)) {
fprintf(files(2), "%s: value must be an integer\n");
fprintf(stderr, "%s: value must be an integer\n", program);
exit;
}
if (! isint(base_lim)) {
fprintf(files(2), "%s: base limit must be an integer\n");
fprintf(stderr, "%s: base limit must be an integer\n", program);
exit;
}
if (base_lim <= 1) {
fprintf(files(2), "%s: base limit is too small\n");
fprintf(stderr, "%s: base limit is too small\n", program);
exit;
}
++base_lim;
@@ -81,7 +92,7 @@ if (base_lim <= 2^20+1) { /* 2^20 requires ~96 Megs of memory */
}
/*
* remove nestest powers
* remove nearest powers
*/
while (abs(x) >= base_lim) {

View File

@@ -2,7 +2,7 @@
/*
* simple - an example of a simple calc shell script
*
* Copyright (C) 1999-2007,2014 Landon Curt Noll
* Copyright (C) 1999-2007,2014,2019,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
@@ -30,3 +30,9 @@
* This is an example of a simple calc shell script.
*/
print "This simple calc shell script works!"
print "config(\"program\")=", config("program");
print "argv()=", argv();
argc = argv();
for (i=0; i < argc; ++i) {
print "argv(":i:")=", argv(i);
}

View File

@@ -1,8 +1,8 @@
#!/usr/local/src/bin/calc/calc -q -f
#!/usr/local/src/bin/calc/calc -q -p -f
/*
* sqaure - print the squares of input values
* square - print the squares of input values
*
* Copyright (C) 2000-2007,2014 Ernest Bowen
* Copyright (C) 2000-2007,2014,2019,2021 Ernest Bowen
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -33,10 +33,6 @@
* cat file | ./square
* echo "123" | ./square
*
* Within calc:
*
* > read square
*
* With input from a terminal, there is no prompt but each non-empty
* line of input is evaluated as a calc expression and if it can be
* calculated, the square of the value of that expression is displayed.
@@ -52,6 +48,8 @@
* 1522756
* ln(2)
* ~.48045301391820142467
* 2i
* -4
* config("mode","frac"), bernoulli(10)
* 25/4356
* config("mode", "hex"), 0xff
@@ -59,6 +57,6 @@
*/
global s;
while ((s = prompt("")))
while (s = fgetline(files(0))) {
print "\t":eval(s)^2;
}

View File

@@ -1,7 +1,7 @@
/*
* custom - interface for custom software and hardware interfaces
*
* Copyright (C) 1999-2006 Landon Curt Noll
* Copyright (C) 1999-2006,2018,2021,2022 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -47,6 +47,11 @@
#endif /* CUSTOM */
#include "attribute.h"
#include "banned.h" /* include after system header <> includes */
BOOL allow_custom = FALSE; /* TRUE => custom builtins allowed */
@@ -73,12 +78,12 @@ custom(char *name, int count, VALUE **vals)
if (count < p->minargs) {
math_error("Too few arguments for custom "
"function \"%s\"", p->name);
/*NOTREACHED*/
not_reached();
}
if (count > p->maxargs) {
math_error("Too many arguments for custom "
"function \"%s\"", p->name);
/*NOTREACHED*/
not_reached();
}
/* call the custom function */
@@ -109,7 +114,7 @@ custom(char *name, int count, VALUE **vals)
/*
* showcustom - display the names and brief descriptins of custom functions
* showcustom - display the names and brief descriptions of custom functions
*/
/*ARGSUSED*/
void
@@ -180,6 +185,7 @@ customhelp(char *name)
#if defined(CUSTOM)
char *customname; /* a string of the form: custom/name */
size_t snprintf_len; /* malloced snprintf buffer length */
/*
* firewall
@@ -191,12 +197,14 @@ customhelp(char *name)
/*
* form the custom help name
*/
customname = (char *)malloc(sizeof("custhelp")+1+strlen(name)+1);
snprintf_len = sizeof("custhelp")+1+strlen(name)+1;
customname = (char *)malloc(snprintf_len+1);
if (customname == NULL) {
math_error("bad malloc of customname");
/*NOTREACHED*/
not_reached();
}
sprintf(customname, "custhelp/%s", name);
snprintf(customname, snprintf_len, "custhelp/%s", name);
customname[snprintf_len] = '\0'; /* paranoia */
/*
* give help directly to the custom file

View File

@@ -1,7 +1,7 @@
/*
* custom - interface for custom software and hardware interfaces
*
* Copyright (C) 1999-2007 Landon Curt Noll
* Copyright (C) 1999-2007,2021 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
@@ -35,7 +35,7 @@
*
* before they include this file.
*
* Keep this file down to a minimum. Don't put custom builtin funcion
* Keep this file down to a minimum. Don't put custom builtin function
* stuff in this file!
*/
@@ -45,7 +45,7 @@
/*
* arg count definitons
* arg count definitions
*/
#define MAX_CUSTOM_ARGS 100 /* maximum number of custom arguments */

View File

@@ -4,7 +4,7 @@ Custom calc resource files
The following custom calc resource files are provided because they serve
as examples of how use the custom interface. The custom interface
allows for machine dependent and/or non-portable code to be added as
builtins to the calc program. A few example custom functions and
built-ins to the calc program. A few example custom functions and
resource files are shipped with calc to provide you with examples.
By default, the custom builtin returns an error. Calc have been
@@ -41,7 +41,7 @@ pzasusb8.cal
Run custom("pzasusb8") on a standard set of data, print Endian
related information and print value size information.
## Copyright (C) 1999 Landon Curt Noll
## Copyright (C) 1999,2021 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -220,7 +220,7 @@ Step 5: Write your custom function
NOTE: If you do not use any of the 3 function parameters,
then you should declare that function parameter to be UNUSED.
For example, if the count and vals parameters were not used
in your custom function, then your declaraction should be:
in your custom function, then your declaration should be:
/*ARGSUSED*/
VALUE
@@ -374,12 +374,12 @@ Step 5: Write your custom function
One is able to set bit 8 by way of the calc command line:
calc -D 128
calc -D 128
See the calc man page for details. One may also set that bit
while running calc by way of the config() builtin function:
config("calc_debug", 128);
config("calc_debug", 128);
See the help/config file for details on calc_debug.
@@ -645,7 +645,7 @@ Step 12: Contribute
and consider submitting your custom function for possible
inclusion in later versions of calc.
## Copyright (C) 1999-2007 Landon Curt Noll
## Copyright (C) 1999-2007,2021 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

Some files were not shown because too many files have changed in this diff Show More