mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Release calc version 2.11.0t10
This commit is contained in:
79
CHANGES
79
CHANGES
@@ -1,4 +1,10 @@
|
|||||||
Following is the change from calc version 2.11.0t8.9.1 to date:
|
The following are the changes from calc version 2.11.0t10 to date:
|
||||||
|
|
||||||
|
Misc code cleanup. Removed dead code. Removed trailing whitespace.
|
||||||
|
Fixed whitespace to make the best use of 8 character tabs.
|
||||||
|
|
||||||
|
|
||||||
|
The following are the changes from calc version 2.11.0t8.9.1 to 2.11.0t9.4.5:
|
||||||
|
|
||||||
The config("verbose_quit") will control the printing of the message:
|
The config("verbose_quit") will control the printing of the message:
|
||||||
|
|
||||||
@@ -219,8 +225,9 @@ Following is the change from calc version 2.11.0t8.9.1 to date:
|
|||||||
10000 will be considered calc errors instead. The Makefile symbol
|
10000 will be considered calc errors instead. The Makefile symbol
|
||||||
ERRNO_DECL has gone away as well as calc_errno.c and calc_errno.h.
|
ERRNO_DECL has gone away as well as calc_errno.c and calc_errno.h.
|
||||||
|
|
||||||
On system errors are are not known to to the libc strerror() function,
|
System errors that are are not known to to the libc strerror()
|
||||||
strerror() will now print something such as:
|
function, will now print (via the strerror() calc builtin function)
|
||||||
|
something such as:
|
||||||
|
|
||||||
Unknown error 9999
|
Unknown error 9999
|
||||||
|
|
||||||
@@ -235,7 +242,7 @@ Following is the change from calc version 2.11.0t8.9.1 to date:
|
|||||||
stay under the radar of spammers as much as one can do so.
|
stay under the radar of spammers as much as one can do so.
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.11.0t8 to 2.11.0t8.9:
|
The following are the changes from calc version 2.11.0t8 to 2.11.0t8.9:
|
||||||
|
|
||||||
Moved 'wishlist' enhancements from the help/todo file to a new
|
Moved 'wishlist' enhancements from the help/todo file to a new
|
||||||
help/wishlist file. Ordered, by priority, help/todo items into
|
help/wishlist file. Ordered, by priority, help/todo items into
|
||||||
@@ -391,7 +398,7 @@ Following is the change from calc version 2.11.0t8 to 2.11.0t8.9:
|
|||||||
Fixed misc compiler warnings.
|
Fixed misc compiler warnings.
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.11.0t7 to 2.11.0t7.5:
|
The following are the changes from calc version 2.11.0t7 to 2.11.0t7.5:
|
||||||
|
|
||||||
Calc has some new command line flags / command line meaning:
|
Calc has some new command line flags / command line meaning:
|
||||||
(Thanks goes to Ernest Bowen <ernie@turing.une.edu.au>)
|
(Thanks goes to Ernest Bowen <ernie@turing.une.edu.au>)
|
||||||
@@ -539,7 +546,7 @@ Following is the change from calc version 2.11.0t7 to 2.11.0t7.5:
|
|||||||
Misc calc man page fixes.
|
Misc calc man page fixes.
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.11.0t1 to 2.11.0t6.3:
|
The following are the changes from calc version 2.11.0t1 to 2.11.0t6.3:
|
||||||
|
|
||||||
Removed the makefile symbol MAIN. Now forcing all functions to correctly
|
Removed the makefile symbol MAIN. Now forcing all functions to correctly
|
||||||
be declared main. To satisfy some old broken compilers, a return 0;
|
be declared main. To satisfy some old broken compilers, a return 0;
|
||||||
@@ -731,12 +738,12 @@ Following is the change from calc version 2.11.0t1 to 2.11.0t6.3:
|
|||||||
Fixed misc compile warnings and notices.
|
Fixed misc compile warnings and notices.
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.3t5.38 to 2.11.0t0:
|
The following are the changes from calc version 2.10.3t5.38 to 2.11.0t0:
|
||||||
|
|
||||||
Fixed a few compile problems found under Red Hat 6.0 Linux.
|
Fixed a few compile problems found under Red Hat 6.0 Linux.
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.3t5.38 to 2.11.3t5.46:
|
The following are the changes from calc version 2.10.3t5.38 to 2.11.3t5.46:
|
||||||
|
|
||||||
Fixed a bug discovered by Ernest Bowen related to matrix-to-matrix copies.
|
Fixed a bug discovered by Ernest Bowen related to matrix-to-matrix copies.
|
||||||
|
|
||||||
@@ -793,7 +800,7 @@ Following is the change from calc version 2.10.3t5.38 to 2.11.3t5.46:
|
|||||||
into a single section.
|
into a single section.
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.3t5.34 to 2.10.3t5.37:
|
The following are the changes from calc version 2.10.3t5.34 to 2.10.3t5.37:
|
||||||
|
|
||||||
Per request from David I Bell, the README line:
|
Per request from David I Bell, the README line:
|
||||||
|
|
||||||
@@ -1312,7 +1319,7 @@ Following is the change from calc version 2.10.3t5.34 to 2.10.3t5.37:
|
|||||||
user-specified bound.
|
user-specified bound.
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.3t5.28 to 2.10.3t5.33:
|
The following are the changes from calc version 2.10.3t5.28 to 2.10.3t5.33:
|
||||||
|
|
||||||
Added hnrmod(v, h, n, r) builtin to compute:
|
Added hnrmod(v, h, n, r) builtin to compute:
|
||||||
|
|
||||||
@@ -1674,11 +1681,11 @@ Following is the change from calc version 2.10.3t5.28 to 2.10.3t5.33:
|
|||||||
Added regression tests related to saveval(), dot and pointers.
|
Added regression tests related to saveval(), dot and pointers.
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.3t5.11 to 2.10.3t5.27:
|
The following are the changes from calc version 2.10.3t5.11 to 2.10.3t5.27:
|
||||||
|
|
||||||
The todo help file as been updated with the in-progress items:
|
The todo help file as been updated with the in-progress items:
|
||||||
|
|
||||||
XXX - block print function is not written yet ...
|
xxx - block print function is not written yet ...
|
||||||
|
|
||||||
Expanded the role of blk() to produce unnamed blocks as in:
|
Expanded the role of blk() to produce unnamed blocks as in:
|
||||||
|
|
||||||
@@ -1816,7 +1823,7 @@ Following is the change from calc version 2.10.3t5.11 to 2.10.3t5.27:
|
|||||||
where x was not 2^n-1 would leak memory. This has been fixed.
|
where x was not 2^n-1 would leak memory. This has been fixed.
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.3t5.1 to 2.10.3t5.10:
|
The following are the changes from calc version 2.10.3t5.1 to 2.10.3t5.10:
|
||||||
|
|
||||||
Misc printf warning bug fixes.
|
Misc printf warning bug fixes.
|
||||||
|
|
||||||
@@ -2017,7 +2024,7 @@ Following is the change from calc version 2.10.3t5.1 to 2.10.3t5.10:
|
|||||||
regression tests for memsize(), sizeof() and size().
|
regression tests for memsize(), sizeof() and size().
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.3t4.16 to 2.10.3t5.0:
|
The following are the changes from calc version 2.10.3t4.16 to 2.10.3t5.0:
|
||||||
|
|
||||||
The calc source now comes with a custom sub-directory which
|
The calc source now comes with a custom sub-directory which
|
||||||
contains the custom interface code. The main Makefile now
|
contains the custom interface code. The main Makefile now
|
||||||
@@ -2209,7 +2216,7 @@ Following is the change from calc version 2.10.3t4.16 to 2.10.3t5.0:
|
|||||||
The max(), min() builtins work for lists.
|
The max(), min() builtins work for lists.
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.3t3 to 2.10.3t4.15:
|
The following are the changes from calc version 2.10.3t3 to 2.10.3t4.15:
|
||||||
|
|
||||||
The priority of unary + and - to that of binary + and - when they are
|
The priority of unary + and - to that of binary + and - when they are
|
||||||
applied to a first or only term. Thus:
|
applied to a first or only term. Thus:
|
||||||
@@ -2385,7 +2392,7 @@ Following is the change from calc version 2.10.3t3 to 2.10.3t4.15:
|
|||||||
Fixed error in using cmdbuf("").
|
Fixed error in using cmdbuf("").
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.3t0 to 2.10.3t2:
|
The following are the changes from calc version 2.10.3t0 to 2.10.3t2:
|
||||||
|
|
||||||
Bumped to version 2.10.3 due to the amount of changes.
|
Bumped to version 2.10.3 due to the amount of changes.
|
||||||
|
|
||||||
@@ -2547,7 +2554,7 @@ Following is the change from calc version 2.10.3t0 to 2.10.3t2:
|
|||||||
SGI 6.2 and later uses -xansi.
|
SGI 6.2 and later uses -xansi.
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.2t33 to 2.10.2t34:
|
The following are the changes from calc version 2.10.2t33 to 2.10.2t34:
|
||||||
|
|
||||||
Fixed a bug related to fact().
|
Fixed a bug related to fact().
|
||||||
|
|
||||||
@@ -2624,7 +2631,7 @@ Following is the change from calc version 2.10.2t33 to 2.10.2t34:
|
|||||||
http://www.latech.edu/~acm/HelloWorld.shtml
|
http://www.latech.edu/~acm/HelloWorld.shtml
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.2t25 to 2.10.2t32:
|
The following are the changes from calc version 2.10.2t25 to 2.10.2t32:
|
||||||
|
|
||||||
Eliminated use of VARARG and <varargs.h>. Calc supports only
|
Eliminated use of VARARG and <varargs.h>. Calc supports only
|
||||||
<stdarg.h>. The VARARGS Makefile variable has been eliminated.
|
<stdarg.h>. The VARARGS Makefile variable has been eliminated.
|
||||||
@@ -2808,7 +2815,7 @@ Following is the change from calc version 2.10.2t25 to 2.10.2t32:
|
|||||||
and file system permits.
|
and file system permits.
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.2t4 to 2.10.2t24:
|
The following are the changes from calc version 2.10.2t4 to 2.10.2t24:
|
||||||
|
|
||||||
Added makefile debugging rules:
|
Added makefile debugging rules:
|
||||||
|
|
||||||
@@ -3093,7 +3100,7 @@ Following is the change from calc version 2.10.2t4 to 2.10.2t24:
|
|||||||
SWAP_HALF_IN_OFF_T.
|
SWAP_HALF_IN_OFF_T.
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.2t1 to 2.10.2t3:
|
The following are the changes from calc version 2.10.2t1 to 2.10.2t3:
|
||||||
|
|
||||||
Fixed bug in the regression suite that made test3400 and test4100
|
Fixed bug in the regression suite that made test3400 and test4100
|
||||||
fail on correct computations.
|
fail on correct computations.
|
||||||
@@ -3269,7 +3276,7 @@ Following is the change from calc version 2.10.2t1 to 2.10.2t3:
|
|||||||
treated as read-only.
|
treated as read-only.
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.1t21 to 2.10.2t0:
|
The following are the changes from calc version 2.10.1t21 to 2.10.2t0:
|
||||||
|
|
||||||
Bumped patch level 2.10.2t0 in honor of having help files for
|
Bumped patch level 2.10.2t0 in honor of having help files for
|
||||||
all builtin functions. Beta release will happen at the end of
|
all builtin functions. Beta release will happen at the end of
|
||||||
@@ -3351,7 +3358,7 @@ Following is the change from calc version 2.10.1t21 to 2.10.2t0:
|
|||||||
mat D[] = { }
|
mat D[] = { }
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.1t20 to 2.10.1t20:
|
The following are the changes from calc version 2.10.1t20 to 2.10.1t20:
|
||||||
|
|
||||||
Changes made in preparation for Blum Blum Shub random number generator.
|
Changes made in preparation for Blum Blum Shub random number generator.
|
||||||
|
|
||||||
@@ -3428,7 +3435,7 @@ Following is the change from calc version 2.10.1t20 to 2.10.1t20:
|
|||||||
<ernie@neumann.une.edu.au>
|
<ernie@neumann.une.edu.au>
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.1t11 to 2.10.1t19:
|
The following are the changes from calc version 2.10.1t11 to 2.10.1t19:
|
||||||
|
|
||||||
Added many more regression tests to lib/regress.cal. Some
|
Added many more regression tests to lib/regress.cal. Some
|
||||||
due to <ernie@neumann.une.edu.au>.
|
due to <ernie@neumann.une.edu.au>.
|
||||||
@@ -3628,7 +3635,7 @@ Following is the change from calc version 2.10.1t11 to 2.10.1t19:
|
|||||||
Ha Lam <hl@kuhep5.phsx.ukans.edu>
|
Ha Lam <hl@kuhep5.phsx.ukans.edu>
|
||||||
|
|
||||||
|
|
||||||
Following is the change from calc version 2.10.0t13 to 2.10.1t10:
|
The following are the changes from calc version 2.10.0t13 to 2.10.1t10:
|
||||||
|
|
||||||
Added SB8, USB8, SB16, USB16, SB32, USB32 typedefs, determined by
|
Added SB8, USB8, SB16, USB16, SB32, USB32 typedefs, determined by
|
||||||
longbits and declared in longbits.h, to deal with 8, 16 and 32 bit
|
longbits and declared in longbits.h, to deal with 8, 16 and 32 bit
|
||||||
@@ -3745,7 +3752,8 @@ Following is the change from calc version 2.10.0t13 to 2.10.1t10:
|
|||||||
digits or bits rather than places, e.g. round(.00238, 2, 32)
|
digits or bits rather than places, e.g. round(.00238, 2, 32)
|
||||||
returns .0023, round(.00238, 2, 56) returns .0024.
|
returns .0023, round(.00238, 2, 56) returns .0024.
|
||||||
|
|
||||||
Following is the change from calc version 2.9.3t11 to 2.10.0t12:
|
|
||||||
|
The following are the changes from calc version 2.9.3t11 to 2.10.0t12:
|
||||||
|
|
||||||
The default ${LIBDIR}/bindings CALCBINDINGS uses ^D for editing.
|
The default ${LIBDIR}/bindings CALCBINDINGS uses ^D for editing.
|
||||||
The alternate CALCBINDINGS ${LIBDIR}/altbind uses ^D for EOF.
|
The alternate CALCBINDINGS ${LIBDIR}/altbind uses ^D for EOF.
|
||||||
@@ -3799,7 +3807,8 @@ Following is the change from calc version 2.9.3t11 to 2.10.0t12:
|
|||||||
to provide a more extensive test suite for some builtin numeric
|
to provide a more extensive test suite for some builtin numeric
|
||||||
functions.
|
functions.
|
||||||
|
|
||||||
Following is the change from calc version 2.9.3t9.2+ to 2.9.3t10:
|
|
||||||
|
The following are the changes from calc version 2.9.3t9.2+ to 2.9.3t10:
|
||||||
|
|
||||||
Added many help files for builtin functions and some symbols.
|
Added many help files for builtin functions and some symbols.
|
||||||
More help files are needed, see help/todo.
|
More help files are needed, see help/todo.
|
||||||
@@ -3902,7 +3911,8 @@ Following is the change from calc version 2.9.3t9.2+ to 2.9.3t10:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Following is the change from calc version 2.9.3t8 to 2.9.3t9.2:
|
|
||||||
|
The following are the changes from calc version 2.9.3t8 to 2.9.3t9.2:
|
||||||
|
|
||||||
Use of the macro zisleone(z) has been clarified. The zisleone(z) macro
|
Use of the macro zisleone(z) has been clarified. The zisleone(z) macro
|
||||||
tests if z <= 1. The macro zisabsleone(z) tests of z is 1, 0 or -1.
|
tests if z <= 1. The macro zisabsleone(z) tests of z is 1, 0 or -1.
|
||||||
@@ -4110,7 +4120,8 @@ Following is the change from calc version 2.9.3t8 to 2.9.3t9.2:
|
|||||||
|
|
||||||
Fixed bug where reserved keyword used as symbol name caused a core dump.
|
Fixed bug where reserved keyword used as symbol name caused a core dump.
|
||||||
|
|
||||||
Following is the change from calc version 2.9.3t7 to 2.9.3t7:
|
|
||||||
|
The following are the changes from calc version 2.9.3t7 to 2.9.3t7:
|
||||||
|
|
||||||
The 'show' command by itself will issue an error message
|
The 'show' command by itself will issue an error message
|
||||||
that will remind one of the possible show arguments.
|
that will remind one of the possible show arguments.
|
||||||
@@ -4157,7 +4168,8 @@ Following is the change from calc version 2.9.3t7 to 2.9.3t7:
|
|||||||
Added utoz(), ztou() to zmath.c, and utoq(), qtou() to qmath.c
|
Added utoz(), ztou() to zmath.c, and utoq(), qtou() to qmath.c
|
||||||
in preparation for 2.9.3t9 mods.
|
in preparation for 2.9.3t9 mods.
|
||||||
|
|
||||||
Following is the change from calc version 2.9.2 to 2.9.3t7:
|
|
||||||
|
The following are the changes from calc version 2.9.2 to 2.9.3t7:
|
||||||
|
|
||||||
Calc can now compile on OSF/1, SGI and IBM RS6000 systems.
|
Calc can now compile on OSF/1, SGI and IBM RS6000 systems.
|
||||||
|
|
||||||
@@ -4278,7 +4290,8 @@ Following is the change from calc version 2.9.2 to 2.9.3t7:
|
|||||||
Updated the help/todo list. A BUGS file was added. Volunteers are
|
Updated the help/todo list. A BUGS file was added. Volunteers are
|
||||||
welcome to send in patches!
|
welcome to send in patches!
|
||||||
|
|
||||||
Following is the change from calc version 2.9.1 to 2.9.1:
|
|
||||||
|
The following are the changes from calc version 2.9.1 to 2.9.1:
|
||||||
|
|
||||||
Fixed floor() for values -1 < x < 0.
|
Fixed floor() for values -1 < x < 0.
|
||||||
|
|
||||||
@@ -4292,12 +4305,14 @@ Following is the change from calc version 2.9.1 to 2.9.1:
|
|||||||
|
|
||||||
Added more regression test code.
|
Added more regression test code.
|
||||||
|
|
||||||
Following is the change from calc version 2.9.0 to 2.9.0:
|
|
||||||
|
The following are the changes from calc version 2.9.0 to 2.9.0:
|
||||||
|
|
||||||
A major bug was fixed in subtracting two numbers when the first
|
A major bug was fixed in subtracting two numbers when the first
|
||||||
number was zero. The problem caused wrong answers and core dumps.
|
number was zero. The problem caused wrong answers and core dumps.
|
||||||
|
|
||||||
Following is a list of visible changes to calc from version 1.27.0 to 2.8.0:
|
|
||||||
|
The following are the changes from calc version 1.27.0 to 2.8.0:
|
||||||
|
|
||||||
Full prototypes have been provided for all C functions, and are used
|
Full prototypes have been provided for all C functions, and are used
|
||||||
if calc is compiled with an ANSI compiler.
|
if calc is compiled with an ANSI compiler.
|
||||||
|
5
addop.c
5
addop.c
@@ -535,8 +535,7 @@ addop(long op)
|
|||||||
qfree(q);
|
qfree(q);
|
||||||
fp->f_opcodes[count - 2] = OP_ZERO;
|
fp->f_opcodes[count - 2] = OP_ZERO;
|
||||||
fp->f_opcodecount--;
|
fp->f_opcodecount--;
|
||||||
}
|
} else if (qisone(q)) {
|
||||||
else if (qisone(q)) {
|
|
||||||
qfree(q);
|
qfree(q);
|
||||||
fp->f_opcodes[count - 2] = OP_ONE;
|
fp->f_opcodes[count - 2] = OP_ONE;
|
||||||
fp->f_opcodecount--;
|
fp->f_opcodecount--;
|
||||||
@@ -639,5 +638,3 @@ addoplabel(long op, LABEL *label)
|
|||||||
addop(op);
|
addop(op);
|
||||||
uselabel(label);
|
uselabel(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* END CODE */
|
|
||||||
|
11
assocfunc.c
11
assocfunc.c
@@ -245,8 +245,7 @@ assoccmp(ASSOC *ap1, ASSOC *ap2)
|
|||||||
hash = ep1->e_hash;
|
hash = ep1->e_hash;
|
||||||
dim = ep1->e_dim;
|
dim = ep1->e_dim;
|
||||||
for (ep2 = ap2->a_table[hash % size2]; ;
|
for (ep2 = ap2->a_table[hash % size2]; ;
|
||||||
ep2 = ep2->e_next)
|
ep2 = ep2->e_next) {
|
||||||
{
|
|
||||||
if (ep2 == NULL)
|
if (ep2 == NULL)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
if (ep2->e_hash != hash)
|
if (ep2->e_hash != hash)
|
||||||
@@ -283,8 +282,7 @@ assoccopy(ASSOC *oldap)
|
|||||||
|
|
||||||
for (oldhi = 0; oldhi < oldap->a_size; oldhi++) {
|
for (oldhi = 0; oldhi < oldap->a_size; oldhi++) {
|
||||||
for (oldep = oldap->a_table[oldhi]; oldep;
|
for (oldep = oldap->a_table[oldhi]; oldep;
|
||||||
oldep = oldep->e_next)
|
oldep = oldep->e_next) {
|
||||||
{
|
|
||||||
ep = (ASSOCELEM *) malloc(ELEMSIZE(oldep->e_dim));
|
ep = (ASSOCELEM *) malloc(ELEMSIZE(oldep->e_dim));
|
||||||
if (ep == NULL) {
|
if (ep == NULL) {
|
||||||
math_error("Cannot allocate association element");
|
math_error("Cannot allocate association element");
|
||||||
@@ -449,8 +447,7 @@ assocprint(ASSOC *ap, long max_print)
|
|||||||
((ap->a_count == 1) ? "" : "s"));
|
((ap->a_count == 1) ? "" : "s"));
|
||||||
|
|
||||||
for (index = 0; ((index < max_print) && (index < ap->a_count));
|
for (index = 0; ((index < max_print) && (index < ap->a_count));
|
||||||
index++)
|
index++) {
|
||||||
{
|
|
||||||
ep = elemindex(ap, index);
|
ep = elemindex(ap, index);
|
||||||
if (ep == NULL)
|
if (ep == NULL)
|
||||||
continue;
|
continue;
|
||||||
@@ -491,5 +488,3 @@ compareindices(VALUE *v1, VALUE *v2, long dim)
|
|||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* END CODE */
|
|
||||||
|
9
block.c
9
block.c
@@ -479,7 +479,7 @@ blk_print(BLOCK *blk)
|
|||||||
BOOL havetail;
|
BOOL havetail;
|
||||||
USB8 *ptr;
|
USB8 *ptr;
|
||||||
|
|
||||||
/* XXX - use the config parameters for better print control */
|
/* XXX - should use the config parameters for better print control */
|
||||||
|
|
||||||
printf("chunksize = %d, maxsize = %d, datalen = %d\n\t",
|
printf("chunksize = %d, maxsize = %d, datalen = %d\n\t",
|
||||||
(int)blk->blkchunk, (int)blk->maxsize, (int)blk->datalen);
|
(int)blk->blkchunk, (int)blk->maxsize, (int)blk->datalen);
|
||||||
@@ -512,9 +512,9 @@ nblock_print(NBLOCK *nblk)
|
|||||||
printf("chunksize = %d, maxsize = %d, datalen = %d\n\t",
|
printf("chunksize = %d, maxsize = %d, datalen = %d\n\t",
|
||||||
(int)blk->blkchunk, (int)blk->maxsize, (int)blk->datalen);
|
(int)blk->blkchunk, (int)blk->maxsize, (int)blk->datalen);
|
||||||
printf("NULL");
|
printf("NULL");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
blk_print(blk);
|
blk_print(blk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -556,8 +556,7 @@ reallocnblock(int id, int len, int chunk)
|
|||||||
math_error("Allocation failed");
|
math_error("Allocation failed");
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
}
|
} else if (newsize != oldsize) {
|
||||||
else if (newsize != oldsize) {
|
|
||||||
newdata = realloc(blk->data, newsize);
|
newdata = realloc(blk->data, newsize);
|
||||||
if (newdata == NULL) {
|
if (newdata == NULL) {
|
||||||
math_error("Reallocation failed");
|
math_error("Reallocation failed");
|
||||||
|
45
comfunc.c
45
comfunc.c
@@ -138,38 +138,6 @@ csqrt(COMPLEX *c, NUMBER *epsilon, long R)
|
|||||||
|
|
||||||
up1 = up2 = 0;
|
up1 = up2 = 0;
|
||||||
sign = (R & 64) != 0;
|
sign = (R & 64) != 0;
|
||||||
#if 0
|
|
||||||
if (qiszero(epsilon)) {
|
|
||||||
aes = qsquare(c->real);
|
|
||||||
bes = qsquare(c->imag);
|
|
||||||
v = qqadd(aes, bes);
|
|
||||||
qfree(aes);
|
|
||||||
qfree(bes);
|
|
||||||
u = qsqrt(v, epsilon, 0);
|
|
||||||
qfree(v);
|
|
||||||
if (qiszero(u)) {
|
|
||||||
qfree(u);
|
|
||||||
return clink(&_czero_);
|
|
||||||
}
|
|
||||||
aes = qqadd(u, c->real);
|
|
||||||
qfree(u);
|
|
||||||
bes = qscale(aes, -1);
|
|
||||||
qfree(aes);
|
|
||||||
u = qsqrt(bes, epsilon, R);
|
|
||||||
qfree(bes);
|
|
||||||
if (qiszero(u)) {
|
|
||||||
qfree(u);
|
|
||||||
return clink(&_czero_);
|
|
||||||
}
|
|
||||||
aes = qscale(c->imag, -1);
|
|
||||||
v = qqdiv(aes, u);
|
|
||||||
qfree(aes);
|
|
||||||
r = comalloc();
|
|
||||||
r->real = u;
|
|
||||||
r->imag = v;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
imsign = c->imag->num.sign;
|
imsign = c->imag->num.sign;
|
||||||
es = qsquare(epsilon);
|
es = qsquare(epsilon);
|
||||||
aes = qqdiv(c->real, es);
|
aes = qqdiv(c->real, es);
|
||||||
@@ -255,8 +223,7 @@ csqrt(COMPLEX *c, NUMBER *epsilon, long R)
|
|||||||
up2 = -1;
|
up2 = -1;
|
||||||
zfree(tmp1);
|
zfree(tmp1);
|
||||||
zfree(aa);
|
zfree(aa);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
s1 = zsqrt(tmp3, &cc, 0);
|
s1 = zsqrt(tmp3, &cc, 0);
|
||||||
zfree(tmp3);
|
zfree(tmp3);
|
||||||
zadd(cc, a, &tmp1);
|
zadd(cc, a, &tmp1);
|
||||||
@@ -333,9 +300,9 @@ csqrt(COMPLEX *c, NUMBER *epsilon, long R)
|
|||||||
zfree(mul2);
|
zfree(mul2);
|
||||||
mul2 = tmp2;
|
mul2 = tmp2;
|
||||||
}
|
}
|
||||||
if (ziszero(mul1))
|
if (ziszero(mul1)) {
|
||||||
u = qlink(&_qzero_);
|
u = qlink(&_qzero_);
|
||||||
else {
|
} else {
|
||||||
mul1.sign = sign ^ epsilon->num.sign;
|
mul1.sign = sign ^ epsilon->num.sign;
|
||||||
u = qalloc();
|
u = qalloc();
|
||||||
zreduce(mul1, epsilon->den, &tmp2, &u->den);
|
zreduce(mul1, epsilon->den, &tmp2, &u->den);
|
||||||
@@ -343,9 +310,9 @@ csqrt(COMPLEX *c, NUMBER *epsilon, long R)
|
|||||||
zfree(tmp2);
|
zfree(tmp2);
|
||||||
}
|
}
|
||||||
zfree(mul1);
|
zfree(mul1);
|
||||||
if (ziszero(mul2))
|
if (ziszero(mul2)) {
|
||||||
v = qlink(&_qzero_);
|
v = qlink(&_qzero_);
|
||||||
else {
|
} else {
|
||||||
mul2.sign = imsign ^ sign ^ epsilon->num.sign;
|
mul2.sign = imsign ^ sign ^ epsilon->num.sign;
|
||||||
v = qalloc();
|
v = qalloc();
|
||||||
zreduce(mul2, epsilon->den, &tmp2, &v->den);
|
zreduce(mul2, epsilon->den, &tmp2, &v->den);
|
||||||
@@ -1147,5 +1114,3 @@ cprintfr(COMPLEX *c)
|
|||||||
zprintval(i->den, 0L, 0L);
|
zprintval(i->den, 0L, 0L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* END CODE */
|
|
||||||
|
55
func.c
55
func.c
@@ -1476,9 +1476,9 @@ f_min(int count, VALUE **vals)
|
|||||||
if (qisneg(rel.v_num)) {
|
if (qisneg(rel.v_num)) {
|
||||||
freevalue(&min);
|
freevalue(&min);
|
||||||
min = term;
|
min = term;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
freevalue(&term);
|
freevalue(&term);
|
||||||
|
}
|
||||||
freevalue(&rel);
|
freevalue(&rel);
|
||||||
}
|
}
|
||||||
return min;
|
return min;
|
||||||
@@ -1532,9 +1532,9 @@ f_max(int count, VALUE **vals)
|
|||||||
if (qisneg(rel.v_num)) {
|
if (qisneg(rel.v_num)) {
|
||||||
freevalue(&max);
|
freevalue(&max);
|
||||||
max = term;
|
max = term;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
freevalue(&term);
|
freevalue(&term);
|
||||||
|
}
|
||||||
freevalue(&rel);
|
freevalue(&rel);
|
||||||
}
|
}
|
||||||
return max;
|
return max;
|
||||||
@@ -3370,9 +3370,9 @@ f_root(int count, VALUE **vals)
|
|||||||
err.v_subtype = V_NOSUBTYPE;
|
err.v_subtype = V_NOSUBTYPE;
|
||||||
result.v_subtype = V_NOSUBTYPE;
|
result.v_subtype = V_NOSUBTYPE;
|
||||||
|
|
||||||
if (count > 2)
|
if (count > 2) {
|
||||||
vp = vals[2];
|
vp = vals[2];
|
||||||
else {
|
} else {
|
||||||
err.v_num = conf->epsilon;
|
err.v_num = conf->epsilon;
|
||||||
err.v_type = V_NUM;
|
err.v_type = V_NUM;
|
||||||
vp = &err;
|
vp = &err;
|
||||||
@@ -3391,9 +3391,9 @@ f_power(int count, VALUE **vals)
|
|||||||
err.v_subtype = V_NOSUBTYPE;
|
err.v_subtype = V_NOSUBTYPE;
|
||||||
result.v_subtype = V_NOSUBTYPE;
|
result.v_subtype = V_NOSUBTYPE;
|
||||||
|
|
||||||
if (count > 2)
|
if (count > 2) {
|
||||||
vp = vals[2];
|
vp = vals[2];
|
||||||
else {
|
} else {
|
||||||
err.v_num = conf->epsilon;
|
err.v_num = conf->epsilon;
|
||||||
err.v_type = V_NUM;
|
err.v_type = V_NUM;
|
||||||
vp = &err;
|
vp = &err;
|
||||||
@@ -3413,9 +3413,9 @@ f_polar(int count, VALUE **vals)
|
|||||||
err.v_subtype = V_NOSUBTYPE;
|
err.v_subtype = V_NOSUBTYPE;
|
||||||
result.v_subtype = V_NOSUBTYPE;
|
result.v_subtype = V_NOSUBTYPE;
|
||||||
|
|
||||||
if (count > 2)
|
if (count > 2) {
|
||||||
vp = vals[2];
|
vp = vals[2];
|
||||||
else {
|
} else {
|
||||||
err.v_num = conf->epsilon;
|
err.v_num = conf->epsilon;
|
||||||
err.v_type = V_NUM;
|
err.v_type = V_NUM;
|
||||||
vp = &err;
|
vp = &err;
|
||||||
@@ -4138,10 +4138,10 @@ f_search(int count, VALUE **vals)
|
|||||||
qfree(start);
|
qfree(start);
|
||||||
start = qlink(&_qzero_);
|
start = qlink(&_qzero_);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
start = qlink(start);
|
start = qlink(start);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (end) {
|
if (end) {
|
||||||
if (!qispos(end)) {
|
if (!qispos(end)) {
|
||||||
end = qqadd(size, end);
|
end = qqadd(size, end);
|
||||||
@@ -4388,8 +4388,7 @@ f_rsearch(int count, VALUE **vals)
|
|||||||
else
|
else
|
||||||
end = qlink(size);
|
end = qlink(size);
|
||||||
start = qlink(&_qzero_);
|
start = qlink(&_qzero_);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (start == NULL)
|
if (start == NULL)
|
||||||
start = qlink(&_qzero_);
|
start = qlink(&_qzero_);
|
||||||
if (end == NULL)
|
if (end == NULL)
|
||||||
@@ -4726,9 +4725,9 @@ f_freopen(int count, VALUE **vals)
|
|||||||
return error_value(E_FREOPEN2);
|
return error_value(E_FREOPEN2);
|
||||||
}
|
}
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (count == 2)
|
if (count == 2) {
|
||||||
id = reopenid(vals[0]->v_file, mode, NULL);
|
id = reopenid(vals[0]->v_file, mode, NULL);
|
||||||
else {
|
} else {
|
||||||
if (vals[2]->v_type != V_STR)
|
if (vals[2]->v_type != V_STR)
|
||||||
return error_value(E_FREOPEN3);
|
return error_value(E_FREOPEN3);
|
||||||
id = reopenid(vals[0]->v_file, mode,
|
id = reopenid(vals[0]->v_file, mode,
|
||||||
@@ -4963,9 +4962,9 @@ f_newerror(int count, VALUE **vals)
|
|||||||
if (nexterrnum == E_USERDEF)
|
if (nexterrnum == E_USERDEF)
|
||||||
initstr(&newerrorstr);
|
initstr(&newerrorstr);
|
||||||
index = findstr(&newerrorstr, str);
|
index = findstr(&newerrorstr, str);
|
||||||
if (index >= 0)
|
if (index >= 0) {
|
||||||
errnum = E_USERDEF + index;
|
errnum = E_USERDEF + index;
|
||||||
else {
|
} else {
|
||||||
if (nexterrnum == 32767)
|
if (nexterrnum == 32767)
|
||||||
math_error("Too many new error values");
|
math_error("Too many new error values");
|
||||||
errnum = nexterrnum++;
|
errnum = nexterrnum++;
|
||||||
@@ -5092,9 +5091,9 @@ f_fflush(int count, VALUE **vals)
|
|||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (count == 0)
|
if (count == 0) {
|
||||||
i = flushall();
|
i = flushall();
|
||||||
else {
|
} else {
|
||||||
for (n = 0; n < count; n++) {
|
for (n = 0; n < count; n++) {
|
||||||
if (vals[n]->v_type != V_FILE)
|
if (vals[n]->v_type != V_FILE)
|
||||||
return error_value(E_FFLUSH);
|
return error_value(E_FFLUSH);
|
||||||
@@ -5130,9 +5129,9 @@ f_error(int count, VALUE **vals)
|
|||||||
r = E_ERROR2;
|
r = E_ERROR2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
r = set_errno(-1);
|
r = set_errno(-1);
|
||||||
|
}
|
||||||
|
|
||||||
return error_value(r);
|
return error_value(r);
|
||||||
}
|
}
|
||||||
@@ -5192,9 +5191,9 @@ f_fseek(int count, VALUE **vals)
|
|||||||
return error_value(E_FSEEK1);
|
return error_value(E_FSEEK1);
|
||||||
if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num))
|
if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num))
|
||||||
return error_value(E_FSEEK2);
|
return error_value(E_FSEEK2);
|
||||||
if (count == 2)
|
if (count == 2) {
|
||||||
whence = 0;
|
whence = 0;
|
||||||
else {
|
} else {
|
||||||
if (vals[2]->v_type != V_NUM || qisfrac(vals[2]->v_num) ||
|
if (vals[2]->v_type != V_NUM || qisfrac(vals[2]->v_num) ||
|
||||||
qisneg(vals[2]->v_num))
|
qisneg(vals[2]->v_num))
|
||||||
return error_value(E_FSEEK2);
|
return error_value(E_FSEEK2);
|
||||||
@@ -5248,10 +5247,10 @@ f_rewind(int count, VALUE **vals)
|
|||||||
/* initialize VALUE */
|
/* initialize VALUE */
|
||||||
result.v_subtype = V_NOSUBTYPE;
|
result.v_subtype = V_NOSUBTYPE;
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0) {
|
||||||
rewindall();
|
rewindall();
|
||||||
|
|
||||||
else {
|
} else {
|
||||||
for (n = 0; n < count; n++) {
|
for (n = 0; n < count; n++) {
|
||||||
if (vals[n]->v_type != V_FILE)
|
if (vals[n]->v_type != V_FILE)
|
||||||
return error_value(E_REWIND1);
|
return error_value(E_REWIND1);
|
||||||
@@ -6886,9 +6885,9 @@ f_blocks(int count, VALUE **vals)
|
|||||||
|
|
||||||
nblk = findnblock(id);
|
nblk = findnblock(id);
|
||||||
|
|
||||||
if (nblk == NULL)
|
if (nblk == NULL) {
|
||||||
return error_value(E_BLOCKS2);
|
return error_value(E_BLOCKS2);
|
||||||
else {
|
} else {
|
||||||
result.v_type = V_NBLOCK;
|
result.v_type = V_NBLOCK;
|
||||||
result.v_nblock = nblk;
|
result.v_nblock = nblk;
|
||||||
}
|
}
|
||||||
|
19
hist.c
19
hist.c
@@ -516,9 +516,9 @@ do_bind_line(KEY_MAP *map, char *line)
|
|||||||
} else {
|
} else {
|
||||||
key = CONTROL(*cp++);
|
key = CONTROL(*cp++);
|
||||||
}
|
}
|
||||||
}
|
} else if (key == '\\') {
|
||||||
else if (key == '\\')
|
|
||||||
key = *cp++;
|
key = *cp++;
|
||||||
|
}
|
||||||
|
|
||||||
while (isspace((int)*cp))
|
while (isspace((int)*cp))
|
||||||
cp++;
|
cp++;
|
||||||
@@ -582,8 +582,7 @@ do_default_line(KEY_MAP *map, char *line)
|
|||||||
func_name = cp;
|
func_name = cp;
|
||||||
while ((*cp != '\0') && !isspace((int)*cp))
|
while ((*cp != '\0') && !isspace((int)*cp))
|
||||||
cp++;
|
cp++;
|
||||||
if (*cp != '\0')
|
if (*cp != '\0') {
|
||||||
{
|
|
||||||
*cp++ = '\0';
|
*cp++ = '\0';
|
||||||
while (isspace((int)*cp))
|
while (isspace((int)*cp))
|
||||||
cp++;
|
cp++;
|
||||||
@@ -592,15 +591,13 @@ do_default_line(KEY_MAP *map, char *line)
|
|||||||
if (func == NULL)
|
if (func == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (*cp == '\0')
|
if (*cp == '\0') {
|
||||||
next = map;
|
next = map;
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
next_name = cp;
|
next_name = cp;
|
||||||
while ((*cp != '\0') && !isspace((int)*cp))
|
while ((*cp != '\0') && !isspace((int)*cp))
|
||||||
cp++;
|
cp++;
|
||||||
if (*cp != '\0')
|
if (*cp != '\0') {
|
||||||
{
|
|
||||||
*cp++ = '\0';
|
*cp++ = '\0';
|
||||||
while (isspace((int)*cp))
|
while (isspace((int)*cp))
|
||||||
cp++;
|
cp++;
|
||||||
@@ -1406,9 +1403,9 @@ beep(void)
|
|||||||
static void
|
static void
|
||||||
echo_char(int ch)
|
echo_char(int ch)
|
||||||
{
|
{
|
||||||
if (isprint(ch))
|
if (isprint(ch)) {
|
||||||
putchar(ch);
|
putchar(ch);
|
||||||
else {
|
} else {
|
||||||
putchar('^');
|
putchar('^');
|
||||||
putchar((ch + '@') & 0x7f);
|
putchar((ch + '@') & 0x7f);
|
||||||
}
|
}
|
||||||
|
7
input.c
7
input.c
@@ -524,9 +524,9 @@ nextchar(void)
|
|||||||
if (cip->i_num) {
|
if (cip->i_num) {
|
||||||
ch = chartoint(*cip->i_cp++);
|
ch = chartoint(*cip->i_cp++);
|
||||||
cip->i_num--;
|
cip->i_num--;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
ch = EOF;
|
ch = EOF;
|
||||||
|
}
|
||||||
} else if (cip->i_fp) { /* from file */
|
} else if (cip->i_fp) { /* from file */
|
||||||
ch = fgetc(cip->i_fp);
|
ch = fgetc(cip->i_fp);
|
||||||
} else if (!stdin_tty) { /* from file */
|
} else if (!stdin_tty) { /* from file */
|
||||||
@@ -908,6 +908,3 @@ addreadset(char *name, char *path, struct stat *sbuf)
|
|||||||
/* return index of the newly added entry */
|
/* return index of the newly added entry */
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* END CODE */
|
|
||||||
|
11
listfunc.c
11
listfunc.c
@@ -35,9 +35,9 @@ insertlistfirst(LIST *lp, VALUE *vp)
|
|||||||
|
|
||||||
ep = elemalloc();
|
ep = elemalloc();
|
||||||
copyvalue(vp, &ep->e_value);
|
copyvalue(vp, &ep->e_value);
|
||||||
if (lp->l_count == 0)
|
if (lp->l_count == 0) {
|
||||||
lp->l_last = ep;
|
lp->l_last = ep;
|
||||||
else {
|
} else {
|
||||||
lp->l_cacheindex++;
|
lp->l_cacheindex++;
|
||||||
lp->l_first->e_prev = ep;
|
lp->l_first->e_prev = ep;
|
||||||
ep->e_next = lp->l_first;
|
ep->e_next = lp->l_first;
|
||||||
@@ -61,9 +61,9 @@ insertlistlast(LIST *lp, VALUE *vp)
|
|||||||
|
|
||||||
ep = elemalloc();
|
ep = elemalloc();
|
||||||
copyvalue(vp, &ep->e_value);
|
copyvalue(vp, &ep->e_value);
|
||||||
if (lp->l_count == 0)
|
if (lp->l_count == 0) {
|
||||||
lp->l_first = ep;
|
lp->l_first = ep;
|
||||||
else {
|
} else {
|
||||||
lp->l_last->e_next = ep;
|
lp->l_last->e_next = ep;
|
||||||
ep->e_prev = lp->l_last;
|
ep->e_prev = lp->l_last;
|
||||||
}
|
}
|
||||||
@@ -246,8 +246,7 @@ listsegment(LIST *lp, long n1, long n2)
|
|||||||
insertlistlast(newlp, &ep->e_value);
|
insertlistlast(newlp, &ep->e_value);
|
||||||
ep = ep->e_next;
|
ep = ep->e_next;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
i = n1 - n2 + 1;
|
i = n1 - n2 + 1;
|
||||||
while(n2-- > 0 && ep)
|
while(n2-- > 0 && ep)
|
||||||
ep = ep->e_next;
|
ep = ep->e_next;
|
||||||
|
3
md5.c
3
md5.c
@@ -254,8 +254,7 @@ MD5Final(HASH *state)
|
|||||||
SWAP_B8_IN_B32(md5Ctx->data + i,
|
SWAP_B8_IN_B32(md5Ctx->data + i,
|
||||||
md5Ctx->data + i);
|
md5Ctx->data + i);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (count % 4) {
|
if (count % 4) {
|
||||||
math_error("This should not happen in MD5Final");
|
math_error("This should not happen in MD5Final");
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
|
6
obj.c
6
obj.c
@@ -150,11 +150,11 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3)
|
|||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
oip = &objectinfo[action];
|
oip = &objectinfo[action];
|
||||||
if (v1->v_type == V_OBJ)
|
if (v1->v_type == V_OBJ) {
|
||||||
oap = v1->v_obj->o_actions;
|
oap = v1->v_obj->o_actions;
|
||||||
else if (v2->v_type == V_OBJ)
|
} else if (v2->v_type == V_OBJ) {
|
||||||
oap = v2->v_obj->o_actions;
|
oap = v2->v_obj->o_actions;
|
||||||
else {
|
} else {
|
||||||
math_error("Object routine called with non-object");
|
math_error("Object routine called with non-object");
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
|
12
opcodes.c
12
opcodes.c
@@ -1441,8 +1441,7 @@ o_abs(void)
|
|||||||
if (v2->v_type == V_ADDR)
|
if (v2->v_type == V_ADDR)
|
||||||
v2 = v2->v_addr;
|
v2 = v2->v_addr;
|
||||||
if ((v1->v_type != V_NUM) || (v2->v_type != V_NUM) ||
|
if ((v1->v_type != V_NUM) || (v2->v_type != V_NUM) ||
|
||||||
!qispos(v2->v_num))
|
!qispos(v2->v_num)) {
|
||||||
{
|
|
||||||
absvalue(v1, v2, &tmp);
|
absvalue(v1, v2, &tmp);
|
||||||
freevalue(stack--);
|
freevalue(stack--);
|
||||||
freevalue(stack);
|
freevalue(stack);
|
||||||
@@ -1600,11 +1599,11 @@ o_bit (void)
|
|||||||
}
|
}
|
||||||
freevalue(stack--);
|
freevalue(stack--);
|
||||||
freevalue(stack);
|
freevalue(stack);
|
||||||
if (r > 1)
|
if (r > 1) {
|
||||||
*stack = error_value(E_BIT1);
|
*stack = error_value(E_BIT1);
|
||||||
else if (r < 0)
|
} else if (r < 0) {
|
||||||
stack->v_type = V_NULL;
|
stack->v_type = V_NULL;
|
||||||
else {
|
} else {
|
||||||
stack->v_type = V_NUM;
|
stack->v_type = V_NUM;
|
||||||
stack->v_num = itoq(r);
|
stack->v_num = itoq(r);
|
||||||
}
|
}
|
||||||
@@ -3937,6 +3936,3 @@ calclevel(void)
|
|||||||
{
|
{
|
||||||
return calc_depth - 1;
|
return calc_depth - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* END CODE */
|
|
||||||
|
50
qfunc.c
50
qfunc.c
@@ -303,35 +303,10 @@ qsqrt(NUMBER *q1, NUMBER *epsilon, long rnd)
|
|||||||
if (qiszero(q1))
|
if (qiszero(q1))
|
||||||
return qlink(&_qzero_);
|
return qlink(&_qzero_);
|
||||||
sign = (rnd & 64) != 0;
|
sign = (rnd & 64) != 0;
|
||||||
#if 0
|
|
||||||
if (qiszero(epsilon)) {
|
|
||||||
s1 = zesqrt(q1->num, &tmp1);
|
|
||||||
if (s1) {
|
|
||||||
if (qisint(q1)) {
|
|
||||||
r = qalloc();
|
|
||||||
tmp1.sign = sign;
|
|
||||||
r->num = tmp1;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
s2 = zesqrt(q1->den, &tmp2);
|
|
||||||
if (s2) {
|
|
||||||
r = qalloc();
|
|
||||||
tmp1.sign = sign;
|
|
||||||
r->num = tmp1;
|
|
||||||
r->den = tmp2;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
zfree(tmp2);
|
|
||||||
}
|
|
||||||
zfree(tmp1);
|
|
||||||
return qlink(&_qzero_);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (qiszero(epsilon)) {
|
if (qiszero(epsilon)) {
|
||||||
math_error("Zero epsilon for qsqrt");
|
math_error("Zero epsilon for qsqrt");
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
etemp = *epsilon;
|
etemp = *epsilon;
|
||||||
etemp.num.sign = 0;
|
etemp.num.sign = 0;
|
||||||
@@ -384,8 +359,7 @@ qsqrt(NUMBER *q1, NUMBER *epsilon, long rnd)
|
|||||||
zshift(tmp1, -1, &mul);
|
zshift(tmp1, -1, &mul);
|
||||||
up = (*tmp1.v & 1) ? s1 + s2 : -1;
|
up = (*tmp1.v & 1) ? s1 + s2 : -1;
|
||||||
zfree(tmp1);
|
zfree(tmp1);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
s1 = zquo(tmp2, divisor, &quo, 0);
|
s1 = zquo(tmp2, divisor, &quo, 0);
|
||||||
zfree(tmp2);
|
zfree(tmp2);
|
||||||
s2 = zsqrt(quo, &mul, 0);
|
s2 = zsqrt(quo, &mul, 0);
|
||||||
@@ -568,9 +542,9 @@ qilog10(NUMBER *q)
|
|||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Here if the number is less than one.
|
* Here if the number is less than one.
|
||||||
* If the number is the inverse of a power of ten, then the obvious answer
|
* If the number is the inverse of a power of ten, then the
|
||||||
* will be off by one. Subtracting one if the number is the inverse of an
|
* obvious answer will be off by one. Subtracting one if the
|
||||||
* integer will fix it.
|
* number is the inverse of an integer will fix it.
|
||||||
*/
|
*/
|
||||||
if (zisunit(tmp1))
|
if (zisunit(tmp1))
|
||||||
zsub(q->den, _one_, &tmp2);
|
zsub(q->den, _one_, &tmp2);
|
||||||
@@ -1095,8 +1069,7 @@ qcfappr(NUMBER *q, NUMBER *epsilon, long rnd)
|
|||||||
zfree(denbnd);
|
zfree(denbnd);
|
||||||
return qlink(q);
|
return qlink(q);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (rnd & 16)
|
if (rnd & 16)
|
||||||
epsilon1 = qscale(epsilon, -1);
|
epsilon1 = qscale(epsilon, -1);
|
||||||
else
|
else
|
||||||
@@ -1107,9 +1080,9 @@ qcfappr(NUMBER *q, NUMBER *epsilon, long rnd)
|
|||||||
zfree(tmp1);
|
zfree(tmp1);
|
||||||
qfree(epsilon1);
|
qfree(epsilon1);
|
||||||
}
|
}
|
||||||
if (rnd & 16 && !zistwo(q->den))
|
if (rnd & 16 && !zistwo(q->den)) {
|
||||||
s = 0;
|
s = 0;
|
||||||
else {
|
} else {
|
||||||
s = esign ? -1 : 1;
|
s = esign ? -1 : 1;
|
||||||
if (rnd & 1)
|
if (rnd & 1)
|
||||||
s = -s;
|
s = -s;
|
||||||
@@ -1164,8 +1137,7 @@ qcfappr(NUMBER *q, NUMBER *epsilon, long rnd)
|
|||||||
zfree(tmp1);
|
zfree(tmp1);
|
||||||
}
|
}
|
||||||
zfree(denbnd);
|
zfree(denbnd);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (s < 0) {
|
if (s < 0) {
|
||||||
zfree(tmp1);
|
zfree(tmp1);
|
||||||
zfree(tmp2);
|
zfree(tmp2);
|
||||||
@@ -1251,9 +1223,9 @@ qcfsim(NUMBER *q, long rnd)
|
|||||||
|
|
||||||
if (qiszero(q) && rnd & 26)
|
if (qiszero(q) && rnd & 26)
|
||||||
return qlink(&_qzero_);
|
return qlink(&_qzero_);
|
||||||
if (rnd & 24)
|
if (rnd & 24) {
|
||||||
s = q->num.sign;
|
s = q->num.sign;
|
||||||
else {
|
} else {
|
||||||
s = rnd & 1;
|
s = rnd & 1;
|
||||||
if (rnd & 2)
|
if (rnd & 2)
|
||||||
s ^= q->num.sign;
|
s ^= q->num.sign;
|
||||||
@@ -1558,5 +1530,3 @@ qprimetest(NUMBER *q1, NUMBER *q2, NUMBER *q3)
|
|||||||
}
|
}
|
||||||
return zprimetest(q1->num, ztoi(q2->num), q3->num);
|
return zprimetest(q1->num, ztoi(q2->num), q3->num);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* END CODE */
|
|
||||||
|
73
qio.c
73
qio.c
@@ -16,11 +16,6 @@
|
|||||||
#define PRINTF1(fmt, a1) math_fmt(fmt, a1)
|
#define PRINTF1(fmt, a1) math_fmt(fmt, a1)
|
||||||
#define PRINTF2(fmt, a1, a2) math_fmt(fmt, a1, a2)
|
#define PRINTF2(fmt, a1, a2) math_fmt(fmt, a1, a2)
|
||||||
|
|
||||||
#if 0
|
|
||||||
static long etoalen;
|
|
||||||
static char *etoabuf = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static long scalefactor;
|
static long scalefactor;
|
||||||
static ZVALUE scalenumber = { 0, 0, 0 };
|
static ZVALUE scalenumber = { 0, 0, 0 };
|
||||||
|
|
||||||
@@ -152,72 +147,6 @@ qprintf(char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* Read a number from the specified FILE stream (NULL means stdin).
|
|
||||||
* The number can be an integer, a fraction, a real number, an
|
|
||||||
* exponential number, or a hex, octal or binary number. Leading blanks
|
|
||||||
* are skipped. Illegal numbers return NULL. Unrecognized characters
|
|
||||||
* remain to be read on the line.
|
|
||||||
* q = qreadval(fp);
|
|
||||||
*
|
|
||||||
* given:
|
|
||||||
* fp file stream to read from (or NULL)
|
|
||||||
*/
|
|
||||||
NUMBER *
|
|
||||||
qreadval(FILE *fp)
|
|
||||||
{
|
|
||||||
NUMBER *r; /* returned number */
|
|
||||||
char *cp; /* current buffer location */
|
|
||||||
long savecc; /* characters saved in buffer */
|
|
||||||
long scancc; /* characters parsed correctly */
|
|
||||||
int ch; /* current character */
|
|
||||||
|
|
||||||
if (fp == NULL)
|
|
||||||
fp = stdin;
|
|
||||||
if (etoabuf == NULL) {
|
|
||||||
etoabuf = (char *)malloc(OUTBUFSIZE + 2);
|
|
||||||
if (etoabuf == NULL)
|
|
||||||
return NULL;
|
|
||||||
etoalen = OUTBUFSIZE;
|
|
||||||
}
|
|
||||||
cp = etoabuf;
|
|
||||||
ch = fgetc(fp);
|
|
||||||
while ((ch == ' ') || (ch == '\t'))
|
|
||||||
ch = fgetc(fp);
|
|
||||||
savecc = 0;
|
|
||||||
for (;;) {
|
|
||||||
if (ch == EOF)
|
|
||||||
return NULL;
|
|
||||||
if (savecc >= etoalen)
|
|
||||||
{
|
|
||||||
cp = (char *)realloc(etoabuf, etoalen + OUTBUFSIZE + 2);
|
|
||||||
if (cp == NULL)
|
|
||||||
return NULL;
|
|
||||||
etoabuf = cp;
|
|
||||||
etoalen += OUTBUFSIZE;
|
|
||||||
cp += savecc;
|
|
||||||
}
|
|
||||||
*cp++ = (char)ch;
|
|
||||||
*cp = '\0';
|
|
||||||
scancc = qparse(etoabuf, QPF_SLASH);
|
|
||||||
if (scancc != ++savecc)
|
|
||||||
break;
|
|
||||||
ch = fgetc(fp);
|
|
||||||
}
|
|
||||||
ungetc(ch, fp);
|
|
||||||
if (scancc < 0)
|
|
||||||
return NULL;
|
|
||||||
r = str2q(etoabuf);
|
|
||||||
if (ziszero(r->den)) {
|
|
||||||
qfree(r);
|
|
||||||
r = NULL;
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print a number in the specified output mode.
|
* Print a number in the specified output mode.
|
||||||
* If MODE_DEFAULT is given, then the default output mode is used.
|
* If MODE_DEFAULT is given, then the default output mode is used.
|
||||||
@@ -734,5 +663,3 @@ fitprint(NUMBER *q, long width)
|
|||||||
PUTCHAR('/');
|
PUTCHAR('/');
|
||||||
fitzprint(q->den, dendigits, width2);
|
fitzprint(q->den, dendigits, width2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* END CODE */
|
|
||||||
|
55
qmath.c
55
qmath.c
@@ -573,9 +573,9 @@ qquo(NUMBER *q1, NUMBER *q2, long rnd)
|
|||||||
|
|
||||||
if (qiszero(q1) || qiszero(q2))
|
if (qiszero(q1) || qiszero(q2))
|
||||||
return qlink(&_qzero_);
|
return qlink(&_qzero_);
|
||||||
if (qisint(q1) && qisint(q2))
|
if (qisint(q1) && qisint(q2)) {
|
||||||
zquo(q1->num, q2->num, &tmp, rnd);
|
zquo(q1->num, q2->num, &tmp, rnd);
|
||||||
else {
|
} else {
|
||||||
zmul(q1->num, q2->den, &tmp1);
|
zmul(q1->num, q2->den, &tmp1);
|
||||||
zmul(q2->num, q1->den, &tmp2);
|
zmul(q2->num, q1->den, &tmp2);
|
||||||
zquo(tmp1, tmp2, &tmp, rnd);
|
zquo(tmp1, tmp2, &tmp, rnd);
|
||||||
@@ -1132,26 +1132,6 @@ qtenpow(long n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* Test to see if the specified bit of a number is on (counted from zero).
|
|
||||||
* Returns TRUE if the bit is set, or FALSE if it is not.
|
|
||||||
* i = qbittest(q, n);
|
|
||||||
*/
|
|
||||||
BOOL
|
|
||||||
qbittest(NUMBER *q, long n)
|
|
||||||
{
|
|
||||||
int x, y;
|
|
||||||
|
|
||||||
if ((n < 0) || (n >= (q->num.len * BASEB)))
|
|
||||||
return FALSE;
|
|
||||||
x = q->num.v[n / BASEB];
|
|
||||||
y = (1 << (n % BASEB));
|
|
||||||
return ((x & y) != 0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the precision of a number (usually for examining an epsilon value).
|
* Return the precision of a number (usually for examining an epsilon value).
|
||||||
* The precision of a number e less than 1 is the positive
|
* The precision of a number e less than 1 is the positive
|
||||||
@@ -1173,23 +1153,6 @@ qprecision(NUMBER *q)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* Return an integer indicating the sign of a number (-1, 0, or 1).
|
|
||||||
* i = qtst(q);
|
|
||||||
*/
|
|
||||||
FLAG
|
|
||||||
qtest(NUMBER *q)
|
|
||||||
{
|
|
||||||
if (!ztest(q->num))
|
|
||||||
return 0;
|
|
||||||
if (q->num.sign)
|
|
||||||
return -1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determine whether or not one number exactly divides another one.
|
* Determine whether or not one number exactly divides another one.
|
||||||
* Returns TRUE if the first number is an integer multiple of the second one.
|
* Returns TRUE if the first number is an integer multiple of the second one.
|
||||||
@@ -1246,19 +1209,19 @@ qrel(NUMBER *q1, NUMBER *q2)
|
|||||||
/*
|
/*
|
||||||
* Quick check failed, must actually do the full comparison.
|
* Quick check failed, must actually do the full comparison.
|
||||||
*/
|
*/
|
||||||
if (zisunit(q2->den))
|
if (zisunit(q2->den)) {
|
||||||
z1 = q1->num;
|
z1 = q1->num;
|
||||||
else if (zisone(q1->num))
|
} else if (zisone(q1->num)) {
|
||||||
z1 = q2->den;
|
z1 = q2->den;
|
||||||
else {
|
} else {
|
||||||
z1f = 1;
|
z1f = 1;
|
||||||
zmul(q1->num, q2->den, &z1);
|
zmul(q1->num, q2->den, &z1);
|
||||||
}
|
}
|
||||||
if (zisunit(q1->den))
|
if (zisunit(q1->den)) {
|
||||||
z2 = q2->num;
|
z2 = q2->num;
|
||||||
else if (zisone(q2->num))
|
} else if (zisone(q2->num)) {
|
||||||
z2 = q1->den;
|
z2 = q1->den;
|
||||||
else {
|
} else {
|
||||||
z2f = 1;
|
z2f = 1;
|
||||||
zmul(q2->num, q1->den, &z2);
|
zmul(q2->num, q1->den, &z2);
|
||||||
}
|
}
|
||||||
@@ -1470,5 +1433,3 @@ shownumbers(void)
|
|||||||
}
|
}
|
||||||
printf("\nNumber: %ld\n", count);
|
printf("\nNumber: %ld\n", count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* END CODE */
|
|
||||||
|
11
qmath.h
11
qmath.h
@@ -148,17 +148,6 @@ extern void setepsilon(NUMBER *q);
|
|||||||
extern NUMBER *qbitvalue(long i);
|
extern NUMBER *qbitvalue(long i);
|
||||||
extern NUMBER *qtenpow(long i);
|
extern NUMBER *qtenpow(long i);
|
||||||
|
|
||||||
#if 0
|
|
||||||
extern NUMBER *qmulmod(NUMBER *q1, NUMBER *q2, NUMBER *q3);
|
|
||||||
extern NUMBER *qsquaremod(NUMBER *q1, NUMBER *q2);
|
|
||||||
extern NUMBER *qaddmod(NUMBER *q1, NUMBER *q2, NUMBER *q3);
|
|
||||||
extern NUMBER *qsubmod(NUMBER *q1, NUMBER *q2, NUMBER *q3);
|
|
||||||
extern NUMBER *qreadval(FILE *fp);
|
|
||||||
extern NUMBER *qnegmod(NUMBER *q1, NUMBER *q2);
|
|
||||||
extern BOOL qbittest(NUMBER *q, long i);
|
|
||||||
extern FLAG qtest(NUMBER *q);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Transcendental functions. These all take an epsilon argument to
|
* Transcendental functions. These all take an epsilon argument to
|
||||||
|
120
qmod.c
120
qmod.c
@@ -108,8 +108,7 @@ qquomod(NUMBER *q1, NUMBER *q2, NUMBER **retqdiv, NUMBER **retqmod)
|
|||||||
if (qiszero(q2)) { /* zero modulus case */
|
if (qiszero(q2)) { /* zero modulus case */
|
||||||
qq = qlink(&_qzero_);
|
qq = qlink(&_qzero_);
|
||||||
qm = qlink(q1);
|
qm = qlink(q1);
|
||||||
}
|
} else if (qisint(q1) && qisint(q2)) { /* integer case */
|
||||||
else if (qisint(q1) && qisint(q2)) { /* integer case */
|
|
||||||
zdiv(q1->num, q2->num, &tmp1, &tmp2, conf->quomod);
|
zdiv(q1->num, q2->num, &tmp1, &tmp2, conf->quomod);
|
||||||
if (ziszero(tmp1)) {
|
if (ziszero(tmp1)) {
|
||||||
zfree(tmp1);
|
zfree(tmp1);
|
||||||
@@ -127,8 +126,7 @@ qquomod(NUMBER *q1, NUMBER *q2, NUMBER **retqdiv, NUMBER **retqmod)
|
|||||||
qm->num = tmp2;
|
qm->num = tmp2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else { /* fractional case */
|
||||||
else { /* fractional case */
|
|
||||||
zmul(q1->num, q2->den, &tmp1);
|
zmul(q1->num, q2->den, &tmp1);
|
||||||
zmul(q2->num, q1->den, &tmp2);
|
zmul(q2->num, q1->den, &tmp2);
|
||||||
zdiv(tmp1, tmp2, &tmp3, &tmp4, conf->quomod);
|
zdiv(tmp1, tmp2, &tmp3, &tmp4, conf->quomod);
|
||||||
@@ -160,118 +158,6 @@ qquomod(NUMBER *q1, NUMBER *q2, NUMBER **retqdiv, NUMBER **retqmod)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* Return the product of two integers modulo a third integer.
|
|
||||||
* The result is in the range 0 to q3 - 1 inclusive.
|
|
||||||
* q4 = (q1 * q2) mod q3.
|
|
||||||
*/
|
|
||||||
NUMBER *
|
|
||||||
qmulmod(NUMBER *q1, NUMBER *q2, NUMBER *q3)
|
|
||||||
{
|
|
||||||
NUMBER *q;
|
|
||||||
|
|
||||||
if (qisneg(q3) || qiszero(q3))
|
|
||||||
math_error("Non-positive modulus");
|
|
||||||
if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3))
|
|
||||||
math_error("Non-integers for qmulmod");
|
|
||||||
if (qiszero(q1) || qiszero(q2) || qisunit(q3))
|
|
||||||
return qlink(&_qzero_);
|
|
||||||
q = qalloc();
|
|
||||||
zmulmod(q1->num, q2->num, q3->num, &q->num);
|
|
||||||
return q;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Return the square of an integer modulo another integer.
|
|
||||||
* The result is in the range 0 to q2 - 1 inclusive.
|
|
||||||
* q2 = (q1^2) mod q2.
|
|
||||||
*/
|
|
||||||
NUMBER *
|
|
||||||
qsquaremod(NUMBER *q1, NUMBER *q2)
|
|
||||||
{
|
|
||||||
NUMBER *q;
|
|
||||||
|
|
||||||
if (qisneg(q2) || qiszero(q2))
|
|
||||||
math_error("Non-positive modulus");
|
|
||||||
if (qisfrac(q1) || qisfrac(q2))
|
|
||||||
math_error("Non-integers for qsquaremod");
|
|
||||||
if (qiszero(q1) || qisunit(q2))
|
|
||||||
return qlink(&_qzero_);
|
|
||||||
if (qisunit(q1))
|
|
||||||
return qlink(&_qone_);
|
|
||||||
q = qalloc();
|
|
||||||
zsquaremod(q1->num, q2->num, &q->num);
|
|
||||||
return q;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Return the sum of two integers modulo a third integer.
|
|
||||||
* The result is in the range 0 to q3 - 1 inclusive.
|
|
||||||
* q4 = (q1 + q2) mod q3.
|
|
||||||
*/
|
|
||||||
NUMBER *
|
|
||||||
qaddmod(NUMBER *q1, NUMBER *q2, NUMBER *q3)
|
|
||||||
{
|
|
||||||
NUMBER *q;
|
|
||||||
|
|
||||||
if (qisneg(q3) || qiszero(q3))
|
|
||||||
math_error("Non-positive modulus");
|
|
||||||
if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3))
|
|
||||||
math_error("Non-integers for qaddmod");
|
|
||||||
q = qalloc();
|
|
||||||
zaddmod(q1->num, q2->num, q3->num, &q->num);
|
|
||||||
return q;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Return the difference of two integers modulo a third integer.
|
|
||||||
* The result is in the range 0 to q3 - 1 inclusive.
|
|
||||||
* q4 = (q1 - q2) mod q3.
|
|
||||||
*/
|
|
||||||
NUMBER *
|
|
||||||
qsubmod(NUMBER *q1, NUMBER *q2, NUMBER *q3)
|
|
||||||
{
|
|
||||||
NUMBER *q;
|
|
||||||
|
|
||||||
if (qisneg(q3) || qiszero(q3))
|
|
||||||
math_error("Non-positive modulus");
|
|
||||||
if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3))
|
|
||||||
math_error("Non-integers for qsubmod");
|
|
||||||
if (q1 == q2)
|
|
||||||
return qlink(&_qzero_);
|
|
||||||
q = qalloc();
|
|
||||||
zsubmod(q1->num, q2->num, q3->num, &q->num);
|
|
||||||
return q;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Return the negative of an integer modulo another integer.
|
|
||||||
* The result is in the range 0 to q2 - 1 inclusive.
|
|
||||||
* q2 = (-q1) mod q2.
|
|
||||||
*/
|
|
||||||
NUMBER *
|
|
||||||
qnegmod(NUMBER *q1, NUMBER *q2)
|
|
||||||
{
|
|
||||||
NUMBER *q;
|
|
||||||
|
|
||||||
if (qisneg(q2) || qiszero(q2))
|
|
||||||
math_error("Non-positive modulus");
|
|
||||||
if (qisfrac(q1) || qisfrac(q2))
|
|
||||||
math_error("Non-integers for qnegmod");
|
|
||||||
if (qiszero(q1) || qisunit(q2))
|
|
||||||
return qlink(&_qzero_);
|
|
||||||
q = qalloc();
|
|
||||||
znegmod(q1->num, q2->num, &q->num);
|
|
||||||
return q;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return whether or not two integers are congruent modulo a third integer.
|
* Return whether or not two integers are congruent modulo a third integer.
|
||||||
* Returns TRUE if the numbers are not congruent, and FALSE if they are.
|
* Returns TRUE if the numbers are not congruent, and FALSE if they are.
|
||||||
@@ -521,5 +407,3 @@ freeredcdata(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* END CODE */
|
|
||||||
|
43
qtrans.c
43
qtrans.c
@@ -112,9 +112,9 @@ qsincos(NUMBER *q, long bitnum, NUMBER **vs, NUMBER **vc)
|
|||||||
if (m > h) {
|
if (m > h) {
|
||||||
zshift(cossum, -h, &qtmp1->num);
|
zshift(cossum, -h, &qtmp1->num);
|
||||||
zbitvalue(m - h, &qtmp1->den);
|
zbitvalue(m - h, &qtmp1->den);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
zshift(cossum, - m, &qtmp1->num);
|
zshift(cossum, - m, &qtmp1->num);
|
||||||
|
}
|
||||||
zfree(cossum);
|
zfree(cossum);
|
||||||
*vc = qtmp1;
|
*vc = qtmp1;
|
||||||
h = zlowbit(sinsum);
|
h = zlowbit(sinsum);
|
||||||
@@ -122,9 +122,9 @@ qsincos(NUMBER *q, long bitnum, NUMBER **vs, NUMBER **vc)
|
|||||||
if (m > h) {
|
if (m > h) {
|
||||||
zshift(sinsum, -h, &qtmp2->num);
|
zshift(sinsum, -h, &qtmp2->num);
|
||||||
zbitvalue(m - h, &qtmp2->den);
|
zbitvalue(m - h, &qtmp2->den);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
zshift(sinsum, -m, &qtmp2->num);
|
zshift(sinsum, -m, &qtmp2->num);
|
||||||
|
}
|
||||||
zfree(sinsum);
|
zfree(sinsum);
|
||||||
*vs = qtmp2;
|
*vs = qtmp2;
|
||||||
return;
|
return;
|
||||||
@@ -378,8 +378,7 @@ qasin(NUMBER *q, NUMBER *epsilon)
|
|||||||
epsilon1 = qscale(epsilon, 1L);
|
epsilon1 = qscale(epsilon, 1L);
|
||||||
qtmp2 = qpi(epsilon1);
|
qtmp2 = qpi(epsilon1);
|
||||||
qtmp1 = qscale(qtmp2, -1L);
|
qtmp1 = qscale(qtmp2, -1L);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
epsilon1 = qscale(epsilon, -2L);
|
epsilon1 = qscale(epsilon, -2L);
|
||||||
qtmp1 = qalloc();
|
qtmp1 = qalloc();
|
||||||
zsquare(q->num, &qtmp1->num);
|
zsquare(q->num, &qtmp1->num);
|
||||||
@@ -528,9 +527,9 @@ qatan(NUMBER *q, NUMBER *epsilon)
|
|||||||
if (k) {
|
if (k) {
|
||||||
zshift(sum, -k, &qtmp->num);
|
zshift(sum, -k, &qtmp->num);
|
||||||
zfree(sum);
|
zfree(sum);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
qtmp->num = sum;
|
qtmp->num = sum;
|
||||||
|
}
|
||||||
zbitvalue(m - 4 - k, &qtmp->den);
|
zbitvalue(m - 4 - k, &qtmp->den);
|
||||||
res = qmappr(qtmp, epsilon, 24L);
|
res = qmappr(qtmp, epsilon, 24L);
|
||||||
qfree(qtmp);
|
qfree(qtmp);
|
||||||
@@ -842,9 +841,9 @@ qexprel(NUMBER *q, long bitnum)
|
|||||||
if (zrel(ztmp1, B) >= 0) {
|
if (zrel(ztmp1, B) >= 0) {
|
||||||
zshift(ztmp1, -m - 1, &sum);
|
zshift(ztmp1, -m - 1, &sum);
|
||||||
k++;
|
k++;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
zshift(ztmp1, -m, &sum);
|
zshift(ztmp1, -m, &sum);
|
||||||
|
}
|
||||||
zfree(ztmp1);
|
zfree(ztmp1);
|
||||||
}
|
}
|
||||||
zfree(B);
|
zfree(B);
|
||||||
@@ -957,8 +956,7 @@ qln(NUMBER *q, NUMBER *epsilon)
|
|||||||
if (k) {
|
if (k) {
|
||||||
zshift(sum, -k, &qtmp->num);
|
zshift(sum, -k, &qtmp->num);
|
||||||
zfree(sum);
|
zfree(sum);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
qtmp->num = sum;
|
qtmp->num = sum;
|
||||||
}
|
}
|
||||||
zbitvalue(m - k - n, &qtmp->den);
|
zbitvalue(m - k - n, &qtmp->den);
|
||||||
@@ -1003,8 +1001,7 @@ qpower(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
|
|||||||
if (zrel(q1->num, q1->den) < 0) {
|
if (zrel(q1->num, q1->den) < 0) {
|
||||||
q1tmp = qinv(q1);
|
q1tmp = qinv(q1);
|
||||||
q2tmp = qneg(q2);
|
q2tmp = qneg(q2);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
q1tmp = qlink(q1);
|
q1tmp = qlink(q1);
|
||||||
q2tmp = qlink(q2);
|
q2tmp = qlink(q2);
|
||||||
}
|
}
|
||||||
@@ -1031,8 +1028,7 @@ qpower(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
|
|||||||
tmp2 = qmul(tmp1, &_qlge_);
|
tmp2 = qmul(tmp1, &_qlge_);
|
||||||
m = qtoi(tmp2);
|
m = qtoi(tmp2);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (m > 0) {
|
if (m > 0) {
|
||||||
tmp1 = itoq(m + 1);
|
tmp1 = itoq(m + 1);
|
||||||
tmp2 = qmul(tmp1, q2tmp);
|
tmp2 = qmul(tmp1, q2tmp);
|
||||||
@@ -1070,9 +1066,9 @@ qpower(NUMBER *q1, NUMBER *q2, NUMBER *epsilon)
|
|||||||
tmp2 = qexprel(tmp1, m - n + 3);
|
tmp2 = qexprel(tmp1, m - n + 3);
|
||||||
qfree(tmp1);
|
qfree(tmp1);
|
||||||
tmp1 = qinv(tmp2);
|
tmp1 = qinv(tmp2);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
tmp1 = qexprel(tmp2, m - n + 3) ;
|
tmp1 = qexprel(tmp2, m - n + 3) ;
|
||||||
|
}
|
||||||
qfree(tmp2);
|
qfree(tmp2);
|
||||||
tmp2 = qmappr(tmp1, epsilon, 24L);
|
tmp2 = qmappr(tmp1, epsilon, 24L);
|
||||||
qfree(tmp1);
|
qfree(tmp1);
|
||||||
@@ -1240,9 +1236,9 @@ qcoth(NUMBER *q, NUMBER *epsilon)
|
|||||||
tmp1 = qmul(&_qlge_, tmp2);
|
tmp1 = qmul(&_qlge_, tmp2);
|
||||||
k = qtoi(tmp1);
|
k = qtoi(tmp1);
|
||||||
qfree(tmp1);
|
qfree(tmp1);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
k = 2 * k;
|
k = 2 * k;
|
||||||
|
}
|
||||||
k = 4 - k - n;
|
k = 4 - k - n;
|
||||||
if (k < 4)
|
if (k < 4)
|
||||||
k = 4;
|
k = 4;
|
||||||
@@ -1333,9 +1329,9 @@ qcsch(NUMBER *q, NUMBER *epsilon)
|
|||||||
tmp2 = qmul(&_qlge_, tmp1);
|
tmp2 = qmul(&_qlge_, tmp1);
|
||||||
k = qtoi(tmp2);
|
k = qtoi(tmp2);
|
||||||
qfree(tmp2);
|
qfree(tmp2);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
k = 2 * qilog2(tmp1);
|
k = 2 * qilog2(tmp1);
|
||||||
|
}
|
||||||
if (k + n >= 1) {
|
if (k + n >= 1) {
|
||||||
qfree(tmp1);
|
qfree(tmp1);
|
||||||
return qlink(&_qzero_);
|
return qlink(&_qzero_);
|
||||||
@@ -1518,6 +1514,3 @@ qacoth(NUMBER *q, NUMBER *epsilon)
|
|||||||
qfree(tmp);
|
qfree(tmp);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* END CODE */
|
|
||||||
|
3
shs.c
3
shs.c
@@ -380,8 +380,7 @@ shsFinal(HASH *state)
|
|||||||
for (i=0; i < SHS_CHUNKWORDS; ++i) {
|
for (i=0; i < SHS_CHUNKWORDS; ++i) {
|
||||||
SWAP_B8_IN_B32(dig->data+i, dig->data+i);
|
SWAP_B8_IN_B32(dig->data+i, dig->data+i);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (count % 4) {
|
if (count % 4) {
|
||||||
math_error("This should not happen in shsFinal");
|
math_error("This should not happen in shsFinal");
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
|
3
shs1.c
3
shs1.c
@@ -357,8 +357,7 @@ shs1Final(HASH *state)
|
|||||||
for (i=0; i < SHS1_CHUNKWORDS; ++i) {
|
for (i=0; i < SHS1_CHUNKWORDS; ++i) {
|
||||||
SWAP_B8_IN_B32(dig->data+i, dig->data+i);
|
SWAP_B8_IN_B32(dig->data+i, dig->data+i);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (count % 4) {
|
if (count % 4) {
|
||||||
math_error("This should not happen in shs1Final");
|
math_error("This should not happen in shs1Final");
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
|
9
string.c
9
string.c
@@ -586,8 +586,7 @@ stringsegment(STRING *s1, long n1, long n2)
|
|||||||
if (n1 >= n2) {
|
if (n1 >= n2) {
|
||||||
while (len-- > 0)
|
while (len-- > 0)
|
||||||
*c++ = *c1--;
|
*c++ = *c1--;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
while (len-- > 0)
|
while (len-- > 0)
|
||||||
*c++ = *c1++;
|
*c++ = *c1++;
|
||||||
}
|
}
|
||||||
@@ -640,8 +639,7 @@ stringshift(STRING *s1, long n)
|
|||||||
*--c = ((unsigned char) *--c1 >> j) | ch;
|
*--c = ((unsigned char) *--c1 >> j) | ch;
|
||||||
ch = (unsigned char) *c1 << k;
|
ch = (unsigned char) *c1 << k;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
while (i-- > 0)
|
while (i-- > 0)
|
||||||
*c++ = '\0';
|
*c++ = '\0';
|
||||||
i = len - n;
|
i = len - n;
|
||||||
@@ -1392,6 +1390,3 @@ showliterals(void)
|
|||||||
}
|
}
|
||||||
printf("\nNumber: %ld\n", count);
|
printf("\nNumber: %ld\n", count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* END CODE */
|
|
||||||
|
8
value.c
8
value.c
@@ -1542,18 +1542,18 @@ sqrtvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres)
|
|||||||
copyvalue(v1, vres);
|
copyvalue(v1, vres);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (v2->v_type == V_NULL)
|
if (v2->v_type == V_NULL) {
|
||||||
q = conf->epsilon;
|
q = conf->epsilon;
|
||||||
else {
|
} else {
|
||||||
if (v2->v_type != V_NUM || qiszero(v2->v_num)) {
|
if (v2->v_type != V_NUM || qiszero(v2->v_num)) {
|
||||||
*vres = error_value(E_SQRT2);
|
*vres = error_value(E_SQRT2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
q = v2->v_num;
|
q = v2->v_num;
|
||||||
}
|
}
|
||||||
if (v3->v_type == V_NULL)
|
if (v3->v_type == V_NULL) {
|
||||||
R = conf->sqrt;
|
R = conf->sqrt;
|
||||||
else {
|
} else {
|
||||||
if (v3->v_type != V_NUM || qisfrac(v3->v_num)) {
|
if (v3->v_type != V_NUM || qisfrac(v3->v_num)) {
|
||||||
*vres = error_value(E_SQRT3);
|
*vres = error_value(E_SQRT3);
|
||||||
return;
|
return;
|
||||||
|
@@ -18,7 +18,7 @@ static char *program;
|
|||||||
#define MAJOR_VER 2 /* major version */
|
#define MAJOR_VER 2 /* major version */
|
||||||
#define MINOR_VER 11 /* minor version */
|
#define MINOR_VER 11 /* minor version */
|
||||||
#define MAJOR_PATCH 0 /* patch level or 0 if no patch */
|
#define MAJOR_PATCH 0 /* patch level or 0 if no patch */
|
||||||
#define MINOR_PATCH "9.4.5" /* test number or empty string if no patch */
|
#define MINOR_PATCH "10" /* test number or empty string if no patch */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* calc version constants
|
* calc version constants
|
||||||
|
81
zfunc.c
81
zfunc.c
@@ -611,61 +611,6 @@ zmodinv(ZVALUE u, ZVALUE v, ZVALUE *res)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* Approximate the quotient of two integers by another set of smaller
|
|
||||||
* integers. This uses continued fractions to determine the smaller set.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
zapprox(ZVALUE z1, ZVALUE z2, ZVALUE *res1, ZVALUE *res2)
|
|
||||||
{
|
|
||||||
int sign;
|
|
||||||
ZVALUE u1, v1, u3, v3, q, t1, t2, t3;
|
|
||||||
|
|
||||||
sign = ((z1.sign != 0) ^ (z2.sign != 0));
|
|
||||||
z1.sign = 0;
|
|
||||||
z2.sign = 0;
|
|
||||||
v3 = z2;
|
|
||||||
u3 = z1;
|
|
||||||
u1 = _one_;
|
|
||||||
v1 = _zero_;
|
|
||||||
while (!ziszero(v3)) {
|
|
||||||
zdiv(u3, v3, &q, &t1, 0);
|
|
||||||
zmul(v1, q, &t2);
|
|
||||||
zsub(u1, t2, &t3);
|
|
||||||
zfree(q);
|
|
||||||
zfree(t2);
|
|
||||||
zfree(u1);
|
|
||||||
if ((u3.v != z1.v) && (u3.v != z2.v))
|
|
||||||
zfree(u3);
|
|
||||||
u1 = v1;
|
|
||||||
u3 = v3;
|
|
||||||
v1 = t3;
|
|
||||||
v3 = t1;
|
|
||||||
}
|
|
||||||
if (!zisunit(u3)) {
|
|
||||||
math_error("Non-relativly prime numbers for approx");
|
|
||||||
/*NOTREACHED*/
|
|
||||||
}
|
|
||||||
if ((u3.v != z1.v) && (u3.v != z2.v))
|
|
||||||
zfree(u3);
|
|
||||||
if ((v3.v != z1.v) && (v3.v != z2.v))
|
|
||||||
zfree(v3);
|
|
||||||
zfree(v1);
|
|
||||||
zmul(u1, z1, &t1);
|
|
||||||
zsub(t1, _one_, &t2);
|
|
||||||
zfree(t1);
|
|
||||||
zquo(t2, z2, &t1, 0);
|
|
||||||
zfree(t2);
|
|
||||||
u1.sign = (BOOL)sign;
|
|
||||||
t1.sign = 0;
|
|
||||||
*res1 = t1;
|
|
||||||
*res2 = u1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compute the greatest common divisor of a pair of integers.
|
* Compute the greatest common divisor of a pair of integers.
|
||||||
*/
|
*/
|
||||||
@@ -784,8 +729,9 @@ zgcd(ZVALUE z1, ZVALUE z2, ZVALUE *res)
|
|||||||
*a++ = (HALF) f;
|
*a++ = (HALF) f;
|
||||||
}
|
}
|
||||||
if (f >>= BASEB) {len++; *a = (HALF) f;}
|
if (f >>= BASEB) {len++; *a = (HALF) f;}
|
||||||
|
} else {
|
||||||
|
memcpy(gcd.v + o, b0, n * sizeof(HALF));
|
||||||
}
|
}
|
||||||
else memcpy(gcd.v + o, b0, n * sizeof(HALF));
|
|
||||||
gcd.len = len;
|
gcd.len = len;
|
||||||
gcd.sign = 0;
|
gcd.sign = 0;
|
||||||
freeh(A);
|
freeh(A);
|
||||||
@@ -962,9 +908,12 @@ zgcd(ZVALUE z1, ZVALUE z2, ZVALUE *res)
|
|||||||
*a++ = (HALF) f;
|
*a++ = (HALF) f;
|
||||||
f >>= BASEB;
|
f >>= BASEB;
|
||||||
}
|
}
|
||||||
if (f) {len++; *a = (HALF) f;}
|
if (f) {
|
||||||
|
len++; *a = (HALF) f;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
memcpy(gcd.v + o, b0, n * sizeof(HALF));
|
||||||
}
|
}
|
||||||
else memcpy(gcd.v + o, b0, n * sizeof(HALF));
|
|
||||||
gcd.len = len;
|
gcd.len = len;
|
||||||
gcd.sign = 0;
|
gcd.sign = 0;
|
||||||
freeh(A);
|
freeh(A);
|
||||||
@@ -1535,8 +1484,7 @@ zsqrt(ZVALUE z, ZVALUE *dest, long rnd)
|
|||||||
f = A[1];
|
f = A[1];
|
||||||
g = (FULL) A[0] << (j + BASEB);
|
g = (FULL) A[0] << (j + BASEB);
|
||||||
d = e = topbit = (FULL)1 << (k - 1);
|
d = e = topbit = (FULL)1 << (k - 1);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (j)
|
if (j)
|
||||||
f = (FULL) A[m-1] << (j + BASEB) | (FULL) A[m-2] << j |
|
f = (FULL) A[m-1] << (j + BASEB) | (FULL) A[m-2] << j |
|
||||||
A[m-3] >> k;
|
A[m-3] >> k;
|
||||||
@@ -1609,8 +1557,7 @@ zsqrt(ZVALUE z, ZVALUE *dest, long rnd)
|
|||||||
A[m1 - 4] = (HALF)f;
|
A[m1 - 4] = (HALF)f;
|
||||||
m = m1 - 2;
|
m = m1 - 2;
|
||||||
k1 = k + 1;
|
k1 = k + 1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
A[m1 - 1] = 1;
|
A[m1 - 1] = 1;
|
||||||
A[m1 - 2] = (HALF)(e >> (BASEB - 1));
|
A[m1 - 2] = (HALF)(e >> (BASEB - 1));
|
||||||
A[m1 - 3] = ((HALF)(e << 1) | (HALF)(s > 0));
|
A[m1 - 3] = ((HALF)(e << 1) | (HALF)(s > 0));
|
||||||
@@ -1667,9 +1614,9 @@ zsqrt(ZVALUE z, ZVALUE *dest, long rnd)
|
|||||||
a[1] |= 1;
|
a[1] |= 1;
|
||||||
}
|
}
|
||||||
*a = ((HALF)(x << 1) | (HALF)(u > 0));
|
*a = ((HALF)(x << 1) | (HALF)(u > 0));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
*a = u;
|
*a = u;
|
||||||
|
}
|
||||||
m--;
|
m--;
|
||||||
if (*--a == u) {
|
if (*--a == u) {
|
||||||
while (m > 1 && *--a == u)
|
while (m > 1 && *--a == u)
|
||||||
@@ -1742,9 +1689,9 @@ done: if (s == 0) {
|
|||||||
n++;
|
n++;
|
||||||
*a = 1;
|
*a = 1;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
remsign = 1;
|
remsign = 1;
|
||||||
|
}
|
||||||
sqrt.v = alloc(n);
|
sqrt.v = alloc(n);
|
||||||
sqrt.len = n;
|
sqrt.len = n;
|
||||||
sqrt.sign = 0;
|
sqrt.sign = 0;
|
||||||
@@ -1903,5 +1850,3 @@ zissquare(ZVALUE z)
|
|||||||
zfree(tmp);
|
zfree(tmp);
|
||||||
return (n ? TRUE : FALSE);
|
return (n ? TRUE : FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* END CODE */
|
|
||||||
|
45
zmath.c
45
zmath.c
@@ -816,9 +816,9 @@ done: while (m > 0 && A[m - 1] == 0)
|
|||||||
val = rem->sign ? -1 : 1;
|
val = rem->sign ? -1 : 1;
|
||||||
if (a1[len - 1] == 0)
|
if (a1[len - 1] == 0)
|
||||||
len--;
|
len--;
|
||||||
if (len == 0)
|
if (len == 0) {
|
||||||
*quo = _zero_;
|
*quo = _zero_;
|
||||||
else {
|
} else {
|
||||||
quo->len = len;
|
quo->len = len;
|
||||||
quo->v = alloc(len);
|
quo->v = alloc(len);
|
||||||
memcpy(quo->v, a1, len * sizeof(HALF));
|
memcpy(quo->v, a1, len * sizeof(HALF));
|
||||||
@@ -1318,8 +1318,7 @@ zxor(ZVALUE z1, ZVALUE z2, ZVALUE *res)
|
|||||||
j = z1.len;
|
j = z1.len;
|
||||||
h1 = z2.v;
|
h1 = z2.v;
|
||||||
h2 = z1.v;
|
h2 = z1.v;
|
||||||
}
|
} else if (z1.len == z2.len) {
|
||||||
else if (z1.len == z2.len) {
|
|
||||||
while (len > 1 && z1.v[len-1] == z2.v[len-1])
|
while (len > 1 && z1.v[len-1] == z2.v[len-1])
|
||||||
len--;
|
len--;
|
||||||
j = len;
|
j = len;
|
||||||
@@ -1353,8 +1352,7 @@ zandnot(ZVALUE z1, ZVALUE z2, ZVALUE *res)
|
|||||||
len--;
|
len--;
|
||||||
j = len;
|
j = len;
|
||||||
k = 0;
|
k = 0;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
j = z2.len;
|
j = z2.len;
|
||||||
k = len - z2.len;
|
k = len - z2.len;
|
||||||
}
|
}
|
||||||
@@ -1505,41 +1503,6 @@ zhighbit(ZVALUE z)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* Reverse the bits of a particular range of bits of a number.
|
|
||||||
*
|
|
||||||
* This function returns an integer with bits a thru b swapped.
|
|
||||||
* That is, bit a is swapped with bit b, bit a+1 is swapped with b-1,
|
|
||||||
* and so on.
|
|
||||||
*
|
|
||||||
* As a special case, if the ending bit position is < 0, is it taken to
|
|
||||||
* mean the highest bit set. Thus zbitrev(0, -1, z, &res) will
|
|
||||||
* perform a complete bit reverse of the number 'z'.
|
|
||||||
*
|
|
||||||
* As a special case, if the starting bit position is < 0, is it taken to
|
|
||||||
* mean the lowest bit set. Thus zbitrev(-1, -1, z, &res) is the
|
|
||||||
* same as zbitrev(lowbit(z), highbit(z), z, &res).
|
|
||||||
*
|
|
||||||
* Note that the low order bit number is taken to be 0. Also, bitrev
|
|
||||||
* ignores the sign of the number.
|
|
||||||
*
|
|
||||||
* Bits beyond the highest bit are taken to be zero. Thus the calling
|
|
||||||
* bitrev(0, 100, _one_, &res) will result in a value of 2^100.
|
|
||||||
*
|
|
||||||
* given:
|
|
||||||
* low lowest bit to reverse, <0 => lowbit(z)
|
|
||||||
* high highest bit to reverse, <0 => highbit(z)
|
|
||||||
* z value to bit reverse
|
|
||||||
* res resulting bit reverse number
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
zbitrev(long low, long high, ZVALUE z, ZVALUE *res)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return whether or not the specifed bit number is set in a number.
|
* Return whether or not the specifed bit number is set in a number.
|
||||||
* Rightmost bit of a number is bit 0.
|
* Rightmost bit of a number is bit 0.
|
||||||
|
5
zmath.h
5
zmath.h
@@ -349,11 +349,6 @@ extern void zlcmfact(ZVALUE z, ZVALUE *dest);
|
|||||||
/*
|
/*
|
||||||
* Misc misc functions. :-)
|
* Misc misc functions. :-)
|
||||||
*/
|
*/
|
||||||
#if 0
|
|
||||||
extern void zapprox(ZVALUE z1, ZVALUE z2, ZVALUE *res1, ZVALUE *res2);
|
|
||||||
extern void zmulmod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res);
|
|
||||||
extern void zsubmod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res);
|
|
||||||
#endif
|
|
||||||
extern void zsquaremod(ZVALUE z1, ZVALUE z2, ZVALUE *res);
|
extern void zsquaremod(ZVALUE z1, ZVALUE z2, ZVALUE *res);
|
||||||
extern void zminmod(ZVALUE z1, ZVALUE z2, ZVALUE *res);
|
extern void zminmod(ZVALUE z1, ZVALUE z2, ZVALUE *res);
|
||||||
extern BOOL zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3);
|
extern BOOL zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3);
|
||||||
|
238
zmod.c
238
zmod.c
@@ -30,76 +30,6 @@ BOOL havelastmod = FALSE;
|
|||||||
static ZVALUE lastmod[1];
|
static ZVALUE lastmod[1];
|
||||||
static ZVALUE lastmodinv[1];
|
static ZVALUE lastmodinv[1];
|
||||||
|
|
||||||
#if 0
|
|
||||||
extern void zaddmod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res);
|
|
||||||
extern void znegmod(ZVALUE z1, ZVALUE z2, ZVALUE *res);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Multiply two numbers together and then mod the result with a third number.
|
|
||||||
* The two numbers to be multiplied can be negative or out of modulo range.
|
|
||||||
* The result will be in the range 0 to the modulus - 1.
|
|
||||||
*
|
|
||||||
* given:
|
|
||||||
* z1 first number to be multiplied
|
|
||||||
* z2 second number to be multiplied
|
|
||||||
* z3 number to take mod with
|
|
||||||
* res result
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
zmulmod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res)
|
|
||||||
{
|
|
||||||
ZVALUE tmp;
|
|
||||||
FULL prod;
|
|
||||||
FULL digit;
|
|
||||||
BOOL neg;
|
|
||||||
|
|
||||||
if (ziszero(z3) || zisneg(z3))
|
|
||||||
math_error("Mod of non-positive integer");
|
|
||||||
/*NOTREACHED*/
|
|
||||||
if (ziszero(z1) || ziszero(z2) || zisunit(z3)) {
|
|
||||||
*res = _zero_;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If the modulus is a single digit number, then do the result
|
|
||||||
* cheaply. Check especially for a small power of two.
|
|
||||||
*/
|
|
||||||
if (zistiny(z3)) {
|
|
||||||
neg = (z1.sign != z2.sign);
|
|
||||||
digit = z3.v[0];
|
|
||||||
if ((digit & -digit) == digit) { /* NEEDS 2'S COMP */
|
|
||||||
prod = ((FULL) z1.v[0]) * ((FULL) z2.v[0]);
|
|
||||||
prod &= (digit - 1);
|
|
||||||
} else {
|
|
||||||
z1.sign = 0;
|
|
||||||
z2.sign = 0;
|
|
||||||
prod = (FULL) zmodi(z1, (long) digit);
|
|
||||||
prod *= (FULL) zmodi(z2, (long) digit);
|
|
||||||
prod %= digit;
|
|
||||||
}
|
|
||||||
if (neg && prod)
|
|
||||||
prod = digit - prod;
|
|
||||||
itoz((long) prod, res);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The modulus is more than one digit.
|
|
||||||
* Actually do the multiply and divide if necessary.
|
|
||||||
*/
|
|
||||||
zmul(z1, z2, &tmp);
|
|
||||||
if (zispos(tmp) && ((tmp.len < z3.len) || ((tmp.len == z3.len) &&
|
|
||||||
(tmp.v[tmp.len-1] < z2.v[z3.len-1]))))
|
|
||||||
{
|
|
||||||
*res = tmp;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
zmod(tmp, z3, res, 0);
|
|
||||||
zfree(tmp);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Square a number and then mod the result with a second number.
|
* Square a number and then mod the result with a second number.
|
||||||
@@ -159,154 +89,6 @@ zsquaremod(ZVALUE z1, ZVALUE z2, ZVALUE *res)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* Add two numbers together and then mod the result with a third number.
|
|
||||||
* The two numbers to be added can be negative or out of modulo range.
|
|
||||||
* The result will be in the range 0 to the modulus - 1.
|
|
||||||
*
|
|
||||||
* given:
|
|
||||||
* z1 first number to be added
|
|
||||||
* z2 second number to be added
|
|
||||||
* z3 number to take mod with
|
|
||||||
* res result
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
zaddmod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res)
|
|
||||||
{
|
|
||||||
ZVALUE tmp;
|
|
||||||
FULL sumdigit;
|
|
||||||
FULL moddigit;
|
|
||||||
|
|
||||||
if (ziszero(z3) || zisneg(z3))
|
|
||||||
math_error("Mod of non-positive integer");
|
|
||||||
/*NOTREACHED*/
|
|
||||||
if ((ziszero(z1) && ziszero(z2)) || zisunit(z3)) {
|
|
||||||
*res = _zero_;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (zistwo(z2)) {
|
|
||||||
if ((z1.v[0] + z2.v[0]) & 0x1)
|
|
||||||
*res = _one_;
|
|
||||||
else
|
|
||||||
*res = _zero_;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
zadd(z1, z2, &tmp);
|
|
||||||
if (zisneg(tmp) || (tmp.len > z3.len)) {
|
|
||||||
zmod(tmp, z3, res, 0);
|
|
||||||
zfree(tmp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sumdigit = tmp.v[tmp.len - 1];
|
|
||||||
moddigit = z3.v[z3.len - 1];
|
|
||||||
if ((tmp.len < z3.len) || (sumdigit < moddigit)) {
|
|
||||||
*res = tmp;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (sumdigit < 2 * moddigit) {
|
|
||||||
zsub(tmp, z3, res);
|
|
||||||
zfree(tmp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
zmod(tmp, z2, res, 0);
|
|
||||||
zfree(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Subtract two numbers together and then mod the result with a third number.
|
|
||||||
* The two numbers to be subtract can be negative or out of modulo range.
|
|
||||||
* The result will be in the range 0 to the modulus - 1.
|
|
||||||
*
|
|
||||||
* given:
|
|
||||||
* z1 number to be subtracted from
|
|
||||||
* z2 number to be subtracted
|
|
||||||
* z3 number to take mod with
|
|
||||||
* res result
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
zsubmod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res)
|
|
||||||
{
|
|
||||||
if (ziszero(z3) || zisneg(z3)) {
|
|
||||||
math_error("Mod of non-positive integer");
|
|
||||||
/*NOTREACHED*/
|
|
||||||
}
|
|
||||||
if (ziszero(z2)) {
|
|
||||||
zmod(z1, z3, res, 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (ziszero(z1)) {
|
|
||||||
znegmod(z2, z3, res);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ((z1.sign == z2.sign) && (z1.len == z2.len) &&
|
|
||||||
(z1.v[0] == z2.v[0]) && (zcmp(z1, z2) == 0)) {
|
|
||||||
*res = _zero_;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
z2.sign = !z2.sign;
|
|
||||||
zaddmod(z1, z2, z3, res);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate the negative of a number modulo another number.
|
|
||||||
* The number to be negated can be negative or out of modulo range.
|
|
||||||
* The result will be in the range 0 to the modulus - 1.
|
|
||||||
*
|
|
||||||
* given:
|
|
||||||
* z1 number to take negative of
|
|
||||||
* z2 number to take mod with
|
|
||||||
* res result
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
znegmod(ZVALUE z1, ZVALUE z2, ZVALUE *res)
|
|
||||||
{
|
|
||||||
int sign;
|
|
||||||
int cv;
|
|
||||||
|
|
||||||
if (ziszero(z2) || zisneg(z2)) {
|
|
||||||
math_error("Mod of non-positive integer");
|
|
||||||
/*NOTREACHED*/
|
|
||||||
}
|
|
||||||
if (ziszero(z1) || zisunit(z2)) {
|
|
||||||
*res = _zero_;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (zistwo(z2)) {
|
|
||||||
if (z1.v[0] & 0x1)
|
|
||||||
*res = _one_;
|
|
||||||
else
|
|
||||||
*res = _zero_;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If the absolute value of the number is within the modulo range,
|
|
||||||
* then the result is just a copy or a subtraction. Otherwise go
|
|
||||||
* ahead and negate and reduce the result.
|
|
||||||
*/
|
|
||||||
sign = z1.sign;
|
|
||||||
z1.sign = 0;
|
|
||||||
cv = zrel(z1, z2);
|
|
||||||
if (cv == 0) {
|
|
||||||
*res = _zero_;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (cv < 0) {
|
|
||||||
if (sign)
|
|
||||||
zcopy(z1, res);
|
|
||||||
else
|
|
||||||
zsub(z2, z1, res);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
z1.sign = !sign;
|
|
||||||
zmod(z1, z2, res, 0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calculate the number congruent to the given number whose absolute
|
* Calculate the number congruent to the given number whose absolute
|
||||||
* value is minimal. The number to be reduced can be negative or out of
|
* value is minimal. The number to be reduced can be negative or out of
|
||||||
@@ -477,8 +259,7 @@ zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3)
|
|||||||
*/
|
*/
|
||||||
if ((tmp1.sign == tmp2.sign) &&
|
if ((tmp1.sign == tmp2.sign) &&
|
||||||
((tmp1.len < len) || (zrel(tmp1, z3) < 0)) &&
|
((tmp1.len < len) || (zrel(tmp1, z3) < 0)) &&
|
||||||
((tmp2.len < len) || (zrel(tmp2, z3) < 0)))
|
((tmp2.len < len) || (zrel(tmp2, z3) < 0))) {
|
||||||
{
|
|
||||||
if (tmp1.v != z1.v)
|
if (tmp1.v != z1.v)
|
||||||
zfree(tmp1);
|
zfree(tmp1);
|
||||||
if (tmp2.v != z2.v)
|
if (tmp2.v != z2.v)
|
||||||
@@ -747,8 +528,7 @@ zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res)
|
|||||||
/*
|
/*
|
||||||
* If modulus is large enough use zmod5
|
* If modulus is large enough use zmod5
|
||||||
*/
|
*/
|
||||||
if (z3.len >= conf->pow2)
|
if (z3.len >= conf->pow2) {
|
||||||
{
|
|
||||||
if (havelastmod && zcmp(z3, *lastmod)) {
|
if (havelastmod && zcmp(z3, *lastmod)) {
|
||||||
zfree(*lastmod);
|
zfree(*lastmod);
|
||||||
zfree(*lastmodinv);
|
zfree(*lastmodinv);
|
||||||
@@ -869,8 +649,7 @@ zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res)
|
|||||||
* If the modulus is odd and small enough then use
|
* If the modulus is odd and small enough then use
|
||||||
* the REDC algorithm. The size where this is done is configurable.
|
* the REDC algorithm. The size where this is done is configurable.
|
||||||
*/
|
*/
|
||||||
if (z3.len < conf->redc2 && zisodd(z3))
|
if (z3.len < conf->redc2 && zisodd(z3)) {
|
||||||
{
|
|
||||||
if (powermodredc && zcmp(powermodredc->mod, z3)) {
|
if (powermodredc && zcmp(powermodredc->mod, z3)) {
|
||||||
zredcfree(powermodredc);
|
zredcfree(powermodredc);
|
||||||
powermodredc = NULL;
|
powermodredc = NULL;
|
||||||
@@ -1283,8 +1062,7 @@ zredcdecode(REDC *rp, ZVALUE z1, ZVALUE *res)
|
|||||||
if (len == 0)
|
if (len == 0)
|
||||||
len = 1;
|
len = 1;
|
||||||
res->len = len;
|
res->len = len;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
/* Here 0 < z1 < 2^bitnum */
|
/* Here 0 < z1 < 2^bitnum */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1318,9 +1096,9 @@ zredcdecode(REDC *rp, ZVALUE z1, ZVALUE *res)
|
|||||||
zp1.len = tmp1.len - modlen;
|
zp1.len = tmp1.len - modlen;
|
||||||
zp1.sign = 0;
|
zp1.sign = 0;
|
||||||
zadd(zp1, _one_, res);
|
zadd(zp1, _one_, res);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
*res = _one_;
|
*res = _one_;
|
||||||
|
}
|
||||||
zfree(tmp1);
|
zfree(tmp1);
|
||||||
}
|
}
|
||||||
if (ztop.len) {
|
if (ztop.len) {
|
||||||
@@ -2033,9 +1811,9 @@ zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res)
|
|||||||
if (sign && !ziszero(ans)) {
|
if (sign && !ziszero(ans)) {
|
||||||
zsub(rp->mod, ans, res);
|
zsub(rp->mod, ans, res);
|
||||||
zfree(ans);
|
zfree(ans);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
*res = ans;
|
*res = ans;
|
||||||
|
}
|
||||||
if (ztmp.len)
|
if (ztmp.len)
|
||||||
zfree(ztmp);
|
zfree(ztmp);
|
||||||
}
|
}
|
||||||
|
8
zmul.c
8
zmul.c
@@ -535,8 +535,7 @@ domul(HALF *v1, LEN size1, HALF *v2, LEN size2, HALF *ans)
|
|||||||
h2--;
|
h2--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((sizeC > sizeD) || ((sizeC == sizeD) && (*h1 > *h2)))
|
if ((sizeC > sizeD) || ((sizeC == sizeD) && (*h1 > *h2))) {
|
||||||
{
|
|
||||||
neg = !neg;
|
neg = !neg;
|
||||||
h1 = baseC;
|
h1 = baseC;
|
||||||
h2 = baseD;
|
h2 = baseD;
|
||||||
@@ -1046,8 +1045,7 @@ dosquare(HALF *vp, LEN size, HALF *ans)
|
|||||||
h2--;
|
h2--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((sizeA > sizeB) || ((sizeA == sizeB) && (*h1 > *h2)))
|
if ((sizeA > sizeB) || ((sizeA == sizeB) && (*h1 > *h2))) {
|
||||||
{
|
|
||||||
h1 = baseA;
|
h1 = baseA;
|
||||||
h2 = baseB;
|
h2 = baseB;
|
||||||
sizeAB = sizeA;
|
sizeAB = sizeA;
|
||||||
@@ -1155,5 +1153,3 @@ zalloctemp(LEN len)
|
|||||||
buflen = len;
|
buflen = len;
|
||||||
return hp;
|
return hp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* END CODE */
|
|
||||||
|
12
zprime.c
12
zprime.c
@@ -973,15 +973,13 @@ zprimetest(ZVALUE z, long count, ZVALUE skip)
|
|||||||
if (ziszero(skip)) {
|
if (ziszero(skip)) {
|
||||||
type = 0;
|
type = 0;
|
||||||
zbase = _zero_;
|
zbase = _zero_;
|
||||||
}
|
} else if (zisone(skip)) {
|
||||||
else if (zisone(skip)) {
|
|
||||||
type = 1;
|
type = 1;
|
||||||
itoz(2, &zbase);
|
itoz(2, &zbase);
|
||||||
limit = 1 << 16;
|
limit = 1 << 16;
|
||||||
if (!zge16b(z))
|
if (!zge16b(z))
|
||||||
limit = ztolong(z);
|
limit = ztolong(z);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
type = 2;
|
type = 2;
|
||||||
if (zrel(skip, z) >= 0 || zisneg(skip))
|
if (zrel(skip, z) >= 0 || zisneg(skip))
|
||||||
zmod(skip, z, &zbase, 0);
|
zmod(skip, z, &zbase, 0);
|
||||||
@@ -1082,15 +1080,13 @@ zredcprimetest(ZVALUE z, long count, ZVALUE skip)
|
|||||||
if (ziszero(skip)) {
|
if (ziszero(skip)) {
|
||||||
zbase = _zero_;
|
zbase = _zero_;
|
||||||
type = 0;
|
type = 0;
|
||||||
}
|
} else if (zisone(skip)) {
|
||||||
else if (zisone(skip)) {
|
|
||||||
itoz(2, &zbase);
|
itoz(2, &zbase);
|
||||||
type = 1;
|
type = 1;
|
||||||
limit = 1 << 16;
|
limit = 1 << 16;
|
||||||
if (!zge16b(z))
|
if (!zge16b(z))
|
||||||
limit = ztolong(z);
|
limit = ztolong(z);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
zredcencode(rp, skip, &zbase);
|
zredcencode(rp, skip, &zbase);
|
||||||
type = 2;
|
type = 2;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user