mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Release calc version 2.11.5t1.1
This commit is contained in:
@@ -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/12/15 14:42:52 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 test8600.cal
|
||||
test8500.cal test8600.cal chi.cal intfile.cal
|
||||
|
||||
# These files are found (but not built) in the distribution
|
||||
#
|
||||
|
65
cal/README
65
cal/README
@@ -64,7 +64,7 @@ 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
|
||||
@@ -128,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, ...])
|
||||
@@ -163,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)
|
||||
@@ -756,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.4 $
|
||||
## @(#) $Id: README,v 29.4 2000/12/17 12:26:04 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
|
||||
|
251
cal/chi.cal
Normal file
251
cal/chi.cal
Normal 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
222
cal/intfile.cal
Normal 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.4 $
|
||||
* @(#) $Id: intfile.cal,v 29.4 2001/04/08 08:13:10 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, "r");
|
||||
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, "r");
|
||||
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, "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.
|
||||
*/
|
||||
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, "w");
|
||||
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;
|
||||
}
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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.6 $
|
||||
* @(#) $Id: regress.cal,v 29.6 2000/12/17 12:26:42 chongo Exp $
|
||||
* @(#) $Revision: 29.7 $
|
||||
* @(#) $Id: regress.cal,v 29.7 2001/04/08 10:09:39 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"');
|
||||
|
||||
@@ -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';
|
||||
@@ -5112,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:", "r");
|
||||
print '5902: ofd = fopen("NUL:", "r")';
|
||||
cfd = fopen("NUL:", "r");
|
||||
print '5903: cfd = fopen("NUL:", "r")';
|
||||
} else {
|
||||
ofd = fopen("/dev/null", "r");
|
||||
print '5902: ofd = fopen("/dev/null", "r")';
|
||||
cfd = fopen("/dev/null", "r");
|
||||
print '5903: cfd = fopen("/dev/null", "r")';
|
||||
}
|
||||
fclose(cfd);
|
||||
print '5904: fclose(cfd)';
|
||||
blk = blk();
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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.3 $
|
||||
* @(#) $Id: test4600.cal,v 29.3 2001/04/08 10:09:39 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/test4600.cal,v $
|
||||
*
|
||||
* Under source code control: 1996/07/02 20:04:40
|
||||
@@ -87,35 +87,68 @@ define stest(str, verbose)
|
||||
print '**** ftell(f) != 13 failed';
|
||||
return 1;
|
||||
}
|
||||
if (search(f, "and") != 109) {
|
||||
print 'failed';
|
||||
print '**** search(f, "and") != 109 failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 112) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 112 failed';
|
||||
return 1;
|
||||
}
|
||||
if (!isnull(search(f, "and"))) {
|
||||
print 'failed';
|
||||
print '**** !isnull(search(f, "and")) failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 172) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 172 failed';
|
||||
return 1;
|
||||
}
|
||||
if (rsearch(f, "and") != 109) {
|
||||
print 'failed';
|
||||
print '**** rsearch(f, "and") != 109 failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 111) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 111 failed';
|
||||
return 1;
|
||||
if (config("windows")) {
|
||||
if (search(f, "and") != 110) {
|
||||
print 'failed';
|
||||
print '**** search(f, "and") != 110 failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 113) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 113 failed';
|
||||
return 1;
|
||||
}
|
||||
if (!isnull(search(f, "and"))) {
|
||||
print 'failed';
|
||||
print '**** !isnull(search(f, "and")) failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 174) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 174 failed';
|
||||
return 1;
|
||||
}
|
||||
if (rsearch(f, "and") != 110) {
|
||||
print 'failed';
|
||||
print '**** rsearch(f, "and") != 110 failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 112) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 112 failed';
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (search(f, "and") != 109) {
|
||||
print 'failed';
|
||||
print '**** search(f, "and") != 109 failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 112) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 112 failed';
|
||||
return 1;
|
||||
}
|
||||
if (!isnull(search(f, "and"))) {
|
||||
print 'failed';
|
||||
print '**** !isnull(search(f, "and")) failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 172) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 172 failed';
|
||||
return 1;
|
||||
}
|
||||
if (rsearch(f, "and") != 109) {
|
||||
print 'failed';
|
||||
print '**** rsearch(f, "and") != 109 failed';
|
||||
return 1;
|
||||
}
|
||||
if (ftell(f) != 111) {
|
||||
print 'failed';
|
||||
print '**** ftell(f) != 111 failed';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (iserror(fseek(f, -4, 1))) {
|
||||
print 'failed';
|
||||
|
Reference in New Issue
Block a user