Compare commits

..

10 Commits

Author SHA1 Message Date
Landon Curt Noll
a0aba073a6 Release calc version 2.11.5t3 2017-05-21 15:38:40 -07:00
Landon Curt Noll
59837e385c Release calc version 2.11.5t2.1 2017-05-21 15:38:40 -07:00
Landon Curt Noll
bea726fc16 Release calc version 2.11.5t2 2017-05-21 15:38:40 -07:00
Landon Curt Noll
fc0a3dd183 Release calc version 2.11.5t1.1 2017-05-21 15:38:39 -07:00
Landon Curt Noll
63d9b22067 Release calc version 2.11.5t1.0 2017-05-21 15:38:39 -07:00
Landon Curt Noll
fc85ac3791 Release calc version 2.11.5t0 2017-05-21 15:38:39 -07:00
Landon Curt Noll
3d55811205 Release calc version 2.11.4t2 2017-05-21 15:38:39 -07:00
Landon Curt Noll
296aa50ac7 Release calc version 2.11.2t1 2017-05-21 15:38:38 -07:00
Landon Curt Noll
5e098d2adf Release calc version 2.11.4t1 2017-05-21 15:38:38 -07:00
Landon Curt Noll
ae2a752314 Release calc version 2.11.3t0 2017-05-21 15:38:38 -07:00
123 changed files with 9927 additions and 3157 deletions

71
BUGS
View File

@@ -83,6 +83,51 @@ Problems with known work-a-rounds:
to fail the regression test. The work-a-round is to compile with -O
or to use gcc-2.96 or later.
This bug has been observed on the Sparc and the PowerPC machine.
On the PowerPC with gcc-2.95 when compiled with -O2, the following
patch seems to help:
*** zfunc.c.orig Fri Feb 23 18:18:39 2001
--- zfunc.c Fri Feb 23 18:39:33 2001
***************
*** 1481,1487 ****
{
HALF *a, *A, *b, *a0, u;
int i, j, j1, j2, k, k1, m, m0, m1, n, n0, o;
! FULL d, e, f, g, h, s, t, x, topbit;
int remsign;
BOOL up, onebit;
ZVALUE sqrt;
--- 1481,1488 ----
{
HALF *a, *A, *b, *a0, u;
int i, j, j1, j2, k, k1, m, m0, m1, n, n0, o;
! volatile FULL d;
! FULL e, f, g, h, s, t, x, topbit;
int remsign;
BOOL up, onebit;
ZVALUE sqrt;
*** zmath.c 2000/06/07 14:02:13 29.2
--- zmath.c 2001/03/13 19:47:03
***************
*** 1608,1614 ****
void
zbitvalue(long n, ZVALUE *res)
{
! ZVALUE z;
if (n < 0) n = 0;
z.sign = 0;
--- 1608,1614 ----
void
zbitvalue(long n, ZVALUE *res)
{
! volatile ZVALUE z;
if (n < 0) n = 0;
z.sign = 0;
* Solaris cc somtimes barfs while compiling zrand.c. In particular, calc
barfs on on the SVAL macro. The work-a-round is to use the Solaric cc
Makefile set sets -DFORCE_STDC. I.e,:
@@ -163,6 +208,28 @@ Problems with known work-a-rounds:
or performance. The work-a-round is to ignore these warnings
under BSDI.
* The chi.cal resource file does not work well with odd degrees
of freedom. Can someone improve this algorithm?
* The intfile.cal resource file reads and writes big or little Endian
integers to/from files the hard way. It does NOT use blkcpy. The
following code:
i = (ord("\n") << 16) | (ord("i") << 8) | ord("H")
b = blk()
copy(i, b)
fd = fopen("file", "w")
copy(b, fd);
fclose(fd)
will write an extra NUL octet to the file. Where as:
read intfile
i = (ord("\n") << 16) | (ord("i") << 8) | ord("H")
be2file(i, "file2")
will not.
## Copyright (C) 1999 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
@@ -179,8 +246,8 @@ Problems with known work-a-rounds:
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.5 $
## @(#) $Id: BUGS,v 29.5 2000/06/07 14:02:13 chongo Exp $
## @(#) $Revision: 29.10 $
## @(#) $Id: BUGS,v 29.10 2001/04/08 11:32:52 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/RCS/BUGS,v $
##
## Under source code control: 1994/03/18 14:06:13

454
CHANGES
View File

@@ -1,4 +1,452 @@
The following are the changes from calc version 2.11.2t0 to date:
The following are the changes from calc version 2.11.5t2 to date:
Fixed a bug, reported by Ernest Bowen <ernie at turing dot
une dot edu dot au> that caused command lines to be echoed in
interactive mode. Fixed a bug that sometimes left the terminal
in a non-echoing state when calc exited.
Renamed error codes E_FGETWORD1 and E_FGETWORD2 symbols to
E_FGETFIELD1 and E_FGETFIELD2.
Made a minor format change to the top of the calc man page.
The findid() function in file.c 2nd argument changed. The argument
is now mostly a writable flag. This function now finds the file
I/O structure for the specified file id, and verifies that
it is opened in the required manner (0 for reading or 1 for writing).
If the 2nd argument is -1, then no open checks are made at all and
NULL is then returned if the id represents a closed file.
The calc builtin function, fopen(), now allows one to specify
opening files in binary modes. On POSIX / Linux / Un*x-like systems,
text file is the same as a binary file and so 'b' to an fopen has
no effect and is ignored. However on systems such as MS Windoz
the 'b' / binary mode has meaning. See 'help fopen' for details.
On systems (such as MS Windoz), calc will produce a different error
message when it attempts to open /dev/tty. This will condition
will occur in things like calc scripts when they switch from ``batch
processing'' commands from and want to start interactive mode.
Regression tests fopen in binary mode in a few places where a
difference between text and binary string lengths matter.
The intfile calc resource file also uses binary mode.
Changed the rand() builtin and its related functions srand() and
randbit() to use the Subtractive 100 generator instead of the
additive 55 generator. This generator as improved random properties.
As a result, of this change, the values produced by rand(),
rand() and randbit() are now different.
Updated regression tests for new rand() and randbit() output.
Applied a bug fix from Ernest Bowen <ernie at turing dot une dot
edu dot au> dealing with one-line "static" declaration like:
static a = 1, b;
Added regression test 8310 to test for the static bug fix.
The following are the changes from calc version 2.11.5t0 to date:
Fixed a compile problem with Linux 2.4 / Debian. Thanks goes
to Martin Buck <m at rtin-buck dot de> for help with this issue.
Fixed a bug in how L64_FORMAT (it determined if "%ld" or "%lld"
is appropriate for printing of 64 bit long longs) was determined.
Thanks goes to Martin Buck <m at rtin-buck dot de> for reporting
this bug and testing the fix.
An effort was made to make calc easier to build under Windoz
using the Cygwin project (http://sources.redhat.com/cygwin/).
Thanks to the work of Thomas Jones-Low (tjoneslo and softstart
dot com), a number of #if defined(_WIN32)'s have been added
to calc source. These changes should not effect Windoz
free system such as GNU/Linux, Solaris, POSIX-like, etc ...
Added windll.h to deal with Windoz related DLL issues.
Using the convention of 'extern DLL' instead of 'DLL extern'
to deal with symbols that export to or import from a DLL.
Added HAVE_MALLOC_H, HAVE_STDLIB_H, HAVE_STRING_H, HAVE_TIMES_H,
HAVE_SYS_TIMES_H, HAVE_TIME_H, HAVE_SYS_TIME_H, HAVE_UNISTD_H
and HAVE_URANDOM to the Makefile. If these symcols are empty,
then the Makefile looks for the appropriate system include file.
If they are YES, then the Makefile will assume they exist.
If they are NO, then the Makefile will assume they do not exist.
Changed HAVE_URANDOM to match the empty, YES, NO values.
If HAVE_URANDOM is empty, then the Makefile will look for /dev/urandom.
If HAVE_URANDOM is YES, then the Makefile will assume /dev/urandom exists.
If HAVE_URANDOM is NO, then the Makefile will assume /dev/urandom does
not exist.
If TERMCONTROL is -DUSE_WIN32, then the Windoz terminal control
(no TERMIOS, no TERMIO, no SGTTY) will be assumed.
Added a win32_hsrc Makefile rule to create hsrc files appropriate
for a Windoz system using Cygwin gcc environment. Added win32.mkdef
which is used by the win32_hsrc rule to set the Windoz specific
Makefile values to build hsrc files. The hsrc files are built
under the win32 directory.
Added FPOS_POS_BITS, OFF_T_BITS, DEV_BITS and INODE_BITS Makefile
symbiols to allow one to force the size of a file position, file
offset, dev and inode value. Leaving these values blank will
Makefile to determine their size.
Fixed a bug in the way file offsets, device and inode values are copied.
Added chi.cal for a initial stab as a Chi^2 function. The chi_prob()
function does not work well with odd degrees of freedom, however.
Added big 3 to config("resource_debug"). Calc resource file scripts
check for config("resource_debug") & 8 prior to printing internal debug
statements. Thus by default they do not print them.
Added intfile.cal as a calc resource file script:
file2be(filename)
Read filename and return an integer that is built from the
octets in that file in Big Endian order. The first octets
of the file become the most significant bits of the integer.
file2le(filename)
Read filename and return an integer that is built from the
octets in that file in Little Endian order. The first octets
of the file become the most significant bits of the integer.
be2file(v, filename)
Write the absolute value of v into filename in Big Endian order.
The v argument must be on integer. The most significant bits
of the integer become the first octets of the file.
le2file(v, filename)
Write the absolute value of v into filename in Little Endian order.
The v argument must be on integer. The least significant bits
of the integer become the last octets of the file.
Added the following help aliases:
copy blkcpy
read command
write command
quit command
exit command
abort command
cd command
show command
Added the cscript:
fproduct filename term ...
to write the big Endian product of terms to a filename. Use - for stdout.
Fixed calc path in help/script.
Added read-only parameter, config("windows") to indicate if the system
is MS windowz WIN32 like system.
Configuration values that used to return "true" or "false" now return
1 (a true value) or 0 (a false value). Thus one can do:
if (config("tab")) { ... } else { ... }
The configuration values that now return 1 or 0 are:
config("tilde")
config("tab")
config("leadzero")
config("blkverbose")
config("verbose_quit")
config("windows")
Now shipping a win32 sub-directory that contains hsrc .h files
that have been attempted to be built for windoz.
The following are the changes from calc version 2.11.4t1 to date:
Added missing test8600.cal test file.
Fixes cscript files to deal with the -S flag being replaced by
-f and possibly other flags.
Added regression tests for builtin functions bernoulli, catalan,
euler, freeeuler, and sleep. Added non-base 10 regression tests
for digit, digits and places.
The bernoulli.cal script now just calls the bernoulli() builtin
function. It remains for backward compatibility.
The Makefile now builds have_fpos_pos.h to determine if the
a non-scalar FILEPOS has a __pos stucture element. If it does,
the FILEPOS_BITS is taken to be the size of just the __pos element.
Misc fixes related to non-scalar (e.g., structure) FILEPOS. Fixed
a compile problems where non-scalar FILEPOS were incorrectly assigned.
Fixed make depend rule.
Return an error on malloc / realloc failures for bernoulli and
euler functions.
Added MAKEFILE_REV make variable to help determine Makefile version.
Fixed the way the env rule reports Makefile values.
The following are the changes from calc version 2.11.3t0 to 2.11.4:
Increased the maximum number of args for functions from 100 to 1024.
Increased calc's internal evaluation stack from 1024 to 2048 args.
Added test8600.cal to the regression suite to test these new limits.
Updated and fixed misc typos in calc/README.
Clarified in the COPYING file that ALL calc source files, both
LGPL covered and exceptions to the LGPL files may be freely used
and distributed.
Added help files or updated for: bernoulli, calc_tty, catalan,
digit, digits, euler, freeeuler, places and sleep.
A collection of 18 patches from Ernest Bowen
<ernie at turing dot une dot edu dot au>:
(1) A new flag -f has been defined which has the effect of a read
command without the need to terminate the file name with a semicolon
or newline. Thus:
calc "read alpha; read beta;"
may be replaced by:
calc -f alpha -f beta
Quotations marks are recognized in a command like
calc -f 'alpha beta'
in which the name of the file to be read includes a space.
(2) Flags are interpreted even if they are in a string, as in:
calc "-q -i define f(x) = x^2;"
which has the effect of:
calc -q -i "define f(x) = x^2;"
To achieve this, the use of getopts() in calc.c has been dropped in
favour of direct reading of the arguments produced by the shell.
In effect, until a "--" or "-s" or a calc command (recognized
by not starting with '-') is encountered, the quotation signs in
command lines like the above example are ignored. Dropping getopts()
permits calc to specify completely the syntax rules calc will apply
to whatever it is given by the shell being used.
(3) For executable script (also called interpreter) files with first
line starting with "#!", the starting of options with -S has been
replaced by ending the options with -f. For example, the first line:
#! full_pathname_for_calc -S -q -i
is to be replaced by:
#! full_pathname_for_calc -q -i -f
Thus, if the pathname is /usr/bin/calc and myfile contains:
#!/usr/bin/calc -q -i -f
global deg = pi()/180;
define Sin(x) = sin(x * deg);
and has been made executable by:
chmod u+x myfile
myfile would be like a version of calc that ignored any startup
files and had an already defined global variable deg and a function
Sin(x) which will return an approximation to the sine of x degrees.
The invocation of myfile may be followed by other options (since
the first line in the script has only flagged options) and/or calc
commands as in:
./myfile -c read alpha '; define f(x) = Sin(x)^2'
(The quotation marks avoid shell interpretation of the semicolon and
parentheses.)
(4) The old -S syntax for executable scripts implied the -s flag so that
arguments in an invocation like
./myfile alpha beta
are passed to calc; in this example argv(0) = 'alpha', argv(1) =
'beta'. This has been changed in two ways: an explicit -s is required
in the first line of the script and then the arguments passed in the
above example are argv(0) = 'myfile', argv(1) = 'alpha', argv(1) = 'beta'.
In an ordinary command line, "-s" indicates that the shell words
after the one in which "-s" occurred are to be passed as arguments
rather than commands or options. For example:
calc "-q -s A = 27;" alpha beta
invokes calc with the q-flag set, one command "A = 27;", and two arguments.
(5) Piping to calc may be followed by calc becoming interactive.
This should occur if there is no -p flag but -i is specified, e.g.:
cat beta | calc -i -f alpha
which will do essentially the same as:
calc -i -f alpha -f beta
(6) The read and help commands have been changed so that several
files may be referred to in succession by separating their names
by whitespace. For example:
> read alpha beta gamma;
does essentially the same as:
> read alpha; read beta; read gamma;
This is convenient for commands like:
calc read file?.cal
when file?.cal expands to something like file1.cal file2.cal file3.cal:
myfiles='alpha beta gamma'
calc read $myfiles
or for C-shell users:
set myfiles=(alpha beta gamma)
calc read $myfiles
(7) The -once option for read has been extended to -f. For example,
calc -f -once alpha
will ignore alpha if alpha has been read in the startup files. In a
multiple read statement, -once applies only to the next named file.
For example
> read -once alpha beta -once gamma;
will read alpha and gamma only if they have not already been read,
but in any case, will read beta.
(8) A fault in the programming for the cd command has been corrected
so that specifying a directory by a string constant will work. E.g:
> cd "my work"
should work if the current directory has a directory with name "my work".
(9) new functions bernoulli(n) and euler(n) have been defined to
return the Bernoulli number and the Euler number with index n.
After evaluation for an even positive n, this value and these for
smaller positive even n are stored in a table from which the values
can be reread when required. The memory used for the stored values
can be freed by calling the function freebernoulli() or freeeuler().
The function catalan(n) returns the catalan number with index n.
This is evaluated using essentially comb(2*n, n)/(n+1).
(10) A function sleep(n) has been defined which for positive n calls
the system function sleep(n) if n is an integer, usleep(n) for other
real n. This suspends operation for n seconds and returns the null
value except when n is integral and the sleep is interrupted by a
SIGINT, in which case the remaining number of seconds is returned.
(11) The effect of config("trace", 8) which displays opcodes of
functions as they are successfully defined has been restricted to
functions defioed with explicit use of "define". Thus, it has been
deactivated for the ephemeral functions used for evaluation of calc
command lines or eval() functions.
(12) The functions digit(), digits(), places() have been extended to
admit an optional additional argument for an integral greater-than-one
base which defaults to 10. There is now no builtin limit on the
size of n in digit(x, n, b), for example, digit(1/7, -1e100) which
would not work before can now be handled.
(13) The function, digits(x), which returns the number of decimal
digits in the integer part of x has been changed so that if abs(x) <
1, it returns 0 rather than 1. This also now applies to digits(x,b).
(14) Some programming in value.c has been improved. In particular,
several occurrences of:
vres->v_type = v1->v_type;
...
if (v1->v_type < 0) {
copyvalue(v1, vres);
return;
}
have been replaced by code that achieves exactly the same result:
vres->v_type = v1->v_type;
...
if (v1->v_type < 0)
return;
(15) Some operations and functions involving null-valued arguments
have been changed so that they return null-value rather than "bad
argument-type" error-value. E.g. null() << 2 is now null-valued
rather than a "bad argument for <<" error-value.
(16) "global" and "local" may now be used in expressions. For example:
> for (local i = 0; i < 5; i++) print i^2;
is now acceptable, as is:
> define f(x = global x) = (global x = x)^2;
which breaks wise programming rules and would probably better be handled
by something like:
> global x
> define f(t = x) = (x = t)^2;
Both definitions produce the same code for f. For non-null t, f(t)
returns t^2 and assigns the value of t to x; f() and f(t) with null t
return x^2.
Within expressions, "global" and "local" are to be followed by just one
identifier. In "(global a = 2, b)" the comma is a comma-operator; the
global variable a is created if necessary and assigned the value 2, the
variable b has to already exist. The statement "global a = 2, b" is
a declaration of global variables and creates both a and b if they
don't already exist.
(18) In a config object, several components have been changed from
long to LEN so that they will now be 32 bit integers for machines with
either 32 or 64-bit longs. In setting such components, the arguments
are now to less than 2^31. Before this change:
> config("mul2", 2^32 + 3)
would be accepted on a 64-bit machine but result in the same as:
> config("mul2", 3)
The following are the changes from calc version 2.11.2t0 to 2.11.2t1.0:
Fixed a bug whereby help files are not displayed correctly on
systems such as NetBSD 1.4.1. Thanks to a fix from Jakob Naumann.
@@ -4766,8 +5214,8 @@ Following is a list of visible changes to calc from version 1.24.7 to 1.26.1:
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.11 $
## @(#) $Id: CHANGES,v 29.11 2000/06/07 15:51:35 chongo Exp $
## @(#) $Revision: 29.29 $
## @(#) $Id: CHANGES,v 29.29 2001/04/14 22:56:46 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/RCS/CHANGES,v $
##
## Under source code control: 1993/06/02 18:12:57

23
COPYING
View File

@@ -12,8 +12,8 @@ This file is Copyrighted
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
# @(#) $Revision: 29.2 $
# @(#) $Id: COPYING,v 29.2 2000/06/07 14:02:13 chongo Exp $
# @(#) $Revision: 29.5 $
# @(#) $Id: COPYING,v 29.5 2000/12/18 10:22:55 chongo Exp $
# @(#) $Source: /usr/local/src/cmd/calc/RCS/COPYING,v $
=-=
@@ -140,7 +140,7 @@ Calc copyrights and exception files
-----------------------------------
With the exception of the files listed below, Calc is covered under
the following Copyrights:
the following GNU Lesser General Public License Copyrights:
Copyright (C) year David I. Bell
Copyright (C) year David I. Bell and Landon Curt Noll
@@ -150,12 +150,11 @@ Calc copyrights and exception files
Copyright (C) year Ernest Bowen and Landon Curt Noll
Copyright (C) year Ernest Bowen
A few files are not covered under the GNU Lesser General Public
License. The source files not covered are:
These files are not covered under one of the Copyrights listed above:
shs1.c shs1.h shs.c shs.h
md5.c md5.h lib/qtime.cal COPYING
COPYING-LGPL
shs1.c shs1.h shs.c shs.h
md5.c md5.h COPYING COPYING-LGPL
cal/qtime.cal
The file COPYING-LGPL, which contains a copy of the version 2.1
GNU Lesser General Public License, is itself Copyrighted by the
@@ -167,6 +166,14 @@ Calc copyrights and exception files
top of this file. It is important to note that you may distribute
verbatim copies of this file but you may not modify this file.
Some of these exception files are in the public domain. Other
exception files have non-LGPL Copyrights. Other files are under a
LGPL Copyright but have different authors.
In all cases one may use and distribute these exception files freely.
And because one may freely distribute the LGPL covered files, the
entire calc source may be freely used and distributed.
=-=
General Copyleft and License info

851
Makefile

File diff suppressed because it is too large Load Diff

116
README.WINDOWS Normal file
View File

@@ -0,0 +1,116 @@
Dear calc user on a Windoz based system,
See the HOWTO.INSTALL file for information on how to build and install calc.
See also the README file.
NOTE: The Windoz port is extremely experimental, untested and perhaps
incomplete. We are in the process of making it easier. The
following should help anyone who is trying to make a go of this
under the current code conditions.
NOTE: We are currently ONLY making an effort to support building under
Windoz using the Cygwin project (http://sources.redhat.com/cygwin/)
with the GCC compiler and Un*x tools for Windows.
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.
Of course you are welcome to send us any patches that fix your
Windoz build environment.
=-=
An effort is being made to allow windows users to compile calc using the
Cygwin project (http://sources.redhat.com/cygwin/) with the GCC compiler
and Un*x tools for Windows.
The major porting work was performed by Thomas Jones-Low
(tjoneslo at softstart dot com). He said:
I had previous stated to this group that I have successfully managed
to port a version of Calc to Windows, and promised some point to
post what was required, so here it is.
One obvious manner of doing this port is to get the latest version
of the Cygwin project (http://sources.redhat.com/cygwin/) with the
GCC compiler and Un*x tools for Windows and recompile.
I built my working version using Calc ... I am using Visual C++
version 7.0, which is an older version of the Microsoft development
tools. The make file provided with Calc is not compatible with
NMAKE, so I used the Visual Studio tools to generate another one
(not included). Calc is built in two parts, calc.dll, which is the
library, and calcexe.exe which is the command line interface.
He recommends that you generate by hand all of the header files generated
by the make file:
align32.h args.h calcerr.h conf.h endian_calc.h
fposval.h have_const.h have_fpos.h have_fpos_pos.h have_malloc.h
have_memmv.h have_newstr.h have_offscl.h have_posscl.h
have_stdlib.h have_string.h have_times.h have_uid_t.h
have_unistd.h longbits.h longlong.h terminal.h
have_ustat.h have_getsid.h have_getpgid.h
have_gettime.h have_getprid.h have_urandom.h have_rusage.h
have_strdup.h
You will find generated versions of these files located in the win32
sub-directory. These files may be appropriate for your Cygwin building
needs. Just copy the win32/*.[ch] files up into the top level calc
source directory, edited (if needed) and build using the Cygwin GCC
compiler.
=-=
People who maintain calc need to keep in mind the following:
The following was added to opcodes.h, config.h, zmath.h and value.h:
#if defined(_WIN32)
#ifdef _EXPORTING
#define DLL __declspec(dllexport)
#else
#define DLL __declspec(dllimport)
#endif
#else /* Windoz free systems */
#define DLL
#endif /* Windoz free systems */
Then DLL was added in front of all the exported functions. For example:
extern int configtype(char*);
was changed to:
DLL extern int configtype(char*);
## Copyright (C) 2001 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
## as published by the Free Software Foundation.
##
## Calc is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
## Public License for more details.
##
## A copy of version 2.1 of the GNU Lesser General Public License is
## distributed with calc under the filename COPYING-LGPL. You should have
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.6 $
## @(#) $Id: README.WINDOWS,v 29.6 2001/04/08 22:13:38 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/RCS/README.WINDOWS,v $
##
## Under source code control: 2001/02/25 14:00:05
## File existed as early as: 2001
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: addop.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: addop.c,v 29.3 2000/07/17 15:35:49 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/addop.c,v $
*
* Under source code control: 1990/02/15 01:48:10
@@ -208,7 +208,7 @@ endfunc(void)
memcpy((char *) fp, (char *) curfunc, size);
if (curfunc != functemplate)
free(curfunc);
if (conf->traceflags & TRACE_FNCODES) {
if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) {
dumpnames = TRUE;
for (size = 0; size < fp->f_opcodecount; ) {
printf("%ld: ", (long)size);
@@ -318,7 +318,7 @@ freefunc(FUNC *fp)
/*NOTREACHED*/
}
}
if (conf->traceflags & TRACE_FNCODES) {
if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) {
printf("Freeing function \"%s\"\n",namestr(&funcnames,index));
dumpnames = FALSE;
for (i = 0; i < fp->f_opcodecount; ) {

View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: blkcpy.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: blkcpy.c,v 29.3 2001/04/10 22:06:46 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/blkcpy.c,v $
*
* Under source code control: 1997/04/18 20:41:26
@@ -581,7 +581,7 @@ copyblk2file(BLOCK *sblk, long ssi, long num, FILEID id, long dsi)
if (num == 0)
return 0;
fiop = findid(id, 'w');
fiop = findid(id, TRUE);
if (fiop == NULL)
return E_COPYF1;
fp = fiop->fp;
@@ -618,7 +618,7 @@ copyfile2blk(FILEID id, long ssi, long num, BLOCK *dblk, long dsi, BOOL noreloc)
if (id < 3) /* excludes copying from stdin */
return E_COPYF1;
fiop = findid(id, 'r');
fiop = findid(id, FALSE);
if (fiop == NULL)
return E_COPYF1;
@@ -690,7 +690,7 @@ copystr2file(STRING *str, long ssi, long num, FILEID id, long dsi)
return 0;
if ((USB32) ssi + num > len)
return E_COPY5; /* Insufficient memory in str */
fiop = findid(id, 'w');
fiop = findid(id, TRUE);
if (fiop == NULL)
return E_COPYF1;
fp = fiop->fp;

View File

@@ -18,8 +18,8 @@
# received a copy with calc; if not, write to Free Software Foundation, Inc.
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
# @(#) $Revision: 29.2 $
# @(#) $Id: Makefile,v 29.2 2000/06/07 14:02:25 chongo Exp $
# @(#) $Revision: 29.5 $
# @(#) $Id: Makefile,v 29.5 2001/03/31 16:24:17 chongo Exp $
# @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/Makefile,v $
#
# Under source code control: 1991/07/21 05:00:54
@@ -70,7 +70,7 @@ CALC_FILES= README bigprime.cal deg.cal ellip.cal lucas.cal lucas_chk.cal \
test3500.cal seedrandom.cal test4000.cal test4100.cal test4600.cal \
beer.cal hello.cal test5100.cal test5200.cal randombitrun.cal \
randomrun.cal xx_print.cal natnumset.cal qtime.cal test8400.cal \
test8500.cal
test8500.cal test8600.cal chi.cal intfile.cal
# These files are found (but not built) in the distribution
#

View File

@@ -1,7 +1,7 @@
Calc standard resource files
----------------------------
To load a reosurce file, try:
To load a resource file, try:
read filename
@@ -59,12 +59,12 @@ files have already been read, the read -once will act as a noop.
The "resource_debug" parameter is intended for controlling the possible
display of special information relating to functions, objects, and
other structures created by instructions in calc resoure files.
other structures created by instructions in calc resource files.
Zero value of config("resource_debug") means that no such information
is displayed. For other values, the non-zero bits which currently
have meanings are as follows:
n Meaning of bit n of config("resource_debug")
n Meaning of bit n of config("resource_debug")
0 When a function is defined, redefined or undefined at
interactive level, a message saying what has been done
@@ -74,6 +74,12 @@ have meanings are as follows:
the reading of a file, a message saying what has been done
is displayed.
2 Show func will display more information about a functions
arguments as well as more argument sdummary information.
3 During execution, allow calc standard resource files
to output additional debugging information.
The value for config("resource_debug") in both oldstd and newstd is 3,
but if calc is invoked with the -d flag, its initial value is zero.
Thus, if calc is started without the -d flag, until config("resource_debug")
@@ -97,6 +103,14 @@ either of the bottom 2 bits set:
print "funcB(size, mass, ...) defined";
}
If your the resource file needs to output special debugging informatin,
we recommend that you check for bit 3 of the config("resource_debug")
before printing the debug statement:
if (config("resource_debug") & 8) {
print "DEBUG: This a sample debug statement";
}
=-=
The following is a brief description of some of the calc resource files
@@ -116,6 +130,10 @@ 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
the buildin function.
bigprime.cal
@@ -124,6 +142,24 @@ bigprime.cal
A prime test, base a, on p*2^x+1 for even x>m.
chi.cal
Z(x[, eps])
P(x[, eps])
chi_prob(chi_sq, v[, eps])
Computes the Probability, given the Null Hypothesis, that a given
Chi squared values >= chi_sq with v degrees of freedom.
The chi_prob() function does not work well with odd degrees of freedom.
It is reasonable with even degrees of freedom, although one must give
a sifficently small error term as the degress gets large (>100).
The Z(x) and P(x) are internal statistical funcions.
eps is an optional epsilon() like error term.
chrem.cal
chrem(r1,m1 [,r2,m2, ...])
@@ -159,6 +195,33 @@ hello.cal
http://www.latech.edu/~acm/helloworld/calc.html
intfile.cal
file2be(filename)
Read filename and return an integer that is built from the
octets in that file in Big Endian order. The first octets
of the file become the most significant bits of the integer.
file2le(filename)
Read filename and return an integer that is built from the
octets in that file in Little Endian order. The first octets
of the file become the most significant bits of the integer.
be2file(v, filename)
Write the absolute value of v into filename in Big Endian order.
The v argument must be on integer. The most significant bits
of the integer become the first octets of the file.
le2file(v, filename)
Write the absolute value of v into filename in Little Endian order.
The v argument must be on integer. The least significant bits
of the integer become the last octets of the file.
lucas.cal
lucas(h, n)
@@ -274,7 +337,7 @@ pell.cal
pell(D)
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.
pi.cal
@@ -288,7 +351,7 @@ pi.cal
The piforever() prints digits of pi, nicely formatted, for as long
as your free memory space and system up time allows.
The piforever() funcion (written by Klaus Alexander Seistrup
The piforever() function (written by Klaus Alexander Seistrup
<klaus@seistrup.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.
@@ -356,7 +419,7 @@ quat.cal
quat_shift(a, b)
Calculate using quaternions of the form: a + bi + cj + dk. In these
functions, quaternians are manipulated in the form: s + v, where
functions, quaternions are manipulated in the form: s + v, where
s is a scalar and v is a vector of size 3.
@@ -386,7 +449,7 @@ randombitrun.cal
randombitrun([run_cnt])
Using randombit(1) to generate a sequence of random bits, determine if
the number and kength of identical bits runs match what is expected.
the number and length of identical bits runs match what is expected.
By default, run_cnt is to test the next 65536 random values.
This tests the Blum-Blum-Shub generator.
@@ -489,7 +552,7 @@ test1700.cal
value
This resoure files is used by regress.cal to test the read and use keywords.
This resource files is used by regress.cal to test the read and use keywords.
test2600.cal
@@ -514,7 +577,7 @@ test2600.cal
checkresult(x, y, z, a)
test2600(verbose, tnum)
This resoure files is used by regress.cal to test some of builtin functions
This resource files is used by regress.cal to test some of builtin functions
in terms of accuracy and roundoff.
@@ -537,7 +600,7 @@ test2700.cal
iscomsq(x)
test2700(verbose, tnum)
This resoure files is used by regress.cal to test sqrt() for real and
This resource files is used by regress.cal to test sqrt() for real and
complex values.
@@ -625,7 +688,7 @@ test4000.cal
test4000(verbose, tnum) defined
This resource file is used by regress.cal to test ptest, nextcand and
prevcand buildins.
prevcand builtins.
test4100.cal
@@ -677,6 +740,35 @@ test5200.cal
This resource file is used by regress.cal to test the fix of a
global/static bug.
test8400.cal
test8400() defined
This resource file is used by regress.cal to check for quit-based
memory leaks.
test8500.cal
global err_8500
global L_8500
global ver_8500
global old_seed_8500
global cfg_8500
onetest_8500(a,b,rnd) defined
divmod_8500(N, M1, M2, testnum) defined
This resource file is used by regress.cal to the // and % operators.
test8600.cal
global min_8600
global max_8600
global hash_8600
global hmean_8600
This resource file is used by regress.cal to test a change of
allowing up to 1024 args to be passed to a builtin function.
unitfrac.cal
unitfrac(x)
@@ -705,7 +797,7 @@ xx_print.cal
Demo for the xx_print object routines.
## Copyright (C) 1999 David I. Bell and Landon Curt Noll
## Copyright (C) 2000 David I. Bell and Landon Curt Noll
##
## Primary author: Landon Curt Noll
##
@@ -723,8 +815,8 @@ xx_print.cal
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: README,v 29.2 2000/06/07 14:02:25 chongo Exp $
## @(#) $Revision: 29.8 $
## @(#) $Id: README,v 29.8 2001/03/31 16:26:23 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/README,v $
##
## Under source code control: 1990/02/15 01:50:32

View File

@@ -1,7 +1,7 @@
/*
* bernoulli - clculate the Nth Bernoulli number B(n)
*
* Copyright (C) 1999 David I. Bell
* Copyright (C) 2000 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
@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: bernoulli.cal,v 29.2 2000/06/07 14:02:25 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: bernoulli.cal,v 29.3 2000/12/17 12:26:04 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/bernoulli.cal,v $
*
* Under source code control: 1991/09/30 11:18:41
@@ -29,12 +29,16 @@
/*
* Calculate the Nth Bernoulli number B(n).
* This uses the following symbolic formula to calculate B(n):
*
* NOTE: This is now a bulitin function.
*
* The non-buildin code used the following symbolic formula to calculate B(n):
*
* (b+1)^(n+1) - b^(n+1) = 0
*
* where b is a dummy value, and each power b^i gets replaced by B(i).
* For example, for n = 3:
*
* (b+1)^4 - b^4 = 0
* b^4 + 4*b^3 + 6*b^2 + 4*b + 1 - b^4 = 0
* 4*b^3 + 6*b^2 + 4*b + 1 = 0
@@ -48,11 +52,14 @@
*/
/*
static Bnmax;
static mat Bn[1001];
*/
define B(n)
{
/*
local nn, np1, i, sum, mulval, divval, combval;
if (!isint(n) || (n < 0))
@@ -85,4 +92,6 @@ define B(n)
}
Bnmax = n;
return Bn[n];
*/
return bernoulli(n);
}

251
cal/chi.cal Normal file
View File

@@ -0,0 +1,251 @@
/*
* chi - chi^2 probabilities with degrees of freedom for null hypothesis
*
* Copyright (C) 2001 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.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: chi.cal,v 29.2 2001/04/08 10:21:23 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/chi.cal,v $
*
* Under source code control: 2001/03/27 14:10:11
* File existed as early as: 2001
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* Z(x)
*
* From Handbook of Mathematical Functions
* 10th printing, Dec 1972 with corrections
* National Bureau of Standards
*
* Section 26.2.1, p931.
*/
define Z(x, eps_term)
{
local eps; /* error term */
/* obtain the error term */
if (isnull(eps_term)) {
eps = epsilon();
} else {
eps = eps_term;
}
/* compute Z(x) value */
return exp(-x*x/2, eps) / sqrt(2*pi(eps), eps);
}
/*
* P(x[, eps]) asymtotic P(x) expansion for x>0 to an given epsilon error term
*
* NOTE: If eps is omitted, the stored epsilon value is used.
*
* From Handbook of Mathematical Functions
* 10th printing, Dec 1972 with corrections
* National Bureau of Standards
*
* 26.2.11, p932:
*
* P(x) = 1/2 + Z(x) * sum(n=0; n < infinity){x^(2*n+1)/(1*3*5*...(2*n+1)};
*
* We continue the fraction until it is less than epsilon error term.
*
* Also note 26.2.5:
*
* P(x) + Q(x) = 1
*/
define P(x, eps_term)
{
local eps; /* error term */
local s; /* sum */
local x2; /* x^2 */
local x_term; /* x^(2*r+1) */
local odd_prod; /* 1*3*5* ... */
local odd_term; /* next odd value to multiply into odd_prod */
local term; /* the recent term added to the sum */
/* obtain the error term */
if (isnull(eps_term)) {
eps = epsilon();
} else {
eps = eps_term;
}
/* firewall */
if (x <= 0) {
if (x == 0) {
return 0; /* hack */
} else {
quit "Q(x[,eps]) 1st argument must be >= 0";
}
}
if (eps <= 0) {
quit "Q(x[,eps]) 2nd argument must be > 0";
}
/*
* aproximate sum(n=0; n < infinity){x^(2*n+1)/(1*3*5*...(2*n+1)}
*/
x2 = x*x;
x_term = x;
s = x_term; /* 1st term */
odd_term = 1;
odd_prod = 1;
do {
/* compute the term */
odd_term += 2;
odd_prod *= odd_term;
x_term *= x2;
term = x_term / odd_prod;
s += term;
} while (term >= eps);
/* apply term and factor */
return 0.5 + Z(x,eps)*s;
}
/*
* chi_prob(chi_sq, v[, eps]) - Prob of >= chi^2 with v degrees of freedom
*
* Computes the Probability, given the Null Hypothesis, that a given
* Chi squared values >= chi_sq with v degrees of freedom.
*
* The chi_prob() function does not work well with odd degrees of freedom.
* It is reasonable with even degrees of freedom, although one must give
* a sifficently small error term as the degress 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
* this odd degrees of freedom case?
*
* NOTE: This function works well with even degrees of freedom. However
* when the even degrees gets large (say, as you approach 100), you
* need to increase your error term.
*
* From Handbook of Mathematical Functions
* 10th printing, Dec 1972 with corrections
* National Bureau of Standards
*
* Section 26.4.4, p941:
*
* For odd v:
*
* Q(chi_sq, v) = 2*Q(chi) + 2*Z(chi) * (
* sum(r=1, r<=(r-1)/2) {(chi_sq^r/chi) / (1*3*5*...(2*r-1)});
*
* chi = sqrt(chi_sq)
*
* NOTE: Q(x) = 1-P(x)
*
* Section 26.4.5, p941.
*
* For even v:
*
* Q(chi_sq, v) = sqrt(2*pi()) * Z(chi) * ( 1 +
* sum(r=1, r=((v-2)/2)) { chi_sq^r / (2*4*...*(2r)) } );
*
* chi = sqrt(chi_sq)
*
* Observe that:
*
* Z(x) = exp(-x*x/2) / sqrt(2*pi()); (Section 26.2.1, p931)
*
* and thus:
*
* sqrt(2*pi()) * Z(chi) =
* sqrt(2*pi()) * Z(sqrt(chi_sq)) =
* sqrt(2*pi()) * exp(-sqrt(chi_sq)*sqrt(chi_sq)/2) / sqrt(2*pi()) =
* exp(-sqrt(chi_sq)*sqrt(chi_sq)/2) =
* exp(-sqrt(-chi_sq/2)
*
* So:
*
* Q(chi_sq, v) = exp(-sqrt(-chi_sq/2) * ( 1 + sum(....){...} );
*/
define chi_prob(chi_sq, v, eps_term)
{
local eps; /* error 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 chi_term; /* chi_sq^r */
local ret; /* return value */
/* obtain the error term */
if (isnull(eps_term)) {
eps = epsilon();
} else {
eps = eps_term;
}
/*
* odd degrees of freedom
*/
if (isodd(v)) {
local chi; /* sqrt(chi_sq) */
/* setup for sum */
s = 1;
d = 1;
chi = sqrt(abs(chi_sq), eps);
chi_term = chi;
r_lim = (v-1)/2;
/* compute sum(r=1, r=((v-1)/2)) {(chi_sq^r/chi) / (1*3*5...*(2r-1))} */
for (r=2; r <= r_lim; ++r) {
chi_term *= chi_sq;
d *= (2*r)-1;
s += chi_term/d;
}
/* apply term and factor, Q(x) = 1-P(x) */
ret = 2*(1-P(chi)) + 2*Z(chi)*s;
/*
* even degrees of freedom
*/
} else {
/* setup for sum */
s =1;
d = 1;
chi_term = 1;
r_lim = (v-2)/2;
/* compute sum(r=1, r=((v-2)/2)) { chi_sq^r / (2*4*...*(2r)) } */
for (r=1; r <= r_lim; ++r) {
chi_term *= chi_sq;
d *= r*2;
s += chi_term/d;
}
/* apply factor - see observation in the main comment above */
ret = exp(-chi_sq/2, eps) * s;
}
return ret;
}

222
cal/intfile.cal Normal file
View File

@@ -0,0 +1,222 @@
/*
* intfile - integer to file and file to integer conversion
*
* Copyright (C) 2001 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.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.5 $
* @(#) $Id: intfile.cal,v 29.5 2001/04/10 22:09:34 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/intfile.cal,v $
*
* Under source code control: 2001/03/31 08:13:11
* File existed as early as: 2001
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* 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)
* will be changed when the subsequent integer is written back.
*/
/*
* file2be - convert a file into an big endian integer
*
* given:
* filename filename to read
*
* returns:
* integer read from its contents on big endian order
*/
define file2be(filename)
{
local fd; /* open file */
local ret; /* integer to return */
local c; /* character read from the file */
local i;
/*
* open the file for reading
*/
fd = fopen(filename, "rb");
if (!isfile(fd)) quit "file2be: cannot open file for reading";
/*
* read the contents of the file
*
* The first octets become the most significant bits of the integer.
*/
ret = 0;
while (! isnull(c = fgetc(fd))) {
ret <<= 8;
ret += ord(c);
}
/*
* cleanup and return the integer
*/
fclose(fd);
return ret;
}
/*
* file2le - convert a file into an little endian integer
*
* given:
* filename filename to read
*
* returns:
* integer read from its contents on little endian order
*/
define file2le(filename)
{
local fd; /* open file */
local ret; /* integer to return */
local c; /* character read from the file */
local shft; /* bit shift for the c value */
local i;
/*
* open the file for reading
*/
fd = fopen(filename, "rb");
if (!isfile(fd)) quit "file2le: cannot open file for reading";
/*
* read the contents of the file into a string
*
* The first octets become are the least significant bits of the integer.
*/
ret = 0;
shft = 0;
while (! isnull(c = fgetc(fd))) {
ret |= (ord(c) << shft);
shft += 8;
}
/*
* cleanup and return the integer
*/
fclose(fd);
return ret;
}
/*
* be2file - convert a big endian integer into a file
*
* given:
* v integer to write to the file
* filename filename to write
*
* returns:
* The number of octets written to the file.
*
* NOTE: The absolute value of the integer is written to the file.
*/
define be2file(v, filename)
{
local fd; /* open file */
local octlen; /* length of v in octets */
local i;
/*
* firewall
*/
if (!isint(v)) {
quit "be2file: 1st arg not an integer";
}
v = abs(v);
/*
* open the file for writing
*/
fd = fopen(filename, "wb");
if (!isfile(fd)) quit "be2file: cannot open file for writing";
/*
* write the octets to the file
*
* The most significant bits of the integer become the first file octets.
*/
octlen = int((highbit(v)+8) / 8);
for (i=octlen-1; i >= 0; --i) {
fputc(fd, char(v >> (i*8)));
}
/*
* cleanup
*/
fclose(fd);
return octlen;
}
/*
* le2file - convert a little endian integer into a file
*
* given:
* v integer to write to the file
* filename filename to write
*
* returns:
* The number of octets written to the file.
*
* NOTE: The absolute value of the integer is written to the file.
*/
define le2file(v, filename)
{
local fd; /* open file */
local cnt; /* octets written */
/*
* firewall
*/
if (!isint(v)) {
quit "be2file: 1st arg not an integer";
}
v = abs(v);
/*
* open the file for writing
*/
fd = fopen(filename, "wb");
if (!isfile(fd)) quit "le2file: cannot open file for writing";
/*
* Write the octets to the file.
*
* The least significant bits of the integer become the first file octets.
*/
cnt = 0;
while (v > 0) {
fputc(fd, char(v));
v >>= 8;
++cnt;
}
/*
* cleanup
*/
fclose(fd);
return cnt;
}

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: lucas.cal,v 29.2 2000/06/07 14:02:25 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: lucas.cal,v 29.3 2001/03/31 13:31:34 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/lucas.cal,v $
*
* Under source code control: 1990/05/03 16:49:51
@@ -1030,7 +1030,7 @@ gen_v1(h, n)
define
ldebug(funct, str)
{
if (config("resource_debug") & 3) {
if (config("resource_debug") & 8) {
print "DEBUG:", funct:":", str;
}
return;

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: lucas_chk.cal,v 29.2 2000/06/07 14:02:25 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: lucas_chk.cal,v 29.3 2001/03/31 13:31:34 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/lucas_chk.cal,v $
*
* Under source code control: 1991/01/11 05:41:43
@@ -336,7 +336,7 @@ lucas_chk(high_n, quiet)
/* skip primes where h>=2^n */
if (highbit(h_p[i]) >= n_p[i]) {
if (config("resource_debug") & 3) {
if (config("resource_debug") & 8) {
print "h>=2^n skip:", h_p[i]:"*2^":n_p[i]:"-1";
}
continue;

View File

@@ -1,24 +1,46 @@
/*
* qtime - Display time as English sentence
*
* Copyright (C) 1999 Klaus Alexander Seistrup and Landon Curt Noll
*
* Written by: Klaus Alexander Seistrup <kseis@magnetic-ink.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
* 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.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.4 $
* @(#) $Id: qtime.cal,v 29.4 2000/12/18 10:18:40 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/qtime.cal,v $
*
* Under source code control: 1999/10/13 04:10:33
* File existed as early as: 1999
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* usage:
* qtime(utc_hr_offset)
*
* utc_hr_offset Offset from UTC in hours.
*
* Written by: Klaus Alexander Seistrup <kseis@magnetic-ink.dk>
* With minor mods by: Landon Curt Noll <http://www.isthe.com/chongo/>
*
* See:
* http://www.magnetic-ink.dk/download/qtime.html
*
* for examples of qtime() written on other languages.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: qtime.cal,v 29.2 2000/06/07 14:02:25 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/qtime.cal,v $
*
* This file is not covered under version 2.1 of the GNU LGPL.
*/

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.3 $
* @(#) $Id: regress.cal,v 29.3 2000/06/07 14:02:25 chongo Exp $
* @(#) $Revision: 29.10 $
* @(#) $Id: regress.cal,v 29.10 2001/04/14 22:53:57 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/regress.cal,v $
*
* Under source code control: 1990/02/15 01:50:36
@@ -411,10 +411,10 @@ define test_config()
'516: config("pow2") == 40');
vrfy(config("redc2") == 50,
'517: config("redc2") == 50');
vrfy(config("tilde") == "true",
'518: config("tilde") == "true"');
vrfy(config("tab") == "true",
'519: config("tab") == "true"');
vrfy(config("tilde"),
'518: config("tilde")');
vrfy(config("tab"),
'519: config("tab")');
vrfy(config("quomod") == 0,
'520: config("quomod") == 0');
vrfy(config("quo") == 2,
@@ -433,10 +433,10 @@ define test_config()
'527: config("outround") == 2');
vrfy(config("round") == 24,
'528: config("round") == 24');
vrfy(config("leadzero") == "false",
'529: config("leadzero") == "false"');
vrfy(config("fullzero") == "false",
'530: config("fullzero") == "false"');
vrfy(config("leadzero") == 0,
'529: config("leadzero") == 0');
vrfy(config("fullzero") == 0,
'530: config("fullzero") == 0');
vrfy(config("maxscan") == 20,
'531: config("maxscan") == 20');
vrfy(config("prompt") == "> ",
@@ -452,10 +452,10 @@ define test_config()
vrfy(config("quo", 0) == 2, '536: config("quo", 0) == 2');
vrfy(config("outround", 24) == 2,
'537: config("outround", 24) == 2');
vrfy(config("leadzero","y") == "false",
'538: config("leadzero","y") == "false"');
vrfy(config("fullzero", 1) == "false",
'539: config("fullzero", 1) == "false"');
vrfy(config("leadzero","y") == 0,
'538: config("leadzero","y") == 0');
vrfy(config("fullzero", 1) == 0,
'539: config("fullzero", 1) == 0');
vrfy(config("prompt", "; ") == "> ",
'540: config("prompt", "; ") == "> "');
vrfy(config("more", ";; ") == ">> ",
@@ -467,14 +467,14 @@ define test_config()
'543: config("all",callcfg) == newcfg');
vrfy(config("display",2) == 20,
'544: config("display",2) == 20');
vrfy(config("fullzero",1) == "false",
'545: config("fullzero",1) == "false"');
vrfy(config("fullzero",1) == 0,
'545: config("fullzero",1) == 0');
vrfy(strprintf("%d %d %d", 0, 1, 2) == ".00 1.00 2.00",
'546: strprintf("%d %d %d", 0, 1, 2) == ".00 1.00 2.00"');
vrfy(config("display",20) == 2,
'547: config("display",20) == 2');
vrfy(config("fullzero",0) == "true",
'548: config("fullzero",0) == "true"');
vrfy(config("fullzero",0),
'548: config("fullzero",0)');
vrfy(strprintf("%d %d %d", 0, 1, 2) == "0 1 2",
'549: strprintf("%d %d %d", 0, 1, 2) == "0 1 2"');
@@ -755,7 +755,7 @@ define test_functions()
vrfy(den(17) == 1, '712: den(17) == 1');
vrfy(den(3/7) == 7, '713: den(3/7) == 7');
vrfy(den(-2/3) == 3, '714: den(-2/3) == 3');
vrfy(digits(0) == 1, '715: digits(0) == 1');
vrfy(digits(0) == 0, '715: digits(0) == 0');
vrfy(digits(9) == 1, '716: digits(9) == 1');
vrfy(digits(10) == 2, '717: digits(10) == 2');
vrfy(digits(-691) == 3, '718: digits(-691) == 3');
@@ -996,8 +996,13 @@ define test_functions()
vrfy(strpos(a, "abc") == 1, '946: strpos(a, "abc") == 1');
vrfy(strpos(a, "xyz") == 0, '947: strpos(a, "xyz") == 0');
vrfy(strpos(a, a) == 1, '948: strpos(a, a) == 1');
vrfy(system("") == 0, '949: system("") == 0');
vrfy(system("true") == 0, '950: system("true") == 0');
if (config("windows")) {
print '949: test skipped for windows systems';
print '950: test skipped for windows systems';
} else {
vrfy(system("") == 0, '949: system("") == 0');
vrfy(system("true") == 0, '950: system("true") == 0');
}
print '951: test disabled due to stdin dependency';
print '952: test removed';
print '953: test removed';
@@ -1029,8 +1034,8 @@ define test_functions()
vrfy(digit(a,-1) == 4, '974: digit(a,-1) == 4');
vrfy(digit(a,-2) == 2, '975: digit(a,-2) == 2');
vrfy(digit(a,-3) == 8, '976: digit(a,-3) == 8');
vrfy(digits(0) == 1, '977: digits(0) == 1');
vrfy(digits(0.0123) == 1, '978: digits(0.0123) == 1');
vrfy(digits(0) == 0, '977: digits(0) == 0');
vrfy(digits(0.0123) == 0, '978: digits(0.0123) == 0');
vrfy(digits(3.7) == 1, '979: digits(3.7) == 1');
vrfy(digits(-27) == 2, '980: digits(-27) == 2');
vrfy(digits(-99.7) == 2, '981: digits(-99.7) == 2');
@@ -1223,7 +1228,85 @@ define test_functions()
vrfy(hnrmod(21<<500+7,3,500,-1) == (21<<500+7)%(3<<500-1),
'1112: hnrmod(21<<500+7,3,500,-1) == (21<<500+7)%(3<<500-1)');
print '1113: Ending test_functions';
/*
* catalan testing
*/
vrfy(catalan(2) == 2, '1113: catalan(2) == 2');
vrfy(catalan(3) == 5, '1114: catalan(3) == 5');
vrfy(catalan(4) == 14, '1115: catalan(4) == 14');
vrfy(catalan(20) == 6564120420, '1116: catalan(20) == 6564120420');
/*
* bernoulli builtin function testing
*/
vrfy(bernoulli(0) == 1, '1117: bernoulli(0) == 1');
vrfy(bernoulli(1) == -1/2, '1118: bernoulli(1) == -1/2');
vrfy(bernoulli(2) == 1/6, '1119: bernoulli(2) == 1/6');
vrfy(bernoulli(3) == 0, '1120: bernoulli(3) == 0');
vrfy(bernoulli(4) == -1/30, '1121: bernoulli(4) == -1/30');
vrfy(bernoulli(5) == 0, '1122: bernoulli(5) == 0');
vrfy(bernoulli(6) == 1/42, '1123: bernoulli(6) == 1/42');
vrfy(bernoulli(32) == -7709321041217/510,
'1124: bernoulli(32) == -7709321041217/510');
/*
* euler function testing
*/
vrfy(euler(0) == 1, '1125: euler(0) == 1');
vrfy(euler(1) == 0, '1126: euler(1) == 0');
vrfy(euler(2) == -1, '1127: euler(2) == -1');
vrfy(euler(3) == 0, '1128: euler(3) == 0');
vrfy(freeeuler() == null(), '1129: freeeuler() == null()');
vrfy(euler(4) == 5, '1130: euler(4) == 5');
vrfy(euler(5) == 0, '1131: euler(5) == 0');
vrfy(euler(6) == -61, '1132: euler(6) == -61');
vrfy(euler(32) == 177519391579539289436664789665,
'1130: euler(32) == 177519391579539289436664789665');
vrfy(freeeuler() == null(), '1133: freeeuler() == null()');
/*
* digit with non-10 base
*/
a = 123456.789;
print '1134: a = 123456.789';
vrfy(digit(a, 6, 100) == 0, '1135: digit(a, 6, 100) == 0');
vrfy(digit(a, 5, 100) == 0, '1136: digit(a, 5, 100) == 0');
vrfy(digit(a, 4, 100) == 0, '1137: digit(a, 4, 100) == 0');
vrfy(digit(a, 3, 100) == 0, '1138: digit(a, 3, 100) == 0');
vrfy(digit(a, 2, 100) == 12, '1139: digit(a, 2, 100) == 12');
vrfy(digit(a, 1, 100) == 34, '1140: digit(a, 1, 100) == 34');
vrfy(digit(a, 0, 100) == 56, '1141: digit(a, 0, 100) == 56');
vrfy(digit(a, -1, 100) == 78, '1142: digit(a, -1, 100) == 78');
vrfy(digit(a, -2, 100) == 90, '1143: digit(a, -2, 100) == 90');
vrfy(digit(a, -3, 100) == 0, '1144: digit(a, -3, 100) == 0');
vrfy(digit(a, -4, 100) == 0, '1145: digit(a, -4, 100) == 0');
vrfy(digit(a, -5, 100) == 0, '1146: digit(a, -5, 100) == 0');
vrfy(digit(a, -6, 100) == 0, '1146: digit(a, -6, 100) == 0');
/*
* digits with a non-10 base
*/
vrfy(digits(a, 100) == 3, '1147: digits(a, 100) == 3');
vrfy(digits(2^256-1, 256) == 32,'1148: digits(2^256-1, 256) == 32');
/*
* places with a non-10 base
*/
vrfy(places(0.0123, 2) == -1, '1149: places(0.0123, 2) == -1');
vrfy(places(0.625, 2) == 3, '1150: places(0.625, 2) == 3');
vrfy(places(0.625, 8) == 1, '1151: places(0.625, 8) == 1');
vrfy(places(171/2^712, 2) == 712,
'1152: places(171/2^7120.625, 2) == 712');
vrfy(places(171/2^712, 64) == 119,
'1152: places(171/2^7120.625, 64) == 119');
/*
* verify sleep
*/
vrfy(sleep(1/5) == null(), '1153: sleep(1/5) == null()');
vrfy(sleep(1) == null(), '1154: sleep(1) == null()');
print '1155: Ending test_functions';
}
print '017: parsed test_functions()';
@@ -1484,31 +1567,31 @@ define test_rand()
/* test the additive 55 shuffle generator */
tmp = srand(0);
print '1505: tmp = srand(0)';
vrfy(rand() == 0xc79ef743e2e6849c, \
'1506: rand() == 0xc79ef743e2e6849c');
vrfy(rand() == 0x8d2dcb2bed321284, \
'1507: rand() == 0x8d2dcb2bed321284');
vrfy(rand() == 0x1fe5b46fba7e069d, \
'1506: rand() == 0x1fe5b46fba7e069d');
vrfy(rand() == 0x308d32d9bdf2dc6f, \
'1507: rand() == 0x308d32d9bdf2dc6f');
tmp = srand(init);
print '1508: tmp = srand(init)';
vrfy(rand() == 0xc79ef743e2e6849c, \
'1509: rand() == 0xc79ef743e2e6849c');
vrfy(rand() == 0x8d2dcb2bed321284, \
'1510: rand() == 0x8d2dcb2bed321284');
vrfy(rand() == 0x1fe5b46fba7e069d, \
'1509: rand() == 0x1fe5b46fba7e069d');
vrfy(rand() == 0x308d32d9bdf2dc6f, \
'1510: rand() == 0x308d32d9bdf2dc6f');
/* test range interface */
tmp = srand(0);
print '1511: tmp = srand(0)';
vrfy(rand(12345678901234567890) == 0x8d2dcb2bed321284, \
'1512: rand(12345678901234567890) == 0x8d2dcb2bed321284');
vrfy(rand(216091) == 0x13d2b, '1513: rand(216091) == 0x13d2b');
vrfy(rand(100) == 0x26, '1514: rand(100) == 0x26');
vrfy(rand(-46,46) == -0xf, '1515: rand(-46,46) == -0xf');
vrfy(rand(12345678901234567890) == 0x1fe5b46fba7e069d, \
'1512: rand(12345678901234567890) == 0x1fe5b46fba7e069d');
vrfy(rand(216091) == 0xc234, '1513: rand(216091) == 0xc234');
vrfy(rand(100) == 0x59, '1514: rand(100) == 0x59');
vrfy(rand(-46,46) == 0x2d, '1515: rand(-46,46) == 0x2d');
tmp = srand(0);
print '1516: tmp = srand(0)';
vrfy(rand(2^64) == 0xc79ef743e2e6849c, \
'1517: rand(2^64) == 0xc79ef743e2e6849c');
vrfy(rand(0,2^64) == 0x8d2dcb2bed321284, \
'1518: rand(0,2^64) == 0x8d2dcb2bed321284');
vrfy(rand(2^64) == 0x1fe5b46fba7e069d, \
'1517: rand(2^64) == 0x1fe5b46fba7e069d');
vrfy(rand(0,2^64) == 0x308d32d9bdf2dc6f, \
'1518: rand(0,2^64) == 0x308d32d9bdf2dc6f');
/* test different forms of seeding the initial state */
tmp = srand(0);
@@ -1516,7 +1599,7 @@ define test_rand()
vrfy(srand() == init, '1520: srand() == init');
tmp = srand(0x87e6ec938ff55aa5<<64);
print '1521: tmp = srand(0x87e6ec938ff55aa5<<64)';
vrfy(srand() == init, '1522: srand() == init');
print '1522: test disabled';
tmp = srand(state0);
print '1523: tmp = srand(state0)';
vrfy(srand() == init, '1524: srand() == init');
@@ -1528,35 +1611,35 @@ define test_rand()
/* test the bit length interface */
tmp = srand(0);
print '1528: tmp = srand(0)';
vrfy(randbit(64) == 0xc79ef743e2e6849c, \
'1529: randbit(64) == 0xc79ef743e2e6849c');
vrfy(randbit(128) == 0x8d2dcb2bed3212844f4ad31f3818af34, \
'1530: randbit(128) == 0x8d2dcb2bed3212844f4ad31f3818af34');
vrfy(randbit(64) == 0x23a252f60bae4907, \
'1531: randbit(64) == 0x23a252f60bae4907');
vrfy(randbit(128) == 0xa8ed5b6203e2b1da32848cd9b3f1e3fa, \
'1532: randbit(128) == 0xa8ed5b6203e2b1da32848cd9b3f1e3fa');
vrfy(randbit(64) == 0x1fe5b46fba7e069d, \
'1529: randbit(64) == 0x1fe5b46fba7e069d');
vrfy(randbit(128) == 0x308d32d9bdf2dc6f45d3e3b3361b79e4, \
'1530: randbit(128) == 0x308d32d9bdf2dc6f45d3e3b3361b79e4');
vrfy(randbit(64) == 0xd4ef1e3336022d81, \
'1531: randbit(64) == 0xd4ef1e3336022d81');
vrfy(randbit(128) == 0x66b086e6c34e42124a1fc5d4e5c6f598, \
'1532: randbit(128) == 0x66b086e6c34e42124a1fc5d4e5c6f598');
tmp = srand(0);
print '1533: tmp = srand(0)';
vrfy(randbit(32) == 0xc79ef743, '1534: randbit(32) == 0xc79ef743');
vrfy(randbit(32) == 0xe2e6849c, '1535: randbit(32) == 0xe2e6849c');
vrfy(randbit(1) == 0x1, '1536: randbit(1) == 0x1');
vrfy(randbit(5) == 0x3, '1537: randbit(5) == 0x3');
vrfy(randbit(33) == 0x96e595f6, '1538: randbit(33) == 0x96e595f6');
vrfy(randbit(25) == 0x1321284, '1539: randbit(25) == 0x1321284');
vrfy(randbit(32) == 0x1fe5b46f, '1534: randbit(32) == 0x1fe5b46f');
vrfy(randbit(32) == 0xba7e069d, '1535: randbit(32) == 0xba7e069d');
vrfy(randbit(1) == 0x0, '1536: randbit(1) == 0x0');
vrfy(randbit(5) == 0xc, '1537: randbit(5) == 0xc');
vrfy(randbit(33) == 0x46996cde, '1538: randbit(33) == 0x46996cde');
vrfy(randbit(25) == 0x1f2dc6f, '1539: randbit(25) == 0x1f2dc6f');
vrfy(randbit(2) == 0x1, '1540: randbit(2) == 0x1');
vrfy(randbit(13) == 0x7a5, '1541: randbit(13) == 0x7a5');
vrfy(randbit(18) == 0x1a63e, '1542: randbit(18) == 0x1a63e');
vrfy(randbit(8) == 0x70, '1543: randbit(8) == 0x70');
vrfy(randbit(9) == 0x62, '1544: randbit(9) == 0x62');
vrfy(randbit(70) == 0x2f3423a252f60bae49, \
'1545: randbit(70) == 0x2f3423a252f60bae49');
vrfy(randbit(13) == 0x2e9, '1541: randbit(13) == 0x2e9');
vrfy(randbit(18) == 0x3c766, '1542: randbit(18) == 0x3c766');
vrfy(randbit(8) == 0x6c, '1543: randbit(8) == 0x6c');
vrfy(randbit(9) == 0x6d, '1544: randbit(9) == 0x6d');
vrfy(randbit(70) == 0x39e4d4ef1e3336022d, \
'1545: randbit(70) == 0x39e4d4ef1e3336022d');
print '1546: test unused';
vrfy(randbit(8) == 0x7, '1547: randbit(8) == 0x7');
vrfy(randbit(65) == 0x151dab6c407c563b4, \
'1548: randbit(65) == 0x151dab6c407c563b4');
vrfy(randbit(63) == 0x32848cd9b3f1e3fa, \
'1549: randbit(63) == 0x32848cd9b3f1e3fa');
vrfy(randbit(8) == 0x81, '1547: randbit(8) == 0x81');
vrfy(randbit(65) == 0xcd610dcd869c8424, \
'1548: randbit(65) == 0xcd610dcd869c8424');
vrfy(randbit(63) == 0x4a1fc5d4e5c6f598, \
'1549: randbit(63) == 0x4a1fc5d4e5c6f598');
/* check to be sure that the srand(1) bug was fixed */
tmp = srand(1);
@@ -1565,36 +1648,36 @@ define test_rand()
print '1551: n = 1';
vrfy(num(n), '1552: num(n)');
vrfy(den(n), '1553: den(n)');
vrfy(randbit(64) == 0x4280429f8069cb27, \
'1554: randbit(64) == 0x4280429f8069cb27');
vrfy(randbit(64) == 0xbf989a4c504a541d, \
'1554: randbit(64) == 0xbf989a4c504a541d');
/* test randbit skip interface */
tmp = srand(0);
print '1555: tmp = srand(0)';
vrfy(randbit(20) == 817647, '1556: randbit(20) == 817647');
vrfy(randbit(20) == 476130, '1557: randbit(20) == 476130');
vrfy(randbit(20) == 944201, '1558: randbit(20) == 944201');
vrfy(randbit(20) == 822573, '1559: randbit(20) == 822573');
vrfy(randbit(20) == 0x1fe5b, '1556: randbit(20) == 0x1fe5b');
vrfy(randbit(20) == 0x46fba, '1557: randbit(20) == 0x46fba');
vrfy(randbit(20) == 0x7e069, '1558: randbit(20) == 0x7e069');
vrfy(randbit(20) == 0xd308d, '1559: randbit(20) == 0xd308d');
tmp = srand(0);
print '1560: tmp = srand(0)';
vrfy(randbit(-20) == 20, '1561: randbit(-20) == 20');
vrfy(randbit(20) == 476130, '1562: randbit(20) == 476130');
vrfy(randbit(20) == 290746, '1562: randbit(20) == 290746');
vrfy(randbit(-20) == 20, '1563: randbit(-20) == 20');
vrfy(randbit(20) == 822573, '1564: randbit(20) == 822573');
vrfy(randbit(20) == 864397, '1564: randbit(20) == 864397');
/* test randbit without and arg */
tmp = srand(0);
print '1565: tmp = srand(0)';
vrfy(randbit() == 1, '1566: randbit() == 1');
vrfy(randbit() == 1, '1567: randbit() == 1');
vrfy(randbit() == 0, '1566: randbit() == 0');
vrfy(randbit() == 0, '1567: randbit() == 0');
vrfy(randbit() == 0, '1568: randbit() == 0');
vrfy(randbit() == 1, '1569: randbit() == 1');
/* test seed() as best as we can */
vrfy(seed() >= 0, '1569: seed() >= 0');
vrfy(seed() < 2^64, '1570: seed() < 2^64');
vrfy(isrand(srand(seed())), '1571: isrand(srand(seed()))');
vrfy(seed() >= 0, '1570: seed() >= 0');
vrfy(seed() < 2^64, '1571: seed() < 2^64');
vrfy(isrand(srand(seed())), '1572: isrand(srand(seed()))');
print '1572: Ending rand test';
print '1573: Ending rand test';
}
print '025: parsed test_rand()';
@@ -2987,7 +3070,7 @@ define test_error()
vrfy(root(3,2,0) == error(10029),
'3644: root(3,2,0) == error(10029)');
vrfy(norm("x") == error(10030), '3645: norm("x") == error(10030)');
vrfy(null() << 2 == error(10031),'3646: null() << 2 == error(10031)');
vrfy(list() << 2 == error(10031),'3646: list() << 2 == error(10031)');
vrfy(1.5 << 2 == error(10031), '3647: 1.5 << 2 == error(10031)');
vrfy(3 << "x" == error(10032), '3648: 3 << "x" == error(10032)');
vrfy(3 << 1.5 == error(10032), '3649: 3 << 1.5 == error(10032)');
@@ -5034,10 +5117,17 @@ define test_is()
*/
a = assoc();
print '5901: a = assoc()';
ofd = fopen("/dev/null", "r");
print '5902: ofd = fopen("/dev/null", "r")';
cfd = fopen("/dev/null", "r");
print '5903: cfd = fopen("/dev/null", "r")';
if (config("windows")) {
ofd = fopen("NUL:", "rb");
print '5902: ofd = fopen("NUL:", "rb")';
cfd = fopen("NUL:", "rb");
print '5903: cfd = fopen("NUL:", "rb")';
} else {
ofd = fopen("/dev/null","rb");
print '5902: ofd = fopen("/dev/null","rb")';
cfd = fopen("/dev/null","rb");
print '5903: cfd = fopen("/dev/null","rb")';
}
fclose(cfd);
print '5904: fclose(cfd)';
blk = blk();
@@ -6215,8 +6305,8 @@ define test_blkcpy()
/* blkcpy the last 5 octets of B1 to a new block C */
blkcpy(C = blk(), B1, 5, ,100);
print '6821: blkcpy(C = blk(), B1, 5, ,100);';
blkcpy(C = blk(), B1,5,,100);
print '6821: blkcpy(C = blk(), B1,5,,100);';
vrfy(C == A, '6822: C == A');
/* blkcpy to and from a file */
@@ -6232,8 +6322,8 @@ define test_blkcpy()
blkcpy(fs, A, ,100);
print '6828: blkcpy(fs, A, ,100);';
vrfy(size(fs) == 105, '6829: size(f) == 105');
blkcpy(C = blk(), fs, 2, ,100);
print '6830: blkcpy(C = blk(), fs, 2, ,100)';
blkcpy(C = blk(), fs,2,,100);
print '6830: blkcpy(C = blk(), fs,2,,100)';
vrfy(C == (blk() = {1,2}), '6831: C == (blk() = {1,2}');
/* blkcpy string to a block */
@@ -7515,7 +7605,9 @@ vrfy(j8300(10) == 11, '8307: j8300(10) == 11');
{static k8300 = 5} define l8300(x) = k8300 + x;
print '8308: {static k8300 = 5} define l8300(x) = k8300 + x;';
vrfy(l8300(10) == 15, '8309: l8300(10) == 15');
print '8310: Ending define tests';
static a8300 = 1, b8300;
vrfy(a8300 == 1, '8310: a8300 == 1');
print '8311: Ending define tests';
/*
@@ -7538,6 +7630,15 @@ read -once "test8500";
/* 85xx: Ending test_divmod is printed by test8500.cal */
/*
* test_maxargs - test up to 1024 args being passed to a builtin function
*/
print;
print '8600: Starting test_1024args'
read -once "test8600";
/* 86xx: Ending test_1024args is printed by test8600.cal */
/*
* read various calc resource files
*

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: seedrandom.cal,v 29.2 2000/06/07 14:02:25 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: seedrandom.cal,v 29.3 2001/03/31 13:31:34 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/seedrandom.cal,v $
*
* Under source code control: 1996/01/01 08:21:00
@@ -115,7 +115,7 @@ define seedrandom(seed1, seed2, size, trials)
p = 2*fp+1;
} while (ptest(p,1,0) == 0);
} while(ptest(p, trials) == 0 || ptest(fp, trials) == 0);
if (config("resource_debug") & 3) {
if (config("resource_debug") & 8) {
print "/* 1st Blum prime */ p=", p;
}
@@ -129,7 +129,7 @@ define seedrandom(seed1, seed2, size, trials)
q = 2*fq+1;
} while (ptest(q,1,0) == 0);
} while(ptest(q, trials) == 0 || ptest(fq, trials) == 0);
if (config("resource_debug") & 3) {
if (config("resource_debug") & 8) {
print "/* 2nd Blum prime */ q=", q;
}
@@ -139,7 +139,7 @@ define seedrandom(seed1, seed2, size, trials)
n = p*q; /* the Blum modulus */
binsize = highbit(n)+1; /* smallest power of 2 > p*q */
r = pmod(rand(1<<ceil(binsize*4/5), 1<<(binsize-2)), 2, n);
if (config("resource_debug") & 3) {
if (config("resource_debug") & 8) {
print "/* seed quadratic residue */ r=", r;
print "/* newn", binsize, "bit quadratic residue*/ newn=", n;
}

View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: test4600.cal,v 29.2 2000/06/07 14:02:25 chongo Exp $
* @(#) $Revision: 29.4 $
* @(#) $Id: test4600.cal,v 29.4 2001/04/10 22:09:02 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/test4600.cal,v $
*
* Under source code control: 1996/07/02 20:04:40
@@ -53,10 +53,10 @@ define stest(str, verbose)
/*
* do file operations
*/
f = fopen("junk4600", "w");
f = fopen("junk4600", "wb");
if (iserror(f)) {
print 'failed';
print '**** fopen("junk4600", "w") failed';
print '**** fopen("junk4600", "wb") failed';
return 1;
}
if (iserror(fputs(f,
@@ -67,9 +67,9 @@ define stest(str, verbose)
print '**** fputs(f, "Fourscore ... failed';
return 1;
}
if (iserror(freopen(f, "r"))) {
if (iserror(freopen(f, "rb"))) {
print 'failed';
print '**** iserror(freopen(f, "r")) failed';
print '**** iserror(freopen(f, "rb")) failed';
return 1;
}
if (iserror(rewind(f))) {
@@ -173,7 +173,7 @@ define ttest(str, m, n, verbose)
print str:":",:;
}
i = rm("-f", "junk4600");
f = fopen("junk4600", "w");
f = fopen("junk4600", "wb");
if (isnull(n))
n = 4;
@@ -198,7 +198,7 @@ define ttest(str, m, n, verbose)
fflush(f);
if (verbose > 1)
printf("File has size %d\n", pos[i]);
freopen(f, "r");
freopen(f, "rb");
if (size(f) != pos[i]) {
print 'failed';
printf("**** Failure 1 for file size\n");

1406
cal/test8600.cal Normal file

File diff suppressed because it is too large Load Diff

935
calc.c

File diff suppressed because it is too large Load Diff

251
calc.h
View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.3 $
* @(#) $Id: calc.h,v 29.3 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.6 $
* @(#) $Id: calc.h,v 29.6 2001/03/17 21:31:47 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/calc.h,v $
*
* Under source code control: 1990/02/15 01:48:31
@@ -32,9 +32,8 @@
#define __CALC_H__
#include <setjmp.h>
#include "win32dll.h"
#include "value.h"
#include "have_const.h"
@@ -60,10 +59,9 @@
#define MAXERROR 512 /* maximum length of error message string */
#define SYMBOLSIZE 256 /* maximum symbol name size */
#define MAXINDICES 20 /* maximum number of indices for objects */
#define MAXLABELS 100 /* maximum number of user labels in function */
#define MAXSTRING 1024 /* maximum size of string constant */
#define MAXSTACK 1000 /* maximum depth of evaluation stack */
#define MAXSTACK 2048 /* maximum depth of evaluation stack */
#define MAXFILES 20 /* maximum number of opened files */
#define PROMPT1 "> " /* default normal prompt*/
#define PROMPT2 ">> " /* default prompt inside multi-line input */
@@ -95,152 +93,157 @@
/*
* File I/O routines.
*/
extern FILEID openid(char *name, char *mode);
extern FILEID indexid(long index);
extern BOOL validid(FILEID id);
extern BOOL errorid(FILEID id);
extern BOOL eofid(FILEID id);
extern int closeid(FILEID id);
extern int getcharid(FILEID id);
extern int idprintf(FILEID id, char *fmt, int count, VALUE **vals);
extern int idfputc(FILEID id, int ch);
extern int idfputs(FILEID id, char *str);
extern int printid(FILEID id, int flags);
extern int flushid(FILEID id);
extern int readid(FILEID id, int flags, char **retptr);
extern int getloc(FILEID id, ZVALUE *loc);
extern int setloc(FILEID id, ZVALUE zpos);
extern int getsize(FILEID id, ZVALUE *size);
extern int get_device(FILEID id, ZVALUE *dev);
extern int get_inode(FILEID id, ZVALUE *ino);
extern FILEID reopenid(FILEID id, char *mode, char *name);
extern int closeall(void);
extern int flushall(void);
extern int idfputstr(FILEID id, char *str);
extern int rewindid(FILEID id);
extern void rewindall(void);
extern ZVALUE zfilesize(FILEID id);
extern void showfiles(void);
extern int fscanfid(FILEID id, char *fmt, int count, VALUE **vals);
extern int scanfstr(char *str, char *fmt, int count, VALUE **vals);
extern int ftellid(FILEID id, ZVALUE *res);
extern int fseekid(FILEID id, ZVALUE offset, int whence);
extern int isattyid(FILEID id);
extern int fsearch(FILEID id, char *str, ZVALUE start, ZVALUE end, ZVALUE *res);
extern int frsearch(FILEID id, char *str, ZVALUE first, ZVALUE last, ZVALUE *res);
extern void showconstants(void);
extern void freeconstant(unsigned long);
extern void freestringconstant(long);
extern void trimconstants(void);
extern DLL FILEID openid(char *name, char *mode);
extern DLL FILEID indexid(long index);
extern DLL BOOL validid(FILEID id);
extern DLL BOOL errorid(FILEID id);
extern DLL BOOL eofid(FILEID id);
extern DLL int closeid(FILEID id);
extern DLL int getcharid(FILEID id);
extern DLL int idprintf(FILEID id, char *fmt, int count, VALUE **vals);
extern DLL int idfputc(FILEID id, int ch);
extern DLL int idfputs(FILEID id, char *str);
extern DLL int printid(FILEID id, int flags);
extern DLL int flushid(FILEID id);
extern DLL int readid(FILEID id, int flags, char **retptr);
extern DLL int getloc(FILEID id, ZVALUE *loc);
extern DLL int setloc(FILEID id, ZVALUE zpos);
extern DLL int getsize(FILEID id, ZVALUE *size);
extern DLL int get_device(FILEID id, ZVALUE *dev);
extern DLL int get_inode(FILEID id, ZVALUE *ino);
extern DLL FILEID reopenid(FILEID id, char *mode, char *name);
extern DLL int closeall(void);
#if !defined(_WIN32)
extern DLL int flushall(void);
#endif
extern DLL int idfputstr(FILEID id, char *str);
extern DLL int rewindid(FILEID id);
extern DLL void rewindall(void);
extern DLL ZVALUE zfilesize(FILEID id);
extern DLL void showfiles(void);
extern DLL int fscanfid(FILEID id, char *fmt, int count, VALUE **vals);
extern DLL int scanfstr(char *str, char *fmt, int count, VALUE **vals);
extern DLL int ftellid(FILEID id, ZVALUE *res);
extern DLL int fseekid(FILEID id, ZVALUE offset, int whence);
extern DLL int isattyid(FILEID id);
extern DLL int fsearch(FILEID id, char *str, ZVALUE start, ZVALUE end, ZVALUE *res);
extern DLL int frsearch(FILEID id, char *str, ZVALUE first, ZVALUE last, ZVALUE *res);
extern DLL void showconstants(void);
extern DLL void freeconstant(unsigned long);
extern DLL void freestringconstant(long);
extern DLL void trimconstants(void);
/*
* Input routines.
*/
extern int openstring(char *str, long num);
extern int openterminal(void);
extern int opensearchfile(char *name, char *pathlist, char *exten, int reopen_ok);
extern char *nextline(void);
extern int nextchar(void);
extern void reread(void);
extern void resetinput(void);
extern void setprompt(char *);
extern BOOL inputisterminal(void);
extern int inputlevel(void);
extern long calclevel(void);
extern char *inputname(void);
extern long linenumber(void);
extern void runrcfiles(void);
extern void closeinput(void);
extern DLL int openstring(char *str, long num);
extern DLL int openterminal(void);
extern DLL int opensearchfile(char *name, char *pathlist, char *exten, int reopen_ok);
extern DLL char *nextline(void);
extern DLL int nextchar(void);
extern DLL void reread(void);
extern DLL void resetinput(void);
extern DLL void setprompt(char *);
extern DLL BOOL inputisterminal(void);
extern DLL int inputlevel(void);
extern DLL long calclevel(void);
extern DLL char *inputname(void);
extern DLL long linenumber(void);
extern DLL void runrcfiles(void);
extern DLL void closeinput(void);
/*
* Other routines.
*/
extern NUMBER *constvalue(unsigned long index);
extern long addnumber(char *str);
extern long addqconstant(NUMBER *q);
extern void initstack(void);
extern void getcommands(BOOL toplevel);
extern void givehelp(char *type);
extern void libcalc_call_me_first(void);
extern void libcalc_call_me_last(void);
extern BOOL calc_tty(int fd);
extern BOOL orig_tty(int fd);
extern void showerrors(void);
extern char *calc_strdup(CONST char *);
extern void getshellfile(char *shellfile);
extern DLL NUMBER *constvalue(unsigned long index);
extern DLL long addnumber(char *str);
extern DLL long addqconstant(NUMBER *q);
extern DLL void initstack(void);
extern DLL void getcommands(BOOL toplevel);
extern DLL void givehelp(char *type);
extern DLL void libcalc_call_me_first(void);
extern DLL void libcalc_call_me_last(void);
extern DLL BOOL calc_tty(int fd);
extern DLL BOOL orig_tty(int fd);
extern DLL void showerrors(void);
extern DLL char *calc_strdup(CONST char *);
/*
* Initialization
*/
extern void initialize(void);
extern void reinitialize(void);
extern int isatty(int tty); /* TRUE if fd is a tty */
extern char *version(void); /* return version string */
extern int post_init; /* TRUE => setjmp for math_error is ready */
extern DLL void initialize(void);
extern DLL void reinitialize(void);
#if !defined (_WIN32)
extern DLL int isatty(int tty); /* TRUE if fd is a tty */
#endif
extern DLL char *version(void); /* return version string */
extern DLL int post_init; /* TRUE => math_error setjmp is ready */
/*
* global flags and definitions
*/
extern int abortlevel; /* current level of aborts */
extern BOOL inputwait; /* TRUE if in a terminal input wait */
extern jmp_buf jmpbuf; /* for errors */
extern DLL int abortlevel; /* current level of aborts */
extern DLL BOOL inputwait; /* TRUE if in a terminal input wait */
extern DLL jmp_buf jmpbuf; /* for errors */
extern int p_flag; /* TRUE => pipe mode */
extern int q_flag; /* TRUE => don't execute rc files */
extern int u_flag; /* TRUE => unbuffer stdin and stdout */
extern int d_flag; /* TRUE => disable heading, resource_debug */
extern int c_flag; /* TRUE => continue after error if permitted */
extern int i_flag; /* TRUE => try to go interactive after error */
extern int s_flag; /* TRUE => keep args as strings for argv() */
extern int stoponerror; /* >0 => stop, <0 => continue, ==0 => use -c */
extern BOOL abort_now; /* TRUE => try to go interactive */
extern DLL int p_flag; /* TRUE => pipe mode */
extern DLL int q_flag; /* TRUE => don't execute rc files */
extern DLL int u_flag; /* TRUE => unbuffer stdin and stdout */
extern DLL int d_flag; /* TRUE => disable heading, resource_debug */
extern DLL int c_flag; /* TRUE => continue after error if permitted */
extern DLL int i_flag; /* TRUE => try to go interactive after error */
extern DLL int s_flag; /* TRUE => keep args as strings for argv() */
extern DLL int stoponerror; /* >0 => stop, <0 => continue, ==0 => use -c */
extern DLL BOOL abort_now; /* TRUE => try to go interactive */
extern int argc_value; /* count of argv[] strings for argv() builtin */
extern char **argv_value; /* argv[] strings for argv() builtin */
extern DLL int argc_value; /* count of argv[] strings for argv() builtin */
extern DLL char **argv_value; /* argv[] strings for argv() builtin */
extern char *pager; /* $PAGER or default */
extern int stdin_tty; /* TRUE if stdin is a tty */
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 DLL char *pager; /* $PAGER or default */
extern DLL int stdin_tty; /* TRUE if stdin is a tty */
extern DLL int havecommands; /* TRUE if have cmd args) */
extern DLL char *program; /* our name */
extern DLL char *base_name; /* basename of our name */
extern DLL char cmdbuf[]; /* command line expression */
extern int abortlevel; /* current level of aborts */
extern BOOL inputwait; /* TRUE if in a terminal input wait */
extern VALUE *stack; /* execution stack */
extern int dumpnames; /* TRUE => dump names rather than indices */
extern DLL int abortlevel; /* current level of aborts */
extern DLL BOOL inputwait; /* TRUE if in a terminal input wait */
extern DLL VALUE *stack; /* execution stack */
extern DLL int dumpnames; /* TRUE => dump names rather than indices */
extern char *calcpath; /* $CALCPATH or default */
extern char *calcrc; /* $CALCRC or default */
extern char *calcbindings; /* $CALCBINDINGS or default */
extern char *home; /* $HOME or default */
extern char *shell; /* $SHELL or default */
extern char *program; /* our name (argv[0]) */
extern DLL char *calcpath; /* $CALCPATH or default */
extern DLL char *calcrc; /* $CALCRC or default */
extern DLL char *calcbindings; /* $CALCBINDINGS or default */
extern DLL char *home; /* $HOME or default */
extern DLL char *shell; /* $SHELL or default */
extern DLL char *program; /* our name (argv[0]) */
extern int no_env; /* TRUE (-e) => ignore env vars on startup */
extern int errmax; /* if >= 0, error when errcount exceeds errmax */
extern int new_std; /* TRUE (-n) => use newstd configuration */
extern DLL int no_env; /* TRUE (-e) => ignore env vars on startup */
extern DLL int errmax; /* if >= 0, error when errcount exceeds errmax */
extern DLL int new_std; /* TRUE (-n) => use newstd configuration */
extern int allow_read; /* FALSE => may not open any files for reading */
extern int allow_write; /* FALSE => may not open any files for writing */
extern int allow_exec; /* FALSE => may not execute any commands */
extern DLL int allow_read; /* FALSE => dont open any files for reading */
extern DLL int allow_write; /* FALSE => dont open any files for writing */
extern DLL int allow_exec; /* FALSE => may not execute any commands */
/*
* calc startup and run state
*/
typedef enum {
RUN_UNKNOWN = -1, /* unknown or unset start state */
RUN_BEGIN = 0, /* calc execution starts */
RUN_RCFILES = 1, /* rc files being evaluated */
RUN_PRE_CMD_ARGS = 2, /* prepare to evaluate cmd args */
RUN_CMD_ARGS = 3, /* cmd args being evaluated */
RUN_PRE_TOP_LEVEL = 4, /* prepare to start top level activity */
RUN_TOP_LEVEL = 5, /* running at top level */
RUN_EXIT = 6, /* normal exit from calc */
RUN_EXIT_WITH_ERROR = 7 /* exit with error */
RUN_ZERO, /* unknown or unset start state */
RUN_BEGIN, /* calc execution starts */
RUN_RCFILES, /* rc files being evaluated */
RUN_PRE_CMD_ARGS, /* prepare to evaluate cmd args */
RUN_CMD_ARGS, /* cmd args being evaluated */
RUN_PRE_TOP_LEVEL, /* prepare to start top level activity */
RUN_TOP_LEVEL, /* running at top level */
RUN_EXIT, /* normal exit from calc */
RUN_EXIT_WITH_ERROR /* exit with error */
} run;
extern run run_state;
extern char *run_state_name(run state);
extern DLL run run_state;
extern DLL char *run_state_name(run state);
/*
* calc version information
@@ -251,7 +254,7 @@ extern int calc_minor_ver;
extern int calc_major_patch;
extern char *calc_minor_patch;
extern char *Copyright;
extern char *version(void);
extern DLL char *version(void);
#endif /* !__CALC_H__ */

View File

@@ -15,8 +15,8 @@
.\" received a copy with calc; if not, write to Free Software Foundation, Inc.
.\" 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
.\"
.\" @(#) $Revision: 29.5 $
.\" @(#) $Id: calc.man,v 29.5 2000/06/07 14:02:13 chongo Exp $
.\" @(#) $Revision: 29.6 $
.\" @(#) $Id: calc.man,v 29.6 2001/04/10 21:48:46 chongo Exp $
.\" @(#) $Source: /usr/local/src/cmd/calc/RCS/calc.man,v $
.\"
.\" Under source code control: 1991/07/23 05:48:26
@@ -36,20 +36,21 @@ calc \- arbitrary precision calculator
.RB [ \-c ]
.RB [ \-C ]
.RB [ \-d ]
.RB [ -D\ \&calc_debug[:resource_debug[:user_debug]] ]
.br
.in +5n
.RB [ -D\ \&calc_debug[:resource_debug[:user_debug]] ]
.br
.RB [ \-e ]
.RB [ \-h ]
.RB [ \-i ]
.RB [ \-m\ \&mode ]
.RB [ \-n ]
.br
.RB [ \-p ]
.RB [ \-q ]
.RB [ \-s ]
.RB [ \-u ]
.RB [ \-v ]
.br
.RB [ calc_cmd\ \&.\|.\|. ]
.in -5n
.sp

View File

@@ -17,8 +17,8 @@
# received a copy with calc; if not, write to Free Software Foundation, Inc.
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
# @(#) $Revision: 29.2 $
# @(#) $Id: calcerr.tbl,v 29.2 2000/06/07 14:02:13 chongo Exp $
# @(#) $Revision: 29.4 $
# @(#) $Id: calcerr.tbl,v 29.4 2001/04/10 22:06:46 chongo Exp $
# @(#) $Source: /usr/local/src/cmd/calc/RCS/calcerr.tbl,v $
#
# Under source code control: 1996/05/23 17:38:44
@@ -108,8 +108,8 @@ E_FGETSTR1 Non-file first argument for fgetstr
E_FGETSTR2 File not open for reading for fgetstr
E_FGETLINE1 Non-file argument for fgetline
E_FGETLINE2 File not open for reading for fgetline
E_FGETWORD1 Non-file argument for fgetword
E_FGETWORD2 File not open for reading for fgetword
E_FGETFIELD1 Non-file argument for fgetfield
E_FGETFIELD2 File not open for reading for fgetfield
E_REWIND1 Non-file argument for rewind
E_FILES Non-integer argument for files
E_PRINTF1 Non-string fmt argument for fprint
@@ -375,3 +375,21 @@ E_GD3 Infinite or too-large result for gd
E_AGD3 Infinite or too-large result for agd
E_POWER4 Too-large value for power
E_ROOT4 Too-large value for root
E_DGT1 Non-real first arg for digit
E_DGT2 Non-integral second arg for digit
E_DGT3 Bad third arg for digit
E_PLCS1 Bad first argument for places
E_PLCS2 Bad second argument for places
E_DGTS1 Bad first argument for digits
E_DGTS2 Bad second argument for digits
E_ILOG Bad first argument for ilog
E_ILOGB Bad second argument for ilog
E_ILOG10 Bad argument for ilog10
E_ILOG2 Bad argument for ilog2
E_COMB1 Non-integer second arg for comb
E_COMB2 Too-large second arg for comb
E_CTLN Bad argument for catalan
E_BERN Bad argument for bern
E_EULER Bad argument for euler
E_SLEEP Bad argument for sleep
E_TTY calc_tty failure

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: cmath.h,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: cmath.h,v 29.3 2000/07/17 15:35:49 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/cmath.h,v $
*
* Under source code control: 1993/07/30 19:42:45
@@ -83,6 +83,7 @@ extern BOOL ccmp(COMPLEX *c1, COMPLEX *c2);
* More complicated functions.
*/
extern COMPLEX *cpowi(COMPLEX *c, NUMBER *q);
extern NUMBER *cilog(COMPLEX *c, ZVALUE base);
/*

430
codegen.c
View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: codegen.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.5 $
* @(#) $Id: codegen.c,v 29.5 2001/04/14 22:55:39 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/codegen.c,v $
*
* Under source code control: 1990/02/15 01:48:13
@@ -45,11 +45,15 @@
#include "func.h"
#include "conf.h"
#if defined(_WIN32)
# include <direct.h>
#endif
static BOOL rdonce; /* TRUE => do not reread this file */
FUNC *curfunc;
static BOOL getfilename(char *name, BOOL msg_ok, BOOL *once);
static int getfilename(char *name, BOOL *once);
static BOOL getid(char *buf);
static void getshowstatement(void);
static void getfunction(void);
@@ -71,7 +75,7 @@ static void getsimplebody(void);
static void getcondition(void);
static void getmatargs(void);
static void getelement(void);
static void usesymbol(char *name, BOOL autodef);
static void usesymbol(char *name, int autodef);
static void definesymbol(char *name, int symtype);
static void getcallargs(char *name);
static void do_changedir(void);
@@ -90,9 +94,16 @@ static int getshiftexpr(void);
static int getreference(void);
static int getincdecexpr(void);
static int getterm(void);
static int getidexpr(BOOL okmat, BOOL autodef);
static int getidexpr(BOOL okmat, int autodef);
static long getinitlist(void);
#define INDICALLOC 8
static int quickindices[INDICALLOC];
static int * newindices;
static int * indices;
static int maxindices;
/*
* Read all the commands from an input file.
@@ -133,49 +144,63 @@ getcommands(BOOL toplevel)
return;
case T_HELP:
if (!getfilename(name, FALSE, NULL)) {
strcpy(name, DEFAULTCALCHELP);
for (;;) {
switch(getfilename(name, NULL)) {
case 1:
strcpy(name, DEFAULTCALCHELP);
case 0:
givehelp(name);
continue;
default:
break;
}
break;
}
givehelp(name);
break;
case T_READ:
if (!getfilename(name, TRUE, &rdonce))
break;
if (!allow_read) {
scanerror(T_NULL,
"read command disallowed by -m mode\n");
break;
}
switch (opensearchfile(name,calcpath,CALCEXT,rdonce)) {
case 0:
getcommands(FALSE);
closeinput();
break;
case 1:
/* previously read and -once was given */
break;
case -2:
scanerror(T_NULL,
"Maximum input depth reached");
break;
default:
scanerror(T_NULL, "Cannot open \"%s\"\n", name);
for (;;) {
if (getfilename(name, &rdonce))
break;
switch (opensearchfile(name,calcpath,
CALCEXT,rdonce)) {
case 0:
getcommands(FALSE);
closeinput();
continue;
case 1:
/* prev read and -once was given */
continue;
case -2:
scanerror(T_NULL,
"Maximum input depth reached");
break;
default:
scanerror(T_NULL,
"Cannot open \"%s\"", name);
continue;
}
break;
}
break;
case T_WRITE:
if (!getfilename(name, TRUE, NULL))
break;
if (!allow_write) {
scanerror(T_NULL,
"write command disallowed by -m mode\n");
break;
}
if (writeglobals(name))
if (getfilename(name, NULL))
break;
if (writeglobals(name)) {
scanerror(T_NULL,
"Error writing \"%s\"\n", name);
}
break;
case T_CD:
@@ -497,9 +522,10 @@ getsimpledeclaration(int symtype)
switch (gettoken()) {
case T_SYMBOL:
rescantoken();
res = getonevariable(symtype);
if (res)
if (getonevariable(symtype)) {
res = 1;
addop(OP_POP);
}
continue;
case T_COMMA:
continue;
@@ -529,7 +555,7 @@ getonevariable(int symtype)
res = getonevariable(symtype);
definesymbol(name, symtype);
if (res) {
usesymbol(name, FALSE);
usesymbol(name, 0);
addop(OP_ASSIGNBACK);
}
return res;
@@ -892,7 +918,7 @@ getstatement(LABEL *contlabel, LABEL *breaklabel, LABEL *nextcaselabel, LABEL *d
return;
case T_ELSE:
scanerror(T_SEMICOLON, "ELSE without preceeding IF");
scanerror(T_SEMICOLON, "ELSE without preceding IF");
return;
case T_SHOW:
@@ -1021,7 +1047,6 @@ getobjdeclaration(int symtype)
int count; /* number of elements */
int index; /* current index */
int i; /* loop counter */
int indices[MAXINDICES]; /* indices for elements */
int oldmode;
if (gettoken() != T_SYMBOL) {
@@ -1038,58 +1063,89 @@ getobjdeclaration(int symtype)
* Read in the definition of the elements of the object.
*/
count = 0;
indices = quickindices;
maxindices = INDICALLOC;
oldmode = tokenmode(TM_DEFAULT);
for (;;) {
switch (gettoken()) {
case T_SYMBOL:
if (count == MAXINDICES) {
scanerror(T_SEMICOLON,
"Too many elements in OBJ "
"statement");
(void) tokenmode(oldmode);
return;
}
index = addelement(tokensymbol());
for (i = 0; i < count; i++) {
if (indices[i] == index) {
scanerror(T_SEMICOLON,
"Duplicate element name "
"\"%s\"", tokensymbol());
case T_SYMBOL:
if (count == maxindices) {
if (maxindices == INDICALLOC) {
maxindices += INDICALLOC;
newindices = (int *) malloc(maxindices *
sizeof(int));
if (newindices == NULL) {
scanerror(T_SEMICOLON, "Out of memory for indices malloc");
(void) tokenmode(oldmode);
return;
}
memcpy(newindices, quickindices,
INDICALLOC * sizeof(int));
indices = newindices;
} else {
maxindices += INDICALLOC;
newindices = (int *) realloc(indices,
maxindices * sizeof(int));
if (newindices == NULL) {
free(indices);
scanerror(T_SEMICOLON, "Out of memory for indices realloc");
(void) tokenmode(oldmode);
return;
}
indices = newindices;
}
indices[count++] = index;
if (gettoken() == T_COMMA)
continue;
rescantoken();
if (gettoken() != T_RIGHTBRACE) {
scanerror(T_SEMICOLON,
"Bad object type definition");
}
index = addelement(tokensymbol());
for (i = 0; i < count; i++) {
if (indices[i] == index) {
if (indices != quickindices)
free(indices);
scanerror(T_SEMICOLON, "Duplicate element name \"%s\"", tokensymbol());
(void) tokenmode(oldmode);
return;
}
/*FALLTHRU*/
case T_RIGHTBRACE:
(void) tokenmode(oldmode);
if (defineobject(name, indices, count)) {
scanerror(T_NULL,
"Object type \"%s\" is already defined", name);
return;
}
getobjvars(name, symtype);
return;
case T_NEWLINE:
}
indices[count++] = index;
if (gettoken() == T_COMMA)
continue;
default:
scanerror(T_SEMICOLON,
"Bad object type definition");
rescantoken();
if (gettoken() != T_RIGHTBRACE) {
if (indices != quickindices)
free(indices);
scanerror(T_SEMICOLON, "Bad object type definition");
(void) tokenmode(oldmode);
return;
}
/*FALLTHRU*/
case T_RIGHTBRACE:
(void) tokenmode(oldmode);
if (defineobject(name, indices, count)) {
if (indices != quickindices)
free(indices);
scanerror(T_NULL,
"Object type \"%s\" is already defined", name);
return;
}
if (indices != quickindices)
free(indices);
getobjvars(name, symtype);
return;
case T_NEWLINE:
continue;
default:
if (indices != quickindices)
free(indices);
scanerror(T_SEMICOLON, "Bad object type definition");
(void) tokenmode(oldmode);
return;
}
}
}
static void
getoneobj(long index, int symtype)
{
@@ -1098,11 +1154,11 @@ getoneobj(long index, int symtype)
if (gettoken() == T_SYMBOL) {
if (symtype == SYM_UNDEFINED) {
rescantoken();
(void) getidexpr(TRUE, TRUE);
(void) getidexpr(TRUE, 1);
} else {
symname = tokensymbol();
definesymbol(symname, symtype);
usesymbol(symname, FALSE);
usesymbol(symname, 0);
}
getoneobj(index, symtype);
addop(OP_ASSIGN);
@@ -1181,11 +1237,11 @@ getonematrix(int symtype)
if (gettoken() == T_SYMBOL) {
if (symtype == SYM_UNDEFINED) {
rescantoken();
(void) getidexpr(FALSE, TRUE);
(void) getidexpr(FALSE, 1);
} else {
name = tokensymbol();
definesymbol(name, symtype);
usesymbol(name, FALSE);
usesymbol(name, 0);
}
while (gettoken() == T_COMMA);
rescantoken();
@@ -2028,7 +2084,25 @@ getterm(void)
case T_SYMBOL:
rescantoken();
type = getidexpr(TRUE, FALSE);
type = getidexpr(TRUE, 0);
break;
case T_GLOBAL:
if (gettoken() != T_SYMBOL) {
scanerror(T_NULL, "Global id expected");
break;
}
rescantoken();
type = getidexpr(TRUE, T_GLOBAL);
break;
case T_LOCAL:
if (gettoken() != T_SYMBOL) {
scanerror(T_NULL, "Local id expected");
break;
}
rescantoken();
type = getidexpr(TRUE, T_LOCAL);
break;
case T_LEFTBRACKET:
@@ -2077,11 +2151,11 @@ getterm(void)
/*
* Read in an identifier expressions.
* This is a symbol name followed by parenthesis, or by square brackets or
* element refernces. The symbol can be a global or a local variable name.
* element references. The symbol can be a global or a local variable name.
* Returns the type of expression found.
*/
static int
getidexpr(BOOL okmat, BOOL autodef)
getidexpr(BOOL okmat, int autodef)
{
int type;
char name[SYMBOLSIZE+1]; /* symbol name */
@@ -2091,18 +2165,19 @@ getidexpr(BOOL okmat, BOOL autodef)
if (!getid(name))
return type;
switch (gettoken()) {
case T_LEFTPAREN:
oldmode = tokenmode(TM_DEFAULT);
getcallargs(name);
(void) tokenmode(oldmode);
type = 0;
break;
case T_ASSIGN:
autodef = TRUE;
/* fall into default case */
default:
rescantoken();
usesymbol(name, autodef);
case T_LEFTPAREN:
oldmode = tokenmode(TM_DEFAULT);
getcallargs(name);
(void) tokenmode(oldmode);
type = 0;
break;
case T_ASSIGN:
if (autodef != T_GLOBAL && autodef != T_LOCAL)
autodef = 1;
/* fall into default case */
default:
rescantoken();
usesymbol(name, autodef);
}
/*
* Now collect as many element references and matrix index operations
@@ -2110,27 +2185,27 @@ getidexpr(BOOL okmat, BOOL autodef)
*/
for (;;) {
switch (gettoken()) {
case T_LEFTBRACKET:
rescantoken();
if (!okmat)
return type;
getmatargs();
type = 0;
break;
case T_ARROW:
addop(OP_DEREF);
/*FALLTHRU*/
case T_PERIOD:
getelement();
type = 0;
break;
case T_LEFTPAREN:
scanerror(T_NULL,
"Function calls not allowed "
"as expressions");
default:
rescantoken();
case T_LEFTBRACKET:
rescantoken();
if (!okmat)
return type;
getmatargs();
type = 0;
break;
case T_ARROW:
addop(OP_DEREF);
/*FALLTHRU*/
case T_PERIOD:
getelement();
type = 0;
break;
case T_LEFTPAREN:
scanerror(T_NULL,
"Function calls not allowed "
"as expressions");
default:
rescantoken();
return type;
}
}
}
@@ -2144,71 +2219,37 @@ getidexpr(BOOL okmat, BOOL autodef)
*
* given:
* name filename to read
* msg_ok TRUE => ok to print error messages
* once non-NULL => set to TRUE of -once read
*/
static BOOL
getfilename(char *name, BOOL msg_ok, BOOL *once)
static int
getfilename(char *name, BOOL *once)
{
STRING *s;
int i;
/* look at the next token */
(void) tokenmode(TM_NEWLINES | TM_ALLSYMS);
switch (gettoken()) {
case T_STRING:
s = findstring(tokenstring());
strcpy(name, s->s_str);
sfree(s);
break;
case T_SYMBOL:
strcpy(name, tokensymbol());
break;
default:
if (msg_ok)
scanerror(T_SEMICOLON, "Filename expected");
return FALSE;
}
/* determine if we care about a possible -once option */
if (once != NULL) {
/* we care about a possible -once option */
if (strcmp(name, "-once") == 0) {
/* -once option found */
*once = TRUE;
/* look for the filename */
switch (gettoken()) {
case T_STRING:
s = findstring(tokenstring());
strcpy(name, s->s_str);
sfree(s);
break;
case T_SYMBOL:
strcpy(name, tokensymbol());
break;
default:
if (msg_ok)
scanerror(T_SEMICOLON,
"Filename expected");
return FALSE;
}
} else {
*once = FALSE;
for (i = 2; i > 0; i--) {
switch (gettoken()) {
case T_STRING:
s = findstring(tokenstring());
strcpy(name, s->s_str);
sfree(s);
break;
case T_SYMBOL:
strcpy(name, tokensymbol());
break;
default:
rescantoken();
return -1;
}
}
/* look at the next token */
switch (gettoken()) {
case T_SEMICOLON:
case T_NEWLINE:
case T_EOF:
break;
default:
if (msg_ok)
scanerror(T_SEMICOLON,
"Missing semicolon after filename");
return FALSE;
if (i == 2 && once != NULL) {
if ((*once = !strcmp(name, "-once")))
continue;
}
break;
}
return TRUE;
return 0;
}
@@ -2433,11 +2474,26 @@ definesymbol(char *name, int symtype)
*
* given:
* name symbol name to be checked
* autodef TRUE => define is symbol is not known
* autodef 1 => define if symbol is not known
* T_GLOBAL => get global, define if necessary
*/
static void
usesymbol(char *name, BOOL autodef)
usesymbol(char *name, int autodef)
{
if (autodef == T_GLOBAL) {
addopptr(OP_GLOBALADDR, (char *) addglobal(name, FALSE));
return;
}
if (autodef == T_LOCAL) {
if (symboltype(name) == SYM_PARAM) {
scanerror(T_COMMA,
"Variable \"%s\" is already defined", name);
return;
}
addopone(OP_LOCALADDR, addlocal(name));
return;
}
switch (symboltype(name)) {
case SYM_LOCAL:
addopone(OP_LOCALADDR, (long) findlocal(name));
@@ -2544,24 +2600,25 @@ static void
do_changedir(void)
{
char *p;
STRING *s;
/* look at the next token */
(void) tokenmode(TM_NEWLINES | TM_ALLSYMS);
/* determine the new directory */
s = NULL;
switch (gettoken()) {
case T_NULL:
case T_NEWLINE:
case T_SEMICOLON:
p = home;
break;
default:
p = tokensymbol(); /* This is not enough XXX */
if (p == NULL) {
case T_STRING:
s = findstring(tokenstring());
p = s->s_str;
break;
case T_SYMBOL:
p = tokensymbol();
break;
default:
p = home;
}
break;
}
if (p == NULL) {
fprintf(stderr, "Cannot determine HOME directory\n");
}
@@ -2570,29 +2627,8 @@ do_changedir(void)
if (chdir(p)) {
perror(p);
}
return;
if (s != NULL)
sfree(s);
}
/*
* getshellfile - process the contents of a shellfile
*/
void
getshellfile(char *shellfile)
{
/*
* treat the calc shell script as if we were reading it
*/
if (!allow_read) {
scanerror(T_NULL,
"reading of calc shell script \"%s\" "
"dislloaed by -m mode\n", shellfile);
} else if (opensearchfile(shellfile, NULL, NULL, FALSE) == 0) {
getcommands(FALSE);
closeinput();
} else {
scanerror(T_NULL,
"Cannot open calc shell script \"%s\"\n", shellfile);
}
return;
}

View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: comfunc.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: comfunc.c,v 29.3 2000/07/17 15:35:49 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/comfunc.c,v $
*
* Under source code control: 1990/02/15 01:48:13
@@ -1007,7 +1007,7 @@ cpolar(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
long m, n;
if (qiszero(epsilon)) {
math_error("Zero epsilson for cpolar");
math_error("Zero epsilon for cpolar");
/*NOTREACHED*/
}
if (qiszero(q1))
@@ -1162,3 +1162,27 @@ cprintfr(COMPLEX *c)
zprintval(i->den, 0L, 0L);
}
}
NUMBER *
cilog(COMPLEX *c, ZVALUE base)
{
NUMBER *qr, *qi;
qr = qilog(c->real, base);
qi = qilog(c->imag, base);
if (qr == NULL) {
if (qi == NULL)
return NULL;
return qi;
}
if (qi == NULL)
return qr;
if (qrel(qr, qi) >= 0) {
qfree(qi);
return qr;
}
qfree(qr);
return qi;
}

302
config.c
View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.3 $
* @(#) $Id: config.c,v 29.3 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.6 $
* @(#) $Id: config.c,v 29.6 2001/04/08 10:07:19 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/config.c,v $
*
* Under source code control: 1991/07/20 00:21:56
@@ -90,6 +90,7 @@ NAMETYPE configs[] = {
{"ctrl-d", CONFIG_CTRL_D}, /* alias for ctrl_d */
{"program", CONFIG_PROGRAM},
{"basename", CONFIG_BASENAME},
{"windows", CONFIG_WINDOWS},
{"version", CONFIG_VERSION},
{NULL, 0}
};
@@ -109,10 +110,10 @@ 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 aproximations */
TRUE, /* ok to print a tilde on approximations */
TRUE, /* ok to print tab before numeric values */
0, /* quomod() default rounding mode */
2, /* quotent // default rounding mode */
2, /* quotient // default rounding mode */
0, /* mod % default rounding mode */
24, /* sqrt() default rounding mode */
24, /* appr() default rounding mode */
@@ -136,6 +137,11 @@ 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)
TRUE, /* running under windows */
#else
FALSE, /* congrats, you are not using windows */
#endif
NULL /* version */
};
CONFIG newstd = { /* new non-backward compatible configuration */
@@ -149,10 +155,10 @@ 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 aproximations */
TRUE, /* ok to print a tilde on approximations */
TRUE, /* ok to print tab before numeric values */
0, /* quomod() default rounding mode */
0, /* quotent // default rounding mode */
0, /* quotient // default rounding mode */
0, /* mod % default rounding mode */
24, /* sqrt() default rounding mode */
24, /* appr() default rounding mode */
@@ -176,6 +182,11 @@ 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)
TRUE, /* running under windows */
#else
FALSE, /* congrats, you are not using windows */
#endif
NULL /* version */
};
CONFIG *conf = NULL; /* loaded in at startup - current configuration */
@@ -287,10 +298,11 @@ static NAMETYPE truth[] = {
/*
* declate static functions
* declare static functions
*/
static long lookup_long(NAMETYPE *set, char *name);
static char *lookup_name(NAMETYPE *set, long val);
static int getlen(VALUE *vp, LEN *lp);
/*
@@ -360,6 +372,26 @@ lookup_name(NAMETYPE *set, long val)
}
/*
* Check whether VALUE at vp is a LEN (32-bit signed integer) and if so,
* copy that integer to lp.
* Return: 1, 2, 0, or -1 XXX
*/
static int
getlen(VALUE *vp, LEN *lp)
{
if (vp->v_type != V_NUM || !qisint(vp->v_num))
return 1;
if (zge31b(vp->v_num->num))
return 2;
*lp = ztoi(vp->v_num->num);
if (*lp < 0)
return -1;
return 0;
}
/*
* Set the specified configuration type to the specified value.
* An error is generated if the type number or value is illegal.
@@ -370,6 +402,7 @@ setconfig(int type, VALUE *vp)
NUMBER *q;
CONFIG *newconf; /* new configuration to set */
long temp;
LEN len;
char *p;
switch (type) {
@@ -414,15 +447,11 @@ setconfig(int type, VALUE *vp)
break;
case CONFIG_DISPLAY:
if (vp->v_type != V_NUM) {
math_error("Non-numeric for display");
if (getlen(vp, &len)) {
math_error("Bad value for display");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q) || !zistiny(q->num))
temp = -1;
math_setdigits(temp);
math_setdigits(len);
break;
case CONFIG_MODE:
@@ -447,91 +476,51 @@ setconfig(int type, VALUE *vp)
break;
case CONFIG_MAXPRINT:
if (vp->v_type != V_NUM) {
math_error("Non-numeric for maxprint");
if (getlen(vp, &len)) {
math_error("Bad value for maxprint");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q) || !zistiny(q->num))
temp = -1;
if (temp < 0) {
math_error("Maxprint value is out of range");
/*NOTREACHED*/
}
conf->maxprint = temp;
conf->maxprint = len;
break;
case CONFIG_MUL2:
if (vp->v_type != V_NUM) {
math_error("Non-numeric for mul2");
if (getlen(vp, &len)) {
math_error("Bad value for mul2");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q))
temp = -1;
if (temp == 0)
temp = MUL_ALG2;
if (temp < 2) {
math_error("Illegal mul2 value");
/*NOTREACHED*/
}
conf->mul2 = (int)temp;
if (len == 0)
len = MUL_ALG2;
conf->mul2 = len;
break;
case CONFIG_SQ2:
if (vp->v_type != V_NUM) {
math_error("Non-numeric for sq2");
if (getlen(vp, &len)) {
math_error("Bad value for sq2");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q))
temp = -1;
if (temp == 0)
temp = SQ_ALG2;
if (temp < 2) {
math_error("Illegal sq2 value");
/*NOTREACHED*/
}
conf->sq2 = (int)temp;
if (len == 0)
len = SQ_ALG2;
conf->sq2 = len;
break;
case CONFIG_POW2:
if (vp->v_type != V_NUM) {
math_error("Non-numeric for pow2");
if (getlen(vp, &len)) {
math_error("Bad value for pow2");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q))
temp = -1;
if (temp == 0)
temp = POW_ALG2;
if (temp < 1) {
math_error("Illegal pow2 value");
/*NOTREACHED*/
}
conf->pow2 = (int)temp;
if (len == 0)
len = POW_ALG2;
conf->pow2 = len;
break;
case CONFIG_REDC2:
if (vp->v_type != V_NUM) {
math_error("Non-numeric for redc2");
if (getlen(vp, &len)) {
math_error("Bad value for redc2");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q))
temp = -1;
if (temp == 0)
temp = REDC_ALG2;
if (temp < 1) {
math_error("Illegal redc2 value");
/*NOTREACHED*/
}
conf->redc2 = (int)temp;
if (len == 0)
len = REDC_ALG2;
conf->redc2 = len;
break;
case CONFIG_TILDE:
@@ -563,129 +552,75 @@ setconfig(int type, VALUE *vp)
break;
case CONFIG_QUOMOD:
if (vp->v_type != V_NUM) {
math_error("Non numeric for quomod");
if (getlen(vp, &len)) {
math_error("Illegal value for quomod");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
math_error("Illegal quomod parameter value");
/*NOTREACHED*/
}
conf->quomod = temp;
conf->quomod = len;
break;
case CONFIG_QUO:
if (vp->v_type != V_NUM) {
math_error("Non numeric for quo");
if (getlen(vp, &len)) {
math_error("Illegal value for quo");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
math_error("Illegal quo parameter value");
/*NOTREACHED*/
}
conf->quo = temp;
conf->quo = len;
break;
case CONFIG_MOD:
if (vp->v_type != V_NUM) {
math_error("Non numeric for mod");
if (getlen(vp, &len)) {
math_error("Illegal value for mod");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
math_error("Illegal mod parameter value");
/*NOTREACHED*/
}
conf->mod = temp;
conf->mod = len;
break;
case CONFIG_SQRT:
if (vp->v_type != V_NUM) {
math_error("Non numeric for sqrt");
if (getlen(vp, &len)) {
math_error("Illegal value for sqrt");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
math_error("Illegal sqrt parameter value");
/*NOTREACHED*/
}
conf->sqrt = temp;
conf->sqrt = len;
break;
case CONFIG_APPR:
if (vp->v_type != V_NUM) {
math_error("Non numeric for appr");
if (getlen(vp, &len)) {
math_error("Illegal value for appr");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
math_error("Illegal appr parameter value");
/*NOTREACHED*/
}
conf->appr = temp;
conf->appr = len;
break;
case CONFIG_CFAPPR:
if (vp->v_type != V_NUM) {
math_error("Non numeric for cfappr");
if (getlen(vp, &len)) {
math_error("Illegal value for cfappr");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
math_error("Illegal cfappr parameter value");
/*NOTREACHED*/
}
conf->cfappr = temp;
conf->cfappr = len;
break;
case CONFIG_CFSIM:
if (vp->v_type != V_NUM) {
math_error("Non numeric for cfsim");
if (getlen(vp, &len)) {
math_error("Illegal value for cfsim");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
math_error("Illegal cfsim parameter value");
/*NOTREACHED*/
}
conf->cfsim = temp;
conf->cfsim = len;
break;
case CONFIG_OUTROUND:
if (vp->v_type != V_NUM) {
math_error("Non numeric for outround");
if (getlen(vp, &len)) {
math_error("Illegal value for outround");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
math_error("Illegal output parameter value");
/*NOTREACHED*/
}
conf->outround = temp;
conf->outround = len;
break;
case CONFIG_ROUND:
if (vp->v_type != V_NUM) {
math_error("Non numeric for round");
if (getlen(vp, &len)) {
math_error("Illegal value for round");
/*NOTREACHED*/
}
q = vp->v_num;
temp = qtoi(q);
if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) {
math_error("Illegal output parameter value");
/*NOTREACHED*/
}
conf->round = temp;
conf->round = len;
break;
case CONFIG_LEADZERO:
@@ -898,11 +833,15 @@ setconfig(int type, VALUE *vp)
/*NOTREACHED*/
case CONFIG_BASENAME:
math_error("The program config parameter is read-only");
math_error("The basename config parameter is read-only");
/*NOTREACHED*/
case CONFIG_WINDOWS:
math_error("The windows config parameter is read-only");
/*NOTREACHED*/
case CONFIG_VERSION:
math_error("The program config parameter is read-only");
math_error("The version config parameter is read-only");
/*NOTREACHED*/
default:
@@ -1104,20 +1043,18 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
break;
case CONFIG_TILDE:
vp->v_type = V_STR;
if (cfg->tilde_ok) {
vp->v_str = makenewstring(TRUE_STRING);
vp->v_num = itoq(1);
} else {
vp->v_str = makenewstring(FALSE_STRING);
vp->v_num = itoq(0);
}
return;
case CONFIG_TAB:
vp->v_type = V_STR;
if (cfg->tab_ok) {
vp->v_str = makenewstring(TRUE_STRING);
vp->v_num = itoq(1);
} else {
vp->v_str = makenewstring(FALSE_STRING);
vp->v_num = itoq(0);
}
return;
@@ -1158,20 +1095,18 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
break;
case CONFIG_LEADZERO:
vp->v_type = V_STR;
if (cfg->leadzero) {
vp->v_str = makenewstring(TRUE_STRING);
vp->v_num = itoq(1);
} else {
vp->v_str = makenewstring(FALSE_STRING);
vp->v_num = itoq(0);
}
return;
case CONFIG_FULLZERO:
vp->v_type = V_STR;
if (cfg->fullzero) {
vp->v_str = makenewstring(TRUE_STRING);
vp->v_num = itoq(1);
} else {
vp->v_str = makenewstring(FALSE_STRING);
vp->v_num = itoq(0);
}
return;
@@ -1194,11 +1129,10 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
break;
case CONFIG_BLKVERBOSE:
vp->v_type = V_STR;
if (cfg->blkverbose) {
vp->v_str = makenewstring(TRUE_STRING);
vp->v_num = itoq(1);
} else {
vp->v_str = makenewstring(FALSE_STRING);
vp->v_num = itoq(0);
}
return;
@@ -1235,11 +1169,10 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
break;
case CONFIG_VERBOSE_QUIT:
vp->v_type = V_STR;
if (cfg->verbose_quit) {
vp->v_str = makenewstring(TRUE_STRING);
vp->v_num = itoq(1);
} else {
vp->v_str = makenewstring(FALSE_STRING);
vp->v_num = itoq(0);
}
return;
@@ -1271,6 +1204,14 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
}
return;
case CONFIG_WINDOWS:
if (cfg->windows) {
vp->v_num = itoq(1);
} else {
vp->v_num = itoq(0);
}
return;
case CONFIG_VERSION:
vp->v_type = V_STR;
if (cfg->version == NULL) {
@@ -1311,12 +1252,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 invaid");
math_error("CONFIG #1 value is invalid");
/*NOTREACHED*/
}
if (cfg2 == NULL || cfg2->epsilon == NULL || cfg2->prompt1 == NULL ||
cfg2->prompt2 == NULL) {
math_error("CONFIG #2 value is invaid");
math_error("CONFIG #2 value is invalid");
/*NOTREACHED*/
}
@@ -1371,6 +1312,7 @@ config_cmp(CONFIG *cfg1, CONFIG *cfg2)
(cfg1->version == NULL && cfg2->version != NULL) ||
(cfg1->version != NULL && cfg2->version == NULL) ||
cfg1->windows != cfg2->windows ||
(cfg1->version != NULL && cfg2->version != NULL &&
strcmp(cfg1->version, cfg2->version) != 0);
}

View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.3 $
* @(#) $Id: config.h,v 29.3 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.9 $
* @(#) $Id: config.h,v 29.9 2001/04/14 22:47:21 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/config.h,v $
*
* Under source code control: 1995/11/01 22:20:17
@@ -35,6 +35,7 @@
#define __CONFIG_H__
#include "win32dll.h"
#include "nametype.h"
#include "qmath.h"
@@ -82,6 +83,7 @@
#define CONFIG_PROGRAM 35
#define CONFIG_BASENAME 36
#define CONFIG_VERSION 37
#define CONFIG_WINDOWS 38
/*
@@ -110,26 +112,26 @@
*/
struct config {
int outmode; /* current output mode */
long outdigits; /* current output digits for float or exp */
LEN outdigits; /* current output digits for float or exp */
NUMBER *epsilon; /* default error for real functions */
long epsilonprec; /* epsilon binary precision (tied to epsilon) */
FLAG traceflags; /* tracing flags */
long maxprint; /* number of elements to print */
LEN maxprint; /* number of elements to print */
LEN mul2; /* size of number to use multiply algorithm 2 */
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 */
long quomod; /* quomod() default rounding mode */
long quo; /* quotent // default rounding mode */
long mod; /* mod % default rounding mode */
long sqrt; /* sqrt() default rounding mode */
long appr; /* appr() default rounding mode */
long cfappr; /* cfappr() default rounding mode */
long cfsim; /* cfsim() default rounding mode */
long outround; /* output default rounding mode */
long round; /* round()/bround() default rounding mode */
LEN quomod; /* quomod() default rounding mode */
LEN quo; /* quotient // default rounding mode */
LEN mod; /* mod % default rounding mode */
LEN sqrt; /* sqrt() default rounding mode */
LEN appr; /* appr() default rounding mode */
LEN cfappr; /* cfappr() default rounding mode */
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 */
long maxscancount; /* max scan errors before abort */
@@ -146,6 +148,7 @@ struct config {
int ctrl_d; /* see CTRL_D_xyz below */
char *program; /* our name */
char *base_name; /* basename of our name */
BOOL windows; /* TRUE => running under MS windows */
char *version; /* calc version string */
};
typedef struct config CONFIG;
@@ -157,7 +160,8 @@ typedef struct config CONFIG;
#define RSCDBG_STDIN_FUNC (0x00000001) /* interactive func define debug */
#define RSCDBG_FILE_FUNC (0x00000002) /* file read func define debug */
#define RSCDBG_FUNC_INFO (0x00000004) /* print extra info for show func */
#define RSCDBG_MASK (0x00000007)
#define RSCDBG_PRINT_DBG (0x00000008) /* print debug messages */
#define RSCDBG_MASK (0x0000000f)
/*
@@ -169,7 +173,8 @@ typedef struct config CONFIG;
#define CALCDBG_BLOCK (0x00000008) /* block debug */
#define CALCDBG_TTY (0x00000010) /* report TTY state changes */
#define CALCDBG_RUNSTATE (0x00000020) /* report run_state changes */
#define CALCDBG_MASK (0x0000003f)
#define CALCDBG_RAND (0x00000040) /* report rand() activity */
#define CALCDBG_MASK (0x0000007f)
/*
* ctrl-d meanings
@@ -182,23 +187,23 @@ typedef struct config CONFIG;
/*
* global configuration states and aliases
*/
extern CONFIG *conf; /* current configuration */
extern CONFIG oldstd; /* backward compatible standard configuration */
extern CONFIG newstd; /* new non-backward compatible configuration */
extern char *calc_debug; /* !=NULL => value of config("calc_debug") */
extern char *resource_debug; /* !=NULL => config("resource_debug") value */
extern char *user_debug; /* !=NULL => value of config("user_debug") */
extern DLL CONFIG *conf; /* current configuration */
extern DLL CONFIG oldstd; /* backward compatible standard configuration */
extern DLL CONFIG newstd; /* new non-backward compatible configuration */
extern DLL char *calc_debug; /* !=NULL => value of config("calc_debug") */
extern DLL char *resource_debug; /* !=NULL => config("resource_debug") value */
extern DLL char *user_debug; /* !=NULL => value of config("user_debug") */
/*
* configuration externals
*/
extern CONFIG *config_copy(CONFIG *src);
extern void config_free(CONFIG *cfg);
extern void config_print(CONFIG *cfg);
extern int configtype(char*);
extern void config_print(CONFIG*);
extern BOOL config_cmp(CONFIG*, CONFIG*);
extern DLL CONFIG *config_copy(CONFIG *src);
extern DLL void config_free(CONFIG *cfg);
extern DLL void config_print(CONFIG *cfg);
extern DLL int configtype(char*);
extern DLL void config_print(CONFIG*);
extern DLL BOOL config_cmp(CONFIG*, CONFIG*);
#endif /* !__CONFIG_H__ */

View File

@@ -17,8 +17,8 @@
# received a copy with calc; if not, write to Free Software Foundation, Inc.
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
# @(#) $Revision: 29.5 $
# @(#) $Id: Makefile,v 29.5 2000/06/07 14:02:59 chongo Exp $
# @(#) $Revision: 29.9 $
# @(#) $Id: Makefile,v 29.9 2001/04/08 10:53:52 chongo Exp $
# @(#) $Source: /usr/local/src/cmd/calc/cscript/RCS/Makefile,v $
#
# Under source code control: 1999/11/29 11:10:26
@@ -65,7 +65,7 @@ FMT= fmt
#
# The ${SCRIPT_SRC} is built from ${SCRIPT} and has the .calc extensions.
#
# 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.
# To add a script:
#
# 1) Name the file with a .calc filename extension
@@ -76,15 +76,16 @@ FMT= fmt
#
# make detaillist
#
SCRIPT= mersenne piforever plus simple
SCRIPT= mersenne piforever plus simple square fproduct
SCRIPT_SRC= mersenne.calc piforever.calc plus.calc simple.calc
SCRIPT_SRC= mersenne.calc piforever.calc plus.calc simple.calc square.calc \
fproduct.calc
# These files are found (but not built) in the distribution
#
DISTLIST= ${SCRIPT_SRC} ${MAKE_FILE} README
# These files are used to make (but not built) a calc .a library
# These files are used to make (but not build) a calc .a library
#
CALCLIBLIST=
@@ -92,10 +93,10 @@ CALCLIBLIST=
#
all: ${SCRIPT} ${SCRIPT_SRC} .all
# used by the upper level Makefile to determine of we have done all
# used by the upper level Makefile to determine if we have done all
#
# NOTE: Due to bogus shells found on one common system we must have
# an non-emoty else clause for every if condition. *sigh*
# a non-empty else clause for every if condition. *sigh*
#
.all:
rm -f .all
@@ -114,7 +115,7 @@ all: ${SCRIPT} ${SCRIPT_SRC} .all
distlist: ${DISTLIST}
${Q}for i in ${DISTLIST}; do \
echo cscript/$$i; \
done | ${SORT}
done | LANG=C ${SORT}
distdir:
${Q}echo cscript
@@ -131,7 +132,7 @@ detaillist:
else \
echo $$i; \
fi; \
done | ${SORT}) | ${FMT} -70 | \
done | LANG=C ${SORT}) | ${FMT} -70 | \
${SED} -e '1s/xxxxxxx/SCRIPT=/' -e '2,$$s/^/ /' \
-e 's/$$/ \\/' -e '$$s/ \\$$//'
${Q}echo
@@ -142,7 +143,7 @@ detaillist:
else \
echo $$i.calc; \
fi; \
done | ${SORT}) | ${FMT} -70 | \
done | LANG=C ${SORT}) | ${FMT} -70 | \
${SED} -e '1s/xxxxxxxxxxx/SCRIPT_SRC=/' -e '2,$$s/^/ /' \
-e 's/$$/ \\/' -e '$$s/ \\$$//'
@@ -245,3 +246,11 @@ simple: simple.calc
rm -f $@
${SED} -e "1s:^#!/usr/local/src/cmd/calc/calc:#!${BINDIR}/calc:" $?>$@
${CHMOD} +x $@
square: square.calc
rm -f $@
${SED} -e "1s:^#!/usr/local/src/cmd/calc/calc:#!${BINDIR}/calc:" $?>$@
${CHMOD} +x $@
fproduct: fproduct.calc
rm -f $@
${SED} -e "1s:^#!/usr/local/src/cmd/calc/calc:#!${BINDIR}/calc:" $?>$@
${CHMOD} +x $@

View File

@@ -19,6 +19,11 @@ For more info, see:
=-=
fproduct filename term ...
Write the big Endian product of terms to a file. Use - for stdout.
mersenne exp
Print the value of 2^exp-1.
@@ -54,8 +59,8 @@ simple
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.4 $
## @(#) $Id: README,v 29.4 2000/06/07 14:02:59 chongo Exp $
## @(#) $Revision: 29.5 $
## @(#) $Id: README,v 29.5 2001/04/08 08:24:40 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/cscript/RCS/README,v $
##
## Under source code control: 1999/12/17 10:23:40

88
cscript/fproduct.calc Normal file
View File

@@ -0,0 +1,88 @@
#!/usr/local/bin/calc -q -s -f
/*
* fproduct - write the big Endian product of terms to a file
*
* usage:
* fproduct filename term [term ...]
*
* filename where to write the product, use - for stdout
* term ... terms to multiply
*
* Copyright (C) 2001 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.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.1 $
* @(#) $Id: fproduct.calc,v 29.1 2001/04/08 08:25:15 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/cscript/RCS/fproduct.calc,v $
*
* Under source code control: 2001/04/07 20:13:11
* File existed as early as: 2001
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* parse args
*/
argc = argv();
if (argc < 2) {
fprintf(files(2), "usage: %s term [term ...]\n", argv(0));
exit;
}
filename = argv(1);
/*
* build the product
*/
product = 1;
for (i=2; i < argc; ++i) {
product *= eval(argv(i));
}
product = abs(product);
/*
* open the file for writing, "-" is stdout
*/
if (filename == "-") {
fd = files(1);
} else {
fd = fopen(filename, "w");
if (!isfile(fd)) quit "be2file: cannot open file for writing";
}
/*
* write the octets to the file
*
* The most significant bits of the integer become the first file octets.
*/
if (product > 0) {
octlen = int((highbit(product)+8) / 8);
for (i=octlen-1; i >= 0; --i) {
fputc(fd, char(product >> (i*8)));
}
}
/*
* cleanup
*/
if (filename != "-") {
fclose(fd);
}

View File

@@ -1,4 +1,4 @@
#!/usr/local/src/cmd/calc/calc -S
#!/usr/local/src/cmd/calc/calc -q -s -f
#
# mersenne - print the value of a mersenne number
#
@@ -18,8 +18,8 @@
# received a copy with calc; if not, write to Free Software Foundation, Inc.
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
# @(#) $Revision: 29.2 $
# @(#) $Id: mersenne.calc,v 29.2 2000/06/07 14:02:59 chongo Exp $
# @(#) $Revision: 29.3 $
# @(#) $Id: mersenne.calc,v 29.3 2000/12/15 14:56:54 chongo Exp $
# @(#) $Source: /usr/local/src/cmd/calc/cscript/RCS/mersenne.calc,v $
#
# Under source code control: 1999/11/30 00:09:01;
@@ -35,13 +35,19 @@
/*
* parse args
*/
if (argv() != 1) {
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";
}
global n = eval(argv(1));
if (!isint(n) || n <= 0) {
quit "Argument to be a positive integer";
}
/*
* print the decimal value of 2^n-1
*/
print "2^": argv(0) : "-1 =", 2^eval(argv(0))-1;
print "2^": n : "-1 =", 2^n-1;

View File

@@ -1,4 +1,4 @@
#!/usr/local/src/cmd/calc/calc -S
#!/usr/local/src/cmd/calc/calc -q -f
#
# piforever - print digits of pi forever (or as long as your mem/cpu allow)
#
@@ -18,8 +18,8 @@
# received a copy with calc; if not, write to Free Software Foundation, Inc.
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
# @(#) $Revision: 29.2 $
# @(#) $Id: piforever.calc,v 29.2 2000/06/07 14:02:59 chongo Exp $
# @(#) $Revision: 29.3 $
# @(#) $Id: piforever.calc,v 29.3 2000/12/15 14:56:54 chongo Exp $
# @(#) $Source: /usr/local/src/cmd/calc/cscript/RCS/piforever.calc,v $
#
# Under source code control: 1999/11/30 00:11:36

View File

@@ -1,4 +1,4 @@
#!/usr/local/src/cmd/calc/calc -S
#!/usr/local/src/cmd/calc/calc -q -s -f
#
# plus - add two or more arguments together
#
@@ -18,8 +18,8 @@
# received a copy with calc; if not, write to Free Software Foundation, Inc.
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
# @(#) $Revision: 29.2 $
# @(#) $Id: plus.calc,v 29.2 2000/06/07 14:02:59 chongo Exp $
# @(#) $Revision: 29.3 $
# @(#) $Id: plus.calc,v 29.3 2000/12/15 14:56:54 chongo Exp $
# @(#) $Source: /usr/local/src/cmd/calc/cscript/RCS/plus.calc,v $
#
# Under source code control: 1999/11/29 10:22:37
@@ -35,19 +35,19 @@
/*
* parse args
*/
if (argv() < 1) {
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";
}
/*
* print the sum of the 2 args
* print the sum of the args
*
* Since args are strings, we must eval them before using them numerically.
*/
sum = 0;
for (i=0; i < argv(); ++i) {
for (i=1; i < argv(); ++i) {
sum += eval(argv(i));
}
print sum;

View File

@@ -1,4 +1,4 @@
#!/usr/local/src/cmd/calc/calc -S
#!/usr/local/src/cmd/calc/calc -q -f
#
# simple - an example of a simple calc shell script
#
@@ -18,8 +18,8 @@
# received a copy with calc; if not, write to Free Software Foundation, Inc.
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
# @(#) $Revision: 29.2 $
# @(#) $Id: simple.calc,v 29.2 2000/06/07 14:02:59 chongo Exp $
# @(#) $Revision: 29.3 $
# @(#) $Id: simple.calc,v 29.3 2000/12/15 14:56:54 chongo Exp $
# @(#) $Source: /usr/local/src/cmd/calc/cscript/RCS/simple.calc,v $
#
# Under source code control: 1999/11/29 10:22:37
@@ -32,4 +32,4 @@
/*
* This is an example of a simple calc shell script.
*/
print "The simple calc shell script works!"
print "This simple calc shell script works!"

65
cscript/square.calc Normal file
View File

@@ -0,0 +1,65 @@
#!/usr/local/src/cmd/calc/calc -q -f
#
# sqaure - print the squares of input values
#
# Copyright (C) 2000 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
# as published by the Free Software Foundation.
#
# Calc is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
# Public License for more details.
#
# A copy of version 2.1 of the GNU Lesser General Public License is
# distributed with calc under the filename COPYING-LGPL. You should have
# received a copy with calc; if not, write to Free Software Foundation, Inc.
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
# @(#) $Revision: 29.3 $
# @(#) $Id: square.calc,v 29.3 2000/12/17 14:31:58 chongo Exp $
# @(#) $Source: /usr/local/src/cmd/calc/cscript/RCS/square.calc,v $
#
# Under source code control: 2000/12/15 06:52:01
# File existed as early as: 2000
#
# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
# Usage:
#
# From the shell:
#
# ./square
# 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.
# Execution stops when an empty line is input.
#
# From the shell:
#
# ./square
#
# The following shows lines of input followed by output:
#
# 1234
# 1522756
# ln(2)
# ~.48045301391820142467
# config("mode","frac"), bernoulli(10)
# 25/4356
# config("mode", "hex"), 0xff
# 0xfe01
#
global s;
while ((s = prompt("")))
print "\t":eval(s)^2;

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: custom.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: custom.c,v 29.3 2001/03/17 21:31:47 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/custom.c,v $
*
* Under source code control: 1997/03/03 04:53:08
@@ -34,11 +34,10 @@
#include "value.h"
#include "custom.h"
#include <stdio.h>
#if defined(CUSTOM)
#include <stdio.h>
#include "calc.h"
#include "have_string.h"

View File

@@ -18,8 +18,8 @@
# received a copy with calc; if not, write to Free Software Foundation, Inc.
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
# @(#) $Revision: 29.2 $
# @(#) $Id: Makefile,v 29.2 2000/06/07 14:03:03 chongo Exp $
# @(#) $Revision: 29.6 $
# @(#) $Id: Makefile,v 29.6 2001/04/08 10:53:52 chongo Exp $
# @(#) $Source: /usr/local/src/cmd/calc/custom/RCS/Makefile,v $
#
# Under source code control: 1997/03/09 02:28:54
@@ -406,7 +406,10 @@ depend:
echo '#endif /* '"$$tag"' */' >> "skel/custom/$$i"; \
done
${Q}(cd ..; ${MAKE} hsrc)
${Q}for i in `cd ..; ${MAKE} h_list`; do \
${Q}for i in `cd ..; ${MAKE} h_list 2>&1 | \
${SED} -e '/Entering directory/d' \
-e '/Nothing to be done/d' \
-e '/Leaving directory/d'`; do \
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
echo "#if !defined($$tag)" > "skel/$$i"; \
echo "#define $$tag" >> "skel/$$i"; \
@@ -429,7 +432,8 @@ depend:
${Q}mv Makefile Makefile.bak
${Q}${SED} -n '1,/^# DO NOT DELETE THIS LINE/p' Makefile.bak > Makefile
${Q}echo "" >> Makefile
${Q}${SED} -n '3,$$p' skel/custom/makedep.out | ${SORT} -u >> Makefile
${Q}${SED} -n '3,$$p' skel/custom/makedep.out | \
LANG=C ${SORT} -u >> Makefile
-${Q}rm -rf skel
-${Q}if cmp -s Makefile.bak Makefile; then \
echo 'custom Makefile was already up to date'; \
@@ -457,7 +461,7 @@ clean:
clobber:
-rm -f ${TARGETS}
rm -f .all Makefile.tmp
rm -f .all Makefile.tmp Makefile.bak
install: all
-${Q}if [ ! -d ${TOPDIR} ]; then \
@@ -534,11 +538,13 @@ install: all
# DO NOT DELETE THIS LINE
c_argv.o: ../alloc.h
c_argv.o: ../block.h
c_argv.o: ../byteswap.h
c_argv.o: ../calc.h
c_argv.o: ../calcerr.h
c_argv.o: ../calc.h
c_argv.o: c_argv.c
c_argv.o: ../cmath.h
c_argv.o: ../config.h
c_argv.o: ../custom.h
@@ -554,16 +560,17 @@ c_argv.o: ../longbits.h
c_argv.o: ../md5.h
c_argv.o: ../nametype.h
c_argv.o: ../qmath.h
c_argv.o: ../shs.h
c_argv.o: ../shs1.h
c_argv.o: ../shs.h
c_argv.o: ../string.h
c_argv.o: ../value.h
c_argv.o: ../win32dll.h
c_argv.o: ../zmath.h
c_argv.o: c_argv.c
c_devnull.o: ../alloc.h
c_devnull.o: ../block.h
c_devnull.o: ../byteswap.h
c_devnull.o: ../calcerr.h
c_devnull.o: c_devnull.c
c_devnull.o: ../cmath.h
c_devnull.o: ../config.h
c_devnull.o: ../custom.h
@@ -579,16 +586,17 @@ c_devnull.o: ../longbits.h
c_devnull.o: ../md5.h
c_devnull.o: ../nametype.h
c_devnull.o: ../qmath.h
c_devnull.o: ../shs.h
c_devnull.o: ../shs1.h
c_devnull.o: ../shs.h
c_devnull.o: ../string.h
c_devnull.o: ../value.h
c_devnull.o: ../win32dll.h
c_devnull.o: ../zmath.h
c_devnull.o: c_devnull.c
c_help.o: ../alloc.h
c_help.o: ../block.h
c_help.o: ../byteswap.h
c_help.o: ../calcerr.h
c_help.o: c_help.c
c_help.o: ../cmath.h
c_help.o: ../config.h
c_help.o: ../custom.h
@@ -604,18 +612,19 @@ c_help.o: ../longbits.h
c_help.o: ../md5.h
c_help.o: ../nametype.h
c_help.o: ../qmath.h
c_help.o: ../shs.h
c_help.o: ../shs1.h
c_help.o: ../shs.h
c_help.o: ../string.h
c_help.o: ../value.h
c_help.o: ../win32dll.h
c_help.o: ../zmath.h
c_help.o: c_help.c
c_pzasusb8.o: ../alloc.h
c_pzasusb8.o: ../block.h
c_pzasusb8.o: ../byteswap.h
c_pzasusb8.o: ../calcerr.h
c_pzasusb8.o: ../cmath.h
c_pzasusb8.o: ../config.h
c_pzasusb8.o: c_pzasusb8.c
c_pzasusb8.o: ../custom.h
c_pzasusb8.o: ../endian_calc.h
c_pzasusb8.o: ../hash.h
@@ -629,20 +638,21 @@ c_pzasusb8.o: ../longbits.h
c_pzasusb8.o: ../md5.h
c_pzasusb8.o: ../nametype.h
c_pzasusb8.o: ../qmath.h
c_pzasusb8.o: ../shs.h
c_pzasusb8.o: ../shs1.h
c_pzasusb8.o: ../shs.h
c_pzasusb8.o: ../string.h
c_pzasusb8.o: ../value.h
c_pzasusb8.o: ../win32dll.h
c_pzasusb8.o: ../zmath.h
c_pzasusb8.o: c_pzasusb8.c
c_sysinfo.o: ../alloc.h
c_sysinfo.o: ../block.h
c_sysinfo.o: ../byteswap.h
c_sysinfo.o: ../calc.h
c_sysinfo.o: ../calcerr.h
c_sysinfo.o: ../calc.h
c_sysinfo.o: ../cmath.h
c_sysinfo.o: ../conf.h
c_sysinfo.o: ../config.h
c_sysinfo.o: c_sysinfo.c
c_sysinfo.o: ../custom.h
c_sysinfo.o: ../endian_calc.h
c_sysinfo.o: ../fposval.h
@@ -660,14 +670,14 @@ c_sysinfo.o: ../md5.h
c_sysinfo.o: ../nametype.h
c_sysinfo.o: ../prime.h
c_sysinfo.o: ../qmath.h
c_sysinfo.o: ../shs.h
c_sysinfo.o: ../shs1.h
c_sysinfo.o: ../shs.h
c_sysinfo.o: ../string.h
c_sysinfo.o: ../value.h
c_sysinfo.o: ../win32dll.h
c_sysinfo.o: ../zmath.h
c_sysinfo.o: ../zrand.h
c_sysinfo.o: ../zrandom.h
c_sysinfo.o: c_sysinfo.c
custtbl.o: ../alloc.h
custtbl.o: ../block.h
custtbl.o: ../byteswap.h
@@ -675,6 +685,7 @@ custtbl.o: ../calcerr.h
custtbl.o: ../cmath.h
custtbl.o: ../config.h
custtbl.o: ../custom.h
custtbl.o: custtbl.c
custtbl.o: ../endian_calc.h
custtbl.o: ../hash.h
custtbl.o: ../have_const.h
@@ -687,9 +698,9 @@ custtbl.o: ../longbits.h
custtbl.o: ../md5.h
custtbl.o: ../nametype.h
custtbl.o: ../qmath.h
custtbl.o: ../shs.h
custtbl.o: ../shs1.h
custtbl.o: ../shs.h
custtbl.o: ../string.h
custtbl.o: ../value.h
custtbl.o: ../win32dll.h
custtbl.o: ../zmath.h
custtbl.o: custtbl.c

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.3 $
* @(#) $Id: c_sysinfo.c,v 29.3 2000/06/07 14:03:03 chongo Exp $
* @(#) $Revision: 29.5 $
* @(#) $Id: c_sysinfo.c,v 29.5 2001/04/14 23:04:17 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/custom/RCS/c_sysinfo.c,v $
*
* Under source code control: 1997/03/09 23:14:40
@@ -64,7 +64,7 @@ struct infoname {
FULL nmbr; /* if str==NULL ==> value fo #define as a FULL */
};
static struct infoname sys_info[] = {
{"A55", "slots in an additive 55 table", NULL, (FULL)A55},
{"S100", "slots in an subtractive 100 table", NULL, (FULL)S100},
{"BASE", "base for calculations", NULL, (FULL)BASE},
{"BASE1", "one less than base", NULL, (FULL)BASE},
{"BASEB", "bits in the calculation base", NULL, (FULL)BASEB},
@@ -112,7 +112,6 @@ static struct infoname sys_info[] = {
{"MAXFILES", "max number of opened files", NULL, (FULL)MAXFILES},
{"MAXFULL", "largest SFULL value", NULL, (FULL)MAXFULL},
{"MAXHALF", "largest SHALF value", NULL, (FULL)MAXHALF},
{"MAXINDICES", "max number of indices for objects", NULL, (FULL)MAXINDICES},
{"MAXLABELS", "max number of user labels in function", NULL, (FULL)MAXLABELS},
{"MAXLEN", "longest storage size allowed", NULL, (FULL)MAXLEN},
{"MAXLONG", "largest long val", NULL, (FULL)MAXLONG},

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: endian.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: endian.c,v 29.3 2001/03/18 02:59:42 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/endian.c,v $
*
* Under source code control: 1993/11/15 04:32:58
@@ -48,8 +48,10 @@ char byte[8] = { (char)0x12, (char)0x36, (char)0x48, (char)0x59,
int
main(void)
{
#if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
/* pointers into the byte order array */
int *intp = (int *)byte;
#endif
#if defined(DEBUG)
short *shortp = (short *)byte;
long *longp = (long *)byte;
@@ -69,6 +71,11 @@ main(void)
printf("#define BIG_ENDIAN\t4321\n");
printf("#define LITTLE_ENDIAN\t1234\n");
#if defined(LITTLE_ENDIAN)
printf("#define CALC_BYTE_ORDER\tLITTLE_ENDIAN\n");
#elif defined(BIG_ENDIAN)
printf("#define CALC_BYTE_ORDER\tBIG_ENDIAN\n");
#else
/* Determine byte order */
if (intp[0] == 0x12364859) {
/* Most Significant Byte first */
@@ -81,6 +88,7 @@ main(void)
"Unknown int Byte Order, set CALC_BYTE_ORDER in Makefile\n");
exit(1);
}
#endif
/* exit(0); */
return 0;
}

161
file.c
View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: file.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.7 $
* @(#) $Id: file.c,v 29.7 2001/04/10 22:06:46 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/file.c,v $
*
* Under source code control: 1991/07/20 00:21:56
@@ -35,15 +35,23 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
#include <ctype.h>
#include "calc.h"
#include "longbits.h"
#include "have_fpos.h"
#include "have_fpos_pos.h"
#include "fposval.h"
#include "file.h"
#include "calcerr.h"
#if defined(_WIN32)
# include <io.h>
#endif
#define READSIZE 1024 /* buffer size for reading */
/*
@@ -150,7 +158,7 @@ file_init(void)
} else {
fp = (FILE *) fdopen(i, "w");
if (fp) {
strcpy(files[idnum].mode, "w?");
strcpy(files[idnum].mode, "w");
files[idnum].reading = FALSE;
}
else
@@ -199,7 +207,7 @@ openid(char *name, char *mode)
int i;
if (idnum >= MAXFILES)
return -77;
return -E_FOPEN3;
fiop = &files[3];
for (i = 3; i < MAXFILES; fiop++,i++) {
@@ -235,11 +243,32 @@ openid(char *name, char *mode)
fiop->reading = TRUE;
fiop->writing = TRUE;
fiop->action = 0;
if (mode[1] == '\0') {
if (*mode == 'r')
/*
* determine file open mode
*
* While a leading 'r' is for reading and a leading 'w' is
* for writing, the presense of a '+' in the string means
* both reading and writing. A leading 'a' means append
* which is writing.
*/
if (mode[0] == 'r') {
fiop->reading = TRUE;
if (strchr(mode, '+') == NULL) {
fiop->writing = FALSE;
else
} else {
fiop->writing = TRUE;
}
} else if (mode[0] == 'w' || mode[0] == 'a') {
fiop->writing = TRUE;
if (strchr(mode, '+') == NULL) {
fiop->reading = FALSE;
} else {
fiop->reading = TRUE;
}
} else {
fiop->reading = FALSE;
fiop->writing = FALSE;
}
strcpy(fiop->mode, mode);
return id;
@@ -338,11 +367,32 @@ reopenid(FILEID id, char *mode, char *name)
fiop->reading = TRUE;
fiop->writing = TRUE;
fiop->action = 0;
if (mode[1] == '\0') {
if (*mode == 'r')
/*
* determine file open mode
*
* While a leading 'r' is for reading and a leading 'w' is
* for writing, the presense of a '+' in the string means
* both reading and writing. A leading 'a' means append
* which is writing.
*/
if (mode[0] == 'r') {
fiop->reading = TRUE;
if (strchr(mode, '+') == NULL) {
fiop->writing = FALSE;
else
} else {
fiop->writing = TRUE;
}
} else if (mode[0] == 'w' || mode[0] == 'a') {
fiop->writing = TRUE;
if (strchr(mode, '+') == NULL) {
fiop->reading = FALSE;
} else {
fiop->reading = TRUE;
}
} else {
fiop->reading = FALSE;
fiop->writing = FALSE;
}
strcpy(fiop->mode, mode);
return id;
@@ -350,13 +400,13 @@ reopenid(FILEID id, char *mode, char *name)
/*
* Find the file I/O structure for the specified file id, and verify that
* it is opened in the required manner ('r' for reading or 'w' for writing).
* If mode is 0, then no open checks are made at all, and NULL is then
* Find the file I/O structure for the specified file id, and verifies that
* it is opened in the required manner (0 for reading or 1 for writing).
* If writable is -1, then no open checks are made at all and NULL is then
* returned if the id represents a closed file.
*/
FILEIO *
findid(FILEID id, int mode)
findid(FILEID id, int writable)
{
FILEIO *fiop; /* file structure */
int i;
@@ -375,21 +425,11 @@ findid(FILEID id, int mode)
if (i == idnum)
return NULL;
switch (mode) {
case 'r':
if (!fiop->reading)
return NULL;
break;
case 'w':
if (!fiop->writing)
return NULL;
break;
case 0:
break;
default:
/* This should not happen */
math_error("Unknown findid mode");
/*NOTREACHED*/
if (writable >= 0) {
if ((writable && !fiop->writing) ||
(!writable && !fiop->reading)) {
return NULL;
}
}
return fiop;
}
@@ -401,7 +441,7 @@ findid(FILEID id, int mode)
BOOL
validid(FILEID id)
{
return (findid(id, 0) != NULL);
return (findid(id, -1) != NULL);
}
@@ -497,7 +537,7 @@ errorid(FILEID id)
{
FILEIO *fiop; /* file structure */
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL)
return EOF;
return (ferror(fiop->fp) != 0);
@@ -512,7 +552,7 @@ eofid(FILEID id)
{
FILEIO *fiop; /* file structure */
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL)
return EOF;
return (feof(fiop->fp) != 0);
@@ -527,7 +567,7 @@ flushid(FILEID id)
{
FILEIO *fiop; /* file structure */
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL)
return 0;
if (!fiop->writing || fiop->action == 'r')
@@ -536,6 +576,7 @@ flushid(FILEID id)
}
#if !defined(_WIN32)
int
flushall(void)
{
@@ -551,6 +592,7 @@ flushall(void)
}
return err;
}
#endif /* Windoz free systems */
/*
@@ -588,7 +630,7 @@ readid(FILEID id, int flags, char **retptr)
totlen = 0;
str = NULL;
fiop = findid(id, 'r');
fiop = findid(id, FALSE);
if (fiop == NULL)
return 1;
nlstop = (flags & 1);
@@ -669,7 +711,7 @@ getcharid(FILEID id)
FILEIO *fiop;
FILEPOS fpos;
fiop = findid(id, 'r');
fiop = findid(id, FALSE);
if (fiop == NULL)
return -2;
if (fiop->action == 'w') {
@@ -700,7 +742,7 @@ printid(FILEID id, int flags)
/*
* filewall - file is closed
*/
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL) {
if (flags & PRINT_UNAMBIG)
math_fmt("FILE %d closed", id);
@@ -777,7 +819,7 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals)
BOOL printstring;
BOOL printchar;
fiop = findid(id, 'w');
fiop = findid(id, TRUE);
if (fiop == NULL)
return 1;
if (fiop->action == 'r') {
@@ -1004,7 +1046,7 @@ idfputc(FILEID id, int ch)
FILEPOS fpos;
/* get the file info pointer */
fiop = findid(id, 'w');
fiop = findid(id, TRUE);
if (fiop == NULL)
return 1;
if (fiop->action == 'r') {
@@ -1039,7 +1081,7 @@ idungetc(FILEID id, int ch)
{
FILEIO *fiop;
fiop = findid(id, 'r');
fiop = findid(id, FALSE);
if (fiop == NULL)
return -2;
if (fiop->action != 'r')
@@ -1062,7 +1104,7 @@ idfputs(FILEID id, char *str)
FILEPOS fpos;
/* get the file info pointer */
fiop = findid(id, 'w');
fiop = findid(id, TRUE);
if (fiop == NULL)
return 1;
@@ -1100,7 +1142,7 @@ idfputstr(FILEID id, char *str)
FILEPOS fpos;
/* get the file info pointer */
fiop = findid(id, 'w');
fiop = findid(id, TRUE);
if (fiop == NULL)
return 1;
@@ -1130,7 +1172,7 @@ int
rewindid(FILEID id)
{
FILEIO *fiop;
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL)
return 1;
rewind(fiop->fp);
@@ -1178,7 +1220,7 @@ filepos2z(FILEPOS pos)
ret.len = FILEPOS_BITS/BASEB;
ret.v = alloc(ret.len);
zclearval(ret);
SWAP_HALF_IN_FILEPOS(ret.v, &pos);
SWAP_HALF_IN_FILEPOS(ret.v, (HALF *)&pos);
ret.sign = 0;
ztrim(&ret);
@@ -1239,7 +1281,8 @@ z2filepos(ZVALUE zpos)
if (!zgtmaxfull(zpos)) {
/* ztofull puts the value into native byte order */
pos = ztofull(zpos);
ret = pos;
memset(&ret, 0, sizeof(FILEPOS));
memcpy((void *)&ret, (void *)&pos, sizeof(pos));
return ret;
}
@@ -1251,7 +1294,7 @@ z2filepos(ZVALUE zpos)
memcpy(&tmp, zpos.v, sizeof(FILEPOS));
} else {
/* copy what bits we can into the temp value */
tmp = 0;
memset(&tmp, 0, sizeof(FILEPOS));
memcpy(&tmp, zpos.v, zpos.len*BASEB/8);
}
/* swap into native byte order */
@@ -1317,7 +1360,7 @@ getloc(FILEID id, ZVALUE *res)
/*
* convert id to stream
*/
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL) {
/* file not open */
return -1;
@@ -1342,7 +1385,7 @@ ftellid(FILEID id, ZVALUE *res)
FILEPOS fpos; /* current file position */
/* get FILEIO */
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL)
return -2;
@@ -1365,7 +1408,7 @@ fseekid(FILEID id, ZVALUE offset, int whence)
int ret = 0; /* return code */
/* setup */
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL)
return -2;
@@ -1490,7 +1533,7 @@ setloc(FILEID id, ZVALUE zpos)
/*
* convert id to stream
*/
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL) {
/* file not open */
return -1;
@@ -1658,7 +1701,7 @@ getsize(FILEID id, ZVALUE *res)
/*
* convert id to stream
*/
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL) {
/* file not open */
return 1;
@@ -1694,7 +1737,7 @@ get_device(FILEID id, ZVALUE *dev)
/*
* convert id to stream
*/
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL) {
/* file not open */
return -1;
@@ -1727,7 +1770,7 @@ get_inode(FILEID id, ZVALUE *inode)
/*
* convert id to stream
*/
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL) {
/* file not open */
return -1;
@@ -1763,7 +1806,7 @@ zfilesize(FILEID id)
ZVALUE ret; /* file size as a ZVALUE return value */
/* file FILEIO */
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL) {
/* return neg value for non-file error */
itoz(-1, &ret);
@@ -2133,7 +2176,7 @@ fscanfid(FILEID id, char *fmt, int count, VALUE **vals)
FILE *fp;
FILEPOS fpos;
fiop = findid(id, 'r');
fiop = findid(id, FALSE);
if (fiop == NULL)
return -2;
@@ -2397,7 +2440,7 @@ isattyid(FILEID id)
{
FILEIO *fiop;
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL)
return -2;
return isatty(fileno(fiop->fp));
@@ -2434,7 +2477,7 @@ fsearch(FILEID id, char *str, ZVALUE start, ZVALUE end, ZVALUE *res)
long k = 0;
/* get FILEIO */
fiop = findid(id, 'r');
fiop = findid(id, FALSE);
if (fiop == NULL)
return -2;
@@ -2553,7 +2596,7 @@ frsearch(FILEID id, char *str, ZVALUE first, ZVALUE last, ZVALUE *res)
char *s; /* str comparison pointer */
/* get FILEIO */
fiop = findid(id, 'r');
fiop = findid(id, FALSE);
if (fiop == NULL)
return -2;
@@ -2630,7 +2673,7 @@ findfname(FILEID id)
{
FILEIO *fiop;
fiop = findid(id, 0);
fiop = findid(id, -1);
if (fiop == NULL)
return NULL;

8
file.h
View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: file.h,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: file.h,v 29.3 2001/04/10 22:06:46 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/file.h,v $
*
* Under source code control: 1996/05/24 05:55:58
@@ -50,7 +50,7 @@ typedef struct {
BOOL reading; /* TRUE if opened for reading */
BOOL writing; /* TRUE if opened for writing */
char action; /* most recent use for 'r', 'w' or 0 */
char mode[3]; /* open mode */
char mode[sizeof("rb+")];/* open mode */
} FILEIO;
@@ -85,7 +85,7 @@ typedef struct {
/*
* external functions
*/
extern FILEIO * findid(FILEID id, int mode);
extern FILEIO * findid(FILEID id, int writable);
extern int fgetposid(FILEID id, FILEPOS *ptr);
extern int fsetposid(FILEID id, FILEPOS *ptr);
extern int get_open_siz(FILE *fp, ZVALUE *res);

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: fposval.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.6 $
* @(#) $Id: fposval.c,v 29.6 2001/03/18 03:01:41 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/fposval.c,v $
*
* Under source code control: 1994/11/05 03:19:52
@@ -63,6 +63,7 @@
#include "endian_calc.h"
#include "have_offscl.h"
#include "have_posscl.h"
#include "have_fpos_pos.h"
char *program; /* our name */
@@ -83,7 +84,15 @@ main(int argc, char **argv)
/*
* print the file position information
*/
#if defined(HAVE_FPOS_POS)
fileposlen = FPOS_POS_BITS;
#else /* ! HAVE_FPOS_POS */
# if defined(FPOS_BITS)
fileposlen = FPOS_BITS;
# else
fileposlen = sizeof(FILEPOS)*8;
# endif
#endif /* ! HAVE_FPOS_POS */
printf("#undef FILEPOS_BITS\n");
printf("#define FILEPOS_BITS %d\n", fileposlen);
#if CALC_BYTE_ORDER == BIG_ENDIAN
@@ -113,8 +122,8 @@ main(int argc, char **argv)
* Normally a "(*(dest) = *(src))" would do, but on some
* systems a FILEPOS is not a scalar hince we must memcpy.
*/
printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t%s%d%s\n",
"memcpy((void *)(dest), (void *)(src), sizeof(",fileposlen,"))");
printf("#define SWAP_HALF_IN_FILEPOS(dest, src)\t%s\n",
"memcpy((void *)(dest), (void *)(src), sizeof(FPOS_POS_BITS))");
#endif /* HAVE_FILEPOS_SCALAR */
#endif /* CALC_BYTE_ORDER == BIG_ENDIAN */
putchar('\n');
@@ -122,7 +131,11 @@ main(int argc, char **argv)
/*
* print the stat file size information
*/
#if defined(OFF_T_BITS)
stsizelen = OFF_T_BITS;
#else
stsizelen = sizeof(buf.st_size)*8;
#endif
printf("#undef OFF_T_BITS\n");
printf("#define OFF_T_BITS %d\n", stsizelen);
#if CALC_BYTE_ORDER == BIG_ENDIAN
@@ -156,7 +169,7 @@ main(int argc, char **argv)
* systems, a off_t is not a scalar hince we must memcpy.
*/
printf("#define SWAP_HALF_IN_OFF_T(dest, src)\t%s%d%s\n",
"memcpy((void *)(dest), (void *)(src), sizeof(",stsizelen,"))");
"memcpy((void *)(dest), (void *)(src), ", stsizelen/8, ")");
#endif /* HAVE_OFF_T_SCALAR */
#endif /* CALC_BYTE_ORDER == BIG_ENDIAN */
putchar('\n');
@@ -164,7 +177,11 @@ main(int argc, char **argv)
/*
* print the dev_t size
*/
#if defined(DEV_BITS)
devlen = DEV_BITS;
#else
devlen = sizeof(buf.st_dev)*8;
#endif
printf("#undef DEV_BITS\n");
printf("#define DEV_BITS %d\n", devlen);
#if CALC_BYTE_ORDER == BIG_ENDIAN
@@ -193,14 +210,18 @@ main(int argc, char **argv)
* systems, a DEV is not a scalar hince we must memcpy.
*/
printf("#define SWAP_HALF_IN_DEV(dest, src)\t%s%d%s\n",
"memcpy((void *)(dest), (void *)(src), sizeof(",devlen,"))");
"memcpy((void *)(dest), (void *)(src), ", devlen/8, ")");
#endif /* CALC_BYTE_ORDER == BIG_ENDIAN */
putchar('\n');
/*
* print the ino_t size
*/
#if defined(INODE_BITS)
inodelen = INODE_BITS;
#else
inodelen = sizeof(buf.st_ino)*8;
#endif
printf("#undef INODE_BITS\n");
printf("#define INODE_BITS %d\n", inodelen);
#if CALC_BYTE_ORDER == BIG_ENDIAN
@@ -229,7 +250,7 @@ main(int argc, char **argv)
* systems, a INODE is not a scalar hince we must memcpy.
*/
printf("#define SWAP_HALF_IN_INODE(dest, src)\t%s%d%s\n",
"memcpy((void *)(dest), (void *)(src), sizeof(",inodelen,"))");
"memcpy((void *)(dest), (void *)(src), ", inodelen/8, ")");
#endif /* CALC_BYTE_ORDER == BIG_ENDIAN */
/* exit(0); */
return 0;

474
func.c
View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.3 $
* @(#) $Id: func.c,v 29.3 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.9 $
* @(#) $Id: func.c,v 29.9 2001/04/10 22:06:46 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/func.c,v $
*
* Under source code control: 1990/02/15 01:48:15
@@ -35,6 +35,11 @@
#include <sys/types.h>
#include <errno.h>
#if defined(_WIN32)
# include <io.h>
# define _access access
#endif
#if defined(FUNCLIST)
#define CONST /* disabled for FUNCLIST in case NATIVE_CC doesn't have it */
@@ -160,9 +165,9 @@ static STRINGHEAD newerrorstr;
/*
* arg count definitons
* arg count definitions
*/
#define IN 100 /* maximum number of arguments */
#define IN 1024 /* maximum number of arguments */
#define FE 0x01 /* flag to indicate default epsilon argument */
#define FA 0x02 /* preserve addresses of variables */
@@ -256,8 +261,8 @@ f_prompt(VALUE *vp)
cp = nextline();
closeinput();
if (cp == NULL) {
math_error("End of file while prompting");
/*NOTREACHED*/
result.v_type = V_NULL;
return result;
}
if (*cp == '\0') {
result.v_str = slink(&_nullstring_);
@@ -278,7 +283,7 @@ f_prompt(VALUE *vp)
static VALUE
f_display(int count, VALUE **vals)
{
long oldvalue;
LEN oldvalue;
VALUE res;
/* initialize VALUE */
@@ -293,9 +298,9 @@ f_display(int count, VALUE **vals)
fprintf(stderr,
"Out-of-range arg for display ignored\n");
else
conf->outdigits = qtoi(vals[0]->v_num);
conf->outdigits = (LEN) qtoi(vals[0]->v_num);
}
res.v_num = itoq(oldvalue);
res.v_num = itoq((long) oldvalue);
return res;
}
@@ -1012,7 +1017,7 @@ f_srand(int count, VALUE **vals)
break;
default:
math_error("illegal type of arg passsed to srand()");
math_error("illegal type of arg passed to srand()");
/*NOTREACHED*/
break;
}
@@ -1158,7 +1163,7 @@ f_srandom(int count, VALUE **vals)
break;
default:
math_error("illegal type of arg passsed to srandom()");
math_error("illegal type of arg passed to srandom()");
/*NOTREACHED*/
break;
}
@@ -1220,8 +1225,10 @@ f_primetest(int count, NUMBER **vals)
{
/* parse args */
switch (count) {
case 1: return itoq((long) qprimetest(vals[0], &_qone_, &_qone_));
case 2: return itoq((long) qprimetest(vals[0], vals[1], &_qone_));
case 1: return itoq((long) qprimetest(vals[0],
qlink(&_qone_), qlink(&_qone_)));
case 2: return itoq((long) qprimetest(vals[0],
vals[1], qlink(&_qone_)));
default: return itoq((long) qprimetest(vals[0], vals[1], vals[2]));
}
}
@@ -1253,37 +1260,76 @@ f_setbit(int count, VALUE **vals)
}
static NUMBER *
f_digit(NUMBER *val1, NUMBER *val2)
static VALUE
f_digit(int count, VALUE **vals)
{
if (qisfrac(val2)) {
math_error("Non-integral digit position");
/*NOTREACHED*/
VALUE res;
ZVALUE base;
if (vals[0]->v_type != V_NUM)
return error_value(E_DGT1);
if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num))
return error_value(E_DGT2);
if (count == 3) {
if (vals[2]->v_type != V_NUM || qisfrac(vals[2]->v_num))
return error_value(E_DGT3);
base = vals[2]->v_num->num;
} else {
base = _ten_;
}
if (qiszero(val1) || (qisint(val1) && qisneg(val2)))
return qlink(&_qzero_);
if (zge31b(val2->num)) {
if (qisneg(val2)) {
math_error("Very large digit position");
/*NOTREACHED*/
}
return qlink(&_qzero_);
}
return itoq((long) qdigit(val1, qtoi(val2)));
res.v_type = V_NUM;
res.v_num = qdigit(vals[0]->v_num, vals[1]->v_num->num, base);
if (res.v_num == NULL)
return error_value(E_DGT3);
return res;
}
static NUMBER *
f_digits(NUMBER *val)
static VALUE
f_digits(int count, VALUE **vals)
{
return itoq((long) qdigits(val));
ZVALUE base;
VALUE res;
if (vals[0]->v_type != V_NUM)
return error_value(E_DGTS1);
if (count > 1) {
if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num)
|| qiszero(vals[1]->v_num) || qisunit(vals[1]->v_num))
return error_value(E_DGTS2);
base = vals[1]->v_num->num;
} else {
base = _ten_;
}
res.v_type = V_NUM;
res.v_num = itoq(qdigits(vals[0]->v_num, base));
return res;
}
static NUMBER *
f_places(NUMBER *val)
static VALUE
f_places(int count, VALUE **vals)
{
return itoq((long) qplaces(val));
long places;
VALUE res;
if (vals[0]->v_type != V_NUM)
return error_value(E_PLCS1);
if (count > 1) {
if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num))
return error_value(E_PLCS2);
places = qplaces(vals[0]->v_num, vals[1]->v_num->num);
if (places == -2)
return error_value(E_PLCS2);
} else
places = qdecplaces(vals[0]->v_num);
res.v_type = V_NUM;
res.v_num = itoq(places);
return res;
}
@@ -1969,7 +2015,7 @@ f_ln(int count, VALUE **vals)
return result;
}
ctmp.real = vals[0]->v_num;
ctmp.imag = &_qzero_;
ctmp.imag = qlink(&_qzero_);
ctmp.links = 1;
c = cln(&ctmp, err);
break;
@@ -3128,6 +3174,135 @@ f_agd(int count, VALUE **vals)
}
static VALUE
f_comb(VALUE *v1, VALUE *v2)
{
long n;
VALUE result;
VALUE tmp1, tmp2, div;
if (v2->v_type != V_NUM || qisfrac(v2->v_num))
return error_value(E_COMB1);
result.v_subtype = V_NOSUBTYPE;
result.v_type = V_NUM;
if (qisneg(v2->v_num)) {
result.v_num = qlink(&_qzero_);
return result;
}
if (qiszero(v2->v_num)) {
result.v_num = qlink(&_qone_);
return result;
}
if (qisone(v2->v_num)) {
copyvalue(v1, &result);
return result;
}
if (v1->v_type == V_NUM) {
result.v_num = qcomb(v1->v_num, v2->v_num);
if (result.v_num == NULL)
return error_value(E_COMB2);
return result;
}
if (zge24b(v2->v_num->num))
return error_value(E_COMB2);
n = qtoi(v2->v_num);
copyvalue(v1, &result);
decvalue(v1, &tmp1);
div.v_type = V_NUM;
div.v_num = qlink(&_qtwo_);
n--;
for (;;) {
mulvalue(&result, &tmp1, &tmp2);
freevalue(&result);
divvalue(&tmp2, &div, &result);
freevalue(&tmp2);
if (--n == 0 || !testvalue(&result) || result.v_type < 0) {
freevalue(&tmp1);
freevalue(&div);
return result;
}
decvalue(&tmp1, &tmp2);
freevalue(&tmp1);
tmp1 = tmp2;
incvalue(&div, &tmp2);
freevalue(&div);
div = tmp2;
}
}
static VALUE
f_bern(VALUE *vp)
{
VALUE res;
if (vp->v_type != V_NUM || qisfrac(vp->v_num))
return error_value(E_BERN);
res.v_subtype = V_NOSUBTYPE;
res.v_type = V_NUM;
res.v_num = qbern(vp->v_num->num);
if (res.v_num == NULL)
return error_value(E_BERN);
return res;
}
static VALUE
f_freebern(void)
{
VALUE res;
qfreebern();
res.v_type = V_NULL;
res.v_subtype = V_NOSUBTYPE;
return res;
}
static VALUE
f_euler(VALUE *vp)
{
VALUE res;
if (vp->v_type!=V_NUM || qisfrac(vp->v_num))
return error_value(E_EULER);
res.v_subtype = V_NOSUBTYPE;
res.v_type = V_NUM;
res.v_num = qeuler(vp->v_num->num);
if (res.v_num == NULL)
return error_value(E_EULER);
return res;
}
static VALUE
f_freeeuler(void)
{
VALUE res;
qfreeeuler();
res.v_type = V_NULL;
res.v_subtype = V_NOSUBTYPE;
return res;
}
static VALUE
f_catalan(VALUE *vp)
{
VALUE res;
if (vp->v_type!=V_NUM || qisfrac(vp->v_num) || zge31b(vp->v_num->num))
return error_value(E_CTLN);
res.v_type = V_NUM;
res.v_subtype = V_NOSUBTYPE;
res.v_num = qcatalan(vp->v_num);
if (res.v_num == NULL)
return error_value(E_CTLN);
return res;
}
static VALUE
f_arg(int count, VALUE **vals)
{
@@ -3178,7 +3353,7 @@ f_trunc(int count, NUMBER **vals)
{
NUMBER *val;
val = &_qzero_;
val = qlink(&_qzero_);
if (count == 2)
val = vals[1];
return qtrunc(*vals, val);
@@ -3260,7 +3435,7 @@ f_btrunc(int count, NUMBER **vals)
{
NUMBER *val;
val = &_qzero_;
val = qlink(&_qzero_);
if (count == 2)
val = vals[1];
return qbtrunc(*vals, val);
@@ -3365,7 +3540,7 @@ f_ceil(VALUE *val)
tmp.v_subtype = V_NOSUBTYPE;
tmp.v_type = V_NUM;
tmp.v_num = &_qone_;
tmp.v_num = qlink(&_qone_);
apprvalue(val, &tmp, &tmp, &res);
return res;
}
@@ -3382,9 +3557,9 @@ f_floor(VALUE *val)
tmp2.v_subtype = V_NOSUBTYPE;
tmp1.v_type = V_NUM;
tmp1.v_num = &_qone_;
tmp1.v_num = qlink(&_qone_);
tmp2.v_type = V_NUM;
tmp2.v_num = &_qzero_;
tmp2.v_num = qlink(&_qzero_);
apprvalue(val, &tmp1, &tmp2, &res);
return res;
}
@@ -3488,24 +3663,82 @@ f_polar(int count, VALUE **vals)
}
static NUMBER *
f_ilog(NUMBER *val1, NUMBER *val2)
static VALUE
f_ilog(VALUE *v1, VALUE *v2)
{
return itoq(qilog(val1, val2));
VALUE res;
if (v2->v_type != V_NUM || qisfrac(v2->v_num) || qiszero(v2->v_num) ||
qisunit(v2->v_num))
return error_value(E_ILOGB);
switch(v1->v_type) {
case V_NUM:
res.v_num = qilog(v1->v_num, v2->v_num->num);
break;
case V_COM:
res.v_num = cilog(v1->v_com, v2->v_num->num);
break;
default:
return error_value(E_ILOG);
}
if (res.v_num == NULL)
return error_value(E_LOGINF);
res.v_type = V_NUM;
res.v_subtype = V_NOSUBTYPE;
return res;
}
static NUMBER *
f_ilog2(NUMBER *val)
static VALUE
f_ilog2(VALUE *vp)
{
return itoq(qilog2(val));
VALUE res;
switch(vp->v_type) {
case V_NUM:
res.v_num = qilog(vp->v_num, _two_);
break;
case V_COM:
res.v_num = cilog(vp->v_com, _two_);
break;
default:
return error_value(E_ILOG2);
}
if (res.v_num == NULL)
return error_value(E_LOGINF);
res.v_type = V_NUM;
res.v_subtype = V_NOSUBTYPE;
return res;
}
static NUMBER *
f_ilog10(NUMBER *val)
static VALUE
f_ilog10(VALUE *vp)
{
return itoq(qilog10(val));
VALUE res;
switch(vp->v_type) {
case V_NUM:
res.v_num = qilog(vp->v_num, _ten_);
break;
case V_COM:
res.v_num = cilog(vp->v_com, _ten_);
break;
default:
return error_value(E_ILOG10);
}
if (res.v_num == NULL)
return error_value(E_LOGINF);
res.v_type = V_NUM;
res.v_subtype = V_NOSUBTYPE;
return res;
}
@@ -4696,10 +4929,14 @@ f_listremove(VALUE *vp)
static NUMBER *
f_runtime(void)
{
#if defined(_WIN32)
return qlink(&_qzero_);
#else /* Windoz free systems */
struct tms buf;
times(&buf);
return iitoq((long) buf.tms_utime, (long) CLK_TCK);
#endif /* Windoz free systems */
}
@@ -4750,24 +4987,31 @@ f_fopen(VALUE *v1, VALUE *v2)
/* initialize VALUE */
result.v_subtype = V_NOSUBTYPE;
/* check for a valid mode [rwa][b+\0][b+\0] */
if (v1->v_type != V_STR || v2->v_type != V_STR)
return error_value(E_FOPEN1);
mode = v2->v_str->s_str;
if ((*mode != 'r') && (*mode != 'w') && (*mode != 'a'))
return error_value(E_FOPEN2);
if (mode[1] != '\0') {
if (mode[1] != '+')
return error_value(E_FOPEN2);
if (mode[2] != '\0')
if (mode[1] != '+' && mode[1] != 'b')
return error_value(E_FOPEN2);
if (mode[2] != '\0') {
if ((mode[2] != '+' && mode[2] != 'b') ||
mode[1] == mode[2])
return error_value(E_FOPEN2);
if (mode[3] != '\0')
return error_value(E_FOPEN2);
}
}
/* try to open */
errno = 0;
id = openid(v1->v_str->s_str, v2->v_str->s_str);
if (id == FILEID_NONE)
return error_value(errno);
if (id < 0)
return error_value(E_FOPEN3);
return error_value(-id);
result.v_type = V_FILE;
result.v_file = id;
return result;
@@ -4784,21 +5028,27 @@ f_freopen(int count, VALUE **vals)
/* initialize VALUE */
result.v_subtype = V_NOSUBTYPE;
/* check for a valid mode [rwa][b+\0][b+\0] */
if (vals[0]->v_type != V_FILE)
return error_value(E_FREOPEN1);
if (vals[1]->v_type != V_STR)
return error_value(E_FREOPEN2);
mode = vals[1]->v_str->s_str;
if ((*mode != 'r') && (*mode != 'w') && (*mode != 'a'))
return error_value(E_FREOPEN2);
if (mode[1] != '\0') {
if (mode[1] != '+')
return error_value(E_FREOPEN2);
if (mode[2] != '\0')
if (mode[1] != '+' && mode[1] != 'b')
return error_value(E_FREOPEN2);
if (mode[2] != '\0') {
if ((mode[2] != '+' && mode[2] != 'b') ||
mode[1] == mode[2])
return error_value(E_FOPEN2);
if (mode[3] != '\0')
return error_value(E_FREOPEN2);
}
}
/* try to reopen */
errno = 0;
if (count == 2) {
id = reopenid(vals[0]->v_file, mode, NULL);
@@ -5904,10 +6154,10 @@ f_fgetfield(VALUE *vp)
result.v_subtype = V_NOSUBTYPE;
if (vp->v_type != V_FILE)
return error_value(E_FGETWORD1);
return error_value(E_FGETFIELD1);
i = readid(vp->v_file, 14, &str);
if (i > 0)
return error_value(E_FGETWORD2);
return error_value(E_FGETFIELD2);
result.v_type = V_NULL;
if (i == 0) {
result.v_type = V_STR;
@@ -6459,6 +6709,19 @@ f_isatty(VALUE *vp)
}
static VALUE
f_calc_tty(void)
{
VALUE res;
if (!calc_tty(FILEID_STDIN))
return error_value(E_TTY);
res.v_type = V_NULL;
res.v_subtype = V_NOSUBTYPE;
return res;
}
static VALUE
f_inputlevel (void)
{
@@ -6646,11 +6909,64 @@ f_system(VALUE *vp)
if (conf->calc_debug & CALCDBG_SYSTEM) {
printf("%s\n", vp->v_str->s_str);
}
result.v_num = itoq((long) system(vp->v_str->s_str));
#if defined(_WIN32)
/* if the execute length is 0 then use NULL in system call */
if (strlen(vp->v_str->s_str) == 0) {
result.v_num = itoq((long)system(NULL));
} else {
result.v_num = itoq((long)system(vp->v_str->s_str));
}
#else /* Windoz free systems */
result.v_num = itoq((long)system(vp->v_str->s_str));
#endif /* Windoz free systems */
return result;
}
static VALUE
f_sleep(int count, VALUE **vals)
{
long time;
VALUE res;
NUMBER *q1, *q2;
res.v_type = V_NULL;
#if !defined(_WIN32)
if (count > 0) {
if (vals[0]->v_type != V_NUM || qisneg(vals[0]->v_num))
return error_value(E_SLEEP);
if (qisint(vals[0]->v_num)) {
if (zge31b(vals[0]->v_num->num))
return error_value(E_SLEEP);
time = ztoi(vals[0]->v_num->num);
time = sleep(time);
}
else {
q1 = qscale(vals[0]->v_num, 20);
q2 = qint(q1);
qfree(q1);
if (zge31b(q2->num)) {
qfree(q2);
return error_value(E_SLEEP);
}
time = ztoi(q2->num);
qfree(q2);
/* BSD 4.3 usleep has void return */
usleep(time);
return res;
}
} else {
time = sleep(1);
}
if (time) {
res.v_type = V_NUM;
res.v_num = itoq(time);
}
#endif /* Windoz free systems */
return res;
}
/*
* set the default output base/mode
*/
@@ -7493,6 +7809,8 @@ static CONST struct builtin builtins[] = {
"arithmetic mean of values"},
{"base", 0, 1, 0, OP_NOP, f_base, 0,
"set default output base"},
{"bernoulli", 1, 1, 0, OP_NOP, 0, f_bern,
"Bernoulli number for index a"},
{"bit", 2, 2, 0, OP_BIT, 0, 0,
"whether bit b in value a is set"},
{"blk", 0, 3, 0, OP_NOP, 0, f_blk,
@@ -7509,6 +7827,10 @@ static CONST struct builtin builtins[] = {
"truncate a to b number of binary places"},
{"calclevel", 0, 0, 0, OP_NOP, 0, f_calclevel,
"current calculation level"},
{"calc_tty", 0, 0, 0, OP_NOP, 0, f_calc_tty,
"set tty for interactivity"},
{"catalan", 1, 1, 0, OP_NOP, 0, f_catalan,
"catalan number for index a"},
{"ceil", 1, 1, 0, OP_NOP, 0, f_ceil,
"smallest integer greater than or equal to number"},
{"cfappr", 1, 3, 0, OP_NOP, f_cfappr, 0,
@@ -7521,7 +7843,7 @@ static CONST struct builtin builtins[] = {
"command buffer"},
{"cmp", 2, 2, 0, OP_CMP, 0, 0,
"compare values returning -1, 0, or 1"},
{"comb", 2, 2, 0, OP_NOP, qcomb, 0,
{"comb", 2, 2, 0, OP_NOP, 0, f_comb,
"combinatorial number a!/b!(a-b)!"},
{"config", 1, 2, 0, OP_SETCONFIG, 0, 0,
"set or read configuration value"},
@@ -7555,10 +7877,10 @@ static CONST struct builtin builtins[] = {
"denominator of fraction"},
{"det", 1, 1, 0, OP_NOP, 0, f_det,
"determinant of matrix"},
{"digit", 2, 2, 0, OP_NOP, f_digit, 0,
{"digit", 2, 3, 0, OP_NOP, 0, f_digit,
"digit at specified decimal place of number"},
{"digits", 1, 1, 0, OP_NOP, f_digits, 0,
"number of digits in number"},
{"digits", 1, 2, 0, OP_NOP, 0, f_digits,
"number of digits in base b representation of a"},
{"display", 0, 1, 0, OP_NOP, 0, f_display,
"number of decimal digits for displaying numbers"},
{"dp", 2, 2, 0, OP_NOP, 0, f_dp,
@@ -7573,6 +7895,8 @@ static CONST struct builtin builtins[] = {
"set or read calc_errno"},
{"error", 0, 1, 0, OP_NOP, 0, f_error,
"generate error value"},
{"euler", 1, 1, 0, OP_NOP, 0, f_euler,
"Euler number"},
{"eval", 1, 1, 0, OP_NOP, 0, f_eval,
"evaluate expression from string to value"},
{"exp", 1, 2, 0, OP_NOP, 0, f_exp,
@@ -7623,6 +7947,10 @@ static CONST struct builtin builtins[] = {
"write one or more null-terminated strings to a file"},
{"free", 0, IN, FA, OP_NOP, 0, f_free,
"free listed or all global variables"},
{"freebernoulli", 0, 0, 0, OP_NOP, 0, f_freebern,
"free stored Benoulli numbers"},
{"freeeuler", 0, 0, 0, OP_NOP, 0, f_freeeuler,
"free stored Euler numbers"},
{"freeglobals", 0, 0, 0, OP_NOP, 0, f_freeglobals,
"free all global and visible static variables"},
{"freeredc", 0, 0, 0, OP_NOP, 0, f_freeredc,
@@ -7663,11 +7991,11 @@ static CONST struct builtin builtins[] = {
"v mod h*2^n+r, h>0, n>0, r = -1, 0 or 1"},
{"hypot", 2, 3, FE, OP_NOP, qhypot, 0,
"hypotenuse of right triangle within accuracy c"},
{"ilog", 2, 2, 0, OP_NOP, f_ilog, 0,
"integral log of one number with another"},
{"ilog10", 1, 1, 0, OP_NOP, f_ilog10, 0,
{"ilog", 2, 2, 0, OP_NOP, 0, f_ilog,
"integral log of a to integral base b"},
{"ilog10", 1, 1, 0, OP_NOP, 0, f_ilog10,
"integral log of a number base 10"},
{"ilog2", 1, 1, 0, OP_NOP, f_ilog2, 0,
{"ilog2", 1, 1, 0, OP_NOP, 0, f_ilog2,
"integral log of a number base 2"},
{"im", 1, 1, 0, OP_IM, 0, 0,
"imaginary part of complex number"},
@@ -7833,8 +8161,8 @@ static CONST struct builtin builtins[] = {
"value of pi accurate to within epsilon"},
{"pix", 1, 2, 0, OP_NOP, f_pix, 0,
"number of primes <= a < 2^32, return b if error"},
{"places", 1, 1, 0, OP_NOP, f_places, 0,
"places after decimal point (-1 if infinite)"},
{"places", 1, 2, 0, OP_NOP, 0, f_places,
"places after \"decimal\" point (-1 if infinite)"},
{"pmod", 3, 3, 0, OP_NOP, qpowermod,0,
"mod of a power (a ^ b (mod c))"},
{"polar", 2, 3, 0, OP_NOP, 0, f_polar,
@@ -7937,6 +8265,8 @@ static CONST struct builtin builtins[] = {
"total number of elements in value"},
{"sizeof", 1, 1, 0, OP_NOP, 0, f_sizeof,
"number of octets used to hold the value"},
{"sleep", 0, 1, 0, OP_NOP, 0, f_sleep,
"suspend operatioo for a seconds"},
{"sort", 1, 1, 0, OP_NOP, 0, f_sort,
"sort a copy of a matrix or list"},
{"sqrt", 1, 3, 0, OP_NOP, 0, f_sqrt,

5
hash.c
View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.3 $
* @(#) $Id: hash.c,v 29.3 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.4 $
* @(#) $Id: hash.c,v 29.4 2001/04/14 22:47:21 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/hash.c,v $
*
* Under source code control: 1995/11/23 05:13:11
@@ -911,6 +911,7 @@ hash_value(int type, void *v, HASH *state)
(USB8 *)value->v_rand->buffer, SLEN*FULL_BITS/8);
state = hash_int(type, value->v_rand->j, state);
state = hash_int(type, value->v_rand->k, state);
state = hash_int(type, value->v_rand->need_to_skip, state);
(state->update)(state,
(USB8 *)value->v_rand->slot, SCNT*FULL_BITS/8);
(state->update)(state,

68
have_fpos_pos.c Normal file
View File

@@ -0,0 +1,68 @@
/*
* have_fpos_pos - Determine if a __pos element in FILEPOS
*
* Copyright (C) 2000 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.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: have_fpos_pos.c,v 29.2 2001/03/18 03:00:11 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/have_fpos_pos.c,v $
*
* Under source code control: 2000/12/17 01:23
* File existed as early as: 2000
*
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
*/
/*
* If the symbol HAVE_NO_FPOS is defined, we will output nothing.
* If the HAVE_FILEPOS_SCALAR is defuned, we will output nothing.
* If we are able to compile this program, then we must have the
* __pos element in a non-scalar FILEPOS.
*/
#include <stdio.h>
#include "have_fpos.h"
#include "have_posscl.h"
int
main(void)
{
#if !defined(HAVE_NO_FPOS) && !defined(HAVE_FILEPOS_SCALAR)
fpos_t pos; /* file position */
/* print a __pos element in fpos_t */
printf("#undef HAVE_FPOS_POS\n");
printf("#define HAVE_FPOS_POS 1 /* yes */\n\n");
/* determine __pos element size */
printf("#undef FPOS_POS_BITS\t/* no */\n");
# if defined(FPOS_POS_BITS)
printf("#define FPOS_POS_BITS %d\n\n", FPOS_POS_BITS);
# else
printf("#define FPOS_POS_BITS %d\n\n", sizeof(pos.__pos)*8);
# endif
#else
/* we have no __pos element */
printf("#undef HAVE_FPOS_POS\t/* no */\n");
printf("#undef FPOS_POS_BITS\n");
#endif
/* exit(0); */
return 0;
}

23
help.c
View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.4 $
* @(#) $Id: help.c,v 29.4 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.8 $
* @(#) $Id: help.c,v 29.8 2001/04/08 08:29:28 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/help.c,v $
*
* Under source code control: 1997/09/14 10:58:30
@@ -42,6 +42,11 @@
#include <unistd.h>
#endif
#if defined(_WIN32)
# define popen _popen
# define pclose _pclose
#endif
/*
* some help topics are symbols, so we alias them to nice filenames
@@ -57,6 +62,7 @@ static struct help_alias {
{".", "oldvalue"},
{"%", "mod"},
{"//", "quo"},
{"copy", "blkcpy"},
{"copying", "COPYING"},
{"copying-lgpl", "COPYING-LGPL"},
{"copying_lgpl", "COPYING-LGPL"},
@@ -65,6 +71,13 @@ static struct help_alias {
{"COPYRIGHT", "copyright"},
{"Copyleft", "copyright"},
{"COPYLEFT", "copyright"},
{"read", "command"},
{"write", "command"},
{"quit", "command"},
{"exit", "command"},
{"abort", "command"},
{"cd", "command"},
{"show", "command"},
{"stdlib", "resource"},
{NULL, NULL}
};
@@ -105,7 +118,11 @@ page_file(FILE *stream)
/*
* form a write pipe to a pager
*/
cmd = popen(pager, "w");
if (pager == NULL || pager[0] == '\0') {
cmd = stdout;
} else {
cmd = popen(pager, "w");
}
if (cmd == NULL) {
fprintf(stderr, "unable form pipe to pager: %s", pager);
return;

View File

@@ -18,8 +18,8 @@
# received a copy with calc; if not, write to Free Software Foundation, Inc.
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
# @(#) $Revision: 29.3 $
# @(#) $Id: Makefile,v 29.3 2000/06/07 14:02:33 chongo Exp $
# @(#) $Revision: 29.6 $
# @(#) $Id: Makefile,v 29.6 2001/04/08 10:53:52 chongo Exp $
# @(#) $Source: /usr/local/src/cmd/calc/help/RCS/Makefile,v $
#
# Under source code control: 1991/07/23 06:47:57
@@ -140,30 +140,31 @@ BLT_HELP_FILES= ${BLT_HELP_FILES_3} ${BLT_HELP_FILES_5} \
# This list is prodiced by the detaillist rule when no WARNINGS are detected.
#
DETAIL_HELP= abs access acos acosh acot acoth acsc acsch address agd append \
appr arg argv arrow asec asech asin asinh assign atan atan2 atanh \
avg base bit blk blkcpy blkfree blocks bround btrunc calclevel ceil \
cfappr cfsim char cmdbuf cmp comb conj cos cosh cot coth count cp \
csc csch ctime delete den dereference det digit digits dp epsilon \
errcount errmax errno error eval exp fact factor fclose fcnt feof \
ferror fflush fgetc fgetfield fgetline fgets fgetstr fib files floor \
fopen forall fprintf fputc fputs fputstr frac free freeglobals \
freeredc freestatics frem freopen fscan fscanf fseek fsize ftell \
gcd gcdrem gd getenv hash head highbit hmean hnrmod hypot ilog \
ilog10 ilog2 im indices inputlevel insert int inverse iroot isassoc \
isatty isblk isconfig isdefined iserror iseven isfile ishash isident \
isint islist ismat ismult isnull isnum isobj isobjtype isodd isprime \
isptr isqrt isrand israndom isreal isrel issimple issq isstr istype \
jacobi join lcm lcmfact lfactor ln lowbit ltol makelist matdim \
matfill matmax matmin matsum mattrace mattrans max md5 memsize meq \
min minv mmin mne mod modify name near newerror nextcand nextprime \
norm null num oldvalue ord param perm pfact pi pix places pmod polar \
poly pop popcnt power prevcand prevprime printf prompt protect ptest \
appr arg argv arrow asec asech asin asinh assign atan atan2 atanh avg \
base bernoulli bit blk blkcpy blkfree blocks bround btrunc calc_tty \
calclevel catalan ceil cfappr cfsim char cmdbuf cmp comb conj cos \
cosh cot coth count cp csc csch ctime delete den dereference det \
digit digits dp epsilon errcount errmax errno error euler eval \
exp fact factor fclose fcnt feof ferror fflush fgetc fgetfield \
fgetline fgets fgetstr fib files floor fopen forall fprintf fputc \
fputs fputstr frac free freebernoulli freeeuler freeglobals freeredc \
freestatics frem freopen fscan fscanf fseek fsize ftell gcd gcdrem \
gd getenv hash head highbit hmean hnrmod hypot ilog ilog10 ilog2 \
im indices inputlevel insert int inverse iroot isassoc isatty isblk \
isconfig isdefined iserror iseven isfile ishash isident isint islist \
ismat ismult isnull isnum isobj isobjtype isodd isprime isptr isqrt \
isrand israndom isreal isrel issimple issq isstr istype jacobi join \
lcm lcmfact lfactor ln lowbit ltol makelist matdim matfill matmax \
matmin matsum mattrace mattrans max md5 memsize meq min minv mmin \
mne mod modify name near newerror nextcand nextprime norm null \
num oldvalue ord param perm pfact pi pix places pmod polar poly \
pop popcnt power prevcand prevprime printf prompt protect ptest \
push putenv quo quomod rand randbit random randombit randperm rcin \
rcmul rcout rcpow rcsq re remove reverse rewind rm root round rsearch \
runtime saveval scale scan scanf search sec sech seed segment select \
sgn sha sha1 sin sinh size sizeof sort sqrt srand srandom ssq str \
strcat strerror strlen strpos strprintf strscan strscanf substr \
sum swap system tail tan tanh test time trunc xor
sgn sha sha1 sin sinh size sizeof sleep sort sqrt srand srandom \
ssq str strcat strerror strlen strpos strprintf strscan strscanf \
substr sum swap system tail tan tanh test time trunc xor
# This list is of files that are clones of DETAIL_HELP files. They are
# built from DETAIL_HELP files.
@@ -454,7 +455,7 @@ builtin: builtin.top builtin.end ../func.c funclist.sed
distlist: ${DISTLIST}
${Q}for i in ${DISTLIST}; do \
echo help/$$i; \
done | ${SORT}
done | LANG=C ${SORT}
distdir:
${Q}echo help
@@ -484,7 +485,7 @@ detaillist:
else \
echo $$i; \
fi; \
done | ${SORT}) | ${FMT} -70 | \
done | LANG=C ${SORT}) | ${FMT} -70 | \
${SED} -e '1s/xxxxx/DETAIL_HELP=/' -e '2,$$s/^/ /' \
-e 's/$$/ \\/' -e '$$s/ \\$$//'

67
help/bernoulli Normal file
View File

@@ -0,0 +1,67 @@
NAME
bernoulli - Bernoulli number
SYNOPSIS
bernoulli(n)
TYPES
n integer, n < 2^31 if even
return rational
DESCRIPTION
Returns the Bernoulli number with index n, i.e. the coefficient B_n in
the expansion
t/(exp(t) - 1) = Sum B_n * t^n/n!
bernouuli(n) is zero both for n < 0 and for n odd and > 2.
When bernoulli(n) is computed for positive even n, the values for
n and smaller positive even indices are stored in a table so that
a later call to bernoulli(k) with 0 <= k < n will be executed quickly.
Considerable runtime and memory are required for calculating
bernoulli(n) for large even n. For n = 1000, the numerator has
1779 digits, the denominator 9 digits.
The memory used to store calculated bernoulli numbers is freed by
freebernoulli().
EXAMPLE
> config("mode", "frac"),;
> for (n = 0; n <= 6; n++) print bernoulli(n),; print;
1 -1/2 1/6 0 -1/30 0 1/42
LIMITS
n < 2^31-1
LIBRARY
NUMBER *qbernoulli(long n)
SEE ALSO
euler, catalan, comb, fact, perm
## Copyright (C) 2000 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
## as published by the Free Software Foundation.
##
## Calc is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
## Public License for more details.
##
## A copy of version 2.1 of the GNU Lesser General Public License is
## distributed with calc under the filename COPYING-LGPL. You should have
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.4 $
## @(#) $Id: bernoulli,v 29.4 2000/12/17 12:27:58 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/bernoulli,v $
##
## Under source code control: 2000/07/13 01:33:00
## File existed as early as: 2000
##
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

52
help/calc_tty Normal file
View File

@@ -0,0 +1,52 @@
NAME
calc_tty - restore normal input conditions for interactive use
SYNOPSIS
calc_tty()
TYPES
return none if appears to be successful, error-value otherwise
DESCRIPTION
This may enable a return to normal operation if abnormal activity
results from a change of one or more terminal characteristics, as
may occur when activity is resumed by an fg command after a ctrl-Z
interrupt, or by any of the three commands:
> !stty echo
> !stty -cbreak
> !stty echo -cbreak
EXAMPLE
> calc_tty();
LIBRARY
none
SEE ALSO
none
## Copyright (C) 2000 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
## as published by the Free Software Foundation.
##
## Calc is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
## Public License for more details.
##
## A copy of version 2.1 of the GNU Lesser General Public License is
## distributed with calc under the filename COPYING-LGPL. You should have
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.1 $
## @(#) $Id: calc_tty,v 29.1 2000/12/14 10:31:45 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/calc_tty,v $
##
## Under source code control: 2000/12/14 01:33:00
## File existed as early as: 2000
##
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

63
help/catalan Normal file
View File

@@ -0,0 +1,63 @@
NAME
catalan - Catalan number
SYNOPSIS
catalan(n)
TYPES
n integer
return integer
DESCRIPTION
If n >= 0, this returns the Catalan number for index n:
catalan(n) = comb(2*n,n)/(n + 1)
Zero is returned for negative n.
The Catalan numbers occur in solutions of several elementary
combinatorial problems, e.g. for n >= 1, catalan(n) is the number of
ways of using parentheses to express a product of n + 1 letters in
terms of binary products; it is the number of ways of dissecting a
convex polygon with n + 2 sides into triangles by nonintersecting
diagonals; it is the number of integer-component-incrementing paths
from (x,y) = (0,0) to (x,y) = (n,n) for which always y <= x.
EXAMPLE
> print catalan(2), catalan(3), catalan(4), catalan(20)
2 5 14 6564120420
LIMITS
none
LINK LIBRARY
NUMBER *qcatalan(NUMBER *n)
SEE ALSO
comb, fact, perm
## Copyright (C) 2000 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
## as published by the Free Software Foundation.
##
## Calc is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
## Public License for more details.
##
## A copy of version 2.1 of the GNU Lesser General Public License is
## distributed with calc under the filename COPYING-LGPL. You should have
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: catalan,v 29.2 2000/12/17 12:27:58 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/catalan,v $
##
## Under source code control: 2000/12/14 01:33:00
## File existed as early as: 2000
##
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -47,6 +47,7 @@ Configuration parameters
"ctrl_d" The interactive meaning of ^D (Control D)
"program" Read-only calc program or shell script path
"basename" Read-only basename of the program value
"windows" Read-only indicator of MS windows
"version" Read-only calc version
The "all" config value allows one to save/restore the configuration
@@ -509,7 +510,9 @@ Detailed config descriptions
5 Report on changes to the run state of calc.
Bits >= 6 are reserved for future use and should not be used at this time.
6 Report on rand() subtractive 100 shuffle generator issues.
Bits >= 7 are reserved for future use and should not be used at this time.
By default, "calc_debug" is 0. The initial value may be overridden
by the -D command line option.
@@ -539,6 +542,9 @@ Detailed config descriptions
2 Show func will display more information about a functions
arguments as well as more argument sdummary information.
3 During execution, allow calc standard resource files
to output additional debugging information.
The value for config("resource_debug") in both oldstd and newstd is 3,
but if calc is invoked with the -d flag, its initial value is zero.
Thus, if calc is started without the -d flag, until config("resource_debug")
@@ -674,6 +680,13 @@ Detailed config descriptions
=-=
config("windows") <== NOTE: This is a read-only config value
Returns TRUE if you are running on a MS windows system, false if you
are running on an operating system that does not hate you.
=-=
config("version") <== NOTE: This is a read-only config value
The version string of the calc program can be obtained by:
@@ -698,8 +711,8 @@ Detailed config descriptions
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: config,v 29.2 2000/06/07 14:02:33 chongo Exp $
## @(#) $Revision: 29.5 $
## @(#) $Id: config,v 29.5 2001/04/14 22:46:33 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/config,v $
##
## Under source code control: 1991/07/21 04:37:17

View File

@@ -1,121 +1,197 @@
Function definitions
NAME
define - command keyword to start a function definition
Function definitions are introduced by the 'define' keyword.
Other than this, the basic structure of an ordinary definition
is like in that in C: parameters are specified for the function
within parenthesis, the function body is introduced by a left brace,
variables may declared for the function, statements implementing the
function may follow, any value to be returned by the function is specified
by a return statement, and the function definition is ended with a
right brace.
SYNTAX
define fname([param_1 [= default_1], ...]) = [expr]
define fname([param_1 [= default_1], ...]) { [statement_1 ... ] }
There are some subtle differences, however. The types of parameters
and variables are not defined at compile time, and may vary during
execution and be different in different calls to the function. For
example, a two-argument function add may be defined by
TYPES
fname identifier, not a builtin function name
param_1, ... identifiers, no two the same
default_1, ... expressions
expr expression
statement_1, ... statements
define add(a,b) {
return a + b;
}
DESCRIPTION
The intention of a function definition is that the identifier fname
becomes the name of a function which may be called by an expression
of the form fname(arg_1, arg_2, ...), where arg_1, arg_2, ... are
expressions (including possibly blanks, which are treated as
null values). Evaluation of the function begins with evaluation
of arg_1, arg_2, ...; then, in increasing order of i, if arg_i is
null-valued and "= default_i" has been included in the definition,
default_i is evaluated and its value becomes the value of arg_i.
The instructions in expr or the listed statements are then executed
with each occurrence of param_i replaced by the value obtained
for arg_i.
and be called with integer, fractional, or complex number values for a
and b, or, under some compatibility conditions, matrices or objects.
Any variable, not already defined as global, used in a definition has
to be declared as local, global or static, and retains this character
until its scope is terminated by the end of the definition, the end of
the file being read or some other condition (see help variable for
details).
In a call, arg_i may be preceded by a backquote (`) to indicate that
evaluation of arg_i is not to include a final evaluation of an lvalue.
For example, suppose a function f and a global variable A have been
defined by:
For example, the following function computes the factorial of n, where
we may suppose it is to be called only with positive integral values
for n:
define f(x) = (x = 3);
global mat A[3];
define factorial(n)
{
local ans;
If g() is a function that evaluates to 2:
ans = 1;
while (n > 1)
ans *= n--;
return ans;
}
f(A[g()]);
(In calc, this definition is unncessary since there is a built-in
function fact(n), also expressible as n!, which returns the factorial
of n.)
assigns the value of A[2] to the parameter x and then assigns the
value 3 to x:
Any functions used in the body of the definition need not have already
been defined; it is sufficient that they have been defined when they are
encountered during evaluation when the function is called.
f(`A[g()]);
If a function definition is sufficiently simple and does not require
local or static variables, it may be defined in shortened manner by
using an equals sign following by an expression involving some or all
of the parameters and already existing global variables.
has essentially the effect of assigning A[2] as an lvalue to x and
then assigning the value 3 to A[2]. (Very old versions of calc
achieved the same result by using '&' as in f(&A[g()]).)
In this case, the definition is terminated by a newline character
(which may be preceded by a semicolon), and the value the function
returns when called will be determined by the specified expression.
Loops and "if" statements are not allowed (but ? : expressions and the
logical operators ||, && and ! are permitted). As an example, the
average of two numbers could be defined as:
The number of arguments arg_1, arg_2, ... in a call need not equal the
number of parameters. If there are fewer arguments than parameters,
the "missing" values are assigned the null value.
define average(a, b) = (a + b) / 2;
In the definition of a function, the builtin function param(n)
provides a way of referring to the parameters. If n (which may
result from evaluating an expreession) is zero, it returns the number
of arguments in a call to the function, and if 1 <= n <= param(0),
param(n) refers to the parameter with index n.
(Again, this function is not necessary, as the same result is
returned by the builtin function avg() when called with the
two arguments a, b.)
If no error occurs and no quit statement or abort statement is
encountered during evaluation of the expression or the statements,
the function call returns a value. In the expression form, this is
simply the value of the expression.
Function definitions can be very complicated. Functions may be
defined on the command line if desired, but editing of partial
functions is not possible past a single line. If an error is made
on a previous line, then the function must be finished (with probable
errors) and reentered from the beginning. Thus for complicated
functions, it is best to use an editor to create the definition in a
file, and then enter the calculator and read in the file containing
the definition.
In the statement form, if a return statement is encountered,
the "return" keyword is to be either immediately followed by an
expression or by a statement terminator (semicolon or rightbrace);
in the former case, the expression is evaluated, evaluation of
the function ceases, and the value obtained for the expression is
returned as the "value of the function"; in the no-expression case,
evaluation ceases immediately and the null-value is returned.
The parameters of a function can be referenced by name, as in
normal C usage, or by using the 'param' function. This function
returns the specified parameter of the function it is in, where
the parameters are numbered starting from 1. The total number
of parameters to the function is returned by using 'param(0)'.
Using this function allows you to implement varargs-like routines
which can handle up to 100 calling parameters. For example:
In the expression form of definition, the end of the expression expr
is to be indicated by either a semicolon or a newline not within
a part enclosed by parentheses; the definition may extend over
several physical lines by ending each line with a '\' character or by
enclosing the expression in parentheses. In interactive mode, that
a definition has not been completed is indicated by the continuation
prompt. A ctrl-C interrupt at this stage will abort the definition.
define sc()
{
local s, i;
If the expr is omitted from an expression definition, as in:
s = 0;
for (i = 1; i <= param(0); i++)
s += param(i)^3;
return s;
}
define h() = ;
defines a function which returns the sum of the cubes of all its
parameters.
any call to the function will evaluate the arguments and return the
null value.
Any identifier other than a reserved word (if, for, etc.) and the
name of a builtin function (abs, fact, sin, etc.) can be used when
defining a new function or redefining an existing function.
In the statement form, the definition ends when a matching right
brace completes the "block" started by the initial left brace.
Newlines within the block are treated as white space; statements
within the block end with a ';' or a '}' matching an earlier '{'.
An indication of how a user-defined function is stored may be obtained
by using the "show opcodes" command. For example:
If a function with name fname had been defined earlier, the old
definition has no effect on the new definition, but if the definition
is completed successfully, the new definition replaces the old one;
otherwise the old definition is retained. The number of parameters
and their names in the new definiton may be quite different from
those in the old definition.
> global alpha
> define f(x) = 5 + alpha * x
"f" defined
> show opcodes f
0: NUMBER 5
2: GLOBALADDR alpha
4: PARAMADDR 0
6: MUL
7: ADD
8: RETURN
An attempt at a definition may fail because of scanerrors as the
definition is compiled. Common causes of these are: bad syntax,
using identifiers as names of variables not yet defined. It is
not a fault to have in the definition a call to a function that has
not yet been defined; it is sufficient that the function has been
defined when a call is made to the function.
After fname has been defined, the definition may be removed by the command:
## Copyright (C) 1999 Landon Curt Noll
undefine fname
The definitions of all user-defined functions may be removed by:
undefine *
If bit 0 of config("resource_debug") is set and the define command is
at interactive level, a message saying that fname has been defined
or redefined is displayed. The same message is displayed if bit 1
of config("resource_debug") is set and the define command is read
from a file.
The identifiers used for the parameters in a function definition do
not form part of the completed definition. For example,
define f(a,b) = a + b;
define g(alpha, beta) = alpha + beta;
result in identical code for the functions f, g.
If config("trace") & 8 is nonzero, the opcodes of a newly defined
function are displayed on completion of its definition, parameters
being specified by names used in the definition. For example:
> config("trace", 8),
> define f(a,b) = a + b
0: PARAMADDR a
2: PARAMADDR b
4: ADD
5: RETURN
f(a,b) defined
The opcodes may also be displayed later using the show opcodes command;
parameters will be specified by indices instead of by names. For example:
> show opco f
0: PARAMADDR 0
2: PARAMADDR 1
4: ADD
5: RETURN
When a function is defined by the statement mode, the opcodes normally
include DEBUG opcodes which specify statement boundaries at which
SIGINT interruptions are likely to be least risky. Inclusion of
the DEBUG opcodes is disabled if config("trace") & 2 is nonzero.
For details, see help interrupt.
While config("trace") & 1 is nonzero, the opcodes are displayed as
they are being evaluated. The current function is identified by its
name, or "*" in the case of a command-line and "**" in the case of
an eval(str) evaluation.
When a function is called, argument values may be of any type for
which the operations and any functions used within the body of the
definition can be executed. For example, whatever the intention at
the time they were defined, the functions f1(), f2() defined above
may be called with integer, fractional, or complex-number values, or
with both arguments strings, or under some compatibility conditions,
matrices or objects.
EXAMPLE
> define f(a,b) = 2*a + b;
> define g(alpha, beta)
>> {
>> local a, pi2;
>>
>> pi2 = 2 * pi();
>> a = sin(alpha % pi2);
>> if (a > 0.0) {
>> return a*beta;
>> }
>> if (beta > 0.0) {
>> a *= cos(-beta % pi2);
>> }
>> return a;
>> }
LIMITS
The number of arguments in a function-call cannot exceed 100.
LIBRARY
none
SEE ALSO
param, variable, undefine, show
## Copyright (C) 2000 David I. Bell, Landon Curt Noll and 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
@@ -131,10 +207,11 @@ Function definitions
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: define,v 29.2 2000/06/07 14:02:33 chongo Exp $
## @(#) $Revision: 29.3 $
## @(#) $Id: define,v 29.3 2000/07/17 15:36:26 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/define,v $
##
##
## Under source code control: 1991/07/21 04:37:18
## File existed as early as: 1991
##

View File

@@ -1,38 +1,93 @@
NAME
digit - digit at specified position in a decimal representation
digit - digit at specified position in a "decimal" representation
SYNOPSIS
digit(x, y)
digit(x, n [, b])
TYPES
x real
y integer
n integer
b integer >= 2, default = 10
return integer
DESCRIPTION
By extending the digits on the left, and if necessary, the digits
on the right, by infinite strings of zeros, abs(x) may be considered
to have the decimal representation:
... d_2 d_1 d_0.d_-1 d_-2 ...
d(x,n,b) returns the digit with index n in a standard base-b "decimal"
representation of x, which may be described as follows:
For an arbitrary base b >= 2, following the pattern of decimal (base 10)
notation in elementary arithmetic, a base-b "decimal" representation of
a positive real number may be considered to be specified by a finite or
infinite sequence of "digits" with possibly a "decimal" point
to indicate where the fractional part of the representation begins.
Just as the digits for base 10 are the integers 0, 1, 2, ..., 9, the
digits for a base-b representation are the integers d for which
0 <= d < b. The index for a digit position is the count, positively to
the left, of the number from the "units" position immediately to the
left of the "decimal" point; the digit d_n at position n contributes
additively d_n * b^n to the value of x. For example,
d_2 d_1 d_0 . d_-1 d_-2
represents the number
d_2 * b^2 + d_1 * b + d0 + d_-1 * b^-1 + d_-2 * b^-2
The sequence of digits has to be infinite if den(x) has a prime factor
which is not a factor of the base b. In cases where the representation
may terminate, the digits are considered to continue with an infinite
string of zeros rather than the other possibility of an infinite
sequence of (b - 1)s. Thus, for the above example, d_n = 0 for
n = -3, -4, ... Similarly, a representation may be considered to
continue with an infinite string of zeros on the left, so that in the
above example d_n = 0 also for n >= 3.
For negative x, digit(x,n,b) is given by digit(abs(x),n,b); the
standard "decimal" representation of this x is a - sign followed by
the representation of abs(x).
In calc, the "real" numbers are all rational and for these the
digits following the decimal point eventually form a recurring sequence.
With base-b digits for x as explained above, the integer whose base-b
representation is
b_n+k-1 b_n_k-2 ... b_n,
i.e. the k digits with last digit b_n, is given by
digit(b^-r * x, q, b^k)
if r and q satisfy n = q * b + r.
digit(x,y) then returns the digit d_y.
EXAMPLE
> x = 12.34
> print digit(x,2), digit(x,1), digit(x,0), digit(x,-1), digit(x,-2)
0 1 2 3 4
> a = 123456.789
> for (n = 6; n >= -6; n++) print digit(a, n),; print
0 1 2 3 4 5 6 7 8 9 0 0 0
> x = 10/7
> print digit(x,1), digit(x,0), digit(x,-1), digit(x,-2), digit(x,-3)
0 1 4 2 8
> for (n = 6; n >= -6; n--) print digit(a, n, 100),; print
0 0 0 0 12 34 56 78 90 0 0 0 0
> for (n = 6; n >= -6; n--) print digit(a, n, 256),; print
0 0 0 0 1 226 64 201 251 231 108 139 67
> for (n = 1; n >= -12; n++) print digit(10/7, n),; print
> 0 1 4 2 8 5 7 1 4 2 8 5 7 1
> print digit(10/7, -7e1000, 1e6)
428571
LIMITS
If x is not an integer, y > -2^31
The absolute value of the integral part of x is assumed to be less
than 2^2^31, ensuring that digit(x, n, b) will be zero if n >= 2^31.
The size of negative n is limited only by the capacity of the computer
being used.
LINK LIBRARY
long qdigit(NUMBER *x, long y)
NUMBER * qdigit(NUMBER *q, ZVALUE dpos, ZVALUE base)
SEE ALSO
bit
@@ -53,8 +108,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: digit,v 29.2 2000/06/07 14:02:33 chongo Exp $
## @(#) $Revision: 29.4 $
## @(#) $Id: digit,v 29.4 2000/12/17 12:27:58 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/digit,v $
##
## Under source code control: 1995/10/03 10:40:01

View File

@@ -1,30 +1,36 @@
NAME
digits - return number of digits in an integer or integer part
digits - return number of "decimal" digits in an integral part
SYNOPSIS
digits(x)
digits(x [,b])
TYPES
x real
b integer >= 2, defaults to 10
return integer
DESCRIPTION
For real x, digits(x) returns the number of digits in the decimal
representation of int(abs(x)). If x >= 1, digits(x) = 1 + ilog10(x).
Returns the least non-negative integer n for which abs(x) < b^n.
digits(x, b) = 0 if and only if abs(x) < 1.
For real x with absolute value >= 1, digits(x, b) is the number
of digits in the standard base-b "decimal" representation of int(abs(x));
this is also given by 1 + ilog(x, b).
EXAMPLE
> print digits(0), digits(0.0123), digits(3.7), digits(-27), digits(-99.7)
1 1 1 2 2
0 0 1 2 2
LIMITS
none
LINK LIBRARY
long qdigits(NUMBER *x)
long qdigits(NUMBER *q, ZVALUE base)
SEE ALSO
places
digit, places
## Copyright (C) 1999 Landon Curt Noll
##
@@ -42,8 +48,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: digits,v 29.2 2000/06/07 14:02:33 chongo Exp $
## @(#) $Revision: 29.3 $
## @(#) $Id: digits,v 29.3 2000/12/14 10:32:24 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/digits,v $
##
## Under source code control: 1995/10/03 10:40:01

63
help/euler Normal file
View File

@@ -0,0 +1,63 @@
NAME
euler - Euler number
SYNOPSIS
euler(n)
TYPES
n integer, n <= 1000000 if even
return integer
DESCRIPTION
Returns the Euler number with index n, i.e. the coefficient E_n in
the expansion
sech(t) = Sigma E_n * t^n/n!
When euler(n) is computed for positive even n, the values for
n and smaller positive even indices are stored in a table so that
a later call to euler(k) with 0 <= k <= n will be executed quickly.
If euler(k) is called with negative k, zero is returned and the
memory used by the table iu freed.
Considerable runtime and memery are required for calculating
euler(n) for large even n.
EXAMPLE
> for (n = 0; n <= 6; n++) print euler(n),; print;
1 0 -1 0 5 0 -61
LIMITS
none
LINK LIBRARY
NUMBER *qeuler(long n)
SEE ALSO
bernoulli, bell, catalan, comb, fact, perm
## Copyright (C) 2000 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
## as published by the Free Software Foundation.
##
## Calc is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
## Public License for more details.
##
## A copy of version 2.1 of the GNU Lesser General Public License is
## distributed with calc under the filename COPYING-LGPL. You should have
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: euler,v 29.2 2000/12/17 12:27:58 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/euler,v $
##
## Under source code control: 2000/12/14 01:33:00
## File existed as early as: 2000
##
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -15,9 +15,39 @@ DESCRIPTION
opened for either reading, writing, or appending. The mode
is controlled by the mode flag as follows:
"r" reading
"w" writing
"a" appending
allow allow file is positioned file(*)
mode reading writing truncated at mode
---- ------- ------- --------- --------- ----
r Y N N beginning text
rb Y N N beginning binary
r+ Y N N beginning text
r+b Y N N beginning binary
rb+ Y N N beginning binary
w N Y Y beginning text
wb N Y Y beginning binary
w+ Y Y Y beginning text
w+b Y Y Y beginning binary
wb+ Y Y Y beginning binary
a N Y Y end text
ab N Y Y end binary
a+ Y Y Y end text
a+b Y Y Y end binary
ab+ Y Y Y end binary
(*) NOTE on 'b' / binary/text mode:
The 'b' or fopen binary mode has no effect on POSIX / Linux
/ Un*x-like systems. On those systems a text file is the
same as a binary file (as it should be for any modern-day
operating system). Adding 'b' to an fopen has no effect
and is ignored.
Some non-POSIX systems sucn as MS Windoz treat text files
and binary files differently. In text mode MS Windoz consider
"\r\n" and end-of-line character. On an Apple MAC, the
text mode end-of-line character is "\r".
Names of files are subject to ~ expansion just like the C or
Korn shell. For example, the file name:
@@ -90,8 +120,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: fopen,v 29.2 2000/06/07 14:02:33 chongo Exp $
## @(#) $Revision: 29.3 $
## @(#) $Id: fopen,v 29.3 2001/04/10 21:46:45 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fopen,v $
##
## Under source code control: 1994/10/27 03:04:17

49
help/freebernoulli Normal file
View File

@@ -0,0 +1,49 @@
NAME
freebernoulli - free stored Benoulli numbers
SYNOPSIS
freebernoulli()
TYPES
return none
DESCRIPTION
The memory used to store calculated bernoulli numbers is freed by
freebernoulli().
EXAMPLE
> freebernoulli();
LIMITS
none
LINK LIBRARY
void qfreebern(void);
SEE ALSO
bernoulli
## Copyright (C) 2000 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
## as published by the Free Software Foundation.
##
## Calc is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
## Public License for more details.
##
## A copy of version 2.1 of the GNU Lesser General Public License is
## distributed with calc under the filename COPYING-LGPL. You should have
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: freebernoulli,v 29.2 2000/07/17 15:36:26 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freebernoulli,v $
##
## Under source code control: 2000/07/13
## File existed as early as: 2000
##
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

49
help/freeeuler Normal file
View File

@@ -0,0 +1,49 @@
NAME
freeeuler - free stored Euler numbers
SYNOPSIS
freeeuler()
TYPES
return none
DESCRIPTION
The memory used to store calculated Euler numbers is freed by
freeeuler().
EXAMPLE
> freeeuler();
LIMITS
none
LINK LIBRARY
void qfreeeuler(void);
SEE ALSO
euler, bernoulli, freebernoulli
## Copyright (C) 2000 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
## as published by the Free Software Foundation.
##
## Calc is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
## Public License for more details.
##
## A copy of version 2.1 of the GNU Lesser General Public License is
## distributed with calc under the filename COPYING-LGPL. You should have
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.1 $
## @(#) $Id: freeeuler,v 29.1 2000/12/14 10:31:45 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/freeeuler,v $
##
## Under source code control: 2000/12/14 01:33:00
## File existed as early as: 2000
##
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -15,10 +15,13 @@ Interrupts
[Abort level n]
where n ranges from 1 to 3. For n equal to 1, the calculator will
abort calculations at the next statement boundary. For n equal to 2,
the calculator will abort calculations at the next opcode boundary.
For n equal to 3, the calculator will abort calculations at the next
lowest level arithmetic operation boundary.
abort calculations at the next statement boundary specified by an
ABORT opcode as described below. For n equal to 2, the calculator
will abort calculations at the next opcode boundary. For n equal to 3,
the calculator will abort calculations at the next attempt to allocate
memory for the result of an integer arithmetic operation; this
level may be appropriate for stopping a builtin operation like
inversion of a large matrix.
If a final interrupt is given when n is 3, the calculator will
immediately abort the current calculation and longjmp back to the
@@ -27,8 +30,77 @@ Interrupts
be done as a last resort. You are advised to quit the calculator
after this has been done.
## Copyright (C) 1999 Landon Curt Noll
##
ABORT opcodes
If config("trace") & 2 is zero, ABORT opcodes are introduced at
various places in the opcodes for evaluation of command lines
and functions defined by "define ... { ... }" commands. In the
following, config("trace") has been set equal to 8 so that opcodes
are displayed when a function is defined. The function f(x)
evaluates x + (x - 1) + (x - 2) + ... until a zero term is
encountered. If f() is called with a negative or fractional x,
the calculation is never completed and to stop it, an interruption
(on many systems, by ctrl-C) will be necessary.
> config("trace", 8),
> define f(x) {local s; while (x) {s += x--} return s}
0: DEBUG line 2
2: PARAMADDR x
4: JUMPZ 19
6: DEBUG line 2
8: LOCALADDR s
10: DUPLICATE
11: PARAMADDR x
13: POSTDEC
14: POP
15: ADD
16: ASSIGNPOP
17: JUMP 2
19: DEBUG line 2
21: LOCALADDR s
23: RETURN
f(x) defined
(The line number following DEBUG refers to the line in the file
from which the definition is read.) If an attempt is made to
evaluate f(-1), the effect of the DEBUG at opcode 6 ensures that
a single SIGINT will stop the calculation at a start of
{s += x--} loop. In interactive mode, with ^C indicating
input of ctrl-C, the displayed output is as in:
> f(-1)
^C
[Abort level 1]
"f": line 2: Calculation aborted at statement boundary
The DEBUG opcodes are disabled by nonzero config("trace") & 2.
Changing config("trace") to achieve this, and defining g(x) with
the same definition as for f(x) gives:
> define g(x) {local s; while (x) {s += x--} return s}
0: PARAMADDR x
2: JUMPZ 15
4: LOCALADDR s
6: DUPLICATE
7: PARAMADDR x
9: POSTDEC
10: POP
11: ADD
12: ASSIGNPOP
13: JUMP 0
15: LOCALADDR s
17: RETURN
g(x) defined
If g(-1) is called, two interrupts are necessary, as in:
> g(-1)
^C
[Abort level 1]
^C
[Abort level 2]
"g": Calculation aborted in opcode
## 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.
@@ -43,8 +115,8 @@ Interrupts
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: interrupt,v 29.2 2000/06/07 14:02:33 chongo Exp $
## @(#) $Revision: 29.4 $
## @(#) $Id: interrupt,v 29.4 2000/07/17 15:38:52 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/interrupt,v $
##
## Under source code control: 1991/07/21 04:37:21

View File

@@ -1,34 +1,41 @@
NAME
places - return number of decimal places
places - return number of "decimal" places in a fractional part
SYNOPSIS
places(x)
places(x [,b])
TYPES
x real
b integer >= 2, defaults to 10
return integer
DESCRIPTION
If x has a finite decimal representation (with nonzero last digit),
places(x) returns the number of digits after the decimal point in this
representation; this is the least non-negative integer n for which
10^n * x is an integer.
Returns the least non-negative integer n for which b^n * x is an
integer, or -1 if there is no such integer.
If x does not have a finite decimal representation, places(x) returns -1.
places(x,b) = 0 if and only if x is an integer.
places(x,b) = n > 0 if and only if the fractional part of abs(x)
has a finite base-b "decimal" representation with n digits of which
the last digit is nonzero. This occurs if and only if every prime
factor of den(x) is a factor of b.
EXAMPLE
> print places(3), places(0.0123), places(3.70), places(1e-10), places(3/7)
0 4 1 10 -1
> print places(0.0123, 2), places(.625, 2), places(.625, 8)
-1 3 1
LIMITS
none
LINK LIBRARY
long qplaces(NUMBER *x)
long qplaces(NUMBER *q, ZVALUE base)
SEE ALSO
digits
digit, digits
## Copyright (C) 1999 Landon Curt Noll
##
@@ -46,8 +53,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: places,v 29.2 2000/06/07 14:02:33 chongo Exp $
## @(#) $Revision: 29.4 $
## @(#) $Id: places,v 29.4 2000/12/17 12:27:58 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/places,v $
##
## Under source code control: 1995/10/03 10:40:02

View File

@@ -1,5 +1,5 @@
NAME
rand - additive 55 shuffle pseudo-random number generator
rand - subtractive 100 shuffle pseudo-random number generator
SYNOPSIS
rand([[min, ] max])
@@ -11,7 +11,7 @@ TYPES
return integer
DESCRIPTION
Generate a pseudo-random number using an additive 55 shuffle generator.
Generate a pseudo-random number using an subtractive 100 shuffle generator.
We return a pseudo-random number over the half closed interval [min,max).
By default, min is 0 and max is 2^64.
@@ -38,36 +38,40 @@ DESCRIPTION
when seeded with the same seed.
The rand generator has two distinct parts, the additive 55 method
and the shuffle method. The additive 55 method is described in:
The rand generator has two distinct parts, the subtractive 100 method
and the shuffle method. The subtractive 100 method is described in:
"The Art of Computer Programming - Seminumerical Algorithms"
by Knuth, Vol 2, 2nd edition (1981), Section 3.2.2, page 27,
Algorithm A.
"The Art of Computer Programming - Seminumerical Algorithms",
Vol 2, 3rd edition (1998), Section 3.6, page 186, formula (2).
The period and other properties of the additive 55 method
The "use only the first 100 our of every 1009" is described in
Knuth's "The Art of Computer Programming - Seminumerical Algorithms",
Vol 2, 3rd edition (1998), Section 3.6, page 188".
The period and other properties of the subtractive 100 method
make it very useful to 'seed' other generators.
The shuffle method is feed values by the additive 55 method.
The shuffle method is feed values by the subtractive 100 method.
The shuffle method is described in:
"The Art of Computer Programming - Seminumerical Algorithms"
by Knuth, Vol 2, 2nd edition (1981), Section 3.2.2, page 32,
Algorithm B.
"The Art of Computer Programming - Seminumerical Algorithms",
Vol 2, 3rd edition (1998), Section 3.2.2, page 34, Algorithm B.
The rand generator has a good period, and is fast. It is reasonable as
generators go, though there are better ones available. The shuffle
method has a very good period, and is fast. It is fairly good as
generators go, particularly when it is feed reasonably random
numbers. Because of this, we use feed values from the additive 55
numbers. Because of this, we use feed values from the subtractive 100
method into the shuffle method.
The rand generator uses two internal tables:
additive table - 55 entries of 64 bits used by the additive 55 method
additive table - 100 entries of 64 bits used by the subtractive
100 method
shuffle table - 256 entries of 64 bits used by the shuffle method
feed by the additive 55 method from the additive table
feed by the subtractive 100 method from the
subtractive table
The goals of this generator are:
@@ -95,21 +99,21 @@ DESCRIPTION
a standard against which other generators may be measured.
The Rand book of numbers was groups into groups of 20 digits. The
first 55 groups < 2^64 were used to initialize the default additive
first 100 groups < 2^64 were used to initialize the default additive
table. The size of 20 digits was used because 2^64 is 20 digits
long. The restriction of < 2^64 was used to prevent modulus biasing.
The shuffle table size is longer than the 100 entries recommended
by Knuth. We use a power of 2 shuffle table length so that the
shuffle process can select a table entry from a new additive 55
shuffle process can select a table entry from a new subtractive 100
value by extracting its low order bits. The value 256 is convenient
in that it is the size of a byte which allows for easy extraction.
We use the upper byte of the additive 55 value to select the
We use the upper byte of the subtractive 100 value to select the
shuffle table entry because it allows all of 64 bits to play a part
in the entry selection. If we were to select a lower 8 bits in the
64 bit value, carries that propagate above our 8 bits would not
impact the additive 55 generator output.
impact the subtractive 100 generator output.
It is 'nice' when a seed of "n" produces a 'significantly different'
sequence than a seed of "n+1". Generators, by convention, assign
@@ -161,7 +165,7 @@ DESCRIPTION
The values 'a' and 'c for randreseed64 are taken from the Rand book
of numbers. Because m=2^64 is 20 decimal digits long, we will
search the Rand book of numbers 20 at a time. We will skip any of
the 55 values that were used to initialize the additive 55
the 100 values that were used to initialize the subtractive 100
generators. The values obtained from the Rand book are:
a = 6316878969928993981
@@ -190,36 +194,40 @@ DESCRIPTION
The truly paranoid might suggest that my claims in the MAGIC NUMBERS
section are a lie intended to entrap people. Well they are not, but
you need not take my (Landon Curt Noll) word for it.
if you that paranoid why would you use a non-cryprographically strong
pseudo-random number generator in the first place? You would be
better off using the random() builtin function.
The random numbers from the Rand book of random numbers can be
The two constants that were picked from the Rand Book of Random Numbers
The random numbers from the Rand Book of Random Numbers can be
verified by anyone who obtains the book. As these numbers were
created before I (Landon Curt Noll) was born (you can look up my
birth record if you want), I claim to have no possible influence on
their generation.
created before I (Landon Curt Noll) was born (you can look up
my birth record if you want), I claim to have no possible influence
on their generation.
There is a very slight chance that the electronic copy of the
Rand book that I was given access to differs from the printed text.
I am willing to provide access to this electronic copy should
anyone wants to compare it to the printed text.
Rand Book of Random Numbers that I was given access to differs
from the printed text. I am willing to provide access to this
electronic copy should anyone wants to compare it to the printed text.
When using the a55 generator, one may select your own 55 additive
When using the s100 generator, one may select your own 100 subtractive
values by calling:
srand(mat55)
srand(mat100)
and avoid using my magic numbers. Of course, you must pick good
additive 55 values yourself!
and avoid using my magic numbers. The randreseed64 process is NOT
applied to the matrix values. Of course, you must pick good subtractive
100 values yourself!
EXAMPLE
> print srand(0), rand(), rand(), rand()
RAND state 14384206130809570460 10173010522823332484 5713611208311484212
RAND state 2298441576805697181 3498508396312845423 5031615567549397476
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123)
17 104 74 47 48 46
106 59 99 99 25 88
> print rand(2,12), rand(2^50,3^50), rand(0,2), rand(-400000, 120000)
11 170570393286648531699560 1 -96605
2 658186291252503497642116 1 -324097
LIMITS
min < max
@@ -248,8 +256,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: rand,v 29.2 2000/06/07 14:02:33 chongo Exp $
## @(#) $Revision: 29.3 $
## @(#) $Id: rand,v 29.3 2001/04/14 22:46:33 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rand,v $
##
## Under source code control: 1996/01/01 02:16:09

View File

@@ -1,62 +1,264 @@
Calc shell scripts
------------------
If an executable file begins with:
There are several ways calc may be used in shell scripts. The
syntax for these varies widely for different shells and systems,
but common to most are commands like echo, if, for, goto, shift,
and exit, as well as the accessing of environment parameters, shell
variables, and command-line arguments.
#!/usr/local/bin/calc -S [-other_flags ...]
As a simple example, assuming a C or Bourne shell, let add be a
file containing just one line:
the rest of the file will be processed in shell script mode.
Note that -S (UPPER CASE -S) must be the first -flag on the
``#!'' line. Any other optional ``-other_flags'' must come
after the -S.
calc -q -- $1 + $2
In shell script mode the contents of the file are evaluated
and executed as if they were processed by the read command.
Any optional ``-other_flags'' will by parsed first followed
by any arguments given shell script itself.
Then:
In shell script mode, -s (lower case -s) is always assumed.
In addition, -d and -p are automatically set if -i is not
given.
./add 1.23 4.56
For example, if the file /tmp/mersenne:
should respond with the display of:
#!/usr/local/bin/calc -S -q
#
# mersenne - an example of a calc shell script file
5.9
/* parse args */
if (argv() != 1) {
fprintf(files(2), "usage: %s exp\n", config("program"));
abort "must give one exponent arg";
}
The "-q" was included in the command to avoid reading of any
start-up calc files which could contain commands not wanted
here. The "--" indicates that there are no more options;
without it, if $1 began with '-', calc would interpret it as
the first character of another option. To execute the file,
the strings "1.23" and "4.56" were assigned to $1 and $2, so
calc was in effect asked to evaluate the string "1.23 + 4.56".
/* print the mersenne number */
print "2^": argv(0) : "-1 =", 2^eval(argv(0))-1;
By making add executable by a command like:
is made an executable file by:
chmod u+x add
chmod +x /tmp/mersenne
the command used here may be simplified to:
then the command line:
./add 1.23 4.56
/tmp/mersenne 127
Here we shall assume that any script we refer to has been made
executable in this way.
will print:
Because $1 and $2, and instructions in the script, are to read
by calc as expressions or commands, they may be much more
complicated than in the above example, but if they involve
characters with special interpretations by the shell (spaces
for word separation, * or ? or [ ...] for file-name expansion,
! (without immediately following space) for history expansion,
( ... ) for shell-function arguments, { ... } for brace
expansion, $ for parameter or variable expansion, <, <<, >, >>
for redirection of input or output, etc.) it will usually be
necessary to quote or escape tho characters, or usually more
conveniently, quote whole expressions with single or double
quotes.
2^127-1 = 170141183460469231731687303715884105727
For example, the add script should have no problem with
commands like:
Note that because -s is assumed in shell script mode and
non-dashed args are made available as strings via the argv()
builtin function. Therefore:
./add "sqrt(2)" "3 * 4"
2^eval(argv(0))-1
./add "mat A[2,2] = {1,2,3,4}" "A^2"
will print the decimal value of 2^n-1 but
./add "2 + 3i" "(3 + 4i)^2"
2^argv(0)-1
If the shell arguments are to be integers, one could use
scripts like the following with arithmetic expansion
for the bash and ksh:
will not.
declare -i a=$1
declare -i b=$2
calc -q -- $a + $b
and for csh:
@ a = $1
@ b = $2
calc -q -- $a + $b
Specifying the shell for a script may be done by including
in the script a first line with the "magic number" "#!" and
the full file path for the shell as in:
#!/bin/bash
declare -i a=$1
declare -i b=$2
calc -q -- $a + $b
For a script to multiply rather than add two expressions, one
could have a file mul with the one line:
calc -q -- $1 \* $2
or:
calc -q -- "$1 * $2"
which will work so long as $1 and $2 are literal numbers, but
will not work for:
./mul 2+3 4
or:
./mul "2 + 3" 4
both of which calc interprets as evaluating 2 + 3 * 4. What should
work for most shells is:
calc -q -- "($1) * ($2)"
For adding an arbitrary number of expressions that evaluate to
rational numbers expressible with at most 20 decimal places,
simple shell script could be used:
s=0
for i do
s=`calc -q -- $s + $i`
done
echo sum = $s
This is not particularly efficient since it calls calc once for
each argument. Also, a more serious script would permit more
general numbers.
Another way of handling a sum of several expressions is with
the script addall2 with a here document:
calc "-q -s" $* << +
global i, n, s;
n = argv();
for (i = 0; i < n; i++)
s += eval(argv(i));
print "sum =", s;
+
In executing the command:
./addall2 2 3 4
the $* in ths script expands to 2 3 4, and because of the "-s"
in the options, calc starts with argv(0) = "2", argv(1) = "3",
argv(2)= "4". As there is only one calc process involved and
the eval() function accepts as argument any string that
represents the body of a calc function, the strings argv(0),
argv(1), ... could evaluate to any value types for which the
additions to be performed are defined, and variables defined in
one argv() can be used in later arguments.
For systems that support interpreter files, essentially the
same thing may be done more efficiently by using calc as an
interpreter. Assuming the full path for calc is
/usr/local/bin/calc, one could use the file addall3 with contents
#!/usr/local/bin/calc -q -s -f
global i, n, s;
n = argv();
for (i = 1; i <= n; i++)
s += eval(argv(i));
print "sum =", s;
After the command:
addall3 2 3 4
the arguments calc receives are argv(0) = "addall3", argv(1) =
"2", argv(3) = "3", argv(4) = "4".
Another kind of script that can be useful is sqrts1:
calc -q 'global s; while (scanf("%s", s) == 1) print sqrt(eval(s));'
or what is essentially an interpreter equivalent sqrts2:
#!/usr/local/bin/calc -q -f
global s;
while (scanf('%s', s) == 1)
print sqrt(eval(s));
If sqrts is either of these scripts, the command:
echo 27 2+3i | sqrts
or, if datafile contains the one line:
27 2+3i
or the two lines:
27
2+3i
either:
cat datafile | ./sqrts
or:
./sqrts < datafile
should display the square-roots of 27 and 2+3i. The output could
be piped to another command by | or directed to a file by use of
> or >>.
With no specified input, either sqrts1 or sqrts2 will wait
without any prompt for input from the keyboard and as each line
is completed display the square-roots of the expressions
entered. Exit can be achieved by entering exit or entering
ctrl-D (interpreted as EOF) rather than a line of input.
One advantage of an interpreter file like sqrts2 (which has only
options, but neither "-s" nor "--" in its first line) is that it
can be invoked with further options as in
echo 2 3 4 | ./sqrts2 -i -D 32
An advantage of non-interpreter files is that they can use shell
features. For example, for unquoted arguments or arguments in
double quotes parameter expansion (indicated by unquoted '$') and
command substitution (using backquotes) occur before lines are
compiled by calc. For example, if doit is an executable
script with contents
calc -q -- "$1($2)"
it may be used as in:
./doit sqrt 7
and:
./doit exp 7
to display the values of sqrt(7) and exp(7). The "--" prevents a
leading '-' in the $1 argument as indicating one or more additional
options. E.g., without the "--" in doit,
./doit -sqrt 7
would be interpreted as:
calc -q "-sqrt(7)"
in which the dash in the quoted part would be taken as indicating a
list of options -s, -q, -r, etc.; this would give an "illegal option"
error as calc has no -r option.
In invoking the doit script it is not necessary that $1 expand to a
calc function name and $2 to an expression; all that is required is
that:
$1($2)
expands to a string that calc will recognize as a command. E.g.:
./doit "define f(x) = x^2; 2 + mod" "f(7), 6"
does the same as:
calc -q -- "define f(x) = x^2; 2 + mod(f(7), 6)"
Essentially the same is achieved by the contents of doit is changed to:
calc -q -p -- << +
$1($2)
+
The "-p" stops calc going interactive; without it the effect would be
be the same as that of a script with the one line:
calc -q -i -- "$1($2)"
For more information use the following calc commands:
@@ -65,7 +267,7 @@ For more information use the following calc commands:
help config
help cscript
## Copyright (C) 1999 Landon Curt Noll
## Copyright (C) 2000 Landon Curt Noll and 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
@@ -81,8 +283,8 @@ For more information use the following calc commands:
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.3 $
## @(#) $Id: script,v 29.3 2000/06/07 14:02:33 chongo Exp $
## @(#) $Revision: 29.5 $
## @(#) $Id: script,v 29.5 2001/04/08 07:56:32 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/script,v $
##
## Under source code control: 1999/11/30 05:29:48
@@ -90,3 +292,4 @@ For more information use the following calc commands:
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

68
help/sleep Normal file
View File

@@ -0,0 +1,68 @@
NAME
sleep - suspend operation for a specified time
SYNOPSIS
sleep([n])
TYPES
n non-negative real, defaults to 1
return integer or null value
DESCRIPTION
This uses the C-library sleep (if n is integral) or usleep (for
non-integral n) to suspend operation for n seconds. If n is an
integer and the sleep is stopped by an interruption, the number
of seconds remaining is returned.
One kind of use is to slow down output to permit easier reading of
results, as in:
> for (i = 0; i < 100; i++) {
print sqrt(i);
sleep(1/2);
}
The following illustrates what happens if ctrl-C is hit 5 seconds
after the first command:
> print sleep(20)
[Abort level 1]
15
>
EXAMPLE
> sleep(1/3);
> sleep(20);
LIBRARY
none
SEE ALSO
none
## Copyright (C) 2000 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
## as published by the Free Software Foundation.
##
## Calc is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
## Public License for more details.
##
## A copy of version 2.1 of the GNU Lesser General Public License is
## distributed with calc under the filename COPYING-LGPL. You should have
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: sleep,v 29.2 2000/12/17 12:27:58 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sleep,v $
##
## Under source code control: 2000/12/14 01:33:00
## File existed as early as: 2000
##
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -1,5 +1,5 @@
NAME
srand - seed the additive 55 shuffle pseudo-random number generator
srand - seed the subtractive 100 shuffle pseudo-random number generator
SYNOPSIS
srand([seed])
@@ -10,43 +10,43 @@ TYPES
return rand state
DESCRIPTION
Seed the pseudo-random number using an additive 55 shuffle generator.
Seed the pseudo-random number using an subtractive 100 shuffle generator.
For integer seed != 0:
Any buffered rand generator bits are flushed. The additive table
for the rand generator is loaded with the default additive table.
Any buffered rand generator bits are flushed. The subtractive table
for the rand generator is loaded with the default subtractive table.
The low order 64 bits of seed is xor-ed against each table value.
The additive table is shuffled according to seed/2^64.
The subtractive table is shuffled according to seed/2^64.
The following calc code produces the same effect on the internal
additive table:
subtractive table:
/* reload default additive table xor-ed with low 64 seed bits */
/* reload default subtractive table xor-ed with low 64 seed bits */
seed_xor = seed & ((1<<64)-1);
for (i=0; i < 55; ++i) {
additive[i] = xor(default_additive[i], seed_xor);
for (i=0; i < 100; ++i) {
subtractive[i] = xor(default_subtractive[i], seed_xor);
}
/* shuffle the additive table */
/* shuffle the subtractive table */
seed >>= 64;
for (i=55; seed > 0 && i > 0; --i) {
for (i=100; seed > 0 && i > 0; --i) {
quomod(seed, i+1, seed, j);
swap(additive[i], additive[j]);
swap(subtractive[i], subtractive[j]);
}
Seed must be >= 0. All seed values < 0 are reserved for future use.
The additive table pointers are reset to additive[23] and additive[54].
Last the shuffle table is loaded with successive values from the
additive 55 generator.
The subtractive table pointers are reset to subtractive[36]
and subtractive[99]. Last the shuffle table is loaded with
successive values from the subtractive 100 generator.
There is no limit on the size of a seed. On the other hand,
extremely large seeds require large tables and long seed times.
Using a seed in the range of [2^64, 2^64 * 55!) should be
Using a seed in the range of [2^64, 2^64 * 100!) should be
sufficient for most purposes. An easy way to stay within this
range to to use seeds that are between 21 and 93 digits, or
64 to 308 bits long.
range to to use seeds that are between 21 and 178 digits, or
64 to 588 bits long.
To help make the generator produced by seed S, significantly
different from S+1, seeds are scrambled prior to use. The
@@ -68,9 +68,9 @@ DESCRIPTION
After this call, the rand generator is restored to its initial
state after calc started.
The additive 55 pointers are reset to additive[23] and additive[54].
Last the shuffle table is loaded with successive values from the
additive 55 generator.
The subtractive 100 pointers are reset to subtractive[36]
and subtractive[99]. Last the shuffle table is loaded with
successive values from the subtractive 100 generator.
The call:
@@ -80,14 +80,14 @@ DESCRIPTION
For matrix arg:
Any buffered random bits are flushed. The additive table with the
first 55 entries of the matrix mod 2^64.
Any buffered random bits are flushed. The subtractive table with the
first 100 entries of the matrix mod 2^64.
The additive 55 pointers are reset to additive[23] and additive[54].
Last the shuffle table is loaded with successive values from the
additive 55 generator.
The subtractive 100 pointers are reset to subtractive[36]
and subtractive[99]. Last the shuffle table is loaded with
successive values from the subtractive 100 generator.
This form allows one to load the internal additive 55 generator
This form allows one to load the internal subtractive 100 generator
with user supplied values.
The randreseed64 process is NOT applied to the matrix values.
@@ -114,7 +114,7 @@ DESCRIPTION
For no arg given:
Return current a55 generator state. This call does not alter
Return current s100 generator state. This call does not alter
the generator state.
This call allows one to take a snapshot of the current generator state.
@@ -126,25 +126,25 @@ EXAMPLE
RAND state
> state = srand();
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123);
32 60 67 71 1 77
80 95 41 78 100 27
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123);
52 72 110 15 69 58
122 109 12 95 80 32
> state2 = srand(state);
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123);
32 60 67 71 1 77
80 95 41 78 100 27
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123);
52 72 110 15 69 58
122 109 12 95 80 32
> state3 = srand();
> print state3 == state2;
1
> print rand();
641407694185874626
10710588361472584495
LIMITS
for matrix arg, the matrix must have at least 55 integers
for matrix arg, the matrix must have at least 100 integers
LINK LIBRARY
RAND *zsrand(ZVALUE *pseed, MATRIX *pmat55)
RAND *zsrand(ZVALUE *pseed, MATRIX *pmat100)
RAND *zsetrand(RAND *state)
SEE ALSO
@@ -166,8 +166,8 @@ SEE ALSO
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: srand,v 29.2 2000/06/07 14:02:33 chongo Exp $
## @(#) $Revision: 29.3 $
## @(#) $Id: srand,v 29.3 2001/04/14 22:46:33 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/srand,v $
##
## Under source code control: 1996/01/01 04:19:07

8
hist.c
View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: hist.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: hist.c,v 29.3 2001/03/17 21:31:47 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/hist.c,v $
*
* Under source code control: 1993/05/02 20:09:19
@@ -40,7 +40,9 @@
#include <stdio.h>
#include <ctype.h>
#include <pwd.h>
#if !defined(_WIN32)
# include <pwd.h>
#endif
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)

12
hist.h
View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: hist.h,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: hist.h,v 29.3 2001/03/17 21:31:47 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/hist.h,v $
*
* Under source code control: 1993/05/02 20:09:20
@@ -64,10 +64,10 @@
#define HIST_NOTTY 3 /* terminal modes could not be set */
extern int hist_init(char *filename);
extern void hist_term(void);
extern int hist_getline(char *prompt, char *buf, int len);
extern void hist_saveline(char *line, int len);
extern DLL int hist_init(char *filename);
extern DLL void hist_term(void);
extern DLL int hist_getline(char *prompt, char *buf, int len);
extern DLL void hist_saveline(char *line, int len);
#endif /* !__HIST_H__ */

55
input.c
View File

@@ -1,5 +1,5 @@
/*
* input - nsted input source file reader
* input - nested input source file reader
*
* Copyright (C) 1999 David I. Bell
*
@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: input.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.5 $
* @(#) $Id: input.c,v 29.5 2001/03/17 21:31:47 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/input.c,v $
*
* Under source code control: 1990/02/15 01:48:16
@@ -35,7 +35,9 @@
#include <stdio.h>
#include <ctype.h>
#include <pwd.h>
#if !defined(_WIN32)
# include <pwd.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
@@ -140,7 +142,7 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once)
* /
* name
* .
* extenstion
* extension
* \0
* guard byte
*/
@@ -257,11 +259,17 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once)
static char *
homeexpand(char *name)
{
#if defined(_WIN32)
return NULL;
#else /* Windoz free systems */
struct passwd *ent; /* password entry */
char *home2; /* fullpath of the home directory */
char *fullpath; /* the malloced expanded path */
char *after; /* after the ~user or ~ */
char *username; /* extratced username */
char *username; /* extracted username */
/* firewall */
if (name[0] != HOMECHAR)
@@ -323,6 +331,7 @@ homeexpand(char *name)
}
sprintf(fullpath, "%s%s", home2, after);
return fullpath;
#endif /* Windoz free systems */
}
@@ -795,6 +804,15 @@ runrcfiles(void)
* This function returns the index of the readset element that matches
* a given device/inode, -1 otherwise.
*
*
* WIN32 NOTE:
*
* This function does not work under WIN32. The sbuf->st_ino is always
* zero because the FAT and NTFS filesystems do not support inodes.
* They also don't support links, which is why you need this function
* under UNIX. For WIN32, use _fullpath() to determine if you have
* already opened a file.
*
* given:
* sbuf stat of the inode in question
*/
@@ -802,6 +820,9 @@ static int
isinoderead(struct stat *sbuf)
{
int i;
#if defined(_WIN32)
char fullpathname[_MAX_PATH];
#endif
/* deal with the empty case */
if (readset == NULL || maxreadset <= 0) {
@@ -811,12 +832,22 @@ isinoderead(struct stat *sbuf)
/* scan the entire readset */
for (i=0; i < maxreadset; ++i) {
#if defined(_WIN32)
if (readset[i].active &&
strcmp(readset[i].path,
_fullpath(fullpathname,cip->i_name,
_MAX_PATH)) == 0) {
/* found a match */
return i;
}
#else /* Windoz free systems */
if (readset[i].active &&
sbuf->st_dev == readset[i].inode.st_dev &&
sbuf->st_ino == readset[i].inode.st_ino) {
/* found a match */
return i;
}
#endif /* Windoz free systems */
}
/* no match found */
@@ -873,7 +904,7 @@ findfreeread(void)
}
maxreadset += READSET_ALLOC;
/* return the furst newly allocated free entry */
/* return the first newly allocated free entry */
return maxreadset-READSET_ALLOC;
}
@@ -923,11 +954,21 @@ addreadset(char *name, char *path, struct stat *sbuf)
return -1;
}
strcpy(readset[ret].name, name);
#if defined(_WIN32)
/*
* For WIN32, _fullpath expands the path to a fully qualified
* path name, which under WIN32 FAT and NTFS is unique, just
* like UNIX inodes. _fullpath also allocated the memory for
* this new longer path name.
*/
readset[ret].path = _fullpath(NULL, path, 0);
#else /* Windoz free systems */
readset[ret].path = (char *)malloc(strlen(path)+1);
if (readset[ret].path == NULL) {
return -1;
}
strcpy(readset[ret].path, path);
#endif /* Windoz free systems */
readset[ret].inode = *sbuf;
readset[ret].active = 1;

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.3 $
* @(#) $Id: lib_calc.c,v 29.3 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.7 $
* @(#) $Id: lib_calc.c,v 29.7 2001/04/08 22:05:40 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/lib_calc.c,v $
*
* Under source code control: 1996/06/17 18:06:19
@@ -32,7 +32,10 @@
#include <stdio.h>
#include <setjmp.h>
#include <signal.h>
#include <pwd.h>
#if !defined(_WIN32)
# include <pwd.h>
#endif
#include "calc.h"
#include "zmath.h"
@@ -63,18 +66,31 @@
# include <termios.h>
typedef struct termios ttystruct;
#elif defined(USE_TERMIOS)
#elif defined(USE_TERMIO)
# include <termio.h>
typedef struct termio ttystruct;
#else /* assume USE_SGTTY */
#elif defined(USE_SGTTY)
# include <sys/ioctl.h>
typedef struct sgttyb ttystruct;
#else
typedef struct {int fd;} ttystruct;
#endif
#if !defined(_WIN32)
# if !defined(USE_SGTTY) && !defined (USE_TERMIOS) && !defined(USE_TERMIO)
-=*#*=- A Windoz free system without termio, termios or sgtty!!! -=*#*=-
-=*#*=- We do not know how to compile for such a host, sorry!!!! -=*#*=-
# endif
#endif /* Windoz */
/*
* in case we do not have certain .h files
*/
@@ -97,7 +113,7 @@ jmp_buf jmpbuf; /* for errors */
char *program = "calc"; /* our name */
char *base_name = "calc"; /* basename of our name */
char cmdbuf[MAXCMD+1+1+1]; /* command line expression + "\n\0" + guard */
run run_state = RUN_UNKNOWN; /* calc startup and run state */
run run_state = RUN_ZERO; /* calc startup run state */
/*
@@ -165,7 +181,7 @@ static int init_done = 0; /* 1 => we already initialized */
static int *fd_setup = NULL; /* fd's setup for interaction or -1 */
static int fd_setup_len = 0; /* number of fd's in fd_setup */
static ttystruct *fd_orig = NULL; /* fd original state */
static ttystruct *fd_cur = NULL; /* fd current atate */
static ttystruct *fd_cur = NULL; /* fd current state */
static void initenv(void); /* setup calc environment */
static int find_tty_state(int fd); /* find slot for saved tty state */
@@ -192,7 +208,9 @@ libcalc_call_me_first(void)
* Disable SIGPIPE so that the pipe to the help file pager will
* not stop calc.
*/
#if !defined(_WIN32)
(void) signal(SIGPIPE, SIG_IGN);
#endif
/*
* determine the basename
@@ -314,7 +332,7 @@ initialize(void)
math_cleardiversions();
math_setfp(stdout);
math_setmode(MODE_INITIAL);
math_setdigits((long)DISPLAY_DEFAULT);
math_setdigits(DISPLAY_DEFAULT);
conf->maxprint = MAXPRINT_DEFAULT;
}
@@ -373,7 +391,9 @@ cvmalloc_error(char *message)
static void
initenv(void)
{
#if !defined(_WIN32)
struct passwd *ent; /* our password entry */
#endif
char *c;
/* determine the $CALCPATH value */
@@ -402,6 +422,12 @@ initenv(void)
/* determine the $HOME value */
c = (no_env ? NULL : getenv(HOME));
home = (c ? strdup(c) : NULL);
#if defined(_WIN32)
if (home == NULL || home[0] == '\0') {
/* just assume . is home if all else fails */
home = ".";
}
#else /* Windoz free systems */
if (home == NULL || home[0] == '\0') {
ent = (struct passwd *)getpwuid(geteuid());
if (ent == NULL) {
@@ -411,6 +437,7 @@ initenv(void)
home = (char *)malloc(strlen(ent->pw_dir)+1);
strcpy(home, ent->pw_dir);
}
#endif /* Windoz free systems */
/* determine the $PAGER value */
c = (no_env ? NULL : getenv(PAGER));
@@ -431,7 +458,7 @@ initenv(void)
*
* Anything that uses libcalc.a can call this function after they are
* completely finished with libcalc.a processing. The only effect of
* this funcion is to free storage that might otherwise go unused.
* this function is to free storage that might otherwise go unused.
*
* NOTE: If, for any reason, you need to do more libcalc.a processing,
* then you will need to call libcalc_call_me_first() again.
@@ -461,15 +488,13 @@ libcalc_call_me_last(void)
/*
* restore all changed descriptor states
*/
if (fd_setup_len > 0) {
for (i=0; i < fd_setup_len; ++i) {
if (fd_setup[i] >= 0) {
if (conf->calc_debug & CALCDBG_TTY)
printf("libcalc_call_me_last: fd %d "
"not in original state, "
"restoring it", fd_setup[i]);
orig_tty(fd_setup[i]);
}
for (i=0; i < fd_setup_len; ++i) {
if (fd_setup[i] >= 0) {
if (conf->calc_debug & CALCDBG_TTY)
printf("libcalc_call_me_last: fd %d "
"not in original state, "
"restoring it", fd_setup[i]);
orig_tty(fd_setup[i]);
}
}
@@ -488,24 +513,24 @@ char *
run_state_name(run state)
{
switch (state) {
case RUN_UNKNOWN:
return "RUN_UNKNOWN";
case RUN_ZERO:
return "ZERO";
case RUN_BEGIN:
return "RUN_BEGIN";
return "BEGIN";
case RUN_RCFILES:
return "RUN_RCFILES";
return "RCFILES";
case RUN_PRE_CMD_ARGS:
return "RUN_PRE_CMD_ARGS";
return "PRE_CMD_ARGS";
case RUN_CMD_ARGS:
return "RUN_CMD_ARGS";
return "CMD_ARGS";
case RUN_PRE_TOP_LEVEL:
return "RUN_PRE_TOP_LEVEL";
return "PRE_TOP_LEVEL";
case RUN_TOP_LEVEL:
return "RUN_TOP_LEVEL";
return "TOP_LEVEL";
case RUN_EXIT:
return "RUN_EXIT";
return "EXIT";
case RUN_EXIT_WITH_ERROR:
return "RUN_EXIT_WITH_ERROR";
return "EXIT_WITH_ERROR";
}
return "RUN_invalid";
}
@@ -579,7 +604,7 @@ find_tty_state(int fd)
}
/*
* case: need to initlally malloc some state
* case: need to initially malloc some state
*/
if (fd_setup_len <= 0 || fd_setup == NULL || fd_orig == NULL) {
@@ -728,10 +753,10 @@ calc_tty(int fd)
printf("calc_tty: stty -ECHO -ECHOE -ECHOK -ICANON +ISTRIP "
"VMIN=1 VTIME=0: fd %d\n", fd);
#else /* assume USE_SGTTY */
#elif defined (USE_TERMIOS)
/*
* assume USE_SGTTY tty state method
* USE_TERMIOS tty state method
*/
if (fd_setup[slot] < 0 && tcgetattr(fd, fd_orig+slot) < 0) {
if (conf->calc_debug & CALCDBG_TTY)
@@ -754,6 +779,10 @@ calc_tty(int fd)
if (conf->calc_debug & CALCDBG_TTY)
printf("calc_tty: stty -ECHO -ECHOE -ECHOK -ICANON +ISTRIP "
"VMIN=1 VTIME=0: fd %d\n", fd);
#else /* Using none of the above */
fd_cur[slot] = fd_orig[slot];
#endif
/*
@@ -819,7 +848,7 @@ orig_tty(int fd)
if (conf->calc_debug & CALCDBG_TTY)
printf("orig_tty: TCSETAW restored fd %d\n", fd);
#else /* assume USE_SGTTY */
#elif defined (USE_TERMIOS)
/*
* assume USE_SGTTY tty state method
@@ -827,6 +856,12 @@ orig_tty(int fd)
(void) tcsetattr(fd, TCSANOW, fd_orig+slot);
if (conf->calc_debug & CALCDBG_TTY)
printf("orig_tty: TCSANOW restored fd %d\n", fd);
#else /* nothing assigned */
if (conf->calc_debug & CALCDBG_TTY)
printf ("orig_tty: nothing restored to fd %d\n", fd);
#endif
/*
@@ -835,8 +870,8 @@ orig_tty(int fd)
fd_cur[slot] = fd_orig[slot];
/*
* Since current state is the orignal state, we can free up
* this slot. This also prevents functins such as the
* Since current state is the original state, we can free up
* this slot. This also prevents functions such as the
* libcalc_call_me_last() function from re-restoring it.
*/
fd_setup[slot] = -1;

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: longlong.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: longlong.c,v 29.3 2001/02/23 20:46:38 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/longlong.c,v $
*
* Under source code control: 1994/08/05 01:09:19
@@ -119,10 +119,10 @@ main(int argc, char **argv)
printf(" * if defined(L64_FORMAT), ok to use %%ld\n");
printf(" * if !defined(L64_FORMAT), use %%lld\n");
printf(" */\n");
if (buf[0] == '-') {
printf("#undef L64_FORMAT\n");
} else {
if (strcmp(buf, "1311768467284833366") == 0) {
printf("#define L64_FORMAT\n");
} else {
printf("#undef L64_FORMAT\n");
}
/*

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: math_error.h,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: math_error.h,v 29.3 2001/03/17 21:31:47 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/math_error.h,v $
*
* Under source code control: 1997/03/23 18:37:10
@@ -33,10 +33,13 @@
#define __MATH_ERROR_H__
#include "win32dll.h"
/*
* Global data definitions.
*/
extern jmp_buf jmpbuf; /* for errors */
extern DLL jmp_buf jmpbuf; /* for errors */
#endif /* !__MATH_ERROR_H__ */

View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: opcodes.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: opcodes.c,v 29.3 2000/07/17 15:35:49 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/opcodes.c,v $
*
* Under source code control: 1990/02/15 01:48:19
@@ -225,7 +225,7 @@ static void
o_paramvalue(FUNC *fp, int argcount, VALUE *args, long index)
{
if ((unsigned long)index >= argcount) {
math_error("Bad paramaeter index");
math_error("Bad parameter index");
/*NOTREACHED*/
}
args += index;
@@ -896,7 +896,7 @@ o_deref(void)
return;
}
if (stack->v_type != V_ADDR) {
math_error("Deferencing a non-variable");
math_error("Dereferencing a non-variable");
/*NOTREACHED*/
}
vp = vp->v_addr;
@@ -3228,8 +3228,8 @@ o_quit(FUNC *fp, long index)
freevalue(stack--);
}
freevalue(stackarray);
libcalc_call_me_last();
exit(0);
run_state = RUN_EXIT;
longjmp(jmpbuf, 1);
}
if (cp)
printf("%s\n", cp);
@@ -3512,10 +3512,10 @@ static struct opcode opcodes[MAX_OPCODE+1] = {
{o_nop, OPNUL, "NOP"}, /* no operation */
{o_localaddr, OPLOC, "LOCALADDR"}, /* address of local variable */
{o_globaladdr, OPGLB, "GLOBALADDR"}, /* address of global variable */
{o_paramaddr, OPPAR, "PARAMADDR"}, /* address of paramater variable */
{o_paramaddr, OPPAR, "PARAMADDR"}, /* address of parameter variable */
{o_localvalue, OPLOC, "LOCALVALUE"}, /* value of local variable */
{o_globalvalue, OPGLB, "GLOBALVALUE"}, /* value of global variable */
{o_paramvalue, OPPAR, "PARAMVALUE"}, /* value of paramater variable */
{o_paramvalue, OPPAR, "PARAMVALUE"}, /* value of parameter variable */
{o_number, OPONE, "NUMBER"}, /* constant real numeric value */
{o_indexaddr, OPTWO, "INDEXADDR"}, /* array index address */
{o_printresult, OPNUL, "PRINTRESULT"}, /* print result of top-level expression */

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: opcodes.h,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.4 $
* @(#) $Id: opcodes.h,v 29.4 2001/03/17 21:31:47 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/opcodes.h,v $
*
* Under source code control: 1990/02/15 01:48:35
@@ -32,6 +32,9 @@
#define __OPCODES_H__
#include "win32dll.h"
/*
* Opcodes
*/
@@ -174,8 +177,8 @@
/*
* external declarations
*/
extern char *funcname; /* function being executed */
extern long funcline; /* function line being executed */
extern DLL char *funcname; /* function being executed */
extern DLL long funcline; /* function line being executed */
#endif /* !__OPCODES_H__ */

533
qfunc.c
View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: qfunc.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.4 $
* @(#) $Id: qfunc.c,v 29.4 2000/12/17 13:07:32 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/qfunc.c,v $
*
* Under source code control: 1990/02/15 01:48:20
@@ -34,10 +34,17 @@
#include "config.h"
#include "prime.h"
static NUMBER **B_table;
static long B_num;
static long B_allocnum;
static NUMBER **E_table;
static long E_num;
#define QALLOCNUM 64
/*
* Set the default precision for real calculations.
* The precision must be between zero and one.
* Set the default epsilon for approximate calculations.
* This must be greater than zero.
*
* given:
* q number to be set as the new epsilon
@@ -47,8 +54,8 @@ setepsilon(NUMBER *q)
{
NUMBER *old;
if (qisneg(q) || qiszero(q) || (qreli(q, 1L) >= 0)) {
math_error("Epsilon value must be between zero and one");
if (qisneg(q) || qiszero(q)) {
math_error("Epsilon value must be greater than zero");
/*NOTREACHED*/
}
old = conf->epsilon;
@@ -234,7 +241,7 @@ qpowi(NUMBER *q1, NUMBER *q2)
/*
* Given the legs of a right triangle, compute its hypothenuse within
* Given the legs of a right triangle, compute its hypotenuse within
* the specified error. This is sqrt(a^2 + b^2).
*/
NUMBER *
@@ -262,7 +269,7 @@ qhypot(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
/*
* Given one leg of a right triangle with unit hypothenuse, calculate
* Given one leg of a right triangle with unit hypotenuse, calculate
* the other leg within the specified error. This is sqrt(1 - a^2).
* If the wantneg flag is nonzero, then negative square root is returned.
*/
@@ -557,12 +564,11 @@ qilog10(NUMBER *q)
* The number is not an integer.
* Compute the result if the number is greater than one.
*/
if ((q->num.len > q->den.len) ||
((q->num.len == q->den.len) && (zrel(tmp1, q->den) > 0))) {
zquo(tmp1, q->den, &tmp2, 0);
n = zlog10(tmp2);
zfree(tmp2);
return n;
if (zrel(tmp1, q->den) > 0) {
zquo(tmp1, q->den, &tmp2, 0);
n = zlog10(tmp2);
zfree(tmp2);
return n;
}
/*
* Here if the number is less than one.
@@ -583,104 +589,162 @@ qilog10(NUMBER *q)
* Return the integer floor of the logarithm of a number relative to
* a specified integral base.
*/
long
qilog(NUMBER *q1, NUMBER *q2)
NUMBER *
qilog(NUMBER *q, ZVALUE base)
{
long n;
ZVALUE tmp1, tmp2;
if (qiszero(q1)) {
math_error("Zero argument for ilog");
/*NOTREACHED*/
}
if (qisfrac(q2) || zrel(q2->num, _one_) <= 0) {
math_error("Base for ilog non-integral or less than 2");
/*NOTREACHED*/
}
if (qisunit(q1))
return 0;
tmp1 = q1->num;
if (qiszero(q))
return NULL;
if (qisunit(q))
return qlink(&_qzero_);
if (qisint(q))
return itoq(zlog(q->num, base));
tmp1 = q->num;
tmp1.sign = 0;
if (qisint(q1))
return zlog(tmp1, q2->num);
if (zrel(tmp1, q1->den) > 0) {
zquo(tmp1, q1->den, &tmp2, 0);
n = zlog(tmp2, q2->num);
if (zrel(tmp1, q->den) > 0) {
zquo(tmp1, q->den, &tmp2, 0);
n = zlog(tmp2, base);
zfree(tmp2);
return n;
return itoq(n);
}
if (zisunit(tmp1))
zsub(q1->den, _one_, &tmp2);
zsub(q->den, _one_, &tmp2);
else
zquo(q1->den, tmp1, &tmp2, 0);
n = -zlog(tmp2, q2->num) - 1;
zquo(q->den, tmp1, &tmp2, 0);
n = -zlog(tmp2, base) - 1;
zfree(tmp2);
return n;
return itoq(n);
}
/*
* Return the number of digits in a number, ignoring the sign.
* For fractions, this is the number of digits of its greatest integer.
* Examples: qdigits(3456) = 4, qdigits(-23.45) = 2, qdigits(.0120) = 1.
* Return the number of digits in the representation to a specified
* base of the integral part of a number.
* Examples: qdigits(3456,10) = 4, qdigits(-23.45, 10) = 2.
*
* given:
* q number to count digits of
*/
long
qdigits(NUMBER *q)
qdigits(NUMBER *q, ZVALUE base)
{
long n; /* number of digits */
ZVALUE temp; /* temporary value */
if (zabsrel(q->num, q->den) < 1)
return 0;
if (qisint(q))
return zdigits(q->num);
return 1 + zlog(q->num, base);
zquo(q->num, q->den, &temp, 2);
n = zdigits(temp);
n = 1 + zlog(temp, base);
zfree(temp);
return n;
}
/*
* Return the digit at the specified decimal place of a number represented
* in floating point. The lowest digit of the integral part of a number
* is the zeroth decimal place. Negative decimal places indicate digits
* to the right of the decimal point. Examples: qdigit(1234.5678, 1) = 3,
* qdigit(1234.5678, -3) = 7.
* Return the digit at the specified place in the expansion to specified
* base of a rational number. The places specified by dpos are numbered from
* the "units" place just before the "decimal" point, so that negative
* dpos indicates the (-dpos)th place to the right of the point.
* Examples: qdigit(1234.5678, 1, 10) = 3, qdigit(1234.5678, -3, 10) = 7.
* The signs of the number and the base are ignored.
*/
long
qdigit(NUMBER *q, long n)
NUMBER *
qdigit(NUMBER *q, ZVALUE dpos, ZVALUE base)
{
ZVALUE tenpow, tmp1, tmp2;
long res;
ZVALUE N, D;
ZVALUE K;
long k;
ZVALUE A, B, C; /* temporary integers */
NUMBER *res;
/*
* Zero number or negative decimal place of integer is trivial.
* In the first stage, q is expressed as base^k * N/D where
* gcd(D, base) = 1
* K is k as a ZVALUE
*/
if (qiszero(q) || (qisint(q) && (n < 0)))
return 0;
/*
* For non-negative decimal places, answer is easy.
*/
if (n >= 0) {
if (qisint(q))
return zdigit(q->num, n);
zquo(q->num, q->den, &tmp1, 2);
res = zdigit(tmp1, n);
zfree(tmp1);
return res;
base.sign = 0;
if (ziszero(base) || zisunit(base))
return NULL;
if (qiszero(q) || (qisint(q) && zisneg(dpos)) ||
(zge31b(dpos) && !zisneg(dpos)))
return qlink(&_qzero_);
k = zfacrem(q->num, base, &N);
if (k == 0) {
k = zgcdrem(q->den, base, &D);
if (k > 0) {
zequo(q->den, D, &A);
itoz(k, &K);
zpowi(base, K, &B);
zfree(K);
zequo(B, A, &C);
zfree(A);
zfree(B);
zmul(C, q->num, &N);
zfree(C);
k = -k;
}
else
N = q->num;
}
/*
* Fractional value and want negative digit, must work harder.
*/
ztenpow(-n, &tenpow);
zmul(q->num, tenpow, &tmp1);
zfree(tenpow);
zquo(tmp1, q->den, &tmp2, 2);
tmp2.sign = 0;
res = zmodi(tmp2, 10L);
zfree(tmp1);
zfree(tmp2);
if (k >= 0)
D = q->den;
itoz(k, &K);
if (zrel(dpos, K) >= 0) {
zsub(dpos, K, &A);
zfree(K);
zpowi(base, A, &B);
zfree(A);
zmul(D, B, &A);
zfree(B);
zquo(N, A, &B, 0);
} else {
if (zisunit(D)) {
if (k != 0)
zfree(N);
zfree(K);
if (k < 0)
zfree(D);
return qlink(&_qzero_);
}
zsub(K, dpos, &A);
zfree(K);
zpowermod(base, A, D, &C);
zfree(A);
zmod(N, D, &A, 0);
zmul(C, A, &B);
zfree(A);
zfree(C);
zmod(B, D, &A, 0);
zfree(B);
zmodinv(D, base, &B);
zsub(base, B, &C);
zfree(B);
zmul(C, A, &B);
zfree(C);
}
zfree(A);
if (k != 0)
zfree(N);
if (k < 0)
zfree(D);
zmod(B, base, &A, 0);
zfree(B);
if (ziszero(A)) {
zfree(A);
return qlink(&_qzero_);
}
if (zisone(A)) {
zfree(A);
return qlink(&_qone_);
}
res = qalloc();
res->num = A;
return res;
}
@@ -848,67 +912,255 @@ qperm(NUMBER *q1, NUMBER *q2)
/*
* Compute the combinatorial function q1 * (q1-1) * ... * (q1-q2+1)/q2!
* Compute the combinatorial function q(q - 1) ...(q - n + 1)/n!
* n is to be a nonnegative integer
*/
NUMBER *
qcomb(NUMBER *q1, NUMBER *q2)
qcomb(NUMBER *q, NUMBER *n)
{
NUMBER *r;
NUMBER *qtmp1, *qtmp2;
NUMBER *q1, *q2;
long i, j;
ZVALUE z;
if (qisfrac(q2)) {
math_error("Non-integral second argument for comb");
if (!qisint(n) || qisneg(n)) {
math_error("Bad second arg in call to qcomb!");
/*NOTREACHED*/
}
if (qisneg(q2))
return qlink(&_qzero_);
if (qiszero(q2) || qcmp(q1, q2) == 0)
return qlink(&_qone_);
if (qisone(q2))
return qlink(q1);
if (qisint(q1)) {
if (qisneg(q1)) {
qtmp1 = qsub(q2, q1);
qtmp2 = qdec(qtmp1);
qfree(qtmp1);
r = qalloc();
zcomb(qtmp2->num, q2->num, &r->num);
qfree(qtmp2);
if (qiseven(q2))
if (qisint(q)) {
switch (zcomb(q->num, n->num, &z)) {
case 0:
return qlink(&_qzero_);
case 1:
return qlink(&_qone_);
case -1:
return qlink(&_qnegone_);
case 2:
return qlink(q);
case -2:
return NULL;
default:
r = qalloc();
r->num = z;
return r;
qtmp2 = qneg(r);
qfree(r);
return qtmp2;
}
if (qrel(q2, q1) > 0)
return qlink(&_qzero_);
r = qalloc();
zcomb(q1->num, q2->num, &r->num);
return r;
}
if (zge31b(q2->num)) {
math_error("Too large second argument for comb");
/*NOTREACHED*/
}
i = qtoi(q2);
q1 = qlink(q1);
r = qlink(q1);
if (zge31b(n->num))
return NULL;
i = ztoi(n->num);
q = qlink(q);
r = qlink(q);
j = 1;
while (--i > 0) {
qtmp1 = qdec(q1);
qfree(q1);
q1 = qtmp1;
qtmp2 = qmul(r, q1);
q1 = qdec(q);
qfree(q);
q = q1;
q2 = qmul(r, q);
qfree(r);
r = qdivi(qtmp2, ++j);
qfree(qtmp2);
r = qdivi(q2, ++j);
qfree(q2);
}
qfree(q1);
qfree(q);
return r;
}
/*
* Compute the Bernoulli number with index n
* For even positive n, newly calculated values for all even indices up
* to n are stored in table at B_table.
*/
NUMBER *
qbern(ZVALUE z)
{
long n, i, k, m, nn, dd;
NUMBER **p;
NUMBER *s, *s1, *c, *c1, *t;
size_t sz;
if (zisone(z))
return qlink(&_qneghalf_);
if (zisodd(z) || z.sign)
return qlink(&_qzero_);
if (zge31b(z))
return NULL;
n = ztoi(z);
if (n == 0)
return qlink(&_qone_);
m = (n >> 1) - 1;
if (m < B_num)
return qlink(B_table[m]);
if (m >= B_allocnum) {
k = (m/QALLOCNUM + 1) * QALLOCNUM;
sz = k * sizeof(NUMBER *);
if (sz < (size_t) k)
return NULL;
if (B_allocnum == 0)
p = (NUMBER **) malloc(sz);
else
p = (NUMBER **) realloc(B_table, sz);
if (p == NULL)
return NULL;
B_allocnum = k;
B_table = p;
}
for (k = B_num; k <= m; k++) {
nn = 2 * k + 3;
dd = 1;
c1 = itoq(nn);
c = qinv(c1);
qfree(c1);
s = qsub(&_qonehalf_, c);
i = k;
for (i = 0; i < k; i++) {
c1 = qmuli(c, nn--);
qfree(c);
c = qdivi(c1, dd++);
qfree(c1);
c1 = qmuli(c, nn--);
qfree(c);
c = qdivi(c1, dd++);
qfree(c1);
t = qmul(c, B_table[i]);
s1 = qsub(s, t);
qfree(t);
qfree(s);
s = s1;
}
B_table[k] = s;
qfree(c);
}
B_num = k;
return qlink(B_table[m]);
}
void
qfreebern(void)
{
long k;
if (B_num > 0) {
for (k = 0; k < B_num; k++)
qfree(B_table[k]);
free(B_table);
}
B_table = NULL;
B_allocnum = 0;
B_num = 0;
}
/*
* Compute the Euler number with index n = z
* For even positive n, newly calculated values with all even indices up
* to n are stored in E_table for later quick access.
*/
NUMBER *
qeuler(ZVALUE z)
{
long i, k, m, n, nn, dd;
NUMBER **p;
NUMBER *s, *s1, *c, *c1, *t;
size_t sz;
if (ziszero(z))
return qlink(&_qone_);
if (zisodd(z) || zisneg(z))
return qlink(&_qzero_);
if (zge31b(z))
return NULL;
n = ztoi(z);
m = (n >> 1) - 1;
if (m < E_num)
return qlink(E_table[m]);
sz = (m + 1) * sizeof(NUMBER *);
if (sz < (size_t) m + 1)
return NULL;
if (E_num)
p = (NUMBER **) realloc(E_table, sz);
else
p = (NUMBER **) malloc(sz);
if (p == NULL)
return NULL;
E_table = p;
for (k = E_num; k <= m; k++) {
nn = 2 * k + 2;
dd = 1;
c = qlink(&_qone_);
s = qlink(&_qnegone_);
i = k;
for (i = 0; i < k; i++) {
c1 = qmuli(c, nn--);
qfree(c);
c = qdivi(c1, dd++);
qfree(c1);
c1 = qmuli(c, nn--);
qfree(c);
c = qdivi(c1, dd++);
qfree(c1);
t = qmul(c, E_table[i]);
s1 = qsub(s, t);
qfree(t);
qfree(s);
s = s1;
}
E_table[k] = s;
qfree(c);
}
E_num = k;
return qlink(E_table[m]);
}
void
qfreeeuler(void)
{
long k;
if (E_num > 0) {
for (k = 0; k < E_num; k++)
qfree(E_table[k]);
free(E_table);
}
E_table = NULL;
E_num = 0;
}
/*
* Catalan numbers: catalan(n) = comb(2*n, n)/(n+1)
* To be called only with integer q
*/
NUMBER *
qcatalan(NUMBER *q)
{
NUMBER *A, *B;
NUMBER *res;
if (qisneg(q))
return qlink(&_qzero_);
A = qscale(q, 1);
B = qcomb(A, q);
if (B == NULL)
return NULL;
qfree(A);
A = qinc(q);
res = qqdiv(B, A);
qfree(A);
qfree(B);
return res;
}
/*
* Compute the Jacobi function (a / b).
* -1 => a is not quadratic residue mod b
@@ -1236,7 +1488,7 @@ qcfappr(NUMBER *q, NUMBER *epsilon, long rnd)
/*
* Calculate the nearest-above, or nearest-below, or nearest, number
* with denominator less than the given number, the choice between
* possibilities being dertermined by the parameter rnd.
* possibilities being determined by the parameter rnd.
*/
NUMBER *
qcfsim(NUMBER *q, long rnd)
@@ -1405,7 +1657,7 @@ qlcm(NUMBER *q1, NUMBER *q2)
/*
* Remove all occurences of the specified factor from a number.
* Remove all occurrences of the specified factor from a number.
* Returned number is always positive or zero.
*/
NUMBER *
@@ -1456,7 +1708,8 @@ qgcdrem(NUMBER *q1, NUMBER *q2)
return qlink(&_qone_);
if (qiszero(q1))
return qlink(&_qzero_);
zgcdrem(q1->num, q2->num, &tmp);
if (zgcdrem(q1->num, q2->num, &tmp) == 0)
return qqabs(q1);
if (zisunit(tmp)) {
zfree(tmp);
return qlink(&_qone_);
@@ -1493,15 +1746,14 @@ qlowfactor(NUMBER *q1, NUMBER *q2)
return utoq(zlowfactor(q1->num, count));
}
/*
* Return the number of places after the decimal point needed to exactly
* represent the specified number as a real number. Integers return zero,
* and non-terminating decimals return minus one. Examples:
* qplaces(1/7)=-1, qplaces(3/10)= 1, qplaces(1/8)=3, qplaces(4)=0.
* qdecplaces(1.23) = 2, qdecplaces(3) = 0, qdecplaces(1/7) = -1.
*/
long
qplaces(NUMBER *q)
qdecplaces(NUMBER *q)
{
long twopow, fivepow;
HALF fiveval[2];
@@ -1532,6 +1784,39 @@ qplaces(NUMBER *q)
}
/*
* Return, if possible, the minimum number of places after the decimal
* point needed to exactly represent q with the specified base.
* Integers return 0 and numbers with non-terminating expansions -1.
* Returns -2 if base inadmissible
*/
long
qplaces(NUMBER *q, ZVALUE base)
{
long count;
ZVALUE tmp;
if (base.len == 1 && base.v[0] == 10)
return qdecplaces(q);
if (ziszero(base) || zisunit(base))
return -2;
if (qisint(q))
return 0;
if (zisonebit(base)) {
if (!zisonebit(q->den))
return -1;
return 1 + (zlowbit(q->den) - 1)/zlowbit(base);
}
count = zgcdrem(q->den, base, &tmp);
if (count == 0)
return -1;
if (!zisunit(tmp))
count = -1;
zfree(tmp);
return count;
}
/*
* Perform a probabilistic primality test (algorithm P in Knuth).
* Returns FALSE if definitely not prime, or TRUE if probably prime.

8
qio.c
View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: qio.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: qio.c,v 29.3 2000/07/17 15:35:49 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/qio.c,v $
*
* Under source code control: 1993/07/30 19:42:46
@@ -191,7 +191,7 @@ qprintnum(NUMBER *q, int outmode)
break;
case MODE_REAL:
prec = qplaces(q);
prec = qdecplaces(q);
if ((prec < 0) || (prec > conf->outdigits)) {
if (conf->tilde_ok)
PUTCHAR('~');
@@ -629,7 +629,7 @@ qparse(char *cp, int flags)
/*
* Print an integer which is guaranteed to fit in the specified number
* of columns, using imbedded '...' characters if numerator and/or
* of columns, using embedded '...' characters if numerator and/or
* denominator is too large.
*/
void

View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: qmath.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: qmath.c,v 29.3 2000/07/17 15:35:49 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/qmath.c,v $
*
* Under source code control: 1990/02/15 01:48:21
@@ -43,10 +43,12 @@ NUMBER _qfour_ = { { _fourval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL };
NUMBER _qten_ = { { _tenval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL };
NUMBER _qnegone_ = { { _oneval_, 1, 1 }, { _oneval_, 1, 0 }, 1, NULL };
NUMBER _qonehalf_ = { { _oneval_, 1, 0 }, { _twoval_, 1, 0 }, 1, NULL };
NUMBER _qneghalf_ = { { _oneval_, 1, 1 }, { _twoval_, 1, 0 }, 1, NULL };
NUMBER _qonesqbase_ = { { _oneval_, 1, 0 }, { _sqbaseval_, 2, 0 }, 1, NULL };
NUMBER * initnumbs[INITCONSTCOUNT] = {&_qzero_, &_qone_, &_qtwo_, &_qthree_,
&_qfour_, &_qten_, &_qnegone_, &_qonehalf_};
&_qfour_, &_qten_, &_qnegone_, &_qonehalf_, &_qneghalf_};
/*
* Create another copy of a number.

23
qmath.h
View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: qmath.h,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: qmath.h,v 29.3 2000/07/17 15:35:49 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/qmath.h,v $
*
* Under source code control: 1993/07/30 19:42:47
@@ -34,8 +34,7 @@
#include "zmath.h"
#define INITCONSTCOUNT 8 /* number of initnumbs[] pre-defined constants */
#define INITCONSTCOUNT 9 /* number of initnumbs[] pre-defined constants */
/*
* Rational arithmetic definitions.
@@ -157,14 +156,15 @@ extern BOOL qprimetest(NUMBER *q1, NUMBER *q2, NUMBER *q3);
extern BOOL qissquare(NUMBER *q);
extern long qilog2(NUMBER *q);
extern long qilog10(NUMBER *q);
extern long qilog(NUMBER *q1, NUMBER *q2);
extern NUMBER *qilog(NUMBER *q, ZVALUE base);
extern BOOL qcmpmod(NUMBER *q1, NUMBER *q2, NUMBER *q3);
extern BOOL qquomod(NUMBER *q1, NUMBER *q2, NUMBER **retdiv, NUMBER **retmod);
extern FLAG qnear(NUMBER *q1, NUMBER *q2, NUMBER *epsilon);
extern long qdigit(NUMBER *q, long i);
extern NUMBER *qdigit(NUMBER *q, ZVALUE dpos, ZVALUE base);
extern long qprecision(NUMBER *q);
extern long qplaces(NUMBER *q);
extern long qdigits(NUMBER *q);
extern long qplaces(NUMBER *q, ZVALUE base);
extern long qdecplaces(NUMBER *q);
extern long qdigits(NUMBER *q, ZVALUE base);
extern void setepsilon(NUMBER *q);
extern NUMBER *qbitvalue(long i);
extern NUMBER *qtenpow(long i);
@@ -208,6 +208,11 @@ extern NUMBER *qacsch(NUMBER *q, NUMBER *epsilon);
extern NUMBER *qacoth(NUMBER *q, NUMBER *epsilon);
extern NUMBER *qlegtoleg(NUMBER *q, NUMBER *epsilon, BOOL wantneg);
extern NUMBER *qpi(NUMBER *epsilon);
extern NUMBER *qcatalan(NUMBER *);
extern NUMBER *qbern(ZVALUE z);
extern void qfreebern(void);
extern NUMBER *qeuler(ZVALUE z);
extern void qfreeeuler(void);
/*
@@ -258,7 +263,7 @@ extern NUMBER *swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all);
/*
* constants used often by the arithmetic routines
*/
extern NUMBER _qzero_, _qone_, _qnegone_, _qonehalf_, _qonesqbase_;
extern NUMBER _qzero_, _qone_, _qnegone_, _qonehalf_, _qneghalf_, _qonesqbase_;
extern NUMBER _qtwo_, _qthree_, _qfour_;
extern NUMBER * initnumbs[];

View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.3 $
* @(#) $Id: quickhash.c,v 29.3 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.4 $
* @(#) $Id: quickhash.c,v 29.4 2001/04/14 22:47:21 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/quickhash.c,v $
*
* Under source code control: 1995/03/04 11:34:23
@@ -304,7 +304,7 @@ objhash(OBJECT *op, QCKHASH val)
/*
* randhash - return a trivial hash for an a55 state
* randhash - return a trivial hash for an s100 state
*
* given:
* state - state to hash
@@ -326,6 +326,7 @@ randhash(RAND *r, QCKHASH val)
val = fnv(r->j, V_RAND+val);
val = fnv(r->k, val);
val = fnv(r->bits, val);
val = fnv(r->need_to_skip, val);
/* hash the state arrays */
return fnv_fullhash(&r->buffer[0], SLEN+SCNT+SHUFLEN, val);

View File

@@ -17,8 +17,8 @@
# received a copy with calc; if not, write to Free Software Foundation, Inc.
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
# @(#) $Revision: 29.2 $
# @(#) $Id: Makefile,v 29.2 2000/06/07 14:02:54 chongo Exp $
# @(#) $Revision: 29.5 $
# @(#) $Id: Makefile,v 29.5 2001/04/08 10:53:52 chongo Exp $
# @(#) $Source: /usr/local/src/cmd/calc/sample/RCS/Makefile,v $
#
# Under source code control: 1997/04/19 22:46:49
@@ -378,7 +378,10 @@ depend:
fi; \
done
${Q}(cd ..; ${MAKE} hsrc)
${Q}for i in `cd ..; ${MAKE} h_list`; do \
${Q}for i in `cd ..; ${MAKE} h_list 2>&1 | \
${SED} -e '/Entering directory/d' \
-e '/Nothing to be done/d' \
-e '/Leaving directory/d'`; do \
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
echo "#if !defined($$tag)" > "skel/$$i"; \
echo "#define $$tag" >> "skel/$$i"; \
@@ -401,7 +404,8 @@ depend:
${Q}mv Makefile Makefile.bak
${Q}${SED} -n '1,/^# DO NOT DELETE THIS LINE/p' Makefile.bak > Makefile
${Q}echo "" >> Makefile
${Q}${SED} -n '3,$$p' skel/sample/makedep.out | ${SORT} -u >> Makefile
${Q}${SED} -n '3,$$p' skel/sample/makedep.out | \
LANG=C ${SORT} -u >> Makefile
-${Q}rm -rf skel
-${Q}if cmp -s Makefile.bak Makefile; then \
echo 'sample Makefile was already up to date'; \
@@ -443,11 +447,12 @@ install: all
# DO NOT DELETE THIS LINE
many_random.o: ../alloc.h
many_random.o: ../block.h
many_random.o: ../byteswap.h
many_random.o: ../calc.h
many_random.o: ../calcerr.h
many_random.o: ../calc.h
many_random.o: ../cmath.h
many_random.o: ../config.h
many_random.o: ../endian_calc.h
@@ -460,21 +465,22 @@ many_random.o: ../have_stdlib.h
many_random.o: ../have_string.h
many_random.o: ../lib_util.h
many_random.o: ../longbits.h
many_random.o: many_random.c
many_random.o: ../md5.h
many_random.o: ../nametype.h
many_random.o: ../qmath.h
many_random.o: ../shs.h
many_random.o: ../shs1.h
many_random.o: ../shs.h
many_random.o: ../string.h
many_random.o: ../value.h
many_random.o: ../win32dll.h
many_random.o: ../zmath.h
many_random.o: ../zrandom.h
many_random.o: many_random.c
test_random.o: ../alloc.h
test_random.o: ../block.h
test_random.o: ../byteswap.h
test_random.o: ../calc.h
test_random.o: ../calcerr.h
test_random.o: ../calc.h
test_random.o: ../cmath.h
test_random.o: ../config.h
test_random.o: ../endian_calc.h
@@ -490,10 +496,11 @@ test_random.o: ../longbits.h
test_random.o: ../md5.h
test_random.o: ../nametype.h
test_random.o: ../qmath.h
test_random.o: ../shs.h
test_random.o: ../shs1.h
test_random.o: ../shs.h
test_random.o: ../string.h
test_random.o: test_random.c
test_random.o: ../value.h
test_random.o: ../win32dll.h
test_random.o: ../zmath.h
test_random.o: ../zrandom.h
test_random.o: test_random.c

79
seed.c
View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: seed.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.4 $
* @(#) $Id: seed.c,v 29.4 2001/03/17 21:31:47 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/seed.c,v $
*
* Under source code control: 1999/10/03 10:06:53
@@ -40,7 +40,16 @@
#include <stdio.h>
#include <errno.h>
#include "have_unistd.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#if defined(_WIN32)
# include <process.h>
# define pid_t int
#endif
/*
* PORTING NOTE:
@@ -55,10 +64,19 @@
*/
#include <sys/types.h>
#include <sys/stat.h>
#include "have_times.h"
#if defined(HAVE_TIME_H)
#include <time.h>
#endif
#if defined(HAVE_SYS_TIME_H)
#include <sys/time.h>
#endif
#if defined(HAVE_SYS_TIMES_H)
#include <sys/times.h>
#include <sys/resource.h>
#endif
#if !defined(_WIN32)
# include <sys/resource.h>
#endif
#include <setjmp.h>
#include "qmath.h"
#include "longbits.h"
@@ -69,14 +87,15 @@
#include "have_getprid.h"
#include "have_urandom.h"
#include "have_rusage.h"
#include "have_uid_t.h"
#if defined(HAVE_USTAT)
# include <ustat.h>
#endif /* HAVE_USTAT */
#endif
#if defined(HAVE_URANDOM)
# include <fcntl.h>
# define DEV_URANDOM "/dev/urandom"
# define DEV_URANDOM_POOL 16
#endif /* HAVE_URANDOM */
#endif
/*
@@ -272,26 +291,32 @@ pseudo_seed(void)
#if defined(HAVE_GETTIME)
# if defined(CLOCK_SGI_CYCLE)
struct timespec sgi_cycle; /* SGI hardware clock */
# endif /* CLOCK_SGI_CYCLE */
# endif
# if defined(CLOCK_REALTIME)
struct timespec realtime; /* POSIX realtime clock */
# endif /* CLOCK_REALTIME */
#endif /* HAVE_GETTIME */
# endif
#endif
#if defined(HAVE_GETPRID)
prid_t getprid; /* project ID */
#endif /* HAVE_GETPRID */
#endif
#if defined(HAVE_URANDOM)
int urandom_fd; /* open descriptor for /dev/urandom */
int urandom_ret; /* read() of /dev/random */
char urandom_pool[DEV_URANDOM_POOL]; /* /dev/urandom data pool */
#endif /* HAVE_URANDOM */
#endif
#if defined(HAVE_SYS_TIME_H)
struct timeval tp; /* time of day */
#endif
pid_t getpid; /* process ID */
#if !defined(_WIN32)
pid_t getppid; /* parent process ID */
#endif
#if defined(HAVE_UID_T)
uid_t getuid; /* real user ID */
uid_t geteuid; /* effective user ID */
gid_t getgid; /* real group ID */
gid_t getegid; /* effective group ID */
#endif
struct stat stat_dot; /* stat of "." */
struct stat stat_dotdot; /* stat of ".." */
struct stat stat_tmp; /* stat of "/tmp" */
@@ -307,19 +332,21 @@ pseudo_seed(void)
struct ustat ustat_stdin; /* usage stat of stdin */
struct ustat ustat_stdout; /* usage stat of stdout */
struct ustat ustat_stderr; /* usage stat of stderr */
#endif /* HAVE_USTAT */
#endif
#if defined(HAVE_GETSID)
pid_t getsid; /* session ID */
#endif /* HAVE_GETSID */
#endif
#if defined(HAVE_GETPGID)
pid_t getpgid; /* process group ID */
#endif /* HAVE_GETPGID */
#endif
#if defined(HAVE_GETRUSAGE)
struct rusage rusage; /* resource utilization */
struct rusage rusage_chld; /* resource utilization of children */
#endif /* HAVE_GETRUSAGE */
#endif
#if defined(HAVE_SYS_TIME_H)
struct timeval tp2; /* time of day again */
struct tms times; /* process times */
#endif
time_t time; /* local time */
size_t size; /* size of this data structure */
jmp_buf env; /* setjmp() context */
@@ -339,14 +366,14 @@ pseudo_seed(void)
#if defined(HAVE_GETTIME)
# if defined(CLOCK_SGI_CYCLE)
(void) clock_gettime(CLOCK_SGI_CYCLE, &sdata.sgi_cycle);
# endif /* CLOCK_SGI_CYCLE */
# endif
# if defined(CLOCK_REALTIME)
(void) clock_gettime(CLOCK_REALTIME, &sdata.realtime);
# endif /* CLOCK_REALTIME */
#endif /* HAVE_GETTIME */
# endif
#endif
#if defined(HAVE_GETPRID)
sdata.getprid = getprid();
#endif /* HAVE_GETPRID */
#endif
#if defined(HAVE_URANDOM)
sdata.urandom_fd = open(DEV_URANDOM, O_NONBLOCK|O_RDONLY);
if (sdata.urandom_fd >= 0) {
@@ -358,13 +385,19 @@ pseudo_seed(void)
sdata.urandom_ret = EOF;
}
#endif /* HAVE_URANDOM */
#if defined(HAVE_SYS_TIME_H)
(void) gettimeofday(&sdata.tp, NULL);
#endif
sdata.getpid = getpid();
#if !defined(_WIN32)
sdata.getppid = getppid();
#endif
#if defined(HAVE_UID_T)
sdata.getuid = getuid();
sdata.geteuid = geteuid();
sdata.getgid = getgid();
sdata.getegid = getegid();
#endif
(void) stat(".", &sdata.stat_dot);
(void) stat("..", &sdata.stat_dotdot);
(void) stat("/tmp", &sdata.stat_tmp);
@@ -380,19 +413,21 @@ pseudo_seed(void)
(void) ustat(sdata.fstat_stdin.st_dev, &sdata.ustat_stdin);
(void) ustat(sdata.fstat_stdout.st_dev, &sdata.ustat_stdout);
(void) ustat(sdata.fstat_stderr.st_dev, &sdata.ustat_stderr);
#endif /* HAVE_USTAT */
#endif
#if defined(HAVE_GETSID)
sdata.getsid = getsid((pid_t)0);
#endif /* HAVE_GETSID */
#endif
#if defined(HAVE_GETPGID)
sdata.getpgid = getpgid((pid_t)0);
#endif /* HAVE_GETPGID */
#endif
#if defined(HAVE_GETRUSAGE)
(void) getrusage(RUSAGE_SELF, &sdata.rusage);
(void) getrusage(RUSAGE_CHILDREN, &sdata.rusage_chld);
#endif /* HAVE_GETRUSAGE */
#endif
#if defined(HAVE_SYS_TIME_H)
(void) gettimeofday(&sdata.tp2, NULL);
(void) times(&sdata.times);
#endif
sdata.time = time(NULL);
sdata.size = sizeof(sdata);
(void) setjmp(sdata.env);

13
token.c
View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.3 $
* @(#) $Id: token.c,v 29.3 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.4 $
* @(#) $Id: token.c,v 29.4 2000/07/17 15:35:49 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/token.c,v $
*
* Under source code control: 1990/02/15 01:48:25
@@ -178,8 +178,8 @@ gettoken(void)
type = T_NULL;
while (type == T_NULL) {
ch = nextchar();
if (allsyms && ((ch!=' ') &&
(ch!=';') && (ch!='"') && (ch!='\n'))) {
if (allsyms && ch!=' ' && ch!=';' && ch!='"' &&
ch!='\'' && ch!='\n' && ch!=EOF) {
reread();
type = eatsymbol();
break;
@@ -566,10 +566,11 @@ eatsymbol(void)
if (allsyms) {
for (;;) {
ch = nextchar();
if ((ch == ' ') || (ch == ';') || (ch == '\n'))
if (ch == ' ' || ch == ';' ||
ch == '\n' || ch == EOF)
break;
if (cc-- > 0)
*cp++ = (char)ch;
*cp++ = (char) ch;
}
reread();
*cp = '\0';

228
value.c
View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: value.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.3 $
* @(#) $Id: value.c,v 29.3 2000/07/17 15:35:49 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/value.c,v $
*
* Under source code control: 1990/02/15 01:48:25
@@ -57,10 +57,10 @@ freevalue(VALUE *vp)
type = vp->v_type;
vp->v_type = V_NULL;
if (type < 0)
vp->v_subtype = V_NOSUBTYPE;
if (type <= 0)
return;
switch (type) {
case V_NULL:
case V_ADDR:
case V_OCTET:
case V_NBLOCK:
@@ -111,7 +111,6 @@ freevalue(VALUE *vp)
math_error("Freeing unknown value type");
/*NOTREACHED*/
}
vp->v_subtype = V_NOSUBTYPE;
}
@@ -341,7 +340,7 @@ negvalue(VALUE *vp, VALUE *vres)
*vres = objcall(OBJ_NEG, vp, NULL_VALUE, NULL_VALUE);
return;
default:
if (vp->v_type < 0)
if (vp->v_type <= 0)
return;
*vres = error_value(E_NEG);
return;
@@ -349,76 +348,6 @@ negvalue(VALUE *vp, VALUE *vres)
}
/*
* addnumeric - add two numeric values togethter
*
* If either value is not real or complex, it is assumed to have
* a value of 0.
*
* Result is placed in the indicated location.
*/
void
addnumeric(VALUE *v1, VALUE *v2, VALUE *vres)
{
COMPLEX *c;
/*
* add numeric values
*/
vres->v_subtype = V_NOSUBTYPE;
switch (TWOVAL(v1->v_type, v2->v_type)) {
case TWOVAL(V_NUM, V_NUM):
vres->v_num = qqadd(v1->v_num, v2->v_num);
vres->v_type = V_NUM;
return;
case TWOVAL(V_COM, V_NUM):
vres->v_com = caddq(v1->v_com, v2->v_num);
vres->v_type = V_COM;
return;
case TWOVAL(V_NUM, V_COM):
vres->v_com = caddq(v2->v_com, v1->v_num);
vres->v_type = V_COM;
return;
case TWOVAL(V_COM, V_COM):
vres->v_com = cadd(v1->v_com, v2->v_com);
vres->v_type = V_COM;
c = vres->v_com;
if (!cisreal(c))
return;
vres->v_num = qlink(c->real);
vres->v_type = V_NUM;
comfree(c);
return;
}
/*
* assume zero if a value is not numeric
*/
if (v1->v_type == V_NUM) {
/* v1 + 0 == v1 */
vres->v_type = v1->v_type;
vres->v_num = qlink(v1->v_num);
} else if (v1->v_type == V_COM) {
/* v1 + 0 == v1 */
vres->v_type = v1->v_type;
vres->v_com = clink(v1->v_com);
} else if (v2->v_type == V_NUM) {
/* v2 + 0 == v2 */
vres->v_type = v2->v_type;
vres->v_num = qlink(v2->v_num);
} else if (v2->v_type == V_COM) {
/* v2 + 0 == v2 */
vres->v_type = v2->v_type;
vres->v_com = clink(v2->v_com);
} else {
/* 0 + 0 = 0 */
vres->v_type = V_NUM;
vres->v_num = qlink(&_qzero_);
}
return;
}
/*
* Add two arbitrary values together.
* Result is placed in the indicated location.
@@ -502,15 +431,12 @@ addvalue(VALUE *v1, VALUE *v2, VALUE *vres)
return;
default:
if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) {
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type < 0)
return;
}
if (v2->v_type < 0) {
copyvalue(v2, vres);
return;
}
*vres = error_value(E_ADD);
if (v2->v_type > 0)
*vres = error_value(E_ADD);
else
vres->v_type = v2->v_type;
return;
}
*vres = objcall(OBJ_ADD, v1, v2, NULL_VALUE);
@@ -592,12 +518,10 @@ subvalue(VALUE *v1, VALUE *v2, VALUE *vres)
return;
default:
if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) {
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type <= 0)
return;
}
if (v2->v_type < 0) {
copyvalue(v2, vres);
if (v2->v_type <= 0) {
vres->v_type = v2->v_type;
return;
}
*vres = error_value(E_SUB);
@@ -659,12 +583,10 @@ mulvalue(VALUE *v1, VALUE *v2, VALUE *vres)
return;
default:
if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) {
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type <= 0)
return;
}
if (v2->v_type < 0) {
copyvalue(v2, vres);
if (v2->v_type <= 0) {
vres->v_type = v2->v_type;
return;
}
*vres = error_value(E_MUL);
@@ -713,8 +635,8 @@ squarevalue(VALUE *vp, VALUE *vres)
*vres = objcall(OBJ_SQUARE, vp, NULL_VALUE, NULL_VALUE);
return;
default:
if (vp->v_type < 0) {
copyvalue(vp, vres);
if (vp->v_type <= 0) {
vres->v_type = vp->v_type;
return;
}
*vres = error_value(E_SQUARE);
@@ -767,10 +689,8 @@ invertvalue(VALUE *vp, VALUE *vres)
vres->v_num = qlink(&_qzero_);
return;
}
if (vp->v_type < 0) {
copyvalue(vp, vres);
if (vp->v_type <= 0)
return;
}
*vres = error_value(E_INV);
return;
}
@@ -819,12 +739,10 @@ andvalue(VALUE *v1, VALUE *v2, VALUE *vres)
return;
default:
if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) {
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type < 0)
return;
}
if (v2->v_type < 0) {
copyvalue(v2, vres);
vres->v_type = v2->v_type;
return;
}
*vres = error_value(E_AND);
@@ -877,12 +795,10 @@ orvalue(VALUE *v1, VALUE *v2, VALUE *vres)
return;
default:
if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) {
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type < 0)
return;
}
if (v2->v_type < 0) {
copyvalue(v2, vres);
vres->v_type = v2->v_type;
return;
}
*vres = error_value(E_OR);
@@ -1097,10 +1013,9 @@ apprvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres)
vres->v_type = v1->v_type;
vres->v_subtype = V_NOSUBTYPE;
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type <= 0)
return;
}
e = NULL;
switch(v2->v_type) {
case V_NUM: e = v2->v_num;
@@ -1239,10 +1154,8 @@ roundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres)
vres->v_com = c;
return;
default:
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type <= 0)
return;
}
*vres = error_value(E_ROUND);
return;
}
@@ -1327,10 +1240,8 @@ broundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres)
vres->v_com = c;
return;
default:
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type <= 0)
return;
}
*vres = error_value(E_BROUND);
return;
}
@@ -1374,10 +1285,8 @@ intvalue(VALUE *vp, VALUE *vres)
*vres = objcall(OBJ_INT, vp, NULL_VALUE, NULL_VALUE);
return;
default:
if (vp->v_type < 0) {
copyvalue(vp, vres);
if (vp->v_type <= 0)
return;
}
*vres = error_value(E_INT);
return;
}
@@ -1423,10 +1332,8 @@ fracvalue(VALUE *vp, VALUE *vres)
*vres = objcall(OBJ_FRAC, vp, NULL_VALUE, NULL_VALUE);
return;
default:
if (vp->v_type < 0) {
copyvalue(vp, vres);
if (vp->v_type < 0)
return;
}
*vres = error_value(E_FRAC);
return;
}
@@ -1461,7 +1368,7 @@ incvalue(VALUE *vp, VALUE *vres)
vres->v_addr = vp->v_addr + 1;
break;
default:
if (vp->v_type >= 0)
if (vp->v_type > 0)
*vres = error_value(E_INCV);
break;
}
@@ -1533,8 +1440,8 @@ conjvalue(VALUE *vp, VALUE *vres)
*vres = objcall(OBJ_CONJ, vp, NULL_VALUE, NULL_VALUE);
return;
default:
if (vp->v_type < 0) {
copyvalue(vp, vres);
if (vp->v_type <= 0) {
vres->v_type = vp->v_type;
return;
}
*vres = error_value(E_CONJ);
@@ -1560,8 +1467,8 @@ sqrtvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres)
}
vres->v_type = v1->v_type;
vres->v_subtype = V_NOSUBTYPE;
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type <= 0) {
vres->v_type = v1->v_type;
return;
}
if (v2->v_type == V_NULL) {
@@ -1630,8 +1537,8 @@ rootvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres)
COMPLEX *c;
vres->v_subtype = V_NOSUBTYPE;
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type <= 0) {
vres->v_type = v1->v_type;
return;
}
if (v2->v_type != V_NUM) {
@@ -1700,8 +1607,8 @@ absvalue(VALUE *v1, VALUE *v2, VALUE *vres)
return;
}
vres->v_subtype = V_NOSUBTYPE;
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type <= 0) {
vres->v_type = v1->v_type;
return;
}
switch (v1->v_type) {
@@ -1739,8 +1646,8 @@ normvalue(VALUE *vp, VALUE *vres)
vres->v_type = vp->v_type;
vres->v_subtype = V_NOSUBTYPE;
if (vp->v_type < 0) {
copyvalue(vp, vres);
if (vp->v_type <= 0) {
vres->v_type = vp->v_type;
return;
}
switch (vp->v_type) {
@@ -1786,8 +1693,8 @@ shiftvalue(VALUE *v1, VALUE *v2, BOOL rightshift, VALUE *vres)
VALUE tmp;
vres->v_subtype = V_NOSUBTYPE;
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type <= 0) {
vres->v_type = v1->v_type;
return;
}
if ((v2->v_type != V_NUM) || (qisfrac(v2->v_num))) {
@@ -1872,8 +1779,8 @@ scalevalue(VALUE *v1, VALUE *v2, VALUE *vres)
long n = 0;
vres->v_subtype = V_NOSUBTYPE;
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type <= 0) {
vres->v_type = v1->v_type;
return;
}
if ((v2->v_type != V_NUM) || qisfrac(v2->v_num)) {
@@ -1924,9 +1831,9 @@ powivalue(VALUE *v1, VALUE *v2, VALUE *vres)
}
vres->v_type = v1->v_type;
vres->v_subtype = V_NOSUBTYPE;
if (v1->v_type < 0 && v1->v_type != -E_1OVER0)
if (v1->v_type <= 0 && v1->v_type != -E_1OVER0)
return;
if (v2->v_type < 0) {
if (v2->v_type <= 0) {
vres->v_type = v2->v_type;
return;
}
@@ -1982,8 +1889,8 @@ powervalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres)
COMPLEX *c, ctmp1, ctmp2;
vres->v_subtype = V_NOSUBTYPE;
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type <= 0) {
vres->v_type = v1->v_type;
return;
}
if (v1->v_type != V_NUM && v1->v_type != V_COM) {
@@ -2063,9 +1970,9 @@ divvalue(VALUE *v1, VALUE *v2, VALUE *vres)
vres->v_type = v1->v_type;
vres->v_subtype = V_NOSUBTYPE;
if (v1->v_type < 0)
if (v1->v_type <= 0)
return;
if (v2->v_type < 0) {
if (v2->v_type <= 0) {
if (testvalue(v1) && v2->v_type == -E_1OVER0) {
vres->v_type = V_NUM;
vres->v_num = qlink(&_qzero_);
@@ -2146,10 +2053,9 @@ quovalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres)
vres->v_type = v1->v_type;
vres->v_subtype = V_NOSUBTYPE;
if (v1->v_type < 0) {
copyvalue(v1, vres);
if (v1->v_type <= 0)
return;
}
if (v1->v_type == V_MAT) {
vres->v_mat = matquoval(v1->v_mat, v2, v3);
return;
@@ -2162,8 +2068,8 @@ quovalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres)
*vres = objcall(OBJ_QUO, v1, v2, v3);
return;
}
if (v2->v_type < 0) {
copyvalue(v2, vres);
if (v2->v_type <= 0) {
vres->v_type = v2->v_type;
return;
}
if (v2->v_type != V_NUM) {
@@ -2224,12 +2130,11 @@ modvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres)
NUMBER *q1, *q2;
long rnd;
vres->v_subtype = V_NOSUBTYPE;
if (v1->v_type < 0) {
copyvalue(v1, vres);
return;
}
vres->v_type = v1->v_type;
vres->v_subtype = V_NOSUBTYPE;
if (v1->v_type <= 0)
return;
if (v1->v_type == V_MAT) {
vres->v_mat = matmodval(v1->v_mat, v2, v3);
return;
@@ -2242,8 +2147,8 @@ modvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres)
*vres = objcall(OBJ_MOD, v1, v2, v3);
return;
}
if (v2->v_type < 0) {
copyvalue(v2, vres);
if (v2->v_type <= 0) {
vres->v_type = v2->v_type;
return;
}
if (v2->v_type != V_NUM) {
@@ -2387,7 +2292,7 @@ comparevalue(VALUE *v1, VALUE *v2)
return comparevalue(v2, v1);
if (v1->v_type != v2->v_type)
return TRUE;
if (v1->v_type < 0)
if (v1->v_type <= 0)
return FALSE;
switch (v1->v_type) {
case V_NUM:
@@ -2408,8 +2313,6 @@ comparevalue(VALUE *v1, VALUE *v2)
case V_ASSOC:
r = assoccmp(v1->v_assoc, v2->v_assoc);
break;
case V_NULL:
break;
case V_FILE:
r = (v1->v_file != v2->v_file);
break;
@@ -2697,11 +2600,8 @@ sgnvalue(VALUE *vp, VALUE *vres)
*vres = objcall(OBJ_SGN, vp, NULL_VALUE, NULL_VALUE);
return;
default:
if (vp->v_type < 0) {
copyvalue(vp, vres);
return;
}
*vres = error_value(E_SGN);
if (vp->v_type > 0)
*vres = error_value(E_SGN);
return;
}
}
@@ -2855,7 +2755,7 @@ config_print(CONFIG *cfg)
*/
if (cfg == NULL || cfg->epsilon == NULL || cfg->prompt1 == NULL ||
cfg->prompt2 == NULL) {
math_error("CONFIG value is invaid");
math_error("CONFIG value is invalid");
/*NOTREACHED*/
}

342
value.h
View File

@@ -17,8 +17,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.2 $
* @(#) $Id: value.h,v 29.2 2000/06/07 14:02:13 chongo Exp $
* @(#) $Revision: 29.5 $
* @(#) $Id: value.h,v 29.5 2001/03/17 21:31:47 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/value.h,v $
*
* Under source code control: 1993/07/30 19:42:47
@@ -32,6 +32,7 @@
#define __VALUE_H__
#include "win32dll.h"
#include "cmath.h"
#include "config.h"
#include "shs.h"
@@ -187,60 +188,59 @@ struct value {
/*
* value functions
*/
extern void freevalue(VALUE *vp);
extern void copyvalue(VALUE *vp, VALUE *vres);
extern void negvalue(VALUE *vp, VALUE *vres);
extern void addvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern void addnumeric(VALUE *v1, VALUE *v2, VALUE *vres);
extern void subvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern void mulvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern void orvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern void andvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern void compvalue(VALUE *vp, VALUE *vres);
extern void xorvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern void squarevalue(VALUE *vp, VALUE *vres);
extern void invertvalue(VALUE *vp, VALUE *vres);
extern void roundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern void broundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern void setminusvalue(VALUE *, VALUE *, VALUE *);
extern void backslashvalue(VALUE *, VALUE *);
extern void contentvalue(VALUE *, VALUE *);
extern void hashopvalue(VALUE *, VALUE *, VALUE *);
extern void apprvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern void intvalue(VALUE *vp, VALUE *vres);
extern void fracvalue(VALUE *vp, VALUE *vres);
extern void incvalue(VALUE *vp, VALUE *vres);
extern void decvalue(VALUE *vp, VALUE *vres);
extern void conjvalue(VALUE *vp, VALUE *vres);
extern void sqrtvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern void rootvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern void absvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern void normvalue(VALUE *vp, VALUE *vres);
extern void shiftvalue(VALUE *v1, VALUE *v2, BOOL rightshift, VALUE *vres);
extern void scalevalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern void powivalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern void powervalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern void divvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern void quovalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern void modvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern BOOL testvalue(VALUE *vp);
extern BOOL comparevalue(VALUE *v1, VALUE *v2);
extern BOOL acceptvalue(VALUE *v1, VALUE *v2);
extern void relvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern void sgnvalue(VALUE *vp, VALUE *vres);
extern QCKHASH hashvalue(VALUE *vp, QCKHASH val);
extern void printvalue(VALUE *vp, int flags);
extern BOOL precvalue(VALUE *v1, VALUE *v2);
extern VALUE error_value(int e);
extern int set_errno(int e);
extern int set_errcount(int e);
extern long countlistitems(LIST *lp);
extern void addlistitems(LIST *lp, VALUE *vres);
extern void addlistinv(LIST *lp, VALUE *vres);
extern void copy2octet(VALUE *, OCTET *);
extern int copystod(VALUE *, long, long, VALUE *, long);
extern void protectall(VALUE *, int);
extern void set_update(int);
extern DLL void freevalue(VALUE *vp);
extern DLL void copyvalue(VALUE *vp, VALUE *vres);
extern DLL void negvalue(VALUE *vp, VALUE *vres);
extern DLL void addvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern DLL void subvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern DLL void mulvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern DLL void orvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern DLL void andvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern DLL void compvalue(VALUE *vp, VALUE *vres);
extern DLL void xorvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern DLL void squarevalue(VALUE *vp, VALUE *vres);
extern DLL void invertvalue(VALUE *vp, VALUE *vres);
extern DLL void roundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern DLL void broundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern DLL void setminusvalue(VALUE *, VALUE *, VALUE *);
extern DLL void backslashvalue(VALUE *, VALUE *);
extern DLL void contentvalue(VALUE *, VALUE *);
extern DLL void hashopvalue(VALUE *, VALUE *, VALUE *);
extern DLL void apprvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern DLL void intvalue(VALUE *vp, VALUE *vres);
extern DLL void fracvalue(VALUE *vp, VALUE *vres);
extern DLL void incvalue(VALUE *vp, VALUE *vres);
extern DLL void decvalue(VALUE *vp, VALUE *vres);
extern DLL void conjvalue(VALUE *vp, VALUE *vres);
extern DLL void sqrtvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern DLL void rootvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern DLL void absvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern DLL void normvalue(VALUE *vp, VALUE *vres);
extern DLL void shiftvalue(VALUE *v1, VALUE *v2, BOOL rightshift, VALUE *vres);
extern DLL void scalevalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern DLL void powivalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern DLL void powervalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern DLL void divvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern DLL void quovalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern DLL void modvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
extern DLL BOOL testvalue(VALUE *vp);
extern DLL BOOL comparevalue(VALUE *v1, VALUE *v2);
extern DLL BOOL acceptvalue(VALUE *v1, VALUE *v2);
extern DLL void relvalue(VALUE *v1, VALUE *v2, VALUE *vres);
extern DLL void sgnvalue(VALUE *vp, VALUE *vres);
extern DLL QCKHASH hashvalue(VALUE *vp, QCKHASH val);
extern DLL void printvalue(VALUE *vp, int flags);
extern DLL BOOL precvalue(VALUE *v1, VALUE *v2);
extern DLL VALUE error_value(int e);
extern DLL int set_errno(int e);
extern DLL int set_errcount(int e);
extern DLL long countlistitems(LIST *lp);
extern DLL void addlistitems(LIST *lp, VALUE *vres);
extern DLL void addlistinv(LIST *lp, VALUE *vres);
extern DLL void copy2octet(VALUE *, OCTET *);
extern DLL int copystod(VALUE *, long, long, VALUE *, long);
extern DLL void protectall(VALUE *, int);
extern DLL void set_update(int);
/*
@@ -257,44 +257,44 @@ struct matrix {
#define matsize(n) (sizeof(MATRIX) - sizeof(VALUE) + ((n) * sizeof(VALUE)))
extern MATRIX *matadd(MATRIX *m1, MATRIX *m2);
extern MATRIX *matsub(MATRIX *m1, MATRIX *m2);
extern MATRIX *matmul(MATRIX *m1, MATRIX *m2);
extern MATRIX *matneg(MATRIX *m);
extern MATRIX *matalloc(long size);
extern MATRIX *matcopy(MATRIX *m);
extern MATRIX *matinit(MATRIX *m, VALUE *v1, VALUE *v2);
extern MATRIX *matsquare(MATRIX *m);
extern MATRIX *matinv(MATRIX *m);
extern MATRIX *matscale(MATRIX *m, long n);
extern MATRIX *matshift(MATRIX *m, long n);
extern MATRIX *matmulval(MATRIX *m, VALUE *vp);
extern MATRIX *matpowi(MATRIX *m, NUMBER *q);
extern MATRIX *matconj(MATRIX *m);
extern MATRIX *matquoval(MATRIX *m, VALUE *vp, VALUE *v3);
extern MATRIX *matmodval(MATRIX *m, VALUE *vp, VALUE *v3);
extern MATRIX *matint(MATRIX *m);
extern MATRIX *matfrac(MATRIX *m);
extern MATRIX *matappr(MATRIX *m, VALUE *v2, VALUE *v3);
extern VALUE mattrace(MATRIX *m);
extern MATRIX *mattrans(MATRIX *m);
extern MATRIX *matcross(MATRIX *m1, MATRIX *m2);
extern BOOL mattest(MATRIX *m);
extern void matsum(MATRIX *m, VALUE *vres);
extern BOOL matcmp(MATRIX *m1, MATRIX *m2);
extern int matsearch(MATRIX *m, VALUE *vp, long start, long end, ZVALUE *index);
extern int matrsearch(MATRIX *m, VALUE *vp, long start, long end, ZVALUE *index);
extern VALUE matdet(MATRIX *m);
extern VALUE matdot(MATRIX *m1, MATRIX *m2);
extern void matfill(MATRIX *m, VALUE *v1, VALUE *v2);
extern void matfree(MATRIX *m);
extern void matprint(MATRIX *m, long max_print);
extern VALUE *matindex(MATRIX *mp, BOOL create, long dim, VALUE *indices);
extern void matreverse(MATRIX *m);
extern void matsort(MATRIX *m);
extern BOOL matisident(MATRIX *m);
extern MATRIX *matround(MATRIX *m, VALUE *v2, VALUE *v3);
extern MATRIX *matbround(MATRIX *m, VALUE *v2, VALUE *v3);
extern DLL MATRIX *matadd(MATRIX *m1, MATRIX *m2);
extern DLL MATRIX *matsub(MATRIX *m1, MATRIX *m2);
extern DLL MATRIX *matmul(MATRIX *m1, MATRIX *m2);
extern DLL MATRIX *matneg(MATRIX *m);
extern DLL MATRIX *matalloc(long size);
extern DLL MATRIX *matcopy(MATRIX *m);
extern DLL MATRIX *matinit(MATRIX *m, VALUE *v1, VALUE *v2);
extern DLL MATRIX *matsquare(MATRIX *m);
extern DLL MATRIX *matinv(MATRIX *m);
extern DLL MATRIX *matscale(MATRIX *m, long n);
extern DLL MATRIX *matshift(MATRIX *m, long n);
extern DLL MATRIX *matmulval(MATRIX *m, VALUE *vp);
extern DLL MATRIX *matpowi(MATRIX *m, NUMBER *q);
extern DLL MATRIX *matconj(MATRIX *m);
extern DLL MATRIX *matquoval(MATRIX *m, VALUE *vp, VALUE *v3);
extern DLL MATRIX *matmodval(MATRIX *m, VALUE *vp, VALUE *v3);
extern DLL MATRIX *matint(MATRIX *m);
extern DLL MATRIX *matfrac(MATRIX *m);
extern DLL MATRIX *matappr(MATRIX *m, VALUE *v2, VALUE *v3);
extern DLL VALUE mattrace(MATRIX *m);
extern DLL MATRIX *mattrans(MATRIX *m);
extern DLL MATRIX *matcross(MATRIX *m1, MATRIX *m2);
extern DLL BOOL mattest(MATRIX *m);
extern DLL void matsum(MATRIX *m, VALUE *vres);
extern DLL BOOL matcmp(MATRIX *m1, MATRIX *m2);
extern DLL int matsearch(MATRIX *m, VALUE *vp, long start, long end, ZVALUE *index);
extern DLL int matrsearch(MATRIX *m, VALUE *vp, long start, long end, ZVALUE *index);
extern DLL VALUE matdet(MATRIX *m);
extern DLL VALUE matdot(MATRIX *m1, MATRIX *m2);
extern DLL void matfill(MATRIX *m, VALUE *v1, VALUE *v2);
extern DLL void matfree(MATRIX *m);
extern DLL void matprint(MATRIX *m, long max_print);
extern DLL VALUE *matindex(MATRIX *mp, BOOL create, long dim, VALUE *indices);
extern DLL void matreverse(MATRIX *m);
extern DLL void matsort(MATRIX *m);
extern DLL BOOL matisident(MATRIX *m);
extern DLL MATRIX *matround(MATRIX *m, VALUE *v2, VALUE *v3);
extern DLL MATRIX *matbround(MATRIX *m, VALUE *v2, VALUE *v3);
/*
@@ -321,32 +321,32 @@ struct list {
};
extern void insertlistfirst(LIST *lp, VALUE *vp);
extern void insertlistlast(LIST *lp, VALUE *vp);
extern void insertlistmiddle(LIST *lp, long index, VALUE *vp);
extern void removelistfirst(LIST *lp, VALUE *vp);
extern void removelistlast(LIST *lp, VALUE *vp);
extern void removelistmiddle(LIST *lp, long index, VALUE *vp);
extern void listfree(LIST *lp);
extern void listprint(LIST *lp, long max_print);
extern int listsearch(LIST *lp, VALUE *vp, long start, long end, ZVALUE *index);
extern int listrsearch(LIST *lp, VALUE *vp, long start, long end, ZVALUE *index);
extern BOOL listcmp(LIST *lp1, LIST *lp2);
extern VALUE *listfindex(LIST *lp, long index);
extern LIST *listalloc(void);
extern LIST *listcopy(LIST *lp);
extern void listreverse(LIST *lp);
extern void listsort(LIST *lp);
extern LIST *listappr(LIST *lp, VALUE *v2, VALUE *v3);
extern LIST *listround(LIST *m, VALUE *v2, VALUE *v3);
extern LIST *listbround(LIST *m, VALUE *v2, VALUE *v3);
extern LIST *listquo(LIST *lp, VALUE *v2, VALUE *v3);
extern LIST *listmod(LIST *lp, VALUE *v2, VALUE *v3);
extern BOOL evp(LISTELEM *cp, LISTELEM *x, VALUE *vres);
extern BOOL evalpoly(LIST *clist, LISTELEM *x, VALUE *vres);
extern void insertitems(LIST *lp1, LIST *lp2);
extern LISTELEM *listelement(LIST *, long);
extern LIST *listsegment(LIST *, long, long);
extern DLL void insertlistfirst(LIST *lp, VALUE *vp);
extern DLL void insertlistlast(LIST *lp, VALUE *vp);
extern DLL void insertlistmiddle(LIST *lp, long index, VALUE *vp);
extern DLL void removelistfirst(LIST *lp, VALUE *vp);
extern DLL void removelistlast(LIST *lp, VALUE *vp);
extern DLL void removelistmiddle(LIST *lp, long index, VALUE *vp);
extern DLL void listfree(LIST *lp);
extern DLL void listprint(LIST *lp, long max_print);
extern DLL int listsearch(LIST *lp, VALUE *vp, long start, long end, ZVALUE *index);
extern DLL int listrsearch(LIST *lp, VALUE *vp, long start, long end, ZVALUE *index);
extern DLL BOOL listcmp(LIST *lp1, LIST *lp2);
extern DLL VALUE *listfindex(LIST *lp, long index);
extern DLL LIST *listalloc(void);
extern DLL LIST *listcopy(LIST *lp);
extern DLL void listreverse(LIST *lp);
extern DLL void listsort(LIST *lp);
extern DLL LIST *listappr(LIST *lp, VALUE *v2, VALUE *v3);
extern DLL LIST *listround(LIST *m, VALUE *v2, VALUE *v3);
extern DLL LIST *listbround(LIST *m, VALUE *v2, VALUE *v3);
extern DLL LIST *listquo(LIST *lp, VALUE *v2, VALUE *v3);
extern DLL LIST *listmod(LIST *lp, VALUE *v2, VALUE *v3);
extern DLL BOOL evp(LISTELEM *cp, LISTELEM *x, VALUE *vres);
extern DLL BOOL evalpoly(LIST *clist, LISTELEM *x, VALUE *vres);
extern DLL void insertitems(LIST *lp1, LIST *lp2);
extern DLL LISTELEM *listelement(LIST *, long);
extern DLL LIST *listsegment(LIST *, long, long);
/*
@@ -371,15 +371,15 @@ struct assoc {
};
extern ASSOC *assocalloc(long initsize);
extern ASSOC *assoccopy(ASSOC *ap);
extern void assocfree(ASSOC *ap);
extern void assocprint(ASSOC *ap, long max_print);
extern int assocsearch(ASSOC *ap, VALUE *vp, long start, long end, ZVALUE *index);
extern int assocrsearch(ASSOC *ap, VALUE *vp, long start, long end, ZVALUE *index);
extern BOOL assoccmp(ASSOC *ap1, ASSOC *ap2);
extern VALUE *assocfindex(ASSOC *ap, long index);
extern VALUE *associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices);
extern DLL ASSOC *assocalloc(long initsize);
extern DLL ASSOC *assoccopy(ASSOC *ap);
extern DLL void assocfree(ASSOC *ap);
extern DLL void assocprint(ASSOC *ap, long max_print);
extern DLL int assocsearch(ASSOC *ap, VALUE *vp, long start, long end, ZVALUE *index);
extern DLL int assocrsearch(ASSOC *ap, VALUE *vp, long start, long end, ZVALUE *index);
extern DLL BOOL assoccmp(ASSOC *ap1, ASSOC *ap2);
extern DLL VALUE *assocfindex(ASSOC *ap, long index);
extern DLL VALUE *associndex(ASSOC *ap, BOOL create, long dim, VALUE *indices);
/*
@@ -461,62 +461,62 @@ struct object {
(sizeof(OBJECT) + ((elements) - USUAL_ELEMENTS) * sizeof(VALUE))
extern OBJECT *objcopy(OBJECT *op);
extern OBJECT *objalloc(long index);
extern VALUE objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3);
extern void objfree(OBJECT *op);
extern int addelement(char *name);
extern int defineobject(char *name, int indices[], int count);
extern int checkobject(char *name);
extern void showobjfuncs(void);
extern void showobjtypes(void);
extern int findelement(char *name);
extern char *objtypename(unsigned long index);
extern int objoffset(OBJECT *op, long index);
extern DLL OBJECT *objcopy(OBJECT *op);
extern DLL OBJECT *objalloc(long index);
extern DLL VALUE objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3);
extern DLL void objfree(OBJECT *op);
extern DLL int addelement(char *name);
extern DLL int defineobject(char *name, int indices[], int count);
extern DLL int checkobject(char *name);
extern DLL void showobjfuncs(void);
extern DLL void showobjtypes(void);
extern DLL int findelement(char *name);
extern DLL char *objtypename(unsigned long index);
extern DLL int objoffset(OBJECT *op, long index);
/*
* Configuration parameter name and type.
*/
extern NAMETYPE configs[];
extern void config_value(CONFIG *cfg, int type, VALUE *ret);
extern void setconfig(int type, VALUE *vp);
extern void config_print(CONFIG *cfg); /* the CONFIG to print */
extern DLL void config_value(CONFIG *cfg, int type, VALUE *ret);
extern DLL void setconfig(int type, VALUE *vp);
extern DLL void config_print(CONFIG *cfg); /* the CONFIG to print */
/*
* size, memsize and sizeof support
*/
extern long elm_count(VALUE *vp);
extern long lsizeof(VALUE *vp);
extern long memsize(VALUE *vp);
extern DLL long elm_count(VALUE *vp);
extern DLL long lsizeof(VALUE *vp);
extern DLL long memsize(VALUE *vp);
/*
* String functions
*/
extern STRING *stringadd(STRING *, STRING *);
extern STRING *stringcopy(STRING *);
extern STRING *stringsub(STRING *, STRING *);
extern STRING *stringmul(NUMBER *, STRING *);
extern STRING *stringand(STRING *, STRING *);
extern STRING *stringor(STRING *, STRING *);
extern STRING *stringxor(STRING *, STRING *);
extern STRING *stringdiff(STRING *, STRING *);
extern STRING *stringsegment(STRING *, long, long);
extern STRING *stringshift(STRING *, long);
extern STRING *stringcomp(STRING *);
extern STRING *stringneg(STRING *);
extern STRING *stringcpy(STRING *, STRING *);
extern STRING *stringncpy(STRING *, STRING *, long);
extern long stringcontent(STRING *s);
extern long stringlowbit(STRING *s);
extern long stringhighbit(STRING *s);
extern BOOL stringcmp(STRING *, STRING *);
extern BOOL stringrel(STRING *, STRING *);
extern int stringbit(STRING *, long);
extern BOOL stringtest(STRING *);
extern int stringsetbit(STRING *, long, BOOL);
extern int stringsearch(STRING *, STRING *, long, long, ZVALUE *);
extern int stringrsearch(STRING *, STRING *, long, long, ZVALUE *);
extern DLL STRING *stringadd(STRING *, STRING *);
extern DLL STRING *stringcopy(STRING *);
extern DLL STRING *stringsub(STRING *, STRING *);
extern DLL STRING *stringmul(NUMBER *, STRING *);
extern DLL STRING *stringand(STRING *, STRING *);
extern DLL STRING *stringor(STRING *, STRING *);
extern DLL STRING *stringxor(STRING *, STRING *);
extern DLL STRING *stringdiff(STRING *, STRING *);
extern DLL STRING *stringsegment(STRING *, long, long);
extern DLL STRING *stringshift(STRING *, long);
extern DLL STRING *stringcomp(STRING *);
extern DLL STRING *stringneg(STRING *);
extern DLL STRING *stringcpy(STRING *, STRING *);
extern DLL STRING *stringncpy(STRING *, STRING *, long);
extern DLL long stringcontent(STRING *s);
extern DLL long stringlowbit(STRING *s);
extern DLL long stringhighbit(STRING *s);
extern DLL BOOL stringcmp(STRING *, STRING *);
extern DLL BOOL stringrel(STRING *, STRING *);
extern DLL int stringbit(STRING *, long);
extern DLL BOOL stringtest(STRING *);
extern DLL int stringsetbit(STRING *, long, BOOL);
extern DLL int stringsearch(STRING *, STRING *, long, long, ZVALUE *);
extern DLL int stringrsearch(STRING *, STRING *, long, long, ZVALUE *);
#endif /* !__VALUE_H__ */

View File

@@ -19,8 +19,8 @@
* received a copy with calc; if not, write to Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* @(#) $Revision: 29.13 $
* @(#) $Id: version.c,v 29.13 2000/06/07 16:12:19 chongo Exp $
* @(#) $Revision: 29.24 $
* @(#) $Id: version.c,v 29.24 2001/04/14 22:56:46 chongo Exp $
* @(#) $Source: /usr/local/src/cmd/calc/RCS/version.c,v $
*
* Under source code control: 1990/05/22 11:00:58
@@ -42,8 +42,8 @@ static char *program;
#define MAJOR_VER 2 /* major version */
#define MINOR_VER 11 /* minor version */
#define MAJOR_PATCH 2 /* patch level or 0 if no patch */
#define MINOR_PATCH "1.0" /* test number or empty string if no patch */
#define MAJOR_PATCH 5 /* patch level or 0 if no patch */
#define MINOR_PATCH "3" /* test number or empty string if no patch */
/*
* calc version constants

58
win32.mkdef Normal file
View File

@@ -0,0 +1,58 @@
TERMCONTROL=-DUSE_WIN32
HAVE_VSPRINTF=-UDONT_HAVE_VSPRINTF
BYTE_ORDER=-DLITTLE_ENDIAN
LONG_BITS=32
LONGLONG_BITS=0
HAVE_FPOS=-DHAVE_NO_FPOS
HAVE_FPOS_POS=-DHAVE_NO_FPOS_POS
FPOS_POS_BITS=-UFPOS_POS_BITS
FPOS_BITS=-DFPOS_BITS=64
OFF_T_BITS=-DOFF_T_BITS=32
DEV_BITS=-DDEV_BITS=32
INODE_BITS=-DINODE_BITS=16
HAVE_OFFSCL=-UOFF_T_NON_SCALAR
HAVE_POSSCL=-UFILEPOS_NON_SCALAR
HAVE_CONST=-UHAVE_NO_CONST
HAVE_UID_T=-DHAVE_NO_UID_T
HAVE_NEWSTR=-UHAVE_NO_NEWSTR
HAVE_MEMMOVE=-UHAVE_NO_MEMMOVE
HAVE_USTAT=-DHAVE_NO_USTAT
HAVE_GETSID=-DHAVE_NO_GETSID
HAVE_GETPGID=-DHAVE_NO_GETPGID
HAVE_GETTIME=-DHAVE_NO_GETTIME
HAVE_GETPRID=-DHAVE_NO_GETPRID
HAVE_URANDOM_H=NO
HAVE_GETRUSAGE=-DHAVE_NO_GETRUSAGE
HAVE_STRDUP=-UHAVE_NO_STRDUP
ALIGN32=-UMUST_ALIGN32
HAVE_MALLOC_H=YES
HAVE_STDLIB_H=YES
HAVE_STRING_H=YES
HAVE_TIMES_H=NO
HAVE_SYS_TIMES_H=NO
HAVE_TIME_H=YES
HAVE_SYS_TIME_H=NO
HAVE_UNISTD_H=NO
LIBDIR=/lib/calc
HELPDIR=/lib/calc/help
INCDIRCALC=/include/calc
CUSTOMLIBDIR=/lib/calc/custom
CUSTOMHELPDIR=/lib/calc/help/custhelp
SCRIPTDIR=/lib/calc/cscript
MANDIR=
CATDIR=
MANEXT=
CATEXT=
NROFF=
NROFF_ARG=
MANMAKE=
MANMODE=
CALCPATH=./cal
CALCRC='/lib/calc/startup:~/.calcrc:./.calcinit'
USE_READLINE=
READLINE_LIB=
READLINE_INCLUDE=
CALCPAGER=
ECHO=

15
win32/align32.h Normal file
View File

@@ -0,0 +1,15 @@
/*
* DO NOT EDIT -- generated by the Makefile
*/
#if !defined(__MUST_ALIGN32_H__)
#define __MUST_ALIGN32_H__
/* must we always align 32 bit accesses? */
/* forced to not require 32 bit alignment */
#undef MUST_ALIGN32
#endif /* !__MUST_ALIGN32_H__ */

18
win32/args.h Normal file
View File

@@ -0,0 +1,18 @@
/*
* DO NOT EDIT -- generated by the Makefile
*/
#if !defined(__ARGS_H__)
#define __ARGS_H__
/* what type of variable args do we have? */
#define STDARG /* use <stdarg.h> */
#include <stdarg.h>
/* should we use vsprintf()? */
#define HAVE_VS /* yes */
#endif /* !__ARGS_H__ */

379
win32/calcerr.c Normal file
View File

@@ -0,0 +1,379 @@
/*
* DO NOT EDIT
*
* generated by calcerr.tbl via Makefile
*/
#include <stdio.h>
#include "calcerr.h"
#include "have_const.h"
/*
* names of calc error values
*/
CONST char *error_table[E__COUNT+2] = {
"No error",
"Division by zero",
"Indeterminate (0/0)",
"Bad arguments for +",
"Bad arguments for binary -",
"Bad arguments for *",
"Bad arguments for /",
"Bad argument for unary -",
"Bad argument for squaring",
"Bad argument for inverse",
"Bad argument for ++",
"Bad argument for --",
"Bad argument for int",
"Bad argument for frac",
"Bad argument for conj",
"Bad first argument for appr",
"Bad second argument for appr",
"Bad third argument for appr",
"Bad first argument for round",
"Bad second argument for round",
"Bad third argument for round",
"Bad first argument for bround",
"Bad second argument for bround",
"Bad third argument for bround",
"Bad first argument for sqrt",
"Bad second argument for sqrt",
"Bad third argument for sqrt",
"Bad first argument for root",
"Bad second argument for root",
"Bad third argument for root",
"Bad argument for norm",
"Bad first argument for << or >>",
"Bad second argument for << or >>",
"Bad first argument for scale",
"Bad second argument for scale",
"Bad first argument for ^",
"Bad second argument for ^",
"Bad first argument for power",
"Bad second argument for power",
"Bad third argument for power",
"Bad first argument for quo or //",
"Bad second argument for quo or //",
"Bad third argument for quo",
"Bad first argument for mod or %",
"Bad second argument for mod or %",
"Bad third argument for mod",
"Bad argument for sgn",
"Bad first argument for abs",
"Bad second argument for abs",
"Scan error in argument for eval",
"Non-simple type for str",
"Non-real epsilon for exp",
"Bad first argument for exp",
"Non-file first argument for fputc",
"Bad second argument for fputc",
"File not open for writing for fputc",
"Non-file first argument for fgetc",
"File not open for reading for fgetc",
"Non-string arguments for fopen",
"Unrecognized mode for fopen",
"Non-file first argument for freopen",
"Non-string or unrecognized mode for freopen",
"Non-string third argument for freopen",
"Non-file argument for fclose",
"Non-file argument for fflush",
"Non-file first argument for fputs",
"Non-string argument after first for fputs",
"File not open for writing for fputs",
"Non-file argument for fgets",
"File not open for reading for fgets",
"Non-file first argument for fputstr",
"Non-string argument after first for fputstr",
"File not open for writing for fputstr",
"Non-file first argument for fgetstr",
"File not open for reading for fgetstr",
"Non-file argument for fgetline",
"File not open for reading for fgetline",
"Non-file argument for fgetfield",
"File not open for reading for fgetfield",
"Non-file argument for rewind",
"Non-integer argument for files",
"Non-string fmt argument for fprint",
"Stdout not open for writing to ???",
"Non-file first argument for fprintf",
"Non-string second (fmt) argument for fprintf",
"File not open for writing for fprintf",
"Non-string first (fmt) argument for strprintf",
"Error in attempting strprintf ???",
"Non-file first argument for fscan",
"File not open for reading for fscan",
"Non-string first argument for strscan",
"Non-file first argument for fscanf",
"Non-string second (fmt) argument for fscanf",
"Non-lvalue argument after second for fscanf",
"File not open for reading or other error for fscanf",
"Non-string first argument for strscanf",
"Non-string second (fmt) argument for strscanf",
"Non-lvalue argument after second for strscanf",
"Some error in attempting strscanf ???",
"Non-string first (fmt) argument for scanf",
"Non-lvalue argument after first for scanf",
"Some error in attempting scanf ???",
"Non-file argument for ftell",
"File not open or other error for ftell",
"Non-file first argument for fseek",
"Non-integer or negative second argument for fseek",
"File not open or other error for fseek",
"Non-file argument for fsize",
"File not open or other error for fsize",
"Non-file argument for feof",
"File not open or other error for feof",
"Non-file argument for ferror",
"File not open or other error for ferror",
"Non-file argument for ungetc",
"File not open for reading for ungetc",
"Bad second argument or other error for ungetc",
"Exponent too big in scanning",
"E_ISATTY1 is no longer used",
"E_ISATTY2 is no longer used",
"Non-string first argument for access",
"Bad second argument for access",
"Bad first argument for search",
"Bad second argument for search",
"Bad third argument for search",
"Bad fourth argument for search",
"Cannot find fsize or fpos for search",
"File not readable for search",
"Bad first argument for rsearch",
"Bad second argument for rsearch",
"Bad third argument for rsearch",
"Bad fourth argument for rsearch",
"Cannot find fsize or fpos for rsearch",
"File not readable for rsearch",
"Too many open files",
"Attempt to rewind a file that is not open",
"Bad argument type for strerror",
"Index out of range for strerror",
"Bad epsilon for cos",
"Bad first argument for cos",
"Bad epsilon for sin",
"Bad first argument for sin",
"Non-string argument for eval",
"Bad epsilon for arg",
"Bad first argument for arg",
"Non-real argument for polar",
"Bad epsilon for polar",
"Non-integral argument for fcnt",
"Non-variable first argument for matfill",
"Non-matrix first argument-value for matfill",
"Non-matrix argument for matdim",
"Non-matrix argument for matsum",
"E_ISIDENT is no longer used",
"Non-matrix argument for mattrans",
"Non-two-dimensional matrix for mattrans",
"Non-matrix argument for det",
"Matrix for det not of dimension 2",
"Non-square matrix for det",
"Non-matrix first argument for matmin",
"Non-positive-integer second argument for matmin",
"Second argument for matmin exceeds dimension",
"Non-matrix first argument for matmin",
"Second argument for matmax not positive integer",
"Second argument for matmax exceeds dimension",
"Non-matrix argument for cp",
"Non-one-dimensional matrix for cp",
"Matrix size not 3 for cp",
"Non-matrix argument for dp",
"Non-one-dimensional matrix for dp",
"Different-size matrices for dp",
"Non-string argument for strlen",
"Non-string argument for strcat",
"Non-string first argument for strcat",
"Non-non-negative integer second argument for strcat",
"Bad argument for char",
"Non-string argument for ord",
"Non-list-variable first argument for insert",
"Non-integral second argument for insert",
"Non-list-variable first argument for push",
"Non-list-variable first argument for append",
"Non-list-variable first argument for delete",
"Non-integral second argument for delete",
"Non-list-variable argument for pop",
"Non-list-variable argument for remove",
"Bad epsilon argument for ln",
"Non-numeric first argument for ln",
"Non-integer argument for error",
"Argument outside range for error",
"Attempt to eval at maximum input depth",
"Unable to open string for reading",
"First argument for rm is not a non-empty string",
"Unable to remove a file",
"Operation allowed because calc mode disallows read operations",
"Operation allowed because calc mode disallows write operations",
"Operation allowed because calc mode disallows exec operations",
"Unordered arguments for min",
"Unordered arguments for max",
"Unordered items for minimum of list",
"Unordered items for maximum of list",
"Size undefined for argument type",
"Calc must be run with a -C argument to use custom function",
"Calc was built with custom functions disabled",
"Custom function unknown, try: show custom",
"Non-integral length for block",
"Negative or too-large length for block",
"Non-integral chunksize for block",
"Negative or too-large chunksize for block",
"Named block does not exist for blkfree",
"Non-integral id specification for blkfree",
"Block with specified id does not exist",
"Block already freed",
"No-realloc protection prevents blkfree",
"Non-integer argument for blocks",
"Non-allocated index number for blocks",
"Non-integer or negative source index for copy",
"Source index too large for copy",
"E_COPY3 is no longer used",
"Non-integer or negative number for copy",
"Number too large for copy",
"Non-integer or negative destination index for copy",
"Destination index too large for copy",
"Freed block source for copy",
"Unsuitable source type for copy",
"Freed block destinction for copy",
"Unsuitable destination type for copy",
"Incompatible source and destination for copy",
"No-copy-from source variable",
"No-copy-to destination variable",
"No-copy-from source named block",
"No-copy-to destination named block",
"No-relocation destination for copy",
"File not open for copy",
"fseek or fsize failure for copy",
"fwrite error for copy",
"fread error for copy",
"Non-variable first argument for protect",
"Non-integer second argument for protect",
"Out-of-range second argument for protect",
"No-copy-to destination for matfill",
"No-assign-from source for matfill",
"Non-matrix argument for mattrace",
"Non-two-dimensional argument for mattrace",
"Non-square argument for mattrace",
"Bad epsilon for tan",
"Bad argument for tan",
"Bad epsilon for cot",
"Bad argument for cot",
"Bad epsilon for sec",
"Bad argument for sec",
"Bad epsilon for csc",
"Bad argument for csc",
"Bad epsilon for sinh",
"Bad argument for sinh",
"Bad epsilon for cosh",
"Bad argument for cosh",
"Bad epsilon for tanh",
"Bad argument for tanh",
"Bad epsilon for coth",
"Bad argument for coth",
"Bad epsilon for sech",
"Bad argument for sech",
"Bad epsilon for csch",
"Bad argument for csch",
"Bad epsilon for asin",
"Bad argument for asin",
"Bad epsilon for acos",
"Bad argument for acos",
"Bad epsilon for atan",
"Bad argument for atan",
"Bad epsilon for acot",
"Bad argument for acot",
"Bad epsilon for asec",
"Bad argument for asec",
"Bad epsilon for acsc",
"Bad argument for acsc",
"Bad epsilon for asin",
"Bad argument for asinh",
"Bad epsilon for acosh",
"Bad argument for acosh",
"Bad epsilon for atanh",
"Bad argument for atanh",
"Bad epsilon for acoth",
"Bad argument for acoth",
"Bad epsilon for asech",
"Bad argument for asech",
"Bad epsilon for acsch",
"Bad argument for acsch",
"Bad epsilon for gd",
"Bad argument for gd",
"Bad epsilon for agd",
"Bad argument for agd",
"Log of zero or infinity",
"String addition failure",
"String multiplication failure",
"String reversal failure",
"String subtraction failure",
"Bad argument type for bit",
"Index too large for bit",
"Non-integer second argument for setbit",
"Out-of-range index for setbit",
"Non-string first argument for setbit",
"Bad argument for or",
"Bad argument for and",
"Allocation failure for string or",
"Allocation failure for string and",
"Bad argument for xorvalue",
"Bad argument for comp",
"Allocation failure for string diff",
"Allocation failure for string comp",
"Bad first argument for segment",
"Bad second argument for segment",
"Bad third argument for segment",
"Failure for string segment",
"Bad argument type for highbit",
"Non-integer argument for highbit",
"Bad argument type for lowbit",
"Non-integer argument for lowbit",
"Bad argument type for unary hash op",
"Bad argument type for binary hash op",
"Bad first argument for head",
"Bad second argument for head",
"Failure for strhead",
"Bad first argument for tail",
"Bad second argument for tail",
"Failure for strtail",
"Failure for strshift",
"Non-string argument for strcmp",
"Bad argument type for strncmp",
"Varying types of argument for xor",
"Bad argument type for xor",
"Bad argument type for strcpy",
"Bad argument type for strncpy",
"Bad argument type for unary backslash",
"Bad argument type for setminus",
"Bad first argument type for indices",
"Bad second argument for indices",
"Too-large re(argument) for exp",
"Too-large re(argument) for sinh",
"Too-large re(argument) for cosh",
"Too-large im(argument) for sin",
"Too-large im(argument) for cos",
"Infinite or too-large result for gd",
"Infinite or too-large result for agd",
"Too-large value for power",
"Too-large value for root",
"Non-real first arg for digit",
"Non-integral second arg for digit",
"Bad third arg for digit",
"Bad first argument for places",
"Bad second argument for places",
"Bad first argument for digits",
"Bad second argument for digits",
"Bad first argument for ilog",
"Bad second argument for ilog",
"Bad argument for ilog10",
"Bad argument for ilog2",
"Non-integer second arg for comb",
"Too-large second arg for comb",
"Bad argument for catalan",
"Bad argument for bern",
"Bad argument for euler",
"Bad argument for sleep",
"calc_tty failure",
NULL
};

383
win32/calcerr.h Normal file
View File

@@ -0,0 +1,383 @@
/*
* DO NOT EDIT
*
* generated by calcerr.tbl via Makefile
*/
#if !defined(__CALCERR_H__)
#define __CALCERR_H__
#define E__BASE 10000 /* calc errors start above here */
#define E_1OVER0 10001 /* Division by zero */
#define E_0OVER0 10002 /* Indeterminate (0/0) */
#define E_ADD 10003 /* Bad arguments for + */
#define E_SUB 10004 /* Bad arguments for binary - */
#define E_MUL 10005 /* Bad arguments for * */
#define E_DIV 10006 /* Bad arguments for / */
#define E_NEG 10007 /* Bad argument for unary - */
#define E_SQUARE 10008 /* Bad argument for squaring */
#define E_INV 10009 /* Bad argument for inverse */
#define E_INCV 10010 /* Bad argument for ++ */
#define E_DECV 10011 /* Bad argument for -- */
#define E_INT 10012 /* Bad argument for int */
#define E_FRAC 10013 /* Bad argument for frac */
#define E_CONJ 10014 /* Bad argument for conj */
#define E_APPR 10015 /* Bad first argument for appr */
#define E_APPR2 10016 /* Bad second argument for appr */
#define E_APPR3 10017 /* Bad third argument for appr */
#define E_ROUND 10018 /* Bad first argument for round */
#define E_ROUND2 10019 /* Bad second argument for round */
#define E_ROUND3 10020 /* Bad third argument for round */
#define E_BROUND 10021 /* Bad first argument for bround */
#define E_BROUND2 10022 /* Bad second argument for bround */
#define E_BROUND3 10023 /* Bad third argument for bround */
#define E_SQRT 10024 /* Bad first argument for sqrt */
#define E_SQRT2 10025 /* Bad second argument for sqrt */
#define E_SQRT3 10026 /* Bad third argument for sqrt */
#define E_ROOT 10027 /* Bad first argument for root */
#define E_ROOT2 10028 /* Bad second argument for root */
#define E_ROOT3 10029 /* Bad third argument for root */
#define E_NORM 10030 /* Bad argument for norm */
#define E_SHIFT 10031 /* Bad first argument for << or >> */
#define E_SHIFT2 10032 /* Bad second argument for << or >> */
#define E_SCALE 10033 /* Bad first argument for scale */
#define E_SCALE2 10034 /* Bad second argument for scale */
#define E_POWI 10035 /* Bad first argument for ^ */
#define E_POWI2 10036 /* Bad second argument for ^ */
#define E_POWER 10037 /* Bad first argument for power */
#define E_POWER2 10038 /* Bad second argument for power */
#define E_POWER3 10039 /* Bad third argument for power */
#define E_QUO 10040 /* Bad first argument for quo or // */
#define E_QUO2 10041 /* Bad second argument for quo or // */
#define E_QUO3 10042 /* Bad third argument for quo */
#define E_MOD 10043 /* Bad first argument for mod or % */
#define E_MOD2 10044 /* Bad second argument for mod or % */
#define E_MOD3 10045 /* Bad third argument for mod */
#define E_SGN 10046 /* Bad argument for sgn */
#define E_ABS 10047 /* Bad first argument for abs */
#define E_ABS2 10048 /* Bad second argument for abs */
#define E_EVAL 10049 /* Scan error in argument for eval */
#define E_STR 10050 /* Non-simple type for str */
#define E_EXP1 10051 /* Non-real epsilon for exp */
#define E_EXP2 10052 /* Bad first argument for exp */
#define E_FPUTC1 10053 /* Non-file first argument for fputc */
#define E_FPUTC2 10054 /* Bad second argument for fputc */
#define E_FPUTC3 10055 /* File not open for writing for fputc */
#define E_FGETC1 10056 /* Non-file first argument for fgetc */
#define E_FGETC2 10057 /* File not open for reading for fgetc */
#define E_FOPEN1 10058 /* Non-string arguments for fopen */
#define E_FOPEN2 10059 /* Unrecognized mode for fopen */
#define E_FREOPEN1 10060 /* Non-file first argument for freopen */
#define E_FREOPEN2 10061 /* Non-string or unrecognized mode for freopen */
#define E_FREOPEN3 10062 /* Non-string third argument for freopen */
#define E_FCLOSE1 10063 /* Non-file argument for fclose */
#define E_FFLUSH 10064 /* Non-file argument for fflush */
#define E_FPUTS1 10065 /* Non-file first argument for fputs */
#define E_FPUTS2 10066 /* Non-string argument after first for fputs */
#define E_FPUTS3 10067 /* File not open for writing for fputs */
#define E_FGETS1 10068 /* Non-file argument for fgets */
#define E_FGETS2 10069 /* File not open for reading for fgets */
#define E_FPUTSTR1 10070 /* Non-file first argument for fputstr */
#define E_FPUTSTR2 10071 /* Non-string argument after first for fputstr */
#define E_FPUTSTR3 10072 /* File not open for writing for fputstr */
#define E_FGETSTR1 10073 /* Non-file first argument for fgetstr */
#define E_FGETSTR2 10074 /* File not open for reading for fgetstr */
#define E_FGETLINE1 10075 /* Non-file argument for fgetline */
#define E_FGETLINE2 10076 /* File not open for reading for fgetline */
#define E_FGETFIELD1 10077 /* Non-file argument for fgetfield */
#define E_FGETFIELD2 10078 /* File not open for reading for fgetfield */
#define E_REWIND1 10079 /* Non-file argument for rewind */
#define E_FILES 10080 /* Non-integer argument for files */
#define E_PRINTF1 10081 /* Non-string fmt argument for fprint */
#define E_PRINTF2 10082 /* Stdout not open for writing to ??? */
#define E_FPRINTF1 10083 /* Non-file first argument for fprintf */
#define E_FPRINTF2 10084 /* Non-string second (fmt) argument for fprintf */
#define E_FPRINTF3 10085 /* File not open for writing for fprintf */
#define E_STRPRINTF1 10086 /* Non-string first (fmt) argument for strprintf */
#define E_STRPRINTF2 10087 /* Error in attempting strprintf ??? */
#define E_FSCAN1 10088 /* Non-file first argument for fscan */
#define E_FSCAN2 10089 /* File not open for reading for fscan */
#define E_STRSCAN 10090 /* Non-string first argument for strscan */
#define E_FSCANF1 10091 /* Non-file first argument for fscanf */
#define E_FSCANF2 10092 /* Non-string second (fmt) argument for fscanf */
#define E_FSCANF3 10093 /* Non-lvalue argument after second for fscanf */
#define E_FSCANF4 10094 /* File not open for reading or other error for fscanf */
#define E_STRSCANF1 10095 /* Non-string first argument for strscanf */
#define E_STRSCANF2 10096 /* Non-string second (fmt) argument for strscanf */
#define E_STRSCANF3 10097 /* Non-lvalue argument after second for strscanf */
#define E_STRSCANF4 10098 /* Some error in attempting strscanf ??? */
#define E_SCANF1 10099 /* Non-string first (fmt) argument for scanf */
#define E_SCANF2 10100 /* Non-lvalue argument after first for scanf */
#define E_SCANF3 10101 /* Some error in attempting scanf ??? */
#define E_FTELL1 10102 /* Non-file argument for ftell */
#define E_FTELL2 10103 /* File not open or other error for ftell */
#define E_FSEEK1 10104 /* Non-file first argument for fseek */
#define E_FSEEK2 10105 /* Non-integer or negative second argument for fseek */
#define E_FSEEK3 10106 /* File not open or other error for fseek */
#define E_FSIZE1 10107 /* Non-file argument for fsize */
#define E_FSIZE2 10108 /* File not open or other error for fsize */
#define E_FEOF1 10109 /* Non-file argument for feof */
#define E_FEOF2 10110 /* File not open or other error for feof */
#define E_FERROR1 10111 /* Non-file argument for ferror */
#define E_FERROR2 10112 /* File not open or other error for ferror */
#define E_UNGETC1 10113 /* Non-file argument for ungetc */
#define E_UNGETC2 10114 /* File not open for reading for ungetc */
#define E_UNGETC3 10115 /* Bad second argument or other error for ungetc */
#define E_BIGEXP 10116 /* Exponent too big in scanning */
#define E_ISATTY1 10117 /* E_ISATTY1 is no longer used */
#define E_ISATTY2 10118 /* E_ISATTY2 is no longer used */
#define E_ACCESS1 10119 /* Non-string first argument for access */
#define E_ACCESS2 10120 /* Bad second argument for access */
#define E_SEARCH1 10121 /* Bad first argument for search */
#define E_SEARCH2 10122 /* Bad second argument for search */
#define E_SEARCH3 10123 /* Bad third argument for search */
#define E_SEARCH4 10124 /* Bad fourth argument for search */
#define E_SEARCH5 10125 /* Cannot find fsize or fpos for search */
#define E_SEARCH6 10126 /* File not readable for search */
#define E_RSEARCH1 10127 /* Bad first argument for rsearch */
#define E_RSEARCH2 10128 /* Bad second argument for rsearch */
#define E_RSEARCH3 10129 /* Bad third argument for rsearch */
#define E_RSEARCH4 10130 /* Bad fourth argument for rsearch */
#define E_RSEARCH5 10131 /* Cannot find fsize or fpos for rsearch */
#define E_RSEARCH6 10132 /* File not readable for rsearch */
#define E_FOPEN3 10133 /* Too many open files */
#define E_REWIND2 10134 /* Attempt to rewind a file that is not open */
#define E_STRERROR1 10135 /* Bad argument type for strerror */
#define E_STRERROR2 10136 /* Index out of range for strerror */
#define E_COS1 10137 /* Bad epsilon for cos */
#define E_COS2 10138 /* Bad first argument for cos */
#define E_SIN1 10139 /* Bad epsilon for sin */
#define E_SIN2 10140 /* Bad first argument for sin */
#define E_EVAL2 10141 /* Non-string argument for eval */
#define E_ARG1 10142 /* Bad epsilon for arg */
#define E_ARG2 10143 /* Bad first argument for arg */
#define E_POLAR1 10144 /* Non-real argument for polar */
#define E_POLAR2 10145 /* Bad epsilon for polar */
#define E_FCNT 10146 /* Non-integral argument for fcnt */
#define E_MATFILL1 10147 /* Non-variable first argument for matfill */
#define E_MATFILL2 10148 /* Non-matrix first argument-value for matfill */
#define E_MATDIM 10149 /* Non-matrix argument for matdim */
#define E_MATSUM 10150 /* Non-matrix argument for matsum */
#define E_ISIDENT 10151 /* E_ISIDENT is no longer used */
#define E_MATTRANS1 10152 /* Non-matrix argument for mattrans */
#define E_MATTRANS2 10153 /* Non-two-dimensional matrix for mattrans */
#define E_DET1 10154 /* Non-matrix argument for det */
#define E_DET2 10155 /* Matrix for det not of dimension 2 */
#define E_DET3 10156 /* Non-square matrix for det */
#define E_MATMIN1 10157 /* Non-matrix first argument for matmin */
#define E_MATMIN2 10158 /* Non-positive-integer second argument for matmin */
#define E_MATMIN3 10159 /* Second argument for matmin exceeds dimension */
#define E_MATMAX1 10160 /* Non-matrix first argument for matmin */
#define E_MATMAX2 10161 /* Second argument for matmax not positive integer */
#define E_MATMAX3 10162 /* Second argument for matmax exceeds dimension */
#define E_CP1 10163 /* Non-matrix argument for cp */
#define E_CP2 10164 /* Non-one-dimensional matrix for cp */
#define E_CP3 10165 /* Matrix size not 3 for cp */
#define E_DP1 10166 /* Non-matrix argument for dp */
#define E_DP2 10167 /* Non-one-dimensional matrix for dp */
#define E_DP3 10168 /* Different-size matrices for dp */
#define E_STRLEN 10169 /* Non-string argument for strlen */
#define E_STRCAT 10170 /* Non-string argument for strcat */
#define E_SUBSTR1 10171 /* Non-string first argument for strcat */
#define E_SUBSTR2 10172 /* Non-non-negative integer second argument for strcat */
#define E_CHAR 10173 /* Bad argument for char */
#define E_ORD 10174 /* Non-string argument for ord */
#define E_INSERT1 10175 /* Non-list-variable first argument for insert */
#define E_INSERT2 10176 /* Non-integral second argument for insert */
#define E_PUSH 10177 /* Non-list-variable first argument for push */
#define E_APPEND 10178 /* Non-list-variable first argument for append */
#define E_DELETE1 10179 /* Non-list-variable first argument for delete */
#define E_DELETE2 10180 /* Non-integral second argument for delete */
#define E_POP 10181 /* Non-list-variable argument for pop */
#define E_REMOVE 10182 /* Non-list-variable argument for remove */
#define E_LN1 10183 /* Bad epsilon argument for ln */
#define E_LN2 10184 /* Non-numeric first argument for ln */
#define E_ERROR1 10185 /* Non-integer argument for error */
#define E_ERROR2 10186 /* Argument outside range for error */
#define E_EVAL3 10187 /* Attempt to eval at maximum input depth */
#define E_EVAL4 10188 /* Unable to open string for reading */
#define E_RM1 10189 /* First argument for rm is not a non-empty string */
#define E_RM2 10190 /* Unable to remove a file */
#define E_RDPERM 10191 /* Operation allowed because calc mode disallows read operations */
#define E_WRPERM 10192 /* Operation allowed because calc mode disallows write operations */
#define E_EXPERM 10193 /* Operation allowed because calc mode disallows exec operations */
#define E_MIN 10194 /* Unordered arguments for min */
#define E_MAX 10195 /* Unordered arguments for max */
#define E_LISTMIN 10196 /* Unordered items for minimum of list */
#define E_LISTMAX 10197 /* Unordered items for maximum of list */
#define E_SIZE 10198 /* Size undefined for argument type */
#define E_NO_C_ARG 10199 /* Calc must be run with a -C argument to use custom function */
#define E_NO_CUSTOM 10200 /* Calc was built with custom functions disabled */
#define E_UNK_CUSTOM 10201 /* Custom function unknown, try: show custom */
#define E_BLK1 10202 /* Non-integral length for block */
#define E_BLK2 10203 /* Negative or too-large length for block */
#define E_BLK3 10204 /* Non-integral chunksize for block */
#define E_BLK4 10205 /* Negative or too-large chunksize for block */
#define E_BLKFREE1 10206 /* Named block does not exist for blkfree */
#define E_BLKFREE2 10207 /* Non-integral id specification for blkfree */
#define E_BLKFREE3 10208 /* Block with specified id does not exist */
#define E_BLKFREE4 10209 /* Block already freed */
#define E_BLKFREE5 10210 /* No-realloc protection prevents blkfree */
#define E_BLOCKS1 10211 /* Non-integer argument for blocks */
#define E_BLOCKS2 10212 /* Non-allocated index number for blocks */
#define E_COPY1 10213 /* Non-integer or negative source index for copy */
#define E_COPY2 10214 /* Source index too large for copy */
#define E_COPY3 10215 /* E_COPY3 is no longer used */
#define E_COPY4 10216 /* Non-integer or negative number for copy */
#define E_COPY5 10217 /* Number too large for copy */
#define E_COPY6 10218 /* Non-integer or negative destination index for copy */
#define E_COPY7 10219 /* Destination index too large for copy */
#define E_COPY8 10220 /* Freed block source for copy */
#define E_COPY9 10221 /* Unsuitable source type for copy */
#define E_COPY10 10222 /* Freed block destinction for copy */
#define E_COPY11 10223 /* Unsuitable destination type for copy */
#define E_COPY12 10224 /* Incompatible source and destination for copy */
#define E_COPY13 10225 /* No-copy-from source variable */
#define E_COPY14 10226 /* No-copy-to destination variable */
#define E_COPY15 10227 /* No-copy-from source named block */
#define E_COPY16 10228 /* No-copy-to destination named block */
#define E_COPY17 10229 /* No-relocation destination for copy */
#define E_COPYF1 10230 /* File not open for copy */
#define E_COPYF2 10231 /* fseek or fsize failure for copy */
#define E_COPYF3 10232 /* fwrite error for copy */
#define E_COPYF4 10233 /* fread error for copy */
#define E_PROTECT1 10234 /* Non-variable first argument for protect */
#define E_PROTECT2 10235 /* Non-integer second argument for protect */
#define E_PROTECT3 10236 /* Out-of-range second argument for protect */
#define E_MATFILL3 10237 /* No-copy-to destination for matfill */
#define E_MATFILL4 10238 /* No-assign-from source for matfill */
#define E_MATTRACE1 10239 /* Non-matrix argument for mattrace */
#define E_MATTRACE2 10240 /* Non-two-dimensional argument for mattrace */
#define E_MATTRACE3 10241 /* Non-square argument for mattrace */
#define E_TAN1 10242 /* Bad epsilon for tan */
#define E_TAN2 10243 /* Bad argument for tan */
#define E_COT1 10244 /* Bad epsilon for cot */
#define E_COT2 10245 /* Bad argument for cot */
#define E_SEC1 10246 /* Bad epsilon for sec */
#define E_SEC2 10247 /* Bad argument for sec */
#define E_CSC1 10248 /* Bad epsilon for csc */
#define E_CSC2 10249 /* Bad argument for csc */
#define E_SINH1 10250 /* Bad epsilon for sinh */
#define E_SINH2 10251 /* Bad argument for sinh */
#define E_COSH1 10252 /* Bad epsilon for cosh */
#define E_COSH2 10253 /* Bad argument for cosh */
#define E_TANH1 10254 /* Bad epsilon for tanh */
#define E_TANH2 10255 /* Bad argument for tanh */
#define E_COTH1 10256 /* Bad epsilon for coth */
#define E_COTH2 10257 /* Bad argument for coth */
#define E_SECH1 10258 /* Bad epsilon for sech */
#define E_SECH2 10259 /* Bad argument for sech */
#define E_CSCH1 10260 /* Bad epsilon for csch */
#define E_CSCH2 10261 /* Bad argument for csch */
#define E_ASIN1 10262 /* Bad epsilon for asin */
#define E_ASIN2 10263 /* Bad argument for asin */
#define E_ACOS1 10264 /* Bad epsilon for acos */
#define E_ACOS2 10265 /* Bad argument for acos */
#define E_ATAN1 10266 /* Bad epsilon for atan */
#define E_ATAN2 10267 /* Bad argument for atan */
#define E_ACOT1 10268 /* Bad epsilon for acot */
#define E_ACOT2 10269 /* Bad argument for acot */
#define E_ASEC1 10270 /* Bad epsilon for asec */
#define E_ASEC2 10271 /* Bad argument for asec */
#define E_ACSC1 10272 /* Bad epsilon for acsc */
#define E_ACSC2 10273 /* Bad argument for acsc */
#define E_ASINH1 10274 /* Bad epsilon for asin */
#define E_ASINH2 10275 /* Bad argument for asinh */
#define E_ACOSH1 10276 /* Bad epsilon for acosh */
#define E_ACOSH2 10277 /* Bad argument for acosh */
#define E_ATANH1 10278 /* Bad epsilon for atanh */
#define E_ATANH2 10279 /* Bad argument for atanh */
#define E_ACOTH1 10280 /* Bad epsilon for acoth */
#define E_ACOTH2 10281 /* Bad argument for acoth */
#define E_ASECH1 10282 /* Bad epsilon for asech */
#define E_ASECH2 10283 /* Bad argument for asech */
#define E_ACSCH1 10284 /* Bad epsilon for acsch */
#define E_ACSCH2 10285 /* Bad argument for acsch */
#define E_GD1 10286 /* Bad epsilon for gd */
#define E_GD2 10287 /* Bad argument for gd */
#define E_AGD1 10288 /* Bad epsilon for agd */
#define E_AGD2 10289 /* Bad argument for agd */
#define E_LOGINF 10290 /* Log of zero or infinity */
#define E_STRADD 10291 /* String addition failure */
#define E_STRMUL 10292 /* String multiplication failure */
#define E_STRNEG 10293 /* String reversal failure */
#define E_STRSUB 10294 /* String subtraction failure */
#define E_BIT1 10295 /* Bad argument type for bit */
#define E_BIT2 10296 /* Index too large for bit */
#define E_SETBIT1 10297 /* Non-integer second argument for setbit */
#define E_SETBIT2 10298 /* Out-of-range index for setbit */
#define E_SETBIT3 10299 /* Non-string first argument for setbit */
#define E_OR 10300 /* Bad argument for or */
#define E_AND 10301 /* Bad argument for and */
#define E_STROR 10302 /* Allocation failure for string or */
#define E_STRAND 10303 /* Allocation failure for string and */
#define E_XOR 10304 /* Bad argument for xorvalue */
#define E_COMP 10305 /* Bad argument for comp */
#define E_STRDIFF 10306 /* Allocation failure for string diff */
#define E_STRCOMP 10307 /* Allocation failure for string comp */
#define E_SEG1 10308 /* Bad first argument for segment */
#define E_SEG2 10309 /* Bad second argument for segment */
#define E_SEG3 10310 /* Bad third argument for segment */
#define E_STRSEG 10311 /* Failure for string segment */
#define E_HIGHBIT1 10312 /* Bad argument type for highbit */
#define E_HIGHBIT2 10313 /* Non-integer argument for highbit */
#define E_LOWBIT1 10314 /* Bad argument type for lowbit */
#define E_LOWBIT2 10315 /* Non-integer argument for lowbit */
#define E_CONTENT 10316 /* Bad argument type for unary hash op */
#define E_HASHOP 10317 /* Bad argument type for binary hash op */
#define E_HEAD1 10318 /* Bad first argument for head */
#define E_HEAD2 10319 /* Bad second argument for head */
#define E_STRHEAD 10320 /* Failure for strhead */
#define E_TAIL1 10321 /* Bad first argument for tail */
#define E_TAIL2 10322 /* Bad second argument for tail */
#define E_STRTAIL 10323 /* Failure for strtail */
#define E_STRSHIFT 10324 /* Failure for strshift */
#define E_STRCMP 10325 /* Non-string argument for strcmp */
#define E_STRNCMP 10326 /* Bad argument type for strncmp */
#define E_XOR1 10327 /* Varying types of argument for xor */
#define E_XOR2 10328 /* Bad argument type for xor */
#define E_STRCPY 10329 /* Bad argument type for strcpy */
#define E_STRNCPY 10330 /* Bad argument type for strncpy */
#define E_BACKSLASH 10331 /* Bad argument type for unary backslash */
#define E_SETMINUS 10332 /* Bad argument type for setminus */
#define E_INDICES1 10333 /* Bad first argument type for indices */
#define E_INDICES2 10334 /* Bad second argument for indices */
#define E_EXP3 10335 /* Too-large re(argument) for exp */
#define E_SINH3 10336 /* Too-large re(argument) for sinh */
#define E_COSH3 10337 /* Too-large re(argument) for cosh */
#define E_SIN3 10338 /* Too-large im(argument) for sin */
#define E_COS3 10339 /* Too-large im(argument) for cos */
#define E_GD3 10340 /* Infinite or too-large result for gd */
#define E_AGD3 10341 /* Infinite or too-large result for agd */
#define E_POWER4 10342 /* Too-large value for power */
#define E_ROOT4 10343 /* Too-large value for root */
#define E_DGT1 10344 /* Non-real first arg for digit */
#define E_DGT2 10345 /* Non-integral second arg for digit */
#define E_DGT3 10346 /* Bad third arg for digit */
#define E_PLCS1 10347 /* Bad first argument for places */
#define E_PLCS2 10348 /* Bad second argument for places */
#define E_DGTS1 10349 /* Bad first argument for digits */
#define E_DGTS2 10350 /* Bad second argument for digits */
#define E_ILOG 10351 /* Bad first argument for ilog */
#define E_ILOGB 10352 /* Bad second argument for ilog */
#define E_ILOG10 10353 /* Bad argument for ilog10 */
#define E_ILOG2 10354 /* Bad argument for ilog2 */
#define E_COMB1 10355 /* Non-integer second arg for comb */
#define E_COMB2 10356 /* Too-large second arg for comb */
#define E_CTLN 10357 /* Bad argument for catalan */
#define E_BERN 10358 /* Bad argument for bern */
#define E_EULER 10359 /* Bad argument for euler */
#define E_SLEEP 10360 /* Bad argument for sleep */
#define E_TTY 10361 /* calc_tty failure */
#define E__HIGHEST 10361 /* highest calc error */
#define E__COUNT 361 /* number of calc errors */
#define E_USERDEF 20000 /* base of user defined errors */
/* names of calc error values */
#endif /* !__CALCERR_H__ */

41
win32/conf.h Normal file
View File

@@ -0,0 +1,41 @@
/*
* DO NOT EDIT -- generated by the Makefile
*/
#if !defined(__CONF_H__)
#define __CONF_H__
/* the default :-separated search path */
#if !defined(DEFAULTCALCPATH)
#define DEFAULTCALCPATH "./cal"
#endif /* DEFAULTCALCPATH */
/* the default :-separated startup file list */
#if !defined(DEFAULTCALCRC)
#define DEFAULTCALCRC "/lib/calc/startup:~/.calcrc:./.calcinit"
#endif /* DEFAULTCALCRC */
/* the location of the help directory */
#if !defined(HELPDIR)
#define HELPDIR "/lib/calc/help"
#endif /* HELPDIR */
/* the location of the custom help directory */
#if !defined(CUSTOMHELPDIR)
#define CUSTOMHELPDIR "/lib/calc/help/custhelp"
#endif /* CUSTOMHELPDIR */
/* the default pager to use */
#if !defined(DEFAULTCALCPAGER)
#define DEFAULTCALCPAGER ""
#endif /* DEFAULTCALCPAGER */
/* where the echo command is located */
#if !defined(ECHO_PROG)
#define ECHO_PROG ""
#endif /* ECHO_PROG */
#endif /* !__CONF_H__ */

16
win32/endian_calc.h Normal file
View File

@@ -0,0 +1,16 @@
/*
* DO NOT EDIT -- generated by the Makefile
*/
#if !defined(__ENDIAN_CALC_H__)
#define __ENDIAN_CALC_H__
/* what byte order are we? */
#define BIG_ENDIAN 4321
#define LITTLE_ENDIAN 1234
#define CALC_BYTE_ORDER LITTLE_ENDIAN
#endif /* !__ENDIAN_CALC_H__ */

28
win32/fposval.h Normal file
View File

@@ -0,0 +1,28 @@
/*
* DO NOT EDIT -- generated by the Makefile
*/
#if !defined(__FPOSVAL_H__)
#define __FPOSVAL_H__
/* what are our file position & size types? */
#undef FILEPOS_BITS
#define FILEPOS_BITS 64
#define SWAP_HALF_IN_FILEPOS(dest, src) (*(dest) = *(src))
#undef OFF_T_BITS
#define OFF_T_BITS 32
#define SWAP_HALF_IN_OFF_T(dest, src) (*(dest) = *(src))
#undef DEV_BITS
#define DEV_BITS 32
#define SWAP_HALF_IN_DEV(dest, src) memcpy((void *)(dest), (void *)(src), 4)
#undef INODE_BITS
#define INODE_BITS 16
#define SWAP_HALF_IN_INODE(dest, src) memcpy((void *)(dest), (void *)(src), 2)
#endif /* !__FPOSVAL_H__ */

16
win32/have_const.h Normal file
View File

@@ -0,0 +1,16 @@
/*
* DO NOT EDIT -- generated by the Makefile
*/
#if !defined(__HAVE_CONST_H__)
#define __HAVE_CONST_H__
/* do we have or want const? */
#define HAVE_CONST /* yes */
#undef CONST
#define CONST const /* yes */
#endif /* !__HAVE_CONST_H__ */

16
win32/have_fpos.h Normal file
View File

@@ -0,0 +1,16 @@
/*
* DO NOT EDIT -- generated by the Makefile
*/
#if !defined(__HAVE_FPOS_H__)
#define __HAVE_FPOS_H__
/* do we have fgetpos & fsetpos functions? */
#undef HAVE_FPOS /* no */
typedef long FILEPOS;
#endif /* !__HAVE_FPOS_H__ */

15
win32/have_fpos_pos.h Normal file
View File

@@ -0,0 +1,15 @@
/*
* DO NOT EDIT -- generated by the Makefile
*/
#if !defined(__HAVE_FPOS_POS_H__)
#define __HAVE_FPOS_POS_H__
/* do we have fgetpos & fsetpos functions? */
#undef HAVE_FPOS_POS /* no */
#undef FPOS_POS_BITS
#endif /* !__HAVE_FPOS_POS_H__ */

14
win32/have_getpgid.h Normal file
View File

@@ -0,0 +1,14 @@
/*
* DO NOT EDIT -- generated by the Makefile
*/
#if !defined(__HAVE_GETPGID_H__)
#define __HAVE_GETPGID_H__
/* do we have or want getpgid()? */
#undef HAVE_GETPGID /* no */
#endif /* !__HAVE_GETPGID_H__ */

14
win32/have_getprid.h Normal file
View File

@@ -0,0 +1,14 @@
/*
* DO NOT EDIT -- generated by the Makefile
*/
#if !defined(__HAVE_GETPRID_H__)
#define __HAVE_GETPRID_H__
/* do we have or want getprid()? */
#undef HAVE_GETPRID /* no */
#endif /* !__HAVE_GETPRID_H__ */

14
win32/have_getsid.h Normal file
View File

@@ -0,0 +1,14 @@
/*
* DO NOT EDIT -- generated by the Makefile
*/
#if !defined(__HAVE_GETSID_H__)
#define __HAVE_GETSID_H__
/* do we have or want getsid()? */
#undef HAVE_GETSID /* no */
#endif /* !__HAVE_GETSID_H__ */

14
win32/have_gettime.h Normal file
View File

@@ -0,0 +1,14 @@
/*
* DO NOT EDIT -- generated by the Makefile
*/
#if !defined(__HAVE_GETTIME_H__)
#define __HAVE_GETTIME_H__
/* do we have or want clock_gettime()? */
#undef HAVE_GETTIME /* no */
#endif /* !__HAVE_GETTIME_H__ */

14
win32/have_malloc.h Normal file
View File

@@ -0,0 +1,14 @@
/*
* DO NOT EDIT -- generated by the Makefile
*/
#if !defined(__HAVE_MALLOC_H__)
#define __HAVE_MALLOC_H__
/* do we have /usr/include/malloc.h? */
#define HAVE_MALLOC_H /* yes */
#endif /* !__HAVE_MALLOC_H__ */

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