diff --git a/BUGS b/BUGS index ca80ea3..9a6e212 100644 --- a/BUGS +++ b/BUGS @@ -66,13 +66,13 @@ Please include the following information in the new issue: * Version of calc you are using - If you cannot compile calc, then look at version.c - and report the #define that start with: + If you cannot compile calc, then look at version.c + and report the #define that start with: - #define MAJOR_VER - #define MINOR_VER - #define MAJOR_PATCH - #define MINOR_PATCH + #define MAJOR_VER + #define MINOR_VER + #define MAJOR_PATCH + #define MINOR_PATCH * If you modified calc from an official patch, send us the mods you made @@ -88,7 +88,7 @@ Please include the following information in the new issue: * cd to the calc source directory, and send the contents of debug.out.txt produced by this command: - make debug + make debug PLEASE attach the debug.out.txt file to your GitHub issue (bug report)!! @@ -122,16 +122,16 @@ mis-features in calc: This works as expected: - if (expr) { - ... - } + if (expr) { + ... + } However this WILL NOT WORK AS EXPECTED: - if (expr) - { - ... - } + if (expr) + { + ... + } This needs to be changed. See also "help statement", "help unexpected", and "help todo". @@ -143,28 +143,28 @@ mis-features in calc: integers to/from files the hard way. It does NOT use blkcpy. The following code: - i = (ord("\n") << 16) | (ord("i") << 8) | ord("H") - b = blk() - copy(i, b) - fd = fopen("file", "w") - copy(b, fd); - fclose(fd) + i = (ord("\n") << 16) | (ord("i") << 8) | ord("H") + b = blk() + copy(i, b) + fd = fopen("file", "w") + copy(b, fd); + fclose(fd) will write an extra NUL octet to the file. Where as: - read intfile - i = (ord("\n") << 16) | (ord("i") << 8) | ord("H") - be2file(i, "file2") + read intfile + i = (ord("\n") << 16) | (ord("i") << 8) | ord("H") + be2file(i, "file2") will not. * The numerator is assumed - The numerator value of 1 appears to be assumed. In calc: + The numerator value of 1 appears to be assumed. In calc: - / 2 + / 2 - will produce a value of 0.5 as if the numerator 1 was given. + will produce a value of 0.5 as if the numerator 1 was given. =-= @@ -177,7 +177,7 @@ mis-features in calc: ## ## 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 +## 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 @@ -185,8 +185,8 @@ mis-features in calc: ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/18 14:06:13 -## File existed as early as: 1994 +## Under source code control: 1994/03/18 14:06:13 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/CHANGES b/CHANGES index 6c3defc..0c29883 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +The following are the changes from calc version 2.15.0.7 to 2.15.1.0: + + Converted all ASCII tabs to ASCII spaces using a 8 character + tab stop, for all files, except for all Makefiles (plus rpm.mk). + The `git diff -w` reports no changes. + + The following are the changes from calc version 2.15.0.6 to 2.15.0.7: Thanks to GitHub user @bambooleafz a critical bug (GitHub issue @@ -37,19 +44,19 @@ The following are the changes from calc version 2.15.0.3 to 2.15.0.4: Removed unused macros from zmath.h: - SWAP_B32_IN_HASH(dest, src) - SWAP_B16_IN_HASH(dest, src) - SWAP_B8_IN_HASH(dest, src) - SWAP_B32_IN_FLAG(dest, src) - SWAP_B16_IN_FLAG(dest, src) - SWAP_B8_IN_FLAG(dest, src) + SWAP_B32_IN_HASH(dest, src) + SWAP_B16_IN_HASH(dest, src) + SWAP_B8_IN_HASH(dest, src) + SWAP_B32_IN_FLAG(dest, src) + SWAP_B16_IN_FLAG(dest, src) + SWAP_B8_IN_FLAG(dest, src) When SWAP_HALF_IN_B32(dest, src), SWAP_B32_IN_FULL(dest, src), SWAP_B16_IN_HALF(dest, src), SWAP_B32_IN_bool(dest, src), or SWAP_B32_IN_LEN(dest, src), SWAP_HALF_IN_FILEPOS(dest, src) is an assignment such as: - (*(dest) = *(src)) + (*(dest) = *(src)) We now case the dest and src pointers to the proper type before referencing and performing the assignment. @@ -134,30 +141,30 @@ The following are the changes from calc version 2.14.3.5 to 2.15.0.1: Added the following new trigonometric functions: - versin(x [,eps]) versed trigonometric sine - coversin(x [,eps]) coversed trigonometric sine - vercos(x [,eps]) versed trigonometric cosine - covercos(x [,eps]) coversed trigonometric cosine - aversin(x [,eps]) inverse versed trigonometric sine - acoversin(x [,eps]) inverse coversed trigonometric sine - avercos(x [,eps]) inverse versed trigonometric cosine - acovercos(x [,eps]) inverse coversed trigonometric cosine - haversin(x [,eps]) half versed trigonometric sine - hacoversin(x [,eps]) half coversed trigonometric sine - havercos(x [,eps]) half versed trigonometric cosine - hacovercos(x [,eps]) half coversed trigonometric cosine - ahaversin(x [,eps]) inverse half versed trigonometric sine - ahacoversin(x [,eps]) inverse half coversed trigonometric sine - ahavercos(x [,eps]) inverse half versed trigonometric cosine - ahacovercos(x [,eps]) inverse half coversed trigonometric cosine - exsec(x [,eps]) exterior trigonometric secant - aexsec(x [,eps]) inverse exterior trigonometric secant - excsc(x [,eps]) exterior trigonometric cosecant - aexcsc(x [,eps]) inverse exterior trigonometric cosecant - crd(x [,eps]) trigonometric chord of a unit circle - acrd(x [,eps]) inverse trigonometric chord of a unit circle - cas(x [,eps]) trigonometric cosine plus sine - cis(x [,eps]) Euler's formula + versin(x [,eps]) versed trigonometric sine + coversin(x [,eps]) coversed trigonometric sine + vercos(x [,eps]) versed trigonometric cosine + covercos(x [,eps]) coversed trigonometric cosine + aversin(x [,eps]) inverse versed trigonometric sine + acoversin(x [,eps]) inverse coversed trigonometric sine + avercos(x [,eps]) inverse versed trigonometric cosine + acovercos(x [,eps]) inverse coversed trigonometric cosine + haversin(x [,eps]) half versed trigonometric sine + hacoversin(x [,eps]) half coversed trigonometric sine + havercos(x [,eps]) half versed trigonometric cosine + hacovercos(x [,eps]) half coversed trigonometric cosine + ahaversin(x [,eps]) inverse half versed trigonometric sine + ahacoversin(x [,eps]) inverse half coversed trigonometric sine + ahavercos(x [,eps]) inverse half versed trigonometric cosine + ahacovercos(x [,eps]) inverse half coversed trigonometric cosine + exsec(x [,eps]) exterior trigonometric secant + aexsec(x [,eps]) inverse exterior trigonometric secant + excsc(x [,eps]) exterior trigonometric cosecant + aexcsc(x [,eps]) inverse exterior trigonometric cosecant + crd(x [,eps]) trigonometric chord of a unit circle + acrd(x [,eps]) inverse trigonometric chord of a unit circle + cas(x [,eps]) trigonometric cosine plus sine + cis(x [,eps]) Euler's formula As Msys2 is a fork of Cygwin, if the OSNAME is Msys, the Cygwin target will be used. Thanks to GitHub user @iahung2 for the @@ -302,23 +309,23 @@ The following are the changes from calc version 2.14.3.5 to 2.15.0.1: renamed the following test calc resource files that are related to the calc regression test suite: - cal/test1700.cal -> cal/test8000.read.cal - cal/test2300.cal -> cal/test2300.obj_incdec.cal - cal/test2600.cal -> cal/test2600.numfunc.cal - cal/test2700.cal -> cal/test2700.isqrt.cal - cal/test3100.cal -> cal/test3100.matobj.cal - cal/test3400.cal -> cal/test3400.trig.cal - cal/test4000.cal -> cal/test4000.ptest.cal - cal/test4100.cal -> cal/test4100.redc.cal - cal/test4600.cal -> cal/test4600.fileop.cal - cal/test5100.cal -> cal/test5100.newdecl.cal - cal/test5200.cal -> cal/test5200.globstat.cal - cal/test8400.cal -> cal/test8400.quit.cal - cal/test8500.cal -> cal/test8500.divmod.cal - cal/test8600.cal -> cal/test8600.maxargs.cal - cal/set8700.cal -> cal/test8700.dotest.cal - cal/test8900.cal -> cal/test8900.special.cal - cal/test9300.cal -> cal/test9300.frem.cal + cal/test1700.cal -> cal/test8000.read.cal + cal/test2300.cal -> cal/test2300.obj_incdec.cal + cal/test2600.cal -> cal/test2600.numfunc.cal + cal/test2700.cal -> cal/test2700.isqrt.cal + cal/test3100.cal -> cal/test3100.matobj.cal + cal/test3400.cal -> cal/test3400.trig.cal + cal/test4000.cal -> cal/test4000.ptest.cal + cal/test4100.cal -> cal/test4100.redc.cal + cal/test4600.cal -> cal/test4600.fileop.cal + cal/test5100.cal -> cal/test5100.newdecl.cal + cal/test5200.cal -> cal/test5200.globstat.cal + cal/test8400.cal -> cal/test8400.quit.cal + cal/test8500.cal -> cal/test8500.divmod.cal + cal/test8600.cal -> cal/test8600.maxargs.cal + cal/set8700.cal -> cal/test8700.dotest.cal + cal/test8900.cal -> cal/test8900.special.cal + cal/test9300.cal -> cal/test9300.frem.cal Added to test 94dd, read of a number of new calc resource files that are not already read as a result of the calc regression test suite. @@ -345,29 +352,29 @@ The following are the changes from calc version 2.14.3.5 to 2.15.0.1: that users of libcalc may directly round complex number to nearest multiple of a given real number: - E_FUNC COMPLEX *cmappr(COMPLEX *c, NUMBER *e, long rnd, bool cfree); + E_FUNC COMPLEX *cmappr(COMPLEX *c, NUMBER *e, long rnd, bool cfree); For example: - COMPLEX *c; /* complex number to round to nearest epsilon */ - NUMBER *eps; /* epsilon rounding precision */ - COMPLEX *res; /* c rounded to nearest epsilon */ - long rnd = 24L; /* a common rounding mode */ - bool ok_to_free; /* true ==> free c, false ==> do not free c */ + COMPLEX *c; /* complex number to round to nearest epsilon */ + NUMBER *eps; /* epsilon rounding precision */ + COMPLEX *res; /* c rounded to nearest epsilon */ + long rnd = 24L; /* a common rounding mode */ + bool ok_to_free; /* true ==> free c, false ==> do not free c */ - ... + ... - res = cmappr(c, eps, ok_to_free); + res = cmappr(c, eps, ok_to_free); The complex trigonometric functions tan, cot, sec, csc were implemented in func.c as calls to complex sin and complex cos. We added the following direct calls to comfunc.c so that users of libcalc may call them directly: - E_FUNC COMPLEX *c_tan(COMPLEX *c, NUMBER *eps); - E_FUNC COMPLEX *c_cot(COMPLEX *c, NUMBER *eps); - E_FUNC COMPLEX *c_sec(COMPLEX *c, NUMBER *eps); - E_FUNC COMPLEX *c_cot(COMPLEX *c, NUMBER *eps); + E_FUNC COMPLEX *c_tan(COMPLEX *c, NUMBER *eps); + E_FUNC COMPLEX *c_cot(COMPLEX *c, NUMBER *eps); + E_FUNC COMPLEX *c_sec(COMPLEX *c, NUMBER *eps); + E_FUNC COMPLEX *c_cot(COMPLEX *c, NUMBER *eps); Added help/errorcodes rule to the top level Makefile. @@ -429,21 +436,21 @@ The following are the changes from calc version 2.14.3.5 to 2.15.0.1: Code that used the old array error_table[] of error message strings such as: - #include "calcerr.h" + #include "calcerr.h" - char *msg; /* calc computation error message */ + char *msg; /* calc computation error message */ - msg = error_table[errnum - E__BASE]; + msg = error_table[errnum - E__BASE]; where errnum is the calc computation error code E__BASE <= errnum <= E__HIGHEST, may now use: - #include "errtbl.h" - #include "errsym.h" + #include "errtbl.h" + #include "errsym.h" - char *msg; /* calc computation error message */ + char *msg; /* calc computation error message */ - msg = error_table[errnum - E__BASE].errmsg; + msg = error_table[errnum - E__BASE].errmsg; Rename the #define E__COUNT to ECOUNT to avoid confusion with "E_STRING" error symbols. @@ -523,43 +530,43 @@ The following are the changes from calc version 2.14.3.4 to 2.14.3.5: The config("triground") controls rounding for the following trigonometric and hyperbolic functions: - sin, cos, tan, cot, sec, csc - asin, acos, atan, acot, asec, acsc - versin, coversin, vercos, covercos - aversin, acoversin, avercos, acovercos - haversin, hacoversin, havercos, hacovercos - ahaversin, hacoversin, havercos, ahacovercos - exsec, aexsec, excsc, aexcsc - crd, acrd - cas, cis - sinh, cosh, tanh, coth, sech, csch - asinh, acosh, atanh, acoth, asech, acsch + sin, cos, tan, cot, sec, csc + asin, acos, atan, acot, asec, acsc + versin, coversin, vercos, covercos + aversin, acoversin, avercos, acovercos + haversin, hacoversin, havercos, hacovercos + ahaversin, hacoversin, havercos, ahacovercos + exsec, aexsec, excsc, aexcsc + crd, acrd + cas, cis + sinh, cosh, tanh, coth, sech, csch + asinh, acosh, atanh, acoth, asech, acsch In addition to taking a complex root (such as via the power function on a complex value), "triground" is used for: - exp, polar + exp, polar For the above mentioned functions, the rounding mode used to round the result to the nearest epsilon value is controlled by, and defaults to: - config("triground", 24) + config("triground", 24) As with other config options, the call returns the previous mode, without a 2nd argument, returns the current mode without changing it: - config("triground") + config("triground") When printing an error, calc used to print the errnum (error number): - ; 1/0 - Error 10001 + ; 1/0 + Error 10001 Calc now prints the errsym (errsym): - ; 1/0 - Error E_DIVBYZERO + ; 1/0 + Error E_DIVBYZERO Added errsym E_LN_3 for ln(0). Added errsym E_LOG_5 for log(0). @@ -619,11 +626,11 @@ The following are the changes from calc version 2.14.3.0 to 2.14.3.4: We no longer support the Makefile variable ${ALLOW_CUSTOM} to be empty. Normally ${ALLOW_CUSTOM} is: - ALLOW_CUSTOM= -DCUSTOM + ALLOW_CUSTOM= -DCUSTOM Now, to disable custom disable custom even if -C is given, use: - ALLOW_CUSTOM="-UCUSTOM" + ALLOW_CUSTOM="-UCUSTOM" Dropped support of Makefile.simple and custom/Makefile.simple. The calc version 2.14.3.0 is the last release that supported @@ -705,10 +712,10 @@ The following are the changes from calc version 2.14.2.1 to 2.14.3.0: Added cal/fnv_tool.cal, a calc resource file defining: - find_fnv_prime(bits) - deprecated_fnv0(bits,fnv_prime,string) - fnv_offset_basis(bits,fnv_prime) - fnv1a_style_hash(bits,fnv_prime,prev_hash,string) + find_fnv_prime(bits) + deprecated_fnv0(bits,fnv_prime,string) + fnv_offset_basis(bits,fnv_prime) + fnv1a_style_hash(bits,fnv_prime,prev_hash,string) Fixed sorted order of cal/README. @@ -725,20 +732,20 @@ The following are the changes from calc version 2.14.2.1 to 2.14.3.0: For old Apple Power PC systems, the following is added: - COMMON_CFLAGS+= -std=gnu99 - COMMON_LDFLAGS+= -std=gnu99 - ARCH_CFLAGS+= -arch ppc + COMMON_CFLAGS+= -std=gnu99 + COMMON_LDFLAGS+= -std=gnu99 + ARCH_CFLAGS+= -arch ppc Old Apple Power PC systems should be detected by the "uname -p" command returning "powerpc". One may force the Power PC mode by adding to the end of any make command: - make ...make_args... target=Darwin arch=powerpc + make ...make_args... target=Darwin arch=powerpc or by adding the following in the Makefile.local file: - target= Darwin - arch= powerpc + target= Darwin + arch= powerpc Improved the output of the calcinfo rule by adding echos of various uname values as well as some top Makefile variables. @@ -754,27 +761,27 @@ The following are the changes from calc version 2.14.2.0 to 2.14.2.0: Added cal/splitbits.cal: - splitbits(x, b) + splitbits(x, b) - Given an integer x, split the value into a list of integers, - each of which is at most b bits long. + Given an integer x, split the value into a list of integers, + each of which is at most b bits long. - The value b must be an integer > 0. + The value b must be an integer > 0. - The number of elements in the returned list is: + The number of elements in the returned list is: - ceil((highbit(x) + 1) / b) + ceil((highbit(x) + 1) / b) - If x == 0, then a list of 1 element containing 0 is returned. + If x == 0, then a list of 1 element containing 0 is returned. - If x < 0, then the two's compliment of abs(x) is returned. - Even though calc represents negative integers as positive values - with sign bit, the bits returned by this function are as if - the integer converted as if the integer was a two's compliment value. + If x < 0, then the two's compliment of abs(x) is returned. + Even though calc represents negative integers as positive values + with sign bit, the bits returned by this function are as if + the integer converted as if the integer was a two's compliment value. - See also the help command: + See also the help command: - ; help resource + ; help resource The following are the changes from calc version 2.14.1.5 to 2.14.1.6: @@ -819,10 +826,10 @@ The following are the changes from calc version 2.14.1.3 to 2.14.1.4: Updated COPYING file to indicate that these files are now covered under "The Unlicense" (see https://unlicense.org): - sha1.c - sha1.h - cal/dotest.cal - cal/screen.cal + sha1.c + sha1.h + cal/dotest.cal + cal/screen.cal Updated help/credit to match the above changes to COPYING. @@ -841,10 +848,10 @@ The following are the changes from calc version 2.14.1.3 to 2.14.1.4: Fixed all make chk ASAN warnings under macOS 13.2.1 when calc is compiled with the following uncommented lines in Makefile.local: - DEBUG:= -O0 -g - CFLAGS+= -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined - LDFLAGS+= -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined - CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1 + DEBUG:= -O0 -g + CFLAGS+= -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined + LDFLAGS+= -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined + CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1 Improved how pointers to functions are declared for the builtins array in func.c to avoid function declarations without a prototype @@ -915,20 +922,20 @@ The following are the changes from calc version 2.14.1.0 to 2.14.1.2: For example, with the default, config("tilde_space", 0): - ; 1/3 - ~0.33333333333333333333 - ; sqrt(7 + 5i,1e-100) - ~2.79305614578749801863+~0.89507688693280053094i + ; 1/3 + ~0.33333333333333333333 + ; sqrt(7 + 5i,1e-100) + ~2.79305614578749801863+~0.89507688693280053094i With config("tilde_space", 1): - ; 1/3 - ~ 0.33333333333333333333 - ; sqrt(7 + 5i,1e-100) - ~ 2.79305614578749801863+~ 0.89507688693280053094i + ; 1/3 + ~ 0.33333333333333333333 + ; sqrt(7 + 5i,1e-100) + ~ 2.79305614578749801863+~ 0.89507688693280053094i NOTE: Use of config("tilde_space", 1) can break printing and scanning - of complex values via "%c". + of complex values via "%c". To enable "tilde_space", use config("tilde_space", 1) on the command line and/or use config("tilde_space", 1),; in your ~/.calcrc. @@ -940,13 +947,13 @@ The following are the changes from calc version 2.14.1.0 to 2.14.1.2: For example, with the default, config("tilde_space", 0): - ; pi(1e-50) - ~3.14159265358979323846 + ; pi(1e-50) + ~3.14159265358979323846 With config("tilde_space", 1): - ; pi(1e-50) - ~ 3.14159265358979323846 + ; pi(1e-50) + ~ 3.14159265358979323846 Added config("fraction_space", boolean). The "fraction_space" controls whether or not a space (' ') is printed before and after fractions. @@ -954,21 +961,21 @@ The following are the changes from calc version 2.14.1.0 to 2.14.1.2: For example, with the default, config("fraction_space", 0): - ; base(1/3), - ; 1/7 - 1/7 + ; base(1/3), + ; 1/7 + 1/7 With config("fraction_space", 1): - ; base(1/3), - ; 1/7 - 1 / 7 + ; base(1/3), + ; 1/7 + 1 / 7 NOTE: Use of config("fraction_space", 1) can break printing and scanning - of fractional values via "%r". + of fractional values via "%r". NOTE: Use of config("fraction_space", 1) can break printing and scanning - of complex values via "%c". + of complex values via "%c". Added config("fraction_space", boolean) to help/config, along with a few few minor text improvements. Updated cal/regress to test @@ -982,19 +989,19 @@ The following are the changes from calc version 2.14.1.0 to 2.14.1.2: For example, with the default, config("complex_space", 0): - ; asin(2) - 1.57079632679489661923-1.31695789692481670863i + ; asin(2) + 1.57079632679489661923-1.31695789692481670863i With config("complex_space", 1): - ; asin(2) - 1.57079632679489661923 - 1.31695789692481670863i + ; asin(2) + 1.57079632679489661923 - 1.31695789692481670863i NOTE: Use of config("complex_space", 1) can break printing and scanning - of fractional values via "%r". + of fractional values via "%r". NOTE: Use of config("complex_space", 1) can break printing and scanning - of complex values via "%c". + of complex values via "%c". Added config("complex_space", boolean) to help/config, along with a few few minor text improvements. Updated cal/regress to test @@ -1110,60 +1117,60 @@ The following are the changes from calc version 2.14.1.0 to 2.14.1.0: Added cal/comma.cal: - Convert numbers into strings with 3-digit group and integer-fraction - separators. + Convert numbers into strings with 3-digit group and integer-fraction + separators. - If the value is an integer, the integer-fraction separator is not used. + If the value is an integer, the integer-fraction separator is not used. - str_comma(x, [group, [decimal]]) + str_comma(x, [group, [decimal]]) - Convert x into a string. + Convert x into a string. - If group is given and is a string, group will be used as - the 3-digit group separator, otherwise the default 3-digit - group separator will be used. + If group is given and is a string, group will be used as + the 3-digit group separator, otherwise the default 3-digit + group separator will be used. - If decimal is given and is a string, group will be used as - the integer-fraction separator, otherwise the default - integer-fraction separator will be used. + If decimal is given and is a string, group will be used as + the integer-fraction separator, otherwise the default + integer-fraction separator will be used. - The decimal and group arguments are optional. + The decimal and group arguments are optional. - set_default_group_separator(group) + set_default_group_separator(group) - Change the default 3-digit group separator if group is a string, - otherwise the default 3-digit group separator will not be - changed. Return the old 3-digit group separator. + Change the default 3-digit group separator if group is a string, + otherwise the default 3-digit group separator will not be + changed. Return the old 3-digit group separator. - set_default_decimal_separator(decimal) + set_default_decimal_separator(decimal) - Change the default 3-digit group separator if decimal is a - string, otherwise the default integer-fraction separator - will not be changed. Return the old integer-fraction separator. + Change the default 3-digit group separator if decimal is a + string, otherwise the default integer-fraction separator + will not be changed. Return the old integer-fraction separator. - print_comma(x, [group, [decimal]]) + print_comma(x, [group, [decimal]]) - Print the value produced by str_comma(x, [group, [decimal]]) - followed by a newline. + Print the value produced by str_comma(x, [group, [decimal]]) + followed by a newline. - If the str_comma() does not return a string, nothing is printed. + If the str_comma() does not return a string, nothing is printed. - The decimal and group arguments are optional. + The decimal and group arguments are optional. - The value produced by str_comma() is returned. + The value produced by str_comma() is returned. - fprint_comma(fd, x, [group, [decimal]]) + fprint_comma(fd, x, [group, [decimal]]) - Print the value produced by str_comma(x, [group, [decimal]]), - without a trailing newline, on file fd. + Print the value produced by str_comma(x, [group, [decimal]]), + without a trailing newline, on file fd. - If the str_comma() does not return a string, nothing is printed. + If the str_comma() does not return a string, nothing is printed. - If fd is not an open file, nothing is printed. + If fd is not an open file, nothing is printed. - The decimal and group arguments are optional. + The decimal and group arguments are optional. - The value produced by str_comma() is returned. + The value produced by str_comma() is returned. The following are the changes from calc version 2.14.0.15 to 2.14.0.15: @@ -1211,7 +1218,7 @@ The following are the changes from calc version 2.14.0.14 to 2.14.0.14: Established a tagging procedure for a production release. Production git tags will be of the form: - prod-2.x.y.z + prod-2.x.y.z The following are the changes from calc version 2.14.0.13 to 2.14.0.13: @@ -1249,49 +1256,49 @@ The following are the changes from calc version 2.14.0.13 to 2.14.0.13: By default, compiler warnings have been turned up. The Makefile variable ${CCWARN} now defaults to: - CCWARN= -Wall -Wextra -pedantic + CCWARN= -Wall -Wextra -pedantic The previous level of compiler warnings can be easily restored by adding to Makefile.local: - CCWARN:= -Wall + CCWARN:= -Wall The readline, history and ncurses libraries are now default. The Makefile variables ${USE_READLINE}, ${READLINE_LIB}, and ${READLINE_EXTRAS} now default to: - USE_READLINE= -DUSE_READLINE - READLINE_LIB= -lreadline - READLINE_EXTRAS= -lhistory -lncurses + USE_READLINE= -DUSE_READLINE + READLINE_LIB= -lreadline + READLINE_EXTRAS= -lhistory -lncurses The previous mode where readline, history and ncurses libraries were not compiled in by default can be easily restored by adding to Makefile.local: - USE_READLINE:= - READLINE_LIB:= - READLINE_EXTRAS:= + USE_READLINE:= + READLINE_LIB:= + READLINE_EXTRAS:= We have renamed "stable" as "production". We have renamed "unstable" as "tested". On the web site: - http://www.isthe.com/chongo/src/calc/ + http://www.isthe.com/chongo/src/calc/ these files has been renamed: - 2.x.y.z_IS_LATEST_STABLE ==> 2.x.y.z_IS_LATEST_PRODUCTION - 2.x.y.z_IS_LATEST_UNSTABLE ==> 2.x.y.z_IS_LATEST_TESTED + 2.x.y.z_IS_LATEST_STABLE ==> 2.x.y.z_IS_LATEST_PRODUCTION + 2.x.y.z_IS_LATEST_UNSTABLE ==> 2.x.y.z_IS_LATEST_TESTED The terms 'stable' and 'unstable' were both misleading and inaccurate. For details see the new documention file: - README.RELEASE + README.RELEASE See also the help command: - ; help release + ; help release Fixed bug impacting how have_ustat.h was formed. @@ -1315,7 +1322,7 @@ The following are the changes from calc version 2.14.0.11 to 2.14.0.12: Added have_environ.c to build have_environ.h in order to determine if: - extern char **environ; /* user environment */ + extern char **environ; /* user environment */ is an valid external symbol. @@ -1340,16 +1347,16 @@ The following are the changes from calc version 2.14.0.11 to 2.14.0.12: Added some preliminary notes about attempts to compile calc under Windows 11. - BTW: While we are unable to use Windows 11, we welcome - Windows 11 developers to try compiling calc natively - (instead of via a Linux virtual machine). If you are - able to compile Windows 11 natively, we would welcome - GitHub pull requests showing any needed modifications: + BTW: While we are unable to use Windows 11, we welcome + Windows 11 developers to try compiling calc natively + (instead of via a Linux virtual machine). If you are + able to compile Windows 11 natively, we would welcome + GitHub pull requests showing any needed modifications: - https://github.com/lcn2/calc/pulls + https://github.com/lcn2/calc/pulls - Please also add notes to the 'Compiling calc under Windows 11' - section in README.WINDOWS file. + Please also add notes to the 'Compiling calc under Windows 11' + section in README.WINDOWS file. We added Makefile.simple as part of the master branch source to help those who may be using a make tool that does not support @@ -1364,19 +1371,19 @@ The following are the changes from calc version 2.14.0.9 to 2.14.0.10: Due to issues with clang and Apple Silicon, ARCH_CFLAGS is now, by default, empty: - ARCH_CFLAGS= + ARCH_CFLAGS= If you want to use, say, -march=native, then either change the Makefile or make with: - make all ARCH_CFLAGS='-march=native' + make all ARCH_CFLAGS='-march=native' Added arch and hardware as GNU Makefile computed values. As with ${target}, ${arch} and ${hardware} is computed by uname: - target: uname -a - arch: uname -p - hardware: uname -m + target: uname -a + arch: uname -p + hardware: uname -m Fixed compiling calc on Apple Silicon with HomeBrew. On Apple Silicon, HomeBrew installs on into a different location. The @@ -1408,7 +1415,7 @@ The following are the changes from calc version 2.14.0.7 to 2.14.0.8: largest (highly probable) prime palindrome under 280 decimal digits (text tweet limit): - prevprimepal(1e280) + prevprimepal(1e280) The following are the changes from calc version 2.14.0.0 to 2.14.0.6: @@ -1416,30 +1423,30 @@ The following are the changes from calc version 2.14.0.0 to 2.14.0.6: The :-separated default CALCRC value has been reversed. The default CALCRC was: - ${CALC_SHAREDIR}/startup:~/.calcrc:./.calcinit + ${CALC_SHAREDIR}/startup:~/.calcrc:./.calcinit The default CALCRC is now: - ./.calcinit:~/.calcrc:${CALC_SHAREDIR}/startup + ./.calcinit:~/.calcrc:${CALC_SHAREDIR}/startup See "help environment" for details. Added engineering mode as per a GitHub pull request from . Thank you! For example: - ; config("mode","eng"), - ; 10^41 - 100e39 + ; config("mode","eng"), + ; 10^41 + 100e39 or for example: - ; base(1000), - ; 2^23209-1 - ~402.87411577898877818187e6984 + ; base(1000), + ; 2^23209-1 + ~402.87411577898877818187e6984 For more information see: - help base + help base Added regression test code for engineering mode. Improved and expanded regression test code related to the base() and base2() @@ -1452,14 +1459,14 @@ The following are the changes from calc version 2.14.0.0 to 2.14.0.6: Added builtin functions to convert between degrees, radians and gradians: - d2r(deg) - given degrees returns radians - g2r(grad) - given gradians returns radians + d2r(deg) - given degrees returns radians + g2r(grad) - given gradians returns radians - r2d(rad) - given radians returns degrees - g2d(grad) - given gradians returns degrees + r2d(rad) - given radians returns degrees + g2d(grad) - given gradians returns degrees - r2g(rad) - given radians returns gradians - d2g(deg) - given degrees returns gradians + r2g(rad) - given radians returns gradians + d2g(deg) - given degrees returns gradians Add 6 functions take a 2nd optional epsilon argument. For d2r(deg, ep), r2d(rad, ep), the optional 2nd epsilon argument controls @@ -1499,52 +1506,52 @@ The following are the changes from calc version 2.14.0.0 to 2.14.0.6: degrees, minutes and seconds under the config("mod") round rules: - d2dms(degs, d, m, s [,rnd]) - given degs, compute d, m, s - d2dm(degs, d, m [,rnd]) - given degs, compute d, m + d2dms(degs, d, m, s [,rnd]) - given degs, compute d, m, s + d2dm(degs, d, m [,rnd]) - given degs, compute d, m - See help/d2dms and help/d2dm. + See help/d2dms and help/d2dm. Example: - ; print d2dms(360.321,deg=,min=,sec=), deg, min, sec; - 0.321 0 19 15.6 + ; print d2dms(360.321,deg=,min=,sec=), deg, min, sec; + 0.321 0 19 15.6 - ; print d2dm(360.321,deg=,min=), deg, min; - 0.321 0 19.26 + ; print d2dm(360.321,deg=,min=), deg, min; + 0.321 0 19.26 Added builtin functions to convert between gradians and gradians, minutes and seconds under the config("mod") round rules: - g2gms(grads, g, m, s [,rnd]) - given grads, compute g, m, s - g2gm(grads, g, m [,rnd]) - given grads, compute g, m + g2gms(grads, g, m, s [,rnd]) - given grads, compute g, m, s + g2gm(grads, g, m [,rnd]) - given grads, compute g, m - See help/g2gms and help/g2gm. + See help/g2gms and help/g2gm. Example: - ; print g2gms(400.321,grad=,min=,sec=), grad, min, sec; - 0.321 0 19 15.6 + ; print g2gms(400.321,grad=,min=,sec=), grad, min, sec; + 0.321 0 19 15.6 - ; print g2gm(400.321,grad=,min=), grad, min; - 0.321 0 19.26 + ; print g2gm(400.321,grad=,min=), grad, min; + 0.321 0 19.26 Added builtin functions to convert between hours and hours, minutes and seconds under the config("mod") round rules: - h2hms(hours, h, m, s [,rnd]) - given hours, compute h, m, s - h2hm(hours, h, m [,rnd]) - given hours, compute h, m + h2hms(hours, h, m, s [,rnd]) - given hours, compute h, m, s + h2hm(hours, h, m [,rnd]) - given hours, compute h, m - See help/h2hms and help/h2hm. + See help/h2hms and help/h2hm. Example: - ; print h2hms(24.321,hour=,min=,sec=), hour, min, sec; - 0.321 0 19 15.6 + ; print h2hms(24.321,hour=,min=,sec=), hour, min, sec; + 0.321 0 19 15.6 - ; print h2hm(24.321,hour=,min=), hour, min; - 0.321 0 19.26 + ; print h2hm(24.321,hour=,min=), hour, min; + 0.321 0 19.26 Renumbered regression tests 3408 thru 3437, to 9102 thru 9131. @@ -1559,50 +1566,50 @@ The following are the changes from calc version 2.14.0.0 to 2.14.0.6: Added builtin functions to convert between degrees, minutes and seconds and degrees under the config("mod") round rules: - dms2d(d, m, s [,rnd]) - convert deg, min, and secs to deg - dm2d(d, m [,rnd]) - convert deg, min to deg + dms2d(d, m, s [,rnd]) - convert deg, min, and secs to deg + dm2d(d, m [,rnd]) - convert deg, min to deg - See help/dms2d and help/dm2d. + See help/dms2d and help/dm2d. Example: - ; print dms2d(12, 20, 44.16); - 12.3456 + ; print dms2d(12, 20, 44.16); + 12.3456 - ; print dm2d(3601, -25.5594); - 0.57401 + ; print dm2d(3601, -25.5594); + 0.57401 Added builtin functions to convert between gradians, minutes and seconds and gradians under the config("mod") round rules: - gms2g(g, m, s [,rnd]) - convert grad, min, and secs to grad - gm2g(g, m [,rnd]) - convert grad and min to grad + gms2g(g, m, s [,rnd]) - convert grad, min, and secs to grad + gm2g(g, m [,rnd]) - convert grad and min to grad - See help/g2gms and help/g2gm. + See help/g2gms and help/g2gm. Example: - ; print gms2g(12, 20, 44.16); - 12.3456 + ; print gms2g(12, 20, 44.16); + 12.3456 - ; print gm2g(4001, -25.5594); - 0.57401 + ; print gm2g(4001, -25.5594); + 0.57401 Added builtin functions to convert between hours, minutes and seconds and hours under the config("mod") round rules: - hms2h(h, m, s [,rnd]) - convert hours, min, and secs to hours - hm2h(h, m [,rnd]) - convert hours, min to hours + hms2h(h, m, s [,rnd]) - convert hours, min, and secs to hours + hm2h(h, m [,rnd]) - convert hours, min to hours - See help/hms2h and help/hm2h. + See help/hms2h and help/hm2h. Example: - ; print hms2h(12, 20, 44.16); - 12.3456 + ; print hms2h(12, 20, 44.16); + 12.3456 - ; print hm2h(241, -25.5594); - 0.57401 + ; print hm2h(241, -25.5594); + 0.57401 Fixed typo in cal/statistics.cal thanks to a report by . @@ -1613,15 +1620,15 @@ The following are the changes from calc version 2.14.0.0 to 2.14.0.6: Fixed a really obscure bug in the internal initconstants() function of const.c that has been sitting for over 31 years! - We are amazed that nobody has encountered this bug before - now. Nevertheless, our very extensive regression and - multi-architecture testing found the bug. Now, after all - those years, it is fixed. + We are amazed that nobody has encountered this bug before + now. Nevertheless, our very extensive regression and + multi-architecture testing found the bug. Now, after all + those years, it is fixed. Fixed issues identified by the default CodeUL GitHub security code scan: - Wrong type of arguments to printf in have_fpos_pos.c - Multiplication result converted to larger type in zfunc.c + Wrong type of arguments to printf in have_fpos_pos.c + Multiplication result converted to larger type in zfunc.c The following are the changes from calc version 2.13.0.1 to 2.13.0.1: @@ -1643,16 +1650,16 @@ The following are the changes from calc version 2.13.0.1 to 2.13.0.1: One may override any Makefile setting by modifying Makefile.local. For example, Makefile.local could force BLD_TYPE: - HAVE_STRING_H:= YES - HAVE_TIMES_H:= YES - SED:= /usr/local/bin/nsed + HAVE_STRING_H:= YES + HAVE_TIMES_H:= YES + SED:= /usr/local/bin/nsed Added ${LOC_MKF} to specify the make of the file that is included just before the all file. So one could place the above override lines into a different file and call make changing the ${LOC_MKF} value. For example: - make LOC_MKF=Makefile.private clobber all chk + make LOC_MKF=Makefile.private clobber all chk Updated HOWTO.INSTALL to mention Makefile.local. @@ -1682,7 +1689,7 @@ The following are the changes from calc version 2.13.0.0 to 2.13.0.0: For all calc Makefiles, including those in sub-directories, near the top there is now a line of the form: - # SRC: ... some message about the origin ... + # SRC: ... some message about the origin ... Fixed how the calc(1) man page is installed under macOS. @@ -1694,14 +1701,14 @@ The following are the changes from calc version 2.13.0.0 to 2.13.0.0: line must end in a -f. For example, if calc is in /usr/local/bin/calc, then the following would be the first line of a calc script: - #!/usr/local/bin/calc -f - ... + #!/usr/local/bin/calc -f + ... It is common that -q be used with a calc script, so assuming the same /usr/local/bin/calc path: - #!/usr/local/bin/calc -q -f - ... + #!/usr/local/bin/calc -q -f + ... Use of -s in the #! first line of a calc script is not needed since -f implies -f. @@ -1724,7 +1731,7 @@ The following are the changes from calc version 2.13.0.0 to 2.13.0.0: Due to incompatible changes to the argv() function, and #! calc scripts, we are setting the version to the next minor number: - 2.13.0.x + 2.13.0.x Updated BUGS file as per v2.13.0 fixes. @@ -1733,13 +1740,13 @@ The following are the changes from calc version 2.12.8.2 to 2.12.9.1: Added notes to help/unexpected about: - display() will limit the number of digits printed after decimal point + display() will limit the number of digits printed after decimal point - %d will format after the decimal point for non-integer numeric values + %d will format after the decimal point for non-integer numeric values - %x will format as fractions for non-integer numeric values + %x will format as fractions for non-integer numeric values - fprintf(fd, "%d\n", huge_value) may need fflush(fd) to finish + fprintf(fd, "%d\n", huge_value) may need fflush(fd) to finish Fixed Makefile dependencies for the args.h rule. @@ -1780,18 +1787,18 @@ The following are the changes from calc version 2.12.8.2 to 2.12.9.1: function may lead to a fatal compiler complication. If that happens, consider compiling as: - make clobber all chk CCBAN=-DUNBAN + make clobber all chk CCBAN=-DUNBAN as see if this is a work-a-round. If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us! Please send us a bug report. See the file: - BUGS + BUGS or the URL: - http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html + http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html for how to send us such a bug report. @@ -1887,7 +1894,7 @@ The following are the changes from calc version 2.12.7.5 to 2.12.8.0: To print out information about the calc compilation environment, we added the following make rule: - make calcinfo + make calcinfo Improved how 'make debug' operates. @@ -1912,17 +1919,17 @@ The following are the changes from calc version 2.12.7.5 to 2.12.8.0: The calc-tester mailing list has been retired. See: - * How to submit a calc bug report: + * How to submit a calc bug report: - http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html + http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html - * How to contribute code to calc: + * How to contribute code to calc: - http://www.isthe.com/chongo/tech/comp/calc/calc-contrib.html + http://www.isthe.com/chongo/tech/comp/calc/calc-contrib.html - * How to submit a question about calc: + * How to submit a question about calc: - http://www.isthe.com/chongo/tech/comp/calc/calc-question.html + http://www.isthe.com/chongo/tech/comp/calc/calc-question.html The following are the changes from calc version 2.12.7.1 to 2.12.7.5: @@ -1931,16 +1938,16 @@ The following are the changes from calc version 2.12.7.1 to 2.12.7.5: NL. The code in 2.12.7.0 is correct. The CHANGE notes should have read: - The following is a partial list of escape sequences recognized - in strings and in printf formats: + The following is a partial list of escape sequences recognized + in strings and in printf formats: - \a audible bell byte 0x07 in ASCII encoding - \b backspace byte 0x08 in ASCII encoding - \f form feed byte 0x0c in ASCII encoding - \n newline byte 0x0a in ASCII encoding - \r return byte 0x0d in ASCII encoding - \t tab byte 0x09 in ASCII encoding - \v vertical tab byte 0x0b in ASCII encoding + \a audible bell byte 0x07 in ASCII encoding + \b backspace byte 0x08 in ASCII encoding + \f form feed byte 0x0c in ASCII encoding + \n newline byte 0x0a in ASCII encoding + \r return byte 0x0d in ASCII encoding + \t tab byte 0x09 in ASCII encoding + \v vertical tab byte 0x0b in ASCII encoding Fixed a segfault when getpwuid() returned NULL during initialization. Thanks goes to baratharon GitHub user for reporting this issue. @@ -1955,13 +1962,13 @@ The following are the changes from calc version 2.12.7.1 to 2.12.7.5: the ${CFLAGS} for compiling C code. are ${CC} when compiling C files. The default value is: - ARCH_CFLAGS= -march=native + ARCH_CFLAGS= -march=native which directs C compiler to compile for the native machine. To disable use of '-march=native', set ARCH_CFLAGS to the empty string as in: - make all ARCH_CFLAGS= + make all ARCH_CFLAGS= To make calc RPMs more portable, they are compiled with an empty ARCH_CFLAGS. @@ -2029,13 +2036,13 @@ The following are the changes from calc version 2.12.6.10: to 2.12.7.0: The following is a partial list of escape sequences recognized in strings and in printf formats: - \a audible bell byte 0x07 in ASCII encoding - \b backspace byte 0x08 in ASCII encoding - \f form feed byte 0x0c in ASCII encoding - \n newline byte 0x0a in ASCII encoding - \r return byte 0x0d in ASCII encoding - \t tab byte 0x09 in ASCII encoding - \v vertical tab byte 0x0b in ASCII encoding + \a audible bell byte 0x07 in ASCII encoding + \b backspace byte 0x08 in ASCII encoding + \f form feed byte 0x0c in ASCII encoding + \n newline byte 0x0a in ASCII encoding + \r return byte 0x0d in ASCII encoding + \t tab byte 0x09 in ASCII encoding + \v vertical tab byte 0x0b in ASCII encoding The following are the changes from calc version 2.12.6.9 to 2.12.6.9: @@ -2063,19 +2070,19 @@ The following are the changes from calc version 2.12.6.9 to 2.12.6.9: Made experimental changes to macOS builds to not require use of /usr/include. The INCDIR for macOS uses: - INCDIR= $(shell xcrun --show-sdk-path --sdk macosx)/usr/include + INCDIR= $(shell xcrun --show-sdk-path --sdk macosx)/usr/include to determine the upper path of the /usr/include directory for macOS. In some rare cases, the Darwin target seems to not automatically detected. If you are running under macOS, and that happens, you can force the target to be Darwin: - # for macOS users only, force the target to be darwin - # - make target=Darwin clobber - make target=Darwin all - make target=Darwin chk - make target=Darwin install + # for macOS users only, force the target to be darwin + # + make target=Darwin clobber + make target=Darwin all + make target=Darwin chk + make target=Darwin install The following are the changes from calc version 2.12.6.6 to 2.12.6.8: @@ -2090,7 +2097,7 @@ The following are the changes from calc version 2.12.6.6 to 2.12.6.8: Fixed errors in various help files such as: - mat randbit seed srandom types + mat randbit seed srandom types Removed the MAXSTRING symbol because it was no longer used by calc. @@ -2168,41 +2175,41 @@ The following are the changes from calc version 2.12.6.0 to 2.12.6.0: Example on macOS (Darwin), one may invoke clang's -fsanitize facility by: - make clobber all \ - COMMON_ADD='-fsanitize=undefined -fsanitize=address' + make clobber all \ + COMMON_ADD='-fsanitize=undefined -fsanitize=address' Another example. To force C warnings to be treated as errors: - make COMMON_ADD='-Werror' + make COMMON_ADD='-Werror' Created a GitHub repository for calc: - https://github.com/lcn2/calc + https://github.com/lcn2/calc NOTE: The calc GitHub repository represents the an active - development stream. While an effort will be made to keep - the master branch of the calc GitHub repository in working - order, that tree may be unstable. Those wishing for more - reliable releases use releases found at calc mirror sites: + development stream. While an effort will be made to keep + the master branch of the calc GitHub repository in working + order, that tree may be unstable. Those wishing for more + reliable releases use releases found at calc mirror sites: - http://www.isthe.com/chongo/tech/comp/calc/calc-mirror.html + http://www.isthe.com/chongo/tech/comp/calc/calc-mirror.html IMPORTANT NOTE: - On 2017 June 05, the calc GitHub history was re-written. - Anyone who was tracking the calc "pre-release" on GitHub prior - to version 2.12.6.0 should do a: + On 2017 June 05, the calc GitHub history was re-written. + Anyone who was tracking the calc "pre-release" on GitHub prior + to version 2.12.6.0 should do a: - git reset --hard origin/master - git cleanup -f + git reset --hard origin/master + git cleanup -f - Or you may just want to start over: + Or you may just want to start over: - rm -rf calc - git clone https://github.com/lcn2/calc.git + rm -rf calc + git clone https://github.com/lcn2/calc.git - Sorry about that. The previous GitHub repository was an useful - experiment. Based on what we learned, we decided to rebuild it. + Sorry about that. The previous GitHub repository was an useful + experiment. Based on what we learned, we decided to rebuild it. Renamed README to README.FIRST. Added README.md for the GitHub repository. @@ -2210,7 +2217,7 @@ The following are the changes from calc version 2.12.6.0 to 2.12.6.0: Fixed reading from standard input (stdin) when -p is given on the command line. This now prints hello: - echo hello | calc -p 'stdin = files(0); print fgetline(stdin);' + echo hello | calc -p 'stdin = files(0); print fgetline(stdin);' Added more debugging related to stdin when bit 4 of calc_debug is set (e.g., running calc with -D16). @@ -2241,11 +2248,11 @@ The following are the changes from calc version 2.12.5.4 to 2.12.5.6: Rewrote gen_v1() in the lucas.cal resource file using the method based on a paper: - "A note on primality tests for N = h*2^n-1", by Oystein J. Rodseth, - Department of Mathematics, University of Bergen, BIT Numerical - Mathematics. 34 (3): pp 451-454. + "A note on primality tests for N = h*2^n-1", by Oystein J. Rodseth, + Department of Mathematics, University of Bergen, BIT Numerical + Mathematics. 34 (3): pp 451-454. - http://folk.uib.no/nmaoy/papers/luc.pdf + http://folk.uib.no/nmaoy/papers/luc.pdf The improved gen_v1() function is capable of returning a value for all valid values of h and n. As a result, the trial tables @@ -2300,15 +2307,15 @@ The following are the changes from calc version 2.12.5.3 to 2.12.5.3: macOS (Darwin) users who installed calc version 2.12.5.2 should, after installing version 2.12.5.3: - rm -rf /opt/calc + rm -rf /opt/calc The following are the changes from calc version 2.12.5.1 to 2.12.5.2: NOTE: calc version 2.12.5.2, for macOS (Darwin) users, - installed under /opt/calc. We neglected to mention this - AND /usr/local would have been a better choice. Sorry! - Fixed in calc version 2.12.5.3. + installed under /opt/calc. We neglected to mention this + AND /usr/local would have been a better choice. Sorry! + Fixed in calc version 2.12.5.3. Removed rules and makefile variables associated with shortened calc version numbers of less than 4 levels. @@ -2319,16 +2326,16 @@ The following are the changes from calc version 2.12.5.1 to 2.12.5.2: Lowered REDC levels: - #define MAXREDC 256 /* number of entries in REDC cache */ + #define MAXREDC 256 /* number of entries in REDC cache */ - #define SQ_ALG2 28 /* size for alternative squaring */ - config("sq2") == 28 /* was 3388 */ - #define MUL_ALG2 28 /* size for alternative multiply */ - config("mul2") == 28 /* was 1780 */ - #define POW_ALG2 20 /* size for using REDC for powers */ - config("pow2") == 20 /* was 176 */ - #define REDC_ALG2 25 /* size for using alternative REDC */ - config("redc2") == 25 /* was 220 */ + #define SQ_ALG2 28 /* size for alternative squaring */ + config("sq2") == 28 /* was 3388 */ + #define MUL_ALG2 28 /* size for alternative multiply */ + config("mul2") == 28 /* was 1780 */ + #define POW_ALG2 20 /* size for using REDC for powers */ + config("pow2") == 20 /* was 176 */ + #define REDC_ALG2 25 /* size for using alternative REDC */ + config("redc2") == 25 /* was 220 */ The alg_config.cal script appears to be not correctly finding the best REDC values. While it has been improved, alg_config.cal still @@ -2342,30 +2349,30 @@ The following are the changes from calc version 2.12.5.0 to 2.12.5.1: There is a new calc bug report Email address: -NOTE: calc-bug-report Email address no longer in use +NOTE: calc-bug-report Email address no longer in use - This replaces the old calc-bugs Email address. + This replaces the old calc-bugs Email address. - To be sure we see your Email reporting a calc bug, please use the - following phase in your Email Subject line: + To be sure we see your Email reporting a calc bug, please use the + following phase in your Email Subject line: - calc bug report + calc bug report - That phrase in your subject line will help ensure your - request will get past our anti-spam filters. You may have - additional words in your subject line. + That phrase in your subject line will help ensure your + request will get past our anti-spam filters. You may have + additional words in your subject line. - However, you may find it more helpful to simply subscribe - to the calc-tester mailing list (see above) and then to - send your report to that mailing list as a wider set calc - testers may be able to help you. + However, you may find it more helpful to simply subscribe + to the calc-tester mailing list (see above) and then to + send your report to that mailing list as a wider set calc + testers may be able to help you. The following makefile rules that were related to printing the upper values of the calc version, rules that were made obsolete in calc version 2.12.4.14, have been removed: - calc_vers calc_ver calc_ve - vers ver ve + calc_vers calc_ver calc_ve + vers ver ve Noted that the hash() builtin function, internally known as quickhash (used for internal objects such as the associative @@ -2379,11 +2386,11 @@ The following are the changes from calc version 2.12.4.14 to 2.12.5.0: For Apple OS X / Darwin target: - MACOSX_DEPLOYMENT_TARGET is no longer defined - using clang compiler + MACOSX_DEPLOYMENT_TARGET is no longer defined + using clang compiler - By default, -install-name is used when forming shared libs. - To force -install-name to not be used, set SET_INSTALL_NAME=no. + By default, -install-name is used when forming shared libs. + To force -install-name to not be used, set SET_INSTALL_NAME=no. The have_stdvs.c test uses and fixed va_start() test call that didn't use last arg. @@ -2405,27 +2412,27 @@ The following are the changes from calc version 2.12.4.14 to 2.12.5.0: We made important fixes to the calc command line history: - Fixed a bug in the command line history where calc would sometimes - crash. There was code that used memcpy() instead of memmove() - that could corrupt the command line history when entering a - into into history that was similar to a previous entry. Thanks - goes to Einar Lielmanis for first - identifying this mistake. + Fixed a bug in the command line history where calc would sometimes + crash. There was code that used memcpy() instead of memmove() + that could corrupt the command line history when entering a + into into history that was similar to a previous entry. Thanks + goes to Einar Lielmanis for first + identifying this mistake. - The calc command line history code, in general was not robust. - We made use a patch from Mathias Buhr , that while it uses a bit more memory: is much more - flexible, readable and robust. This patch replaced the improper - use of memcpy() (see above) with better code. Thanks! + The calc command line history code, in general was not robust. + We made use a patch from Mathias Buhr , that while it uses a bit more memory: is much more + flexible, readable and robust. This patch replaced the improper + use of memcpy() (see above) with better code. Thanks! The alg_config.cal calc resource file has been reworked to produce better diagnostics while attempting to determine the ideal values for mul2, sq2, and pow2. However, it has been shown that this code is not correct. Suggestions for a replacement are welcome! - calc -u 'read alg_config; config("user_debug", 2),; best_mul2();' - calc -u 'read alg_config; config("user_debug", 2),; best_sq2();' - calc -u 'read alg_config; config("user_debug", 2),; best_pow2();' + calc -u 'read alg_config; config("user_debug", 2),; best_mul2();' + calc -u 'read alg_config; config("user_debug", 2),; best_sq2();' + calc -u 'read alg_config; config("user_debug", 2),; best_pow2();' Fixed a number of pedantic compiler warnings. @@ -2507,20 +2514,20 @@ The following are the changes from calc version 2.12.4.11 to 2.12.4.13: Calc source code is now picky v2.3 clean using: - picky -s -v file file2 .. + picky -s -v file file2 .. With the exception of: - help/errorcodes.sed - cal/set8700.line + help/errorcodes.sed + cal/set8700.line Due to the long lines in those files, we use: - picky -w -s -v help/errorcodes.sed cal/set8700.line + picky -w -s -v help/errorcodes.sed cal/set8700.line For more information about the picky tool, see: - http://cis.csuohio.edu/~somos/picky.html + http://cis.csuohio.edu/~somos/picky.html Removed functions from strings.cal that have been replaced by the new ctype-like builtin functions. @@ -2576,7 +2583,7 @@ The following are the changes from calc version 2.12.4.6 to version 2.12.4.10: Improved the formatting of the output from: - help resource + help resource We replaced COPYING-LGPL with the version that is found at http://www.gnu.org/licenses/lgpl-2.1.txt because that version @@ -2586,20 +2593,20 @@ The following are the changes from calc version 2.12.4.6 to version 2.12.4.10: We fixed a number of places where "the the" was used when just "the" should be used. - NOTE: Fixes to grammar, spelling and minor formatting - problems are welcome. Please send us your patches! + NOTE: Fixes to grammar, spelling and minor formatting + problems are welcome. Please send us your patches! With the exception of 3 source files, we became "picky" about line lengths and other issues reported by the picky tool: - cal/test8900.cal - cal/set8700.line - help/errorcodes.sed + cal/test8900.cal + cal/set8700.line + help/errorcodes.sed The above 3 files now pass picky -w (OK except for line length). For more information about the picky tool, see: - http://cis.csuohio.edu/~somos/picky.html + http://cis.csuohio.edu/~somos/picky.html The following are the changes from calc version 2.12.4.3 to 2.12.4.5: @@ -2648,7 +2655,7 @@ The following are the changes from calc version 2.12.4.0 to 2.12.4.2: Added prep makefile rule to make is easier to compile calc without an optimizer. By doing: - make clobber prep + make clobber prep one may build a calc binary that is easier to debug. @@ -2750,9 +2757,9 @@ The following are the changes from calc version 2.12.1.1 to 2.12.2.2: for installation on a production system. To get the same effect as the calc binary in the calc rpm, try: - make clobber - make calc-dynamic-only BLD_TYPE=calc-dynamic-only LD_SHARE= - make install + make clobber + make calc-dynamic-only BLD_TYPE=calc-dynamic-only LD_SHARE= + make install The libcalc and libcustcalc shared libraries are now tied to the 4 level calc version instead of just 3 levels. For example, @@ -2768,11 +2775,11 @@ The following are the changes from calc version 2.12.1.1 to 2.12.2.2: Added this high priority item to the calc help/todo list: - It is overkill to have nearly everything wind up in libcalc. - Form a libcalcmath and a libcalclang so that an application - that just wants to link with the calc math libs can use them - without dragging in all of the other calc language, I/O, - and builtin functions. + It is overkill to have nearly everything wind up in libcalc. + Form a libcalcmath and a libcalclang so that an application + that just wants to link with the calc math libs can use them + without dragging in all of the other calc language, I/O, + and builtin functions. Fixed the wording for the -i flag in the calc man page. @@ -2805,11 +2812,11 @@ The following are the changes from calc version 2.12.1.1 to 2.12.2.2: what was calc-something.tar.gz is now calc-something.tar.bz2. To "uncompress" use: - bunzip2 calc-something.tar.bz2 + bunzip2 calc-something.tar.bz2 On some systems, one may untar directly by: - tar -jxvf calc-something.tar.bz2 + tar -jxvf calc-something.tar.bz2 The Makefile variable ${BYTE_ORDER} was replaced by ${CALC_BYTE_ORDER}. @@ -2863,19 +2870,19 @@ The following are the changes from calc version 2.12.1.10 to 2.12.2: Renamed the following source files: - math_error.h ==> lib_calc.h - string.c ==> str.c - string.h ==> str.h + math_error.h ==> lib_calc.h + string.c ==> str.c + string.h ==> str.h Renamed the following variables related to calc error processing: - int calc_jmp ==> int calc_use_matherr_jmpbuf - jmp_buf calc_jmp_buf ==> jmp_buf calc_matherr_jmpbuf + int calc_jmp ==> int calc_use_matherr_jmpbuf + jmp_buf calc_jmp_buf ==> jmp_buf calc_matherr_jmpbuf - int post_init ==> int calc_use_scanerr_jmpbuf - jmp_buf jmpbuf ==> jmpbuf calc_scanerr_jmpbuf + int post_init ==> int calc_use_scanerr_jmpbuf + jmp_buf jmpbuf ==> jmpbuf calc_scanerr_jmpbuf - char *calc_error ==> char calc_err_msg[MAXERROR+1] + char *calc_error ==> char calc_err_msg[MAXERROR+1] These values are now declared in the lib_calc.h include file. The value MAXERROR is now defined in lib_calc.h instead of calc.h. @@ -2885,7 +2892,7 @@ The following are the changes from calc version 2.12.1.10 to 2.12.2: Parse/scan errors will not be printed if calc_print_scanerr_msg is zero. By default: - int calc_print_scanerr_msg = 1; + int calc_print_scanerr_msg = 1; This variable is declared in the lib_calc.h include file. Storage comes from libcalc. @@ -2893,7 +2900,7 @@ The following are the changes from calc version 2.12.1.10 to 2.12.2: Parse/scan warnings will not be printed if calc_print_scanwarn_msg is zero. By default: - int calc_print_scanwarn_msg = 1; + int calc_print_scanwarn_msg = 1; This variable is declared in the lib_calc.h include file. Storage comes from libcalc. @@ -2929,20 +2936,20 @@ The following are the changes from calc version 2.12.1.10 to 2.12.2: Replaced the concept of compiler sets in the Makefile with host target section in the Makefile. Initial host targets are: - Linux - Darwin - FreeBSD - (default) <<== Target does not match any previous target name - Simple + Linux + Darwin + FreeBSD + (default) <<== Target does not match any previous target name + Simple - NOTE: If your target is not supported below and the default target - is not suitable for your needs, please send to the: + NOTE: If your target is not supported below and the default target + is not suitable for your needs, please send to the: -NOTE: calc-contrib Email address no longer in use +NOTE: calc-contrib Email address no longer in use - Email address an "ifeq ($(target),YOUR_TARGET_NAME)" - ... "endif" set of lines from the Makefile so that - we can consider them for the next release. + Email address an "ifeq ($(target),YOUR_TARGET_NAME)" + ... "endif" set of lines from the Makefile so that + we can consider them for the next release. The custom/Makefile is now constructed from 3 parts: custom/Makefile.head, the host target section in Makefile, and the custom/Makefile.tail. @@ -2956,11 +2963,11 @@ NOTE: calc-contrib Email address no longer in use you should try using the Makefile.simple and custom/Makefile.simple files: - mv Makefile Makefile.gmake - cp Makefile.simple Makefile - mv custom/Makefile custom/Makefile.gmake - cp custom/Makefile.simple custom/Makefile - make all + mv Makefile Makefile.gmake + cp Makefile.simple Makefile + mv custom/Makefile custom/Makefile.gmake + cp custom/Makefile.simple custom/Makefile + make all Added the ability to build calc with dynamic libraries, static libraries or both. Many thanks goes to Matthew Miller (mattdm @@ -2970,21 +2977,21 @@ NOTE: calc-contrib Email address no longer in use Added BLD_TYPE Makefile variable to control how calc is built. The BLD_TYPE value may be one of: - BLD_TYPE= calc-dynamic-only - BLD_TYPE= calc-static-only + BLD_TYPE= calc-dynamic-only + BLD_TYPE= calc-static-only Each host target establishes a default BLD_TYPE value. Of course one can override the host target BLD_TYPE on the make command line: - make clobber - make calc-dynamic-only BLD_TYPE=calc-dynamic-only + make clobber + make calc-dynamic-only BLD_TYPE=calc-dynamic-only - make clobber - make calc-static-only BLD_TYPE=calc-static-only + make clobber + make calc-static-only BLD_TYPE=calc-static-only - NOTE: It is a very good idea to first clobber (remove) any previously - built .o, libs and executables before switching the build - between static and dynamic. + NOTE: It is a very good idea to first clobber (remove) any previously + built .o, libs and executables before switching the build + between static and dynamic. which have the same effect as make all with a given build phase set. @@ -3042,17 +3049,17 @@ NOTE: calc-contrib Email address no longer in use Added custom registers. The custom register function: - custom("register", 3) + custom("register", 3) returns the value of custom register 3. Custom registers, initialized with 0, may take on any calc value: - custom("register", regnum, value) + custom("register", regnum, value) Added REGNUM_MAX to the sysinfo custom function to return the maximum register number: - custom("sysinfo", "REGNUM_MAX") + custom("sysinfo", "REGNUM_MAX") which defaults to 31. The first custom register is 0 and thus the default number of custom registers is 32. @@ -3069,8 +3076,8 @@ NOTE: calc-contrib Email address no longer in use For a ^ b and a ** b, "a" and "b" can be a real value or a complex value: 2^3 3i^4 - 2.5 ^ 3.5 0.5i ^ 0.25 - 2.5 ^ 2.718i 3.13145i ^ 0.30103i + 2.5 ^ 3.5 0.5i ^ 0.25 + 2.5 ^ 2.718i 3.13145i ^ 0.30103i Fixed typos in the calc man page thanks to a Debian bug report by A. Costa that was kindly forwarded @@ -3083,26 +3090,26 @@ The following are the changes from calc version 2.12.1.8 to 2.12.1.9: comments. Improved calc comment documentation in "help unexpected" to help other avoid similar mistakes. Calc comments are of the form: - /* c style comments */ - /* - * multi-line - * comments - */ - ## two or more #-signs - ### in a row - ### Note that # along is a calc unary and binary operator + /* c style comments */ + /* + * multi-line + * comments + */ + ## two or more #-signs + ### in a row + ### Note that # along is a calc unary and binary operator Added "help pound" or "help #' to document the # operator, comments, and the first line of cscript files. Documented these help commands in "help help": - help -> - help * - help . - help % - help // - help # + help -> + help * + help . + help % + help // + help # The usage help file is now formed from the contents of the calc man page. So "help usage" prints the version of the calc man page. Added ${COL} @@ -3180,26 +3187,26 @@ The following are the changes from calc version 2.12.1.6 to 2.12.1.7: Documented the mis-feature about how calc parses if, for, while and do statements in an unexpected way. For example: - This works as expected: + This works as expected: - if (expr) { - ... - } + if (expr) { + ... + } - However this WILL NOT WORK AS EXPECTED: + However this WILL NOT WORK AS EXPECTED: - if (expr) - { - ... - } + if (expr) + { + ... + } - because calc will parse the if being terminated by - an empty statement followed by a + because calc will parse the if being terminated by + an empty statement followed by a - if (expr) ; - { - ... - } + if (expr) ; + { + ... + } See also "help statement", "help unexpected", "help todo", and "help bugs". @@ -3269,8 +3276,8 @@ The following are the changes from calc version 2.12.0 to 2.12.0.8: etc.) for VT100 terminals and terminal window emulators (i.e., xterm, Apple OS/X Terminal, etc.) that support them. For example: - ; read screen - ; print green:"This is green. ":red:"This is red.":black + ; read screen + ; print green:"This is green. ":red:"This is red.":black Fixed a bug where too many open files returned E_FOPEN3. Now a new error symbol F_MANYOPEN is used for too many open files. @@ -3278,9 +3285,9 @@ The following are the changes from calc version 2.12.0 to 2.12.0.8: Added the builtin function fpathopen() to open a file while searching along a path: - ; fd2 = fpathopen("tmp/date", "r", ".:~:~sc:/tmp:/var/tmp:/var") - ; print fd2 - "/var/tmp/date" + ; fd2 = fpathopen("tmp/date", "r", ".:~:~sc:/tmp:/var/tmp:/var") + ; print fd2 + "/var/tmp/date" By default, fpathopen() searches along CALCPATH. @@ -3328,51 +3335,51 @@ The following are the changes from calc version 2.12.0 to 2.12.0.8: level. When comparing with older source, one may use the -b argument of the diff command to ignore changes in amount of white space: - diff -b -r -u calc-2.11.11 calc-2.12.0 + diff -b -r -u calc-2.11.11 calc-2.12.0 The read, write, and help commands use the value of global string variable if the symbol name starts with a $. For example: - global x = "lucas.cal"; - read $x; /* same as read lucas.cal or read "lucas.cal" */ + global x = "lucas.cal"; + read $x; /* same as read lucas.cal or read "lucas.cal" */ Added dotest.cal resource. Based on a design by Ernest Bowen , the dotest evaluates individual lines from a file. The dotest() function takes 1 to 3 arguments: - dotest(dotest_file [,dotest_code [,dotest_maxcond]]) + dotest(dotest_file [,dotest_code [,dotest_maxcond]]) - dotest_file + dotest_file - Search along CALCPATH for dotest_file, which contains lines that - should evaluate to 1. Comment lines and empty lines are ignored. - Comment lines should use ## instead of the multi like /* ... */ - because lines are evaluated one line at a time. + Search along CALCPATH for dotest_file, which contains lines that + should evaluate to 1. Comment lines and empty lines are ignored. + Comment lines should use ## instead of the multi like /* ... */ + because lines are evaluated one line at a time. - dotest_code + dotest_code - Assign the code number that is to be printed at the start of - each non-error line and after **** in each error line. - The default code number is 999. + Assign the code number that is to be printed at the start of + each non-error line and after **** in each error line. + The default code number is 999. - dotest_maxcond + dotest_maxcond - The maximum number of error conditions that may be detected. - An error condition is not a sign of a problem, in some cases - a line deliberately forces an error condition. A value of -1, - the default, implies a maximum of 2147483647. + The maximum number of error conditions that may be detected. + An error condition is not a sign of a problem, in some cases + a line deliberately forces an error condition. A value of -1, + the default, implies a maximum of 2147483647. - Global variables and functions must be declared ahead of time because - the dotest scope of evaluation is a line at a time. For example: + Global variables and functions must be declared ahead of time because + the dotest scope of evaluation is a line at a time. For example: - ; read dotest.cal - ; read set8700.cal - ; dotest("set8700.line"); + ; read dotest.cal + ; read set8700.cal + ; dotest("set8700.line"); Updated the todo / wish list items. The top priority now is to convert calc to GNU autoconf / configure to build the calc. - ; help todo + ; help todo Added missing help file for the stoponerror() builtin. @@ -3443,42 +3450,42 @@ The following are the changes from calc version 2.12.0 to 2.12.0.8: Changed the default values for the following config() parameters: - config("mul2") == 1780 - config("sq2") == 3388 - config("pow2") == 176 + config("mul2") == 1780 + config("sq2") == 3388 + config("pow2") == 176 - These values were determined established on a 1.8GHz AMD 32-bit - CPU of ~3406 BogoMIPS by the new resource file: + These values were determined established on a 1.8GHz AMD 32-bit + CPU of ~3406 BogoMIPS by the new resource file: - cal/alg_config.cal + cal/alg_config.cal Regarding the alg_config.cal resource file: - The best_mul2() function returns the optimal value of config("mul2"). - The best_sq2() function returns the optimal value of config("sq2"). - The best_pow2() function returns the optimal value of config("pow2"). - The other functions are just support functions. + The best_mul2() function returns the optimal value of config("mul2"). + The best_sq2() function returns the optimal value of config("sq2"). + The best_pow2() function returns the optimal value of config("pow2"). + The other functions are just support functions. - By design, best_mul2(), best_sq2(), and best_pow2() take a few - minutes to run. These functions increase the number of times a - given computational loop is executed until a minimum amount of CPU - time is consumed. To watch these functions progress, one can set - the config("user_debug") value. + By design, best_mul2(), best_sq2(), and best_pow2() take a few + minutes to run. These functions increase the number of times a + given computational loop is executed until a minimum amount of CPU + time is consumed. To watch these functions progress, one can set + the config("user_debug") value. - Here is a suggested way to use the alg_config.cal resource file: + Here is a suggested way to use the alg_config.cal resource file: - ; read alg_config - ; config("user_debug",2),; - ; best_mul2(); best_sq2(); best_pow2(); - ; best_mul2(); best_sq2(); best_pow2(); - ; best_mul2(); best_sq2(); best_pow2(); + ; read alg_config + ; config("user_debug",2),; + ; best_mul2(); best_sq2(); best_pow2(); + ; best_mul2(); best_sq2(); best_pow2(); + ; best_mul2(); best_sq2(); best_pow2(); - NOTE: It is perfectly normal for the optimal value returned - to differ slightly from run to run. Slight variations due to - inaccuracy in CPU timings will cause the best value returned to - differ slightly from run to run. + NOTE: It is perfectly normal for the optimal value returned + to differ slightly from run to run. Slight variations due to + inaccuracy in CPU timings will cause the best value returned to + differ slightly from run to run. - See "help resource" for more information on alg_config.cal. + See "help resource" for more information on alg_config.cal. Updated the "help variable" text to reflect the current calc use of ` (backquote), * (star), and & (ampersand). @@ -3486,46 +3493,46 @@ The following are the changes from calc version 2.12.0 to 2.12.0.8: Removal of some restrictions on the use of the same identifier for more than one of parameter, local, static or global variable. - For example, at command level, one could use: + For example, at command level, one could use: - for (local x = 0; x < 10; x++) print sqrt(x); + for (local x = 0; x < 10; x++) print sqrt(x); - At the beginning of a statement, "(global A)" is a way of - indicating a reference to the variable A, whereas "global A" - would be taken as a declaration. Parentheses are not required in - "++global A" or "global A++" when "global" is used in this way. + At the beginning of a statement, "(global A)" is a way of + indicating a reference to the variable A, whereas "global A" + would be taken as a declaration. Parentheses are not required in + "++global A" or "global A++" when "global" is used in this way. - The patch extends this "specifier" (or "qualifier") feature - to static variables, but such that "static A" refers only - to a static variable at the current file and function scope - levels. (If there is already a static variable A at the current - file and function levels, a declaration statement "static A" - would end the scope of that variable and define a new static - variable with identifier A. A "global A" declaration is more - drastic in that it ends the scope of any static variable A at - the same or higher scope levels.) + The patch extends this "specifier" (or "qualifier") feature + to static variables, but such that "static A" refers only + to a static variable at the current file and function scope + levels. (If there is already a static variable A at the current + file and function levels, a declaration statement "static A" + would end the scope of that variable and define a new static + variable with identifier A. A "global A" declaration is more + drastic in that it ends the scope of any static variable A at + the same or higher scope levels.) - Unlike a static declaration in which an "initialization" occurs at - most once, in the specifier case, "static A = expr" is simply an - assignment which may be repeated any number of times. An example - of its use is: + Unlike a static declaration in which an "initialization" occurs at + most once, in the specifier case, "static A = expr" is simply an + assignment which may be repeated any number of times. An example + of its use is: - define np() = static a = nextprime(a); + define np() = static a = nextprime(a); - For n not too large, the n-th call to this function will - return the n-th prime. The variable a here will be private to - the function. + For n not too large, the n-th call to this function will + return the n-th prime. The variable a here will be private to + the function. - Because one can use "global", "local" or "static" to specify a - type of variable, there seems little point in restricting the - ways identifiers that can be used in more than one of these - or as parameters. Obviously, introducing A as a local variable - when it is being used as a parameter can lead to confusion and a - warning is appropriate, but if it is to be used only occasionally, - it might be convenient to be able to refer to it as "local A" - rather than introducing another identifier. While it may be - silly to use the same identifier for both a parameter and local - variable, it should not be illegal. + Because one can use "global", "local" or "static" to specify a + type of variable, there seems little point in restricting the + ways identifiers that can be used in more than one of these + or as parameters. Obviously, introducing A as a local variable + when it is being used as a parameter can lead to confusion and a + warning is appropriate, but if it is to be used only occasionally, + it might be convenient to be able to refer to it as "local A" + rather than introducing another identifier. While it may be + silly to use the same identifier for both a parameter and local + variable, it should not be illegal. Added warnings for possibly questionable code in function definitions. @@ -3538,10 +3545,10 @@ The following are the changes from calc version 2.12.0 to 2.12.0.8: value is TRUE by default. Examples of variable name collisions include when: - * both local and static variables have the same name - * both local and global variables have the same name - * both function parameter and local variables have the same name - * both function parameter and global variables have the same name + * both local and static variables have the same name + * both local and global variables have the same name + * both function parameter and local variables have the same name + * both function parameter and global variables have the same name Fix of a bug which causes some static variables not to be correctly unscoped when their identifiers are used in a global declaration. @@ -3561,7 +3568,7 @@ The following are the changes from calc version 2.12.0 to 2.12.0.8: Changed the definition of the function ssq() to enable list arguments to be processed in the same way as in sum(). For example: - ssq(1,2, list(3,4,list(5,6)), list(), 7, 8) + ssq(1,2, list(3,4,list(5,6)), list(), 7, 8) returns the value of 1^2 + 2^2 + ... + 8^2 == 204. @@ -3569,8 +3576,8 @@ The following are the changes from calc version 2.12.0 to 2.12.0.8: various ways of evaluating sums, sums of squares, etc, for large lists and matrices. For example: - read sumtimes - doalltimes(1e6) + read sumtimes + doalltimes(1e6) Calc now ignores carriage returns (\r), vertical tabs (\v), and form feeds (\f) when token parsing. Thus users on Windows systems @@ -3608,7 +3615,7 @@ The following are the changes from calc version 2.11.10.1 to 2.11.11: Fixed a bug reported by the sourceforge user: cedars where: - ln(exp(6)) == 3 /* WRONG!!! */ + ln(exp(6)) == 3 /* WRONG!!! */ incorrectly returned 1. This bug was fixed by Ernest Bowen . The regression test @@ -3625,7 +3632,7 @@ The following are the changes from calc version 2.11.10.1 to 2.11.11: Added the bug about: - calc 'read ellip; efactor(13*17*19)' + calc 'read ellip; efactor(13*17*19)' to the BUGS file. See "help bugs" or the BUGS source file for details. Anyone want to track down and fix this bug? @@ -3645,15 +3652,15 @@ The following are the changes from calc version 2.11.10.1 to 2.11.11: Changed the calc man page to note that using -- in the command will separate calc options from arguments as in: - calc -p -- -1 - -7 + calc -p -- -1 - -7 Noted how Apple OS X can make use of readline in the Makefile. In particular: - # For Apple OS X: install fink from http://fink.sourceforge.net - # and then do a 'fink install readline' and then use: - # - READLINE_LIB= -L/sw/lib -lreadline -lhistory -lncurses + # For Apple OS X: install fink from http://fink.sourceforge.net + # and then do a 'fink install readline' and then use: + # + READLINE_LIB= -L/sw/lib -lreadline -lhistory -lncurses Added linear.cal as a calc standard resource file. @@ -3713,7 +3720,7 @@ The following are the changes from calc version 2.11.10 to 2.11.10: Fixed -d so that: - calc -d 2/3 + calc -d 2/3 will print 0.66666666666666666667 without the leading tilde as advertised in the man page. @@ -3733,7 +3740,7 @@ The following are the changes from calc version 2.11.10 to 2.11.10: Added custom function: - custom("pmodm127", q) + custom("pmodm127", q) to compute 2^(2^127-1) mod q. While currently slower than just doing pmod(2,2^127-1,q), it is added to give an example of a @@ -3783,14 +3790,14 @@ The following are the changes from calc version 2.11.9 to 2.11.9.3: The Makefile builds have_unused.h which defines, if the unused attribute is supported: - #define HAVE_UNUSED /* yes */ - #define UNUSED __attribute__((unused)) /* yes */ + #define HAVE_UNUSED /* yes */ + #define UNUSED __attribute__((unused)) /* yes */ or defines, if the unused is not supported (or if the Makefile variable is HAVE_UNUSED= -DHAVE_NO_UNUSED): - #undef HAVE_UNUSED /* no */ - #define UNUSED /* no */ + #undef HAVE_UNUSED /* no */ + #define UNUSED /* no */ Fixed numerous warnings about comparison between signed and unsigned value warnings and unused parameter warnings in version.c, zrand.c, @@ -3824,7 +3831,7 @@ The following are the changes from calc version 2.11.8.0 to 2.11.8.1: configuration (calc -n or config("all", "newstd")) is now the default calc configuration. The flag: - calc -O + calc -O was added to get the old classic calc configuration. The flag command line flag, -n, now does nothing. Use of -n is deprecated and may go @@ -3832,17 +3839,17 @@ The following are the changes from calc version 2.11.8.0 to 2.11.8.1: The following table gives the summary of these changes: - pre v2.11.8 v2.11.8 - default pre v2.11.8 -O & oldstd v2.11.8 - and oldstd -n & newstd classic cfg default - -------------------------------------------------------- - epsilon 1e-20 1e-10 1e-20 1e-20 - quo 2 2 2 2 - outround 2 24 2 24 - leadzero 0 1 0 1 - fullzero 0 1 0 0 - prompt > ; > ; - more >> ;; >> ;; + pre v2.11.8 v2.11.8 + default pre v2.11.8 -O & oldstd v2.11.8 + and oldstd -n & newstd classic cfg default + -------------------------------------------------------- + epsilon 1e-20 1e-10 1e-20 1e-20 + quo 2 2 2 2 + outround 2 24 2 24 + leadzero 0 1 0 1 + fullzero 0 1 0 0 + prompt > ; > ; + more >> ;; >> ;; With the exception of epsilon being 1e-20, and fullzero being unset, the new default calc config is like it was (pre-2.11.8) with calc -n / @@ -3937,15 +3944,15 @@ The following are the changes from calc version 2.11.6.0 to 2.11.6.2: a value in two bases. Flipping back and forth between to bases is a bit of a pain. With base2(), calc will output a value twice: - ; 234567 - 234567 - ; base2(16), - ; 234567 - 234567 /* 0x39447 */ - ; 131072 - 131072 /* 0x20000 */ - ; base2(0), - ; 131072 + ; 234567 + 234567 + ; base2(16), + ; 234567 + 234567 /* 0x39447 */ + ; 131072 + 131072 /* 0x20000 */ + ; base2(0), + ; 131072 131072 By default, base2() is disabled. Calling base2(0) will also turn @@ -3955,13 +3962,13 @@ The following are the changes from calc version 2.11.6.0 to 2.11.6.2: Added repeat.cal as a calc resource file script: - repeat(digit_set, repeat_count) + repeat(digit_set, repeat_count) - Return the value of the digit_set repeated repeat_count times. - Both digit_set and repeat_count must be integers > 0. + Return the value of the digit_set repeated repeat_count times. + Both digit_set and repeat_count must be integers > 0. - For example repeat(423,5) returns the value 423423423423423, - which is the digit_set 423 repeated 5 times. + For example repeat(423,5) returns the value 423423423423423, + which is the digit_set 423 repeated 5 times. Makefile no longer makes a direct reference to Red Hat 6.0. @@ -4001,16 +4008,16 @@ The following are the changes from calc version 2.11.5.5 to 2.11.5.9: Now using version numbers of one of these forms: - x.y.z.w - x.y.z - x.y + x.y.z.w + x.y.z + x.y Changed the READLINE_LIB Makefile variable to not link with -lreadline by default. If you do have readline, we recommend that you use it. If you can install the GNU readline: - http://freshmeat.net/projects/gnureadline/ - http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html + http://freshmeat.net/projects/gnureadline/ + http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html we recommend it. But if not, you should set the USE_READLINE, READLINE_LIB, and READLINE_INCLUDE Makefile variables to empty. @@ -4082,18 +4089,18 @@ The following are the changes from calc version 2.11.5t4.1 to 2.11.5t4.4: Added subject requirements for the calc-tester-request and calc-bugs-mail Email aliases. See: - http://www.isthe.com/chongo/tech/comp/calc/email.html + http://www.isthe.com/chongo/tech/comp/calc/email.html for details. Corrected a bug that incorrectly set the default calc path back in version 2.11.5t4. The default CALCPATH is now: - .:./cal:~/.cal:/usr/share/calc:/usr/share/calc/custom + .:./cal:~/.cal:/usr/share/calc:/usr/share/calc/custom and the default CALCRC is now: - /usr/share/calc/startup:~/.calcrc:./.calcinit + /usr/share/calc/startup:~/.calcrc:./.calcinit This fixes the missing bindings error and it places the calc resource files into the default path. @@ -4147,7 +4154,7 @@ The following are the changes from calc version 2.11.5t3 to 2.11.5t4: Added the cscript: - powerterm [base_limit] value + powerterm [base_limit] value to write the value as the sum (or difference) of powers <= base_limit where base_limit by default is 10000. @@ -4168,22 +4175,22 @@ The following are the changes from calc version 2.11.5t3 to 2.11.5t4: Calc has new default installation locations: - Makefile var old location new location - ------------ ------------ ------------ - TOPDIR /usr/local/lib <> - BINDIR /usr/local/bin /usr/bin - SHAREDIR <> /usr/share - INCDIR /usr/local/include /usr/include - LIBDIR /usr/local/lib/calc /usr/lib - CSHAREDIR <> /usr/share/calc - HELPDIR /usr/local/lib/calc/help /usr/share/calc/help - INCDIRCALC /usr/local/include/calc /usr/include/calc - CUSTOMLIBDIR /usr/local/lib/calc/custom /usr/share/calc/custom + Makefile var old location new location + ------------ ------------ ------------ + TOPDIR /usr/local/lib <> + BINDIR /usr/local/bin /usr/bin + SHAREDIR <> /usr/share + INCDIR /usr/local/include /usr/include + LIBDIR /usr/local/lib/calc /usr/lib + CSHAREDIR <> /usr/share/calc + HELPDIR /usr/local/lib/calc/help /usr/share/calc/help + INCDIRCALC /usr/local/include/calc /usr/include/calc + CUSTOMLIBDIR /usr/local/lib/calc/custom /usr/share/calc/custom CUSTOMHELPDIR /usr/local/lib/calc/help/custhelp /usr/share/calc/custhelp - CUSTOMINCDIR <> /usr/include/calc/custom - SCRIPTDIR /usr/local/bin/cscript /usr/bin/cscript - MANDIR <> /usr/share/man/man1 - CATDIR <> <> + CUSTOMINCDIR <> /usr/include/calc/custom + SCRIPTDIR /usr/local/bin/cscript /usr/bin/cscript + MANDIR <> /usr/share/man/man1 + CATDIR <> <> The Makefile variable ${TOPDIR} is no longer used. In some places it has been replaced by a new Makefile variable ${SHAREDIR}. Some @@ -4201,7 +4208,7 @@ The following are the changes from calc version 2.11.5t3 to 2.11.5t4: If you install using the new default locations, you can remove old calc files installed in the old default location by doing: - make olduninstall + make olduninstall The following are the changes from calc version 2.11.5t2 to 2.11.5t2.1: @@ -4249,7 +4256,7 @@ The following are the changes from calc version 2.11.5t2 to 2.11.5t2.1: Applied a bug fix from Ernest Bowen dealing with one-line "static" declaration like: - static a = 1, b; + static a = 1, b; Added regression test 8310 to test for the static bug fix. @@ -4313,44 +4320,44 @@ The following are the changes from calc version 2.11.5t0 to 2.11.5t1.1: Added intfile.cal as a calc resource file script: - file2be(filename) + 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. + 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) + 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. + 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) + 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. + 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) + 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. + Write the absolute value of v into filename in Little Endian order. + The v argument must be on integer. The least significant bits + of the integer become the last octets of the file. Added the following help aliases: - copy blkcpy - read command - write command - quit command - exit command - abort command - cd command - show command + copy blkcpy + read command + write command + quit command + exit command + abort command + cd command + show command Added the cscript: - fproduct filename term ... + fproduct filename term ... to write the big Endian product of terms to a filename. Use - for stdout. @@ -4362,16 +4369,16 @@ The following are the changes from calc version 2.11.5t0 to 2.11.5t1.1: Configuration values that used to return "true" or "false" now return 1 (a true value) or 0 (a false value). Thus one can do: - if (config("tab")) { ... } else { ... } + if (config("tab")) { ... } else { ... } The configuration values that now return 1 or 0 are: - config("tilde") - config("tab") - config("leadzero") - config("blkverbose") - config("verbose_quit") - config("windows") + config("tilde") + config("tab") + config("leadzero") + config("blkverbose") + config("verbose_quit") + config("windows") Now shipping a win32 sub-directory that contains hsrc .h files that have been attempted to be built for Windows. @@ -4429,25 +4436,25 @@ The following are the changes from calc version 2.11.3t0 to 2.11.4: command without the need to terminate the file name with a semicolon or newline. Thus: - calc "read alpha; read beta;" + calc "read alpha; read beta;" may be replaced by: - calc -f alpha -f beta + calc -f alpha -f beta Quotations marks are recognized in a command like - calc -f 'alpha beta' + calc -f 'alpha beta' in which the name of the file to be read includes a space. (2) Flags are interpreted even if they are in a string, as in: - calc "-q -i define f(x) = x^2;" + calc "-q -i define f(x) = x^2;" which has the effect of: - calc -q -i "define f(x) = x^2;" + calc -q -i "define f(x) = x^2;" To achieve this, the use of getopts() in calc.c has been dropped in favor of direct reading of the arguments produced by the shell. @@ -4461,21 +4468,21 @@ The following are the changes from calc version 2.11.3t0 to 2.11.4: line starting with "#!", the starting of options with -S has been replaced by ending the options with -f. For example, the first line: - #! full_pathname_for_calc -S -q -i + #! full_pathname_for_calc -S -q -i is to be replaced by: - #! full_pathname_for_calc -q -i -f + #! full_pathname_for_calc -q -i -f Thus, if the pathname is /usr/bin/calc and myfile contains: - #!/usr/bin/calc -q -i -f - global deg = pi()/180; - define Sin(x) = sin(x * deg); + #!/usr/bin/calc -q -i -f + global deg = pi()/180; + define Sin(x) = sin(x * deg); and has been made executable by: - chmod u+x myfile + chmod u+x myfile myfile would be like a version of calc that ignored any startup files and had an already defined global variable deg and a function @@ -4484,7 +4491,7 @@ The following are the changes from calc version 2.11.3t0 to 2.11.4: the first line in the script has only flagged options) and/or calc commands as in: - ./myfile -c read alpha '; define f(x) = Sin(x)^2' + ./myfile -c read alpha '; define f(x) = Sin(x)^2' (The quotation marks avoid shell interpretation of the semicolon and parentheses.) @@ -4492,7 +4499,7 @@ The following are the changes from calc version 2.11.3t0 to 2.11.4: (4) The old -S syntax for executable scripts implied the -s flag so that arguments in an invocation like - ./myfile alpha beta + ./myfile alpha beta are passed to calc; in this example argv(0) = 'alpha', argv(1) = 'beta'. This has been changed in two ways: an explicit -s is required @@ -4503,53 +4510,53 @@ The following are the changes from calc version 2.11.3t0 to 2.11.4: after the one in which "-s" occurred are to be passed as arguments rather than commands or options. For example: - calc "-q -s A = 27;" alpha beta + calc "-q -s A = 27;" alpha beta invokes calc with the q-flag set, one command "A = 27;", and two arguments. (5) Piping to calc may be followed by calc becoming interactive. This should occur if there is no -p flag but -i is specified, e.g.: - cat beta | calc -i -f alpha + cat beta | calc -i -f alpha which will do essentially the same as: - calc -i -f alpha -f beta + calc -i -f alpha -f beta (6) The read and help commands have been changed so that several files may be referred to in succession by separating their names by whitespace. For example: - ; read alpha beta gamma; + ; read alpha beta gamma; does essentially the same as: - ; read alpha; read beta; read gamma; + ; read alpha; read beta; read gamma; This is convenient for commands like: - calc read file?.cal + calc read file?.cal when file?.cal expands to something like file1.cal file2.cal file3.cal: - myfiles='alpha beta gamma' - calc read $myfiles + myfiles='alpha beta gamma' + calc read $myfiles or for C-shell users: - set myfiles=(alpha beta gamma) - calc read $myfiles + set myfiles=(alpha beta gamma) + calc read $myfiles (7) The -once option for read has been extended to -f. For example, - calc -f -once alpha + calc -f -once alpha will ignore alpha if alpha has been read in the startup files. In a multiple read statement, -once applies only to the next named file. For example - ; read -once alpha beta -once gamma; + ; read -once alpha beta -once gamma; will read alpha and gamma only if they have not already been read, but in any case, will read beta. @@ -4557,7 +4564,7 @@ The following are the changes from calc version 2.11.3t0 to 2.11.4: (8) A fault in the programming for the cd command has been corrected so that specifying a directory by a string constant will work. E.g: - ; cd "my work" + ; cd "my work" should work if the current directory has a directory with name "my work". @@ -4596,19 +4603,19 @@ The following are the changes from calc version 2.11.3t0 to 2.11.4: (14) Some programming in value.c has been improved. In particular, several occurrences of: - vres->v_type = v1->v_type; - ... - if (v1->v_type < 0) { - copyvalue(v1, vres); - return; - } + vres->v_type = v1->v_type; + ... + if (v1->v_type < 0) { + copyvalue(v1, vres); + return; + } have been replaced by code that achieves exactly the same result: - vres->v_type = v1->v_type; - ... - if (v1->v_type < 0) - return; + vres->v_type = v1->v_type; + ... + if (v1->v_type < 0) + return; (15) Some operations and functions involving null-valued arguments have been changed so that they return null-value rather than "bad @@ -4617,17 +4624,17 @@ The following are the changes from calc version 2.11.3t0 to 2.11.4: (16) "global" and "local" may now be used in expressions. For example: - ; for (local i = 0; i < 5; i++) print i^2; + ; for (local i = 0; i < 5; i++) print i^2; is now acceptable, as is: - ; define f(x = global x) = (global x = x)^2; + ; define f(x = global x) = (global x = x)^2; which breaks wise programming rules and would probably better be handled by something like: - ; global x - ; define f(t = x) = (x = t)^2; + ; global x + ; define f(t = x) = (x = t)^2; Both definitions produce the same code for f. For non-null t, f(t) returns t^2 and assigns the value of t to x; f() and f(t) with null t @@ -4645,11 +4652,11 @@ The following are the changes from calc version 2.11.3t0 to 2.11.4: either 32 or 64-bit longs. In setting such components, the arguments are now to less than 2^31. Before this change: - ; config("mul2", 2^32 + 3) + ; config("mul2", 2^32 + 3) would be accepted on a 64-bit machine but result in the same as: - ; config("mul2", 3) + ; config("mul2", 3) The following are the changes from calc version 2.11.2t0 to 2.11.2t1.0: @@ -4661,9 +4668,9 @@ The following are the changes from calc version 2.11.2t0 to 2.11.2t1.0: www.isthe.com. NOTE: The Email address uses 'asthe' and the web site URL uses 'isthe'. -NOTE: calc-bugs Email address no longer in use -NOTE: calc-contrib Email address no longer in use -NOTE: calc-tester-request Email address no longer in use +NOTE: calc-bugs Email address no longer in use +NOTE: calc-contrib Email address no longer in use +NOTE: calc-tester-request Email address no longer in use Replaced explicit Email addresses found this file with the notation to reduce the potential for those folks @@ -4690,18 +4697,18 @@ The following are the changes from calc version 2.11.1 to 2.11.1t2.2: Placed calc under version 2.1 of the GNU Lesser General Public License. - The calc commands: + The calc commands: - help copyright - help copying - help copying-lgpl + help copyright + help copying + help copying-lgpl - should display the generic calc copyright as well as the contents - of the COPYING and COPYING-LGPL files. + should display the generic calc copyright as well as the contents + of the COPYING and COPYING-LGPL files. - Those files contain information about the calc's GNU Lesser General - Public License, and in particular the conditions under which you - are allowed to change it and/or distribute copies of it. + Those files contain information about the calc's GNU Lesser General + Public License, and in particular the conditions under which you + are allowed to change it and/or distribute copies of it. Removed the lint facility from the Makefile. Eliminated Makefile variables: ${LCFLAGS}, ${LINT}, ${LINTLIB} and ${LINTFLAGS}. @@ -4712,11 +4719,11 @@ The following are the changes from calc version 2.11.1 to 2.11.1t2.2: Calc source and documentation now uses these terms: - *.cal files calc resource file - *.a files calc binary link library - #! files calc shell script + *.cal files calc resource file + *.a files calc binary link library + #! files calc shell script - Renamed 'help stdlib' to 'help resource'. The 'help stdlib' is + Renamed 'help stdlib' to 'help resource'. The 'help stdlib' is aliased to 'help resource' for arg compatibility. Renamed config("lib_debug") to config("resource_debug"). @@ -4744,7 +4751,7 @@ The following are the changes from calc version 2.11.1 to 2.11.1t2.2: The following are the changes from calc version 2.11.0t10 to 2.11.0t11: - Misc code cleanup. Removed dead code. Removed trailing whitespace. + Misc code cleanup. Removed dead code. Removed trailing whitespace. Fixed whitespace to make the best use of 8 character tabs. Fixed some bugs relating to '// and %' in combination with some @@ -4769,7 +4776,7 @@ The following are the changes from calc version 2.11.0t10 to 2.11.0t11: Added zero dimensional matrices. A zero dimensional matrix is defined as: - mat A[] or A = mat[] + mat A[] or A = mat[] Updated the help/mat file to reflect the current status of matrices including zero dimensional matrices. @@ -4797,37 +4804,37 @@ The following are the changes from calc version 2.11.0t10 to 2.11.0t11: A new config("ctrl_d") value controls how the ``delete_char'', which by default is bound to ^D (Control D), will or will not exit calc: - config("ctrl_d", "virgin_eof") + config("ctrl_d", "virgin_eof") - If ^D is the only character that has been typed on a line, - then calc will exit. Otherwise ^D will act according to the - calc binding, which by default is a Emacs-style delete-char. + If ^D is the only character that has been typed on a line, + then calc will exit. Otherwise ^D will act according to the + calc binding, which by default is a Emacs-style delete-char. - This is the default mode. + This is the default mode. - config("ctrl_d", "never_eof") + config("ctrl_d", "never_eof") - The ^D never exits calc and only acts according calc binding, - which by default is a Emacs-style delete-char. + The ^D never exits calc and only acts according calc binding, + which by default is a Emacs-style delete-char. - Emacs purists may want to set this in their ~/.calcrc startup file. + Emacs purists may want to set this in their ~/.calcrc startup file. - config("ctrl_d", "empty_eof") + config("ctrl_d", "empty_eof") - The ^D always exits calc if typed on an empty line. This - condition occurs when ^D either the first character typed, - or when all other characters on the line have been removed - (say by deleting them). + The ^D always exits calc if typed on an empty line. This + condition occurs when ^D either the first character typed, + or when all other characters on the line have been removed + (say by deleting them). - Users who always want to exit when ^D is typed at the beginning - of a line may want to set this in their ~/.calcrc startup file. + Users who always want to exit when ^D is typed at the beginning + of a line may want to set this in their ~/.calcrc startup file. - Note that config("ctrl_d") apples to the character bound to each - and every ``delete_char''. So if an alternate binding it setup, - then those char(s) will have this functionality. + Note that config("ctrl_d") apples to the character bound to each + and every ``delete_char''. So if an alternate binding it setup, + then those char(s) will have this functionality. Updated help/config and help/mode, improved the readability and - fixed a few typos. Documented modes, block formats and block bases + fixed a few typos. Documented modes, block formats and block bases ("mode", "blkfmt" & "blkbase") that were previously left off out of the documentation. @@ -4847,9 +4854,9 @@ The following are the changes from calc version 2.11.0t10 to 2.11.0t11: Fixed a bug related to opening to a calc session: - define res_add(a,b) = obj res {r} = {a.r + b.r}; - ... - obj res A = {1,2}. obj res B = {3,4} + define res_add(a,b) = obj res {r} = {a.r + b.r}; + ... + obj res A = {1,2}. obj res B = {3,4} A hash of an object takes into account the object type. If X and Y are different kinds of objects but have the same component values, @@ -4859,17 +4866,17 @@ The following are the changes from calc version 2.11.0t10 to 2.11.0t11: Added support for config("ctrl_d") to the GNU-readline interface as written by Klaus Alexander Seistrup . - Currently, the config("ctrl_d", "virgin_eof") is not fully - supported. Under GNU-readline, it acts the same way as - config("ctrl_d", "empty_eof"). Emacs users may find this - objectionable as ``hi^A^D^D^D'' will cause calc to exit due to - the issuing of one too many ^D's. + Currently, the config("ctrl_d", "virgin_eof") is not fully + supported. Under GNU-readline, it acts the same way as + config("ctrl_d", "empty_eof"). Emacs users may find this + objectionable as ``hi^A^D^D^D'' will cause calc to exit due to + the issuing of one too many ^D's. - Emacs users may want to put: + Emacs users may want to put: - config("ctrl_d", "never_eof"),; + config("ctrl_d", "never_eof"),; - into their ~/.calcrc startup files to avoid this problem. + into their ~/.calcrc startup files to avoid this problem. Made misc documentation fixes. @@ -4878,86 +4885,86 @@ The following are the changes from calc version 2.11.0t10 to 2.11.0t11: Applied Ernest Bowen's complex function power(), exp() and transcendental function patch: - Calc will return a "too-large argument" error-value for exp(x, - epsilon) if re(x) >= 2^30 or if an estimate indicates that the - result will have absolute value greater than 2^2^30 * epsilon. - Otherwise the evaluation will be attempted but may fail due to - shortage of memory or may require a long runtime if the result - will be very large. + Calc will return a "too-large argument" error-value for exp(x, + epsilon) if re(x) >= 2^30 or if an estimate indicates that the + result will have absolute value greater than 2^2^30 * epsilon. + Otherwise the evaluation will be attempted but may fail due to + shortage of memory or may require a long runtime if the result + will be very large. - The power(a, b, epsilon) builtin will return a "too-large result" - if an estimate indicates that the result will have absolute value - that is > 2^2^30 * epsilon. Otherwise the evaluation will be - attempted but may fail due to shortage of memory or may require - a long runtime if the result will be very large. + The power(a, b, epsilon) builtin will return a "too-large result" + if an estimate indicates that the result will have absolute value + that is > 2^2^30 * epsilon. Otherwise the evaluation will be + attempted but may fail due to shortage of memory or may require + a long runtime if the result will be very large. - Changes have been made to the algorithms used for some special - functions sinh(), cosh(), tanh(), sin(), cos(), etc., that make - use of exp(). In particular tanh(x) is now much faster and - doesn't run out of memory when x is very large - the value to - be returned is then 1 to a high degree of accuracy. + Changes have been made to the algorithms used for some special + functions sinh(), cosh(), tanh(), sin(), cos(), etc., that make + use of exp(). In particular tanh(x) is now much faster and + doesn't run out of memory when x is very large - the value to + be returned is then 1 to a high degree of accuracy. - When the true value of a transcendental function is 1, as is - cos(x) for x == 0, calc's version of the function will now return - 1 rather than the nearest multiple of epsilon. E.g. cos(0, 3/8) - no longer returns 9/8. + When the true value of a transcendental function is 1, as is + cos(x) for x == 0, calc's version of the function will now return + 1 rather than the nearest multiple of epsilon. E.g. cos(0, 3/8) + no longer returns 9/8. - The restriction of abs(n) < 1000000 on scale(x, n) has been - removed. The only condition n now has to satisfy for calc to - attempt the operation is n < 2^31, the same as for calc to - attempt x << n and x^n. + The restriction of abs(n) < 1000000 on scale(x, n) has been + removed. The only condition n now has to satisfy for calc to + attempt the operation is n < 2^31, the same as for calc to + attempt x << n and x^n. - Changed root(x,n) so that when x is negative and n is odd it - returns the principal complex n-th root of x rather than -1, e.g. - root(-1,3) now returns -.5+.8660...i. + Changed root(x,n) so that when x is negative and n is odd it + returns the principal complex n-th root of x rather than -1, e.g. + root(-1,3) now returns -.5+.8660...i. - Changed power(a,b) to permit a to be negative when b is real. - E.g. power(-2,3) will now return 8 rather than cause a "negative - base" error. + Changed power(a,b) to permit a to be negative when b is real. + E.g. power(-2,3) will now return 8 rather than cause a "negative + base" error. - Fixed several improper free and link problems in the comfunc.c code. + Fixed several improper free and link problems in the comfunc.c code. Removed BOOL_B64 symbol from Makefile. The following config values return "true" or "false" strings: - tilde tab leadzero fullzero blkverbose verbose_quit + tilde tab leadzero fullzero blkverbose verbose_quit - These config values can still be set with same boolean strings - ("on", "off", "true", "false", "t", ...) as well as via the - numerical values 0 (for "false") and non-0 (for "true"), however. + These config values can still be set with same boolean strings + ("on", "off", "true", "false", "t", ...) as well as via the + numerical values 0 (for "false") and non-0 (for "true"), however. - Added -s to the calc command line. The -s flag will cause unused + Added -s to the calc command line. The -s flag will cause unused args (args after all of the -options on the command line) to remain as unevaluated strings. If calc is called with -s, then the new function argv() will return - the number of strings on the command line. Also argv(n) will return + the number of strings on the command line. Also argv(n) will return the n-th such string or null is no such string exists. Calc now handles calc shell scripts. A calc shell script is an executable file that starts with: - #!/usr/local/bin/calc -S + #!/usr/local/bin/calc -S - Where ``/usr/local/bin/calc'' is the path to the calc binary. - Additional -options may be added to the line, but it MUST - start with -S. For example, the executable file ``plus'' - contain the following: + Where ``/usr/local/bin/calc'' is the path to the calc binary. + Additional -options may be added to the line, but it MUST + start with -S. For example, the executable file ``plus'' + contain the following: - #!/usr/local/bin/calc -S -e - /* - * This is a simple calc shell script to add two values - */ - print eval(argv(0)) + eval(argv(1)); + #!/usr/local/bin/calc -S -e + /* + * This is a simple calc shell script to add two values + */ + print eval(argv(0)) + eval(argv(1)); - then the following command: + then the following command: - ./plus 23 'pi(1e-5)' + ./plus 23 'pi(1e-5)' - will print: + will print: - 26.14159 + 26.14159 If calc is called with -S as the first arg, then calc will assume that it is being called from a #! calc shell script file. The -S implies @@ -4970,12 +4977,12 @@ The following are the changes from calc version 2.11.0t10 to 2.11.0t11: The following lines are treated as comments by calc: - #! this is a comment - # this is a comment - # this is a comment - # - # The lone # above was also a comment - ## is also a comment + #! this is a comment + # this is a comment + # this is a comment + # + # The lone # above was also a comment + ## is also a comment Improved how calc makes changes to file descriptor interactive state. Moved state changing code to calc_tty() and orig_tty() in lib_calc.c. @@ -4984,23 +4991,23 @@ The following are the changes from calc version 2.11.0t10 to 2.11.0t11: Added the following read-only config values: - config("program") path to calc program or calc shell script - config("basename") basename of config("program") - config("version") calc version string + config("program") path to calc program or calc shell script + config("basename") basename of config("program") + config("version") calc version string 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: - Quit or abort executed + Quit or abort executed - when a non-interactive ABORT, QUIT or EXIT is encountered. By default, - config("verbose_quit") is TRUE and the message is printed. If one does: + when a non-interactive ABORT, QUIT or EXIT is encountered. By default, + config("verbose_quit") is TRUE and the message is printed. If one does: - config("verbose_quit", 0) + config("verbose_quit", 0) - the message is disabled. + the message is disabled. Added 8400 regression test set and test8400.cal to test the new quit and config("verbose_quit") functionality. @@ -5024,38 +5031,38 @@ The following are the changes from calc version 2.11.0t8.9.1 to 2.11.0t9.4.5: When prompt() occurs while reading a file, it will take input from the terminal rather than taking it from a file. For example: - /* This demonstrates the use of prompt() and some other things */ - config("verbose_quit", 0); - define getnumber() { - local x; - for (;;) { - x = eval(prompt(">>> ")); - if (isnum(x)) - return x; - print "Not a number! Try again"; - } - } - print "This will display the sqrt of each number you enter"; - print "Enter quit to stop"; - for (;;) { - print sqrt(getnumber()); - } - print "Good bye"; + /* This demonstrates the use of prompt() and some other things */ + config("verbose_quit", 0); + define getnumber() { + local x; + for (;;) { + x = eval(prompt(">>> ")); + if (isnum(x)) + return x; + print "Not a number! Try again"; + } + } + print "This will display the sqrt of each number you enter"; + print "Enter quit to stop"; + for (;;) { + print sqrt(getnumber()); + } + print "Good bye"; - Comments entered at input terminal level may be spread over several - lines. For example: + Comments entered at input terminal level may be spread over several + lines. For example: - /* - * Assume that this calc script is called: comment.cal - * Then these commands now work: - * cat comment.cal | calc - * calc < comment.cal - */ - print "Hello"; + /* + * Assume that this calc script is called: comment.cal + * Then these commands now work: + * cat comment.cal | calc + * calc < comment.cal + */ + print "Hello"; Added: - -D calc_debug[:lib_debug:[user_debug]] + -D calc_debug[:lib_debug:[user_debug]] to set the initial value of config("calc_debug"), config("lib_debug") and config("user_debug"). @@ -5069,11 +5076,11 @@ The following are the changes from calc version 2.11.0t8.9.1 to 2.11.0t9.4.5: Added bits 4 and 5 to config("calc_debug"): - 4 Report on changes to the state of stdin as well as changes - to internal variables that control the setting and restoring - of stdin. + 4 Report on changes to the state of stdin as well as changes + to internal variables that control the setting and restoring + of stdin. - 5 Report on changes to the run state of calc. + 5 Report on changes to the run state of calc. Fixed portability issue in seed.c relating to /dev/urandom and ustat. @@ -5086,18 +5093,18 @@ The following are the changes from calc version 2.11.0t8.9.1 to 2.11.0t9.4.5: GNU-readline. Note that GNU-readline is not shipped with calc. His patch only provides the hooks to use it. One must comment out: - USE_READLINE= - READLINE_LIB= - READLINE_INCLUDE= + USE_READLINE= + READLINE_LIB= + READLINE_INCLUDE= - and comment in: + and comment in: - USE_READLINE= -DUSE_READLINE - READLINE_LIB= -lreadline -lhistory - READLINE_INCLUDE= -I/usr/include/readline + USE_READLINE= -DUSE_READLINE + READLINE_LIB= -lreadline -lhistory + READLINE_INCLUDE= -I/usr/include/readline - in addition to pre-installing GNU-readline in your system to use - this facility. + in addition to pre-installing GNU-readline in your system to use + this facility. Changed the "object already defined" math_error to a scanerror message. @@ -5115,30 +5122,30 @@ The following are the changes from calc version 2.11.0t8.9.1 to 2.11.0t9.4.5: Added patch by Klaus Alexander Seistrup related to GNU-readline: - + enable calc specific bindings in ~/.inputrc - + save a copy of your session to disk and reload them next - time you're using calc - + only add a line to the history if it is different from - the previous line + + enable calc specific bindings in ~/.inputrc + + save a copy of your session to disk and reload them next + time you're using calc + + only add a line to the history if it is different from + the previous line Added the Makefile symbol HAVE_GETRUSAGE to determine if the system supports the getrusage() system call. Fixed the make depend code in the custom and sample Makefiles. - Fixed how the help/builtin file is formed. The help/Makefile is + Fixed how the help/builtin file is formed. The help/Makefile is now given the name of the native C compiler by the top level Makefile. The include files are installed under INCDIRCALC (a new Makefile variable) - which by default is ${INCDIR}/calc. The INCDIR (also a new Makefile var) + which by default is ${INCDIR}/calc. The INCDIR (also a new Makefile var) by default is /usr/local/include. Include files previously installed directly under ${LIBDIR} will be removed. Added the piforever() function to lib/pi.cal. It was written by Klaus Alexander Seistrup and was inspired by - an algorithm conceived by Lambert Meertens. (See also the ABC + an algorithm conceived by Lambert Meertens. (See also the ABC Programmer's Handbook, by Geurts, Meertens & Pemberton, published - by Prentice-Hall (UK) Ltd., 1990.) The piforever() function prints + by Prentice-Hall (UK) Ltd., 1990.) The piforever() function prints digits of pi for as long as your memory and system uptime allows. :-) Fixed the URLs found throughout the source and documentation which did @@ -5146,50 +5153,50 @@ The following are the changes from calc version 2.11.0t8.9.1 to 2.11.0t9.4.5: Cleaned up and improved handling of "mat" and "obj". The comma in: - mat A[2], B[3]; + mat A[2], B[3]; - is changed to whatever is appropriate in the context: + is changed to whatever is appropriate in the context: - + comma operator - + separator of arguments in a function call - + separator of arguments in a definition - etc. + + comma operator + + separator of arguments in a function call + + separator of arguments in a definition + etc. - The expression (mat A[2]), B[3] returns B[3], assuming B already - exists as something created by a statement like: global mat B[4]. + The expression (mat A[2]), B[3] returns B[3], assuming B already + exists as something created by a statement like: global mat B[4]. - What used to be done by the expression: + What used to be done by the expression: - mat A[2], B[3] + mat A[2], B[3] - will now require something like: + will now require something like: - mat A[2], mat B[3] or A = mat[2], B = mat[3] + mat A[2], mat B[3] or A = mat[2], B = mat[3] - For example, if obj point and obj pair are known types, the - following is now allowed: + For example, if obj point and obj pair are known types, the + following is now allowed: - L = list(mat[2], mat[3], obj point, obj pair) + L = list(mat[2], mat[3], obj point, obj pair) - As another example, the following is allowed: + As another example, the following is allowed: - define f(a = mat[2] = {3,4}) = 5 * a; + define f(a = mat[2] = {3,4}) = 5 * a; - as well as the following: + as well as the following: - obj point {x,y}, PP = obj pair {A,B} = {obj point, obj point} + obj point {x,y}, PP = obj pair {A,B} = {obj point, obj point} - which creates two object types at compile time and when executed, - assigns a pair-object value to a variable PP. + which creates two object types at compile time and when executed, + assigns a pair-object value to a variable PP. Fixed a bug whereby a for loop would behave incorrectly. For example: - config("trace", 2), - global x; - define f() {for ( ; x > 0; x--) {print x;}} - x = 5, f() + config("trace", 2), + global x; + define f() {for ( ; x > 0; x--) {print x;}} + x = 5, f() - will stop after printing 1 instead of looping forever. + will stop after printing 1 instead of looping forever. Added values l_format, which when CHECK_L_FORMAT is defined ahead of including longlong.h will help detect when a system can deal with @@ -5198,8 +5205,8 @@ The following are the changes from calc version 2.11.0t8.9.1 to 2.11.0t9.4.5: otherwise if "%lld" is required, l_format will be < 0. Added HAVE_STRDUP Makefile variable as well as the have_strdup.c - program that forms the have_strdup.h file. The have_strdup.h file - will define HAVE_STRDUP is the system has strdup(). If HAVE_STRDUP + program that forms the have_strdup.h file. The have_strdup.h file + will define HAVE_STRDUP is the system has strdup(). If HAVE_STRDUP is not defined, then calc will use calc_strdup() to simulate the real strdup() function. @@ -5214,7 +5221,7 @@ The following are the changes from calc version 2.11.0t8.9.1 to 2.11.0t9.4.5: function, will now print (via the strerror() calc builtin function) something such as: - Unknown error 9999 + Unknown error 9999 Fixed some insure code inspection tool issues that were discovered and investigated by Michel van der List . @@ -5230,7 +5237,7 @@ The following are the changes from calc version 2.11.0t8.9.1 to 2.11.0t9.4.5: 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 - help/wishlist file. Ordered, by priority, help/todo items into + help/wishlist file. Ordered, by priority, help/todo items into Very High, High and Medium priority items. The BUGS file now has a 'bugs' section as well as a 'mis-features' @@ -5241,7 +5248,7 @@ The following are the changes from calc version 2.11.0t8 to 2.11.0t8.9: Calc now allows multiple defines to occur on the same line: (Thanks goes to Ernest Bowen ) - define f8300(x) = x^2; define g8300(x) = 1 - x; + define f8300(x) = x^2; define g8300(x) = 1 - x; Improved calc's ability to deal with and recover from errors. @@ -5277,28 +5284,28 @@ The following are the changes from calc version 2.11.0t8 to 2.11.0t8.9: builtin produced FNV hash values that did not match the FNV-1 algorithm as specified in: - http://www.isthe.com/chongo/tech/comp/fnv/index.html + http://www.isthe.com/chongo/tech/comp/fnv/index.html Removed an unused argument in the function getbody() in codegen.c. Encountering of EOF in getbody() will cause a scanerror rather then stop activity. This will now result in a scanerror: - echo 'define f(x) { ' > myfile - calc -i read myfile + echo 'define f(x) { ' > myfile + calc -i read myfile A '{' at the start of a command and a later matching '}' surrounding zero or more statements (and possibly newlines) results in a function body to be "evaluated". This permits another command to follow on the same line as the '}' as in: - {display(5)} read something; - and: - {static a = 5} define f(x) = a + x; + {display(5)} read something; + and: + {static a = 5} define f(x) = a + x; String constants can now be concatenated. For example: - s = "curds" ' and ' "whey"; + s = "curds" ' and ' "whey"; Added FNV hash to the regression test suite. @@ -5309,21 +5316,21 @@ The following are the changes from calc version 2.11.0t8 to 2.11.0t8.9: improve the way config("calc_debug"). Now the lower 4 bits of the config("calc_debug") parameter have the following meaning: - n Meaning of bit n of config("calc_debug") + n Meaning of bit n of config("calc_debug") 0 Outputs shell commands prior to execution. 1 Outputs currently active functions when a quit instruction - is executed. + is executed. 2 Some details of shs, shs1 and md5 hash states are included - in the output when these are printed. + in the output when these are printed. 3 When a function constructs a block value, tests are - made that the result has the properties required for use of - that block, e.g. that the pointer to the start of the - block is not NULL, and that its "length" is not negative. - A failure will result in a runtime error. + made that the result has the properties required for use of + that block, e.g. that the pointer to the start of the + block is not NULL, and that its "length" is not negative. + A failure will result in a runtime error. Changed the meaning of (config("calc_debug") & 1) from only printing the shell commands (and pausing) while displaying help files into @@ -5331,32 +5338,32 @@ The following are the changes from calc version 2.11.0t8 to 2.11.0t8.9: Documented the meaning of config("lib_debug"): - n Meaning of bit n of config("lib_debug") + n Meaning of bit n of config("lib_debug") - 0 When a function is defined, redefined or undefined at - interactive level, a message saying what has been done - is displayed. + 0 When a function is defined, redefined or undefined at + interactive level, a message saying what has been done + is displayed. - 1 When a function is defined, redefined or undefined during - the reading of a file, a message saying what has been done - is displayed. + 1 When a function is defined, redefined or undefined during + the reading of a file, a message saying what has been done + is displayed. - The value for config("lib_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("lib_debug") is changed, a message will be output when a - function is defined either interactively or during the reading - of a file. + The value for config("lib_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("lib_debug") is changed, a message will be output when a + function is defined either interactively or during the reading + of a file. Changed the calc lib files to reflect the new config("lib_debug") - bit field meaning. Calc lib files that need to print extra information + bit field meaning. Calc lib files that need to print extra information should now do something such as: - if (config("lib_debug") & 3) { - print "obj xyz defined"; - print "funcA([val1 [, val2]]) defined"; - print "funcB(size, mass, ...) defined"; - } + if (config("lib_debug") & 3) { + print "obj xyz defined"; + print "funcA([val1 [, val2]]) defined"; + print "funcB(size, mass, ...) defined"; + } Fixed the help/custom_cal, help/new_custom, and help/copy files so that they contain the correct contents instead of the 'usage' file. @@ -5388,68 +5395,68 @@ 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: (Thanks goes to Ernest Bowen ) - -i Go into interactive mode if possible. + -i Go into interactive mode if possible. - -c Continue reading command lines even after an execution - error has caused the abandonment of a line + -c Continue reading command lines even after an execution + error has caused the abandonment of a line - To understand the -i and -c effects, consider the following - file (call it myfile.cal) which has deliberate errors in it: + To understand the -i and -c effects, consider the following + file (call it myfile.cal) which has deliberate errors in it: - print 1; - mat A[1] = {2,3}; - print 2; - epsilon(-1); - print 3; + print 1; + mat A[1] = {2,3}; + print 2; + epsilon(-1); + print 3; - calc read myfile + calc read myfile - Reports an error on the 2nd line and exits; prints 1 only. + Reports an error on the 2nd line and exits; prints 1 only. - calc -c read myfile + calc -c read myfile - Report errors on the 2nd and 4th lines and exits; prints 1,2 and 3. + Report errors on the 2nd and 4th lines and exits; prints 1,2 and 3. - calc -i read myfile + calc -i read myfile - Report errors on the 2nd and gives you a prompt; prints 1 only. + Report errors on the 2nd and gives you a prompt; prints 1 only. - calc -i -c read myfile + calc -i -c read myfile - Report errors on the 2nd and 4th and gives you a prompt; - prints 1, 2 and 3. + Report errors on the 2nd and 4th and gives you a prompt; + prints 1, 2 and 3. - cat myfile | calc + cat myfile | calc - Reports an error on the 2nd line and exits; prints 1 only. + Reports an error on the 2nd line and exits; prints 1 only. - cat myfile | calc -c + cat myfile | calc -c - Report errors on the 2nd and 4th lines and exits; prints 1,2 and 3. + Report errors on the 2nd and 4th lines and exits; prints 1,2 and 3. - Note that continuation refers to command lines, not to statements. So: + Note that continuation refers to command lines, not to statements. So: - calc -c 'print "start"; mat A[1] = {2,3}; print "end";' + calc -c 'print "start"; mat A[1] = {2,3}; print "end";' - since it contains no newline, the whole string is compiled, - but execution is abandoned when the error is encountered and - the string ``end'' is not printed. + since it contains no newline, the whole string is compiled, + but execution is abandoned when the error is encountered and + the string ``end'' is not printed. - You can use your shell to supply newlines in your command line - arguments. For example in sh, ksh, bash: + You can use your shell to supply newlines in your command line + arguments. For example in sh, ksh, bash: - calc -c 'print "start"; - mat A[1] = {2,3}; - print "end";' + calc -c 'print "start"; + mat A[1] = {2,3}; + print "end";' - will print both ``start'' and ``end''. C-shell users can do: + will print both ``start'' and ``end''. C-shell users can do: - calc -c 'print "start"; \ - mat A[1] = {2,3}; \ - print "end";' + calc -c 'print "start"; \ + mat A[1] = {2,3}; \ + print "end";' - however sh, ksh, bash will not see ``end'' printed because their - shell will remove the internal newlines. + however sh, ksh, bash will not see ``end'' printed because their + shell will remove the internal newlines. Added display(n) builtin which does almost the same as config("display",n) except that rather than causing an execution with an out-of-range or @@ -5460,40 +5467,40 @@ The following are the changes from calc version 2.11.0t7 to 2.11.0t7.5: Added another command line flag to calc: - -d Disable display of the opening title and config("lib_debug",0) + -d Disable display of the opening title and config("lib_debug",0) - The command: + The command: - calc 'read qtime; qtime(2)' + calc 'read qtime; qtime(2)' - will output something like: + will output something like: - qtime(utc_hr_offset) defined - It's nearly ten past six. + qtime(utc_hr_offset) defined + It's nearly ten past six. - whereas: + whereas: - calc -d 'read qtime; qtime(2)' + calc -d 'read qtime; qtime(2)' - will just say: + will just say: - It's nearly ten past six. + It's nearly ten past six. A call of errmax(-1) will prevent errcount from aborting calc. Add the function stoponerror(n) which, as the name implies, controls if calc stop on an error based on the value of n: - n > 0 stop on error even if -c was given on the command line - n == 0 if -c, continue, without -c, stop - n < 0 continue on error, even if -c was given on the command line + n > 0 stop on error even if -c was given on the command line + n == 0 if -c, continue, without -c, stop + n < 0 continue on error, even if -c was given on the command line Calc compilation now stops at the first scanerror. Restored the feature where -p disables the printing of leading tabs as of config("tab",0) had been executed. So using calc in a pipe: - calc -p 2+17 | whey + calc -p 2+17 | whey will write '19' instead of '\t19' to the whey command. @@ -5507,9 +5514,9 @@ The following are the changes from calc version 2.11.0t7 to 2.11.0t7.5: Added the Makefile variable ${LCC} to invoke the local c compiler. By default, ${CC} also run the ${LCC} compiler. The distinction is - useful when using something such as purify. In the case of ${LCC}, + useful when using something such as purify. In the case of ${LCC}, only the local C compiler is invoked. In the case of ${CC} a purify - compile is invoked. Only the source that must be compiled and run + compile is invoked. Only the source that must be compiled and run on the local machine use ${LCC}; everything else uses ${CC}. Fixed memory buffer related problem in eatstring() in token.c. @@ -5520,13 +5527,13 @@ The following are the changes from calc version 2.11.0t7 to 2.11.0t7.5: Fixed compilation warnings and problems on BSDI. - Removed ${CCMAIN} as a variable from the Makefile. Now files + Removed ${CCMAIN} as a variable from the Makefile. Now files use either ${CFLAGS} for general C source and ${ICFLAGS} for intermediate C source (e.g., special code for building hsrc files). The main calc URL is now: - http://www.isthe.com/chongo/tech/comp/calc/ + http://www.isthe.com/chongo/tech/comp/calc/ Misc calc man page fixes. @@ -5538,7 +5545,7 @@ The following are the changes from calc version 2.11.0t1 to 2.11.0t6.3: (instead of an exit(0);) is used at the end of main(). A few of files that were added to calc used 4 character indentation - whereas most of calc uses 8 character indentation. These imported + whereas most of calc uses 8 character indentation. These imported sources have been changed to conform better with the calc style. Added the program calc_errno.c and the Makefile symbol ERRNO_DECL. @@ -5554,7 +5561,7 @@ The following are the changes from calc version 2.11.0t1 to 2.11.0t6.3: Changed check.awk to be more 'old awk' friendly. - Made some of the source a little more ++ friendly. We are NOT + Made some of the source a little more ++ friendly. We are NOT porting calc to C++! We will NOT support C++ compilation of calc. Calc will written ANSI C. We just compiled with a suggestion from Love-Jensen, John to make calc's version @@ -5604,11 +5611,11 @@ The following are the changes from calc version 2.11.0t1 to 2.11.0t6.3: Ernest Bowen . Added FORCE_STDC symbol. When defined it will force __STDC__ like - conditions. Thus for compilers with as the Solaris cc compiler + conditions. Thus for compilers with as the Solaris cc compiler that are ANSI-like but still define __STDC__ as 0, one can use -DFORCE_STDC and make use of ANSI-like features. - Removed the CCSHS symbol from the Makefile. The shs.c and shs1.c + Removed the CCSHS symbol from the Makefile. The shs.c and shs1.c files are now compiled with full ${CFLAGS}. The custom.c file is now compiled with full ${CFLAGS}. @@ -5653,11 +5660,11 @@ The following are the changes from calc version 2.11.0t1 to 2.11.0t6.3: of recursion, and assign values to any number of particular elements by an appropriate "initialization" expression. For example: - A = mat[2] = {list(1,2), list(3,4,list(5,6))}; + A = mat[2] = {list(1,2), list(3,4,list(5,6))}; and then assign values to the 6 number elements by: - A = {{7,8}, {9,10,{11,12}}}; + A = {{7,8}, {9,10,{11,12}}}; Closed files that were previously left open from test4600.cal as executed by regress.cal and from opening /dev/null by @@ -5683,13 +5690,13 @@ The following are the changes from calc version 2.11.0t1 to 2.11.0t6.3: Removed if (config("lib_debug") >= 0) { ... } the ends of most of the calc library scripts because it was redundant with the - new config("lib_debug") >= 0 functionality. Some of the calc + new config("lib_debug") >= 0 functionality. Some of the calc library still has a partial section because some useful additional information was being printed: - chrem.cal deg.cal lucas_tbl.cal randrun.cal - mfactor.cal mod.cal poly.cal seedrandom.cal - surd.cal varargs.cal + chrem.cal deg.cal lucas_tbl.cal randrun.cal + mfactor.cal mod.cal poly.cal seedrandom.cal + surd.cal varargs.cal Fixed ellip.cal so that its defined function does not conflict with the factor() builtin function. @@ -5711,12 +5718,12 @@ The following are the changes from calc version 2.11.0t1 to 2.11.0t6.3: A patch from Ernest Bowen now defines special meaning to the first 2 bits of config("lib_debug"): - bit 0 set => messages printed when input is from a terminal - bit 1 set => messages printed when reading from a file + bit 0 set => messages printed when input is from a terminal + bit 1 set => messages printed when reading from a file The lib/regress.cal regression suite does: - config("lib_debug", -4); + config("lib_debug", -4); to eliminate lib messages (both bit 0 and bit 1 are not set). @@ -5763,7 +5770,7 @@ The following are the changes from calc version 2.10.3t5.38 to 2.11.3t5.46: Fixed the regress.cal dependency list. Make chk and check will exit with an error if check.awk detects - a problem in the regression output. (Martin Buck) + a problem in the regression output. (Martin Buck) Fixed print line for test #4404. @@ -5798,31 +5805,31 @@ The following are the changes from calc version 2.10.3t5.34 to 2.10.3t5.37: Added help files for: - address agd arrow dereference free freeglobals freeredc freestatics - gd isptr mattrace oldvalue saveval & * -> and . + address agd arrow dereference free freeglobals freeredc freestatics + gd isptr mattrace oldvalue saveval & * -> and . - Fixed blkcpy() and copy() arg order and processing. Now: + Fixed blkcpy() and copy() arg order and processing. Now: - A = blk() = {1,2,3,4} - B = blk() - blkcpy(B,A) - blkcpy(B,A) + A = blk() = {1,2,3,4} + B = blk() + blkcpy(B,A) + blkcpy(B,A) will result in B being twice as long as A. Since "make chk" pipes the regression output to awk, we cannot assume that stdout and stderr are ttys. Tests #5985 and #5986 - have been removed for this reason. (thanks to Martin Buck + have been removed for this reason. (thanks to Martin Buck for this report) Fixed the order of prints in regress.cal. By convention, a print of a test line happens after the test. This is because function - parsed messages occur after the function is parsed. Also the + parsed messages occur after the function is parsed. Also the boolean test will verify before any print statements. Therefore a non-test line is tested and printed as follows: - y = sha(); - print '7125: y = sha()'; + y = sha(); + print '7125: y = sha()'; The perm(a,b) and comb(a,b) have been extended to arbitrary real a and integer b. @@ -5831,7 +5838,7 @@ The following are the changes from calc version 2.10.3t5.34 to 2.10.3t5.37: Moved string.c into libcalc.a. - The NUMBER union was converted back into a flat structure. Changes + The NUMBER union was converted back into a flat structure. Changes where 'num' and 'next' symbols were changed to avoid #define conflicts were reverse since the #define's needed to support the union went away. @@ -5842,812 +5849,812 @@ The following are the changes from calc version 2.10.3t5.34 to 2.10.3t5.37: (0) In the past: - A = B = strcat("abc", "def"); + A = B = strcat("abc", "def"); - would store "abc" and "def" as literal strings never to be freed, and - store "abcdef" once each for both A and B. Now the "abc" and "bcd" - are freed immediately after they are concatenated and "abcdef" is stored - only once, just as the number 47 would be stored only once for + would store "abc" and "def" as literal strings never to be freed, and + store "abcdef" once each for both A and B. Now the "abc" and "bcd" + are freed immediately after they are concatenated and "abcdef" is stored + only once, just as the number 47 would be stored only once for - A = B = 47; + A = B = 47; - The new STRING structure that achieves this stores not only the - address of the first character in the string, but also the "length" - with which the string was created, the current "links" count, and - when links == 0 (which indicates the string has been freed) the - address of the next freed STRING. Except for the null string "", - all string values are "allocated"; the concept of literal string - remains for names of variables, object types and elements, etc. + The new STRING structure that achieves this stores not only the + address of the first character in the string, but also the "length" + with which the string was created, the current "links" count, and + when links == 0 (which indicates the string has been freed) the + address of the next freed STRING. Except for the null string "", + all string values are "allocated"; the concept of literal string + remains for names of variables, object types and elements, etc. (1) strings may now include '\0', as in A = "abc\0def". In normal printing - this prints as "abc" and strlen(A) returns 3, but its "real" length - of 7 is given by size(A). (As before there is an 8th zero character - and sizeof(A) returns 8.) + this prints as "abc" and strlen(A) returns 3, but its "real" length + of 7 is given by size(A). (As before there is an 8th zero character + and sizeof(A) returns 8.) (2) If A is an lvalue whose current value is a string of size n, then - for 0 <= i < n, A[i] returns the character with index i as an addressed - octet using the same structure as for blocks, i.e. there is no - distinction between a string-octet and a block-octet. The same - operations and functions can be used for both, and as before, an octet - is in some respects a number in [0,256) and in others a one-character - string. For example, for A = "abc\0def" one will have both A[0] == "a" - and A[0] == 97. Assignments to octets can be used to change - characters in the string, e.g. A[0] = "A", A[1] = 0, A[2] -= 32, - A[3] = " " will change the above A to "A\0C def". + for 0 <= i < n, A[i] returns the character with index i as an addressed + octet using the same structure as for blocks, i.e. there is no + distinction between a string-octet and a block-octet. The same + operations and functions can be used for both, and as before, an octet + is in some respects a number in [0,256) and in others a one-character + string. For example, for A = "abc\0def" one will have both A[0] == "a" + and A[0] == 97. Assignments to octets can be used to change + characters in the string, e.g. A[0] = "A", A[1] = 0, A[2] -= 32, + A[3] = " " will change the above A to "A\0C def". (3) "show strings" now displays the indices, links, length, and some or all - of the early and late characters in all unfreed strings which are values - of lvalues or occur as "constants" in function definitions, - using "\n", "\t", "\0", "\252", etc. when appropriate. For example, - the string A in (1) would be displayed as in the definition there. - Only one line is used for each string. I've also changed the - analogous "show numbers" so that only some digits of numbers that - would require more than one line are displayed. + of the early and late characters in all unfreed strings which are values + of lvalues or occur as "constants" in function definitions, + using "\n", "\t", "\0", "\252", etc. when appropriate. For example, + the string A in (1) would be displayed as in the definition there. + Only one line is used for each string. I've also changed the + analogous "show numbers" so that only some digits of numbers that + would require more than one line are displayed. (4) "show literals" is analogous to "show constants" for number "constants" - in that it displays only the strings that have been introduced by - literal strings as in A = "abc". There is a major difference between - strings and numbers in that there are operations by which characters - in any string may be changed. For example, after A = "abc", - A[0] = "X" changes A to "Xbc". It follows that if a literal string - is to be constant in the sense of never changing, such a character- - changing operation should never be applied to that string. + in that it displays only the strings that have been introduced by + literal strings as in A = "abc". There is a major difference between + strings and numbers in that there are operations by which characters + in any string may be changed. For example, after A = "abc", + A[0] = "X" changes A to "Xbc". It follows that if a literal string + is to be constant in the sense of never changing, such a character- + changing operation should never be applied to that string. - In this connection, it should be noted that if B is string-valued, then + In this connection, it should be noted that if B is string-valued, then - A = B + A = B - results in A referring to exactly the same string as B rather than to - a copy of what is in B. This is like the use of character-pointers in - C, as in + results in A referring to exactly the same string as B rather than to + a copy of what is in B. This is like the use of character-pointers in + C, as in - char *s1, *s2; - s1 = "abc"; - s2 = s1; + char *s1, *s2; + s1 = "abc"; + s2 = s1; - To achieve the effect of + To achieve the effect of - s2 = (char *) malloc(4); - strcpy(s2, s1); + s2 = (char *) malloc(4); + strcpy(s2, s1); - I have extended the str() function to accept a string as argument. Then + I have extended the str() function to accept a string as argument. Then - A = str(B); + A = str(B); - will create a new string at a different location from that of B but - with the same length and characters. One will then have A == B, - *A == *B, but &*A != &*B, &A[0] != &B[0]. + will create a new string at a different location from that of B but + with the same length and characters. One will then have A == B, + *A == *B, but &*A != &*B, &A[0] != &B[0]. - To assist in analyzing this sort of thing, I have defined a links() - function which for number or string valued argument returns the number - of links to the occurrence of that argument that is being referred to. - For example, supposing "abc" has not been used earlier: + To assist in analyzing this sort of thing, I have defined a links() + function which for number or string valued argument returns the number + of links to the occurrence of that argument that is being referred to. + For example, supposing "abc" has not been used earlier: - ; A = "abc" - ; links(A) - 2 - ; links(A) - 1 + ; A = "abc" + ; links(A) + 2 + ; links(A) + 1 - The two links in the first call are to A and the current "oldvalue"; - in the second call, the only link is to A, the oldvalue now being 2. + The two links in the first call are to A and the current "oldvalue"; + in the second call, the only link is to A, the oldvalue now being 2. (5) strcat(S1, S2, ...) works as before; contribution of a string stops when - '\0' is encountered. E.g. + '\0' is encountered. E.g. - strcat("abc\0def", "ghi") + strcat("abc\0def", "ghi") - will return "abcghi". + will return "abcghi". (6) For concatenation of full strings I have chosen to follow - some other languages (like Java, but not Mathematica which uses "<>") - and use "+" so that, e.g. + some other languages (like Java, but not Mathematica which uses "<>") + and use "+" so that, e.g. - "abc\0def" + "ghi" + "abc\0def" + "ghi" - returns the string "abc\0defghi". This immediately gives obvious - meanings to multiplication by positive integers as in + returns the string "abc\0defghi". This immediately gives obvious + meanings to multiplication by positive integers as in - 2 * "abc" = "abc" + "abc" = "abcabc", + 2 * "abc" = "abc" + "abc" = "abcabc", - to negation to reverse as string as in + to negation to reverse as string as in - - "abc" = "cba", + - "abc" = "cba", - to multiplication by fractions as in + to multiplication by fractions as in - 0.5 * "abcd" = "ab", + 0.5 * "abcd" = "ab", - (where the length is int(0.5 * size("abcd")), and finally, by combining - these to + (where the length is int(0.5 * size("abcd")), and finally, by combining + these to - k * A and A * k + k * A and A * k - for any real number k and any string A. In the case of k == 1, these - return a new string rather than A itself. (This differs from - "" + A and A + "" which return A.) + for any real number k and any string A. In the case of k == 1, these + return a new string rather than A itself. (This differs from + "" + A and A + "" which return A.) (7) char(x) has been changed so that it will accept any integer x or octet - as argument and return a string of size one with character value - x % 256. In the past calc has required 0 <= x < 256; now negative - x is acceptable; for example, 1000 * char(-1) will now produce the - same as 1000 * "\377" or 1000 * "\xff". + as argument and return a string of size one with character value + x % 256. In the past calc has required 0 <= x < 256; now negative + x is acceptable; for example, 1000 * char(-1) will now produce the + same as 1000 * "\377" or 1000 * "\xff". (8) For a string s, test(s) now returns zero not only for the null string - "" but also for a string all of whose characters are '\0'. + "" but also for a string all of whose characters are '\0'. (9) Similarly <, <=, etc. now compare all characters including occurrences - of '\0' until a difference is encountered or the end of a string is - reached. If no difference is encountered but one string is longer than - the other, the longer string is considered as greater even if the - remaining characters are all '\0'. + of '\0' until a difference is encountered or the end of a string is + reached. If no difference is encountered but one string is longer than + the other, the longer string is considered as greater even if the + remaining characters are all '\0'. (10) To retain the C sense of comparison of null-terminated strings I have - defined strcmp(S1, S2), and then, for completeness, strncmp(S1, S2, n). - For similar reasons, strcpy(S1, S2) and strncpy(S1, S2, n) have been - defined. + defined strcmp(S1, S2), and then, for completeness, strncmp(S1, S2, n). + For similar reasons, strcpy(S1, S2) and strncpy(S1, S2, n) have been + defined. (11) For strings, I have defined | and & as bitwise "or" and "and" - functions, with S1 | S2 having the size of the larger of S1 and S2, - S1 & S2 having the size of the smaller of S1 and S2. By using, say, - 4-character strings, one can simulate a C integral type so far as the - | and & operations are concerned. It then seemed appropriate to - use the operator ~ for a "bitwise complement" as in C. Thus I have - defined ~s for a string s to be the string of the same size as s - with each character being complemented by the C ~ operation. + functions, with S1 | S2 having the size of the larger of S1 and S2, + S1 & S2 having the size of the smaller of S1 and S2. By using, say, + 4-character strings, one can simulate a C integral type so far as the + | and & operations are concerned. It then seemed appropriate to + use the operator ~ for a "bitwise complement" as in C. Thus I have + defined ~s for a string s to be the string of the same size as s + with each character being complemented by the C ~ operation. (12) For boolean algebra work on strings it is convenient also to have - the bitwise xor and setminus binary operations. Using C's '^' for xor - would be confusing when this is used elsewhere for powers, so I - decided to use ~. For setminus, I adopted the commonly used '\'. - Strings of fixed size n can now be used for a boolean algebra - structure with 8 * n elements. The zero element is n * char(0), - the unity is n * char(-1), and one have all of the usual laws like - A & (B | C) == A & B | A * C, A \ B = A & ~B, etc. + the bitwise xor and setminus binary operations. Using C's '^' for xor + would be confusing when this is used elsewhere for powers, so I + decided to use ~. For setminus, I adopted the commonly used '\'. + Strings of fixed size n can now be used for a boolean algebra + structure with 8 * n elements. The zero element is n * char(0), + the unity is n * char(-1), and one have all of the usual laws like + A & (B | C) == A & B | A * C, A \ B = A & ~B, etc. (13) Having extended the bitwise operations for strings, it was appropriate - to do the same for integers. Definitions of the binary ~ and \ - operations for non-negative integers are straightforward. For - the unary ~ operation, I decided to do what C does with integer - types, and defined ~N to be -N - 1. With the appropriate extensions of - |, &, \ and the binary ~, one gets in effect the boolean algebra of - finite sets of natural numbers and their complements, by identifying - the set with distinct integer elements i_1, i_2, ... with the integer + to do the same for integers. Definitions of the binary ~ and \ + operations for non-negative integers are straightforward. For + the unary ~ operation, I decided to do what C does with integer + types, and defined ~N to be -N - 1. With the appropriate extensions of + |, &, \ and the binary ~, one gets in effect the boolean algebra of + finite sets of natural numbers and their complements, by identifying + the set with distinct integer elements i_1, i_2, ... with the integer - 2^i_1 + 2^i_2 + ... + 2^i_1 + 2^i_2 + ... - For ~N for non-integer real N, I have simply used -N. There is some - logic in this and it is certainly better than an error value. - I have not defined the binary operations |, &, ~, \ for non-integral - arguments. + For ~N for non-integer real N, I have simply used -N. There is some + logic in this and it is certainly better than an error value. + I have not defined the binary operations |, &, ~, \ for non-integral + arguments. - The use of ~N in this way conflicts with calc's method of displaying - a number when it has to be rounded to config("display") decimals. - To resolve this, my preference would be to replace the printing of - "~" as a prefix by a trailing ellipsis "...", the rounding always - being towards zero. E.g. with config("display", 5), 1/7 would print - as ".14285..." rather than "~.14285". The config("outround") - parameter would determine the type of rounding only for the - equivalent of config("tilde", 0). + The use of ~N in this way conflicts with calc's method of displaying + a number when it has to be rounded to config("display") decimals. + To resolve this, my preference would be to replace the printing of + "~" as a prefix by a trailing ellipsis "...", the rounding always + being towards zero. E.g. with config("display", 5), 1/7 would print + as ".14285..." rather than "~.14285". The config("outround") + parameter would determine the type of rounding only for the + equivalent of config("tilde", 0). (14) For objects, users may create their own definitions for binary |, - &, ~ and \ with xx_or, xx_and, xx_xor, xx_setminus functions. - For unary ~ and \ operations, I have used the names xx_comp and - xx_backslash. + &, ~ and \ with xx_or, xx_and, xx_xor, xx_setminus functions. + For unary ~ and \ operations, I have used the names xx_comp and + xx_backslash. (15) For the obviously useful feature corresponding to cardinality of a - set, I have defined #S for a string S to be the number of nonzero bits - in S. For a degree of consistency, it was then appropriate to - define #N for a nonnegative integer N to be the number of nonzero bits - in the binary representation of N. I've extended this to arbitrary - real N by using in effect #(abs(num(N))). I feel it is better to make - this available to users rather than having #N invoke an error message - or return an error value. For defining #X for an xx-object X, I - have used the name xx_content to suggest that it is appropriate for - something which has the sense of a content (like number of members of, - area, etc.). + set, I have defined #S for a string S to be the number of nonzero bits + in S. For a degree of consistency, it was then appropriate to + define #N for a nonnegative integer N to be the number of nonzero bits + in the binary representation of N. I've extended this to arbitrary + real N by using in effect #(abs(num(N))). I feel it is better to make + this available to users rather than having #N invoke an error message + or return an error value. For defining #X for an xx-object X, I + have used the name xx_content to suggest that it is appropriate for + something which has the sense of a content (like number of members of, + area, etc.). (16) Having recognized # as a token, it seemed appropriate to permit its - use for a binary operation. For real numbers x and y I have defined - x # y to be abs(x - y). (This is often symbolized by x ~ y, but it - would be confusing to have x ~ y meaning xor(x,y) for strings and - abs(x-y) for numbers.) Because '#' is commonly called the hash symbol, - I have used xx_hashop to permit definition of x # y for xx-objects. + use for a binary operation. For real numbers x and y I have defined + x # y to be abs(x - y). (This is often symbolized by x ~ y, but it + would be confusing to have x ~ y meaning xor(x,y) for strings and + abs(x-y) for numbers.) Because '#' is commonly called the hash symbol, + I have used xx_hashop to permit definition of x # y for xx-objects. (17) For a similar reason I've added one line of code to codegen.c so that - /A returns the inverse of A. + /A returns the inverse of A. (18) Also for a list L, +L now returns the sum of the elements of L. For - an xx object A, +A requires and uses the definition of xx_plus. + an xx object A, +A requires and uses the definition of xx_plus. (19) I have given the unary operators ~, #, /, \, and except at the - beginning of an expression + and -, the same precedence with - right-to-left associativity. This precedence is now weaker than - unary * and &, but stronger than binary & and the shift and power - operators. One difference from before is that now + beginning of an expression + and -, the same precedence with + right-to-left associativity. This precedence is now weaker than + unary * and &, but stronger than binary & and the shift and power + operators. One difference from before is that now - a ^ - b ^ c + a ^ - b ^ c - evaluates as a ^ (- (b ^ c)) rather than a ^ ((- b) ^ c). + evaluates as a ^ (- (b ^ c)) rather than a ^ ((- b) ^ c). (20) For octets o1, o2, I've defined o1 | o2, o1 & o2, o1 ~ o2, ~o1 so - that they return 1-character strings. #o for an octet o returns the - number of nonzero bits in o. + that they return 1-character strings. #o for an octet o returns the + number of nonzero bits in o. (21) For substrings I've left substr() essentially as before, but - for consistency with the normal block/matrix indexing, I've extended - the segment function to accept a string as first argument. Then + for consistency with the normal block/matrix indexing, I've extended + the segment function to accept a string as first argument. Then - segment(A, m, n) + segment(A, m, n) - returns essentially the string formed from the character with index m - to the character with index n, ignoring indices < 0 and indices >= - len(A); thus, if m and n are both in [0, size(A)) - the string is of length abs(m - n) + 1, the order of the characters - being reversed if n < m. Here the indices for a list of size len are - 0, 1, ..., len - 1. As it makes some sense, if 0 <= n < size(A), + returns essentially the string formed from the character with index m + to the character with index n, ignoring indices < 0 and indices >= + len(A); thus, if m and n are both in [0, size(A)) + the string is of length abs(m - n) + 1, the order of the characters + being reversed if n < m. Here the indices for a list of size len are + 0, 1, ..., len - 1. As it makes some sense, if 0 <= n < size(A), - segment(A, n) + segment(A, n) - now returns the one-character string with its character being that with - index n in A. (I've made a corresponding modification to the segment - function for lists.) Some examples, if A = "abcdef", + now returns the one-character string with its character being that with + index n in A. (I've made a corresponding modification to the segment + function for lists.) Some examples, if A = "abcdef", - segment(A,2,4) = "cde", + segment(A,2,4) = "cde", - segment(A,4,2) = "edc", + segment(A,4,2) = "edc", - segment(A,3) = "d", + segment(A,3) = "d", - segment(A, -2, 8) = "abcdef", + segment(A, -2, 8) = "abcdef", - segment(A,7,8) = "". + segment(A,7,8) = "". (22) As essentially particular cases of segment(), I've defined - head(A, n) and tail(A, n) to be the strings formed by the first - or last abs(n) characters of A, the strings being4]5O~? reversed ' - if n is negative. I've changed the definitions of head and tail for - lists to be consistent with this interpretation of negative n. + head(A, n) and tail(A, n) to be the strings formed by the first + or last abs(n) characters of A, the strings being4]5O~? reversed ' + if n is negative. I've changed the definitions of head and tail for + lists to be consistent with this interpretation of negative n. (23) Similarly I've left strpos essentially as at present, but search - and rsearch have been extended to strings. For example, + and rsearch have been extended to strings. For example, - search(A, B, m, n) + search(A, B, m, n) - returns the index i of the first occurrence of the string B in A - if m <= i < n, or the null value if there is no such occurrence. - As for other uses of search, negative m is interpreted as - size(A) + m, negative n as size(A) + n. For a match in this - search, all size(B) characters, including occurrences of '\0', - in B must match successive characters in A. + returns the index i of the first occurrence of the string B in A + if m <= i < n, or the null value if there is no such occurrence. + As for other uses of search, negative m is interpreted as + size(A) + m, negative n as size(A) + n. For a match in this + search, all size(B) characters, including occurrences of '\0', + in B must match successive characters in A. - The function rsearch() behaves similarly but searches in reverse order - of the indices. + The function rsearch() behaves similarly but searches in reverse order + of the indices. (24) A string A of length N determines in obvious ways arrays of M = 8 * N - bits. If the characters in increasing index order are c_0, c_1, ... - and the bits in increasing order in c_i are b_j, b_j+1, ..., b_j+7 - where j = 8 * i, I've taken the array of bits determined by A to be + bits. If the characters in increasing index order are c_0, c_1, ... + and the bits in increasing order in c_i are b_j, b_j+1, ..., b_j+7 + where j = 8 * i, I've taken the array of bits determined by A to be - b_0, b_1, ..., b_M-1 + b_0, b_1, ..., b_M-1 - For example, since "a" = char(97) and 97 = 0b01100001, and - "b" = char(98) = 0b01100010, the string "ab" determines the 16-bit - array + For example, since "a" = char(97) and 97 = 0b01100001, and + "b" = char(98) = 0b01100010, the string "ab" determines the 16-bit + array - 1000011001000110 + 1000011001000110 - in which the bits in the binary representations of "a" and "b" have - been reversed. + in which the bits in the binary representations of "a" and "b" have + been reversed. - bit with index n in this array. This is consistent with the use of - bit for a number ch in [0,256), i.e. bit(char(ch), n) = bit(ch, n). - For n < 0 or n >= size(A), bit(A,n) returns the null value. + bit with index n in this array. This is consistent with the use of + bit for a number ch in [0,256), i.e. bit(char(ch), n) = bit(ch, n). + For n < 0 or n >= size(A), bit(A,n) returns the null value. (25) For assigning values to specified bits in a string, I've defined - setbit(A, n) and setbit(A, n, v). The first assigns the value 1 to - bit(A, n), the second assigns test(v) to bit(A, n). + setbit(A, n) and setbit(A, n, v). The first assigns the value 1 to + bit(A, n), the second assigns test(v) to bit(A, n). (26) For consistency with the corresponding number operations, the shift - operations A << n and A >> n have been defined to give what look - like right- and left-shifts, respectively. For example, "ab" << 2 - returns the 16-bit array + operations A << n and A >> n have been defined to give what look + like right- and left-shifts, respectively. For example, "ab" << 2 + returns the 16-bit array - 0010000110010001 + 0010000110010001 - in which the array for "ab" has been moved 2 bits to the right. + in which the array for "ab" has been moved 2 bits to the right. (27) To achieve much the same as the C strcpy and strncpy functions for - null-terminated strings, strcpy(S1, S2) and strncpy(S1, S2, n) have - been defined. Unlike the blkcpy() and copy() functions, the copying - for these is only from the beginning of the strings. Also, unlike C, - no memory overflow can occur as the copying ceases when size(S1) is - reached. Note that these overwrite the content of S1 (which affects - all strings linked to it) as well as returning S1. Examples: + null-terminated strings, strcpy(S1, S2) and strncpy(S1, S2, n) have + been defined. Unlike the blkcpy() and copy() functions, the copying + for these is only from the beginning of the strings. Also, unlike C, + no memory overflow can occur as the copying ceases when size(S1) is + reached. Note that these overwrite the content of S1 (which affects + all strings linked to it) as well as returning S1. Examples: - S = strcpy(6 * "x", "abc") <=> S = "abc\0xx" + S = strcpy(6 * "x", "abc") <=> S = "abc\0xx" - S = strcpy(3 * "x", "abcdef") <=> S = "abc" + S = strcpy(3 * "x", "abcdef") <=> S = "abc" - S = strncpy(6 * "x", "abcd", 2) <=> S = "ab\0xxx" + S = strncpy(6 * "x", "abcd", 2) <=> S = "ab\0xxx" - S = strncpy(6 * "x", "ab", 4) <=> S = "ab\0\0xx" + S = strncpy(6 * "x", "ab", 4) <=> S = "ab\0\0xx" - S = strncpy(6 * "x", "ab", 20) <=> S = "ab\0\0\0\0" + S = strncpy(6 * "x", "ab", 20) <=> S = "ab\0\0\0\0" - If a new string S not linked to S1 is to be created, this can be - achieved by using str(S1) in place of S1. For example, the strcpy in + If a new string S not linked to S1 is to be created, this can be + achieved by using str(S1) in place of S1. For example, the strcpy in - A = "xxxxxx" - S = strcpy(str("xxxxxx"), "abc") + A = "xxxxxx" + S = strcpy(str("xxxxxx"), "abc") - would not change the value of A. + would not change the value of A. (28) I've extended the definitions of copy(A, B, ssi, num, dsi) and - blkcpy(B, A, num, ssi, dsi) to allow for string-to-string copying - and block-to-string copying, but num is now an upper bound for the - number of characters to be copied - copying will cease before num - characters are copied if the end of the data in the source A or the - end of the destination B is reached. As with other character-changing - operations, copying to a string B will not change the locations of - B[0], B[1], ... or the size of B. + blkcpy(B, A, num, ssi, dsi) to allow for string-to-string copying + and block-to-string copying, but num is now an upper bound for the + number of characters to be copied - copying will cease before num + characters are copied if the end of the data in the source A or the + end of the destination B is reached. As with other character-changing + operations, copying to a string B will not change the locations of + B[0], B[1], ... or the size of B. - In the case of copying a string to itself, characters are copied in - order of increasing index, which is different from block-to-block - copying where a memmove is used. This affects only copy from a - string to itself. For example, + In the case of copying a string to itself, characters are copied in + order of increasing index, which is different from block-to-block + copying where a memmove is used. This affects only copy from a + string to itself. For example, - A = "abcdefg"; - copy(A, A, , , 2); + A = "abcdefg"; + copy(A, A, , , 2); - will result in A == "abababa". If the overwriting that occurs here - is not wanted, one may use + will result in A == "abababa". If the overwriting that occurs here + is not wanted, one may use - A = "abcdefg"; - copy(str(A), A, , , 2); + A = "abcdefg"; + copy(str(A), A, , , 2); - which results in A == "ababcde". + which results in A == "ababcde". (29) perm(a,b) and comb(a,b) have been extended to accept any real a and - any integer b except for perm(a, b) with integer a such that b <= a < 0 - which gives a "division by zero" error. For positive b, both functions - are polynomials in a of degree b; for negative b, perm(a,b) is a - rational function (1/((a + 1) * (a+2) ...) with abs(b) factors in the - denominator), and comb(a,b) = 0. (An obvious "todo" is to extend this - to complex or other types of a.) + any integer b except for perm(a, b) with integer a such that b <= a < 0 + which gives a "division by zero" error. For positive b, both functions + are polynomials in a of degree b; for negative b, perm(a,b) is a + rational function (1/((a + 1) * (a+2) ...) with abs(b) factors in the + denominator), and comb(a,b) = 0. (An obvious "todo" is to extend this + to complex or other types of a.) (30) Although it is not illegal, it seems pointless to use a comma operator - with a constant or simple variable as in + with a constant or simple variable as in - ; 2 * 3,14159 - 14159 - ; a = 4; b = 5; - ; A = (a , b + 2); - ; A - 7 + ; 2 * 3,14159 + 14159 + ; a = 4; b = 5; + ; A = (a , b + 2); + ; A + 7 - I have added a few lines to addop.c so that when this occurs a - "unused value ignored" message and the relevant line number are - displayed. I have found this useful as I occasionally type ',' - when I mean '.'. + I have added a few lines to addop.c so that when this occurs a + "unused value ignored" message and the relevant line number are + displayed. I have found this useful as I occasionally type ',' + when I mean '.'. - There may be one or two other changes resulting from the way I have - rewritten the optimization code in addop.c. I think there was a bug - that assumed that PTR_SIZE would be the same as sizeof(long). By - the way, the new OP_STRING is now of index rather than pointer type. - It follows that pointers are now used in opcodes only for global - variables. By introducing a table of addresses of global variables - like those used for "constants" and "literal strings", the use of - pointers in opcodes could be eliminated. + There may be one or two other changes resulting from the way I have + rewritten the optimization code in addop.c. I think there was a bug + that assumed that PTR_SIZE would be the same as sizeof(long). By + the way, the new OP_STRING is now of index rather than pointer type. + It follows that pointers are now used in opcodes only for global + variables. By introducing a table of addresses of global variables + like those used for "constants" and "literal strings", the use of + pointers in opcodes could be eliminated. (31) When calc has executed a quit (or exit) statement in a function or - eval evaluation, it has invoked a call to math_error() which causes - a long jump to an initial state without freeing any data on the - stack, etc. Maybe more detail should be added to math_error(), but - to achieve the freeing of memory for a quit statement and at the same - time give more information about its occurrence I have changed the - way opcodes.c handles OP_QUIT. Now it should free the local variables - and whatever is on the stack, and display the name and line-number, - for each of the functions currently being evaluated. The last - function listed should be the "top-level" one with name "*". - Strings being eval-ed will have name "**". + eval evaluation, it has invoked a call to math_error() which causes + a long jump to an initial state without freeing any data on the + stack, etc. Maybe more detail should be added to math_error(), but + to achieve the freeing of memory for a quit statement and at the same + time give more information about its occurrence I have changed the + way opcodes.c handles OP_QUIT. Now it should free the local variables + and whatever is on the stack, and display the name and line-number, + for each of the functions currently being evaluated. The last + function listed should be the "top-level" one with name "*". + Strings being eval-ed will have name "**". - Here is a demo: + Here is a demo: - ; global a; - ; - ; define f(x) {local i = x^2; a++; - ;; if (x > 5) quit "Too large!"; return i;} - f() defined - ; define g(x) = f(x) + f(2*x); - g() defined - ; g(2) - 20 - ; g(3) - Too large! - "f": line 3 - "g": line 0 - "*": line 6 - ; eval("g(3)") - Too large! - "f": line 3 - "g": line 0 - "**": line 1 - "*": line 7 - ; a - 6 + ; global a; + ; + ; define f(x) {local i = x^2; a++; + ;; if (x > 5) quit "Too large!"; return i;} + f() defined + ; define g(x) = f(x) + f(2*x); + g() defined + ; g(2) + 20 + ; g(3) + Too large! + "f": line 3 + "g": line 0 + "*": line 6 + ; eval("g(3)") + Too large! + "f": line 3 + "g": line 0 + "**": line 1 + "*": line 7 + ; a + 6 (32) I've made several small changes like removing - if (vp->v_type == V_NUM) { - q = qinv(vp->v_num); - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack->v_num = q; - stack->v_type = V_NUM; - return; - } + if (vp->v_type == V_NUM) { + q = qinv(vp->v_num); + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack->v_num = q; + stack->v_type = V_NUM; + return; + } - from the definition of o_invert. Presumably these lines were intended - to speed up execution for the common case of numerical argument. - Comparing the runtimes with and without these lines for inverting - thousands of large random numbers in a matrix suggest that execution - for real numbers is slightly faster without these lines. + from the definition of o_invert. Presumably these lines were intended + to speed up execution for the common case of numerical argument. + Comparing the runtimes with and without these lines for inverting + thousands of large random numbers in a matrix suggest that execution + for real numbers is slightly faster without these lines. - Maybe this and other similar treatment of "special cases" should be - looked at more closely. + Maybe this and other similar treatment of "special cases" should be + looked at more closely. (33) The new lib script lib/natnumset.cal demonstrates how the new - string operators and functions may be used for defining and - working with sets of natural numbers not exceeding a - user-specified bound. + string operators and functions may be used for defining and + working with sets of natural numbers not exceeding a + user-specified bound. 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: - v % (h * 2^n + r), h>0, n>0, r = -1, 0 or 1 + v % (h * 2^n + r), h>0, n>0, r = -1, 0 or 1 Changed lucas.cal and mersenne.cal to make use of hnrmod(). A number of changes from Ernest Bowen: - (1) introduction of unary & and * analogous to those in C; - - For an lvalue var, &var returns what I call a - value-pointer; this is a constant which may be assigned to - a variable as in p = &var, and then *p in expressions has - the same effect as var. Here is a simple example of their use: - - ; define s(L) {local v=0; while (size(L)) v+= *pop(L);return v;} - s() defined - ; global a = 1, b = 2; - ; L = list(&a, &b); - ; print s(L) - 3 - ; b = 3; - ; print s(L) - 4 - - Octet-pointers, number-pointers, and string-pointers in - much the same way, but have not attempted to do much with - the latter two. - - To print a pointer, use the "%p" specifier. - - Some arithmetic operations has been defined for corresponding - C operations. For example: - - ; A = mat[4]; - ; p = &A[0]; - ; *(p+2) == A[2] - ; ++p - ; *p == A[1] - - There is at present no protection against "illegal" use of & - and *, e.g. if one attempts here to assign a value to *(p+5), - or to use p after assigning another value to A. - - NOTE: Unlike C, in calc &A[0] and A are quite different things. - - NOTE: If the current value of a variable X is an octet, - number or string, *X may be used to to return the value of - X; in effect X is an address and *X is the value at X. - - Added isptr(p) builtin to return 0 is p is not a pointer, - and >0 if it is a pointer. The value of isptr(p) comes from - the V_XYZ #define (see the top of value.h) of the value to - which p points. - - To allow & to be used as a C-like address operator, use of it - has been dropped in calls to user-defined functions. For the - time being I have replaced it by the back-quote `. For example: - - ; global a - ; define f(a,b) = a = b - ; f(&a,5) - ; print a - 0 - ; f(`a,5) - ; print a - 5 - - However, one may use & in a similar way as in: - - ; define g(a,b) = *a = b - ; g(&a, 7) - ; print a - 7 - - There is no hashvalue for pointers. Thus, like error values, - they cannot be used as indices in an association. - - The -> also works in calc. For example: - - ; obj xy {x,y} - ; obj uvw {u, v, w} - ; obj xy A = {1,2} - ; obj uvw B = {3,4,5} - ; p = &A - ; q = &B - ; p->x - 1 - ; p->y = 6 - ; A - obj xy {1, 6} - ; q -> u - 3 - ; p->y = q - ; A - obj xy {1, v-ptr: 1400474c0} - ; p->y->u - 3 - ; p->y->u = 7 - ; B - obj uvw {7, 4, 5} - ; p -> y = p - ; A - obj xy {1, v-ptr: 140047490} - ; p -> y -> x - 1 - ; p->y->y - v-ptr: 140047490 - ; p->y->y-> x - 1 - ; p->y->y->x = 8 - ; A - obj xy {8, v-ptr: 140047490} - - - (2) a method of "protecting" variables; - - For the various kinds of "protection", of an l_value var, - bits of var->v_subtype, of which only bits 0 and 1 have been - used in the past to indicate literal and allocated strings. - This has meant initialization of var->v_subtype when a new var - is introduced, and for assignments, etc., examination of the - appropriate bits to confirm that the operation is to be permitted. - - See help/protect for details. - - (3) automatic "freeing" of constants that are no longer required. + (1) introduction of unary & and * analogous to those in C; + + For an lvalue var, &var returns what I call a + value-pointer; this is a constant which may be assigned to + a variable as in p = &var, and then *p in expressions has + the same effect as var. Here is a simple example of their use: + + ; define s(L) {local v=0; while (size(L)) v+= *pop(L);return v;} + s() defined + ; global a = 1, b = 2; + ; L = list(&a, &b); + ; print s(L) + 3 + ; b = 3; + ; print s(L) + 4 + + Octet-pointers, number-pointers, and string-pointers in + much the same way, but have not attempted to do much with + the latter two. + + To print a pointer, use the "%p" specifier. + + Some arithmetic operations has been defined for corresponding + C operations. For example: + + ; A = mat[4]; + ; p = &A[0]; + ; *(p+2) == A[2] + ; ++p + ; *p == A[1] + + There is at present no protection against "illegal" use of & + and *, e.g. if one attempts here to assign a value to *(p+5), + or to use p after assigning another value to A. + + NOTE: Unlike C, in calc &A[0] and A are quite different things. + + NOTE: If the current value of a variable X is an octet, + number or string, *X may be used to to return the value of + X; in effect X is an address and *X is the value at X. + + Added isptr(p) builtin to return 0 is p is not a pointer, + and >0 if it is a pointer. The value of isptr(p) comes from + the V_XYZ #define (see the top of value.h) of the value to + which p points. + + To allow & to be used as a C-like address operator, use of it + has been dropped in calls to user-defined functions. For the + time being I have replaced it by the back-quote `. For example: + + ; global a + ; define f(a,b) = a = b + ; f(&a,5) + ; print a + 0 + ; f(`a,5) + ; print a + 5 + + However, one may use & in a similar way as in: + + ; define g(a,b) = *a = b + ; g(&a, 7) + ; print a + 7 + + There is no hashvalue for pointers. Thus, like error values, + they cannot be used as indices in an association. + + The -> also works in calc. For example: + + ; obj xy {x,y} + ; obj uvw {u, v, w} + ; obj xy A = {1,2} + ; obj uvw B = {3,4,5} + ; p = &A + ; q = &B + ; p->x + 1 + ; p->y = 6 + ; A + obj xy {1, 6} + ; q -> u + 3 + ; p->y = q + ; A + obj xy {1, v-ptr: 1400474c0} + ; p->y->u + 3 + ; p->y->u = 7 + ; B + obj uvw {7, 4, 5} + ; p -> y = p + ; A + obj xy {1, v-ptr: 140047490} + ; p -> y -> x + 1 + ; p->y->y + v-ptr: 140047490 + ; p->y->y-> x + 1 + ; p->y->y->x = 8 + ; A + obj xy {8, v-ptr: 140047490} + + + (2) a method of "protecting" variables; + + For the various kinds of "protection", of an l_value var, + bits of var->v_subtype, of which only bits 0 and 1 have been + used in the past to indicate literal and allocated strings. + This has meant initialization of var->v_subtype when a new var + is introduced, and for assignments, etc., examination of the + appropriate bits to confirm that the operation is to be permitted. + + See help/protect for details. + + (3) automatic "freeing" of constants that are no longer required. - For the "freeing" of constants, the definition of a NUMBER - structure so that a NUMBER * q could be regarded as a - pointing to a "freed number" if q->links = 0. - - The old q->num was changed to a union q->nu which had a pointer - to the old q->num if q->links > 0 and to the next freed number - if q->links = 0. The old "num" is #defined to "nu->n_num". - - The prior method calc has used for handling "constants" amounted - to leakage. After: - - ; define f(x) = 27 + x; - ; a = 27; + For the "freeing" of constants, the definition of a NUMBER + structure so that a NUMBER * q could be regarded as a + pointing to a "freed number" if q->links = 0. + + The old q->num was changed to a union q->nu which had a pointer + to the old q->num if q->links > 0 and to the next freed number + if q->links = 0. The old "num" is #defined to "nu->n_num". + + The prior method calc has used for handling "constants" amounted + to leakage. After: + + ; define f(x) = 27 + x; + ; a = 27; - It is of course necessary for the constant 27 to be stored, but - if one now redefines f and a by: + It is of course necessary for the constant 27 to be stored, but + if one now redefines f and a by: - ; define f(x) = 45 + x; - ; a = 45; + ; define f(x) = 45 + x; + ; a = 45; - There seems little point in retaining 27 as a constant and - therefore using up memory. If this example seems trivial, - replace 27 with a few larger numbers like 2e12345, or better, - -2e12345, for which calc needs memory for both 2e12345 and - -2e12345! + There seems little point in retaining 27 as a constant and + therefore using up memory. If this example seems trivial, + replace 27 with a few larger numbers like 2e12345, or better, + -2e12345, for which calc needs memory for both 2e12345 and + -2e12345! - Constants are automatically freed a definition when a - function is re- or un-defined. + Constants are automatically freed a definition when a + function is re- or un-defined. - The qalloc(q) and qfree(q) functions have been changed so - that that q->links = 0 is permitted and indicates that q - has been freed. If a number has been introduced as a - constant, i.e. by a literal numeral as in the above - examples, its links becoming zero indicates that it is no - longer required and its position in the table of constants - becomes available for a later new constant. + The qalloc(q) and qfree(q) functions have been changed so + that that q->links = 0 is permitted and indicates that q + has been freed. If a number has been introduced as a + constant, i.e. by a literal numeral as in the above + examples, its links becoming zero indicates that it is no + longer required and its position in the table of constants + becomes available for a later new constant. - (4) extension of transcendental functions like tan, tanh, etc. - to complex arguments + (4) extension of transcendental functions like tan, tanh, etc. + to complex arguments - (5) definition of gd(z) and agd(z), i.e. the gudermannian and - inverse gudermannian + (5) definition of gd(z) and agd(z), i.e. the gudermannian and + inverse gudermannian - (6) introduction of show options for displaying information about - current constants, global variables, static variables, and cached - redc moduli. + (6) introduction of show options for displaying information about + current constants, global variables, static variables, and cached + redc moduli. - To help you follow what is going on, the following show - items have been introduced: + To help you follow what is going on, the following show + items have been introduced: - show constants ==> display the currently stored constants - show numbers ==> display the currently stored numbers - show redcdata ==> display the currently stored redc moduli - show statics ==> display info about static variables - show real ==> display only real-valued variables + show constants ==> display the currently stored constants + show numbers ==> display the currently stored numbers + show redcdata ==> display the currently stored redc moduli + show statics ==> display info about static variables + show real ==> display only real-valued variables - The constants are automatically initialized as constants and - should always appear, with links >= 1, in in the list of constants. + The constants are automatically initialized as constants and + should always appear, with links >= 1, in in the list of constants. - The show command: + The show command: - show globals + show globals - has been redefined so that it gives information about all - current global and still active static variables. + has been redefined so that it gives information about all + current global and still active static variables. - (7) definition of functions for freeing globals, statics, redc values + (7) definition of functions for freeing globals, statics, redc values - To free memory used by different kinds of variable, the following - builtins have been added: + To free memory used by different kinds of variable, the following + builtins have been added: - freeglobals(); /* free all globals */ - freestatics(); /* free all statics */ - freeredc(); /* free redc moduli */ - free(a, b, ...); /* free specific variables */ + freeglobals(); /* free all globals */ + freestatics(); /* free all statics */ + freeredc(); /* free redc moduli */ + free(a, b, ...); /* free specific variables */ - NOTE: These functions do not "undefine" the variables, but - have the effect of assigning the null value to them, and so - frees the memory used for elements of a list, matrix or object. + NOTE: These functions do not "undefine" the variables, but + have the effect of assigning the null value to them, and so + frees the memory used for elements of a list, matrix or object. - See 10) below for info about "undefine *". + See 10) below for info about "undefine *". - (8) enhancement of handling of "old value": having it return an - lvalue and giving option of disabling updating. + (8) enhancement of handling of "old value": having it return an + lvalue and giving option of disabling updating. - Now, by default, "." return an lvalue with the appropriate - value instead of copying the old value. + Now, by default, "." return an lvalue with the appropriate + value instead of copying the old value. - So that a string of commands may be given without changing - the "oldvalue", the new builtin: + So that a string of commands may be given without changing + the "oldvalue", the new builtin: - saveval(0) + saveval(0) - function simply disables the updating of the "." value. - The default updating can be resumed by calling: + function simply disables the updating of the "." value. + The default updating can be resumed by calling: - saveval(1) + saveval(1) - The "." value: + The "." value: - ; 2 + 2 - 4 - ; . - 4 + ; 2 + 2 + 4 + ; . + 4 - can now be treated as an unnamed variable. For example: + can now be treated as an unnamed variable. For example: - ; mat x[3,3]={1,2,3,4,5,6,7,8,9} - ; x - ; print .[1,2] - 6 + ; mat x[3,3]={1,2,3,4,5,6,7,8,9} + ; x + ; print .[1,2] + 6 - (9) for a list L defining L[i] to be same as L[[i]] + (9) for a list L defining L[i] to be same as L[[i]] - (10) extending undefine to permit its application to all user-defined - functions by using "undefine *". + (10) extending undefine to permit its application to all user-defined + functions by using "undefine *". - The command: + The command: - undefine * + undefine * - undefines all current user-defined functions. After - executing all the above freeing functions (and if - necessary free(.) to free the current "old value"), the - only remaining numbers as displayed by: + undefines all current user-defined functions. After + executing all the above freeing functions (and if + necessary free(.) to free the current "old value"), the + only remaining numbers as displayed by: - show numbers + show numbers - should be those associated with epsilon(), and if it has been - called, qpi(). + should be those associated with epsilon(), and if it has been + called, qpi(). - (11) storing the most recently calculated value of qpi(epsilon)i and - epsilon so that when called again with the same epsilon it - is copied rather than recalculated. + (11) storing the most recently calculated value of qpi(epsilon)i and + epsilon so that when called again with the same epsilon it + is copied rather than recalculated. - (12) defining trace() for square matrices + (12) defining trace() for square matrices - (13) expression in parentheses may now be followed by a qualifier - computable with its type + (13) expression in parentheses may now be followed by a qualifier + computable with its type - When an expression in parentheses evaluates to an lvalue - whose current value is a matrix, list or object, it may - now be followed by a qualifier compatible with its type. + When an expression in parentheses evaluates to an lvalue + whose current value is a matrix, list or object, it may + now be followed by a qualifier compatible with its type. - For example: + For example: - ; A = list(1,2,4); - ; B = mat[2,2] = {5,6,7,8}; - ; define f(x) = (x ? A : B)[[1]]; - ; print f(1), f(0) - 2 6 + ; A = list(1,2,4); + ; B = mat[2,2] = {5,6,7,8}; + ; define f(x) = (x ? A : B)[[1]]; + ; print f(1), f(0) + 2 6 - ; obj xy {x,y} - ; C = obj xy = {4,5} - ; p = &C - ; *p.x - Not indexing matrix or object - ; (*p).x - 4 + ; obj xy {x,y} + ; C = obj xy = {4,5} + ; p = &C + ; *p.x + Not indexing matrix or object + ; (*p).x + 4 - (14) swap(a,b) now permits swapping of octets in the same or different - blocks. + (14) swap(a,b) now permits swapping of octets in the same or different + blocks. - For example: + For example: - ; A = blk() = {1,2,3} - ; B = blk() = {4,5,6} - ; swap(A[0], B[2]) - ; A - chunksize = 256, maxsize = 256, datalen = 3 - 060203 + ; A = blk() = {1,2,3} + ; B = blk() = {4,5,6} + ; swap(A[0], B[2]) + ; A + chunksize = 256, maxsize = 256, datalen = 3 + 060203 A few bug fixes from Ernest Bowen: - B1: qcmpi(q, n) in qmath.c sometimes gave the wrong result if - LONG_BITS > BASEB, len = 1 and nf = 0, since it then - reduces to the value of (nf != q->num.v[1]) in which - q->num.v[1] is not part of the size-1 array of HALFs for - q->num. At present this is used only for changing opcodes - for ^2 and ^4 from sequences involving OP_POWER to - sequences using OP_SQUARE, which has no effect on the - results of calculations. + B1: qcmpi(q, n) in qmath.c sometimes gave the wrong result if + LONG_BITS > BASEB, len = 1 and nf = 0, since it then + reduces to the value of (nf != q->num.v[1]) in which + q->num.v[1] is not part of the size-1 array of HALFs for + q->num. At present this is used only for changing opcodes + for ^2 and ^4 from sequences involving OP_POWER to + sequences using OP_SQUARE, which has no effect on the + results of calculations. - B2: in matdet(m) in matfunc.c, a copy of the matrix m was not freed - when the determinant turned out have zero value. + B2: in matdet(m) in matfunc.c, a copy of the matrix m was not freed + when the determinant turned out have zero value. - B3: in f_search() in func.c, a qlinking of the NUMBER * storing the - the size of a file was not qfreed. + B3: in f_search() in func.c, a qlinking of the NUMBER * storing the + the size of a file was not qfreed. - B4: in comalloc() in commath.c the initial zero values for real and - imag parts are qlinked but not qfreed when nonzero values are - assigned to them. Rather than changing - the definition of comalloc(), I have included any relevant - qfrees with the calls to comalloc() as in - c = comalloc(); - qfree(c->real); - c->real = ... + B4: in comalloc() in commath.c the initial zero values for real and + imag parts are qlinked but not qfreed when nonzero values are + assigned to them. Rather than changing + the definition of comalloc(), I have included any relevant + qfrees with the calls to comalloc() as in + c = comalloc(); + qfree(c->real); + c->real = ... - B5: in calls to matsum(), zeros are qlinked but not qfreed. Rather - than changing addnumeric(), I have changed the definition - of matsum(m) so that it simply adds the components of m, - which requires only that the relevant additions be defined, - not that all components of m be numbers. + B5: in calls to matsum(), zeros are qlinked but not qfreed. Rather + than changing addnumeric(), I have changed the definition + of matsum(m) so that it simply adds the components of m, + which requires only that the relevant additions be defined, + not that all components of m be numbers. Simple arithmetic expressions with literal numbers are evaluated during compilation rather than execution. So: - define f(x) = 2 + 3 + x; + define f(x) = 2 + 3 + x; will be stored as if defined by: - define f(x) = 5 + x; + define f(x) = 5 + x; Fixed bug with lowhex2bin conversation in lib_util.c. It did not correctly convert from hex ASCII to binary values due to a table @@ -6661,7 +6668,7 @@ The following are the changes from calc version 2.10.3t5.28 to 2.10.3t5.33: is now 10000 cycles. SGI Mips r10k compile set is specified for IRIX6.5 with v7.2 - compilers. A note for pre-IRIX6.5 and/or pre-v7.2 compilers + compilers. A note for pre-IRIX6.5 and/or pre-v7.2 compilers is given in the compile set. Added regression tests related to saveval(), dot and pointers. @@ -6671,20 +6678,20 @@ 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: - 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: - B = blk(len, chunk) + B = blk(len, chunk) and named blocks as in: - B = blk(str, len, chunk) + B = blk(str, len, chunk) A block may be changed (with possible loss of data only if len is less than the old len) by: - C = blk(B, len, chunk) + C = blk(B, len, chunk) For an unnamed block B, this creates a new block C and copies min(len, oldlen) octets to it, B remaining unchanged. For a named @@ -6692,7 +6699,7 @@ The following are the changes from calc version 2.10.3t5.11 to 2.10.3t5.27: so that for example, C[i] = x will result in B[i] == x. Thus, for a named block, "B = " does nothing (other than B = B) in: - B = blk(B, len, chunk) + B = blk(B, len, chunk) but is necessary for changing an unnamed block. @@ -6701,13 +6708,13 @@ The following are the changes from calc version 2.10.3t5.11 to 2.10.3t5.27: The builtin function blkfree(val) will free memory allocated to block. If val is a named block, or the name of a named block, or the identifying index for a named block, blkfree(val) frees the - memory block allocated to this named block. The block remains + memory block allocated to this named block. The block remains in existence with the same name, identifying index, and chunksize, but its size and maxsize becomes zero and the pointer for the start of its data block null. The builtin function blocks() returns the number of blocks that - have been created but not freed by the blkfree() function. When called + have been created but not freed by the blkfree() function. When called as blocks(id) and the argument id less than the number of named blocks that have been created, blocks(id) returns the named block with identifying index id. @@ -6722,7 +6729,7 @@ The following are the changes from calc version 2.10.3t5.11 to 2.10.3t5.27: Added isobjtype() to determine the type of an object. The isatty(v) builtin will return 1 if v is a file that associated - with a tty (terminal, xterm, etc.) and 0 otherwise. The isatty(v) + with a tty (terminal, xterm, etc.) and 0 otherwise. The isatty(v) builtin will no longer return an error if v is not a file or is a closed file. @@ -6739,25 +6746,25 @@ The following are the changes from calc version 2.10.3t5.11 to 2.10.3t5.27: Blocks will expand when required by the copy() builtin function: - ; f = fopen("help/full", "r") - ; B = blk() - ; B - chunksize = 256, maxsize = 256, datalen = 0 - ; copy(B, f) - ; B - chunksize = 256, maxsize = 310272, datalen = 310084 - 2a2a2a2a2a2a2a2a2a2a2a2a2a0a2a20696e74726f0a2a2a2a2a2a2a2a2a... + ; f = fopen("help/full", "r") + ; B = blk() + ; B + chunksize = 256, maxsize = 256, datalen = 0 + ; copy(B, f) + ; B + chunksize = 256, maxsize = 310272, datalen = 310084 + 2a2a2a2a2a2a2a2a2a2a2a2a2a0a2a20696e74726f0a2a2a2a2a2a2a2a2a... - NOTE: Your results will differ because changes to help/full. + NOTE: Your results will differ because changes to help/full. The blkcpy() builtin args now more closely match that of memcpy(), strncpy: - blkcpy(dst, src [, num [, dsi [, ssi]]]) + blkcpy(dst, src [, num [, dsi [, ssi]]]) The copy() builtin args now more closely match that the cp command: - copy(src, dst [, num [, ssi [, dsi]]]) + copy(src, dst [, num [, ssi [, dsi]]]) but otherwise does the same thing as blkcpy. @@ -6781,15 +6788,15 @@ The following are the changes from calc version 2.10.3t5.11 to 2.10.3t5.27: Resolved a number of missing symbols for libcalc users. Added lib_util.{c,h} to the calc source to support users of - libcalc.a. These utility routines are not directly used by + libcalc.a. These utility routines are not directly used by calc but are otherwise have utility to those programmers who directly use libcalc.a instead. - Added sample sub-directory. This sub-directory contains a few - sample programs that use libcalc.a. These sample programs are + Added sample sub-directory. This sub-directory contains a few + sample programs that use libcalc.a. These sample programs are built via the all rule because they will help check to see that libcalc.a library does not contain external references that - cannot be resolved. At the current time none of these sample + cannot be resolved. At the current time none of these sample programs are installed. Added a libcalc_call_me_last() call to return storage created @@ -6800,11 +6807,11 @@ The following are the changes from calc version 2.10.3t5.11 to 2.10.3t5.27: Fixed fseek() file operations for SunOS. - Fixed convz2hex() fencepost error. It also removes leading 0's. + Fixed convz2hex() fencepost error. It also removes leading 0's. Plugged a memory leak relating to pmod. The following calculation: - pmod(2, x, something) + pmod(2, x, something) where x was not 2^n-1 would leak memory. This has been fixed. @@ -6815,62 +6822,62 @@ The following are the changes from calc version 2.10.3t5.1 to 2.10.3t5.10: Calc now permits chains of initializations as in: - obj point {x,y} P = {1,2} = {3,4} = {5,6} + obj point {x,y} P = {1,2} = {3,4} = {5,6} Here the initializations are applied from left to right. It may look silly, but the 1, 2, ... could be replaced by expressions with side effects. As an example of its use suppose A and B are expressions with side effects: - P = {A, B} + P = {A, B} - has the effect of P.x = A; P.y = B. Sometimes one might want these in + has the effect of P.x = A; P.y = B. Sometimes one might want these in the reverse order: P.y = B; P.x = A. This is achieved by: - P = { , B} = {A} + P = { , B} = {A} Another example of its use: - obj point Q = {P, P} = {{1, 2}, {3, 4}} + obj point Q = {P, P} = {{1, 2}, {3, 4}} which results in Q having Q.x.x = 1, Q.x.y = 2, etc. - The role of the comma in has been changed. Expressions such as: + The role of the comma in has been changed. Expressions such as: - mat A[2], B[3] + mat A[2], B[3] are equivalent to: - (mat A[2]), (mat B[3]) + (mat A[2]), (mat B[3]) Now, expr1, expr2 returns type of expr2 rather than EXPR_RVALUE. This permits expressions such as: - (a = 2, b) = 3 + (a = 2, b) = 3 - Also, expr1 ? expr2 : expr3 returns type(expr2) | type(expr3). + Also, expr1 ? expr2 : expr3 returns type(expr2) | type(expr3). This will make the result an lvalue (i.e. EXPR_RVALUE bit not set) For example, if both expr2 and expr3 are lvalues. Then: - a ? b : c = d + a ? b : c = d has the effect of b = d if a is "nonzero", otherwise c = d. This may be compared with - d = a ? b : c + d = a ? b : c which does d = b if a is "nonzero", otherwise d = c. And now, expr1 || expr2 and expr1 && expr2 each return - htype(expr1)| type(expr2). So for example: + htype(expr1)| type(expr2). So for example: - a || b = c + a || b = c has the effect of a = c if a is "nonzero", otherwise b = c. And for example: - a && b = c + a && b = c has the effect of a = c if a is "zero", otherwise b = c. @@ -6879,22 +6886,22 @@ The following are the changes from calc version 2.10.3t5.1 to 2.10.3t5.10: already defined, then: - a = ( - 2 - + - f - ( - 3 - ) - ) + a = ( + 2 + + + f + ( + 3 + ) + ) and - b = sqrt ( - 20 - , - 1 - ) + b = sqrt ( + 20 + , + 1 + ) will be accepted, and in interactive mode the continue-line prompt will be displayed. @@ -6904,16 +6911,16 @@ The following are the changes from calc version 2.10.3t5.1 to 2.10.3t5.10: until the expected conditions and statements are completed. For example: - s = 0; - for (i = 0; i < 5; i++) - { - s += i; - } - print s; + s = 0; + for (i = 0; i < 5; i++) + { + s += i; + } + print s; Now 's' will print '10' instead of '5'. - Added more regression tests to regress.cal. Changed the error + Added more regression tests to regress.cal. Changed the error counter from 'err' to 'prob'. The errmax() is set very high and the expected value of errcount() is kept in ecnt. @@ -6926,12 +6933,12 @@ The following are the changes from calc version 2.10.3t5.1 to 2.10.3t5.10: The blkalloc() builtin has been renamed blk(). - Only a "fixed" type of BLOCK will be used. Other types of + Only a "fixed" type of BLOCK will be used. Other types of blocks in the future will be different VALUE types. Introduced an undefine command so that - undefine f, g, ... + undefine f, g, ... frees the memory used to store code for user-defined functions f, g, ..., effectively removing them from the list of defined @@ -6943,18 +6950,18 @@ The following are the changes from calc version 2.10.3t5.1 to 2.10.3t5.10: Some experimental changes to block and octet handling, so that after: - B = blk(N) + B = blk(N) B[i] for 0 <= i < N behaves for some operations like an lvalue for a USB8 in B. xx_assign added to object functions to permit the possibility of - specifying what A = B will do if A is an xx-object. Normal + specifying what A = B will do if A is an xx-object. Normal assignment use of = is restored by the command: undefine xx_assign. For error-value err, errno(err) returns the error-code for err and - stores this in calc_errno; error(err) returns err as if + stores this in calc_errno; error(err) returns err as if error(errno(err)) were called. Anticipating probable future use, names have been introduced for @@ -6976,7 +6983,7 @@ The following are the changes from calc version 2.10.3t5.1 to 2.10.3t5.10: In most cases, CALC_ENV= CALCPATH=./lib is sufficient. Added ${CALC_LIBS} to list the libraries created and used to - build calc. The CALC_LIBS= custom/libcustcalc.a libcalc.a + build calc. The CALC_LIBS= custom/libcustcalc.a libcalc.a is standard for everyone. Improved how 'make calc' and 'make all' rules work with respect @@ -6996,10 +7003,10 @@ The following are the changes from calc version 2.10.3t5.1 to 2.10.3t5.10: To avoid symbol conflicts, *.h files produced and shipped with calc are enclosed that as similar to the following: - #if !defined(__CALC_H__) - #define __CALC_H__ - .. - #endif /* !__CALC_H__ */ + #if !defined(__CALC_H__) + #define __CALC_H__ + .. + #endif /* !__CALC_H__ */ Added memsize(x) builtin to print the best approximation of the size of 'x' including overhead. The sizeof(x) builtin attempts @@ -7013,7 +7020,7 @@ The following are the changes from calc version 2.10.3t5.1 to 2.10.3t5.10: 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 - contains the custom interface code. The main Makefile now + contains the custom interface code. The main Makefile now drives the building and installing of this code in a similar way that it drives the lib and help sub-directories. (see below) @@ -7031,17 +7038,17 @@ The following are the changes from calc version 2.10.3t4.16 to 2.10.3t5.0: This config parameter takes the place of the lib_debug global variable. By convention, "lib_debug" has the following meanings: - <-1 no debug messages are printed though some internal - debug actions and information may be collected + <-1 no debug messages are printed though some internal + debug actions and information may be collected - -1 no debug messages are printed, no debug actions will be taken + -1 no debug messages are printed, no debug actions will be taken - 0 only usage message regarding each important object are - printed at the time of the read (default) + 0 only usage message regarding each important object are + printed at the time of the read (default) - >0 messages regarding each important object are - printed at the time of the read in addition - to other debug messages + >0 messages regarding each important object are + printed at the time of the read in addition + to other debug messages The "calc_debug" is reserved by convention for internal calc routines. The output of "calc_debug" will change from release to release. @@ -7049,17 +7056,17 @@ The following are the changes from calc version 2.10.3t4.16 to 2.10.3t5.0: routine (make check). By convention, "calc_debug" has the following meanings: - <-1 reserved for future use + <-1 reserved for future use - -1 no debug messages are printed, no debug actions will be taken + -1 no debug messages are printed, no debug actions will be taken - 0 very little, if any debugging is performed (and then mostly - in alpha test code). The only output is as a result of - internal fatal errors (typically either math_error() or - exit() will be called). (default) + 0 very little, if any debugging is performed (and then mostly + in alpha test code). The only output is as a result of + internal fatal errors (typically either math_error() or + exit() will be called). (default) - >0 a greater degree of debugging is performed and more - verbose messages are printed (regress.cal uses 1). + >0 a greater degree of debugging is performed and more + verbose messages are printed (regress.cal uses 1). The "user_debug" is provided for use by users. Calc ignores this value other than to set it to 0 by default (for both "oldstd" and "newstd"). @@ -7069,16 +7076,16 @@ The following are the changes from calc version 2.10.3t4.16 to 2.10.3t5.0: The following is suggested as a convention for use of "user_debug". These are only suggestions: feel free to use it as you like: - <-1 no debug messages are printed though some internal - debug actions and information may be collected + <-1 no debug messages are printed though some internal + debug actions and information may be collected - -1 no debug messages are printed, no debug actions will be taken + -1 no debug messages are printed, no debug actions will be taken - 0 very little, if any debugging is performed. The only output - are from fatal errors. (default) + 0 very little, if any debugging is performed. The only output + are from fatal errors. (default) - >0 a greater degree of debugging is performed and more - verbose messages are printed + >0 a greater degree of debugging is performed and more + verbose messages are printed Added more code related to the BLOCK type. @@ -7098,8 +7105,8 @@ The following are the changes from calc version 2.10.3t4.16 to 2.10.3t5.0: Given the following: - obj point {x,y} - obj point P, Q + obj point {x,y} + obj point P, Q will will now create P and Q as obj point objects. @@ -7108,7 +7115,7 @@ The following are the changes from calc version 2.10.3t4.16 to 2.10.3t5.0: Added the custom() builtin function. The custom() builtin interface is designed to make it easier for local custom modification to be added to calc. Custom functions are - non-standard or non-portable code. For these reasons, one must can + non-standard or non-portable code. For these reasons, one must can only execute custom() code by way of an explicit action. By default, custom() returns an error. A new calc command line @@ -7132,7 +7139,7 @@ The following are the changes from calc version 2.10.3t4.16 to 2.10.3t5.0: of calling config("all", "newstd") at startup time. Added -e as a calc command line option to ignore all environment - variables at startup time. The getenv() builtin function will + variables at startup time. The getenv() builtin function will still return values, however. Added -i as a calc command line option. This has the effect @@ -7149,7 +7156,7 @@ The following are the changes from calc version 2.10.3t4.16 to 2.10.3t5.0: The 'make check' rule now uses the -i calc command line flag so that regress.cal can continue beyond when errcount exceeds errmax. In regress.cal, vrfy() reports when errcount exceeds - errmax and resets errmax to match errcount. This check + errmax and resets errmax to match errcount. This check and report is independent of the test success of failure. Fixed missing or out of order tests in regress.cal. @@ -7164,16 +7171,16 @@ The following are the changes from calc version 2.10.3t4.16 to 2.10.3t5.0: The help command will search ${LIBDIR}/custhelp if it fails to find a file in ${LIBDIR}. This allows the help command to also print - help for a custom function. However if a standard help file and a + help for a custom function. However if a standard help file and a custom help file share the same name, help will only print the - standard help file. One can skip the standard help file and print + standard help file. One can skip the standard help file and print the custom help file by: - help custhelp/name + help custhelp/name or by: - custom("help", "name") + custom("help", "name") Added minor sanity checks the help command's filename. @@ -7207,14 +7214,14 @@ 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 applied to a first or only term. Thus: - -16^-2 == -1/256 - -7^2 == -49 - -3! == -6 + -16^-2 == -1/256 + -7^2 == -49 + -3! == -6 Running ranlib is no longer the default. Systems that need RANLIB should edit the Makefile and comment back in: - RANLIB=ranlib + RANLIB=ranlib Dropped support of SGI r8k. @@ -7250,7 +7257,7 @@ The following are the changes from calc version 2.10.3t3 to 2.10.3t4.15: and randrun.cal a55 tests. Improved hash.c interface to lower level hash functions. The hash - interface does not yet have a func.c interface ... it is still + interface does not yet have a func.c interface ... it is still under test. Added randombitrun.cal to test the Blum-Blum-Shub generator. @@ -7260,30 +7267,30 @@ The following are the changes from calc version 2.10.3t3 to 2.10.3t4.15: In the original version, each call to newerror(str) created a new error-value. Now a new value will be created only if str has not - been used in a previous call to newerror(). In effect, the string + been used in a previous call to newerror(). In effect, the string serves to identify the error-value; for example: - return newerror("Non-integer argument"); + return newerror("Non-integer argument"); can be used in one or more functions, some of which may be repeatedly called, but after it has been called once, it will always return the same value as if one had initially used the assignment: - non_integer_argument_error = newerror("Non-integer argument") + non_integer_argument_error = newerror("Non-integer argument") and then in each function used: - return non_integer_argument_error; + return non_integer_argument_error; The new definition of newerror() permits its freer use in cases like: - define foo(a) { + define foo(a) { - if (!isint(a)) - return newerror("Non-integer argument"); - ... - } + if (!isint(a)) + return newerror("Non-integer argument"); + ... + } One might say that "new" in "newerror" used to mean being different from any earlier error-value. Now it means being not one of the @@ -7310,11 +7317,11 @@ The following are the changes from calc version 2.10.3t3 to 2.10.3t4.15: Added "blkmaxprint" config value, which limits the octets to print for a block. A "blkmaxprint" of 0 means to print all octets of a - block, regardless of size. The default is to print only the first + block, regardless of size. The default is to print only the first 256 octets. The "blkverbose" determines if all lines, including duplicates - should be printed. If TRUE, then all lines are printed. If false, + should be printed. If TRUE, then all lines are printed. If false, duplicate lines are skipped and only a "*" is printed in a style similar to od. This config value has not meaning if "blkfmt" is "str". The default value for "blkverbose" is FALSE: duplicate @@ -7323,39 +7330,39 @@ The following are the changes from calc version 2.10.3t3 to 2.10.3t4.15: The "blkbase" determines the base in which octets of a block are printed. Possible values are: - "hexadecimal" Octets printed in 2 digit hex - "hex" + "hexadecimal" Octets printed in 2 digit hex + "hex" - "octal" Octets printed in 3 digit octal - "oct" + "octal" Octets printed in 3 digit octal + "oct" - "character" Octets printed as chars with non-printing - "char" chars as \123 or \n, \t, \r + "character" Octets printed as chars with non-printing + "char" chars as \123 or \n, \t, \r - "binary" Octets printed as 0 or 1 chars - "bin" + "binary" Octets printed as 0 or 1 chars + "bin" - "raw" Octets printed as is, i.e. raw binary - "none" + "raw" Octets printed as is, i.e. raw binary + "none" The default "blkbase" is "hex". The "blkfmt" determines for format of how block are printed: - "line" print in lines of up to 79 chars + newline - "lines" + "line" print in lines of up to 79 chars + newline + "lines" - "str" print as one long string - "string" - "strings" + "str" print as one long string + "string" + "strings" - "od" print in od-like format, with leading offset, - "odstyle" followed by octets in the given base - "od_style" + "od" print in od-like format, with leading offset, + "odstyle" followed by octets in the given base + "od_style" - "hd" print in hex dump format, with leading offset, - "hdstyle" followed by octets in the given base, followed - "hd_style" by chars or '.' if no-printable or blank + "hd" print in hex dump format, with leading offset, + "hdstyle" followed by octets in the given base, followed + "hd_style" by chars or '.' if no-printable or blank The default "blkfmt" is "hd". @@ -7364,12 +7371,12 @@ The following are the changes from calc version 2.10.3t3 to 2.10.3t4.15: Assignments to matrices and objects has been changed. The assignments in: - A = list(1,2,3,4); - B = makelist(4) = {1,2,3,4}; + A = list(1,2,3,4); + B = makelist(4) = {1,2,3,4}; will result in A == B. Then: - A = {,,5} + A = {,,5} will result in A == list(1,2,5,4). @@ -7387,43 +7394,43 @@ The following are the changes from calc version 2.10.3t0 to 2.10.3t2: Fixed a casting problem in label.c. A lot of work was performed on the code generation by Ernest Bowen - . Declarations no longer + . Declarations no longer need to precede code: - define f(x) { - local i = x^2; - print "i = ":i; - local j = i; - ... - } + define f(x) { + local i = x^2; + print "i = ":i; + local j = i; + ... + } The scope of a variable extends from the end of the declaration (including initialization code for the variable) at which it is first created to the limit given by the following rules: - local variable: to the end of the function being defined + local variable: to the end of the function being defined - global variable: to the end of the session with calc + global variable: to the end of the session with calc - static within a function definition: to the first of: + static within a function definition: to the first of: - an end of a global, static or local declaration (including - initialization code) with the same identifier + an end of a global, static or local declaration (including + initialization code) with the same identifier - the end of the definition + the end of the definition - static at top level within a file: to the first of: + static at top level within a file: to the first of: - the next static declaration of the identifier at top level - in the file, + the next static declaration of the identifier at top level + in the file, - the next global declaration of the identifier at top level - in the file or in any function definition in the file, + the next global declaration of the identifier at top level + in the file or in any function definition in the file, - the next global declaration of the identifier at any level - in a file being read as a result of a "read" command, + the next global declaration of the identifier at any level + in a file being read as a result of a "read" command, - the end of the file. + the end of the file. The scope of a top-level global or static variable may be interrupted by the use of the identifier as a parameter or local or @@ -7443,57 +7450,57 @@ The following are the changes from calc version 2.10.3t0 to 2.10.3t2: and b = 0 if none of the x's have been positive odd, otherwise b = the first positive odd x + the number of positive odd x's: - define f(x) { - if (isint(x) && x > 0) { - if (iseven(x)) { - static a = x; - a++; - } else { - static b = x; - b++; - } - } - global a = a, b = b; - print "a =",a,"b =",b; - } + define f(x) { + if (isint(x) && x > 0) { + if (iseven(x)) { + static a = x; + a++; + } else { + static b = x; + b++; + } + } + global a = a, b = b; + print "a =",a,"b =",b; + } Fixed some faults in the handling of syntax errors for the matrix - and object creation operators mat and obj. In previous versions of calc: + and object creation operators mat and obj. In previous versions of calc: - mat; <- Bad dimension 0 for matrix - mat A; <- Bad dimension 0 for matrix - global mat A; <- Bad dimension 0 for matrix - mat A[2], mat B[3] <- Semicolon expected - global mat A[2], mat B[3] <- Bad syntax in declaration statement + mat; <- Bad dimension 0 for matrix + mat A; <- Bad dimension 0 for matrix + global mat A; <- Bad dimension 0 for matrix + mat A[2], mat B[3] <- Semicolon expected + global mat A[2], mat B[3] <- Bad syntax in declaration statement Now: - this statement has the same effect as - -------------- ---------------------- - mat A[2], B[3] (A = mat[2]), B[3] + this statement has the same effect as + -------------- ---------------------- + mat A[2], B[3] (A = mat[2]), B[3] - global mat A[2], B[3] global A, B; A = mat[2]; B = mat[3]; + global mat A[2], B[3] global A, B; A = mat[2]; B = mat[3]; Initialization remains essentially as before except that for objects, spaces between identifiers indicate assignments as in simple variable declarations. Thus, after: - obj point {x,y}; - obj point P, Q R = {1,2} + obj point {x,y}; + obj point P, Q R = {1,2} P has {0,0}, Q and R have {1,2}. In the corresponding expression with matrices commas between identifiers before the initialization are ignored. For example: - this statement has the same effect as - -------------- ---------------------- - mat A, B C [2] = {1,2} A = B = C = (mat[2] = {1,2}) + this statement has the same effect as + -------------- ---------------------- + mat A, B C [2] = {1,2} A = B = C = (mat[2] = {1,2}) One can also do things like: - L = list(mat[2] = {1,2}, obj point = {3,4}, mat[2] = {5,6}) - A = mat[2,2] = {1,2,3,4}^2 - B = mat[2,2] = {1,2,3,4} * mat[2,2] = {5,6,7,8} + L = list(mat[2] = {1,2}, obj point = {3,4}, mat[2] = {5,6}) + A = mat[2,2] = {1,2,3,4}^2 + B = mat[2,2] = {1,2,3,4} * mat[2,2] = {5,6,7,8} where the initialization = has stronger binding than the assignment = and the * sign. @@ -7501,16 +7508,16 @@ The following are the changes from calc version 2.10.3t0 to 2.10.3t2: Matrices and objects can be mixed in declarations after any simple variables as in: - global a, b, mat A, B[2] = {3,4}, C[2] = {4,5}, obj point P = {5,6}, Q + global a, b, mat A, B[2] = {3,4}, C[2] = {4,5}, obj point P = {5,6}, Q Fixed some bugs related to global and static scoping. See the 5200 regress test and lib/test5200.cal for details. Optimized opcode generator so that functions defined using '=' do not - have two unreached opcodes. I.e.,: + have two unreached opcodes. I.e.,: - define f(x) = x^2 - show opcodes f + define f(x) = x^2 + show opcodes f Also unreachable opcodes UNDEF and RETURN are now not included at the end of any user-defined function. @@ -7524,11 +7531,11 @@ The following are the changes from calc version 2.10.3t0 to 2.10.3t2: A label can now be immediately by a right-brace. For example: - define test_newop3(x) {if (x < 0) goto l132; ++x; l132: return x;} + define test_newop3(x) {if (x < 0) goto l132; ++x; l132: return x;} The LONG_BITS make variable, if set, will force the size of a long as well as forcing the USB8, SB8, USB16, SB16, USB32, SB32, - HAVE_B64, USB64, SB64, U(x) and L(x) types. If the longbits + HAVE_B64, USB64, SB64, U(x) and L(x) types. If the longbits program is given an arg (of 32 or 64), then it will output based on a generic 32 or 64 bit machine where the long is the same size as the wordsize. @@ -7548,80 +7555,80 @@ The following are the changes from calc version 2.10.2t33 to 2.10.2t34: Thanks to Ernest Bowen , for two or three arguments, - search(x, val, start); - rsearch(x, val, start); + search(x, val, start); + rsearch(x, val, start); and for matrix, list or association x: - search(f, str, start); - rsearch(f, str, start); + search(f, str, start); + rsearch(f, str, start); for a file stream f open for reading, behave as before except for a few differences: - (1) there are no limits on the integer-valued start. + (1) there are no limits on the integer-valued start. - (2) negative values of start are interpreted as offsets from the size of - x and f. For example, + (2) negative values of start are interpreted as offsets from the size of + x and f. For example, - search(x, val, -100) + search(x, val, -100) - searches the last 100 elements of x for the first i for which - x[[i]] = val. + searches the last 100 elements of x for the first i for which + x[[i]] = val. - (3) for a file f, when start + strlen(str) >= size(f) and - search(f, str, start) returns null, i.e. str is - not found, the file position after the search will be + (3) for a file f, when start + strlen(str) >= size(f) and + search(f, str, start) returns null, i.e. str is + not found, the file position after the search will be - size(f) - strlen(str) + 1 + size(f) - strlen(str) + 1 - rather than size(f). + rather than size(f). For four arguments: - search(a, b, c, d) - rsearch(a, b, c, d), + search(a, b, c, d) + rsearch(a, b, c, d), a has the role of x or f, and b the role of val or str as described above for the three-argument case, and for search(), c is essentially "start" as before, but for rsearch() is better for c and d to be the same as for search(). For a non-file case, if: - 0 <= c < d <= size(a), + 0 <= c < d <= size(a), the index-interval over which the search is to take place is: - c <= i < d. + c <= i < d. If the user has defined a function accept(v,b), this is used rather than the test v == b to decide for matrix, list, or association searches when a "match" of v = a[[i]] with b occurs. E.g. after: - define accept(v,b) = (v >= b); + define accept(v,b) = (v >= b); then calling: - search(a, 5, 100, 200) + search(a, 5, 100, 200) will return, if it exists, the smallest index i for which 100 <= i < 200 and a[[i]] >= 5. To restore the effect of the original "match" function, one would then have to: - define accept(v,b) == (v == b). + define accept(v,b) == (v == b). Renamed the calc symbol BYTE_ORDER to CALC_BYTE_ORDER in order to avoid conflict. Added beer.cal and hello.cal lib progs in support of: :-) - http://www.ionet.net/~timtroyr/funhouse/beer.html - http://www.latech.edu/~acm/HelloWorld.shtml + http://www.ionet.net/~timtroyr/funhouse/beer.html + http://www.latech.edu/~acm/HelloWorld.shtml The following are the changes from calc version 2.10.2t25 to 2.10.2t32: Eliminated use of VARARG and . Calc supports only - . The VARARGS Makefile variable has been eliminated. + . The VARARGS Makefile variable has been eliminated. Source is converted to ANSI C. In particular, functions will now have ANSI C style args. Any comments from old K&R @@ -7656,129 +7663,129 @@ The following are the changes from calc version 2.10.2t25 to 2.10.2t32: Confusion over the scope of static and global values has been reduced by a patch from Ernest Bowen . - The change introduced by the following patch terminates the - scope of a static variable at any static declaration with the - same name at the same level, or at any global declaration with - the same name at any level. With the example above, the scope - of the static "a" introduced in the third line ends when the - "global a" is read in the last line. Thus one may now use the - same name in several "static" areas as in: + The change introduced by the following patch terminates the + scope of a static variable at any static declaration with the + same name at the same level, or at any global declaration with + the same name at any level. With the example above, the scope + of the static "a" introduced in the third line ends when the + "global a" is read in the last line. Thus one may now use the + same name in several "static" areas as in: - ; static a = 10; - ; define f(x) = a + x; - ; static a = 20; - ; define g(x) = a + x; - ; global a; + ; static a = 10; + ; define f(x) = a + x; + ; static a = 20; + ; define g(x) = a + x; + ; global a; - The first "a" exists only for the definition of f(); the second - "a" only for the definition of g(). At the end one has only - the global "a". + The first "a" exists only for the definition of f(); the second + "a" only for the definition of g(). At the end one has only + the global "a". - Ending the scope of a static variable in this way is consistent - with the normal use of static variables as in: + Ending the scope of a static variable in this way is consistent + with the normal use of static variables as in: - ; static a = 10; - ; define f(x) {static a = 20; return a++ + x;} - ; define g(x) = a + x; - ; global a; + ; static a = 10; + ; define f(x) {static a = 20; return a++ + x;} + ; define g(x) = a + x; + ; global a; - The scope of the first "a" is temporarily interrupted by the - "static a" in the second line; the second "a" remains active - until its scope ends with the ending of the definition of f(). - Thus one ends with g(x) = 10 + x and on successive calls to - f(), f(x) returns 20 + x, 21 + x, etc. With successive "static - a" declarations at the same level, the active one at any stage - is the most recent; if the instructions are being read from a - file, the scope of the last "static a" ends at the end-of-file. + The scope of the first "a" is temporarily interrupted by the + "static a" in the second line; the second "a" remains active + until its scope ends with the ending of the definition of f(). + Thus one ends with g(x) = 10 + x and on successive calls to + f(), f(x) returns 20 + x, 21 + x, etc. With successive "static + a" declarations at the same level, the active one at any stage + is the most recent; if the instructions are being read from a + file, the scope of the last "static a" ends at the end-of-file. - Here I have assumed that no "global a" is encountered. As - there can be only one global variable with name "a", it seems - to me that its use must end the scope of any static "a". Thus - the changes I introduce are such that after: + Here I have assumed that no "global a" is encountered. As + there can be only one global variable with name "a", it seems + to me that its use must end the scope of any static "a". Thus + the changes I introduce are such that after: - ; global a = 10; - ; define f(x) = a + x; - ; static a = 20; - ; define g(x) = a + x; - ; define h(x) {global a = 30; return a + x;} - ; define i(x) = a + x; + ; global a = 10; + ; define f(x) = a + x; + ; static a = 20; + ; define g(x) = a + x; + ; define h(x) {global a = 30; return a + x;} + ; define i(x) = a + x; - g(x) will always return 20 + x, and until h(x) has been called, - f(x) and i(x) will return 10 + x; when h(x) is called, it - returns 30 + x and any later call to f(x) or i(x) will return - 30 + x. It is the reading of "global a" in the definition of - h() that terminates the scope of the static a = 20, so that the - "a" for the last line is the global variable defined in the - first line. The "a = 30" is executed only when h() is called. + g(x) will always return 20 + x, and until h(x) has been called, + f(x) and i(x) will return 10 + x; when h(x) is called, it + returns 30 + x and any later call to f(x) or i(x) will return + 30 + x. It is the reading of "global a" in the definition of + h() that terminates the scope of the static a = 20, so that the + "a" for the last line is the global variable defined in the + first line. The "a = 30" is executed only when h() is called. - Users who find this confusing might be well advised to use - different names for different variables at the same scope level. + Users who find this confusing might be well advised to use + different names for different variables at the same scope level. - The other changes produced by the patch are more straightforward, - but some tricky programming was needed to get the possibility of - multiple assignments and what seems to be the appropriate order - of executions and assignments. For example, the order for the - declaration: + The other changes produced by the patch are more straightforward, + but some tricky programming was needed to get the possibility of + multiple assignments and what seems to be the appropriate order + of executions and assignments. For example, the order for the + declaration: - global a, b = expr1, c, d = expr2, e, f + global a, b = expr1, c, d = expr2, e, f - will be: + will be: - evaluation of expr1; - assignment to b; - evaluation of expr2; - assignment to d; + evaluation of expr1; + assignment to b; + evaluation of expr2; + assignment to d; - Thus the effect is the same as for: + Thus the effect is the same as for: - a = 0; b = expr1; c = 0; d = expr2; e = 0; f = 0; + a = 0; b = expr1; c = 0; d = expr2; e = 0; f = 0; - The order is important when the same name is used for different - variables in the same context. E.g. one may have: + The order is important when the same name is used for different + variables in the same context. E.g. one may have: - define f(x) { - global a = 10; - static a = a; - local a = a--; + define f(x) { + global a = 10; + static a = a; + local a = a--; - while (--a > 0) - x++; - return x; - } + while (--a > 0) + x++; + return x; + } - Every time this is called, the global "a" is assigned the value - 10. The first time it is called, the value 10 is passed on to - the static "a" and then to the local "a". In each later call - the "static a = a" is ignored and the static "a" is one less than - it was in the preceding call. I'm not recommending this style of - programming but it is good that calc will be able to handle it. + Every time this is called, the global "a" is assigned the value + 10. The first time it is called, the value 10 is passed on to + the static "a" and then to the local "a". In each later call + the "static a = a" is ignored and the static "a" is one less than + it was in the preceding call. I'm not recommending this style of + programming but it is good that calc will be able to handle it. - I've also changed dumpop to do something recent versions do not do: - distinguish between static and global variables with the same name. + I've also changed dumpop to do something recent versions do not do: + distinguish between static and global variables with the same name. - Other changes: commas may be replaced by spaces in a sequence of - identifiers in a declaration. so one may now write: + Other changes: commas may be replaced by spaces in a sequence of + identifiers in a declaration. so one may now write: - global a b c = 10, d e = 20 + global a b c = 10, d e = 20 - The comma after the 10 is still required. Multiple occurrences - of an identifier in a local declaration are now acceptable as - they are for global or static declarations: + The comma after the 10 is still required. Multiple occurrences + of an identifier in a local declaration are now acceptable as + they are for global or static declarations: - local a b c = 10, a = 20; + local a b c = 10, a = 20; - does the same as: + does the same as: - local a b c; - a = b = c = 10; - a = 20; + local a b c; + a = b = c = 10; + a = 20; - The static case is different in that: + The static case is different in that: - static a b c = 10, a = 20; + static a b c = 10, a = 20; - creates four static variables, the first "a" having a very short and - useless life. + creates four static variables, the first "a" having a very short and + useless life. Added new tests to verify the new assignments above. @@ -7806,26 +7813,26 @@ The following are the changes from calc version 2.10.2t4 to 2.10.2t24: Added makefile debugging rules: - make chk like a 'make check' (run the regression tests) - except that only a few lines around interesting - (and presumable error messages) are printed. - No output if no errors are found. + make chk like a 'make check' (run the regression tests) + except that only a few lines around interesting + (and presumable error messages) are printed. + No output if no errors are found. - make env print important makefile values + make env print important makefile values - make mkdebug 'make env' + version information and a - make with verbose output and printing of - constructed files + make mkdebug 'make env' + version information and a + make with verbose output and printing of + constructed files - make debug 'make mkdebug' with a 'make clobber' - so that the entire make is verbose and - a constructed files are printed + make debug 'make mkdebug' with a 'make clobber' + so that the entire make is verbose and + a constructed files are printed Improved instructions in 'BUGS' section on reporting problems. In particular we made it easy for people to send in a full diagnostic output by sending 'debug.out' which is made as follows: - make debug > debug.out + make debug > debug.out Added -v to calc command line to print the version and exit. @@ -7848,8 +7855,8 @@ The following are the changes from calc version 2.10.2t4 to 2.10.2t24: The show keyword is now a statement instead of a command: - ; define demo() {local f = open("foo", "w"); show files; fclose(f);} - ; demo() + ; define demo() {local f = open("foo", "w"); show files; fclose(f);} + ; demo() Added a new trace option for display of links to real and complex numbers. This is activated by config("trace", 4). The printing of @@ -7863,7 +7870,7 @@ The following are the changes from calc version 2.10.2t4 to 2.10.2t24: is assigned to lvalues, "linking" rather than copying occurs. Different sets of mutually linked values may contain the same number. For example: - a = b = 2 + 3; x, y = 2 + 3; + a = b = 2 + 3; x, y = 2 + 3; a and b are linked, and x and y are linked, but a and x are not linked. @@ -7871,7 +7878,7 @@ The following are the changes from calc version 2.10.2t4 to 2.10.2t24: file to indicate where recent versions of calc are available. The regression test suite output has been changed so that it will - output the same information regardless of CPU performance. In + output the same information regardless of CPU performance. In particular, CPU times of certain tests are not printed. This allows one to compare the regression output of two different systems easier. @@ -7879,33 +7886,33 @@ The following are the changes from calc version 2.10.2t4 to 2.10.2t24: and returns a matrix or object of the specified type. Thus one may use assignments like: - A = mat[2]; /* same as: mat A[2]; */ - P = obj point; /* same as: obj point P; */ + A = mat[2]; /* same as: mat A[2]; */ + P = obj point; /* same as: obj point P; */ The obj and mat keywords may be with "local", "global", "static" as in: - local mat A[2]; + local mat A[2]; Several matrices or objects may be assigned or declared in the one statement, as in: - mat A, B[2], C[3]; /* same as: mat A[2], B[2], C[3] */ + mat A, B[2], C[3]; /* same as: mat A[2], B[2], C[3] */ except that only one matrix creation occurs and is copied as in: - A = B = mat[2]; + A = B = mat[2]; Initialization of matrices and objects now occur before assignments: - mat A, B [2] = {1,2}; /* same as: A = B = (mat[2] = {1,2}); */ + mat A, B [2] = {1,2}; /* same as: A = B = (mat[2] = {1,2}); */ Missing arguments are considered as "no change" rather than "assign null values". As in recent versions of calc, the default value assigned to matrix elements is zero and the default for object - elements is a null value). Thus: + elements is a null value). Thus: - mat A[2] = {1,2}; - A = { , 3}; + mat A[2] = {1,2}; + A = { , 3}; will change the value of A to {1,3}. @@ -7913,61 +7920,61 @@ The following are the changes from calc version 2.10.2t4 to 2.10.2t24: the type of object A is, the assignment = may be combined with +, -, *, etc. as in: - A += {3, 4}; /* same as: A[0] += 3; A[1] += 4; */ - A += { }; /* same as: A += A; */ + A += {3, 4}; /* same as: A[0] += 3; A[1] += 4; */ + A += { }; /* same as: A += A; */ In (non-local) declarations, the earlier value of a variable may be used in the initialization list: - mat A[3]={1,2,3}; mat A[3]={A[2],A[1],A[0]}; /* same as: A={3,2,1} */ + mat A[3]={1,2,3}; mat A[3]={A[2],A[1],A[0]}; /* same as: A={3,2,1} */ Also: - mat A[3] = {1,2,3}; - mat A[3] = {A, A, A}; + mat A[3] = {1,2,3}; + mat A[3] = {A, A, A}; produces a 3-element matrix, each of whose elements is a 3-element matrix. The notation A[i][j] requires A[i] to be a matrix, whereas B[i,j] accesses an element in a 2-dimensional matrix. Thus: - B == A[i] implies A[i][j] = B[j] + B == A[i] implies A[i][j] = B[j] There is requirement in the use of A[i][j] that the matrices A[i] - for i = 0, 1, ... all be of the same size. Thus: + for i = 0, 1, ... all be of the same size. Thus: - mat A[3] = {(mat[2]), (mat[3]), (mat[2])}; + mat A[3] = {(mat[2]), (mat[3]), (mat[2])}; produces a matrix with a 7-element structure: - A[0][0], A[0][1], A[1][0], A[1][1], A[1][2], A[2][0], A[2][1] + A[0][0], A[0][1], A[1][0], A[1][1], A[1][2], A[2][0], A[2][1] One can initialize matrices and objects whose elements are matrices and/or objects: - obj point {x,y} - obj point P; - obj point A = {P,P}; + obj point {x,y} + obj point P; + obj point A = {P,P}; or: - obj point {x,y}; - obj point P; - mat A[2] = {P,P}; - A = {{1,2}, {3,4}}; + obj point {x,y}; + obj point P; + mat A[2] = {P,P}; + A = {{1,2}, {3,4}}; The config("trace", 8) causes opcodes of newly defined functions are displayed. Also show can now show the opcodes for a function. For example: - config("trace", 8); - define f(x) = x^2; - show opcodes f; - define g(x,y) {static mat A[2]; A += {x,y}; return A;} - show opcodes g - g(2,3); - show opcodes g; - g(3,4); + config("trace", 8); + define f(x) = x^2; + show opcodes f; + define g(x,y) {static mat A[2]; A += {x,y}; return A;} + show opcodes g + g(2,3); + show opcodes g; + g(3,4); The two sequences displayed for f should show the different ways the parameter is displayed. The third sequence for g should also @@ -7984,23 +7991,23 @@ The following are the changes from calc version 2.10.2t4 to 2.10.2t24: Reduced the Makefile CC set: - CCOPT are flags given to ${CC} for optimization - CCWARN are flags given to ${CC} for warning message control - CCMISC are misc flags given to ${CC} + CCOPT are flags given to ${CC} for optimization + CCWARN are flags given to ${CC} for warning message control + CCMISC are misc flags given to ${CC} - CFLAGS are all flags given to ${CC} - [[often includes CCOPT, CCWARN, CCMISC]] - ICFLAGS are given to ${CC} for intermediate progs + CFLAGS are all flags given to ${CC} + [[often includes CCOPT, CCWARN, CCMISC]] + ICFLAGS are given to ${CC} for intermediate progs - CCMAIN are flags for ${CC} when files with main() instead of CFLAGS - CCSHS are flags given to ${CC} for compiling shs.c instead of CFLAGS + CCMAIN are flags for ${CC} when files with main() instead of CFLAGS + CCSHS are flags given to ${CC} for compiling shs.c instead of CFLAGS - LCFLAGS are CC-style flags for ${LINT} - LDFLAGS are flags given to ${CC} for linking .o files - ILDFLAGS are flags given to ${CC} for linking .o files - for intermediate progs + LCFLAGS are CC-style flags for ${LINT} + LDFLAGS are flags given to ${CC} for linking .o files + ILDFLAGS are flags given to ${CC} for linking .o files + for intermediate progs - CC is how the C compiler is invoked + CC is how the C compiler is invoked Added more tests to regress.cal. @@ -8014,10 +8021,10 @@ The following are the changes from calc version 2.10.2t4 to 2.10.2t24: Now each invocation of make is done via ${MAKE} and includes: - MAKE_FILE=${MAKE_FILE} - TOPDIR=${TOPDIR} - LIBDIR=${LIBDIR} - HELPDIR=${HELPDIR} + MAKE_FILE=${MAKE_FILE} + TOPDIR=${TOPDIR} + LIBDIR=${LIBDIR} + HELPDIR=${HELPDIR} Setting MAKE_FILE= will cause make to not re-make if the Makefile is edited. @@ -8036,29 +8043,29 @@ The following are the changes from calc version 2.10.2t4 to 2.10.2t24: Statements such as: - mat A[2][3]; + mat A[2][3]; now to the same as: - mat M[3]; - mat A[2] = {M, M}; + mat M[3]; + mat A[2] = {M, M}; To initialize such an A one can use a statement like - A = {{1,2,3}, {4,5,6}}; + A = {{1,2,3}, {4,5,6}}; or combine initialization with creation by: - mat A[2][3] = {{1,2,3}, {4,5,6}}; + mat A[2][3] = {{1,2,3}, {4,5,6}}; One would then have, for example, A[1][0] = 4. Also, the inner braces cannot be removed from the initialization for A: - mat A[2][3] = {1,2}; + mat A[2][3] = {1,2}; results in exactly the same as: - mat A[2] = {1,2}; + mat A[2] = {1,2}; Added rm("file") builtin to remove a file. @@ -8083,7 +8090,7 @@ The following are the changes from calc version 2.10.2t4 to 2.10.2t24: for more tests. Fixed all out of sequence test numbers. Fixed some malformed regression reports. - Renamed STSIZE_BITS to OFF_T_BITS. Renamed SWAP_HALF_IN_STSIZE to + Renamed STSIZE_BITS to OFF_T_BITS. Renamed SWAP_HALF_IN_STSIZE to SWAP_HALF_IN_OFF_T. @@ -8146,22 +8153,22 @@ The following are the changes from calc version 2.10.2t1 to 2.10.2t3: may be "reopened" with the freopen() command. This write to a file and then read it, use: - f = fopen("junk", "w") - freopen(f, "r") + f = fopen("junk", "w") + freopen(f, "r") - To use the same stream f for a new file, one may use: + To use the same stream f for a new file, one may use: - freopen(f, mode, newfilename) + freopen(f, mode, newfilename) - which closes f (assuming it is open) and then opens newfilename on f. + which closes f (assuming it is open) and then opens newfilename on f. - And as before: + And as before: - f = fopen("curds", "r") - g = fopen("curds", "r") + f = fopen("curds", "r") + g = fopen("curds", "r") - results in two file ids (f and g) that refer to the same file - name but with different pointers. + results in two file ids (f and g) that refer to the same file + name but with different pointers. Calc now understands "w+", "a+" and "r+" file modes. @@ -8180,20 +8187,20 @@ The following are the changes from calc version 2.10.2t1 to 2.10.2t3: terminating '\0' when writing a string to a file. This can be done at present with a sequence of instructions like: - fputs(f, "Landon"); fputc(f, 0); - fputs(f, "Curt"); fputc(f, 0); - fputs(f, "Noll"); fputc(f, 0); + fputs(f, "Landon"); fputc(f, 0); + fputs(f, "Curt"); fputc(f, 0); + fputs(f, "Noll"); fputc(f, 0); - One may now do: + One may now do: - fputstr(f, "Landon", "Curt", "Noll"); + fputstr(f, "Landon", "Curt", "Noll"); - and read them back by: + and read them back by: - rewind(f); - x = fgetstr(f); /* returns "Landon" */ - y = fgetstr(f); /* returns "Curt" */ - z = fgetstr(f); /* returns "Noll" */ + rewind(f); + x = fgetstr(f); /* returns "Landon" */ + y = fgetstr(f); /* returns "Curt" */ + z = fgetstr(f); /* returns "Noll" */ The builtin fgetfield() returns the next field of non-whitespace characters. @@ -8201,10 +8208,10 @@ The following are the changes from calc version 2.10.2t1 to 2.10.2t3: The builtins scan(), fscan(), strscan() read tokens (fields of non-whitespace characters) and evaluates them. Thus: - global a,b,c; - strscan("2+3 4^2\n c=a+b", a, b, 0); + global a,b,c; + strscan("2+3 4^2\n c=a+b", a, b, 0); - results in a = 5, b = 16, c = 21 + results in a = 5, b = 16, c = 21 The functions scanf, fscanf, strscanf behave like the C functions scanf, fscanf, sscanf. The conversion specifiers recognized are "%c", @@ -8216,7 +8223,7 @@ The following are the changes from calc version 2.10.2t1 to 2.10.2t3: E.g. expressions like 2e4i+7/8 are acceptable. The builtin size(x) now returns the size of x if x is an open file - or -1 if x is a file but not open. If s is a string, size(s) returns + or -1 if x is a file but not open. If s is a string, size(s) returns characters in s. Added builtin access("foo", "w") returns the null value if a file @@ -8231,14 +8238,14 @@ The following are the changes from calc version 2.10.2t1 to 2.10.2t3: Calc error codes are now as follows: - <0 invalid - 0 .. sys_nerr-1 system error ala C's errno values - sys_nerr .. E__BASE-1 reserved for future system errors - E__BASE .. E__HIGHEST calc internal errors - E__HIGHEST+1 .. E_USERDEF-1 invalid - E_USERDEF .. user defined errors + <0 invalid + 0 .. sys_nerr-1 system error ala C's errno values + sys_nerr .. E__BASE-1 reserved for future system errors + E__BASE .. E__HIGHEST calc internal errors + E__HIGHEST+1 .. E_USERDEF-1 invalid + E_USERDEF .. user defined errors - Currently, E__BASE == 10000 and E_USERDEF == 20000. Of course, + Currently, E__BASE == 10000 and E_USERDEF == 20000. Of course, sys_nerr is system defined however is likely to be < E__BASE. Renamed CONST_TYPE (as defined in have_const.h) to just CONST. @@ -8246,17 +8253,17 @@ The following are the changes from calc version 2.10.2t1 to 2.10.2t3: on if your compiler understands const. CONST is beginning to be used with read-only tables and some - function arguments. This allows certain compilers to better + function arguments. This allows certain compilers to better optimize the code as well as alerts one to when some value is being changed inappropriately. Use of CONST as in: - int foo(CONST int curds, char *CONST whey) + int foo(CONST int curds, char *CONST whey) while legal C is not as useful because the caller is protected - by the fact that args are passed by value. However, the + by the fact that args are passed by value. However, the in the following: - int bar(CONST char *fizbin, CONST HALF *data) + int bar(CONST char *fizbin, CONST HALF *data) is useful because it calls the compiler that the string pointed at by 'fizbin' and the HALF array pointer at by 'data' should be @@ -8271,7 +8278,7 @@ The following are the changes from calc version 2.10.1t21 to 2.10.2t0: Fewer items listed in BUGS due to a number of bug fixes. - Less todo in the help/todo file because more has already been done. :-) + Less todo in the help/todo file because more has already been done. :-) All builtin functions have help files! While a number need cleanup and some of the LIMITS, LIBRARY and SEE ALSO sections need fixing @@ -8282,7 +8289,7 @@ The following are the changes from calc version 2.10.1t21 to 2.10.2t0: The recognition of '\' as an escape character in the format argument of printf() has been dropped. Thus: - printf("\\n"); + printf("\\n"); will print the two-character string "\n" rather than the a one-character carriage return. @@ -8293,17 +8300,17 @@ The following are the changes from calc version 2.10.1t21 to 2.10.2t0: so that for example, after config("mode","real"), config("display", 5), config("fullzero", 1), both: - print 0, 1, 2; - printf("%d %d %d\n", 0, 1, 2); + print 0, 1, 2; + printf("%d %d %d\n", 0, 1, 2); print: - .00000 1.00000, 2.00000 + .00000 1.00000, 2.00000 The bug which caused calc to exit on: - b = "print 27+" - eval(b) + b = "print 27+" + eval(b) has been fixed. @@ -8312,11 +8319,11 @@ The following are the changes from calc version 2.10.1t21 to 2.10.2t0: The following: - for (i = 1; i < 10; i++) print i^2,; + for (i = 1; i < 10; i++) print i^2,; now prints the same as: - for (i = 1; i < 10; i++) print i^2,; + for (i = 1; i < 10; i++) print i^2,; The show globals will print '...' in the middle of large values. @@ -8328,21 +8335,21 @@ The following are the changes from calc version 2.10.1t21 to 2.10.2t0: The param(n) builtin, then n > 0, may be used as an lvalue: - ; define g() = (param(2) = param(1)); - ; define h() = (param(1)++, param(2)--); - ; u = 5 - ; v = 10 - ; print g(u, &v), u, v; - 5 5 5 - ; print h(&u, &v), u, v; - 5 6 4 + ; define g() = (param(2) = param(1)); + ; define h() = (param(1)++, param(2)--); + ; u = 5 + ; v = 10 + ; print g(u, &v), u, v; + 5 5 5 + ; print h(&u, &v), u, v; + 5 6 4 Missing args now evaluate to null as in: - A = list(1,,3) - B = list(,,) - mat C[] = {,,} - mat D[] = { } + A = list(1,,3) + B = list(,,) + mat C[] = {,,} + mat D[] = { } The following are the changes from calc version 2.10.1t20 to 2.10.1t20: @@ -8351,11 +8358,11 @@ The following are the changes from calc version 2.10.1t20 to 2.10.1t20: REDC bug fixes: - Fixed yet another bug in zdiv which occasionally caused the "top digit" - of a nonzero quotient to be zero. + Fixed yet another bug in zdiv which occasionally caused the "top digit" + of a nonzero quotient to be zero. - Fixed a bug in zredcmul() where a rarely required "topdigit" is - sometimes lost rather than added to the appropriate carry. + Fixed a bug in zredcmul() where a rarely required "topdigit" is + sometimes lost rather than added to the appropriate carry. A new function zredcmodinv(ZVALUE z, ZVALUE *res) has been defined for evaluating rp->inv in zredcalloc(). @@ -8442,15 +8449,15 @@ The following are the changes from calc version 2.10.1t11 to 2.10.1t19: Complex number ordering/comparison has been changed such that: - a < b implies a + c < b + c - a < b and c > 0 implies a * c < b * c - a < b implies -a > -b + a < b implies a + c < b + c + a < b and c > 0 implies a * c < b * c + a < b implies -a > -b To achieve a "natural" partial ordering of the complex numbers with the above properties, cmp(a,b) for real or complex numbers may be considered as follows: - cmp(a,b) = sgn(re(a) - re(b)) + sgn(im(a) - im(b)) * 1i + cmp(a,b) = sgn(re(a) - re(b)) + sgn(im(a) - im(b)) * 1i The cmp help file has been updated. @@ -8459,23 +8466,23 @@ The following are the changes from calc version 2.10.1t11 to 2.10.1t19: Added the CONFIG type; a structure containing all of the configuration values under the control of config(). Added V_CONFIG data type. - The call config("all") returns a V_CONFIG. One may now save/restore + The call config("all") returns a V_CONFIG. One may now save/restore the configuration state as follows: - x = config("all") - ... - config("all",x) + x = config("all") + ... + config("all",x) Added two configuration aliases, "oldstd" (for old backward compatible standard configuration) and "newstd" (for new style configuration). One may set the historic configuration state by: - config("all", "oldstd") + config("all", "oldstd") One may use what some people consider to be a better but not backward compatible configuration state by: - config("all", "newstd") + config("all", "newstd") Renamed config.h (configuration file built during the make) to conf.h. Added a new config.h to contain info on the V_CONFIG type. @@ -8503,14 +8510,14 @@ The following are the changes from calc version 2.10.1t11 to 2.10.1t19: Set config("cfsim",8) by default (in "oldstd"). Setup initial idea for config("all", "newstd") to be the default with the following changes: - display 10 - epsilon 1e-10 - quo 0 - outround 24 - leadzero 1 - fullzero 1 - prompt "; " (allows full line cut/paste) - more ";; " (allows full line cut/paste) + display 10 + epsilon 1e-10 + quo 0 + outround 24 + leadzero 1 + fullzero 1 + prompt "; " (allows full line cut/paste) + more ";; " (allows full line cut/paste) The "newstd" is a (hopefully) more preferred configuration than the historic default. @@ -8548,15 +8555,15 @@ The following are the changes from calc version 2.10.1t11 to 2.10.1t19: nature of math_error(). Unfortunately some due to some systems not dealing with /*NOTREACHED*/ comments correctly, calls of the form: - if (foo) - math_error("bar"); + if (foo) + math_error("bar"); must be turned into: - if (foo) { - math_error("bar"); - /*NOTREACHED*/ - } + if (foo) { + math_error("bar"); + /*NOTREACHED*/ + } The ploy() function can take a list of coefficients. See the help/poly file. Added poly.c. + See help/error for details. - Added singular forms of help files. For example one can now get + Added singular forms of help files. For example one can now get help for binding, bug, change, errorcode and type. The builtin mmin(x, md) has been changed to return the same as @@ -8586,7 +8593,7 @@ The following are the changes from calc version 2.10.1t11 to 2.10.1t19: The builtin avg(x_1, x_2, ...) has been changed to accept list-valued - arguments: a list x_i contributes its elements to the list of + arguments: a list x_i contributes its elements to the list of items to be averaged. E.g. avg(list(1,2,list(3,4)),5) is treated as if it were avg(1,2,3,4,5). If an error value is encountered in the items to be averaged, the first such value is returned. If the @@ -8607,7 +8614,7 @@ The following are the changes from calc version 2.10.1t11 to 2.10.1t19: Calc used to accept with no warning or error message, gcdrem(0,2) or generally gcdrem(0,y) for any y with abs(y) > 1, but then went into an infinite loop. This has been fixed by never calling zfacrem() with zero x. - Both frem(x,y) and gcdrem(x,y) now reject y = -1, 0 or 1 as errors. For + Both frem(x,y) and gcdrem(x,y) now reject y = -1, 0 or 1 as errors. For nonzero x, and y == -1 or 1, defining frem(x,y) and gcdrem(x,y) to equal abs(x) is almost as natural as defining x^0 to be 1. Similarly, if x is not zero then gcdrem(x,0) == 1. @@ -8651,7 +8658,7 @@ The following are the changes from calc version 2.10.0t13 to 2.10.1t10: and if HAVE_LONGLONG, in longbits.h if it is needed. The only place were a long long constant might be used is in longlong.c. Any long long constants, if HAVE_LONGLONG, are hidden under the U(x) and - L(x) macros on longbits.h. And of course, if you don't have long long, + L(x) macros on longbits.h. And of course, if you don't have long long, then HAVE_LONGLONG will NOT be defined and long long's will not be used. The longlong.h file is no longer directly used by the main calc source. @@ -8676,12 +8683,12 @@ The following are the changes from calc version 2.10.0t13 to 2.10.1t10: bit 6 returns the non-principal root rather than the principal value. If commands are given on the command line, leading tabs are not - printed in output. Giving a command on the command line implies + printed in output. Giving a command on the command line implies that config("tab",0) was given. Pipe processing is enabled by use of -p. For example: - echo "print 2^21701-1, 2^23209-1" | calc -p | fizzbin + echo "print 2^21701-1, 2^23209-1" | calc -p | fizzbin In pipe mode, calc does not prompt, does not print leading tabs and does not print the initial version header. @@ -8690,28 +8697,28 @@ The following are the changes from calc version 2.10.0t13 to 2.10.1t10: and < MAXFILES. Calc assumes they are available for reading and writing. For example: - $ echo "A line of text in the file on descriptor 5" > datafile - $ calc 5 datafile + $ calc 5b.file + calc -m 0 3b.file - NOTE: Files presented to calc in this way are opened in an unknown - mode. Calc will try to read or write them if directed. + NOTE: Files presented to calc in this way are opened in an unknown + mode. Calc will try to read or write them if directed. The maximum command line size it MAXCMD (16384) bytes. Calc objects to command lines that are longer. @@ -8755,24 +8762,24 @@ The following are the changes from calc version 2.9.3t11 to 2.10.0t12: The Makefile CC flag system has been changed. The new CC flag system includes: - CCMAIN are flags for ${CC} when compiling only files with main() - CCOPT are flags given to ${CC} for optimization - CCWARN are flags given to ${CC} for warning message control - CCMISC are misc flags given to ${CC} + CCMAIN are flags for ${CC} when compiling only files with main() + CCOPT are flags given to ${CC} for optimization + CCWARN are flags given to ${CC} for warning message control + CCMISC are misc flags given to ${CC} - CNOWARN are all flags given to ${CC} except ${CCWARN} flags - CFLAGS are all flags given to ${CC} - ICFLAGS are given to ${CC} for intermediate progs + CNOWARN are all flags given to ${CC} except ${CCWARN} flags + CFLAGS are all flags given to ${CC} + ICFLAGS are given to ${CC} for intermediate progs - LCFLAGS are CC-style flags for ${LINT} - LDFLAGS are flags given to ${CC} for linking .o files - ILDFLAGS are given to ${CC} for linking .o's for intermediate progs + LCFLAGS are CC-style flags for ${LINT} + LDFLAGS are flags given to ${CC} for linking .o files + ILDFLAGS are given to ${CC} for linking .o's for intermediate progs - CC is how the C compiler is invoked + CC is how the C compiler is invoked The syntax error: - print a[3][[4]] + print a[3][[4]] used to send calc into a loop printing 'missing expression'. This has been fixed. @@ -8784,11 +8791,11 @@ The following are the changes from calc version 2.9.3t11 to 2.10.0t12: stderr is re-directed to a non-file by some test suite. Changed how , or simulate stdarg is determined. - Changed how vsprintf() vs sprintf() is determined. The args.h file + Changed how vsprintf() vs sprintf() is determined. The args.h file is created by Makefile to test which combination works. Setting VARARG and/or HAVE_VSPRINTF in the Makefile will alter these tests and direct a specific combination to be used. Removed have_vs.c, - std_arg.h and try_stdarg.c. Added have_stdvs.c and have_varvs.c. + std_arg.h and try_stdarg.c. Added have_stdvs.c and have_varvs.c. Added 3rd optional arg to round(), bround(), appr() to specify the type of rounding to be used. @@ -8832,17 +8839,17 @@ The following are the changes from calc version 2.9.3t9.2+ to 2.9.3t10: Fixed bug that caused: - global a,b,c (newline with no semicolon) - read test.cal + global a,b,c (newline with no semicolon) + read test.cal the read command to not be recognized. The show command looks at only the first 4 chars of the argument so that: - show globals - show global - show glob + show globals + show global + show glob do the same thing. @@ -8900,12 +8907,12 @@ The following are the changes from calc version 2.9.3t9.2+ to 2.9.3t10: of the function. Some source tools got confused when: arg order did not match as in: - void - funct(foo,bar) - int bar; /* this caused a problem */ - char *foo; /* even though it should not! */ - { - } + void + funct(foo,bar) + int bar; /* this caused a problem */ + char *foo; /* even though it should not! */ + { + } The following are the changes from calc version 2.9.3t8 to 2.9.3t9.2: @@ -8937,14 +8944,14 @@ The following are the changes from calc version 2.9.3t8 to 2.9.3t9.2: The second ptest() argument, which is now optional, defaults to 1. This ptest(x) is the same as ptest(x,1). - Added an optional 3rd argument to ptest(). The 3rd arg tells how many + Added an optional 3rd argument to ptest(). The 3rd arg tells how many tests to skip. Thus ptest(a,10) performs the same probabilistic tests as ptest(a,3) and ptest(a,7,3). The ptest() builtin by default will determine if a value is divisible - by a trivial prime. Thus, ptest(a,0) will only perform a quick trivial + by a trivial prime. Thus, ptest(a,0) will only perform a quick trivial factor check. If the test count is < 0, then this trivial factor check - is omitted. Thus ptest(a,10) performs the same amount of work as + is omitted. Thus ptest(a,10) performs the same amount of work as ptest(a,3) and ptest(a,-7,3) and the same amount of work as ptest(a,-3) and ptest(a,7,3). @@ -8955,7 +8962,7 @@ The following are the changes from calc version 2.9.3t8 to 2.9.3t9.2: Added nextprime(x) and and prevprime(x) return the next and previous primes with respect to x respectively. As of this - release, x must be < 2^32. With one argument, they will return + release, x must be < 2^32. With one argument, they will return an error if x is out of range. With two arguments, they will not generate an error but instead will return y. @@ -8987,17 +8994,17 @@ The following are the changes from calc version 2.9.3t8 to 2.9.3t9.2: instead will return y. Added pix(x) to return the number of primes <= x. As of this - release, x must be < 2^32. With one argument, pix(x) will + release, x must be < 2^32. With one argument, pix(x) will return an error if x is out of range. With two arguments, pix(x,y) will not generate an error but instead will return y. - Fixed the way *.h files are formed. Each file guards against + Fixed the way *.h files are formed. Each file guards against multiple inclusion. Fixed numeric I/O on 64 bit systems. Previously the print and constant conversion routines assumed a base of 2^16. - Added support for 'long long' type. If the Makefile is setup + Added support for 'long long' type. If the Makefile is setup with 'LONGLONG_BITS=', then it will attempt to detect support for the 'long long' type. If the Makefile is setup with 'LONGLONG_BITS=64', then a 64 bit 'long long' is assumed. @@ -9013,7 +9020,7 @@ The following are the changes from calc version 2.9.3t8 to 2.9.3t9.2: Fixed btrunc() limit. The ord("string") function can now take a string of multiple - characters. However it still will only operate on the first + characters. However it still will only operate on the first character. Renamed stdarg.h to std_arg.h and endian.h endian_calc.h to @@ -9023,15 +9030,15 @@ The following are the changes from calc version 2.9.3t8 to 2.9.3t9.2: Added additive 55 shuffle generator functions rand(), randbits() and its seed function srand(). Calling rand(a,b) produces a random value over the open half interval [a,b). With one arg, - rand(a) is equivalent to rand(0,a). Calling rand() produces + rand(a) is equivalent to rand(0,a). Calling rand() produces 64 random bits and is equivalent to rand(0,2^64). Calling randbit(x>0) produces x random bits. Calling randbit(skip<0) skips -skip bits and returns -skip. - The srand() function will return the current state. The call - srand(0) returns the initial state. Calling srand(x), where - x > 0 will seed the generator to a different state. Calling + The srand() function will return the current state. The call + srand(0) returns the initial state. Calling srand(x), where + x > 0 will seed the generator to a different state. Calling srand(mat55) (mat55 is a matrix of integers at least 55 elements long) will seed the internal table with the matrix elements mod 2^64. Finally calling srand(state) where state is a generator state @@ -9058,33 +9065,33 @@ The following are the changes from calc version 2.9.3t8 to 2.9.3t9.2: When a file file is printed, the file number is also printed: - FILE 3 "/etc/motd" (reading, pos 127) + FILE 3 "/etc/motd" (reading, pos 127) Added matsum() to sum all numeric values in a matrix. The following code now works, thanks to a fix by (Ernest Bowen): - mat A[3] = {1, 2, 3}; - A[0] = A; - print A[0]; + mat A[3] = {1, 2, 3}; + A[0] = A; + print A[0]; Also thanks to ernie, calc can process compound expressions such as 1 ? 2 ? 3 : 4 : 5. Also^2 thanks to ernie, the = operator is more general: - (a = 3) = 4 (same as a = 3; a = 4) - (a += 3) *= 4 (same as a += 3; a *= 4) - matfill(B = A, 4) (same as B = A; matfill(B, 4);) + (a = 3) = 4 (same as a = 3; a = 4) + (a += 3) *= 4 (same as a += 3; a *= 4) + matfill(B = A, 4) (same as B = A; matfill(B, 4);) Also^3 thanks to ernie, the ++ and -- operators are more general. - a = 3 - ++(b = a) (a == 3, b == 4) - ++++a (a == 5) - (++a)++ == 6 (a == 7) - (++a) *= b (a == 32, b == 4) + a = 3 + ++(b = a) (a == 3, b == 4) + ++++a (a == 5) + (++a)++ == 6 (a == 7) + (++a) *= b (a == 32, b == 4) Fixed a bug related to calling epsilon(variable) thanks to ernie. @@ -9092,7 +9099,7 @@ The following are the changes from calc version 2.9.3t8 to 2.9.3t9.2: Some compilers do not support the const type. The file have_const.h, which is built from have_const.c will determine if we can or should - use const. See the Makefile for details. + use const. See the Makefile for details. Some systems do not have uid_t. The file have_uid_t.h, which is built from have_uid_t.c will determine if we can or should @@ -9102,11 +9109,11 @@ The following are the changes from calc version 2.9.3t8 to 2.9.3t9.2: Some systems do not have memcpy(), memset() and strchr(). The file have_newstr.h, which is built from have_newstr.c will determine if we can or should depend libc providing these - functions. See the Makefile for details. + functions. See the Makefile for details. The Makefile symbol DONT_HAVE_VSPRINTF is now called HAVE_VSPRINTF. The file have_vs.h, which is built from have_vs.c will determine if - we can or should depend libc providing vsprintf(). See the Makefile + we can or should depend libc providing vsprintf(). See the Makefile for details. Removed UID_T and OLD_BSD symbols from the Makefile. @@ -9134,7 +9141,7 @@ The following are the changes from calc version 2.9.3t7 to 2.9.3t7: message and command prompt if stdin is not a tty. Thus the shell command: - echo "fact(100)" | calc + echo "fact(100)" | calc only prints the result. (thanks to Ha S. Lam ) @@ -9151,7 +9158,7 @@ The following are the changes from calc version 2.9.3t7 to 2.9.3t7: digit, ), matrix operations (size, index, creation), scaling, shifting, rounding and computing a Fibonacci number is 2^31. For example, one cannot raise a number by a power >= 2^31. - One cannot test for a bit position >= 2^31. One cannot round + One cannot test for a bit position >= 2^31. One cannot round a value to 2^31 decimal digit places. One cannot compute the Fibonacci number F(2^31). @@ -9171,7 +9178,7 @@ 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. A number of systems that have both and do - not correctly implement both types. On some System V, MIPS and DEC + not correctly implement both types. On some System V, MIPS and DEC systems, vsprintf() and do not mix. While calc will pass the regression test, use of undefined variables will cause problems. The Makefile has been modified to look for this problem @@ -9184,20 +9191,20 @@ The following are the changes from calc version 2.9.2 to 2.9.3t7: The library script nextprim.cal is now a link to nextprime.cal. The lib/Makefile will take care of this link and install. - The show command now takes singular forms. For example, the + The show command now takes singular forms. For example, the command 'show builtin' does the same as 'show builtins'. This allows show to match the historic singular names used in the help system. Synced 'show builtin' output with 'help builtin' output. - Fixed the ilog2() builtin. Previously ilog2(2^-20) returned + Fixed the ilog2() builtin. Previously ilog2(2^-20) returned -21 instead of -20. - The internal function qprecision() has been fixed. The changes + The internal function qprecision() has been fixed. The changes ensure that for any e for which 0 < e <= 1: - 1/4 < sup(abs(appr(x,e) - x))/e <= 1/2. + 1/4 < sup(abs(appr(x,e) - x))/e <= 1/2. Here 'sup' denotes the least upper bound over values of x (supremum). Previously calc did: 1/4 <= sup(abs(appr(x,e) - x))/e < 1. @@ -9206,7 +9213,7 @@ The following are the changes from calc version 2.9.2 to 2.9.3t7: Added -once to the READ command. The command: - read -once filename + read -once filename like the regular READ expect that it will ignore filename if is has been previously read. @@ -9235,7 +9242,7 @@ The following are the changes from calc version 2.9.2 to 2.9.3t7: work-a-rounds involved initializing or making static, certain local variables. - The cryrand.cal library has been improved. Due to the way + The cryrand.cal library has been improved. Due to the way the initial quadratic residues are selected, the random numbers produced differ from previous versions. @@ -9254,7 +9261,7 @@ The following are the changes from calc version 2.9.2 to 2.9.3t7: The value atan2(0,0) now returns 0 value in conformance with the 4.3BSD ANSI/IEEE 754-1985 math library. - For all values of x, x^0 yields 1. The major change here is + For all values of x, x^0 yields 1. The major change here is that 0^0 yields 1 instead of an error. Fixed gcd() bug that caused gcd(2,3,1/2) to ignore the 1/2 arg. @@ -9284,7 +9291,7 @@ The following are the changes from calc version 2.9.2 to 2.9.3t7: The regression test code is now more extensive. - 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! @@ -9349,7 +9356,7 @@ The following are the changes from calc version 1.27.0 to 2.8.0: statement, to immediately define a variable as an object. Object definitions can be repeated as long as they are exactly the same - as the previous definition. This allows the rereading of files which + as the previous definition. This allows the rereading of files which happen to define objects. The integer, rational, and complex routines have been made into a @@ -9381,15 +9388,15 @@ Following is a list of visible changes to calc from version 1.24.7 to 1.26.1: There is a new emacs-like command line editing and edit history feature. The old history mechanism has been removed. The key bindings for the new editing commands are slightly configurable - since they are read in from an initialization file. This file is + since they are read in from an initialization file. This file is usually called /usr/lib/calc/bindings, but can be changed by the - CALCBINDINGS environment variable. All editing code is + CALCBINDINGS environment variable. All editing code is self-contained in the new files hist.c and hist.h, which can be easily extracted and used in other programs. Two new library files have been added: chrem.cal and cryrand.cal. The first of these solves the Chinese remainder problem for a set - of modulo's and remainders. The second of these implements several + of modulo's and remainders. The second of these implements several very good random number generators for large numbers. A small bug which allowed division by zero was fixed. @@ -9411,7 +9418,7 @@ Following is a list of visible changes to calc from version 1.24.7 to 1.26.1: ## ## 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 +## 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 @@ -9419,8 +9426,8 @@ Following is a list of visible changes to calc from version 1.24.7 to 1.26.1: ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1993/06/02 18:12:57 -## File existed as early as: 1989 +## Under source code control: 1993/06/02 18:12:57 +## File existed as early as: 1989 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/CONTRIB-CODE b/CONTRIB-CODE index a36e8db..0572c9f 100644 --- a/CONTRIB-CODE +++ b/CONTRIB-CODE @@ -49,7 +49,7 @@ See also the calc wishlist by running the calc command: ## ## 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 +## 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 @@ -57,8 +57,8 @@ See also the calc wishlist by running the calc command: ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/03/09 16:33:22 -## File existed as early as: 1997 +## Under source code control: 1997/03/09 16:33:22 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/COPYING b/COPYING index 1b0944d..4842db7 100644 --- a/COPYING +++ b/COPYING @@ -1,4 +1,4 @@ - calc - arbitrary precision calculator + calc - arbitrary precision calculator This file is Copyrighted ------------------------ @@ -6,11 +6,11 @@ This file is Copyrighted This file is not covered under version 2.1 of the GNU LGPL. This file is covered under the following Copyright: - Copyright (C) 1999-2023 Landon Curt Noll - All rights reserved. + Copyright (C) 1999-2023 Landon Curt Noll + All rights reserved. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. -=- @@ -33,21 +33,21 @@ Calc is covered by the GNU Lesser General Public License A copy of the GNU Lesser General Public License is distributed with calc under the filename: - COPYING-LGPL + COPYING-LGPL - You may display this file by the calc command: help copying + You may display this file by the calc command: help copying You may display the GNU Lesser General - Public License by the calc command: help copying-lgpl + Public License by the calc command: help copying-lgpl You should have received a copy of the version 2.1 GNU Lesser General Public License with calc; if not, write to the following address: - Free Software Foundation, Inc. - 51 Franklin Street - Fifth Floor - Boston, MA 02110-1301 - USA + Free Software Foundation, Inc. + 51 Franklin Street + Fifth Floor + Boston, MA 02110-1301 + USA Calc's relationship to the GNU Lesser General Public License ------------------------------------------------------------ @@ -55,22 +55,22 @@ Calc's relationship to the GNU Lesser General Public License In section 0 of the GNU Lesser General Public License, one finds the following definition: - The "Library", below, refers to any such software library or - work which has been distributed under these terms. + The "Library", below, refers to any such software library or + work which has been distributed under these terms. Calc is distributed under the terms of the GNU Lesser General Public License. In the same section 0, one also find the following: - For a library, complete source code means all the source code - for all modules it contains, plus any associated interface - definition files, plus the scripts used to control compilation - and installation of the library. + For a library, complete source code means all the source code + for all modules it contains, plus any associated interface + definition files, plus the scripts used to control compilation + and installation of the library. There are at least two calc binary link libraries found in calc: - libcalc.a libcustcalc.a + libcalc.a libcustcalc.a Clearly all files that go into the creation of those binary link libraries are covered under the License. @@ -78,26 +78,26 @@ Calc's relationship to the GNU Lesser General Public License The "scripts used to control compilation and installation of the of the library" include: - * Makefiles - * source files created by the Makefiles - * source code used in the creation of intermediate source files + * Makefiles + * source files created by the Makefiles + * source code used in the creation of intermediate source files All of those files are covered under the License. The "associated interface definition files" are those files that: - * show how the calc binary link libraries are used - * test the validity of the binary link libraries - * document routines found in the binary link libraries - * show how one can interactively use the binary link libraries + * show how the calc binary link libraries are used + * test the validity of the binary link libraries + * document routines found in the binary link libraries + * show how one can interactively use the binary link libraries Calc provides an extensive set of files that perform the above functions. - * files under the sample sub-directory - * files under the help sub-directory - * files under the lib sub-directory - * the main calc.c file + * files under the sample sub-directory + * files under the help sub-directory + * files under the lib sub-directory + * the main calc.c file The "complete source code" includes ALL files shipped with calc, except for the exception files explicitly listed in the "Calc @@ -111,22 +111,22 @@ Calc copyrights and exception files With the exception of the files listed below, Calc is covered under the following GNU Lesser General Public License Copyrights: - Copyright (C) year David I. Bell - Copyright (C) year David I. Bell and Landon Curt Noll - Copyright (C) year David I. Bell and Ernest Bowen - Copyright (C) year David I. Bell, Landon Curt Noll and Ernest Bowen - Copyright (C) year Landon Curt Noll - Copyright (C) year Ernest Bowen and Landon Curt Noll - Copyright (C) year Ernest Bowen - Copyright (C) year Petteri Kettunen and Landon Curt Noll - Copyright (C) year Christoph Zurnieden - Copyright (C) year Landon Curt Noll and Thomas Jones-Low - Copyright (C) year Klaus Alexander Seistrup and Landon Curt Noll + Copyright (C) year David I. Bell + Copyright (C) year David I. Bell and Landon Curt Noll + Copyright (C) year David I. Bell and Ernest Bowen + Copyright (C) year David I. Bell, Landon Curt Noll and Ernest Bowen + Copyright (C) year Landon Curt Noll + Copyright (C) year Ernest Bowen and Landon Curt Noll + Copyright (C) year Ernest Bowen + Copyright (C) year Petteri Kettunen and Landon Curt Noll + Copyright (C) year Christoph Zurnieden + Copyright (C) year Landon Curt Noll and Thomas Jones-Low + Copyright (C) year Klaus Alexander Seistrup and Landon Curt Noll These files are not covered under one of the Copyrights listed above: - sha1.c sha1.h COPYING - COPYING-LGPL cal/screen.cal + sha1.c sha1.h COPYING + COPYING-LGPL cal/screen.cal The file COPYING-LGPL, which contains a copy of the version 2.1 GNU Lesser General Public License, is itself Copyrighted by the @@ -140,37 +140,37 @@ Calc copyrights and exception files These files are covered under "The Unlicense": - sha1.c - sha1.h - cal/dotest.cal - cal/screen.cal + sha1.c + sha1.h + cal/dotest.cal + cal/screen.cal "The Unlicense" is as follows: - This is free and unencumbered software released into the public domain. + This is free and unencumbered software released into the public domain. - Anyone is free to copy, modify, publish, use, compile, sell, or - distribute this software, either in source code form or as a compiled - binary, for any purpose, commercial or non-commercial, and by any - means. + Anyone is free to copy, modify, publish, use, compile, sell, or + distribute this software, either in source code form or as a compiled + binary, for any purpose, commercial or non-commercial, and by any + means. - In jurisdictions that recognize copyright laws, the author or authors - of this software dedicate any and all copyright interest in the - software to the public domain. We make this dedication for the benefit - of the public at large and to the detriment of our heirs and - successors. We intend this dedication to be an overt act of - relinquishment in perpetuity of all present and future rights to this - software under copyright law. + In jurisdictions that recognize copyright laws, the author or authors + of this software dedicate any and all copyright interest in the + software to the public domain. We make this dedication for the benefit + of the public at large and to the detriment of our heirs and + successors. We intend this dedication to be an overt act of + relinquishment in perpetuity of all present and future rights to this + software under copyright law. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR - OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - OTHER DEALINGS IN THE SOFTWARE. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. - For more information, please refer to + For more information, please refer to In all cases one may use and distribute these exception files freely. And because one may freely distribute the LGPL covered files, the @@ -183,12 +183,12 @@ General Copyleft and License info For general information on Copylefts, see: - http://www.gnu.org/copyleft/ + http://www.gnu.org/copyleft/ For information on GNU Lesser General Public Licenses, see: - http://www.gnu.org/copyleft/lesser.html - http://www.gnu.org/copyleft/lesser.txt + http://www.gnu.org/copyleft/lesser.html + http://www.gnu.org/copyleft/lesser.txt -=- @@ -198,10 +198,10 @@ Why calc did not use the GNU General Public License It has been suggested that one should consider using the GNU General Public License instead of the GNU Lesser General Public License: - http://www.gnu.org/philosophy/why-not-lgpl.html + http://www.gnu.org/philosophy/why-not-lgpl.html As you can read in the above URL, there are times where a library - cannot give free software any particular advantage. One of those + cannot give free software any particular advantage. One of those times is when there is significantly similar versions available that are not covered under a Copyleft such as the GNU General Public License. diff --git a/HOWTO.INSTALL b/HOWTO.INSTALL index 475e2bf..c7c4bd4 100644 --- a/HOWTO.INSTALL +++ b/HOWTO.INSTALL @@ -10,7 +10,7 @@ Open up the 'Assets' tag below a given release and download these RPMs: * calc*.rpm - - all that is needed if you just want to use calc + - all that is needed if you just want to use calc If your platform supports rpm and matches one of the "calc*.rpm" files, you may just install that "calc*.rpm". For exammple on an x86_64 system: @@ -25,7 +25,7 @@ files for use in other programs: * calc-devel-*.rpm - - calc *.h header and *.a lib files for use in other programs + - calc *.h header and *.a lib files for use in other programs Alternately to the above github link, you might try looking at the RPMs under: @@ -209,10 +209,10 @@ the standard Microsoft Windows developor environment to compile calc. You should determine if these Makefile variables are reasonable: - INCDIR Where the system include (.h) files are kept. - BINDIR Where to install calc binary files. - LIBDIR Where to install calc link library (*.a) files. - CALC_SHAREDIR Where to install calc help, .cal, startup, and config files. + INCDIR Where the system include (.h) files are kept. + BINDIR Where to install calc binary files. + LIBDIR Where to install calc link library (*.a) files. + CALC_SHAREDIR Where to install calc help, .cal, startup, and config files. You may want to change the default installation locations for these values, which are based on the 4 values listed above: @@ -227,25 +227,25 @@ these values, which are based on the 4 values listed above: If you want to install calc files under a top level directory, then set the T value: The calc install is performed under ${T}, the calc build is - performed under /. The purpose for ${T} is to allow someone + performed under /. The purpose for ${T} is to allow someone to install calc somewhere other than into the system area. For example, if: - BINDIR= /usr/bin - LIBDIR= /usr/lib - CALC_SHAREDIR= /usr/share/calc + BINDIR= /usr/bin + LIBDIR= /usr/lib + CALC_SHAREDIR= /usr/share/calc and if: - T= /var/tmp/testing + T= /var/tmp/testing Then the installation locations will be: - calc binary files: /var/tmp/testing/usr/bin - calc link library: /var/tmp/testing/usr/lib - calc help, .cal ...: /var/tmp/testing/usr/share/calc - ... etc ... /var/tmp/testing/... + calc binary files: /var/tmp/testing/usr/bin + calc link library: /var/tmp/testing/usr/lib + calc help, .cal ...: /var/tmp/testing/usr/share/calc + ... etc ... /var/tmp/testing/... If ${T} is empty, calc is installed under /, which is the same top of tree for which it was built. If ${T} is non-empty, then @@ -341,7 +341,7 @@ before you install: Calc is distributed with an extensive collection of help files that are accessible from the command line. The following assume that you are running calc from the distribution directory or that you have -installed calc. In these examples, the "; " is the calc prompt, not +installed calc. In these examples, the "; " is the calc prompt, not something that you type. For list of help topics: @@ -392,7 +392,7 @@ a numner of important make rules and thus fail to properly compile calc. ## ## 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 +## 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 @@ -400,8 +400,8 @@ a numner of important make rules and thus fail to properly compile calc. ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1999/09/27 20:48:44 -## File existed as early as: 1999 +## Under source code control: 1999/09/27 20:48:44 +## File existed as early as: 1999 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/LIBRARY b/LIBRARY index 70b42ea..d41fa9a 100644 --- a/LIBRARY +++ b/LIBRARY @@ -19,9 +19,9 @@ FIRST THINGS FIRST ------------------ ............................................................................... -. . +. . . You MUST call libcalc_call_me_first() prior to using libcalc lib functions! . -. . +. . ............................................................................... The function libcalc_call_me_first() takes no args and returns void. You @@ -34,16 +34,16 @@ INCLUDE FILES To use any of these routines in your own programs, you need to include the appropriate include file. These include files are: - zmath.h (for integer arithmetic) - qmath.h (for rational arithmetic) - cmath.h (for complex number arithmetic) + zmath.h (for integer arithmetic) + qmath.h (for rational arithmetic) + cmath.h (for complex number arithmetic) You never need to include more than one of the above files, even if you wish to use more than one type of arithmetic, since qmath.h automatically includes zmath.h, and cmath.h automatically includes qmath.h. The prototypes for the available routines are listed in the above include -files. Some of these routines are meant for internal use, and so aren't +files. Some of these routines are meant for internal use, and so aren't convenient for outside use. So you should read the source for a routine to see if it really does what you think it does. I won't guarantee that obscure internal routines won't change or disappear in future releases! @@ -61,20 +61,20 @@ to define CALC_SRC. You need to include the following file to get the symbols and variables related to error handling: - lib_calc.h + lib_calc.h External programs may want to compile with: - -I${INCDIR} -L${LIBDIR} -lcalc + -I${INCDIR} -L${LIBDIR} -lcalc If custom functions are also used, they may want to compile with: - -I${INCDIR} -L${LIBDIR} -lcalc -lcustcalc + -I${INCDIR} -L${LIBDIR} -lcalc -lcustcalc The CALC_SRC symbol should NOT be defined by default. However if you are feeling pedantic you may want to force CALC_SRC to be undefined: - -UCALC_SRC + -UCALC_SRC as well. @@ -87,64 +87,64 @@ condition, such as malloc failures, division by zero, or some form of an internal computation error. The routine is called in the manner of printf, with a format string and optional arguments: - void math_error(char *fmt, ...); + void math_error(char *fmt, ...); Your program must handle math errors in one of three ways: 1) Print the error message and then exit - There is a math_error() function supplied with the calc library. - By default, this routine simply prints a message to stderr and - then exits. By simply linking in this link library, any calc - errors will result in a error message on stderr followed by - an exit. + There is a math_error() function supplied with the calc library. + By default, this routine simply prints a message to stderr and + then exits. By simply linking in this link library, any calc + errors will result in a error message on stderr followed by + an exit. 2) Use setjmp and longjmp in your program - Use setjmp at some appropriate level in your program, and let - the longjmp in math_error() return to that level and to allow you - to recover from the error. This is what the calc program does. + Use setjmp at some appropriate level in your program, and let + the longjmp in math_error() return to that level and to allow you + to recover from the error. This is what the calc program does. - If one sets up calc_matherr_jmpbuf, and then sets - calc_use_matherr_jmpbuf to non-zero then math_error() will - longjmp back with the return value of calc_use_matherr_jmpbuf. - In addition, the last calc error message will be found in - calc_err_msg; this error is not printed to stderr. The calc - error message will not have a trailing newline. + If one sets up calc_matherr_jmpbuf, and then sets + calc_use_matherr_jmpbuf to non-zero then math_error() will + longjmp back with the return value of calc_use_matherr_jmpbuf. + In addition, the last calc error message will be found in + calc_err_msg; this error is not printed to stderr. The calc + error message will not have a trailing newline. - For example: + For example: - #include - #include "lib_calc.h" + #include + #include "lib_calc.h" - int error; + int error; - ... + ... - if ((error = setjmp(calc_matherr_jmpbuf)) != 0) { + if ((error = setjmp(calc_matherr_jmpbuf)) != 0) { - /* report the error */ - printf("Ouch: %s\n", calc_err_msg); + /* report the error */ + printf("Ouch: %s\n", calc_err_msg); - /* reinitialize calc after the longjmp */ - reinitialize(); - } - calc_use_matherr_jmpbuf = 1; + /* reinitialize calc after the longjmp */ + reinitialize(); + } + calc_use_matherr_jmpbuf = 1; - If calc_use_matherr_jmpbuf is non-zero, then the jmp_buf value - calc_matherr_jmpbuf must be initialized by the setjmp() function - or your program will crash. + If calc_use_matherr_jmpbuf is non-zero, then the jmp_buf value + calc_matherr_jmpbuf must be initialized by the setjmp() function + or your program will crash. 3) Supply your own math_error function: - void math_error(char *fmt, ...); + void math_error(char *fmt, ...); - Your math_error() function may exit or transfer control to outside - of the calc library, but it must never return or calc will crash. + Your math_error() function may exit or transfer control to outside + of the calc library, but it must never return or calc will crash. External programs can obtain the appropriate calc symbols by compiling with: - -I${INCDIR} -L${LIBDIR} -lcalc + -I${INCDIR} -L${LIBDIR} -lcalc ------------------------- PARSE/SCAN ERROR HANDLING @@ -159,15 +159,15 @@ any parse/scan errors. By default, this variable it set to 1 and so parse/scan errors are printed to stderr. By setting this value to zero, parse/scan errors are not printed: - #include "lib_calc.h" + #include "lib_calc.h" - /* do not print parse/scan errors to stderr */ - calc_print_scanerr_msg = 0; + /* do not print parse/scan errors to stderr */ + calc_print_scanerr_msg = 0; The last calc math error or calc parse/scan error message is kept in the NUL terminated buffer: - char calc_err_msg[MAXERROR+1]; + char calc_err_msg[MAXERROR+1]; The value of calc_print_scanerr_msg does not change the use of the calc_err_msg[] buffer. Messages are stored in that @@ -182,54 +182,54 @@ Your program must handle parse/scan errors in one of two ways: 1) exit on error - If you do not setup the calc_scanerr_jmpbuf, then when calc - encounters a parse/scan error, a message will be printed to - stderr and calc will exit. + If you do not setup the calc_scanerr_jmpbuf, then when calc + encounters a parse/scan error, a message will be printed to + stderr and calc will exit. 2) Use setjmp and longjmp in your program - Use setjmp at some appropriate level in your program, and let - the longjmp in scanerror() return to that level and to allow you - to recover from the error. This is what the calc program does. + Use setjmp at some appropriate level in your program, and let + the longjmp in scanerror() return to that level and to allow you + to recover from the error. This is what the calc program does. - If one sets up calc_scanerr_jmpbuf, and then sets - calc_use_scanerr_jmpbuf to non-zero then scanerror() will longjmp - back with the return with a non-zero code. In addition, the last - calc error message will be found in calc_err_msg[]; this error is - not printed to stderr. The calc error message will not have a - trailing newline. + If one sets up calc_scanerr_jmpbuf, and then sets + calc_use_scanerr_jmpbuf to non-zero then scanerror() will longjmp + back with the return with a non-zero code. In addition, the last + calc error message will be found in calc_err_msg[]; this error is + not printed to stderr. The calc error message will not have a + trailing newline. - For example: + For example: - #include - #include "lib_calc.h" + #include + #include "lib_calc.h" - int scan_error; + int scan_error; - ... + ... - /* delay the printing of the parse/scan error */ - calc_use_scanerr_jmpbuf = 0; /* this is optional */ + /* delay the printing of the parse/scan error */ + calc_use_scanerr_jmpbuf = 0; /* this is optional */ - if ((scan_error = setjmp(calc_scanerr_jmpbuf)) != 0) { + if ((scan_error = setjmp(calc_scanerr_jmpbuf)) != 0) { - /* report the parse/scan */ - if (calc_use_scanerr_jmpbuf == 0) { - printf("parse error: %s\n", calc_err_msg); - } + /* report the parse/scan */ + if (calc_use_scanerr_jmpbuf == 0) { + printf("parse error: %s\n", calc_err_msg); + } - /* initialize calc after the longjmp */ - initialize(); - } - calc_use_scanerr_jmpbuf = 1; + /* initialize calc after the longjmp */ + initialize(); + } + calc_use_scanerr_jmpbuf = 1; - If calc_use_scanerr_jmpbuf is non-zero, then the jmp_buf value - calc_scanerr_jmpbuf must be initialized by the setjmp() function - or your program will crash. + If calc_use_scanerr_jmpbuf is non-zero, then the jmp_buf value + calc_scanerr_jmpbuf must be initialized by the setjmp() function + or your program will crash. External programs can obtain the appropriate calc symbols by compiling with: - -I${INCDIR} -L${LIBDIR} -lcalc + -I${INCDIR} -L${LIBDIR} -lcalc --------------------------- PARSE/SCAN WARNING HANDLING @@ -239,22 +239,22 @@ Calc parse/scan warning message are printed to stderr by the warning() function. The routine is called in the manner of printf, with a format string and optional arguments: - void warning(char *fmt, ...); + void warning(char *fmt, ...); The variable, calc_print_scanwarn_msg, controls if calc prints to stderr, any parse/scan warnings. By default, this variable it set to 1 and so parse/scan warnings are printed to stderr. By setting this value to zero, parse/scan warnings are not printed: - #include "lib_calc.h" + #include "lib_calc.h" - /* do not print parse/scan warnings to stderr */ - calc_print_scanwarn_msg = 0; + /* do not print parse/scan warnings to stderr */ + calc_print_scanwarn_msg = 0; The last calc calc parse/scan warning message is kept in the NUL terminated buffer: - char calc_warn_msg[MAXERROR+1]; + char calc_warn_msg[MAXERROR+1]; The value of calc_print_scanwarn_msg does not change the use of the calc_warn_msg[] buffer. Messages are stored in that @@ -264,19 +264,19 @@ Your program must handle parse/scan warnings in one of two ways: 1) print the warning to stderr and continue - The warning() from libcalc prints warning messages to - stderr and returns. The flow of execution is not changed. - This is what calc does by default. + The warning() from libcalc prints warning messages to + stderr and returns. The flow of execution is not changed. + This is what calc does by default. 2) Supply your own warning function: - void warning(char *fmt, ...); + void warning(char *fmt, ...); - Your warning function should simply return when it is finished. + Your warning function should simply return when it is finished. External programs can obtain the appropriate calc symbols by compiling with: - -I${INCDIR} -L${LIBDIR} -lcalc + -I${INCDIR} -L${LIBDIR} -lcalc --------------- @@ -308,7 +308,7 @@ output strings with space filling, output formatted strings like printf, and flush the output. Output from these routines is diverted as described above. You can change the default output mode by calling math_setmode, and you can -change the default number of digits printed by calling math_setdigits. These +change the default number of digits printed by calling math_setdigits. These routines return the previous values. The possible modes are described in zmath.h. @@ -320,7 +320,7 @@ The arbitrary precision integer routines define a structure called a ZVALUE. This is defined in zmath.h. A ZVALUE contains a pointer to an array of integers, the length of the array, and a sign flag. The array is allocated using malloc, so you need to free this array when you are done with a -ZVALUE. To do this, you should call zfree() with the ZVALUE as an argument +ZVALUE. To do this, you should call zfree() with the ZVALUE as an argument and never try to free the array yourself using free(). The reason for this is that sometimes the pointer points to a statically allocated arrays which should NOT be freed. @@ -329,11 +329,11 @@ The ZVALUE structures are passed to routines by value, and are returned through pointers. For example, to multiply two small integers together, you could do the following: - ZVALUE z1, z2, z3; + ZVALUE z1, z2, z3; - itoz(3L, &z1); - itoz(4L, &z2); - zmul(z1, z2, &z3); + itoz(3L, &z1); + itoz(4L, &z2); + zmul(z1, z2, &z3); Use zcopy to copy one ZVALUE to another. There is no sharing of arrays between different ZVALUEs even if they have the same value, so you MUST @@ -354,67 +354,67 @@ address to a routine as a destination value, otherwise memory will be lost. The following shows an example of the correct way to free memory over a long sequence of operations. - ZVALUE z1, z2, z3; + ZVALUE z1, z2, z3; - z1 = _one_; - str2z("12345678987654321", &z2); - zadd(z1, z2, &z3); - zfree(z1); - zfree(z2); - zsquare(z3, &z1); - zfree(z3); - itoz(17L, &z2); - zsub(z1, z2, &z3); - zfree(z1); - zfree(z2); - zfree(z3); + z1 = _one_; + str2z("12345678987654321", &z2); + zadd(z1, z2, &z3); + zfree(z1); + zfree(z2); + zsquare(z3, &z1); + zfree(z3); + itoz(17L, &z2); + zsub(z1, z2, &z3); + zfree(z1); + zfree(z2); + zfree(z3); There are some quick checks you can make on integers. For example, whether or not they are zero, negative, even, and so on. These are all macros defined in zmath.h, and should be used instead of checking the parts of the ZVALUE yourself. Examples of such checks are: - ziseven(z) (number is even) - zisodd(z) (number is odd) - ziszero(z) (number is zero) - zisneg(z) (number is negative) - zispos(z) (number is positive) - zisunit(z) (number is 1 or -1) - zisone(z) (number is 1) - zisnegone(z) (number is -1) - zistwo(z) (number is 2) - zisabstwo(z) (number is 2 or -2) - zisabsleone(z) (number is -1, 0 or 1) - zislezero(z) (number is <= 0) - zisleone(z) (number is <= 1) - zge16b(z) (number is >= 2^16) - zge24b(z) (number is >= 2^24) - zge31b(z) (number is >= 2^31) - zge32b(z) (number is >= 2^32) - zge64b(z) (number is >= 2^64) + ziseven(z) (number is even) + zisodd(z) (number is odd) + ziszero(z) (number is zero) + zisneg(z) (number is negative) + zispos(z) (number is positive) + zisunit(z) (number is 1 or -1) + zisone(z) (number is 1) + zisnegone(z) (number is -1) + zistwo(z) (number is 2) + zisabstwo(z) (number is 2 or -2) + zisabsleone(z) (number is -1, 0 or 1) + zislezero(z) (number is <= 0) + zisleone(z) (number is <= 1) + zge16b(z) (number is >= 2^16) + zge24b(z) (number is >= 2^24) + zge31b(z) (number is >= 2^31) + zge32b(z) (number is >= 2^32) + zge64b(z) (number is >= 2^64) Typically the largest unsigned long is typedefed to FULL. The following macros are useful in dealing with this data type: - MAXFULL (largest positive FULL value) - MAXUFULL (largest unsigned FULL value) - zgtmaxfull(z) (number is > MAXFULL) - zgtmaxufull(z) (number is > MAXUFULL) - zgtmaxlong(z) (number is > MAXLONG, largest long value) - zgtmaxulong(z) (number is > MAXULONG, largest unsigned long value) + MAXFULL (largest positive FULL value) + MAXUFULL (largest unsigned FULL value) + zgtmaxfull(z) (number is > MAXFULL) + zgtmaxufull(z) (number is > MAXUFULL) + zgtmaxlong(z) (number is > MAXLONG, largest long value) + zgtmaxulong(z) (number is > MAXULONG, largest unsigned long value) If zgtmaxufull(z) is false, then one may quickly convert the absolute value of number into a full with the macro: - ztofull(z) (convert abs(number) to FULL) - ztoulong(z) (convert abs(number) to an unsigned long) - ztolong(z) (convert abs(number) to a long) + ztofull(z) (convert abs(number) to FULL) + ztoulong(z) (convert abs(number) to an unsigned long) + ztolong(z) (convert abs(number) to a long) If the value is too large for ztofull(), ztoulong() or ztolong(), only the low order bits converted. There are two types of comparisons you can make on ZVALUEs. This is whether -or not they are equal, or the ordering on size of the numbers. The zcmp +or not they are equal, or the ordering on size of the numbers. The zcmp function tests whether two ZVALUEs are equal, returning true if they differ. The zrel function tests the relative sizes of two ZVALUEs, returning -1 if the first one is smaller, 0 if they are the same, and 1 if the first one @@ -422,11 +422,11 @@ is larger. To determine if z is an integer power of 2, use zispowerof2: - ZVALUE z; /* value to check if it is a power of */ - FULL log2; /* set to log base 2 of z when is_power_of_2 is true */ - bool is_power_of_2; + ZVALUE z; /* value to check if it is a power of */ + FULL log2; /* set to log base 2 of z when is_power_of_2 is true */ + bool is_power_of_2; - is_power_of_2 = zispowerof2(z, &log2) + is_power_of_2 = zispowerof2(z, &log2) Returns true if z an integer power of 2: set log2 to log base 2 of z. Returns false if z is NOT integer power of 2 and leave log2 untouched. @@ -445,35 +445,35 @@ is always positive. If the NUMBER is an integer, the denominator has the value 1. Unlike ZVALUEs, NUMBERs are passed using pointers, and pointers to them are -returned by functions. So the basic type for using fractions is not really +returned by functions. So the basic type for using fractions is not really (NUMBER), but is (NUMBER *). NUMBERs are allocated using the qalloc routine. This returns a pointer to a number which has the value 1. Because of the special property of a ZVALUE of 1, the numerator and denominator of this returned value can simply be overwritten with new ZVALUEs without needing to free them first. The following illustrates this: - NUMBER *q; + NUMBER *q; - q = qalloc(); - itoz(55L, &q->num); + q = qalloc(); + itoz(55L, &q->num); A better way to create NUMBERs with particular values is to use the itoq, iitoq, or str2q functions. Using itoq makes a long value into a NUMBER, using iitoq makes a pair of longs into the numerator and denominator of a NUMBER (reducing them first if needed), and str2q converts a string representing -a number into the corresponding NUMBER. The str2q function accepts input in +a number into the corresponding NUMBER. The str2q function accepts input in integral, fractional, real, or exponential formats. Examples of allocating numbers are: - NUMBER *q1, *q2, *q3, *q4; + NUMBER *q1, *q2, *q3, *q4; - q1 = itoq(66L); - q2 = iitoq(2L, 3L); - q3 = str2q("456.78"); - q4 = utoq((FULL) 1234567890L); + q1 = itoq(66L); + q2 = iitoq(2L, 3L); + q3 = str2q("456.78"); + q4 = utoq((FULL) 1234567890L); Also unlike ZVALUEs, NUMBERs are quickly copied. This is because they contain -a link count, which is the number of pointers there are to the NUMBER. The +a link count, which is the number of pointers there are to the NUMBER. The qlink macro is used to copy a pointer to a NUMBER, and simply increments the link count and returns the same pointer. Since it is a macro, the argument should not be a function call, but a real pointer variable. The @@ -486,16 +486,16 @@ the ZVALUEs contained within the NUMBER, and then puts the NUMBER structure onto a free list for quick reuse. The following is an example of allocating NUMBERs, copying them, adding them, and finally deleting them again. - NUMBER *q1, *q2, *q3, *q4; + NUMBER *q1, *q2, *q3, *q4; - q1 = itoq(111L); - q2 = qlink(q1); - q3 = qqadd(q1, q2); - q4 = qnum(q2, q3); + q1 = itoq(111L); + q2 = qlink(q1); + q3 = qqadd(q1, q2); + q4 = qnum(q2, q3); - qfree(q1); - qfree(q2); - qfree(q3); + qfree(q1); + qfree(q2); + qfree(q3); Because of the passing of pointers and the ability to copy numbers easily, you might wish to use the rational number routines even for integral @@ -513,55 +513,55 @@ There are some transcendental functions in the link library, such as sin and cos. These cannot be evaluated exactly as fractions. Therefore, they accept another argument which tells how accurate you want the result. This is an "epsilon" value, and the returned value will be within that -quantity of the correct value. This is usually an absolute difference, +quantity of the correct value. This is usually an absolute difference, but for some functions (such as exp), this is a relative difference. For example, to calculate sin(0.5) to 100 decimal places, you could do: - NUMBER *q, *ans, *epsilon; + NUMBER *q, *ans, *epsilon; - q = str2q("0.5"); - epsilon = str2q("1e-100"); - ans = qsin(q, epsilon); + q = str2q("0.5"); + epsilon = str2q("1e-100"); + ans = qsin(q, epsilon); There are many convenience macros similar to the ones for ZVALUEs which can give quick information about NUMBERs. In addition, there are some new ones applicable to fractions. These are all defined in qmath.h. Some of these macros are: - qiszero(q) (number is zero) - qisneg(q) (number is negative) - qispos(q) (number is positive) - qisint(q) (number is an integer) - qisfrac(q) (number is fractional) - qisunit(q) (number is 1 or -1) - qisone(q) (number is 1) - qisnegone(q) (number is -1) - qistwo(q) (number is 2) - qiseven(q) (number is an even integer) - qisodd(q) (number is an odd integer) - qisreciprocal(q) (number is 1 / an integer and q != 0) + qiszero(q) (number is zero) + qisneg(q) (number is negative) + qispos(q) (number is positive) + qisint(q) (number is an integer) + qisfrac(q) (number is fractional) + qisunit(q) (number is 1 or -1) + qisone(q) (number is 1) + qisnegone(q) (number is -1) + qistwo(q) (number is 2) + qiseven(q) (number is an even integer) + qisodd(q) (number is an odd integer) + qisreciprocal(q) (number is 1 / an integer and q != 0) The comparisons for NUMBERs are similar to the ones for ZVALUEs. You use the qcmp and qrel functions. -There are four predefined values for fractions. You should qlink them when +There are four predefined values for fractions. You should qlink them when you want to use them. These are _qzero_, _qone_, _qnegone_, and _qonehalf_. These have the values 0, 1, -1, and 1/2. An example of using them is: - NUMBER *q1, *q2; + NUMBER *q1, *q2; - q1 = qlink(&_qonehalf_); - q2 = qlink(&_qone_); + q1 = qlink(&_qonehalf_); + q2 = qlink(&_qone_); To determine if q is an integer power of 2, use qispowerof2: - NUMBER *q; /* value to check if it is a power of */ - NUMBER *qlog2; /* set to log base 2 of q when is_power_of_2 is true */ - bool is_power_of_2; + NUMBER *q; /* value to check if it is a power of */ + NUMBER *qlog2; /* set to log base 2 of q when is_power_of_2 is true */ + bool is_power_of_2; - q = utoq((FULL) 1234567890L); - qlog2 = qalloc(); - is_power_of_2 = qispowerof2(q, &qlog2); + q = utoq((FULL) 1234567890L); + qlog2 = qalloc(); + is_power_of_2 = qispowerof2(q, &qlog2); Returns true if q an integer power of 2: set *qlog2 to log base 2 of q. Returns false if q is NOT integer power of 2 and leave *qlog2 untouched. @@ -572,7 +572,7 @@ USING COMPLEX NUMBERS --------------------- The arbitrary precision complex arithmetic routines define a structure -called COMPLEX. This is defined in cmath.h. This contains two NUMBERs +called COMPLEX. This is defined in cmath.h. This contains two NUMBERs for the real and imaginary parts of a complex number, and a count of the number of links there are to this COMPLEX number. @@ -583,19 +583,19 @@ fractional parts using qqtoc. You can copy COMPLEX values using clink which increments the link count. And you free a COMPLEX value using cfree. The following example illustrates this: - NUMBER *q1, *q2; - COMPLEX *c1, *c2, *c3; + NUMBER *q1, *q2; + COMPLEX *c1, *c2, *c3; - q1 = itoq(3L); - q2 = itoq(4L); - c1 = qqtoc(q1, q2); - qfree(q1); - qfree(q2); - c2 = clink(c1); - c3 = cmul(c1, c2); - cfree(c1); - cfree(c2); - cfree(c3); + q1 = itoq(3L); + q2 = itoq(4L); + c1 = qqtoc(q1, q2); + qfree(q1); + qfree(q2); + c2 = clink(c1); + c3 = cmul(c1, c2); + cfree(c1); + cfree(c2); + cfree(c3); As a shortcut, when you want to manipulate a COMPLEX value by a real value, you can use the caddq, csubq, cmulq, and cdivq routines. These accept one @@ -605,33 +605,33 @@ There is no direct routine to convert a string value into a COMPLEX value. But you can do this yourself by converting two strings into two NUMBERS, and then using the qqtoc routine. -COMPLEX values are always returned from these routines. To split out the +COMPLEX values are always returned from these routines. To split out the real and imaginary parts into normal NUMBERs, you can simply qlink the two components, as shown in the following example: - COMPLEX *c; - NUMBER *rp, *ip; + COMPLEX *c; + NUMBER *rp, *ip; - c = calloc(); - rp = qlink(c->real); - ip = qlink(c->imag); + c = calloc(); + rp = qlink(c->real); + ip = qlink(c->imag); There are many macros for checking quick things about complex numbers, similar to the ZVALUE and NUMBER macros. In addition, there are some -only used for complex numbers. Examples of macros are: +only used for complex numbers. Examples of macros are: - cisreal(c) (number is real) - cisimag(c) (number is pure imaginary) - ciszero(c) (number is zero) - cisnegone(c) (number is -1) - cisone(c) (number is 1) - cisrunit(c) (number is 1 or -1) - cisiunit(c) (number is i or -i) - cisunit(c) (number is 1, -1, i, or -i) - cistwo(c) (number is 2) - cisint(c) (number is has integer real and imaginary parts) - ciseven(c) (number is has even real and imaginary parts) - cisodd(c) (number is has odd real and imaginary parts) + cisreal(c) (number is real) + cisimag(c) (number is pure imaginary) + ciszero(c) (number is zero) + cisnegone(c) (number is -1) + cisone(c) (number is 1) + cisrunit(c) (number is 1 or -1) + cisiunit(c) (number is i or -i) + cisunit(c) (number is 1, -1, i, or -i) + cistwo(c) (number is 2) + cisint(c) (number is has integer real and imaginary parts) + ciseven(c) (number is has even real and imaginary parts) + cisodd(c) (number is has odd real and imaginary parts) There is only one comparison you can make for COMPLEX values, and that is for equality. The ccmp function returns true if two complex numbers differ. @@ -641,13 +641,13 @@ That is, the imaginary part of the COMPLEX is 0. You may convert the COMPLEX into a new allocated NUMBER that is real part of the COMPLEX value. For example: - COMPLEX *c; - NUMBER *q; - bool ok_to_free; /* true ==> free COMPLEX value, false ==> do not */ + COMPLEX *c; + NUMBER *q; + bool ok_to_free; /* true ==> free COMPLEX value, false ==> do not */ - if (cisreal(c)) { - q = c_to_q(c, ok_to_free); - } + if (cisreal(c)) { + q = c_to_q(c, ok_to_free); + } The 2nd argument to c_to_q() determines if the complex argument should be freed or not. Pass a false value as the 2nd arg if you wish to continue to use the @@ -655,13 +655,13 @@ COMPLEX value. To convert a NUMBER into a COMPLEX value, use: - COMPLEX *c; - NUMBER *q; + COMPLEX *c; + NUMBER *q; - c = q_to_c(q); + c = q_to_c(q); -There are three predefined values for complex numbers. You should clink -them when you want to use them. They are _czero_, _cone_, and _conei_. +There are three predefined values for complex numbers. You should clink +them when you want to use them. They are _czero_, _cone_, and _conei_. These have the values 0, 1, and i. ---------------- @@ -683,7 +683,7 @@ need call libcalc_call_me_last() only once. ## ## 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 +## 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 @@ -691,8 +691,8 @@ need call libcalc_call_me_last() only once. ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1993/07/30 19:44:49 -## File existed as early as: 1993 +## Under source code control: 1993/07/30 19:44:49 +## File existed as early as: 1993 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/QUESTIONS b/QUESTIONS index 0aceb32..fb5a04e 100644 --- a/QUESTIONS +++ b/QUESTIONS @@ -1,7 +1,7 @@ If you have a general question about calc, consider opening a new Github discussion under: - https://github.com/lcn2/calc/discussions + https://github.com/lcn2/calc/discussions Look over the existing discussions to see of your question fits under one of those exiting discussions. @@ -30,7 +30,7 @@ Please be patient as we cannot always respond to discussion messages quickly. ## ## 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 +## 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 @@ -38,8 +38,8 @@ Please be patient as we cannot always respond to discussion messages quickly. ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/02/10 00:15:05 -## File existed as early as: 2021 +## Under source code control: 2021/02/10 00:15:05 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/README.FIRST b/README.FIRST index 293a3fa..d74246b 100644 --- a/README.FIRST +++ b/README.FIRST @@ -4,7 +4,7 @@ See the HOWTO.INSTALL file for information on how to build and install calc. To be sure that your version of calc is up to date, check out: - http://www.isthe.com/chongo/tech/comp/calc/calc-download.html + http://www.isthe.com/chongo/tech/comp/calc/calc-download.html We are interested in any/all feedback on recent versions of calc. In particular we would like to hear about: @@ -27,7 +27,7 @@ If you run into problems, see the BUGS file. Calc is distributed with an extensive collection of help files that are accessible from the command line. The following assume that you are running calc from the distribution directory or that you have -installed calc. In these examples, the "; " is the calc prompt, not +installed calc. In these examples, the "; " is the calc prompt, not something that you type in. For list of help topics: @@ -105,7 +105,7 @@ for information about how to ask a question. ## ## 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 +## 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 @@ -113,8 +113,8 @@ for information about how to ask a question. ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 05:27:59 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 05:27:59 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/README.RELEASE b/README.RELEASE index 199fc5b..43741b9 100644 --- a/README.RELEASE +++ b/README.RELEASE @@ -2,15 +2,15 @@ On calc versions and releases Calc version numbers have 4 levels. For example: - ++=== top 2 levels: calc builtin functions compatibility - || - vvvv + ++=== top 2 levels: calc builtin functions compatibility + || + vvvv - 2.14.0.8 - \\\\\\ - ^ \\\\----> top 3 levels: calc important code base change - | - +--- top version level: internal representation compatibility + 2.14.0.8 + \\\\\\ + ^ \\\\----> top 3 levels: calc important code base change + | + +--- top version level: internal representation compatibility The top version level (e.g., 2) refers to the internal representation of values. Any library or hardware linked/built for calc 2 will be able @@ -35,10 +35,10 @@ a top 3 level release. The file, "version.h" defines the 4 version levels: - MAJOR_VER /* level 1: major library version */ - MINOR_VER /* level 2: minor library version */ - MAJOR_PATCH /* level 3: major software version level */ - MINOR_PATCH /* level 4: minor software version level */ + MAJOR_VER /* level 1: major library version */ + MINOR_VER /* level 2: minor library version */ + MAJOR_PATCH /* level 3: major software version level */ + MINOR_PATCH /* level 4: minor software version level */ The program "ver_calc" will print information about the compiled @@ -46,8 +46,8 @@ calc version as defined "version.h" when "ver_calc" was compiled: usage: ./ver_calc [-h] [-V] - -h print this message and exit non-zero - -V print 3-level version (def: print 4-level version) + -h print this message and exit non-zero + -V print 3-level version (def: print 4-level version) Also "calc -v" will print the calc version as defined "version.h" when "calc" was compiled. @@ -56,7 +56,7 @@ The master branch: The public repository of calc source code is: - http://github.com/lcn2/calc + http://github.com/lcn2/calc On that GitHub site you may find released version of calc, "production", "tested" and "alpha". All commits on the master @@ -65,66 +65,66 @@ The master branch: Any "alpha" commit is likely future code for a future "tested" or "production" version of calc. -alpha ==> untagged GitHub commit +alpha ==> untagged GitHub commit - Any untagged commit to the GitHub master branch should be - considered as alpha code that may make calc unstable. + Any untagged commit to the GitHub master branch should be + considered as alpha code that may make calc unstable. - While we try to avoid breaking the calc code with commits, - there is a risk that picking up such a change could - negatively impact the code. + While we try to avoid breaking the calc code with commits, + there is a risk that picking up such a change could + negatively impact the code. - NOTE: The calc version found in "version.h", and printed - by both "ver_calc [-V]" and "calc -v" for an untagged - commit is the previous "tested" or "production" version - of calc. Any "alpha" changes that remain are code - for some future version of calc. + NOTE: The calc version found in "version.h", and printed + by both "ver_calc [-V]" and "calc -v" for an untagged + commit is the previous "tested" or "production" version + of calc. Any "alpha" changes that remain are code + for some future version of calc. - At the last stage of the release process, "version.h" - will be updated as well as the top level version range - listed in "CHANGES". + At the last stage of the release process, "version.h" + will be updated as well as the top level version range + listed in "CHANGES". -tested ==> tagged GitHub pre-release commit +tested ==> tagged GitHub pre-release commit - A new version of calc has been released and has recently passed - regression testing on at least to different platforms and chip - architectures. + A new version of calc has been released and has recently passed + regression testing on at least to different platforms and chip + architectures. - The "tested" class was historically called "untested", - however this term was misleading as such releases ARE tested. - Since 2.14.0.13 we have used the term "tested". + The "tested" class was historically called "untested", + however this term was misleading as such releases ARE tested. + Since 2.14.0.13 we have used the term "tested". - All tested releases are tagged with a new version number. - Such releases have GitHub assets such as a source tarball, - zip file, source rpm, development rpm and binary rpm. See the - orange "Pre-release" GitHub releases under: + All tested releases are tagged with a new version number. + Such releases have GitHub assets such as a source tarball, + zip file, source rpm, development rpm and binary rpm. See the + orange "Pre-release" GitHub releases under: - https://github.com/lcn2/calc/releases + https://github.com/lcn2/calc/releases - At the bottom of a given release is a "> Assets" that may - be opened to reveal down-loadable files. + At the bottom of a given release is a "> Assets" that may + be opened to reveal down-loadable files. -production ==> tagged GitHub release commit +production ==> tagged GitHub release commit - A new version of calc has been released and has undergone - extensive testing over time over a number of platforms. - Sometimes a "tested" release that is found work well over - a period of time will be re-released with a new version - number as a "production" release. + A new version of calc has been released and has undergone + extensive testing over time over a number of platforms. + Sometimes a "tested" release that is found work well over + a period of time will be re-released with a new version + number as a "production" release. - The latest production GitHub release is marked with green - "Latest" label under: + The latest production GitHub release is marked with green + "Latest" label under: - https://github.com/lcn2/calc/releases + https://github.com/lcn2/calc/releases - A release that has neither an orange "Pre-release" nor - a green "Latest" label is a prior production class release. + A release that has neither an orange "Pre-release" nor + a green "Latest" label is a prior production class release. - At the bottom of a given release is a "> Assets" that may - be opened to reveal down-loadable files. + At the bottom of a given release is a "> Assets" that may + be opened to reveal down-loadable files. - Production class code where stability is critical should use a - "production" release. + Production class code where stability is critical should use a + "production" release. A historical note and apology: @@ -143,7 +143,7 @@ A historical note and apology: ## ## 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 +## 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 @@ -151,8 +151,8 @@ A historical note and apology: ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/12/12 19:36:26 -## File existed as early as: 2021 +## Under source code control: 2021/12/12 19:36:26 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/README.WINDOWS b/README.WINDOWS index 47deb3a..8fc02bb 100644 --- a/README.WINDOWS +++ b/README.WINDOWS @@ -23,7 +23,7 @@ BTW: While we are unable to use Windows 11, we welcome Windows 11 virtual machine). If you are able to compile Windows 11 natively, we would welcome GitHub pull requests showing any needed modifications: - https://github.com/lcn2/calc/pulls + https://github.com/lcn2/calc/pulls We were given this advice from a Windows 11 developer: @@ -32,9 +32,9 @@ We were given this advice from a Windows 11 developer: https://cygwin.com/install.html IMPORTANT: While installing Cygwin, and during Cygwin Setup, be sure to - select all the MinGW64 packages relating to gcc. + select all the MinGW64 packages relating to gcc. - See the "Compiling with Cygwin" section below. + See the "Compiling with Cygwin" section below. NOTE: Compiling calc under Windows 11 is work in progress. If you run into problems, consider the "Compiling with Cygwin" section below. @@ -79,11 +79,11 @@ compilation steps that GitHub user @Leoongithub recommends: 0. Install the latest version of cygwin (https://cygwin.com/install.html). NOTE: In addition to the default packages, you also need to check these - three packages: gcc-core, make, and libreadline-devel. The version - of these packages does not matter. Just choose the latest version. + three packages: gcc-core, make, and libreadline-devel. The version + of these packages does not matter. Just choose the latest version. NOTE: The addition of "target=Cygwin" to make commands below - is done just in case the target is not set properly by make. + is done just in case the target is not set properly by make. 1. Change (cd) into the top of the source code directory of calc. @@ -92,35 +92,35 @@ compilation steps that GitHub user @Leoongithub recommends: 2. make clobber target=Cygwin NOTE: This helps ensure that you are starting from a so-called "clean slate", - and that you have nothing hanging around from previous attempts to compile. + and that you have nothing hanging around from previous attempts to compile. 3. make all target=Cygwin NOTE: If successful, you should have a calc executable. However that executable - may not be working properly. Advance to step (4) to test. + may not be working properly. Advance to step (4) to test. 4. make chk target=Cygwin NOTE: If you want this command be be verbose, try: - make check target=Cygwin + make check target=Cygwin NOTE: This will run calc with the regress.cal regression suite. This step could take - for a while to run, depending on the speed/performance of your machine. - If all is well (all regression tests pass), you will see at the end: + for a while to run, depending on the speed/performance of your machine. + If all is well (all regression tests pass), you will see at the end: - chk OK + chk OK Otherwise you may see calc exit non-zero after it prints some lines with '****' - error messages followed by a line including a final error count of the form: + error messages followed by a line including a final error count of the form: - **** 2 error(s) found \/++\/ + **** 2 error(s) found \/++\/ If you see some errors that may relate to files and I/O, all may not be lost. - It could simply mean that your Windows environment is not conforming to standard - I/O and file operations. The calc mathematical engine may be just fine. On the - other hand if you see mathematical related regression test failures, this is - bad sign that your calc executable under Windows is not usable. + It could simply mean that your Windows environment is not conforming to standard + I/O and file operations. The calc mathematical engine may be just fine. On the + other hand if you see mathematical related regression test failures, this is + bad sign that your calc executable under Windows is not usable. 5. make install target=Cygwin @@ -136,7 +136,7 @@ We would prefer a Windows 11 solution that does not require a Windows 11 developer to install a Linux virtual machine. Nevertheless, a Windows 11 user might want to use the Microsoft Windows Subsystem (WSL) for Linux: - https://docs.microsoft.com/en-us/windows/wsl/ + https://docs.microsoft.com/en-us/windows/wsl/ We have been told that you will need to turn on virtualization to use this WSL subsystem. @@ -168,7 +168,7 @@ NOTE: The use of calc under Windows 10 has been deprecated in favor of one ## ## 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 +## 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 @@ -176,8 +176,8 @@ NOTE: The use of calc under Windows 10 has been deprecated in favor of one ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2001/02/25 14:00:05 -## File existed as early as: 2001 +## Under source code control: 2001/02/25 14:00:05 +## File existed as early as: 2001 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/README.md b/README.md index fa4ab01..e929f55 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ via zsh: calc Calc is an interactive calculator which provides for easy large numeric calculations, but which also can be easily programmed -for difficult or long calculations. It can accept a command line +for difficult or long calculations. It can accept a command line argument, in which case it executes that single command and exits. Otherwise, it enters interactive mode. In this mode, it accepts commands one at a time, processes them, and displays the answers. @@ -189,12 +189,12 @@ followed by a function declaration very similar to C. ```sh define f2(n) { - local ans; + local ans; - ans = 1; - while (n > 1) - ans *= (n -= 2); - return ans; + ans = 1; + while (n > 1) + ans *= (n -= 2); + return ans; } ``` diff --git a/addop.c b/addop.c index 779e8c0..8850777 100644 --- a/addop.c +++ b/addop.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:10 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:10 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -38,24 +38,24 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define FUNCALLOCSIZE 20 /* reallocate size for functions */ -#define OPCODEALLOCSIZE 100 /* reallocate size for opcodes in functions */ +#define FUNCALLOCSIZE 20 /* reallocate size for functions */ +#define OPCODEALLOCSIZE 100 /* reallocate size for opcodes in functions */ STATIC unsigned long maxopcodes;/* number of opcodes available */ -STATIC long newindex; /* index of new function */ -STATIC char *newname; /* name of new function */ -STATIC long oldop; /* previous opcode */ -STATIC long oldoldop; /* opcode before previous opcode */ -STATIC long debugline; /* line number of latest debug opcode */ -STATIC long funccount; /* number of functions */ -STATIC long funcavail; /* available number of functions */ -STATIC FUNC *functemplate; /* function definition template */ -STATIC FUNC **functions; /* table of functions */ -STATIC STRINGHEAD funcnames; /* function names */ +STATIC long newindex; /* index of new function */ +STATIC char *newname; /* name of new function */ +STATIC long oldop; /* previous opcode */ +STATIC long oldoldop; /* opcode before previous opcode */ +STATIC long debugline; /* line number of latest debug opcode */ +STATIC long funccount; /* number of functions */ +STATIC long funcavail; /* available number of functions */ +STATIC FUNC *functemplate; /* function definition template */ +STATIC FUNC **functions; /* table of functions */ +STATIC STRINGHEAD funcnames; /* function names */ /* @@ -64,20 +64,20 @@ STATIC STRINGHEAD funcnames; /* function names */ void initfunctions(void) { - initstr(&funcnames); - maxopcodes = OPCODEALLOCSIZE; - functemplate = (FUNC *) malloc(funcsize(maxopcodes)); - if (functemplate == NULL) { - math_error("Cannot allocate function template"); - not_reached(); - } - functions = (FUNC **) malloc(sizeof(FUNC *) * FUNCALLOCSIZE); - if (functions == NULL) { - math_error("Cannot allocate function table"); - not_reached(); - } - funccount = 0; - funcavail = FUNCALLOCSIZE; + initstr(&funcnames); + maxopcodes = OPCODEALLOCSIZE; + functemplate = (FUNC *) malloc(funcsize(maxopcodes)); + if (functemplate == NULL) { + math_error("Cannot allocate function template"); + not_reached(); + } + functions = (FUNC **) malloc(sizeof(FUNC *) * FUNCALLOCSIZE); + if (functions == NULL) { + math_error("Cannot allocate function table"); + not_reached(); + } + funccount = 0; + funcavail = FUNCALLOCSIZE; } @@ -87,50 +87,50 @@ initfunctions(void) void showfunctions(void) { - FUNC *fp; /* current function */ - long count; - long index; + FUNC *fp; /* current function */ + long count; + long index; - count = 0; - if (funccount > 0) { - if (conf->resource_debug & RSCDBG_FUNC_INFO) - math_str("Index\tName \tArgs\tOpcodes\n" - "-----\t------ \t---- \t------\n"); - else - math_str("Name\tArguments\n" - "----\t---------\n"); - for (index = 0; index < funccount; index++) { - fp = functions[index]; - if (conf->resource_debug & RSCDBG_FUNC_INFO) { + count = 0; + if (funccount > 0) { + if (conf->resource_debug & RSCDBG_FUNC_INFO) + math_str("Index\tName \tArgs\tOpcodes\n" + "-----\t------ \t---- \t------\n"); + else + math_str("Name\tArguments\n" + "----\t---------\n"); + for (index = 0; index < funccount; index++) { + fp = functions[index]; + if (conf->resource_debug & RSCDBG_FUNC_INFO) { - math_fmt("%5ld\t%-12s\t", index, - namestr(&funcnames,index)); - if (fp) { - count++; - math_fmt("%-5d\t%-5ld\n", - fp->f_paramcount, fp->f_opcodecount); - } else { - math_str("null\t0\n"); - } - } else { - if (fp == NULL) - continue; - count++; - math_fmt("%-12s\t%-2d\n", namestr(&funcnames, - index), fp->f_paramcount); - } - } - } - if (conf->resource_debug & RSCDBG_FUNC_INFO) { - math_fmt("\nNumber non-null: %ld\n", count); - math_fmt("Number null: %ld\n", funccount - count); - math_fmt("Total number: %ld\n", funccount); - } else { - if (count > 0) - math_fmt("\nNumber: %ld\n", count); - else - math_str("No user functions defined\n"); - } + math_fmt("%5ld\t%-12s\t", index, + namestr(&funcnames,index)); + if (fp) { + count++; + math_fmt("%-5d\t%-5ld\n", + fp->f_paramcount, fp->f_opcodecount); + } else { + math_str("null\t0\n"); + } + } else { + if (fp == NULL) + continue; + count++; + math_fmt("%-12s\t%-2d\n", namestr(&funcnames, + index), fp->f_paramcount); + } + } + } + if (conf->resource_debug & RSCDBG_FUNC_INFO) { + math_fmt("\nNumber non-null: %ld\n", count); + math_fmt("Number null: %ld\n", funccount - count); + math_fmt("Total number: %ld\n", funccount); + } else { + if (count > 0) + math_fmt("\nNumber: %ld\n", count); + else + math_str("No user functions defined\n"); + } } @@ -141,38 +141,38 @@ showfunctions(void) * The new structure is returned in the global curfunc variable. * * given: - * name name of function - * newflag true if need new structure + * name name of function + * newflag true if need new structure */ void beginfunc(char *name, bool newflag) { - register FUNC *fp; /* current function */ + register FUNC *fp; /* current function */ - newindex = adduserfunc(name); - maxopcodes = OPCODEALLOCSIZE; - fp = functemplate; - if (newflag) { - fp = (FUNC *) malloc(funcsize(maxopcodes)); - if (fp == NULL) { - math_error("Cannot allocate temporary function"); - not_reached(); - } - } - fp->f_next = NULL; - fp->f_localcount = 0; - fp->f_opcodecount = 0; - fp->f_savedvalue.v_type = V_NULL; - fp->f_savedvalue.v_subtype = V_NOSUBTYPE; - newname = namestr(&funcnames, newindex); - fp->f_name = newname; - curfunc = fp; - initlocals(); - initlabels(); - oldop = OP_NOP; - oldoldop = OP_NOP; - debugline = 0; - errorcount = 0; + newindex = adduserfunc(name); + maxopcodes = OPCODEALLOCSIZE; + fp = functemplate; + if (newflag) { + fp = (FUNC *) malloc(funcsize(maxopcodes)); + if (fp == NULL) { + math_error("Cannot allocate temporary function"); + not_reached(); + } + } + fp->f_next = NULL; + fp->f_localcount = 0; + fp->f_opcodecount = 0; + fp->f_savedvalue.v_type = V_NULL; + fp->f_savedvalue.v_subtype = V_NOSUBTYPE; + newname = namestr(&funcnames, newindex); + fp->f_name = newname; + curfunc = fp; + initlocals(); + initlabels(); + oldop = OP_NOP; + oldoldop = OP_NOP; + debugline = 0; + errorcount = 0; } @@ -184,56 +184,56 @@ beginfunc(char *name, bool newflag) void endfunc(void) { - register FUNC *fp; /* function just finished */ - size_t size; /* size of just created function */ - unsigned long index; + register FUNC *fp; /* function just finished */ + size_t size; /* size of just created function */ + unsigned long index; - if (oldop != OP_RETURN) { - addop(OP_UNDEF); - addop(OP_RETURN); - } + if (oldop != OP_RETURN) { + addop(OP_UNDEF); + addop(OP_RETURN); + } - checklabels(); + checklabels(); - if (errorcount) { - scanerror(T_NULL,"Compilation of \"%s\" failed: %ld error(s)", - newname, errorcount); - return; - } - size = funcsize(curfunc->f_opcodecount); - fp = (FUNC *) malloc(size); - if (fp == NULL) { - math_error("Cannot commit function"); - not_reached(); - } - memcpy((char *) fp, (char *) curfunc, size); - if (curfunc != functemplate) - free(curfunc); - if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) { - dumpnames = true; - for (size = 0; size < fp->f_opcodecount; ) { - printf("%ld: ", (unsigned long)size); - size += dumpop(&fp->f_opcodes[size]); - } - } - if ((inputisterminal() && conf->resource_debug & RSCDBG_STDIN_FUNC) || - (!inputisterminal() && conf->resource_debug & RSCDBG_FILE_FUNC)) { - printf("%s(", newname); - for (index = 0; index < fp->f_paramcount; index++) { - if (index) - putchar(','); - printf("%s", paramname(index)); - } - printf(") "); - if (functions[newindex]) - printf("re"); - printf("defined\n"); - } - if (functions[newindex]) { - freenumbers(functions[newindex]); - free(functions[newindex]); - } - functions[newindex] = fp; + if (errorcount) { + scanerror(T_NULL,"Compilation of \"%s\" failed: %ld error(s)", + newname, errorcount); + return; + } + size = funcsize(curfunc->f_opcodecount); + fp = (FUNC *) malloc(size); + if (fp == NULL) { + math_error("Cannot commit function"); + not_reached(); + } + memcpy((char *) fp, (char *) curfunc, size); + if (curfunc != functemplate) + free(curfunc); + if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) { + dumpnames = true; + for (size = 0; size < fp->f_opcodecount; ) { + printf("%ld: ", (unsigned long)size); + size += dumpop(&fp->f_opcodes[size]); + } + } + if ((inputisterminal() && conf->resource_debug & RSCDBG_STDIN_FUNC) || + (!inputisterminal() && conf->resource_debug & RSCDBG_FILE_FUNC)) { + printf("%s(", newname); + for (index = 0; index < fp->f_paramcount; index++) { + if (index) + putchar(','); + printf("%s", paramname(index)); + } + printf(") "); + if (functions[newindex]) + printf("re"); + printf("defined\n"); + } + if (functions[newindex]) { + freenumbers(functions[newindex]); + free(functions[newindex]); + } + functions[newindex] = fp; } @@ -243,32 +243,32 @@ endfunc(void) * and an error will be generated when it is called if it is still undefined. * * given: - * name name of function + * name name of function */ long adduserfunc(char *name) { - long index; /* index of function */ + long index; /* index of function */ - index = findstr(&funcnames, name); - if (index >= 0) - return index; - if (funccount >= funcavail) { - functions = (FUNC **) realloc(functions, - sizeof(FUNC *) * (funcavail + FUNCALLOCSIZE)); - if (functions == NULL) { - math_error("Failed to reallocate function table"); - not_reached(); - } - funcavail += FUNCALLOCSIZE; - } - if (addstr(&funcnames, name) == NULL) { - math_error("Cannot save function name"); - not_reached(); - } - index = funccount++; - functions[index] = NULL; - return index; + index = findstr(&funcnames, name); + if (index >= 0) + return index; + if (funccount >= funcavail) { + functions = (FUNC **) realloc(functions, + sizeof(FUNC *) * (funcavail + FUNCALLOCSIZE)); + if (functions == NULL) { + math_error("Failed to reallocate function table"); + not_reached(); + } + funcavail += FUNCALLOCSIZE; + } + if (addstr(&funcnames, name) == NULL) { + math_error("Cannot save function name"); + not_reached(); + } + index = funccount++; + functions[index] = NULL; + return index; } /* @@ -277,23 +277,23 @@ adduserfunc(char *name) void rmuserfunc(char *name) { - long index; /* index of function */ + long index; /* index of function */ - index = findstr(&funcnames, name); - if (index < 0) { - warning("No function named \"%s\" to be undefined", name); - return; - } - if (functions[index] == NULL) { - warning("No defined function \"%s\" to be undefined", name); - return; - } - freenumbers(functions[index]); - free(functions[index]); - if ((inputisterminal() && conf->resource_debug & RSCDBG_STDIN_FUNC) || - (!inputisterminal() && conf->resource_debug & RSCDBG_FILE_FUNC)) - printf("%s() undefined\n", name); - functions[index] = NULL; + index = findstr(&funcnames, name); + if (index < 0) { + warning("No function named \"%s\" to be undefined", name); + return; + } + if (functions[index] == NULL) { + warning("No defined function \"%s\" to be undefined", name); + return; + } + freenumbers(functions[index]); + free(functions[index]); + if ((inputisterminal() && conf->resource_debug & RSCDBG_STDIN_FUNC) || + (!inputisterminal() && conf->resource_debug & RSCDBG_FILE_FUNC)) + printf("%s() undefined\n", name); + functions[index] = NULL; } @@ -303,50 +303,50 @@ rmuserfunc(char *name) void freefunc(FUNC *fp) { - long index; - unsigned long i; + long index; + unsigned long i; - if (fp == NULL) - return; - if (fp == curfunc) { - index = newindex; - } else { - for (index = 0; index < funccount; index++) { - if (functions[index] == fp) - break; - } - if (index == funccount) { - math_error("Bad call to freefunc!!!"); - not_reached(); - } - } - if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) { - printf("Freeing function \"%s\"\n",namestr(&funcnames,index)); - dumpnames = false; - for (i = 0; i < fp->f_opcodecount; ) { - printf("%ld: ", i); - i += dumpop(&fp->f_opcodes[i]); - } - } - freenumbers(fp); - if (fp != functemplate) - free(fp); + if (fp == NULL) + return; + if (fp == curfunc) { + index = newindex; + } else { + for (index = 0; index < funccount; index++) { + if (functions[index] == fp) + break; + } + if (index == funccount) { + math_error("Bad call to freefunc!!!"); + not_reached(); + } + } + if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) { + printf("Freeing function \"%s\"\n",namestr(&funcnames,index)); + dumpnames = false; + for (i = 0; i < fp->f_opcodecount; ) { + printf("%ld: ", i); + i += dumpop(&fp->f_opcodes[i]); + } + } + freenumbers(fp); + if (fp != functemplate) + free(fp); } void rmalluserfunc(void) { - FUNC *fp; - long index; + FUNC *fp; + long index; - for (index = 0; index < funccount; index++) { - fp = functions[index]; - if (fp) { - freefunc(fp); - functions[index] = NULL; - } - } + for (index = 0; index < funccount; index++) { + fp = functions[index]; + if (fp) { + freefunc(fp); + functions[index] = NULL; + } + } } @@ -357,12 +357,12 @@ rmalluserfunc(void) long getuserfunc(char *name) { - long index; + long index; - index = findstr(&funcnames, name); - if (index >= 0 && functions[index] != NULL) - return index; - return -1L; + index = findstr(&funcnames, name); + if (index >= 0 && functions[index] != NULL) + return index; + return -1L; } @@ -373,9 +373,9 @@ getuserfunc(char *name) void clearopt(void) { - oldop = OP_NOP; - oldoldop = OP_NOP; - debugline = 0; + oldop = OP_NOP; + oldoldop = OP_NOP; + debugline = 0; } @@ -385,11 +385,11 @@ clearopt(void) FUNC * findfunc(long index) { - if (index >= funccount) { - math_error("Undefined function"); - not_reached(); - } - return functions[index]; + if (index >= funccount) { + math_error("Undefined function"); + not_reached(); + } + return functions[index]; } @@ -399,7 +399,7 @@ findfunc(long index) char * namefunc(long index) { - return namestr(&funcnames, index); + return namestr(&funcnames, index); } @@ -410,8 +410,8 @@ namefunc(long index) void writeindexop(void) { - if (oldop == OP_INDEXADDR) - curfunc->f_opcodes[curfunc->f_opcodecount - 1] = true; + if (oldop == OP_INDEXADDR) + curfunc->f_opcodes[curfunc->f_opcodecount - 1] = true; } @@ -423,197 +423,197 @@ writeindexop(void) void addop(long op) { - register FUNC *fp; /* current function */ - NUMBER *q, *q1, *q2; - unsigned long count; - bool cut; - int diff; + register FUNC *fp; /* current function */ + NUMBER *q, *q1, *q2; + unsigned long count; + bool cut; + int diff; - fp = curfunc; - count = fp->f_opcodecount; - cut = true; - diff = 2; - q = NULL; - if ((count + 5) >= maxopcodes) { - maxopcodes += OPCODEALLOCSIZE; - fp = (FUNC *) malloc(funcsize(maxopcodes)); - if (fp == NULL) { - math_error("cannot malloc function"); - not_reached(); - } - memcpy((char *) fp, (char *) curfunc, - funcsize(curfunc->f_opcodecount)); - if (curfunc != functemplate) - free(curfunc); - curfunc = fp; - } + fp = curfunc; + count = fp->f_opcodecount; + cut = true; + diff = 2; + q = NULL; + if ((count + 5) >= maxopcodes) { + maxopcodes += OPCODEALLOCSIZE; + fp = (FUNC *) malloc(funcsize(maxopcodes)); + if (fp == NULL) { + math_error("cannot malloc function"); + not_reached(); + } + memcpy((char *) fp, (char *) curfunc, + funcsize(curfunc->f_opcodecount)); + if (curfunc != functemplate) + free(curfunc); + curfunc = fp; + } - /* - * Check the current opcode against the previous opcode and try to - * slightly optimize the code depending on the various combinations. - */ - switch (op) { - case OP_GETVALUE: - switch (oldop) { - case OP_NUMBER: - case OP_ZERO: - case OP_ONE: - case OP_IMAGINARY: - case OP_GETEPSILON: - case OP_SETEPSILON: - case OP_STRING: - case OP_UNDEF: - case OP_GETCONFIG: - case OP_SETCONFIG: - return; - case OP_DUPLICATE: - diff = 1; - oldop = OP_DUPVALUE; - break; - case OP_FIADDR: - diff = 1; - oldop = OP_FIVALUE; - break; - case OP_GLOBALADDR: - diff = 1 + PTR_SIZE; - oldop = OP_GLOBALVALUE; - break; - case OP_LOCALADDR: - oldop = OP_LOCALVALUE; - break; - case OP_PARAMADDR: - oldop = OP_PARAMVALUE; - break; - case OP_ELEMADDR: - oldop = OP_ELEMVALUE; - break; - default: - cut = false; + /* + * Check the current opcode against the previous opcode and try to + * slightly optimize the code depending on the various combinations. + */ + switch (op) { + case OP_GETVALUE: + switch (oldop) { + case OP_NUMBER: + case OP_ZERO: + case OP_ONE: + case OP_IMAGINARY: + case OP_GETEPSILON: + case OP_SETEPSILON: + case OP_STRING: + case OP_UNDEF: + case OP_GETCONFIG: + case OP_SETCONFIG: + return; + case OP_DUPLICATE: + diff = 1; + oldop = OP_DUPVALUE; + break; + case OP_FIADDR: + diff = 1; + oldop = OP_FIVALUE; + break; + case OP_GLOBALADDR: + diff = 1 + PTR_SIZE; + oldop = OP_GLOBALVALUE; + break; + case OP_LOCALADDR: + oldop = OP_LOCALVALUE; + break; + case OP_PARAMADDR: + oldop = OP_PARAMVALUE; + break; + case OP_ELEMADDR: + oldop = OP_ELEMVALUE; + break; + default: + cut = false; - } - if (cut) { - fp->f_opcodes[count - diff] = oldop; - return; - } - break; - case OP_POP: - switch (oldop) { - case OP_ASSIGN: - fp->f_opcodes[count-1] = OP_ASSIGNPOP; - oldop = OP_ASSIGNPOP; - return; - case OP_NUMBER: - case OP_IMAGINARY: - q = constvalue(fp->f_opcodes[count-1]); - qfree(q); - break; - case OP_STRING: - sfree(findstring((long)fp->f_opcodes[count-1])); - break; - case OP_LOCALADDR: - case OP_PARAMADDR: - break; - case OP_GLOBALADDR: - diff = 1 + PTR_SIZE; - break; - case OP_UNDEF: - fp->f_opcodecount -= 1; - oldop = OP_NOP; - oldoldop = OP_NOP; - return; - default: - cut = false; - } - if (cut) { - fp->f_opcodecount -= diff; - oldop = OP_NOP; - oldoldop = OP_NOP; - warning("Constant before comma operator"); - return; - } - break; - case OP_NEGATE: - if (oldop == OP_NUMBER) { - q = constvalue(fp->f_opcodes[count-1]); - fp->f_opcodes[count-1] = addqconstant(qneg(q)); - qfree(q); - return; - } - } - if (oldop == OP_NUMBER) { - if (oldoldop == OP_NUMBER) { - q1 = constvalue(fp->f_opcodes[count - 3]); - q2 = constvalue(fp->f_opcodes[count - 1]); - switch (op) { - case OP_DIV: - if (qiszero(q2)) { - cut = false; - break; - } - q = qqdiv(q1,q2); - break; - case OP_MUL: - q = qmul(q1,q2); - break; - case OP_ADD: - q = qqadd(q1,q2); - break; - case OP_SUB: - q = qsub(q1,q2); - break; - case OP_POWER: - if (qisfrac(q2) || qisneg(q2)) - cut = false; - else - q = qpowi(q1,q2); - break; - default: - cut = false; - } - if (cut) { - qfree(q1); - qfree(q2); - fp->f_opcodes[count - 3] = addqconstant(q); - fp->f_opcodecount -= 2; - oldoldop = OP_NOP; - return; - } - } else if (op != OP_NUMBER) { - q = constvalue(fp->f_opcodes[count - 1]); - if (op == OP_POWER) { - if (qcmpi(q, 2L) == 0) { - fp->f_opcodecount--; - fp->f_opcodes[count - 2] = OP_SQUARE; - qfree(q); - oldop = OP_SQUARE; - return; - } - if (qcmpi(q, 4L) == 0) { - fp->f_opcodes[count - 2] = OP_SQUARE; - fp->f_opcodes[count - 1] = OP_SQUARE; - qfree(q); - oldop = OP_SQUARE; - return; - } - } - if (qiszero(q)) { - qfree(q); - fp->f_opcodes[count - 2] = OP_ZERO; - fp->f_opcodecount--; - } else if (qisone(q)) { - qfree(q); - fp->f_opcodes[count - 2] = OP_ONE; - fp->f_opcodecount--; - } - } - } - /* - * No optimization possible, so store the opcode. - */ - fp->f_opcodes[fp->f_opcodecount] = op; - fp->f_opcodecount++; - oldoldop = oldop; - oldop = op; + } + if (cut) { + fp->f_opcodes[count - diff] = oldop; + return; + } + break; + case OP_POP: + switch (oldop) { + case OP_ASSIGN: + fp->f_opcodes[count-1] = OP_ASSIGNPOP; + oldop = OP_ASSIGNPOP; + return; + case OP_NUMBER: + case OP_IMAGINARY: + q = constvalue(fp->f_opcodes[count-1]); + qfree(q); + break; + case OP_STRING: + sfree(findstring((long)fp->f_opcodes[count-1])); + break; + case OP_LOCALADDR: + case OP_PARAMADDR: + break; + case OP_GLOBALADDR: + diff = 1 + PTR_SIZE; + break; + case OP_UNDEF: + fp->f_opcodecount -= 1; + oldop = OP_NOP; + oldoldop = OP_NOP; + return; + default: + cut = false; + } + if (cut) { + fp->f_opcodecount -= diff; + oldop = OP_NOP; + oldoldop = OP_NOP; + warning("Constant before comma operator"); + return; + } + break; + case OP_NEGATE: + if (oldop == OP_NUMBER) { + q = constvalue(fp->f_opcodes[count-1]); + fp->f_opcodes[count-1] = addqconstant(qneg(q)); + qfree(q); + return; + } + } + if (oldop == OP_NUMBER) { + if (oldoldop == OP_NUMBER) { + q1 = constvalue(fp->f_opcodes[count - 3]); + q2 = constvalue(fp->f_opcodes[count - 1]); + switch (op) { + case OP_DIV: + if (qiszero(q2)) { + cut = false; + break; + } + q = qqdiv(q1,q2); + break; + case OP_MUL: + q = qmul(q1,q2); + break; + case OP_ADD: + q = qqadd(q1,q2); + break; + case OP_SUB: + q = qsub(q1,q2); + break; + case OP_POWER: + if (qisfrac(q2) || qisneg(q2)) + cut = false; + else + q = qpowi(q1,q2); + break; + default: + cut = false; + } + if (cut) { + qfree(q1); + qfree(q2); + fp->f_opcodes[count - 3] = addqconstant(q); + fp->f_opcodecount -= 2; + oldoldop = OP_NOP; + return; + } + } else if (op != OP_NUMBER) { + q = constvalue(fp->f_opcodes[count - 1]); + if (op == OP_POWER) { + if (qcmpi(q, 2L) == 0) { + fp->f_opcodecount--; + fp->f_opcodes[count - 2] = OP_SQUARE; + qfree(q); + oldop = OP_SQUARE; + return; + } + if (qcmpi(q, 4L) == 0) { + fp->f_opcodes[count - 2] = OP_SQUARE; + fp->f_opcodes[count - 1] = OP_SQUARE; + qfree(q); + oldop = OP_SQUARE; + return; + } + } + if (qiszero(q)) { + qfree(q); + fp->f_opcodes[count - 2] = OP_ZERO; + fp->f_opcodecount--; + } else if (qisone(q)) { + qfree(q); + fp->f_opcodes[count - 2] = OP_ONE; + fp->f_opcodecount--; + } + } + } + /* + * No optimization possible, so store the opcode. + */ + fp->f_opcodes[fp->f_opcodecount] = op; + fp->f_opcodecount++; + oldoldop = oldop; + oldop = op; } @@ -624,18 +624,18 @@ addop(long op) void addopone(long op, long arg) { - if (op == OP_DEBUG) { - if ((conf->traceflags & TRACE_NODEBUG) || (arg == debugline)) - return; - debugline = arg; - if (oldop == OP_DEBUG) { - curfunc->f_opcodes[curfunc->f_opcodecount - 1] = arg; - return; - } - } - addop(op); - curfunc->f_opcodes[curfunc->f_opcodecount] = arg; - curfunc->f_opcodecount++; + if (op == OP_DEBUG) { + if ((conf->traceflags & TRACE_NODEBUG) || (arg == debugline)) + return; + debugline = arg; + if (oldop == OP_DEBUG) { + curfunc->f_opcodes[curfunc->f_opcodecount - 1] = arg; + return; + } + } + addop(op); + curfunc->f_opcodes[curfunc->f_opcodecount] = arg; + curfunc->f_opcodecount++; } @@ -646,9 +646,9 @@ addopone(long op, long arg) void addoptwo(long op, long arg1, long arg2) { - addop(op); - curfunc->f_opcodes[curfunc->f_opcodecount++] = arg1; - curfunc->f_opcodes[curfunc->f_opcodecount++] = arg2; + addop(op); + curfunc->f_opcodes[curfunc->f_opcodecount++] = arg1; + curfunc->f_opcodes[curfunc->f_opcodecount++] = arg2; } @@ -658,12 +658,12 @@ addoptwo(long op, long arg1, long arg2) void addopptr(long op, char *ptr) { - char **ptraddr; + char **ptraddr; - addop(op); - ptraddr = (char **) &curfunc->f_opcodes[curfunc->f_opcodecount]; - *ptraddr = ptr; - curfunc->f_opcodecount += PTR_SIZE; + addop(op); + ptraddr = (char **) &curfunc->f_opcodes[curfunc->f_opcodecount]; + *ptraddr = ptr; + curfunc->f_opcodecount += PTR_SIZE; } @@ -673,21 +673,21 @@ addopptr(long op, char *ptr) void addopfunction(long op, long index, int count) { - long newop; + long newop; - if ((op == OP_CALL) && ((newop = builtinopcode(index)) != OP_NOP)) { - if ((newop == OP_SETCONFIG) && (count == 1)) - newop = OP_GETCONFIG; - if ((newop == OP_SETEPSILON) && (count == 0)) - newop = OP_GETEPSILON; - if ((newop == OP_ABS) && (count == 1)) - addop(OP_GETEPSILON); - addop(newop); - return; - } - addop(op); - curfunc->f_opcodes[curfunc->f_opcodecount++] = index; - curfunc->f_opcodes[curfunc->f_opcodecount++] = count; + if ((op == OP_CALL) && ((newop = builtinopcode(index)) != OP_NOP)) { + if ((newop == OP_SETCONFIG) && (count == 1)) + newop = OP_GETCONFIG; + if ((newop == OP_SETEPSILON) && (count == 0)) + newop = OP_GETEPSILON; + if ((newop == OP_ABS) && (count == 1)) + addop(OP_GETEPSILON); + addop(newop); + return; + } + addop(op); + curfunc->f_opcodes[curfunc->f_opcodecount++] = index; + curfunc->f_opcodes[curfunc->f_opcodecount++] = count; } @@ -695,11 +695,11 @@ addopfunction(long op, long index, int count) * Add a jump-type opcode and a label to the function being compiled. * * given: - * label label to be added + * label label to be added */ void addoplabel(long op, LABEL *label) { - addop(op); - uselabel(label); + addop(op); + uselabel(label); } diff --git a/align32.c b/align32.c index ff11551..2aefa99 100644 --- a/align32.c +++ b/align32.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/11/23 05:18:06 - * File existed as early as: 1995 + * Under source code control: 1995/11/23 05:18:06 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -42,42 +42,42 @@ #include "have_unused.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -static void buserr(int arg); /* catch alignment errors */ +static void buserr(int arg); /* catch alignment errors */ int main(void) { - char byte[2*sizeof(USB32)]; /* mis-alignment buffer */ - USB32 *p; /* mis-alignment pointer */ - unsigned long i; + char byte[2*sizeof(USB32)]; /* mis-alignment buffer */ + USB32 *p; /* mis-alignment pointer */ + unsigned long i; #if defined(MUST_ALIGN32) - /* force alignment */ - printf("#define MUST_ALIGN32\t%c* forced to align 32 bit values *%c\n", - '/', '/'); + /* force alignment */ + printf("#define MUST_ALIGN32\t%c* forced to align 32 bit values *%c\n", + '/', '/'); #else - /* setup to catch alignment bus errors */ - signal(SIGBUS, buserr); - signal(SIGSEGV, buserr); /* some systems will generate SEGV instead! */ + /* setup to catch alignment bus errors */ + signal(SIGBUS, buserr); + signal(SIGSEGV, buserr); /* some systems will generate SEGV instead! */ - /* mis-align our long fetches */ - for (i=0; i < sizeof(USB32); ++i) { - p = (USB32 *)(byte+i); - *p = i; - *p += 1; - } + /* mis-align our long fetches */ + for (i=0; i < sizeof(USB32); ++i) { + p = (USB32 *)(byte+i); + *p = i; + *p += 1; + } - /* if we got here, then we can mis-align longs */ - printf("#undef MUST_ALIGN32\t%c* can mis-align 32 bit values *%c\n", - '/', '/'); + /* if we got here, then we can mis-align longs */ + printf("#undef MUST_ALIGN32\t%c* can mis-align 32 bit values *%c\n", + '/', '/'); #endif - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } @@ -85,14 +85,14 @@ main(void) * buserr - catch an alignment error * * given: - * arg to keep ANSI C happy + * arg to keep ANSI C happy */ /*ARGSUSED*/ static void buserr(int UNUSED(arg)) { - /* alignment is required */ - printf("#define MUST_ALIGN32\t%c* must align 32 bit values *%c\n", - '/', '/'); - exit(0); + /* alignment is required */ + printf("#define MUST_ALIGN32\t%c* must align 32 bit values *%c\n", + '/', '/'); + exit(0); } diff --git a/alloc.h b/alloc.h index 1d405ba..cb6c7c2 100644 --- a/alloc.h +++ b/alloc.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:29 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:29 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,7 +28,7 @@ #define INCLUDE_ALLOC_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "have_newstr.h" # include "have_string.h" # include "have_memmv.h" diff --git a/assocfunc.c b/assocfunc.c index 9e91b6d..7827218 100644 --- a/assocfunc.c +++ b/assocfunc.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1993/07/20 23:04:27 - * File existed as early as: 1993 + * Under source code control: 1993/07/20 23:04:27 + * File existed as early as: 1993 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -37,13 +37,13 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define MINHASHSIZE 31 /* minimum size of hash tables */ -#define GROWHASHSIZE 50 /* approximate growth for hash tables */ -#define CHAINLENGTH 10 /* desired number of elements on a hash chain */ -#define ELEMSIZE(n) (sizeof(ASSOCELEM) + (sizeof(VALUE) * ((n) - 1))) +#define MINHASHSIZE 31 /* minimum size of hash tables */ +#define GROWHASHSIZE 50 /* approximate growth for hash tables */ +#define CHAINLENGTH 10 /* desired number of elements on a hash chain */ +#define ELEMSIZE(n) (sizeof(ASSOCELEM) + (sizeof(VALUE) * ((n) - 1))) S_FUNC ASSOCELEM *elemindex(ASSOC *ap, long index); @@ -59,75 +59,75 @@ S_FUNC void assoc_elemfree(ASSOCELEM *ep); * the index value doesn't exist, a pointer to a NULL value is returned. * * given: - * ap association to index into - * create whether to create the index value - * dim dimension of the indexing - * indices table of values being indexed by + * ap association to index into + * create whether to create the index value + * dim dimension of the indexing + * indices table of values being indexed by */ VALUE * associndex(ASSOC *ap, bool create, long dim, VALUE *indices) { - ASSOCELEM **listhead; - ASSOCELEM *ep; - STATIC VALUE val; - QCKHASH hash; - int i; + ASSOCELEM **listhead; + ASSOCELEM *ep; + STATIC VALUE val; + QCKHASH hash; + int i; - if (dim < 0) { - math_error("Negative dimension for indexing association"); - not_reached(); - } + if (dim < 0) { + math_error("Negative dimension for indexing association"); + not_reached(); + } - /* - * Calculate the hash value to use for this set of indices - * so that we can first select the correct hash chain, and - * also so we can quickly compare each element for a match. - */ - hash = QUICKHASH_BASIS; - for (i = 0; i < dim; i++) - hash = hashvalue(&indices[i], hash); + /* + * Calculate the hash value to use for this set of indices + * so that we can first select the correct hash chain, and + * also so we can quickly compare each element for a match. + */ + hash = QUICKHASH_BASIS; + for (i = 0; i < dim; i++) + hash = hashvalue(&indices[i], hash); - /* - * Search the correct hash chain for the specified set of indices. - * If found, return the address of the found element's value. - */ - listhead = &ap->a_table[hash % ap->a_size]; - for (ep = *listhead; ep; ep = ep->e_next) { - if ((ep->e_hash != hash) || (ep->e_dim != dim)) - continue; - if (compareindices(ep->e_indices, indices, dim)) - return &ep->e_value; - } + /* + * Search the correct hash chain for the specified set of indices. + * If found, return the address of the found element's value. + */ + listhead = &ap->a_table[hash % ap->a_size]; + for (ep = *listhead; ep; ep = ep->e_next) { + if ((ep->e_hash != hash) || (ep->e_dim != dim)) + continue; + if (compareindices(ep->e_indices, indices, dim)) + return &ep->e_value; + } - /* - * The set of indices was not found. - * Either return a pointer to a NULL value for a read reference, - * or allocate a new element in the list for a write reference. - */ - if (!create) { - val.v_type = V_NULL; - val.v_subtype = V_NOSUBTYPE; - return &val; - } + /* + * The set of indices was not found. + * Either return a pointer to a NULL value for a read reference, + * or allocate a new element in the list for a write reference. + */ + if (!create) { + val.v_type = V_NULL; + val.v_subtype = V_NOSUBTYPE; + return &val; + } - ep = (ASSOCELEM *) malloc(ELEMSIZE(dim)); - if (ep == NULL) { - math_error("Cannot allocate association element"); - not_reached(); - } - ep->e_dim = dim; - ep->e_hash = hash; - ep->e_value.v_type = V_NULL; - ep->e_value.v_subtype = V_NOSUBTYPE; - for (i = 0; i < dim; i++) - copyvalue(&indices[i], &ep->e_indices[i]); - ep->e_next = *listhead; - *listhead = ep; - ap->a_count++; + ep = (ASSOCELEM *) malloc(ELEMSIZE(dim)); + if (ep == NULL) { + math_error("Cannot allocate association element"); + not_reached(); + } + ep->e_dim = dim; + ep->e_hash = hash; + ep->e_value.v_type = V_NULL; + ep->e_value.v_subtype = V_NOSUBTYPE; + for (i = 0; i < dim; i++) + copyvalue(&indices[i], &ep->e_indices[i]); + ep->e_next = *listhead; + *listhead = ep; + ap->a_count++; - resize(ap, ap->a_count / CHAINLENGTH); + resize(ap, ap->a_count / CHAINLENGTH); - return &ep->e_value; + return &ep->e_value; } @@ -139,25 +139,25 @@ associndex(ASSOC *ap, bool create, long dim, VALUE *indices) int assocsearch(ASSOC *ap, VALUE *vp, long i, long j, ZVALUE *index) { - ASSOCELEM *ep; + ASSOCELEM *ep; - if (i < 0 || j > ap->a_count) { - math_error("This should not happen in assocsearch"); - not_reached(); - } - while (i < j) { - ep = elemindex(ap, i); - if (ep == NULL) { - math_error("This should not happen in assocsearch"); - not_reached(); - } - if (acceptvalue(&ep->e_value, vp)) { - utoz(i, index); - return 0; - } - i++; - } - return 1; + if (i < 0 || j > ap->a_count) { + math_error("This should not happen in assocsearch"); + not_reached(); + } + while (i < j) { + ep = elemindex(ap, i); + if (ep == NULL) { + math_error("This should not happen in assocsearch"); + not_reached(); + } + if (acceptvalue(&ep->e_value, vp)) { + utoz(i, index); + return 0; + } + i++; + } + return 1; } @@ -169,26 +169,26 @@ assocsearch(ASSOC *ap, VALUE *vp, long i, long j, ZVALUE *index) int assocrsearch(ASSOC *ap, VALUE *vp, long i, long j, ZVALUE *index) { - ASSOCELEM *ep; + ASSOCELEM *ep; - if (i < 0 || j > ap->a_count) { - math_error("This should not happen in assocsearch"); - not_reached(); - } - j--; - while (j >= i) { - ep = elemindex(ap, j); - if (ep == NULL) { - math_error("This should not happen in assocsearch"); - not_reached(); - } - if (acceptvalue(&ep->e_value, vp)) { - utoz(j, index); - return 0; - } - j--; - } - return 1; + if (i < 0 || j > ap->a_count) { + math_error("This should not happen in assocsearch"); + not_reached(); + } + j--; + while (j >= i) { + ep = elemindex(ap, j); + if (ep == NULL) { + math_error("This should not happen in assocsearch"); + not_reached(); + } + if (acceptvalue(&ep->e_value, vp)) { + utoz(j, index); + return 0; + } + j--; + } + return 1; } @@ -197,29 +197,29 @@ assocrsearch(ASSOC *ap, VALUE *vp, long i, long j, ZVALUE *index) * double-bracket operation. * * given: - * ap association to index into - * index index of desired element + * ap association to index into + * index index of desired element */ S_FUNC ASSOCELEM * elemindex(ASSOC *ap, long index) { - ASSOCELEM *ep; - int i; + ASSOCELEM *ep; + int i; - if ((index < 0) || (index > ap->a_count)) - return NULL; + if ((index < 0) || (index > ap->a_count)) + return NULL; - /* - * This loop should be made more efficient by remembering - * previously requested locations within the association. - */ - for (i = 0; i < ap->a_size; i++) { - for (ep = ap->a_table[i]; ep; ep = ep->e_next) { - if (index-- == 0) - return ep; - } - } - return NULL; + /* + * This loop should be made more efficient by remembering + * previously requested locations within the association. + */ + for (i = 0; i < ap->a_size; i++) { + for (ep = ap->a_table[i]; ep; ep = ep->e_next) { + if (index-- == 0) + return ep; + } + } + return NULL; } @@ -228,18 +228,18 @@ elemindex(ASSOC *ap, long index) * of an association. Returns NULL if there is no such element. * * given: - * ap association to index into - * index index of desired element + * ap association to index into + * index index of desired element */ VALUE * assocfindex(ASSOC *ap, long index) { - ASSOCELEM *ep; + ASSOCELEM *ep; - ep = elemindex(ap, index); - if (ep == NULL) - return NULL; - return &ep->e_value; + ep = elemindex(ap, index); + if (ep == NULL) + return NULL; + return &ep->e_value; } @@ -250,17 +250,17 @@ assocfindex(ASSOC *ap, long index) LIST * associndices(ASSOC *ap, long index) { - ASSOCELEM *ep; - LIST *lp; - int i; + ASSOCELEM *ep; + LIST *lp; + int i; - ep = elemindex(ap, index); - if (ep == NULL) - return NULL; - lp = listalloc(); - for (i = 0; i < ep->e_dim; i++) - insertlistlast(lp, &ep->e_indices[i]); - return lp; + ep = elemindex(ap, index); + if (ep == NULL) + return NULL; + lp = listalloc(); + for (i = 0; i < ep->e_dim; i++) + insertlistlast(lp, &ep->e_indices[i]); + return lp; } @@ -271,43 +271,43 @@ associndices(ASSOC *ap, long index) bool assoccmp(ASSOC *ap1, ASSOC *ap2) { - ASSOCELEM **table1; - ASSOCELEM *ep1; - ASSOCELEM *ep2; - long size1; - long size2; - QCKHASH hash; - long dim; + ASSOCELEM **table1; + ASSOCELEM *ep1; + ASSOCELEM *ep2; + long size1; + long size2; + QCKHASH hash; + long dim; - if (ap1 == ap2) - return false; - if (ap1->a_count != ap2->a_count) - return true; + if (ap1 == ap2) + return false; + if (ap1->a_count != ap2->a_count) + return true; - table1 = ap1->a_table; - size1 = ap1->a_size; - size2 = ap2->a_size; - while (size1-- > 0) { - for (ep1 = *table1++; ep1; ep1 = ep1->e_next) { - hash = ep1->e_hash; - dim = ep1->e_dim; - for (ep2 = ap2->a_table[hash % size2]; ; - ep2 = ep2->e_next) { - if (ep2 == NULL) - return true; - if (ep2->e_hash != hash) - continue; - if (ep2->e_dim != dim) - continue; - if (compareindices(ep1->e_indices, - ep2->e_indices, dim)) - break; - } - if (comparevalue(&ep1->e_value, &ep2->e_value)) - return true; - } - } - return false; + table1 = ap1->a_table; + size1 = ap1->a_size; + size2 = ap2->a_size; + while (size1-- > 0) { + for (ep1 = *table1++; ep1; ep1 = ep1->e_next) { + hash = ep1->e_hash; + dim = ep1->e_dim; + for (ep2 = ap2->a_table[hash % size2]; ; + ep2 = ep2->e_next) { + if (ep2 == NULL) + return true; + if (ep2->e_hash != hash) + continue; + if (ep2->e_dim != dim) + continue; + if (compareindices(ep1->e_indices, + ep2->e_indices, dim)) + break; + } + if (comparevalue(&ep1->e_value, &ep2->e_value)) + return true; + } + } + return false; } @@ -317,39 +317,39 @@ assoccmp(ASSOC *ap1, ASSOC *ap2) ASSOC * assoccopy(ASSOC *oldap) { - ASSOC *ap; - ASSOCELEM *oldep; - ASSOCELEM *ep; - ASSOCELEM **listhead; - int oldhi; - int i; + ASSOC *ap; + ASSOCELEM *oldep; + ASSOCELEM *ep; + ASSOCELEM **listhead; + int oldhi; + int i; - ap = assocalloc(oldap->a_count / CHAINLENGTH); - ap->a_count = oldap->a_count; + ap = assocalloc(oldap->a_count / CHAINLENGTH); + ap->a_count = oldap->a_count; - for (oldhi = 0; oldhi < oldap->a_size; oldhi++) { - for (oldep = oldap->a_table[oldhi]; oldep; - oldep = oldep->e_next) { - ep = (ASSOCELEM *) malloc(ELEMSIZE(oldep->e_dim)); - if (ep == NULL) { - math_error("Cannot allocate " - "association element"); - not_reached(); - } - ep->e_dim = oldep->e_dim; - ep->e_hash = oldep->e_hash; - ep->e_value.v_type = V_NULL; - ep->e_value.v_subtype = V_NOSUBTYPE; - for (i = 0; i < ep->e_dim; i++) - copyvalue(&oldep->e_indices[i], - &ep->e_indices[i]); - copyvalue(&oldep->e_value, &ep->e_value); - listhead = &ap->a_table[ep->e_hash % ap->a_size]; - ep->e_next = *listhead; - *listhead = ep; - } - } - return ap; + for (oldhi = 0; oldhi < oldap->a_size; oldhi++) { + for (oldep = oldap->a_table[oldhi]; oldep; + oldep = oldep->e_next) { + ep = (ASSOCELEM *) malloc(ELEMSIZE(oldep->e_dim)); + if (ep == NULL) { + math_error("Cannot allocate " + "association element"); + not_reached(); + } + ep->e_dim = oldep->e_dim; + ep->e_hash = oldep->e_hash; + ep->e_value.v_type = V_NULL; + ep->e_value.v_subtype = V_NOSUBTYPE; + for (i = 0; i < ep->e_dim; i++) + copyvalue(&oldep->e_indices[i], + &ep->e_indices[i]); + copyvalue(&oldep->e_value, &ep->e_value); + listhead = &ap->a_table[ep->e_hash % ap->a_size]; + ep->e_next = *listhead; + *listhead = ep; + } + } + return ap; } @@ -361,41 +361,41 @@ assoccopy(ASSOC *oldap) S_FUNC void resize(ASSOC *ap, long newsize) { - ASSOCELEM **oldtable; - ASSOCELEM **newtable; - ASSOCELEM **oldlist; - ASSOCELEM **newlist; - ASSOCELEM *ep; - int i; + ASSOCELEM **oldtable; + ASSOCELEM **newtable; + ASSOCELEM **oldlist; + ASSOCELEM **newlist; + ASSOCELEM *ep; + int i; - if (newsize < ap->a_size + GROWHASHSIZE) - return; + if (newsize < ap->a_size + GROWHASHSIZE) + return; - newsize = (long) next_prime((FULL)newsize); - newtable = (ASSOCELEM **) malloc(sizeof(ASSOCELEM *) * newsize); - if (newtable == NULL) { - math_error("No memory to grow association"); - not_reached(); - } - for (i = 0; i < newsize; i++) - newtable[i] = NULL; + newsize = (long) next_prime((FULL)newsize); + newtable = (ASSOCELEM **) malloc(sizeof(ASSOCELEM *) * newsize); + if (newtable == NULL) { + math_error("No memory to grow association"); + not_reached(); + } + for (i = 0; i < newsize; i++) + newtable[i] = NULL; - oldtable = ap->a_table; - oldlist = oldtable; - for (i = 0; i < ap->a_size; i++) { - while (*oldlist) { - ep = *oldlist; - *oldlist = ep->e_next; - newlist = &newtable[ep->e_hash % newsize]; - ep->e_next = *newlist; - *newlist = ep; - } - oldlist++; - } + oldtable = ap->a_table; + oldlist = oldtable; + for (i = 0; i < ap->a_size; i++) { + while (*oldlist) { + ep = *oldlist; + *oldlist = ep->e_next; + newlist = &newtable[ep->e_hash % newsize]; + ep->e_next = *newlist; + *newlist = ep; + } + oldlist++; + } - ap->a_table = newtable; - ap->a_size = newsize; - free((char *) oldtable); + ap->a_table = newtable; + ap->a_size = newsize; + free((char *) oldtable); } @@ -405,14 +405,14 @@ resize(ASSOC *ap, long newsize) S_FUNC void assoc_elemfree(ASSOCELEM *ep) { - int i; + int i; - for (i = 0; i < ep->e_dim; i++) - freevalue(&ep->e_indices[i]); - freevalue(&ep->e_value); - ep->e_dim = 0; - ep->e_next = NULL; - free((char *) ep); + for (i = 0; i < ep->e_dim; i++) + freevalue(&ep->e_indices[i]); + freevalue(&ep->e_value); + ep->e_dim = 0; + ep->e_next = NULL; + free((char *) ep); } @@ -423,27 +423,27 @@ assoc_elemfree(ASSOCELEM *ep) ASSOC * assocalloc(long initsize) { - register ASSOC *ap; - int i; + register ASSOC *ap; + int i; - if (initsize < MINHASHSIZE) - initsize = MINHASHSIZE; - ap = (ASSOC *) malloc(sizeof(ASSOC)); - if (ap == NULL) { - math_error("No memory for association"); - not_reached(); - } - ap->a_count = 0; - ap->a_size = initsize; - ap->a_table = (ASSOCELEM **) malloc(sizeof(ASSOCELEM *) * initsize); - if (ap->a_table == NULL) { - free((char *) ap); - math_error("No memory for association"); - not_reached(); - } - for (i = 0; i < initsize; i++) - ap->a_table[i] = NULL; - return ap; + if (initsize < MINHASHSIZE) + initsize = MINHASHSIZE; + ap = (ASSOC *) malloc(sizeof(ASSOC)); + if (ap == NULL) { + math_error("No memory for association"); + not_reached(); + } + ap->a_count = 0; + ap->a_size = initsize; + ap->a_table = (ASSOCELEM **) malloc(sizeof(ASSOCELEM *) * initsize); + if (ap->a_table == NULL) { + free((char *) ap); + math_error("No memory for association"); + not_reached(); + } + for (i = 0; i < initsize; i++) + ap->a_table[i] = NULL; + return ap; } @@ -453,25 +453,25 @@ assocalloc(long initsize) void assocfree(ASSOC *ap) { - ASSOCELEM **listhead; - ASSOCELEM *ep; - ASSOCELEM *nextep; - int i; + ASSOCELEM **listhead; + ASSOCELEM *ep; + ASSOCELEM *nextep; + int i; - listhead = ap->a_table; - for (i = 0; i < ap->a_size; i++) { - nextep = *listhead; - *listhead = NULL; - while (nextep) { - ep = nextep; - nextep = ep->e_next; - assoc_elemfree(ep); - } - listhead++; - } - free((char *) ap->a_table); - ap->a_table = NULL; - free((char *) ap); + listhead = ap->a_table; + for (i = 0; i < ap->a_size; i++) { + nextep = *listhead; + *listhead = NULL; + while (nextep) { + ep = nextep; + nextep = ep->e_next; + assoc_elemfree(ep); + } + listhead++; + } + free((char *) ap->a_table); + ap->a_table = NULL; + free((char *) ap); } @@ -482,39 +482,39 @@ assocfree(ASSOC *ap) void assocprint(ASSOC *ap, long max_print) { - ASSOCELEM *ep; - long index; - long i; - int savemode; + ASSOCELEM *ep; + long index; + long i; + int savemode; - if (max_print <= 0) { - math_fmt("assoc (%ld element%s)", ap->a_count, - ((ap->a_count == 1) ? "" : "s")); - return; - } - math_fmt("\n assoc (%ld element%s):\n", ap->a_count, - ((ap->a_count == 1) ? "" : "s")); + if (max_print <= 0) { + math_fmt("assoc (%ld element%s)", ap->a_count, + ((ap->a_count == 1) ? "" : "s")); + return; + } + math_fmt("\n assoc (%ld element%s):\n", ap->a_count, + ((ap->a_count == 1) ? "" : "s")); - for (index = 0; ((index < max_print) && (index < ap->a_count)); - index++) { - ep = elemindex(ap, index); - if (ep == NULL) - continue; - math_str(" ["); - for (i = 0; i < ep->e_dim; i++) { - if (i) - math_chr(','); - savemode = math_setmode(MODE_FRAC); - printvalue(&ep->e_indices[i], - (PRINT_SHORT | PRINT_UNAMBIG)); - math_setmode(savemode); - } - math_str("] = "); - printvalue(&ep->e_value, PRINT_SHORT | PRINT_UNAMBIG); - math_chr('\n'); - } - if (max_print < ap->a_count) - math_str(" ...\n"); + for (index = 0; ((index < max_print) && (index < ap->a_count)); + index++) { + ep = elemindex(ap, index); + if (ep == NULL) + continue; + math_str(" ["); + for (i = 0; i < ep->e_dim; i++) { + if (i) + math_chr(','); + savemode = math_setmode(MODE_FRAC); + printvalue(&ep->e_indices[i], + (PRINT_SHORT | PRINT_UNAMBIG)); + math_setmode(savemode); + } + math_str("] = "); + printvalue(&ep->e_value, PRINT_SHORT | PRINT_UNAMBIG); + math_chr('\n'); + } + if (max_print < ap->a_count) + math_str(" ...\n"); } @@ -525,15 +525,15 @@ assocprint(ASSOC *ap, long max_print) S_FUNC bool compareindices(VALUE *v1, VALUE *v2, long dim) { - int i; + int i; - for (i = 0; i < dim; i++) - if (v1[i].v_type != v2[i].v_type) - return false; + for (i = 0; i < dim; i++) + if (v1[i].v_type != v2[i].v_type) + return false; - while (dim-- > 0) - if (comparevalue(v1++, v2++)) - return false; + while (dim-- > 0) + if (comparevalue(v1++, v2++)) + return false; - return true; + return true; } diff --git a/attribute.h b/attribute.h index feb5497..0a25763 100644 --- a/attribute.h +++ b/attribute.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2022/01/21 22:51:25 - * File existed as early as: 2022 + * Under source code control: 2022/01/21 22:51:25 + * File existed as early as: 2022 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ diff --git a/banned.h b/banned.h index 424d363..b8ffa6a 100644 --- a/banned.h +++ b/banned.h @@ -27,18 +27,18 @@ * function may lead to a fatal compiler complication. * If that happens, consider compiling as: * - * make clobber all chk CCBAN=-DUNBAN + * make clobber all chk CCBAN=-DUNBAN * * as see if this is a work-a-round. * * If YOU discover a need for the -DUNBAN work-a-round, PLEASE tell us! * Please send us a bug report. See the file: * - * BUGS + * BUGS * * or the URL: * - * http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html + * http://www.isthe.com/chongo/tech/comp/calc/calc-bugrept.html * * for how to send us such a bug report. * @@ -50,7 +50,7 @@ * * 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 + * 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 @@ -58,11 +58,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2021/03/06 21:07:31 - * File existed as early as: 2021 + * Under source code control: 2021/03/06 21:07:31 + * File existed as early as: 2021 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -82,7 +82,7 @@ /* * In the spirit of: * - * https://github.com/git/git/blob/master/banned.h + * https://github.com/git/git/blob/master/banned.h * * we will ban the use of certain unsafe functions by turning * then into function calls that do not exist. @@ -157,22 +157,22 @@ /* * XXX - As of 2021, functions such as: * - * gmtime_s - * localtime_s - * ctime_s - * asctime_s + * gmtime_s + * localtime_s + * ctime_s + * asctime_s * * are not universal. We cannot yet ban the following * functions because we do not have a portable AND * widely available alternative. Therefore we just * have to be extra careful when using: * - * gmtime - * localtime - * ctime - * ctime_r - * asctime - * asctime_r + * gmtime + * localtime + * ctime + * ctime_r + * asctime + * asctime_r */ #endif /* !UNBAN */ diff --git a/blkcpy.c b/blkcpy.c index e4f484c..6b32deb 100644 --- a/blkcpy.c +++ b/blkcpy.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/04/18 20:41:26 - * File existed as early as: 1997 + * Under source code control: 1997/04/18 20:41:26 + * File existed as early as: 1997 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -37,237 +37,237 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* * copystod - copy num indexed items from source value to destination value * * given: - * ssi = source starting index - * num = number of items (octets or values) to be copied - * sdi = destination starting index + * ssi = source starting index + * num = number of items (octets or values) to be copied + * sdi = destination starting index * * returns: - * zero if successful, otherwise error-code number + * zero if successful, otherwise error-code number */ int copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi) { - BLOCK *sblk; - BLOCK *dblk; - bool noreloc; + BLOCK *sblk; + BLOCK *dblk; + bool noreloc; - sblk = NULL; - dblk = NULL; + sblk = NULL; + dblk = NULL; - /* - * check protections - */ - if (svp->v_subtype & V_NOCOPYFROM) - return E_COPY_13; - if (dvp->v_subtype & V_NOCOPYTO) - return E_COPY_14; - noreloc = ((dvp->v_subtype & V_NOREALLOC) != 0); + /* + * check protections + */ + if (svp->v_subtype & V_NOCOPYFROM) + return E_COPY_13; + if (dvp->v_subtype & V_NOCOPYTO) + return E_COPY_14; + noreloc = ((dvp->v_subtype & V_NOREALLOC) != 0); - /* - * determine/check source type - */ - switch(svp->v_type) { - case V_NBLOCK: - if (svp->v_nblock->subtype & V_NOCOPYFROM) - return E_COPY_15; - sblk = svp->v_nblock->blk; - if (sblk->data == NULL) - return E_COPY_08; - break; - case V_BLOCK: - sblk = svp->v_block; - break; - case V_STR: - case V_OCTET: - case V_NUM: - case V_FILE: - case V_MAT: - case V_LIST: - break; - default: - return E_COPY_09; - } + /* + * determine/check source type + */ + switch(svp->v_type) { + case V_NBLOCK: + if (svp->v_nblock->subtype & V_NOCOPYFROM) + return E_COPY_15; + sblk = svp->v_nblock->blk; + if (sblk->data == NULL) + return E_COPY_08; + break; + case V_BLOCK: + sblk = svp->v_block; + break; + case V_STR: + case V_OCTET: + case V_NUM: + case V_FILE: + case V_MAT: + case V_LIST: + break; + default: + return E_COPY_09; + } - /* - * determine/check destination type - */ - switch(dvp->v_type) { - case V_NBLOCK: - if (dvp->v_nblock->subtype & V_NOCOPYTO) - return E_COPY_16; - noreloc |=((dvp->v_nblock->subtype & V_NOREALLOC) != 0); - dblk = dvp->v_nblock->blk; - if (dblk->data == NULL) - return E_COPY_10; - break; - case V_BLOCK: - noreloc = ((dvp->v_subtype & V_NOREALLOC) != 0); - dblk = dvp->v_block; - break; - case V_STR: - case V_NUM: - case V_FILE: - case V_MAT: - case V_LIST: - break; - default: - return E_COPY_11; - } + /* + * determine/check destination type + */ + switch(dvp->v_type) { + case V_NBLOCK: + if (dvp->v_nblock->subtype & V_NOCOPYTO) + return E_COPY_16; + noreloc |=((dvp->v_nblock->subtype & V_NOREALLOC) != 0); + dblk = dvp->v_nblock->blk; + if (dblk->data == NULL) + return E_COPY_10; + break; + case V_BLOCK: + noreloc = ((dvp->v_subtype & V_NOREALLOC) != 0); + dblk = dvp->v_block; + break; + case V_STR: + case V_NUM: + case V_FILE: + case V_MAT: + case V_LIST: + break; + default: + return E_COPY_11; + } - /* - * copy based on source - */ - switch (svp->v_type) { - case V_BLOCK: - case V_NBLOCK: - /* - * copy from a block - */ - switch(dvp->v_type) { - case V_BLOCK: - case V_NBLOCK: - return copyblk2blk(sblk, ssi, num, dblk, dsi, noreloc); - case V_NUM: - { - NUMBER *n; /* modified number */ - int rt; /* return code */ + /* + * copy based on source + */ + switch (svp->v_type) { + case V_BLOCK: + case V_NBLOCK: + /* + * copy from a block + */ + switch(dvp->v_type) { + case V_BLOCK: + case V_NBLOCK: + return copyblk2blk(sblk, ssi, num, dblk, dsi, noreloc); + case V_NUM: + { + NUMBER *n; /* modified number */ + int rt; /* return code */ - /* copy to a number */ - rt = copyblk2num(sblk, ssi, num, dvp->v_num, dsi, &n); - if (rt == 0) { - qfree(dvp->v_num); - dvp->v_num = n; - } - return rt; - } - case V_FILE: - return copyblk2file(sblk, ssi, num, dvp->v_file, dsi); - case V_MAT: - return copyblk2mat(sblk, ssi, num, dvp->v_mat, dsi); - case V_STR: - return copyblk2str(sblk, ssi, num, dvp->v_str, dsi); - } - return E_COPY_12; + /* copy to a number */ + rt = copyblk2num(sblk, ssi, num, dvp->v_num, dsi, &n); + if (rt == 0) { + qfree(dvp->v_num); + dvp->v_num = n; + } + return rt; + } + case V_FILE: + return copyblk2file(sblk, ssi, num, dvp->v_file, dsi); + case V_MAT: + return copyblk2mat(sblk, ssi, num, dvp->v_mat, dsi); + case V_STR: + return copyblk2str(sblk, ssi, num, dvp->v_str, dsi); + } + return E_COPY_12; - case V_STR: - switch(dvp->v_type) { - case V_BLOCK: - case V_NBLOCK: - /* copy to a block */ - return copystr2blk(svp->v_str, ssi, num, dblk, dsi, - noreloc); - case V_FILE: - return copystr2file(svp->v_str, ssi, num, - dvp->v_file, dsi); - case V_STR: - return copystr2str(svp->v_str, ssi, num, dvp->v_str, - dsi); - } - return E_COPY_12; + case V_STR: + switch(dvp->v_type) { + case V_BLOCK: + case V_NBLOCK: + /* copy to a block */ + return copystr2blk(svp->v_str, ssi, num, dblk, dsi, + noreloc); + case V_FILE: + return copystr2file(svp->v_str, ssi, num, + dvp->v_file, dsi); + case V_STR: + return copystr2str(svp->v_str, ssi, num, dvp->v_str, + dsi); + } + return E_COPY_12; - case V_OCTET: - switch(dvp->v_type) { - case V_BLOCK: - case V_NBLOCK: - return copyostr2blk((char *) svp->v_octet, ssi, num, - dblk, dsi, noreloc); - case V_STR: - return copyostr2str((char *) svp->v_octet, ssi, num, - dvp->v_str, dsi); - } - return E_COPY_12; + case V_OCTET: + switch(dvp->v_type) { + case V_BLOCK: + case V_NBLOCK: + return copyostr2blk((char *) svp->v_octet, ssi, num, + dblk, dsi, noreloc); + case V_STR: + return copyostr2str((char *) svp->v_octet, ssi, num, + dvp->v_str, dsi); + } + return E_COPY_12; - case V_NUM: + case V_NUM: - /* - * copy from a number - */ - if (dblk != NULL) { - /* copy to a block */ - return copynum2blk(svp->v_num, ssi, num, dblk, - dsi, noreloc); - } - switch (dvp->v_type) { - case V_MAT: - /* copy to a matrix */ - return E_COPY_12; /* not yet - XXX */ - case V_LIST: - /* copy to a list */ - return E_COPY_12; /* not yet - XXX */ - } - break; - case V_FILE: + /* + * copy from a number + */ + if (dblk != NULL) { + /* copy to a block */ + return copynum2blk(svp->v_num, ssi, num, dblk, + dsi, noreloc); + } + switch (dvp->v_type) { + case V_MAT: + /* copy to a matrix */ + return E_COPY_12; /* not yet - XXX */ + case V_LIST: + /* copy to a list */ + return E_COPY_12; /* not yet - XXX */ + } + break; + case V_FILE: - /* - * copy from a file - */ - if (dblk != NULL) { - /* copy to a block */ - return copyfile2blk(svp->v_file, ssi, num, - dblk, dsi, noreloc); - } - switch (dvp->v_type) { - case V_NUM: - /* copy to a number */ - return E_COPY_12; /* not yet - XXX */ - } - break; + /* + * copy from a file + */ + if (dblk != NULL) { + /* copy to a block */ + return copyfile2blk(svp->v_file, ssi, num, + dblk, dsi, noreloc); + } + switch (dvp->v_type) { + case V_NUM: + /* copy to a number */ + return E_COPY_12; /* not yet - XXX */ + } + break; - case V_MAT: + case V_MAT: - /* - * copy from a matrix - */ - if (dblk != NULL) { - /* copy to a block */ - return copymat2blk(svp->v_mat, ssi, num, dblk, - dsi, noreloc); - } - switch (dvp->v_type) { - case V_MAT: - /* copy to a matrix */ - return copymat2mat(svp->v_mat, ssi, num, - dvp->v_mat, dsi); - case V_LIST: - /* copy to a list */ - return copymat2list(svp->v_mat, ssi, num, - dvp->v_list, dsi); - } - break; + /* + * copy from a matrix + */ + if (dblk != NULL) { + /* copy to a block */ + return copymat2blk(svp->v_mat, ssi, num, dblk, + dsi, noreloc); + } + switch (dvp->v_type) { + case V_MAT: + /* copy to a matrix */ + return copymat2mat(svp->v_mat, ssi, num, + dvp->v_mat, dsi); + case V_LIST: + /* copy to a list */ + return copymat2list(svp->v_mat, ssi, num, + dvp->v_list, dsi); + } + break; - case V_LIST: + case V_LIST: - /* - * copy from a list - */ - if (dblk != NULL) { - /* copy to a block */ - return E_COPY_12; /* not yet - XXX */ - } - switch (dvp->v_type) { - case V_MAT: - /* copy to a matrix */ - return copylist2mat(svp->v_list, ssi, num, - dvp->v_mat, dsi); - case V_LIST: - /* copy to a list */ - return copylist2list(svp->v_list, ssi, num, - dvp->v_list, dsi); - } - break; - } + /* + * copy from a list + */ + if (dblk != NULL) { + /* copy to a block */ + return E_COPY_12; /* not yet - XXX */ + } + switch (dvp->v_type) { + case V_MAT: + /* copy to a matrix */ + return copylist2mat(svp->v_list, ssi, num, + dvp->v_mat, dsi); + case V_LIST: + /* copy to a list */ + return copylist2list(svp->v_list, ssi, num, + dvp->v_list, dsi); + } + break; + } - /* - * unsupported copy combination - */ - return E_COPY_12; + /* + * unsupported copy combination + */ + return E_COPY_12; } @@ -277,45 +277,45 @@ copystod(VALUE *svp, long ssi, long num, VALUE *dvp, long dsi) int copymat2mat(MATRIX *smat, long ssi, long num, MATRIX *dmat, long dsi) { - long i; - VALUE *vp; - VALUE *vq; - VALUE *vtemp; - unsigned short subtype; + long i; + VALUE *vp; + VALUE *vq; + VALUE *vtemp; + unsigned short subtype; - if (ssi > smat->m_size) - return E_COPY_02; + if (ssi > smat->m_size) + return E_COPY_02; - if (num < 0) - num = smat->m_size - ssi; - if (ssi + num > smat->m_size) - return E_COPY_05; - if (num == 0) - return 0; - if (dsi < 0) - dsi = 0; - if (dsi + num > dmat->m_size) - return E_COPY_07; - vtemp = (VALUE *) malloc(num * sizeof(VALUE)); - if (vtemp == NULL) { - math_error("Out of memory for mat-to-mat copy"); - not_reached(); - } - vp = smat->m_table + ssi; - vq = vtemp; - i = num; - while (i-- > 0) - copyvalue(vp++, vq++); - vp = vtemp; - vq = dmat->m_table + dsi; - for (i = num; i > 0; i--, vp++, vq++) { - subtype = vq->v_subtype; - freevalue(vq); - *vq = *vp; - vq->v_subtype |= subtype; - } - free(vtemp); - return 0; + if (num < 0) + num = smat->m_size - ssi; + if (ssi + num > smat->m_size) + return E_COPY_05; + if (num == 0) + return 0; + if (dsi < 0) + dsi = 0; + if (dsi + num > dmat->m_size) + return E_COPY_07; + vtemp = (VALUE *) malloc(num * sizeof(VALUE)); + if (vtemp == NULL) { + math_error("Out of memory for mat-to-mat copy"); + not_reached(); + } + vp = smat->m_table + ssi; + vq = vtemp; + i = num; + while (i-- > 0) + copyvalue(vp++, vq++); + vp = vtemp; + vq = dmat->m_table + dsi; + for (i = num; i > 0; i--, vp++, vq++) { + subtype = vq->v_subtype; + freevalue(vq); + *vq = *vp; + vq->v_subtype |= subtype; + } + free(vtemp); + return 0; } @@ -325,49 +325,49 @@ copymat2mat(MATRIX *smat, long ssi, long num, MATRIX *dmat, long dsi) int copyblk2mat(BLOCK *blk, long ssi, long num, MATRIX *dmat, long dsi) { - OCTET *op; - VALUE *vp; - VALUE *vq; - VALUE *vtemp; - long i; - unsigned short subtype; + OCTET *op; + VALUE *vp; + VALUE *vq; + VALUE *vtemp; + long i; + unsigned short subtype; - if (ssi > blk->datalen) - return E_COPY_02; - if (num < 0) - num = blk->datalen - ssi; - if (ssi + num > blk->datalen) - return E_COPY_05; - if (num == 0) - return 0; - if (dsi < 0) - dsi = 0; - if (dsi + num > dmat->m_size) - return E_COPY_07; - op = blk->data + ssi; - vtemp = (VALUE *) malloc(num * sizeof(VALUE)); - if (vtemp == NULL) { - math_error("Out of memory for block-to-matrix copy"); - not_reached(); - } - vp = vtemp; - i = num; - while (i-- > 0) { - vp->v_type = V_NUM; - vp->v_subtype = V_NOSUBTYPE; - vp->v_num = itoq((long) *op++); - vp++; - } - vp = vtemp; - vq = dmat->m_table + dsi; - for (i = num; i > 0; i--, vp++, vq++) { - subtype = vq->v_subtype; - freevalue(vq); - *vq = *vp; - vq->v_subtype |= subtype; - } - free(vtemp); - return 0; + if (ssi > blk->datalen) + return E_COPY_02; + if (num < 0) + num = blk->datalen - ssi; + if (ssi + num > blk->datalen) + return E_COPY_05; + if (num == 0) + return 0; + if (dsi < 0) + dsi = 0; + if (dsi + num > dmat->m_size) + return E_COPY_07; + op = blk->data + ssi; + vtemp = (VALUE *) malloc(num * sizeof(VALUE)); + if (vtemp == NULL) { + math_error("Out of memory for block-to-matrix copy"); + not_reached(); + } + vp = vtemp; + i = num; + while (i-- > 0) { + vp->v_type = V_NUM; + vp->v_subtype = V_NOSUBTYPE; + vp->v_num = itoq((long) *op++); + vp++; + } + vp = vtemp; + vq = dmat->m_table + dsi; + for (i = num; i > 0; i--, vp++, vq++) { + subtype = vq->v_subtype; + freevalue(vq); + *vq = *vp; + vq->v_subtype |= subtype; + } + free(vtemp); + return 0; } @@ -376,47 +376,47 @@ copyblk2mat(BLOCK *blk, long ssi, long num, MATRIX *dmat, long dsi) */ int copymat2blk(MATRIX *smat, long ssi, long num, BLOCK *dblk, long dsi, - bool noreloc) + bool noreloc) { - long i; - long newlen; - long newsize; - USB8 *newdata; - VALUE *vp; - OCTET *op; + long i; + long newlen; + long newsize; + USB8 *newdata; + VALUE *vp; + OCTET *op; - if (ssi > smat->m_size) - return E_COPY_02; - if (num < 0) - num = smat->m_size - ssi; - if (num == 0) - return 0; - if (ssi + num > smat->m_size) - return E_COPY_05; - if (dsi < 0) - dsi = dblk->datalen; - newlen = dsi + num; - if (newlen <= 0) - return E_COPY_07; - if (newlen >= dblk->maxsize) { - if (noreloc) - return E_COPY_17; - newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk; - newdata = (USB8*) realloc(dblk->data, newsize); - if (newdata == NULL) { - math_error("Out of memory for matrix-to-block copy"); - not_reached(); - } - dblk->data = newdata; - dblk->maxsize = newsize; - } - vp = smat->m_table + ssi; - op = dblk->data + dsi; - for (i = num; i > 0; i--) - copy2octet(vp++, op++); - if (newlen > dblk->datalen) - dblk->datalen = newlen; - return 0; + if (ssi > smat->m_size) + return E_COPY_02; + if (num < 0) + num = smat->m_size - ssi; + if (num == 0) + return 0; + if (ssi + num > smat->m_size) + return E_COPY_05; + if (dsi < 0) + dsi = dblk->datalen; + newlen = dsi + num; + if (newlen <= 0) + return E_COPY_07; + if (newlen >= dblk->maxsize) { + if (noreloc) + return E_COPY_17; + newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk; + newdata = (USB8*) realloc(dblk->data, newsize); + if (newdata == NULL) { + math_error("Out of memory for matrix-to-block copy"); + not_reached(); + } + dblk->data = newdata; + dblk->maxsize = newsize; + } + vp = smat->m_table + ssi; + op = dblk->data + dsi; + for (i = num; i > 0; i--) + copy2octet(vp++, op++); + if (newlen > dblk->datalen) + dblk->datalen = newlen; + return 0; } @@ -426,47 +426,47 @@ copymat2blk(MATRIX *smat, long ssi, long num, BLOCK *dblk, long dsi, int copymat2list(MATRIX *smat, long ssi, long num, LIST *lp, long dsi) { - VALUE *vp; - VALUE *vq; - LISTELEM *ep; - VALUE *vtemp; - long i; - unsigned short subtype; + VALUE *vp; + VALUE *vq; + LISTELEM *ep; + VALUE *vtemp; + long i; + unsigned short subtype; - if (ssi > smat->m_size) - return E_COPY_02; - if (num < 0) - num = smat->m_size - ssi; - if (num == 0) - return 0; - if (ssi + num > smat->m_size) - return E_COPY_05; - if (dsi < 0) - dsi = 0; - if (dsi + num > lp->l_count) - return E_COPY_07; - vtemp = (VALUE *) malloc(num * sizeof(VALUE)); - if (vtemp == NULL) { - math_error("Out of memory for matrix-to-list copy"); - not_reached(); - } - vp = smat->m_table + ssi; - vq = vtemp; - i = num; - while (i-- > 0) - copyvalue(vp++, vq++); - vq = vtemp; - ep = listelement(lp, (long) dsi); - i = num; - while (i-- > 0) { - subtype = ep->e_value.v_subtype; - freevalue(&ep->e_value); - ep->e_value = *vq++; - ep->e_value.v_subtype |= subtype; - ep = ep->e_next; - } - free(vtemp); - return 0; + if (ssi > smat->m_size) + return E_COPY_02; + if (num < 0) + num = smat->m_size - ssi; + if (num == 0) + return 0; + if (ssi + num > smat->m_size) + return E_COPY_05; + if (dsi < 0) + dsi = 0; + if (dsi + num > lp->l_count) + return E_COPY_07; + vtemp = (VALUE *) malloc(num * sizeof(VALUE)); + if (vtemp == NULL) { + math_error("Out of memory for matrix-to-list copy"); + not_reached(); + } + vp = smat->m_table + ssi; + vq = vtemp; + i = num; + while (i-- > 0) + copyvalue(vp++, vq++); + vq = vtemp; + ep = listelement(lp, (long) dsi); + i = num; + while (i-- > 0) { + subtype = ep->e_value.v_subtype; + freevalue(&ep->e_value); + ep->e_value = *vq++; + ep->e_value.v_subtype |= subtype; + ep = ep->e_next; + } + free(vtemp); + return 0; } @@ -476,47 +476,47 @@ copymat2list(MATRIX *smat, long ssi, long num, LIST *lp, long dsi) int copylist2mat(LIST *lp, long ssi, long num, MATRIX *dmat, long dsi) { - VALUE *vp; - VALUE *vq; - LISTELEM *ep; - VALUE *vtemp; - long i; - unsigned short subtype; + VALUE *vp; + VALUE *vq; + LISTELEM *ep; + VALUE *vtemp; + long i; + unsigned short subtype; - if (ssi > lp->l_count) - return E_COPY_02; - if (num < 0) - num = lp->l_count - ssi; - if (num == 0) - return 0; - if (ssi + num > lp->l_count) - return E_COPY_05; - if (dsi < 0) - dsi = 0; - if (dsi + num > dmat->m_size) - return E_COPY_07; - vtemp = (VALUE *) malloc(num * sizeof(VALUE)); - if (vtemp == NULL) { - math_error("Out of memory for list-to-matrix copy"); - not_reached(); - } - ep = listelement(lp, (long) ssi); - vp = vtemp; - i = num; - while (i-- > 0) { - copyvalue(&ep->e_value, vp++); - ep = ep->e_next; - } - vp = vtemp; - vq = dmat->m_table + dsi; - for (i = num; i > 0; i--, vp++, vq++) { - subtype = vq->v_subtype; - freevalue(vq); - *vq = *vp; - vq->v_subtype |= subtype; - } - free(vtemp); - return 0; + if (ssi > lp->l_count) + return E_COPY_02; + if (num < 0) + num = lp->l_count - ssi; + if (num == 0) + return 0; + if (ssi + num > lp->l_count) + return E_COPY_05; + if (dsi < 0) + dsi = 0; + if (dsi + num > dmat->m_size) + return E_COPY_07; + vtemp = (VALUE *) malloc(num * sizeof(VALUE)); + if (vtemp == NULL) { + math_error("Out of memory for list-to-matrix copy"); + not_reached(); + } + ep = listelement(lp, (long) ssi); + vp = vtemp; + i = num; + while (i-- > 0) { + copyvalue(&ep->e_value, vp++); + ep = ep->e_next; + } + vp = vtemp; + vq = dmat->m_table + dsi; + for (i = num; i > 0; i--, vp++, vq++) { + subtype = vq->v_subtype; + freevalue(vq); + *vq = *vp; + vq->v_subtype |= subtype; + } + free(vtemp); + return 0; } @@ -526,49 +526,49 @@ copylist2mat(LIST *lp, long ssi, long num, MATRIX *dmat, long dsi) int copylist2list(LIST *slp, long ssi, long num, LIST *dlp, long dsi) { - long i; - LISTELEM *sep; - LISTELEM *dep; - VALUE *vtemp; - VALUE *vp; - unsigned short subtype; + long i; + LISTELEM *sep; + LISTELEM *dep; + VALUE *vtemp; + VALUE *vp; + unsigned short subtype; - if (ssi > slp->l_count) - return E_COPY_02; - if (num < 0) - num = slp->l_count - ssi; - if (num == 0) - return 0; - if (ssi + num > slp->l_count) - return E_COPY_05; - if (dsi < 0) - dsi = 0; - if (dsi + num > dlp->l_count) - return E_COPY_07; - vtemp = (VALUE *) malloc(num * sizeof(VALUE)); - if (vtemp == NULL) { - math_error("Out of memory for list-to-list copy"); - not_reached(); - } - sep = listelement(slp, (long) ssi); - vp = vtemp; - i = num; - while (i-- > 0) { - copyvalue(&sep->e_value, vp++); - sep = sep->e_next; - } - dep = listelement(dlp, (long) dsi); - vp = vtemp; - i = num; - while (i-- > 0) { - subtype = dep->e_value.v_subtype; - freevalue(&dep->e_value); - dep->e_value = *vp++; - dep->e_value.v_subtype |= subtype; - dep = dep->e_next; - } - free(vtemp); - return 0; + if (ssi > slp->l_count) + return E_COPY_02; + if (num < 0) + num = slp->l_count - ssi; + if (num == 0) + return 0; + if (ssi + num > slp->l_count) + return E_COPY_05; + if (dsi < 0) + dsi = 0; + if (dsi + num > dlp->l_count) + return E_COPY_07; + vtemp = (VALUE *) malloc(num * sizeof(VALUE)); + if (vtemp == NULL) { + math_error("Out of memory for list-to-list copy"); + not_reached(); + } + sep = listelement(slp, (long) ssi); + vp = vtemp; + i = num; + while (i-- > 0) { + copyvalue(&sep->e_value, vp++); + sep = sep->e_next; + } + dep = listelement(dlp, (long) dsi); + vp = vtemp; + i = num; + while (i-- > 0) { + subtype = dep->e_value.v_subtype; + freevalue(&dep->e_value); + dep->e_value = *vp++; + dep->e_value.v_subtype |= subtype; + dep = dep->e_next; + } + free(vtemp); + return 0; } @@ -578,34 +578,34 @@ copylist2list(LIST *slp, long ssi, long num, LIST *dlp, long dsi) int copyblk2file(BLOCK *sblk, long ssi, long num, FILEID id, long dsi) { - FILEIO *fiop; - FILE *fp; - long numw; + FILEIO *fiop; + FILE *fp; + long numw; - if (ssi > sblk->datalen) - return E_COPY_02; - if (num < 0) - num = sblk->datalen - ssi; - if (num == 0) - return 0; + if (ssi > sblk->datalen) + return E_COPY_02; + if (num < 0) + num = sblk->datalen - ssi; + if (num == 0) + return 0; - fiop = findid(id, true); - if (fiop == NULL) - return E_COPYF_1; - fp = fiop->fp; - if (id == 1 || id == 2) { - numw = idfputstr(id, (char *)sblk->data + ssi); /* XXX */ - return 0; - } - if (dsi >= 0) { - if (fseek(fp, dsi, 0)) - return E_COPYF_2; - } - numw = fwrite(sblk->data + ssi, 1, num, fp); - if (numw < num) - return E_COPYF_3; - fflush(fp); - return 0; + fiop = findid(id, true); + if (fiop == NULL) + return E_COPYF_1; + fp = fiop->fp; + if (id == 1 || id == 2) { + numw = idfputstr(id, (char *)sblk->data + ssi); /* XXX */ + return 0; + } + if (dsi >= 0) { + if (fseek(fp, dsi, 0)) + return E_COPYF_2; + } + numw = fwrite(sblk->data + ssi, 1, num, fp); + if (numw < num) + return E_COPYF_3; + fflush(fp); + return 0; } @@ -615,65 +615,65 @@ copyblk2file(BLOCK *sblk, long ssi, long num, FILEID id, long dsi) int copyfile2blk(FILEID id, long ssi, long num, BLOCK *dblk, long dsi, bool noreloc) { - FILEIO *fiop; - FILE *fp; - long numw; - ZVALUE fsize; - long filelen; - long newlen; - long newsize; - OCTET *newdata; + FILEIO *fiop; + FILE *fp; + long numw; + ZVALUE fsize; + long filelen; + long newlen; + long newsize; + OCTET *newdata; - if (id < 3) /* excludes copying from stdin */ - return E_COPYF_1; - fiop = findid(id, false); - if (fiop == NULL) - return E_COPYF_1; + if (id < 3) /* excludes copying from stdin */ + return E_COPYF_1; + fiop = findid(id, false); + if (fiop == NULL) + return E_COPYF_1; - fp = fiop->fp; + fp = fiop->fp; - if (get_open_siz(fp, &fsize)) - return E_COPYF_2; - if (zge31b(fsize)) { - zfree(fsize); - return E_COPY_05; - } - filelen = ztoi(fsize); - zfree(fsize); + if (get_open_siz(fp, &fsize)) + return E_COPYF_2; + if (zge31b(fsize)) { + zfree(fsize); + return E_COPY_05; + } + filelen = ztoi(fsize); + zfree(fsize); - if (ssi > filelen) - return E_COPY_02; - if (num < 0) - num = filelen - ssi; - if (num == 0) - return 0; - if (ssi + num > filelen) - return E_COPY_05; - if (fseek(fp, ssi, 0)) /* using system fseek XXX */ - return E_COPYF_2; - if (dsi < 0) - dsi = dblk->datalen; - newlen = dsi + num; - if (newlen <= 0) - return E_COPY_07; - if (newlen >= dblk->maxsize) { - if (noreloc) - return E_COPY_17; - newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk; - newdata = (USB8*) realloc(dblk->data, newsize); - if (newdata == NULL) { - math_error("Out of memory for block-to-block copy"); - not_reached(); - } - dblk->data = newdata; - dblk->maxsize = newsize; - } - numw = fread(dblk->data + dsi, 1, num, fp); - if (numw < num) - return E_COPYF_4; - if (newlen > dblk->datalen) - dblk->datalen = newlen; - return 0; + if (ssi > filelen) + return E_COPY_02; + if (num < 0) + num = filelen - ssi; + if (num == 0) + return 0; + if (ssi + num > filelen) + return E_COPY_05; + if (fseek(fp, ssi, 0)) /* using system fseek XXX */ + return E_COPYF_2; + if (dsi < 0) + dsi = dblk->datalen; + newlen = dsi + num; + if (newlen <= 0) + return E_COPY_07; + if (newlen >= dblk->maxsize) { + if (noreloc) + return E_COPY_17; + newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk; + newdata = (USB8*) realloc(dblk->data, newsize); + if (newdata == NULL) { + math_error("Out of memory for block-to-block copy"); + not_reached(); + } + dblk->data = newdata; + dblk->maxsize = newsize; + } + numw = fread(dblk->data + dsi, 1, num, fp); + if (numw < num) + return E_COPYF_4; + if (newlen > dblk->datalen) + dblk->datalen = newlen; + return 0; } @@ -683,38 +683,38 @@ copyfile2blk(FILEID id, long ssi, long num, BLOCK *dblk, long dsi, bool noreloc) int copystr2file(STRING *str, long ssi, long num, FILEID id, long dsi) { - long len; - FILEIO *fiop; - long numw; - FILE *fp; + long len; + FILEIO *fiop; + long numw; + FILE *fp; - len = str->s_len; + len = str->s_len; - if (ssi >= len) - return E_COPY_02; - if (num < 0) - num = len - ssi; - if (num <= 0) /* Nothing to be copied */ - return 0; - if (ssi + num > len) - return E_COPY_05; /* Insufficient memory in str */ - fiop = findid(id, true); - if (fiop == NULL) - return E_COPYF_1; - fp = fiop->fp; - if (id == 1 || id == 2) { - numw = idfputstr(id, str->s_str + ssi); /* XXX */ - return 0; - } - if (dsi >= 0) { - if (fseek(fp, dsi, 0)) - return E_COPYF_2; - } - numw = fwrite(str->s_str + ssi, 1, num, fp); - if (numw < num) - return E_COPYF_3; - fflush(fp); - return 0; + if (ssi >= len) + return E_COPY_02; + if (num < 0) + num = len - ssi; + if (num <= 0) /* Nothing to be copied */ + return 0; + if (ssi + num > len) + return E_COPY_05; /* Insufficient memory in str */ + fiop = findid(id, true); + if (fiop == NULL) + return E_COPYF_1; + fp = fiop->fp; + if (id == 1 || id == 2) { + numw = idfputstr(id, str->s_str + ssi); /* XXX */ + return 0; + } + if (dsi >= 0) { + if (fseek(fp, dsi, 0)) + return E_COPYF_2; + } + numw = fwrite(str->s_str + ssi, 1, num, fp); + if (numw < num) + return E_COPYF_3; + fflush(fp); + return 0; } @@ -723,41 +723,41 @@ copystr2file(STRING *str, long ssi, long num, FILEID id, long dsi) */ int copyblk2blk(BLOCK *sblk, long ssi, long num, BLOCK *dblk, long dsi, - bool noreloc) + bool noreloc) { - long newlen; - long newsize; - USB8 *newdata; + long newlen; + long newsize; + USB8 *newdata; - if (ssi > sblk->datalen) - return E_COPY_02; - if (num < 0) - num = sblk->datalen - ssi; - if (num == 0) /* Nothing to be copied */ - return 0; - if (ssi + num > sblk->datalen) - return E_COPY_05; - if (dsi < 0) - dsi = dblk->datalen; - newlen = dsi + num; - if (newlen <= 0) - return E_COPY_07; - if (newlen >= dblk->maxsize) { - if (noreloc) - return E_COPY_17; - newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk; - newdata = (USB8*) realloc(dblk->data, newsize); - if (newdata == NULL) { - math_error("Out of memory for block-to-block copy"); - not_reached(); - } - dblk->data = newdata; - dblk->maxsize = newsize; - } - memmove(dblk->data + dsi, sblk->data + ssi, num); - if (newlen > dblk->datalen) - dblk->datalen = newlen; - return 0; + if (ssi > sblk->datalen) + return E_COPY_02; + if (num < 0) + num = sblk->datalen - ssi; + if (num == 0) /* Nothing to be copied */ + return 0; + if (ssi + num > sblk->datalen) + return E_COPY_05; + if (dsi < 0) + dsi = dblk->datalen; + newlen = dsi + num; + if (newlen <= 0) + return E_COPY_07; + if (newlen >= dblk->maxsize) { + if (noreloc) + return E_COPY_17; + newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk; + newdata = (USB8*) realloc(dblk->data, newsize); + if (newdata == NULL) { + math_error("Out of memory for block-to-block copy"); + not_reached(); + } + dblk->data = newdata; + dblk->maxsize = newsize; + } + memmove(dblk->data + dsi, sblk->data + ssi, num); + if (newlen > dblk->datalen) + dblk->datalen = newlen; + return 0; } @@ -766,43 +766,43 @@ copyblk2blk(BLOCK *sblk, long ssi, long num, BLOCK *dblk, long dsi, */ int copystr2blk(STRING *str, long ssi, long num, BLOCK *dblk, long dsi, - bool noreloc) + bool noreloc) { - long len; - long newlen; - long newsize; - USB8 *newdata; + long len; + long newlen; + long newsize; + USB8 *newdata; - len = str->s_len; + len = str->s_len; - if (ssi >= len) - return E_COPY_02; - if (num < 0) - num = len - ssi; - if (num <= 0) /* Nothing to be copied */ - return 0; - if (dsi < 0) - dsi = dblk->datalen; - newlen = dsi + num + 1; - if (newlen <= 0) - return E_COPY_07; - if (newlen >= dblk->maxsize) { - if (noreloc) - return E_COPY_17; - newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk; - newdata = (USB8*) realloc(dblk->data, newsize); - if (newdata == NULL) { - math_error("Out of memory for string-to-block copy"); - not_reached(); - } - dblk->data = newdata; - dblk->maxsize = newsize; - } - memmove(dblk->data + dsi, str->s_str + ssi, num); - dblk->data[dsi + num] = '\0'; - if (newlen > dblk->datalen) - dblk->datalen = newlen; - return 0; + if (ssi >= len) + return E_COPY_02; + if (num < 0) + num = len - ssi; + if (num <= 0) /* Nothing to be copied */ + return 0; + if (dsi < 0) + dsi = dblk->datalen; + newlen = dsi + num + 1; + if (newlen <= 0) + return E_COPY_07; + if (newlen >= dblk->maxsize) { + if (noreloc) + return E_COPY_17; + newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk; + newdata = (USB8*) realloc(dblk->data, newsize); + if (newdata == NULL) { + math_error("Out of memory for string-to-block copy"); + not_reached(); + } + dblk->data = newdata; + dblk->maxsize = newsize; + } + memmove(dblk->data + dsi, str->s_str + ssi, num); + dblk->data[dsi + num] = '\0'; + if (newlen > dblk->datalen) + dblk->datalen = newlen; + return 0; } @@ -814,21 +814,21 @@ copystr2blk(STRING *str, long ssi, long num, BLOCK *dblk, long dsi, int copystr2str(STRING *sstr, long ssi, long num, STRING *dstr, long dsi) { - char *c, *c1; + char *c, *c1; - if (num < 0 || (size_t)(ssi + num) > sstr->s_len) - num = sstr->s_len - ssi; - if (num <= 0) - return 0; /* Nothing to be copied */ - if (dsi < 0) /* default destination index */ - dsi = 0; - if ((size_t)(dsi + num) > dstr->s_len) - num = dstr->s_len - dsi; - c1 = sstr->s_str + ssi; - c = dstr->s_str + dsi; - while (num-- > 0) - *c++ = *c1++; - return 0; + if (num < 0 || (size_t)(ssi + num) > sstr->s_len) + num = sstr->s_len - ssi; + if (num <= 0) + return 0; /* Nothing to be copied */ + if (dsi < 0) /* default destination index */ + dsi = 0; + if ((size_t)(dsi + num) > dstr->s_len) + num = dstr->s_len - dsi; + c1 = sstr->s_str + ssi; + c = dstr->s_str + dsi; + while (num-- > 0) + *c++ = *c1++; + return 0; } @@ -840,21 +840,21 @@ copystr2str(STRING *sstr, long ssi, long num, STRING *dstr, long dsi) int copyblk2str(BLOCK *sblk, long ssi, long num, STRING *dstr, long dsi) { - USB8 *c, *c1; + USB8 *c, *c1; - if (num < 0 || ssi + num > sblk->datalen) - num = sblk->datalen - ssi; - if (num <= 0) - return 0; /* Nothing to be copied */ - if (dsi < 0) /* default destination index */ - dsi = 0; - if ((size_t)(dsi + num) > dstr->s_len) - num = dstr->s_len - dsi; - c1 = sblk->data + ssi; - c = (USB8 *)dstr->s_str + dsi; - while (num-- > 0) - *c++ = *c1++; - return 0; + if (num < 0 || ssi + num > sblk->datalen) + num = sblk->datalen - ssi; + if (num <= 0) + return 0; /* Nothing to be copied */ + if (dsi < 0) /* default destination index */ + dsi = 0; + if ((size_t)(dsi + num) > dstr->s_len) + num = dstr->s_len - dsi; + c1 = sblk->data + ssi; + c = (USB8 *)dstr->s_str + dsi; + while (num-- > 0) + *c++ = *c1++; + return 0; } /* * copyostr2str - copy octet-specified string to string @@ -862,24 +862,24 @@ copyblk2str(BLOCK *sblk, long ssi, long num, STRING *dstr, long dsi) int copyostr2str(char *sstr, long ssi, long num, STRING *dstr, long dsi) { - size_t len; - char *c, *c1; + size_t len; + char *c, *c1; - len = strlen(sstr); + len = strlen(sstr); - if (num < 0 || (size_t)(ssi + num) > len) - num = len - ssi; - if (num <= 0) /* Nothing to be copied */ - return 0; - if (dsi < 0) - dsi = 0; /* Default destination index */ - if ((size_t)(dsi + num) > dstr->s_len) - num = dstr->s_len - dsi; - c1 = sstr + ssi; - c = dstr->s_str + dsi; - while (num-- > 0) - *c++ = *c1++; - return 0; + if (num < 0 || (size_t)(ssi + num) > len) + num = len - ssi; + if (num <= 0) /* Nothing to be copied */ + return 0; + if (dsi < 0) + dsi = 0; /* Default destination index */ + if ((size_t)(dsi + num) > dstr->s_len) + num = dstr->s_len - dsi; + c1 = sstr + ssi; + c = dstr->s_str + dsi; + while (num-- > 0) + *c++ = *c1++; + return 0; } @@ -889,40 +889,40 @@ copyostr2str(char *sstr, long ssi, long num, STRING *dstr, long dsi) int copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,bool noreloc) { - size_t len; - size_t newlen; - size_t newsize; - USB8 *newdata; + size_t len; + size_t newlen; + size_t newsize; + USB8 *newdata; - len = strlen(str) + 1; + len = strlen(str) + 1; - if (ssi > 0 && (size_t)ssi > len) - return E_COPY_02; - if (num < 0 || (size_t)(ssi + num) > len) - num = len - ssi; - if (num <= 0) /* Nothing to be copied */ - return 0; - if (dsi < 0) - dsi = dblk->datalen; /* Default destination index */ - newlen = dsi + num; - if (newlen <= 0) - return E_COPY_07; - if (newlen >= (size_t)dblk->maxsize) { - if (noreloc) - return E_COPY_17; - newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk; - newdata = (USB8*) realloc(dblk->data, newsize); - if (newdata == NULL) { - math_error("Out of memory for string-to-block copy"); - not_reached(); - } - dblk->data = newdata; - dblk->maxsize = newsize; - } - memmove(dblk->data + dsi, str + ssi, num); - if (newlen > (size_t)dblk->datalen) - dblk->datalen = newlen; - return 0; + if (ssi > 0 && (size_t)ssi > len) + return E_COPY_02; + if (num < 0 || (size_t)(ssi + num) > len) + num = len - ssi; + if (num <= 0) /* Nothing to be copied */ + return 0; + if (dsi < 0) + dsi = dblk->datalen; /* Default destination index */ + newlen = dsi + num; + if (newlen <= 0) + return E_COPY_07; + if (newlen >= (size_t)dblk->maxsize) { + if (noreloc) + return E_COPY_17; + newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk; + newdata = (USB8*) realloc(dblk->data, newsize); + if (newdata == NULL) { + math_error("Out of memory for string-to-block copy"); + not_reached(); + } + dblk->data = newdata; + dblk->maxsize = newsize; + } + memmove(dblk->data + dsi, str + ssi, num); + if (newlen > (size_t)dblk->datalen) + dblk->datalen = newlen; + return 0; } #if !defined(HAVE_MEMMOVE) /* @@ -931,53 +931,53 @@ copyostr2blk(char *str,long ssi,long num,BLOCK *dblk,long dsi,bool noreloc) * Copying between objects that overlap will take place correctly. * * given: - * s1 destination - * s2 source - * n octet count + * s1 destination + * s2 source + * n octet count * * returns: - * s1 + * s1 */ void * memmove(void *s1, CONST void *s2, MEMMOVE_SIZE_T n) { - /* - * firewall - */ - if (s1 == NULL || s2 == NULL) { - math_error("bogus memmove NULL ptr"); - not_reached(); - } - if (n <= 0) { - /* neg or 0 count does nothing */ - return s1; - } - if ((char *)s1 == (char *)s2) { - /* copy to same location does nothing */ - return s1; - } + /* + * firewall + */ + if (s1 == NULL || s2 == NULL) { + math_error("bogus memmove NULL ptr"); + not_reached(); + } + if (n <= 0) { + /* neg or 0 count does nothing */ + return s1; + } + if ((char *)s1 == (char *)s2) { + /* copy to same location does nothing */ + return s1; + } - /* - * determine if we need to deal with overlap copy - */ - if ((char *)s1 > (char *)s2 && (char *)s1 < (char *)s2+n) { + /* + * determine if we need to deal with overlap copy + */ + if ((char *)s1 > (char *)s2 && (char *)s1 < (char *)s2+n) { - /* - * we have to copy backwards ... slowly - */ - while (n-- > 0) { - ((char *)s1)[n] = ((char *)s2)[n]; - } + /* + * we have to copy backwards ... slowly + */ + while (n-- > 0) { + ((char *)s1)[n] = ((char *)s2)[n]; + } - } else { + } else { - /* - * safe ... no overlap problems - */ - (void) memcpy(s1, s2, n); + /* + * safe ... no overlap problems + */ + (void) memcpy(s1, s2, n); - } - return s1; + } + return s1; } #endif @@ -987,50 +987,50 @@ memmove(void *s1, CONST void *s2, MEMMOVE_SIZE_T n) */ int copynum2blk(NUMBER *snum, long ssi, long num, BLOCK *dblk, long dsi, - bool noreloc) + bool noreloc) { - size_t newlen; - size_t newsize; - USB8 *newdata; + size_t newlen; + size_t newsize; + USB8 *newdata; #if CALC_BYTE_ORDER == BIG_ENDIAN - ZVALUE *swnum; /* byte swapped numerator */ + ZVALUE *swnum; /* byte swapped numerator */ #endif - if (ssi > snum->num.len) - return E_COPY_02; - if (num < 0) - num = snum->num.len - ssi; - if (num == 0) /* Nothing to be copied */ - return 0; - if (ssi + num > snum->num.len) - return E_COPY_05; - if (dsi < 0) - dsi = dblk->datalen; - newlen = dsi + (num*sizeof(HALF)); - if (newlen <= 0) - return E_COPY_07; - if (newlen >= (size_t)dblk->maxsize) { - if (noreloc) - return E_COPY_17; - newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk; - newdata = (USB8*) realloc(dblk->data, newsize); - if (newdata == NULL) { - math_error("Out of memory for num-to-block copy"); - not_reached(); - } - dblk->data = newdata; - dblk->maxsize = newsize; - } + if (ssi > snum->num.len) + return E_COPY_02; + if (num < 0) + num = snum->num.len - ssi; + if (num == 0) /* Nothing to be copied */ + return 0; + if (ssi + num > snum->num.len) + return E_COPY_05; + if (dsi < 0) + dsi = dblk->datalen; + newlen = dsi + (num*sizeof(HALF)); + if (newlen <= 0) + return E_COPY_07; + if (newlen >= (size_t)dblk->maxsize) { + if (noreloc) + return E_COPY_17; + newsize = (1 + newlen/dblk->blkchunk) * dblk->blkchunk; + newdata = (USB8*) realloc(dblk->data, newsize); + if (newdata == NULL) { + math_error("Out of memory for num-to-block copy"); + not_reached(); + } + dblk->data = newdata; + dblk->maxsize = newsize; + } #if CALC_BYTE_ORDER == LITTLE_ENDIAN - memmove(dblk->data+dsi, (char *)(snum->num.v+ssi), num*sizeof(HALF)); + memmove(dblk->data+dsi, (char *)(snum->num.v+ssi), num*sizeof(HALF)); #else - swnum = swap_b8_in_ZVALUE(NULL, &(snum->num), false); - memmove(dblk->data+dsi, (char *)(swnum->v+ssi), num*sizeof(HALF)); - zfree(*swnum); + swnum = swap_b8_in_ZVALUE(NULL, &(snum->num), false); + memmove(dblk->data+dsi, (char *)(swnum->v+ssi), num*sizeof(HALF)); + zfree(*swnum); #endif - if (newlen > (size_t)dblk->datalen) - dblk->datalen = newlen; - return 0; + if (newlen > (size_t)dblk->datalen) + dblk->datalen = newlen; + return 0; } @@ -1039,75 +1039,75 @@ copynum2blk(NUMBER *snum, long ssi, long num, BLOCK *dblk, long dsi, */ int copyblk2num(BLOCK *sblk, long ssi, long num, NUMBER *dnum, long dsi, - NUMBER **res) + NUMBER **res) { - size_t newlen; - NUMBER *ret; /* cloned and modified numerator */ + size_t newlen; + NUMBER *ret; /* cloned and modified numerator */ #if CALC_BYTE_ORDER == BIG_ENDIAN - HALF *swapped; /* byte swapped input data */ - unsigned long halflen; /* length of the input rounded up to HALFs */ - HALF *h; /* copy byteswap pointer */ - unsigned long i; + HALF *swapped; /* byte swapped input data */ + unsigned long halflen; /* length of the input rounded up to HALFs */ + HALF *h; /* copy byteswap pointer */ + unsigned long i; #endif - if (ssi > sblk->datalen) - return E_COPY_02; - if (num < 0) - num = sblk->datalen - ssi; - if (num == 0) /* Nothing to be copied */ - return 0; - if (ssi + num > sblk->datalen) - return E_COPY_05; - if (dsi < 0) - dsi = dnum->num.len; - newlen = dsi + ((num+sizeof(HALF)-1)/sizeof(HALF)); - if (newlen <= 0) - return E_COPY_07; + if (ssi > sblk->datalen) + return E_COPY_02; + if (num < 0) + num = sblk->datalen - ssi; + if (num == 0) /* Nothing to be copied */ + return 0; + if (ssi + num > sblk->datalen) + return E_COPY_05; + if (dsi < 0) + dsi = dnum->num.len; + newlen = dsi + ((num+sizeof(HALF)-1)/sizeof(HALF)); + if (newlen <= 0) + return E_COPY_07; - /* quasi-clone the numerator to the new size */ - ret = qalloc(); - ret->num.sign = dnum->num.sign; - ret->num.v = alloc(newlen); - ret->num.len = newlen; - /* ensure that any trailing octets will be zero filled */ - ret->num.v[newlen-1] = 0; - zcopyval(dnum->num, ret->num); - if (!zisunit(ret->den)) { - ret->den.len = dnum->den.len; - ret->den.v = alloc(dnum->den.len); - zcopyval(dnum->den, ret->den); - } + /* quasi-clone the numerator to the new size */ + ret = qalloc(); + ret->num.sign = dnum->num.sign; + ret->num.v = alloc(newlen); + ret->num.len = newlen; + /* ensure that any trailing octets will be zero filled */ + ret->num.v[newlen-1] = 0; + zcopyval(dnum->num, ret->num); + if (!zisunit(ret->den)) { + ret->den.len = dnum->den.len; + ret->den.v = alloc(dnum->den.len); + zcopyval(dnum->den, ret->den); + } - /* move the data */ + /* move the data */ #if CALC_BYTE_ORDER == LITTLE_ENDIAN - memmove((char *)(ret->num.v + dsi), sblk->data + ssi, num); + memmove((char *)(ret->num.v + dsi), sblk->data + ssi, num); #else - /* form a HALF aligned copy of the input */ - halflen = (num+sizeof(HALF)-1) / sizeof(HALF); - swapped = (HALF *)malloc(halflen * sizeof(HALF)); - if (swapped == NULL) { - math_error("Out of memory for block-to-num copy"); - not_reached(); - } - /* ensure that any trailing octets will be zero filled */ - swapped[halflen-1] = 0; - memcpy(swapped, sblk->data + ssi, num); - /* byte swap the copy of the input */ - for (i=0, h=swapped; i < halflen; ++i, ++h) { - SWAP_B8_IN_HALF(h, h); - } - /* copy over whole byte-swapped HALFs */ - memcpy((char *)(ret->num.v + dsi), swapped, - (num/sizeof(HALF))*sizeof(HALF)); - /* copy over any octets in the last partial HALF */ - i = num % sizeof(HALF); - if (i != 0) { - memcpy((char *)(ret->num.v + dsi)+num-i, - (char *)swapped + num-i, i); - } - free(swapped); + /* form a HALF aligned copy of the input */ + halflen = (num+sizeof(HALF)-1) / sizeof(HALF); + swapped = (HALF *)malloc(halflen * sizeof(HALF)); + if (swapped == NULL) { + math_error("Out of memory for block-to-num copy"); + not_reached(); + } + /* ensure that any trailing octets will be zero filled */ + swapped[halflen-1] = 0; + memcpy(swapped, sblk->data + ssi, num); + /* byte swap the copy of the input */ + for (i=0, h=swapped; i < halflen; ++i, ++h) { + SWAP_B8_IN_HALF(h, h); + } + /* copy over whole byte-swapped HALFs */ + memcpy((char *)(ret->num.v + dsi), swapped, + (num/sizeof(HALF))*sizeof(HALF)); + /* copy over any octets in the last partial HALF */ + i = num % sizeof(HALF); + if (i != 0) { + memcpy((char *)(ret->num.v + dsi)+num-i, + (char *)swapped + num-i, i); + } + free(swapped); #endif - /* save new number */ - *res = ret; - return 0; + /* save new number */ + *res = ret; + return 0; } diff --git a/blkcpy.h b/blkcpy.h index 4f8a0ac..b2d3d9a 100644 --- a/blkcpy.h +++ b/blkcpy.h @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/04/18 20:41:25 - * File existed as early as: 1997 + * Under source code control: 1997/04/18 20:41:25 + * File existed as early as: 1997 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ diff --git a/block.c b/block.c index 463384c..9283682 100644 --- a/block.c +++ b/block.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,11 +19,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/02/27 00:29:40 - * File existed as early as: 1997 + * Under source code control: 1997/02/27 00:29:40 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -42,7 +42,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ #define NBLOCKCHUNK 16 @@ -61,55 +61,55 @@ S_FUNC void blkchk(BLOCK*); * blkalloc - allocate a block * * given: - * len - initial memory length of the block - * type - BLK_TYPE_XYZ - * chunk - allocation chunk size + * len - initial memory length of the block + * type - BLK_TYPE_XYZ + * chunk - allocation chunk size * * returns: - * pointer to a newly allocated BLOCK + * pointer to a newly allocated BLOCK */ BLOCK * blkalloc(int len, int chunk) { - BLOCK *nblk; /* new block allocated */ + BLOCK *nblk; /* new block allocated */ - /* - * firewall - */ - if (len < 0) - len = 0; - if (chunk <= 0) - chunk = BLK_CHUNKSIZE; + /* + * firewall + */ + if (len < 0) + len = 0; + if (chunk <= 0) + chunk = BLK_CHUNKSIZE; - /* - * allocate BLOCK - */ - nblk = (BLOCK *)malloc(sizeof(BLOCK)); - if (nblk == NULL) { - math_error("cannot allocate block"); - not_reached(); - } + /* + * allocate BLOCK + */ + nblk = (BLOCK *)malloc(sizeof(BLOCK)); + if (nblk == NULL) { + math_error("cannot allocate block"); + not_reached(); + } - /* - * initialize BLOCK - */ - nblk->blkchunk = chunk; - nblk->maxsize = ((len+chunk)/chunk)*chunk; - nblk->data = (USB8*)malloc(nblk->maxsize); - if (nblk->data == NULL) { - math_error("cannot allocate block data storage"); - not_reached(); - } - memset(nblk->data, 0, nblk->maxsize); - nblk->datalen = len; + /* + * initialize BLOCK + */ + nblk->blkchunk = chunk; + nblk->maxsize = ((len+chunk)/chunk)*chunk; + nblk->data = (USB8*)malloc(nblk->maxsize); + if (nblk->data == NULL) { + math_error("cannot allocate block data storage"); + not_reached(); + } + memset(nblk->data, 0, nblk->maxsize); + nblk->datalen = len; - /* - * return BLOCK - */ - if (conf->calc_debug & CALCDBG_BLOCK) { - blkchk(nblk); - } - return nblk; + /* + * return BLOCK + */ + if (conf->calc_debug & CALCDBG_BLOCK) { + blkchk(nblk); + } + return nblk; } @@ -120,85 +120,85 @@ blkalloc(int len, int chunk) * is what is called to free block storage. * * given: - * blk - the block to free + * blk - the block to free */ void blk_free(BLOCK *blk) { - /* free if non-NULL */ - if (blk != NULL) { + /* free if non-NULL */ + if (blk != NULL) { - /* free data storage */ - if (blk->data != NULL) { - free(blk->data); - } + /* free data storage */ + if (blk->data != NULL) { + free(blk->data); + } - /* free the block */ - free(blk); - } - return; + /* free the block */ + free(blk); + } + return; } /* * blkchk - check the sanity of a block * - * These checks should never fail if calc is working correctly. During + * These checks should never fail if calc is working correctly. During * debug time, we plan to call this function often. Once we are satisfied, * we will normally call this code only in a few places. * * If "calc_debug" has the bit corresponding to CALCDBG_BLOCK set, this * function is called during execution of the following builtins: * - * alloc(), realloc(), free() + * alloc(), realloc(), free() * * given: - * blk - the BLOCK to check + * blk - the BLOCK to check * * returns: - * if all is OK, otherwise math_error() is called and this - * function does not return + * if all is OK, otherwise math_error() is called and this + * function does not return */ S_FUNC void blkchk(BLOCK *blk) { - /* - * firewall - general sanity check - */ - if ((conf->calc_debug & CALCDBG_BLOCK) == 0) { - /* do nothing when debugging is disabled */ - return; - } - if (blk == NULL) { - math_error("internal: blk ptr is NULL"); - not_reached(); - } + /* + * firewall - general sanity check + */ + if ((conf->calc_debug & CALCDBG_BLOCK) == 0) { + /* do nothing when debugging is disabled */ + return; + } + if (blk == NULL) { + math_error("internal: blk ptr is NULL"); + not_reached(); + } - /* - * pointers must not be NULL - */ - if (blk->data == NULL) { - math_error("internal: blk->data ptr is NULL"); - not_reached(); - } + /* + * pointers must not be NULL + */ + if (blk->data == NULL) { + math_error("internal: blk->data ptr is NULL"); + not_reached(); + } - /* - * check data lengths - */ - if (blk->datalen < 0) { - math_error("internal: blk->datalen < 0"); - not_reached(); - } + /* + * check data lengths + */ + if (blk->datalen < 0) { + math_error("internal: blk->datalen < 0"); + not_reached(); + } - /* - * check the datalen and datalen2 values - */ - if (blk->datalen < 0) { - math_error("internal: blk->datalen < 0"); - not_reached(); - } - return; + /* + * check the datalen and datalen2 values + */ + if (blk->datalen < 0) { + math_error("internal: blk->datalen < 0"); + not_reached(); + } + return; } @@ -207,173 +207,173 @@ blkchk(BLOCK *blk) * * Reallocation of a block can change several aspects of a block. * - * It can change the much data it holds or can hold. + * It can change the much data it holds or can hold. * - * It can change the memory footprint (in terms of - * how much storage is malloced for current or future use). + * It can change the memory footprint (in terms of + * how much storage is malloced for current or future use). * - * It can change the chunk size used to grow malloced size - * as the data size grows. + * It can change the chunk size used to grow malloced size + * as the data size grows. * * Each of the len and chunksize may be kept the same. * * given: - * blk - old BLOCK to reallocate - * newlen - how much data the block holds - * newchunk - allocation chunk size (<0 ==> no change, 0 == default) + * blk - old BLOCK to reallocate + * newlen - how much data the block holds + * newchunk - allocation chunk size (<0 ==> no change, 0 == default) */ BLOCK * blkrealloc(BLOCK *blk, int newlen, int newchunk) { - USB8 *nblk; /* realloced storage */ - int newmax; /* new maximum stoage size */ + USB8 *nblk; /* realloced storage */ + int newmax; /* new maximum stoage size */ - /* - * firewall - */ - if (conf->calc_debug & CALCDBG_BLOCK) { - blkchk(blk); - } + /* + * firewall + */ + if (conf->calc_debug & CALCDBG_BLOCK) { + blkchk(blk); + } - /* - * process args - */ - /* newlen < 0 means do not change the length */ - if (newlen < 0) { - newlen = blk->datalen; - } - /* newchunk <= 0 means do not change the chunk size */ - if (newchunk < 0) { - newchunk = blk->blkchunk; - } else if (newchunk == 0) { - newchunk = BLK_CHUNKSIZE; - } + /* + * process args + */ + /* newlen < 0 means do not change the length */ + if (newlen < 0) { + newlen = blk->datalen; + } + /* newchunk <= 0 means do not change the chunk size */ + if (newchunk < 0) { + newchunk = blk->blkchunk; + } else if (newchunk == 0) { + newchunk = BLK_CHUNKSIZE; + } - /* - * reallocate storage if we have a different allocation size - */ - newmax = ((newlen+newchunk)/newchunk)*newchunk; - if (newmax != blk->maxsize) { + /* + * reallocate storage if we have a different allocation size + */ + newmax = ((newlen+newchunk)/newchunk)*newchunk; + if (newmax != blk->maxsize) { - /* reallocate new storage */ - nblk = (USB8*)realloc(blk->data, newmax); - if (nblk == NULL) { - math_error("cannot reallocate block storage"); - not_reached(); - } + /* reallocate new storage */ + nblk = (USB8*)realloc(blk->data, newmax); + if (nblk == NULL) { + math_error("cannot reallocate block storage"); + not_reached(); + } - /* clear any new storage */ - if (newmax > blk->maxsize) { - memset(nblk+blk->maxsize, 0, (newmax-blk->maxsize)); - } - blk->maxsize = newmax; + /* clear any new storage */ + if (newmax > blk->maxsize) { + memset(nblk+blk->maxsize, 0, (newmax-blk->maxsize)); + } + blk->maxsize = newmax; - /* restore the data pointers */ - blk->data = nblk; - } + /* restore the data pointers */ + blk->data = nblk; + } - /* - * deal the case of a newlen == 0 early and return - */ - if (newlen == 0) { + /* + * deal the case of a newlen == 0 early and return + */ + if (newlen == 0) { - /* - * setup the empty buffer - * - * We know that newtype is not circular since we force - * newlen to be at least 1 (because circular blocks - * always have at least one unused octet). - */ - if (blk->datalen < blk->maxsize) { - memset(blk->data, 0, blk->datalen); - } else { - memset(blk->data, 0, blk->maxsize); - } - blk->datalen = 0; - if (conf->calc_debug & CALCDBG_BLOCK) { - blkchk(blk); - } - return blk; - } + /* + * setup the empty buffer + * + * We know that newtype is not circular since we force + * newlen to be at least 1 (because circular blocks + * always have at least one unused octet). + */ + if (blk->datalen < blk->maxsize) { + memset(blk->data, 0, blk->datalen); + } else { + memset(blk->data, 0, blk->maxsize); + } + blk->datalen = 0; + if (conf->calc_debug & CALCDBG_BLOCK) { + blkchk(blk); + } + return blk; + } - /* - * Set the data length - * - * We also know that the new block is not empty since we have - * already dealt with that case above. - * - * After this section of code, limit and datalen will be - * correct in terms of the new type. - */ - if (newlen > blk->datalen) { + /* + * Set the data length + * + * We also know that the new block is not empty since we have + * already dealt with that case above. + * + * After this section of code, limit and datalen will be + * correct in terms of the new type. + */ + if (newlen > blk->datalen) { - /* there is new storage, clear it */ - memset(blk->data + blk->datalen, 0, newlen-blk->datalen); - /* growing storage for blocks grows the data */ - blk->datalen = newlen; + /* there is new storage, clear it */ + memset(blk->data + blk->datalen, 0, newlen-blk->datalen); + /* growing storage for blocks grows the data */ + blk->datalen = newlen; - } else if (newlen <= blk->datalen) { + } else if (newlen <= blk->datalen) { - /* the block will be full */ - blk->datalen = newlen; - } + /* the block will be full */ + blk->datalen = newlen; + } - /* - * return realloced type - */ - if (conf->calc_debug & CALCDBG_BLOCK) { - blkchk(blk); - } - return blk; + /* + * return realloced type + */ + if (conf->calc_debug & CALCDBG_BLOCK) { + blkchk(blk); + } + return blk; } /* * blktrunc - truncate a BLOCK down to a minimal fixed block * - * NOTE: THIS IS NOT THE INTERNAL CALC FREE FUNCTION!! This + * NOTE: THIS IS NOT THE INTERNAL CALC FREE FUNCTION!! This * is what blktrunc() builtin calls to reduce storage of a block * down to an absolute minimum. * * This actually forms a zero length fixed block with a chunk of 1. * * given: - * blk - the BLOCK to shrink + * blk - the BLOCK to shrink * * returns: - * pointer to a newly allocated BLOCK + * pointer to a newly allocated BLOCK */ void blktrunc(BLOCK *blk) { - /* - * firewall - */ - if (conf->calc_debug & CALCDBG_BLOCK) { - blkchk(blk); - } + /* + * firewall + */ + if (conf->calc_debug & CALCDBG_BLOCK) { + blkchk(blk); + } - /* - * free the old storage - */ - free(blk->data); + /* + * free the old storage + */ + free(blk->data); - /* - * setup as a zero length fixed block - */ - blk->blkchunk = 1; - blk->maxsize = 1; - blk->datalen = 0; - blk->data = (USB8*)malloc(1); - if (blk->data == NULL) { - math_error("cannot allocate truncated block storage"); - not_reached(); - } - blk->data[0] = (USB8)0; - if (conf->calc_debug & CALCDBG_BLOCK) { - blkchk(blk); - } - return; + /* + * setup as a zero length fixed block + */ + blk->blkchunk = 1; + blk->maxsize = 1; + blk->datalen = 0; + blk->data = (USB8*)malloc(1); + if (blk->data == NULL) { + math_error("cannot allocate truncated block storage"); + not_reached(); + } + blk->data[0] = (USB8)0; + if (conf->calc_debug & CALCDBG_BLOCK) { + blkchk(blk); + } + return; } @@ -381,40 +381,40 @@ blktrunc(BLOCK *blk) * blk_copy - copy a block * * given: - * blk - the block to copy + * blk - the block to copy * * returns: - * pointer to copy of blk + * pointer to copy of blk */ BLOCK * blk_copy(BLOCK *blk) { - BLOCK *nblk; /* copy of blk */ + BLOCK *nblk; /* copy of blk */ - /* - * malloc new block - */ - nblk = (BLOCK *)malloc(sizeof(BLOCK)); - if (nblk == NULL) { - math_error("blk_copy: cannot malloc BLOCK"); - not_reached(); - } + /* + * malloc new block + */ + nblk = (BLOCK *)malloc(sizeof(BLOCK)); + if (nblk == NULL) { + math_error("blk_copy: cannot malloc BLOCK"); + not_reached(); + } - /* - * duplicate most of the block - */ - *nblk = *blk; + /* + * duplicate most of the block + */ + *nblk = *blk; - /* - * duplicate block data - */ - nblk->data = (USB8 *)malloc(blk->maxsize); - if (nblk->data == NULL) { - math_error("blk_copy: cannot duplicate block data"); - not_reached(); - } - memcpy(nblk->data, blk->data, blk->maxsize); - return nblk; + /* + * duplicate block data + */ + nblk->data = (USB8 *)malloc(blk->maxsize); + if (nblk->data == NULL) { + math_error("blk_copy: cannot duplicate block data"); + not_reached(); + } + memcpy(nblk->data, blk->data, blk->maxsize); + return nblk; } @@ -422,50 +422,50 @@ blk_copy(BLOCK *blk) * blk_cmp - compare blocks * * given: - * a first BLOCK - * b second BLOCK + * a first BLOCK + * b second BLOCK * * returns: - * true => BLOCKs are different - * false => BLOCKs are the same + * true => BLOCKs are different + * false => BLOCKs are the same */ int blk_cmp(BLOCK *a, BLOCK *b) { - /* - * firewall and quick check - */ - if (a == b) { - /* pointers to the same object */ - return false; - } - if (a == NULL || b == NULL) { - /* one pointer is NULL, so they differ */ - return true; - } + /* + * firewall and quick check + */ + if (a == b) { + /* pointers to the same object */ + return false; + } + if (a == NULL || b == NULL) { + /* one pointer is NULL, so they differ */ + return true; + } - /* - * compare lengths - */ - if (a->datalen != b->datalen) { - /* different lengths are different */ - return true; - } + /* + * compare lengths + */ + if (a->datalen != b->datalen) { + /* different lengths are different */ + return true; + } - /* - * compare the section - * - * We have the same lengths and types, so compare the data sections. - */ - if (memcmp(a->data, b->data, a->datalen) != 0) { - /* different sections are different */ - return true; - } + /* + * compare the section + * + * We have the same lengths and types, so compare the data sections. + */ + if (memcmp(a->data, b->data, a->datalen) != 0) { + /* different sections are different */ + return true; + } - /* - * the blocks are the same - */ - return false; + /* + * the blocks are the same + */ + return false; } @@ -477,23 +477,23 @@ blk_cmp(BLOCK *a, BLOCK *b) void blk_print(BLOCK *blk) { - long i; - bool havetail; - USB8 *ptr; + long i; + bool havetail; + USB8 *ptr; - /* XXX - should 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", - (int)blk->blkchunk, (int)blk->maxsize, (int)blk->datalen); - i = blk->datalen; - havetail = (i > 30); - if (havetail) - i = 30; - ptr = blk->data; - while (i-- > 0) - printf("%02x", *ptr++); - if (havetail) - printf("..."); + printf("chunksize = %d, maxsize = %d, datalen = %d\n\t", + (int)blk->blkchunk, (int)blk->maxsize, (int)blk->datalen); + i = blk->datalen; + havetail = (i > 30); + if (havetail) + i = 30; + ptr = blk->data; + while (i-- > 0) + printf("%02x", *ptr++); + if (havetail) + printf("..."); } @@ -504,19 +504,19 @@ blk_print(BLOCK *blk) void nblock_print(NBLOCK *nblk) { - BLOCK *blk; + BLOCK *blk; - /* XXX - use the config parameters for better print control */ + /* XXX - use the config parameters for better print control */ - blk = nblk->blk; - printf("block %d: %s\n\t", nblk->id, nblk->name); - if (blk->data == NULL) { - printf("chunksize = %d, maxsize = %d, datalen = %d\n\t", - (int)blk->blkchunk, (int)blk->maxsize, (int)blk->datalen); - printf("NULL"); - } else { - blk_print(blk); - } + blk = nblk->blk; + printf("block %d: %s\n\t", nblk->id, nblk->name); + if (blk->data == NULL) { + printf("chunksize = %d, maxsize = %d, datalen = %d\n\t", + (int)blk->blkchunk, (int)blk->maxsize, (int)blk->datalen); + printf("NULL"); + } else { + blk_print(blk); + } } @@ -531,47 +531,47 @@ nblock_print(NBLOCK *nblk) NBLOCK * reallocnblock(int id, int len, int chunk) { - BLOCK *blk; - int newsize; - int oldsize; - USB8* newdata; + BLOCK *blk; + int newsize; + int oldsize; + USB8* newdata; - /* Fire wall */ - if (id < 0 || id >= nblockcount) { - math_error("Bad id in call to reallocnblock"); - not_reached(); - } + /* Fire wall */ + if (id < 0 || id >= nblockcount) { + math_error("Bad id in call to reallocnblock"); + not_reached(); + } - blk = nblocks[id]->blk; - if (len < 0) - len = blk->datalen; - if (chunk < 0) - chunk = blk->blkchunk; - else if (chunk == 0) - chunk = BLK_CHUNKSIZE; - newsize = (1 + len/chunk) * chunk; - oldsize = blk->maxsize; - newdata = blk->data; - if (newdata == NULL) { - newdata = malloc(newsize); - if (newdata == NULL) { - math_error("Allocation failed"); - not_reached(); - } - } else if (newsize != oldsize) { - newdata = realloc(blk->data, newsize); - if (newdata == NULL) { - math_error("Reallocation failed"); - not_reached(); - } - } - memset(newdata + len, 0, newsize - len); + blk = nblocks[id]->blk; + if (len < 0) + len = blk->datalen; + if (chunk < 0) + chunk = blk->blkchunk; + else if (chunk == 0) + chunk = BLK_CHUNKSIZE; + newsize = (1 + len/chunk) * chunk; + oldsize = blk->maxsize; + newdata = blk->data; + if (newdata == NULL) { + newdata = malloc(newsize); + if (newdata == NULL) { + math_error("Allocation failed"); + not_reached(); + } + } else if (newsize != oldsize) { + newdata = realloc(blk->data, newsize); + if (newdata == NULL) { + math_error("Reallocation failed"); + not_reached(); + } + } + memset(newdata + len, 0, newsize - len); - blk->maxsize = newsize; - blk->datalen = len; - blk->blkchunk = chunk; - blk->data = newdata; - return nblocks[id]; + blk->maxsize = newsize; + blk->datalen = len; + blk->blkchunk = chunk; + blk->data = newdata; + return nblocks[id]; } @@ -582,54 +582,54 @@ reallocnblock(int id, int len, int chunk) NBLOCK * createnblock(char *name, int len, int chunk) { - NBLOCK *res; - char *newname; + NBLOCK *res; + char *newname; - if (nblockcount >= maxnblockcount) { - if (maxnblockcount <= 0) { - maxnblockcount = NBLOCKCHUNK; - nblocks = (NBLOCK **)malloc(NBLOCKCHUNK * - sizeof(NBLOCK *)); - if (nblocks == NULL) { - maxnblockcount = 0; - math_error("unable to malloc new named blocks"); - not_reached(); - } - } else { - maxnblockcount += NBLOCKCHUNK; - nblocks = (NBLOCK **)realloc(nblocks, maxnblockcount * - sizeof(NBLOCK *)); - if (nblocks == NULL) { - maxnblockcount = 0; - math_error("cannot malloc more named blocks"); - not_reached(); - } - } - } - if (nblockcount == 0) - initstr(&nblocknames); - if (findstr(&nblocknames, name) >= 0) { - math_error("Named block already exists!!!"); - not_reached(); - } - newname = addstr(&nblocknames, name); - if (newname == NULL) { - math_error("Block name allocation failed"); - not_reached(); - } + if (nblockcount >= maxnblockcount) { + if (maxnblockcount <= 0) { + maxnblockcount = NBLOCKCHUNK; + nblocks = (NBLOCK **)malloc(NBLOCKCHUNK * + sizeof(NBLOCK *)); + if (nblocks == NULL) { + maxnblockcount = 0; + math_error("unable to malloc new named blocks"); + not_reached(); + } + } else { + maxnblockcount += NBLOCKCHUNK; + nblocks = (NBLOCK **)realloc(nblocks, maxnblockcount * + sizeof(NBLOCK *)); + if (nblocks == NULL) { + maxnblockcount = 0; + math_error("cannot malloc more named blocks"); + not_reached(); + } + } + } + if (nblockcount == 0) + initstr(&nblocknames); + if (findstr(&nblocknames, name) >= 0) { + math_error("Named block already exists!!!"); + not_reached(); + } + newname = addstr(&nblocknames, name); + if (newname == NULL) { + math_error("Block name allocation failed"); + not_reached(); + } - res = (NBLOCK *) malloc(sizeof(NBLOCK)); - if (res == NULL) { - math_error("Named block allocation failed"); - not_reached(); - } + res = (NBLOCK *) malloc(sizeof(NBLOCK)); + if (res == NULL) { + math_error("Named block allocation failed"); + not_reached(); + } - nblocks[nblockcount] = res; - res->name = newname; - res->subtype = V_NOSUBTYPE; - res->id = nblockcount++; - res->blk = blkalloc(len, chunk); - return res; + nblocks[nblockcount] = res; + res->name = newname; + res->subtype = V_NOSUBTYPE; + res->id = nblockcount++; + res->blk = blkalloc(len, chunk); + return res; } @@ -639,7 +639,7 @@ createnblock(char *name, int len, int chunk) int findnblockid(char * name) { - return findstr(&nblocknames, name); + return findstr(&nblocknames, name); } @@ -649,20 +649,20 @@ findnblockid(char * name) int removenblock(int id) { - NBLOCK *nblk; + NBLOCK *nblk; - if (id < 0 || id >= nblockcount) - return E_BLKFREE_3; - nblk = nblocks[id]; - if (nblk->blk->data == NULL) - return 0; - if (nblk->subtype & V_NOREALLOC) - return E_BLKFREE_5; - free(nblk->blk->data); - nblk->blk->data = NULL; - nblk->blk->maxsize = 0; - nblk->blk->datalen = 0; - return 0; + if (id < 0 || id >= nblockcount) + return E_BLKFREE_3; + nblk = nblocks[id]; + if (nblk->blk->data == NULL) + return 0; + if (nblk->subtype & V_NOREALLOC) + return E_BLKFREE_5; + free(nblk->blk->data); + nblk->blk->data = NULL; + nblk->blk->maxsize = 0; + nblk->blk->datalen = 0; + return 0; } @@ -672,14 +672,14 @@ removenblock(int id) int countnblocks(void) { - int n; - int id; + int n; + int id; - for (n = 0, id = 0; id < nblockcount; id++) { - if (nblocks[id]->blk->data != NULL) - n++; - } - return n; + for (n = 0, id = 0; id < nblockcount; id++) { + if (nblocks[id]->blk->data != NULL) + n++; + } + return n; } @@ -689,19 +689,19 @@ countnblocks(void) void shownblocks(void) { - int id; + int id; - if (countnblocks() == 0) { - printf("No unfreed named blocks\n\n"); - return; - } - printf(" id name\n"); - printf("---- -----\n"); - for (id = 0; id < nblockcount; id++) { - if (nblocks[id]->blk->data != NULL) - printf("%3d %s\n", id, nblocks[id]->name); - } - printf("\n"); + if (countnblocks() == 0) { + printf("No unfreed named blocks\n\n"); + return; + } + printf(" id name\n"); + printf("---- -----\n"); + for (id = 0; id < nblockcount; id++) { + if (nblocks[id]->blk->data != NULL) + printf("%3d %s\n", id, nblocks[id]->name); + } + printf("\n"); } @@ -712,41 +712,41 @@ shownblocks(void) NBLOCK * findnblock(int id) { - if (id < 0 || id >= nblockcount) - return NULL; - return nblocks[id]; + if (id < 0 || id >= nblockcount) + return NULL; + return nblocks[id]; } /* * Create a new block with specified newlen and new chunksize and copy - * min(newlen, oldlen) octets to the new block. The old block is + * min(newlen, oldlen) octets to the new block. The old block is * not changed. */ BLOCK * copyrealloc(BLOCK *blk, int newlen, int newchunk) { - BLOCK * newblk; - int oldlen; + BLOCK * newblk; + int oldlen; - oldlen = blk->datalen; + oldlen = blk->datalen; - if (newlen < 0) /* retain length */ - newlen = oldlen; + if (newlen < 0) /* retain length */ + newlen = oldlen; - if (newchunk < 0) /* retain chunksize */ - newchunk = blk->blkchunk; - else if (newchunk == 0) /* use default chunksize */ - newchunk = BLK_CHUNKSIZE; + if (newchunk < 0) /* retain chunksize */ + newchunk = blk->blkchunk; + else if (newchunk == 0) /* use default chunksize */ + newchunk = BLK_CHUNKSIZE; - newblk = blkalloc(newlen, newchunk); + newblk = blkalloc(newlen, newchunk); - if (newlen < oldlen) - oldlen = newlen; + if (newlen < oldlen) + oldlen = newlen; - if (newlen > 0) - memcpy(newblk->data, blk->data, oldlen); + if (newlen > 0) + memcpy(newblk->data, blk->data, oldlen); - return newblk; + return newblk; } diff --git a/block.h b/block.h index faa3006..ca48555 100644 --- a/block.h +++ b/block.h @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,11 +19,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/02/21 05:03:39 - * File existed as early as: 1997 + * Under source code control: 1997/02/21 05:03:39 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -41,114 +41,114 @@ * * Block functions and operations: * - * x[i] - * (i-1)th octet + * x[i] + * (i-1)th octet * - * blk(len [, blkchunk]) - * unnamed block - * len > 0 - * blkchunk defaults to BLK_CHUNKSIZE + * blk(len [, blkchunk]) + * unnamed block + * len > 0 + * blkchunk defaults to BLK_CHUNKSIZE * - * blk(name, [len [, blkchunk]]) - * named block - * len > 0 - * blkchunk defaults to BLK_CHUNKSIZE + * blk(name, [len [, blkchunk]]) + * named block + * len > 0 + * blkchunk defaults to BLK_CHUNKSIZE * - * blkfree(x) - * Reduce storage down to 0 octets. + * blkfree(x) + * Reduce storage down to 0 octets. * - * size(x) - * The length of data stored in the block. + * size(x) + * The length of data stored in the block. * - * sizeof(x) == blk->maxsize - * Allocation size in memory + * sizeof(x) == blk->maxsize + * Allocation size in memory * - * isblk(x) - * returns 0 is x is not a BLOCK, 1 if x is an - * unnamed block, 2 if x is a named BLOCK + * isblk(x) + * returns 0 is x is not a BLOCK, 1 if x is an + * unnamed block, 2 if x is a named BLOCK * - * blkread(x, size, count, fd [, offset]) - * blkwrite(x, size, count, fd [, offset]) - * returns number of items written - * offset is restricted in value by block type + * blkread(x, size, count, fd [, offset]) + * blkwrite(x, size, count, fd [, offset]) + * returns number of items written + * offset is restricted in value by block type * - * blkset(x, val, length [, offset]) - * only the lower octet of val is used - * offset is restricted in value by block type + * blkset(x, val, length [, offset]) + * only the lower octet of val is used + * offset is restricted in value by block type * - * blkchr(x, val, length [, offset]) - * only the lower octet of val is used - * offset is restricted in value by block type + * blkchr(x, val, length [, offset]) + * only the lower octet of val is used + * offset is restricted in value by block type * - * blkcpy(dest, src, length [, dest_offset [, src_offset]]) - * 0 <= length <= blksize(x) - * offset's are restricted in value by block type - * dest may not == src + * blkcpy(dest, src, length [, dest_offset [, src_offset]]) + * 0 <= length <= blksize(x) + * offset's are restricted in value by block type + * dest may not == src * - * blkmove(dest, src, length [, dest_offset [, src_offset]]) - * 0 <= length <= blksize(x) - * offset's are restricted in value by block type - * overlapping moves are handled correctly + * blkmove(dest, src, length [, dest_offset [, src_offset]]) + * 0 <= length <= blksize(x) + * offset's are restricted in value by block type + * overlapping moves are handled correctly * - * blkccpy(dest, src, stopval, length [, dest_offset [, src_offset]]) - * 0 <= length <= blksize(x) - * offset's are restricted in value by block type + * blkccpy(dest, src, stopval, length [, dest_offset [, src_offset]]) + * 0 <= length <= blksize(x) + * offset's are restricted in value by block type * - * blkcmp(dest, src, length [, dest_offset [, src_offset]]) - * 0 <= length <= blksize(x) - * offset's are restricted in value by block type + * blkcmp(dest, src, length [, dest_offset [, src_offset]]) + * 0 <= length <= blksize(x) + * offset's are restricted in value by block type * - * blkswap(x, a, b) - * swaps groups of 'a' octets within each 'b' octets - * b == a is a noop - * b = a*k for some integer k >= 1 + * blkswap(x, a, b) + * swaps groups of 'a' octets within each 'b' octets + * b == a is a noop + * b = a*k for some integer k >= 1 * - * scatter(src, dest1, dest2 [, dest3 ] ...) - * copy successive octets from src into dest1, dest2, ... - * restarting with dest1 after end of list - * stops at end of src + * scatter(src, dest1, dest2 [, dest3 ] ...) + * copy successive octets from src into dest1, dest2, ... + * restarting with dest1 after end of list + * stops at end of src * - * gather(dest, src1, src2 [, src3 ] ...) - * copy first octet from src1, src2, ... - * copy next octet from src1, src2, ... - * ... - * copy last octet from src1, src2, ... - * copy 0 when there is no more data from a given source + * gather(dest, src1, src2 [, src3 ] ...) + * copy first octet from src1, src2, ... + * copy next octet from src1, src2, ... + * ... + * copy last octet from src1, src2, ... + * copy 0 when there is no more data from a given source * - * blkseek(x, offset, {"in","out"}) - * some seeks may not be allowed by block type + * blkseek(x, offset, {"in","out"}) + * some seeks may not be allowed by block type * - * config("blkmaxprint", count) - * number of octets of a block to print, 0 means all + * config("blkmaxprint", count) + * number of octets of a block to print, 0 means all * - * config("blkverbose", boolean) - * true => print all lines, false => skip dup lines + * config("blkverbose", boolean) + * true => print all lines, false => skip dup lines * - * config("blkbase", "base") - * output block base = { "hex", "octal", "char", "binary", "raw" } - * binary is base 2, raw is just octet values + * config("blkbase", "base") + * output block base = { "hex", "octal", "char", "binary", "raw" } + * binary is base 2, raw is just octet values * - * config("blkfmt", "style") - * style of output = { - * "line", lines in blkbase with no spaces between octets - * "string", as one long line with no spaces between octets - * "od_style", position, spaces between octets - * "hd_style"} position, spaces between octets, chars on end + * config("blkfmt", "style") + * style of output = { + * "line", lines in blkbase with no spaces between octets + * "string", as one long line with no spaces between octets + * "od_style", position, spaces between octets + * "hd_style"} position, spaces between octets, chars on end */ struct block { - LEN blkchunk; /* allocation chunk size */ - LEN maxsize; /* octets actually malloced for this block */ - LEN datalen; /* octets of data held this block */ - USB8 *data; /* pointer to the 1st octet of the allocated data */ + LEN blkchunk; /* allocation chunk size */ + LEN maxsize; /* octets actually malloced for this block */ + LEN datalen; /* octets of data held this block */ + USB8 *data; /* pointer to the 1st octet of the allocated data */ }; typedef struct block BLOCK; struct nblock { - char *name; - int subtype; - int id; - BLOCK *blk; + char *name; + int subtype; + int id; + BLOCK *blk; }; typedef struct nblock NBLOCK; @@ -156,26 +156,26 @@ typedef struct nblock NBLOCK; /* * block debug */ -EXTERN int blk_debug; /* 0 => debug off */ +EXTERN int blk_debug; /* 0 => debug off */ /* * block defaults */ -#define BLK_CHUNKSIZE 256 /* default allocation chunk size for blocks */ +#define BLK_CHUNKSIZE 256 /* default allocation chunk size for blocks */ -#define BLK_DEF_MAXPRINT 256 /* default octets to print */ +#define BLK_DEF_MAXPRINT 256 /* default octets to print */ -#define BLK_BASE_HEX 0 /* output octets in a block in hex */ -#define BLK_BASE_OCT 1 /* output octets in a block in octal */ -#define BLK_BASE_CHAR 2 /* output octets in a block in characters */ -#define BLK_BASE_BINARY 3 /* output octets in a block in base 2 chars */ -#define BLK_BASE_RAW 4 /* output octets in a block in raw binary */ +#define BLK_BASE_HEX 0 /* output octets in a block in hex */ +#define BLK_BASE_OCT 1 /* output octets in a block in octal */ +#define BLK_BASE_CHAR 2 /* output octets in a block in characters */ +#define BLK_BASE_BINARY 3 /* output octets in a block in base 2 chars */ +#define BLK_BASE_RAW 4 /* output octets in a block in raw binary */ -#define BLK_FMT_HD_STYLE 0 /* output in base with chars on end of line */ -#define BLK_FMT_LINE 1 /* output is lines of up to 79 chars */ -#define BLK_FMT_STRING 2 /* output is one long string */ -#define BLK_FMT_OD_STYLE 3 /* output in base with chars */ +#define BLK_FMT_HD_STYLE 0 /* output in base with chars on end of line */ +#define BLK_FMT_LINE 1 /* output is lines of up to 79 chars */ +#define BLK_FMT_STRING 2 /* output is one long string */ +#define BLK_FMT_OD_STYLE 3 /* output in base with chars */ /* diff --git a/bool.h b/bool.h index 0346baf..7fcb2db 100644 --- a/bool.h +++ b/bool.h @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,11 +19,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2023/07/19 17:58:42 - * File existed as early as: 2023 + * Under source code control: 2023/07/19 17:58:42 + * File existed as early as: 2023 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -42,7 +42,7 @@ #if !defined(HAVE_STDBOOL_H) /* fake a header file */ -typedef unsigned char bool; /* fake boolean typedef */ +typedef unsigned char bool; /* fake boolean typedef */ #undef true #define true ((bool)(1)) #undef false diff --git a/byteswap.c b/byteswap.c index a995111..c25e1f0 100644 --- a/byteswap.c +++ b/byteswap.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/10/11 04:44:01 - * File existed as early as: 1995 + * Under source code control: 1995/10/11 04:44:01 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -30,46 +30,46 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* * swap_b8_in_HALFs - swap 8 and if needed, 16 bits in an array of HALFs * * given: - * dest - pointer to where the swapped src will be put or - * NULL to allocate the storage - * src - pointer to a HALF array to swap - * len - length of the src HALF array in HALFs + * dest - pointer to where the swapped src will be put or + * NULL to allocate the storage + * src - pointer to a HALF array to swap + * len - length of the src HALF array in HALFs * * returns: - * pointer to where the swapped src has been put + * pointer to where the swapped src has been put */ HALF * swap_b8_in_HALFs(HALF *dest, HALF *src, LEN len) { - HALF *ret; - LEN i; + HALF *ret; + LEN i; - /* - * allocate storage if needed - */ - if (dest == NULL) { - dest = alloc(len); - } - ret = dest; + /* + * allocate storage if needed + */ + if (dest == NULL) { + dest = alloc(len); + } + ret = dest; - /* - * swap the array - */ - for (i=0; i < len; ++i, ++dest, ++src) { - SWAP_B8_IN_HALF(dest, src); - } + /* + * swap the array + */ + for (i=0; i < len; ++i, ++dest, ++src) { + SWAP_B8_IN_HALF(dest, src); + } - /* - * return the result - */ - return ret; + /* + * return the result + */ + return ret; } @@ -77,14 +77,14 @@ swap_b8_in_HALFs(HALF *dest, HALF *src, LEN len) * swap_b8_in_ZVALUE - swap 8 and if needed, 16 bits in a ZVALUE * * given: - * dest - pointer to where the swapped src will be put or - * NULL to allocate the storage - * src - pointer to a ZVALUE to swap - * all - true => swap every element, false => swap only the - * multi-precision storage + * dest - pointer to where the swapped src will be put or + * NULL to allocate the storage + * src - pointer to a ZVALUE to swap + * all - true => swap every element, false => swap only the + * multi-precision storage * * returns: - * pointer to where the swapped src has been put + * pointer to where the swapped src has been put * * This macro will either switch to the opposite byte sex (Big Endian vs. * Little Endian) the elements of a ZVALUE. @@ -92,52 +92,52 @@ swap_b8_in_HALFs(HALF *dest, HALF *src, LEN len) ZVALUE * swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all) { - /* - * allocate storage if needed - */ - if (dest == NULL) { + /* + * allocate storage if needed + */ + if (dest == NULL) { - /* - * allocate the storage - */ - dest = malloc(sizeof(ZVALUE)); - if (dest == NULL) { - math_error("swap_b8_in_ZVALUE: swap_b8_in_ZVALUE: " - "Not enough memory"); - not_reached(); - } + /* + * allocate the storage + */ + dest = malloc(sizeof(ZVALUE)); + if (dest == NULL) { + math_error("swap_b8_in_ZVALUE: swap_b8_in_ZVALUE: " + "Not enough memory"); + not_reached(); + } - /* - * allocate (by forcing swap_b8_in_ZVALUE) and swap storage - */ - dest->v = swap_b8_in_HALFs(NULL, src->v, src->len); + /* + * allocate (by forcing swap_b8_in_ZVALUE) and swap storage + */ + dest->v = swap_b8_in_HALFs(NULL, src->v, src->len); - } else { + } else { - /* - * swap storage - */ - if (dest->v != NULL) { - zfree(*dest); - } - dest->v = swap_b8_in_HALFs(NULL, src->v, src->len); - } + /* + * swap storage + */ + if (dest->v != NULL) { + zfree(*dest); + } + dest->v = swap_b8_in_HALFs(NULL, src->v, src->len); + } - /* - * swap or copy the rest of the ZVALUE elements - */ - if (all) { - SWAP_B8_IN_LEN(&dest->len, &src->len); - SWAP_B8_IN_bool(&dest->sign, &src->sign); - } else { - dest->len = src->len; - dest->sign = src->sign; - } + /* + * swap or copy the rest of the ZVALUE elements + */ + if (all) { + SWAP_B8_IN_LEN(&dest->len, &src->len); + SWAP_B8_IN_bool(&dest->sign, &src->sign); + } else { + dest->len = src->len; + dest->sign = src->sign; + } - /* - * return the result - */ - return dest; + /* + * return the result + */ + return dest; } @@ -145,14 +145,14 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all) * swap_b8_in_NUMBER - swap 8 and if needed, 16 bits in a NUMBER * * given: - * dest - pointer to where the swapped src will be put or - * NULL to allocate the storage - * src - pointer to a NUMBER to swap - * all - true => swap every element, false => swap only the - * multi-precision storage + * dest - pointer to where the swapped src will be put or + * NULL to allocate the storage + * src - pointer to a NUMBER to swap + * all - true => swap every element, false => swap only the + * multi-precision storage * * returns: - * pointer to where the swapped src has been put + * pointer to where the swapped src has been put * * This macro will either switch to the opposite byte sex (Big Endian vs. * Little Endian) the elements of a NUMBER. @@ -160,48 +160,48 @@ swap_b8_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all) NUMBER * swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, bool all) { - /* - * allocate storage if needed - */ - if (dest == NULL) { + /* + * allocate storage if needed + */ + if (dest == NULL) { - /* - * allocate the storage - */ - dest = malloc(sizeof(NUMBER)); - if (dest == NULL) { - math_error("swap_b8_in_NUMBER: Not enough memory"); - not_reached(); - } + /* + * allocate the storage + */ + dest = malloc(sizeof(NUMBER)); + if (dest == NULL) { + math_error("swap_b8_in_NUMBER: Not enough memory"); + not_reached(); + } - /* - * allocate (by forcing swap_b8_in_ZVALUE) and swap storage - */ - dest->num = *swap_b8_in_ZVALUE(NULL, &src->num, all); - dest->den = *swap_b8_in_ZVALUE(NULL, &src->den, all); + /* + * allocate (by forcing swap_b8_in_ZVALUE) and swap storage + */ + dest->num = *swap_b8_in_ZVALUE(NULL, &src->num, all); + dest->den = *swap_b8_in_ZVALUE(NULL, &src->den, all); - } else { + } else { - /* - * swap storage - */ - dest->num = *swap_b8_in_ZVALUE(&dest->num, &src->num, all); - dest->den = *swap_b8_in_ZVALUE(&dest->den, &src->den, all); - } + /* + * swap storage + */ + dest->num = *swap_b8_in_ZVALUE(&dest->num, &src->num, all); + dest->den = *swap_b8_in_ZVALUE(&dest->den, &src->den, all); + } - /* - * swap or copy the rest of the NUMBER elements - */ - if (all) { - SWAP_B8_IN_LONG(&dest->links, &src->links); - } else { - dest->links = src->links; - } + /* + * swap or copy the rest of the NUMBER elements + */ + if (all) { + SWAP_B8_IN_LONG(&dest->links, &src->links); + } else { + dest->links = src->links; + } - /* - * return the result - */ - return dest; + /* + * return the result + */ + return dest; } @@ -209,14 +209,14 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, bool all) * swap_b8_in_COMPLEX - swap 8 and if needed, 16 bits in a COMPLEX * * given: - * dest - pointer to where the swapped src will be put or - * NULL to allocate the storage - * src - pointer to a COMPLEX to swap - * all - true => swap every element, false => swap only the - * multi-precision storage + * dest - pointer to where the swapped src will be put or + * NULL to allocate the storage + * src - pointer to a COMPLEX to swap + * all - true => swap every element, false => swap only the + * multi-precision storage * * returns: - * pointer to where the swapped src has been put + * pointer to where the swapped src has been put * * This macro will either switch to the opposite byte sex (Big Endian vs. * Little Endian) the elements of a COMPLEX. @@ -224,48 +224,48 @@ swap_b8_in_NUMBER(NUMBER *dest, NUMBER *src, bool all) COMPLEX * swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all) { - /* - * allocate storage if needed - */ - if (dest == NULL) { + /* + * allocate storage if needed + */ + if (dest == NULL) { - /* - * allocate the storage - */ - dest = malloc(sizeof(COMPLEX)); - if (dest == NULL) { - math_error("swap_b8_in_COMPLEX: Not enough memory"); - not_reached(); - } + /* + * allocate the storage + */ + dest = malloc(sizeof(COMPLEX)); + if (dest == NULL) { + math_error("swap_b8_in_COMPLEX: Not enough memory"); + not_reached(); + } - /* - * allocate (by forcing swap_b8_in_ZVALUE) and swap storage - */ - dest->real = swap_b8_in_NUMBER(NULL, src->real, all); - dest->imag = swap_b8_in_NUMBER(NULL, src->imag, all); + /* + * allocate (by forcing swap_b8_in_ZVALUE) and swap storage + */ + dest->real = swap_b8_in_NUMBER(NULL, src->real, all); + dest->imag = swap_b8_in_NUMBER(NULL, src->imag, all); - } else { + } else { - /* - * swap storage - */ - dest->real = swap_b8_in_NUMBER(dest->real, src->real, all); - dest->imag = swap_b8_in_NUMBER(dest->imag, src->imag, all); - } + /* + * swap storage + */ + dest->real = swap_b8_in_NUMBER(dest->real, src->real, all); + dest->imag = swap_b8_in_NUMBER(dest->imag, src->imag, all); + } - /* - * swap or copy the rest of the NUMBER elements - */ - if (all) { - SWAP_B8_IN_LONG(&dest->links, &src->links); - } else { - dest->links = src->links; - } + /* + * swap or copy the rest of the NUMBER elements + */ + if (all) { + SWAP_B8_IN_LONG(&dest->links, &src->links); + } else { + dest->links = src->links; + } - /* - * return the result - */ - return dest; + /* + * return the result + */ + return dest; } @@ -273,39 +273,39 @@ swap_b8_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all) * swap_b16_in_HALFs - swap 16 bits in an array of HALFs * * given: - * dest - pointer to where the swapped src will be put or - * NULL to allocate the storage - * src - pointer to a HALF array to swap - * len - length of the src HALF array in HALFs + * dest - pointer to where the swapped src will be put or + * NULL to allocate the storage + * src - pointer to a HALF array to swap + * len - length of the src HALF array in HALFs * * returns: - * pointer to where the swapped src has been put + * pointer to where the swapped src has been put */ HALF * swap_b16_in_HALFs(HALF *dest, HALF *src, LEN len) { - HALF *ret; - LEN i; + HALF *ret; + LEN i; - /* - * allocate storage if needed - */ - if (dest == NULL) { - dest = alloc(len); - } - ret = dest; + /* + * allocate storage if needed + */ + if (dest == NULL) { + dest = alloc(len); + } + ret = dest; - /* - * swap the array - */ - for (i=0; i < len; ++i, ++dest, ++src) { - SWAP_B16_IN_HALF(dest, src); - } + /* + * swap the array + */ + for (i=0; i < len; ++i, ++dest, ++src) { + SWAP_B16_IN_HALF(dest, src); + } - /* - * return the result - */ - return ret; + /* + * return the result + */ + return ret; } @@ -313,43 +313,43 @@ swap_b16_in_HALFs(HALF *dest, HALF *src, LEN len) * swap_HALFs - swap HALFs in an array of HALFs * * given: - * dest - pointer to where the swapped src will be put or - * NULL to allocate the storage - * src - pointer to a HALF array to swap - * len - length of the src HALF array in HALFs + * dest - pointer to where the swapped src will be put or + * NULL to allocate the storage + * src - pointer to a HALF array to swap + * len - length of the src HALF array in HALFs * * returns: - * pointer to where the swapped src has been put + * pointer to where the swapped src has been put */ HALF * swap_HALFs(HALF *dest, HALF *src, LEN len) { - HALF *s; /* src swap pointer */ - HALF *d; /* dest swap pointer */ - HALF *ret; - LEN i; + HALF *s; /* src swap pointer */ + HALF *d; /* dest swap pointer */ + HALF *ret; + LEN i; - /* - * allocate storage if needed - */ - if (dest == NULL) { - dest = alloc(len); - } - ret = dest; + /* + * allocate storage if needed + */ + if (dest == NULL) { + dest = alloc(len); + } + ret = dest; - /* - * swap HALFs in the array - */ - s = src; - d = &dest[len-1]; - for (i=0; i < len; ++i, --d, ++s) { - *d = *s; - } + /* + * swap HALFs in the array + */ + s = src; + d = &dest[len-1]; + for (i=0; i < len; ++i, --d, ++s) { + *d = *s; + } - /* - * return the result - */ - return ret; + /* + * return the result + */ + return ret; } @@ -357,14 +357,14 @@ swap_HALFs(HALF *dest, HALF *src, LEN len) * swap_b16_in_ZVALUE - swap 16 bits in a ZVALUE * * given: - * dest - pointer to where the swapped src will be put or - * NULL to allocate the storage - * src - pointer to a ZVALUE to swap - * all - true => swap every element, false => swap only the - * multi-precision storage + * dest - pointer to where the swapped src will be put or + * NULL to allocate the storage + * src - pointer to a ZVALUE to swap + * all - true => swap every element, false => swap only the + * multi-precision storage * * returns: - * pointer to where the swapped src has been put + * pointer to where the swapped src has been put * * This macro will either switch to the opposite byte sex (Big Endian vs. * Little Endian) the elements of a ZVALUE. @@ -372,51 +372,51 @@ swap_HALFs(HALF *dest, HALF *src, LEN len) ZVALUE * swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all) { - /* - * allocate storage if needed - */ - if (dest == NULL) { + /* + * allocate storage if needed + */ + if (dest == NULL) { - /* - * allocate the storage - */ - dest = malloc(sizeof(ZVALUE)); - if (dest == NULL) { - math_error("swap_b16_in_ZVALUE: Not enough memory"); - not_reached(); - } + /* + * allocate the storage + */ + dest = malloc(sizeof(ZVALUE)); + if (dest == NULL) { + math_error("swap_b16_in_ZVALUE: Not enough memory"); + not_reached(); + } - /* - * allocate (by forcing swap_b16_in_ZVALUE) and swap storage - */ - dest->v = swap_b16_in_HALFs(NULL, src->v, src->len); + /* + * allocate (by forcing swap_b16_in_ZVALUE) and swap storage + */ + dest->v = swap_b16_in_HALFs(NULL, src->v, src->len); - } else { + } else { - /* - * swap storage - */ - if (dest->v != NULL) { - zfree(*dest); - } - dest->v = swap_b16_in_HALFs(NULL, src->v, src->len); - } + /* + * swap storage + */ + if (dest->v != NULL) { + zfree(*dest); + } + dest->v = swap_b16_in_HALFs(NULL, src->v, src->len); + } - /* - * swap or copy the rest of the ZVALUE elements - */ - if (all) { - SWAP_B16_IN_LEN(&dest->len, &src->len); - SWAP_B16_IN_bool(&dest->sign, &src->sign); - } else { - dest->len = src->len; - dest->sign = src->sign; - } + /* + * swap or copy the rest of the ZVALUE elements + */ + if (all) { + SWAP_B16_IN_LEN(&dest->len, &src->len); + SWAP_B16_IN_bool(&dest->sign, &src->sign); + } else { + dest->len = src->len; + dest->sign = src->sign; + } - /* - * return the result - */ - return dest; + /* + * return the result + */ + return dest; } @@ -424,14 +424,14 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all) * swap_b16_in_NUMBER - swap 16 bits in a NUMBER * * given: - * dest - pointer to where the swapped src will be put or - * NULL to allocate the storage - * src - pointer to a NUMBER to swap - * all - true => swap every element, false => swap only the - * multi-precision storage + * dest - pointer to where the swapped src will be put or + * NULL to allocate the storage + * src - pointer to a NUMBER to swap + * all - true => swap every element, false => swap only the + * multi-precision storage * * returns: - * pointer to where the swapped src has been put + * pointer to where the swapped src has been put * * This macro will either switch to the opposite byte sex (Big Endian vs. * Little Endian) the elements of a NUMBER. @@ -439,48 +439,48 @@ swap_b16_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all) NUMBER * swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, bool all) { - /* - * allocate storage if needed - */ - if (dest == NULL) { + /* + * allocate storage if needed + */ + if (dest == NULL) { - /* - * allocate the storage - */ - dest = malloc(sizeof(NUMBER)); - if (dest == NULL) { - math_error("swap_b16_in_NUMBER: Not enough memory"); - not_reached(); - } + /* + * allocate the storage + */ + dest = malloc(sizeof(NUMBER)); + if (dest == NULL) { + math_error("swap_b16_in_NUMBER: Not enough memory"); + not_reached(); + } - /* - * allocate (by forcing swap_b16_in_ZVALUE) and swap storage - */ - dest->num = *swap_b16_in_ZVALUE(NULL, &src->num, all); - dest->den = *swap_b16_in_ZVALUE(NULL, &src->den, all); + /* + * allocate (by forcing swap_b16_in_ZVALUE) and swap storage + */ + dest->num = *swap_b16_in_ZVALUE(NULL, &src->num, all); + dest->den = *swap_b16_in_ZVALUE(NULL, &src->den, all); - } else { + } else { - /* - * swap storage - */ - dest->num = *swap_b16_in_ZVALUE(&dest->num, &src->num, all); - dest->den = *swap_b16_in_ZVALUE(&dest->den, &src->den, all); - } + /* + * swap storage + */ + dest->num = *swap_b16_in_ZVALUE(&dest->num, &src->num, all); + dest->den = *swap_b16_in_ZVALUE(&dest->den, &src->den, all); + } - /* - * swap or copy the rest of the NUMBER elements - */ - if (all) { - SWAP_B16_IN_LONG(&dest->links, &src->links); - } else { - dest->links = src->links; - } + /* + * swap or copy the rest of the NUMBER elements + */ + if (all) { + SWAP_B16_IN_LONG(&dest->links, &src->links); + } else { + dest->links = src->links; + } - /* - * return the result - */ - return dest; + /* + * return the result + */ + return dest; } @@ -488,14 +488,14 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, bool all) * swap_b16_in_COMPLEX - swap 16 bits in a COMPLEX * * given: - * dest - pointer to where the swapped src will be put or - * NULL to allocate the storage - * src - pointer to a COMPLEX to swap - * all - true => swap every element, false => swap only the - * multi-precision storage + * dest - pointer to where the swapped src will be put or + * NULL to allocate the storage + * src - pointer to a COMPLEX to swap + * all - true => swap every element, false => swap only the + * multi-precision storage * * returns: - * pointer to where the swapped src has been put + * pointer to where the swapped src has been put * * This macro will either switch to the opposite byte sex (Big Endian vs. * Little Endian) the elements of a COMPLEX. @@ -503,48 +503,48 @@ swap_b16_in_NUMBER(NUMBER *dest, NUMBER *src, bool all) COMPLEX * swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all) { - /* - * allocate storage if needed - */ - if (dest == NULL) { + /* + * allocate storage if needed + */ + if (dest == NULL) { - /* - * allocate the storage - */ - dest = malloc(sizeof(COMPLEX)); - if (dest == NULL) { - math_error("swap_b16_in_COMPLEX: Not enough memory"); - not_reached(); - } + /* + * allocate the storage + */ + dest = malloc(sizeof(COMPLEX)); + if (dest == NULL) { + math_error("swap_b16_in_COMPLEX: Not enough memory"); + not_reached(); + } - /* - * allocate (by forcing swap_b16_in_ZVALUE) and swap storage - */ - dest->real = swap_b16_in_NUMBER(NULL, src->real, all); - dest->imag = swap_b16_in_NUMBER(NULL, src->imag, all); + /* + * allocate (by forcing swap_b16_in_ZVALUE) and swap storage + */ + dest->real = swap_b16_in_NUMBER(NULL, src->real, all); + dest->imag = swap_b16_in_NUMBER(NULL, src->imag, all); - } else { + } else { - /* - * swap storage - */ - dest->real = swap_b16_in_NUMBER(dest->real, src->real, all); - dest->imag = swap_b16_in_NUMBER(dest->imag, src->imag, all); - } + /* + * swap storage + */ + dest->real = swap_b16_in_NUMBER(dest->real, src->real, all); + dest->imag = swap_b16_in_NUMBER(dest->imag, src->imag, all); + } - /* - * swap or copy the rest of the NUMBER elements - */ - if (all) { - SWAP_B16_IN_LONG(&dest->links, &src->links); - } else { - dest->links = src->links; - } + /* + * swap or copy the rest of the NUMBER elements + */ + if (all) { + SWAP_B16_IN_LONG(&dest->links, &src->links); + } else { + dest->links = src->links; + } - /* - * return the result - */ - return dest; + /* + * return the result + */ + return dest; } @@ -552,14 +552,14 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all) * swap_HALF_in_ZVALUE - swap HALFs in a ZVALUE * * given: - * dest - pointer to where the swapped src will be put or - * NULL to allocate the storage - * src - pointer to a ZVALUE to swap - * all - true => swap every element, false => swap only the - * multi-precision storage + * dest - pointer to where the swapped src will be put or + * NULL to allocate the storage + * src - pointer to a ZVALUE to swap + * all - true => swap every element, false => swap only the + * multi-precision storage * * returns: - * pointer to where the swapped src has been put + * pointer to where the swapped src has been put * * This macro will either switch to the opposite byte sex (Big Endian vs. * Little Endian) the elements of a ZVALUE. @@ -567,52 +567,52 @@ swap_b16_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all) ZVALUE * swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all) { - /* - * allocate storage if needed - */ - if (dest == NULL) { + /* + * allocate storage if needed + */ + if (dest == NULL) { - /* - * allocate the storage - */ - dest = calloc(1, sizeof(ZVALUE)); - if (dest == NULL) { - math_error("swap_HALF_in_ZVALUE: Not enough memory"); - not_reached(); - } + /* + * allocate the storage + */ + dest = calloc(1, sizeof(ZVALUE)); + if (dest == NULL) { + math_error("swap_HALF_in_ZVALUE: Not enough memory"); + not_reached(); + } - /* - * copy storage because we are dealing with HALFs - */ - dest->v = (HALF *) zcopyval(*src, *dest); + /* + * copy storage because we are dealing with HALFs + */ + dest->v = (HALF *) zcopyval(*src, *dest); - } else { + } else { - /* - * copy storage because we are dealing with HALFs - */ - if (dest->v != NULL) { - zfree(*dest); - dest->v = alloc(src->len); - } - zcopyval(*src, *dest); - } + /* + * copy storage because we are dealing with HALFs + */ + if (dest->v != NULL) { + zfree(*dest); + dest->v = alloc(src->len); + } + zcopyval(*src, *dest); + } - /* - * swap or copy the rest of the ZVALUE elements - */ - if (all) { - SWAP_HALF_IN_LEN(&dest->len, &src->len); - SWAP_HALF_IN_bool(&dest->sign, &src->sign); - } else { - dest->len = src->len; - dest->sign = src->sign; - } + /* + * swap or copy the rest of the ZVALUE elements + */ + if (all) { + SWAP_HALF_IN_LEN(&dest->len, &src->len); + SWAP_HALF_IN_bool(&dest->sign, &src->sign); + } else { + dest->len = src->len; + dest->sign = src->sign; + } - /* - * return the result - */ - return dest; + /* + * return the result + */ + return dest; } @@ -620,14 +620,14 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all) * swap_HALF_in_NUMBER - swap HALFs in a NUMBER * * given: - * dest - pointer to where the swapped src will be put or - * NULL to allocate the storage - * src - pointer to a NUMBER to swap - * all - true => swap every element, false => swap only the - * multi-precision storage + * dest - pointer to where the swapped src will be put or + * NULL to allocate the storage + * src - pointer to a NUMBER to swap + * all - true => swap every element, false => swap only the + * multi-precision storage * * returns: - * pointer to where the swapped src has been put + * pointer to where the swapped src has been put * * This macro will either switch to the opposite byte sex (Big Endian vs. * Little Endian) the elements of a NUMBER. @@ -635,48 +635,48 @@ swap_HALF_in_ZVALUE(ZVALUE *dest, ZVALUE *src, bool all) NUMBER * swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, bool all) { - /* - * allocate storage if needed - */ - if (dest == NULL) { + /* + * allocate storage if needed + */ + if (dest == NULL) { - /* - * allocate the storage - */ - dest = malloc(sizeof(NUMBER)); - if (dest == NULL) { - math_error("swap_HALF_in_NUMBER: Not enough memory"); - not_reached(); - } + /* + * allocate the storage + */ + dest = malloc(sizeof(NUMBER)); + if (dest == NULL) { + math_error("swap_HALF_in_NUMBER: Not enough memory"); + not_reached(); + } - /* - * allocate (by forcing swap_HALF_in_ZVALUE) and swap storage - */ - dest->num = *swap_HALF_in_ZVALUE(NULL, &src->num, all); - dest->den = *swap_HALF_in_ZVALUE(NULL, &src->den, all); + /* + * allocate (by forcing swap_HALF_in_ZVALUE) and swap storage + */ + dest->num = *swap_HALF_in_ZVALUE(NULL, &src->num, all); + dest->den = *swap_HALF_in_ZVALUE(NULL, &src->den, all); - } else { + } else { - /* - * swap storage - */ - dest->num = *swap_HALF_in_ZVALUE(&dest->num, &src->num, all); - dest->den = *swap_HALF_in_ZVALUE(&dest->den, &src->den, all); - } + /* + * swap storage + */ + dest->num = *swap_HALF_in_ZVALUE(&dest->num, &src->num, all); + dest->den = *swap_HALF_in_ZVALUE(&dest->den, &src->den, all); + } - /* - * swap or copy the rest of the NUMBER elements - */ - if (all) { - SWAP_HALF_IN_LONG(&dest->links, &src->links); - } else { - dest->links = src->links; - } + /* + * swap or copy the rest of the NUMBER elements + */ + if (all) { + SWAP_HALF_IN_LONG(&dest->links, &src->links); + } else { + dest->links = src->links; + } - /* - * return the result - */ - return dest; + /* + * return the result + */ + return dest; } @@ -684,14 +684,14 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, bool all) * swap_HALF_in_COMPLEX - swap HALFs in a COMPLEX * * given: - * dest - pointer to where the swapped src will be put or - * NULL to allocate the storage - * src - pointer to a COMPLEX to swap - * all - true => swap every element, false => swap only the - * multi-precision storage + * dest - pointer to where the swapped src will be put or + * NULL to allocate the storage + * src - pointer to a COMPLEX to swap + * all - true => swap every element, false => swap only the + * multi-precision storage * * returns: - * pointer to where the swapped src has been put + * pointer to where the swapped src has been put * * This macro will either switch to the opposite byte sex (Big Endian vs. * Little Endian) the elements of a COMPLEX. @@ -699,46 +699,46 @@ swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, bool all) COMPLEX * swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all) { - /* - * allocate storage if needed - */ - if (dest == NULL) { + /* + * allocate storage if needed + */ + if (dest == NULL) { - /* - * allocate the storage - */ - dest = malloc(sizeof(COMPLEX)); - if (dest == NULL) { - math_error("swap_HALF_in_COMPLEX: Not enough memory"); - not_reached(); - } + /* + * allocate the storage + */ + dest = malloc(sizeof(COMPLEX)); + if (dest == NULL) { + math_error("swap_HALF_in_COMPLEX: Not enough memory"); + not_reached(); + } - /* - * allocate (by forcing swap_HALF_in_ZVALUE) and swap storage - */ - dest->real = swap_HALF_in_NUMBER(NULL, src->real, all); - dest->imag = swap_HALF_in_NUMBER(NULL, src->imag, all); + /* + * allocate (by forcing swap_HALF_in_ZVALUE) and swap storage + */ + dest->real = swap_HALF_in_NUMBER(NULL, src->real, all); + dest->imag = swap_HALF_in_NUMBER(NULL, src->imag, all); - } else { + } else { - /* - * swap storage - */ - dest->real = swap_HALF_in_NUMBER(dest->real, src->real, all); - dest->imag = swap_HALF_in_NUMBER(dest->imag, src->imag, all); - } + /* + * swap storage + */ + dest->real = swap_HALF_in_NUMBER(dest->real, src->real, all); + dest->imag = swap_HALF_in_NUMBER(dest->imag, src->imag, all); + } - /* - * swap or copy the rest of the NUMBER elements - */ - if (all) { - SWAP_HALF_IN_LONG(&dest->links, &src->links); - } else { - dest->links = src->links; - } + /* + * swap or copy the rest of the NUMBER elements + */ + if (all) { + SWAP_HALF_IN_LONG(&dest->links, &src->links); + } else { + dest->links = src->links; + } - /* - * return the result - */ - return dest; + /* + * return the result + */ + return dest; } diff --git a/byteswap.h b/byteswap.h index 75234ca..c2a1803 100644 --- a/byteswap.h +++ b/byteswap.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/10/11 04:44:01 - * File existed as early as: 1995 + * Under source code control: 1995/10/11 04:44:01 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -29,7 +29,7 @@ #define INCLUDE_BYTESWAP_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "longbits.h" #else # include @@ -39,42 +39,42 @@ /* * SWAP_B8_IN_B16 - swap 8 bits in 16 bits * - * dest - pointer to where the swapped src will be put - * src - pointer to a 16 bit value to swap + * dest - pointer to where the swapped src will be put + * src - pointer to a 16 bit value to swap * * This macro will either switch to the opposite byte sex (Big Endian vs. * Little Endian) a 16 bit value. */ -#define SWAP_B8_IN_B16(dest, src) ( \ - *((USB16*)(dest)) = \ - (((*((USB16*)(src))) << 8) | ((*((USB16*)(src))) >> 8)) \ +#define SWAP_B8_IN_B16(dest, src) ( \ + *((USB16*)(dest)) = \ + (((*((USB16*)(src))) << 8) | ((*((USB16*)(src))) >> 8)) \ ) /* * SWAP_B16_IN_B32 - swap 16 bits in 32 bits * - * dest - pointer to where the swapped src will be put - * src - pointer to a 32 bit value to swap + * dest - pointer to where the swapped src will be put + * src - pointer to a 32 bit value to swap */ -#define SWAP_B16_IN_B32(dest, src) ( \ - *((USB32*)(dest)) = \ - (((*((USB32*)(src))) << 16) | ((*((USB32*)(src))) >> 16)) \ +#define SWAP_B16_IN_B32(dest, src) ( \ + *((USB32*)(dest)) = \ + (((*((USB32*)(src))) << 16) | ((*((USB32*)(src))) >> 16)) \ ) /* * SWAP_B8_IN_B32 - swap 8 & 16 bits in 32 bits * - * dest - pointer to where the swapped src will be put - * src - pointer to a 32 bit value to swap + * dest - pointer to where the swapped src will be put + * src - pointer to a 32 bit value to swap * * This macro will either switch to the opposite byte sex (Big Endian vs. * Little Endian) a 32 bit value. */ -#define SWAP_B8_IN_B32(dest, src) ( \ - SWAP_B16_IN_B32(dest, src), \ - (*((USB32*)(dest)) = \ - ((((*((USB32*)(dest))) & (USB32)0xff00ff00) >> 8) | \ - (((*((USB32*)(dest))) & (USB32)0x00ff00ff) << 8))) \ +#define SWAP_B8_IN_B32(dest, src) ( \ + SWAP_B16_IN_B32(dest, src), \ + (*((USB32*)(dest)) = \ + ((((*((USB32*)(dest))) & (USB32)0xff00ff00) >> 8) | \ + (((*((USB32*)(dest))) & (USB32)0x00ff00ff) << 8))) \ ) #if defined(HAVE_B64) @@ -82,41 +82,41 @@ /* * SWAP_B32_IN_B64 - swap 32 bits in 64 bits * - * dest - pointer to where the swapped src will be put - * src - pointer to a 64 bit value to swap + * dest - pointer to where the swapped src will be put + * src - pointer to a 64 bit value to swap */ -#define SWAP_B32_IN_B64(dest, src) ( \ - *((USB64*)(dest)) = \ - (((*((USB64*)(src))) << 32) | ((*((USB64*)(src))) >> 32)) \ +#define SWAP_B32_IN_B64(dest, src) ( \ + *((USB64*)(dest)) = \ + (((*((USB64*)(src))) << 32) | ((*((USB64*)(src))) >> 32)) \ ) /* * SWAP_B16_IN_B64 - swap 16 & 32 bits in 64 bits * - * dest - pointer to where the swapped src will be put - * src - pointer to a 64 bit value to swap + * dest - pointer to where the swapped src will be put + * src - pointer to a 64 bit value to swap */ -#define SWAP_B16_IN_B64(dest, src) ( \ - SWAP_B32_IN_B64(dest, src), \ - (*((USB64*)(dest)) = \ - ((((*((USB64*)(dest))) & (USB64)0xffff0000ffff0000) >> 16) | \ - (((*((USB64*)(dest))) & (USB64)0x0000ffff0000ffff) << 16))) \ +#define SWAP_B16_IN_B64(dest, src) ( \ + SWAP_B32_IN_B64(dest, src), \ + (*((USB64*)(dest)) = \ + ((((*((USB64*)(dest))) & (USB64)0xffff0000ffff0000) >> 16) | \ + (((*((USB64*)(dest))) & (USB64)0x0000ffff0000ffff) << 16))) \ ) /* * SWAP_B8_IN_B64 - swap 16 & 32 bits in 64 bits * - * dest - pointer to where the swapped src will be put - * src - pointer to a 64 bit value to swap + * dest - pointer to where the swapped src will be put + * src - pointer to a 64 bit value to swap * * This macro will either switch to the opposite byte sex (Big Endian vs. * Little Endian) a 64 bit value. */ -#define SWAP_B8_IN_B64(dest, src) ( \ - SWAP_B16_IN_B64(dest, src), \ - (*((USB64*)(dest)) = \ - ((((*((USB64*)(dest))) & (USB64)0xff00ff00ff00ff00) >> 8) | \ - (((*((USB64*)(dest))) & (USB64)0x00ff00ff00ff00ff) << 8))) \ +#define SWAP_B8_IN_B64(dest, src) ( \ + SWAP_B16_IN_B64(dest, src), \ + (*((USB64*)(dest)) = \ + ((((*((USB64*)(dest))) & (USB64)0xff00ff00ff00ff00) >> 8) | \ + (((*((USB64*)(dest))) & (USB64)0x00ff00ff00ff00ff) << 8))) \ ) #else /* HAVE_B64 */ @@ -124,52 +124,52 @@ /* * SWAP_B32_IN_B64 - swap 32 bits in 64 bits (simulated by 2 32 bit values) * - * dest - pointer to where the swapped src will be put - * src - pointer to a 64 bit value to swap + * dest - pointer to where the swapped src will be put + * src - pointer to a 64 bit value to swap */ -#define SWAP_B32_IN_B64(dest, src) ( \ - ((USB32*)(dest))[1] = ((USB32*)(dest))[0], \ - ((USB32*)(dest))[0] = ((USB32*)(dest))[1] \ +#define SWAP_B32_IN_B64(dest, src) ( \ + ((USB32*)(dest))[1] = ((USB32*)(dest))[0], \ + ((USB32*)(dest))[0] = ((USB32*)(dest))[1] \ ) /* * SWAP_B16_IN_B64 - swap 16 & 32 bits in 64 bits (simulated by 2 32 bit vals) * - * dest - pointer to where the swapped src will be put - * src - pointer to a 64 bit value to swap + * dest - pointer to where the swapped src will be put + * src - pointer to a 64 bit value to swap */ -#define SWAP_B16_IN_B64(dest, src) ( \ - SWAP_B16_IN_B32(((USB32*)dest)+1, ((USB32*)src)), \ - SWAP_B16_IN_B32(((USB32*)dest), ((USB32*)src)+1) \ +#define SWAP_B16_IN_B64(dest, src) ( \ + SWAP_B16_IN_B32(((USB32*)dest)+1, ((USB32*)src)), \ + SWAP_B16_IN_B32(((USB32*)dest), ((USB32*)src)+1) \ ) /* * SWAP_B8_IN_B64 - swap 16 & 32 bits in 64 bits (simulated by 2 32 bit vals) * - * dest - pointer to where the swapped src will be put - * src - pointer to a 64 bit value to swap + * dest - pointer to where the swapped src will be put + * src - pointer to a 64 bit value to swap * * This macro will either switch to the opposite byte sex (Big Endian vs. * Little Endian) a 64 bit value. */ -#define SWAP_B8_IN_B64(dest, src) ( \ - SWAP_B8_IN_B32(((USB32*)dest)+1, ((USB32*)src)), \ - SWAP_B8_IN_B32(((USB32*)dest), ((USB32*)src)+1) \ +#define SWAP_B8_IN_B64(dest, src) ( \ + SWAP_B8_IN_B32(((USB32*)dest)+1, ((USB32*)src)), \ + SWAP_B8_IN_B32(((USB32*)dest), ((USB32*)src)+1) \ ) #endif /* HAVE_B64 */ #if LONG_BITS == 64 -#define SWAP_B32_IN_LONG(dest, src) SWAP_B32_IN_B64(dest, src) -#define SWAP_B16_IN_LONG(dest, src) SWAP_B16_IN_B64(dest, src) -#define SWAP_B8_IN_LONG(dest, src) SWAP_B8_IN_B64(dest, src) +#define SWAP_B32_IN_LONG(dest, src) SWAP_B32_IN_B64(dest, src) +#define SWAP_B16_IN_LONG(dest, src) SWAP_B16_IN_B64(dest, src) +#define SWAP_B8_IN_LONG(dest, src) SWAP_B8_IN_B64(dest, src) #else /* LONG_BITS == 64 */ -#define SWAP_B32_IN_LONG(dest, src) SWAP_B32_IN_B32(dest, src) -#define SWAP_B16_IN_LONG(dest, src) SWAP_B16_IN_B32(dest, src) -#define SWAP_B8_IN_LONG(dest, src) SWAP_B8_IN_B32(dest, src) +#define SWAP_B32_IN_LONG(dest, src) SWAP_B32_IN_B32(dest, src) +#define SWAP_B16_IN_LONG(dest, src) SWAP_B16_IN_B32(dest, src) +#define SWAP_B8_IN_LONG(dest, src) SWAP_B8_IN_B32(dest, src) #endif /* LONG_BITS == 64 */ diff --git a/cal/README b/cal/README index d7db5e3..451429c 100644 --- a/cal/README +++ b/cal/README @@ -26,9 +26,9 @@ Executing the resource file will cause several functions to be defined. Executing the lucas function: ; lucas(149,60) - 1 + 1 ; lucas(146,61) - 0 + 0 shows that 149*2^60-1 is prime whereas 146*2^61-1 is not. @@ -41,8 +41,8 @@ be useful! =-= By convention, a resource file only defines and/or initializes functions, -objects and variables. (The regress.cal and testxxx.cal regression test -suite is an exception.) Also by convention, an additional usage message +objects and variables. (The regress.cal and testxxx.cal regression test +suite is an exception.) Also by convention, an additional usage message regarding important object and functions is printed. If a resource file needs to load another resource file, it should use @@ -62,21 +62,21 @@ 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 - is displayed. + 0 When a function is defined, redefined or undefined at + interactive level, a message saying what has been done + is displayed. - 1 When a function is defined, redefined or undefined during - the reading of a file, a message saying what has been done - is displayed. + 1 When a function is defined, redefined or undefined during + 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 summary information. + 2 Show func will display more information about a functions + arguments as well as more argument summary information. - 3 During execution, allow calc standard resource files - to output additional debugging 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. @@ -87,27 +87,27 @@ either interactively or during the reading of a file. Sometimes the information printed is not enough. In addition to the standard information, one might want to print: - * useful obj definitions - * functions with optional args - * functions with optional args where the param() interface is used + * useful obj definitions + * functions with optional args + * functions with optional args where the param() interface is used For these cases we suggest that you place at the bottom of your code something that prints extra information if config("resource_debug") has either of the bottom 2 bits set: - if (config("resource_debug") & 3) { - print "obj xyz defined"; - print "funcA([val1 [, val2]]) defined"; - print "funcB(size, mass, ...) defined"; - } + if (config("resource_debug") & 3) { + print "obj xyz defined"; + print "funcA([val1 [, val2]]) defined"; + print "funcB(size, mass, ...) defined"; + } If your the resource file needs to output special debugging information, 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"; - } + if (config("resource_debug") & 8) { + print "DEBUG: This a sample debug statement"; + } =-= @@ -146,11 +146,11 @@ alg_config.cal Here is a suggested way to use this resource file: - ; read alg_config - ; config("user_debug",2),; - ; best_mul2(); best_sq2(); best_pow2(); - ; best_mul2(); best_sq2(); best_pow2(); - ; best_mul2(); best_sq2(); best_pow2(); + ; read alg_config + ; config("user_debug",2),; + ; best_mul2(); best_sq2(); best_pow2(); + ; best_mul2(); best_sq2(); best_pow2(); + ; best_mul2(); best_sq2(); best_pow2(); NOTE: It is perfectly normal for the optimal value returned to differ slightly from run to run. Slight variations due to inaccuracy in @@ -161,9 +161,9 @@ alg_config.cal config("mul2"), config("sq2"), and config("pow2"). For example one can place into ~/.calcrc these lines: - config("mul2", 1780),; - config("sq2", 3388),; - config("pow2", 176),; + config("mul2", 1780),; + config("sq2", 3388),; + config("pow2", 176),; to automatically and silently change these config values. See help/config and CALCRC in help/environment for more information. @@ -174,7 +174,7 @@ beer.cal This calc resource is calc's contribution to the 99 Bottles of Beer web page: - http://www.ionet.net/~timtroyr/funhouse/beer.html#calc + http://www.ionet.net/~timtroyr/funhouse/beer.html#calc NOTE: This resource produces a lot of output. :-) @@ -186,8 +186,8 @@ bernoulli.cal Calculate the nth Bernoulli number. NOTE: There is now a bernoulli() builtin function. This file is - left here for backward compatibility and now simply returns - the builtin function. + left here for backward compatibility and now simply returns + the builtin function. bernpoly.cal @@ -272,53 +272,53 @@ comma.cal str_comma(x, [group, [decimal]]) - Convert x into a string. + Convert x into a string. - If group is given and is a string, group will be used as - the 3-digit group separator, otherwise the default 3-digit - group separator will be used. + If group is given and is a string, group will be used as + the 3-digit group separator, otherwise the default 3-digit + group separator will be used. - If decimal is given and is a string, group will be used as - the integer-fraction separator, otherwise the default - integer-fraction separator will be used. + If decimal is given and is a string, group will be used as + the integer-fraction separator, otherwise the default + integer-fraction separator will be used. - The decimal and group arguments are optional. + The decimal and group arguments are optional. set_default_group_separator(group) - Change the default 3-digit group separator if group is a string, - otherwise the default 3-digit group separator will not be - changed. Return the old 3-digit group separator. + Change the default 3-digit group separator if group is a string, + otherwise the default 3-digit group separator will not be + changed. Return the old 3-digit group separator. set_default_decimal_separator(decimal) - Change the default 3-digit group separator if decimal is a - string, otherwise the default integer-fraction separator - will not be changed. Return the old integer-fraction separator. + Change the default 3-digit group separator if decimal is a + string, otherwise the default integer-fraction separator + will not be changed. Return the old integer-fraction separator. print_comma(x, [group, [decimal]]) - Print the value produced by str_comma(x, [group, [decimal]]) - followed by a newline. + Print the value produced by str_comma(x, [group, [decimal]]) + followed by a newline. - If the str_comma() does not return a string, nothing is printed. + If the str_comma() does not return a string, nothing is printed. - The decimal and group arguments are optional. + The decimal and group arguments are optional. - The value produced by str_comma() is returned. + The value produced by str_comma() is returned. fprint_comma(fd, x, [group, [decimal]]) - Print the value produced by str_comma(x, [group, [decimal]]), - without a trailing newline, on file fd. + Print the value produced by str_comma(x, [group, [decimal]]), + without a trailing newline, on file fd. - If the str_comma() does not return a string, nothing is printed. + If the str_comma() does not return a string, nothing is printed. - If fd is not an open file, nothing is printed. + If fd is not an open file, nothing is printed. - The decimal and group arguments are optional. + The decimal and group arguments are optional. - The value produced by str_comma() is returned. + The value produced by str_comma() is returned. deg.cal @@ -362,30 +362,30 @@ dotest.cal dotest_file - Search along CALCPATH for dotest_file, which contains lines that - should evaluate to 1. Comment lines and empty lines are ignored. - Comment lines should use ## instead of the multi like /* ... */ - because lines are evaluated one line at a time. + Search along CALCPATH for dotest_file, which contains lines that + should evaluate to 1. Comment lines and empty lines are ignored. + Comment lines should use ## instead of the multi like /* ... */ + because lines are evaluated one line at a time. dotest_code - Assign the code number that is to be printed at the start of - each non-error line and after **** in each error line. - The default code number is 999. + Assign the code number that is to be printed at the start of + each non-error line and after **** in each error line. + The default code number is 999. dotest_maxcond - The maximum number of error conditions that may be detected. - An error condition is not a sign of a problem, in some cases - a line deliberately forces an error condition. A value of -1, - the default, implies a maximum of 2147483647. + The maximum number of error conditions that may be detected. + An error condition is not a sign of a problem, in some cases + a line deliberately forces an error condition. A value of -1, + the default, implies a maximum of 2147483647. Global variables and functions must be declared ahead of time because the dotest scope of evaluation is a line at a time. For example: - read dotest.cal - read set8700.cal - dotest("set8700.line"); + read dotest.cal + read set8700.cal + dotest("set8700.line"); ellip.cal @@ -403,7 +403,7 @@ factorial.cal See: - http://en.wikipedia.org/wiki/Factorial + http://en.wikipedia.org/wiki/Factorial for information on the factorial. This function depends on the script toomcook.cal. @@ -416,7 +416,7 @@ factorial.cal the next lower prime is taking as the end point b. The end point b must not exceed 4294967291. See: - http://en.wikipedia.org/wiki/Primorial + http://en.wikipedia.org/wiki/Primorial for information on the primorial. @@ -566,54 +566,54 @@ fnv_util.cal find_fnv_prime(bits) - If bits == null(), this function will attempt to prompt stdin - for a value and provide commends on the value of bits. + If bits == null(), this function will attempt to prompt stdin + for a value and provide commends on the value of bits. - given: - bits number of bits in the hash, null() ==> prompt for value + given: + bits number of bits in the hash, null() ==> prompt for value - returns: - 0 ==> no FNV prime found - >0 ==> FNV prime + returns: + 0 ==> no FNV prime found + >0 ==> FNV prime deprecated_fnv0(bits, fnv_prime, string) - If fnv_prime == null(), this function will try to compute the FNV prime - for a hash of size bits. + If fnv_prime == null(), this function will try to compute the FNV prime + for a hash of size bits. - given: - bits number of bits in FNV hash - fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible - string string to hash + given: + bits number of bits in FNV hash + fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible + string string to hash - returns: - FNV-0 hash, for size bytes, of string + returns: + FNV-0 hash, for size bytes, of string - NOTE: This function does NOT attempt to determine that fnv_prime is prime. + NOTE: This function does NOT attempt to determine that fnv_prime is prime. fnv_offset_basis(bits, fnv_prime) - given: - bits number of bits in FNV hash - fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible + given: + bits number of bits in FNV hash + fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible - returns: - FNV offset basis for a hash size of bits and an FNV prime of fnv_prime + returns: + FNV offset basis for a hash size of bits and an FNV prime of fnv_prime - NOTE: This function does NOT attempt to determine that fnv_prime is prime. + NOTE: This function does NOT attempt to determine that fnv_prime is prime. fnv1a_style_hash(bits, fnv_prime, prev_hash, string) - given: - bits number of bits in FNV hash - fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible - prev_hash previous hash value, null() ==> generate FNV offset basis - string string to hash + given: + bits number of bits in FNV hash + fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible + prev_hash previous hash value, null() ==> generate FNV offset basis + string string to hash - returns: - "FNV-style" hash of bits + returns: + "FNV-style" hash of bits - NOTE: This function does NOT attempt to determine that fnv_prime is prime. + NOTE: This function does NOT attempt to determine that fnv_prime is prime. gvec.cal @@ -626,8 +626,8 @@ hello.cal Calc's contribution to the Hello World! page: - http://www.latech.edu/~acm/HelloWorld.shtml - http://www.latech.edu/~acm/helloworld/calc.html + http://www.latech.edu/~acm/HelloWorld.shtml + http://www.latech.edu/~acm/helloworld/calc.html NOTE: This resource produces a lot of output. :-) @@ -671,27 +671,27 @@ 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. + 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. + 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. + 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. + 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. intnum.cal @@ -733,9 +733,9 @@ intnum.cal ; define f(x){return sin(x);} f(x) defined ; quadts(0,pi()) - 2 - 0.00000000000000000000 + 0.00000000000000000000 ; quadgl(0,pi()) - 2 - 0.00000000000000000000 + 0.00000000000000000000 Sometimes rounding errors accumulate, it might be a good idea to crank up the working precision a notch or two. @@ -743,39 +743,39 @@ intnum.cal ; define f(x){ return exp(-x^2);} f(x) redefined ; quadts(0,pinf()) - pi() - 0.00000000000000000000 + 0.00000000000000000000 ; quadgl(0,pinf()) - pi() - 0.00000000000000000001 + 0.00000000000000000001 ; define f(x){ return exp(-x^2);} f(x) redefined ; quadgl(ninf(),pinf()) - sqrt(pi()) - 0.00000000000000000000 + 0.00000000000000000000 ; quadts(ninf(),pinf()) - sqrt(pi()) - -0.00000000000000000000 + -0.00000000000000000000 Using the "points" parameter is a bit tricky ; define f(x){ return 1/x; } f(x) redefined ; quadts(1,1,mat[3]={1i,-1,-1i}) - 2i*pi() - 0.00000000000000000001i + 0.00000000000000000001i ; quadgl(1,1,mat[3]={1i,-1,-1i}) - 2i*pi() - 0.00000000000000000001i + 0.00000000000000000001i The make* functions make it a bit simpler ; quadts(1,1,makepoints(1i,-1,-1i)) - 2i*pi() - 0.00000000000000000001i + 0.00000000000000000001i ; quadgl(1,1,makepoints(1i,-1,-1i)) - 2i*pi() - 0.00000000000000000001i + 0.00000000000000000001i ; define f(x){ return abs(sin(x));} f(x) redefined ; quadts(0,2*pi(),makepoints(pi())) - 4 - 0.00000000000000000000 + 0.00000000000000000000 ; quadgl(0,2*pi(),makepoints(pi())) - 4 - 0.00000000000000000000 + 0.00000000000000000000 The quad*core functions do not offer anything fancy but the third parameter controls the so called "order" which is just the number of nodes computed. @@ -785,34 +785,34 @@ intnum.cal ; define f(x){ return exp(x);} f(x) redefined ; s=usertime();quadglcore(-3,3)- (exp(3)-exp(-3));e=usertime();e-s - 0.00000000000000000001 - 2.632164 + 0.00000000000000000001 + 2.632164 ; s=usertime();quadglcore(-3,3)- (exp(3)-exp(-3));e=usertime();e-s - 0.00000000000000000001 - 0.016001 + 0.00000000000000000001 + 0.016001 ; quadgldeletenodes() ; s=usertime();quadglcore(-3,3,14)- (exp(3)-exp(-3));e=usertime();e-s - -0.00000000000000000000 - 0.024001 + -0.00000000000000000000 + 0.024001 ; s=usertime();quadglcore(-3,3,14)- (exp(3)-exp(-3));e=usertime();e-s - -0.00000000000000000000 - 0 + -0.00000000000000000000 + 0 It is not much but can sum up. The tanh-sinh algorithm is not optimizable as much as the Gauss-Legendre algorithm but is per se much faster. ; s=usertime();quadtscore(-3,3)- (exp(3)-exp(-3));e=usertime();e-s - -0.00000000000000000001 - 0.128008 + -0.00000000000000000001 + 0.128008 ; s=usertime();quadtscore(-3,3)- (exp(3)-exp(-3));e=usertime();e-s - -0.00000000000000000001 - 0.036002 + -0.00000000000000000001 + 0.036002 ; s=usertime();quadtscore(-3,3,49)- (exp(3)-exp(-3));e=usertime();e-s - -0.00000000000000000000 - 0.036002 + -0.00000000000000000000 + 0.036002 ; s=usertime();quadtscore(-3,3,49)- (exp(3)-exp(-3));e=usertime();e-s - -0.00000000000000000000 - 0.01200 + -0.00000000000000000000 + 0.01200 lambertw.cal @@ -885,7 +885,7 @@ lucas.cal prove that h*2^n-1 is prime or not prime. NOTE: Some call this term u(0). The function gen_u0(h, n, v1) - simply calls gen_u2(h, n, v1) for such people. :-) + simply calls gen_u2(h, n, v1) for such people. :-) gen_v1(h, v) @@ -925,7 +925,7 @@ mfactor.cal By default, start_k == 1, rept_loop = 10000 and p_elim = 17. The p_elim == 17 overhead takes ~3 minutes on an 200 MHz r4k CPU and - requires about ~13 Megs of memory. The p_elim == 13 overhead + requires about ~13 Megs of memory. The p_elim == 13 overhead takes about 3 seconds and requires ~1.5 Megs of memory. The value p_elim == 17 is best for long factorizations. It is the @@ -1014,19 +1014,19 @@ palindrome.cal Important functions are: - Find the next / previous palindrome: + Find the next / previous palindrome: - nextpal(val) - prevpal(val) + nextpal(val) + prevpal(val) - Test if a value is a palindrome: + Test if a value is a palindrome: - ispal(val) + ispal(val) - Find the next / previous palindrome that is a (highly probable) prime: + Find the next / previous palindrome that is a (highly probable) prime: - nextprimepal(val) - prevprimepal(val) + nextprimepal(val) + prevprimepal(val) pell.cal @@ -1073,7 +1073,7 @@ pollard.cal poly.cal - Calculate with polynomials of one variable. There are many functions. + Calculate with polynomials of one variable. There are many functions. Read the documentation in the resource file. @@ -1117,7 +1117,7 @@ quat.cal quat_scale(a, b) quat_shift(a, b) - Calculate using quaternions of the form: a + bi + cj + dk. In these + Calculate using quaternions of the form: a + bi + cj + dk. In these functions, quaternions are manipulated in the form: s + v, where s is a scalar and v is a vector of size 3. @@ -1199,17 +1199,17 @@ regress.cal screen.cal up - CUU /* same as up */ + CUU /* same as up */ down = CUD - CUD /* same as down */ + CUD /* same as down */ forward - CUF /* same as forward */ + CUF /* same as forward */ back = CUB - CUB /* same as back */ + CUB /* same as back */ save - SCP /* same as save */ + SCP /* same as save */ restore - RCP /* same as restore */ + RCP /* same as restore */ cls home eraseline @@ -1246,8 +1246,8 @@ screen.cal For example: - read screen - print green:"This is green. ":red:"This is red.":black + read screen + print green:"This is green. ":red:"This is red.":black seedrandom.cal @@ -1255,13 +1255,13 @@ seedrandom.cal seedrandom(seed1, seed2, bitsize [,trials]) Given: - seed1 - a large random value (at least 10^20 and perhaps < 10^93) - seed2 - a large random value (at least 10^20 and perhaps < 10^93) - size - min Blum modulus as a power of 2 (at least 100, perhaps > 1024) - trials - number of ptest() trials (default 25) (optional arg) + seed1 - a large random value (at least 10^20 and perhaps < 10^93) + seed2 - a large random value (at least 10^20 and perhaps < 10^93) + size - min Blum modulus as a power of 2 (at least 100, perhaps > 1024) + trials - number of ptest() trials (default 25) (optional arg) Returns: - the previous random state + the previous random state Seed the cryptographically strong Blum generator. This functions allows one to use the raw srandom() without the burden of finding appropriate @@ -1299,7 +1299,7 @@ specialfunctions.cal Calculates the value of the beta function. See: - https://en.wikipedia.org/wiki/Beta_function + https://en.wikipedia.org/wiki/Beta_function http://mathworld.wolfram.com/BetaFunction.html http://dlmf.nist.gov/5.12 @@ -1310,7 +1310,7 @@ specialfunctions.cal Calculates the value of the regularized incomplete beta function. See: - https://en.wikipedia.org/wiki/Beta_function + https://en.wikipedia.org/wiki/Beta_function http://mathworld.wolfram.com/RegularizedBetaFunction.html http://dlmf.nist.gov/8.17 @@ -1322,7 +1322,7 @@ specialfunctions.cal Calculates the value of the exponential integral Ei(z) function at z. See: - http://en.wikipedia.org/wiki/Exponential_integral + http://en.wikipedia.org/wiki/Exponential_integral http://www.cs.utah.edu/~vpegorar/research/2011_JGT/ for information on the exponential integral Ei(z) function. @@ -1332,7 +1332,7 @@ specialfunctions.cal Calculates the value of the error function at z. See: - http://en.wikipedia.org/wiki/Error_function + http://en.wikipedia.org/wiki/Error_function for information on the error function function. @@ -1341,7 +1341,7 @@ specialfunctions.cal Calculates the value of the complementary error function at z. See: - http://en.wikipedia.org/wiki/Error_function + http://en.wikipedia.org/wiki/Error_function for information on the complementary error function function. @@ -1350,7 +1350,7 @@ specialfunctions.cal Calculates the value of the imaginary error function at z. See: - http://en.wikipedia.org/wiki/Error_function + http://en.wikipedia.org/wiki/Error_function for information on the imaginary error function function. @@ -1359,7 +1359,7 @@ specialfunctions.cal Calculates the inverse of the error function at x. See: - http://en.wikipedia.org/wiki/Error_function + http://en.wikipedia.org/wiki/Error_function for information on the inverse of the error function function. @@ -1368,7 +1368,7 @@ specialfunctions.cal Calculates the value of the complex error function at z. See: - http://en.wikipedia.org/wiki/Faddeeva_function + http://en.wikipedia.org/wiki/Faddeeva_function for information on the complex error function function. @@ -1377,7 +1377,7 @@ specialfunctions.cal Calculates the value of the Euler gamma function at z. See: - http://en.wikipedia.org/wiki/Gamma_function + http://en.wikipedia.org/wiki/Gamma_function http://dlmf.nist.gov/5 for information on the Euler gamma function. @@ -1388,7 +1388,7 @@ specialfunctions.cal Calculates the value of the lower incomplete gamma function for arbitrary a, z. See: - http://en.wikipedia.org/wiki/Incomplete_gamma_function + http://en.wikipedia.org/wiki/Incomplete_gamma_function for information on the lower incomplete gamma function. @@ -1397,7 +1397,7 @@ specialfunctions.cal Calculates the value of the regularized lower incomplete gamma function for a, z with a not in -N. See: - http://en.wikipedia.org/wiki/Incomplete_gamma_function + http://en.wikipedia.org/wiki/Incomplete_gamma_function for information on the regularized lower incomplete gamma function. @@ -1406,7 +1406,7 @@ specialfunctions.cal Calculates the value of the regularized upper incomplete gamma function for a, z with a not in -N. See: - http://en.wikipedia.org/wiki/Incomplete_gamma_function + http://en.wikipedia.org/wiki/Incomplete_gamma_function for information on the regularized upper incomplete gamma function. @@ -1420,7 +1420,7 @@ specialfunctions.cal Calculates partial values of the harmonic series up to limit. See: - http://en.wikipedia.org/wiki/Harmonic_series_(mathematics) + http://en.wikipedia.org/wiki/Harmonic_series_(mathematics) http://mathworld.wolfram.com/HarmonicSeries.html for information on the harmonic series. @@ -1430,7 +1430,7 @@ specialfunctions.cal Calculates the natural logarithm of the beta function. See: - https://en.wikipedia.org/wiki/Beta_function + https://en.wikipedia.org/wiki/Beta_function http://mathworld.wolfram.com/BetaFunction.html http://dlmf.nist.gov/5.12 @@ -1441,7 +1441,7 @@ specialfunctions.cal Calculates the value of the logarithm of the Euler gamma function at z. See: - http://en.wikipedia.org/wiki/Gamma_function + http://en.wikipedia.org/wiki/Gamma_function http://dlmf.nist.gov/5.15 for information on the derivatives of the the Euler gamma function. @@ -1452,7 +1452,7 @@ specialfunctions.cal Calculates the value of the m-th derivative of the Euler gamma function at z. See: - http://en.wikipedia.org/wiki/Polygamma + http://en.wikipedia.org/wiki/Polygamma http://dlmf.nist.gov/5 for information on the n-th derivative of the Euler gamma function. This @@ -1464,7 +1464,7 @@ specialfunctions.cal Calculates the value of the first derivative of the Euler gamma function at z. See: - http://en.wikipedia.org/wiki/Digamma_function + http://en.wikipedia.org/wiki/Digamma_function http://dlmf.nist.gov/5 for information on the first derivative of the Euler gamma function. @@ -1474,7 +1474,7 @@ specialfunctions.cal Calculates the value of the Riemann Zeta function at s. See: - http://en.wikipedia.org/wiki/Riemann_zeta_function + http://en.wikipedia.org/wiki/Riemann_zeta_function http://dlmf.nist.gov/25.2 for information on the Riemann zeta function. This function depends @@ -1492,7 +1492,7 @@ splitbits.cal The number of elements in the returned list is: - ceil((highbit(x) + 1) / b) + ceil((highbit(x) + 1) / b) If x == 0, then a list of 1 element containing 0 is returned. @@ -1502,17 +1502,17 @@ splitbits.cal the integer converted as if the integer was a two's compliment value. For example: - ; L = splitbits(-1, 8); - ; print L[[0]] - 255 + ; L = splitbits(-1, 8); + ; print L[[0]] + 255 - ; L = splitbits(-2, 8); - ; print L[[0]] - 254 + ; L = splitbits(-2, 8); + ; print L[[0]] + 254 - ; L = splitbits(-3, 8); - ; print L[[0]] - 253 + ; L = splitbits(-3, 8); + ; print L[[0]] + 253 The first element of the list contains the lowest order bits of x. The last element of the list contains the highest number @@ -1520,19 +1520,19 @@ splitbits.cal For example: - ; x = 2^23209-1 - ; L = splitbits(x, 16); - ; print size(L), L[[0]] + ; x = 2^23209-1 + ; L = splitbits(x, 16); + ; print size(L), L[[0]] - ; print istype(2, 3i), istype(2, "2"), istype(2, null()) - 0 0 0 + ; print istype(2, 3i), istype(2, "2"), istype(2, null()) + 0 0 0 - ; mat a[2] - ; b = list(1,2,3) - ; c = assoc() - ; obj chongo {was, here} d; - ; print istype(a,b), istype(b,c), istype(c,d) - 0 0 0 + ; mat a[2] + ; b = list(1,2,3) + ; c = assoc() + ; obj chongo {was, here} d; + ; print istype(a,b), istype(b,c), istype(c,d) + 0 0 0 statistics.cal @@ -1596,8 +1596,8 @@ strings.cal functions in calc. WARNING: If the remaining functions in this calc resource file become - calc builtin functions, then strings.cal may be removed in - a future release. + calc builtin functions, then strings.cal may be removed in + a future release. sumsq.cal @@ -1627,7 +1627,7 @@ sumtimes.cal the list or matrix to use. The doalltimes() function will run all of the sumtimes tests. For example: - doalltimes(1e6); + doalltimes(1e6); surd.cal @@ -1883,17 +1883,17 @@ test8900.special.cal This function tests a number of calc resource functions contributed by Christoph Zurnieden. These include: - bernpoly.cal - brentsolve.cal - constants.cal - factorial2.cal - factorial.cal - lambertw.cal - lnseries.cal - specialfunctions.cal - statistics.cal - toomcook.cal - zeta2.cal + bernpoly.cal + brentsolve.cal + constants.cal + factorial2.cal + factorial.cal + lambertw.cal + lnseries.cal + specialfunctions.cal + statistics.cal + toomcook.cal + zeta2.cal test9300.frem.cal @@ -1920,14 +1920,14 @@ toomcook.cal Toom-Cook multiplication algorithm. Multiply two integers a,b by way of the Toom-Cook algorithm. See: - http://en.wikipedia.org/wiki/Toom%E2%80%93Cook_multiplication + http://en.wikipedia.org/wiki/Toom%E2%80%93Cook_multiplication toomcook3square(a) toomcook4square(a) Square the integer a by way of the Toom-Cook algorithm. See: - http://en.wikipedia.org/wiki/Toom%E2%80%93Cook_multiplication + http://en.wikipedia.org/wiki/Toom%E2%80%93Cook_multiplication The function toomCook4(a,b) calls the function toomCook3(a,b) which calls built-in multiplication at a specific cut-off point. The @@ -1981,7 +1981,7 @@ zeta2.cal Calculate the value of the Hurwitz Zeta function. See: - http://en.wikipedia.org/wiki/Hurwitz_zeta_function + http://en.wikipedia.org/wiki/Hurwitz_zeta_function http://dlmf.nist.gov/25.11 for information on this special zeta function. @@ -1997,7 +1997,7 @@ zeta2.cal ## ## 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 +## 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 @@ -2005,8 +2005,8 @@ zeta2.cal ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1990/02/15 01:50:32 -## File existed as early as: before 1990 +## Under source code control: 1990/02/15 01:50:32 +## File existed as early as: before 1990 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/cal/alg_config.cal b/cal/alg_config.cal index 7cab146..2792324 100644 --- a/cal/alg_config.cal +++ b/cal/alg_config.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,25 +17,25 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2006/06/07 14:10:11 - * File existed as early as: 2006 + * Under source code control: 2006/06/07 14:10:11 + * File existed as early as: 2006 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ -static test_time; /* try for this many seconds in loop test */ +static test_time; /* try for this many seconds in loop test */ /* * close_to_one - set to 1 if the ratio is close enough to 1 * * given: - * ratio the ratio of time between two algorithms + * ratio the ratio of time between two algorithms * * returns: - * 1 When ratio is near 1.0 - * 0 otherwise + * 1 When ratio is near 1.0 + * 0 otherwise * * We consider the range [0.995, 1.005] to be close enough to 1 to be call unity * because of the precision of the CPU timing. @@ -44,12 +44,12 @@ define close_to_one(ratio) { /* firewall */ if (!isreal(ratio)) { - quit "close: 1st arg: must be a real number"; + quit "close: 1st arg: must be a real number"; } /* check if the ratio is far from unity */ if ((ratio < 0.995) || (ratio > 1.005)) { - return 0; + return 0; } /* we are close to unity */ @@ -61,96 +61,96 @@ define close_to_one(ratio) * mul_loop - measure the CPU time to perform a set of multiply loops * * given: - * repeat number of multiply loops to perform - * x array of 5 values, each the same length in BASEB-bit words + * repeat number of multiply loops to perform + * x array of 5 values, each the same length in BASEB-bit words * - * NOTE: When their lengths are 1 BASEB-bit word, then a - * dummy loop of simple constants are used. Thus the - * length == 1 is an approximation of loop overhead. + * NOTE: When their lengths are 1 BASEB-bit word, then a + * dummy loop of simple constants are used. Thus the + * length == 1 is an approximation of loop overhead. * * returns: - * approximate runtime to perform repeat the multiply loops + * approximate runtime to perform repeat the multiply loops * * NOTE: This is an internal support function that is normally - * not called directly from the command line. Call the - * function best_mul2() instead. + * not called directly from the command line. Call the + * function best_mul2() instead. */ define mul_loop(repeat, x) { - local start; /* start of execution */ - local end; /* end of execution */ - local answer; /* multiplicand */ - local len; /* length of each element */ - local baseb_bytes; /* bytes in a BASEB-bit word */ + local start; /* start of execution */ + local end; /* end of execution */ + local answer; /* multiplicand */ + local len; /* length of each element */ + local baseb_bytes; /* bytes in a BASEB-bit word */ local i; /* firewall */ if (!isint(repeat) || repeat < 0) { - quit "mul_loop: 1st arg: repeat must be an integer > 0"; + quit "mul_loop: 1st arg: repeat must be an integer > 0"; } if (size(*x) != 5) { - quit "mul_loop: 2nd arg matrix does not have 5 elements"; + quit "mul_loop: 2nd arg matrix does not have 5 elements"; } if (matdim(*x) != 1) { - quit "mul_loop: 2nd arg matrix is not 1 dimensional"; + quit "mul_loop: 2nd arg matrix is not 1 dimensional"; } if (matmin(*x, 1) != 0) { - quit "mul_loop: 2nd arg matrix index range does not start with 0"; + quit "mul_loop: 2nd arg matrix index range does not start with 0"; } if (matmax(*x, 1) != 4) { - quit "mul_loop: 2nd arg matrix index range does not end with 4"; + quit "mul_loop: 2nd arg matrix index range does not end with 4"; } baseb_bytes = config("baseb") / 8; len = sizeof((*x)[0]) / baseb_bytes; for (i=1; i < 4; ++i) { - if ((sizeof((*x)[i]) / baseb_bytes) != len) { - quit "mul_loop: 2nd arg matrix elements are not of " - "equal BASEB-bit word length"; - } + if ((sizeof((*x)[i]) / baseb_bytes) != len) { + quit "mul_loop: 2nd arg matrix elements are not of " + "equal BASEB-bit word length"; + } } /* multiply pairwise, all sets of a given length */ start = usertime(); for (i=0; i < repeat; ++i) { - if (len == 1) { - /* we use len == 1 to test this tester loop overhead */ - answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; - /**/ - answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; - /**/ - answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; - /**/ - answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; - /**/ - answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; - } else { - answer = (*x)[0] * (*x)[1]; - answer = (*x)[0] * (*x)[2]; - answer = (*x)[0] * (*x)[3]; - answer = (*x)[0] * (*x)[4]; - /**/ - answer = (*x)[1] * (*x)[0]; - answer = (*x)[1] * (*x)[2]; - answer = (*x)[1] * (*x)[3]; - answer = (*x)[1] * (*x)[4]; - /**/ - answer = (*x)[2] * (*x)[0]; - answer = (*x)[2] * (*x)[1]; - answer = (*x)[2] * (*x)[3]; - answer = (*x)[2] * (*x)[4]; - /**/ - answer = (*x)[3] * (*x)[0]; - answer = (*x)[3] * (*x)[1]; - answer = (*x)[3] * (*x)[2]; - answer = (*x)[3] * (*x)[4]; - /**/ - answer = (*x)[4] * (*x)[0]; - answer = (*x)[4] * (*x)[1]; - answer = (*x)[4] * (*x)[2]; - answer = (*x)[4] * (*x)[3]; - } + if (len == 1) { + /* we use len == 1 to test this tester loop overhead */ + answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; + /**/ + answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; + /**/ + answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; + /**/ + answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; + /**/ + answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; answer = 0 * 0; + } else { + answer = (*x)[0] * (*x)[1]; + answer = (*x)[0] * (*x)[2]; + answer = (*x)[0] * (*x)[3]; + answer = (*x)[0] * (*x)[4]; + /**/ + answer = (*x)[1] * (*x)[0]; + answer = (*x)[1] * (*x)[2]; + answer = (*x)[1] * (*x)[3]; + answer = (*x)[1] * (*x)[4]; + /**/ + answer = (*x)[2] * (*x)[0]; + answer = (*x)[2] * (*x)[1]; + answer = (*x)[2] * (*x)[3]; + answer = (*x)[2] * (*x)[4]; + /**/ + answer = (*x)[3] * (*x)[0]; + answer = (*x)[3] * (*x)[1]; + answer = (*x)[3] * (*x)[2]; + answer = (*x)[3] * (*x)[4]; + /**/ + answer = (*x)[4] * (*x)[0]; + answer = (*x)[4] * (*x)[1]; + answer = (*x)[4] * (*x)[2]; + answer = (*x)[4] * (*x)[3]; + } } /* @@ -165,10 +165,10 @@ define mul_loop(repeat, x) * mul_ratio - ratio of rates of 1st and 2nd multiply algorithms * * given: - * len length in BASEB-bit words to multiply + * len length in BASEB-bit words to multiply * * return: - * ratio of (1st / 2nd) algorithm rate. + * ratio of (1st / 2nd) algorithm rate. * * When want to determine a rate to a precision of 1 part in 1000. * Most systems today return CPU time to at least 10 msec precision. @@ -177,28 +177,28 @@ define mul_loop(repeat, x) * which usually requires timing of loops that last 10 seconds or more. * * NOTE: This is an internal support function that is normally - * not called directly from the command line. Call the - * function best_mul2() instead. + * not called directly from the command line. Call the + * function best_mul2() instead. */ define mul_ratio(len) { - local mat x[5]; /* array of values for mul_loop to multiply */ - local mat one[5]; /* array if single BASEB-bit values */ - local baseb; /* calc word size in bits */ - local orig_cfg; /* caller configuration */ - local loops; /* number of multiply loops to time */ - local tlen; /* time to perform some number of loops */ - local tover; /* est of time for loop overhead */ - local alg1_rate; /* loop rate of 1st algorithm */ - local alg2_rate; /* loop rate of 2nd algorithm */ - local ret; /* return ratio, or 1.0 */ + local mat x[5]; /* array of values for mul_loop to multiply */ + local mat one[5]; /* array if single BASEB-bit values */ + local baseb; /* calc word size in bits */ + local orig_cfg; /* caller configuration */ + local loops; /* number of multiply loops to time */ + local tlen; /* time to perform some number of loops */ + local tover; /* est of time for loop overhead */ + local alg1_rate; /* loop rate of 1st algorithm */ + local alg2_rate; /* loop rate of 2nd algorithm */ + local ret; /* return ratio, or 1.0 */ local i; /* * firewall */ if (!isint(len) || len < 2) { - quit "mul_ratio: 1st arg: len is not an integer > 1"; + quit "mul_ratio: 1st arg: len is not an integer > 1"; } /* @@ -220,10 +220,10 @@ define mul_ratio(len) baseb = config("baseb"); srand(sha1(sha1(baseb, config("version")))); for (i=0; i < 5; ++i) { - /* force the values to be a full len words long */ - x[i] = ((1<<(((len-1) * baseb) + baseb-1)) | - randbit(((len-1) * baseb) + baseb-2)); - /* single BASEB-bit values */ + /* force the values to be a full len words long */ + x[i] = ((1<<(((len-1) * baseb) + baseb-1)) | + randbit(((len-1) * baseb) + baseb-2)); + /* single BASEB-bit values */ one[i] = 1; } @@ -233,11 +233,11 @@ define mul_ratio(len) config("mul2", 2^31-1),; loops = 1/2; do { - loops *= 2; - tlen = mul_loop(loops, &x); - if (config("user_debug") > 3) { - printf("\t alg1 loops %d took %.3f sec\n", loops, tlen); - } + loops *= 2; + tlen = mul_loop(loops, &x); + if (config("user_debug") > 3) { + printf("\t alg1 loops %d took %.3f sec\n", loops, tlen); + } } while (tlen < 1.0); /* @@ -245,32 +245,32 @@ define mul_ratio(len) */ loops = max(1, ceil(loops * test_time / tlen)); if (loops < 16) { - if (config("user_debug") > 1) { - printf(" we must expand alg1 loop test time to about %d secs\n", - ceil(test_time * (16 / loops))); - } - loops = 16; + if (config("user_debug") > 1) { + printf(" we must expand alg1 loop test time to about %d secs\n", + ceil(test_time * (16 / loops))); + } + loops = 16; } if (config("user_debug") > 3) { - printf("\t will try alg1 %d loops\n", loops); + printf("\t will try alg1 %d loops\n", loops); } tlen = mul_loop(loops, &x); if (config("user_debug") > 3) { - printf("\t alg1 time = %.3f secs\n", tlen); + printf("\t alg1 time = %.3f secs\n", tlen); } tover = mul_loop(loops, &one); if (config("user_debug") > 3) { - printf("\t alg1 overhead look %.3f secs\n", tover); + printf("\t alg1 overhead look %.3f secs\n", tover); } if (tlen <= tover) { - quit "mul_ratio: overhead >= loop time"; + quit "mul_ratio: overhead >= loop time"; } alg1_rate = loops / (tlen - tover); if (config("user_debug") > 2) { - printf("\tmultiply alg1 rate = %.3f loopsets/sec\n", alg1_rate); + printf("\tmultiply alg1 rate = %.3f loopsets/sec\n", alg1_rate); } if (alg1_rate <= 0.0) { - quit "mul_ratio: alg1 rate was <= 0.0"; + quit "mul_ratio: alg1 rate was <= 0.0"; } /* @@ -279,11 +279,11 @@ define mul_ratio(len) config("mul2", 2),; loops = 1/2; do { - loops *= 2; - tlen = mul_loop(loops, &x); - if (config("user_debug") > 3) { - printf("\t alg2 loops %d took %.3f sec\n", loops, tlen); - } + loops *= 2; + tlen = mul_loop(loops, &x); + if (config("user_debug") > 3) { + printf("\t alg2 loops %d took %.3f sec\n", loops, tlen); + } } while (tlen < 1.0); /* @@ -291,29 +291,29 @@ define mul_ratio(len) */ loops = max(1, ceil(loops * test_time / tlen)); if (loops < 16) { - if (config("user_debug") > 1) { - printf(" we must expand alg2 loop test time to about %d secs\n", - ceil(test_time * (16 / loops))); - } - loops = 16; + if (config("user_debug") > 1) { + printf(" we must expand alg2 loop test time to about %d secs\n", + ceil(test_time * (16 / loops))); + } + loops = 16; } tlen = mul_loop(loops, &x); if (config("user_debug") > 3) { - printf("\t alg2 time = %.3f secs\n", tlen); + printf("\t alg2 time = %.3f secs\n", tlen); } tover = mul_loop(loops, &one); if (config("user_debug") > 3) { - printf("\t alg2 overhead look %.3f secs\n", tover); + printf("\t alg2 overhead look %.3f secs\n", tover); } if (tlen <= tover) { - quit "mul_ratio: overhead >= loop time"; + quit "mul_ratio: overhead >= loop time"; } alg2_rate = loops / (tlen - tover); if (config("user_debug") > 2) { - printf("\tmultiply alg2 rate = %.3f loopsets/sec\n", alg2_rate); + printf("\tmultiply alg2 rate = %.3f loopsets/sec\n", alg2_rate); } if (alg2_rate <= 0.0) { - quit "mul_ratio: alg2 rate was <= 0.0"; + quit "mul_ratio: alg2 rate was <= 0.0"; } /* @@ -326,8 +326,8 @@ define mul_ratio(len) */ ret = alg1_rate / alg2_rate; if (config("user_debug") > 2) { - printf("\tprecise ratio is: %.f mul_ratio will return: %.3f\n", - alg1_rate / alg2_rate, ret); + printf("\tprecise ratio is: %.f mul_ratio will return: %.3f\n", + alg1_rate / alg2_rate, ret); } return ret; } @@ -337,25 +337,25 @@ define mul_ratio(len) * best_mul2 - determine the best config("mul2") parameter * * NOTE: Due to precision problems with CPU measurements, it is not - * unusual for the output of this function to vary slightly - * from run to run. + * unusual for the output of this function to vary slightly + * from run to run. * * NOTE: This function is designed to take a long time to run. - * We recommend setting: + * We recommend setting: * - * config("user_debug", 2) + * config("user_debug", 2) * - * so that yon can watch the progress of this function. + * so that yon can watch the progress of this function. */ define best_mul2() { - local ratio; /* previously calculated alg1/alg2 ratio */ - local low; /* low loop value tested */ - local high; /* high loop value tested */ - local mid; /* between low and high */ - local best_val; /* value found with ratio closest to unity */ - local best_ratio; /* closest ratio found to unity */ - local expand; /* how fast to expand the length */ + local ratio; /* previously calculated alg1/alg2 ratio */ + local low; /* low loop value tested */ + local high; /* high loop value tested */ + local mid; /* between low and high */ + local best_val; /* value found with ratio closest to unity */ + local best_ratio; /* closest ratio found to unity */ + local expand; /* how fast to expand the length */ /* * setup @@ -365,8 +365,8 @@ define best_mul2() printf("The best_mul2() function will take a LONG time to run!\n"); printf("It is important that best_mul2() run on an otherwise idle host!\n"); if (config("user_debug") <= 0) { - printf("To monitor progress, set user_debug to 2: " - "config(\"user_debug\", 2)\n"); + printf("To monitor progress, set user_debug to 2: " + "config(\"user_debug\", 2)\n"); } printf("Starting with loop test time of %d secs\n", test_time); @@ -376,56 +376,56 @@ define best_mul2() high = 8; best_val = high; if (config("user_debug") > 0) { - printf("testing multiply alg1/alg2 ratio for len = %d\n", high); + printf("testing multiply alg1/alg2 ratio for len = %d\n", high); } ratio = mul_ratio(high); best_ratio = ratio; if (config("user_debug") > 1) { - printf(" multiply alg1/alg2 ratio = %.6f\n", ratio); + printf(" multiply alg1/alg2 ratio = %.6f\n", ratio); } if (ratio < 1.0) { - quit "best_mul2: tests imply mul2 should be < 16, which seems bogus"; + quit "best_mul2: tests imply mul2 should be < 16, which seems bogus"; } /* * expand lengths until the ratio flips */ do { - /* - * determine the parameters of the next ratio test - * - * We will multiplicatively expand our test level until - * the ratio drops below 1.0. - */ - expand = 2; - low = high; - high *= expand; - if (config("user_debug") > 1) { - printf(" expand the next test range by a factor of %d\n", - expand); - } + /* + * determine the parameters of the next ratio test + * + * We will multiplicatively expand our test level until + * the ratio drops below 1.0. + */ + expand = 2; + low = high; + high *= expand; + if (config("user_debug") > 1) { + printf(" expand the next test range by a factor of %d\n", + expand); + } - /* - * determine the alg1/alg2 test ratio for this new length - */ - if (high >= 2^31) { - quit "best_mul2: test implies mul2 >= 2^31, which seems bogus"; - } - if (config("user_debug") > 0) { - printf("testing multiply alg1/alg2 ratio for len = %d\n", high); - } - ratio = mul_ratio(high); - if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { - best_val = high; - best_ratio = ratio; - if (config("user_debug") > 1) { - printf(" len %d has a new closest ratio to unity: %.6f\n", - best_val, best_ratio); - } - } - if (config("user_debug") > 1) { - printf(" multiply alg1/alg2 ratio = %.6f\n", ratio); - } + /* + * determine the alg1/alg2 test ratio for this new length + */ + if (high >= 2^31) { + quit "best_mul2: test implies mul2 >= 2^31, which seems bogus"; + } + if (config("user_debug") > 0) { + printf("testing multiply alg1/alg2 ratio for len = %d\n", high); + } + ratio = mul_ratio(high); + if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { + best_val = high; + best_ratio = ratio; + if (config("user_debug") > 1) { + printf(" len %d has a new closest ratio to unity: %.6f\n", + best_val, best_ratio); + } + } + if (config("user_debug") > 1) { + printf(" multiply alg1/alg2 ratio = %.6f\n", ratio); + } } while (ratio > 1.0); /* @@ -434,39 +434,39 @@ define best_mul2() * drop down powers of two until the ratio is again >= 1.0 */ if (expand > 2) { - do { + do { - /* - * contract by 2 - */ - high /= 2; - low = high / 2; - if (config("user_debug") > 0) { - printf("re-testing multiply alg1/alg2 ratio for len = %d\n", - high); - } - ratio = mul_ratio(high); - if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { - best_val = high; - best_ratio = ratio; - if (config("user_debug") > 1) { - printf(" len %d has a new closest ratio " - "to unity: %.6f\n", - best_val, best_ratio); - } - } - if (config("user_debug") > 1) { - printf(" multiply alg1/alg2 ratio = %.6f\n", ratio); - } + /* + * contract by 2 + */ + high /= 2; + low = high / 2; + if (config("user_debug") > 0) { + printf("re-testing multiply alg1/alg2 ratio for len = %d\n", + high); + } + ratio = mul_ratio(high); + if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { + best_val = high; + best_ratio = ratio; + if (config("user_debug") > 1) { + printf(" len %d has a new closest ratio " + "to unity: %.6f\n", + best_val, best_ratio); + } + } + if (config("user_debug") > 1) { + printf(" multiply alg1/alg2 ratio = %.6f\n", ratio); + } - } while (ratio <= 1.0); + } while (ratio <= 1.0); - /* now that the ratio flipped again, use the previous range */ - low = high; - high = high * 2; + /* now that the ratio flipped again, use the previous range */ + low = high; + high = high * 2; } if (config("user_debug") > 0) { - printf("Starting binary search between %d and %d\n", low, high); + printf("Starting binary search between %d and %d\n", low, high); } /* @@ -474,69 +474,69 @@ define best_mul2() */ while (low+1 < high) { - /* try the mid-point */ - mid = int((low+high)/2); - if (config("user_debug") > 0) { - printf("testing multiply alg1/alg2 ratio for len = %d\n", mid); - } - ratio = mul_ratio(mid); - if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { - best_val = mid; - best_ratio = ratio; - if (config("user_debug") > 1) { - printf(" len %d has a new closest ratio to unity: %.6f\n", - best_val, best_ratio); - } - } - if (config("user_debug") > 1) { - printf(" len %d multiply alg1/alg2 ratio = %.6f\n", mid, ratio); - } + /* try the mid-point */ + mid = int((low+high)/2); + if (config("user_debug") > 0) { + printf("testing multiply alg1/alg2 ratio for len = %d\n", mid); + } + ratio = mul_ratio(mid); + if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { + best_val = mid; + best_ratio = ratio; + if (config("user_debug") > 1) { + printf(" len %d has a new closest ratio to unity: %.6f\n", + best_val, best_ratio); + } + } + if (config("user_debug") > 1) { + printf(" len %d multiply alg1/alg2 ratio = %.6f\n", mid, ratio); + } - /* stop search if near unity */ - if (close_to_one(ratio)) { - low = mid; - high = mid; - if (config("user_debug") > 0) { - printf("\twe are close enough to unity ratio at: %d\n", mid); - } - break; - } + /* stop search if near unity */ + if (close_to_one(ratio)) { + low = mid; + high = mid; + if (config("user_debug") > 0) { + printf("\twe are close enough to unity ratio at: %d\n", mid); + } + break; + } - /* bump lower range up if we went over */ - if (ratio > 1.0) { - if (config("user_debug") > 2) { - printf("\tmove low from %d up to %d\n", - low, mid); - } - low = mid; + /* bump lower range up if we went over */ + if (ratio > 1.0) { + if (config("user_debug") > 2) { + printf("\tmove low from %d up to %d\n", + low, mid); + } + low = mid; - /* drop higher range down if we went under */ - } else { - if (config("user_debug") > 2) { - printf("\tmove high from %d down to %d\n", - high, mid); - } - high = mid; - } + /* drop higher range down if we went under */ + } else { + if (config("user_debug") > 2) { + printf("\tmove high from %d down to %d\n", + high, mid); + } + high = mid; + } - /* report on test loop progress */ - if (config("user_debug") > 1) { - printf("\tsetting low: %d high: %d diff: %d\n", - low, high, high-low); - } + /* report on test loop progress */ + if (config("user_debug") > 1) { + printf("\tsetting low: %d high: %d diff: %d\n", + low, high, high-low); + } } /* * return on the suggested config("mul2") value */ if (config("user_debug") > 0) { - printf("Best value for multiply is near %d\n", best_val); - printf("Best multiply alg1/alg2 ratio is: %.6f\n", best_ratio); - printf("We suggest placing this line in your .calcrc:\n"); - printf("config(\"mul2\", %d),;\n", best_val); - printf("WARNING: It is believed that the output " - "of this resource file is bogus!\n"); - printf("WARNING: You may NOT wish to follow the above suggestion.\n"); + printf("Best value for multiply is near %d\n", best_val); + printf("Best multiply alg1/alg2 ratio is: %.6f\n", best_ratio); + printf("We suggest placing this line in your .calcrc:\n"); + printf("config(\"mul2\", %d),;\n", best_val); + printf("WARNING: It is believed that the output " + "of this resource file is bogus!\n"); + printf("WARNING: You may NOT wish to follow the above suggestion.\n"); } return mid; } @@ -546,96 +546,96 @@ define best_mul2() * sq_loop - measure the CPU time to perform a set of square loops * * given: - * repeat number of square loops to perform - * x array of 5 values, each the same length in BASEB-bit words + * repeat number of square loops to perform + * x array of 5 values, each the same length in BASEB-bit words * - * NOTE: When their lengths are 1 BASEB-bit word, then a - * dummy loop of simple constants are used. Thus the - * length == 1 is an approximation of loop overhead. + * NOTE: When their lengths are 1 BASEB-bit word, then a + * dummy loop of simple constants are used. Thus the + * length == 1 is an approximation of loop overhead. * returns: - * approximate runtime to perform a square loop + * approximate runtime to perform a square loop * * NOTE: This is an internal support function that is normally - * not called directly from the command line. Call the - * function best_sq2() instead. + * not called directly from the command line. Call the + * function best_sq2() instead. */ define sq_loop(repeat, x) { - local start; /* start of execution */ - local end; /* end of execution */ - local answer; /* squared value */ - local len; /* length of each element */ - local baseb_bytes; /* bytes in a BASEB-bit word */ + local start; /* start of execution */ + local end; /* end of execution */ + local answer; /* squared value */ + local len; /* length of each element */ + local baseb_bytes; /* bytes in a BASEB-bit word */ local i; /* firewall */ if (!isint(repeat) || repeat < 0) { - quit "sq_loop: 1st arg: repeat must be an integer > 0"; + quit "sq_loop: 1st arg: repeat must be an integer > 0"; } if (size(*x) != 5) { - quit "sq_loop: 2nd arg matrix does not have 5 elements"; + quit "sq_loop: 2nd arg matrix does not have 5 elements"; } if (matdim(*x) != 1) { - quit "sq_loop: 2nd arg matrix is not 1 dimensional"; + quit "sq_loop: 2nd arg matrix is not 1 dimensional"; } if (matmin(*x, 1) != 0) { - quit "sq_loop: 2nd arg matrix index range does not start with 0"; + quit "sq_loop: 2nd arg matrix index range does not start with 0"; } if (matmax(*x, 1) != 4) { - quit "sq_loop: 2nd arg matrix index range does not end with 4"; + quit "sq_loop: 2nd arg matrix index range does not end with 4"; } baseb_bytes = config("baseb") / 8; len = sizeof((*x)[0]) / baseb_bytes; for (i=1; i < 4; ++i) { - if ((sizeof((*x)[i]) / baseb_bytes) != len) { - quit "sq_loop: 2nd arg matrix elements are not of equal " - "BASEB-bit word length"; - } + if ((sizeof((*x)[i]) / baseb_bytes) != len) { + quit "sq_loop: 2nd arg matrix elements are not of equal " + "BASEB-bit word length"; + } } /* square pairwise, all sets of a given length */ start = usertime(); for (i=0; i < repeat; ++i) { - if (len == 1) { - /* we use len == 1 to test this tester loop overhead */ - answer = 0^2; answer = 0^2; answer = 0^2; answer = 0^2; - answer = 0^2; - /**/ - answer = 0^2; answer = 0^2; answer = 0^2; answer = 0^2; - answer = 0^2; - /**/ - answer = 0^2; answer = 0^2; answer = 0^2; answer = 0^2; - answer = 0^2; - /**/ - answer = 0^2; answer = 0^2; answer = 0^2; answer = 0^2; - answer = 0^2; - } else { - /* one square loop */ - answer = (*x)[0]^2; - answer = (*x)[1]^2; - answer = (*x)[2]^2; - answer = (*x)[3]^2; - answer = (*x)[4]^2; - /**/ - answer = (*x)[0]^2; - answer = (*x)[1]^2; - answer = (*x)[2]^2; - answer = (*x)[3]^2; - answer = (*x)[4]^2; - /**/ - answer = (*x)[0]^2; - answer = (*x)[1]^2; - answer = (*x)[2]^2; - answer = (*x)[3]^2; - answer = (*x)[4]^2; - /**/ - answer = (*x)[0]^2; - answer = (*x)[1]^2; - answer = (*x)[2]^2; - answer = (*x)[3]^2; - answer = (*x)[4]^2; - } + if (len == 1) { + /* we use len == 1 to test this tester loop overhead */ + answer = 0^2; answer = 0^2; answer = 0^2; answer = 0^2; + answer = 0^2; + /**/ + answer = 0^2; answer = 0^2; answer = 0^2; answer = 0^2; + answer = 0^2; + /**/ + answer = 0^2; answer = 0^2; answer = 0^2; answer = 0^2; + answer = 0^2; + /**/ + answer = 0^2; answer = 0^2; answer = 0^2; answer = 0^2; + answer = 0^2; + } else { + /* one square loop */ + answer = (*x)[0]^2; + answer = (*x)[1]^2; + answer = (*x)[2]^2; + answer = (*x)[3]^2; + answer = (*x)[4]^2; + /**/ + answer = (*x)[0]^2; + answer = (*x)[1]^2; + answer = (*x)[2]^2; + answer = (*x)[3]^2; + answer = (*x)[4]^2; + /**/ + answer = (*x)[0]^2; + answer = (*x)[1]^2; + answer = (*x)[2]^2; + answer = (*x)[3]^2; + answer = (*x)[4]^2; + /**/ + answer = (*x)[0]^2; + answer = (*x)[1]^2; + answer = (*x)[2]^2; + answer = (*x)[3]^2; + answer = (*x)[4]^2; + } } /* @@ -650,10 +650,10 @@ define sq_loop(repeat, x) * sq_ratio - ratio of rates of 1st and 2nd square algorithms * * given: - * len length in BASEB-bit words to square + * len length in BASEB-bit words to square * * return: - * ratio of (1st / 2nd) algorithm rates + * ratio of (1st / 2nd) algorithm rates * * When want to determine a rate to a precision of 1 part in 1000. * Most systems today return CPU time to at least 10 msec precision. @@ -662,28 +662,28 @@ define sq_loop(repeat, x) * which usually requires timing of loops that last 10 seconds or more. * * NOTE: This is an internal support function that is normally - * not called directly from the command line. Call the - * function best_sq2() instead. + * not called directly from the command line. Call the + * function best_sq2() instead. */ define sq_ratio(len) { - local mat x[5]; /* array of values for sq_loop to square */ - local mat one[5]; /* array if single BASEB-bit values */ - local baseb; /* calc word size in bits */ - local orig_cfg; /* caller configuration */ - local loops; /* number of square loops to time */ - local tlen; /* time to perform some number of loops */ - local tover; /* est of time for loop overhead */ - local alg1_rate; /* loop rate of 1st algorithm */ - local alg2_rate; /* loop rate of 2nd algorithm */ - local ret; /* return ratio, or 1.0 */ + local mat x[5]; /* array of values for sq_loop to square */ + local mat one[5]; /* array if single BASEB-bit values */ + local baseb; /* calc word size in bits */ + local orig_cfg; /* caller configuration */ + local loops; /* number of square loops to time */ + local tlen; /* time to perform some number of loops */ + local tover; /* est of time for loop overhead */ + local alg1_rate; /* loop rate of 1st algorithm */ + local alg2_rate; /* loop rate of 2nd algorithm */ + local ret; /* return ratio, or 1.0 */ local i; /* * firewall */ if (!isint(len) || len < 2) { - quit "sq_ratio: 1st arg: len is not an integer > 1"; + quit "sq_ratio: 1st arg: len is not an integer > 1"; } /* @@ -705,10 +705,10 @@ define sq_ratio(len) baseb = config("baseb"); srand(sha1(sha1(baseb, config("version")))); for (i=0; i < 5; ++i) { - /* force the values to be a full len words long */ - x[i] = ((1<<(((len-1) * baseb) + baseb-1)) | - randbit(((len-1) * baseb) + baseb-2)); - /* single BASEB-bit values */ + /* force the values to be a full len words long */ + x[i] = ((1<<(((len-1) * baseb) + baseb-1)) | + randbit(((len-1) * baseb) + baseb-2)); + /* single BASEB-bit values */ one[i] = 1; } @@ -718,11 +718,11 @@ define sq_ratio(len) config("sq2", 2^31-1),; loops = 1/2; do { - loops *= 2; - tlen = sq_loop(loops, &x); - if (config("user_debug") > 3) { - printf("\t alg1 loops %d took %.3f sec\n", loops, tlen); - } + loops *= 2; + tlen = sq_loop(loops, &x); + if (config("user_debug") > 3) { + printf("\t alg1 loops %d took %.3f sec\n", loops, tlen); + } } while (tlen < 1.0); /* @@ -730,29 +730,29 @@ define sq_ratio(len) */ loops = max(1, ceil(loops * test_time / tlen)); if (loops < 16) { - if (config("user_debug") > 1) { - printf(" we must expand alg1 loop test time to about %d secs\n", - ceil(test_time * (16 / loops))); - } - loops = 16; + if (config("user_debug") > 1) { + printf(" we must expand alg1 loop test time to about %d secs\n", + ceil(test_time * (16 / loops))); + } + loops = 16; } tlen = sq_loop(loops, &x); if (config("user_debug") > 3) { - printf("\t alg1 time = %.3f secs\n", tlen); + printf("\t alg1 time = %.3f secs\n", tlen); } tover = sq_loop(loops, &one); if (config("user_debug") > 3) { - printf("\t alg1 overhead look %.3f secs\n", tover); + printf("\t alg1 overhead look %.3f secs\n", tover); } if (tlen <= tover) { - quit "sq_ratio: overhead >= loop time"; + quit "sq_ratio: overhead >= loop time"; } alg1_rate = loops / (tlen - tover); if (config("user_debug") > 2) { - printf("\tsquare alg1 rate = %.3f loopsets/sec\n", alg1_rate); + printf("\tsquare alg1 rate = %.3f loopsets/sec\n", alg1_rate); } if (alg1_rate <= 0.0) { - quit "sq_ratio: alg1 rate was <= 0.0"; + quit "sq_ratio: alg1 rate was <= 0.0"; } /* @@ -761,11 +761,11 @@ define sq_ratio(len) config("sq2", 2),; loops = 1/2; do { - loops *= 2; - tlen = sq_loop(loops, &x); - if (config("user_debug") > 3) { - printf("\t alg2 loops %d took %.3f sec\n", loops, tlen); - } + loops *= 2; + tlen = sq_loop(loops, &x); + if (config("user_debug") > 3) { + printf("\t alg2 loops %d took %.3f sec\n", loops, tlen); + } } while (tlen < 1.0); /* @@ -773,29 +773,29 @@ define sq_ratio(len) */ loops = max(1, ceil(loops * test_time / tlen)); if (loops < 16) { - if (config("user_debug") > 1) { - printf(" we must expand alg2 loop test time to about %d secs\n", - ceil(test_time * (16 / loops))); - } - loops = 16; + if (config("user_debug") > 1) { + printf(" we must expand alg2 loop test time to about %d secs\n", + ceil(test_time * (16 / loops))); + } + loops = 16; } tlen = sq_loop(loops, &x); if (config("user_debug") > 3) { - printf("\t alg2 time = %.3f secs\n", tlen); + printf("\t alg2 time = %.3f secs\n", tlen); } tover = sq_loop(loops, &one); if (config("user_debug") > 3) { - printf("\t alg2 overhead look %.3f secs\n", tover); + printf("\t alg2 overhead look %.3f secs\n", tover); } if (tlen <= tover) { - quit "sq_ratio: overhead >= loop time"; + quit "sq_ratio: overhead >= loop time"; } alg2_rate = loops / (tlen - tover); if (config("user_debug") > 2) { - printf("\tsquare alg2 rate = %.3f loopsets/sec\n", alg2_rate); + printf("\tsquare alg2 rate = %.3f loopsets/sec\n", alg2_rate); } if (alg2_rate <= 0.0) { - quit "sq_ratio: alg2 rate was <= 0.0"; + quit "sq_ratio: alg2 rate was <= 0.0"; } /* @@ -808,8 +808,8 @@ define sq_ratio(len) */ ret = alg1_rate / alg2_rate; if (config("user_debug") > 2) { - printf("\tprecise ratio is: %.f sq_ratio will return: %.3f\n", - alg1_rate / alg2_rate, ret); + printf("\tprecise ratio is: %.f sq_ratio will return: %.3f\n", + alg1_rate / alg2_rate, ret); } return ret; } @@ -819,25 +819,25 @@ define sq_ratio(len) * best_sq2 - determine the best config("sq2") parameter * * NOTE: Due to precision problems with CPU measurements, it is not - * unusual for the output of this function to vary slightly - * from run to run. + * unusual for the output of this function to vary slightly + * from run to run. * * NOTE: This function is designed to take a long time to run. - * We recommend setting: + * We recommend setting: * - * config("user_debug", 2) + * config("user_debug", 2) * - * so that yon can watch the progress of this function. + * so that yon can watch the progress of this function. */ define best_sq2() { - local ratio; /* previously calculated alg1/alg2 ratio */ - local low; /* low loop value tested */ - local high; /* high loop value tested */ - local mid; /* between low and high */ - local best_val; /* value found with ratio closest to unity */ - local best_ratio; /* closest ratio found to unity */ - local expand; /* how fast to expand the length */ + local ratio; /* previously calculated alg1/alg2 ratio */ + local low; /* low loop value tested */ + local high; /* high loop value tested */ + local mid; /* between low and high */ + local best_val; /* value found with ratio closest to unity */ + local best_ratio; /* closest ratio found to unity */ + local expand; /* how fast to expand the length */ /* * setup @@ -847,8 +847,8 @@ define best_sq2() printf("The best_sq2() function will take a LONG time to run!\n"); printf("It is important that best_sq2() run on an otherwise idle host!\n"); if (config("user_debug") <= 0) { - printf("To monitor progress, set user_debug to 2: " - "config(\"user_debug\", 2)\n"); + printf("To monitor progress, set user_debug to 2: " + "config(\"user_debug\", 2)\n"); } printf("Starting with loop test time of %d secs\n", test_time); @@ -858,56 +858,56 @@ define best_sq2() high = 8; best_val = high; if (config("user_debug") > 0) { - printf("testing square alg1/alg2 ratio for len = %d\n", high); + printf("testing square alg1/alg2 ratio for len = %d\n", high); } ratio = sq_ratio(high); best_ratio = ratio; if (config("user_debug") > 1) { - printf(" square alg1/alg2 ratio = %.3f\n", ratio); + printf(" square alg1/alg2 ratio = %.3f\n", ratio); } if (ratio < 1.0) { - quit "best_sq2: test implies sq2 < 16, which seems bogus"; + quit "best_sq2: test implies sq2 < 16, which seems bogus"; } /* * expand lengths until the ratio flips */ do { - /* - * determine the parameters of the next ratio test - * - * We will multiplicatively expand our test level until - * the ratio drops below 1.0. - */ - expand = 2; - low = high; - high *= expand; - if (config("user_debug") > 1) { - printf(" expand the next test range by a factor of %d\n", - expand); - } + /* + * determine the parameters of the next ratio test + * + * We will multiplicatively expand our test level until + * the ratio drops below 1.0. + */ + expand = 2; + low = high; + high *= expand; + if (config("user_debug") > 1) { + printf(" expand the next test range by a factor of %d\n", + expand); + } - /* - * determine the alg1/alg2 test ratio for this new length - */ - if (high >= 2^31) { - quit "best_sq2: tests imply sq2 >= 2^31, which seems bogus"; - } - if (config("user_debug") > 0) { - printf("testing square alg1/alg2 ratio for len = %d\n", high); - } - ratio = sq_ratio(high); - if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { - best_val = high; - best_ratio = ratio; - if (config("user_debug") > 1) { - printf(" len %d has a new closest ratio to unity: %.6f\n", - best_val, best_ratio); - } - } - if (config("user_debug") > 1) { - printf(" square alg1/alg2 ratio = %.3f\n", ratio); - } + /* + * determine the alg1/alg2 test ratio for this new length + */ + if (high >= 2^31) { + quit "best_sq2: tests imply sq2 >= 2^31, which seems bogus"; + } + if (config("user_debug") > 0) { + printf("testing square alg1/alg2 ratio for len = %d\n", high); + } + ratio = sq_ratio(high); + if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { + best_val = high; + best_ratio = ratio; + if (config("user_debug") > 1) { + printf(" len %d has a new closest ratio to unity: %.6f\n", + best_val, best_ratio); + } + } + if (config("user_debug") > 1) { + printf(" square alg1/alg2 ratio = %.3f\n", ratio); + } } while (ratio > 1.0); /* @@ -916,39 +916,39 @@ define best_sq2() * drop down powers of two until the ratio is again >= 1.0 */ if (expand > 2) { - do { + do { - /* - * contract by 2 - */ - high /= 2; - low = high / 2; - if (config("user_debug") > 0) { - printf("re-testing multiply alg1/alg2 ratio for len = %d\n", - high); - } - ratio = mul_ratio(high); - if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { - best_val = high; - best_ratio = ratio; - if (config("user_debug") > 1) { - printf(" len %d has a new closest ratio " - "to unity: %.6f\n", - best_val, best_ratio); - } - } - if (config("user_debug") > 1) { - printf(" multiply alg1/alg2 ratio = %.6f\n", ratio); - } + /* + * contract by 2 + */ + high /= 2; + low = high / 2; + if (config("user_debug") > 0) { + printf("re-testing multiply alg1/alg2 ratio for len = %d\n", + high); + } + ratio = mul_ratio(high); + if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { + best_val = high; + best_ratio = ratio; + if (config("user_debug") > 1) { + printf(" len %d has a new closest ratio " + "to unity: %.6f\n", + best_val, best_ratio); + } + } + if (config("user_debug") > 1) { + printf(" multiply alg1/alg2 ratio = %.6f\n", ratio); + } - } while (ratio <= 1.0); + } while (ratio <= 1.0); - /* now that the ratio flipped again, use the previous range */ - low = high; - high = high * 2; + /* now that the ratio flipped again, use the previous range */ + low = high; + high = high * 2; } if (config("user_debug") > 0) { - printf("Starting binary search between %d and %d\n", low, high); + printf("Starting binary search between %d and %d\n", low, high); } /* @@ -956,56 +956,56 @@ define best_sq2() */ while (low+1 < high) { - /* try the mid-point */ - mid = int((low+high)/2); - if (config("user_debug") > 0) { - printf("testing square alg1/alg2 ratio for len = %d\n", mid); - } - ratio = sq_ratio(mid); - if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { - best_val = mid; - best_ratio = ratio; - if (config("user_debug") > 1) { - printf(" len %d has a new closest ratio to unity: %.6f\n", - best_val, best_ratio); - } - } - if (config("user_debug") > 1) { - printf(" len %d square alg1/alg2 ratio = %.6f\n", mid, ratio); - } + /* try the mid-point */ + mid = int((low+high)/2); + if (config("user_debug") > 0) { + printf("testing square alg1/alg2 ratio for len = %d\n", mid); + } + ratio = sq_ratio(mid); + if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { + best_val = mid; + best_ratio = ratio; + if (config("user_debug") > 1) { + printf(" len %d has a new closest ratio to unity: %.6f\n", + best_val, best_ratio); + } + } + if (config("user_debug") > 1) { + printf(" len %d square alg1/alg2 ratio = %.6f\n", mid, ratio); + } - /* stop search if near unity */ - if (close_to_one(ratio)) { - low = mid; - high = mid; - if (config("user_debug") > 0) { - printf("\twe are close enough to unity ratio at: %d\n", mid); - } - break; - } + /* stop search if near unity */ + if (close_to_one(ratio)) { + low = mid; + high = mid; + if (config("user_debug") > 0) { + printf("\twe are close enough to unity ratio at: %d\n", mid); + } + break; + } - /* bump lower range up if we went over */ - if (ratio > 1.0) { - if (config("user_debug") > 2) { - printf("\tmove low from %d up to %d\n", - low, mid); - } - low = mid; + /* bump lower range up if we went over */ + if (ratio > 1.0) { + if (config("user_debug") > 2) { + printf("\tmove low from %d up to %d\n", + low, mid); + } + low = mid; - /* drop higher range down if we went under */ - } else { - if (config("user_debug") > 2) { - printf("\tmove high from %d down to %d\n", - high, mid); - } - high = mid; - } + /* drop higher range down if we went under */ + } else { + if (config("user_debug") > 2) { + printf("\tmove high from %d down to %d\n", + high, mid); + } + high = mid; + } - /* report on test loop progress */ - if (config("user_debug") > 1) { - printf("\tsetting low: %d high: %d diff: %d\n", - low, high, high-low); - } + /* report on test loop progress */ + if (config("user_debug") > 1) { + printf("\tsetting low: %d high: %d diff: %d\n", + low, high, high-low); + } } /* @@ -1013,13 +1013,13 @@ define best_sq2() */ mid = int((low+high)/2); if (config("user_debug") > 0) { - printf("Best value for square is near %d\n", best_val); - printf("Best square alg1/alg2 ratio is: %.6f\n", best_ratio); - printf("We suggest placing this line in your .calcrc:\n"); - printf("config(\"sq2\", %d),;\n", best_val); - printf("WARNING: It is believed that the output " - "of this resource file is bogus!\n"); - printf("WARNING: You may NOT wish to follow the above suggestion.\n"); + printf("Best value for square is near %d\n", best_val); + printf("Best square alg1/alg2 ratio is: %.6f\n", best_ratio); + printf("We suggest placing this line in your .calcrc:\n"); + printf("config(\"sq2\", %d),;\n", best_val); + printf("WARNING: It is believed that the output " + "of this resource file is bogus!\n"); + printf("WARNING: You may NOT wish to follow the above suggestion.\n"); } return mid; } @@ -1029,108 +1029,108 @@ define best_sq2() * pow_loop - measure the CPU time to perform a set of pmod loops * * given: - * repeat number of pmod loops to perform - * x array of 5 values, each the same length in BASEB-bit words + * repeat number of pmod loops to perform + * x array of 5 values, each the same length in BASEB-bit words * - * NOTE: When their lengths are 1 BASEB-bit word, then a - * dummy loop of simple constants are used. Thus the - * length == 1 is an approximation of loop overhead. + * NOTE: When their lengths are 1 BASEB-bit word, then a + * dummy loop of simple constants are used. Thus the + * length == 1 is an approximation of loop overhead. * - * ex exponent for pmod value + * ex exponent for pmod value * * returns: - * approximate runtime to perform a pmod loop + * approximate runtime to perform a pmod loop * * NOTE: This is an internal support function that is normally - * not called directly from the command line. Call the - * function best_pow2() instead. + * not called directly from the command line. Call the + * function best_pow2() instead. */ define pow_loop(repeat, x, ex) { - local start; /* start of execution */ - local end; /* end of execution */ - local answer; /* pmod value */ - local len; /* length of each element */ - local baseb_bytes; /* bytes in a BASEB-bit word */ + local start; /* start of execution */ + local end; /* end of execution */ + local answer; /* pmod value */ + local len; /* length of each element */ + local baseb_bytes; /* bytes in a BASEB-bit word */ local i; /* firewall */ if (!isint(repeat) || repeat < 0) { - quit "pow_loop: 1st arg: repeat must be an integer > 0"; + quit "pow_loop: 1st arg: repeat must be an integer > 0"; } if (size(*x) != 5) { - quit "pow_loop: 2nd arg matrix does not have 5 elements"; + quit "pow_loop: 2nd arg matrix does not have 5 elements"; } if (matdim(*x) != 1) { - quit "pow_loop: 2nd arg matrix is not 1 dimensional"; + quit "pow_loop: 2nd arg matrix is not 1 dimensional"; } if (matmin(*x, 1) != 0) { - quit "pow_loop: 2nd arg matrix index range does not start with 0"; + quit "pow_loop: 2nd arg matrix index range does not start with 0"; } if (matmax(*x, 1) != 4) { - quit "pow_loop: 2nd arg matrix index range does not end with 4"; + quit "pow_loop: 2nd arg matrix index range does not end with 4"; } baseb_bytes = config("baseb") / 8; len = sizeof((*x)[0]) / baseb_bytes; for (i=1; i < 4; ++i) { - if ((sizeof((*x)[i]) / baseb_bytes) != len) { - quit "pow_loop: 2nd arg matrix elements are not of " - "equal BASEB-bit word length"; - } + if ((sizeof((*x)[i]) / baseb_bytes) != len) { + quit "pow_loop: 2nd arg matrix elements are not of " + "equal BASEB-bit word length"; + } } if (!isint(ex) || ex < 3) { - quit" pow_loop: 3rd arg ex is not an integer > 2"; + quit" pow_loop: 3rd arg ex is not an integer > 2"; } /* pmod pairwise, all sets of a given length */ start = usertime(); for (i=0; i < repeat; ++i) { - if (len == 1) { - /* we use len == 1 to test this tester loop overhead */ - answer = pmod(0,0,0); answer = pmod(0,0,0); - answer = pmod(0,0,0); answer = pmod(0,0,0); - /**/ - answer = pmod(0,0,0); answer = pmod(0,0,0); - answer = pmod(0,0,0); answer = pmod(0,0,0); - /**/ - answer = pmod(0,0,0); answer = pmod(0,0,0); - answer = pmod(0,0,0); answer = pmod(0,0,0); - /**/ - answer = pmod(0,0,0); answer = pmod(0,0,0); - answer = pmod(0,0,0); answer = pmod(0,0,0); - /**/ - answer = pmod(0,0,0); answer = pmod(0,0,0); - answer = pmod(0,0,0); answer = pmod(0,0,0); - /**/ - answer = pmod(0,0,0); answer = pmod(0,0,0); - answer = pmod(0,0,0); answer = pmod(0,0,0); - } else { - answer = pmod((*x)[0], ex, (*x)[1]); - answer = pmod((*x)[0], ex, (*x)[2]); - answer = pmod((*x)[0], ex, (*x)[3]); - answer = pmod((*x)[0], ex, (*x)[4]); - /**/ - answer = pmod((*x)[1], ex, (*x)[0]); - answer = pmod((*x)[1], ex, (*x)[2]); - answer = pmod((*x)[1], ex, (*x)[3]); - answer = pmod((*x)[1], ex, (*x)[4]); - /**/ - answer = pmod((*x)[2], ex, (*x)[0]); - answer = pmod((*x)[2], ex, (*x)[1]); - answer = pmod((*x)[2], ex, (*x)[3]); - answer = pmod((*x)[2], ex, (*x)[4]); - /**/ - answer = pmod((*x)[3], ex, (*x)[0]); - answer = pmod((*x)[3], ex, (*x)[1]); - answer = pmod((*x)[3], ex, (*x)[2]); - answer = pmod((*x)[3], ex, (*x)[4]); - /**/ - answer = pmod((*x)[4], ex, (*x)[0]); - answer = pmod((*x)[4], ex, (*x)[1]); - answer = pmod((*x)[4], ex, (*x)[2]); - answer = pmod((*x)[4], ex, (*x)[3]); - } + if (len == 1) { + /* we use len == 1 to test this tester loop overhead */ + answer = pmod(0,0,0); answer = pmod(0,0,0); + answer = pmod(0,0,0); answer = pmod(0,0,0); + /**/ + answer = pmod(0,0,0); answer = pmod(0,0,0); + answer = pmod(0,0,0); answer = pmod(0,0,0); + /**/ + answer = pmod(0,0,0); answer = pmod(0,0,0); + answer = pmod(0,0,0); answer = pmod(0,0,0); + /**/ + answer = pmod(0,0,0); answer = pmod(0,0,0); + answer = pmod(0,0,0); answer = pmod(0,0,0); + /**/ + answer = pmod(0,0,0); answer = pmod(0,0,0); + answer = pmod(0,0,0); answer = pmod(0,0,0); + /**/ + answer = pmod(0,0,0); answer = pmod(0,0,0); + answer = pmod(0,0,0); answer = pmod(0,0,0); + } else { + answer = pmod((*x)[0], ex, (*x)[1]); + answer = pmod((*x)[0], ex, (*x)[2]); + answer = pmod((*x)[0], ex, (*x)[3]); + answer = pmod((*x)[0], ex, (*x)[4]); + /**/ + answer = pmod((*x)[1], ex, (*x)[0]); + answer = pmod((*x)[1], ex, (*x)[2]); + answer = pmod((*x)[1], ex, (*x)[3]); + answer = pmod((*x)[1], ex, (*x)[4]); + /**/ + answer = pmod((*x)[2], ex, (*x)[0]); + answer = pmod((*x)[2], ex, (*x)[1]); + answer = pmod((*x)[2], ex, (*x)[3]); + answer = pmod((*x)[2], ex, (*x)[4]); + /**/ + answer = pmod((*x)[3], ex, (*x)[0]); + answer = pmod((*x)[3], ex, (*x)[1]); + answer = pmod((*x)[3], ex, (*x)[2]); + answer = pmod((*x)[3], ex, (*x)[4]); + /**/ + answer = pmod((*x)[4], ex, (*x)[0]); + answer = pmod((*x)[4], ex, (*x)[1]); + answer = pmod((*x)[4], ex, (*x)[2]); + answer = pmod((*x)[4], ex, (*x)[3]); + } } /* @@ -1145,10 +1145,10 @@ define pow_loop(repeat, x, ex) * pow_ratio - ratio of rates of 1st and 2nd pmod algorithms * * given: - * len length in BASEB-bit words to pmod + * len length in BASEB-bit words to pmod * * return: - * ratio of (1st / 2nd) algorithm rates + * ratio of (1st / 2nd) algorithm rates * * When want to determine a rate to a precision of 1 part in 1000. * Most systems today return CPU time to at least 10 msec precision. @@ -1157,29 +1157,29 @@ define pow_loop(repeat, x, ex) * which usually requires timing of loops that last 10 seconds or more. * * NOTE: This is an internal support function that is normally - * not called directly from the command line. Call the - * function best_pow2() instead. + * not called directly from the command line. Call the + * function best_pow2() instead. */ define pow_ratio(len) { - local mat x[5]; /* array of values for pow_loop to pmod */ - local mat one[5]; /* array if single BASEB-bit values */ - local baseb; /* calc word size in bits */ - local orig_cfg; /* caller configuration */ - local loops; /* number of pmod loops to time */ - local tlen; /* time to perform some number of loops */ - local tover; /* est of time for loop overhead */ - local alg1_rate; /* loop rate of 1st algorithm */ - local alg2_rate; /* loop rate of 2nd algorithm */ - local ex; /* exponent to use in pow_loop() */ - local ret; /* return ratio, or 1.0 */ + local mat x[5]; /* array of values for pow_loop to pmod */ + local mat one[5]; /* array if single BASEB-bit values */ + local baseb; /* calc word size in bits */ + local orig_cfg; /* caller configuration */ + local loops; /* number of pmod loops to time */ + local tlen; /* time to perform some number of loops */ + local tover; /* est of time for loop overhead */ + local alg1_rate; /* loop rate of 1st algorithm */ + local alg2_rate; /* loop rate of 2nd algorithm */ + local ex; /* exponent to use in pow_loop() */ + local ret; /* return ratio, or 1.0 */ local i; /* * firewall */ if (!isint(len) || len < 2) { - quit "pow_ratio: 1st arg: len is not an integer > 1"; + quit "pow_ratio: 1st arg: len is not an integer > 1"; } /* @@ -1206,10 +1206,10 @@ define pow_ratio(len) baseb = config("baseb"); srand(sha1(sha1(ex, baseb, config("version")))); for (i=0; i < 5; ++i) { - /* force the values to be a full len words long */ - x[i] = ((1<<(((len-1) * baseb) + baseb-1)) | - randbit(((len-1) * baseb) + baseb-2)); - /* single BASEB-bit values */ + /* force the values to be a full len words long */ + x[i] = ((1<<(((len-1) * baseb) + baseb-1)) | + randbit(((len-1) * baseb) + baseb-2)); + /* single BASEB-bit values */ one[i] = 1; } @@ -1220,11 +1220,11 @@ define pow_ratio(len) config("redc2", 2^31-1),; loops = 1/2; do { - loops *= 2; - tlen = pow_loop(loops, &x, ex); - if (config("user_debug") > 3) { - printf("\t alg1 loops %d took %.3f sec\n", loops, tlen); - } + loops *= 2; + tlen = pow_loop(loops, &x, ex); + if (config("user_debug") > 3) { + printf("\t alg1 loops %d took %.3f sec\n", loops, tlen); + } } while (tlen < 1.0); /* @@ -1232,29 +1232,29 @@ define pow_ratio(len) */ loops = max(1, ceil(loops * test_time / tlen)); if (loops < 16) { - if (config("user_debug") > 1) { - printf(" we must expand alg1 loop test time to about %d secs\n", - ceil(test_time * (16 / loops))); - } - loops = 16; + if (config("user_debug") > 1) { + printf(" we must expand alg1 loop test time to about %d secs\n", + ceil(test_time * (16 / loops))); + } + loops = 16; } tlen = pow_loop(loops, &x, ex); if (config("user_debug") > 3) { - printf("\t alg1 time = %.3f secs\n", tlen); + printf("\t alg1 time = %.3f secs\n", tlen); } tover = pow_loop(loops, &one, ex); if (config("user_debug") > 3) { - printf("\t alg1 overhead look %.3f secs\n", tover); + printf("\t alg1 overhead look %.3f secs\n", tover); } if (tlen <= tover) { - quit "pow_ratio: overhead >= loop time"; + quit "pow_ratio: overhead >= loop time"; } alg1_rate = loops / (tlen - tover); if (config("user_debug") > 2) { - printf("\tpmod alg1 rate = %.3f loopsets/sec\n", alg1_rate); + printf("\tpmod alg1 rate = %.3f loopsets/sec\n", alg1_rate); } if (alg1_rate <= 0.0) { - quit "pow_ratio: alg1 rate was <= 0.0"; + quit "pow_ratio: alg1 rate was <= 0.0"; } /* @@ -1264,11 +1264,11 @@ define pow_ratio(len) config("redc2", 2^31-1),; loops = 1/2; do { - loops *= 2; - tlen = pow_loop(loops, &x, ex); - if (config("user_debug") > 3) { - printf("\t alg2 loops %d took %.3f sec\n", loops, tlen); - } + loops *= 2; + tlen = pow_loop(loops, &x, ex); + if (config("user_debug") > 3) { + printf("\t alg2 loops %d took %.3f sec\n", loops, tlen); + } } while (tlen < 1.0); /* @@ -1276,29 +1276,29 @@ define pow_ratio(len) */ loops = max(1, ceil(loops * test_time / tlen)); if (loops < 16) { - if (config("user_debug") > 1) { - printf(" we must expand alg2 loop test time to about %d secs\n", - ceil(test_time * (16 / loops))); - } - loops = 16; + if (config("user_debug") > 1) { + printf(" we must expand alg2 loop test time to about %d secs\n", + ceil(test_time * (16 / loops))); + } + loops = 16; } tlen = pow_loop(loops, &x, ex); if (config("user_debug") > 3) { - printf("\t alg2 time = %.3f secs\n", tlen); + printf("\t alg2 time = %.3f secs\n", tlen); } tover = pow_loop(loops, &one, ex); if (config("user_debug") > 3) { - printf("\t alg2 overhead look %.3f secs\n", tover); + printf("\t alg2 overhead look %.3f secs\n", tover); } if (tlen <= tover) { - quit "pow_ratio: overhead >= loop time"; + quit "pow_ratio: overhead >= loop time"; } alg2_rate = loops / (tlen - tover); if (config("user_debug") > 2) { - printf("\tpmod alg2 rate = %.3f loopsets/sec\n", alg2_rate); + printf("\tpmod alg2 rate = %.3f loopsets/sec\n", alg2_rate); } if (alg2_rate <= 0.0) { - quit "pow_ratio: alg2 rate was <= 0.0"; + quit "pow_ratio: alg2 rate was <= 0.0"; } /* @@ -1311,8 +1311,8 @@ define pow_ratio(len) */ ret = alg1_rate / alg2_rate; if (config("user_debug") > 2) { - printf("\tprecise ratio is: %.f pow_ratio will return: %.3f\n", - alg1_rate / alg2_rate, ret); + printf("\tprecise ratio is: %.f pow_ratio will return: %.3f\n", + alg1_rate / alg2_rate, ret); } return ret; } @@ -1322,26 +1322,26 @@ define pow_ratio(len) * best_pow2 - determine the best config("pow2") parameter w/o REDC2 * * NOTE: Due to precision problems with CPU measurements, it is not - * unusual for the output of this function to vary slightly - * from run to run. + * unusual for the output of this function to vary slightly + * from run to run. * * NOTE: This function is designed to take a long time to run. - * We recommend setting: + * We recommend setting: * - * config("user_debug", 2) + * config("user_debug", 2) * - * so that yon can watch the progress of this function. + * so that yon can watch the progress of this function. */ define best_pow2() { - local ratio; /* previously calculated alg1/alg2 ratio */ - local low; /* low loop value tested */ - local high; /* high loop value tested */ - local mid; /* between low and high */ - local best_val; /* value found with ratio closest to unity */ - local best_ratio; /* closest ratio found to unity */ - local expand; /* how fast to expand the length */ - local looped; /* 1 ==> we have expanded lengths before */ + local ratio; /* previously calculated alg1/alg2 ratio */ + local low; /* low loop value tested */ + local high; /* high loop value tested */ + local mid; /* between low and high */ + local best_val; /* value found with ratio closest to unity */ + local best_ratio; /* closest ratio found to unity */ + local expand; /* how fast to expand the length */ + local looped; /* 1 ==> we have expanded lengths before */ /* * setup @@ -1351,8 +1351,8 @@ define best_pow2() printf("The best_pow2() function will take a LONG time to run!\n"); printf("It is important that best_pow2() run on an otherwise idle host!\n"); if (config("user_debug") <= 0) { - printf("To monitor progress, set user_debug to 2: " - "config(\"user_debug\", 2)\n"); + printf("To monitor progress, set user_debug to 2: " + "config(\"user_debug\", 2)\n"); } printf("Starting with loop test time of %d secs\n", test_time); @@ -1366,31 +1366,31 @@ define best_pow2() low = 4; high = 4; best_val = high; - best_ratio = 1e10; /* not a real value */ + best_ratio = 1e10; /* not a real value */ do { - high *= 4; - if (config("user_debug") > 0) { - printf("testing pmod alg1/alg2 ratio for len = %d\n", high); - } - ratio = pow_ratio(high); - if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { - best_val = high; - best_ratio = ratio; - if (config("user_debug") > 1) { - printf(" len %d has a new closest ratio to unity: %.6f\n", - best_val, best_ratio); - } - } - if (config("user_debug") > 1) { - printf(" pmod alg1/alg2 ratio = %.3f\n", ratio); - if (ratio > 1.0 && ratio <= 1.02) { - printf(" while alg1 is slightly better than alg2, " - "it is not clearly better\n"); - } - } + high *= 4; + if (config("user_debug") > 0) { + printf("testing pmod alg1/alg2 ratio for len = %d\n", high); + } + ratio = pow_ratio(high); + if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { + best_val = high; + best_ratio = ratio; + if (config("user_debug") > 1) { + printf(" len %d has a new closest ratio to unity: %.6f\n", + best_val, best_ratio); + } + } + if (config("user_debug") > 1) { + printf(" pmod alg1/alg2 ratio = %.3f\n", ratio); + if (ratio > 1.0 && ratio <= 1.02) { + printf(" while alg1 is slightly better than alg2, " + "it is not clearly better\n"); + } + } } while (ratio <= 1.02); if (config("user_debug") > 0) { - printf("starting the pow2 search above %d\n", high); + printf("starting the pow2 search above %d\n", high); } /* @@ -1398,56 +1398,56 @@ define best_pow2() */ looped = 0; do { - /* - * determine the parameters of the next ratio test - * - * We will multiplicatively expand our test level until - * the ratio drops below 1.0. - * - * NOTE: At low lengths, the ratios seen to be very small - * so we force an expansion of 4 to speed us on our - * way to larger lengths. At these somewhat larger - * lengths, the ratios usually don't get faster than - * 1.25, so we need to expand force a more rapid - * expansion than normal. At lengths longer than - * 2k, the time to test becomes very long, so we - * want to slow down at these higher lengths. - */ - expand = 2; - if (looped) { - low = high; - } - high *= expand; - if (config("user_debug") > 1) { - printf(" expand the next test range by a factor of %d\n", - expand); - } + /* + * determine the parameters of the next ratio test + * + * We will multiplicatively expand our test level until + * the ratio drops below 1.0. + * + * NOTE: At low lengths, the ratios seen to be very small + * so we force an expansion of 4 to speed us on our + * way to larger lengths. At these somewhat larger + * lengths, the ratios usually don't get faster than + * 1.25, so we need to expand force a more rapid + * expansion than normal. At lengths longer than + * 2k, the time to test becomes very long, so we + * want to slow down at these higher lengths. + */ + expand = 2; + if (looped) { + low = high; + } + high *= expand; + if (config("user_debug") > 1) { + printf(" expand the next test range by a factor of %d\n", + expand); + } - /* - * determine the alg1/alg2 test ratio for this new length - */ - if (high >= 2^31) { - quit "best_pow2: test implies pow2 >= 2^31, which seems bogus"; - } - if (config("user_debug") > 0) { - printf("testing pmod alg1/alg2 ratio for len = %d\n", high); - } - ratio = pow_ratio(high); - if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { - best_val = high; - best_ratio = ratio; - if (config("user_debug") > 1) { - printf(" len %d has a new closest ratio to unity: %.6f\n", - best_val, best_ratio); - } - } - if (config("user_debug") > 1) { - printf(" pmod alg1/alg2 ratio = %.6f\n", ratio); - } - looped = 1; + /* + * determine the alg1/alg2 test ratio for this new length + */ + if (high >= 2^31) { + quit "best_pow2: test implies pow2 >= 2^31, which seems bogus"; + } + if (config("user_debug") > 0) { + printf("testing pmod alg1/alg2 ratio for len = %d\n", high); + } + ratio = pow_ratio(high); + if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { + best_val = high; + best_ratio = ratio; + if (config("user_debug") > 1) { + printf(" len %d has a new closest ratio to unity: %.6f\n", + best_val, best_ratio); + } + } + if (config("user_debug") > 1) { + printf(" pmod alg1/alg2 ratio = %.6f\n", ratio); + } + looped = 1; } while (ratio > 1.0); if (config("user_debug") > 0) { - printf("Starting binary search between %d and %d\n", low, high); + printf("Starting binary search between %d and %d\n", low, high); } /* @@ -1455,56 +1455,56 @@ define best_pow2() */ while (low+1 < high) { - /* try the mid-point */ - mid = int((low+high)/2); - if (config("user_debug") > 0) { - printf("testing pow2 alg1/alg2 ratio for len = %d\n", mid); - } - ratio = pow_ratio(mid); - if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { - best_val = mid; - best_ratio = ratio; - if (config("user_debug") > 1) { - printf(" len %d has a new closest ratio to unity: %.6f\n", - best_val, best_ratio); - } - } - if (config("user_debug") > 1) { - printf(" len %d pmod alg1/alg2 ratio = %.6f\n", mid, ratio); - } + /* try the mid-point */ + mid = int((low+high)/2); + if (config("user_debug") > 0) { + printf("testing pow2 alg1/alg2 ratio for len = %d\n", mid); + } + ratio = pow_ratio(mid); + if (abs(ratio - 1.0) < abs(best_ratio - 1.0)) { + best_val = mid; + best_ratio = ratio; + if (config("user_debug") > 1) { + printf(" len %d has a new closest ratio to unity: %.6f\n", + best_val, best_ratio); + } + } + if (config("user_debug") > 1) { + printf(" len %d pmod alg1/alg2 ratio = %.6f\n", mid, ratio); + } - /* stop search if near unity */ - if (close_to_one(ratio)) { - low = mid; - high = mid; - if (config("user_debug") > 0) { - printf("\twe are close enough to unity ratio at: %d\n", mid); - } - break; - } + /* stop search if near unity */ + if (close_to_one(ratio)) { + low = mid; + high = mid; + if (config("user_debug") > 0) { + printf("\twe are close enough to unity ratio at: %d\n", mid); + } + break; + } - /* bump lower range up if we went over */ - if (ratio > 1.0) { - if (config("user_debug") > 2) { - printf("\tmove low from %d up to %d\n", - low, mid); - } - low = mid; + /* bump lower range up if we went over */ + if (ratio > 1.0) { + if (config("user_debug") > 2) { + printf("\tmove low from %d up to %d\n", + low, mid); + } + low = mid; - /* drop higher range down if we went under */ - } else { - if (config("user_debug") > 2) { - printf("\tmove high from %d down to %d\n", - high, mid); - } - high = mid; - } + /* drop higher range down if we went under */ + } else { + if (config("user_debug") > 2) { + printf("\tmove high from %d down to %d\n", + high, mid); + } + high = mid; + } - /* report on test loop progress */ - if (config("user_debug") > 1) { - printf("\tsetting low: %d high: %d diff: %d\n", - low, high, high-low); - } + /* report on test loop progress */ + if (config("user_debug") > 1) { + printf("\tsetting low: %d high: %d diff: %d\n", + low, high, high-low); + } } /* @@ -1512,13 +1512,13 @@ define best_pow2() */ mid = int((low+high)/2); if (config("user_debug") > 0) { - printf("Best value for pmod is near %d\n", best_val); - printf("Best pmod alg1/alg2 ratio is: %.6f\n", best_ratio); - printf("We suggest placing this line in your .calcrc:\n"); - printf("config(\"pow2\", %d),;\n", best_val); - printf("WARNING: It is believed that the output " - "of this resource file is bogus!\n"); - printf("WARNING: You may NOT wish to follow the above suggestion.\n"); + printf("Best value for pmod is near %d\n", best_val); + printf("Best pmod alg1/alg2 ratio is: %.6f\n", best_ratio); + printf("We suggest placing this line in your .calcrc:\n"); + printf("config(\"pow2\", %d),;\n", best_val); + printf("WARNING: It is believed that the output " + "of this resource file is bogus!\n"); + printf("WARNING: You may NOT wish to follow the above suggestion.\n"); } return mid; } diff --git a/cal/beer.cal b/cal/beer.cal index 61788bb..bd8e8d8 100644 --- a/cal/beer.cal +++ b/cal/beer.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1996/11/13 13:21:05 - * File existed as early as: 1996 + * Under source code control: 1996/11/13 13:21:05 + * File existed as early as: 1996 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -30,17 +30,17 @@ for (i=99; i > 0;) { - /* current wall state */ - some_bottles = (i != 1) ? "bottles" : "bottle"; - print i, some_bottles, "of beer on the wall,",; - print i, some_bottles, "of beer!"; + /* current wall state */ + some_bottles = (i != 1) ? "bottles" : "bottle"; + print i, some_bottles, "of beer on the wall,",; + print i, some_bottles, "of beer!"; - /* glug, glug */ - --i; - print "Take one down and pass it around,",; + /* glug, glug */ + --i; + print "Take one down and pass it around,",; - /* new wall state */ - less = (i > 0) ? i : "no"; - bottles = (i!=1) ? "bottles" : "bottle"; - print less, bottles, "of beer on the wall!\n"; + /* new wall state */ + less = (i > 0) ? i : "no"; + bottles = (i!=1) ? "bottles" : "bottle"; + print less, bottles, "of beer on the wall!\n"; } diff --git a/cal/bernoulli.cal b/cal/bernoulli.cal index a6ed208..9e4e4de 100644 --- a/cal/bernoulli.cal +++ b/cal/bernoulli.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1991/09/30 11:18:41 - * File existed as early as: 1991 + * Under source code control: 1991/09/30 11:18:41 + * File existed as early as: 1991 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -30,16 +30,16 @@ * * The non-builtin code used the following symbolic formula to calculate B(n): * - * (b+1)^(n+1) - b^(n+1) = 0 + * (b+1)^(n+1) - b^(n+1) = 0 * * where b is a dummy value, and each power b^i gets replaced by B(i). * For example, for n = 3: * - * (b+1)^4 - b^4 = 0 - * b^4 + 4*b^3 + 6*b^2 + 4*b + 1 - b^4 = 0 - * 4*b^3 + 6*b^2 + 4*b + 1 = 0 - * 4*B(3) + 6*B(2) + 4*B(1) + 1 = 0 - * B(3) = -(6*B(2) + 4*B(1) + 1) / 4 + * (b+1)^4 - b^4 = 0 + * b^4 + 4*b^3 + 6*b^2 + 4*b + 1 - b^4 = 0 + * 4*b^3 + 6*b^2 + 4*b + 1 = 0 + * 4*B(3) + 6*B(2) + 4*B(1) + 1 = 0 + * B(3) = -(6*B(2) + 4*B(1) + 1) / 4 * * The combinatorial factors in the expansion of the above formula are * calculated interactively, and we use the fact that B(2i+1) = 0 if i > 0. @@ -56,38 +56,38 @@ static mat Bn[1001]; define B(n) { /* - local nn, np1, i, sum, mulval, divval, combval; + local nn, np1, i, sum, mulval, divval, combval; - if (!isint(n) || (n < 0)) - quit "Non-negative integer required for Bernoulli"; + if (!isint(n) || (n < 0)) + quit "Non-negative integer required for Bernoulli"; - if (n == 0) - return 1; - if (n == 1) - return -1/2; - if (isodd(n)) - return 0; - if (n > 1000) - quit "Very large Bernoulli"; + if (n == 0) + return 1; + if (n == 1) + return -1/2; + if (isodd(n)) + return 0; + if (n > 1000) + quit "Very large Bernoulli"; - if (n <= Bnmax) - return Bn[n]; + if (n <= Bnmax) + return Bn[n]; - for (nn = Bnmax + 2; nn <= n; nn+=2) { - np1 = nn + 1; - mulval = np1; - divval = 1; - combval = 1; - sum = 1 - np1 / 2; - for (i = 2; i < np1; i+=2) { - combval = combval * mulval-- / divval++; - combval = combval * mulval-- / divval++; - sum += combval * Bn[i]; - } - Bn[nn] = -sum / np1; - } - Bnmax = n; - return Bn[n]; + for (nn = Bnmax + 2; nn <= n; nn+=2) { + np1 = nn + 1; + mulval = np1; + divval = 1; + combval = 1; + sum = 1 - np1 / 2; + for (i = 2; i < np1; i+=2) { + combval = combval * mulval-- / divval++; + combval = combval * mulval-- / divval++; + sum += combval * Bn[i]; + } + Bn[nn] = -sum / np1; + } + Bnmax = n; + return Bn[n]; */ - return bernoulli(n); + return bernoulli(n); } diff --git a/cal/bernpoly.cal b/cal/bernpoly.cal index 8911abb..2a85b2f 100644 --- a/cal/bernpoly.cal +++ b/cal/bernpoly.cal @@ -17,8 +17,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2013/08/11 01:31:28 - * File existed as early as: 2013 + * Under source code control: 2013/08/11 01:31:28 + * File existed as early as: 2013 */ diff --git a/cal/bigprime.cal b/cal/bigprime.cal index 56bbc12..983b9f1 100644 --- a/cal/bigprime.cal +++ b/cal/bigprime.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,29 +17,29 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1991/05/22 21:56:32 - * File existed as early as: 1991 + * Under source code control: 1991/05/22 21:56:32 + * File existed as early as: 1991 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ define bigprime(a, m, p) { - local n1, n; + local n1, n; - n1 = 2^m * p; - for (;;) { - m++; - n1 += n1; - n = n1 + 1; - if (isodd(m)) - continue; - print m; - if (pmod(a, n1 / 2, n) != n1) - continue; - if (pmod(a, n1 / p, n) == 1) - continue; - print " " : n; - } + n1 = 2^m * p; + for (;;) { + m++; + n1 += n1; + n = n1 + 1; + if (isodd(m)) + continue; + print m; + if (pmod(a, n1 / 2, n) != n1) + continue; + if (pmod(a, n1 / p, n) == 1) + continue; + print " " : n; + } } diff --git a/cal/bindings b/cal/bindings index 92c75f9..bc33214 100644 --- a/cal/bindings +++ b/cal/bindings @@ -8,7 +8,7 @@ # # 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 +# 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 @@ -16,56 +16,56 @@ # received a copy with calc; if not, write to Free Software Foundation, Inc. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # -# Under source code control: 1993/05/02 20:09:19 -# File existed as early as: 1993 +# Under source code control: 1993/05/02 20:09:19 +# File existed as early as: 1993 # # Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ # NOTE: This facility is ignored if calc was compiled with GNU-readline. -# In that case, the standard readline mechanisms (see readline(3)) -# are used in place of those found below. +# In that case, the standard readline mechanisms (see readline(3)) +# are used in place of those found below. -map base-map +map base-map default insert-char -^@ set-mark -^A start-of-line -^B backward-char -^D delete-char -^E end-of-line -^F forward-char -^H backward-kill-char -^J new-line -^K kill-line -^L refresh-line -^M new-line -^N forward-history -^O save-line -^P backward-history -^R reverse-search -^T swap-chars -^U flush-input -^V quote-char -^W kill-region -^Y yank -^? backward-kill-char -^[ ignore-char esc-map +^@ set-mark +^A start-of-line +^B backward-char +^D delete-char +^E end-of-line +^F forward-char +^H backward-kill-char +^J new-line +^K kill-line +^L refresh-line +^M new-line +^N forward-history +^O save-line +^P backward-history +^R reverse-search +^T swap-chars +^U flush-input +^V quote-char +^W kill-region +^Y yank +^? backward-kill-char +^[ ignore-char esc-map -map esc-map -default ignore-char base-map -G start-of-line -H backward-history -P forward-history -K backward-char -M forward-char -O end-of-line -S delete-char -g goto-line -s backward-word -t forward-word -d forward-kill-word -u uppercase-word -l lowercase-word -h list-history -^[ flush-input -[ arrow-key +map esc-map +default ignore-char base-map +G start-of-line +H backward-history +P forward-history +K backward-char +M forward-char +O end-of-line +S delete-char +g goto-line +s backward-word +t forward-word +d forward-kill-word +u uppercase-word +l lowercase-word +h list-history +^[ flush-input +[ arrow-key diff --git a/cal/brentsolve.cal b/cal/brentsolve.cal index 32f81f4..a67a22c 100644 --- a/cal/brentsolve.cal +++ b/cal/brentsolve.cal @@ -17,8 +17,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2013/08/11 01:31:28 - * File existed as early as: 2013 + * Under source code control: 2013/08/11 01:31:28 + * File existed as early as: 2013 */ diff --git a/cal/chi.cal b/cal/chi.cal index b854d25..407ecf9 100644 --- a/cal/chi.cal +++ b/cal/chi.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2001/03/27 14:10:11 - * File existed as early as: 2001 + * Under source code control: 2001/03/27 14:10:11 + * File existed as early as: 2001 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -29,20 +29,20 @@ * Z(x) * * From Handbook of Mathematical Functions - * 10th printing, Dec 1972 with corrections - * National Bureau of Standards + * 10th printing, Dec 1972 with corrections + * National Bureau of Standards * * Section 26.2.1, p931. */ define Z(x, eps_term) { - local eps; /* error term */ + local eps; /* error term */ /* obtain the error term */ if (isnull(eps_term)) { - eps = epsilon(); + eps = epsilon(); } else { - eps = eps_term; + eps = eps_term; } /* compute Z(x) value */ @@ -56,46 +56,46 @@ define Z(x, eps_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 + * 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)}; + * 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 + * 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 */ + 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(); + eps = epsilon(); } else { - eps = eps_term; + eps = eps_term; } /* firewall */ if (x <= 0) { - if (x == 0) { - return 0; /* hack */ - } else { - quit "Q(x[,eps]) 1st argument must be >= 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"; + quit "Q(x[,eps]) 2nd argument must be > 0"; } /* @@ -103,17 +103,17 @@ define P(x, eps_term) */ x2 = x*x; x_term = x; - s = x_term; /* 1st term */ + 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; + /* compute the term */ + odd_term += 2; + odd_prod *= odd_term; + x_term *= x2; + term = x_term / odd_prod; + s += term; } while (term >= eps); @@ -133,68 +133,68 @@ define P(x, eps_term) * a sufficiently small error term as the degrees gets large (>100). * * NOTE: This function does not work well with odd degrees of freedom. - * Can somebody help / find a bug / provide a better method of - * this odd degrees of freedom case? + * 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. + * 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 + * 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)}); + * 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) + * chi = sqrt(chi_sq) * - * NOTE: Q(x) = 1-P(x) + * 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)) } ); + * 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) + * chi = sqrt(chi_sq) * * Observe that: * - * Z(x) = exp(-x*x/2) / sqrt(2*pi()); (Section 26.2.1, p931) + * 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) + * 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(....){...} ); + * 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; /* denominator (2*4*6*... or 1*3*5...) */ - local chi_term; /* chi_sq^r */ - local ret; /* return value */ + local eps; /* error term */ + local r; /* index in finite sum */ + local r_lim; /* limit value for r */ + local s; /* sum */ + local d; /* denominator (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(); + eps = epsilon(); } else { - eps = eps_term; + eps = eps_term; } /* @@ -202,45 +202,45 @@ define chi_prob(chi_sq, v, eps_term) */ if (isodd(v)) { - local chi; /* sqrt(chi_sq) */ + 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; + /* 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; - } + /* 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; + /* 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; + /* 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; - } + /* 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; + /* apply factor - see observation in the main comment above */ + ret = exp(-chi_sq/2, eps) * s; } return ret; diff --git a/cal/chrem.cal b/cal/chrem.cal index aeb9581..3e98cf9 100644 --- a/cal/chrem.cal +++ b/cal/chrem.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,33 +19,33 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1992/09/26 01:00:47 - * File existed as early as: 1992 + * Under source code control: 1992/09/26 01:00:47 + * File existed as early as: 1992 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * When possible, chrem finds solutions for x of a set of congruence * of the form: * - * x = r1 (mod m1) - * x = r2 (mod m2) - * ... + * x = r1 (mod m1) + * x = r2 (mod m2) + * ... * * where the residues r1, r2, ... and the moduli m1, m2, ... are * given integers. The Chinese remainder theorem states that if * m1, m2, ... are relatively prime in pairs, the above congruence - * have a unique solution modulo m1 * m2 * ... If m1, m2, ... + * have a unique solution modulo m1 * m2 * ... If m1, m2, ... * are not relatively prime in pairs, it is possible that no solution * exists. If solutions exist, the general solution is expressible as: * - * x = r (mod m) + * x = r (mod m) * - * where m = lcm(m1,m2,...), and if m > 0, 0 <= r < m. This + * where m = lcm(m1,m2,...), and if m > 0, 0 <= r < m. This * solution may be interpreted as: * - * x = r + k * m [[NOTE 1]] + * x = r + k * m [[NOTE 1]] * * where k is an arbitrary integer. * @@ -53,19 +53,19 @@ * * usage: * - * chrem(r1,m1 [,r2,m2, ...]) + * chrem(r1,m1 [,r2,m2, ...]) * - * r1, r2, ... remainder integers or null values - * m1, m2, ... moduli integers + * r1, r2, ... remainder integers or null values + * m1, m2, ... moduli integers * - * chrem(r_list, [m_list]) + * chrem(r_list, [m_list]) * - * r_list list (r1,r2, ...) - * m_list list (m1,m2, ...) + * r_list list (r1,r2, ...) + * m_list list (m1,m2, ...) * - * If m_list is omitted, then 'defaultmlist' is used. - * This default list is a global value that may be changed - * by the user. Initially it is the first 8 primes. + * If m_list is omitted, then 'defaultmlist' is used. + * This default list is a global value that may be changed + * by the user. Initially it is the first 8 primes. * * If a remainder is null(), then the corresponding congruence is * ignored. This is useful when working with a fixed list of moduli. @@ -75,17 +75,17 @@ * * The moduli may be any integers, not necessarily relatively prime in * pairs (as required for the Chinese remainder theorem). Any moduli - * may be zero; x = r (mod 0) has the meaning of x = r. + * may be zero; x = r (mod 0) has the meaning of x = r. * * returns: * * If args were integer pairs: * - * r ('r' is defined above, see [[NOTE 1]]) + * r ('r' is defined above, see [[NOTE 1]]) * * If 1 or 2 list args were given: * - * (r, m) ('r' and 'm' are defined above, see [[NOTE 1]]) + * (r, m) ('r' and 'm' are defined above, see [[NOTE 1]]) * * NOTE: In all cases, null() is returned if there is no solution. * @@ -95,20 +95,20 @@ * * Sun-Tsu, 1st century A.D. * - * To find a number for which the reminders after division by 3, 5, 7 - * are 2, 3, 2, respectively: + * To find a number for which the reminders after division by 3, 5, 7 + * are 2, 3, 2, respectively: * - * chrem(2,3,3,5,2,7) ---> 23 + * chrem(2,3,3,5,2,7) ---> 23 * * Fibonacci, 13th century A.D. * - * To find a number divisible by 7 which leaves remainder 1 when - * divided by 2, 3, 4, 5, or 6: + * To find a number divisible by 7 which leaves remainder 1 when + * divided by 2, 3, 4, 5, or 6: * * - * chrem(list(0,1,1,1,1,1),list(7,2,3,4,5,6)) ---> (301,420) + * chrem(list(0,1,1,1,1,1),list(7,2,3,4,5,6)) ---> (301,420) * - * i.e., any value that is 301 mod 420. + * i.e., any value that is 301 mod 420. */ @@ -116,10 +116,10 @@ static defaultmlist = list(2,3,5,7,11,13,17,19); /* The first eight primes */ define chrem() { - local argc; /* number of args given */ - local rlist; /* reminder list - ri */ - local mlist; /* modulus list - mi */ - local list_args; /* true => args given are lists, not r1,m1, ... */ + local argc; /* number of args given */ + local rlist; /* reminder list - ri */ + local mlist; /* modulus list - mi */ + local list_args; /* true => args given are lists, not r1,m1, ... */ local m,z,r,y,d,t,x,u,i; /* @@ -127,25 +127,25 @@ define chrem() */ argc = param(0); if (argc == 0) { - quit "usage: chrem(r1,m1 [,r2,m2 ...]) or chrem(r_list, m_list)"; + quit "usage: chrem(r1,m1 [,r2,m2 ...]) or chrem(r_list, m_list)"; } list_args = islist(param(1)); if (list_args) { - rlist = param(1); - mlist = (argc == 1) ? defaultmlist : param(2); - if (size(rlist) > size(mlist)) { - quit "too many residues"; - } + rlist = param(1); + mlist = (argc == 1) ? defaultmlist : param(2); + if (size(rlist) > size(mlist)) { + quit "too many residues"; + } } else { - if (argc % 2 == 1) { - quit "odd number integers given"; - } - rlist = list(); - mlist = list(); - for (i=1; i <= argc; i+=2) { - push(rlist, param(i)); - push(mlist, param(i+1)); - } + if (argc % 2 == 1) { + quit "odd number integers given"; + } + rlist = list(); + mlist = list(); + for (i=1; i <= argc; i+=2) { + push(rlist, param(i)); + push(mlist, param(i+1)); + } } /* @@ -154,46 +154,46 @@ define chrem() m = 1; z = 0; while (size(rlist)) { - r=pop(rlist); - y=abs(pop(mlist)); - if (r==null()) - continue; - if (m) { - if (y) { - d = t = z - r; - m = lcm(x=m, y); - while (d % y) { - u = x; - x %= y; - swap(x,y); - if (y==0) - return; - z += (t *= -u/y); - } - } else { - if ((r % m) != (z % m)) - return; - else { - m = 0; - z = r; - } - } - } else if (((y) && (r % y != z % y)) || (r != z)) - return; + r=pop(rlist); + y=abs(pop(mlist)); + if (r==null()) + continue; + if (m) { + if (y) { + d = t = z - r; + m = lcm(x=m, y); + while (d % y) { + u = x; + x %= y; + swap(x,y); + if (y==0) + return; + z += (t *= -u/y); + } + } else { + if ((r % m) != (z % m)) + return; + else { + m = 0; + z = r; + } + } + } else if (((y) && (r % y != z % y)) || (r != z)) + return; } if (m) { - z %= m; - if (z < 0) - z += m; + z %= m; + if (z < 0) + z += m; } /* * return information as required */ if (list_args) { - return list(z,m); + return list(z,m); } else { - return z; + return z; } } diff --git a/cal/comma.cal b/cal/comma.cal index f1a3bb3..d52413f 100644 --- a/cal/comma.cal +++ b/cal/comma.cal @@ -7,53 +7,53 @@ * * str_comma(x, [group, [decimal]]) * - * Convert x into a string. + * Convert x into a string. * - * If group is given and is a string, group will be used as - * the 3-digit group separator, otherwise the default 3-digit - * group separator will be used. + * If group is given and is a string, group will be used as + * the 3-digit group separator, otherwise the default 3-digit + * group separator will be used. * - * If decimal is given and is a string, group will be used as - * the integer-fraction separator, otherwise the default - * integer-fraction separator will be used. + * If decimal is given and is a string, group will be used as + * the integer-fraction separator, otherwise the default + * integer-fraction separator will be used. * - * The decimal and group arguments are optional. + * The decimal and group arguments are optional. * * set_default_group_separator(group) * - * Change the default 3-digit group separator if group is a string, - * otherwise the default 3-digit group separator will not be - * changed. Return the old 3-digit group separator. + * Change the default 3-digit group separator if group is a string, + * otherwise the default 3-digit group separator will not be + * changed. Return the old 3-digit group separator. * * set_default_decimal_separator(decimal) * - * Change the default 3-digit group separator if decimal is a - * string, otherwise the default integer-fraction separator - * will not be changed. Return the old integer-fraction separator. + * Change the default 3-digit group separator if decimal is a + * string, otherwise the default integer-fraction separator + * will not be changed. Return the old integer-fraction separator. * * print_comma(x, [group, [decimal]]) * - * Print the value produced by str_comma(x, [group, [decimal]]) - * followed by a newline. + * Print the value produced by str_comma(x, [group, [decimal]]) + * followed by a newline. * - * If the str_comma() does not return a string, nothing is printed. + * If the str_comma() does not return a string, nothing is printed. * - * The decimal and group arguments are optional. + * The decimal and group arguments are optional. * - * The value produced by str_comma() is returned. + * The value produced by str_comma() is returned. * * fprint_comma(fd, x, [group, [decimal]]) * - * Print the value produced by str_comma(x, [group, [decimal]]), - * without a trailing newline, on file fd. + * Print the value produced by str_comma(x, [group, [decimal]]), + * without a trailing newline, on file fd. * - * If the str_comma() does not return a string, nothing is printed. + * If the str_comma() does not return a string, nothing is printed. * - * If fd is not an open file, nothing is printed. + * If fd is not an open file, nothing is printed. * - * The decimal and group arguments are optional. + * The decimal and group arguments are optional. * - * The value produced by str_comma() is returned. + * The value produced by str_comma() is returned. * * Copyright (C) 2022 Landon Curt Noll * @@ -78,8 +78,8 @@ */ -static default_group_separator = ","; /* default 3-digit group separator */ -static default_decimal_separator = "."; /* default integer-fraction separator */ +static default_group_separator = ","; /* default 3-digit group separator */ +static default_decimal_separator = "."; /* default integer-fraction separator */ /* @@ -92,9 +92,9 @@ static default_decimal_separator = "."; /* default integer-fraction separator */ * * For example: * - * string = str_comma(x); - * string = str_comma(x), " ", "."); - * string = str_comma(x), ".", ","); + * string = str_comma(x); + * string = str_comma(x), " ", "."); + * string = str_comma(x), ".", ","); * * Internally the function calls: * @@ -109,37 +109,37 @@ static default_decimal_separator = "."; /* default integer-fraction separator */ * * given: * - * x number to convert + * x number to convert * * optional args: * - * group use this 3-digit group separator - * decimal use this integer-fraction separator + * group use this 3-digit group separator + * decimal use this integer-fraction separator * * returns: * - * string containing the base 10 digits with group and decimal separators, OR - * null() if x is not a number, OR - * null() if group is neither null() (not given) nor a string, OR - * null() if group is null() (not given) AND default_group_separator is not a string, OR - * null() if decimal is neither null() (not given) nor a string, OR - * null() if decimal is null() (not given) AND default_decimal_separator is not a string. + * string containing the base 10 digits with group and decimal separators, OR + * null() if x is not a number, OR + * null() if group is neither null() (not given) nor a string, OR + * null() if group is null() (not given) AND default_group_separator is not a string, OR + * null() if decimal is neither null() (not given) nor a string, OR + * null() if decimal is null() (not given) AND default_decimal_separator is not a string. */ define str_comma(x, group, decimal) { - local group_separator; /* 3-digit group separator */ - local decimal_separator; /* separator between decimal integer and decimal fraction */ - local sign_str; /* leading - if x < 0 or empty if x >= 0 */ - local integer; /* integer part of absolute value of x */ - local int_str; /* integer as a string */ - local int_len; /* number of digits in int_str */ - local first_group_len; /* length of 1st group before the 1st 3-digit group separator */ - local fraction; /* factional part of absolute value of x */ - local frac_str; /* fraction as a string */ - local frac_len; /* number of digits in frac_str including leading 0. */ - local ret; /* string to return */ - local config_leadzero; /* config("leadzero") to restore */ - local config_tilde; /* config("tilde") to restore */ + local group_separator; /* 3-digit group separator */ + local decimal_separator; /* separator between decimal integer and decimal fraction */ + local sign_str; /* leading - if x < 0 or empty if x >= 0 */ + local integer; /* integer part of absolute value of x */ + local int_str; /* integer as a string */ + local int_len; /* number of digits in int_str */ + local first_group_len; /* length of 1st group before the 1st 3-digit group separator */ + local fraction; /* factional part of absolute value of x */ + local frac_str; /* fraction as a string */ + local frac_len; /* number of digits in frac_str including leading 0. */ + local ret; /* string to return */ + local config_leadzero; /* config("leadzero") to restore */ + local config_tilde; /* config("tilde") to restore */ local i; /* @@ -148,28 +148,28 @@ define str_comma(x, group, decimal) * Return null() if args or conditions are bogus. */ if (!isreal(x)) { - return null(); + return null(); } group_separator = isnull(group) ? default_group_separator : group; decimal_separator = isnull(decimal) ? default_decimal_separator : decimal; if (!isstr(group_separator)) { - return null(); + return null(); } if (!isstr(decimal_separator)) { - return null(); + return null(); } /* * split number */ if (x < 0) { - sign_str = "-"; - integer = int(-x); - fraction = frac(-x); + sign_str = "-"; + integer = int(-x); + fraction = frac(-x); } else { - sign_str = ""; - integer = int(x); - fraction = frac(x); + sign_str = ""; + integer = int(x); + fraction = frac(x); } ret = sign_str; @@ -199,32 +199,32 @@ define str_comma(x, group, decimal) * case: integer is 3 or fewer digits */ if (integer < 1000) { - ret += int_str; + ret += int_str; /* * case: integer is 4 or more digits */ } else { - /* - * form a decimal string using group separators - */ + /* + * form a decimal string using group separators + */ - /* - * form the initial leading digits before 1st group separator - */ - first_group_len = int_len % 3; - if (first_group_len == 0) { - first_group_len = 3; - } - ret += substr(int_str, 1, first_group_len); + /* + * form the initial leading digits before 1st group separator + */ + first_group_len = int_len % 3; + if (first_group_len == 0) { + first_group_len = 3; + } + ret += substr(int_str, 1, first_group_len); - /* - * until end of digits, print group separator followed by 3 more digits - */ - for (i = first_group_len+1; i < int_len; i += 3) { - ret += group_separator + substr(int_str, i, 3); - } + /* + * until end of digits, print group separator followed by 3 more digits + */ + for (i = first_group_len+1; i < int_len; i += 3) { + ret += group_separator + substr(int_str, i, 3); + } } /* @@ -236,24 +236,24 @@ define str_comma(x, group, decimal) */ if (fraction == 0) { - /* no fraction, nothing more to do */ + /* no fraction, nothing more to do */ /* * case: x is not an integer */ } else { - /* - * add integer-fraction separator - */ - ret += decimal_separator; + /* + * add integer-fraction separator + */ + ret += decimal_separator; - /* - * add remaining digits - * - * Skip over the leading 0. in frac_str - */ - ret += substr(frac_str, 2, frac_len-1); + /* + * add remaining digits + * + * Skip over the leading 0. in frac_str + */ + ret += substr(frac_str, 2, frac_len-1); } /* @@ -269,19 +269,19 @@ define str_comma(x, group, decimal) * If group is not a string, then the default 3-digit group separator * is not changed. Thus, this will only return the default 3-digit group separator: * - * set_default_group_separator(null()); + * set_default_group_separator(null()); * * given: * - * group 3-digit group separator + * group 3-digit group separator * * returns: * - * previous 3-digit group separator value + * previous 3-digit group separator value */ define set_default_group_separator(group) { - local old_default_group_separator; /* previous default 3-digit group separator to return */ + local old_default_group_separator; /* previous default 3-digit group separator to return */ /* * save current 3-digit group separator @@ -292,7 +292,7 @@ define set_default_group_separator(group) * change 3-digit group separator if group is a string */ if (isstr(group)) { - default_group_separator = group; + default_group_separator = group; } return old_default_group_separator; } @@ -304,19 +304,19 @@ define set_default_group_separator(group) * If decimal is not a string, then the default integer-fraction separator * is not changed. Thus, this will only return the integer-fraction separator: * - * set_default_decimal_separator(null()); + * set_default_decimal_separator(null()); * * given: * - * decimal separator between decimal integer and decimal fraction (def: ".") + * decimal separator between decimal integer and decimal fraction (def: ".") * * returns: * - * previous integer-fraction separator value + * previous integer-fraction separator value */ define set_default_decimal_separator(decimal) { - local old_default_decimal_separator; /* previous default integer-fraction separator */ + local old_default_decimal_separator; /* previous default integer-fraction separator */ /* * save current integer-fraction separator @@ -327,7 +327,7 @@ define set_default_decimal_separator(decimal) * change 3-digit decimal integer-fraction if decimal is a string */ if (isstr(decimal)) { - default_decimal_separator = decimal; + default_decimal_separator = decimal; } return old_default_decimal_separator; } @@ -339,34 +339,34 @@ define set_default_decimal_separator(decimal) * This function prints the result of str_comma(x, group, decimal) followed by a newline. * For example: * - * print_comma(x); - * print_comma(x), " ", "."); - * print_comma(x), ".", ","); + * print_comma(x); + * print_comma(x), " ", "."); + * print_comma(x), ".", ","); * * If str_comma() does not return a string, this function prints nothing. * * NOTE: To print without a newline, use fprint_comma(fd, x, group, decimal). * * given: - * x number to convert + * x number to convert * * optional args: * - * group use this 3-digit group separator - * decimal use this integer-fraction separator + * group use this 3-digit group separator + * decimal use this integer-fraction separator * * returns: * - * string containing the base 10 digits with group and decimal separators, OR - * null() if x is not a number, OR - * null() if group is neither null() (not given) nor a string, OR - * null() if group is null() (not given) AND default_group_separator is not a string, OR - * null() if decimal is neither null() (not given) nor a string, OR - * null() if decimal is null() (not given) AND default_decimal_separator is not a string. + * string containing the base 10 digits with group and decimal separators, OR + * null() if x is not a number, OR + * null() if group is neither null() (not given) nor a string, OR + * null() if group is null() (not given) AND default_group_separator is not a string, OR + * null() if decimal is neither null() (not given) nor a string, OR + * null() if decimal is null() (not given) AND default_decimal_separator is not a string. */ define print_comma(x, group, decimal) { - local ret; /* base 10 string with 3-digit group and integer-fraction separators */ + local ret; /* base 10 string with 3-digit group and integer-fraction separators */ /* * convert to string @@ -377,7 +377,7 @@ define print_comma(x, group, decimal) * print converted string */ if (isstr(ret)) { - printf("%s\n", ret); + printf("%s\n", ret); } return ret; } @@ -389,9 +389,9 @@ define print_comma(x, group, decimal) * This function prints the result of str_comma(x, group, decimal) on an open file, without a trailing newline. * For example: * - * fprint_comma(files(1), x); - * fprint_comma(fd, x), " ", "."); - * fprint_comma(files(2), x), ".", ","); + * fprint_comma(files(1), x); + * fprint_comma(fd, x), " ", "."); + * fprint_comma(files(2), x), ".", ","); * * If str_comma() does not return a string, this function prints nothing. * @@ -400,26 +400,26 @@ define print_comma(x, group, decimal) * NOTE: To print with a newline, use print_comma(x, group, decimal). * * given: - * fd open file - * x number to convert + * fd open file + * x number to convert * * optional args: * - * group use this 3-digit group separator - * decimal use this integer-fraction separator + * group use this 3-digit group separator + * decimal use this integer-fraction separator * * returns: * - * string containing the base 10 digits with group and integer-fraction separators, OR - * null() if x is not a number, OR - * null() if group is neither null() (not given) nor a string, OR - * null() if group is null() (not given) AND default_group_separator is not a string, OR - * null() if decimal is neither null() (not given) nor a string, OR - * null() if decimal is null() (not given) AND default_decimal_separator is not a string. + * string containing the base 10 digits with group and integer-fraction separators, OR + * null() if x is not a number, OR + * null() if group is neither null() (not given) nor a string, OR + * null() if group is null() (not given) AND default_group_separator is not a string, OR + * null() if decimal is neither null() (not given) nor a string, OR + * null() if decimal is null() (not given) AND default_decimal_separator is not a string. */ define fprint_comma(fd, x, group, decimal) { - local ret; /* base 10 string with 3-digit group and integer-fraction separators */ + local ret; /* base 10 string with 3-digit group and integer-fraction separators */ /* * convert to string @@ -430,8 +430,8 @@ define fprint_comma(fd, x, group, decimal) * print converted string */ if (isstr(ret) && isfile(fd)) { - fprintf(fd, "%s", ret); - fflush(fd); + fprintf(fd, "%s", ret); + fflush(fd); } return ret; } diff --git a/cal/constants.cal b/cal/constants.cal index be2a266..21a9ee0 100644 --- a/cal/constants.cal +++ b/cal/constants.cal @@ -17,8 +17,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2013/08/11 01:31:28 - * File existed as early as: 2013 + * Under source code control: 2013/08/11 01:31:28 + * File existed as early as: 2013 */ diff --git a/cal/deg.cal b/cal/deg.cal index 51d4cac..420ffb8 100644 --- a/cal/deg.cal +++ b/cal/deg.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:50:33 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:50:33 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,105 +28,105 @@ obj deg {deg, min, sec}; define deg(deg, min, sec) { - local ans; + local ans; - if (isnull(sec)) - sec = 0; - if (isnull(min)) - min = 0; - obj deg ans; - ans.deg = deg; - ans.min = min; - ans.sec = sec; - fixdeg(ans); - return ans; + if (isnull(sec)) + sec = 0; + if (isnull(min)) + min = 0; + obj deg ans; + ans.deg = deg; + ans.min = min; + ans.sec = sec; + fixdeg(ans); + return ans; } define deg_add(a, b) { - local obj deg ans; + local obj deg ans; - ans.deg = 0; - ans.min = 0; - ans.sec = 0; - if (istype(a, ans)) { - ans.deg += a.deg; - ans.min += a.min; - ans.sec += a.sec; - } else - ans.deg += a; - if (istype(b, ans)) { - ans.deg += b.deg; - ans.min += b.min; - ans.sec += b.sec; - } else - ans.deg += b; - fixdeg(ans); - return ans; + ans.deg = 0; + ans.min = 0; + ans.sec = 0; + if (istype(a, ans)) { + ans.deg += a.deg; + ans.min += a.min; + ans.sec += a.sec; + } else + ans.deg += a; + if (istype(b, ans)) { + ans.deg += b.deg; + ans.min += b.min; + ans.sec += b.sec; + } else + ans.deg += b; + fixdeg(ans); + return ans; } define deg_neg(a) { - local obj deg ans; + local obj deg ans; - ans.deg = -a.deg; - ans.min = -a.min; - ans.sec = -a.sec; - return ans; + ans.deg = -a.deg; + ans.min = -a.min; + ans.sec = -a.sec; + return ans; } define deg_sub(a, b) { - return a - b; + return a - b; } define deg_mul(a, b) { - local obj deg ans; + local obj deg ans; - if (istype(a, ans) && istype(b, ans)) - quit "Cannot multiply degrees together"; - if (istype(a, ans)) { - ans.deg = a.deg * b; - ans.min = a.min * b; - ans.sec = a.sec * b; - } else { - ans.deg = b.deg * a; - ans.min = b.min * a; - ans.sec = b.sec * a; - } - fixdeg(ans); - return ans; + if (istype(a, ans) && istype(b, ans)) + quit "Cannot multiply degrees together"; + if (istype(a, ans)) { + ans.deg = a.deg * b; + ans.min = a.min * b; + ans.sec = a.sec * b; + } else { + ans.deg = b.deg * a; + ans.min = b.min * a; + ans.sec = b.sec * a; + } + fixdeg(ans); + return ans; } define deg_print(a) { - print a.deg : 'd' : a.min : 'm' : a.sec : 's' :; + print a.deg : 'd' : a.min : 'm' : a.sec : 's' :; } define deg_abs(a) { - return a.deg + a.min / 60 + a.sec / 3600; + return a.deg + a.min / 60 + a.sec / 3600; } define fixdeg(a) { - a.min += frac(a.deg) * 60; - a.deg = int(a.deg); - a.sec += frac(a.min) * 60; - a.min = int(a.min); - a.min += a.sec // 60; - a.sec %= 60; - a.deg += a.min // 60; - a.min %= 60; - a.deg %= 360; + a.min += frac(a.deg) * 60; + a.deg = int(a.deg); + a.sec += frac(a.min) * 60; + a.min = int(a.min); + a.min += a.sec // 60; + a.sec %= 60; + a.deg += a.min // 60; + a.min %= 60; + a.deg %= 360; } if (config("resource_debug") & 3) { diff --git a/cal/dms.cal b/cal/dms.cal index 696087a..c91ea4d 100644 --- a/cal/dms.cal +++ b/cal/dms.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:50:33 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:50:33 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,14 +28,14 @@ obj dms {deg, min, sec}; define dms(deg, min, sec) { - local obj dms ans; /* return value */ + local obj dms ans; /* return value */ /* default missing args to 0 */ if (isnull(sec)) { - sec = 0; + sec = 0; } if (isnull(min)) { - min = 0; + min = 0; } /* load object */ @@ -51,30 +51,30 @@ define dms(deg, min, sec) define dms_add(a, b) { - local obj dms ans; /* return value */ + local obj dms ans; /* return value */ /* initialize value to 1st arg */ if (istype(a, ans)) { - /* 1st arg is dms object, load it */ - ans.deg = a.deg; - ans.min = a.min; - ans.sec = a.sec; + /* 1st arg is dms object, load it */ + ans.deg = a.deg; + ans.min = a.min; + ans.sec = a.sec; } else { - /* 1st arg is not dms, assume scalar degrees */ - ans.deg = a; - ans.min = 0; - ans.sec = 0; + /* 1st arg is not dms, assume scalar degrees */ + ans.deg = a; + ans.min = 0; + ans.sec = 0; } /* add value of 2nd arg */ if (istype(b, ans)) { - /* 2nd arg is dms object, add it */ - ans.deg += b.deg; - ans.min += b.min; - ans.sec += b.sec; + /* 2nd arg is dms object, add it */ + ans.deg += b.deg; + ans.min += b.min; + ans.sec += b.sec; } else { - /* 2nd arg is not dms, add scalar degrees */ - ans.deg += b; + /* 2nd arg is not dms, add scalar degrees */ + ans.deg += b; } /* return normalized result */ @@ -85,19 +85,19 @@ define dms_add(a, b) define dms_neg(a) { - local obj dms ans; /* return value */ + local obj dms ans; /* return value */ /* negate argument */ if (istype(a, ans)) { - /* 1st arg is dms object, load it */ - ans.deg = -a.deg; - ans.min = -a.min; - ans.sec = -a.sec; + /* 1st arg is dms object, load it */ + ans.deg = -a.deg; + ans.min = -a.min; + ans.sec = -a.sec; } else { - /* 2nd arg is not dms, negate scalar degrees */ - ans.deg = -a; - ans.min = 0; - ans.sec = 0; + /* 2nd arg is not dms, negate scalar degrees */ + ans.deg = -a; + ans.min = 0; + ans.sec = 0; } /* return normalized result */ @@ -108,30 +108,30 @@ define dms_neg(a) define dms_sub(a, b) { - local obj dms ans; /* return value */ + local obj dms ans; /* return value */ /* initialize value to 1st arg */ if (istype(a, ans)) { - /* 1st arg is dms object, load it */ - ans.deg = a.deg; - ans.min = a.min; - ans.sec = a.sec; + /* 1st arg is dms object, load it */ + ans.deg = a.deg; + ans.min = a.min; + ans.sec = a.sec; } else { - /* 1st arg is not dms, assume scalar degrees */ - ans.deg = a; - ans.min = 0; - ans.sec = 0; + /* 1st arg is not dms, assume scalar degrees */ + ans.deg = a; + ans.min = 0; + ans.sec = 0; } /* subtract value of 2nd arg */ if (istype(b, ans)) { - /* 2nd arg is dms object, subtract it */ - ans.deg -= b.deg; - ans.min -= b.min; - ans.sec -= b.sec; + /* 2nd arg is dms object, subtract it */ + ans.deg -= b.deg; + ans.min -= b.min; + ans.sec -= b.sec; } else { - /* 2nd arg is not dms, subtract scalar degrees */ - ans.deg -= b; + /* 2nd arg is not dms, subtract scalar degrees */ + ans.deg -= b; } /* return normalized result */ @@ -142,23 +142,23 @@ define dms_sub(a, b) define dms_mul(a, b) { - local obj dms ans; /* return value */ + local obj dms ans; /* return value */ /* dms object multiplication */ if (istype(a, ans) && istype(b, ans)) { - ans.deg = dms_abs(a) * dms_abs(b); - ans.min = 0; - ans.sec = 0; + ans.deg = dms_abs(a) * dms_abs(b); + ans.min = 0; + ans.sec = 0; /* scalar multiplication */ } else if (istype(a, ans)) { - ans.deg = a.deg * b; - ans.min = a.min * b; - ans.sec = a.sec * b; + ans.deg = a.deg * b; + ans.min = a.min * b; + ans.sec = a.sec * b; } else { - ans.deg = b.deg * a; - ans.min = b.min * a; - ans.sec = b.sec * a; + ans.deg = b.deg * a; + ans.min = b.min * a; + ans.sec = b.sec * a; } /* return normalized result */ @@ -169,11 +169,11 @@ define dms_mul(a, b) define dms_print(a) { - local obj dms ans; /* temp object for dms type testing */ + local obj dms ans; /* temp object for dms type testing */ /* firewall - arg must be a dms object */ if (! istype(a, ans)) { - quit "dms_print called with non dms object"; + quit "dms_print called with non dms object"; } /* print in dms form */ @@ -183,12 +183,12 @@ define dms_print(a) define dms_abs(a) { - local obj dms ans; /* temp object for dms type testing */ - local deg; /* return scalar value */ + local obj dms ans; /* temp object for dms type testing */ + local deg; /* return scalar value */ /* firewall - just absolute value non dms objects */ if (! istype(a, ans)) { - return abs(a); + return abs(a); } /* compute degrees */ @@ -201,12 +201,12 @@ define dms_abs(a) define dms_norm(a) { - local obj dms ans; /* temp object for dms type testing */ - local deg; /* degrees */ + local obj dms ans; /* temp object for dms type testing */ + local deg; /* degrees */ /* firewall - arg must be a dms object */ if (! istype(a, ans)) { - quit "dms_norm called with non dms object"; + quit "dms_norm called with non dms object"; } /* square degrees (norm is the square of absolute value */ @@ -219,18 +219,18 @@ define dms_norm(a) define dms_test(a) { - local obj dms ans; /* temp value */ + local obj dms ans; /* temp value */ /* firewall - arg must be a dms object */ if (! istype(a, ans)) { - quit "dms_test called with non dms object"; + quit "dms_test called with non dms object"; } /* return false of non-zero */ ans = fixdms(a); if (ans.deg == 0 && ans.min == 0 && ans.sec == 0) { - /* false */ - return 0; + /* false */ + return 0; } /* true */ return 1; @@ -239,11 +239,11 @@ define dms_test(a) define dms_int(a) { - local obj dms ans; /* return value */ + local obj dms ans; /* return value */ /* firewall - arg must be a dms object */ if (! istype(a, ans)) { - quit "dms_int called with non dms object"; + quit "dms_int called with non dms object"; } /* normalize the argument */ @@ -259,11 +259,11 @@ define dms_int(a) define dms_frac(a) { - local obj dms ans; /* return value */ + local obj dms ans; /* return value */ /* firewall - arg must be a dms object */ if (! istype(a, ans)) { - quit "dms_frac called with non dms object"; + quit "dms_frac called with non dms object"; } /* normalize the argument */ @@ -281,7 +281,7 @@ define dms_frac(a) define dms_rel(a,b) { - local abs_a, abs_b; /* scalars of the arguments */ + local abs_a, abs_b; /* scalars of the arguments */ /* compute scalars of the arguments */ abs_a = dms_abs(a); @@ -294,7 +294,7 @@ define dms_rel(a,b) define dms_cmp(a,b) { - local abs_a, abs_b; /* scalars of the arguments */ + local abs_a, abs_b; /* scalars of the arguments */ /* compute scalars of the arguments */ abs_a = dms_abs(a); @@ -307,16 +307,16 @@ define dms_cmp(a,b) define dms_inc(a) { - local obj dms ans; /* return value */ + local obj dms ans; /* return value */ /* increment a dms object */ if (istype(a, ans)) { - ans = a; - ++ans.sec; + ans = a; + ++ans.sec; - /* return normalized result */ - ans = fixdms(ans); - return ans; + /* return normalized result */ + ans = fixdms(ans); + return ans; } /* increment a scalar */ @@ -326,16 +326,16 @@ define dms_inc(a) define dms_dec(a) { - local obj dms ans; /* return value */ + local obj dms ans; /* return value */ /* decrement a dms object */ if (istype(a, ans)) { - ans = a; - --ans.sec; + ans = a; + --ans.sec; - /* return normalized result */ - ans = fixdms(ans); - return ans; + /* return normalized result */ + ans = fixdms(ans); + return ans; } /* decrement a scalar */ @@ -345,11 +345,11 @@ define dms_dec(a) define fixdms(a) { - local obj dms ans; /* temp value */ + local obj dms ans; /* temp value */ /* firewall */ if (! istype(a, ans)) { - quit "attempt to fix a non dms object"; + quit "attempt to fix a non dms object"; } /* use builtin d2dms function */ diff --git a/cal/dotest.cal b/cal/dotest.cal index 831a81c..21f68a7 100644 --- a/cal/dotest.cal +++ b/cal/dotest.cal @@ -7,7 +7,7 @@ * This file is not covered under version 2.1 of the GNU LGPL. * This file is covered under "The unlicense": * - * https://unlicense.org + * https://unlicense.org * * In particular: * @@ -36,8 +36,8 @@ * * For more information, please refer to * - * Under source dotest_code control: 2006/03/08 05:54:09 - * File existed as early as: 2006 + * Under source dotest_code control: 2006/03/08 05:54:09 + * File existed as early as: 2006 */ @@ -45,29 +45,29 @@ * dotest - perform tests from dotest_testline file * * given: - * dotest_file filename containing single test lines - * dotest_code regress.cal test number to use (def: 0) - * dotest_maxcond max error conditions allowed (def: <0 ==> 2^31-1) + * dotest_file filename containing single test lines + * dotest_code regress.cal test number to use (def: 0) + * dotest_maxcond max error conditions allowed (def: <0 ==> 2^31-1) * * returns: - * number of line test failures + * number of line test failures * * NOTE: All variables used by the dotest() function start with "dotest_". - * The dotest_file and dotest_read should not use any variable - * that starts with "dotest_". + * The dotest_file and dotest_read should not use any variable + * that starts with "dotest_". */ define dotest(dotest_file, dotest_code = 0, dotest_maxcond = -1) { - local dotest_f_file; /* open file containing test lines */ - local dotest_testline; /* test line */ - local dotest_testeval; /* eval value from dotest_testline test line */ - local dotest_tmperrcnt; /* temp error count after line test */ - local dotest_errcnt; /* total number of errors */ - local dotest_failcnt; /* number of line tests failed */ - local dotest_testnum; /* number of test lines evaluated */ - local dotest_linenum; /* test line number */ - local dotest_old_errmax; /* value of errmax() prior to calling */ - local dotest_old_errcount; /* value of errcount() prior to calling */ + local dotest_f_file; /* open file containing test lines */ + local dotest_testline; /* test line */ + local dotest_testeval; /* eval value from dotest_testline test line */ + local dotest_tmperrcnt; /* temp error count after line test */ + local dotest_errcnt; /* total number of errors */ + local dotest_failcnt; /* number of line tests failed */ + local dotest_testnum; /* number of test lines evaluated */ + local dotest_linenum; /* test line number */ + local dotest_old_errmax; /* value of errmax() prior to calling */ + local dotest_old_errcount; /* value of errcount() prior to calling */ /* * preserve calling stats @@ -87,9 +87,9 @@ define dotest(dotest_file, dotest_code = 0, dotest_maxcond = -1) * setup error accounting for dotest */ if (dotest_maxcond >= 0 && dotest_maxcond < 2147483647) { - errmax(dotest_maxcond + dotest_old_errcount + 1),; + errmax(dotest_maxcond + dotest_old_errcount + 1),; } else { - errmax(2147483647),; + errmax(2147483647),; } /* @@ -98,9 +98,9 @@ define dotest(dotest_file, dotest_code = 0, dotest_maxcond = -1) printf("%d-: opening line file: %d", dotest_code, dotest_file); dotest_f_file = fpathopen(dotest_file, "r"); if (!isfile(dotest_f_file)) { - printf("**** Unable to file or open file \"%s\"\n", - dotest_file); - quit; + printf("**** Unable to file or open file \"%s\"\n", + dotest_file); + quit; } printf('%d: testing "%s"\n', dotest_code, dotest_file); @@ -109,73 +109,73 @@ define dotest(dotest_file, dotest_code = 0, dotest_maxcond = -1) */ for (;;) { - /* get the next test line */ - dotest_testline = fgets(dotest_f_file); - ++dotest_linenum; - if (iserror(dotest_testline)) { - quit "**** Error while reading file"; - } else if (isnull(dotest_testline)) { - /* EOF - end of test file */ - break; - } + /* get the next test line */ + dotest_testline = fgets(dotest_f_file); + ++dotest_linenum; + if (iserror(dotest_testline)) { + quit "**** Error while reading file"; + } else if (isnull(dotest_testline)) { + /* EOF - end of test file */ + break; + } - /* skip empty lines */ - if (dotest_testline == "\n") { - continue; - } + /* skip empty lines */ + if (dotest_testline == "\n") { + continue; + } - /* evaluate the test line */ - dotest_testeval = eval(dotest_testline); + /* evaluate the test line */ + dotest_testeval = eval(dotest_testline); - /* ignore white space or comment lines */ - if (isnull(dotest_testeval)) { - continue; - } + /* ignore white space or comment lines */ + if (isnull(dotest_testeval)) { + continue; + } - /* look for test line parse errors */ - if (iserror(dotest_testeval)) { - printf("**** evaluation error: "); - ++dotest_failcnt; + /* look for test line parse errors */ + if (iserror(dotest_testeval)) { + printf("**** evaluation error: "); + ++dotest_failcnt; - /* look for test line dotest_failcnt */ - } else if (dotest_testeval != 1) { - printf("**** did not return 1: "); - ++dotest_failcnt; - } + /* look for test line dotest_failcnt */ + } else if (dotest_testeval != 1) { + printf("**** did not return 1: "); + ++dotest_failcnt; + } - /* show the test line we just performed */ - printf("%d-%d: %s", dotest_code, dotest_linenum, dotest_testline); + /* show the test line we just performed */ + printf("%d-%d: %s", dotest_code, dotest_linenum, dotest_testline); - /* error accounting */ - dotest_tmperrcnt = errcount() - dotest_errcnt; - if (dotest_tmperrcnt > 0) { + /* error accounting */ + dotest_tmperrcnt = errcount() - dotest_errcnt; + if (dotest_tmperrcnt > 0) { - /* report any other errors */ - if (dotest_tmperrcnt > 1) { - printf("%d-%d: NOTE: %d error conditions(s): %s\n", - dotest_code, dotest_linenum, dotest_tmperrcnt); - } + /* report any other errors */ + if (dotest_tmperrcnt > 1) { + printf("%d-%d: NOTE: %d error conditions(s): %s\n", + dotest_code, dotest_linenum, dotest_tmperrcnt); + } - /* report the calc error string */ - printf("%d-%d: NOTE: last error string: %s\n", - dotest_code, dotest_linenum, strerror()); + /* report the calc error string */ + printf("%d-%d: NOTE: last error string: %s\n", + dotest_code, dotest_linenum, strerror()); - /* new error count level */ - dotest_errcnt = errcount(); - if (dotest_maxcond >= 0 && - dotest_old_errcount-dotest_errcnt > dotest_maxcond) { - printf("%d-%d: total error conditions: %d > %d\n", - dotest_code, dotest_linenum, - dotest_maxcond, dotest_old_errcount-dotest_errcnt); - } - } + /* new error count level */ + dotest_errcnt = errcount(); + if (dotest_maxcond >= 0 && + dotest_old_errcount-dotest_errcnt > dotest_maxcond) { + printf("%d-%d: total error conditions: %d > %d\n", + dotest_code, dotest_linenum, + dotest_maxcond, dotest_old_errcount-dotest_errcnt); + } + } } /* * test the close of the line file */ printf("%d-: detected %d error condition(s), many of which may be OK\n", - dotest_code, dotest_old_errcount-dotest_errcnt); + dotest_code, dotest_old_errcount-dotest_errcnt); printf("%d-: closing line file: %d\n", dotest_code, dotest_file); fclose(dotest_f_file); @@ -183,11 +183,11 @@ define dotest(dotest_file, dotest_code = 0, dotest_maxcond = -1) * test line file accounting */ if (dotest_failcnt > 0) { - printf("**** %d-: %d test failure(s) in %d line(s)\n", - dotest_code, dotest_failcnt, dotest_linenum); + printf("**** %d-: %d test failure(s) in %d line(s)\n", + dotest_code, dotest_failcnt, dotest_linenum); } else { - printf("%d-: no failure(s) in %d line(s)\n", - dotest_code, dotest_linenum); + printf("%d-: no failure(s) in %d line(s)\n", + dotest_code, dotest_linenum); } /* diff --git a/cal/ellip.cal b/cal/ellip.cal index 4c4bb4a..22d6403 100644 --- a/cal/ellip.cal +++ b/cal/ellip.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,16 +17,16 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:50:33 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:50:33 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * Attempt to factor numbers using elliptic functions: * - * y^2 = x^3 + a*x + b (mod ellip_N). + * y^2 = x^3 + a*x + b (mod ellip_N). * * Many points (x,y) (mod ellip_N) are found that solve the above equation, * starting from a trivial solution and 'multiplying' that point together @@ -47,13 +47,13 @@ * Theory and Cryptography" by Neal Koblitz for a good explanation. * * efactor(iN, ia, B, force) - * iN is the number to be factored. - * ia is the initial value of a in the equation, and each successive - * value of a is an independent attempt at factoring (default 1). - * B is the limit of the primes that make up the high power that the - * point is raised to for each factoring attempt (default 100). - * force is a flag to attempt to factor numbers even if they are - * thought to already be prime (default false). + * iN is the number to be factored. + * ia is the initial value of a in the equation, and each successive + * value of a is an independent attempt at factoring (default 1). + * B is the limit of the primes that make up the high power that the + * point is raised to for each factoring attempt (default 100). + * force is a flag to attempt to factor numbers even if they are + * thought to already be prime (default false). * * Making B larger makes the power the point being raised to contain more * prime factors, thus increasing the chance that the order of the point @@ -77,114 +77,114 @@ * of the powers so far. * * If a factor is found, it is returned and is also saved in the global - * variable f. The number being factored is also saved in the global + * variable f. The number being factored is also saved in the global * variable ellip_N. */ obj point {x, y}; -global ellip_N; /* number to factor */ -global ellip_a; /* first coefficient */ -global ellip_b; /* second coefficient */ -global ellip_f; /* found factor */ +global ellip_N; /* number to factor */ +global ellip_a; /* first coefficient */ +global ellip_b; /* second coefficient */ +global ellip_f; /* found factor */ define efactor(iN, ia, B, force) { - local C, x, p; + local C, x, p; - if (!force && ptest(iN, 50)) - return 1; - if (isnull(B)) - B = 100; - if (isnull(ia)) - ia = 1; - obj point x; - ellip_a = ia; - ellip_b = -ia; - ellip_N = iN; - C = isqrt(ellip_N); - C = 2 * C + 2 * isqrt(C) + 1; - ellip_f = 0; - while (ellip_f == 0) { - print "A =", ellip_a; - x.x = 1; - x.y = 1; - print 2, x; - x = x ^ (2 ^ (highbit(C) + 1)); - for (p = 3; ((p < B) && (ellip_f == 0)); p += 2) { - if (!ptest(p, 1)) - continue; - print p, x; - x = x ^ (p ^ ((highbit(C) // highbit(p)) + 1)); - } - ellip_a++; - ellip_b--; - } - return ellip_f; + if (!force && ptest(iN, 50)) + return 1; + if (isnull(B)) + B = 100; + if (isnull(ia)) + ia = 1; + obj point x; + ellip_a = ia; + ellip_b = -ia; + ellip_N = iN; + C = isqrt(ellip_N); + C = 2 * C + 2 * isqrt(C) + 1; + ellip_f = 0; + while (ellip_f == 0) { + print "A =", ellip_a; + x.x = 1; + x.y = 1; + print 2, x; + x = x ^ (2 ^ (highbit(C) + 1)); + for (p = 3; ((p < B) && (ellip_f == 0)); p += 2) { + if (!ptest(p, 1)) + continue; + print p, x; + x = x ^ (p ^ ((highbit(C) // highbit(p)) + 1)); + } + ellip_a++; + ellip_b--; + } + return ellip_f; } define point_print(p) { - print "(" : p.x : "," : p.y : ")" :; + print "(" : p.x : "," : p.y : ")" :; } define point_mul(p1, p2) { - local r, m; + local r, m; - if (p2 == 1) - return p1; - if (p1 == p2) - return point_square(`p1); - obj point r; - m = (minv(p2.x - p1.x, ellip_N) * (p2.y - p1.y)) % ellip_N; - if (m == 0) { - if (ellip_f == 0) - ellip_f = gcd(p2.x - p1.x, ellip_N); - r.x = 1; - r.y = 1; - return r; - } - r.x = (m^2 - p1.x - p2.x) % ellip_N; - r.y = ((m * (p1.x - r.x)) - p1.y) % ellip_N; - return r; + if (p2 == 1) + return p1; + if (p1 == p2) + return point_square(`p1); + obj point r; + m = (minv(p2.x - p1.x, ellip_N) * (p2.y - p1.y)) % ellip_N; + if (m == 0) { + if (ellip_f == 0) + ellip_f = gcd(p2.x - p1.x, ellip_N); + r.x = 1; + r.y = 1; + return r; + } + r.x = (m^2 - p1.x - p2.x) % ellip_N; + r.y = ((m * (p1.x - r.x)) - p1.y) % ellip_N; + return r; } define point_square(p) { - local r, m; + local r, m; - obj point r; - m = ((3 * p.x^2 + ellip_a) * minv(p.y << 1, ellip_N)) % ellip_N; - if (m == 0) { - if (ellip_f == 0) - ellip_f = gcd(p.y << 1, ellip_N); - r.x = 1; - r.y = 1; - return r; - } - r.x = (m^2 - p.x - p.x) % ellip_N; - r.y = ((m * (p.x - r.x)) - p.y) % ellip_N; - return r; + obj point r; + m = ((3 * p.x^2 + ellip_a) * minv(p.y << 1, ellip_N)) % ellip_N; + if (m == 0) { + if (ellip_f == 0) + ellip_f = gcd(p.y << 1, ellip_N); + r.x = 1; + r.y = 1; + return r; + } + r.x = (m^2 - p.x - p.x) % ellip_N; + r.y = ((m * (p.x - r.x)) - p.y) % ellip_N; + return r; } define point_pow(p, pow) { - local bit, r, t; + local bit, r, t; - r = 1; - if (isodd(pow)) - r = p; - t = p; - for (bit = 2; ((bit <= pow) && (ellip_f == 0)); bit <<= 1) { - t = point_square(`t); - if (bit & pow) - r = point_mul(`t, `r); - } - return r; + r = 1; + if (isodd(pow)) + r = p; + t = p; + for (bit = 2; ((bit <= pow) && (ellip_f == 0)); bit <<= 1) { + t = point_square(`t); + if (bit & pow) + r = point_mul(`t, `r); + } + return r; } diff --git a/cal/factorial.cal b/cal/factorial.cal index 59a606c..24ac7f7 100644 --- a/cal/factorial.cal +++ b/cal/factorial.cal @@ -17,8 +17,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2013/08/11 01:31:28 - * File existed as early as: 2013 + * Under source code control: 2013/08/11 01:31:28 + * File existed as early as: 2013 */ diff --git a/cal/factorial2.cal b/cal/factorial2.cal index 94f60da..ab25802 100644 --- a/cal/factorial2.cal +++ b/cal/factorial2.cal @@ -17,8 +17,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2013/08/11 01:31:28 - * File existed as early as: 2013 + * Under source code control: 2013/08/11 01:31:28 + * File existed as early as: 2013 */ @@ -56,7 +56,7 @@ define __CZ__factor_factorial(n,start){ if(start){ if(!isint(start) && start < 0 && start > n) return newerror("__CZ__factor_factorial(n,start): value of " - "parameter 'start' out of range"); + "parameter 'start' out of range"); if(start == n && isprime(n)){ prime_list = mat[1 , 2]; prime_list[0,0] = n; @@ -64,7 +64,7 @@ define __CZ__factor_factorial(n,start){ } else if(!isprime(start) && nextprime(start) >n) return newerror("__CZ__factor_factorial(n,start): value of parameter " - "'start' out of range"); + "'start' out of range"); else{ if(!isprime(start)) prime = nextprime(start); else prime = start; @@ -168,34 +168,34 @@ define __CZ__add_factored_factorials(matrix_2n,matrix_n){ timings - this comb comb-this rel. k/n + this comb comb-this rel. k/n ; benchmark_binomial(10,13) -n=2^13 k=2^10 0.064004 0.016001 + 0.76923076923076923077 -n=2^13 k=2^11 0.064004 0.048003 + 0.84615384615384615385 -n=2^13 k=2^12 0.068004 0.124008 - 0.92307692307692307692 +n=2^13 k=2^10 0.064004 0.016001 + 0.76923076923076923077 +n=2^13 k=2^11 0.064004 0.048003 + 0.84615384615384615385 +n=2^13 k=2^12 0.068004 0.124008 - 0.92307692307692307692 ; benchmark_binomial(10,15) -n=2^15 k=2^10 0.216014 0.024001 + 0.66666666666666666667 -n=2^15 k=2^11 0.220014 0.064004 + 0.73333333333333333333 -n=2^15 k=2^12 0.228014 0.212014 + 0.8 -n=2^15 k=2^13 0.216013 0.664042 - 0.86666666666666666667 -n=2^15 k=2^14 0.240015 1.868117 - 0.93333333333333333333 +n=2^15 k=2^10 0.216014 0.024001 + 0.66666666666666666667 +n=2^15 k=2^11 0.220014 0.064004 + 0.73333333333333333333 +n=2^15 k=2^12 0.228014 0.212014 + 0.8 +n=2^15 k=2^13 0.216013 0.664042 - 0.86666666666666666667 +n=2^15 k=2^14 0.240015 1.868117 - 0.93333333333333333333 ; benchmark_binomial(11,15) -n=2^15 k=2^11 0.216014 0.068004 + 0.73333333333333333333 -n=2^15 k=2^12 0.236015 0.212013 + 0.8 -n=2^15 k=2^13 0.216013 0.656041 - 0.86666666666666666667 -n=2^15 k=2^14 0.244016 1.872117 - 0.93333333333333333333 +n=2^15 k=2^11 0.216014 0.068004 + 0.73333333333333333333 +n=2^15 k=2^12 0.236015 0.212013 + 0.8 +n=2^15 k=2^13 0.216013 0.656041 - 0.86666666666666666667 +n=2^15 k=2^14 0.244016 1.872117 - 0.93333333333333333333 ; benchmark_binomial(11,18) -n=2^18 k=2^11 1.652103 0.100006 + 0.61111111111111111111 -n=2^18 k=2^12 1.608101 0.336021 + 0.66666666666666666667 -n=2^18 k=2^13 1.700106 1.140071 + 0.72222222222222222222 -n=2^18 k=2^14 1.756109 3.924245 - 0.77777777777777777778 -n=2^18 k=2^15 2.036127 13.156822 - 0.83333333333333333333 -n=2^18 k=2^16 2.172135 41.974624 - 0.88888888888888888889 -n=2^18 k=2^17 2.528158 121.523594 - 0.94444444444444444444 +n=2^18 k=2^11 1.652103 0.100006 + 0.61111111111111111111 +n=2^18 k=2^12 1.608101 0.336021 + 0.66666666666666666667 +n=2^18 k=2^13 1.700106 1.140071 + 0.72222222222222222222 +n=2^18 k=2^14 1.756109 3.924245 - 0.77777777777777777778 +n=2^18 k=2^15 2.036127 13.156822 - 0.83333333333333333333 +n=2^18 k=2^16 2.172135 41.974624 - 0.88888888888888888889 +n=2^18 k=2^17 2.528158 121.523594 - 0.94444444444444444444 ; benchmark_binomial(15,25) -n=2^25 k=2^15 303.790985 38.266392 + 0.6 +n=2^25 k=2^15 303.790985 38.266392 + 0.6 ; benchmark_binomial(17,25) -n=2^25 k=2^17 319.127944 529.025062 - 0.68 +n=2^25 k=2^17 319.127944 529.025062 - 0.68 */ define benchmark_binomial(s,limit){ @@ -207,7 +207,7 @@ define benchmark_binomial(s,limit){ T1 = end-start; start=usertime();B=comb(N,K);end=usertime(); T2 = end-start; - print "n=2^"limit,"k=2^"k," ",T1," ",T2,T1 0 be the number if bits in the FNV hash. Then: * - * t = floor((5+n)/12) + * t = floor((5+n)/12) * * The FNV prime, for the given n bits is the smallest prime of the form: * - * p = 256^t + 2^8 + b + * p = 256^t + 2^8 + b * * such that: * - * 0 < b < 2^8 - * The number of one-bits in b must be 4 or 5 - * p mod (2^40 - 2^24 - 1) > (2^24 + 2^8 + 2^7) + * 0 < b < 2^8 + * The number of one-bits in b must be 4 or 5 + * p mod (2^40 - 2^24 - 1) > (2^24 + 2^8 + 2^7) * * If you force n to not be a power of 2, for example: * - * n = 44 + * n = 44 * * you will find that the FNV prime for 44 bits is: * - * p44 = 4294967597 - * = 0x10000012d - * = 0b100000000000000000000000100101101 - * = 2^32 + 301 = 2^32 + 2^8 + 2^5 + 2^3 + 2^2 + 2^0 + * p44 = 4294967597 + * = 0x10000012d + * = 0b100000000000000000000000100101101 + * = 2^32 + 301 = 2^32 + 2^8 + 2^5 + 2^3 + 2^2 + 2^0 * * However a hash size of 44 bits is not a true FNV hash, it is only a "FNV-style" hash. * * NOTE: We disallow n <= 31 because there are no FNV primes that small. * * NOTE: For n that is a power of 2 and n > 1024, you will find that - * that FNV primes become so rare that that one may not find a suitable - * FNV prime. For n = powers of 2 >= 2048 and <= 1048576, - * there is NO FNV primes. + * that FNV primes become so rare that that one may not find a suitable + * FNV prime. For n = powers of 2 >= 2048 and <= 1048576, + * there is NO FNV primes. * - * As for as hashing goes, large values of n, even if an - * FNV hash may be found, are unlikely to be truly useful. :-) + * As for as hashing goes, large values of n, even if an + * FNV hash may be found, are unlikely to be truly useful. :-) */ /* * Copyright (c) 2023 by Landon Curt Noll. All Rights Reserved. @@ -105,86 +105,86 @@ * for a value and provide commends on the value of bits. * * given: - * bits number of bits in the hash, null() ==> prompt for value + * bits number of bits in the hash, null() ==> prompt for value * * returns: - * 0 ==> no FNV prime found - * >0 ==> FNV prime + * 0 ==> no FNV prime found + * >0 ==> FNV prime */ define find_fnv_prime(bits) { - local b; /* lower octet of the potential FNV prime: [1,255] */ - local p; /* value to test as an FNV prime */ - local t; /* power of 256 part of the FNV prime */ - local one_bits; /* number of 1 bits in b */ - local p_minus_b; /* potential FNV prime less b */ - local interactive; /* true ==> interactive mode and print commentary */ + local b; /* lower octet of the potential FNV prime: [1,255] */ + local p; /* value to test as an FNV prime */ + local t; /* power of 256 part of the FNV prime */ + local one_bits; /* number of 1 bits in b */ + local p_minus_b; /* potential FNV prime less b */ + local interactive; /* true ==> interactive mode and print commentary */ /* * case: no arg, prompt for bits and print commentary */ - interactive = 0; /* assume non-interactive mode */ + interactive = 0; /* assume non-interactive mode */ if (isnull(bits)) { - /* - * must be attached to an interactive terminal - */ - if (!isatty(files(0))) { - print "# FATAL: stdin is not a tty: not attached to an interactive terminal"; - return 0; - } - interactive = 1; /* set interactive mode */ + /* + * must be attached to an interactive terminal + */ + if (!isatty(files(0))) { + print "# FATAL: stdin is not a tty: not attached to an interactive terminal"; + return 0; + } + interactive = 1; /* set interactive mode */ - /* - * prompt for the number of bits - */ - do { - local strscanf_ret; /* return from strscanf_ret */ - local input; /* value read after prompt */ + /* + * prompt for the number of bits + */ + do { + local strscanf_ret; /* return from strscanf_ret */ + local input; /* value read after prompt */ - /* - * prompt and obtain the input - */ - input = prompt("Enter hash size in bits: "); - strscanf_ret = strscanf(input, "%i", bits); - print "input =", input; - print "bits =", bits; - if (!isint(bits) || bits <= 0) { - print; - print "# NOTE: must enter a integer > 0, try again"; - print; - } - } while (!isint(bits) || bits <= 0); + /* + * prompt and obtain the input + */ + input = prompt("Enter hash size in bits: "); + strscanf_ret = strscanf(input, "%i", bits); + print "input =", input; + print "bits =", bits; + if (!isint(bits) || bits <= 0) { + print; + print "# NOTE: must enter a integer > 0, try again"; + print; + } + } while (!isint(bits) || bits <= 0); } /* * firewall - bits must be non-negative integer */ if (!isint(bits) || bits < 0) { - if (interactive) { - print "# FATAL: bits must be non-negative integer"; - } - return 0; + if (interactive) { + print "# FATAL: bits must be non-negative integer"; + } + return 0; } /* * provide commentary on the choice of bits if we are interactive */ if (interactive) { - if (popcnt(bits) == 1) { - if (bits > 1024) { - print "# WARNING: FNV primes for bit size powers of 2 > 1024 are extremely rare."; - print "# WARNING: There are no FNV primes for bit size powers of 2 >= 2048 and <= 1048576."; - } - print "n =", bits; - } else { - if (bits < 32) { - print "# WARNING: bits < 32 is not recommended because there isn't enough bits to be worth hashing"; - } - print "# WARNING: because bits is not a power of 2, we can only form an \"FNV-style hash\": not a true FNV hash."; - print "# WARNING: A \"FNV-style hash\" may not have the desired hash properties of a true FNV hash."; - print "n =", bits; - } + if (popcnt(bits) == 1) { + if (bits > 1024) { + print "# WARNING: FNV primes for bit size powers of 2 > 1024 are extremely rare."; + print "# WARNING: There are no FNV primes for bit size powers of 2 >= 2048 and <= 1048576."; + } + print "n =", bits; + } else { + if (bits < 32) { + print "# WARNING: bits < 32 is not recommended because there isn't enough bits to be worth hashing"; + } + print "# WARNING: because bits is not a power of 2, we can only form an \"FNV-style hash\": not a true FNV hash."; + print "# WARNING: A \"FNV-style hash\" may not have the desired hash properties of a true FNV hash."; + print "n =", bits; + } } /* @@ -198,28 +198,28 @@ define find_fnv_prime(bits) */ for (b=1; b < 256; ++b) { - /* - * reject b unless the of one-bits in bottom octet of p is 4 or 5 - */ - one_bits = popcnt(b); - if (one_bits != 4 && one_bits != 5) { - continue; - } + /* + * reject b unless the of one-bits in bottom octet of p is 4 or 5 + */ + one_bits = popcnt(b); + if (one_bits != 4 && one_bits != 5) { + continue; + } - /* - * reject p if p mod (2^40 - 2^24 - 1) <= (2^24 + 2^8 + 2^7) - */ - p = p_minus_b + b; - if ((p % (2^40 - 2^24 - 1)) <= (2^24 + 2^8 + 2^7)) { - continue; - } + /* + * reject p if p mod (2^40 - 2^24 - 1) <= (2^24 + 2^8 + 2^7) + */ + p = p_minus_b + b; + if ((p % (2^40 - 2^24 - 1)) <= (2^24 + 2^8 + 2^7)) { + continue; + } - /* - * accept potential p value that is prime - */ - if (ptest(p) == 1) { - return p; - } + /* + * accept potential p value that is prime + */ + if (ptest(p) == 1) { + return p; + } } /* @@ -227,29 +227,29 @@ define find_fnv_prime(bits) */ if (b >= 256) { - /* - * examine results if interactive - */ - if (interactive) { - print "# FATAL: There is no a suitable FNV prime for bits =", bits; - quit "find_fnv_prime: FATAL: FNV prime search failed"; - } + /* + * examine results if interactive + */ + if (interactive) { + print "# FATAL: There is no a suitable FNV prime for bits =", bits; + quit "find_fnv_prime: FATAL: FNV prime search failed"; + } - /* - * return 0 to indicate no FNV prime found - */ - return 0; + /* + * return 0 to indicate no FNV prime found + */ + return 0; } /* * provide FNV commentary if interactive */ if (interactive) { - print "t =", t; - print "b =", b; - print "# NOTE: p = 256^":t, "+ 2^8 +", b; - print; - print "p =", p; + print "t =", t; + print "b =", b; + print "# NOTE: p = 256^":t, "+ 2^8 +", b; + print; + print "p =", p; } /* @@ -266,44 +266,44 @@ define find_fnv_prime(bits) * for a hash of size bits. * * given: - * bits number of bits in FNV hash - * fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible - * string string to hash + * bits number of bits in FNV hash + * fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible + * string string to hash * * returns: - * FNV-0 hash, for size bytes, of string + * FNV-0 hash, for size bytes, of string * * NOTE: This function does NOT attempt to determine that fnv_prime is prime. */ define deprecated_fnv0(bits, fnv_prime, string) { - local hash; /* FNV hash value */ - local len; /* length of string */ - local base; /* base of FNV hash: 2^bits */ + local hash; /* FNV hash value */ + local len; /* length of string */ + local base; /* base of FNV hash: 2^bits */ local i; /* * firewall */ if (!isint(bits) || bits <= 0) { - quit "deprecated_fnv0: FATAL: bits arg must be an integer > 0"; + quit "deprecated_fnv0: FATAL: bits arg must be an integer > 0"; } if (!isstr(string)) { - quit "deprecated_fnv0: FATAL: string arg must be a string"; + quit "deprecated_fnv0: FATAL: string arg must be a string"; } /* * fnv_prime == null() means to try and generate the FNV prime */ if (isnull(fnv_prime)) { - /* try to generate an FNV prime */ - fnv_prime = find_fnv_prime(bits); - if (fnv_prime == 0) { - quit "deprecated_fnv0: FATAL: no FNV prime exists for the given hash size in bits"; - } + /* try to generate an FNV prime */ + fnv_prime = find_fnv_prime(bits); + if (fnv_prime == 0) { + quit "deprecated_fnv0: FATAL: no FNV prime exists for the given hash size in bits"; + } } if (!isint(fnv_prime) || fnv_prime <= 0) { - quit "deprecated_fnv0: FATAL: fnv_prime arg must be an integer > 0 and should be prime"; + quit "deprecated_fnv0: FATAL: fnv_prime arg must be an integer > 0 and should be prime"; } /* @@ -313,7 +313,7 @@ define deprecated_fnv0(bits, fnv_prime, string) base = 2^bits; hash = 0; for (i=0; i < len; ++i) { - hash = xor((hash * fnv_prime) % base, ord(string[i])); + hash = xor((hash * fnv_prime) % base, ord(string[i])); } return hash; } @@ -323,18 +323,18 @@ define deprecated_fnv0(bits, fnv_prime, string) * fnv_offset_basis - generate and FNV offset basis * * given: - * bits number of bits in FNV hash - * fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible + * bits number of bits in FNV hash + * fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible * * returns: - * FNV offset basis for a hash size of bits and an FNV prime of fnv_prime + * FNV offset basis for a hash size of bits and an FNV prime of fnv_prime * * NOTE: This function does NOT attempt to determine that fnv_prime is prime. */ define fnv_offset_basis(bits, fnv_prime) { - local fnv0_hash = 0; /* FNV-0 hash value */ + local fnv0_hash = 0; /* FNV-0 hash value */ /* string to generate a FNV offset basis - do not change this value */ static chongo_was_here = "chongo /\\../\\"; @@ -343,21 +343,21 @@ fnv_offset_basis(bits, fnv_prime) * firewall */ if (!isint(bits) || bits <= 0) { - quit "fnv_offset_basis: FATAL: bits arg must be an integer > 0"; + quit "fnv_offset_basis: FATAL: bits arg must be an integer > 0"; } /* * fnv_prime == null() means to try and generate the FNV prime */ if (isnull(fnv_prime)) { - /* try to generate an FNV prime */ - fnv_prime = find_fnv_prime(bits); - if (fnv_prime == 0) { - quit "fnv_offset_basis: FATAL: no FNV prime exists for the given hash size in bits"; - } + /* try to generate an FNV prime */ + fnv_prime = find_fnv_prime(bits); + if (fnv_prime == 0) { + quit "fnv_offset_basis: FATAL: no FNV prime exists for the given hash size in bits"; + } } if (!isint(fnv_prime) || fnv_prime <= 0) { - quit "fnv_offset_basis: FATAL: fnv_prime arg must be an integer > 0 and should be prime"; + quit "fnv_offset_basis: FATAL: fnv_prime arg must be an integer > 0 and should be prime"; } /* @@ -374,10 +374,10 @@ fnv_offset_basis(bits, fnv_prime) * These functions, if given non-standard values, will produce bogus results. * To produce a true FNV-1a hash: * - * bits must be a power of 2 - * 32 <= bits - * fnv_prime == find_fnv_prime(bits) OR fnv_prime == null() - * prev_hash == previous FNV hash OR prev_hash == null() + * bits must be a power of 2 + * 32 <= bits + * fnv_prime == find_fnv_prime(bits) OR fnv_prime == null() + * prev_hash == previous FNV hash OR prev_hash == null() * * If fnv_prime == null(), this function will try to compute the FNV prime * for a hash of size bits. @@ -388,64 +388,64 @@ fnv_offset_basis(bits, fnv_prime) * One may chain "FNV-style" hashes by replacing the offset_basis with * the hash state of the previous hash. For the first hash: * - * fnv_prime = find_fnv_prime(bits) - * hash_val = fnv_style_hash(bits, fnv_prime, null(), string_a); + * fnv_prime = find_fnv_prime(bits) + * hash_val = fnv_style_hash(bits, fnv_prime, null(), string_a); * * then: * - * hash_val = fnv_style_hash(bits, fnv_prime, hash_val, string_b); + * hash_val = fnv_style_hash(bits, fnv_prime, hash_val, string_b); * * This will produce the same as the string_a concatenated with string_b: * - * hash_val = fnv_style_hash(bits, null(), null(), string_a + string_b); + * hash_val = fnv_style_hash(bits, null(), null(), string_a + string_b); * * NOTE: Because string_a and string_b are strings, the expression: * - * string_a + string_b + * string_a + string_b * - * is string_a concatenated with string_b. + * is string_a concatenated with string_b. * * given: - * bits number of bits in FNV hash - * fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible - * prev_hash previous hash value, null() ==> generate FNV offset basis - * string string to hash + * bits number of bits in FNV hash + * fnv_prime FNV prime, null() ==> generate suitable FNV prime if possible + * prev_hash previous hash value, null() ==> generate FNV offset basis + * string string to hash * * returns: - * "FNV-style" hash of bits + * "FNV-style" hash of bits * * NOTE: This function does NOT attempt to determine that fnv_prime is prime. */ define fnv1a_style_hash(bits, fnv_prime, prev_hash, string) { - local hash = 0; /* FNV hash value */ - local len; /* length of string */ - local base; /* base of FNV hash: 2^bits */ + local hash = 0; /* FNV hash value */ + local len; /* length of string */ + local base; /* base of FNV hash: 2^bits */ local i; /* * firewall */ if (!isint(bits) || bits <= 0) { - quit "fnv1a_style_hash: FATAL: bits arg must be an integer > 0"; + quit "fnv1a_style_hash: FATAL: bits arg must be an integer > 0"; } if (!isstr(string)) { - quit "fnv1a_style_hash: FATAL: string arg must be a string"; + quit "fnv1a_style_hash: FATAL: string arg must be a string"; } /* * fnv_prime == null() means to try and generate the FNV prime */ if (isnull(fnv_prime)) { - /* try to generate an FNV prime */ - fnv_prime = find_fnv_prime(bits); - if (fnv_prime == 0) { - quit "fnv1a_style_hash: FATAL: no FNV prime exists for the given hash size in bits"; - } + /* try to generate an FNV prime */ + fnv_prime = find_fnv_prime(bits); + if (fnv_prime == 0) { + quit "fnv1a_style_hash: FATAL: no FNV prime exists for the given hash size in bits"; + } } if (!isint(fnv_prime) || fnv_prime <= 0) { - quit "fnv1a_style_hash: FATAL: fnv_prime arg must be an integer > 0 and should be prime"; + quit "fnv1a_style_hash: FATAL: fnv_prime arg must be an integer > 0 and should be prime"; } /* @@ -453,11 +453,11 @@ fnv1a_style_hash(bits, fnv_prime, prev_hash, string) */ if (isnull(prev_hash)) { - /* generate the FNV offset basis for a hash of size bits */ - prev_hash = fnv_offset_basis(bits, fnv_prime); + /* generate the FNV offset basis for a hash of size bits */ + prev_hash = fnv_offset_basis(bits, fnv_prime); } if (!isint(prev_hash) || prev_hash < 0) { - quit "fnv1a_style_hash: FATAL: prev_hash arg must be an integer => 0"; + quit "fnv1a_style_hash: FATAL: prev_hash arg must be an integer => 0"; } /* @@ -467,7 +467,7 @@ fnv1a_style_hash(bits, fnv_prime, prev_hash, string) base = 2^bits; hash = prev_hash; for (i=0; i < len; ++i) { - hash = xor((hash * fnv_prime) % base, ord(string[i])); + hash = xor((hash * fnv_prime) % base, ord(string[i])); } return hash; } diff --git a/cal/gvec.cal b/cal/gvec.cal index e7fa3a4..d857270 100644 --- a/cal/gvec.cal +++ b/cal/gvec.cal @@ -17,37 +17,37 @@ define gvec(function, vector) { local xlen,y,foo; - local precx = 1e-50; /* default for now */ + local precx = 1e-50; /* default for now */ local argc = param(0)-1; - local old_tilde; /* previous config("tilde") */ + local old_tilde; /* previous config("tilde") */ /* * parse args */ local plist = mat[argc]; if (config("resource_debug") & 8) { - print "plist=", plist; - print "argc=", argc; + print "plist=", plist; + print "argc=", argc; } for(local i = 0; i< argc; i++) { - local ii = i + 2; - if (config("resource_debug") & 8) { - print "ii=", ii; - print "param(" : ii : "}=", param(ii); - print "size(param(" : ii : ")=", size(param(ii)); - } - plist[i] = size(param(ii)); + local ii = i + 2; + if (config("resource_debug") & 8) { + print "ii=", ii; + print "param(" : ii : "}=", param(ii); + print "size(param(" : ii : ")=", size(param(ii)); + } + plist[i] = size(param(ii)); } local slist=sort(plist); if (config("resource_debug") & 8) { - print "plist=", plist; + print "plist=", plist; } local argm = argc-1; if (config("resource_debug") & 8) { - print "argm=", argm; + print "argm=", argm; } if (slist[0] != slist[argm]) { - quit "lengths don't match"; + quit "lengths don't match"; } xlen = size(vector); y = mat[xlen]; @@ -67,32 +67,32 @@ define gvec(function, vector) */ if (isdefined(function)) { - /* yep, it's a function, either builtin or user-defined */ - for (local j=0; j 1) { + quit "Error: operator can accept only one argument"; + } + for (j=0; j /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* diff --git a/cal/hms.cal b/cal/hms.cal index 2596f93..0a23094 100644 --- a/cal/hms.cal +++ b/cal/hms.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2010/09/01 17:14:55 - * File existed as early as: 2010 + * Under source code control: 2010/09/01 17:14:55 + * File existed as early as: 2010 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,14 +28,14 @@ obj hms {hour, min, sec}; define hms(hour, min, sec) { - local obj hms ans; /* return value */ + local obj hms ans; /* return value */ /* default missing args to 0 */ if (isnull(sec)) { - sec = 0; + sec = 0; } if (isnull(min)) { - min = 0; + min = 0; } /* load object */ @@ -51,30 +51,30 @@ define hms(hour, min, sec) define hms_add(a, b) { - local obj hms ans; /* return value */ + local obj hms ans; /* return value */ /* initialize value to 1st arg */ if (istype(a, ans)) { - /* 1st arg is hms object, load it */ - ans.hour = a.hour; - ans.min = a.min; - ans.sec = a.sec; + /* 1st arg is hms object, load it */ + ans.hour = a.hour; + ans.min = a.min; + ans.sec = a.sec; } else { - /* 1st arg is not hms, assume scalar hours */ - ans.hour = a; - ans.min = 0; - ans.sec = 0; + /* 1st arg is not hms, assume scalar hours */ + ans.hour = a; + ans.min = 0; + ans.sec = 0; } /* add value of 2nd arg */ if (istype(b, ans)) { - /* 2nd arg is hms object, add it */ - ans.hour += b.hour; - ans.min += b.min; - ans.sec += b.sec; + /* 2nd arg is hms object, add it */ + ans.hour += b.hour; + ans.min += b.min; + ans.sec += b.sec; } else { - /* 2nd arg is not hms, add scalar hours */ - ans.hour += b; + /* 2nd arg is not hms, add scalar hours */ + ans.hour += b; } /* return normalized result */ @@ -85,19 +85,19 @@ define hms_add(a, b) define hms_neg(a) { - local obj hms ans; /* return value */ + local obj hms ans; /* return value */ /* negate argument */ if (istype(a, ans)) { - /* 1st arg is hms object, load it */ - ans.hour = -a.hour; - ans.min = -a.min; - ans.sec = -a.sec; + /* 1st arg is hms object, load it */ + ans.hour = -a.hour; + ans.min = -a.min; + ans.sec = -a.sec; } else { - /* 2nd arg is not hms, negate scalar hours */ - ans.hour = -a; - ans.min = 0; - ans.sec = 0; + /* 2nd arg is not hms, negate scalar hours */ + ans.hour = -a; + ans.min = 0; + ans.sec = 0; } /* return normalized result */ @@ -108,30 +108,30 @@ define hms_neg(a) define hms_sub(a, b) { - local obj hms ans; /* return value */ + local obj hms ans; /* return value */ /* initialize value to 1st arg */ if (istype(a, ans)) { - /* 1st arg is hms object, load it */ - ans.hour = a.hour; - ans.min = a.min; - ans.sec = a.sec; + /* 1st arg is hms object, load it */ + ans.hour = a.hour; + ans.min = a.min; + ans.sec = a.sec; } else { - /* 1st arg is not hms, assume scalar hours */ - ans.hour = a; - ans.min = 0; - ans.sec = 0; + /* 1st arg is not hms, assume scalar hours */ + ans.hour = a; + ans.min = 0; + ans.sec = 0; } /* subtract value of 2nd arg */ if (istype(b, ans)) { - /* 2nd arg is hms object, subtract it */ - ans.hour -= b.hour; - ans.min -= b.min; - ans.sec -= b.sec; + /* 2nd arg is hms object, subtract it */ + ans.hour -= b.hour; + ans.min -= b.min; + ans.sec -= b.sec; } else { - /* 2nd arg is not hms, subtract scalar hours */ - ans.hour -= b; + /* 2nd arg is not hms, subtract scalar hours */ + ans.hour -= b; } /* return normalized result */ @@ -142,23 +142,23 @@ define hms_sub(a, b) define hms_mul(a, b) { - local obj hms ans; /* return value */ + local obj hms ans; /* return value */ /* hms object multiplication */ if (istype(a, ans) && istype(b, ans)) { - ans.hour = hms_abs(a) * hms_abs(b); - ans.min = 0; - ans.sec = 0; + ans.hour = hms_abs(a) * hms_abs(b); + ans.min = 0; + ans.sec = 0; /* scalar multiplication */ } else if (istype(a, ans)) { - ans.hour = a.hour * b; - ans.min = a.min * b; - ans.sec = a.sec * b; + ans.hour = a.hour * b; + ans.min = a.min * b; + ans.sec = a.sec * b; } else { - ans.hour = b.hour * a; - ans.min = b.min * a; - ans.sec = b.sec * a; + ans.hour = b.hour * a; + ans.min = b.min * a; + ans.sec = b.sec * a; } /* return normalized result */ @@ -169,11 +169,11 @@ define hms_mul(a, b) define hms_print(a) { - local obj hms ans; /* temp object for hms type testing */ + local obj hms ans; /* temp object for hms type testing */ /* firewall - arg must be a hms object */ if (! istype(a, ans)) { - quit "hms_print called with non hms object"; + quit "hms_print called with non hms object"; } /* print in hms form */ @@ -183,12 +183,12 @@ define hms_print(a) define hms_abs(a) { - local obj hms ans; /* temp object for hms type testing */ - local hour; /* return scalar value */ + local obj hms ans; /* temp object for hms type testing */ + local hour; /* return scalar value */ /* firewall - just absolute value non hms objects */ if (! istype(a, ans)) { - return abs(a); + return abs(a); } /* compute hours */ @@ -201,12 +201,12 @@ define hms_abs(a) define hms_norm(a) { - local obj hms ans; /* temp object for hms type testing */ - local hour; /* hours */ + local obj hms ans; /* temp object for hms type testing */ + local hour; /* hours */ /* firewall - arg must be a hms object */ if (! istype(a, ans)) { - quit "hms_norm called with non hms object"; + quit "hms_norm called with non hms object"; } /* square hours (norm is the square of absolute value */ @@ -219,18 +219,18 @@ define hms_norm(a) define hms_test(a) { - local obj hms ans; /* temp value */ + local obj hms ans; /* temp value */ /* firewall - arg must be a hms object */ if (! istype(a, ans)) { - quit "hms_test called with non hms object"; + quit "hms_test called with non hms object"; } /* return false of non-zero */ ans = fixhms(a); if (ans.hour == 0 && ans.min == 0 && ans.sec == 0) { - /* false */ - return 0; + /* false */ + return 0; } /* true */ return 1; @@ -239,11 +239,11 @@ define hms_test(a) define hms_int(a) { - local obj hms ans; /* return value */ + local obj hms ans; /* return value */ /* firewall - arg must be a hms object */ if (! istype(a, ans)) { - quit "hms_int called with non hms object"; + quit "hms_int called with non hms object"; } /* normalize the argument */ @@ -259,11 +259,11 @@ define hms_int(a) define hms_frac(a) { - local obj hms ans; /* return value */ + local obj hms ans; /* return value */ /* firewall - arg must be a hms object */ if (! istype(a, ans)) { - quit "hms_frac called with non hms object"; + quit "hms_frac called with non hms object"; } /* normalize the argument */ @@ -281,7 +281,7 @@ define hms_frac(a) define hms_rel(a,b) { - local abs_a, abs_b; /* scalars of the arguments */ + local abs_a, abs_b; /* scalars of the arguments */ /* compute scalars of the arguments */ abs_a = hms_abs(a); @@ -294,7 +294,7 @@ define hms_rel(a,b) define hms_cmp(a,b) { - local abs_a, abs_b; /* scalars of the arguments */ + local abs_a, abs_b; /* scalars of the arguments */ /* compute scalars of the arguments */ abs_a = hms_abs(a); @@ -307,16 +307,16 @@ define hms_cmp(a,b) define hms_inc(a) { - local obj hms ans; /* return value */ + local obj hms ans; /* return value */ /* increment a hms object */ if (istype(a, ans)) { - ans = a; - ++ans.sec; + ans = a; + ++ans.sec; - /* return normalized result */ - ans = fixhms(ans); - return ans; + /* return normalized result */ + ans = fixhms(ans); + return ans; } /* increment a scalar */ @@ -326,16 +326,16 @@ define hms_inc(a) define hms_dec(a) { - local obj hms ans; /* return value */ + local obj hms ans; /* return value */ /* decrement a hms object */ if (istype(a, ans)) { - ans = a; - --ans.sec; + ans = a; + --ans.sec; - /* return normalized result */ - ans = fixhms(ans); - return ans; + /* return normalized result */ + ans = fixhms(ans); + return ans; } /* decrement a scalar */ @@ -345,11 +345,11 @@ define hms_dec(a) define fixhms(a) { - local obj hms ans; /* temp value */ + local obj hms ans; /* temp value */ /* firewall */ if (! istype(a, ans)) { - quit "attempt to fix a non hms object"; + quit "attempt to fix a non hms object"; } /* use builtin h2hms function */ diff --git a/cal/infinities.cal b/cal/infinities.cal index 3f293ae..19b06ad 100644 --- a/cal/infinities.cal +++ b/cal/infinities.cal @@ -26,9 +26,9 @@ resource_debug_level = config("resource_debug", 0); define isinfinite(x) { if (isstr(x)) { - if (strncmp(x, "cinf", 4) == 0 - || strncmp(x, "pinf", 4) == 0 || strncmp(x, "ninf", 4) == 0) - return 1; + if (strncmp(x, "cinf", 4) == 0 + || strncmp(x, "pinf", 4) == 0 || strncmp(x, "ninf", 4) == 0) + return 1; } return 0; } @@ -36,8 +36,8 @@ define isinfinite(x) define iscinf(x) { if (isstr(x)) { - if (strncmp(x, "cinf", 4) == 0) - return 1; + if (strncmp(x, "cinf", 4) == 0) + return 1; } return 0; } @@ -45,8 +45,8 @@ define iscinf(x) define ispinf(x) { if (isstr(x)) { - if (strncmp(x, "pinf", 4) == 0) - return 1; + if (strncmp(x, "pinf", 4) == 0) + return 1; } return 0; } @@ -54,8 +54,8 @@ define ispinf(x) define isninf(x) { if (isstr(x)) { - if (strncmp(x, "ninf", 4) == 0) - return 1; + if (strncmp(x, "ninf", 4) == 0) + return 1; } return 0; } diff --git a/cal/intfile.cal b/cal/intfile.cal index 93772af..e070c46 100644 --- a/cal/intfile.cal +++ b/cal/intfile.cal @@ -27,9 +27,9 @@ /* * 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. + * 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. */ @@ -37,16 +37,16 @@ * file2be - convert a file into an big Endian integer * * given: - * filename filename to read + * filename filename to read * * returns: - * integer read from its contents on big Endian order + * integer read from its contents on big Endian order */ define file2be(filename) { - local fd; /* open file */ - local ret; /* integer to return */ - local c; /* character read from the file */ + local fd; /* open file */ + local ret; /* integer to return */ + local c; /* character read from the file */ local i; /* @@ -62,8 +62,8 @@ define file2be(filename) */ ret = 0; while (! isnull(c = fgetc(fd))) { - ret <<= 8; - ret += ord(c); + ret <<= 8; + ret += ord(c); } /* @@ -78,17 +78,17 @@ define file2be(filename) * file2le - convert a file into an little Endian integer * * given: - * filename filename to read + * filename filename to read * * returns: - * integer read from its contents on little Endian order + * integer read from its contents on little Endian order */ define file2le(filename) { - 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 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; /* @@ -105,8 +105,8 @@ define file2le(filename) ret = 0; shft = 0; while (! isnull(c = fgetc(fd))) { - ret |= (ord(c) << shft); - shft += 8; + ret |= (ord(c) << shft); + shft += 8; } /* @@ -121,25 +121,25 @@ define file2le(filename) * be2file - convert a big Endian integer into a file * * given: - * v integer to write to the file - * filename filename to write + * v integer to write to the file + * filename filename to write * * returns: - * The number of octets written to the file. + * 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 fd; /* open file */ + local octlen; /* length of v in octets */ local i; /* * firewall */ if (!isint(v)) { - quit "be2file: 1st arg not an integer"; + quit "be2file: 1st arg not an integer"; } v = abs(v); @@ -156,7 +156,7 @@ define be2file(v, filename) */ octlen = int((highbit(v)+8) / 8); for (i=octlen-1; i >= 0; --i) { - fputc(fd, char(v >> (i*8))); + fputc(fd, char(v >> (i*8))); } /* @@ -171,24 +171,24 @@ define be2file(v, filename) * le2file - convert a little Endian integer into a file * * given: - * v integer to write to the file - * filename filename to write + * v integer to write to the file + * filename filename to write * * returns: - * The number of octets written to the file. + * 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 */ + local fd; /* open file */ + local cnt; /* octets written */ /* * firewall */ if (!isint(v)) { - quit "be2file: 1st arg not an integer"; + quit "be2file: 1st arg not an integer"; } v = abs(v); @@ -205,9 +205,9 @@ define le2file(v, filename) */ cnt = 0; while (v > 0) { - fputc(fd, char(v)); - v >>= 8; - ++cnt; + fputc(fd, char(v)); + v >>= 8; + ++cnt; } /* diff --git a/cal/intnum.cal b/cal/intnum.cal index befff66..ff58c78 100644 --- a/cal/intnum.cal +++ b/cal/intnum.cal @@ -43,7 +43,7 @@ define quadtscomputenodes(order, expo, eps) local t cht sht chp sum k PI places; local h t0 x w; if (__CZ__tanhsinh_order == order && __CZ__tanhsinh_prec == eps) - return 1; + return 1; __CZ__tanhsinh_order = order; __CZ__tanhsinh_prec = eps; __CZ__tanhsinh_x = list(); @@ -68,34 +68,34 @@ define quadtscomputenodes(order, expo, eps) */ /* make use of x(-t) = -x(t), w(-t) = w(t) */ for (k = 0; k < 20 * order + 1; k++) { - /* - * x = tanh(pi/2 * sinh(t)) - * w = pi/2 * cosh(t) / cosh(pi/2 * sinh(t))^2 - */ - t = bround(t0 + k * h, places); + /* + * x = tanh(pi/2 * sinh(t)) + * w = pi/2 * cosh(t) / cosh(pi/2 * sinh(t))^2 + */ + t = bround(t0 + k * h, places); - cht = bround(cosh(t), places); - sht = bround(sinh(t), places); - chp = bround(cosh(0.5 * PI * sht), places); - x = bround(tanh(0.5 * PI * sht), places); - w = bround((PI * h * cht) / (2 * chp ^ 2), places); - /* - * c = bround(exp(a-b),places); - * d = bround(1/c,places); - * co =bround( (c+d)/2,places); - * si =bround( (c-d)/2,places); - * x = bround(si / co,places); - * w = bround((a+b) / co^2,places); - */ - if (abs(x - 1) <= eps) - break; + cht = bround(cosh(t), places); + sht = bround(sinh(t), places); + chp = bround(cosh(0.5 * PI * sht), places); + x = bround(tanh(0.5 * PI * sht), places); + w = bround((PI * h * cht) / (2 * chp ^ 2), places); + /* + * c = bround(exp(a-b),places); + * d = bround(1/c,places); + * co =bround( (c+d)/2,places); + * si =bround( (c-d)/2,places); + * x = bround(si / co,places); + * w = bround((a+b) / co^2,places); + */ + if (abs(x - 1) <= eps) + break; - append(__CZ__tanhsinh_x, x); - append(__CZ__tanhsinh_w, w); - /* - * a *= udelta; - * b *= urdelta; - */ + append(__CZ__tanhsinh_x, x); + append(__CZ__tanhsinh_w, w); + /* + * a *= udelta; + * b *= urdelta; + */ } /* Normalize the weights to make them add up to 2 (two) */ @@ -119,100 +119,100 @@ define quadtscore(a, b, n) places = highbit(1 + int (1 / epsilon())) +1; m = int (4 + max(0, ln(places / 30.0) / ln(2))) + 2; if (!isnull(n)) { - order = n; - m = ilog(order / 3, 2) + 1; + order = n; + m = ilog(order / 3, 2) + 1; } else - order = 3 * 2 ^ (m - 1); + order = 3 * 2 ^ (m - 1); quadtscomputenodes(order, m, epsilon()); sizel = size(__CZ__tanhsinh_w); if (isinfinite(a) || isinfinite(b)) { - /* - * x - * t = ------------ - * 2 - * sqrt(1 - y ) - */ - if (isninf(a) && ispinf(b)) { - for (k = 0; k < sizel; k++) { - x1 = __CZ__tanhsinh_x[k]; - x2 = -__CZ__tanhsinh_x[k]; - w1 = __CZ__tanhsinh_w[k]; + /* + * x + * t = ------------ + * 2 + * sqrt(1 - y ) + */ + if (isninf(a) && ispinf(b)) { + for (k = 0; k < sizel; k++) { + x1 = __CZ__tanhsinh_x[k]; + x2 = -__CZ__tanhsinh_x[k]; + w1 = __CZ__tanhsinh_w[k]; - x = bround(x1 * (1 - x1 ^ 2) ^ (-1 / 2), places); - xm = bround(x2 * (1 - x2 ^ 2) ^ (-1 / 2), places); - w = bround(w1 * (((1 - x1 ^ 2) ^ (-1 / 2)) / (1 - x1 ^ 2)), - places); - w2 = bround(w1 * (((1 - x2 ^ 2) ^ (-1 / 2)) / (1 - x2 ^ 2)), - places); - sum += bround(w * f(x), places); - sum += bround(w2 * f(xm), places); - } - } - /* - * 1 - * t = - - + b + 1 - * x - */ - else if (isninf(a) && !iscinf(b)) { - for (k = 0; k < sizel; k++) { - x1 = __CZ__tanhsinh_x[k]; - x2 = -__CZ__tanhsinh_x[k]; - w1 = __CZ__tanhsinh_w[k]; - - x = bround((b + 1) - (2 / (x1 + 1)), places); - xm = bround((b + 1) - (2 / (x2 + 1)), places); - w = bround(w1 * (1 / 2 * (2 / (x1 + 1)) ^ 2), places); - w2 = bround(w1 * (1 / 2 * (2 / (x2 + 1)) ^ 2), places); - sum += bround(w * f(x), places); - sum += bround(w2 * f(xm), places); - } - } - /* - * 1 - * t = - + a - 1 - * x - */ - else if (!iscinf(a) && ispinf(b)) { - for (k = 0; k < sizel; k++) { - x1 = __CZ__tanhsinh_x[k]; - x2 = -__CZ__tanhsinh_x[k]; - w1 = __CZ__tanhsinh_w[k]; - x = bround((a - 1) + (2 / (x1 + 1)), places); - xm = bround((a - 1) + (2 / (x2 + 1)), places); - w = bround(w1 * (((1 / 2) * (2 / (x1 + 1)) ^ 2)), places); - w2 = bround(w1 * (((1 / 2) * (2 / (x2 + 1)) ^ 2)), places); - sum += bround(w * f(x), places); - sum += bround(w2 * f(xm), places); - } - } else if (isninf(a) || isninf(b)) { - /*TODO: swap(a,b) and negate(w)? Lookup! */ - return newerror("quadtscore: reverse limits?"); - } else { - return - newerror("quadtscore: complex infinity not yet implemented"); + x = bround(x1 * (1 - x1 ^ 2) ^ (-1 / 2), places); + xm = bround(x2 * (1 - x2 ^ 2) ^ (-1 / 2), places); + w = bround(w1 * (((1 - x1 ^ 2) ^ (-1 / 2)) / (1 - x1 ^ 2)), + places); + w2 = bround(w1 * (((1 - x2 ^ 2) ^ (-1 / 2)) / (1 - x2 ^ 2)), + places); + sum += bround(w * f(x), places); + sum += bround(w2 * f(xm), places); + } } - ret = sum; + /* + * 1 + * t = - - + b + 1 + * x + */ + else if (isninf(a) && !iscinf(b)) { + for (k = 0; k < sizel; k++) { + x1 = __CZ__tanhsinh_x[k]; + x2 = -__CZ__tanhsinh_x[k]; + w1 = __CZ__tanhsinh_w[k]; + + x = bround((b + 1) - (2 / (x1 + 1)), places); + xm = bround((b + 1) - (2 / (x2 + 1)), places); + w = bround(w1 * (1 / 2 * (2 / (x1 + 1)) ^ 2), places); + w2 = bround(w1 * (1 / 2 * (2 / (x2 + 1)) ^ 2), places); + sum += bround(w * f(x), places); + sum += bround(w2 * f(xm), places); + } + } + /* + * 1 + * t = - + a - 1 + * x + */ + else if (!iscinf(a) && ispinf(b)) { + for (k = 0; k < sizel; k++) { + x1 = __CZ__tanhsinh_x[k]; + x2 = -__CZ__tanhsinh_x[k]; + w1 = __CZ__tanhsinh_w[k]; + x = bround((a - 1) + (2 / (x1 + 1)), places); + xm = bround((a - 1) + (2 / (x2 + 1)), places); + w = bround(w1 * (((1 / 2) * (2 / (x1 + 1)) ^ 2)), places); + w2 = bround(w1 * (((1 / 2) * (2 / (x2 + 1)) ^ 2)), places); + sum += bround(w * f(x), places); + sum += bround(w2 * f(xm), places); + } + } else if (isninf(a) || isninf(b)) { + /*TODO: swap(a,b) and negate(w)? Lookup! */ + return newerror("quadtscore: reverse limits?"); + } else { + return + newerror("quadtscore: complex infinity not yet implemented"); + } + ret = sum; } else { - /* Avoid rounding errors */ - if (a == -1 && b == 1) { - c = 1; - d = 0; - } else { - c = (b - a) / 2; - d = (b + a) / 2; - } - sum = 0; - for (k = 0; k < sizel; k++) { - sum += - bround(__CZ__tanhsinh_w[k] * f(c * __CZ__tanhsinh_x[k] + d), - places); - sum += - bround(__CZ__tanhsinh_w[k] * f(c * -__CZ__tanhsinh_x[k] + d), - places); - } - ret = c * sum; + /* Avoid rounding errors */ + if (a == -1 && b == 1) { + c = 1; + d = 0; + } else { + c = (b - a) / 2; + d = (b + a) / 2; + } + sum = 0; + for (k = 0; k < sizel; k++) { + sum += + bround(__CZ__tanhsinh_w[k] * f(c * __CZ__tanhsinh_x[k] + d), + places); + sum += + bround(__CZ__tanhsinh_w[k] * f(c * -__CZ__tanhsinh_x[k] + d), + places); + } + ret = c * sum; } epsilon(eps); return ret; @@ -225,97 +225,97 @@ define quadts(a, b, points) local k sp results epsbits nsect interval length segment slope C ; local x1 x2 y1 y2 sum D1 D2 D3 D4; if (param(0) < 2) - return newerror("quadts: not enough arguments"); + return newerror("quadts: not enough arguments"); epsbits = highbit(1 + int (1 / epsilon())) +1; if (param(0) < 3 || isnull(points)) { - /* return as given */ - return quadtscore(a, b); + /* return as given */ + return quadtscore(a, b); } else { - if ((isinfinite(a) || isinfinite(b)) - && (!ismat(points) && !islist(points))) - return - newerror(strcat - ("quadts: segments of infinite length ", - "are not yet supported")); - if (ismat(points) || islist(points)) { - sp = size(points); - if (sp == 0) - return - newerror(strcat - ("quadts: variable 'points` must be a list or ", - "1d-matrix of a length > 0")); - /* check if all points are numbers */ - for (k = 0; k < sp; k++) { - if (!isnum(points[k])) - return - newerror(strcat - ("quadts: elements of 'points` must be", - " numbers only")); - } - /* We have n-1 intervals and a and b, hence n-1 + 2 results */ - results = mat[sp + 1]; + if ((isinfinite(a) || isinfinite(b)) + && (!ismat(points) && !islist(points))) + return + newerror(strcat + ("quadts: segments of infinite length ", + "are not yet supported")); + if (ismat(points) || islist(points)) { + sp = size(points); + if (sp == 0) + return + newerror(strcat + ("quadts: variable 'points` must be a list or ", + "1d-matrix of a length > 0")); + /* check if all points are numbers */ + for (k = 0; k < sp; k++) { + if (!isnum(points[k])) + return + newerror(strcat + ("quadts: elements of 'points` must be", + " numbers only")); + } + /* We have n-1 intervals and a and b, hence n-1 + 2 results */ + results = mat[sp + 1]; if (a != points[0]) { - results[0] = quadtscore(a, points[0]); + results[0] = quadtscore(a, points[0]); } else { results[0] = 0; } - if (sp == 1) { + if (sp == 1) { if (b != points[0]) { - results[1] = quadtscore(points[0], b); + results[1] = quadtscore(points[0], b); } else { results[1] = 0; } - } else { - for (k = 1; k < sp; k++) { - results[k] = quadtscore(points[k - 1], points[k]); - } + } else { + for (k = 1; k < sp; k++) { + results[k] = quadtscore(points[k - 1], points[k]); + } if (b != points[k - 1]) { - results[k] = quadtscore(points[k - 1], b); + results[k] = quadtscore(points[k - 1], b); } else { results[k] = 0; } - } - } else { - if (!isint(points) || points <= 0) - return newerror(strcat("quadts: variable 'points` must be a ", - "list or a positive integer")); - /* Taking "points" as the number of equally spaced intervals */ - results = mat[points + 1]; - /* It is easy if a,b lie on the real line */ - if (isreal(a) && isreal(b)) { - length = abs(a - b); - segment = length / points; + } + } else { + if (!isint(points) || points <= 0) + return newerror(strcat("quadts: variable 'points` must be a ", + "list or a positive integer")); + /* Taking "points" as the number of equally spaced intervals */ + results = mat[points + 1]; + /* It is easy if a,b lie on the real line */ + if (isreal(a) && isreal(b)) { + length = abs(a - b); + segment = length / points; - for (k = 1; k <= points; k++) { - results[k - 1] = - quadtscore(a + (k - 1) * segment, a + k * segment); - } - } else { - /* We have at least one complex limit but treat "points" still + for (k = 1; k <= points; k++) { + results[k - 1] = + quadtscore(a + (k - 1) * segment, a + k * segment); + } + } else { + /* We have at least one complex limit but treat "points" still * as the number of equally spaced intervals on a straight line * connecting a and b. Computing the segments here is a bit * more complicated but not much, it should have been taught in * high school. - * Other contours by way of a list of points */ - slope = (im(b) - im(a)) / (re(b) - re(a)); - C = (im(a) + slope) * re(a); - length = abs(re(a) - re(b)); - segment = length / points; + * Other contours by way of a list of points */ + slope = (im(b) - im(a)) / (re(b) - re(a)); + C = (im(a) + slope) * re(a); + length = abs(re(a) - re(b)); + segment = length / points; - /* y = mx+C where m is the slope, x is the real part and y the - * imaginary part */ + /* y = mx+C where m is the slope, x is the real part and y the + * imaginary part */ if(re(a)>re(b))swap(a,b); - for (k = re(a); k <= (re(b)); k+=segment) { - x1 = slope*(k) + C; - results[k] = quadtscore(k + x1 * 1i); - } - } /* else of isreal */ - } /* else of ismat|islist */ - } /* else of isnull(points) */ + for (k = re(a); k <= (re(b)); k+=segment) { + x1 = slope*(k) + C; + results[k] = quadtscore(k + x1 * 1i); + } + } /* else of isreal */ + } /* else of ismat|islist */ + } /* else of isnull(points) */ /* With a bit of undeserved luck we have a result by now. */ sp = size(results); for (k = 0; k < sp; k++) { - sum += results[k]; + sum += results[k]; } return sum; } @@ -330,7 +330,7 @@ define quadglcomputenodes(N) local places k l x w t1 t2 t3 t4 t5 r tmp; if (__CZ__gl_order == N && __CZ__gl_prec == epsilon()) - return; + return; __CZ__gl_x = mat[N]; __CZ__gl_w = mat[N]; @@ -344,28 +344,28 @@ define quadglcomputenodes(N) * Trick shamelessly stolen from D. Bailey et .al (program "arprec") */ for (k = 1; k <= N//2; k++) { - r = bround(cos(pi() * (k - .25) / (N + .5)), places); - while (1) { - t1 = 1, t2 = 0; - for (l = 1; l <= N; l++) { - t3 = t2; - t2 = t1; - t1 = bround(((2 * l - 1) * r * t2 - (l - 1) * t3) / l, places); - } - t4 = bround(N * (r * t1 - t2) / ((r ^ 2) - 1), places); - t5 = r; - tmp = t1 / t4; - r = r - tmp; - if (abs(tmp) <= epsilon()) - break; - } - x = r; - w = bround(2 / ((1 - r ^ 2) * t4 ^ 2), places); + r = bround(cos(pi() * (k - .25) / (N + .5)), places); + while (1) { + t1 = 1, t2 = 0; + for (l = 1; l <= N; l++) { + t3 = t2; + t2 = t1; + t1 = bround(((2 * l - 1) * r * t2 - (l - 1) * t3) / l, places); + } + t4 = bround(N * (r * t1 - t2) / ((r ^ 2) - 1), places); + t5 = r; + tmp = t1 / t4; + r = r - tmp; + if (abs(tmp) <= epsilon()) + break; + } + x = r; + w = bround(2 / ((1 - r ^ 2) * t4 ^ 2), places); - __CZ__gl_x[k - 1] = x; - __CZ__gl_w[k - 1] = w; - __CZ__gl_x[N - k] = -__CZ__gl_x[k - 1]; - __CZ__gl_w[N - k] = __CZ__gl_w[k - 1]; + __CZ__gl_x[k - 1] = x; + __CZ__gl_w[k - 1] = w; + __CZ__gl_x[N - k] = -__CZ__gl_x[k - 1]; + __CZ__gl_w[N - k] = __CZ__gl_w[k - 1]; } return; } @@ -386,64 +386,64 @@ define quadglcore(a, b, n) eps = epsilon(epsilon() * 1e-2); places = highbit(1 + int (1 / epsilon())) +1; if (!isnull(n)) - order = n; + order = n; else { - m = int (4 + max(0, ln(places / 30.0) / ln(2))) + 2; - order = 3 * 2 ^ (m - 1); + m = int (4 + max(0, ln(places / 30.0) / ln(2))) + 2; + order = 3 * 2 ^ (m - 1); } quadglcomputenodes(order, 1); if (isinfinite(a) || isinfinite(b)) { - if (isninf(a) && ispinf(b)) { - for (k = 0; k < order; k++) { - x1 = __CZ__gl_x[k]; - w1 = __CZ__gl_w[k]; + if (isninf(a) && ispinf(b)) { + for (k = 0; k < order; k++) { + x1 = __CZ__gl_x[k]; + w1 = __CZ__gl_w[k]; - x = bround(x1 * (1 - x1 ^ 2) ^ (-1 / 2), places); - w = bround(w1 * (((1 - x1 ^ 2) ^ (-1 / 2)) / (1 - x1 ^ 2)), - places); - sum += bround(w * f(x), places); - } - } else if (isninf(a) && !iscinf(b)) { - for (k = 0; k < order; k++) { - x1 = __CZ__gl_x[k]; - w1 = __CZ__gl_w[k]; + x = bround(x1 * (1 - x1 ^ 2) ^ (-1 / 2), places); + w = bround(w1 * (((1 - x1 ^ 2) ^ (-1 / 2)) / (1 - x1 ^ 2)), + places); + sum += bround(w * f(x), places); + } + } else if (isninf(a) && !iscinf(b)) { + for (k = 0; k < order; k++) { + x1 = __CZ__gl_x[k]; + w1 = __CZ__gl_w[k]; - x = bround((b + 1) - (2 / (x1 + 1)), places); - w = bround(w1 * (1 / 2 * (2 / (x1 + 1)) ^ 2), places); - sum += bround(w * f(x), places); - } - } else if (!iscinf(a) && ispinf(b)) { - for (k = 0; k < order; k++) { - x1 = __CZ__gl_x[k]; - w1 = __CZ__gl_w[k]; - x = bround((a - 1) + (2 / (x1 + 1)), places); - w = bround(w1 * (((1 / 2) * (2 / (x1 + 1)) ^ 2)), places); - sum += bround(w * f(x), places); - } - } else if (isninf(a) || isninf(b)) { - /*TODO: swap(a,b) and negate(w)? Lookup! */ - return newerror("quadglcore: reverse limits?"); - } else - return - newerror("quadglcore: complex infinity not yet implemented"); - ret = sum; + x = bround((b + 1) - (2 / (x1 + 1)), places); + w = bround(w1 * (1 / 2 * (2 / (x1 + 1)) ^ 2), places); + sum += bround(w * f(x), places); + } + } else if (!iscinf(a) && ispinf(b)) { + for (k = 0; k < order; k++) { + x1 = __CZ__gl_x[k]; + w1 = __CZ__gl_w[k]; + x = bround((a - 1) + (2 / (x1 + 1)), places); + w = bround(w1 * (((1 / 2) * (2 / (x1 + 1)) ^ 2)), places); + sum += bround(w * f(x), places); + } + } else if (isninf(a) || isninf(b)) { + /*TODO: swap(a,b) and negate(w)? Lookup! */ + return newerror("quadglcore: reverse limits?"); + } else + return + newerror("quadglcore: complex infinity not yet implemented"); + ret = sum; } else { - /* Avoid rounding errors */ - if (a == -1 && b == 1) { - c = 1; - d = 0; - } else { - c = (b - a) / 2; - d = (b + a) / 2; - } - sum = 0; - for (k = 0; k < order; k++) { - sum += bround(__CZ__gl_w[k] * f(c * __CZ__gl_x[k] + d), places); - } - ret = c * sum; + /* Avoid rounding errors */ + if (a == -1 && b == 1) { + c = 1; + d = 0; + } else { + c = (b - a) / 2; + d = (b + a) / 2; + } + sum = 0; + for (k = 0; k < order; k++) { + sum += bround(__CZ__gl_w[k] * f(c * __CZ__gl_x[k] + d), places); + } + ret = c * sum; } epsilon(eps); return ret; @@ -452,97 +452,97 @@ define quadglcore(a, b, n) define quadgl(a, b, points) { local k sp results epsbits nsect interval length segment slope C x1 y1 x2 - y2; + y2; local sum D1 D2 D3 D4; if (param(0) < 2) - return newerror("quadgl: not enough arguments"); + return newerror("quadgl: not enough arguments"); epsbits = highbit(1 + int (1 / epsilon())) +1; if (isnull(points)) { - /* return as given */ - return quadglcore(a, b); + /* return as given */ + return quadglcore(a, b); } else { - /* But if we could half the time needed to execute a single operation - * we could do all of it in just twice that time. */ - if (isinfinite(a) || isinfinite(b) - && (!ismat(points) && !islist(points))) - return - newerror(strcat - ("quadgl: multiple segments of infinite length ", - "are not yet supported")); - if (ismat(points) || islist(points)) { - sp = size(points); - if (sp == 0) - return - newerror(strcat - ("quadgl: variable 'points` must be a list or ", - "1d-matrix of a length > 0")); - /* check if all points are numbers */ - for (k = 0; k < sp; k++) { - if (!isnum(points[k])) - return - newerror(strcat - ("quadgl: elements of 'points` must be ", - "numbers only")); - } - /* We have n-1 intervals and a and b, hence n-1 + 2 results */ - results = mat[sp + 1]; + /* But if we could half the time needed to execute a single operation + * we could do all of it in just twice that time. */ + if (isinfinite(a) || isinfinite(b) + && (!ismat(points) && !islist(points))) + return + newerror(strcat + ("quadgl: multiple segments of infinite length ", + "are not yet supported")); + if (ismat(points) || islist(points)) { + sp = size(points); + if (sp == 0) + return + newerror(strcat + ("quadgl: variable 'points` must be a list or ", + "1d-matrix of a length > 0")); + /* check if all points are numbers */ + for (k = 0; k < sp; k++) { + if (!isnum(points[k])) + return + newerror(strcat + ("quadgl: elements of 'points` must be ", + "numbers only")); + } + /* We have n-1 intervals and a and b, hence n-1 + 2 results */ + results = mat[sp + 1]; if (a != points[0]) { - results[0] = quadglcore(a, points[0]); + results[0] = quadglcore(a, points[0]); } else { results[0] = 0; } - if (sp == 1) { - if (b != points[0]) { - results[1] = quadglcore(points[0], b); + if (sp == 1) { + if (b != points[0]) { + results[1] = quadglcore(points[0], b); } else { results[1] = 0; } - } else { - for (k = 1; k < sp; k++) { - results[k] = quadglcore(points[k - 1], points[k]); - } + } else { + for (k = 1; k < sp; k++) { + results[k] = quadglcore(points[k - 1], points[k]); + } if (b != points[k - 1]) { - results[k] = quadglcore(points[k - 1], b); + results[k] = quadglcore(points[k - 1], b); } else { results[k] = 0; } - } - } else { - if (!isint(points) || points <= 0) - return newerror(strcat("quadgl: variable 'points` must be a ", - "list or a positive integer")); - /* Taking "points" as the number of equally spaced intervals */ - results = mat[points + 1]; - /* It is easy if a,b lie on the real line */ - if (isreal(a) && isreal(b)) { - length = abs(a - b); - segment = length / points; + } + } else { + if (!isint(points) || points <= 0) + return newerror(strcat("quadgl: variable 'points` must be a ", + "list or a positive integer")); + /* Taking "points" as the number of equally spaced intervals */ + results = mat[points + 1]; + /* It is easy if a,b lie on the real line */ + if (isreal(a) && isreal(b)) { + length = abs(a - b); + segment = length / points; - for (k = 1; k <= points; k++) { - results[k - 1] = - quadglcore(a + (k - 1) * segment, a + k * segment); - } - } else { - /* Other contours by way of a list of points */ - slope = (im(b) - im(a)) / (re(b) - re(a)); - C = (im(a) + slope) * re(a); - length = abs(re(a) - re(b)); - segment = length / points; + for (k = 1; k <= points; k++) { + results[k - 1] = + quadglcore(a + (k - 1) * segment, a + k * segment); + } + } else { + /* Other contours by way of a list of points */ + slope = (im(b) - im(a)) / (re(b) - re(a)); + C = (im(a) + slope) * re(a); + length = abs(re(a) - re(b)); + segment = length / points; - /* y = mx+C where m is the slope, x is the real part and y the - * imaginary part */ + /* y = mx+C where m is the slope, x is the real part and y the + * imaginary part */ if(re(a)>re(b))swap(a,b); - for (k = re(a); k <= (re(b)); k+=segment) { - x1 = slope*(k) + C; - results[k] = quadglcore(k + x1 * 1i); - } - } /* else of isreal */ - } /* else of ismat|islist */ - } /* else of isnull(points) */ + for (k = re(a); k <= (re(b)); k+=segment) { + x1 = slope*(k) + C; + results[k] = quadglcore(k + x1 * 1i); + } + } /* else of isreal */ + } /* else of ismat|islist */ + } /* else of isnull(points) */ /* With a bit of undeserved luck we have a result by now. */ sp = size(results); for (k = 0; k < sp; k++) { - sum += results[k]; + sum += results[k]; } return sum; } @@ -550,49 +550,49 @@ define quadgl(a, b, points) define quad(a, b, points = -1, method = "tanhsinh") { if (isnull(a) || isnull(b) || param(0) < 2) - return newerror("quad: both limits must be given"); + return newerror("quad: both limits must be given"); if (isstr(a)) { - if (strncmp(a, "cinf", 1) == 0) - return - newerror(strcat - ("quad: complex infinity not yet supported, use", - " 'pinf' or 'ninf' respectively")); + if (strncmp(a, "cinf", 1) == 0) + return + newerror(strcat + ("quad: complex infinity not yet supported, use", + " 'pinf' or 'ninf' respectively")); } if (isstr(b)) { - if (strncmp(b, "cinf", 1) == 0) - return - newerror(strcat - ("quad: complex infinity not yet supported, use", - " 'pinf' or 'ninf' respectively")); + if (strncmp(b, "cinf", 1) == 0) + return + newerror(strcat + ("quad: complex infinity not yet supported, use", + " 'pinf' or 'ninf' respectively")); } if (param(0) == 3) { - if (isstr(points)) - method = points; + if (isstr(points)) + method = points; } if (strncmp(method, "tanhsinh", 1) == 0) { - if (!isstr(points)) { - if (points == -1) { - return quadts(a, b); - } else { - return quadts(a, b, points); - } - } else { - return quadts(a, b); - } + if (!isstr(points)) { + if (points == -1) { + return quadts(a, b); + } else { + return quadts(a, b, points); + } + } else { + return quadts(a, b); + } } if (strncmp(method, "gausslegendre", 1) == 0) { - if (!isstr(points)) { - if (points == -1) { - return quadgl(a, b); - } else { - return quadgl(a, b, points); - } - } else { - return quadgl(a, b); - } + if (!isstr(points)) { + if (points == -1) { + return quadgl(a, b); + } else { + return quadgl(a, b, points); + } + } else { + return quadgl(a, b); + } } } @@ -602,33 +602,33 @@ define makerange(start, end, steps) local segment; steps = int (steps); if (steps < 1) { - return newerror("makerange: number of steps must be > 0"); + return newerror("makerange: number of steps must be > 0"); } if (!isnum(start) || !isnum(end)) { - return newerror("makerange: only numbers are supported yet"); + return newerror("makerange: only numbers are supported yet"); } if (isreal(start) && isreal(end)) { - step = (end - start) / (steps); - print step; - ret = mat[steps + 1]; - for (k = 0; k <= steps; k++) { - ret[k] = k * step + start; - } + step = (end - start) / (steps); + print step; + ret = mat[steps + 1]; + for (k = 0; k <= steps; k++) { + ret[k] = k * step + start; + } } else { - ret = mat[steps + 1]; - if (re(start) > re(end)) { - swap(start, end); - } + ret = mat[steps + 1]; + if (re(start) > re(end)) { + swap(start, end); + } - slope = (im(end) - im(start)) / (re(end) - re(start)); - C = im(start) - slope * re(start); - length = abs(re(start) - re(end)); - segment = length / (steps); + slope = (im(end) - im(start)) / (re(end) - re(start)); + C = im(start) - slope * re(start); + length = abs(re(start) - re(end)); + segment = length / (steps); - for (k = re(start), l = 0; k <= (re(end)); k += segment, l++) { - x1 = slope * (k) + C; - ret[l] = k + x1 * 1i; - } + for (k = re(start), l = 0; k <= (re(end)); k += segment, l++) { + x1 = slope * (k) + C; + ret[l] = k + x1 * 1i; + } } return ret; @@ -638,23 +638,23 @@ define makecircle(radius, center, points) { local ret k a b twopi centerx centery; if (!isint(points) || points < 2) { - return - newerror("makecircle: number of points is not a positive integer"); + return + newerror("makecircle: number of points is not a positive integer"); } if (!isnum(center)) { - return newerror("makecircle: center does not lie on the complex plane"); + return newerror("makecircle: center does not lie on the complex plane"); } if (!isreal(radius) || radius <= 0) { - return newerror("makecircle: radius is not a real > 0"); + return newerror("makecircle: radius is not a real > 0"); } ret = mat[points]; twopi = 2 * pi(); centerx = re(center); centery = im(center); for (k = 0; k < points; k++) { - a = centerx + radius * cos(twopi * k / points); - b = centery + radius * sin(twopi * k / points); - ret[k] = a + b * 1i; + a = centerx + radius * cos(twopi * k / points); + b = centery + radius * sin(twopi * k / points); + ret[k] = a + b * 1i; } return ret; } @@ -663,32 +663,32 @@ define makeellipse(angle, a, b, center, points) { local ret k x y twopi centerx centery; if (!isint(points) || points < 2) { - return - newerror("makeellipse: number of points is not a positive integer"); + return + newerror("makeellipse: number of points is not a positive integer"); } if (!isnum(center)) { - return - newerror("makeellipse: center does not lie on the complex plane"); + return + newerror("makeellipse: center does not lie on the complex plane"); } if (!isreal(a) || a <= 0) { - return newerror("makecircle: a is not a real > 0"); + return newerror("makecircle: a is not a real > 0"); } if (!isreal(b) || b <= 0) { - return newerror("makecircle: b is not a real > 0"); + return newerror("makecircle: b is not a real > 0"); } if (!isreal(angle)) { - return newerror("makecircle: angle is not a real"); + return newerror("makecircle: angle is not a real"); } ret = mat[points]; twopi = 2 * pi(); centerx = re(center); centery = im(center); for (k = 0; k < points; k++) { - x = centerx + a * cos(twopi * k / points) * cos(angle) - - b * sin(twopi * k / points) * sin(angle); - y = centerx + a * cos(twopi * k / points) * sin(angle) - + b * sin(twopi * k / points) * cos(angle); - ret[k] = x + y * 1i; + x = centerx + a * cos(twopi * k / points) * cos(angle) + - b * sin(twopi * k / points) * sin(angle); + y = centerx + a * cos(twopi * k / points) * sin(angle) + + b * sin(twopi * k / points) * cos(angle); + ret[k] = x + y * 1i; } return ret; } @@ -698,13 +698,13 @@ define makepoints() local ret k; ret = mat[param(0)]; for (k = 0; k < param(0); k++) { - if (!isnum(param(k + 1))) { - return - newerror(strcat - ("makepoints: parameter number \"", str(k + 1), - "\" is not a number")); - } - ret[k] = param(k + 1); + if (!isnum(param(k + 1))) { + return + newerror(strcat + ("makepoints: parameter number \"", str(k + 1), + "\" is not a number")); + } + ret[k] = param(k + 1); } return ret; } diff --git a/cal/lambertw.cal b/cal/lambertw.cal index 9ac6e5d..c0a0bd2 100644 --- a/cal/lambertw.cal +++ b/cal/lambertw.cal @@ -17,8 +17,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2013/08/11 01:31:28 - * File existed as early as: 2013 + * Under source code control: 2013/08/11 01:31:28 + * File existed as early as: 2013 */ @@ -109,10 +109,10 @@ define lambertw_series_print(){ The exact branch must be given explicitly, e.g.: ; lambertw(-exp(-1)+.001)-lambertw_series(-exp(-1)+.001,epsilon()*1e-10,0) - -0.14758879113205794065490184399030194122136720202792- + -0.14758879113205794065490184399030194122136720202792- 0.00000000000000000000000000000000000000000000000000i ; lambertw(-exp(-1)+.001)-lambertw_series(-exp(-1)+.001,epsilon()*1e-10,1) - 0.00000000000000000000000000000000000000000000000000- + 0.00000000000000000000000000000000000000000000000000- 0.00000000000000000000000000000000000000000000000000i */ define lambertw_series(z,eps,branch,terms){ @@ -210,34 +210,34 @@ define lambertw(z,branch){ sufficient precision itself (M below was calculated by Mathematica and also with the series above with epsilon(1e-200)): ; epsilon(1e-50) - 0.00000000000000000001 + 0.00000000000000000001 ; display(50) - 20 + 20 ; M=-0.9999999999999999999999997668356018402875796636464119050387 ; lambertw(-exp(-1)+1e-50,0)-M - -0.00000000000000000000000002678416515423276355643684 + -0.00000000000000000000000002678416515423276355643684 ; epsilon(1e-60) - 0.0000000000000000000000000000000000000000000000000 + 0.0000000000000000000000000000000000000000000000000 ; A=-exp(-1)+1e-50 ; epsilon(1e-50) - 0.00000000000000000000000000000000000000000000000000 + 0.00000000000000000000000000000000000000000000000000 ; lambertw(A,0)-M - -0.00000000000000000000000000000000000231185460220585 + -0.00000000000000000000000000000000000231185460220585 ; lambertw_series(A,epsilon(),0)-M - -0.00000000000000000000000000000000000132145133161626 + -0.00000000000000000000000000000000000132145133161626 ; epsilon(1e-100) - 0.00000000000000000000000000000000000000000000000001 + 0.00000000000000000000000000000000000000000000000001 ; A=-exp(-1)+1e-50 ; epsilon(1e-65) - 0.00000000000000000000000000000000000000000000000000 + 0.00000000000000000000000000000000000000000000000000 ; lambertw_series(A,epsilon(),0)-M - 0.00000000000000000000000000000000000000000000000000 + 0.00000000000000000000000000000000000000000000000000 ; lambertw_series(-exp(-1)+1e-50,epsilon(),0)-M - -0.00000000000000000000000000000000000000002959444084 + -0.00000000000000000000000000000000000000002959444084 ; epsilon(1e-74) - 0.00000000000000000000000000000000000000000000000000 + 0.00000000000000000000000000000000000000000000000000 ; lambertw_series(-exp(-1)+1e-50,epsilon(),0)-M - -0.00000000000000000000000000000000000000000000000006 + -0.00000000000000000000000000000000000000000000000006 */ closeness = abs(z-branchpoint); if( closeness< 1){ diff --git a/cal/linear.cal b/cal/linear.cal index 507e1f4..b9831ec 100644 --- a/cal/linear.cal +++ b/cal/linear.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,23 +17,23 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2005/12/12 06:41:50 - * File existed as early as: 2005 + * Under source code control: 2005/12/12 06:41:50 + * File existed as early as: 2005 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * linear - perform a simple two point 2D linear interpolation * * given: - * x0, y0 first known point on the line - * x1, y1 second known point on the line - * x a given point to interpolate on + * x0, y0 first known point on the line + * x1, y1 second known point on the line + * x a given point to interpolate on * * returns: - * y such that (x,y) is on the line defined by (x0,y0) and (x1,y1) + * y such that (x,y) is on the line defined by (x0,y0) and (x1,y1) * * NOTE: The line cannot be vertical. So x0 != y0. */ @@ -41,10 +41,10 @@ define linear(x0, y0, x1, y1, x) { /* firewall */ if (!isnum(x0) || ! isnum(y0) || !isnum(x1) || ! isnum(y1) || !isnum(x)) { - quit "non-numeric argument passed to linear"; + quit "non-numeric argument passed to linear"; } if (x0 == x1) { - quit "linear given a line with an infinite slope"; + quit "linear given a line with an infinite slope"; } /* return y = y0 + (delta_Y/delta_X) * (x - x0) */ diff --git a/cal/lnseries.cal b/cal/lnseries.cal index 2c89126..a3862c9 100644 --- a/cal/lnseries.cal +++ b/cal/lnseries.cal @@ -17,8 +17,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2013/08/11 01:31:28 - * File existed as early as: 2013 + * Under source code control: 2013/08/11 01:31:28 + * File existed as early as: 2013 */ diff --git a/cal/lucas.cal b/cal/lucas.cal index 5868411..de794d7 100644 --- a/cal/lucas.cal +++ b/cal/lucas.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,31 +17,31 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/05/03 16:49:51 - * File existed as early as: 1990 + * Under source code control: 1990/05/03 16:49:51 + * File existed as early as: 1990 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * For a general tutorial on how to find a new largest known prime, see: * - * http://www.isthe.com/chongo/tech/math/prime/prime-tutorial.pdf + * http://www.isthe.com/chongo/tech/math/prime/prime-tutorial.pdf * * Also see the reference code, available both C and go: * - * https://github.com/arcetri/goprime + * https://github.com/arcetri/goprime */ /* * NOTE: This is a standard calc resource file. For information on calc see: * - * http://www.isthe.com/chongo/tech/comp/calc/index.html + * http://www.isthe.com/chongo/tech/comp/calc/index.html * * To obtain your own copy of calc, see: * - * http://www.isthe.com/chongo/tech/comp/calc/calc-download.html + * http://www.isthe.com/chongo/tech/comp/calc/calc-download.html */ /* @@ -51,33 +51,33 @@ * John Brown, Landon Curt Noll, Bodo Parady, Gene Smith, Joel Smith and * Sergio Zarantonello proved the following 65087 digit number to be prime: * - * 216193 - * 391581 * 2 -1 + * 216193 + * 391581 * 2 -1 * * At the time of discovery, this number was the largest known prime. * The primality was demonstrated by a program implementing the test * found in these routines. An Amdahl 1200 takes 1987 seconds to test * the primality of this number. A Cray 2 took several hours to - * confirm this prime. As of 31 Dec 1995, this prime was the 3rd + * confirm this prime. As of 31 Dec 1995, this prime was the 3rd * largest known prime and the largest known non-Mersenne prime. * * The same team also discovered the following twin prime pair: * - * 11235 11235 - * 1706595 * 2 -1 1706595 * 2 +1 + * 11235 11235 + * 1706595 * 2 -1 1706595 * 2 +1 * * At the time of discovery, this was the largest known twin prime pair. * * See: * - * http://www.isthe.com/chongo/tech/math/prime/amdahl6.html + * http://www.isthe.com/chongo/tech/math/prime/amdahl6.html * * for more information on the Amdahl 6 group. * * NOTE: Both largest known and largest known twin prime records have been - * broken. Rather than update this file each time, I'll just - * congratulate the finders and encourage others to try for - * larger finds. Records were made to be broken after all! + * broken. Rather than update this file each time, I'll just + * congratulate the finders and encourage others to try for + * larger finds. Records were made to be broken after all! */ /* @@ -85,7 +85,7 @@ * * For a general tutorial on how to find a new largest known prime, see: * - * http://www.isthe.com/chongo/tech/math/prime/prime-tutorial.pdf + * http://www.isthe.com/chongo/tech/math/prime/prime-tutorial.pdf * * The routines in calc were designed to be portable, and to work on * numbers of 'sane' size. The Amdahl 6 team used a 'ultra-high speed @@ -95,23 +95,23 @@ * was based on the PFA Fast Fourier Transform and on Winograd's radix FFTs. * * NOTE: While the PFA Fast Fourier Transform and Winograd's radix FFTs - * might have been optimal for the Amdahl 6 team at the time, - * they might not be optimal for your CPU architecture. See - * the above mentioned tutorial for information on better - * methods of performing multiplications and squares of very - * large numbers. + * might have been optimal for the Amdahl 6 team at the time, + * they might not be optimal for your CPU architecture. See + * the above mentioned tutorial for information on better + * methods of performing multiplications and squares of very + * large numbers. * * Having a fast computer, and a good multi-precision package are * critical, but one also needs to know where to look in order to have * a good chance at a record. Knowing what to test is beyond the scope * of this routine. However the following observations are noted: * - * test numbers of the form h*2^n-1 - * fix a value of n and vary the value h - * n mod 2^x == 0 for some value of x, say > 7 or more - * h*2^n-1 is not divisible by any small prime < 2^40 - * 0 < h < 2^39 - * h*2^n+1 is not divisible by any small prime < 2^40 + * test numbers of the form h*2^n-1 + * fix a value of n and vary the value h + * n mod 2^x == 0 for some value of x, say > 7 or more + * h*2^n-1 is not divisible by any small prime < 2^40 + * 0 < h < 2^39 + * h*2^n+1 is not divisible by any small prime < 2^40 * * The Mersenne test for '2^n-1' is the fastest known primality test * for a given large numbers. However, it is faster to search for @@ -126,7 +126,7 @@ * 'h', the time to test each number remains relatively constant. * * It is clearly a win to eliminate potential test candidates by - * rejecting numbers that that are divisible by 'small' primes. We + * rejecting numbers that that are divisible by 'small' primes. We * (the "Amdahl 6") rejected all numbers that were divisible by primes * less than '2^40'. We stopped looking for small factors at '2^40' * when the rate of candidates being eliminated was slowed down to @@ -138,11 +138,11 @@ * if 'h*(2^n mod q) mod q' == 1. One can compute '2^n mod q' by making * use of the following: * - * if - * y = 2^x mod q - * then - * 2^(2x) mod q == y^2 mod q 0 bit - * 2^(2x+1) mod q == 2*y^2 mod q 1 bit + * if + * y = 2^x mod q + * then + * 2^(2x) mod q == y^2 mod q 0 bit + * 2^(2x+1) mod q == 2*y^2 mod q 1 bit * * The choice of which expression depends on the binary pattern of 'n'. * Since '1' bits require an extra step (multiply by 2), one should @@ -160,13 +160,13 @@ * 'h*2^n+1' is divisible by a small primes. * * NOTE: Today, for world record sized h*2^n-1 primes, one might - * search for factors < 2^46 or more. By excluding h*2^n-1 - * with prime factors < 2^46, where h*2^n-1 is a bit larger - * than the largest known prime, one may exclude about 96.5% - * of candidates that have "small" prime factors. + * search for factors < 2^46 or more. By excluding h*2^n-1 + * with prime factors < 2^46, where h*2^n-1 is a bit larger + * than the largest known prime, one may exclude about 96.5% + * of candidates that have "small" prime factors. */ -pprod256 = 0; /* product of "primes up to 256" / "primes up to 46" */ +pprod256 = 0; /* product of "primes up to 256" / "primes up to 46" */ /* * lucas - lucas primality test on h*2^n-1 @@ -174,64 +174,64 @@ pprod256 = 0; /* product of "primes up to 256" / "primes up to 46" */ * ABOUT THE TEST: * * This routine will perform a primality test on h*2^n-1 based on - * the mathematics of Lucas, Lehmer and Riesel. One should read + * the mathematics of Lucas, Lehmer and Riesel. One should read * the following article: * * Ref1: - * "Lucasian Criteria for the Primality of N=h*2^n-1", by Hans Riesel, - * Mathematics of Computation, Vol 23 #108, pp. 869-875, Oct 1969 + * "Lucasian Criteria for the Primality of N=h*2^n-1", by Hans Riesel, + * Mathematics of Computation, Vol 23 #108, pp. 869-875, Oct 1969 * - * http://www.ams.org/journals/mcom/1969-23-108/S0025-5718-1969-0262163-1/ - * S0025-5718-1969-0262163-1.pdf + * http://www.ams.org/journals/mcom/1969-23-108/S0025-5718-1969-0262163-1/ + * S0025-5718-1969-0262163-1.pdf * - * NOTE: Join the above two lines for the complete URL of the paper. + * NOTE: Join the above two lines for the complete URL of the paper. * * The following book is also useful: * * Ref2: - * "Prime numbers and Computer Methods for Factorization", by Hans Riesel, - * Birkhauser, 1985, pp 131-134, 278-285, 438-444 + * "Prime numbers and Computer Methods for Factorization", by Hans Riesel, + * Birkhauser, 1985, pp 131-134, 278-285, 438-444 * * A few useful Legendre identities may be found in: * * Ref3: - * "Introduction to Analytic Number Theory", by Tom A. Apostol, - * Springer-Verlag, 1984, p 188. + * "Introduction to Analytic Number Theory", by Tom A. Apostol, + * Springer-Verlag, 1984, p 188. * * An excellent 5-page paper by Oystein J. Rodseth (we apologize that the * ASCII character set does not allow us to spell his name with the * umlaut marks on the O's): * * NOTE: The original Amdahl 6 method predates the publication of Ref4. - * The gen_v1() function used by lucas() uses the Ref4 method. - * See the 'Amdahl 6 legacy code' section below for the original - * method of generating v(1). + * The gen_v1() function used by lucas() uses the Ref4 method. + * See the 'Amdahl 6 legacy code' section below for the original + * method of generating v(1). * * Ref4: * - * "A note on primality tests for N = h*2^n-1", by Oystein J. Rodseth, - * Department of Mathematics, University of Bergen, BIT Numerical - * Mathematics. 34 (3): pp 451-454. + * "A note on primality tests for N = h*2^n-1", by Oystein J. Rodseth, + * Department of Mathematics, University of Bergen, BIT Numerical + * Mathematics. 34 (3): pp 451-454. * - * http://folk.uib.no/nmaoy/papers/luc.pdf + * http://folk.uib.no/nmaoy/papers/luc.pdf * - * This test is performed as follows: (see Ref1, Theorem 5) + * This test is performed as follows: (see Ref1, Theorem 5) * - * a) generate u(2) (see the function gen_u2() below) - * (NOTE: some call this u(0)) + * a) generate u(2) (see the function gen_u2() below) + * (NOTE: some call this u(0)) * - * b) generate u(n) according to the rule: + * b) generate u(n) according to the rule: * - * u(i+1) = u(i)^2-2 mod h*2^n-1 + * u(i+1) = u(i)^2-2 mod h*2^n-1 * - * c) h*2^n-1 is prime if and only if u(n) == 0 Q.E.D. :-) + * c) h*2^n-1 is prime if and only if u(n) == 0 Q.E.D. :-) * * Now the following conditions must be true for the test to work: * - * n >= 2 - * h >= 1 - * h < 2^n - * h mod 2 == 1 + * n >= 2 + * h >= 1 + * h < 2^n + * h mod 2 == 1 * * A few miscellaneous notes: * @@ -244,228 +244,228 @@ pprod256 = 0; /* product of "primes up to 256" / "primes up to 46" */ * as 2^39). * * The condition 'h mod 2 == 1' is not a problem. Say one is testing - * 'j*2^m-1', where j is even. If we note that: + * 'j*2^m-1', where j is even. If we note that: * - * j mod 2^x == 0 for x>0 implies j*2^m-1 == ((j/2^x)*2^(m+x))-1, + * j mod 2^x == 0 for x>0 implies j*2^m-1 == ((j/2^x)*2^(m+x))-1, * * then we can let h=j/2^x and n=m+x and test 'h*2^n-1' which is the value. * We need only consider odd values of h because we can rewrite our numbers * do make this so. * * input: - * h h as in h*2^n-1 (must be >= 1) - * n n as in h*2^n-1 (must be >= 1) + * h h as in h*2^n-1 (must be >= 1) + * n n as in h*2^n-1 (must be >= 1) * * returns: - * 1 => h*2^n-1 is prime - * 0 => h*2^n-1 is not prime + * 1 => h*2^n-1 is prime + * 0 => h*2^n-1 is not prime * -1 => a test could not be formed, or h >= 2^n, h <= 0, n <= 0 */ define lucas(h, n) { - local testval; /* h*2^n-1 */ - local shiftdown; /* the power of 2 that divides h */ - local u; /* the u(i) sequence value */ - local v1; /* the v(1) generator of u(2) */ - local i; /* u sequence cycle number */ - local oldh; /* pre-reduced h */ - local oldn; /* pre-reduced n */ - local bits; /* highbit of h*2^n-1 */ + local testval; /* h*2^n-1 */ + local shiftdown; /* the power of 2 that divides h */ + local u; /* the u(i) sequence value */ + local v1; /* the v(1) generator of u(2) */ + local i; /* u sequence cycle number */ + local oldh; /* pre-reduced h */ + local oldn; /* pre-reduced n */ + local bits; /* highbit of h*2^n-1 */ - /* - * check arg types - */ - if (!isint(h)) { - quit "FATAL: bad args: h must be an integer"; - } - if (h < 1) { - quit "FATAL: bad args: h must be an integer >= 1"; - } - if (!isint(n)) { - quit "FATAL: bad args: n must be an integer"; - } - if (n < 1) { - quit "FATAL: bad args: n must be an integer >= 1"; - } + /* + * check arg types + */ + if (!isint(h)) { + quit "FATAL: bad args: h must be an integer"; + } + if (h < 1) { + quit "FATAL: bad args: h must be an integer >= 1"; + } + if (!isint(n)) { + quit "FATAL: bad args: n must be an integer"; + } + if (n < 1) { + quit "FATAL: bad args: n must be an integer >= 1"; + } - /* - * reduce h if even - * - * we will force h to be odd by moving powers of two over to 2^n - */ - oldh = h; - oldn = n; - shiftdown = fcnt(h,2); /* h % 2^shiftdown == 0, max shiftdown */ - if (shiftdown > 0) { - h >>= shiftdown; - n += shiftdown; - } + /* + * reduce h if even + * + * we will force h to be odd by moving powers of two over to 2^n + */ + oldh = h; + oldn = n; + shiftdown = fcnt(h,2); /* h % 2^shiftdown == 0, max shiftdown */ + if (shiftdown > 0) { + h >>= shiftdown; + n += shiftdown; + } - /* - * enforce the 0 < h < 2^n rule - */ - if (h <= 0 || n <= 0) { - print "ERROR: reduced args violate the rule: 0 < h < 2^n"; - print " ERROR: h=":oldh, "n=":oldn, "reduced h=":h, "n=":n; - ldebug("lucas", "unknown: h <= 0 || n <= 0"); - return -1; - } - if (highbit(h) >= n) { - print "ERROR: reduced args violate the rule: h < 2^n"; - print " ERROR: h=":oldh, "n=":oldn, "reduced h=":h, "n=":n; - ldebug("lucas", "unknown: highbit(h) >= n"); - return -1; - } + /* + * enforce the 0 < h < 2^n rule + */ + if (h <= 0 || n <= 0) { + print "ERROR: reduced args violate the rule: 0 < h < 2^n"; + print " ERROR: h=":oldh, "n=":oldn, "reduced h=":h, "n=":n; + ldebug("lucas", "unknown: h <= 0 || n <= 0"); + return -1; + } + if (highbit(h) >= n) { + print "ERROR: reduced args violate the rule: h < 2^n"; + print " ERROR: h=":oldh, "n=":oldn, "reduced h=":h, "n=":n; + ldebug("lucas", "unknown: highbit(h) >= n"); + return -1; + } - /* - * catch the degenerate case of h*2^n-1 == 1 - */ - if (h == 1 && n == 1) { - ldebug("lucas", "not prime: h == 1 && n == 1"); - return 0; /* 1*2^1-1 == 1 is not prime */ - } + /* + * catch the degenerate case of h*2^n-1 == 1 + */ + if (h == 1 && n == 1) { + ldebug("lucas", "not prime: h == 1 && n == 1"); + return 0; /* 1*2^1-1 == 1 is not prime */ + } - /* - * catch the degenerate case of n==2 - * - * n==2 and 0 0 h==1 or h==3 - */ - if (h == 1 && n == 2) { - ldebug("lucas", "prime: h == 1 && n == 2"); - return 1; /* 1*2^2-1 == 3 is prime */ - } - if (h == 3 && n == 2) { - ldebug("lucas", "prime: h == 3 && n == 2"); - return 1; /* 3*2^2-1 == 11 is prime */ - } + /* + * catch the degenerate case of n==2 + * + * n==2 and 0 0 h==1 or h==3 + */ + if (h == 1 && n == 2) { + ldebug("lucas", "prime: h == 1 && n == 2"); + return 1; /* 1*2^2-1 == 3 is prime */ + } + if (h == 3 && n == 2) { + ldebug("lucas", "prime: h == 3 && n == 2"); + return 1; /* 3*2^2-1 == 11 is prime */ + } - /* - * catch small primes < 257 - * - * We check for only a few primes because the other primes < 257 - * violate the checks above. - */ - if (h == 1) { - if (n == 3 || n == 5 || n == 7) { - ldebug("lucas", "prime: 3, 7, 31, 127 are prime"); - return 1; /* 3, 7, 31, 127 are prime */ - } - } - if (h == 3) { - if (n == 2 || n == 3 || n == 4 || n == 6) { - ldebug("lucas", "prime: 11, 23, 47, 191 are prime"); - return 1; /* 11, 23, 47, 191 are prime */ - } - } - if (h == 5 && n == 4) { - ldebug("lucas", "prime: 79 is prime"); - return 1; /* 79 is prime */ - } - if (h == 7 && n == 5) { - ldebug("lucas", "prime: 223 is prime"); - return 1; /* 223 is prime */ - } - if (h == 15 && n == 4) { - ldebug("lucas", "prime: 239 is prime"); - return 1; /* 239 is prime */ - } + /* + * catch small primes < 257 + * + * We check for only a few primes because the other primes < 257 + * violate the checks above. + */ + if (h == 1) { + if (n == 3 || n == 5 || n == 7) { + ldebug("lucas", "prime: 3, 7, 31, 127 are prime"); + return 1; /* 3, 7, 31, 127 are prime */ + } + } + if (h == 3) { + if (n == 2 || n == 3 || n == 4 || n == 6) { + ldebug("lucas", "prime: 11, 23, 47, 191 are prime"); + return 1; /* 11, 23, 47, 191 are prime */ + } + } + if (h == 5 && n == 4) { + ldebug("lucas", "prime: 79 is prime"); + return 1; /* 79 is prime */ + } + if (h == 7 && n == 5) { + ldebug("lucas", "prime: 223 is prime"); + return 1; /* 223 is prime */ + } + if (h == 15 && n == 4) { + ldebug("lucas", "prime: 239 is prime"); + return 1; /* 239 is prime */ + } - /* - * Verify that h*2^n-1 is not a multiple of 3 - * - * The case for h*2^n-1 == 3 is handled above. - */ - if (((h % 3 == 1) && (n % 2 == 0)) || ((h % 3 == 2) && (n % 2 == 1))) { - /* no need to test h*2^n-1, it is a multiple of 3 */ - ldebug("lucas","not-prime: != 3 and is a multiple of 3"); - return 0; - } + /* + * Verify that h*2^n-1 is not a multiple of 3 + * + * The case for h*2^n-1 == 3 is handled above. + */ + if (((h % 3 == 1) && (n % 2 == 0)) || ((h % 3 == 2) && (n % 2 == 1))) { + /* no need to test h*2^n-1, it is a multiple of 3 */ + ldebug("lucas","not-prime: != 3 and is a multiple of 3"); + return 0; + } - /* - * Avoid any numbers divisible by small primes - */ - /* - * check for 5 <= prime factors < 31 - * pfact(30)/6 = 1078282205 - */ - testval = h*2^n - 1; - if (gcd(testval, 1078282205) > 1) { - /* a small 5 <= prime < 31 divides h*2^n-1 */ - ldebug("lucas",\ - "not-prime: a small 5<=prime<31 divides h*2^n-1"); - return 0; - } - /* - * check for 31 <= prime factors < 53 - * pfact(52)/pfact(30) = 95041567 - */ - if (gcd(testval, 95041567) > 1) { - /* a small 31 <= prime < 53 divides h*2^n-1 */ - ldebug("lucas","not-prime: 31<=prime<53 divides h*2^n-1"); - return 0; - } - /* - * check for prime 53 <= factors < 257, if h*2^n-1 is large - * 2^276 > pfact(256)/pfact(52) > 2^275 - */ - bits = highbit(testval); - if (bits >= 275) { - if (pprod256 <= 0) { - pprod256 = pfact(256)/pfact(52); - } - if (gcd(testval, pprod256) > 1) { - /* a small 53 <= prime < 257 divides h*2^n-1 */ - ldebug("lucas",\ - "not-prime: 53<=prime<257 divides h*2^n-1"); - return 0; - } - } + /* + * Avoid any numbers divisible by small primes + */ + /* + * check for 5 <= prime factors < 31 + * pfact(30)/6 = 1078282205 + */ + testval = h*2^n - 1; + if (gcd(testval, 1078282205) > 1) { + /* a small 5 <= prime < 31 divides h*2^n-1 */ + ldebug("lucas",\ + "not-prime: a small 5<=prime<31 divides h*2^n-1"); + return 0; + } + /* + * check for 31 <= prime factors < 53 + * pfact(52)/pfact(30) = 95041567 + */ + if (gcd(testval, 95041567) > 1) { + /* a small 31 <= prime < 53 divides h*2^n-1 */ + ldebug("lucas","not-prime: 31<=prime<53 divides h*2^n-1"); + return 0; + } + /* + * check for prime 53 <= factors < 257, if h*2^n-1 is large + * 2^276 > pfact(256)/pfact(52) > 2^275 + */ + bits = highbit(testval); + if (bits >= 275) { + if (pprod256 <= 0) { + pprod256 = pfact(256)/pfact(52); + } + if (gcd(testval, pprod256) > 1) { + /* a small 53 <= prime < 257 divides h*2^n-1 */ + ldebug("lucas",\ + "not-prime: 53<=prime<257 divides h*2^n-1"); + return 0; + } + } - /* - * try to compute u(2) (NOTE: some call this u(0)) - * - * We will use gen_v1() to give us a v(1) using the values - * of 'h' and 'n'. We will then use gen_u2() to convert - * the v(1) into u(2). - * - * If gen_v1() returns a negative value, then we failed to - * generate a test for h*2^n-1. The legacy function, - * legacy_gen_v1() used by the Amdahl 6 could have returned - * -1. The new gen_v1() based on the method outlined in Ref4 - * will never return -1 if h*2^n-1 is not a multiple of 3. - * Because the "multiple of 3" case is handled above, the - * call below to gen_v1() will never return -1. - */ - v1 = gen_v1(h, n); - if (v1 < 0) { - /* failure to test number */ - print "unable to compute v(1) for", h : "*2^" : n : "-1"; - ldebug("lucas", "unknown: no v(1)"); - return -1; - } - u = gen_u2(h, n, v1); + /* + * try to compute u(2) (NOTE: some call this u(0)) + * + * We will use gen_v1() to give us a v(1) using the values + * of 'h' and 'n'. We will then use gen_u2() to convert + * the v(1) into u(2). + * + * If gen_v1() returns a negative value, then we failed to + * generate a test for h*2^n-1. The legacy function, + * legacy_gen_v1() used by the Amdahl 6 could have returned + * -1. The new gen_v1() based on the method outlined in Ref4 + * will never return -1 if h*2^n-1 is not a multiple of 3. + * Because the "multiple of 3" case is handled above, the + * call below to gen_v1() will never return -1. + */ + v1 = gen_v1(h, n); + if (v1 < 0) { + /* failure to test number */ + print "unable to compute v(1) for", h : "*2^" : n : "-1"; + ldebug("lucas", "unknown: no v(1)"); + return -1; + } + u = gen_u2(h, n, v1); - /* - * compute u(n) (NOTE: some call this u(n-2)) - */ - for (i=3; i <= n; ++i) { - /* u = (u^2 - 2) % testval; */ - u = hnrmod(u^2 - 2, h, n, -1); - } + /* + * compute u(n) (NOTE: some call this u(n-2)) + */ + for (i=3; i <= n; ++i) { + /* u = (u^2 - 2) % testval; */ + u = hnrmod(u^2 - 2, h, n, -1); + } - /* - * return 1 if prime, 0 is not prime - */ - if (u == 0) { - ldebug("lucas", "prime: end of test"); - return 1; - } else { - ldebug("lucas", "not-prime: end of test"); - return 0; - } + /* + * return 1 if prime, 0 is not prime + */ + if (u == 0) { + ldebug("lucas", "prime: end of test"); + return 1; + } else { + ldebug("lucas", "not-prime: end of test"); + return 0; + } } /* @@ -475,27 +475,27 @@ lucas(h, n) * Some, like the author of this code, prefer to start * with U(2). This is so one may say: * - * 2^p-1 is prime if u(p) = 0 mod 2^p-1 + * 2^p-1 is prime if u(p) = 0 mod 2^p-1 * or: - * h*2^p-1 is prime if u(p) = 0 mod h*2^p-1 + * h*2^p-1 is prime if u(p) = 0 mod h*2^p-1 * * According to Ref1, Theorem 5: * - * u(2) = alpha^h + alpha^(-h) (NOTE: Ref1 calls it u(0)) + * u(2) = alpha^h + alpha^(-h) (NOTE: Ref1 calls it u(0)) * * Now: * - * v(x) = alpha^x + alpha^(-x) (Ref1, bottom of page 872) + * v(x) = alpha^x + alpha^(-x) (Ref1, bottom of page 872) * * Therefore: * - * u(2) = v(h) (NOTE: Ref1 calls it u(0)) + * u(2) = v(h) (NOTE: Ref1 calls it u(0)) * - * We calculate v(h) as follows: (Ref1, top of page 873) + * We calculate v(h) as follows: (Ref1, top of page 873) * - * v(0) = alpha^0 + alpha^(-0) = 2 - * v(1) = alpha^1 + alpha^(-1) = gen_v1(h,n) - * v(n+2) = v(1)*v(n+1) - v(n) + * v(0) = alpha^0 + alpha^(-0) = 2 + * v(1) = alpha^1 + alpha^(-1) = gen_v1(h,n) + * v(n+2) = v(1)*v(n+1) - v(n) * * This function does not concern itself with the value of 'alpha'. * The gen_v1() function is used to compute v(1), and identity @@ -503,8 +503,8 @@ lucas(h, n) * * It can be shown that the following are true: * - * v(2*n) = v(n)^2 - 2 - * v(2*n+1) = v(n+1)*v(n) - v(1) + * v(2*n) = v(n)^2 - 2 + * v(2*n+1) = v(n+1)*v(n) - v(1) * * To prevent v(x) from growing too large, one may replace v(x) with * `v(x) mod h*2^n-1' at any time. @@ -512,125 +512,125 @@ lucas(h, n) * See the function gen_v1() for details on the value of v(1). * * input: - * h - h as in h*2^n-1 (must be >= 1) - * n - n as in h*2^n-1 (must be >= 1) - * v1 - gen_v1(h,n) (must be >= 3) (see function below) + * h - h as in h*2^n-1 (must be >= 1) + * n - n as in h*2^n-1 (must be >= 1) + * v1 - gen_v1(h,n) (must be >= 3) (see function below) * * returns: - * u(2) - initial value for Lucas test on h*2^n-1 - * -1 - failed to generate u(2) + * u(2) - initial value for Lucas test on h*2^n-1 + * -1 - failed to generate u(2) */ define gen_u2(h, n, v1) { - local shiftdown; /* the power of 2 that divides h */ - local r; /* low value: v(n) */ - local s; /* high value: v(n+1) */ - local hbits; /* highest bit set in h */ - local oldh; /* pre-reduced h */ - local oldn; /* pre-reduced n */ - local i; + local shiftdown; /* the power of 2 that divides h */ + local r; /* low value: v(n) */ + local s; /* high value: v(n+1) */ + local hbits; /* highest bit set in h */ + local oldh; /* pre-reduced h */ + local oldn; /* pre-reduced n */ + local i; - /* - * check arg types - */ - if (!isint(h)) { - quit "bad args: h must be an integer"; - } - if (h < 0) { - quit "bad args: h must be an integer >= 1"; - } - if (!isint(n)) { - quit "bad args: n must be an integer"; - } - if (n < 1) { - quit "bad args: n must be an integer >= 1"; - } - if (!isint(v1)) { - quit "bad args: v1 must be an integer"; - } - if (v1 < 3) { - quit "bogus arg: v1 must be an integer >= 3"; - } + /* + * check arg types + */ + if (!isint(h)) { + quit "bad args: h must be an integer"; + } + if (h < 0) { + quit "bad args: h must be an integer >= 1"; + } + if (!isint(n)) { + quit "bad args: n must be an integer"; + } + if (n < 1) { + quit "bad args: n must be an integer >= 1"; + } + if (!isint(v1)) { + quit "bad args: v1 must be an integer"; + } + if (v1 < 3) { + quit "bogus arg: v1 must be an integer >= 3"; + } - /* - * reduce h if even - * - * we will force h to be odd by moving powers of two over to 2^n - */ - oldh = h; - oldn = n; - shiftdown = fcnt(h,2); /* h % 2^shiftdown == 0, max shiftdown */ - if (shiftdown > 0) { - h >>= shiftdown; - n += shiftdown; - } + /* + * reduce h if even + * + * we will force h to be odd by moving powers of two over to 2^n + */ + oldh = h; + oldn = n; + shiftdown = fcnt(h,2); /* h % 2^shiftdown == 0, max shiftdown */ + if (shiftdown > 0) { + h >>= shiftdown; + n += shiftdown; + } - /* - * enforce the h > 0 and n >= 2 rules - */ - if (h <= 0 || n < 1) { - print " ERROR: h=":oldh, "n=":oldn, "reduced h=":h, "n=":n; - quit "reduced args violate the rule: 0 < h < 2^n"; - } - hbits = highbit(h); - if (hbits >= n) { - print " ERROR: h=":oldh, "n=":oldn, "reduced h=":h, "n=":n; - quit "reduced args violate the rule: 0 < h < 2^n"; - } + /* + * enforce the h > 0 and n >= 2 rules + */ + if (h <= 0 || n < 1) { + print " ERROR: h=":oldh, "n=":oldn, "reduced h=":h, "n=":n; + quit "reduced args violate the rule: 0 < h < 2^n"; + } + hbits = highbit(h); + if (hbits >= n) { + print " ERROR: h=":oldh, "n=":oldn, "reduced h=":h, "n=":n; + quit "reduced args violate the rule: 0 < h < 2^n"; + } - /* - * build up u2 based on the reversed bits of h - */ - /* setup for bit loop */ - r = v1; - s = (r^2 - 2); + /* + * build up u2 based on the reversed bits of h + */ + /* setup for bit loop */ + r = v1; + s = (r^2 - 2); - /* - * deal with small h as a special case - * - * The h value is odd > 0, and it needs to be - * at least 2 bits long for the loop below to work. - */ - if (h == 1) { - ldebug("gen_u2", "quick h == 1 case"); - /* return r%(h*2^n-1); */ - return hnrmod(r, h, n, -1); - } + /* + * deal with small h as a special case + * + * The h value is odd > 0, and it needs to be + * at least 2 bits long for the loop below to work. + */ + if (h == 1) { + ldebug("gen_u2", "quick h == 1 case"); + /* return r%(h*2^n-1); */ + return hnrmod(r, h, n, -1); + } - /* cycle from second highest bit to second lowest bit of h */ - for (i=hbits-1; i > 0; --i) { + /* cycle from second highest bit to second lowest bit of h */ + for (i=hbits-1; i > 0; --i) { - /* bit(i) is 1 */ - if (bit(h,i)) { + /* bit(i) is 1 */ + if (bit(h,i)) { - /* compute v(2n+1) = v(r+1)*v(r)-v1 */ - /* r = (r*s - v1) % (h*2^n-1); */ - r = hnrmod((r*s - v1), h, n, -1); + /* compute v(2n+1) = v(r+1)*v(r)-v1 */ + /* r = (r*s - v1) % (h*2^n-1); */ + r = hnrmod((r*s - v1), h, n, -1); - /* compute v(2n+2) = v(r+1)^2-2 */ - /* s = (s^2 - 2) % (h*2^n-1); */ - s = hnrmod((s^2 - 2), h, n, -1); + /* compute v(2n+2) = v(r+1)^2-2 */ + /* s = (s^2 - 2) % (h*2^n-1); */ + s = hnrmod((s^2 - 2), h, n, -1); - /* bit(i) is 0 */ - } else { + /* bit(i) is 0 */ + } else { - /* compute v(2n+1) = v(r+1)*v(r)-v1 */ - /* s = (r*s - v1) % (h*2^n-1); */ - s = hnrmod((r*s - v1), h, n, -1); + /* compute v(2n+1) = v(r+1)*v(r)-v1 */ + /* s = (r*s - v1) % (h*2^n-1); */ + s = hnrmod((r*s - v1), h, n, -1); - /* compute v(2n) = v(r)^-2 */ - /* r = (r^2 - 2) % (h*2^n-1); */ - r = hnrmod((r^2 - 2), h, n, -1); - } - } + /* compute v(2n) = v(r)^-2 */ + /* r = (r^2 - 2) % (h*2^n-1); */ + r = hnrmod((r^2 - 2), h, n, -1); + } + } - /* we know that h is odd, so the final bit(0) is 1 */ - /* r = (r*s - v1) % (h*2^n-1); */ - r = hnrmod((r*s - v1), h, n, -1); + /* we know that h is odd, so the final bit(0) is 1 */ + /* r = (r*s - v1) % (h*2^n-1); */ + r = hnrmod((r*s - v1), h, n, -1); - /* compute the final u2 return value */ - return r; + /* compute the final u2 return value */ + return r; } /* @@ -640,9 +640,9 @@ gen_u2(h, n, v1) * Some, like the author of this code, prefer to start * with u(2). This is so one may say: * - * 2^p-1 is prime if u(p) = 0 mod 2^p-1 + * 2^p-1 is prime if u(p) = 0 mod 2^p-1 * or: - * h*2^n-1 is prime if U(n) = 0 mod h*2^n-1 + * h*2^n-1 is prime if U(n) = 0 mod h*2^n-1 * * For those using the old code with gen_u0(), we * simply call gen_u2() instead. @@ -650,18 +650,18 @@ gen_u2(h, n, v1) * See the function gen_u2() for details. * * input: - * h - h as in h*2^n-1 (must be >= 1) - * n - n as in h*2^n-1 (must be >= 1) - * v1 - gen_v1(h,n) (see function below) + * h - h as in h*2^n-1 (must be >= 1) + * n - n as in h*2^n-1 (must be >= 1) + * v1 - gen_v1(h,n) (see function below) * * returns: - * u(2) - initial value for Lucas test on h*2^n-1 - * -1 - failed to generate u(2) + * u(2) - initial value for Lucas test on h*2^n-1 + * -1 - failed to generate u(2) */ define gen_u0(h, n, v1) { - return gen_u2(h, n, v1); + return gen_u2(h, n, v1); } /* @@ -669,87 +669,87 @@ gen_u0(h, n, v1) * * For a given h*2^n-1, v(1) == x if: * - * jacobi(x-2, h*2^n-1) == 1 (Ref4, condition 1) part 1 - * jacobi(x+2, h*2^n-1) == -1 (Ref4, condition 1) part 2 + * jacobi(x-2, h*2^n-1) == 1 (Ref4, condition 1) part 1 + * jacobi(x+2, h*2^n-1) == -1 (Ref4, condition 1) part 2 * * Now when x-2 <= 0: * - * jacobi(x-2, h*2^n-1) == 0 + * jacobi(x-2, h*2^n-1) == 0 * * because: * - * jacobi(x,y) == 0 if x <= 0 + * jacobi(x,y) == 0 if x <= 0 * * So for (Ref4, condition 1) part 1 to be true: * - * x-2 > 0 + * x-2 > 0 * * And therefore: * - * x > 2 + * x > 2 * * input: - * x potential v(1) value - * h h as in h*2^n-1 (h must be odd >= 1) - * n n as in h*2^n-1 (must be >= 1) + * x potential v(1) value + * h h as in h*2^n-1 (h must be odd >= 1) + * n n as in h*2^n-1 (must be >= 1) * * returns: - * 1 if v(1) == x for h*2^n-1 - * 0 otherwise + * 1 if v(1) == x for h*2^n-1 + * 0 otherwise */ define rodseth_xhn(x, h, n) { - local testval; /* h*2^n-1 */ + local testval; /* h*2^n-1 */ - /* - * check arg types - */ - if (!isint(h)) { - quit "bad args: h must be an integer"; - } - if (iseven(h)) { - quit "bad args: h must be an odd integer"; - } - if (h < 1) { - quit "bad args: h must be an integer >= 1"; - } - if (!isint(n)) { - quit "bad args: n must be an integer"; - } - if (n < 1) { - quit "bad args: n must be an integer >= 1"; - } - if (!isint(x)) { - quit "bad args: x must be an integer"; - } + /* + * check arg types + */ + if (!isint(h)) { + quit "bad args: h must be an integer"; + } + if (iseven(h)) { + quit "bad args: h must be an odd integer"; + } + if (h < 1) { + quit "bad args: h must be an integer >= 1"; + } + if (!isint(n)) { + quit "bad args: n must be an integer"; + } + if (n < 1) { + quit "bad args: n must be an integer >= 1"; + } + if (!isint(x)) { + quit "bad args: x must be an integer"; + } - /* - * firewall - */ - if (x <= 2) { - return 0; - } + /* + * firewall + */ + if (x <= 2) { + return 0; + } - /* - * Check for jacobi(x-2, h*2^n-1) == 1 (Ref4, condition 1) part 1 - */ - testval = h*2^n-1; - if (jacobi(x-2, testval) != 1) { - return 0; - } + /* + * Check for jacobi(x-2, h*2^n-1) == 1 (Ref4, condition 1) part 1 + */ + testval = h*2^n-1; + if (jacobi(x-2, testval) != 1) { + return 0; + } - /* - * Check for jacobi(x+2, h*2^n-1) == -1 (Ref4, condition 1) part 2 - */ - if (jacobi(x+2, testval) != -1) { - return 0; - } + /* + * Check for jacobi(x+2, h*2^n-1) == -1 (Ref4, condition 1) part 2 + */ + if (jacobi(x+2, testval) != -1) { + return 0; + } - /* - * v(1) == x for this h*2^n-1 - */ - return 1; + /* + * v(1) == x for this h*2^n-1 + */ + return 1; } /* @@ -757,8 +757,8 @@ rodseth_xhn(x, h, n) * * When h mod 3 == 0, according to Ref4 we need to find the first value X where: * - * jacobi(X-2, h*2^n-1) == 1 (Ref4, condition 1) part 1 - * jacobi(X+2, h*2^n-1) == -1 (Ref4, condition 1) part 2 + * jacobi(X-2, h*2^n-1) == 1 (Ref4, condition 1) part 1 + * jacobi(X+2, h*2^n-1) == -1 (Ref4, condition 1) part 2 * * We can show that X > 2. See the comments in the rodseth_xhn(x,h,n) above. * @@ -835,47 +835,47 @@ rodseth_xhn(x, h, n) * 4331116 <= n <= 4332116, these are the smallest v(1) values that were found: * * smallest percentage - * v(1) used + * v(1) used * -------- --------- - * 3 40.0000 % - * 5 25.6833 % - * 9 11.6924 % - * 11 10.4528 % - * 15 4.8048 % - * 17 2.3458 % - * 21 1.3734 % - * 29 1.0527 % - * 20 0.8595 % - * 27 0.5758 % - * 35 0.4420 % - * 36 0.2433 % - * 39 0.1779 % - * 41 0.0885 % - * 45 0.0571 % - * 32 0.0337 % - * 51 0.0289 % - * 44 0.0205 % - * 49 0.0176 % - * 56 0.0137 % - * 59 0.0108 % - * 57 0.0053 % - * 65 0.0047 % - * 55 0.0045 % - * 69 0.0031 % - * 71 0.0024 % - * 66 0.0011 % - * 95 0.0008 % - * 81 0.0008 % - * 77 0.0006 % - * 72 0.0005 % - * 99 0.0004 % - * 80 0.0003 % - * 74 0.0003 % - * 84 0.0002 % - * 67 0.0002 % - * 87 0.0001 % - * 104 0.0001 % - * 129 0.0001 % + * 3 40.0000 % + * 5 25.6833 % + * 9 11.6924 % + * 11 10.4528 % + * 15 4.8048 % + * 17 2.3458 % + * 21 1.3734 % + * 29 1.0527 % + * 20 0.8595 % + * 27 0.5758 % + * 35 0.4420 % + * 36 0.2433 % + * 39 0.1779 % + * 41 0.0885 % + * 45 0.0571 % + * 32 0.0337 % + * 51 0.0289 % + * 44 0.0205 % + * 49 0.0176 % + * 56 0.0137 % + * 59 0.0108 % + * 57 0.0053 % + * 65 0.0047 % + * 55 0.0045 % + * 69 0.0031 % + * 71 0.0024 % + * 66 0.0011 % + * 95 0.0008 % + * 81 0.0008 % + * 77 0.0006 % + * 72 0.0005 % + * 99 0.0004 % + * 80 0.0003 % + * 74 0.0003 % + * 84 0.0002 % + * 67 0.0002 % + * 87 0.0001 % + * 104 0.0001 % + * 129 0.0001 % * * However, a case can be made for considering only odd values for v(1) * candidates. When h * 2^n-1 is prime and h is an odd multiple of 3, @@ -885,7 +885,7 @@ rodseth_xhn(x, h, n) * * See: * - * https://github.com/arcetri/verified-prime + * https://github.com/arcetri/verified-prime * * for that list of 146553 known primes of the form h*2^n-1. * @@ -897,51 +897,51 @@ rodseth_xhn(x, h, n) * smallest percentage * odd v(1) used * -------- --------- - * 3 40.0000 % - * 5 25.6833 % - * 9 11.6924 % - * 11 10.4528 % - * 15 4.8048 % - * 17 2.3458 % - * 21 1.6568 % - * 29 1.6174 % - * 35 0.4529 % - * 27 0.3546 % - * 39 0.3470 % - * 41 0.2159 % - * 45 0.1173 % - * 31 0.0661 % - * 51 0.0619 % - * 55 0.0419 % - * 59 0.0250 % - * 49 0.0170 % - * 69 0.0110 % - * 65 0.0098 % - * 71 0.0078 % - * 85 0.0048 % - * 81 0.0044 % - * 95 0.0038 % - * 99 0.0021 % - * 125 0.0009 % - * 57 0.0007 % - * 111 0.0005 % - * 77 0.0003 % - * 165 0.0003 % - * 155 0.0002 % - * 129 0.0002 % - * 101 0.0002 % - * 53 0.0001 % + * 3 40.0000 % + * 5 25.6833 % + * 9 11.6924 % + * 11 10.4528 % + * 15 4.8048 % + * 17 2.3458 % + * 21 1.6568 % + * 29 1.6174 % + * 35 0.4529 % + * 27 0.3546 % + * 39 0.3470 % + * 41 0.2159 % + * 45 0.1173 % + * 31 0.0661 % + * 51 0.0619 % + * 55 0.0419 % + * 59 0.0250 % + * 49 0.0170 % + * 69 0.0110 % + * 65 0.0098 % + * 71 0.0078 % + * 85 0.0048 % + * 81 0.0044 % + * 95 0.0038 % + * 99 0.0021 % + * 125 0.0009 % + * 57 0.0007 % + * 111 0.0005 % + * 77 0.0003 % + * 165 0.0003 % + * 155 0.0002 % + * 129 0.0002 % + * 101 0.0002 % + * 53 0.0001 % * * Moreover when evaluating odd candidates for v(1), one may cache Jacobi * symbol evaluations to reduce the number of Jacobi symbol evaluations to * a minimum. For example, if one tests 5 and finds that the 2nd case fails: * - * jacobi(5+2, h*2^n-1) != -1 + * jacobi(5+2, h*2^n-1) != -1 * * Then if one is later testing 9, the Jacobi symbol value for the first * 1st case: * - * jacobi(7-2, h*2^n-1) + * jacobi(7-2, h*2^n-1) * * is already known. * @@ -952,9 +952,9 @@ rodseth_xhn(x, h, n) * Given this information, when odd h is a multiple of 3 we try, in order, * these odd values of X: * - * 3, 5, 9, 11, 15, 17, 21, 29, 27, 35, 39, 41, 31, 45, 51, 55, 49, 59, - * 69, 65, 71, 57, 85, 81, 95, 99, 77, 53, 67, 125, 111, 105, 87, 129, - * 101, 83, 165, 155, 149, 141, 121, 109 + * 3, 5, 9, 11, 15, 17, 21, 29, 27, 35, 39, 41, 31, 45, 51, 55, 49, 59, + * 69, 65, 71, 57, 85, 81, 95, 99, 77, 53, 67, 125, 111, 105, 87, 129, + * 101, 83, 165, 155, 149, 141, 121, 109 * * And stop on the first value of X where: * @@ -977,128 +977,128 @@ x_tbl = { 69, 65, 71, 57, 85, 81, 95, 99, 77, 53, 67, 125, 111, 105, 87, 129, 101, 83, 165, 155, 149, 141, 121, 109 }; -next_x = 167; /* must be 2 more than the largest value in x_tbl[] */ +next_x = 167; /* must be 2 more than the largest value in x_tbl[] */ /* * gen_v1 - compute the v(1) for a given h*2^n-1 if we can * * This function assumes: * - * n > 2 (n==2 has already been eliminated) - * h mod 2 == 1 - * h < 2^n - * h*2^n-1 mod 3 != 0 (h*2^n-1 has no small factors, such as 3) + * n > 2 (n==2 has already been eliminated) + * h mod 2 == 1 + * h < 2^n + * h*2^n-1 mod 3 != 0 (h*2^n-1 has no small factors, such as 3) * * The generation of v(1) depends on the value of h. There are two cases * to consider, h mod 3 != 0, and h mod 3 == 0. * *** * - * Case 1: (h mod 3 != 0) + * Case 1: (h mod 3 != 0) * * This case is easy. * - * In Ref1, page 869, one finds that if: (or see Ref2, page 131-132) + * In Ref1, page 869, one finds that if: (or see Ref2, page 131-132) * - * h mod 6 == +/-1 - * h*2^n-1 mod 3 != 0 + * h mod 6 == +/-1 + * h*2^n-1 mod 3 != 0 * * which translates, gives the functions assumptions, into the condition: * - * h mod 3 != 0 + * h mod 3 != 0 * * If this case condition is true, then: * - * u(2) = (2+sqrt(3))^h + (2-sqrt(3))^h (see Ref1, page 869) - * = (2+sqrt(3))^h + (2+sqrt(3))^(-h) (NOTE: some call this u(2)) + * u(2) = (2+sqrt(3))^h + (2-sqrt(3))^h (see Ref1, page 869) + * = (2+sqrt(3))^h + (2+sqrt(3))^(-h) (NOTE: some call this u(2)) * * and since Ref1, Theorem 5 states: * - * u(2) = alpha^h + alpha^(-h) (NOTE: some call this u(2)) - * r = abs(2^2 - 1^2*3) = 1 + * u(2) = alpha^h + alpha^(-h) (NOTE: some call this u(2)) + * r = abs(2^2 - 1^2*3) = 1 * - * where these values work for Case 1: (h mod 3 != 0) + * where these values work for Case 1: (h mod 3 != 0) * - * a = 1 - * b = 2 - * D = 1 + * a = 1 + * b = 2 + * D = 1 * * Now at the bottom of Ref1, page 872 states: * - * v(x) = alpha^x + alpha^(-x) + * v(x) = alpha^x + alpha^(-x) * * If we let: * - * alpha = (2+sqrt(3)) + * alpha = (2+sqrt(3)) * * then * - * u(2) = v(h) (NOTE: some call this u(2)) + * u(2) = v(h) (NOTE: some call this u(2)) * * so we can always return * - * v(1) = alpha^1 + alpha^(-1) - * = (2+sqrt(3)) + (2-sqrt(3)) - * = 4 + * v(1) = alpha^1 + alpha^(-1) + * = (2+sqrt(3)) + (2-sqrt(3)) + * = 4 * * In 40% of the cases when h is not a multiple of 3, 3 is a valid value * for v(1). We can test if 3 is a valid value for v(1) in this case: * - * if jacobi(1, h*2^n-1) == 1 and jacobi(5, h*2^n-1) == -1, then - * v(1) = 3 - * else - * v(1) = 4 + * if jacobi(1, h*2^n-1) == 1 and jacobi(5, h*2^n-1) == -1, then + * v(1) = 3 + * else + * v(1) = 4 * * NOTE: The above "if then else" works only of h is not a multiple of 3. * *** * - * Case 2: (h mod 3 == 0) + * Case 2: (h mod 3 == 0) * * For the case where h is a multiple of 3, we turn to Ref4. * * The central theorem on page 3 of that paper states that * we may set v(1) to the first value X that satisfies: * - * jacobi(X-2, h*2^n-1) == 1 (Ref4, condition 1) - * jacobi(X+2, h*2^n-1) == -1 (Ref4, condition 1) + * jacobi(X-2, h*2^n-1) == 1 (Ref4, condition 1) + * jacobi(X+2, h*2^n-1) == -1 (Ref4, condition 1) * - * NOTE: Ref4 uses P, which we shall refer to as X. - * Ref4 uses N, which we shall refer to as h*2^n-1. + * NOTE: Ref4 uses P, which we shall refer to as X. + * Ref4 uses N, which we shall refer to as h*2^n-1. * - * NOTE: Ref4 uses the term Legendre-Jacobi symbol, which - * we shall refer to as the Jacobi symbol. + * NOTE: Ref4 uses the term Legendre-Jacobi symbol, which + * we shall refer to as the Jacobi symbol. * * Before we address the two conditions, we need some background information - * on two symbols, Legendre and Jacobi. In Ref 2, pp 278, 284-285, we find + * on two symbols, Legendre and Jacobi. In Ref 2, pp 278, 284-285, we find * the following definitions of jacobi(a,b) and L(a,p): * * The Legendre symbol L(a,p) takes the value: * - * L(a,p) == 1 => a is a quadratic residue of p - * L(a,p) == -1 => a is NOT a quadratic residue of p + * L(a,p) == 1 => a is a quadratic residue of p + * L(a,p) == -1 => a is NOT a quadratic residue of p * * when: * - * p is prime - * p mod 2 == 1 - * gcd(a,p) == 1 + * p is prime + * p mod 2 == 1 + * gcd(a,p) == 1 * * The value a is a quadratic residue of b if there exists some integer z * such that: * - * z^2 mod b == a + * z^2 mod b == a * * The Jacobi symbol jacobi(a,b) takes the value: * - * jacobi(a,b) == 1 => b is not prime, - * or a is a quadratic residue of b - * jacobi(a,b) == -1 => a is NOT a quadratic residue of b + * jacobi(a,b) == 1 => b is not prime, + * or a is a quadratic residue of b + * jacobi(a,b) == -1 => a is NOT a quadratic residue of b * * when * - * b mod 2 == 1 - * gcd(a,b) == 1 + * b mod 2 == 1 + * gcd(a,b) == 1 * * It is worth noting for the Legendre symbol, in order for L(X+/-2, * h*2^n-1) to be defined, we must ensure that neither X-2 nor X+2 are @@ -1111,12 +1111,12 @@ next_x = 167; /* must be 2 more than the largest value in x_tbl[] */ * * Returning to the testing of conditions in Ref4, condition 1: * - * jacobi(X-2, h*2^n-1) == 1 - * jacobi(X+2, h*2^n-1) == -1 + * jacobi(X-2, h*2^n-1) == 1 + * jacobi(X+2, h*2^n-1) == -1 * * When such an X is found, we set: * - * v(1) = X + * v(1) = X * *** * @@ -1126,191 +1126,191 @@ next_x = 167; /* must be 2 more than the largest value in x_tbl[] */ * * we return: * - * v(1) == 4 + * v(1) == 4 * * h mod 3 == 0 * * we return: * - * v(1) = X + * v(1) = X * * where X > 2 in a integer such that: * - * jacobi(X-2, h*2^n-1) == 1 - * jacobi(X+2, h*2^n-1) == -1 + * jacobi(X-2, h*2^n-1) == 1 + * jacobi(X+2, h*2^n-1) == -1 * *** * * input: - * h h as in h*2^n-1 (h must be odd >= 1) - * n n as in h*2^n-1 (must be >= 1) + * h h as in h*2^n-1 (h must be odd >= 1) + * n n as in h*2^n-1 (must be >= 1) * * output: - * returns v(1), or - * -1 when h*2^n-1 is a multiple of 3 + * returns v(1), or + * -1 when h*2^n-1 is a multiple of 3 */ define gen_v1(h, n) { - local x; /* potential v(1) to test */ - local i; /* x_tbl index */ - local v1m2; /* X-2 1st case */ - local v1p2; /* X+2 2nd case */ - local testval; /* h*2^n-1 - value we are testing if prime */ - local mat cached_v1[next_x]; /* cached Jacobi symbol values or 0 */ + local x; /* potential v(1) to test */ + local i; /* x_tbl index */ + local v1m2; /* X-2 1st case */ + local v1p2; /* X+2 2nd case */ + local testval; /* h*2^n-1 - value we are testing if prime */ + local mat cached_v1[next_x]; /* cached Jacobi symbol values or 0 */ - /* - * check arg types - */ - if (!isint(h)) { - quit "bad args: h must be an integer"; - } - if (iseven(h)) { - quit "bad args: h must be an odd integer"; - } - if (h < 1) { - quit "bad args: h must be an integer >= 1"; - } - if (!isint(n)) { - quit "bad args: n must be an integer"; - } - if (n < 1) { - quit "bad args: n must be an integer >= 1"; - } + /* + * check arg types + */ + if (!isint(h)) { + quit "bad args: h must be an integer"; + } + if (iseven(h)) { + quit "bad args: h must be an odd integer"; + } + if (h < 1) { + quit "bad args: h must be an integer >= 1"; + } + if (!isint(n)) { + quit "bad args: n must be an integer"; + } + if (n < 1) { + quit "bad args: n must be an integer >= 1"; + } - /* - * pretest: Verify that h*2^n-1 is not a multiple of 3 - */ - if (((h % 3 == 1) && (n % 2 == 0)) || ((h % 3 == 2) && (n % 2 == 1))) { - /* no need to test h*2^n-1, it is not prime */ - return -1; - } + /* + * pretest: Verify that h*2^n-1 is not a multiple of 3 + */ + if (((h % 3 == 1) && (n % 2 == 0)) || ((h % 3 == 2) && (n % 2 == 1))) { + /* no need to test h*2^n-1, it is not prime */ + return -1; + } - /* - * Common Mersenne number case: - * - * For Mersenne numbers: - * - * 2^n-1 - * - * we can use, 40% of the time, v(1) == 3. However nearly all code that - * implements the Lucas-Lehmer test uses v(1) == 4. Whenever for - * h != 0 mod 3, and particular the Mersenne number case of when h == 1: - * - * 1*2^n-1 - * - * v(1) == 4 always works. For this reason, we return 4 when h == 1. - */ - if (h == 1) { - /* v(1) == 4 always works for the Mersenne number case */ - return 4; - } + /* + * Common Mersenne number case: + * + * For Mersenne numbers: + * + * 2^n-1 + * + * we can use, 40% of the time, v(1) == 3. However nearly all code that + * implements the Lucas-Lehmer test uses v(1) == 4. Whenever for + * h != 0 mod 3, and particular the Mersenne number case of when h == 1: + * + * 1*2^n-1 + * + * v(1) == 4 always works. For this reason, we return 4 when h == 1. + */ + if (h == 1) { + /* v(1) == 4 always works for the Mersenne number case */ + return 4; + } - /* - * check for Case 1: (h mod 3 != 0) - */ - if (h % 3 != 0) { - if (rodseth_xhn(3, h, n) == 1) { - /* 40% of the time, 3 works when h mod 3 != 0 */ - return 3; - } else { - /* otherwise 4 always works when h mod 3 != 0 */ - return 4; - } - } + /* + * check for Case 1: (h mod 3 != 0) + */ + if (h % 3 != 0) { + if (rodseth_xhn(3, h, n) == 1) { + /* 40% of the time, 3 works when h mod 3 != 0 */ + return 3; + } else { + /* otherwise 4 always works when h mod 3 != 0 */ + return 4; + } + } - /* - * What follow is Case 2: (h mod 3 == 0) - */ + /* + * What follow is Case 2: (h mod 3 == 0) + */ - /* - * clear cache - */ - matfill(cached_v1, 0); + /* + * clear cache + */ + matfill(cached_v1, 0); - /* - * We will look for x that satisfies conditions in Ref4, condition 1: - * - * jacobi(X-2, h*2^n-1) == 1 part 1 - * jacobi(X+2, h*2^n-1) == -1 part 2 - * - * NOTE: If we wanted to be super optimal, we would cache - * jacobi(X+2, h*2^n-1) that that when we increment X - * to the next odd value, the now jacobi(X-2, h*2^n-1) - * does not need to be re-evaluated. - */ - testval = h*2^n-1; - for (i=0; i < x_tbl_len; ++i) { + /* + * We will look for x that satisfies conditions in Ref4, condition 1: + * + * jacobi(X-2, h*2^n-1) == 1 part 1 + * jacobi(X+2, h*2^n-1) == -1 part 2 + * + * NOTE: If we wanted to be super optimal, we would cache + * jacobi(X+2, h*2^n-1) that that when we increment X + * to the next odd value, the now jacobi(X-2, h*2^n-1) + * does not need to be re-evaluated. + */ + testval = h*2^n-1; + for (i=0; i < x_tbl_len; ++i) { - /* - * obtain the next test candidate - */ - x = x_tbl[i]; + /* + * obtain the next test candidate + */ + x = x_tbl[i]; - /* - * Check x for condition 1 part 1 - * - * jacobi(x-2, h*2^n-1) == 1 - */ - v1m2 = x-2; - if (cached_v1[v1m2] == 0) { - cached_v1[v1m2] = jacobi(v1m2, testval); - } - if (cached_v1[v1m2] != 1) { - continue; - } + /* + * Check x for condition 1 part 1 + * + * jacobi(x-2, h*2^n-1) == 1 + */ + v1m2 = x-2; + if (cached_v1[v1m2] == 0) { + cached_v1[v1m2] = jacobi(v1m2, testval); + } + if (cached_v1[v1m2] != 1) { + continue; + } - /* - * Check x for condition 1 part 2 - * - * jacobi(x+2, h*2^n-1) == -1 - */ - v1p2 = x+2; - if (cached_v1[v1p2] == 0) { - cached_v1[v1p2] = jacobi(v1p2, testval); - } - if (cached_v1[v1p2] != -1) { - continue; - } + /* + * Check x for condition 1 part 2 + * + * jacobi(x+2, h*2^n-1) == -1 + */ + v1p2 = x+2; + if (cached_v1[v1p2] == 0) { + cached_v1[v1p2] = jacobi(v1p2, testval); + } + if (cached_v1[v1p2] != -1) { + continue; + } - /* - * found a x that satisfies Ref4 condition 1 - */ - ldebug("gen_v1", "h= " + str(h) + " n= " + str(n) + - " v1= " + str(x) + " using tbl[ " + - str(i) + " ]"); - return x; - } + /* + * found a x that satisfies Ref4 condition 1 + */ + ldebug("gen_v1", "h= " + str(h) + " n= " + str(n) + + " v1= " + str(x) + " using tbl[ " + + str(i) + " ]"); + return x; + } - /* - * We are in that rare case (less than 1 in 1 000 000) where none of the - * common X values satisfy Ref4 condition 1. We start a linear search - * of odd values at next_x from here on. - */ - x = next_x; - while (rodseth_xhn(x, h, n) != 1) { - x += 2; - } - /* finally found a v(1) value */ - ldebug("gen_v1", "h= " + str(h) + " n= " + str(n) + - " v1= " + str(x) + " beyond tbl"); - return x; + /* + * We are in that rare case (less than 1 in 1 000 000) where none of the + * common X values satisfy Ref4 condition 1. We start a linear search + * of odd values at next_x from here on. + */ + x = next_x; + while (rodseth_xhn(x, h, n) != 1) { + x += 2; + } + /* finally found a v(1) value */ + ldebug("gen_v1", "h= " + str(h) + " n= " + str(n) + + " v1= " + str(x) + " beyond tbl"); + return x; } /* * ldebug - print a debug statement * * input: - * funct name of calling function - * str string to print + * funct name of calling function + * str string to print */ define ldebug(funct, str) { - if (config("resource_debug") & 8) { - print "DEBUG:", funct:":", str; - } - return; + if (config("resource_debug") & 8) { + print "DEBUG:", funct:":", str; + } + return; } /* @@ -1319,10 +1319,10 @@ ldebug(funct, str) ************************ * * NOTE: What follows is legacy code based on the method used by the - * Amdahl 6 group: + * Amdahl 6 group: * - * John Brown, Landon Curt Noll, Bodo Parady, Gene Smith, - * Joel Smith and Sergio Zarantonello + * John Brown, Landon Curt Noll, Bodo Parady, Gene Smith, + * Joel Smith and Sergio Zarantonello * * This method generated v(1) for nearly all values, except for a * few rare cases when h mod 3 == 0. The code is NOT used by lucas.cal @@ -1349,17 +1349,17 @@ ldebug(funct, str) * It should be noted that the D values all satisfy the selection values * as outlined in the legacy_gen_v1() function comments. That is: * - * D == P*(2^f)*(3^g) + * D == P*(2^f)*(3^g) * * where f == 0 and g == 0, P == D. So we simply need to check that * one of the following two cases are true: * - * P mod 4 == 1 and J(h*2^n-1 mod P, P) == -1 - * P mod 4 == -1 and J(h*2^n-1 mod P, P) == 1 + * P mod 4 == 1 and J(h*2^n-1 mod P, P) == -1 + * P mod 4 == -1 and J(h*2^n-1 mod P, P) == 1 * * In all cases, the value of r is: * - * r == Q*(2^j)*(3^k)*(z^2) + * r == Q*(2^j)*(3^k)*(z^2) * * where Q == 1. No further processing is needed to compute v(1) when r * is of this form. @@ -1367,80 +1367,80 @@ ldebug(funct, str) legacy_quickmax = 8; mat legacy_d_qval[legacy_quickmax]; mat legacy_v1_qval[legacy_quickmax]; -legacy_d_qval[0] = 5; legacy_v1_qval[0] = 3; /* a=1 b=1 r=4 */ -legacy_d_qval[1] = 7; legacy_v1_qval[1] = 5; /* a=3 b=1 r=12 D=21 */ -legacy_d_qval[2] = 13; legacy_v1_qval[2] = 11; /* a=3 b=1 r=4 */ -legacy_d_qval[3] = 11; legacy_v1_qval[3] = 20; /* a=3 b=1 r=2 */ -legacy_d_qval[4] = 29; legacy_v1_qval[4] = 27; /* a=5 b=1 r=4 */ -legacy_d_qval[5] = 53; legacy_v1_qval[5] = 51; /* a=53 b=1 r=4 */ -legacy_d_qval[6] = 17; legacy_v1_qval[6] = 66; /* a=17 b=1 r=1 */ -legacy_d_qval[7] = 19; legacy_v1_qval[7] = 74; /* a=38 b=1 r=2 */ +legacy_d_qval[0] = 5; legacy_v1_qval[0] = 3; /* a=1 b=1 r=4 */ +legacy_d_qval[1] = 7; legacy_v1_qval[1] = 5; /* a=3 b=1 r=12 D=21 */ +legacy_d_qval[2] = 13; legacy_v1_qval[2] = 11; /* a=3 b=1 r=4 */ +legacy_d_qval[3] = 11; legacy_v1_qval[3] = 20; /* a=3 b=1 r=2 */ +legacy_d_qval[4] = 29; legacy_v1_qval[4] = 27; /* a=5 b=1 r=4 */ +legacy_d_qval[5] = 53; legacy_v1_qval[5] = 51; /* a=53 b=1 r=4 */ +legacy_d_qval[6] = 17; legacy_v1_qval[6] = 66; /* a=17 b=1 r=1 */ +legacy_d_qval[7] = 19; legacy_v1_qval[7] = 74; /* a=38 b=1 r=2 */ /* * legacy_gen_v1 - compute the v(1) for a given h*2^n-1 if we can * * This function assumes: * - * n > 2 (n==2 has already been eliminated) - * h mod 2 == 1 - * h < 2^n - * h*2^n-1 mod 3 != 0 (h*2^n-1 has no small factors, such as 3) + * n > 2 (n==2 has already been eliminated) + * h mod 2 == 1 + * h < 2^n + * h*2^n-1 mod 3 != 0 (h*2^n-1 has no small factors, such as 3) * * The generation of v(1) depends on the value of h. There are two cases * to consider, h mod 3 != 0, and h mod 3 == 0. * *** * - * Case 1: (h mod 3 != 0) + * Case 1: (h mod 3 != 0) * * This case is easy and always finds v(1). * - * In Ref1, page 869, one finds that if: (or see Ref2, page 131-132) + * In Ref1, page 869, one finds that if: (or see Ref2, page 131-132) * - * h mod 6 == +/-1 - * h*2^n-1 mod 3 != 0 + * h mod 6 == +/-1 + * h*2^n-1 mod 3 != 0 * * which translates, gives the functions assumptions, into the condition: * - * h mod 3 != 0 + * h mod 3 != 0 * * If this case condition is true, then: * - * u(2) = (2+sqrt(3))^h + (2-sqrt(3))^h (see Ref1, page 869) - * = (2+sqrt(3))^h + (2+sqrt(3))^(-h) (some call this u(0)) + * u(2) = (2+sqrt(3))^h + (2-sqrt(3))^h (see Ref1, page 869) + * = (2+sqrt(3))^h + (2+sqrt(3))^(-h) (some call this u(0)) * * and since Ref1, Theorem 5 states: * - * u(2) = alpha^h + alpha^(-h) - * r = abs(2^2 - 1^2*3) = 1 + * u(2) = alpha^h + alpha^(-h) + * r = abs(2^2 - 1^2*3) = 1 * - * where these values work for Case 1: (h mod 3 != 0) + * where these values work for Case 1: (h mod 3 != 0) * - * a = 1 - * b = 2 - * D = 1 + * a = 1 + * b = 2 + * D = 1 * * Now at the bottom of Ref1, page 872 states: * - * v(x) = alpha^x + alpha^(-x) + * v(x) = alpha^x + alpha^(-x) * * If we let: * - * alpha = (2+sqrt(3)) + * alpha = (2+sqrt(3)) * * then * - * u(2) = v(h) + * u(2) = v(h) * * so we simply return * - * v(1) = alpha^1 + alpha^(-1) - * = (2+sqrt(3)) + (2-sqrt(3)) - * = 4 + * v(1) = alpha^1 + alpha^(-1) + * = (2+sqrt(3)) + (2-sqrt(3)) + * = 4 * *** * - * Case 2: (h mod 3 == 0) + * Case 2: (h mod 3 == 0) * * This case is not so easy and finds v(1) in most all cases. In this * version of this program, we will simply return -1 (failure) if we @@ -1449,8 +1449,8 @@ legacy_d_qval[7] = 19; legacy_v1_qval[7] = 74; /* a=38 b=1 r=2 */ * * Ref1, Theorem 5 contains the following definitions: * - * r = abs(a^2 - b^2*D) - * alpha = (a + b*sqrt(D))^2/r + * r = abs(a^2 - b^2*D) + * alpha = (a + b*sqrt(D))^2/r * * where D is 'square free', and 'alpha = epsilon^s' (for some s>0) are units * in the quadratic field K(sqrt(D)). @@ -1460,57 +1460,57 @@ legacy_d_qval[7] = 19; legacy_v1_qval[7] = 74; /* a=38 b=1 r=2 */ * * Now Ref1, Theorem 5 states that if: * - * L(D, h*2^n-1) = -1 [condition 1] - * L(r, h*2^n-1) * (a^2 - b^2*D)/r = -1 [condition 2] + * L(D, h*2^n-1) = -1 [condition 1] + * L(r, h*2^n-1) * (a^2 - b^2*D)/r = -1 [condition 2] * * where L(x,y) is the Legendre symbol (see below), then: * - * u(2) = alpha^h + alpha^(-h) + * u(2) = alpha^h + alpha^(-h) * * The bottom of Ref1, page 872 states: * - * v(x) = alpha^x + alpha^(-x) + * v(x) = alpha^x + alpha^(-x) * * thus since: * - * u(2) = v(h) + * u(2) = v(h) * * so we want to return: * - * v(1) = alpha^1 + alpha^(-1) + * v(1) = alpha^1 + alpha^(-1) * * Therefore we need to take a given (D,a,b), determine if the two conditions * are true, and return the related v(1). * * Before we address the two conditions, we need some background information - * on two symbols, Legendre and Jacobi. In Ref 2, pp 278, 284-285, we find + * on two symbols, Legendre and Jacobi. In Ref 2, pp 278, 284-285, we find * the following definitions of J(a,p) and L(a,n): * * The Legendre symbol L(a,p) takes the value: * - * L(a,p) == 1 => a is a quadratic residue of p - * L(a,p) == -1 => a is NOT a quadratic residue of p + * L(a,p) == 1 => a is a quadratic residue of p + * L(a,p) == -1 => a is NOT a quadratic residue of p * * when * - * p is prime - * p mod 2 == 1 - * gcd(a,p) == 1 + * p is prime + * p mod 2 == 1 + * gcd(a,p) == 1 * * The value x is a quadratic residue of y if there exists some integer z * such that: * - * z^2 mod y == x + * z^2 mod y == x * * The Jacobi symbol J(x,y) takes the value: * - * J(x,y) == 1 => y is not prime, or x is a quadratic residue of y - * J(x,y) == -1 => x is NOT a quadratic residue of y + * J(x,y) == 1 => y is not prime, or x is a quadratic residue of y + * J(x,y) == -1 => x is NOT a quadratic residue of y * * when * - * y mod 2 == 1 - * gcd(x,y) == 1 + * y mod 2 == 1 + * gcd(x,y) == 1 * * In the following comments on Legendre and Jacobi identities, we shall * assume that the arguments to the symbolic are valid over the symbol @@ -1518,161 +1518,161 @@ legacy_d_qval[7] = 19; legacy_v1_qval[7] = 74; /* a=38 b=1 r=2 */ * * In Ref2, pp 280-284, we find that: * - * L(a,p)*L(b,p) == L(a*b,p) {A3.5} - * J(x,y)*J(z,y) == J(x*z,y) {A3.14} - * L(a,p) == L(p,a) * (-1)^((a-1)*(p-1)/4) {A3.8} - * J(x,y) == J(y,x) * (-1)^((x-1)*(y-1)/4) {A3.17} + * L(a,p)*L(b,p) == L(a*b,p) {A3.5} + * J(x,y)*J(z,y) == J(x*z,y) {A3.14} + * L(a,p) == L(p,a) * (-1)^((a-1)*(p-1)/4) {A3.8} + * J(x,y) == J(y,x) * (-1)^((x-1)*(y-1)/4) {A3.17} * - * The equality L(a,p) == J(a,p) when: {note 0} + * The equality L(a,p) == J(a,p) when: {note 0} * - * p is prime - * p mod 2 == 1 - * gcd(a,p) == 1 + * p is prime + * p mod 2 == 1 + * gcd(a,p) == 1 * * It can be shown that (see Ref3): * - * L(a,p) == L(a mod p, p) {note 1} - * L(z^2, p) == 1 {note 2} + * L(a,p) == L(a mod p, p) {note 1} + * L(z^2, p) == 1 {note 2} * * From Ref2, table 32: * - * p mod 8 == +/-1 implies L(2,p) == 1 {note 3} - * p mod 12 == +/-1 implies L(3,p) == 1 {note 4} + * p mod 8 == +/-1 implies L(2,p) == 1 {note 3} + * p mod 12 == +/-1 implies L(3,p) == 1 {note 4} * * Since h*2^n-1 mod 8 == -1, for n>2, note 3 implies: * - * L(2, h*2^n-1) == 1 (n>2) {note 5} + * L(2, h*2^n-1) == 1 (n>2) {note 5} * * Since h=3*A, h*2^n-1 mod 12 == -1, for A>0, note 4 implies: * - * L(3, h*2^n-1) == 1 {note 6} + * L(3, h*2^n-1) == 1 {note 6} * * By use of {A3.5}, {note 2}, {note 5} and {note 6}, one can show: * - * L((2^g)*(3^l)*(z^2), h*2^n-1) == 1 (g>=0,l>=0,z>0,n>2) {note 7} + * L((2^g)*(3^l)*(z^2), h*2^n-1) == 1 (g>=0,l>=0,z>0,n>2) {note 7} * * Returning to the testing of conditions, take condition 1: * - * L(D, h*2^n-1) == -1 [condition 1] + * L(D, h*2^n-1) == -1 [condition 1] * * In order for J(D, h*2^n-1) to be defined, we must ensure that D - * is not a factor of h*2^n-1. This is done by pre-screening h*2^n-1 to + * is not a factor of h*2^n-1. This is done by pre-screening h*2^n-1 to * not have small factors and selecting D less than that factor check limit. * * By use of {note 7}, we can show that when we choose D to be: * - * D is square free - * D = P*(2^f)*(3^g) (P is prime>2) + * D is square free + * D = P*(2^f)*(3^g) (P is prime>2) * * The square free condition implies f = 0 or 1, g = 0 or 1. If f and g * are both 1, P must be a prime > 3. * * So given such a D value: * - * L(D, h*2^n-1) == L(P*(2^g)*(3^l), h*2^n-1) - * == L(P, h*2^n-1) * L((2^g)*(3^l), h*2^n-1) {A3.5} - * == L(P, h*2^n-1) * 1 {note 7} - * == L(h*2^n-1, P)*(-1)^((h*2^n-2)*(P-1)/4) {A3.8} - * == L(h*2^n-1 mod P, P)*(-1)^((h*2^n-2)*(P-1)/4) {note 1} - * == J(h*2^n-1 mod P, P)*(-1)^((h*2^n-2)*(P-1)/4) {note 0} + * L(D, h*2^n-1) == L(P*(2^g)*(3^l), h*2^n-1) + * == L(P, h*2^n-1) * L((2^g)*(3^l), h*2^n-1) {A3.5} + * == L(P, h*2^n-1) * 1 {note 7} + * == L(h*2^n-1, P)*(-1)^((h*2^n-2)*(P-1)/4) {A3.8} + * == L(h*2^n-1 mod P, P)*(-1)^((h*2^n-2)*(P-1)/4) {note 1} + * == J(h*2^n-1 mod P, P)*(-1)^((h*2^n-2)*(P-1)/4) {note 0} * * When does J(h*2^n-1 mod P, P)*(-1)^((h*2^n-2)*(P-1)/4) take the value of -1, - * thus satisfy [condition 1]? The answer depends on P. Now P is a prime>2, + * thus satisfy [condition 1]? The answer depends on P. Now P is a prime>2, * thus P mod 4 == 1 or -1. * * Take P mod 4 == 1: * - * P mod 4 == 1 implies (-1)^((h*2^n-2)*(P-1)/4) == 1 + * P mod 4 == 1 implies (-1)^((h*2^n-2)*(P-1)/4) == 1 * * Thus: * - * L(D, h*2^n-1) == L(h*2^n-1 mod P, P) * (-1)^((h*2^n-2)*(P-1)/4) - * == L(h*2^n-1 mod P, P) - * == J(h*2^n-1 mod P, P) + * L(D, h*2^n-1) == L(h*2^n-1 mod P, P) * (-1)^((h*2^n-2)*(P-1)/4) + * == L(h*2^n-1 mod P, P) + * == J(h*2^n-1 mod P, P) * * Take P mod 4 == -1: * - * P mod 4 == -1 implies (-1)^((h*2^n-2)*(P-1)/4) == -1 + * P mod 4 == -1 implies (-1)^((h*2^n-2)*(P-1)/4) == -1 * * Thus: * - * L(D, h*2^n-1) == L(h*2^n-1 mod P, P) * (-1)^((h*2^n-2)*(P-1)/4) - * == L(h*2^n-1 mod P, P) * -1 - * == -J(h*2^n-1 mod P, P) + * L(D, h*2^n-1) == L(h*2^n-1 mod P, P) * (-1)^((h*2^n-2)*(P-1)/4) + * == L(h*2^n-1 mod P, P) * -1 + * == -J(h*2^n-1 mod P, P) * * Therefore [condition 1] is met if, and only if, one of the following * to cases are true: * - * P mod 4 == 1 and J(h*2^n-1 mod P, P) == -1 - * P mod 4 == -1 and J(h*2^n-1 mod P, P) == 1 + * P mod 4 == 1 and J(h*2^n-1 mod P, P) == -1 + * P mod 4 == -1 and J(h*2^n-1 mod P, P) == 1 * * Now consider [condition 2]: * - * L(r, h*2^n-1) * (a^2 - b^2*D)/r == -1 [condition 2] + * L(r, h*2^n-1) * (a^2 - b^2*D)/r == -1 [condition 2] * * We select only a, b, r and D values where: * - * (a^2 - b^2*D)/r == -1 + * (a^2 - b^2*D)/r == -1 * * Therefore in order for [condition 2] to be met, we must show that: * - * L(r, h*2^n-1) == 1 + * L(r, h*2^n-1) == 1 * * If we select r to be of the form: * - * r == Q*(2^j)*(3^k)*(z^2) (Q == 1, j>=0, k>=0, z>0) + * r == Q*(2^j)*(3^k)*(z^2) (Q == 1, j>=0, k>=0, z>0) * * then by use of {note 7}: * - * L(r, h*2^n-1) == L(Q*(2^j)*(3^k)*(z^2), h*2^n-1) - * == L((2^j)*(3^k)*(z^2), h*2^n-1) - * == 1 {note 2} + * L(r, h*2^n-1) == L(Q*(2^j)*(3^k)*(z^2), h*2^n-1) + * == L((2^j)*(3^k)*(z^2), h*2^n-1) + * == 1 {note 2} * * and thus, [condition 2] is met. * * If we select r to be of the form: * - * r == Q*(2^j)*(3^k)*(z^2) (Q is prime>2, j>=0, k>=0, z>0) + * r == Q*(2^j)*(3^k)*(z^2) (Q is prime>2, j>=0, k>=0, z>0) * * then by use of {note 7}: * - * L(r, h*2^n-1) == L(Q*(2^j)*(3^k)*(z^2), h*2^n-1) - * == L(Q, h*2^n-1) * L((2^j)*(3^k)*(z^2), h*2^n-1) {A3.5} - * == L(Q, h*2^n-1) * 1 {note 2} - * == L(h*2^n-1, Q) * (-1)^((h*2^n-2)*(Q-1)/4) {A3.8} - * == L(h*2^n-1 mod Q, Q)*(-1)^((h*2^n-2)*(Q-1)/4) {note 1} - * == J(h*2^n-1 mod Q, Q)*(-1)^((h*2^n-2)*(Q-1)/4) {note 0} + * L(r, h*2^n-1) == L(Q*(2^j)*(3^k)*(z^2), h*2^n-1) + * == L(Q, h*2^n-1) * L((2^j)*(3^k)*(z^2), h*2^n-1) {A3.5} + * == L(Q, h*2^n-1) * 1 {note 2} + * == L(h*2^n-1, Q) * (-1)^((h*2^n-2)*(Q-1)/4) {A3.8} + * == L(h*2^n-1 mod Q, Q)*(-1)^((h*2^n-2)*(Q-1)/4) {note 1} + * == J(h*2^n-1 mod Q, Q)*(-1)^((h*2^n-2)*(Q-1)/4) {note 0} * * When does J(h*2^n-1 mod Q, Q)*(-1)^((h*2^n-2)*(Q-1)/4) take the value of 1, - * thus satisfy [condition 2]? The answer depends on Q. Now Q is a prime>2, + * thus satisfy [condition 2]? The answer depends on Q. Now Q is a prime>2, * thus Q mod 4 == 1 or -1. * * Take Q mod 4 == 1: * - * Q mod 4 == 1 implies (-1)^((h*2^n-2)*(Q-1)/4) == 1 + * Q mod 4 == 1 implies (-1)^((h*2^n-2)*(Q-1)/4) == 1 * * Thus: * - * L(D, h*2^n-1) == L(h*2^n-1 mod Q, Q) * (-1)^((h*2^n-2)*(Q-1)/4) - * == L(h*2^n-1 mod Q, Q) - * == J(h*2^n-1 mod Q, Q) + * L(D, h*2^n-1) == L(h*2^n-1 mod Q, Q) * (-1)^((h*2^n-2)*(Q-1)/4) + * == L(h*2^n-1 mod Q, Q) + * == J(h*2^n-1 mod Q, Q) * * Take Q mod 4 == -1: * - * Q mod 4 == -1 implies (-1)^((h*2^n-2)*(Q-1)/4) == -1 + * Q mod 4 == -1 implies (-1)^((h*2^n-2)*(Q-1)/4) == -1 * * Thus: * - * L(D, h*2^n-1) == L(h*2^n-1 mod Q, Q) * (-1)^((h*2^n-2)*(Q-1)/4) - * == L(h*2^n-1 mod Q, Q) * -1 - * == -J(h*2^n-1 mod Q, Q) + * L(D, h*2^n-1) == L(h*2^n-1 mod Q, Q) * (-1)^((h*2^n-2)*(Q-1)/4) + * == L(h*2^n-1 mod Q, Q) * -1 + * == -J(h*2^n-1 mod Q, Q) * - * Therefore [condition 2] is met by selecting D = Q*(2^j)*(3^k)*(z^2), + * Therefore [condition 2] is met by selecting D = Q*(2^j)*(3^k)*(z^2), * where Q is prime>2, j>=0, k>=0, z>0; if and only if one of the following * to cases are true: * - * Q mod 4 == 1 and J(h*2^n-1 mod Q, Q) == 1 - * Q mod 4 == -1 and J(h*2^n-1 mod Q, Q) == -1 + * Q mod 4 == 1 and J(h*2^n-1 mod Q, Q) == 1 + * Q mod 4 == -1 and J(h*2^n-1 mod Q, Q) == -1 * *** * @@ -1682,165 +1682,165 @@ legacy_d_qval[7] = 19; legacy_v1_qval[7] = 74; /* a=38 b=1 r=2 */ * * we return: * - * v(1) == 4 + * v(1) == 4 * * h mod 3 == 0 * * define: * - * r == abs(a^2 - b^2*D) - * alpha == (a + b*sqrt(D))^2/r + * r == abs(a^2 - b^2*D) + * alpha == (a + b*sqrt(D))^2/r * * we return: * - * v(1) = alpha^1 + alpha^(-1) + * v(1) = alpha^1 + alpha^(-1) * * if and only if we can find a given a, b, D that obey all the * following selection rules: * - * D is square free + * D is square free * - * D == P*(2^f)*(3^g) (P is prime>2, f,g == 0 or 1) + * D == P*(2^f)*(3^g) (P is prime>2, f,g == 0 or 1) * - * (a^2 - b^2*D)/r == -1 + * (a^2 - b^2*D)/r == -1 * - * r == Q*(2^j)*(3^k)*(z^2) (Q==1 or Q is prime>2, j>=0, k>=0, z>0) + * r == Q*(2^j)*(3^k)*(z^2) (Q==1 or Q is prime>2, j>=0, k>=0, z>0) * - * one of the following is true: - * P mod 4 == 1 and J(h*2^n-1 mod P, P) == -1 - * P mod 4 == -1 and J(h*2^n-1 mod P, P) == 1 + * one of the following is true: + * P mod 4 == 1 and J(h*2^n-1 mod P, P) == -1 + * P mod 4 == -1 and J(h*2^n-1 mod P, P) == 1 * - * if Q is prime, then one of the following is true: - * Q mod 4 == 1 and J(h*2^n-1 mod Q, Q) == 1 - * Q mod 4 == -1 and J(h*2^n-1 mod Q, Q) == -1 + * if Q is prime, then one of the following is true: + * Q mod 4 == 1 and J(h*2^n-1 mod Q, Q) == 1 + * Q mod 4 == -1 and J(h*2^n-1 mod Q, Q) == -1 * * If we cannot find a v(1) quickly enough, then we will give up - * testing h*2^n-1. This does not happen too often, so this hack + * testing h*2^n-1. This does not happen too often, so this hack * is not too bad. * *** * * input: - * h h as in h*2^n-1 (must be >= 1) - * n n as in h*2^n-1 (must be >= 1) + * h h as in h*2^n-1 (must be >= 1) + * n n as in h*2^n-1 (must be >= 1) * * output: - * returns v(1), or -1 is there is no quick way + * returns v(1), or -1 is there is no quick way */ define legacy_gen_v1(h, n) { - local d; /* the 'D' value to try */ - local val_mod; /* h*2^n-1 mod 'D' */ - local i; + local d; /* the 'D' value to try */ + local val_mod; /* h*2^n-1 mod 'D' */ + local i; - /* - * check arg types - */ - if (!isint(h)) { - quit "bad args: h must be an integer"; - } - if (h < 1) { - quit "bad args: h must be an integer >= 1"; - } - if (!isint(n)) { - quit "bad args: n must be an integer"; - } - if (n < 1) { - quit "bad args: n must be an integer >= 1"; - } + /* + * check arg types + */ + if (!isint(h)) { + quit "bad args: h must be an integer"; + } + if (h < 1) { + quit "bad args: h must be an integer >= 1"; + } + if (!isint(n)) { + quit "bad args: n must be an integer"; + } + if (n < 1) { + quit "bad args: n must be an integer >= 1"; + } - /* - * check for case 1 - */ - if (h % 3 != 0) { - /* v(1) is easy to compute */ - return 4; - } + /* + * check for case 1 + */ + if (h % 3 != 0) { + /* v(1) is easy to compute */ + return 4; + } - /* - * We will try all 'D' values until we find a proper v(1) - * or run out of 'D' values. - */ - for (i=0; i < legacy_quickmax; ++i) { + /* + * We will try all 'D' values until we find a proper v(1) + * or run out of 'D' values. + */ + for (i=0; i < legacy_quickmax; ++i) { - /* grab our 'D' value */ - d = legacy_d_qval[i]; + /* grab our 'D' value */ + d = legacy_d_qval[i]; - /* compute h*2^n-1 mod 'D' quickly */ - val_mod = (h*pmod(2,n%(d-1),d)-1) % d; + /* compute h*2^n-1 mod 'D' quickly */ + val_mod = (h*pmod(2,n%(d-1),d)-1) % d; - /* - * if 'D' mod 4 == 1, then - * (h*2^n-1) mod 'D' can not be a quadratic residue of 'D' - * else - * (h*2^n-1) mod 'D' must be a quadratic residue of 'D' - */ - if (d%4 == 1) { - /* D mod 4 == 1, so check for J(D, h*2^n-1) == -1 */ - if (jacobi(val_mod, d) == -1) { - /* it worked, return the related v(1) value */ - return legacy_v1_qval[i]; - } - } else { - /* D mod 4 == -1, so check for J(D, h*2^n-1) == 1 */ - if (jacobi(val_mod, d) == 1) { - /* it worked, return the related v(1) value */ - return legacy_v1_qval[i]; - } - } - } + /* + * if 'D' mod 4 == 1, then + * (h*2^n-1) mod 'D' can not be a quadratic residue of 'D' + * else + * (h*2^n-1) mod 'D' must be a quadratic residue of 'D' + */ + if (d%4 == 1) { + /* D mod 4 == 1, so check for J(D, h*2^n-1) == -1 */ + if (jacobi(val_mod, d) == -1) { + /* it worked, return the related v(1) value */ + return legacy_v1_qval[i]; + } + } else { + /* D mod 4 == -1, so check for J(D, h*2^n-1) == 1 */ + if (jacobi(val_mod, d) == 1) { + /* it worked, return the related v(1) value */ + return legacy_v1_qval[i]; + } + } + } - /* - * This is an example of a more complex proof construction. - * The code above will not be able to find the v(1) for: - * - * 81*2^81-1 - * - * We will check with: - * - * v(1)=81 D=6557 a=79 b=1 r=316 - * - * Now, D==79*83 and r=79*2^2. If we show that: - * - * J(h*2^n-1 mod 79, 79) == -1 - * J(h*2^n-1 mod 83, 83) == 1 - * - * then we will satisfy [condition 1]. Observe: - * - * 79 mod 4 == -1 implies (-1)^((h*2^n-2)*(79-1)/4) == -1 - * 83 mod 4 == -1 implies (-1)^((h*2^n-2)*(83-1)/4) == -1 - * - * J(D, h*2^n-1) == J(83, h*2^n-1) * J(79, h*2^n-1) - * == J(h*2^n-1, 83) * (-1)^((h*2^n-2)*(83-1)/4) * - * J(h*2^n-1, 79) * (-1)^((h*2^n-2)*(79-1)/4) - * == J(h*2^n-1 mod 83, 83) * -1 * - * J(h*2^n-1 mod 79, 79) * -1 - * == 1 * -1 * - * -1 * -1 - * == -1 - * - * We will also satisfy [condition 2]. Observe: - * - * (a^2 - b^2*D)/r == (79^2 - 1^1*6557)/316 - * == -1 - * - * L(r, h*2^n-1) == L(Q*(2^j)*(3^k)*(z^2), h*2^n-1) - * == L(79, h*2^n-1) * L(2^2, h*2^n-1) - * == L(79, h*2^n-1) * 1 - * == L(h*2^n-1, 79) * (-1)^((h*2^n-2)*(79-1)/4) - * == L(h*2^n-1, 79) * -1 - * == L(h*2^n-1 mod 79, 79) * -1 - * == J(h*2^n-1 mod 79, 79) * -1 - * == -1 * -1 - * == 1 - */ - if (jacobi( ((h*pmod(2,n%(79-1),79)-1)%79), 79 ) == -1 && - jacobi( ((h*pmod(2,n%(83-1),83)-1)%83), 83 ) == 1) { - /* return the associated v(1)=81 */ - return 81; - } + /* + * This is an example of a more complex proof construction. + * The code above will not be able to find the v(1) for: + * + * 81*2^81-1 + * + * We will check with: + * + * v(1)=81 D=6557 a=79 b=1 r=316 + * + * Now, D==79*83 and r=79*2^2. If we show that: + * + * J(h*2^n-1 mod 79, 79) == -1 + * J(h*2^n-1 mod 83, 83) == 1 + * + * then we will satisfy [condition 1]. Observe: + * + * 79 mod 4 == -1 implies (-1)^((h*2^n-2)*(79-1)/4) == -1 + * 83 mod 4 == -1 implies (-1)^((h*2^n-2)*(83-1)/4) == -1 + * + * J(D, h*2^n-1) == J(83, h*2^n-1) * J(79, h*2^n-1) + * == J(h*2^n-1, 83) * (-1)^((h*2^n-2)*(83-1)/4) * + * J(h*2^n-1, 79) * (-1)^((h*2^n-2)*(79-1)/4) + * == J(h*2^n-1 mod 83, 83) * -1 * + * J(h*2^n-1 mod 79, 79) * -1 + * == 1 * -1 * + * -1 * -1 + * == -1 + * + * We will also satisfy [condition 2]. Observe: + * + * (a^2 - b^2*D)/r == (79^2 - 1^1*6557)/316 + * == -1 + * + * L(r, h*2^n-1) == L(Q*(2^j)*(3^k)*(z^2), h*2^n-1) + * == L(79, h*2^n-1) * L(2^2, h*2^n-1) + * == L(79, h*2^n-1) * 1 + * == L(h*2^n-1, 79) * (-1)^((h*2^n-2)*(79-1)/4) + * == L(h*2^n-1, 79) * -1 + * == L(h*2^n-1 mod 79, 79) * -1 + * == J(h*2^n-1 mod 79, 79) * -1 + * == -1 * -1 + * == 1 + */ + if (jacobi( ((h*pmod(2,n%(79-1),79)-1)%79), 79 ) == -1 && + jacobi( ((h*pmod(2,n%(83-1),83)-1)%83), 83 ) == 1) { + /* return the associated v(1)=81 */ + return 81; + } - /* no quick and dirty v(1), so return -1 */ - return -1; + /* no quick and dirty v(1), so return -1 */ + return -1; } diff --git a/cal/lucas_chk.cal b/cal/lucas_chk.cal index aca1a3f..4427dd5 100644 --- a/cal/lucas_chk.cal +++ b/cal/lucas_chk.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1991/01/11 05:41:43 - * File existed as early as: 1991 + * Under source code control: 1991/01/11 05:41:43 + * File existed as early as: 1991 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -31,260 +31,260 @@ * * These values were taken from: * - * "Prime numbers and Computer Methods for Factorization", by Hans Riesel, - * Birkhauser, 1985, pp 384-387. + * "Prime numbers and Computer Methods for Factorization", by Hans Riesel, + * Birkhauser, 1985, pp 384-387. * * This routine assumes that the file "lucas.cal" has been loaded. * * NOTE: There are several errors in Riesel's table that have been corrected - * in this file: + * in this file: * - * 193*2^87-1 is prime - * 193*2^97-1 is NOT prime - * 199*2^211-1 is prime - * 199*2^221-1 is NOT prime + * 193*2^87-1 is prime + * 193*2^97-1 is NOT prime + * 199*2^211-1 is prime + * 199*2^221-1 is NOT prime */ -static prime_cnt = 1145; /* number of primes in the list */ +static prime_cnt = 1145; /* number of primes in the list */ /* h = prime parameters */ static mat h_p[prime_cnt] = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* element 0 */ - 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 7, 7, 7, 7, - 7, 7, 7, 7, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 13, 13, 13, 13, 13, 13, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, /* 100 */ - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 23, 23, - 23, 23, 23, 23, 23, 23, 23, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 27, 27, 27, 27, 27, 27, 27, /* 200 */ - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 29, 29, 29, - 29, 29, 31, 31, 31, 31, 31, 31, 31, 31, - 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, - 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, - 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, - 33, 33, 33, 33, 35, 35, 35, 35, 35, 35, - 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, - 35, 37, 39, 39, 39, 39, 39, 39, 39, 39, - 39, 41, 41, 41, 41, 41, 41, 41, 41, 41, /* 300 */ - 41, 41, 41, 41, 43, 43, 43, 43, 43, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 47, 47, 47, 47, 49, - 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, - 49, 49, 49, 49, 49, 49, 51, 51, 51, 51, - 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, - 51, 53, 53, 53, 53, 53, 53, 53, 53, 53, - 53, 55, 55, 55, 55, 55, 55, 55, 55, 55, /* 400 */ - 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, - 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, - 57, 57, 57, 57, 57, 57, 57, 57, 59, 59, - 59, 59, 59, 59, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 63, 63, 63, 63, 63, 63, 63, 63, 63, - 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, - 63, 63, 63, 63, 65, 65, 65, 65, 65, 65, - 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, - 65, 65, 67, 67, 67, 67, 67, 67, 67, 67, /* 500 */ - 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, - 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, - 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, - 69, 69, 71, 71, 71, 73, 73, 73, 73, 73, - 73, 75, 75, 75, 75, 75, 75, 75, 75, 75, - 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, - 75, 75, 75, 75, 75, 75, 75, 77, 77, 77, - 77, 77, 77, 77, 77, 77, 77, 77, 77, 79, - 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, - 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, /* 600 */ - 81, 81, 81, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 85, 85, 85, 85, 85, - 85, 85, 85, 85, 87, 87, 87, 87, 87, 87, - 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, - 87, 87, 87, 87, 87, 87, 89, 89, 89, 89, - 89, 89, 89, 89, 89, 91, 91, 91, 91, 91, - 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, - 91, 91, 91, 91, 91, 91, 91, 93, 93, 93, - 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, /* 700 */ - 93, 93, 93, 93, 93, 95, 95, 95, 95, 95, - 95, 95, 95, 95, 95, 97, 97, 97, 97, 97, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 101, 101, 101, 101, - 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, - 103, 103, 103, 105, 105, 105, 105, 105, 105, 105, - 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, - 105, 105, 107, 107, 107, 107, 107, 107, 107, 107, - 107, 107, 107, 107, 107, 107, 109, 109, 109, 109, - 109, 113, 113, 113, 113, 113, 113, 113, 113, 113, /* 800 */ - 113, 115, 115, 115, 115, 115, 115, 115, 115, 115, - 115, 115, 115, 115, 115, 115, 115, 119, 119, 119, - 119, 119, 119, 119, 119, 121, 121, 121, 121, 121, - 121, 121, 121, 121, 121, 121, 121, 125, 125, 125, - 125, 125, 125, 127, 127, 131, 131, 131, 131, 131, - 131, 131, 131, 131, 131, 133, 133, 133, 133, 133, - 133, 133, 133, 133, 133, 133, 133, 133, 137, 137, - 137, 137, 139, 139, 139, 139, 139, 139, 139, 139, - 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, - 139, 139, 139, 139, 139, 139, 139, 139, 139, 143, /* 900 */ - 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, - 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, - 143, 143, 143, 145, 145, 145, 145, 145, 145, 145, - 145, 145, 145, 145, 149, 149, 149, 149, 149, 149, - 149, 151, 151, 151, 155, 155, 155, 155, 155, 155, - 155, 155, 155, 155, 155, 155, 157, 157, 157, 157, - 157, 157, 157, 157, 157, 161, 161, 161, 161, 161, - 161, 161, 161, 161, 161, 161, 161, 161, 161, 161, - 163, 163, 163, 163, 167, 167, 167, 167, 167, 167, - 167, 167, 167, 167, 167, 167, 169, 169, 169, 169, /* 1000 */ - 169, 169, 169, 169, 169, 169, 169, 169, 173, 173, - 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, - 173, 173, 173, 173, 175, 175, 175, 175, 175, 175, - 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, - 179, 179, 179, 181, 181, 181, 181, 181, 181, 181, - 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, - 181, 181, 181, 181, 181, 181, 181, 181, 185, 185, - 185, 185, 185, 185, 185, 185, 185, 185, 187, 187, - 187, 187, 187, 191, 193, 193, 193, 193, 193, 193, - 193, 197, 197, 197, 197, 197, 197, 197, 197, 197, /* 1100 */ - 197, 197, 197, 197, 197, 197, 197, 197, 197, 199, - 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, - 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, - 199, 199, 199, 199, 199 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* element 0 */ + 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 7, 7, 7, 7, + 7, 7, 7, 7, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 13, 13, 13, 13, 13, 13, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, /* 100 */ + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 21, 21, 21, 21, 21, 21, 21, 21, + 21, 21, 21, 21, 21, 21, 21, 21, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 25, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 27, 27, 27, 27, 27, 27, 27, /* 200 */ + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 29, 29, 29, + 29, 29, 31, 31, 31, 31, 31, 31, 31, 31, + 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 35, 35, 35, 35, 35, 35, + 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, + 35, 37, 39, 39, 39, 39, 39, 39, 39, 39, + 39, 41, 41, 41, 41, 41, 41, 41, 41, 41, /* 300 */ + 41, 41, 41, 41, 43, 43, 43, 43, 43, 45, + 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, + 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, + 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, + 45, 45, 45, 45, 45, 47, 47, 47, 47, 49, + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, + 49, 49, 49, 49, 49, 49, 51, 51, 51, 51, + 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, + 51, 53, 53, 53, 53, 53, 53, 53, 53, 53, + 53, 55, 55, 55, 55, 55, 55, 55, 55, 55, /* 400 */ + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, + 57, 57, 57, 57, 57, 57, 57, 57, 59, 59, + 59, 59, 59, 59, 61, 61, 61, 61, 61, 61, + 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, + 61, 63, 63, 63, 63, 63, 63, 63, 63, 63, + 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, + 63, 63, 63, 63, 65, 65, 65, 65, 65, 65, + 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, + 65, 65, 67, 67, 67, 67, 67, 67, 67, 67, /* 500 */ + 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, + 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, + 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, + 69, 69, 71, 71, 71, 73, 73, 73, 73, 73, + 73, 75, 75, 75, 75, 75, 75, 75, 75, 75, + 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, + 75, 75, 75, 75, 75, 75, 75, 77, 77, 77, + 77, 77, 77, 77, 77, 77, 77, 77, 77, 79, + 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, + 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, /* 600 */ + 81, 81, 81, 83, 83, 83, 83, 83, 83, 83, + 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, + 83, 83, 83, 83, 83, 85, 85, 85, 85, 85, + 85, 85, 85, 85, 87, 87, 87, 87, 87, 87, + 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, + 87, 87, 87, 87, 87, 87, 89, 89, 89, 89, + 89, 89, 89, 89, 89, 91, 91, 91, 91, 91, + 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, + 91, 91, 91, 91, 91, 91, 91, 93, 93, 93, + 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, /* 700 */ + 93, 93, 93, 93, 93, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 97, 97, 97, 97, 97, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 101, 101, 101, 101, + 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, + 103, 103, 103, 105, 105, 105, 105, 105, 105, 105, + 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, + 105, 105, 107, 107, 107, 107, 107, 107, 107, 107, + 107, 107, 107, 107, 107, 107, 109, 109, 109, 109, + 109, 113, 113, 113, 113, 113, 113, 113, 113, 113, /* 800 */ + 113, 115, 115, 115, 115, 115, 115, 115, 115, 115, + 115, 115, 115, 115, 115, 115, 115, 119, 119, 119, + 119, 119, 119, 119, 119, 121, 121, 121, 121, 121, + 121, 121, 121, 121, 121, 121, 121, 125, 125, 125, + 125, 125, 125, 127, 127, 131, 131, 131, 131, 131, + 131, 131, 131, 131, 131, 133, 133, 133, 133, 133, + 133, 133, 133, 133, 133, 133, 133, 133, 137, 137, + 137, 137, 139, 139, 139, 139, 139, 139, 139, 139, + 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, + 139, 139, 139, 139, 139, 139, 139, 139, 139, 143, /* 900 */ + 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, + 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, + 143, 143, 143, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 149, 149, 149, 149, 149, 149, + 149, 151, 151, 151, 155, 155, 155, 155, 155, 155, + 155, 155, 155, 155, 155, 155, 157, 157, 157, 157, + 157, 157, 157, 157, 157, 161, 161, 161, 161, 161, + 161, 161, 161, 161, 161, 161, 161, 161, 161, 161, + 163, 163, 163, 163, 167, 167, 167, 167, 167, 167, + 167, 167, 167, 167, 167, 167, 169, 169, 169, 169, /* 1000 */ + 169, 169, 169, 169, 169, 169, 169, 169, 173, 173, + 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, + 173, 173, 173, 173, 175, 175, 175, 175, 175, 175, + 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, + 179, 179, 179, 181, 181, 181, 181, 181, 181, 181, + 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, + 181, 181, 181, 181, 181, 181, 181, 181, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 187, 187, + 187, 187, 187, 191, 193, 193, 193, 193, 193, 193, + 193, 197, 197, 197, 197, 197, 197, 197, 197, 197, /* 1100 */ + 197, 197, 197, 197, 197, 197, 197, 197, 197, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199 }; /* n (exponent) prime parameters */ static mat n_p[prime_cnt] = { - 2, 3, 5, 7, 13, 17, 19, 31, 61, 89, /* element 0 */ - 107, 127, 521, 607, 1, 2, 3, 4, 6, 7, - 11, 18, 34, 38, 43, 55, 64, 76, 94, 103, - 143, 206, 216, 306, 324, 391, 458, 470, 827, 2, - 4, 8, 10, 12, 14, 18, 32, 48, 54, 72, - 148, 184, 248, 270, 274, 420, 1, 5, 9, 17, - 21, 29, 45, 177, 1, 3, 7, 13, 15, 21, - 43, 63, 99, 109, 159, 211, 309, 343, 415, 469, - 781, 871, 939, 2, 26, 50, 54, 126, 134, 246, - 354, 362, 950, 3, 7, 23, 287, 291, 795, 1, - 2, 4, 5, 10, 14, 17, 31, 41, 73, 80, /* 100 */ - 82, 116, 125, 145, 157, 172, 202, 224, 266, 289, - 293, 463, 2, 4, 6, 16, 20, 36, 54, 60, - 96, 124, 150, 252, 356, 460, 612, 654, 664, 698, - 702, 972, 1, 3, 5, 21, 41, 49, 89, 133, - 141, 165, 189, 293, 305, 395, 651, 665, 771, 801, - 923, 953, 1, 2, 3, 7, 10, 13, 18, 27, - 37, 51, 74, 157, 271, 458, 530, 891, 4, 6, - 12, 46, 72, 244, 264, 544, 888, 3, 9, 11, - 17, 23, 35, 39, 75, 105, 107, 155, 215, 335, - 635, 651, 687, 1, 2, 4, 5, 8, 10, 14, /* 200 */ - 28, 37, 38, 70, 121, 122, 160, 170, 253, 329, - 362, 454, 485, 500, 574, 892, 962, 4, 16, 76, - 148, 184, 1, 5, 7, 11, 13, 23, 33, 35, - 37, 47, 115, 205, 235, 271, 409, 739, 837, 887, - 2, 3, 6, 8, 10, 22, 35, 42, 43, 46, - 56, 91, 102, 106, 142, 190, 208, 266, 330, 360, - 382, 462, 503, 815, 2, 6, 10, 20, 44, 114, - 146, 156, 174, 260, 306, 380, 654, 686, 702, 814, - 906, 1, 3, 24, 105, 153, 188, 605, 795, 813, - 839, 2, 10, 14, 18, 50, 114, 122, 294, 362, /* 300 */ - 554, 582, 638, 758, 7, 31, 67, 251, 767, 1, - 2, 3, 4, 5, 6, 8, 9, 14, 15, 16, - 22, 28, 29, 36, 37, 54, 59, 85, 93, 117, - 119, 161, 189, 193, 256, 308, 322, 327, 411, 466, - 577, 591, 902, 928, 946, 4, 14, 70, 78, 1, - 5, 7, 9, 13, 15, 29, 33, 39, 55, 81, - 95, 205, 279, 581, 807, 813, 1, 9, 10, 19, - 22, 57, 69, 97, 141, 169, 171, 195, 238, 735, - 885, 2, 6, 8, 42, 50, 62, 362, 488, 642, - 846, 1, 3, 5, 7, 15, 33, 41, 57, 69, /* 400 */ - 75, 77, 131, 133, 153, 247, 305, 351, 409, 471, - 1, 2, 4, 5, 8, 10, 20, 22, 25, 26, - 32, 44, 62, 77, 158, 317, 500, 713, 12, 16, - 72, 160, 256, 916, 3, 5, 9, 13, 17, 19, - 25, 39, 63, 67, 75, 119, 147, 225, 419, 715, - 895, 2, 3, 8, 11, 14, 16, 28, 32, 39, - 66, 68, 91, 98, 116, 126, 164, 191, 298, 323, - 443, 714, 758, 759, 4, 6, 12, 22, 28, 52, - 78, 94, 124, 162, 174, 192, 204, 304, 376, 808, - 930, 972, 5, 9, 21, 45, 65, 77, 273, 677, /* 500 */ - 1, 4, 5, 7, 9, 11, 13, 17, 19, 23, - 29, 37, 49, 61, 79, 99, 121, 133, 141, 164, - 173, 181, 185, 193, 233, 299, 313, 351, 377, 540, - 569, 909, 2, 14, 410, 7, 11, 19, 71, 79, - 131, 1, 3, 5, 6, 18, 19, 20, 22, 28, - 29, 39, 43, 49, 75, 85, 92, 111, 126, 136, - 159, 162, 237, 349, 381, 767, 969, 2, 4, 14, - 26, 58, 60, 64, 100, 122, 212, 566, 638, 1, - 3, 7, 15, 43, 57, 61, 75, 145, 217, 247, - 3, 5, 11, 17, 21, 27, 81, 101, 107, 327, /* 600 */ - 383, 387, 941, 2, 4, 8, 10, 14, 18, 22, - 24, 26, 28, 36, 42, 58, 64, 78, 158, 198, - 206, 424, 550, 676, 904, 5, 11, 71, 113, 115, - 355, 473, 563, 883, 1, 2, 8, 9, 10, 12, - 22, 29, 32, 50, 57, 69, 81, 122, 138, 200, - 296, 514, 656, 682, 778, 881, 4, 8, 12, 24, - 48, 52, 64, 84, 96, 1, 3, 9, 13, 15, - 17, 19, 23, 47, 57, 67, 73, 77, 81, 83, - 191, 301, 321, 435, 867, 869, 917, 3, 4, 7, - 10, 15, 18, 19, 24, 27, 39, 60, 84, 111, /* 700 */ - 171, 192, 222, 639, 954, 2, 6, 26, 32, 66, - 128, 170, 288, 320, 470, 1, 9, 45, 177, 585, - 1, 4, 5, 7, 8, 11, 19, 25, 28, 35, - 65, 79, 212, 271, 361, 461, 10, 18, 54, 70, - 3, 7, 11, 19, 63, 75, 95, 127, 155, 163, - 171, 283, 563, 2, 3, 5, 6, 8, 9, 25, - 32, 65, 113, 119, 155, 177, 299, 335, 426, 462, - 617, 896, 10, 12, 18, 24, 28, 40, 90, 132, - 214, 238, 322, 532, 858, 940, 9, 149, 177, 419, - 617, 8, 14, 74, 80, 274, 334, 590, 608, 614, /* 800 */ - 650, 1, 3, 11, 13, 19, 21, 31, 49, 59, - 69, 73, 115, 129, 397, 623, 769, 12, 16, 52, - 160, 192, 216, 376, 436, 1, 3, 21, 27, 37, - 43, 91, 117, 141, 163, 373, 421, 2, 4, 44, - 182, 496, 904, 25, 113, 2, 14, 34, 38, 42, - 78, 90, 178, 778, 974, 3, 11, 15, 19, 31, - 59, 75, 103, 163, 235, 375, 615, 767, 2, 18, - 38, 62, 1, 5, 7, 9, 15, 19, 21, 35, - 37, 39, 41, 49, 69, 111, 115, 141, 159, 181, - 201, 217, 487, 567, 677, 765, 811, 841, 917, 2, /* 900 */ - 4, 6, 8, 12, 18, 26, 32, 34, 36, 42, - 60, 78, 82, 84, 88, 154, 174, 208, 256, 366, - 448, 478, 746, 5, 13, 15, 31, 77, 151, 181, - 245, 445, 447, 883, 4, 16, 48, 60, 240, 256, - 304, 5, 221, 641, 2, 8, 14, 16, 44, 46, - 82, 172, 196, 254, 556, 806, 1, 5, 33, 121, - 125, 305, 445, 473, 513, 2, 6, 18, 22, 34, - 54, 98, 122, 146, 222, 306, 422, 654, 682, 862, - 3, 31, 63, 303, 4, 6, 8, 10, 16, 32, - 38, 42, 52, 456, 576, 668, 1, 5, 11, 17, /* 1000 */ - 67, 137, 157, 203, 209, 227, 263, 917, 2, 4, - 6, 16, 32, 50, 76, 80, 96, 104, 162, 212, - 230, 260, 480, 612, 1, 3, 9, 21, 23, 41, - 47, 57, 69, 83, 193, 249, 291, 421, 433, 997, - 8, 68, 108, 3, 5, 7, 9, 11, 17, 23, - 31, 35, 43, 47, 83, 85, 99, 101, 195, 267, - 281, 363, 391, 519, 623, 653, 673, 701, 2, 6, - 10, 18, 26, 40, 46, 78, 230, 542, 1, 17, - 21, 53, 253, 226, 3, 15, 27, 63, 87, 135, - 543, 2, 16, 20, 22, 40, 82, 112, 178, 230, /* 1100 */ - 302, 304, 328, 374, 442, 472, 500, 580, 694, 1, - 5, 7, 15, 19, 23, 25, 27, 43, 65, 99, - 125, 141, 165, 201, 211, 331, 369, 389, 445, 461, - 463, 467, 513, 583, 835 + 2, 3, 5, 7, 13, 17, 19, 31, 61, 89, /* element 0 */ + 107, 127, 521, 607, 1, 2, 3, 4, 6, 7, + 11, 18, 34, 38, 43, 55, 64, 76, 94, 103, + 143, 206, 216, 306, 324, 391, 458, 470, 827, 2, + 4, 8, 10, 12, 14, 18, 32, 48, 54, 72, + 148, 184, 248, 270, 274, 420, 1, 5, 9, 17, + 21, 29, 45, 177, 1, 3, 7, 13, 15, 21, + 43, 63, 99, 109, 159, 211, 309, 343, 415, 469, + 781, 871, 939, 2, 26, 50, 54, 126, 134, 246, + 354, 362, 950, 3, 7, 23, 287, 291, 795, 1, + 2, 4, 5, 10, 14, 17, 31, 41, 73, 80, /* 100 */ + 82, 116, 125, 145, 157, 172, 202, 224, 266, 289, + 293, 463, 2, 4, 6, 16, 20, 36, 54, 60, + 96, 124, 150, 252, 356, 460, 612, 654, 664, 698, + 702, 972, 1, 3, 5, 21, 41, 49, 89, 133, + 141, 165, 189, 293, 305, 395, 651, 665, 771, 801, + 923, 953, 1, 2, 3, 7, 10, 13, 18, 27, + 37, 51, 74, 157, 271, 458, 530, 891, 4, 6, + 12, 46, 72, 244, 264, 544, 888, 3, 9, 11, + 17, 23, 35, 39, 75, 105, 107, 155, 215, 335, + 635, 651, 687, 1, 2, 4, 5, 8, 10, 14, /* 200 */ + 28, 37, 38, 70, 121, 122, 160, 170, 253, 329, + 362, 454, 485, 500, 574, 892, 962, 4, 16, 76, + 148, 184, 1, 5, 7, 11, 13, 23, 33, 35, + 37, 47, 115, 205, 235, 271, 409, 739, 837, 887, + 2, 3, 6, 8, 10, 22, 35, 42, 43, 46, + 56, 91, 102, 106, 142, 190, 208, 266, 330, 360, + 382, 462, 503, 815, 2, 6, 10, 20, 44, 114, + 146, 156, 174, 260, 306, 380, 654, 686, 702, 814, + 906, 1, 3, 24, 105, 153, 188, 605, 795, 813, + 839, 2, 10, 14, 18, 50, 114, 122, 294, 362, /* 300 */ + 554, 582, 638, 758, 7, 31, 67, 251, 767, 1, + 2, 3, 4, 5, 6, 8, 9, 14, 15, 16, + 22, 28, 29, 36, 37, 54, 59, 85, 93, 117, + 119, 161, 189, 193, 256, 308, 322, 327, 411, 466, + 577, 591, 902, 928, 946, 4, 14, 70, 78, 1, + 5, 7, 9, 13, 15, 29, 33, 39, 55, 81, + 95, 205, 279, 581, 807, 813, 1, 9, 10, 19, + 22, 57, 69, 97, 141, 169, 171, 195, 238, 735, + 885, 2, 6, 8, 42, 50, 62, 362, 488, 642, + 846, 1, 3, 5, 7, 15, 33, 41, 57, 69, /* 400 */ + 75, 77, 131, 133, 153, 247, 305, 351, 409, 471, + 1, 2, 4, 5, 8, 10, 20, 22, 25, 26, + 32, 44, 62, 77, 158, 317, 500, 713, 12, 16, + 72, 160, 256, 916, 3, 5, 9, 13, 17, 19, + 25, 39, 63, 67, 75, 119, 147, 225, 419, 715, + 895, 2, 3, 8, 11, 14, 16, 28, 32, 39, + 66, 68, 91, 98, 116, 126, 164, 191, 298, 323, + 443, 714, 758, 759, 4, 6, 12, 22, 28, 52, + 78, 94, 124, 162, 174, 192, 204, 304, 376, 808, + 930, 972, 5, 9, 21, 45, 65, 77, 273, 677, /* 500 */ + 1, 4, 5, 7, 9, 11, 13, 17, 19, 23, + 29, 37, 49, 61, 79, 99, 121, 133, 141, 164, + 173, 181, 185, 193, 233, 299, 313, 351, 377, 540, + 569, 909, 2, 14, 410, 7, 11, 19, 71, 79, + 131, 1, 3, 5, 6, 18, 19, 20, 22, 28, + 29, 39, 43, 49, 75, 85, 92, 111, 126, 136, + 159, 162, 237, 349, 381, 767, 969, 2, 4, 14, + 26, 58, 60, 64, 100, 122, 212, 566, 638, 1, + 3, 7, 15, 43, 57, 61, 75, 145, 217, 247, + 3, 5, 11, 17, 21, 27, 81, 101, 107, 327, /* 600 */ + 383, 387, 941, 2, 4, 8, 10, 14, 18, 22, + 24, 26, 28, 36, 42, 58, 64, 78, 158, 198, + 206, 424, 550, 676, 904, 5, 11, 71, 113, 115, + 355, 473, 563, 883, 1, 2, 8, 9, 10, 12, + 22, 29, 32, 50, 57, 69, 81, 122, 138, 200, + 296, 514, 656, 682, 778, 881, 4, 8, 12, 24, + 48, 52, 64, 84, 96, 1, 3, 9, 13, 15, + 17, 19, 23, 47, 57, 67, 73, 77, 81, 83, + 191, 301, 321, 435, 867, 869, 917, 3, 4, 7, + 10, 15, 18, 19, 24, 27, 39, 60, 84, 111, /* 700 */ + 171, 192, 222, 639, 954, 2, 6, 26, 32, 66, + 128, 170, 288, 320, 470, 1, 9, 45, 177, 585, + 1, 4, 5, 7, 8, 11, 19, 25, 28, 35, + 65, 79, 212, 271, 361, 461, 10, 18, 54, 70, + 3, 7, 11, 19, 63, 75, 95, 127, 155, 163, + 171, 283, 563, 2, 3, 5, 6, 8, 9, 25, + 32, 65, 113, 119, 155, 177, 299, 335, 426, 462, + 617, 896, 10, 12, 18, 24, 28, 40, 90, 132, + 214, 238, 322, 532, 858, 940, 9, 149, 177, 419, + 617, 8, 14, 74, 80, 274, 334, 590, 608, 614, /* 800 */ + 650, 1, 3, 11, 13, 19, 21, 31, 49, 59, + 69, 73, 115, 129, 397, 623, 769, 12, 16, 52, + 160, 192, 216, 376, 436, 1, 3, 21, 27, 37, + 43, 91, 117, 141, 163, 373, 421, 2, 4, 44, + 182, 496, 904, 25, 113, 2, 14, 34, 38, 42, + 78, 90, 178, 778, 974, 3, 11, 15, 19, 31, + 59, 75, 103, 163, 235, 375, 615, 767, 2, 18, + 38, 62, 1, 5, 7, 9, 15, 19, 21, 35, + 37, 39, 41, 49, 69, 111, 115, 141, 159, 181, + 201, 217, 487, 567, 677, 765, 811, 841, 917, 2, /* 900 */ + 4, 6, 8, 12, 18, 26, 32, 34, 36, 42, + 60, 78, 82, 84, 88, 154, 174, 208, 256, 366, + 448, 478, 746, 5, 13, 15, 31, 77, 151, 181, + 245, 445, 447, 883, 4, 16, 48, 60, 240, 256, + 304, 5, 221, 641, 2, 8, 14, 16, 44, 46, + 82, 172, 196, 254, 556, 806, 1, 5, 33, 121, + 125, 305, 445, 473, 513, 2, 6, 18, 22, 34, + 54, 98, 122, 146, 222, 306, 422, 654, 682, 862, + 3, 31, 63, 303, 4, 6, 8, 10, 16, 32, + 38, 42, 52, 456, 576, 668, 1, 5, 11, 17, /* 1000 */ + 67, 137, 157, 203, 209, 227, 263, 917, 2, 4, + 6, 16, 32, 50, 76, 80, 96, 104, 162, 212, + 230, 260, 480, 612, 1, 3, 9, 21, 23, 41, + 47, 57, 69, 83, 193, 249, 291, 421, 433, 997, + 8, 68, 108, 3, 5, 7, 9, 11, 17, 23, + 31, 35, 43, 47, 83, 85, 99, 101, 195, 267, + 281, 363, 391, 519, 623, 653, 673, 701, 2, 6, + 10, 18, 26, 40, 46, 78, 230, 542, 1, 17, + 21, 53, 253, 226, 3, 15, 27, 63, 87, 135, + 543, 2, 16, 20, 22, 40, 82, 112, 178, 230, /* 1100 */ + 302, 304, 328, 374, 442, 472, 500, 580, 694, 1, + 5, 7, 15, 19, 23, 25, 27, 43, 65, 99, + 125, 141, 165, 201, 211, 331, 369, 389, 445, 461, + 463, 467, 513, 583, 835 }; @@ -299,82 +299,82 @@ read -once "lucas.cal"; * when n_p is below a given limit. * * input: - * high_n skip tests on n_p[i] > high_n - * [quiet] if given and != 0, then do not print individual test results + * high_n skip tests on n_p[i] > high_n + * [quiet] if given and != 0, then do not print individual test results * * returns: - * 1 all is OK - * 0 something went wrong + * 1 all is OK + * 0 something went wrong */ define lucas_chk(high_n, quiet) { - local i; /* index */ - local result; /* 0 => non-prime, 1 => prime, -1 => bad test */ - local error; /* number of errors and bad tests found */ + local i; /* index */ + local result; /* 0 => non-prime, 1 => prime, -1 => bad test */ + local error; /* number of errors and bad tests found */ - /* - * firewall - */ - if (!isint(high_n)) { - ldebug("test_lucas", "high_n is non-int"); - quit "FATAL: bad args: high_n must be an integer"; - } - if (param(0) == 1) { - quiet = 0; - } + /* + * firewall + */ + if (!isint(high_n)) { + ldebug("test_lucas", "high_n is non-int"); + quit "FATAL: bad args: high_n must be an integer"; + } + if (param(0) == 1) { + quiet = 0; + } - /* - * scan thru the above prime table - */ - error = 0; - for (i=0; i < prime_cnt; ++i) { + /* + * scan thru the above prime table + */ + error = 0; + for (i=0; i < prime_cnt; ++i) { - /* skip primes where h>=2^n */ - if (highbit(h_p[i]) >= n_p[i]) { - if (config("resource_debug") & 8) { - print "h>=2^n skip:", h_p[i]:"*2^":n_p[i]:"-1"; - } - continue; - } + /* skip primes where h>=2^n */ + if (highbit(h_p[i]) >= n_p[i]) { + if (config("resource_debug") & 8) { + print "h>=2^n skip:", h_p[i]:"*2^":n_p[i]:"-1"; + } + continue; + } - /* test the prime if it is small enough */ - if (n_p[i] <= high_n) { + /* test the prime if it is small enough */ + if (n_p[i] <= high_n) { - /* test the table value */ - result = lucas(h_p[i], n_p[i]); + /* test the table value */ + result = lucas(h_p[i], n_p[i]); - /* report the test */ - if (result == 0) { - print "ERROR, bad primality test of",\ - h_p[i]:"*2^":n_p[i]:"-1"; - ++error; - } else if (result == 1) { - if (quiet == 0) { - print h_p[i]:"*2^":n_p[i]:"-1 is prime"; - } - } else if (result == -1) { - print "ERROR, failed to compute v(1) for",\ - h_p[i]:"*2^":n_p[i]:"-1"; - ++error; - } else { - print "ERROR, bogus return value:", result; - ++error; - } - } - } + /* report the test */ + if (result == 0) { + print "ERROR, bad primality test of",\ + h_p[i]:"*2^":n_p[i]:"-1"; + ++error; + } else if (result == 1) { + if (quiet == 0) { + print h_p[i]:"*2^":n_p[i]:"-1 is prime"; + } + } else if (result == -1) { + print "ERROR, failed to compute v(1) for",\ + h_p[i]:"*2^":n_p[i]:"-1"; + ++error; + } else { + print "ERROR, bogus return value:", result; + ++error; + } + } + } - /* return the full status */ - if (error == 0) { - if (quiet == 0) { - print "lucas_chk(":high_n:") passed"; - } - return 1; - } else if (error == 1) { - print "lucas_chk(":high_n:") failed", error, "test"; - return 0; - } else { - print "lucas_chk(":high_n:") failed", error, "tests"; - return 0; - } + /* return the full status */ + if (error == 0) { + if (quiet == 0) { + print "lucas_chk(":high_n:") passed"; + } + return 1; + } else if (error == 1) { + print "lucas_chk(":high_n:") failed", error, "test"; + return 0; + } else { + print "lucas_chk(":high_n:") failed", error, "tests"; + return 0; + } } diff --git a/cal/mersenne.cal b/cal/mersenne.cal index 706c757..fdc1367 100644 --- a/cal/mersenne.cal +++ b/cal/mersenne.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1991/05/22 21:56:36 - * File existed as early as: 1991 + * Under source code control: 1991/05/22 21:56:36 + * File existed as early as: 1991 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -32,26 +32,26 @@ define mersenne(p) { - local u, i, p_mask; + local u, i, p_mask; - /* firewall */ - if (! isint(p)) - quit "p is not an integer"; + /* firewall */ + if (! isint(p)) + quit "p is not an integer"; - /* two is a special case */ - if (p == 2) - return 1; + /* two is a special case */ + if (p == 2) + return 1; - /* if p is not prime, then 2^p-1 is not prime */ - if (! ptest(p,1)) - return 0; + /* if p is not prime, then 2^p-1 is not prime */ + if (! ptest(p,1)) + return 0; - /* lltest: u(i+1) = u(i)^2 - 2 mod 2^p-1 */ - u = 4; - for (i = 2; i < p; ++i) { - u = hnrmod(u^2 - 2, 1, p, -1); - } + /* lltest: u(i+1) = u(i)^2 - 2 mod 2^p-1 */ + u = 4; + for (i = 2; i < p; ++i) { + u = hnrmod(u^2 - 2, 1, p, -1); + } - /* 2^p-1 is prime iff u(p) = 0 mod 2^p-1 */ - return (u == 0); + /* 2^p-1 is prime iff u(p) = 0 mod 2^p-1 */ + return (u == 0); } diff --git a/cal/mfactor.cal b/cal/mfactor.cal index f4893b2..ff90e14 100644 --- a/cal/mfactor.cal +++ b/cal/mfactor.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1996/07/06 06:09:40 - * File existed as early as: 1996 + * Under source code control: 1996/07/06 06:09:40 + * File existed as early as: 1996 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -29,12 +29,12 @@ * * We will assume that mfactor is called with p_elim == 17. * - * n = (the Mersenne exponent we are testing) - * Q = 4*2*3*5*7*11*13*17 (4 * pfact(of some reasonable integer)) + * n = (the Mersenne exponent we are testing) + * Q = 4*2*3*5*7*11*13*17 (4 * pfact(of some reasonable integer)) * * We first determine all values of h mod Q such that: * - * gcd(h*n+1, Q) == 1 and h*n+1 == +/-1 mod 8 + * gcd(h*n+1, Q) == 1 and h*n+1 == +/-1 mod 8 * * There will be 2*1*2*4*6*10*12*16 such values of h. * @@ -45,59 +45,59 @@ * * We need only test factors of the form: * - * (Q*g*n + hx) + 1 + * (Q*g*n + hx) + 1 * * where: * - * g is an integer >= 0 - * hx is computed from hset[] difference value described above + * g is an integer >= 0 + * hx is computed from hset[] difference value described above * * Note that (Q*g*n + hx) is always even and that hx is a multiple * of n. Thus the typical factor form: * - * 2*k*n + 1 + * 2*k*n + 1 * * implies that: * - * k = (Q*g + hx/n)/2 + * k = (Q*g + hx/n)/2 * * This allows us to quickly eliminate factor values that are divisible - * by 2, 3, 5, 7, 11, 13 or 17. (well <= p value found below) + * by 2, 3, 5, 7, 11, 13 or 17. (well <= p value found below) * * The following loop shows how test_factor is advanced to higher test - * values using hset[]. Here, hcount is the number of elements in hset[]. + * values using hset[]. Here, hcount is the number of elements in hset[]. * It can be shown that hset[0] == 0. We add hset[hcount] to the hset[] * array for looping control convenience. * - * (* increase test_factor thru other possible test values *) - * test_factor = 0; - * hindx = 0; - * do { - * while (++hindx <= hcount) { - * test_factor += hset[hindx]; - * } - * hindx = 0; - * } while (test_factor < some_limit); + * (* increase test_factor thru other possible test values *) + * test_factor = 0; + * hindx = 0; + * do { + * while (++hindx <= hcount) { + * test_factor += hset[hindx]; + * } + * hindx = 0; + * } while (test_factor < some_limit); * * The test, mfactor(67, 1, 10000) took on an 200 MHz r4k (user CPU seconds): * - * 210.83 (prior to use of hset[]) - * 78.35 (hset[] for p_elim = 7) - * 73.87 (hset[] for p_elim = 11) - * 73.92 (hset[] for p_elim = 13) - * 234.16 (hset[] for p_elim = 17) - * p_elim == 19 requires over 190 Megs of memory + * 210.83 (prior to use of hset[]) + * 78.35 (hset[] for p_elim = 7) + * 73.87 (hset[] for p_elim = 11) + * 73.92 (hset[] for p_elim = 13) + * 234.16 (hset[] for p_elim = 17) + * p_elim == 19 requires over 190 Megs of memory * * Over a long period of time, the call to load_hset() becomes insignificant. * If we look at the user CPU seconds from the first 10000 cycle to the * end of the test we find: * - * 205.00 (prior to use of hset[]) - * 75.89 (hset[] for p_elim = 7) - * 73.74 (hset[] for p_elim = 11) - * 70.61 (hset[] for p_elim = 13) - * 57.78 (hset[] for p_elim = 17) - * p_elim == 19 rejected because of memory size + * 205.00 (prior to use of hset[]) + * 75.89 (hset[] for p_elim = 7) + * 73.74 (hset[] for p_elim = 11) + * 70.61 (hset[] for p_elim = 13) + * 57.78 (hset[] for p_elim = 17) + * p_elim == 19 rejected because of memory size * * The p_elim == 17 overhead takes ~3 minutes on an 200 MHz r4k CPU and * requires about ~13 Megs of memory. The p_elim == 13 overhead @@ -108,8 +108,8 @@ * for p_elim == 13. * * NOTE: The values above are prior to optimizations where hset[] was - * multiplied by n plus other optimizations. Thus, the CPU - * times you may get will not likely match the above values. + * multiplied by n plus other optimizations. Thus, the CPU + * times you may get will not likely match the above values. */ @@ -118,198 +118,198 @@ * * Mersenne numbers are numbers of the form: * - * 2^n-1 for integer n > 0 + * 2^n-1 for integer n > 0 * * We know that factors of a Mersenne number are of the form: * - * 2*k*n+1 and +/- 1 mod 8 + * 2*k*n+1 and +/- 1 mod 8 * * We make use of the hset[] difference array to eliminate factor * candidates that would otherwise be divisible by 2, 3, 5, 7 ... p_elim. * * given: - * n attempt to factor M(n) = 2^n-1 - * start_k the value k in 2*k*n+1 to start the search (def: 1) - * rept_loop loop cycle reporting (def: 10000) - * p_elim largest prime to eliminate from test factors (def: 17) + * n attempt to factor M(n) = 2^n-1 + * start_k the value k in 2*k*n+1 to start the search (def: 1) + * rept_loop loop cycle reporting (def: 10000) + * p_elim largest prime to eliminate from test factors (def: 17) * * returns: - * factor of (2^n)-1 + * factor of (2^n)-1 * * NOTE: The p_elim argument is optional and defaults to 17. A p_elim value - * of 17 is faster than 13 for even medium length runs. However 13 - * uses less memory and has a shorter startup time. + * of 17 is faster than 13 for even medium length runs. However 13 + * uses less memory and has a shorter startup time. */ define mfactor(n, start_k, rept_loop, p_elim) { - local Q; /* 4*pfact(p_elim), hset[] cycle size */ - local hcount; /* elements in the hset[] difference array */ - local loop; /* report loop count */ - local q; /* test factor of 2^n-1 */ - local g; /* g as in test candidate form: (Q*g*hset[i])*n + 1 */ - local hindx; /* hset[] index */ - local i; - local tmp; - local tmp2; + local Q; /* 4*pfact(p_elim), hset[] cycle size */ + local hcount; /* elements in the hset[] difference array */ + local loop; /* report loop count */ + local q; /* test factor of 2^n-1 */ + local g; /* g as in test candidate form: (Q*g*hset[i])*n + 1 */ + local hindx; /* hset[] index */ + local i; + local tmp; + local tmp2; - /* - * firewall - */ - if (!isint(n) || n <= 0) { - quit "n must be an integer > 0"; - } - if (!isint(start_k)) { - start_k = 1; - } else if (!isint(start_k) || start_k <= 0) { - quit "start_k must be an integer > 0"; - } - if (!isint(rept_loop)) { - rept_loop = 10000; - } - if (rept_loop < 1) { - quit "rept_loop must be an integer > 0"; - } - if (!isint(p_elim)) { - p_elim = 17; - } - if (p_elim < 3) { - quit "p_elim must be an integer > 2 (try 13 or 17)"; - } + /* + * firewall + */ + if (!isint(n) || n <= 0) { + quit "n must be an integer > 0"; + } + if (!isint(start_k)) { + start_k = 1; + } else if (!isint(start_k) || start_k <= 0) { + quit "start_k must be an integer > 0"; + } + if (!isint(rept_loop)) { + rept_loop = 10000; + } + if (rept_loop < 1) { + quit "rept_loop must be an integer > 0"; + } + if (!isint(p_elim)) { + p_elim = 17; + } + if (p_elim < 3) { + quit "p_elim must be an integer > 2 (try 13 or 17)"; + } - /* - * declare our global values - */ - Q = 4*pfact(p_elim); - hcount = 2; - /* allocate the h difference array */ - for (i=2; i <= p_elim; i = nextcand(i)) { - hcount *= (i-1); - } - local mat hset[hcount+1]; + /* + * declare our global values + */ + Q = 4*pfact(p_elim); + hcount = 2; + /* allocate the h difference array */ + for (i=2; i <= p_elim; i = nextcand(i)) { + hcount *= (i-1); + } + local mat hset[hcount+1]; - /* - * load the hset[] difference array - */ - { - local x; /* h*n+1 mod 8 */ - local h; /* potential h value */ - local last_h; /* previous valid h value */ + /* + * load the hset[] difference array + */ + { + local x; /* h*n+1 mod 8 */ + local h; /* potential h value */ + local last_h; /* previous valid h value */ - last_h = 0; - for (i=0,h=0; h < Q; ++h) { - if (gcd(h*n+1,Q) == 1) { - x = (h*n+1) % 8; - if (x == 1 || x == 7) { - hset[i++] = (h-last_h) * n; - last_h = h; - } - } - } - hset[hcount] = Q*n - last_h*n; - } + last_h = 0; + for (i=0,h=0; h < Q; ++h) { + if (gcd(h*n+1,Q) == 1) { + x = (h*n+1) % 8; + if (x == 1 || x == 7) { + hset[i++] = (h-last_h) * n; + last_h = h; + } + } + } + hset[hcount] = Q*n - last_h*n; + } - /* - * setup - * - * determine the next g and hset[] index (hindx) values such that: - * - * 2*start_k <= (Q*g + hset[hindx]) - * - * and (Q*g + hset[hindx]) is a minimum and where: - * - * Q = (4 * pfact(of some reasonable integer)) - * g = (some integer) (hset[] cycle number) - * - * We also compute 'q', the next test candidate. - */ - g = (2*start_k) // Q; - tmp = 2*start_k - Q*g; - for (tmp2=0, hindx=0; - hindx < hcount && (tmp2 += hset[hindx]/n) < tmp; - ++hindx) { - } - if (hindx == hcount) { - /* we are beyond the end of a hset[] cycle, start at the next */ - ++g; - hindx = 0; - tmp2 = hset[0]/n; - } - q = (Q*g + tmp2)*n + 1; + /* + * setup + * + * determine the next g and hset[] index (hindx) values such that: + * + * 2*start_k <= (Q*g + hset[hindx]) + * + * and (Q*g + hset[hindx]) is a minimum and where: + * + * Q = (4 * pfact(of some reasonable integer)) + * g = (some integer) (hset[] cycle number) + * + * We also compute 'q', the next test candidate. + */ + g = (2*start_k) // Q; + tmp = 2*start_k - Q*g; + for (tmp2=0, hindx=0; + hindx < hcount && (tmp2 += hset[hindx]/n) < tmp; + ++hindx) { + } + if (hindx == hcount) { + /* we are beyond the end of a hset[] cycle, start at the next */ + ++g; + hindx = 0; + tmp2 = hset[0]/n; + } + q = (Q*g + tmp2)*n + 1; - /* - * look for a factor - * - * We ignore factors that themselves are divisible by a prime <= - * some small prime p. - * - * This process is guaranteed to find the smallest factor - * of 2^n-1. A smallest factor of 2^n-1 must be prime, otherwise - * the divisors of that factor would also be factors of 2^n-1. - * Thus we know that if a test factor itself is not prime, it - * cannot be the smallest factor of 2^n-1. - * - * Eliminating all non-prime test factors would take too long. - * However we can eliminate 80.81% of the test factors - * by not using test factors that are divisible by a prime <= 17. - */ - if (pmod(2,n,q) == 1) { - return q; - } else { - /* report this loop */ - printf("at 2*%d*%d+1, CPU: %f\n", - (q-1)/(2*n), n, usertime()); - fflush(files(1)); - loop = 0; - } - do { - /* - * determine if we need to report - * - * NOTE: (q-1)/(2*n) is the k value from 2*k*n + 1. - */ - if (rept_loop <= ++loop) { - /* report this loop */ - printf("at 2*%d*%d+1, CPU: %f\n", - (q-1)/(2*n), n, usertime()); - fflush(files(1)); - loop = 0; - } + /* + * look for a factor + * + * We ignore factors that themselves are divisible by a prime <= + * some small prime p. + * + * This process is guaranteed to find the smallest factor + * of 2^n-1. A smallest factor of 2^n-1 must be prime, otherwise + * the divisors of that factor would also be factors of 2^n-1. + * Thus we know that if a test factor itself is not prime, it + * cannot be the smallest factor of 2^n-1. + * + * Eliminating all non-prime test factors would take too long. + * However we can eliminate 80.81% of the test factors + * by not using test factors that are divisible by a prime <= 17. + */ + if (pmod(2,n,q) == 1) { + return q; + } else { + /* report this loop */ + printf("at 2*%d*%d+1, CPU: %f\n", + (q-1)/(2*n), n, usertime()); + fflush(files(1)); + loop = 0; + } + do { + /* + * determine if we need to report + * + * NOTE: (q-1)/(2*n) is the k value from 2*k*n + 1. + */ + if (rept_loop <= ++loop) { + /* report this loop */ + printf("at 2*%d*%d+1, CPU: %f\n", + (q-1)/(2*n), n, usertime()); + fflush(files(1)); + loop = 0; + } - /* - * skip if divisible by a prime <= 449 - * - * The value 281 was determined by timing loops - * which found that 281 was at or near the - * minimum time to factor 2^(2^127-1)-1. - * - * The addition of the do { ... } while (factor(q, 449)>1); - * loop reduced the factoring loop time (36504 k values with - * the hset[] initialization time removed) from 25.69 sec to - * 15.62 sec of CPU time on a 200MHz r4k. - */ - do { - /* - * determine the next factor candidate - */ - q += hset[++hindx]; - if (hindx >= hcount) { - hindx = 0; - /* - * if we cared about g, - * then we wound ++g here too - */ - } - } while (factor(q, 449) > 1); - } while (pmod(2,n,q) != 1); + /* + * skip if divisible by a prime <= 449 + * + * The value 281 was determined by timing loops + * which found that 281 was at or near the + * minimum time to factor 2^(2^127-1)-1. + * + * The addition of the do { ... } while (factor(q, 449)>1); + * loop reduced the factoring loop time (36504 k values with + * the hset[] initialization time removed) from 25.69 sec to + * 15.62 sec of CPU time on a 200MHz r4k. + */ + do { + /* + * determine the next factor candidate + */ + q += hset[++hindx]; + if (hindx >= hcount) { + hindx = 0; + /* + * if we cared about g, + * then we wound ++g here too + */ + } + } while (factor(q, 449) > 1); + } while (pmod(2,n,q) != 1); - /* - * return the factor found - * - * q is a factor of (2^n)-1 - */ - return q; + /* + * return the factor found + * + * q is a factor of (2^n)-1 + */ + return q; } if (config("resource_debug") & 3) { - print "mfactor(n [, start_k=1 [, rept_loop=10000 [, p_elim=17]]])" + print "mfactor(n [, start_k=1 [, rept_loop=10000 [, p_elim=17]]])" } diff --git a/cal/mod.cal b/cal/mod.cal index 50ca95a..9aeb88d 100644 --- a/cal/mod.cal +++ b/cal/mod.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,192 +17,192 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:50:34 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:50:34 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ -obj mod {a}; /* definition of the object */ +obj mod {a}; /* definition of the object */ -global mod_value = 100; /* modulus value (value of N) */ +global mod_value = 100; /* modulus value (value of N) */ define lmod(a) { - local obj mod x; + local obj mod x; - if (!isreal(a) || !isint(a)) - quit "Bad argument for lmod function"; - x.a = a % mod_value; - return x; + if (!isreal(a) || !isint(a)) + quit "Bad argument for lmod function"; + x.a = a % mod_value; + return x; } define mod_print(a) { - if (digits(mod_value) <= 20) - print a.a, "(mod", mod_value : ")" :; - else - print a.a, "(mod N)" :; + if (digits(mod_value) <= 20) + print a.a, "(mod", mod_value : ")" :; + else + print a.a, "(mod N)" :; } define mod_one() { - return lmod(1); + return lmod(1); } define mod_cmp(a, b) { - if (isnum(a)) - return (a % mod_value) != b.a; - if (isnum(b)) - return (b % mod_value) != a.a; - return a.a != b.a; + if (isnum(a)) + return (a % mod_value) != b.a; + if (isnum(b)) + return (b % mod_value) != a.a; + return a.a != b.a; } define mod_rel(a, b) { - if (isnum(a)) - a = lmod(a); - if (isnum(b)) - b = lmod(b); - if (a.a < b.a) - return -1; - return a.a != b.a; + if (isnum(a)) + a = lmod(a); + if (isnum(b)) + b = lmod(b); + if (a.a < b.a) + return -1; + return a.a != b.a; } define mod_add(a, b) { - local obj mod x; + local obj mod x; - if (isnum(b)) { - if (!isint(b)) - quit "Adding non-integer"; - x.a = (a.a + b) % mod_value; - return x; - } - if (isnum(a)) { - if (!isint(a)) - quit "Adding non-integer"; - x.a = (a + b.a) % mod_value; - return x; - } - x.a = (a.a + b.a) % mod_value; - return x; + if (isnum(b)) { + if (!isint(b)) + quit "Adding non-integer"; + x.a = (a.a + b) % mod_value; + return x; + } + if (isnum(a)) { + if (!isint(a)) + quit "Adding non-integer"; + x.a = (a + b.a) % mod_value; + return x; + } + x.a = (a.a + b.a) % mod_value; + return x; } define mod_sub(a, b) { - return a + (-b); + return a + (-b); } define mod_neg(a) { - local obj mod x; + local obj mod x; - x.a = mod_value - a.a; - return x; + x.a = mod_value - a.a; + return x; } define mod_mul(a, b) { - local obj mod x; + local obj mod x; - if (isnum(b)) { - if (!isint(b)) - quit "Multiplying by non-integer"; - x.a = (a.a * b) % mod_value; - return x; - } - if (isnum(a)) { - if (!isint(a)) - quit "Multiplying by non-integer"; - x.a = (a * b.a) % mod_value; - return x; - } - x.a = (a.a * b.a) % mod_value; - return x; + if (isnum(b)) { + if (!isint(b)) + quit "Multiplying by non-integer"; + x.a = (a.a * b) % mod_value; + return x; + } + if (isnum(a)) { + if (!isint(a)) + quit "Multiplying by non-integer"; + x.a = (a * b.a) % mod_value; + return x; + } + x.a = (a.a * b.a) % mod_value; + return x; } define mod_square(a) { - local obj mod x; + local obj mod x; - x.a = a.a^2 % mod_value; - return x; + x.a = a.a^2 % mod_value; + return x; } define mod_inc(a) { - local x; + local x; - x = a; - if (++x.a == mod_value) - x.a = 0; - return x; + x = a; + if (++x.a == mod_value) + x.a = 0; + return x; } define mod_dec(a) { - local x; + local x; - x = a; - if (--x.a < 0) - x.a = mod_value - 1; - return x; + x = a; + if (--x.a < 0) + x.a = mod_value - 1; + return x; } define mod_inv(a) { - local obj mod x; + local obj mod x; - x.a = minv(a.a, mod_value); - return x; + x.a = minv(a.a, mod_value); + return x; } define mod_div(a, b) { - local c; - local obj mod x; - local obj mod y; - if (isnum(a)) - a = lmod(a); - if (isnum(b)) - b = lmod(b); - c = gcd(a.a, b.a); - x.a = a.a / c; - y.a = b.a / c; - return x * inverse(y); + local c; + local obj mod x; + local obj mod y; + if (isnum(a)) + a = lmod(a); + if (isnum(b)) + b = lmod(b); + c = gcd(a.a, b.a); + x.a = a.a / c; + y.a = b.a / c; + return x * inverse(y); } define mod_pow(a, b) { - local x, y, z; + local x, y, z; - obj mod x; - y = a; - z = b; - if (b < 0) { - y = inverse(a); - z = -b; - } - x.a = pmod(y.a, z, mod_value); - return x; + obj mod x; + y = a; + z = b; + if (b < 0) { + y = inverse(a); + z = -b; + } + x.a = pmod(y.a, z, mod_value); + return x; } diff --git a/cal/natnumset.cal b/cal/natnumset.cal index 3cfa310..9ea8c2e 100644 --- a/cal/natnumset.cal +++ b/cal/natnumset.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/09/07 23:53:51 - * File existed as early as: 1997 + * Under source code control: 1997/09/07 23:53:51 + * File existed as early as: 1997 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -40,14 +40,14 @@ * * In an assignment of a set-valued lvalue to an lvalue, as in * - * A = set(1,2,3); - * B = A; + * A = set(1,2,3); + * B = A; * * the sets share the same data string, so a change to either has the effect * of changing both. A set equal to A but with a different string can be * created by * - * B = A | set() + * B = A | set() * * The functions empty() and full() return the empty set and the set of all * integers in [0,B] respectively. @@ -57,58 +57,58 @@ * test(A) returns 0 or 1 according as A is or is not the empty set * * isin(A, n) for set A and integer n returns 1 if n is in A, 0 if - * 0 <= n <= B and n is not in A, the null value if n < 0 or n > B. + * 0 <= n <= B and n is not in A, the null value if n < 0 or n > B. * * addmember(A, n) adds n as a member of A, provided n is in [0, B]; - * this is also achieved by A |= n. + * this is also achieved by A |= n. * * rmmember(A, n) removes n from A if it is a member; this is also achieved - * by A \= n. + * by A \= n. * * The following unary and binary operations are defined for sets A, B. - * For binary operations with one argument a set and the other an - * integer n, the integer taken to represent set(n). + * For binary operations with one argument a set and the other an + * integer n, the integer taken to represent set(n). * - * A | B = union of A and B, integers in at least one of A and B - * A & B = intersection of A and B, integers in both A and B - * A ~ B = symmetric difference (boolean sum) of A and Bi, integers - * in exactly one of A and B - * A \ B = set difference, integers in A but not in B + * A | B = union of A and B, integers in at least one of A and B + * A & B = intersection of A and B, integers in both A and B + * A ~ B = symmetric difference (boolean sum) of A and Bi, integers + * in exactly one of A and B + * A \ B = set difference, integers in A but not in B * - * ~A = complement of A, integers not in A - * #A = number of integers in A - * !A = 1 or 0 according as A is empty or not empty - * +A = sum of the members of A + * ~A = complement of A, integers not in A + * #A = number of integers in A + * !A = 1 or 0 according as A is empty or not empty + * +A = sum of the members of A * - * min(A) = least member of A, -1 for empty set - * max(A) = greatest member of A, -1 for empty set - * sum(A) = sum of the members of A + * min(A) = least member of A, -1 for empty set + * max(A) = greatest member of A, -1 for empty set + * sum(A) = sum of the members of A * * In the following a and b denote arbitrary members of A and B: * - * A + B = set of sums a + b - * A - B = set of differences a - b - * A * B = set of products a * b - * A ^ n = set of powers a ^ n - * A % m = set of integers congruent to a mod m + * A + B = set of sums a + b + * A - B = set of differences a - b + * A * B = set of products a * b + * A ^ n = set of powers a ^ n + * A % m = set of integers congruent to a mod m * - * A == B returns 1 or not according as A and B are equal or not - * A != B = !(A == B) - * A <= B returns 1 if A is a subset of B, i.e. every member of A is - * a member of B - * A < B = ((A <= B) && (A != B)) - * A >= B = (B <= A) - * A > B = (B < A) + * A == B returns 1 or not according as A and B are equal or not + * A != B = !(A == B) + * A <= B returns 1 if A is a subset of B, i.e. every member of A is + * a member of B + * A < B = ((A <= B) && (A != B)) + * A >= B = (B <= A) + * A > B = (B < A) * * Expressions may be formed from the above "arithmetic" operations in * the usual way, with parentheses for variations from the usual precedence * rules. For example * - * A + 3 * A ^ 2 + (A - B) ^ 3 + * A + 3 * A ^ 2 + (A - B) ^ 3 * * returns the set of integers expressible as * - * a_1 + 3 * a_2 ^ 2 + (a_3 - b) ^3 + * a_1 + 3 * a_2 ^ 2 + (a_3 - b) ^3 * * where a_1, a_2, a_3 are in A, and b is in B. * @@ -119,28 +119,28 @@ * isinterval(A) returns 1 if A is a non-empty interval, 0 otherwise. * * randset(n, a, b) returns a random set of n integers between a and b - * inclusive; a defaults to 0, b to N-1. An error occurs if - * n is too large. + * inclusive; a defaults to 0, b to N-1. An error occurs if + * n is too large. * * polyvals(L, A) for L = list(c_0, c_1, c_2, ...) returns the set of * values of * - * c_0 + c_1 * a + c_2 * a^2 + ... + * c_0 + c_1 * a + c_2 * a^2 + ... * * for a in the set A. * * polyvals2(L, A, B) returns the set of values of poly(L, i, j) for i in - * A and j in B. Here L is a list whose members are integers or - * lists of integers, the latter representing polynomials in the - * second variable. For example, with L = list(0, list(0, 1), 1), - * polyvals2(L, A, B) will return the values of i^2 + i * j for - * i in A, j in B. + * A and j in B. Here L is a list whose members are integers or + * lists of integers, the latter representing polynomials in the + * second variable. For example, with L = list(0, list(0, 1), 1), + * polyvals2(L, A, B) will return the values of i^2 + i * j for + * i in A, j in B. * */ -static N; /* Number of integers in [0,B], = B + 1 */ -static M; /* Maximum string size required, = N // 8 */ +static N; /* Number of integers in [0,B], = B + 1 */ +static M; /* Maximum string size required, = N // 8 */ obj set {s}; @@ -148,17 +148,17 @@ define isset(a) = istype(a, obj set); define setbound(n) { - local v; + local v; - v = N - 1; - if (isnull(n)) - return v; - if (!isint(n) || n < 0) - quit "Bad argument for setbound"; - N = n + 1; - M = quo(N, 8, 1); /* M // 8 rounded up */ - if (v >= 0) - return v; + v = N - 1; + if (isnull(n)) + return v; + if (!isint(n) || n < 0) + quit "Bad argument for setbound"; + N = n + 1; + M = quo(N, 8, 1); /* M // 8 rounded up */ + if (v >= 0) + return v; } setbound(100); @@ -167,90 +167,90 @@ define empty() = obj set = {""}; define full() { - local v; + local v; - obj set v; - v.s = M * char(-1); - if (!ismult(N, 8)) v.s[M-1] = 255 >> (8 - N & 7); - return v; + obj set v; + v.s = M * char(-1); + if (!ismult(N, 8)) v.s[M-1] = 255 >> (8 - N & 7); + return v; } define isin(a, b) { - if (!isset(a) || !isint(b)) - quit "Bad argument for isin"; - return bit(a.s, b); + if (!isset(a) || !isint(b)) + quit "Bad argument for isin"; + return bit(a.s, b); } define addmember(a, n) { - if (!isset(a) || !isint(n)) - quit "Bad argument for addmember"; - if (n < N && n >= 0) - setbit(a.s, n); + if (!isset(a) || !isint(n)) + quit "Bad argument for addmember"; + if (n < N && n >= 0) + setbit(a.s, n); } define rmmember(a, n) { - if (n < N && n >= 0) - setbit(a.s, n, 0); + if (n < N && n >= 0) + setbit(a.s, n, 0); } define set() { - local i, v, s; + local i, v, s; - s = M * char(0); - for (i = 1; i <= param(0); i++) { - v = param(i); - if (!isint(v)) - quit "Non-integral argument for set"; - if (v >= 0 && v < N) - setbit(s, v); - } - return mkset(s); + s = M * char(0); + for (i = 1; i <= param(0); i++) { + v = param(i); + if (!isint(v)) + quit "Non-integral argument for set"; + if (v >= 0 && v < N) + setbit(s, v); + } + return mkset(s); } define mkset(s) { - local h, m; + local h, m; - if (!isstr(s)) - quit "Non-string argument for mkset"; - h = highbit(s); - if (h >= N) - quit "Too-long string for mkset"; - m = quo(h + 1, 8, 1); - return obj set = {head(s, m)}; + if (!isstr(s)) + quit "Non-string argument for mkset"; + h = highbit(s); + if (h >= N) + quit "Too-long string for mkset"; + m = quo(h + 1, 8, 1); + return obj set = {head(s, m)}; } define primes(a,b) { - local i, s, m; + local i, s, m; - if (isnull(b)) { - if (isnull(a)) { - a = 0; - b = N - 1; - } - else b = 0; - } + if (isnull(b)) { + if (isnull(a)) { + a = 0; + b = N - 1; + } + else b = 0; + } - if (!isint(a) || !isint(b)) - quit "Non-integer argument for primes"; - if (a > b) - swap(a,b); - if (b < 0 || a >= N) - return empty(); - a = max(a, 0); - b = min(b, N-1); - s = M * char(0); - for (i = a; i <= b; i++) - if (isprime(i)) - setbit(s, i); - return mkset(s); + if (!isint(a) || !isint(b)) + quit "Non-integer argument for primes"; + if (a > b) + swap(a,b); + if (b < 0 || a >= N) + return empty(); + a = max(a, 0); + b = min(b, N-1); + s = M * char(0); + for (i = a; i <= b; i++) + if (isprime(i)) + setbit(s, i); + return mkset(s); } define set_max(a) = highbit(a.s); @@ -261,56 +261,56 @@ define set_not(a) = !a.s; define set_cmp(a,b) { - if (isset(a) && isset(b)) - return a.s != b.s; - return 1; + if (isset(a) && isset(b)) + return a.s != b.s; + return 1; } define set_rel(a,b) { - local c; + local c; - if (a == b) - return 0; - if (isset(a)) { - if (isset(b)) { - c = a & b; - if (c == a) - return -1; - if (c == b) - return 1; - return; - } - if (!isint(b)) - return set_rel(a, set(b)); - } - if (isint(a)) - return set_rel(set(a), b); + if (a == b) + return 0; + if (isset(a)) { + if (isset(b)) { + c = a & b; + if (c == a) + return -1; + if (c == b) + return 1; + return; + } + if (!isint(b)) + return set_rel(a, set(b)); + } + if (isint(a)) + return set_rel(set(a), b); } define set_or(a, b) { - if (isset(a)) { - if (isset(b)) - return obj set = {a.s | b.s}; - if (isint(b)) - return a | set(b); - } - if (isint(a)) - return set(a) | b; - return newerror("Bad argument for set_or"); + if (isset(a)) { + if (isset(b)) + return obj set = {a.s | b.s}; + if (isint(b)) + return a | set(b); + } + if (isint(a)) + return set(a) | b; + return newerror("Bad argument for set_or"); } define set_and(a, b) { - if (isint(a)) - return set(a) & b; - if (isint(b)) - return a & set(b); - if (!isset(a) || !isset(b)) - return newerror("Bad argument for set_and"); - return mkset(a.s & b.s); + if (isint(a)) + return set(a) & b; + if (isint(b)) + return a & set(b); + if (!isset(a) || !isset(b)) + return newerror("Bad argument for set_and"); + return mkset(a.s & b.s); } @@ -318,295 +318,295 @@ define set_comp(a) = full() \ a; define set_setminus(a,b) { - if (isint(a)) - return set(a) \ b; - if (isint(b)) - return a \ set(b); - if (!isset(a) || !isset(b)) - return newerror("Bad argument for set_setminus"); - return mkset(a.s \ b.s); + if (isint(a)) + return set(a) \ b; + if (isint(b)) + return a \ set(b); + if (!isset(a) || !isset(b)) + return newerror("Bad argument for set_setminus"); + return mkset(a.s \ b.s); } define set_xor(a,b) { - if (isint(a)) - return set(a) ~ b; - if (isint(b)) - return a ~ set(b); - if (!isset(a) || !isset(b)) - return newerror("Bad argument for set_xor"); - return mkset(a.s ~ b.s); + if (isint(a)) + return set(a) ~ b; + if (isint(b)) + return a ~ set(b); + if (!isset(a) || !isset(b)) + return newerror("Bad argument for set_xor"); + return mkset(a.s ~ b.s); } define set_content(a) = #a.s; define set_add(a, b) { - local s, i, j, m, n; + local s, i, j, m, n; - if (isint(a)) - return set(a) + b; - if (isint(b)) - return a + set(b); - if (!isset(a) || !isset(b)) - return newerror("Bad argument for set_add"); - if (!a || !b) - return empty(); - m = highbit(a.s); - n = highbit(b.s); - s = M * char(0); - for (i = 0; i <= m; i++) - if (isin(a, i)) - for (j = 0; j <= n && i + j < N; j++) - if (isin(b, j)) - setbit(s, i + j); - return mkset(s); + if (isint(a)) + return set(a) + b; + if (isint(b)) + return a + set(b); + if (!isset(a) || !isset(b)) + return newerror("Bad argument for set_add"); + if (!a || !b) + return empty(); + m = highbit(a.s); + n = highbit(b.s); + s = M * char(0); + for (i = 0; i <= m; i++) + if (isin(a, i)) + for (j = 0; j <= n && i + j < N; j++) + if (isin(b, j)) + setbit(s, i + j); + return mkset(s); } define set_sub(a,b) { - local s, i, j, m, n; + local s, i, j, m, n; - if (isint(b)) - return a - set(b); - if (isint(a)) - return set(a) - b; - if (isset(a) && isset(b)) { - if (!a || !b) - return empty(); - m = highbit(a.s); - n = highbit(b.s); - s = M * char(0); - for (i = 0; i <= m; i++) - if (isin(a, i)) - for (j = 0; j <= n && j <= i; j++) - if (isin(b, j)) - setbit(s, i - j); - return mkset(s); - } - return newerror("Bad argument for set_sub"); + if (isint(b)) + return a - set(b); + if (isint(a)) + return set(a) - b; + if (isset(a) && isset(b)) { + if (!a || !b) + return empty(); + m = highbit(a.s); + n = highbit(b.s); + s = M * char(0); + for (i = 0; i <= m; i++) + if (isin(a, i)) + for (j = 0; j <= n && j <= i; j++) + if (isin(b, j)) + setbit(s, i - j); + return mkset(s); + } + return newerror("Bad argument for set_sub"); } define set_mul(a, b) { - local s, i, j, m, n; + local s, i, j, m, n; - if (isset(a)) { - s = M * char(0); - m = highbit(a.s); - if (isset(b)) { - if (!a || !b) - return empty(); - n = highbit(b.s); - for (i = 0; i <= m; ++i) - if (isin(a, i)) - for (j = 1; j <= n && i * j < N; ++j) - if (isin(b, j)) - setbit(s, i * j); - return mkset(s); - } - if (isint(b)) { - if (b == 0) { - if (a) - return set(0); - return empty(); - } - s = M * char(0); - for (i = 0; i <= m && b * i < N; ++i) - if (isin(a, i)) - setbit(s, b * i); - return mkset(s); - } - } - if (isint(a)) - return b * a; - return newerror("Bad argument for set_mul"); + if (isset(a)) { + s = M * char(0); + m = highbit(a.s); + if (isset(b)) { + if (!a || !b) + return empty(); + n = highbit(b.s); + for (i = 0; i <= m; ++i) + if (isin(a, i)) + for (j = 1; j <= n && i * j < N; ++j) + if (isin(b, j)) + setbit(s, i * j); + return mkset(s); + } + if (isint(b)) { + if (b == 0) { + if (a) + return set(0); + return empty(); + } + s = M * char(0); + for (i = 0; i <= m && b * i < N; ++i) + if (isin(a, i)) + setbit(s, b * i); + return mkset(s); + } + } + if (isint(a)) + return b * a; + return newerror("Bad argument for set_mul"); } define set_square(a) { - local s, i, m; + local s, i, m; - s = M * char(0); - m = highbit(a.s); - for (i = 0; i <= m && i^2 < N; ++i) - if (bit(a.s, i)) - setbit(s, i^2); - return mkset(s); + s = M * char(0); + m = highbit(a.s); + for (i = 0; i <= m && i^2 < N; ++i) + if (bit(a.s, i)) + setbit(s, i^2); + return mkset(s); } define set_pow(a, n) { - local s, i, m; + local s, i, m; - if (!isint(n) || n < 0) - quit "Bad exponent for set_power"; - s = M * char(0); - m = highbit(a.s); - for (i = 0; i <= m && i^n < N; ++i) - if (bit(a.s, i)) - setbit(s, i^n); - return mkset(s); + if (!isint(n) || n < 0) + quit "Bad exponent for set_power"; + s = M * char(0); + m = highbit(a.s); + for (i = 0; i <= m && i^n < N; ++i) + if (bit(a.s, i)) + setbit(s, i^n); + return mkset(s); } define set_sum(a) { - local v, m, i; + local v, m, i; - v = 0; - m = highbit(a.s); - for (i = 0; i <= m; ++i) - if (bit(a.s, i)) - v += i; - return v; + v = 0; + m = highbit(a.s); + for (i = 0; i <= m; ++i) + if (bit(a.s, i)) + v += i; + return v; } define set_plus(a) = set_sum(a); define interval(a, b) { - local i, j, s; - static tail = "\0\1\3\7\17\37\77\177\377"; + local i, j, s; + static tail = "\0\1\3\7\17\37\77\177\377"; - if (!isint(a) || !isint(b)) - quit "Non-integer argument for interval"; - if (a > b) - swap(a, b); - if (b < 0 || a >= N) - return empty(); - a = max(a, 0); - b = min(b, N-1); - i = quo(a, 8, 0); - j = quo(b, 8, 0); - s = M * char(0); - if (i == j) { - s[i] = tail[b + 1 - 8 * i] \ tail[a - 8 * i]; - return mkset(s); - } - s[i] = ~tail[a - 8 * i]; - while (++i < j) - s[i] = -1; - s[j] = tail[b + 1 - 8 * j]; - return mkset(s); + if (!isint(a) || !isint(b)) + quit "Non-integer argument for interval"; + if (a > b) + swap(a, b); + if (b < 0 || a >= N) + return empty(); + a = max(a, 0); + b = min(b, N-1); + i = quo(a, 8, 0); + j = quo(b, 8, 0); + s = M * char(0); + if (i == j) { + s[i] = tail[b + 1 - 8 * i] \ tail[a - 8 * i]; + return mkset(s); + } + s[i] = ~tail[a - 8 * i]; + while (++i < j) + s[i] = -1; + s[j] = tail[b + 1 - 8 * j]; + return mkset(s); } define isinterval(a) { - local i, max, s; + local i, max, s; - if (!isset(a)) - quit "Non-set argument for isinterval"; + if (!isset(a)) + quit "Non-set argument for isinterval"; - s = a.s; - if (!s) - return 0; - for (i = lowbit(s) + 1, max = highbit(s); i < max; i++) - if (!bit(s, i)) - return 0; - return 1; + s = a.s; + if (!s) + return 0; + for (i = lowbit(s) + 1, max = highbit(s); i < max; i++) + if (!bit(s, i)) + return 0; + return 1; } define set_mod(a, b) { - local s, m, i, j; + local s, m, i, j; - if (isset(a) && isint(b)) { - s = M * char(0); - m = highbit(a.s); - for (i = 0; i <= m; i++) - if (bit(a.s, i)) - for (j = 0; j < N; j++) - if (meq(i, j, b)) - setbit(s, j); - return mkset(s); - } - return newerror("Bad argument for set_mod"); + if (isset(a) && isint(b)) { + s = M * char(0); + m = highbit(a.s); + for (i = 0; i <= m; i++) + if (bit(a.s, i)) + for (j = 0; j < N; j++) + if (meq(i, j, b)) + setbit(s, j); + return mkset(s); + } + return newerror("Bad argument for set_mod"); } define randset(n, a, b) { - local m, s, i; + local m, s, i; - if (isnull(a)) - a = 0; - if (isnull(b)) - b = N - 1; - if (!isint(n) || !isint(a) || !isint(b) || n < 0 || a < 0 || b < 0) - quit "Bad argument for randset"; - if (a > b) - swap(a, b); - m = b - a + 1; - if (n > m) - return newerror("Too many numbers specified for randset"); - if (2 * n > m) - return interval(a,b) \ randset(m - n, a, b); - ++b; - s = M * char(0); - while (n-- > 0) { - do - i = rand(a, b); - while - (bit(s, i)); - setbit(s, i); - } - return mkset(s); + if (isnull(a)) + a = 0; + if (isnull(b)) + b = N - 1; + if (!isint(n) || !isint(a) || !isint(b) || n < 0 || a < 0 || b < 0) + quit "Bad argument for randset"; + if (a > b) + swap(a, b); + m = b - a + 1; + if (n > m) + return newerror("Too many numbers specified for randset"); + if (2 * n > m) + return interval(a,b) \ randset(m - n, a, b); + ++b; + s = M * char(0); + while (n-- > 0) { + do + i = rand(a, b); + while + (bit(s, i)); + setbit(s, i); + } + return mkset(s); } define polyvals(L, A) { - local s, m, v, i; + local s, m, v, i; - if (!islist(L)) - quit "Non-list first argument for polyvals"; - if (!isset(A)) - quit "Non-set second argument for polyvals"; - m = highbit(A.s); - s = M * char(0); - for (i = 0; i <= m; i++) - if (bit(A.s, i)) { - v = poly(L,i); - if (v >> 0 && v < N) - setbit(s, v); - } - return mkset(s); + if (!islist(L)) + quit "Non-list first argument for polyvals"; + if (!isset(A)) + quit "Non-set second argument for polyvals"; + m = highbit(A.s); + s = M * char(0); + for (i = 0; i <= m; i++) + if (bit(A.s, i)) { + v = poly(L,i); + if (v >> 0 && v < N) + setbit(s, v); + } + return mkset(s); } define polyvals2(L, A, B) { - local s1, s2, s, m, n, i, j, v; + local s1, s2, s, m, n, i, j, v; - s1 = A.s; - s2 = B.s; - m = highbit(s1); - n = highbit(s2); - s = M * char(0); - for (i = 0; i <= m; i++) - if (bit(s1, i)) - for (j = 0; j <= n; j++) - if (bit(s2, j)) { - v = poly(L, i, j); - if (v >= 0 && v < N) - setbit(s, v); - } - return mkset(s); + s1 = A.s; + s2 = B.s; + m = highbit(s1); + n = highbit(s2); + s = M * char(0); + for (i = 0; i <= m; i++) + if (bit(s1, i)) + for (j = 0; j <= n; j++) + if (bit(s2, j)) { + v = poly(L, i, j); + if (v >= 0 && v < N) + setbit(s, v); + } + return mkset(s); } define set_print(a) { - local i, s, m; + local i, s, m; - s = a.s; - i = lowbit(s); - print "set(":; - if (i >= 0) { - print i:; - m = highbit(s); - while (++i <= m) - if (bit(s, i)) - print ",":i:; - } - print ")",; + s = a.s; + i = lowbit(s); + print "set(":; + if (i >= 0) { + print i:; + m = highbit(s); + while (++i <= m) + if (bit(s, i)) + print ",":i:; + } + print ")",; } -local N, M; /* End scope of static variables N, M */ +local N, M; /* End scope of static variables N, M */ diff --git a/cal/palindrome.cal b/cal/palindrome.cal index f0e3a66..0d2f549 100644 --- a/cal/palindrome.cal +++ b/cal/palindrome.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2021/11/06 14:35:37 - * File existed as early as: 2021 + * Under source code control: 2021/11/06 14:35:37 + * File existed as early as: 2021 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -30,23 +30,23 @@ * NOTE: We assume base 10 digits and place 1 is the units digit. * * given: - * val value to find a digit of - * place digit place + * val value to find a digit of + * place digit place * * returns: - * value (>= 0 and < 10) that is the place-th digit of val - * or 0 if place is not a digit of val + * value (>= 0 and < 10) that is the place-th digit of val + * or 0 if place is not a digit of val */ define digitof(val, place) { - local d; /* length of val in digits */ + local d; /* length of val in digits */ /* determine length */ d = digits(val); /* firewall - return 0 if digit place doesn't exist */ if (place < 1 || place > d) { - return 0; + return 0; } /* return the place-th digit of val as a single digit */ @@ -60,18 +60,18 @@ define digitof(val, place) * NOTE: We assume base 10 digits and place 1 is the units digit. * * given: - * d digits of a value - * place digit place + * d digits of a value + * place digit place * * returns: - * given palindrome val, the other digit paired with place - * or 0 if place is not a digit of val + * given palindrome val, the other digit paired with place + * or 0 if place is not a digit of val */ define copalplace(d, place) { /* firewall - return 0 if digit place doesn't exist */ if (d < 1 || place < 1 || place > d) { - return 0; + return 0; } /* return digit coplace */ @@ -85,18 +85,18 @@ define copalplace(d, place) * NOTE: We assume base 10 digits and place 1 is the units digit. * * NOTE: When the value has an odd number of digits, the upper half - * includes the middle digit. + * includes the middle digit. * * given: - * val a value + * val a value * * returns: - * the upper half digits of a value + * the upper half digits of a value */ define upperhalf(val) { - local d; /* length of val in digits */ - local halfd; /* length of upper hand of val */ + local d; /* length of val in digits */ + local halfd; /* length of upper hand of val */ /* determine length */ d = digits(val); @@ -113,16 +113,16 @@ define upperhalf(val) * NOTE: We assume base 10 digits and place 1 is the units digit. * * given: - * val a value + * val a value * * returns: - * val as a palindrome with lower half being reverse digits of val + * val as a palindrome with lower half being reverse digits of val */ define mkpal(val) { - local d; /* length of val in digits */ - local i; /* counter */ - local ret; /* palindrome being formed */ + local d; /* length of val in digits */ + local i; /* counter */ + local ret; /* palindrome being formed */ /* determine length */ d = digits(val); @@ -130,7 +130,7 @@ define mkpal(val) /* insert digits in reverse order at the bottom */ ret = val; for (i=0; i < d; ++i) { - ret = ret*10 + digit(val, i); + ret = ret*10 + digit(val, i); } return ret; } @@ -142,18 +142,18 @@ define mkpal(val) * NOTE: We assume base 10 digits and place 1 is the units digit. * * given: - * val a value - * digit the digit to put into the middle of the palindrome + * val a value + * digit the digit to put into the middle of the palindrome * * returns: - * val as a palindrome with lower half being reverse digits of val - * and digit as a middle digit + * val as a palindrome with lower half being reverse digits of val + * and digit as a middle digit */ define mkpalmiddigit(val, digit) { - local d; /* length of val in digits */ - local i; /* counter */ - local ret; /* palindrome being formed */ + local d; /* length of val in digits */ + local i; /* counter */ + local ret; /* palindrome being formed */ /* determine length */ d = digits(val); @@ -161,7 +161,7 @@ define mkpalmiddigit(val, digit) /* insert digits in reverse order at the bottom */ ret = val*10 + digit; for (i=0; i < d; ++i) { - ret = ret*10 + digit(val, i); + ret = ret*10 + digit(val, i); } return ret; } @@ -173,31 +173,31 @@ define mkpalmiddigit(val, digit) * NOTE: We assume base 10 digits and place 1 is the units digit. * * given: - * val a value + * val a value * * returns: - * 1 ==> val is a palindrome - * 0 ==> val is NOT a palindrome + * 1 ==> val is a palindrome + * 0 ==> val is NOT a palindrome */ define ispal(val) { - local half; /* upper half of digits of val */ - local digit; /* middle digit */ + local half; /* upper half of digits of val */ + local digit; /* middle digit */ /* case: val has an even number of digits */ if (iseven(digits(val))) { - /* test palindrome-ness */ - return (val == mkpal(upperhalf(val))); + /* test palindrome-ness */ + return (val == mkpal(upperhalf(val))); /* case: val can an odd number of digits */ } else { - /* test palindrome-ness */ - half = upperhalf(val); - digit = half % 10; - half //= 10; - return (val == mkpalmiddigit(half, digit)); + /* test palindrome-ness */ + half = upperhalf(val); + digit = half % 10; + half //= 10; + return (val == mkpalmiddigit(half, digit)); } } @@ -208,21 +208,21 @@ define ispal(val) * NOTE: We assume base 10 digits and place 1 is the units digit. * * given: - * pal a palindrome + * pal a palindrome * * returns: - * next palindrome > pal + * next palindrome > pal */ define palnextpal(pal) { - local paldigits; /* digits in pal */ - local half; /* upper half of newval */ - local newhalf; /* half+1 */ - local newpal; /* new palindrome */ + local paldigits; /* digits in pal */ + local half; /* upper half of newval */ + local newhalf; /* half+1 */ + local newpal; /* new palindrome */ /* case: negative palindrome */ if (pal < 0) { - return -(palprevpal(-pal)); + return -(palprevpal(-pal)); } /* @@ -244,19 +244,19 @@ define palnextpal(pal) */ paldigits = digits(pal); if (digits(newhalf) == digits(half)) { - /* no change in half digits: process as normal */ - if (iseven(paldigits)) { - newpal = mkpal(newhalf); - } else { - newpal = mkpalmiddigit(newhalf // 10, newhalf % 10); - } + /* no change in half digits: process as normal */ + if (iseven(paldigits)) { + newpal = mkpal(newhalf); + } else { + newpal = mkpalmiddigit(newhalf // 10, newhalf % 10); + } } else { - /* change in half digits: process as opposite */ - if (iseven(paldigits)) { - newpal = mkpalmiddigit(newhalf // 10, newhalf % 10); - } else { - newpal = mkpal(newhalf); - } + /* change in half digits: process as opposite */ + if (iseven(paldigits)) { + newpal = mkpalmiddigit(newhalf // 10, newhalf % 10); + } else { + newpal = mkpal(newhalf); + } } /* @@ -272,22 +272,22 @@ define palnextpal(pal) * NOTE: We assume base 10 digits and place 1 is the units digit. * * given: - * val a value + * val a value * * returns: - * next palindrome > val + * next palindrome > val */ define nextpal(val) { - local newval; /* val+1 */ - local newvaldigits; /* digits in newval */ - local half; /* upper half of newval */ - local pal; /* palindrome test value */ - local newpal; /* new palindrome */ + local newval; /* val+1 */ + local newvaldigits; /* digits in newval */ + local half; /* upper half of newval */ + local pal; /* palindrome test value */ + local newpal; /* new palindrome */ /* case: negative value */ if (val < 0) { - return -(prevpal(-val)); + return -(prevpal(-val)); } /* @@ -298,7 +298,7 @@ define nextpal(val) /* case: single digit palindrome */ if (newvaldigits < 2) { - return newval; + return newval; } /* @@ -314,16 +314,16 @@ define nextpal(val) * half may not or may include the middle digit. */ if (iseven(newvaldigits)) { - pal = mkpal(half); + pal = mkpal(half); } else { - pal = mkpalmiddigit(half // 10, half % 10); + pal = mkpalmiddigit(half // 10, half % 10); } /* * case: we found a larger palindrome, we are done */ if (pal > val) { - return pal; + return pal; } /* @@ -344,33 +344,33 @@ define nextpal(val) * NOTE: We assume base 10 digits and place 1 is the units digit. * * given: - * pal a palindrome + * pal a palindrome * * returns: - * previous palindrome < pal + * previous palindrome < pal */ define palprevpal(pal) { - local paldigits; /* digits in pal */ - local half; /* upper half of newval */ - local newhalf; /* half+1 */ - local newpal; /* new palindrome */ + local paldigits; /* digits in pal */ + local half; /* upper half of newval */ + local newhalf; /* half+1 */ + local newpal; /* new palindrome */ /* case: negative value */ if (pal < 0) { - return -(palnextpal(-pal)); + return -(palnextpal(-pal)); } /* case: single digit palindrome */ if (pal < 10) { - newpal = pal-1; - return newpal; + newpal = pal-1; + return newpal; } /* case: 10 or 11 */ if (pal < 12) { - newpal = 9; - return newpal; + newpal = 9; + return newpal; } /* @@ -392,19 +392,19 @@ define palprevpal(pal) */ paldigits = digits(pal); if (digits(newhalf) == digits(half)) { - /* no change in half digits: process as normal */ - if (iseven(paldigits)) { - newpal = mkpal(newhalf); - } else { - newpal = mkpalmiddigit(newhalf // 10, newhalf % 10); - } + /* no change in half digits: process as normal */ + if (iseven(paldigits)) { + newpal = mkpal(newhalf); + } else { + newpal = mkpalmiddigit(newhalf // 10, newhalf % 10); + } } else { - /* change in half digits: process as opposite */ - if (iseven(paldigits)) { - newpal = mkpalmiddigit(newhalf // 10, newhalf % 10); - } else { - newpal = mkpal(newhalf); - } + /* change in half digits: process as opposite */ + if (iseven(paldigits)) { + newpal = mkpalmiddigit(newhalf // 10, newhalf % 10); + } else { + newpal = mkpal(newhalf); + } } /* @@ -420,22 +420,22 @@ define palprevpal(pal) * NOTE: We assume base 10 digits and place 1 is the units digit. * * given: - * val a value + * val a value * * returns: - * previous palindrome < val + * previous palindrome < val */ define prevpal(val) { - local newval; /* val-1 */ - local newvaldigits; /* digits in newval */ - local half; /* upper half of newval */ - local pal; /* palindrome test value */ - local newpal; /* new palindrome */ + local newval; /* val-1 */ + local newvaldigits; /* digits in newval */ + local half; /* upper half of newval */ + local pal; /* palindrome test value */ + local newpal; /* new palindrome */ /* case: negative value */ if (val < 0) { - return -(nextpal(-val)); + return -(nextpal(-val)); } /* @@ -446,7 +446,7 @@ define prevpal(val) /* case: single digit palindrome */ if (newvaldigits < 2) { - return newval; + return newval; } /* @@ -462,16 +462,16 @@ define prevpal(val) * half may not or may include the middle digit. */ if (iseven(newvaldigits)) { - pal = mkpal(half); + pal = mkpal(half); } else { - pal = mkpalmiddigit(half // 10, half % 10); + pal = mkpalmiddigit(half // 10, half % 10); } /* * case: we found a smaller palindrome, we are done */ if (pal < val) { - return pal; + return pal; } /* @@ -492,15 +492,15 @@ define prevpal(val) * NOTE: We assume base 10 digits and place 1 is the units digit. * * given: - * val a value + * val a value * * returns: - * next palindrome (highly probable) prime > val + * next palindrome (highly probable) prime > val */ define nextprimepal(val) { - local pal; /* palindrome test value */ - local dpal; /* digits in pal */ + local pal; /* palindrome test value */ + local dpal; /* digits in pal */ /* * pre-start under the next palindrome @@ -512,45 +512,45 @@ define nextprimepal(val) */ do { - /* case: negative values and tiny values */ - if (pal < 2) { - return 2; - } + /* case: negative values and tiny values */ + if (pal < 2) { + return 2; + } - /* - * compute the next palindrome - */ - pal = palnextpal(pal); - dpal = digits(pal); + /* + * compute the next palindrome + */ + pal = palnextpal(pal); + dpal = digits(pal); - /* case: 11 is the only prime palindrome with even digit count */ - if (pal == 11) { - return 11; - } + /* case: 11 is the only prime palindrome with even digit count */ + if (pal == 11) { + return 11; + } - /* case: even number of digits and not 11 */ - if (iseven(dpal)) { + /* case: even number of digits and not 11 */ + if (iseven(dpal)) { - /* - * Except for 11 (which is handled above already), there are - * no prime palindrome with even digits. So we need to - * increase the digit count and work with that larger palindrome. - */ - pal = nextpal(10^dpal); - } + /* + * Except for 11 (which is handled above already), there are + * no prime palindrome with even digits. So we need to + * increase the digit count and work with that larger palindrome. + */ + pal = nextpal(10^dpal); + } - /* case: palindrome is even or ends in 5 */ - if (iseven(pal % 10) || (pal%10 == 10/2)) { + /* case: palindrome is even or ends in 5 */ + if (iseven(pal % 10) || (pal%10 == 10/2)) { - /* - * we need to increase the bottom and top digits - * so that we have a chance to be prime - */ - pal += (1 + 10^(dpal-1)); - } - if (config("resource_debug") & 0x8) { - print "DEBUG: nextprimepal:", pal; - } + /* + * we need to increase the bottom and top digits + * so that we have a chance to be prime + */ + pal += (1 + 10^(dpal-1)); + } + if (config("resource_debug") & 0x8) { + print "DEBUG: nextprimepal:", pal; + } } while (ptest(pal) == 0 && pal > 0); /* return palindrome that his (highly probable) prime or 0 */ @@ -564,15 +564,15 @@ define nextprimepal(val) * NOTE: We assume base 10 digits and place 1 is the units digit. * * given: - * val a value + * val a value * * returns: - * prev palindrome (highly probable) prime < val or 0 + * prev palindrome (highly probable) prime < val or 0 */ define prevprimepal(val) { - local pal; /* palindrome test value */ - local dpal; /* digits in pal */ + local pal; /* palindrome test value */ + local dpal; /* digits in pal */ /* * pre-start over the previous palindrome @@ -584,56 +584,56 @@ define prevprimepal(val) */ do { - /* - * case: single digit values are always palindromes - */ - if (val < 10) { - /* - * The prevcand() call will return 0 if there is no previous prime - * such as the case when val < 2. - */ - return prevcand(pal); - } + /* + * case: single digit values are always palindromes + */ + if (val < 10) { + /* + * The prevcand() call will return 0 if there is no previous prime + * such as the case when val < 2. + */ + return prevcand(pal); + } - /* - * compute the previous palindrome - */ - pal = palprevpal(pal); - dpal = digits(pal); + /* + * compute the previous palindrome + */ + pal = palprevpal(pal); + dpal = digits(pal); - /* case: 11 is the only prime palindrome with even digit count */ - if (pal == 11) { - return 11; - } + /* case: 11 is the only prime palindrome with even digit count */ + if (pal == 11) { + return 11; + } - /* case: 2 digit palindrome and not 11 */ - if (dpal == 2) { - return 7; - } + /* case: 2 digit palindrome and not 11 */ + if (dpal == 2) { + return 7; + } - /* case: even number of digits */ - if (iseven(dpal)) { + /* case: even number of digits */ + if (iseven(dpal)) { - /* - * Except for 11 (which is handled above already), there are - * no prime palindrome with even digits. So we need to - * decrease the digit count and work with that smaller palindrome. - */ - pal = prevpal(10^(dpal-1)); - } + /* + * Except for 11 (which is handled above already), there are + * no prime palindrome with even digits. So we need to + * decrease the digit count and work with that smaller palindrome. + */ + pal = prevpal(10^(dpal-1)); + } - /* case: palindrome is even or ends in 5 */ - if (iseven(pal % 10) || (pal%10 == 10/2)) { + /* case: palindrome is even or ends in 5 */ + if (iseven(pal % 10) || (pal%10 == 10/2)) { - /* - * we need to decrease the bottom and top digits - * so that we have a chance to be prime - */ - pal -= (1 + 10^(dpal-1)); - } - if (config("resource_debug") & 0x8) { - print "DEBUG: prevprimepal:", pal; - } + /* + * we need to decrease the bottom and top digits + * so that we have a chance to be prime + */ + pal -= (1 + 10^(dpal-1)); + } + if (config("resource_debug") & 0x8) { + print "DEBUG: prevprimepal:", pal; + } } while (ptest(pal) == 0 && pal > 0); /* return palindrome that his (highly probable) prime or 0 */ diff --git a/cal/pell.cal b/cal/pell.cal index 1011e9f..9583759 100644 --- a/cal/pell.cal +++ b/cal/pell.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:50:34 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:50:34 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -31,60 +31,60 @@ define pell(D) { - local X, Y; + local X, Y; - X = pellx(D); - if (isnull(X)) { - print "D=":D:" is square"; - return; - } - Y = isqrt((X^2 - 1) / D); - print X : "^2 - " : D : "*" : Y : "^2 = " : X^2 - D*Y^2; + X = pellx(D); + if (isnull(X)) { + print "D=":D:" is square"; + return; + } + Y = isqrt((X^2 - 1) / D); + print X : "^2 - " : D : "*" : Y : "^2 = " : X^2 - D*Y^2; } /* * Function to solve Pell's equation * Returns the solution X to: - * X^2 - D * Y^2 = 1 + * X^2 - D * Y^2 = 1 */ define pellx(D) { - local R, Rp, U, Up, V, Vp, A, T, Q1, Q2, n; - local mat ans[2,2]; - local mat tmp[2,2]; + local R, Rp, U, Up, V, Vp, A, T, Q1, Q2, n; + local mat ans[2,2]; + local mat tmp[2,2]; - R = isqrt(D); - Vp = D - R^2; - if (Vp == 0) - return; - Rp = R + R; - U = Rp; - Up = U; - V = 1; - A = 0; - n = 0; - ans[0,0] = 1; - ans[1,1] = 1; - tmp[0,1] = 1; - tmp[1,0] = 1; - do { - T = V; - V = A * (Up - U) + Vp; - Vp = T; - A = U // V; - Up = U; - U = Rp - U % V; - tmp[0,0] = A; - ans *= tmp; - n++; - } while (A != Rp); - Q2 = ans[[1]]; - Q1 = isqrt(Q2^2 * D + 1); - if (isodd(n)) { - T = Q1^2 + D * Q2^2; - Q2 = Q1 * Q2 * 2; - Q1 = T; - } - return Q1; + R = isqrt(D); + Vp = D - R^2; + if (Vp == 0) + return; + Rp = R + R; + U = Rp; + Up = U; + V = 1; + A = 0; + n = 0; + ans[0,0] = 1; + ans[1,1] = 1; + tmp[0,1] = 1; + tmp[1,0] = 1; + do { + T = V; + V = A * (Up - U) + Vp; + Vp = T; + A = U // V; + Up = U; + U = Rp - U % V; + tmp[0,0] = A; + ans *= tmp; + n++; + } while (A != Rp); + Q2 = ans[[1]]; + Q1 = isqrt(Q2^2 * D + 1); + if (isodd(n)) { + T = Q1^2 + D * Q2^2; + Q2 = Q1 * Q2 * 2; + Q1 = T; + } + return Q1; } diff --git a/cal/pi.cal b/cal/pi.cal index 0b9ce88..4a357aa 100644 --- a/cal/pi.cal +++ b/cal/pi.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1991/05/22 21:56:37 - * File existed as early as: 1991 + * Under source code control: 1991/05/22 21:56:37 + * File existed as early as: 1991 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -31,43 +31,43 @@ define qpi(epsilon) { - local niter, yn, ym, tm, an, am, t, tn, sqrt2, epsilon2, count, digits; - local bits, bits2; + local niter, yn, ym, tm, an, am, t, tn, sqrt2, epsilon2, count, digits; + local bits, bits2; - if (isnull(epsilon)) - epsilon = epsilon(); - digits = digits(1/epsilon); - if (digits <= 8) { niter = 1; epsilon = 1e-8; } - else if (digits <= 40) { niter = 2; epsilon = 1e-40; } - else if (digits <= 170) { niter = 3; epsilon = 1e-170; } - else if (digits <= 693) { niter = 4; epsilon = 1e-693; } - else { - niter = 4; - t = 693; - while (t < digits) { - ++niter; - t *= 4; - } - } - epsilon2 = epsilon/(digits/10 + 1); - digits = digits(1/epsilon2); - sqrt2 = sqrt(2, epsilon2); - bits = abs(ilog2(epsilon)) + 1; - bits2 = abs(ilog2(epsilon2)) + 1; - yn = sqrt2 - 1; - an = 6 - 4 * sqrt2; - tn = 2; - for (count = 0; count < niter; ++count) { - ym = yn; - am = an; - tn *= 4; - t = sqrt(sqrt(1-ym^4, epsilon2), epsilon2); - yn = (1-t)/(1+t); - an = (1+yn)^4*am-tn*yn*(1+yn+yn^2); - yn = bround(yn, bits2); - an = bround(an, bits2); - } - return (bround(1/an, bits)); + if (isnull(epsilon)) + epsilon = epsilon(); + digits = digits(1/epsilon); + if (digits <= 8) { niter = 1; epsilon = 1e-8; } + else if (digits <= 40) { niter = 2; epsilon = 1e-40; } + else if (digits <= 170) { niter = 3; epsilon = 1e-170; } + else if (digits <= 693) { niter = 4; epsilon = 1e-693; } + else { + niter = 4; + t = 693; + while (t < digits) { + ++niter; + t *= 4; + } + } + epsilon2 = epsilon/(digits/10 + 1); + digits = digits(1/epsilon2); + sqrt2 = sqrt(2, epsilon2); + bits = abs(ilog2(epsilon)) + 1; + bits2 = abs(ilog2(epsilon2)) + 1; + yn = sqrt2 - 1; + an = 6 - 4 * sqrt2; + tn = 2; + for (count = 0; count < niter; ++count) { + ym = yn; + am = an; + tn *= 4; + t = sqrt(sqrt(1-ym^4, epsilon2), epsilon2); + yn = (1-t)/(1+t); + an = (1+yn)^4*am-tn*yn*(1+yn+yn^2); + yn = bround(yn, bits2); + an = bround(an, bits2); + } + return (bround(1/an, bits)); } @@ -86,58 +86,58 @@ define qpi(epsilon) define piforever() { - local k = 2; - local a = 4; - local b = 1; - local a1 = 12; - local b1 = 4; - local a2, b2, p, q, d, d1; - local stdout = files(1); - local first = 1, row = -1, col = 0; + local k = 2; + local a = 4; + local b = 1; + local a1 = 12; + local b1 = 4; + local a2, b2, p, q, d, d1; + local stdout = files(1); + local first = 1, row = -1, col = 0; - while (1) { - /* - * Next approximation - */ - p = k * k; - q = k + ++k; + while (1) { + /* + * Next approximation + */ + p = k * k; + q = k + ++k; - a2 = a; - b2 = b; + a2 = a; + b2 = b; - a = a1; - a1 = p * a2 + q * a1; - b = b1; - b1 = p * b2 + q * b1; + a = a1; + a1 = p * a2 + q * a1; + b = b1; + b1 = p * b2 + q * b1; - /* - * Print common digits - */ - d = a // b; - d1 = a1 // b1; + /* + * Print common digits + */ + d = a // b; + d1 = a1 // b1; - while (d == d1) { - if (first) { - printf("%d.", d); - first = 0; - } else { - if (!(col % 50)) { - printf("\n"); - col = 0; - if (!(++row % 20)) { - printf("\n"); - row = 0; - } - } - printf("%d", d); - if (!(++col % 10)) - printf(" "); - } - a = 10 * (a % b); - a1 = 10 * (a1 % b1); - d = a // b; - d1 = a1 // b1; - } - fflush(stdout); - } + while (d == d1) { + if (first) { + printf("%d.", d); + first = 0; + } else { + if (!(col % 50)) { + printf("\n"); + col = 0; + if (!(++row % 20)) { + printf("\n"); + row = 0; + } + } + printf("%d", d); + if (!(++col % 10)) + printf(" "); + } + a = 10 * (a % b); + a1 = 10 * (a1 % b1); + d = a // b; + d1 = a1 // b1; + } + fflush(stdout); + } } diff --git a/cal/pix.cal b/cal/pix.cal index c002dc0..540fef7 100644 --- a/cal/pix.cal +++ b/cal/pix.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,51 +17,51 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1996/07/09 03:14:14 - * File existed as early as: 1996 + * Under source code control: 1996/07/09 03:14:14 + * File existed as early as: 1996 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * Here is an iterative method of finding the number of primes less than - * or equal to a given number. This method is from "Computer Recreations" + * or equal to a given number. This method is from "Computer Recreations" * June 1996 issue of Scientific American. * * NOTE: For reasonable values of x, the builtin function pix(x) is - * much faster. This code is provided because the method - * is interesting. + * much faster. This code is provided because the method + * is interesting. */ define pi_of_x(x) { - local An; /* A(n) */ - local An1; /* A(n-1) */ - local An2; /* A(n-2) */ - local An3; /* A(n-3) */ - local primes; /* number of primes found */ - local n; /* loop counter */ + local An; /* A(n) */ + local An1; /* A(n-1) */ + local An2; /* A(n-2) */ + local An3; /* A(n-3) */ + local primes; /* number of primes found */ + local n; /* loop counter */ - /* - * setup - */ - An1 = 2; - An2 = 0; - An3 = 3; - primes = 1; + /* + * setup + */ + An1 = 2; + An2 = 0; + An3 = 3; + primes = 1; - /* - * main A(n+1)=A(n-1)+A(n-2) sequence loop - */ - for (n = 3; n < x; ++n) { - An = An2 + An3; - An3 = An2; - An2 = An1; - An1 = An; - if (An % n == 0) - ++primes; - } - return primes; + /* + * main A(n+1)=A(n-1)+A(n-2) sequence loop + */ + for (n = 3; n < x; ++n) { + An = An2 + An3; + An3 = An2; + An2 = An1; + An1 = An; + if (An % n == 0) + ++primes; + } + return primes; } diff --git a/cal/pollard.cal b/cal/pollard.cal index 68f1462..9270d61 100644 --- a/cal/pollard.cal +++ b/cal/pollard.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,32 +17,32 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1991/05/22 21:56:37 - * File existed as early as: 1991 + * Under source code control: 1991/05/22 21:56:37 + * File existed as early as: 1991 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ define pfactor(N, B, ai, af) { - local a, k, i, d; + local a, k, i, d; - if (isnull(B)) - B = 1000; - if (isnull(ai)) - ai = 2; - if (isnull(af)) - af = ai + 20; - k = lcmfact(B); - d = lfactor(N, B); - if (d > 1) - return d; - for (a = ai; a <= af; a++) { - i = pmod(a, k, N); - d = gcd(i - 1, N); - if ((d > 1) && (d != N)) - return d; - } - return 1; + if (isnull(B)) + B = 1000; + if (isnull(ai)) + ai = 2; + if (isnull(af)) + af = ai + 20; + k = lcmfact(B); + d = lfactor(N, B); + if (d > 1) + return d; + for (a = ai; a <= af; a++) { + i = pmod(a, k, N); + d = gcd(i - 1, N); + if ((d > 1) && (d != N)) + return d; + } + return 1; } diff --git a/cal/poly.cal b/cal/poly.cal index f4029ac..c7d880f 100644 --- a/cal/poly.cal +++ b/cal/poly.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,420 +17,420 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:50:35 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:50:35 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * A collection of functions designed for calculations involving - * polynomials in one variable (by Ernest W. Bowen). + * polynomials in one variable (by Ernest W. Bowen). * * On starting the program the independent variable has identifier x - * and name "x", i.e. the user can refer to it as x, the - * computer displays it as "x". The name of the independent - * variable is stored as varname, so, for example, varname = "alpha" - * will change its name to "alpha". At any time, the independent - * variable has only one name. For some purposes, a name like - * "sin(t)" or "(a + b)" or "\lambda" might be useful; - * names like "*" or "-27" are legal but might give expressions - * that are difficult to interpret. + * and name "x", i.e. the user can refer to it as x, the + * computer displays it as "x". The name of the independent + * variable is stored as varname, so, for example, varname = "alpha" + * will change its name to "alpha". At any time, the independent + * variable has only one name. For some purposes, a name like + * "sin(t)" or "(a + b)" or "\lambda" might be useful; + * names like "*" or "-27" are legal but might give expressions + * that are difficult to interpret. * * Polynomial expressions may be constructed from numbers and the - * independent variable and other polynomials by the algebraic - * operations +, -, *, ^, and if the result is a polynomial /. - * The operations // and % are defined to have the quotient and - * remainder meanings as usually defined for polynomials. + * independent variable and other polynomials by the algebraic + * operations +, -, *, ^, and if the result is a polynomial /. + * The operations // and % are defined to have the quotient and + * remainder meanings as usually defined for polynomials. * * When polynomials are assigned to identifiers, it is convenient to - * think of the polynomials as values. For example, p = (x - 1)^2 - * assigns to p a polynomial value in the same way as q = (7 - 1)^2 - * would assign to q a number value. As with number expressions - * involving operations, the expression used to define the - * polynomial is usually lost; in the above example, the normal - * computer display for p will be x^2 - 2x + 1. Different - * identifiers may of course have the same polynomial value. + * think of the polynomials as values. For example, p = (x - 1)^2 + * assigns to p a polynomial value in the same way as q = (7 - 1)^2 + * would assign to q a number value. As with number expressions + * involving operations, the expression used to define the + * polynomial is usually lost; in the above example, the normal + * computer display for p will be x^2 - 2x + 1. Different + * identifiers may of course have the same polynomial value. * * The polynomial we think of as a_0 + a_1 * x + ... + a_n * x^n, - * for number coefficients a_0, a_1, ... a_n may also be - * constructed as pol(a_0, a_1, ..., a_n). Note that here the - * coefficients are to be in ascending power order. The independent - * variable is pol(0,1), so to use t, say, as an identifier for - * this, one may assign t = pol(0,1). To simultaneously specify - * an identifier and a name for the independent variable, there is - * the instruction var, used as in identifier = var(name). For - * example, to use "t" in the way "x" is initially, one may give - * the instruction t = var("t"). + * for number coefficients a_0, a_1, ... a_n may also be + * constructed as pol(a_0, a_1, ..., a_n). Note that here the + * coefficients are to be in ascending power order. The independent + * variable is pol(0,1), so to use t, say, as an identifier for + * this, one may assign t = pol(0,1). To simultaneously specify + * an identifier and a name for the independent variable, there is + * the instruction var, used as in identifier = var(name). For + * example, to use "t" in the way "x" is initially, one may give + * the instruction t = var("t"). * * There are four parameters pmode, order, iod and ims for controlling - * the format in which polynomials are displayed. - * The parameter pmode may have values "alg" or "list": the - * former gives a display as an algebraic formula, while - * the latter only lists the coefficients. Whether the terms or - * coefficients are in ascending or descending power order is - * controlled by order being "up" or "down". If the - * parameter iod (for integer-only display), the polynomial - * is expressed in terms of a polynomial whose coefficients are - * integers with gcd = 1, the leading coefficient having positive - * real part, with where necessary a leading multiplying integer, - * a Gaussian integer multiplier if the coefficients are complex - * with a common complex factor, and a trailing divisor integer. - * If a non-zero value is assigned to the parameter ims, - * multiplication signs will be inserted where appropriate; - * this may be useful if the expression is to be copied to a - * program or a string to be used with eval. + * the format in which polynomials are displayed. + * The parameter pmode may have values "alg" or "list": the + * former gives a display as an algebraic formula, while + * the latter only lists the coefficients. Whether the terms or + * coefficients are in ascending or descending power order is + * controlled by order being "up" or "down". If the + * parameter iod (for integer-only display), the polynomial + * is expressed in terms of a polynomial whose coefficients are + * integers with gcd = 1, the leading coefficient having positive + * real part, with where necessary a leading multiplying integer, + * a Gaussian integer multiplier if the coefficients are complex + * with a common complex factor, and a trailing divisor integer. + * If a non-zero value is assigned to the parameter ims, + * multiplication signs will be inserted where appropriate; + * this may be useful if the expression is to be copied to a + * program or a string to be used with eval. * * For evaluation of polynomials the standard function is ev(p, t). - * If p is a polynomial and t anything for which the relevant - * operations can be performed, this returns the value of p - * at t. The function ev(p, t) also accepts lists or matrices - * as possible values for p; each element of p is then evaluated - * at t. For other p, t is ignored and the value of p is returned. - * If an identifier, a, say, is used for the polynomial, list or - * matrix p, the definition - * define a(t) = ev(a, t); - * permits a(t) to be used for the value of a at t as if the - * polynomial, list or matrix were a function. For example, - * if a = 1 + x^2, a(2) will return the value 5, just as if - * define a(t) = 1 + t^2; - * had been used. However, when the polynomial definition is - * used, changing the polynomial a will change a(t) to the value - * of the new polynomial at t. For example, - * after - * L = list(x, x^2, x^3, x^4); - define a(t) = ev(a, t); - * the loop - * for (i = 0; i < 4; i++) - * print ev(L[[i]], 5); - * may be replaced by - * for (i = 0; i < 4; i++) { - * a = L[[i]]; - * print a(5); - * } + * If p is a polynomial and t anything for which the relevant + * operations can be performed, this returns the value of p + * at t. The function ev(p, t) also accepts lists or matrices + * as possible values for p; each element of p is then evaluated + * at t. For other p, t is ignored and the value of p is returned. + * If an identifier, a, say, is used for the polynomial, list or + * matrix p, the definition + * define a(t) = ev(a, t); + * permits a(t) to be used for the value of a at t as if the + * polynomial, list or matrix were a function. For example, + * if a = 1 + x^2, a(2) will return the value 5, just as if + * define a(t) = 1 + t^2; + * had been used. However, when the polynomial definition is + * used, changing the polynomial a will change a(t) to the value + * of the new polynomial at t. For example, + * after + * L = list(x, x^2, x^3, x^4); + define a(t) = ev(a, t); + * the loop + * for (i = 0; i < 4; i++) + * print ev(L[[i]], 5); + * may be replaced by + * for (i = 0; i < 4; i++) { + * a = L[[i]]; + * print a(5); + * } * * Matrices with polynomial elements may be added, subtracted and - * multiplied as long as the usual rules for compatibility are - * observed. Also, matrices may be multiplied by polynomials, - * i.e. if p is a polynomial and A a matrix whose elements - * may be numbers or polynomials, p * A returns the matrix of - * the same shape as A with each element multiplied by p. - * Square matrices may also be 'substituted for the variable' in - * polynomials, e.g. if A is an m x m matrix, and - * p = x^2 + 3 * x + 2, ev(p, A) returns the same as - * A^2 + 3 * A + 2 * I, where I is the unit m x m matrix. + * multiplied as long as the usual rules for compatibility are + * observed. Also, matrices may be multiplied by polynomials, + * i.e. if p is a polynomial and A a matrix whose elements + * may be numbers or polynomials, p * A returns the matrix of + * the same shape as A with each element multiplied by p. + * Square matrices may also be 'substituted for the variable' in + * polynomials, e.g. if A is an m x m matrix, and + * p = x^2 + 3 * x + 2, ev(p, A) returns the same as + * A^2 + 3 * A + 2 * I, where I is the unit m x m matrix. * * On starting this program, three demonstration polynomials a, b, c - * have been defined. The functions a(t), b(t), c(t) corresponding - * to a, b, c, and x(t) corresponding to x, have also been - * defined, so the usual function notation can be used for - * evaluations of a, b, c and x. For x, as long as x identifies - * the independent variable, x(t) should return the value of t, - * i.e. it acts as an identity function. + * have been defined. The functions a(t), b(t), c(t) corresponding + * to a, b, c, and x(t) corresponding to x, have also been + * defined, so the usual function notation can be used for + * evaluations of a, b, c and x. For x, as long as x identifies + * the independent variable, x(t) should return the value of t, + * i.e. it acts as an identity function. * * Functions defined include: * - * monic(a) returns the monic multiple of a, i.e., if a != 0, - * the multiple of a with leading coefficient 1 - * conj(a) returns the complex conjugate of a - * ispmult(a,b) returns 1 or 0 according as a is or is not - * a polynomial multiple of b - * pgcd(a,b) returns the monic gcd of a and b - * pfgcd(a,b) returns a list of three polynomials (g, u, v) - * where g = pgcd(a,b) and g = u * a + v * b. - * plcm(a,b) returns the monic lcm of a and b + * monic(a) returns the monic multiple of a, i.e., if a != 0, + * the multiple of a with leading coefficient 1 + * conj(a) returns the complex conjugate of a + * ispmult(a,b) returns 1 or 0 according as a is or is not + * a polynomial multiple of b + * pgcd(a,b) returns the monic gcd of a and b + * pfgcd(a,b) returns a list of three polynomials (g, u, v) + * where g = pgcd(a,b) and g = u * a + v * b. + * plcm(a,b) returns the monic lcm of a and b * - * interp(X,Y,t) returns the value at t of the polynomial given - * by Newtonian divided difference interpolation, where - * X is a list of x-values, Y a list of corresponding - * y-values. If t is omitted, the interpolating - * polynomial is returned. A y-value may be replaced by - * list (y, y_1, y_2, ...), where y_1, y_2, ... are - * the reduced derivatives at the corresponding x; - * i.e. y_r is the r-th derivative divided by fact(r). - * mdet(A) returns the determinant of the square matrix A, - * computed by an algorithm that does not require - * inverses; the built-in det function usually fails - * for matrices with polynomial elements. - * D(a,n) returns the n-th derivative of a; if n is omitted, - * the first derivative is returned. + * interp(X,Y,t) returns the value at t of the polynomial given + * by Newtonian divided difference interpolation, where + * X is a list of x-values, Y a list of corresponding + * y-values. If t is omitted, the interpolating + * polynomial is returned. A y-value may be replaced by + * list (y, y_1, y_2, ...), where y_1, y_2, ... are + * the reduced derivatives at the corresponding x; + * i.e. y_r is the r-th derivative divided by fact(r). + * mdet(A) returns the determinant of the square matrix A, + * computed by an algorithm that does not require + * inverses; the built-in det function usually fails + * for matrices with polynomial elements. + * D(a,n) returns the n-th derivative of a; if n is omitted, + * the first derivative is returned. * * A first-time user can see what the initially defined polynomials - * a, b and c are, and experiment with the algebraic operations - * and other functions that have been defined by giving - * instructions like: - * a - * b - * c - * (x^2 + 1) * a - * a^27 - * a * b - * a % b - * a // b - * a(1 + x) - * a(b) - * conj(c) - * g = pgcd(a, b) - * g - * a / g - * D(a) - * mat A[2,2] = {1 + x, x^2, 3, 4*x} - * mdet(A) - * D(A) - * A^2 - * define A(t) = ev(A, t) - * A(2) - * A(1 + x) - * define L(t) = ev(L, t) - * L = list(x, x^2, x^3, x^4) - * L(5) - * a(L) - * interp(list(0,1,2,3), list(2,3,5,7)) - * interp(list(0,1,2), list(0,list(1,0),2)) + * a, b and c are, and experiment with the algebraic operations + * and other functions that have been defined by giving + * instructions like: + * a + * b + * c + * (x^2 + 1) * a + * a^27 + * a * b + * a % b + * a // b + * a(1 + x) + * a(b) + * conj(c) + * g = pgcd(a, b) + * g + * a / g + * D(a) + * mat A[2,2] = {1 + x, x^2, 3, 4*x} + * mdet(A) + * D(A) + * A^2 + * define A(t) = ev(A, t) + * A(2) + * A(1 + x) + * define L(t) = ev(L, t) + * L = list(x, x^2, x^3, x^4) + * L(5) + * a(L) + * interp(list(0,1,2,3), list(2,3,5,7)) + * interp(list(0,1,2), list(0,list(1,0),2)) * * One check on some of the functions is provided by the Cayley-Hamilton - * theorem: if A is any m x m matrix and I the m x m unit matrix, - * and x is pol(0,1), - * ev(mdet(x * I - A), A) - * should return the zero m x m matrix. + * theorem: if A is any m x m matrix and I the m x m unit matrix, + * and x is pol(0,1), + * ev(mdet(x * I - A), A) + * should return the zero m x m matrix. */ obj poly {p}; define pol() { - local u,i,s; - obj poly u; - s = list(); - for (i=1; i<= param(0); i++) append (s,param(i)); - i=size(s) -1; - while (i>=0 && s[[i]]==0) {i--; remove(s)} - u.p = s; - return u; + local u,i,s; + obj poly u; + s = list(); + for (i=1; i<= param(0); i++) append (s,param(i)); + i=size(s) -1; + while (i>=0 && s[[i]]==0) {i--; remove(s)} + u.p = s; + return u; } define ispoly(a) { - local y; - obj poly y; - return istype(a,y); + local y; + obj poly y; + return istype(a,y); } define findlist(a) { - if (ispoly(a)) return a.p; - if (a) return list(a); - return list(); + if (ispoly(a)) return a.p; + if (a) return list(a); + return list(); } -pmode = "alg"; /* The other acceptable pmode is "list" */ -ims = 0; /* To be non-zero if multiplication signs to be inserted */ -iod = 0; /* To be non-zero for integer-only display */ -order = "down" /* Determines order in which coefficients displayed */ +pmode = "alg"; /* The other acceptable pmode is "list" */ +ims = 0; /* To be non-zero if multiplication signs to be inserted */ +iod = 0; /* To be non-zero for integer-only display */ +order = "down" /* Determines order in which coefficients displayed */ define poly_print(a) { - local f, g, t; - if (size(a.p) == 0) { - print 0:; - return; - } - if (iod) { - g = gcdcoeffs(a); - t = a.p[[size(a.p) - 1]] / g; - if (re(t) < 0) { t = -t; g = -g;} - if (g != 1) { - if (!isreal(t)) { - if (im(t) > re(t)) g *= 1i; - else if (im(t) <= -re(t)) g *= -1i; - } - if (isreal(g)) f = g; - else f = gcd(re(g), im(g)); - if (num(f) != 1) { - print num(f):; - if (ims) print"*":; - } - if (!isreal(g)) { - printf("(%d)", g/f); - if (ims) print"*":; - } - if (pmode == "alg") print"(":; - polyprint(1/g * a); - if (pmode == "alg") print")":; - if (den(f) > 1) print "/":den(f):; - return; - } - } - polyprint(a); + local f, g, t; + if (size(a.p) == 0) { + print 0:; + return; + } + if (iod) { + g = gcdcoeffs(a); + t = a.p[[size(a.p) - 1]] / g; + if (re(t) < 0) { t = -t; g = -g;} + if (g != 1) { + if (!isreal(t)) { + if (im(t) > re(t)) g *= 1i; + else if (im(t) <= -re(t)) g *= -1i; + } + if (isreal(g)) f = g; + else f = gcd(re(g), im(g)); + if (num(f) != 1) { + print num(f):; + if (ims) print"*":; + } + if (!isreal(g)) { + printf("(%d)", g/f); + if (ims) print"*":; + } + if (pmode == "alg") print"(":; + polyprint(1/g * a); + if (pmode == "alg") print")":; + if (den(f) > 1) print "/":den(f):; + return; + } + } + polyprint(a); } define polyprint(a) { - local s,n,i,c; - s = a.p; - n=size(s) - 1; - if (pmode=="alg") { - if (order == "up") { - i = 0; - while (!s[[i]]) i++; - pterm (s[[i]], i); - for (i++ ; i <= n; i++) { - c = s[[i]]; - if (c) { - if (isreal(c)) { - if (c > 0) print" + ":; - else { - print" - ":; - c = -c; - } - } - else print " + ":; - pterm(c,i); - } - } - return; - } - if (order == "down") { - pterm(s[[n]],n); - for (i=n-1; i>=0; i--) { - c = s[[i]]; - if (c) { - if (isreal(c)) { - if (c > 0) print" + ":; - else { - print" - ":; - c = -c; - } - } - else print " + ":; - pterm(c,i); - } - } - return; - } - quit "order to be up or down"; - } - if (pmode=="list") { - plist(s); - return; - } - print pmode,:"is unknown mode"; + local s,n,i,c; + s = a.p; + n=size(s) - 1; + if (pmode=="alg") { + if (order == "up") { + i = 0; + while (!s[[i]]) i++; + pterm (s[[i]], i); + for (i++ ; i <= n; i++) { + c = s[[i]]; + if (c) { + if (isreal(c)) { + if (c > 0) print" + ":; + else { + print" - ":; + c = -c; + } + } + else print " + ":; + pterm(c,i); + } + } + return; + } + if (order == "down") { + pterm(s[[n]],n); + for (i=n-1; i>=0; i--) { + c = s[[i]]; + if (c) { + if (isreal(c)) { + if (c > 0) print" + ":; + else { + print" - ":; + c = -c; + } + } + else print " + ":; + pterm(c,i); + } + } + return; + } + quit "order to be up or down"; + } + if (pmode=="list") { + plist(s); + return; + } + print pmode,:"is unknown mode"; } define poly_neg(a) { - local s,i,y; - obj poly y; - s = a.p; - for (i=0; i< size(s); i++) s[[i]] = -s[[i]]; - y.p = s; - return y; + local s,i,y; + obj poly y; + s = a.p; + for (i=0; i< size(s); i++) s[[i]] = -s[[i]]; + y.p = s; + return y; } define poly_conj(a) { - local s,i,y; - obj poly y; - s = a.p; - for (i=0; i < size(s); i++) s[[i]] = conj(s[[i]]); - y.p = s; - return y; + local s,i,y; + obj poly y; + s = a.p; + for (i=0; i < size(s); i++) s[[i]] = conj(s[[i]]); + y.p = s; + return y; } -define poly_inv(a) = pol(1)/a; /* This exists only for a of zero degree */ +define poly_inv(a) = pol(1)/a; /* This exists only for a of zero degree */ define poly_add(a,b) { - local sa, sb, i, y; - obj poly y; - sa=findlist(a); sb=findlist(b); - if (size(sa) > size(sb)) swap(sa,sb); - for (i=0; i< size(sa); i++) sa[[i]] += sb[[i]]; - while (i < size(sb)) append (sa, sb[[i++]]); - while (i > 0 && sa[[--i]]==0) remove (sa); - y.p = sa; - return y; + local sa, sb, i, y; + obj poly y; + sa=findlist(a); sb=findlist(b); + if (size(sa) > size(sb)) swap(sa,sb); + for (i=0; i< size(sa); i++) sa[[i]] += sb[[i]]; + while (i < size(sb)) append (sa, sb[[i++]]); + while (i > 0 && sa[[--i]]==0) remove (sa); + y.p = sa; + return y; } define poly_sub(a,b) { - return a + (-b); + return a + (-b); } define poly_cmp(a,b) { - local sa, sb; - sa = findlist(a); - sb=findlist(b); - return (sa != sb); + local sa, sb; + sa = findlist(a); + sb=findlist(b); + return (sa != sb); } define poly_mul(a,b) { - local sa,sb,i, j, y; - if (ismat(a)) swap(a,b); - if (ismat(b)) { - y = b; - for (i=matmin(b,1); i <= matmax(b,1); i++) - for (j = matmin(b,2); j<= matmax(b,2); j++) - y[i,j] = a * b[i,j]; - return y; - } - obj poly y; - sa=findlist(a); sb=findlist(b); - y.p = listmul(sa,sb); - return y; + local sa,sb,i, j, y; + if (ismat(a)) swap(a,b); + if (ismat(b)) { + y = b; + for (i=matmin(b,1); i <= matmax(b,1); i++) + for (j = matmin(b,2); j<= matmax(b,2); j++) + y[i,j] = a * b[i,j]; + return y; + } + obj poly y; + sa=findlist(a); sb=findlist(b); + y.p = listmul(sa,sb); + return y; } define listmul(a,b) { - local da,db, s, i, j, u; - da=size(a)-1; db=size(b)-1; - s=list(); - if (da >= 0 && db >= 0) { - for (i=0; i<= da+db; i++) { u=0; - for (j = max(0,i-db); j <= min(i, da); j++) - u += a[[j]]*b[[i-j]]; append (s,u);}} - return s; + local da,db, s, i, j, u; + da=size(a)-1; db=size(b)-1; + s=list(); + if (da >= 0 && db >= 0) { + for (i=0; i<= da+db; i++) { u=0; + for (j = max(0,i-db); j <= min(i, da); j++) + u += a[[j]]*b[[i-j]]; append (s,u);}} + return s; } define ev(a,t) { - local v, i, j; - if (ismat(a)) { - v = a; - for (i = matmin(a,1); i <= matmax(a,1); i++) - for (j = matmin(a,2); j <= matmax(a,2); j++) - v[i,j] = ev(a[i,j], t); - return v; - } - if (islist(a)) { - v = list(); - for (i = 0; i < size(a); i++) - append(v, ev(a[[i]], t)); - return v; - } - if (!ispoly(a)) return a; - if (islist(t)) { - v = list(); - for (i = 0; i < size(t); i++) - append(v, ev(a, t[[i]])); - return v; - } - if (ismat(t)) return evpm(a.p, t); - return evp(a.p, t); + local v, i, j; + if (ismat(a)) { + v = a; + for (i = matmin(a,1); i <= matmax(a,1); i++) + for (j = matmin(a,2); j <= matmax(a,2); j++) + v[i,j] = ev(a[i,j], t); + return v; + } + if (islist(a)) { + v = list(); + for (i = 0; i < size(a); i++) + append(v, ev(a[[i]], t)); + return v; + } + if (!ispoly(a)) return a; + if (islist(t)) { + v = list(); + for (i = 0; i < size(t); i++) + append(v, ev(a, t[[i]])); + return v; + } + if (ismat(t)) return evpm(a.p, t); + return evp(a.p, t); } define evp(s,t) { - local n,v,i; - n = size(s); - if (!n) return 0; - v = s[[n-1]]; - for (i = n - 2; i >= 0; i--) v=t * v +s[[i]]; - return v; + local n,v,i; + n = size(s); + if (!n) return 0; + v = s[[n-1]]; + for (i = n - 2; i >= 0; i--) v=t * v +s[[i]]; + return v; } define evpm(s,t) { - local m, n, V, i, I; - n = size(s); - m = matmax(t,1) - matmin(t,1); - if (matmax(t,2) - matmin(t,2) != m) quit "Non-square matrix"; - mat V[m+1, m+1]; - if (!n) return V; - mat I[m+1, m+1]; - matfill(I, 0, 1); - V = s[[n-1]] * I; - for (i = n - 2; i >= 0; i--) V = t * V + s[[i]] * I; - return V; + local m, n, V, i, I; + n = size(s); + m = matmax(t,1) - matmin(t,1); + if (matmax(t,2) - matmin(t,2) != m) quit "Non-square matrix"; + mat V[m+1, m+1]; + if (!n) return V; + mat I[m+1, m+1]; + matfill(I, 0, 1); + V = s[[n-1]] * I; + for (i = n - 2; i >= 0; i--) V = t * V + s[[i]] * I; + return V; } pzero = pol(0); x = pol(0,1); @@ -438,268 +438,268 @@ varname = "x"; define x(t) = ev(x, t); define iszero(a) { - if (ispoly(a)) - return !size(a.p); - return a == 0; + if (ispoly(a)) + return !size(a.p); + return a == 0; } define isstring(a) = istype(a, " "); define var(name) { - if (!isstring(name)) quit "Argument of var is to be a string"; - varname = name; - return pol(0,1); + if (!isstring(name)) quit "Argument of var is to be a string"; + varname = name; + return pol(0,1); } define pcoeff(a) { - if (isreal(a)) print a:; - else print "(":a:")":; + if (isreal(a)) print a:; + else print "(":a:")":; } define pterm(a,n) { - if (n==0) { - pcoeff(a); - return; - } - if (n==1) { - if (a!=1) { - pcoeff(a); - if (ims) print"*":; - } - print varname:; - return; - } - if (a!=1) { - pcoeff(a); - if (ims) print"*":; - } - print varname:"^":n:; + if (n==0) { + pcoeff(a); + return; + } + if (n==1) { + if (a!=1) { + pcoeff(a); + if (ims) print"*":; + } + print varname:; + return; + } + if (a!=1) { + pcoeff(a); + if (ims) print"*":; + } + print varname:"^":n:; } define plist(s) { - local i, n; - n = size(s); - print "( ":; - if (order == "up") { - for (i=0; i< n-1 ; i++) - print s[[i]]:",",:; - if (n) print s[[i]],")":; - else print "0 )":; - } - else { - if (n) print s[[n-1]]:; - for (i = n - 2; i >= 0; i--) - print ", ":s[[i]]:; - print " )":; - } + local i, n; + n = size(s); + print "( ":; + if (order == "up") { + for (i=0; i< n-1 ; i++) + print s[[i]]:",",:; + if (n) print s[[i]],")":; + else print "0 )":; + } + else { + if (n) print s[[n-1]]:; + for (i = n - 2; i >= 0; i--) + print ", ":s[[i]]:; + print " )":; + } } define deg(a) = size(a.p) - 1; define polydiv(a,b) { - local d, u, i, m, n, sa, sb, sq; - local obj poly q; - local obj poly r; - sa=findlist(a); sb = findlist(b); sq = list(); - m=size(sa)-1; n=size(sb)-1; - if (n<0) quit "Zero divisor"; - if (m= n) { u = sa[[m]]/d; - for (i = 0; i< n; i++) sa[[m-n+i]] -= u*sb[[i]]; - push(sq,u); remove(sa); m--; - while (m>=n && sa[[m]]==0) { m--; remove(sa); push(sq,0)}} - while (m>=0 && sa[[m]]==0) { m--; remove(sa);} - q.p = sq; r.p = sa; - return list(q, r);} + local d, u, i, m, n, sa, sb, sq; + local obj poly q; + local obj poly r; + sa=findlist(a); sb = findlist(b); sq = list(); + m=size(sa)-1; n=size(sb)-1; + if (n<0) quit "Zero divisor"; + if (m= n) { u = sa[[m]]/d; + for (i = 0; i< n; i++) sa[[m-n+i]] -= u*sb[[i]]; + push(sq,u); remove(sa); m--; + while (m>=n && sa[[m]]==0) { m--; remove(sa); push(sq,0)}} + while (m>=0 && sa[[m]]==0) { m--; remove(sa);} + q.p = sq; r.p = sa; + return list(q, r);} define poly_mod(a,b) { - local u; - u=polydiv(a,b); - return u[[1]]; + local u; + u=polydiv(a,b); + return u[[1]]; } define poly_quo(a,b) { - local p; - p = polydiv(a,b); - return p[[0]]; + local p; + p = polydiv(a,b); + return p[[0]]; } define ispmult(a,b) = iszero(a % b); define poly_div(a,b) { - if (!ispmult(a,b)) quit "Result not a polynomial"; - return poly_quo(a,b); + if (!ispmult(a,b)) quit "Result not a polynomial"; + return poly_quo(a,b); } define pgcd(a,b) { - local r; - if (iszero(a) && iszero(b)) return pzero; - while (!iszero(b)) { - r = a % b; - a = b; - b = r; - } - return monic(a); + local r; + if (iszero(a) && iszero(b)) return pzero; + while (!iszero(b)) { + r = a % b; + a = b; + b = r; + } + return monic(a); } define plcm(a,b) = monic( a * b // pgcd(a,b)); define pfgcd(a,b) { - local u, v, u1, v1, s, q, r, d, w; - u = v1 = pol(1); v = u1 = pol(0); - while (size(b.p) > 0) {s = polydiv(a,b); - q = s[[0]]; - a = b; b = s[[1]]; u -= q*u1; v -= -q*v1; - swap(u,u1); swap(v,v1);} - d=size(a.p)-1; if (d>=0 && (w= 1/a.p[[d]]) !=1) - { a *= w; u *= w; v *= w;} - return list(a,u,v); + local u, v, u1, v1, s, q, r, d, w; + u = v1 = pol(1); v = u1 = pol(0); + while (size(b.p) > 0) {s = polydiv(a,b); + q = s[[0]]; + a = b; b = s[[1]]; u -= q*u1; v -= -q*v1; + swap(u,u1); swap(v,v1);} + d=size(a.p)-1; if (d>=0 && (w= 1/a.p[[d]]) !=1) + { a *= w; u *= w; v *= w;} + return list(a,u,v); } define monic(a) { - local s, c, i, d, y; - if (iszero(a)) return pzero; - obj poly y; - s = findlist(a); - d = size(s)-1; - for (i=0; i<=d; i++) s[[i]] /= s[[d]]; - y.p = s; - return y; + local s, c, i, d, y; + if (iszero(a)) return pzero; + obj poly y; + s = findlist(a); + d = size(s)-1; + for (i=0; i<=d; i++) s[[i]] /= s[[d]]; + y.p = s; + return y; } define coefficient(a,n) = (n < size(a.p)) ? a.p[[n]] : 0; define D(a, n) { - local i,j,v; - if (isnull(n)) n = 1; - if (!isint(n) || n < 1) quit "Bad order for derivative"; - if (ismat(a)) { - v = a; - for (i = matmin(a,1); i <= matmax(a,1); i++) - for (j = matmin(a,2); j <= matmax(a,2); j++) - v[i,j] = D(a[i,j], n); - return v; - } - if (!ispoly(a)) return 0; - return Dp(a,n); + local i,j,v; + if (isnull(n)) n = 1; + if (!isint(n) || n < 1) quit "Bad order for derivative"; + if (ismat(a)) { + v = a; + for (i = matmin(a,1); i <= matmax(a,1); i++) + for (j = matmin(a,2); j <= matmax(a,2); j++) + v[i,j] = D(a[i,j], n); + return v; + } + if (!ispoly(a)) return 0; + return Dp(a,n); } define Dp(a,n) { - local i, v; - if (n > 1) return Dp(Dp(a, n-1), 1); - obj poly v; - v.p=list(); - for (i=1; i 1) return Dp(Dp(a, n-1), 1); + obj poly v; + v.p=list(); + for (i=1; i re(b)) b *= -1i; - else if (im(b) <= -re(b)) b *= 1i; - return b; + if (isreal(a) && isreal(b)) return gcd(a,b); + while (a) { + b -= bround(b/a) * a; + swap(a,b); + } + if (re(b) < 0) b = -b; + if (im(b) > re(b)) b *= -1i; + else if (im(b) <= -re(b)) b *= 1i; + return b; } define gcdcoeffs(a) { - local s,i,g, c; - s = a.p; - g=0; - for (i=0; i < size(s) && g != 1; i++) - if (c = s[[i]]) g = cgcd(g, c); - return g; + local s,i,g, c; + s = a.p; + g=0; + for (i=0; i < size(s) && g != 1; i++) + if (c = s[[i]]) g = cgcd(g, c); + return g; } define interp(X, Y, t) = evalfd(makediffs(X,Y), t); define makediffs(X,Y) { - local U, D, d, x, y, i, j, k, m, n, s; - U = D = list(); - n = size(X); - if (size(Y) != n) quit"Arguments to be lists of same size"; - for (i = n-1; i >= 0; i--) { - x = X[[i]]; - y = Y[[i]]; - m = size(U); - if (isnum(y)) { - d = y; - for (j = 0; j < m; j++) { - d = D[[j]] = (D[[j]]-d)/(U[[j]] - x); - } - push(U, x); - push(D, y); - } - else { - s = size(y); - for (k = 0; k < s ; k++) { - d = y[[k]]; - for (j = 0; j < m; j++) { - d = D[[j]] = (D[[j]] - d)/(U[[j]] - x); - } - } - for (j=s-1; j >=0; j--) { - push(U,x); - push(D, y[[j]]); - } - } - } - return list(U, D); + local U, D, d, x, y, i, j, k, m, n, s; + U = D = list(); + n = size(X); + if (size(Y) != n) quit"Arguments to be lists of same size"; + for (i = n-1; i >= 0; i--) { + x = X[[i]]; + y = Y[[i]]; + m = size(U); + if (isnum(y)) { + d = y; + for (j = 0; j < m; j++) { + d = D[[j]] = (D[[j]]-d)/(U[[j]] - x); + } + push(U, x); + push(D, y); + } + else { + s = size(y); + for (k = 0; k < s ; k++) { + d = y[[k]]; + for (j = 0; j < m; j++) { + d = D[[j]] = (D[[j]] - d)/(U[[j]] - x); + } + } + for (j=s-1; j >=0; j--) { + push(U,x); + push(D, y[[j]]); + } + } + } + return list(U, D); } define evalfd(T, t) { - local U, D, n, i, v; - if (isnull(t)) t = pol(0,1); - U = T[[0]]; - D = T[[1]]; - n = size(U); - v = D[[n-1]]; - for (i = n-2; i >= 0; i--) - v = v * (t - U[[i]]) + D[[i]]; - return v; + local U, D, n, i, v; + if (isnull(t)) t = pol(0,1); + U = T[[0]]; + D = T[[1]]; + n = size(U); + v = D[[n-1]]; + for (i = n-2; i >= 0; i--) + v = v * (t - U[[i]]) + D[[i]]; + return v; } define mdet(A) { - local n, i, j, k, I, J; - n = matmax(A,1) - (i = matmin(A,1)); - if (matmax(A,2) - (j = matmin(A,2)) != n) - quit "Non-square matrix for mdet"; - I = J = list(); - k = n + 1; - while (k--) { - append(I,i++); - append(J,j++); - } - return M(A, n+1, I, J); + local n, i, j, k, I, J; + n = matmax(A,1) - (i = matmin(A,1)); + if (matmax(A,2) - (j = matmin(A,2)) != n) + quit "Non-square matrix for mdet"; + I = J = list(); + k = n + 1; + while (k--) { + append(I,i++); + append(J,j++); + } + return M(A, n+1, I, J); } define M(A, n, I, J) { - local v, J0, i, j, j1; - if (n == 1) return A[ I[[0]], J[[0]] ]; - v = 0; - i = remove(I); - for (j = 0; j < n; j++) { - J0 = J; - j1 = delete(J0, j); - v += (-1)^(n-1+j) * A[i, j1] * M(A, n-1, I, J0); - } - return v; + local v, J0, i, j, j1; + if (n == 1) return A[ I[[0]], J[[0]] ]; + v = 0; + i = remove(I); + for (j = 0; j < n; j++) { + J0 = J; + j1 = delete(J0, j); + v += (-1)^(n-1+j) * A[i, j1] * M(A, n-1, I, J0); + } + return v; } define mprint(A) { - local i,j; - if (!ismat(A)) quit "Argument to be a matrix"; - for (i = matmin(A,1); i <= matmax(A,1); i++) { - for (j = matmin(A,2); j <= matmax(A,2); j++) - printf("%8.4d ", A[i,j]); - printf("\n"); - } + local i,j; + if (!ismat(A)) quit "Argument to be a matrix"; + for (i = matmin(A,1); i <= matmax(A,1); i++) { + for (j = matmin(A,2); j <= matmax(A,2); j++) + printf("%8.4d ", A[i,j]); + printf("\n"); + } } obj poly a; @@ -715,5 +715,5 @@ b=pol(5,16,8,1); c=pol(1+2i,3+4i,5+6i); if (config("resource_debug") & 3) { - print "obj poly {p} defined"; + print "obj poly {p} defined"; } diff --git a/cal/prompt.cal b/cal/prompt.cal index 1bc9044..cf9f98a 100644 --- a/cal/prompt.cal +++ b/cal/prompt.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/12/18 04:43:25 - * File existed as early as: 1995 + * Under source code control: 1995/12/18 04:43:25 + * File existed as early as: 1995 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -32,7 +32,7 @@ * entering "end", "exit" or "quit"; "end" returns to the level from * which adder() is called, e.g. with: * - * for (;;) adder() + * for (;;) adder() * * entering "end" would start a new edition with sum = 0; "quit" and * "exit" return to the top level. @@ -43,25 +43,25 @@ * thus the string may include variables, assignments, functions, etc. * as in: * - * 2 + 3 - * x = 2 + 3, x^3 - * x^2 - * local x = 2; while (x < 100) x *= 2; x % 100 - * x - * exp(2, 1e-5) - * sum - * print sum^2; - * 3; print sum^2; + * 2 + 3 + * x = 2 + 3, x^3 + * x^2 + * local x = 2; while (x < 100) x *= 2; x % 100 + * x + * exp(2, 1e-5) + * sum + * print sum^2; + * 3; print sum^2; * * (Here the second line creates x as a global variable; the local - * variable x in the fourth line has no effect on the global x. In + * variable x in the fourth line has no effect on the global x. In * the last three lines, sum is the sum of numbers already entered, so * the third last line doubles the value of sum. The value returned * by "print sum^2;" is the null value, so the second last line adds * nothing to sum. The last line returns the value 3, i.e. the last * non-null value found for the expressions separated by semicolons, * so sum will be increased by 3 after the "print sum^2;" command - * is executed. XXX The terminating semicolon is essential in the + * is executed. XXX The terminating semicolon is essential in the * last two lines. A command like eval("print 7;") is acceptable to * calc but eval("print 7") causes an exit from calc. XXX) * @@ -72,44 +72,44 @@ * * Calling showvalues(str) assumes str defines a function of x as in: * - * "sin(x)", "x^2 + 3*x", "exp(x, 1e-5)". + * "sin(x)", "x^2 + 3*x", "exp(x, 1e-5)". * * Values of the function so defined are returned for values of x - * entered in response to the ? prompt. Operation is terminated by + * entered in response to the ? prompt. Operation is terminated by * entering "end", "exit" or "quit". */ define adder() { - global sum = 0; - local s, t; - for (;;) { - s = prompt("? "); - if (s == "end") - break; - t = eval(s); - if (!isnum(t)) { - print "Please enter a number"; - continue; - } - sum += t; - print "\t":sum; - } + global sum = 0; + local s, t; + for (;;) { + s = prompt("? "); + if (s == "end") + break; + t = eval(s); + if (!isnum(t)) { + print "Please enter a number"; + continue; + } + sum += t; + print "\t":sum; + } } global prompt_x; define showvalues(str) { - local s; - for (;;) { - s = prompt("? "); - if (s == "end") - break; - prompt_x = eval(s); - if (!isnum(prompt_x)) { - print "Please enter a number"; - continue; - } - print "\t":eval(str); - } + local s; + for (;;) { + s = prompt("? "); + if (s == "end") + break; + prompt_x = eval(s); + if (!isnum(prompt_x)) { + print "Please enter a number"; + continue; + } + print "\t":eval(str); + } } diff --git a/cal/psqrt.cal b/cal/psqrt.cal index 059a850..f30cfe6 100644 --- a/cal/psqrt.cal +++ b/cal/psqrt.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:50:35 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:50:35 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -31,40 +31,40 @@ define psqrt(u, p) { - local p1, q, n, y, r, v, w, t, k; + local p1, q, n, y, r, v, w, t, k; - p1 = p - 1; - r = lowbit(p1); - q = p >> r; - t = 1 << (r - 1); - for (n = 2; ; n++) { - if (ptest(n, 1) == 0) - continue; - y = pmod(n, q, p); - k = pmod(y, t, p); - if (k == 1) - continue; - if (k != p1) - return; - break; - } - t = pmod(u, (q - 1) / 2, p); - v = (t * u) % p; - w = (t^2 * u) % p; - while (w != 1) { - k = 0; - t = w; - do { - k++; - t = t^2 % p; - } while (t != 1); - if (k == r) - return; - t = pmod(y, 1 << (r - k - 1), p); - y = t^2 % p; - v = (v * t) % p; - w = (w * y) % p; - r = k; - } - return min(v, p - v); + p1 = p - 1; + r = lowbit(p1); + q = p >> r; + t = 1 << (r - 1); + for (n = 2; ; n++) { + if (ptest(n, 1) == 0) + continue; + y = pmod(n, q, p); + k = pmod(y, t, p); + if (k == 1) + continue; + if (k != p1) + return; + break; + } + t = pmod(u, (q - 1) / 2, p); + v = (t * u) % p; + w = (t^2 * u) % p; + while (w != 1) { + k = 0; + t = w; + do { + k++; + t = t^2 % p; + } while (t != 1); + if (k == r) + return; + t = pmod(y, 1 << (r - k - 1), p); + y = t^2 % p; + v = (v * t) % p; + w = (w * y) % p; + r = k; + } + return min(v, p - v); } diff --git a/cal/qtime.cal b/cal/qtime.cal index a81d6d1..ec50b0a 100644 --- a/cal/qtime.cal +++ b/cal/qtime.cal @@ -12,7 +12,7 @@ * * 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 + * 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 @@ -20,21 +20,21 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/10/13 04:10:33 - * File existed as early as: 1999 + * Under source code control: 1999/10/13 04:10:33 + * File existed as early as: 1999 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * qtime(utc_hr_offset) + * qtime(utc_hr_offset) * - * utc_hr_offset Offset from UTC in hours. + * utc_hr_offset Offset from UTC in hours. * * See: - * http://www.magnetic-ink.dk/download/qtime.html + * http://www.magnetic-ink.dk/download/qtime.html * * for examples of qtime() written on other languages. */ @@ -45,42 +45,42 @@ */ define qtime(utc_hr_offset) { - static mat hr[12] = { - "twelve", "one", "two", "three", "four", "five", - "six", "seven", "eight", "nine", "ten", "eleven" - }; - static mat mn[7] = { - "", "five ", "ten ", "a quarter ", "twenty ", "twenty-five ", "half " - }; - static mat ny[5] = { - "nearly ", "almost ", "", "just after ", "after " - }; - static mat up[3] = { - "to ", "", "past " - }; - local adj_mins = (((time() + utc_hr_offset*3600) % 86400) + 30)//60+27; - local hours = (adj_mins // 60) % 12; - local minutes = adj_mins % 60; - local almost = minutes % 5; - local divisions = (minutes // 5) - 5; - local to_past_idx = divisions > 0 ? 1 : 0; + static mat hr[12] = { + "twelve", "one", "two", "three", "four", "five", + "six", "seven", "eight", "nine", "ten", "eleven" + }; + static mat mn[7] = { + "", "five ", "ten ", "a quarter ", "twenty ", "twenty-five ", "half " + }; + static mat ny[5] = { + "nearly ", "almost ", "", "just after ", "after " + }; + static mat up[3] = { + "to ", "", "past " + }; + local adj_mins = (((time() + utc_hr_offset*3600) % 86400) + 30)//60+27; + local hours = (adj_mins // 60) % 12; + local minutes = adj_mins % 60; + local almost = minutes % 5; + local divisions = (minutes // 5) - 5; + local to_past_idx = divisions > 0 ? 1 : 0; - if (divisions < 0) { - divisions = -divisions; - to_past_idx = -1; - } - ++to_past_idx; + if (divisions < 0) { + divisions = -divisions; + to_past_idx = -1; + } + ++to_past_idx; - /* - * Print the English sentence - * - * We avoid forward and back quotes just to show that the char() - * builtin function can be used in conjunction with a printf. - */ - printf("It%cs %s%s%s%s", - char(0x27), ny[almost], mn[divisions], - up[to_past_idx], hr[hours]); - if (divisions == 0) - printf(" o%cclock", char(0x27)); - print "."; + /* + * Print the English sentence + * + * We avoid forward and back quotes just to show that the char() + * builtin function can be used in conjunction with a printf. + */ + printf("It%cs %s%s%s%s", + char(0x27), ny[almost], mn[divisions], + up[to_past_idx], hr[hours]); + if (divisions == 0) + printf(" o%cclock", char(0x27)); + print "."; } diff --git a/cal/quat.cal b/cal/quat.cal index 7ab3438..0d289d1 100644 --- a/cal/quat.cal +++ b/cal/quat.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,205 +17,205 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:50:35 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:50:35 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * Routines to handle quaternions of the form: - * a + bi + cj + dk + * a + bi + cj + dk * * Note: In this module, quaternians are manipulated in the form: - * s + v + * s + v * Where s is a scalar and v is a vector of size 3. */ -obj quat {s, v}; /* definition of the quaternion object */ +obj quat {s, v}; /* definition of the quaternion object */ define quat(a,b,c,d) { - local obj quat x; + local obj quat x; - x.s = isnull(a) ? 0 : a; - mat x.v[3]; - x.v[0] = isnull(b) ? 0 : b; - x.v[1] = isnull(c) ? 0 : c; - x.v[2] = isnull(d) ? 0 : d; - return x; + x.s = isnull(a) ? 0 : a; + mat x.v[3]; + x.v[0] = isnull(b) ? 0 : b; + x.v[1] = isnull(c) ? 0 : c; + x.v[2] = isnull(d) ? 0 : d; + return x; } define quat_print(a) { - print "quat(" : a.s : ", " : a.v[0] : ", " : - a.v[1] : ", " : a.v[2] : ")" :; + print "quat(" : a.s : ", " : a.v[0] : ", " : + a.v[1] : ", " : a.v[2] : ")" :; } define quat_norm(a) { - return a.s^2 + dp(a.v, a.v); + return a.s^2 + dp(a.v, a.v); } define quat_abs(a, e) { - return sqrt(a.s^2 + dp(a.v, a.v), e); + return sqrt(a.s^2 + dp(a.v, a.v), e); } define quat_conj(a) { - local obj quat x; + local obj quat x; - x.s = a.s; - x.v = -a.v; - return x; + x.s = a.s; + x.v = -a.v; + return x; } define quat_add(a, b) { - local obj quat x; + local obj quat x; - if (!istype(b, x)) { - x.s = a.s + b; - x.v = a.v; - return x; - } - if (!istype(a, x)) { - x.s = a + b.s; - x.v = b.v; - return x; - } - x.s = a.s + b.s; - x.v = a.v + b.v; - if (x.v) - return x; - return x.s; + if (!istype(b, x)) { + x.s = a.s + b; + x.v = a.v; + return x; + } + if (!istype(a, x)) { + x.s = a + b.s; + x.v = b.v; + return x; + } + x.s = a.s + b.s; + x.v = a.v + b.v; + if (x.v) + return x; + return x.s; } define quat_sub(a, b) { - local obj quat x; + local obj quat x; - if (!istype(b, x)) { - x.s = a.s - b; - x.v = a.v; - return x; - } - if (!istype(a, x)) { - x.s = a - b.s; - x.v = -b.v; - return x; - } - x.s = a.s - b.s; - x.v = a.v - b.v; - if (x.v) - return x; - return x.s; + if (!istype(b, x)) { + x.s = a.s - b; + x.v = a.v; + return x; + } + if (!istype(a, x)) { + x.s = a - b.s; + x.v = -b.v; + return x; + } + x.s = a.s - b.s; + x.v = a.v - b.v; + if (x.v) + return x; + return x.s; } define quat_inc(a) { - local x; + local x; - x = a; - x.s++; - return x; + x = a; + x.s++; + return x; } define quat_dec(a) { - local x; + local x; - x = a; - x.s--; - return x; + x = a; + x.s--; + return x; } define quat_neg(a) { - local obj quat x; + local obj quat x; - x.s = -a.s; - x.v = -a.v; - return x; + x.s = -a.s; + x.v = -a.v; + return x; } define quat_mul(a, b) { - local obj quat x; + local obj quat x; - if (!istype(b, x)) { - x.s = a.s * b; - x.v = a.v * b; - } else if (!istype(a, x)) { - x.s = b.s * a; - x.v = b.v * a; - } else { - x.s = a.s * b.s - dp(a.v, b.v); - x.v = a.s * b.v + b.s * a.v + cp(a.v, b.v); - } - if (x.v) - return x; - return x.s; + if (!istype(b, x)) { + x.s = a.s * b; + x.v = a.v * b; + } else if (!istype(a, x)) { + x.s = b.s * a; + x.v = b.v * a; + } else { + x.s = a.s * b.s - dp(a.v, b.v); + x.v = a.s * b.v + b.s * a.v + cp(a.v, b.v); + } + if (x.v) + return x; + return x.s; } define quat_div(a, b) { - local obj quat x; + local obj quat x; - if (!istype(b, x)) { - x.s = a.s / b; - x.v = a.v / b; - return x; - } - return a * quat_inv(b); + if (!istype(b, x)) { + x.s = a.s / b; + x.v = a.v / b; + return x; + } + return a * quat_inv(b); } define quat_inv(a) { - local x, q2; + local x, q2; - obj quat x; - q2 = a.s^2 + dp(a.v, a.v); - x.s = a.s / q2; - x.v = a.v / (-q2); - return x; + obj quat x; + q2 = a.s^2 + dp(a.v, a.v); + x.s = a.s / q2; + x.v = a.v / (-q2); + return x; } define quat_scale(a, b) { - local obj quat x; + local obj quat x; - x.s = scale(a.s, b); - x.v = scale(a.v, b); - return x; + x.s = scale(a.s, b); + x.v = scale(a.v, b); + return x; } define quat_shift(a, b) { - local obj quat x; + local obj quat x; - x.s = a.s << b; - x.v = a.v << b; - if (x.v) - return x; - return x.s; + x.s = a.s << b; + x.v = a.v << b; + if (x.v) + return x; + return x.s; } if (config("resource_debug") & 3) { diff --git a/cal/randbitrun.cal b/cal/randbitrun.cal index 1c00e26..fc7afa2 100644 --- a/cal/randbitrun.cal +++ b/cal/randbitrun.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/02/13 03:43:11 - * File existed as early as: 1995 + * Under source code control: 1995/02/13 03:43:11 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -32,30 +32,30 @@ define randbitrun(run_cnt) { - local i; /* index */ - local max_run; /* longest run */ - local long_run_cnt; /* number of runs longer than MAX_RUN */ - local run; /* current run length */ - local tally_sum; /* sum of all tally values */ - local last; /* last random number */ - local current; /* current random number */ - local MAX_RUN = 18; /* max run we will keep track of */ + local i; /* index */ + local max_run; /* longest run */ + local long_run_cnt; /* number of runs longer than MAX_RUN */ + local run; /* current run length */ + local tally_sum; /* sum of all tally values */ + local last; /* last random number */ + local current; /* current random number */ + local MAX_RUN = 18; /* max run we will keep track of */ local mat tally[1:MAX_RUN]; /* tally of length of a rise run of 'x' */ - local mat prob[1:MAX_RUN]; /* prob[x] = probability of 'x' length run */ + local mat prob[1:MAX_RUN]; /* prob[x] = probability of 'x' length run */ /* * parse args */ if (param(0) == 0) { - run_cnt = 65536; + run_cnt = 65536; } /* * run setup */ - max_run = 0; /* no runs yet */ - long_run_cnt = 0; /* no long runs set */ - current = randbit(1); /* our first number */ + max_run = 0; /* no runs yet */ + long_run_cnt = 0; /* no long runs set */ + current = randbit(1); /* our first number */ run = 1; /* @@ -63,10 +63,10 @@ define randbitrun(run_cnt) * * A bit run length of 'r' occurs with a probability of: * - * 1/2^n; + * 1/2^n; */ for (i=1; i <= MAX_RUN; ++i) { - prob[i] = 1.0/(1< max_run) { - max_run = run; - } - if (run > MAX_RUN) { - ++long_run_cnt; - } else { - ++tally[run]; - } + /* record the stats */ + if (run > max_run) { + max_run = run; + } + if (run > MAX_RUN) { + ++long_run_cnt; + } else { + ++tally[run]; + } - /* start a new run */ - current = randbit(1); - run = 1; + /* start a new run */ + current = randbit(1); + run = 1; - /* note the continuing run */ - } else { - ++run; - } + /* note the continuing run */ + } else { + ++run; + } } /* determine the number of runs found */ tally_sum = matsum(tally) + long_run_cnt; @@ -109,9 +109,9 @@ define randbitrun(run_cnt) printf("rand runbit test used %d values to produce %d runs\n", run_cnt, tally_sum); for (i=1; i <= MAX_RUN; ++i) { - printf("length=%d\tprob=%9.7f\texpect=%d \tcount=%d \terr=%9.7f\n", - i, prob[i], round(tally_sum*prob[i]), tally[i], - (tally[i] - round(tally_sum*prob[i]))/tally_sum); + printf("length=%d\tprob=%9.7f\texpect=%d \tcount=%d \terr=%9.7f\n", + i, prob[i], round(tally_sum*prob[i]), tally[i], + (tally[i] - round(tally_sum*prob[i]))/tally_sum); } printf("length>%d\t\t\t\t\tcount=%d\n", MAX_RUN, long_run_cnt); printf("max length=%d\n", max_run); diff --git a/cal/randmprime.cal b/cal/randmprime.cal index 5e2a981..da0119c 100644 --- a/cal/randmprime.cal +++ b/cal/randmprime.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1994/03/14 23:11:21 - * File existed as early as: 1994 + * Under source code control: 1994/03/14 23:11:21 + * File existed as early as: 1994 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -32,37 +32,37 @@ read -once "lucas.cal" * randmprime - find a random prime of the form h*2^n-1 of a given size * * given: - * bits minimum bits in prime to return - * seed random seed for srandom() - * [dbg] if given, enable debugging + * bits minimum bits in prime to return + * seed random seed for srandom() + * [dbg] if given, enable debugging * * returns: - * a prime of the form h*2^n-1 + * a prime of the form h*2^n-1 */ define randmprime(bits, seed, dbg) { - local n; /* n as in h*2^n-1 */ - local h; /* h as in h*2^n-1 */ - local plush; /* value added to h since the beginning */ - local init; /* initial CPU time */ - local start; /* CPU time before last test */ - local stop; /* CPU time after last test */ - local tmp; /* just a tmp place holder value */ - local ret; /* h*2^n-1 that is prime */ + local n; /* n as in h*2^n-1 */ + local h; /* h as in h*2^n-1 */ + local plush; /* value added to h since the beginning */ + local init; /* initial CPU time */ + local start; /* CPU time before last test */ + local stop; /* CPU time after last test */ + local tmp; /* just a tmp place holder value */ + local ret; /* h*2^n-1 that is prime */ /* firewall */ if (param(0) < 2 || param(0) > 3) { - quit "bad usage: rndprime(dig, seed [,dbg])"; + quit "bad usage: rndprime(dig, seed [,dbg])"; } if (!isint(bits) || bits < 0 || !isint(seed) || seed < 0) { - quit "args must be non-negative integers"; + quit "args must be non-negative integers"; } if (bits < 1) { - bits = 1; + bits = 1; } if (param(0) == 2 || dbg < 0) { - dbg = 0; + dbg = 0; } /* seed generator */ @@ -76,57 +76,57 @@ randmprime(bits, seed, dbg) ++n; } if (dbg >= 1) { - print "DEBUG3: initial h =", h; - print "DEBUG3: initial n =", n; + print "DEBUG3: initial h =", h; + print "DEBUG3: initial n =", n; } /* * loop until we find a prime */ if (dbg >= 1) { - start = usertime(); - init = usertime(); - plush = 0; - print "DEBUG1: testing (h+" : plush : ")*2^" : n : "-1"; + start = usertime(); + init = usertime(); + plush = 0; + print "DEBUG1: testing (h+" : plush : ")*2^" : n : "-1"; } while (lucas(h,n) == 0) { - /* bump h, and n if needed */ - if (dbg >= 2) { - stop = usertime(); - print "DEBUG2: last test:", stop-start, " total time:", stop-init; - } - if (dbg >= 1) { - print "DEBUG1: composite: (h+" : plush : ")*2^" : n : "-1"; - plush += 2; - } - h += 2; - while (highbit(h) >= n) { - ++n; - } - if (dbg >= 1) { - print "DEBUG1: testing (h+" : plush : ")*2^" : n : "-1"; - start = stop; - } + /* bump h, and n if needed */ + if (dbg >= 2) { + stop = usertime(); + print "DEBUG2: last test:", stop-start, " total time:", stop-init; + } + if (dbg >= 1) { + print "DEBUG1: composite: (h+" : plush : ")*2^" : n : "-1"; + plush += 2; + } + h += 2; + while (highbit(h) >= n) { + ++n; + } + if (dbg >= 1) { + print "DEBUG1: testing (h+" : plush : ")*2^" : n : "-1"; + start = stop; + } } /* found a prime */ if (dbg >= 2) { - stop = usertime(); - print "DEBUG2: last test:", stop-start, " total time:", stop-init; - print "DEBUG3: " : h : "*2^" : n : "-1 is prime"; + stop = usertime(); + print "DEBUG2: last test:", stop-start, " total time:", stop-init; + print "DEBUG3: " : h : "*2^" : n : "-1 is prime"; } if (dbg >= 1) { - print "DEBUG1: prime: (h+" : plush : ")*2^" : n : "-1"; + print "DEBUG1: prime: (h+" : plush : ")*2^" : n : "-1"; } ret = h*2^n-1; if (dbg >= 3) { - print "DEBUG3: highbit(h):", highbit(h); - print "DEBUG3: digits(h):", digits(h); - print "DEBUG3: highbit(n):", highbit(n); - print "DEBUG3: digits(2^n):", int(n*ln(10)/ln(2)+1); - print "DEBUG3: highbit(h*2^n-1):", highbit(ret); - print "DEBUG3: digits(h*2^n)-1:", digits(ret); + print "DEBUG3: highbit(h):", highbit(h); + print "DEBUG3: digits(h):", digits(h); + print "DEBUG3: highbit(n):", highbit(n); + print "DEBUG3: digits(2^n):", int(n*ln(10)/ln(2)+1); + print "DEBUG3: highbit(h*2^n-1):", highbit(ret); + print "DEBUG3: digits(h*2^n)-1:", digits(ret); } return ret; } diff --git a/cal/randombitrun.cal b/cal/randombitrun.cal index d66f2e4..21e1c90 100644 --- a/cal/randombitrun.cal +++ b/cal/randombitrun.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/02/13 03:43:11 - * File existed as early as: 1995 + * Under source code control: 1995/02/13 03:43:11 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -32,30 +32,30 @@ define randombitrun(run_cnt) { - local i; /* index */ - local max_run; /* longest run */ - local long_run_cnt; /* number of runs longer than MAX_RUN */ - local run; /* current run length */ - local tally_sum; /* sum of all tally values */ - local last; /* last random number */ - local current; /* current random number */ - local MAX_RUN = 18; /* max run we will keep track of */ + local i; /* index */ + local max_run; /* longest run */ + local long_run_cnt; /* number of runs longer than MAX_RUN */ + local run; /* current run length */ + local tally_sum; /* sum of all tally values */ + local last; /* last random number */ + local current; /* current random number */ + local MAX_RUN = 18; /* max run we will keep track of */ local mat tally[1:MAX_RUN]; /* tally of length of a rise run of 'x' */ - local mat prob[1:MAX_RUN]; /* prob[x] = probability of 'x' length run */ + local mat prob[1:MAX_RUN]; /* prob[x] = probability of 'x' length run */ /* * parse args */ if (param(0) == 0) { - run_cnt = 65536; + run_cnt = 65536; } /* * run setup */ - max_run = 0; /* no runs yet */ - long_run_cnt = 0; /* no long runs set */ - current = randombit(1); /* our first number */ + max_run = 0; /* no runs yet */ + long_run_cnt = 0; /* no long runs set */ + current = randombit(1); /* our first number */ run = 1; /* @@ -63,10 +63,10 @@ define randombitrun(run_cnt) * * A bit run length of 'r' occurs with a probability of: * - * 1/2^n; + * 1/2^n; */ for (i=1; i <= MAX_RUN; ++i) { - prob[i] = 1.0/(1< max_run) { - max_run = run; - } - if (run > MAX_RUN) { - ++long_run_cnt; - } else { - ++tally[run]; - } + /* record the stats */ + if (run > max_run) { + max_run = run; + } + if (run > MAX_RUN) { + ++long_run_cnt; + } else { + ++tally[run]; + } - /* start a new run */ - current = randombit(1); - run = 1; + /* start a new run */ + current = randombit(1); + run = 1; - /* note the continuing run */ - } else { - ++run; - } + /* note the continuing run */ + } else { + ++run; + } } /* determine the number of runs found */ tally_sum = matsum(tally) + long_run_cnt; @@ -109,9 +109,9 @@ define randombitrun(run_cnt) printf("random runbit test used %d values to produce %d runs\n", run_cnt, tally_sum); for (i=1; i <= MAX_RUN; ++i) { - printf("length=%d\tprob=%9.7f\texpect=%d \tcount=%d \terr=%9.7f\n", - i, prob[i], round(tally_sum*prob[i]), tally[i], - (tally[i] - round(tally_sum*prob[i]))/tally_sum); + printf("length=%d\tprob=%9.7f\texpect=%d \tcount=%d \terr=%9.7f\n", + i, prob[i], round(tally_sum*prob[i]), tally[i], + (tally[i] - round(tally_sum*prob[i]))/tally_sum); } printf("length>%d\t\t\t\t\tcount=%d\n", MAX_RUN, long_run_cnt); printf("max length=%d\n", max_run); diff --git a/cal/randomrun.cal b/cal/randomrun.cal index 5f1d1bc..0f46280 100644 --- a/cal/randomrun.cal +++ b/cal/randomrun.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/02/19 03:35:59 - * File existed as early as: 1997 + * Under source code control: 1997/02/19 03:35:59 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -41,30 +41,30 @@ define randomrun(run_cnt) { - local i; /* index */ - local max_run; /* longest run */ - local long_run_cnt; /* number of runs longer than MAX_RUN */ - local run; /* current run length */ - local tally_sum; /* sum of all tally values */ - local last; /* last random number */ - local current; /* current random number */ - local MAX_RUN = 9; /* max run we will keep track of */ + local i; /* index */ + local max_run; /* longest run */ + local long_run_cnt; /* number of runs longer than MAX_RUN */ + local run; /* current run length */ + local tally_sum; /* sum of all tally values */ + local last; /* last random number */ + local current; /* current random number */ + local MAX_RUN = 9; /* max run we will keep track of */ local mat tally[1:MAX_RUN]; /* tally of length of a rise run of 'x' */ - local mat prob[1:MAX_RUN]; /* prob[x] = probability of 'x' length run */ + local mat prob[1:MAX_RUN]; /* prob[x] = probability of 'x' length run */ /* * parse args */ if (param(0) == 0) { - run_cnt = 65536; + run_cnt = 65536; } /* * run setup */ - max_run = 0; /* no runs yet */ - long_run_cnt = 0; /* no long runs set */ - current = random(); /* our first number */ + max_run = 0; /* no runs yet */ + long_run_cnt = 0; /* no long runs set */ + current = random(); /* our first number */ run = 1; /* @@ -72,10 +72,10 @@ define randomrun(run_cnt) * * A run length of 'r' occurs with a probability of: * - * 1/r! - 1/(r+1)! + * 1/r! - 1/(r+1)! */ for (i=1; i <= MAX_RUN; ++i) { - prob[i] = 1.0/fact(i) - 1.0/fact(i+1); + prob[i] = 1.0/fact(i) - 1.0/fact(i+1); } /* @@ -83,31 +83,31 @@ define randomrun(run_cnt) */ for (i=0; i < run_cnt; ++i) { - /* get our current number */ - last = current; - current = random(); + /* get our current number */ + last = current; + current = random(); - /* look for a run break */ - if (current < last) { + /* look for a run break */ + if (current < last) { - /* record the stats */ - if (run > max_run) { - max_run = run; - } - if (run > MAX_RUN) { - ++long_run_cnt; - } else { - ++tally[run]; - } + /* record the stats */ + if (run > max_run) { + max_run = run; + } + if (run > MAX_RUN) { + ++long_run_cnt; + } else { + ++tally[run]; + } - /* start a new run */ - current = random(); - run = 1; + /* start a new run */ + current = random(); + run = 1; - /* note the continuing run */ - } else { - ++run; - } + /* note the continuing run */ + } else { + ++run; + } } /* determine the number of runs found */ tally_sum = matsum(tally) + long_run_cnt; @@ -118,9 +118,9 @@ define randomrun(run_cnt) printf("random run test used %d values to produce %d runs\n", run_cnt, tally_sum); for (i=1; i <= MAX_RUN; ++i) { - printf("length=%d\tprob=%9.7f\texpect=%d \tcount=%d \terr=%9.7f\n", - i, prob[i], round(tally_sum*prob[i]), tally[i], - (tally[i] - round(tally_sum*prob[i]))/tally_sum); + printf("length=%d\tprob=%9.7f\texpect=%d \tcount=%d \terr=%9.7f\n", + i, prob[i], round(tally_sum*prob[i]), tally[i], + (tally[i] - round(tally_sum*prob[i]))/tally_sum); } printf("length>%d\t\t\t\t\tcount=%d\n", MAX_RUN, long_run_cnt); printf("max length=%d\n", max_run); diff --git a/cal/randrun.cal b/cal/randrun.cal index 59db94f..11cab2d 100644 --- a/cal/randrun.cal +++ b/cal/randrun.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/02/12 20:00:06 - * File existed as early as: 1995 + * Under source code control: 1995/02/12 20:00:06 + * File existed as early as: 1995 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -40,30 +40,30 @@ define randrun(run_cnt) { - local i; /* index */ - local max_run; /* longest run */ - local long_run_cnt; /* number of runs longer than MAX_RUN */ - local run; /* current run length */ - local tally_sum; /* sum of all tally values */ - local last; /* last random number */ - local current; /* current random number */ - local MAX_RUN = 9; /* max run we will keep track of */ + local i; /* index */ + local max_run; /* longest run */ + local long_run_cnt; /* number of runs longer than MAX_RUN */ + local run; /* current run length */ + local tally_sum; /* sum of all tally values */ + local last; /* last random number */ + local current; /* current random number */ + local MAX_RUN = 9; /* max run we will keep track of */ local mat tally[1:MAX_RUN]; /* tally of length of a rise run of 'x' */ - local mat prob[1:MAX_RUN]; /* prob[x] = probability of 'x' length run */ + local mat prob[1:MAX_RUN]; /* prob[x] = probability of 'x' length run */ /* * parse args */ if (param(0) == 0) { - run_cnt = 65536; + run_cnt = 65536; } /* * run setup */ - max_run = 0; /* no runs yet */ - long_run_cnt = 0; /* no long runs set */ - current = rand(); /* our first number */ + max_run = 0; /* no runs yet */ + long_run_cnt = 0; /* no long runs set */ + current = rand(); /* our first number */ run = 1; /* @@ -71,10 +71,10 @@ define randrun(run_cnt) * * A run length of 'r' occurs with a probability of: * - * 1/r! - 1/(r+1)! + * 1/r! - 1/(r+1)! */ for (i=1; i <= MAX_RUN; ++i) { - prob[i] = 1.0/fact(i) - 1.0/fact(i+1); + prob[i] = 1.0/fact(i) - 1.0/fact(i+1); } /* @@ -82,31 +82,31 @@ define randrun(run_cnt) */ for (i=0; i < run_cnt; ++i) { - /* get our current number */ - last = current; - current = rand(); + /* get our current number */ + last = current; + current = rand(); - /* look for a run break */ - if (current < last) { + /* look for a run break */ + if (current < last) { - /* record the stats */ - if (run > max_run) { - max_run = run; - } - if (run > MAX_RUN) { - ++long_run_cnt; - } else { - ++tally[run]; - } + /* record the stats */ + if (run > max_run) { + max_run = run; + } + if (run > MAX_RUN) { + ++long_run_cnt; + } else { + ++tally[run]; + } - /* start a new run */ - current = rand(); - run = 1; + /* start a new run */ + current = rand(); + run = 1; - /* note the continuing run */ - } else { - ++run; - } + /* note the continuing run */ + } else { + ++run; + } } /* determine the number of runs found */ tally_sum = matsum(tally) + long_run_cnt; @@ -117,9 +117,9 @@ define randrun(run_cnt) printf("rand run test used %d values to produce %d runs\n", run_cnt, tally_sum); for (i=1; i <= MAX_RUN; ++i) { - printf("length=%d\tprob=%9.7f\texpect=%d \tcount=%d \terr=%9.7f\n", - i, prob[i], round(tally_sum*prob[i]), tally[i], - (tally[i] - round(tally_sum*prob[i]))/tally_sum); + printf("length=%d\tprob=%9.7f\texpect=%d \tcount=%d \terr=%9.7f\n", + i, prob[i], round(tally_sum*prob[i]), tally[i], + (tally[i] - round(tally_sum*prob[i]))/tally_sum); } printf("length>%d\t\t\t\t\tcount=%d\n", MAX_RUN, long_run_cnt); printf("max length=%d\n", max_run); diff --git a/cal/regress.cal b/cal/regress.cal index 71b6285..2c3b390 100644 --- a/cal/regress.cal +++ b/cal/regress.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,29 +17,29 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:50:36 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:50:36 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * IMPORTANT NOTE: When adding new tests, look for comments with: * - * * *********************************************** * - * * NOTE: ==> Room for new tests ....-.... <== here * - * * *********************************************** * + * * *********************************************** * + * * NOTE: ==> Room for new tests ....-.... <== here * + * * *********************************************** * * * Select test numbers using a new block of a multiple of 100 test numbers. * * Test the correct execution of the calculator by reading this resource file. - * Errors are reported with '****' messages, or worse. :-) + * Errors are reported with '****' messages, or worse. :-) * * NOTE: Unlike most calc resource files, this one performs its work when - * it is read. Normally one would just define functions and - * values for later use. In the case of the regression test, - * we do not want to do this. + * it is read. Normally one would just define functions and + * values for later use. In the case of the regression test, + * we do not want to do this. */ @@ -54,18 +54,18 @@ print '002: Within each section, output should be numbered sequentially'; /* * test 003: define regression test global variables and error counts */ -global prob; /* libregress.cal problem counter */ -prob = 0; /* clear problem counter */ -errcount(0),; /* clear error count */ -errmax(-1),; /* prevent errcount from aborting */ -global ecnt; /* expected value of errcount() */ -ecnt = 0; /* clear expected errcount() value */ -initcfg = config("all", "newstd"); /* set config to startup default */ -defcfg = config("all"); /* capture the default config */ -config("resource_debug", 0),; /* disable resource startup messages */ -config("calc_debug", 0),; /* disable internal debugging */ -config("verbose_quit", 0),; /* disable quit messages */ -startcfg = config("all"); /* save state for later use */ +global prob; /* libregress.cal problem counter */ +prob = 0; /* clear problem counter */ +errcount(0),; /* clear error count */ +errmax(-1),; /* prevent errcount from aborting */ +global ecnt; /* expected value of errcount() */ +ecnt = 0; /* clear expected errcount() value */ +initcfg = config("all", "newstd"); /* set config to startup default */ +defcfg = config("all"); /* capture the default config */ +config("resource_debug", 0),; /* disable resource startup messages */ +config("calc_debug", 0),; /* disable internal debugging */ +config("verbose_quit", 0),; /* disable quit messages */ +startcfg = config("all"); /* save state for later use */ print '003: parsed global definitions'; @@ -83,18 +83,18 @@ print '003: parsed global definitions'; */ define vrfy(test, str) { - if (errcount() > ecnt) { - print '**** errcount:' : errcount(), ' > ecnt:' : ecnt; - ecnt = errcount(); - ++prob; - } - if (test != 1) { - print '**** Non-true result:', str; - ++prob; - } else { - print str; - } - return; + if (errcount() > ecnt) { + print '**** errcount:' : errcount(), ' > ecnt:' : ecnt; + ecnt = errcount(); + ++prob; + } + if (test != 1) { + print '**** Non-true result:', str; + ++prob; + } else { + print str; + } + return; } print '004: parsed vrfy()'; @@ -106,8 +106,8 @@ print '004: parsed vrfy()'; */ define prob(str) { - print '****' , str; - ++prob; + print '****' , str; + ++prob; } print '005: parsed prob()'; @@ -123,73 +123,73 @@ print '005: parsed prob()'; */ define test_booleans() { - local x; - local y; - local t1, t2, t3; + local x; + local y; + local t1, t2, t3; - print '300: Beginning test_booleans'; + print '300: Beginning test_booleans'; - if (0) - print '**** if (0)'; - if (0) - prob = prob + 1; + if (0) + print '**** if (0)'; + if (0) + prob = prob + 1; - if (1) - print '301: if (1)'; + if (1) + print '301: if (1)'; - if (2) - print '302: if (2)'; + if (2) + print '302: if (2)'; - if (1) - print '303: if (1) else'; - else - print '**** if (1) else'; - if (1) - print '304: if (1) else'; - else - prob = prob + 1; + if (1) + print '303: if (1) else'; + else + print '**** if (1) else'; + if (1) + print '304: if (1) else'; + else + prob = prob + 1; - if (0) - print '**** if (0) else'; - else - print '305: if (0) else'; - if (0) - prob = prob + 1; - else - print '306: if (0) else'; + if (0) + print '**** if (0) else'; + else + print '305: if (0) else'; + if (0) + prob = prob + 1; + else + print '306: if (0) else'; - if (1 == 1) - print '307: if 1 == 1'; - else - print '**** if 1 == 1'; - if (1 == 1) - print '308: if 1 == 1'; - else - prob = prob + 1; + if (1 == 1) + print '307: if 1 == 1'; + else + print '**** if 1 == 1'; + if (1 == 1) + print '308: if 1 == 1'; + else + prob = prob + 1; - if (1 != 2) - print '309: if 1 != 2'; - else - print '**** if 1 != 2'; - if (1 != 2) - print '310: if 1 != 2'; - else - prob = prob + 1; + if (1 != 2) + print '309: if 1 != 2'; + else + print '**** if 1 != 2'; + if (1 != 2) + print '310: if 1 != 2'; + else + prob = prob + 1; - vrfy(1, '311: vrfy 1'); - vrfy(2 == 2, '312: vrfy 2 == 2'); - vrfy(2 != 3, '313: vrfy 2 != 3'); - vrfy(2 < 3, '314: vrfy 2 < 3'); - vrfy(2 <= 2, '315: vrfy 2 <= 2'); - vrfy(2 <= 3, '316: vrfy 2 <= 3'); - vrfy(3 > 2, '317: vrfy 3 > 2'); - vrfy(2 >= 2, '318: vrfy 2 >= 2'); - vrfy(3 >= 2, '319: vrfy 3 >= 2'); - vrfy(!0, '320: vrfy !0'); - vrfy(!1 == 0,'321: vrfy !1 == 0'); - vrfy((1 ? 2 ? 3 : 4 : 5) == 3, '322: (1 ? 2 ? 3 : 4 : 5) == 3'); + vrfy(1, '311: vrfy 1'); + vrfy(2 == 2, '312: vrfy 2 == 2'); + vrfy(2 != 3, '313: vrfy 2 != 3'); + vrfy(2 < 3, '314: vrfy 2 < 3'); + vrfy(2 <= 2, '315: vrfy 2 <= 2'); + vrfy(2 <= 3, '316: vrfy 2 <= 3'); + vrfy(3 > 2, '317: vrfy 3 > 2'); + vrfy(2 >= 2, '318: vrfy 2 >= 2'); + vrfy(3 >= 2, '319: vrfy 3 >= 2'); + vrfy(!0, '320: vrfy !0'); + vrfy(!1 == 0,'321: vrfy !1 == 0'); + vrfy((1 ? 2 ? 3 : 4 : 5) == 3, '322: (1 ? 2 ? 3 : 4 : 5) == 3'); - print '323: Ending test_booleans'; + print '323: Ending test_booleans'; } print '006: parsed test_booleans()'; @@ -201,9 +201,9 @@ print '006: parsed test_booleans()'; */ define getglobalvar() { - global globalvar; + global globalvar; - return globalvar; + return globalvar; } print '007: parsed getglobalvar()'; /* @@ -211,108 +211,108 @@ print '007: parsed getglobalvar()'; */ define test_variables() { - local x1, x2, x3; - global g1, g2; - local t; - local x; + local x1, x2, x3; + global g1, g2; + local t; + local x; - print '350: Beginning test_variables'; + print '350: Beginning test_variables'; - x1 = 5; - x3 = 7 * 2; - x2 = 9 + 1; - globalvar = 22; - g1 = 19 - 3; - g2 = 79; - vrfy(x1 == 5, '351: x1 == 5'); - vrfy(x2 == 10, '352: x2 == 10'); - vrfy(x3 == 14, '353: x3 == 14'); - vrfy(g1 == 16, '354: g1 == 16'); - vrfy(g2 == 79, '355: g2 == 79'); - vrfy(globalvar == 22, '356: globalvar == 22'); - vrfy(getglobalvar() == 22, '357: getglobalvar() == 22'); - x1 = x2 + x3 + g1; - vrfy(x1 == 40, '358: x1 == 40'); - g1 = x3 + g2; - vrfy(g1 == 93, '359: g1 == 207'); - x1 = 5; - vrfy(x1++ == 5, '360: x1++ == 5'); - vrfy(x1 == 6, '361: x1 == 6'); - vrfy(++x1 == 7, '362: ++x1 == 7'); - x1 += 3; - vrfy(x1 == 10, '363: x1 == 10'); - x1 -= 6; - vrfy(x1 == 4, '364: x1 == 4'); - x1 *= 3; - vrfy(x1 == 12, '365: x1 == 12'); - x1 /= 4; - vrfy(x1 == 3, '366: x1 == 3'); - x1 = x2 = x3; - vrfy(x2 == 14, '367: x2 == 14'); - vrfy(x1 == 14, '368: x1 == 14'); + x1 = 5; + x3 = 7 * 2; + x2 = 9 + 1; + globalvar = 22; + g1 = 19 - 3; + g2 = 79; + vrfy(x1 == 5, '351: x1 == 5'); + vrfy(x2 == 10, '352: x2 == 10'); + vrfy(x3 == 14, '353: x3 == 14'); + vrfy(g1 == 16, '354: g1 == 16'); + vrfy(g2 == 79, '355: g2 == 79'); + vrfy(globalvar == 22, '356: globalvar == 22'); + vrfy(getglobalvar() == 22, '357: getglobalvar() == 22'); + x1 = x2 + x3 + g1; + vrfy(x1 == 40, '358: x1 == 40'); + g1 = x3 + g2; + vrfy(g1 == 93, '359: g1 == 207'); + x1 = 5; + vrfy(x1++ == 5, '360: x1++ == 5'); + vrfy(x1 == 6, '361: x1 == 6'); + vrfy(++x1 == 7, '362: ++x1 == 7'); + x1 += 3; + vrfy(x1 == 10, '363: x1 == 10'); + x1 -= 6; + vrfy(x1 == 4, '364: x1 == 4'); + x1 *= 3; + vrfy(x1 == 12, '365: x1 == 12'); + x1 /= 4; + vrfy(x1 == 3, '366: x1 == 3'); + x1 = x2 = x3; + vrfy(x2 == 14, '367: x2 == 14'); + vrfy(x1 == 14, '368: x1 == 14'); - if (2 && 3) { - print '369: if (2 && 3)'; - } else { - print '**** if (2 && 3)'; - ++prob; - } + if (2 && 3) { + print '369: if (2 && 3)'; + } else { + print '**** if (2 && 3)'; + ++prob; + } - if (2 && 0) { - print '**** if (2 && 0)'; - ++prob; - } else { - print '370: if (2 && 0)'; - } + if (2 && 0) { + print '**** if (2 && 0)'; + ++prob; + } else { + print '370: if (2 && 0)'; + } - if (0 && 2) { - print '**** if (0 && 2)'; - ++prob; - } else { - print '371: if (0 && 2)'; - } + if (0 && 2) { + print '**** if (0 && 2)'; + ++prob; + } else { + print '371: if (0 && 2)'; + } - if (0 && 0) { - print '**** if (0 && 0)'; - ++prob; - } else { - print '372: if (0 && 0)'; - } + if (0 && 0) { + print '**** if (0 && 0)'; + ++prob; + } else { + print '372: if (0 && 0)'; + } - if (2 || 0) { - print '373: if (2 || 0)'; - } else { - print '**** if (2 || 0)'; - ++prob; - } + if (2 || 0) { + print '373: if (2 || 0)'; + } else { + print '**** if (2 || 0)'; + ++prob; + } - if (0 || 2) { - print '374: if (0 || 2)'; - } else { - print '**** if (0 || 2)'; - ++prob; - } + if (0 || 2) { + print '374: if (0 || 2)'; + } else { + print '**** if (0 || 2)'; + ++prob; + } - if (0 || 0) { - print '**** if (0 || 0)'; - ++prob; - } else { - print '375: if (0 || 0)'; - } + if (0 || 0) { + print '**** if (0 || 0)'; + ++prob; + } else { + print '375: if (0 || 0)'; + } - x = 2 || 3; vrfy(x == 2, '376: (2 || 3) == 2'); - x = 2 || 0; vrfy(x == 2, '377: (2 || 0) == 2'); - x = 0 || 3; vrfy(x == 3, '378: (0 || 3) == 3'); - x = 0 || 0; vrfy(x == 0, '379: (0 || 0) == 0'); - x = 2 && 3; vrfy(x == 3, '380: (2 && 3) == 3'); - x = 2 && 0; vrfy(x == 0, '381: (2 && 0) == 0'); - x = 0 && 3; vrfy(x == 0, '382: (0 && 3) == 0'); - x = 2 || prob('2 || prob()'); - print "383: x = 2 || prob('2 || prob()'"; - x = 0 && prob('0 && prob()'); - print "384: x = 0 && prob('0 && prob()'"; + x = 2 || 3; vrfy(x == 2, '376: (2 || 3) == 2'); + x = 2 || 0; vrfy(x == 2, '377: (2 || 0) == 2'); + x = 0 || 3; vrfy(x == 3, '378: (0 || 3) == 3'); + x = 0 || 0; vrfy(x == 0, '379: (0 || 0) == 0'); + x = 2 && 3; vrfy(x == 3, '380: (2 && 3) == 3'); + x = 2 && 0; vrfy(x == 0, '381: (2 && 0) == 0'); + x = 0 && 3; vrfy(x == 0, '382: (0 && 3) == 0'); + x = 2 || prob('2 || prob()'); + print "383: x = 2 || prob('2 || prob()'"; + x = 0 && prob('0 && prob()'); + print "384: x = 0 && prob('0 && prob()'"; - print '385: Ending test_variables'; + print '385: Ending test_variables'; } print '008: parsed test_variables()'; @@ -324,81 +324,81 @@ print '008: parsed test_variables()'; */ define test_arithmetic() { - local x; + local x; - print '400: Beginning test_arithmetic'; + print '400: Beginning test_arithmetic'; - vrfy(3+4==7, '401: 3 + 4 == 7'); - vrfy(4-1==3, '402: 4 - 1 == 3'); - vrfy(2*3==6, '403: 2 * 3 == 6'); - vrfy(8/4==2, '404: 8 / 4 == 2'); - vrfy(2^3==8, '405: 2 ^ 3 == 8'); - vrfy(9-4-2==3, '406: 9-4-2 == 3'); - vrfy(9-4+2==7, '407: 9-4+2 == 7'); - vrfy(-5+2==-3, '408: -5+2 == -3'); - vrfy(2*3+1==7, '409: 2*3+1 == 7'); - vrfy(1+2*3==7, '410: 1+2*3 == 7'); - vrfy((1+2)*3==9, '411: (1+2)*3 == 9'); - vrfy(2*(3+1)==8, '412: 2*(3+1) == 8'); - vrfy(9-(2+3)==4, '413: 9-(2+3) == 4'); - vrfy(9+(2-3)==8, '414: 9+(2-3) == 8'); - vrfy((2+3)*(4+5)==45, '415: (2+3)*(4+5) == 45'); - vrfy(10/(2+3)==2, '416: 10/(2+3) == 2'); - vrfy(12/3+4==8, '417: 12/3+4 == 8'); - vrfy(6+12/3==10, '418: 6+12/3 == 10'); - vrfy(2+3==1+4, '419: 2+3 == 1+4'); - vrfy(-(2+3)==-5, '420: -(2+3) == -5'); - vrfy(7&18==2, '421: 7&18 == 2'); - vrfy(3|17==19, '422: 3|17 == 19'); - vrfy(2&3|1==3, '423: 2&3|1 == 3'); - vrfy(2&(3|1)==2, '424: 2&(3|1) == 2'); - vrfy(3<<4==48, '425: 3<<4 == 48'); - vrfy(5>>1==2, '426: 5>>1 == 2'); - vrfy(3<<-1==1, '427: 3<<-1 == 1'); - vrfy(5>>-2==20, '428: 5>>-2 == 20'); - vrfy(1<<2<<3==65536, '429: 1<<2<<3 == 65536'); - vrfy((1<<2)<<3==32, '430: (1<<2)<<3 == 32'); - vrfy(2^3^2==512, '431: 2^3^2 == 512'); - vrfy((2^3)^2==64, '432: (2^3)^2 == 64'); - vrfy(4//3==1, '433: 4//3==1'); - vrfy(4//-3==-1, '434: 4//-3==-1'); - vrfy(0.75//-0.51==-1, '435: 0.75//-0.51==-1'); - vrfy(0.75//-0.50==-1, '436: 0.75//-0.50==-1'); - vrfy(0.75//-0.49==-1, '437: 0.75//-0.49==-1'); - vrfy((3/4)//(-1/4)==-3, '438: (3/4)//(-1/4)==-3'); - vrfy(7%3==1, '439: 7%3==1'); - vrfy(0-.5==-.5, '440: 0-.5==-.5'); - vrfy(0^0 == 1, '441: 0^0 == 1'); - vrfy(0^1 == 0, '442: 0^1 == 0'); - vrfy(1^0 == 1, '443: 1^0 == 1'); - vrfy(1^1 == 1, '444: 1^1 == 1'); - vrfy(1/(.8+.8i)==.625-.625i, '445: 1/(.8+.8i)==.625-.625i'); - vrfy((.6+.8i)*(3.6-4.8i)==6, '446: (.6+.8i)*(3.6-4.8i)==6'); - vrfy(-16^-2 == -1/256, '447: -16^-2 == -1/256'); - vrfy(-7^2 == -49, '448: -7^2 == -49'); - vrfy(-3! == -6, '449: -3! == -6'); - vrfy(0^(0-0) == 1, '450: 0^(0-0) == 1'); - vrfy(0^(2-2) == 1, '451: 0^(2-2) == 1'); - vrfy(2^0 == 1, '452: 2^0 == 1'); - vrfy(2^(0-0) == 1, '453: 2^(0-0) == 1'); - vrfy(2^(2-2) == 1, '454: 2^(2-2) == 1'); - vrfy((2^23209-1)^0 == 1, '455: (2^23209-1)^0 == 1'); - vrfy((2^23209-1)^(0-0) == 1, '456: (2^23209-1)^(0-0) == 1'); - vrfy((2^23209-1)^(2-2) == 1, '457: (2^23209-1)^(2-2) == 1'); - vrfy((2^23209-1)^((2^23209-1)-(2^23209-1)) == 1, - '458: (2^23209-1)^((2^23209-1)-(2^23209-1)) == 1'); - vrfy(0^2 == 0, '459: 0^2 == 0'); - vrfy(0^3 == 0, '460: 0^3 == 0'); - vrfy(0^12 == 0, '461: 0^12 == 0'); - vrfy(0^13 == 0, '462: 0^13 == 0'); - x = 0; - vrfy(x == 0, '463: x == 0'); - vrfy(0^2 == 0, '464: 0^2 == 0'); - vrfy(0^3 == 0, '465: 0^3 == 0'); - vrfy(0^12 == 0, '466: 0^12 == 0'); - vrfy(x^13 == 0, '467: x^13 == 0'); + vrfy(3+4==7, '401: 3 + 4 == 7'); + vrfy(4-1==3, '402: 4 - 1 == 3'); + vrfy(2*3==6, '403: 2 * 3 == 6'); + vrfy(8/4==2, '404: 8 / 4 == 2'); + vrfy(2^3==8, '405: 2 ^ 3 == 8'); + vrfy(9-4-2==3, '406: 9-4-2 == 3'); + vrfy(9-4+2==7, '407: 9-4+2 == 7'); + vrfy(-5+2==-3, '408: -5+2 == -3'); + vrfy(2*3+1==7, '409: 2*3+1 == 7'); + vrfy(1+2*3==7, '410: 1+2*3 == 7'); + vrfy((1+2)*3==9, '411: (1+2)*3 == 9'); + vrfy(2*(3+1)==8, '412: 2*(3+1) == 8'); + vrfy(9-(2+3)==4, '413: 9-(2+3) == 4'); + vrfy(9+(2-3)==8, '414: 9+(2-3) == 8'); + vrfy((2+3)*(4+5)==45, '415: (2+3)*(4+5) == 45'); + vrfy(10/(2+3)==2, '416: 10/(2+3) == 2'); + vrfy(12/3+4==8, '417: 12/3+4 == 8'); + vrfy(6+12/3==10, '418: 6+12/3 == 10'); + vrfy(2+3==1+4, '419: 2+3 == 1+4'); + vrfy(-(2+3)==-5, '420: -(2+3) == -5'); + vrfy(7&18==2, '421: 7&18 == 2'); + vrfy(3|17==19, '422: 3|17 == 19'); + vrfy(2&3|1==3, '423: 2&3|1 == 3'); + vrfy(2&(3|1)==2, '424: 2&(3|1) == 2'); + vrfy(3<<4==48, '425: 3<<4 == 48'); + vrfy(5>>1==2, '426: 5>>1 == 2'); + vrfy(3<<-1==1, '427: 3<<-1 == 1'); + vrfy(5>>-2==20, '428: 5>>-2 == 20'); + vrfy(1<<2<<3==65536, '429: 1<<2<<3 == 65536'); + vrfy((1<<2)<<3==32, '430: (1<<2)<<3 == 32'); + vrfy(2^3^2==512, '431: 2^3^2 == 512'); + vrfy((2^3)^2==64, '432: (2^3)^2 == 64'); + vrfy(4//3==1, '433: 4//3==1'); + vrfy(4//-3==-1, '434: 4//-3==-1'); + vrfy(0.75//-0.51==-1, '435: 0.75//-0.51==-1'); + vrfy(0.75//-0.50==-1, '436: 0.75//-0.50==-1'); + vrfy(0.75//-0.49==-1, '437: 0.75//-0.49==-1'); + vrfy((3/4)//(-1/4)==-3, '438: (3/4)//(-1/4)==-3'); + vrfy(7%3==1, '439: 7%3==1'); + vrfy(0-.5==-.5, '440: 0-.5==-.5'); + vrfy(0^0 == 1, '441: 0^0 == 1'); + vrfy(0^1 == 0, '442: 0^1 == 0'); + vrfy(1^0 == 1, '443: 1^0 == 1'); + vrfy(1^1 == 1, '444: 1^1 == 1'); + vrfy(1/(.8+.8i)==.625-.625i, '445: 1/(.8+.8i)==.625-.625i'); + vrfy((.6+.8i)*(3.6-4.8i)==6, '446: (.6+.8i)*(3.6-4.8i)==6'); + vrfy(-16^-2 == -1/256, '447: -16^-2 == -1/256'); + vrfy(-7^2 == -49, '448: -7^2 == -49'); + vrfy(-3! == -6, '449: -3! == -6'); + vrfy(0^(0-0) == 1, '450: 0^(0-0) == 1'); + vrfy(0^(2-2) == 1, '451: 0^(2-2) == 1'); + vrfy(2^0 == 1, '452: 2^0 == 1'); + vrfy(2^(0-0) == 1, '453: 2^(0-0) == 1'); + vrfy(2^(2-2) == 1, '454: 2^(2-2) == 1'); + vrfy((2^23209-1)^0 == 1, '455: (2^23209-1)^0 == 1'); + vrfy((2^23209-1)^(0-0) == 1, '456: (2^23209-1)^(0-0) == 1'); + vrfy((2^23209-1)^(2-2) == 1, '457: (2^23209-1)^(2-2) == 1'); + vrfy((2^23209-1)^((2^23209-1)-(2^23209-1)) == 1, + '458: (2^23209-1)^((2^23209-1)-(2^23209-1)) == 1'); + vrfy(0^2 == 0, '459: 0^2 == 0'); + vrfy(0^3 == 0, '460: 0^3 == 0'); + vrfy(0^12 == 0, '461: 0^12 == 0'); + vrfy(0^13 == 0, '462: 0^13 == 0'); + x = 0; + vrfy(x == 0, '463: x == 0'); + vrfy(0^2 == 0, '464: 0^2 == 0'); + vrfy(0^3 == 0, '465: 0^3 == 0'); + vrfy(0^12 == 0, '466: 0^12 == 0'); + vrfy(x^13 == 0, '467: x^13 == 0'); - print '462: Ending test_arithmetic'; + print '462: Ending test_arithmetic'; } print '009: parsed test_arithmetic()'; @@ -410,168 +410,168 @@ print '009: parsed test_arithmetic()'; */ define test_config() { - local callcfg; /* caller configuration value */ - local oldcfg; /* caller configuration value */ - local newcfg; /* caller configuration value */ + local callcfg; /* caller configuration value */ + local oldcfg; /* caller configuration value */ + local newcfg; /* caller configuration value */ - print '500: Beginning test_config'; + print '500: Beginning test_config'; - /* check the set and return of all config */ - callcfg = config("all"); - print '501: callcfg = config("all")'; - vrfy(callcfg == startcfg, '502: callcfg == startcfg'); + /* check the set and return of all config */ + callcfg = config("all"); + print '501: callcfg = config("all")'; + vrfy(callcfg == startcfg, '502: callcfg == startcfg'); - callcfg = config("all", "oldstd"); - print '503: callcfg = config("all","oldstd")'; - vrfy(callcfg == startcfg, '504: callcfg == startcfg'); - oldcfg = config("all"); - print '505: oldcfg = config("all");'; - vrfy(config("all") == oldcfg, '506: config("all") == oldcfg'); - vrfy(oldcfg==config("all","newstd"), - '507: oldcfg==config("all","newstd")'); - vrfy(defcfg == config("all"), '508: defcfg == config("all")'); + callcfg = config("all", "oldstd"); + print '503: callcfg = config("all","oldstd")'; + vrfy(callcfg == startcfg, '504: callcfg == startcfg'); + oldcfg = config("all"); + print '505: oldcfg = config("all");'; + vrfy(config("all") == oldcfg, '506: config("all") == oldcfg'); + vrfy(oldcfg==config("all","newstd"), + '507: oldcfg==config("all","newstd")'); + vrfy(defcfg == config("all"), '508: defcfg == config("all")'); - /* vrfy the state of the default config */ - vrfy(config("mode") == "real", - '509: config("mode") == "real"'); - vrfy(config("display") == 20, - '510: config("display") == 20'); - vrfy(config("epsilon") == 1e-20, - '511: config("epsilon") == 1e-20'); - vrfy(config("trace") == 0, - '512: config("trace") == 0'); - vrfy(config("maxprint") == 16, - '513: config("maxprint") == 16'); - vrfy(config("mul2") == 28, - '514: config("mul2") == 28'); - vrfy(config("sq2") == 28, - '515: config("sq2") == 28'); - vrfy(config("pow2") == 20, - '516: config("pow2") == 20'); - vrfy(config("redc2") == 25, - '517: config("redc2") == 25'); - vrfy(config("tilde"), - '518: config("tilde")'); - vrfy(config("tab"), - '519: config("tab")'); - vrfy(config("quomod") == 0, - '520: config("quomod") == 0'); - vrfy(config("quo") == 2, - '521: config("quo") == 2'); - vrfy(config("mod") == 0, - '522: config("mod") == 0'); - vrfy(config("sqrt") == 24, - '523: config("sqrt") == 24'); - vrfy(config("appr") == 24, - '524: config("appr") == 24'); - vrfy(config("cfappr") == 0, - '525: config("cfappr") == 0'); - vrfy(config("cfsim") == 8, - '526: config("cfsim") == 8'); - vrfy(config("outround") == 24, - '527: config("outround") == 24'); - vrfy(config("round") == 24, - '528: config("round") == 24'); - vrfy(config("leadzero") == 1, - '529: config("leadzero") == 1'); - vrfy(config("fullzero") == 0, - '530: config("fullzero") == 0'); - vrfy(config("maxscan") == 20, - '531: config("maxscan") == 20'); - vrfy(config("prompt") == "; ", - '532: config("prompt") == "; "'); - vrfy(config("more") == ";; ", - '533: config("more") == ";; "'); + /* vrfy the state of the default config */ + vrfy(config("mode") == "real", + '509: config("mode") == "real"'); + vrfy(config("display") == 20, + '510: config("display") == 20'); + vrfy(config("epsilon") == 1e-20, + '511: config("epsilon") == 1e-20'); + vrfy(config("trace") == 0, + '512: config("trace") == 0'); + vrfy(config("maxprint") == 16, + '513: config("maxprint") == 16'); + vrfy(config("mul2") == 28, + '514: config("mul2") == 28'); + vrfy(config("sq2") == 28, + '515: config("sq2") == 28'); + vrfy(config("pow2") == 20, + '516: config("pow2") == 20'); + vrfy(config("redc2") == 25, + '517: config("redc2") == 25'); + vrfy(config("tilde"), + '518: config("tilde")'); + vrfy(config("tab"), + '519: config("tab")'); + vrfy(config("quomod") == 0, + '520: config("quomod") == 0'); + vrfy(config("quo") == 2, + '521: config("quo") == 2'); + vrfy(config("mod") == 0, + '522: config("mod") == 0'); + vrfy(config("sqrt") == 24, + '523: config("sqrt") == 24'); + vrfy(config("appr") == 24, + '524: config("appr") == 24'); + vrfy(config("cfappr") == 0, + '525: config("cfappr") == 0'); + vrfy(config("cfsim") == 8, + '526: config("cfsim") == 8'); + vrfy(config("outround") == 24, + '527: config("outround") == 24'); + vrfy(config("round") == 24, + '528: config("round") == 24'); + vrfy(config("leadzero") == 1, + '529: config("leadzero") == 1'); + vrfy(config("fullzero") == 0, + '530: config("fullzero") == 0'); + vrfy(config("maxscan") == 20, + '531: config("maxscan") == 20'); + vrfy(config("prompt") == "; ", + '532: config("prompt") == "; "'); + vrfy(config("more") == ";; ", + '533: config("more") == ";; "'); - /* convert to "oldstd" config by individual changes */ - print '534: test unused'; - vrfy(config("outround", 2) == 24, - '535: config("outround", 2) == 24'); - vrfy(config("leadzero","n") == 1, - '536: config("leadzero","n") == 1'); - print '537: test unused'; - vrfy(config("prompt", "> ") == "; ", - '538: config("prompt", "> ") == "; "'); - vrfy(config("more", ">> ") == ";; ", - '539: config("more", ">> ") == ";; "'); - vrfy(config("all") == oldcfg, '540: config("all") == oldcfg'); + /* convert to "oldstd" config by individual changes */ + print '534: test unused'; + vrfy(config("outround", 2) == 24, + '535: config("outround", 2) == 24'); + vrfy(config("leadzero","n") == 1, + '536: config("leadzero","n") == 1'); + print '537: test unused'; + vrfy(config("prompt", "> ") == "; ", + '538: config("prompt", "> ") == "; "'); + vrfy(config("more", ">> ") == ";; ", + '539: config("more", ">> ") == ";; "'); + vrfy(config("all") == oldcfg, '540: config("all") == oldcfg'); - /* restore the configuration at the start of this function */ - vrfy(config("all",callcfg) == oldcfg, - '541: config("all",callcfg) == oldcfg'); + /* restore the configuration at the start of this function */ + vrfy(config("all",callcfg) == oldcfg, + '541: config("all",callcfg) == oldcfg'); - /* display and fullzero tests */ - vrfy(config("display",2) == 20, - '542: config("display",2) == 20'); - vrfy(config("leadzero",0) == 1, - '543: config("leadzero",0) == 1'); - vrfy(config("fullzero",1) == 0, - '544: config("fullzero",1) == 0'); - vrfy(strprintf("%d %d %d", 0, 1, 2) == ".00 1.00 2.00", - '545: strprintf("%d %d %d", 0, 1, 2) == ".00 1.00 2.00"'); - vrfy(config("display",20) == 2, - '546: config("display",20) == 2'); - vrfy(config("leadzero",1) == 0, - '547: config("leadzero",1) == 0'); - vrfy(config("fullzero",0) == 1, - '548: config("fullzero",0) == 1'); - vrfy(strprintf("%d %d %d", 0, 1, 2) == "0 1 2", - '549: strprintf("%d %d %d", 0, 1, 2) == "0 1 2"'); + /* display and fullzero tests */ + vrfy(config("display",2) == 20, + '542: config("display",2) == 20'); + vrfy(config("leadzero",0) == 1, + '543: config("leadzero",0) == 1'); + vrfy(config("fullzero",1) == 0, + '544: config("fullzero",1) == 0'); + vrfy(strprintf("%d %d %d", 0, 1, 2) == ".00 1.00 2.00", + '545: strprintf("%d %d %d", 0, 1, 2) == ".00 1.00 2.00"'); + vrfy(config("display",20) == 2, + '546: config("display",20) == 2'); + vrfy(config("leadzero",1) == 0, + '547: config("leadzero",1) == 0'); + vrfy(config("fullzero",0) == 1, + '548: config("fullzero",0) == 1'); + vrfy(strprintf("%d %d %d", 0, 1, 2) == "0 1 2", + '549: strprintf("%d %d %d", 0, 1, 2) == "0 1 2"'); - /* restore calling config */ - vrfy(config("all",callcfg) == startcfg, - '550: config("all",callcfg) == startcfg'); - vrfy(config("all") == callcfg, '551: config("all") == callcfg'); - vrfy(config("all") == startcfg, '552: config("all") == startcfg'); + /* restore calling config */ + vrfy(config("all",callcfg) == startcfg, + '550: config("all",callcfg) == startcfg'); + vrfy(config("all") == callcfg, '551: config("all") == callcfg'); + vrfy(config("all") == startcfg, '552: config("all") == startcfg'); - /* check read-only config values */ - vrfy(strlen(config("program")) > 0, - '553: strlen(config("program")) > 0'); - vrfy(strlen(config("basename")) > 0, - '554: strlen(config("basename")) > 0'); - vrfy(strlen(config("version")) > 0, - '555: strlen(config("version")) > 0'); + /* check read-only config values */ + vrfy(strlen(config("program")) > 0, + '553: strlen(config("program")) > 0'); + vrfy(strlen(config("basename")) > 0, + '554: strlen(config("basename")) > 0'); + vrfy(strlen(config("version")) > 0, + '555: strlen(config("version")) > 0'); - /* mode2 is off by default */ - vrfy(config("mode2") == "off", - '556: config("mode2") == "off"'); + /* mode2 is off by default */ + vrfy(config("mode2") == "off", + '556: config("mode2") == "off"'); - /* hz is numeric */ - vrfy(isint(config("hz")), '557: isint(config("hz"))'); + /* hz is numeric */ + vrfy(isint(config("hz")), '557: isint(config("hz"))'); - /* compile_custom is simple */ - vrfy(issimple(config("compile_custom")), - '558: issimple(config("compile_custom"))'); + /* compile_custom is simple */ + vrfy(issimple(config("compile_custom")), + '558: issimple(config("compile_custom"))'); - /* allow_custom is simple */ - vrfy(issimple(config("allow_custom")), - '559: issimple(config("allow_custom"))'); + /* allow_custom is simple */ + vrfy(issimple(config("allow_custom")), + '559: issimple(config("allow_custom"))'); - /* allow_custom is simple */ - vrfy(issimple(config("allow_custom")), - '559: issimple(config("allow_custom"))'); + /* allow_custom is simple */ + vrfy(issimple(config("allow_custom")), + '559: issimple(config("allow_custom"))'); - /* baseb is numeric */ - vrfy(isint(config("baseb")), '560: isint(config("baseb"))'); + /* baseb is numeric */ + vrfy(isint(config("baseb")), '560: isint(config("baseb"))'); - /* redecl_warn is simple */ - vrfy(issimple(config("redecl_warn")), - '561: issimple(config("redecl_warn"))'); + /* redecl_warn is simple */ + vrfy(issimple(config("redecl_warn")), + '561: issimple(config("redecl_warn"))'); - /* dupvar_warn is simple */ - vrfy(issimple(config("dupvar_warn")), - '562: issimple(config("rdupvar_warn"))'); + /* dupvar_warn is simple */ + vrfy(issimple(config("dupvar_warn")), + '562: issimple(config("rdupvar_warn"))'); - /* test space modes */ - vrfy(config("tilde_space") == 0, - '563: config("tilde_space") == 0'); - vrfy(config("fraction_space") == 0, - '564: config("fraction_space") == 0'); - vrfy(config("complex_space") == 0, - '565: config("complex_space") == 0'); + /* test space modes */ + vrfy(config("tilde_space") == 0, + '563: config("tilde_space") == 0'); + vrfy(config("fraction_space") == 0, + '564: config("fraction_space") == 0'); + vrfy(config("complex_space") == 0, + '565: config("complex_space") == 0'); - print '566: Ending test_config'; + print '566: Ending test_config'; } print '010: parsed test_config()'; @@ -583,24 +583,24 @@ print '010: parsed test_config()'; */ define muldivcheck(a, b, c, str) { - local abc, acb, bac, bca, cab, cba; + local abc, acb, bac, bca, cab, cba; - abc = (a * b) * c; - acb = (a * c) * b; - bac = (b * a) * c; - bca = (b * c) * a; - cab = (c * a) * b; - cba = (c * b) * a; + abc = (a * b) * c; + acb = (a * c) * b; + bac = (b * a) * c; + bca = (b * c) * a; + cab = (c * a) * b; + cba = (c * b) * a; - if (abc != acb) {print '**** abc != acb:', str; ++prob;} - if (acb != bac) {print '**** acb != bac:', str; ++prob;} - if (bac != bca) {print '**** bac != bca:', str; ++prob;} - if (bca != cab) {print '**** bca != cab:', str; ++prob;} - if (cab != cba) {print '**** cab != cba:', str; ++prob;} - if (abc/a != b*c) {print '**** abc/a != bc:', str; ++prob;} - if (abc/b != a*c) {print '**** abc/b != ac:', str; ++prob;} - if (abc/c != a*b) {print '**** abc/c != ab:', str; ++prob;} - print str; + if (abc != acb) {print '**** abc != acb:', str; ++prob;} + if (acb != bac) {print '**** acb != bac:', str; ++prob;} + if (bac != bca) {print '**** bac != bca:', str; ++prob;} + if (bca != cab) {print '**** bca != cab:', str; ++prob;} + if (cab != cba) {print '**** cab != cba:', str; ++prob;} + if (abc/a != b*c) {print '**** abc/a != bc:', str; ++prob;} + if (abc/b != a*c) {print '**** abc/b != ac:', str; ++prob;} + if (abc/c != a*b) {print '**** abc/c != ab:', str; ++prob;} + print str; } print '011: parsed muldivcheck()'; /* @@ -608,28 +608,28 @@ print '011: parsed muldivcheck()'; */ define squarecheck(a, b, str) { - local a2, b2, tab, apb, apb2, t; + local a2, b2, tab, apb, apb2, t; - a2 = a^2; - b2 = b^2; - tab = a * b * 2; - apb = a + b; - apb2 = apb^2; - if (a2 != a*a) {print '**** a^2 != a*a:', str; ++prob;} - if (b2 != b*b) {print '**** b^2 != b*b:', str; ++prob;} - if (apb2 != apb*apb) { - print '**** (a+b)^2 != (a+b)*(a+b):', str; - ++prob; - } - if (a2+tab+b2 != apb2) { - print '**** (a+b)^2 != a^2 + 2ab + b^2:', str; - ++prob; - } - if (a2/a != a) {print '**** a^2/a != a:', str; ++prob;} - if (b2/b != b) {print '**** b^2/b != b:', str; ++prob;} - if (apb2/apb != apb) {print '**** (a+b)^2/(a+b) != a+b:', str; ++prob;} - if (a2*b2 != (a*b)^2) {print '**** a^2*b^2 != (ab)^2:', str; ++prob;} - print str; + a2 = a^2; + b2 = b^2; + tab = a * b * 2; + apb = a + b; + apb2 = apb^2; + if (a2 != a*a) {print '**** a^2 != a*a:', str; ++prob;} + if (b2 != b*b) {print '**** b^2 != b*b:', str; ++prob;} + if (apb2 != apb*apb) { + print '**** (a+b)^2 != (a+b)*(a+b):', str; + ++prob; + } + if (a2+tab+b2 != apb2) { + print '**** (a+b)^2 != a^2 + 2ab + b^2:', str; + ++prob; + } + if (a2/a != a) {print '**** a^2/a != a:', str; ++prob;} + if (b2/b != b) {print '**** b^2/b != b:', str; ++prob;} + if (apb2/apb != apb) {print '**** (a+b)^2/(a+b) != a+b:', str; ++prob;} + if (a2*b2 != (a*b)^2) {print '**** a^2*b^2 != (ab)^2:', str; ++prob;} + print str; } print '012: parsed squarecheck()'; /* @@ -637,20 +637,20 @@ print '012: parsed squarecheck()'; */ define powercheck(a, p1, p2, str) { - local a1, a2, a3; - local b1, b2, b3; + local a1, a2, a3; + local b1, b2, b3; - a1 = (a^p1)^p2; - a2 = (a^p2)^p1; - a3 = a^(p1*p2); - b1 = (a**p1)**p2; - b2 = (a**p2)**p1; - b3 = a**(p1*p2); - if (a1 != a2) {print '**** (a^p1)^p2 != (a^p2)^p1:', str; ++prob;} - if (a1 != a3) {print '**** (a^p1)^p2 != a^(p1*p2):', str; ++prob;} - if (b1 != b2) {print '**** (b^p1)^p2 != (b^p2)^p1:', str; ++prob;} - if (b1 != b3) {print '**** (b^p1)^p2 != b^(p1*p2):', str; ++prob;} - print str; + a1 = (a^p1)^p2; + a2 = (a^p2)^p1; + a3 = a^(p1*p2); + b1 = (a**p1)**p2; + b2 = (a**p2)**p1; + b3 = a**(p1*p2); + if (a1 != a2) {print '**** (a^p1)^p2 != (a^p2)^p1:', str; ++prob;} + if (a1 != a3) {print '**** (a^p1)^p2 != a^(p1*p2):', str; ++prob;} + if (b1 != b2) {print '**** (b^p1)^p2 != (b^p2)^p1:', str; ++prob;} + if (b1 != b3) {print '**** (b^p1)^p2 != b^(p1*p2):', str; ++prob;} + print str; } print '013: parsed powercheck()'; /* @@ -658,22 +658,22 @@ print '013: parsed powercheck()'; */ define fraccheck(a, b, c, str) { - local ab, bc, ca, aoc, boc, aob; + local ab, bc, ca, aoc, boc, aob; - ab = a * b; - bc = b * c; - ca = c * a; - aoc = ab / bc; - if (num(aoc) != a) {print '**** num(aoc) != a:', str; ++prob;} - if (den(aoc) != c) {print '**** den(aoc) != c:', str; ++prob;} - boc = ab / ca; - if (num(boc) != b) {print '**** num(boc) != b:', str; ++prob;} - if (den(boc) != c) {print '**** den(boc) != c:', str; ++prob;} - aob = ca / bc; - if (num(aob) != a) {print '**** num(aob) != a:', str; ++prob;} - if (den(aob) != b) {print '**** den(aob) != b:', str; ++prob;} - if (aob*boc != aoc) {print '**** aob*boc != aoc;', str; ++prob;} - print str; + ab = a * b; + bc = b * c; + ca = c * a; + aoc = ab / bc; + if (num(aoc) != a) {print '**** num(aoc) != a:', str; ++prob;} + if (den(aoc) != c) {print '**** den(aoc) != c:', str; ++prob;} + boc = ab / ca; + if (num(boc) != b) {print '**** num(boc) != b:', str; ++prob;} + if (den(boc) != c) {print '**** den(boc) != c:', str; ++prob;} + aob = ca / bc; + if (num(aob) != a) {print '**** num(aob) != a:', str; ++prob;} + if (den(aob) != b) {print '**** den(aob) != b:', str; ++prob;} + if (aob*boc != aoc) {print '**** aob*boc != aoc;', str; ++prob;} + print str; } print '014: parsed fraccheck()'; /* @@ -681,43 +681,43 @@ print '014: parsed fraccheck()'; */ define algcheck(a, b, str) { - local ss, ms, t1, t2, t3, t4, t5, t6, t7; - local a1, a2, a3, a4, a5, a6, a7; - local oldmul2, oldsq2; + local ss, ms, t1, t2, t3, t4, t5, t6, t7; + local a1, a2, a3, a4, a5, a6, a7; + local oldmul2, oldsq2; - oldmul2 = config("mul2", 2); - oldsq2 = config("sq2", 2); - a1 = a * b; - a2 = a * a; - a3 = b * b; - a4 = a^2; - a5 = b^2; - a6 = a2^2; - a7 = pmod(3,a-1,a); - for (ms = 2; ms < 20; ms++) { - for (ss = 2; ss < 20; ss++) { - config("mul2", ms); - config("sq2", ss); - t1 = a * b; - t2 = a * a; - t3 = b * b; - t4 = a^2; - t5 = b^2; - t6 = t2^2; - if (((ms + ss) % 37) == 4) - t7 = pmod(3,a-1,a); - if (t1 != a1) {print '**** t1 != a1:', str; ++prob;} - if (t2 != a2) {print '**** t2 != a2:', str; ++prob;} - if (t3 != a3) {print '**** t3 != a3:', str; ++prob;} - if (t4 != a4) {print '**** t4 != a4:', str; ++prob;} - if (t5 != a5) {print '**** t5 != a5:', str; ++prob;} - if (t6 != a6) {print '**** t6 != a6:', str; ++prob;} - if (t7 != a7) {print '**** t7 != a7:', str; ++prob;} - } - } - config("mul2", oldmul2); - config("sq2", oldsq2); - print str; + oldmul2 = config("mul2", 2); + oldsq2 = config("sq2", 2); + a1 = a * b; + a2 = a * a; + a3 = b * b; + a4 = a^2; + a5 = b^2; + a6 = a2^2; + a7 = pmod(3,a-1,a); + for (ms = 2; ms < 20; ms++) { + for (ss = 2; ss < 20; ss++) { + config("mul2", ms); + config("sq2", ss); + t1 = a * b; + t2 = a * a; + t3 = b * b; + t4 = a^2; + t5 = b^2; + t6 = t2^2; + if (((ms + ss) % 37) == 4) + t7 = pmod(3,a-1,a); + if (t1 != a1) {print '**** t1 != a1:', str; ++prob;} + if (t2 != a2) {print '**** t2 != a2:', str; ++prob;} + if (t3 != a3) {print '**** t3 != a3:', str; ++prob;} + if (t4 != a4) {print '**** t4 != a4:', str; ++prob;} + if (t5 != a5) {print '**** t5 != a5:', str; ++prob;} + if (t6 != a6) {print '**** t6 != a6:', str; ++prob;} + if (t7 != a7) {print '**** t7 != a7:', str; ++prob;} + } + } + config("mul2", oldmul2); + config("sq2", oldsq2); + print str; } print '015: parsed algcheck()'; /* @@ -725,78 +725,78 @@ print '015: parsed algcheck()'; */ define test_bignums() { - local a, b, c, d; + local a, b, c, d; - print '600: Beginning test_bignums'; + print '600: Beginning test_bignums'; - a = 64357824568234938591; - b = 12764632632458756817; - c = 43578234973856347982; - muldivcheck(a, b, c, '601: muldivcheck 1'); - a = 3^100; - b = 5^97; - c = 7^88; - muldivcheck(a, b, c, '602: muldivcheck 2'); - a = 2^160 - 1; - b = 2^161 - 1; - c = 2^162 - 1; - muldivcheck(a, b, c, '603: muldivcheck 3'); - a = 3^35 / 5^35; - b = 7^35 / 11^35; - c = 13^35 / 17^35; - muldivcheck(a, b, c, '604: muldivcheck 4'); - a = (10^97-1) / 9; - b = (10^53-1) / 9; - c = (10^37-1) / 9; - muldivcheck(a, b, c, '605: muldivcheck 5'); - a = 17^50; - b = 19^47; - squarecheck(a, b, '606: squarecheck 1'); - a = 2^111-1; - b = 2^17; - squarecheck(a, b, '607: squarecheck 2'); - a = 23^43 / 29^43; - b = 31^42 / 37^29; - squarecheck(a, b, '608: squarecheck 3'); - a = 4657892345743659834657238947854639; - b = 43784356784365893467659347867689; - squarecheck(a, b, '609: squarecheck 4'); - a = (10^80-1) / 9; - b = (10^50-1) / 9; - squarecheck(a, b, '610: squarecheck 5'); - a = 101^99; - b = 2 * a; - squarecheck(a, b, '611: squarecheck 6'); - a = (10^19-1) / 9; - vrfy(ptest(a, 20), '612: primetest R19'); - a = (10^23-1) / 9; - vrfy(ptest(a, 20), '613: primetest R23'); - a = 2^127 - 1; - vrfy(ptest(a, 1), '614: primetest M127'); - a = 2^521 - 1; - vrfy(ptest(a, 1), '615: primetest M521'); - powercheck(17, 127, 30, '616: powercheck 1'); - powercheck(111, 899, 6, '617: powercheck 2'); - powercheck(3, 87, 89, '618: powercheck 3'); - fraccheck(3^200, 5^173, 7^138, '619: fraccheck 1'); - fraccheck(11^100, 12^98, 13^121, '620: fraccheck 2'); - fraccheck(101^270, 103^111, 105^200, '621: fraccheck 3'); - a = 0xffff0000ffffffff00000000ffff0000000000000000ffff; - b = 0x555544440000000000000000000000000000000011112222333344440000; - c = 0x999911113333000011111111000022220000000000000000333300000000ffff; - d = 0x3333ffffffff0000000000000000ffffffffffffffff000000000000; - algcheck(a, a, '622: algcheck 1'); - algcheck(a, b, '623: algcheck 2'); - algcheck(a, c, '624: algcheck 3'); - algcheck(a, d, '625: algcheck 4'); - algcheck(b, b, '626: algcheck 5'); - algcheck(b, c, '627: algcheck 6'); - algcheck(b, d, '628: algcheck 7'); - algcheck(c, c, '629: algcheck 8'); - algcheck(c, d, '630: algcheck 9'); - algcheck(d, d, '631: algcheck 10'); + a = 64357824568234938591; + b = 12764632632458756817; + c = 43578234973856347982; + muldivcheck(a, b, c, '601: muldivcheck 1'); + a = 3^100; + b = 5^97; + c = 7^88; + muldivcheck(a, b, c, '602: muldivcheck 2'); + a = 2^160 - 1; + b = 2^161 - 1; + c = 2^162 - 1; + muldivcheck(a, b, c, '603: muldivcheck 3'); + a = 3^35 / 5^35; + b = 7^35 / 11^35; + c = 13^35 / 17^35; + muldivcheck(a, b, c, '604: muldivcheck 4'); + a = (10^97-1) / 9; + b = (10^53-1) / 9; + c = (10^37-1) / 9; + muldivcheck(a, b, c, '605: muldivcheck 5'); + a = 17^50; + b = 19^47; + squarecheck(a, b, '606: squarecheck 1'); + a = 2^111-1; + b = 2^17; + squarecheck(a, b, '607: squarecheck 2'); + a = 23^43 / 29^43; + b = 31^42 / 37^29; + squarecheck(a, b, '608: squarecheck 3'); + a = 4657892345743659834657238947854639; + b = 43784356784365893467659347867689; + squarecheck(a, b, '609: squarecheck 4'); + a = (10^80-1) / 9; + b = (10^50-1) / 9; + squarecheck(a, b, '610: squarecheck 5'); + a = 101^99; + b = 2 * a; + squarecheck(a, b, '611: squarecheck 6'); + a = (10^19-1) / 9; + vrfy(ptest(a, 20), '612: primetest R19'); + a = (10^23-1) / 9; + vrfy(ptest(a, 20), '613: primetest R23'); + a = 2^127 - 1; + vrfy(ptest(a, 1), '614: primetest M127'); + a = 2^521 - 1; + vrfy(ptest(a, 1), '615: primetest M521'); + powercheck(17, 127, 30, '616: powercheck 1'); + powercheck(111, 899, 6, '617: powercheck 2'); + powercheck(3, 87, 89, '618: powercheck 3'); + fraccheck(3^200, 5^173, 7^138, '619: fraccheck 1'); + fraccheck(11^100, 12^98, 13^121, '620: fraccheck 2'); + fraccheck(101^270, 103^111, 105^200, '621: fraccheck 3'); + a = 0xffff0000ffffffff00000000ffff0000000000000000ffff; + b = 0x555544440000000000000000000000000000000011112222333344440000; + c = 0x999911113333000011111111000022220000000000000000333300000000ffff; + d = 0x3333ffffffff0000000000000000ffffffffffffffff000000000000; + algcheck(a, a, '622: algcheck 1'); + algcheck(a, b, '623: algcheck 2'); + algcheck(a, c, '624: algcheck 3'); + algcheck(a, d, '625: algcheck 4'); + algcheck(b, b, '626: algcheck 5'); + algcheck(b, c, '627: algcheck 6'); + algcheck(b, d, '628: algcheck 7'); + algcheck(c, c, '629: algcheck 8'); + algcheck(c, d, '630: algcheck 9'); + algcheck(d, d, '631: algcheck 10'); - print '632: Ending test_bignums'; + print '632: Ending test_bignums'; } print '016: parsed test_bignums()'; @@ -812,686 +812,686 @@ print '016: parsed test_bignums()'; */ define test_functions() { - local a, b; - local pi; - local h, n, r, m, v; - local n2, m2, v2; - local t; + local a, b; + local pi; + local h, n, r, m, v; + local n2, m2, v2; + local t; - print '700: Beginning test_functions'; + print '700: Beginning test_functions'; - vrfy(abs(3) == 3, '701: abs(3) == 3'); - vrfy(abs(-4) == 4, '702: abs(-4) == 4'); - vrfy(avg(7) == 7, '703: avg(7) == 7'); - vrfy(avg(3,5) == 4, '704: avg(3,5) == 4'); - vrfy(cmp(2,3) == -1, '705: cmp(2,3) == -1'); - vrfy(cmp(6,6) == 0, '706: cmp(6,6) == 0'); - vrfy(cmp(7,4) == 1, '707: cmp(7,4) == 1'); - vrfy(comb(9,9) == 1, '708: comb(9,9) == 1'); - vrfy(comb(5,2) == 10, '709: comb(5,2) == 10'); - vrfy(conj(4) == 4, '710: conj(4) == 4'); - vrfy(conj(2-3i) == 2+3i, '711: conj(2-3i) == 2+3i'); - vrfy(den(17) == 1, '712: den(17) == 1'); - vrfy(den(3/7) == 7, '713: den(3/7) == 7'); - vrfy(den(-2/3) == 3, '714: den(-2/3) == 3'); - vrfy(digits(0) == 1, '715: digits(0) == 1'); - vrfy(digits(9) == 1, '716: digits(9) == 1'); - vrfy(digits(10) == 2, '717: digits(10) == 2'); - vrfy(digits(-691) == 3, '718: digits(-691) == 3'); - vrfy(eval('2+3') == 5, "719: eval('2+3') == 5"); - vrfy(fcnt(11,3) == 0, '720: fcnt(11,3) == 0'); - vrfy(fcnt(18,3) == 2, '721: fcnt(18,3) == 2'); - vrfy(fib(0) == 0, '722: fib(0) == 0'); - vrfy(fib(1) == 1, '723: fib(1) == 1'); - vrfy(fib(9) == 34, '724: fib(9) == 34'); - vrfy(frem(12,5) == 12, '725: frem(12,5) == 12'); - vrfy(frem(45,3) == 5, '726: frem(45,3) == 5'); - vrfy(fact(0) == 1, '727: fact(0) == 1'); - vrfy(fact(1) == 1, '728: fact(1) == 1'); - vrfy(fact(5) == 120, '729: fact(5) == 120'); - vrfy(frac(3) == 0, '730: frac(3) == 0'); - vrfy(frac(2/3) == 2/3, '731: frac(2/3) == 2/3'); - vrfy(frac(17/3) == 2/3, '732: frac(17/3) == 2/3'); - vrfy(gcd(0,3) == 3, '733: gcd(0,3) == 3'); - vrfy(gcd(1,12) == 1, '734: gcd(1,12) == 1'); - vrfy(gcd(11,7) == 1, '735: gcd(11,7) == 1'); - vrfy(gcd(20,65) == 5, '736: gcd(20,65) == 5'); - vrfy(gcdrem(20,3) == 20, '737: gcdrem(20,3) == 20'); - vrfy(gcdrem(100,6) == 25, '738: gcdrem(100,6) == 25'); - vrfy(highbit(1) == 0, '739: highbit(1) == 0'); - vrfy(highbit(15) == 3, '740: highbit(15) == 3'); - vrfy(hypot(3,4) == 5, '741: hypot(3,4) == 5'); - vrfy(ilog(90,3) == 4, '742: ilog(90,3) == 4'); - vrfy(ilog10(123) == 2, '743: ilog10(123) == 2'); - vrfy(ilog2(17) == 4, '744: ilog2(17) == 4'); - vrfy(im(3) == 0, '745: im(3) == 0'); - vrfy(im(2+3i) == 3, '746: im(2+3i) == 3'); - vrfy(fact(20) == 2432902008176640000, - '747: fact(20) == 2432902008176640000'); - vrfy(fact(100) == 100*fact(99), '748: fact(100) == 100*fact(99)'); - vrfy(comb(100,25) == 100!/75!/25!, - '749: comb(100,25) == 100!/75!/25!'); - vrfy(perm(100,50) == 100!/50!, '750: perm(100,50) == 100!/50!'); - print '751: test unused'; - print '752: test unused'; - print '753: test unused'; - print '754: test unused'; - print '755: test unused'; - print '756: test unused'; - vrfy(int(5) == 5, '757: int(5) == 5'); - vrfy(int(19/3) == 6, '758: int(19/3) == 6'); - vrfy(inverse(3/2) == 2/3, '759: inverse(3/2) == 2/3'); - vrfy(iroot(18,2) == 4, '760: iroot(18,2) == 4'); - vrfy(iroot(100,3) == 4, '761: iroot(100,3) == 4'); - vrfy(iseven(10) == 1, '762: iseven(10) == 1'); - vrfy(iseven(13) == 0, '763: iseven(13) == 0'); - vrfy(iseven('a') == 0, "764: iseven('a') == 0"); - vrfy(isint(7) == 1, '765: isint(7) == 1'); - vrfy(isint(19/2) == 0, '766: isint(19/2) == 0'); - vrfy(isint('a') == 0, "767: isint('a') == 0"); - vrfy(islist(3) == 0, '768: islist(3) == 0'); - vrfy(islist(list(2,3)) == 1, '769: islist(list(2,3)) == 1'); - vrfy(ismat(3) == 0, '770: ismat(3) == 0'); - vrfy(ismult(7,3) == 0, '771: ismult(7,3) == 0'); - vrfy(ismult(15,5) == 1, '772: ismult(15,5) == 1'); - vrfy(isnull(3) == 0, '773: isnull(3) == 0'); - vrfy(isnull(null()) == 1, '774: isnull(null()) == 1'); - vrfy(isnum(2/3) == 1, '775: isnum(2/3) == 1'); - vrfy(isnum('xx') == 0, "776: isnum('xx') == 0"); - vrfy(isobj(3) == 0, '777: isobj(3) == 0'); - vrfy(isodd(7) == 1, '778: isodd(7) == 1'); - vrfy(isodd(8) == 0, '779: isodd(8) == 0'); - vrfy(isodd('x') == 0, "780: isodd('a') == 0"); - vrfy(isqrt(27) == 5, '781: isqrt(27) == 5'); - vrfy(isreal(3) == 1, '782: isreal(3) == 1'); - vrfy(isreal('x') == 0, "783: isreal('x') == 0"); - vrfy(isreal(2+3i) == 0, '784: isreal(2+3i) == 0'); - vrfy(isstr(5) == 0, '785: isstr(5) == 0'); - vrfy(isstr('foo') == 1, "786: isstr('foo') == 1"); - vrfy(isrel(10,14) == 0, '787: isrel(10,14) == 0'); - vrfy(isrel(15,22) == 1, '788: isrel(15,22) == 1'); - vrfy(issimple(6) == 1, '789: issimple(6) == 1'); - vrfy(issimple(3-2i) == 1, '790: issimple(3-2i) == 1'); - vrfy(issimple(list(5)) == 0, '791: issimple(list(5)) == 0'); - vrfy(issq(26) == 0, '792: issq(26) == 0'); - vrfy(issq(9/4) == 1, '793: issq(9/4) == 1'); - print '794: test unused'; - vrfy(istype(9,4) == 1, '795: istype(9,4) == 1'); - vrfy(istype(3,'xx') == 0, "796: istype(3,'xx') == 0"); - vrfy(jacobi(5,11) == 1, '797: jacobi(2,7) == 1'); - vrfy(jacobi(6,13) == -1, '798: jacobi(6,13) == -1'); - vrfy(lcm(3,4,5,6) == 60, '799: lcm(3,4,5,6) == 60'); - vrfy(lcmfact(8) == 840, '800: lcmfact(8) == 840'); - vrfy(lfactor(21,5) == 3, '801: lfactor(21,5) == 3'); - vrfy(lfactor(97,20) == 1, '802: lfactor(97,20) == 1'); - vrfy(lowbit(12) == 2, '803: lowbit(12) == 2'); - vrfy(lowbit(17) == 0, '804: lowbit(17) == 0'); - vrfy(ltol(1) == 0, '805: ltol(1) == 0'); - vrfy(max(3,-9,7,4) == 7, '806: max(3,-9,7,4) == 7'); - vrfy(meq(13,33,10) == 1, '807: meq(13,33,10) == 1'); - vrfy(meq(7,19,11) == 0, '808: meq(7,19,11) == 0'); - vrfy(min(9,5,12) == 5, '809: min(9,5,12) == 5'); - vrfy(minv(13,97) == 15, '810: minv(13,97) == 15'); - vrfy(mne(16,37,10) == 1, '811: mne(16,37,10) == 1'); - vrfy(mne(46,79,11) == 0, '812: mne(46,79,11) == 0'); - vrfy(norm(4) == 16, '813: norm(4) == 16'); - vrfy(norm(2-3i) == 13, '814: norm(2-3i) == 13'); - vrfy(num(7) == 7, '815: num(7) == 7'); - vrfy(num(11/4) == 11, '816: num(11/4) == 11'); - vrfy(num(-9/5) == -9, '817: num(-9/5) == -9'); - vrfy(char(ord('a')+2) == 'c', "818: char(ord('a')+2) == 'c'"); - vrfy(perm(7,3) == 210, '819: perm(7,3) == 210'); - vrfy(pfact(10) == 210, '820: pfact(10) == 210'); - vrfy(places(3/7) == -1, '821: places(3/7) == -1'); - vrfy(places(.347) == 3, '822: places(.347) == 3'); - vrfy(places(17) == 0, '823: places(17) == 0'); - vrfy(pmod(3,36,37) == 1, '824: pmod(3,36,37) == 1'); - vrfy(poly(2,3,5,2) == 19, '825: poly(2,3,5,2) == 19'); - vrfy(ptest(101,10) == 1, '826: ptest(101,10) == 1'); - vrfy(ptest(221,30) == 0, '827: ptest(221,30) == 0'); - vrfy(re(9) == 9, '828: re(9) == 9'); - vrfy(re(-7+3i) == -7, '829: re(-7+3i) == -7'); - vrfy(scale(3,4) == 48, '830: scale(3,4) == 48'); - vrfy(sgn(-4) == -1, '831: sgn(-4) == -1'); - vrfy(sgn(0) == 0, '832: sgn(0) == 0'); - vrfy(sgn(3) == 1, '833: sgn(3) == 1'); - vrfy(size(7) == 1, '834: size(7) == 1'); - vrfy(sqrt(121) == 11, '835: sqrt(121) == 11'); - vrfy(ssq(2,3,4) == 29, '836: ssq(2,3,4) == 29'); - vrfy(str(45) == '45', "837: str(45) == '45'"); - vrfy(strcat('a','bc','def')=='abcdef', - "838: strcat('a','bc','def')=='abcdef'"); - vrfy(strlen('') == 0, "839: strlen('') == 0"); - vrfy(strlen('abcd') == 4, "840: strlen('abcd') == 4"); - vrfy(substr('abcd',2,1) == 'b', "841: substr('abcd',2,1) == 'b'"); - vrfy(substr('abcd',3,4) == 'cd', "842: substr('abcd',3,4) == 'cd'"); - vrfy(substr('abcd',1,3) == 'abc', "843: substr('abcd',1,3) == 'abc'"); - vrfy(xor(17,17) == 0, '844: xor(17,17) == 0'); - vrfy(xor(12,5) == 9, '845: xor(12,5) == 9'); - vrfy(mmin(3,7) == 3, '846: mmin(3,7) == 3'); - vrfy(mmin(4,7) == -3, '847: mmin(4,7) == -3'); - vrfy(digit(123,2) == 1, '848: digit(123,2) == 1'); - vrfy(ismult(3/4, 1/7) == 0, '849: ismult(3/4, 1/7) == 0'); - vrfy(gcd(3/4, 1/7) == 1/28, '850: gcd(3/4,1/7) == 1/28'); - vrfy(gcd(2,3,1/2) == 1/2, '851: gcd(2,3,1/2) == 1/2'); - vrfy(gcd(17,7,1/7) == 1/7, '852: gcd(17,7,1/7) == 1/7'); - vrfy(gcd(2) == 2, '853: gcd(2) == 2'); - vrfy(gcd(-2) == 2, '854: gcd(-2) == 2'); - vrfy(floor(1.5) == 1, '855: floor(1.5) == 1'); - vrfy(floor(.5) == 0, '856: floor(.5) == 0'); - vrfy(floor(-.5) == -1, '857: floor(-.5) == -1'); - vrfy(floor(-1.5) == -2, '858: floor(-1.5) == -2'); - vrfy(ceil(1.5) == 2, '859: ceil(1.5) == 2'); - vrfy(ceil(.5) == 1, '860: ceil(.5) == 1'); - vrfy(ceil(-.5) == 0, '861: ceil(-.5) == 0'); - vrfy(ceil(-1.5) == -1, '862: ceil(-1.5) == -1'); - vrfy(frac(-7.2) == -.2, '863: frac(-7.2) == -.2'); - vrfy(gcd(4, 5, 1/3) == 1/3, '864: gcd(4, 5, 1/3) == 1/3'); - vrfy(ltol(7/25) == 24/25, '865: ltol(7/25) == 24/25'); - vrfy(hmean(1,2,3) == 18/11, '866: hmean(1,2,3) == 18/11'); - vrfy(ilog2(2^-20) == -20, '867: ilog2(2^-20) == -20'); - vrfy(ord("DBell") == 68, '868: ord("DBell") == 68'); - vrfy(cmp("a","b") == -1, '869: cmp("a","b") == -1'); - vrfy(cmp("abcd","abc") == 1, '870: cmp("abcd","abc") == 1'); - vrfy(cmp(3,4i) == 1-1i, '871: cmp(3,4i) == 1-1i'); - vrfy(cmp(4,4i) == 1-1i, '872: cmp(4,4i) == 1-1i'); - vrfy(cmp(5,4i) == 1-1i, '873: cmp(5,4i) == 1-1i'); - vrfy(cmp(-5,4i) == -1-1i, '874: cmp(-5,4i) == -1-1i'); - vrfy(cmp(-4i,5) == -1-1i, '875: cmp(-4i,5) == -1-1i'); - vrfy(cmp(-4i,-5) == 1-1i, '876: cmp(-4i,-5) == 1-1i'); - vrfy(cmp(3i,4i) == -1i, '877: cmp(3i,4i) == -1i'); - vrfy(cmp(4i,4i) == 0, '878: cmp(4i,4i) == 0'); - vrfy(cmp(5i,4i) == 1i, '879: cmp(5i,4i) == 1i'); - vrfy(cmp(3+4i,5) == -1+1i, '880: cmp(3+4i,5) == -1+1i'); - vrfy(cmp(3+4i,-5) == 1+1i, '881: cmp(3+4i,-5) == 1+1i'); - vrfy(cmp(3+4i,3+4i) == 0, '882: cmp(3+4i,3+4i) == 0'); - vrfy(cmp(3+4i,3-4i) == 1i, '883: cmp(3+4i,3-4i) == 1i'); - vrfy(cmp(3+4i,2+3i) == 1+1i, '884: cmp(3+4i,2+3i) == 1+1i'); - vrfy(cmp(3+4i,-4-5i) == 1+1i, '885: cmp(3+4i,-4-5i) == 1+1i'); - vrfy(comb(7,0) == 1, '886: comb(7,0) == 1'); - vrfy(comb(0,0) == 1, '887: comb(0,0) == 1'); - vrfy(perm(7,0) == 1, '888: perm(7,0) == 1'); - vrfy(perm(0,0) == 1, '889: perm(0,0) == 1'); - vrfy(isfile(files(0)) == 1, '890: isfile(files(0)) == 1'); - vrfy(isfile(0) == 0, '891: isfile(0) == 0'); - vrfy(ismult(4^67, 2^59) == 1, '892: ismult(4^67, 2^59) == 1'); - vrfy(ismult(13, 4/67) == 0, '893: ismult(13, 4/67) == 0'); - vrfy(ismult(13, 7/56) == 1, '894: ismult(13, 7/56) == 1'); - vrfy(isnum(2i) == 1, '895: isnum(2i) == 1'); - vrfy(iseven(1/3) == 0, '896: iseven(1/3) == 0'); - vrfy(isodd(1/3) == 0, '897: isodd(1/3) == 0'); - vrfy(isrel(-5, 6) == 1, '898: isrel(-5, 6) == 1'); - vrfy(isrel(-2, 6) == 0, '899: isrel(-2, 6) == 0'); - vrfy(bit(9,0) == 1, '900: bit(9,0) == 1'); - vrfy(bit(9,1) == 0, '901: bit(9,1) == 0'); - vrfy(bit(9,2) == 0, '902: bit(9,2) == 0'); - vrfy(bit(9,3) == 1, '903: bit(9,3) == 1'); - vrfy(bit(1.25, -2) == 1, '904: bit(1.25, -2) == 1'); - vrfy(bit(1.25, -1) == 0, '905: bit(1.25, -1) == 0'); - vrfy(bit(1.25, 0) == 1, '906: bit(1.25, 0) == 1'); - vrfy(bit(pi(), 1) == 1, '907: bit(pi(), 1) == 1'); - vrfy(bit(pi(), -2) == 0, '908: bit(pi(), -2) == 0'); - vrfy(bit(pi(), -3) == 1, '909: bit(pi(), -3) == 1'); - vrfy(istype(2, 3.0) == 1, '910: istype(2, 3.0) == 1'); - vrfy(istype(2, "2") == 0, '911: istype(2, "2") == 0'); - vrfy(istype(2, 3i) == 0, '912: istype(2, 3i) == 0'); - vrfy(istype(2i+2, 3i) == 1, '913: istype(2i+2, 3i) == 1'); - a = epsilon(); - print '914: a = epsilon()'; - vrfy(epsilon(a) == epsilon(), '915: epsilon(a) == epsilon()'); - vrfy(epsilon(a) == epsilon(), '916: epsilon(a) == epsilon()'); - vrfy(epsilon(a) == epsilon(), '917: epsilon(a) == epsilon()'); - vrfy(epsilon() == a, '918: epsilon() == a'); - b = 1e-6; - print '919: b = 1e-6'; - vrfy(epsilon(b) == a, '920: epsilon(b) == a'); - vrfy(epsilon(b) == epsilon(), '921: epsilon(b) == epsilon()'); - vrfy(epsilon(b) == epsilon(), '922: epsilon(b) == epsilon()'); - vrfy(epsilon(b) == epsilon(), '923: epsilon(b) == epsilon()'); - vrfy(epsilon() == 1e-6, '924: epsilon() == 1e-6'); - vrfy(epsilon(a) == b, '925: epsilon(a) == b'); - vrfy(epsilon(a) == epsilon(), '926: epsilon(a) == epsilon()'); - vrfy(epsilon(a) == epsilon(), '927: epsilon(a) == epsilon()'); - vrfy(epsilon(a) == epsilon(), '928: epsilon(a) == epsilon()'); - vrfy(epsilon(a) == a, '929: epsilon(a) == a'); - vrfy(quomod(13,5,a,b) == 1, '930: quomod(13,5,a,b) == 1'); - vrfy(a == 2, '931: a == 2'); - vrfy(b == 3, '932: b == 3'); - vrfy(quomod(15.6,5.2,a,b) == 0, '933: quomod(15.6,5.2,a,b) == 0'); - vrfy(a == 3, '934: a == 3'); - vrfy(b == 0, '935: b == 0'); - vrfy(putenv("abcd=efg") == 0, '936: putenv("abcd=efg")'); - vrfy(getenv("abcd") == "efg", '937: getenv("abcd") == "efg"'); - vrfy(putenv("abcd","123")==0, '938: putenv("abcd","123")'); - vrfy(getenv("abcd") == "123", '939: getenv("abcd") == "123"'); - vrfy(isnull(getenv("notavar")) == 1, - '940: isnull(getenv("notavar")) == 1'); - a = "abcdefg"; - print '941: a = "abcdefg"'; - vrfy(strpos(a, "c") == 3, '942: strpos(a, "c") == 3'); - vrfy(strpos(a, "def") == 4, '943: strpos(a, "def") == 4'); - vrfy(strpos(a, "defg") == 4, '944: strpos(a, "defg") == 4'); - vrfy(strpos(a, "defgh") == 0, '945: strpos(a, "defgh") == 0'); - 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'); - if (config("windows") || config("cygwin")) { - print '949: test skipped for windows or cygwin systems'; - print '950: test skipped for windows or cygwin 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'; - vrfy(isstr(cmdbuf()) == 1, '954: isstr(cmdbuf()) == 1'); - vrfy(abs(root(4,3,0.1)-1.5874) < 0.1, - '955: abs(root(4,3,0.1)-1.5874) < 0.1'); - print '956: a = 2^300 + 69962309754533779525365054067'; - a = 2^300 + 69962309754533779525365054067; - a /= 2^211; - print '957: a /= 2^211'; - vrfy(appr(a, 1e-20) == 2^89, '958: appr(a, 1e-20) == 2^89'); - vrfy(digits(5e149) == 150, '959: digits(5e149) == 150'); - vrfy(highbit(2) == 1, '960: highbit(2) == 1'); - vrfy(highbit(3) == 1, '961: highbit(3) == 1'); - vrfy(highbit(4) == 2, '962: highbit(4) == 2'); - vrfy(highbit(-15) == 3, '963: highbit(-15) == 3'); - vrfy(highbit(2^27) == 27, '964: highbit(2^27) == 27'); - a = 12.34; - print '965: a = 12.34'; - vrfy(digit(a,2) == 0, '966: digit(a,2) == 0'); - vrfy(digit(a,1) == 1, '967: digit(a,1) == 1'); - vrfy(digit(a,0) == 2, '968: digit(a,0) == 2'); - vrfy(digit(a,-1) == 3, '969: digit(a,-1) == 3'); - vrfy(digit(a,-2) == 4, '970: digit(a,-2) == 4'); - a = 10/7; - print '971: a = 10/7'; - vrfy(digit(a,1) == 0, '972: digit(a,1) == 0'); - vrfy(digit(a,0) == 1, '973: digit(a,0) == 1'); - vrfy(digit(a,-1) == 4, '974: digit(a,-1) == 4'); - vrfy(digit(a,-2) == 2, '975: digit(a,-2) == 2'); - vrfy(digit(a,-3) == 8, '976: digit(a,-3) == 8'); - vrfy(digits(0) == 1, '977: digits(0) == 1'); - vrfy(digits(0.0123) == 1, '978: digits(0.0123) == 1'); - vrfy(digits(3.7) == 1, '979: digits(3.7) == 1'); - vrfy(digits(-27) == 2, '980: digits(-27) == 2'); - vrfy(digits(-99.7) == 2, '981: digits(-99.7) == 2'); - vrfy(ilog2(1) == 0, '982: ilog2(1) == 0'); - vrfy(ilog2(2) == 1, '983: ilog2(2) == 1'); - vrfy(ilog2(3) == 1, '984: ilog2(3) == 1'); - vrfy(ilog2(4) == 2, '985: ilog2(4) == 2'); - vrfy(ilog2(1/15) == -4, '986: ilog2(1/15) == -4'); - vrfy(places(3) == 0, '987: places(3) == 0'); - vrfy(places(0.0123) == 4, '988: places(0.0123) == 4'); - vrfy(places(3.70) == 1, '989: places(3.70) == 1'); - vrfy(places(1e-10) == 10, '990: places(1e-10) == 10'); - vrfy(places(3/7) == -1, '991: places(/37) == -1'); - vrfy(ilog10(7.7) == 0, '992: ilog10(7.7) == 0'); - vrfy(ilog10(77.7) == 1, '993: ilog10(77.7) == 1'); - vrfy(ilog10(777) == 2, '994: ilog10(777) == 2'); - vrfy(ilog10(.00777) == -3, '995: ilog10(.00777) == -3'); - vrfy(ilog10(1e27) == 27, '996: ilog10(1e27) == 27'); - vrfy(lowbit(2) == 1, '997: lowbit(2) == 1'); - vrfy(lowbit(3) == 0, '998: lowbit(3) == 0'); - vrfy(lowbit(4) == 2, '999: lowbit(4) == 2'); - vrfy(lowbit(-15) == 0, '1000: lowbit(-15) == 0'); - vrfy(lowbit(2^27) == 27, '1001: lowbit(2^27) == 27'); - vrfy(char(0102) == 'B', '1002: char(0102) == \'B\''); - vrfy(char(0x6f) == 'o', '1003: char(0x6f) == \'o\''); - vrfy(char(119) == 'w', '1004: char(119) == \'w\''); - vrfy(char(0145) == 'e', '1005: char(0145) == \'e\''); - vrfy(char(0x6e) == 'n', '1006: char(0x6e) == \'n\''); - vrfy(den(-1.25) == 4, '1007: den(-1.25) == 4'); - vrfy(den(121/33) == 3, '1008: den(121/33) == 3'); - vrfy(gcd(9/10, 11/5, 4/25) == 0.02, - '1009: gcd(9/10, 11/5, 4/25) == 0.02'); - vrfy(gcd(0,0,0,0,0) == 0, '1010: gcd(0,0,0,0,0) == 0'); - vrfy(hypot(3, 4, 1e-6) == 5, '1011: hypot(3, 4, 1e-6) == 5'); - vrfy(hypot(2,-3,1e-6) == 3605551/1e6, - '1012: hypot(2,-3,1e-6) == 3605551/1e6'); - vrfy(im(-4.25 - 7i) == -7, '1013: im(-4.25 - 7i) == -7'); - vrfy(lcm(12, -24, 30) == -120,'1014: lcm(12, -24, 30) == -120'); - vrfy(lcm(9/10, 11/5, 4/25) == 79.2, - '1015: lcm(9/10, 11/5, 4/25) == 79.2'); - vrfy(lcm(2) == 2, '1016: lcm(2) == 2'); - vrfy(max(2) == 2, '1017: max(2) == 2'); - vrfy(min(2) == 2, '1018: min(2) == 2'); - vrfy(re(-4.25 - 7i) == -4.25, '1019: re(-4.25 - 7i) == -4.25'); - vrfy(size("abc") == 3, '1020: size("abc") == 3'); - vrfy(str("") == "", '1021: str("") == ""'); - vrfy(str(null()) == "", '1022: str(null()) == ""'); - vrfy(str("Ernest Bowen") == "Ernest Bowen", - '1023: str("Ernest Bowen") == "Ernest Bowen"'); - vrfy(strlen("a b\tc\\d") == 7, - '1024: strlen("a b\tc\\d") == 7'); - vrfy(xor(2) == 2, '1025: xor(2) == 2'); - vrfy(xor(5, 3, 7, 2, 9) == 10, - '1026: xor(5, 3, 7, 2, 9) == 10'); - vrfy(xor(0,0) == 0, '1027: xor(0,0) == 0'); - vrfy(xor(0,1) == 1, '1028: xor(0,1) == 1'); - vrfy(xor(1,0) == 1, '1029: xor(1,0) == 1'); - vrfy(xor(1,1) == 0, '1030: xor(1,1) == 0'); - vrfy(xor(5,3,-7,2,9) == -12, '1031: xor(5,3,-7,2,9) == -12'); - vrfy(fib(-2) == -1, '1032: fib(-2) == -1'); - vrfy(fib(-1) == 1, '1033: fib(-1) == 1'); - vrfy(fib(-10) == -55, '1034: fib(-10) == -55'); - vrfy(ilog(1/8, 3) == -2, '1035: ilog(1/8, 3) == -2'); - vrfy(ilog(8.9, 3) == 1, '1036: ilog(8.9, 3) == 1'); - vrfy(iroot(1,9) == 1, '1037: iroot(1,9) == 1'); - vrfy(iroot(pi()^8,5) == 6, '1038: iroot(pi()^8,5)'); - vrfy(isqrt(8.5) == 2, '1039: isqrt(8.5) == 2'); - vrfy(isqrt(2e56) == 14142135623730950488016887242, - '1040: isqrt(2e56) == 14142135623730950488016887242'); - vrfy(near(22/7, 3.15, .01) == -1, - '1041: near(22/7, 3.15, .01) == -1'); - vrfy(near(22/7, 3.15, .005) == 1, - '1042: near(22/7, 3.15, .005) == 1'); - vrfy(norm(3.4) == 11.56, '1043: isqrt(3.4) == 11.56'); - vrfy(pi(1e-5) == 3.14159, '1044: pi(1e-5) == 3.14159'); - pi = pi(1e-10); - print '1045: pi = pi(1e-10)'; - vrfy(pi == 3.1415926536, '1046: pi == 3.1415926536'); - vrfy(polar(2,pi/2,1e-5)==2i, '1047: polar(2,pi/2,1e-5)==2i'); - vrfy(power(exp(1,1e-20),pi(1e-20)*1i/2,1e-20) == 1i, - '1048: power(exp(1,1e-20),pi(1e-20)*1i/2,1e-20) == 1i'); - vrfy(ssq(1+2i, 3-4i, 5 +6i) == -21+40i, - '1049: ssq(1+2i, 3-4i, 5 +6i) == -21+40i'); - vrfy(isreal(ln(1 + 1e-10i, 1e-5)), - '1050: isreal(ln(1 + 1e-10i, 1e-5))'); - vrfy(isreal(exp(pi(1e-10)*1i, 1e-5)), - '1051: isreal(exp(pi(1e-10)*1i, 1e-5))'); - vrfy(cfappr(43/30, 10, 0) == 10/7, - '1052: cfappr(43/30, 10, 0) == 10/7'); - vrfy(cfappr(43/30, 10, 1) == 13/9, - '1053: cfappr(43/30, 10, 1) == 13/9'); - vrfy(cfappr(43/30, 10, 16) == 10/7, - '1054: cfappr(43/30, 10, 16) == 10/7'); - vrfy(cfappr(6/5, 1/2, 16) == 1, - '1055: cfappr(6/5, 1/2, 16) == 1'); - vrfy(cfsim(13,8) == 0, '1056: cfsim(13,8) == 0'); - vrfy(cfsim(1057,8) == 0, '1057: cfsim(1057,8) == 0'); - vrfy(mod(11,5,0) == 1, '1058: mod(11,5,0) == 1'); - vrfy(mod(11,5,1) == -4, '1059: mod(11,5,1) == -4'); - vrfy(mod(-11,5,2) == -1, '1060: mod(-11,5,2) == -1'); - vrfy(mod(-11,-5,3) == 4, '1061: mod(-11,-5,3) == 4'); - vrfy(mod(12.5,5,16) == 2.5, '1062: mod(12.5,5,16) == 2.5'); - vrfy(mod(12.5,5,17) == -2.5, '1063: mod(12.5,5,17) == -2.5'); - vrfy(mod(12.5,5,24) == 2.5, '1064: mod(12.5,5,24) == 2.5'); - vrfy(mod(-7.5,-5,24) == 2.5, '1065: mod(-7.5,-5,24) == 2.5'); - vrfy(quo(11,5,0) == 2, '1066: quo(11,5,0) == 2'); - vrfy(quo(11,5,1) == 3, '1067: quo(11,5,1) == 3'); - vrfy(quo(-11,5,2) == -2, '1068: quo(-11,5,2) == -2'); - vrfy(quo(-11,-5,3) == 3, '1069: quo(-11,-5,3) == 3'); - vrfy(quo(12.5,5,16) == 2, '1070: quo(12.5,5,16) == 2'); - vrfy(quo(12.5,5,17) == 3, '1071: quo(12.5,5,17) == 3'); - vrfy(quo(12.5,5,24) == 2, '1072: quo(12.5,5,24) == 2'); - vrfy(quo(-7.5,-5,24) == 2, '1073: quo(-7.5,-5,24) == 2'); - vrfy(frac(2.5 + 3i) == .5, '1074: frac(2.5 + 3i) == .5'); - vrfy(root(1i,1000,1e-2)==1, '1075: root(1i,1000,1e-2) == 1'); - vrfy(scale(2+3i,2)==8+12i, '1076: scale(2+3i,2) == 8+12i'); - vrfy(frem(8,4) == 2, '1077: frem(8,4) == 2'); - vrfy(jacobi(80,199) == 1, '1078: jacobi(80,199) == 1'); - vrfy(test(1), '1079: test(1)'); - vrfy(!test(0), '1080: !test(0)'); - vrfy(hnrmod(2^177-1,1,177,-1)==0, - '1081: hnrmod(2^177-1,1,177,-1)==0'); - vrfy(hnrmod(2^178-2,1,177,-1)==0, - '1082: hnrmod(2^178-2,1,177,-1)==0'); - vrfy(hnrmod(2^178-3,1,177,1)==2^177-4, - '1083: hnrmod(2^178-3,1,177,1)==2^177-4'); - vrfy(hnrmod(2^179-4,1,177,0)==2^177-4, - '1084: hnrmod(2^179-4,1,177,0)==2^177-4'); - vrfy(hnrmod(1234567^2,13,17,-1)==1155404, - '1085: hnrmod(1234567^2,13,17,-1)==1155404'); - vrfy(hnrmod(3276^54,45,415,1)==3276^54%(45*2^415+1), - '1086: hnrmod(3276^54,45,415,1)==3276^54%(45*2^415+1)'); - vrfy(hnrmod(3276^54,45,415,0)==3276^54%(45*2^415), - '1087: hnrmod(3276^54,45,415,0)==3276^54%(45*2^415)'); - vrfy(hnrmod(3276^54,45,415,-1)==3276^54%(45*2^415-1), - '1088: hnrmod(3276^54,45,415,-1)==3276^54%(45*2^415-1)'); - vrfy(hnrmod(10^40, 17, 51, 1) == 33827019788296445, - '1089: hnrmod(10^40, 17, 51, 1) == 33827019788296445'); - vrfy(hnrmod(3192487935759423423521,16,65,1)==241008883965895164956, - '1090: hnrmod(3192487935759423423521,16,65,1)==241008883965895164956'); + vrfy(abs(3) == 3, '701: abs(3) == 3'); + vrfy(abs(-4) == 4, '702: abs(-4) == 4'); + vrfy(avg(7) == 7, '703: avg(7) == 7'); + vrfy(avg(3,5) == 4, '704: avg(3,5) == 4'); + vrfy(cmp(2,3) == -1, '705: cmp(2,3) == -1'); + vrfy(cmp(6,6) == 0, '706: cmp(6,6) == 0'); + vrfy(cmp(7,4) == 1, '707: cmp(7,4) == 1'); + vrfy(comb(9,9) == 1, '708: comb(9,9) == 1'); + vrfy(comb(5,2) == 10, '709: comb(5,2) == 10'); + vrfy(conj(4) == 4, '710: conj(4) == 4'); + vrfy(conj(2-3i) == 2+3i, '711: conj(2-3i) == 2+3i'); + vrfy(den(17) == 1, '712: den(17) == 1'); + vrfy(den(3/7) == 7, '713: den(3/7) == 7'); + vrfy(den(-2/3) == 3, '714: den(-2/3) == 3'); + vrfy(digits(0) == 1, '715: digits(0) == 1'); + vrfy(digits(9) == 1, '716: digits(9) == 1'); + vrfy(digits(10) == 2, '717: digits(10) == 2'); + vrfy(digits(-691) == 3, '718: digits(-691) == 3'); + vrfy(eval('2+3') == 5, "719: eval('2+3') == 5"); + vrfy(fcnt(11,3) == 0, '720: fcnt(11,3) == 0'); + vrfy(fcnt(18,3) == 2, '721: fcnt(18,3) == 2'); + vrfy(fib(0) == 0, '722: fib(0) == 0'); + vrfy(fib(1) == 1, '723: fib(1) == 1'); + vrfy(fib(9) == 34, '724: fib(9) == 34'); + vrfy(frem(12,5) == 12, '725: frem(12,5) == 12'); + vrfy(frem(45,3) == 5, '726: frem(45,3) == 5'); + vrfy(fact(0) == 1, '727: fact(0) == 1'); + vrfy(fact(1) == 1, '728: fact(1) == 1'); + vrfy(fact(5) == 120, '729: fact(5) == 120'); + vrfy(frac(3) == 0, '730: frac(3) == 0'); + vrfy(frac(2/3) == 2/3, '731: frac(2/3) == 2/3'); + vrfy(frac(17/3) == 2/3, '732: frac(17/3) == 2/3'); + vrfy(gcd(0,3) == 3, '733: gcd(0,3) == 3'); + vrfy(gcd(1,12) == 1, '734: gcd(1,12) == 1'); + vrfy(gcd(11,7) == 1, '735: gcd(11,7) == 1'); + vrfy(gcd(20,65) == 5, '736: gcd(20,65) == 5'); + vrfy(gcdrem(20,3) == 20, '737: gcdrem(20,3) == 20'); + vrfy(gcdrem(100,6) == 25, '738: gcdrem(100,6) == 25'); + vrfy(highbit(1) == 0, '739: highbit(1) == 0'); + vrfy(highbit(15) == 3, '740: highbit(15) == 3'); + vrfy(hypot(3,4) == 5, '741: hypot(3,4) == 5'); + vrfy(ilog(90,3) == 4, '742: ilog(90,3) == 4'); + vrfy(ilog10(123) == 2, '743: ilog10(123) == 2'); + vrfy(ilog2(17) == 4, '744: ilog2(17) == 4'); + vrfy(im(3) == 0, '745: im(3) == 0'); + vrfy(im(2+3i) == 3, '746: im(2+3i) == 3'); + vrfy(fact(20) == 2432902008176640000, + '747: fact(20) == 2432902008176640000'); + vrfy(fact(100) == 100*fact(99), '748: fact(100) == 100*fact(99)'); + vrfy(comb(100,25) == 100!/75!/25!, + '749: comb(100,25) == 100!/75!/25!'); + vrfy(perm(100,50) == 100!/50!, '750: perm(100,50) == 100!/50!'); + print '751: test unused'; + print '752: test unused'; + print '753: test unused'; + print '754: test unused'; + print '755: test unused'; + print '756: test unused'; + vrfy(int(5) == 5, '757: int(5) == 5'); + vrfy(int(19/3) == 6, '758: int(19/3) == 6'); + vrfy(inverse(3/2) == 2/3, '759: inverse(3/2) == 2/3'); + vrfy(iroot(18,2) == 4, '760: iroot(18,2) == 4'); + vrfy(iroot(100,3) == 4, '761: iroot(100,3) == 4'); + vrfy(iseven(10) == 1, '762: iseven(10) == 1'); + vrfy(iseven(13) == 0, '763: iseven(13) == 0'); + vrfy(iseven('a') == 0, "764: iseven('a') == 0"); + vrfy(isint(7) == 1, '765: isint(7) == 1'); + vrfy(isint(19/2) == 0, '766: isint(19/2) == 0'); + vrfy(isint('a') == 0, "767: isint('a') == 0"); + vrfy(islist(3) == 0, '768: islist(3) == 0'); + vrfy(islist(list(2,3)) == 1, '769: islist(list(2,3)) == 1'); + vrfy(ismat(3) == 0, '770: ismat(3) == 0'); + vrfy(ismult(7,3) == 0, '771: ismult(7,3) == 0'); + vrfy(ismult(15,5) == 1, '772: ismult(15,5) == 1'); + vrfy(isnull(3) == 0, '773: isnull(3) == 0'); + vrfy(isnull(null()) == 1, '774: isnull(null()) == 1'); + vrfy(isnum(2/3) == 1, '775: isnum(2/3) == 1'); + vrfy(isnum('xx') == 0, "776: isnum('xx') == 0"); + vrfy(isobj(3) == 0, '777: isobj(3) == 0'); + vrfy(isodd(7) == 1, '778: isodd(7) == 1'); + vrfy(isodd(8) == 0, '779: isodd(8) == 0'); + vrfy(isodd('x') == 0, "780: isodd('a') == 0"); + vrfy(isqrt(27) == 5, '781: isqrt(27) == 5'); + vrfy(isreal(3) == 1, '782: isreal(3) == 1'); + vrfy(isreal('x') == 0, "783: isreal('x') == 0"); + vrfy(isreal(2+3i) == 0, '784: isreal(2+3i) == 0'); + vrfy(isstr(5) == 0, '785: isstr(5) == 0'); + vrfy(isstr('foo') == 1, "786: isstr('foo') == 1"); + vrfy(isrel(10,14) == 0, '787: isrel(10,14) == 0'); + vrfy(isrel(15,22) == 1, '788: isrel(15,22) == 1'); + vrfy(issimple(6) == 1, '789: issimple(6) == 1'); + vrfy(issimple(3-2i) == 1, '790: issimple(3-2i) == 1'); + vrfy(issimple(list(5)) == 0, '791: issimple(list(5)) == 0'); + vrfy(issq(26) == 0, '792: issq(26) == 0'); + vrfy(issq(9/4) == 1, '793: issq(9/4) == 1'); + print '794: test unused'; + vrfy(istype(9,4) == 1, '795: istype(9,4) == 1'); + vrfy(istype(3,'xx') == 0, "796: istype(3,'xx') == 0"); + vrfy(jacobi(5,11) == 1, '797: jacobi(2,7) == 1'); + vrfy(jacobi(6,13) == -1, '798: jacobi(6,13) == -1'); + vrfy(lcm(3,4,5,6) == 60, '799: lcm(3,4,5,6) == 60'); + vrfy(lcmfact(8) == 840, '800: lcmfact(8) == 840'); + vrfy(lfactor(21,5) == 3, '801: lfactor(21,5) == 3'); + vrfy(lfactor(97,20) == 1, '802: lfactor(97,20) == 1'); + vrfy(lowbit(12) == 2, '803: lowbit(12) == 2'); + vrfy(lowbit(17) == 0, '804: lowbit(17) == 0'); + vrfy(ltol(1) == 0, '805: ltol(1) == 0'); + vrfy(max(3,-9,7,4) == 7, '806: max(3,-9,7,4) == 7'); + vrfy(meq(13,33,10) == 1, '807: meq(13,33,10) == 1'); + vrfy(meq(7,19,11) == 0, '808: meq(7,19,11) == 0'); + vrfy(min(9,5,12) == 5, '809: min(9,5,12) == 5'); + vrfy(minv(13,97) == 15, '810: minv(13,97) == 15'); + vrfy(mne(16,37,10) == 1, '811: mne(16,37,10) == 1'); + vrfy(mne(46,79,11) == 0, '812: mne(46,79,11) == 0'); + vrfy(norm(4) == 16, '813: norm(4) == 16'); + vrfy(norm(2-3i) == 13, '814: norm(2-3i) == 13'); + vrfy(num(7) == 7, '815: num(7) == 7'); + vrfy(num(11/4) == 11, '816: num(11/4) == 11'); + vrfy(num(-9/5) == -9, '817: num(-9/5) == -9'); + vrfy(char(ord('a')+2) == 'c', "818: char(ord('a')+2) == 'c'"); + vrfy(perm(7,3) == 210, '819: perm(7,3) == 210'); + vrfy(pfact(10) == 210, '820: pfact(10) == 210'); + vrfy(places(3/7) == -1, '821: places(3/7) == -1'); + vrfy(places(.347) == 3, '822: places(.347) == 3'); + vrfy(places(17) == 0, '823: places(17) == 0'); + vrfy(pmod(3,36,37) == 1, '824: pmod(3,36,37) == 1'); + vrfy(poly(2,3,5,2) == 19, '825: poly(2,3,5,2) == 19'); + vrfy(ptest(101,10) == 1, '826: ptest(101,10) == 1'); + vrfy(ptest(221,30) == 0, '827: ptest(221,30) == 0'); + vrfy(re(9) == 9, '828: re(9) == 9'); + vrfy(re(-7+3i) == -7, '829: re(-7+3i) == -7'); + vrfy(scale(3,4) == 48, '830: scale(3,4) == 48'); + vrfy(sgn(-4) == -1, '831: sgn(-4) == -1'); + vrfy(sgn(0) == 0, '832: sgn(0) == 0'); + vrfy(sgn(3) == 1, '833: sgn(3) == 1'); + vrfy(size(7) == 1, '834: size(7) == 1'); + vrfy(sqrt(121) == 11, '835: sqrt(121) == 11'); + vrfy(ssq(2,3,4) == 29, '836: ssq(2,3,4) == 29'); + vrfy(str(45) == '45', "837: str(45) == '45'"); + vrfy(strcat('a','bc','def')=='abcdef', + "838: strcat('a','bc','def')=='abcdef'"); + vrfy(strlen('') == 0, "839: strlen('') == 0"); + vrfy(strlen('abcd') == 4, "840: strlen('abcd') == 4"); + vrfy(substr('abcd',2,1) == 'b', "841: substr('abcd',2,1) == 'b'"); + vrfy(substr('abcd',3,4) == 'cd', "842: substr('abcd',3,4) == 'cd'"); + vrfy(substr('abcd',1,3) == 'abc', "843: substr('abcd',1,3) == 'abc'"); + vrfy(xor(17,17) == 0, '844: xor(17,17) == 0'); + vrfy(xor(12,5) == 9, '845: xor(12,5) == 9'); + vrfy(mmin(3,7) == 3, '846: mmin(3,7) == 3'); + vrfy(mmin(4,7) == -3, '847: mmin(4,7) == -3'); + vrfy(digit(123,2) == 1, '848: digit(123,2) == 1'); + vrfy(ismult(3/4, 1/7) == 0, '849: ismult(3/4, 1/7) == 0'); + vrfy(gcd(3/4, 1/7) == 1/28, '850: gcd(3/4,1/7) == 1/28'); + vrfy(gcd(2,3,1/2) == 1/2, '851: gcd(2,3,1/2) == 1/2'); + vrfy(gcd(17,7,1/7) == 1/7, '852: gcd(17,7,1/7) == 1/7'); + vrfy(gcd(2) == 2, '853: gcd(2) == 2'); + vrfy(gcd(-2) == 2, '854: gcd(-2) == 2'); + vrfy(floor(1.5) == 1, '855: floor(1.5) == 1'); + vrfy(floor(.5) == 0, '856: floor(.5) == 0'); + vrfy(floor(-.5) == -1, '857: floor(-.5) == -1'); + vrfy(floor(-1.5) == -2, '858: floor(-1.5) == -2'); + vrfy(ceil(1.5) == 2, '859: ceil(1.5) == 2'); + vrfy(ceil(.5) == 1, '860: ceil(.5) == 1'); + vrfy(ceil(-.5) == 0, '861: ceil(-.5) == 0'); + vrfy(ceil(-1.5) == -1, '862: ceil(-1.5) == -1'); + vrfy(frac(-7.2) == -.2, '863: frac(-7.2) == -.2'); + vrfy(gcd(4, 5, 1/3) == 1/3, '864: gcd(4, 5, 1/3) == 1/3'); + vrfy(ltol(7/25) == 24/25, '865: ltol(7/25) == 24/25'); + vrfy(hmean(1,2,3) == 18/11, '866: hmean(1,2,3) == 18/11'); + vrfy(ilog2(2^-20) == -20, '867: ilog2(2^-20) == -20'); + vrfy(ord("DBell") == 68, '868: ord("DBell") == 68'); + vrfy(cmp("a","b") == -1, '869: cmp("a","b") == -1'); + vrfy(cmp("abcd","abc") == 1, '870: cmp("abcd","abc") == 1'); + vrfy(cmp(3,4i) == 1-1i, '871: cmp(3,4i) == 1-1i'); + vrfy(cmp(4,4i) == 1-1i, '872: cmp(4,4i) == 1-1i'); + vrfy(cmp(5,4i) == 1-1i, '873: cmp(5,4i) == 1-1i'); + vrfy(cmp(-5,4i) == -1-1i, '874: cmp(-5,4i) == -1-1i'); + vrfy(cmp(-4i,5) == -1-1i, '875: cmp(-4i,5) == -1-1i'); + vrfy(cmp(-4i,-5) == 1-1i, '876: cmp(-4i,-5) == 1-1i'); + vrfy(cmp(3i,4i) == -1i, '877: cmp(3i,4i) == -1i'); + vrfy(cmp(4i,4i) == 0, '878: cmp(4i,4i) == 0'); + vrfy(cmp(5i,4i) == 1i, '879: cmp(5i,4i) == 1i'); + vrfy(cmp(3+4i,5) == -1+1i, '880: cmp(3+4i,5) == -1+1i'); + vrfy(cmp(3+4i,-5) == 1+1i, '881: cmp(3+4i,-5) == 1+1i'); + vrfy(cmp(3+4i,3+4i) == 0, '882: cmp(3+4i,3+4i) == 0'); + vrfy(cmp(3+4i,3-4i) == 1i, '883: cmp(3+4i,3-4i) == 1i'); + vrfy(cmp(3+4i,2+3i) == 1+1i, '884: cmp(3+4i,2+3i) == 1+1i'); + vrfy(cmp(3+4i,-4-5i) == 1+1i, '885: cmp(3+4i,-4-5i) == 1+1i'); + vrfy(comb(7,0) == 1, '886: comb(7,0) == 1'); + vrfy(comb(0,0) == 1, '887: comb(0,0) == 1'); + vrfy(perm(7,0) == 1, '888: perm(7,0) == 1'); + vrfy(perm(0,0) == 1, '889: perm(0,0) == 1'); + vrfy(isfile(files(0)) == 1, '890: isfile(files(0)) == 1'); + vrfy(isfile(0) == 0, '891: isfile(0) == 0'); + vrfy(ismult(4^67, 2^59) == 1, '892: ismult(4^67, 2^59) == 1'); + vrfy(ismult(13, 4/67) == 0, '893: ismult(13, 4/67) == 0'); + vrfy(ismult(13, 7/56) == 1, '894: ismult(13, 7/56) == 1'); + vrfy(isnum(2i) == 1, '895: isnum(2i) == 1'); + vrfy(iseven(1/3) == 0, '896: iseven(1/3) == 0'); + vrfy(isodd(1/3) == 0, '897: isodd(1/3) == 0'); + vrfy(isrel(-5, 6) == 1, '898: isrel(-5, 6) == 1'); + vrfy(isrel(-2, 6) == 0, '899: isrel(-2, 6) == 0'); + vrfy(bit(9,0) == 1, '900: bit(9,0) == 1'); + vrfy(bit(9,1) == 0, '901: bit(9,1) == 0'); + vrfy(bit(9,2) == 0, '902: bit(9,2) == 0'); + vrfy(bit(9,3) == 1, '903: bit(9,3) == 1'); + vrfy(bit(1.25, -2) == 1, '904: bit(1.25, -2) == 1'); + vrfy(bit(1.25, -1) == 0, '905: bit(1.25, -1) == 0'); + vrfy(bit(1.25, 0) == 1, '906: bit(1.25, 0) == 1'); + vrfy(bit(pi(), 1) == 1, '907: bit(pi(), 1) == 1'); + vrfy(bit(pi(), -2) == 0, '908: bit(pi(), -2) == 0'); + vrfy(bit(pi(), -3) == 1, '909: bit(pi(), -3) == 1'); + vrfy(istype(2, 3.0) == 1, '910: istype(2, 3.0) == 1'); + vrfy(istype(2, "2") == 0, '911: istype(2, "2") == 0'); + vrfy(istype(2, 3i) == 0, '912: istype(2, 3i) == 0'); + vrfy(istype(2i+2, 3i) == 1, '913: istype(2i+2, 3i) == 1'); + a = epsilon(); + print '914: a = epsilon()'; + vrfy(epsilon(a) == epsilon(), '915: epsilon(a) == epsilon()'); + vrfy(epsilon(a) == epsilon(), '916: epsilon(a) == epsilon()'); + vrfy(epsilon(a) == epsilon(), '917: epsilon(a) == epsilon()'); + vrfy(epsilon() == a, '918: epsilon() == a'); + b = 1e-6; + print '919: b = 1e-6'; + vrfy(epsilon(b) == a, '920: epsilon(b) == a'); + vrfy(epsilon(b) == epsilon(), '921: epsilon(b) == epsilon()'); + vrfy(epsilon(b) == epsilon(), '922: epsilon(b) == epsilon()'); + vrfy(epsilon(b) == epsilon(), '923: epsilon(b) == epsilon()'); + vrfy(epsilon() == 1e-6, '924: epsilon() == 1e-6'); + vrfy(epsilon(a) == b, '925: epsilon(a) == b'); + vrfy(epsilon(a) == epsilon(), '926: epsilon(a) == epsilon()'); + vrfy(epsilon(a) == epsilon(), '927: epsilon(a) == epsilon()'); + vrfy(epsilon(a) == epsilon(), '928: epsilon(a) == epsilon()'); + vrfy(epsilon(a) == a, '929: epsilon(a) == a'); + vrfy(quomod(13,5,a,b) == 1, '930: quomod(13,5,a,b) == 1'); + vrfy(a == 2, '931: a == 2'); + vrfy(b == 3, '932: b == 3'); + vrfy(quomod(15.6,5.2,a,b) == 0, '933: quomod(15.6,5.2,a,b) == 0'); + vrfy(a == 3, '934: a == 3'); + vrfy(b == 0, '935: b == 0'); + vrfy(putenv("abcd=efg") == 0, '936: putenv("abcd=efg")'); + vrfy(getenv("abcd") == "efg", '937: getenv("abcd") == "efg"'); + vrfy(putenv("abcd","123")==0, '938: putenv("abcd","123")'); + vrfy(getenv("abcd") == "123", '939: getenv("abcd") == "123"'); + vrfy(isnull(getenv("notavar")) == 1, + '940: isnull(getenv("notavar")) == 1'); + a = "abcdefg"; + print '941: a = "abcdefg"'; + vrfy(strpos(a, "c") == 3, '942: strpos(a, "c") == 3'); + vrfy(strpos(a, "def") == 4, '943: strpos(a, "def") == 4'); + vrfy(strpos(a, "defg") == 4, '944: strpos(a, "defg") == 4'); + vrfy(strpos(a, "defgh") == 0, '945: strpos(a, "defgh") == 0'); + 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'); + if (config("windows") || config("cygwin")) { + print '949: test skipped for windows or cygwin systems'; + print '950: test skipped for windows or cygwin 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'; + vrfy(isstr(cmdbuf()) == 1, '954: isstr(cmdbuf()) == 1'); + vrfy(abs(root(4,3,0.1)-1.5874) < 0.1, + '955: abs(root(4,3,0.1)-1.5874) < 0.1'); + print '956: a = 2^300 + 69962309754533779525365054067'; + a = 2^300 + 69962309754533779525365054067; + a /= 2^211; + print '957: a /= 2^211'; + vrfy(appr(a, 1e-20) == 2^89, '958: appr(a, 1e-20) == 2^89'); + vrfy(digits(5e149) == 150, '959: digits(5e149) == 150'); + vrfy(highbit(2) == 1, '960: highbit(2) == 1'); + vrfy(highbit(3) == 1, '961: highbit(3) == 1'); + vrfy(highbit(4) == 2, '962: highbit(4) == 2'); + vrfy(highbit(-15) == 3, '963: highbit(-15) == 3'); + vrfy(highbit(2^27) == 27, '964: highbit(2^27) == 27'); + a = 12.34; + print '965: a = 12.34'; + vrfy(digit(a,2) == 0, '966: digit(a,2) == 0'); + vrfy(digit(a,1) == 1, '967: digit(a,1) == 1'); + vrfy(digit(a,0) == 2, '968: digit(a,0) == 2'); + vrfy(digit(a,-1) == 3, '969: digit(a,-1) == 3'); + vrfy(digit(a,-2) == 4, '970: digit(a,-2) == 4'); + a = 10/7; + print '971: a = 10/7'; + vrfy(digit(a,1) == 0, '972: digit(a,1) == 0'); + vrfy(digit(a,0) == 1, '973: digit(a,0) == 1'); + vrfy(digit(a,-1) == 4, '974: digit(a,-1) == 4'); + vrfy(digit(a,-2) == 2, '975: digit(a,-2) == 2'); + vrfy(digit(a,-3) == 8, '976: digit(a,-3) == 8'); + vrfy(digits(0) == 1, '977: digits(0) == 1'); + vrfy(digits(0.0123) == 1, '978: digits(0.0123) == 1'); + vrfy(digits(3.7) == 1, '979: digits(3.7) == 1'); + vrfy(digits(-27) == 2, '980: digits(-27) == 2'); + vrfy(digits(-99.7) == 2, '981: digits(-99.7) == 2'); + vrfy(ilog2(1) == 0, '982: ilog2(1) == 0'); + vrfy(ilog2(2) == 1, '983: ilog2(2) == 1'); + vrfy(ilog2(3) == 1, '984: ilog2(3) == 1'); + vrfy(ilog2(4) == 2, '985: ilog2(4) == 2'); + vrfy(ilog2(1/15) == -4, '986: ilog2(1/15) == -4'); + vrfy(places(3) == 0, '987: places(3) == 0'); + vrfy(places(0.0123) == 4, '988: places(0.0123) == 4'); + vrfy(places(3.70) == 1, '989: places(3.70) == 1'); + vrfy(places(1e-10) == 10, '990: places(1e-10) == 10'); + vrfy(places(3/7) == -1, '991: places(/37) == -1'); + vrfy(ilog10(7.7) == 0, '992: ilog10(7.7) == 0'); + vrfy(ilog10(77.7) == 1, '993: ilog10(77.7) == 1'); + vrfy(ilog10(777) == 2, '994: ilog10(777) == 2'); + vrfy(ilog10(.00777) == -3, '995: ilog10(.00777) == -3'); + vrfy(ilog10(1e27) == 27, '996: ilog10(1e27) == 27'); + vrfy(lowbit(2) == 1, '997: lowbit(2) == 1'); + vrfy(lowbit(3) == 0, '998: lowbit(3) == 0'); + vrfy(lowbit(4) == 2, '999: lowbit(4) == 2'); + vrfy(lowbit(-15) == 0, '1000: lowbit(-15) == 0'); + vrfy(lowbit(2^27) == 27, '1001: lowbit(2^27) == 27'); + vrfy(char(0102) == 'B', '1002: char(0102) == \'B\''); + vrfy(char(0x6f) == 'o', '1003: char(0x6f) == \'o\''); + vrfy(char(119) == 'w', '1004: char(119) == \'w\''); + vrfy(char(0145) == 'e', '1005: char(0145) == \'e\''); + vrfy(char(0x6e) == 'n', '1006: char(0x6e) == \'n\''); + vrfy(den(-1.25) == 4, '1007: den(-1.25) == 4'); + vrfy(den(121/33) == 3, '1008: den(121/33) == 3'); + vrfy(gcd(9/10, 11/5, 4/25) == 0.02, + '1009: gcd(9/10, 11/5, 4/25) == 0.02'); + vrfy(gcd(0,0,0,0,0) == 0, '1010: gcd(0,0,0,0,0) == 0'); + vrfy(hypot(3, 4, 1e-6) == 5, '1011: hypot(3, 4, 1e-6) == 5'); + vrfy(hypot(2,-3,1e-6) == 3605551/1e6, + '1012: hypot(2,-3,1e-6) == 3605551/1e6'); + vrfy(im(-4.25 - 7i) == -7, '1013: im(-4.25 - 7i) == -7'); + vrfy(lcm(12, -24, 30) == -120,'1014: lcm(12, -24, 30) == -120'); + vrfy(lcm(9/10, 11/5, 4/25) == 79.2, + '1015: lcm(9/10, 11/5, 4/25) == 79.2'); + vrfy(lcm(2) == 2, '1016: lcm(2) == 2'); + vrfy(max(2) == 2, '1017: max(2) == 2'); + vrfy(min(2) == 2, '1018: min(2) == 2'); + vrfy(re(-4.25 - 7i) == -4.25, '1019: re(-4.25 - 7i) == -4.25'); + vrfy(size("abc") == 3, '1020: size("abc") == 3'); + vrfy(str("") == "", '1021: str("") == ""'); + vrfy(str(null()) == "", '1022: str(null()) == ""'); + vrfy(str("Ernest Bowen") == "Ernest Bowen", + '1023: str("Ernest Bowen") == "Ernest Bowen"'); + vrfy(strlen("a b\tc\\d") == 7, + '1024: strlen("a b\tc\\d") == 7'); + vrfy(xor(2) == 2, '1025: xor(2) == 2'); + vrfy(xor(5, 3, 7, 2, 9) == 10, + '1026: xor(5, 3, 7, 2, 9) == 10'); + vrfy(xor(0,0) == 0, '1027: xor(0,0) == 0'); + vrfy(xor(0,1) == 1, '1028: xor(0,1) == 1'); + vrfy(xor(1,0) == 1, '1029: xor(1,0) == 1'); + vrfy(xor(1,1) == 0, '1030: xor(1,1) == 0'); + vrfy(xor(5,3,-7,2,9) == -12, '1031: xor(5,3,-7,2,9) == -12'); + vrfy(fib(-2) == -1, '1032: fib(-2) == -1'); + vrfy(fib(-1) == 1, '1033: fib(-1) == 1'); + vrfy(fib(-10) == -55, '1034: fib(-10) == -55'); + vrfy(ilog(1/8, 3) == -2, '1035: ilog(1/8, 3) == -2'); + vrfy(ilog(8.9, 3) == 1, '1036: ilog(8.9, 3) == 1'); + vrfy(iroot(1,9) == 1, '1037: iroot(1,9) == 1'); + vrfy(iroot(pi()^8,5) == 6, '1038: iroot(pi()^8,5)'); + vrfy(isqrt(8.5) == 2, '1039: isqrt(8.5) == 2'); + vrfy(isqrt(2e56) == 14142135623730950488016887242, + '1040: isqrt(2e56) == 14142135623730950488016887242'); + vrfy(near(22/7, 3.15, .01) == -1, + '1041: near(22/7, 3.15, .01) == -1'); + vrfy(near(22/7, 3.15, .005) == 1, + '1042: near(22/7, 3.15, .005) == 1'); + vrfy(norm(3.4) == 11.56, '1043: isqrt(3.4) == 11.56'); + vrfy(pi(1e-5) == 3.14159, '1044: pi(1e-5) == 3.14159'); + pi = pi(1e-10); + print '1045: pi = pi(1e-10)'; + vrfy(pi == 3.1415926536, '1046: pi == 3.1415926536'); + vrfy(polar(2,pi/2,1e-5)==2i, '1047: polar(2,pi/2,1e-5)==2i'); + vrfy(power(exp(1,1e-20),pi(1e-20)*1i/2,1e-20) == 1i, + '1048: power(exp(1,1e-20),pi(1e-20)*1i/2,1e-20) == 1i'); + vrfy(ssq(1+2i, 3-4i, 5 +6i) == -21+40i, + '1049: ssq(1+2i, 3-4i, 5 +6i) == -21+40i'); + vrfy(isreal(ln(1 + 1e-10i, 1e-5)), + '1050: isreal(ln(1 + 1e-10i, 1e-5))'); + vrfy(isreal(exp(pi(1e-10)*1i, 1e-5)), + '1051: isreal(exp(pi(1e-10)*1i, 1e-5))'); + vrfy(cfappr(43/30, 10, 0) == 10/7, + '1052: cfappr(43/30, 10, 0) == 10/7'); + vrfy(cfappr(43/30, 10, 1) == 13/9, + '1053: cfappr(43/30, 10, 1) == 13/9'); + vrfy(cfappr(43/30, 10, 16) == 10/7, + '1054: cfappr(43/30, 10, 16) == 10/7'); + vrfy(cfappr(6/5, 1/2, 16) == 1, + '1055: cfappr(6/5, 1/2, 16) == 1'); + vrfy(cfsim(13,8) == 0, '1056: cfsim(13,8) == 0'); + vrfy(cfsim(1057,8) == 0, '1057: cfsim(1057,8) == 0'); + vrfy(mod(11,5,0) == 1, '1058: mod(11,5,0) == 1'); + vrfy(mod(11,5,1) == -4, '1059: mod(11,5,1) == -4'); + vrfy(mod(-11,5,2) == -1, '1060: mod(-11,5,2) == -1'); + vrfy(mod(-11,-5,3) == 4, '1061: mod(-11,-5,3) == 4'); + vrfy(mod(12.5,5,16) == 2.5, '1062: mod(12.5,5,16) == 2.5'); + vrfy(mod(12.5,5,17) == -2.5, '1063: mod(12.5,5,17) == -2.5'); + vrfy(mod(12.5,5,24) == 2.5, '1064: mod(12.5,5,24) == 2.5'); + vrfy(mod(-7.5,-5,24) == 2.5, '1065: mod(-7.5,-5,24) == 2.5'); + vrfy(quo(11,5,0) == 2, '1066: quo(11,5,0) == 2'); + vrfy(quo(11,5,1) == 3, '1067: quo(11,5,1) == 3'); + vrfy(quo(-11,5,2) == -2, '1068: quo(-11,5,2) == -2'); + vrfy(quo(-11,-5,3) == 3, '1069: quo(-11,-5,3) == 3'); + vrfy(quo(12.5,5,16) == 2, '1070: quo(12.5,5,16) == 2'); + vrfy(quo(12.5,5,17) == 3, '1071: quo(12.5,5,17) == 3'); + vrfy(quo(12.5,5,24) == 2, '1072: quo(12.5,5,24) == 2'); + vrfy(quo(-7.5,-5,24) == 2, '1073: quo(-7.5,-5,24) == 2'); + vrfy(frac(2.5 + 3i) == .5, '1074: frac(2.5 + 3i) == .5'); + vrfy(root(1i,1000,1e-2)==1, '1075: root(1i,1000,1e-2) == 1'); + vrfy(scale(2+3i,2)==8+12i, '1076: scale(2+3i,2) == 8+12i'); + vrfy(frem(8,4) == 2, '1077: frem(8,4) == 2'); + vrfy(jacobi(80,199) == 1, '1078: jacobi(80,199) == 1'); + vrfy(test(1), '1079: test(1)'); + vrfy(!test(0), '1080: !test(0)'); + vrfy(hnrmod(2^177-1,1,177,-1)==0, + '1081: hnrmod(2^177-1,1,177,-1)==0'); + vrfy(hnrmod(2^178-2,1,177,-1)==0, + '1082: hnrmod(2^178-2,1,177,-1)==0'); + vrfy(hnrmod(2^178-3,1,177,1)==2^177-4, + '1083: hnrmod(2^178-3,1,177,1)==2^177-4'); + vrfy(hnrmod(2^179-4,1,177,0)==2^177-4, + '1084: hnrmod(2^179-4,1,177,0)==2^177-4'); + vrfy(hnrmod(1234567^2,13,17,-1)==1155404, + '1085: hnrmod(1234567^2,13,17,-1)==1155404'); + vrfy(hnrmod(3276^54,45,415,1)==3276^54%(45*2^415+1), + '1086: hnrmod(3276^54,45,415,1)==3276^54%(45*2^415+1)'); + vrfy(hnrmod(3276^54,45,415,0)==3276^54%(45*2^415), + '1087: hnrmod(3276^54,45,415,0)==3276^54%(45*2^415)'); + vrfy(hnrmod(3276^54,45,415,-1)==3276^54%(45*2^415-1), + '1088: hnrmod(3276^54,45,415,-1)==3276^54%(45*2^415-1)'); + vrfy(hnrmod(10^40, 17, 51, 1) == 33827019788296445, + '1089: hnrmod(10^40, 17, 51, 1) == 33827019788296445'); + vrfy(hnrmod(3192487935759423423521,16,65,1)==241008883965895164956, + '1090: hnrmod(3192487935759423423521,16,65,1)==241008883965895164956'); - /* - * minv bug fix - */ - a = 2868611690182699929873981931; - print '1091: a = 2868611690182699929873981931'; - b = 502922899875329926125584830; - print '1092: b = 502922899875329926125584830'; - vrfy(minv(b,a) == 1111092570983877189739032190, - '1093: minv(b,a) == 1111092570983877189739032190'); - vrfy(mod(minv(b,a)*b,a) == 1, - '1094: mod(minv(b,a)*b,a) == 1'); + /* + * minv bug fix + */ + a = 2868611690182699929873981931; + print '1091: a = 2868611690182699929873981931'; + b = 502922899875329926125584830; + print '1092: b = 502922899875329926125584830'; + vrfy(minv(b,a) == 1111092570983877189739032190, + '1093: minv(b,a) == 1111092570983877189739032190'); + vrfy(mod(minv(b,a)*b,a) == 1, + '1094: mod(minv(b,a)*b,a) == 1'); - /* - * more functions to test - */ - vrfy(popcnt(32767) == 15, '1095: popcnt(32767) == 15'); - vrfy(popcnt(3/2) == 3, '1096: popcnt(3/2) == 3'); - vrfy(popcnt(-237/39929,1) == 17, - '1097: popcnt(-237/39929,1) == 17'); - vrfy(popcnt(-237/39929,0) == 7, - '1098: popcnt(-237/39929,0) == 7'); - vrfy(popcnt(-237/39929) == 17, - '1099: popcnt(-237/39929) == 17'); - vrfy(popcnt(pi(1e-20)) == 65, '1100: popcnt(pi(1e-20)) == 65'); - vrfy(popcnt(pi(1e-20),0) == 69, '1101: popcnt(pi(1e-20),0) == 69'); - vrfy(popcnt(17^777) == 1593, '1102: popcnt(17^777) == 1593'); + /* + * more functions to test + */ + vrfy(popcnt(32767) == 15, '1095: popcnt(32767) == 15'); + vrfy(popcnt(3/2) == 3, '1096: popcnt(3/2) == 3'); + vrfy(popcnt(-237/39929,1) == 17, + '1097: popcnt(-237/39929,1) == 17'); + vrfy(popcnt(-237/39929,0) == 7, + '1098: popcnt(-237/39929,0) == 7'); + vrfy(popcnt(-237/39929) == 17, + '1099: popcnt(-237/39929) == 17'); + vrfy(popcnt(pi(1e-20)) == 65, '1100: popcnt(pi(1e-20)) == 65'); + vrfy(popcnt(pi(1e-20),0) == 69, '1101: popcnt(pi(1e-20),0) == 69'); + vrfy(popcnt(17^777) == 1593, '1102: popcnt(17^777) == 1593'); - /* - * more hnrmod testing - */ - vrfy(hnrmod(21<<100+5,3,100,1) == (21<<100+5)%(3<<100+1), - '1103: hnrmod(21<<100+5,3,100,1) == (21<<100+5)%(3<<100+1)'); - vrfy(hnrmod(21<<500+7,3,500,1) == (21<<500+7)%(3<<500+1), - '1104: hnrmod(21<<500+7,3,500,1) == (21<<500+7)%(3<<500+1)'); - vrfy(hnrmod(-767256,84,1,0) == (-767256)%(84<<1+0), - '1105: hnrmod(-767256,84,1,0) == (-767256)%(84<<1+0)'); - vrfy(hnrmod(-831150,75,1,0) == (-831150)%(75<<1+0), - '1106: hnrmod(-831150,75,1,0) == (-831150)%(75<<1+0)'); - vrfy(hnrmod(-767256,84,1,1) == (-767256)%(84<<1+1), - '1107: hnrmod(-767256,84,1,1) == (-767256)%(84<<1+1)'); - vrfy(hnrmod(-831150,75,1,1) == (-831150)%(75<<1+1), - '1108: hnrmod(-831150,75,1,1) == (-831150)%(75<<1+1)'); - vrfy(hnrmod(-767256,84,1,-1) == (-767256)%(84<<1-1), - '1109: hnrmod(-767256,84,1,-1) == (-767256)%(84<<1-1)'); - vrfy(hnrmod(-831150,75,1,-1) == (-831150)%(75<<1-1), - '1110: hnrmod(-831150,75,1,-1) == (-831150)%(75<<1-1)'); - vrfy(hnrmod(21<<100+5,3,100,0) == (21<<100+5)%(3<<100+0), - '1111: hnrmod(21<<100+5,3,100,0) == (21<<100+5)%(3<<100+0)'); - vrfy(hnrmod(21<<500+7,3,500,-1) == (21<<500+7)%(3<<500-1), - '1112: hnrmod(21<<500+7,3,500,-1) == (21<<500+7)%(3<<500-1)'); + /* + * more hnrmod testing + */ + vrfy(hnrmod(21<<100+5,3,100,1) == (21<<100+5)%(3<<100+1), + '1103: hnrmod(21<<100+5,3,100,1) == (21<<100+5)%(3<<100+1)'); + vrfy(hnrmod(21<<500+7,3,500,1) == (21<<500+7)%(3<<500+1), + '1104: hnrmod(21<<500+7,3,500,1) == (21<<500+7)%(3<<500+1)'); + vrfy(hnrmod(-767256,84,1,0) == (-767256)%(84<<1+0), + '1105: hnrmod(-767256,84,1,0) == (-767256)%(84<<1+0)'); + vrfy(hnrmod(-831150,75,1,0) == (-831150)%(75<<1+0), + '1106: hnrmod(-831150,75,1,0) == (-831150)%(75<<1+0)'); + vrfy(hnrmod(-767256,84,1,1) == (-767256)%(84<<1+1), + '1107: hnrmod(-767256,84,1,1) == (-767256)%(84<<1+1)'); + vrfy(hnrmod(-831150,75,1,1) == (-831150)%(75<<1+1), + '1108: hnrmod(-831150,75,1,1) == (-831150)%(75<<1+1)'); + vrfy(hnrmod(-767256,84,1,-1) == (-767256)%(84<<1-1), + '1109: hnrmod(-767256,84,1,-1) == (-767256)%(84<<1-1)'); + vrfy(hnrmod(-831150,75,1,-1) == (-831150)%(75<<1-1), + '1110: hnrmod(-831150,75,1,-1) == (-831150)%(75<<1-1)'); + vrfy(hnrmod(21<<100+5,3,100,0) == (21<<100+5)%(3<<100+0), + '1111: hnrmod(21<<100+5,3,100,0) == (21<<100+5)%(3<<100+0)'); + vrfy(hnrmod(21<<500+7,3,500,-1) == (21<<500+7)%(3<<500-1), + '1112: hnrmod(21<<500+7,3,500,-1) == (21<<500+7)%(3<<500-1)'); - /* - * catalan testing - */ - vrfy(catalan(2) == 2, '1113: catalan(2) == 2'); - vrfy(catalan(3) == 5, '1114: catalan(3) == 5'); - vrfy(catalan(4) == 14, '1115: catalan(4) == 14'); - vrfy(catalan(20) == 6564120420, '1116: catalan(20) == 6564120420'); + /* + * catalan testing + */ + vrfy(catalan(2) == 2, '1113: catalan(2) == 2'); + vrfy(catalan(3) == 5, '1114: catalan(3) == 5'); + vrfy(catalan(4) == 14, '1115: catalan(4) == 14'); + vrfy(catalan(20) == 6564120420, '1116: catalan(20) == 6564120420'); - /* - * bernoulli builtin function testing - */ - vrfy(bernoulli(0) == 1, '1117: bernoulli(0) == 1'); - vrfy(bernoulli(1) == -1/2, '1118: bernoulli(1) == -1/2'); - vrfy(bernoulli(2) == 1/6, '1119: bernoulli(2) == 1/6'); - vrfy(bernoulli(3) == 0, '1120: bernoulli(3) == 0'); - vrfy(bernoulli(4) == -1/30, '1121: bernoulli(4) == -1/30'); - vrfy(bernoulli(5) == 0, '1122: bernoulli(5) == 0'); - vrfy(bernoulli(6) == 1/42, '1123: bernoulli(6) == 1/42'); - vrfy(bernoulli(32) == -7709321041217/510, - '1124: bernoulli(32) == -7709321041217/510'); + /* + * bernoulli builtin function testing + */ + vrfy(bernoulli(0) == 1, '1117: bernoulli(0) == 1'); + vrfy(bernoulli(1) == -1/2, '1118: bernoulli(1) == -1/2'); + vrfy(bernoulli(2) == 1/6, '1119: bernoulli(2) == 1/6'); + vrfy(bernoulli(3) == 0, '1120: bernoulli(3) == 0'); + vrfy(bernoulli(4) == -1/30, '1121: bernoulli(4) == -1/30'); + vrfy(bernoulli(5) == 0, '1122: bernoulli(5) == 0'); + vrfy(bernoulli(6) == 1/42, '1123: bernoulli(6) == 1/42'); + vrfy(bernoulli(32) == -7709321041217/510, + '1124: bernoulli(32) == -7709321041217/510'); - /* - * euler function testing - */ - vrfy(euler(0) == 1, '1125: euler(0) == 1'); - vrfy(euler(1) == 0, '1126: euler(1) == 0'); - vrfy(euler(2) == -1, '1127: euler(2) == -1'); - vrfy(euler(3) == 0, '1128: euler(3) == 0'); - vrfy(freeeuler() == null(), '1129: freeeuler() == null()'); - vrfy(euler(4) == 5, '1130: euler(4) == 5'); - vrfy(euler(5) == 0, '1131: euler(5) == 0'); - vrfy(euler(6) == -61, '1132: euler(6) == -61'); - vrfy(euler(32) == 177519391579539289436664789665, - '1130: euler(32) == 177519391579539289436664789665'); - vrfy(freeeuler() == null(), '1133: freeeuler() == null()'); + /* + * euler function testing + */ + vrfy(euler(0) == 1, '1125: euler(0) == 1'); + vrfy(euler(1) == 0, '1126: euler(1) == 0'); + vrfy(euler(2) == -1, '1127: euler(2) == -1'); + vrfy(euler(3) == 0, '1128: euler(3) == 0'); + vrfy(freeeuler() == null(), '1129: freeeuler() == null()'); + vrfy(euler(4) == 5, '1130: euler(4) == 5'); + vrfy(euler(5) == 0, '1131: euler(5) == 0'); + vrfy(euler(6) == -61, '1132: euler(6) == -61'); + vrfy(euler(32) == 177519391579539289436664789665, + '1130: euler(32) == 177519391579539289436664789665'); + vrfy(freeeuler() == null(), '1133: freeeuler() == null()'); - /* - * digit with non-10 base - */ + /* + * digit with non-10 base + */ a = 123456.789; - print '1134: a = 123456.789'; - vrfy(digit(a, 6, 100) == 0, '1135: digit(a, 6, 100) == 0'); - vrfy(digit(a, 5, 100) == 0, '1136: digit(a, 5, 100) == 0'); - vrfy(digit(a, 4, 100) == 0, '1137: digit(a, 4, 100) == 0'); - vrfy(digit(a, 3, 100) == 0, '1138: digit(a, 3, 100) == 0'); - vrfy(digit(a, 2, 100) == 12, '1139: digit(a, 2, 100) == 12'); - vrfy(digit(a, 1, 100) == 34, '1140: digit(a, 1, 100) == 34'); - vrfy(digit(a, 0, 100) == 56, '1141: digit(a, 0, 100) == 56'); - vrfy(digit(a, -1, 100) == 78, '1142: digit(a, -1, 100) == 78'); - vrfy(digit(a, -2, 100) == 90, '1143: digit(a, -2, 100) == 90'); - vrfy(digit(a, -3, 100) == 0, '1144: digit(a, -3, 100) == 0'); - vrfy(digit(a, -4, 100) == 0, '1145: digit(a, -4, 100) == 0'); - vrfy(digit(a, -5, 100) == 0, '1146: digit(a, -5, 100) == 0'); - vrfy(digit(a, -6, 100) == 0, '1146: digit(a, -6, 100) == 0'); + print '1134: a = 123456.789'; + vrfy(digit(a, 6, 100) == 0, '1135: digit(a, 6, 100) == 0'); + vrfy(digit(a, 5, 100) == 0, '1136: digit(a, 5, 100) == 0'); + vrfy(digit(a, 4, 100) == 0, '1137: digit(a, 4, 100) == 0'); + vrfy(digit(a, 3, 100) == 0, '1138: digit(a, 3, 100) == 0'); + vrfy(digit(a, 2, 100) == 12, '1139: digit(a, 2, 100) == 12'); + vrfy(digit(a, 1, 100) == 34, '1140: digit(a, 1, 100) == 34'); + vrfy(digit(a, 0, 100) == 56, '1141: digit(a, 0, 100) == 56'); + vrfy(digit(a, -1, 100) == 78, '1142: digit(a, -1, 100) == 78'); + vrfy(digit(a, -2, 100) == 90, '1143: digit(a, -2, 100) == 90'); + vrfy(digit(a, -3, 100) == 0, '1144: digit(a, -3, 100) == 0'); + vrfy(digit(a, -4, 100) == 0, '1145: digit(a, -4, 100) == 0'); + vrfy(digit(a, -5, 100) == 0, '1146: digit(a, -5, 100) == 0'); + vrfy(digit(a, -6, 100) == 0, '1146: digit(a, -6, 100) == 0'); - /* - * digits with a non-10 base - */ - vrfy(digits(a, 100) == 3, '1147: digits(a, 100) == 3'); - vrfy(digits(2^256-1, 256) == 32,'1148: digits(2^256-1, 256) == 32'); + /* + * digits with a non-10 base + */ + vrfy(digits(a, 100) == 3, '1147: digits(a, 100) == 3'); + vrfy(digits(2^256-1, 256) == 32,'1148: digits(2^256-1, 256) == 32'); - /* - * places with a non-10 base - */ - vrfy(places(0.0123, 2) == -1, '1149: places(0.0123, 2) == -1'); - vrfy(places(0.625, 2) == 3, '1150: places(0.625, 2) == 3'); - vrfy(places(0.625, 8) == 1, '1151: places(0.625, 8) == 1'); - vrfy(places(171/2^712, 2) == 712, - '1152: places(171/2^7120.625, 2) == 712'); - vrfy(places(171/2^712, 64) == 119, - '1152: places(171/2^7120.625, 64) == 119'); + /* + * places with a non-10 base + */ + vrfy(places(0.0123, 2) == -1, '1149: places(0.0123, 2) == -1'); + vrfy(places(0.625, 2) == 3, '1150: places(0.625, 2) == 3'); + vrfy(places(0.625, 8) == 1, '1151: places(0.625, 8) == 1'); + vrfy(places(171/2^712, 2) == 712, + '1152: places(171/2^7120.625, 2) == 712'); + vrfy(places(171/2^712, 64) == 119, + '1152: places(171/2^7120.625, 64) == 119'); - /* - * verify sleep - */ - vrfy(sleep(1/5) == null(), '1153: sleep(1/5) == null()'); - vrfy(sleep(1/100) == null(), '1154: sleep(1/100) == null()'); + /* + * verify sleep + */ + vrfy(sleep(1/5) == null(), '1153: sleep(1/5) == null()'); + vrfy(sleep(1/100) == null(), '1154: sleep(1/100) == null()'); - /* - * verify calcpath - */ - vrfy(isstr(calcpath()), '1155: isstr(calcpath())'); + /* + * verify calcpath + */ + vrfy(isstr(calcpath()), '1155: isstr(calcpath())'); - /* - * ssq use of lists - */ - vrfy(ssq(1,2, list(3,4,list(5,6)), list(), 7, 8) == 204, - '1156: ssq(1,2, list(3,4,list(5,6)), list(), 7, 8) == 204'); + /* + * ssq use of lists + */ + vrfy(ssq(1,2, list(3,4,list(5,6)), list(), 7, 8) == 204, + '1156: ssq(1,2, list(3,4,list(5,6)), list(), 7, 8) == 204'); - /* - * quomod 5th argument rounding tests - */ - vrfy(quomod(10,-3,a,b,0) == 1, '1157: vrfy(quomod(10,-3,a,b,0) == 1'); - vrfy(a == -4, '1158: a == -4'); - vrfy(b == -2, '1159: b == -2'); - vrfy(quomod(-10,-3,a,b,1) == 1, '1160: vrfy(quomod(-10,-3,a,b,1) == 1'); - vrfy(a == 4, '1161: a == 4'); - vrfy(b == 2, '1162: b == 2'); - vrfy(quomod(10,3,a,b,2) == 1, '1163: vrfy(quomod(10,3,a,b,2) == 1'); - vrfy(a == 3, '1164: a == 3'); - vrfy(b == 1, '1165: b == 1'); - vrfy(quomod(-10,3,a,b,3) == 1, '1166: vrfy(quomod(-10,3,a,b,3) == 1'); - vrfy(a == -4, '1167: a == -4'); - vrfy(b == 2, '1168: b == 2'); - vrfy(quomod(10,-3,a,b,4) == 1, '1169: vrfy(quomod(10,-3,a,b,4) == 1'); - vrfy(a == -3, '1170: a == -3'); - vrfy(b == 1, '1171: b == 1'); - vrfy(quomod(-10,-3,a,b,5) == 1, '1172: vrfy(quomod(-10,-3,a,b,5) == 1'); - vrfy(a == 3, '1173: a == 3'); - vrfy(b == -1, '1174: b == -1'); - vrfy(quomod(10,3,a,b,6) == 1, '1175: vrfy(quomod(10,3,a,b,6) == 1'); - vrfy(a == 3, '1176: a == 3'); - vrfy(b == 1, '1177: b == 1'); - vrfy(quomod(-10,3,a,b,7) == 1, '1178: vrfy(quomod(-10,3,a,b,7) == 1'); - vrfy(a == -4, '1179: a == -4'); - vrfy(b == 2, '1180: b == 2'); - vrfy(quomod(10,-3,a,b,8) == 1, '1181: vrfy(quomod(10,-3,a,b,8) == 1'); - vrfy(a == -4, '1182: a == -4'); - vrfy(b == -2, '1183: b == -2'); - vrfy(quomod(-10,-3,a,b,9) == 1, '1184: vrfy(quomod(-10,-3,a,b,9) == 1'); - vrfy(a == 3, '1185: a == 3'); - vrfy(b == -1, '1186: b == -1'); - vrfy(quomod(10,3,a,b,10) == 1, '1187: vrfy(quomod(10,3,a,b,10) == 1'); - vrfy(a == 4, '1188: a == 4'); - vrfy(b == -2, '1189: b == -2'); - vrfy(quomod(-10,3,a,b,11) == 1, '1190: vrfy(quomod(-10,3,a,b,11) == 1'); - vrfy(a == -4, '1191: a == -4'); - vrfy(b == 2, '1192: b == 2'); - vrfy(quomod(10,-3,a,b,12) == 1, '1193: vrfy(quomod(10,-3,a,b,12) == 1'); - vrfy(a == -3, '1194: a == -3'); - vrfy(b == 1, '1195: b == 1'); - vrfy(quomod(-10,-3,a,b,13) == 1, - '1196: vrfy(quomod(-10,-3,a,b,13) == 1'); - vrfy(a == 4, '1197: a == 4'); - vrfy(b == 2, '1198: b == 2'); - vrfy(quomod(10,3,a,b,14) == 1, '1199: vrfy(quomod(10,3,a,b,14) == 1'); - vrfy(a == 4, '1200: a == 4'); - vrfy(b == -2, '1201: b == -2'); - vrfy(quomod(-10,3,a,b,15) == 1, '1202: vrfy(quomod(-10,3,a,b,15) == 1'); - vrfy(a == -4, '1203: a == -4'); - vrfy(b == 2, '1204: b == 2'); + /* + * quomod 5th argument rounding tests + */ + vrfy(quomod(10,-3,a,b,0) == 1, '1157: vrfy(quomod(10,-3,a,b,0) == 1'); + vrfy(a == -4, '1158: a == -4'); + vrfy(b == -2, '1159: b == -2'); + vrfy(quomod(-10,-3,a,b,1) == 1, '1160: vrfy(quomod(-10,-3,a,b,1) == 1'); + vrfy(a == 4, '1161: a == 4'); + vrfy(b == 2, '1162: b == 2'); + vrfy(quomod(10,3,a,b,2) == 1, '1163: vrfy(quomod(10,3,a,b,2) == 1'); + vrfy(a == 3, '1164: a == 3'); + vrfy(b == 1, '1165: b == 1'); + vrfy(quomod(-10,3,a,b,3) == 1, '1166: vrfy(quomod(-10,3,a,b,3) == 1'); + vrfy(a == -4, '1167: a == -4'); + vrfy(b == 2, '1168: b == 2'); + vrfy(quomod(10,-3,a,b,4) == 1, '1169: vrfy(quomod(10,-3,a,b,4) == 1'); + vrfy(a == -3, '1170: a == -3'); + vrfy(b == 1, '1171: b == 1'); + vrfy(quomod(-10,-3,a,b,5) == 1, '1172: vrfy(quomod(-10,-3,a,b,5) == 1'); + vrfy(a == 3, '1173: a == 3'); + vrfy(b == -1, '1174: b == -1'); + vrfy(quomod(10,3,a,b,6) == 1, '1175: vrfy(quomod(10,3,a,b,6) == 1'); + vrfy(a == 3, '1176: a == 3'); + vrfy(b == 1, '1177: b == 1'); + vrfy(quomod(-10,3,a,b,7) == 1, '1178: vrfy(quomod(-10,3,a,b,7) == 1'); + vrfy(a == -4, '1179: a == -4'); + vrfy(b == 2, '1180: b == 2'); + vrfy(quomod(10,-3,a,b,8) == 1, '1181: vrfy(quomod(10,-3,a,b,8) == 1'); + vrfy(a == -4, '1182: a == -4'); + vrfy(b == -2, '1183: b == -2'); + vrfy(quomod(-10,-3,a,b,9) == 1, '1184: vrfy(quomod(-10,-3,a,b,9) == 1'); + vrfy(a == 3, '1185: a == 3'); + vrfy(b == -1, '1186: b == -1'); + vrfy(quomod(10,3,a,b,10) == 1, '1187: vrfy(quomod(10,3,a,b,10) == 1'); + vrfy(a == 4, '1188: a == 4'); + vrfy(b == -2, '1189: b == -2'); + vrfy(quomod(-10,3,a,b,11) == 1, '1190: vrfy(quomod(-10,3,a,b,11) == 1'); + vrfy(a == -4, '1191: a == -4'); + vrfy(b == 2, '1192: b == 2'); + vrfy(quomod(10,-3,a,b,12) == 1, '1193: vrfy(quomod(10,-3,a,b,12) == 1'); + vrfy(a == -3, '1194: a == -3'); + vrfy(b == 1, '1195: b == 1'); + vrfy(quomod(-10,-3,a,b,13) == 1, + '1196: vrfy(quomod(-10,-3,a,b,13) == 1'); + vrfy(a == 4, '1197: a == 4'); + vrfy(b == 2, '1198: b == 2'); + vrfy(quomod(10,3,a,b,14) == 1, '1199: vrfy(quomod(10,3,a,b,14) == 1'); + vrfy(a == 4, '1200: a == 4'); + vrfy(b == -2, '1201: b == -2'); + vrfy(quomod(-10,3,a,b,15) == 1, '1202: vrfy(quomod(-10,3,a,b,15) == 1'); + vrfy(a == -4, '1203: a == -4'); + vrfy(b == 2, '1204: b == 2'); - /* runtime(), systime(), usertime() return numeric values */ - vrfy(isnum(runtime()), '1205: isnum(runtime())'); - vrfy(isnum(systime()), '1206: isnum(systime())'); - vrfy(isnum(usertime()), '1207: isnum(usertime())'); + /* runtime(), systime(), usertime() return numeric values */ + vrfy(isnum(runtime()), '1205: isnum(runtime())'); + vrfy(isnum(systime()), '1206: isnum(systime())'); + vrfy(isnum(usertime()), '1207: isnum(usertime())'); - /* more jacobi tests */ - vrfy(jacobi(987897,987) == 0, '1208: jacobi(987897,987) == 0'); - vrfy(jacobi(897,987) == 0, '1209: jacobi(897,987) == 0'); - vrfy(jacobi(987,897) == 0, '1210: jacobi(987,897) == 0'); - vrfy(jacobi(90,897) == 0, '1211: jacobi(90,897) == 0'); - vrfy(jacobi(45,897) == 0, '1212: jacobi(45,897) == 0'); - vrfy(jacobi(897,45) == 0, '1213: jacobi(897,45) == 0'); - vrfy(jacobi(42,45) == 0, '1214: jacobi(42,45) == 0'); - vrfy(jacobi(21,45) == 0, '1215: jacobi(21,45) == 0'); - vrfy(jacobi(45,21) == 0, '1216: jacobi(45,21) == 0'); - vrfy(jacobi(3,21) == 0, '1217: jacobi(3,21) == 0'); - vrfy(jacobi(0,21) == 0, '1218: jacobi(0,21) == 0'); - vrfy(jacobi(0,20003) == 0, '1219: jacobi(0,20003) == 0'); - vrfy(jacobi(1,20003) == 1, '1220: jacobi(1,20003) == 1'); - vrfy(jacobi(1236,20003) == 1, '1221: jacobi(1236,20003) == 1'); - vrfy(jacobi(618,20003) == -1, '1222: jacobi(618,20003) == -1'); - vrfy(jacobi(309,20003) == 1, '1223: jacobi(309,20003) == 1'); - vrfy(jacobi(227,309) == 1, '1224: jacobi(227,309) == 1'); - vrfy(jacobi(82,227) == 1, '1225: jacobi(82,227) == 1'); - vrfy(jacobi(41,227) == -1, '1226: jacobi(41,227) == -1'); - vrfy(jacobi(22,41) == -1, '1227: jacobi(22,41) == -1'); - vrfy(jacobi(11,41) == -1, '1228: jacobi(11,41) == -1'); - vrfy(jacobi(8,11) == -1, '1229: jacobi(8,11) == -1'); - vrfy(jacobi(4,11) == 1, '1230: jacobi(4,11) == 1'); - vrfy(jacobi(2,11) == -1, '1231: jacobi(2,11) == -1'); - vrfy(jacobi(1,11) == 1, '1232: jacobi(1,11) == 1'); - vrfy(jacobi(0,11) == 0, '1233: jacobi(0,11) == 0'); - vrfy(jacobi(0,0) == 0, '1234: jacobi(0,0) == 0'); - vrfy(jacobi(-1,0) == 0, '1235: jacobi(-1,0) == 0'); - vrfy(jacobi(-1,-1) == 0, '1236: jacobi(-1,-1) == 0'); - vrfy(jacobi(0,-1) == 0, '1237: jacobi(0,-1) == 0'); + /* more jacobi tests */ + vrfy(jacobi(987897,987) == 0, '1208: jacobi(987897,987) == 0'); + vrfy(jacobi(897,987) == 0, '1209: jacobi(897,987) == 0'); + vrfy(jacobi(987,897) == 0, '1210: jacobi(987,897) == 0'); + vrfy(jacobi(90,897) == 0, '1211: jacobi(90,897) == 0'); + vrfy(jacobi(45,897) == 0, '1212: jacobi(45,897) == 0'); + vrfy(jacobi(897,45) == 0, '1213: jacobi(897,45) == 0'); + vrfy(jacobi(42,45) == 0, '1214: jacobi(42,45) == 0'); + vrfy(jacobi(21,45) == 0, '1215: jacobi(21,45) == 0'); + vrfy(jacobi(45,21) == 0, '1216: jacobi(45,21) == 0'); + vrfy(jacobi(3,21) == 0, '1217: jacobi(3,21) == 0'); + vrfy(jacobi(0,21) == 0, '1218: jacobi(0,21) == 0'); + vrfy(jacobi(0,20003) == 0, '1219: jacobi(0,20003) == 0'); + vrfy(jacobi(1,20003) == 1, '1220: jacobi(1,20003) == 1'); + vrfy(jacobi(1236,20003) == 1, '1221: jacobi(1236,20003) == 1'); + vrfy(jacobi(618,20003) == -1, '1222: jacobi(618,20003) == -1'); + vrfy(jacobi(309,20003) == 1, '1223: jacobi(309,20003) == 1'); + vrfy(jacobi(227,309) == 1, '1224: jacobi(227,309) == 1'); + vrfy(jacobi(82,227) == 1, '1225: jacobi(82,227) == 1'); + vrfy(jacobi(41,227) == -1, '1226: jacobi(41,227) == -1'); + vrfy(jacobi(22,41) == -1, '1227: jacobi(22,41) == -1'); + vrfy(jacobi(11,41) == -1, '1228: jacobi(11,41) == -1'); + vrfy(jacobi(8,11) == -1, '1229: jacobi(8,11) == -1'); + vrfy(jacobi(4,11) == 1, '1230: jacobi(4,11) == 1'); + vrfy(jacobi(2,11) == -1, '1231: jacobi(2,11) == -1'); + vrfy(jacobi(1,11) == 1, '1232: jacobi(1,11) == 1'); + vrfy(jacobi(0,11) == 0, '1233: jacobi(0,11) == 0'); + vrfy(jacobi(0,0) == 0, '1234: jacobi(0,0) == 0'); + vrfy(jacobi(-1,0) == 0, '1235: jacobi(-1,0) == 0'); + vrfy(jacobi(-1,-1) == 0, '1236: jacobi(-1,-1) == 0'); + vrfy(jacobi(0,-1) == 0, '1237: jacobi(0,-1) == 0'); - /* - * NOTE: Function tests are continued in test_functionss() - * starting at test 9000. - */ + /* + * NOTE: Function tests are continued in test_functionss() + * starting at test 9000. + */ - print '1293: Ending test_functions'; + print '1293: Ending test_functions'; } print '017: parsed test_functions()'; @@ -1507,17 +1507,17 @@ __ = 63; print "019: __ = 63"; define _test_underscore() { - local _a = 27; - local __a = 23209; + local _a = 27; + local __a = 23209; - print "4500: Beginning _test_underscore"; + print "4500: Beginning _test_underscore"; - vrfy(_a == 27, '4501: _a == 27'); - vrfy(_ == 49, '4502: _ == 49'); - vrfy(__ == 63, '4503: __ == 63'); - vrfy(__a == 23209, '4504: __a == 23209'); + vrfy(_a == 27, '4501: _a == 27'); + vrfy(_ == 49, '4502: _ == 49'); + vrfy(__ == 63, '4503: __ == 63'); + vrfy(__a == 23209, '4504: __a == 23209'); - print "4505: Ending _test_underscore"; + print "4505: Ending _test_underscore"; } print '020: parsed _test_underscore()'; @@ -1534,47 +1534,47 @@ print '020: parsed _test_underscore()'; */ define test_assoc() { - static a; - static b; - local A; + static a; + static b; + local A; - print '1300: Beginning associations test'; + print '1300: Beginning associations test'; - a = assoc(); - vrfy(size(a) == 0, '1301: size(a) == 0'); - a["curds"] = 13; - print '1302: a["curds"] = 13'; - vrfy(a["curds"] == 13, '1303: a["curds"] == 13'); - a[13] = 17; - print '1304: a[13] = 17'; - vrfy(a[13] == 17, '1305: a[13] == 17'); - vrfy(a[a["curds"]] == 17, '1306: a[a["curds"]] == 17'); - a[17] = 19; - print '1307: a[17] = 19'; - vrfy(a[17] == 19, '1308: a[17] == 19'); - vrfy(a[a["curds"]+4] == 19, '1309: a[a["curds"]+4] == 19'); - vrfy(size(a) == 3, '1310: size(a) == 3'); - vrfy(a[[search(a,17)]] == 17, '1311: (a[[search(a,17)]] == 17'); - vrfy(isnull(search(a,16)), '1312: isnull(search(a,16))'); - a["curds","whey"] = "spider"; - print '1313: a["curds","whey"] = "spider"'; - vrfy(a["curds","whey"] == "spider", - '1314: a["curds","whey"] == "spider"'); - vrfy(a[[rsearch(a,"spider")]] == "spider", - '1315: a[[rsearch(a,"spider")]] == "spider"'); - b = a; - print '1316: b = a'; - vrfy(b[17] == 19, '1317: b[17] == 19'); - vrfy(a == b, '1318: a == b'); - vrfy(isassoc(a) == 1, '1319: isassoc(a) == 1'); - vrfy(isassoc(1) == 0, '1320: isassoc(1) == 0'); - A = assoc(); - vrfy(quomod(13, 5, A[1], A[2]) == 1, - '1321: quomod(13, 5, A[1], A[2]) == 1'); - vrfy(A[1] == 2, '1322: A[1] == 2'); - vrfy(A[2] == 3, '1323: A[2] == 3'); + a = assoc(); + vrfy(size(a) == 0, '1301: size(a) == 0'); + a["curds"] = 13; + print '1302: a["curds"] = 13'; + vrfy(a["curds"] == 13, '1303: a["curds"] == 13'); + a[13] = 17; + print '1304: a[13] = 17'; + vrfy(a[13] == 17, '1305: a[13] == 17'); + vrfy(a[a["curds"]] == 17, '1306: a[a["curds"]] == 17'); + a[17] = 19; + print '1307: a[17] = 19'; + vrfy(a[17] == 19, '1308: a[17] == 19'); + vrfy(a[a["curds"]+4] == 19, '1309: a[a["curds"]+4] == 19'); + vrfy(size(a) == 3, '1310: size(a) == 3'); + vrfy(a[[search(a,17)]] == 17, '1311: (a[[search(a,17)]] == 17'); + vrfy(isnull(search(a,16)), '1312: isnull(search(a,16))'); + a["curds","whey"] = "spider"; + print '1313: a["curds","whey"] = "spider"'; + vrfy(a["curds","whey"] == "spider", + '1314: a["curds","whey"] == "spider"'); + vrfy(a[[rsearch(a,"spider")]] == "spider", + '1315: a[[rsearch(a,"spider")]] == "spider"'); + b = a; + print '1316: b = a'; + vrfy(b[17] == 19, '1317: b[17] == 19'); + vrfy(a == b, '1318: a == b'); + vrfy(isassoc(a) == 1, '1319: isassoc(a) == 1'); + vrfy(isassoc(1) == 0, '1320: isassoc(1) == 0'); + A = assoc(); + vrfy(quomod(13, 5, A[1], A[2]) == 1, + '1321: quomod(13, 5, A[1], A[2]) == 1'); + vrfy(A[1] == 2, '1322: A[1] == 2'); + vrfy(A[2] == 3, '1323: A[2] == 3'); - print '1324: Ending associations test'; + print '1324: Ending associations test'; } print '023: parsed test_assoc()'; @@ -1586,150 +1586,150 @@ print '023: parsed test_assoc()'; */ define test_list() { - static a; - static b; - static x = list(11,13,17,23,29); - static y0 = list(1,3,7,3,9); - static y1 = list(-9,-7,-3,-7,-1); - static y2 = list(-9,-7,-3,3,9); - static y3 = list(1,3,7,-7,-1); - static y4 = list(1,3,-3,3,-1); - local A,B,C,D,E; - local y,z; - local list1, list2; + static a; + static b; + static x = list(11,13,17,23,29); + static y0 = list(1,3,7,3,9); + static y1 = list(-9,-7,-3,-7,-1); + static y2 = list(-9,-7,-3,3,9); + static y3 = list(1,3,7,-7,-1); + static y4 = list(1,3,-3,3,-1); + local A,B,C,D,E; + local y,z; + local list1, list2; - print '1400: Beginning list test'; + print '1400: Beginning list test'; - a = list(2,3,5); - vrfy(a == list(2,3,5), '1401: a == list(2,3,5)'); - vrfy(a[[0]] == 2, '1402: a[[0]] == 2'); - vrfy(a[[1]] == 3, '1403: a[[1]] == 3'); - vrfy(a[[2]] == 5, '1404: a[[2]] == 5'); - vrfy(size(a) == 3, '1405: size(a) == 3'); - vrfy(search(a,3) == 1, '1406: search(a,3) == 1'); - vrfy(isnull(search(a,3,2)), '1407: isnull(search(a,3,2))'); - vrfy(rsearch(a,3,2) == 1, '1408: rsearch(a,3,2) == 1'); - push(a,7); - print '1409: push(a,7)'; - vrfy(search(a,7) == 0, '1410: search(a,7) == 0'); - vrfy(pop(a) == 7, '1411: pop(a) == 7'); - vrfy(size(a) == 3, '1412: size(a) == 3'); - append(a,7); - print '1413: append(a,7)'; - vrfy(search(a,7) == 3, '1414: search(a,7) == 3'); - vrfy(size(a) == 4, '1415: size(a) == 4'); - vrfy(remove(a) == 7, '1416: remove(a) == 7'); - vrfy(size(a) == 3, '1417: size(a) == 3'); - b = a; - print '1418: b = a'; - insert(a,1,7); - print '1419: insert(a,1,7)'; - vrfy(search(a,2) == 0, '1420: search(a,2) == 0'); - vrfy(search(a,7) == 1, '1421: search(a,7) == 1'); - vrfy(search(a,3) == 2, '1422: search(a,3) == 2'); - vrfy(search(a,5) == 3, '1423: search(a,5) == 3'); - vrfy(size(a) == 4, '1424: size(a) == 4'); - vrfy(delete(a,1) == 7, '1425: remove(a) == 7'); - vrfy(search(a,2) == 0, '1426: search(a,2) == 0'); - vrfy(search(a,3) == 1, '1427: search(a,3) == 1'); - vrfy(search(a,5) == 2, '1428: search(a,5) == 2'); - vrfy(size(a) == 3, '1429: size(a) == 3'); - vrfy(a == b, '1430: a == b'); - A = list(1,2,3); - print '1431: A = list(1,2,3)'; - B = list(4,5); - print '1432: B = list(4,5)'; - C = join(A,B); - print '1433: C = join(A,B)'; - D = list(1,2,3,4,5); - print '1434: D = list(1,2,3,4,5)'; - vrfy(C == D, '1435: C == D'); - E = list(5,4,3,2,1); - print '1436: E = list(5,4,3,2,1)'; - vrfy(reverse(D) == E, '1437: reverse(D) == E'); - vrfy(sort(list(1,3,5,2,4))==D,'1438: sort(list(1,3,5,2,4))==D'); - vrfy(head(D,2) == list(1,2), '1439: head(D,2) == list(1,2)'); - vrfy(head(D,-2) == list(2,1), '1440: head(D,-2) == list(2,1)'); - vrfy(head(D,5) == D, '1441: head(D,5) == D'); - vrfy(head(D,6) == D, '1442: head(D,6) == D'); - vrfy(head(D,-5) == E, '1443: head(D,-5) == E'); - vrfy(head(D,-6) == E, '1444: head(D,-6) == E'); - vrfy(tail(E,2) == list(2,1), '1445: tail(E,2) == list(2,1)'); - vrfy(tail(E,-2) == list(1,2), '1446: tail(E,-2) == list(1,2)'); - vrfy(tail(E,5) == E, '1447: tail(E,5) == E'); - vrfy(tail(E,6) == E, '1448: tail(E,6) == E'); - vrfy(tail(E,-5) == D, '1449: tail(E,-5) == D'); - vrfy(tail(E,-6) == D, '1450: tail(E,-6) == D'); - vrfy(segment(D,1,3) == list(2,3,4), - '1451: segment(D,1,3) == list(2,3,4)'); - vrfy(segment(D,3,1) == list(4,3,2), - '1452: segment(D,3,1) == list(4,3,2)'); - vrfy(segment(D,0,2) == head(D,3), - '1453: segment(D,0,2) == head(D,3)'); - vrfy(segment(D,2,0) == tail(E,3), - '1454: segment(D,2,0) == tail(E,3)'); - vrfy(segment(D,0,4) == head(D,5), - '1455: segment(D,0,4) == head(D,5)'); - vrfy(segment(D,4,0) == head(E,5), - '1456: segment(D,4,0) == head(E,5)'); - vrfy(segment(D,3,4) == tail(D,2), - '1457: segment(D,3,4) == tail(D,2)'); - vrfy(segment(D,4,3) == head(E,2), - '1458: segment(D,4,3) == head(E,2)'); - for (y=0; y < size(D); ++y) { - for (z=y; z < size(D); ++z) { - if (D != join(head(D,y), segment(D,y,z), tail(D,size(D)-z-1))) { - prob(strcat("join loop failed at y=",str(y)," z=",str(z))); - } - } - } - print '1459: join loop test'; - vrfy(mod(x,10,0) == y0, '1460: mod(x,10,0) == y0'); - vrfy(mod(x,10,1) == y1, '1461: mod(x,10,1) == y1'); - vrfy(mod(x,10,2) == y0, '1462: mod(x,10,2) == y0'); - vrfy(mod(x,10,3) == y1, '1463: mod(x,10,3) == y1'); - vrfy(mod(x,10,4) == y0, '1464: mod(x,10,4) == y0'); - vrfy(mod(x,10,5) == y1, '1465: mod(x,10,5) == y1'); - vrfy(mod(x,10,6) == y0, '1466: mod(x,10,6) == y0'); - vrfy(mod(x,10,7) == y1, '1467: mod(x,10,7) == y1'); - vrfy(mod(x,10,8) == y2, '1468: mod(x,10,8) == y2'); - vrfy(mod(x,10,9) == y3, '1469: mod(x,10,9) == y3'); - vrfy(mod(x,10,10) == y2, '1470: mod(x,10,10) == y2'); - vrfy(mod(x,10,11) == y3, '1471: mod(x,10,11) == y3'); - vrfy(mod(x,10,12) == y2, '1472: mod(x,10,12) == y2'); - vrfy(mod(x,10,13) == y3, '1473: mod(x,10,13) == y3'); - vrfy(mod(x,10,14) == y2, '1474: mod(x,10,14) == y2'); - vrfy(mod(x,10,15) == y3, '1475: mod(x,10,15) == y3'); - vrfy(mod(x,10,16) == y4, '1476: mod(x,10,16) == y4'); - vrfy(mod(x,10,16) == y4, '1477: mod(x,10,16) == y4'); - vrfy(mod(x,10,18) == y4, '1478: mod(x,10,18) == y4'); - vrfy(mod(x,10,19) == y4, '1479: mod(x,10,18) == y4'); - vrfy(mod(x,10,20) == y4, '1480: mod(x,10,20) == y4'); - vrfy(mod(x,10,21) == y4, '1481: mod(x,10,21) == y4'); - vrfy(mod(x,10,22) == y4, '1482: mod(x,10,22) == y4'); - vrfy(mod(x,10,23) == y4, '1483: mod(x,10,23) == y4'); - vrfy(mod(x,10,24) == y4, '1484: mod(x,10,24) == y4'); - vrfy(mod(x,10,25) == y4, '1485: mod(x,10,25) == y4'); - vrfy(mod(x,10,26) == y4, '1486: mod(x,10,26) == y4'); - vrfy(mod(x,10,27) == y4, '1487: mod(x,10,27) == y4'); - vrfy(mod(x,10,28) == y4, '1488: mod(x,10,28) == y4'); - vrfy(mod(x,10,29) == y4, '1489: mod(x,10,29) == y4'); - vrfy(mod(x,10,30) == y4, '1490: mod(x,10,30) == y4'); - vrfy(mod(x,10,31) == y4, '1491: mod(x,10,31) == y4'); - list1 = list(3,1,"x",2,null()); - print '1492: list1 = list(3,1,"x",2,null())'; - list2 = list(null(),1,2,3,"x"); - print '1493: list2 = list(null(),1,2,3,"x")'; - vrfy(sort(list1) == list2, '1494: sort(list1) == list2'); - A = list(1,2,3,4); - print '1495: A = list(1,2,3,4)'; - B = makelist(4) = {1,2,3,4}; - print '1496: B = makelist(4) = {1,2,3,4}'; - vrfy(A == B, '1497: A == B'); - vrfy((A = {,,5}) == list(1,2,5,4), - '1498: (A = {,,5}) == list(1,2,5,4)'); + a = list(2,3,5); + vrfy(a == list(2,3,5), '1401: a == list(2,3,5)'); + vrfy(a[[0]] == 2, '1402: a[[0]] == 2'); + vrfy(a[[1]] == 3, '1403: a[[1]] == 3'); + vrfy(a[[2]] == 5, '1404: a[[2]] == 5'); + vrfy(size(a) == 3, '1405: size(a) == 3'); + vrfy(search(a,3) == 1, '1406: search(a,3) == 1'); + vrfy(isnull(search(a,3,2)), '1407: isnull(search(a,3,2))'); + vrfy(rsearch(a,3,2) == 1, '1408: rsearch(a,3,2) == 1'); + push(a,7); + print '1409: push(a,7)'; + vrfy(search(a,7) == 0, '1410: search(a,7) == 0'); + vrfy(pop(a) == 7, '1411: pop(a) == 7'); + vrfy(size(a) == 3, '1412: size(a) == 3'); + append(a,7); + print '1413: append(a,7)'; + vrfy(search(a,7) == 3, '1414: search(a,7) == 3'); + vrfy(size(a) == 4, '1415: size(a) == 4'); + vrfy(remove(a) == 7, '1416: remove(a) == 7'); + vrfy(size(a) == 3, '1417: size(a) == 3'); + b = a; + print '1418: b = a'; + insert(a,1,7); + print '1419: insert(a,1,7)'; + vrfy(search(a,2) == 0, '1420: search(a,2) == 0'); + vrfy(search(a,7) == 1, '1421: search(a,7) == 1'); + vrfy(search(a,3) == 2, '1422: search(a,3) == 2'); + vrfy(search(a,5) == 3, '1423: search(a,5) == 3'); + vrfy(size(a) == 4, '1424: size(a) == 4'); + vrfy(delete(a,1) == 7, '1425: remove(a) == 7'); + vrfy(search(a,2) == 0, '1426: search(a,2) == 0'); + vrfy(search(a,3) == 1, '1427: search(a,3) == 1'); + vrfy(search(a,5) == 2, '1428: search(a,5) == 2'); + vrfy(size(a) == 3, '1429: size(a) == 3'); + vrfy(a == b, '1430: a == b'); + A = list(1,2,3); + print '1431: A = list(1,2,3)'; + B = list(4,5); + print '1432: B = list(4,5)'; + C = join(A,B); + print '1433: C = join(A,B)'; + D = list(1,2,3,4,5); + print '1434: D = list(1,2,3,4,5)'; + vrfy(C == D, '1435: C == D'); + E = list(5,4,3,2,1); + print '1436: E = list(5,4,3,2,1)'; + vrfy(reverse(D) == E, '1437: reverse(D) == E'); + vrfy(sort(list(1,3,5,2,4))==D,'1438: sort(list(1,3,5,2,4))==D'); + vrfy(head(D,2) == list(1,2), '1439: head(D,2) == list(1,2)'); + vrfy(head(D,-2) == list(2,1), '1440: head(D,-2) == list(2,1)'); + vrfy(head(D,5) == D, '1441: head(D,5) == D'); + vrfy(head(D,6) == D, '1442: head(D,6) == D'); + vrfy(head(D,-5) == E, '1443: head(D,-5) == E'); + vrfy(head(D,-6) == E, '1444: head(D,-6) == E'); + vrfy(tail(E,2) == list(2,1), '1445: tail(E,2) == list(2,1)'); + vrfy(tail(E,-2) == list(1,2), '1446: tail(E,-2) == list(1,2)'); + vrfy(tail(E,5) == E, '1447: tail(E,5) == E'); + vrfy(tail(E,6) == E, '1448: tail(E,6) == E'); + vrfy(tail(E,-5) == D, '1449: tail(E,-5) == D'); + vrfy(tail(E,-6) == D, '1450: tail(E,-6) == D'); + vrfy(segment(D,1,3) == list(2,3,4), + '1451: segment(D,1,3) == list(2,3,4)'); + vrfy(segment(D,3,1) == list(4,3,2), + '1452: segment(D,3,1) == list(4,3,2)'); + vrfy(segment(D,0,2) == head(D,3), + '1453: segment(D,0,2) == head(D,3)'); + vrfy(segment(D,2,0) == tail(E,3), + '1454: segment(D,2,0) == tail(E,3)'); + vrfy(segment(D,0,4) == head(D,5), + '1455: segment(D,0,4) == head(D,5)'); + vrfy(segment(D,4,0) == head(E,5), + '1456: segment(D,4,0) == head(E,5)'); + vrfy(segment(D,3,4) == tail(D,2), + '1457: segment(D,3,4) == tail(D,2)'); + vrfy(segment(D,4,3) == head(E,2), + '1458: segment(D,4,3) == head(E,2)'); + for (y=0; y < size(D); ++y) { + for (z=y; z < size(D); ++z) { + if (D != join(head(D,y), segment(D,y,z), tail(D,size(D)-z-1))) { + prob(strcat("join loop failed at y=",str(y)," z=",str(z))); + } + } + } + print '1459: join loop test'; + vrfy(mod(x,10,0) == y0, '1460: mod(x,10,0) == y0'); + vrfy(mod(x,10,1) == y1, '1461: mod(x,10,1) == y1'); + vrfy(mod(x,10,2) == y0, '1462: mod(x,10,2) == y0'); + vrfy(mod(x,10,3) == y1, '1463: mod(x,10,3) == y1'); + vrfy(mod(x,10,4) == y0, '1464: mod(x,10,4) == y0'); + vrfy(mod(x,10,5) == y1, '1465: mod(x,10,5) == y1'); + vrfy(mod(x,10,6) == y0, '1466: mod(x,10,6) == y0'); + vrfy(mod(x,10,7) == y1, '1467: mod(x,10,7) == y1'); + vrfy(mod(x,10,8) == y2, '1468: mod(x,10,8) == y2'); + vrfy(mod(x,10,9) == y3, '1469: mod(x,10,9) == y3'); + vrfy(mod(x,10,10) == y2, '1470: mod(x,10,10) == y2'); + vrfy(mod(x,10,11) == y3, '1471: mod(x,10,11) == y3'); + vrfy(mod(x,10,12) == y2, '1472: mod(x,10,12) == y2'); + vrfy(mod(x,10,13) == y3, '1473: mod(x,10,13) == y3'); + vrfy(mod(x,10,14) == y2, '1474: mod(x,10,14) == y2'); + vrfy(mod(x,10,15) == y3, '1475: mod(x,10,15) == y3'); + vrfy(mod(x,10,16) == y4, '1476: mod(x,10,16) == y4'); + vrfy(mod(x,10,16) == y4, '1477: mod(x,10,16) == y4'); + vrfy(mod(x,10,18) == y4, '1478: mod(x,10,18) == y4'); + vrfy(mod(x,10,19) == y4, '1479: mod(x,10,18) == y4'); + vrfy(mod(x,10,20) == y4, '1480: mod(x,10,20) == y4'); + vrfy(mod(x,10,21) == y4, '1481: mod(x,10,21) == y4'); + vrfy(mod(x,10,22) == y4, '1482: mod(x,10,22) == y4'); + vrfy(mod(x,10,23) == y4, '1483: mod(x,10,23) == y4'); + vrfy(mod(x,10,24) == y4, '1484: mod(x,10,24) == y4'); + vrfy(mod(x,10,25) == y4, '1485: mod(x,10,25) == y4'); + vrfy(mod(x,10,26) == y4, '1486: mod(x,10,26) == y4'); + vrfy(mod(x,10,27) == y4, '1487: mod(x,10,27) == y4'); + vrfy(mod(x,10,28) == y4, '1488: mod(x,10,28) == y4'); + vrfy(mod(x,10,29) == y4, '1489: mod(x,10,29) == y4'); + vrfy(mod(x,10,30) == y4, '1490: mod(x,10,30) == y4'); + vrfy(mod(x,10,31) == y4, '1491: mod(x,10,31) == y4'); + list1 = list(3,1,"x",2,null()); + print '1492: list1 = list(3,1,"x",2,null())'; + list2 = list(null(),1,2,3,"x"); + print '1493: list2 = list(null(),1,2,3,"x")'; + vrfy(sort(list1) == list2, '1494: sort(list1) == list2'); + A = list(1,2,3,4); + print '1495: A = list(1,2,3,4)'; + B = makelist(4) = {1,2,3,4}; + print '1496: B = makelist(4) = {1,2,3,4}'; + vrfy(A == B, '1497: A == B'); + vrfy((A = {,,5}) == list(1,2,5,4), + '1498: (A = {,,5}) == list(1,2,5,4)'); - print '1499: Ending list test'; + print '1499: Ending list test'; } print '024: parsed test_list()'; @@ -1741,136 +1741,136 @@ print '024: parsed test_list()'; */ define test_rand() { - local init; /* initial generator state */ - local state0; /* a generator state */ - local tmp; - local n; + local init; /* initial generator state */ + local state0; /* a generator state */ + local tmp; + local n; - print '1500: Beginning rand test'; + print '1500: Beginning rand test'; - /* test save and restore of the initial state */ - tmp = srand(0); - print '1501: tmp = srand(0)'; - init = srand(); - print '1502: init = srand()'; - state0 = srand(0); - print '1503: state0 = srand(0)'; - vrfy(state0 == init, '1504: state0 == init'); + /* test save and restore of the initial state */ + tmp = srand(0); + print '1501: tmp = srand(0)'; + init = srand(); + print '1502: init = srand()'; + state0 = srand(0); + print '1503: state0 = srand(0)'; + vrfy(state0 == init, '1504: state0 == init'); - /* test the subtractive 100 shuffle generator */ - tmp = srand(0); - print '1505: tmp = srand(0)'; - vrfy(rand() == 0x1fe5b46fba7e069d, \ - '1506: rand() == 0x1fe5b46fba7e069d'); - vrfy(rand() == 0x308d32d9bdf2dc6f, \ - '1507: rand() == 0x308d32d9bdf2dc6f'); - tmp = srand(init); - print '1508: tmp = srand(init)'; - vrfy(rand() == 0x1fe5b46fba7e069d, \ - '1509: rand() == 0x1fe5b46fba7e069d'); - vrfy(rand() == 0x308d32d9bdf2dc6f, \ - '1510: rand() == 0x308d32d9bdf2dc6f'); + /* test the subtractive 100 shuffle generator */ + tmp = srand(0); + print '1505: tmp = srand(0)'; + vrfy(rand() == 0x1fe5b46fba7e069d, \ + '1506: rand() == 0x1fe5b46fba7e069d'); + vrfy(rand() == 0x308d32d9bdf2dc6f, \ + '1507: rand() == 0x308d32d9bdf2dc6f'); + tmp = srand(init); + print '1508: tmp = srand(init)'; + vrfy(rand() == 0x1fe5b46fba7e069d, \ + '1509: rand() == 0x1fe5b46fba7e069d'); + vrfy(rand() == 0x308d32d9bdf2dc6f, \ + '1510: rand() == 0x308d32d9bdf2dc6f'); - /* test range interface */ - tmp = srand(0); - print '1511: tmp = srand(0)'; - vrfy(rand(12345678901234567890) == 0x1fe5b46fba7e069d, \ - '1512: rand(12345678901234567890) == 0x1fe5b46fba7e069d'); - vrfy(rand(216091) == 0xc234, '1513: rand(216091) == 0xc234'); - vrfy(rand(100) == 0x59, '1514: rand(100) == 0x59'); - vrfy(rand(-46,46) == 0x2d, '1515: rand(-46,46) == 0x2d'); - tmp = srand(0); - print '1516: tmp = srand(0)'; - vrfy(rand(2^64) == 0x1fe5b46fba7e069d, \ - '1517: rand(2^64) == 0x1fe5b46fba7e069d'); - vrfy(rand(0,2^64) == 0x308d32d9bdf2dc6f, \ - '1518: rand(0,2^64) == 0x308d32d9bdf2dc6f'); + /* test range interface */ + tmp = srand(0); + print '1511: tmp = srand(0)'; + vrfy(rand(12345678901234567890) == 0x1fe5b46fba7e069d, \ + '1512: rand(12345678901234567890) == 0x1fe5b46fba7e069d'); + vrfy(rand(216091) == 0xc234, '1513: rand(216091) == 0xc234'); + vrfy(rand(100) == 0x59, '1514: rand(100) == 0x59'); + vrfy(rand(-46,46) == 0x2d, '1515: rand(-46,46) == 0x2d'); + tmp = srand(0); + print '1516: tmp = srand(0)'; + vrfy(rand(2^64) == 0x1fe5b46fba7e069d, \ + '1517: rand(2^64) == 0x1fe5b46fba7e069d'); + vrfy(rand(0,2^64) == 0x308d32d9bdf2dc6f, \ + '1518: rand(0,2^64) == 0x308d32d9bdf2dc6f'); - /* test different forms of seeding the initial state */ - tmp = srand(0); - print '1519: tmp = srand(0)'; - vrfy(srand() == init, '1520: srand() == init'); - tmp = srand(0x87e6ec938ff55aa5<<64); - print '1521: tmp = srand(0x87e6ec938ff55aa5<<64)'; - print '1522: test disabled'; - tmp = srand(state0); - print '1523: tmp = srand(state0)'; - vrfy(srand() == init, '1524: srand() == init'); - tmp = srand(init); - print '1525: tmp = srand(init)'; - vrfy(srand() == init, '1526: srand() == init'); - vrfy(tmp == init, '1527: tmp == init'); + /* test different forms of seeding the initial state */ + tmp = srand(0); + print '1519: tmp = srand(0)'; + vrfy(srand() == init, '1520: srand() == init'); + tmp = srand(0x87e6ec938ff55aa5<<64); + print '1521: tmp = srand(0x87e6ec938ff55aa5<<64)'; + print '1522: test disabled'; + tmp = srand(state0); + print '1523: tmp = srand(state0)'; + vrfy(srand() == init, '1524: srand() == init'); + tmp = srand(init); + print '1525: tmp = srand(init)'; + vrfy(srand() == init, '1526: srand() == init'); + vrfy(tmp == init, '1527: tmp == init'); - /* test the bit length interface */ - tmp = srand(0); - print '1528: tmp = srand(0)'; - vrfy(randbit(64) == 0x1fe5b46fba7e069d, \ - '1529: randbit(64) == 0x1fe5b46fba7e069d'); - vrfy(randbit(128) == 0x308d32d9bdf2dc6f45d3e3b3361b79e4, \ - '1530: randbit(128) == 0x308d32d9bdf2dc6f45d3e3b3361b79e4'); - vrfy(randbit(64) == 0xd4ef1e3336022d81, \ - '1531: randbit(64) == 0xd4ef1e3336022d81'); - vrfy(randbit(128) == 0x66b086e6c34e42124a1fc5d4e5c6f598, \ - '1532: randbit(128) == 0x66b086e6c34e42124a1fc5d4e5c6f598'); - tmp = srand(0); - print '1533: tmp = srand(0)'; - vrfy(randbit(32) == 0x1fe5b46f, '1534: randbit(32) == 0x1fe5b46f'); - vrfy(randbit(32) == 0xba7e069d, '1535: randbit(32) == 0xba7e069d'); - vrfy(randbit(1) == 0x0, '1536: randbit(1) == 0x0'); - vrfy(randbit(5) == 0xc, '1537: randbit(5) == 0xc'); - vrfy(randbit(33) == 0x46996cde, '1538: randbit(33) == 0x46996cde'); - vrfy(randbit(25) == 0x1f2dc6f, '1539: randbit(25) == 0x1f2dc6f'); - vrfy(randbit(2) == 0x1, '1540: randbit(2) == 0x1'); - vrfy(randbit(13) == 0x2e9, '1541: randbit(13) == 0x2e9'); - vrfy(randbit(18) == 0x3c766, '1542: randbit(18) == 0x3c766'); - vrfy(randbit(8) == 0x6c, '1543: randbit(8) == 0x6c'); - vrfy(randbit(9) == 0x6d, '1544: randbit(9) == 0x6d'); - vrfy(randbit(70) == 0x39e4d4ef1e3336022d, \ - '1545: randbit(70) == 0x39e4d4ef1e3336022d'); - print '1546: test unused'; - vrfy(randbit(8) == 0x81, '1547: randbit(8) == 0x81'); - vrfy(randbit(65) == 0xcd610dcd869c8424, \ - '1548: randbit(65) == 0xcd610dcd869c8424'); - vrfy(randbit(63) == 0x4a1fc5d4e5c6f598, \ - '1549: randbit(63) == 0x4a1fc5d4e5c6f598'); + /* test the bit length interface */ + tmp = srand(0); + print '1528: tmp = srand(0)'; + vrfy(randbit(64) == 0x1fe5b46fba7e069d, \ + '1529: randbit(64) == 0x1fe5b46fba7e069d'); + vrfy(randbit(128) == 0x308d32d9bdf2dc6f45d3e3b3361b79e4, \ + '1530: randbit(128) == 0x308d32d9bdf2dc6f45d3e3b3361b79e4'); + vrfy(randbit(64) == 0xd4ef1e3336022d81, \ + '1531: randbit(64) == 0xd4ef1e3336022d81'); + vrfy(randbit(128) == 0x66b086e6c34e42124a1fc5d4e5c6f598, \ + '1532: randbit(128) == 0x66b086e6c34e42124a1fc5d4e5c6f598'); + tmp = srand(0); + print '1533: tmp = srand(0)'; + vrfy(randbit(32) == 0x1fe5b46f, '1534: randbit(32) == 0x1fe5b46f'); + vrfy(randbit(32) == 0xba7e069d, '1535: randbit(32) == 0xba7e069d'); + vrfy(randbit(1) == 0x0, '1536: randbit(1) == 0x0'); + vrfy(randbit(5) == 0xc, '1537: randbit(5) == 0xc'); + vrfy(randbit(33) == 0x46996cde, '1538: randbit(33) == 0x46996cde'); + vrfy(randbit(25) == 0x1f2dc6f, '1539: randbit(25) == 0x1f2dc6f'); + vrfy(randbit(2) == 0x1, '1540: randbit(2) == 0x1'); + vrfy(randbit(13) == 0x2e9, '1541: randbit(13) == 0x2e9'); + vrfy(randbit(18) == 0x3c766, '1542: randbit(18) == 0x3c766'); + vrfy(randbit(8) == 0x6c, '1543: randbit(8) == 0x6c'); + vrfy(randbit(9) == 0x6d, '1544: randbit(9) == 0x6d'); + vrfy(randbit(70) == 0x39e4d4ef1e3336022d, \ + '1545: randbit(70) == 0x39e4d4ef1e3336022d'); + print '1546: test unused'; + vrfy(randbit(8) == 0x81, '1547: randbit(8) == 0x81'); + vrfy(randbit(65) == 0xcd610dcd869c8424, \ + '1548: randbit(65) == 0xcd610dcd869c8424'); + vrfy(randbit(63) == 0x4a1fc5d4e5c6f598, \ + '1549: randbit(63) == 0x4a1fc5d4e5c6f598'); - /* check to be sure that the srand(1) bug was fixed */ - tmp = srand(1); - print '1550: tmp = srand(1)'; - n = 1; - print '1551: n = 1'; - vrfy(num(n), '1552: num(n)'); - vrfy(den(n), '1553: den(n)'); - vrfy(randbit(64) == 0xbf989a4c504a541d, \ - '1554: randbit(64) == 0xbf989a4c504a541d'); - /* test randbit skip interface */ - tmp = srand(0); - print '1555: tmp = srand(0)'; - vrfy(randbit(20) == 0x1fe5b, '1556: randbit(20) == 0x1fe5b'); - vrfy(randbit(20) == 0x46fba, '1557: randbit(20) == 0x46fba'); - vrfy(randbit(20) == 0x7e069, '1558: randbit(20) == 0x7e069'); - vrfy(randbit(20) == 0xd308d, '1559: randbit(20) == 0xd308d'); - tmp = srand(0); - print '1560: tmp = srand(0)'; - vrfy(randbit(-20) == 20, '1561: randbit(-20) == 20'); - vrfy(randbit(20) == 290746, '1562: randbit(20) == 290746'); - vrfy(randbit(-20) == 20, '1563: randbit(-20) == 20'); - vrfy(randbit(20) == 864397, '1564: randbit(20) == 864397'); + /* check to be sure that the srand(1) bug was fixed */ + tmp = srand(1); + print '1550: tmp = srand(1)'; + n = 1; + print '1551: n = 1'; + vrfy(num(n), '1552: num(n)'); + vrfy(den(n), '1553: den(n)'); + vrfy(randbit(64) == 0xbf989a4c504a541d, \ + '1554: randbit(64) == 0xbf989a4c504a541d'); + /* test randbit skip interface */ + tmp = srand(0); + print '1555: tmp = srand(0)'; + vrfy(randbit(20) == 0x1fe5b, '1556: randbit(20) == 0x1fe5b'); + vrfy(randbit(20) == 0x46fba, '1557: randbit(20) == 0x46fba'); + vrfy(randbit(20) == 0x7e069, '1558: randbit(20) == 0x7e069'); + vrfy(randbit(20) == 0xd308d, '1559: randbit(20) == 0xd308d'); + tmp = srand(0); + print '1560: tmp = srand(0)'; + vrfy(randbit(-20) == 20, '1561: randbit(-20) == 20'); + vrfy(randbit(20) == 290746, '1562: randbit(20) == 290746'); + vrfy(randbit(-20) == 20, '1563: randbit(-20) == 20'); + vrfy(randbit(20) == 864397, '1564: randbit(20) == 864397'); - /* test randbit without and arg */ - tmp = srand(0); - print '1565: tmp = srand(0)'; - vrfy(randbit() == 0, '1566: randbit() == 0'); - vrfy(randbit() == 0, '1567: randbit() == 0'); - vrfy(randbit() == 0, '1568: randbit() == 0'); - vrfy(randbit() == 1, '1569: randbit() == 1'); + /* test randbit without and arg */ + tmp = srand(0); + print '1565: tmp = srand(0)'; + vrfy(randbit() == 0, '1566: randbit() == 0'); + vrfy(randbit() == 0, '1567: randbit() == 0'); + vrfy(randbit() == 0, '1568: randbit() == 0'); + vrfy(randbit() == 1, '1569: randbit() == 1'); - /* test seed() as best as we can */ - vrfy(seed() >= 0, '1570: seed() >= 0'); - vrfy(seed() < 2^64, '1571: seed() < 2^64'); - vrfy(isrand(srand(seed())), '1572: isrand(srand(seed()))'); + /* test seed() as best as we can */ + vrfy(seed() >= 0, '1570: seed() >= 0'); + vrfy(seed() < 2^64, '1571: seed() < 2^64'); + vrfy(isrand(srand(seed())), '1572: isrand(srand(seed()))'); - print '1573: Ending rand test'; + print '1573: Ending rand test'; } print '025: parsed test_rand()'; @@ -1882,330 +1882,330 @@ print '025: parsed test_rand()'; */ define test_mode() { - local tmp; + local tmp; - print '1600: Beginning mode/base test'; + print '1600: Beginning mode/base test'; - tmp = config("mode", "frac"); - print '1601: tmp = config("mode", "frac")'; - tmp = config("mode", "frac"); - print '1602: tmp = config("mode", "frac")'; - vrfy(base() == 1/3, '1603: base() == 1/3'); + tmp = config("mode", "frac"); + print '1601: tmp = config("mode", "frac")'; + tmp = config("mode", "frac"); + print '1602: tmp = config("mode", "frac")'; + vrfy(base() == 1/3, '1603: base() == 1/3'); - tmp = config("mode", "int"); - print '1604: tmp = config("mode", "int")'; - vrfy(tmp == "fraction", '1605: tmp == "fraction"'); - vrfy(base() == -10, '1606: base() == -10'); + tmp = config("mode", "int"); + print '1604: tmp = config("mode", "int")'; + vrfy(tmp == "fraction", '1605: tmp == "fraction"'); + vrfy(base() == -10, '1606: base() == -10'); - tmp = config("mode", "real"); - print '1607: tmp = config("mode", "real")'; - vrfy(tmp == "integer", '1608: tmp == "integer"'); - vrfy(base() == 10, '1609: base() == 10'); + tmp = config("mode", "real"); + print '1607: tmp = config("mode", "real")'; + vrfy(tmp == "integer", '1608: tmp == "integer"'); + vrfy(base() == 10, '1609: base() == 10'); - tmp = config("mode", "exp"); - print '1610: tmp = config("mode", "exp")'; - vrfy(tmp == "real", '1611: tmp == "real"'); - vrfy(base() == 1e20, '1612: base() == 1e20'); + tmp = config("mode", "exp"); + print '1610: tmp = config("mode", "exp")'; + vrfy(tmp == "real", '1611: tmp == "real"'); + vrfy(base() == 1e20, '1612: base() == 1e20'); - tmp = config("mode", "hex"); - print '1613: tmp = config("mode", "hex")'; - vrfy(tmp == "scientific", '1614: tmp == "scientific"'); - vrfy(base() == 16, '1615: base() == 16'); + tmp = config("mode", "hex"); + print '1613: tmp = config("mode", "hex")'; + vrfy(tmp == "scientific", '1614: tmp == "scientific"'); + vrfy(base() == 16, '1615: base() == 16'); - tmp = config("mode", "oct"); - print '1616: tmp = config("mode", "oct")'; - vrfy(tmp == "hexadecimal", '1617: tmp == "hexadecimal"'); - vrfy(base() == 8, '1618: base() == 8'); + tmp = config("mode", "oct"); + print '1616: tmp = config("mode", "oct")'; + vrfy(tmp == "hexadecimal", '1617: tmp == "hexadecimal"'); + vrfy(base() == 8, '1618: base() == 8'); - tmp = config("mode", "bin"); - print '1619: tmp = config("mode", "bin")'; - vrfy(tmp == "octal", '1620: tmp == "octal"'); - vrfy(base() == 2, '1621: base() == 2'); + tmp = config("mode", "bin"); + print '1619: tmp = config("mode", "bin")'; + vrfy(tmp == "octal", '1620: tmp == "octal"'); + vrfy(base() == 2, '1621: base() == 2'); - tmp = config("mode", "eng"); - print '1622: tmp = config("mode", "eng")'; - vrfy(tmp == "binary", '1623: tmp == "binary"'); - vrfy(base() == 1000, '1624: base() == 1000'); + tmp = config("mode", "eng"); + print '1622: tmp = config("mode", "eng")'; + vrfy(tmp == "binary", '1623: tmp == "binary"'); + vrfy(base() == 1000, '1624: base() == 1000'); - tmp = config("mode", "real"); - print '1625: tmp = config("mode", "real")'; - vrfy(tmp == "engineering", '1626: tmp == "engineering"'); + tmp = config("mode", "real"); + print '1625: tmp = config("mode", "real")'; + vrfy(tmp == "engineering", '1626: tmp == "engineering"'); - tmp = base(1/3); - print '1627: tmp = base(1/3)'; - vrfy(config("mode") == "fraction", - '1628: config("mode") == "fraction"'); + tmp = base(1/3); + print '1627: tmp = base(1/3)'; + vrfy(config("mode") == "fraction", + '1628: config("mode") == "fraction"'); - tmp = base(-10); - print '1629: tmp = base(-10)'; - vrfy(config("mode") == "integer", - '1630: config("mode") == "integer"'); + tmp = base(-10); + print '1629: tmp = base(-10)'; + vrfy(config("mode") == "integer", + '1630: config("mode") == "integer"'); - tmp = base(10); - print '1631: tmp = base(10)'; - vrfy(config("mode") == "real", '1632: config("mode") == "real"'); + tmp = base(10); + print '1631: tmp = base(10)'; + vrfy(config("mode") == "real", '1632: config("mode") == "real"'); - tmp = base(1e20); - print '1633: tmp = base(1e20)'; - vrfy(config("mode") == "scientific", - '1634: config("mode") == "scientific"'); + tmp = base(1e20); + print '1633: tmp = base(1e20)'; + vrfy(config("mode") == "scientific", + '1634: config("mode") == "scientific"'); - tmp = base(16); - print '1635: tmp = base(16)'; - vrfy(config("mode") == "hexadecimal", \ - '1636: config("mode") == "hexadecimal"'); + tmp = base(16); + print '1635: tmp = base(16)'; + vrfy(config("mode") == "hexadecimal", \ + '1636: config("mode") == "hexadecimal"'); - tmp = base(8); - print '1637: tmp = base(8)'; - vrfy(config("mode") == "octal", '1638: config("mode") == "octal"'); + tmp = base(8); + print '1637: tmp = base(8)'; + vrfy(config("mode") == "octal", '1638: config("mode") == "octal"'); - tmp = base(2); - print '1639: tmp = base(2)'; - vrfy(config("mode") == "binary",'1640: config("mode") == "binary"'); + tmp = base(2); + print '1639: tmp = base(2)'; + vrfy(config("mode") == "binary",'1640: config("mode") == "binary"'); - tmp = base(1000); - print '1641: tmp = base(1000)'; - vrfy(config("mode") == "engineering", - '1642: config("mode") == "engineering"'); + tmp = base(1000); + print '1641: tmp = base(1000)'; + vrfy(config("mode") == "engineering", + '1642: config("mode") == "engineering"'); - tmp = base(1/3); - print '1643: tmp = base(1/3)'; - vrfy(str(0x80000000) == "2147483648", \ - '1644: str(0x8000000) == \"2147483648\"'); - vrfy(str(0xffffffff) == "4294967295", \ - '1645: str(0xffffffff) == \"4294967295\"'); - vrfy(str(3e9) == "3000000000", \ - '1646: str(3e9) == \"3000000000\"'); - vrfy(str(1/3) == "1/3", \ - '1647: str(1/3) == \"1/3\"'); - vrfy(str(2e8) == "200000000", \ - '1648: str(2e8) == \"200000000"'); - vrfy(str(200e6) == "200000000", \ - '1649: str(200e6) == \"200000000"'); - vrfy(str(0b100111) == "39", \ - '1650: str(0b100111) == \"39"'); - vrfy(str(07543) == "3939", \ - '1651: str(07543) == \"3939"'); - vrfy(str(7543) == "7543", \ - '1652: str(7543) == \"7543"'); + tmp = base(1/3); + print '1643: tmp = base(1/3)'; + vrfy(str(0x80000000) == "2147483648", \ + '1644: str(0x8000000) == \"2147483648\"'); + vrfy(str(0xffffffff) == "4294967295", \ + '1645: str(0xffffffff) == \"4294967295\"'); + vrfy(str(3e9) == "3000000000", \ + '1646: str(3e9) == \"3000000000\"'); + vrfy(str(1/3) == "1/3", \ + '1647: str(1/3) == \"1/3\"'); + vrfy(str(2e8) == "200000000", \ + '1648: str(2e8) == \"200000000"'); + vrfy(str(200e6) == "200000000", \ + '1649: str(200e6) == \"200000000"'); + vrfy(str(0b100111) == "39", \ + '1650: str(0b100111) == \"39"'); + vrfy(str(07543) == "3939", \ + '1651: str(07543) == \"3939"'); + vrfy(str(7543) == "7543", \ + '1652: str(7543) == \"7543"'); - tmp = base(8); - print '1653: tmp = base(8)'; - vrfy(str(0x80000000) == "020000000000", \ - '1654: str(0x8000000) == \"020000000000\"'); - vrfy(str(0xffffffff) == "037777777777", \ - '1655: str(0xffffffff) == \"037777777777\"'); - vrfy(str(3e9) == "026264057000", \ - '1656: str(3e9) == \"026264057000\"'); - vrfy(str(1/3) == "1/3", \ - '1657: str(1/3) == \"1/3\"'); - vrfy(str(2e8) == "01372741000", \ - '1658: str(2e8) == \"01372741000"'); - vrfy(str(200e6) == "01372741000", \ - '1659: str(200e6) == \"01372741000"'); - vrfy(str(0b100111) == "047", \ - '1660: str(0b100111) == \"047"'); - vrfy(str(07543) == "07543", \ - '1661: str(07543) == \"07543"'); - vrfy(str(7543) == "016567", \ - '1662: str(7543) == \"016567"'); + tmp = base(8); + print '1653: tmp = base(8)'; + vrfy(str(0x80000000) == "020000000000", \ + '1654: str(0x8000000) == \"020000000000\"'); + vrfy(str(0xffffffff) == "037777777777", \ + '1655: str(0xffffffff) == \"037777777777\"'); + vrfy(str(3e9) == "026264057000", \ + '1656: str(3e9) == \"026264057000\"'); + vrfy(str(1/3) == "1/3", \ + '1657: str(1/3) == \"1/3\"'); + vrfy(str(2e8) == "01372741000", \ + '1658: str(2e8) == \"01372741000"'); + vrfy(str(200e6) == "01372741000", \ + '1659: str(200e6) == \"01372741000"'); + vrfy(str(0b100111) == "047", \ + '1660: str(0b100111) == \"047"'); + vrfy(str(07543) == "07543", \ + '1661: str(07543) == \"07543"'); + vrfy(str(7543) == "016567", \ + '1662: str(7543) == \"016567"'); - tmp = base(16); - print '1663: tmp = base(16)'; - vrfy(str(0x80000000) == "0x80000000", \ - '1664: str(0x8000000) == \"0x80000000\"'); - vrfy(str(0xffffffff) == "0xffffffff", \ - '1665: str(0xffffffff) == \"0xffffffff\"'); - vrfy(str(3e9) == "0xb2d05e00", \ - '1666: str(3e9) == \"0xb2d05e00\"'); - vrfy(str(1/3) == "1/3", \ - '1667: str(1/3) == \"1/3\"'); - vrfy(str(2e8) == "0xbebc200", \ - '1668: str(2e8) == \"0xbebc200"'); - vrfy(str(200e6) == "0xbebc200", \ - '1669: str(200e6) == \"0xbebc200"'); - vrfy(str(0b100111) == "0x27", \ - '1670: str(0b100111) == \"0x27"'); - vrfy(str(07543) == "0xf63", \ - '1671: str(07543) == \"0xf63"'); - vrfy(str(7543) == "0x1d77", \ - '1672: str(7543) == \"0x1d77"'); + tmp = base(16); + print '1663: tmp = base(16)'; + vrfy(str(0x80000000) == "0x80000000", \ + '1664: str(0x8000000) == \"0x80000000\"'); + vrfy(str(0xffffffff) == "0xffffffff", \ + '1665: str(0xffffffff) == \"0xffffffff\"'); + vrfy(str(3e9) == "0xb2d05e00", \ + '1666: str(3e9) == \"0xb2d05e00\"'); + vrfy(str(1/3) == "1/3", \ + '1667: str(1/3) == \"1/3\"'); + vrfy(str(2e8) == "0xbebc200", \ + '1668: str(2e8) == \"0xbebc200"'); + vrfy(str(200e6) == "0xbebc200", \ + '1669: str(200e6) == \"0xbebc200"'); + vrfy(str(0b100111) == "0x27", \ + '1670: str(0b100111) == \"0x27"'); + vrfy(str(07543) == "0xf63", \ + '1671: str(07543) == \"0xf63"'); + vrfy(str(7543) == "0x1d77", \ + '1672: str(7543) == \"0x1d77"'); - tmp = base(2); - print '1673: tmp = base(2)'; - vrfy(str(0x80000000) == "0b10000000000000000000000000000000", \ - '1674: str(0x8000000) == \"0b10000000000000000000000000000000\"'); - vrfy(str(0xffffffff) == "0b11111111111111111111111111111111", \ - '1675: str(0xffffffff) == \"0b11111111111111111111111111111111\"'); - vrfy(str(3e9) == "0b10110010110100000101111000000000", \ - '1676: str(3e9) == \"0b10110010110100000101111000000000\"'); - vrfy(str(1/3) == "1/0b11", \ - '1677: str(1/3) == \"1/0b11\"'); - vrfy(str(2e8) == "0b1011111010111100001000000000", \ - '1678: str(2e8) == \"0b1011111010111100001000000000"'); - vrfy(str(200e6) == "0b1011111010111100001000000000", \ - '1679: str(200e6) == \"0b1011111010111100001000000000"'); - vrfy(str(0b100111) == "0b100111", \ - '1680: str(0b100111) == \"0b100111"'); - vrfy(str(07543) == "0b111101100011", \ - '1681: str(07543) == \"0b111101100011"'); - vrfy(str(7543) == "0b1110101110111", \ - '1682: str(7543) == \"0b1110101110111"'); + tmp = base(2); + print '1673: tmp = base(2)'; + vrfy(str(0x80000000) == "0b10000000000000000000000000000000", \ + '1674: str(0x8000000) == \"0b10000000000000000000000000000000\"'); + vrfy(str(0xffffffff) == "0b11111111111111111111111111111111", \ + '1675: str(0xffffffff) == \"0b11111111111111111111111111111111\"'); + vrfy(str(3e9) == "0b10110010110100000101111000000000", \ + '1676: str(3e9) == \"0b10110010110100000101111000000000\"'); + vrfy(str(1/3) == "1/0b11", \ + '1677: str(1/3) == \"1/0b11\"'); + vrfy(str(2e8) == "0b1011111010111100001000000000", \ + '1678: str(2e8) == \"0b1011111010111100001000000000"'); + vrfy(str(200e6) == "0b1011111010111100001000000000", \ + '1679: str(200e6) == \"0b1011111010111100001000000000"'); + vrfy(str(0b100111) == "0b100111", \ + '1680: str(0b100111) == \"0b100111"'); + vrfy(str(07543) == "0b111101100011", \ + '1681: str(07543) == \"0b111101100011"'); + vrfy(str(7543) == "0b1110101110111", \ + '1682: str(7543) == \"0b1110101110111"'); - tmp = base(1e20); - print '1683: tmp = base(1e20)'; - vrfy(str(0x80000000) == "2.147483648e9", \ - '1684: str(0x8000000) == \"2.147483648e9\"'); - vrfy(str(0xffffffff) == "4.294967295e9", \ - '1685: str(0xffffffff) == \"4.294967295e9\"'); - vrfy(str(3e9) == "3e9", \ - '1686: str(3e9) == \"3e9\"'); - vrfy(str(1/3) == "~3.33333333333333333333e-1", \ - '1687: str(1/3) == \"~3.33333333333333333333e-1\"'); - vrfy(str(2e8) == "2e8", \ - '1688: str(2e8) == \"2e8"'); - vrfy(str(200e6) == "2e8", \ - '1689: str(200e6) == \"2e8"'); - vrfy(str(0b100111) == "3.9e1", \ - '1690: str(0b100111) == \"3.9e1"'); - vrfy(str(07543) == "3.939e3", \ - '1691: str(07543) == \"3.939e3"'); - vrfy(str(7543) == "7.543e3", \ - '1692: str(7543) == \"7.543e3"'); + tmp = base(1e20); + print '1683: tmp = base(1e20)'; + vrfy(str(0x80000000) == "2.147483648e9", \ + '1684: str(0x8000000) == \"2.147483648e9\"'); + vrfy(str(0xffffffff) == "4.294967295e9", \ + '1685: str(0xffffffff) == \"4.294967295e9\"'); + vrfy(str(3e9) == "3e9", \ + '1686: str(3e9) == \"3e9\"'); + vrfy(str(1/3) == "~3.33333333333333333333e-1", \ + '1687: str(1/3) == \"~3.33333333333333333333e-1\"'); + vrfy(str(2e8) == "2e8", \ + '1688: str(2e8) == \"2e8"'); + vrfy(str(200e6) == "2e8", \ + '1689: str(200e6) == \"2e8"'); + vrfy(str(0b100111) == "3.9e1", \ + '1690: str(0b100111) == \"3.9e1"'); + vrfy(str(07543) == "3.939e3", \ + '1691: str(07543) == \"3.939e3"'); + vrfy(str(7543) == "7.543e3", \ + '1692: str(7543) == \"7.543e3"'); - tmp = base(1000); - print '1693: tmp = base(1000)'; - vrfy(str(0x80000000) == "2.147483648e9", \ - '1694: str(0x8000000) == \"2.147483648e9"'); - vrfy(str(0xffffffff) == "4.294967295e9", \ - '1695: str(0xffffffff) == \"4.294967295e9\"'); - vrfy(str(3e9) == "3e9", \ - '1696: str(3e9) == \"3e9\"'); - vrfy(str(1/3) == "~333.33333333333333333333e-3", \ - '1697: str(1/3) == \"~333.33333333333333333333e-3\"'); - vrfy(str(2e8) == "200e6", \ - '1698: str(2e8) == \"200e6"'); - vrfy(str(200e6) == "200e6", \ - '1699: str(200e6) == \"200e6"'); - vrfy(str(0b100111) == "39", \ - '1700: str(0b100111) == \"39"'); - vrfy(str(07543) == "3.939e3", \ - '1701: str(07543) == \"3.939e3"'); - vrfy(str(7543) == "7.543e3", \ - '1702: str(7543) == \"7.543e3"'); + tmp = base(1000); + print '1693: tmp = base(1000)'; + vrfy(str(0x80000000) == "2.147483648e9", \ + '1694: str(0x8000000) == \"2.147483648e9"'); + vrfy(str(0xffffffff) == "4.294967295e9", \ + '1695: str(0xffffffff) == \"4.294967295e9\"'); + vrfy(str(3e9) == "3e9", \ + '1696: str(3e9) == \"3e9\"'); + vrfy(str(1/3) == "~333.33333333333333333333e-3", \ + '1697: str(1/3) == \"~333.33333333333333333333e-3\"'); + vrfy(str(2e8) == "200e6", \ + '1698: str(2e8) == \"200e6"'); + vrfy(str(200e6) == "200e6", \ + '1699: str(200e6) == \"200e6"'); + vrfy(str(0b100111) == "39", \ + '1700: str(0b100111) == \"39"'); + vrfy(str(07543) == "3.939e3", \ + '1701: str(07543) == \"3.939e3"'); + vrfy(str(7543) == "7.543e3", \ + '1702: str(7543) == \"7.543e3"'); - tmp = base(-10); - print '1703: tmp = base(-10)'; - vrfy(str(0x80000000) == "2147483648", \ - '1704: str(0x8000000) == \"2147483648\"'); - vrfy(str(0xffffffff) == "4294967295", \ - '1705: str(0xffffffff) == \"4294967295\"'); - vrfy(str(3e9) == "3000000000", \ - '1706: str(3e9) == \"3000000000\"'); - vrfy(str(1/3) == "~0", \ - '1707: str(1/3) == \"~0\"'); - vrfy(str(2e8) == "200000000", \ - '1708: str(2e8) == \"200000000"'); - vrfy(str(200e6) == "200000000", \ - '1709: str(200e6) == \"200000000"'); - vrfy(str(0b100111) == "39", \ - '1710: str(0b100111) == \"39"'); - vrfy(str(07543) == "3939", \ - '1711: str(07543) == \"3939"'); - vrfy(str(7543) == "7543", \ - '1712: str(7543) == \"7543"'); + tmp = base(-10); + print '1703: tmp = base(-10)'; + vrfy(str(0x80000000) == "2147483648", \ + '1704: str(0x8000000) == \"2147483648\"'); + vrfy(str(0xffffffff) == "4294967295", \ + '1705: str(0xffffffff) == \"4294967295\"'); + vrfy(str(3e9) == "3000000000", \ + '1706: str(3e9) == \"3000000000\"'); + vrfy(str(1/3) == "~0", \ + '1707: str(1/3) == \"~0\"'); + vrfy(str(2e8) == "200000000", \ + '1708: str(2e8) == \"200000000"'); + vrfy(str(200e6) == "200000000", \ + '1709: str(200e6) == \"200000000"'); + vrfy(str(0b100111) == "39", \ + '1710: str(0b100111) == \"39"'); + vrfy(str(07543) == "3939", \ + '1711: str(07543) == \"3939"'); + vrfy(str(7543) == "7543", \ + '1712: str(7543) == \"7543"'); - tmp = base(10); - print '1713: tmp = base(10)'; - vrfy(str(0x80000000) == "2147483648", \ - '1714: str(0x8000000) == \"2147483648\"'); - vrfy(str(0xffffffff) == "4294967295", \ - '1715: str(0xffffffff) == \"4294967295\"'); - vrfy(str(3e9) == "3000000000", \ - '1716: str(3e9) == \"3000000000\"'); - vrfy(str(1/3) == "~0.33333333333333333333", \ - '1717: str(1/3) == \"~0.33333333333333333333"'); - vrfy(str(2e8) == "200000000", \ - '1718: str(2e8) == \"200000000"'); - vrfy(str(200e6) == "200000000", \ - '1719: str(200e6) == \"200000000"'); - vrfy(str(0b100111) == "39", \ - '1720: str(0b100111) == \"39"'); - vrfy(str(07543) == "3939", \ - '1721: str(07543) == \"3939"'); - vrfy(str(7543) == "7543", \ - '1722: str(7543) == \"7543"'); + tmp = base(10); + print '1713: tmp = base(10)'; + vrfy(str(0x80000000) == "2147483648", \ + '1714: str(0x8000000) == \"2147483648\"'); + vrfy(str(0xffffffff) == "4294967295", \ + '1715: str(0xffffffff) == \"4294967295\"'); + vrfy(str(3e9) == "3000000000", \ + '1716: str(3e9) == \"3000000000\"'); + vrfy(str(1/3) == "~0.33333333333333333333", \ + '1717: str(1/3) == \"~0.33333333333333333333"'); + vrfy(str(2e8) == "200000000", \ + '1718: str(2e8) == \"200000000"'); + vrfy(str(200e6) == "200000000", \ + '1719: str(200e6) == \"200000000"'); + vrfy(str(0b100111) == "39", \ + '1720: str(0b100111) == \"39"'); + vrfy(str(07543) == "3939", \ + '1721: str(07543) == \"3939"'); + vrfy(str(7543) == "7543", \ + '1722: str(7543) == \"7543"'); - /* test base2() functionality */ - vrfy(base2() == 0, '1723: base2() == 0'); - vrfy(base2(0) == 0, '1724: base2(0) == 0'); - vrfy(base2() == 0, '1725: base2() == 0'); + /* test base2() functionality */ + vrfy(base2() == 0, '1723: base2() == 0'); + vrfy(base2(0) == 0, '1724: base2(0) == 0'); + vrfy(base2() == 0, '1725: base2() == 0'); - vrfy(base2(16) == 0, '1726: base2(16) == 0'); - vrfy(base2() == 16, '1727: base2() == 16'); - vrfy(str(3e9) == "3000000000 /* 0xb2d05e00 */", - '1728: str(3e9) == "3000000000 /* 0xb2d05e00 */"'); + vrfy(base2(16) == 0, '1726: base2(16) == 0'); + vrfy(base2() == 16, '1727: base2() == 16'); + vrfy(str(3e9) == "3000000000 /* 0xb2d05e00 */", + '1728: str(3e9) == "3000000000 /* 0xb2d05e00 */"'); - vrfy(base2(1/3) == 16, '1728: base2(16) == 16'); - vrfy(base2() == 1/3, '1729: base2() == 1/3'); - vrfy(str(23209) == "23209 /* 23209 */", - '1730: str(23209) == "23209 /* 23209 */"'); - vrfy(str(3/2) == "1.5 /* 3/2 */", - '1731: str(3/2) == "1.5 /* 3/2 */"'); + vrfy(base2(1/3) == 16, '1728: base2(16) == 16'); + vrfy(base2() == 1/3, '1729: base2() == 1/3'); + vrfy(str(23209) == "23209 /* 23209 */", + '1730: str(23209) == "23209 /* 23209 */"'); + vrfy(str(3/2) == "1.5 /* 3/2 */", + '1731: str(3/2) == "1.5 /* 3/2 */"'); - vrfy(base2(8) == 1/3, '1732: base2(8) == 1/3'); - vrfy(base2() == 8, '1733: base2() == 8'); - vrfy(str(23209) == "23209 /* 055251 */", - '1734: str(23209) == "23209 /* 055251 */"'); - vrfy(str(3/2) == "1.5 /* 3/2 */", - '1735: str(3/2) == "1.5 /* 3/2 */"'); + vrfy(base2(8) == 1/3, '1732: base2(8) == 1/3'); + vrfy(base2() == 8, '1733: base2() == 8'); + vrfy(str(23209) == "23209 /* 055251 */", + '1734: str(23209) == "23209 /* 055251 */"'); + vrfy(str(3/2) == "1.5 /* 3/2 */", + '1735: str(3/2) == "1.5 /* 3/2 */"'); - vrfy(base2(2) == 8, '1736: base2(2) == 8'); - vrfy(base2() == 2, '1737: base2() == 2'); - vrfy(str(23209) == "23209 /* 0b101101010101001 */", - '1738: str(23209) == "23209 /* 0b101101010101001 */"'); - vrfy(str(3/2) == "1.5 /* 0b11/0b10 */", - '1739: str(3/2) == "1.5 /* 0b11/0b10 */"'); + vrfy(base2(2) == 8, '1736: base2(2) == 8'); + vrfy(base2() == 2, '1737: base2() == 2'); + vrfy(str(23209) == "23209 /* 0b101101010101001 */", + '1738: str(23209) == "23209 /* 0b101101010101001 */"'); + vrfy(str(3/2) == "1.5 /* 0b11/0b10 */", + '1739: str(3/2) == "1.5 /* 0b11/0b10 */"'); - vrfy(base2(1e20) == 2, '1740: base2(1e20) == 2'); - vrfy(base2() == 1e20, '1741: base2() == 1e20'); - vrfy(str(23209) == "23209 /* 2.3209e4 */", - '1742: str(23209) == "23209 /* 2.3209e4 */"'); - vrfy(str(3/2) == "1.5 /* 1.5 */", - '1743: str(3/2) == "1.5 /* 1.5 */"'); + vrfy(base2(1e20) == 2, '1740: base2(1e20) == 2'); + vrfy(base2() == 1e20, '1741: base2() == 1e20'); + vrfy(str(23209) == "23209 /* 2.3209e4 */", + '1742: str(23209) == "23209 /* 2.3209e4 */"'); + vrfy(str(3/2) == "1.5 /* 1.5 */", + '1743: str(3/2) == "1.5 /* 1.5 */"'); - vrfy(base2(-10) == 1e20, '1744: base2(-10) == 1e20'); - vrfy(base2() == -10, '1745: base2() == -10'); - vrfy(str(23209) == "23209 /* 23209 */", - '1746: str(23209) == "23209 /* 23209 */"'); - vrfy(str(3/2) == "1.5 /* ~2 */", - '1747: str(3/2) == "1.5 /* ~2 */"'); + vrfy(base2(-10) == 1e20, '1744: base2(-10) == 1e20'); + vrfy(base2() == -10, '1745: base2() == -10'); + vrfy(str(23209) == "23209 /* 23209 */", + '1746: str(23209) == "23209 /* 23209 */"'); + vrfy(str(3/2) == "1.5 /* ~2 */", + '1747: str(3/2) == "1.5 /* ~2 */"'); - vrfy(base2(1000) == -10, '1748: base2(1000) == -1000'); - vrfy(base2() == 1000, '1749: base2() == 1000'); - vrfy(str(23209) == "23209 /* 23.209e3 */", - '1750: str(23209) == "23209 /* 23.209e3 */"'); - vrfy(str(3/2) == "1.5 /* 1.5 */", - '1751: str(3/2) == "1.5 /* 1.5 */"'); + vrfy(base2(1000) == -10, '1748: base2(1000) == -1000'); + vrfy(base2() == 1000, '1749: base2() == 1000'); + vrfy(str(23209) == "23209 /* 23.209e3 */", + '1750: str(23209) == "23209 /* 23.209e3 */"'); + vrfy(str(3/2) == "1.5 /* 1.5 */", + '1751: str(3/2) == "1.5 /* 1.5 */"'); - vrfy(base2(10) == 1000, '1752: base2(10) == 1000'); - vrfy(base2() == 10, '1753: base2() == 10'); - vrfy(str(23209) == "23209 /* 23209 */", - '1754: str(23209) == "23209 /* 23209 */"'); - vrfy(str(3/2) == "1.5 /* 1.5 */", - '1755: str(3/2) == "1.5 /* 1.5 */"'); + vrfy(base2(10) == 1000, '1752: base2(10) == 1000'); + vrfy(base2() == 10, '1753: base2() == 10'); + vrfy(str(23209) == "23209 /* 23209 */", + '1754: str(23209) == "23209 /* 23209 */"'); + vrfy(str(3/2) == "1.5 /* 1.5 */", + '1755: str(3/2) == "1.5 /* 1.5 */"'); - vrfy(base2(0) == 10, '1756: base2(0) == 10'); - vrfy(base2() == 0, '1757: base2() == 0'); - vrfy(str(23209) == "23209", - '1758: str(23209) == "23209"'); - vrfy(str(3/2) == "1.5", - '1759: str(3/2) == "1.5"'); + vrfy(base2(0) == 10, '1756: base2(0) == 10'); + vrfy(base2() == 0, '1757: base2() == 0'); + vrfy(str(23209) == "23209", + '1758: str(23209) == "23209"'); + vrfy(str(3/2) == "1.5", + '1759: str(3/2) == "1.5"'); - vrfy(base() == 10, '1760: base() == 10'); - vrfy(base2() == 0, '1761: base2() == 0'); + vrfy(base() == 10, '1760: base() == 10'); + vrfy(base2() == 0, '1761: base2() == 0'); - print '1762: Ending mode/base test'; + print '1762: Ending mode/base test'; } print '026: parsed test_mode()'; @@ -2220,50 +2220,50 @@ print '027: read -once surd'; /**/ define test_obj() { - static obj surd a; - static obj surd b; - local PP; + static obj surd a; + static obj surd b; + local PP; - print '1800: Beginning object test'; + print '1800: Beginning object test'; - surd_type = -1; - vrfy(surd_type == -1, '1801: surd_type == -1'); - a = surd(2,3); - print '1802: a = surd(2,3)'; - vrfy(a == surd(2,3), '1803: a == surd(2,3)'); - vrfy(surd_value(a) == 2+3i, '1804: surd_value(a) == 2+3i'); - vrfy(conj(a) == surd(2,-3), '1805: conj(a) == surd(2,-3)'); - vrfy(norm(a) == 13, '1806: norm(a) == 13'); - vrfy(a+1 == surd(3,3), '1807: a+1 == surd(3,3)'); - b = surd(3,4); - print '1808: b = surd(3,4)'; - vrfy(a+b == surd(5,7), '1809: a+b == surd(5,7)'); - vrfy(a-b == surd(-1,-1), '1810: a-b == surd(-1,-1)'); - vrfy(++a == surd(3,3), '1811: ++a == surd(3,3)'); - vrfy(--a == surd(2,3), '1812: --a == surd(2,3)'); - vrfy(-a == surd(-2,-3), '1813: -a == surd(-2,-3)'); - vrfy(a*2 == surd(4,6), '1814: a*2 == surd(4,6)'); - vrfy(a*b == surd(-6,17), '1815: a*b == surd(-6,17)'); - vrfy(a^2 == surd(-5,12), '1816: a^2 == surd(-5,12)'); - vrfy(scale(a,2) == surd(8,12), '1817: scale(a,2) == surd(8,12)'); - vrfy(a<<3 == surd(16,24), '1818: a<<3 == surd(16,24)'); - vrfy(a/2 == surd(1,1.5), '1819: a/2 == surd(1,1.5)'); - vrfy(a/b == surd(0.72,0.04), '1820: a/b == surd(0.72,0.04)'); - vrfy(1/b == surd(0.12,-0.16), '1821: 1/b == surd(0.12,-0.16)'); - vrfy(inverse(b) == 1/b, '1822: inverse(b) == 1/b'); - vrfy(a != b, '1823: a != b'); - surd_type = 2; - print '1824: surd_type = 2'; - vrfy(surd_type == 2, '1825: surd_type == 2'); - vrfy(sgn(a) == 1, '1826: sgn(a) == 1'); - vrfy(a < b, '1827: a < b'); - vrfy(a <= a, '1828: a < a'); - vrfy(isobj(a) == 1, '1829: isobj(a) == 1'); + surd_type = -1; + vrfy(surd_type == -1, '1801: surd_type == -1'); + a = surd(2,3); + print '1802: a = surd(2,3)'; + vrfy(a == surd(2,3), '1803: a == surd(2,3)'); + vrfy(surd_value(a) == 2+3i, '1804: surd_value(a) == 2+3i'); + vrfy(conj(a) == surd(2,-3), '1805: conj(a) == surd(2,-3)'); + vrfy(norm(a) == 13, '1806: norm(a) == 13'); + vrfy(a+1 == surd(3,3), '1807: a+1 == surd(3,3)'); + b = surd(3,4); + print '1808: b = surd(3,4)'; + vrfy(a+b == surd(5,7), '1809: a+b == surd(5,7)'); + vrfy(a-b == surd(-1,-1), '1810: a-b == surd(-1,-1)'); + vrfy(++a == surd(3,3), '1811: ++a == surd(3,3)'); + vrfy(--a == surd(2,3), '1812: --a == surd(2,3)'); + vrfy(-a == surd(-2,-3), '1813: -a == surd(-2,-3)'); + vrfy(a*2 == surd(4,6), '1814: a*2 == surd(4,6)'); + vrfy(a*b == surd(-6,17), '1815: a*b == surd(-6,17)'); + vrfy(a^2 == surd(-5,12), '1816: a^2 == surd(-5,12)'); + vrfy(scale(a,2) == surd(8,12), '1817: scale(a,2) == surd(8,12)'); + vrfy(a<<3 == surd(16,24), '1818: a<<3 == surd(16,24)'); + vrfy(a/2 == surd(1,1.5), '1819: a/2 == surd(1,1.5)'); + vrfy(a/b == surd(0.72,0.04), '1820: a/b == surd(0.72,0.04)'); + vrfy(1/b == surd(0.12,-0.16), '1821: 1/b == surd(0.12,-0.16)'); + vrfy(inverse(b) == 1/b, '1822: inverse(b) == 1/b'); + vrfy(a != b, '1823: a != b'); + surd_type = 2; + print '1824: surd_type = 2'; + vrfy(surd_type == 2, '1825: surd_type == 2'); + vrfy(sgn(a) == 1, '1826: sgn(a) == 1'); + vrfy(a < b, '1827: a < b'); + vrfy(a <= a, '1828: a < a'); + vrfy(isobj(a) == 1, '1829: isobj(a) == 1'); - obj pt {x,y}, PP = obj pair {A,B} = {obj pt, obj pt}; - print '1830: obj pt {x,y}, PP = obj pair {A,B} = {obj pt, obj pt}'; + obj pt {x,y}, PP = obj pair {A,B} = {obj pt, obj pt}; + print '1830: obj pt {x,y}, PP = obj pair {A,B} = {obj pt, obj pt}'; - print '1831: Ending object test'; + print '1831: Ending object test'; } print '028: parsed test_obj()'; @@ -2275,199 +2275,199 @@ print '028: parsed test_obj()'; */ define test_prime() { - print '1900: Beginning prime builtins test'; + print '1900: Beginning prime builtins test'; - vrfy(isprime(-3) == 1, '1901: isprime(-3) == 1'); - vrfy(isprime(-1) == 0, '1902: isprime(-1) == 0'); - vrfy(isprime(0) == 0, '1903: isprime(0) == 0'); - vrfy(isprime(1) == 0, '1904: isprime(1) == 0'); - vrfy(isprime(2) == 1, '1905: isprime(2) == 1'); - vrfy(isprime(3) == 1, '1906: isprime(3) == 1'); - vrfy(isprime(4) == 0, '1907: isprime(4) == 0'); - vrfy(isprime(5) == 1, '1908: isprime(5) == 1'); - vrfy(isprime(17) == 1, '1909: isprime(17) == 1'); - vrfy(isprime(100) == 0, '1910: isprime(100) == 0'); - vrfy(isprime(21701,-1) == 1, '1911: isprime(21701,-1) == 1'); - vrfy(isprime(65521,-1) == 1, '1912: isprime(65521,-1) == 1'); - vrfy(isprime(65535,-1) == 0, '1913: isprime(65535,-1) == 0'); - vrfy(isprime(65536,-1) == 0, '1914: isprime(65536,-1) == 0'); - vrfy(isprime(1234577) == 1, '1915: isprime(1234577) == 1'); - vrfy(isprime(1234579) == 0, '1916: isprime(1234579) == 0'); - vrfy(isprime(2^31-9) == 0, '1917: isprime(2^31-9) == 0'); - vrfy(isprime(2^31-1) == 1, '1918: isprime(2^31-1) == 1'); - vrfy(isprime(2^31+9) == 0, '1919: isprime(2^31+11) == 0'); - vrfy(isprime(2^31+11) == 1, '1920: isprime(2^31+11) == 1'); - vrfy(isprime(3e9) == 0, '1921: isprime(3e9) == 0'); - vrfy(isprime(3e9+19) == 1, '1922: isprime(3e9+19) == 1'); - vrfy(isprime(2^32-7) == 0, '1923: isprime(2^32-7) == 0'); - vrfy(isprime(2^32-5) == 1, '1924: isprime(2^32-5) == 1'); - vrfy(isprime(2^32,-1) == 0, '1925: isprime(2^32,-1) == 0'); - vrfy(isprime(2^32+1,-1) == -1, '1926: isprime(2^32+1,-1) == -1'); - vrfy(isprime(3^99,2) == 2, '1927: isprime(3^99,2) == 2'); - vrfy(isprime(4^99,2) == 0, '1928: isprime(3^99,2) == 0'); - vrfy(nextprime(-3) == 5, '1929: nextprime(-3) == 5'); - vrfy(nextprime(0) == 2, '1930: nextprime(0) == 2'); - vrfy(nextprime(1) == 2, '1931: nextprime(1) == 2'); - vrfy(nextprime(2) == 3, '1932: nextprime(2) == 3'); - vrfy(nextprime(3) == 5, '1933: nextprime(3) == 5'); - vrfy(nextprime(4) == 5, '1934: nextprime(4) == 5'); - vrfy(nextprime(5) == 7, '1935: nextprime(5) == 7'); - vrfy(nextprime(17) == 19, '1936: nextprime(17) == 19'); - vrfy(nextprime(100) == 101, '1937: nextprime(100) == 101'); - vrfy(nextprime(21701,-1) == 21713, - '1938: nextprime(21701,-1) == 21713'); - vrfy(nextprime(65519) == 65521, - '1939: nextprime(65519) == 65521'); - vrfy(nextprime(65520) == 65521, - '1940: nextprime(65520) == 65521'); - vrfy(nextprime(65521,-1) == 65537, - '1941: nextprime(65521,-1) == 65537'); - vrfy(nextprime(65531) == 65537, - '1942: nextprime(65531) == 65537'); - vrfy(nextprime(65535,-1) == 65537, - '1943: nextprime(65535,-1) == 65537'); - vrfy(nextprime(65536) == 65537, - '1944: nextprime(65536) == 65537'); - vrfy(nextprime(1234576,2)==1234577, - '1945: nextprime(1234576,2)==1234577'); - vrfy(nextprime(2^31-9) == 2^31-1, - '1946: nextprime(2^31-9) == 2^31-1'); - vrfy(nextprime(2^31-1) == 2^31+11, - '1947: nextprime(2^31-1) == 2^31+11'); - vrfy(nextprime(3e9) == 3e9+19,'1948: nextprime(3e9) == 3e9+19'); - vrfy(nextprime(2^32-7) == 2^32-5, - '1949: nextprime(2^32-7) == 2^32-5'); - vrfy(nextprime(2^32,-1) == -1, '1950: nextprime(2^32,-1) == -1'); - vrfy(nextprime(2^32+5,-1) == -1,'1951: nextprime(2^32+5,-1) == -1'); - vrfy(nextprime(3^99,-1) == -1, '1952: nextprime(3^99,-1) == -1'); - vrfy(nextprime(3^99,2) == 2, '1953: nextprime(3^99,2) == 2'); - vrfy(prevprime(-3,-1) == 2, '1954: prevprime(-3,-1) == 2'); - vrfy(prevprime(0,-1) == 0, '1955: prevprime(0,-1) == 0'); - vrfy(prevprime(1,-1) == 0, '1956: prevprime(1,-1) == 0'); - vrfy(prevprime(2,-2) == 0, '1957: prevprime(2,-2) == 0'); - vrfy(prevprime(5) == 3, '1958: prevprime(5) == 3'); - vrfy(prevprime(4) == 3, '1959: prevprime(4) == 3'); - vrfy(prevprime(7) == 5, '1960: prevprime(7) == 5'); - vrfy(prevprime(19) == 17, '1961: prevprime(19) == 17'); - vrfy(prevprime(100) == 97, '1962: prevprime(100) == 97'); - vrfy(prevprime(21713,-1) == 21701, - '1963: prevprime(21713,-1) == 21701'); - vrfy(prevprime(65520) == 65519, - '1964: prevprime(65520) == 65519'); - vrfy(prevprime(65521) == 65519, - '1965: prevprime(65521) == 65519'); - vrfy(prevprime(65522) == 65521, - '1966: prevprime(65520) == 65521'); - vrfy(prevprime(65523) == 65521, - '1967: prevprime(65523) == 65521'); - vrfy(prevprime(65531) == 65521, - '1968: prevprime(65531) == 65521'); - vrfy(prevprime(65535) == 65521, - '1969: prevprime(65535) == 65521'); - vrfy(prevprime(65536) == 65521, - '1970: prevprime(65536) == 65521'); - vrfy(prevprime(65537) == 65521, - '1971: prevprime(65537) == 65521'); - vrfy(prevprime(65539) == 65537, - '1972: prevprime(65539) == 65537'); - vrfy(prevprime(1234578,2)==1234577, - '1973: prevprime(1234578,2)==1234577'); - vrfy(prevprime(2^31-1) == 2^31-19, - '1974: prevprime(2^31-1) == 2^31-19'); - vrfy(prevprime(2^31+11) == 2^31-1, - '1975: prevprime(2^31+11) == 2^31-1'); - vrfy(prevprime(3e9) == 3e9-71,'1976: prevprime(3e9) == 3e9-17'); - vrfy(prevprime(2^32-3) == 2^32-5, - '1977: prevprime(2^32-3) == 2^32-5'); - vrfy(prevprime(2^32-1) == 2^32-5, - '1978: prevprime(2^32-1) == 2^32-5'); - vrfy(prevprime(2^32,-1) == -1, '1979: prevprime(2^32,-1) == -1'); - vrfy(prevprime(3^99,-1) == -1, '1980: prevprime(3^99,-1) == -1'); - vrfy(prevprime(3^99,2) == 2, '1981: prevprime(3^99,2) == 2'); - vrfy(pix(-1) == 0, '1982: pix(-1) == 0'); - vrfy(pix(1) == 0, '1983: pix(1) == 0'); - vrfy(pix(2) == 1, '1984: pix(2) == 1'); - vrfy(pix(3) == 2, '1985: pix(3) == 2'); - vrfy(pix(100) == 25, '1986: pix(100) == 25'); - vrfy(pix(1000) == 168, '1987: pix(1000) == 168'); - vrfy(pix(10000) == 1229, '1988: pix(10000) == 1229'); - vrfy(pix(100000) == 9592, '1989: pix(100000) == 9592'); - vrfy(pix(2^19+59) == 43393, '1990: pix(2^19+59) == 43393'); - vrfy(pix(1000000) == 78498, '1991: pix(1000000) == 78498'); - vrfy(pix(10000000) == 664579, '1992: pix(10000000) == 664579'); - vrfy(pix(2^32-6) == 203280220, '1993: pix(2^32-6) == 203280220'); - vrfy(pix(2^32-5) == 203280221, '1994: pix(2^32-5) == 203280221'); - vrfy(pix(2^32-1) == 203280221, '1995: pix(2^32-1) == 203280221'); - vrfy(pfact(40) == 7420738134810,'1996: pfact(40) == 7420738134810'); - vrfy(pfact(200)/pfact(198)==199,'1997: pfact(200)/pfact(198)==199'); - vrfy(nextprime(3e9)==nextcand(3e9), - '1998: nextprime(3e9)==nextcand(3e9)'); - vrfy(prevprime(3e9)==prevcand(3e9), - '1999: prevprime(3e9)==prevcand(3e9)'); - vrfy(nextcand(2^100,0)-2^100 == 3, - '2000: nextcand(2^100,0)-2^100 == 3'); - vrfy(nextcand(2^100)-2^100 == 277, - '2001: nextcand(2^100)-2^100 == 277'); - vrfy(2^100-prevcand(2^100,0) == 5, - '2002: 2^100-prevcand(2^100,0) == 5'); - vrfy(2^100-prevcand(2^100) == 15, - '2003: 2^100-prevcand(2^100) == 15'); - vrfy(nextcand(2^50,4,5)-2^50 == 55, - '2004: nextcand(2^50,4,5)-2^50 == 55'); - vrfy(2^50-prevcand(2^50,4,5) == 27, - '2005: 2^50-prevcand(2^50,4,5) == 27'); - vrfy(nextprime(2^32-6) == 2^32-5, - '2006: nextprime(2^32-6) == 2^32-5'); - vrfy(nextprime(2^32-5) == 2^32+15, - '2007: nextprime(2^32-5) == 2^32+15'); - vrfy(prevprime(2^32-1) == 2^32-5, - '2008: prevprime(2^32-1) == 2^32-5'); - vrfy(prevcand(2^50,4,5,0,4) == 0, - '2009: prevcand(2^50,4,5,0,4) == 0'); - vrfy(2^50-prevcand(2^50,4,5,1,4) == 27, - '2010: 2^50-prevcand(2^50,4,5,1,4) == 27'); - vrfy(prevcand(2^50,4,5,2,4) == 2, - '2011: prevcand(2^50,4,5,2,4) == 2'); - vrfy(2^50-prevcand(2^50,4,5,3,4) == 113, - '2012: 2^50-prevcand(2^50,4,5,3,4) == 113'); - vrfy(2^50-prevcand(2^50,4,5,7,17) == 813, - '2013: 2^50-prevcand(2^50,4,5,7,17) == 813'); - vrfy(nextcand(2^50,4,5,0,4) == 0, - '2014: nextcand(2^50,4,5,0,4) == 0'); - vrfy(nextcand(2^50,4,5,1,4)-2^50 == 145, - '2015: nextcand(2^50,4,5,1,4)-2^50 == 145'); - vrfy(nextcand(2^50,4,5,2,4) == 0, - '2016: nextcand(2^50,4,5,2,4) == 0'); - vrfy(nextcand(2^50,4,5,3,4)-2^50 == 55, - '2017: nextcand(2^50,4,5,3,4)-2^50 == 55'); - vrfy(nextcand(2^50,4,5,7,17)-2^50 == 853, - '2018: nextcand(2^50,4,5,7,17)-2^50 == 853'); - vrfy(ptest(2^100+277) == 1, '2019: ptest(2^100+277) == 1'); - vrfy(ptest(2^50-27,4,5) == 1, '2020: ptest(2^50-27,4,5) == 1'); - vrfy(ptest(2^50+55,4,5) == 1, '2021: ptest(2^50+55,4,5) == 1'); - vrfy(ptest(2^32+1,10) == 0, '2022: ptest(2^32+1,10) == 0'); - vrfy(lfactor(1001,100) == 7, '2023: lfactor(1001,100) == 7'); - vrfy(lfactor(1001,4) == 7, '2024: lfactor(1001,4) == 7'); - vrfy(lfactor(1001,3) == 1, '2025: lfactor(1001,3) == 1'); - vrfy(lfactor(127,10000) == 1, '2026: lfactor(127,10000) == 1'); - vrfy(lfactor(2^19-1,10000) == 1,'2027: lfactor(2^19-1,10000) == 1'); - vrfy(lfactor(2^31-1,10000) == 1,'2028: lfactor(2^31-1,10000) == 1'); - vrfy(lfactor(2^32-5,10000) == 1,'2029: lfactor(2^32-5,10000) == 1'); - vrfy(lfactor(2^38+7,50000) == 1,'2030: lfactor(2^38+7,50000) == 1'); - vrfy(lfactor(1009^2,pix(1009)) == 1009, - '2031: lfactor(1009^2,pix(1009)) == 1009'); - vrfy(lfactor(1009^2,pix(1009)-1) == 1, - '2032: lfactor(1009^2,pix(1009)-1) == 1'); - vrfy(lfactor(65519*65521,7000) == 65519, - '2033: lfactor(65519*65521,7000) == 65519'); - vrfy(lfactor(65521^2,pix(65521)) == 65521, - '2034: lfactor(65521^2,pix(65521)) == 65521'); - vrfy(lfactor(65521^2,pix(65521)-1) == 1, - '2035: lfactor(65521^2,pix(65521)-1) == 1'); - vrfy(lfactor(524309^6,100000) == 524309, - '2036: lfactor(524309^6,100000) == 524309'); + vrfy(isprime(-3) == 1, '1901: isprime(-3) == 1'); + vrfy(isprime(-1) == 0, '1902: isprime(-1) == 0'); + vrfy(isprime(0) == 0, '1903: isprime(0) == 0'); + vrfy(isprime(1) == 0, '1904: isprime(1) == 0'); + vrfy(isprime(2) == 1, '1905: isprime(2) == 1'); + vrfy(isprime(3) == 1, '1906: isprime(3) == 1'); + vrfy(isprime(4) == 0, '1907: isprime(4) == 0'); + vrfy(isprime(5) == 1, '1908: isprime(5) == 1'); + vrfy(isprime(17) == 1, '1909: isprime(17) == 1'); + vrfy(isprime(100) == 0, '1910: isprime(100) == 0'); + vrfy(isprime(21701,-1) == 1, '1911: isprime(21701,-1) == 1'); + vrfy(isprime(65521,-1) == 1, '1912: isprime(65521,-1) == 1'); + vrfy(isprime(65535,-1) == 0, '1913: isprime(65535,-1) == 0'); + vrfy(isprime(65536,-1) == 0, '1914: isprime(65536,-1) == 0'); + vrfy(isprime(1234577) == 1, '1915: isprime(1234577) == 1'); + vrfy(isprime(1234579) == 0, '1916: isprime(1234579) == 0'); + vrfy(isprime(2^31-9) == 0, '1917: isprime(2^31-9) == 0'); + vrfy(isprime(2^31-1) == 1, '1918: isprime(2^31-1) == 1'); + vrfy(isprime(2^31+9) == 0, '1919: isprime(2^31+11) == 0'); + vrfy(isprime(2^31+11) == 1, '1920: isprime(2^31+11) == 1'); + vrfy(isprime(3e9) == 0, '1921: isprime(3e9) == 0'); + vrfy(isprime(3e9+19) == 1, '1922: isprime(3e9+19) == 1'); + vrfy(isprime(2^32-7) == 0, '1923: isprime(2^32-7) == 0'); + vrfy(isprime(2^32-5) == 1, '1924: isprime(2^32-5) == 1'); + vrfy(isprime(2^32,-1) == 0, '1925: isprime(2^32,-1) == 0'); + vrfy(isprime(2^32+1,-1) == -1, '1926: isprime(2^32+1,-1) == -1'); + vrfy(isprime(3^99,2) == 2, '1927: isprime(3^99,2) == 2'); + vrfy(isprime(4^99,2) == 0, '1928: isprime(3^99,2) == 0'); + vrfy(nextprime(-3) == 5, '1929: nextprime(-3) == 5'); + vrfy(nextprime(0) == 2, '1930: nextprime(0) == 2'); + vrfy(nextprime(1) == 2, '1931: nextprime(1) == 2'); + vrfy(nextprime(2) == 3, '1932: nextprime(2) == 3'); + vrfy(nextprime(3) == 5, '1933: nextprime(3) == 5'); + vrfy(nextprime(4) == 5, '1934: nextprime(4) == 5'); + vrfy(nextprime(5) == 7, '1935: nextprime(5) == 7'); + vrfy(nextprime(17) == 19, '1936: nextprime(17) == 19'); + vrfy(nextprime(100) == 101, '1937: nextprime(100) == 101'); + vrfy(nextprime(21701,-1) == 21713, + '1938: nextprime(21701,-1) == 21713'); + vrfy(nextprime(65519) == 65521, + '1939: nextprime(65519) == 65521'); + vrfy(nextprime(65520) == 65521, + '1940: nextprime(65520) == 65521'); + vrfy(nextprime(65521,-1) == 65537, + '1941: nextprime(65521,-1) == 65537'); + vrfy(nextprime(65531) == 65537, + '1942: nextprime(65531) == 65537'); + vrfy(nextprime(65535,-1) == 65537, + '1943: nextprime(65535,-1) == 65537'); + vrfy(nextprime(65536) == 65537, + '1944: nextprime(65536) == 65537'); + vrfy(nextprime(1234576,2)==1234577, + '1945: nextprime(1234576,2)==1234577'); + vrfy(nextprime(2^31-9) == 2^31-1, + '1946: nextprime(2^31-9) == 2^31-1'); + vrfy(nextprime(2^31-1) == 2^31+11, + '1947: nextprime(2^31-1) == 2^31+11'); + vrfy(nextprime(3e9) == 3e9+19,'1948: nextprime(3e9) == 3e9+19'); + vrfy(nextprime(2^32-7) == 2^32-5, + '1949: nextprime(2^32-7) == 2^32-5'); + vrfy(nextprime(2^32,-1) == -1, '1950: nextprime(2^32,-1) == -1'); + vrfy(nextprime(2^32+5,-1) == -1,'1951: nextprime(2^32+5,-1) == -1'); + vrfy(nextprime(3^99,-1) == -1, '1952: nextprime(3^99,-1) == -1'); + vrfy(nextprime(3^99,2) == 2, '1953: nextprime(3^99,2) == 2'); + vrfy(prevprime(-3,-1) == 2, '1954: prevprime(-3,-1) == 2'); + vrfy(prevprime(0,-1) == 0, '1955: prevprime(0,-1) == 0'); + vrfy(prevprime(1,-1) == 0, '1956: prevprime(1,-1) == 0'); + vrfy(prevprime(2,-2) == 0, '1957: prevprime(2,-2) == 0'); + vrfy(prevprime(5) == 3, '1958: prevprime(5) == 3'); + vrfy(prevprime(4) == 3, '1959: prevprime(4) == 3'); + vrfy(prevprime(7) == 5, '1960: prevprime(7) == 5'); + vrfy(prevprime(19) == 17, '1961: prevprime(19) == 17'); + vrfy(prevprime(100) == 97, '1962: prevprime(100) == 97'); + vrfy(prevprime(21713,-1) == 21701, + '1963: prevprime(21713,-1) == 21701'); + vrfy(prevprime(65520) == 65519, + '1964: prevprime(65520) == 65519'); + vrfy(prevprime(65521) == 65519, + '1965: prevprime(65521) == 65519'); + vrfy(prevprime(65522) == 65521, + '1966: prevprime(65520) == 65521'); + vrfy(prevprime(65523) == 65521, + '1967: prevprime(65523) == 65521'); + vrfy(prevprime(65531) == 65521, + '1968: prevprime(65531) == 65521'); + vrfy(prevprime(65535) == 65521, + '1969: prevprime(65535) == 65521'); + vrfy(prevprime(65536) == 65521, + '1970: prevprime(65536) == 65521'); + vrfy(prevprime(65537) == 65521, + '1971: prevprime(65537) == 65521'); + vrfy(prevprime(65539) == 65537, + '1972: prevprime(65539) == 65537'); + vrfy(prevprime(1234578,2)==1234577, + '1973: prevprime(1234578,2)==1234577'); + vrfy(prevprime(2^31-1) == 2^31-19, + '1974: prevprime(2^31-1) == 2^31-19'); + vrfy(prevprime(2^31+11) == 2^31-1, + '1975: prevprime(2^31+11) == 2^31-1'); + vrfy(prevprime(3e9) == 3e9-71,'1976: prevprime(3e9) == 3e9-17'); + vrfy(prevprime(2^32-3) == 2^32-5, + '1977: prevprime(2^32-3) == 2^32-5'); + vrfy(prevprime(2^32-1) == 2^32-5, + '1978: prevprime(2^32-1) == 2^32-5'); + vrfy(prevprime(2^32,-1) == -1, '1979: prevprime(2^32,-1) == -1'); + vrfy(prevprime(3^99,-1) == -1, '1980: prevprime(3^99,-1) == -1'); + vrfy(prevprime(3^99,2) == 2, '1981: prevprime(3^99,2) == 2'); + vrfy(pix(-1) == 0, '1982: pix(-1) == 0'); + vrfy(pix(1) == 0, '1983: pix(1) == 0'); + vrfy(pix(2) == 1, '1984: pix(2) == 1'); + vrfy(pix(3) == 2, '1985: pix(3) == 2'); + vrfy(pix(100) == 25, '1986: pix(100) == 25'); + vrfy(pix(1000) == 168, '1987: pix(1000) == 168'); + vrfy(pix(10000) == 1229, '1988: pix(10000) == 1229'); + vrfy(pix(100000) == 9592, '1989: pix(100000) == 9592'); + vrfy(pix(2^19+59) == 43393, '1990: pix(2^19+59) == 43393'); + vrfy(pix(1000000) == 78498, '1991: pix(1000000) == 78498'); + vrfy(pix(10000000) == 664579, '1992: pix(10000000) == 664579'); + vrfy(pix(2^32-6) == 203280220, '1993: pix(2^32-6) == 203280220'); + vrfy(pix(2^32-5) == 203280221, '1994: pix(2^32-5) == 203280221'); + vrfy(pix(2^32-1) == 203280221, '1995: pix(2^32-1) == 203280221'); + vrfy(pfact(40) == 7420738134810,'1996: pfact(40) == 7420738134810'); + vrfy(pfact(200)/pfact(198)==199,'1997: pfact(200)/pfact(198)==199'); + vrfy(nextprime(3e9)==nextcand(3e9), + '1998: nextprime(3e9)==nextcand(3e9)'); + vrfy(prevprime(3e9)==prevcand(3e9), + '1999: prevprime(3e9)==prevcand(3e9)'); + vrfy(nextcand(2^100,0)-2^100 == 3, + '2000: nextcand(2^100,0)-2^100 == 3'); + vrfy(nextcand(2^100)-2^100 == 277, + '2001: nextcand(2^100)-2^100 == 277'); + vrfy(2^100-prevcand(2^100,0) == 5, + '2002: 2^100-prevcand(2^100,0) == 5'); + vrfy(2^100-prevcand(2^100) == 15, + '2003: 2^100-prevcand(2^100) == 15'); + vrfy(nextcand(2^50,4,5)-2^50 == 55, + '2004: nextcand(2^50,4,5)-2^50 == 55'); + vrfy(2^50-prevcand(2^50,4,5) == 27, + '2005: 2^50-prevcand(2^50,4,5) == 27'); + vrfy(nextprime(2^32-6) == 2^32-5, + '2006: nextprime(2^32-6) == 2^32-5'); + vrfy(nextprime(2^32-5) == 2^32+15, + '2007: nextprime(2^32-5) == 2^32+15'); + vrfy(prevprime(2^32-1) == 2^32-5, + '2008: prevprime(2^32-1) == 2^32-5'); + vrfy(prevcand(2^50,4,5,0,4) == 0, + '2009: prevcand(2^50,4,5,0,4) == 0'); + vrfy(2^50-prevcand(2^50,4,5,1,4) == 27, + '2010: 2^50-prevcand(2^50,4,5,1,4) == 27'); + vrfy(prevcand(2^50,4,5,2,4) == 2, + '2011: prevcand(2^50,4,5,2,4) == 2'); + vrfy(2^50-prevcand(2^50,4,5,3,4) == 113, + '2012: 2^50-prevcand(2^50,4,5,3,4) == 113'); + vrfy(2^50-prevcand(2^50,4,5,7,17) == 813, + '2013: 2^50-prevcand(2^50,4,5,7,17) == 813'); + vrfy(nextcand(2^50,4,5,0,4) == 0, + '2014: nextcand(2^50,4,5,0,4) == 0'); + vrfy(nextcand(2^50,4,5,1,4)-2^50 == 145, + '2015: nextcand(2^50,4,5,1,4)-2^50 == 145'); + vrfy(nextcand(2^50,4,5,2,4) == 0, + '2016: nextcand(2^50,4,5,2,4) == 0'); + vrfy(nextcand(2^50,4,5,3,4)-2^50 == 55, + '2017: nextcand(2^50,4,5,3,4)-2^50 == 55'); + vrfy(nextcand(2^50,4,5,7,17)-2^50 == 853, + '2018: nextcand(2^50,4,5,7,17)-2^50 == 853'); + vrfy(ptest(2^100+277) == 1, '2019: ptest(2^100+277) == 1'); + vrfy(ptest(2^50-27,4,5) == 1, '2020: ptest(2^50-27,4,5) == 1'); + vrfy(ptest(2^50+55,4,5) == 1, '2021: ptest(2^50+55,4,5) == 1'); + vrfy(ptest(2^32+1,10) == 0, '2022: ptest(2^32+1,10) == 0'); + vrfy(lfactor(1001,100) == 7, '2023: lfactor(1001,100) == 7'); + vrfy(lfactor(1001,4) == 7, '2024: lfactor(1001,4) == 7'); + vrfy(lfactor(1001,3) == 1, '2025: lfactor(1001,3) == 1'); + vrfy(lfactor(127,10000) == 1, '2026: lfactor(127,10000) == 1'); + vrfy(lfactor(2^19-1,10000) == 1,'2027: lfactor(2^19-1,10000) == 1'); + vrfy(lfactor(2^31-1,10000) == 1,'2028: lfactor(2^31-1,10000) == 1'); + vrfy(lfactor(2^32-5,10000) == 1,'2029: lfactor(2^32-5,10000) == 1'); + vrfy(lfactor(2^38+7,50000) == 1,'2030: lfactor(2^38+7,50000) == 1'); + vrfy(lfactor(1009^2,pix(1009)) == 1009, + '2031: lfactor(1009^2,pix(1009)) == 1009'); + vrfy(lfactor(1009^2,pix(1009)-1) == 1, + '2032: lfactor(1009^2,pix(1009)-1) == 1'); + vrfy(lfactor(65519*65521,7000) == 65519, + '2033: lfactor(65519*65521,7000) == 65519'); + vrfy(lfactor(65521^2,pix(65521)) == 65521, + '2034: lfactor(65521^2,pix(65521)) == 65521'); + vrfy(lfactor(65521^2,pix(65521)-1) == 1, + '2035: lfactor(65521^2,pix(65521)-1) == 1'); + vrfy(lfactor(524309^6,100000) == 524309, + '2036: lfactor(524309^6,100000) == 524309'); - print '2037: Ending prime builtins test'; + print '2037: Ending prime builtins test'; } print '029: parsed test_prime()'; @@ -2477,16 +2477,16 @@ print '029: parsed test_prime()'; * * This function performs the Lucas primality test suite. */ -read -once "lucas_chk"; /* obtain our needed Lucas resource file */ +read -once "lucas_chk"; /* obtain our needed Lucas resource file */ print '030: read lucas_chk'; /**/ define test_lucas() { - print '2100: Beginning lucas check test'; + print '2100: Beginning lucas check test'; - vrfy(lucas_chk(100,1) == 1, '2101: lucas_chk(100,1) == 1'); + vrfy(lucas_chk(100,1) == 1, '2101: lucas_chk(100,1) == 1'); - print '2102: Ending lucas check test'; + print '2102: Ending lucas check test'; } print '031: parsed test_lucas()'; @@ -2498,97 +2498,97 @@ print '031: parsed test_lucas()'; */ define test_newop() { - static mat A[3] = {1,2,3}; - static mat A2[3] = {1,2,3}; - local B; - local v; - local a; - local b; + static mat A[3] = {1,2,3}; + static mat A2[3] = {1,2,3}; + local B; + local v; + local a; + local b; - print '2200: Beginning operator functionality test'; + print '2200: Beginning operator functionality test'; - (v = 3) = 4; - print '2201: (v = 3) = 4'; - vrfy(v == 4, '2202: v == 4'); - (v += 3) *= 4; - print '2203: (v += 3) *= 4'; - vrfy(v == 28, '2204: v == 28'); - vrfy(A == A2, '2205: A == A2'); - matfill(B = A, 4); - print '2206: matfill(B = A, 4)'; - vrfy(A == A2, '2207: A == A2'); - vrfy(size(B) == 3, '2208: size(B) == 3'); - vrfy(B[0] == 4, '2209: B[0] == 4'); - vrfy(B[1] == 4, '2210: B[1] == 4'); - vrfy(B[2] == 4, '2211: B[2] == 4'); - a = 3; - print '2212: a = 3'; - ++(b = a); - print '2213: ++(b = a)'; - vrfy(a == 3, '2214: a == 3'); - vrfy(b == 4, '2215: b == 4'); - ++++a; - print '2216: ++++a'; - vrfy(a == 5, '2217: a == 5'); - vrfy((++a)++ == 6, '2218: (++a)++ == 6'); - vrfy(a == 7, '2219: a == 7'); - (++a) *= b; - print '2220: (++a) *= b'; - vrfy(a == 32, '2221: a == 32'); - vrfy(b == 4, '2222: b == 4'); - vrfy(++(a*=b) == 129, '2223: ++(a*=b) == 129'); - vrfy(a == 129, '2224: a == 129'); - vrfy(b == 4, '2225: b == 4'); - vrfy((a = (--a / b++))-- == 32, - '2226: (a = (--a / b++))-- == 32'); - vrfy(a == 31, '2227: a == 31'); - vrfy(b == 5, '2228: b == 5'); - vrfy((++++a / ----b) == 11, - '2229: (++++a / ----b) == 11'); - vrfy(a == 33, '2230: a == 33'); - vrfy(b == 3, '2231: b == 3'); - vrfy((a/=(--a/++b))-- == 4, - '2232: (a/=(--a/++b))-- == 4'); - vrfy(a == 3, '2233: a == 3'); - vrfy(b == 4, '2234: b == 4'); - v = a----; - print '2235: v = a----'; - vrfy(v == 3, '2236: v == 3'); - vrfy(a == 1, '2237: a == 1'); - a = ----v; - print '2238: a = ----v'; - vrfy(a == 1, '2239: a == 1'); - vrfy(v == 1, '2240: v == 1'); - v = a++++; - print '2241: v = a++++'; - vrfy(a == 3, '2242: a == 3'); - vrfy(v == 1, '2243: v == 1'); - a = ++++v; - print '2244: a = ++++v'; - vrfy(a == 3, '2245: a == 3'); - vrfy(v == 3, '2246: v == 3'); - a = ----v----; - print '2247: a = ----v----'; - vrfy(a == 1, '2248: a == 1'); - vrfy(v == -1, '2249: v == -1'); - v = ++++a++++; - print '2250: v = ++++a++++'; - vrfy(a == 5, '2251: a == 5'); - vrfy(v == 3, '2252: v == 3'); - a = ++++v----; - print '2253: a = ++++v----'; - vrfy(a == 5, '2254: a == 5'); - vrfy(v == 3, '2255: v == 3'); - v = --++a--++; - print '2256: v = --++a--++'; - vrfy(a == 5, '2257: a == 5'); - vrfy(v == 5, '2258: v == 5'); - a = -++v; - print '2259: a = -++v'; - vrfy(a == -6, '2260: a == -6'); - vrfy(v == 6, '2261: v == 6'); + (v = 3) = 4; + print '2201: (v = 3) = 4'; + vrfy(v == 4, '2202: v == 4'); + (v += 3) *= 4; + print '2203: (v += 3) *= 4'; + vrfy(v == 28, '2204: v == 28'); + vrfy(A == A2, '2205: A == A2'); + matfill(B = A, 4); + print '2206: matfill(B = A, 4)'; + vrfy(A == A2, '2207: A == A2'); + vrfy(size(B) == 3, '2208: size(B) == 3'); + vrfy(B[0] == 4, '2209: B[0] == 4'); + vrfy(B[1] == 4, '2210: B[1] == 4'); + vrfy(B[2] == 4, '2211: B[2] == 4'); + a = 3; + print '2212: a = 3'; + ++(b = a); + print '2213: ++(b = a)'; + vrfy(a == 3, '2214: a == 3'); + vrfy(b == 4, '2215: b == 4'); + ++++a; + print '2216: ++++a'; + vrfy(a == 5, '2217: a == 5'); + vrfy((++a)++ == 6, '2218: (++a)++ == 6'); + vrfy(a == 7, '2219: a == 7'); + (++a) *= b; + print '2220: (++a) *= b'; + vrfy(a == 32, '2221: a == 32'); + vrfy(b == 4, '2222: b == 4'); + vrfy(++(a*=b) == 129, '2223: ++(a*=b) == 129'); + vrfy(a == 129, '2224: a == 129'); + vrfy(b == 4, '2225: b == 4'); + vrfy((a = (--a / b++))-- == 32, + '2226: (a = (--a / b++))-- == 32'); + vrfy(a == 31, '2227: a == 31'); + vrfy(b == 5, '2228: b == 5'); + vrfy((++++a / ----b) == 11, + '2229: (++++a / ----b) == 11'); + vrfy(a == 33, '2230: a == 33'); + vrfy(b == 3, '2231: b == 3'); + vrfy((a/=(--a/++b))-- == 4, + '2232: (a/=(--a/++b))-- == 4'); + vrfy(a == 3, '2233: a == 3'); + vrfy(b == 4, '2234: b == 4'); + v = a----; + print '2235: v = a----'; + vrfy(v == 3, '2236: v == 3'); + vrfy(a == 1, '2237: a == 1'); + a = ----v; + print '2238: a = ----v'; + vrfy(a == 1, '2239: a == 1'); + vrfy(v == 1, '2240: v == 1'); + v = a++++; + print '2241: v = a++++'; + vrfy(a == 3, '2242: a == 3'); + vrfy(v == 1, '2243: v == 1'); + a = ++++v; + print '2244: a = ++++v'; + vrfy(a == 3, '2245: a == 3'); + vrfy(v == 3, '2246: v == 3'); + a = ----v----; + print '2247: a = ----v----'; + vrfy(a == 1, '2248: a == 1'); + vrfy(v == -1, '2249: v == -1'); + v = ++++a++++; + print '2250: v = ++++a++++'; + vrfy(a == 5, '2251: a == 5'); + vrfy(v == 3, '2252: v == 3'); + a = ++++v----; + print '2253: a = ++++v----'; + vrfy(a == 5, '2254: a == 5'); + vrfy(v == 3, '2255: v == 3'); + v = --++a--++; + print '2256: v = --++a--++'; + vrfy(a == 5, '2257: a == 5'); + vrfy(v == 5, '2258: v == 5'); + a = -++v; + print '2259: a = -++v'; + vrfy(a == -6, '2260: a == -6'); + vrfy(v == 6, '2261: v == 6'); - print '2262: Ending operator functionality test'; + print '2262: Ending operator functionality test'; } print '032: parsed test_newop()'; @@ -2603,55 +2603,55 @@ print '033: read -once test2300.obj_incdec'; /**/ define test_xx_incdec() { - local A, B; - local n; + local A, B; + local n; - print '2300: Beginning object increment/decrement test'; + print '2300: Beginning object increment/decrement test'; - A = mkmat(1,2,3); - print '2301: A = mkmat(1,2,3)'; - vrfy(ckmat(A,1,2,3) == 1, - '2302: ckmat(A,1,2,3) == 1'); - B = A++; - print '2303: B = A++'; - vrfy(ckmat(B,1,2,3) == 1, - '2304: ckmat(B,1,2,3) == 1'); - vrfy(ckmat(A,2,3,4) == 1, - '2305: ckmat(A,2,3,4) == 1'); - B = A--; - print '2306: B = A--'; - vrfy(ckmat(A,1,2,3) == 1, - '2307: ckmat(A,1,2,3) == 1'); - vrfy(ckmat(B,2,3,4) == 1, - '2308: ckmat(B,2,3,4) == 1'); - B = ++A; - print '2309: B = ++A'; - vrfy(ckmat(A,2,3,4) == 1, - '2310: ckmat(A,2,3,4) == 1'); - vrfy(ckmat(B,2,3,4) == 1, - '2311: ckmat(B,2,3,4) == 1'); - B = --A; - print '2312: B = --A'; - vrfy(ckmat(A,1,2,3) == 1, - '2313: ckmat(A,1,2,3) == 1'); - vrfy(ckmat(B,1,2,3) == 1, - '2314: ckmat(B,1,2,3) == 1'); + A = mkmat(1,2,3); + print '2301: A = mkmat(1,2,3)'; + vrfy(ckmat(A,1,2,3) == 1, + '2302: ckmat(A,1,2,3) == 1'); + B = A++; + print '2303: B = A++'; + vrfy(ckmat(B,1,2,3) == 1, + '2304: ckmat(B,1,2,3) == 1'); + vrfy(ckmat(A,2,3,4) == 1, + '2305: ckmat(A,2,3,4) == 1'); + B = A--; + print '2306: B = A--'; + vrfy(ckmat(A,1,2,3) == 1, + '2307: ckmat(A,1,2,3) == 1'); + vrfy(ckmat(B,2,3,4) == 1, + '2308: ckmat(B,2,3,4) == 1'); + B = ++A; + print '2309: B = ++A'; + vrfy(ckmat(A,2,3,4) == 1, + '2310: ckmat(A,2,3,4) == 1'); + vrfy(ckmat(B,2,3,4) == 1, + '2311: ckmat(B,2,3,4) == 1'); + B = --A; + print '2312: B = --A'; + vrfy(ckmat(A,1,2,3) == 1, + '2313: ckmat(A,1,2,3) == 1'); + vrfy(ckmat(B,1,2,3) == 1, + '2314: ckmat(B,1,2,3) == 1'); - n = 1; - print '2315: n = 1'; - vrfy(n + n + n + n++ == 4, - '2316: n + n + n + n++ == 4'); - vrfy(n == 2, '2317: n == 2'); - n = 1; - print '2318: n = 1'; - vrfy(n + n + n++ == 3, '2319: n + n + n++ == 3'); - vrfy(n == 2, '2320: n == 2'); - n = 1; - print '2321: n = 1'; - vrfy(n + n++ == 2, '2322: n + n++ == 3'); - vrfy(n == 2, '2323: n == 2'); + n = 1; + print '2315: n = 1'; + vrfy(n + n + n + n++ == 4, + '2316: n + n + n + n++ == 4'); + vrfy(n == 2, '2317: n == 2'); + n = 1; + print '2318: n = 1'; + vrfy(n + n + n++ == 3, '2319: n + n + n++ == 3'); + vrfy(n == 2, '2320: n == 2'); + n = 1; + print '2321: n = 1'; + vrfy(n + n++ == 2, '2322: n + n++ == 3'); + vrfy(n == 2, '2323: n == 2'); - print '2315: Ending object increment/decrement test'; + print '2315: Ending object increment/decrement test'; } print '034: parsed test_xx_incdec()'; @@ -2663,283 +2663,283 @@ print '034: parsed test_xx_incdec()'; */ define test_round() { - local mode; + local mode; - print '2400: Beginning config rounding mode test'; + print '2400: Beginning config rounding mode test'; - /* appr mode 0 */ - mode = 0; - print '2401: mode = 0'; - vrfy(appr(-5.44,0.1,mode) == -5.5, - '2402: appr(-5.44,0.1,mode) == -5.5'); - vrfy(appr(5.44,0.1,mode) == 5.4, - '2403: appr(5.44,0.1,mode) == 5.4'); - vrfy(appr(5.7,1,mode) == 5, - '2404: appr(5.7,1,mode) == 5'); - vrfy(appr(-5.7,1,mode) == -6, - '2405: appr(-5.7,1,mode) == -6'); - vrfy(appr(-5.44,-0.1,mode) == -5.4, - '2406: appr(-5.44,-0.1,mode) == -5.4'); - vrfy(appr(5.44,-0.1,mode) == 5.5, - '2407: appr(5.44,-0.1,mode) == 5.5'); - vrfy(appr(5.7,-1,mode) == 6, - '2408: appr(5.7,-1,mode) == 6'); - vrfy(appr(-5.7,-1,mode) == -5, - '2409: appr(-5.7,-1,mode) == -5'); + /* appr mode 0 */ + mode = 0; + print '2401: mode = 0'; + vrfy(appr(-5.44,0.1,mode) == -5.5, + '2402: appr(-5.44,0.1,mode) == -5.5'); + vrfy(appr(5.44,0.1,mode) == 5.4, + '2403: appr(5.44,0.1,mode) == 5.4'); + vrfy(appr(5.7,1,mode) == 5, + '2404: appr(5.7,1,mode) == 5'); + vrfy(appr(-5.7,1,mode) == -6, + '2405: appr(-5.7,1,mode) == -6'); + vrfy(appr(-5.44,-0.1,mode) == -5.4, + '2406: appr(-5.44,-0.1,mode) == -5.4'); + vrfy(appr(5.44,-0.1,mode) == 5.5, + '2407: appr(5.44,-0.1,mode) == 5.5'); + vrfy(appr(5.7,-1,mode) == 6, + '2408: appr(5.7,-1,mode) == 6'); + vrfy(appr(-5.7,-1,mode) == -5, + '2409: appr(-5.7,-1,mode) == -5'); - /* appr mode 1 */ - mode = 1; - print '2410: mode = 1'; - vrfy(appr(-5.44,0.1,mode) == -5.4, - '2411: appr(-5.44,0.1,mode) == -5.4'); - vrfy(appr(5.44,0.1,mode) == 5.5, - '2412: appr(5.44,0.1,mode) == 5.5'); - vrfy(appr(5.7,1,mode) == 6, - '2413: appr(5.7,1,mode) == 6'); - vrfy(appr(-5.7,1,mode) == -5, - '2414: appr(-5.7,1,mode) == -5'); - vrfy(appr(-5.44,-0.1,mode) == -5.5, - '2415: appr(-5.44,-0.1,mode) == -5.5'); - vrfy(appr(5.44,-0.1,mode) == 5.4, - '2416: appr(5.44,-0.1,mode) == 5.4'); - vrfy(appr(5.7,-1,mode) == 5, - '2417: appr(5.7,-1,mode) == 5'); - vrfy(appr(-5.7,-1,mode) == -6, - '2418: appr(-5.7,-1,mode) == -6'); + /* appr mode 1 */ + mode = 1; + print '2410: mode = 1'; + vrfy(appr(-5.44,0.1,mode) == -5.4, + '2411: appr(-5.44,0.1,mode) == -5.4'); + vrfy(appr(5.44,0.1,mode) == 5.5, + '2412: appr(5.44,0.1,mode) == 5.5'); + vrfy(appr(5.7,1,mode) == 6, + '2413: appr(5.7,1,mode) == 6'); + vrfy(appr(-5.7,1,mode) == -5, + '2414: appr(-5.7,1,mode) == -5'); + vrfy(appr(-5.44,-0.1,mode) == -5.5, + '2415: appr(-5.44,-0.1,mode) == -5.5'); + vrfy(appr(5.44,-0.1,mode) == 5.4, + '2416: appr(5.44,-0.1,mode) == 5.4'); + vrfy(appr(5.7,-1,mode) == 5, + '2417: appr(5.7,-1,mode) == 5'); + vrfy(appr(-5.7,-1,mode) == -6, + '2418: appr(-5.7,-1,mode) == -6'); - /* appr mode 2 */ - mode = 2; - print '2419: mode = 2'; - vrfy(appr(-5.44,0.1,mode) == -5.4, - '2420: appr(-5.44,0.1,mode) == -5.4'); - vrfy(appr(5.44,0.1,mode) == 5.4, - '2421: appr(5.44,0.1,mode) == 5.4'); - vrfy(appr(5.7,1,mode) == 5, - '2422: appr(5.7,1,mode) == 5'); - vrfy(appr(-5.7,1,mode) == -5, - '2423: appr(-5.7,1,mode) == -5'); + /* appr mode 2 */ + mode = 2; + print '2419: mode = 2'; + vrfy(appr(-5.44,0.1,mode) == -5.4, + '2420: appr(-5.44,0.1,mode) == -5.4'); + vrfy(appr(5.44,0.1,mode) == 5.4, + '2421: appr(5.44,0.1,mode) == 5.4'); + vrfy(appr(5.7,1,mode) == 5, + '2422: appr(5.7,1,mode) == 5'); + vrfy(appr(-5.7,1,mode) == -5, + '2423: appr(-5.7,1,mode) == -5'); - /* appr mode 3 */ - mode = 3; - print '2424: mode = 3'; - vrfy(appr(-5.44,0.1,mode) == -5.5, - '2425: appr(-5.44,0.1,mode) == -5.5'); - vrfy(appr(5.44,0.1,mode) == 5.5, - '2426: appr(5.44,0.1,mode) == 5.5'); - vrfy(appr(5.7,1,mode) == 6, - '2427: appr(5.7,1,mode) == 6'); - vrfy(appr(-5.7,1,mode) == -6, - '2428: appr(-5.7,1,mode) == -6'); + /* appr mode 3 */ + mode = 3; + print '2424: mode = 3'; + vrfy(appr(-5.44,0.1,mode) == -5.5, + '2425: appr(-5.44,0.1,mode) == -5.5'); + vrfy(appr(5.44,0.1,mode) == 5.5, + '2426: appr(5.44,0.1,mode) == 5.5'); + vrfy(appr(5.7,1,mode) == 6, + '2427: appr(5.7,1,mode) == 6'); + vrfy(appr(-5.7,1,mode) == -6, + '2428: appr(-5.7,1,mode) == -6'); - /* appr mode 4 */ - mode = 4; - print '2429: mode = 4'; - vrfy(appr(-5.44,0.1,mode) == -5.5, - '2430: appr(-5.44,0.1,mode) == -5.5'); - vrfy(appr(5.44,0.1,mode) == 5.4, - '2431: appr(5.44,0.1,mode) == 5.4'); - vrfy(appr(5.7,1,mode) == 5, - '2432: appr(5.7,1,mode) == 5'); - vrfy(appr(-5.7,1,mode) == -6, - '2433: appr(-5.7,1,mode) == -6'); + /* appr mode 4 */ + mode = 4; + print '2429: mode = 4'; + vrfy(appr(-5.44,0.1,mode) == -5.5, + '2430: appr(-5.44,0.1,mode) == -5.5'); + vrfy(appr(5.44,0.1,mode) == 5.4, + '2431: appr(5.44,0.1,mode) == 5.4'); + vrfy(appr(5.7,1,mode) == 5, + '2432: appr(5.7,1,mode) == 5'); + vrfy(appr(-5.7,1,mode) == -6, + '2433: appr(-5.7,1,mode) == -6'); - /* appr mode 5 */ - mode = 5; - print '2434: mode = 5'; - vrfy(appr(-5.44,0.1,mode) == -5.4, - '2435: appr(-5.44,0.1,mode) == -5.4'); - vrfy(appr(5.44,0.1,mode) == 5.5, - '2436: appr(5.44,0.1,mode) == 5.5'); - vrfy(appr(5.7,1,mode) == 6, - '2437: appr(5.7,1,mode) == 6'); - vrfy(appr(-5.7,1,mode) == -5, - '2438: appr(-5.7,1,mode) == -5'); + /* appr mode 5 */ + mode = 5; + print '2434: mode = 5'; + vrfy(appr(-5.44,0.1,mode) == -5.4, + '2435: appr(-5.44,0.1,mode) == -5.4'); + vrfy(appr(5.44,0.1,mode) == 5.5, + '2436: appr(5.44,0.1,mode) == 5.5'); + vrfy(appr(5.7,1,mode) == 6, + '2437: appr(5.7,1,mode) == 6'); + vrfy(appr(-5.7,1,mode) == -5, + '2438: appr(-5.7,1,mode) == -5'); - /* appr mode 6 */ - mode = 6; - print '2439: mode = 6'; - vrfy(appr(-5.44,0.1,mode) == -5.4, - '2440: appr(-5.44,0.1,mode) == -5.4'); - vrfy(appr(5.44,0.1,mode) == 5.4, - '2441: appr(5.44,0.1,mode) == 5.4'); - vrfy(appr(5.7,1,mode) == 5, - '2442: appr(5.7,1,mode) == 5'); - vrfy(appr(-5.7,1,mode) == -5, - '2443: appr(-5.7,1,mode) == -5'); - vrfy(appr(-5.44,-0.1,mode) == -5.5, - '2444: appr(-5.44,-0.1,mode) == -5.5'); - vrfy(appr(5.44,-0.1,mode) == 5.5, - '2445: appr(5.44,-0.1,mode) == 5.5'); - vrfy(appr(5.7,-1,mode) == 6, - '2446: appr(5.7,-1,mode) == 6'); - vrfy(appr(-5.7,-1,mode) == -6, - '2447: appr(-5.7,-1,mode) == -6'); + /* appr mode 6 */ + mode = 6; + print '2439: mode = 6'; + vrfy(appr(-5.44,0.1,mode) == -5.4, + '2440: appr(-5.44,0.1,mode) == -5.4'); + vrfy(appr(5.44,0.1,mode) == 5.4, + '2441: appr(5.44,0.1,mode) == 5.4'); + vrfy(appr(5.7,1,mode) == 5, + '2442: appr(5.7,1,mode) == 5'); + vrfy(appr(-5.7,1,mode) == -5, + '2443: appr(-5.7,1,mode) == -5'); + vrfy(appr(-5.44,-0.1,mode) == -5.5, + '2444: appr(-5.44,-0.1,mode) == -5.5'); + vrfy(appr(5.44,-0.1,mode) == 5.5, + '2445: appr(5.44,-0.1,mode) == 5.5'); + vrfy(appr(5.7,-1,mode) == 6, + '2446: appr(5.7,-1,mode) == 6'); + vrfy(appr(-5.7,-1,mode) == -6, + '2447: appr(-5.7,-1,mode) == -6'); - /* appr mode 7 */ - mode = 7; - print '2448: mode = 7'; - vrfy(appr(-5.44,0.1,mode) == -5.5, - '2449: appr(-5.44,0.1,mode) == -5.5'); - vrfy(appr(5.44,0.1,mode) == 5.5, - '2450: appr(5.44,0.1,mode) == 5.5'); - vrfy(appr(5.7,1,mode) == 6, - '2451: appr(5.7,1,mode) == 6'); - vrfy(appr(-5.7,1,mode) == -6, - '2452: appr(-5.7,1,mode) == -6'); - vrfy(appr(-5.44,-0.1,mode) == -5.4, - '2453: appr(-5.44,-0.1,mode) == -5.4'); - vrfy(appr(5.44,-0.1,mode) == 5.4, - '2454: appr(5.44,-0.1,mode) == 5.4'); - vrfy(appr(5.7,-1,mode) == 5, - '2455: appr(5.7,-1,mode) == 5'); - vrfy(appr(-5.7,-1,mode) == -5, - '2456: appr(-5.7,-1,mode) == -5'); + /* appr mode 7 */ + mode = 7; + print '2448: mode = 7'; + vrfy(appr(-5.44,0.1,mode) == -5.5, + '2449: appr(-5.44,0.1,mode) == -5.5'); + vrfy(appr(5.44,0.1,mode) == 5.5, + '2450: appr(5.44,0.1,mode) == 5.5'); + vrfy(appr(5.7,1,mode) == 6, + '2451: appr(5.7,1,mode) == 6'); + vrfy(appr(-5.7,1,mode) == -6, + '2452: appr(-5.7,1,mode) == -6'); + vrfy(appr(-5.44,-0.1,mode) == -5.4, + '2453: appr(-5.44,-0.1,mode) == -5.4'); + vrfy(appr(5.44,-0.1,mode) == 5.4, + '2454: appr(5.44,-0.1,mode) == 5.4'); + vrfy(appr(5.7,-1,mode) == 5, + '2455: appr(5.7,-1,mode) == 5'); + vrfy(appr(-5.7,-1,mode) == -5, + '2456: appr(-5.7,-1,mode) == -5'); - /* appr mode 8 */ - mode = 8; - print '2457: mode = 8'; - vrfy(appr(-5.44,0.1,mode) == -5.4, - '2458: appr(-5.44,0.1,mode) == -5.4'); - vrfy(appr(5.44,0.1,mode) == 5.4, - '2459: appr(5.44,0.1,mode) == 5.4'); - vrfy(appr(5.7,1,mode) == 6, - '2460: appr(5.7,1,mode) == 6'); - vrfy(appr(-5.7,1,mode) == -6, - '2461: appr(-5.7,1,mode) == -6'); + /* appr mode 8 */ + mode = 8; + print '2457: mode = 8'; + vrfy(appr(-5.44,0.1,mode) == -5.4, + '2458: appr(-5.44,0.1,mode) == -5.4'); + vrfy(appr(5.44,0.1,mode) == 5.4, + '2459: appr(5.44,0.1,mode) == 5.4'); + vrfy(appr(5.7,1,mode) == 6, + '2460: appr(5.7,1,mode) == 6'); + vrfy(appr(-5.7,1,mode) == -6, + '2461: appr(-5.7,1,mode) == -6'); - /* appr mode 9 */ - mode = 9; - print '2462: mode = 9'; - vrfy(appr(-5.44,0.1,mode) == -5.5, - '2463: appr(-5.44,0.1,mode) == -5.5'); - vrfy(appr(5.44,0.1,mode) == 5.5, - '2464: appr(5.44,0.1,mode) == 5.5'); - vrfy(appr(5.7,1,mode) == 5, - '2465: appr(5.7,1,mode) == 5'); - vrfy(appr(-5.7,1,mode) == -5, - '2466: appr(-5.7,1,mode) == -5'); + /* appr mode 9 */ + mode = 9; + print '2462: mode = 9'; + vrfy(appr(-5.44,0.1,mode) == -5.5, + '2463: appr(-5.44,0.1,mode) == -5.5'); + vrfy(appr(5.44,0.1,mode) == 5.5, + '2464: appr(5.44,0.1,mode) == 5.5'); + vrfy(appr(5.7,1,mode) == 5, + '2465: appr(5.7,1,mode) == 5'); + vrfy(appr(-5.7,1,mode) == -5, + '2466: appr(-5.7,1,mode) == -5'); - /* appr mode 10 */ - mode = 10; - print '2467: mode = 10'; - vrfy(appr(-5.44,0.1,mode) == -5.5, - '2468: appr(-5.44,0.1,mode) == -5.5'); - vrfy(appr(5.44,0.1,mode) == 5.4, - '2469: appr(5.44,0.1,mode) == 5.4'); - vrfy(appr(5.7,1,mode) == 6, - '2470: appr(5.7,1,mode) == 6'); - vrfy(appr(-5.7,1,mode) == -5, - '2471: appr(-5.7,1,mode) == -5'); - vrfy(appr(-5.44,-0.1,mode) == -5.4, - '2472: appr(-5.44,-0.1,mode) == -5.4'); - vrfy(appr(5.44,-0.1,mode) == 5.5, - '2473: appr(5.44,-0.1,mode) == 5.5'); - vrfy(appr(5.7,-1,mode) == 5, - '2474: appr(5.7,-1,mode) == 5'); - vrfy(appr(-5.7,-1,mode) == -6, - '2475: appr(-5.7,-1,mode) == -6'); + /* appr mode 10 */ + mode = 10; + print '2467: mode = 10'; + vrfy(appr(-5.44,0.1,mode) == -5.5, + '2468: appr(-5.44,0.1,mode) == -5.5'); + vrfy(appr(5.44,0.1,mode) == 5.4, + '2469: appr(5.44,0.1,mode) == 5.4'); + vrfy(appr(5.7,1,mode) == 6, + '2470: appr(5.7,1,mode) == 6'); + vrfy(appr(-5.7,1,mode) == -5, + '2471: appr(-5.7,1,mode) == -5'); + vrfy(appr(-5.44,-0.1,mode) == -5.4, + '2472: appr(-5.44,-0.1,mode) == -5.4'); + vrfy(appr(5.44,-0.1,mode) == 5.5, + '2473: appr(5.44,-0.1,mode) == 5.5'); + vrfy(appr(5.7,-1,mode) == 5, + '2474: appr(5.7,-1,mode) == 5'); + vrfy(appr(-5.7,-1,mode) == -6, + '2475: appr(-5.7,-1,mode) == -6'); - /* appr mode 11 */ - mode = 11; - print '2476: mode = 11'; - vrfy(appr(-5.44,0.1,mode) == -5.4, - '2477: appr(-5.44,0.1,mode) == -5.4'); - vrfy(appr(5.44,0.1,mode) == 5.5, - '2478: appr(5.44,0.1,mode) == 5.5'); - vrfy(appr(5.7,1,mode) == 5, - '2479: appr(5.7,1,mode) == 5'); - vrfy(appr(-5.7,1,mode) == -6, - '2480: appr(-5.7,1,mode) == -6'); - vrfy(appr(-5.44,-0.1,mode) == -5.5, - '2481: appr(-5.44,-0.1,mode) == -5.5'); - vrfy(appr(5.44,-0.1,mode) == 5.4, - '2482: appr(5.44,-0.1,mode) == 5.4'); - vrfy(appr(5.7,-1,mode) == 6, - '2483: appr(5.7,-1,mode) == 6'); - vrfy(appr(-5.7,-1,mode) == -5, - '2484: appr(-5.7,-1,mode) == -5'); + /* appr mode 11 */ + mode = 11; + print '2476: mode = 11'; + vrfy(appr(-5.44,0.1,mode) == -5.4, + '2477: appr(-5.44,0.1,mode) == -5.4'); + vrfy(appr(5.44,0.1,mode) == 5.5, + '2478: appr(5.44,0.1,mode) == 5.5'); + vrfy(appr(5.7,1,mode) == 5, + '2479: appr(5.7,1,mode) == 5'); + vrfy(appr(-5.7,1,mode) == -6, + '2480: appr(-5.7,1,mode) == -6'); + vrfy(appr(-5.44,-0.1,mode) == -5.5, + '2481: appr(-5.44,-0.1,mode) == -5.5'); + vrfy(appr(5.44,-0.1,mode) == 5.4, + '2482: appr(5.44,-0.1,mode) == 5.4'); + vrfy(appr(5.7,-1,mode) == 6, + '2483: appr(5.7,-1,mode) == 6'); + vrfy(appr(-5.7,-1,mode) == -5, + '2484: appr(-5.7,-1,mode) == -5'); - /* appr mode 12 */ - mode = 12; - print '2485: mode = 12'; - vrfy(appr(-5.44,0.1,mode) == -5.4, - '2486: appr(-5.44,0.1,mode) == -5.4'); - vrfy(appr(5.44,0.1,mode) == 5.4, - '2487: appr(5.44,0.1,mode) == 5.4'); - vrfy(appr(5.7,1,mode) == 6, - '2488: appr(5.7,1,mode) == 6'); - vrfy(appr(-5.7,1,mode) == -6, - '2489: appr(-5.7,1,mode) == -6'); - vrfy(appr(-5.44,-0.1,mode) == -5.5, - '2490: appr(-5.44,-0.1,mode) == -5.5'); - vrfy(appr(5.44,-0.1,mode) == 5.5, - '2491: appr(5.44,-0.1,mode) == 5.5'); - vrfy(appr(5.7,-1,mode) == 5, - '2492: appr(5.7,-1,mode) == 5'); - vrfy(appr(-5.7,-1,mode) == -5, - '2493: appr(-5.7,-1,mode) == -5'); + /* appr mode 12 */ + mode = 12; + print '2485: mode = 12'; + vrfy(appr(-5.44,0.1,mode) == -5.4, + '2486: appr(-5.44,0.1,mode) == -5.4'); + vrfy(appr(5.44,0.1,mode) == 5.4, + '2487: appr(5.44,0.1,mode) == 5.4'); + vrfy(appr(5.7,1,mode) == 6, + '2488: appr(5.7,1,mode) == 6'); + vrfy(appr(-5.7,1,mode) == -6, + '2489: appr(-5.7,1,mode) == -6'); + vrfy(appr(-5.44,-0.1,mode) == -5.5, + '2490: appr(-5.44,-0.1,mode) == -5.5'); + vrfy(appr(5.44,-0.1,mode) == 5.5, + '2491: appr(5.44,-0.1,mode) == 5.5'); + vrfy(appr(5.7,-1,mode) == 5, + '2492: appr(5.7,-1,mode) == 5'); + vrfy(appr(-5.7,-1,mode) == -5, + '2493: appr(-5.7,-1,mode) == -5'); - /* appr mode 13 */ - mode = 13; - print '2494: mode = 13'; - vrfy(appr(-5.44,0.1,mode) == -5.5, - '2495: appr(-5.44,0.1,mode) == -5.5'); - vrfy(appr(5.44,0.1,mode) == 5.5, - '2496: appr(5.44,0.1,mode) == 5.5'); - vrfy(appr(5.7,1,mode) == 5, - '2497: appr(5.7,1,mode) == 5'); - vrfy(appr(-5.7,1,mode) == -5, - '2498: appr(-5.7,1,mode) == -5'); - vrfy(appr(-5.44,-0.1,mode) == -5.4, - '2499: appr(-5.44,-0.1,mode) == -5.4'); - vrfy(appr(5.44,-0.1,mode) == 5.4, - '2500: appr(5.44,-0.1,mode) == 5.4'); - vrfy(appr(5.7,-1,mode) == 6, - '2501: appr(5.7,-1,mode) == 6'); - vrfy(appr(-5.7,-1,mode) == -6, - '2502: appr(-5.7,-1,mode) == -6'); + /* appr mode 13 */ + mode = 13; + print '2494: mode = 13'; + vrfy(appr(-5.44,0.1,mode) == -5.5, + '2495: appr(-5.44,0.1,mode) == -5.5'); + vrfy(appr(5.44,0.1,mode) == 5.5, + '2496: appr(5.44,0.1,mode) == 5.5'); + vrfy(appr(5.7,1,mode) == 5, + '2497: appr(5.7,1,mode) == 5'); + vrfy(appr(-5.7,1,mode) == -5, + '2498: appr(-5.7,1,mode) == -5'); + vrfy(appr(-5.44,-0.1,mode) == -5.4, + '2499: appr(-5.44,-0.1,mode) == -5.4'); + vrfy(appr(5.44,-0.1,mode) == 5.4, + '2500: appr(5.44,-0.1,mode) == 5.4'); + vrfy(appr(5.7,-1,mode) == 6, + '2501: appr(5.7,-1,mode) == 6'); + vrfy(appr(-5.7,-1,mode) == -6, + '2502: appr(-5.7,-1,mode) == -6'); - /* appr mode 14 */ - mode = 14; - print '2503: mode = 14'; - vrfy(appr(-5.44,0.1,mode) == -5.5, - '2504: appr(-5.44,0.1,mode) == -5.5'); - vrfy(appr(5.44,0.1,mode) == 5.4, - '2505: appr(5.44,0.1,mode) == 5.4'); - vrfy(appr(5.7,1,mode) == 6, - '2506: appr(5.7,1,mode) == 6'); - vrfy(appr(-5.7,1,mode) == -5, - '2507: appr(-5.7,1,mode) == -5'); - vrfy(appr(-5.44,-0.1,mode) == -5.5, - '2508: appr(-5.44,-0.1,mode) == -5.5'); - vrfy(appr(5.44,-0.1,mode) == 5.4, - '2509: appr(5.44,-0.1,mode) == 5.4'); - vrfy(appr(5.7,-1,mode) == 6, - '2510: appr(5.7,-1,mode) == 6'); - vrfy(appr(-5.7,-1,mode) == -5, - '2511: appr(-5.7,-1,mode) == -5'); + /* appr mode 14 */ + mode = 14; + print '2503: mode = 14'; + vrfy(appr(-5.44,0.1,mode) == -5.5, + '2504: appr(-5.44,0.1,mode) == -5.5'); + vrfy(appr(5.44,0.1,mode) == 5.4, + '2505: appr(5.44,0.1,mode) == 5.4'); + vrfy(appr(5.7,1,mode) == 6, + '2506: appr(5.7,1,mode) == 6'); + vrfy(appr(-5.7,1,mode) == -5, + '2507: appr(-5.7,1,mode) == -5'); + vrfy(appr(-5.44,-0.1,mode) == -5.5, + '2508: appr(-5.44,-0.1,mode) == -5.5'); + vrfy(appr(5.44,-0.1,mode) == 5.4, + '2509: appr(5.44,-0.1,mode) == 5.4'); + vrfy(appr(5.7,-1,mode) == 6, + '2510: appr(5.7,-1,mode) == 6'); + vrfy(appr(-5.7,-1,mode) == -5, + '2511: appr(-5.7,-1,mode) == -5'); - /* appr mode 15 */ - mode = 15; - print '2512: mode = 15'; - vrfy(appr(-5.44,0.1,mode) == -5.4, - '2513: appr(-5.44,0.1,mode) == -5.4'); - vrfy(appr(5.44,0.1,mode) == 5.5, - '2514: appr(5.44,0.1,mode) == 5.5'); - vrfy(appr(5.7,1,mode) == 5, - '2515: appr(5.7,1,mode) == 5'); - vrfy(appr(-5.7,1,mode) == -6, - '2516: appr(-5.7,1,mode) == -6'); - vrfy(appr(-5.44,-0.1,mode) == -5.4, - '2517: appr(-5.44,-0.1,mode) == -5.4'); - vrfy(appr(5.44,-0.1,mode) == 5.5, - '2518: appr(5.44,-0.1,mode) == 5.5'); - vrfy(appr(5.7,-1,mode) == 5, - '2519: appr(5.7,-1,mode) == 5'); - vrfy(appr(-5.7,-1,mode) == -6, - '2520: appr(-5.7,-1,mode) == -6'); + /* appr mode 15 */ + mode = 15; + print '2512: mode = 15'; + vrfy(appr(-5.44,0.1,mode) == -5.4, + '2513: appr(-5.44,0.1,mode) == -5.4'); + vrfy(appr(5.44,0.1,mode) == 5.5, + '2514: appr(5.44,0.1,mode) == 5.5'); + vrfy(appr(5.7,1,mode) == 5, + '2515: appr(5.7,1,mode) == 5'); + vrfy(appr(-5.7,1,mode) == -6, + '2516: appr(-5.7,1,mode) == -6'); + vrfy(appr(-5.44,-0.1,mode) == -5.4, + '2517: appr(-5.44,-0.1,mode) == -5.4'); + vrfy(appr(5.44,-0.1,mode) == 5.5, + '2518: appr(5.44,-0.1,mode) == 5.5'); + vrfy(appr(5.7,-1,mode) == 5, + '2519: appr(5.7,-1,mode) == 5'); + vrfy(appr(-5.7,-1,mode) == -6, + '2520: appr(-5.7,-1,mode) == -6'); - print '2521: Ending config rounding mode test'; + print '2521: Ending config rounding mode test'; } print '035: parsed test_round()'; @@ -2956,181 +2956,181 @@ read -once "test2600.numfunc"; print '036: read -once test2600.numfunc'; define test_2600() { - local tnum; /* test number */ - local i; + local tnum; /* test number */ + local i; - /* - * NOTE: The various functions test in this are often accurate to - * eps (epsilon) or better, which defaults to about 20 decimal - * digits. We test a number of functions to 10 digits using - * round(..., 10) because we do not want to have to put lots - * of digits in the verify identities. - */ + /* + * NOTE: The various functions test in this are often accurate to + * eps (epsilon) or better, which defaults to about 20 decimal + * digits. We test a number of functions to 10 digits using + * round(..., 10) because we do not want to have to put lots + * of digits in the verify identities. + */ - print '2600: Beginning extensive numeric function test'; + print '2600: Beginning extensive numeric function test'; - i = config("sqrt"); - print '2601: i = config("sqrt")'; + i = config("sqrt"); + print '2601: i = config("sqrt")'; - tnum = test2600(1, 2602); + tnum = test2600(1, 2602); - i = config("sqrt", i); - print tnum++: ': i = config("sqrt", i)'; + i = config("sqrt", i); + print tnum++: ': i = config("sqrt", i)'; - i = epsilon(1e-100),; - print tnum++: ': i = epsilon(1e-100),;'; - vrfy(ln(exp(6)) == 6, - strcat(str(tnum++), ': ln(exp(6)) == 6')); - vrfy(ln(exp(4)^4) == 16, - strcat(str(tnum++), ': ln(exp(4)^4) == 16')); - vrfy(ln(exp(6.5)^8) == 52, - strcat(str(tnum++), ': ln(exp(6.5)^8) == 52')); - vrfy(ln(exp(5)^16) == 80, - strcat(str(tnum++), ': ln(exp(5)^16) == 80')); - vrfy(ln(exp(4.5)^4) == 18, - strcat(str(tnum++), ': ln(exp(4.5)^4) == 18')); - vrfy(ln(exp(4)^8) == 32, - strcat(str(tnum++), ': ln(exp(4)^8) == 32')); - vrfy(ln(exp(60/11)^11) == 60, - strcat(str(tnum++), ': ln(exp(60/11)^11) == 60')); - vrfy(ln(exp(6)^15) == 90, - strcat(str(tnum++), ': ln(exp(6)^11) == 90')); - vrfy(ln(exp(80/17)^17) == 80, - strcat(str(tnum++), ': ln(exp(80/17)^17) == 80')); - vrfy(ln(exp(6)^15) == 90, - strcat(str(tnum++), ': ln(exp(6)^15) == 90')); - vrfy(ln(exp(5)^18) == 90, - strcat(str(tnum++), ': ln(exp(5)^18) == 90')); - vrfy(log(1e6) == 6, - strcat(str(tnum++), ': log(1e6)) == 6')); - vrfy(log(1) == 0, - strcat(str(tnum++), ': log(1)) == 0')); - vrfy(log(100) == 2, - strcat(str(tnum++), ': log(100)) == 2')); - vrfy(log(1e66) == 66, - strcat(str(tnum++), ': log(1e66)) == 66')); - vrfy(log(1e127) == 127, - strcat(str(tnum++), ': log(1e127)) == 127')); - vrfy(round(log(17^47),10) == 57.8310993048, - strcat(str(tnum++), - ': round(log(17^47),10) == 57.8310993048')); - vrfy(round(log(127),10) == 2.103803721, - strcat(str(tnum++), - ': round(log(127),10) == 2.103803721')); - vrfy(round(log(0.25,0.00001),5) == -0.60206, - strcat(str(tnum++), - ': round(log(0.25,0.00001),5) == -0.60206')); - vrfy(round(log(0.25,1e-10),10) == -0.6020599913, - strcat(str(tnum++), - ': round(log(0.25,1e-10),10) == -0.6020599913')); - vrfy(round( log(1.2+1.2i,1e-5),5) == 0.2297+0.34109i, - strcat(str(tnum++), - ': round(log(1.2+1.2i,1e-5),5) == 0.2297+0.34109i')); - vrfy(round( log(1.2+1.2i,1e-10),10) == 0.2296962439+0.3410940885i, - strcat(str(tnum++), - ': round(log(1.2+1.2i,1e-10),10) == ', - '0.2296962439+0.3410940885i')); - vrfy(log2(0.5) == -1, - strcat(str(tnum++), ': log2(0.5) == -1')); - vrfy(log2(0.5) == -1, - strcat(str(tnum++), ': log2(0.5) == -1')); - vrfy(log2(0.5) == log2(0.5), - strcat(str(tnum++), ': log2(0.5) == log2(0.5)')); - vrfy(0^0 == 1, - strcat(str(tnum++), ': 0^0 == 1')); - vrfy(1^0 == 1, - strcat(str(tnum++), ': 1^0 == 1')); - vrfy(1^1 == 1, - strcat(str(tnum++), ': 1^1 == 1')); - vrfy(2^0 == 1, - strcat(str(tnum++), ': 2^0 == 1')); - vrfy(log2(1) == 0, - strcat(str(tnum++), ': log2(1) == 0')); - vrfy(log2(1.0) == 0, - strcat(str(tnum++), ': log2(1.0) == 0')); - vrfy(log2(2) == 1, - strcat(str(tnum++), ': log2(2) == 1')); - vrfy(log2(4) == 2, - strcat(str(tnum++), ': log2(4) == 2')); - vrfy(log2(1024) == 10, - strcat(str(tnum++), ': log2(1024) == 10')); - vrfy(log2(2^500) == 500, - strcat(str(tnum++), ': log2(2^500) == 500')); - vrfy(log2(1/2^23209) == -23209, - strcat(str(tnum++), ': log2(1/2^23209) == -23209')); - vrfy(round(log2(127),10) == 6.9886846868, - strcat(str(tnum++), - ': round(log2(127),10) == 6.9886846868')); - vrfy(round(log2(23209),10) == 14.5023967426, - strcat(str(tnum++), - ': round(log2(23209),10) == 14.5023967426')); - vrfy(round(log2(2^17-19),10) == 16.9997908539, - strcat(str(tnum++), - ': round(log2(2^17-19),10) == 16.9997908539')); - vrfy(round(log2(-127),10) == 6.9886846868+4.5323601418i, - strcat(str(tnum++), - ': round(log2(-127),10) == 6.9886846868+4.5323601418i')); - vrfy(round(log2(2+3i),10) == 1.8502198591+1.4178716307i, - strcat(str(tnum++), - ': round(log2(2+3i),10) == 1.8502198591+1.4178716307i')); - vrfy(round(log2(-2+3i),10) == 1.8502198591+3.1144885111i, - strcat(str(tnum++), - ': round(log2(-2+3i),10) == 1.8502198591+3.1144885111i')); - vrfy(round(log2(2-3i),10) == 1.8502198591-1.4178716307i, - strcat(str(tnum++), - ': round(log2(2-3i),10) == 1.8502198591-1.4178716307i')); - vrfy(round(log2(-2-3i),10) == 1.8502198591-3.1144885111i, - strcat(str(tnum++), - ': round(log2(-2-3i),10) == 1.8502198591-3.1144885111i')); - vrfy(round(log2(17+0.3i),10) == 4.0876874474+0.0254566819i, - strcat(str(tnum++), - ': round(log2(17+0.3i),10) == 4.0876874474+0.0254566819i')); - vrfy(logn(2, 2) == 1, - strcat(str(tnum++), ': logn(2, 2) == 1')); - vrfy(logn(4, 2) == 2, - strcat(str(tnum++), ': logn(4, 2) == 2')); - vrfy(logn(1024, 2) == 10, - strcat(str(tnum++), ': logn(1024, 2) == 10')); - vrfy(logn(2^500, 2) == 500, - strcat(str(tnum++), ': logn(2^500, 2) == 500')); - vrfy(logn(1/2^23209, 2) == -23209, - strcat(str(tnum++), ': logn(1/2^23209, 2) == -23209')); - vrfy(round(logn(127, 1/13),10) == -1.8886092516, - strcat(str(tnum++), - ': round(logn(127, 1/13),10) == -1.8886092516')); - vrfy(round(logn(23209, sqrt(3)),10) == 18.299987206, - strcat(str(tnum++), - ': round(logn(23209, sqrt(3)),10) == 18.299987206')); - vrfy(round(logn(2, 42),10) == 0.1854490234, - strcat(str(tnum++), - ': round(logn(2, 42),10) == 0.1854490234')); - vrfy(round(logn(1024, 42),10) == 1.8544902342, - strcat(str(tnum++), - ': round(logn(1024, 42),10) == 1.8544902342')); - vrfy(round(logn(2^500, 42),10) == 92.7245117077, - strcat(str(tnum++), - ': round(logn(2^500, 42),10) == 92.7245117077')); - vrfy(round(logn(1/2^23209, 42),10) == -4304.0863844473, - strcat(str(tnum++), - ': round(logn(1/2^23209, 42),10) == -4304.0863844473')); - vrfy(logn(-1, 1i) == 2, - strcat(str(tnum++), ': logn(-1, 1i) == 2')); - vrfy(round(logn(22+3i, 3i),10) == 0.984899142-1.2848465788i, - strcat(str(tnum++), - ': round(logn(22+3i, 3i),10) == 0.984899142-1.2848465788i')); - vrfy(round(logn(22.2+3.3i, -4-3.3i),10) == 0.5456929478+0.9025545623i, - strcat(str(tnum++), - ': round(logn(22.2+3.3i, -4-3.3i),10) == 0.5456929478+0.9025545623i')); - vrfy(round(logn(-127, 7),10) == 2.4894197139+1.6144592571i, - strcat(str(tnum++), - ': round(logn(-127, 7),10) == 2.4894197139+1.6144592571i')); - vrfy(round(logn(-127, 7i),10) == 2.2963271277-0.2392040372i, - strcat(str(tnum++), - ': round(logn(-127, 7i),10) == 2.2963271277-0.2392040372i')); + i = epsilon(1e-100),; + print tnum++: ': i = epsilon(1e-100),;'; + vrfy(ln(exp(6)) == 6, + strcat(str(tnum++), ': ln(exp(6)) == 6')); + vrfy(ln(exp(4)^4) == 16, + strcat(str(tnum++), ': ln(exp(4)^4) == 16')); + vrfy(ln(exp(6.5)^8) == 52, + strcat(str(tnum++), ': ln(exp(6.5)^8) == 52')); + vrfy(ln(exp(5)^16) == 80, + strcat(str(tnum++), ': ln(exp(5)^16) == 80')); + vrfy(ln(exp(4.5)^4) == 18, + strcat(str(tnum++), ': ln(exp(4.5)^4) == 18')); + vrfy(ln(exp(4)^8) == 32, + strcat(str(tnum++), ': ln(exp(4)^8) == 32')); + vrfy(ln(exp(60/11)^11) == 60, + strcat(str(tnum++), ': ln(exp(60/11)^11) == 60')); + vrfy(ln(exp(6)^15) == 90, + strcat(str(tnum++), ': ln(exp(6)^11) == 90')); + vrfy(ln(exp(80/17)^17) == 80, + strcat(str(tnum++), ': ln(exp(80/17)^17) == 80')); + vrfy(ln(exp(6)^15) == 90, + strcat(str(tnum++), ': ln(exp(6)^15) == 90')); + vrfy(ln(exp(5)^18) == 90, + strcat(str(tnum++), ': ln(exp(5)^18) == 90')); + vrfy(log(1e6) == 6, + strcat(str(tnum++), ': log(1e6)) == 6')); + vrfy(log(1) == 0, + strcat(str(tnum++), ': log(1)) == 0')); + vrfy(log(100) == 2, + strcat(str(tnum++), ': log(100)) == 2')); + vrfy(log(1e66) == 66, + strcat(str(tnum++), ': log(1e66)) == 66')); + vrfy(log(1e127) == 127, + strcat(str(tnum++), ': log(1e127)) == 127')); + vrfy(round(log(17^47),10) == 57.8310993048, + strcat(str(tnum++), + ': round(log(17^47),10) == 57.8310993048')); + vrfy(round(log(127),10) == 2.103803721, + strcat(str(tnum++), + ': round(log(127),10) == 2.103803721')); + vrfy(round(log(0.25,0.00001),5) == -0.60206, + strcat(str(tnum++), + ': round(log(0.25,0.00001),5) == -0.60206')); + vrfy(round(log(0.25,1e-10),10) == -0.6020599913, + strcat(str(tnum++), + ': round(log(0.25,1e-10),10) == -0.6020599913')); + vrfy(round( log(1.2+1.2i,1e-5),5) == 0.2297+0.34109i, + strcat(str(tnum++), + ': round(log(1.2+1.2i,1e-5),5) == 0.2297+0.34109i')); + vrfy(round( log(1.2+1.2i,1e-10),10) == 0.2296962439+0.3410940885i, + strcat(str(tnum++), + ': round(log(1.2+1.2i,1e-10),10) == ', + '0.2296962439+0.3410940885i')); + vrfy(log2(0.5) == -1, + strcat(str(tnum++), ': log2(0.5) == -1')); + vrfy(log2(0.5) == -1, + strcat(str(tnum++), ': log2(0.5) == -1')); + vrfy(log2(0.5) == log2(0.5), + strcat(str(tnum++), ': log2(0.5) == log2(0.5)')); + vrfy(0^0 == 1, + strcat(str(tnum++), ': 0^0 == 1')); + vrfy(1^0 == 1, + strcat(str(tnum++), ': 1^0 == 1')); + vrfy(1^1 == 1, + strcat(str(tnum++), ': 1^1 == 1')); + vrfy(2^0 == 1, + strcat(str(tnum++), ': 2^0 == 1')); + vrfy(log2(1) == 0, + strcat(str(tnum++), ': log2(1) == 0')); + vrfy(log2(1.0) == 0, + strcat(str(tnum++), ': log2(1.0) == 0')); + vrfy(log2(2) == 1, + strcat(str(tnum++), ': log2(2) == 1')); + vrfy(log2(4) == 2, + strcat(str(tnum++), ': log2(4) == 2')); + vrfy(log2(1024) == 10, + strcat(str(tnum++), ': log2(1024) == 10')); + vrfy(log2(2^500) == 500, + strcat(str(tnum++), ': log2(2^500) == 500')); + vrfy(log2(1/2^23209) == -23209, + strcat(str(tnum++), ': log2(1/2^23209) == -23209')); + vrfy(round(log2(127),10) == 6.9886846868, + strcat(str(tnum++), + ': round(log2(127),10) == 6.9886846868')); + vrfy(round(log2(23209),10) == 14.5023967426, + strcat(str(tnum++), + ': round(log2(23209),10) == 14.5023967426')); + vrfy(round(log2(2^17-19),10) == 16.9997908539, + strcat(str(tnum++), + ': round(log2(2^17-19),10) == 16.9997908539')); + vrfy(round(log2(-127),10) == 6.9886846868+4.5323601418i, + strcat(str(tnum++), + ': round(log2(-127),10) == 6.9886846868+4.5323601418i')); + vrfy(round(log2(2+3i),10) == 1.8502198591+1.4178716307i, + strcat(str(tnum++), + ': round(log2(2+3i),10) == 1.8502198591+1.4178716307i')); + vrfy(round(log2(-2+3i),10) == 1.8502198591+3.1144885111i, + strcat(str(tnum++), + ': round(log2(-2+3i),10) == 1.8502198591+3.1144885111i')); + vrfy(round(log2(2-3i),10) == 1.8502198591-1.4178716307i, + strcat(str(tnum++), + ': round(log2(2-3i),10) == 1.8502198591-1.4178716307i')); + vrfy(round(log2(-2-3i),10) == 1.8502198591-3.1144885111i, + strcat(str(tnum++), + ': round(log2(-2-3i),10) == 1.8502198591-3.1144885111i')); + vrfy(round(log2(17+0.3i),10) == 4.0876874474+0.0254566819i, + strcat(str(tnum++), + ': round(log2(17+0.3i),10) == 4.0876874474+0.0254566819i')); + vrfy(logn(2, 2) == 1, + strcat(str(tnum++), ': logn(2, 2) == 1')); + vrfy(logn(4, 2) == 2, + strcat(str(tnum++), ': logn(4, 2) == 2')); + vrfy(logn(1024, 2) == 10, + strcat(str(tnum++), ': logn(1024, 2) == 10')); + vrfy(logn(2^500, 2) == 500, + strcat(str(tnum++), ': logn(2^500, 2) == 500')); + vrfy(logn(1/2^23209, 2) == -23209, + strcat(str(tnum++), ': logn(1/2^23209, 2) == -23209')); + vrfy(round(logn(127, 1/13),10) == -1.8886092516, + strcat(str(tnum++), + ': round(logn(127, 1/13),10) == -1.8886092516')); + vrfy(round(logn(23209, sqrt(3)),10) == 18.299987206, + strcat(str(tnum++), + ': round(logn(23209, sqrt(3)),10) == 18.299987206')); + vrfy(round(logn(2, 42),10) == 0.1854490234, + strcat(str(tnum++), + ': round(logn(2, 42),10) == 0.1854490234')); + vrfy(round(logn(1024, 42),10) == 1.8544902342, + strcat(str(tnum++), + ': round(logn(1024, 42),10) == 1.8544902342')); + vrfy(round(logn(2^500, 42),10) == 92.7245117077, + strcat(str(tnum++), + ': round(logn(2^500, 42),10) == 92.7245117077')); + vrfy(round(logn(1/2^23209, 42),10) == -4304.0863844473, + strcat(str(tnum++), + ': round(logn(1/2^23209, 42),10) == -4304.0863844473')); + vrfy(logn(-1, 1i) == 2, + strcat(str(tnum++), ': logn(-1, 1i) == 2')); + vrfy(round(logn(22+3i, 3i),10) == 0.984899142-1.2848465788i, + strcat(str(tnum++), + ': round(logn(22+3i, 3i),10) == 0.984899142-1.2848465788i')); + vrfy(round(logn(22.2+3.3i, -4-3.3i),10) == 0.5456929478+0.9025545623i, + strcat(str(tnum++), + ': round(logn(22.2+3.3i, -4-3.3i),10) == 0.5456929478+0.9025545623i')); + vrfy(round(logn(-127, 7),10) == 2.4894197139+1.6144592571i, + strcat(str(tnum++), + ': round(logn(-127, 7),10) == 2.4894197139+1.6144592571i')); + vrfy(round(logn(-127, 7i),10) == 2.2963271277-0.2392040372i, + strcat(str(tnum++), + ': round(logn(-127, 7i),10) == 2.2963271277-0.2392040372i')); epsilon(i),; - print tnum++: ': epsilon(i),;'; + print tnum++: ': epsilon(i),;'; - print tnum: ': Ending extensive numeric function test'; + print tnum: ': Ending extensive numeric function test'; } print '037: parsed test_2600()'; @@ -3144,13 +3144,13 @@ read -once "test2700.isqrt"; print '038: read -once test2700.isqrt'; define test_2700() { - local tnum; /* test number */ + local tnum; /* test number */ - print '2700: Beginning complex sqrt test'; + print '2700: Beginning complex sqrt test'; - tnum = test2700(1, 2701); + tnum = test2700(1, 2701); - print tnum: ': Ending complex sqrt test'; + print tnum: ': Ending complex sqrt test'; } print '039: parsed test_2700()'; @@ -3169,200 +3169,200 @@ print '042: global mat_D'; /**/ define test_matrix() { - static mat b[4,4]; - static mat binv[4,4] = { - 0, 1, 0, 0, 2, -3/2, 2, -1/2, -3, - 0.5, -1.0, 0.5, 1.0, 0.0, 0.0, 0.0 - }; - static mat c[] = { 1, 2+3i, -5+4i, 5i+6, -7i }; - static mat d[-1:1, -2:2, -3:3, -4:4]; - static mat A[2] = {1,2}; - static mat id0[2,2] = {1,0,0,1}; - static mat id1[0:2,-1:1] = {1,0,0,0,1,0,0,0,1}; - static mat noid0[2,2] = {1,2,0,1}; - static mat noid1[2,3] = {1,0,0,1,0,0}; - static mat noid2[4] = {1,0,0,1}; - static mat xp[3] = {2,3,4}; - static mat yp[3] = {3,4,5}; - static mat zp[3] = {-1,2,-1}; - static mat X[2,2] = {1,2,3,4}; - static mat Y[2,2] = {5,6,7,8}; - static mat Z[2,2] = {190,232,286,352}; - static mat x[] = {11,13,17,23,29}; - static mat y0[] = {1,3,7,3,9}; - static mat y1[] = {-9,-7,-3,-7,-1}; - static mat y2[] = {-9,-7,-3,3,9}; - static mat y3[] = {1,3,7,-7,-1}; - static mat y4[] = {1,3,-3,3,-1}; - local B; - local mat e[5,5]; - local mat M[2]; - local mat zero3[3]; + static mat b[4,4]; + static mat binv[4,4] = { + 0, 1, 0, 0, 2, -3/2, 2, -1/2, -3, + 0.5, -1.0, 0.5, 1.0, 0.0, 0.0, 0.0 + }; + static mat c[] = { 1, 2+3i, -5+4i, 5i+6, -7i }; + static mat d[-1:1, -2:2, -3:3, -4:4]; + static mat A[2] = {1,2}; + static mat id0[2,2] = {1,0,0,1}; + static mat id1[0:2,-1:1] = {1,0,0,0,1,0,0,0,1}; + static mat noid0[2,2] = {1,2,0,1}; + static mat noid1[2,3] = {1,0,0,1,0,0}; + static mat noid2[4] = {1,0,0,1}; + static mat xp[3] = {2,3,4}; + static mat yp[3] = {3,4,5}; + static mat zp[3] = {-1,2,-1}; + static mat X[2,2] = {1,2,3,4}; + static mat Y[2,2] = {5,6,7,8}; + static mat Z[2,2] = {190,232,286,352}; + static mat x[] = {11,13,17,23,29}; + static mat y0[] = {1,3,7,3,9}; + static mat y1[] = {-9,-7,-3,-7,-1}; + static mat y2[] = {-9,-7,-3,3,9}; + static mat y3[] = {1,3,7,-7,-1}; + static mat y4[] = {1,3,-3,3,-1}; + local B; + local mat e[5,5]; + local mat M[2]; + local mat zero3[3]; - print '2800: Beginning test_matrix'; + print '2800: Beginning test_matrix'; - b[0,0] = 0; - vrfy(b[0,0] == 0, '2801: b[0,0] == 0'); - b[0,1] = 0; - vrfy(b[0,1] == 0, '2802: b[0,1] == 0'); - b[0,2] = 0; - vrfy(b[0,2] == 0, '2803: b[0,2] == 0'); - b[0,3] = 1; - vrfy(b[0,3] == 1, '2804: b[0,3] == 1'); - b[1,0] = 1; - vrfy(b[1,0] == 1, '2805: b[1,0] == 1'); - b[1,1] = 0; - vrfy(b[1,1] == 0, '2806: b[1,1] == 0'); - b[1,2] = 0; - vrfy(b[1,2] == 0, '2807: b[1,2] == 0'); - b[1,3] = 0; - vrfy(b[1,3] == 0, '2808: b[1,3] == 0'); - b[2,0] = 1; - vrfy(b[2,0] == 1, '2809: b[2,0] == 1'); - b[2,1] = 1; - vrfy(b[2,1] == 1, '2810: b[2,1] == 1'); - b[2,2] = 1; - vrfy(b[2,2] == 1, '2811: b[2,2] == 1'); - b[2,3] = 1; - vrfy(b[2,3] == 1, '2812: b[2,3] == 1'); - b[3,0] = 1; - vrfy(b[3,0] == 1, '2813: b[3,0] == 1'); - b[3,1] = 2; - vrfy(b[3,1] == 2, '2814: b[3,1] == 2'); - b[3,2] = 4; - vrfy(b[3,2] == 4, '2815: b[3,2] == 4'); - b[3,3] = 8; - vrfy(b[3,3] == 8, '2816: b[3,3] == 8'); - vrfy(det(b) == -2, '2817: det(b) == -2'); - vrfy(binv[0,0] == 0, '2818: binv[0,0] == 0'); - vrfy(binv[0,1] == 1, '2819: binv[0,1] == 1'); - vrfy(binv[0,2] == 0, '2820: binv[0,2] == 0'); - vrfy(binv[0,3] == 0, '2821: binv[0,3] == 0'); - vrfy(binv[1,0] == 2, '2822: binv[1,0] == 2'); - vrfy(binv[1,1] == -3/2, '2823: binv[1,1] == -3/2'); - vrfy(binv[1,2] == 2, '2824: binv[1,2] == 2'); - vrfy(binv[1,3] == -1/2, '2825: binv[1,3] == -1/2'); - vrfy(binv[2,0] == -3, '2826: binv[2,0] == -3'); - vrfy(binv[2,1] == 1/2, '2827: binv[2,1] == 1/2'); - vrfy(binv[2,2] == -1, '2828: binv[2,2] == -1'); - vrfy(binv[2,3] == 1/2, '2829: binv[2,3] == 1/2'); - vrfy(binv[3,0] == 1, '2830: binv[3,0] == 1'); - vrfy(binv[3,1] == 0, '2831: binv[3,1] == 0'); - vrfy(binv[3,2] == 0, '2832: binv[3,2] == 0'); - vrfy(binv[3,3] == 0, '2833: binv[3,3] == 0'); - vrfy(inverse(b) == binv, '2834: inverse(b) == binv'); - vrfy(avg(b) == b, '2835: avg(b) == b'); - vrfy(avg(binv) == binv, '2836: avg(binv) == binv'); - vrfy((b+binv)/2 == avg(b,binv), '2837: (b+binv)/2 == avg(b,binv)'); - vrfy(ismat(b) == 1, '2838: ismat(b) == 1'); - vrfy(matsum(b) == 21, '2839: matsum(b) == 21'); - vrfy(matsum(binv) == 1, '2840: matsum(binv) == 1'); - vrfy(c[0] == 1, '2841: c[0] == 1'); - vrfy(c[1] == 2+3i, '2842: c[1] == 2+3i'); - vrfy(c[2] == -5+4i, '2843: c[2] == -5+4i'); - vrfy(c[3] == 6+5i, '2844: c[3] == 6+5i'); - vrfy(c[4] == -7i, '2845: c[4] == -7i'); - vrfy(matsum(c) == 4+5i, '2846: matsum(c) == 4+5i'); - vrfy(matdim(b) == 2, '2847: matdim(b) == 2'); - vrfy(matdim(c) == 1, '2848: matdim(c) == 1'); - vrfy(matdim(d) == 4, '2849: matdim(c) == 4'); - vrfy(matmax(c,1) == 4, '2850: matmax(c,1) == 4'); - vrfy(matmin(c,1) == 0, '2851: matmin(c,1) == 0'); - vrfy(matmin(d,1) == -1, '2852: matmin(d,1) == -1'); - vrfy(matmin(d,3) == -3, '2853: matmin(d,3) == -3'); - vrfy(matmax(d,1) == 1, '2854: matmin(d,1) == 1'); - vrfy(matmax(d,3) == 3, '2855: matmin(d,3) == 3'); - vrfy(size(binv) == 16, '2856: size(binv) == 16'); - vrfy(size(c) == 5, '2857: size(c) == 5'); - vrfy(size(d) == 945, '2858: size(d) == 945'); - vrfy(size(e) == 25, '2859: size(e) == 25'); - matfill(d,1); - print '2860: matfill(d,1)'; - vrfy(matsum(d) == 945, '2861: matsum(d) == 945'); - matfill(e,1,0); - print '2862: matfill(e,1,0)'; - vrfy(matsum(d) == 945, '2863: matsum(d) == 945'); - vrfy(matsum(e) == 20, '2864: matsum(e) == 20'); - vrfy(search(binv,1) == 1, '2865: search(binv,1) == 1'); - vrfy(search(binv,2) == 4, '2866: search(binv,2) == 4'); - vrfy(search(binv,2,4) == 4, '2867: search(binv,2,4) == 4'); - vrfy(search(binv,2,5) == 6, '2868: search(binv,2,5) == 6'); - vrfy(rsearch(binv,2) == 6, '2869: rsearch(binv,2) == 6'); - vrfy(rsearch(binv,2,6) == 6, '2870: rsearch(binv,2,6) == 6'); - vrfy(rsearch(binv,2,5) == 4, '2871: rsearch(binv,2,5) == 4'); - vrfy(A[0] == 1, '2872: A[0] == 1'); - vrfy(A[1] == 2, '2873: A[1] == 2'); - A[0] = A; - print '2874: A[0] = A'; - B = A[0]; - print '2875: B = A[0]'; - vrfy(B[0] == 1, '2876: B[0] == 1'); - vrfy(B[1] == 2, '2877: B[1] == 2'); - mat_D = mat_C[0]; - print '2878: mat_D = mat_C[0]'; - vrfy(mat_D[0] == 1, '2879: mat_D[0] == 1'); - vrfy(mat_D[1] == 2, '2880: mat_D[1] == 2'); - vrfy(quomod(15.6,5.2,M[0],M[1]) == 0, - '2881: quomod(15.6,5.2,M[0],M[1]) == 0'); - vrfy(M[0] == 3, '2882: M[0] == 3'); - vrfy(M[1] == 0, '2883: M[1] == 0'); - vrfy(isident(id0) == 1, '2884: isident(id0) == 1'); - vrfy(isident(id1) == 1, '2885: isident(id1) == 1'); - vrfy(isident(noid0) == 0, '2886: isident(noid0) == 0'); - vrfy(isident(noid1) == 0, '2887: isident(noid1) == 0'); - vrfy(isident(noid2) == 0, '2888: isident(noid2) == 0'); - vrfy(xp[0] == 2, '2889: xp[0] == 2'); - vrfy(xp[1] == 3, '2890: xp[1] == 3'); - vrfy(xp[2] == 4, '2891: xp[2] == 4'); - vrfy(yp[0] == 3, '2892: yp[0] == 3'); - vrfy(yp[1] == 4, '2893: yp[1] == 4'); - vrfy(yp[2] == 5, '2894: yp[2] == 5'); - vrfy(zp[0] == -1, '2895: zp[0] == -1'); - vrfy(zp[1] == 2, '2896: zp[1] == 2'); - vrfy(zp[2] == -1, '2897: zp[2] == -1'); - vrfy(cp(xp,yp) == zp, '2898: cp(xp,yp) == zp'); - vrfy(cp(yp,xp) == -zp, '2899: cp(yp,xp) == -zp'); - matfill(zero3,0); - print '2900: matfill(zero3,0)'; - vrfy(cp(xp,xp) == zero3, '2901: cp(xp,xp) == zero3'); - vrfy(dp(xp,yp) == 38, '2902: dp(xp,yp) == 38'); - vrfy(dp(yp,xp) == 38, '2903: dp(yp,xp) == 38'); - vrfy(dp(zp,dp(xp,yp)*zp) == 228,'2904: dp(zp,dp(xp,yp)*zp) == 228'); - vrfy(ssq(X, Y, X + Y) == Z, '2905: ssq(X, Y, X + Y) == Z'); - vrfy(mod(x,10,0) == y0, '2906: mod(x,10,0) == y0'); - vrfy(mod(x,10,1) == y1, '2907: mod(x,10,1) == y1'); - vrfy(mod(x,10,2) == y0, '2908: mod(x,10,2) == y0'); - vrfy(mod(x,10,3) == y1, '2909: mod(x,10,3) == y1'); - vrfy(mod(x,10,4) == y0, '2910: mod(x,10,4) == y0'); - vrfy(mod(x,10,5) == y1, '2911: mod(x,10,5) == y1'); - vrfy(mod(x,10,6) == y0, '2912: mod(x,10,6) == y0'); - vrfy(mod(x,10,7) == y1, '2913: mod(x,10,7) == y1'); - vrfy(mod(x,10,8) == y2, '2914: mod(x,10,8) == y2'); - vrfy(mod(x,10,9) == y3, '2915: mod(x,10,9) == y3'); - vrfy(mod(x,10,10) == y2, '2916: mod(x,10,10) == y2'); - vrfy(mod(x,10,11) == y3, '2917: mod(x,10,11) == y3'); - vrfy(mod(x,10,12) == y2, '2918: mod(x,10,12) == y2'); - vrfy(mod(x,10,13) == y3, '2919: mod(x,10,13) == y3'); - vrfy(mod(x,10,14) == y2, '2920: mod(x,10,14) == y2'); - vrfy(mod(x,10,15) == y3, '2921: mod(x,10,15) == y3'); - vrfy(mod(x,10,16) == y4, '2922: mod(x,10,16) == y4'); - vrfy(mod(x,10,16) == y4, '2923: mod(x,10,16) == y4'); - vrfy(mod(x,10,18) == y4, '2924: mod(x,10,18) == y4'); - vrfy(mod(x,10,19) == y4, '2925: mod(x,10,18) == y4'); - vrfy(mod(x,10,20) == y4, '2926: mod(x,10,20) == y4'); - vrfy(mod(x,10,21) == y4, '2927: mod(x,10,21) == y4'); - vrfy(mod(x,10,22) == y4, '2928: mod(x,10,22) == y4'); - vrfy(mod(x,10,23) == y4, '2929: mod(x,10,23) == y4'); - vrfy(mod(x,10,24) == y4, '2930: mod(x,10,24) == y4'); - vrfy(mod(x,10,25) == y4, '2931: mod(x,10,25) == y4'); - vrfy(mod(x,10,26) == y4, '2932: mod(x,10,26) == y4'); - vrfy(mod(x,10,27) == y4, '2933: mod(x,10,27) == y4'); - vrfy(mod(x,10,28) == y4, '2934: mod(x,10,28) == y4'); - vrfy(mod(x,10,29) == y4, '2935: mod(x,10,29) == y4'); - vrfy(mod(x,10,30) == y4, '2936: mod(x,10,30) == y4'); - vrfy(mod(x,10,31) == y4, '2937: mod(x,10,31) == y4'); + b[0,0] = 0; + vrfy(b[0,0] == 0, '2801: b[0,0] == 0'); + b[0,1] = 0; + vrfy(b[0,1] == 0, '2802: b[0,1] == 0'); + b[0,2] = 0; + vrfy(b[0,2] == 0, '2803: b[0,2] == 0'); + b[0,3] = 1; + vrfy(b[0,3] == 1, '2804: b[0,3] == 1'); + b[1,0] = 1; + vrfy(b[1,0] == 1, '2805: b[1,0] == 1'); + b[1,1] = 0; + vrfy(b[1,1] == 0, '2806: b[1,1] == 0'); + b[1,2] = 0; + vrfy(b[1,2] == 0, '2807: b[1,2] == 0'); + b[1,3] = 0; + vrfy(b[1,3] == 0, '2808: b[1,3] == 0'); + b[2,0] = 1; + vrfy(b[2,0] == 1, '2809: b[2,0] == 1'); + b[2,1] = 1; + vrfy(b[2,1] == 1, '2810: b[2,1] == 1'); + b[2,2] = 1; + vrfy(b[2,2] == 1, '2811: b[2,2] == 1'); + b[2,3] = 1; + vrfy(b[2,3] == 1, '2812: b[2,3] == 1'); + b[3,0] = 1; + vrfy(b[3,0] == 1, '2813: b[3,0] == 1'); + b[3,1] = 2; + vrfy(b[3,1] == 2, '2814: b[3,1] == 2'); + b[3,2] = 4; + vrfy(b[3,2] == 4, '2815: b[3,2] == 4'); + b[3,3] = 8; + vrfy(b[3,3] == 8, '2816: b[3,3] == 8'); + vrfy(det(b) == -2, '2817: det(b) == -2'); + vrfy(binv[0,0] == 0, '2818: binv[0,0] == 0'); + vrfy(binv[0,1] == 1, '2819: binv[0,1] == 1'); + vrfy(binv[0,2] == 0, '2820: binv[0,2] == 0'); + vrfy(binv[0,3] == 0, '2821: binv[0,3] == 0'); + vrfy(binv[1,0] == 2, '2822: binv[1,0] == 2'); + vrfy(binv[1,1] == -3/2, '2823: binv[1,1] == -3/2'); + vrfy(binv[1,2] == 2, '2824: binv[1,2] == 2'); + vrfy(binv[1,3] == -1/2, '2825: binv[1,3] == -1/2'); + vrfy(binv[2,0] == -3, '2826: binv[2,0] == -3'); + vrfy(binv[2,1] == 1/2, '2827: binv[2,1] == 1/2'); + vrfy(binv[2,2] == -1, '2828: binv[2,2] == -1'); + vrfy(binv[2,3] == 1/2, '2829: binv[2,3] == 1/2'); + vrfy(binv[3,0] == 1, '2830: binv[3,0] == 1'); + vrfy(binv[3,1] == 0, '2831: binv[3,1] == 0'); + vrfy(binv[3,2] == 0, '2832: binv[3,2] == 0'); + vrfy(binv[3,3] == 0, '2833: binv[3,3] == 0'); + vrfy(inverse(b) == binv, '2834: inverse(b) == binv'); + vrfy(avg(b) == b, '2835: avg(b) == b'); + vrfy(avg(binv) == binv, '2836: avg(binv) == binv'); + vrfy((b+binv)/2 == avg(b,binv), '2837: (b+binv)/2 == avg(b,binv)'); + vrfy(ismat(b) == 1, '2838: ismat(b) == 1'); + vrfy(matsum(b) == 21, '2839: matsum(b) == 21'); + vrfy(matsum(binv) == 1, '2840: matsum(binv) == 1'); + vrfy(c[0] == 1, '2841: c[0] == 1'); + vrfy(c[1] == 2+3i, '2842: c[1] == 2+3i'); + vrfy(c[2] == -5+4i, '2843: c[2] == -5+4i'); + vrfy(c[3] == 6+5i, '2844: c[3] == 6+5i'); + vrfy(c[4] == -7i, '2845: c[4] == -7i'); + vrfy(matsum(c) == 4+5i, '2846: matsum(c) == 4+5i'); + vrfy(matdim(b) == 2, '2847: matdim(b) == 2'); + vrfy(matdim(c) == 1, '2848: matdim(c) == 1'); + vrfy(matdim(d) == 4, '2849: matdim(c) == 4'); + vrfy(matmax(c,1) == 4, '2850: matmax(c,1) == 4'); + vrfy(matmin(c,1) == 0, '2851: matmin(c,1) == 0'); + vrfy(matmin(d,1) == -1, '2852: matmin(d,1) == -1'); + vrfy(matmin(d,3) == -3, '2853: matmin(d,3) == -3'); + vrfy(matmax(d,1) == 1, '2854: matmin(d,1) == 1'); + vrfy(matmax(d,3) == 3, '2855: matmin(d,3) == 3'); + vrfy(size(binv) == 16, '2856: size(binv) == 16'); + vrfy(size(c) == 5, '2857: size(c) == 5'); + vrfy(size(d) == 945, '2858: size(d) == 945'); + vrfy(size(e) == 25, '2859: size(e) == 25'); + matfill(d,1); + print '2860: matfill(d,1)'; + vrfy(matsum(d) == 945, '2861: matsum(d) == 945'); + matfill(e,1,0); + print '2862: matfill(e,1,0)'; + vrfy(matsum(d) == 945, '2863: matsum(d) == 945'); + vrfy(matsum(e) == 20, '2864: matsum(e) == 20'); + vrfy(search(binv,1) == 1, '2865: search(binv,1) == 1'); + vrfy(search(binv,2) == 4, '2866: search(binv,2) == 4'); + vrfy(search(binv,2,4) == 4, '2867: search(binv,2,4) == 4'); + vrfy(search(binv,2,5) == 6, '2868: search(binv,2,5) == 6'); + vrfy(rsearch(binv,2) == 6, '2869: rsearch(binv,2) == 6'); + vrfy(rsearch(binv,2,6) == 6, '2870: rsearch(binv,2,6) == 6'); + vrfy(rsearch(binv,2,5) == 4, '2871: rsearch(binv,2,5) == 4'); + vrfy(A[0] == 1, '2872: A[0] == 1'); + vrfy(A[1] == 2, '2873: A[1] == 2'); + A[0] = A; + print '2874: A[0] = A'; + B = A[0]; + print '2875: B = A[0]'; + vrfy(B[0] == 1, '2876: B[0] == 1'); + vrfy(B[1] == 2, '2877: B[1] == 2'); + mat_D = mat_C[0]; + print '2878: mat_D = mat_C[0]'; + vrfy(mat_D[0] == 1, '2879: mat_D[0] == 1'); + vrfy(mat_D[1] == 2, '2880: mat_D[1] == 2'); + vrfy(quomod(15.6,5.2,M[0],M[1]) == 0, + '2881: quomod(15.6,5.2,M[0],M[1]) == 0'); + vrfy(M[0] == 3, '2882: M[0] == 3'); + vrfy(M[1] == 0, '2883: M[1] == 0'); + vrfy(isident(id0) == 1, '2884: isident(id0) == 1'); + vrfy(isident(id1) == 1, '2885: isident(id1) == 1'); + vrfy(isident(noid0) == 0, '2886: isident(noid0) == 0'); + vrfy(isident(noid1) == 0, '2887: isident(noid1) == 0'); + vrfy(isident(noid2) == 0, '2888: isident(noid2) == 0'); + vrfy(xp[0] == 2, '2889: xp[0] == 2'); + vrfy(xp[1] == 3, '2890: xp[1] == 3'); + vrfy(xp[2] == 4, '2891: xp[2] == 4'); + vrfy(yp[0] == 3, '2892: yp[0] == 3'); + vrfy(yp[1] == 4, '2893: yp[1] == 4'); + vrfy(yp[2] == 5, '2894: yp[2] == 5'); + vrfy(zp[0] == -1, '2895: zp[0] == -1'); + vrfy(zp[1] == 2, '2896: zp[1] == 2'); + vrfy(zp[2] == -1, '2897: zp[2] == -1'); + vrfy(cp(xp,yp) == zp, '2898: cp(xp,yp) == zp'); + vrfy(cp(yp,xp) == -zp, '2899: cp(yp,xp) == -zp'); + matfill(zero3,0); + print '2900: matfill(zero3,0)'; + vrfy(cp(xp,xp) == zero3, '2901: cp(xp,xp) == zero3'); + vrfy(dp(xp,yp) == 38, '2902: dp(xp,yp) == 38'); + vrfy(dp(yp,xp) == 38, '2903: dp(yp,xp) == 38'); + vrfy(dp(zp,dp(xp,yp)*zp) == 228,'2904: dp(zp,dp(xp,yp)*zp) == 228'); + vrfy(ssq(X, Y, X + Y) == Z, '2905: ssq(X, Y, X + Y) == Z'); + vrfy(mod(x,10,0) == y0, '2906: mod(x,10,0) == y0'); + vrfy(mod(x,10,1) == y1, '2907: mod(x,10,1) == y1'); + vrfy(mod(x,10,2) == y0, '2908: mod(x,10,2) == y0'); + vrfy(mod(x,10,3) == y1, '2909: mod(x,10,3) == y1'); + vrfy(mod(x,10,4) == y0, '2910: mod(x,10,4) == y0'); + vrfy(mod(x,10,5) == y1, '2911: mod(x,10,5) == y1'); + vrfy(mod(x,10,6) == y0, '2912: mod(x,10,6) == y0'); + vrfy(mod(x,10,7) == y1, '2913: mod(x,10,7) == y1'); + vrfy(mod(x,10,8) == y2, '2914: mod(x,10,8) == y2'); + vrfy(mod(x,10,9) == y3, '2915: mod(x,10,9) == y3'); + vrfy(mod(x,10,10) == y2, '2916: mod(x,10,10) == y2'); + vrfy(mod(x,10,11) == y3, '2917: mod(x,10,11) == y3'); + vrfy(mod(x,10,12) == y2, '2918: mod(x,10,12) == y2'); + vrfy(mod(x,10,13) == y3, '2919: mod(x,10,13) == y3'); + vrfy(mod(x,10,14) == y2, '2920: mod(x,10,14) == y2'); + vrfy(mod(x,10,15) == y3, '2921: mod(x,10,15) == y3'); + vrfy(mod(x,10,16) == y4, '2922: mod(x,10,16) == y4'); + vrfy(mod(x,10,16) == y4, '2923: mod(x,10,16) == y4'); + vrfy(mod(x,10,18) == y4, '2924: mod(x,10,18) == y4'); + vrfy(mod(x,10,19) == y4, '2925: mod(x,10,18) == y4'); + vrfy(mod(x,10,20) == y4, '2926: mod(x,10,20) == y4'); + vrfy(mod(x,10,21) == y4, '2927: mod(x,10,21) == y4'); + vrfy(mod(x,10,22) == y4, '2928: mod(x,10,22) == y4'); + vrfy(mod(x,10,23) == y4, '2929: mod(x,10,23) == y4'); + vrfy(mod(x,10,24) == y4, '2930: mod(x,10,24) == y4'); + vrfy(mod(x,10,25) == y4, '2931: mod(x,10,25) == y4'); + vrfy(mod(x,10,26) == y4, '2932: mod(x,10,26) == y4'); + vrfy(mod(x,10,27) == y4, '2933: mod(x,10,27) == y4'); + vrfy(mod(x,10,28) == y4, '2934: mod(x,10,28) == y4'); + vrfy(mod(x,10,29) == y4, '2935: mod(x,10,29) == y4'); + vrfy(mod(x,10,30) == y4, '2936: mod(x,10,30) == y4'); + vrfy(mod(x,10,31) == y4, '2937: mod(x,10,31) == y4'); - print '2938: Ending mat_functions'; + print '2938: Ending mat_functions'; } print '043: parsed test_matrix()'; @@ -3374,33 +3374,33 @@ print '043: parsed test_matrix()'; */ define test_strings() { - local x, y, z; + local x, y, z; - print '3000: Beginning test_strings'; + print '3000: Beginning test_strings'; - x = 'string'; - print "3001: x = 'string'"; - y = "string"; - print '3002: y = "string"'; - z = x; - print '3003: z = x'; - vrfy(z == "string", '3004: z == "string"'); - vrfy(z != "foo", '3005: z != "foo"'); - vrfy(z != 3, '3006: z != 3'); - vrfy('' == "", '3007: \'\' == ""'); - vrfy("a" == "a", '3008: "a" == "a"'); - vrfy("c" != "d", '3009: "c" != "d"'); - vrfy("" != "a", '3010: "" != "a"'); - vrfy("rs" < "rt", '3011: "rs" < "rt"'); - vrfy("rs" < "ss", '3012: "rs < "ss"'); - vrfy("rs" <= "rs", '3013: "rs" <= "rs"'); - vrfy("rs" <= "tu", '3014: "rs" <= "tu"'); - vrfy("rs" > "cd", '3015: "rs" > "cd"'); - vrfy("rs" >= "rs", '3016: "rs" >= "rs"'); - vrfy("rs" >= "cd", '3017: "rs" >= "cd"'); - vrfy("abc" > "ab", '3018: "abc" > "ab"'); + x = 'string'; + print "3001: x = 'string'"; + y = "string"; + print '3002: y = "string"'; + z = x; + print '3003: z = x'; + vrfy(z == "string", '3004: z == "string"'); + vrfy(z != "foo", '3005: z != "foo"'); + vrfy(z != 3, '3006: z != 3'); + vrfy('' == "", '3007: \'\' == ""'); + vrfy("a" == "a", '3008: "a" == "a"'); + vrfy("c" != "d", '3009: "c" != "d"'); + vrfy("" != "a", '3010: "" != "a"'); + vrfy("rs" < "rt", '3011: "rs" < "rt"'); + vrfy("rs" < "ss", '3012: "rs < "ss"'); + vrfy("rs" <= "rs", '3013: "rs" <= "rs"'); + vrfy("rs" <= "tu", '3014: "rs" <= "tu"'); + vrfy("rs" > "cd", '3015: "rs" > "cd"'); + vrfy("rs" >= "rs", '3016: "rs" >= "rs"'); + vrfy("rs" >= "cd", '3017: "rs" >= "cd"'); + vrfy("abc" > "ab", '3018: "abc" > "ab"'); - print '3019: Ending test_strings'; + print '3019: Ending test_strings'; } print '044: parsed test_strings()'; @@ -3415,75 +3415,75 @@ print '045: read -once test3100.matobj'; /**/ define test_matobj() { - local mat A[3,3] = {2, 3, 5, 7, 11, 13, 17, 19, 23}; - local mat B[2,2]; + local mat A[3,3] = {2, 3, 5, 7, 11, 13, 17, 19, 23}; + local mat B[2,2]; - print '3100: Beginning test_matobj'; + print '3100: Beginning test_matobj'; - vrfy(det(A) == -78, '3101: det(A) == -78'); - vrfy(det(A^2) == 6084, '3102: det(A^2) == 6084'); - vrfy(det(A^3) == -474552, '3103: det(A^3) == -474552'); - vrfy(det(A^-1) == -1/78, '3104: det(A^-1) == -1/78'); - md = 0; - print '3105: md = 0'; - B[0,0] = res(2); - print '3106: B[0,0] = res(2)'; - B[0,1] = res(3); - print '3107: B[0,1] = res(3)'; - B[1,0] = res(5); - print '3108: B[1,0] = res(5)'; - B[1,1] = res(7); - print '3109: B[1,1] = res(7)'; - print '3110: md = 0'; - md = 0; - vrfy(det(B) == res(-1), '3111: det(B) == res(-1)'); - md = 1; - print '3112: md = 1'; - vrfy(det(B) == 0, '3113: det(B) == 0'); - md = 2; - print '3114: md = 2'; - vrfy(det(B) == res(1), '3115: det(B) == res(1)'); - md = 3; - print '3116: md = 3'; - vrfy(det(B) == res(2), '3117: det(B) == res(2)'); - md = 4; - print '3118: md = 4'; - vrfy(det(B) == res(3), '3119: det(B) == res(3)'); - md = 5; - print '3120: md = 5'; - vrfy(det(B) == res(4), '3121: det(B) == res(4)'); - md = 6; - print '3122: md = 6'; - vrfy(det(B) == res(5), '3123: det(B) == res(5)'); - md = 7; - print '3124: md = 7'; - vrfy(det(B) == res(6), '3125: det(B) == res(6)'); - md = 8; - print '3126: md = 8'; - vrfy(det(B) == res(7), '3127: det(B) == res(7)'); - md = 9; - print '3128: md = 9'; - vrfy(det(B) == res(8), '3129: det(B) == res(8)'); - md = 10; - print '3130: md = 10'; - vrfy(det(B) == res(9), '3131: det(B) == res(9)'); - md = 11; - print '3132: md = 11'; - vrfy(det(B) == res(10), '3133: det(B) == res(10)'); - md = 12; - print '3134: md = 12'; - vrfy(det(B) == res(11), '3135: det(B) == res(11)'); - md = 13; - print '3136: md = 13'; - vrfy(det(B) == res(12), '3137: det(B) == res(12)'); - md = 14; - print '3138: md = 14'; - vrfy(det(B) == res(13), '3139: det(B) == res(13)'); - md = 15; - print '3140: md = 15'; - vrfy(det(B) == res(14), '3141: det(B) == res(14)'); + vrfy(det(A) == -78, '3101: det(A) == -78'); + vrfy(det(A^2) == 6084, '3102: det(A^2) == 6084'); + vrfy(det(A^3) == -474552, '3103: det(A^3) == -474552'); + vrfy(det(A^-1) == -1/78, '3104: det(A^-1) == -1/78'); + md = 0; + print '3105: md = 0'; + B[0,0] = res(2); + print '3106: B[0,0] = res(2)'; + B[0,1] = res(3); + print '3107: B[0,1] = res(3)'; + B[1,0] = res(5); + print '3108: B[1,0] = res(5)'; + B[1,1] = res(7); + print '3109: B[1,1] = res(7)'; + print '3110: md = 0'; + md = 0; + vrfy(det(B) == res(-1), '3111: det(B) == res(-1)'); + md = 1; + print '3112: md = 1'; + vrfy(det(B) == 0, '3113: det(B) == 0'); + md = 2; + print '3114: md = 2'; + vrfy(det(B) == res(1), '3115: det(B) == res(1)'); + md = 3; + print '3116: md = 3'; + vrfy(det(B) == res(2), '3117: det(B) == res(2)'); + md = 4; + print '3118: md = 4'; + vrfy(det(B) == res(3), '3119: det(B) == res(3)'); + md = 5; + print '3120: md = 5'; + vrfy(det(B) == res(4), '3121: det(B) == res(4)'); + md = 6; + print '3122: md = 6'; + vrfy(det(B) == res(5), '3123: det(B) == res(5)'); + md = 7; + print '3124: md = 7'; + vrfy(det(B) == res(6), '3125: det(B) == res(6)'); + md = 8; + print '3126: md = 8'; + vrfy(det(B) == res(7), '3127: det(B) == res(7)'); + md = 9; + print '3128: md = 9'; + vrfy(det(B) == res(8), '3129: det(B) == res(8)'); + md = 10; + print '3130: md = 10'; + vrfy(det(B) == res(9), '3131: det(B) == res(9)'); + md = 11; + print '3132: md = 11'; + vrfy(det(B) == res(10), '3133: det(B) == res(10)'); + md = 12; + print '3134: md = 12'; + vrfy(det(B) == res(11), '3135: det(B) == res(11)'); + md = 13; + print '3136: md = 13'; + vrfy(det(B) == res(12), '3137: det(B) == res(12)'); + md = 14; + print '3138: md = 14'; + vrfy(det(B) == res(13), '3139: det(B) == res(13)'); + md = 15; + print '3140: md = 15'; + vrfy(det(B) == res(14), '3141: det(B) == res(14)'); - print '3142: Ending test_matobj'; + print '3142: Ending test_matobj'; } print '046: parsed test_matobj()'; @@ -3495,37 +3495,37 @@ print '046: parsed test_matobj()'; */ define test_poly() { - print '3200: Beginning test_matobj'; + print '3200: Beginning test_matobj'; - vrfy(poly(2,3,5,2) == 19, '3201: poly(2,3,5,2) == 19'); - vrfy(poly(list(5,3,2),2) == 19,\ - '3202: poly(list(5,3,2),2) == 19'); - vrfy(poly(list(5,3,2)) == 5, '3203: poly(list(5,3,2)) == 5'); - vrfy(poly(2) == 2, '3204: poly(2) == 2'); - vrfy(poly(list(5,3,2),2,3) == 19,\ - '3205: poly(list(5,3,2),2,3) == 19'); - vrfy(poly(list()) == 0, '3206: poly(list()) == 0'); - vrfy(poly(list(),2,3) == 0, '3207: poly(list(),2,3) == 0'); - vrfy(poly(list(list(5,3,2)),7,2) == 19,\ - '3208: poly(list(list(5,3,2)),7,2) == 19'); - vrfy(poly(list(list(1,2,3),list(4,5),6),7) == 323,\ - '3209: poly(list(list(1,2,3),list(4,5),6),7) == 323'); - vrfy(poly(list(list(1,2,3),list(4,5),6),7,8) == 811,\ - '3210: poly(list(list(1,2,3),list(4,5),6),7,8) == 811'); - vrfy(poly(list(list(1,2,3),list(4,5),6),7,8,9) == 811,\ - '3211: poly(list(list(1,2,3),list(4,5),6),7,8,9)==811'); - vrfy(poly(list(5,3,2), list()) == 5,\ - '3212: poly(list(5,3,2), list() == 5'); - vrfy(poly(list(5,3,2), list(2)) == 19,\ - '3213: poly(list(5,3,2), list(2)) == 19'); - vrfy(poly(list(5,3,2), list(2,3)) == 19,\ - '3214: poly(list(5,3,2), list(2,3)) == 19'); - vrfy(poly(list(list(list(0,0,0,0,0,1))),2,3,4) == 4^5,\ - '3215: poly(list(list(list(0,0,0,0,0,1))),2,3,4)==4^5'); - vrfy(poly(list(list(list(0,0,0,0,0,1))),2,list(3,4)) == 4^5,\ - '3216: poly(list(list(list(0,0,0,0,0,1))),2,list(3,4))==4^5'); + vrfy(poly(2,3,5,2) == 19, '3201: poly(2,3,5,2) == 19'); + vrfy(poly(list(5,3,2),2) == 19,\ + '3202: poly(list(5,3,2),2) == 19'); + vrfy(poly(list(5,3,2)) == 5, '3203: poly(list(5,3,2)) == 5'); + vrfy(poly(2) == 2, '3204: poly(2) == 2'); + vrfy(poly(list(5,3,2),2,3) == 19,\ + '3205: poly(list(5,3,2),2,3) == 19'); + vrfy(poly(list()) == 0, '3206: poly(list()) == 0'); + vrfy(poly(list(),2,3) == 0, '3207: poly(list(),2,3) == 0'); + vrfy(poly(list(list(5,3,2)),7,2) == 19,\ + '3208: poly(list(list(5,3,2)),7,2) == 19'); + vrfy(poly(list(list(1,2,3),list(4,5),6),7) == 323,\ + '3209: poly(list(list(1,2,3),list(4,5),6),7) == 323'); + vrfy(poly(list(list(1,2,3),list(4,5),6),7,8) == 811,\ + '3210: poly(list(list(1,2,3),list(4,5),6),7,8) == 811'); + vrfy(poly(list(list(1,2,3),list(4,5),6),7,8,9) == 811,\ + '3211: poly(list(list(1,2,3),list(4,5),6),7,8,9)==811'); + vrfy(poly(list(5,3,2), list()) == 5,\ + '3212: poly(list(5,3,2), list() == 5'); + vrfy(poly(list(5,3,2), list(2)) == 19,\ + '3213: poly(list(5,3,2), list(2)) == 19'); + vrfy(poly(list(5,3,2), list(2,3)) == 19,\ + '3214: poly(list(5,3,2), list(2,3)) == 19'); + vrfy(poly(list(list(list(0,0,0,0,0,1))),2,3,4) == 4^5,\ + '3215: poly(list(list(list(0,0,0,0,0,1))),2,3,4)==4^5'); + vrfy(poly(list(list(list(0,0,0,0,0,1))),2,list(3,4)) == 4^5,\ + '3216: poly(list(list(list(0,0,0,0,0,1))),2,list(3,4))==4^5'); - print '3217: Ending test_poly'; + print '3217: Ending test_poly'; } print '047: parsed test_poly()'; @@ -3540,14 +3540,14 @@ print '048: read -once test3300.det'; /**/ define test_det() { - local tnum; /* test number */ - local i; + local tnum; /* test number */ + local i; - print '3300: Beginning test_det'; + print '3300: Beginning test_det'; - tnum = test3300(1, 3301); + tnum = test3300(1, 3301); - print tnum: ': Ending test_det'; + print tnum: ': Ending test_det'; } print '049: parsed test_det()'; @@ -3563,690 +3563,690 @@ print '050: read -once test3400.trig'; /**/ define test_trig() { - local tnum; /* test number */ - local pi; /* pi to 1e-20 precision */ - local i; + local tnum; /* test number */ + local pi; /* pi to 1e-20 precision */ + local i; - /* - * NOTE: The various functions test in this are often accurate to - * eps (epsilon) or better, which defaults to about 20 decimal - * digits. We test a number of functions to 10 digits using - * round(..., 10) because we do not want to have to put lots - * of digits in the verify identities. - */ + /* + * NOTE: The various functions test in this are often accurate to + * eps (epsilon) or better, which defaults to about 20 decimal + * digits. We test a number of functions to 10 digits using + * round(..., 10) because we do not want to have to put lots + * of digits in the verify identities. + */ - print '3400: Beginning test_trig'; + print '3400: Beginning test_trig'; - /* test 3401-3407 */ - tnum = test3400(1, 3401); - vrfy(tnum++ == 3407, '3407: tnum == 3407'); - pi = pi(1e-20); + /* test 3401-3407 */ + tnum = test3400(1, 3401); + vrfy(tnum++ == 3407, '3407: tnum == 3407'); + pi = pi(1e-20); - /* test trigonometric sine */ - vrfy(sin(0, 1e-10) == 0, - strcat(str(tnum++), ': sin(0, 1e-10) == 0')); - vrfy(round(sin(1, 1e-10), 10) == 0.8414709848, - strcat(str(tnum++), - ': round(sin(1, 1e-10), 10) == 0.8414709848')); - vrfy(round(sin(2 + 3i, 1e-10), 10) == 9.1544991469-4.16890696i, - strcat(str(tnum++), - ': round(sin(2 + 3i, 1e-10), 10) == 9.1544991469-4.16890696i')); - vrfy(sin(pi/6, 1e-10) == 0.5, - strcat(str(tnum++), ': sin(pi/6, 1e-10) == 0.5')); - vrfy(sin(pi/2, 1e-10) == 1, - strcat(str(tnum++), ': sin(pi/2, 1e-10) == 1')); - vrfy(sin(pi, 1e-10) == 0, - strcat(str(tnum++), ': sin(pi, 1e-10) == 1')); - vrfy(round(sin(1/2, 1e-10), 10) == 0.4794255386, - strcat(str(tnum++), - ': round(sin(1/2, 1e-10), 10) == 0.4794255386')); - vrfy(round(sin(5/7, 1e-10), 10) == 0.6550778972, - strcat(str(tnum++), - ': round(sin(5/7, 1e-10), 10) == 0.6550778972')); - vrfy(round(sin(42/7, 1e-10), 10) == -0.2794154982, - strcat(str(tnum++), - ': round(sin(42/7, 1e-10), 10) == -0.2794154982')); + /* test trigonometric sine */ + vrfy(sin(0, 1e-10) == 0, + strcat(str(tnum++), ': sin(0, 1e-10) == 0')); + vrfy(round(sin(1, 1e-10), 10) == 0.8414709848, + strcat(str(tnum++), + ': round(sin(1, 1e-10), 10) == 0.8414709848')); + vrfy(round(sin(2 + 3i, 1e-10), 10) == 9.1544991469-4.16890696i, + strcat(str(tnum++), + ': round(sin(2 + 3i, 1e-10), 10) == 9.1544991469-4.16890696i')); + vrfy(sin(pi/6, 1e-10) == 0.5, + strcat(str(tnum++), ': sin(pi/6, 1e-10) == 0.5')); + vrfy(sin(pi/2, 1e-10) == 1, + strcat(str(tnum++), ': sin(pi/2, 1e-10) == 1')); + vrfy(sin(pi, 1e-10) == 0, + strcat(str(tnum++), ': sin(pi, 1e-10) == 1')); + vrfy(round(sin(1/2, 1e-10), 10) == 0.4794255386, + strcat(str(tnum++), + ': round(sin(1/2, 1e-10), 10) == 0.4794255386')); + vrfy(round(sin(5/7, 1e-10), 10) == 0.6550778972, + strcat(str(tnum++), + ': round(sin(5/7, 1e-10), 10) == 0.6550778972')); + vrfy(round(sin(42/7, 1e-10), 10) == -0.2794154982, + strcat(str(tnum++), + ': round(sin(42/7, 1e-10), 10) == -0.2794154982')); - /* test trigonometric cosine */ - vrfy(cos(0, 1e-10) == 1, - strcat(str(tnum++), ': cos(0, 1e-10) == 1')); - vrfy(round(cos(1, 1e-10), 10) == 0.5403023059, - strcat(str(tnum++), - ': round(cos(0.2, 1e-10), 10) == 0.5403023059')); - vrfy(cos(pi/3, 1e-10) == 0.5, - strcat(str(tnum++), ': cos(pi/3, 1e-10) == 0.5')); - vrfy(cos(pi/2, 1e-10) == 0, - strcat(str(tnum++), ': cos(pi/2, 1e-10) == 0')); - vrfy(cos(pi, 1e-10) == -1, - strcat(str(tnum++), ': cos(pi, 1e-10) == -1')); - vrfy(round(cos(2 + 3i, 1e-10), 10) == -4.189625691-9.1092278938i, - strcat(str(tnum++), - ': round(cos(2 + 3i, 1e-10), 10) == -4.189625691-9.1092278938i')); - vrfy(round(cos(1/2, 1e-10), 10) == 0.8775825619, - strcat(str(tnum++), - ': round(cos(1/2, 1e-10), 10) == 0.8775825619')); - vrfy(round(cos(5/7, 1e-10), 10) == 0.7555613467, - strcat(str(tnum++), - ': round(cos(5/7, 1e-10), 10) == 0.7555613467')); - vrfy(round(cos(42/7, 1e-10), 10) == 0.9601702866, - strcat(str(tnum++), - ': round(cos(42/7, 1e-10), 10) == 0.9601702866')); + /* test trigonometric cosine */ + vrfy(cos(0, 1e-10) == 1, + strcat(str(tnum++), ': cos(0, 1e-10) == 1')); + vrfy(round(cos(1, 1e-10), 10) == 0.5403023059, + strcat(str(tnum++), + ': round(cos(0.2, 1e-10), 10) == 0.5403023059')); + vrfy(cos(pi/3, 1e-10) == 0.5, + strcat(str(tnum++), ': cos(pi/3, 1e-10) == 0.5')); + vrfy(cos(pi/2, 1e-10) == 0, + strcat(str(tnum++), ': cos(pi/2, 1e-10) == 0')); + vrfy(cos(pi, 1e-10) == -1, + strcat(str(tnum++), ': cos(pi, 1e-10) == -1')); + vrfy(round(cos(2 + 3i, 1e-10), 10) == -4.189625691-9.1092278938i, + strcat(str(tnum++), + ': round(cos(2 + 3i, 1e-10), 10) == -4.189625691-9.1092278938i')); + vrfy(round(cos(1/2, 1e-10), 10) == 0.8775825619, + strcat(str(tnum++), + ': round(cos(1/2, 1e-10), 10) == 0.8775825619')); + vrfy(round(cos(5/7, 1e-10), 10) == 0.7555613467, + strcat(str(tnum++), + ': round(cos(5/7, 1e-10), 10) == 0.7555613467')); + vrfy(round(cos(42/7, 1e-10), 10) == 0.9601702866, + strcat(str(tnum++), + ': round(cos(42/7, 1e-10), 10) == 0.9601702866')); - /* test trigonometric tangent */ - vrfy(tan(0, 1e-10) == 0, - strcat(str(tnum++), ': tan(0, 1e-10) == 0')); - vrfy(round(tan(1, 1e-10), 10) == 1.5574077247, - strcat(str(tnum++), - ': round(tan(0.2, 1e-10), 10) == 1.5574077247')); - vrfy(round(tan(pi/6, 1e-10), 10) == 0.5773502692, - strcat(str(tnum++), - ': round(tan(pi/6, 1e-10), 10) == 0.5773502692')); - vrfy(round(tan(pi/3, 1e-10), 10) == 1.7320508076, - strcat(str(tnum++), - ': round(tan(pi/3, 1e-10), 10) == 1.7320508076')); - vrfy(tan(pi, 1e-10) == 0, - strcat(str(tnum++), ': tan(pi, 1e-10) == 0')); - vrfy(round(tan(1/2, 1e-10), 10) == 0.5463024898, - strcat(str(tnum++), - ': round(tan(1/2, 1e-10), 10) == 0.5463024898')); - vrfy(round(tan(5/7, 1e-10), 10) == 0.8670082185, - strcat(str(tnum++), - ': round(tan(5/7, 1e-10), 10) == 0.8670082185')); - vrfy(round(tan(42/7, 1e-10), 10) == -0.2910061914, - strcat(str(tnum++), - ': round(tan(42/7, 1e-10), 10) == -0.2910061914')); + /* test trigonometric tangent */ + vrfy(tan(0, 1e-10) == 0, + strcat(str(tnum++), ': tan(0, 1e-10) == 0')); + vrfy(round(tan(1, 1e-10), 10) == 1.5574077247, + strcat(str(tnum++), + ': round(tan(0.2, 1e-10), 10) == 1.5574077247')); + vrfy(round(tan(pi/6, 1e-10), 10) == 0.5773502692, + strcat(str(tnum++), + ': round(tan(pi/6, 1e-10), 10) == 0.5773502692')); + vrfy(round(tan(pi/3, 1e-10), 10) == 1.7320508076, + strcat(str(tnum++), + ': round(tan(pi/3, 1e-10), 10) == 1.7320508076')); + vrfy(tan(pi, 1e-10) == 0, + strcat(str(tnum++), ': tan(pi, 1e-10) == 0')); + vrfy(round(tan(1/2, 1e-10), 10) == 0.5463024898, + strcat(str(tnum++), + ': round(tan(1/2, 1e-10), 10) == 0.5463024898')); + vrfy(round(tan(5/7, 1e-10), 10) == 0.8670082185, + strcat(str(tnum++), + ': round(tan(5/7, 1e-10), 10) == 0.8670082185')); + vrfy(round(tan(42/7, 1e-10), 10) == -0.2910061914, + strcat(str(tnum++), + ': round(tan(42/7, 1e-10), 10) == -0.2910061914')); - /* test trigonometric cotangent */ - vrfy(round(cot(1, 1e-10), 10) == 0.6420926159, - strcat(str(tnum++), - ': round(cot(0.2, 1e-10), 10) == 0.6420926159')); - vrfy(round(cot(pi/12, 1e-10), 10) == 3.7320508076, - strcat(str(tnum++), - ': round(cot(pi/12, 1e-10), 10) == 3.7320508076')); - vrfy(round(cot(pi/6, 1e-10), 10) == 1.7320508076, - strcat(str(tnum++), - ': round(cot(pi/6, 1e-10), 10) == 1.7320508076')); - vrfy(round(cot(pi/3, 1e-10), 10) == 0.5773502692, - strcat(str(tnum++), - ': round(cot(pi/3, 1e-10), 10) == 0.5773502692')); - vrfy(cot(pi/2, 1e-10) == 0, - strcat(str(tnum++), ': cot(pi/2, 1e-10) == 0')); - vrfy(round(cot(1/2, 1e-10), 10) == 1.8304877217, - strcat(str(tnum++), - ': round(cot(1/2, 1e-10), 10) == 1.8304877217')); - vrfy(round(cot(5/7, 1e-10), 10) == 1.1533916042, - strcat(str(tnum++), - ': round(cot(5/7, 1e-10), 10) == 1.1533916042')); - vrfy(round(cot(42/7, 1e-10), 10) == -3.4363530042, - strcat(str(tnum++), - ': round(cot(42/7, 1e-10), 10) == -3.4363530042')); + /* test trigonometric cotangent */ + vrfy(round(cot(1, 1e-10), 10) == 0.6420926159, + strcat(str(tnum++), + ': round(cot(0.2, 1e-10), 10) == 0.6420926159')); + vrfy(round(cot(pi/12, 1e-10), 10) == 3.7320508076, + strcat(str(tnum++), + ': round(cot(pi/12, 1e-10), 10) == 3.7320508076')); + vrfy(round(cot(pi/6, 1e-10), 10) == 1.7320508076, + strcat(str(tnum++), + ': round(cot(pi/6, 1e-10), 10) == 1.7320508076')); + vrfy(round(cot(pi/3, 1e-10), 10) == 0.5773502692, + strcat(str(tnum++), + ': round(cot(pi/3, 1e-10), 10) == 0.5773502692')); + vrfy(cot(pi/2, 1e-10) == 0, + strcat(str(tnum++), ': cot(pi/2, 1e-10) == 0')); + vrfy(round(cot(1/2, 1e-10), 10) == 1.8304877217, + strcat(str(tnum++), + ': round(cot(1/2, 1e-10), 10) == 1.8304877217')); + vrfy(round(cot(5/7, 1e-10), 10) == 1.1533916042, + strcat(str(tnum++), + ': round(cot(5/7, 1e-10), 10) == 1.1533916042')); + vrfy(round(cot(42/7, 1e-10), 10) == -3.4363530042, + strcat(str(tnum++), + ': round(cot(42/7, 1e-10), 10) == -3.4363530042')); - /* test trigonometric cosecant */ - vrfy(round(csc(1, 1e-10), 10) == 1.1883951058, - strcat(str(tnum++), - ': round(csc(0.2, 1e-10), 10) == 1.1883951058')); - vrfy(csc(pi/6, 1e-10) == 2, - strcat(str(tnum++), ': csc(pi/6, 1e-10) == 2')); - vrfy(round(csc(pi/3, 1e-10), 10) == 1.1547005384, - strcat(str(tnum++), - ': round(csc(pi/3, 1e-10), 10) == 1.1547005384')); - vrfy(round(csc(4*pi/3, 1e-10), 10) == -1.1547005384, - strcat(str(tnum++), - ': round(csc(4*pi/3, 1e-10), 10) == -1.1547005384')); - vrfy(round(csc(1/2, 1e-10), 10) == 2.0858296429, - strcat(str(tnum++), - ': round(csc(1/2, 1e-10), 10) == 2.0858296429')); - vrfy(round(csc(5/7, 1e-10), 10) == 1.5265360109, - strcat(str(tnum++), - ': round(csc(5/7, 1e-10), 10) == 1.5265360109')); - vrfy(round(csc(42/7, 1e-10), 10) == -3.5788995473, - strcat(str(tnum++), - ': round(csc(42/7, 1e-10), 10) == -3.5788995473')); + /* test trigonometric cosecant */ + vrfy(round(csc(1, 1e-10), 10) == 1.1883951058, + strcat(str(tnum++), + ': round(csc(0.2, 1e-10), 10) == 1.1883951058')); + vrfy(csc(pi/6, 1e-10) == 2, + strcat(str(tnum++), ': csc(pi/6, 1e-10) == 2')); + vrfy(round(csc(pi/3, 1e-10), 10) == 1.1547005384, + strcat(str(tnum++), + ': round(csc(pi/3, 1e-10), 10) == 1.1547005384')); + vrfy(round(csc(4*pi/3, 1e-10), 10) == -1.1547005384, + strcat(str(tnum++), + ': round(csc(4*pi/3, 1e-10), 10) == -1.1547005384')); + vrfy(round(csc(1/2, 1e-10), 10) == 2.0858296429, + strcat(str(tnum++), + ': round(csc(1/2, 1e-10), 10) == 2.0858296429')); + vrfy(round(csc(5/7, 1e-10), 10) == 1.5265360109, + strcat(str(tnum++), + ': round(csc(5/7, 1e-10), 10) == 1.5265360109')); + vrfy(round(csc(42/7, 1e-10), 10) == -3.5788995473, + strcat(str(tnum++), + ': round(csc(42/7, 1e-10), 10) == -3.5788995473')); - /* test trigonometric secant */ - vrfy(sec(0, 1e-10) == 1, - strcat(str(tnum++), ': sec(0, 1e-10) == 1')); - vrfy(round(sec(1, 1e-10), 10) == 1.8508157177, - strcat(str(tnum++), - ': round(sec(0.2, 1e-10), 10) == 1.8508157177')); - vrfy(round(sec(pi/6, 1e-10), 10) == 1.1547005384, - strcat(str(tnum++), - ': round(sec(pi/6, 1e-10), 10) == 1.1547005384')); - vrfy(sec(pi/3, 1e-10) == 2, - strcat(str(tnum++), ': sec(pi/2, 1e-10) == 2')); - vrfy(sec(pi, 1e-10) == -1, - strcat(str(tnum++), ': sec(pi, 1e-10) == -1')); - vrfy(round(sec(1/2, 1e-10), 10) == 1.1394939273, - strcat(str(tnum++), - ': round(sec(1/2, 1e-10), 10) == 1.1394939273')); - vrfy(round(sec(5/7, 1e-10), 10) == 1.3235192673, - strcat(str(tnum++), - ': round(sec(5/7, 1e-10), 10) == 1.3235192673')); - vrfy(round(sec(42/7, 1e-10), 10) == 1.0414819266, - strcat(str(tnum++), - ': round(sec(42/7, 1e-10), 10) == 1.0414819266')); + /* test trigonometric secant */ + vrfy(sec(0, 1e-10) == 1, + strcat(str(tnum++), ': sec(0, 1e-10) == 1')); + vrfy(round(sec(1, 1e-10), 10) == 1.8508157177, + strcat(str(tnum++), + ': round(sec(0.2, 1e-10), 10) == 1.8508157177')); + vrfy(round(sec(pi/6, 1e-10), 10) == 1.1547005384, + strcat(str(tnum++), + ': round(sec(pi/6, 1e-10), 10) == 1.1547005384')); + vrfy(sec(pi/3, 1e-10) == 2, + strcat(str(tnum++), ': sec(pi/2, 1e-10) == 2')); + vrfy(sec(pi, 1e-10) == -1, + strcat(str(tnum++), ': sec(pi, 1e-10) == -1')); + vrfy(round(sec(1/2, 1e-10), 10) == 1.1394939273, + strcat(str(tnum++), + ': round(sec(1/2, 1e-10), 10) == 1.1394939273')); + vrfy(round(sec(5/7, 1e-10), 10) == 1.3235192673, + strcat(str(tnum++), + ': round(sec(5/7, 1e-10), 10) == 1.3235192673')); + vrfy(round(sec(42/7, 1e-10), 10) == 1.0414819266, + strcat(str(tnum++), + ': round(sec(42/7, 1e-10), 10) == 1.0414819266')); - /* test versed trigonometric sine */ - vrfy(versin(0, 1e-10) == 0, - strcat(str(tnum++), ': versin(0, 1e-10) == 0')); - vrfy(round(versin(0.2, 1e-10), 10) == 0.0199334222, - strcat(str(tnum++), - ': round(versin(0.2, 1e-10), 10) == 0.0199334222')); - vrfy(round(versin(3/7, 1e-10), 10) == 0.0904396483, - strcat(str(tnum++), - ': round(versin(3/7, 1e-10), 10) == 0.0904396483')); - vrfy(round(versin(-31, 1e-10), 10) == 0.0852576422, - strcat(str(tnum++), - ': round(versin(-31, 1e-10), 10) == 0.0852576422')); - vrfy(versin(pi/3, 1e-10) == 0.5, - strcat(str(tnum++), ': versin(pi/3, 1e-10) == 0.5')); - vrfy(versin(pi/2, 1e-10) == 1, - strcat(str(tnum++), ': versin(pi/2, 1e-10) == 1')); - vrfy(versin(pi, 1e-10) == 2, - strcat(str(tnum++), ': versin(pi, 1e-10) == 2')); - vrfy(versin(3*pi/2, 1e-10) == 1, - strcat(str(tnum++), ': versin(3*pi/2, 1e-10) == 1')); - vrfy(round(versin(1, 1e-10), 10) == 0.4596976941, - strcat(str(tnum++), - ': round(versin(1, 1e-10), 10) == 0.4596976941')); - vrfy(round(versin(2 + 3i, 1e-10), 10) == 5.189625691+9.1092278938i, - strcat(str(tnum++), - ': round(versin(2 + 3i, 1e-10), 10) == 5.189625691+9.1092278938i')); + /* test versed trigonometric sine */ + vrfy(versin(0, 1e-10) == 0, + strcat(str(tnum++), ': versin(0, 1e-10) == 0')); + vrfy(round(versin(0.2, 1e-10), 10) == 0.0199334222, + strcat(str(tnum++), + ': round(versin(0.2, 1e-10), 10) == 0.0199334222')); + vrfy(round(versin(3/7, 1e-10), 10) == 0.0904396483, + strcat(str(tnum++), + ': round(versin(3/7, 1e-10), 10) == 0.0904396483')); + vrfy(round(versin(-31, 1e-10), 10) == 0.0852576422, + strcat(str(tnum++), + ': round(versin(-31, 1e-10), 10) == 0.0852576422')); + vrfy(versin(pi/3, 1e-10) == 0.5, + strcat(str(tnum++), ': versin(pi/3, 1e-10) == 0.5')); + vrfy(versin(pi/2, 1e-10) == 1, + strcat(str(tnum++), ': versin(pi/2, 1e-10) == 1')); + vrfy(versin(pi, 1e-10) == 2, + strcat(str(tnum++), ': versin(pi, 1e-10) == 2')); + vrfy(versin(3*pi/2, 1e-10) == 1, + strcat(str(tnum++), ': versin(3*pi/2, 1e-10) == 1')); + vrfy(round(versin(1, 1e-10), 10) == 0.4596976941, + strcat(str(tnum++), + ': round(versin(1, 1e-10), 10) == 0.4596976941')); + vrfy(round(versin(2 + 3i, 1e-10), 10) == 5.189625691+9.1092278938i, + strcat(str(tnum++), + ': round(versin(2 + 3i, 1e-10), 10) == 5.189625691+9.1092278938i')); - /* test inverse versed trigonometric sine */ - vrfy(aversin(0) == 0, - strcat(str(tnum++), ': aversin(0) == 0')); - vrfy(round(aversin(0.5, 1e-10), 10) == 1.0471975512, - strcat(str(tnum++), - ': round(aversin(0.5, 1e-10), 10) == 1.0471975512')); - vrfy(round(aversin(-5, 1e-10), 10) == 2.4778887303i, - strcat(str(tnum++), - ': round(aversin(-5, 1e-10), 10) == 2.4778887303i')); - vrfy(round(aversin(2 + 3i, 1e-10), 10) == 1.8783999763+1.8641615439i, - strcat(str(tnum++), - ': round(aversin(2 + 3i, 1e-10), 10) == 1.8783999763+1.8641615439i')); + /* test inverse versed trigonometric sine */ + vrfy(aversin(0) == 0, + strcat(str(tnum++), ': aversin(0) == 0')); + vrfy(round(aversin(0.5, 1e-10), 10) == 1.0471975512, + strcat(str(tnum++), + ': round(aversin(0.5, 1e-10), 10) == 1.0471975512')); + vrfy(round(aversin(-5, 1e-10), 10) == 2.4778887303i, + strcat(str(tnum++), + ': round(aversin(-5, 1e-10), 10) == 2.4778887303i')); + vrfy(round(aversin(2 + 3i, 1e-10), 10) == 1.8783999763+1.8641615439i, + strcat(str(tnum++), + ': round(aversin(2 + 3i, 1e-10), 10) == 1.8783999763+1.8641615439i')); - /* test coversed trigonometric sine */ - vrfy(coversin(0, 1e-10) == 1, - strcat(str(tnum++), ': coversin(0, 1e-10) == 1')); - vrfy(round(coversin(0.2, 1e-10), 10) == 0.8013306692, - strcat(str(tnum++), - ': round(coversin(0.2, 1e-10), 10) == 0.8013306692')); - vrfy(round(coversin(3/7, 1e-10), 10) == 0.584428145, - strcat(str(tnum++), - ': round(coversin(3/7, 1e-10), 10) == 0.584428145')); - vrfy(round(coversin(-31, 1e-10), 10) == 0.5959623547, - strcat(str(tnum++), - ': round(coversin(-31, 1e-10), 10) == 0.5959623547')); - vrfy(coversin(pi/6, 1e-10) == 0.5, - strcat(str(tnum++), ': coversin(pi/6, 1e-10) == 0.5')); - vrfy(coversin(pi/2, 1e-10) == 0, - strcat(str(tnum++), ': coversin(pi/2, 1e-10) == 0')); - vrfy(coversin(pi, 1e-10) == 1, - strcat(str(tnum++), ': coversin(pi, 1e-10) == 1')); - vrfy(coversin(3*pi/2, 1e-10) == 2, - strcat(str(tnum++), ': coversin(3*pi/2, 1e-10) == 2')); - vrfy(round(coversin(1, 1e-10), 10) == 0.1585290152, - strcat(str(tnum++), - ': round(coversin(1, 1e-10), 10) == 0.1585290152')); - vrfy(round(coversin(2 + 3i, 1e-10), 10) == -8.1544991469+4.16890696i, - strcat(str(tnum++), - ': round(coversin(2 + 3i, 1e-10), 10) == -8.1544991469+4.16890696i')); + /* test coversed trigonometric sine */ + vrfy(coversin(0, 1e-10) == 1, + strcat(str(tnum++), ': coversin(0, 1e-10) == 1')); + vrfy(round(coversin(0.2, 1e-10), 10) == 0.8013306692, + strcat(str(tnum++), + ': round(coversin(0.2, 1e-10), 10) == 0.8013306692')); + vrfy(round(coversin(3/7, 1e-10), 10) == 0.584428145, + strcat(str(tnum++), + ': round(coversin(3/7, 1e-10), 10) == 0.584428145')); + vrfy(round(coversin(-31, 1e-10), 10) == 0.5959623547, + strcat(str(tnum++), + ': round(coversin(-31, 1e-10), 10) == 0.5959623547')); + vrfy(coversin(pi/6, 1e-10) == 0.5, + strcat(str(tnum++), ': coversin(pi/6, 1e-10) == 0.5')); + vrfy(coversin(pi/2, 1e-10) == 0, + strcat(str(tnum++), ': coversin(pi/2, 1e-10) == 0')); + vrfy(coversin(pi, 1e-10) == 1, + strcat(str(tnum++), ': coversin(pi, 1e-10) == 1')); + vrfy(coversin(3*pi/2, 1e-10) == 2, + strcat(str(tnum++), ': coversin(3*pi/2, 1e-10) == 2')); + vrfy(round(coversin(1, 1e-10), 10) == 0.1585290152, + strcat(str(tnum++), + ': round(coversin(1, 1e-10), 10) == 0.1585290152')); + vrfy(round(coversin(2 + 3i, 1e-10), 10) == -8.1544991469+4.16890696i, + strcat(str(tnum++), + ': round(coversin(2 + 3i, 1e-10), 10) == -8.1544991469+4.16890696i')); - /* test inverse coversed trigonometric sine */ - vrfy(round(acoversin(0, 1e-10), 10) == 1.5707963268, - strcat(str(tnum++), - ': round(acoversin(0.5, 1e-10), 10) == 1.5707963268')); - vrfy(round(acoversin(0.5, 1e-10), 10) == 0.5235987756, - strcat(str(tnum++), - ': round(acoversin(0.5, 1e-10), 10) == 0.5235987756')); - vrfy(acoversin(1) == 0, - strcat(str(tnum++), ': acoversin(1) == 0')); - vrfy(round(acoversin(-5, 1e-10), 10) == 1.5707963268-2.4778887303i, - strcat(str(tnum++), - ': round(acoversin(-5, 1e-10), 10) == 1.5707963268-2.4778887303i')); - vrfy(round(acoversin(2 + 3i, 1e-10), 10) == -0.3076036495-1.8641615442i, - strcat(str(tnum++), - ': round(acoversin(2 + 3i, 1e-10), 10) == -0.3076036495-1.8641615442i')); + /* test inverse coversed trigonometric sine */ + vrfy(round(acoversin(0, 1e-10), 10) == 1.5707963268, + strcat(str(tnum++), + ': round(acoversin(0.5, 1e-10), 10) == 1.5707963268')); + vrfy(round(acoversin(0.5, 1e-10), 10) == 0.5235987756, + strcat(str(tnum++), + ': round(acoversin(0.5, 1e-10), 10) == 0.5235987756')); + vrfy(acoversin(1) == 0, + strcat(str(tnum++), ': acoversin(1) == 0')); + vrfy(round(acoversin(-5, 1e-10), 10) == 1.5707963268-2.4778887303i, + strcat(str(tnum++), + ': round(acoversin(-5, 1e-10), 10) == 1.5707963268-2.4778887303i')); + vrfy(round(acoversin(2 + 3i, 1e-10), 10) == -0.3076036495-1.8641615442i, + strcat(str(tnum++), + ': round(acoversin(2 + 3i, 1e-10), 10) == -0.3076036495-1.8641615442i')); - /* test versed trigonometric cosine */ - vrfy(vercos(0, 1e-10) == 2, - strcat(str(tnum++), ': vercos(0, 1e-10) == 2')); - vrfy(round(vercos(0.2, 1e-10), 10) == 1.9800665778, - strcat(str(tnum++), - ': round(vercos(0.2, 1e-10), 10) == 1.9800665778')); - vrfy(round(vercos(3/7, 1e-10), 10) == 1.9095603517, - strcat(str(tnum++), - ': round(vercos(3/7, 1e-10), 10) == 1.9095603517')); - vrfy(round(vercos(-31, 1e-10), 10) == 1.9147423578, - strcat(str(tnum++), - ': round(vercos(-31, 1e-10), 10) == 1.9147423578')); - vrfy(vercos(pi/3, 1e-10) == 1.5, - strcat(str(tnum++), ': vercos(pi/3, 1e-10) == 1.5')); - vrfy(vercos(pi/2, 1e-10) == 1, - strcat(str(tnum++), ': vercos(pi/2, 1e-10) == 1')); - vrfy(vercos(pi, 1e-10) == 0, - strcat(str(tnum++), ': vercos(pi, 1e-10) == 0')); - vrfy(vercos(3*pi/2, 1e-10) == 1, - strcat(str(tnum++), ': vercos(3*pi/2, 1e-10) == 1')); - vrfy(round(vercos(1, 1e-10), 10) == 1.5403023059, - strcat(str(tnum++), - ': round(vercos(1, 1e-10), 10) == 1.5403023059')); - vrfy(round(vercos(2 + 3i, 1e-10), 10) == -3.189625691-9.1092278938i, - strcat(str(tnum++), - ': round(vercos(2 + 3i, 1e-10), 10) == -3.189625691-9.1092278938i')); + /* test versed trigonometric cosine */ + vrfy(vercos(0, 1e-10) == 2, + strcat(str(tnum++), ': vercos(0, 1e-10) == 2')); + vrfy(round(vercos(0.2, 1e-10), 10) == 1.9800665778, + strcat(str(tnum++), + ': round(vercos(0.2, 1e-10), 10) == 1.9800665778')); + vrfy(round(vercos(3/7, 1e-10), 10) == 1.9095603517, + strcat(str(tnum++), + ': round(vercos(3/7, 1e-10), 10) == 1.9095603517')); + vrfy(round(vercos(-31, 1e-10), 10) == 1.9147423578, + strcat(str(tnum++), + ': round(vercos(-31, 1e-10), 10) == 1.9147423578')); + vrfy(vercos(pi/3, 1e-10) == 1.5, + strcat(str(tnum++), ': vercos(pi/3, 1e-10) == 1.5')); + vrfy(vercos(pi/2, 1e-10) == 1, + strcat(str(tnum++), ': vercos(pi/2, 1e-10) == 1')); + vrfy(vercos(pi, 1e-10) == 0, + strcat(str(tnum++), ': vercos(pi, 1e-10) == 0')); + vrfy(vercos(3*pi/2, 1e-10) == 1, + strcat(str(tnum++), ': vercos(3*pi/2, 1e-10) == 1')); + vrfy(round(vercos(1, 1e-10), 10) == 1.5403023059, + strcat(str(tnum++), + ': round(vercos(1, 1e-10), 10) == 1.5403023059')); + vrfy(round(vercos(2 + 3i, 1e-10), 10) == -3.189625691-9.1092278938i, + strcat(str(tnum++), + ': round(vercos(2 + 3i, 1e-10), 10) == -3.189625691-9.1092278938i')); - /* test inverse versed trigonometric cosine */ - vrfy(round(avercos(0, 1e-10), 10) == 3.1415926536, - strcat(str(tnum++), - ': round(avercos(0, 1e-10), 10) == 3.1415926536')); - vrfy(round(avercos(0.5, 1e-10), 10) == 2.0943951024, - strcat(str(tnum++), - ': round(avercos(0.5, 1e-10), 10) == 2.0943951024')); - vrfy(avercos(2) == 0, - strcat(str(tnum++), ': avercos(2) == 0')); - vrfy(round(avercos(-5, 1e-10), 10) == 3.1415926536-2.4778887303i, - strcat(str(tnum++), - ': round(avercos(-5, 1e-10), 10) == 3.1415926536-2.4778887303i')); - vrfy(round(avercos(2 + 3i, 1e-10), 10) == 1.2631926773-1.8641615442i, - strcat(str(tnum++), - ': round(avercos(2 + 3i, 1e-10), 10) == 1.2631926773-1.8641615442i')); + /* test inverse versed trigonometric cosine */ + vrfy(round(avercos(0, 1e-10), 10) == 3.1415926536, + strcat(str(tnum++), + ': round(avercos(0, 1e-10), 10) == 3.1415926536')); + vrfy(round(avercos(0.5, 1e-10), 10) == 2.0943951024, + strcat(str(tnum++), + ': round(avercos(0.5, 1e-10), 10) == 2.0943951024')); + vrfy(avercos(2) == 0, + strcat(str(tnum++), ': avercos(2) == 0')); + vrfy(round(avercos(-5, 1e-10), 10) == 3.1415926536-2.4778887303i, + strcat(str(tnum++), + ': round(avercos(-5, 1e-10), 10) == 3.1415926536-2.4778887303i')); + vrfy(round(avercos(2 + 3i, 1e-10), 10) == 1.2631926773-1.8641615442i, + strcat(str(tnum++), + ': round(avercos(2 + 3i, 1e-10), 10) == 1.2631926773-1.8641615442i')); - /* test coversed trigonometric cosine */ - vrfy(covercos(0, 1e-10) == 1, - strcat(str(tnum++), ': covercos(0, 1e-10) == 1')); - vrfy(round(covercos(0.2, 1e-10), 10) == 1.1986693308, - strcat(str(tnum++), - ': round(covercos(0.2, 1e-10), 10) == 1.1986693308')); - vrfy(round(covercos(3/7, 1e-10), 10) == 1.415571855, - strcat(str(tnum++), - ': round(covercos(3/7, 1e-10), 10) == 1.415571855')); - vrfy(round(covercos(-31, 1e-10), 10) == 1.4040376453, - strcat(str(tnum++), - ': round(covercos(-31, 1e-10), 10) == 1.4040376453')); - vrfy(covercos(pi/6, 1e-10) == 1.5, - strcat(str(tnum++), ': covercos(pi/6, 1e-10) == 1.5')); - vrfy(covercos(pi/2, 1e-10) == 2, - strcat(str(tnum++), ': covercos(pi/2, 1e-10) == 2')); - vrfy(covercos(pi, 1e-10) == 1, - strcat(str(tnum++), ': covercos(pi, 1e-10) == 1')); - vrfy(covercos(3*pi/2, 1e-10) == 0, - strcat(str(tnum++), ': covercos(3*pi/2, 1e-10) == 0')); - vrfy(round(covercos(1, 1e-10), 10) == 1.8414709848, - strcat(str(tnum++), - ': round(covercos(1, 1e-10), 10) == 1.8414709848')); - vrfy(round(covercos(2 + 3i, 1e-10), 10) == 10.1544991469-4.16890696i, - strcat(str(tnum++), - ': round(covercos(2 + 3i, 1e-10), 10) == 10.1544991469-4.16890696i')); + /* test coversed trigonometric cosine */ + vrfy(covercos(0, 1e-10) == 1, + strcat(str(tnum++), ': covercos(0, 1e-10) == 1')); + vrfy(round(covercos(0.2, 1e-10), 10) == 1.1986693308, + strcat(str(tnum++), + ': round(covercos(0.2, 1e-10), 10) == 1.1986693308')); + vrfy(round(covercos(3/7, 1e-10), 10) == 1.415571855, + strcat(str(tnum++), + ': round(covercos(3/7, 1e-10), 10) == 1.415571855')); + vrfy(round(covercos(-31, 1e-10), 10) == 1.4040376453, + strcat(str(tnum++), + ': round(covercos(-31, 1e-10), 10) == 1.4040376453')); + vrfy(covercos(pi/6, 1e-10) == 1.5, + strcat(str(tnum++), ': covercos(pi/6, 1e-10) == 1.5')); + vrfy(covercos(pi/2, 1e-10) == 2, + strcat(str(tnum++), ': covercos(pi/2, 1e-10) == 2')); + vrfy(covercos(pi, 1e-10) == 1, + strcat(str(tnum++), ': covercos(pi, 1e-10) == 1')); + vrfy(covercos(3*pi/2, 1e-10) == 0, + strcat(str(tnum++), ': covercos(3*pi/2, 1e-10) == 0')); + vrfy(round(covercos(1, 1e-10), 10) == 1.8414709848, + strcat(str(tnum++), + ': round(covercos(1, 1e-10), 10) == 1.8414709848')); + vrfy(round(covercos(2 + 3i, 1e-10), 10) == 10.1544991469-4.16890696i, + strcat(str(tnum++), + ': round(covercos(2 + 3i, 1e-10), 10) == 10.1544991469-4.16890696i')); - /* test inverse coversed trigonometric cosine */ - vrfy(round(acovercos(0, 1e-10), 10) == 1.5707963268, - strcat(str(tnum++), - ': round(acovercos(0, 1e-10), 10) == 1.5707963268')); - vrfy(round(acovercos(0.5, 1e-10), 10) == 0.5235987756, - strcat(str(tnum++), - ': round(acovercos(0.5, 1e-10), 10) == 0.5235987756')); - vrfy(acovercos(1) == 0, - strcat(str(tnum++), ': acovercos(1) == 0')); - vrfy(round(acovercos(-5, 1e-10), 10) == -1.5707963268+2.4778887303i, - strcat(str(tnum++), - ': round(acovercos(-5, 1e-10), 10) == -1.5707963268+2.4778887303i')); - vrfy(round(acovercos(2 + 3i, 1e-10), 10) == 0.3076036495+1.8641615442i, - strcat(str(tnum++), - ': round(acovercos(2 + 3i, 1e-10), 10) == 0.3076036495+1.8641615442i')); + /* test inverse coversed trigonometric cosine */ + vrfy(round(acovercos(0, 1e-10), 10) == 1.5707963268, + strcat(str(tnum++), + ': round(acovercos(0, 1e-10), 10) == 1.5707963268')); + vrfy(round(acovercos(0.5, 1e-10), 10) == 0.5235987756, + strcat(str(tnum++), + ': round(acovercos(0.5, 1e-10), 10) == 0.5235987756')); + vrfy(acovercos(1) == 0, + strcat(str(tnum++), ': acovercos(1) == 0')); + vrfy(round(acovercos(-5, 1e-10), 10) == -1.5707963268+2.4778887303i, + strcat(str(tnum++), + ': round(acovercos(-5, 1e-10), 10) == -1.5707963268+2.4778887303i')); + vrfy(round(acovercos(2 + 3i, 1e-10), 10) == 0.3076036495+1.8641615442i, + strcat(str(tnum++), + ': round(acovercos(2 + 3i, 1e-10), 10) == 0.3076036495+1.8641615442i')); - /* test half versed trigonometric sine */ - vrfy(haversin(0, 1e-10) == 0, - strcat(str(tnum++), ': haversin(0, 1e-10) == 0')); - vrfy(round(haversin(0.2, 1e-10), 10) == 0.0099667111, - strcat(str(tnum++), - ': round(haversin(0.2, 1e-10), 10) == 0.0099667111')); - vrfy(round(haversin(3/7, 1e-10), 10) == 0.0452198242, - strcat(str(tnum++), - ': round(haversin(3/7, 1e-10), 10) == 0.0452198242')); - vrfy(round(haversin(-31, 1e-10), 10) == 0.0426288211, - strcat(str(tnum++), - ': round(haversin(-31, 1e-10), 10) == 0.0426288211')); - vrfy(haversin(pi/3, 1e-10) == 0.25, - strcat(str(tnum++), ': haversin(pi/3, 1e-10) == 0.25')); - vrfy(haversin(pi/2, 1e-10) == 0.5, - strcat(str(tnum++), ': haversin(pi/2, 1e-10) == 0.5')); - vrfy(haversin(pi, 1e-10) == 1, - strcat(str(tnum++), ': haversin(pi, 1e-10) == 1')); - vrfy(haversin(3*pi/2, 1e-10) == 0.5, - strcat(str(tnum++), ': haversin(3*pi/2, 1e-10) == 0.5')); - vrfy(round(haversin(1, 1e-10), 10) == 0.229848847, - strcat(str(tnum++), - ': round(haversin(1, 1e-10), 10) == 0.229848847')); - vrfy(round(haversin(2 + 3i, 1e-10), 10) == 2.5948128455+4.5546139469i, - strcat(str(tnum++), - ': round(haversin(2 + 3i, 1e-10), 10) == 2.5948128455+4.5546139469i')); + /* test half versed trigonometric sine */ + vrfy(haversin(0, 1e-10) == 0, + strcat(str(tnum++), ': haversin(0, 1e-10) == 0')); + vrfy(round(haversin(0.2, 1e-10), 10) == 0.0099667111, + strcat(str(tnum++), + ': round(haversin(0.2, 1e-10), 10) == 0.0099667111')); + vrfy(round(haversin(3/7, 1e-10), 10) == 0.0452198242, + strcat(str(tnum++), + ': round(haversin(3/7, 1e-10), 10) == 0.0452198242')); + vrfy(round(haversin(-31, 1e-10), 10) == 0.0426288211, + strcat(str(tnum++), + ': round(haversin(-31, 1e-10), 10) == 0.0426288211')); + vrfy(haversin(pi/3, 1e-10) == 0.25, + strcat(str(tnum++), ': haversin(pi/3, 1e-10) == 0.25')); + vrfy(haversin(pi/2, 1e-10) == 0.5, + strcat(str(tnum++), ': haversin(pi/2, 1e-10) == 0.5')); + vrfy(haversin(pi, 1e-10) == 1, + strcat(str(tnum++), ': haversin(pi, 1e-10) == 1')); + vrfy(haversin(3*pi/2, 1e-10) == 0.5, + strcat(str(tnum++), ': haversin(3*pi/2, 1e-10) == 0.5')); + vrfy(round(haversin(1, 1e-10), 10) == 0.229848847, + strcat(str(tnum++), + ': round(haversin(1, 1e-10), 10) == 0.229848847')); + vrfy(round(haversin(2 + 3i, 1e-10), 10) == 2.5948128455+4.5546139469i, + strcat(str(tnum++), + ': round(haversin(2 + 3i, 1e-10), 10) == 2.5948128455+4.5546139469i')); - /* test inverse half versed trigonometric sine */ - vrfy(ahaversin(0, 1e-10) == 0, - strcat(str(tnum++), ': ahaversin(0, 1e-10) == 0')); - vrfy(round(ahaversin(0.5, 1e-10), 10) == 1.5707963268, - strcat(str(tnum++), - ': round(ahaversin(0.5, 1e-10), 10) == 1.5707963268')); - vrfy(round(ahaversin(1, 1e-10), 10) == 3.1415926536, - strcat(str(tnum++), - ': round(ahaversin(1, 1e-10), 10) == 3.1415926536')); - vrfy(round(ahaversin(-5, 1e-10), 10) == 3.0889699048i, - strcat(str(tnum++), - ': round(ahaversin(-5, 1e-10), 10) == 3.0889699048i')); - vrfy(round(ahaversin(2 + 3i, 1e-10), 10) == 2.03004373+2.5998241933i, - strcat(str(tnum++), - ': round(ahaversin(2 + 3i, 1e-10), 10) == 2.03004373+2.5998241933i')); + /* test inverse half versed trigonometric sine */ + vrfy(ahaversin(0, 1e-10) == 0, + strcat(str(tnum++), ': ahaversin(0, 1e-10) == 0')); + vrfy(round(ahaversin(0.5, 1e-10), 10) == 1.5707963268, + strcat(str(tnum++), + ': round(ahaversin(0.5, 1e-10), 10) == 1.5707963268')); + vrfy(round(ahaversin(1, 1e-10), 10) == 3.1415926536, + strcat(str(tnum++), + ': round(ahaversin(1, 1e-10), 10) == 3.1415926536')); + vrfy(round(ahaversin(-5, 1e-10), 10) == 3.0889699048i, + strcat(str(tnum++), + ': round(ahaversin(-5, 1e-10), 10) == 3.0889699048i')); + vrfy(round(ahaversin(2 + 3i, 1e-10), 10) == 2.03004373+2.5998241933i, + strcat(str(tnum++), + ': round(ahaversin(2 + 3i, 1e-10), 10) == 2.03004373+2.5998241933i')); - /* test half coversed trigonometric sine */ - vrfy(hacoversin(0, 1e-10) == 0.5, - strcat(str(tnum++), ': hacoversin(0, 1e-10) == 0.5')); - vrfy(round(hacoversin(0.2, 1e-10), 10) == 0.4006653346, - strcat(str(tnum++), - ': round(hacoversin(0.2, 1e-10), 10) == 0.4006653346')); - vrfy(round(hacoversin(3/7, 1e-10), 10) == 0.2922140725, - strcat(str(tnum++), - ': round(hacoversin(3/7, 1e-10), 10) == 0.2922140725')); - vrfy(round(hacoversin(-31, 1e-10), 10) == 0.2979811774, - strcat(str(tnum++), - ': round(hacoversin(-31, 1e-10), 10) == 0.2979811774')); - vrfy(hacoversin(pi/6, 1e-10) == 0.25, - strcat(str(tnum++), ': hacoversin(pi/6, 1e-10) == 0.25')); - vrfy(hacoversin(pi/2, 1e-10) == 0, - strcat(str(tnum++), ': hacoversin(pi/2, 1e-10) == 0')); - vrfy(hacoversin(pi, 1e-10) == 0.5, - strcat(str(tnum++), ': hacoversin(pi, 1e-10) == 0.5')); - vrfy(hacoversin(3*pi/2, 1e-10) == 1, - strcat(str(tnum++), ': hacoversin(3*pi/2, 1e-10) == 1')); - vrfy(round(hacoversin(1, 1e-10), 10) == 0.0792645076, - strcat(str(tnum++), - ': round(hacoversin(1, 1e-10), 10) == 0.0792645076')); - vrfy(round(hacoversin(2 + 3i, 1e-10), 10) == -4.0772495734+2.08445348i, - strcat(str(tnum++), - ': round(hacoversin(2 + 3i, 1e-10), 10) == -4.0772495734+2.08445348i')); + /* test half coversed trigonometric sine */ + vrfy(hacoversin(0, 1e-10) == 0.5, + strcat(str(tnum++), ': hacoversin(0, 1e-10) == 0.5')); + vrfy(round(hacoversin(0.2, 1e-10), 10) == 0.4006653346, + strcat(str(tnum++), + ': round(hacoversin(0.2, 1e-10), 10) == 0.4006653346')); + vrfy(round(hacoversin(3/7, 1e-10), 10) == 0.2922140725, + strcat(str(tnum++), + ': round(hacoversin(3/7, 1e-10), 10) == 0.2922140725')); + vrfy(round(hacoversin(-31, 1e-10), 10) == 0.2979811774, + strcat(str(tnum++), + ': round(hacoversin(-31, 1e-10), 10) == 0.2979811774')); + vrfy(hacoversin(pi/6, 1e-10) == 0.25, + strcat(str(tnum++), ': hacoversin(pi/6, 1e-10) == 0.25')); + vrfy(hacoversin(pi/2, 1e-10) == 0, + strcat(str(tnum++), ': hacoversin(pi/2, 1e-10) == 0')); + vrfy(hacoversin(pi, 1e-10) == 0.5, + strcat(str(tnum++), ': hacoversin(pi, 1e-10) == 0.5')); + vrfy(hacoversin(3*pi/2, 1e-10) == 1, + strcat(str(tnum++), ': hacoversin(3*pi/2, 1e-10) == 1')); + vrfy(round(hacoversin(1, 1e-10), 10) == 0.0792645076, + strcat(str(tnum++), + ': round(hacoversin(1, 1e-10), 10) == 0.0792645076')); + vrfy(round(hacoversin(2 + 3i, 1e-10), 10) == -4.0772495734+2.08445348i, + strcat(str(tnum++), + ': round(hacoversin(2 + 3i, 1e-10), 10) == -4.0772495734+2.08445348i')); - /* test inverse half coversed trigonometric sine */ - vrfy(ahacoversin(1, 1e-10) == 0, - strcat(str(tnum++), ': ahacoversin(1, 1e-10) == 0')); - vrfy(round(ahacoversin(0.5, 1e-10), 10) == 0.5235987756, - strcat(str(tnum++), - ': round(ahacoversin(0.5, 1e-10), 10) == 0.5235987756')); - vrfy(round(ahacoversin(0, 1e-10), 10) == 1.5707963268, - strcat(str(tnum++), - ': round(ahacoversin(0, 1e-10), 10) == 1.5707963268')); - vrfy(round(ahacoversin(-5, 1e-10), 10) == 1.5707963268-3.0889699048i, - strcat(str(tnum++), - ': round(ahacoversin(-5, 1e-10), 10) == 1.5707963268-3.0889699048i')); - vrfy(round(ahacoversin(2 + 3i, 1e-10), 10) == -0.4592474035-2.5998241938i, - strcat(str(tnum++), - ': round(ahacoversin(2 + 3i, 1e-10), 10) == -0.4592474035-2.5998241938i')); + /* test inverse half coversed trigonometric sine */ + vrfy(ahacoversin(1, 1e-10) == 0, + strcat(str(tnum++), ': ahacoversin(1, 1e-10) == 0')); + vrfy(round(ahacoversin(0.5, 1e-10), 10) == 0.5235987756, + strcat(str(tnum++), + ': round(ahacoversin(0.5, 1e-10), 10) == 0.5235987756')); + vrfy(round(ahacoversin(0, 1e-10), 10) == 1.5707963268, + strcat(str(tnum++), + ': round(ahacoversin(0, 1e-10), 10) == 1.5707963268')); + vrfy(round(ahacoversin(-5, 1e-10), 10) == 1.5707963268-3.0889699048i, + strcat(str(tnum++), + ': round(ahacoversin(-5, 1e-10), 10) == 1.5707963268-3.0889699048i')); + vrfy(round(ahacoversin(2 + 3i, 1e-10), 10) == -0.4592474035-2.5998241938i, + strcat(str(tnum++), + ': round(ahacoversin(2 + 3i, 1e-10), 10) == -0.4592474035-2.5998241938i')); - /* test half versed trigonometric cosine */ - vrfy(havercos(0, 1e-10) == 1, - strcat(str(tnum++), ': havercos(0, 1e-10) == 1')); - vrfy(round(havercos(0.2, 1e-10), 10) == 0.9900332889, - strcat(str(tnum++), - ': round(havercos(0.2, 1e-10), 10) == 0.9900332889')); - vrfy(round(havercos(3/7, 1e-10), 10) == 0.9547801758, - strcat(str(tnum++), - ': round(havercos(3/7, 1e-10), 10) == 0.9547801758')); - vrfy(round(havercos(-31, 1e-10), 10) == 0.9573711789, - strcat(str(tnum++), - ': round(havercos(-31, 1e-10), 10) == 0.9573711789')); - vrfy(havercos(pi/3, 1e-10) == 0.75, - strcat(str(tnum++), ': havercos(pi/3, 1e-10) == 0.75')); - vrfy(havercos(pi/2, 1e-10) == 0.5, - strcat(str(tnum++), ': havercos(pi/2, 1e-10) == 0.5')); - vrfy(havercos(pi, 1e-10) == 0, - strcat(str(tnum++), ': havercos(pi, 1e-10) == 0')); - vrfy(havercos(3*pi/2, 1e-10) == 0.5, - strcat(str(tnum++), ': havercos(3*pi/2, 1e-10) == 0.5')); - vrfy(round(havercos(1, 1e-10), 10) == 0.770151153, - strcat(str(tnum++), - ': round(havercos(1, 1e-10), 10) == 0.770151153')); - vrfy(round(havercos(2 + 3i, 1e-10), 10) == -1.5948128455-4.5546139469i, - strcat(str(tnum++), - ': round(havercos(2 + 3i, 1e-10), 10) == -1.5948128455-4.5546139469i')); + /* test half versed trigonometric cosine */ + vrfy(havercos(0, 1e-10) == 1, + strcat(str(tnum++), ': havercos(0, 1e-10) == 1')); + vrfy(round(havercos(0.2, 1e-10), 10) == 0.9900332889, + strcat(str(tnum++), + ': round(havercos(0.2, 1e-10), 10) == 0.9900332889')); + vrfy(round(havercos(3/7, 1e-10), 10) == 0.9547801758, + strcat(str(tnum++), + ': round(havercos(3/7, 1e-10), 10) == 0.9547801758')); + vrfy(round(havercos(-31, 1e-10), 10) == 0.9573711789, + strcat(str(tnum++), + ': round(havercos(-31, 1e-10), 10) == 0.9573711789')); + vrfy(havercos(pi/3, 1e-10) == 0.75, + strcat(str(tnum++), ': havercos(pi/3, 1e-10) == 0.75')); + vrfy(havercos(pi/2, 1e-10) == 0.5, + strcat(str(tnum++), ': havercos(pi/2, 1e-10) == 0.5')); + vrfy(havercos(pi, 1e-10) == 0, + strcat(str(tnum++), ': havercos(pi, 1e-10) == 0')); + vrfy(havercos(3*pi/2, 1e-10) == 0.5, + strcat(str(tnum++), ': havercos(3*pi/2, 1e-10) == 0.5')); + vrfy(round(havercos(1, 1e-10), 10) == 0.770151153, + strcat(str(tnum++), + ': round(havercos(1, 1e-10), 10) == 0.770151153')); + vrfy(round(havercos(2 + 3i, 1e-10), 10) == -1.5948128455-4.5546139469i, + strcat(str(tnum++), + ': round(havercos(2 + 3i, 1e-10), 10) == -1.5948128455-4.5546139469i')); - /* test inverse half versed trigonometric cosine */ - vrfy(ahavercos(0, 1e-10) == 0, - strcat(str(tnum++), ': ahavercos(0, 1e-10) == 0')); - vrfy(round(ahavercos(0.5, 1e-10), 10) == 1.5707963268, - strcat(str(tnum++), - ': round(ahavercos(0.5, 1e-10), 10) == 1.5707963268')); - vrfy(round(ahavercos(1, 1e-10), 10) == 3.1415926536, - strcat(str(tnum++), - ': round(ahavercos(1, 1e-10), 10) == 3.1415926536')); - vrfy(round(ahavercos(-5, 1e-10), 10) == 3.0889699048i, - strcat(str(tnum++), - ': round(ahavercos(-5, 1e-10), 10) == 3.0889699048i')); - vrfy(round(ahavercos(2 + 3i, 1e-10), 10) == 2.03004373+2.5998241933i, - strcat(str(tnum++), - ': round(ahavercos(2 + 3i, 1e-10), 10) == 2.03004373+2.5998241933i')); + /* test inverse half versed trigonometric cosine */ + vrfy(ahavercos(0, 1e-10) == 0, + strcat(str(tnum++), ': ahavercos(0, 1e-10) == 0')); + vrfy(round(ahavercos(0.5, 1e-10), 10) == 1.5707963268, + strcat(str(tnum++), + ': round(ahavercos(0.5, 1e-10), 10) == 1.5707963268')); + vrfy(round(ahavercos(1, 1e-10), 10) == 3.1415926536, + strcat(str(tnum++), + ': round(ahavercos(1, 1e-10), 10) == 3.1415926536')); + vrfy(round(ahavercos(-5, 1e-10), 10) == 3.0889699048i, + strcat(str(tnum++), + ': round(ahavercos(-5, 1e-10), 10) == 3.0889699048i')); + vrfy(round(ahavercos(2 + 3i, 1e-10), 10) == 2.03004373+2.5998241933i, + strcat(str(tnum++), + ': round(ahavercos(2 + 3i, 1e-10), 10) == 2.03004373+2.5998241933i')); - /* test half coversed trigonometric cosine */ - vrfy(hacovercos(0, 1e-10) == 0.5, - strcat(str(tnum++), ': hacovercos(0, 1e-10) == 0.5')); - vrfy(round(hacovercos(0.2, 1e-10), 10) == 0.5993346654, - strcat(str(tnum++), - ': round(hacovercos(0.2, 1e-10), 10) == 0.5993346654')); - vrfy(round(hacovercos(3/7, 1e-10), 10) == 0.7077859275, - strcat(str(tnum++), - ': round(hacovercos(3/7, 1e-10), 10) == 0.7077859275')); - vrfy(round(hacovercos(-31, 1e-10), 10) == 0.7020188226, - strcat(str(tnum++), - ': round(hacovercos(-31, 1e-10), 10) == 0.7020188226')); - vrfy(hacovercos(pi/6, 1e-10) == 0.75, - strcat(str(tnum++), ': hacovercos(pi/6, 1e-10) == 0.75')); - vrfy(hacovercos(pi/2, 1e-10) == 1, - strcat(str(tnum++), ': hacovercos(pi/2, 1e-10) == 1')); - vrfy(hacovercos(pi, 1e-10) == 0.5, - strcat(str(tnum++), ': hacovercos(pi, 1e-10) == 0.5')); - vrfy(hacovercos(3*pi/2, 1e-10) == 0, - strcat(str(tnum++), ': hacovercos(3*pi/2, 1e-10) == 0')); - vrfy(round(hacovercos(1, 1e-10), 10) == 0.9207354924, - strcat(str(tnum++), - ': round(hacovercos(1, 1e-10), 10) == 0.9207354924')); - vrfy(round(hacovercos(2 + 3i, 1e-10), 10) == 5.0772495734-2.08445348i, - strcat(str(tnum++), - ': round(hacovercos(2 + 3i, 1e-10), 10) == 5.0772495734-2.08445348i')); + /* test half coversed trigonometric cosine */ + vrfy(hacovercos(0, 1e-10) == 0.5, + strcat(str(tnum++), ': hacovercos(0, 1e-10) == 0.5')); + vrfy(round(hacovercos(0.2, 1e-10), 10) == 0.5993346654, + strcat(str(tnum++), + ': round(hacovercos(0.2, 1e-10), 10) == 0.5993346654')); + vrfy(round(hacovercos(3/7, 1e-10), 10) == 0.7077859275, + strcat(str(tnum++), + ': round(hacovercos(3/7, 1e-10), 10) == 0.7077859275')); + vrfy(round(hacovercos(-31, 1e-10), 10) == 0.7020188226, + strcat(str(tnum++), + ': round(hacovercos(-31, 1e-10), 10) == 0.7020188226')); + vrfy(hacovercos(pi/6, 1e-10) == 0.75, + strcat(str(tnum++), ': hacovercos(pi/6, 1e-10) == 0.75')); + vrfy(hacovercos(pi/2, 1e-10) == 1, + strcat(str(tnum++), ': hacovercos(pi/2, 1e-10) == 1')); + vrfy(hacovercos(pi, 1e-10) == 0.5, + strcat(str(tnum++), ': hacovercos(pi, 1e-10) == 0.5')); + vrfy(hacovercos(3*pi/2, 1e-10) == 0, + strcat(str(tnum++), ': hacovercos(3*pi/2, 1e-10) == 0')); + vrfy(round(hacovercos(1, 1e-10), 10) == 0.9207354924, + strcat(str(tnum++), + ': round(hacovercos(1, 1e-10), 10) == 0.9207354924')); + vrfy(round(hacovercos(2 + 3i, 1e-10), 10) == 5.0772495734-2.08445348i, + strcat(str(tnum++), + ': round(hacovercos(2 + 3i, 1e-10), 10) == 5.0772495734-2.08445348i')); - /* test inverse half coversed trigonometric cosine */ - vrfy(ahacovercos(0, 1e-10) == 0, - strcat(str(tnum++), ': ahacovercos(0, 1e-10) == 0')); - vrfy(round(ahacovercos(0.5, 1e-10), 10) == 1.0471975512, - strcat(str(tnum++), - ': round(ahacovercos(0.5, 1e-10), 10) == 1.0471975512')); - vrfy(round(ahacovercos(1, 1e-10), 10) == 1.5707963268, - strcat(str(tnum++), - ': round(ahacovercos(1, 1e-10), 10) == 1.5707963268')); - vrfy(round(ahacovercos(-5, 1e-10), 10) == 1.5707963268-3.0889699048i, - strcat(str(tnum++), - ': round(ahacovercos(-5, 1e-10), 10) == 1.5707963268-3.0889699048i')); - vrfy(round(ahacovercos(2 + 3i, 1e-10), 10) == -0.4592474035-2.5998241938i, - strcat(str(tnum++), - ': round(ahacovercos(2 + 3i, 1e-10), 10) == -0.4592474035-2.5998241938i')); + /* test inverse half coversed trigonometric cosine */ + vrfy(ahacovercos(0, 1e-10) == 0, + strcat(str(tnum++), ': ahacovercos(0, 1e-10) == 0')); + vrfy(round(ahacovercos(0.5, 1e-10), 10) == 1.0471975512, + strcat(str(tnum++), + ': round(ahacovercos(0.5, 1e-10), 10) == 1.0471975512')); + vrfy(round(ahacovercos(1, 1e-10), 10) == 1.5707963268, + strcat(str(tnum++), + ': round(ahacovercos(1, 1e-10), 10) == 1.5707963268')); + vrfy(round(ahacovercos(-5, 1e-10), 10) == 1.5707963268-3.0889699048i, + strcat(str(tnum++), + ': round(ahacovercos(-5, 1e-10), 10) == 1.5707963268-3.0889699048i')); + vrfy(round(ahacovercos(2 + 3i, 1e-10), 10) == -0.4592474035-2.5998241938i, + strcat(str(tnum++), + ': round(ahacovercos(2 + 3i, 1e-10), 10) == -0.4592474035-2.5998241938i')); - /* test exterior trigonometric secant */ - vrfy(exsec(0, 1e-10) == 0, - strcat(str(tnum++), ': exsec(0, 1e-10) == 0')); - vrfy(round(exsec(0.2, 1e-10), 10) == 0.0203388449, - strcat(str(tnum++), - ': round(exsec(0.2, 1e-10), 10) == 0.0203388449')); - vrfy(round(exsec(3/7, 1e-10), 10) == 0.0994322676, - strcat(str(tnum++), - ': round(exsec(3/7, 1e-10), 10) == 0.0994322676')); - vrfy(round(exsec(-31, 1e-10), 10) == 0.0932039951, - strcat(str(tnum++), - ': round(exsec(-31, 1e-10), 10) == 0.0932039951')); - vrfy(exsec(pi/3, 1e-10) == 1, - strcat(str(tnum++), ': exsec(pi/3, 1e-10) == 1')); - vrfy(exsec(2*pi/3, 1e-10) == -3, - strcat(str(tnum++), ': exsec(2*pi/3, 1e-10) == -3')); - vrfy(exsec(pi, 1e-10) == -2, - strcat(str(tnum++), ': exsec(pi, 1e-10) == -2')); - vrfy(exsec(2*pi, 1e-10) == 0, - strcat(str(tnum++), ': exsec(2*pi, 1e-10) == 0')); - vrfy(round(exsec(1, 1e-10), 10) == 0.8508157177, - strcat(str(tnum++), - ': round(exsec(1, 1e-10), 10) == 0.8508157177')); - vrfy(round(exsec(2 + 3i, 1e-10), 10) == -1.0416749644+0.0906111372i, - strcat(str(tnum++), - ': round(exsec(2 + 3i, 1e-10), 10) == -1.0416749644+0.0906111372i')); + /* test exterior trigonometric secant */ + vrfy(exsec(0, 1e-10) == 0, + strcat(str(tnum++), ': exsec(0, 1e-10) == 0')); + vrfy(round(exsec(0.2, 1e-10), 10) == 0.0203388449, + strcat(str(tnum++), + ': round(exsec(0.2, 1e-10), 10) == 0.0203388449')); + vrfy(round(exsec(3/7, 1e-10), 10) == 0.0994322676, + strcat(str(tnum++), + ': round(exsec(3/7, 1e-10), 10) == 0.0994322676')); + vrfy(round(exsec(-31, 1e-10), 10) == 0.0932039951, + strcat(str(tnum++), + ': round(exsec(-31, 1e-10), 10) == 0.0932039951')); + vrfy(exsec(pi/3, 1e-10) == 1, + strcat(str(tnum++), ': exsec(pi/3, 1e-10) == 1')); + vrfy(exsec(2*pi/3, 1e-10) == -3, + strcat(str(tnum++), ': exsec(2*pi/3, 1e-10) == -3')); + vrfy(exsec(pi, 1e-10) == -2, + strcat(str(tnum++), ': exsec(pi, 1e-10) == -2')); + vrfy(exsec(2*pi, 1e-10) == 0, + strcat(str(tnum++), ': exsec(2*pi, 1e-10) == 0')); + vrfy(round(exsec(1, 1e-10), 10) == 0.8508157177, + strcat(str(tnum++), + ': round(exsec(1, 1e-10), 10) == 0.8508157177')); + vrfy(round(exsec(2 + 3i, 1e-10), 10) == -1.0416749644+0.0906111372i, + strcat(str(tnum++), + ': round(exsec(2 + 3i, 1e-10), 10) == -1.0416749644+0.0906111372i')); - /* test inverse exterior trigonometric secant */ - vrfy(aexsec(0, 1e-10) == 0, - strcat(str(tnum++), ': aexsec(0, 1e-10) == 0')); - vrfy(round(aexsec(0.2, 1e-10), 10) == 0.5856855435, - strcat(str(tnum++), - ': round(aexsec(0.2, 1e-10), 10) == 0.5856855435')); - vrfy(round(aexsec(3/7, 1e-10), 10) == 0.7953988302, - strcat(str(tnum++), - ': round(aexsec(3/7, 1e-10), 10) == 0.7953988302')); - vrfy(round(aexsec(-31, 1e-10), 10) == 1.6041358361, - strcat(str(tnum++), - ': round(aexsec(-31, 1e-10), 10) == 1.6041358361')); - vrfy(round(aexsec(1, 1e-10), 10) == 1.0471975512, - strcat(str(tnum++), - ': round(aexsec(1, 1e-10), 10) == 1.0471975512')); - vrfy(round(aexsec(2 + 3i, 1e-10), 10) == 1.4057101283+0.1681700706i, - strcat(str(tnum++), - ': round(aexsec(2 + 3i, 1e-10), 10) == 1.4057101283+0.1681700706i')); + /* test inverse exterior trigonometric secant */ + vrfy(aexsec(0, 1e-10) == 0, + strcat(str(tnum++), ': aexsec(0, 1e-10) == 0')); + vrfy(round(aexsec(0.2, 1e-10), 10) == 0.5856855435, + strcat(str(tnum++), + ': round(aexsec(0.2, 1e-10), 10) == 0.5856855435')); + vrfy(round(aexsec(3/7, 1e-10), 10) == 0.7953988302, + strcat(str(tnum++), + ': round(aexsec(3/7, 1e-10), 10) == 0.7953988302')); + vrfy(round(aexsec(-31, 1e-10), 10) == 1.6041358361, + strcat(str(tnum++), + ': round(aexsec(-31, 1e-10), 10) == 1.6041358361')); + vrfy(round(aexsec(1, 1e-10), 10) == 1.0471975512, + strcat(str(tnum++), + ': round(aexsec(1, 1e-10), 10) == 1.0471975512')); + vrfy(round(aexsec(2 + 3i, 1e-10), 10) == 1.4057101283+0.1681700706i, + strcat(str(tnum++), + ': round(aexsec(2 + 3i, 1e-10), 10) == 1.4057101283+0.1681700706i')); - /* test exterior trigonometric cosecant */ - vrfy(round(excsc(0.2, 1e-10), 10) == 4.0334895477, - strcat(str(tnum++), - ': round(excsc(0.2, 1e-10), 10) == 4.0334895477')); - vrfy(round(excsc(3/7, 1e-10), 10) == 1.4063227285, - strcat(str(tnum++), - ': round(excsc(3/7, 1e-10), 10) == 1.4063227285')); - vrfy(round(excsc(-31, 1e-10), 10) == 1.475016899, - strcat(str(tnum++), - ': round(excsc(-31, 1e-10), 10) == 1.475016899')); - vrfy(excsc(pi/6, 1e-10) == 1, - strcat(str(tnum++), ': excsc(pi/6, 1e-10) == 1')); - vrfy(excsc(pi/2, 1e-10) == 0, - strcat(str(tnum++), ': excsc(pi/2, 1e-10) == 0')); - vrfy(excsc(3*pi/2, 1e-10) == -2, - strcat(str(tnum++), ': excsc(3*pi/2, 1e-10) == -2')); - vrfy(round(excsc(1, 1e-10), 10) == 0.1883951058, - strcat(str(tnum++), - ': round(excsc(1, 1e-10), 10) == 0.1883951058')); - vrfy(round(excsc(2 + 3i, 1e-10), 10) == -0.9095267902+0.0412009863i, - strcat(str(tnum++), - ': round(excsc(2 + 3i, 1e-10), 10) == -0.9095267902+0.0412009863i')); + /* test exterior trigonometric cosecant */ + vrfy(round(excsc(0.2, 1e-10), 10) == 4.0334895477, + strcat(str(tnum++), + ': round(excsc(0.2, 1e-10), 10) == 4.0334895477')); + vrfy(round(excsc(3/7, 1e-10), 10) == 1.4063227285, + strcat(str(tnum++), + ': round(excsc(3/7, 1e-10), 10) == 1.4063227285')); + vrfy(round(excsc(-31, 1e-10), 10) == 1.475016899, + strcat(str(tnum++), + ': round(excsc(-31, 1e-10), 10) == 1.475016899')); + vrfy(excsc(pi/6, 1e-10) == 1, + strcat(str(tnum++), ': excsc(pi/6, 1e-10) == 1')); + vrfy(excsc(pi/2, 1e-10) == 0, + strcat(str(tnum++), ': excsc(pi/2, 1e-10) == 0')); + vrfy(excsc(3*pi/2, 1e-10) == -2, + strcat(str(tnum++), ': excsc(3*pi/2, 1e-10) == -2')); + vrfy(round(excsc(1, 1e-10), 10) == 0.1883951058, + strcat(str(tnum++), + ': round(excsc(1, 1e-10), 10) == 0.1883951058')); + vrfy(round(excsc(2 + 3i, 1e-10), 10) == -0.9095267902+0.0412009863i, + strcat(str(tnum++), + ': round(excsc(2 + 3i, 1e-10), 10) == -0.9095267902+0.0412009863i')); - /* test inverse exterior trigonometric cosecant */ - vrfy(round(aexcsc(0, 1e-10), 10) == 1.5707963268, - strcat(str(tnum++), - ': round(aexcsc(0, 1e-10), 10) == 1.5707963268')); - vrfy(round(aexcsc(0.2, 1e-10), 10) == 0.9851107833, - strcat(str(tnum++), - ': round(aexcsc(0.2, 1e-10), 10) == 0.9851107833')); - vrfy(round(aexcsc(3/7, 1e-10), 10) == 0.7753974966, - strcat(str(tnum++), - ': round(aexcsc(3/7, 1e-10), 10) == 0.7753974966')); - vrfy(round(aexcsc(-31, 1e-10), 10) == -0.0333395093, - strcat(str(tnum++), - ': round(aexcsc(-31, 1e-10), 10) == -0.0333395093')); - vrfy(round(aexcsc(1, 1e-10), 10) == 0.5235987756, - strcat(str(tnum++), - ': round(aexcsc(1, 1e-10), 10) == 0.5235987756')); - vrfy(round(aexcsc(2 + 3i, 1e-10), 10) == 0.1650861985-0.1681700706i, - strcat(str(tnum++), - ': round(aexcsc(2 + 3i, 1e-10), 10) == 0.1650861985-0.1681700706i')); + /* test inverse exterior trigonometric cosecant */ + vrfy(round(aexcsc(0, 1e-10), 10) == 1.5707963268, + strcat(str(tnum++), + ': round(aexcsc(0, 1e-10), 10) == 1.5707963268')); + vrfy(round(aexcsc(0.2, 1e-10), 10) == 0.9851107833, + strcat(str(tnum++), + ': round(aexcsc(0.2, 1e-10), 10) == 0.9851107833')); + vrfy(round(aexcsc(3/7, 1e-10), 10) == 0.7753974966, + strcat(str(tnum++), + ': round(aexcsc(3/7, 1e-10), 10) == 0.7753974966')); + vrfy(round(aexcsc(-31, 1e-10), 10) == -0.0333395093, + strcat(str(tnum++), + ': round(aexcsc(-31, 1e-10), 10) == -0.0333395093')); + vrfy(round(aexcsc(1, 1e-10), 10) == 0.5235987756, + strcat(str(tnum++), + ': round(aexcsc(1, 1e-10), 10) == 0.5235987756')); + vrfy(round(aexcsc(2 + 3i, 1e-10), 10) == 0.1650861985-0.1681700706i, + strcat(str(tnum++), + ': round(aexcsc(2 + 3i, 1e-10), 10) == 0.1650861985-0.1681700706i')); - /* test trigonometric chord of a unit circle */ - vrfy(crd(0, 1e-10) == 0, - strcat(str(tnum++), ': crd(0, 1e-10) == 0')); - vrfy(round(crd(0.2, 1e-10), 10) == 0.1996668332, - strcat(str(tnum++), - ': round(crd(0.2, 1e-10), 10) == 0.1996668332')); - vrfy(round(crd(3/7, 1e-10), 10) == 0.4252990674, - strcat(str(tnum++), - ': round(crd(3/7, 1e-10), 10) == 0.4252990674')); - vrfy(round(crd(-31, 1e-10), 10) == -0.4129349638, - strcat(str(tnum++), - ': round(crd(-31, 1e-10), 10) == -0.4129349638')); - vrfy(crd(pi/3, 1e-10) == 1, - strcat(str(tnum++), ': crd(pi/3, 1e-10) == 1')); - vrfy(crd(pi, 1e-10) == 2, - strcat(str(tnum++), ': crd(pi, 1e-10) == 2')); - vrfy(crd(5*pi/3, 1e-10) == 1, - strcat(str(tnum++), ': crd(5*pi/3, 1e-10) == 1')); - vrfy(round(crd(1, 1e-10), 10) == 0.9588510772, - strcat(str(tnum++), - ': round(crd(1, 1e-10), 10) == 0.9588510772')); - vrfy(round(crd(2 + 3i, 1e-10), 10) == 3.9589688712+2.3009091988i, - strcat(str(tnum++), - ': round(crd(2 + 3i, 1e-10), 10) == 3.9589688712+2.3009091988i')); + /* test trigonometric chord of a unit circle */ + vrfy(crd(0, 1e-10) == 0, + strcat(str(tnum++), ': crd(0, 1e-10) == 0')); + vrfy(round(crd(0.2, 1e-10), 10) == 0.1996668332, + strcat(str(tnum++), + ': round(crd(0.2, 1e-10), 10) == 0.1996668332')); + vrfy(round(crd(3/7, 1e-10), 10) == 0.4252990674, + strcat(str(tnum++), + ': round(crd(3/7, 1e-10), 10) == 0.4252990674')); + vrfy(round(crd(-31, 1e-10), 10) == -0.4129349638, + strcat(str(tnum++), + ': round(crd(-31, 1e-10), 10) == -0.4129349638')); + vrfy(crd(pi/3, 1e-10) == 1, + strcat(str(tnum++), ': crd(pi/3, 1e-10) == 1')); + vrfy(crd(pi, 1e-10) == 2, + strcat(str(tnum++), ': crd(pi, 1e-10) == 2')); + vrfy(crd(5*pi/3, 1e-10) == 1, + strcat(str(tnum++), ': crd(5*pi/3, 1e-10) == 1')); + vrfy(round(crd(1, 1e-10), 10) == 0.9588510772, + strcat(str(tnum++), + ': round(crd(1, 1e-10), 10) == 0.9588510772')); + vrfy(round(crd(2 + 3i, 1e-10), 10) == 3.9589688712+2.3009091988i, + strcat(str(tnum++), + ': round(crd(2 + 3i, 1e-10), 10) == 3.9589688712+2.3009091988i')); - /* test inverse trigonometric chord of a unit circle */ - vrfy(acrd(0, 1e-10) == 0, - strcat(str(tnum++), ': acrd(0, 1e-10) == 0')); - vrfy(round(acrd(0.2, 1e-10), 10) == 0.2003348424, - strcat(str(tnum++), - ': round(acrd(0.2, 1e-10), 10) == 0.2003348424')); - vrfy(round(acrd(3/7, 1e-10), 10) == 0.4319209974, - strcat(str(tnum++), - ': round(acrd(3/7, 1e-10), 10) == 0.4319209974')); - vrfy(round(acrd(-31, 1e-10), 10) == -3.1415926536+6.8658899902i, - strcat(str(tnum++), - ': round(acrd(-31, 1e-10), 10) == -3.1415926536+6.8658899902i')); - vrfy(round(acrd(1, 1e-10), 10) == 1.0471975512, - strcat(str(tnum++), - ': round(acrd(1, 1e-10), 10) == 1.0471975512')); - vrfy(round(acrd(2 + 3i, 1e-10), 10) == 1.0471975512+2.6339157938i, - strcat(str(tnum++), - ': round(acrd(2 + 3i, 1e-10), 10) == 1.0471975512+2.6339157938i')); + /* test inverse trigonometric chord of a unit circle */ + vrfy(acrd(0, 1e-10) == 0, + strcat(str(tnum++), ': acrd(0, 1e-10) == 0')); + vrfy(round(acrd(0.2, 1e-10), 10) == 0.2003348424, + strcat(str(tnum++), + ': round(acrd(0.2, 1e-10), 10) == 0.2003348424')); + vrfy(round(acrd(3/7, 1e-10), 10) == 0.4319209974, + strcat(str(tnum++), + ': round(acrd(3/7, 1e-10), 10) == 0.4319209974')); + vrfy(round(acrd(-31, 1e-10), 10) == -3.1415926536+6.8658899902i, + strcat(str(tnum++), + ': round(acrd(-31, 1e-10), 10) == -3.1415926536+6.8658899902i')); + vrfy(round(acrd(1, 1e-10), 10) == 1.0471975512, + strcat(str(tnum++), + ': round(acrd(1, 1e-10), 10) == 1.0471975512')); + vrfy(round(acrd(2 + 3i, 1e-10), 10) == 1.0471975512+2.6339157938i, + strcat(str(tnum++), + ': round(acrd(2 + 3i, 1e-10), 10) == 1.0471975512+2.6339157938i')); - /* test cosine plus sine */ - vrfy(cas(0, 1e-10) == 1, - strcat(str(tnum++), ': cas(0, 1e-10) == 1')); - vrfy(round(cas(0.2, 1e-10), 10) == 1.1787359086, - strcat(str(tnum++), - ': round(cas(0.2, 1e-10), 10) == 1.1787359086')); - vrfy(round(cas(3/7, 1e-10), 10) == 1.3251322067, - strcat(str(tnum++), - ': round(cas(3/7, 1e-10), 10) == 1.3251322067')); - vrfy(round(cas(-31, 1e-10), 10) == 1.3187800031, - strcat(str(tnum++), - ': round(cas(-31, 1e-10), 10) == 1.3187800031')); - vrfy(cas(pi/2, 1e-10) == 1, - strcat(str(tnum++), ': cas(pi/2, 1e-10) == 1')); - vrfy(cas(pi, 1e-10) == -1, - strcat(str(tnum++), ': cas(pi, 1e-10) == -1')); - vrfy(cas(3*pi/2, 1e-10) == -1, - strcat(str(tnum++), ': cas(3*pi/2, 1e-10) == -1')); - vrfy(round(cas(1, 1e-10), 10) == 1.3817732907, - strcat(str(tnum++), - ': round(cas(1, 1e-10), 10) == 1.3817732907')); - vrfy(round(cas(2 + 3i, 1e-10), 10) == 4.9648734559-13.2781348538i, - strcat(str(tnum++), - ': round(cas(2 + 3i, 1e-10), 10) == 4.9648734559-13.2781348538i')); + /* test cosine plus sine */ + vrfy(cas(0, 1e-10) == 1, + strcat(str(tnum++), ': cas(0, 1e-10) == 1')); + vrfy(round(cas(0.2, 1e-10), 10) == 1.1787359086, + strcat(str(tnum++), + ': round(cas(0.2, 1e-10), 10) == 1.1787359086')); + vrfy(round(cas(3/7, 1e-10), 10) == 1.3251322067, + strcat(str(tnum++), + ': round(cas(3/7, 1e-10), 10) == 1.3251322067')); + vrfy(round(cas(-31, 1e-10), 10) == 1.3187800031, + strcat(str(tnum++), + ': round(cas(-31, 1e-10), 10) == 1.3187800031')); + vrfy(cas(pi/2, 1e-10) == 1, + strcat(str(tnum++), ': cas(pi/2, 1e-10) == 1')); + vrfy(cas(pi, 1e-10) == -1, + strcat(str(tnum++), ': cas(pi, 1e-10) == -1')); + vrfy(cas(3*pi/2, 1e-10) == -1, + strcat(str(tnum++), ': cas(3*pi/2, 1e-10) == -1')); + vrfy(round(cas(1, 1e-10), 10) == 1.3817732907, + strcat(str(tnum++), + ': round(cas(1, 1e-10), 10) == 1.3817732907')); + vrfy(round(cas(2 + 3i, 1e-10), 10) == 4.9648734559-13.2781348538i, + strcat(str(tnum++), + ': round(cas(2 + 3i, 1e-10), 10) == 4.9648734559-13.2781348538i')); - /* test Euler's formula */ - vrfy(cis(0, 1e-10) == 1, - strcat(str(tnum++), ': cis(0, 1e-10) == 1')); - vrfy(cis(pi/2, 1e-10) == 1i, - strcat(str(tnum++), ': cis(pi/2, 1e-10) == 1i')); - vrfy(round(cis(0.2, 1e-10), 10) == 0.9800665778+0.1986693308i, - strcat(str(tnum++), - ': round(cis(0.2, 1e-10), 10) == 0.9800665778+0.1986693308i')); - vrfy(round(cis(3/7, 1e-10), 10) == 0.9095603517+0.415571855i, - strcat(str(tnum++), - ': round(cis(3/7, 1e-10), 10) == 0.9095603517+0.415571855i')); - vrfy(round(cis(-31, 1e-10), 10) == 0.9147423578+0.4040376453i, - strcat(str(tnum++), - ': round(cis(-31, 1e-10), 10) == 0.9147423578+0.4040376453i')); - vrfy(round(cis(1, 1e-10), 10) == 0.5403023059+0.8414709848i, - strcat(str(tnum++), - ': round(cis(1, 1e-10), 10) == 0.5403023059+0.8414709848i')); - vrfy(round(cis(2 + 3i, 1e-10), 10) == -0.020718731+0.0452712532i, - strcat(str(tnum++), - ': round(cis(2 + 3i, 1e-10), 10) == -0.020718731+0.0452712532i')); + /* test Euler's formula */ + vrfy(cis(0, 1e-10) == 1, + strcat(str(tnum++), ': cis(0, 1e-10) == 1')); + vrfy(cis(pi/2, 1e-10) == 1i, + strcat(str(tnum++), ': cis(pi/2, 1e-10) == 1i')); + vrfy(round(cis(0.2, 1e-10), 10) == 0.9800665778+0.1986693308i, + strcat(str(tnum++), + ': round(cis(0.2, 1e-10), 10) == 0.9800665778+0.1986693308i')); + vrfy(round(cis(3/7, 1e-10), 10) == 0.9095603517+0.415571855i, + strcat(str(tnum++), + ': round(cis(3/7, 1e-10), 10) == 0.9095603517+0.415571855i')); + vrfy(round(cis(-31, 1e-10), 10) == 0.9147423578+0.4040376453i, + strcat(str(tnum++), + ': round(cis(-31, 1e-10), 10) == 0.9147423578+0.4040376453i')); + vrfy(round(cis(1, 1e-10), 10) == 0.5403023059+0.8414709848i, + strcat(str(tnum++), + ': round(cis(1, 1e-10), 10) == 0.5403023059+0.8414709848i')); + vrfy(round(cis(2 + 3i, 1e-10), 10) == -0.020718731+0.0452712532i, + strcat(str(tnum++), + ': round(cis(2 + 3i, 1e-10), 10) == -0.020718731+0.0452712532i')); - print strcat(str(tnum++), ': Ending test_trig'); + print strcat(str(tnum++), ': Ending test_trig'); } print '051: parsed test_trig()'; @@ -4259,20 +4259,20 @@ print '051: parsed test_trig()'; * After defining test_frem we print errcount() and ecnt. * * NOTE: We moved test3500 to test9300. We parse this code here, - * however we execute this code as a 9300 test. + * however we execute this code as a 9300 test. */ read -once "test9300.frem"; print '052: read -once test9300.frem'; /**/ define test_frem() { - local tnum; /* test number */ + local tnum; /* test number */ - print '9300: Beginning test_frem'; + print '9300: Beginning test_frem'; - tnum = test9300(1, 9301, 200, 61); + tnum = test9300(1, 9301, 200, 61); - print tnum: ': Ending test_frem'; + print tnum: ': Ending test_frem'; } print '053: parsed test_frem()'; print '054: errcount():', errcount() : ', ecnt:', ecnt; @@ -4292,31 +4292,31 @@ global u_glob = 5; print '057: global u_glob = 5'; global v_glob = 10; print '058: global v_glob = 10'; -vrfy(g_param(u_glob, `v_glob) == 5, '059: g_param(u_glob, `v_glob) == 5'); -vrfy(u_glob == 5, '060: u_glob == 5'); -vrfy(v_glob == 5, '061: v_glob == 5'); -vrfy(h_param(`u_glob, `v_glob) == 5, '062: h_param(`u_glob, `v_glob) == 5'); -vrfy(u_glob == 6, '063: u_glob == 6'); -vrfy(v_glob == 4, '064: v_glob == 4'); +vrfy(g_param(u_glob, `v_glob) == 5, '059: g_param(u_glob, `v_glob) == 5'); +vrfy(u_glob == 5, '060: u_glob == 5'); +vrfy(v_glob == 5, '061: v_glob == 5'); +vrfy(h_param(`u_glob, `v_glob) == 5, '062: h_param(`u_glob, `v_glob) == 5'); +vrfy(u_glob == 6, '063: u_glob == 6'); +vrfy(v_glob == 4, '064: v_glob == 4'); /**/ define test_param() { - local u, v; + local u, v; - print '3800: Beginning test_param'; + print '3800: Beginning test_param'; - u = 5; - print '3801: u = 5'; - v = 10; - print '3802: v = 10'; - vrfy(g_param(u, `v) == 5, '3803: g_param(u, `v) == 5'); - vrfy(u == 5, '3804: u == 5'); - vrfy(v == 5, '3805: v == 5'); - vrfy(h_param(`u, `v) == 5, '3806: h_param(`u, `v) == 5'); - vrfy(u == 6, '3807: u == 6'); - vrfy(v == 4, '3808: v == 4'); + u = 5; + print '3801: u = 5'; + v = 10; + print '3802: v = 10'; + vrfy(g_param(u, `v) == 5, '3803: g_param(u, `v) == 5'); + vrfy(u == 5, '3804: u == 5'); + vrfy(v == 5, '3805: v == 5'); + vrfy(h_param(`u, `v) == 5, '3806: h_param(`u, `v) == 5'); + vrfy(u == 6, '3807: u == 6'); + vrfy(v == 4, '3808: v == 4'); - print '3809: Ending test_param'; + print '3809: Ending test_param'; } print '065: parsed test_param()'; @@ -4328,36 +4328,36 @@ print '065: parsed test_param()'; */ define test_noarg() { - local A,B,C,D; + local A,B,C,D; - print '3900: Beginning test_noarg'; + print '3900: Beginning test_noarg'; - A = list(1,,3); - print '3901: A = list(1,,3)'; - vrfy(A[[0]] == 1, '3902: A[[0]] == 1'); - vrfy(isnull(A[[1]]), '3903: isnull(A[[1]])'); - vrfy(A[[2]] == 3, '3904: A[[2]] == 3'); - vrfy(size(A) == 3, '3905: size(A) == 3'); + A = list(1,,3); + print '3901: A = list(1,,3)'; + vrfy(A[[0]] == 1, '3902: A[[0]] == 1'); + vrfy(isnull(A[[1]]), '3903: isnull(A[[1]])'); + vrfy(A[[2]] == 3, '3904: A[[2]] == 3'); + vrfy(size(A) == 3, '3905: size(A) == 3'); - B = list(,,); - print '3906: B = list(,,)'; - vrfy(isnull(B[[0]]), '3907: isnull(B[[0]])'); - vrfy(isnull(B[[1]]), '3908: isnull(B[[1]])'); - vrfy(isnull(B[[2]]), '3909: isnull(B[[2]])'); - vrfy(size(B) == 3, '3910: size(B) == 3'); + B = list(,,); + print '3906: B = list(,,)'; + vrfy(isnull(B[[0]]), '3907: isnull(B[[0]])'); + vrfy(isnull(B[[1]]), '3908: isnull(B[[1]])'); + vrfy(isnull(B[[2]]), '3909: isnull(B[[2]])'); + vrfy(size(B) == 3, '3910: size(B) == 3'); - mat C[] = {,,}; - print '3911: mat C[] = {,,}'; - vrfy(C[0] == 0, '3912: C[0] == 0'); - vrfy(C[1] == 0, '3913: C[1] == 0'); - vrfy(C[2] == 0, '3914: C[2] == 0'); - vrfy(size(C) == 3, '3915: size(C) == 3'); + mat C[] = {,,}; + print '3911: mat C[] = {,,}'; + vrfy(C[0] == 0, '3912: C[0] == 0'); + vrfy(C[1] == 0, '3913: C[1] == 0'); + vrfy(C[2] == 0, '3914: C[2] == 0'); + vrfy(size(C) == 3, '3915: size(C) == 3'); - mat D[] = { }; - print '3916: mat D[] = { }'; - vrfy(D[0] == 0, '3917: D[0] == 0'); - vrfy(size(D) == 1, '3918: size(D) == 1'); - print '3919: Ending test_noarg'; + mat D[] = { }; + print '3916: mat D[] = { }'; + vrfy(D[0] == 0, '3917: D[0] == 0'); + vrfy(size(D) == 1, '3918: size(D) == 1'); + print '3919: Ending test_noarg'; } print '066: parsed test_noarg()'; @@ -4372,13 +4372,13 @@ print '067: read -once test4000.ptest'; /**/ define test_ptest() { - local tnum; /* test number */ + local tnum; /* test number */ - print '4000: Beginning test_ptest'; + print '4000: Beginning test_ptest'; - tnum = test4000(1, 4001); + tnum = test4000(1, 4001); - print tnum: ': Ending test_ptest'; + print tnum: ': Ending test_ptest'; } print '068: parsed test_ptest()'; @@ -4393,13 +4393,13 @@ print '069: read -once test4100.redc'; /**/ define test_redc() { - local tnum; /* test number */ + local tnum; /* test number */ - print '4100: Beginning test_redc'; + print '4100: Beginning test_redc'; - tnum = test4100(1, 4101); + tnum = test4100(1, 4101); - print tnum: ': Ending test_redc'; + print tnum: ': Ending test_redc'; } print '070: parsed test_redc()'; @@ -4411,165 +4411,165 @@ print '070: parsed test_redc()'; */ define test_fileops() { - local a, b, c, f, m, n, p, r, s, x, y, z; - local L = "Landon"; - local C = "Curt"; - local N = "Noll"; - local LCN = "Landon\nCurt\nNoll\n"; - local long = "0123456789abcdef0123456789abcdef"; + local a, b, c, f, m, n, p, r, s, x, y, z; + local L = "Landon"; + local C = "Curt"; + local N = "Noll"; + local LCN = "Landon\nCurt\nNoll\n"; + local long = "0123456789abcdef0123456789abcdef"; - print '4200: Beginning test_fileops'; + print '4200: Beginning test_fileops'; - /* - * fputs tests - */ - x = rm("-f", "junk4200"); - print '4201: x = rm("-f", "junk4200")'; - vrfy(!iserror(f = fopen("junk4200", "w+")), - '4202: !iserror(f = fopen("junk4200", "w+"))'); - vrfy(!iserror(fputs(f, LCN)), '4203: !iserror(fputs(f, LCN))'); - vrfy(isnull(rewind(f)), '4204: isnull(rewind(f))'); - vrfy(fgetfield(f) == L, '4205: fgetfield(f) == L'); - vrfy(fgetfield(f) == C, '4206: fgetfield(f) == C'); - vrfy(fgetfield(f) == N, '4207: fgetfield(f) == N'); - vrfy(isnull(fgetfield(f)), '4208: isnull(fgetfield(f))'); - vrfy(isnull(rewind(f)), '4209: isnull(rewind(f))'); - vrfy(fgetline(f) == L, '4210: fgetline(f) == L'); - vrfy(fgetline(f) == C, '4211: fgetline(f) == C'); - vrfy(fgetline(f) == N, '4212: fgetline(f) == N'); - vrfy(isnull(fgetline(f)), '4213: isnull(fgetline(f))'); - vrfy(isnull(rewind(f)), '4214: isnull(rewind(f))'); - vrfy(fgets(f) == strcat(L,"\n"), '4215: fgets(f) == strcat(L,"\\n")'); - vrfy(fgets(f) == strcat(C,"\n"), '4216: fgets(f) == strcat(C,"\\n")'); - vrfy(fgets(f) == strcat(N,"\n"), '4217: fgets(f) == strcat(N,"\\n")'); - vrfy(isnull(fgets(f)), '4218: isnull(fgets(f))'); - vrfy(isnull(rewind(f)), '4219: isnull(rewind(f))'); - vrfy(fgetstr(f) == LCN, '4220: fgetstr(f) == LCN'); - vrfy(isnull(fclose(f)), '4221: isnull(fclose(f))'); - vrfy(isnull(fclose(f)), '4222: isnull(fclose(f))'); + /* + * fputs tests + */ + x = rm("-f", "junk4200"); + print '4201: x = rm("-f", "junk4200")'; + vrfy(!iserror(f = fopen("junk4200", "w+")), + '4202: !iserror(f = fopen("junk4200", "w+"))'); + vrfy(!iserror(fputs(f, LCN)), '4203: !iserror(fputs(f, LCN))'); + vrfy(isnull(rewind(f)), '4204: isnull(rewind(f))'); + vrfy(fgetfield(f) == L, '4205: fgetfield(f) == L'); + vrfy(fgetfield(f) == C, '4206: fgetfield(f) == C'); + vrfy(fgetfield(f) == N, '4207: fgetfield(f) == N'); + vrfy(isnull(fgetfield(f)), '4208: isnull(fgetfield(f))'); + vrfy(isnull(rewind(f)), '4209: isnull(rewind(f))'); + vrfy(fgetline(f) == L, '4210: fgetline(f) == L'); + vrfy(fgetline(f) == C, '4211: fgetline(f) == C'); + vrfy(fgetline(f) == N, '4212: fgetline(f) == N'); + vrfy(isnull(fgetline(f)), '4213: isnull(fgetline(f))'); + vrfy(isnull(rewind(f)), '4214: isnull(rewind(f))'); + vrfy(fgets(f) == strcat(L,"\n"), '4215: fgets(f) == strcat(L,"\\n")'); + vrfy(fgets(f) == strcat(C,"\n"), '4216: fgets(f) == strcat(C,"\\n")'); + vrfy(fgets(f) == strcat(N,"\n"), '4217: fgets(f) == strcat(N,"\\n")'); + vrfy(isnull(fgets(f)), '4218: isnull(fgets(f))'); + vrfy(isnull(rewind(f)), '4219: isnull(rewind(f))'); + vrfy(fgetstr(f) == LCN, '4220: fgetstr(f) == LCN'); + vrfy(isnull(fclose(f)), '4221: isnull(fclose(f))'); + vrfy(isnull(fclose(f)), '4222: isnull(fclose(f))'); - /* - * fgetstr tests - */ - vrfy(!iserror(f = fopen("junk4200", "w+")), - '4223: !iserror(f)'); + /* + * fgetstr tests + */ + vrfy(!iserror(f = fopen("junk4200", "w+")), + '4223: !iserror(f)'); - vrfy(isnull(fputstr(f, L, C, N)), - '4224: isnulll(fputstr(f, L, C, N))'); - vrfy(isnull(rewind(f)), '4225: isnull(rewind(f))'); - vrfy(fgetstr(f) == L, '4226: fgetstr(f) == L'); - vrfy(fgetstr(f) == C, '4227: fgetstr(f) == C'); - vrfy(fgetstr(f) == N, '4228: fgetstr(f) == N'); - vrfy(isnull(fgetstr(f)), '4229: isnull(fgetstr(f))'); - n = ftell(f); - print '4230: n = ftell(f)'; - vrfy(isnull(fputs(f,L,"\n",C,"\n",N,"\n")), - '4231: isnull(fputs(f,L,"\\n",C,"\\n",N,"\\n"))'); - fseek(f, n); - print '4232: fseek(f, n)'; - vrfy(fgetstr(f) == LCN, '4233: fgetstr(f) == LCN'); - vrfy(isnull(fclose(f)), '4234: isnull(fclose(f))'); + vrfy(isnull(fputstr(f, L, C, N)), + '4224: isnulll(fputstr(f, L, C, N))'); + vrfy(isnull(rewind(f)), '4225: isnull(rewind(f))'); + vrfy(fgetstr(f) == L, '4226: fgetstr(f) == L'); + vrfy(fgetstr(f) == C, '4227: fgetstr(f) == C'); + vrfy(fgetstr(f) == N, '4228: fgetstr(f) == N'); + vrfy(isnull(fgetstr(f)), '4229: isnull(fgetstr(f))'); + n = ftell(f); + print '4230: n = ftell(f)'; + vrfy(isnull(fputs(f,L,"\n",C,"\n",N,"\n")), + '4231: isnull(fputs(f,L,"\\n",C,"\\n",N,"\\n"))'); + fseek(f, n); + print '4232: fseek(f, n)'; + vrfy(fgetstr(f) == LCN, '4233: fgetstr(f) == LCN'); + vrfy(isnull(fclose(f)), '4234: isnull(fclose(f))'); - /* - * fscanf tests - */ - a = exp(27, 1e-1000); - print '4235: a = exp(27, 1e-1000)'; - b = sqrt(7 + 5i, 1e-2000); - print '4236: b = sqrt(7 + 5i, 1e-2000)'; - c = config("display", 1000); - print '4237: c = config("display", 1000)'; - vrfy(!iserror(f=fopen("junk4200","w+")), - '4238: !iserror(f=fopen("junk4200","w+"))'); - vrfy(!iserror(fprintf(f, "%f\n\tand\n\t%r",a,b)), - '4239: !iserror(fprintf(f, "%f\\n\\tand\\n\\t%r",a,b))'); - vrfy(isnull(rewind(f)), '4240: isnull(rewind(f))'); - vrfy(fscanf(f,"%f and %r",x,y)==2, - '4241: fscanf(f,"%f and %r",x,y)==2'); - vrfy(x == a && y == b, '4242: x == a && y == b'); - vrfy(!iserror(freopen(f, "w+")), '4243: !iserror(freopen(f, "w+"))'); - L = "Landon\n"; - print '4244: L = "Landon\\n"'; - C = "\tCurt\n"; - print '4245: C = "\tCurt\\n"'; - N = "\t\tNoll\n"; - print '4246: N = "\\t\\tNoll\\n"'; - vrfy(isnull(fputs(f, L, "|", C, "[", N, "]" )), - '4247: isnull(fputs(f, L, "|", C, "[", N, "]" ))'); - vrfy(isnull(rewind(f)), '4248: isnull(rewind(f))'); - vrfy(fscanf(f, "%[^|]%*c%[^[]%*c%[^]]", x,y,z) == 3, - '4249: fscanf(f, "%[^|]%*c%[^[]%*c%[^]]", x,y,z) == 3'); - vrfy(x == L && y == C && z == N, - '4250: x == L && y == C && z == N'); - vrfy(isnull(rewind(f)), '4251: isnull(rewind(f))'); - vrfy(fscanf(f, "%*[^|]%*c%n%*[^[]%*c%n", m, n) == 2, - '4252: fscanf(f, "%*[^|]%*c%n%*[^[]%*c%n", m, n) == 2'); - fseek(f, m); - print '4253: fseek(f, m)'; - vrfy(fscanf(f, "%3c", x) == 1, '4254: fscanf(f, "%3c", x) == 1'); - vrfy(x == "\tCu", '4255: x == "\tCu"'); - fseek(f, n); - print '4256: fseek(f, n)'; - vrfy(fscanf(f, "%s", y) == 1, '4257: fscanf(f, "%s", y) == 1'); - vrfy(y == "Noll", '4258: y == "Noll"'); - vrfy(isnull(fclose(f)), '4259: isnull(fclose(f))'); + /* + * fscanf tests + */ + a = exp(27, 1e-1000); + print '4235: a = exp(27, 1e-1000)'; + b = sqrt(7 + 5i, 1e-2000); + print '4236: b = sqrt(7 + 5i, 1e-2000)'; + c = config("display", 1000); + print '4237: c = config("display", 1000)'; + vrfy(!iserror(f=fopen("junk4200","w+")), + '4238: !iserror(f=fopen("junk4200","w+"))'); + vrfy(!iserror(fprintf(f, "%f\n\tand\n\t%r",a,b)), + '4239: !iserror(fprintf(f, "%f\\n\\tand\\n\\t%r",a,b))'); + vrfy(isnull(rewind(f)), '4240: isnull(rewind(f))'); + vrfy(fscanf(f,"%f and %r",x,y)==2, + '4241: fscanf(f,"%f and %r",x,y)==2'); + vrfy(x == a && y == b, '4242: x == a && y == b'); + vrfy(!iserror(freopen(f, "w+")), '4243: !iserror(freopen(f, "w+"))'); + L = "Landon\n"; + print '4244: L = "Landon\\n"'; + C = "\tCurt\n"; + print '4245: C = "\tCurt\\n"'; + N = "\t\tNoll\n"; + print '4246: N = "\\t\\tNoll\\n"'; + vrfy(isnull(fputs(f, L, "|", C, "[", N, "]" )), + '4247: isnull(fputs(f, L, "|", C, "[", N, "]" ))'); + vrfy(isnull(rewind(f)), '4248: isnull(rewind(f))'); + vrfy(fscanf(f, "%[^|]%*c%[^[]%*c%[^]]", x,y,z) == 3, + '4249: fscanf(f, "%[^|]%*c%[^[]%*c%[^]]", x,y,z) == 3'); + vrfy(x == L && y == C && z == N, + '4250: x == L && y == C && z == N'); + vrfy(isnull(rewind(f)), '4251: isnull(rewind(f))'); + vrfy(fscanf(f, "%*[^|]%*c%n%*[^[]%*c%n", m, n) == 2, + '4252: fscanf(f, "%*[^|]%*c%n%*[^[]%*c%n", m, n) == 2'); + fseek(f, m); + print '4253: fseek(f, m)'; + vrfy(fscanf(f, "%3c", x) == 1, '4254: fscanf(f, "%3c", x) == 1'); + vrfy(x == "\tCu", '4255: x == "\tCu"'); + fseek(f, n); + print '4256: fseek(f, n)'; + vrfy(fscanf(f, "%s", y) == 1, '4257: fscanf(f, "%s", y) == 1'); + vrfy(y == "Noll", '4258: y == "Noll"'); + vrfy(isnull(fclose(f)), '4259: isnull(fclose(f))'); - /* - * fpathopen tests - */ - vrfy(!iserror(p=fpathopen("junk4200","r",".")), - '4260: !iserror(p=fparhopen("junk4200","r","."))'); - vrfy(!iserror(fclose(p)), '4261: !iserror(fclose(p))'); - vrfy(!iserror(r=fpathopen("regress.cal","r")), - '4262: !iserror(r=fparhopen("regress.cal","r","."))'); - vrfy(!iserror(fclose(r)), '4263: !iserror(fclose(r))'); + /* + * fpathopen tests + */ + vrfy(!iserror(p=fpathopen("junk4200","r",".")), + '4260: !iserror(p=fparhopen("junk4200","r","."))'); + vrfy(!iserror(fclose(p)), '4261: !iserror(fclose(p))'); + vrfy(!iserror(r=fpathopen("regress.cal","r")), + '4262: !iserror(r=fparhopen("regress.cal","r","."))'); + vrfy(!iserror(fclose(r)), '4263: !iserror(fclose(r))'); - /* - * verify non-stack overflow on long filenames - */ - long = long + long + long + long; - print '4264: long = long + long + long + long;'; - long = long + long + long + long; - print '4265: long = long + long + long + long;'; - vrfy(strlen(long) == 512, '4266: strlen(long) == 512'); - /* bump ecnt up by 1 */ - ++ecnt; - print '4267: ++ecnt;'; - vrfy(isfile(p=fopen(long,"r")) == 0, - '4268: isfile(p=fopen(long,"r")) == 0'); + /* + * verify non-stack overflow on long filenames + */ + long = long + long + long + long; + print '4264: long = long + long + long + long;'; + long = long + long + long + long; + print '4265: long = long + long + long + long;'; + vrfy(strlen(long) == 512, '4266: strlen(long) == 512'); + /* bump ecnt up by 1 */ + ++ecnt; + print '4267: ++ecnt;'; + vrfy(isfile(p=fopen(long,"r")) == 0, + '4268: isfile(p=fopen(long,"r")) == 0'); - /* - * test fgetfile() and fgetline() - */ - vrfy(!iserror(p=fopen("tmp4200","w")), - '4269: !iserror(p=fopen("tmp4200","w"))'); - vrfy(!iserror(fputs(p,"chongo\n")), - '4270: !iserror(fputs(p,"chongo\n"))'); - vrfy(!iserror(fputs(p,"w\0a\0s\n")), - '4271: !iserror(fputs(p,"w\0a\0s\n"))'); - vrfy(!iserror(fputs(p,"here\n")), - '4272: !iserror(fputs(p,"here\n"))'); - vrfy(!iserror(fclose(p)), '4273: !iserror(fclose(p))'); - vrfy(!iserror(p=fopen("tmp4200","r")), - '4274: !iserror(p=fopen("tmp4200","r"))'); - vrfy(!iserror(s=fgetline(p)), '4275: !iserror(s=fgetline(p))'); - vrfy(strcmp(s,"chongo") == 0, '4276: strcmp(s,"chongo") == 0'); - vrfy(!iserror(s=fgetfile(p)), '4277: !iserror(s=fgetfile(p))'); - vrfy(strcmp(s,"w\0a\0s\nhere\n") == 0, - '4278: strcmp(s,"w\0a\0s\nhere\n") == 0'); - vrfy(!iserror(fclose(p)), '4279: !iserror(fclose(p))'); + /* + * test fgetfile() and fgetline() + */ + vrfy(!iserror(p=fopen("tmp4200","w")), + '4269: !iserror(p=fopen("tmp4200","w"))'); + vrfy(!iserror(fputs(p,"chongo\n")), + '4270: !iserror(fputs(p,"chongo\n"))'); + vrfy(!iserror(fputs(p,"w\0a\0s\n")), + '4271: !iserror(fputs(p,"w\0a\0s\n"))'); + vrfy(!iserror(fputs(p,"here\n")), + '4272: !iserror(fputs(p,"here\n"))'); + vrfy(!iserror(fclose(p)), '4273: !iserror(fclose(p))'); + vrfy(!iserror(p=fopen("tmp4200","r")), + '4274: !iserror(p=fopen("tmp4200","r"))'); + vrfy(!iserror(s=fgetline(p)), '4275: !iserror(s=fgetline(p))'); + vrfy(strcmp(s,"chongo") == 0, '4276: strcmp(s,"chongo") == 0'); + vrfy(!iserror(s=fgetfile(p)), '4277: !iserror(s=fgetfile(p))'); + vrfy(strcmp(s,"w\0a\0s\nhere\n") == 0, + '4278: strcmp(s,"w\0a\0s\nhere\n") == 0'); + vrfy(!iserror(fclose(p)), '4279: !iserror(fclose(p))'); - /* - * cleanup - */ - x = rm("junk4200"); - print '4280: x = rm("junk4200")'; - x = rm("tmp4200"); - print '4281: x = rm("tmp4200")'; - x = config("display", 20); - print '4282: x = config("display", 20)'; + /* + * cleanup + */ + x = rm("junk4200"); + print '4280: x = rm("junk4200")'; + x = rm("tmp4200"); + print '4281: x = rm("tmp4200")'; + x = config("display", 20); + print '4282: x = config("display", 20)'; - print '4283: Ending test_fileops'; + print '4283: Ending test_fileops'; } print '071: parsed test_fileops()'; @@ -4587,99 +4587,99 @@ mat mat_Z0, mat_Z1 [2] = {1,2}; print '074: mat mat_Z0, mat_Z1 [2] = {1,2}'; define test_matdcl() { - local mat_Y0; - local mat mat_Y1, mat_Y2[2], mat_Y3[3]; - local mat M0, M1, M2[2,2]; - local i; + local mat_Y0; + local mat mat_Y1, mat_Y2[2], mat_Y3[3]; + local mat M0, M1, M2[2,2]; + local i; - print '4300: Beginning test_matdcl'; + print '4300: Beginning test_matdcl'; - vrfy(size(mat_X0) == 4, '4301: size(mat_X0) == 4'); - vrfy(size(mat_X1) == 2, '4302: size(mat_X1) == 2'); - vrfy(size(mat_X2) == 2, '4303: size(mat_X2) == 2'); - vrfy(size(mat_X3) == 3, '4304: size(mat_X3) == 3'); - vrfy(ismat(mat_X0), '4305: ismat(mat_X0)'); - vrfy(ismat(mat_X1), '4306: ismat(mat_X1)'); - vrfy(ismat(mat_X2), '4307: ismat(mat_X2)'); - vrfy(ismat(mat_X3), '4308: ismat(mat_X3)'); - mat_Y0 = mat[4]; - print '4309: mat_Y0 = mat[4]'; - vrfy(size(mat_Y0) == 4, '4310: size(mat_Y0) == 4'); - vrfy(size(mat_Y1) == 2, '4311: size(mat_Y1) == 2'); - vrfy(size(mat_Y2) == 2, '4312: size(mat_Y2) == 2'); - vrfy(size(mat_Y3) == 3, '4313: size(mat_Y3) == 3'); - vrfy(ismat(mat_Y0), '4314: ismat(mat_Y0)'); - vrfy(ismat(mat_Y1), '4315: ismat(mat_Y1)'); - vrfy(ismat(mat_Y2), '4316: ismat(mat_Y2)'); - vrfy(ismat(mat_Y3), '4317: ismat(mat_Y3)'); - vrfy(size(mat_Z0) == 2, '4318: size(mat_Z0) == 2'); - vrfy(size(mat_Z1) == 2, '4319: size(mat_Z1) == 2'); - vrfy(ismat(mat_Z0), '4320: ismat(mat_Z0)'); - vrfy(ismat(mat_Z1), '4321: ismat(mat_Z1)'); - vrfy(mat_Z0 == mat_Z1, '4322: mat_Z0 == mat_Z1'); - vrfy(mat_Z0 == (mat[2] = {1,2}), '4323: mat_Z0 == (mat[2] = {1,2})'); - vrfy(mat_Z0[0] == 1, '4324: mat_Z0[0] == 1'); - vrfy(mat_Z0[1] == 2, '4325: mat_Z0[1] == 2'); - mat_Z1 = {,3}; - print '4326: mat_Z1 = {,3}'; - vrfy(mat_Z0 != mat_Z1, '4327: mat_Z0 != mat_Z1'); - vrfy(mat_Z1[0] == 1, '4328: mat_Z1[0] == 1'); - vrfy(mat_Z1[1] == 3, '4329: mat_Z1[1] == 3'); - mat_X3 = {2,3,5}; - print '4330: mat_X3 = {2,3,5}'; - mat_X3 += {3,4,5}; - print '4331: mat_X3 += {3,4,5}'; - vrfy(mat_X3[0] == 5, '4332: mat_X3[0] == 5'); - vrfy(mat_X3[1] == 7, '4333: mat_X3[1] == 7'); - vrfy(mat_X3[2] == 10, '4334: mat_X3[2] == 10'); - mat_Y3 = mat_X3; - print '4335: mat_Y3 = mat_X3'; - mat_Y3 -= {,1,2}; - print '4336: mat_Y3 -= {0,1,}'; - vrfy(mat_Y3[0] == 0, '4337: mat_Y3[0] == 0'); - vrfy(mat_Y3[1] == 6, '4338: mat_Y3[1] == 6'); - vrfy(mat_Y3[2] == 8, '4339: mat_Y3[2] == 8'); - ecnt += 2; - print '4340: ecnt += 2'; - mat_Y3 += 2; - print '4341: mat_Y3 += 2'; - vrfy(mat_Y3 == error("E_ADD"), '4342: mat_Y3 == error("E_ADD")'); - vrfy(errcount() == ecnt, '4343: errcount() == ecnt'); - mat_Z0 += { }; - print '4344: mat_Z0 += { }'; - vrfy(mat_Z0[0] == 2, '4345: mat_Z0[0] == 2'); - vrfy(mat_Z0[1] == 4, '4346: mat_Z0[1] == 4'); - mat_Y0 = {mat_Z0, ,mat_Z1, mat_X3}; - print '4347: mat_Y0 = {mat_Z0, ,mat_Z1, mat_X3}'; - vrfy(size(mat_Y0) == 4, '4348: size(mat_Y0) == 4'); - for (i=0; i < 4; ++i) mat_X0[i] = size(mat_Y0[i]); - print '4349: for (i=0; i < 4; ++i) mat_X0[i] = size(mat_Y0[i])'; - mat_X0==(mat[4]={2,1,2,3}); - print '4350: mat_X0==(mat[4]={2,1,2,3})'; - vrfy(mat_Y0[0] == mat_Z0, '4351: mat_Y0[0] == mat_Z0'); - vrfy(mat_Y0[1] == 0, '4352: mat_Y0[1] == 0'); - vrfy(mat_Y0[2] == mat_Z1, '4353: mat_Y0[2] == mat_Z1'); - vrfy(mat_Y0[3] == mat_X3, '4354: mat_Y0[3] == mat_X3'); - vrfy(mat_Y0[0][0] == 2, '4355: mat_Y0[0][0] == 2'); - vrfy(mat_Y0[0][1] == 4, '4356: mat_Y0[0][1] == 4'); - vrfy(mat_Y0[2][0] == 1, '4357: mat_Y0[2][0] == 1'); - vrfy(mat_Y0[2][1] == 3, '4358: mat_Y0[2][1] == 3'); - vrfy(mat_Y0[3][0] == 5, '4359: mat_Y0[3][0] == 5'); - vrfy(mat_Y0[3][1] == 7, '4360: mat_Y0[3][1] == 7'); - vrfy(mat_Y0[3][2] == 10, '4361: mat_Y0[3][2] == 10'); + vrfy(size(mat_X0) == 4, '4301: size(mat_X0) == 4'); + vrfy(size(mat_X1) == 2, '4302: size(mat_X1) == 2'); + vrfy(size(mat_X2) == 2, '4303: size(mat_X2) == 2'); + vrfy(size(mat_X3) == 3, '4304: size(mat_X3) == 3'); + vrfy(ismat(mat_X0), '4305: ismat(mat_X0)'); + vrfy(ismat(mat_X1), '4306: ismat(mat_X1)'); + vrfy(ismat(mat_X2), '4307: ismat(mat_X2)'); + vrfy(ismat(mat_X3), '4308: ismat(mat_X3)'); + mat_Y0 = mat[4]; + print '4309: mat_Y0 = mat[4]'; + vrfy(size(mat_Y0) == 4, '4310: size(mat_Y0) == 4'); + vrfy(size(mat_Y1) == 2, '4311: size(mat_Y1) == 2'); + vrfy(size(mat_Y2) == 2, '4312: size(mat_Y2) == 2'); + vrfy(size(mat_Y3) == 3, '4313: size(mat_Y3) == 3'); + vrfy(ismat(mat_Y0), '4314: ismat(mat_Y0)'); + vrfy(ismat(mat_Y1), '4315: ismat(mat_Y1)'); + vrfy(ismat(mat_Y2), '4316: ismat(mat_Y2)'); + vrfy(ismat(mat_Y3), '4317: ismat(mat_Y3)'); + vrfy(size(mat_Z0) == 2, '4318: size(mat_Z0) == 2'); + vrfy(size(mat_Z1) == 2, '4319: size(mat_Z1) == 2'); + vrfy(ismat(mat_Z0), '4320: ismat(mat_Z0)'); + vrfy(ismat(mat_Z1), '4321: ismat(mat_Z1)'); + vrfy(mat_Z0 == mat_Z1, '4322: mat_Z0 == mat_Z1'); + vrfy(mat_Z0 == (mat[2] = {1,2}), '4323: mat_Z0 == (mat[2] = {1,2})'); + vrfy(mat_Z0[0] == 1, '4324: mat_Z0[0] == 1'); + vrfy(mat_Z0[1] == 2, '4325: mat_Z0[1] == 2'); + mat_Z1 = {,3}; + print '4326: mat_Z1 = {,3}'; + vrfy(mat_Z0 != mat_Z1, '4327: mat_Z0 != mat_Z1'); + vrfy(mat_Z1[0] == 1, '4328: mat_Z1[0] == 1'); + vrfy(mat_Z1[1] == 3, '4329: mat_Z1[1] == 3'); + mat_X3 = {2,3,5}; + print '4330: mat_X3 = {2,3,5}'; + mat_X3 += {3,4,5}; + print '4331: mat_X3 += {3,4,5}'; + vrfy(mat_X3[0] == 5, '4332: mat_X3[0] == 5'); + vrfy(mat_X3[1] == 7, '4333: mat_X3[1] == 7'); + vrfy(mat_X3[2] == 10, '4334: mat_X3[2] == 10'); + mat_Y3 = mat_X3; + print '4335: mat_Y3 = mat_X3'; + mat_Y3 -= {,1,2}; + print '4336: mat_Y3 -= {0,1,}'; + vrfy(mat_Y3[0] == 0, '4337: mat_Y3[0] == 0'); + vrfy(mat_Y3[1] == 6, '4338: mat_Y3[1] == 6'); + vrfy(mat_Y3[2] == 8, '4339: mat_Y3[2] == 8'); + ecnt += 2; + print '4340: ecnt += 2'; + mat_Y3 += 2; + print '4341: mat_Y3 += 2'; + vrfy(mat_Y3 == error("E_ADD"), '4342: mat_Y3 == error("E_ADD")'); + vrfy(errcount() == ecnt, '4343: errcount() == ecnt'); + mat_Z0 += { }; + print '4344: mat_Z0 += { }'; + vrfy(mat_Z0[0] == 2, '4345: mat_Z0[0] == 2'); + vrfy(mat_Z0[1] == 4, '4346: mat_Z0[1] == 4'); + mat_Y0 = {mat_Z0, ,mat_Z1, mat_X3}; + print '4347: mat_Y0 = {mat_Z0, ,mat_Z1, mat_X3}'; + vrfy(size(mat_Y0) == 4, '4348: size(mat_Y0) == 4'); + for (i=0; i < 4; ++i) mat_X0[i] = size(mat_Y0[i]); + print '4349: for (i=0; i < 4; ++i) mat_X0[i] = size(mat_Y0[i])'; + mat_X0==(mat[4]={2,1,2,3}); + print '4350: mat_X0==(mat[4]={2,1,2,3})'; + vrfy(mat_Y0[0] == mat_Z0, '4351: mat_Y0[0] == mat_Z0'); + vrfy(mat_Y0[1] == 0, '4352: mat_Y0[1] == 0'); + vrfy(mat_Y0[2] == mat_Z1, '4353: mat_Y0[2] == mat_Z1'); + vrfy(mat_Y0[3] == mat_X3, '4354: mat_Y0[3] == mat_X3'); + vrfy(mat_Y0[0][0] == 2, '4355: mat_Y0[0][0] == 2'); + vrfy(mat_Y0[0][1] == 4, '4356: mat_Y0[0][1] == 4'); + vrfy(mat_Y0[2][0] == 1, '4357: mat_Y0[2][0] == 1'); + vrfy(mat_Y0[2][1] == 3, '4358: mat_Y0[2][1] == 3'); + vrfy(mat_Y0[3][0] == 5, '4359: mat_Y0[3][0] == 5'); + vrfy(mat_Y0[3][1] == 7, '4360: mat_Y0[3][1] == 7'); + vrfy(mat_Y0[3][2] == 10, '4361: mat_Y0[3][2] == 10'); - M0 = {(mat[2]={5,17}),(mat[2]={3,4}),(mat[2]={2,3}),(mat[2]={1,2})}; - print '4362: M0 = {(mat[2]={5,17}), ...}'; - M1 = {(mat[2]={5,3}),(mat[2]={2,5}),(mat[2]={1,5}),(mat[2]={3,2})}; - print '4363: M1 = {(mat[2]={5,3}), ...}'; - M2 = M0+M1; - print '4364: M2 = M0+M1'; - vrfy(M2[0,0]==(mat[2]={10,20}), '4365: M2[0,0]==(mat[2]={10,20})'); - vrfy(M2[0,1]==(mat[2]={5,9}), '4366: M2[0,1]==(mat[2]={5,9})'); - vrfy(M2[1,0]==(mat[2]={3,8}), '4367: M2[1,0]==(mat[2]={3,20})'); - vrfy(M2[1,1]==(mat[2]={4,4}), '4368: M2[1,1]==(mat[2]={4,4})'); + M0 = {(mat[2]={5,17}),(mat[2]={3,4}),(mat[2]={2,3}),(mat[2]={1,2})}; + print '4362: M0 = {(mat[2]={5,17}), ...}'; + M1 = {(mat[2]={5,3}),(mat[2]={2,5}),(mat[2]={1,5}),(mat[2]={3,2})}; + print '4363: M1 = {(mat[2]={5,3}), ...}'; + M2 = M0+M1; + print '4364: M2 = M0+M1'; + vrfy(M2[0,0]==(mat[2]={10,20}), '4365: M2[0,0]==(mat[2]={10,20})'); + vrfy(M2[0,1]==(mat[2]={5,9}), '4366: M2[0,1]==(mat[2]={5,9})'); + vrfy(M2[1,0]==(mat[2]={3,8}), '4367: M2[1,0]==(mat[2]={3,20})'); + vrfy(M2[1,1]==(mat[2]={4,4}), '4368: M2[1,1]==(mat[2]={4,4})'); - print '4369: Ending test_matdcl'; + print '4369: Ending test_matdcl'; } print '075: parsed test_matdcl()'; @@ -4691,151 +4691,151 @@ print '075: parsed test_matdcl()'; */ define test_objmat() { - static obj surd P, R, S, T, U; - local mat M0[2] = {5,17}; - local mat M1[2] = {3,4}; - local mat M2[2,2] = {1,2,3,5}; - local mat M3[2,2] = {3,5,7,11}; - local mat M4[2,2] = {51,82,116,187}; - local Q; - local V; - local A,B,C,M; + static obj surd P, R, S, T, U; + local mat M0[2] = {5,17}; + local mat M1[2] = {3,4}; + local mat M2[2,2] = {1,2,3,5}; + local mat M3[2,2] = {3,5,7,11}; + local mat M4[2,2] = {51,82,116,187}; + local Q; + local V; + local A,B,C,M; - print '4400: Beginning test_objmat'; + print '4400: Beginning test_objmat'; - surd_type = -1; - print '4401: surd_type == -1'; - P = {M0,M1}; - print '4402: P = {M0,M1}'; - vrfy(P == surd(M0,M1), '4403: P == surd(M0,M1)'); - vrfy(P != surd(M1,M0), '4404: P != surd(M1,M0)'); - vrfy(conj(P)==surd(M0,-M1), '4405: conj(P)==surd(M0,-M1)'); - Q = surd_value(P); - print '4406: Q = surd_value(P)'; - vrfy(ismat(Q), '4407: ismat(Q)'); - vrfy(Q == (mat[2]={5+3i,17+4i}), '4408: Q == (mat[2]={5+3i,17+4i})'); - R = {M2,M3}; - print '4409: R = {M2,M3}'; - vrfy(norm(R) == M4, '4410: norm(R) == M4'); - vrfy(det(surd_value(R^2)) == -23-6i, \ - '4411: det(surd_value(R^2)) == -23-6i'); - vrfy(det(norm(R^5))==268107761663283843865, \ - '4412: det(norm(R^5))==268107761663283843865'); - S = {M2+M3, M2-M3}; - print '4413: S = {M2+M3, M2-M3}'; - T = {M2+3*M3, 5*M2-M3}; - print '4414: T = {M2+3*M3, 5*M2-M3}'; - U = {(M4 -= {50,80,110,180}), M4+M2}; - print '4415: U = {(M4 -= {50,80,110,180}), M4+M2}'; - vrfy(det(surd_value(R*S*T*U)) == 480-15040i, - '4416: det(surd_value(R*S*T*U)) == 480-15040i'); - vrfy(det(surd_value(R*S+T*U)) == 78+514i, - '4417: det(surd_value(R*S+T*U)) == 78+514i'); - V = norm(det(surd_value(R^5+S^5+T^5+U^5))); - print '4418: V = norm(det(surd_value(R^5+S^5+T^5+U^5)))'; - vrfy(V == 41952632964892462488299378, \ - '4419: V == 41952632964892462488299378'); - V = norm(det(surd_value(R^5-S^5+T^5-U^5))); - print '4420: V = norm(det(surd_value(R^5-S^5+T^5-U^5)))'; - vrfy(V == 40891924356202870926321650, \ - '4421: V == 40891924356202870926321650'); + surd_type = -1; + print '4401: surd_type == -1'; + P = {M0,M1}; + print '4402: P = {M0,M1}'; + vrfy(P == surd(M0,M1), '4403: P == surd(M0,M1)'); + vrfy(P != surd(M1,M0), '4404: P != surd(M1,M0)'); + vrfy(conj(P)==surd(M0,-M1), '4405: conj(P)==surd(M0,-M1)'); + Q = surd_value(P); + print '4406: Q = surd_value(P)'; + vrfy(ismat(Q), '4407: ismat(Q)'); + vrfy(Q == (mat[2]={5+3i,17+4i}), '4408: Q == (mat[2]={5+3i,17+4i})'); + R = {M2,M3}; + print '4409: R = {M2,M3}'; + vrfy(norm(R) == M4, '4410: norm(R) == M4'); + vrfy(det(surd_value(R^2)) == -23-6i, \ + '4411: det(surd_value(R^2)) == -23-6i'); + vrfy(det(norm(R^5))==268107761663283843865, \ + '4412: det(norm(R^5))==268107761663283843865'); + S = {M2+M3, M2-M3}; + print '4413: S = {M2+M3, M2-M3}'; + T = {M2+3*M3, 5*M2-M3}; + print '4414: T = {M2+3*M3, 5*M2-M3}'; + U = {(M4 -= {50,80,110,180}), M4+M2}; + print '4415: U = {(M4 -= {50,80,110,180}), M4+M2}'; + vrfy(det(surd_value(R*S*T*U)) == 480-15040i, + '4416: det(surd_value(R*S*T*U)) == 480-15040i'); + vrfy(det(surd_value(R*S+T*U)) == 78+514i, + '4417: det(surd_value(R*S+T*U)) == 78+514i'); + V = norm(det(surd_value(R^5+S^5+T^5+U^5))); + print '4418: V = norm(det(surd_value(R^5+S^5+T^5+U^5)))'; + vrfy(V == 41952632964892462488299378, \ + '4419: V == 41952632964892462488299378'); + V = norm(det(surd_value(R^5-S^5+T^5-U^5))); + print '4420: V = norm(det(surd_value(R^5-S^5+T^5-U^5)))'; + vrfy(V == 40891924356202870926321650, \ + '4421: V == 40891924356202870926321650'); - vrfy((mat [3] = {2,3,5})+(mat[3] = {7,11,13}) == (mat[3]={9,14,18}),\ + vrfy((mat [3] = {2,3,5})+(mat[3] = {7,11,13}) == (mat[3]={9,14,18}),\ '4422: (mat [3] = {2,3,5})+(mat[3] = {7,11,13}) == (mat[3]={9,14,18})'); - vrfy((mat [2,2] = {2,3,5,7})^2 == (mat[2,2] = {19, 27, 45, 64}),\ - '4423: (mat [2,2] = {2,3,5,7})^2 == (mat[2,2] = {19, 27, 45, 64})'); + vrfy((mat [2,2] = {2,3,5,7})^2 == (mat[2,2] = {19, 27, 45, 64}),\ + '4423: (mat [2,2] = {2,3,5,7})^2 == (mat[2,2] = {19, 27, 45, 64})'); - vrfy((mat [] = {1,2,3}) == (mat[3] = {1,2,3}), - '4424: (mat [] = {1,2,3}) == (mat[3] = {1,2,3})'); + vrfy((mat [] = {1,2,3}) == (mat[3] = {1,2,3}), + '4424: (mat [] = {1,2,3}) == (mat[3] = {1,2,3})'); - mat A[3] = {2,3,5}; - print '4425: mat A[3] = {2,3,5}'; - mat A[3] = {A[0], A[2], A[1]}; - print '4426: mat A[3] = {A[0], A[2], A[1]}'; - vrfy(A == (mat[3] = {2, 5, 3}), '4427: A == (mat[3] = {2, 5, 3})'); + mat A[3] = {2,3,5}; + print '4425: mat A[3] = {2,3,5}'; + mat A[3] = {A[0], A[2], A[1]}; + print '4426: mat A[3] = {A[0], A[2], A[1]}'; + vrfy(A == (mat[3] = {2, 5, 3}), '4427: A == (mat[3] = {2, 5, 3})'); - B = mat[3] = {2,5,3}; - print '4428: B = mat[3] = {2,5,3}'; - vrfy(A == B, '4429: A == B'); + B = mat[3] = {2,5,3}; + print '4428: B = mat[3] = {2,5,3}'; + vrfy(A == B, '4429: A == B'); - mat A[2] = {A[1], A[2]}; - print '4430: mat A[2] = {A[1], A[2]}'; - vrfy(A == (mat[2] = {5, 3}), '4431: A == (mat[2] = {5, 3})'); + mat A[2] = {A[1], A[2]}; + print '4430: mat A[2] = {A[1], A[2]}'; + vrfy(A == (mat[2] = {5, 3}), '4431: A == (mat[2] = {5, 3})'); - A = B; - print '4432: A = B'; - A = {A[0], A[2], A[1]}; - print '4433: A = {A[0], A[2], A[1]}'; - vrfy(A == (mat[3] = {2, 3, 3}), '4434: A == (mat[3] = {2, 3, 3})'); + A = B; + print '4432: A = B'; + A = {A[0], A[2], A[1]}; + print '4433: A = {A[0], A[2], A[1]}'; + vrfy(A == (mat[3] = {2, 3, 3}), '4434: A == (mat[3] = {2, 3, 3})'); - A = mat[3] = {1,2} = {,3,4}; - print '4435: A = mat[3] = {1,2} = {,3,4}'; - vrfy(A == (mat[3] = {1,3,4}), '4436: A == (mat[3] = {1,3,4})'); + A = mat[3] = {1,2} = {,3,4}; + print '4435: A = mat[3] = {1,2} = {,3,4}'; + vrfy(A == (mat[3] = {1,3,4}), '4436: A == (mat[3] = {1,3,4})'); - mat A[4] = {1,2,3,4}; - print '4437: mat A[4] = {1,2,3,4}'; - A = {,5,,6}; - print '4438: A = {,5,,6}'; - vrfy(A == (mat[4] = {1,5,3,6}), '4439: A == (mat[4] = {1,5,3,6})'); + mat A[4] = {1,2,3,4}; + print '4437: mat A[4] = {1,2,3,4}'; + A = {,5,,6}; + print '4438: A = {,5,,6}'; + vrfy(A == (mat[4] = {1,5,3,6}), '4439: A == (mat[4] = {1,5,3,6})'); - A = {7}; - print '4440: A = {7}'; - vrfy(A == (mat[4] = {7,5,3,6}), '4441: A == (mat[4] = {7,5,3,6})'); + A = {7}; + print '4440: A = {7}'; + vrfy(A == (mat[4] = {7,5,3,6}), '4441: A == (mat[4] = {7,5,3,6})'); - mat M[2]; - print '4442: mat M[2]'; - mat A, B, C [3] = {M, M, M}; - print '4443: mat A, B, C [3] = {M, M, M}'; + mat M[2]; + print '4442: mat M[2]'; + mat A, B, C [3] = {M, M, M}; + print '4443: mat A, B, C [3] = {M, M, M}'; - A = {{2, 3}, {5, 7}, {11, 13}}; - print '4444: A = {{2, 3}, {5, 7}, {11, 13}}'; - B = {{1, 2}, {3, 4}, {5, 6}}; - print '4445: B = {{1, 2}, {3, 4}, {5, 6}}'; - C = {{3, 5}, {8, 11}, {16, 19}}; - print '4446: C = {{3, 5}, {8, 11}, {16, 19}}'; + A = {{2, 3}, {5, 7}, {11, 13}}; + print '4444: A = {{2, 3}, {5, 7}, {11, 13}}'; + B = {{1, 2}, {3, 4}, {5, 6}}; + print '4445: B = {{1, 2}, {3, 4}, {5, 6}}'; + C = {{3, 5}, {8, 11}, {16, 19}}; + print '4446: C = {{3, 5}, {8, 11}, {16, 19}}'; - vrfy(A + B == C, '4447: A + B == C'); + vrfy(A + B == C, '4447: A + B == C'); - mat A[2][3]; - print '4448: mat A[2][3]'; - A = {{1, 2, 3}, {4, 5, 6}}; - print '4449: A = {{1, 2, 3}, {4, 5, 6}}'; - vrfy(A[0][1] == 2, '4450: A[0][1] == 2'); + mat A[2][3]; + print '4448: mat A[2][3]'; + A = {{1, 2, 3}, {4, 5, 6}}; + print '4449: A = {{1, 2, 3}, {4, 5, 6}}'; + vrfy(A[0][1] == 2, '4450: A[0][1] == 2'); - vrfy(A[1,0] == 4, '4451: A[1,0] == 4'); + vrfy(A[1,0] == 4, '4451: A[1,0] == 4'); - B = mat[2][3] = {{1, 2, 3}, {4, 5, 6}}; - print '4452: B = mat[2][3] = {{1, 2, 3}, {4, 5, 6}}'; - vrfy(A == B, '4453: A == B'); + B = mat[2][3] = {{1, 2, 3}, {4, 5, 6}}; + print '4452: B = mat[2][3] = {{1, 2, 3}, {4, 5, 6}}'; + vrfy(A == B, '4453: A == B'); - mat A[2][3] = {{1, 2, 3}, {4, 5, 6}}; - print '4454: mat A[2][3] = {{1, 2, 3}, {4, 5, 6}}'; - vrfy(A == B, '4455: A == B'); + mat A[2][3] = {{1, 2, 3}, {4, 5, 6}}; + print '4454: mat A[2][3] = {{1, 2, 3}, {4, 5, 6}}'; + vrfy(A == B, '4455: A == B'); - mat A[2][3] = {{1,2,3},4}; - print '4456: mat A[2][3] = {{1,2,3},4}'; - vrfy(A[0] == (mat[3] = {1,2,3}), '4457: A[0] == (mat[3] = {1,2,3})'); + mat A[2][3] = {{1,2,3},4}; + print '4456: mat A[2][3] = {{1,2,3},4}'; + vrfy(A[0] == (mat[3] = {1,2,3}), '4457: A[0] == (mat[3] = {1,2,3})'); - vrfy(A[1] == 4, '4458: A[1] == 4'); + vrfy(A[1] == 4, '4458: A[1] == 4'); - A += {{3,5,7}, 11}; - print '4459: A += {{3,5,7}, 11}'; + A += {{3,5,7}, 11}; + print '4459: A += {{3,5,7}, 11}'; - vrfy(A[0] == (mat[3]={4,7,10}), '4460: A[0] == (mat[3]={4,7,10})'); + vrfy(A[0] == (mat[3]={4,7,10}), '4460: A[0] == (mat[3]={4,7,10})'); - vrfy(A[1] == 15, '4461: A[1] == 15'); + vrfy(A[1] == 15, '4461: A[1] == 15'); - mat A[2,2][2,2]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}}; + mat A[2,2][2,2]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}}; print '4462: mat A[2,2][2,2]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}}'; - B = A^2; - print '4463: B = A^2'; + B = A^2; + print '4463: B = A^2'; - vrfy(B[0,0] == (mat[2,2] = {118, 132, 166, 188}), \ - '4464: B[0,0] == (mat[2,2] = {118, 132, 166, 188})'); + vrfy(B[0,0] == (mat[2,2] = {118, 132, 166, 188}), \ + '4464: B[0,0] == (mat[2,2] = {118, 132, 166, 188})'); - print '4465: Ending test_objmat'; + print '4465: Ending test_objmat'; } print '076: parsed test_objmat()'; @@ -4850,13 +4850,13 @@ print '077: read -once test4600.fileop'; /**/ define test_fileop() { - local tnum; /* test number */ + local tnum; /* test number */ - print '4600: Beginning test_fileop'; + print '4600: Beginning test_fileop'; - tnum = test4600(1, 4601); + tnum = test4600(1, 4601); - print tnum: ': Ending test_fileop'; + print tnum: ': Ending test_fileop'; } print '078: parsed test_fileop()'; @@ -4876,8 +4876,8 @@ read "./test082.cal"; print '083: read "./test082.cal"'; d_081 = rm("test082.cal"); print '084: d081 = rm("test082.cal")'; -vrfy(__ == 63, '085: __ == 63'); -vrfy(x_081 == isqrt(2e5000), '086: x_081 == isqrt(2e5000)'); +vrfy(__ == 63, '085: __ == 63'); +vrfy(x_081 == isqrt(2e5000), '086: x_081 == isqrt(2e5000)'); /* @@ -4887,28 +4887,28 @@ vrfy(x_081 == isqrt(2e5000), '086: x_081 == isqrt(2e5000)'); */ define test_charset() { - print '4700: Beginning test_charset'; + print '4700: Beginning test_charset'; - vrfy("\a" == char(7), '4701: "\\a" == char(7)'); - vrfy("\v" == char(11), '4702: "\\v" == char(11)'); - vrfy("\e" == char(27), '4703: "\\e" == char(27)'); - vrfy("\\" == char(92), '4704: "\\\\" == char(92)'); - vrfy("\101" == "A", '4705: "\\101" == "A"'); - vrfy("\123" == char(0123), '4706: "\\123" == char(0123)'); - vrfy("\123\124" == "ST", '4707: "\\123\\124" == "ST"'); - vrfy("\311" == char(201), '4708: "\\311" == char(201)'); + vrfy("\a" == char(7), '4701: "\\a" == char(7)'); + vrfy("\v" == char(11), '4702: "\\v" == char(11)'); + vrfy("\e" == char(27), '4703: "\\e" == char(27)'); + vrfy("\\" == char(92), '4704: "\\\\" == char(92)'); + vrfy("\101" == "A", '4705: "\\101" == "A"'); + vrfy("\123" == char(0123), '4706: "\\123" == char(0123)'); + vrfy("\123\124" == "ST", '4707: "\\123\\124" == "ST"'); + vrfy("\311" == char(201), '4708: "\\311" == char(201)'); /* NOTE: We skip non-ASCII to avoid problems with old awk that cannot handle them */ -/* vrfy("\119" == "\t9", '4709: "\\119" == "\t9"'); */ -/* vrfy("\765" == "\365", '4710: "\\765" == "\365"'); */ - vrfy("\x61" == "a", '4711: "\\x61" == "a"'); - vrfy("\x73" == "s", '4712: "\\x73" == "s"'); - vrfy("\xea" == char(234), '4713: "\\xea" == char(234)'); - vrfy("\x61\x62\x63" == "abc", '4714: "\\x61\\x62\\x63" == "abc"'); - vrfy("\x8g" == "\bg", '4715: "\\x8g" == "\bg"'); - vrfy(eval('"\\\\"') == "\\", - '4716: eval(\'"\\\\\\\\"\') == "\\\\"'); +/* vrfy("\119" == "\t9", '4709: "\\119" == "\t9"'); */ +/* vrfy("\765" == "\365", '4710: "\\765" == "\365"'); */ + vrfy("\x61" == "a", '4711: "\\x61" == "a"'); + vrfy("\x73" == "s", '4712: "\\x73" == "s"'); + vrfy("\xea" == char(234), '4713: "\\xea" == char(234)'); + vrfy("\x61\x62\x63" == "abc", '4714: "\\x61\\x62\\x63" == "abc"'); + vrfy("\x8g" == "\bg", '4715: "\\x8g" == "\bg"'); + vrfy(eval('"\\\\"') == "\\", + '4716: eval(\'"\\\\\\\\"\') == "\\\\"'); - print '4717: Ending test_charset'; + print '4717: Ending test_charset'; } print '087: parsed test_charset()'; @@ -4920,135 +4920,135 @@ print '087: parsed test_charset()'; */ define test_strprintf() { - local callcfg; /* caller configuration value */ - local c; /* modified configuration */ + local callcfg; /* caller configuration value */ + local c; /* modified configuration */ - print '4800: Beginning test_strprintf'; + print '4800: Beginning test_strprintf'; - /* setup */ - callcfg = config("all"); - print '4801: callcfg = config("all")'; - c = config("mode", "frac"); - print '4802: c = config("mode", "frac")'; - c = config("outround", 24); - print '4803: c = config("outround", 24)'; - c = config("display", 2); - print '4804: c = config("display", 2)'; - c = config("tilde", 0); - print '4805: c = config("tilde", 0)'; - c = config("tilde_space", 1); - print '4806: c = config("tilde_space", 1)'; - c = config("leadzero", 0); - print '4807: c = config("leadzero", 0)'; - c = config("fullzero", 0); - print '4808: c = config("fullzero", 0)'; + /* setup */ + callcfg = config("all"); + print '4801: callcfg = config("all")'; + c = config("mode", "frac"); + print '4802: c = config("mode", "frac")'; + c = config("outround", 24); + print '4803: c = config("outround", 24)'; + c = config("display", 2); + print '4804: c = config("display", 2)'; + c = config("tilde", 0); + print '4805: c = config("tilde", 0)'; + c = config("tilde_space", 1); + print '4806: c = config("tilde_space", 1)'; + c = config("leadzero", 0); + print '4807: c = config("leadzero", 0)'; + c = config("fullzero", 0); + print '4808: c = config("fullzero", 0)'; - /* tests with tilde == 0 */ - vrfy(strprintf("%d%d", 27, 29) == "2729", - '4809: strprintf("%d%d", 27, 29) == "2729"'); - vrfy(strprintf("%5d%3d", 27, 29) == " 27 29", - '4810: strprintf("%5d%3d", 27, 29) == " 27 29"; '); - vrfy(strprintf("%-5d%-3d", 27, 29) == "27 29 ", - '4811: strprintf("%-5d%-3d", 27, 29) == "27 29 "'); - vrfy(strprintf("%f", 1.375) == "1.38", - '4812: strprintf("%f", 1.375) == "1.38"'); - vrfy(strprintf("%f", 1.385) == "1.38", - '4813: strprintf("%f", 1.385) == "1.38"'); - vrfy(strprintf("%f", .375) == ".38", - '4814: strprintf("%f", .375) == ".38"'); - vrfy(strprintf("%f", .385) == ".38", - '4815: strprintf("%f", .385) == ".38"'); + /* tests with tilde == 0 */ + vrfy(strprintf("%d%d", 27, 29) == "2729", + '4809: strprintf("%d%d", 27, 29) == "2729"'); + vrfy(strprintf("%5d%3d", 27, 29) == " 27 29", + '4810: strprintf("%5d%3d", 27, 29) == " 27 29"; '); + vrfy(strprintf("%-5d%-3d", 27, 29) == "27 29 ", + '4811: strprintf("%-5d%-3d", 27, 29) == "27 29 "'); + vrfy(strprintf("%f", 1.375) == "1.38", + '4812: strprintf("%f", 1.375) == "1.38"'); + vrfy(strprintf("%f", 1.385) == "1.38", + '4813: strprintf("%f", 1.385) == "1.38"'); + vrfy(strprintf("%f", .375) == ".38", + '4814: strprintf("%f", .375) == ".38"'); + vrfy(strprintf("%f", .385) == ".38", + '4815: strprintf("%f", .385) == ".38"'); - /* tests with tilde == 1 */ - c = config("tilde", 1); - print '4816: c = config("tilde", 1)'; - vrfy(strprintf("%f", 1.375) == "~ 1.38", - '4817: strprintf("%f", 1.375) == "~ 1.38"'); - vrfy(strprintf("%f", 27/29) == "~ .93", - '4818: strprintf("%f", 27/29) == "~ .93"'); - vrfy(strprintf("%r", 27/29) == "27/29", - '4819: strprintf("%r", 27/29) == "27/29"'); - vrfy(strprintf("%o", 27/29) == "033/035", - '4820: strprintf("%o", 27/29) == "033/035"'); - vrfy(strprintf("%x", 27/29) == "0x1b/0x1d", - '4821: strprintf("%x", 27/29) == "0x1b/0x1d"'); - vrfy(strprintf("%b", 27/29) == "0b11011/0b11101", - '4822: strprintf("%b", 27/29) == "0b11011/0b11101"'); - vrfy(strprintf("%e", 12345) == "~ 1.23e4", - '4823: strprintf("%e", 12345) == "~ 1.23e4"'); - vrfy(strprintf("%g", .385) == "~ .38", - '4824: strprintf("%g", .385) == "~ .38"'); - vrfy(strprintf("%g", 385) == "~ 3.8e2", - '4825: strprintf("%g", 385) == "~ 3.8e2"'); + /* tests with tilde == 1 */ + c = config("tilde", 1); + print '4816: c = config("tilde", 1)'; + vrfy(strprintf("%f", 1.375) == "~ 1.38", + '4817: strprintf("%f", 1.375) == "~ 1.38"'); + vrfy(strprintf("%f", 27/29) == "~ .93", + '4818: strprintf("%f", 27/29) == "~ .93"'); + vrfy(strprintf("%r", 27/29) == "27/29", + '4819: strprintf("%r", 27/29) == "27/29"'); + vrfy(strprintf("%o", 27/29) == "033/035", + '4820: strprintf("%o", 27/29) == "033/035"'); + vrfy(strprintf("%x", 27/29) == "0x1b/0x1d", + '4821: strprintf("%x", 27/29) == "0x1b/0x1d"'); + vrfy(strprintf("%b", 27/29) == "0b11011/0b11101", + '4822: strprintf("%b", 27/29) == "0b11011/0b11101"'); + vrfy(strprintf("%e", 12345) == "~ 1.23e4", + '4823: strprintf("%e", 12345) == "~ 1.23e4"'); + vrfy(strprintf("%g", .385) == "~ .38", + '4824: strprintf("%g", .385) == "~ .38"'); + vrfy(strprintf("%g", 385) == "~ 3.8e2", + '4825: strprintf("%g", 385) == "~ 3.8e2"'); - /* tests with tilde == 1 and tilde_space == 0 */ - c = config("tilde_space", 0); - print '4826: c = config("tilde_space", 0)'; - vrfy(strprintf("%f", 1.375) == "~1.38", - '4827: strprintf("%f", 1.375) == "~1.38"'); - vrfy(strprintf("%f", 27/29) == "~.93", - '4828: strprintf("%f", 27/29) == "~.93"'); - vrfy(strprintf("%e", 12345) == "~1.23e4", - '4829: strprintf("%e", 12345) == "~1.23e4"'); - vrfy(strprintf("%g", .385) == "~.38", - '4830: strprintf("%g", .385) == "~.38"'); - vrfy(strprintf("%g", 385) == "~3.8e2", - '4831: strprintf("%g", 385) == "~3.8e2"'); + /* tests with tilde == 1 and tilde_space == 0 */ + c = config("tilde_space", 0); + print '4826: c = config("tilde_space", 0)'; + vrfy(strprintf("%f", 1.375) == "~1.38", + '4827: strprintf("%f", 1.375) == "~1.38"'); + vrfy(strprintf("%f", 27/29) == "~.93", + '4828: strprintf("%f", 27/29) == "~.93"'); + vrfy(strprintf("%e", 12345) == "~1.23e4", + '4829: strprintf("%e", 12345) == "~1.23e4"'); + vrfy(strprintf("%g", .385) == "~.38", + '4830: strprintf("%g", .385) == "~.38"'); + vrfy(strprintf("%g", 385) == "~3.8e2", + '4831: strprintf("%g", 385) == "~3.8e2"'); - /* tests with tilde_space == 0 */ - c = config("tilde_space", 1); - print '4832: c = config("tilde_space", 1)'; - vrfy(strprintf("%f", 1.375) == "~ 1.38", - '4833: strprintf("%f", 1.375) == "~ 1.38"'); - vrfy(strprintf("%f", 27/29) == "~ .93", - '4834: strprintf("%f", 27/29) == "~ .93"'); - vrfy(strprintf("%e", 12345) == "~ 1.23e4", - '4835: strprintf("%e", 12345) == "~ 1.23e4"'); - vrfy(strprintf("%g", .385) == "~ .38", - '4836: strprintf("%g", .385) == "~ .38"'); - vrfy(strprintf("%g", 385) == "~ 3.8e2", - '4837: strprintf("%g", 385) == "~ 3.8e2"'); + /* tests with tilde_space == 0 */ + c = config("tilde_space", 1); + print '4832: c = config("tilde_space", 1)'; + vrfy(strprintf("%f", 1.375) == "~ 1.38", + '4833: strprintf("%f", 1.375) == "~ 1.38"'); + vrfy(strprintf("%f", 27/29) == "~ .93", + '4834: strprintf("%f", 27/29) == "~ .93"'); + vrfy(strprintf("%e", 12345) == "~ 1.23e4", + '4835: strprintf("%e", 12345) == "~ 1.23e4"'); + vrfy(strprintf("%g", .385) == "~ .38", + '4836: strprintf("%g", .385) == "~ .38"'); + vrfy(strprintf("%g", 385) == "~ 3.8e2", + '4837: strprintf("%g", 385) == "~ 3.8e2"'); - /* mode tests with tilde == 0 */ - c = config("tilde", 0); - print '4838: c = config("tilde", 0)'; - vrfy(strprintf("%e", 12345) == "1.23e4", - '4839: strprintf("%e", 12345) == "1.23e4"'); - vrfy(strprintf("%.3e", 12345) == "1.234e4", - '4840: strprintf("%.3e", 12345) == "1.234e4"'); - vrfy(strprintf("%e", .00012345) == "1.23e-4", - '4841: strprintf("%e", .00012345) == "1.23e-4"'); - vrfy(strprintf("%d %d", 27) == "27 ", - '4842: strprintf("%d %d", 27) == "27 "'); - vrfy(strprintf("%d", 27, 29) == "27", - '4843: strprintf("%d", 27, 29) == "27"'); - vrfy(strprintf("%r = %f", 27/29, 27/29) == "27/29 = .93", - '4844: strprintf("%r = %f", 27/29, 27/29) == "27/29 = .93"'); - vrfy(strprintf("%s", "abc") == "abc", - '4845: strprintf("%s", "abc") == "abc"'); - vrfy(strprintf("%f", "abc") == "abc", - '4846: strprintf("%f", "abc") == "abc"'); - vrfy(strprintf("%e", "abc") == "abc", - '4847: strprintf("%e", "abc") == "abc"'); - vrfy(strprintf("%5s", "abc") == " abc", - '4848: strprintf("%5s", "abc") == " abc"'); - vrfy(strprintf("%-5s", "abc") == "abc ", - '4849: strprintf("%-5s", "abc") == "abc "'); - vrfy(strprintf("%g", .385) == ".38", - '4850: strprintf("%g", .385) == ".38"'); - vrfy(strprintf("%g", 385) == "3.8e2", - '4851: strprintf("%g", 385) == "3.8e2"'); + /* mode tests with tilde == 0 */ + c = config("tilde", 0); + print '4838: c = config("tilde", 0)'; + vrfy(strprintf("%e", 12345) == "1.23e4", + '4839: strprintf("%e", 12345) == "1.23e4"'); + vrfy(strprintf("%.3e", 12345) == "1.234e4", + '4840: strprintf("%.3e", 12345) == "1.234e4"'); + vrfy(strprintf("%e", .00012345) == "1.23e-4", + '4841: strprintf("%e", .00012345) == "1.23e-4"'); + vrfy(strprintf("%d %d", 27) == "27 ", + '4842: strprintf("%d %d", 27) == "27 "'); + vrfy(strprintf("%d", 27, 29) == "27", + '4843: strprintf("%d", 27, 29) == "27"'); + vrfy(strprintf("%r = %f", 27/29, 27/29) == "27/29 = .93", + '4844: strprintf("%r = %f", 27/29, 27/29) == "27/29 = .93"'); + vrfy(strprintf("%s", "abc") == "abc", + '4845: strprintf("%s", "abc") == "abc"'); + vrfy(strprintf("%f", "abc") == "abc", + '4846: strprintf("%f", "abc") == "abc"'); + vrfy(strprintf("%e", "abc") == "abc", + '4847: strprintf("%e", "abc") == "abc"'); + vrfy(strprintf("%5s", "abc") == " abc", + '4848: strprintf("%5s", "abc") == " abc"'); + vrfy(strprintf("%-5s", "abc") == "abc ", + '4849: strprintf("%-5s", "abc") == "abc "'); + vrfy(strprintf("%g", .385) == ".38", + '4850: strprintf("%g", .385) == ".38"'); + vrfy(strprintf("%g", 385) == "3.8e2", + '4851: strprintf("%g", 385) == "3.8e2"'); - c = config("fraction_space", 1); - print '4852: c = config("fraction_space", 1)'; - vrfy(strprintf("%r = %f", 27/29, 27/29) == "27 / 29 = .93", - '4853: strprintf("%r = %f", 27/29, 27/29) == "27 / 29 = .93"'); + c = config("fraction_space", 1); + print '4852: c = config("fraction_space", 1)'; + vrfy(strprintf("%r = %f", 27/29, 27/29) == "27 / 29 = .93", + '4853: strprintf("%r = %f", 27/29, 27/29) == "27 / 29 = .93"'); - /* restore config */ - c = config("all", callcfg); - print '4854: c = config("all", callcfg)'; + /* restore config */ + c = config("all", callcfg); + print '4854: c = config("all", callcfg)'; - print '4855: Ending test_strprintf'; + print '4855: Ending test_strprintf'; } print '088: parsed test_strprintf()'; @@ -5057,53 +5057,53 @@ print '088: parsed test_strprintf()'; * test 089-123: global and static assignment tests */ global a = 10, b, c d = 20, e; -print '089: global a = 10, b, c d = 20, e, f'; -vrfy(a == 10, '090: a == 10'); -vrfy(b == 0, '091: b == 0'); -vrfy(c == 20, '092: c == 20'); -vrfy(d == 20, '093: d == 20'); -vrfy(e == 0, '094: e == 0'); -vrfy(f == 0, '095: f == 0'); +print '089: global a = 10, b, c d = 20, e, f'; +vrfy(a == 10, '090: a == 10'); +vrfy(b == 0, '091: b == 0'); +vrfy(c == 20, '092: c == 20'); +vrfy(d == 20, '093: d == 20'); +vrfy(e == 0, '094: e == 0'); +vrfy(f == 0, '095: f == 0'); static a b = 30, c, e = 30; -print '096: static a b = 30, c, e = 30'; -vrfy(a == 30, '097: a == 30'); -vrfy(b == 30, '098: b == 30'); -vrfy(c == 0, '099: c == 0'); -vrfy(e == 30, '100: e == 30'); +print '096: static a b = 30, c, e = 30'; +vrfy(a == 30, '097: a == 30'); +vrfy(b == 30, '098: b == 30'); +vrfy(c == 0, '099: c == 0'); +vrfy(e == 30, '100: e == 30'); global a, b; -print '101: global a, b'; -vrfy(a == 10, '102: a == 10'); -vrfy(b == 0, '103: b == 0'); +print '101: global a, b'; +vrfy(a == 10, '102: a == 10'); +vrfy(b == 0, '103: b == 0'); static mat A, B[2,2] = {1,2,3,4}; -print '104: static mat A, B[2,2] = {1,2,3,4}'; +print '104: static mat A, B[2,2] = {1,2,3,4}'; define f100(x,y) = (mat [2,2] = {x,0,0,y}) * A; -print '105: define f100(x,y) = (mat [2,2] = {x,0,0,y}) * A'; +print '105: define f100(x,y) = (mat [2,2] = {x,0,0,y}) * A'; define g100(x) = (mat[2,2] = {x,x,x,x}) + B; -print '106: define g100(x) = (mat[2,2] = {x,x,x,x}) + B'; +print '106: define g100(x) = (mat[2,2] = {x,x,x,x}) + B'; define h100(a,b,c,d) = ((B = {a,b,c,d}), null()); -print '107: define h100(a,b,c,d) = ((B = {a,b,c,d}), null())'; +print '107: define h100(a,b,c,d) = ((B = {a,b,c,d}), null())'; global A, B; -print '108: global A, B'; -vrfy(A == 0, '109: A == 0'); -vrfy(B == 0, '110: B == 0'); +print '108: global A, B'; +vrfy(A == 0, '109: A == 0'); +vrfy(B == 0, '110: B == 0'); x = test(f100(2,3) == (mat[2,2] = {2, 4, 9, 12})); -vrfy(x, '111: test(f100(2,3) == (mat[2,2] = {2, 4, 9, 12}))'); +vrfy(x, '111: test(f100(2,3) == (mat[2,2] = {2, 4, 9, 12}))'); x = test(g100(4) == (mat[2,2] = {5,6,7,8})); -vrfy(x, '112: test(g100(4) == (mat[2,2] = {5,6,7,8}))'); +vrfy(x, '112: test(g100(4) == (mat[2,2] = {5,6,7,8}))'); x = test(h100(2,3,5,7) == null()); -vrfy(x, '113: test(h100(2,3,5,7) == null())'); +vrfy(x, '113: test(h100(2,3,5,7) == null())'); x = test(g100(4) == (mat[2,2] = {6,7,9,11})); -vrfy(x, '114: test(g100(4) == (mat[2,2] = {6,7,9,11}))'); +vrfy(x, '114: test(g100(4) == (mat[2,2] = {6,7,9,11}))'); global obj point {x,y} P Q = {1,2}, R={3,4}, S; -print '115: global obj point {x,y} P, Q = {1,2}, R={3,4}, S'; -vrfy(P.x == 1, '116: P.x == 1'); -vrfy(P.y == 2, '117: P.y == 2'); -vrfy(Q.x == 1, '118: Q.x == 1'); -vrfy(Q.y == 2, '119: Q.y == 2'); -vrfy(R.x == 3, '120: R.x == 3'); -vrfy(R.y == 4, '121: R.y == 4'); -vrfy(S.x == 0, '122: S.x == 0'); -vrfy(S.y == 0, '123: S.y == 0'); +print '115: global obj point {x,y} P, Q = {1,2}, R={3,4}, S'; +vrfy(P.x == 1, '116: P.x == 1'); +vrfy(P.y == 2, '117: P.y == 2'); +vrfy(Q.x == 1, '118: Q.x == 1'); +vrfy(Q.y == 2, '119: Q.y == 2'); +vrfy(R.x == 3, '120: R.x == 3'); +vrfy(R.y == 4, '121: R.y == 4'); +vrfy(S.x == 0, '122: S.x == 0'); +vrfy(S.y == 0, '123: S.y == 0'); /* @@ -5113,32 +5113,32 @@ vrfy(S.y == 0, '123: S.y == 0'); */ define test_listsearch() { - local L; + local L; - print '4900: Beginning test_listsearch'; + print '4900: Beginning test_listsearch'; - L = list(); - print '4901: L = list()'; - vrfy(isnull(search(L,1)), '4902: isnull(search(L,1))'); - vrfy(isnull(rsearch(L,1)), '4903: isnull(search(L,1))'); - L = list(0,1,2,3,0,1,2,3,0,1); - print '4904: L = list(0,1,2,3,0,1,2,3,0,1)'; - vrfy(search(L,0) == 0, '4905: search(L,0) == 0'); - vrfy(rsearch(L,0) == 8, '4906: rsearch(L,0) == 8'); - vrfy(search(L,0,2) == 4, '4907: search(L,0,2) == 4'); - vrfy(rsearch(L,0,7) == 4, '4908: rsearch(L,0,7) == 4'); - vrfy(isnull(search(L,2,7)), '4909: isnull(search(L,2,7))'); - vrfy(isnull(rsearch(L,3,2)), '4910: isnull(rsearch(L,3,2))'); - vrfy(isnull(search(L,0,1,4)), '4911: isnull(search(L,0,1,4)'); - vrfy(isnull(rsearch(L,0,1,4)), '4912: isnull(rsearch(L,0,1,4)'); - vrfy(search(L,0,-5) == 8, '4913: search(L,0,-5) == 8'); - vrfy(rsearch(L,0,-9,-2) == 4, '4914: rsearch(L,0,-9,-2) == 4'); - vrfy(isnull(search(L,3,20)), '4915: isnull(search(L,3,20)'); - vrfy(isnull(search(L,3,0,-20)), '4916: isnull(search(L,3,0,-20)'); - vrfy(isnull(rsearch(L,3,20,2)), '4917: isnull(rsearch(L,3,20,2)'); - vrfy(rsearch(L,3,-20,20) == 7, '4918: rsearch(L,3,-20,20) == 7'); + L = list(); + print '4901: L = list()'; + vrfy(isnull(search(L,1)), '4902: isnull(search(L,1))'); + vrfy(isnull(rsearch(L,1)), '4903: isnull(search(L,1))'); + L = list(0,1,2,3,0,1,2,3,0,1); + print '4904: L = list(0,1,2,3,0,1,2,3,0,1)'; + vrfy(search(L,0) == 0, '4905: search(L,0) == 0'); + vrfy(rsearch(L,0) == 8, '4906: rsearch(L,0) == 8'); + vrfy(search(L,0,2) == 4, '4907: search(L,0,2) == 4'); + vrfy(rsearch(L,0,7) == 4, '4908: rsearch(L,0,7) == 4'); + vrfy(isnull(search(L,2,7)), '4909: isnull(search(L,2,7))'); + vrfy(isnull(rsearch(L,3,2)), '4910: isnull(rsearch(L,3,2))'); + vrfy(isnull(search(L,0,1,4)), '4911: isnull(search(L,0,1,4)'); + vrfy(isnull(rsearch(L,0,1,4)), '4912: isnull(rsearch(L,0,1,4)'); + vrfy(search(L,0,-5) == 8, '4913: search(L,0,-5) == 8'); + vrfy(rsearch(L,0,-9,-2) == 4, '4914: rsearch(L,0,-9,-2) == 4'); + vrfy(isnull(search(L,3,20)), '4915: isnull(search(L,3,20)'); + vrfy(isnull(search(L,3,0,-20)), '4916: isnull(search(L,3,0,-20)'); + vrfy(isnull(rsearch(L,3,20,2)), '4917: isnull(rsearch(L,3,20,2)'); + vrfy(rsearch(L,3,-20,20) == 7, '4918: rsearch(L,3,-20,20) == 7'); - print '4919: Ending test_listsearch'; + print '4919: Ending test_listsearch'; } print '124: parsed test_listsearch()'; @@ -5153,141 +5153,141 @@ print '124: parsed test_listsearch()'; */ define test_filesearch() { - local f, g; /* open files */ - local s; /* local string */ - local a, b, c, d; /* new error values */ - local x; + local f, g; /* open files */ + local s; /* local string */ + local a, b, c, d; /* new error values */ + local x; - print '5000: Beginning test_filesearch'; + print '5000: Beginning test_filesearch'; - /* - * setup - */ - print '5001: x = rm("-f", "junk5000")'; - x = rm("-f", "junk5000"); - f = fopen("junk5000", "w"); - print '5002: f = fopen("junk5000", "w")'; - if (iserror(f)) { - prob("Unable to open \"junk5000\" for writing"); - return; - } - print '5003: if (iserror(f)) { ... }'; - s = "alpha beta gamma "; - print '5004: s = "alpha beta gamma "'; + /* + * setup + */ + print '5001: x = rm("-f", "junk5000")'; + x = rm("-f", "junk5000"); + f = fopen("junk5000", "w"); + print '5002: f = fopen("junk5000", "w")'; + if (iserror(f)) { + prob("Unable to open \"junk5000\" for writing"); + return; + } + print '5003: if (iserror(f)) { ... }'; + s = "alpha beta gamma "; + print '5004: s = "alpha beta gamma "'; - fputs(f, s); - print '5005: fputs(f, s)'; - fflush(f); - print '5006: fflush(f)'; - print '5007: test unused'; + fputs(f, s); + print '5005: fputs(f, s)'; + fflush(f); + print '5006: fflush(f)'; + print '5007: test unused'; - /* bump errmax up by 16 */ - ecnt += 16; - print '5008: ecnt += 16'; + /* bump errmax up by 16 */ + ecnt += 16; + print '5008: ecnt += 16'; - vrfy(search(f, 45) == error("E_SEARCH_2"), - '5009: search(f, 45) == error("E_SEARCH_2")'); - vrfy(search(f, "a", 1/2) == error("E_SEARCH_3"), - '5010: search(f, "a", 1/2) == error(E_SEARCH_3")'); - vrfy(search(f, "a", 0, "b") == error("E_SEARCH_4"), - '5011: search(f, "a", 0, "b") == error("E_SEARCH_4")'); - vrfy(search(f, "a", 0) == error("E_SEARCH_6"), - '5012: search(f, "a") == error("E_SEARCH_6")'); - vrfy(rsearch(f, 45) == error("E_RSEARCH_2"), - '5013: rsearch(f, 45) == error("E_RSEARCH_2")'); - vrfy(rsearch(f, "a", "b") == error("E_RSEARCH_3"), - '5014: rsearch(f, "a", "b") == error("E_RSEARCH_3")'); - vrfy(rsearch(f, "a", 0, "b") == error("E_RSEARCH_4"), - '5015: rsearch(f, "a", 0, "b") == error("E_RSEARCH_4")'); - vrfy(rsearch(f, "a", 0) == error("E_RSEARCH_6"), - '5016: rsearch(f,"a",0) == error("E_RSEARCH_6")'); + vrfy(search(f, 45) == error("E_SEARCH_2"), + '5009: search(f, 45) == error("E_SEARCH_2")'); + vrfy(search(f, "a", 1/2) == error("E_SEARCH_3"), + '5010: search(f, "a", 1/2) == error(E_SEARCH_3")'); + vrfy(search(f, "a", 0, "b") == error("E_SEARCH_4"), + '5011: search(f, "a", 0, "b") == error("E_SEARCH_4")'); + vrfy(search(f, "a", 0) == error("E_SEARCH_6"), + '5012: search(f, "a") == error("E_SEARCH_6")'); + vrfy(rsearch(f, 45) == error("E_RSEARCH_2"), + '5013: rsearch(f, 45) == error("E_RSEARCH_2")'); + vrfy(rsearch(f, "a", "b") == error("E_RSEARCH_3"), + '5014: rsearch(f, "a", "b") == error("E_RSEARCH_3")'); + vrfy(rsearch(f, "a", 0, "b") == error("E_RSEARCH_4"), + '5015: rsearch(f, "a", 0, "b") == error("E_RSEARCH_4")'); + vrfy(rsearch(f, "a", 0) == error("E_RSEARCH_6"), + '5016: rsearch(f,"a",0) == error("E_RSEARCH_6")'); - /* errmax and errcount should be bumped up the 16 errors above */ - vrfy(errcount() == ecnt, '5017: errcount() == ecnt'); + /* errmax and errcount should be bumped up the 16 errors above */ + vrfy(errcount() == ecnt, '5017: errcount() == ecnt'); - if (freopen(f, "r")) { - prob("Unable to reopen \"junk5000\" for reading"); - return; - } - print '5018: if (freopen(f, "r")) { ... }'; - vrfy(fsize(f) == 17, '5019: fsize(f) == 17'); - vrfy(search(f, s, 0) == 0, '5020: search(f, s, 0) == 0'); - vrfy(ftell(f) == 17, '5021: ftell(f) == 17'); - vrfy(rsearch(f, s, 0) == 0, '5022: rsearch(f, s, 0) == 0'); - vrfy(ftell(f) == 16, '5023: ftell(f) == 16'); - vrfy(search(f, "", 2) == 2, '5024: search(f, "", 2) == 2'); - vrfy(ftell(f) == 2, '5025: ftell(f) == 2'); - vrfy(search(f, "", 17) == 17, '5026: search(f, "", 17) == 17'); - vrfy(ftell(f) == 17, '5027: ftell(f) == 17'); - vrfy(isnull(search(f, "", 100)), - '5028: isnull(search(f, "", 100))'); - vrfy(ftell(f) == 17, '5029: ftell(f) == 17'); - vrfy(rsearch(f, "", 5) == 5, '5030: rsearch(f, "", 5) == 5'); - vrfy(ftell(f) == 5, '5031: ftell(f) == 5'); - vrfy(search(f, "beta", 0) == 6, '5032: search(f, "beta", 0) == 6'); - vrfy(ftell(f) == 10, '5033: ftell(f) == 10'); - vrfy(rsearch(f, "beta", 100) == 6, - '5034: rsearch(f, "beta", 100) == 6'); - vrfy(ftell(f) == 9, '5035: ftell(f) == 9'); - vrfy(search(f, "a", 2) == 4, '5036: search(f, "a", 2) == 4'); - vrfy(ftell(f) == 5, '5037: ftell(f) == 5'); - vrfy(search(f, "a", 4) == 4, '5038: search(f, "a", 4) == 4'); - vrfy(search(f, "m") == 13, '5039: search(f, "m") == 13'); - vrfy(search(f, "m") == 14, '5040: search(f, "m") == 14'); - vrfy(isnull(search(f, "m")), '5041: isnull(search(f, "m"))'); - vrfy(rsearch(f, "m", 15) == 14, '5042: rsearch(f, "m", 14) == 14'); - vrfy(isnull(search(f, "beta", 7)), - '5043: isnull(search(f, "beta", 7))'); - vrfy(ftell(f) == 14, '5044: ftell(f) == 14'); - vrfy(search(f,"a",2,15) == 4, '5045: search(f,"a",2,15) == 4'); - vrfy(ftell(f) == 5, '5046: ftell(f) == 5'); - vrfy(isnull(search(f,"a",2,4)), '5047: isnull(search(f,"a",2,4))'); - vrfy(ftell(f) == 4, '5048: ftell(f) == 4'); - vrfy(search(f,"a",,5) == 4, '5049: search(f,"a",,5) == 4'); - vrfy(rsearch(f,"a",2,15) == 12, '5050: rsearch(f,"a",2,15) == 12'); - vrfy(ftell(f) == 12, '5051: ftell(f) == 12'); - vrfy(rsearch(f,"a",2,12) == 9, '5052: rsearch(f,"a",2,12) == 9'); + if (freopen(f, "r")) { + prob("Unable to reopen \"junk5000\" for reading"); + return; + } + print '5018: if (freopen(f, "r")) { ... }'; + vrfy(fsize(f) == 17, '5019: fsize(f) == 17'); + vrfy(search(f, s, 0) == 0, '5020: search(f, s, 0) == 0'); + vrfy(ftell(f) == 17, '5021: ftell(f) == 17'); + vrfy(rsearch(f, s, 0) == 0, '5022: rsearch(f, s, 0) == 0'); + vrfy(ftell(f) == 16, '5023: ftell(f) == 16'); + vrfy(search(f, "", 2) == 2, '5024: search(f, "", 2) == 2'); + vrfy(ftell(f) == 2, '5025: ftell(f) == 2'); + vrfy(search(f, "", 17) == 17, '5026: search(f, "", 17) == 17'); + vrfy(ftell(f) == 17, '5027: ftell(f) == 17'); + vrfy(isnull(search(f, "", 100)), + '5028: isnull(search(f, "", 100))'); + vrfy(ftell(f) == 17, '5029: ftell(f) == 17'); + vrfy(rsearch(f, "", 5) == 5, '5030: rsearch(f, "", 5) == 5'); + vrfy(ftell(f) == 5, '5031: ftell(f) == 5'); + vrfy(search(f, "beta", 0) == 6, '5032: search(f, "beta", 0) == 6'); + vrfy(ftell(f) == 10, '5033: ftell(f) == 10'); + vrfy(rsearch(f, "beta", 100) == 6, + '5034: rsearch(f, "beta", 100) == 6'); + vrfy(ftell(f) == 9, '5035: ftell(f) == 9'); + vrfy(search(f, "a", 2) == 4, '5036: search(f, "a", 2) == 4'); + vrfy(ftell(f) == 5, '5037: ftell(f) == 5'); + vrfy(search(f, "a", 4) == 4, '5038: search(f, "a", 4) == 4'); + vrfy(search(f, "m") == 13, '5039: search(f, "m") == 13'); + vrfy(search(f, "m") == 14, '5040: search(f, "m") == 14'); + vrfy(isnull(search(f, "m")), '5041: isnull(search(f, "m"))'); + vrfy(rsearch(f, "m", 15) == 14, '5042: rsearch(f, "m", 14) == 14'); + vrfy(isnull(search(f, "beta", 7)), + '5043: isnull(search(f, "beta", 7))'); + vrfy(ftell(f) == 14, '5044: ftell(f) == 14'); + vrfy(search(f,"a",2,15) == 4, '5045: search(f,"a",2,15) == 4'); + vrfy(ftell(f) == 5, '5046: ftell(f) == 5'); + vrfy(isnull(search(f,"a",2,4)), '5047: isnull(search(f,"a",2,4))'); + vrfy(ftell(f) == 4, '5048: ftell(f) == 4'); + vrfy(search(f,"a",,5) == 4, '5049: search(f,"a",,5) == 4'); + vrfy(rsearch(f,"a",2,15) == 12, '5050: rsearch(f,"a",2,15) == 12'); + vrfy(ftell(f) == 12, '5051: ftell(f) == 12'); + vrfy(rsearch(f,"a",2,12) == 9, '5052: rsearch(f,"a",2,12) == 9'); - /* generate 2 more errors */ - ecnt += 2; - print '5053: ecnt += 2'; - a = 2 + ""; - print '5054: a = 2 + ""'; - g = fopen(3, "r"); - print '5055: g = fopen(3, "r")'; - c = 5^2; - print '5056: c = 5^2'; - vrfy(errcount() == ecnt, '5057: errcount() == ecnt'); + /* generate 2 more errors */ + ecnt += 2; + print '5053: ecnt += 2'; + a = 2 + ""; + print '5054: a = 2 + ""'; + g = fopen(3, "r"); + print '5055: g = fopen(3, "r")'; + c = 5^2; + print '5056: c = 5^2'; + vrfy(errcount() == ecnt, '5057: errcount() == ecnt'); - /* generate 4 more errors by testing newerror */ - ecnt += 4; - print '5058: ecnt += 4'; - a = newerror("alpha"); - print '5059: a = newerror("alpha")'; - b = newerror("beta"); - print '5060: b = newerror("beta")'; - c = newerror("alpha"); - print '5061: c = newerror("alpha")'; - d = newerror("beta"); - print '5062: d = newerror("beta")'; - vrfy(errcount() == ecnt, '5063: errcount() == ecnt'); - vrfy(a == c, '5064: a == c'); - vrfy(b == d, '5065: b == d'); + /* generate 4 more errors by testing newerror */ + ecnt += 4; + print '5058: ecnt += 4'; + a = newerror("alpha"); + print '5059: a = newerror("alpha")'; + b = newerror("beta"); + print '5060: b = newerror("beta")'; + c = newerror("alpha"); + print '5061: c = newerror("alpha")'; + d = newerror("beta"); + print '5062: d = newerror("beta")'; + vrfy(errcount() == ecnt, '5063: errcount() == ecnt'); + vrfy(a == c, '5064: a == c'); + vrfy(b == d, '5065: b == d'); - /* test error(0) */ - error(0); - print '5066: error(0)'; - vrfy(strerror() == "No error", '5067: strerror() == "No error"'); + /* test error(0) */ + error(0); + print '5066: error(0)'; + vrfy(strerror() == "No error", '5067: strerror() == "No error"'); - /* - * close down - */ - fclose(f); - print '5068: fclose(f)'; - rm("junk5000"); - print '5069: rm("junk5000")'; + /* + * close down + */ + fclose(f); + print '5068: fclose(f)'; + rm("junk5000"); + print '5069: rm("junk5000")'; - print '5070: Ending test_filesearch'; + print '5070: Ending test_filesearch'; } print '125: parsed test_filesearch()'; @@ -5303,53 +5303,53 @@ print '126: read -once test5100.newdecl'; define test_newdecl() { - print '5100: Beginning test_newdecl'; + print '5100: Beginning test_newdecl'; - /* - * test5100 calls - */ - test5100(1); - print '5101: test5100(1)'; - vrfy(a5100 == 0, '5102: a5100 == 0'); - vrfy(b5100 == 2, '5103: b5100 == 2'); - test5100(1); - print '5104: test5100(1)'; - vrfy(a5100 == 0, '5105: a5100 == 0'); - vrfy(b5100 == 3, '5106: b5100 == 3'); - test5100(1); - print '5107: test5100(1)'; - vrfy(a5100 == 0, '5108: a5100 == 0'); - vrfy(b5100 == 4, '5109: b5100 == 4'); - test5100(2); - print '5110: test5100(2)'; - vrfy(a5100 == 3, '5111: a5100 == 3'); - vrfy(b5100 == 4, '5112: b5100 == 4'); - test5100(2); - print '5113: test5100(2)'; - vrfy(a5100 == 4, '5114: a5100 == 4'); - vrfy(b5100 == 4, '5115: b5100 == 4'); - test5100(2); - print '5116: test5100(2)'; - vrfy(a5100 == 5, '5117: a5100 == 5'); - vrfy(b5100 == 4, '5118: b5100 == 4'); - test5100(3); - print '5119: test5100(3)'; - vrfy(a5100 == 5, '5120: a5100 == 5'); - vrfy(b5100 == 5, '5121: b5100 == 5'); - test5100(9); - print '5122: test5100(9)'; - vrfy(a5100 == 5, '5123: a5100 == 5'); - vrfy(b5100 == 6, '5124: b5100 == 6'); - test5100(0); - print '5125: test5100(0)'; - vrfy(a5100 == 5, '5126: a5100 == 5'); - vrfy(b5100 == 6, '5127: b5100 == 6'); - test5100(-1); - print '5128: test5100(-1)'; - vrfy(a5100 == 5, '5129: a5100 == 5'); - vrfy(b5100 == 6, '5130: b5100 == 6'); + /* + * test5100 calls + */ + test5100(1); + print '5101: test5100(1)'; + vrfy(a5100 == 0, '5102: a5100 == 0'); + vrfy(b5100 == 2, '5103: b5100 == 2'); + test5100(1); + print '5104: test5100(1)'; + vrfy(a5100 == 0, '5105: a5100 == 0'); + vrfy(b5100 == 3, '5106: b5100 == 3'); + test5100(1); + print '5107: test5100(1)'; + vrfy(a5100 == 0, '5108: a5100 == 0'); + vrfy(b5100 == 4, '5109: b5100 == 4'); + test5100(2); + print '5110: test5100(2)'; + vrfy(a5100 == 3, '5111: a5100 == 3'); + vrfy(b5100 == 4, '5112: b5100 == 4'); + test5100(2); + print '5113: test5100(2)'; + vrfy(a5100 == 4, '5114: a5100 == 4'); + vrfy(b5100 == 4, '5115: b5100 == 4'); + test5100(2); + print '5116: test5100(2)'; + vrfy(a5100 == 5, '5117: a5100 == 5'); + vrfy(b5100 == 4, '5118: b5100 == 4'); + test5100(3); + print '5119: test5100(3)'; + vrfy(a5100 == 5, '5120: a5100 == 5'); + vrfy(b5100 == 5, '5121: b5100 == 5'); + test5100(9); + print '5122: test5100(9)'; + vrfy(a5100 == 5, '5123: a5100 == 5'); + vrfy(b5100 == 6, '5124: b5100 == 6'); + test5100(0); + print '5125: test5100(0)'; + vrfy(a5100 == 5, '5126: a5100 == 5'); + vrfy(b5100 == 6, '5127: b5100 == 6'); + test5100(-1); + print '5128: test5100(-1)'; + vrfy(a5100 == 5, '5129: a5100 == 5'); + vrfy(b5100 == 6, '5130: b5100 == 6'); - print '5131: Ending test_newdecl'; + print '5131: Ending test_newdecl'; } print '127: parsed test_newdecl()'; @@ -5365,32 +5365,32 @@ print '128: read -once test5200.globstat'; /**/ define test_globstat() { - print '5200: Beginning test_globstat'; + print '5200: Beginning test_globstat'; - /* - * test {f,g,h}5200 calls - */ - vrfy(a5200 == 10, '5201: a5200 == 10'); - vrfy(eval("a5200") == 10, '5202: eval("a5200") == 10'); - vrfy(f5200(1) == 21, '5203: f5200(1) == 21'); - vrfy(a5200 == 10, '5204: a5200 == 10'); - vrfy(eval("a5200") == 10, '5205: eval("a5200") == 10'); - vrfy(h5200(2) == 12, '5206: h5200(2) == 12'); - vrfy(a5200 == 10, '5207: a5200 == 10'); - vrfy(eval("a5200") == 10, '5208: eval("a5200") == 10'); - vrfy(g5200(3) == 33, '5209: g5200(3) == 33'); - vrfy(a5200 == 30, '5210: a5200 == 30'); - vrfy(eval("a5200") == 30, '5211: eval("a5200") == 30'); - vrfy(h5200(4) == 34, '5212: h5200(4) == 34'); - vrfy(f5200(5) == 25, '5213: f5200(5) == 25'); - vrfy(h5200(6) == 36, '5214: h5200(6) == 36'); - vrfy(g5200(7) == 37, '5215: g5200(7) == 37'); - vrfy(f5200(8) == 28, '5216: f5200(8) == 28'); - vrfy(g5200(9) == 39, '5217: g5200(9) == 39'); - vrfy(a5200 == 30, '5218: a5200 == 30'); - vrfy(eval("a5200") == 30, '5219: eval("a5200") == 30'); + /* + * test {f,g,h}5200 calls + */ + vrfy(a5200 == 10, '5201: a5200 == 10'); + vrfy(eval("a5200") == 10, '5202: eval("a5200") == 10'); + vrfy(f5200(1) == 21, '5203: f5200(1) == 21'); + vrfy(a5200 == 10, '5204: a5200 == 10'); + vrfy(eval("a5200") == 10, '5205: eval("a5200") == 10'); + vrfy(h5200(2) == 12, '5206: h5200(2) == 12'); + vrfy(a5200 == 10, '5207: a5200 == 10'); + vrfy(eval("a5200") == 10, '5208: eval("a5200") == 10'); + vrfy(g5200(3) == 33, '5209: g5200(3) == 33'); + vrfy(a5200 == 30, '5210: a5200 == 30'); + vrfy(eval("a5200") == 30, '5211: eval("a5200") == 30'); + vrfy(h5200(4) == 34, '5212: h5200(4) == 34'); + vrfy(f5200(5) == 25, '5213: f5200(5) == 25'); + vrfy(h5200(6) == 36, '5214: h5200(6) == 36'); + vrfy(g5200(7) == 37, '5215: g5200(7) == 37'); + vrfy(f5200(8) == 28, '5216: f5200(8) == 28'); + vrfy(g5200(9) == 39, '5217: g5200(9) == 39'); + vrfy(a5200 == 30, '5218: a5200 == 30'); + vrfy(eval("a5200") == 30, '5219: eval("a5200") == 30'); - print '5220: Ending test_globstat'; + print '5220: Ending test_globstat'; } print '129: parsed test_globstat()'; @@ -5402,8 +5402,8 @@ print '129: parsed test_globstat()'; */ define test_newop2(x) {if (x < 0) goto l130; ++x; l130: return x;} print '130: define test_newop3(x) {if (x < 0) goto l130; ++x; l130: return x;}' -vrfy(test_newop2(100) == 101, '131: test_newop2(100) == 101'); -vrfy(test_newop2(-100) == -100, '132: test_newop2(-100) == -100'); +vrfy(test_newop2(100) == 101, '131: test_newop2(100) == 101'); +vrfy(test_newop2(-100) == -100, '132: test_newop2(-100) == -100'); /* @@ -5412,19 +5412,19 @@ vrfy(test_newop2(-100) == -100, '132: test_newop2(-100) == -100'); * This function tests more label stuff. */ define test_newop3(x) { - if (x < 4) - if (iseven(x)) - goto l135; - else - return 2; - return 3; - l135: - return 1; + if (x < 4) + if (iseven(x)) + goto l135; + else + return 2; + return 3; + l135: + return 1; } print '133: define test_newop3(x) ...'; -vrfy(test_newop3(2) == 1, '134: test_newop3(2) == 1'); -vrfy(test_newop3(3) == 2, '135: test_newop3(3) == 2'); -vrfy(test_newop3(4) == 3, '136: test_newop3(4) == 3'); +vrfy(test_newop3(2) == 1, '134: test_newop3(2) == 1'); +vrfy(test_newop3(3) == 2, '135: test_newop3(3) == 2'); +vrfy(test_newop3(4) == 3, '136: test_newop3(4) == 3'); /* @@ -5434,335 +5434,335 @@ vrfy(test_newop3(4) == 3, '136: test_newop3(4) == 3'); */ define test_random() { - local init; /* initial generator state */ - local state0; /* a generator state */ - local state1; /* a generator state */ - local tmp; - local n; + local init; /* initial generator state */ + local state0; /* a generator state */ + local state1; /* a generator state */ + local tmp; + local n; - print '5300: Beginning random test'; + print '5300: Beginning random test'; - /* test save and restore of the initial state */ - tmp = srandom(0); - print '5301: tmp = srandom(0)'; - init = srandom(); - print '5302: init = srandom()'; - state0 = srandom(0); - print '5303: state0 = srandom(0)'; - vrfy(state0 == init, '5304: state0 == init'); + /* test save and restore of the initial state */ + tmp = srandom(0); + print '5301: tmp = srandom(0)'; + init = srandom(); + print '5302: init = srandom()'; + state0 = srandom(0); + print '5303: state0 = srandom(0)'; + vrfy(state0 == init, '5304: state0 == init'); - /* test the subtractive 100 shuffle generator */ - tmp = srandom(0); - print '5305: tmp = srandom(0)'; - vrfy(random() == 0x7fb838a8a0a95046, \ - '5306: random() == 0x7fb838a8a0a95046'); - vrfy(random() == 0xb9d9d9fb4440f7bb, \ - '5307: random() == 0xb9d9d9fb4440f7bb'); - tmp = srandom(init); - print '5308: tmp = srandom(init)'; - vrfy(random() == 0x7fb838a8a0a95046, \ - '5309: random() == 0x7fb838a8a0a95046'); - vrfy(random() == 0xb9d9d9fb4440f7bb, \ - '5310: random() == 0xb9d9d9fb4440f7bb'); + /* test the subtractive 100 shuffle generator */ + tmp = srandom(0); + print '5305: tmp = srandom(0)'; + vrfy(random() == 0x7fb838a8a0a95046, \ + '5306: random() == 0x7fb838a8a0a95046'); + vrfy(random() == 0xb9d9d9fb4440f7bb, \ + '5307: random() == 0xb9d9d9fb4440f7bb'); + tmp = srandom(init); + print '5308: tmp = srandom(init)'; + vrfy(random() == 0x7fb838a8a0a95046, \ + '5309: random() == 0x7fb838a8a0a95046'); + vrfy(random() == 0xb9d9d9fb4440f7bb, \ + '5310: random() == 0xb9d9d9fb4440f7bb'); - /* test range interface */ - tmp = srandom(0); - print '5311: tmp = srandom(0)'; - vrfy(random(12345678901234567890) == 0x7fb838a8a0a95046, \ - '5312: random(12345678901234567890) == 0x7fb838a8a0a95046'); - vrfy(random(216091) == 0x2e767, '5313: random(216091) == 0x2e767'); - vrfy(random(100) == 0x33, '5314: random(100) == 0x33'); - vrfy(random(-46,46) == -0xc, '5315: random(-46,46) == -0xc'); - tmp = srandom(0); - print '5316: tmp = srandom(0)'; - vrfy(random(2^64) == 0x7fb838a8a0a95046, \ - '5317: random(2^64) == 0x7fb838a8a0a95046'); - vrfy(random(0,2^64) == 0xb9d9d9fb4440f7bb, \ - '5318: random(0,2^64) == 0xb9d9d9fb4440f7bb'); + /* test range interface */ + tmp = srandom(0); + print '5311: tmp = srandom(0)'; + vrfy(random(12345678901234567890) == 0x7fb838a8a0a95046, \ + '5312: random(12345678901234567890) == 0x7fb838a8a0a95046'); + vrfy(random(216091) == 0x2e767, '5313: random(216091) == 0x2e767'); + vrfy(random(100) == 0x33, '5314: random(100) == 0x33'); + vrfy(random(-46,46) == -0xc, '5315: random(-46,46) == -0xc'); + tmp = srandom(0); + print '5316: tmp = srandom(0)'; + vrfy(random(2^64) == 0x7fb838a8a0a95046, \ + '5317: random(2^64) == 0x7fb838a8a0a95046'); + vrfy(random(0,2^64) == 0xb9d9d9fb4440f7bb, \ + '5318: random(0,2^64) == 0xb9d9d9fb4440f7bb'); - /* test different forms of seeding the initial state */ - tmp = srandom(0); - print '5319: tmp = srandom(0)'; - vrfy(srandom() == init, '5320: srandom() == init'); - tmp = srandom(0x87e6ec938ff55aa5<<64); - print '5321: tmp = srandom(0x87e6ec938ff55aa5<<64)'; - vrfy(srandom() == init, '5322: srandom() == init'); - tmp = srandom(state0); - print '5323: tmp = srandom(state0)'; - vrfy(srandom() == init, '5324: srandom() == init'); - tmp = srandom(init); - print '5325: tmp = srandom(init)'; - vrfy(srandom() == init, '5326: srandom() == init'); - vrfy(tmp == init, '5327: tmp == init'); + /* test different forms of seeding the initial state */ + tmp = srandom(0); + print '5319: tmp = srandom(0)'; + vrfy(srandom() == init, '5320: srandom() == init'); + tmp = srandom(0x87e6ec938ff55aa5<<64); + print '5321: tmp = srandom(0x87e6ec938ff55aa5<<64)'; + vrfy(srandom() == init, '5322: srandom() == init'); + tmp = srandom(state0); + print '5323: tmp = srandom(state0)'; + vrfy(srandom() == init, '5324: srandom() == init'); + tmp = srandom(init); + print '5325: tmp = srandom(init)'; + vrfy(srandom() == init, '5326: srandom() == init'); + vrfy(tmp == init, '5327: tmp == init'); - /* test the bit length interface */ - tmp = srandom(0); - print '5328: tmp = srandomom(0)'; - vrfy(randombit(64) == 0x7fb838a8a0a95046, \ - '5329: randombit(64) == 0x7fb838a8a0a95046'); - vrfy(randombit(128) == 0xb9d9d9fb4440f7bbc1a7bd3b4e853fc9, \ - '5330: randombit(128) == 0xb9d9d9fb4440f7bbc1a7bd3b4e853fc9'); - vrfy(randombit(64) == 0x2d4e1588719986aa, \ - '5331: randombit(64) == 0x2d4e1588719986aa'); - vrfy(randombit(128) == 0x8d68905434b020ccb849e17a03a5c441, \ - '5332: randombit(128) == 0x8d68905434b020ccb849e17a03a5c441'); - tmp = srandom(0); - print '5333: tmp = srandom(0)'; - vrfy(randombit(32) == 0x7fb838a8, '5334: randombit(32) == 0x7fb838a8'); - vrfy(randombit(32) == 0xa0a95046, '5335: randombit(32) == 0xa0a95046'); - vrfy(randombit(1) == 0x1, '5336: randombit(1) == 0x1'); - vrfy(randombit(5) == 0xe, '5337: randombit(5) == 0xe'); - vrfy(randombit(33) == 0xececfda2, '5338: randombit(33) == 0xececfda2'); - vrfy(randombit(25) == 0x40f7bb, '5339: randombit(25) == 0x40f7bb'); - vrfy(randombit(2) == 0x3, '5340: randombit(2) == 0x3'); - vrfy(randombit(13) == 0xd3, '5341: randombit(13) == 0xd3'); - vrfy(randombit(18) == 0x37a76, '5342: randombit(18) == 0x37a76'); - vrfy(randombit(8) == 0x9d, '5343: randombit(8) == 0x9d'); - vrfy(randombit(9) == 0x14, '5344: randombit(9) == 0x14'); - vrfy(randombit(70) == 0x3fc92d4e1588719986, \ - '5345: randombit(70) == 0x3fc92d4e1588719986'); - vrfy(randombit(123) == 0x5546b4482a1a5810665c24f0bd01d2e, \ - '5346: randombit(123) == 0x5546b4482a1a5810665c24f0bd01d2e'); - vrfy(randombit(8) == 0x22, '5347: randombit(8) == 0x22'); - vrfy(randombit(65) == 0x1d2a104aaf523699, \ - '5348: randombit(65) == 0x1d2a104aaf523699'); - vrfy(randombit(63) == 0x60e63d498ba690ec, \ - '5349: randombit(63) == 0x60e63d498ba690ec'); - vrfy(randombit(1) == 0x1, '5350: randombit(1) == 0x1'); - vrfy(randombit(2) == 0x3, '5351: randombit(2) == 0x3'); - vrfy(randombit(4) == 0x0, '5352: randombit(4) == 0x0'); - vrfy(randombit(3) == 0x0, '5353: randombit(3) == 0x0'); - state1 = srandom(); - print '5354: state1 = srandom()'; + /* test the bit length interface */ + tmp = srandom(0); + print '5328: tmp = srandomom(0)'; + vrfy(randombit(64) == 0x7fb838a8a0a95046, \ + '5329: randombit(64) == 0x7fb838a8a0a95046'); + vrfy(randombit(128) == 0xb9d9d9fb4440f7bbc1a7bd3b4e853fc9, \ + '5330: randombit(128) == 0xb9d9d9fb4440f7bbc1a7bd3b4e853fc9'); + vrfy(randombit(64) == 0x2d4e1588719986aa, \ + '5331: randombit(64) == 0x2d4e1588719986aa'); + vrfy(randombit(128) == 0x8d68905434b020ccb849e17a03a5c441, \ + '5332: randombit(128) == 0x8d68905434b020ccb849e17a03a5c441'); + tmp = srandom(0); + print '5333: tmp = srandom(0)'; + vrfy(randombit(32) == 0x7fb838a8, '5334: randombit(32) == 0x7fb838a8'); + vrfy(randombit(32) == 0xa0a95046, '5335: randombit(32) == 0xa0a95046'); + vrfy(randombit(1) == 0x1, '5336: randombit(1) == 0x1'); + vrfy(randombit(5) == 0xe, '5337: randombit(5) == 0xe'); + vrfy(randombit(33) == 0xececfda2, '5338: randombit(33) == 0xececfda2'); + vrfy(randombit(25) == 0x40f7bb, '5339: randombit(25) == 0x40f7bb'); + vrfy(randombit(2) == 0x3, '5340: randombit(2) == 0x3'); + vrfy(randombit(13) == 0xd3, '5341: randombit(13) == 0xd3'); + vrfy(randombit(18) == 0x37a76, '5342: randombit(18) == 0x37a76'); + vrfy(randombit(8) == 0x9d, '5343: randombit(8) == 0x9d'); + vrfy(randombit(9) == 0x14, '5344: randombit(9) == 0x14'); + vrfy(randombit(70) == 0x3fc92d4e1588719986, \ + '5345: randombit(70) == 0x3fc92d4e1588719986'); + vrfy(randombit(123) == 0x5546b4482a1a5810665c24f0bd01d2e, \ + '5346: randombit(123) == 0x5546b4482a1a5810665c24f0bd01d2e'); + vrfy(randombit(8) == 0x22, '5347: randombit(8) == 0x22'); + vrfy(randombit(65) == 0x1d2a104aaf523699, \ + '5348: randombit(65) == 0x1d2a104aaf523699'); + vrfy(randombit(63) == 0x60e63d498ba690ec, \ + '5349: randombit(63) == 0x60e63d498ba690ec'); + vrfy(randombit(1) == 0x1, '5350: randombit(1) == 0x1'); + vrfy(randombit(2) == 0x3, '5351: randombit(2) == 0x3'); + vrfy(randombit(4) == 0x0, '5352: randombit(4) == 0x0'); + vrfy(randombit(3) == 0x0, '5353: randombit(3) == 0x0'); + state1 = srandom(); + print '5354: state1 = srandom()'; - /* test randombit skip interface */ - tmp = srandom(0); - print '5355: tmp = srandom(0)'; - vrfy(randombit(20) == 523139, '5356: randombit(20) == 523139'); - vrfy(randombit(20) == 567456, '5357: randombit(20) == 567456'); - vrfy(randombit(20) == 693508, '5358: randombit(20) == 693508'); - vrfy(randombit(20) == 440793, '5359: randombit(20) == 440793'); - tmp = srandom(0); - print '5360: tmp = srandom(0)'; - vrfy(randombit(-20) == 20, '5361: randombit(-20) == 20'); - vrfy(randombit(20) == 567456, '5362: randombit(20) == 567456'); - vrfy(randombit(-20) == 20, '5363: randombit(-20) == 20'); - vrfy(randombit(20) == 440793, '5364: randombit(20) == 440793'); + /* test randombit skip interface */ + tmp = srandom(0); + print '5355: tmp = srandom(0)'; + vrfy(randombit(20) == 523139, '5356: randombit(20) == 523139'); + vrfy(randombit(20) == 567456, '5357: randombit(20) == 567456'); + vrfy(randombit(20) == 693508, '5358: randombit(20) == 693508'); + vrfy(randombit(20) == 440793, '5359: randombit(20) == 440793'); + tmp = srandom(0); + print '5360: tmp = srandom(0)'; + vrfy(randombit(-20) == 20, '5361: randombit(-20) == 20'); + vrfy(randombit(20) == 567456, '5362: randombit(20) == 567456'); + vrfy(randombit(-20) == 20, '5363: randombit(-20) == 20'); + vrfy(randombit(20) == 440793, '5364: randombit(20) == 440793'); - /* test randombit without and arg */ - tmp = srandom(0); - print '5365: tmp = srandom(0)'; - vrfy(randombit() == 0, '5366: randombit() == 0'); - vrfy(randombit() == 1, '5367: randombit() == 1'); - vrfy(randombit() == 1, '5368: randombit() == 1'); + /* test randombit without and arg */ + tmp = srandom(0); + print '5365: tmp = srandom(0)'; + vrfy(randombit() == 0, '5366: randombit() == 0'); + vrfy(randombit() == 1, '5367: randombit() == 1'); + vrfy(randombit() == 1, '5368: randombit() == 1'); - /* test range interface some more */ - tmp = srandom(state1); - print '5369: tmp = srandom(state1)'; - vrfy(random(-46,46) == -0x7, '5370: random(-46,46) == -0x7'); - vrfy(random(21701,23209) == 23061, - '5371: random(21701,23209) == 23061'); - vrfy(random(0x22,0x1d2a104aaf523699) == 0x17c97dfa80bbdf1b, - '5372: random(0x22,0x1d2a104aaf523699) == 0x17c97dfa80bbdf1b'); - vrfy(random(0x2d4e16aa,0x7fb83046) == 0x48e98d92, - '5373: random(0x2d4e16aa,0x7fb83046) == 0x48e98d92'); - vrfy(random(-0x2d4986aa,0x7fb83846) == 0x3b3f6c0c, - '5374: random(-0x2d4986aa,0x7fb83846) == 0x3b3f6c0c'); - vrfy(random(-0x2d9986aa,-0x7fb9504) == -0x235f9ce1, - '5375: random(-0x2d9986aa,-0x7fb9504) == -0x235f9ce1'); + /* test range interface some more */ + tmp = srandom(state1); + print '5369: tmp = srandom(state1)'; + vrfy(random(-46,46) == -0x7, '5370: random(-46,46) == -0x7'); + vrfy(random(21701,23209) == 23061, + '5371: random(21701,23209) == 23061'); + vrfy(random(0x22,0x1d2a104aaf523699) == 0x17c97dfa80bbdf1b, + '5372: random(0x22,0x1d2a104aaf523699) == 0x17c97dfa80bbdf1b'); + vrfy(random(0x2d4e16aa,0x7fb83046) == 0x48e98d92, + '5373: random(0x2d4e16aa,0x7fb83046) == 0x48e98d92'); + vrfy(random(-0x2d4986aa,0x7fb83846) == 0x3b3f6c0c, + '5374: random(-0x2d4986aa,0x7fb83846) == 0x3b3f6c0c'); + vrfy(random(-0x2d9986aa,-0x7fb9504) == -0x235f9ce1, + '5375: random(-0x2d9986aa,-0x7fb9504) == -0x235f9ce1'); - /* test pre-compiled random states */ - tmp = srandom(init); - print '5376: tmp = srandom(init)'; - state0 = srandom(0,1); - print '5377: state0 = srandom(0,1)'; - vrfy(randombit(123) == 0x4cf8834399f8832d5c1ec35f20095f0, \ - '5378: randombit(123) == 0x4cf8834399f8832d5c1ec35f20095f0'); - state1 = srandom(123455432112345,1); - print '5379: state1 = srandom(123455432112345,1)'; - vrfy(randombit(123) == 0x437c9618d5a9c07d935b0ff7cef7346, \ - '5380: randombit(123) == 0x437c9618d5a9c07d935b0ff7cef7346'); - tmp = srandom(0,1); - print '5381: tmp = srandom(0,1)'; - vrfy(randombit(-123) == 123, '5382: randombit(-123) == 123'); - vrfy(srandom() == state1, '5383: srandom() == state1'); - tmp = srandom(0,2); - print '5384: tmp = srandom(0,2)'; - vrfy(randombit(123) == 0x7d53b2dbfe1edcb07df84f7fe96d5e9, \ - '5385: randombit(123) == 0x7d53b2dbfe1edcb07df84f7fe96d5e9'); - tmp = srandom(0,3); - print '5386: tmp = srandom(0,3)'; - vrfy(randombit(123) == 0x365cbae1adb9a706816abe3b64c1f2a, \ - '5387: randombit(123) == 0x365cbae1adb9a706816abe3b64c1f2a'); - tmp = srandom(0,4); - print '5388: tmp = srandom(0,4)'; - vrfy(randombit(123) == 0x63d9621736e59a3a5a8311117a1ef01, \ - '5389: randombit(123) == 0x63d9621736e59a3a5a8311117a1ef01'); - tmp = srandom(0,5); - print '5390: tmp = srandom(0,5)'; - vrfy(randombit(123) == 0x38d90517d6d532d1efb6eaf26bf927, \ - '5391: randombit(123) == 0x38d90517d6d532d1efb6eaf26bf927'); - tmp = srandom(0,6); - print '5392: tmp = srandom(0,6)'; - vrfy(randombit(123) == 0x146f2a1ce8cabcc313ab24f73747fbc, \ - '5393: randombit(123) == 0x146f2a1ce8cabcc313ab24f73747fbc'); - tmp = srandom(0,7); - print '5394: tmp = srandom(0,7)'; - vrfy(randombit(123) == 0x7a4a2b4ed817e5267358ea2979155d8, \ - '5395: randombit(123) == 0x7a4a2b4ed817e5267358ea2979155d8'); - tmp = srandom(0,8); - print '5396: tmp = srandom(0,8)'; - vrfy(randombit(123) == 0x5f30f211464854a37989cca3a8ecd0a, \ - '5397: randombit(123) == 0x5f30f211464854a37989cca3a8ecd0a'); - tmp = srandom(0,9); - print '5398: tmp = srandom(0,9)'; - vrfy(randombit(123) == 0x73aa8e572ee77682ae317804ed8d6e5, \ - '5399: randombit(123) == 0x73aa8e572ee77682ae317804ed8d6e5'); - tmp = srandom(0,10); - print '5400: tmp = srandom(0,10)'; - vrfy(randombit(123) == 0x49c7acca8f461ad2edf4cb7651f18d3, \ - '5401: randombit(123) == 0x49c7acca8f461ad2edf4cb7651f18d3'); - tmp = srandom(0,11); - print '5402: tmp = srandom(0,11)'; - vrfy(randombit(123) == 0x6042e2169a73140ffab1881df99a0ee, \ - '5403: randombit(123) == 0x6042e2169a73140ffab1881df99a0ee'); - tmp = srandom(0,12); - print '5404: tmp = srandom(0,12)'; - vrfy(randombit(123) == 0x7b98097947d478611d96f4d7a1cd2af, \ - '5405: randombit(123) == 0x7b98097947d478611d96f4d7a1cd2af'); - tmp = srandom(0,13); - print '5406: tmp = srandom(0,13)'; - vrfy(randombit(123) == 0x12324fd76d7a4a5a979765be2d57cfa, \ - '5407: randombit(123) == 0x12324fd76d7a4a5a979765be2d57cfa'); - tmp = srandom(0,14); - print '5408: tmp = srandom(0,14)'; - vrfy(randombit(123) == 0x377ff9ef04ee24887984995f91489a3, \ - '5409: randombit(123) == 0x377ff9ef04ee24887984995f91489a3'); - tmp = srandom(0,15); - print '5410: tmp = srandom(0,15)'; - vrfy(randombit(123) == 0x7db2b6245c5a24a1a52f74c8f828c6f, \ - '5411: randombit(123) == 0x7db2b6245c5a24a1a52f74c8f828c6f'); - tmp = srandom(0,16); - print '5412: tmp = srandom(0,16)'; - vrfy(randombit(123) == 0x5958e6cc460c28a5e741706fd442f12, \ - '5413: randombit(123) == 0x5958e6cc460c28a5e741706fd442f12'); - tmp = srandom(0,17); - print '5414: tmp = srandom(0,17)'; - vrfy(randombit(123) == 0x68c40ccf3805b2734d0d2881ca268d, \ - '5415: randombit(123) == 0x68c40ccf3805b2734d0d2881ca268d'); - tmp = srandom(0,18); - print '5416: tmp = srandom(0,18)'; - vrfy(randombit(123) == 0x4afc6cd3b9e14dadc5b75c6a81602e5, \ - '5417: randombit(123) == 0x4afc6cd3b9e14dadc5b75c6a81602e5'); - tmp = srandom(0,19); - print '5418: tmp = srandom(0,19)'; - vrfy(randombit(123) == 0x3ea4d30abf7da6596d2425e0a9a6348, \ - '5419: randombit(123) == 0x3ea4d30abf7da6596d2425e0a9a6348'); - tmp = srandom(0,20); - print '5420: tmp = srandom(0,20)'; - vrfy(randombit(123) == 0x77f848c70d4622ed41956eceb3f15f6, \ - '5421: randombit(123) == 0x77f848c70d4622ed41956eceb3f15f6'); - vrfy(randombit(123) == 0x5bfa034925acaf7ad5ba5d8f7f32369, \ - '5422: randombit(123) == 0x5bfa034925acaf7ad5ba5d8f7f32369'); - vrfy(randombit(123) == 0x761100a4cecbdac8c8d539dee0e278e, \ - '5423: randombit(123) == 0x761100a4cecbdac8c8d539dee0e278e'); + /* test pre-compiled random states */ + tmp = srandom(init); + print '5376: tmp = srandom(init)'; + state0 = srandom(0,1); + print '5377: state0 = srandom(0,1)'; + vrfy(randombit(123) == 0x4cf8834399f8832d5c1ec35f20095f0, \ + '5378: randombit(123) == 0x4cf8834399f8832d5c1ec35f20095f0'); + state1 = srandom(123455432112345,1); + print '5379: state1 = srandom(123455432112345,1)'; + vrfy(randombit(123) == 0x437c9618d5a9c07d935b0ff7cef7346, \ + '5380: randombit(123) == 0x437c9618d5a9c07d935b0ff7cef7346'); + tmp = srandom(0,1); + print '5381: tmp = srandom(0,1)'; + vrfy(randombit(-123) == 123, '5382: randombit(-123) == 123'); + vrfy(srandom() == state1, '5383: srandom() == state1'); + tmp = srandom(0,2); + print '5384: tmp = srandom(0,2)'; + vrfy(randombit(123) == 0x7d53b2dbfe1edcb07df84f7fe96d5e9, \ + '5385: randombit(123) == 0x7d53b2dbfe1edcb07df84f7fe96d5e9'); + tmp = srandom(0,3); + print '5386: tmp = srandom(0,3)'; + vrfy(randombit(123) == 0x365cbae1adb9a706816abe3b64c1f2a, \ + '5387: randombit(123) == 0x365cbae1adb9a706816abe3b64c1f2a'); + tmp = srandom(0,4); + print '5388: tmp = srandom(0,4)'; + vrfy(randombit(123) == 0x63d9621736e59a3a5a8311117a1ef01, \ + '5389: randombit(123) == 0x63d9621736e59a3a5a8311117a1ef01'); + tmp = srandom(0,5); + print '5390: tmp = srandom(0,5)'; + vrfy(randombit(123) == 0x38d90517d6d532d1efb6eaf26bf927, \ + '5391: randombit(123) == 0x38d90517d6d532d1efb6eaf26bf927'); + tmp = srandom(0,6); + print '5392: tmp = srandom(0,6)'; + vrfy(randombit(123) == 0x146f2a1ce8cabcc313ab24f73747fbc, \ + '5393: randombit(123) == 0x146f2a1ce8cabcc313ab24f73747fbc'); + tmp = srandom(0,7); + print '5394: tmp = srandom(0,7)'; + vrfy(randombit(123) == 0x7a4a2b4ed817e5267358ea2979155d8, \ + '5395: randombit(123) == 0x7a4a2b4ed817e5267358ea2979155d8'); + tmp = srandom(0,8); + print '5396: tmp = srandom(0,8)'; + vrfy(randombit(123) == 0x5f30f211464854a37989cca3a8ecd0a, \ + '5397: randombit(123) == 0x5f30f211464854a37989cca3a8ecd0a'); + tmp = srandom(0,9); + print '5398: tmp = srandom(0,9)'; + vrfy(randombit(123) == 0x73aa8e572ee77682ae317804ed8d6e5, \ + '5399: randombit(123) == 0x73aa8e572ee77682ae317804ed8d6e5'); + tmp = srandom(0,10); + print '5400: tmp = srandom(0,10)'; + vrfy(randombit(123) == 0x49c7acca8f461ad2edf4cb7651f18d3, \ + '5401: randombit(123) == 0x49c7acca8f461ad2edf4cb7651f18d3'); + tmp = srandom(0,11); + print '5402: tmp = srandom(0,11)'; + vrfy(randombit(123) == 0x6042e2169a73140ffab1881df99a0ee, \ + '5403: randombit(123) == 0x6042e2169a73140ffab1881df99a0ee'); + tmp = srandom(0,12); + print '5404: tmp = srandom(0,12)'; + vrfy(randombit(123) == 0x7b98097947d478611d96f4d7a1cd2af, \ + '5405: randombit(123) == 0x7b98097947d478611d96f4d7a1cd2af'); + tmp = srandom(0,13); + print '5406: tmp = srandom(0,13)'; + vrfy(randombit(123) == 0x12324fd76d7a4a5a979765be2d57cfa, \ + '5407: randombit(123) == 0x12324fd76d7a4a5a979765be2d57cfa'); + tmp = srandom(0,14); + print '5408: tmp = srandom(0,14)'; + vrfy(randombit(123) == 0x377ff9ef04ee24887984995f91489a3, \ + '5409: randombit(123) == 0x377ff9ef04ee24887984995f91489a3'); + tmp = srandom(0,15); + print '5410: tmp = srandom(0,15)'; + vrfy(randombit(123) == 0x7db2b6245c5a24a1a52f74c8f828c6f, \ + '5411: randombit(123) == 0x7db2b6245c5a24a1a52f74c8f828c6f'); + tmp = srandom(0,16); + print '5412: tmp = srandom(0,16)'; + vrfy(randombit(123) == 0x5958e6cc460c28a5e741706fd442f12, \ + '5413: randombit(123) == 0x5958e6cc460c28a5e741706fd442f12'); + tmp = srandom(0,17); + print '5414: tmp = srandom(0,17)'; + vrfy(randombit(123) == 0x68c40ccf3805b2734d0d2881ca268d, \ + '5415: randombit(123) == 0x68c40ccf3805b2734d0d2881ca268d'); + tmp = srandom(0,18); + print '5416: tmp = srandom(0,18)'; + vrfy(randombit(123) == 0x4afc6cd3b9e14dadc5b75c6a81602e5, \ + '5417: randombit(123) == 0x4afc6cd3b9e14dadc5b75c6a81602e5'); + tmp = srandom(0,19); + print '5418: tmp = srandom(0,19)'; + vrfy(randombit(123) == 0x3ea4d30abf7da6596d2425e0a9a6348, \ + '5419: randombit(123) == 0x3ea4d30abf7da6596d2425e0a9a6348'); + tmp = srandom(0,20); + print '5420: tmp = srandom(0,20)'; + vrfy(randombit(123) == 0x77f848c70d4622ed41956eceb3f15f6, \ + '5421: randombit(123) == 0x77f848c70d4622ed41956eceb3f15f6'); + vrfy(randombit(123) == 0x5bfa034925acaf7ad5ba5d8f7f32369, \ + '5422: randombit(123) == 0x5bfa034925acaf7ad5ba5d8f7f32369'); + vrfy(randombit(123) == 0x761100a4cecbdac8c8d539dee0e278e, \ + '5423: randombit(123) == 0x761100a4cecbdac8c8d539dee0e278e'); - tmp = srandom(7^23+19,2); - print '5424: tmp = srandom(7^23+19,2)'; - vrfy(randombit(123) == 0x89b7ec9413e8af84a0c64ffc64d5a8, \ - '5425: randombit(123) == 0x89b7ec9413e8af84a0c64ffc64d5a8'); - tmp = srandom(7^23+19,3); - print '5426: tmp = srandom(7^23+19,3)'; - vrfy(randombit(123) == 0x7a2b8a6ca93a29deb1c3a674a30bf26, \ - '5427: randombit(123) == 0x7a2b8a6ca93a29deb1c3a674a30bf26'); - tmp = srandom(7^23+19,4); - print '5428: tmp = srandom(7^23+19,4)'; - vrfy(randombit(123) == 0x5425c6614dffcc0f376de4e9355c7df, \ - '5429: randombit(123) == 0x5425c6614dffcc0f376de4e9355c7df'); - tmp = srandom(7^23+19,5); - print '5430: tmp = srandom(7^23+19,5)'; - vrfy(randombit(123) == 0x70fca502499fa3717e346df5438886d, \ - '5431: randombit(123) == 0x70fca502499fa3717e346df5438886d'); - tmp = srandom(7^23+19,6); - print '5432: tmp = srandom(7^23+19,6)'; - vrfy(randombit(123) == 0x6ff886ac0918ad503290544af2cbd03, \ - '5433: randombit(123) == 0x6ff886ac0918ad503290544af2cbd03'); - tmp = srandom(7^23+19,7); - print '5434: tmp = srandom(7^23+19,7)'; - vrfy(randombit(123) == 0x5747d8c33d6d6dc53357779dffcc430, \ - '5435: randombit(123) == 0x5747d8c33d6d6dc53357779dffcc430'); - tmp = srandom(7^23+19,8); - print '5436: tmp = srandom(7^23+19,8)'; - vrfy(randombit(123) == 0x12769f65324d5e7986120b0caf071ad, \ - '5437: randombit(123) == 0x12769f65324d5e7986120b0caf071ad'); - tmp = srandom(7^23+19,9); - print '5438: tmp = srandom(7^23+19,9)'; - vrfy(randombit(123) == 0x3f94d3585b986539158f6ccd97d261e, \ - '5439: randombit(123) == 0x3f94d3585b986539158f6ccd97d261e'); - tmp = srandom(7^23+19,10); - print '5440: tmp = srandom(7^23+19,10)'; - vrfy(randombit(123) == 0x12874c359fffc6c0eda2aebfea97c71, \ - '5441: randombit(123) == 0x12874c359fffc6c0eda2aebfea97c71'); - tmp = srandom(7^23+19,11); - print '5442: tmp = srandom(7^23+19,11)'; - vrfy(randombit(123) == 0x7e0480a70c6f32f6594db8fd58ada7, \ - '5443: randombit(123) == 0x7e0480a70c6f32f6594db8fd58ada7'); - tmp = srandom(7^23+19,12); - print '5444: tmp = srandom(7^23+19,12)'; - vrfy(randombit(123) == 0x7f900aa8c7b9dacb6bf4ca0f5f81cb8, \ - '5445: randombit(123) == 0x7f900aa8c7b9dacb6bf4ca0f5f81cb8'); - tmp = srandom(7^23+19,13); - print '5446: tmp = srandom(7^23+19,13)'; - vrfy(randombit(123) == 0x39311c5aa41e42bb5d7807bdb60aecc, \ - '5447: randombit(123) == 0x39311c5aa41e42bb5d7807bdb60aecc'); - tmp = srandom(7^23+19,14); - print '5448: tmp = srandom(7^23+19,14)'; - vrfy(randombit(123) == 0x508bc8c5bd4555262b7ecd32a1ecd8e, \ - '5449: randombit(123) == 0x508bc8c5bd4555262b7ecd32a1ecd8e'); - tmp = srandom(7^23+19,15); - print '5450: tmp = srandom(7^23+19,15)'; - vrfy(randombit(123) == 0x442d2076b8d58d3815841180e8401b6, \ - '5451: randombit(123) == 0x442d2076b8d58d3815841180e8401b6'); - tmp = srandom(7^23+19,16); - print '5452: tmp = srandom(7^23+19,16)'; - vrfy(randombit(123) == 0x38db53974de9d3eea82a6ba35d2dc53, \ - '5453: randombit(123) == 0x38db53974de9d3eea82a6ba35d2dc53'); - tmp = srandom(7^23+19,17); - print '5454: tmp = srandom(7^23+19,17)'; - vrfy(randombit(123) == 0x42c1d9d86c9c67acb518ee008ce8f38, \ - '5455: randombit(123) == 0x42c1d9d86c9c67acb518ee008ce8f38'); - tmp = srandom(7^23+19,18); - print '5456: tmp = srandom(7^23+19,18)'; - vrfy(randombit(123) == 0x10dc81d7ef0a7aeb4aea1d4ac1fac2a, \ - '5457: randombit(123) == 0x10dc81d7ef0a7aeb4aea1d4ac1fac2a'); - tmp = srandom(7^23+19,19); - print '5458: tmp = srandom(7^23+19,19)'; - vrfy(randombit(123) == 0x469f8d91b643e0bcc4b5d5c2fe61cfb, \ - '5459: randombit(123) == 0x469f8d91b643e0bcc4b5d5c2fe61cfb'); - tmp = srandom(7^23+19,20); - print '5460: tmp = srandom(7^23+19,20)'; - vrfy(randombit(123) == 0x7f056e87cfcbe04a072e17502ef38f5, \ - '5461: randombit(123) == 0x7f056e87cfcbe04a072e17502ef38f5'); - vrfy(randombit(123) == 0x5d10d7665e56dee0ec5ea7d918ba073, \ - '5462: randombit(123) == 0x5d10d7665e56dee0ec5ea7d918ba073'); - vrfy(randombit(123) == 0x2058f802dd42b3aee4e734eacc13057, \ - '5463: randombit(123) == 0x2058f802dd42b3aee4e734eacc13057'); + tmp = srandom(7^23+19,2); + print '5424: tmp = srandom(7^23+19,2)'; + vrfy(randombit(123) == 0x89b7ec9413e8af84a0c64ffc64d5a8, \ + '5425: randombit(123) == 0x89b7ec9413e8af84a0c64ffc64d5a8'); + tmp = srandom(7^23+19,3); + print '5426: tmp = srandom(7^23+19,3)'; + vrfy(randombit(123) == 0x7a2b8a6ca93a29deb1c3a674a30bf26, \ + '5427: randombit(123) == 0x7a2b8a6ca93a29deb1c3a674a30bf26'); + tmp = srandom(7^23+19,4); + print '5428: tmp = srandom(7^23+19,4)'; + vrfy(randombit(123) == 0x5425c6614dffcc0f376de4e9355c7df, \ + '5429: randombit(123) == 0x5425c6614dffcc0f376de4e9355c7df'); + tmp = srandom(7^23+19,5); + print '5430: tmp = srandom(7^23+19,5)'; + vrfy(randombit(123) == 0x70fca502499fa3717e346df5438886d, \ + '5431: randombit(123) == 0x70fca502499fa3717e346df5438886d'); + tmp = srandom(7^23+19,6); + print '5432: tmp = srandom(7^23+19,6)'; + vrfy(randombit(123) == 0x6ff886ac0918ad503290544af2cbd03, \ + '5433: randombit(123) == 0x6ff886ac0918ad503290544af2cbd03'); + tmp = srandom(7^23+19,7); + print '5434: tmp = srandom(7^23+19,7)'; + vrfy(randombit(123) == 0x5747d8c33d6d6dc53357779dffcc430, \ + '5435: randombit(123) == 0x5747d8c33d6d6dc53357779dffcc430'); + tmp = srandom(7^23+19,8); + print '5436: tmp = srandom(7^23+19,8)'; + vrfy(randombit(123) == 0x12769f65324d5e7986120b0caf071ad, \ + '5437: randombit(123) == 0x12769f65324d5e7986120b0caf071ad'); + tmp = srandom(7^23+19,9); + print '5438: tmp = srandom(7^23+19,9)'; + vrfy(randombit(123) == 0x3f94d3585b986539158f6ccd97d261e, \ + '5439: randombit(123) == 0x3f94d3585b986539158f6ccd97d261e'); + tmp = srandom(7^23+19,10); + print '5440: tmp = srandom(7^23+19,10)'; + vrfy(randombit(123) == 0x12874c359fffc6c0eda2aebfea97c71, \ + '5441: randombit(123) == 0x12874c359fffc6c0eda2aebfea97c71'); + tmp = srandom(7^23+19,11); + print '5442: tmp = srandom(7^23+19,11)'; + vrfy(randombit(123) == 0x7e0480a70c6f32f6594db8fd58ada7, \ + '5443: randombit(123) == 0x7e0480a70c6f32f6594db8fd58ada7'); + tmp = srandom(7^23+19,12); + print '5444: tmp = srandom(7^23+19,12)'; + vrfy(randombit(123) == 0x7f900aa8c7b9dacb6bf4ca0f5f81cb8, \ + '5445: randombit(123) == 0x7f900aa8c7b9dacb6bf4ca0f5f81cb8'); + tmp = srandom(7^23+19,13); + print '5446: tmp = srandom(7^23+19,13)'; + vrfy(randombit(123) == 0x39311c5aa41e42bb5d7807bdb60aecc, \ + '5447: randombit(123) == 0x39311c5aa41e42bb5d7807bdb60aecc'); + tmp = srandom(7^23+19,14); + print '5448: tmp = srandom(7^23+19,14)'; + vrfy(randombit(123) == 0x508bc8c5bd4555262b7ecd32a1ecd8e, \ + '5449: randombit(123) == 0x508bc8c5bd4555262b7ecd32a1ecd8e'); + tmp = srandom(7^23+19,15); + print '5450: tmp = srandom(7^23+19,15)'; + vrfy(randombit(123) == 0x442d2076b8d58d3815841180e8401b6, \ + '5451: randombit(123) == 0x442d2076b8d58d3815841180e8401b6'); + tmp = srandom(7^23+19,16); + print '5452: tmp = srandom(7^23+19,16)'; + vrfy(randombit(123) == 0x38db53974de9d3eea82a6ba35d2dc53, \ + '5453: randombit(123) == 0x38db53974de9d3eea82a6ba35d2dc53'); + tmp = srandom(7^23+19,17); + print '5454: tmp = srandom(7^23+19,17)'; + vrfy(randombit(123) == 0x42c1d9d86c9c67acb518ee008ce8f38, \ + '5455: randombit(123) == 0x42c1d9d86c9c67acb518ee008ce8f38'); + tmp = srandom(7^23+19,18); + print '5456: tmp = srandom(7^23+19,18)'; + vrfy(randombit(123) == 0x10dc81d7ef0a7aeb4aea1d4ac1fac2a, \ + '5457: randombit(123) == 0x10dc81d7ef0a7aeb4aea1d4ac1fac2a'); + tmp = srandom(7^23+19,19); + print '5458: tmp = srandom(7^23+19,19)'; + vrfy(randombit(123) == 0x469f8d91b643e0bcc4b5d5c2fe61cfb, \ + '5459: randombit(123) == 0x469f8d91b643e0bcc4b5d5c2fe61cfb'); + tmp = srandom(7^23+19,20); + print '5460: tmp = srandom(7^23+19,20)'; + vrfy(randombit(123) == 0x7f056e87cfcbe04a072e17502ef38f5, \ + '5461: randombit(123) == 0x7f056e87cfcbe04a072e17502ef38f5'); + vrfy(randombit(123) == 0x5d10d7665e56dee0ec5ea7d918ba073, \ + '5462: randombit(123) == 0x5d10d7665e56dee0ec5ea7d918ba073'); + vrfy(randombit(123) == 0x2058f802dd42b3aee4e734eacc13057, \ + '5463: randombit(123) == 0x2058f802dd42b3aee4e734eacc13057'); - /* test seed() as best as we can */ - vrfy(seed() >= 0, '5464: seed() >= 0'); - vrfy(seed() < 2^64, '5465: seed() < 2^64'); - vrfy(israndom(srandom(seed())), '5466: israndom(srandom(seed()))'); + /* test seed() as best as we can */ + vrfy(seed() >= 0, '5464: seed() >= 0'); + vrfy(seed() < 2^64, '5465: seed() < 2^64'); + vrfy(israndom(srandom(seed())), '5466: israndom(srandom(seed()))'); - /* verify random(10,11) double bug fix */ - vrfy(random(10,11) == 10, '5467: random(10,11) == 10'); - vrfy(random(10,11) == 10, '5468: random(10,11) == 10'); - vrfy(random(10,11) == 10, '5469: random(10,11) == 10'); - vrfy(random(0,1) == 0, '5470: random(0,1) == 0'); - vrfy(random(0,1) == 0, '5471: random(0,1) == 0'); + /* verify random(10,11) double bug fix */ + vrfy(random(10,11) == 10, '5467: random(10,11) == 10'); + vrfy(random(10,11) == 10, '5468: random(10,11) == 10'); + vrfy(random(10,11) == 10, '5469: random(10,11) == 10'); + vrfy(random(0,1) == 0, '5470: random(0,1) == 0'); + vrfy(random(0,1) == 0, '5471: random(0,1) == 0'); - print '5472: Ending test_random'; + print '5472: Ending test_random'; } print '137: parsed test_random()'; @@ -5774,194 +5774,194 @@ print '137: parsed test_random()'; */ for (s5500 = 0, i = 0; i < 5; i++) s5500 += i; print "138: for (s5500 = 0, i = 0; i < 5; i++) s5500 += i;"; -vrfy(s5500 == 10, '139: s5500 == 10'); -vrfy(i == 5, '140: i == 5'); +vrfy(s5500 == 10, '139: s5500 == 10'); +vrfy(i == 5, '140: i == 5'); for (s5500 = 0, i = 0; i < 9; i++) { - s5500 += i; + s5500 += i; } print "141: for (s5500 = 0, i = 0; i < 9; i++) { s5500 += i; }"; -vrfy(s5500 == 36, '142: s5500 == 36'); -vrfy(i == 9, '143: i == 9'); +vrfy(s5500 == 36, '142: s5500 == 36'); +vrfy(i == 9, '143: i == 9'); { - local i; - for (s5500 = 0, i = 0; i < 10; i++) - s5500 += i; - vrfy(s5500 == 45, '144: s5500 == 45'); - vrfy(i == 10, '145: i == 10'); + local i; + for (s5500 = 0, i = 0; i < 10; i++) + s5500 += i; + vrfy(s5500 == 45, '144: s5500 == 45'); + vrfy(i == 10, '145: i == 10'); } print "146: { local i; for (s5500 = 0, i = 0; i < 10; i++) s5500 += i; ... }"; -vrfy(s5500 == 45, '147: s5500 == 45'); -vrfy(i == 9, '148: i == 9'); +vrfy(s5500 == 45, '147: s5500 == 45'); +vrfy(i == 9, '148: i == 9'); /**/ define test_newsyn() { - local i; /* loop counter */ + local i; /* loop counter */ - print '5500: Beginning test_newsyn'; + print '5500: Beginning test_newsyn'; - /* - * check basic for loop completion and scoping - */ - for (s5500 = 0, i = 0; i < 5; i++) - s5500 += i; - print "5501: for (s5500 = 0, i = 0; i < 5; i++) s5500 += i;"; - vrfy(s5500 == 10, '5502: s5500 == 10'); - vrfy(i == 5, '5503: i == 5'); - /**/ - for (s5500 = 0, i = 0; i < 6; i++) - { - s5500 += i; - } - print "5504: for (s5500 = 0, i = 0; i < 6; i++) { s5500 += i; }"; - vrfy(s5500 == 15, '5505: s5500 == 15'); - vrfy(i == 6, '5506: i == 6'); - /**/ - for (s5500 = 0, i = 0; i < 3; i++) { - s5500 += i; - } - print "5507: for (s5500 = 0, i = 0; i < 3; i++) { s5500 += i; }"; - vrfy(s5500 == 3, '5508: s5500 == 3'); - vrfy(i == 3, '5509: i == 3'); - /**/ - { - for (s5500 = 0, i = 0; i < 11; i++) - s5500 += i; - vrfy(s5500 == 55, '5510: s5500 == 45'); - vrfy(i == 11, '5511: i == 11'); - } - print "5512: { local i; for (s5500 = 0, i = 0; i < 10; i++) ": - "s5500 += i; ... }"; - vrfy(s5500 == 55, '5513: s5500 == 55'); - vrfy(i == 11, '5514: i == 11'); + /* + * check basic for loop completion and scoping + */ + for (s5500 = 0, i = 0; i < 5; i++) + s5500 += i; + print "5501: for (s5500 = 0, i = 0; i < 5; i++) s5500 += i;"; + vrfy(s5500 == 10, '5502: s5500 == 10'); + vrfy(i == 5, '5503: i == 5'); + /**/ + for (s5500 = 0, i = 0; i < 6; i++) + { + s5500 += i; + } + print "5504: for (s5500 = 0, i = 0; i < 6; i++) { s5500 += i; }"; + vrfy(s5500 == 15, '5505: s5500 == 15'); + vrfy(i == 6, '5506: i == 6'); + /**/ + for (s5500 = 0, i = 0; i < 3; i++) { + s5500 += i; + } + print "5507: for (s5500 = 0, i = 0; i < 3; i++) { s5500 += i; }"; + vrfy(s5500 == 3, '5508: s5500 == 3'); + vrfy(i == 3, '5509: i == 3'); + /**/ + { + for (s5500 = 0, i = 0; i < 11; i++) + s5500 += i; + vrfy(s5500 == 55, '5510: s5500 == 45'); + vrfy(i == 11, '5511: i == 11'); + } + print "5512: { local i; for (s5500 = 0, i = 0; i < 10; i++) ": + "s5500 += i; ... }"; + vrfy(s5500 == 55, '5513: s5500 == 55'); + vrfy(i == 11, '5514: i == 11'); - /* - * test completion of while loops - */ - i = 0; - print '5515: i = 0'; - s5500 = 0; - print '5516: s5500 = 0'; - while (++i < 4) - s5500 += i; - print "5517: while (++i < 4) s5500 += i;"; - vrfy(s5500 == 6, '5518: s5500 == 6'); - vrfy(i == 4, '5519: i == 4'); - /**/ - i = 0; - print '5520: i = 0'; - s5500 = 0; - print '5521: s5500 = 0'; - while (++i < 7) - { - s5500 += i; - } - print "5522: while (++i < 7) { s5500 += i; }"; - vrfy(s5500 == 21, '5523: s5500 == 21'); - vrfy(i == 7, '5524: i == 7'); - /**/ - i = 0; - print '5525: i = 0'; - s5500 = 0; - print '5526: s5500 = 0'; - while (++i < 8) { - s5500 += i; - } - print "5527: while (++i < 8) { s5500 += i; }"; - vrfy(s5500 == 28, '5528: s5500 == 28'); - vrfy(i == 8, '5529: i == 8'); + /* + * test completion of while loops + */ + i = 0; + print '5515: i = 0'; + s5500 = 0; + print '5516: s5500 = 0'; + while (++i < 4) + s5500 += i; + print "5517: while (++i < 4) s5500 += i;"; + vrfy(s5500 == 6, '5518: s5500 == 6'); + vrfy(i == 4, '5519: i == 4'); + /**/ + i = 0; + print '5520: i = 0'; + s5500 = 0; + print '5521: s5500 = 0'; + while (++i < 7) + { + s5500 += i; + } + print "5522: while (++i < 7) { s5500 += i; }"; + vrfy(s5500 == 21, '5523: s5500 == 21'); + vrfy(i == 7, '5524: i == 7'); + /**/ + i = 0; + print '5525: i = 0'; + s5500 = 0; + print '5526: s5500 = 0'; + while (++i < 8) { + s5500 += i; + } + print "5527: while (++i < 8) { s5500 += i; }"; + vrfy(s5500 == 28, '5528: s5500 == 28'); + vrfy(i == 8, '5529: i == 8'); - /* - * test completion of do-while loops - */ - i = 0; - print '5530: i = 0'; - s5500 = 0; - print '5531: s5500 = 0'; - do - s5500 += i; - while (++i < 12); - print "5532: do s5500 += i; while (++i < 12);"; - vrfy(s5500 == 66, '5533: s5500 == 66'); - vrfy(i == 12, '5534: i == 12'); - /**/ - i = 0; - print '5535: i = 0'; - s5500 = 0; - print '5536: s5500 = 0'; - do { - s5500 += i; - } while (++i < 14) - print "5537: do { s5500 += i; } while (++i < 14);"; - vrfy(s5500 == 91, '5538: s5500 == 91'); - vrfy(i == 14, '5539: i == 14'); - /**/ - i = 0; - print '5540: i = 0'; - s5500 = 0; - print '5541: s5500 = 0'; - do - { - s5500 += i; - } - while (++i < 13) - ; - print "5542: do { s5500 += i; } while (++i < 13);"; - vrfy(s5500 == 78, '5543: s5500 == 78'); - vrfy(i == 13, '5544: i == 13'); + /* + * test completion of do-while loops + */ + i = 0; + print '5530: i = 0'; + s5500 = 0; + print '5531: s5500 = 0'; + do + s5500 += i; + while (++i < 12); + print "5532: do s5500 += i; while (++i < 12);"; + vrfy(s5500 == 66, '5533: s5500 == 66'); + vrfy(i == 12, '5534: i == 12'); + /**/ + i = 0; + print '5535: i = 0'; + s5500 = 0; + print '5536: s5500 = 0'; + do { + s5500 += i; + } while (++i < 14) + print "5537: do { s5500 += i; } while (++i < 14);"; + vrfy(s5500 == 91, '5538: s5500 == 91'); + vrfy(i == 14, '5539: i == 14'); + /**/ + i = 0; + print '5540: i = 0'; + s5500 = 0; + print '5541: s5500 = 0'; + do + { + s5500 += i; + } + while (++i < 13) + ; + print "5542: do { s5500 += i; } while (++i < 13);"; + vrfy(s5500 == 78, '5543: s5500 == 78'); + vrfy(i == 13, '5544: i == 13'); - /* - * test the completion of switch - */ - switch (i) { - case 12: prob("switch showed i was 12 instead of 13"); break; - case 13: - vrfy(i == 13, '5545: i == 13'); - break; - default: - prob("switch showed i was something other than 13"); - break; - } - switch - ( - i - ) - { - case - 1 - : - prob( - "switch showed i was 1 instead of 13" - ) - ; - break - ; - case - 2 - : - prob( - "switch showed i was 2 instead of 13" - ) - ; - break - ; - default - : - vrfy - ( - i - == - 13 - , - '5546: i == 13' - ) - ; - } + /* + * test the completion of switch + */ + switch (i) { + case 12: prob("switch showed i was 12 instead of 13"); break; + case 13: + vrfy(i == 13, '5545: i == 13'); + break; + default: + prob("switch showed i was something other than 13"); + break; + } + switch + ( + i + ) + { + case + 1 + : + prob( + "switch showed i was 1 instead of 13" + ) + ; + break + ; + case + 2 + : + prob( + "switch showed i was 2 instead of 13" + ) + ; + break + ; + default + : + vrfy + ( + i + == + 13 + , + '5546: i == 13' + ) + ; + } - print '5547: Ending test_newsyn'; + print '5547: Ending test_newsyn'; } print '149: parsed test_newsyn()'; -vrfy(s5500 == 45, '150: s5500 == 45'); -vrfy(i == 9, '151: i == 9'); +vrfy(s5500 == 45, '150: s5500 == 45'); +vrfy(i == 9, '151: i == 9'); /* @@ -5976,81 +5976,81 @@ print '153: xx5600_print() = printf("xx")'; /**/ define test_commaeq() { - local i; - local A, B, C, D; - local a5600 = 0, b5600 = 0; - obj xy5600 {x, y}; + local i; + local A, B, C, D; + local a5600 = 0, b5600 = 0; + obj xy5600 {x, y}; - /* - * Calculations with i - */ - print '5600: Beginning test_commaeq'; - i = 5; - print '5601: i = 5'; - vrfy(i == 5, '5602: i == 5'); - i += 2 *= 3 -= 1; - print '5603: i += 2 *= 3 -= 1'; - vrfy(i == 20, '5604: i == 20'); - ++i /= 7; - print '5607: ++i /= 7'; - vrfy(i == 3, '5608: i == 3'); + /* + * Calculations with i + */ + print '5600: Beginning test_commaeq'; + i = 5; + print '5601: i = 5'; + vrfy(i == 5, '5602: i == 5'); + i += 2 *= 3 -= 1; + print '5603: i += 2 *= 3 -= 1'; + vrfy(i == 20, '5604: i == 20'); + ++i /= 7; + print '5607: ++i /= 7'; + vrfy(i == 3, '5608: i == 3'); - /* - * xx5600 object type - */ - mat A[3] = {1,2,xx5600}; - print '5609: mat A[3] = {1,2,xx5600}'; - vrfy(A[2] == xx5600, '5610: A[2] == xx5600'); - vrfy(strprintf("%d", xx5600) == "xx", - '5611: strprintf("%d", xx5600) == "xx"'); + /* + * xx5600 object type + */ + mat A[3] = {1,2,xx5600}; + print '5609: mat A[3] = {1,2,xx5600}'; + vrfy(A[2] == xx5600, '5610: A[2] == xx5600'); + vrfy(strprintf("%d", xx5600) == "xx", + '5611: strprintf("%d", xx5600) == "xx"'); - /* - * xy5600 object type - */ - obj xy5600 A = {1, 2} = {3, 4}; - print '5612: obj xy5600 A = {1, 2} = {3, 4}'; - vrfy(A.x == 3, '5613: A.x == 3'); - vrfy(A.y == 4, '5614: A.y == 4'); - obj xy5600 B = {A,A}; - print '5613: obj xy5600 B = {A,A}'; - vrfy(B.x.x == 3, '5615: B.x.x == 3'); - vrfy(B.y.y == 4, '5616: B.y.y == 4'); - obj xy5600 C; - print '5617: obj xy5600 C'; - C = {1, 2} = {C, C}; - print '5618: C = {1, 2} = {C, C}'; - vrfy(C.x.x == 1, '5619: C.x.x == 1'); - vrfy(C.y.x.y == 2, '5620: C.y.x.y == 2'); - D = 7; - print '5621: D = 7'; - obj xy5600 D = {1,2} = {D,D}; - print '5622: obj xy5600 D = {1,2} = {D,D}'; - vrfy(D.x == 7, '5623: D.x == 7'); - vrfy(D.y == 7, '5624: D.y == 7'); + /* + * xy5600 object type + */ + obj xy5600 A = {1, 2} = {3, 4}; + print '5612: obj xy5600 A = {1, 2} = {3, 4}'; + vrfy(A.x == 3, '5613: A.x == 3'); + vrfy(A.y == 4, '5614: A.y == 4'); + obj xy5600 B = {A,A}; + print '5613: obj xy5600 B = {A,A}'; + vrfy(B.x.x == 3, '5615: B.x.x == 3'); + vrfy(B.y.y == 4, '5616: B.y.y == 4'); + obj xy5600 C; + print '5617: obj xy5600 C'; + C = {1, 2} = {C, C}; + print '5618: C = {1, 2} = {C, C}'; + vrfy(C.x.x == 1, '5619: C.x.x == 1'); + vrfy(C.y.x.y == 2, '5620: C.y.x.y == 2'); + D = 7; + print '5621: D = 7'; + obj xy5600 D = {1,2} = {D,D}; + print '5622: obj xy5600 D = {1,2} = {D,D}'; + vrfy(D.x == 7, '5623: D.x == 7'); + vrfy(D.y == 7, '5624: D.y == 7'); - /* - * matrix assignment - */ - mat A[3] = {1,2,3}, mat B[2] = {1,2}; - print '5625: mat A[3] = {1,2,3}, mat B[2] = {1,2}'; - vrfy(A[0] == 1, '5626: A[0] == 1'); - vrfy(B[1] == 2, '5627: B[1] == 2'); + /* + * matrix assignment + */ + mat A[3] = {1,2,3}, mat B[2] = {1,2}; + print '5625: mat A[3] = {1,2,3}, mat B[2] = {1,2}'; + vrfy(A[0] == 1, '5626: A[0] == 1'); + vrfy(B[1] == 2, '5627: B[1] == 2'); - /* - * misc = and , expressions - */ - vrfy(((a5600 = 2, b5600) = 3) && a5600 + b5600 == 5, - '5628: ((a5600 = 2, b5600) = 3) && a5600 + b5600 == 5'); - vrfy((2 ? a5600 : b5600 = 4) && a5600 == 4, - '5629: (2 ? a5600 : b5600 = 4) && a5600 == 4'); - vrfy((0 ? a5600 : b5600 = 5) && b5600 == 5, - '5630: (0 ? a5600 : b5600 = 5) && b5600 == 5'); - vrfy((a5600 || b5600 = 6) && a5600 == 6 && b5600 == 5, - '5631: (a5600 || b5600 = 6) && a5600 == 6 && b5600 == 5'); - vrfy((a5600 && b5600 = 7) && a5600 == 6 && b5600 == 7, - '5632: (a5600 && b5600 = 7) && a5600 == 6 && b5600 == 7'); + /* + * misc = and , expressions + */ + vrfy(((a5600 = 2, b5600) = 3) && a5600 + b5600 == 5, + '5628: ((a5600 = 2, b5600) = 3) && a5600 + b5600 == 5'); + vrfy((2 ? a5600 : b5600 = 4) && a5600 == 4, + '5629: (2 ? a5600 : b5600 = 4) && a5600 == 4'); + vrfy((0 ? a5600 : b5600 = 5) && b5600 == 5, + '5630: (0 ? a5600 : b5600 = 5) && b5600 == 5'); + vrfy((a5600 || b5600 = 6) && a5600 == 6 && b5600 == 5, + '5631: (a5600 || b5600 = 6) && a5600 == 6 && b5600 == 5'); + vrfy((a5600 && b5600 = 7) && a5600 == 6 && b5600 == 7, + '5632: (a5600 && b5600 = 7) && a5600 == 6 && b5600 == 7'); - print '5633: Ending test_commaeq'; + print '5633: Ending test_commaeq'; } print '155: parsed test_commaeq()'; @@ -6064,173 +6064,173 @@ print '155: parsed test_commaeq()'; */ define test_size() { - local z; /* test integer values */ - local q; /* test rational values */ - local c; /* test complex values */ - local m; /* test matrix */ - local l; /* test list */ - local a; /* test association */ + local z; /* test integer values */ + local q; /* test rational values */ + local c; /* test complex values */ + local m; /* test matrix */ + local l; /* test list */ + local a; /* test association */ - print '5700: Beginning test_size'; + print '5700: Beginning test_size'; - /* - * 0, -1 and 1 values are reported as 0 sizeof - */ - vrfy(sizeof(0) == 0, '5701: sizeof(0) == 0'); - vrfy(sizeof(1) == 0, '5702: sizeof(1) == 0'); - vrfy(sizeof(-1) == 0, '5703: sizeof(-1) == 0'); - z = 0; - print '5704: z = 0'; - vrfy(sizeof(z) == 0, '5705: sizeof(z) == 0'); - z = 1; - print '5706: z = 1'; - vrfy(sizeof(z) == 0, '5707: sizeof(z) == 0'); - z = -1; - print '5708: z = -1'; - vrfy(sizeof(z) == 0, '5709: sizeof(z) == 0'); + /* + * 0, -1 and 1 values are reported as 0 sizeof + */ + vrfy(sizeof(0) == 0, '5701: sizeof(0) == 0'); + vrfy(sizeof(1) == 0, '5702: sizeof(1) == 0'); + vrfy(sizeof(-1) == 0, '5703: sizeof(-1) == 0'); + z = 0; + print '5704: z = 0'; + vrfy(sizeof(z) == 0, '5705: sizeof(z) == 0'); + z = 1; + print '5706: z = 1'; + vrfy(sizeof(z) == 0, '5707: sizeof(z) == 0'); + z = -1; + print '5708: z = -1'; + vrfy(sizeof(z) == 0, '5709: sizeof(z) == 0'); - /* - * non-integer rationals are larger than integers - */ - q = 13/2; - print '5710: q = 13/2'; - vrfy(sizeof(13)*2 == sizeof(q), '5711: sizeof(13)*2 == sizeof(q)'); - q = 13; - print '5712: q = 13'; - vrfy(sizeof(13) == sizeof(q), '5713: sizeof(13) == sizeof(q)'); - q = (17^139 + 674) / (17^139 + 686); - print '5714: q = (17^139 + 674) / (17^139 + 686)'; - vrfy(sizeof(17^139 + 674)*2 == sizeof(q), - '5715: sizeof(17^139 + 674)*2 == sizeof(q)'); + /* + * non-integer rationals are larger than integers + */ + q = 13/2; + print '5710: q = 13/2'; + vrfy(sizeof(13)*2 == sizeof(q), '5711: sizeof(13)*2 == sizeof(q)'); + q = 13; + print '5712: q = 13'; + vrfy(sizeof(13) == sizeof(q), '5713: sizeof(13) == sizeof(q)'); + q = (17^139 + 674) / (17^139 + 686); + print '5714: q = (17^139 + 674) / (17^139 + 686)'; + vrfy(sizeof(17^139 + 674)*2 == sizeof(q), + '5715: sizeof(17^139 + 674)*2 == sizeof(q)'); - /* - * reciprocals are the same size of their integer inverses - */ - q = 1/13; - print '5716: q = 1/13'; - vrfy(sizeof(13) == sizeof(q), '5717: sizeof(13) == sizeof(q)'); - q = 1/(17^139 + 674); - print '5718: q = 1/(17^139 + 674)'; - vrfy(sizeof(17^139 + 674) == sizeof(q), - '5717: sizeof(17^139 + 674) == sizeof(q)'); + /* + * reciprocals are the same size of their integer inverses + */ + q = 1/13; + print '5716: q = 1/13'; + vrfy(sizeof(13) == sizeof(q), '5717: sizeof(13) == sizeof(q)'); + q = 1/(17^139 + 674); + print '5718: q = 1/(17^139 + 674)'; + vrfy(sizeof(17^139 + 674) == sizeof(q), + '5717: sizeof(17^139 + 674) == sizeof(q)'); - /* - * negative values are the same size as positive values - */ - vrfy(sizeof(17^139 + 674) == sizeof(-q), - '5718: sizeof(17^139 + 674) == sizeof(-q)'); - vrfy(sizeof(-(17^139 + 674)) == sizeof(-q), - '5719: sizeof(-(17^139 + 674)) == sizeof(-q)'); - q = 1/-13; - print '5720: q = 1/-13'; - vrfy(sizeof(13) == sizeof(q), '5721: sizeof(13) == sizeof(q)'); + /* + * negative values are the same size as positive values + */ + vrfy(sizeof(17^139 + 674) == sizeof(-q), + '5718: sizeof(17^139 + 674) == sizeof(-q)'); + vrfy(sizeof(-(17^139 + 674)) == sizeof(-q), + '5719: sizeof(-(17^139 + 674)) == sizeof(-q)'); + q = 1/-13; + print '5720: q = 1/-13'; + vrfy(sizeof(13) == sizeof(q), '5721: sizeof(13) == sizeof(q)'); - /* - * complex values with a real or imaginary part of 0, 1 or -1 - * are the same size as rationals - */ - c = 0 + 4i; - print '5722: c = 0 + 4i'; - vrfy(sizeof(3) == sizeof(c), '5723: sizeof(3) == sizeof(c)'); - c = 3 + 0i; - print '5724: c = 3 + 0i'; - vrfy(sizeof(3) == sizeof(c), '5725: sizeof(3) == sizeof(c)'); - c = 1 + 4i; - print '5726: c = 1 + 4i'; - vrfy(sizeof(3) == sizeof(c), '5727: sizeof(3) == sizeof(c)'); - c = 3 + 1i; - print '5728: c = 3 + 1i'; - vrfy(sizeof(3) == sizeof(c), '5729: sizeof(3) == sizeof(c)'); - c = -1 + 4i; - print '5730: c = -1 + 4i'; - vrfy(sizeof(3) == sizeof(c), '5731: sizeof(3) == sizeof(c)'); - c = 3 + -1i; - print '5732: c = 3 + -1i'; - vrfy(sizeof(3) == sizeof(c), '5733: sizeof(3) == sizeof(c)'); + /* + * complex values with a real or imaginary part of 0, 1 or -1 + * are the same size as rationals + */ + c = 0 + 4i; + print '5722: c = 0 + 4i'; + vrfy(sizeof(3) == sizeof(c), '5723: sizeof(3) == sizeof(c)'); + c = 3 + 0i; + print '5724: c = 3 + 0i'; + vrfy(sizeof(3) == sizeof(c), '5725: sizeof(3) == sizeof(c)'); + c = 1 + 4i; + print '5726: c = 1 + 4i'; + vrfy(sizeof(3) == sizeof(c), '5727: sizeof(3) == sizeof(c)'); + c = 3 + 1i; + print '5728: c = 3 + 1i'; + vrfy(sizeof(3) == sizeof(c), '5729: sizeof(3) == sizeof(c)'); + c = -1 + 4i; + print '5730: c = -1 + 4i'; + vrfy(sizeof(3) == sizeof(c), '5731: sizeof(3) == sizeof(c)'); + c = 3 + -1i; + print '5732: c = 3 + -1i'; + vrfy(sizeof(3) == sizeof(c), '5733: sizeof(3) == sizeof(c)'); - /* - * general complex values are twice the size as rationals - */ - c = 3 + 4i; - print '5734: c = 3 + 4i'; - vrfy(sizeof(3)*2 == sizeof(c), '5735: sizeof(3)*2 == sizeof(c)'); - z = 17^139 + 686; - print '5736: z = 17^139 + 686'; - c = z + z*1i; - print '5737: c = z + z*1i'; - vrfy(sizeof(z)*2 == sizeof(c), '5738: sizeof(z)*2 == sizeof(c)'); - q = 1/(17^139 + 674); - print '5739: q = 1/(17^139 + 674)'; - c = q + q*1i; - print '5740: c = q + q*1i'; - vrfy(sizeof(q)*2 == sizeof(c), '5741: sizeof(q)*2 == sizeof(c)'); - c = (z*q) + (1/(z*q))*1i; - print '5742: c = (z*q) + (1/(z*q))*1i'; - vrfy(sizeof(z*q)*2 == sizeof(c), '5743: sizeof(z*q)*2 == sizeof(c)'); - vrfy(sizeof(z)*4 == sizeof(c), '5744: sizeof(z)*4 == sizeof(c)'); - vrfy(sizeof(q)*4 == sizeof(c), '5745: sizeof(q)*4 == sizeof(c)'); + /* + * general complex values are twice the size as rationals + */ + c = 3 + 4i; + print '5734: c = 3 + 4i'; + vrfy(sizeof(3)*2 == sizeof(c), '5735: sizeof(3)*2 == sizeof(c)'); + z = 17^139 + 686; + print '5736: z = 17^139 + 686'; + c = z + z*1i; + print '5737: c = z + z*1i'; + vrfy(sizeof(z)*2 == sizeof(c), '5738: sizeof(z)*2 == sizeof(c)'); + q = 1/(17^139 + 674); + print '5739: q = 1/(17^139 + 674)'; + c = q + q*1i; + print '5740: c = q + q*1i'; + vrfy(sizeof(q)*2 == sizeof(c), '5741: sizeof(q)*2 == sizeof(c)'); + c = (z*q) + (1/(z*q))*1i; + print '5742: c = (z*q) + (1/(z*q))*1i'; + vrfy(sizeof(z*q)*2 == sizeof(c), '5743: sizeof(z*q)*2 == sizeof(c)'); + vrfy(sizeof(z)*4 == sizeof(c), '5744: sizeof(z)*4 == sizeof(c)'); + vrfy(sizeof(q)*4 == sizeof(c), '5745: sizeof(q)*4 == sizeof(c)'); - /* - * size of numeric values is always 1 - */ - vrfy(size(0) == 1, '5746: size(0) == 1'); - vrfy(size(1) == 1, '5747: size(1) == 1'); - vrfy(size(13^10) == 1, '5748: size(13^10) == 1'); - vrfy(size(z) == 1, '5749: size(z) == 1'); - vrfy(size(q) == 1, '5750: size(q) == 1'); - vrfy(size(c) == 1, '5751: size(c) == 1'); + /* + * size of numeric values is always 1 + */ + vrfy(size(0) == 1, '5746: size(0) == 1'); + vrfy(size(1) == 1, '5747: size(1) == 1'); + vrfy(size(13^10) == 1, '5748: size(13^10) == 1'); + vrfy(size(z) == 1, '5749: size(z) == 1'); + vrfy(size(q) == 1, '5750: size(q) == 1'); + vrfy(size(c) == 1, '5751: size(c) == 1'); - /* - * size of a matrix is the sum of the sizes of the elements - * sizeof of a matrix is the sum of the sizeof's of the elements - */ - mat m[] = {z,q,c}; - print '5752: mat m[] = {z,q,c}'; - vrfy(size(m) == size(z)+size(q)+size(c), - '5753: size(m) == size(z)+size(q)+size(c)'); - vrfy(sizeof(m) == sizeof(z)+sizeof(q)+sizeof(c), - '5754: sizeof(m) == sizeof(z)+sizeof(q)+sizeof(c)'); + /* + * size of a matrix is the sum of the sizes of the elements + * sizeof of a matrix is the sum of the sizeof's of the elements + */ + mat m[] = {z,q,c}; + print '5752: mat m[] = {z,q,c}'; + vrfy(size(m) == size(z)+size(q)+size(c), + '5753: size(m) == size(z)+size(q)+size(c)'); + vrfy(sizeof(m) == sizeof(z)+sizeof(q)+sizeof(c), + '5754: sizeof(m) == sizeof(z)+sizeof(q)+sizeof(c)'); - /* - * size of a list is the number of elements - * sizeof of a list is the sum of the sizeof's of the elements - */ - l = list(z,q,c,m); - print '5755: list(z,q,c,m)'; - vrfy(size(l) == 4, '5756: size(l) == 4'); - vrfy(sizeof(l) == 2*sizeof(m), '5757: sizeof(l) == 2*sizeof(m)'); + /* + * size of a list is the number of elements + * sizeof of a list is the sum of the sizeof's of the elements + */ + l = list(z,q,c,m); + print '5755: list(z,q,c,m)'; + vrfy(size(l) == 4, '5756: size(l) == 4'); + vrfy(sizeof(l) == 2*sizeof(m), '5757: sizeof(l) == 2*sizeof(m)'); - /* - * size of an assoc is the number of elements - * sizeof of an assoc is the sum of the sizeof's of the elements - */ - a = assoc(); - print '5758: a = assoc()'; - a["z"] = z+1; - print '5759: a["z"] = z+1'; - a["q"] = q+2; - print '5760: a["q"] = q+2'; - a["c"] = c+3; - print '5761: a["c"] = c+3'; - a[m] = m; - print '5762: a[m] = m'; - a[l] = l; - print '5763: a[l] = l'; - vrfy(size(a) == 5, '5764: size(a) == 5'); - vrfy(sizeof(a) == 25*sizeof(z), '5765: sizeof(a) == 25*sizeof(z)'); + /* + * size of an assoc is the number of elements + * sizeof of an assoc is the sum of the sizeof's of the elements + */ + a = assoc(); + print '5758: a = assoc()'; + a["z"] = z+1; + print '5759: a["z"] = z+1'; + a["q"] = q+2; + print '5760: a["q"] = q+2'; + a["c"] = c+3; + print '5761: a["c"] = c+3'; + a[m] = m; + print '5762: a[m] = m'; + a[l] = l; + print '5763: a[l] = l'; + vrfy(size(a) == 5, '5764: size(a) == 5'); + vrfy(sizeof(a) == 25*sizeof(z), '5765: sizeof(a) == 25*sizeof(z)'); - /* - * about all we can say about memsize is that it will always be - * larger than sizeof - */ - vrfy(sizeof(z) < memsize(z), '5766: sizeof(z) < memsize(z)'); - vrfy(sizeof(q) < memsize(q), '5767: sizeof(q) < memsize(q)'); - vrfy(sizeof(c) < memsize(c), '5768: sizeof(c) < memsize(c)'); - vrfy(sizeof(m) < memsize(m), '5769: sizeof(m) < memsize(m)'); - vrfy(sizeof(l) < memsize(l), '5770: sizeof(l) < memsize(l)'); - vrfy(sizeof(a) < memsize(a), '5771: sizeof(a) < memsize(a)'); + /* + * about all we can say about memsize is that it will always be + * larger than sizeof + */ + vrfy(sizeof(z) < memsize(z), '5766: sizeof(z) < memsize(z)'); + vrfy(sizeof(q) < memsize(q), '5767: sizeof(q) < memsize(q)'); + vrfy(sizeof(c) < memsize(c), '5768: sizeof(c) < memsize(c)'); + vrfy(sizeof(m) < memsize(m), '5769: sizeof(m) < memsize(m)'); + vrfy(sizeof(l) < memsize(l), '5770: sizeof(l) < memsize(l)'); + vrfy(sizeof(a) < memsize(a), '5771: sizeof(a) < memsize(a)'); - print '5772: Ending test_size'; + print '5772: Ending test_size'; } print '156: parsed test_size()'; @@ -6240,47 +6240,47 @@ print '156: parsed test_size()'; * * This function tests assignment of constants and variables. */ -global X5800, Y5800; /* X5800, Y5800 for "variables" */ +global X5800, Y5800; /* X5800, Y5800 for "variables" */ print '158: global X5800, Y5800'; obj xy5800 {x, y}; print '159: obj xy5800 {x, y}'; /**/ define test_assign(base, work) { - print base: ': Beginning test_assign'; + print base: ': Beginning test_assign'; - /* - * value assignments - */ - A = base+1; - print base+1: ': A = base+1'; - B = base+2; - print base+2: ': B = base+2'; - X5800 = base+3; - print base+3: ': X5800 = base+3'; - Y5800 = base+4; - print base+4: ': Y5800 = base+4'; - obj xy5800 A={1,2}, obj xy5800 B={3,4}; - print base+5: ': obj xy5800 A={1,2}, obj xy5800 B={3,4}'; + /* + * value assignments + */ + A = base+1; + print base+1: ': A = base+1'; + B = base+2; + print base+2: ': B = base+2'; + X5800 = base+3; + print base+3: ': X5800 = base+3'; + Y5800 = base+4; + print base+4: ': Y5800 = base+4'; + obj xy5800 A={1,2}, obj xy5800 B={3,4}; + print base+5: ': obj xy5800 A={1,2}, obj xy5800 B={3,4}'; - /* - * test assignment - */ - X5800 = A; - print base+6: ': X5800 = A'; - if (work) { - vrfy(X5800 == A, strprintf('%d: X5800 == A', base+7)); - X5800 = Y5800 = B; - print base+8: ': X5800 = Y5800 = B'; - } else { - vrfy(X5800 == B, strprintf('%d: X5800 == B', base+7)); - X5800 = Y5800 = A; - print base+8: ': X5800 = Y5800 = A'; - } - vrfy(X5800 == B, strprintf('%d: X5800 == B', base+9)); - vrfy(Y5800 == B, strprintf('%d: Y5800 == B', base+10)); + /* + * test assignment + */ + X5800 = A; + print base+6: ': X5800 = A'; + if (work) { + vrfy(X5800 == A, strprintf('%d: X5800 == A', base+7)); + X5800 = Y5800 = B; + print base+8: ': X5800 = Y5800 = B'; + } else { + vrfy(X5800 == B, strprintf('%d: X5800 == B', base+7)); + X5800 = Y5800 = A; + print base+8: ': X5800 = Y5800 = A'; + } + vrfy(X5800 == B, strprintf('%d: X5800 == B', base+9)); + vrfy(Y5800 == B, strprintf('%d: Y5800 == B', base+10)); - print base+11: ': Ending test_assign'; + print base+11: ': Ending test_assign'; } print '160: test_assign()'; @@ -6290,1055 +6290,1055 @@ print '160: test_assign()'; * * This function tests is related functions. */ -vrfy(isobjtype("xy5900") == 0, '161: isobjtype("xy5900") == 0'); +vrfy(isobjtype("xy5900") == 0, '161: isobjtype("xy5900") == 0'); obj xy5900 {x, y}; -print '162: obj xy5900 {x, y}'; -vrfy(isobjtype("xy5900") == 1, '163: isobjtype("xy5900") == 1'); +print '162: obj xy5900 {x, y}'; +vrfy(isobjtype("xy5900") == 1, '163: isobjtype("xy5900") == 1'); /**/ -vrfy(isdefined("fun5900") == 0, '164: isdefined("fun5900") == 0'); +vrfy(isdefined("fun5900") == 0, '164: isdefined("fun5900") == 0'); define fun5900() { return 1; }; -print '165: define fun5900() { return 1; }'; -vrfy(isdefined("fun5900") == 2, '166: isdefined("fun5900") == 2'); +print '165: define fun5900() { return 1; }'; +vrfy(isdefined("fun5900") == 2, '166: isdefined("fun5900") == 2'); undefine fun5900; -vrfy(isdefined("fun5900") == 0, '167: isdefined("fun5900") == 0'); +vrfy(isdefined("fun5900") == 0, '167: isdefined("fun5900") == 0'); /**/ define test_is() { - local loc; /* unassigned local variable */ - local a; /* assoc */ - local ofd; /* open file descriptor */ - local cfd; /* closed file descriptor */ - local blk; /* unnamed block */ - local nblk; /* named block */ - local cfg; /* config state */ - local serr; /* system value */ - local nerr; /* new error value */ - local odd; /* odd integer */ - local even; /* even integer that is 10 times odd */ - local hash; /* sha1 hash value */ - local id; /* identity matrix */ - local list; /* list value */ - local matrix; /* non-identity matrix */ - local nul; /* null value */ - local object; /* object */ - local rand; /* rand seed */ - local random; /* random seed */ - local real; /* real non-integer value */ - local prime; /* odd prime */ - local square; /* square of an odd prime */ - local string; /* string */ - local com; /* complex value */ - local rndint; /* a random integer */ - local rndexp; /* a random exponent */ - local rndval; /* rndint ^ rndexp */ - local i; /* integer value */ - local ok; /* 1 ==> issq() tests were OK, 0 ==> failure */ + local loc; /* unassigned local variable */ + local a; /* assoc */ + local ofd; /* open file descriptor */ + local cfd; /* closed file descriptor */ + local blk; /* unnamed block */ + local nblk; /* named block */ + local cfg; /* config state */ + local serr; /* system value */ + local nerr; /* new error value */ + local odd; /* odd integer */ + local even; /* even integer that is 10 times odd */ + local hash; /* sha1 hash value */ + local id; /* identity matrix */ + local list; /* list value */ + local matrix; /* non-identity matrix */ + local nul; /* null value */ + local object; /* object */ + local rand; /* rand seed */ + local random; /* random seed */ + local real; /* real non-integer value */ + local prime; /* odd prime */ + local square; /* square of an odd prime */ + local string; /* string */ + local com; /* complex value */ + local rndint; /* a random integer */ + local rndexp; /* a random exponent */ + local rndval; /* rndint ^ rndexp */ + local i; /* integer value */ + local ok; /* 1 ==> issq() tests were OK, 0 ==> failure */ - print '5900: Beginning test_is'; + print '5900: Beginning test_is'; - /* - * setup values - */ - a = assoc(); - print '5901: a = assoc()'; - if (config("windows")) { - ofd = fopen("NUL:", "rb"); - print '5902: ofd = fopen("NUL:", "rb")'; - cfd = fopen("NUL:", "rb"); - print '5903: cfd = fopen("NUL:", "rb")'; - } else { - ofd = fopen("/dev/null","rb"); - print '5902: ofd = fopen("/dev/null","rb")'; - cfd = fopen("/dev/null","rb"); - print '5903: cfd = fopen("/dev/null","rb")'; - } - fclose(cfd); - print '5904: fclose(cfd)'; - blk = blk(); - print '5905: blk = blk()'; - nblk = blk("blk5900"); - print '5906: nblk = blk("blk5900")'; - cfg = config("all"); - print '5907: cfg = config("all")'; - ecnt += 2; - print '5908: ecnt += 2'; - serr = error("E_1"); - print '5909: serr = error("E_1")'; - nerr = newerror("curds"); - print '5910: nerr = newerror("curds")'; - odd = 23209; - print '5911: odd = 23209'; - even = odd*10; - print '5912: even = odd*10'; - hash = sha1(); - print '5913: hash = sha1()'; - mat id[3,3] = {1,0,0,0,1,0,0,0,1}; - print '5914: id[3,3] = {1,0,0,0,1,0,0,0,1}'; - list = list(2,3,4); - print '5915: list = list(2,3,4)'; - mat matrix[2]; - print '5916: mat matrix[2]'; - nul = null(); - print '5917: nul = null()'; - obj xy5900 object; - print '5918: obj xy5900 object'; - rand = srand(0); - print '5919: rand = srand(0)'; - random = srandom(0); - print '5920: random = srandom(0)'; - real = 345.23045897; - print '5921: real = 345.23045897'; - prime = 3217; - print '5922: prime = 3217'; - square = prime^2; - print '5923: square = prime^2'; - string = "a string"; - print '5924: string = "a string"'; - com = 3+4i; - print '5925: com = 3+4i'; + /* + * setup values + */ + a = assoc(); + print '5901: a = assoc()'; + if (config("windows")) { + ofd = fopen("NUL:", "rb"); + print '5902: ofd = fopen("NUL:", "rb")'; + cfd = fopen("NUL:", "rb"); + print '5903: cfd = fopen("NUL:", "rb")'; + } else { + ofd = fopen("/dev/null","rb"); + print '5902: ofd = fopen("/dev/null","rb")'; + cfd = fopen("/dev/null","rb"); + print '5903: cfd = fopen("/dev/null","rb")'; + } + fclose(cfd); + print '5904: fclose(cfd)'; + blk = blk(); + print '5905: blk = blk()'; + nblk = blk("blk5900"); + print '5906: nblk = blk("blk5900")'; + cfg = config("all"); + print '5907: cfg = config("all")'; + ecnt += 2; + print '5908: ecnt += 2'; + serr = error("E_1"); + print '5909: serr = error("E_1")'; + nerr = newerror("curds"); + print '5910: nerr = newerror("curds")'; + odd = 23209; + print '5911: odd = 23209'; + even = odd*10; + print '5912: even = odd*10'; + hash = sha1(); + print '5913: hash = sha1()'; + mat id[3,3] = {1,0,0,0,1,0,0,0,1}; + print '5914: id[3,3] = {1,0,0,0,1,0,0,0,1}'; + list = list(2,3,4); + print '5915: list = list(2,3,4)'; + mat matrix[2]; + print '5916: mat matrix[2]'; + nul = null(); + print '5917: nul = null()'; + obj xy5900 object; + print '5918: obj xy5900 object'; + rand = srand(0); + print '5919: rand = srand(0)'; + random = srandom(0); + print '5920: random = srandom(0)'; + real = 345.23045897; + print '5921: real = 345.23045897'; + prime = 3217; + print '5922: prime = 3217'; + square = prime^2; + print '5923: square = prime^2'; + string = "a string"; + print '5924: string = "a string"'; + com = 3+4i; + print '5925: com = 3+4i'; - print '5926: test unused'; - print '5927: test unused'; - print '5928: test unused'; - print '5929: test unused'; + print '5926: test unused'; + print '5927: test unused'; + print '5928: test unused'; + print '5929: test unused'; - /* - * test isassoc - */ - vrfy(isassoc(loc) == 0, '5930: isassoc(loc) == 0'); - vrfy(isassoc(a) == 1, '5931: isassoc(a) == 1'); - vrfy(isassoc(ofd) == 0, '5932: isassoc(ofd) == 0'); - vrfy(isassoc(cfd) == 0, '5933: isassoc(cfd) == 0'); - vrfy(isassoc(blk) == 0, '5934: isassoc(blk) == 0'); - vrfy(isassoc(nblk) == 0, '5935: isassoc(nblk) == 0'); - vrfy(isassoc(cfg) == 0, '5936: isassoc(cfg) == 0'); - vrfy(isassoc(serr) == 0, '5937: isassoc(serr) == 0'); - vrfy(isassoc(nerr) == 0, '5938: isassoc(nerr) == 0'); - vrfy(isassoc(odd) == 0, '5939: isassoc(odd) == 0'); - vrfy(isassoc(even) == 0, '5940: isassoc(even) == 0'); - vrfy(isassoc(hash) == 0, '5941: isassoc(hash) == 0'); - vrfy(isassoc(id) == 0, '5942: isassoc(id) == 0'); - vrfy(isassoc(list) == 0, '5943: isassoc(list) == 0'); - vrfy(isassoc(matrix) == 0, '5944: isassoc(matrix) == 0'); - vrfy(isassoc(nul) == 0, '5945: isassoc(nul) == 0'); - vrfy(isassoc(object) == 0, '5946: isassoc(object) == 0'); - vrfy(isassoc(rand) == 0, '5947: isassoc(rand) == 0'); - vrfy(isassoc(random) == 0, '5948: isassoc(random) == 0'); - vrfy(isassoc(real) == 0, '5949: isassoc(real) == 0'); - vrfy(isassoc(prime) == 0, '5950: isassoc(prime) == 0'); - vrfy(isassoc(square) == 0, '5951: isassoc(square) == 0'); - vrfy(isassoc(string) == 0, '5952: isassoc(string) == 0'); - vrfy(isassoc(com) == 0, '5953: isassoc(com) == 0'); - print '5954: test unused'; - print '5955: test unused'; - print '5955: test unused'; - print '5956: test unused'; - print '5957: test unused'; - print '5958: test unused'; - print '5959: test unused'; + /* + * test isassoc + */ + vrfy(isassoc(loc) == 0, '5930: isassoc(loc) == 0'); + vrfy(isassoc(a) == 1, '5931: isassoc(a) == 1'); + vrfy(isassoc(ofd) == 0, '5932: isassoc(ofd) == 0'); + vrfy(isassoc(cfd) == 0, '5933: isassoc(cfd) == 0'); + vrfy(isassoc(blk) == 0, '5934: isassoc(blk) == 0'); + vrfy(isassoc(nblk) == 0, '5935: isassoc(nblk) == 0'); + vrfy(isassoc(cfg) == 0, '5936: isassoc(cfg) == 0'); + vrfy(isassoc(serr) == 0, '5937: isassoc(serr) == 0'); + vrfy(isassoc(nerr) == 0, '5938: isassoc(nerr) == 0'); + vrfy(isassoc(odd) == 0, '5939: isassoc(odd) == 0'); + vrfy(isassoc(even) == 0, '5940: isassoc(even) == 0'); + vrfy(isassoc(hash) == 0, '5941: isassoc(hash) == 0'); + vrfy(isassoc(id) == 0, '5942: isassoc(id) == 0'); + vrfy(isassoc(list) == 0, '5943: isassoc(list) == 0'); + vrfy(isassoc(matrix) == 0, '5944: isassoc(matrix) == 0'); + vrfy(isassoc(nul) == 0, '5945: isassoc(nul) == 0'); + vrfy(isassoc(object) == 0, '5946: isassoc(object) == 0'); + vrfy(isassoc(rand) == 0, '5947: isassoc(rand) == 0'); + vrfy(isassoc(random) == 0, '5948: isassoc(random) == 0'); + vrfy(isassoc(real) == 0, '5949: isassoc(real) == 0'); + vrfy(isassoc(prime) == 0, '5950: isassoc(prime) == 0'); + vrfy(isassoc(square) == 0, '5951: isassoc(square) == 0'); + vrfy(isassoc(string) == 0, '5952: isassoc(string) == 0'); + vrfy(isassoc(com) == 0, '5953: isassoc(com) == 0'); + print '5954: test unused'; + print '5955: test unused'; + print '5955: test unused'; + print '5956: test unused'; + print '5957: test unused'; + print '5958: test unused'; + print '5959: test unused'; - /* - * test isatty - */ - vrfy(isatty(loc) == 0, '5960: isatty(loc) == 0'); - vrfy(isatty(a) == 0, '5961: isatty(a) == 0'); - vrfy(isatty(ofd) == 0, '5962: isatty(ofd) == 0'); - vrfy(isatty(cfd) == 0, '5963: isatty(cfd) == 0'); - vrfy(isatty(blk) == 0, '5964: isatty(blk) == 0'); - vrfy(isatty(nblk) == 0, '5965: isatty(nblk) == 0'); - vrfy(isatty(cfg) == 0, '5966: isatty(cfg) == 0'); - vrfy(isatty(serr) == 0, '5967: isatty(serr) == 0'); - vrfy(isatty(nerr) == 0, '5968: isatty(nerr) == 0'); - vrfy(isatty(odd) == 0, '5969: isatty(odd) == 0'); - vrfy(isatty(even) == 0, '5970: isatty(even) == 0'); - vrfy(isatty(hash) == 0, '5971: isatty(hash) == 0'); - vrfy(isatty(id) == 0, '5972: isatty(id) == 0'); - vrfy(isatty(list) == 0, '5973: isatty(list) == 0'); - vrfy(isatty(matrix) == 0, '5974: isatty(matrix) == 0'); - vrfy(isatty(nul) == 0, '5975: isatty(nul) == 0'); - vrfy(isatty(object) == 0, '5976: isatty(object) == 0'); - vrfy(isatty(rand) == 0, '5977: isatty(rand) == 0'); - vrfy(isatty(random) == 0, '5978: isatty(random) == 0'); - vrfy(isatty(real) == 0, '5979: isatty(real) == 0'); - vrfy(isatty(prime) == 0, '5980: isatty(prime) == 0'); - vrfy(isatty(square) == 0, '5981: isatty(square) == 0'); - vrfy(isatty(string) == 0, '5982: isatty(string) == 0'); - vrfy(isatty(com) == 0, '5983: isatty(com) == 0'); - print '5984: test disabled due to stdin dependency'; - /* if we pipe to awk (for make chk), stdout and stderr are not ttys */ - print '5985: test unused'; - print '5986: test unused'; - vrfy(isatty(files(3)) == 0, '5987: isatty(files(3)) == 0'); - print '5988: test unused'; - print '5989: test unused'; + /* + * test isatty + */ + vrfy(isatty(loc) == 0, '5960: isatty(loc) == 0'); + vrfy(isatty(a) == 0, '5961: isatty(a) == 0'); + vrfy(isatty(ofd) == 0, '5962: isatty(ofd) == 0'); + vrfy(isatty(cfd) == 0, '5963: isatty(cfd) == 0'); + vrfy(isatty(blk) == 0, '5964: isatty(blk) == 0'); + vrfy(isatty(nblk) == 0, '5965: isatty(nblk) == 0'); + vrfy(isatty(cfg) == 0, '5966: isatty(cfg) == 0'); + vrfy(isatty(serr) == 0, '5967: isatty(serr) == 0'); + vrfy(isatty(nerr) == 0, '5968: isatty(nerr) == 0'); + vrfy(isatty(odd) == 0, '5969: isatty(odd) == 0'); + vrfy(isatty(even) == 0, '5970: isatty(even) == 0'); + vrfy(isatty(hash) == 0, '5971: isatty(hash) == 0'); + vrfy(isatty(id) == 0, '5972: isatty(id) == 0'); + vrfy(isatty(list) == 0, '5973: isatty(list) == 0'); + vrfy(isatty(matrix) == 0, '5974: isatty(matrix) == 0'); + vrfy(isatty(nul) == 0, '5975: isatty(nul) == 0'); + vrfy(isatty(object) == 0, '5976: isatty(object) == 0'); + vrfy(isatty(rand) == 0, '5977: isatty(rand) == 0'); + vrfy(isatty(random) == 0, '5978: isatty(random) == 0'); + vrfy(isatty(real) == 0, '5979: isatty(real) == 0'); + vrfy(isatty(prime) == 0, '5980: isatty(prime) == 0'); + vrfy(isatty(square) == 0, '5981: isatty(square) == 0'); + vrfy(isatty(string) == 0, '5982: isatty(string) == 0'); + vrfy(isatty(com) == 0, '5983: isatty(com) == 0'); + print '5984: test disabled due to stdin dependency'; + /* if we pipe to awk (for make chk), stdout and stderr are not ttys */ + print '5985: test unused'; + print '5986: test unused'; + vrfy(isatty(files(3)) == 0, '5987: isatty(files(3)) == 0'); + print '5988: test unused'; + print '5989: test unused'; - /* - * test isblk - */ - vrfy(isblk(loc) == 0, '5990: isblk(loc) == 0'); - vrfy(isblk(a) == 0, '5991: isblk(a) == 0'); - vrfy(isblk(ofd) == 0, '5992: isblk(ofd) == 0'); - vrfy(isblk(cfd) == 0, '5993: isblk(cfd) == 0'); - vrfy(isblk(blk) == 1, '5994: isblk(blk) == 1'); - vrfy(isblk(nblk) == 2, '5995: isblk(nblk) == 2'); - vrfy(isblk(cfg) == 0, '5996: isblk(cfg) == 0'); - vrfy(isblk(serr) == 0, '5997: isblk(serr) == 0'); - vrfy(isblk(nerr) == 0, '5998: isblk(nerr) == 0'); - vrfy(isblk(odd) == 0, '5999: isblk(odd) == 0'); - vrfy(isblk(even) == 0, '6000: isblk(even) == 0'); - vrfy(isblk(hash) == 0, '6001: isblk(hash) == 0'); - vrfy(isblk(id) == 0, '6002: isblk(id) == 0'); - vrfy(isblk(list) == 0, '6003: isblk(list) == 0'); - vrfy(isblk(matrix) == 0, '6004: isblk(matrix) == 0'); - vrfy(isblk(nul) == 0, '6005: isblk(nul) == 0'); - vrfy(isblk(object) == 0, '6006: isblk(object) == 0'); - vrfy(isblk(rand) == 0, '6007: isblk(rand) == 0'); - vrfy(isblk(random) == 0, '6008: isblk(random) == 0'); - vrfy(isblk(real) == 0, '6009: isblk(real) == 0'); - vrfy(isblk(prime) == 0, '6010: isblk(prime) == 0'); - vrfy(isblk(square) == 0, '6011: isblk(square) == 0'); - vrfy(isblk(string) == 0, '6012: isblk(string) == 0'); - vrfy(isblk(com) == 0, '6013: isblk(com) == 0'); - print '6014: test unused'; - print '6015: test unused'; - print '6015: test unused'; - print '6016: test unused'; - print '6017: test unused'; - print '6018: test unused'; - print '6019: test unused'; + /* + * test isblk + */ + vrfy(isblk(loc) == 0, '5990: isblk(loc) == 0'); + vrfy(isblk(a) == 0, '5991: isblk(a) == 0'); + vrfy(isblk(ofd) == 0, '5992: isblk(ofd) == 0'); + vrfy(isblk(cfd) == 0, '5993: isblk(cfd) == 0'); + vrfy(isblk(blk) == 1, '5994: isblk(blk) == 1'); + vrfy(isblk(nblk) == 2, '5995: isblk(nblk) == 2'); + vrfy(isblk(cfg) == 0, '5996: isblk(cfg) == 0'); + vrfy(isblk(serr) == 0, '5997: isblk(serr) == 0'); + vrfy(isblk(nerr) == 0, '5998: isblk(nerr) == 0'); + vrfy(isblk(odd) == 0, '5999: isblk(odd) == 0'); + vrfy(isblk(even) == 0, '6000: isblk(even) == 0'); + vrfy(isblk(hash) == 0, '6001: isblk(hash) == 0'); + vrfy(isblk(id) == 0, '6002: isblk(id) == 0'); + vrfy(isblk(list) == 0, '6003: isblk(list) == 0'); + vrfy(isblk(matrix) == 0, '6004: isblk(matrix) == 0'); + vrfy(isblk(nul) == 0, '6005: isblk(nul) == 0'); + vrfy(isblk(object) == 0, '6006: isblk(object) == 0'); + vrfy(isblk(rand) == 0, '6007: isblk(rand) == 0'); + vrfy(isblk(random) == 0, '6008: isblk(random) == 0'); + vrfy(isblk(real) == 0, '6009: isblk(real) == 0'); + vrfy(isblk(prime) == 0, '6010: isblk(prime) == 0'); + vrfy(isblk(square) == 0, '6011: isblk(square) == 0'); + vrfy(isblk(string) == 0, '6012: isblk(string) == 0'); + vrfy(isblk(com) == 0, '6013: isblk(com) == 0'); + print '6014: test unused'; + print '6015: test unused'; + print '6015: test unused'; + print '6016: test unused'; + print '6017: test unused'; + print '6018: test unused'; + print '6019: test unused'; - /* - * test isconfig - */ - vrfy(isconfig(loc) == 0, '6020: isconfig(loc) == 0'); - vrfy(isconfig(a) == 0, '6021: isconfig(a) == 0'); - vrfy(isconfig(ofd) == 0, '6022: isconfig(ofd) == 0'); - vrfy(isconfig(cfd) == 0, '6023: isconfig(cfd) == 0'); - vrfy(isconfig(blk) == 0, '6024: isconfig(blk) == 0'); - vrfy(isconfig(nblk) == 0, '6025: isconfig(nblk) == 0'); - vrfy(isconfig(cfg) == 1, '6026: isconfig(cfg) == 1'); - vrfy(isconfig(serr) == 0, '6027: isconfig(serr) == 0'); - vrfy(isconfig(nerr) == 0, '6028: isconfig(nerr) == 0'); - vrfy(isconfig(odd) == 0, '6029: isconfig(odd) == 0'); - vrfy(isconfig(even) == 0, '6030: isconfig(even) == 0'); - vrfy(isconfig(hash) == 0, '6031: isconfig(hash) == 0'); - vrfy(isconfig(id) == 0, '6032: isconfig(id) == 0'); - vrfy(isconfig(list) == 0, '6033: isconfig(list) == 0'); - vrfy(isconfig(matrix) == 0, '6034: isconfig(matrix) == 0'); - vrfy(isconfig(nul) == 0, '6035: isconfig(nul) == 0'); - vrfy(isconfig(object) == 0, '6036: isconfig(object) == 0'); - vrfy(isconfig(rand) == 0, '6037: isconfig(rand) == 0'); - vrfy(isconfig(random) == 0, '6038: isconfig(random) == 0'); - vrfy(isconfig(real) == 0, '6039: isconfig(real) == 0'); - vrfy(isconfig(prime) == 0, '6040: isconfig(prime) == 0'); - vrfy(isconfig(square) == 0, '6041: isconfig(square) == 0'); - vrfy(isconfig(string) == 0, '6042: isconfig(string) == 0'); - vrfy(isconfig(com) == 0, '6043: isconfig(com) == 0'); - print '6044: test unused'; - print '6045: test unused'; - print '6045: test unused'; - print '6046: test unused'; - print '6047: test unused'; - print '6048: test unused'; - print '6049: test unused'; + /* + * test isconfig + */ + vrfy(isconfig(loc) == 0, '6020: isconfig(loc) == 0'); + vrfy(isconfig(a) == 0, '6021: isconfig(a) == 0'); + vrfy(isconfig(ofd) == 0, '6022: isconfig(ofd) == 0'); + vrfy(isconfig(cfd) == 0, '6023: isconfig(cfd) == 0'); + vrfy(isconfig(blk) == 0, '6024: isconfig(blk) == 0'); + vrfy(isconfig(nblk) == 0, '6025: isconfig(nblk) == 0'); + vrfy(isconfig(cfg) == 1, '6026: isconfig(cfg) == 1'); + vrfy(isconfig(serr) == 0, '6027: isconfig(serr) == 0'); + vrfy(isconfig(nerr) == 0, '6028: isconfig(nerr) == 0'); + vrfy(isconfig(odd) == 0, '6029: isconfig(odd) == 0'); + vrfy(isconfig(even) == 0, '6030: isconfig(even) == 0'); + vrfy(isconfig(hash) == 0, '6031: isconfig(hash) == 0'); + vrfy(isconfig(id) == 0, '6032: isconfig(id) == 0'); + vrfy(isconfig(list) == 0, '6033: isconfig(list) == 0'); + vrfy(isconfig(matrix) == 0, '6034: isconfig(matrix) == 0'); + vrfy(isconfig(nul) == 0, '6035: isconfig(nul) == 0'); + vrfy(isconfig(object) == 0, '6036: isconfig(object) == 0'); + vrfy(isconfig(rand) == 0, '6037: isconfig(rand) == 0'); + vrfy(isconfig(random) == 0, '6038: isconfig(random) == 0'); + vrfy(isconfig(real) == 0, '6039: isconfig(real) == 0'); + vrfy(isconfig(prime) == 0, '6040: isconfig(prime) == 0'); + vrfy(isconfig(square) == 0, '6041: isconfig(square) == 0'); + vrfy(isconfig(string) == 0, '6042: isconfig(string) == 0'); + vrfy(isconfig(com) == 0, '6043: isconfig(com) == 0'); + print '6044: test unused'; + print '6045: test unused'; + print '6045: test unused'; + print '6046: test unused'; + print '6047: test unused'; + print '6048: test unused'; + print '6049: test unused'; - /* - * test isdefined - */ - vrfy(isdefined("loc") == 0, '6050: isdefined("loc") == 0'); - vrfy(isdefined("a") == 0, '6051: isdefined("a") == 0'); - vrfy(isdefined("ofd") == 0, '6052: isdefined("ofd") == 0'); - vrfy(isdefined("cfd") == 0, '6053: isdefined("cfd") == 0'); - vrfy(isdefined("blk") == 1, '6054: isdefined("blk") == 1'); - vrfy(isdefined("nblk") == 0, '6055: isdefined("nblk") == 0'); - vrfy(isdefined("cfg") == 0, '6056: isdefined("cfg") == 0'); - vrfy(isdefined("serr") == 0, '6057: isdefined("serr") == 0'); - vrfy(isdefined("nerr") == 0, '6058: isdefined("nerr") == 0'); - vrfy(isdefined("odd") == 0, '6059: isdefined("odd") == 0'); - vrfy(isdefined("even") == 0, '6060: isdefined("even") == 0'); - vrfy(isdefined("hash") == 1, '6061: isdefined("hash") == 1'); - vrfy(isdefined("id") == 0, '6062: isdefined("id") == 0'); - vrfy(isdefined("list") == 1, '6063: isdefined("list") == 1'); - vrfy(isdefined("matrix") == 0, '6064: isdefined("matrix") == 0'); - vrfy(isdefined("nul") == 0, '6065: isdefined("nul") == 0'); - vrfy(isdefined("object") == 0, '6066: isdefined("object") == 0'); - vrfy(isdefined("rand") == 1, '6067: isdefined("rand") == 1'); - vrfy(isdefined("random") == 1, '6068: isdefined("random") == 1'); - vrfy(isdefined("real") == 0, '6069: isdefined("real") == 0'); - vrfy(isdefined("prime") == 0, '6070: isdefined("prime") == 0'); - vrfy(isdefined("square") == 0, '6071: isdefined("square") == 0'); - vrfy(isdefined("string") == 0, '6072: isdefined("string") == 0'); - vrfy(isdefined("abs") == 1, '6073: isdefined("abs") == 1'); - vrfy(isdefined("notafunc") == 0, '6074: isdefined("notafunc") == 0'); - vrfy(isdefined("com") == 0, '6075: isdefined("com") == 0'); - print '6076: test unused'; - print '6077: test unused'; - print '6078: test unused'; - print '6079: test unused'; + /* + * test isdefined + */ + vrfy(isdefined("loc") == 0, '6050: isdefined("loc") == 0'); + vrfy(isdefined("a") == 0, '6051: isdefined("a") == 0'); + vrfy(isdefined("ofd") == 0, '6052: isdefined("ofd") == 0'); + vrfy(isdefined("cfd") == 0, '6053: isdefined("cfd") == 0'); + vrfy(isdefined("blk") == 1, '6054: isdefined("blk") == 1'); + vrfy(isdefined("nblk") == 0, '6055: isdefined("nblk") == 0'); + vrfy(isdefined("cfg") == 0, '6056: isdefined("cfg") == 0'); + vrfy(isdefined("serr") == 0, '6057: isdefined("serr") == 0'); + vrfy(isdefined("nerr") == 0, '6058: isdefined("nerr") == 0'); + vrfy(isdefined("odd") == 0, '6059: isdefined("odd") == 0'); + vrfy(isdefined("even") == 0, '6060: isdefined("even") == 0'); + vrfy(isdefined("hash") == 1, '6061: isdefined("hash") == 1'); + vrfy(isdefined("id") == 0, '6062: isdefined("id") == 0'); + vrfy(isdefined("list") == 1, '6063: isdefined("list") == 1'); + vrfy(isdefined("matrix") == 0, '6064: isdefined("matrix") == 0'); + vrfy(isdefined("nul") == 0, '6065: isdefined("nul") == 0'); + vrfy(isdefined("object") == 0, '6066: isdefined("object") == 0'); + vrfy(isdefined("rand") == 1, '6067: isdefined("rand") == 1'); + vrfy(isdefined("random") == 1, '6068: isdefined("random") == 1'); + vrfy(isdefined("real") == 0, '6069: isdefined("real") == 0'); + vrfy(isdefined("prime") == 0, '6070: isdefined("prime") == 0'); + vrfy(isdefined("square") == 0, '6071: isdefined("square") == 0'); + vrfy(isdefined("string") == 0, '6072: isdefined("string") == 0'); + vrfy(isdefined("abs") == 1, '6073: isdefined("abs") == 1'); + vrfy(isdefined("notafunc") == 0, '6074: isdefined("notafunc") == 0'); + vrfy(isdefined("com") == 0, '6075: isdefined("com") == 0'); + print '6076: test unused'; + print '6077: test unused'; + print '6078: test unused'; + print '6079: test unused'; - /* - * test iserror - */ - vrfy(iserror(loc) == 0, '6080: iserror(loc) == 0'); - vrfy(iserror(a) == 0, '6081: iserror(a) == 0'); - vrfy(iserror(ofd) == 0, '6082: iserror(ofd) == 0'); - vrfy(iserror(cfd) == 0, '6083: iserror(cfd) == 0'); - vrfy(iserror(blk) == 0, '6084: iserror(blk) == 0'); - vrfy(iserror(nblk) == 0, '6085: iserror(nblk) == 0'); - vrfy(iserror(cfg) == 0, '6086: iserror(cfg) == 0'); - vrfy(iserror(serr) == 1, '6087: iserror(serr) == 1'); - vrfy(iserror(nerr) > 0, '6088: iserror(nerr) > 0'); - vrfy(iserror(odd) == 0, '6089: iserror(odd) == 0'); - vrfy(iserror(even) == 0, '6090: iserror(even) == 0'); - vrfy(iserror(hash) == 0, '6091: iserror(hash) == 0'); - vrfy(iserror(id) == 0, '6092: iserror(id) == 0'); - vrfy(iserror(list) == 0, '6093: iserror(list) == 0'); - vrfy(iserror(matrix) == 0, '6094: iserror(matrix) == 0'); - vrfy(iserror(nul) == 0, '6095: iserror(nul) == 0'); - vrfy(iserror(object) == 0, '6096: iserror(object) == 0'); - vrfy(iserror(rand) == 0, '6097: iserror(rand) == 0'); - vrfy(iserror(random) == 0, '6098: iserror(random) == 0'); - vrfy(iserror(real) == 0, '6099: iserror(real) == 0'); - vrfy(iserror(prime) == 0, '6100: iserror(prime) == 0'); - vrfy(iserror(square) == 0, '6101: iserror(square) == 0'); - vrfy(iserror(string) == 0, '6102: iserror(string) == 0'); - vrfy(iserror(com) == 0, '6103: iserror(com) == 0'); - print '6104: test unused'; - print '6105: test unused'; - print '6105: test unused'; - print '6106: test unused'; - print '6107: test unused'; - print '6108: test unused'; - print '6109: test unused'; + /* + * test iserror + */ + vrfy(iserror(loc) == 0, '6080: iserror(loc) == 0'); + vrfy(iserror(a) == 0, '6081: iserror(a) == 0'); + vrfy(iserror(ofd) == 0, '6082: iserror(ofd) == 0'); + vrfy(iserror(cfd) == 0, '6083: iserror(cfd) == 0'); + vrfy(iserror(blk) == 0, '6084: iserror(blk) == 0'); + vrfy(iserror(nblk) == 0, '6085: iserror(nblk) == 0'); + vrfy(iserror(cfg) == 0, '6086: iserror(cfg) == 0'); + vrfy(iserror(serr) == 1, '6087: iserror(serr) == 1'); + vrfy(iserror(nerr) > 0, '6088: iserror(nerr) > 0'); + vrfy(iserror(odd) == 0, '6089: iserror(odd) == 0'); + vrfy(iserror(even) == 0, '6090: iserror(even) == 0'); + vrfy(iserror(hash) == 0, '6091: iserror(hash) == 0'); + vrfy(iserror(id) == 0, '6092: iserror(id) == 0'); + vrfy(iserror(list) == 0, '6093: iserror(list) == 0'); + vrfy(iserror(matrix) == 0, '6094: iserror(matrix) == 0'); + vrfy(iserror(nul) == 0, '6095: iserror(nul) == 0'); + vrfy(iserror(object) == 0, '6096: iserror(object) == 0'); + vrfy(iserror(rand) == 0, '6097: iserror(rand) == 0'); + vrfy(iserror(random) == 0, '6098: iserror(random) == 0'); + vrfy(iserror(real) == 0, '6099: iserror(real) == 0'); + vrfy(iserror(prime) == 0, '6100: iserror(prime) == 0'); + vrfy(iserror(square) == 0, '6101: iserror(square) == 0'); + vrfy(iserror(string) == 0, '6102: iserror(string) == 0'); + vrfy(iserror(com) == 0, '6103: iserror(com) == 0'); + print '6104: test unused'; + print '6105: test unused'; + print '6105: test unused'; + print '6106: test unused'; + print '6107: test unused'; + print '6108: test unused'; + print '6109: test unused'; - /* - * test iseven - */ - vrfy(iseven(loc) == 1, '6110: iseven(loc) == 1'); - vrfy(iseven(a) == 0, '6111: iseven(a) == 0'); - vrfy(iseven(ofd) == 0, '6112: iseven(ofd) == 0'); - vrfy(iseven(cfd) == 0, '6113: iseven(cfd) == 0'); - vrfy(iseven(blk) == 0, '6114: iseven(blk) == 0'); - vrfy(iseven(nblk) == 0, '6115: iseven(nblk) == 0'); - vrfy(iseven(cfg) == 0, '6116: iseven(cfg) == 0'); - vrfy(iseven(serr) == 0, '6117: iseven(serr) == 0'); - vrfy(iseven(nerr) == 0, '6118: iseven(nerr) == 0'); - vrfy(iseven(odd) == 0, '6119: iseven(odd) == 0'); - vrfy(iseven(even) == 1, '6120: iseven(even) == 1'); - vrfy(iseven(hash) == 0, '6121: iseven(hash) == 0'); - vrfy(iseven(id) == 0, '6122: iseven(id) == 0'); - vrfy(iseven(list) == 0, '6123: iseven(list) == 0'); - vrfy(iseven(matrix) == 0, '6124: iseven(matrix) == 0'); - vrfy(iseven(nul) == 0, '6125: iseven(nul) == 0'); - vrfy(iseven(object) == 0, '6126: iseven(object) == 0'); - vrfy(iseven(rand) == 0, '6127: iseven(rand) == 0'); - vrfy(iseven(random) == 0, '6128: iseven(random) == 0'); - vrfy(iseven(real) == 0, '6129: iseven(real) == 0'); - vrfy(iseven(prime) == 0, '6130: iseven(prime) == 0'); - vrfy(iseven(square) == 0, '6131: iseven(square) == 0'); - vrfy(iseven(string) == 0, '6132: iseven(string) == 0'); - vrfy(iseven(com) == 0, '6133: iseven(com) == 0'); - print '6134: test unused'; - print '6135: test unused'; - print '6135: test unused'; - print '6136: test unused'; - print '6137: test unused'; - print '6138: test unused'; - print '6139: test unused'; + /* + * test iseven + */ + vrfy(iseven(loc) == 1, '6110: iseven(loc) == 1'); + vrfy(iseven(a) == 0, '6111: iseven(a) == 0'); + vrfy(iseven(ofd) == 0, '6112: iseven(ofd) == 0'); + vrfy(iseven(cfd) == 0, '6113: iseven(cfd) == 0'); + vrfy(iseven(blk) == 0, '6114: iseven(blk) == 0'); + vrfy(iseven(nblk) == 0, '6115: iseven(nblk) == 0'); + vrfy(iseven(cfg) == 0, '6116: iseven(cfg) == 0'); + vrfy(iseven(serr) == 0, '6117: iseven(serr) == 0'); + vrfy(iseven(nerr) == 0, '6118: iseven(nerr) == 0'); + vrfy(iseven(odd) == 0, '6119: iseven(odd) == 0'); + vrfy(iseven(even) == 1, '6120: iseven(even) == 1'); + vrfy(iseven(hash) == 0, '6121: iseven(hash) == 0'); + vrfy(iseven(id) == 0, '6122: iseven(id) == 0'); + vrfy(iseven(list) == 0, '6123: iseven(list) == 0'); + vrfy(iseven(matrix) == 0, '6124: iseven(matrix) == 0'); + vrfy(iseven(nul) == 0, '6125: iseven(nul) == 0'); + vrfy(iseven(object) == 0, '6126: iseven(object) == 0'); + vrfy(iseven(rand) == 0, '6127: iseven(rand) == 0'); + vrfy(iseven(random) == 0, '6128: iseven(random) == 0'); + vrfy(iseven(real) == 0, '6129: iseven(real) == 0'); + vrfy(iseven(prime) == 0, '6130: iseven(prime) == 0'); + vrfy(iseven(square) == 0, '6131: iseven(square) == 0'); + vrfy(iseven(string) == 0, '6132: iseven(string) == 0'); + vrfy(iseven(com) == 0, '6133: iseven(com) == 0'); + print '6134: test unused'; + print '6135: test unused'; + print '6135: test unused'; + print '6136: test unused'; + print '6137: test unused'; + print '6138: test unused'; + print '6139: test unused'; - /* - * test isfile - */ - vrfy(isfile(loc) == 0, '6140: isfile(loc) == 0'); - vrfy(isfile(a) == 0, '6141: isfile(a) == 0'); - vrfy(isfile(ofd) == 1, '6142: isfile(ofd) == 1'); - vrfy(isfile(cfd) == 1, '6143: isfile(cfd) == 1'); - vrfy(isfile(blk) == 0, '6144: isfile(blk) == 0'); - vrfy(isfile(nblk) == 0, '6145: isfile(nblk) == 0'); - vrfy(isfile(cfg) == 0, '6146: isfile(cfg) == 0'); - vrfy(isfile(serr) == 0, '6147: isfile(serr) == 0'); - vrfy(isfile(nerr) == 0, '6148: isfile(nerr) == 0'); - vrfy(isfile(odd) == 0, '6149: isfile(odd) == 0'); - vrfy(isfile(even) == 0, '6150: isfile(even) == 0'); - vrfy(isfile(hash) == 0, '6151: isfile(hash) == 0'); - vrfy(isfile(id) == 0, '6152: isfile(id) == 0'); - vrfy(isfile(list) == 0, '6153: isfile(list) == 0'); - vrfy(isfile(matrix) == 0, '6154: isfile(matrix) == 0'); - vrfy(isfile(nul) == 0, '6155: isfile(nul) == 0'); - vrfy(isfile(object) == 0, '6156: isfile(object) == 0'); - vrfy(isfile(rand) == 0, '6157: isfile(rand) == 0'); - vrfy(isfile(random) == 0, '6158: isfile(random) == 0'); - vrfy(isfile(real) == 0, '6159: isfile(real) == 0'); - vrfy(isfile(prime) == 0, '6160: isfile(prime) == 0'); - vrfy(isfile(square) == 0, '6161: isfile(square) == 0'); - vrfy(isfile(string) == 0, '6162: isfile(string) == 0'); - vrfy(isfile(com) == 0, '6163: isfile(com) == 0'); - vrfy(isfile(files(0)) == 1, '6164: isfile(files(0)) == 1'); - vrfy(isfile(files(1)) == 1, '6165: isfile(files(1)) == 1'); - vrfy(isfile(files(2)) == 1, '6166: isfile(files(2)) == 1'); - vrfy(isfile(files(3)) == 1, '6167: isfile(files(3)) == 1'); - print '6168: test unused'; - print '6169: test unused'; + /* + * test isfile + */ + vrfy(isfile(loc) == 0, '6140: isfile(loc) == 0'); + vrfy(isfile(a) == 0, '6141: isfile(a) == 0'); + vrfy(isfile(ofd) == 1, '6142: isfile(ofd) == 1'); + vrfy(isfile(cfd) == 1, '6143: isfile(cfd) == 1'); + vrfy(isfile(blk) == 0, '6144: isfile(blk) == 0'); + vrfy(isfile(nblk) == 0, '6145: isfile(nblk) == 0'); + vrfy(isfile(cfg) == 0, '6146: isfile(cfg) == 0'); + vrfy(isfile(serr) == 0, '6147: isfile(serr) == 0'); + vrfy(isfile(nerr) == 0, '6148: isfile(nerr) == 0'); + vrfy(isfile(odd) == 0, '6149: isfile(odd) == 0'); + vrfy(isfile(even) == 0, '6150: isfile(even) == 0'); + vrfy(isfile(hash) == 0, '6151: isfile(hash) == 0'); + vrfy(isfile(id) == 0, '6152: isfile(id) == 0'); + vrfy(isfile(list) == 0, '6153: isfile(list) == 0'); + vrfy(isfile(matrix) == 0, '6154: isfile(matrix) == 0'); + vrfy(isfile(nul) == 0, '6155: isfile(nul) == 0'); + vrfy(isfile(object) == 0, '6156: isfile(object) == 0'); + vrfy(isfile(rand) == 0, '6157: isfile(rand) == 0'); + vrfy(isfile(random) == 0, '6158: isfile(random) == 0'); + vrfy(isfile(real) == 0, '6159: isfile(real) == 0'); + vrfy(isfile(prime) == 0, '6160: isfile(prime) == 0'); + vrfy(isfile(square) == 0, '6161: isfile(square) == 0'); + vrfy(isfile(string) == 0, '6162: isfile(string) == 0'); + vrfy(isfile(com) == 0, '6163: isfile(com) == 0'); + vrfy(isfile(files(0)) == 1, '6164: isfile(files(0)) == 1'); + vrfy(isfile(files(1)) == 1, '6165: isfile(files(1)) == 1'); + vrfy(isfile(files(2)) == 1, '6166: isfile(files(2)) == 1'); + vrfy(isfile(files(3)) == 1, '6167: isfile(files(3)) == 1'); + print '6168: test unused'; + print '6169: test unused'; - /* - * test ishash - */ - vrfy(ishash(loc) == 0, '6170: ishash(loc) == 0'); - vrfy(ishash(a) == 0, '6171: ishash(a) == 0'); - vrfy(ishash(ofd) == 0, '6172: ishash(ofd) == 0'); - vrfy(ishash(cfd) == 0, '6173: ishash(cfd) == 0'); - vrfy(ishash(blk) == 0, '6174: ishash(blk) == 0'); - vrfy(ishash(nblk) == 0, '6175: ishash(nblk) == 0'); - vrfy(ishash(cfg) == 0, '6176: ishash(cfg) == 0'); - vrfy(ishash(serr) == 0, '6177: ishash(serr) == 0'); - vrfy(ishash(nerr) == 0, '6178: ishash(nerr) == 0'); - vrfy(ishash(odd) == 0, '6179: ishash(odd) == 0'); - vrfy(ishash(even) == 0, '6180: ishash(even) == 0'); - vrfy(ishash(hash) == 2, '6181: ishash(hash) == 2'); - vrfy(ishash(id) == 0, '6182: ishash(id) == 0'); - vrfy(ishash(list) == 0, '6183: ishash(list) == 0'); - vrfy(ishash(matrix) == 0, '6184: ishash(matrix) == 0'); - vrfy(ishash(nul) == 0, '6185: ishash(nul) == 0'); - vrfy(ishash(object) == 0, '6186: ishash(object) == 0'); - vrfy(ishash(rand) == 0, '6187: ishash(rand) == 0'); - vrfy(ishash(random) == 0, '6188: ishash(random) == 0'); - vrfy(ishash(real) == 0, '6189: ishash(real) == 0'); - vrfy(ishash(prime) == 0, '6190: ishash(prime) == 0'); - vrfy(ishash(square) == 0, '6191: ishash(square) == 0'); - vrfy(ishash(string) == 0, '6192: ishash(string) == 0'); - vrfy(ishash(com) == 0, '6193: ishash(com) == 0'); - print '6194: test unused'; - print '6195: test unused'; - print '6196: test unused'; - print '6197: test unused'; - print '6198: test unused'; - print '6199: test unused'; + /* + * test ishash + */ + vrfy(ishash(loc) == 0, '6170: ishash(loc) == 0'); + vrfy(ishash(a) == 0, '6171: ishash(a) == 0'); + vrfy(ishash(ofd) == 0, '6172: ishash(ofd) == 0'); + vrfy(ishash(cfd) == 0, '6173: ishash(cfd) == 0'); + vrfy(ishash(blk) == 0, '6174: ishash(blk) == 0'); + vrfy(ishash(nblk) == 0, '6175: ishash(nblk) == 0'); + vrfy(ishash(cfg) == 0, '6176: ishash(cfg) == 0'); + vrfy(ishash(serr) == 0, '6177: ishash(serr) == 0'); + vrfy(ishash(nerr) == 0, '6178: ishash(nerr) == 0'); + vrfy(ishash(odd) == 0, '6179: ishash(odd) == 0'); + vrfy(ishash(even) == 0, '6180: ishash(even) == 0'); + vrfy(ishash(hash) == 2, '6181: ishash(hash) == 2'); + vrfy(ishash(id) == 0, '6182: ishash(id) == 0'); + vrfy(ishash(list) == 0, '6183: ishash(list) == 0'); + vrfy(ishash(matrix) == 0, '6184: ishash(matrix) == 0'); + vrfy(ishash(nul) == 0, '6185: ishash(nul) == 0'); + vrfy(ishash(object) == 0, '6186: ishash(object) == 0'); + vrfy(ishash(rand) == 0, '6187: ishash(rand) == 0'); + vrfy(ishash(random) == 0, '6188: ishash(random) == 0'); + vrfy(ishash(real) == 0, '6189: ishash(real) == 0'); + vrfy(ishash(prime) == 0, '6190: ishash(prime) == 0'); + vrfy(ishash(square) == 0, '6191: ishash(square) == 0'); + vrfy(ishash(string) == 0, '6192: ishash(string) == 0'); + vrfy(ishash(com) == 0, '6193: ishash(com) == 0'); + print '6194: test unused'; + print '6195: test unused'; + print '6196: test unused'; + print '6197: test unused'; + print '6198: test unused'; + print '6199: test unused'; - /* - * test isident - */ - vrfy(isident(loc) == 0, '6200: isident(loc) == 0'); - vrfy(isident(a) == 0, '6201: isident(a) == 0'); - vrfy(isident(ofd) == 0, '6202: isident(ofd) == 0'); - vrfy(isident(cfd) == 0, '6203: isident(cfd) == 0'); - vrfy(isident(blk) == 0, '6204: isident(blk) == 0'); - vrfy(isident(nblk) == 0, '6205: isident(nblk) == 0'); - vrfy(isident(cfg) == 0, '6206: isident(cfg) == 0'); - vrfy(isident(serr) == 0, '6207: isident(serr) == 0'); - vrfy(isident(nerr) == 0, '6208: isident(nerr) == 0'); - vrfy(isident(odd) == 0, '6209: isident(odd) == 0'); - vrfy(isident(even) == 0, '6210: isident(even) == 0'); - vrfy(isident(hash) == 0, '6211: isident(hash) == 0'); - vrfy(isident(id) == 1, '6212: isident(id) == 1'); - vrfy(isident(list) == 0, '6213: isident(list) == 0'); - vrfy(isident(matrix) == 0, '6214: isident(matrix) == 0'); - vrfy(isident(nul) == 0, '6215: isident(nul) == 0'); - vrfy(isident(object) == 0, '6216: isident(object) == 0'); - vrfy(isident(rand) == 0, '6217: isident(rand) == 0'); - vrfy(isident(random) == 0, '6218: isident(random) == 0'); - vrfy(isident(real) == 0, '6219: isident(real) == 0'); - vrfy(isident(prime) == 0, '6220: isident(prime) == 0'); - vrfy(isident(square) == 0, '6221: isident(square) == 0'); - vrfy(isident(string) == 0, '6222: isident(string) == 0'); - vrfy(isident(com) == 0, '6223: isident(com) == 0'); - print '6224: test unused'; - print '6225: test unused'; - print '6226: test unused'; - print '6227: test unused'; - print '6228: test unused'; - print '6229: test unused'; + /* + * test isident + */ + vrfy(isident(loc) == 0, '6200: isident(loc) == 0'); + vrfy(isident(a) == 0, '6201: isident(a) == 0'); + vrfy(isident(ofd) == 0, '6202: isident(ofd) == 0'); + vrfy(isident(cfd) == 0, '6203: isident(cfd) == 0'); + vrfy(isident(blk) == 0, '6204: isident(blk) == 0'); + vrfy(isident(nblk) == 0, '6205: isident(nblk) == 0'); + vrfy(isident(cfg) == 0, '6206: isident(cfg) == 0'); + vrfy(isident(serr) == 0, '6207: isident(serr) == 0'); + vrfy(isident(nerr) == 0, '6208: isident(nerr) == 0'); + vrfy(isident(odd) == 0, '6209: isident(odd) == 0'); + vrfy(isident(even) == 0, '6210: isident(even) == 0'); + vrfy(isident(hash) == 0, '6211: isident(hash) == 0'); + vrfy(isident(id) == 1, '6212: isident(id) == 1'); + vrfy(isident(list) == 0, '6213: isident(list) == 0'); + vrfy(isident(matrix) == 0, '6214: isident(matrix) == 0'); + vrfy(isident(nul) == 0, '6215: isident(nul) == 0'); + vrfy(isident(object) == 0, '6216: isident(object) == 0'); + vrfy(isident(rand) == 0, '6217: isident(rand) == 0'); + vrfy(isident(random) == 0, '6218: isident(random) == 0'); + vrfy(isident(real) == 0, '6219: isident(real) == 0'); + vrfy(isident(prime) == 0, '6220: isident(prime) == 0'); + vrfy(isident(square) == 0, '6221: isident(square) == 0'); + vrfy(isident(string) == 0, '6222: isident(string) == 0'); + vrfy(isident(com) == 0, '6223: isident(com) == 0'); + print '6224: test unused'; + print '6225: test unused'; + print '6226: test unused'; + print '6227: test unused'; + print '6228: test unused'; + print '6229: test unused'; - /* - * test isint - */ - vrfy(isint(loc) == 1, '6230: isint(loc) == 1'); - vrfy(isint(a) == 0, '6231: isint(a) == 0'); - vrfy(isint(ofd) == 0, '6232: isint(ofd) == 0'); - vrfy(isint(cfd) == 0, '6233: isint(cfd) == 0'); - vrfy(isint(blk) == 0, '6234: isint(blk) == 0'); - vrfy(isint(nblk) == 0, '6235: isint(nblk) == 0'); - vrfy(isint(cfg) == 0, '6236: isint(cfg) == 0'); - vrfy(isint(serr) == 0, '6237: isint(serr) == 0'); - vrfy(isint(nerr) == 0, '6238: isint(nerr) == 0'); - vrfy(isint(odd) == 1, '6239: isint(odd) == 1'); - vrfy(isint(even) == 1, '6240: isint(even) == 1'); - vrfy(isint(hash) == 0, '6241: isint(hash) == 0'); - vrfy(isint(id) == 0, '6242: isint(id) == 0'); - vrfy(isint(list) == 0, '6243: isint(list) == 0'); - vrfy(isint(matrix) == 0, '6244: isint(matrix) == 0'); - vrfy(isint(nul) == 0, '6245: isint(nul) == 0'); - vrfy(isint(object) == 0, '6246: isint(object) == 0'); - vrfy(isint(rand) == 0, '6247: isint(rand) == 0'); - vrfy(isint(random) == 0, '6248: isint(random) == 0'); - vrfy(isint(real) == 0, '6249: isint(real) == 0'); - vrfy(isint(prime) == 1, '6250: isint(prime) == 1'); - vrfy(isint(square) == 1, '6251: isint(square) == 1'); - vrfy(isint(string) == 0, '6252: isint(string) == 0'); - vrfy(isint(com) == 0, '6253: isint(com) == 0'); - print '6254: test unused'; - print '6255: test unused'; - print '6255: test unused'; - print '6256: test unused'; - print '6257: test unused'; - print '6258: test unused'; - print '6259: test unused'; + /* + * test isint + */ + vrfy(isint(loc) == 1, '6230: isint(loc) == 1'); + vrfy(isint(a) == 0, '6231: isint(a) == 0'); + vrfy(isint(ofd) == 0, '6232: isint(ofd) == 0'); + vrfy(isint(cfd) == 0, '6233: isint(cfd) == 0'); + vrfy(isint(blk) == 0, '6234: isint(blk) == 0'); + vrfy(isint(nblk) == 0, '6235: isint(nblk) == 0'); + vrfy(isint(cfg) == 0, '6236: isint(cfg) == 0'); + vrfy(isint(serr) == 0, '6237: isint(serr) == 0'); + vrfy(isint(nerr) == 0, '6238: isint(nerr) == 0'); + vrfy(isint(odd) == 1, '6239: isint(odd) == 1'); + vrfy(isint(even) == 1, '6240: isint(even) == 1'); + vrfy(isint(hash) == 0, '6241: isint(hash) == 0'); + vrfy(isint(id) == 0, '6242: isint(id) == 0'); + vrfy(isint(list) == 0, '6243: isint(list) == 0'); + vrfy(isint(matrix) == 0, '6244: isint(matrix) == 0'); + vrfy(isint(nul) == 0, '6245: isint(nul) == 0'); + vrfy(isint(object) == 0, '6246: isint(object) == 0'); + vrfy(isint(rand) == 0, '6247: isint(rand) == 0'); + vrfy(isint(random) == 0, '6248: isint(random) == 0'); + vrfy(isint(real) == 0, '6249: isint(real) == 0'); + vrfy(isint(prime) == 1, '6250: isint(prime) == 1'); + vrfy(isint(square) == 1, '6251: isint(square) == 1'); + vrfy(isint(string) == 0, '6252: isint(string) == 0'); + vrfy(isint(com) == 0, '6253: isint(com) == 0'); + print '6254: test unused'; + print '6255: test unused'; + print '6255: test unused'; + print '6256: test unused'; + print '6257: test unused'; + print '6258: test unused'; + print '6259: test unused'; - /* - * test islist - */ - vrfy(islist(loc) == 0, '6260: islist(loc) == 0'); - vrfy(islist(a) == 0, '6261: islist(a) == 0'); - vrfy(islist(ofd) == 0, '6262: islist(ofd) == 0'); - vrfy(islist(cfd) == 0, '6263: islist(cfd) == 0'); - vrfy(islist(blk) == 0, '6264: islist(blk) == 0'); - vrfy(islist(nblk) == 0, '6265: islist(nblk) == 0'); - vrfy(islist(cfg) == 0, '6266: islist(cfg) == 0'); - vrfy(islist(serr) == 0, '6267: islist(serr) == 0'); - vrfy(islist(nerr) == 0, '6268: islist(nerr) == 0'); - vrfy(islist(odd) == 0, '6269: islist(odd) == 0'); - vrfy(islist(even) == 0, '6270: islist(even) == 0'); - vrfy(islist(hash) == 0, '6271: islist(hash) == 0'); - vrfy(islist(id) == 0, '6272: islist(id) == 0'); - vrfy(islist(list) == 1, '6273: islist(list) == 1'); - vrfy(islist(matrix) == 0, '6274: islist(matrix) == 0'); - vrfy(islist(nul) == 0, '6275: islist(nul) == 0'); - vrfy(islist(object) == 0, '6276: islist(object) == 0'); - vrfy(islist(rand) == 0, '6277: islist(rand) == 0'); - vrfy(islist(random) == 0, '6278: islist(random) == 0'); - vrfy(islist(real) == 0, '6279: islist(real) == 0'); - vrfy(islist(prime) == 0, '6280: islist(prime) == 0'); - vrfy(islist(square) == 0, '6281: islist(square) == 0'); - vrfy(islist(string) == 0, '6282: islist(string) == 0'); - vrfy(islist(com) == 0, '6283: islist(com) == 0'); - print '6284: test unused'; - print '6255: test unused'; - print '6285: test unused'; - print '6286: test unused'; - print '6287: test unused'; - print '6288: test unused'; - print '6289: test unused'; + /* + * test islist + */ + vrfy(islist(loc) == 0, '6260: islist(loc) == 0'); + vrfy(islist(a) == 0, '6261: islist(a) == 0'); + vrfy(islist(ofd) == 0, '6262: islist(ofd) == 0'); + vrfy(islist(cfd) == 0, '6263: islist(cfd) == 0'); + vrfy(islist(blk) == 0, '6264: islist(blk) == 0'); + vrfy(islist(nblk) == 0, '6265: islist(nblk) == 0'); + vrfy(islist(cfg) == 0, '6266: islist(cfg) == 0'); + vrfy(islist(serr) == 0, '6267: islist(serr) == 0'); + vrfy(islist(nerr) == 0, '6268: islist(nerr) == 0'); + vrfy(islist(odd) == 0, '6269: islist(odd) == 0'); + vrfy(islist(even) == 0, '6270: islist(even) == 0'); + vrfy(islist(hash) == 0, '6271: islist(hash) == 0'); + vrfy(islist(id) == 0, '6272: islist(id) == 0'); + vrfy(islist(list) == 1, '6273: islist(list) == 1'); + vrfy(islist(matrix) == 0, '6274: islist(matrix) == 0'); + vrfy(islist(nul) == 0, '6275: islist(nul) == 0'); + vrfy(islist(object) == 0, '6276: islist(object) == 0'); + vrfy(islist(rand) == 0, '6277: islist(rand) == 0'); + vrfy(islist(random) == 0, '6278: islist(random) == 0'); + vrfy(islist(real) == 0, '6279: islist(real) == 0'); + vrfy(islist(prime) == 0, '6280: islist(prime) == 0'); + vrfy(islist(square) == 0, '6281: islist(square) == 0'); + vrfy(islist(string) == 0, '6282: islist(string) == 0'); + vrfy(islist(com) == 0, '6283: islist(com) == 0'); + print '6284: test unused'; + print '6255: test unused'; + print '6285: test unused'; + print '6286: test unused'; + print '6287: test unused'; + print '6288: test unused'; + print '6289: test unused'; - /* - * test ismat - */ - vrfy(ismat(loc) == 0, '6290: ismat(loc) == 0'); - vrfy(ismat(a) == 0, '6291: ismat(a) == 0'); - vrfy(ismat(ofd) == 0, '6292: ismat(ofd) == 0'); - vrfy(ismat(cfd) == 0, '6293: ismat(cfd) == 0'); - vrfy(ismat(blk) == 0, '6294: ismat(blk) == 0'); - vrfy(ismat(nblk) == 0, '6295: ismat(nblk) == 0'); - vrfy(ismat(cfg) == 0, '6296: ismat(cfg) == 0'); - vrfy(ismat(serr) == 0, '6297: ismat(serr) == 0'); - vrfy(ismat(nerr) == 0, '6298: ismat(nerr) == 0'); - vrfy(ismat(odd) == 0, '6299: ismat(odd) == 0'); - vrfy(ismat(even) == 0, '6300: ismat(even) == 0'); - vrfy(ismat(hash) == 0, '6301: ismat(hash) == 0'); - vrfy(ismat(id) == 1, '6302: ismat(id) == 1'); - vrfy(ismat(list) == 0, '6303: ismat(list) == 0'); - vrfy(ismat(matrix) == 1, '6304: ismat(matrix) == 1'); - vrfy(ismat(nul) == 0, '6305: ismat(nul) == 0'); - vrfy(ismat(object) == 0, '6306: ismat(object) == 0'); - vrfy(ismat(rand) == 0, '6307: ismat(rand) == 0'); - vrfy(ismat(random) == 0, '6308: ismat(random) == 0'); - vrfy(ismat(real) == 0, '6309: ismat(real) == 0'); - vrfy(ismat(prime) == 0, '6310: ismat(prime) == 0'); - vrfy(ismat(square) == 0, '6311: ismat(square) == 0'); - vrfy(ismat(string) == 0, '6312: ismat(string) == 0'); - vrfy(ismat(com) == 0, '6313: ismat(com) == 0'); - print '6314: test unused'; - print '6215: test unused'; - print '6315: test unused'; - print '6316: test unused'; - print '6317: test unused'; - print '6318: test unused'; - print '6319: test unused'; + /* + * test ismat + */ + vrfy(ismat(loc) == 0, '6290: ismat(loc) == 0'); + vrfy(ismat(a) == 0, '6291: ismat(a) == 0'); + vrfy(ismat(ofd) == 0, '6292: ismat(ofd) == 0'); + vrfy(ismat(cfd) == 0, '6293: ismat(cfd) == 0'); + vrfy(ismat(blk) == 0, '6294: ismat(blk) == 0'); + vrfy(ismat(nblk) == 0, '6295: ismat(nblk) == 0'); + vrfy(ismat(cfg) == 0, '6296: ismat(cfg) == 0'); + vrfy(ismat(serr) == 0, '6297: ismat(serr) == 0'); + vrfy(ismat(nerr) == 0, '6298: ismat(nerr) == 0'); + vrfy(ismat(odd) == 0, '6299: ismat(odd) == 0'); + vrfy(ismat(even) == 0, '6300: ismat(even) == 0'); + vrfy(ismat(hash) == 0, '6301: ismat(hash) == 0'); + vrfy(ismat(id) == 1, '6302: ismat(id) == 1'); + vrfy(ismat(list) == 0, '6303: ismat(list) == 0'); + vrfy(ismat(matrix) == 1, '6304: ismat(matrix) == 1'); + vrfy(ismat(nul) == 0, '6305: ismat(nul) == 0'); + vrfy(ismat(object) == 0, '6306: ismat(object) == 0'); + vrfy(ismat(rand) == 0, '6307: ismat(rand) == 0'); + vrfy(ismat(random) == 0, '6308: ismat(random) == 0'); + vrfy(ismat(real) == 0, '6309: ismat(real) == 0'); + vrfy(ismat(prime) == 0, '6310: ismat(prime) == 0'); + vrfy(ismat(square) == 0, '6311: ismat(square) == 0'); + vrfy(ismat(string) == 0, '6312: ismat(string) == 0'); + vrfy(ismat(com) == 0, '6313: ismat(com) == 0'); + print '6314: test unused'; + print '6215: test unused'; + print '6315: test unused'; + print '6316: test unused'; + print '6317: test unused'; + print '6318: test unused'; + print '6319: test unused'; - /* - * test ismult - */ - vrfy(ismult(odd,even) == 0, '6320: ismult(odd,even) == 0'); - vrfy(ismult(even,odd) == 1, '6321: ismult(even,odd) == 1'); - vrfy(ismult(odd,odd) == 1, '6322: ismult(odd,odd) == 1'); - vrfy(ismult(even,prime) == 0, '6323: ismult(even,prime) == 0'); - vrfy(ismult(square,prime) == 1, '6324: ismult(square,prime) == 1'); - vrfy(ismult(real,prime) == 0, '6325: ismult(real,prime) == 0'); - vrfy(ismult(real,real*34) == 0, '6326: ismult(real,real*34) == 0'); - vrfy(ismult(real*34,real) == 1, '6327: ismult(real*34,real) == 1'); - print '6328: test unused'; - print '6329: test unused'; + /* + * test ismult + */ + vrfy(ismult(odd,even) == 0, '6320: ismult(odd,even) == 0'); + vrfy(ismult(even,odd) == 1, '6321: ismult(even,odd) == 1'); + vrfy(ismult(odd,odd) == 1, '6322: ismult(odd,odd) == 1'); + vrfy(ismult(even,prime) == 0, '6323: ismult(even,prime) == 0'); + vrfy(ismult(square,prime) == 1, '6324: ismult(square,prime) == 1'); + vrfy(ismult(real,prime) == 0, '6325: ismult(real,prime) == 0'); + vrfy(ismult(real,real*34) == 0, '6326: ismult(real,real*34) == 0'); + vrfy(ismult(real*34,real) == 1, '6327: ismult(real*34,real) == 1'); + print '6328: test unused'; + print '6329: test unused'; - /* - * test isnull - */ - vrfy(isnull(loc) == 0, '6330: isnull(loc) == 0'); - vrfy(isnull(a) == 0, '6331: isnull(a) == 0'); - vrfy(isnull(ofd) == 0, '6332: isnull(ofd) == 0'); - vrfy(isnull(cfd) == 0, '6333: isnull(cfd) == 0'); - vrfy(isnull(blk) == 0, '6334: isnull(blk) == 0'); - vrfy(isnull(nblk) == 0, '6335: isnull(nblk) == 0'); - vrfy(isnull(cfg) == 0, '6336: isnull(cfg) == 0'); - vrfy(isnull(serr) == 0, '6337: isnull(serr) == 0'); - vrfy(isnull(nerr) == 0, '6338: isnull(nerr) == 0'); - vrfy(isnull(odd) == 0, '6339: isnull(odd) == 0'); - vrfy(isnull(even) == 0, '6340: isnull(even) == 0'); - vrfy(isnull(hash) == 0, '6341: isnull(hash) == 0'); - vrfy(isnull(id) == 0, '6342: isnull(id) == 0'); - vrfy(isnull(list) == 0, '6343: isnull(list) == 0'); - vrfy(isnull(matrix) == 0, '6344: isnull(matrix) == 0'); - vrfy(isnull(nul) == 1, '6345: isnull(nul) == 1'); - vrfy(isnull(object) == 0, '6346: isnull(object) == 0'); - vrfy(isnull(rand) == 0, '6347: isnull(rand) == 0'); - vrfy(isnull(random) == 0, '6348: isnull(random) == 0'); - vrfy(isnull(real) == 0, '6349: isnull(real) == 0'); - vrfy(isnull(prime) == 0, '6350: isnull(prime) == 0'); - vrfy(isnull(square) == 0, '6351: isnull(square) == 0'); - vrfy(isnull(string) == 0, '6352: isnull(string) == 0'); - vrfy(isnull(com) == 0, '6353: isnull(com) == 0'); - print '6354: test unused'; - print '6355: test unused'; - print '6355: test unused'; - print '6356: test unused'; - print '6357: test unused'; - print '6358: test unused'; - print '6359: test unused'; + /* + * test isnull + */ + vrfy(isnull(loc) == 0, '6330: isnull(loc) == 0'); + vrfy(isnull(a) == 0, '6331: isnull(a) == 0'); + vrfy(isnull(ofd) == 0, '6332: isnull(ofd) == 0'); + vrfy(isnull(cfd) == 0, '6333: isnull(cfd) == 0'); + vrfy(isnull(blk) == 0, '6334: isnull(blk) == 0'); + vrfy(isnull(nblk) == 0, '6335: isnull(nblk) == 0'); + vrfy(isnull(cfg) == 0, '6336: isnull(cfg) == 0'); + vrfy(isnull(serr) == 0, '6337: isnull(serr) == 0'); + vrfy(isnull(nerr) == 0, '6338: isnull(nerr) == 0'); + vrfy(isnull(odd) == 0, '6339: isnull(odd) == 0'); + vrfy(isnull(even) == 0, '6340: isnull(even) == 0'); + vrfy(isnull(hash) == 0, '6341: isnull(hash) == 0'); + vrfy(isnull(id) == 0, '6342: isnull(id) == 0'); + vrfy(isnull(list) == 0, '6343: isnull(list) == 0'); + vrfy(isnull(matrix) == 0, '6344: isnull(matrix) == 0'); + vrfy(isnull(nul) == 1, '6345: isnull(nul) == 1'); + vrfy(isnull(object) == 0, '6346: isnull(object) == 0'); + vrfy(isnull(rand) == 0, '6347: isnull(rand) == 0'); + vrfy(isnull(random) == 0, '6348: isnull(random) == 0'); + vrfy(isnull(real) == 0, '6349: isnull(real) == 0'); + vrfy(isnull(prime) == 0, '6350: isnull(prime) == 0'); + vrfy(isnull(square) == 0, '6351: isnull(square) == 0'); + vrfy(isnull(string) == 0, '6352: isnull(string) == 0'); + vrfy(isnull(com) == 0, '6353: isnull(com) == 0'); + print '6354: test unused'; + print '6355: test unused'; + print '6355: test unused'; + print '6356: test unused'; + print '6357: test unused'; + print '6358: test unused'; + print '6359: test unused'; - /* - * test isnum - */ - vrfy(isnum(loc) == 1, '6360: isnum(loc) == 1'); - vrfy(isnum(a) == 0, '6361: isnum(a) == 0'); - vrfy(isnum(ofd) == 0, '6362: isnum(ofd) == 0'); - vrfy(isnum(cfd) == 0, '6363: isnum(cfd) == 0'); - vrfy(isnum(blk) == 0, '6364: isnum(blk) == 0'); - vrfy(isnum(nblk) == 0, '6365: isnum(nblk) == 0'); - vrfy(isnum(cfg) == 0, '6366: isnum(cfg) == 0'); - vrfy(isnum(serr) == 0, '6367: isnum(serr) == 0'); - vrfy(isnum(nerr) == 0, '6368: isnum(nerr) == 0'); - vrfy(isnum(odd) == 1, '6369: isnum(odd) == 1'); - vrfy(isnum(even) == 1, '6370: isnum(even) == 1'); - vrfy(isnum(hash) == 0, '6371: isnum(hash) == 0'); - vrfy(isnum(id) == 0, '6372: isnum(id) == 0'); - vrfy(isnum(list) == 0, '6373: isnum(list) == 0'); - vrfy(isnum(matrix) == 0, '6374: isnum(matrix) == 0'); - vrfy(isnum(nul) == 0, '6375: isnum(nul) == 0'); - vrfy(isnum(object) == 0, '6376: isnum(object) == 0'); - vrfy(isnum(rand) == 0, '6377: isnum(rand) == 0'); - vrfy(isnum(random) == 0, '6378: isnum(random) == 0'); - vrfy(isnum(real) == 1, '6379: isnum(real) == 1'); - vrfy(isnum(prime) == 1, '6380: isnum(prime) == 1'); - vrfy(isnum(square) == 1, '6381: isnum(square) == 1'); - vrfy(isnum(string) == 0, '6382: isnum(string) == 0'); - vrfy(isnum(com) == 1, '6379: isnum(com) == 1'); - print '6384: test unused'; - print '6385: test unused'; - print '6385: test unused'; - print '6386: test unused'; - print '6387: test unused'; - print '6388: test unused'; - print '6389: test unused'; + /* + * test isnum + */ + vrfy(isnum(loc) == 1, '6360: isnum(loc) == 1'); + vrfy(isnum(a) == 0, '6361: isnum(a) == 0'); + vrfy(isnum(ofd) == 0, '6362: isnum(ofd) == 0'); + vrfy(isnum(cfd) == 0, '6363: isnum(cfd) == 0'); + vrfy(isnum(blk) == 0, '6364: isnum(blk) == 0'); + vrfy(isnum(nblk) == 0, '6365: isnum(nblk) == 0'); + vrfy(isnum(cfg) == 0, '6366: isnum(cfg) == 0'); + vrfy(isnum(serr) == 0, '6367: isnum(serr) == 0'); + vrfy(isnum(nerr) == 0, '6368: isnum(nerr) == 0'); + vrfy(isnum(odd) == 1, '6369: isnum(odd) == 1'); + vrfy(isnum(even) == 1, '6370: isnum(even) == 1'); + vrfy(isnum(hash) == 0, '6371: isnum(hash) == 0'); + vrfy(isnum(id) == 0, '6372: isnum(id) == 0'); + vrfy(isnum(list) == 0, '6373: isnum(list) == 0'); + vrfy(isnum(matrix) == 0, '6374: isnum(matrix) == 0'); + vrfy(isnum(nul) == 0, '6375: isnum(nul) == 0'); + vrfy(isnum(object) == 0, '6376: isnum(object) == 0'); + vrfy(isnum(rand) == 0, '6377: isnum(rand) == 0'); + vrfy(isnum(random) == 0, '6378: isnum(random) == 0'); + vrfy(isnum(real) == 1, '6379: isnum(real) == 1'); + vrfy(isnum(prime) == 1, '6380: isnum(prime) == 1'); + vrfy(isnum(square) == 1, '6381: isnum(square) == 1'); + vrfy(isnum(string) == 0, '6382: isnum(string) == 0'); + vrfy(isnum(com) == 1, '6379: isnum(com) == 1'); + print '6384: test unused'; + print '6385: test unused'; + print '6385: test unused'; + print '6386: test unused'; + print '6387: test unused'; + print '6388: test unused'; + print '6389: test unused'; - /* - * test isobj - */ - vrfy(isobj(loc) == 0, '6390: isobj(loc) == 0'); - vrfy(isobj(a) == 0, '6391: isobj(a) == 0'); - vrfy(isobj(ofd) == 0, '6392: isobj(ofd) == 0'); - vrfy(isobj(cfd) == 0, '6393: isobj(cfd) == 0'); - vrfy(isobj(blk) == 0, '6394: isobj(blk) == 0'); - vrfy(isobj(nblk) == 0, '6395: isobj(nblk) == 0'); - vrfy(isobj(cfg) == 0, '6396: isobj(cfg) == 0'); - vrfy(isobj(serr) == 0, '6397: isobj(serr) == 0'); - vrfy(isobj(nerr) == 0, '6398: isobj(nerr) == 0'); - vrfy(isobj(odd) == 0, '6399: isobj(odd) == 0'); - vrfy(isobj(even) == 0, '6400: isobj(even) == 0'); - vrfy(isobj(hash) == 0, '6401: isobj(hash) == 0'); - vrfy(isobj(id) == 0, '6402: isobj(id) == 0'); - vrfy(isobj(list) == 0, '6403: isobj(list) == 0'); - vrfy(isobj(matrix) == 0, '6404: isobj(matrix) == 0'); - vrfy(isobj(nul) == 0, '6405: isobj(nul) == 0'); - vrfy(isobj(object) == 1, '6406: isobj(object) == 1'); - vrfy(isobj(rand) == 0, '6407: isobj(rand) == 0'); - vrfy(isobj(random) == 0, '6408: isobj(random) == 0'); - vrfy(isobj(real) == 0, '6409: isobj(real) == 0'); - vrfy(isobj(prime) == 0, '6410: isobj(prime) == 0'); - vrfy(isobj(square) == 0, '6411: isobj(square) == 0'); - vrfy(isobj(string) == 0, '6412: isobj(string) == 0'); - vrfy(isobj(com) == 0, '6413: isobj(com) == 0'); - print '6414: test unused'; - print '6415: test unused'; - print '6415: test unused'; - print '6416: test unused'; - print '6417: test unused'; - print '6418: test unused'; - print '6419: test unused'; + /* + * test isobj + */ + vrfy(isobj(loc) == 0, '6390: isobj(loc) == 0'); + vrfy(isobj(a) == 0, '6391: isobj(a) == 0'); + vrfy(isobj(ofd) == 0, '6392: isobj(ofd) == 0'); + vrfy(isobj(cfd) == 0, '6393: isobj(cfd) == 0'); + vrfy(isobj(blk) == 0, '6394: isobj(blk) == 0'); + vrfy(isobj(nblk) == 0, '6395: isobj(nblk) == 0'); + vrfy(isobj(cfg) == 0, '6396: isobj(cfg) == 0'); + vrfy(isobj(serr) == 0, '6397: isobj(serr) == 0'); + vrfy(isobj(nerr) == 0, '6398: isobj(nerr) == 0'); + vrfy(isobj(odd) == 0, '6399: isobj(odd) == 0'); + vrfy(isobj(even) == 0, '6400: isobj(even) == 0'); + vrfy(isobj(hash) == 0, '6401: isobj(hash) == 0'); + vrfy(isobj(id) == 0, '6402: isobj(id) == 0'); + vrfy(isobj(list) == 0, '6403: isobj(list) == 0'); + vrfy(isobj(matrix) == 0, '6404: isobj(matrix) == 0'); + vrfy(isobj(nul) == 0, '6405: isobj(nul) == 0'); + vrfy(isobj(object) == 1, '6406: isobj(object) == 1'); + vrfy(isobj(rand) == 0, '6407: isobj(rand) == 0'); + vrfy(isobj(random) == 0, '6408: isobj(random) == 0'); + vrfy(isobj(real) == 0, '6409: isobj(real) == 0'); + vrfy(isobj(prime) == 0, '6410: isobj(prime) == 0'); + vrfy(isobj(square) == 0, '6411: isobj(square) == 0'); + vrfy(isobj(string) == 0, '6412: isobj(string) == 0'); + vrfy(isobj(com) == 0, '6413: isobj(com) == 0'); + print '6414: test unused'; + print '6415: test unused'; + print '6415: test unused'; + print '6416: test unused'; + print '6417: test unused'; + print '6418: test unused'; + print '6419: test unused'; - /* - * test isobjtype - */ - vrfy(isobjtype("loc") == 0, '6420: isobjtype("loc") == 0'); - vrfy(isobjtype("a") == 0, '6421: isobjtype("a") == 0'); - vrfy(isobjtype("ofd") == 0, '6422: isobjtype("ofd") == 0'); - vrfy(isobjtype("xy5800") == 1, '6423: isobjtype("xy5800") == 1'); - vrfy(isobjtype("xy5900") == 1, '6424: isobjtype("xy5900") == 1'); - print '6425: test unused'; - print '6426: test unused'; - print '6427: test unused'; - print '6428: test unused'; - print '6429: test unused'; + /* + * test isobjtype + */ + vrfy(isobjtype("loc") == 0, '6420: isobjtype("loc") == 0'); + vrfy(isobjtype("a") == 0, '6421: isobjtype("a") == 0'); + vrfy(isobjtype("ofd") == 0, '6422: isobjtype("ofd") == 0'); + vrfy(isobjtype("xy5800") == 1, '6423: isobjtype("xy5800") == 1'); + vrfy(isobjtype("xy5900") == 1, '6424: isobjtype("xy5900") == 1'); + print '6425: test unused'; + print '6426: test unused'; + print '6427: test unused'; + print '6428: test unused'; + print '6429: test unused'; - /* - * test isodd - */ - vrfy(isodd(loc) == 0, '6430: isodd(loc) == 0'); - vrfy(isodd(a) == 0, '6431: isodd(a) == 0'); - vrfy(isodd(ofd) == 0, '6432: isodd(ofd) == 0'); - vrfy(isodd(cfd) == 0, '6433: isodd(cfd) == 0'); - vrfy(isodd(blk) == 0, '6434: isodd(blk) == 0'); - vrfy(isodd(nblk) == 0, '6435: isodd(nblk) == 0'); - vrfy(isodd(cfg) == 0, '6436: isodd(cfg) == 0'); - vrfy(isodd(serr) == 0, '6437: isodd(serr) == 0'); - vrfy(isodd(nerr) == 0, '6438: isodd(nerr) == 0'); - vrfy(isodd(odd) == 1, '6439: isodd(odd) == 1'); - vrfy(isodd(even) == 0, '6440: isodd(even) == 0'); - vrfy(isodd(hash) == 0, '6441: isodd(hash) == 0'); - vrfy(isodd(id) == 0, '6442: isodd(id) == 0'); - vrfy(isodd(list) == 0, '6443: isodd(list) == 0'); - vrfy(isodd(matrix) == 0, '6444: isodd(matrix) == 0'); - vrfy(isodd(nul) == 0, '6445: isodd(nul) == 0'); - vrfy(isodd(object) == 0, '6446: isodd(object) == 0'); - vrfy(isodd(rand) == 0, '6447: isodd(rand) == 0'); - vrfy(isodd(random) == 0, '6448: isodd(random) == 0'); - vrfy(isodd(real) == 0, '6449: isodd(real) == 0'); - vrfy(isodd(prime) == 1, '6450: isodd(prime) == 1'); - vrfy(isodd(square) == 1, '6451: isodd(square) == 1'); - vrfy(isodd(string) == 0, '6452: isodd(string) == 0'); - vrfy(isodd(com) == 0, '6453: isodd(com) == 0'); - print '6454: test unused'; - print '6455: test unused'; - print '6455: test unused'; - print '6456: test unused'; - print '6457: test unused'; - print '6458: test unused'; - print '6459: test unused'; + /* + * test isodd + */ + vrfy(isodd(loc) == 0, '6430: isodd(loc) == 0'); + vrfy(isodd(a) == 0, '6431: isodd(a) == 0'); + vrfy(isodd(ofd) == 0, '6432: isodd(ofd) == 0'); + vrfy(isodd(cfd) == 0, '6433: isodd(cfd) == 0'); + vrfy(isodd(blk) == 0, '6434: isodd(blk) == 0'); + vrfy(isodd(nblk) == 0, '6435: isodd(nblk) == 0'); + vrfy(isodd(cfg) == 0, '6436: isodd(cfg) == 0'); + vrfy(isodd(serr) == 0, '6437: isodd(serr) == 0'); + vrfy(isodd(nerr) == 0, '6438: isodd(nerr) == 0'); + vrfy(isodd(odd) == 1, '6439: isodd(odd) == 1'); + vrfy(isodd(even) == 0, '6440: isodd(even) == 0'); + vrfy(isodd(hash) == 0, '6441: isodd(hash) == 0'); + vrfy(isodd(id) == 0, '6442: isodd(id) == 0'); + vrfy(isodd(list) == 0, '6443: isodd(list) == 0'); + vrfy(isodd(matrix) == 0, '6444: isodd(matrix) == 0'); + vrfy(isodd(nul) == 0, '6445: isodd(nul) == 0'); + vrfy(isodd(object) == 0, '6446: isodd(object) == 0'); + vrfy(isodd(rand) == 0, '6447: isodd(rand) == 0'); + vrfy(isodd(random) == 0, '6448: isodd(random) == 0'); + vrfy(isodd(real) == 0, '6449: isodd(real) == 0'); + vrfy(isodd(prime) == 1, '6450: isodd(prime) == 1'); + vrfy(isodd(square) == 1, '6451: isodd(square) == 1'); + vrfy(isodd(string) == 0, '6452: isodd(string) == 0'); + vrfy(isodd(com) == 0, '6453: isodd(com) == 0'); + print '6454: test unused'; + print '6455: test unused'; + print '6455: test unused'; + print '6456: test unused'; + print '6457: test unused'; + print '6458: test unused'; + print '6459: test unused'; - /* - * test isprime - */ - vrfy(isprime(loc) == 0, '6460: isprime(loc) == 0'); - vrfy(isprime(odd) == 1, '6461: isprime(odd) == 1'); - vrfy(isprime(even) == 0, '6462: isprime(even) == 0'); - vrfy(isprime(prime) == 1, '6463: isprime(prime) == 1'); - vrfy(isprime(square) == 0, '6464: isprime(square) == 0'); - print '6465: test unused'; - print '6466: test unused'; - print '6468: test unused'; - print '6468: test unused'; - print '6469: test unused'; + /* + * test isprime + */ + vrfy(isprime(loc) == 0, '6460: isprime(loc) == 0'); + vrfy(isprime(odd) == 1, '6461: isprime(odd) == 1'); + vrfy(isprime(even) == 0, '6462: isprime(even) == 0'); + vrfy(isprime(prime) == 1, '6463: isprime(prime) == 1'); + vrfy(isprime(square) == 0, '6464: isprime(square) == 0'); + print '6465: test unused'; + print '6466: test unused'; + print '6468: test unused'; + print '6468: test unused'; + print '6469: test unused'; - /* - * test isrand - */ - vrfy(isrand(loc) == 0, '6470: isrand(loc) == 0'); - vrfy(isrand(a) == 0, '6471: isrand(a) == 0'); - vrfy(isrand(ofd) == 0, '6472: isrand(ofd) == 0'); - vrfy(isrand(cfd) == 0, '6473: isrand(cfd) == 0'); - vrfy(isrand(blk) == 0, '6474: isrand(blk) == 0'); - vrfy(isrand(nblk) == 0, '6475: isrand(nblk) == 0'); - vrfy(isrand(cfg) == 0, '6476: isrand(cfg) == 0'); - vrfy(isrand(serr) == 0, '6477: isrand(serr) == 0'); - vrfy(isrand(nerr) == 0, '6478: isrand(nerr) == 0'); - vrfy(isrand(odd) == 0, '6479: isrand(odd) == 0'); - vrfy(isrand(even) == 0, '6480: isrand(even) == 0'); - vrfy(isrand(hash) == 0, '6481: isrand(hash) == 0'); - vrfy(isrand(id) == 0, '6482: isrand(id) == 0'); - vrfy(isrand(list) == 0, '6483: isrand(list) == 0'); - vrfy(isrand(matrix) == 0, '6484: isrand(matrix) == 0'); - vrfy(isrand(nul) == 0, '6485: isrand(nul) == 0'); - vrfy(isrand(object) == 0, '6486: isrand(object) == 0'); - vrfy(isrand(rand) == 1, '6487: isrand(rand) == 1'); - vrfy(isrand(random) == 0, '6488: isrand(random) == 0'); - vrfy(isrand(real) == 0, '6489: isrand(real) == 0'); - vrfy(isrand(prime) == 0, '6490: isrand(prime) == 0'); - vrfy(isrand(square) == 0, '6491: isrand(square) == 0'); - vrfy(isrand(string) == 0, '6492: isrand(string) == 0'); - vrfy(isrand(com) == 0, '6493: isrand(com) == 0'); - print '6494: test unused'; - print '6495: test unused'; - print '6495: test unused'; - print '6496: test unused'; - print '6497: test unused'; - print '6498: test unused'; - print '6499: test unused'; + /* + * test isrand + */ + vrfy(isrand(loc) == 0, '6470: isrand(loc) == 0'); + vrfy(isrand(a) == 0, '6471: isrand(a) == 0'); + vrfy(isrand(ofd) == 0, '6472: isrand(ofd) == 0'); + vrfy(isrand(cfd) == 0, '6473: isrand(cfd) == 0'); + vrfy(isrand(blk) == 0, '6474: isrand(blk) == 0'); + vrfy(isrand(nblk) == 0, '6475: isrand(nblk) == 0'); + vrfy(isrand(cfg) == 0, '6476: isrand(cfg) == 0'); + vrfy(isrand(serr) == 0, '6477: isrand(serr) == 0'); + vrfy(isrand(nerr) == 0, '6478: isrand(nerr) == 0'); + vrfy(isrand(odd) == 0, '6479: isrand(odd) == 0'); + vrfy(isrand(even) == 0, '6480: isrand(even) == 0'); + vrfy(isrand(hash) == 0, '6481: isrand(hash) == 0'); + vrfy(isrand(id) == 0, '6482: isrand(id) == 0'); + vrfy(isrand(list) == 0, '6483: isrand(list) == 0'); + vrfy(isrand(matrix) == 0, '6484: isrand(matrix) == 0'); + vrfy(isrand(nul) == 0, '6485: isrand(nul) == 0'); + vrfy(isrand(object) == 0, '6486: isrand(object) == 0'); + vrfy(isrand(rand) == 1, '6487: isrand(rand) == 1'); + vrfy(isrand(random) == 0, '6488: isrand(random) == 0'); + vrfy(isrand(real) == 0, '6489: isrand(real) == 0'); + vrfy(isrand(prime) == 0, '6490: isrand(prime) == 0'); + vrfy(isrand(square) == 0, '6491: isrand(square) == 0'); + vrfy(isrand(string) == 0, '6492: isrand(string) == 0'); + vrfy(isrand(com) == 0, '6493: isrand(com) == 0'); + print '6494: test unused'; + print '6495: test unused'; + print '6495: test unused'; + print '6496: test unused'; + print '6497: test unused'; + print '6498: test unused'; + print '6499: test unused'; - /* - * test israndom - */ - vrfy(israndom(loc) == 0, '6500: israndom(loc) == 0'); - vrfy(israndom(a) == 0, '6501: israndom(a) == 0'); - vrfy(israndom(ofd) == 0, '6502: israndom(ofd) == 0'); - vrfy(israndom(cfd) == 0, '6503: israndom(cfd) == 0'); - vrfy(israndom(blk) == 0, '6504: israndom(blk) == 0'); - vrfy(israndom(nblk) == 0, '6505: israndom(nblk) == 0'); - vrfy(israndom(cfg) == 0, '6506: israndom(cfg) == 0'); - vrfy(israndom(serr) == 0, '6507: israndom(serr) == 0'); - vrfy(israndom(nerr) == 0, '6508: israndom(nerr) == 0'); - vrfy(israndom(odd) == 0, '6509: israndom(odd) == 0'); - vrfy(israndom(even) == 0, '6510: israndom(even) == 0'); - vrfy(israndom(hash) == 0, '6511: israndom(hash) == 0'); - vrfy(israndom(id) == 0, '6512: israndom(id) == 0'); - vrfy(israndom(list) == 0, '6513: israndom(list) == 0'); - vrfy(israndom(matrix) == 0, '6514: israndom(matrix) == 0'); - vrfy(israndom(nul) == 0, '6515: israndom(nul) == 0'); - vrfy(israndom(object) == 0, '6516: israndom(object) == 0'); - vrfy(israndom(rand) == 0, '6517: israndom(rand) == 0'); - vrfy(israndom(random) == 1, '6518: israndom(random) == 1'); - vrfy(israndom(real) == 0, '6519: israndom(real) == 0'); - vrfy(israndom(prime) == 0, '6520: israndom(prime) == 0'); - vrfy(israndom(square) == 0, '6521: israndom(square) == 0'); - vrfy(israndom(string) == 0, '6522: israndom(string) == 0'); - vrfy(israndom(com) == 0, '6523: israndom(com) == 0'); - print '6524: test unused'; - print '6525: test unused'; - print '6526: test unused'; - print '6527: test unused'; - print '6528: test unused'; - print '6529: test unused'; + /* + * test israndom + */ + vrfy(israndom(loc) == 0, '6500: israndom(loc) == 0'); + vrfy(israndom(a) == 0, '6501: israndom(a) == 0'); + vrfy(israndom(ofd) == 0, '6502: israndom(ofd) == 0'); + vrfy(israndom(cfd) == 0, '6503: israndom(cfd) == 0'); + vrfy(israndom(blk) == 0, '6504: israndom(blk) == 0'); + vrfy(israndom(nblk) == 0, '6505: israndom(nblk) == 0'); + vrfy(israndom(cfg) == 0, '6506: israndom(cfg) == 0'); + vrfy(israndom(serr) == 0, '6507: israndom(serr) == 0'); + vrfy(israndom(nerr) == 0, '6508: israndom(nerr) == 0'); + vrfy(israndom(odd) == 0, '6509: israndom(odd) == 0'); + vrfy(israndom(even) == 0, '6510: israndom(even) == 0'); + vrfy(israndom(hash) == 0, '6511: israndom(hash) == 0'); + vrfy(israndom(id) == 0, '6512: israndom(id) == 0'); + vrfy(israndom(list) == 0, '6513: israndom(list) == 0'); + vrfy(israndom(matrix) == 0, '6514: israndom(matrix) == 0'); + vrfy(israndom(nul) == 0, '6515: israndom(nul) == 0'); + vrfy(israndom(object) == 0, '6516: israndom(object) == 0'); + vrfy(israndom(rand) == 0, '6517: israndom(rand) == 0'); + vrfy(israndom(random) == 1, '6518: israndom(random) == 1'); + vrfy(israndom(real) == 0, '6519: israndom(real) == 0'); + vrfy(israndom(prime) == 0, '6520: israndom(prime) == 0'); + vrfy(israndom(square) == 0, '6521: israndom(square) == 0'); + vrfy(israndom(string) == 0, '6522: israndom(string) == 0'); + vrfy(israndom(com) == 0, '6523: israndom(com) == 0'); + print '6524: test unused'; + print '6525: test unused'; + print '6526: test unused'; + print '6527: test unused'; + print '6528: test unused'; + print '6529: test unused'; - /* - * test isreal - */ - vrfy(isreal(loc) == 1, '6530: isreal(loc) == 1'); - vrfy(isreal(a) == 0, '6531: isreal(a) == 0'); - vrfy(isreal(ofd) == 0, '6532: isreal(ofd) == 0'); - vrfy(isreal(cfd) == 0, '6533: isreal(cfd) == 0'); - vrfy(isreal(blk) == 0, '6534: isreal(blk) == 0'); - vrfy(isreal(nblk) == 0, '6535: isreal(nblk) == 0'); - vrfy(isreal(cfg) == 0, '6536: isreal(cfg) == 0'); - vrfy(isreal(serr) == 0, '6537: isreal(serr) == 0'); - vrfy(isreal(nerr) == 0, '6538: isreal(nerr) == 0'); - vrfy(isreal(odd) == 1, '6539: isreal(odd) == 1'); - vrfy(isreal(even) == 1, '6540: isreal(even) == 1'); - vrfy(isreal(hash) == 0, '6541: isreal(hash) == 0'); - vrfy(isreal(id) == 0, '6542: isreal(id) == 0'); - vrfy(isreal(list) == 0, '6543: isreal(list) == 0'); - vrfy(isreal(matrix) == 0, '6544: isreal(matrix) == 0'); - vrfy(isreal(nul) == 0, '6545: isreal(nul) == 0'); - vrfy(isreal(object) == 0, '6546: isreal(object) == 0'); - vrfy(isreal(rand) == 0, '6547: isreal(rand) == 0'); - vrfy(isreal(random) == 0, '6548: isreal(random) == 0'); - vrfy(isreal(real) == 1, '6549: isreal(real) == 1'); - vrfy(isreal(prime) == 1, '6550: isreal(prime) == 1'); - vrfy(isreal(square) == 1, '6551: isreal(square) == 1'); - vrfy(isreal(string) == 0, '6552: isreal(string) == 0'); - vrfy(isreal(com) == 0, '6553: isreal(com) == 0'); - print '6554: test unused'; - print '6555: test unused'; - print '6555: test unused'; - print '6556: test unused'; - print '6557: test unused'; - print '6558: test unused'; - print '6559: test unused'; + /* + * test isreal + */ + vrfy(isreal(loc) == 1, '6530: isreal(loc) == 1'); + vrfy(isreal(a) == 0, '6531: isreal(a) == 0'); + vrfy(isreal(ofd) == 0, '6532: isreal(ofd) == 0'); + vrfy(isreal(cfd) == 0, '6533: isreal(cfd) == 0'); + vrfy(isreal(blk) == 0, '6534: isreal(blk) == 0'); + vrfy(isreal(nblk) == 0, '6535: isreal(nblk) == 0'); + vrfy(isreal(cfg) == 0, '6536: isreal(cfg) == 0'); + vrfy(isreal(serr) == 0, '6537: isreal(serr) == 0'); + vrfy(isreal(nerr) == 0, '6538: isreal(nerr) == 0'); + vrfy(isreal(odd) == 1, '6539: isreal(odd) == 1'); + vrfy(isreal(even) == 1, '6540: isreal(even) == 1'); + vrfy(isreal(hash) == 0, '6541: isreal(hash) == 0'); + vrfy(isreal(id) == 0, '6542: isreal(id) == 0'); + vrfy(isreal(list) == 0, '6543: isreal(list) == 0'); + vrfy(isreal(matrix) == 0, '6544: isreal(matrix) == 0'); + vrfy(isreal(nul) == 0, '6545: isreal(nul) == 0'); + vrfy(isreal(object) == 0, '6546: isreal(object) == 0'); + vrfy(isreal(rand) == 0, '6547: isreal(rand) == 0'); + vrfy(isreal(random) == 0, '6548: isreal(random) == 0'); + vrfy(isreal(real) == 1, '6549: isreal(real) == 1'); + vrfy(isreal(prime) == 1, '6550: isreal(prime) == 1'); + vrfy(isreal(square) == 1, '6551: isreal(square) == 1'); + vrfy(isreal(string) == 0, '6552: isreal(string) == 0'); + vrfy(isreal(com) == 0, '6553: isreal(com) == 0'); + print '6554: test unused'; + print '6555: test unused'; + print '6555: test unused'; + print '6556: test unused'; + print '6557: test unused'; + print '6558: test unused'; + print '6559: test unused'; - /* - * test isrel - */ - vrfy(isrel(odd,even) == 0, '6560: isrel(odd,even) == 0'); - vrfy(isrel(even,odd) == 0, '6561: isrel(even,odd) == 0'); - vrfy(isrel(odd,odd) == 0, '6562: isrel(odd,odd) == 0'); - vrfy(isrel(even,prime) == 1, '6563: isrel(even,prime) == 1'); - vrfy(isrel(square,prime) == 0, '6564: isrel(square,prime) == 0'); - vrfy(isrel(prime,square) == 0, '6565: isrel(prime,square) == 0'); - vrfy(isrel(even,square) == 1, '6566: isrel(even,square) == 1'); - vrfy(isrel(prime,even) == 1, '6567: isrel(prime,even) == 1'); - print '6568: test unused'; - print '6569: test unused'; + /* + * test isrel + */ + vrfy(isrel(odd,even) == 0, '6560: isrel(odd,even) == 0'); + vrfy(isrel(even,odd) == 0, '6561: isrel(even,odd) == 0'); + vrfy(isrel(odd,odd) == 0, '6562: isrel(odd,odd) == 0'); + vrfy(isrel(even,prime) == 1, '6563: isrel(even,prime) == 1'); + vrfy(isrel(square,prime) == 0, '6564: isrel(square,prime) == 0'); + vrfy(isrel(prime,square) == 0, '6565: isrel(prime,square) == 0'); + vrfy(isrel(even,square) == 1, '6566: isrel(even,square) == 1'); + vrfy(isrel(prime,even) == 1, '6567: isrel(prime,even) == 1'); + print '6568: test unused'; + print '6569: test unused'; - /* - * test bit (this was isset and thus was included here, however - * we leave it here for now rather than renumber - * the tests below) - */ - vrfy(bit(odd,0) == 1, '6570: bit(odd,0) == 1'); - vrfy(bit(odd,1) == 0, '6571: bit(odd,1) == 0'); - vrfy(bit(odd,2) == 0, '6572: bit(odd,2) == 0'); - vrfy(bit(odd,3) == 1, '6573: bit(odd,3) == 1'); - vrfy(bit(real,4) == 1, '6574: bit(real,4) == 1'); - vrfy(bit(real,5) == 0, '6575: bit(real,5) == 0'); - vrfy(bit(real,6) == 1, '6576: bit(real,6) == 1'); - vrfy(bit(real,7) == 0, '6577: bit(real,7) == 0'); - print '6578: test unused'; - print '6579: test unused'; + /* + * test bit (this was isset and thus was included here, however + * we leave it here for now rather than renumber + * the tests below) + */ + vrfy(bit(odd,0) == 1, '6570: bit(odd,0) == 1'); + vrfy(bit(odd,1) == 0, '6571: bit(odd,1) == 0'); + vrfy(bit(odd,2) == 0, '6572: bit(odd,2) == 0'); + vrfy(bit(odd,3) == 1, '6573: bit(odd,3) == 1'); + vrfy(bit(real,4) == 1, '6574: bit(real,4) == 1'); + vrfy(bit(real,5) == 0, '6575: bit(real,5) == 0'); + vrfy(bit(real,6) == 1, '6576: bit(real,6) == 1'); + vrfy(bit(real,7) == 0, '6577: bit(real,7) == 0'); + print '6578: test unused'; + print '6579: test unused'; - /* - * test issimple - */ - vrfy(issimple(loc) == 1, '6580: issimple(loc) == 1'); - vrfy(issimple(a) == 0, '6581: issimple(a) == 0'); - vrfy(issimple(ofd) == 0, '6582: issimple(ofd) == 0'); - vrfy(issimple(cfd) == 0, '6583: issimple(cfd) == 0'); - vrfy(issimple(blk) == 0, '6584: issimple(blk) == 0'); - vrfy(issimple(nblk) == 0, '6585: issimple(nblk) == 0'); - vrfy(issimple(cfg) == 0, '6586: issimple(cfg) == 0'); - vrfy(issimple(serr) == 0, '6587: issimple(serr) == 0'); - vrfy(issimple(nerr) == 0, '6588: issimple(nerr) == 0'); - vrfy(issimple(odd) == 1, '6589: issimple(odd) == 1'); - vrfy(issimple(even) == 1, '6590: issimple(even) == 1'); - vrfy(issimple(hash) == 0, '6591: issimple(hash) == 0'); - vrfy(issimple(id) == 0, '6592: issimple(id) == 0'); - vrfy(issimple(list) == 0, '6593: issimple(list) == 0'); - vrfy(issimple(matrix) == 0, '6594: issimple(matrix) == 0'); - vrfy(issimple(nul) == 1, '6595: issimple(nul) == 1'); - vrfy(issimple(object) == 0, '6596: issimple(object) == 0'); - vrfy(issimple(rand) == 0, '6597: issimple(rand) == 0'); - vrfy(issimple(random) == 0, '6598: issimple(random) == 0'); - vrfy(issimple(real) == 1, '6599: issimple(real) == 1'); - vrfy(issimple(prime) == 1, '6600: issimple(prime) == 1'); - vrfy(issimple(square) == 1, '6601: issimple(square) == 1'); - vrfy(issimple(string) == 1, '6602: issimple(string) == 1'); - vrfy(issimple(com) == 1, '6603: issimple(com) == 1'); - print '6604: test unused'; - print '6605: test unused'; - print '6606: test unused'; - print '6607: test unused'; - print '6608: test unused'; - print '6609: test unused'; + /* + * test issimple + */ + vrfy(issimple(loc) == 1, '6580: issimple(loc) == 1'); + vrfy(issimple(a) == 0, '6581: issimple(a) == 0'); + vrfy(issimple(ofd) == 0, '6582: issimple(ofd) == 0'); + vrfy(issimple(cfd) == 0, '6583: issimple(cfd) == 0'); + vrfy(issimple(blk) == 0, '6584: issimple(blk) == 0'); + vrfy(issimple(nblk) == 0, '6585: issimple(nblk) == 0'); + vrfy(issimple(cfg) == 0, '6586: issimple(cfg) == 0'); + vrfy(issimple(serr) == 0, '6587: issimple(serr) == 0'); + vrfy(issimple(nerr) == 0, '6588: issimple(nerr) == 0'); + vrfy(issimple(odd) == 1, '6589: issimple(odd) == 1'); + vrfy(issimple(even) == 1, '6590: issimple(even) == 1'); + vrfy(issimple(hash) == 0, '6591: issimple(hash) == 0'); + vrfy(issimple(id) == 0, '6592: issimple(id) == 0'); + vrfy(issimple(list) == 0, '6593: issimple(list) == 0'); + vrfy(issimple(matrix) == 0, '6594: issimple(matrix) == 0'); + vrfy(issimple(nul) == 1, '6595: issimple(nul) == 1'); + vrfy(issimple(object) == 0, '6596: issimple(object) == 0'); + vrfy(issimple(rand) == 0, '6597: issimple(rand) == 0'); + vrfy(issimple(random) == 0, '6598: issimple(random) == 0'); + vrfy(issimple(real) == 1, '6599: issimple(real) == 1'); + vrfy(issimple(prime) == 1, '6600: issimple(prime) == 1'); + vrfy(issimple(square) == 1, '6601: issimple(square) == 1'); + vrfy(issimple(string) == 1, '6602: issimple(string) == 1'); + vrfy(issimple(com) == 1, '6603: issimple(com) == 1'); + print '6604: test unused'; + print '6605: test unused'; + print '6606: test unused'; + print '6607: test unused'; + print '6608: test unused'; + print '6609: test unused'; - /* - * test issq - */ - vrfy(issq(loc) == 1, '6610: issq(loc) == 1'); - vrfy(issq(odd) == 0, '6611: issq(odd) == 0'); - vrfy(issq(even) == 0, '6612: issq(even) == 0'); - vrfy(issq(prime) == 0, '6613: issq(prime) == 0'); - vrfy(issq(square) == 1, '6614: issq(square) == 1'); - print '6615: test unused'; - print '6616: test unused'; - print '6618: test unused'; - print '6618: test unused'; - print '6619: test unused'; + /* + * test issq + */ + vrfy(issq(loc) == 1, '6610: issq(loc) == 1'); + vrfy(issq(odd) == 0, '6611: issq(odd) == 0'); + vrfy(issq(even) == 0, '6612: issq(even) == 0'); + vrfy(issq(prime) == 0, '6613: issq(prime) == 0'); + vrfy(issq(square) == 1, '6614: issq(square) == 1'); + print '6615: test unused'; + print '6616: test unused'; + print '6618: test unused'; + print '6618: test unused'; + print '6619: test unused'; - /* - * test isstr - */ - vrfy(isstr(loc) == 0, '6620: isstr(loc) == 0'); - vrfy(isstr(a) == 0, '6621: isstr(a) == 0'); - vrfy(isstr(ofd) == 0, '6622: isstr(ofd) == 0'); - vrfy(isstr(cfd) == 0, '6623: isstr(cfd) == 0'); - vrfy(isstr(blk) == 0, '6624: isstr(blk) == 0'); - vrfy(isstr(nblk) == 0, '6625: isstr(nblk) == 0'); - vrfy(isstr(cfg) == 0, '6626: isstr(cfg) == 0'); - vrfy(isstr(serr) == 0, '6627: isstr(serr) == 0'); - vrfy(isstr(nerr) == 0, '6628: isstr(nerr) == 0'); - vrfy(isstr(odd) == 0, '6629: isstr(odd) == 0'); - vrfy(isstr(even) == 0, '6630: isstr(even) == 0'); - vrfy(isstr(hash) == 0, '6631: isstr(hash) == 0'); - vrfy(isstr(id) == 0, '6632: isstr(id) == 0'); - vrfy(isstr(list) == 0, '6633: isstr(list) == 0'); - vrfy(isstr(matrix) == 0, '6634: isstr(matrix) == 0'); - vrfy(isstr(nul) == 0, '6635: isstr(nul) == 0'); - vrfy(isstr(object) == 0, '6636: isstr(object) == 0'); - vrfy(isstr(rand) == 0, '6637: isstr(rand) == 0'); - vrfy(isstr(random) == 0, '6638: isstr(random) == 0'); - vrfy(isstr(real) == 0, '6639: isstr(real) == 0'); - vrfy(isstr(prime) == 0, '6640: isstr(prime) == 0'); - vrfy(isstr(square) == 0, '6641: isstr(square) == 0'); - vrfy(isstr(string) == 1, '6642: isstr(string) == 1'); - vrfy(isstr(com) == 0, '6643: isstr(com) == 0'); - print '6644: test unused'; - print '6645: test unused'; - print '6645: test unused'; - print '6646: test unused'; - print '6647: test unused'; - print '6648: test unused'; - print '6649: test unused'; + /* + * test isstr + */ + vrfy(isstr(loc) == 0, '6620: isstr(loc) == 0'); + vrfy(isstr(a) == 0, '6621: isstr(a) == 0'); + vrfy(isstr(ofd) == 0, '6622: isstr(ofd) == 0'); + vrfy(isstr(cfd) == 0, '6623: isstr(cfd) == 0'); + vrfy(isstr(blk) == 0, '6624: isstr(blk) == 0'); + vrfy(isstr(nblk) == 0, '6625: isstr(nblk) == 0'); + vrfy(isstr(cfg) == 0, '6626: isstr(cfg) == 0'); + vrfy(isstr(serr) == 0, '6627: isstr(serr) == 0'); + vrfy(isstr(nerr) == 0, '6628: isstr(nerr) == 0'); + vrfy(isstr(odd) == 0, '6629: isstr(odd) == 0'); + vrfy(isstr(even) == 0, '6630: isstr(even) == 0'); + vrfy(isstr(hash) == 0, '6631: isstr(hash) == 0'); + vrfy(isstr(id) == 0, '6632: isstr(id) == 0'); + vrfy(isstr(list) == 0, '6633: isstr(list) == 0'); + vrfy(isstr(matrix) == 0, '6634: isstr(matrix) == 0'); + vrfy(isstr(nul) == 0, '6635: isstr(nul) == 0'); + vrfy(isstr(object) == 0, '6636: isstr(object) == 0'); + vrfy(isstr(rand) == 0, '6637: isstr(rand) == 0'); + vrfy(isstr(random) == 0, '6638: isstr(random) == 0'); + vrfy(isstr(real) == 0, '6639: isstr(real) == 0'); + vrfy(isstr(prime) == 0, '6640: isstr(prime) == 0'); + vrfy(isstr(square) == 0, '6641: isstr(square) == 0'); + vrfy(isstr(string) == 1, '6642: isstr(string) == 1'); + vrfy(isstr(com) == 0, '6643: isstr(com) == 0'); + print '6644: test unused'; + print '6645: test unused'; + print '6645: test unused'; + print '6646: test unused'; + print '6647: test unused'; + print '6648: test unused'; + print '6649: test unused'; - /* - * test istype - */ - vrfy(istype(odd,even) == 1, '6650: istype(odd,even) == 1'); - vrfy(istype(even,odd) == 1, '6651: istype(even,odd) == 1'); - vrfy(istype(odd,odd) == 1, '6652: istype(odd,odd) == 1'); - vrfy(istype(even,prime) == 1, '6653: istype(even,prime) == 1'); - vrfy(istype(square,prime) == 1, '6654: istype(square,prime) == 1'); - vrfy(istype(prime,square) == 1, '6655: istype(prime,square) == 1'); - vrfy(istype(even,square) == 1, '6656: istype(even,square) == 1'); - vrfy(istype(prime,even) == 1, '6657: istype(prime,even) == 1'); - vrfy(istype(prime,com) == 0, '6658: istype(prime,com) == 0'); - vrfy(istype(matrix,com) == 0, '6659: istype(matrix,com) == 0'); + /* + * test istype + */ + vrfy(istype(odd,even) == 1, '6650: istype(odd,even) == 1'); + vrfy(istype(even,odd) == 1, '6651: istype(even,odd) == 1'); + vrfy(istype(odd,odd) == 1, '6652: istype(odd,odd) == 1'); + vrfy(istype(even,prime) == 1, '6653: istype(even,prime) == 1'); + vrfy(istype(square,prime) == 1, '6654: istype(square,prime) == 1'); + vrfy(istype(prime,square) == 1, '6655: istype(prime,square) == 1'); + vrfy(istype(even,square) == 1, '6656: istype(even,square) == 1'); + vrfy(istype(prime,even) == 1, '6657: istype(prime,even) == 1'); + vrfy(istype(prime,com) == 0, '6658: istype(prime,com) == 0'); + vrfy(istype(matrix,com) == 0, '6659: istype(matrix,com) == 0'); - vrfy(istype(matrix,list) == 0, '6660: istype(matrix,list) == 0'); - vrfy(istype(matrix,odd) == 0, '6661: istype(matrix,odd) == 0'); - vrfy(istype(a,odd) == 0, '6662: istype(a,odd) == 0'); + vrfy(istype(matrix,list) == 0, '6660: istype(matrix,list) == 0'); + vrfy(istype(matrix,odd) == 0, '6661: istype(matrix,odd) == 0'); + vrfy(istype(a,odd) == 0, '6662: istype(a,odd) == 0'); - /* - * perform more extensive issq() testing - */ - ok = 1; - for (i=0; i < 256; ++i) { - /* rndval will be a square - even powers>0 of x>1 */ - rndexp = random(1, 16) * 2; - rndint = random(2, 4294967296); - if (issq(rndint)) { - ++rndint; - } - rndval = rndint ^ rndexp; - if (issq(rndval) == 0) { - prob(strprintf("issq(%d^%d) returned 0", - rndint, rndexp)); - ok = 0; - } - } - if (ok) { - print '6663: issq() on 256 squares'; - } else { - print '****: failure(s): 6663: faiissq() on 256 squares'; - } - for (i=0; i < 256; ++i) { - /* rndval will not be a square - 1 + even powers>0 of x>1 */ - rndexp = random(1, 16) * 2; - rndint = random(2, 4294967296); - rndval = rndint ^ rndexp; - if (issq(rndval+1) != 0) { - prob(strprintf("issq(%d^%d)+1 returned non-zero", - rndint, rndexp)); - ok = 0; - } - } - if (ok) { - print '6664: issq() on 256 squares+1'; - } else { - print '****: failure(s): 6664: issq() on 256 squares+1'; - } - print '6664: issq() on 256 squares+1'; - for (i=0; i < 256; ++i) { - /* rndval will not be a square - odd powers>0 of x>1 */ - rndexp = (random(1, 16) * 2) + 1; - rndint = random(2, 4294967296); - if (issq(rndint)) { - ++rndint; - } - rndval = rndint ^ rndexp; - if (issq(rndval) != 0) { - prob(strprintf("issq(%d^%d) returned non-zero", - rndint, rndexp)); - ok = 0; - } - } - if (ok) { - print '6665: issq() on 256 non-squares'; - } else { - print '****: failure(s): 6665: issq() on 256 non-squares'; - } + /* + * perform more extensive issq() testing + */ + ok = 1; + for (i=0; i < 256; ++i) { + /* rndval will be a square - even powers>0 of x>1 */ + rndexp = random(1, 16) * 2; + rndint = random(2, 4294967296); + if (issq(rndint)) { + ++rndint; + } + rndval = rndint ^ rndexp; + if (issq(rndval) == 0) { + prob(strprintf("issq(%d^%d) returned 0", + rndint, rndexp)); + ok = 0; + } + } + if (ok) { + print '6663: issq() on 256 squares'; + } else { + print '****: failure(s): 6663: faiissq() on 256 squares'; + } + for (i=0; i < 256; ++i) { + /* rndval will not be a square - 1 + even powers>0 of x>1 */ + rndexp = random(1, 16) * 2; + rndint = random(2, 4294967296); + rndval = rndint ^ rndexp; + if (issq(rndval+1) != 0) { + prob(strprintf("issq(%d^%d)+1 returned non-zero", + rndint, rndexp)); + ok = 0; + } + } + if (ok) { + print '6664: issq() on 256 squares+1'; + } else { + print '****: failure(s): 6664: issq() on 256 squares+1'; + } + print '6664: issq() on 256 squares+1'; + for (i=0; i < 256; ++i) { + /* rndval will not be a square - odd powers>0 of x>1 */ + rndexp = (random(1, 16) * 2) + 1; + rndint = random(2, 4294967296); + if (issq(rndint)) { + ++rndint; + } + rndval = rndint ^ rndexp; + if (issq(rndval) != 0) { + prob(strprintf("issq(%d^%d) returned non-zero", + rndint, rndexp)); + ok = 0; + } + } + if (ok) { + print '6665: issq() on 256 non-squares'; + } else { + print '****: failure(s): 6665: issq() on 256 non-squares'; + } - /* - * cleanup - */ - blkfree("blk5900"); - print '6666: blkfree("blk5900")'; - fclose(ofd); - print '6667: fclose(ofd)'; + /* + * cleanup + */ + blkfree("blk5900"); + print '6666: blkfree("blk5900")'; + fclose(ofd); + print '6667: fclose(ofd)'; - print '6668: Ending test_is'; + print '6668: Ending test_is'; } print '168: test_is()'; @@ -7350,193 +7350,193 @@ print '168: test_is()'; */ define test_blk() { - local A, B, C, A1, A2, B1; + local A, B, C, A1, A2, B1; - print '6700: Beginning test_blk'; + print '6700: Beginning test_blk'; - A = blk(20); - print '6701: A = blk(20);'; - vrfy(size(A) == 20, '6702: size(A) == 20'); - vrfy(sizeof(A) == 256, '6703: sizeof(A) == 256'); - B = A; - print '6704: B = A;'; - vrfy(size(B) == 20, '6705: size(B) == 20'); - vrfy(A == B, '6706: A == B'); + A = blk(20); + print '6701: A = blk(20);'; + vrfy(size(A) == 20, '6702: size(A) == 20'); + vrfy(sizeof(A) == 256, '6703: sizeof(A) == 256'); + B = A; + print '6704: B = A;'; + vrfy(size(B) == 20, '6705: size(B) == 20'); + vrfy(A == B, '6706: A == B'); - A[5] = 21; - print '6707: A[5] = 21;'; - vrfy(A[5] == 21, '6708: A[5] == 21'); + A[5] = 21; + print '6707: A[5] = 21;'; + vrfy(A[5] == 21, '6708: A[5] == 21'); - A[6] = 'abc'; - print '6709: A[6] = "abc";'; - vrfy(A[6] == ord('a'), '6710: A[6] == ord("a")'); + A[6] = 'abc'; + print '6709: A[6] = "abc";'; + vrfy(A[6] == ord('a'), '6710: A[6] == ord("a")'); - A[7] = 260; - print '6711: A[7] = 260;'; - vrfy(A[7] == 4, '6712: A[7] == 4'); + A[7] = 260; + print '6711: A[7] = 260;'; + vrfy(A[7] == 4, '6712: A[7] == 4'); - A[8] = 3+4i; - print '6713: A[8] = 3+4i;'; - vrfy(A[8] == 3, '6714: A[8] == 3'); + A[8] = 3+4i; + print '6713: A[8] = 3+4i;'; + vrfy(A[8] == 3, '6714: A[8] == 3'); - vrfy(A != B, '6715: A != B'); + vrfy(A != B, '6715: A != B'); - /* Equality of blocks of same data-length is unaffected by maxsizes */ + /* Equality of blocks of same data-length is unaffected by maxsizes */ - C = blk(A, ,128); - print '6716: C = blk(A, ,128);'; - vrfy(size(C) == size(A), '6717: size(C) == size(A)'); - vrfy(sizeof(C) == 128, '6718: sizeof(C) == 128'); - vrfy(C == A, '6719: C == A'); + C = blk(A, ,128); + print '6716: C = blk(A, ,128);'; + vrfy(size(C) == size(A), '6717: size(C) == size(A)'); + vrfy(sizeof(C) == 128, '6718: sizeof(C) == 128'); + vrfy(C == A, '6719: C == A'); - /* Blocks of different lengths test as unequal */ + /* Blocks of different lengths test as unequal */ - C = blk(A,30); - print '6720: C = blk(A,30);'; - vrfy(size(C) == 30, '6721: size(C) == 30'); - vrfy(C != A, '6722: C != A;'); + C = blk(A,30); + print '6720: C = blk(A,30);'; + vrfy(size(C) == 30, '6721: size(C) == 30'); + vrfy(C != A, '6722: C != A;'); - /* Reducing length to that of original data restores equality */ + /* Reducing length to that of original data restores equality */ - C = blk(C,20); - print '6723: C = blk(C,20);'; - vrfy(C == A, '6724: C == A'); + C = blk(C,20); + print '6723: C = blk(C,20);'; + vrfy(C == A, '6724: C == A'); - /* Reading block beyond data length extends length */ + /* Reading block beyond data length extends length */ - A[29] = 7; - print '6725: A[29] = 7;'; - vrfy(A[29] == 7, '6726: A[29] == 7'); - vrfy(size(A) == 30, '6727: size(A) == 30'); + A[29] = 7; + print '6725: A[29] = 7;'; + vrfy(A[29] == 7, '6726: A[29] == 7'); + vrfy(size(A) == 30, '6727: size(A) == 30'); - /* Reducing length clears memory beyond new length */ + /* Reducing length clears memory beyond new length */ - A = blk(A, 20); - print '6728: A = blk(A, 20);'; - vrfy(A[29] == 0, '6729: A[29] == 0'); + A = blk(A, 20); + print '6728: A = blk(A, 20);'; + vrfy(A[29] == 0, '6729: A[29] == 0'); - /* Reducing length to zero and initializing a few early values */ + /* Reducing length to zero and initializing a few early values */ - A = blk(A,0) = {1,,3,,5}; - print '6730: A = blk(A,0) = {1,,3,5};'; + A = blk(A,0) = {1,,3,,5}; + print '6730: A = blk(A,0) = {1,,3,5};'; - vrfy(A[4] == 5, '6731: A[4] == 5'); - vrfy(size(A) == 5, '6732: size(A) == 5'); + vrfy(A[4] == 5, '6731: A[4] == 5'); + vrfy(size(A) == 5, '6732: size(A) == 5'); - /* Assignment of copy with initialization */ + /* Assignment of copy with initialization */ - B = A; - print '6733: B = A;'; - C=blk(A)={,,,,,,,,,,0xbb}; - print '6734: C=blk(A)={,,,,,,,,,,0xbb};'; + B = A; + print '6733: B = A;'; + C=blk(A)={,,,,,,,,,,0xbb}; + print '6734: C=blk(A)={,,,,,,,,,,0xbb};'; - /* A has not been changed */ + /* A has not been changed */ - vrfy(A == B, '6735: A == B'); - vrfy(C[10] == 0xbb, '6736: C[10] == 0xbb'); + vrfy(A == B, '6735: A == B'); + vrfy(C[10] == 0xbb, '6736: C[10] == 0xbb'); - /* Testing named blocks */ + /* Testing named blocks */ - A1 = blk("blk6700"); - print '6737: A1 = blk("blk6700");'; - A2 = blk("blk6700"); - print '6738: A2 = blk("blk6700");'; - vrfy(A1 == A2, '6739: A1 == A2'); - vrfy(size(A1) == 0, '6740: size(A1) == 0'); - vrfy(sizeof(A1) == 256, '6741: sizeof(A1) == 256'); - print '6742: test disabled: test(A1) == 0'; - print '6743: test disabled: str(A1) == "blk6700"'; - vrfy(blocks() == 1, '6744: blocks() == 1'); - vrfy(blocks(1) == A1, '6745: blocks(1) == A1'); + A1 = blk("blk6700"); + print '6737: A1 = blk("blk6700");'; + A2 = blk("blk6700"); + print '6738: A2 = blk("blk6700");'; + vrfy(A1 == A2, '6739: A1 == A2'); + vrfy(size(A1) == 0, '6740: size(A1) == 0'); + vrfy(sizeof(A1) == 256, '6741: sizeof(A1) == 256'); + print '6742: test disabled: test(A1) == 0'; + print '6743: test disabled: str(A1) == "blk6700"'; + vrfy(blocks() == 1, '6744: blocks() == 1'); + vrfy(blocks(1) == A1, '6745: blocks(1) == A1'); - /* A second named block */ + /* A second named block */ - B1 = blk("+++6700", 15, 10) = {1,2,3,4,5}; - print - '6746: B1 = blk("+++6700", 15 , 10) = {1,2,3,4,5};'; - vrfy(size(B1) == 15, '6747: size(B1) == 15'); - vrfy(sizeof(B1) == 20, '6748: sizeof(B1) == 20'); - vrfy(test(B1) == 1, '6749: test(B1) == 1'); - print '6750: test disabled: str(B1) == "+++6700"'; - vrfy(blocks() == 2, '6751: blocks() == 2'); - vrfy(blocks(2) == B1, '6752: blocks(2) == B1'); - vrfy(B1 != A1, '6753: B1 != A1'); + B1 = blk("+++6700", 15, 10) = {1,2,3,4,5}; + print + '6746: B1 = blk("+++6700", 15 , 10) = {1,2,3,4,5};'; + vrfy(size(B1) == 15, '6747: size(B1) == 15'); + vrfy(sizeof(B1) == 20, '6748: sizeof(B1) == 20'); + vrfy(test(B1) == 1, '6749: test(B1) == 1'); + print '6750: test disabled: str(B1) == "+++6700"'; + vrfy(blocks() == 2, '6751: blocks() == 2'); + vrfy(blocks(2) == B1, '6752: blocks(2) == B1'); + vrfy(B1 != A1, '6753: B1 != A1'); - /* Referencing octets beyond datalen increases datalen */ + /* Referencing octets beyond datalen increases datalen */ - A1[15] = 29; - print '6754: A1[15] = 29;'; - vrfy(A1[15] == 29, '6755: A1[15] == 29'); - vrfy(A2[15] == 29, '6756: A2[15] == 29'); - vrfy(size(A1) == 16, '6757: size(A1) == 16'); - vrfy(test(A1) == 1, '6758: test(A1) == 1'); - A1[99] = 11; - print '6759: A1[99] = 11;'; - vrfy(size(A1) == 100, '6760: size(A1) == 100'); - vrfy(A1[99] == 11, '6761: A1[99] == 11'); + A1[15] = 29; + print '6754: A1[15] = 29;'; + vrfy(A1[15] == 29, '6755: A1[15] == 29'); + vrfy(A2[15] == 29, '6756: A2[15] == 29'); + vrfy(size(A1) == 16, '6757: size(A1) == 16'); + vrfy(test(A1) == 1, '6758: test(A1) == 1'); + A1[99] = 11; + print '6759: A1[99] = 11;'; + vrfy(size(A1) == 100, '6760: size(A1) == 100'); + vrfy(A1[99] == 11, '6761: A1[99] == 11'); - /* increasing chunksize */ + /* increasing chunksize */ - null(blk(A1, , 1000)); - print '6762: null(blk(A1, , 1000));'; - vrfy(size(A1) == 100, '6763: size(A1) == 100'); - vrfy(sizeof(A1) == 1000, '6764: sizeof(A1) == 1000'); - vrfy(A1[99] == 11, '6765: A1[99] == 11'); + null(blk(A1, , 1000)); + print '6762: null(blk(A1, , 1000));'; + vrfy(size(A1) == 100, '6763: size(A1) == 100'); + vrfy(sizeof(A1) == 1000, '6764: sizeof(A1) == 1000'); + vrfy(A1[99] == 11, '6765: A1[99] == 11'); - /* reducing data-length */ + /* reducing data-length */ - A1 = blk(A1, 10); - print '6766: A1 = blk(A1, 10);'; - vrfy(size(A1) == 10, '6767: size(A1) == 10'); + A1 = blk(A1, 10); + print '6766: A1 = blk(A1, 10);'; + vrfy(size(A1) == 10, '6767: size(A1) == 10'); - /* all octets now zero */ + /* all octets now zero */ - vrfy(test(A1) == 0, '6768: test(A1) == 0'); - vrfy(A1[99] == 0, '6769: A1[99] == 0'); + vrfy(test(A1) == 0, '6768: test(A1) == 0'); + vrfy(A1[99] == 0, '6769: A1[99] == 0'); - /* freeing memory */ + /* freeing memory */ - blkfree(A1); - print '6770: blkfree(A1);'; + blkfree(A1); + print '6770: blkfree(A1);'; - /* freeing named block memory reduces number of unfreed blocks */ + /* freeing named block memory reduces number of unfreed blocks */ - vrfy(blocks() == 1, '6771: blocks() == 1'); + vrfy(blocks() == 1, '6771: blocks() == 1'); - /* 'removed' block still exists but has zero size and maxsize */ + /* 'removed' block still exists but has zero size and maxsize */ - vrfy(blocks(1) == A1, '6772: blocks(1) == A1'); - vrfy(size(A1) == 0, '6773: size(A1) == 0'); - vrfy(sizeof(A1) == 0, '6774: sizeof(A1) == 0'); - vrfy(test(A1) == 0, '6775: test(A1) == 0'); - print '6776: test disabled: str(A1) == "blk6700"'; + vrfy(blocks(1) == A1, '6772: blocks(1) == A1'); + vrfy(size(A1) == 0, '6773: size(A1) == 0'); + vrfy(sizeof(A1) == 0, '6774: sizeof(A1) == 0'); + vrfy(test(A1) == 0, '6775: test(A1) == 0'); + print '6776: test disabled: str(A1) == "blk6700"'; - /* Equality of named blocks not affected by freeing of memory */ + /* Equality of named blocks not affected by freeing of memory */ - vrfy(A1 == A2, '6777: A1 == A2'); + vrfy(A1 == A2, '6777: A1 == A2'); - /* Executing blk('blk6700') reallocates memory for A1 */ + /* Executing blk('blk6700') reallocates memory for A1 */ - null(blk('blk6700')); - print '6778: null(blk("blk6700"));'; - vrfy(size(A1) == 0, '6779: size(A1) == 0'); - vrfy(sizeof(A1) == 1000, '6780: sizeof(A1) == 1000'); + null(blk('blk6700')); + print '6778: null(blk("blk6700"));'; + vrfy(size(A1) == 0, '6779: size(A1) == 0'); + vrfy(sizeof(A1) == 1000, '6780: sizeof(A1) == 1000'); - /* A2 still refers to same block as A1 */ + /* A2 still refers to same block as A1 */ - A1[100] = 0xff; - print '6781: A1[100] = 0xff;'; - vrfy(A2[100] == 0xff, '6782: A2[100] == 0xff'); + A1[100] = 0xff; + print '6781: A1[100] = 0xff;'; + vrfy(A2[100] == 0xff, '6782: A2[100] == 0xff'); - /* A possibly confusing initialization and assignment */ + /* A possibly confusing initialization and assignment */ - mat A1[2] = {A1, B1}; - print '6783: mat A1[2] = {A1, B1};'; - vrfy(A1[0] == A2, '6784: A1[0] == A2'); - vrfy(A1[1] == B1, '6785: A1[1] == B1'); - vrfy(A1[0][100] == 0xff, '6786: A1[0][100] == 0xff'); + mat A1[2] = {A1, B1}; + print '6783: mat A1[2] = {A1, B1};'; + vrfy(A1[0] == A2, '6784: A1[0] == A2'); + vrfy(A1[1] == B1, '6785: A1[1] == B1'); + vrfy(A1[0][100] == 0xff, '6786: A1[0][100] == 0xff'); - print '6787: Ending test_blk'; + print '6787: Ending test_blk'; } print '169: parsed test_blk()'; @@ -7548,158 +7548,158 @@ print '169: parsed test_blk()'; */ define test_blkcpy() { - local A, B, C, A1, A2, B1, fs, S, M1, M2, L1, L2, x; + local A, B, C, A1, A2, B1, fs, S, M1, M2, L1, L2, x; - print '6800: Beginning test_blkcpy'; + print '6800: Beginning test_blkcpy'; - A = blk() = {1,2,3,4,5}; - print '6801: A = blk() = {1,2,3,4,5};'; - B = blk(); - print '6802: B = blk();'; - blkcpy(B, A); - print '6803: blkcpy(B, A);'; - vrfy(A == B, '6804: A == B'); - blkcpy(B, A, ,10); - print '6805: blkcpy(B, A, ,10)'; - vrfy(size(B) == 15, '6806: size(B) == 15'); - blkcpy(B, A, , 15, 3); - print '6807: blkcpy(A, 3, B, 15);'; - vrfy(size(B) == 17, '6808: size(B) == 17'); - vrfy(B[16] == 5, '6809: B[16] == 5'); + A = blk() = {1,2,3,4,5}; + print '6801: A = blk() = {1,2,3,4,5};'; + B = blk(); + print '6802: B = blk();'; + blkcpy(B, A); + print '6803: blkcpy(B, A);'; + vrfy(A == B, '6804: A == B'); + blkcpy(B, A, ,10); + print '6805: blkcpy(B, A, ,10)'; + vrfy(size(B) == 15, '6806: size(B) == 15'); + blkcpy(B, A, , 15, 3); + print '6807: blkcpy(A, 3, B, 15);'; + vrfy(size(B) == 17, '6808: size(B) == 17'); + vrfy(B[16] == 5, '6809: B[16] == 5'); - /* create named block A1 and blkcpy A into B[0]... and B[100]... */ + /* create named block A1 and blkcpy A into B[0]... and B[100]... */ - x = rm("-f", "blk6800"); - print '6810: x = rm("-f", "blk6800")'; - A1 = blk("blk6800"); - print '6811: A1 = blk("blk6800");'; - vrfy(size(A1) == 0, '6812: size(A1) == 0'); - blkcpy(A1, A); - print '6813: blkcpy(A1, A);'; - vrfy(size(A1) == 5, '6814: size(A1) == 5'); - blkcpy(A1, A, ,100); - print '6815: blkcpy(A1, A, ,100);'; - vrfy(size(A1) == 105, '6816: size(A1) == 105'); + x = rm("-f", "blk6800"); + print '6810: x = rm("-f", "blk6800")'; + A1 = blk("blk6800"); + print '6811: A1 = blk("blk6800");'; + vrfy(size(A1) == 0, '6812: size(A1) == 0'); + blkcpy(A1, A); + print '6813: blkcpy(A1, A);'; + vrfy(size(A1) == 5, '6814: size(A1) == 5'); + blkcpy(A1, A, ,100); + print '6815: blkcpy(A1, A, ,100);'; + vrfy(size(A1) == 105, '6816: size(A1) == 105'); - /* create named block B1 and blkcpy first 5 octets of A1 to B[100]... */ + /* create named block B1 and blkcpy first 5 octets of A1 to B[100]... */ - B1 = blk("beta"); - print '6817: B1 = blk("beta")'; - vrfy(size(B1) == 0, '6818: size(B1) == 0'); - blkcpy(B1, A1, 5, 100, 0); - print '6819: blkcpy(B1, A1, 5, 100, 0)'; - vrfy(size(B1) == 105, '6820: size(B1) == 105'); + B1 = blk("beta"); + print '6817: B1 = blk("beta")'; + vrfy(size(B1) == 0, '6818: size(B1) == 0'); + blkcpy(B1, A1, 5, 100, 0); + print '6819: blkcpy(B1, A1, 5, 100, 0)'; + vrfy(size(B1) == 105, '6820: size(B1) == 105'); - /* blkcpy the last 5 octets of B1 to a new block C */ + /* blkcpy the last 5 octets of B1 to a new block C */ - blkcpy(C = blk(), B1,5,,100); - print '6821: blkcpy(C = blk(), B1,5,,100);'; - vrfy(C == A, '6822: C == A'); + blkcpy(C = blk(), B1,5,,100); + print '6821: blkcpy(C = blk(), B1,5,,100);'; + vrfy(C == A, '6822: C == A'); - /* blkcpy to and from a file */ + /* blkcpy to and from a file */ - fs = fopen("junk6800", "w+"); - print '6823: fs = fopen("junk6800", "w+");'; - blkcpy(fs, A); - print '6824: blkcpy(fs, A);'; - vrfy(size(fs) == 5, '6825: size(f) == 5'); - blkcpy(B = blk(), fs); - print '6826: blkcpy(B = blk(), fs);'; - vrfy(B == A, '6827: B == A'); - blkcpy(fs, A, ,100); - print '6828: blkcpy(fs, A, ,100);'; - vrfy(size(fs) == 105, '6829: size(f) == 105'); - blkcpy(C = blk(), fs,2,,100); - print '6830: blkcpy(C = blk(), fs,2,,100)'; - vrfy(C == (blk() = {1,2}), '6831: C == (blk() = {1,2}'); + fs = fopen("junk6800", "w+"); + print '6823: fs = fopen("junk6800", "w+");'; + blkcpy(fs, A); + print '6824: blkcpy(fs, A);'; + vrfy(size(fs) == 5, '6825: size(f) == 5'); + blkcpy(B = blk(), fs); + print '6826: blkcpy(B = blk(), fs);'; + vrfy(B == A, '6827: B == A'); + blkcpy(fs, A, ,100); + print '6828: blkcpy(fs, A, ,100);'; + vrfy(size(fs) == 105, '6829: size(f) == 105'); + blkcpy(C = blk(), fs,2,,100); + print '6830: blkcpy(C = blk(), fs,2,,100)'; + vrfy(C == (blk() = {1,2}), '6831: C == (blk() = {1,2}'); - /* blkcpy string to a block */ + /* blkcpy string to a block */ - A = blk(); - print '6832: A = blk();'; + A = blk(); + print '6832: A = blk();'; - /* Note that "blk6800" is not here considered to name a block */ + /* Note that "blk6800" is not here considered to name a block */ - blkcpy(A, "blk6800 "); - print '6833: blkcpy(A, "blk6800");'; - vrfy(size(A) == 9, '6834: size(A) == 9'); - blkcpy(A, "beta", , 7); - print '6835: blkcpy(A, "beta", , 7);'; - vrfy(size(A) == 12, '6836: size(A) == 12'); + blkcpy(A, "blk6800 "); + print '6833: blkcpy(A, "blk6800");'; + vrfy(size(A) == 9, '6834: size(A) == 9'); + blkcpy(A, "beta", , 7); + print '6835: blkcpy(A, "beta", , 7);'; + vrfy(size(A) == 12, '6836: size(A) == 12'); - /* read strings from A */ + /* read strings from A */ - S = strprintf("%s", A[0]); - print '6837: S = strprintf("%s", A[0]);'; - vrfy(S == "blk6800beta", '6838: S == "blk6800beta"'); - S = strprintf("%s", A[8]); - print '6839: S = strprintf("%s", A[8]);'; - vrfy(S == "eta", '6840: S == "eta"'); + S = strprintf("%s", A[0]); + print '6837: S = strprintf("%s", A[0]);'; + vrfy(S == "blk6800beta", '6838: S == "blk6800beta"'); + S = strprintf("%s", A[8]); + print '6839: S = strprintf("%s", A[8]);'; + vrfy(S == "eta", '6840: S == "eta"'); - mat M1[2,2] = {1,2,3,4}; - print '6841: mat M1[2,2] = {1,2,3,4};'; - mat M2[4]; - print '6842: mat M2[4];'; - blkcpy(M2, M1); - print '6843: blkcpy(M2, M1)'; - vrfy(M2 == (mat[4]={1,2,3,4}), '6844: M2 == (mat[4]={1,2,3,4}'); - blkcpy(M2, M2, 2, 2, 0); - print '6845: blkcpy(M2, M2, 2, 2, 0);'; - vrfy(M2 == (mat[4]={1,2,1,2}), '6846: M2 == (mat[4]={1,2,1,2}'); + mat M1[2,2] = {1,2,3,4}; + print '6841: mat M1[2,2] = {1,2,3,4};'; + mat M2[4]; + print '6842: mat M2[4];'; + blkcpy(M2, M1); + print '6843: blkcpy(M2, M1)'; + vrfy(M2 == (mat[4]={1,2,3,4}), '6844: M2 == (mat[4]={1,2,3,4}'); + blkcpy(M2, M2, 2, 2, 0); + print '6845: blkcpy(M2, M2, 2, 2, 0);'; + vrfy(M2 == (mat[4]={1,2,1,2}), '6846: M2 == (mat[4]={1,2,1,2}'); - /* blkcpy between blocks and matrices */ + /* blkcpy between blocks and matrices */ - B = blk(); - print '6847: B = blk()'; - blkcpy(B, M1); - print '6848: blkcpy(B, M1)'; - vrfy(B == (blk() = {1,2,3,4}), '6849: B == (blk() = {1,2,3,4}'); - blkcpy(M2, B, 2, ,2); - print '6850: blkcpy(B,2,2,M2);'; - vrfy(M2 == (mat[4]={3,4,1,2}), '6851: M2 == (mat[4]={3,4,1,2})'); + B = blk(); + print '6847: B = blk()'; + blkcpy(B, M1); + print '6848: blkcpy(B, M1)'; + vrfy(B == (blk() = {1,2,3,4}), '6849: B == (blk() = {1,2,3,4}'); + blkcpy(M2, B, 2, ,2); + print '6850: blkcpy(B,2,2,M2);'; + vrfy(M2 == (mat[4]={3,4,1,2}), '6851: M2 == (mat[4]={3,4,1,2})'); - /* blkcpy between matrices and lists */ + /* blkcpy between matrices and lists */ - L1 = makelist(4); - print '6852: L1 = makelist(4);'; - blkcpy(L1, M2); - print '6853: blkcpy(L1, M2);'; + L1 = makelist(4); + print '6852: L1 = makelist(4);'; + blkcpy(L1, M2); + print '6853: blkcpy(L1, M2);'; - blkcpy(M2, L1, 2, ,2); - print '6854: blkcpy(M2, L1, 2, ,2);'; - vrfy(M2 == (mat[4]={1,2,1,2}), '6855: M2 == (mat[4]={1,2,1,2}'); + blkcpy(M2, L1, 2, ,2); + print '6854: blkcpy(M2, L1, 2, ,2);'; + vrfy(M2 == (mat[4]={1,2,1,2}), '6855: M2 == (mat[4]={1,2,1,2}'); - /* blkcpy lists to lists */ + /* blkcpy lists to lists */ - L2 = makelist(4); - print '6856: L2 = makelist(4);'; - blkcpy(L2, L1); - print '6857: blkcpy(L2, L1);'; - vrfy(L1 == L2, '6858: L1 == L2'); - blkcpy(L2, L1, 2, 2, 0); - print '6859: blkcpy(L2, L1, 2, 2, 0)'; - vrfy(L2 == list(3,4,3,4), '6860: L2 == list(3,4,3,4)'); + L2 = makelist(4); + print '6856: L2 = makelist(4);'; + blkcpy(L2, L1); + print '6857: blkcpy(L2, L1);'; + vrfy(L1 == L2, '6858: L1 == L2'); + blkcpy(L2, L1, 2, 2, 0); + print '6859: blkcpy(L2, L1, 2, 2, 0)'; + vrfy(L2 == list(3,4,3,4), '6860: L2 == list(3,4,3,4)'); - /* blkcpy between structures and substructures */ + /* blkcpy between structures and substructures */ - M2[0] = L2; - print '6861: M2[0] = L2;'; - blkcpy(M2, M2[0]); - print '6862: blkcpy(M2, M2[0]);'; - vrfy(M2 == (mat[4]={3,4,3,4}), '6863: M2 == (mat[4]={3,4,3,4})'); - M2[2] = list(1,2,3,4); - print '6864: M2[2] = list(1,2,3,4);'; - blkcpy(M2[2], M2); - print '6865: blkcpy(M2[2], M2);'; - vrfy(M2[2][[2]][[2]] == 3, '6866: M2[2][[2]][[2]] == 3'); + M2[0] = L2; + print '6861: M2[0] = L2;'; + blkcpy(M2, M2[0]); + print '6862: blkcpy(M2, M2[0]);'; + vrfy(M2 == (mat[4]={3,4,3,4}), '6863: M2 == (mat[4]={3,4,3,4})'); + M2[2] = list(1,2,3,4); + print '6864: M2[2] = list(1,2,3,4);'; + blkcpy(M2[2], M2); + print '6865: blkcpy(M2[2], M2);'; + vrfy(M2[2][[2]][[2]] == 3, '6866: M2[2][[2]][[2]] == 3'); - /* cleanup */ - fclose(fs); - print '6867: fclose(fs)'; - x = rm("junk6800"); - print '6868: x = rm("junk6800")'; + /* cleanup */ + fclose(fs); + print '6867: fclose(fs)'; + x = rm("junk6800"); + print '6868: x = rm("junk6800")'; - print '6868: Ending test_blkcpy'; + print '6868: Ending test_blkcpy'; } print '170: parsed test_blkcpy()'; @@ -7711,41 +7711,41 @@ print '170: parsed test_blkcpy()'; */ define test_name() { - local f, A, x; + local f, A, x; - print '6900: Beginning test_name'; + print '6900: Beginning test_name'; - x = rm("-f", "junk6900"); - print '6901: x = rm("-f", "junk6900")'; - f = fopen("junk6900", "w"); - print '6902: f = fopen("junk6900", "w")'; - vrfy(name(f) == "junk6900", '6903: name(f) == "junk6900"'); + x = rm("-f", "junk6900"); + print '6901: x = rm("-f", "junk6900")'; + f = fopen("junk6900", "w"); + print '6902: f = fopen("junk6900", "w")'; + vrfy(name(f) == "junk6900", '6903: name(f) == "junk6900"'); - /* file stream loses name when file is closed */ + /* file stream loses name when file is closed */ - fclose(f); - print '6904: fclose(f)'; - vrfy(name(f) == null(), '6905: name(f) == null()'); - A = blk("blk6900"); - print '6906: A = blk("blk6900")'; - vrfy(name(A) == "blk6900", '6907: name(A) == "blk6900"'); + fclose(f); + print '6904: fclose(f)'; + vrfy(name(f) == null(), '6905: name(f) == null()'); + A = blk("blk6900"); + print '6906: A = blk("blk6900")'; + vrfy(name(A) == "blk6900", '6907: name(A) == "blk6900"'); - /* name of block is not lost when its data memory is freed */ + /* name of block is not lost when its data memory is freed */ - blkfree("blk6900"); - print '6908: blkfree("blk6900");'; - vrfy(name(A) == "blk6900", '6909: name(A) == "blk6900"'); + blkfree("blk6900"); + print '6908: blkfree("blk6900");'; + vrfy(name(A) == "blk6900", '6909: name(A) == "blk6900"'); - /* values other than named blocks and files have no name */ + /* values other than named blocks and files have no name */ - vrfy(name(27) == null(), '6910: name(27) == null()'); + vrfy(name(27) == null(), '6910: name(27) == null()'); - /* cleanup */ + /* cleanup */ - x = rm("junk6900"); - print '6911: x = rm("junk6900")'; + x = rm("junk6900"); + print '6911: x = rm("junk6900")'; - print '6912: Ending test_name'; + print '6912: Ending test_name'; } print '171: parsed test_name()'; @@ -7757,39 +7757,39 @@ print '171: parsed test_name()'; */ define test_blkprintf() { - local A, B; + local A, B; - print '7000: Beginning test_blkprintf'; - A = blk("alpha"); - print '7001: A = blk("alpha")'; - B = blk(); - print '7002: B = blk();'; - copy("abc yz", A); - print '7003: copy("abc yz", A);'; - copy("defg", B); - print '7004: copy("defg", B);'; - vrfy(strprintf("%s", A) == "abc yz", - '7005: strprintf("%s", A) == "abc yz"'); - vrfy(strprintf("%s", A[2]) == "c yz", - '7006: strprintf("%s", A[2]) == "c yz"'); - vrfy(strprintf("%s", A[7]) == "", - '7007: strprintf("%s", A[7]) == ""'); - vrfy(strprintf("%c", A) == "a", - '7008: strprintf("%c", A == "a"'); - vrfy(strprintf("%c", A[4]) == "y", - '7009: strprintf("%c", A[4]) == "y"'); - vrfy(strprintf("%s", B) == "defg", - '7010: strprintf("%s", B) == "defg"'); - vrfy(strprintf("%s", B[1]) == "efg", - '7011: strprintf("%s", B[1]) == "efg"'); - vrfy(strprintf("%s", B[7]) == "", - '7012: strprintf("%s", B[7]) == ""'); - vrfy(strprintf("%c", B) == "d", - '7013: strprintf("%c", B == "d"'); - vrfy(strprintf("%c", B[2]) == "f", - '7014: strprintf("%c", B[2]) == "f"'); + print '7000: Beginning test_blkprintf'; + A = blk("alpha"); + print '7001: A = blk("alpha")'; + B = blk(); + print '7002: B = blk();'; + copy("abc yz", A); + print '7003: copy("abc yz", A);'; + copy("defg", B); + print '7004: copy("defg", B);'; + vrfy(strprintf("%s", A) == "abc yz", + '7005: strprintf("%s", A) == "abc yz"'); + vrfy(strprintf("%s", A[2]) == "c yz", + '7006: strprintf("%s", A[2]) == "c yz"'); + vrfy(strprintf("%s", A[7]) == "", + '7007: strprintf("%s", A[7]) == ""'); + vrfy(strprintf("%c", A) == "a", + '7008: strprintf("%c", A == "a"'); + vrfy(strprintf("%c", A[4]) == "y", + '7009: strprintf("%c", A[4]) == "y"'); + vrfy(strprintf("%s", B) == "defg", + '7010: strprintf("%s", B) == "defg"'); + vrfy(strprintf("%s", B[1]) == "efg", + '7011: strprintf("%s", B[1]) == "efg"'); + vrfy(strprintf("%s", B[7]) == "", + '7012: strprintf("%s", B[7]) == ""'); + vrfy(strprintf("%c", B) == "d", + '7013: strprintf("%c", B == "d"'); + vrfy(strprintf("%c", B[2]) == "f", + '7014: strprintf("%c", B[2]) == "f"'); - print '7015: Ending test_blkprintf'; + print '7015: Ending test_blkprintf'; } print '172: parsed test_blkprintf()'; @@ -7807,84 +7807,84 @@ print '172: parsed test_blkprintf()'; */ define test_sha1() { - local a, b, c, d, e, f, x, y, z, L, M, B; + local a, b, c, d, e, f, x, y, z, L, M, B; - print '7200: Beginning test_sha1'; - y = sha1(); - print '7201: y = sha1();'; - z = sha1(); - print '7202: z = sha1();'; - vrfy(y == z, '7203: y == z'); - z = sha1(1); - print '7204: z = sha1(1);'; - vrfy(sha1(y,1) == z, '7205: sha1(y,1) == z'); - vrfy(sha1(z,2) == sha1(1,2), '7206: sha1(z,2) == sha1(1,2)'); - vrfy(sha1(sha1()) == 0xda39a3ee5e6b4b0d3255bfef95601890afd80709, - '7207: sha1(sha1()) == 0xda39a3ee5e6b4b0d3255bfef95601890afd80709'); - vrfy(sha1("x", "y", "z") == sha1("xyz"), - '7208: sha1("x", "y", "z") == sha1("xyz")'); + print '7200: Beginning test_sha1'; + y = sha1(); + print '7201: y = sha1();'; + z = sha1(); + print '7202: z = sha1();'; + vrfy(y == z, '7203: y == z'); + z = sha1(1); + print '7204: z = sha1(1);'; + vrfy(sha1(y,1) == z, '7205: sha1(y,1) == z'); + vrfy(sha1(z,2) == sha1(1,2), '7206: sha1(z,2) == sha1(1,2)'); + vrfy(sha1(sha1()) == 0xda39a3ee5e6b4b0d3255bfef95601890afd80709, + '7207: sha1(sha1()) == 0xda39a3ee5e6b4b0d3255bfef95601890afd80709'); + vrfy(sha1("x", "y", "z") == sha1("xyz"), + '7208: sha1("x", "y", "z") == sha1("xyz")'); - vrfy(sha1(sha1("this is",7^19-8,"a composite",3i+4.5,"hash")) == - 0x68aa4fe0a9b6d1662f8d2dbdeee8879239185d09, - '7209: sha1(sha1("this is",7^19-8,"a composite",3i+4.5,"hash")) ' + - '== ...'); + vrfy(sha1(sha1("this is",7^19-8,"a composite",3i+4.5,"hash")) == + 0x68aa4fe0a9b6d1662f8d2dbdeee8879239185d09, + '7209: sha1(sha1("this is",7^19-8,"a composite",3i+4.5,"hash")) ' + + '== ...'); - z = sha1(list(1,2,3), "curds and whey", 2^21701-1, pi(1e-100)); - print '7210: z = sha1(list(1,2,3), "curds and whey",', - '2^21701-1, pi(1e-100));'; - vrfy(sha1(z) == 0x158cc87deeb9dd478ca14e3ab359205b0fb15b83, - '7211: sha1(z) == 0x158cc87deeb9dd478ca14e3ab359205b0fb15b83'); + z = sha1(list(1,2,3), "curds and whey", 2^21701-1, pi(1e-100)); + print '7210: z = sha1(list(1,2,3), "curds and whey",', + '2^21701-1, pi(1e-100));'; + vrfy(sha1(z) == 0x158cc87deeb9dd478ca14e3ab359205b0fb15b83, + '7211: sha1(z) == 0x158cc87deeb9dd478ca14e3ab359205b0fb15b83'); - y = sha1(); - print '7212: y = sha1();'; - y = sha1(y, list(1,2,3), "curds and whey"); - print '7213: y = sha1(y, list(1,2,3), "curds and whey");'; - y = sha1(y, 2^21701-1); - print '7214: y = sha1(y, 2^21701-1);'; - y = sha1(y, pi(1e-100)); - print '7215: y = sha1(y, pi(1e-100));'; - vrfy(y == z, '7216: y == z'); + y = sha1(); + print '7212: y = sha1();'; + y = sha1(y, list(1,2,3), "curds and whey"); + print '7213: y = sha1(y, list(1,2,3), "curds and whey");'; + y = sha1(y, 2^21701-1); + print '7214: y = sha1(y, 2^21701-1);'; + y = sha1(y, pi(1e-100)); + print '7215: y = sha1(y, pi(1e-100));'; + vrfy(y == z, '7216: y == z'); - vrfy(sha1(sha1("a"))==0x86f7e437faa5a7fce15d1ddcb9eaeaea377667b8, - '7217: sha1(sha1("a"))==0x86f7e437faa5a7fce15d1ddcb9eaeaea377667b8'); + vrfy(sha1(sha1("a"))==0x86f7e437faa5a7fce15d1ddcb9eaeaea377667b8, + '7217: sha1(sha1("a"))==0x86f7e437faa5a7fce15d1ddcb9eaeaea377667b8'); - vrfy(sha1(sha1("ab"))==0xda23614e02469a0d7c7bd1bdab5c9c474b1904dc, - '7218: sha1(sha1("ab"))==0xda23614e02469a0d7c7bd1bdab5c9c474b1904dc'); - vrfy(sha1(sha1("abc"))==0xa9993e364706816aba3e25717850c26c9cd0d89d, - '7219: sha1(sha1("abc"))==0xa9993e364706816aba3e25717850c26c9cd0d89d' - ); - vrfy(sha1(sha1("abcd"))==0x81fe8bfe87576c3ecb22426f8e57847382917acf, - '7220: sha1(sha1("abcd"))==0x81fe8bfe87576c3ecb22426f8e57847382917acf'); - vrfy(sha1(sha1("abcde"))==0x03de6c570bfe24bfc328ccd7ca46b76eadaf4334, + vrfy(sha1(sha1("ab"))==0xda23614e02469a0d7c7bd1bdab5c9c474b1904dc, + '7218: sha1(sha1("ab"))==0xda23614e02469a0d7c7bd1bdab5c9c474b1904dc'); + vrfy(sha1(sha1("abc"))==0xa9993e364706816aba3e25717850c26c9cd0d89d, + '7219: sha1(sha1("abc"))==0xa9993e364706816aba3e25717850c26c9cd0d89d' + ); + vrfy(sha1(sha1("abcd"))==0x81fe8bfe87576c3ecb22426f8e57847382917acf, + '7220: sha1(sha1("abcd"))==0x81fe8bfe87576c3ecb22426f8e57847382917acf'); + vrfy(sha1(sha1("abcde"))==0x03de6c570bfe24bfc328ccd7ca46b76eadaf4334, '7221: sha1(sha1("abcde"))==0x03de6c570bfe24bfc328ccd7ca46b76eadaf4334'); - vrfy(sha1(sha1("abcdef"))== 0x1f8ac10f23c5b5bc1167bda84b833e5c057a77d2, + vrfy(sha1(sha1("abcdef"))== 0x1f8ac10f23c5b5bc1167bda84b833e5c057a77d2, '7222: sha1(sha1("abcdef"))==0x1f8ac10f23c5b5bc1167bda84b833e5c057a77d2'); - vrfy(sha1(sha1("abcdefg"))==0x2fb5e13419fc89246865e7a324f476ec624e8740, + vrfy(sha1(sha1("abcdefg"))==0x2fb5e13419fc89246865e7a324f476ec624e8740, '7223: sha1(sha1("abcdefg"))==0x2fb5e13419fc89246865e7a324f476ec624e8740'); - vrfy(sha1(sha1("abcdefgh"))==0x425af12a0743502b322e93a015bcf868e324d56a, + vrfy(sha1(sha1("abcdefgh"))==0x425af12a0743502b322e93a015bcf868e324d56a, '7224: sha1(sha1("abcdefgh"))==0x425af12a0743502b322e93a015bcf868e324d56a'); - vrfy(sha1(sha1(1))==0x53dd4e1734ad47d45e41c23e4ce42d7f1f98c1e8, - '7225: sha1(sha1(1))==0x53dd4e1734ad47d45e41c23e4ce42d7f1f98c1e8'); - vrfy(sha1(sha1(22/7))==0xf8e2510f85f7b9bf088b321188e9f70620f44246, - '7226: sha1(sha1(22/7))==0xf8e2510f85f7b9bf088b321188e9f70620f44246'); - vrfy(sha1(sha1(isqrt(2e1000)))== - 0x6852a1365c51050c3d039e3c5d9cf29c12283ef4, + vrfy(sha1(sha1(1))==0x53dd4e1734ad47d45e41c23e4ce42d7f1f98c1e8, + '7225: sha1(sha1(1))==0x53dd4e1734ad47d45e41c23e4ce42d7f1f98c1e8'); + vrfy(sha1(sha1(22/7))==0xf8e2510f85f7b9bf088b321188e9f70620f44246, + '7226: sha1(sha1(22/7))==0xf8e2510f85f7b9bf088b321188e9f70620f44246'); + vrfy(sha1(sha1(isqrt(2e1000)))== + 0x6852a1365c51050c3d039e3c5d9cf29c12283ef4, '7227: sha1(sha1(isqrt(2e1000)))==0x6852a1365c51050c3d039e3c5d9cf29c12283ef4' ); - L = list(1,2,3); - print '7228: L = list(1,2,3)'; - mat M[3] = {4,5,6}; - print '7229: mat M[3] = {4,5,6}'; - B = blk() = {7,8,9}; - print '7230: B = blk() = {7,8,9}'; - vrfy(sha1(sha1(L), M, B) == sha1(L, M, B), - '7231: sha1(sha1(L), M, B) == sha1(L, M, B)'); - vrfy(sha1(sha1(L,M), B) == sha1(L, M, B), - '7232: sha1(sha1(L, M), B) == sha1(L, M, B)'); + L = list(1,2,3); + print '7228: L = list(1,2,3)'; + mat M[3] = {4,5,6}; + print '7229: mat M[3] = {4,5,6}'; + B = blk() = {7,8,9}; + print '7230: B = blk() = {7,8,9}'; + vrfy(sha1(sha1(L), M, B) == sha1(L, M, B), + '7231: sha1(sha1(L), M, B) == sha1(L, M, B)'); + vrfy(sha1(sha1(L,M), B) == sha1(L, M, B), + '7232: sha1(sha1(L, M), B) == sha1(L, M, B)'); - print '7233: Ending test_sha1'; + print '7233: Ending test_sha1'; } print '174: parsed test_sha1()'; @@ -7916,199 +7916,199 @@ print '180: define g7500e(a,b) = *a = b' */ define test_ptr() { - local a, b, c, A, B, B1, B2, M, L, p, q, p0, q0; + local a, b, c, A, B, B1, B2, M, L, p, q, p0, q0; - print '7500: Beginning test_ptr'; + print '7500: Beginning test_ptr'; - vrfy(isoctet(27) == 0, '7501: isoctet(27) == 0'); - vrfy(isptr(27) == 0, '7502: isptr(27) == 0'); + vrfy(isoctet(27) == 0, '7501: isoctet(27) == 0'); + vrfy(isptr(27) == 0, '7502: isptr(27) == 0'); - /* testing octet pointers */ + /* testing octet pointers */ - B = blk() = {1,2,3,4,5,6}; - print '7503: B = blk() = {1,2,3,4,5,6};'; - vrfy(isoctet(B[0]) == 1, '7504: isoctet(B[0]) == 1'); - vrfy(isnum(B[0]) == 0, '7505: isnum(B[0]) == 0'); - vrfy(isptr(B[0]) == 0, '7506: isptr(B[0]) == 0'); - vrfy(isoctet(*B[0]) == 0, '7507: isoctet(*B[0]) == 0'); - vrfy(isnum(*B[0]) == 1, '7508: isnum(*B[0]) == 1'); - vrfy(isoctet(&B[0]) == 0, '7509: isoctet(&B[0]) == 0'); - vrfy(isptr(&B[0]) == 1, '7510: isptr(&B[0]) == 1'); - vrfy(*B[3] == B[3], '7511: *B[3]== B[3]'); - vrfy(*&B[3] == B[3], '7512: *&B[3] == B[3]'); - vrfy(&B[0] + 3 == &B[3], '7513: &B[0] + 3 == &B[3]'); - vrfy(&B[3] - &B[0] == 3, '7514: &B[3] - &B[0] == 3'); - vrfy(&B[3] - 3 == &B[0], '7515: &B[3 - 3 == &B[1]'); - vrfy(&B[3] > &B[0], '7516: &B[3] > &B[0]'); - swap(B[0], B[5]); - print '7517: swap(B[0], B[5]);'; - vrfy(B[0] == 6 && B[5] == 1, '7518: B[0] == 6 && B[5] == 1'); + B = blk() = {1,2,3,4,5,6}; + print '7503: B = blk() = {1,2,3,4,5,6};'; + vrfy(isoctet(B[0]) == 1, '7504: isoctet(B[0]) == 1'); + vrfy(isnum(B[0]) == 0, '7505: isnum(B[0]) == 0'); + vrfy(isptr(B[0]) == 0, '7506: isptr(B[0]) == 0'); + vrfy(isoctet(*B[0]) == 0, '7507: isoctet(*B[0]) == 0'); + vrfy(isnum(*B[0]) == 1, '7508: isnum(*B[0]) == 1'); + vrfy(isoctet(&B[0]) == 0, '7509: isoctet(&B[0]) == 0'); + vrfy(isptr(&B[0]) == 1, '7510: isptr(&B[0]) == 1'); + vrfy(*B[3] == B[3], '7511: *B[3]== B[3]'); + vrfy(*&B[3] == B[3], '7512: *&B[3] == B[3]'); + vrfy(&B[0] + 3 == &B[3], '7513: &B[0] + 3 == &B[3]'); + vrfy(&B[3] - &B[0] == 3, '7514: &B[3] - &B[0] == 3'); + vrfy(&B[3] - 3 == &B[0], '7515: &B[3 - 3 == &B[1]'); + vrfy(&B[3] > &B[0], '7516: &B[3] > &B[0]'); + swap(B[0], B[5]); + print '7517: swap(B[0], B[5]);'; + vrfy(B[0] == 6 && B[5] == 1, '7518: B[0] == 6 && B[5] == 1'); - /* testing octet-pointer-valued variables */ + /* testing octet-pointer-valued variables */ - p = &B[0], q = &B[5]; - print '7519: p = &B[0], q = &B[5]'; - vrfy(isoctet(p) == 0, '7520: isoctet(p) == 0'); - vrfy(isptr(p) == 1, '7521: isptr(p) == 1'); - vrfy(isoctet(*p) == 1, '7522: isoctet(*p) == 1'); - vrfy(isptr(*p) == 0, '7523: isptr(*p) == 0'); - vrfy(p == &B[0], '7524: p == &B[0]'); - vrfy(q != p, '7525: q != p'); - vrfy(q > p, '7526: q > p'); - vrfy(*p == B[0], '7527: *p == B[0]'); - vrfy(&B[1] == p + 1, '7528: &B[1] == p + 1'); - vrfy(q == p + 5, '7529: q == p + 5'); - *p = 1, *q = 6; - print '7530: *p = 1, *q = 6'; - vrfy(B[0] == 1 && B[5] == 6, '7531: B[0] == 1 && B[5] == 6'); - a = *p, b = *q; - print '7532: a = *p, b = *q'; - vrfy(a == 1 && b == 6, '7533: a == 1 && b == 6'); - *(p + 3) = 7; - print '7534: *(p + 3) = 7;'; - vrfy(B[3] == 7, '7535: B[3] == 7'); - *(q - 2) = 8; - print '7536: *(q - 2) = 8;'; - vrfy(B[3] == 8, '7537: B[3] == 8'); - p0 = p++; - print '7538: p0 = p++;'; - vrfy(p0 == &B[0] && p == &B[1], '7539: p0 == &B[0] && p == &B[1]'); - q0 = --q; - print '7540: q0 = --q'; - vrfy(q0 == &B[4] && q == q0, '7541: q0 == &B[4] && q == q0'); - a = *p++, b = *q--; - print '7542: a = *p++, b = *q--;'; - vrfy(a == 2 && b == 5, '7543: a == 2 && b == 5'); - vrfy(p - &B[0] == 2 && q == &B[0] + 3, - '7544: p - &B[0] == 2 && q == &B[0] + 3'); - a = *--q, b = *----q; - print '7545: a = *--q, b = *----q;'; - vrfy(q == &B[0], '7546: q == &B[0]'); - vrfy(a == 3 && b == 1, '7547: a == 3 && b == 1'); - a = (*p)++; - print '7548: a = (*p)++;'; - vrfy(a == 3 && B[2] == 4, '7549: a == 3 && B[2] == 4'); - a = ++(*++p)++; - print '7550: a = ++(*++p)++;'; - vrfy(a == 9 && B[3] == 10, '7551: a == 9 && B[3] == 10'); + p = &B[0], q = &B[5]; + print '7519: p = &B[0], q = &B[5]'; + vrfy(isoctet(p) == 0, '7520: isoctet(p) == 0'); + vrfy(isptr(p) == 1, '7521: isptr(p) == 1'); + vrfy(isoctet(*p) == 1, '7522: isoctet(*p) == 1'); + vrfy(isptr(*p) == 0, '7523: isptr(*p) == 0'); + vrfy(p == &B[0], '7524: p == &B[0]'); + vrfy(q != p, '7525: q != p'); + vrfy(q > p, '7526: q > p'); + vrfy(*p == B[0], '7527: *p == B[0]'); + vrfy(&B[1] == p + 1, '7528: &B[1] == p + 1'); + vrfy(q == p + 5, '7529: q == p + 5'); + *p = 1, *q = 6; + print '7530: *p = 1, *q = 6'; + vrfy(B[0] == 1 && B[5] == 6, '7531: B[0] == 1 && B[5] == 6'); + a = *p, b = *q; + print '7532: a = *p, b = *q'; + vrfy(a == 1 && b == 6, '7533: a == 1 && b == 6'); + *(p + 3) = 7; + print '7534: *(p + 3) = 7;'; + vrfy(B[3] == 7, '7535: B[3] == 7'); + *(q - 2) = 8; + print '7536: *(q - 2) = 8;'; + vrfy(B[3] == 8, '7537: B[3] == 8'); + p0 = p++; + print '7538: p0 = p++;'; + vrfy(p0 == &B[0] && p == &B[1], '7539: p0 == &B[0] && p == &B[1]'); + q0 = --q; + print '7540: q0 = --q'; + vrfy(q0 == &B[4] && q == q0, '7541: q0 == &B[4] && q == q0'); + a = *p++, b = *q--; + print '7542: a = *p++, b = *q--;'; + vrfy(a == 2 && b == 5, '7543: a == 2 && b == 5'); + vrfy(p - &B[0] == 2 && q == &B[0] + 3, + '7544: p - &B[0] == 2 && q == &B[0] + 3'); + a = *--q, b = *----q; + print '7545: a = *--q, b = *----q;'; + vrfy(q == &B[0], '7546: q == &B[0]'); + vrfy(a == 3 && b == 1, '7547: a == 3 && b == 1'); + a = (*p)++; + print '7548: a = (*p)++;'; + vrfy(a == 3 && B[2] == 4, '7549: a == 3 && B[2] == 4'); + a = ++(*++p)++; + print '7550: a = ++(*++p)++;'; + vrfy(a == 9 && B[3] == 10, '7551: a == 9 && B[3] == 10'); - /* testing octets, & and * in arguments of user-defined functions */ + /* testing octets, & and * in arguments of user-defined functions */ - A = blk() = {1,2,3}; - print '7552: A = blk() = {1,2,3};'; - vrfy(g7500a(A[0],5) == 5, '7553: g7500a(A[0],5) == 5'); - vrfy(A[0] == 5, '7554: A[0] == 5'); - vrfy(g7500a(`A[0],5) == 5, '7555: g7500a(`A[0],5) == 5'); - vrfy(A[0] == 5, '7556: A[0] == 5'); - vrfy(g7500b(&A[0],3) == &A[3], '7557: g7500b(&A[0],3) == &A[3]'); - vrfy(g7500c(&A[0],2) == 3, '7558: g7500c(&A[0], 2) == 3'); - vrfy(g7500d(`A[0]) == &A[0], '7559: g7500d(`A[0]) == &A[0]'); - p = &A[0]; - print '7560: p = &A[0];'; - vrfy(g7500a(*p, 6) == 6, '7561: g7500a(*p, 6) == 6'); - vrfy(*p == 6, '7562: *p == 6'); - vrfy(g7500a(`*p,6) == 6, '7563: g7500a(`*p,6) == 6'); - vrfy(*p == 6, '7564: *p == 6'); - vrfy(g7500b(p,3) == p + 3, '7565: g7500b(p,3) == p + 3'); - vrfy(g7500c(p,2) == 3, '7566: g7500c(p,2) == 3'); - vrfy(g7500d(`*p) == p, '7567: g7500d(`*p) == p'); - vrfy(g7500e(p,4) == 4, '7568: g7500e(p,4) == 4'); - vrfy(A[0] == 4, '7569: A[0] == 4'); - vrfy(g7500e(p+2,5) == 5, '7570: g7500e(p+2,5) == 5'); - vrfy(A[2] == 5, '7571: A[2] == 5'); + A = blk() = {1,2,3}; + print '7552: A = blk() = {1,2,3};'; + vrfy(g7500a(A[0],5) == 5, '7553: g7500a(A[0],5) == 5'); + vrfy(A[0] == 5, '7554: A[0] == 5'); + vrfy(g7500a(`A[0],5) == 5, '7555: g7500a(`A[0],5) == 5'); + vrfy(A[0] == 5, '7556: A[0] == 5'); + vrfy(g7500b(&A[0],3) == &A[3], '7557: g7500b(&A[0],3) == &A[3]'); + vrfy(g7500c(&A[0],2) == 3, '7558: g7500c(&A[0], 2) == 3'); + vrfy(g7500d(`A[0]) == &A[0], '7559: g7500d(`A[0]) == &A[0]'); + p = &A[0]; + print '7560: p = &A[0];'; + vrfy(g7500a(*p, 6) == 6, '7561: g7500a(*p, 6) == 6'); + vrfy(*p == 6, '7562: *p == 6'); + vrfy(g7500a(`*p,6) == 6, '7563: g7500a(`*p,6) == 6'); + vrfy(*p == 6, '7564: *p == 6'); + vrfy(g7500b(p,3) == p + 3, '7565: g7500b(p,3) == p + 3'); + vrfy(g7500c(p,2) == 3, '7566: g7500c(p,2) == 3'); + vrfy(g7500d(`*p) == p, '7567: g7500d(`*p) == p'); + vrfy(g7500e(p,4) == 4, '7568: g7500e(p,4) == 4'); + vrfy(A[0] == 4, '7569: A[0] == 4'); + vrfy(g7500e(p+2,5) == 5, '7570: g7500e(p+2,5) == 5'); + vrfy(A[2] == 5, '7571: A[2] == 5'); - /* testing pointers to values */ + /* testing pointers to values */ - A = 27, p = &A; - print '7572: A = 27, p = &A;'; - vrfy(isptr(A) == 0, '7573: isptr(A) == 0'); - vrfy(isptr(&A) == 2, '7574: isptr(&A) == 2'); - vrfy(isptr(p) == 2, '7575: isptr(p) == 2'); - vrfy(*p == 27, '7576: *p == 27'); - vrfy(p == &A, '7577: p == &A'); - *p = 45; - print '7578: *p = 45;'; - vrfy(A == 45, '7579: A == 45'); - q = p; - print '7580: q = p;'; - vrfy(q == &A, '7581: q == &A'); - q = &p; - print '7582: q = &p'; - vrfy(*q == p, '7583: *q == p'); - vrfy(**q == A, '7584: **q == A'); - vrfy(***q == A, '7585: ***q == A'); - M = mat[4] = {1,2,3,4}; - print '7586: M = mat[4] = {1,2,3,4};'; - p = &M[0], *p = 5; - print '7587: p = &M[0], *p = 5;'; - vrfy(M[0] == 5, '7588: M[0] == 5'); - *++p = 6; - print '7589: *++p = 6;'; - vrfy(M[1] == 6, '7590: M[1] == 6'); - q = p++; - print '7591: q = p++;'; - vrfy(q == &M[1], '7592: q == &M[1]'); - vrfy(p == &M[2], '7593: p == &M[2]'); - quomod(17,5,*q,*p); - print '7594: quomod(17,5,*p,*q);'; - vrfy(M[1] == 3 && M[2] == 2, '7595: M[1] == 3 && M[2] == 2'); - swap(*p, *q); - print '7596: swap(*p, *q);'; - vrfy(M[1] == 2 && M[2] == 3, '7597: M[1] == 2 && M[2] == 3'); - A = *M = {7,8}; - print '7598: A = *M = {7,8};'; - vrfy(M == (mat[4] = {5,2,3,4}), '7599: M == (mat[4] = {5,2,3,4})'); - vrfy(A == (mat[4] = {7,8,3,4}), '7600: A == (mat[4] = {7,8,3,4})'); + A = 27, p = &A; + print '7572: A = 27, p = &A;'; + vrfy(isptr(A) == 0, '7573: isptr(A) == 0'); + vrfy(isptr(&A) == 2, '7574: isptr(&A) == 2'); + vrfy(isptr(p) == 2, '7575: isptr(p) == 2'); + vrfy(*p == 27, '7576: *p == 27'); + vrfy(p == &A, '7577: p == &A'); + *p = 45; + print '7578: *p = 45;'; + vrfy(A == 45, '7579: A == 45'); + q = p; + print '7580: q = p;'; + vrfy(q == &A, '7581: q == &A'); + q = &p; + print '7582: q = &p'; + vrfy(*q == p, '7583: *q == p'); + vrfy(**q == A, '7584: **q == A'); + vrfy(***q == A, '7585: ***q == A'); + M = mat[4] = {1,2,3,4}; + print '7586: M = mat[4] = {1,2,3,4};'; + p = &M[0], *p = 5; + print '7587: p = &M[0], *p = 5;'; + vrfy(M[0] == 5, '7588: M[0] == 5'); + *++p = 6; + print '7589: *++p = 6;'; + vrfy(M[1] == 6, '7590: M[1] == 6'); + q = p++; + print '7591: q = p++;'; + vrfy(q == &M[1], '7592: q == &M[1]'); + vrfy(p == &M[2], '7593: p == &M[2]'); + quomod(17,5,*q,*p); + print '7594: quomod(17,5,*p,*q);'; + vrfy(M[1] == 3 && M[2] == 2, '7595: M[1] == 3 && M[2] == 2'); + swap(*p, *q); + print '7596: swap(*p, *q);'; + vrfy(M[1] == 2 && M[2] == 3, '7597: M[1] == 2 && M[2] == 3'); + A = *M = {7,8}; + print '7598: A = *M = {7,8};'; + vrfy(M == (mat[4] = {5,2,3,4}), '7599: M == (mat[4] = {5,2,3,4})'); + vrfy(A == (mat[4] = {7,8,3,4}), '7600: A == (mat[4] = {7,8,3,4})'); - /* Values which point to themselves */ + /* Values which point to themselves */ - A = &A; - print '7601: A = &A;'; - vrfy(&A == A && *A == A, '7602: &A == A && *A == A'); - A = &B, B = &A; - print '7603: A = &B, B = &A;'; - vrfy(**A == A && ***A == B, '7604: **A == A && ***A == B'); + A = &A; + print '7601: A = &A;'; + vrfy(&A == A && *A == A, '7602: &A == A && *A == A'); + A = &B, B = &A; + print '7603: A = &B, B = &A;'; + vrfy(**A == A && ***A == B, '7604: **A == A && ***A == B'); - /* Testing functions that return pointers */ + /* Testing functions that return pointers */ - M[3] = 7; - print '7605: M[3] = 7;'; - vrfy(*g7500b(&M[1], 2) == 7, '7606: *g7500b(&M[1], 2) == 7'); + M[3] = 7; + print '7605: M[3] = 7;'; + vrfy(*g7500b(&M[1], 2) == 7, '7606: *g7500b(&M[1], 2) == 7'); - *g7500b(&M[1], 2) = 8; - print '7607: *g7500b(&M[1], 2) = 8;'; - vrfy(M[3] == 8, '7608: M[3] == 8'); - M[3] = list(9,10); - print '7609: M[3] = list(9,10);'; - vrfy((*g7500b(&M[1], 2))[[1]] == 10, - '7610: (*g7500b(&M[1], 2))[[1]] == 10'); + *g7500b(&M[1], 2) = 8; + print '7607: *g7500b(&M[1], 2) = 8;'; + vrfy(M[3] == 8, '7608: M[3] == 8'); + M[3] = list(9,10); + print '7609: M[3] = list(9,10);'; + vrfy((*g7500b(&M[1], 2))[[1]] == 10, + '7610: (*g7500b(&M[1], 2))[[1]] == 10'); - /* Testing number and string pointers */ + /* Testing number and string pointers */ - a = 24, b = 4 * 6, c = 4!; - print '7611: a = 24, b = 4 * 6, c= 4!;'; - vrfy(isptr(&*a) == 4, '7612: isptr(&*a) == 4'); - vrfy(&*a == &24, '7613: &*a == &24'); - vrfy(&*a == &*b, '7614: &*a == &*b'); - vrfy(&*a != &*c, '7615: &*a != &*c'); + a = 24, b = 4 * 6, c = 4!; + print '7611: a = 24, b = 4 * 6, c= 4!;'; + vrfy(isptr(&*a) == 4, '7612: isptr(&*a) == 4'); + vrfy(&*a == &24, '7613: &*a == &24'); + vrfy(&*a == &*b, '7614: &*a == &*b'); + vrfy(&*a != &*c, '7615: &*a != &*c'); - a = b = "abc", c = strcat("a", "bc"); - print '7616: a = b = "abc", c = strcat("a", "bc");'; - vrfy(isptr(&*a) == 3, '7617: isptr(&*a) == 3'); - vrfy(&*a == &"abc", '7618: &*a == &"abc"'); - vrfy(&*a == &*b, '7619: &*a == &*b'); - vrfy(&*a != &*c, '7620: &*a != &*c'); - a = c; - print '7621: a = c;'; - vrfy(&*a == &*c, '7622: &*a == &*c'); + a = b = "abc", c = strcat("a", "bc"); + print '7616: a = b = "abc", c = strcat("a", "bc");'; + vrfy(isptr(&*a) == 3, '7617: isptr(&*a) == 3'); + vrfy(&*a == &"abc", '7618: &*a == &"abc"'); + vrfy(&*a == &*b, '7619: &*a == &*b'); + vrfy(&*a != &*c, '7620: &*a != &*c'); + a = c; + print '7621: a = c;'; + vrfy(&*a == &*c, '7622: &*a == &*c'); - /* Verifying null-ness of freed numbers */ + /* Verifying null-ness of freed numbers */ - c = 4!, p = &*c, free(c); - print '7623: c = 4!, p = &*c, free(c)'; - vrfy(isnull(*p), '7624: isnull(*p)'); + c = 4!, p = &*c, free(c); + print '7623: c = 4!, p = &*c, free(c)'; + vrfy(isnull(*p), '7624: isnull(*p)'); - print '7625: Ending test_ptr'; + print '7625: Ending test_ptr'; } print '181: parsed test_ptr()'; @@ -8120,107 +8120,107 @@ print '181: parsed test_ptr()'; */ define test_newstring() { - local A, B, C, D, S, p, q; + local A, B, C, D, S, p, q; - print '7700: Beginning test_newstring'; + print '7700: Beginning test_newstring'; - A = "abcdef", B = "xyz"; - print '7701: A = "abcdef", B = "xyz";'; - vrfy(A + B == "abcdefxyz", '7702: A + B == "abcdefxyz"'); - vrfy(-A == "fedcba", '7703: -A == "fedcba"'); - vrfy(A - B == "abcdefzyx", '7704: A - B == "abcdefzyx"'); - vrfy(2 * B == "xyzxyz", '7705: 2 * B == "xyzxyz"'); - vrfy(-2 * B == "zyxzyx", '7706: -2 * B == "zyxzyx"'); - vrfy(B * 3 == "xyzxyzxyz", '7707: B * 3 == "xyzxyzxyz"'); - vrfy(2.5 * B == "xyzxyzx", '7708: 2.5 * B == "xyzxyzx"'); - vrfy(0 * B == "", '7709: 0 * B == ""'); - vrfy(3 * "12" == "121212", '7710: 2 * "12" == "121212"'); - vrfy(A/2 == "abc", '7711: A/2 == "abc"'); - vrfy(A | B == "y\173\173def", '7712: A | B == "y\\173\\173def"'); - vrfy(A & B == "``b", '7713: A & B == "``b"'); - vrfy(A \ B == "\1\2\1def", '7714: A \\ B == "\\1\\2\\1def"'); - vrfy(A ~ B == "\31\e\31def", '7715: A ~ B == "\\31\\e\\31def"'); - vrfy(~B == "\207\206\205", '7716: ~B == "\\207\\206\\205"'); - C = "abcdef"; - print '7717: C = "abcdef";'; - vrfy(&*A == &*C, '7718: &*A == &*C'); - D = "abc\0ef"; - print '7719: D = "abc\0ef;"'; - vrfy(size(D) == 6, '7720: size(D) == 6'); - vrfy(strlen(D) == 3, '7721: strlen(D) == 3'); - vrfy(strcat(D,B) == "abcxyz", '7722: strcat(D,B) == "abcxyz"'); + A = "abcdef", B = "xyz"; + print '7701: A = "abcdef", B = "xyz";'; + vrfy(A + B == "abcdefxyz", '7702: A + B == "abcdefxyz"'); + vrfy(-A == "fedcba", '7703: -A == "fedcba"'); + vrfy(A - B == "abcdefzyx", '7704: A - B == "abcdefzyx"'); + vrfy(2 * B == "xyzxyz", '7705: 2 * B == "xyzxyz"'); + vrfy(-2 * B == "zyxzyx", '7706: -2 * B == "zyxzyx"'); + vrfy(B * 3 == "xyzxyzxyz", '7707: B * 3 == "xyzxyzxyz"'); + vrfy(2.5 * B == "xyzxyzx", '7708: 2.5 * B == "xyzxyzx"'); + vrfy(0 * B == "", '7709: 0 * B == ""'); + vrfy(3 * "12" == "121212", '7710: 2 * "12" == "121212"'); + vrfy(A/2 == "abc", '7711: A/2 == "abc"'); + vrfy(A | B == "y\173\173def", '7712: A | B == "y\\173\\173def"'); + vrfy(A & B == "``b", '7713: A & B == "``b"'); + vrfy(A \ B == "\1\2\1def", '7714: A \\ B == "\\1\\2\\1def"'); + vrfy(A ~ B == "\31\e\31def", '7715: A ~ B == "\\31\\e\\31def"'); + vrfy(~B == "\207\206\205", '7716: ~B == "\\207\\206\\205"'); + C = "abcdef"; + print '7717: C = "abcdef";'; + vrfy(&*A == &*C, '7718: &*A == &*C'); + D = "abc\0ef"; + print '7719: D = "abc\0ef;"'; + vrfy(size(D) == 6, '7720: size(D) == 6'); + vrfy(strlen(D) == 3, '7721: strlen(D) == 3'); + vrfy(strcat(D,B) == "abcxyz", '7722: strcat(D,B) == "abcxyz"'); - vrfy(bit(A,0) == 1, '7723: bit(A,0) == 1'); - vrfy(!bit(A,12), '7724: !bit(A,12)'); - vrfy(bit(A,13), '7725: bit(A,13)'); - vrfy(lowbit(A) == 0, '7726: lowbit(A) == 0'); - vrfy(highbit(A) == 46, '7727: highbit(A) == 46'); - vrfy(#A == 21, '7728: #A == 21'); + vrfy(bit(A,0) == 1, '7723: bit(A,0) == 1'); + vrfy(!bit(A,12), '7724: !bit(A,12)'); + vrfy(bit(A,13), '7725: bit(A,13)'); + vrfy(lowbit(A) == 0, '7726: lowbit(A) == 0'); + vrfy(highbit(A) == 46, '7727: highbit(A) == 46'); + vrfy(#A == 21, '7728: #A == 21'); - vrfy(A[2] == "c", '7729: A[2] == "c"'); - vrfy(char(A[2]) == "c", '7730: char(A[2]) == "c"'); - vrfy(A[2] == 99, '7731: A[2] == 99'); - vrfy(ord(A[2]) == 99, '7731: ord(A[2]) == 99'); - vrfy(A[2] == A[0] + 2, '7732: A[2] == A[0] + 2'); - vrfy(3 * A[2] == 297, '7733: 3 * A[2] == 297'); - vrfy(3 * char(A[2]) == "ccc", '7734: 3 * char(A[2]) == "ccc"'); + vrfy(A[2] == "c", '7729: A[2] == "c"'); + vrfy(char(A[2]) == "c", '7730: char(A[2]) == "c"'); + vrfy(A[2] == 99, '7731: A[2] == 99'); + vrfy(ord(A[2]) == 99, '7731: ord(A[2]) == 99'); + vrfy(A[2] == A[0] + 2, '7732: A[2] == A[0] + 2'); + vrfy(3 * A[2] == 297, '7733: 3 * A[2] == 297'); + vrfy(3 * char(A[2]) == "ccc", '7734: 3 * char(A[2]) == "ccc"'); - vrfy(head(A,3) == "abc", '7735: head(A,3) == "abc"'); - vrfy(head(A,-3) == "cba", '7736: head(A,-3) == "cba"'); - vrfy(tail(A,3) == "def", '7737: tail(A,3) == "def"'); - vrfy(tail(A,-3) == "fed", '7738: tail(A,-3) == "fed"'); - vrfy(segment(A,2) == "c", '7739: segment(A,2) == "c"'); - vrfy(segment(A,2,4) == "cde", '7740: segment(A,2,4) == "cde"'); - vrfy(segment(A,4,2) == "edc", '7741: segment(A,4,2) == "edc"'); + vrfy(head(A,3) == "abc", '7735: head(A,3) == "abc"'); + vrfy(head(A,-3) == "cba", '7736: head(A,-3) == "cba"'); + vrfy(tail(A,3) == "def", '7737: tail(A,3) == "def"'); + vrfy(tail(A,-3) == "fed", '7738: tail(A,-3) == "fed"'); + vrfy(segment(A,2) == "c", '7739: segment(A,2) == "c"'); + vrfy(segment(A,2,4) == "cde", '7740: segment(A,2,4) == "cde"'); + vrfy(segment(A,4,2) == "edc", '7741: segment(A,4,2) == "edc"'); - vrfy(search(A, "c") == 2, '7742: search(A, "c") == 2'); - vrfy(search(A, "x") == null(), '7743: search(A, "x") == null()'); - vrfy(search("abbcbc", "bc") == 2, - '7744: search("abbcbc", "bc") == 2'); - vrfy(search("abbcbc", "bc", 2) == 2, - '7745: search("abbcbc", "bc", 2) == 2'); - vrfy(search("abbcbc", "bc", 3) == 4, - '7746: search("abbcbc", "bc", 3) == 4'); - vrfy(search("abbcbc", "bc", -3) == 4, - '7747: search("abbcbc", "bc", -3) == 4'); - vrfy(search("abbcbc", "bc", -4) == 2, - '7748: search("abbcbc", "bc", -4) == 2'); - vrfy(search("abbcbc", "bc", , 3) == null(), - '7749: search("abbcbc", "bc", , 3) == null()'); - vrfy(search("abbcbc", "bc", , 4) == 2, - '7750: search("abbcbc", "bc", , 4) == 2'); + vrfy(search(A, "c") == 2, '7742: search(A, "c") == 2'); + vrfy(search(A, "x") == null(), '7743: search(A, "x") == null()'); + vrfy(search("abbcbc", "bc") == 2, + '7744: search("abbcbc", "bc") == 2'); + vrfy(search("abbcbc", "bc", 2) == 2, + '7745: search("abbcbc", "bc", 2) == 2'); + vrfy(search("abbcbc", "bc", 3) == 4, + '7746: search("abbcbc", "bc", 3) == 4'); + vrfy(search("abbcbc", "bc", -3) == 4, + '7747: search("abbcbc", "bc", -3) == 4'); + vrfy(search("abbcbc", "bc", -4) == 2, + '7748: search("abbcbc", "bc", -4) == 2'); + vrfy(search("abbcbc", "bc", , 3) == null(), + '7749: search("abbcbc", "bc", , 3) == null()'); + vrfy(search("abbcbc", "bc", , 4) == 2, + '7750: search("abbcbc", "bc", , 4) == 2'); - vrfy(rsearch("abbcbc", "bc") == 4, - '7751: rsearch("abbcbc", "bc") == 4'); + vrfy(rsearch("abbcbc", "bc") == 4, + '7751: rsearch("abbcbc", "bc") == 4'); - p = &A[0]; - print '7752: p = &A[0];'; - vrfy(-*p == -97, '7753: -*p == -97'); - vrfy(~*p == char(158), '7754: ~*p == char(158)'); - vrfy(/-#~*p == -1/5, '7755: /-#~*p == -1/5'); + p = &A[0]; + print '7752: p = &A[0];'; + vrfy(-*p == -97, '7753: -*p == -97'); + vrfy(~*p == char(158), '7754: ~*p == char(158)'); + vrfy(/-#~*p == -1/5, '7755: /-#~*p == -1/5'); - A[0] = "A"; - print '7756: A[0] = "A";'; - vrfy(A == "Abcdef", '7757: A == "Abcdef"'); - A[1] = 173; - print '7758: A[1] = 173;'; - vrfy(A == "A\255cdef", '7759: A == "A\\255cdef"'); - setbit(A, 18); - print '7760: setbit(A,10);'; - vrfy(A == "A\255gdef", '7761: A == "A\\255gdef"'); - setbit(A, 16, 0); - print '7762: setbit(A, 16, 0);'; + A[0] = "A"; + print '7756: A[0] = "A";'; + vrfy(A == "Abcdef", '7757: A == "Abcdef"'); + A[1] = 173; + print '7758: A[1] = 173;'; + vrfy(A == "A\255cdef", '7759: A == "A\\255cdef"'); + setbit(A, 18); + print '7760: setbit(A,10);'; + vrfy(A == "A\255gdef", '7761: A == "A\\255gdef"'); + setbit(A, 16, 0); + print '7762: setbit(A, 16, 0);'; /* NOTE: We skip non-ASCII to avoid problems with old awk that cannot handle them */ -/* vrfy(A == "A\255fdef", '7763: A == "A\255fdef"'); */ +/* vrfy(A == "A\255fdef", '7763: A == "A\255fdef"'); */ - q = "curds" " and " "whey"; - print '7764: q = "curds" " and " "whey"'; - vrfy(q == "curds and whey", '7765: q == "curds and whey"'); - q = "chongo" ' was ' "here"; - print '7766: q = "chongo" \' was \' "here"'; - vrfy(q == "chongo was here", '7767: q == "chongo was here"'); + q = "curds" " and " "whey"; + print '7764: q = "curds" " and " "whey"'; + vrfy(q == "curds and whey", '7765: q == "curds and whey"'); + q = "chongo" ' was ' "here"; + print '7766: q = "chongo" \' was \' "here"'; + vrfy(q == "chongo was here", '7767: q == "chongo was here"'); - print '7768: Ending test_newstring'; + print '7768: Ending test_newstring'; } print '182: parsed test_newstring()'; @@ -8233,22 +8233,22 @@ print '182: parsed test_newstring()'; */ define test_newcomb() { - print '7800: Beginning test_newcomb'; + print '7800: Beginning test_newcomb'; - vrfy(comb(2, 5) == 0, '7801: comb(2, 5) == 0'); - vrfy(comb(2, -2) == 0, '7802: comb(2, -2) == 0'); - vrfy(comb(1/2, 4) == -5/128, '7803: comb(1/2, 4) == -5/128'); - vrfy(comb(1/2, 5) == 7/256, '7804: comb(1/2, 5) == 7/256'); + vrfy(comb(2, 5) == 0, '7801: comb(2, 5) == 0'); + vrfy(comb(2, -2) == 0, '7802: comb(2, -2) == 0'); + vrfy(comb(1/2, 4) == -5/128, '7803: comb(1/2, 4) == -5/128'); + vrfy(comb(1/2, 5) == 7/256, '7804: comb(1/2, 5) == 7/256'); - vrfy(perm(2, -1) == 1/3, '7805: perm(2, -1) == 1/3'); - vrfy(perm(2, -2) == 1/12, '7806: perm(2, -2) == 1/12'); - vrfy(perm(2, -3) == 1/60, '7807: perm(2, -3) == 1/60'); - vrfy(perm(1/2, 4) == -15/16, '7808: perm(1/2, 4) == -15/16'); - vrfy(perm(1/2, 5) == 105/32, '7809: perm(1/2, 5) == 105/32'); - vrfy(perm(1/2,-1) == 2/3, '7810: perm(1/2, -1) == 2/3'); - vrfy(perm(1/2,-2) == 4/15, '7811: perm(1/2, -2) == 4/15'); + vrfy(perm(2, -1) == 1/3, '7805: perm(2, -1) == 1/3'); + vrfy(perm(2, -2) == 1/12, '7806: perm(2, -2) == 1/12'); + vrfy(perm(2, -3) == 1/60, '7807: perm(2, -3) == 1/60'); + vrfy(perm(1/2, 4) == -15/16, '7808: perm(1/2, 4) == -15/16'); + vrfy(perm(1/2, 5) == 105/32, '7809: perm(1/2, 5) == 105/32'); + vrfy(perm(1/2,-1) == 2/3, '7810: perm(1/2, -1) == 2/3'); + vrfy(perm(1/2,-2) == 4/15, '7811: perm(1/2, -2) == 4/15'); - print '7812: Ending test_newcomb'; + print '7812: Ending test_newcomb'; } print '183: parsed test_newcomb()'; @@ -8261,13 +8261,13 @@ print '183: parsed test_newcomb()'; */ define f7900(a,b,n) { - local s, x; + local s, x; - if (a > b) - return -f7900(b, a, n); - for (s = 0, x = a; x < b; x++) - s += perm(x, n); - return s; + if (a > b) + return -f7900(b, a, n); + for (s = 0, x = a; x < b; x++) + s += perm(x, n); + return s; } print '184: parsed f7900()'; /**/ @@ -8282,32 +8282,32 @@ print '185: define g7900(a,b,n) = ...'; */ define test_bigcomb() { - local a, b, n, i, v1, v2; + local a, b, n, i, v1, v2; - print '7900: Starting test_bigcomb'; - a = 1234/4321; - print '7901: a = 1234/4321'; - b = 3456/6543; - print '7902: b = 3456/6543'; - n = 47; - print '7903: n = 47'; - v1 = perm(a + b, n); - print '7904: v1 = perm(a + b, n)'; - v2 = 0; - print '7905: v2 = 0'; - for (i = 0; i <= n; i++) - v2 += comb(n, i) * perm(a, i) * perm(b, n - i); - print '7906: for (i=0;i<=n;i++) v2 += comb(n,i)*perm(a,i)*perm(b,n-i)'; - vrfy(v1 == v2, '7910: v1 == v2'); + print '7900: Starting test_bigcomb'; + a = 1234/4321; + print '7901: a = 1234/4321'; + b = 3456/6543; + print '7902: b = 3456/6543'; + n = 47; + print '7903: n = 47'; + v1 = perm(a + b, n); + print '7904: v1 = perm(a + b, n)'; + v2 = 0; + print '7905: v2 = 0'; + for (i = 0; i <= n; i++) + v2 += comb(n, i) * perm(a, i) * perm(b, n - i); + print '7906: for (i=0;i<=n;i++) v2 += comb(n,i)*perm(a,i)*perm(b,n-i)'; + vrfy(v1 == v2, '7910: v1 == v2'); - vrfy(f7900(-10,10,5) == g7900(-10,10,5), - '7911: f7900(-10,10,5) == g7900(10,10,5)'); - vrfy(f7900(5,15,-4) == g7900(5,15,-4), - '7912: f7900(5,15,-4) == g7900(5,15,-4)'); - vrfy(f7900(-7/4,33/4,-2) == g7900(-7/4,33/4,-2), - '7913: f7900(-7/4,33/4,-2) == g7900(-7/4,33/4,-2)'); + vrfy(f7900(-10,10,5) == g7900(-10,10,5), + '7911: f7900(-10,10,5) == g7900(10,10,5)'); + vrfy(f7900(5,15,-4) == g7900(5,15,-4), + '7912: f7900(5,15,-4) == g7900(5,15,-4)'); + vrfy(f7900(-7/4,33/4,-2) == g7900(-7/4,33/4,-2), + '7913: f7900(-7/4,33/4,-2) == g7900(-7/4,33/4,-2)'); - print '7914: Ending test_bigcomb'; + print '7914: Ending test_bigcomb'; } print '186: parsed test_bigcomb()'; @@ -8322,66 +8322,66 @@ print '187: read -once natnumset;'; /**/ define test_natnumset() { - local A, B, C, D, P, P1, L1, L2; + local A, B, C, D, P, P1, L1, L2; - print '8100: Starting test_natnumset'; + print '8100: Starting test_natnumset'; - A = set(17, 2, 0, 24, 2); - print '8101: A = set(17, 2, 0, 24, 2);'; - B = set(41, 17, 11, 2, 19, 17); - print '8102: B = set(41, 17, 11, 2, 19, 17);'; - vrfy(A | B == set(0,2,11,17,19,24,41), - '8103: A | B == set(0,2,11,17,19,24,41)'); - vrfy(A & B == set(2,17), '8104: A & B == set(2,17)'); - vrfy(A \ B == set(0,24), '8105: A \\ B == set(0, 24)'); - vrfy(B \ A == set(11,19,41), '8106: B \\ A == set(11,19,41)'); - vrfy(A ~ B == set(0,11,19,24,41), - '8107: A ~ B == set(0,11,19,24,41)'); - vrfy(#A == 4, '8108: #A == 4'); - vrfy(#~A == 97, '8109: #~A == 97'); - vrfy(A + 5 == set(5,7,22,29), '8110: A + 5 == set(5,7,22,29)'); - vrfy(A - 5 == set(12,19), '8111: A - 5 == set(12,19)'); - vrfy(30 - A == set(6,13,28,30), '8112: 30 - A == set(6,13,28,30)'); - vrfy(2 * A == set(0,4,34,48), '8113: 2 * A == set(0,4,34,48)'); - vrfy(10 * A == set(0,20), '8114: 10 * A == set(0,20)'); - vrfy(A + A == set(0,2,4,17,19,24,26,34,41,48), - '8115: A + A == set(0,2,4,17,19,24,26,34,41,48)'); - vrfy(A - A == set(0,2,7,15,17,22,24), - '8116: A - A == set(0,2,7,15,17,22,24)'); - vrfy(set(2,3,5,7)^2 == set(4,9,25,49), - '8117: set(2,3,5,7)^2 == set(4,9,25,49)'); - vrfy(interval(8,12) == set(8,9,10,11,12), - '8118: interval(8,12) == set(8,9,10,11,12)'); - vrfy(min(A) == 0, '8119: min(A) == 0'); - vrfy(max(A) == 24, '8120: max(A) == 24'); - P = primes(); - print '8121: P = primes();'; - vrfy(#P == 25, '8122: #P == 25'); - vrfy(+P == 1060, '8123: +P == 1060'); - vrfy(isin(P,31), '8124: isin(P,31)'); - vrfy(!isin(P,51), '8125: !isin(P,51)'); - P1 = primes(20,40); - print '8126: P1 = primes(20,40)'; - vrfy(P1 == set(23,29,31,37), '8127: P1 == set(23,29,31,37)'); - vrfy(P1 < P, '8128: P1 < P'); - vrfy(P1 & (set(3) % 4) == set(23,31), - '8129: P1 & (set(3) % 4) == set(23,31)'); + A = set(17, 2, 0, 24, 2); + print '8101: A = set(17, 2, 0, 24, 2);'; + B = set(41, 17, 11, 2, 19, 17); + print '8102: B = set(41, 17, 11, 2, 19, 17);'; + vrfy(A | B == set(0,2,11,17,19,24,41), + '8103: A | B == set(0,2,11,17,19,24,41)'); + vrfy(A & B == set(2,17), '8104: A & B == set(2,17)'); + vrfy(A \ B == set(0,24), '8105: A \\ B == set(0, 24)'); + vrfy(B \ A == set(11,19,41), '8106: B \\ A == set(11,19,41)'); + vrfy(A ~ B == set(0,11,19,24,41), + '8107: A ~ B == set(0,11,19,24,41)'); + vrfy(#A == 4, '8108: #A == 4'); + vrfy(#~A == 97, '8109: #~A == 97'); + vrfy(A + 5 == set(5,7,22,29), '8110: A + 5 == set(5,7,22,29)'); + vrfy(A - 5 == set(12,19), '8111: A - 5 == set(12,19)'); + vrfy(30 - A == set(6,13,28,30), '8112: 30 - A == set(6,13,28,30)'); + vrfy(2 * A == set(0,4,34,48), '8113: 2 * A == set(0,4,34,48)'); + vrfy(10 * A == set(0,20), '8114: 10 * A == set(0,20)'); + vrfy(A + A == set(0,2,4,17,19,24,26,34,41,48), + '8115: A + A == set(0,2,4,17,19,24,26,34,41,48)'); + vrfy(A - A == set(0,2,7,15,17,22,24), + '8116: A - A == set(0,2,7,15,17,22,24)'); + vrfy(set(2,3,5,7)^2 == set(4,9,25,49), + '8117: set(2,3,5,7)^2 == set(4,9,25,49)'); + vrfy(interval(8,12) == set(8,9,10,11,12), + '8118: interval(8,12) == set(8,9,10,11,12)'); + vrfy(min(A) == 0, '8119: min(A) == 0'); + vrfy(max(A) == 24, '8120: max(A) == 24'); + P = primes(); + print '8121: P = primes();'; + vrfy(#P == 25, '8122: #P == 25'); + vrfy(+P == 1060, '8123: +P == 1060'); + vrfy(isin(P,31), '8124: isin(P,31)'); + vrfy(!isin(P,51), '8125: !isin(P,51)'); + P1 = primes(20,40); + print '8126: P1 = primes(20,40)'; + vrfy(P1 == set(23,29,31,37), '8127: P1 == set(23,29,31,37)'); + vrfy(P1 < P, '8128: P1 < P'); + vrfy(P1 & (set(3) % 4) == set(23,31), + '8129: P1 & (set(3) % 4) == set(23,31)'); - L1 = list(3,2,1); - print '8130: L1 = list(3,2,1);'; - C = set(2,3,5,7); - print '8131: C = set(2,3,5,7);'; - vrfy(polyvals(L1, C) == set(11,18,38,66), - '8132: polyvals(L1, C) == set(11,18,38,66)'); - L2 = list(0,list(0,1),1); - print '8133: L2 = list(0,list(0,1),1);'; - D = set(4,6); - print '8134: D = set(4,6);'; + L1 = list(3,2,1); + print '8130: L1 = list(3,2,1);'; + C = set(2,3,5,7); + print '8131: C = set(2,3,5,7);'; + vrfy(polyvals(L1, C) == set(11,18,38,66), + '8132: polyvals(L1, C) == set(11,18,38,66)'); + L2 = list(0,list(0,1),1); + print '8133: L2 = list(0,list(0,1),1);'; + D = set(4,6); + print '8134: D = set(4,6);'; - vrfy(polyvals2(L2,C,D) == set(12,16,21,27,45,55,77,91), - '8135: polyvals(L2,C,D) == set(12,16,21,27,45,55,77,91)'); + vrfy(polyvals2(L2,C,D) == set(12,16,21,27,45,55,77,91), + '8135: polyvals(L2,C,D) == set(12,16,21,27,45,55,77,91)'); - print '8136: Ending test_natnumset'; + print '8136: Ending test_natnumset'; } print '188: parsed test_natnumset()'; @@ -8395,48 +8395,48 @@ define func8200(x,y) {if (x>0) return calclevel()+func8200(x-1,y)-y; return 0;} print '189: define func8200(x,y)'; define test_somenew() { - local a, s, y; + local a, s, y; - print '8200: Starting test_somenew'; + print '8200: Starting test_somenew'; - vrfy(char(-1) == char(255), '8201: char(-1) == char(255)'); - vrfy(char(258) == char(2), '8202: char(258) == char(2)'); + vrfy(char(-1) == char(255), '8201: char(-1) == char(255)'); + vrfy(char(258) == char(2), '8202: char(258) == char(2)'); - vrfy(size(char(0)) == 1, '8203: size(char(0)) == 1'); - vrfy(strlen(char(0)) == 0, '8204: strlen(char(0)) == 0'); - vrfy(char(0) != "", '8205: char(0) != ""'); - vrfy(str(char(0)) == "", '8206: str(char(0)) == ""'); + vrfy(size(char(0)) == 1, '8203: size(char(0)) == 1'); + vrfy(strlen(char(0)) == 0, '8204: strlen(char(0)) == 0'); + vrfy(char(0) != "", '8205: char(0) != ""'); + vrfy(str(char(0)) == "", '8206: str(char(0)) == ""'); - vrfy(str("abc") == "abc", '8207: str("abc") == "abc"'); + vrfy(str("abc") == "abc", '8207: str("abc") == "abc"'); - vrfy(2^-3^2 == 1/512, '8208: 2^-3^2 == 1/512'); - vrfy(/2 == .5, '8209: /2 == .5'); - vrfy(/-2 == -.5, '8210: /-2 == -.5'); - vrfy(1+/2 == 1.5, '8211: 1+/2 == 1.5'); + vrfy(2^-3^2 == 1/512, '8208: 2^-3^2 == 1/512'); + vrfy(/2 == .5, '8209: /2 == .5'); + vrfy(/-2 == -.5, '8210: /-2 == -.5'); + vrfy(1+/2 == 1.5, '8211: 1+/2 == 1.5'); - ecnt += 6; - print '8212: ecnt += 6'; - vrfy(0^-2 == 1/0, '8213: 0^-2 == 1/0'); - vrfy(inverse(0) == 1/0, '8214: inverse(0) == 1/0'); - vrfy(1/(1/0) == 0, '8215: 1/(1/0) == 0'); - vrfy(inverse(1/0) == 0, '8216: inverse(1/0) == 0'); + ecnt += 6; + print '8212: ecnt += 6'; + vrfy(0^-2 == 1/0, '8213: 0^-2 == 1/0'); + vrfy(inverse(0) == 1/0, '8214: inverse(0) == 1/0'); + vrfy(1/(1/0) == 0, '8215: 1/(1/0) == 0'); + vrfy(inverse(1/0) == 0, '8216: inverse(1/0) == 0'); - a = isqrt(2e1000); s = "xyz"; - print '8217: a = isqrt(2e1000); s = "xyz";'; - vrfy(hash(a,s) == 2708885378, '8218: hash(a,s) == 2708885378'); - vrfy(hash("curds n whey") == 2376141927, - '8219: hash("curds n whey") == 2376141927'); + a = isqrt(2e1000); s = "xyz"; + print '8217: a = isqrt(2e1000); s = "xyz";'; + vrfy(hash(a,s) == 2708885378, '8218: hash(a,s) == 2708885378'); + vrfy(hash("curds n whey") == 2376141927, + '8219: hash("curds n whey") == 2376141927'); - y = calclevel(); - print '8220: y = calclevel()'; - vrfy(func8200(0,y) == 0, '8221: func8200(0,y) == 0'); - vrfy(func8200(1,y) == 1, '8222: func8200(1,y) == 1'); - vrfy(func8200(10,y) == 55, '8223: func8200(10,y) == 55'); - vrfy(func8200(100,y) == 5050, '8224: func8200(100,y) == 5050'); + y = calclevel(); + print '8220: y = calclevel()'; + vrfy(func8200(0,y) == 0, '8221: func8200(0,y) == 0'); + vrfy(func8200(1,y) == 1, '8222: func8200(1,y) == 1'); + vrfy(func8200(10,y) == 55, '8223: func8200(10,y) == 55'); + vrfy(func8200(100,y) == 5050, '8224: func8200(100,y) == 5050'); - vrfy(inputlevel() == 1, '8225: inputlevel() == 1'); + vrfy(inputlevel() == 1, '8225: inputlevel() == 1'); - print '8226: Ending test_somenew'; + print '8226: Ending test_somenew'; } print '190: parsed test_somenew()'; @@ -8448,76 +8448,76 @@ print '190: parsed test_somenew()'; */ define test_exponentiation() { - local a; + local a; - print '8800: Starting test_exponentiation'; + print '8800: Starting test_exponentiation'; - /* unexpected help file cases */ - vrfy(2^3 == 8, '8801: 2^3 == 8'); - vrfy(2.5 ^ 3.5 == power(2.5, 3.5), - '8802: 2.5 ^ 3.5 == power(2.5, 3.5)'); - vrfy(2.5 ^ 2.718i == power(2.5, 2.718i), - '8803: 2.5 ^ 2.718i == power(2.5, 2.718i)'); - vrfy(3i^4 == 81, '8804: 3i^4 == 81'); - vrfy(0.5i ^ 0.25 == power(0.5i, 0.25), - '8804: 0.5i ^ 0.25 == power(0.5i, 0.25)'); - vrfy(3.13145i^0.30103i == power(3.13145i, 0.30103i), - '8806: 3.13145i^0.30103i == power(3.13145i, 0.30103i)'); + /* unexpected help file cases */ + vrfy(2^3 == 8, '8801: 2^3 == 8'); + vrfy(2.5 ^ 3.5 == power(2.5, 3.5), + '8802: 2.5 ^ 3.5 == power(2.5, 3.5)'); + vrfy(2.5 ^ 2.718i == power(2.5, 2.718i), + '8803: 2.5 ^ 2.718i == power(2.5, 2.718i)'); + vrfy(3i^4 == 81, '8804: 3i^4 == 81'); + vrfy(0.5i ^ 0.25 == power(0.5i, 0.25), + '8804: 0.5i ^ 0.25 == power(0.5i, 0.25)'); + vrfy(3.13145i^0.30103i == power(3.13145i, 0.30103i), + '8806: 3.13145i^0.30103i == power(3.13145i, 0.30103i)'); - /* deal with some corner error cases */ - ecnt += 12; - print '8807: ecnt += 2'; - vrfy((1/0) ^ -1 == 0, '8808: (1/0) ^ -1 == 0'); - vrfy((1/0) ^ -2 == 0, '8809: (1/0) ^ -2 == 0'); - vrfy((1/0) ^ 0 == error("E_DIVBYZERO"), '8810: (1/0) ^ 0 == error("E_DIVBYZERO")'); - vrfy((1/0) ^ 3 == error("E_DIVBYZERO"), '8811: (1/0) ^ 3 == error("E_DIVBYZERO")'); - vrfy(0 ^ -2 == error("E_DIVBYZERO"), '8812: 0 ^ -2 == error("E_DIVBYZERO")'); - vrfy((1/0) ^ 1i == error("E_DIVBYZERO"),'8813: (1/0) ^ 1i == error("E_DIVBYZERO")'); - vrfy((1/0) ^ 0i == error("E_DIVBYZERO"),'8814: (1/0) ^ 0i == error("E_DIVBYZERO")'); + /* deal with some corner error cases */ + ecnt += 12; + print '8807: ecnt += 2'; + vrfy((1/0) ^ -1 == 0, '8808: (1/0) ^ -1 == 0'); + vrfy((1/0) ^ -2 == 0, '8809: (1/0) ^ -2 == 0'); + vrfy((1/0) ^ 0 == error("E_DIVBYZERO"), '8810: (1/0) ^ 0 == error("E_DIVBYZERO")'); + vrfy((1/0) ^ 3 == error("E_DIVBYZERO"), '8811: (1/0) ^ 3 == error("E_DIVBYZERO")'); + vrfy(0 ^ -2 == error("E_DIVBYZERO"), '8812: 0 ^ -2 == error("E_DIVBYZERO")'); + vrfy((1/0) ^ 1i == error("E_DIVBYZERO"),'8813: (1/0) ^ 1i == error("E_DIVBYZERO")'); + vrfy((1/0) ^ 0i == error("E_DIVBYZERO"),'8814: (1/0) ^ 0i == error("E_DIVBYZERO")'); - /* real ^ real */ - vrfy(5^6 == 15625, '8815: 5^6 == 15625'); - vrfy(10^31 == 1e31, '8816: 10^31 == 1e31'); - vrfy(10 ^ (127/31) == power(10, 127/31), - '8817: 10 ^ (127/31) == power(10, 127/31)'); - vrfy((10^31) ^ 10 == 1e310, '8818: (10^31) ^ 10 == 1e310'); + /* real ^ real */ + vrfy(5^6 == 15625, '8815: 5^6 == 15625'); + vrfy(10^31 == 1e31, '8816: 10^31 == 1e31'); + vrfy(10 ^ (127/31) == power(10, 127/31), + '8817: 10 ^ (127/31) == power(10, 127/31)'); + vrfy((10^31) ^ 10 == 1e310, '8818: (10^31) ^ 10 == 1e310'); - /* complex ^ real */ - vrfy(10i ^ 10 == -1e10, '8819: 10i ^ 10 == -1e10'); - vrfy((-10i) ^ 10 == -1e10, '8820: (-10i) ^ 10 == -1e10'); - vrfy((1+1i) ^ 4 == -4, '8821: (1+1i) ^ 4 == -4'); - vrfy((1+1i) ^ 65536 == 2^32768, '8822: (1+1i) ^ 65536 == 2^32768'); - vrfy((1+1i) ^ (2^20) == 2^(2^19), - '8823: (1+1i) ^ (2^20) == 2^(2^19)'); - vrfy((31+17i) ^ pi() == power(31+17i, pi()), - '8824: (31+17i) ^ pi() == power(31+17i, pi()'); - vrfy((5+7i) ^ exp(5) == power(5+7i, exp(5)), - '8825: (5+7i) ^ exp(5) == power(5+7i, exp(5))'); + /* complex ^ real */ + vrfy(10i ^ 10 == -1e10, '8819: 10i ^ 10 == -1e10'); + vrfy((-10i) ^ 10 == -1e10, '8820: (-10i) ^ 10 == -1e10'); + vrfy((1+1i) ^ 4 == -4, '8821: (1+1i) ^ 4 == -4'); + vrfy((1+1i) ^ 65536 == 2^32768, '8822: (1+1i) ^ 65536 == 2^32768'); + vrfy((1+1i) ^ (2^20) == 2^(2^19), + '8823: (1+1i) ^ (2^20) == 2^(2^19)'); + vrfy((31+17i) ^ pi() == power(31+17i, pi()), + '8824: (31+17i) ^ pi() == power(31+17i, pi()'); + vrfy((5+7i) ^ exp(5) == power(5+7i, exp(5)), + '8825: (5+7i) ^ exp(5) == power(5+7i, exp(5))'); - /* real ^ complex */ - vrfy(10 ^ 1i == power(10, 1i), '8826: 10 ^ 1i == power(10, 1i)'); - vrfy(10 ^ (2+3i) == power(10, 2+3i), - '8827: 10 ^ (2+3i) == power(10, 2+3i)'); - vrfy(pi() ^ (2+3i) == power(pi(), 2+3i), - '8828: pi() ^ (2+3i) == power(pi(), 2+3i)'); - vrfy(exp(64) ^ (2+3i) == power(exp(64), 2+3i), - '8828: exp(64) ^ (2+3i) == power(exp(64), 2+3i)'); - vrfy(pi() ^ (257+127i) == power(pi(), 257+127i), - '8829: pi() ^ (257+127i) == power(pi(), 257+127i)'); - vrfy(pi() ^ asin(-2) == power(pi(), asin(-2)), - '8830: pi() ^ asin(-2) == power(pi(), asin(-2)'); + /* real ^ complex */ + vrfy(10 ^ 1i == power(10, 1i), '8826: 10 ^ 1i == power(10, 1i)'); + vrfy(10 ^ (2+3i) == power(10, 2+3i), + '8827: 10 ^ (2+3i) == power(10, 2+3i)'); + vrfy(pi() ^ (2+3i) == power(pi(), 2+3i), + '8828: pi() ^ (2+3i) == power(pi(), 2+3i)'); + vrfy(exp(64) ^ (2+3i) == power(exp(64), 2+3i), + '8828: exp(64) ^ (2+3i) == power(exp(64), 2+3i)'); + vrfy(pi() ^ (257+127i) == power(pi(), 257+127i), + '8829: pi() ^ (257+127i) == power(pi(), 257+127i)'); + vrfy(pi() ^ asin(-2) == power(pi(), asin(-2)), + '8830: pi() ^ asin(-2) == power(pi(), asin(-2)'); - /* complex ^ complex */ - vrfy((3+4i) ^ (2+3i) == power(3+4i, 2+3i), - '8831: (3+4i) ^ (2+3i) == power(3+4i, 2+3i)'); - vrfy(ln(-10) ^ (2+3i) == power(ln(-10), 2+3i), - '8832: ln(-10) ^ (2+3i) == power(ln(-10), 2+3i)'); - vrfy((pi()*1i) ^ asin(-2) == power(pi()*1i, asin(-2)), - '8833: (pi()*1i) ^ asin(-2) == power(pi()*1i, asin(-2))'); - vrfy((exp(1)+pi()*1i) ^ asin(-2) == power(exp(1)+pi()*1i, asin(-2)), - '8834: (exp(1)+pi()*1i) ^ asin(-2) == power(exp(1)+pi()*1i, asin(-2))'); + /* complex ^ complex */ + vrfy((3+4i) ^ (2+3i) == power(3+4i, 2+3i), + '8831: (3+4i) ^ (2+3i) == power(3+4i, 2+3i)'); + vrfy(ln(-10) ^ (2+3i) == power(ln(-10), 2+3i), + '8832: ln(-10) ^ (2+3i) == power(ln(-10), 2+3i)'); + vrfy((pi()*1i) ^ asin(-2) == power(pi()*1i, asin(-2)), + '8833: (pi()*1i) ^ asin(-2) == power(pi()*1i, asin(-2))'); + vrfy((exp(1)+pi()*1i) ^ asin(-2) == power(exp(1)+pi()*1i, asin(-2)), + '8834: (exp(1)+pi()*1i) ^ asin(-2) == power(exp(1)+pi()*1i, asin(-2))'); - print '8835: Ending test_exponentiation'; + print '8835: Ending test_exponentiation'; } print '191: parsed test_exponentiation()'; @@ -8529,15 +8529,15 @@ print '191: parsed test_exponentiation()'; */ define test_quit() { - local x8400 = 23209; /* watch for lost memory */ - static s8400 = 21701; /* watch for lost memory */ + local x8400 = 23209; /* watch for lost memory */ + static s8400 = 21701; /* watch for lost memory */ - print '8400: Starting test_quit'; + print '8400: Starting test_quit'; - quit; - prob('quit did not end the test_quit() function'); + quit; + prob('quit did not end the test_quit() function'); - /* 8400 series continued after return, do not print end here */ + /* 8400 series continued after return, do not print end here */ } print '192: parsed test_quit()'; @@ -8848,7 +8848,7 @@ return test_random(); */ print; return test_newsyn(); -vrfy(s5500 == 78, '5548: s5500 == 78'); +vrfy(s5500 == 78, '5548: s5500 == 78'); /* @@ -8881,19 +8881,19 @@ print '5852: define xy5800_assign(a, b) = a.y = b'; X5800 = 9; print '5853: X5800 = 9'; vrfy(X5800 == (obj xy5800 = {3,9}), - '5854: X5800 == (obj xy5800 = {3,9})'); + '5854: X5800 == (obj xy5800 = {3,9})'); asserr = newerror("Incompatible types for ="); print '5855: asserr = newerror("Incompatible types for =")'; define xy5800_assign(a, b) { - if (istype(b, obj xy5800)) { - a.x = b.x; - a.y = b.y; - } else if (isreal(b)) { - a.x = b; - a.y = 0; - } else { - error(asserr); - } + if (istype(b, obj xy5800)) { + a.x = b.x; + a.y = b.y; + } else if (isreal(b)) { + a.x = b; + a.y = 0; + } else { + error(asserr); + } } print '5856: xy5800_assign(a, b) { ... };'; ecnt += 2; @@ -8901,20 +8901,20 @@ print '5857: ecnt += 2'; X5800 = 2 + 3i; print '5858: X5800 = 2 + 3i'; vrfy(X5800 == (obj xy5800 = {3,9}), - '5859: X5800 == (obj xy5800 = {3,9})'); -vrfy(errno() > 0, '5860: errno() > 0'); + '5859: X5800 == (obj xy5800 = {3,9})'); +vrfy(errno() > 0, '5860: errno() > 0'); vrfy(strerror() == "Incompatible types for =", - '5861: strerror() == "Incompatible types for ="'); + '5861: strerror() == "Incompatible types for ="'); X5800 = 2; -print '5862: X5800 = 2'; +print '5862: X5800 = 2'; vrfy(X5800 == (obj xy5800 = {2,0}), - '5863: X5800 == (obj xy5800 = {2,0})'); + '5863: X5800 == (obj xy5800 = {2,0})'); X5800 = obj xy5800 = {1,2}; -print '5864: X5800 = obj xy5800 = {1,2}'; +print '5864: X5800 = obj xy5800 = {1,2}'; vrfy(X5800 == (obj xy5800 = {1,2}), - '5865: X5800 == (obj xy5800 = {1,2})'); + '5865: X5800 == (obj xy5800 = {1,2})'); define f5800(a5800 = mat[2] = {3,4}) = 5 * a5800; -print '5866: define f5800(a5800 = mat[2] = {3,4}) = 5 * a5800;' +print '5866: define f5800(a5800 = mat[2] = {3,4}) = 5 * a5800;' vrfy(f5800() == (mat[] = {15,20}),'5867: f5800() == (mat[] = {15,20})'); print '5868: End of 5800 sequence'; @@ -8976,38 +8976,38 @@ return test_sha1(); */ print; print '7400: Beginning test_savedot'; -print '7401: saveval(1);'; +print '7401: saveval(1);'; saveval(1); -print '7402: a7400 = 2;'; +print '7402: a7400 = 2;'; a7400 = 2; -vrfy(. == 2, '7403: . == 2;'); -vrfy((. += 3, . == 5), '7404: (. += 3, . == 5)'); -vrfy(. == 5, '7405: . == 5;'); -print '7406: a7400 = 5; b7400 = 6;'; +vrfy(. == 2, '7403: . == 2;'); +vrfy((. += 3, . == 5), '7404: (. += 3, . == 5)'); +vrfy(. == 5, '7405: . == 5;'); +print '7406: a7400 = 5; b7400 = 6;'; a7400 = 5; b7400 = 6; -vrfy(. == 6, '7407: . == 6'); -print '7408: a7400 = 7; b7400 = 8; null()'; +vrfy(. == 6, '7407: . == 6'); +print '7408: a7400 = 7; b7400 = 8; null()'; a7400 = 7; b7400 = 8; null(); -vrfy(. == 6, '7409: . == 6'); -print '7410: saveval(0);'; +vrfy(. == 6, '7409: . == 6'); +print '7410: saveval(0);'; saveval(0); -print '7411: a7400 = 9;'; +print '7411: a7400 = 9;'; a7400 = 9; -vrfy(. == 6, '7412: . == 6'); +vrfy(. == 6, '7412: . == 6'); print '7413: a7400 = 2; saveval(1); b7400 = 3; saveval(0); c7400 = 4;'; a7400 = 2; saveval(1); b7400 = 3; saveval(0); c7400 = 4; -vrfy(. == 3, '7414: . == 3'); -print '7415: free(.);'; +vrfy(. == 3, '7414: . == 3'); +print '7415: free(.);'; free(.); -vrfy(isnull(.), '7416: isnull(.)'); -print '7417: a7400 = 4;'; +vrfy(isnull(.), '7416: isnull(.)'); +print '7417: a7400 = 4;'; a7400 = 4; -vrfy(isnull(.), '7418: isnull(.)'); -print '7419: saveval(1);'; +vrfy(isnull(.), '7418: isnull(.)'); +print '7419: saveval(1);'; saveval(1); -print '7420: obj pair7400 {one,two} = {1,2};'; +print '7420: obj pair7400 {one,two} = {1,2};'; obj pair7400 {one,two} = {1,2}; -vrfy(. .one == 1, '7421: . .one == 1'); +vrfy(. .one == 1, '7421: . .one == 1'); print '7422: Ending test_savedot'; @@ -9045,28 +9045,28 @@ return test_bigcomb(); print; print '8000: Beginning read test'; value = 0; -vrfy(value == 0, '8001: value == 0'); +vrfy(value == 0, '8001: value == 0'); read "test8000.read"; -print '8002: read "test8000.read";'; -vrfy(value == 1, '8003: value == 1'); +print '8002: read "test8000.read";'; +vrfy(value == 1, '8003: value == 1'); read -once "test8000.read"; -print '8004: read -once "test8000.read";'; -vrfy(value == 1, '8005: value == 1'); +print '8004: read -once "test8000.read";'; +vrfy(value == 1, '8005: value == 1'); read "test8000.read.cal"; -print '8006: read "test8000.read.cal";'; -vrfy(value == 2, '8007: value == 2'); +print '8006: read "test8000.read.cal";'; +vrfy(value == 2, '8007: value == 2'); read -once "test8000.read.cal" -print '8008: read -once "test8000.read.cal";'; -vrfy(value == 2, '8009: value == 2'); +print '8008: read -once "test8000.read.cal";'; +vrfy(value == 2, '8009: value == 2'); read "test8000.read.cal"; -print '8010: read "test8000.read.cal";'; -vrfy(value == 3, '8011: value == 3'); +print '8010: read "test8000.read.cal";'; +vrfy(value == 3, '8011: value == 3'); {++value;} read "test8000.read.cal"; -print '8012: {++value;} read "test8000.read.cal";'; -vrfy(value == 5, '8013: value == 5'); +print '8012: {++value;} read "test8000.read.cal";'; +vrfy(value == 5, '8013: value == 5'); {++value;} read -once "test8000.read.cal"; -print '8014: {++value;} read -once "test8000.read.cal";'; -vrfy(value == 6, '8015: value == 6'); +print '8014: {++value;} read -once "test8000.read.cal";'; +vrfy(value == 6, '8015: value == 6'); print '8016: Ending read test'; @@ -9088,22 +9088,22 @@ return test_somenew(); * test 83dd: misc define tests */ print; -print '8300: Starting define tests'; +print '8300: Starting define tests'; define f8300(x) = x^2; define g8300(x) = 1 - x; -print '8301: define f8300(x) = x^2; define g8300(x) = 1 - x;'; -vrfy(f8300(10) == 100, '8302: f8300(10) == 100'); -vrfy(g8300(10) == -9, '8303: g8300(10) == -9'); +print '8301: define f8300(x) = x^2; define g8300(x) = 1 - x;'; +vrfy(f8300(10) == 100, '8302: f8300(10) == 100'); +vrfy(g8300(10) == -9, '8303: g8300(10) == -9'); define h8300(x)=x^3;define i8300(x)=x-1;define j8300(x)=x+1; -print '8304: define h8300(x)=x^3;define i8300(x)=x-1;define j8300(x)=x+1;'; -vrfy(h8300(10) == 1000, '8305: h8300(10) == 1000'); -vrfy(i8300(10) == 9, '8306: i8300(10) == 9'); -vrfy(j8300(10) == 11, '8307: j8300(10) == 11'); +print '8304: define h8300(x)=x^3;define i8300(x)=x-1;define j8300(x)=x+1;'; +vrfy(h8300(10) == 1000, '8305: h8300(10) == 1000'); +vrfy(i8300(10) == 9, '8306: i8300(10) == 9'); +vrfy(j8300(10) == 11, '8307: j8300(10) == 11'); {static k8300 = 5} define l8300(x) = k8300 + x; -print '8308: {static k8300 = 5} define l8300(x) = k8300 + x;'; -vrfy(l8300(10) == 15, '8309: l8300(10) == 15'); +print '8308: {static k8300 = 5} define l8300(x) = k8300 + x;'; +vrfy(l8300(10) == 15, '8309: l8300(10) == 15'); static a8300 = 1, b8300; -vrfy(a8300 == 1, '8310: a8300 == 1'); -print '8311: Ending define tests'; +vrfy(a8300 == 1, '8310: a8300 == 1'); +print '8311: Ending define tests'; /* @@ -9112,9 +9112,9 @@ print '8311: Ending define tests'; print; return test_quit(); read -once test8400.quit; -print '8404: read -once test8400.quit'; -vrfy(test8400() == 64434, '8405: test8400() == 64434'); -print '8406: Ending test_quit'; +print '8404: read -once test8400.quit'; +vrfy(test8400() == 64434, '8405: test8400() == 64434'); +print '8406: Ending test_quit'; /* @@ -9178,109 +9178,109 @@ ecnt = 214; */ define test_functions2() { - print '9001: Beginning test_functions2'; + print '9001: Beginning test_functions2'; - /* ctype function tests */ - vrfy(isalnum("A") == 1, '9002: isalnum("A") == 1'); - vrfy(isalnum("a") == 1, '9003: isalnum("a") == 1'); - vrfy(isalnum("2") == 1, '9004: isalnum("2") == 1'); - vrfy(isalnum("\t") == 0, '9005: isalnum("\\t") == 0'); + /* ctype function tests */ + vrfy(isalnum("A") == 1, '9002: isalnum("A") == 1'); + vrfy(isalnum("a") == 1, '9003: isalnum("a") == 1'); + vrfy(isalnum("2") == 1, '9004: isalnum("2") == 1'); + vrfy(isalnum("\t") == 0, '9005: isalnum("\\t") == 0'); - vrfy(isalpha("A") == 1, '9006: isalpha("A") == 1'); - vrfy(isalpha("a") == 1, '9007: isalpha("a") == 1'); - vrfy(isalpha("2") == 0, '9008: isalpha("2") == 0'); - vrfy(isalpha("\t") == 0, '9009: isalpha("\\t") == 0'); + vrfy(isalpha("A") == 1, '9006: isalpha("A") == 1'); + vrfy(isalpha("a") == 1, '9007: isalpha("a") == 1'); + vrfy(isalpha("2") == 0, '9008: isalpha("2") == 0'); + vrfy(isalpha("\t") == 0, '9009: isalpha("\\t") == 0'); - vrfy(iscntrl("A") == 0, '9010: iscntrl("A") == 0'); - vrfy(iscntrl("a") == 0, '9011: iscntrl("a") == 0'); - vrfy(iscntrl("2") == 0, '9012: iscntrl("2") == 0'); - vrfy(iscntrl("\t") == 1, '9013: iscntrl("\\t") == 1'); + vrfy(iscntrl("A") == 0, '9010: iscntrl("A") == 0'); + vrfy(iscntrl("a") == 0, '9011: iscntrl("a") == 0'); + vrfy(iscntrl("2") == 0, '9012: iscntrl("2") == 0'); + vrfy(iscntrl("\t") == 1, '9013: iscntrl("\\t") == 1'); - vrfy(isdigit("A") == 0, '9014: isdigit("A") == 0'); - vrfy(isdigit("a") == 0, '9015: isdigit("a") == 0'); - vrfy(isdigit("2") == 1, '9016: isdigit("2") == 1'); - vrfy(isdigit("\t") == 0, '9017: isdigit("\\t") == 0'); + vrfy(isdigit("A") == 0, '9014: isdigit("A") == 0'); + vrfy(isdigit("a") == 0, '9015: isdigit("a") == 0'); + vrfy(isdigit("2") == 1, '9016: isdigit("2") == 1'); + vrfy(isdigit("\t") == 0, '9017: isdigit("\\t") == 0'); - vrfy(isgraph("A") == 1, '9018: isgraph("A") == 1'); - vrfy(isgraph("a") == 1, '9019: isgraph("a") == 1'); - vrfy(isgraph("2") == 1, '9020: isgraph("2") == 1'); - vrfy(isgraph("\t") == 0, '9021: isgraph("\\t") == 0'); + vrfy(isgraph("A") == 1, '9018: isgraph("A") == 1'); + vrfy(isgraph("a") == 1, '9019: isgraph("a") == 1'); + vrfy(isgraph("2") == 1, '9020: isgraph("2") == 1'); + vrfy(isgraph("\t") == 0, '9021: isgraph("\\t") == 0'); - vrfy(islower("A") == 0, '9022: islower("A") == 0'); - vrfy(islower("a") == 1, '9023: islower("a") == 1'); - vrfy(islower("1") == 0, '9024: islower("1") == 0'); + vrfy(islower("A") == 0, '9022: islower("A") == 0'); + vrfy(islower("a") == 1, '9023: islower("a") == 1'); + vrfy(islower("1") == 0, '9024: islower("1") == 0'); - vrfy(isprint("A") == 1, '9025: isprint("A") == 1'); - vrfy(isprint("a") == 1, '9026: isprint("a") == 1'); - vrfy(isprint(" ") == 1, '9027: isprint(" ") == 1'); - vrfy(isprint("\t") == 0, '9028: isprint("\\t") == 0'); + vrfy(isprint("A") == 1, '9025: isprint("A") == 1'); + vrfy(isprint("a") == 1, '9026: isprint("a") == 1'); + vrfy(isprint(" ") == 1, '9027: isprint(" ") == 1'); + vrfy(isprint("\t") == 0, '9028: isprint("\\t") == 0'); - vrfy(ispunct("A") == 0, '9029: ispunct("A") == 0'); - vrfy(ispunct("a") == 0, '9030: ispunct("a") == 0'); - vrfy(ispunct(" ") == 0, '9031: ispunct(" ") == 0'); - vrfy(ispunct("?") == 1, '9032: ispunct("?") == 1'); + vrfy(ispunct("A") == 0, '9029: ispunct("A") == 0'); + vrfy(ispunct("a") == 0, '9030: ispunct("a") == 0'); + vrfy(ispunct(" ") == 0, '9031: ispunct(" ") == 0'); + vrfy(ispunct("?") == 1, '9032: ispunct("?") == 1'); - vrfy(isspace("A") == 0, '9033: isspace("A") == 0'); - vrfy(isspace("Krik") == 0, '9034: isspace("Krik") == 0'); - vrfy(isspace(" ") == 1, '9035: isspace(" ") == 1'); - vrfy(isspace("?") == 0, '9036: isspace("?") == 0'); + vrfy(isspace("A") == 0, '9033: isspace("A") == 0'); + vrfy(isspace("Krik") == 0, '9034: isspace("Krik") == 0'); + vrfy(isspace(" ") == 1, '9035: isspace(" ") == 1'); + vrfy(isspace("?") == 0, '9036: isspace("?") == 0'); - vrfy(isupper("A") == 1, '9037: isupper("A") == 1'); - vrfy(isupper("a") == 0, '9038: isupper("a") == 0'); - vrfy(isupper("1") == 0, '9039: isupper("1") == 0'); + vrfy(isupper("A") == 1, '9037: isupper("A") == 1'); + vrfy(isupper("a") == 0, '9038: isupper("a") == 0'); + vrfy(isupper("1") == 0, '9039: isupper("1") == 0'); - vrfy(isxdigit("A") == 1, '9040: isxdigit("A") == 1'); - vrfy(isxdigit("f") == 1, '9041: isxdigit("f") == 1'); - vrfy(isxdigit("2") == 1, '9042: isxdigit("2") == 1'); - vrfy(isxdigit("x") == 0, '9043: isxdigit("x") == 0'); + vrfy(isxdigit("A") == 1, '9040: isxdigit("A") == 1'); + vrfy(isxdigit("f") == 1, '9041: isxdigit("f") == 1'); + vrfy(isxdigit("2") == 1, '9042: isxdigit("2") == 1'); + vrfy(isxdigit("x") == 0, '9043: isxdigit("x") == 0'); - vrfy(strcasecmp("ab", "aBc") == -1, - '9044: strcasecmp("ab", "aBc") == -1'); - vrfy(strcasecmp("abc", "aBb") == 1, - '9045: strcasecmp("abc", "aBb") == 1'); - vrfy(strcasecmp("abc", "abc") == 0, - '9046: strcasecmp("abc", "abc") == 0'); - vrfy(strcasecmp("abc", "aBc") == 0, - '9047: strcasecmp("abc", "aBc") == 0'); - vrfy(strcasecmp("abc", "aBd") == -1, - '9048: strcasecmp("abc", "aBd") == -1'); - vrfy(strcasecmp("abc\0", "aBc") == 1, - '9049: strcasecmp("a8c\\0", "aBc") == 1'); - vrfy(strcasecmp("a\0b", "A\0c") == -1, - '9050: strcasecmp("a\\0b", "A\\0c") == -1'); + vrfy(strcasecmp("ab", "aBc") == -1, + '9044: strcasecmp("ab", "aBc") == -1'); + vrfy(strcasecmp("abc", "aBb") == 1, + '9045: strcasecmp("abc", "aBb") == 1'); + vrfy(strcasecmp("abc", "abc") == 0, + '9046: strcasecmp("abc", "abc") == 0'); + vrfy(strcasecmp("abc", "aBc") == 0, + '9047: strcasecmp("abc", "aBc") == 0'); + vrfy(strcasecmp("abc", "aBd") == -1, + '9048: strcasecmp("abc", "aBd") == -1'); + vrfy(strcasecmp("abc\0", "aBc") == 1, + '9049: strcasecmp("a8c\\0", "aBc") == 1'); + vrfy(strcasecmp("a\0b", "A\0c") == -1, + '9050: strcasecmp("a\\0b", "A\\0c") == -1'); - vrfy(strncasecmp("abc", "xyz", 0) == 0, - '9051: strncasecmp("abc", "xyz", 0) == 0'); - vrfy(strncasecmp("abc", "xyz", 1) == -1, - '9052: strncasecmp("abc", "xyz", 1) == -1'); - vrfy(strncasecmp("abc", "", 1) == 1, - '9053: strncasecmp("abc", "", 1) == 1'); - vrfy(strncasecmp("a", "b", 2) == -1, - '9054: strncasecmp("a", "b", 2) == -1'); - vrfy(strncasecmp("ab", "Ac", 2) == -1, - '9055: strncasecmp("ab", "Ac", 2) == -1'); - vrfy(strncasecmp("\0ac", "\0b", 2) == -1, - '9056: strncasecmp("\\0ac", "\\0b", 2) == -1'); - vrfy(strncasecmp("ab", "aBc", 2) == 0, - '9057: strncasecmp("ab", "aBc", 2) == 0'); - vrfy(strncasecmp("abc", "abd", 2) == 0, - '9058: strncasecmp("abc", "abd", 2) == 0'); + vrfy(strncasecmp("abc", "xyz", 0) == 0, + '9051: strncasecmp("abc", "xyz", 0) == 0'); + vrfy(strncasecmp("abc", "xyz", 1) == -1, + '9052: strncasecmp("abc", "xyz", 1) == -1'); + vrfy(strncasecmp("abc", "", 1) == 1, + '9053: strncasecmp("abc", "", 1) == 1'); + vrfy(strncasecmp("a", "b", 2) == -1, + '9054: strncasecmp("a", "b", 2) == -1'); + vrfy(strncasecmp("ab", "Ac", 2) == -1, + '9055: strncasecmp("ab", "Ac", 2) == -1'); + vrfy(strncasecmp("\0ac", "\0b", 2) == -1, + '9056: strncasecmp("\\0ac", "\\0b", 2) == -1'); + vrfy(strncasecmp("ab", "aBc", 2) == 0, + '9057: strncasecmp("ab", "aBc", 2) == 0'); + vrfy(strncasecmp("abc", "abd", 2) == 0, + '9058: strncasecmp("abc", "abd", 2) == 0'); - local s1 = " gnu lesser general public license"; - print '9059: local s1 = " gnu lesser general public license";'; + local s1 = " gnu lesser general public license"; + print '9059: local s1 = " gnu lesser general public license";'; - vrfy(strcmp(strtolower(" GNU Lesser General Public License"), s1) == 0, - '9060: strcmp(strtolower(" GNU Lesser General Public License"),' + - ' s1) == 0'); + vrfy(strcmp(strtolower(" GNU Lesser General Public License"), s1) == 0, + '9060: strcmp(strtolower(" GNU Lesser General Public License"),' + + ' s1) == 0'); - local s2 = " GNU LESSER GENERAL PUBLIC LICENSE"; - print '9061: local s2 = " GNU LESSER GENERAL PUBLIC LICENSE";'; + local s2 = " GNU LESSER GENERAL PUBLIC LICENSE"; + print '9061: local s2 = " GNU LESSER GENERAL PUBLIC LICENSE";'; - vrfy(strcmp(strtoupper(" GNU Lesser General Public License"), s2) == 0, - '9062: strcmp(strtoupper(" GNU Lesser General Public License"),' + - ' s2) == 0'); + vrfy(strcmp(strtoupper(" GNU Lesser General Public License"), s2) == 0, + '9062: strcmp(strtoupper(" GNU Lesser General Public License"),' + + ' s2) == 0'); - print '9063: Ending test_functions2'; + print '9063: Ending test_functions2'; } print; print '9000: parsed test_functions2()'; @@ -9296,385 +9296,385 @@ return test_functions2(); */ define test_functions3() { - local d, m, s, g, h; + local d, m, s, g, h; - print '9101: Beginning test_functions3'; + print '9101: Beginning test_functions3'; - /* d2r & r2d */ - vrfy(d2r(180) == pi(), - '9102: d2r(180) == pi()'); - vrfy(d2r(180, 1e-100) == pi(1e-100), - '9103: d2r(180, 1e-100) == pi(1e-100)'); - vrfy(r2d(pi()/2) == 90, - '9104: r2d(pi()/2) == 90'); - vrfy(r2d(pi(1e-15)/2) == 14137166941154068500000/157079632679489661923, - '9105: r2d(pi(1e-15)/2) == ' + - '14137166941154068500000/157079632679489661923'); - vrfy(r2d(d2r(40)) == 40, - '9106: r2d(d2r(40)) == 40'); - vrfy(r2d(d2r(40,1e-90),1e-90) == 40, - '9107: r2d(d2r(40,1e-90),1e-90) == 40'); - vrfy(d2r(180i) == 1i*pi(), - '9108: d2r(1808) == 1i*pi()'); - vrfy(d2r(180i+90) == 1i*pi() + pi()/2, - '9109: d2r(180i+90) == 1i*pi() + pi()/2'); - vrfy(r2d(d2r(40+40i)) == 40+40i, - '9110: r2d(d2r(40+40i)) == 40+40i'); - vrfy(r2d(d2r(40+40i,1e-60),1e-60) == 40+40i, - '9111: r2d(d2r(40+40i,1e-60),1e-60) == 40+40i'); + /* d2r & r2d */ + vrfy(d2r(180) == pi(), + '9102: d2r(180) == pi()'); + vrfy(d2r(180, 1e-100) == pi(1e-100), + '9103: d2r(180, 1e-100) == pi(1e-100)'); + vrfy(r2d(pi()/2) == 90, + '9104: r2d(pi()/2) == 90'); + vrfy(r2d(pi(1e-15)/2) == 14137166941154068500000/157079632679489661923, + '9105: r2d(pi(1e-15)/2) == ' + + '14137166941154068500000/157079632679489661923'); + vrfy(r2d(d2r(40)) == 40, + '9106: r2d(d2r(40)) == 40'); + vrfy(r2d(d2r(40,1e-90),1e-90) == 40, + '9107: r2d(d2r(40,1e-90),1e-90) == 40'); + vrfy(d2r(180i) == 1i*pi(), + '9108: d2r(1808) == 1i*pi()'); + vrfy(d2r(180i+90) == 1i*pi() + pi()/2, + '9109: d2r(180i+90) == 1i*pi() + pi()/2'); + vrfy(r2d(d2r(40+40i)) == 40+40i, + '9110: r2d(d2r(40+40i)) == 40+40i'); + vrfy(r2d(d2r(40+40i,1e-60),1e-60) == 40+40i, + '9111: r2d(d2r(40+40i,1e-60),1e-60) == 40+40i'); - /* g2r & r2g */ - vrfy(g2r(200) == pi(), - '9112: g2r(200) == pi()'); - vrfy(g2r(200, 1e-100) == pi(1e-100), - '9113: g2r(180, 1e-100) == pi(1e-100)'); - vrfy(r2g(pi()/2) == 100, - '9114: r2g(pi()/2) == 100'); - vrfy(r2g(pi(1e-15)/2) == 15707963267948965000000/157079632679489661923, - '9115: r2g(pi(1e-15)/2) == ' + - '15707963267948965000000/157079632679489661923'); - vrfy(r2g(g2r(40)) == 40, - '9116: r2g(g2r(40)) == 40'); - vrfy(r2g(g2r(40,1e-90),1e-90) == 40, - '9117: r2g(g2r(40,1e-90),1e-90) == 40'); - vrfy(g2r(200i) == 1i*pi(), - '9118: g2r(200i) == 1i*pi()'); - vrfy(g2r(200i+150) == pi()*0.75 + 1i*pi(), - '9119: g2r(200i+150) == pi()*0.75 + 1i*pi()'); - vrfy(r2g(g2r(40+40i)) == 40+40i, - '9120: r2g(g2r(40+40i)) == 40+40i'); - vrfy(r2g(g2r(40+40i,1e-60),1e-60) == 40+40i, - '9121: r2g(g2r(40+40i,1e-60),1e-60) == 40+40i'); + /* g2r & r2g */ + vrfy(g2r(200) == pi(), + '9112: g2r(200) == pi()'); + vrfy(g2r(200, 1e-100) == pi(1e-100), + '9113: g2r(180, 1e-100) == pi(1e-100)'); + vrfy(r2g(pi()/2) == 100, + '9114: r2g(pi()/2) == 100'); + vrfy(r2g(pi(1e-15)/2) == 15707963267948965000000/157079632679489661923, + '9115: r2g(pi(1e-15)/2) == ' + + '15707963267948965000000/157079632679489661923'); + vrfy(r2g(g2r(40)) == 40, + '9116: r2g(g2r(40)) == 40'); + vrfy(r2g(g2r(40,1e-90),1e-90) == 40, + '9117: r2g(g2r(40,1e-90),1e-90) == 40'); + vrfy(g2r(200i) == 1i*pi(), + '9118: g2r(200i) == 1i*pi()'); + vrfy(g2r(200i+150) == pi()*0.75 + 1i*pi(), + '9119: g2r(200i+150) == pi()*0.75 + 1i*pi()'); + vrfy(r2g(g2r(40+40i)) == 40+40i, + '9120: r2g(g2r(40+40i)) == 40+40i'); + vrfy(r2g(g2r(40+40i,1e-60),1e-60) == 40+40i, + '9121: r2g(g2r(40+40i,1e-60),1e-60) == 40+40i'); - /* g2d & d2g */ - vrfy(g2d(200) == 180, - '9122: g2d(200) == 180'); - vrfy(g2d(200, 1e-100) == 180, - '9123: g2d(180, 1e-100) == 180'); - vrfy(d2g(81) == 90, - '9124: d2g(81) == 90'); - vrfy(d2g(pi(1e-15)/2) == 3141592653589793/1800000000000000, - '9125: d2g(pi(1e-15)/2) == 3141592653589793/1800000000000000'); - vrfy(d2g(g2d(40)) == 40, - '9126: d2g(g2d(40)) == 40'); - vrfy(d2g(g2d(40,1e-90),1e-90) == 40, - '9127: d2g(g2d(40,1e-90),1e-90) == 40'); - vrfy(g2d(200i) == 180i, - '9128: g2d(200i) == 180i'); - vrfy(g2d(200i+47) == 42.3 + 180i, - '9129: g2d(200i+47) == 42.3 + 180i'); - vrfy(d2g(g2d(40+40i)) == 40+40i, - '9130: d2g(g2d(40+40i)) == 40+40i'); - vrfy(d2g(g2d(40+40i,1e-90),1e-90) == 40+40i, - '9131: d2g(g2d(40+40i,1e-90),1e-90) == 40+40i'); + /* g2d & d2g */ + vrfy(g2d(200) == 180, + '9122: g2d(200) == 180'); + vrfy(g2d(200, 1e-100) == 180, + '9123: g2d(180, 1e-100) == 180'); + vrfy(d2g(81) == 90, + '9124: d2g(81) == 90'); + vrfy(d2g(pi(1e-15)/2) == 3141592653589793/1800000000000000, + '9125: d2g(pi(1e-15)/2) == 3141592653589793/1800000000000000'); + vrfy(d2g(g2d(40)) == 40, + '9126: d2g(g2d(40)) == 40'); + vrfy(d2g(g2d(40,1e-90),1e-90) == 40, + '9127: d2g(g2d(40,1e-90),1e-90) == 40'); + vrfy(g2d(200i) == 180i, + '9128: g2d(200i) == 180i'); + vrfy(g2d(200i+47) == 42.3 + 180i, + '9129: g2d(200i+47) == 42.3 + 180i'); + vrfy(d2g(g2d(40+40i)) == 40+40i, + '9130: d2g(g2d(40+40i)) == 40+40i'); + vrfy(d2g(g2d(40+40i,1e-90),1e-90) == 40+40i, + '9131: d2g(g2d(40+40i,1e-90),1e-90) == 40+40i'); - /* d2dms */ - vrfy(d2dms(12.3456,d,m,s) == 12.3456, - '9132: d2dms(12.3456,d,m,s) == 12.3456'); - vrfy(d == 12, - '9133: d == 12'); - vrfy(m == 20, - '9133: m == 20'); - vrfy(s == 44.16, - '9134: s == 44.16'); + /* d2dms */ + vrfy(d2dms(12.3456,d,m,s) == 12.3456, + '9132: d2dms(12.3456,d,m,s) == 12.3456'); + vrfy(d == 12, + '9133: d == 12'); + vrfy(m == 20, + '9133: m == 20'); + vrfy(s == 44.16, + '9134: s == 44.16'); - vrfy(d2dms(1234.5678,d,m,s) == 154.5678, - '9135: d2dms(1234.5678,d,m,s) == 154.5678'); - vrfy(d == 154, - '9136: d == 154'); - vrfy(m == 34, - '9137: m == 34'); - vrfy(s == 4.08, - '9138: s == 4.08'); + vrfy(d2dms(1234.5678,d,m,s) == 154.5678, + '9135: d2dms(1234.5678,d,m,s) == 154.5678'); + vrfy(d == 154, + '9136: d == 154'); + vrfy(m == 34, + '9137: m == 34'); + vrfy(s == 4.08, + '9138: s == 4.08'); - vrfy(d2dms(-1234.5678,d,m,s) == 205.4322, - '9139: d2dms(-1234.5678,d,m,s) == 205.4322'); - vrfy(d == 205, - '9140: d == 205'); - vrfy(m == 25, - '9141: m == 25'); - vrfy(s == 55.92, - '9142: s == 55.92'); + vrfy(d2dms(-1234.5678,d,m,s) == 205.4322, + '9139: d2dms(-1234.5678,d,m,s) == 205.4322'); + vrfy(d == 205, + '9140: d == 205'); + vrfy(m == 25, + '9141: m == 25'); + vrfy(s == 55.92, + '9142: s == 55.92'); - vrfy(d2dms(360.321,d,m,s,1) == -359.679, - '9143: d2dms(360.321,d,m,s,1) == -359.679'); - vrfy(d == -359, - '9144: d == -359'); - vrfy(m == -40, - '9145: m == -40'); - vrfy(s == -44.4, - '9146: s == -44.4'); + vrfy(d2dms(360.321,d,m,s,1) == -359.679, + '9143: d2dms(360.321,d,m,s,1) == -359.679'); + vrfy(d == -359, + '9144: d == -359'); + vrfy(m == -40, + '9145: m == -40'); + vrfy(s == -44.4, + '9146: s == -44.4'); - /* d2dm */ - vrfy(d2dm(12.3456,d,m) == 12.3456, - '9147: d2dm(12.3456,d,m) == 12.3456'); - vrfy(d == 12, - '9148: d == 12'); - vrfy(m == 20.736, - '9149: m == 20.736'); + /* d2dm */ + vrfy(d2dm(12.3456,d,m) == 12.3456, + '9147: d2dm(12.3456,d,m) == 12.3456'); + vrfy(d == 12, + '9148: d == 12'); + vrfy(m == 20.736, + '9149: m == 20.736'); - vrfy(d2dm(1234.5678,d,m) == 154.5678, - '9150: d2dm(1234.5678,d,m) == 154.5678'); - vrfy(d == 154, - '9151: d == 154'); - vrfy(m == 34.068, - '9152: m == 34.068'); + vrfy(d2dm(1234.5678,d,m) == 154.5678, + '9150: d2dm(1234.5678,d,m) == 154.5678'); + vrfy(d == 154, + '9151: d == 154'); + vrfy(m == 34.068, + '9152: m == 34.068'); - vrfy(d2dm(-1234.5678,d,m) == 205.4322, - '9153: d2dm(-1234.5678,d,m) == 205.4322'); - vrfy(d == 205, - '9154: d == 205'); - vrfy(m == 25.932, - '9155: m == 25.932'); + vrfy(d2dm(-1234.5678,d,m) == 205.4322, + '9153: d2dm(-1234.5678,d,m) == 205.4322'); + vrfy(d == 205, + '9154: d == 205'); + vrfy(m == 25.932, + '9155: m == 25.932'); - vrfy(d2dm(360.321,d,m,1) == -359.679, - '9156: d2dm(360.321,d,m,1) == -359.679'); - vrfy(d == -359, - '9167: d == -359'); - vrfy(m == -40.74, - '9158: m == -40.74'); + vrfy(d2dm(360.321,d,m,1) == -359.679, + '9156: d2dm(360.321,d,m,1) == -359.679'); + vrfy(d == -359, + '9167: d == -359'); + vrfy(m == -40.74, + '9158: m == -40.74'); - /* g2gms */ - vrfy(g2gms(12.3456,g,m,s) == 12.3456, - '9159: g2gms(12.3456,g,m,s) == 12.3456'); - vrfy(g == 12, - '9133: g == 12'); - vrfy(m == 20, - '9160: m == 20'); - vrfy(s == 44.16, - '9161: s == 44.16'); + /* g2gms */ + vrfy(g2gms(12.3456,g,m,s) == 12.3456, + '9159: g2gms(12.3456,g,m,s) == 12.3456'); + vrfy(g == 12, + '9133: g == 12'); + vrfy(m == 20, + '9160: m == 20'); + vrfy(s == 44.16, + '9161: s == 44.16'); - vrfy(g2gms(1234.5678,g,m,s) == 34.5678, - '9162: g2gms(1234.5678,g,m,s) == 34.5678'); - vrfy(g == 34, - '9163: g == 34'); - vrfy(m == 34, - '9164: m == 34'); - vrfy(s == 4.08, - '9165: s == 4.08'); + vrfy(g2gms(1234.5678,g,m,s) == 34.5678, + '9162: g2gms(1234.5678,g,m,s) == 34.5678'); + vrfy(g == 34, + '9163: g == 34'); + vrfy(m == 34, + '9164: m == 34'); + vrfy(s == 4.08, + '9165: s == 4.08'); - vrfy(g2gms(-1234.5678,g,m,s) == 365.4322, - '9166: g2gms(-1234.5678,g,m,s) == 365.4322'); - vrfy(g == 365, - '9167: g == 365'); - vrfy(m == 25, - '9168: m == 25'); - vrfy(s == 55.92, - '9169: s == 55.92'); + vrfy(g2gms(-1234.5678,g,m,s) == 365.4322, + '9166: g2gms(-1234.5678,g,m,s) == 365.4322'); + vrfy(g == 365, + '9167: g == 365'); + vrfy(m == 25, + '9168: m == 25'); + vrfy(s == 55.92, + '9169: s == 55.92'); - vrfy(g2gms(400.321,g,m,s,1) == -399.679, - '9170: g2gms(400.321,g,m,s,1) == -399.679'); - vrfy(g == -399, - '9171: g == -399'); - vrfy(m == -40, - '9172: m == -40'); - vrfy(s == -44.4, - '9173: s == -44.4'); + vrfy(g2gms(400.321,g,m,s,1) == -399.679, + '9170: g2gms(400.321,g,m,s,1) == -399.679'); + vrfy(g == -399, + '9171: g == -399'); + vrfy(m == -40, + '9172: m == -40'); + vrfy(s == -44.4, + '9173: s == -44.4'); - /* g2gm */ - vrfy(g2gm(12.3456,g,m) == 12.3456, - '9174: g2gm(12.3456,g,m) == 12.3456'); - vrfy(g == 12, - '9175: g == 12'); - vrfy(m == 20.736, - '9176: m == 20.736'); + /* g2gm */ + vrfy(g2gm(12.3456,g,m) == 12.3456, + '9174: g2gm(12.3456,g,m) == 12.3456'); + vrfy(g == 12, + '9175: g == 12'); + vrfy(m == 20.736, + '9176: m == 20.736'); - vrfy(g2gm(1234.5678,g,m) == 34.5678, - '9177: g2gm(1234.5678,g,m) == 34.5678'); - vrfy(g == 34, - '9178: g == 34'); - vrfy(m == 34.068, - '9179: m == 34.068'); + vrfy(g2gm(1234.5678,g,m) == 34.5678, + '9177: g2gm(1234.5678,g,m) == 34.5678'); + vrfy(g == 34, + '9178: g == 34'); + vrfy(m == 34.068, + '9179: m == 34.068'); - vrfy(g2gm(-1234.5678,g,m) == 365.4322, - '9180: g2gm(-1234.5678,g,m) == 365.4322'); - vrfy(g == 365, - '9181: g == 365'); - vrfy(m == 25.932, - '9182: m == 25.932'); + vrfy(g2gm(-1234.5678,g,m) == 365.4322, + '9180: g2gm(-1234.5678,g,m) == 365.4322'); + vrfy(g == 365, + '9181: g == 365'); + vrfy(m == 25.932, + '9182: m == 25.932'); - vrfy(g2gm(400.321,g,m,1) == -399.679, - '9183: g2gm(400.321,g,m,1) == -399.679'); - vrfy(g == -399, - '9184: g == -399'); - vrfy(m == -40.74, - '9185: m == -40.74'); + vrfy(g2gm(400.321,g,m,1) == -399.679, + '9183: g2gm(400.321,g,m,1) == -399.679'); + vrfy(g == -399, + '9184: g == -399'); + vrfy(m == -40.74, + '9185: m == -40.74'); - /* h2hms */ - vrfy(h2hms(12.3456,h,m,s) == 12.3456, - '9186: h2hms(12.3456,h,m,s) == 12.3456'); - vrfy(h == 12, - '9187: h == 12'); - vrfy(m == 20, - '9188: m == 20'); - vrfy(s == 44.16, - '9189: s == 44.16'); + /* h2hms */ + vrfy(h2hms(12.3456,h,m,s) == 12.3456, + '9186: h2hms(12.3456,h,m,s) == 12.3456'); + vrfy(h == 12, + '9187: h == 12'); + vrfy(m == 20, + '9188: m == 20'); + vrfy(s == 44.16, + '9189: s == 44.16'); - vrfy(h2hms(1234.5678,h,m,s) == 10.5678, - '9190: h2hms(1234.5678,h,m,s) == 10.5678'); - vrfy(h == 10, - '9191: h == 10'); - vrfy(m == 34, - '9192: m == 34'); - vrfy(s == 4.08, - '9193: s == 4.08'); + vrfy(h2hms(1234.5678,h,m,s) == 10.5678, + '9190: h2hms(1234.5678,h,m,s) == 10.5678'); + vrfy(h == 10, + '9191: h == 10'); + vrfy(m == 34, + '9192: m == 34'); + vrfy(s == 4.08, + '9193: s == 4.08'); - vrfy(h2hms(-1234.5678,h,m,s) == 13.4322, - '9194: h2hms(-1234.5678,h,m,s) == 13.4322'); - vrfy(h == 13, - '9195: h == 13'); - vrfy(m == 25, - '9196: m == 25'); - vrfy(s == 55.92, - '9197: s == 55.92'); + vrfy(h2hms(-1234.5678,h,m,s) == 13.4322, + '9194: h2hms(-1234.5678,h,m,s) == 13.4322'); + vrfy(h == 13, + '9195: h == 13'); + vrfy(m == 25, + '9196: m == 25'); + vrfy(s == 55.92, + '9197: s == 55.92'); - vrfy(h2hms(24.321,h,m,s,1) == -23.679, - '9198: h2hms(24.321,h,m,s,1) == -23.679'); - vrfy(h == -23, - '9199: h == -23'); - vrfy(m == -40, - '9200: m == -40'); - vrfy(s == -44.4, - '9201: s == -44.4'); + vrfy(h2hms(24.321,h,m,s,1) == -23.679, + '9198: h2hms(24.321,h,m,s,1) == -23.679'); + vrfy(h == -23, + '9199: h == -23'); + vrfy(m == -40, + '9200: m == -40'); + vrfy(s == -44.4, + '9201: s == -44.4'); - /* h2hm */ - vrfy(h2hm(12.3456,h,m) == 12.3456, - '9202: h2hm(12.3456,h,m) == 12.3456'); - vrfy(h == 12, - '9203: h == 12'); - vrfy(m == 20.736, - '9204: m == 20.736'); + /* h2hm */ + vrfy(h2hm(12.3456,h,m) == 12.3456, + '9202: h2hm(12.3456,h,m) == 12.3456'); + vrfy(h == 12, + '9203: h == 12'); + vrfy(m == 20.736, + '9204: m == 20.736'); - vrfy(h2hm(1234.5678,h,m) == 10.5678, - '9205: h2hm(1234.5678,h,m) == 10.5678'); - vrfy(h == 10, - '9206: h == 10'); - vrfy(m == 34.068, - '9207: m == 34.068'); + vrfy(h2hm(1234.5678,h,m) == 10.5678, + '9205: h2hm(1234.5678,h,m) == 10.5678'); + vrfy(h == 10, + '9206: h == 10'); + vrfy(m == 34.068, + '9207: m == 34.068'); - vrfy(h2hm(-1234.5678,h,m) == 13.4322, - '9208: h2hm(-1234.5678,h,m) == 13.4322'); - vrfy(h == 13, - '9209: h == 13'); - vrfy(m == 25.932, - '9210: m == 25.932'); + vrfy(h2hm(-1234.5678,h,m) == 13.4322, + '9208: h2hm(-1234.5678,h,m) == 13.4322'); + vrfy(h == 13, + '9209: h == 13'); + vrfy(m == 25.932, + '9210: m == 25.932'); - vrfy(h2hm(24.321,h,m,1) == -23.679, - '9211: h2hm(24.321,h,m,1) == -23.679'); - vrfy(h == -23, - '9212: h == -23'); - vrfy(m == -40.74, - '9213: m == -40.74'); + vrfy(h2hm(24.321,h,m,1) == -23.679, + '9211: h2hm(24.321,h,m,1) == -23.679'); + vrfy(h == -23, + '9212: h == -23'); + vrfy(m == -40.74, + '9213: m == -40.74'); - /* dm2d */ - vrfy(dm2d(203, 325.5594) == 208.42599, - '9214: dm2d(203, 325.5594) == 208.42599'); - vrfy(dm2d(3601, -25.5594) == 0.57401, - '9215: dm2d(3601, -25.5594) == 0.57401'); - vrfy(dm2d(-923, -25.5594) == 156.57401, - '9216: dm2d(-923, -25.5594) == 156.57401'); - vrfy(dm2d(203, 325.5594, 1) == -151.57401, - '9217: dm2d(203, 325.5594, 1) == -151.57401'); + /* dm2d */ + vrfy(dm2d(203, 325.5594) == 208.42599, + '9214: dm2d(203, 325.5594) == 208.42599'); + vrfy(dm2d(3601, -25.5594) == 0.57401, + '9215: dm2d(3601, -25.5594) == 0.57401'); + vrfy(dm2d(-923, -25.5594) == 156.57401, + '9216: dm2d(-923, -25.5594) == 156.57401'); + vrfy(dm2d(203, 325.5594, 1) == -151.57401, + '9217: dm2d(203, 325.5594, 1) == -151.57401'); - vrfy(d2dm(dm2d(12, 20.16),d,m) == 12.336, - '9218: d2dm(dm2d(12, 20.16),d,m) == 12.336'); - vrfy(d == 12, - '9219: d == 12'); - vrfy(m == 20.16, - '9220: m == 20.16'); + vrfy(d2dm(dm2d(12, 20.16),d,m) == 12.336, + '9218: d2dm(dm2d(12, 20.16),d,m) == 12.336'); + vrfy(d == 12, + '9219: d == 12'); + vrfy(m == 20.16, + '9220: m == 20.16'); - /* dms2d */ - vrfy(dms2d(12, 20, 44.16) == 12.3456, - '9221: dms2d(12, 20, 44.16) == 12.3456'); - vrfy(dms2d(123.456, -345.68, 4.08) == 117.6958, - '9222: dms2d(123.456, -345.68, 4.08) == 117.6958'); - vrfy(dms2d(-65, -40, -44.4) == 294.321, - '9223: dms2d(-65, -40, -44.4) == 294.321'); - vrfy(dms2d(12, 20, 44.16, 1) == -347.6544, - '9224: dms2d(12, 20, 44.16, 1) == -347.6544'); + /* dms2d */ + vrfy(dms2d(12, 20, 44.16) == 12.3456, + '9221: dms2d(12, 20, 44.16) == 12.3456'); + vrfy(dms2d(123.456, -345.68, 4.08) == 117.6958, + '9222: dms2d(123.456, -345.68, 4.08) == 117.6958'); + vrfy(dms2d(-65, -40, -44.4) == 294.321, + '9223: dms2d(-65, -40, -44.4) == 294.321'); + vrfy(dms2d(12, 20, 44.16, 1) == -347.6544, + '9224: dms2d(12, 20, 44.16, 1) == -347.6544'); - vrfy(d2dms(dms2d(13, 20, 44.16),d,m,s) == 13.3456, - '9225: d2dms(dms2d(13, 20, 44.16),d,m,s) == 13.3456'); - vrfy(d == 13, - '9226: d == 13'); - vrfy(m == 20, - '9227: m == 20'); - vrfy(s == 44.16, - '9228: s == 44.16'); + vrfy(d2dms(dms2d(13, 20, 44.16),d,m,s) == 13.3456, + '9225: d2dms(dms2d(13, 20, 44.16),d,m,s) == 13.3456'); + vrfy(d == 13, + '9226: d == 13'); + vrfy(m == 20, + '9227: m == 20'); + vrfy(s == 44.16, + '9228: s == 44.16'); - /* gm2g */ - vrfy(gm2g(203, 325.5594) == 208.42599, - '9229: gm2g(203, 325.5594) == 208.42599'); - vrfy(gm2g(3601, -25.5594) == 0.57401, - '9230: gm2g(3601, -25.5594) == 0.57401'); - vrfy(gm2g(-923, -25.5594) == 276.57401, - '9231: gm2g(-923, -25.5594) == 276.57401'); - vrfy(gm2g(203, 325.5594, 1) == -191.57401, - '9232: gm2g(203, 325.5594, 1) == -191.57401'); + /* gm2g */ + vrfy(gm2g(203, 325.5594) == 208.42599, + '9229: gm2g(203, 325.5594) == 208.42599'); + vrfy(gm2g(3601, -25.5594) == 0.57401, + '9230: gm2g(3601, -25.5594) == 0.57401'); + vrfy(gm2g(-923, -25.5594) == 276.57401, + '9231: gm2g(-923, -25.5594) == 276.57401'); + vrfy(gm2g(203, 325.5594, 1) == -191.57401, + '9232: gm2g(203, 325.5594, 1) == -191.57401'); - vrfy(g2gm(gm2g(12, 20.16),g,m) == 12.336, - '9233: g2gm(gm2g(12, 20.16),g,m) == 12.336'); - vrfy(g == 12, - '9234: g == 12'); - vrfy(m == 20.16, - '9235: m == 20.16'); + vrfy(g2gm(gm2g(12, 20.16),g,m) == 12.336, + '9233: g2gm(gm2g(12, 20.16),g,m) == 12.336'); + vrfy(g == 12, + '9234: g == 12'); + vrfy(m == 20.16, + '9235: m == 20.16'); - /* gms2g */ - vrfy(gms2g(12, 20, 44.16) == 12.3456, - '9236: gms2g(12, 20, 44.16) == 12.3456'); - vrfy(gms2g(123.456, -345.68, 4.08) == 117.6958, - '9237: gms2g(123.456, -345.68, 4.08) == 117.6958'); - vrfy(gms2g(-65, -40, -44.4) == 334.321, - '9238: gms2g(-65, -40, -44.4) == 334.321'); - vrfy(gms2g(12, 20, 44.16, 1) == -387.6544, - '9239: gms2g(12, 20, 44.16, 1) == -387.6544'); + /* gms2g */ + vrfy(gms2g(12, 20, 44.16) == 12.3456, + '9236: gms2g(12, 20, 44.16) == 12.3456'); + vrfy(gms2g(123.456, -345.68, 4.08) == 117.6958, + '9237: gms2g(123.456, -345.68, 4.08) == 117.6958'); + vrfy(gms2g(-65, -40, -44.4) == 334.321, + '9238: gms2g(-65, -40, -44.4) == 334.321'); + vrfy(gms2g(12, 20, 44.16, 1) == -387.6544, + '9239: gms2g(12, 20, 44.16, 1) == -387.6544'); - vrfy(g2gms(gms2g(14, 20, 44.16),g,m,s) == 14.3456, - '9240: g2gms(gms2g(14, 20, 44.16),g,m,s) == 14.3456'); - vrfy(g == 14, - '9241: g == 14'); - vrfy(m == 20, - '9242: m == 20'); - vrfy(s == 44.16, - '9243: s == 44.16'); + vrfy(g2gms(gms2g(14, 20, 44.16),g,m,s) == 14.3456, + '9240: g2gms(gms2g(14, 20, 44.16),g,m,s) == 14.3456'); + vrfy(g == 14, + '9241: g == 14'); + vrfy(m == 20, + '9242: m == 20'); + vrfy(s == 44.16, + '9243: s == 44.16'); - /* hm2h */ - vrfy(hm2h(203, 325.5594) == 16.42599, - '9244: hm2h(203, 325.5594) == 16.42599'); - vrfy(hm2h(241, -25.5594) == 0.57401, - '9245: hm2h(241, -25.5594) == 0.57401'); - vrfy(hm2h(-923, -25.5594) == 12.57401, - '9246: hm2h(-923, -25.5594) == 12.57401'); - vrfy(hm2h(203, 325.5594, 1) == -7.57401, - '9247: hm2h(203, 325.5594, 1) == -7.57401'); + /* hm2h */ + vrfy(hm2h(203, 325.5594) == 16.42599, + '9244: hm2h(203, 325.5594) == 16.42599'); + vrfy(hm2h(241, -25.5594) == 0.57401, + '9245: hm2h(241, -25.5594) == 0.57401'); + vrfy(hm2h(-923, -25.5594) == 12.57401, + '9246: hm2h(-923, -25.5594) == 12.57401'); + vrfy(hm2h(203, 325.5594, 1) == -7.57401, + '9247: hm2h(203, 325.5594, 1) == -7.57401'); - vrfy(h2hm(hm2h(12, 20.16),h,m) == 12.336, - '9248: h2hm(hm2h(12, 20.16),h,m) == 12.336'); - vrfy(h == 12, - '9249: h == 12'); - vrfy(m == 20.16, - '9250: m == 20.16'); + vrfy(h2hm(hm2h(12, 20.16),h,m) == 12.336, + '9248: h2hm(hm2h(12, 20.16),h,m) == 12.336'); + vrfy(h == 12, + '9249: h == 12'); + vrfy(m == 20.16, + '9250: m == 20.16'); - /* hms2h */ - vrfy(hms2h(12, 20, 44.16) == 12.3456, - '9251: hms2h(12, 20, 44.16) == 12.3456'); - vrfy(hms2h(123.456, -345.68, 4.08) == 21.6958, - '9252: hms2h(123.456, -345.68, 4.08) == 21.6958'); - vrfy(hms2h(-65, -40, -44.4) == 6.321, - '9253: hms2h(-65, -40, -44.4) == 6.321'); - vrfy(hms2h(12, 20, 44.16, 1) == -11.6544, - '9254: hms2h(12, 20, 44.16, 1) == -11.6544'); + /* hms2h */ + vrfy(hms2h(12, 20, 44.16) == 12.3456, + '9251: hms2h(12, 20, 44.16) == 12.3456'); + vrfy(hms2h(123.456, -345.68, 4.08) == 21.6958, + '9252: hms2h(123.456, -345.68, 4.08) == 21.6958'); + vrfy(hms2h(-65, -40, -44.4) == 6.321, + '9253: hms2h(-65, -40, -44.4) == 6.321'); + vrfy(hms2h(12, 20, 44.16, 1) == -11.6544, + '9254: hms2h(12, 20, 44.16, 1) == -11.6544'); - vrfy(h2hms(hms2h(15, 20, 44.16),h,m,s) == 15.3456, - '9255: h2hms(hms2h(15, 20, 44.16),h,m,s) == 15.3456'); - vrfy(h == 15, - '9256: h == 15'); - vrfy(m == 20, - '9257: m == 20'); - vrfy(s == 44.16, - '9258: s == 44.16'); + vrfy(h2hms(hms2h(15, 20, 44.16),h,m,s) == 15.3456, + '9255: h2hms(hms2h(15, 20, 44.16),h,m,s) == 15.3456'); + vrfy(h == 15, + '9256: h == 15'); + vrfy(m == 20, + '9257: m == 20'); + vrfy(s == 44.16, + '9258: s == 44.16'); - print '9259: Ending test_functions3'; + print '9259: Ending test_functions3'; } print; print '9100: parsed test_functions3()'; @@ -9685,7 +9685,7 @@ return test_functions3(); * test 93dd: test_frem - tests of the functions frem, fcnt, gcdrem * * NOTE: We moved test3500 to test9300. We parse this code here, - * however we execute this code as a 9300 test. + * however we execute this code as a 9300 test. */ print; return test_frem(); @@ -9703,170 +9703,170 @@ return test_frem(); * all of real actions of regress.cal. */ print; -print '9400: Starting read of selected calc resource files'; +print '9400: Starting read of selected calc resource files'; read -once alg_config; -print '9401: read -once alg_config'; +print '9401: read -once alg_config'; -print '9402: skipping read -once beer because it is an infinite loop'; +print '9402: skipping read -once beer because it is an infinite loop'; read -once bernoulli; -print '9403: read -once bernoulli'; +print '9403: read -once bernoulli'; -print '9404: skipping read -once bernpoly - will be read via test8900.special'; +print '9404: skipping read -once bernpoly - will be read via test8900.special'; read -once bigprime; -print '9405: read -once bigprime'; +print '9405: read -once bigprime'; -print '9406: skipping read -once brentsolve - will be read via test8900.special'; +print '9406: skipping read -once brentsolve - will be read via test8900.special'; read -once chi; -print '9407: read -once chi'; +print '9407: read -once chi'; read -once chrem; -print '9408: read -once chrem'; +print '9408: read -once chrem'; read -once comma; -print '9409: read -once comma'; +print '9409: read -once comma'; -print '9410: skipping read -once constants - will be read via test8900.special'; +print '9410: skipping read -once constants - will be read via test8900.special'; read -once deg; -print '9411: read -once deg'; +print '9411: read -once deg'; read -once dms; -print '9412: read -once dms'; +print '9412: read -once dms'; -print '9413: skipping read -once dotest - will be read via test8700.dotest'; +print '9413: skipping read -once dotest - will be read via test8700.dotest'; read -once ellip; -print '9414: read -once ellip'; +print '9414: read -once ellip'; -print '9415: skipping read -once factorial - will be read via test8900.special'; +print '9415: skipping read -once factorial - will be read via test8900.special'; -print '9416: skipping read -once factorial2 - will be read via test8900.special'; +print '9416: skipping read -once factorial2 - will be read via test8900.special'; read -once fnv_tool; -print '9417: read -once fnv_tool'; +print '9417: read -once fnv_tool'; read -once gvec; -print '9418: read -once gvec'; +print '9418: read -once gvec'; -print '9419: skipping read -once hello.cal because it is an infinite loop'; +print '9419: skipping read -once hello.cal because it is an infinite loop'; read -once hms; -print '9420: read -once hms'; +print '9420: read -once hms'; -print '9421: skipping read -once infinities - will be read via test8900.special'; +print '9421: skipping read -once infinities - will be read via test8900.special'; read -once intfile; -print '9422: read -once intfile'; +print '9422: read -once intfile'; -print '9423: skipping read -once intnum - will be read via test8900.special'; +print '9423: skipping read -once intnum - will be read via test8900.special'; -print '9424: skipping read -once lambertw - will be read via test8900.special'; +print '9424: skipping read -once lambertw - will be read via test8900.special'; read -once linear; -print '9425: read -once linear'; +print '9425: read -once linear'; read -once lnseries; -print '9426: read -once lnseries'; +print '9426: read -once lnseries'; -print '9427: skipping read -once lucas - will be read via regress'; +print '9427: skipping read -once lucas - will be read via regress'; -print '9428: skipping read -once lucas_chk - will be read via regress'; +print '9428: skipping read -once lucas_chk - will be read via regress'; read -once mersenne; -print '9429: read -once mersenne'; +print '9429: read -once mersenne'; read -once mfactor; -print '9430: read -once mfactor'; +print '9430: read -once mfactor'; read -once mod; -print '9431: read -once mod'; +print '9431: read -once mod'; read -once natnumset; -print '9432: read -once natnumset'; +print '9432: read -once natnumset'; read -once palindrome; -print '9433: read -once palindrome'; +print '9433: read -once palindrome'; read -once pell; -print '9434: read -once pell'; +print '9434: read -once pell'; read -once pi; -print '9435: read -once pi'; +print '9435: read -once pi'; read -once pix; -print '9436: read -once pix'; +print '9436: read -once pix'; read -once pollard; -print '9437: read -once pollard'; +print '9437: read -once pollard'; read -once poly; -print '9438: read -once poly'; +print '9438: read -once poly'; read -once prompt; -print '9439: read -once prompt'; +print '9439: read -once prompt'; read -once psqrt; -print '9440: read -once psqrt'; +print '9440: read -once psqrt'; read -once qtime; -print '9441: read -once qtime'; +print '9441: read -once qtime'; read -once quat; -print '9442: read -once quat'; +print '9442: read -once quat'; read -once randbitrun; -print '9443: read -once randbitrun'; +print '9443: read -once randbitrun'; read -once randmprime; -print '9444: read -once randmprime'; +print '9444: read -once randmprime'; read -once randombitrun; -print '9445: read -once randombitrun'; +print '9445: read -once randombitrun'; read -once randomrun; -print '9446: read -once randomrun'; +print '9446: read -once randomrun'; read -once randrun; -print '9447: read -once randrun'; +print '9447: read -once randrun'; -print '9448: skipping read -once regress - will be read via regress'; +print '9448: skipping read -once regress - will be read via regress'; read -once repeat; -print '9449: read -once repeat'; +print '9449: read -once repeat'; read -once screen; -print '9450: read -once screen'; +print '9450: read -once screen'; read -once seedrandom; -print '9451: read -once seedrandom'; +print '9451: read -once seedrandom'; read -once smallfactors; -print '9452: read -once smallfactors'; +print '9452: read -once smallfactors'; read -once solve; -print '9453: read -once solve'; +print '9453: read -once solve'; -print '9454: skipping read -once specialfunctions - will be read via test8900.special'; +print '9454: skipping read -once specialfunctions - will be read via test8900.special'; read -once splitbits; -print '9455: read -once splitbits'; +print '9455: read -once splitbits'; -print '9456: skipping read -once statistics - will be read via test8900.special'; +print '9456: skipping read -once statistics - will be read via test8900.special'; read -once strings; -print '9457: read -once strings'; +print '9457: read -once strings'; read -once sumsq; -print '9458: read -once sumsq'; +print '9458: read -once sumsq'; read -once sumtimes; -print '9459: read -once sumtimes'; +print '9459: read -once sumtimes'; -print '9460: skipping read -once surd - will be read via regress'; +print '9460: skipping read -once surd - will be read via regress'; print '9461: skipping read -once test2300.obj_incdec - will be read via regress'; @@ -9904,22 +9904,22 @@ print '9477: skipping read -once test8900.special - will be read via regress'; print '9478: skipping read -once test9300.frem - will be read via regress'; -print '9479: skipping read -once toomcook - will be read via test8900.special'; +print '9479: skipping read -once toomcook - will be read via test8900.special'; read -once unitfrac; -print '9480: read -once unitfrac'; +print '9480: read -once unitfrac'; read -once varargs; -print '9481: read -once varargs'; +print '9481: read -once varargs'; read -once write2file; -print '9482: read -once write2file'; +print '9482: read -once write2file'; -print '9483: skipping read -once xx_print.cal because it is a printing demo'; +print '9483: skipping read -once xx_print.cal because it is a printing demo'; -print '9484: skipping read -once zeta2 - will be read via test8900.special'; +print '9484: skipping read -once zeta2 - will be read via test8900.special'; -print '9485: Ending read of selected calc resource files'; +print '9485: Ending read of selected calc resource files'; /* @@ -9931,23 +9931,23 @@ epsilon(1e-20),; print '9501: epsilon(1e-20)'; read -once test9500.trigeq; print '9502: read -once test9500.trigeq'; -vrfy(verify_tan(9503) == 0, '9503: verify_tan(9503) == 0'); -vrfy(verify_cot(9504) == 0, '9504: verify_cot(9504) == 0'); -vrfy(verify_sec(9505) == 0, '9505: verify_sec(9505) == 0'); -vrfy(verify_csc(9506) == 0, '9506: verify_csc(9506) == 0'); -vrfy(verify_versin(9507) == 0, '9507: verify_versin(9507) == 0'); -vrfy(verify_coversin(9508) == 0, '9508: verify_coversin(9508) == 0'); -vrfy(verify_vercos(9509) == 0, '9509: verify_vercos(9509) == 0'); -vrfy(verify_covercos(9510) == 0, '9510: verify_covercos(9510) == 0'); -vrfy(verify_haversin(9511) == 0, '9511: verify_haversin(9511) == 0'); -vrfy(verify_hacoversin(9512) == 0, '9512: verify_hacoversin(9512) == 0'); -vrfy(verify_havercos(9513) == 0, '9513: verify_havercos(9513) == 0'); -vrfy(verify_hacovercos(9514) == 0, '9514: verify_hacovercos(9514) == 0'); -vrfy(verify_exsec(9515) == 0, '9515: verify_exsec(9515) == 0'); -vrfy(verify_excsc(9516) == 0, '9516: verify_excsc(9516) == 0'); -vrfy(verify_crd(9517) == 0, '9517: verify_crd(9517) == 0'); -vrfy(verify_cas(9518) == 0, '9518: verify_cas(9518) == 0'); -vrfy(verify_cis(9519) == 0, '9519: verify_cis(9519) == 0'); +vrfy(verify_tan(9503) == 0, '9503: verify_tan(9503) == 0'); +vrfy(verify_cot(9504) == 0, '9504: verify_cot(9504) == 0'); +vrfy(verify_sec(9505) == 0, '9505: verify_sec(9505) == 0'); +vrfy(verify_csc(9506) == 0, '9506: verify_csc(9506) == 0'); +vrfy(verify_versin(9507) == 0, '9507: verify_versin(9507) == 0'); +vrfy(verify_coversin(9508) == 0, '9508: verify_coversin(9508) == 0'); +vrfy(verify_vercos(9509) == 0, '9509: verify_vercos(9509) == 0'); +vrfy(verify_covercos(9510) == 0, '9510: verify_covercos(9510) == 0'); +vrfy(verify_haversin(9511) == 0, '9511: verify_haversin(9511) == 0'); +vrfy(verify_hacoversin(9512) == 0, '9512: verify_hacoversin(9512) == 0'); +vrfy(verify_havercos(9513) == 0, '9513: verify_havercos(9513) == 0'); +vrfy(verify_hacovercos(9514) == 0, '9514: verify_hacovercos(9514) == 0'); +vrfy(verify_exsec(9515) == 0, '9515: verify_exsec(9515) == 0'); +vrfy(verify_excsc(9516) == 0, '9516: verify_excsc(9516) == 0'); +vrfy(verify_crd(9517) == 0, '9517: verify_crd(9517) == 0'); +vrfy(verify_cas(9518) == 0, '9518: verify_cas(9518) == 0'); +vrfy(verify_cis(9519) == 0, '9519: verify_cis(9519) == 0'); print '9520: Ending trigonometric identities test set'; @@ -9957,16 +9957,16 @@ print '9520: Ending trigonometric identities test set'; */ print; print '9600: Starting test of dupvar_warn and redecl_warn config parameters'; -vrfy(config("redecl_warn",0), '9601: config("redecl_warn",0)'); -vrfy(config("dupvar_warn",0), '9602: config("dupvar_warn",0)'); -vrfy(u_glob == 6, '9603: u_glob == 6'); +vrfy(config("redecl_warn",0), '9601: config("redecl_warn",0)'); +vrfy(config("dupvar_warn",0), '9602: config("dupvar_warn",0)'); +vrfy(u_glob == 6, '9603: u_glob == 6'); global u_glob = 555; -print '9604: declare u_glob'; -vrfy(u_glob == 555, '9605: u_glob == 555'); +print '9604: declare u_glob'; +vrfy(u_glob == 555, '9605: u_glob == 555'); define func_8650(u_glob) { local u_glob; return u_glob; } -print '9606: u_glob as both local and parameter'; +print '9606: u_glob as both local and parameter'; define func_8650a(u_glob) { static u_glob; return u_glob; } -print '9607: u_glob as both static and parameter'; +print '9607: u_glob as both static and parameter'; vrfy(config("redecl_warn",1)==0, '9608: config("redecl_warn",1)==0'); vrfy(config("dupvar_warn",1)==0, '9609: config("dupvar_warn",1)==0'); @@ -9983,211 +9983,211 @@ print '9610: Ending test of dupvar_warn and redecl_warn config parameters'; */ define test_error() { - local strx, e99, list1, e9999; - local a, b, c, n, x; /* used by newerror() */ + local strx, e99, list1, e9999; + local a, b, c, n, x; /* used by newerror() */ - print '9700: Beginning test_error'; + print '9700: Beginning test_error'; - print '9701: ecnt:', ecnt; + print '9701: ecnt:', ecnt; - strx = "x"; - print '9702: strx = "x"'; - e99 = error(99); - print '9703: e99 = error(99)'; - vrfy(1/0 == error("E_DIVBYZERO"), '9704: 1/0 == error("E_DIVBYZERO")'); - vrfy(0/0 == error("E_ZERODIVZERO"), '9705: 0/0 == error("E_ZERODIVZERO")'); - vrfy(2 + "x" == error("E_ADD"), '9706: 2 + "x" == error("E_ADD")'); - vrfy("x" - 2 == error("E_SUB"), '9707: "x" - 2 == error("E_SUB")'); - vrfy("x" * "y" == error("E_MUL"), '9708: "x" * "y" == error("E_MUL")'); - vrfy("x" / "y" == error("E_DIV"), '9709: "x" / "y" == error("E_DIV")'); - vrfy(-list(1) == error("E_NEG"), '9710: -list(1) == error("E_NEG")'); - vrfy("x"^2 == error("E_SQUARE"), '9711: "x"^2 == error("E_SQUARE")'); - vrfy(inverse("x")==error("E_INV"), '9712: inverse("x") == error("E_INV")'); - vrfy(++strx == error("E_INCV"), '9713: ++strx == error("E_INCV")'); - vrfy(strx == error("E_INCV"), '9714: strx == error("E_INCV")'); - strx = "x"; - print '9715: strx = "x"'; - vrfy(strx++ == "x", '9716: strx++ == "x"'); - vrfy(strx == error("E_INCV"), '9717: strx == error("E_INCV")'); - strx = "x"; - print '9718: strx = "x"'; - vrfy(--strx == error("E_DECV"), '9719: strx == error("E_DECV")'); - vrfy(int("x") == error("E_INT"), '9720: int("x") == error("E_INT")'); - vrfy(frac("x") == error("E_FRAC"), '9721: frac("x") == error("E_FRAC")'); - vrfy(conj("x") == error("E_CONJ"), '9722: conj("x") == error("E_CONJ")'); - vrfy(appr("x",.1) == error("E_APPR_1"), - '9723: appr("x",.1) == error("E_APPR_1")'); - vrfy(appr(1.27,.1i) == error("E_APPR_2"), - '9724: appr(1.27,.1i) == error("E_APPR_2")'); - vrfy(appr(1.27,.1,.1) == error("E_APPR_3"), - '9725: appr(1.27,.1,.1) == error("E_APPR_3")'); - vrfy(round("x") == error("E_ROUND_1"), - '9726: round("x") == error("E_ROUND_1")'); - vrfy(round(1.25,.1) == error("E_ROUND_2"), - '9727: round(1.25,.1) == error("E_ROUND_2")'); - vrfy(round(1.25,"x") == error("E_ROUND_2"), - '9728: round(1.25,"x") == error("E_ROUND_2")'); - vrfy(round(1.25,1,.1) == error("E_ROUND_3"), - '9729: round(1.25,1,.1) == error("E_ROUND_3")'); - vrfy(bround("x") == error("E_BROUND_1"), - '9730: bround("x") == error("E_BROUND_1")'); - vrfy(bround(1.25,.1) == error("E_BROUND_2"), - '9731: bround(1.25,.1) == error("E_BROUND_2")'); - vrfy(bround(1.25,"x") == error("E_BROUND_2"), - '9732: bround(1.25,"x") == error("E_BROUND_2")'); - vrfy(bround(1.25,1,.1) == error("E_BROUND_3"), - '9733: bround(1.25,1,.1) == error("E_BROUND_3")'); - vrfy(sqrt("x") == error("E_SQRT_1"), - '9734: sqrt("x") == error("E_SQRT_1")'); - vrfy(sqrt(2,"x") == error("E_SQRT_2"), - '9735: sqrt(2,"x") == error("E_SQRT_2")'); - vrfy(sqrt(2,0) == error("E_SQRT_2"), - '9736: sqrt(2,0) == error("E_SQRT_2")'); - vrfy(sqrt(2,.1,.1) == error("E_SQRT_3"), - '9737: sqrt(2,.1,.1) == error("E_SQRT_3")'); - vrfy(root("x",3) == error("E_ROOT_1"), - '9738: root("x",3) == error("E_ROOT_1")'); - vrfy(root(3,"x") == error("E_ROOT_2"), - '9739: root(3,"x") == error("E_ROOT_2")'); - vrfy(root(3,-2) == error("E_ROOT_2"), - '9740: root(3,-2) == error("E_ROOT_2")'); - vrfy(root(3,0) == error("E_ROOT_2"), - '9741: root(3,0) == error("E_ROOT_2")'); - vrfy(root(3,.1) == error("E_ROOT_2"), - '9742: root(3,.1) == error("E_ROOT_2")'); - vrfy(root(3,2,"x") == error("E_ROOT_3"), - '9743: root(3,2,"x") == error("E_ROOT_3")'); - vrfy(root(3,2,0) == error("E_ROOT_3"), - '9744: root(3,2,0) == error("E_ROOT_3")'); - vrfy(norm("x") == error("E_NORM"), '9745: norm("x") == error("E_NORM")'); - vrfy(list() << 2 == error("E_SHIFT_1"), '9746: list() << 2 == error("E_SHIFT_1")'); - vrfy(1.5 << 2 == error("E_SHIFT_1"), '9747: 1.5 << 2 == error("E_SHIFT_1")'); - vrfy(3 << "x" == error("E_SHIFT_2"), '9748: 3 << "x" == error("E_SHIFT_2")'); - vrfy(3 << 1.5 == error("E_SHIFT_2"), '9749: 3 << 1.5 == error("E_SHIFT_2")'); - vrfy(3 << 2^31 == error("E_SHIFT_2"), '9750: 3 << 2^31 == error("E_SHIFT_2")'); - vrfy(scale("x",2) == error("E_SCALE_1"), - '9751: scale("x",2) == error("E_SCALE_1")'); - vrfy(scale(3,"x") == error("E_SCALE_2"), - '9752: scale(3,"x") == error("E_SCALE_2")'); - vrfy(scale(3,1.5) == error("E_SCALE_2"), - '9753: scale(3,1.5) == error("E_SCALE_2")'); - vrfy(scale(3,2^31) == error("E_SCALE_2"), - '9754: scale(3,2^31) == error("E_SCALE_2")'); - vrfy("x" ^ 3 == error("E_POWI_1"), '9755: "x" ^ 3 == error("E_POWI_1")'); - vrfy(2 ^ "x" == error("E_POWI_2"), '9756: 2 ^ "x" == error("E_POWI_2")'); - vrfy(2 ^ "2" == error("E_POWI_2"), '9757: 2 ^ "2" == error("E_POWI_2")'); - vrfy(power("x",2.1) == error("E_POWER_1"), - '9758: power("x",2.1) == error("E_POWER_1")'); - vrfy(power(2,"x") == error("E_POWER_2"), - '9759: power(2,"x") == error("E_POWER_2")'); - vrfy(power(2,2.1,"x") == error("E_POWER_3"), - '9760: power(2,2.1,"x") == error("E_POWER_3")'); - vrfy(quo("x",3) == error("E_QUO_1"), - '9761: quo("x",3) == error("E_QUO_1")'); - vrfy(quo(8,"x") == error("E_QUO_2"), - '9762: quo(8,"x") == error("E_QUO_2")'); - vrfy(quo(8,3,"x") == error("E_QUO_3"), - '9763: quo(8,3,"x") == error("E_QUO_3")'); - vrfy(quo(8,3,2.1) == error("E_QUO_3"), - '9764: quo(8,3,2.1) == error("E_QUO_3")'); - vrfy(mod("x",3) == error("E_MOD_1"), - '9765: mod("x",3) == error("E_MOD_1")'); - vrfy(mod(8,"x") == error("E_MOD_2"), - '9766: mod(8,"x") == error("E_MOD_2")'); - vrfy(mod(8,3,"x") == error("E_MOD_3"), - '9767: mod(8,3,"x") == error("E_MOD_3")'); - vrfy(mod(8,3,2.1) == error("E_MOD_3"), - '9768: mod(8,3,2.1) == error("E_MOD_3")'); - vrfy(sgn("x") == error("E_SGN"), - '9769: sgn("x") == error("E_SGN")'); - vrfy(abs("x") == error("E_ABS_1"), - '9770: abs("x") == error("E_ABS_1")'); - vrfy(abs(2+3i,"x") == error("E_ABS_2"), - '9771: abs(2+3i,"x") == error("E_ABS_2")'); - vrfy(abs(2+3i,0) == error("E_ABS_2"), - '9772: abs(2+3i,0) == error("E_ABS_2")'); - list1 = list(2,3,"x",4,5); - print '9773: list1 = list(2,3,"x",4,5)'; - vrfy(avg(list1) == error("E_ADD"), - '9774: avg(list1) == error("E_ADD")'); + strx = "x"; + print '9702: strx = "x"'; + e99 = error(99); + print '9703: e99 = error(99)'; + vrfy(1/0 == error("E_DIVBYZERO"), '9704: 1/0 == error("E_DIVBYZERO")'); + vrfy(0/0 == error("E_ZERODIVZERO"), '9705: 0/0 == error("E_ZERODIVZERO")'); + vrfy(2 + "x" == error("E_ADD"), '9706: 2 + "x" == error("E_ADD")'); + vrfy("x" - 2 == error("E_SUB"), '9707: "x" - 2 == error("E_SUB")'); + vrfy("x" * "y" == error("E_MUL"), '9708: "x" * "y" == error("E_MUL")'); + vrfy("x" / "y" == error("E_DIV"), '9709: "x" / "y" == error("E_DIV")'); + vrfy(-list(1) == error("E_NEG"), '9710: -list(1) == error("E_NEG")'); + vrfy("x"^2 == error("E_SQUARE"), '9711: "x"^2 == error("E_SQUARE")'); + vrfy(inverse("x")==error("E_INV"), '9712: inverse("x") == error("E_INV")'); + vrfy(++strx == error("E_INCV"), '9713: ++strx == error("E_INCV")'); + vrfy(strx == error("E_INCV"), '9714: strx == error("E_INCV")'); + strx = "x"; + print '9715: strx = "x"'; + vrfy(strx++ == "x", '9716: strx++ == "x"'); + vrfy(strx == error("E_INCV"), '9717: strx == error("E_INCV")'); + strx = "x"; + print '9718: strx = "x"'; + vrfy(--strx == error("E_DECV"), '9719: strx == error("E_DECV")'); + vrfy(int("x") == error("E_INT"), '9720: int("x") == error("E_INT")'); + vrfy(frac("x") == error("E_FRAC"), '9721: frac("x") == error("E_FRAC")'); + vrfy(conj("x") == error("E_CONJ"), '9722: conj("x") == error("E_CONJ")'); + vrfy(appr("x",.1) == error("E_APPR_1"), + '9723: appr("x",.1) == error("E_APPR_1")'); + vrfy(appr(1.27,.1i) == error("E_APPR_2"), + '9724: appr(1.27,.1i) == error("E_APPR_2")'); + vrfy(appr(1.27,.1,.1) == error("E_APPR_3"), + '9725: appr(1.27,.1,.1) == error("E_APPR_3")'); + vrfy(round("x") == error("E_ROUND_1"), + '9726: round("x") == error("E_ROUND_1")'); + vrfy(round(1.25,.1) == error("E_ROUND_2"), + '9727: round(1.25,.1) == error("E_ROUND_2")'); + vrfy(round(1.25,"x") == error("E_ROUND_2"), + '9728: round(1.25,"x") == error("E_ROUND_2")'); + vrfy(round(1.25,1,.1) == error("E_ROUND_3"), + '9729: round(1.25,1,.1) == error("E_ROUND_3")'); + vrfy(bround("x") == error("E_BROUND_1"), + '9730: bround("x") == error("E_BROUND_1")'); + vrfy(bround(1.25,.1) == error("E_BROUND_2"), + '9731: bround(1.25,.1) == error("E_BROUND_2")'); + vrfy(bround(1.25,"x") == error("E_BROUND_2"), + '9732: bround(1.25,"x") == error("E_BROUND_2")'); + vrfy(bround(1.25,1,.1) == error("E_BROUND_3"), + '9733: bround(1.25,1,.1) == error("E_BROUND_3")'); + vrfy(sqrt("x") == error("E_SQRT_1"), + '9734: sqrt("x") == error("E_SQRT_1")'); + vrfy(sqrt(2,"x") == error("E_SQRT_2"), + '9735: sqrt(2,"x") == error("E_SQRT_2")'); + vrfy(sqrt(2,0) == error("E_SQRT_2"), + '9736: sqrt(2,0) == error("E_SQRT_2")'); + vrfy(sqrt(2,.1,.1) == error("E_SQRT_3"), + '9737: sqrt(2,.1,.1) == error("E_SQRT_3")'); + vrfy(root("x",3) == error("E_ROOT_1"), + '9738: root("x",3) == error("E_ROOT_1")'); + vrfy(root(3,"x") == error("E_ROOT_2"), + '9739: root(3,"x") == error("E_ROOT_2")'); + vrfy(root(3,-2) == error("E_ROOT_2"), + '9740: root(3,-2) == error("E_ROOT_2")'); + vrfy(root(3,0) == error("E_ROOT_2"), + '9741: root(3,0) == error("E_ROOT_2")'); + vrfy(root(3,.1) == error("E_ROOT_2"), + '9742: root(3,.1) == error("E_ROOT_2")'); + vrfy(root(3,2,"x") == error("E_ROOT_3"), + '9743: root(3,2,"x") == error("E_ROOT_3")'); + vrfy(root(3,2,0) == error("E_ROOT_3"), + '9744: root(3,2,0) == error("E_ROOT_3")'); + vrfy(norm("x") == error("E_NORM"), '9745: norm("x") == error("E_NORM")'); + vrfy(list() << 2 == error("E_SHIFT_1"), '9746: list() << 2 == error("E_SHIFT_1")'); + vrfy(1.5 << 2 == error("E_SHIFT_1"), '9747: 1.5 << 2 == error("E_SHIFT_1")'); + vrfy(3 << "x" == error("E_SHIFT_2"), '9748: 3 << "x" == error("E_SHIFT_2")'); + vrfy(3 << 1.5 == error("E_SHIFT_2"), '9749: 3 << 1.5 == error("E_SHIFT_2")'); + vrfy(3 << 2^31 == error("E_SHIFT_2"), '9750: 3 << 2^31 == error("E_SHIFT_2")'); + vrfy(scale("x",2) == error("E_SCALE_1"), + '9751: scale("x",2) == error("E_SCALE_1")'); + vrfy(scale(3,"x") == error("E_SCALE_2"), + '9752: scale(3,"x") == error("E_SCALE_2")'); + vrfy(scale(3,1.5) == error("E_SCALE_2"), + '9753: scale(3,1.5) == error("E_SCALE_2")'); + vrfy(scale(3,2^31) == error("E_SCALE_2"), + '9754: scale(3,2^31) == error("E_SCALE_2")'); + vrfy("x" ^ 3 == error("E_POWI_1"), '9755: "x" ^ 3 == error("E_POWI_1")'); + vrfy(2 ^ "x" == error("E_POWI_2"), '9756: 2 ^ "x" == error("E_POWI_2")'); + vrfy(2 ^ "2" == error("E_POWI_2"), '9757: 2 ^ "2" == error("E_POWI_2")'); + vrfy(power("x",2.1) == error("E_POWER_1"), + '9758: power("x",2.1) == error("E_POWER_1")'); + vrfy(power(2,"x") == error("E_POWER_2"), + '9759: power(2,"x") == error("E_POWER_2")'); + vrfy(power(2,2.1,"x") == error("E_POWER_3"), + '9760: power(2,2.1,"x") == error("E_POWER_3")'); + vrfy(quo("x",3) == error("E_QUO_1"), + '9761: quo("x",3) == error("E_QUO_1")'); + vrfy(quo(8,"x") == error("E_QUO_2"), + '9762: quo(8,"x") == error("E_QUO_2")'); + vrfy(quo(8,3,"x") == error("E_QUO_3"), + '9763: quo(8,3,"x") == error("E_QUO_3")'); + vrfy(quo(8,3,2.1) == error("E_QUO_3"), + '9764: quo(8,3,2.1) == error("E_QUO_3")'); + vrfy(mod("x",3) == error("E_MOD_1"), + '9765: mod("x",3) == error("E_MOD_1")'); + vrfy(mod(8,"x") == error("E_MOD_2"), + '9766: mod(8,"x") == error("E_MOD_2")'); + vrfy(mod(8,3,"x") == error("E_MOD_3"), + '9767: mod(8,3,"x") == error("E_MOD_3")'); + vrfy(mod(8,3,2.1) == error("E_MOD_3"), + '9768: mod(8,3,2.1) == error("E_MOD_3")'); + vrfy(sgn("x") == error("E_SGN"), + '9769: sgn("x") == error("E_SGN")'); + vrfy(abs("x") == error("E_ABS_1"), + '9770: abs("x") == error("E_ABS_1")'); + vrfy(abs(2+3i,"x") == error("E_ABS_2"), + '9771: abs(2+3i,"x") == error("E_ABS_2")'); + vrfy(abs(2+3i,0) == error("E_ABS_2"), + '9772: abs(2+3i,0) == error("E_ABS_2")'); + list1 = list(2,3,"x",4,5); + print '9773: list1 = list(2,3,"x",4,5)'; + vrfy(avg(list1) == error("E_ADD"), + '9774: avg(list1) == error("E_ADD")'); - vrfy(iserror(e99)==99, '9775: iserror(e99) == 99'); - vrfy(e99 + 2 == e99, '9776: e99 + 2 == e99'); - vrfy(e99 - 2 == e99, '9777: e99 - 2 == e99'); - vrfy(e99 * 2 == e99, '9778: e99 * 2 == e99'); - vrfy(e99 / 2 == e99, '9779: e99 / 2 == e99'); - vrfy(e99 // 2 == e99, '9780: e99 // 2 == e99'); - vrfy(e99 % 2 == e99, '9781: e99 % 2 == e99'); - vrfy(e99 ^ 2 == e99, '9782: e99 ^ 2 == e99'); - vrfy(2 + e99 == e99, '9783: 2 + e99 == e99'); - vrfy(2 - e99 == e99, '9784: 2 - e99 == e99'); - vrfy(2 * e99 == e99, '9785: 2 * e99 == e99'); - vrfy(2 / e99 == e99, '9786: 2 / e99 == e99'); - vrfy(2 // e99 == e99, '9787: 2 // e99 == e99'); - vrfy(2 % e99 == e99, '9788: 2 % e99 == e99'); - vrfy(2 ^ e99 == e99, '9789: 2 ^ e99 == e99'); - vrfy(- e99 == e99, '9790: -e99 == e99'); - vrfy(inverse(e99) == e99, '9791: inverse(e99) == e99'); - vrfy(++e99 == e99, '9792: ++e99 == e99'); - vrfy(--e99 == e99, '9793: --e99 == e99'); - vrfy(int(e99) == e99, '9794: int(e99) == e99'); - vrfy(frac(e99) == e99, '9795: frac(e99) == e99'); - vrfy(conj(e99) == e99, '9796: conj(e99) == e99'); - vrfy(norm(e99) == e99, '9797: norm(e99) == e99'); - vrfy(sgn(e99) == e99, '9798: sgn(e99) == e99'); - vrfy(appr(e99,1,0) == e99, '9799: appr(e99,1,0) == e99'); - vrfy(round(e99) == e99, '9800: round(e99) == e99'); - vrfy(bround(e99) == e99, '9801: bround(e99) == e99'); - vrfy(sqrt(e99) == e99, '9802: sqrt(e99) == e99'); - print '9803: a = newerror("alpha")'; - a = newerror("alpha"); - print '9804: b = newerror("beta")'; - b = newerror("beta"); - print '9805: c = newerror("alpha")'; - c = newerror("alpha"); - vrfy(a == c, '9806: a == c'); - vrfy(strerror(a) == "alpha", '9807: strerror(a) == "alpha"'); - print '9808: n = iserror(a)'; - n = iserror(a); - vrfy(a == error(n), '9809: a == error(n)'); - vrfy(newerror() == newerror("???"), - '9810: newerror() == newerror("???")'); - vrfy(newerror("") == newerror(), - '9811: newerror("") == newerror()'); - e9999 = error("E_9999"); - print '9812: e9999 = error("E_9999")'; - vrfy(errno() == 9999, '9813: errno() == 9999'); - vrfy(error() == e9999, '9814: error() == e9999'); - /* test 3715 removed due to non-portable strerror() output */ - x = newerror("Alpha"); - print '9816: x = newerror("Alpha")'; - n = iserror(x); - print '9817: n = iserror(x)'; - vrfy(errno() == n, '9818: errno() == n'); - vrfy(error() == x, '9819: error() == x'); - vrfy(strerror() == "Alpha", '9820: strerror() == "Alpha"'); - vrfy(errno("E_9999") == n, '9821: errno("E_9999") == n'); - vrfy(errno() == 9999, '9822: errno() == 9999'); - vrfy(error() == e9999, '9823: error() == e9999'); - /* test 3724 removed due to non-portable strerror() output */ - a = 1/0; - print '9825: a = 1/0'; - vrfy(strerror() == "Division by zero", - '9826: strerror() == "Division by zero"'); - n = 8191; - print '9827: n = 8191'; - print '9828: test removed due to non-portable strerror() output'; - vrfy(tan(2e9i) == error("E_TAN_5"), '9829: tan(2e9i) == error("E_TAN_5")'); - vrfy(cot(2e9i) == error("E_COT_6"), '9830: cot(2e9i) == error("E_COT_6")'); - vrfy(sec(2e9i) == error("E_SEC_5"), '9831: sec(2e9i) == error("E_SEC_5")'); - vrfy(csc(2e9i) == error("E_CSC_6"), '9832: csc(2e9i) == error("E_CSC_6")'); + vrfy(iserror(e99)==99, '9775: iserror(e99) == 99'); + vrfy(e99 + 2 == e99, '9776: e99 + 2 == e99'); + vrfy(e99 - 2 == e99, '9777: e99 - 2 == e99'); + vrfy(e99 * 2 == e99, '9778: e99 * 2 == e99'); + vrfy(e99 / 2 == e99, '9779: e99 / 2 == e99'); + vrfy(e99 // 2 == e99, '9780: e99 // 2 == e99'); + vrfy(e99 % 2 == e99, '9781: e99 % 2 == e99'); + vrfy(e99 ^ 2 == e99, '9782: e99 ^ 2 == e99'); + vrfy(2 + e99 == e99, '9783: 2 + e99 == e99'); + vrfy(2 - e99 == e99, '9784: 2 - e99 == e99'); + vrfy(2 * e99 == e99, '9785: 2 * e99 == e99'); + vrfy(2 / e99 == e99, '9786: 2 / e99 == e99'); + vrfy(2 // e99 == e99, '9787: 2 // e99 == e99'); + vrfy(2 % e99 == e99, '9788: 2 % e99 == e99'); + vrfy(2 ^ e99 == e99, '9789: 2 ^ e99 == e99'); + vrfy(- e99 == e99, '9790: -e99 == e99'); + vrfy(inverse(e99) == e99, '9791: inverse(e99) == e99'); + vrfy(++e99 == e99, '9792: ++e99 == e99'); + vrfy(--e99 == e99, '9793: --e99 == e99'); + vrfy(int(e99) == e99, '9794: int(e99) == e99'); + vrfy(frac(e99) == e99, '9795: frac(e99) == e99'); + vrfy(conj(e99) == e99, '9796: conj(e99) == e99'); + vrfy(norm(e99) == e99, '9797: norm(e99) == e99'); + vrfy(sgn(e99) == e99, '9798: sgn(e99) == e99'); + vrfy(appr(e99,1,0) == e99, '9799: appr(e99,1,0) == e99'); + vrfy(round(e99) == e99, '9800: round(e99) == e99'); + vrfy(bround(e99) == e99, '9801: bround(e99) == e99'); + vrfy(sqrt(e99) == e99, '9802: sqrt(e99) == e99'); + print '9803: a = newerror("alpha")'; + a = newerror("alpha"); + print '9804: b = newerror("beta")'; + b = newerror("beta"); + print '9805: c = newerror("alpha")'; + c = newerror("alpha"); + vrfy(a == c, '9806: a == c'); + vrfy(strerror(a) == "alpha", '9807: strerror(a) == "alpha"'); + print '9808: n = iserror(a)'; + n = iserror(a); + vrfy(a == error(n), '9809: a == error(n)'); + vrfy(newerror() == newerror("???"), + '9810: newerror() == newerror("???")'); + vrfy(newerror("") == newerror(), + '9811: newerror("") == newerror()'); + e9999 = error("E_9999"); + print '9812: e9999 = error("E_9999")'; + vrfy(errno() == 9999, '9813: errno() == 9999'); + vrfy(error() == e9999, '9814: error() == e9999'); + /* test 3715 removed due to non-portable strerror() output */ + x = newerror("Alpha"); + print '9816: x = newerror("Alpha")'; + n = iserror(x); + print '9817: n = iserror(x)'; + vrfy(errno() == n, '9818: errno() == n'); + vrfy(error() == x, '9819: error() == x'); + vrfy(strerror() == "Alpha", '9820: strerror() == "Alpha"'); + vrfy(errno("E_9999") == n, '9821: errno("E_9999") == n'); + vrfy(errno() == 9999, '9822: errno() == 9999'); + vrfy(error() == e9999, '9823: error() == e9999'); + /* test 3724 removed due to non-portable strerror() output */ + a = 1/0; + print '9825: a = 1/0'; + vrfy(strerror() == "Division by zero", + '9826: strerror() == "Division by zero"'); + n = 8191; + print '9827: n = 8191'; + print '9828: test removed due to non-portable strerror() output'; + vrfy(tan(2e9i) == error("E_TAN_5"), '9829: tan(2e9i) == error("E_TAN_5")'); + vrfy(cot(2e9i) == error("E_COT_6"), '9830: cot(2e9i) == error("E_COT_6")'); + vrfy(sec(2e9i) == error("E_SEC_5"), '9831: sec(2e9i) == error("E_SEC_5")'); + vrfy(csc(2e9i) == error("E_CSC_6"), '9832: csc(2e9i) == error("E_CSC_6")'); - /* errmax and errcount should be bumped up the 148 errors above */ - print '9833: errcount():', errcount(); - print '9833: ecnt:', ecnt; - vrfy(errcount() == ecnt, '9835: errcount() == ecnt'); + /* errmax and errcount should be bumped up the 148 errors above */ + print '9833: errcount():', errcount(); + print '9833: ecnt:', ecnt; + vrfy(errcount() == ecnt, '9835: errcount() == ecnt'); - print '9836: Ending test_error'; + print '9836: Ending test_error'; } print; print '9699: parsed test_error()'; @@ -10204,150 +10204,150 @@ return test_error(); * test 99dd: define vrfy_errsym and test E_STRING in error, errno, strerror, errsym */ print; -print '9900: Prep to test of error("E_STRING") errno("E_STRING"), strerror("E_STRING") and errsym("E_STRING")'; +print '9900: Prep to test of error("E_STRING") errno("E_STRING"), strerror("E_STRING") and errsym("E_STRING")'; /* * vrfy_errsym - verify errsym builtin function for valid errnum codes and errsym "E_STRING" strings */ define vrfy_errsym(testnum, errnum, e_string) { - local res_errnum; /* errnum result of errsym(e_string) */ - local res_errsym; /* errnum result of errsym(errnum) */ + local res_errnum; /* errnum result of errsym(e_string) */ + local res_errsym; /* errnum result of errsym(errnum) */ - /* - * firewall - */ - if (!isint(testnum) || testnum <= 0) { - print '**** Non-true result (' : testnum : \ - '): invalid vrfy_errsym testnum (must be int > 0) 1st arg:', testnum; - ++prob; - return; - } - if (!isint(errnum) || errnum < 0) { - print '**** Non-true result (' : testnum : \ - '): invalid vrfy_errsym errnum (must be int >= 0) 2nd arg:', errnum; - ++prob; - return; - } - if (!isstr(e_string) || strlen(e_string) < 3 || strncmp(e_string, "E_", 2) != 0) { - print '**** Non-true result (' : testnum : \ - '): invalid vrfy_errsym e_string (must be string starting with E_) 3rd arg:', e_string; - ++prob; - return; - } + /* + * firewall + */ + if (!isint(testnum) || testnum <= 0) { + print '**** Non-true result (' : testnum : \ + '): invalid vrfy_errsym testnum (must be int > 0) 1st arg:', testnum; + ++prob; + return; + } + if (!isint(errnum) || errnum < 0) { + print '**** Non-true result (' : testnum : \ + '): invalid vrfy_errsym errnum (must be int >= 0) 2nd arg:', errnum; + ++prob; + return; + } + if (!isstr(e_string) || strlen(e_string) < 3 || strncmp(e_string, "E_", 2) != 0) { + print '**** Non-true result (' : testnum : \ + '): invalid vrfy_errsym e_string (must be string starting with E_) 3rd arg:', e_string; + ++prob; + return; + } - /* - * try errsym("E_STRING") - */ - res_errnum = errsym(e_string); - if (!isint(res_errnum)) { - print '**** Non-true result (' : testnum : \ - '): errsym("' : e_string : '") returned non-integer:', res_errnum; - ++prob; - return; - } + /* + * try errsym("E_STRING") + */ + res_errnum = errsym(e_string); + if (!isint(res_errnum)) { + print '**** Non-true result (' : testnum : \ + '): errsym("' : e_string : '") returned non-integer:', res_errnum; + ++prob; + return; + } - /* - * try errsym(errnum) - */ - res_errsym = errsym(errnum); - if (!isstr(res_errsym)) { - print '**** Non-true result (' : testnum : \ - '): errsym(' : errnum : ') returned non-string:', res_errsym; - ++prob; - return; - } + /* + * try errsym(errnum) + */ + res_errsym = errsym(errnum); + if (!isstr(res_errsym)) { + print '**** Non-true result (' : testnum : \ + '): errsym(' : errnum : ') returned non-string:', res_errsym; + ++prob; + return; + } - /* - * compare errnum and res_errnum - */ - if (errnum != res_errnum) { - print '**** Non-true result (' : testnum : \ - '): vrfy_errsym errnum 2nd arg:', errnum, '!= errsym("' : e_string : '"):', res_errnum; - ++prob; - return; - } + /* + * compare errnum and res_errnum + */ + if (errnum != res_errnum) { + print '**** Non-true result (' : testnum : \ + '): vrfy_errsym errnum 2nd arg:', errnum, '!= errsym("' : e_string : '"):', res_errnum; + ++prob; + return; + } - /* - * compare errsym and res_errsym - */ - if (strcmp(e_string, res_errsym) != 0) { - print '**** Non-true result (' : testnum : \ - '): vrfy_errsym errsym 3rd arg: "' : e_string : '" != errsym(' : errnum : '): "' : res_errsym : '"'; - ++prob; - return; - } + /* + * compare errsym and res_errsym + */ + if (strcmp(e_string, res_errsym) != 0) { + print '**** Non-true result (' : testnum : \ + '): vrfy_errsym errsym 3rd arg: "' : e_string : '" != errsym(' : errnum : '): "' : res_errsym : '"'; + ++prob; + return; + } - /* - * report success - */ - print testnum : ': vrfy_errsym(' : testnum : ',', errnum : ', "' : e_string : '") passed'; - return; + /* + * report success + */ + print testnum : ': vrfy_errsym(' : testnum : ',', errnum : ', "' : e_string : '") passed'; + return; } -print '9901: parsed vrfy_errsym()'; +print '9901: parsed vrfy_errsym()'; ++ecnt,; -print '9902: ++ecnt'; +print '9902: ++ecnt'; res = error("E_ADD"); -print '9903: res = error("E_ADD")'; +print '9903: res = error("E_ADD")'; vrfy(iserror(res) == errsym("E_ADD"), - '9904: iserror(res) == errsym("E_ADD")'); + '9904: iserror(res) == errsym("E_ADD")'); vrfy(errno("E_ADD") == errsym("E_ADD"), - '9905: errno("E_ADD") == errsym("E_ADD")'); + '9905: errno("E_ADD") == errsym("E_ADD")'); vrfy(errno() == errsym("E_ADD"), - '9906: errno() == errsym("E_ADD")'); + '9906: errno() == errsym("E_ADD")'); vrfy(strerror("E_ADD") == "Bad arguments for +", - '9907: strerror("E_ADD") == "Bad arguments for +"'); + '9907: strerror("E_ADD") == "Bad arguments for +"'); vrfy(errsym("E__NONE") == 0, - '9909: errsym("E__NONE") == 0'); + '9909: errsym("E__NONE") == 0'); vrfy_errsym( - 9910, 0, "E_0"); + 9910, 0, "E_0"); vrfy(errsym("E__BASE") == 10000, - '9911: errsym("E__BASE") == 10000'); + '9911: errsym("E__BASE") == 10000'); vrfy_errsym( - 9912, 10000, "E__BASE"); + 9912, 10000, "E__BASE"); vrfy(errsym("E__HIGHEST") > errsym("E__BASE"), - '9913: errsym("E__HIGHEST") > errsym("E__BASE")'); + '9913: errsym("E__HIGHEST") > errsym("E__BASE")'); vrfy(errsym("E__USERDEF") > errsym("E__HIGHEST"), - '9914: errsym("E__USERDEF") > errsym("E__HIGHEST")'); + '9914: errsym("E__USERDEF") > errsym("E__HIGHEST")'); vrfy(errsym("E__USERDEF") == 20000, - '9915: errsym("E__USERDEF") == 20000'); + '9915: errsym("E__USERDEF") == 20000'); vrfy_errsym( - 9916, 20000, "E_20000"); + 9916, 20000, "E_20000"); vrfy(errsym("E__USERMAX") > errsym("E__USERDEF"), - '9917: errsym("E__USERMAX") > errsym("E__USERDEF")'); + '9917: errsym("E__USERMAX") > errsym("E__USERDEF")'); vrfy(errsym("E__USERMAX") == 32767, - '9918: errsym("E__USERMAX") == 32767'); + '9918: errsym("E__USERMAX") == 32767'); vrfy_errsym( - 9919, 32767, "E_32767"); + 9919, 32767, "E_32767"); vrfy_errsym( - 9920, 1, "E_1"); + 9920, 1, "E_1"); vrfy_errsym( - 9921, 7, "E_7"); + 9921, 7, "E_7"); vrfy_errsym( - 9922, 10, "E_10"); + 9922, 10, "E_10"); vrfy_errsym( - 9923, 31, "E_31"); + 9923, 31, "E_31"); vrfy_errsym( - 9924, 100, "E_100"); + 9924, 100, "E_100"); vrfy_errsym( - 9925, 127, "E_127"); + 9925, 127, "E_127"); vrfy_errsym( - 9926, 1000, "E_1000"); + 9926, 1000, "E_1000"); vrfy_errsym( - 9927, 2203, "E_2203"); + 9927, 2203, "E_2203"); vrfy_errsym( - 9928, 19937, "E_19937"); + 9928, 19937, "E_19937"); vrfy_errsym( - 9929, 23209, "E_23209"); + 9929, 23209, "E_23209"); -print '9930: ending test of error("E_STRING") errno("E_STRING"), strerror("E_STRING") and errsym("E_STRING")'; +print '9930: ending test of error("E_STRING") errno("E_STRING"), strerror("E_STRING") and errsym("E_STRING")'; /* @@ -10358,7 +10358,7 @@ print '9930: ending test of error("E_STRING") errno("E_STRING"), strerror("E_STR * that would impact user code, one or more of the tests (test 10ddd) will fail. */ print; -print '10000: verify E_STRING values for calc computation error codes'; +print '10000: verify E_STRING values for calc computation error codes'; vrfy_errsym(10001, 10001, "E_DIVBYZERO"); vrfy_errsym(10002, 10002, "E_ZERODIVZERO"); vrfy_errsym(10003, 10003, "E_ADD"); @@ -10969,7 +10969,7 @@ vrfy_errsym(10605, 10605, "E_CIS_3"); /* NOTE: Reserve thru test 10998 for calc computation error codes */ /* ************************************************************** */ -print '10999: End of E_STRING values for calc computation error codes'; +print '10999: End of E_STRING values for calc computation error codes'; /* ************************************************* */ @@ -10993,11 +10993,11 @@ print; print '99993: Final regression test suite cleanup and report test results'; define count_errors() { - if (prob == 0) { - print "99997: passed all tests /\\../\\"; - } else { - print "****", prob, "error(s) found \\/++\\/"; - } + if (prob == 0) { + print "99997: passed all tests /\\../\\"; + } else { + print "****", prob, "error(s) found \\/++\\/"; + } } print '99994: parsed count_errors()'; freeredc(); @@ -11008,4 +11008,4 @@ print '99996: freestatics()'; return count_errors(); freeglobals(); print '99998: freeglobals()'; -print '99999: Ending regression tests'; /* !!! ==> MUST BE LAST LINE <== !!! */ +print '99999: Ending regression tests'; /* !!! ==> MUST BE LAST LINE <== !!! */ diff --git a/cal/repeat.cal b/cal/repeat.cal index 56ccad4..65c43c4 100644 --- a/cal/repeat.cal +++ b/cal/repeat.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2003/01/05 00:00:01 - * File existed as early as: 2003 + * Under source code control: 2003/01/05 00:00:01 + * File existed as early as: 2003 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -29,18 +29,18 @@ * repeat - return the value of a repeated set of digits * * usage: - * repeat(digit_set, repeat_count) + * repeat(digit_set, repeat_count) */ define repeat(digit_set, repeat_count) { - local digit_count; /* digits in the digit_set */ + local digit_count; /* digits in the digit_set */ /* firewall */ if (!isint(digit_set) || digit_set <= 0) { - quit "digit set must be an integer > 0"; + quit "digit set must be an integer > 0"; } if (!isint(repeat_count) || repeat_count <= 0) { - quit "repeat count must be an integer > 0"; + quit "repeat count must be an integer > 0"; } /* return repeated set of digits */ diff --git a/cal/screen.cal b/cal/screen.cal index 9c051f6..a6c37ec 100644 --- a/cal/screen.cal +++ b/cal/screen.cal @@ -6,7 +6,7 @@ * This file is not covered under version 2.1 of the GNU LGPL. * This file is covered under "The unlicense": * - * https://unlicense.org + * https://unlicense.org * * In particular: * @@ -35,8 +35,8 @@ * * For more information, please refer to * - * Under source code control: 2006/03/08 05:54:09 - * File existed as early as: 2006 + * Under source code control: 2006/03/08 05:54:09 + * File existed as early as: 2006 */ up = CUU ="\e[A"; diff --git a/cal/seedrandom.cal b/cal/seedrandom.cal index 15ab49f..dae8e3e 100644 --- a/cal/seedrandom.cal +++ b/cal/seedrandom.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,18 +17,18 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1996/01/01 08:21:00 - * File existed as early as: 1996 + * Under source code control: 1996/01/01 08:21:00 + * File existed as early as: 1996 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * The period of Blum generators with modulus 'n=p*q' (where p and * q are primes 3 mod 4) is: * - * lambda(n) = lcm(factors of p-1 & q-1) + * lambda(n) = lcm(factors of p-1 & q-1) * * One can construct a generator with a maximal period when * 'p' and 'q' have the fewest possible factors in common. @@ -38,118 +38,118 @@ * such primes. * * given: - * seed1 - a large random value (at least 10^20 and perhaps < 10^314) - * seed2 - a large random value (at least 10^20 and perhaps < 10^314) - * size - min Blum modulus as a power of 2 (at least 32, perhaps >= 512) - * trials - number of ptest() trials (default 25) + * seed1 - a large random value (at least 10^20 and perhaps < 10^314) + * seed2 - a large random value (at least 10^20 and perhaps < 10^314) + * size - min Blum modulus as a power of 2 (at least 32, perhaps >= 512) + * trials - number of ptest() trials (default 25) * * returns: - * the previous random state + * the previous random state * * NOTE: The [10^20, 10^314) range comes from the fact that the 13th internal - * modulus is ~10^315. We want the lower bound seed to be reasonably big. + * modulus is ~10^315. We want the lower bound seed to be reasonably big. */ define seedrandom(seed1, seed2, size, trials) { - local p; /* first Blum prime */ - local fp; /* prime co-factor of p-1 */ - local sp; /* min bit size of p */ - local q; /* second Blum prime */ - local fq; /* prime co-factor of q-1 */ - local sq; /* min bit size of q */ - local n; /* Blum modulus */ - local binsize; /* smallest power of 2 > n=p*q */ - local r; /* initial quadratic residue */ - local random_state; /* the initial rand state */ - local random_junk; /* rand state that is not needed */ - local old_state; /* old random state to return */ + local p; /* first Blum prime */ + local fp; /* prime co-factor of p-1 */ + local sp; /* min bit size of p */ + local q; /* second Blum prime */ + local fq; /* prime co-factor of q-1 */ + local sq; /* min bit size of q */ + local n; /* Blum modulus */ + local binsize; /* smallest power of 2 > n=p*q */ + local r; /* initial quadratic residue */ + local random_state; /* the initial rand state */ + local random_junk; /* rand state that is not needed */ + local old_state; /* old random state to return */ - /* - * firewall - */ - if (!isint(seed1)) { - quit "1st arg (seed1) is not an int"; - } - if (!isint(seed2)) { - quit "2nd arg (seed2) is not an int"; - } - if (!isint(size)) { - quit "3rd arg (size) is not an int"; - } - if (!isint(trials)) { - trials = 25; - } - if (digits(seed1) <= 20) { - quit "1st arg (seed1) must be > 10^20 and perhaps < 10^314"; - } - if (digits(seed2) <= 20) { - quit "2nd arg (seed2) must be > 10^20 and perhaps < 10^314"; - } - if (size < 32) { - quit "3rd arg (size) needs to be >= 32 (perhaps >= 512)"; - } - if (trials < 1) { - quit "4th arg (trials) must be > 0"; - } + /* + * firewall + */ + if (!isint(seed1)) { + quit "1st arg (seed1) is not an int"; + } + if (!isint(seed2)) { + quit "2nd arg (seed2) is not an int"; + } + if (!isint(size)) { + quit "3rd arg (size) is not an int"; + } + if (!isint(trials)) { + trials = 25; + } + if (digits(seed1) <= 20) { + quit "1st arg (seed1) must be > 10^20 and perhaps < 10^314"; + } + if (digits(seed2) <= 20) { + quit "2nd arg (seed2) must be > 10^20 and perhaps < 10^314"; + } + if (size < 32) { + quit "3rd arg (size) needs to be >= 32 (perhaps >= 512)"; + } + if (trials < 1) { + quit "4th arg (trials) must be > 0"; + } - /* - * determine the search parameters - */ - ++size; /* convert power of 2 to bit length */ - sp = int((size/2)-(size*0.03)+1); - sq = size - sp; + /* + * determine the search parameters + */ + ++size; /* convert power of 2 to bit length */ + sp = int((size/2)-(size*0.03)+1); + sq = size - sp; - /* - * find the first Blum prime - */ - random_state = srandom(seed1, 13); - do { - do { - fp = nextcand(2^sp+randombit(sp), 1, 1, 3, 4); - p = 2*fp+1; - } while (ptest(p,1,0) == 0); - } while(ptest(p, trials) == 0 || ptest(fp, trials) == 0); - if (config("resource_debug") & 8) { - print "/* 1st Blum prime */ p=", p; - } + /* + * find the first Blum prime + */ + random_state = srandom(seed1, 13); + do { + do { + fp = nextcand(2^sp+randombit(sp), 1, 1, 3, 4); + p = 2*fp+1; + } while (ptest(p,1,0) == 0); + } while(ptest(p, trials) == 0 || ptest(fp, trials) == 0); + if (config("resource_debug") & 8) { + print "/* 1st Blum prime */ p=", p; + } - /* - * find the 2nd Blum prime - */ - random_junk = srandom(seed2, 13); - do { - do { - fq = nextcand(2^sq+randombit(sq), 1, 1, 3, 4); - q = 2*fq+1; - } while (ptest(q,1,0) == 0); - } while(ptest(q, trials) == 0 || ptest(fq, trials) == 0); - if (config("resource_debug") & 8) { - print "/* 2nd Blum prime */ q=", q; - } + /* + * find the 2nd Blum prime + */ + random_junk = srandom(seed2, 13); + do { + do { + fq = nextcand(2^sq+randombit(sq), 1, 1, 3, 4); + q = 2*fq+1; + } while (ptest(q,1,0) == 0); + } while(ptest(q, trials) == 0 || ptest(fq, trials) == 0); + if (config("resource_debug") & 8) { + print "/* 2nd Blum prime */ q=", q; + } - /* - * seed the Blum generator - */ - n = p*q; /* the Blum modulus */ - binsize = highbit(n)+1; /* smallest power of 2 > p*q */ - r = pmod(rand(1< /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ strcpy("", "") == "" @@ -49,7 +49,7 @@ strncpy("ab", "xyz", 3) == "xy" strcmp("", "") == 0 strcmp("", "a") == -1 strcmp("\n", "\n") == 0 -strcmp("\0", "") == 1 ## '\0' treated like other characters +strcmp("\0", "") == 1 ## '\0' treated like other characters strcmp("ab", "") == 1 strcmp("ab", "a") == 1 strcmp("ab", "ab") == 0 @@ -123,15 +123,15 @@ substr("abcd",5,1) == "" substr("a\0c\0",2,2) == "\0c" ## '\0' treated like other characters substr("a\0c\0",2,3) == "\0c\0" -#"" == 0 ## # operator counts number of bits +#"" == 0 ## # operator counts number of bits #"\0" == 0 # "a" == 3 - # "ab" == 6 ## white space ignored + # "ab" == 6 ## white space ignored # "abc" == 10 # 27 == 4 # 0b1010111011 == 7 -7 # 9 == 2 ## 7 # 9 = abs(7 - 9) +7 # 9 == 2 ## 7 # 9 = abs(7 - 9) 3/4 # 2/3 == 1/12 a = 5, a #= 2, a == 3 @@ -181,9 +181,9 @@ protect(set8700_A[2]) == 1024 protect(set8700_A[2][0], 512), protect(set8700_A[2][0]) == 1536 ## Testing simple assignment of matrix -set8700_B = set8700_A, protect(set8700_B) == 1024 ## protect(set8700_A) copied -protect(set8700_B[2]) == 1024 ## protect(set8700_A[2]) copied -protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied +set8700_B = set8700_A, protect(set8700_B) == 1024 ## protect(set8700_A) copied +protect(set8700_B[2]) == 1024 ## protect(set8700_A[2]) copied +protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied ## copying matrix to list set8700_B = list(5,6,7), protect(set8700_B) == 1024 @@ -192,18 +192,18 @@ protect(set8700_B[2]) == 0 protect(set8700_A,0), protect(set8700_A) == 0 copy(set8700_A,set8700_B), set8700_B[0] == 1 && set8700_B[1] == 2 set8700_B[2] == list(3,4) -protect(set8700_B) == 1024 ## protect(set8700_A) not copied -protect(set8700_B[0]) == 1024 ## protect(set8700_A[0]) copied -protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied +protect(set8700_B) == 1024 ## protect(set8700_A) not copied +protect(set8700_B[0]) == 1024 ## protect(set8700_A[0]) copied +protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied ## copying matrix to matrix set8700_B = mat[3], protect(set8700_B) == 1024 protect(set8700_B[2]) == 0 copy(set8700_A,set8700_B), set8700_B[0] == 1 && set8700_B[1] == 2 set8700_B[2] == list(3,4) -protect(set8700_B) == 1024 ## protect(set8700_A) not copied -protect(set8700_B[0]) == 1024 ## protect(set8700_A[0]) copied -protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied +protect(set8700_B) == 1024 ## protect(set8700_A) not copied +protect(set8700_B[0]) == 1024 ## protect(set8700_A[0]) copied +protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied ## Testing list protection set8700_A = list(1, 2, list(3,4)), 1 @@ -212,18 +212,18 @@ protect(set8700_A[2]) == 1024 protect(set8700_A[2][0], 512), protect(set8700_A[2][0]) == 1536 ## Simple assignment of list -set8700_B = set8700_A, protect(set8700_B) == 1024 ## protect(set8700_A) copied -protect(set8700_B[2]) == 1024 ## protect(set8700_A[2]) copied -protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied +set8700_B = set8700_A, protect(set8700_B) == 1024 ## protect(set8700_A) copied +protect(set8700_B[2]) == 1024 ## protect(set8700_A[2]) copied +protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied ## Copying list to list set8700_B = list(5,6,7), protect(set8700_B) == 1024 protect(set8700_B[2]) == 0 copy(set8700_A,set8700_B), set8700_B[0] == 1 && set8700_B[1] == 2 set8700_B[2] == list(3,4) -protect(set8700_B) == 1024 ## protect(set8700_A) not copied -protect(set8700_B[0]) == 1024 ## protect(set8700_A[0]) copied -protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied +protect(set8700_B) == 1024 ## protect(set8700_A) not copied +protect(set8700_B[0]) == 1024 ## protect(set8700_A[0]) copied +protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied ## Copying list to matrix set8700_B = mat[3], protect(set8700_B) == 1024 @@ -231,8 +231,8 @@ protect(set8700_B[2]) == 0 copy(set8700_A,set8700_B), set8700_B[0] == 1 && set8700_B[1] == 2 set8700_B[2] == list(3,4) protect(set8700_B) == 1024 -protect(set8700_B[0]) == 1024 ## protect(set8700_A[0]) copied -protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied +protect(set8700_B[0]) == 1024 ## protect(set8700_A[0]) copied +protect(set8700_B[2][0]) == 1536 ## protect(set8700_A[2][0]) copied ## Protecting one element of a list set8700_A = list(1,4,3,2), protect(set8700_A[1]) == 0 @@ -241,16 +241,16 @@ protect(set8700_A[1], 1024), protect(set8700_A[1]) == 1024 ## Testing sort set8700_A = sort(set8700_A), set8700_A == list(1,2,3,4) protect(set8700_A[1]) == 0 -protect(set8700_A[3]) == 1024 ## status of 4 +protect(set8700_A[3]) == 1024 ## status of 4 ## Testings reverse set8700_A = reverse(set8700_A), set8700_A == list(4,3,2,1) -protect(set8700_A[0]) == 1024 ## status of 4 +protect(set8700_A[0]) == 1024 ## status of 4 ## Testing swap swap(set8700_A[0], set8700_A[1]), set8700_A == list(3,4,2,1) -protect(set8700_A[0]) == 0 ## status moved -protect(set8700_A[1]) == 1024 ## 4 retains protection +protect(set8700_A[0]) == 0 ## status moved +protect(set8700_A[1]) == 1024 ## 4 retains protection ## Testing list with protected list argument protect(set8700_A, 0), protect(set8700_A) == 0 @@ -258,23 +258,23 @@ protect(set8700_A, 512), protect(set8700_A) == 512 protect(set8700_A[1]) == 1024 set8700_L = list(1,set8700_A,3), protect(set8700_L) == 0 protect(set8700_L[0]) == 0 -protect(set8700_L[1]) == 512 ## protect(set8700_A) copied -protect(set8700_L[1][1]) == 1024 ## protect(set8700_A[1]) copied +protect(set8700_L[1]) == 512 ## protect(set8700_A) copied +protect(set8700_L[1][1]) == 1024 ## protect(set8700_A[1]) copied ## Testing list with "initialization" set8700_L = list(1,2,3), protect(set8700_L) == 0 -protect(set8700_L[0]) | protect(set8700_L[1]) | protect(set8700_L[2]) == 0 ## All zero +protect(set8700_L[0]) | protect(set8700_L[1]) | protect(set8700_L[2]) == 0 ## All zero set8700_L = {1,set8700_A}, set8700_L[1] == set8700_A -protect(set8700_L[1]) == 512 ## protect(set8700_A) copied -protect(set8700_L[1][1]) == 1024 ## protect(set8700_A[1]) copied -set8700_L[1] = 2, protect(set8700_L[1]) == 512 ## Not changed +protect(set8700_L[1]) == 512 ## protect(set8700_A) copied +protect(set8700_L[1][1]) == 1024 ## protect(set8700_A[1]) copied +set8700_L[1] = 2, protect(set8700_L[1]) == 512 ## Not changed ## Testing matrix with "initialization" set8700_M = mat[3] = {1,set8700_A}, protect(set8700_M) == 0 protect(set8700_M[0]) == 0 -protect(set8700_M[1]) == 512 ## protect(set8700_A) copied +protect(set8700_M[1]) == 512 ## protect(set8700_A) copied protect(set8700_M[2]) == 0 -protect(set8700_M[1][1]) == 1024 ## protect(set8700_A[1]) copied +protect(set8700_M[1][1]) == 1024 ## protect(set8700_A[1]) copied ## Testing push, pop, append, remove set8700_A = list(1,2), protect(set8700_A,0,1), protect(set8700_A[0]) == 0 @@ -319,12 +319,12 @@ set8700_x == 7 set8700_x-- == error(10388) protect(set8700_A,0), protect(set8700_A,16), 1 -set8700_A = "abcdef", protect(set8700_A) == 16 ## No copy to set8700_A +set8700_A = "abcdef", protect(set8700_A) == 16 ## No copy to set8700_A protect(set8700_B,0), set8700_B = "xyz", protect(set8700_B) == 0 copy(set8700_B, set8700_A) == error(10226) -set8700_A == "abcdef" ## set8700_A not changed +set8700_A == "abcdef" ## set8700_A not changed protect(set8700_A,0), copy(set8700_B,set8700_A), set8700_A == "xyzdef" -protect(set8700_B,128), protect(set8700_B) == 128 ## No copy from set8700_B +protect(set8700_B,128), protect(set8700_B) == 128 ## No copy from set8700_B copy(set8700_B,set8700_A,,,3) == error(10225) set8700_A == "xyzdef" protect(set8700_B,0), copy(set8700_B,set8700_A,,,3), set8700_A == "xyzxyz" @@ -354,7 +354,7 @@ set8700_x = 7, protect(set8700_x,0), protect(set8700_x, 512), 1 set8700_A = {set8700_x,,set8700_x}, protect(set8700_A[0]) == 1536 protect(set8700_A[1]) == 0 protect(set8700_A[2]) == 512 -protect(set8700_A,16), protect(set8700_A) == 16 ## No copy to +protect(set8700_A,16), protect(set8700_A) == 16 ## No copy to set8700_A == (mat[3] = {7,0,7}) set8700_A = {1,2,3}, errno() == 10390; set8700_A == (mat[3] = {7,0,7}) @@ -368,7 +368,7 @@ set8700_A = list(2,3,5), modify(set8700_A, 7) == error(10406) protect(set8700_A,2), modify(set8700_A, "set8700_f") == error(10407) protect(set8700_A,0), modify(set8700_A, "h") == error(10408) set8700_B = 42, protect(set8700_B,0), modify(set8700_B, "set8700_f") == error(10409) -set8700_A == list(2,3,5) ## set8700_A not affected by failures +set8700_A == list(2,3,5) ## set8700_A not affected by failures protect(set8700_A,0,1), modify(set8700_A, "set8700_f") == null() set8700_A == list(4,9,25) modify(set8700_A,"set8700_g") == null() @@ -389,7 +389,7 @@ set8700_L = {{1,2,3},{'a','b','c'}}, set8700_L[0] == (mat[3] = {1,0,3}) set8700_L[1] == (mat[3] = {'a','b',0}) set8700_M = mat[2], protect(set8700_M,0), set8700_M = {1,2,3,4}, set8700_M == (mat[2] = {1,2}) set8700_x = 5, set8700_M = {set8700_x++, set8700_x++, set8700_x++, set8700_x++, set8700_x++}, set8700_M == (mat[2] = {5,6}) -set8700_x == 10 ## All initialization terms evaluated +set8700_x == 10 ## All initialization terms evaluated set8700_S = " ", set8700_S = {'a','b','c','d'}, set8700_S == "abc" set8700_P = obj set8700_point = {1,2,3,4}, set8700_P.set8700_x == 1 && set8700_P.set8700_y == 2 && set8700_P.set8700_z == 3 diff --git a/cal/smallfactors.cal b/cal/smallfactors.cal index a243ee2..8a9b4ad 100644 --- a/cal/smallfactors.cal +++ b/cal/smallfactors.cal @@ -28,7 +28,7 @@ define smallfactors(x0) local d q x flist tuple w; if (x >= (2 ^ 32) - 1) - return newerror("smallfactors: number must be < 2^32 -1"); + return newerror("smallfactors: number must be < 2^32 -1"); tuple = mat[2]; flist = list(); @@ -37,19 +37,19 @@ define smallfactors(x0) q = 0; tuple[0] = d; if (x < 2) - return 0; + return 0; do { - q = x // d; - while (x == (q * d)) { - tuple[0] = d; - tuple[1]++; - x = floor(q); - q = x // d; - } - d = nextprime(d); - if (tuple[1] > 0) - append(flist, tuple); - tuple = mat[2]; + q = x // d; + while (x == (q * d)) { + tuple[0] = d; + tuple[1]++; + x = floor(q); + q = x // d; + } + d = nextprime(d); + if (tuple[1] > 0) + append(flist, tuple); + tuple = mat[2]; } while (d <= x); return flist; } @@ -58,7 +58,7 @@ define printsmallfactors(flist) { local k; for (k = 0; k < size(flist); k++) { - print flist[k][0]:"^":flist[k][1]; + print flist[k][0]:"^":flist[k][1]; } } diff --git a/cal/solve.cal b/cal/solve.cal index 3141fb9..2dfc048 100644 --- a/cal/solve.cal +++ b/cal/solve.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:50:37 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:50:37 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -32,35 +32,35 @@ define solve(low, high, epsilon) { - local flow, fhigh, fmid, mid, places; + local flow, fhigh, fmid, mid, places; - if (isnull(epsilon)) - epsilon = epsilon(); - if (epsilon <= 0) - quit "Non-positive epsilon value"; - places = highbit(1 + int(1/epsilon)) + 1; - flow = f(low); - if (abs(flow) < epsilon) - return low; - fhigh = f(high); - if (abs(fhigh) < epsilon) - return high; - if (sgn(flow) == sgn(fhigh)) - quit "Non-opposite signs"; - while (1) { - mid = bround(high - fhigh * (high - low) / (fhigh - flow), - places); - if ((mid == low) || (mid == high)) - places++; - fmid = f(mid); - if (abs(fmid) < epsilon) - return mid; - if (sgn(fmid) == sgn(flow)) { - low = mid; - flow = fmid; - } else { - high = mid; - fhigh = fmid; - } - } + if (isnull(epsilon)) + epsilon = epsilon(); + if (epsilon <= 0) + quit "Non-positive epsilon value"; + places = highbit(1 + int(1/epsilon)) + 1; + flow = f(low); + if (abs(flow) < epsilon) + return low; + fhigh = f(high); + if (abs(fhigh) < epsilon) + return high; + if (sgn(flow) == sgn(fhigh)) + quit "Non-opposite signs"; + while (1) { + mid = bround(high - fhigh * (high - low) / (fhigh - flow), + places); + if ((mid == low) || (mid == high)) + places++; + fmid = f(mid); + if (abs(fmid) < epsilon) + return mid; + if (sgn(fmid) == sgn(flow)) { + low = mid; + flow = fmid; + } else { + high = mid; + fhigh = fmid; + } + } } diff --git a/cal/specialfunctions.cal b/cal/specialfunctions.cal index 06b0569..e82a694 100644 --- a/cal/specialfunctions.cal +++ b/cal/specialfunctions.cal @@ -17,8 +17,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2013/08/11 01:31:28 - * File existed as early as: 2013 + * Under source code control: 2013/08/11 01:31:28 + * File existed as early as: 2013 */ @@ -152,21 +152,21 @@ define __CZ__lngammarp(z) holds_enough = 0; if (size(__CZ__Ck) != a) { - __CZ__Ck = mat[a]; - holds_enough = 1; + __CZ__Ck = mat[a]; + holds_enough = 1; } factrl = 1.0; - __CZ__Ck[0] = sqrt(2 * pi()); /* c_0 */ + __CZ__Ck[0] = sqrt(2 * pi()); /* c_0 */ for (n = 1; n < a; n++) { - if (holds_enough == 1) { - __CZ__Ck[n] = (a - n) ^ (n - 0.5) * exp(a - n) / factrl; - factrl *= -n} + if (holds_enough == 1) { + __CZ__Ck[n] = (a - n) ^ (n - 0.5) * exp(a - n) / factrl; + factrl *= -n} } sum = __CZ__Ck[0]; for (n = 1; n < a; n++) { - sum += __CZ__Ck[n] / (z + n); + sum += __CZ__Ck[n] / (z + n); } ret = ln(sum) + (-(z + a)) + ln(z + a) * (z + 0.5); @@ -177,7 +177,7 @@ define __CZ__lngammarp(z) * in that case. */ if (im(ret)) { - ret = re(ret) + ln(exp(im(ret) * 1i)); + ret = re(ret) + ln(exp(im(ret) * 1i)); } epsilon(epsilon); @@ -189,27 +189,27 @@ define __CZ__lngamma_lanczos(z) { local a k g zghalf lanczos; mat lanczos[15] = { - 9.9999999999999709182e-1, - 5.7156235665862923516e1, - -5.9597960355475491248e1, - 1.4136097974741747173e1, - -4.9191381609762019978e-1, - 3.3994649984811888638e-5, - 4.6523628927048576010e-5, - -9.8374475304879566105e-5, - 1.5808870322491249322e-4, - -2.1026444172410489480e-4, - 2.1743961811521265523e-4, - -1.6431810653676390482e-4, - 8.4418223983852751308e-5, - -2.6190838401581411237e-5, - 3.6899182659531626821e-6 + 9.9999999999999709182e-1, + 5.7156235665862923516e1, + -5.9597960355475491248e1, + 1.4136097974741747173e1, + -4.9191381609762019978e-1, + 3.3994649984811888638e-5, + 4.6523628927048576010e-5, + -9.8374475304879566105e-5, + 1.5808870322491249322e-4, + -2.1026444172410489480e-4, + 2.1743961811521265523e-4, + -1.6431810653676390482e-4, + 8.4418223983852751308e-5, + -2.6190838401581411237e-5, + 3.6899182659531626821e-6 }; g = 607 / 128; z = z - 1; a = 0; for (k = 12; k >= 1; k--) { - a += lanczos[k] / (z + k); + a += lanczos[k] / (z + k); } a += lanczos[0]; zghalf = z + g + .5; @@ -221,10 +221,10 @@ define __CZ__print__CZ__Ck() { local k; if (size(__CZ__Ck) <= 1) { - __CZ__lngammarp(2.2 - 2.2i); + __CZ__lngammarp(2.2 - 2.2i); } for (k = 0; k < size(__CZ__Ck); k++) { - print __CZ__Ck[k]; + print __CZ__Ck[k]; } } @@ -232,16 +232,16 @@ define __CZ__print__CZ__Ck() define kroneckerdelta(i, j) { if (isnull(j)) { - if (i == 0) { - return 1; - } else { - return 0; - } + if (i == 0) { + return 1; + } else { + return 0; + } } if (i != j) { - return 0; + return 0; } else { - return 1; + return 1; } } @@ -260,19 +260,19 @@ define __CZ__lngstirling(z, n) z2 = z ^ 2; if (size(__CZ__precomp_stirling) < n) { - __CZ__precomp_stirling = mat[n]; - for (k = 1; k <= n; k++) { - bernterm = bernoulli(2 * k) / (2 * k * (2 * k - 1)); - __CZ__precomp_stirling[k - 1] = bernterm; - sum += bernterm / zz; - zz *= z2; - } + __CZ__precomp_stirling = mat[n]; + for (k = 1; k <= n; k++) { + bernterm = bernoulli(2 * k) / (2 * k * (2 * k - 1)); + __CZ__precomp_stirling[k - 1] = bernterm; + sum += bernterm / zz; + zz *= z2; + } } else { - for (k = 1; k <= n; k++) { - bernterm = __CZ__precomp_stirling[k - 1]; - sum += bernterm / zz; - zz *= z2; - } + for (k = 1; k <= n; k++) { + bernterm = __CZ__precomp_stirling[k - 1]; + sum += bernterm / zz; + zz *= z2; + } } return head + sum; } @@ -287,7 +287,7 @@ define R(z, k) ab = a / b; /* a/b might round to zero */ if (abs(ab) < epsilon()) { - return digits(1 / epsilon()); + return digits(1 / epsilon()); } return digits(1 / (a / b)); } @@ -298,49 +298,49 @@ define lngammasmall(z) local ret eps flag corr; flag = 0; if (isint(z)) { - if (z <= 0) { - return newerror("gamma(z): z is a negative integer"); - } else { - /* may hold up accuracy a bit longer, but YMMV */ - if (z < 20) { - return ln((z - 1) !); - } else { - return __CZ__lngamma_lanczos(z); - } - } + if (z <= 0) { + return newerror("gamma(z): z is a negative integer"); + } else { + /* may hold up accuracy a bit longer, but YMMV */ + if (z < 20) { + return ln((z - 1) !); + } else { + return __CZ__lngamma_lanczos(z); + } + } } else { - if (re(z) < 0) { - if (im(z) && im(z) < 0) { - z = conj(z); - flag = 1; - } + if (re(z) < 0) { + if (im(z) && im(z) < 0) { + z = conj(z); + flag = 1; + } - ret = ln(pi() / sin(pi() * z)) - __CZ__lngamma_lanczos(1 - z); + ret = ln(pi() / sin(pi() * z)) - __CZ__lngamma_lanczos(1 - z); - if (!im(z)) { - if (abs(z) <= 1 / 2) { - ret = re(ret) - pi() * 1i; - } else if (isodd(floor(abs(re(z))))) { - ret = re(ret) + (ceil(abs(z)) * pi() * 1i); - } else if (iseven(floor(abs(re(z))))) { - /* < n+1/2 */ - if (iseven(floor(abs(z)))) { - ret = re(ret) + (ceil(abs(z) - 1 / 2 - 1) * pi() * 1i); - } else { - ret = re(ret) + (ceil(abs(z) - 1 / 2) * pi() * 1i); - } - } - } else { - corr = ceil(re(z) / 2 - 3 / 4 - kroneckerdelta(im(z)) / 4); - ret = ret + 2 * (corr * pi()) * 1i; - } - if (flag == 1) { - ret = conj(ret); - } - return ret; - } - ret = (__CZ__lngamma_lanczos(z)); - return ret; + if (!im(z)) { + if (abs(z) <= 1 / 2) { + ret = re(ret) - pi() * 1i; + } else if (isodd(floor(abs(re(z))))) { + ret = re(ret) + (ceil(abs(z)) * pi() * 1i); + } else if (iseven(floor(abs(re(z))))) { + /* < n+1/2 */ + if (iseven(floor(abs(z)))) { + ret = re(ret) + (ceil(abs(z) - 1 / 2 - 1) * pi() * 1i); + } else { + ret = re(ret) + (ceil(abs(z) - 1 / 2) * pi() * 1i); + } + } + } else { + corr = ceil(re(z) / 2 - 3 / 4 - kroneckerdelta(im(z)) / 4); + ret = ret + 2 * (corr * pi()) * 1i; + } + if (flag == 1) { + ret = conj(ret); + } + return ret; + } + ret = (__CZ__lngamma_lanczos(z)); + return ret; } } @@ -355,255 +355,255 @@ define lngamma(z) local corr d37 d52 termcount; /* z \in \mathbf{Z} */ if (isint(z)) { - /*The gamma-function has poles at zero and the negative integers */ - if (z <= 0) { - return newerror("lngamma(z): z is a negative integer"); - } else { - /* may hold up accuracy a bit longer, but YMMV */ - if (z < 20) { - return ln((z - 1) !); - } else { - return __CZ__lngammarp(z); - } - } - } else { /*if(isint(z)) */ - if (re(z) > 0) { - flag = 0; - eps = epsilon(); - epsilon(eps * 1e-3); + /*The gamma-function has poles at zero and the negative integers */ + if (z <= 0) { + return newerror("lngamma(z): z is a negative integer"); + } else { + /* may hold up accuracy a bit longer, but YMMV */ + if (z < 20) { + return ln((z - 1) !); + } else { + return __CZ__lngammarp(z); + } + } + } else { /*if(isint(z)) */ + if (re(z) > 0) { + flag = 0; + eps = epsilon(); + epsilon(eps * 1e-3); - /* Compute values on the real line with Spouge's algorithm */ - if (!im(z)) { - ret = __CZ__lngammarp(z); - epsilon(eps); - return ret; - } - /* Do the rest with the Stirling series. */ - /* This code repeats down under. Booh! */ - /* Make it a positive im(z) */ - if (im(z) < 0) { - z = conj(z); - flag = 1; - } - /* Evaluate the number of terms needed */ - decdigits = floor(digits(1 / eps)); - /* 20 dec. digits is the default in calc(?) */ - if (decdigits <= 21) { - /* set 20 as the minimum */ - epsilon(1e-22); - increasedby = 0; - /* inflate z */ - Z = z; - while (abs(z) < 10) { - z++; - increasedby++; - } + /* Compute values on the real line with Spouge's algorithm */ + if (!im(z)) { + ret = __CZ__lngammarp(z); + epsilon(eps); + return ret; + } + /* Do the rest with the Stirling series. */ + /* This code repeats down under. Booh! */ + /* Make it a positive im(z) */ + if (im(z) < 0) { + z = conj(z); + flag = 1; + } + /* Evaluate the number of terms needed */ + decdigits = floor(digits(1 / eps)); + /* 20 dec. digits is the default in calc(?) */ + if (decdigits <= 21) { + /* set 20 as the minimum */ + epsilon(1e-22); + increasedby = 0; + /* inflate z */ + Z = z; + while (abs(z) < 10) { + z++; + increasedby++; + } - ret = __CZ__lngstirling(z, 11); - /* deflate z */ - if (increasedby > 1) { - for (k = 0; k < increasedby; k++) { - ret = ret - ln(Z + (k)); - } - } - /* Undo conjugate if one has been applied */ - if (flag == 1) { - ret = conj(ret); - } - epsilon(eps); - return ret; - } else { - d37 = decdigits * .37; - d52 = decdigits * .52; - termcount = ceil(d52); - if (abs(z) >= d52) { - if (abs(im(z)) >= d37) { - termcount = ceil(d37); - } else { - termcount = ceil(d52); - } - } + ret = __CZ__lngstirling(z, 11); + /* deflate z */ + if (increasedby > 1) { + for (k = 0; k < increasedby; k++) { + ret = ret - ln(Z + (k)); + } + } + /* Undo conjugate if one has been applied */ + if (flag == 1) { + ret = conj(ret); + } + epsilon(eps); + return ret; + } else { + d37 = decdigits * .37; + d52 = decdigits * .52; + termcount = ceil(d52); + if (abs(z) >= d52) { + if (abs(im(z)) >= d37) { + termcount = ceil(d37); + } else { + termcount = ceil(d52); + } + } - Z = z; - increasedby = 0; - /* inflate z */ - if (abs(im(z)) >= d37) { - while (abs(z) < d52 + 1) { - z++; - increasedby++; - } - } else { - tmp = R(z, termcount); - tmp2 = tmp; - while (tmp2 < decdigits) { - z++; - increasedby++; - tmp2 = R(z, termcount); - if (tmp2 < tmp) { - return - newerror(strcat - ("lngamma(1): something happened ", - "that shouldn't have happened")); - } - } - } + Z = z; + increasedby = 0; + /* inflate z */ + if (abs(im(z)) >= d37) { + while (abs(z) < d52 + 1) { + z++; + increasedby++; + } + } else { + tmp = R(z, termcount); + tmp2 = tmp; + while (tmp2 < decdigits) { + z++; + increasedby++; + tmp2 = R(z, termcount); + if (tmp2 < tmp) { + return + newerror(strcat + ("lngamma(1): something happened ", + "that shouldn't have happened")); + } + } + } - corr = ceil(re(z) / 2 - 3 / 4 - kroneckerdelta(im(z)) / 4); + corr = ceil(re(z) / 2 - 3 / 4 - kroneckerdelta(im(z)) / 4); - ret = __CZ__lngstirling(z, termcount); + ret = __CZ__lngstirling(z, termcount); - /* deflate z */ - if (increasedby > 1) { - for (k = 0; k < increasedby; k++) { - ret = ret - ln(Z + (k)); - } - } - /* Undo conjugate if one has been applied */ - if (flag == 1) { - ret = conj(ret); - } - epsilon(eps); - return ret; - } /* if(decdigits <= 20){...} else */ - } else { /* re(z)<0 */ - eps = epsilon(); - epsilon(eps * 1e-3); + /* deflate z */ + if (increasedby > 1) { + for (k = 0; k < increasedby; k++) { + ret = ret - ln(Z + (k)); + } + } + /* Undo conjugate if one has been applied */ + if (flag == 1) { + ret = conj(ret); + } + epsilon(eps); + return ret; + } /* if(decdigits <= 20){...} else */ + } else { /* re(z)<0 */ + eps = epsilon(); + epsilon(eps * 1e-3); - /* Use Spouge's approximation on the real line */ - if (!im(z)) { - /* reflection */ - ret = ln(pi() / sin(pi() * z)) - __CZ__lngammarp(1 - z); - /* it is log(gamma) and im(log(even(-x))) = k\pi, therefore: */ - if (abs(z) <= 1 / 2) { - ret = re(ret) - pi() * 1i; - } else if (isodd(floor(abs(re(z))))) { - ret = re(ret) + (ceil(abs(z)) * pi() * 1i); - } else if (iseven(floor(abs(re(z))))) { - /* < n+1/2 */ - if (iseven(floor(abs(z)))) { - ret = re(ret) + (ceil(abs(z) - 1 / 2 - 1) * pi() * 1i); - } else { - ret = re(ret) + (ceil(abs(z) - 1 / 2) * pi() * 1i); - } - } - epsilon(eps); - return ret; - } else { - /* Make it a positive im(z) */ - if (im(z) < 0) { - z = conj(z); - flag = 1; - } - /* Evaluate the number of terms needed */ - decdigits = floor(digits(1 / eps)); - /* 20 dec. digits is the default in calc(?) */ - if (decdigits <= 21) { - /* set 20 as the minimum */ - epsilon(1e-22); - termcount = 11; - increasedby = 0; - Z = z; - /* inflate z */ - if (im(z) >= digits(1 / epsilon()) * .37) { - while (abs(1 - z) < 10) { - z--; - increasedby++; - } - } else { - tmp = R(1 - z, termcount); - tmp2 = tmp; - while (tmp2 < 21) { - z--; - increasedby++; - tmp2 = R(1 - z, termcount); - if (tmp2 < tmp) { - return - newerror(strcat - ("lngamma(1): something happened ", - "that should not have happened")); - } - } - } + /* Use Spouge's approximation on the real line */ + if (!im(z)) { + /* reflection */ + ret = ln(pi() / sin(pi() * z)) - __CZ__lngammarp(1 - z); + /* it is log(gamma) and im(log(even(-x))) = k\pi, therefore: */ + if (abs(z) <= 1 / 2) { + ret = re(ret) - pi() * 1i; + } else if (isodd(floor(abs(re(z))))) { + ret = re(ret) + (ceil(abs(z)) * pi() * 1i); + } else if (iseven(floor(abs(re(z))))) { + /* < n+1/2 */ + if (iseven(floor(abs(z)))) { + ret = re(ret) + (ceil(abs(z) - 1 / 2 - 1) * pi() * 1i); + } else { + ret = re(ret) + (ceil(abs(z) - 1 / 2) * pi() * 1i); + } + } + epsilon(eps); + return ret; + } else { + /* Make it a positive im(z) */ + if (im(z) < 0) { + z = conj(z); + flag = 1; + } + /* Evaluate the number of terms needed */ + decdigits = floor(digits(1 / eps)); + /* 20 dec. digits is the default in calc(?) */ + if (decdigits <= 21) { + /* set 20 as the minimum */ + epsilon(1e-22); + termcount = 11; + increasedby = 0; + Z = z; + /* inflate z */ + if (im(z) >= digits(1 / epsilon()) * .37) { + while (abs(1 - z) < 10) { + z--; + increasedby++; + } + } else { + tmp = R(1 - z, termcount); + tmp2 = tmp; + while (tmp2 < 21) { + z--; + increasedby++; + tmp2 = R(1 - z, termcount); + if (tmp2 < tmp) { + return + newerror(strcat + ("lngamma(1): something happened ", + "that should not have happened")); + } + } + } - corr = ceil(re(z) / 2 - 3 / 4 - kroneckerdelta(im(z)) / 4); + corr = ceil(re(z) / 2 - 3 / 4 - kroneckerdelta(im(z)) / 4); - /* reflection */ - ret = - ln(pi() / sin(pi() * z)) - __CZ__lngstirling(1 - z, - termcount); + /* reflection */ + ret = + ln(pi() / sin(pi() * z)) - __CZ__lngstirling(1 - z, + termcount); - /* deflate z */ - if (increasedby > 0) { - for (k = 0; k < increasedby; k++) { - ret = ret + ln(z + (k)); - } - } - /* Apply correction term */ - ret = ret + 2 * (corr * pi()) * 1i; - /* Undo conjugate if one has been applied */ - if (flag == 1) { - ret = conj(ret); - } + /* deflate z */ + if (increasedby > 0) { + for (k = 0; k < increasedby; k++) { + ret = ret + ln(z + (k)); + } + } + /* Apply correction term */ + ret = ret + 2 * (corr * pi()) * 1i; + /* Undo conjugate if one has been applied */ + if (flag == 1) { + ret = conj(ret); + } - epsilon(eps); - return ret; - } else { - d37 = decdigits * .37; - d52 = decdigits * .52; - termcount = ceil(d52); - if (abs(z) >= d52) { - if (abs(im(z)) >= d37) { - termcount = ceil(d37); - } else { - termcount = ceil(d52); - } - } - increasedby = 0; - Z = z; - /* inflate z */ - if (abs(im(z)) >= d37) { - while (abs(1 - z) < d52 + 1) { - z--; - increasedby++; - } - } else { - tmp = R(1 - z, termcount); - tmp2 = tmp; - while (tmp2 < decdigits) { - z--; - increasedby++; - tmp2 = R(1 - z, termcount); - if (tmp2 < tmp) { - return - newerror(strcat - ("lngamma(1): something happened ", - "that should not have happened")); - } - } - } - corr = ceil(re(z) / 2 - 3 / 4 - kroneckerdelta(im(z)) / 4); - /* reflection */ - ret = - ln(pi() / sin(pi() * (z))) - __CZ__lngstirling(1 - z, - termcount); - /* deflate z */ - if (increasedby > 0) { - for (k = 0; k < increasedby; k++) { - ret = ret + ln(z + (k)); - } - } - /* Apply correction term */ - ret = ret + 2 * ((corr) * pi()) * 1i; - /* Undo conjugate if one has been applied */ - if (flag == 1) { - ret = conj(ret); - } - epsilon(eps); - return ret; - } /* if(decdigits <= 20){...} else */ - } /*if(!im(z)){...} else */ - } /* if(re(z) > 0){...} else */ - } /*if(isint(z)){...} else */ + epsilon(eps); + return ret; + } else { + d37 = decdigits * .37; + d52 = decdigits * .52; + termcount = ceil(d52); + if (abs(z) >= d52) { + if (abs(im(z)) >= d37) { + termcount = ceil(d37); + } else { + termcount = ceil(d52); + } + } + increasedby = 0; + Z = z; + /* inflate z */ + if (abs(im(z)) >= d37) { + while (abs(1 - z) < d52 + 1) { + z--; + increasedby++; + } + } else { + tmp = R(1 - z, termcount); + tmp2 = tmp; + while (tmp2 < decdigits) { + z--; + increasedby++; + tmp2 = R(1 - z, termcount); + if (tmp2 < tmp) { + return + newerror(strcat + ("lngamma(1): something happened ", + "that should not have happened")); + } + } + } + corr = ceil(re(z) / 2 - 3 / 4 - kroneckerdelta(im(z)) / 4); + /* reflection */ + ret = + ln(pi() / sin(pi() * (z))) - __CZ__lngstirling(1 - z, + termcount); + /* deflate z */ + if (increasedby > 0) { + for (k = 0; k < increasedby; k++) { + ret = ret + ln(z + (k)); + } + } + /* Apply correction term */ + ret = ret + 2 * ((corr) * pi()) * 1i; + /* Undo conjugate if one has been applied */ + if (flag == 1) { + ret = conj(ret); + } + epsilon(eps); + return ret; + } /* if(decdigits <= 20){...} else */ + } /*if(!im(z)){...} else */ + } /* if(re(z) > 0){...} else */ + } /*if(isint(z)){...} else */ } /* Warning about large values? */ @@ -613,24 +613,24 @@ define gamma(z) /* exp(log(gamma(z))) = exp(lngamma(z)), so use Spouge here? */ local ret eps; if (isint(z)) { - if (z <= 0) { - return newerror("gamma(z): z is a negative integer"); - } else { - /* may hold up accuracy a bit longer, but YMMV */ - if (z < 20) { - return (z - 1) ! *1.0; - } else { - eps = epsilon(epsilon() * 1e-2); - ret = exp(lngamma(z)); - epsilon(eps); - return ret; - } - } + if (z <= 0) { + return newerror("gamma(z): z is a negative integer"); + } else { + /* may hold up accuracy a bit longer, but YMMV */ + if (z < 20) { + return (z - 1) ! *1.0; + } else { + eps = epsilon(epsilon() * 1e-2); + ret = exp(lngamma(z)); + epsilon(eps); + return ret; + } + } } else { - eps = epsilon(epsilon() * 1e-2); - ret = exp(lngamma(z)); - epsilon(eps); - return ret; + eps = epsilon(epsilon() * 1e-2); + ret = exp(lngamma(z)); + epsilon(eps); + return ret; } } @@ -638,12 +638,12 @@ define __CZ__harmonicF(a, b, s) { local c; if (b == a) { - return s; + return s; } if (b - a > 1) { - c = (b + a) >> 1; - return (__CZ__harmonicF(a, c, 1 / a) + - __CZ__harmonicF(c + 1, b, 1 / b)); + c = (b + a) >> 1; + return (__CZ__harmonicF(a, c, 1 / a) + + __CZ__harmonicF(c + 1, b, 1 / b)); } return (1 / a + 1 / b); } @@ -651,14 +651,14 @@ define __CZ__harmonicF(a, b, s) define harmonic(limit) { if (!isint(limit)) { - return newerror("harmonic(limit): limit is not an integer"); + return newerror("harmonic(limit): limit is not an integer"); } if (limit <= 0) { - return newerror("harmonic(limit): limit is <=0"); + return newerror("harmonic(limit): limit is <=0"); } /* The binary splitting algorithm returns 0 for f(1,1,0) */ if (limit == 1) { - return 1; + return 1; } return __CZ__harmonicF(1, limit, 0); } @@ -677,10 +677,10 @@ define __CZ__gammainc_series_lower(a, z) fact = 1; eps = epsilon(); while (abs(tmp - ret) > eps) { - tmp = ret; - ret += (z ^ (k + a)) / ((a + k) * fact); - k++; - fact *= -k; + tmp = ret; + ret += (z ^ (k + a)) / ((a + k) * fact); + k++; + fact *= -k; } return gamma(a) - ret; } @@ -693,7 +693,7 @@ define __CZ__gammainc_cf(a, z, n) local ret k num1 denom1 num2 denom2; ret = 0; for (k = n + 1; k > 1; k--) { - ret = ((1 - k) * (k - 1 - a)) / (2 * k - 1 + z - a + ret); + ret = ((1 - k) * (k - 1 - a)) / (2 * k - 1 + z - a + ret); } return ((z ^ a * exp(-z)) / (1 + z - a + ret)); } @@ -703,7 +703,7 @@ define __CZ__gammainc_integer_a(a, z) { local k sum fact zz; for (k = 0; k < a; k++) { - sum += (z ^ k) / (k !); + sum += (z ^ k) / (k !); } return (a - 1) ! *exp(-z) * sum; } @@ -718,8 +718,8 @@ define __CZ__endcf(n, a, z, P) local ret; ret = - P * ln(10) + ln(4 * pi() * sqrt(n)) + re(z + (3 / 2 - a) * ln(z) - - lngamma(1 - a)); + P * ln(10) + ln(4 * pi() * sqrt(n)) + re(z + (3 / 2 - a) * ln(z) - + lngamma(1 - a)); ret = ret / (sqrt(8 * (abs(z) + re(z)))); return ret ^ 2; @@ -730,59 +730,59 @@ define gammainc(a, z) { local ret nterms eps epsilon tmp_before tmp_after n A B C sum k; if (z == 0) { - return 1; + return 1; } if (isint(a)) { - if (a > 0) { - if (a == 1) { - return exp(-z); - } - return __CZ__gammainc_integer_a(a, z); - } else { - if (a == 0) { - return -expoint(-z) + 1 / 2 * (ln(-z) - ln(-1 / z)) - ln(z); - } else if (a == -1) { - return expoint(-z) + 1 / 2 * (ln(-1 / z) - ln(-z)) + ln(z) + - (exp(-z) / z); - } else { - A = (-1) ^ ((-a) - 1) / ((-a) !); - B = expoint(-z) - 1 / 2 * (ln(-z) - ln(1 / -z)) + ln(z); - C = exp(-z); - sum = 0; - for (k = 1; k < -a; k++) { - sum += (z ^ (k - a - 1)) / (fallingfactorial(-a, k)); - } - return A * B - C * sum; - } - } + if (a > 0) { + if (a == 1) { + return exp(-z); + } + return __CZ__gammainc_integer_a(a, z); + } else { + if (a == 0) { + return -expoint(-z) + 1 / 2 * (ln(-z) - ln(-1 / z)) - ln(z); + } else if (a == -1) { + return expoint(-z) + 1 / 2 * (ln(-1 / z) - ln(-z)) + ln(z) + + (exp(-z) / z); + } else { + A = (-1) ^ ((-a) - 1) / ((-a) !); + B = expoint(-z) - 1 / 2 * (ln(-z) - ln(1 / -z)) + ln(z); + C = exp(-z); + sum = 0; + for (k = 1; k < -a; k++) { + sum += (z ^ (k - a - 1)) / (fallingfactorial(-a, k)); + } + return A * B - C * sum; + } + } } if (re(z) <= 1.1 || re(z) < a + 1) { - eps = epsilon(epsilon() * 1e-10); - ret = __CZ__gammainc_series_lower(a, z); - epsilon(eps); - return ret; + eps = epsilon(epsilon() * 1e-10); + ret = __CZ__gammainc_series_lower(a, z); + epsilon(eps); + return ret; } else { - eps = epsilon(epsilon() * 1e-10); - if (abs(exp(-z)) <= eps) { - return 0; - } - tmp_before = 0; - tmp_after = 1; - n = 1; - while (ceil(tmp_before) != ceil(tmp_after)) { - tmp_before = tmp_after; - tmp_after = __CZ__endcf(n++, a, z, digits(1 / eps)); - /* a still quite arbitrary limit */ - if (n > 10) { - return - newerror(strcat - ("gammainc: evaluating limit for continued ", - "fraction does not converge")); - } - } - ret = __CZ__gammainc_cf(a, z, ceil(tmp_after)); - epsilon(eps); - return ret; + eps = epsilon(epsilon() * 1e-10); + if (abs(exp(-z)) <= eps) { + return 0; + } + tmp_before = 0; + tmp_after = 1; + n = 1; + while (ceil(tmp_before) != ceil(tmp_after)) { + tmp_before = tmp_after; + tmp_after = __CZ__endcf(n++, a, z, digits(1 / eps)); + /* a still quite arbitrary limit */ + if (n > 10) { + return + newerror(strcat + ("gammainc: evaluating limit for continued ", + "fraction does not converge")); + } + } + ret = __CZ__gammainc_cf(a, z, ceil(tmp_after)); + epsilon(eps); + return ret; } } @@ -809,10 +809,10 @@ define g(prec) { local eps ret; if (!isnull(prec)) { - eps = epsilon(prec); - ret = -psi(1); - epsilon(eps); - return ret; + eps = epsilon(prec); + ret = -psi(1); + epsilon(eps); + return ret; } return -psi(1); } @@ -821,13 +821,13 @@ define __CZ__series_converged(new, old, max) { local eps; if (isnull(max)) { - eps = epsilon(); + eps = epsilon(); } else { - eps = max; + eps = max; } if (abs(re(new - old)) <= eps * abs(re(new)) - && abs(im(new - old)) <= eps * abs(im(new))) { - return true; + && abs(im(new - old)) <= eps * abs(im(new))) { + return true; } return false; } @@ -839,13 +839,13 @@ define __CZ__ei_power(z) tmp = 1; k = 1; while (k) { - tmp *= z / k; - old = ei; - ei += tmp / k; - if (__CZ__series_converged(ei, old)) { - break; - } - k++; + tmp *= z / k; + old = ei; + ei += tmp / k; + if (__CZ__series_converged(ei, old)) { + break; + } + k++; } return ei; } @@ -856,12 +856,12 @@ define __CZ__ei_asymp(z) ei = sgn(im(z)) * 1i * pi(); tmp = exp(z) / z; for (k = 1; k <= floor(abs(z)) + 1; k++) { - old = ei; - ei += tmp; - if (__CZ__series_converged(ei, old)) { - return ei; - } - tmp *= k / z; + old = ei; + ei += tmp; + if (__CZ__series_converged(ei, old)) { + return ei; + } + tmp *= k / z; } return newerror("expoint: asymptotic series does not converge"); } @@ -871,28 +871,28 @@ define __CZ__ei_cf(z) local ei c d k old; ei = sgn(im(z)) * 1i * pi(); if (ei != 0) { - c = 1 / ei; - d = 0; - c = 1 / (1 - z - exp(z) * c); - d = 1 / (1 - z - exp(z) * d); - ei *= d / c; + c = 1 / ei; + d = 0; + c = 1 / (1 - z - exp(z) * c); + d = 1 / (1 - z - exp(z) * d); + ei *= d / c; } else { - c = NUMBER_POSITIVE_INFINITY(); - d = 0; - c = 0; - d = 1 / (1 - z - exp(z) * d); - ei = d * (-exp(z)); + c = NUMBER_POSITIVE_INFINITY(); + d = 0; + c = 0; + d = 1 / (1 - z - exp(z) * d); + ei = d * (-exp(z)); } k = 1; while (1) { - c = 1 / (2 * k + 1 - z - k * k * c); - d = 1 / (2 * k + 1 - z - k * k * d); - old = ei; - ei *= d / c; - if (__CZ__series_converged(ei, old)) { - break; - } - k++; + c = 1 / (2 * k + 1 - z - k * k * c); + d = 1 / (2 * k + 1 - z - k * k * d); + old = ei; + ei *= d / c; + if (__CZ__series_converged(ei, old)) { + break; + } + k++; } return ei; } @@ -902,46 +902,46 @@ define expoint(z) local ei eps ret; eps = epsilon(epsilon() * 1e-5); if (abs(z) >= NUMBER_POSITIVE_INFINITY()) { - if (config("user_debug") > 0) { - print "expoint: abs(z) > +inf"; - } - ret = sgn(im(z)) * 1i * pi() + exp(z) / z; - epsilon(eps); - return ret; + if (config("user_debug") > 0) { + print "expoint: abs(z) > +inf"; + } + ret = sgn(im(z)) * 1i * pi() + exp(z) / z; + epsilon(eps); + return ret; } if (abs(z) > 2 - 1.035 * log(epsilon())) { - if (config("user_debug") > 0) { - print "expoint: using asymptotic series"; - } - ei = __CZ__ei_asymp(z); - if (!iserror(ei)) { - ret = ei; - epsilon(eps); - return ret; - } + if (config("user_debug") > 0) { + print "expoint: using asymptotic series"; + } + ei = __CZ__ei_asymp(z); + if (!iserror(ei)) { + ret = ei; + epsilon(eps); + return ret; + } } if (abs(z) > 1 && (re(z) < 0 || abs(im(z)) > 1)) { - if (config("user_debug") > 0) { - print "expoint: using continued fraction"; - } - ret = __CZ__ei_cf(z); - epsilon(eps); - return ret; + if (config("user_debug") > 0) { + print "expoint: using continued fraction"; + } + ret = __CZ__ei_cf(z); + epsilon(eps); + return ret; } if (abs(z) > 0) { - if (config("user_debug") > 0) { - print "expoint: using power series"; - } - ret = __CZ__ei_power(z); - epsilon(eps); - return ret; + if (config("user_debug") > 0) { + print "expoint: using power series"; + } + ret = __CZ__ei_power(z); + epsilon(eps); + return ret; } if (abs(z) == 0) { - if (config("user_debug") > 0) { - print "expoint: abs(z) = zero "; - } - epsilon(eps); - return NUMBER_NEGATIVE_INFINITY(); + if (config("user_debug") > 0) { + print "expoint: abs(z) = zero "; + } + epsilon(eps); + return NUMBER_NEGATIVE_INFINITY(); } } @@ -994,7 +994,7 @@ define __CZ__ibetacf_a(a, b, z, n) { local A B m places; if (n == 1) { - return 1; + return 1; } m = n - 1; places = highbit(1 + int (1 / epsilon())) +1; @@ -1010,7 +1010,7 @@ define __CZ__ibetacf_b(a, b, z, n) m = n - 1; A = bround((m * (b - m) * z) / (a + 2 * m - 1), places++); B = bround(((a + m) * (a - (a + b) * z + 1 + m * (2 - z))) / (a + 2 * m + - 1), places++); + 1), places++); return m + A + B; } @@ -1022,32 +1022,32 @@ define __CZ__ibeta_cf_var_dm(a, b, z, max) eps = epsilon(); if (isnull(max)) { - max = 100; + max = 100; } places = highbit(1 + int (1 / epsilon())) + 1; f = eps; c = f; d = 0; for (m = 1; m <= max; m++) { - d = bround(__CZ__ibetacf_b(a, b, z, m) + - __CZ__ibetacf_a(a, b, z, m) * d, places++); - if (abs(d) < eps) { - d = eps; - } - c = bround(__CZ__ibetacf_b(a, b, z, m) + - __CZ__ibetacf_a(a, b, z, m) / c, places++); - if (abs(c) < eps) { - c = eps; - } - d = 1 / d; - check = c * d; - f = f * check; - if (abs(check - 1) < eps) { - break; - } + d = bround(__CZ__ibetacf_b(a, b, z, m) + + __CZ__ibetacf_a(a, b, z, m) * d, places++); + if (abs(d) < eps) { + d = eps; + } + c = bround(__CZ__ibetacf_b(a, b, z, m) + + __CZ__ibetacf_a(a, b, z, m) / c, places++); + if (abs(c) < eps) { + c = eps; + } + d = 1 / d; + check = c * d; + f = f * check; + if (abs(check - 1) < eps) { + break; + } } if (m > max) { - return newerror("ibeta: continuous fraction does not converge"); + return newerror("ibeta: continuous fraction does not converge"); } return f; } @@ -1057,57 +1057,57 @@ define betainc_complex(z, a, b) local factor ret eps cf sum k N places tmp tmp2; if (z == 0) { - if (re(a) > 0) { - return 0; - } - if (re(a) < 0) { - return newerror("betainc_complex: z == 0 and re(a) < 0"); - } + if (re(a) > 0) { + return 0; + } + if (re(a) < 0) { + return newerror("betainc_complex: z == 0 and re(a) < 0"); + } } if (z == 1) { - if (re(b) > 0) { - return 1; - } else { - return newerror("betainc_complex: z == 1 and re(b) < 0"); - } + if (re(b) > 0) { + return 1; + } else { + return newerror("betainc_complex: z == 1 and re(b) < 0"); + } } if (b <= 0) { - if (isint(b)) { - return 0; - } else { - return newerror("betainc_complex: b <= 0"); - } + if (isint(b)) { + return 0; + } else { + return newerror("betainc_complex: b <= 0"); + } } if (z == 1 / 2 && (a == b)) { - return 1 / 2; + return 1 / 2; } if (isint(a) && isint(b)) { - eps = epsilon(epsilon() * 1e-10); - N = a + b - 1; - sum = 0; - for (k = a; k <= N; k++) { - tmp = ln(z) * k + ln(1 - z) * (N - k); - tmp2 = exp(ln(comb(N, k)) + tmp); - sum += tmp2; - } - epsilon(eps); + eps = epsilon(epsilon() * 1e-10); + N = a + b - 1; + sum = 0; + for (k = a; k <= N; k++) { + tmp = ln(z) * k + ln(1 - z) * (N - k); + tmp2 = exp(ln(comb(N, k)) + tmp); + sum += tmp2; + } + epsilon(eps); return sum; } else if (re(z) <= re((a + 1) / (a + b + 2))) { - eps = epsilon(epsilon() * 1e-10); - places = highbit(1 + int (1 / epsilon())) + 1; - factor = bround((ln(z ^ a * (1 - z) ^ b) - lnbeta(a, b)), places); - cf = bround(__CZ__ibeta_cf_var_dm(a, b, z), places); - ret = factor + ln(cf); - if (abs(ret//ln(2)) >= places) { - ret = 0; - } else { - ret = bround(exp(factor + ln(cf)), places); - } - epsilon(eps); - return ret; + eps = epsilon(epsilon() * 1e-10); + places = highbit(1 + int (1 / epsilon())) + 1; + factor = bround((ln(z ^ a * (1 - z) ^ b) - lnbeta(a, b)), places); + cf = bround(__CZ__ibeta_cf_var_dm(a, b, z), places); + ret = factor + ln(cf); + if (abs(ret//ln(2)) >= places) { + ret = 0; + } else { + ret = bround(exp(factor + ln(cf)), places); + } + epsilon(eps); + return ret; } else if (re(z) > re((a + 1) / (a + b + 2)) - || re(1 - z) < re((b + 1) / (a + b + 2))) { - ret = 1 - betainc_complex(1 - z, b, a); + || re(1 - z) < re((b + 1) / (a + b + 2))) { + ret = 1 - betainc_complex(1 - z, b, a); } return ret; } @@ -1163,31 +1163,31 @@ define __CZ__ibetaas63(x, a, b, beta) value = x; /* inverse incbeta calculates it already */ if (isnull(beta)) - beta = lnbeta(a, b); + beta = lnbeta(a, b); if (a <= 0.0 || b <= 0.0) { - return newerror("betainc: domain error: a < 0 and/or b < 0"); + return newerror("betainc: domain error: a < 0 and/or b < 0"); } if (x < 0.0 || 1.0 < x) { - return newerror("betainc: domain error: x<0 or x>1"); + return newerror("betainc: domain error: x<0 or x>1"); } if (x == 0.0 || x == 1.0) { - return value; + return value; } asb = a + b; cx = 1.0 - x; if (a < asb * x) { - xx = cx; - cx = x; - aa = b; - bb = a; - indx = 1; + xx = cx; + cx = x; + aa = b; + bb = a; + indx = 1; } else { - xx = x; - aa = a; - bb = b; - indx = 0; + xx = x; + aa = a; + bb = b; + indx = 0; } term = 1.0; @@ -1198,36 +1198,36 @@ define __CZ__ibetaas63(x, a, b, beta) rx = xx / cx; temp = bb - ai; if (ns == 0) { - rx = xx; + rx = xx; } places = highbit(1 + int (1 / acu)) + 1; while (1) { - term = bround(term * temp * rx / (aa + ai), places++); - value = value + term;; - temp = abs(term); + term = bround(term * temp * rx / (aa + ai), places++); + value = value + term;; + temp = abs(term); - if (temp <= acu && temp <= abs(acu * value)) { - value = value * exp(aa * ln(xx) - + (bb - 1.0) * ln(cx) - beta) / aa; + if (temp <= acu && temp <= abs(acu * value)) { + value = value * exp(aa * ln(xx) + + (bb - 1.0) * ln(cx) - beta) / aa; - if (indx) { - value = 1.0 - value; - } - break; - } + if (indx) { + value = 1.0 - value; + } + break; + } - ai = ai + 1.0; - ns = ns - 1; + ai = ai + 1.0; + ns = ns - 1; - if (0 <= ns) { - temp = bb - ai; - if (ns == 0) { - rx = xx; - } - } else { - temp = asb; - asb = asb + 1.0; - } + if (0 <= ns) { + temp = bb - ai; + if (ns == 0) { + rx = xx; + } + } else { + temp = asb; + asb = asb + 1.0; + } } epsilon(acu); return value; @@ -1249,32 +1249,32 @@ define betainc(z, a, b) local factor ret eps cf sum k N places tmp tmp2; if (im(z) || im(a) || im(b)) - return betainc_complex(z, a, b); + return betainc_complex(z, a, b); if (z == 0) { - if (re(a) > 0) { - return 0; - } - if (re(a) < 0) { - return newerror("betainc: z == 0 and re(a) < 0"); - } + if (re(a) > 0) { + return 0; + } + if (re(a) < 0) { + return newerror("betainc: z == 0 and re(a) < 0"); + } } if (z == 1) { - if (re(b) > 0) { - return 1; - } else { - return newerror("betainc: z == 1 and re(b) < 0"); - } + if (re(b) > 0) { + return 1; + } else { + return newerror("betainc: z == 1 and re(b) < 0"); + } } if (b <= 0) { - if (isint(b)) { - return 0; - } else { - return newerror("betainc: b <= 0"); - } + if (isint(b)) { + return 0; + } else { + return newerror("betainc: b <= 0"); + } } if (z == 1 / 2 && a == b) { - return 1 / 2; + return 1 / 2; } return __CZ__ibetaas63(z, a, b); @@ -1285,9 +1285,9 @@ define __CZ__erfinvapprox(x) local a; a = 0.147; return sgn(x) * - sqrt(sqrt - ((2 / (pi() * a) + (ln(1 - x ^ 2)) / 2) ^ 2 - (ln(1 - x ^ 2)) / a) - - (2 / (pi() * a) + (ln(1 - x ^ 2)) / 2)); + sqrt(sqrt + ((2 / (pi() * a) + (ln(1 - x ^ 2)) / 2) ^ 2 - (ln(1 - x ^ 2)) / a) + - (2 / (pi() * a) + (ln(1 - x ^ 2)) / 2)); } /* complementary inverse error function, faster at about x < 1-.91 @@ -1298,14 +1298,14 @@ define __CZ__inverffettis(x, n) { local y sqrtpi oldy k places; if (isnull(n)) - n = 205; + n = 205; y = erfinvapprox(1 - x); places = highbit(1 + int (1 / epsilon())) + 1; sqrtpi = sqrt(pi()); do { - oldy = y; - k++; - y = bround((ln(__CZ__fettiscf(y, n) / (sqrtpi * x))) ^ (1 / 2), places); + oldy = y; + k++; + y = bround((ln(__CZ__fettiscf(y, n) / (sqrtpi * x))) ^ (1 / 2), places); } while (abs(y - oldy) / y > epsilon()); return y; } @@ -1317,9 +1317,9 @@ define __CZ__fettiscf(y, n) t = 1 / y; tt = t ^ 2 / 2; for (k = n; k > 0; k--) { - a = 1; - b = k * tt; - r = b / (a + r); + a = 1; + b = k * tt; + r = b / (a + r); } return t / (1 + r); } @@ -1336,21 +1336,21 @@ define __CZ__inverfbin(x) fhigh = x - erf(high); flow = x - erf(low); while (1) { - mid = bround(high - fhigh * (high - low) / (fhigh - flow), places); - if ((mid == low) || (mid == high)) { - places++; - } - fmid = x - erf(mid); - if (abs(fmid) < epsilon) { - return mid; - } - if (sgn(fmid) == sgn(flow)) { - low = mid; - flow = fmid; - } else { - high = mid; - fhigh = fmid; - } + mid = bround(high - fhigh * (high - low) / (fhigh - flow), places); + if ((mid == low) || (mid == high)) { + places++; + } + fmid = x - erf(mid); + if (abs(fmid) < epsilon) { + return mid; + } + if (sgn(fmid) == sgn(flow)) { + low = mid; + flow = fmid; + } else { + high = mid; + fhigh = fmid; + } } } @@ -1358,41 +1358,41 @@ define erfinv(x) { local ret approx a eps y old places errfunc sqrtpihalf flag k; if (x < -1 || x > 1) - return newerror("erfinv: input out of domain (-1<=x<=1)"); + return newerror("erfinv: input out of domain (-1<=x<=1)"); if (x == 0) - return 0; + return 0; if (x == -1) - return NUMBER_NEGATIVE_INFINITY(); + return NUMBER_NEGATIVE_INFINITY(); if (x == +1) - return NUMBER_POSITIVE_INFINITY(); + return NUMBER_POSITIVE_INFINITY(); if (x < 0) { - x = -x; - flag = 1; + x = -x; + flag = 1; } /* No need for full precision */ eps = epsilon(1e-20); if (eps >= 1e-40) { - /* Winitzki, Sergei (6 February 2008). "A handy approximation for the - * error function and its inverse" */ - a = 0.147; - y = sgn(x) * sqrt(sqrt((2 / (pi() * a) - + (ln(1 - x ^ 2)) / 2) ^ 2 - - (ln(1 - x ^ 2)) / a) - - (2 / (pi() * a) + (ln(1 - x ^ 2)) / 2)); + /* Winitzki, Sergei (6 February 2008). "A handy approximation for the + * error function and its inverse" */ + a = 0.147; + y = sgn(x) * sqrt(sqrt((2 / (pi() * a) + + (ln(1 - x ^ 2)) / 2) ^ 2 + - (ln(1 - x ^ 2)) / a) + - (2 / (pi() * a) + (ln(1 - x ^ 2)) / 2)); } else { - /* 20 digits instead of 5 */ - if (x <= .91) { - y = __CZ__inverfbin(x); - } else { - y = __CZ__inverffettis(1 - x); - } + /* 20 digits instead of 5 */ + if (x <= .91) { + y = __CZ__inverfbin(x); + } else { + y = __CZ__inverffettis(1 - x); + } - if (eps <= 1e-20) { - epsilon(eps); - return y; - } + if (eps <= 1e-20) { + epsilon(eps); + return y; + } } epsilon(eps); /* binary digits in number (here: number = epsilon()) */ @@ -1405,13 +1405,13 @@ define erfinv(x) * at higher precision is quite costly; */ do { - old = y; - errfunc = bround(erf(y), places); - if (abs(errfunc - x) <= eps) { - break; - } - y = bround(y - (errfunc - x) / (sqrtpihalf * exp(-y ^ 2)), places); - k++; + old = y; + errfunc = bround(erf(y), places); + if (abs(errfunc - x) <= eps) { + break; + } + y = bround(y - (errfunc - x) / (sqrtpihalf * exp(-y ^ 2)), places); + k++; } while (1); /* * This is not really necessary but e.g: @@ -1428,10 +1428,10 @@ define erfinv(x) * The precision "looks too short". */ if (k == 0) { - y = bround(y - (errfunc - x) / (sqrtpihalf * exp(-y ^ 2)), places); + y = bround(y - (errfunc - x) / (sqrtpihalf * exp(-y ^ 2)), places); } if (flag == 1) { - y = -y; + y = -y; } return y; } diff --git a/cal/splitbits.cal b/cal/splitbits.cal index 66ac6d5..8f61846 100644 --- a/cal/splitbits.cal +++ b/cal/splitbits.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2006/06/07 14:10:11 - * File existed as early as: 2006 + * Under source code control: 2006/06/07 14:10:11 + * File existed as early as: 2006 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -39,43 +39,43 @@ if (! iserror(E_SPLITBITS_3)) E_SPLITBITS_3 = newerror("2nd argument must be an */ define splitbits(x, b) { - local ret; /* list to return */ - local mask; /* 2^b-1 */ - local x_is_reg = 0; /* true if x < 0 */ + local ret; /* list to return */ + local mask; /* 2^b-1 */ + local x_is_reg = 0; /* true if x < 0 */ /* firewall */ if (! isint(x)) { - return error(E_SPLITBITS_1); + return error(E_SPLITBITS_1); } if (! isint(b)) { - return error(E_SPLITBITS_2); + return error(E_SPLITBITS_2); } if (b <= 0) { - return error(E_SPLITBITS_3); + return error(E_SPLITBITS_3); } /* special case: x == 0 */ if (x == 0) { - return list(0); + return list(0); } /* setup for splitting x */ ret = list(); mask = 2^b-1; if (x < 0) { - x_is_reg = 1; - x = abs(x); + x_is_reg = 1; + x = abs(x); } /* split x */ while (x > 0) { - printf("%d %x\n", size(ret), x); - if (x_is_reg) { - append(ret, xor(x & mask, mask)); - } else { - append(ret, x & mask); - } - x >>= b; + printf("%d %x\n", size(ret), x); + if (x_is_reg) { + append(ret, xor(x & mask, mask)); + } else { + append(ret, x & mask); + } + x >>= b; } /* return list */ diff --git a/cal/statistics.cal b/cal/statistics.cal index 3db1798..df69b3a 100644 --- a/cal/statistics.cal +++ b/cal/statistics.cal @@ -17,8 +17,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2013/08/11 01:31:28 - * File existed as early as: 2013 + * Under source code control: 2013/08/11 01:31:28 + * File existed as early as: 2013 */ diff --git a/cal/sumsq.cal b/cal/sumsq.cal index 275b3c2..2a2bfd9 100644 --- a/cal/sumsq.cal +++ b/cal/sumsq.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:50:37 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:50:37 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -32,30 +32,30 @@ define ss(p) { - local a, b, i, p4; + local a, b, i, p4; - if (p == 2) { - print "1^2 + 1^2 = 2"; - return; - } - if ((p % 4) != 1) { - print p, "is not of the form 4N+1"; - return; - } - if (!ptest(p, min(p-2, 10))) { - print p, "is not a prime"; - return; - } - p4 = (p - 1) / 4; - i = 2; - do { - a = pmod(i++, p4, p); - } while ((a^2 % p) == 1); - b = p; - while (b^2 > p) { - i = b % a; - b = a; - a = i; - } - print a : "^2 +" , b : "^2 =" , a^2 + b^2; + if (p == 2) { + print "1^2 + 1^2 = 2"; + return; + } + if ((p % 4) != 1) { + print p, "is not of the form 4N+1"; + return; + } + if (!ptest(p, min(p-2, 10))) { + print p, "is not a prime"; + return; + } + p4 = (p - 1) / 4; + i = 2; + do { + a = pmod(i++, p4, p); + } while ((a^2 % p) == 1); + b = p; + while (b^2 > p) { + i = b % a; + b = a; + a = i; + } + print a : "^2 +" , b : "^2 =" , a^2 + b^2; } diff --git a/cal/sumtimes.cal b/cal/sumtimes.cal index 464d461..de114c1 100644 --- a/cal/sumtimes.cal +++ b/cal/sumtimes.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2006/06/22 17:29 - * File existed as early as: 2006 + * Under source code control: 2006/06/22 17:29 + * File existed as early as: 2006 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ diff --git a/cal/surd.cal b/cal/surd.cal index 3bb5945..382500f 100644 --- a/cal/surd.cal +++ b/cal/surd.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,266 +17,266 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:50:38 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:50:38 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ -obj surd {a, b}; /* definition of the surd object */ +obj surd {a, b}; /* definition of the surd object */ -global surd_type = -1; /* type of surd (value of D) */ -static obj surd surd__; /* example surd for testing against */ +global surd_type = -1; /* type of surd (value of D) */ +static obj surd surd__; /* example surd for testing against */ define surd(a,b) { - local x; + local x; - obj surd x; - x.a = a; - x.b = b; - return x; + obj surd x; + x.a = a; + x.b = b; + return x; } define surd_print(a) { - print "surd(" : a.a : ", " : a.b : ")" :; + print "surd(" : a.a : ", " : a.b : ")" :; } define surd_conj(a) { - local x; + local x; - obj surd x; - x.a = a.a; - x.b = -a.b; - return x; + obj surd x; + x.a = a.a; + x.b = -a.b; + return x; } define surd_norm(a) { - return a.a^2 + abs(surd_type) * a.b^2; + return a.a^2 + abs(surd_type) * a.b^2; } define surd_value(a, xepsilon) { - local epsilon; + local epsilon; - epsilon = xepsilon; - if (isnull(epsilon)) - epsilon = epsilon(); - return a.a + a.b * sqrt(surd_type, epsilon); + epsilon = xepsilon; + if (isnull(epsilon)) + epsilon = epsilon(); + return a.a + a.b * sqrt(surd_type, epsilon); } define surd_add(a, b) { - local obj surd x; + local obj surd x; - if (!istype(b, x)) { - x.a = a.a + b; - x.b = a.b; - return x; - } - if (!istype(a, x)) { - x.a = a + b.a; - x.b = b.b; - return x; - } - x.a = a.a + b.a; - x.b = a.b + b.b; - if (x.b) - return x; - return x.a; + if (!istype(b, x)) { + x.a = a.a + b; + x.b = a.b; + return x; + } + if (!istype(a, x)) { + x.a = a + b.a; + x.b = b.b; + return x; + } + x.a = a.a + b.a; + x.b = a.b + b.b; + if (x.b) + return x; + return x.a; } define surd_sub(a, b) { - local obj surd x; + local obj surd x; - if (!istype(b, x)) { - x.a = a.a - b; - x.b = a.b; - return x; - } - if (!istype(a, x)) { - x.a = a - b.a; - x.b = -b.b; - return x; - } - x.a = a.a - b.a; - x.b = a.b - b.b; - if (x.b) - return x; - return x.a; + if (!istype(b, x)) { + x.a = a.a - b; + x.b = a.b; + return x; + } + if (!istype(a, x)) { + x.a = a - b.a; + x.b = -b.b; + return x; + } + x.a = a.a - b.a; + x.b = a.b - b.b; + if (x.b) + return x; + return x.a; } define surd_inc(a) { - local x; + local x; - x = a; - x.a++; - return x; + x = a; + x.a++; + return x; } define surd_dec(a) { - local x; + local x; - x = a; - x.a--; - return x; + x = a; + x.a--; + return x; } define surd_neg(a) { - local obj surd x; + local obj surd x; - x.a = -a.a; - x.b = -a.b; - return x; + x.a = -a.a; + x.b = -a.b; + return x; } define surd_mul(a, b) { - local obj surd x; + local obj surd x; - if (!istype(b, x)) { - x.a = a.a * b; - x.b = a.b * b; - } else if (!istype(a, x)) { - x.a = b.a * a; - x.b = b.b * a; - } else { - x.a = a.a * b.a + surd_type * a.b * b.b; - x.b = a.a * b.b + a.b * b.a; - } - if (x.b) - return x; - return x.a; + if (!istype(b, x)) { + x.a = a.a * b; + x.b = a.b * b; + } else if (!istype(a, x)) { + x.a = b.a * a; + x.b = b.b * a; + } else { + x.a = a.a * b.a + surd_type * a.b * b.b; + x.b = a.a * b.b + a.b * b.a; + } + if (x.b) + return x; + return x.a; } define surd_square(a) { - local obj surd x; + local obj surd x; - x.a = a.a^2 + a.b^2 * surd_type; - x.b = a.a * a.b * 2; - if (x.b) - return x; - return x.a; + x.a = a.a^2 + a.b^2 * surd_type; + x.b = a.a * a.b * 2; + if (x.b) + return x; + return x.a; } define surd_scale(a, b) { - local obj surd x; + local obj surd x; - x.a = scale(a.a, b); - x.b = scale(a.b, b); - return x; + x.a = scale(a.a, b); + x.b = scale(a.b, b); + return x; } define surd_shift(a, b) { - local obj surd x; + local obj surd x; - x.a = a.a << b; - x.b = a.b << b; - if (x.b) - return x; - return x.a; + x.a = a.a << b; + x.b = a.b << b; + if (x.b) + return x; + return x.a; } define surd_div(a, b) { - local x, y; + local x, y; - if ((a == 0) && b) - return 0; - obj surd x; - if (!istype(b, x)) { - x.a = a.a / b; - x.b = a.b / b; - return x; - } - y = b; - y.b = -b.b; - return (a * y) / (b.a^2 - surd_type * b.b^2); + if ((a == 0) && b) + return 0; + obj surd x; + if (!istype(b, x)) { + x.a = a.a / b; + x.b = a.b / b; + return x; + } + y = b; + y.b = -b.b; + return (a * y) / (b.a^2 - surd_type * b.b^2); } define surd_inv(a) { - return 1 / a; + return 1 / a; } define surd_sgn(a) { - if (surd_type < 0) - quit "Taking sign of complex surd"; - if (a.a == 0) - return sgn(a.b); - if (a.b == 0) - return sgn(a.a); - if ((a.a > 0) && (a.b > 0)) - return 1; - if ((a.a < 0) && (a.b < 0)) - return -1; - return sgn(a.a^2 - a.b^2 * surd_type) * sgn(a.a); + if (surd_type < 0) + quit "Taking sign of complex surd"; + if (a.a == 0) + return sgn(a.b); + if (a.b == 0) + return sgn(a.a); + if ((a.a > 0) && (a.b > 0)) + return 1; + if ((a.a < 0) && (a.b < 0)) + return -1; + return sgn(a.a^2 - a.b^2 * surd_type) * sgn(a.a); } define surd_cmp(a, b) { - if (!istype(a, surd__)) - return ((b.b != 0) || (a != b.a)); - if (!istype(b, surd__)) - return ((a.b != 0) || (b != a.a)); - return ((a.a != b.a) || (a.b != b.b)); + if (!istype(a, surd__)) + return ((b.b != 0) || (a != b.a)); + if (!istype(b, surd__)) + return ((a.b != 0) || (b != a.a)); + return ((a.a != b.a) || (a.b != b.b)); } define surd_rel(a, b) { - local x, y; + local x, y; - if (surd_type < 0) - quit "Relative comparison of complex surds"; - if (!istype(a, surd__)) { - x = a - b.a; - y = -b.b; - } else if (!istype(b, surd__)) { - x = a.a - b; - y = a.b; - } else { - x = a.a - b.a; - y = a.b - b.b; - } - if (y == 0) - return sgn(x); - if (x == 0) - return sgn(y); - if ((x < 0) && (y < 0)) - return -1; - if ((x > 0) && (y > 0)) - return 1; - return sgn(x^2 - y^2 * surd_type) * sgn(x); + if (surd_type < 0) + quit "Relative comparison of complex surds"; + if (!istype(a, surd__)) { + x = a - b.a; + y = -b.b; + } else if (!istype(b, surd__)) { + x = a.a - b; + y = a.b; + } else { + x = a.a - b.a; + y = a.b - b.b; + } + if (y == 0) + return sgn(x); + if (x == 0) + return sgn(y); + if ((x < 0) && (y < 0)) + return -1; + if ((x > 0) && (y > 0)) + return 1; + return sgn(x^2 - y^2 * surd_type) * sgn(x); } if (config("resource_debug") & 3) { diff --git a/cal/test2300.obj_incdec.cal b/cal/test2300.obj_incdec.cal index f8812b5..363f7de 100644 --- a/cal/test2300.obj_incdec.cal +++ b/cal/test2300.obj_incdec.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/07/09 06:12:13 - * File existed as early as: 1995 + * Under source code control: 1995/07/09 06:12:13 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -33,12 +33,12 @@ obj matrix {m} */ define matrix_inc(a) { - local i; + local i; - /* increment each matrix member */ - for (i= 0; i < size(a.m); i++) - ++a.m[[i]]; - return a; + /* increment each matrix member */ + for (i= 0; i < size(a.m); i++) + ++a.m[[i]]; + return a; } /* @@ -46,12 +46,12 @@ define matrix_inc(a) */ define matrix_dec(a) { - local i; + local i; - /* decrement each matrix member */ - for (i= 0; i < size(a.m); i++) - --a.m[[i]]; - return a; + /* decrement each matrix member */ + for (i= 0; i < size(a.m); i++) + --a.m[[i]]; + return a; } /* @@ -59,24 +59,24 @@ define matrix_dec(a) */ define mkmat() { - local s, M, i, v; + local s, M, i, v; - /* firewall */ - s = param(0); - if (s == 0) - quit "Need at least one argument"; + /* firewall */ + s = param(0); + if (s == 0) + quit "Need at least one argument"; - /* create the matrix */ - mat M[s]; + /* create the matrix */ + mat M[s]; - /* load the matrix with the args */ - for (i = 0; i < s; i++) - M[i] = param(i + 1); + /* load the matrix with the args */ + for (i = 0; i < s; i++) + M[i] = param(i + 1); - /* create the object with the matrix */ - obj matrix v; - v.m = M; - return v; + /* create the object with the matrix */ + obj matrix v; + v.m = M; + return v; } /* @@ -84,29 +84,29 @@ define mkmat() */ define ckmat() { - local s, a, i; + local s, a, i; - /* firewall */ - s = param(0); - if (s < 2) - quit "Need at least two arguments"; + /* firewall */ + s = param(0); + if (s < 2) + quit "Need at least two arguments"; - /* get the object to test */ - a = param(1); + /* get the object to test */ + a = param(1); - /* verify the matrix in the object is the right size */ - if (size(a.m) != s-1) { - return 0; - } + /* verify the matrix in the object is the right size */ + if (size(a.m) != s-1) { + return 0; + } - /* check each matrix element with the args passed */ - for (i = 2; i <= s; i++) { - if (a.m[i-2] != param(i)) { - /* args do not match */ - return 0; - } - } + /* check each matrix element with the args passed */ + for (i = 2; i <= s; i++) { + if (a.m[i-2] != param(i)) { + /* args do not match */ + return 0; + } + } - /* args match the matrix in the object */ - return 1; + /* args match the matrix in the object */ + return 1; } diff --git a/cal/test2600.numfunc.cal b/cal/test2600.numfunc.cal index cd464a6..28681a3 100644 --- a/cal/test2600.numfunc.cal +++ b/cal/test2600.numfunc.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/10/13 00:13:14 - * File existed as early as: 1995 + * Under source code control: 1995/10/13 00:13:14 + * File existed as early as: 1995 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -52,405 +52,405 @@ * * Test functions are called as: * - * testabc(str, ..., verbose) + * testabc(str, ..., verbose) * * where str is a string that names the test. This string is printed * without a newline (if verbose > 0), near the beginning of the function. * The verbose parameter controls how verbose the test will be: * - * 0 - print nothing - * 1 - print str and the error count - * 2 - print min and max errors as well - * 3 - print everything including individual loop counts + * 0 - print nothing + * 1 - print str and the error count + * 2 - print min and max errors as well + * 3 - print everything including individual loop counts * * All functions return the number of errors that they detected. */ -global defaultverbose = 1; /* default verbose value */ +global defaultverbose = 1; /* default verbose value */ global err; define testismult(str, n, verbose) { - local a, b, c, i, m; + local a, b, c, i, m; - if (isnull(verbose)) verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = 0; - for (i = 0; i < n; i++) { - if (verbose > 2) print i,:; - a = scale(rand(1,1e1000), rand(100)); - b = scale(rand(1,1e1000), rand(100)); - c = a * b; - if (!ismult(c,a)) { - m++; - if (verbose > 1) { - printf("*** Failure with:\na = %d\nb = %d\n", - a,b); - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("no errors\n"); - } - } - return m; + if (isnull(verbose)) verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = 0; + for (i = 0; i < n; i++) { + if (verbose > 2) print i,:; + a = scale(rand(1,1e1000), rand(100)); + b = scale(rand(1,1e1000), rand(100)); + c = a * b; + if (!ismult(c,a)) { + m++; + if (verbose > 1) { + printf("*** Failure with:\na = %d\nb = %d\n", + a,b); + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("no errors\n"); + } + } + return m; } define testsqrt(str, n, eps, verbose) { - local a, c, i, x, m, min, max; + local a, c, i, x, m, min, max; - if (isnull(verbose)) verbose = 2; - if (verbose > 0) { - print str:":",:; - } - m = 0; - min = 1000; - max = -1000; - if (isnull(eps)) - eps = epsilon(); - for (i = 1; i <= n; i++) { - if (verbose > 2) print i,:; - a = scale(rand(1,1000), rand(100)); - x = sqrt(a, eps); - if (x) - c = (a/x - x)/2/eps; - else - c = a/eps; /* ??? */ - if (c < min) - min = c; - if (c > max) - max = c; - if (abs(c) > 1) { - m++; - if (verbose > 1) { - printf("*** Failure with:\na = %d\neps = %d\n", - a,eps); - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - printf(" %s: rem/eps min=%d, max=%d\n", - str, min, max); - } else { - printf("no errors\n"); - } - } - if (verbose > 1) { - printf(" %s: rem/eps min=%0.4d, max=%0.4d\n", str, min, max); - } - return m; + if (isnull(verbose)) verbose = 2; + if (verbose > 0) { + print str:":",:; + } + m = 0; + min = 1000; + max = -1000; + if (isnull(eps)) + eps = epsilon(); + for (i = 1; i <= n; i++) { + if (verbose > 2) print i,:; + a = scale(rand(1,1000), rand(100)); + x = sqrt(a, eps); + if (x) + c = (a/x - x)/2/eps; + else + c = a/eps; /* ??? */ + if (c < min) + min = c; + if (c > max) + max = c; + if (abs(c) > 1) { + m++; + if (verbose > 1) { + printf("*** Failure with:\na = %d\neps = %d\n", + a,eps); + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + printf(" %s: rem/eps min=%d, max=%d\n", + str, min, max); + } else { + printf("no errors\n"); + } + } + if (verbose > 1) { + printf(" %s: rem/eps min=%0.4d, max=%0.4d\n", str, min, max); + } + return m; } define testexp(str, n, eps, verbose) { - local i, a, c, m, min, max; + local i, a, c, m, min, max; - if (isnull(verbose)) verbose = 2; - if (verbose > 0) { - print str:":",:; - } - if (isnull(eps)) - eps = epsilon(); - min = 1000; - max = -1000; - for (i = 1; i <= n; i++) { - if (verbose > 2) print i,:; - a = rand(1,1e20)/rand(1,1e20) + rand(50); - if (rand(1)) - a = -a; - c = cexp(a, eps); - if (c < min) - min = c; - if (c > max) - max = c; - if (abs(c) > 0.02) { - m++; - if (verbose > 1) { - printf("*** Failure with:\na = %d\neps = %d\n", - a,eps); - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - printf(" %s: rem/eps min=%d, max=%d\n", - str, min, max); - } else { - printf("no errors\n"); - } - } - if (verbose > 1) { - printf(" %s: rem/eps min=%0.4d, max=%0.4d\n", str, min, max); - } - return m; + if (isnull(verbose)) verbose = 2; + if (verbose > 0) { + print str:":",:; + } + if (isnull(eps)) + eps = epsilon(); + min = 1000; + max = -1000; + for (i = 1; i <= n; i++) { + if (verbose > 2) print i,:; + a = rand(1,1e20)/rand(1,1e20) + rand(50); + if (rand(1)) + a = -a; + c = cexp(a, eps); + if (c < min) + min = c; + if (c > max) + max = c; + if (abs(c) > 0.02) { + m++; + if (verbose > 1) { + printf("*** Failure with:\na = %d\neps = %d\n", + a,eps); + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + printf(" %s: rem/eps min=%d, max=%d\n", + str, min, max); + } else { + printf("no errors\n"); + } + } + if (verbose > 1) { + printf(" %s: rem/eps min=%0.4d, max=%0.4d\n", str, min, max); + } + return m; } -define cexp(x,eps) /* Find relative rem/eps for exp(x, eps) */ +define cexp(x,eps) /* Find relative rem/eps for exp(x, eps) */ { - local eps1, v, v1, c; + local eps1, v, v1, c; - if (isnull(eps)) - eps = epsilon(); - eps1 = eps * 1e-6; - v = exp(x, eps); - v1 = exp(x, eps1); - c = round((v1 - v)/v1/eps, 6, 24); - return c; + if (isnull(eps)) + eps = epsilon(); + eps1 = eps * 1e-6; + v = exp(x, eps); + v1 = exp(x, eps1); + c = round((v1 - v)/v1/eps, 6, 24); + return c; } define testln(str, n, eps, verbose) { - local i, a, c, m, min, max; + local i, a, c, m, min, max; - if (isnull(verbose)) verbose = 2; - if (verbose > 0) { - print str:":",:; - } - if (isnull(eps)) - eps = epsilon(); - min = 1000; - max = -1000; - for (i = 1; i <= n; i++) { - if (verbose > 2) print i,:; - a = rand(1,1e20)/rand(1,1e20) + rand(50); - c = cln(a, eps); - if (c < min) - min = c; - if (c > max) - max = c; - if (abs(c) > 0.5) { - m++; - if (verbose > 1) { - printf("*** Failure with:\na = %d\neps = %d\n", - a,eps); - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - printf(" %s: rem/eps min=%d, max=%d\n", - str, min, max); - } else { - printf("no errors\n"); - } - } - if (verbose > 1) { - printf(" %s: rem/eps min=%0.4d, max=%0.4d\n", str, min, max); - } - return m; + if (isnull(verbose)) verbose = 2; + if (verbose > 0) { + print str:":",:; + } + if (isnull(eps)) + eps = epsilon(); + min = 1000; + max = -1000; + for (i = 1; i <= n; i++) { + if (verbose > 2) print i,:; + a = rand(1,1e20)/rand(1,1e20) + rand(50); + c = cln(a, eps); + if (c < min) + min = c; + if (c > max) + max = c; + if (abs(c) > 0.5) { + m++; + if (verbose > 1) { + printf("*** Failure with:\na = %d\neps = %d\n", + a,eps); + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + printf(" %s: rem/eps min=%d, max=%d\n", + str, min, max); + } else { + printf("no errors\n"); + } + } + if (verbose > 1) { + printf(" %s: rem/eps min=%0.4d, max=%0.4d\n", str, min, max); + } + return m; } define cln(a, eps) { - local eps1, v, v1, c; + local eps1, v, v1, c; - if (isnull(eps)) - eps = epsilon(); - eps1 = eps/1e6; - v = ln(a, eps); - v1 = ln(a, eps1); - c = round((v1 - v)/eps, 6, 24); - return c; + if (isnull(eps)) + eps = epsilon(); + eps1 = eps/1e6; + v = ln(a, eps); + v1 = ln(a, eps1); + c = round((v1 - v)/eps, 6, 24); + return c; } define testpower(str, n, b, eps, verbose) { - local i, a, c, m, min, max; + local i, a, c, m, min, max; - if (isnull(verbose)) verbose = 2; - if (verbose > 0) { - print str:":",:; - } - if (isnull(eps)) - eps = epsilon(); - if (!isnum(b)) - quit "Second argument (exponent) to be a number"; - min = 1000; - max = -1000; - for (i = 1; i <= n; i++) { - if (verbose > 2) print i,:; - a = rand(1,1e20)/rand(1,1e20); - c = cpow(a, b, eps); - if (abs(c) > .75) { - m++; - if (verbose > 1) { - printf("*** Failure for a = %d\n", a); - } - } - if (c < min) - min = c; - if (c > max) - max = c; - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - printf(" %s: rem/eps min=%d, max=%d\n", - str, min, max); - } else { - printf("no errors\n"); - } - } - if (verbose > 1) { - printf(" %s: rem/eps min=%0.4d, max=%0.4d\n", str, min, max); - } - return m; + if (isnull(verbose)) verbose = 2; + if (verbose > 0) { + print str:":",:; + } + if (isnull(eps)) + eps = epsilon(); + if (!isnum(b)) + quit "Second argument (exponent) to be a number"; + min = 1000; + max = -1000; + for (i = 1; i <= n; i++) { + if (verbose > 2) print i,:; + a = rand(1,1e20)/rand(1,1e20); + c = cpow(a, b, eps); + if (abs(c) > .75) { + m++; + if (verbose > 1) { + printf("*** Failure for a = %d\n", a); + } + } + if (c < min) + min = c; + if (c > max) + max = c; + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + printf(" %s: rem/eps min=%d, max=%d\n", + str, min, max); + } else { + printf("no errors\n"); + } + } + if (verbose > 1) { + printf(" %s: rem/eps min=%0.4d, max=%0.4d\n", str, min, max); + } + return m; } define testpower2(str, n, eps, verbose) { - local i, a, c, m, min, max; - local b; - local num; - local c2; - local oldeps; + local i, a, c, m, min, max; + local b; + local num; + local c2; + local oldeps; - if (isnull(verbose)) verbose = 2; - if (verbose > 0) { - print str:":",:; - } - if (isnull(eps)) - eps = epsilon(); - oldeps = epsilon(eps); - epsilon(eps),; - if (!isnum(b)) - quit "Second argument (exponent) to be a number"; - min = 1000; - max = -1000; - for (i = 1; i <= n; i++) { - if (verbose > 2) print i,:; + if (isnull(verbose)) verbose = 2; + if (verbose > 0) { + print str:":",:; + } + if (isnull(eps)) + eps = epsilon(); + oldeps = epsilon(eps); + epsilon(eps),; + if (!isnum(b)) + quit "Second argument (exponent) to be a number"; + min = 1000; + max = -1000; + for (i = 1; i <= n; i++) { + if (verbose > 2) print i,:; - /* real ^ real */ - a = rand(1,1e20); - a = a / (int(a/2)+rand(1,1e20)); - b = rand(1,1e20); - b = b / (int(b/2)+rand(1,1e20)); - c = a ^ b; - c2 = power(a, b); - if (c != c2) { - m++; - if (verbose > 1) { - printf("*** real^real failure for a = %d\n", a); - } - } + /* real ^ real */ + a = rand(1,1e20); + a = a / (int(a/2)+rand(1,1e20)); + b = rand(1,1e20); + b = b / (int(b/2)+rand(1,1e20)); + c = a ^ b; + c2 = power(a, b); + if (c != c2) { + m++; + if (verbose > 1) { + printf("*** real^real failure for a = %d\n", a); + } + } - /* complex ^ real */ - a = rand(1,1e20); - a = a / (int(a/2)+rand(1,1e20)); - b = rand(1,1e20); - b = b / (int(b/2)+rand(1,1e20)); - c = (a*1i) ^ b; - c2 = power(a*1i, b); - if (c != c2) { - m++; - if (verbose > 1) { - printf("*** comp^real failure for a = %d\n", a); - } - } + /* complex ^ real */ + a = rand(1,1e20); + a = a / (int(a/2)+rand(1,1e20)); + b = rand(1,1e20); + b = b / (int(b/2)+rand(1,1e20)); + c = (a*1i) ^ b; + c2 = power(a*1i, b); + if (c != c2) { + m++; + if (verbose > 1) { + printf("*** comp^real failure for a = %d\n", a); + } + } - /* real ^ complex */ - a = rand(1,1e20); - a = a / (int(a/2)+rand(1,1e20)); - b = rand(1,1e20); - b = b / (int(b/2)+rand(1,1e20)); - c = a ^ (b*1i); - c2 = power(a, b*1i); - if (c != c2) { - m++; - if (verbose > 1) { - printf("*** real^comp failure for a = %d\n", a); - } - } + /* real ^ complex */ + a = rand(1,1e20); + a = a / (int(a/2)+rand(1,1e20)); + b = rand(1,1e20); + b = b / (int(b/2)+rand(1,1e20)); + c = a ^ (b*1i); + c2 = power(a, b*1i); + if (c != c2) { + m++; + if (verbose > 1) { + printf("*** real^comp failure for a = %d\n", a); + } + } - /* complex ^ complex */ - a = rand(1,1e20); - a = a / (int(a/2)+rand(1,1e20)); - b = rand(1,1e20); - b = b / (int(b/2)+rand(1,1e20)); - c = (a*1i) ^ (b*1i); - c2 = power(a*1i, b*1i); - if (c != c2) { - m++; - if (verbose > 1) { - printf("*** comp^comp failure for a = %d\n", a); - } - } - } - epsilon(oldeps),; - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - printf(" %s: rem/eps min=%d, max=%d\n", - str, min, max); - } else { - printf("no errors\n"); - } - } - if (verbose > 1) { - printf(" %s: rem/eps min=%0.4d, max=%0.4d\n", str, min, max); - } - return m; + /* complex ^ complex */ + a = rand(1,1e20); + a = a / (int(a/2)+rand(1,1e20)); + b = rand(1,1e20); + b = b / (int(b/2)+rand(1,1e20)); + c = (a*1i) ^ (b*1i); + c2 = power(a*1i, b*1i); + if (c != c2) { + m++; + if (verbose > 1) { + printf("*** comp^comp failure for a = %d\n", a); + } + } + } + epsilon(oldeps),; + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + printf(" %s: rem/eps min=%d, max=%d\n", + str, min, max); + } else { + printf("no errors\n"); + } + } + if (verbose > 1) { + printf(" %s: rem/eps min=%0.4d, max=%0.4d\n", str, min, max); + } + return m; } -define cpow(a, b, eps) /* Find rem/eps for power(a,b,eps) */ +define cpow(a, b, eps) /* Find rem/eps for power(a,b,eps) */ { - local v, v1, c, n, d, h; + local v, v1, c, n, d, h; - if (isnull(eps)) - eps = epsilon(); - n = num(b); - d = den(b); + if (isnull(eps)) + eps = epsilon(); + n = num(b); + d = den(b); - v = power(a, b, eps); - h = (a^n/v^d - 1) * v/d; - c = round(h/eps, 6, 24); - return c; + v = power(a, b, eps); + h = (a^n/v^d - 1) * v/d; + c = round(h/eps, 6, 24); + return c; } define testgcd(str, n, verbose) { - local i, a, b, g, m; + local i, a, b, g, m; - if (isnull(verbose)) verbose = 2; - if (verbose > 0) { - print str:":",:; - } - m = 0; - for (i = 1; i <= n; i++) { - if (verbose > 2) print i,:; - a = rand(1,1e1000); - b = rand(1,1e1000); - g = gcd(a,b); - if (!ismult(a,g) || !ismult(b,g) || !g || !isrel(a/g, b/g)) { - m++; - printf("*** Failure for a = %d, b = %d\n", a, b); - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("no errors\n"); - } - } - return m; + if (isnull(verbose)) verbose = 2; + if (verbose > 0) { + print str:":",:; + } + m = 0; + for (i = 1; i <= n; i++) { + if (verbose > 2) print i,:; + a = rand(1,1e1000); + b = rand(1,1e1000); + g = gcd(a,b); + if (!ismult(a,g) || !ismult(b,g) || !g || !isrel(a/g, b/g)) { + m++; + printf("*** Failure for a = %d, b = %d\n", a, b); + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("no errors\n"); + } + } + return m; } define mkreal() = scale(rand(-1000,1001)/rand(1,1000), rand(-100, 101)); @@ -459,110 +459,110 @@ define mkcomplex() = mkreal() + 1i * mkreal(); define mkbigreal() { - local x; + local x; - x = rand(100, 1000)/rand(1,10); - if (rand(2)) - x = -x; - return x; + x = rand(100, 1000)/rand(1,10); + if (rand(2)) + x = -x; + return x; } define mksmallreal() = rand(-10, 11)/rand(100,1000); define testappr(str, n, verbose) { - local x, y, z, m, i, p; + local x, y, z, m, i, p; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = 0; - for (i = 1; i <= n; i++) { - x = rand(3) ? mkreal(): mkcomplex(); - y = mkreal(); - if (verbose > 2) - printf(" %d: x = %d, y = %d\n", i, x, y); + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = 0; + for (i = 1; i <= n; i++) { + x = rand(3) ? mkreal(): mkcomplex(); + y = mkreal(); + if (verbose > 2) + printf(" %d: x = %d, y = %d\n", i, x, y); - for (z = 0; z < 32; z++) { - p = checkappr(x,y,z,verbose); - if (p) { - printf("*** Failure for x=%d, y=%d, z=%d\n", - x, y, z); - m++; - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("no errors\n"); - } - } - return m; + for (z = 0; z < 32; z++) { + p = checkappr(x,y,z,verbose); + if (p) { + printf("*** Failure for x=%d, y=%d, z=%d\n", + x, y, z); + m++; + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("no errors\n"); + } + } + return m; } -define checkappr(x,y,z,verbose) /* Returns 1 if an error is detected */ +define checkappr(x,y,z,verbose) /* Returns 1 if an error is detected */ { - local a; + local a; - a = appr(x,y,z); - if (verbose > 1) - printf("\ta = %d\n", a); - if (isreal(x)) - return checkresult(x,y,z,a); - if (isnum(x)) - return checkresult(re(x), y, z, re(a)) - | checkresult(im(x), y, z, im(a)); + a = appr(x,y,z); + if (verbose > 1) + printf("\ta = %d\n", a); + if (isreal(x)) + return checkresult(x,y,z,a); + if (isnum(x)) + return checkresult(re(x), y, z, re(a)) + | checkresult(im(x), y, z, im(a)); - quit "Bad first argument for checkappr()"; + quit "Bad first argument for checkappr()"; } -define checkresult(x,y,z,a) /* tests correctness of a = appr(x,y,z) */ +define checkresult(x,y,z,a) /* tests correctness of a = appr(x,y,z) */ { - local r, n, s, v; + local r, n, s, v; - if (y == 0) - return (a != x); - r = x - a; - n = a/y; + if (y == 0) + return (a != x); + r = x - a; + n = a/y; - if (!isint(n)) - return 1; - if (abs(r) >= abs(y)) - return 1; - if (r == 0) - return 0; - if (z & 16) { - if (abs(r) > abs(y)/2) - return 1; - if (abs(r) < abs(y)/2) - return 0; - z &= 15; - } - s = sgn(r); - switch (z) { - case 0: v = (s == sgn(y)); break; - case 1: v = (s == -sgn(y)); break; - case 2: v = (s == sgn(x)); break; - case 3: v = (s == -sgn(x)); break; - case 4: v = (s > 0); break; - case 5: v = (s < 0); break; - case 6: v = (s == sgn(x/y)); break; - case 7: v = (s == -sgn(x/y)); break; - case 8: v = iseven(n); break; - case 9: v = isodd(n); break; - case 10: v = (x/y > 0) ? iseven(n) : isodd(n); break; - case 11: v = (x/y > 0) ? isodd(n) : iseven(n); break; - case 12: v = (y > 0) ? iseven(n) : isodd(n); break; - case 13: v = (y > 0) ? isodd(n) : iseven(n); break; - case 14: v = (x > 0) ? iseven(n) : isodd(n); break; - case 15: v = (x > 0) ? isodd(n) : iseven(n); break; - } - return !v; + if (!isint(n)) + return 1; + if (abs(r) >= abs(y)) + return 1; + if (r == 0) + return 0; + if (z & 16) { + if (abs(r) > abs(y)/2) + return 1; + if (abs(r) < abs(y)/2) + return 0; + z &= 15; + } + s = sgn(r); + switch (z) { + case 0: v = (s == sgn(y)); break; + case 1: v = (s == -sgn(y)); break; + case 2: v = (s == sgn(x)); break; + case 3: v = (s == -sgn(x)); break; + case 4: v = (s > 0); break; + case 5: v = (s < 0); break; + case 6: v = (s == sgn(x/y)); break; + case 7: v = (s == -sgn(x/y)); break; + case 8: v = iseven(n); break; + case 9: v = isodd(n); break; + case 10: v = (x/y > 0) ? iseven(n) : isodd(n); break; + case 11: v = (x/y > 0) ? isodd(n) : iseven(n); break; + case 12: v = (y > 0) ? iseven(n) : isodd(n); break; + case 13: v = (y > 0) ? isodd(n) : iseven(n); break; + case 14: v = (x > 0) ? iseven(n) : isodd(n); break; + case 15: v = (x > 0) ? isodd(n) : iseven(n); break; + } + return !v; } /* @@ -570,43 +570,43 @@ define checkresult(x,y,z,a) /* tests correctness of a = appr(x,y,z) */ */ define test2600(verbose, tnum) { - local n; /* test parameter */ - local ep; /* test parameter */ - local i; + local n; /* test parameter */ + local ep; /* test parameter */ + local i; - /* set test parameters */ - n = 5; /* internal test loop count */ - if (isnull(verbose)) { - verbose = defaultverbose; - } - if (isnull(tnum)) { - tnum = 1; /* initial test number */ - } + /* set test parameters */ + n = 5; /* internal test loop count */ + if (isnull(verbose)) { + verbose = defaultverbose; + } + if (isnull(tnum)) { + tnum = 1; /* initial test number */ + } - /* - * test a lot of stuff - */ - srand(2600e2600); - ep = 1e-250; - err += testismult(strcat(str(tnum++), ": mult"), n*20, verbose); - err += testappr(strcat(str(tnum++), ": appr"), n*40, verbose); - err += testexp(strcat(str(tnum++),": exp"), n, ep, verbose); - err += testln(strcat(str(tnum++),": ln"), n, ep, verbose); - err += testpower(strcat(str(tnum++),": power"), n, - rand(2,10), ep, verbose); - err += testgcd(strcat(str(tnum++),": gcd"), n, ep, verbose); - for (i=0; i < 32; ++i) { - config("sqrt", i); - err += testsqrt(strcat(str(tnum++),": sqrt",str(i)), n*10, - ep, verbose); - } - err += testpower2(strcat(str(tnum++),": power"), n*4, ep, verbose); - if (verbose > 1) { - if (err) { - print "***", err, "error(s) found in test2600"; - } else { - print "no errors in test2600"; - } - } - return tnum; + /* + * test a lot of stuff + */ + srand(2600e2600); + ep = 1e-250; + err += testismult(strcat(str(tnum++), ": mult"), n*20, verbose); + err += testappr(strcat(str(tnum++), ": appr"), n*40, verbose); + err += testexp(strcat(str(tnum++),": exp"), n, ep, verbose); + err += testln(strcat(str(tnum++),": ln"), n, ep, verbose); + err += testpower(strcat(str(tnum++),": power"), n, + rand(2,10), ep, verbose); + err += testgcd(strcat(str(tnum++),": gcd"), n, ep, verbose); + for (i=0; i < 32; ++i) { + config("sqrt", i); + err += testsqrt(strcat(str(tnum++),": sqrt",str(i)), n*10, + ep, verbose); + } + err += testpower2(strcat(str(tnum++),": power"), n*4, ep, verbose); + if (verbose > 1) { + if (err) { + print "***", err, "error(s) found in test2600"; + } else { + print "no errors in test2600"; + } + } + return tnum; } diff --git a/cal/test2700.isqrt.cal b/cal/test2700.isqrt.cal index 627e404..301369f 100644 --- a/cal/test2700.isqrt.cal +++ b/cal/test2700.isqrt.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/11/01 22:52:25 - * File existed as early as: 1995 + * Under source code control: 1995/11/01 22:52:25 + * File existed as early as: 1995 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -40,25 +40,25 @@ defaultverbose = 1; define mknonnegreal() { - switch(rand(8)) { - case 0: return rand(20); - case 1: return rand(20,1000); - case 2: return rand(1,10000)/rand(1,100); - case 3: return scale(mkposreal(), rand(1,100)); - case 4: return scale(mkposreal(), -rand(1,100)); - case 5: return rand(1, 1000) + scale(mkfrac(),-rand(1,100)); - case 6: return mkposreal()^2; - case 7: return mkposreal() * (1+scale(mkfrac(),-rand(1,100))); - } + switch(rand(8)) { + case 0: return rand(20); + case 1: return rand(20,1000); + case 2: return rand(1,10000)/rand(1,100); + case 3: return scale(mkposreal(), rand(1,100)); + case 4: return scale(mkposreal(), -rand(1,100)); + case 5: return rand(1, 1000) + scale(mkfrac(),-rand(1,100)); + case 6: return mkposreal()^2; + case 7: return mkposreal() * (1+scale(mkfrac(),-rand(1,100))); + } } define mkposreal() { - local x; + local x; - x = mknonnegreal(); - while (x == 0) - x = mknonnegreal(); - return x; + x = mknonnegreal(); + while (x == 0) + x = mknonnegreal(); + return x; } define mkreal_2700() = rand(2) ? mknonnegreal() : -mknonnegreal(); @@ -67,15 +67,15 @@ define mknonzeroreal() = rand(2) ? mkposreal() : -mkposreal(); /* Number > 0 and < 1, almost uniformly distributed */ define mkposfrac() { - local x,y; + local x,y; - x = rand(1,1000); - do - y = rand(1,1000); - while (y == x); - if (x > y) - swap(x,y); - return x/y; + x = rand(1,1000); + do + y = rand(1,1000); + while (y == x); + if (x > y) + swap(x,y); + return x/y; } /* Nonzero > -1 and < 1 */ @@ -86,13 +86,13 @@ define mksquarereal() = mknonnegreal()^2; /* * We might be able to do better than the following. For non-square * positive integer less than 1e6, could use: - * x = rand(1, 1000); - * return rand(x^2 + 1, (x + 1)^2); + * x = rand(1, 1000); + * return rand(x^2 + 1, (x + 1)^2); * Maybe could do: - * do - * x = mkreal_2700(); - * while - * (issq(x)); + * do + * x = mkreal_2700(); + * while + * (issq(x)); * This would of course not be satisfactory for testing issq(). */ @@ -102,127 +102,127 @@ define mkcomplex_2700() = mkreal_2700() + 1i * mkreal_2700(); define testcsqrt(str, n, verbose) { - local x, y, z, m, i, p, v; + local x, y, z, m, i, p, v; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = 0; - for (i = 1; i <= n; i++) { - if (verbose > 1) print i,:; - x = rand(3) ? mkreal_2700(): mkcomplex_2700(); - y = scale(mknonzeroreal(), -100); - if (verbose > 2) - printf("%d: x = %d, y = %d\n", i, x, y); + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = 0; + for (i = 1; i <= n; i++) { + if (verbose > 1) print i,:; + x = rand(3) ? mkreal_2700(): mkcomplex_2700(); + y = scale(mknonzeroreal(), -100); + if (verbose > 2) + printf("%d: x = %d, y = %d\n", i, x, y); - for (z = 0; z < 128; z++) { - v = sqrt(x,y,z); - p = checksqrt(x,y,z,v); - if (p) { - if (verbose > 0) - printf( - "*** Type %d failure for x = %r, " - "y = %r, z = %d\n", - p, x, y, z); - m++; - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("no errors\n"); - } - } - return m; + for (z = 0; z < 128; z++) { + v = sqrt(x,y,z); + p = checksqrt(x,y,z,v); + if (p) { + if (verbose > 0) + printf( + "*** Type %d failure for x = %r, " + "y = %r, z = %d\n", + p, x, y, z); + m++; + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("no errors\n"); + } + } + return m; } -define checksqrt(x,y,z,v) /* Returns >0 if an error is detected */ +define checksqrt(x,y,z,v) /* Returns >0 if an error is detected */ { - local A, B, X, Y, t1, t2, eps, u, n, f, s; + local A, B, X, Y, t1, t2, eps, u, n, f, s; - A = re(x); - B = im(x); - X = re(v); - Y = im(v); + A = re(x); + B = im(x); + X = re(v); + Y = im(v); - /* checking signs of X and Y */ + /* checking signs of X and Y */ - if (B == 0 && A <= 0) /* t1 = sgn(re(tvsqrt)) */ - t1 = 0; - else - t1 = (z & 64) ? -1 : 1; + if (B == 0 && A <= 0) /* t1 = sgn(re(tvsqrt)) */ + t1 = 0; + else + t1 = (z & 64) ? -1 : 1; - t2 = B ? sgn(B) : (A < 0); /* t2 = sgn(im(tvsqrt)) */ - if (z & 64) - t2 = -t2; + t2 = B ? sgn(B) : (A < 0); /* t2 = sgn(im(tvsqrt)) */ + if (z & 64) + t2 = -t2; - if (t1 == 0 && X != 0) - return 1; + if (t1 == 0 && X != 0) + return 1; - if (t2 == 0 && Y != 0) { - printf("x = %d, Y = %d, t2 = %d\n", x, Y, t2); - return 2; - } + if (t2 == 0 && Y != 0) { + printf("x = %d, Y = %d, t2 = %d\n", x, Y, t2); + return 2; + } - if (X && sgn(X) != t1) - return 3; + if (X && sgn(X) != t1) + return 3; - if (Y && sgn(Y) != t2) - return 4; + if (Y && sgn(Y) != t2) + return 4; - if (z & 32 && iscomsq(x)) - return 5 * (x != v^2); + if (z & 32 && iscomsq(x)) + return 5 * (x != v^2); - eps = (z & 16) ? abs(y)/2 : abs(y); - u = sgn(y); + eps = (z & 16) ? abs(y)/2 : abs(y); + u = sgn(y); - /* Checking X */ + /* Checking X */ - n = X/y; - if (!isint(n)) - return 6; + n = X/y; + if (!isint(n)) + return 6; - if (t1) { - f = checkavrem(A, B, abs(X), eps); + if (t1) { + f = checkavrem(A, B, abs(X), eps); - if (z & 16 && f < 0) - return 7; - if (!(z & 16) && f <= 0) - return 8; + if (z & 16 && f < 0) + return 7; + if (!(z & 16) && f <= 0) + return 8; - if (!(z & 16) || f == 0) { - s = X ? t1 * sgn(A - X^2 + B^2/4/X^2) : t1; - if (s && !checkrounding(s,n,t1,u,z)) - return 9; - } - } + if (!(z & 16) || f == 0) { + s = X ? t1 * sgn(A - X^2 + B^2/4/X^2) : t1; + if (s && !checkrounding(s,n,t1,u,z)) + return 9; + } + } - /* Checking Y */ + /* Checking Y */ - n = Y/y; - if (!isint(n)) - return 10; + n = Y/y; + if (!isint(n)) + return 10; - if (t2) { - f = checkavrem(-A, B, abs(Y), eps); + if (t2) { + f = checkavrem(-A, B, abs(Y), eps); - if (z & 16 && f < 0) - return 11; - if (!(z & 16) && f <= 0) - return 12; + if (z & 16 && f < 0) + return 11; + if (!(z & 16) && f <= 0) + return 12; - if (!(z & 16) || f == 0) { - s = Y ? t2 * sgn(-A - Y^2 + B^2/4/Y^2) : t2; - if (s && !checkrounding(s,n,t2,u,z)) - return 13; - } - } - return 0; + if (!(z & 16) || f == 0) { + s = Y ? t2 * sgn(-A - Y^2 + B^2/4/Y^2) : t2; + if (s && !checkrounding(s,n,t2,u,z)) + return 13; + } + } + return 0; } /* @@ -233,61 +233,61 @@ define checksqrt(x,y,z,v) /* Returns >0 if an error is detected */ define checkavrem(A, B, X, eps) { - local f; + local f; - f = sgn(A - (X + eps)^2 + B^2/4/(X + eps)^2); - if (f > 0) - return -1; /* X < tv - eps */ - if (f == 0) - return 0; /* X = tv - eps */ + f = sgn(A - (X + eps)^2 + B^2/4/(X + eps)^2); + if (f > 0) + return -1; /* X < tv - eps */ + if (f == 0) + return 0; /* X = tv - eps */ - if (X > eps) { - f = sgn(A - (X - eps)^2 + B^2/4/(X - eps)^2); + if (X > eps) { + f = sgn(A - (X - eps)^2 + B^2/4/(X - eps)^2); - if (f < 0) - return -1; /* X > tv + eps */ - if (f == 0) - return 0; /* X = tv + eps */ - } - return 1; /* tv - eps < X < tv + eps */ + if (f < 0) + return -1; /* X > tv + eps */ + if (f == 0) + return 0; /* X = tv + eps */ + } + return 1; /* tv - eps < X < tv + eps */ } define checkrounding(s,n,t,u,z) { - local w; + local w; - switch (z & 15) { - case 0: w = (s == u); break; - case 1: w = (s == -u); break; - case 2: w = (s == t); break; - case 3: w = (s == -t); break; - case 4: w = (s > 0); break; - case 5: w = (s < 0); break; - case 6: w = (s == u/t); break; - case 7: w = (s == -u/t); break; - case 8: w = iseven(n); break; - case 9: w = isodd(n); break; - case 10: w = (u/t > 0) ? iseven(n) : isodd(n); break; - case 11: w = (u/t > 0) ? isodd(n) : iseven(n); break; - case 12: w = (u > 0) ? iseven(n) : isodd(n); break; - case 13: w = (u > 0) ? isodd(n) : iseven(n); break; - case 14: w = (t > 0) ? iseven(n) : isodd(n); break; - case 15: w = (t > 0) ? isodd(n) : iseven(n); break; - } - return w; + switch (z & 15) { + case 0: w = (s == u); break; + case 1: w = (s == -u); break; + case 2: w = (s == t); break; + case 3: w = (s == -t); break; + case 4: w = (s > 0); break; + case 5: w = (s < 0); break; + case 6: w = (s == u/t); break; + case 7: w = (s == -u/t); break; + case 8: w = iseven(n); break; + case 9: w = isodd(n); break; + case 10: w = (u/t > 0) ? iseven(n) : isodd(n); break; + case 11: w = (u/t > 0) ? isodd(n) : iseven(n); break; + case 12: w = (u > 0) ? iseven(n) : isodd(n); break; + case 13: w = (u > 0) ? isodd(n) : iseven(n); break; + case 14: w = (t > 0) ? iseven(n) : isodd(n); break; + case 15: w = (t > 0) ? isodd(n) : iseven(n); break; + } + return w; } define iscomsq(x) { - local c; + local c; - if (isreal(x)) - return issq(abs(x)); - c = norm(x); - if (!issq(c)) - return 0; - return issq((re(x) + sqrt(c,1,32))/2); + if (isreal(x)) + return issq(abs(x)); + c = norm(x); + if (!issq(c)) + return 0; + return issq((re(x) + sqrt(c,1,32))/2); } /* @@ -295,33 +295,33 @@ define iscomsq(x) */ define test2700(verbose, tnum) { - local n; /* test parameter */ - local ep; /* test parameter */ - local i; + local n; /* test parameter */ + local ep; /* test parameter */ + local i; - /* set test parameters */ - n = 32; /* internal test loop count */ - if (isnull(verbose)) { - verbose = defaultverbose; - } - if (isnull(tnum)) { - tnum = 1; /* initial test number */ - } + /* set test parameters */ + n = 32; /* internal test loop count */ + if (isnull(verbose)) { + verbose = defaultverbose; + } + if (isnull(tnum)) { + tnum = 1; /* initial test number */ + } - /* - * test a lot of stuff - */ - srand(2700e2700); - for (i=0; i < n; ++i) { - err += testcsqrt(strcat(str(tnum++),": complex sqrt",str(i)), - 1, verbose); - } - if (verbose > 1) { - if (err) { - print "***", err, "error(s) found in testall"; - } else { - print "no errors in testall"; - } - } - return tnum; + /* + * test a lot of stuff + */ + srand(2700e2700); + for (i=0; i < n; ++i) { + err += testcsqrt(strcat(str(tnum++),": complex sqrt",str(i)), + 1, verbose); + } + if (verbose > 1) { + if (err) { + print "***", err, "error(s) found in testall"; + } else { + print "no errors in testall"; + } + } + return tnum; } diff --git a/cal/test3100.matobj.cal b/cal/test3100.matobj.cal index ffd9c88..ca36e56 100644 --- a/cal/test3100.matobj.cal +++ b/cal/test3100.matobj.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/11/28 11:56:57 - * File existed as early as: 1995 + * Under source code control: 1995/11/28 11:56:57 + * File existed as early as: 1995 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ diff --git a/cal/test3300.det.cal b/cal/test3300.det.cal index 3e29373..0165bca 100644 --- a/cal/test3300.det.cal +++ b/cal/test3300.det.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,82 +19,82 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/12/02 04:27:41 - * File existed as early as: 1995 + * Under source code control: 1995/12/02 04:27:41 + * File existed as early as: 1995 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ -defaultverbose = 1; /* default verbose value */ +defaultverbose = 1; /* default verbose value */ define testi(str, n, N, verbose) { - local A, t, i, j, d1, d2; - local m; + local A, t, i, j, d1, d2; + local m; - if (isnull(verbose)) verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - if (isnull(N)) - N = 1e6; - mat A[n,n]; - for (i = 0; i < n; i++) - for (j = 0; j < n; j++) - A[i,j] = rand(-N, N); - t = runtime(); - d1 = det(A); - t = runtime() - t; - d2 = det(A^2); - if (d2 != d1^2) { - if (verbose > 0) { - printf("*** Failure for n=%d, N=%d, d1=%d\n", n, N, d1); - } - return 1; /* error */ - } else { - if (verbose > 0) { - printf("no errors\n"); - } - if (verbose > 1) { - printf("ok: n=%d, N=%d, d1=%d, t=%d\n", n, N, d1, t); - } - } - return 0; /* ok */ + if (isnull(verbose)) verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + if (isnull(N)) + N = 1e6; + mat A[n,n]; + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) + A[i,j] = rand(-N, N); + t = runtime(); + d1 = det(A); + t = runtime() - t; + d2 = det(A^2); + if (d2 != d1^2) { + if (verbose > 0) { + printf("*** Failure for n=%d, N=%d, d1=%d\n", n, N, d1); + } + return 1; /* error */ + } else { + if (verbose > 0) { + printf("no errors\n"); + } + if (verbose > 1) { + printf("ok: n=%d, N=%d, d1=%d, t=%d\n", n, N, d1, t); + } + } + return 0; /* ok */ } define testr(str, n, N, verbose) { - local A, t, i, j, d1, d2; + local A, t, i, j, d1, d2; - if (isnull(verbose)) verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - if (isnull(N)) - N = 1e6; - mat A[n,n]; - for (i = 0; i < n; i++) - for (j = 0; j < n; j++) - A[i,j] = rand(-(N^2), N^2)/rand(1, N); - t = usertime(); - d1 = det(A); - t = usertime() - t; - d2 = det(A^2); - if (d2 != d1^2) { - if (verbose > 0) { - printf("*** Failure for n=%d, N=%d, d1=%d\n", n, N, d1); - } - return 1; /* error */ - } else { - if (verbose > 0) { - printf("no errors\n"); - } - if (verbose > 1) { - printf("ok: n=%d, N=%d, d1=%d, t=%d\n", n, N, d1, t); - } - } - return 0; /* ok */ + if (isnull(verbose)) verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + if (isnull(N)) + N = 1e6; + mat A[n,n]; + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) + A[i,j] = rand(-(N^2), N^2)/rand(1, N); + t = usertime(); + d1 = det(A); + t = usertime() - t; + d2 = det(A^2); + if (d2 != d1^2) { + if (verbose > 0) { + printf("*** Failure for n=%d, N=%d, d1=%d\n", n, N, d1); + } + return 1; /* error */ + } else { + if (verbose > 0) { + printf("no errors\n"); + } + if (verbose > 1) { + printf("ok: n=%d, N=%d, d1=%d, t=%d\n", n, N, d1, t); + } + } + return 0; /* ok */ } /* @@ -102,39 +102,39 @@ define testr(str, n, N, verbose) */ define test3300(verbose, tnum) { - local N; /* test parameter */ - local i; + local N; /* test parameter */ + local i; - /* - * set test parameters - */ - if (isnull(verbose)) { - verbose = defaultverbose; - } - N = 1e6; - srand(3300e3300); + /* + * set test parameters + */ + if (isnull(verbose)) { + verbose = defaultverbose; + } + N = 1e6; + srand(3300e3300); - /* - * test a lot of stuff - */ - for (i=0; i < 19; ++i) { - err += testi(strcat(str(tnum++), ": testi(", str(i), ")"), \ - i, N, verbose); - } - for (i=0; i < 9; ++i) { - err += testr(strcat(str(tnum++), ": testr(", str(i), ")"), \ - i, N, verbose); - } + /* + * test a lot of stuff + */ + for (i=0; i < 19; ++i) { + err += testi(strcat(str(tnum++), ": testi(", str(i), ")"), \ + i, N, verbose); + } + for (i=0; i < 9; ++i) { + err += testr(strcat(str(tnum++), ": testr(", str(i), ")"), \ + i, N, verbose); + } - /* - * test results - */ - if (verbose > 1) { - if (err) { - print "***", err, "error(s) found in testall"; - } else { - print "no errors in testall"; - } - } - return tnum; + /* + * test results + */ + if (verbose > 1) { + if (err) { + print "***", err, "error(s) found in testall"; + } else { + print "no errors in testall"; + } + } + return tnum; } diff --git a/cal/test3400.trig.cal b/cal/test3400.trig.cal index e65dea1..cf39242 100644 --- a/cal/test3400.trig.cal +++ b/cal/test3400.trig.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/12/02 05:20:11 - * File existed as early as: 1995 + * Under source code control: 1995/12/02 05:20:11 + * File existed as early as: 1995 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -50,223 +50,223 @@ */ -defaultverbose = 1; /* default verbose value */ +defaultverbose = 1; /* default verbose value */ global pi1k = pi(1e-1000); define test3401(str, n, eps, verbose) { - local i, m, x, y, N; + local i, m, x, y, N; - if (isnull(verbose)) verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - if (isnull(n)) n = 250; - if (isnull(eps)) eps = epsilon(); + if (isnull(verbose)) verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + if (isnull(n)) n = 250; + if (isnull(eps)) eps = epsilon(); - m = 0; - N = pi(eps)/eps; - for (i = 0; i < n; i++) { - x = rand(1, N) * eps; - y = cot(x, eps); - if (verbose > 1) - printf("%r\n", x); - if (abs(acot(y, eps) - x) > eps) { - if (verbose > 1) { - printf("*** Failure for x = %r\n", x); - } - m++; - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("no errors\n"); - } - } - return m; + m = 0; + N = pi(eps)/eps; + for (i = 0; i < n; i++) { + x = rand(1, N) * eps; + y = cot(x, eps); + if (verbose > 1) + printf("%r\n", x); + if (abs(acot(y, eps) - x) > eps) { + if (verbose > 1) { + printf("*** Failure for x = %r\n", x); + } + m++; + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("no errors\n"); + } + } + return m; } define test3402(str, n, eps, verbose) { - local i, m, x, y, N; + local i, m, x, y, N; - if (isnull(verbose)) verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - if (isnull(n)) n = 250; - if (isnull(eps)) eps = epsilon(); + if (isnull(verbose)) verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + if (isnull(n)) n = 250; + if (isnull(eps)) eps = epsilon(); - eps = abs(eps); - m = 0; - N = 1e10; - for (i = 0; i < n; i++) { - x = rand(-N, N)/rand(1, N); - y = tan(x/2, eps) - csc(x,eps) + cot(x,eps); - if (verbose > 1) - printf("%r\n", x); - if (abs(y) > eps) { - if (verbose > 1) { - printf("*** Failure for x = %r\n", x); - } - m++; - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("no errors\n"); - } - } - return m; + eps = abs(eps); + m = 0; + N = 1e10; + for (i = 0; i < n; i++) { + x = rand(-N, N)/rand(1, N); + y = tan(x/2, eps) - csc(x,eps) + cot(x,eps); + if (verbose > 1) + printf("%r\n", x); + if (abs(y) > eps) { + if (verbose > 1) { + printf("*** Failure for x = %r\n", x); + } + m++; + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("no errors\n"); + } + } + return m; } define test3403(str, n, eps, verbose) { - local i, m, x, y, N; + local i, m, x, y, N; - if (isnull(verbose)) verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - if (isnull(n)) n = 250; - if (isnull(eps)) eps = epsilon(); + if (isnull(verbose)) verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + if (isnull(n)) n = 250; + if (isnull(eps)) eps = epsilon(); - eps = abs(eps); - m = 0; - N = 1e10; - for (i = 0; i < n; i++) { - x = rand(-N, N)/rand(1, N); - y = tan(x, eps) - cot(x,eps) + 2 * cot(2 * x,eps); - if (verbose > 1) - printf("%r\n", x); - if (abs(y) > eps) { - m++; - if (verbose > 1) { - printf("*** Failure for x = %r\n", x); - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("no errors\n"); - } - } - return m; + eps = abs(eps); + m = 0; + N = 1e10; + for (i = 0; i < n; i++) { + x = rand(-N, N)/rand(1, N); + y = tan(x, eps) - cot(x,eps) + 2 * cot(2 * x,eps); + if (verbose > 1) + printf("%r\n", x); + if (abs(y) > eps) { + m++; + if (verbose > 1) { + printf("*** Failure for x = %r\n", x); + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("no errors\n"); + } + } + return m; } define test3404(str, n, eps, verbose) { - local i, m, x, y, N; + local i, m, x, y, N; - if (isnull(verbose)) verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - if (isnull(n)) n = 250; - if (isnull(eps)) eps = epsilon(); + if (isnull(verbose)) verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + if (isnull(n)) n = 250; + if (isnull(eps)) eps = epsilon(); - eps = abs(eps); - m = 0; - N = 1e10; - for (i = 0; i < n; i++) { - x = rand(-N, N)/rand(1, N); - y = cot(x/2, eps) - csc(x,eps) - cot(x,eps); - if (verbose > 1) - printf("%r\n", x); - if (abs(y) > eps) { - m++; - if (verbose > 1) { - printf("*** Failure for x = %r\n", x); - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("no errors\n"); - } - } - return m; + eps = abs(eps); + m = 0; + N = 1e10; + for (i = 0; i < n; i++) { + x = rand(-N, N)/rand(1, N); + y = cot(x/2, eps) - csc(x,eps) - cot(x,eps); + if (verbose > 1) + printf("%r\n", x); + if (abs(y) > eps) { + m++; + if (verbose > 1) { + printf("*** Failure for x = %r\n", x); + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("no errors\n"); + } + } + return m; } define test3405(str, n, eps, verbose) { - local i, m, x, y, N; + local i, m, x, y, N; - if (isnull(verbose)) verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - if (isnull(n)) n = 250; - if (isnull(eps)) eps = epsilon(); + if (isnull(verbose)) verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + if (isnull(n)) n = 250; + if (isnull(eps)) eps = epsilon(); - m = 0; - N = pi(eps)/eps; - N = quo(N, 2, 0); - for (i = 0; i < n; i++) { - x = rand(-N, N) * eps; - y = tan(x, eps); - if (verbose > 1) - printf("%r\n", x); - if (atan(y, eps) != x) { - m++; - if (verbose > 1) { - printf("*** Failure for x = %r\n", x); - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("no errors\n"); - } - } - return m; + m = 0; + N = pi(eps)/eps; + N = quo(N, 2, 0); + for (i = 0; i < n; i++) { + x = rand(-N, N) * eps; + y = tan(x, eps); + if (verbose > 1) + printf("%r\n", x); + if (atan(y, eps) != x) { + m++; + if (verbose > 1) { + printf("*** Failure for x = %r\n", x); + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("no errors\n"); + } + } + return m; } define test3406(str, n, eps, verbose) { - local i, m, x, y, z, N; + local i, m, x, y, z, N; - if (isnull(verbose)) verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - if (isnull(n)) n = 250; - if (isnull(eps)) eps = epsilon(); + if (isnull(verbose)) verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + if (isnull(n)) n = 250; + if (isnull(eps)) eps = epsilon(); - m = 0; - for (i = 0; i < n; i++) { - x = rand(-1e10, 1e10)/rand(1, 1e10); - N = rand(-1e10, 1e10); - y = sec(x, eps); - z = sec(x + 2 * N * pi1k, eps); - if (verbose > 1) - printf("%r, %d\n", x, N); - if (abs(y-z) > eps) { - m++; - if (verbose > 1) { - printf("*** Failure for x = %r\n", x); - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("no errors\n"); - } - } - return m; + m = 0; + for (i = 0; i < n; i++) { + x = rand(-1e10, 1e10)/rand(1, 1e10); + N = rand(-1e10, 1e10); + y = sec(x, eps); + z = sec(x + 2 * N * pi1k, eps); + if (verbose > 1) + printf("%r, %d\n", x, N); + if (abs(y-z) > eps) { + m++; + if (verbose > 1) { + printf("*** Failure for x = %r\n", x); + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("no errors\n"); + } + } + return m; } /* @@ -274,45 +274,45 @@ define test3406(str, n, eps, verbose) */ define test3400(verbose, tnum) { - local n; /* test parameter */ - local eps; /* test parameter */ - local i; + local n; /* test parameter */ + local eps; /* test parameter */ + local i; - /* - * set test parameters - */ - if (isnull(verbose)) { - verbose = defaultverbose; - } - n = 250; - eps = epsilon(); - srand(3400e3400); + /* + * set test parameters + */ + if (isnull(verbose)) { + verbose = defaultverbose; + } + n = 250; + eps = epsilon(); + srand(3400e3400); - /* - * test a lot of stuff - */ - err += test3401(strcat(str(tnum++), \ - ": acot(cot(x))"), n, eps, verbose); - err += test3402(strcat(str(tnum++), \ - ": tan(x/2)-csc(x)+cot(x)"), n, eps, verbose); - err += test3403(strcat(str(tnum++), \ - ": tan(x)-cot(x)+2*cot(2*x)"), n, eps, verbose); - err += test3404(strcat(str(tnum++), \ - ": cot(x/2)-csc(x)-cot(x)"), n, eps, verbose); - err += test3405(strcat(str(tnum++), \ - ": atan(tan(x))"), n, eps, verbose); - err += test3406(strcat(str(tnum++), \ - ": sec(x)-sec(x+2*N*pi)"), n, eps, verbose); + /* + * test a lot of stuff + */ + err += test3401(strcat(str(tnum++), \ + ": acot(cot(x))"), n, eps, verbose); + err += test3402(strcat(str(tnum++), \ + ": tan(x/2)-csc(x)+cot(x)"), n, eps, verbose); + err += test3403(strcat(str(tnum++), \ + ": tan(x)-cot(x)+2*cot(2*x)"), n, eps, verbose); + err += test3404(strcat(str(tnum++), \ + ": cot(x/2)-csc(x)-cot(x)"), n, eps, verbose); + err += test3405(strcat(str(tnum++), \ + ": atan(tan(x))"), n, eps, verbose); + err += test3406(strcat(str(tnum++), \ + ": sec(x)-sec(x+2*N*pi)"), n, eps, verbose); - /* - * test results - */ - if (verbose > 1) { - if (err) { - print "***", err, "error(s) found in test3400"; - } else { - print "no errors in test3400"; - } - } - return tnum; + /* + * test results + */ + if (verbose > 1) { + if (err) { + print "***", err, "error(s) found in test3400"; + } else { + print "no errors in test3400"; + } + } + return tnum; } diff --git a/cal/test4000.ptest.cal b/cal/test4000.ptest.cal index 5170e43..63fda93 100644 --- a/cal/test4000.ptest.cal +++ b/cal/test4000.ptest.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1996/03/13 02:38:45 - * File existed as early as: 1996 + * Under source code control: 1996/03/13 02:38:45 + * File existed as early as: 1996 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -31,47 +31,47 @@ * rlen(N) for N > 0 generates a random N-word positive integer. * * plen(N) for N > 0 generates an almost certainly prime positive - * integer whose word-count is about N. + * integer whose word-count is about N. * * clen(N) for N > 0 generates a composite odd N-word integer. * * ptimes(str, N [, n [, count [, skip, [, verbose]]]]) - * tests, and finds the runtime, for - * ptest(x, count, skip) for n random almost certainly prime integers x - * with word-count about N; n defaults to ceil(K1/abs(count)/(H1 + N^3)), - * count to COUNT, skip to SKIP. + * tests, and finds the runtime, for + * ptest(x, count, skip) for n random almost certainly prime integers x + * with word-count about N; n defaults to ceil(K1/abs(count)/(H1 + N^3)), + * count to COUNT, skip to SKIP. * * ctimes(str, N [, n [, count [, skip, [, verbose]]]]) - * tests, and finds the runtime, for - * ptest(x, count, skip) for n random composite integers x with word-count - * about N; n defaults to ceil(K2/(H2 + N^3)), count to COUNT, skip - * to SKIP. + * tests, and finds the runtime, for + * ptest(x, count, skip) for n random composite integers x with word-count + * about N; n defaults to ceil(K2/(H2 + N^3)), count to COUNT, skip + * to SKIP. * * crtimes(str,a,b,n, [,count [, skip, [, verbose]]]) - * tests, and finds the runtime, - * for ptest(x, count, skip) for n random integers x between a and b; - * count defaults to COUNT, skip to SKIP. + * tests, and finds the runtime, + * for ptest(x, count, skip) for n random integers x between a and b; + * count defaults to COUNT, skip to SKIP. * * ntimes (str, N [,n, [, count [, skip [, residue [, modulus[,verb]]]]]]) tests - * and finds the runtime for nextcand(...) and prevcand (...) for - * n integers x with word-count about N, etc. n defaults to - * ceil(K3/(H3 + N^3)); + * and finds the runtime for nextcand(...) and prevcand (...) for + * n integers x with word-count about N, etc. n defaults to + * ceil(K3/(H3 + N^3)); * * testnextcand(str, N [, n [, count [, skip [, residue [, modulus [, verb]]]]]) - * performs tests of nextcand(x, count, skip, residue, modulus) - * for n values of x with word-count N; n defaults to - * ceil(K3/(H3 + N^3)), count to COUNT, skip to SKIP, residue to 0, - * modulus to 1. + * performs tests of nextcand(x, count, skip, residue, modulus) + * for n values of x with word-count N; n defaults to + * ceil(K3/(H3 + N^3)), count to COUNT, skip to SKIP, residue to 0, + * modulus to 1. * * testprevcand(str, N [, n [, count [, skip [, residue [, modulus [, verb]]]]]) - * performs tests of prevcand(x, count, skip, residue, modulus) - * for n values of x with word-count N; n defaults to - * ceil(K3/(H3 + N^3)), count to COUNT, skip to SKIP, residue to 0, - * modulus to 1. + * performs tests of prevcand(x, count, skip, residue, modulus) + * for n values of x with word-count N; n defaults to + * ceil(K3/(H3 + N^3)), count to COUNT, skip to SKIP, residue to 0, + * modulus to 1. */ -defaultverbose = 1; /* default verbose value */ +defaultverbose = 1; /* default verbose value */ /* * test defaults @@ -97,324 +97,324 @@ global H3 = 10; define rlen(N) { - if (!isint(N) || N <= 0) - quit "Bad argument for rlen"; - return rand(BASE^(N-1), BASE^N); + if (!isint(N) || N <= 0) + quit "Bad argument for rlen"; + return rand(BASE^(N-1), BASE^N); } define plen(N) = nextcand(rlen(N), 10, 0); define clen(N) { - local n, v; + local n, v; - do { - v = rlen(N); - if (iseven(v)) - v++; - } - while - (ptest(v, 10, 0)); - return v; + do { + v = rlen(N); + if (iseven(v)) + v++; + } + while + (ptest(v, 10, 0)); + return v; } define ptimes(str, N, n, count, skip, verbose) { - local A, i, t, p, m; + local A, i, t, p, m; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = 0; - if (isnull(count)) - count = COUNT; - if (isnull(n)) { - n = ceil(K1/abs(count)/(H1 + N^3)); - if (verbose > 1) { - print "n =",n; - } - } - if (isnull(skip)) - skip = SKIP; - mat A[n]; - for (i = 0; i < n; i++) - A[i] = plen(N); - t = usertime(); - for (i = 0; i < n; i++) { - p = ptest(A[i], count, skip); - if (!p) { - if (verbose > 0) { - printf("*** Error for x = %d\n", A[i]); - m++; - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - t = round(usertime() - t, 4); - if (verbose > 1) { - printf("%d probable primes: time = %d\n", n, t); - } else { - printf("%d probable primes: passed\n", n); - } - } - } - return m; + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = 0; + if (isnull(count)) + count = COUNT; + if (isnull(n)) { + n = ceil(K1/abs(count)/(H1 + N^3)); + if (verbose > 1) { + print "n =",n; + } + } + if (isnull(skip)) + skip = SKIP; + mat A[n]; + for (i = 0; i < n; i++) + A[i] = plen(N); + t = usertime(); + for (i = 0; i < n; i++) { + p = ptest(A[i], count, skip); + if (!p) { + if (verbose > 0) { + printf("*** Error for x = %d\n", A[i]); + m++; + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + t = round(usertime() - t, 4); + if (verbose > 1) { + printf("%d probable primes: time = %d\n", n, t); + } else { + printf("%d probable primes: passed\n", n); + } + } + } + return m; } define ctimes(str, N, n, count, skip, verbose) { - local A, i, r, t, p, m; + local A, i, r, t, p, m; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = 0; - if (isnull(count)) - count = COUNT; - if (isnull(n)) { - n = ceil(K2/(H2 + N^3)); - if (verbose > 1) { - print "n =",n; - } - } - if (isnull(skip)) - skip = SKIP; - mat A[n]; - for (i = 0; i < n; i++) - A[i] = clen(N); - t = usertime(); - for (i = 0; i < n; i++) { - p = ptest(A[i], count, skip); - if (p) { - if (verbose > 0) { - printf("*** Error, what should be rare " - "has occurred for x = %d \n", A[i]); - m++; - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - t = round(usertime() - t, 4); - if (verbose > 1) { - printf("%d probable primes: time = %d\n", n, t); - } else { - printf("%d probable primes: passed\n", n); - } - } - } - return m; + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = 0; + if (isnull(count)) + count = COUNT; + if (isnull(n)) { + n = ceil(K2/(H2 + N^3)); + if (verbose > 1) { + print "n =",n; + } + } + if (isnull(skip)) + skip = SKIP; + mat A[n]; + for (i = 0; i < n; i++) + A[i] = clen(N); + t = usertime(); + for (i = 0; i < n; i++) { + p = ptest(A[i], count, skip); + if (p) { + if (verbose > 0) { + printf("*** Error, what should be rare " + "has occurred for x = %d \n", A[i]); + m++; + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + t = round(usertime() - t, 4); + if (verbose > 1) { + printf("%d probable primes: time = %d\n", n, t); + } else { + printf("%d probable primes: passed\n", n); + } + } + } + return m; } define crtimes(str, a, b, n, count, skip, verbose) { - local A, P, i, t, p, m; + local A, P, i, t, p, m; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = 0; - if (b < a) - swap(a,b); - b++; - if (isnull(count)) - count = COUNT; - if (isnull(skip)) - skip = SKIP; - mat A[n]; - mat P[n]; - for (i = 0; i < n; i++) { - A[i] = rand(a,b); - P[i] = ptest(A[i], 20, 0); - } - t = usertime(); - for (i = 0; i < n; i++) { - p = ptest(A[i], count, skip); - if (p != P[i]) { - if (verbose > 0) { - printf("*** Apparent error for %s x = %d\n", - P[i] ? "prime" : "composite", A[i]); - ++m; - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)?\n", m); - } else { - t = round(usertime() - t, 4); - if (verbose > 1) { - printf("%d probable primes: time = %d\n", n, t); - } else { - printf("%d probable primes: passed\n", n); - } - } - } - return m; + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = 0; + if (b < a) + swap(a,b); + b++; + if (isnull(count)) + count = COUNT; + if (isnull(skip)) + skip = SKIP; + mat A[n]; + mat P[n]; + for (i = 0; i < n; i++) { + A[i] = rand(a,b); + P[i] = ptest(A[i], 20, 0); + } + t = usertime(); + for (i = 0; i < n; i++) { + p = ptest(A[i], count, skip); + if (p != P[i]) { + if (verbose > 0) { + printf("*** Apparent error for %s x = %d\n", + P[i] ? "prime" : "composite", A[i]); + ++m; + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)?\n", m); + } else { + t = round(usertime() - t, 4); + if (verbose > 1) { + printf("%d probable primes: time = %d\n", n, t); + } else { + printf("%d probable primes: passed\n", n); + } + } + } + return m; } define ntimes(str, N, n, count, skip, residue, modulus, verbose) { - local A, i, t, p, tnext, tprev; + local A, i, t, p, tnext, tprev; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - if (isnull(count)) - count = COUNT; - if (isnull(n)) { - n = ceil(K3/(H3 + N^3)); - if (verbose > 1) { - print "n =",n; - } - } - if (isnull(skip)) - skip = SKIP; - if (isnull(residue)) - residue = RESIDUE; - if (isnull(modulus)) - modulus = MODULUS; + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + if (isnull(count)) + count = COUNT; + if (isnull(n)) { + n = ceil(K3/(H3 + N^3)); + if (verbose > 1) { + print "n =",n; + } + } + if (isnull(skip)) + skip = SKIP; + if (isnull(residue)) + residue = RESIDUE; + if (isnull(modulus)) + modulus = MODULUS; - mat A[n]; - for (i = 0; i < n; i++) - A[i] = rlen(N); - t = usertime(); - for (i = 0; i < n; i++) { - p = nextcand(A[i], count, skip, residue, modulus); - } - tnext = round(usertime() - t, 4); - t = usertime(); - for (i = 0; i < n; i++) { - p = prevcand(A[i], count, skip, residue, modulus); - } - tprev = round(usertime() - t, 4); - if (verbose > 0) { - printf("%d evaluations, nextcand: %d, " - "prevcand: %d\n", n, tnext, tprev); - } + mat A[n]; + for (i = 0; i < n; i++) + A[i] = rlen(N); + t = usertime(); + for (i = 0; i < n; i++) { + p = nextcand(A[i], count, skip, residue, modulus); + } + tnext = round(usertime() - t, 4); + t = usertime(); + for (i = 0; i < n; i++) { + p = prevcand(A[i], count, skip, residue, modulus); + } + tprev = round(usertime() - t, 4); + if (verbose > 0) { + printf("%d evaluations, nextcand: %d, " + "prevcand: %d\n", n, tnext, tprev); + } } define testnextcand(str, N, n, count, skip, residue, modulus, verbose) { - local p, x, y, i, m; + local p, x, y, i, m; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = 0; - if (isnull(count)) - count = COUNT; - if (isnull(n)) { - n = ceil(K3/(H3 + N^3)); - print "n =",n; - } - if (isnull(skip)) - skip = SKIP; - if (isnull(residue)) - residue = RESIDUE; - if (isnull(modulus)) - modulus = MODULUS; - for (i = 0; i < n; i++) { - x = rlen(N); - y = nextcand(x, count, skip, residue, modulus); - p = testnext1(x, y, count, skip, residue, modulus); - if (p) { - m++; - if (verbose > 1) { - printf("*** Failure %d for x = %d\n", p, x); - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)?\n", m); - } else { - printf("%d successful tests\n", n); - } - } - return m; + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = 0; + if (isnull(count)) + count = COUNT; + if (isnull(n)) { + n = ceil(K3/(H3 + N^3)); + print "n =",n; + } + if (isnull(skip)) + skip = SKIP; + if (isnull(residue)) + residue = RESIDUE; + if (isnull(modulus)) + modulus = MODULUS; + for (i = 0; i < n; i++) { + x = rlen(N); + y = nextcand(x, count, skip, residue, modulus); + p = testnext1(x, y, count, skip, residue, modulus); + if (p) { + m++; + if (verbose > 1) { + printf("*** Failure %d for x = %d\n", p, x); + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)?\n", m); + } else { + printf("%d successful tests\n", n); + } + } + return m; } define testnext1(x, y, count, skip, residue, modulus) { - if (y <= x) - return 1; - if (!ptest(y, count, skip)) - return 2; - if (mne(y, residue, modulus)) - return 3; - return 0; + if (y <= x) + return 1; + if (!ptest(y, count, skip)) + return 2; + if (mne(y, residue, modulus)) + return 3; + return 0; } define testprevcand(str, N, n, count, skip, residue, modulus, verbose) { - local p, x, y, i, m; + local p, x, y, i, m; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = 0; - if (isnull(count)) - count = COUNT; - if (isnull(n)) { - n = ceil(K3/(H3 + N^3)); - print "n =",n; - } - if (isnull(skip)) - skip = SKIP; - if (isnull(residue)) - residue = RESIDUE; - if (isnull(modulus)) - modulus = MODULUS; - for (i = 0; i < n; i++) { - x = rlen(N); - y = prevcand(x, count, skip, residue, modulus); - p = testprev1(x, y, count, skip, residue, modulus); - if (p) { - m++; - if (verbose > 1) { - printf("*** Failure %d for x = %d\n", p, x); - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)?\n", m); - } else { - printf("%d successful tests\n", n); - } - } - return m; + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = 0; + if (isnull(count)) + count = COUNT; + if (isnull(n)) { + n = ceil(K3/(H3 + N^3)); + print "n =",n; + } + if (isnull(skip)) + skip = SKIP; + if (isnull(residue)) + residue = RESIDUE; + if (isnull(modulus)) + modulus = MODULUS; + for (i = 0; i < n; i++) { + x = rlen(N); + y = prevcand(x, count, skip, residue, modulus); + p = testprev1(x, y, count, skip, residue, modulus); + if (p) { + m++; + if (verbose > 1) { + printf("*** Failure %d for x = %d\n", p, x); + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)?\n", m); + } else { + printf("%d successful tests\n", n); + } + } + return m; } define testprev1(x, y, count, skip, residue, modulus) { - if (y >= x) - return 1; - if (!ptest(y, count, skip)) - return 2; - if (mne(y, residue, modulus)) - return 3; - return 0; + if (y >= x) + return 1; + if (!ptest(y, count, skip)) + return 2; + if (mne(y, residue, modulus)) + return 3; + return 0; } /* @@ -422,52 +422,52 @@ define testprev1(x, y, count, skip, residue, modulus) */ define test4000(v, tnum) { - local n; /* test parameter */ + local n; /* test parameter */ - /* - * set test parameters - */ - srand(4000e4000); + /* + * set test parameters + */ + srand(4000e4000); - /* - * test a lot of stuff - */ - err += ptimes(strcat(str(tnum++),": ptimes(1,250)"), 1, 250,,,v); - err += ptimes(strcat(str(tnum++),": ptimes(3,50)"), 3, 50,,,v); - err += ptimes(strcat(str(tnum++),": ptimes(5,20)"), 5, 20,,,v); + /* + * test a lot of stuff + */ + err += ptimes(strcat(str(tnum++),": ptimes(1,250)"), 1, 250,,,v); + err += ptimes(strcat(str(tnum++),": ptimes(3,50)"), 3, 50,,,v); + err += ptimes(strcat(str(tnum++),": ptimes(5,20)"), 5, 20,,,v); - err += ctimes(strcat(str(tnum++),": ctimes(1,7500)"), 1, 7500,,,v); - err += ctimes(strcat(str(tnum++),": ctimes(3,500)"), 3, 500,,,v); - err += ctimes(strcat(str(tnum++),": ctimes(5,200)"), 5, 200,,,v); + err += ctimes(strcat(str(tnum++),": ctimes(1,7500)"), 1, 7500,,,v); + err += ctimes(strcat(str(tnum++),": ctimes(3,500)"), 3, 500,,,v); + err += ctimes(strcat(str(tnum++),": ctimes(5,200)"), 5, 200,,,v); - err += crtimes(strcat(str(tnum++),": crtimes(2^30,2^31,2500)"), - 2^30, 2^31, 2500,,,v); - err += crtimes(strcat(str(tnum++),": crtimes(2^300,2^301,75)"), - 2^300, 2^301, 75,,,v); + err += crtimes(strcat(str(tnum++),": crtimes(2^30,2^31,2500)"), + 2^30, 2^31, 2500,,,v); + err += crtimes(strcat(str(tnum++),": crtimes(2^300,2^301,75)"), + 2^300, 2^301, 75,,,v); - err += testprevcand(strcat(str(tnum++),": testprevcand(1,250)"), - 1, 250, ,,,,v); - err += testprevcand(strcat(str(tnum++),": testprevcand(3,25)"), - 3, 25, ,,,,v); - err += testprevcand(strcat(str(tnum++),": testprevcand(5,10)"), - 5, 10, ,,,,v); + err += testprevcand(strcat(str(tnum++),": testprevcand(1,250)"), + 1, 250, ,,,,v); + err += testprevcand(strcat(str(tnum++),": testprevcand(3,25)"), + 3, 25, ,,,,v); + err += testprevcand(strcat(str(tnum++),": testprevcand(5,10)"), + 5, 10, ,,,,v); - err += testnextcand(strcat(str(tnum++),": testnextcand(1,250)"), - 1, 250, ,,,,v); - err += testnextcand(strcat(str(tnum++),": testnextcand(3,25)"), - 3, 25, ,,,,v); - err += testnextcand(strcat(str(tnum++),": testnextcand(5,10)"), - 5, 10, ,,,,v); + err += testnextcand(strcat(str(tnum++),": testnextcand(1,250)"), + 1, 250, ,,,,v); + err += testnextcand(strcat(str(tnum++),": testnextcand(3,25)"), + 3, 25, ,,,,v); + err += testnextcand(strcat(str(tnum++),": testnextcand(5,10)"), + 5, 10, ,,,,v); - /* - * report results - */ - if (v > 1) { - if (err) { - print "***", err, "error(s) found in testall"; - } else { - print "no errors in testall"; - } - } - return tnum; + /* + * report results + */ + if (v > 1) { + if (err) { + print "***", err, "error(s) found in testall"; + } else { + print "no errors in testall"; + } + } + return tnum; } diff --git a/cal/test4100.redc.cal b/cal/test4100.redc.cal index bf487be..abf76c4 100644 --- a/cal/test4100.redc.cal +++ b/cal/test4100.redc.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,54 +19,54 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1996/03/13 03:53:22 - * File existed as early as: 1996 + * Under source code control: 1996/03/13 03:53:22 + * File existed as early as: 1996 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * Some severe tests and timing functions for REDC functions and pmod. * * testall(str,n,N,M,verbose) - * performs n tests using arguments x, y, ... - * randomly selected from [-N, N) or when nonnegative values are - * required, [0, N), and m an odd positive integer in [1,N], - * and where a "small" (say less than 10000) exponent k is to be - * used (when computing x^k % m directly) k is random in [0,M). - * Default values for N and M are 1e20 and 100. + * performs n tests using arguments x, y, ... + * randomly selected from [-N, N) or when nonnegative values are + * required, [0, N), and m an odd positive integer in [1,N], + * and where a "small" (say less than 10000) exponent k is to be + * used (when computing x^k % m directly) k is random in [0,M). + * Default values for N and M are 1e20 and 100. * * times(str,N,n,verbose) - * gives times for n evaluations of rcin, etc. with - * N-word arguments; default n is ceil(K1/power(N,1.585). + * gives times for n evaluations of rcin, etc. with + * N-word arguments; default n is ceil(K1/power(N,1.585). * * powtimes(str, N1,N2,n, verbose) - * gives times for n evaluations of pmod(x,k,m) - * for the three algorithms "small", "normal", "bignum" that - * pmod may use, and equivalent functions rcpow(xr,k,m) for - * "small" or "bignum" cases, where xr = rcin(x,m). The - * modulus m is a random positive odd N1-word number; x has - * random integer values in [0, m-1]; k has random N2-word values. - * N2 defaults to 1; n defaults to ceil(K2/power(N1,1.585)/N2). + * gives times for n evaluations of pmod(x,k,m) + * for the three algorithms "small", "normal", "bignum" that + * pmod may use, and equivalent functions rcpow(xr,k,m) for + * "small" or "bignum" cases, where xr = rcin(x,m). The + * modulus m is a random positive odd N1-word number; x has + * random integer values in [0, m-1]; k has random N2-word values. + * N2 defaults to 1; n defaults to ceil(K2/power(N1,1.585)/N2). * * inittimes(str, N, n, verbose) - * displays the times and tests n evaluations of rcin(x,m) - * and rcout(x,m) where m is a random positive odd N-word integer, - * x is a random integer in [0, m-1]; n defaults to ceil(K1/N^2). + * displays the times and tests n evaluations of rcin(x,m) + * and rcout(x,m) where m is a random positive odd N-word integer, + * x is a random integer in [0, m-1]; n defaults to ceil(K1/N^2). * * rlen_4100(N) - * generates a random positive N-word integer. The global - * BASEB should be set to the word-size for the computer being - * used. The parameters K1, K2 which control the default n - * should be adjusted to give reasonable runtimes. + * generates a random positive N-word integer. The global + * BASEB should be set to the word-size for the computer being + * used. The parameters K1, K2 which control the default n + * should be adjusted to give reasonable runtimes. * * olen(N) - * generates a random odd positive N-word number. + * generates a random odd positive N-word number. * */ -defaultverbose = 1; /* default verbose value */ +defaultverbose = 1; /* default verbose value */ /* * test defaults @@ -79,371 +79,371 @@ define rlen_4100(N) = rand(test4100_BASE^(N-1), test4100_BASE^N); define olen(N) { - local v; + local v; - v = rlen_4100(N); - if (iseven(v)) - v++; - return v; + v = rlen_4100(N); + if (iseven(v)) + v++; + return v; } define test4101(x,y,m,k,z1,z2,verbose) { - local xr, yr, v, w, oneone; + local xr, yr, v, w, oneone; - if (isnull(verbose)) - verbose = defaultverbose; - xr = rcin(x,m); - yr = rcin(y,m); - oneone = rcin(rcin(1,m),m); + if (isnull(verbose)) + verbose = defaultverbose; + xr = rcin(x,m); + yr = rcin(y,m); + oneone = rcin(rcin(1,m),m); - if (xr >= m || xr < 0) { - if (verbose > 1) - printf("Failure 1 for x = %d, m = %d\n", x, m); - return 1; - } - if (rcin(x * y, m) != mod(xr * y, m, 0)) { - if (verbose > 1) { - printf("Failure 2 for x = %d, y = %d, m = %d\n", - x, y, m); - } - return 2; - } - if (rcout(xr, m) != x % m) { - if (verbose > 1) - printf("Failure 3 for x = %d, m = %d\n", x, m); - return 3; - } - if (rcout(rcmul(xr,yr,m),m) != mod(x * y, m, 0)) { - if (verbose > 1) - printf("Failure 4 for x = %d, y = %d, m = %d\n", - x, y, m); - return 4; - } - if (rcmul(x,yr,m) != mod(x * y, m, 0)) { - if (verbose > 1) - printf("Failure 5 for x = %d, y = %d, m = %d\n", - x, y, m); - return 5; - } - if (rcin(rcmul(x,y,m),m) != mod(x * y, m, 0)) { - if (verbose > 1) - printf("Failure 6 for x = %d, y = %d, m = %d\n", - x, y, m); - return 6; - } - if (rcout(rcsq(xr,m),m) != mod(x^2, m, 0)) { - if (verbose > 1) - printf("Failure 7 for x = %d, m = %d\n", x, m); - return 7; - } - if (rcin(rcsq(x,m),m) != mod(x^2, m, 0)) { - if (verbose > 1) - printf("Failure 8 for x = %d, m = %d\n", - x, y, m); - return 8; - } - if (rcout(rcpow(xr,k,m),m) != mod(x^k, m, 0)) { - if (verbose > 1) - printf("Failure 9 for x = %d, m = %d, k = %d\n", - x, m, k); - return 9; - } - if (rcpow(x,k,m) != rcin(rcout(x,m)^k, m)) { - if (verbose > 1) - printf("Failure 10: x = %d, k = %d, m = %d\n", - x, k, m); - return 10; - } - if (rcpow(x, z1 * z2, m) != rcpow(rcpow(x,z1,m), z2, m)) { - if (verbose > 1) - printf("Failure 11: x = %d, z1 = %d, z2 = %d, m = %d\n", - x, z1, z2, m); - return 11; - } - if (xr != rcmul(oneone, x, m)) { - if (verbose > 1) - printf("Failure 12: x = %d, m = %d\n", x, m); - return 12; - } + if (xr >= m || xr < 0) { + if (verbose > 1) + printf("Failure 1 for x = %d, m = %d\n", x, m); + return 1; + } + if (rcin(x * y, m) != mod(xr * y, m, 0)) { + if (verbose > 1) { + printf("Failure 2 for x = %d, y = %d, m = %d\n", + x, y, m); + } + return 2; + } + if (rcout(xr, m) != x % m) { + if (verbose > 1) + printf("Failure 3 for x = %d, m = %d\n", x, m); + return 3; + } + if (rcout(rcmul(xr,yr,m),m) != mod(x * y, m, 0)) { + if (verbose > 1) + printf("Failure 4 for x = %d, y = %d, m = %d\n", + x, y, m); + return 4; + } + if (rcmul(x,yr,m) != mod(x * y, m, 0)) { + if (verbose > 1) + printf("Failure 5 for x = %d, y = %d, m = %d\n", + x, y, m); + return 5; + } + if (rcin(rcmul(x,y,m),m) != mod(x * y, m, 0)) { + if (verbose > 1) + printf("Failure 6 for x = %d, y = %d, m = %d\n", + x, y, m); + return 6; + } + if (rcout(rcsq(xr,m),m) != mod(x^2, m, 0)) { + if (verbose > 1) + printf("Failure 7 for x = %d, m = %d\n", x, m); + return 7; + } + if (rcin(rcsq(x,m),m) != mod(x^2, m, 0)) { + if (verbose > 1) + printf("Failure 8 for x = %d, m = %d\n", + x, y, m); + return 8; + } + if (rcout(rcpow(xr,k,m),m) != mod(x^k, m, 0)) { + if (verbose > 1) + printf("Failure 9 for x = %d, m = %d, k = %d\n", + x, m, k); + return 9; + } + if (rcpow(x,k,m) != rcin(rcout(x,m)^k, m)) { + if (verbose > 1) + printf("Failure 10: x = %d, k = %d, m = %d\n", + x, k, m); + return 10; + } + if (rcpow(x, z1 * z2, m) != rcpow(rcpow(x,z1,m), z2, m)) { + if (verbose > 1) + printf("Failure 11: x = %d, z1 = %d, z2 = %d, m = %d\n", + x, z1, z2, m); + return 11; + } + if (xr != rcmul(oneone, x, m)) { + if (verbose > 1) + printf("Failure 12: x = %d, m = %d\n", x, m); + return 12; + } - return 0; + return 0; } define testall(str,n,N,M,verbose) { - local i, p, x, y, z1, z2, c, k, m; + local i, p, x, y, z1, z2, c, k, m; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = 0; - if (isnull(N)) - N = 1e20; - if (isnull(M)) - M = 100; - c = 0; - for (i = 0; i < n; i++) { - x = rand(-N, N); - y = rand(-N, N); - z1 = rand(N); - z2 = rand(N); - c = rand(N); - if (iseven(c)) - c++; - k = rand(M); - if (verbose > 1) - printf("x = %d, y = %d, c = %d, k = %d\n", x, y, c, k); - p = test4101(x,y,c,k,z1,z2); - if (p) { - m++; - if (verbose > 0) { - printf("*** Failure %d in test %d\n", p, i); - } - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("passed %d tests\n", n); - } - } - return m; + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = 0; + if (isnull(N)) + N = 1e20; + if (isnull(M)) + M = 100; + c = 0; + for (i = 0; i < n; i++) { + x = rand(-N, N); + y = rand(-N, N); + z1 = rand(N); + z2 = rand(N); + c = rand(N); + if (iseven(c)) + c++; + k = rand(M); + if (verbose > 1) + printf("x = %d, y = %d, c = %d, k = %d\n", x, y, c, k); + p = test4101(x,y,c,k,z1,z2); + if (p) { + m++; + if (verbose > 0) { + printf("*** Failure %d in test %d\n", p, i); + } + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("passed %d tests\n", n); + } + } + return m; } define times(str,N,n,verbose) { - local m, m2, A, B, C, x, y, t, i, z; - local trcin, trcout, trcmul, trcsq; - local tmul, tsq, tmod, tquomod; + local m, m2, A, B, C, x, y, t, i, z; + local trcin, trcout, trcmul, trcsq; + local tmul, tsq, tmod, tquomod; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = olen(N); - m2 = m^2; - if (isnull(n)) { - n = ceil(test4100_K1/power(N,1.585)); - if (verbose > 1) - printf("n = %d\n", n); - } - mat A[n]; - mat B[n]; - mat C[n]; - for (i = 0; i < n; i++) { - A[i] = rand(m); - B[i] = rand(m); - C[i] = rand(m2); - } - z = rcin(0,m); /* to initialize redc and maybe lastmod information */ - t = usertime(); - for (i = 0; i < n; i++) - z = rcin(A[i],m); - trcin = round(usertime() - t, 3); - t = usertime(); - for (i = 0; i < n; i++) - z = rcout(A[i],m); - trcout = round(usertime() - t, 3); - t = usertime(); - for (i = 0; i < n; i++) - z = rcmul(A[i],B[i],m); - trcmul = round(usertime() - t, 3); - t = usertime(); - for (i = 0; i < n; i++) - z = rcsq(A[i],m); - trcsq = round(usertime() - t, 3); - t = usertime(); - for (i = 0; i < n; i++) - z = A[i] * B[i]; - tmul = round(usertime() - t, 3); - t = usertime(); - for (i = 0; i < n; i++) - z = A[i]^2; - tsq = round(usertime() - t, 3); - t = usertime(); - for (i = 0; i < n; i++) - z = C[i] % A[i]; - tmod = round(usertime() - t, 3); - t = usertime(); - for (i = 0; i < n; i++) - quomod(C[i], A[i], x, y); - tquomod = round(usertime() - t,3); + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = olen(N); + m2 = m^2; + if (isnull(n)) { + n = ceil(test4100_K1/power(N,1.585)); + if (verbose > 1) + printf("n = %d\n", n); + } + mat A[n]; + mat B[n]; + mat C[n]; + for (i = 0; i < n; i++) { + A[i] = rand(m); + B[i] = rand(m); + C[i] = rand(m2); + } + z = rcin(0,m); /* to initialize redc and maybe lastmod information */ + t = usertime(); + for (i = 0; i < n; i++) + z = rcin(A[i],m); + trcin = round(usertime() - t, 3); + t = usertime(); + for (i = 0; i < n; i++) + z = rcout(A[i],m); + trcout = round(usertime() - t, 3); + t = usertime(); + for (i = 0; i < n; i++) + z = rcmul(A[i],B[i],m); + trcmul = round(usertime() - t, 3); + t = usertime(); + for (i = 0; i < n; i++) + z = rcsq(A[i],m); + trcsq = round(usertime() - t, 3); + t = usertime(); + for (i = 0; i < n; i++) + z = A[i] * B[i]; + tmul = round(usertime() - t, 3); + t = usertime(); + for (i = 0; i < n; i++) + z = A[i]^2; + tsq = round(usertime() - t, 3); + t = usertime(); + for (i = 0; i < n; i++) + z = C[i] % A[i]; + tmod = round(usertime() - t, 3); + t = usertime(); + for (i = 0; i < n; i++) + quomod(C[i], A[i], x, y); + tquomod = round(usertime() - t,3); - if (verbose > 1) { - printf("rcin: %d, rcout: %d, rcmul: %d, rcsq: %d\n", - trcin, trcout, trcmul, trcsq); - printf("%s: mul: %d, sq: %d, mod: %d, quomod: %d\n", - str, tmul, tsq, tmod, tquomod); - } else if (verbose > 0) { - printf("no error(s)\n"); - } - return 0; + if (verbose > 1) { + printf("rcin: %d, rcout: %d, rcmul: %d, rcsq: %d\n", + trcin, trcout, trcmul, trcsq); + printf("%s: mul: %d, sq: %d, mod: %d, quomod: %d\n", + str, tmul, tsq, tmod, tquomod); + } else if (verbose > 0) { + printf("no error(s)\n"); + } + return 0; } define powtimes(str, N1, N2, n, verbose) { - local A, Ar, B, v, i, t, z1, z2, z3, z4, z5, cp, crc; - local tsmall, tnormal, tbignum, trcsmall, trcbig, m; + local A, Ar, B, v, i, t, z1, z2, z3, z4, z5, cp, crc; + local tsmall, tnormal, tbignum, trcsmall, trcbig, m; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = 0; + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = 0; - if (isnull(N2)) - N2 = 1; + if (isnull(N2)) + N2 = 1; - if (isnull(n)) { - n = ceil(test4100_K2/power(N1, 1.585)/N2); - printf ("n = %d\n", n); - } - mat A[n]; - mat Ar[n]; - mat B[n]; - v = olen(N1); + if (isnull(n)) { + n = ceil(test4100_K2/power(N1, 1.585)/N2); + printf ("n = %d\n", n); + } + mat A[n]; + mat Ar[n]; + mat B[n]; + v = olen(N1); - cp = config("pow2", 2); - crc = config("redc2", 2); + cp = config("pow2", 2); + crc = config("redc2", 2); - /* initialize redc and lastmod info */ + /* initialize redc and lastmod info */ - z1 = z2 = z3 = z4 = z5 = rcin(0,v); + z1 = z2 = z3 = z4 = z5 = rcin(0,v); - for (i = 0; i < n; i++) { - A[i] = rand(v); - Ar[i] = rcin(A[i], v); - B[i] = rlen_4100(N2); - } - t = usertime(); - for (i = 0; i < n; i++) - z1 += pmod(A[i], B[i], v); - tbignum = round(usertime() - t, 4); - config("pow2", 1e6); - t = usertime(); - for (i = 0; i < n; i++) - z2 += pmod(A[i], B[i], v); - tnormal = round(usertime() - t, 4); - config("redc2",1e6); - t = usertime(); - for (i = 0; i < n; i++) - z3 += pmod(A[i], B[i], v); - tsmall = round(usertime() - t, 4); - t = usertime(); - for (i = 0; i < n; i++) - z4 += rcpow(Ar[i], B[i], v); - trcsmall = round(usertime() - t, 4); - config("redc2", 2); - t = usertime(); - for (i = 0; i < n; i++) - z5 += rcpow(Ar[i], B[i], v); - trcbig = round(usertime() - t, 4); + for (i = 0; i < n; i++) { + A[i] = rand(v); + Ar[i] = rcin(A[i], v); + B[i] = rlen_4100(N2); + } + t = usertime(); + for (i = 0; i < n; i++) + z1 += pmod(A[i], B[i], v); + tbignum = round(usertime() - t, 4); + config("pow2", 1e6); + t = usertime(); + for (i = 0; i < n; i++) + z2 += pmod(A[i], B[i], v); + tnormal = round(usertime() - t, 4); + config("redc2",1e6); + t = usertime(); + for (i = 0; i < n; i++) + z3 += pmod(A[i], B[i], v); + tsmall = round(usertime() - t, 4); + t = usertime(); + for (i = 0; i < n; i++) + z4 += rcpow(Ar[i], B[i], v); + trcsmall = round(usertime() - t, 4); + config("redc2", 2); + t = usertime(); + for (i = 0; i < n; i++) + z5 += rcpow(Ar[i], B[i], v); + trcbig = round(usertime() - t, 4); - if (z1 != z2) { - ++m; - if (verbose > 0) { - print "*** z1 != z2"; - } - } else if (z1 != z3) { - ++m; - if (verbose > 0) { - print "*** z1 != z3"; - } - } else if (z2 != z3) { - ++m; - if (verbose > 0) { - print "*** z2 != z3"; - } - } else if (rcout(z4, v) != z1 % v) { - ++m; - if (verbose > 0) { - print "*** z4 != z1"; - } - } else if (z4 != z5) { - ++m; - if (verbose > 0) { - print "*** z4 != z5"; - } - } - config("pow2", cp); - config("redc2", crc); - if (verbose > 1) { - } - if (verbose > 1) { - printf("Small: %d, normal: %d, bignum: %d\n", - tsmall, tnormal, tbignum); - printf("%s: rcsmall: %d, rcbig: %d\n", - str, trcsmall, trcbig); - } else if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("passed\n"); - } - } - return 0; + if (z1 != z2) { + ++m; + if (verbose > 0) { + print "*** z1 != z2"; + } + } else if (z1 != z3) { + ++m; + if (verbose > 0) { + print "*** z1 != z3"; + } + } else if (z2 != z3) { + ++m; + if (verbose > 0) { + print "*** z2 != z3"; + } + } else if (rcout(z4, v) != z1 % v) { + ++m; + if (verbose > 0) { + print "*** z4 != z1"; + } + } else if (z4 != z5) { + ++m; + if (verbose > 0) { + print "*** z4 != z5"; + } + } + config("pow2", cp); + config("redc2", crc); + if (verbose > 1) { + } + if (verbose > 1) { + printf("Small: %d, normal: %d, bignum: %d\n", + tsmall, tnormal, tbignum); + printf("%s: rcsmall: %d, rcbig: %d\n", + str, trcsmall, trcbig); + } else if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("passed\n"); + } + } + return 0; } define inittimes(str,N,n,verbose) { - local A, M, B, R, i, t, trcin, trcout, m; + local A, M, B, R, i, t, trcin, trcout, m; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = 0; - if (isnull(n)) { - n = ceil(test4100_K1/N^2); - if (verbose > 1) { - printf ("n = %d\n", n); - } - } - mat A[n]; - mat M[n]; - mat B[n]; - mat R[n]; - for (i = 0; i < n; i++) { - M[i] = olen(N); - A[i] = rand(M[i]); - } - t = usertime(); - for (i = 0; i < n; i++) - R[i] = rcin(A[i], M[i]); - trcin = round(usertime() - t, 4); - for (i = 0; i < n; i++) - B[i] = rcout(R[i], M[i]); - trcout = round(usertime() - t, 4); - for (i = 0; i < n; i++) { - if (B[i] != A[i]) { - ++m; - if (verbose > 0) { - print "*** Error!!!"; - } - break; - } - } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)?\n", m); - } else { - if (verbose > 1) { - printf("%d successful tests: rcin: %d, rcout: %d\n", - n, trcin, trcout); - } else { - printf("%d successful tests: passed\n", n); - } - } - } - return m; + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = 0; + if (isnull(n)) { + n = ceil(test4100_K1/N^2); + if (verbose > 1) { + printf ("n = %d\n", n); + } + } + mat A[n]; + mat M[n]; + mat B[n]; + mat R[n]; + for (i = 0; i < n; i++) { + M[i] = olen(N); + A[i] = rand(M[i]); + } + t = usertime(); + for (i = 0; i < n; i++) + R[i] = rcin(A[i], M[i]); + trcin = round(usertime() - t, 4); + for (i = 0; i < n; i++) + B[i] = rcout(R[i], M[i]); + trcout = round(usertime() - t, 4); + for (i = 0; i < n; i++) { + if (B[i] != A[i]) { + ++m; + if (verbose > 0) { + print "*** Error!!!"; + } + break; + } + } + if (verbose > 0) { + if (m) { + printf("*** %d error(s)?\n", m); + } else { + if (verbose > 1) { + printf("%d successful tests: rcin: %d, rcout: %d\n", + n, trcin, trcout); + } else { + printf("%d successful tests: passed\n", n); + } + } + } + return m; } /* @@ -451,40 +451,40 @@ define inittimes(str,N,n,verbose) */ define test4100(v, tnum) { - local n; /* test parameter */ + local n; /* test parameter */ - /* - * set test parameters - */ - srand(4100e4100); + /* + * set test parameters + */ + srand(4100e4100); - /* - * test a lot of stuff - */ - err += testall(strcat(str(tnum++),": testall(10,,500)"), 10,, 500, v); - err += testall(strcat(str(tnum++),": testall(200)"), 200,,, v); + /* + * test a lot of stuff + */ + err += testall(strcat(str(tnum++),": testall(10,,500)"), 10,, 500, v); + err += testall(strcat(str(tnum++),": testall(200)"), 200,,, v); - err += times(strcat(str(tnum++),": times(3,3000)"), 3, 3000, v); - err += times(strcat(str(tnum++),": times(30,300)"), 30, 300, v); - err += times(strcat(str(tnum++),": times(300,30)"), 300, 30, v); - err += times(strcat(str(tnum++),": times(1000,3)"), 1000, 3, v); + err += times(strcat(str(tnum++),": times(3,3000)"), 3, 3000, v); + err += times(strcat(str(tnum++),": times(30,300)"), 30, 300, v); + err += times(strcat(str(tnum++),": times(300,30)"), 300, 30, v); + err += times(strcat(str(tnum++),": times(1000,3)"), 1000, 3, v); - err += powtimes(strcat(str(tnum++),": powtimes(100)"),100,,v); - err += powtimes(strcat(str(tnum++),": powtimes(250)"),250,,v); + err += powtimes(strcat(str(tnum++),": powtimes(100)"),100,,v); + err += powtimes(strcat(str(tnum++),": powtimes(250)"),250,,v); - err += inittimes(strcat(str(tnum++),": inittimes(10)"),10,,v); - err += inittimes(strcat(str(tnum++),": inittimes(100,70)"),100,70,v); - err += inittimes(strcat(str(tnum++),": inittimes(1000,4)"),1000,4,v); + err += inittimes(strcat(str(tnum++),": inittimes(10)"),10,,v); + err += inittimes(strcat(str(tnum++),": inittimes(100,70)"),100,70,v); + err += inittimes(strcat(str(tnum++),": inittimes(1000,4)"),1000,4,v); - /* - * report results - */ - if (v > 1) { - if (err) { - print "***", err, "error(s) found in testall"; - } else { - print "no errors in testall"; - } - } - return tnum; + /* + * report results + */ + if (v > 1) { + if (err) { + print "***", err, "error(s) found in testall"; + } else { + print "no errors in testall"; + } + } + return tnum; } diff --git a/cal/test4600.fileop.cal b/cal/test4600.fileop.cal index 8644b2d..b16da00 100644 --- a/cal/test4600.fileop.cal +++ b/cal/test4600.fileop.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,14 +19,14 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1996/07/02 20:04:40 - * File existed as early as: 1996 + * Under source code control: 1996/07/02 20:04:40 + * File existed as early as: 1996 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ -defaultverbose = 1; /* default verbose value */ +defaultverbose = 1; /* default verbose value */ /* * test globals @@ -35,254 +35,254 @@ global A, f, pos; define stest(str, verbose) { - local x; + local x; - /* setup */ - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - x = rm("-f", "junk4600"); + /* setup */ + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + x = rm("-f", "junk4600"); - /* - * do file operations - */ - f = fopen("junk4600", "wb"); - if (iserror(f)) { - print 'failed'; - print '**** fopen("junk4600", "wb") failed'; - return 1; - } - if (iserror(fputs(f, - "Fourscore and seven years ago our fathers brought forth\n", - "on this continent a new nation, conceived in liberty and dedicated\n", - "to the proposition that all men are created equal.\n"))) { - print 'failed'; - print '**** fputs(f, "Fourscore ... failed'; - return 1; - } - if (iserror(freopen(f, "rb"))) { - print 'failed'; - print '**** iserror(freopen(f, "rb")) failed'; - return 1; - } - if (iserror(rewind(f))) { - print 'failed'; - print '**** iserror(rewind(f)) failed'; - return 1; - } - if (search(f, "and") != 10) { - print 'failed'; - print '**** search(f, "and") != 10 failed'; - return 1; - } - if (ftell(f) != 13) { - print 'failed'; - 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 (iserror(fseek(f, -4, 1))) { - print 'failed'; - print '**** iserror(fseek(f, -4, 1)) failed'; - return 1; - } - if (rsearch(f, "and") != 10) { - print 'failed'; - print '**** rsearch(f, "and") != 10 failed'; - return 1; - } - if (ftell(f) != 12) { - print 'failed'; - print '**** ftell(f) != 12 failed'; - return 1; - } - if (iserror(fseek(f, -4, 1))) { - print 'failed'; - print '**** iserror(fseek(f, -4, 1)) failed'; - return 1; - } - if (!isnull(rsearch(f, "and"))) { - print 'failed'; - print '**** !isnull(rsearch(f, "and")) failed'; - return 1; - } - if (ftell(f) != 0) { - print 'failed'; - print '**** ftell(f) != 0 failed'; - return 1; - } - if (iserror(fclose(f))) { - print 'failed'; - print '**** iserror(fclose(f)) failed'; - return 1; - } + /* + * do file operations + */ + f = fopen("junk4600", "wb"); + if (iserror(f)) { + print 'failed'; + print '**** fopen("junk4600", "wb") failed'; + return 1; + } + if (iserror(fputs(f, + "Fourscore and seven years ago our fathers brought forth\n", + "on this continent a new nation, conceived in liberty and dedicated\n", + "to the proposition that all men are created equal.\n"))) { + print 'failed'; + print '**** fputs(f, "Fourscore ... failed'; + return 1; + } + if (iserror(freopen(f, "rb"))) { + print 'failed'; + print '**** iserror(freopen(f, "rb")) failed'; + return 1; + } + if (iserror(rewind(f))) { + print 'failed'; + print '**** iserror(rewind(f)) failed'; + return 1; + } + if (search(f, "and") != 10) { + print 'failed'; + print '**** search(f, "and") != 10 failed'; + return 1; + } + if (ftell(f) != 13) { + print 'failed'; + 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 (iserror(fseek(f, -4, 1))) { + print 'failed'; + print '**** iserror(fseek(f, -4, 1)) failed'; + return 1; + } + if (rsearch(f, "and") != 10) { + print 'failed'; + print '**** rsearch(f, "and") != 10 failed'; + return 1; + } + if (ftell(f) != 12) { + print 'failed'; + print '**** ftell(f) != 12 failed'; + return 1; + } + if (iserror(fseek(f, -4, 1))) { + print 'failed'; + print '**** iserror(fseek(f, -4, 1)) failed'; + return 1; + } + if (!isnull(rsearch(f, "and"))) { + print 'failed'; + print '**** !isnull(rsearch(f, "and")) failed'; + return 1; + } + if (ftell(f) != 0) { + print 'failed'; + print '**** ftell(f) != 0 failed'; + return 1; + } + if (iserror(fclose(f))) { + print 'failed'; + print '**** iserror(fclose(f)) failed'; + return 1; + } - /* - * cleanup - */ - x = rm("junk4600"); - if (verbose > 0) { - printf("passed\n"); - } - return 0; + /* + * cleanup + */ + x = rm("junk4600"); + if (verbose > 0) { + printf("passed\n"); + } + return 0; } define ttest(str, m, n, verbose) { - local a, s, i, j; + local a, s, i, j; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - i = rm("-f", "junk4600"); - f = fopen("junk4600", "wb"); + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + i = rm("-f", "junk4600"); + f = fopen("junk4600", "wb"); - if (isnull(n)) - n = 4; - if (isnull(m)) - m = 4; + if (isnull(n)) + n = 4; + if (isnull(m)) + m = 4; - mat A[m]; - mat pos[m + 1]; + mat A[m]; + mat pos[m + 1]; - pos[0] = 0; - for (i = 0; i < m; i++) { - j = 1 + randbit(n); - a = ""; - while (j-- > 0) - a = strcat(a, char(rand(32, 127))); - A[i] = a; - fputs(f, a); - pos[i+1] = ftell(f); - if (verbose > 1) - printf("A[%d] has length %d\n", i, strlen(a)); - } - fflush(f); - if (verbose > 1) - printf("File has size %d\n", pos[i]); - freopen(f, "rb"); - if (size(f) != pos[i]) { - print 'failed'; - printf("**** Failure 1 for file size\n"); - return 1; - } - for (i = 0; i < m; i++) { - rewind(f); - for (;;) { - j = search(f, A[i]); - if (isnull(j) || j > pos[i]) { - print 'failed'; - printf("**** Failure 2 for i = %d\n", i); - return 1; - } - if (j == pos[i]) - break; - fseek(f, j + 1, 0); + pos[0] = 0; + for (i = 0; i < m; i++) { + j = 1 + randbit(n); + a = ""; + while (j-- > 0) + a = strcat(a, char(rand(32, 127))); + A[i] = a; + fputs(f, a); + pos[i+1] = ftell(f); + if (verbose > 1) + printf("A[%d] has length %d\n", i, strlen(a)); + } + fflush(f); + if (verbose > 1) + printf("File has size %d\n", pos[i]); + freopen(f, "rb"); + if (size(f) != pos[i]) { + print 'failed'; + printf("**** Failure 1 for file size\n"); + return 1; + } + for (i = 0; i < m; i++) { + rewind(f); + for (;;) { + j = search(f, A[i]); + if (isnull(j) || j > pos[i]) { + print 'failed'; + printf("**** Failure 2 for i = %d\n", i); + return 1; + } + if (j == pos[i]) + break; + fseek(f, j + 1, 0); - } - if (ftell(f) != pos[i + 1]) { - print 'failed'; - printf("**** Failure 3 for i = %d\n", i); - return 1; - } - } - for (i = m - 1; i >= 0; i--) { - fseek(f, 0, 2); - for (;;) { - j = rsearch(f, A[i]); - if (isnull(j) || j < pos[i]) { - print 'failed'; - printf("**** Failure 4 for i = %d\n", i); - return 1; - } - if (j == pos[i]) - break; - fseek(f, -1, 1); - } - if (ftell(f) != pos[i + 1] - 1) { - print 'failed'; - printf("**** Failure 5 for i = %d\n", i); - return 1; - } - } - if (iserror(fclose(f))) { - print 'failed'; - printf("**** Failure 6 for i = %d\n", i); - return 1; - } - i = rm("junk4600"); - if (verbose > 0) { - printf("passed\n"); - } - return 0; + } + if (ftell(f) != pos[i + 1]) { + print 'failed'; + printf("**** Failure 3 for i = %d\n", i); + return 1; + } + } + for (i = m - 1; i >= 0; i--) { + fseek(f, 0, 2); + for (;;) { + j = rsearch(f, A[i]); + if (isnull(j) || j < pos[i]) { + print 'failed'; + printf("**** Failure 4 for i = %d\n", i); + return 1; + } + if (j == pos[i]) + break; + fseek(f, -1, 1); + } + if (ftell(f) != pos[i + 1] - 1) { + print 'failed'; + printf("**** Failure 5 for i = %d\n", i); + return 1; + } + } + if (iserror(fclose(f))) { + print 'failed'; + printf("**** Failure 6 for i = %d\n", i); + return 1; + } + i = rm("junk4600"); + if (verbose > 0) { + printf("passed\n"); + } + return 0; } define sprint(x) { - local i, n; + local i, n; - n = strlen(x); - for (i = 1; i <= n; i++) print ord(substr(x, i, 1)),; - print; + n = strlen(x); + for (i = 1; i <= n; i++) print ord(substr(x, i, 1)),; + print; } define findline(f,s) { - if (!isfile(f)) - quit "First argument to be a file"; - if (!isstr(s)) - quit "Second argument to be a string"; - if (!isnull(search(f,s))) { - rsearch(f, "\n"); - print fgetline(f); - } + if (!isfile(f)) + quit "First argument to be a file"; + if (!isstr(s)) + quit "Second argument to be a string"; + if (!isnull(search(f,s))) { + rsearch(f, "\n"); + print fgetline(f); + } } define findlineold(f,s) { - local str; + local str; - if (!isfile(f)) - quit "First argument to be a file"; - if (!isstr(s)) - quit "Second argument to be a string"; + if (!isfile(f)) + quit "First argument to be a file"; + if (!isstr(s)) + quit "Second argument to be a string"; - while (!isnull(str = fgetline(f)) && strpos(str, s) == 0); - print str; + while (!isnull(str = fgetline(f)) && strpos(str, s) == 0); + print str; } /* @@ -290,32 +290,32 @@ define findlineold(f,s) */ define test4600(v, tnum) { - local n; /* test parameter */ - local i; + local n; /* test parameter */ + local i; - /* - * set test parameters - */ - srand(4600e4600); + /* + * set test parameters + */ + srand(4600e4600); - /* - * test a lot of stuff - */ - for (i=0; i < 10; ++i) { - err += ttest(strcat(str(tnum++), - ": ttest(",str(i),",",str(i),")"), i, i, v); - err += stest(strcat(str(tnum++), ": stest()"), v); - } + /* + * test a lot of stuff + */ + for (i=0; i < 10; ++i) { + err += ttest(strcat(str(tnum++), + ": ttest(",str(i),",",str(i),")"), i, i, v); + err += stest(strcat(str(tnum++), ": stest()"), v); + } - /* - * report results - */ - if (v > 1) { - if (err) { - print "****", err, "error(s) found in testall"; - } else { - print "no errors in testall"; - } - } - return tnum; + /* + * report results + */ + if (v > 1) { + if (err) { + print "****", err, "error(s) found in testall"; + } else { + print "no errors in testall"; + } + } + return tnum; } diff --git a/cal/test5100.newdecl.cal b/cal/test5100.newdecl.cal index 66616e0..81a6c39 100644 --- a/cal/test5100.newdecl.cal +++ b/cal/test5100.newdecl.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,14 +19,14 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1996/12/02 23:57:10 - * File existed as early as: 1996 + * Under source code control: 1996/12/02 23:57:10 + * File existed as early as: 1996 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ -defaultverbose = 1; /* default verbose value */ +defaultverbose = 1; /* default verbose value */ /* * We test the new code generator declaration scope and order. @@ -53,14 +53,14 @@ defaultverbose = 1; /* default verbose value */ */ define test5100(x) { - if (isint(x) && x > 0) { - if (iseven(x)) { - static a5100 = x; - a5100++; - } else { - static b5100 = x; - b5100++; - } - } - global a5100 = a5100, b5100 = b5100; + if (isint(x) && x > 0) { + if (iseven(x)) { + static a5100 = x; + a5100++; + } else { + static b5100 = x; + b5100++; + } + } + global a5100 = a5100, b5100 = b5100; } diff --git a/cal/test5200.globstat.cal b/cal/test5200.globstat.cal index 99d316f..799731c 100644 --- a/cal/test5200.globstat.cal +++ b/cal/test5200.globstat.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,25 +19,25 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/02/07 02:48:10 - * File existed as early as: 1997 + * Under source code control: 1997/02/07 02:48:10 + * File existed as early as: 1997 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ -defaultverbose = 1; /* default verbose value */ +defaultverbose = 1; /* default verbose value */ /* * test the fix of a global/static bug * * Given the following: * - * global a = 10; - * static a = 20; - * define f(x) = a + x; - * define g(x) {global a = 30; return a + x;} - * define h(x) = a + x; + * global a = 10; + * static a = 20; + * define f(x) = a + x; + * define g(x) {global a = 30; return a + x;} + * define h(x) = a + x; * * Older versions of */ diff --git a/cal/test8000.read.cal b/cal/test8000.read.cal index c755495..4025230 100644 --- a/cal/test8000.read.cal +++ b/cal/test8000.read.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1994/03/14 23:12:51 - * File existed as early as: 1994 + * Under source code control: 1994/03/14 23:12:51 + * File existed as early as: 1994 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ diff --git a/cal/test8400.quit.cal b/cal/test8400.quit.cal index 14d29e8..ccce6ca 100644 --- a/cal/test8400.quit.cal +++ b/cal/test8400.quit.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/10/31 01:00:03 - * File existed as early as: 1999 + * Under source code control: 1999/10/31 01:00:03 + * File existed as early as: 1999 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -38,7 +38,7 @@ define test8400() return x8401+s8401; } print "8402: parsed test8400()"; -vrfy(test8400() == 64434, '8403: test8400() == 64434'); +vrfy(test8400() == 64434, '8403: test8400() == 64434'); quit; prob('quit did not end test8400.cal'); diff --git a/cal/test8500.divmod.cal b/cal/test8500.divmod.cal index 29a6646..9e1535d 100644 --- a/cal/test8500.divmod.cal +++ b/cal/test8500.divmod.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/11/12 20:59:59 - * File existed as early as: 1999 + * Under source code control: 1999/11/12 20:59:59 + * File existed as early as: 1999 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -30,10 +30,10 @@ */ -global err_8500; /* divmod_8500 error count */ -global L_8500; /* list of problem values */ -global ver_8500; /* test verbosity - see setting comment near bottom */ -global old_seed_8500; /* old srand() seed */ +global err_8500; /* divmod_8500 error count */ +global L_8500; /* list of problem values */ +global ver_8500; /* test verbosity - see setting comment near bottom */ +global old_seed_8500; /* old srand() seed */ /* * save the config state so that we can change it and restore later @@ -45,73 +45,73 @@ global cfg_8500 = config("all"); * onetest_8500 - perform one division / remainder test * * Returns: - * 0 = test was successful - * >0 = test error indicator + * 0 = test was successful + * >0 = test error indicator */ define onetest_8500(a,b,rnd) { - local q, r, s, S; + local q, r, s, S; - /* - * set a random rounding mode - */ - config("quo", rnd), config("mod", rnd); + /* + * set a random rounding mode + */ + config("quo", rnd), config("mod", rnd); - /* - * perform the division and mod - */ - q = a // b; - r = a % b; + /* + * perform the division and mod + */ + q = a // b; + r = a % b; - /* - * verify the fundamental math - */ - if (a != q * b + r) - return 1; + /* + * verify the fundamental math + */ + if (a != q * b + r) + return 1; - /* - * determine if the rounding worked - */ - if (b) { - if (rnd & 16) - s = sgn(abs(r) - abs(b)/2); - else - s = sgn(abs(r) - abs(b)); + /* + * determine if the rounding worked + */ + if (b) { + if (rnd & 16) + s = sgn(abs(r) - abs(b)/2); + else + s = sgn(abs(r) - abs(b)); - if (s < 0 || r == 0) - return 0; + if (s < 0 || r == 0) + return 0; - if (s > 0) - return 2; + if (s > 0) + return 2; - if (((rnd & 16) && s == 0) || !(rnd & 16)) { + if (((rnd & 16) && s == 0) || !(rnd & 16)) { - S = sgn(r) * sgn(b); /* This is sgn(a/b) - a//b */ - switch (rnd & 15) { - case 0: return (S < 0) ? 3 : 0; - case 1: return (S > 0) ? 4 : 0; - case 2: return (S != sgn(a)*sgn(b)) ? 5 : 0; - case 3: return (S != -sgn(a)*sgn(b)) ? 6 : 0; - break; - case 4: return (S != sgn(b)) ? 7 : 0; - case 5: return (S != -sgn(b)) ? 8 : 0; - case 6: return (S != sgn(a)) ? 9 : 0; - case 7: return (S != -sgn(a)) ? 10 : 0; - case 8: return (isodd(q)) ? 11 : 0; - case 9: return (iseven(q)) ? 12 : 0; - case 10: return (iseven(q) != (a/b > 0)) ? 13:0; - case 11: return (isodd(q) != (a/b > 0)) ? 14:0; - case 12: return (iseven(q) != (b > 0)) ? 15 : 0; - case 13: return (isodd(q) != (b > 0)) ? 16 : 0; - case 14: return (iseven(q) != (a > 0)) ? 17 : 0; - case 15: return (isodd(q) != (a > 0)) ? 18 : 0; - } - } - } + S = sgn(r) * sgn(b); /* This is sgn(a/b) - a//b */ + switch (rnd & 15) { + case 0: return (S < 0) ? 3 : 0; + case 1: return (S > 0) ? 4 : 0; + case 2: return (S != sgn(a)*sgn(b)) ? 5 : 0; + case 3: return (S != -sgn(a)*sgn(b)) ? 6 : 0; + break; + case 4: return (S != sgn(b)) ? 7 : 0; + case 5: return (S != -sgn(b)) ? 8 : 0; + case 6: return (S != sgn(a)) ? 9 : 0; + case 7: return (S != -sgn(a)) ? 10 : 0; + case 8: return (isodd(q)) ? 11 : 0; + case 9: return (iseven(q)) ? 12 : 0; + case 10: return (iseven(q) != (a/b > 0)) ? 13:0; + case 11: return (isodd(q) != (a/b > 0)) ? 14:0; + case 12: return (iseven(q) != (b > 0)) ? 15 : 0; + case 13: return (isodd(q) != (b > 0)) ? 16 : 0; + case 14: return (iseven(q) != (a > 0)) ? 17 : 0; + case 15: return (isodd(q) != (a > 0)) ? 18 : 0; + } + } + } - /* - * all is well - */ - return 0; + /* + * all is well + */ + return 0; } @@ -135,96 +135,96 @@ define onetest_8500(a,b,rnd) { */ define divmod_8500(N = 10, M1 = 2^128, M2 = 2^64, testnum = 0) { - local a, b, i, v, rnd; - local errmsg; /* error message to display */ + local a, b, i, v, rnd; + local errmsg; /* error message to display */ - /* - * firewall - */ - if (!isint(M1) || M1 < 2) - quit "Bad second arg for dtest"; + /* + * firewall + */ + if (!isint(M1) || M1 < 2) + quit "Bad second arg for dtest"; - if (!isint(M2) || M2 < 2) - quit "Bad third arg for dtest"; + if (!isint(M2) || M2 < 2) + quit "Bad third arg for dtest"; - /* - * test setup - */ - err_8500 = 0; - L_8500 = list(); + /* + * test setup + */ + err_8500 = 0; + L_8500 = list(); - /* - * perform the random results - */ - for (i = 0; i < N; i++) { + /* + * perform the random results + */ + for (i = 0; i < N; i++) { - /* - * randomly select two values in the range controlled by M1,M2 - */ - a = rand(-M1+1, M1); - b = rand(-M2+1, M2); - if (rand(2)) { - a = (2 * a + 1) * b; - b *= 2; - } + /* + * randomly select two values in the range controlled by M1,M2 + */ + a = rand(-M1+1, M1); + b = rand(-M2+1, M2); + if (rand(2)) { + a = (2 * a + 1) * b; + b *= 2; + } - /* - * select one of the 32 rounding modes at random - */ - rnd = rand(32); + /* + * select one of the 32 rounding modes at random + */ + rnd = rand(32); - /* - * ver_8500 pre-test reporting - */ - if (ver_8500 > 1) - printf("Test %d: a = %d, b = %d, rnd = %d\n", - i, a, b, rnd); + /* + * ver_8500 pre-test reporting + */ + if (ver_8500 > 1) + printf("Test %d: a = %d, b = %d, rnd = %d\n", + i, a, b, rnd); - /* - * perform the actual test - */ - v = onetest_8500(a, b, rnd); + /* + * perform the actual test + */ + v = onetest_8500(a, b, rnd); - /* - * individual test analysis - */ - if (v != 0) { - err_8500++; - if (ver_8500 != 0) { - if (testnum > 0) { - errmsg = strprintf( - "Failure %d on test %d", v, i); - prob(errmsg); - } else { - printf("Failure %d on test %d", v, i); - } - } - append(L_8500, a, b, rnd); - } - } + /* + * individual test analysis + */ + if (v != 0) { + err_8500++; + if (ver_8500 != 0) { + if (testnum > 0) { + errmsg = strprintf( + "Failure %d on test %d", v, i); + prob(errmsg); + } else { + printf("Failure %d on test %d", v, i); + } + } + append(L_8500, a, b, rnd); + } + } - /* - * report in the results - */ - if (err_8500) { - if (testnum > 0) { - errmsg = strprintf( - "%d: divmod_8500(%d,,,%d): %d failures", - testnum, N, testnum, err_8500); - prob(errmsg); - } else { - printf("%s failure%s", err_8500, - (err_8500 > 1) ? "s" : ""); - } - } else { - if (testnum > 0) { - errmsg = strprintf("%d: divmod_8500(%d,,,%d)", - testnum, N, testnum); - vrfy(err_8500 == 0, errmsg); - } else { - print "No failure"; - } - } + /* + * report in the results + */ + if (err_8500) { + if (testnum > 0) { + errmsg = strprintf( + "%d: divmod_8500(%d,,,%d): %d failures", + testnum, N, testnum, err_8500); + prob(errmsg); + } else { + printf("%s failure%s", err_8500, + (err_8500 > 1) ? "s" : ""); + } + } else { + if (testnum > 0) { + errmsg = strprintf("%d: divmod_8500(%d,,,%d)", + testnum, N, testnum); + vrfy(err_8500 == 0, errmsg); + } else { + print "No failure"; + } + } } /* diff --git a/cal/test8600.maxargs.cal b/cal/test8600.maxargs.cal index 42133a0..00139bd 100644 --- a/cal/test8600.maxargs.cal +++ b/cal/test8600.maxargs.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2000/12/04 19:57:02 - * File existed as early as: 2000 + * Under source code control: 2000/12/04 19:57:02 + * File existed as early as: 2000 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -1315,7 +1315,7 @@ vrfy(hash_8600 == 1365716825, "8604: hash() called with 1024 args"); * int(hmean with 1024 args) */ hmean_8600 = int( - hmean(1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, + hmean(1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, diff --git a/cal/test8700.dotest.cal b/cal/test8700.dotest.cal index 2b9e390..7cdf865 100644 --- a/cal/test8700.dotest.cal +++ b/cal/test8700.dotest.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2006/05/20 14:10:11 - * File existed as early as: 2006 + * Under source code control: 2006/05/20 14:10:11 + * File existed as early as: 2006 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -64,10 +64,10 @@ define set8700_g(set8700_x) } obj set8700_point { - set8700_x, set8700_y, set8700_z + set8700_x, set8700_y, set8700_z } global mat set8700_c[] = { 1, 2+3i, -5+4i, 5i+6, -7i }; global mat set8700_e[] = { 0, 1, 0, 0, 2, -3/2, 2, -1/2, - -3, 0.5, -1.0, 0.5, 1.0, 0.0, 0.0, 0.0 }; + -3, 0.5, -1.0, 0.5, 1.0, 0.0, 0.0, 0.0 }; diff --git a/cal/test8900.special.cal b/cal/test8900.special.cal index 2778dfe..779f5e1 100644 --- a/cal/test8900.special.cal +++ b/cal/test8900.special.cal @@ -17,8 +17,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2013/08/11 01:31:28 - * File existed as early as: 2013 + * Under source code control: 2013/08/11 01:31:28 + * File existed as early as: 2013 */ @@ -52,37 +52,37 @@ define t01() local eps; eps = epsilon(1e-20); if (gamma(5) != 24) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if (!iserror(gamma(-5))) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if (abs(gamma(-5.5) - 0.01091265478190986298673234429) > __CZ__eps) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } if (abs - (gamma(5.5 + 5.5i) - - (-3.760669488993539011972109411 - 1.068828791178021218008599278i)) > - __CZ__eps) { - epsilon(eps); - return 4; + (gamma(5.5 + 5.5i) - + (-3.760669488993539011972109411 - 1.068828791178021218008599278i)) > + __CZ__eps) { + epsilon(eps); + return 4; } if (abs - (gamma(-5.5 + 5.5i) - - (-0.0000000031513765339396 - 0.00000000565396294185819i)) > - __CZ__eps) { - epsilon(eps); - return 5; + (gamma(-5.5 + 5.5i) - + (-0.0000000031513765339396 - 0.00000000565396294185819i)) > + __CZ__eps) { + epsilon(eps); + return 5; } if (abs - (gamma(-5.5 - 5.5i) - - (-0.0000000031513765339396 + 0.00000000565396294185819i)) > - __CZ__eps) { - epsilon(eps); - return 5; + (gamma(-5.5 - 5.5i) - + (-0.0000000031513765339396 + 0.00000000565396294185819i)) > + __CZ__eps) { + epsilon(eps); + return 5; } epsilon(eps); return 0; @@ -97,1505 +97,1505 @@ define t02(type) eps = epsilon(1e-20); if (!isnull(type)) { - /* test lngamma to higher precision */ - epsilon(1e-50) + /* test lngamma to higher precision */ + epsilon(1e-50) } if (!iserror(lngamma(-5))) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if (abs - (lngamma(-4.400) - - (-2.602796356578054085860353775504851660134124890968895 + - 9.424777960769379715387930149838508652591508198125317i)) > - __CZ__eps) { - epsilon(eps); - return 2; + (lngamma(-4.400) - + (-2.602796356578054085860353775504851660134124890968895 + + 9.424777960769379715387930149838508652591508198125317i)) > + __CZ__eps) { + epsilon(eps); + return 2; } if (abs - (lngamma(-3.400) - - (-1.121191815653838606981937409307733431762519256939740 + - 12.566370614359172953850573533118011536788677597500423i)) > - __CZ__eps) { - epsilon(eps); - return 3; + (lngamma(-3.400) - + (-1.121191815653838606981937409307733431762519256939740 + + 12.566370614359172953850573533118011536788677597500423i)) > + __CZ__eps) { + epsilon(eps); + return 3; } if (abs - (lngamma(-2.400) - - (0.1025836159682770986668378753392054643000824013774864 + - 3.1415926535897932384626433832795028841971693993751058i)) > - __CZ__eps) { - epsilon(eps); - return 4; + (lngamma(-2.400) - + (0.1025836159682770986668378753392054643000824013774864 + + 3.1415926535897932384626433832795028841971693993751058i)) > + __CZ__eps) { + epsilon(eps); + return 4; } if (abs - (lngamma(-1.400) - - (0.9780523533221770342957880219518966655729718736522287 + - 6.2831853071795864769252867665590057683943387987502116i)) > - __CZ__eps) { - epsilon(eps); - return 5; + (lngamma(-1.400) - + (0.9780523533221770342957880219518966655729718736522287 + + 6.2831853071795864769252867665590057683943387987502116i)) > + __CZ__eps) { + epsilon(eps); + return 5; } if (abs - (lngamma(-0.4000) - - (1.3145245899433899648003814321688887556844552489655721 - - 3.1415926535897932384626433832795028841971693993751058i)) > - __CZ__eps) { - epsilon(eps); - return 6; + (lngamma(-0.4000) - + (1.3145245899433899648003814321688887556844552489655721 - + 3.1415926535897932384626433832795028841971693993751058i)) > + __CZ__eps) { + epsilon(eps); + return 6; } if (abs - (lngamma(0.6000) - - (0.3982338580692348996168542204008776842343540290573096)) > - __CZ__eps) { - epsilon(eps); - return 7; + (lngamma(0.6000) - + (0.3982338580692348996168542204008776842343540290573096)) > + __CZ__eps) { + epsilon(eps); + return 7; } if (abs - (lngamma(1.600) - - (-0.112591765696755783588659875902784250643756767388458)) > - __CZ__eps) { - epsilon(eps); - return 8; + (lngamma(1.600) - + (-0.112591765696755783588659875902784250643756767388458)) > + __CZ__eps) { + epsilon(eps); + return 8; } if (abs - (lngamma(2.600) - - (0.3574118635489797700622771552455578140571422814237894)) > - __CZ__eps) { - epsilon(eps); - return 9; + (lngamma(2.600) - + (0.3574118635489797700622771552455578140571422814237894)) > + __CZ__eps) { + epsilon(eps); + return 9; } if (abs - (lngamma(3.600) - - (1.3129233085764161315150052635846887793368088719154788)) > - __CZ__eps) { - epsilon(eps); - return 10; + (lngamma(3.600) - + (1.3129233085764161315150052635846887793368088719154788)) > + __CZ__eps) { + epsilon(eps); + return 10; } if (abs - (lngamma(4.600) - - (2.5938571540384804491219685256617291171816887676527152)) > - __CZ__eps) { - epsilon(eps); - return 11; + (lngamma(4.600) - + (2.5938571540384804491219685256617291171816887676527152)) > + __CZ__eps) { + epsilon(eps); + return 11; } if (abs - (lngamma(5.600) - - (4.1199134575335297653279620242457375960984677282246333)) > - __CZ__eps) { - epsilon(eps); - return 12; + (lngamma(5.600) - + (4.1199134575335297653279620242457375960984677282246333)) > + __CZ__eps) { + epsilon(eps); + return 12; } if (abs - (lngamma(55.60) - - (166.72233170723938827069082693550384745200937091660266)) > - __CZ__eps) { - epsilon(eps); - return 13; + (lngamma(55.60) - + (166.72233170723938827069082693550384745200937091660266)) > + __CZ__eps) { + epsilon(eps); + return 13; } if (abs - (lngamma(56.60) - - (170.74051490849592496269608464261138016300186635704956)) > - __CZ__eps) { - epsilon(eps); - return 14; + (lngamma(56.60) - + (170.74051490849592496269608464261138016300186635704956)) > + __CZ__eps) { + epsilon(eps); + return 14; } if (abs - (lngamma(57.60) - - (174.77652389370506221274131245618033272827669850568250)) > - __CZ__eps) { - epsilon(eps); - return 15; + (lngamma(57.60) - + (174.77652389370506221274131245618033272827669850568250)) > + __CZ__eps) { + epsilon(eps); + return 15; } if (abs - (lngamma(58.60) - - (178.83004646140690776801720420409007933842357893886075)) > - __CZ__eps) { - epsilon(eps); - return 16; + (lngamma(58.60) - + (178.83004646140690776801720420409007933842357893886075)) > + __CZ__eps) { + epsilon(eps); + return 16; } if (abs - (lngamma(59.60) - - (182.90078115798987469935628513367638988912775224248394)) > - __CZ__eps) { - epsilon(eps); - return 17; + (lngamma(59.60) - + (182.90078115798987469935628513367638988912775224248394)) > + __CZ__eps) { + epsilon(eps); + return 17; } if (abs - (lngamma(60.60) - - (186.98843673206117877516518619701249930553373579376865)) > - __CZ__eps) { - epsilon(eps); - return 18; + (lngamma(60.60) - + (186.98843673206117877516518619701249930553373579376865)) > + __CZ__eps) { + epsilon(eps); + return 18; } if (abs - (lngamma(61.60) - - (191.09273162513644754284387036762182652754650758452049)) > - __CZ__eps) { - epsilon(eps); - return 19; + (lngamma(61.60) - + (191.09273162513644754284387036762182652754650758452049)) > + __CZ__eps) { + epsilon(eps); + return 19; } if (abs - (lngamma(62.60) - - (195.21339349567592163624487159872030105363069808249176)) > - __CZ__eps) { - epsilon(eps); - return 20; + (lngamma(62.60) - + (195.21339349567592163624487159872030105363069808249176)) > + __CZ__eps) { + epsilon(eps); + return 20; } if (abs - (lngamma(63.60) - - (199.35015877378197447832287757475132376767819599656051)) > - __CZ__eps) { - epsilon(eps); - return 21; + (lngamma(63.60) - + (199.35015877378197447832287757475132376767819599656051)) > + __CZ__eps) { + epsilon(eps); + return 21; } if (abs - (lngamma(64.60) - - (203.50277224412805093867906473893489617123556308738621)) > - __CZ__eps) { - epsilon(eps); - return 22; + (lngamma(64.60) - + (203.50277224412805093867906473893489617123556308738621)) > + __CZ__eps) { + epsilon(eps); + return 22; } if (abs - (lngamma(65.60) - - (207.67098665491660710433686745546968860453554400700257)) > - __CZ__eps) { - epsilon(eps); - return 23; + (lngamma(65.60) - + (207.67098665491660710433686745546968860453554400700257)) > + __CZ__eps) { + epsilon(eps); + return 23; } if (abs - (lngamma(-4.400 + 0.3000i) - - (-3.012170168780542935643977654089900903230224118194902 - - 14.995647773931851220184151830452947610096345479769497i)) > - __CZ__eps) { - epsilon(eps); - return 24; + (lngamma(-4.400 + 0.3000i) - + (-3.012170168780542935643977654089900903230224118194902 - + 14.995647773931851220184151830452947610096345479769497i)) > + __CZ__eps) { + epsilon(eps); + return 24; } if (abs - (lngamma(-3.400 + 0.3000i) - - (-1.528246633748315285937279325345084965509129720585190 - - 11.922131578600057457117323569444702920656889937242177i)) > - __CZ__eps) { - epsilon(eps); - return 25; + (lngamma(-3.400 + 0.3000i) - + (-1.528246633748315285937279325345084965509129720585190 - + 11.922131578600057457117323569444702920656889937242177i)) > + __CZ__eps) { + epsilon(eps); + return 25; } if (abs - (lngamma(-2.400 + 0.3000i) - - (-0.300593543742460500003778676081911614052942606849246 - - 8.8685462985380049870334027293206734277553648141421909i)) > - __CZ__eps) { - epsilon(eps); - return 26; + (lngamma(-2.400 + 0.3000i) - + (-0.300593543742460500003778676081911614052942606849246 - + 8.8685462985380049870334027293206734277553648141421909i)) > + __CZ__eps) { + epsilon(eps); + return 26; } if (abs - (lngamma(-1.400 + 0.3000i) - - (0.5826272868794220627005984935520030051588811118590927 - - 5.8513086394949731836021141952050415691313656065368892i)) > - __CZ__eps) { - epsilon(eps); - return 27; + (lngamma(-1.400 + 0.3000i) - + (0.5826272868794220627005984935520030051588811118590927 - + 5.8513086394949731836021141952050415691313656065368892i)) > + __CZ__eps) { + epsilon(eps); + return 27; } if (abs - (lngamma(-0.4000 + 0.3000i) - - (0.9415471834545804679163683919994364115087855350642294 - - 2.9208093191279264919817355540741378979796654077163755i)) > - __CZ__eps) { - epsilon(eps); - return 28; + (lngamma(-0.4000 + 0.3000i) - + (0.9415471834545804679163683919994364115087855350642294 - + 2.9208093191279264919817355540741378979796654077163755i)) > + __CZ__eps) { + epsilon(eps); + return 28; } if (abs - (lngamma(0.6000 + 0.3000i) - - (0.2484000028946351584991362705412598434332854007039741 - - 0.4227177743314176403219013995119576518240065994565821i)) > - __CZ__eps) { - epsilon(eps); - return 29; + (lngamma(0.6000 + 0.3000i) - + (0.2484000028946351584991362705412598434332854007039741 - + 0.4227177743314176403219013995119576518240065994565821i)) > + __CZ__eps) { + epsilon(eps); + return 29; } if (abs - (lngamma(1.600 + 0.3000i) - - (-0.150853845214250646823230280607484839757524852967790 + - 0.0409298346693884758923548319492567502045304548295381i)) > - __CZ__eps) { - epsilon(eps); - return 30; + (lngamma(1.600 + 0.3000i) - + (-0.150853845214250646823230280607484839757524852967790 + + 0.0409298346693884758923548319492567502045304548295381i)) > + __CZ__eps) { + epsilon(eps); + return 30; } if (abs - (lngamma(2.600 + 0.3000i) - - (0.3364259747848147735313925008357736575841632119933041 + - 0.2262777846650832407783807931778013947197968935401072i)) > - __CZ__eps) { - epsilon(eps); - return 31; + (lngamma(2.600 + 0.3000i) - + (0.3364259747848147735313925008357736575841632119933041 + + 0.2262777846650832407783807931778013947197968935401072i)) > + __CZ__eps) { + epsilon(eps); + return 31; } if (abs - (lngamma(3.600 + 0.3000i) - - (1.2985503009218817344713757767544359650274299875210727 + - 0.3411543900819823748030570769218348455327276444896884i)) > - __CZ__eps) { - epsilon(eps); - return 32; + (lngamma(3.600 + 0.3000i) - + (1.2985503009218817344713757767544359650274299875210727 + + 0.3411543900819823748030570769218348455327276444896884i)) > + __CZ__eps) { + epsilon(eps); + return 32; } if (abs - (lngamma(4.600 + 0.3000i) - - (2.582944367806232942740645241786647084583876190810680103 + - 0.4242956219704236047137253915726161430638589851177078492i)) > - __CZ__eps) { - epsilon(eps); - return 33; + (lngamma(4.600 + 0.3000i) - + (2.582944367806232942740645241786647084583876190810680103 + + 0.4242956219704236047137253915726161430638589851177078492i)) > + __CZ__eps) { + epsilon(eps); + return 33; } if (abs - (lngamma(5.600 + 0.3000i) - - (4.111122815491445860748560095878127604065278239877556104 + - 0.4894207853048094882972548755277837179650295466696997973i)) > - __CZ__eps) { - epsilon(eps); - return 34; + (lngamma(5.600 + 0.3000i) - + (4.111122815491445860748560095878127604065278239877556104 + + 0.4894207853048094882972548755277837179650295466696997973i)) > + __CZ__eps) { + epsilon(eps); + return 34; } if (abs - (lngamma(0.6000 - 4.700i) - - (-6.309230474426685182917699027589840248465208901823736044 - - 2.738444603265429259406748249023722438146218314171151425i)) > - __CZ__eps) { - epsilon(eps); - return 35; + (lngamma(0.6000 - 4.700i) - + (-6.309230474426685182917699027589840248465208901823736044 - + 2.738444603265429259406748249023722438146218314171151425i)) > + __CZ__eps) { + epsilon(eps); + return 35; } if (abs - (lngamma(0.6000 - 3.700i) - - (-4.762470602521331200619631143446813610218360030381255868 - - 1.307861859626688811743330143389568763790196226980935860i)) > - __CZ__eps) { - epsilon(eps); - return 36; + (lngamma(0.6000 - 3.700i) - + (-4.762470602521331200619631143446813610218360030381255868 - + 1.307861859626688811743330143389568763790196226980935860i)) > + __CZ__eps) { + epsilon(eps); + return 36; } if (abs - (lngamma(0.6000 - 2.700i) - - (-3.223449159729432378435059551332376261824297133470481664 - - 0.1525473639596832094518944287785664759918133343972275457i)) > - __CZ__eps) { - epsilon(eps); - return 37; + (lngamma(0.6000 - 2.700i) - + (-3.223449159729432378435059551332376261824297133470481664 - + 0.1525473639596832094518944287785664759918133343972275457i)) > + __CZ__eps) { + epsilon(eps); + return 37; } if (abs - (lngamma(0.6000 - 1.700i) - - (-1.699851882736550416690203691424396333903393386464266356 + - 0.6188153536675997046951505463300498363352953733225308151i)) > - __CZ__eps) { - epsilon(eps); - return 38; + (lngamma(0.6000 - 1.700i) - + (-1.699851882736550416690203691424396333903393386464266356 + + 0.6188153536675997046951505463300498363352953733225308151i)) > + __CZ__eps) { + epsilon(eps); + return 38; } if (abs - (lngamma(0.6000 - 0.7000i) - - (-0.2316312495202586116986763277644377512618333134657045421 + - 0.7368909799768367142682353753277667339824288570492360448i)) > - __CZ__eps) { - epsilon(eps); - return 39; + (lngamma(0.6000 - 0.7000i) - + (-0.2316312495202586116986763277644377512618333134657045421 + + 0.7368909799768367142682353753277667339824288570492360448i)) > + __CZ__eps) { + epsilon(eps); + return 39; } if (abs - (lngamma(0.6000 + 0.3000i) - - (0.2484000028946351584991362705412598434332854007039741619 - - 0.4227177743314176403219013995119576518240065994565821579i)) > - __CZ__eps) { - epsilon(eps); - return 40; + (lngamma(0.6000 + 0.3000i) - + (0.2484000028946351584991362705412598434332854007039741619 - + 0.4227177743314176403219013995119576518240065994565821579i)) > + __CZ__eps) { + epsilon(eps); + return 40; } if (abs - (lngamma(0.6000 + 1.300i) - - (-1.099689479936482253001126014071250387866864940802593030 - - 0.7725489931464399068598744386748572974573591452933440189i)) > - __CZ__eps) { - epsilon(eps); - return 41; + (lngamma(0.6000 + 1.300i) - + (-1.099689479936482253001126014071250387866864940802593030 - + 0.7725489931464399068598744386748572974573591452933440189i)) > + __CZ__eps) { + epsilon(eps); + return 41; } if (abs - (lngamma(0.6000 + 2.300i) - - (-2.611386294578008388513457987969729601048026532835562114 - - 0.2111094845860104400425314901146665256344806614559790152i)) > - __CZ__eps) { - epsilon(eps); - return 42; + (lngamma(0.6000 + 2.300i) - + (-2.611386294578008388513457987969729601048026532835562114 - + 0.2111094845860104400425314901146665256344806614559790152i)) > + __CZ__eps) { + epsilon(eps); + return 42; } if (abs - (lngamma(0.6000 + 3.300i) - - (-4.145670522984067490152016613422534092269675011415945298 + - 0.8081928951523762121254890981027647840025857144095024771i)) > - __CZ__eps) { - epsilon(eps); - return 43; + (lngamma(0.6000 + 3.300i) - + (-4.145670522984067490152016613422534092269675011415945298 + + 0.8081928951523762121254890981027647840025857144095024771i)) > + __CZ__eps) { + epsilon(eps); + return 43; } if (abs - (lngamma(0.6000 + 4.300i) - - (-5.689842576036527320491763306963824853139907301029281610 + - 2.137677242374957442527694027866746053575410791317320138i)) > - __CZ__eps) { - epsilon(eps); - return 44; + (lngamma(0.6000 + 4.300i) - + (-5.689842576036527320491763306963824853139907301029281610 + + 2.137677242374957442527694027866746053575410791317320138i)) > + __CZ__eps) { + epsilon(eps); + return 44; } if (abs - (lngamma(0.6000 + 5.300i) - - (-7.239654605052715210182073623536904206104308839659326676 + - 3.702857758072432142072497796069521049678127217607403327i)) > - __CZ__eps) { - epsilon(eps); - return 45; + (lngamma(0.6000 + 5.300i) - + (-7.239654605052715210182073623536904206104308839659326676 + + 3.702857758072432142072497796069521049678127217607403327i)) > + __CZ__eps) { + epsilon(eps); + return 45; } if (abs - (lngamma(-4.400 - 4.700i) - - (-14.73413592903136179653960750100174060012531669119348359 + - 7.340768981905845672138265648506833394433043135824981559i)) > - __CZ__eps) { - epsilon(eps); - return 46; + (lngamma(-4.400 - 4.700i) - + (-14.73413592903136179653960750100174060012531669119348359 + + 7.340768981905845672138265648506833394433043135824981559i)) > + __CZ__eps) { + epsilon(eps); + return 46; } if (abs - (lngamma(-3.400 - 3.700i) - - (-10.55018529022399813119005433743831737900085357229525796 + - 6.763336971725381912118912702208512629733112628981673298i)) > - __CZ__eps) { - epsilon(eps); - return 47; + (lngamma(-3.400 - 3.700i) - + (-10.55018529022399813119005433743831737900085357229525796 + + 6.763336971725381912118912702208512629733112628981673298i)) > + __CZ__eps) { + epsilon(eps); + return 47; } if (abs - (lngamma(-2.400 - 2.700i) - - (-6.624262018571684573249747079902924251345023570085621326 + - 5.911914743873792313808731773611192661709672638901754910i)) > - __CZ__eps) { - epsilon(eps); - return 48; + (lngamma(-2.400 - 2.700i) - + (-6.624262018571684573249747079902924251345023570085621326 + + 5.911914743873792313808731773611192661709672638901754910i)) > + __CZ__eps) { + epsilon(eps); + return 48; } if (abs - (lngamma(-1.400 - 1.700i) - - (-3.046912030520906458689035477846643788289090086345259335 + - 4.680423062668151424886705499811285399248102868605621987i)) > - __CZ__eps) { - epsilon(eps); - return 49; + (lngamma(-1.400 - 1.700i) - + (-3.046912030520906458689035477846643788289090086345259335 + + 4.680423062668151424886705499811285399248102868605621987i)) > + __CZ__eps) { + epsilon(eps); + return 49; } if (abs - (lngamma(-0.4000 - 0.7000i) - - (-0.01623979147403148300780826047582666582616647435129398527 + - 2.826833421018256285271011446520969788549353956082297248i)) > - __CZ__eps) { - epsilon(eps); - return 50; + (lngamma(-0.4000 - 0.7000i) - + (-0.01623979147403148300780826047582666582616647435129398527 + + 2.826833421018256285271011446520969788549353956082297248i)) > + __CZ__eps) { + epsilon(eps); + return 50; } if (abs - (lngamma(0.6000 + 0.3000i) - - (0.2484000028946351584991362705412598434332854007039741619 - - 0.4227177743314176403219013995119576518240065994565821579i)) > - __CZ__eps) { - epsilon(eps); - return 51; + (lngamma(0.6000 + 0.3000i) - + (0.2484000028946351584991362705412598434332854007039741619 - + 0.4227177743314176403219013995119576518240065994565821579i)) > + __CZ__eps) { + epsilon(eps); + return 51; } if (abs - (lngamma(1.600 + 1.300i) - - (-0.7407695833613238477853561156238169815169605175974563292 + - 0.3658395580779188724109027663961707196451841638334886679i)) > - __CZ__eps) { - epsilon(eps); - return 52; + (lngamma(1.600 + 1.300i) - + (-0.7407695833613238477853561156238169815169605175974563292 + + 0.3658395580779188724109027663961707196451841638334886679i)) > + __CZ__eps) { + epsilon(eps); + return 52; } if (abs - (lngamma(2.600 + 2.300i) - - (-0.7153017561016750689453931991025219163388411460412682694 + - 2.067498782269003991801228117457494590355245722719424742i)) > - __CZ__eps) { - epsilon(eps); - return 53; + (lngamma(2.600 + 2.300i) - + (-0.7153017561016750689453931991025219163388411460412682694 + + 2.067498782269003991801228117457494590355245722719424742i)) > + __CZ__eps) { + epsilon(eps); + return 53; } if (abs - (lngamma(3.600 + 3.300i) - - (-0.2006290139452759775010107586460283514303264993274887714 + - 4.221969149213679168621678150696738907045553787288427746i)) > - __CZ__eps) { - epsilon(eps); - return 54; + (lngamma(3.600 + 3.300i) - + (-0.2006290139452759775010107586460283514303264993274887714 + + 4.221969149213679168621678150696738907045553787288427746i)) > + __CZ__eps) { + epsilon(eps); + return 54; } if (abs - (lngamma(4.600 + 4.300i) - - (0.6404767304085869581018213364351326853699331839312207180 + - 6.685149323469513776483323494807052342570441936959315816i)) > - __CZ__eps) { - epsilon(eps); - return 55; + (lngamma(4.600 + 4.300i) - + (0.6404767304085869581018213364351326853699331839312207180 + + 6.685149323469513776483323494807052342570441936959315816i)) > + __CZ__eps) { + epsilon(eps); + return 55; } if (abs - (lngamma(5.600 + 5.300i) - - (1.727112476786098959996727579157495580048033035060833670 + - 9.383383918093155327986445451264543368751338171298232916i)) > - __CZ__eps) { - epsilon(eps); - return 56; + (lngamma(5.600 + 5.300i) - + (1.727112476786098959996727579157495580048033035060833670 + + 9.383383918093155327986445451264543368751338171298232916i)) > + __CZ__eps) { + epsilon(eps); + return 56; } if (abs - (lngamma(55.60 + 0.3000i) - - (166.7215150367733897769155930653789348483780044274716818 + - 1.202750513929718332820270669742686561426457642272968981i)) > - __CZ__eps) { - epsilon(eps); - return 57; + (lngamma(55.60 + 0.3000i) - + (166.7215150367733897769155930653789348483780044274716818 + + 1.202750513929718332820270669742686561426457642272968981i)) > + __CZ__eps) { + epsilon(eps); + return 57; } if (abs - (lngamma(56.60 + 0.3000i) - - (170.7397127945179968376917410624766834622909691036136375 + - 1.208146145021640303895693686064781770317635078049891748i)) > - __CZ__eps) { - epsilon(eps); - return 58; + (lngamma(56.60 + 0.3000i) - + (170.7397127945179968376917410624766834622909691036136375 + + 1.208146145021640303895693686064781770317635078049891748i)) > + __CZ__eps) { + epsilon(eps); + return 58; } if (abs - (lngamma(57.60 + 0.3000i) - - (174.7757358264026770962028712327193919190938819848539820 + - 1.213446448743774292811195505423481449339002192187714949i)) > - __CZ__eps) { - epsilon(eps); - return 59; + (lngamma(57.60 + 0.3000i) - + (174.7757358264026770962028712327193919190938819848539820 + + 1.213446448743774292811195505423481449339002192187714949i)) > + __CZ__eps) { + epsilon(eps); + return 59; } if (abs - (lngamma(58.60 + 0.3000i) - - (178.8292719572886165808686582437464130998008894472168186 + - 1.218654734982846161251085553080214761347285268088604785i)) > - __CZ__eps) { - epsilon(eps); - return 60; + (lngamma(58.60 + 0.3000i) - + (178.8292719572886165808686582437464130998008894472168186 + + 1.218654734982846161251085553080214761347285268088604785i)) > + __CZ__eps) { + epsilon(eps); + return 60; } if (abs - (lngamma(59.60 + 0.3000i) - - (182.9000197581041057641595126649840680882966589651420637 + - 1.223774144183534973445316592347337056808910609419286930i)) > - __CZ__eps) { - epsilon(eps); - return 61; + (lngamma(59.60 + 0.3000i) - + (182.9000197581041057641595126649840680882966589651420637 + + 1.223774144183534973445316592347337056808910609419286930i)) > + __CZ__eps) { + epsilon(eps); + return 61; } if (abs - (lngamma(60.60 + 0.3000i) - - (186.9876880003631981031020807195926428903734785341818284 + - 1.228807658719925269995511830298415601718771597558190350i)) > - __CZ__eps) { - epsilon(eps); - return 62; + (lngamma(60.60 + 0.3000i) - + (186.9876880003631981031020807195926428903734785341818284 + + 1.228807658719925269995511830298415601718771597558190350i)) > + __CZ__eps) { + epsilon(eps); + return 62; } if (abs - (lngamma(61.60 + 0.3000i) - - (191.0919951469889337316641602771633017764510692037723749 + - 1.233758113328768712483862353815791968059294457847368072i)) > - __CZ__eps) { - epsilon(eps); - return 63; + (lngamma(61.60 + 0.3000i) - + (191.0919951469889337316641602771633017764510692037723749 + + 1.233758113328768712483862353815791968059294457847368072i)) > + __CZ__eps) { + epsilon(eps); + return 63; } if (abs - (lngamma(62.60 + 0.3000i) - - (195.2126688764702481772276457650023207176714432948785485 + - 1.238628204695931980600482702688969918429374403006592554i)) > - __CZ__eps) { - epsilon(eps); - return 64; + (lngamma(62.60 + 0.3000i) - + (195.2126688764702481772276457650023207176714432948785485 + + 1.238628204695931980600482702688969918429374403006592554i)) > + __CZ__eps) { + epsilon(eps); + return 64; } if (abs - (lngamma(63.60 + 0.3000i) - - (199.3494456376687238313417632202369605922807314239672719 + - 1.243420500277190605198320894289870930154643596582155076i)) > - __CZ__eps) { - epsilon(eps); - return 65; + (lngamma(63.60 + 0.3000i) - + (199.3494456376687238313417632202369605922807314239672719 + + 1.243420500277190605198320894289870930154643596582155076i)) > + __CZ__eps) { + epsilon(eps); + return 65; } if (abs - (lngamma(64.60 + 0.3000i) - - (203.5020702328465376706204035728796350972376926574607893 + - 1.248137446425596312819515029227444652080011390838575181i)) > - __CZ__eps) { - epsilon(eps); - return 66; + (lngamma(64.60 + 0.3000i) - + (203.5020702328465376706204035728796350972376926574607893 + + 1.248137446425596312819515029227444652080011390838575181i)) > + __CZ__eps) { + epsilon(eps); + return 66; } if (abs - (lngamma(65.60 + 0.3000i) - - (207.6702954267142863859185793548246421433863939380928954 + - 1.252781375889819416329161991660565854615382764835522506i)) > - __CZ__eps) { - epsilon(eps); - return 67; + (lngamma(65.60 + 0.3000i) - + (207.6702954267142863859185793548246421433863939380928954 + + 1.252781375889819416329161991660565854615382764835522506i)) > + __CZ__eps) { + epsilon(eps); + return 67; } if (abs - (lngamma(55.60 - 4.700i) - - (166.5221258272035253961542734005976077004749775938844000 - - 18.84875483296568553194454925345602004591801239160222174i)) > - __CZ__eps) { - epsilon(eps); - return 68; + (lngamma(55.60 - 4.700i) - + (166.5221258272035253961542734005976077004749775938844000 - + 18.84875483296568553194454925345602004591801239160222174i)) > + __CZ__eps) { + epsilon(eps); + return 68; } if (abs - (lngamma(56.60 - 3.700i) - - (170.6185921690853207517443064939778892985245375960964842 - - 14.90313021223193465377855573208445845565931668639004077i)) > - __CZ__eps) { - epsilon(eps); - return 69; + (lngamma(56.60 - 3.700i) - + (170.6185921690853207517443064939778892985245375960964842 - + 14.90313021223193465377855573208445845565931668639004077i)) > + __CZ__eps) { + epsilon(eps); + return 69; } if (abs - (lngamma(57.60 - 2.700i) - - (174.7127139121008307648437631979262499901446251937177073 - - 10.92201102864604767334040466047947450750373806537116051i)) > - __CZ__eps) { - epsilon(eps); - return 70; + (lngamma(57.60 - 2.700i) - + (174.7127139121008307648437631979262499901446251937177073 - + 10.92201102864604767334040466047947450750373806537116051i)) > + __CZ__eps) { + epsilon(eps); + return 70; } if (abs - (lngamma(58.60 - 1.700i) - - (178.8051797102056562439362100160978710660289490095968327 - - 6.905945104548951236229262516275118301863000955218208856i)) > - __CZ__eps) { - epsilon(eps); - return 71; + (lngamma(58.60 - 1.700i) - + (178.8051797102056562439362100160978710660289490095968327 - + 6.905945104548951236229262516275118301863000955218208856i)) > + __CZ__eps) { + epsilon(eps); + return 71; } if (abs - (lngamma(59.60 - 0.7000i) - - (182.8966358377199778625865269072085032936485484956150669 - - 2.855486362253577342667404413778192112579790386732841204i)) > - __CZ__eps) { - epsilon(eps); - return 72; + (lngamma(59.60 - 0.7000i) - + (182.8966358377199778625865269072085032936485484956150669 - + 2.855486362253577342667404413778192112579790386732841204i)) > + __CZ__eps) { + epsilon(eps); + return 72; } if (abs - (lngamma(60.60 + 0.3000i) - - (186.9876880003631981031020807195926428903734785341818284 + - 1.228807658719925269995511830298415601718771597558190350i)) > - __CZ__eps) { - epsilon(eps); - return 73; + (lngamma(60.60 + 0.3000i) - + (186.9876880003631981031020807195926428903734785341818284 + + 1.228807658719925269995511830298415601718771597558190350i)) > + __CZ__eps) { + epsilon(eps); + return 73; } if (abs - (lngamma(61.60 + 1.300i) - - (191.0789031896982469942903294770974306494712752019213395 + - 5.346377998474074192830409565498522421021695288142347615i)) > - __CZ__eps) { - epsilon(eps); - return 74; + (lngamma(61.60 + 1.300i) - + (191.0789031896982469942903294770974306494712752019213395 + + 5.346377998474074192830409565498522421021695288142347615i)) > + __CZ__eps) { + epsilon(eps); + return 74; } if (abs - (lngamma(62.60 + 2.300i) - - (195.1708115544608858783580589279983618518227865792619427 + - 9.496666208022148051357709844128014322980249562957453155i)) > - __CZ__eps) { - epsilon(eps); - return 75; + (lngamma(62.60 + 2.300i) - + (195.1708115544608858783580589279983618518227865792619427 + + 9.496666208022148051357709844128014322980249562957453155i)) > + __CZ__eps) { + epsilon(eps); + return 75; } if (abs - (lngamma(63.60 + 3.300i) - - (199.2639082667972359747356775354901044881033064193665592 + - 13.67911603585439751926438073480939520547347569839795064i)) > - __CZ__eps) { - epsilon(eps); - return 76; + (lngamma(63.60 + 3.300i) - + (199.2639082667972359747356775354901044881033064193665592 + + 13.67911603585439751926438073480939520547347569839795064i)) > + __CZ__eps) { + epsilon(eps); + return 76; } if (abs - (lngamma(64.60 + 4.300i) - - (203.3586553654963869814883298543618854726441450377694569 + - 17.89317489050227754715433149549722038188972541358048335i)) > - __CZ__eps) { - epsilon(eps); - return 77; + (lngamma(64.60 + 4.300i) - + (203.3586553654963869814883298543618854726441450377694569 + + 17.89317489050227754715433149549722038188972541358048335i)) > + __CZ__eps) { + epsilon(eps); + return 77; } if (abs - (lngamma(65.60 + 5.300i) - - (207.4554835618873492047512087924156663776620358356581503 + - 22.13829509931977678201875089030163451926720764548437834i)) > - __CZ__eps) { - epsilon(eps); - return 78; + (lngamma(65.60 + 5.300i) - + (207.4554835618873492047512087924156663776620358356581503 + + 22.13829509931977678201875089030163451926720764548437834i)) > + __CZ__eps) { + epsilon(eps); + return 78; } if (abs - (lngamma(0.6000 + 55.30i) - - (-85.54482235577983941284251852323648610691188392673393393 + - 166.7640845362830899082977628513038941147191508645382670i)) > - __CZ__eps) { - epsilon(eps); - return 79; + (lngamma(0.6000 + 55.30i) - + (-85.54482235577983941284251852323648610691188392673393393 + + 166.7640845362830899082977628513038941147191508645382670i)) > + __CZ__eps) { + epsilon(eps); + return 79; } if (abs - (lngamma(0.6000 + 56.30i) - - (-87.11382647385499402990266927218873826677912515510914330 + - 170.7858332456548897964755419202916477033408200711519690i)) > - __CZ__eps) { - epsilon(eps); - return 80; + (lngamma(0.6000 + 56.30i) - + (-87.11382647385499402990266927218873826677912515510914330 + + 170.7858332456548897964755419202916477033408200711519690i)) > + __CZ__eps) { + epsilon(eps); + return 80; } if (abs - (lngamma(0.6000 + 57.30i) - - (-88.68286214812485690627962462529848906043953388486922638 + - 174.8253452895478184840703539752269094932785103410249518i)) > - __CZ__eps) { - epsilon(eps); - return 81; + (lngamma(0.6000 + 57.30i) - + (-88.68286214812485690627962462529848906043953388486922638 + + 174.8253452895478184840703539752269094932785103410249518i)) > + __CZ__eps) { + epsilon(eps); + return 81; } if (abs - (lngamma(0.6000 + 58.30i) - - (-90.25192828651651583800480958344256221682554088740576313 + - 178.8823106163841131771861511088137077830986146286084489i)) > - __CZ__eps) { - epsilon(eps); - return 82; + (lngamma(0.6000 + 58.30i) - + (-90.25192828651651583800480958344256221682554088740576313 + + 178.8823106163841131771861511088137077830986146286084489i)) > + __CZ__eps) { + epsilon(eps); + return 82; } if (abs - (lngamma(0.6000 + 59.30i) - - (-91.82102385268587759734139136217993540696936010920994984 + - 182.9564298132977973838333574465352695792546867284831679i)) > - __CZ__eps) { - epsilon(eps); - return 83; + (lngamma(0.6000 + 59.30i) - + (-91.82102385268587759734139136217993540696936010920994984 + + 182.9564298132977973838333574465352695792546867284831679i)) > + __CZ__eps) { + epsilon(eps); + return 83; } if (abs - (lngamma(0.6000 + 60.30i) - - (-93.39014786228910598458529398231928177449383105033168028 + - 187.0474135677690289293542062291360648608774972285628443i)) > - __CZ__eps) { - epsilon(eps); - return 84; + (lngamma(0.6000 + 60.30i) - + (-93.39014786228910598458529398231928177449383105033168028 + + 187.0474135677690289293542062291360648608774972285628443i)) > + __CZ__eps) { + epsilon(eps); + return 84; } if (abs - (lngamma(0.6000 + 61.30i) - - (-94.95929937956076993888890535139227785932447324700640489 + - 191.1549821649831349987910547767822679603735412036380108i)) > - __CZ__eps) { - epsilon(eps); - return 85; + (lngamma(0.6000 + 61.30i) - + (-94.95929937956076993888890535139227785932447324700640489 + + 191.1549821649831349987910547767822679603735412036380108i)) > + __CZ__eps) { + epsilon(eps); + return 85; } if (abs - (lngamma(0.6000 + 62.30i) - - (-96.52847751416891464599424930795884732518087496093651555 + - 195.2788650179992458972186470030422322640959550214072444i)) > - __CZ__eps) { - epsilon(eps); - return 86; + (lngamma(0.6000 + 62.30i) - + (-96.52847751416891464599424930795884732518087496093651555 + + 195.2788650179992458972186470030422322640959550214072444i)) > + __CZ__eps) { + epsilon(eps); + return 86; } if (abs - (lngamma(0.6000 + 63.30i) - - (-98.09768141832058996231194071903760307280235519603364210 + - 199.4188002280943140128727971292337826315387363387763786i)) > - __CZ__eps) { - epsilon(eps); - return 87; + (lngamma(0.6000 + 63.30i) - + (-98.09768141832058996231194071903760307280235519603364210 + + 199.4188002280943140128727971292337826315387363387763786i)) > + __CZ__eps) { + epsilon(eps); + return 87; } if (abs - (lngamma(0.6000 + 64.30i) - - (-99.66691028409427522125385963825011409754630863598190917 + - 203.5745341728981030650825963445356527935331129342248469i)) > - __CZ__eps) { - epsilon(eps); - return 88; + (lngamma(0.6000 + 64.30i) - + (-99.66691028409427522125385963825011409754630863598190917 + + 203.5745341728981030650825963445356527935331129342248469i)) > + __CZ__eps) { + epsilon(eps); + return 88; } if (abs - (lngamma(0.6000 + 65.30i) - - (-101.2361633409781854893699037629524761308029390440175099 + - 207.7458211201573236805249632667291754315339341665724958i)) > - __CZ__eps) { - epsilon(eps); - return 89; + (lngamma(0.6000 + 65.30i) - + (-101.2361633409781854893699037629524761308029390440175099 + + 207.7458211201573236805249632667291754315339341665724958i)) > + __CZ__eps) { + epsilon(eps); + return 89; } if (abs - (lngamma(55.60 + 60.30i) - - (138.3405218869058217717201182836422027677382184890964165 + - 250.9485307086751713133102893231808151265549690071705472i)) > - __CZ__eps) { - epsilon(eps); - return 90; + (lngamma(55.60 + 60.30i) - + (138.3405218869058217717201182836422027677382184890964165 + + 250.9485307086751713133102893231808151265549690071705472i)) > + __CZ__eps) { + epsilon(eps); + return 90; } if (abs - (lngamma(56.60 + 60.30i) - - (142.7474976121018701984157500679190442966110797769323173 + - 251.7744588650459198825346353772080509751313819470548658i)) > - __CZ__eps) { - epsilon(eps); - return 91; + (lngamma(56.60 + 60.30i) - + (142.7474976121018701984157500679190442966110797769323173 + + 251.7744588650459198825346353772080509751313819470548658i)) > + __CZ__eps) { + epsilon(eps); + return 91; } if (abs - (lngamma(57.60 + 60.30i) - - (147.1627435319602425515209166358781832064023544924212637 + - 252.5914974493805839443768868968642526869013797892608722i)) > - __CZ__eps) { - epsilon(eps); - return 92; + (lngamma(57.60 + 60.30i) - + (147.1627435319602425515209166358781832064023544924212637 + + 252.5914974493805839443768868968642526869013797892608722i)) > + __CZ__eps) { + epsilon(eps); + return 92; } if (abs - (lngamma(58.60 + 60.30i) - - (151.5862689029682042031606617640450220740985775964639233 + - 253.3997923739994162421416717294147634900873392644324912i)) > - __CZ__eps) { - epsilon(eps); - return 93; + (lngamma(58.60 + 60.30i) - + (151.5862689029682042031606617640450220740985775964639233 + + 253.3997923739994162421416717294147634900873392644324912i)) > + __CZ__eps) { + epsilon(eps); + return 93; } if (abs - (lngamma(59.60 + 60.30i) - - (156.0180803184689022095120622630277425180433295653817951 + - 254.1994872924291535134537002289372877256760561545266240i)) > - __CZ__eps) { - epsilon(eps); - return 94; + (lngamma(59.60 + 60.30i) - + (156.0180803184689022095120622630277425180433295653817951 + + 254.1994872924291535134537002289372877256760561545266240i)) > + __CZ__eps) { + epsilon(eps); + return 94; } if (abs - (lngamma(60.60 + 60.30i) - - (160.4581818322128207752571131620498333645831099884594593 + - 254.9907235879958949246830907372060458378867915677707498i)) > - __CZ__eps) { - epsilon(eps); - return 95; + (lngamma(60.60 + 60.30i) - + (160.4581818322128207752571131620498333645831099884594593 + + 254.9907235879958949246830907372060458378867915677707498i)) > + __CZ__eps) { + epsilon(eps); + return 95; } if (abs - (lngamma(61.60 + 60.30i) - - (164.9065750781912363906196189745577497508505165621357938 + - 255.7736403669080425654455012237246051402306640891736322i)) > - __CZ__eps) { - epsilon(eps); - return 96; + (lngamma(61.60 + 60.30i) - + (164.9065750781912363906196189745577497508505165621357938 + + 255.7736403669080425654455012237246051402306640891736322i)) > + __CZ__eps) { + epsilon(eps); + return 96; } if (abs - (lngamma(62.60 + 60.30i) - - (169.3632593867220799863942253592790131010186217605278241 + - 256.5483744554910528044048617005478717965073680654042053i)) > - __CZ__eps) { - epsilon(eps); - return 97; + (lngamma(62.60 + 60.30i) - + (169.3632593867220799863942253592790131010186217605278241 + + 256.5483744554910528044048617005478717965073680654042053i)) > + __CZ__eps) { + epsilon(eps); + return 97; } if (abs - (lngamma(63.60 + 60.30i) - - (173.8282318967764198928263540479369804154959334380883398 + - 257.3150604012511380535676929646281795055983167823336193i)) > - __CZ__eps) { - epsilon(eps); - return 98; + (lngamma(63.60 + 60.30i) - + (173.8282318967764198928263540479369804154959334380883398 + + 257.3150604012511380535676929646281795055983167823336193i)) > + __CZ__eps) { + epsilon(eps); + return 98; } if (abs - (lngamma(64.60 + 60.30i) - - (178.3014876645497005489995740718100489155558324227755847 + - 258.0738304774605436591436026066009539042787457216911291i)) > - __CZ__eps) { - epsilon(eps); - return 99; + (lngamma(64.60 + 60.30i) - + (178.3014876645497005489995740718100489155558324227755847 + + 258.0738304774605436591436026066009539042787457216911291i)) > + __CZ__eps) { + epsilon(eps); + return 99; } if (abs - (lngamma(65.60 + 60.30i) - - (182.7830197682960267239662260557525833694506977039319737 + - 258.8248146909724805417993325211754807069936951454932977i)) > - __CZ__eps) { - epsilon(eps); - return 100; + (lngamma(65.60 + 60.30i) - + (182.7830197682960267239662260557525833694506977039319737 + + 258.8248146909724805417993325211754807069936951454932977i)) > + __CZ__eps) { + epsilon(eps); + return 100; } if (abs - (lngamma(55.60 + 55.30i) - - (142.3862162791589253462657451176275726003857264651343509 + - 229.0474972316203435288188174128389032017308276896396827i)) > - __CZ__eps) { - epsilon(eps); - return 101; + (lngamma(55.60 + 55.30i) - + (142.3862162791589253462657451176275726003857264651343509 + + 229.0474972316203435288188174128389032017308276896396827i)) > + __CZ__eps) { + epsilon(eps); + return 101; } if (abs - (lngamma(56.60 + 56.30i) - - (145.9655713474689753168556009847734887663033552824290632 + - 234.2012259525622513896404861908422505950646506577988340i)) > - __CZ__eps) { - epsilon(eps); - return 102; + (lngamma(56.60 + 56.30i) - + (145.9655713474689753168556009847734887663033552824290632 + + 234.2012259525622513896404861908422505950646506577988340i)) > + __CZ__eps) { + epsilon(eps); + return 102; } if (abs - (lngamma(57.60 + 57.30i) - - (149.5627523253413003508200851967083007076485608754907532 + - 239.3727177204530395107173394215426561501560159557014103i)) > - __CZ__eps) { - epsilon(eps); - return 103; + (lngamma(57.60 + 57.30i) - + (149.5627523253413003508200851967083007076485608754907532 + + 239.3727177204530395107173394215426561501560159557014103i)) > + __CZ__eps) { + epsilon(eps); + return 103; } if (abs - (lngamma(58.60 + 58.30i) - - (153.1774470047839472501216057736005131302626263510371392 + - 244.5616624984797644536433102063654140139237547865421532i)) > - __CZ__eps) { - epsilon(eps); - return 104; + (lngamma(58.60 + 58.30i) - + (153.1774470047839472501216057736005131302626263510371392 + + 244.5616624984797644536433102063654140139237547865421532i)) > + __CZ__eps) { + epsilon(eps); + return 104; } if (abs - (lngamma(59.60 + 59.30i) - - (156.8093539260984043245770025957276995010069796775703177 + - 249.7677608875474964335171539461488545902215228674008981i)) > - __CZ__eps) { - epsilon(eps); - return 105; + (lngamma(59.60 + 59.30i) - + (156.8093539260984043245770025957276995010069796775703177 + + 249.7677608875474964335171539461488545902215228674008981i)) > + __CZ__eps) { + epsilon(eps); + return 105; } if (abs - (lngamma(60.60 + 60.30i) - - (160.4581818322128207752571131620498333645831099884594593 + - 254.9907235879958949246830907372060458378867915677707498i)) > - __CZ__eps) { - epsilon(eps); - return 106; + (lngamma(60.60 + 60.30i) - + (160.4581818322128207752571131620498333645831099884594593 + + 254.9907235879958949246830907372060458378867915677707498i)) > + __CZ__eps) { + epsilon(eps); + return 106; } if (abs - (lngamma(61.60 + 61.30i) - - (164.1236491593380218382957487779642572534385362007999916 + - 260.2302708970324395553848679531333038493595454481482560i)) > - __CZ__eps) { - epsilon(eps); - return 107; + (lngamma(61.60 + 61.30i) - + (164.1236491593380218382957487779642572534385362007999916 + + 260.2302708970324395553848679531333038493595454481482560i)) > + __CZ__eps) { + epsilon(eps); + return 107; } if (abs - (lngamma(62.60 + 62.30i) - - (167.8054835609733823774016164868506426238263526697353479 + - 265.4861322389681286058365065491944749198017327500214219i)) > - __CZ__eps) { - epsilon(eps); - return 108; + (lngamma(62.60 + 62.30i) - + (167.8054835609733823774016164868506426238263526697353479 + + 265.4861322389681286058365065491944749198017327500214219i)) > + __CZ__eps) { + epsilon(eps); + return 108; } if (abs - (lngamma(63.60 + 63.30i) - - (171.5034214625769205528980449555097665172285302158028025 + - 270.7580457256222186188843213325906832500862444373572311i)) > - __CZ__eps) { - epsilon(eps); - return 109; + (lngamma(63.60 + 63.30i) - + (171.5034214625769205528980449555097665172285302158028025 + + 270.7580457256222186188843213325906832500862444373572311i)) > + __CZ__eps) { + epsilon(eps); + return 109; } if (abs - (lngamma(64.60 + 64.30i) - - (175.2172076444693933495200678808489471651335658562522069 + - 276.0457577445122795003295082894754935609216218032287116i)) > - __CZ__eps) { - epsilon(eps); - return 110; + (lngamma(64.60 + 64.30i) - + (175.2172076444693933495200678808489471651335658562522069 + + 276.0457577445122795003295082894754935609216218032287116i)) > + __CZ__eps) { + epsilon(eps); + return 110; } if (abs - (lngamma(65.60 + 65.30i) - - (178.9465948507696967449494536146172974534191430062324139 + - 281.3490225726683461623186324992570909685317567794418009i)) > - __CZ__eps) { - epsilon(eps); - return 111; + (lngamma(65.60 + 65.30i) - + (178.9465948507696967449494536146172974534191430062324139 + + 281.3490225726683461623186324992570909685317567794418009i)) > + __CZ__eps) { + epsilon(eps); + return 111; } if (abs - (lngamma(0.6000 + 4.700i) - - (-6.309230474426685182917699027589840248465208901823736044 + - 2.738444603265429259406748249023722438146218314171151425i)) > - __CZ__eps) { - epsilon(eps); - return 112; + (lngamma(0.6000 + 4.700i) - + (-6.309230474426685182917699027589840248465208901823736044 + + 2.738444603265429259406748249023722438146218314171151425i)) > + __CZ__eps) { + epsilon(eps); + return 112; } if (abs - (lngamma(0.6000 + 3.700i) - - (-4.762470602521331200619631143446813610218360030381255868 + - 1.307861859626688811743330143389568763790196226980935860i)) > - __CZ__eps) { - epsilon(eps); - return 113; + (lngamma(0.6000 + 3.700i) - + (-4.762470602521331200619631143446813610218360030381255868 + + 1.307861859626688811743330143389568763790196226980935860i)) > + __CZ__eps) { + epsilon(eps); + return 113; } if (abs - (lngamma(0.6000 + 2.700i) - - (-3.223449159729432378435059551332376261824297133470481664 + - 0.1525473639596832094518944287785664759918133343972275457i)) > - __CZ__eps) { - epsilon(eps); - return 114; + (lngamma(0.6000 + 2.700i) - + (-3.223449159729432378435059551332376261824297133470481664 + + 0.1525473639596832094518944287785664759918133343972275457i)) > + __CZ__eps) { + epsilon(eps); + return 114; } if (abs - (lngamma(0.6000 + 1.700i) - - (-1.699851882736550416690203691424396333903393386464266356 - - 0.6188153536675997046951505463300498363352953733225308151i)) > - __CZ__eps) { - epsilon(eps); - return 115; + (lngamma(0.6000 + 1.700i) - + (-1.699851882736550416690203691424396333903393386464266356 - + 0.6188153536675997046951505463300498363352953733225308151i)) > + __CZ__eps) { + epsilon(eps); + return 115; } if (abs - (lngamma(0.6000 + 0.7000i) - - (-0.2316312495202586116986763277644377512618333134657045421 - - 0.7368909799768367142682353753277667339824288570492360448i)) > - __CZ__eps) { - epsilon(eps); - return 116; + (lngamma(0.6000 + 0.7000i) - + (-0.2316312495202586116986763277644377512618333134657045421 - + 0.7368909799768367142682353753277667339824288570492360448i)) > + __CZ__eps) { + epsilon(eps); + return 116; } if (abs - (lngamma(0.6000 - 0.3000i) - - (0.2484000028946351584991362705412598434332854007039741619 + - 0.4227177743314176403219013995119576518240065994565821579i)) > - __CZ__eps) { - epsilon(eps); - return 117; + (lngamma(0.6000 - 0.3000i) - + (0.2484000028946351584991362705412598434332854007039741619 + + 0.4227177743314176403219013995119576518240065994565821579i)) > + __CZ__eps) { + epsilon(eps); + return 117; } if (abs - (lngamma(0.6000 - 1.300i) - - (-1.099689479936482253001126014071250387866864940802593030 + - 0.7725489931464399068598744386748572974573591452933440189i)) > - __CZ__eps) { - epsilon(eps); - return 118; + (lngamma(0.6000 - 1.300i) - + (-1.099689479936482253001126014071250387866864940802593030 + + 0.7725489931464399068598744386748572974573591452933440189i)) > + __CZ__eps) { + epsilon(eps); + return 118; } if (abs - (lngamma(0.6000 - 2.300i) - - (-2.611386294578008388513457987969729601048026532835562114 + - 0.2111094845860104400425314901146665256344806614559790152i)) > - __CZ__eps) { - epsilon(eps); - return 119; + (lngamma(0.6000 - 2.300i) - + (-2.611386294578008388513457987969729601048026532835562114 + + 0.2111094845860104400425314901146665256344806614559790152i)) > + __CZ__eps) { + epsilon(eps); + return 119; } if (abs - (lngamma(0.6000 - 3.300i) - - (-4.145670522984067490152016613422534092269675011415945298 - - 0.8081928951523762121254890981027647840025857144095024771i)) > - __CZ__eps) { - epsilon(eps); - return 120; + (lngamma(0.6000 - 3.300i) - + (-4.145670522984067490152016613422534092269675011415945298 - + 0.8081928951523762121254890981027647840025857144095024771i)) > + __CZ__eps) { + epsilon(eps); + return 120; } if (abs - (lngamma(0.6000 - 4.300i) - - (-5.689842576036527320491763306963824853139907301029281610 - - 2.137677242374957442527694027866746053575410791317320138i)) > - __CZ__eps) { - epsilon(eps); - return 121; + (lngamma(0.6000 - 4.300i) - + (-5.689842576036527320491763306963824853139907301029281610 - + 2.137677242374957442527694027866746053575410791317320138i)) > + __CZ__eps) { + epsilon(eps); + return 121; } if (abs - (lngamma(0.6000 - 5.300i) - - (-7.239654605052715210182073623536904206104308839659326676 - - 3.702857758072432142072497796069521049678127217607403327i)) > - __CZ__eps) { - epsilon(eps); - return 122; + (lngamma(0.6000 - 5.300i) - + (-7.239654605052715210182073623536904206104308839659326676 - + 3.702857758072432142072497796069521049678127217607403327i)) > + __CZ__eps) { + epsilon(eps); + return 122; } if (abs - (lngamma(-4.400 + 4.700i) - - (-14.73413592903136179653960750100174060012531669119348359 - - 7.340768981905845672138265648506833394433043135824981559i)) > - __CZ__eps) { - epsilon(eps); - return 123; + (lngamma(-4.400 + 4.700i) - + (-14.73413592903136179653960750100174060012531669119348359 - + 7.340768981905845672138265648506833394433043135824981559i)) > + __CZ__eps) { + epsilon(eps); + return 123; } if (abs - (lngamma(-3.400 + 3.700i) - - (-10.55018529022399813119005433743831737900085357229525796 - - 6.763336971725381912118912702208512629733112628981673298i)) > - __CZ__eps) { - epsilon(eps); - return 124; + (lngamma(-3.400 + 3.700i) - + (-10.55018529022399813119005433743831737900085357229525796 - + 6.763336971725381912118912702208512629733112628981673298i)) > + __CZ__eps) { + epsilon(eps); + return 124; } if (abs - (lngamma(-2.400 + 2.700i) - - (-6.624262018571684573249747079902924251345023570085621326 - - 5.911914743873792313808731773611192661709672638901754910i)) > - __CZ__eps) { - epsilon(eps); - return 125; + (lngamma(-2.400 + 2.700i) - + (-6.624262018571684573249747079902924251345023570085621326 - + 5.911914743873792313808731773611192661709672638901754910i)) > + __CZ__eps) { + epsilon(eps); + return 125; } if (abs - (lngamma(-1.400 + 1.700i) - - (-3.046912030520906458689035477846643788289090086345259335 - - 4.680423062668151424886705499811285399248102868605621987i)) > - __CZ__eps) { - epsilon(eps); - return 126; + (lngamma(-1.400 + 1.700i) - + (-3.046912030520906458689035477846643788289090086345259335 - + 4.680423062668151424886705499811285399248102868605621987i)) > + __CZ__eps) { + epsilon(eps); + return 126; } if (abs - (lngamma(-0.4000 + 0.7000i) - - (-0.01623979147403148300780826047582666582616647435129398527 - - 2.826833421018256285271011446520969788549353956082297248i)) > - __CZ__eps) { - epsilon(eps); - return 127; + (lngamma(-0.4000 + 0.7000i) - + (-0.01623979147403148300780826047582666582616647435129398527 - + 2.826833421018256285271011446520969788549353956082297248i)) > + __CZ__eps) { + epsilon(eps); + return 127; } if (abs - (lngamma(0.6000 - 0.3000i) - - (0.2484000028946351584991362705412598434332854007039741619 + - 0.4227177743314176403219013995119576518240065994565821579i)) > - __CZ__eps) { - epsilon(eps); - return 128; + (lngamma(0.6000 - 0.3000i) - + (0.2484000028946351584991362705412598434332854007039741619 + + 0.4227177743314176403219013995119576518240065994565821579i)) > + __CZ__eps) { + epsilon(eps); + return 128; } if (abs - (lngamma(1.600 - 1.300i) - - (-0.7407695833613238477853561156238169815169605175974563292 - - 0.3658395580779188724109027663961707196451841638334886679i)) > - __CZ__eps) { - epsilon(eps); - return 129; + (lngamma(1.600 - 1.300i) - + (-0.7407695833613238477853561156238169815169605175974563292 - + 0.3658395580779188724109027663961707196451841638334886679i)) > + __CZ__eps) { + epsilon(eps); + return 129; } if (abs - (lngamma(2.600 - 2.300i) - - (-0.7153017561016750689453931991025219163388411460412682694 - - 2.067498782269003991801228117457494590355245722719424742i)) > - __CZ__eps) { - epsilon(eps); - return 130; + (lngamma(2.600 - 2.300i) - + (-0.7153017561016750689453931991025219163388411460412682694 - + 2.067498782269003991801228117457494590355245722719424742i)) > + __CZ__eps) { + epsilon(eps); + return 130; } if (abs - (lngamma(3.600 - 3.300i) - - (-0.2006290139452759775010107586460283514303264993274887714 - - 4.221969149213679168621678150696738907045553787288427746i)) > - __CZ__eps) { - epsilon(eps); - return 131; + (lngamma(3.600 - 3.300i) - + (-0.2006290139452759775010107586460283514303264993274887714 - + 4.221969149213679168621678150696738907045553787288427746i)) > + __CZ__eps) { + epsilon(eps); + return 131; } if (abs - (lngamma(4.600 - 4.300i) - - (0.6404767304085869581018213364351326853699331839312207180 - - 6.685149323469513776483323494807052342570441936959315816i)) > - __CZ__eps) { - epsilon(eps); - return 132; + (lngamma(4.600 - 4.300i) - + (0.6404767304085869581018213364351326853699331839312207180 - + 6.685149323469513776483323494807052342570441936959315816i)) > + __CZ__eps) { + epsilon(eps); + return 132; } if (abs - (lngamma(5.600 - 5.300i) - - (1.727112476786098959996727579157495580048033035060833670 - - 9.383383918093155327986445451264543368751338171298232916i)) > - __CZ__eps) { - epsilon(eps); - return 133; + (lngamma(5.600 - 5.300i) - + (1.727112476786098959996727579157495580048033035060833670 - + 9.383383918093155327986445451264543368751338171298232916i)) > + __CZ__eps) { + epsilon(eps); + return 133; } if (abs - (lngamma(55.60 - 0.3000i) - - (166.7215150367733897769155930653789348483780044274716818 - - 1.202750513929718332820270669742686561426457642272968981i)) > - __CZ__eps) { - epsilon(eps); - return 134; + (lngamma(55.60 - 0.3000i) - + (166.7215150367733897769155930653789348483780044274716818 - + 1.202750513929718332820270669742686561426457642272968981i)) > + __CZ__eps) { + epsilon(eps); + return 134; } if (abs - (lngamma(56.60 - 0.3000i) - - (170.7397127945179968376917410624766834622909691036136375 - - 1.208146145021640303895693686064781770317635078049891748i)) > - __CZ__eps) { - epsilon(eps); - return 135; + (lngamma(56.60 - 0.3000i) - + (170.7397127945179968376917410624766834622909691036136375 - + 1.208146145021640303895693686064781770317635078049891748i)) > + __CZ__eps) { + epsilon(eps); + return 135; } if (abs - (lngamma(57.60 - 0.3000i) - - (174.7757358264026770962028712327193919190938819848539820 - - 1.213446448743774292811195505423481449339002192187714949i)) > - __CZ__eps) { - epsilon(eps); - return 136; + (lngamma(57.60 - 0.3000i) - + (174.7757358264026770962028712327193919190938819848539820 - + 1.213446448743774292811195505423481449339002192187714949i)) > + __CZ__eps) { + epsilon(eps); + return 136; } if (abs - (lngamma(58.60 - 0.3000i) - - (178.8292719572886165808686582437464130998008894472168186 - - 1.218654734982846161251085553080214761347285268088604785i)) > - __CZ__eps) { - epsilon(eps); - return 137; + (lngamma(58.60 - 0.3000i) - + (178.8292719572886165808686582437464130998008894472168186 - + 1.218654734982846161251085553080214761347285268088604785i)) > + __CZ__eps) { + epsilon(eps); + return 137; } if (abs - (lngamma(59.60 - 0.3000i) - - (182.9000197581041057641595126649840680882966589651420637 - - 1.223774144183534973445316592347337056808910609419286930i)) > - __CZ__eps) { - epsilon(eps); - return 138; + (lngamma(59.60 - 0.3000i) - + (182.9000197581041057641595126649840680882966589651420637 - + 1.223774144183534973445316592347337056808910609419286930i)) > + __CZ__eps) { + epsilon(eps); + return 138; } if (abs - (lngamma(60.60 - 0.3000i) - - (186.9876880003631981031020807195926428903734785341818284 - - 1.228807658719925269995511830298415601718771597558190350i)) > - __CZ__eps) { - epsilon(eps); - return 139; + (lngamma(60.60 - 0.3000i) - + (186.9876880003631981031020807195926428903734785341818284 - + 1.228807658719925269995511830298415601718771597558190350i)) > + __CZ__eps) { + epsilon(eps); + return 139; } if (abs - (lngamma(61.60 - 0.3000i) - - (191.0919951469889337316641602771633017764510692037723749 - - 1.233758113328768712483862353815791968059294457847368072i)) > - __CZ__eps) { - epsilon(eps); - return 140; + (lngamma(61.60 - 0.3000i) - + (191.0919951469889337316641602771633017764510692037723749 - + 1.233758113328768712483862353815791968059294457847368072i)) > + __CZ__eps) { + epsilon(eps); + return 140; } if (abs - (lngamma(62.60 - 0.3000i) - - (195.2126688764702481772276457650023207176714432948785485 - - 1.238628204695931980600482702688969918429374403006592554i)) > - __CZ__eps) { - epsilon(eps); - return 141; + (lngamma(62.60 - 0.3000i) - + (195.2126688764702481772276457650023207176714432948785485 - + 1.238628204695931980600482702688969918429374403006592554i)) > + __CZ__eps) { + epsilon(eps); + return 141; } if (abs - (lngamma(63.60 - 0.3000i) - - (199.3494456376687238313417632202369605922807314239672719 - - 1.243420500277190605198320894289870930154643596582155076i)) > - __CZ__eps) { - epsilon(eps); - return 142; + (lngamma(63.60 - 0.3000i) - + (199.3494456376687238313417632202369605922807314239672719 - + 1.243420500277190605198320894289870930154643596582155076i)) > + __CZ__eps) { + epsilon(eps); + return 142; } if (abs - (lngamma(64.60 - 0.3000i) - - (203.5020702328465376706204035728796350972376926574607893 - - 1.248137446425596312819515029227444652080011390838575181i)) > - __CZ__eps) { - epsilon(eps); - return 143; + (lngamma(64.60 - 0.3000i) - + (203.5020702328465376706204035728796350972376926574607893 - + 1.248137446425596312819515029227444652080011390838575181i)) > + __CZ__eps) { + epsilon(eps); + return 143; } if (abs - (lngamma(65.60 - 0.3000i) - - (207.6702954267142863859185793548246421433863939380928954 - - 1.252781375889819416329161991660565854615382764835522506i)) > - __CZ__eps) { - epsilon(eps); - return 144; + (lngamma(65.60 - 0.3000i) - + (207.6702954267142863859185793548246421433863939380928954 - + 1.252781375889819416329161991660565854615382764835522506i)) > + __CZ__eps) { + epsilon(eps); + return 144; } if (abs - (lngamma(55.60 - 4.700i) - - (166.5221258272035253961542734005976077004749775938844000 - - 18.84875483296568553194454925345602004591801239160222174i)) > - __CZ__eps) { - epsilon(eps); - return 145; + (lngamma(55.60 - 4.700i) - + (166.5221258272035253961542734005976077004749775938844000 - + 18.84875483296568553194454925345602004591801239160222174i)) > + __CZ__eps) { + epsilon(eps); + return 145; } if (abs - (lngamma(56.60 - 3.700i) - - (170.6185921690853207517443064939778892985245375960964842 - - 14.90313021223193465377855573208445845565931668639004077i)) > - __CZ__eps) { - epsilon(eps); - return 146; + (lngamma(56.60 - 3.700i) - + (170.6185921690853207517443064939778892985245375960964842 - + 14.90313021223193465377855573208445845565931668639004077i)) > + __CZ__eps) { + epsilon(eps); + return 146; } if (abs - (lngamma(57.60 - 2.700i) - - (174.7127139121008307648437631979262499901446251937177073 - - 10.92201102864604767334040466047947450750373806537116051i)) > - __CZ__eps) { - epsilon(eps); - return 147; + (lngamma(57.60 - 2.700i) - + (174.7127139121008307648437631979262499901446251937177073 - + 10.92201102864604767334040466047947450750373806537116051i)) > + __CZ__eps) { + epsilon(eps); + return 147; } if (abs - (lngamma(58.60 - 1.700i) - - (178.8051797102056562439362100160978710660289490095968327 - - 6.905945104548951236229262516275118301863000955218208856i)) > - __CZ__eps) { - epsilon(eps); - return 148; + (lngamma(58.60 - 1.700i) - + (178.8051797102056562439362100160978710660289490095968327 - + 6.905945104548951236229262516275118301863000955218208856i)) > + __CZ__eps) { + epsilon(eps); + return 148; } if (abs - (lngamma(59.60 - 0.7000i) - - (182.8966358377199778625865269072085032936485484956150669 - - 2.855486362253577342667404413778192112579790386732841204i)) > - __CZ__eps) { - epsilon(eps); - return 149; + (lngamma(59.60 - 0.7000i) - + (182.8966358377199778625865269072085032936485484956150669 - + 2.855486362253577342667404413778192112579790386732841204i)) > + __CZ__eps) { + epsilon(eps); + return 149; } if (abs - (lngamma(60.60 + 0.3000i) - - (186.9876880003631981031020807195926428903734785341818284 + - 1.228807658719925269995511830298415601718771597558190350i)) > - __CZ__eps) { - epsilon(eps); - return 150; + (lngamma(60.60 + 0.3000i) - + (186.9876880003631981031020807195926428903734785341818284 + + 1.228807658719925269995511830298415601718771597558190350i)) > + __CZ__eps) { + epsilon(eps); + return 150; } if (abs - (lngamma(61.60 + 1.300i) - - (191.0789031896982469942903294770974306494712752019213395 + - 5.346377998474074192830409565498522421021695288142347615i)) > - __CZ__eps) { - epsilon(eps); - return 151; + (lngamma(61.60 + 1.300i) - + (191.0789031896982469942903294770974306494712752019213395 + + 5.346377998474074192830409565498522421021695288142347615i)) > + __CZ__eps) { + epsilon(eps); + return 151; } if (abs - (lngamma(62.60 + 2.300i) - - (195.1708115544608858783580589279983618518227865792619427 + - 9.496666208022148051357709844128014322980249562957453155i)) > - __CZ__eps) { - epsilon(eps); - return 152; + (lngamma(62.60 + 2.300i) - + (195.1708115544608858783580589279983618518227865792619427 + + 9.496666208022148051357709844128014322980249562957453155i)) > + __CZ__eps) { + epsilon(eps); + return 152; } if (abs - (lngamma(63.60 + 3.300i) - - (199.2639082667972359747356775354901044881033064193665592 + - 13.67911603585439751926438073480939520547347569839795064i)) > - __CZ__eps) { - epsilon(eps); - return 153; + (lngamma(63.60 + 3.300i) - + (199.2639082667972359747356775354901044881033064193665592 + + 13.67911603585439751926438073480939520547347569839795064i)) > + __CZ__eps) { + epsilon(eps); + return 153; } if (abs - (lngamma(64.60 + 4.300i) - - (203.3586553654963869814883298543618854726441450377694569 + - 17.89317489050227754715433149549722038188972541358048335i)) > - __CZ__eps) { - epsilon(eps); - return 154; + (lngamma(64.60 + 4.300i) - + (203.3586553654963869814883298543618854726441450377694569 + + 17.89317489050227754715433149549722038188972541358048335i)) > + __CZ__eps) { + epsilon(eps); + return 154; } if (abs - (lngamma(65.60 + 5.300i) - - (207.4554835618873492047512087924156663776620358356581503 + - 22.13829509931977678201875089030163451926720764548437834i)) > - __CZ__eps) { - epsilon(eps); - return 155; + (lngamma(65.60 + 5.300i) - + (207.4554835618873492047512087924156663776620358356581503 + + 22.13829509931977678201875089030163451926720764548437834i)) > + __CZ__eps) { + epsilon(eps); + return 155; } if (abs - (lngamma(0.6000 - 55.30i) - - (-85.54482235577983941284251852323648610691188392673393393 - - 166.7640845362830899082977628513038941147191508645382670i)) > - __CZ__eps) { - epsilon(eps); - return 156; + (lngamma(0.6000 - 55.30i) - + (-85.54482235577983941284251852323648610691188392673393393 - + 166.7640845362830899082977628513038941147191508645382670i)) > + __CZ__eps) { + epsilon(eps); + return 156; } if (abs - (lngamma(0.6000 - 56.30i) - - (-87.11382647385499402990266927218873826677912515510914330 - - 170.7858332456548897964755419202916477033408200711519690i)) > - __CZ__eps) { - epsilon(eps); - return 157; + (lngamma(0.6000 - 56.30i) - + (-87.11382647385499402990266927218873826677912515510914330 - + 170.7858332456548897964755419202916477033408200711519690i)) > + __CZ__eps) { + epsilon(eps); + return 157; } if (abs - (lngamma(0.6000 - 57.30i) - - (-88.68286214812485690627962462529848906043953388486922638 - - 174.8253452895478184840703539752269094932785103410249518i)) > - __CZ__eps) { - epsilon(eps); - return 158; + (lngamma(0.6000 - 57.30i) - + (-88.68286214812485690627962462529848906043953388486922638 - + 174.8253452895478184840703539752269094932785103410249518i)) > + __CZ__eps) { + epsilon(eps); + return 158; } if (abs - (lngamma(0.6000 - 58.30i) - - (-90.25192828651651583800480958344256221682554088740576313 - - 178.8823106163841131771861511088137077830986146286084489i)) > - __CZ__eps) { - epsilon(eps); - return 159; + (lngamma(0.6000 - 58.30i) - + (-90.25192828651651583800480958344256221682554088740576313 - + 178.8823106163841131771861511088137077830986146286084489i)) > + __CZ__eps) { + epsilon(eps); + return 159; } if (abs - (lngamma(0.6000 - 59.30i) - - (-91.82102385268587759734139136217993540696936010920994984 - - 182.9564298132977973838333574465352695792546867284831679i)) > - __CZ__eps) { - epsilon(eps); - return 160; + (lngamma(0.6000 - 59.30i) - + (-91.82102385268587759734139136217993540696936010920994984 - + 182.9564298132977973838333574465352695792546867284831679i)) > + __CZ__eps) { + epsilon(eps); + return 160; } if (abs - (lngamma(0.6000 - 60.30i) - - (-93.39014786228910598458529398231928177449383105033168028 - - 187.0474135677690289293542062291360648608774972285628443i)) > - __CZ__eps) { - epsilon(eps); - return 161; + (lngamma(0.6000 - 60.30i) - + (-93.39014786228910598458529398231928177449383105033168028 - + 187.0474135677690289293542062291360648608774972285628443i)) > + __CZ__eps) { + epsilon(eps); + return 161; } if (abs - (lngamma(0.6000 - 61.30i) - - (-94.95929937956076993888890535139227785932447324700640489 - - 191.1549821649831349987910547767822679603735412036380108i)) > - __CZ__eps) { - epsilon(eps); - return 162; + (lngamma(0.6000 - 61.30i) - + (-94.95929937956076993888890535139227785932447324700640489 - + 191.1549821649831349987910547767822679603735412036380108i)) > + __CZ__eps) { + epsilon(eps); + return 162; } if (abs - (lngamma(0.6000 - 62.30i) - - (-96.52847751416891464599424930795884732518087496093651555 - - 195.2788650179992458972186470030422322640959550214072444i)) > - __CZ__eps) { - epsilon(eps); - return 163; + (lngamma(0.6000 - 62.30i) - + (-96.52847751416891464599424930795884732518087496093651555 - + 195.2788650179992458972186470030422322640959550214072444i)) > + __CZ__eps) { + epsilon(eps); + return 163; } if (abs - (lngamma(0.6000 - 63.30i) - - (-98.09768141832058996231194071903760307280235519603364210 - - 199.4188002280943140128727971292337826315387363387763786i)) > - __CZ__eps) { - epsilon(eps); - return 164; + (lngamma(0.6000 - 63.30i) - + (-98.09768141832058996231194071903760307280235519603364210 - + 199.4188002280943140128727971292337826315387363387763786i)) > + __CZ__eps) { + epsilon(eps); + return 164; } if (abs - (lngamma(0.6000 - 64.30i) - - (-99.66691028409427522125385963825011409754630863598190917 - - 203.5745341728981030650825963445356527935331129342248469i)) > - __CZ__eps) { - epsilon(eps); - return 165; + (lngamma(0.6000 - 64.30i) - + (-99.66691028409427522125385963825011409754630863598190917 - + 203.5745341728981030650825963445356527935331129342248469i)) > + __CZ__eps) { + epsilon(eps); + return 165; } if (abs - (lngamma(0.6000 - 65.30i) - - (-101.2361633409781854893699037629524761308029390440175099 - - 207.7458211201573236805249632667291754315339341665724958i)) > - __CZ__eps) { - epsilon(eps); - return 166; + (lngamma(0.6000 - 65.30i) - + (-101.2361633409781854893699037629524761308029390440175099 - + 207.7458211201573236805249632667291754315339341665724958i)) > + __CZ__eps) { + epsilon(eps); + return 166; } if (abs - (lngamma(55.60 - 60.30i) - - (138.3405218869058217717201182836422027677382184890964165 - - 250.9485307086751713133102893231808151265549690071705472i)) > - __CZ__eps) { - epsilon(eps); - return 167; + (lngamma(55.60 - 60.30i) - + (138.3405218869058217717201182836422027677382184890964165 - + 250.9485307086751713133102893231808151265549690071705472i)) > + __CZ__eps) { + epsilon(eps); + return 167; } if (abs - (lngamma(56.60 - 60.30i) - - (142.7474976121018701984157500679190442966110797769323173 - - 251.7744588650459198825346353772080509751313819470548658i)) > - __CZ__eps) { - epsilon(eps); - return 168; + (lngamma(56.60 - 60.30i) - + (142.7474976121018701984157500679190442966110797769323173 - + 251.7744588650459198825346353772080509751313819470548658i)) > + __CZ__eps) { + epsilon(eps); + return 168; } if (abs - (lngamma(57.60 - 60.30i) - - (147.1627435319602425515209166358781832064023544924212637 - - 252.5914974493805839443768868968642526869013797892608722i)) > - __CZ__eps) { - epsilon(eps); - return 169; + (lngamma(57.60 - 60.30i) - + (147.1627435319602425515209166358781832064023544924212637 - + 252.5914974493805839443768868968642526869013797892608722i)) > + __CZ__eps) { + epsilon(eps); + return 169; } if (abs - (lngamma(58.60 - 60.30i) - - (151.5862689029682042031606617640450220740985775964639233 - - 253.3997923739994162421416717294147634900873392644324912i)) > - __CZ__eps) { - epsilon(eps); - return 170; + (lngamma(58.60 - 60.30i) - + (151.5862689029682042031606617640450220740985775964639233 - + 253.3997923739994162421416717294147634900873392644324912i)) > + __CZ__eps) { + epsilon(eps); + return 170; } if (abs - (lngamma(59.60 - 60.30i) - - (156.0180803184689022095120622630277425180433295653817951 - - 254.1994872924291535134537002289372877256760561545266240i)) > - __CZ__eps) { - epsilon(eps); - return 171; + (lngamma(59.60 - 60.30i) - + (156.0180803184689022095120622630277425180433295653817951 - + 254.1994872924291535134537002289372877256760561545266240i)) > + __CZ__eps) { + epsilon(eps); + return 171; } if (abs - (lngamma(60.60 - 60.30i) - - (160.4581818322128207752571131620498333645831099884594593 - - 254.9907235879958949246830907372060458378867915677707498i)) > - __CZ__eps) { - epsilon(eps); - return 172; + (lngamma(60.60 - 60.30i) - + (160.4581818322128207752571131620498333645831099884594593 - + 254.9907235879958949246830907372060458378867915677707498i)) > + __CZ__eps) { + epsilon(eps); + return 172; } if (abs - (lngamma(61.60 - 60.30i) - - (164.9065750781912363906196189745577497508505165621357938 - - 255.7736403669080425654455012237246051402306640891736322i)) > - __CZ__eps) { - epsilon(eps); - return 173; + (lngamma(61.60 - 60.30i) - + (164.9065750781912363906196189745577497508505165621357938 - + 255.7736403669080425654455012237246051402306640891736322i)) > + __CZ__eps) { + epsilon(eps); + return 173; } if (abs - (lngamma(62.60 - 60.30i) - - (169.3632593867220799863942253592790131010186217605278241 - - 256.5483744554910528044048617005478717965073680654042053i)) > - __CZ__eps) { - epsilon(eps); - return 174; + (lngamma(62.60 - 60.30i) - + (169.3632593867220799863942253592790131010186217605278241 - + 256.5483744554910528044048617005478717965073680654042053i)) > + __CZ__eps) { + epsilon(eps); + return 174; } if (abs - (lngamma(63.60 - 60.30i) - - (173.8282318967764198928263540479369804154959334380883398 - - 257.3150604012511380535676929646281795055983167823336193i)) > - __CZ__eps) { - epsilon(eps); - return 175; + (lngamma(63.60 - 60.30i) - + (173.8282318967764198928263540479369804154959334380883398 - + 257.3150604012511380535676929646281795055983167823336193i)) > + __CZ__eps) { + epsilon(eps); + return 175; } if (abs - (lngamma(64.60 - 60.30i) - - (178.3014876645497005489995740718100489155558324227755847 - - 258.0738304774605436591436026066009539042787457216911291i)) > - __CZ__eps) { - epsilon(eps); - return 176; - } + (lngamma(64.60 - 60.30i) - + (178.3014876645497005489995740718100489155558324227755847 - + 258.0738304774605436591436026066009539042787457216911291i)) > + __CZ__eps) { + epsilon(eps); + return 176; + } if (abs - (lngamma(65.60 - 60.30i) - - (182.7830197682960267239662260557525833694506977039319737 - - 258.8248146909724805417993325211754807069936951454932977i)) > - __CZ__eps) { - epsilon(eps); - return 177; - } + (lngamma(65.60 - 60.30i) - + (182.7830197682960267239662260557525833694506977039319737 - + 258.8248146909724805417993325211754807069936951454932977i)) > + __CZ__eps) { + epsilon(eps); + return 177; + } if (abs - (lngamma(55.60 - 55.30i) - - (142.3862162791589253462657451176275726003857264651343509 - - 229.0474972316203435288188174128389032017308276896396827i)) > - __CZ__eps) { - epsilon(eps); - return 178; - } + (lngamma(55.60 - 55.30i) - + (142.3862162791589253462657451176275726003857264651343509 - + 229.0474972316203435288188174128389032017308276896396827i)) > + __CZ__eps) { + epsilon(eps); + return 178; + } if (abs - (lngamma(56.60 - 56.30i) - - (145.9655713474689753168556009847734887663033552824290632 - - 234.2012259525622513896404861908422505950646506577988340i)) > - __CZ__eps) { - epsilon(eps); - return 179; - } + (lngamma(56.60 - 56.30i) - + (145.9655713474689753168556009847734887663033552824290632 - + 234.2012259525622513896404861908422505950646506577988340i)) > + __CZ__eps) { + epsilon(eps); + return 179; + } if (abs - (lngamma(57.60 - 57.30i) - - (149.5627523253413003508200851967083007076485608754907532 - - 239.3727177204530395107173394215426561501560159557014103i)) > - __CZ__eps) { - epsilon(eps); - return 180; - } + (lngamma(57.60 - 57.30i) - + (149.5627523253413003508200851967083007076485608754907532 - + 239.3727177204530395107173394215426561501560159557014103i)) > + __CZ__eps) { + epsilon(eps); + return 180; + } if (abs - (lngamma(58.60 - 58.30i) - - (153.1774470047839472501216057736005131302626263510371392 - - 244.5616624984797644536433102063654140139237547865421532i)) > - __CZ__eps) { - epsilon(eps); - return 181; - } + (lngamma(58.60 - 58.30i) - + (153.1774470047839472501216057736005131302626263510371392 - + 244.5616624984797644536433102063654140139237547865421532i)) > + __CZ__eps) { + epsilon(eps); + return 181; + } if (abs - (lngamma(59.60 - 59.30i) - - (156.8093539260984043245770025957276995010069796775703177 - - 249.7677608875474964335171539461488545902215228674008981i)) > - __CZ__eps) { - epsilon(eps); - return 182; - } + (lngamma(59.60 - 59.30i) - + (156.8093539260984043245770025957276995010069796775703177 - + 249.7677608875474964335171539461488545902215228674008981i)) > + __CZ__eps) { + epsilon(eps); + return 182; + } if (abs - (lngamma(60.60 - 60.30i) - - (160.4581818322128207752571131620498333645831099884594593 - - 254.9907235879958949246830907372060458378867915677707498i)) > - __CZ__eps) { - epsilon(eps); - return 183; - } + (lngamma(60.60 - 60.30i) - + (160.4581818322128207752571131620498333645831099884594593 - + 254.9907235879958949246830907372060458378867915677707498i)) > + __CZ__eps) { + epsilon(eps); + return 183; + } if (abs - (lngamma(61.60 - 61.30i) - - (164.1236491593380218382957487779642572534385362007999916 - - 260.2302708970324395553848679531333038493595454481482560i)) > - __CZ__eps) { - epsilon(eps); - return 184; - } + (lngamma(61.60 - 61.30i) - + (164.1236491593380218382957487779642572534385362007999916 - + 260.2302708970324395553848679531333038493595454481482560i)) > + __CZ__eps) { + epsilon(eps); + return 184; + } if (abs - (lngamma(62.60 - 62.30i) - - (167.8054835609733823774016164868506426238263526697353479 - - 265.4861322389681286058365065491944749198017327500214219i)) > - __CZ__eps) { - epsilon(eps); - return 185; - } + (lngamma(62.60 - 62.30i) - + (167.8054835609733823774016164868506426238263526697353479 - + 265.4861322389681286058365065491944749198017327500214219i)) > + __CZ__eps) { + epsilon(eps); + return 185; + } if (abs - (lngamma(63.60 - 63.30i) - - (171.5034214625769205528980449555097665172285302158028025 - - 270.7580457256222186188843213325906832500862444373572311i)) > - __CZ__eps) { - epsilon(eps); - return 186; - } + (lngamma(63.60 - 63.30i) - + (171.5034214625769205528980449555097665172285302158028025 - + 270.7580457256222186188843213325906832500862444373572311i)) > + __CZ__eps) { + epsilon(eps); + return 186; + } if (abs - (lngamma(64.60 - 64.30i) - - (175.2172076444693933495200678808489471651335658562522069 - - 276.0457577445122795003295082894754935609216218032287116i)) > - __CZ__eps) { - epsilon(eps); - return 187; - } + (lngamma(64.60 - 64.30i) - + (175.2172076444693933495200678808489471651335658562522069 - + 276.0457577445122795003295082894754935609216218032287116i)) > + __CZ__eps) { + epsilon(eps); + return 187; + } if (abs - (lngamma(65.60 - 65.30i) - - (178.9465948507696967449494536146172974534191430062324139 - - 281.3490225726683461623186324992570909685317567794418009i)) > - __CZ__eps) { - epsilon(eps); - return 188; + (lngamma(65.60 - 65.30i) - + (178.9465948507696967449494536146172974534191430062324139 - + 281.3490225726683461623186324992570909685317567794418009i)) > + __CZ__eps) { + epsilon(eps); + return 188; } /* a large integer */ if (abs(lngamma(10 ^ 2 + 1) - (ln((10 ^ 2) !))) > __CZ__eps) { - epsilon(eps); - return 189; + epsilon(eps); + return 189; } epsilon(eps); if (isnull(type)) - t02(1); + t02(1); epsilon(eps); return 0; @@ -1606,41 +1606,41 @@ define t03() local eps; eps = epsilon(1e-20); if (abs(psi(5) - 1.506117668431800472726821243) > __CZ__eps) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if (!iserror(psi(-5))) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if (abs(psi(-5.5) - (1.792911330399932941915445023)) > __CZ__eps) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } if (abs(psi(5.5) - (1.611093148581751123733626842)) > __CZ__eps) { - epsilon(eps); - return 4; + epsilon(eps); + return 4; } if (abs - (psi(5.5 + 5.5i) - - (2.005864860662911769895523042 + 0.8322301014098247099090843855i)) > - __CZ__eps) { - epsilon(eps); - return 5; + (psi(5.5 + 5.5i) - + (2.005864860662911769895523042 + 0.8322301014098247099090843855i)) > + __CZ__eps) { + epsilon(eps); + return 5; } if (abs - (psi(-5.5 + 5.5i) - - (2.096773951572002678986432133 + 2.400271643089053271126857721i)) > - __CZ__eps) { - epsilon(eps); - return 6; + (psi(-5.5 + 5.5i) - + (2.096773951572002678986432133 + 2.400271643089053271126857721i)) > + __CZ__eps) { + epsilon(eps); + return 6; } if (abs - (psi(-5.5 - 5.5i) - - (2.096773951572002678986432133 - 2.400271643089053271126857721i)) > - __CZ__eps) { - epsilon(eps); - return 7; + (psi(-5.5 - 5.5i) - + (2.096773951572002678986432133 - 2.400271643089053271126857721i)) > + __CZ__eps) { + epsilon(eps); + return 7; } epsilon(eps); return 0; @@ -1656,38 +1656,38 @@ define t04() local eps; eps = epsilon(1e-20); if (abs(polygamma(2, 5) - (-0.048789732245114496725)) > __CZ__eps) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if (!iserror(polygamma(2, -5))) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if (abs(polygamma(2, -5.5) - (-0.02758791070687679879)) > __CZ__eps) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } if (abs(polygamma(2, 5.5) - (-0.03960894752130204297)) > __CZ__eps) { - epsilon(eps); - return 4; + epsilon(eps); + return 4; } if (abs - (polygamma(2, 5.5 + 5.5i) - - (0.00163921986957704426 + 0.01803230748452131112i)) > __CZ__eps) { - epsilon(eps); - return 5; + (polygamma(2, 5.5 + 5.5i) - + (0.00163921986957704426 + 0.01803230748452131112i)) > __CZ__eps) { + epsilon(eps); + return 5; } if (abs - (polygamma(2, -5.5 + 5.5i) - - (-0.00136603933402926677 - 0.015027048280671555719i)) > __CZ__eps) { - epsilon(eps); - return 6; + (polygamma(2, -5.5 + 5.5i) - + (-0.00136603933402926677 - 0.015027048280671555719i)) > __CZ__eps) { + epsilon(eps); + return 6; } if (abs - (polygamma(2, -5.5 - 5.5i) - - (-0.00136603933402926677 + 0.015027048280671555719i)) > __CZ__eps) { - epsilon(eps); - return 7; + (polygamma(2, -5.5 - 5.5i) - + (-0.00136603933402926677 + 0.015027048280671555719i)) > __CZ__eps) { + epsilon(eps); + return 7; } epsilon(eps); return 0; @@ -1702,173 +1702,173 @@ define t05() local eps; eps = epsilon(1e-20); if (abs(hurwitzzeta(2, 5) - (0.2213229557371153253613040555)) > __CZ__eps) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if (abs(hurwitzzeta(5, 2) - (0.03692775514336992633136548646)) > __CZ__eps){ - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if (abs(hurwitzzeta(2.2, 5) - (0.1363459661171646798298971735))> __CZ__eps){ - epsilon(eps); - return 3; + epsilon(eps); + return 3; } if (abs(hurwitzzeta(2.2, 5.2) - (0.1294703948013920875737274341)) > - __CZ__eps) { - epsilon(eps); - return 4; + __CZ__eps) { + epsilon(eps); + return 4; } if (abs(hurwitzzeta(-2.2, 5.2) - (-43.62740512741650992650645550)) > - __CZ__eps) { - epsilon(eps); - return 5; + __CZ__eps) { + epsilon(eps); + return 5; } if (abs - (hurwitzzeta(-2.2, -5.2) - - (65.71970386778362403451264243 + 47.73828461458444658816112446i)) > - __CZ__eps) { - epsilon(eps); - return 6; + (hurwitzzeta(-2.2, -5.2) - + (65.71970386778362403451264243 + 47.73828461458444658816112446i)) > + __CZ__eps) { + epsilon(eps); + return 6; } if (abs - (hurwitzzeta(2.2, 5.2 + 5.6i) - - (0.038440773159665466748278144 - 0.0662501636737772199523476381i)) > - __CZ__eps) { - epsilon(eps); - return 7; + (hurwitzzeta(2.2, 5.2 + 5.6i) - + (0.038440773159665466748278144 - 0.0662501636737772199523476381i)) > + __CZ__eps) { + epsilon(eps); + return 7; } if (abs - (hurwitzzeta(2.2, 5.2 - 5.6i) - - (0.038440773159665466748278144 + 0.06625016367377721995234763811i)) > - __CZ__eps) { - epsilon(eps); - return 8; + (hurwitzzeta(2.2, 5.2 - 5.6i) - + (0.038440773159665466748278144 + 0.06625016367377721995234763811i)) > + __CZ__eps) { + epsilon(eps); + return 8; } if (abs - (hurwitzzeta(2.2, -5.2 + 5.6i) - - (-0.06570771621451414059240507315 - - 0.02045673968185922880458837166i)) > __CZ__eps) { - epsilon(eps); - return 9; + (hurwitzzeta(2.2, -5.2 + 5.6i) - + (-0.06570771621451414059240507315 - + 0.02045673968185922880458837166i)) > __CZ__eps) { + epsilon(eps); + return 9; } if (abs - (hurwitzzeta(2.2, -5.2 - 5.6i) - - (-0.06570771621451414059240507315 + - 0.02045673968185922880458837166i)) > __CZ__eps) { - epsilon(eps); - return 10; + (hurwitzzeta(2.2, -5.2 - 5.6i) - + (-0.06570771621451414059240507315 + + 0.02045673968185922880458837166i)) > __CZ__eps) { + epsilon(eps); + return 10; } if (abs - (hurwitzzeta(-2.2, 5.2 + 5.6i) - - (171.3023982201237034174265227 - 61.37099215219445965540875817i)) > - __CZ__eps) { - epsilon(eps); - return 11; + (hurwitzzeta(-2.2, 5.2 + 5.6i) - + (171.3023982201237034174265227 - 61.37099215219445965540875817i)) > + __CZ__eps) { + epsilon(eps); + return 11; } if (abs - (hurwitzzeta(-2.2, 5.2 - 5.6i) - - (171.3023982201237034174265227 + 61.37099215219445965540875820i)) > - __CZ__eps) { - epsilon(eps); - return 12; + (hurwitzzeta(-2.2, 5.2 - 5.6i) - + (171.3023982201237034174265227 + 61.37099215219445965540875820i)) > + __CZ__eps) { + epsilon(eps); + return 12; } if (abs - (hurwitzzeta(-2.2, -5.2 + 5.6i) - - (-69.18353604795857246443145272 - 231.4707567406623523296345557i)) > - __CZ__eps) { - epsilon(eps); - return 13; + (hurwitzzeta(-2.2, -5.2 + 5.6i) - + (-69.18353604795857246443145272 - 231.4707567406623523296345557i)) > + __CZ__eps) { + epsilon(eps); + return 13; } if (abs - (hurwitzzeta(-2.2, -5.2 - 5.6i) - - (-69.18353604795857246443145272 + 231.4707567406623523296345557i)) > - __CZ__eps) { - epsilon(eps); - return 14; + (hurwitzzeta(-2.2, -5.2 - 5.6i) - + (-69.18353604795857246443145272 + 231.4707567406623523296345557i)) > + __CZ__eps) { + epsilon(eps); + return 14; } if (abs - (hurwitzzeta(5.2 + 5.6i, 2.2) - - (-0.002865569533484339556271871050 + - 0.0148003604570643921348488531i)) > __CZ__eps) { - epsilon(eps); - return 15; + (hurwitzzeta(5.2 + 5.6i, 2.2) - + (-0.002865569533484339556271871050 + + 0.0148003604570643921348488531i)) > __CZ__eps) { + epsilon(eps); + return 15; } if (abs - (hurwitzzeta(5.2 - 5.6i, 2.2) - - (-0.002865569533484339556271871050 - - 0.0148003604570643921348488531i)) > __CZ__eps) { - epsilon(eps); - return 16; + (hurwitzzeta(5.2 - 5.6i, 2.2) - + (-0.002865569533484339556271871050 - + 0.0148003604570643921348488531i)) > __CZ__eps) { + epsilon(eps); + return 16; } if (abs - (hurwitzzeta(-5.2 + 5.6i, 2.2) - - (-1.837761873462765905576370048 + 3.192719531152431336748963871i)) > - __CZ__eps) { - epsilon(eps); - return 17; + (hurwitzzeta(-5.2 + 5.6i, 2.2) - + (-1.837761873462765905576370048 + 3.192719531152431336748963871i)) > + __CZ__eps) { + epsilon(eps); + return 17; } if (abs - (hurwitzzeta(-5.2 - 5.6i, 2.2) - - (-1.837761873462765905576346060 - 3.192719531152431336748963871i)) > - __CZ__eps) { - epsilon(eps); - return 18; + (hurwitzzeta(-5.2 - 5.6i, 2.2) - + (-1.837761873462765905576346060 - 3.192719531152431336748963871i)) > + __CZ__eps) { + epsilon(eps); + return 18; } if (abs - (hurwitzzeta(5.2 + 5.6i, -2.2) - - (95348834359.70315397408796804 - 162510500631.4367394107265635i)) > - __CZ__eps) { - epsilon(eps); + (hurwitzzeta(5.2 + 5.6i, -2.2) - + (95348834359.70315397408796804 - 162510500631.4367394107265635i)) > + __CZ__eps) { + epsilon(eps); ##return 19; } if (abs - (hurwitzzeta(5.2 - 5.6i, -2.2) - - (0.9651349278612417712864108926 - 3.036274517135684343726981739i)) > - __CZ__eps) { - epsilon(eps); - return 20; + (hurwitzzeta(5.2 - 5.6i, -2.2) - + (0.9651349278612417712864108926 - 3.036274517135684343726981739i)) > + __CZ__eps) { + epsilon(eps); + return 20; } if (abs - (hurwitzzeta(-5.2 + 5.6i, -2.2) - - (2002299780.711849103677017204 - 1543130375.266699195007479145i)) > - __CZ__eps) { - epsilon(eps); + (hurwitzzeta(-5.2 + 5.6i, -2.2) - + (2002299780.711849103677017204 - 1543130375.266699195007479145i)) > + __CZ__eps) { + epsilon(eps); ##return 21; } if (abs - (hurwitzzeta(-5.2 - 5.6i, -2.2) - - (-0.2104165672779048392846890114 + 1.106842659781205784424725697i)) > - __CZ__eps) { - epsilon(eps); - return 22; + (hurwitzzeta(-5.2 - 5.6i, -2.2) - + (-0.2104165672779048392846890114 + 1.106842659781205784424725697i)) > + __CZ__eps) { + epsilon(eps); + return 22; } if (abs - (hurwitzzeta(5.2 + 5.6i, 2.2 + 2.6i) - - (0.10228577464688104933513226525 + 0.2344359367956833252781356235i)) > - __CZ__eps) { - epsilon(eps); - return 23; + (hurwitzzeta(5.2 + 5.6i, 2.2 + 2.6i) - + (0.10228577464688104933513226525 + 0.2344359367956833252781356235i)) > + __CZ__eps) { + epsilon(eps); + return 23; } if (abs - (hurwitzzeta(5.2 + 5.6i, 2.2 - 2.6i) - - (-0.000005879828833971610476305738830 - - 0.000001047520361040864830120054308i)) > __CZ__eps) { - epsilon(eps); - return 24; + (hurwitzzeta(5.2 + 5.6i, 2.2 - 2.6i) - + (-0.000005879828833971610476305738830 - + 0.000001047520361040864830120054308i)) > __CZ__eps) { + epsilon(eps); + return 24; } if (abs - (hurwitzzeta(5.2 + 5.6i, -2.2 + 2.6i) - - (330.37403168831191021183 + 207.41259747950966196661i)) > __CZ__eps) { - epsilon(eps); + (hurwitzzeta(5.2 + 5.6i, -2.2 + 2.6i) - + (330.37403168831191021183 + 207.41259747950966196661i)) > __CZ__eps) { + epsilon(eps); ##return 25; } if (abs - (hurwitzzeta(5.2 + 5.6i, -2.2 - 2.6i) - - (-0.0000000696683752518857692716375 - - 0.0000000517200890759579067258627i)) > __CZ__eps) { - epsilon(eps); + (hurwitzzeta(5.2 + 5.6i, -2.2 - 2.6i) - + (-0.0000000696683752518857692716375 - + 0.0000000517200890759579067258627i)) > __CZ__eps) { + epsilon(eps); ##return 26; } epsilon(eps); @@ -1877,56 +1877,56 @@ define t05() /* test 06 tests zeta(s) * - * Zero with smallest imaginary part - * 1/2+14.13472514173469379045725198i 0 + * Zero with smallest imaginary part + * 1/2+14.13472514173469379045725198i 0 */ define t06() { local eps; eps = epsilon(1e-20); if (abs(zeta(2) - (1.644934066848226436472415167)) > __CZ__eps) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if (!iserror(zeta(1))) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if (abs(zeta(3) - (1.202056903159594285399738162)) > __CZ__eps) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } if (abs(zeta(-3) - (1 / 120)) > __CZ__eps) { - epsilon(eps); - return 4; + epsilon(eps); + return 4; } if (abs - (zeta(5.5 + 5.6i) - - (0.985921045907062298613817 + 0.014724913951794894908415i)) > - __CZ__eps) { - epsilon(eps); - return 5; + (zeta(5.5 + 5.6i) - + (0.985921045907062298613817 + 0.014724913951794894908415i)) > + __CZ__eps) { + epsilon(eps); + return 5; } if (abs - (zeta(5.2 - 5.6i) - - (0.9829916458246897306781279065 - 0.01804690180657353497603622245i)) > - __CZ__eps) { - epsilon(eps); - return 6; + (zeta(5.2 - 5.6i) - + (0.9829916458246897306781279065 - 0.01804690180657353497603622245i)) > + __CZ__eps) { + epsilon(eps); + return 6; } if (abs - (zeta(-5.2 + 5.6i) - - (-1.101851386544252162781870264 - 0.1426833937495229821744935458i)) > - __CZ__eps) { - epsilon(eps); - return 7; + (zeta(-5.2 + 5.6i) - + (-1.101851386544252162781870264 - 0.1426833937495229821744935458i)) > + __CZ__eps) { + epsilon(eps); + return 7; } if (abs - (zeta(-5.2 - 5.6i) - - (-1.101851386544252162781870264 + 0.1426833937495229821744935458i)) > - __CZ__eps) { - epsilon(eps); - return 8; + (zeta(-5.2 - 5.6i) - + (-1.101851386544252162781870264 + 0.1426833937495229821744935458i)) > + __CZ__eps) { + epsilon(eps); + return 8; } epsilon(eps); return 0; @@ -1937,25 +1937,25 @@ define t07() local eps; eps = epsilon(1e-20); if (!iserror(harmonic(0))) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if (harmonic(1) - 1 != 0) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if (harmonic(3) - 11 / 6 != 0) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } if (harmonic(10) - 7381 / 2520 != 0) { - epsilon(eps); - return 4; + epsilon(eps); + return 4; } if (harmonic(100) - (14466636279520351160221518043104131447711 / - 2788815009188499086581352357412492142272) != 0) { - epsilon(eps); - return 5; + 2788815009188499086581352357412492142272) != 0) { + epsilon(eps); + return 5; } epsilon(eps); return 0; @@ -1965,38 +1965,38 @@ define t08() local eps; eps = epsilon(1e-20); if ((doublefactorial(10) - 3840) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if ((doublefactorial(11) - 10395) != 0) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if (abs((doublefactorial(-11) - (-1 / 945))) > __CZ__eps) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } if (!iserror(doublefactorial(-10))) { - epsilon(eps); - return 4; + epsilon(eps); + return 4; } if (abs - ((doublefactorial(5.2) - - 18.37288214375756118207669378072506887684550012806364822857845)) > - __CZ__eps) { - epsilon(eps); - return 7; + ((doublefactorial(5.2) - + 18.37288214375756118207669378072506887684550012806364822857845)) > + __CZ__eps) { + epsilon(eps); + return 7; } if (abs - ((doublefactorial(-5.2) - - 0.310704476688173329838586027938765271259515590892296917353047)) > - __CZ__eps) { - epsilon(eps); - return 8; + ((doublefactorial(-5.2) - + 0.310704476688173329838586027938765271259515590892296917353047)) > + __CZ__eps) { + epsilon(eps); + return 8; } epsilon(eps); return 0; @@ -2006,28 +2006,28 @@ define t09() local eps; eps = epsilon(1e-20); if ((stirling1(10, 0) - (0)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if ((stirling1(0, 10) - (0)) != 0) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if ((stirling1(0, 0) - (1)) != 0) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } if ((stirling1(10, 10) - (1)) != 0) { - epsilon(eps); - return 4; + epsilon(eps); + return 4; } if ((stirling1(10, 1) - (-362880)) != 0) { - epsilon(eps); - return 5; + epsilon(eps); + return 5; } if ((stirling1(10, 5) - (-269325)) != 0) { - epsilon(eps); - return 6; + epsilon(eps); + return 6; } epsilon(eps); return 0; @@ -2038,24 +2038,24 @@ define t010() local eps; eps = epsilon(1e-20); if ((stirling2(10, 0) - (0)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if ((stirling2(0, 10) - (0)) != 0) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if ((stirling2(0, 0) - (1)) != 0) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } if ((stirling2(10, 10) - (1)) != 0) { - epsilon(eps); - return 4; + epsilon(eps); + return 4; } if ((stirling2(10, 1) - (1)) != 0) { - epsilon(eps); - return 5; + epsilon(eps); + return 5; } /* * When an expression such as 0^(6-6) returned 0, @@ -2069,8 +2069,8 @@ define t010() * } */ if ((stirling2(10, 5) - 42525) != 0) { - epsilon(eps); - return 6; + epsilon(eps); + return 6; } epsilon(eps); return 0; @@ -2080,28 +2080,28 @@ define t011() local eps; eps = epsilon(1e-20); if ((stirling2caching(10, 0) - (0)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if ((stirling2caching(0, 10) - (0)) != 0) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if ((stirling2caching(0, 0) - (1)) != 0) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } if ((stirling2caching(10, 10) - (1)) != 0) { - epsilon(eps); - return 4; + epsilon(eps); + return 4; } if ((stirling2caching(10, 1) - (1)) != 0) { - epsilon(eps); - return 5; + epsilon(eps); + return 5; } if ((stirling2caching(10, 5) - (42525)) != 0) { - epsilon(eps); - return 6; + epsilon(eps); + return 6; } epsilon(eps); return 0; @@ -2112,25 +2112,25 @@ define t012() local eps; eps = epsilon(1e-20); if ((bell(0) - (1)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if ((bell(1) - (1)) != 0) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } epsilon(eps); if ((bell(2) - (2)) != 0) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } if ((bell(5) - (52)) != 0) { - epsilon(eps); - return 4; + epsilon(eps); + return 4; } if ((bell(10) - (115975)) != 0) { - epsilon(eps); - return 5; + epsilon(eps); + return 5; } return 0; } @@ -2140,16 +2140,16 @@ define t013() local eps; eps = epsilon(1e-20); if ((subfactorial(0) - (1)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if ((subfactorial(1) - (0)) != 0) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if ((subfactorial(10) - (1334961)) != 0) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } epsilon(eps); return 0; @@ -2160,24 +2160,24 @@ define t014() local eps; eps = epsilon(1e-20); if ((risingfactorial(1, 0) - (1)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if ((risingfactorial(10, 5) - (240240)) != 0) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if (abs(risingfactorial(10.5, 5.5) - (1153886.265503555482030983579)) > - __CZ__eps) { - epsilon(eps); + __CZ__eps) { + epsilon(eps); ##return 3; } if (abs - (risingfactorial(5.5 + 5.6i, 2.2 + 2.6i) - - (3.368463696973104283045428256 + 14.07030243790744467421234172i)) > - __CZ__eps) { - epsilon(eps); - return 4; + (risingfactorial(5.5 + 5.6i, 2.2 + 2.6i) - + (3.368463696973104283045428256 + 14.07030243790744467421234172i)) > + __CZ__eps) { + epsilon(eps); + return 4; } epsilon(eps); return 0; @@ -2188,21 +2188,21 @@ define t015() local eps; eps = epsilon(1e-20); if ((bigcatalan(0) - (1)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if ((bigcatalan(1) - (1)) != 0) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if ((bigcatalan(10) - (16796)) != 0) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } if ((bigcatalan(100) - - (896519947090131496687170070074100632420837521538745909320)) != 0) { - epsilon(eps); - return 4; + (896519947090131496687170070074100632420837521538745909320)) != 0) { + epsilon(eps); + return 4; } epsilon(eps); return 0; @@ -2213,24 +2213,24 @@ define t016() local eps; eps = epsilon(1e-20); if ((binomial(0, 0) - (1)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if ((binomial(1, 0) - (1)) != 0) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if ((binomial(10, 5) - (252)) != 0) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } if ((binomial(100, 50) - (100891344545564193334812497256)) != 0) { - epsilon(eps); - return 4; + epsilon(eps); + return 4; } if ((binomial(1000, 500) - (comb(1000, 500))) != 0) { - epsilon(eps); - return 5; + epsilon(eps); + return 5; } epsilon(eps); return 0; @@ -2242,12 +2242,12 @@ define t017() eps = epsilon(1e-20); if ((factorial(20) - (2432902008176640000)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if ((factorial(100) - (100 !)) != 0) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } epsilon(eps); return 0; @@ -2258,16 +2258,16 @@ define t018() local eps; eps = epsilon(1e-20); if ((primorial(3, 100) - (1152783981972759212376551073665878035)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if ((primorial(0, 20000) - (pfact(20000))) != 0) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if ((primorial(50, 100) - (3749562977351496827)) != 0) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } epsilon(eps); return 0; @@ -2278,8 +2278,8 @@ define t019() local eps; eps = epsilon(1e-20); if ((toomcook3(161 !, 171 !) - (161 ! *171 !)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } epsilon(eps); return 0; @@ -2290,8 +2290,8 @@ define t020() local eps; eps = epsilon(1e-20); if ((toomcook3square(161 !) - (161 ! ^2)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } epsilon(eps); return 0; @@ -2302,8 +2302,8 @@ define t021() local eps; eps = epsilon(1e-20); if ((toomcook4(561 !, 571 !) - (561 ! *571 !)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } epsilon(eps); return 0; @@ -2314,8 +2314,8 @@ define t022() local eps; eps = epsilon(1e-20); if ((toomcook4square(561 !) - (561 ! ^2)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } epsilon(eps); return 0; @@ -2326,24 +2326,24 @@ define t023() local eps; eps = epsilon(1e-20); if ((fallingfactorial(1, 0) - (1)) != 0) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if ((fallingfactorial(10, 5) - (30240)) != 0) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if (abs(fallingfactorial(10.5, 5.5) - (99161.85903301873714177523949)) > - __CZ__eps) { - epsilon(eps); - return 3; + __CZ__eps) { + epsilon(eps); + return 3; } if (abs - (fallingfactorial(5.5 + 5.6i, 2.2 + 2.6i) - - (9.29931208830258420309197062886 + 1.28691176641462072673306933720i)) > - __CZ__eps) { - epsilon(eps); - return 4; + (fallingfactorial(5.5 + 5.6i, 2.2 + 2.6i) - + (9.29931208830258420309197062886 + 1.28691176641462072673306933720i)) > + __CZ__eps) { + epsilon(eps); + return 4; } epsilon(eps); return 0; @@ -2354,93 +2354,93 @@ define t024() local eps; eps = epsilon(1e-20); if (abs - (gammainc(10.5, 5.5) - - (1.0911054922884267714587707298319763515031034460618e6)) > __CZ__eps) { - epsilon(eps); - return 1; + (gammainc(10.5, 5.5) - + (1.0911054922884267714587707298319763515031034460618e6)) > __CZ__eps) { + epsilon(eps); + return 1; } if (abs - (gammainc(-10.5, 5.5) - - (4.2078651459391823080015064331563180161168802280640e-12)) > - __CZ__eps) { - epsilon(eps); - return 2; + (gammainc(-10.5, 5.5) - + (4.2078651459391823080015064331563180161168802280640e-12)) > + __CZ__eps) { + epsilon(eps); + return 2; } if (abs - (gammainc(-10.5, -5.5) - - (-2.6401218205477163162463853253112404396824684325226e-7 - - 9.9525091595256241288827723005552353976489914201570e-7i)) > - __CZ__eps) { - epsilon(eps); - return 3; + (gammainc(-10.5, -5.5) - + (-2.6401218205477163162463853253112404396824684325226e-7 - + 9.9525091595256241288827723005552353976489914201570e-7i)) > + __CZ__eps) { + epsilon(eps); + return 3; } if (abs - (gammainc(1.5, .5) - - (0.71009105827755696037984229929040777357378308627454)) > __CZ__eps) { - epsilon(eps); - return 4; + (gammainc(1.5, .5) - + (0.71009105827755696037984229929040777357378308627454)) > __CZ__eps) { + epsilon(eps); + return 4; } if (abs - (gammainc(1.5, -.5) - - (0.88622692545275801364908374167057259139877472806119 + - 0.32085932483101833896117715124223338525178610972460i)) > __CZ__eps) { - epsilon(eps); - return 5; + (gammainc(1.5, -.5) - + (0.88622692545275801364908374167057259139877472806119 + + 0.32085932483101833896117715124223338525178610972460i)) > __CZ__eps) { + epsilon(eps); + return 5; } if (abs - (gammainc(-1.5, -.5) - - (2.3632718012073547030642233111215269103967326081632 + - 3.9644835083455478417145204862038235291784113581824i)) > __CZ__eps) { - epsilon(eps); - return 6; + (gammainc(-1.5, -.5) - + (2.3632718012073547030642233111215269103967326081632 + + 3.9644835083455478417145204862038235291784113581824i)) > __CZ__eps) { + epsilon(eps); + return 6; } if (abs - (gammainc(1.6 + 2.3i, 2.3 + 1.4i) - - (-0.023112977574442024349110845737131658924522434973607 + - 0.070013601354006150597855752670117927127985847641410i)) > - __CZ__eps) { - epsilon(eps); - return 7; + (gammainc(1.6 + 2.3i, 2.3 + 1.4i) - + (-0.023112977574442024349110845737131658924522434973607 + + 0.070013601354006150597855752670117927127985847641410i)) > + __CZ__eps) { + epsilon(eps); + return 7; } if (abs - (gammainc(-1.6 + 2.3i, 2.3 + 1.4i) - - (0.00129628045952650890786497724124399230099593819048313 + - 0.00015977289383944841440851534670535231366264702893907i)) > - __CZ__eps) { - epsilon(eps); - return 8; + (gammainc(-1.6 + 2.3i, 2.3 + 1.4i) - + (0.00129628045952650890786497724124399230099593819048313 + + 0.00015977289383944841440851534670535231366264702893907i)) > + __CZ__eps) { + epsilon(eps); + return 8; } if (abs - (gammainc(1.6 + 2.3i, -2.3 + 1.4i) - - (0.08011526555206793146266272247818512925483090324121 + - 0.18864341054002800687777400618294098230871057870324i)) > __CZ__eps) { - epsilon(eps); - return 9; + (gammainc(1.6 + 2.3i, -2.3 + 1.4i) - + (0.08011526555206793146266272247818512925483090324121 + + 0.18864341054002800687777400618294098230871057870324i)) > __CZ__eps) { + epsilon(eps); + return 9; } if (abs - (gammainc(-1.6 + 2.3i, -2.3 + 1.4i) - - (-0.0011066646302249434949283340601015297970855623709232 + - 0.0066140667340761534747256896056105993963563038859892i)) > - __CZ__eps) { - epsilon(eps); - return 10; + (gammainc(-1.6 + 2.3i, -2.3 + 1.4i) - + (-0.0011066646302249434949283340601015297970855623709232 + + 0.0066140667340761534747256896056105993963563038859892i)) > + __CZ__eps) { + epsilon(eps); + return 10; } if (abs - (gammainc(-1.6 + 2.3i, -2.3 - 1.4i) - - (-192.26502410894853081990761345498010642885875566887 - - 9.20687819570448375251655049593050937346609469761i)) > __CZ__eps) { - epsilon(eps); - return 11; + (gammainc(-1.6 + 2.3i, -2.3 - 1.4i) - + (-192.26502410894853081990761345498010642885875566887 - + 9.20687819570448375251655049593050937346609469761i)) > __CZ__eps) { + epsilon(eps); + return 11; } if (abs - (gammainc(-1.6 - 2.3i, -2.3 - 1.4i) - - (-0.0011066646302249434949283340601015297970855623709232 - - 0.0066140667340761534747256896056105993963563038859892i)) > - __CZ__eps) { - epsilon(eps); - return 11; + (gammainc(-1.6 - 2.3i, -2.3 - 1.4i) - + (-0.0011066646302249434949283340601015297970855623709232 - + 0.0066140667340761534747256896056105993963563038859892i)) > + __CZ__eps) { + epsilon(eps); + return 11; } epsilon(eps); return 0; @@ -2451,89 +2451,89 @@ define t025() local eps; eps = epsilon(1e-20); if (abs - (expoint(12) - (14959.5326663975288522924618760575328096988328805595)) > - __CZ__eps) { - epsilon(eps); - return 1; + (expoint(12) - (14959.5326663975288522924618760575328096988328805595)) > + __CZ__eps) { + epsilon(eps); + return 1; } if (abs - (expoint(-12) - - (-4.75108182467249393259461269666144183573679127590926e-7)) > - __CZ__eps) { - epsilon(eps); - return 2; + (expoint(-12) - + (-4.75108182467249393259461269666144183573679127590926e-7)) > + __CZ__eps) { + epsilon(eps); + return 2; } if (abs - (expoint(1.2) - - (2.44209228519265163972909726430649285323724645317842)) > __CZ__eps) { - epsilon(eps); - return 3; + (expoint(1.2) - + (2.44209228519265163972909726430649285323724645317842)) > __CZ__eps) { + epsilon(eps); + return 3; } if (abs - (expoint(-1.2) - - (-0.158408436851462561424955970710861738534157976840579)) > - __CZ__eps) { - epsilon(eps); - return 4; + (expoint(-1.2) - + (-0.158408436851462561424955970710861738534157976840579)) > + __CZ__eps) { + epsilon(eps); + return 4; } if (abs - (expoint(12 + 12i) - - (1705.83261134074122070523718220504604600321580158721 - - 9839.85856317985996646693634577761869375870438645474i)) > __CZ__eps) { - epsilon(eps); - return 5; + (expoint(12 + 12i) - + (1705.83261134074122070523718220504604600321580158721 - + 9839.85856317985996646693634577761869375870438645474i)) > __CZ__eps) { + epsilon(eps); + return 5; } if (abs - (expoint(12 - 12i) - - (1705.83261134074122070523718220504604600321580158721 + - 9839.85856317985996646693634577761869375870438645474i)) > __CZ__eps) { - epsilon(eps); - return 6; + (expoint(12 - 12i) - + (1705.83261134074122070523718220504604600321580158721 + + 9839.85856317985996646693634577761869375870438645474i)) > __CZ__eps) { + epsilon(eps); + return 6; } if (abs - (expoint(-12 + 12i) - - (-3.4169734885007076190668662199892409755505147e-7 + - 3.14159259071528119035402366471290026841357196537325i)) > __CZ__eps) { - epsilon(eps); - return 7; + (expoint(-12 + 12i) - + (-3.4169734885007076190668662199892409755505147e-7 + + 3.14159259071528119035402366471290026841357196537325i)) > __CZ__eps) { + epsilon(eps); + return 7; } if (abs - (expoint(12i) - - (-0.04978000688411367559592120873699061022711118653376 + - 3.07576756832126998975847022375791405102780057904392i)) > __CZ__eps) { - epsilon(eps); - return 8; + (expoint(12i) - + (-0.04978000688411367559592120873699061022711118653376 + + 3.07576756832126998975847022375791405102780057904392i)) > __CZ__eps) { + epsilon(eps); + return 8; } if (abs - (expoint(-12i) - - (-0.04978000688411367559592120873699061022711118653376 - - 3.07576756832126998975847022375791405102780057904392i)) > __CZ__eps) { - epsilon(eps); - return 9; + (expoint(-12i) - + (-0.04978000688411367559592120873699061022711118653376 - + 3.07576756832126998975847022375791405102780057904392i)) > __CZ__eps) { + epsilon(eps); + return 9; } /* problem with checking, result is correct for more than 20 dec. digits starting from the left */ if (abs - (expoint(120 + 12i) - - (8.56859444638801538211461026892024105606765234361709e49 - - 6.74517461831409343681783273107064901497483026647260e49i)) > - __CZ__eps) { + (expoint(120 + 12i) - + (8.56859444638801538211461026892024105606765234361709e49 - + 6.74517461831409343681783273107064901497483026647260e49i)) > + __CZ__eps) { ##epsilon(eps); ##return 10; } if (abs - (expoint(-120 + 12i) - - (+3.14159265358979323846264338327950288419716939937511i)) > - __CZ__eps) { - epsilon(eps); - return 11; + (expoint(-120 + 12i) - + (+3.14159265358979323846264338327950288419716939937511i)) > + __CZ__eps) { + epsilon(eps); + return 11; } if (abs - (expoint(-120 - 12i) - - (-3.14159265358979323846264338327950288419716939937511i)) > - __CZ__eps) { - epsilon(eps); - return 12; + (expoint(-120 - 12i) - + (-3.14159265358979323846264338327950288419716939937511i)) > + __CZ__eps) { + epsilon(eps); + return 12; } epsilon(eps); return 0; @@ -2545,40 +2545,40 @@ define t026() eps = epsilon(1e-20); if (abs(erf(-120 - 12i) - (-1)) > __CZ__eps) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if (abs(erf(99.99) - (1)) > __CZ__eps) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } /* 45 dec. digits for eps=1e-50 */ if (abs(erf(9.99) - (0.9999999999999999999999999999999999999999999974468)) > - __CZ__eps) { - epsilon(eps); - return 3; + __CZ__eps) { + epsilon(eps); + return 3; } if (abs - (erf(-2.3 - 1.4i) - - (-0.99424424422056398724487886415624629344477362313756 - - 0.00438943284364679943396666714992729629504347523747i)) > __CZ__eps) { - epsilon(eps); - return 4; + (erf(-2.3 - 1.4i) - + (-0.99424424422056398724487886415624629344477362313756 - + 0.00438943284364679943396666714992729629504347523747i)) > __CZ__eps) { + epsilon(eps); + return 4; } if (abs(erf(-2.3) - (-0.99885682340264334853465254061923085980585130855731)) - > __CZ__eps) { - epsilon(eps); - return 5; + > __CZ__eps) { + epsilon(eps); + return 5; } if (abs(erf(2.3) - (0.99885682340264334853465254061923085980585130855731)) > - __CZ__eps) { - epsilon(eps); - return 6; + __CZ__eps) { + epsilon(eps); + return 6; } if (abs(erf(.99) - (0.83850806955536980357979023052992329627081601140813)) > - __CZ__eps) { - epsilon(eps); - return 7; + __CZ__eps) { + epsilon(eps); + return 7; } epsilon(eps); @@ -2592,9 +2592,9 @@ define t027() local eps; eps = epsilon(1e-20); if (abs(erfc(.99) - (0.16149193044463019642020976947007670372918398859187)) - > __CZ__eps) { - epsilon(eps); - return 1; + > __CZ__eps) { + epsilon(eps); + return 1; } epsilon(eps); return 0; @@ -2605,9 +2605,9 @@ define t028() local eps; eps = epsilon(1e-20); if (abs(erfi(.99) - (1.6200569163157349040754017322766470558922229178510)) > - __CZ__eps) { - epsilon(eps); - return 1; + __CZ__eps) { + epsilon(eps); + return 1; } epsilon(eps); return 0; @@ -2618,11 +2618,11 @@ define t029() local eps; eps = epsilon(1e-20); if (abs - (faddeeva(.99) - - (0.37527356961800734273134990254630990179418484551111 + - 0.60796454197014723823608088189149188617146675891187i)) > __CZ__eps) { - epsilon(eps); - return 1; + (faddeeva(.99) - + (0.37527356961800734273134990254630990179418484551111 + + 0.60796454197014723823608088189149188617146675891187i)) > __CZ__eps) { + epsilon(eps); + return 1; } epsilon(eps); return 0; @@ -2640,12 +2640,12 @@ define t030() local eps; eps = epsilon(1e-20); if (abs - (beta(1.3 + 2.4i, -4.5 - 5.6i) - - (0.000034922633369217658778094854951087306276597448077494 - - 0.000016960351329535510681653275397511166236842713819260i)) > - __CZ__eps) { - epsilon(eps); - return 1; + (beta(1.3 + 2.4i, -4.5 - 5.6i) - + (0.000034922633369217658778094854951087306276597448077494 - + 0.000016960351329535510681653275397511166236842713819260i)) > + __CZ__eps) { + epsilon(eps); + return 1; } epsilon(eps); return 0; @@ -2656,54 +2656,54 @@ define t031() local eps; eps = epsilon(1e-20); if (abs(betainc(1 / 2, 3, 2) - (5 / 16)) > __CZ__eps) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if (abs - (betainc(1 / 2, 3.2, 2.2) - - (0.32023348284114229739228778858728452204329664688830)) > __CZ__eps) { - epsilon(eps); - return 2; + (betainc(1 / 2, 3.2, 2.2) - + (0.32023348284114229739228778858728452204329664688830)) > __CZ__eps) { + epsilon(eps); + return 2; } if (abs - (betainc(1 / exp(1), 3.2, 2.2) - - (0.143501414415760044882767192140002923147960247904570923787840)) > - __CZ__eps) { - epsilon(eps); - return 3; + (betainc(1 / exp(1), 3.2, 2.2) - + (0.143501414415760044882767192140002923147960247904570923787840)) > + __CZ__eps) { + epsilon(eps); + return 3; } if (abs - (betainc(1 / exp(1), 3.2 + 2.2i, 2.2 + 3.2i) - - (0.1920631154241732316251688573913064389571283459161802570675 + - 0.05732686873367104592514061113957628848615221217965454321767i)) > - __CZ__eps) { - epsilon(eps); - return 4; + (betainc(1 / exp(1), 3.2 + 2.2i, 2.2 + 3.2i) - + (0.1920631154241732316251688573913064389571283459161802570675 + + 0.05732686873367104592514061113957628848615221217965454321767i)) > + __CZ__eps) { + epsilon(eps); + return 4; } if (abs - (betainc(1 / exp(1), 3.2 - 2.2i, 2.2 + 3.2i) - - (-1.607827926223643076788007453936176458240169077851360442476 + - 0.3252661246098073645694057662278573284778244036835313591942i)) > - __CZ__eps) { - epsilon(eps); - return 5; + (betainc(1 / exp(1), 3.2 - 2.2i, 2.2 + 3.2i) - + (-1.607827926223643076788007453936176458240169077851360442476 + + 0.3252661246098073645694057662278573284778244036835313591942i)) > + __CZ__eps) { + epsilon(eps); + return 5; } if (abs - (betainc(1 / exp(1), 3.2 - 2.2i, 2.2 - 3.2i) - - (0.1920631154241732316251688573913064389571283459161802570675 - - 0.05732686873367104592514061113957628848615221217965454321767i)) > - __CZ__eps) { - epsilon(eps); - return 6; + (betainc(1 / exp(1), 3.2 - 2.2i, 2.2 - 3.2i) - + (0.1920631154241732316251688573913064389571283459161802570675 - + 0.05732686873367104592514061113957628848615221217965454321767i)) > + __CZ__eps) { + epsilon(eps); + return 6; } if (abs - (betainc(.3 + .2i, 3.2 - 2.2i, 2.2 - 3.2i) - - (0.14627145927962494526466549157120107465791647692488861570015 + - 0.34598256304551640762453165549710979002810660424791884148625i)) > - __CZ__eps) { - epsilon(eps); - return 7; + (betainc(.3 + .2i, 3.2 - 2.2i, 2.2 - 3.2i) - + (0.14627145927962494526466549157120107465791647692488861570015 + + 0.34598256304551640762453165549710979002810660424791884148625i)) > + __CZ__eps) { + epsilon(eps); + return 7; } epsilon(eps); return 0; @@ -2714,30 +2714,30 @@ define t032() local eps; eps = epsilon(1e-20); if (abs(bernpoly(1, 10)) - (19 / 2) > __CZ__eps) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if (abs(bernpoly(10, 10)) - (379041290105 / 66) > __CZ__eps) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if (abs(bernpoly(-10, 10)) - - (0.00000000015893950304018571788968681852452102762225) > __CZ__eps) { - epsilon(eps); - return 3; + (0.00000000015893950304018571788968681852452102762225) > __CZ__eps) { + epsilon(eps); + return 3; } if (abs(bernpoly(1.1, 10)) - - (11.89799882840077795855328366923295539944336494342302) > __CZ__eps) { - epsilon(eps); - return 4; + (11.89799882840077795855328366923295539944336494342302) > __CZ__eps) { + epsilon(eps); + return 4; } if (abs(bernpoly(3, 1.1)) - (33 / 500) > __CZ__eps) { - epsilon(eps); - return 5; + epsilon(eps); + return 5; } if (abs(bernpoly(3, 1.1 + 2.2i)) - (-8.646 - 8.822i) > __CZ__eps) { - epsilon(eps); - return 6; + epsilon(eps); + return 6; } epsilon(eps); @@ -2750,23 +2750,23 @@ define t033() eps = epsilon(1e-20); /* The Omega-constant */ if (abs - (lambertw(1, 0) - - (0.567143290409783872999968662210355549753815787186512508135131)) > - __CZ__eps) { - epsilon(eps); - return 1; + (lambertw(1, 0) - + (0.567143290409783872999968662210355549753815787186512508135131)) > + __CZ__eps) { + epsilon(eps); + return 1; } if (abs - (lambertw(-1, 0) - - (-0.3181315052047641353126542515876645172035176138713998669223 + - 1.337235701430689408901162143193710612539502138460512418876i)) > - __CZ__eps) { - epsilon(eps); - return 2; + (lambertw(-1, 0) - + (-0.3181315052047641353126542515876645172035176138713998669223 + + 1.337235701430689408901162143193710612539502138460512418876i)) > + __CZ__eps) { + epsilon(eps); + return 2; } if (abs(lambertw(-exp(-1), 0) - (-1)) > __CZ__eps) { - epsilon(eps); - return 3; + epsilon(eps); + return 3; } /* We have to calculate -exp(1-) with higher precision here because the @@ -2777,37 +2777,37 @@ define t033() EM1 = -exp(-1); epsilon(epsexp); if (abs - (lambertw(EM1 + .001, 0) - - (-0.92802015005456704876004302525492122474886334787070023086031)) > - __CZ__eps) { - epsilon(eps); - return 4; + (lambertw(EM1 + .001, 0) - + (-0.92802015005456704876004302525492122474886334787070023086031)) > + __CZ__eps) { + epsilon(eps); + return 4; } if (abs - (lambertw(EM1 - .001, 0) - - (-0.998190161498609890007959968479276047800779184376006463826 + - 0.0736719118893463857740469900181632551190421844567768514726i)) > - __CZ__eps) { - epsilon(eps); - return 5; + (lambertw(EM1 - .001, 0) - + (-0.998190161498609890007959968479276047800779184376006463826 + + 0.0736719118893463857740469900181632551190421844567768514726i)) > + __CZ__eps) { + epsilon(eps); + return 5; } if (abs - (lambertw_series(EM1 - .001, epsilon(), 0) - - (-0.998190161498609890007959968479276047800779184376006463826 + - 0.0736719118893463857740469900181632551190421844567768514726i)) > - __CZ__eps) { - epsilon(eps); - return 6; + (lambertw_series(EM1 - .001, epsilon(), 0) - + (-0.998190161498609890007959968479276047800779184376006463826 + + 0.0736719118893463857740469900181632551190421844567768514726i)) > + __CZ__eps) { + epsilon(eps); + return 6; } if (abs - (lambertw(-2.2 - 3.2i, -3) - - (-1.6104280970561586263262514675217857074068306154494786722437 - - 19.368888979715570028505505411206710993669557347359767961957i)) > - __CZ__eps) { - epsilon(eps); - return 1; + (lambertw(-2.2 - 3.2i, -3) - + (-1.6104280970561586263262514675217857074068306154494786722437 - + 19.368888979715570028505505411206710993669557347359767961957i)) > + __CZ__eps) { + epsilon(eps); + return 1; } epsilon(eps); return 0; @@ -2822,12 +2822,12 @@ define t034() sum = 0; lnseries(10000); for (k = 1; k < 10000; k++) { - sum += lnfromseries(k); + sum += lnfromseries(k); } if (abs(sum - lngamma(10000)) > __CZ__eps) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } epsilon(eps); return 0; @@ -2838,69 +2838,69 @@ define t035() local eps; eps = epsilon(1e-20); if (abs(invbetainc(0, 1, 2) - (0)) > __CZ__eps) { - epsilon(eps); - return 1; + epsilon(eps); + return 1; } if (abs(invbetainc(1, 1, 2) - (1)) > __CZ__eps) { - epsilon(eps); - return 2; + epsilon(eps); + return 2; } if (abs - (invbetainc(.6, 2, 2) - - (0.567068922852268236254340214074933386511229358602804986856523)) > - __CZ__eps) { - epsilon(eps); - return 3; + (invbetainc(.6, 2, 2) - + (0.567068922852268236254340214074933386511229358602804986856523)) > + __CZ__eps) { + epsilon(eps); + return 3; } if (abs - (invbetainc(.6, 200, 200) - - 0.50633738276018061834297937341956576111427477636401902379793) > - __CZ__eps) { - epsilon(eps); - return 4; + (invbetainc(.6, 200, 200) - + 0.50633738276018061834297937341956576111427477636401902379793) > + __CZ__eps) { + epsilon(eps); + return 4; } if (abs - (invbetainc(.6, 200, 100) - - 0.673912010450469394843418496081985274734344595591643614514860) > - __CZ__eps) { - epsilon(eps); - return 5; + (invbetainc(.6, 200, 100) - + 0.673912010450469394843418496081985274734344595591643614514860) > + __CZ__eps) { + epsilon(eps); + return 5; } if (abs - (invbetainc(.6, 100, 200) - - 0.339884769324050809456643025345905001680568878491743324211449) > - __CZ__eps) { - epsilon(eps); - return 6; + (invbetainc(.6, 100, 200) - + 0.339884769324050809456643025345905001680568878491743324211449) > + __CZ__eps) { + epsilon(eps); + return 6; } /* Percentiles. Numbers shamelessly stolen from a question at stackoverflow */ if (abs - (invbetainc(0.025, 10008, 151744) - - 0.060703546312525377697082321820950758320207425674954679415395) > - __CZ__eps) { - epsilon(eps); - return 7; + (invbetainc(0.025, 10008, 151744) - + 0.060703546312525377697082321820950758320207425674954679415395) > + __CZ__eps) { + epsilon(eps); + return 7; } if (abs - (invbetainc(0.5, 10008, 151744) - - 0.061870690413044293003568412977601333629269461143858842860376) > - __CZ__eps) { - epsilon(eps); - return 8; + (invbetainc(0.5, 10008, 151744) - + 0.061870690413044293003568412977601333629269461143858842860376) > + __CZ__eps) { + epsilon(eps); + return 8; } if (abs - (invbetainc(0.975, 10008, 151744) - - 0.063051707940007549704137764265896313422520123493324715525400) > - __CZ__eps) { - epsilon(eps); - return 9; + (invbetainc(0.975, 10008, 151744) - + 0.063051707940007549704137764265896313422520123493324715525400) > + __CZ__eps) { + epsilon(eps); + return 9; } /* 3 sigma. But _way_ too slow. */ if (abs - (invbetainc(0.997, 10008, 151744) - - 0.06353033717730117616403237097166742264875876591597) > __CZ__eps) { - epsilon(eps); - return 10; + (invbetainc(0.997, 10008, 151744) - + 0.06353033717730117616403237097166742264875876591597) > __CZ__eps) { + epsilon(eps); + return 10; } epsilon(eps); @@ -3051,40 +3051,40 @@ define t037(){ * * The regress.cal calls this function as: * - * testnum = test8900(1,, 8903); + * testnum = test8900(1,, 8903); */ define test8900(verbose = 0, tnum, testnum = 8903) { local n; - local err; /* do not forget to delete! */ + local err; /* do not forget to delete! */ local i, old_errmax; /* * parse args */ - n = 37; /* number of subtests */ + n = 37; /* number of subtests */ if (isnull(verbose)) { - verbose = 0; + verbose = 0; } if (isnull(tnum)) { - tnum = 1; /* initial test number */ + tnum = 1; /* initial test number */ } /* * run just one test */ else { - err = eval(strcat("t0", str(tnum), "()")); - if (verbose) { - if (err) { - print "*** error", err, - ": found in test8900.cal function test", strcat("t0", - str(tnum)); - } else { - print "no errors in test", strcat("t0", str(tnum)); - } - } - return tnum; + err = eval(strcat("t0", str(tnum), "()")); + if (verbose) { + if (err) { + print "*** error", err, + ": found in test8900.cal function test", strcat("t0", + str(tnum)); + } else { + print "no errors in test", strcat("t0", str(tnum)); + } + } + return tnum; } /* We will cause errors intentionally. A lot of them. */ @@ -3095,29 +3095,29 @@ define test8900(verbose = 0, tnum, testnum = 8903) */ for (i = 0; i < n; ++i) { - /* run a test */ - err += eval(strcat("t0", str(tnum++), "()")); + /* run a test */ + err += eval(strcat("t0", str(tnum++), "()")); - if (verbose) { - if (err) { - print "*** error", err, "in test", testnum:":", strcat("t0", + if (verbose) { + if (err) { + print "*** error", err, "in test", testnum:":", strcat("t0", str(tnum - 1), "()"), - " - ", - eval(strcat("t0", str(tnum - 1), "()")); - } else { - print testnum:": no errors in test", strcat("t0", + " - ", + eval(strcat("t0", str(tnum - 1), "()")); + } else { + print testnum:": no errors in test", strcat("t0", str(tnum - 1)); - } - } - ++testnum; + } + } + ++testnum; } if (verbose) { - if (err) { - print "***", testnum:":", err, - "error(s) found in test8900.cal"; - } else { - print testnum:":", "no errors in test8900.cal"; - } + if (err) { + print "***", testnum:":", err, + "error(s) found in test8900.cal"; + } else { + print testnum:":", "no errors in test8900.cal"; + } } ++testnum; diff --git a/cal/test9300.frem.cal b/cal/test9300.frem.cal index ccedc17..84d61d2 100644 --- a/cal/test9300.frem.cal +++ b/cal/test9300.frem.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,239 +19,239 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/12/18 22:50:46 - * File existed as early as: 1995 + * Under source code control: 1995/12/18 22:50:46 + * File existed as early as: 1995 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * Stringent tests of the functions frem, fcnt, gcdrem. * * testf(n) gives n tests of frem(x,y) and fcnt(x,y) with randomly - * integers x and y generated so that x = f * y^k where f, y and - * k are randomly generated. + * integers x and y generated so that x = f * y^k where f, y and + * k are randomly generated. * * testg(n) gives n tests of gcdrem(x,y) with x and y generated as for - * testf(n). + * testf(n). * * testh(n,N) gives n tests of g = gcdrem(x,y) where x and y are products of - * powers of small primes some of which are common to both x and y. - * This test uses f = abs(x) and iteratively f = frem(f,p) where - * p varies over the prime divisors of y; the final value for f - * should equal g. For both x and y the primes are raised to the - * power rand(N); N defaults to 10. + * powers of small primes some of which are common to both x and y. + * This test uses f = abs(x) and iteratively f = frem(f,p) where + * p varies over the prime divisors of y; the final value for f + * should equal g. For both x and y the primes are raised to the + * power rand(N); N defaults to 10. * * If verbose is > 1, the numbers x, y and values for some of the - * functions will be displayed. Numbers used in testf() - * and testg() occasionally have thousands of digits. + * functions will be displayed. Numbers used in testf() + * and testg() occasionally have thousands of digits. * */ -defaultverbose = 1; /* default verbose value */ +defaultverbose = 1; /* default verbose value */ define testfrem(x,y,verbose) { - local f, n; + local f, n; - if (isnull(verbose)) verbose = defaultverbose; + if (isnull(verbose)) verbose = defaultverbose; - f = frem(x,y); - n = fcnt(x,y); - if (verbose > 1) - printf("frem = %d, fcnt = %d\n\n", f, n); - if (abs(x) != f * abs(y)^n) - return 1; - if (!ismult(x,y) || abs(y) <= 1) { - if (f != abs(x)) - return 2; - if (n != 0) - return 3; - return 0; - } - if (x == 0) { - if (f != 0 || n != 0) - return 4; - return 0; - } - if (f < 0 || !isint(f) || n <= 0) - return 5; - if (ismult(f, y)) - return 6; - if (!ismult(x, y^n)) - return 7; - if (ismult(x, y^(n+1))) - return 8; - return 0; + f = frem(x,y); + n = fcnt(x,y); + if (verbose > 1) + printf("frem = %d, fcnt = %d\n\n", f, n); + if (abs(x) != f * abs(y)^n) + return 1; + if (!ismult(x,y) || abs(y) <= 1) { + if (f != abs(x)) + return 2; + if (n != 0) + return 3; + return 0; + } + if (x == 0) { + if (f != 0 || n != 0) + return 4; + return 0; + } + if (f < 0 || !isint(f) || n <= 0) + return 5; + if (ismult(f, y)) + return 6; + if (!ismult(x, y^n)) + return 7; + if (ismult(x, y^(n+1))) + return 8; + return 0; } define testgcdrem(x,y,verbose) { - local d, q; + local d, q; - if (isnull(verbose)) verbose = defaultverbose; + if (isnull(verbose)) verbose = defaultverbose; - d = gcdrem(x,y); - if (verbose > 1) - printf("gcdrem = %d\n\n", d); - if (y == 0) { - if (d != 1) - return 1; - return 0; - } - if (x == 0) { - if (d != 0) - return 2; - return 0; - } - if (d <= 0) - return 3; - q = x/d; - if (!isint(q)) - return 4; - if (!isrel(d, y)) - return 5; - if (!isrel(d, q)) - return 6; - return 0; + d = gcdrem(x,y); + if (verbose > 1) + printf("gcdrem = %d\n\n", d); + if (y == 0) { + if (d != 1) + return 1; + return 0; + } + if (x == 0) { + if (d != 0) + return 2; + return 0; + } + if (d <= 0) + return 3; + q = x/d; + if (!isint(q)) + return 4; + if (!isrel(d, y)) + return 5; + if (!isrel(d, q)) + return 6; + return 0; } define testf(str,n,verbose) { - local m, x, y, i, k, y1, f1, f, fail; + local m, x, y, i, k, y1, f1, f, fail; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = 0; - for (i = 0; i < n; i++) { - y1 = rand(2^rand(1,6)); - y = rand(-(2^y1), 1 + 2^y1); - f1 = rand(2^rand(1,11)); - f = rand(-(2^f1), 1+2^f1); - k = rand(1,1+2^10); - x = f * y^k; - if (verbose > 1) { - printf("x = %d\n", x); - printf("y = %d\n", y); - } - fail = testfrem(x,y,verbose); - if (fail != 0) { - printf("*** Failure %d on loop %d\n", fail, i); - if (verbose > 1) { - printf(" x = %d\n", x); - printf(" y = %d\n", y); - } - m++; - } - } + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = 0; + for (i = 0; i < n; i++) { + y1 = rand(2^rand(1,6)); + y = rand(-(2^y1), 1 + 2^y1); + f1 = rand(2^rand(1,11)); + f = rand(-(2^f1), 1+2^f1); + k = rand(1,1+2^10); + x = f * y^k; + if (verbose > 1) { + printf("x = %d\n", x); + printf("y = %d\n", y); + } + fail = testfrem(x,y,verbose); + if (fail != 0) { + printf("*** Failure %d on loop %d\n", fail, i); + if (verbose > 1) { + printf(" x = %d\n", x); + printf(" y = %d\n", y); + } + m++; + } + } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("no errors\n"); - } - } - return m; + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("no errors\n"); + } + } + return m; } define testg(str,n,verbose) { - local m, x, y, i, k, y1, f1, f, fail; + local m, x, y, i, k, y1, f1, f, fail; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = 0; - for (i = 0; i < n; i++) { - y1 = rand(2^rand(1,6)); - y = rand(-(2^y1), 1 + 2^y1); - f1 = rand(2^rand(1,11)); - f = rand(-(2^f1), 1+2^f1); - k = rand(1,1+2^10); - x = f * y^k; - if (verbose > 1) { - printf("x = %d\n", x); - printf("y = %d\n", y); - } - fail = testgcdrem(x,y,verbose); - if (fail != 0) { - printf("*** Failure %d on loop %d\n", fail, i); - if (verbose > 1) { - printf(" x = %d\n", x); - printf(" y = %d\n", y); - } - m++; - } - } + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = 0; + for (i = 0; i < n; i++) { + y1 = rand(2^rand(1,6)); + y = rand(-(2^y1), 1 + 2^y1); + f1 = rand(2^rand(1,11)); + f = rand(-(2^f1), 1+2^f1); + k = rand(1,1+2^10); + x = f * y^k; + if (verbose > 1) { + printf("x = %d\n", x); + printf("y = %d\n", y); + } + fail = testgcdrem(x,y,verbose); + if (fail != 0) { + printf("*** Failure %d on loop %d\n", fail, i); + if (verbose > 1) { + printf(" x = %d\n", x); + printf(" y = %d\n", y); + } + m++; + } + } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("no errors\n"); - } - } - return m; + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("no errors\n"); + } + } + return m; } define testh(str,n,N,verbose) { - local m, i, x, y, f, g; + local m, i, x, y, f, g; - if (isnull(verbose)) - verbose = defaultverbose; - if (verbose > 0) { - print str:":",:; - } - m = 0; - if (isnull(N)) - N = 61; - for (i = 0; i < n; i ++) { - x = 2^rand(N)*3^rand(N) * 7^rand(N) * 11^rand(N) * 101^rand(N); - y = 2^rand(N) * 3^rand(N) * 5^rand(N) * 11^rand(N) * 53^rand(N); - if (rand(2)) x = -x; - if (rand(2)) y = -y; + if (isnull(verbose)) + verbose = defaultverbose; + if (verbose > 0) { + print str:":",:; + } + m = 0; + if (isnull(N)) + N = 61; + for (i = 0; i < n; i ++) { + x = 2^rand(N)*3^rand(N) * 7^rand(N) * 11^rand(N) * 101^rand(N); + y = 2^rand(N) * 3^rand(N) * 5^rand(N) * 11^rand(N) * 53^rand(N); + if (rand(2)) x = -x; + if (rand(2)) y = -y; - if (verbose > 1) { - printf("x = %d\n", x); - printf("y = %d\n", y); - } - f = abs(x); - g = gcdrem(x,y); - if (ismult(y,2)) f = frem(f,2); - if (ismult(y,3)) f = frem(f,3); - if (ismult(y,5)) f = frem(f,5); - if (ismult(y,11)) f = frem(f,11); - if (ismult(y,53)) f = frem(f,53); + if (verbose > 1) { + printf("x = %d\n", x); + printf("y = %d\n", y); + } + f = abs(x); + g = gcdrem(x,y); + if (ismult(y,2)) f = frem(f,2); + if (ismult(y,3)) f = frem(f,3); + if (ismult(y,5)) f = frem(f,5); + if (ismult(y,11)) f = frem(f,11); + if (ismult(y,53)) f = frem(f,53); - if (f != g) { - printf("*** Failure on loop %d\n", i); - if (verbose > 1) { - printf(" x = %d\n", x); - printf(" y = %d\n", y); - printf(" f = %d\n", f); - printf(" g = %d\n", g); - } - m++; - } - } + if (f != g) { + printf("*** Failure on loop %d\n", i); + if (verbose > 1) { + printf(" x = %d\n", x); + printf(" y = %d\n", y); + printf(" f = %d\n", f); + printf(" g = %d\n", g); + } + m++; + } + } - if (verbose > 0) { - if (m) { - printf("*** %d error(s)\n", m); - } else { - printf("no errors\n"); - } - } - return m; + if (verbose > 0) { + if (m) { + printf("*** %d error(s)\n", m); + } else { + printf("no errors\n"); + } + } + return m; } /* @@ -259,33 +259,33 @@ define testh(str,n,N,verbose) */ define test9300(verbose, tnum, n, N) { - /* set test parameters */ - if (isnull(verbose)) { - verbose = defaultverbose; - } - if (isnull(tnum)) { - tnum = 9301; /* default test number */ - } - if (isnull(n)) { - n = 200; - } - if (isnull(N)) { - N = 61; - } + /* set test parameters */ + if (isnull(verbose)) { + verbose = defaultverbose; + } + if (isnull(tnum)) { + tnum = 9301; /* default test number */ + } + if (isnull(n)) { + n = 200; + } + if (isnull(N)) { + N = 61; + } - /* - * test a lot of stuff - */ - srand(9300e9300); - err += testf(strcat(str(tnum++), ": frem/fcnt"), n, verbose); - err += testg(strcat(str(tnum++), ": gcdrem"), n, verbose); - err += testh(strcat(str(tnum++),": gcdrem #2"), n, N, verbose); - if (verbose > 1) { - if (err) { - print "***", err, "error(s) found in testall"; - } else { - print "no errors in testall"; - } - } - return tnum; + /* + * test a lot of stuff + */ + srand(9300e9300); + err += testf(strcat(str(tnum++), ": frem/fcnt"), n, verbose); + err += testg(strcat(str(tnum++), ": gcdrem"), n, verbose); + err += testh(strcat(str(tnum++),": gcdrem #2"), n, N, verbose); + if (verbose > 1) { + if (err) { + print "***", err, "error(s) found in testall"; + } else { + print "no errors in testall"; + } + } + return tnum; } diff --git a/cal/test9500.trigeq.cal b/cal/test9500.trigeq.cal index 381ad88..741f5fc 100644 --- a/cal/test9500.trigeq.cal +++ b/cal/test9500.trigeq.cal @@ -9,8 +9,8 @@ * and cos() (trigonometric cosine) are correct. We can reasonably * assume this because of the calc regression test suite: * - * (such as test 34dd and in particular cal/test3400.trig.cal and - * such as test 89dd and in particular cal/test8900.special.cal) + * (such as test 34dd and in particular cal/test3400.trig.cal and + * such as test 89dd and in particular cal/test8900.special.cal) * * will test such those function beforehand. * @@ -30,7 +30,7 @@ * * 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 + * 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 @@ -38,10 +38,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2023/09/10 14:33:06 - * File existed as early as: 2023 + * Under source code control: 2023/09/10 14:33:06 + * File existed as early as: 2023 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -55,22 +55,22 @@ * NOTE: There is no reason to sort these values other than ascetics. :-) */ static base_tval = list( - 1/12, /* ~ 0.08333333333333333333 */ - 1/8, /* 0.12500000000000000000 */ - 1/6, /* ~ 0.16666666666666666667 */ - 1/5, /* 0.20000000000000000000 */ - 1/4, /* 0.25000000000000000000 */ - 1/3, /* ~ 0.33333333333333333333 */ - 3/8, /* 0.37500000000000000000 */ - 5/12, /* ~ 0.41666666666666666667 */ - 1/2, /* 0.50000000000000000000 */ - 2/3, /* ~ 0.66666666666666666667 */ - 3/4, /* 0.75000000000000000000 */ - 4/5, /* 0.80000000000000000000 */ - 5/6, /* ~ 0.83333333333333333333 */ - 7/8, /* 0.87500000000000000000 */ - 11/12, /* ~ 0.91666666666666666667 */ - 1 /* 1.00000000000000000000 */ + 1/12, /* ~ 0.08333333333333333333 */ + 1/8, /* 0.12500000000000000000 */ + 1/6, /* ~ 0.16666666666666666667 */ + 1/5, /* 0.20000000000000000000 */ + 1/4, /* 0.25000000000000000000 */ + 1/3, /* ~ 0.33333333333333333333 */ + 3/8, /* 0.37500000000000000000 */ + 5/12, /* ~ 0.41666666666666666667 */ + 1/2, /* 0.50000000000000000000 */ + 2/3, /* ~ 0.66666666666666666667 */ + 3/4, /* 0.75000000000000000000 */ + 4/5, /* 0.80000000000000000000 */ + 5/6, /* ~ 0.83333333333333333333 */ + 7/8, /* 0.87500000000000000000 */ + 11/12, /* ~ 0.91666666666666666667 */ + 1 /* 1.00000000000000000000 */ ); @@ -94,8 +94,8 @@ tval = list(); * The precompute_trig() function will fill out these lists. * They will be the same size as size as the full test list. */ -sin_tval = list(); /* trigonometric sine of each test test value */ -cos_tval = list(); /* trigonometric cosine of each test test value */ +sin_tval = list(); /* trigonometric sine of each test test value */ +cos_tval = list(); /* trigonometric cosine of each test test value */ /* @@ -109,26 +109,26 @@ cos_tval = list(); /* trigonometric cosine of each test test value */ * Blum-Blum-Shub pseudo-random number generator was seeded with the * following 160-bit SHA1 hash of 3 calls to seed(): * - * sha1(sha1(seed(), seed()<<64, seed()<<128)) == 0x732fda50b1bf6e34b604b7c75b993e5c37a4ad97 + * sha1(sha1(seed(), seed()<<64, seed()<<128)) == 0x732fda50b1bf6e34b604b7c75b993e5c37a4ad97 * * This produced the following 160-bit value that was used to seed * the Blum-Blum-Shub pseudo-random number: * - * srandom(0x732fda50b1bf6e34b604b7c75b993e5c37a4ad97) + * srandom(0x732fda50b1bf6e34b604b7c75b993e5c37a4ad97) * * The seeded Blum-Blum-Shub pseudo-random number generator was then * used to generate a 128-bit value: * - * randombit(128) == 0x37301cf47204f7fababc2f32e39ab338 + * randombit(128) == 0x37301cf47204f7fababc2f32e39ab338 * * We seed the subtractive 100 shuffle pseudo-random number generator * with the above mentioned 128-bit value: * - * srand(0x37301cf47204f7fababc2f32e39ab338) + * srand(0x37301cf47204f7fababc2f32e39ab338) */ define seed_rand() { - return srand(0x37301cf47204f7fababc2f32e39ab338); + return srand(0x37301cf47204f7fababc2f32e39ab338); } @@ -157,27 +157,27 @@ static epsilon_norm = norm(epsilon()); */ define random_rational_value() { - local a; /* epsilon_bits pseudo-random integer > 0 */ - local b; /* epsilon_bits pseudo-random integer > 0 */ + local a; /* epsilon_bits pseudo-random integer > 0 */ + local b; /* epsilon_bits pseudo-random integer > 0 */ - /* - * compute 1st non-zero pseudo-random epsilon_bits integer - */ - do { - a = randbit(epsilon_bits); - } while (a == 0); + /* + * compute 1st non-zero pseudo-random epsilon_bits integer + */ + do { + a = randbit(epsilon_bits); + } while (a == 0); - /* - * compute 2nd non-zero pseudo-random epsilon_bits integer also != a - */ - do { - b = randbit(epsilon_bits); - } while (b == 0 || a == b); + /* + * compute 2nd non-zero pseudo-random epsilon_bits integer also != a + */ + do { + b = randbit(epsilon_bits); + } while (b == 0 || a == b); - /* - * return the min(a,b) / max(a,b): a value > 0 and < 1 - */ - return min(a,b) / max(a,b); + /* + * return the min(a,b) / max(a,b): a value > 0 and < 1 + */ + return min(a,b) / max(a,b); } @@ -188,28 +188,28 @@ define random_rational_value() * * From the test set starts with 16 values from the base_tval[] list: * - * tval = base_tval; + * tval = base_tval; * * We form a list of 32 values by appending all of the above with: * - * tval[i] + 1 + * tval[i] + 1 * * We form a list of 64 values by appending all of the above with: * - * -tval[i] + * -tval[i] * * We form a list of 128 values by appending all of the above with: * - * For values >= 0: tval[i] + random_rational_value - * For values < 0: tval[i] - random_rational_value + * For values >= 0: tval[i] + random_rational_value + * For values < 0: tval[i] - random_rational_value * * We form a list of 256 values by appending all of the above with: * - * tval[i] * pi() + * tval[i] * pi() * * We form a list of 512 values by appending all of the above with: * - * tval[i] * 1i + * tval[i] * 1i * * We for a list of 1024 values by appending new complex values where the * real part is a randomly selected real value (from the first 256 list values), and the @@ -219,87 +219,87 @@ define random_rational_value() */ define form_tval() { - local tval_len; /* current length of the tval[] array */ - local real_cnt; /* number of real values in tval[] array */ - local imag_cnt; /* number of imaginary values in tval[] array */ - local i; + local tval_len; /* current length of the tval[] array */ + local real_cnt; /* number of real values in tval[] array */ + local imag_cnt; /* number of imaginary values in tval[] array */ + local i; - /* - * seed the subtractive 100 shuffle pseudo-random number generator - */ - seed_rand(); + /* + * seed the subtractive 100 shuffle pseudo-random number generator + */ + seed_rand(); - /* - * load base_tval[] array into tval[] array - */ - tval = base_tval; + /* + * load base_tval[] array into tval[] array + */ + tval = base_tval; - /* - * expand all tval with tval+1 - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { - append(tval, tval[i] + 1); - } + /* + * expand all tval with tval+1 + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { + append(tval, tval[i] + 1); + } - /* - * expand all tval with -tval - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { - append(tval, -tval[i]); - } + /* + * expand all tval with -tval + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { + append(tval, -tval[i]); + } - /* - * expand all tval with tval +/- random_rational_value - * - * For values we add random_rational_value if > 0 - * or we subtract crandom_rational_value if < 0. - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * expand all tval with tval +/- random_rational_value + * + * For values we add random_rational_value if > 0 + * or we subtract crandom_rational_value if < 0. + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* use the sign to determine if we add or subtract */ - if (tval[i] >= 0) { - append(tval, tval[i] + random_rational_value()); - } else { - append(tval, tval[i] - random_rational_value()); - } - } + /* use the sign to determine if we add or subtract */ + if (tval[i] >= 0) { + append(tval, tval[i] + random_rational_value()); + } else { + append(tval, tval[i] - random_rational_value()); + } + } - /* - * expand all tval with tval * pi() - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { - append(tval, tval[i] * pi()); - } + /* + * expand all tval with tval * pi() + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { + append(tval, tval[i] * pi()); + } - /* - * expand all tval with tval * 1i - */ - tval_len = size(tval); - /* tval[0] thru tval[real_cnt-1] are real values */ - real_cnt = tval_len; - for (i=0; i < tval_len; ++i) { - append(tval, tval[i] * 1i); - } + /* + * expand all tval with tval * 1i + */ + tval_len = size(tval); + /* tval[0] thru tval[real_cnt-1] are real values */ + real_cnt = tval_len; + for (i=0; i < tval_len; ++i) { + append(tval, tval[i] * 1i); + } - /* - * expand tval with randomly selected real value - * plus randomly selected complex value. - */ - tval_len = size(tval); - /* tval[real_cnt] thru tval[real_cnt+imag_cnt-1] are complex values */ - imag_cnt = tval_len - real_cnt; - for (i=0; i < tval_len; ++i) { - append(tval, tval[rand(0,real_cnt)] + tval[real_cnt + rand(0,imag_cnt)]); - } + /* + * expand tval with randomly selected real value + * plus randomly selected complex value. + */ + tval_len = size(tval); + /* tval[real_cnt] thru tval[real_cnt+imag_cnt-1] are complex values */ + imag_cnt = tval_len - real_cnt; + for (i=0; i < tval_len; ++i) { + append(tval, tval[rand(0,real_cnt)] + tval[real_cnt + rand(0,imag_cnt)]); + } - /* - * last, append our final 0 value - */ - append(tval, 0); + /* + * last, append our final 0 value + */ + append(tval, 0); } @@ -308,41 +308,41 @@ define form_tval() */ define precompute_trig() { - local tval_len; /* current length of the tval[] array */ - local i; + local tval_len; /* current length of the tval[] array */ + local i; - /* - * firewall - be sure tval list is setup - */ - if (size(tval) <= 0) { - form_tval(); - } - tval_len = size(tval); - if (tval_len <= 0) { - quit "FATAL: tval_len is empty"; - } + /* + * firewall - be sure tval list is setup + */ + if (size(tval) <= 0) { + form_tval(); + } + tval_len = size(tval); + if (tval_len <= 0) { + quit "FATAL: tval_len is empty"; + } - /* - * compute trigonometric sine of the tval full test list - */ - for (i=0; i < tval_len; ++i) { - append(sin_tval, sin(tval[i])); - } - if (size(tval) != size(sin_tval)) { - print "****: size(tval):", size(tval), "!= size(sin_tval)", size(sin_tval); - quit "FATAL: sin_tval not same size as tval_len"; - } + /* + * compute trigonometric sine of the tval full test list + */ + for (i=0; i < tval_len; ++i) { + append(sin_tval, sin(tval[i])); + } + if (size(tval) != size(sin_tval)) { + print "****: size(tval):", size(tval), "!= size(sin_tval)", size(sin_tval); + quit "FATAL: sin_tval not same size as tval_len"; + } - /* - * compute trigonometric cosine of the tval full test list - */ - for (i=0; i < tval_len; ++i) { - append(cos_tval, cos(tval[i])); - } - if (size(tval) != size(cos_tval)) { - print "****: size(tval):", size(tval), "!= size(cos_tval)", size(cos_tval); - quit "FATAL: cos_tval not same size as tval_len"; - } + /* + * compute trigonometric cosine of the tval full test list + */ + for (i=0; i < tval_len; ++i) { + append(cos_tval, cos(tval[i])); + } + if (size(tval) != size(cos_tval)) { + print "****: size(tval):", size(tval), "!= size(cos_tval)", size(cos_tval); + quit "FATAL: cos_tval not same size as tval_len"; + } } @@ -350,46 +350,46 @@ define precompute_trig() * compare - compare the trigonometric identity and the trigonometric function value * * given: - * ident_val computed trig value trigonometric identity - * trig_val computed value from the trigonometric function - * name trig function name - * index test index value - * testnum regression test number being performed + * ident_val computed trig value trigonometric identity + * trig_val computed value from the trigonometric function + * name trig function name + * index test index value + * testnum regression test number being performed * * returns: - * 0 ==> trigonometric identity and the trigonometric function value match - * 1 ==> trigonometric identity and the trigonometric function value do NOT match + * 0 ==> trigonometric identity and the trigonometric function value match + * 1 ==> trigonometric identity and the trigonometric function value do NOT match */ define compare(ident_val, trig_val, name, index, testnum) { - local abs_diff; /* absolute difference between ident_val and trig_val */ + local abs_diff; /* absolute difference between ident_val and trig_val */ - /* - * firewall - */ - if (!isnum(trig_val)) { - printf("**** trig test %d-%d failed: %s(tval[%d]): ", - testnum, index, name, index); - printf("%d returned a non-numeric value\n", trig_val); - return 1; - } + /* + * firewall + */ + if (!isnum(trig_val)) { + printf("**** trig test %d-%d failed: %s(tval[%d]): ", + testnum, index, name, index); + printf("%d returned a non-numeric value\n", trig_val); + return 1; + } - /* - * compute absolute difference - */ - abs_diff = abs(ident_val - trig_val); + /* + * compute absolute difference + */ + abs_diff = abs(ident_val - trig_val); - /* - * determine if ident_val within epsilon of trig_val - */ - if (near(norm(abs_diff), epsilon_norm) > 0) { - printf("**** trig test %d-%d failed: %s(tval[%d]): ", - testnum, index, name, index); - printf("%d is not near trig identity value: %d\n", - trig_val, ident_val); - return 1; - } - return 0; + /* + * determine if ident_val within epsilon of trig_val + */ + if (near(norm(abs_diff), epsilon_norm) > 0) { + printf("**** trig test %d-%d failed: %s(tval[%d]): ", + testnum, index, name, index); + printf("%d is not near trig identity value: %d\n", + trig_val, ident_val); + return 1; + } + return 0; } @@ -397,21 +397,21 @@ define compare(ident_val, trig_val, name, index, testnum) * not_near_zero - determine if a value is within epsilon() of 0 * * given: - * value real or complex value + * value real or complex value * * returns: - * 1 ==> value is farther from 0 than epsilon (not near zero) - * 0 ==> value is within epsilon of 0 (near zero) + * 1 ==> value is farther from 0 than epsilon (not near zero) + * 0 ==> value is within epsilon of 0 (near zero) */ define not_near_zero(value) { - if (near(norm(value), epsilon_norm) > 0) { - /* value is farther from 0 than epsilon */ - return 1; - } + if (near(norm(value), epsilon_norm) > 0) { + /* value is farther from 0 than epsilon */ + return 1; + } - /* value is within epsilon of 0 */ - return 0; + /* value is within epsilon of 0 */ + return 0; } @@ -420,59 +420,59 @@ define not_near_zero(value) * * We use the following trigonometric identity: * - * tan(x) = sin(x) / cos(x) + * tan(x) = sin(x) / cos(x) * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_tan(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(sin_tval) <= 0 || size(cos_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(sin_tval) <= 0 || size(cos_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - error_count = 0; - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + error_count = 0; + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* skip test when cos(x) within epsilon of 0 */ - if (not_near_zero(cos_tval[i])) { + /* skip test when cos(x) within epsilon of 0 */ + if (not_near_zero(cos_tval[i])) { - /* compute trigonometric identity */ - ident_val = sin_tval[i] / cos_tval[i]; + /* compute trigonometric identity */ + ident_val = sin_tval[i] / cos_tval[i]; - /* compute trigonometric function */ - trig_val = tan(tval[i]); + /* compute trigonometric function */ + trig_val = tan(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "tan", i, testnum)) { - ++error_count; - } - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "tan", i, testnum)) { + ++error_count; + } + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': tan test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': tan test failure count:', error_count; + } + return error_count; } @@ -481,58 +481,58 @@ define verify_tan(testnum) * * We use the following trigonometric identity: * - * cot(x) = cos(x) / sin(x) + * cot(x) = cos(x) / sin(x) * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_cot(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(sin_tval) <= 0 || size(cos_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(sin_tval) <= 0 || size(cos_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* skip test when sin(x) within epsilon of 0 */ - if (not_near_zero(sin_tval[i])) { + /* skip test when sin(x) within epsilon of 0 */ + if (not_near_zero(sin_tval[i])) { - /* compute trigonometric identity */ - ident_val = cos_tval[i] / sin_tval[i]; + /* compute trigonometric identity */ + ident_val = cos_tval[i] / sin_tval[i]; - /* compute trigonometric function */ - trig_val = cot(tval[i]); + /* compute trigonometric function */ + trig_val = cot(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "cot", i, testnum)) { - ++error_count; - } - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "cot", i, testnum)) { + ++error_count; + } + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': cot test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': cot test failure count:', error_count; + } + return error_count; } @@ -541,58 +541,58 @@ define verify_cot(testnum) * * We use the following trigonometric identity: * - * sec(x) = 1 / cos(x) + * sec(x) = 1 / cos(x) * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_sec(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(cos_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(cos_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* skip test when cos(x) within epsilon of 0 */ - if (not_near_zero(cos_tval[i])) { + /* skip test when cos(x) within epsilon of 0 */ + if (not_near_zero(cos_tval[i])) { - /* compute trigonometric identity */ - ident_val = 1 / cos_tval[i]; + /* compute trigonometric identity */ + ident_val = 1 / cos_tval[i]; - /* compute trigonometric function */ - trig_val = sec(tval[i]); + /* compute trigonometric function */ + trig_val = sec(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "sec", i, testnum)) { - ++error_count; - } - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "sec", i, testnum)) { + ++error_count; + } + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': sec test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': sec test failure count:', error_count; + } + return error_count; } @@ -601,58 +601,58 @@ define verify_sec(testnum) * * We use the following trigonometric identity: * - * csc(x) = 1 / sin(x) + * csc(x) = 1 / sin(x) * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_csc(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(sin_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(sin_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* skip test when sin(x) within epsilon of 0 */ - if (not_near_zero(sin_tval[i])) { + /* skip test when sin(x) within epsilon of 0 */ + if (not_near_zero(sin_tval[i])) { - /* compute trigonometric identity */ - ident_val = 1 / sin_tval[i]; + /* compute trigonometric identity */ + ident_val = 1 / sin_tval[i]; - /* compute trigonometric function */ - trig_val = csc(tval[i]); + /* compute trigonometric function */ + trig_val = csc(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "csc", i, testnum)) { - ++error_count; - } - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "csc", i, testnum)) { + ++error_count; + } + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': csc test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': csc test failure count:', error_count; + } + return error_count; } @@ -661,58 +661,58 @@ define verify_csc(testnum) * * We use the following trigonometric identity: * - * versin(x) = 1 - cos(x) + * versin(x) = 1 - cos(x) * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_versin(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(cos_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(cos_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* skip test when cos(x) within epsilon of 0 */ - if (not_near_zero(cos_tval[i])) { + /* skip test when cos(x) within epsilon of 0 */ + if (not_near_zero(cos_tval[i])) { - /* compute trigonometric identity */ - ident_val = 1 - cos_tval[i]; + /* compute trigonometric identity */ + ident_val = 1 - cos_tval[i]; - /* compute trigonometric function */ - trig_val = versin(tval[i]); + /* compute trigonometric function */ + trig_val = versin(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "versin", i, testnum)) { - ++error_count; - } - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "versin", i, testnum)) { + ++error_count; + } + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': versin test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': versin test failure count:', error_count; + } + return error_count; } @@ -721,58 +721,58 @@ define verify_versin(testnum) * * We use the following trigonometric identity: * - * coversin(x) = 1 - sin(x) + * coversin(x) = 1 - sin(x) * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_coversin(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(sin_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(sin_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* skip test when sin(x) within epsilon of 0 */ - if (not_near_zero(sin_tval[i])) { + /* skip test when sin(x) within epsilon of 0 */ + if (not_near_zero(sin_tval[i])) { - /* compute trigonometric identity */ - ident_val = 1 - sin_tval[i]; + /* compute trigonometric identity */ + ident_val = 1 - sin_tval[i]; - /* compute trigonometric function */ - trig_val = coversin(tval[i]); + /* compute trigonometric function */ + trig_val = coversin(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "coversin", i, testnum)) { - ++error_count; - } - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "coversin", i, testnum)) { + ++error_count; + } + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': coversin test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': coversin test failure count:', error_count; + } + return error_count; } @@ -781,58 +781,58 @@ define verify_coversin(testnum) * * We use the following trigonometric identity: * - * vercos(x) = 1 + cos(x) + * vercos(x) = 1 + cos(x) * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_vercos(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(cos_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(cos_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* skip test when cos(x) within epsilon of 0 */ - if (not_near_zero(cos_tval[i])) { + /* skip test when cos(x) within epsilon of 0 */ + if (not_near_zero(cos_tval[i])) { - /* compute trigonometric identity */ - ident_val = 1 + cos_tval[i]; + /* compute trigonometric identity */ + ident_val = 1 + cos_tval[i]; - /* compute trigonometric function */ - trig_val = vercos(tval[i]); + /* compute trigonometric function */ + trig_val = vercos(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "vercos", i, testnum)) { - ++error_count; - } - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "vercos", i, testnum)) { + ++error_count; + } + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': vercos test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': vercos test failure count:', error_count; + } + return error_count; } @@ -841,58 +841,58 @@ define verify_vercos(testnum) * * We use the following trigonometric identity: * - * covercos(x) = 1 + sin(x) + * covercos(x) = 1 + sin(x) * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_covercos(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(sin_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(sin_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* skip test when sin(x) within epsilon of 0 */ - if (not_near_zero(sin_tval[i])) { + /* skip test when sin(x) within epsilon of 0 */ + if (not_near_zero(sin_tval[i])) { - /* compute trigonometric identity */ - ident_val = 1 + sin_tval[i]; + /* compute trigonometric identity */ + ident_val = 1 + sin_tval[i]; - /* compute trigonometric function */ - trig_val = covercos(tval[i]); + /* compute trigonometric function */ + trig_val = covercos(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "covercos", i, testnum)) { - ++error_count; - } - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "covercos", i, testnum)) { + ++error_count; + } + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': covercos test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': covercos test failure count:', error_count; + } + return error_count; } @@ -901,58 +901,58 @@ define verify_covercos(testnum) * * We use the following trigonometric identity: * - * haversin(x) = versin(x) / 2 = (1 - cos(x)) / 2 + * haversin(x) = versin(x) / 2 = (1 - cos(x)) / 2 * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_haversin(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(cos_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(cos_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* skip test when cos(x) within epsilon of 0 */ - if (not_near_zero(cos_tval[i])) { + /* skip test when cos(x) within epsilon of 0 */ + if (not_near_zero(cos_tval[i])) { - /* compute trigonometric identity */ - ident_val = (1 - cos_tval[i]) / 2; + /* compute trigonometric identity */ + ident_val = (1 - cos_tval[i]) / 2; - /* compute trigonometric function */ - trig_val = haversin(tval[i]); + /* compute trigonometric function */ + trig_val = haversin(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "haversin", i, testnum)) { - ++error_count; - } - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "haversin", i, testnum)) { + ++error_count; + } + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': haversin test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': haversin test failure count:', error_count; + } + return error_count; } @@ -961,58 +961,58 @@ define verify_haversin(testnum) * * We use the following trigonometric identity: * - * hacoversin(x) = coversin(x) / 2 = (1 - sin(x)) / 2 + * hacoversin(x) = coversin(x) / 2 = (1 - sin(x)) / 2 * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_hacoversin(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(sin_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(sin_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* skip test when cos(x) within epsilon of 0 */ - if (not_near_zero(sin_tval[i])) { + /* skip test when cos(x) within epsilon of 0 */ + if (not_near_zero(sin_tval[i])) { - /* compute trigonometric identity */ - ident_val = (1 - sin_tval[i]) / 2; + /* compute trigonometric identity */ + ident_val = (1 - sin_tval[i]) / 2; - /* compute trigonometric function */ - trig_val = hacoversin(tval[i]); + /* compute trigonometric function */ + trig_val = hacoversin(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "hacoversin", i, testnum)) { - ++error_count; - } - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "hacoversin", i, testnum)) { + ++error_count; + } + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': hacoversin test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': hacoversin test failure count:', error_count; + } + return error_count; } @@ -1021,58 +1021,58 @@ define verify_hacoversin(testnum) * * We use the following trigonometric identity: * - * havercos(x) = vercos(x) / 2 = (1 + cos(x)) / 2 + * havercos(x) = vercos(x) / 2 = (1 + cos(x)) / 2 * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_havercos(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(cos_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(cos_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* skip test when cos(x) within epsilon of 0 */ - if (not_near_zero(cos_tval[i])) { + /* skip test when cos(x) within epsilon of 0 */ + if (not_near_zero(cos_tval[i])) { - /* compute trigonometric identity */ - ident_val = (1 + cos_tval[i]) / 2; + /* compute trigonometric identity */ + ident_val = (1 + cos_tval[i]) / 2; - /* compute trigonometric function */ - trig_val = havercos(tval[i]); + /* compute trigonometric function */ + trig_val = havercos(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "havercos", i, testnum)) { - ++error_count; - } - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "havercos", i, testnum)) { + ++error_count; + } + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': havercos test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': havercos test failure count:', error_count; + } + return error_count; } @@ -1081,58 +1081,58 @@ define verify_havercos(testnum) * * We use the following trigonometric identity: * - * hacovercos(x) = covercos(x) / 2 = (1 + sin(x)) / 2 + * hacovercos(x) = covercos(x) / 2 = (1 + sin(x)) / 2 * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_hacovercos(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(sin_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(sin_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* skip test when sin(x) within epsilon of 0 */ - if (not_near_zero(sin_tval[i])) { + /* skip test when sin(x) within epsilon of 0 */ + if (not_near_zero(sin_tval[i])) { - /* compute trigonometric identity */ - ident_val = (1 + sin_tval[i]) / 2; + /* compute trigonometric identity */ + ident_val = (1 + sin_tval[i]) / 2; - /* compute trigonometric function */ - trig_val = hacovercos(tval[i]); + /* compute trigonometric function */ + trig_val = hacovercos(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "hacovercos", i, testnum)) { - ++error_count; - } - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "hacovercos", i, testnum)) { + ++error_count; + } + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': hacovercos test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': hacovercos test failure count:', error_count; + } + return error_count; } @@ -1141,58 +1141,58 @@ define verify_hacovercos(testnum) * * We use the following trigonometric identity: * - * exsec(x) = sec(x) - 1 = (1 / cos(x)) - 1 + * exsec(x) = sec(x) - 1 = (1 / cos(x)) - 1 * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_exsec(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(cos_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(cos_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* skip test when cos(x) within epsilon of 0 */ - if (not_near_zero(cos_tval[i])) { + /* skip test when cos(x) within epsilon of 0 */ + if (not_near_zero(cos_tval[i])) { - /* compute trigonometric identity */ - ident_val = (1 / cos_tval[i]) - 1; + /* compute trigonometric identity */ + ident_val = (1 / cos_tval[i]) - 1; - /* compute trigonometric function */ - trig_val = exsec(tval[i]); + /* compute trigonometric function */ + trig_val = exsec(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "exsec", i, testnum)) { - ++error_count; - } - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "exsec", i, testnum)) { + ++error_count; + } + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': exsec test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': exsec test failure count:', error_count; + } + return error_count; } @@ -1201,58 +1201,58 @@ define verify_exsec(testnum) * * We use the following trigonometric identity: * - * excsc(x) = csc(x) - 1 = (1 / sin(x)) - 1 + * excsc(x) = csc(x) - 1 = (1 / sin(x)) - 1 * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_excsc(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(sin_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(sin_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* skip test when sin(x) within epsilon of 0 */ - if (not_near_zero(sin_tval[i])) { + /* skip test when sin(x) within epsilon of 0 */ + if (not_near_zero(sin_tval[i])) { - /* compute trigonometric identity */ - ident_val = (1 / sin_tval[i]) - 1; + /* compute trigonometric identity */ + ident_val = (1 / sin_tval[i]) - 1; - /* compute trigonometric function */ - trig_val = excsc(tval[i]); + /* compute trigonometric function */ + trig_val = excsc(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "excsc", i, testnum)) { - ++error_count; - } - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "excsc", i, testnum)) { + ++error_count; + } + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': excsc test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': excsc test failure count:', error_count; + } + return error_count; } @@ -1261,56 +1261,56 @@ define verify_excsc(testnum) * * We use the following trigonometric identity: * - * crd(x) = 2 * sin(x / 2) + * crd(x) = 2 * sin(x / 2) * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_crd(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(sin_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(sin_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* NOTE: We actually check the identity: crd(x*2) = 2 * sin(x) */ + /* NOTE: We actually check the identity: crd(x*2) = 2 * sin(x) */ - /* compute trigonometric identity */ - ident_val = 2 * sin_tval[i]; + /* compute trigonometric identity */ + ident_val = 2 * sin_tval[i]; - /* compute trigonometric function */ - trig_val = crd(tval[i] * 2); + /* compute trigonometric function */ + trig_val = crd(tval[i] * 2); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "crd", i, testnum)) { - ++error_count; - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "crd", i, testnum)) { + ++error_count; + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': crd test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': crd test failure count:', error_count; + } + return error_count; } @@ -1319,57 +1319,57 @@ define verify_crd(testnum) * * We use the following trigonometric identity: * - * cas(x) = cos(x) + sin(x) + * cas(x) = cos(x) + sin(x) * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_cas(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(sin_tval) <= 0) { - precompute_trig(); - } - if (size(cos_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(sin_tval) <= 0) { + precompute_trig(); + } + if (size(cos_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* compute trigonometric identity */ - ident_val = cos_tval[i] + sin_tval[i]; + /* compute trigonometric identity */ + ident_val = cos_tval[i] + sin_tval[i]; - /* compute trigonometric function */ - trig_val = cas(tval[i]); + /* compute trigonometric function */ + trig_val = cas(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "cas", i, testnum)) { - ++error_count; - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "cas", i, testnum)) { + ++error_count; + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': cas test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': cas test failure count:', error_count; + } + return error_count; } @@ -1378,56 +1378,56 @@ define verify_cas(testnum) * * We use the following trigonometric identity: * - * cis(x) = cos(x) + i*sin(x) - * cis(x) = exp(1i * x) + * cis(x) = cos(x) + i*sin(x) + * cis(x) = exp(1i * x) * * given: - * testnum regression test number being performed + * testnum regression test number being performed * * returns: - * number of tests that failed + * number of tests that failed */ define verify_cis(testnum) { - local tval_len; /* current length of the tval[] array */ - local ident_val; /* computed trig value trigonometric identity */ - local trig_val; /* computed value from the trigonometric function */ - local error_count; /* number of compare errors detected */ - local i; + local tval_len; /* current length of the tval[] array */ + local ident_val; /* computed trig value trigonometric identity */ + local trig_val; /* computed value from the trigonometric function */ + local error_count; /* number of compare errors detected */ + local i; - /* - * firewall - */ - if (size(sin_tval) <= 0) { - precompute_trig(); - } - if (size(cos_tval) <= 0) { - precompute_trig(); - } + /* + * firewall + */ + if (size(sin_tval) <= 0) { + precompute_trig(); + } + if (size(cos_tval) <= 0) { + precompute_trig(); + } - /* - * for each test value, verify the trigonometric identity within epsilon - */ - tval_len = size(tval); - for (i=0; i < tval_len; ++i) { + /* + * for each test value, verify the trigonometric identity within epsilon + */ + tval_len = size(tval); + for (i=0; i < tval_len; ++i) { - /* compute trigonometric identity */ - ident_val = cos_tval[i] + 1i*sin_tval[i]; + /* compute trigonometric identity */ + ident_val = cos_tval[i] + 1i*sin_tval[i]; - /* compute trigonometric function */ - trig_val = cis(tval[i]); + /* compute trigonometric function */ + trig_val = cis(tval[i]); - /* compare trigonometric identity with trigonometric function value */ - if (compare(ident_val, trig_val, "cis", i, testnum)) { - ++error_count; - } - } + /* compare trigonometric identity with trigonometric function value */ + if (compare(ident_val, trig_val, "cis", i, testnum)) { + ++error_count; + } + } - /* - * report test results - */ - if (error_count != 0) { - print '**** test', testnum : ': cis test failure count:', error_count; - } - return error_count; + /* + * report test results + */ + if (error_count != 0) { + print '**** test', testnum : ': cis test failure count:', error_count; + } + return error_count; } diff --git a/cal/toomcook.cal b/cal/toomcook.cal index 06530c5..04165d9 100644 --- a/cal/toomcook.cal +++ b/cal/toomcook.cal @@ -17,8 +17,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2013/08/11 01:31:28 - * File existed as early as: 2013 + * Under source code control: 2013/08/11 01:31:28 + * File existed as early as: 2013 */ /* @@ -336,7 +336,7 @@ define __CZ__produce_long_random_number(n) ret = 1; if(!isint(n) || n<1) return newerror("__CZ__produce_long_random_number(n): " - "n is not an integer >=1"); + "n is not an integer >=1"); for(k=0;k d) - d = n; - di = 1/d; - print ' [': digits(num(x)): '/': digits(den(x)): ']',, di; - x -= di; - d++; - } while ((num(x) > 1) || (x == di) || (x == 1)); - print ' [1/1]',, x; + if (x <= 0) + quit "Non-positive argument"; + d = 2; + do { + n = int(1 / x) + 1; + if (n > d) + d = n; + di = 1/d; + print ' [': digits(num(x)): '/': digits(den(x)): ']',, di; + x -= di; + d++; + } while ((num(x) > 1) || (x == di) || (x == 1)); + print ' [1/1]',, x; } diff --git a/cal/varargs.cal b/cal/varargs.cal index 4632e37..298f908 100644 --- a/cal/varargs.cal +++ b/cal/varargs.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1991/05/22 21:56:34 - * File existed as early as: 1991 + * Under source code control: 1991/05/22 21:56:34 + * File existed as early as: 1991 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -32,17 +32,17 @@ define sc() { - local s, i; + local s, i; - s = 0; - for (i = 1; i <= param(0); i++) { - if (!isnum(param(i))) { - print "parameter",i,"is not a number"; - continue; - } - s += param(i)^3; - } - return s; + s = 0; + for (i = 1; i <= param(0); i++) { + if (!isnum(param(i))) { + print "parameter",i,"is not a number"; + continue; + } + s += param(i)^3; + } + return s; } if (config("resource_debug") & 3) { diff --git a/cal/write2file.cal b/cal/write2file.cal index 1baf5a4..37236fd 100644 --- a/cal/write2file.cal +++ b/cal/write2file.cal @@ -13,7 +13,7 @@ * * 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 + * 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 @@ -21,11 +21,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2023/08/20 13:13:11 - * File existed as early as: 2023 + * Under source code control: 2023/08/20 13:13:11 + * File existed as early as: 2023 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ diff --git a/cal/xx_print.cal b/cal/xx_print.cal index d1e1f29..e82a88b 100644 --- a/cal/xx_print.cal +++ b/cal/xx_print.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/04/17 00:08:50 - * File existed as early as: 1997 + * Under source code control: 1997/04/17 00:08:50 + * File existed as early as: 1997 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -38,184 +38,184 @@ B = blk(); define is_octet(a) = istype(a, B[0]); define list_print(a) { - local i; - print "(":; - for (i = 0; i < size(a); i++) { - if (i > 0) - print ",":; - if (i >= listmax) { - print "...":; - break; - } - print a[[i]]:; - } - print ")":; + local i; + print "(":; + for (i = 0; i < size(a); i++) { + if (i > 0) + print ",":; + if (i >= listmax) { + print "...":; + break; + } + print a[[i]]:; + } + print ")":; } define mat_print (a) { - local i, j; + local i, j; - if (matdim(a) == 1) { - for (i = 0; i < size(a); i++) { - if (i >= matrowmax) { - printf(" ..."); - break; - } - printf("%8d", a[i]); - } - return; - } - if (matdim(a) > 2) - quit "Dimension for mat_print greater than 2"; + if (matdim(a) == 1) { + for (i = 0; i < size(a); i++) { + if (i >= matrowmax) { + printf(" ..."); + break; + } + printf("%8d", a[i]); + } + return; + } + if (matdim(a) > 2) + quit "Dimension for mat_print greater than 2"; - for (i = matmin(a,1); i <= matmax(a,1); i++) { - if (i >= matmin(a,1) + matcolmax) { - print " ..."; - break; - } - for (j = matmin(a,2); j <= matmax(a,2); j++) { - if (j >= matmin(a,2) + matrowmax) { - printf(" ..."); - break; - } - printf("%8d", a[i,j]); - } - print; - } + for (i = matmin(a,1); i <= matmax(a,1); i++) { + if (i >= matmin(a,1) + matcolmax) { + print " ..."; + break; + } + for (j = matmin(a,2); j <= matmax(a,2); j++) { + if (j >= matmin(a,2) + matrowmax) { + printf(" ..."); + break; + } + printf("%8d", a[i,j]); + } + print; + } } define octet_print(a) { - switch(a) { - case 8: print "BS":; - return; - case 9: print "HT":; - return; - case 10: print "NL":; - return; - case 12: print "FF":; - return; - case 13: print "CR":; - return; - case 27: print "ESC":; - return; - } - if (a > 31 && a < 127) - print char(a):; - else - print "Non-print":; + switch(a) { + case 8: print "BS":; + return; + case 9: print "HT":; + return; + case 10: print "NL":; + return; + case 12: print "FF":; + return; + case 13: print "CR":; + return; + case 27: print "ESC":; + return; + } + if (a > 31 && a < 127) + print char(a):; + else + print "Non-print":; } define blk_print(a) { - local i, n; + local i, n; - n = size(a); + n = size(a); - printf("Unnamed block with %d bytes of data\n", n); - print "First few characters: ":; - for (i = 0; i < n; i++) { - if (i >= blkmax) { - print "...",; - break; - } - print a[i],; - } + printf("Unnamed block with %d bytes of data\n", n); + print "First few characters: ":; + for (i = 0; i < n; i++) { + if (i >= blkmax) { + print "...",; + break; + } + print a[i],; + } } define nblk_print (a) { - local n, i; + local n, i; - n = size(a); + n = size(a); - printf("Block named \"%s\" with %d bytes of data\n", name(a), n); - print "First few characters: ":; - for (i = 0; i < n; i++) { - if (i >= blkmax) { - print "...",; - break; - } - print a[i],; - } + printf("Block named \"%s\" with %d bytes of data\n", name(a), n); + print "First few characters: ":; + for (i = 0; i < n; i++) { + if (i >= blkmax) { + print "...",; + break; + } + print a[i],; + } } define strchar(a) { - if (isstr(a)) - a = ord(a); + if (isstr(a)) + a = ord(a); - else if (is_octet(a)) - a = a; /* This converts octet to number */ + else if (is_octet(a)) + a = a; /* This converts octet to number */ - else if (!isint(a) || a < 0 || a > 255) - quit "Bad argument for strchar"; + else if (!isint(a) || a < 0 || a > 255) + quit "Bad argument for strchar"; - switch (a) { - case 7: print "\\a":; - return; - case 8: print "\\b":; - return; - case 9: print "\\t":; - return; - case 10: print "\\n":; - return; - case 11: print "\\v":; - return; - case 12: print "\\f":; - return; - case 13: print "\\r":; - return; - case 27: print "\\e":; - return; - case 34: print "\\\"":; - return; - case 39: print "\\\'":; - return; - case 92: print "\\\\":; - return; - } - if (a > 31 && a < 127) { - print char(a):; - return; - } - print "\\":; - if (a >= 64) print a // 64:; - a = a % 64; - if (a >= 8) print a // 8:; - a = a % 8; - print a:; + switch (a) { + case 7: print "\\a":; + return; + case 8: print "\\b":; + return; + case 9: print "\\t":; + return; + case 10: print "\\n":; + return; + case 11: print "\\v":; + return; + case 12: print "\\f":; + return; + case 13: print "\\r":; + return; + case 27: print "\\e":; + return; + case 34: print "\\\"":; + return; + case 39: print "\\\'":; + return; + case 92: print "\\\\":; + return; + } + if (a > 31 && a < 127) { + print char(a):; + return; + } + print "\\":; + if (a >= 64) print a // 64:; + a = a % 64; + if (a >= 8) print a // 8:; + a = a % 8; + print a:; } define file_print(a) { - local c; + local c; - rewind(a); - for (;;) { - c = fgetc(a); - if (iserror(c)) - quit "Failure when reading from file"; - if (isnull(c)) - break; - strchar(c); - } - print; + rewind(a); + for (;;) { + c = fgetc(a); + if (iserror(c)) + quit "Failure when reading from file"; + if (isnull(c)) + break; + strchar(c); + } + print; } define error_print(a) { - local n = iserror(a); + local n = iserror(a); - if (n == 10001) { - print "1/0":; - return; - } - if (n == 10002) { - print "0/0":; - return; - } - print strerror(a):; + if (n == 10001) { + print "1/0":; + return; + } + if (n == 10002) { + print "0/0":; + return; + } + print strerror(a):; } @@ -273,11 +273,11 @@ print M; print; define octet_print(a) { - local b, x; - x = a; + local b, x; + x = a; - for (b = 128; b; b >>= 1) - print (x >= b ? (x -= b, 1) : 0):; + for (b = 128; b; b >>= 1) + print (x >= b ? (x -= b, 1) : 0):; } print "Here is the earlier block with a new octet_print()"; diff --git a/cal/zeta2.cal b/cal/zeta2.cal index 171f6ad..0974552 100644 --- a/cal/zeta2.cal +++ b/cal/zeta2.cal @@ -15,8 +15,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2013/08/11 01:31:28 - * File existed as early as: 2013 + * Under source code control: 2013/08/11 01:31:28 + * File existed as early as: 2013 */ @@ -72,7 +72,7 @@ define hurwitzzeta(s,a){ limit=(precision*ln(10)-re((s-.5)*result)+(1.*realpart_a)*ln(2.*pi()))/2; limit=max(2,ceil(max(limit,abs(s*1.)/2))); limit_function=ceil(sqrt((limit+realpart_a/2-.25)^2+(imagpart_s*1.)^2/4)/ - pi()); + pi()); if (config("user_debug") > 0) { print "limit_function = " limit_function; print "limit = " limit; diff --git a/calc.c b/calc.c index af33ea1..65d17d0 100644 --- a/calc.c +++ b/calc.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:11 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:11 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ #include @@ -40,7 +40,7 @@ * getopt.h file is from the Cygwin GNU library * * See: - * http://sources.redhat.com/cygwin/ + * http://sources.redhat.com/cygwin/ */ # include "../getopt/getopt.h" # endif @@ -83,13 +83,13 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* * S_FUNC definitions and functions */ -S_FUNC void intint(int arg); /* interrupt routine */ +S_FUNC void intint(int arg); /* interrupt routine */ S_FUNC void calc_interrupt(char *fmt, ...); S_FUNC int nextcp(char **cpp, int *ip, int argc, char **argv, bool haveendstr); S_FUNC void set_run_state(run state); @@ -100,689 +100,689 @@ S_FUNC void set_run_state(run state); int main(int argc, char **argv) { - int want_defhelp = 0; /* 1=> we only want the default help */ - int cmdlen; /* length of the command string */ - int newcmdlen; - int c; /* option */ - int index; - int maxindex; - char *cp; - char *endcp; - char *bp; - bool done = false; - bool havearg; - bool haveendstr; - bool stdin_closed = false; - size_t len; + int want_defhelp = 0; /* 1=> we only want the default help */ + int cmdlen; /* length of the command string */ + int newcmdlen; + int c; /* option */ + int index; + int maxindex; + char *cp; + char *endcp; + char *bp; + bool done = false; + bool havearg; + bool haveendstr; + bool stdin_closed = false; + size_t len; - /* - * parse args - */ - program = argv[0]; - script_name = strdup(argv[0]); - if (script_name == NULL) { - fprintf(stderr, "%s: failed to strdup(argv[0])\n", program); - exit(1); - } + /* + * parse args + */ + program = argv[0]; + script_name = strdup(argv[0]); + if (script_name == NULL) { + fprintf(stderr, "%s: failed to strdup(argv[0])\n", program); + exit(1); + } - cmdbuf[0] = '\0'; - cmdlen = 0; + cmdbuf[0] = '\0'; + cmdlen = 0; - /* process command line options */ + /* process command line options */ - index = 1; - cp = endcp = NULL; - maxindex = argc; - havecommands = false; - while (index < maxindex && !done) { - cp = argv[index]; - if (*cp == '\0') { - index++; - continue; - } - for (;;) { - havearg = false; - if (*cp != '-') { - done = true; - break; - } - ++cp; - if (*cp == '-') { - cp++; - while (*cp == ' ') - ++cp; - done = true; - break; - } + index = 1; + cp = endcp = NULL; + maxindex = argc; + havecommands = false; + while (index < maxindex && !done) { + cp = argv[index]; + if (*cp == '\0') { + index++; + continue; + } + for (;;) { + havearg = false; + if (*cp != '-') { + done = true; + break; + } + ++cp; + if (*cp == '-') { + cp++; + while (*cp == ' ') + ++cp; + done = true; + break; + } - for (;;) { - c = *cp; - if (c == '\0' || c == ' ') - break; - switch (c) { - case 'C': + for (;;) { + c = *cp; + if (c == '\0' || c == ' ') + break; + switch (c) { + case 'C': #if defined(CUSTOM) - /* - * error if libcustcalc was compiled with CUSTOM undefined - */ - if (custom_compiled() != true) { - math_error("%s: calc was built with custom functions enabled, " - "custom_compiled() returned: %d != %d", - program, custom_compiled(), true); - exit(1); - } + /* + * error if libcustcalc was compiled with CUSTOM undefined + */ + if (custom_compiled() != true) { + math_error("%s: calc was built with custom functions enabled, " + "custom_compiled() returned: %d != %d", + program, custom_compiled(), true); + exit(1); + } - /* - * indicate that custom functions are now allowed - */ - allow_custom = true; - break; + /* + * indicate that custom functions are now allowed + */ + allow_custom = true; + break; #else /* CUSTOM */ - /* - * error if libcustcalc was compiled with CUSTOM defined - */ - if (custom_compiled() != false) { - math_error("%s: calc was built with custom functions disabled, " - "custom_compiled() returned: %d != %d", - program, custom_compiled(), false); - } + /* + * error if libcustcalc was compiled with CUSTOM defined + */ + if (custom_compiled() != false) { + math_error("%s: calc was built with custom functions disabled, " + "custom_compiled() returned: %d != %d", + program, custom_compiled(), false); + } - /* - * we are too early in processing to - * call libcalc_call_me_last() - - * nothing to cleanup - */ - fprintf(stderr, - "%s: calc was built with custom" - " functions disabled, -C usage is" - " disallowed\n", program); - exit(1); + /* + * we are too early in processing to + * call libcalc_call_me_last() - + * nothing to cleanup + */ + fprintf(stderr, + "%s: calc was built with custom" + " functions disabled, -C usage is" + " disallowed\n", program); + exit(1); #endif /* CUSTOM */ - case 'e': - no_env = true; - break; - case 'h': - want_defhelp = 1; - break; - case 'i': - i_flag = true; - break; - case 'm': - cp++; - while (*cp == ' ' || *cp == '\t') - cp++; - if (*cp == '\0') { - index++; - if (index >= argc) { - fprintf(stderr, - "-m expects" - " argument"); - exit(2); - } - cp = argv[index]; - } + case 'e': + no_env = true; + break; + case 'h': + want_defhelp = 1; + break; + case 'i': + i_flag = true; + break; + case 'm': + cp++; + while (*cp == ' ' || *cp == '\t') + cp++; + if (*cp == '\0') { + index++; + if (index >= argc) { + fprintf(stderr, + "-m expects" + " argument"); + exit(2); + } + cp = argv[index]; + } - if (*cp < '0' || *cp > '7') { - /* - * we are too early in - * processing to call - * libcalc_call_me_last() - * nothing to cleanup - */ - fprintf(stderr, - "%s: unknown -m arg\n", - program); - exit(3); - } - allow_read = (((*cp-'0') & 04) > 0); - allow_write = (((*cp-'0') & 02) > 0); - allow_exec = (((*cp-'0') & 01) > 0); - cp++; - if (*cp != ' ' && *cp != '\0') { - fprintf(stderr, "??? m-arg"); - exit(4); - } - havearg = true; - break; - case 'n': - /* - * -n is deprecated and may be reused - * for another purpose in the future - */ - break; - case 'O': - use_old_std = true; - break; - case 'p': - p_flag = true; - break; - case 'q': - q_flag = true; - break; - case 'u': - u_flag = true; - break; - case 'c': - c_flag = true; - break; - case 'd': - d_flag = true; - break; - case 'v': - /* - * we are too early in processing to - * call libcalc_call_me_last() - - * nothing to cleanup - */ - fputs(CALC_TITLE, stdout); + if (*cp < '0' || *cp > '7') { + /* + * we are too early in + * processing to call + * libcalc_call_me_last() + * nothing to cleanup + */ + fprintf(stderr, + "%s: unknown -m arg\n", + program); + exit(3); + } + allow_read = (((*cp-'0') & 04) > 0); + allow_write = (((*cp-'0') & 02) > 0); + allow_exec = (((*cp-'0') & 01) > 0); + cp++; + if (*cp != ' ' && *cp != '\0') { + fprintf(stderr, "??? m-arg"); + exit(4); + } + havearg = true; + break; + case 'n': + /* + * -n is deprecated and may be reused + * for another purpose in the future + */ + break; + case 'O': + use_old_std = true; + break; + case 'p': + p_flag = true; + break; + case 'q': + q_flag = true; + break; + case 'u': + u_flag = true; + break; + case 'c': + c_flag = true; + break; + case 'd': + d_flag = true; + break; + case 'v': + /* + * we are too early in processing to + * call libcalc_call_me_last() - + * nothing to cleanup + */ + fputs(CALC_TITLE, stdout); #if defined(CUSTOM) - fputs(" w/custom functions", stdout); + fputs(" w/custom functions", stdout); #else - fputs(" w/o custom functions", stdout); + fputs(" w/o custom functions", stdout); #endif /* CUSTOM */ - printf(" (version %s)\n", version()); - exit(0); - case 'D': - /* - * parse the -D arg - * - * Could be: - * - * calc_debug - * calc_debug:resource_debug - * calc_debug:resource_debug:user_debug - */ - if (nextcp(&cp, &index, argc, argv, - false)) { - fprintf(stderr, - "-D expects argument\n"); - exit(5); - } - havearg = true; - if (*cp != ':') { - if (*cp < '0' || *cp > '9') { - fprintf(stderr, - "-D expects" - " integer\n"); - exit(6); - } - calc_debug = cp; - (void) strtol(cp, &endcp, 10); - cp = endcp; - if (*cp != '\0' && - *cp != ' ' && *cp != ':') { - fprintf(stderr, - "Bad syntax im -D" - " arg\n"); - exit(7); - } - if (*cp != ':') { - if (nextcp(&cp, &index, - argc, argv, - false) - || *cp != ':') - break; - } - } - if (nextcp(&cp, &index, argc, argv, - false)) { - fprintf(stderr, - "-D : expects" - " argument\n"); - exit(8); - } - if (*cp != ':') { - if (*cp < '0' || *cp > '9') { - fprintf(stderr, - "-D : expects" - " integer\n"); - exit(9); - } - resource_debug = cp; - (void) strtol(cp, &endcp, 10); - cp = endcp; - if (*cp != '\0' && - *cp != ' ' && *cp != ':') { - fprintf(stderr, - "Bad syntax im -D" - " : arg\n"); - exit(10); - } - if (*cp != ':') { - if (nextcp(&cp, &index, - argc, argv, - false) - || *cp != ':') { - break; - } - } - } - if (nextcp(&cp, &index, argc, argv, - false)) { - fprintf(stderr, "-D : : expects" - " argument\n"); - exit(11); - } - if (*cp < '0' || *cp > '9') { - fprintf(stderr, "-D :: expects" - " integer\n"); - exit(12); - } - user_debug = cp; - (void) strtol(cp, &endcp, 10); - cp = endcp; - if (*cp != '\0' && *cp != ' ') { - fprintf(stderr, "Bad syntax in" - " -D : : arg\n"); - exit(13); - } - break; - case 'f': - haveendstr = (cp[1] == '\0'); - if (nextcp(&cp, &index, argc, argv, - haveendstr)) { - fprintf(stderr, "-f expects" - " filename\n"); - exit(14); - } - if (*cp == ';') { - fprintf(stderr, - "-f expects" - " filename\n"); - exit(15); - } - havearg = true; - if (cmdlen > 0) - cmdbuf[cmdlen++] = ' '; - strlcpy(cmdbuf + cmdlen, "read ", - sizeof("read ")); - cmdlen += sizeof("read ")-1; - cmdbuf[cmdlen] = '\0'; - if (strncmp(cp, "-once", - sizeof("-once")) == 0 && - (cp[sizeof("-once")-1] == '\0' || - cp[sizeof("-once")-1] == ' ')) { - cp += sizeof("-once")-1; - haveendstr = (*cp == '\0'); - strlcpy(cmdbuf+cmdlen, "-once ", - sizeof("-once ")); - cmdlen += sizeof("-once ")-1; - cmdbuf[cmdlen] = '\0'; - if (nextcp(&cp, &index, argc, - argv, haveendstr)) { - fprintf(stderr, "-f -once" - " expects" - " filename\n"); - exit(16); - } - } - bp = cmdbuf + cmdlen; - /* - * duplicate -f filename arg - * as a new script_name value - */ - if (script_name != NULL) { - free(script_name); - } - script_name = NULL; - script_name = strdup(cp); - if (script_name == NULL) { - fprintf(stderr, - "strdup(-f argument)" - "failed\n"); - exit(17); - } - /* process -f filename arg */ - if (haveendstr) { - len = strlen(cp); - if (len == 0) { - fprintf(stderr, - "Null" - " filename!\n"); - exit(18); - } - if (cmdlen + len + 2 > MAXCMD) { - fprintf(stderr, - "Commands too" - " long\n"); - exit(19); - } - /* XXX - what if *cp = '\''? */ - *bp++ = '\''; - strlcpy(bp, cp, len+1); - bp += len; - *bp++ = '\''; - cp += len; - cmdlen += len + 2; - } else { - do { - if (cmdlen > MAXCMD) { - fprintf(stderr, - "Commands" - " too long\n"); - exit(20); - } - *bp++ = *cp++; - cmdlen++; - } while (*cp != '\0' && - *cp != ';' && - *cp != ' '); - } - if (*cp == ';') - cp++; - *bp++ = ';'; - *bp = '\0'; - cmdlen++; + printf(" (version %s)\n", version()); + exit(0); + case 'D': + /* + * parse the -D arg + * + * Could be: + * + * calc_debug + * calc_debug:resource_debug + * calc_debug:resource_debug:user_debug + */ + if (nextcp(&cp, &index, argc, argv, + false)) { + fprintf(stderr, + "-D expects argument\n"); + exit(5); + } + havearg = true; + if (*cp != ':') { + if (*cp < '0' || *cp > '9') { + fprintf(stderr, + "-D expects" + " integer\n"); + exit(6); + } + calc_debug = cp; + (void) strtol(cp, &endcp, 10); + cp = endcp; + if (*cp != '\0' && + *cp != ' ' && *cp != ':') { + fprintf(stderr, + "Bad syntax im -D" + " arg\n"); + exit(7); + } + if (*cp != ':') { + if (nextcp(&cp, &index, + argc, argv, + false) + || *cp != ':') + break; + } + } + if (nextcp(&cp, &index, argc, argv, + false)) { + fprintf(stderr, + "-D : expects" + " argument\n"); + exit(8); + } + if (*cp != ':') { + if (*cp < '0' || *cp > '9') { + fprintf(stderr, + "-D : expects" + " integer\n"); + exit(9); + } + resource_debug = cp; + (void) strtol(cp, &endcp, 10); + cp = endcp; + if (*cp != '\0' && + *cp != ' ' && *cp != ':') { + fprintf(stderr, + "Bad syntax im -D" + " : arg\n"); + exit(10); + } + if (*cp != ':') { + if (nextcp(&cp, &index, + argc, argv, + false) + || *cp != ':') { + break; + } + } + } + if (nextcp(&cp, &index, argc, argv, + false)) { + fprintf(stderr, "-D : : expects" + " argument\n"); + exit(11); + } + if (*cp < '0' || *cp > '9') { + fprintf(stderr, "-D :: expects" + " integer\n"); + exit(12); + } + user_debug = cp; + (void) strtol(cp, &endcp, 10); + cp = endcp; + if (*cp != '\0' && *cp != ' ') { + fprintf(stderr, "Bad syntax in" + " -D : : arg\n"); + exit(13); + } + break; + case 'f': + haveendstr = (cp[1] == '\0'); + if (nextcp(&cp, &index, argc, argv, + haveendstr)) { + fprintf(stderr, "-f expects" + " filename\n"); + exit(14); + } + if (*cp == ';') { + fprintf(stderr, + "-f expects" + " filename\n"); + exit(15); + } + havearg = true; + if (cmdlen > 0) + cmdbuf[cmdlen++] = ' '; + strlcpy(cmdbuf + cmdlen, "read ", + sizeof("read ")); + cmdlen += sizeof("read ")-1; + cmdbuf[cmdlen] = '\0'; + if (strncmp(cp, "-once", + sizeof("-once")) == 0 && + (cp[sizeof("-once")-1] == '\0' || + cp[sizeof("-once")-1] == ' ')) { + cp += sizeof("-once")-1; + haveendstr = (*cp == '\0'); + strlcpy(cmdbuf+cmdlen, "-once ", + sizeof("-once ")); + cmdlen += sizeof("-once ")-1; + cmdbuf[cmdlen] = '\0'; + if (nextcp(&cp, &index, argc, + argv, haveendstr)) { + fprintf(stderr, "-f -once" + " expects" + " filename\n"); + exit(16); + } + } + bp = cmdbuf + cmdlen; + /* + * duplicate -f filename arg + * as a new script_name value + */ + if (script_name != NULL) { + free(script_name); + } + script_name = NULL; + script_name = strdup(cp); + if (script_name == NULL) { + fprintf(stderr, + "strdup(-f argument)" + "failed\n"); + exit(17); + } + /* process -f filename arg */ + if (haveendstr) { + len = strlen(cp); + if (len == 0) { + fprintf(stderr, + "Null" + " filename!\n"); + exit(18); + } + if (cmdlen + len + 2 > MAXCMD) { + fprintf(stderr, + "Commands too" + " long\n"); + exit(19); + } + /* XXX - what if *cp = '\''? */ + *bp++ = '\''; + strlcpy(bp, cp, len+1); + bp += len; + *bp++ = '\''; + cp += len; + cmdlen += len + 2; + } else { + do { + if (cmdlen > MAXCMD) { + fprintf(stderr, + "Commands" + " too long\n"); + exit(20); + } + *bp++ = *cp++; + cmdlen++; + } while (*cp != '\0' && + *cp != ';' && + *cp != ' '); + } + if (*cp == ';') + cp++; + *bp++ = ';'; + *bp = '\0'; + cmdlen++; - /* -f implies -s */ - s_flag = true; - maxindex = index + 1; - break; + /* -f implies -s */ + s_flag = true; + maxindex = index + 1; + break; - case 's': - s_flag = true; - maxindex = index + 1; - break; - default: - /* - * we are too early in processing to - * call libcalc_call_me_last() - - * nothing to cleanup - */ - fprintf(stderr, "Illegal option -%c\n", - c); - fprintf(stderr, - "usage: %s [-c] [-C] [-d] [-e] [-h] [-i] [-m mode]\n" - "\t[-D calc_debug[:resource_debug[:user_debug]]]\n" - "\t[-O] [-p] [-q] [-s] [-u] [-v] " - "[--] [calc_cmd ...]\n" - "usage: %s ... -f filename\n" - "1st cscript line: #/path/to/calc ... -s -f\n", - program, program); - exit(21); - } - if (havearg) - break; - cp++; - } - while (*cp == ' ') - cp++; - if (*cp == '\0') { - index++; - break; - } - } - } + case 's': + s_flag = true; + maxindex = index + 1; + break; + default: + /* + * we are too early in processing to + * call libcalc_call_me_last() - + * nothing to cleanup + */ + fprintf(stderr, "Illegal option -%c\n", + c); + fprintf(stderr, + "usage: %s [-c] [-C] [-d] [-e] [-h] [-i] [-m mode]\n" + "\t[-D calc_debug[:resource_debug[:user_debug]]]\n" + "\t[-O] [-p] [-q] [-s] [-u] [-v] " + "[--] [calc_cmd ...]\n" + "usage: %s ... -f filename\n" + "1st cscript line: #/path/to/calc ... -s -f\n", + program, program); + exit(21); + } + if (havearg) + break; + cp++; + } + while (*cp == ' ') + cp++; + if (*cp == '\0') { + index++; + break; + } + } + } - while (index < maxindex) { - size_t cplen; + while (index < maxindex) { + size_t cplen; - if (cmdlen > 0) - cmdbuf[cmdlen++] = ' '; - cplen = strlen(cp); - newcmdlen = cmdlen + cplen; - if (newcmdlen > MAXCMD) { - fprintf(stderr, - "%s: commands too long\n", - program); - exit(22); - } - strlcpy(cmdbuf + cmdlen, cp, cplen+1); - cmdbuf[newcmdlen] = '\0'; - cmdlen = newcmdlen; - index++; - if (index < maxindex) - cp = argv[index]; - } + if (cmdlen > 0) + cmdbuf[cmdlen++] = ' '; + cplen = strlen(cp); + newcmdlen = cmdlen + cplen; + if (newcmdlen > MAXCMD) { + fprintf(stderr, + "%s: commands too long\n", + program); + exit(22); + } + strlcpy(cmdbuf + cmdlen, cp, cplen+1); + cmdbuf[newcmdlen] = '\0'; + cmdlen = newcmdlen; + index++; + if (index < maxindex) + cp = argv[index]; + } - havecommands = (cmdlen > 0); + havecommands = (cmdlen > 0); - if (havecommands) { - cmdbuf[cmdlen++] = '\n'; - cmdbuf[cmdlen] = '\0'; - if (p_flag != true) { - if (freopen("/dev/null", "r", stdin) == NULL) { - perror("in main: freopen(\"/dev/null\", \"r\", stdin) failed:"); - } - stdin_closed = true; - } - } + if (havecommands) { + cmdbuf[cmdlen++] = '\n'; + cmdbuf[cmdlen] = '\0'; + if (p_flag != true) { + if (freopen("/dev/null", "r", stdin) == NULL) { + perror("in main: freopen(\"/dev/null\", \"r\", stdin) failed:"); + } + stdin_closed = true; + } + } - argc_value = argc - maxindex + 1; - argv_value = argv + maxindex; + argc_value = argc - maxindex + 1; + argv_value = argv + maxindex; - /* - * unbuffered mode - */ - if (u_flag) { - if (stdin_closed == false) { - setbuf(stdin, NULL); - } - setbuf(stdout, NULL); - } + /* + * unbuffered mode + */ + if (u_flag) { + if (stdin_closed == false) { + setbuf(stdin, NULL); + } + setbuf(stdout, NULL); + } - /* - * initialize - */ - libcalc_call_me_first(); - if (u_flag) { - if (conf->calc_debug & CALCDBG_TTY) { - if (stdin_closed == false) { - printf("main: stdin set to unbuffered before " - "calling libcalc_call_me_first()\n"); - } else { - printf("main: stdin closed before " - "calling libcalc_call_me_first()\n"); - } - } - } - stdin_tty = isatty(0); /* assume stdin is on fd 0 */ - if (conf->calc_debug & CALCDBG_TTY) - printf("main: stdin_tty is %d\n", stdin_tty); - if (want_defhelp) { - givehelp(DEFAULTCALCHELP); - libcalc_call_me_last(); - exit(0); - } + /* + * initialize + */ + libcalc_call_me_first(); + if (u_flag) { + if (conf->calc_debug & CALCDBG_TTY) { + if (stdin_closed == false) { + printf("main: stdin set to unbuffered before " + "calling libcalc_call_me_first()\n"); + } else { + printf("main: stdin closed before " + "calling libcalc_call_me_first()\n"); + } + } + } + stdin_tty = isatty(0); /* assume stdin is on fd 0 */ + if (conf->calc_debug & CALCDBG_TTY) + printf("main: stdin_tty is %d\n", stdin_tty); + if (want_defhelp) { + givehelp(DEFAULTCALCHELP); + libcalc_call_me_last(); + exit(0); + } - /* - * if allowed or needed, print version and setup bindings - */ - if (!havecommands && stdin_tty) { - if (!d_flag) { - printf("%s (version %s)\n", CALC_TITLE, version()); - printf("Calc is open software. For license details " - "type: help copyright\n"); - printf("[%s]\n\n", - "Type \"exit\" to exit, or \"help\" for help."); - } - switch (hist_init(calcbindings)) { - case HIST_NOFILE: - fprintf(stderr, - "%s: Cannot open bindings file \"%s\", " - "fancy editing disabled.\n", - program, calcbindings); - break; + /* + * if allowed or needed, print version and setup bindings + */ + if (!havecommands && stdin_tty) { + if (!d_flag) { + printf("%s (version %s)\n", CALC_TITLE, version()); + printf("Calc is open software. For license details " + "type: help copyright\n"); + printf("[%s]\n\n", + "Type \"exit\" to exit, or \"help\" for help."); + } + switch (hist_init(calcbindings)) { + case HIST_NOFILE: + fprintf(stderr, + "%s: Cannot open bindings file \"%s\", " + "fancy editing disabled.\n", + program, calcbindings); + break; - case HIST_NOTTY: - fprintf(stderr, - "%s: Cannot set terminal modes, " - "fancy editing disabled\n", program); - break; - } - } + case HIST_NOTTY: + fprintf(stderr, + "%s: Cannot set terminal modes, " + "fancy editing disabled\n", program); + break; + } + } - /* - * establish error longjump point with initial conditions - */ - if (setjmp(calc_scanerr_jmpbuf) == 0) { + /* + * establish error longjump point with initial conditions + */ + if (setjmp(calc_scanerr_jmpbuf) == 0) { - /* - * reset/initialize the computing environment - */ - initialize(); - calc_use_scanerr_jmpbuf = 1; - } + /* + * reset/initialize the computing environment + */ + initialize(); + calc_use_scanerr_jmpbuf = 1; + } - /* - * (re)establish the interrupt handler - */ - (void) signal(SIGINT, intint); + /* + * (re)establish the interrupt handler + */ + (void) signal(SIGINT, intint); - /* - * execute calc code based on the run state - */ - if (run_state == RUN_BEGIN) { - if (!q_flag && allow_read) { - set_run_state(RUN_RCFILES); - runrcfiles(); - } - set_run_state(RUN_PRE_CMD_ARGS); - } + /* + * execute calc code based on the run state + */ + if (run_state == RUN_BEGIN) { + if (!q_flag && allow_read) { + set_run_state(RUN_RCFILES); + runrcfiles(); + } + set_run_state(RUN_PRE_CMD_ARGS); + } - while (run_state == RUN_RCFILES) { - fprintf(stderr, "Error in rcfiles\n"); - if ((c_flag && !stoponerror) || stoponerror < 0) { - getcommands(false); - if (inputlevel() == 0) { - closeinput(); - runrcfiles(); - set_run_state(RUN_PRE_CMD_ARGS); - } else { - closeinput(); - } - } else { - if ((havecommands && !i_flag) || !stdin_tty) { - set_run_state(RUN_EXIT_WITH_ERROR); - } else { - set_run_state(RUN_PRE_CMD_ARGS); - } - } - } + while (run_state == RUN_RCFILES) { + fprintf(stderr, "Error in rcfiles\n"); + if ((c_flag && !stoponerror) || stoponerror < 0) { + getcommands(false); + if (inputlevel() == 0) { + closeinput(); + runrcfiles(); + set_run_state(RUN_PRE_CMD_ARGS); + } else { + closeinput(); + } + } else { + if ((havecommands && !i_flag) || !stdin_tty) { + set_run_state(RUN_EXIT_WITH_ERROR); + } else { + set_run_state(RUN_PRE_CMD_ARGS); + } + } + } - if (run_state == RUN_PRE_CMD_ARGS) { - if (havecommands) { - set_run_state(RUN_CMD_ARGS); - (void) openstring(cmdbuf, strlen(cmdbuf)); - getcommands(false); - closeinput(); - } - set_run_state(RUN_PRE_TOP_LEVEL); - } + if (run_state == RUN_PRE_CMD_ARGS) { + if (havecommands) { + set_run_state(RUN_CMD_ARGS); + (void) openstring(cmdbuf, strlen(cmdbuf)); + getcommands(false); + closeinput(); + } + set_run_state(RUN_PRE_TOP_LEVEL); + } - while (run_state == RUN_CMD_ARGS) { - fprintf(stderr, "Error in commands\n"); - if ((c_flag && !stoponerror) || stoponerror < 0) { - getcommands(false); - if (inputlevel() == 0) - set_run_state(RUN_PRE_TOP_LEVEL); - closeinput(); - } else { - closeinput(); - if (!stdin_tty || !i_flag || p_flag) { - set_run_state(RUN_EXIT_WITH_ERROR); - } else { - set_run_state(RUN_PRE_TOP_LEVEL); - } - } - } + while (run_state == RUN_CMD_ARGS) { + fprintf(stderr, "Error in commands\n"); + if ((c_flag && !stoponerror) || stoponerror < 0) { + getcommands(false); + if (inputlevel() == 0) + set_run_state(RUN_PRE_TOP_LEVEL); + closeinput(); + } else { + closeinput(); + if (!stdin_tty || !i_flag || p_flag) { + set_run_state(RUN_EXIT_WITH_ERROR); + } else { + set_run_state(RUN_PRE_TOP_LEVEL); + } + } + } - if (run_state == RUN_PRE_TOP_LEVEL) { - if (stdin_tty && - (((havecommands) && !i_flag) || p_flag)) { - set_run_state(RUN_EXIT); - } else { - if (stdin_tty) { - reinitialize(); - } else { - resetinput(); - openterminal(); - } - set_run_state(RUN_TOP_LEVEL); - getcommands(true); - } - if (p_flag || (!i_flag && havecommands)) - set_run_state(RUN_EXIT); - } + if (run_state == RUN_PRE_TOP_LEVEL) { + if (stdin_tty && + (((havecommands) && !i_flag) || p_flag)) { + set_run_state(RUN_EXIT); + } else { + if (stdin_tty) { + reinitialize(); + } else { + resetinput(); + openterminal(); + } + set_run_state(RUN_TOP_LEVEL); + getcommands(true); + } + if (p_flag || (!i_flag && havecommands)) + set_run_state(RUN_EXIT); + } - while (run_state == RUN_TOP_LEVEL) { - if (conf->calc_debug & CALCDBG_RUNSTATE) - printf("main: run_state = TOP_LEVEL\n"); - if ((c_flag && !stoponerror) || stoponerror < 0) { - getcommands(true); - if (!inputisterminal()) { - closeinput(); - continue; - } - if (!p_flag && i_flag && !stdin_tty) { - closeinput(); - if(!freopen("/dev/tty", "r", stdin)) { + while (run_state == RUN_TOP_LEVEL) { + if (conf->calc_debug & CALCDBG_RUNSTATE) + printf("main: run_state = TOP_LEVEL\n"); + if ((c_flag && !stoponerror) || stoponerror < 0) { + getcommands(true); + if (!inputisterminal()) { + closeinput(); + continue; + } + if (!p_flag && i_flag && !stdin_tty) { + closeinput(); + if(!freopen("/dev/tty", "r", stdin)) { #if defined(_WIN32) || defined(_WIN64) - fprintf(stderr, - "/dev/tty does not exist on " - "this operating system. " - "Change operating systems\n" - "or don't use this calc mode " - "in the future, sorry!\n"); + fprintf(stderr, + "/dev/tty does not exist on " + "this operating system. " + "Change operating systems\n" + "or don't use this calc mode " + "in the future, sorry!\n"); #else /* Windows free systems */ - fprintf(stderr, - "Unable to associate stdin" - " with /dev/tty"); + fprintf(stderr, + "Unable to associate stdin" + " with /dev/tty"); #endif /* Windows free systems */ - set_run_state(RUN_EXIT_WITH_ERROR); - break; - } + set_run_state(RUN_EXIT_WITH_ERROR); + break; + } - stdin_tty = true; - if (conf->calc_debug & CALCDBG_TTY) - printf("main: stdin_tty is %d\n", - stdin_tty); - reinitialize(); - } - } else { - if (stdin_tty) { - reinitialize(); - getcommands(true); - } else if (inputisterminal() && - !p_flag && (!havecommands||i_flag)) { - closeinput(); - if(!freopen("/dev/tty", "r", stdin)) { + stdin_tty = true; + if (conf->calc_debug & CALCDBG_TTY) + printf("main: stdin_tty is %d\n", + stdin_tty); + reinitialize(); + } + } else { + if (stdin_tty) { + reinitialize(); + getcommands(true); + } else if (inputisterminal() && + !p_flag && (!havecommands||i_flag)) { + closeinput(); + if(!freopen("/dev/tty", "r", stdin)) { #if defined(_WIN32) || defined(_WIN64) - fprintf(stderr, - "/dev/tty does not exist on " - "this operating system. " - "Change operating systems\n" - "or don't use this calc mode " - "in the future, sorry!\n"); + fprintf(stderr, + "/dev/tty does not exist on " + "this operating system. " + "Change operating systems\n" + "or don't use this calc mode " + "in the future, sorry!\n"); #else /* Windows free systems */ - fprintf(stderr, - "Unable to associate stdin" - " with /dev/tty"); + fprintf(stderr, + "Unable to associate stdin" + " with /dev/tty"); #endif /* Windows free systems */ - set_run_state(RUN_EXIT_WITH_ERROR); - break; - } - stdin_tty = true; - if (conf->calc_debug & CALCDBG_TTY) - printf("main: stdin_tty is %d\n", - stdin_tty); - reinitialize(); - } else { - set_run_state(RUN_EXIT_WITH_ERROR); - } - } - } - if (conf->calc_debug & CALCDBG_RUNSTATE) - printf("main: run_state = %s\n", run_state_name(run_state)); + set_run_state(RUN_EXIT_WITH_ERROR); + break; + } + stdin_tty = true; + if (conf->calc_debug & CALCDBG_TTY) + printf("main: stdin_tty is %d\n", + stdin_tty); + reinitialize(); + } else { + set_run_state(RUN_EXIT_WITH_ERROR); + } + } + } + if (conf->calc_debug & CALCDBG_RUNSTATE) + printf("main: run_state = %s\n", run_state_name(run_state)); - /* - * All done! - Jessica Noll, Age 2 - */ - libcalc_call_me_last(); - return (run_state == RUN_EXIT_WITH_ERROR || - run_state == RUN_ZERO) ? 1 : 0; + /* + * All done! - Jessica Noll, Age 2 + */ + libcalc_call_me_last(); + return (run_state == RUN_EXIT_WITH_ERROR || + run_state == RUN_ZERO) ? 1 : 0; } @@ -790,20 +790,20 @@ main(int argc, char **argv) * Interrupt routine. * * given: - * arg to keep ANSI C happy + * arg to keep ANSI C happy */ /*ARGSUSED*/ S_FUNC void intint(int UNUSED(arg)) { - (void) signal(SIGINT, intint); - if (inputwait || (++abortlevel >= ABORT_NOW)) { - calc_interrupt("\nABORT"); - not_reached(); - } - if (abortlevel >= ABORT_MATH) - _math_abort_ = true; - printf("\n[Abort level %d]\n", abortlevel); + (void) signal(SIGINT, intint); + if (inputwait || (++abortlevel >= ABORT_NOW)) { + calc_interrupt("\nABORT"); + not_reached(); + } + if (abortlevel >= ABORT_MATH) + _math_abort_ = true; + printf("\n[Abort level %d]\n", abortlevel); } @@ -813,78 +813,78 @@ intint(int UNUSED(arg)) static void calc_interrupt(char *fmt, ...) { - va_list ap; + va_list ap; - if (funcname && (*funcname != '*')) - fprintf(stderr, "\"%s\": ", funcname); - if (funcline && ((funcname && (*funcname != '*')) || - !inputisterminal())) - fprintf(stderr, "line %ld: ", funcline); - va_start(ap, fmt); - vsnprintf(calc_err_msg, MAXERROR, fmt, ap); - va_end(ap); - calc_err_msg[MAXERROR] = '\0'; /* paranoia */ - fprintf(stderr, "%s\n\n", calc_err_msg); - funcname = NULL; - if (calc_use_scanerr_jmpbuf != 0) { - longjmp(calc_scanerr_jmpbuf, 22); - } else { - fprintf(stderr, "It is too early provide a command line prompt " - "so we must simply exit. Sorry!\n"); - /* - * don't call libcalc_call_me_last() -- we might loop - * and besides ... this is an unusual internal error case - */ - exit(24); - } + if (funcname && (*funcname != '*')) + fprintf(stderr, "\"%s\": ", funcname); + if (funcline && ((funcname && (*funcname != '*')) || + !inputisterminal())) + fprintf(stderr, "line %ld: ", funcline); + va_start(ap, fmt); + vsnprintf(calc_err_msg, MAXERROR, fmt, ap); + va_end(ap); + calc_err_msg[MAXERROR] = '\0'; /* paranoia */ + fprintf(stderr, "%s\n\n", calc_err_msg); + funcname = NULL; + if (calc_use_scanerr_jmpbuf != 0) { + longjmp(calc_scanerr_jmpbuf, 22); + } else { + fprintf(stderr, "It is too early provide a command line prompt " + "so we must simply exit. Sorry!\n"); + /* + * don't call libcalc_call_me_last() -- we might loop + * and besides ... this is an unusual internal error case + */ + exit(24); + } } S_FUNC int nextcp(char **cpp, int *ip, int argc, char **argv, bool haveendstr) { - char *cp; - int index; + char *cp; + int index; - cp = *cpp; - index = *ip; + cp = *cpp; + index = *ip; - if (haveendstr) { - index++; - *ip = index; - if (index >= argc) - return 1; - *cpp = argv[index]; - return 0; - } + if (haveendstr) { + index++; + *ip = index; + if (index >= argc) + return 1; + *cpp = argv[index]; + return 0; + } - if (*cp != '\0') - cp++; - for (;;) { - if (*cp == '\0') { - index++; - *ip = index; - if (index >= argc) - return 1; - cp = argv[index]; - } - while (*cp == ' ') - cp++; - if (*cp != '\0') - break; - } - *cpp = cp; - return 0; + if (*cp != '\0') + cp++; + for (;;) { + if (*cp == '\0') { + index++; + *ip = index; + if (index >= argc) + return 1; + cp = argv[index]; + } + while (*cp == ' ') + cp++; + if (*cp != '\0') + break; + } + *cpp = cp; + return 0; } S_FUNC void set_run_state(run state) { - if (conf->calc_debug & CALCDBG_RUNSTATE) - printf("main: run_state from %s to %s\n", - run_state_name(run_state), - run_state_name(state)); - run_state = state; + if (conf->calc_debug & CALCDBG_RUNSTATE) + printf("main: run_state from %s to %s\n", + run_state_name(run_state), + run_state_name(state)); + run_state = state; } diff --git a/calc.h b/calc.h index 1ba2241..ad788eb 100644 --- a/calc.h +++ b/calc.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:31 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:31 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,7 +28,7 @@ #define INCLUDE_CALC_H #include -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "decl.h" # include "value.h" # include "have_const.h" @@ -42,61 +42,61 @@ /* * Configuration definitions */ -#define CALCPATH "CALCPATH" /* environment variable for files */ -#define CALCRC "CALCRC" /* environment variable for startup */ -#define CALCBINDINGS "CALCBINDINGS" /* env variable for hist bindings */ -#define HOME "HOME" /* environment variable for home dir */ -#define PAGER "PAGER" /* environment variable for help */ -#define SHELL "SHELL" /* environment variable for shell */ -#define CALCHISTFILE "CALCHISTFILE" /* history file environment variable */ -#define CALCHELP "CALCHELP" /* help directory env variable */ -#define CALCCUSTOMHELP "CALCCUSTOMHELP"/* custom help directory env variable */ -#define DEFAULTCALCBINDINGS "bindings" /* default calc bindings file */ -#define DEFAULTCALCHELP "help" /* help file that -h prints */ -#define DEFAULTSHELL "sh" /* default shell to use */ -#define CALCEXT ".cal" /* extension for files read in */ -#define MAX_CALCRC 1024 /* maximum length of $CALCRC */ -#define HOMECHAR '~' /* char which indicates home directory */ -#define DOTCHAR '.' /* char which indicates current directory */ -#define PATHCHAR '/' /* char which separates path components */ +#define CALCPATH "CALCPATH" /* environment variable for files */ +#define CALCRC "CALCRC" /* environment variable for startup */ +#define CALCBINDINGS "CALCBINDINGS" /* env variable for hist bindings */ +#define HOME "HOME" /* environment variable for home dir */ +#define PAGER "PAGER" /* environment variable for help */ +#define SHELL "SHELL" /* environment variable for shell */ +#define CALCHISTFILE "CALCHISTFILE" /* history file environment variable */ +#define CALCHELP "CALCHELP" /* help directory env variable */ +#define CALCCUSTOMHELP "CALCCUSTOMHELP"/* custom help directory env variable */ +#define DEFAULTCALCBINDINGS "bindings" /* default calc bindings file */ +#define DEFAULTCALCHELP "help" /* help file that -h prints */ +#define DEFAULTSHELL "sh" /* default shell to use */ +#define CALCEXT ".cal" /* extension for files read in */ +#define MAX_CALCRC 1024 /* maximum length of $CALCRC */ +#define HOMECHAR '~' /* char which indicates home directory */ +#define DOTCHAR '.' /* char which indicates current directory */ +#define PATHCHAR '/' /* char which separates path components */ #if defined(_WIN32) || defined(_WIN64) -#define LISTCHAR ';' /* char which separates paths in a list */ +#define LISTCHAR ';' /* char which separates paths in a list */ #else -#define LISTCHAR ':' /* char which separates paths in a list */ +#define LISTCHAR ':' /* char which separates paths in a list */ #endif -#define MAXCMD 16384 /* maximum length of command invocation */ +#define MAXCMD 16384 /* maximum length of command invocation */ -#define SYMBOLSIZE 256 /* maximum symbol name size */ -#define MAXLABELS 100 /* maximum number of user labels in function */ -#define MAXSTACK 2048 /* maximum depth of evaluation stack */ -#define MAXFILES 20 /* maximum number of opened files */ -#define PROMPT1 "> " /* default normal prompt*/ -#define PROMPT2 ">> " /* default prompt inside multi-line input */ +#define SYMBOLSIZE 256 /* maximum symbol name size */ +#define MAXLABELS 100 /* maximum number of user labels in function */ +#define MAXSTACK 2048 /* maximum depth of evaluation stack */ +#define MAXFILES 20 /* maximum number of opened files */ +#define PROMPT1 "> " /* default normal prompt*/ +#define PROMPT2 ">> " /* default prompt inside multi-line input */ -#define TRACE_NORMAL 0x00 /* normal trace flags */ -#define TRACE_OPCODES 0x01 /* trace every opcode */ -#define TRACE_NODEBUG 0x02 /* suppress debugging opcodes */ -#define TRACE_LINKS 0x04 /* display links for real and complex numbers */ -#define TRACE_FNCODES 0x08 /* display code for newly defined function */ -#define TRACE_MAX 0x0f /* maximum value for trace flag */ +#define TRACE_NORMAL 0x00 /* normal trace flags */ +#define TRACE_OPCODES 0x01 /* trace every opcode */ +#define TRACE_NODEBUG 0x02 /* suppress debugging opcodes */ +#define TRACE_LINKS 0x04 /* display links for real and complex numbers */ +#define TRACE_FNCODES 0x08 /* display code for newly defined function */ +#define TRACE_MAX 0x0f /* maximum value for trace flag */ -#define ABORT_NONE 0 /* abort not needed yet */ -#define ABORT_STATEMENT 1 /* abort on statement boundary */ -#define ABORT_OPCODE 2 /* abort on any opcode boundary */ -#define ABORT_MATH 3 /* abort on any math operation */ -#define ABORT_NOW 4 /* abort right away */ +#define ABORT_NONE 0 /* abort not needed yet */ +#define ABORT_STATEMENT 1 /* abort on statement boundary */ +#define ABORT_OPCODE 2 /* abort on any opcode boundary */ +#define ABORT_MATH 3 /* abort on any math operation */ +#define ABORT_NOW 4 /* abort right away */ -#define ERRMAX 20 /* default errmax value */ -#define E_OK 0 /* no error */ +#define ERRMAX 20 /* default errmax value */ +#define E_OK 0 /* no error */ /* * File ids corresponding to standard in, out, error, and when not in use. */ -#define FILEID_STDIN ((FILEID) 0) -#define FILEID_STDOUT ((FILEID) 1) -#define FILEID_STDERR ((FILEID) 2) -#define FILEID_NONE ((FILEID) -1) /* must be < 0 */ +#define FILEID_STDIN ((FILEID) 0) +#define FILEID_STDOUT ((FILEID) 1) +#define FILEID_STDERR ((FILEID) 2) +#define FILEID_NONE ((FILEID) -1) /* must be < 0 */ /* * File I/O routines. @@ -139,7 +139,7 @@ E_FUNC int fseekid(FILEID id, ZVALUE offset, int whence); E_FUNC int isattyid(FILEID id); E_FUNC int fsearch(FILEID id, char *str, ZVALUE start, ZVALUE end, ZVALUE *res); E_FUNC int frsearch(FILEID id, char *str, ZVALUE first, ZVALUE last, - ZVALUE *res); + ZVALUE *res); E_FUNC void showconstants(void); E_FUNC void freeconstant(unsigned long); E_FUNC void freestringconstant(long); @@ -151,7 +151,7 @@ E_FUNC void trimconstants(void); E_FUNC int openstring(char *str, size_t num); E_FUNC int openterminal(void); E_FUNC int opensearchfile(char *name, char *pathlist, char *exten, - int reopen_ok); + int reopen_ok); E_FUNC char *nextline(void); E_FUNC int nextchar(void); E_FUNC void reread(void); @@ -187,70 +187,70 @@ E_FUNC char *calc_strdup(CONST char *); E_FUNC void initialize(void); E_FUNC void reinitialize(void); #if !defined(_WIN32) && !defined(_WIN64) -E_FUNC int isatty(int tty); /* true if fd is a tty */ +E_FUNC int isatty(int tty); /* true if fd is a tty */ #endif -E_FUNC char *version(void); /* return version string */ +E_FUNC char *version(void); /* return version string */ /* * global flags and definitions */ -EXTERN int abortlevel; /* current level of aborts */ -EXTERN bool inputwait; /* true if in a terminal input wait */ +EXTERN int abortlevel; /* current level of aborts */ +EXTERN bool inputwait; /* true if in a terminal input wait */ -EXTERN int p_flag; /* true => pipe mode */ -EXTERN int q_flag; /* true => don't execute rc files */ -EXTERN int u_flag; /* true => unbuffer stdin and stdout */ -EXTERN int d_flag; /* true => disable heading, resource_debug */ -EXTERN int c_flag; /* true => continue after error if permitted */ -EXTERN int i_flag; /* true => try to go interactive after error */ -E_FUNC int s_flag; /* true => keep args as strings for argv() */ -EXTERN long stoponerror; /* >0 => stop, <0 => continue, ==0 => use -c */ -EXTERN bool abort_now; /* true => try to go interactive */ +EXTERN int p_flag; /* true => pipe mode */ +EXTERN int q_flag; /* true => don't execute rc files */ +EXTERN int u_flag; /* true => unbuffer stdin and stdout */ +EXTERN int d_flag; /* true => disable heading, resource_debug */ +EXTERN int c_flag; /* true => continue after error if permitted */ +EXTERN int i_flag; /* true => try to go interactive after error */ +E_FUNC int s_flag; /* true => keep args as strings for argv() */ +EXTERN long stoponerror; /* >0 => stop, <0 => continue, ==0 => use -c */ +EXTERN bool abort_now; /* true => try to go interactive */ -E_FUNC int argc_value; /* count of argv[] strings for argv() builtin */ -E_FUNC char **argv_value; /* argv[] strings for argv() builtin */ +E_FUNC int argc_value; /* count of argv[] strings for argv() builtin */ +E_FUNC char **argv_value; /* argv[] strings for argv() builtin */ -EXTERN char *pager; /* $PAGER or default */ -EXTERN int stdin_tty; /* true if stdin is a tty */ -EXTERN int havecommands; /* true if have cmd args) */ -EXTERN char *program; /* our name */ -EXTERN char *base_name; /* basename of our name */ -EXTERN char cmdbuf[]; /* command line expression */ -EXTERN char *script_name; /* program name or -f filename arg or NULL */ +EXTERN char *pager; /* $PAGER or default */ +EXTERN int stdin_tty; /* true if stdin is a tty */ +EXTERN int havecommands; /* true if have cmd args) */ +EXTERN char *program; /* our name */ +EXTERN char *base_name; /* basename of our name */ +EXTERN char cmdbuf[]; /* command line expression */ +EXTERN char *script_name; /* program name or -f filename arg or NULL */ -EXTERN int abortlevel; /* current level of aborts */ -EXTERN bool inputwait; /* true if in a terminal input wait */ -EXTERN VALUE *stack; /* execution stack */ -EXTERN int dumpnames; /* true => dump names rather than indices */ -EXTERN int calc_errno; /* global calc_errno value */ +EXTERN int abortlevel; /* current level of aborts */ +EXTERN bool inputwait; /* true if in a terminal input wait */ +EXTERN VALUE *stack; /* execution stack */ +EXTERN int dumpnames; /* true => dump names rather than indices */ +EXTERN int calc_errno; /* global calc_errno value */ -EXTERN char *calcpath; /* $CALCPATH or default */ -EXTERN char *calcrc; /* $CALCRC or default */ -EXTERN char *calcbindings; /* $CALCBINDINGS or default */ -EXTERN char *home; /* $HOME or default */ -EXTERN char *shell; /* $SHELL or default */ +EXTERN char *calcpath; /* $CALCPATH or default */ +EXTERN char *calcrc; /* $CALCRC or default */ +EXTERN char *calcbindings; /* $CALCBINDINGS or default */ +EXTERN char *home; /* $HOME or default */ +EXTERN char *shell; /* $SHELL or default */ -EXTERN int no_env; /* true (-e) => ignore env vars on startup */ -EXTERN long errmax; /* if >= 0, error when errcount exceeds errmax */ -EXTERN int use_old_std; /* true (-O) => use classic configuration */ +EXTERN int no_env; /* true (-e) => ignore env vars on startup */ +EXTERN long errmax; /* if >= 0, error when errcount exceeds errmax */ +EXTERN int use_old_std; /* true (-O) => use classic configuration */ -EXTERN int allow_read; /* false => don't open any files for reading */ -EXTERN int allow_write; /* false => don't open any files for writing */ -EXTERN int allow_exec; /* false => may not execute any commands */ +EXTERN int allow_read; /* false => don't open any files for reading */ +EXTERN int allow_write; /* false => don't open any files for writing */ +EXTERN int allow_exec; /* false => may not execute any commands */ /* * calc startup and run state */ typedef enum { - RUN_ZERO, /* unknown or unset start state */ - RUN_BEGIN, /* calc execution starts */ - RUN_RCFILES, /* rc files being evaluated */ - RUN_PRE_CMD_ARGS, /* prepare to evaluate cmd args */ - RUN_CMD_ARGS, /* cmd args being evaluated */ - RUN_PRE_TOP_LEVEL, /* prepare to start top level activity */ - RUN_TOP_LEVEL, /* running at top level */ - RUN_EXIT, /* normal exit from calc */ - RUN_EXIT_WITH_ERROR /* exit with error */ + RUN_ZERO, /* unknown or unset start state */ + RUN_BEGIN, /* calc execution starts */ + RUN_RCFILES, /* rc files being evaluated */ + RUN_PRE_CMD_ARGS, /* prepare to evaluate cmd args */ + RUN_CMD_ARGS, /* cmd args being evaluated */ + RUN_PRE_TOP_LEVEL, /* prepare to start top level activity */ + RUN_TOP_LEVEL, /* running at top level */ + RUN_EXIT, /* normal exit from calc */ + RUN_EXIT_WITH_ERROR /* exit with error */ } run; EXTERN run run_state; E_FUNC char *run_state_name(run state); diff --git a/calc.man b/calc.man index c8b9915..858097c 100644 --- a/calc.man +++ b/calc.man @@ -1,5 +1,5 @@ .\" -.\" Copyright (C) 1999-2007,2014,2018,2021 Landon Curt Noll +.\" Copyright (C) 1999-2007,2014,2018,2021 Landon Curt Noll .\" .\" Calc is open software; you can redistribute it and/or modify it under .\" the terms of the version 2.1 of the GNU Lesser General Public License @@ -15,11 +15,11 @@ .\" received a copy with calc; if not, write to Free Software Foundation, Inc. .\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. .\" -.\" Under source code control: 1991/07/23 05:48:26 -.\" File existed as early as: 1991 +.\" Under source code control: 1991/07/23 05:48:26 +.\" File existed as early as: 1991 .\" -.\" chongo /\oo/\ http://www.isthe.com/chongo/ -.\" Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +.\" chongo /\oo/\ http://www.isthe.com/chongo/ +.\" Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ .\" .\" calculator by David I. Bell .\" man page by Landon Noll @@ -636,7 +636,7 @@ may have to be replaced by: .sp 1 .in +5n .nf -print 27! ^2 or print 27\\!^2 +print 27! ^2 or print 27\\!^2 .fi .in -5n diff --git a/calc.spec.in b/calc.spec.in index c05cefc..1889692 100644 --- a/calc.spec.in +++ b/calc.spec.in @@ -9,7 +9,7 @@ # # 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 +# 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 @@ -17,13 +17,13 @@ # received a copy with calc; if not, write to Free Software Foundation, Inc. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # -# Under source code control: 2003/02/16 20:21:39 -# File existed as early as: 2003 +# Under source code control: 2003/02/16 20:21:39 +# File existed as early as: 2003 # # This calculator first developed by David I. Bell with help/mods from others. # -# chongo /\oo/\ http://www.isthe.com/chongo/ -# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +# chongo /\oo/\ http://www.isthe.com/chongo/ +# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ # BUGS # - Uninstalling calc and calc-devel leaves empty dirs /usr/include/calc diff --git a/charbit.c b/charbit.c index 7d593ad..05c636a 100644 --- a/charbit.c +++ b/charbit.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,22 +17,22 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2021/12/07 20:57:50 - * File existed as early as: 2021 + * Under source code control: 2021/12/07 20:57:50 + * File existed as early as: 2021 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * charbit + * charbit * * This prog outputs several defines: * - * CALC_CHARBIT - * after including have_limits.h and perhaps , - * output CALC_CHARBIT as CHAR_BIT (from , or as 8. + * CALC_CHARBIT + * after including have_limits.h and perhaps , + * output CALC_CHARBIT as CHAR_BIT (from , or as 8. */ #include @@ -42,26 +42,26 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int main(void) { - printf("#include \"have_limits.h\"\n"); - printf("#if defined(HAVE_LIMITS_H)\n"); - printf("#include \n"); - printf("#endif\n\n"); + printf("#include \"have_limits.h\"\n"); + printf("#if defined(HAVE_LIMITS_H)\n"); + printf("#include \n"); + printf("#endif\n\n"); #if defined(CHAR_BIT) - printf("#define CALC_CHARBIT (CHAR_BIT) /* from */\n"); + printf("#define CALC_CHARBIT (CHAR_BIT) /* from */\n"); #else /* CHAR_BIT */ - printf("#define CALC_CHARBIT (8) /* no CHAR_BIT, assume 8 */\n"); + printf("#define CALC_CHARBIT (8) /* no CHAR_BIT, assume 8 */\n"); #endif /* CHAR_BIT */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/check.awk b/check.awk index 2731e36..3279f91 100644 --- a/check.awk +++ b/check.awk @@ -10,7 +10,7 @@ # # 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 +# 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 @@ -18,93 +18,93 @@ # received a copy with calc; if not, write to Free Software Foundation, Inc. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # -# Under source code control: 1996/05/25 22:07:58 -# File existed as early as: 1996 +# Under source code control: 1996/05/25 22:07:58 +# File existed as early as: 1996 # -# chongo /\oo/\ http://www.isthe.com/chongo/ -# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +# chongo /\oo/\ http://www.isthe.com/chongo/ +# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ # # This awk script will print 3 lines before and after any non-blank line that -# does not begin with a number. This allows the 'make debug' rule to remove +# does not begin with a number. This allows the 'make debug' rule to remove # all non-interest lines the 'make check' regression output while providing # 3 lines of context around unexpected output. # BEGIN { - havebuf0=0; - buf0=0; - havebuf1=0; - buf1=0; - havebuf2=0; - buf2=0; - error = 0; - end_seen = 0; + havebuf0=0; + buf0=0; + havebuf1=0; + buf1=0; + havebuf2=0; + buf2=0; + error = 0; + end_seen = 0; } NF == 0 { - if (error > 0) { - if (havebuf2) { - print buf2; - } - --error; - } - buf2 = buf1; - havebuf2 = havebuf1; - buf1 = buf0; - havebuf1 = havebuf0; - buf0 = $0; - havebuf0 = 1; - next; + if (error > 0) { + if (havebuf2) { + print buf2; + } + --error; + } + buf2 = buf1; + havebuf2 = havebuf1; + buf1 = buf0; + havebuf1 = havebuf0; + buf0 = $0; + havebuf0 = 1; + next; } /: Ending regression tests$/ { - end_seen = 1; + end_seen = 1; } $1 ~ /^[0-9]+:/ || $1 ~ /^[0-9]+-[0-9]*:/ || $1 ~ /^"\)\)$/ { - if (error > 0) { - if (havebuf2) { - print buf2; - } - --error; - } - buf2 = buf1; - havebuf2 = havebuf1; - buf1 = buf0; - havebuf1 = havebuf0; - buf0 = $0; - havebuf0 = 1; - next; + if (error > 0) { + if (havebuf2) { + print buf2; + } + --error; + } + buf2 = buf1; + havebuf2 = havebuf1; + buf1 = buf0; + havebuf1 = havebuf0; + buf0 = $0; + havebuf0 = 1; + next; } { - error = 6; - if (havebuf2) { - print buf2; - } - buf2 = buf1; - havebuf2 = havebuf1; - buf1 = buf0; - havebuf1 = havebuf0; - buf0 = $0; - havebuf0 = 1; - next; + error = 6; + if (havebuf2) { + print buf2; + } + buf2 = buf1; + havebuf2 = havebuf1; + buf1 = buf0; + havebuf1 = havebuf0; + buf0 = $0; + havebuf0 = 1; + next; } END { - if (error > 0 && havebuf2) { - print buf2; - --error; - } - if (error > 0 && havebuf1) { - print buf1; - --error; - } - if (error > 0 && havebuf0) { - print buf0; - } - if (error > 0 || !end_seen) { - exit(1); - } else { - exit(0); - } + if (error > 0 && havebuf2) { + print buf2; + --error; + } + if (error > 0 && havebuf1) { + print buf1; + --error; + } + if (error > 0 && havebuf0) { + print buf0; + } + if (error > 0 || !end_seen) { + exit(1); + } else { + exit(0); + } } diff --git a/chk_c.c b/chk_c.c index f90eabe..36ec333 100644 --- a/chk_c.c +++ b/chk_c.c @@ -3,17 +3,17 @@ * * This program, to successfully compile, must include: * - * #include - * #include + * #include + * #include * * and must be able to compile all of these types: * - * int8_t uint8_t - * int16_t uint16_t - * int32_t uint32_t - * int64_t uint64_t - * intptr_t uintptr_t - * intmax_t uintmax_t + * int8_t uint8_t + * int16_t uint16_t + * int32_t uint32_t + * int64_t uint64_t + * intptr_t uintptr_t + * intmax_t uintmax_t * * be able to sum values from all of those files, * plus the INTX_C(val) and UINTX_C(val) composing macros, @@ -34,7 +34,7 @@ * * 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 + * 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 @@ -42,11 +42,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2023/08/20 23:57:50 - * File existed as early as: 2023 + * Under source code control: 2023/08/20 23:57:50 + * File existed as early as: 2023 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ #include @@ -96,36 +96,36 @@ static char const *usage = "chk_c version: %s\n"; -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int main(int argc, char *argv[]) { - char *program = "((NULL))"; /* our name */ - int opt; /* the -option found or -1 */ - bool c_flag = false; /* if -h was found */ + char *program = "((NULL))"; /* our name */ + int opt; /* the -option found or -1 */ + bool c_flag = false; /* if -h was found */ #if defined(HAVE_STDINT_H) && defined(HAVE_INTTYPES_H) - int i = -1; /* signed int test value */ - unsigned int ui = 1; /* unsigned int test value */ - long l = -2L; /* signed long test value */ - unsigned long ul = 2UL; /* unsigned long test value */ - long long ll = -4LL; /* signed long long test value */ - unsigned long long ull = 4ULL; /* unsigned long long test value */ - int8_t i8 = INT8_C(-8); /* signed 8-bit test value */ - uint8_t ui8 = UINT8_C(8); /* unsigned 8-bit test value */ - int16_t i16 = INT16_C(-16); /* signed 16-bit test value */ - uint16_t ui16 = UINT16_C(16); /* unsigned 16-bit test value */ - int32_t i32 = INT32_C(-32); /* signed 32-bit test value */ - uint32_t ui32 = UINT32_C(32); /* unsigned 32-bit test value */ - int64_t i64 = INT64_C(-64); /* signed 64-bit test value */ - uint64_t ui64 = UINT64_C(64); /* unsigned 64-bit test value */ - intptr_t iptr = -128; /* integer type capable of holding a pointer */ - intptr_t uiptr = 128; /* unsigned integer type capable of holding a pointer */ - intmax_t imax = INTMAX_C(-256); /* maximum sized signed int test value */ - uintmax_t uimax = UINTMAX_C(256); /* maximum sized unsigned int test value */ - uintmax_t isum = 0; /* sum of all test values as signed value */ - uintmax_t uisum = 0; /* sum of all test values as unsigned value */ + int i = -1; /* signed int test value */ + unsigned int ui = 1; /* unsigned int test value */ + long l = -2L; /* signed long test value */ + unsigned long ul = 2UL; /* unsigned long test value */ + long long ll = -4LL; /* signed long long test value */ + unsigned long long ull = 4ULL; /* unsigned long long test value */ + int8_t i8 = INT8_C(-8); /* signed 8-bit test value */ + uint8_t ui8 = UINT8_C(8); /* unsigned 8-bit test value */ + int16_t i16 = INT16_C(-16); /* signed 16-bit test value */ + uint16_t ui16 = UINT16_C(16); /* unsigned 16-bit test value */ + int32_t i32 = INT32_C(-32); /* signed 32-bit test value */ + uint32_t ui32 = UINT32_C(32); /* unsigned 32-bit test value */ + int64_t i64 = INT64_C(-64); /* signed 64-bit test value */ + uint64_t ui64 = UINT64_C(64); /* unsigned 64-bit test value */ + intptr_t iptr = -128; /* integer type capable of holding a pointer */ + intptr_t uiptr = 128; /* unsigned integer type capable of holding a pointer */ + intmax_t imax = INTMAX_C(-256); /* maximum sized signed int test value */ + uintmax_t uimax = UINTMAX_C(256); /* maximum sized unsigned int test value */ + uintmax_t isum = 0; /* sum of all test values as signed value */ + uintmax_t uisum = 0; /* sum of all test values as unsigned value */ #endif /* HAVE_STDINT_H && HAVE_INTTYPES_H */ /* @@ -133,26 +133,26 @@ main(int argc, char *argv[]) */ program = argv[0]; while ((opt = getopt(argc, argv, "hcV")) != -1) { - switch (opt) { - case 'h': - fprintf(stderr, usage, program, CHK_C_VERSION); - exit(2); - break; - case 'c': - c_flag = true; - break; - case 'V': - printf("%s\n", CHK_C_VERSION); - exit(2); - break; + switch (opt) { + case 'h': + fprintf(stderr, usage, program, CHK_C_VERSION); + exit(2); + break; + case 'c': + c_flag = true; + break; + case 'V': + printf("%s\n", CHK_C_VERSION); + exit(2); + break; default: - fprintf(stderr, usage, program, CHK_C_VERSION); - exit(3); - } + fprintf(stderr, usage, program, CHK_C_VERSION); + exit(3); + } } if (optind != argc) { - fprintf(stderr, usage, program, CHK_C_VERSION); - exit(3); + fprintf(stderr, usage, program, CHK_C_VERSION); + exit(3); } /* @@ -160,14 +160,14 @@ main(int argc, char *argv[]) */ #if !defined(HAVE_STDINT_H) if (c_flag == true) { - printf("HAVE_STDINT_H is undefined\n"); + printf("HAVE_STDINT_H is undefined\n"); } fprintf(stderr, "calc requires include file\n"); exit(1); #else /* HAVE_STDINT_H */ if (c_flag == true) { - printf("HAVE_STDINT_H is defined\n"); - printf(" successfully included\n"); + printf("HAVE_STDINT_H is defined\n"); + printf(" successfully included\n"); } /* @@ -175,14 +175,14 @@ main(int argc, char *argv[]) */ #if !defined(HAVE_INTTYPES_H) if (c_flag == true) { - printf("HAVE_INTTYPES_H is undefined\n"); + printf("HAVE_INTTYPES_H is undefined\n"); } fprintf(stderr, "calc requires include file\n"); exit(1); #else /* HAVE_INTTYPES_H */ if (c_flag == true) { - printf("\nHAVE_INTTYPES_H is defined\n"); - printf(" successfully included\n"); + printf("\nHAVE_INTTYPES_H is defined\n"); + printf(" successfully included\n"); } /* @@ -193,7 +193,7 @@ main(int argc, char *argv[]) exit(1); #endif /* __STDC__ */ if (c_flag == true) { - printf("\n__STDC__ is defined\n"); + printf("\n__STDC__ is defined\n"); } /* @@ -204,7 +204,7 @@ main(int argc, char *argv[]) exit(1); #endif /* __STDC_VERSION__ */ if (c_flag == true) { - printf("__STDC_VERSION__: %ld is defined\n", __STDC_VERSION__); + printf("__STDC_VERSION__: %ld is defined\n", __STDC_VERSION__); } /* @@ -215,7 +215,7 @@ main(int argc, char *argv[]) exit(1); #endif /* __STDC_VERSION__ >= 199901L */ if (c_flag == true) { - printf("__STDC_VERSION__: %ld >= 199901L\n", __STDC_VERSION__); + printf("__STDC_VERSION__: %ld >= 199901L\n", __STDC_VERSION__); } /* @@ -223,11 +223,11 @@ main(int argc, char *argv[]) */ isum = i + ui + l + ul + ll + ull + i8 + ui8 + i16 + ui16 + i32 + ui32 + i64 + ui64 + iptr + uiptr + imax + uimax; if (c_flag == true) { - printf("\nzero valued isum: %jd\n", isum); + printf("\nzero valued isum: %jd\n", isum); } if (isum != 0) { - fprintf(stderr, "failed to add all required integer types into a signed value\n"); - exit(1); + fprintf(stderr, "failed to add all required integer types into a signed value\n"); + exit(1); } /* @@ -235,115 +235,115 @@ main(int argc, char *argv[]) */ uisum = i + ui + l + ul + ll + ull + i8 + ui8 + i16 + ui16 + i32 + ui32 + i64 + ui64 + iptr + uiptr + imax + uimax; if (c_flag == true) { - printf("zero valued uisum: %ju\n", uisum); + printf("zero valued uisum: %ju\n", uisum); } if (uisum != 0) { - fprintf(stderr, "failed to add all required integer types into an unsigned value\n"); - exit(1); + fprintf(stderr, "failed to add all required integer types into an unsigned value\n"); + exit(1); } /* * verify various 32, 64 and max PRI macros as well as MIN and MAX constants */ if (c_flag == true) { - printf("\nsigned integer MIN and MAX\n"); - printf("INT8_MIN: %+"PRId8"\n", (int8_t)INT8_MIN); - printf("INT8_MAX: %+"PRId8"\n", (int8_t)INT8_MAX); - printf("INT16_MIN: %+"PRId16"\n", (int16_t)INT16_MIN); - printf("INT16_MAX: %+"PRId16"\n", (int16_t)INT16_MAX); - printf("INT32_MIN: %+"PRId32"\n", (int32_t)INT32_MIN); - printf("INT32_MAX: %+"PRId32"\n", (int32_t)INT32_MAX); - printf("INT64_MIN: %+"PRId64"\n", (int64_t)INT64_MIN); - printf("INT64_MAX: %+"PRId64"\n", (int64_t)INT64_MAX); - printf("INTPTR_MIN: %+"PRIdMAX"\n", (intptr_t)INTPTR_MIN); - printf("INTPTR_MAX: %+"PRIdMAX"\n", (intptr_t)INTPTR_MAX); - printf("INTMAX_MIN: %+"PRIdMAX"\n", (intmax_t)INTMAX_MIN); - printf("INTMAX_MAX: %+"PRIdMAX"\n", (intmax_t)INTMAX_MAX); + printf("\nsigned integer MIN and MAX\n"); + printf("INT8_MIN: %+"PRId8"\n", (int8_t)INT8_MIN); + printf("INT8_MAX: %+"PRId8"\n", (int8_t)INT8_MAX); + printf("INT16_MIN: %+"PRId16"\n", (int16_t)INT16_MIN); + printf("INT16_MAX: %+"PRId16"\n", (int16_t)INT16_MAX); + printf("INT32_MIN: %+"PRId32"\n", (int32_t)INT32_MIN); + printf("INT32_MAX: %+"PRId32"\n", (int32_t)INT32_MAX); + printf("INT64_MIN: %+"PRId64"\n", (int64_t)INT64_MIN); + printf("INT64_MAX: %+"PRId64"\n", (int64_t)INT64_MAX); + printf("INTPTR_MIN: %+"PRIdMAX"\n", (intptr_t)INTPTR_MIN); + printf("INTPTR_MAX: %+"PRIdMAX"\n", (intptr_t)INTPTR_MAX); + printf("INTMAX_MIN: %+"PRIdMAX"\n", (intmax_t)INTMAX_MIN); + printf("INTMAX_MAX: %+"PRIdMAX"\n", (intmax_t)INTMAX_MAX); - printf("\nunsigned integer MAX\n"); - printf("UINT8_MAX: %"PRIu8"\n", (uint8_t)UINT8_MAX); - printf("UINT16_MAX: %"PRIu16"\n", (uint16_t)UINT16_MAX); - printf("UINT32_MAX: %"PRIu32"\n", (uint32_t)UINT32_MAX); - printf("UINT64_MAX: %"PRIu64"\n", (uint64_t)UINT64_MAX); - printf("UINTPTR_MAX: %"PRIuMAX"\n", (uintptr_t)UINTPTR_MAX); - printf("UINTMAX_MAX: %"PRIuMAX"\n", (uintmax_t)UINTMAX_MAX); + printf("\nunsigned integer MAX\n"); + printf("UINT8_MAX: %"PRIu8"\n", (uint8_t)UINT8_MAX); + printf("UINT16_MAX: %"PRIu16"\n", (uint16_t)UINT16_MAX); + printf("UINT32_MAX: %"PRIu32"\n", (uint32_t)UINT32_MAX); + printf("UINT64_MAX: %"PRIu64"\n", (uint64_t)UINT64_MAX); + printf("UINTPTR_MAX: %"PRIuMAX"\n", (uintptr_t)UINTPTR_MAX); + printf("UINTMAX_MAX: %"PRIuMAX"\n", (uintmax_t)UINTMAX_MAX); - printf("\ninteger MIN and MAX\n"); - printf("INT8_MIN: %"PRIi8"\n", (int8_t)INT8_MIN); - printf("INT8_MAX: %"PRIi8"\n", (int8_t)INT8_MAX); - printf("INT16_MIN: %"PRIi16"\n", (int16_t)INT16_MIN); - printf("INT16_MAX: %"PRIi16"\n", (int16_t)INT16_MAX); - printf("INT32_MIN: %"PRIi32"\n", (int32_t)INT32_MIN); - printf("INT32_MAX: %"PRIi32"\n", (int32_t)INT32_MAX); - printf("INT64_MIN: %"PRIi64"\n", (int64_t)INT64_MIN); - printf("INT64_MAX: %"PRIi64"\n", (int64_t)INT64_MAX); - printf("INTPTR_MIN: %"PRIiMAX"\n", (intptr_t)INTPTR_MIN); - printf("INTPTR_MAX: %"PRIiMAX"\n", (intptr_t)INTPTR_MAX); - printf("INTMAX_MIN: %"PRIiMAX"\n", (intmax_t)INTMAX_MIN); - printf("INTMAX_MAX: %"PRIiMAX"\n", (intmax_t)INTMAX_MAX); + printf("\ninteger MIN and MAX\n"); + printf("INT8_MIN: %"PRIi8"\n", (int8_t)INT8_MIN); + printf("INT8_MAX: %"PRIi8"\n", (int8_t)INT8_MAX); + printf("INT16_MIN: %"PRIi16"\n", (int16_t)INT16_MIN); + printf("INT16_MAX: %"PRIi16"\n", (int16_t)INT16_MAX); + printf("INT32_MIN: %"PRIi32"\n", (int32_t)INT32_MIN); + printf("INT32_MAX: %"PRIi32"\n", (int32_t)INT32_MAX); + printf("INT64_MIN: %"PRIi64"\n", (int64_t)INT64_MIN); + printf("INT64_MAX: %"PRIi64"\n", (int64_t)INT64_MAX); + printf("INTPTR_MIN: %"PRIiMAX"\n", (intptr_t)INTPTR_MIN); + printf("INTPTR_MAX: %"PRIiMAX"\n", (intptr_t)INTPTR_MAX); + printf("INTMAX_MIN: %"PRIiMAX"\n", (intmax_t)INTMAX_MIN); + printf("INTMAX_MAX: %"PRIiMAX"\n", (intmax_t)INTMAX_MAX); - printf("\noctal MIN and MAX\n"); - printf("INT8_MIN: %"PRIo8"\n", (int8_t)INT8_MIN); - printf("INT8_MAX: %"PRIo8"\n", (int8_t)INT8_MAX); - printf("INT16_MIN: %"PRIo16"\n", (int16_t)INT16_MIN); - printf("INT16_MAX: %"PRIo16"\n", (int16_t)INT16_MAX); - printf("INT32_MIN: %"PRIo32"\n", (int32_t)INT32_MIN); - printf("INT32_MAX: %"PRIo32"\n", (int32_t)INT32_MAX); - printf("INT64_MIN: %"PRIo64"\n", (int64_t)INT64_MIN); - printf("INT64_MAX: %"PRIo64"\n", (int64_t)INT64_MAX); - printf("INTPTR_MIN: %"PRIoMAX"\n", (intptr_t)INTPTR_MIN); - printf("INTPTR_MAX: %"PRIoMAX"\n", (intptr_t)INTPTR_MAX); - printf("INTMAX_MIN: %"PRIoMAX"\n", (intmax_t)INTMAX_MIN); - printf("INTMAX_MAX: %"PRIoMAX"\n", (intmax_t)INTMAX_MAX); + printf("\noctal MIN and MAX\n"); + printf("INT8_MIN: %"PRIo8"\n", (int8_t)INT8_MIN); + printf("INT8_MAX: %"PRIo8"\n", (int8_t)INT8_MAX); + printf("INT16_MIN: %"PRIo16"\n", (int16_t)INT16_MIN); + printf("INT16_MAX: %"PRIo16"\n", (int16_t)INT16_MAX); + printf("INT32_MIN: %"PRIo32"\n", (int32_t)INT32_MIN); + printf("INT32_MAX: %"PRIo32"\n", (int32_t)INT32_MAX); + printf("INT64_MIN: %"PRIo64"\n", (int64_t)INT64_MIN); + printf("INT64_MAX: %"PRIo64"\n", (int64_t)INT64_MAX); + printf("INTPTR_MIN: %"PRIoMAX"\n", (intptr_t)INTPTR_MIN); + printf("INTPTR_MAX: %"PRIoMAX"\n", (intptr_t)INTPTR_MAX); + printf("INTMAX_MIN: %"PRIoMAX"\n", (intmax_t)INTMAX_MIN); + printf("INTMAX_MAX: %"PRIoMAX"\n", (intmax_t)INTMAX_MAX); - printf("\nhex MIN and MAX\n"); - printf("INT8_MIN: %"PRIx8"\n", (int8_t)INT8_MIN); - printf("INT8_MAX: %"PRIx8"\n", (int8_t)INT8_MAX); - printf("INT16_MIN: %"PRIx16"\n", (int16_t)INT16_MIN); - printf("INT16_MAX: %"PRIx16"\n", (int16_t)INT16_MAX); - printf("INT32_MIN: %"PRIx32"\n", (int32_t)INT32_MIN); - printf("INT32_MAX: %"PRIx32"\n", (int32_t)INT32_MAX); - printf("INT64_MIN: %"PRIx64"\n", (int64_t)INT64_MIN); - printf("INT64_MAX: %"PRIx64"\n", (int64_t)INT64_MAX); - printf("INTPTR_MIN: %"PRIxMAX"\n", (intptr_t)INTPTR_MIN); - printf("INTPTR_MAX: %"PRIxMAX"\n", (intptr_t)INTPTR_MAX); - printf("INTMAX_MIN: %"PRIxMAX"\n", (intmax_t)INTMAX_MIN); - printf("INTMAX_MAX: %"PRIxMAX"\n", (intmax_t)INTMAX_MAX); + printf("\nhex MIN and MAX\n"); + printf("INT8_MIN: %"PRIx8"\n", (int8_t)INT8_MIN); + printf("INT8_MAX: %"PRIx8"\n", (int8_t)INT8_MAX); + printf("INT16_MIN: %"PRIx16"\n", (int16_t)INT16_MIN); + printf("INT16_MAX: %"PRIx16"\n", (int16_t)INT16_MAX); + printf("INT32_MIN: %"PRIx32"\n", (int32_t)INT32_MIN); + printf("INT32_MAX: %"PRIx32"\n", (int32_t)INT32_MAX); + printf("INT64_MIN: %"PRIx64"\n", (int64_t)INT64_MIN); + printf("INT64_MAX: %"PRIx64"\n", (int64_t)INT64_MAX); + printf("INTPTR_MIN: %"PRIxMAX"\n", (intptr_t)INTPTR_MIN); + printf("INTPTR_MAX: %"PRIxMAX"\n", (intptr_t)INTPTR_MAX); + printf("INTMAX_MIN: %"PRIxMAX"\n", (intmax_t)INTMAX_MIN); + printf("INTMAX_MAX: %"PRIxMAX"\n", (intmax_t)INTMAX_MAX); - printf("\nHEX MIN and MAX\n"); - printf("INT8_MIN: %"PRIX8"\n", (int8_t)INT8_MIN); - printf("INT8_MAX: %"PRIX8"\n", (int8_t)INT8_MAX); - printf("INT16_MIN: %"PRIX16"\n", (int16_t)INT16_MIN); - printf("INT16_MAX: %"PRIX16"\n", (int16_t)INT16_MAX); - printf("INT32_MIN: %"PRIX32"\n", (int32_t)INT32_MIN); - printf("INT32_MAX: %"PRIX32"\n", (int32_t)INT32_MAX); - printf("INT64_MIN: %"PRIX64"\n", (int64_t)INT64_MIN); - printf("INT64_MAX: %"PRIX64"\n", (int64_t)INT64_MAX); - printf("INTPTR_MIN: %"PRIXMAX"\n", (intptr_t)INTPTR_MIN); - printf("INTPTR_MAX: %"PRIXMAX"\n", (intptr_t)INTPTR_MAX); - printf("INTMAX_MIN: %"PRIXMAX"\n", (intmax_t)INTMAX_MIN); - printf("INTMAX_MAX: %"PRIXMAX"\n", (intmax_t)INTMAX_MAX); + printf("\nHEX MIN and MAX\n"); + printf("INT8_MIN: %"PRIX8"\n", (int8_t)INT8_MIN); + printf("INT8_MAX: %"PRIX8"\n", (int8_t)INT8_MAX); + printf("INT16_MIN: %"PRIX16"\n", (int16_t)INT16_MIN); + printf("INT16_MAX: %"PRIX16"\n", (int16_t)INT16_MAX); + printf("INT32_MIN: %"PRIX32"\n", (int32_t)INT32_MIN); + printf("INT32_MAX: %"PRIX32"\n", (int32_t)INT32_MAX); + printf("INT64_MIN: %"PRIX64"\n", (int64_t)INT64_MIN); + printf("INT64_MAX: %"PRIX64"\n", (int64_t)INT64_MAX); + printf("INTPTR_MIN: %"PRIXMAX"\n", (intptr_t)INTPTR_MIN); + printf("INTPTR_MAX: %"PRIXMAX"\n", (intptr_t)INTPTR_MAX); + printf("INTMAX_MIN: %"PRIXMAX"\n", (intmax_t)INTMAX_MIN); + printf("INTMAX_MAX: %"PRIXMAX"\n", (intmax_t)INTMAX_MAX); - printf("\nsizes\n"); - printf("sizeof(int8_t): %lu\n", sizeof(int8_t)); - printf("sizeof(uint8_t): %lu\n", sizeof(uint8_t)); - printf("sizeof(int16_t): %lu\n", sizeof(int16_t)); - printf("sizeof(uint16_t): %lu\n", sizeof(uint16_t)); - printf("sizeof(int32_t): %lu\n", sizeof(int32_t)); - printf("sizeof(uint32_t): %lu\n", sizeof(uint32_t)); - printf("sizeof(int64_t): %lu\n", sizeof(int64_t)); - printf("sizeof(uint64_t): %lu\n", sizeof(uint64_t)); - printf("sizeof(intptr_t): %lu\n", sizeof(intptr_t)); - printf("sizeof(uintptr_t): %lu\n", sizeof(uintptr_t)); - printf("sizeof(intmax_t): %lu\n", sizeof(intmax_t)); - printf("sizeof(uintmax_t): %lu\n", sizeof(uintmax_t)); + printf("\nsizes\n"); + printf("sizeof(int8_t): %lu\n", sizeof(int8_t)); + printf("sizeof(uint8_t): %lu\n", sizeof(uint8_t)); + printf("sizeof(int16_t): %lu\n", sizeof(int16_t)); + printf("sizeof(uint16_t): %lu\n", sizeof(uint16_t)); + printf("sizeof(int32_t): %lu\n", sizeof(int32_t)); + printf("sizeof(uint32_t): %lu\n", sizeof(uint32_t)); + printf("sizeof(int64_t): %lu\n", sizeof(int64_t)); + printf("sizeof(uint64_t): %lu\n", sizeof(uint64_t)); + printf("sizeof(intptr_t): %lu\n", sizeof(intptr_t)); + printf("sizeof(uintptr_t): %lu\n", sizeof(uintptr_t)); + printf("sizeof(intmax_t): %lu\n", sizeof(intmax_t)); + printf("sizeof(uintmax_t): %lu\n", sizeof(uintmax_t)); } /* * All Done!! -- Jessica Noll, age 2 */ if (c_flag == true) { - printf("\nC compiler and select include files appear to support calc.\n"); + printf("\nC compiler and select include files appear to support calc.\n"); } exit(0); #endif /* HAVE_INTTYPES_H */ diff --git a/chk_tree b/chk_tree index b81666c..d2887ff 100755 --- a/chk_tree +++ b/chk_tree @@ -20,11 +20,11 @@ # received a copy with calc; if not, write to Free Software Foundation, Inc. # 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. # -# Under source code control: 2023/10/04 21:04:44 -# File existed as early as: 2023 +# Under source code control: 2023/10/04 21:04:44 +# File existed as early as: 2023 # -# chongo /\oo/\ http://www.isthe.com/chongo/ -# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +# chongo /\oo/\ http://www.isthe.com/chongo/ +# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ # setup # @@ -59,10 +59,10 @@ fi # declare -a FINDDIR mapfile -t FINDDIR < <(find . -type d \ - ! -path './NOTES/*' ! -name NOTES \ - ! -path './.git/*' ! -name .git \ - ! -path './.github/*' ! -name .github | \ - sed -e 's/^\.\///' | sort -u) + ! -path './NOTES/*' ! -name NOTES \ + ! -path './.git/*' ! -name .git \ + ! -path './.github/*' ! -name .github | \ + sed -e 's/^\.\///' | sort -u) if [[ ${#FINDDIR[@]} -le 0 ]]; then echo "$0: ERROR: find dir is empty" 1>&2 EXIT_CODE=12 @@ -73,7 +73,7 @@ fi # declare -a DIFF_DISTDIR_FINDDIR mapfile -t DIFF_DISTDIR_FINDDIR < <(printf '%s\n' "${DISTDIR[@]}" "${FINDDIR[@]}" | - tr ' ' '\n' | sort | uniq -u) + tr ' ' '\n' | sort | uniq -u) if [[ ${#DIFF_DISTDIR_FINDDIR[@]} -ne 0 ]]; then # report that DISTDIR and FINDDIR differ @@ -81,15 +81,15 @@ if [[ ${#DIFF_DISTDIR_FINDDIR[@]} -ne 0 ]]; then echo "$0: ERROR: distdir and find dir differ for critical directories" 1>&2 declare -a ONLY_FINDDIR mapfile -t ONLY_FINDDIR < <(printf '%s\n' "${DISTDIR[@]}" "${DISTDIR[@]}" "${FINDDIR[@]}" | - tr ' ' '\n' | sort | uniq -u) + tr ' ' '\n' | sort | uniq -u) if [[ ${#ONLY_FINDDIR[@]} -ne 0 ]]; then - echo "$0: ERROR: found only in find dir: ${ONLY_FINDDIR[*]}" 1>&2 + echo "$0: ERROR: found only in find dir: ${ONLY_FINDDIR[*]}" 1>&2 fi declare -a ONLY_DISTDIR mapfile -t ONLY_DISTDIR < <(printf '%s\n' "${FINDDIR[@]}" "${FINDDIR[@]}" "${DISTDIR[@]}" | - tr ' ' '\n' | sort | uniq -u) + tr ' ' '\n' | sort | uniq -u) if [[ ${#ONLY_DISTDIR[@]} -ne 0 ]]; then - echo "$0: ERROR: found only in distdir: ${ONLY_DISTDIR[*]}" 1>&2 + echo "$0: ERROR: found only in distdir: ${ONLY_DISTDIR[*]}" 1>&2 fi EXIT_CODE=13 echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 @@ -129,57 +129,57 @@ if [[ -d .git ]]; then # declare -a GITLS mapfile -t GITLS < <(git ls | - grep -v -E '^\.github/|^\.gitignore$|^CODE_OF_CONDUCT\.md$|^CONTRIBUTING\.md$|^SECURITY\.md$' | - sort -u) + grep -v -E '^\.github/|^\.gitignore$|^CODE_OF_CONDUCT\.md$|^CONTRIBUTING\.md$|^SECURITY\.md$' | + sort -u) if [[ ${#GITLS[@]} -le 0 ]]; then - echo "$0: ERROR: git ls is empty" 1>&2 - EXIT_CODE=16 - echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 + echo "$0: ERROR: git ls is empty" 1>&2 + EXIT_CODE=16 + echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 fi # compare DISTLIST and GITLS # declare -a DIFF_DISTLIST_GITLS mapfile -t DIFF_DISTLIST_GITLS < <(printf '%s\n' "${DISTLIST[@]}" "${GITLS[@]}" | - tr ' ' '\n' | sort | uniq -u) + tr ' ' '\n' | sort | uniq -u) if [[ ${#DIFF_DISTLIST_GITLS[@]} -ne 0 ]]; then - # report that DISTLIST and GITLS differ - # - echo "$0: ERROR: distlist and git ls differ for critical files" 1>&2 - declare -a ONLY_GITLS - mapfile -t ONLY_GITLS < <(printf '%s\n' "${DISTLIST[@]}" "${DISTLIST[@]}" "${GITLS[@]}" | - tr ' ' '\n' | sort | uniq -u) - if [[ ${#ONLY_GITLS[@]} -ne 0 ]]; then - echo "$0: ERROR: found only in git ls: ${ONLY_GITLS[*]}" 1>&2 - fi - declare -a ONLY_DISTLIST - mapfile -t ONLY_DISTLIST < <(printf '%s\n' "${GITLS[@]}" "${GITLS[@]}" "${DISTLIST[@]}" | - tr ' ' '\n' | sort | uniq -u) - if [[ ${#ONLY_DISTLIST[@]} -ne 0 ]]; then - echo "$0: ERROR: found only in distlist: ${ONLY_DISTLIST[*]}" 1>&2 - fi - EXIT_CODE=17 - echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 + # report that DISTLIST and GITLS differ + # + echo "$0: ERROR: distlist and git ls differ for critical files" 1>&2 + declare -a ONLY_GITLS + mapfile -t ONLY_GITLS < <(printf '%s\n' "${DISTLIST[@]}" "${DISTLIST[@]}" "${GITLS[@]}" | + tr ' ' '\n' | sort | uniq -u) + if [[ ${#ONLY_GITLS[@]} -ne 0 ]]; then + echo "$0: ERROR: found only in git ls: ${ONLY_GITLS[*]}" 1>&2 + fi + declare -a ONLY_DISTLIST + mapfile -t ONLY_DISTLIST < <(printf '%s\n' "${GITLS[@]}" "${GITLS[@]}" "${DISTLIST[@]}" | + tr ' ' '\n' | sort | uniq -u) + if [[ ${#ONLY_DISTLIST[@]} -ne 0 ]]; then + echo "$0: ERROR: found only in distlist: ${ONLY_DISTLIST[*]}" 1>&2 + fi + EXIT_CODE=17 + echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 fi # verify that there are no staged uncommitted changes under git # GIT_STATUS=$(git status --untracked-files=no --porcelain 2>&1) if [[ -n $GIT_STATUS ]] || ! git diff --cached --quiet --exit-code; then - echo "$0: ERROR: there are staged uncommitted changes" 1>&2 - git status --short - EXIT_CODE=18 - echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 + echo "$0: ERROR: there are staged uncommitted changes" 1>&2 + git status --short + EXIT_CODE=18 + echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 fi # verify that there are no uncommitted changes under git # if ! git diff --quiet --exit-code; then - echo "$0: ERROR: there are unstaged changes" 1>&2 - git status --untracked-files=no --porcelain --short - EXIT_CODE=19 - echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 + echo "$0: ERROR: there are unstaged changes" 1>&2 + git status --untracked-files=no --porcelain --short + EXIT_CODE=19 + echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 fi # verify that master branch is not ahead of 'origin/master' @@ -187,15 +187,15 @@ if [[ -d .git ]]; then GIT_MASTER=$(git rev-list --count master) GIT_ORIGIN_MASTER=$(git rev-list --count origin/master) if [[ $GIT_MASTER -gt $GIT_ORIGIN_MASTER ]]; then - echo "$0: ERROR: master branch is behind of origin/master" 1>&2 - git status master - EXIT_CODE=20 - echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 + echo "$0: ERROR: master branch is behind of origin/master" 1>&2 + git status master + EXIT_CODE=20 + echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 elif [[ $GIT_MASTER -lt $GIT_ORIGIN_MASTER ]]; then - echo "$0: ERROR: master branch is ahead of origin/master" 1>&2 - git status master - EXIT_CODE=21 - echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 + echo "$0: ERROR: master branch is ahead of origin/master" 1>&2 + git status master + EXIT_CODE=21 + echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 fi # verify that branch is not ahead of 'origin/HEAD' @@ -203,15 +203,15 @@ if [[ -d .git ]]; then GIT_HEAD=$(git rev-list --count HEAD) GIT_ORIGIN_HEAD=$(git rev-list --count origin/HEAD) if [[ $GIT_HEAD -gt $GIT_ORIGIN_HEAD ]]; then - echo "$0: ERROR: HEAD is behind of origin/HEAD" 1>&2 - git status HEAD - EXIT_CODE=22 - echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 + echo "$0: ERROR: HEAD is behind of origin/HEAD" 1>&2 + git status HEAD + EXIT_CODE=22 + echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 elif [[ $GIT_HEAD -lt $GIT_ORIGIN_HEAD ]]; then - echo "$0: ERROR: HEAD is ahead of origin/HEAD" 1>&2 - git status HEAD - EXIT_CODE=23 - echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 + echo "$0: ERROR: HEAD is ahead of origin/HEAD" 1>&2 + git status HEAD + EXIT_CODE=23 + echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 fi fi @@ -238,9 +238,9 @@ done declare -a DISTLIST_ALSO_IN_BUILDLIST mapfile -t DISTLIST_ALSO_IN_BUILDLIST < <( for i in "${DISTLIST_A[@]}"; do - if [[ -n "${BUILDLIST_A[$i]}" ]]; then - echo "$i"; - fi + if [[ -n "${BUILDLIST_A[$i]}" ]]; then + echo "$i"; + fi done ) if [[ ${#DISTLIST_ALSO_IN_BUILDLIST[@]} -ne 0 ]]; then @@ -262,18 +262,18 @@ fi # We ignore single letter files as they are used for temporary files. # We ignore files containing the any of the following in any letter case: # -# foo bar baz curds whey rmme +# foo bar baz curds whey rmme # declare -a FINDFILE mapfile -t FINDFILE < <(find . -type f \ - ! -path './NOTES/*' ! -name NOTES \ - ! -path './.git/*' ! -name .git \ - ! -path './.github/*' ! -name .github \ - ! -name 'CODE_OF_CONDUCT.md' ! -name 'CONTRIBUTING.md' ! -name '.gitignore' ! -name 'SECURITY.md' \ - ! -name '*.swp' ! -name '?' ! -iname '*.out*' \ - ! -iname '*foo*' ! -iname '*bar*' ! -iname '*baz*' \ - ! -iname '*curds*' ! -iname '*whey*' ! -iname '*rmmee' -print | - sed -e 's/^\.\///' | sort -u) + ! -path './NOTES/*' ! -name NOTES \ + ! -path './.git/*' ! -name .git \ + ! -path './.github/*' ! -name .github \ + ! -name 'CODE_OF_CONDUCT.md' ! -name 'CONTRIBUTING.md' ! -name '.gitignore' ! -name 'SECURITY.md' \ + ! -name '*.swp' ! -name '?' ! -iname '*.out*' \ + ! -iname '*foo*' ! -iname '*bar*' ! -iname '*baz*' \ + ! -iname '*curds*' ! -iname '*whey*' ! -iname '*rmmee' -print | + sed -e 's/^\.\///' | sort -u) if [[ ${#FINDFILE[@]} -le 0 ]]; then echo "$0: ERROR: find file is empty" 1>&2 EXIT_CODE=26 @@ -294,21 +294,21 @@ declare -a UNKNOWN_FILE mapfile -t UNKNOWN_FILE < <( for i in "${FINDFILE[@]}"; do - # skip if this is a file that is result of building calc - # - if [[ -n ${BUILDLIST_A["$i"]} ]]; then - continue - fi + # skip if this is a file that is result of building calc + # + if [[ -n ${BUILDLIST_A["$i"]} ]]; then + continue + fi - # skip if this is a file that is calc distribution list - # - if [[ -n ${DISTLIST_A["$i"]} ]]; then - continue - fi + # skip if this is a file that is calc distribution list + # + if [[ -n ${DISTLIST_A["$i"]} ]]; then + continue + fi - # print the file of unknown status - # - echo "$i" + # print the file of unknown status + # + echo "$i" done ) if [[ ${#UNKNOWN_FILE[@]} -ne 0 ]]; then @@ -327,15 +327,15 @@ fi # that end in .out, and files containing the any of the following # in any letter case: # -# foo bar baz curds whey rmme +# foo bar baz curds whey rmme # # So we will object is any distlist file is one of these ignored filenames. # INVALID_DISTLIST=$(printf '%s\n' "${DISTLIST[@]}" | \ - tr '[:upper:]' '[:lower:]' | \ - sed -n -e '/^.$/p' -e '/.*foo.*/p' -e '/.*bar.*/p' -e '/.*baz.*/p' \ - -e '/.*curds.*/p' -e '/.*whey.*/p' -e '/.*rmme.*/p' | - tr '\n' ' ') + tr '[:upper:]' '[:lower:]' | \ + sed -n -e '/^.$/p' -e '/.*foo.*/p' -e '/.*bar.*/p' -e '/.*baz.*/p' \ + -e '/.*curds.*/p' -e '/.*whey.*/p' -e '/.*rmme.*/p' | + tr '\n' ' ') if [[ -n $INVALID_DISTLIST ]]; then echo "$0: ERROR: distlist contains invalid filename(s): $INVALID_DISTLIST" 1>&2 EXIT_CODE=28 diff --git a/cmath.h b/cmath.h index 737d42a..9a837b3 100644 --- a/cmath.h +++ b/cmath.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1993/07/30 19:42:45 - * File existed as early as: 1993 + * Under source code control: 1993/07/30 19:42:45 + * File existed as early as: 1993 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,7 +28,7 @@ #define INCLUDE_CMATH_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "qmath.h" #else # include @@ -39,9 +39,9 @@ * Complex arithmetic definitions. */ typedef struct { - NUMBER *real; /* real part of number */ - NUMBER *imag; /* imaginary part of number */ - long links; /* link count */ + NUMBER *real; /* real part of number */ + NUMBER *imag; /* imaginary part of number */ + long links; /* link count */ } COMPLEX; @@ -167,19 +167,19 @@ E_FUNC COMPLEX *swap_HALF_in_COMPLEX(COMPLEX *dest, COMPLEX *src, bool all); /* * macro expansions to speed this thing up */ -#define cisreal(c) (qiszero((c)->imag)) -#define cisimag(c) (qiszero((c)->real) && !cisreal(c)) -#define ciszero(c) (cisreal(c) && qiszero((c)->real)) -#define cisone(c) (cisreal(c) && qisone((c)->real)) -#define cisnegone(c) (cisreal(c) && qisnegone((c)->real)) -#define cisrunit(c) (cisreal(c) && qisunit((c)->real)) -#define cisiunit(c) (qiszero((c)->real) && qisunit((c)->imag)) -#define cisunit(c) (cisrunit(c) || cisiunit(c)) -#define cistwo(c) (cisreal(c) && qistwo((c)->real)) -#define cisint(c) (qisint((c)->real) && qisint((c)->imag)) -#define ciseven(c) (qiseven((c)->real) && qiseven((c)->imag)) -#define cisodd(c) (qisodd((c)->real) || qisodd((c)->imag)) -#define clink(c) ((c)->links++, (c)) +#define cisreal(c) (qiszero((c)->imag)) +#define cisimag(c) (qiszero((c)->real) && !cisreal(c)) +#define ciszero(c) (cisreal(c) && qiszero((c)->real)) +#define cisone(c) (cisreal(c) && qisone((c)->real)) +#define cisnegone(c) (cisreal(c) && qisnegone((c)->real)) +#define cisrunit(c) (cisreal(c) && qisunit((c)->real)) +#define cisiunit(c) (qiszero((c)->real) && qisunit((c)->imag)) +#define cisunit(c) (cisrunit(c) || cisiunit(c)) +#define cistwo(c) (cisreal(c) && qistwo((c)->real)) +#define cisint(c) (qisint((c)->real) && qisint((c)->imag)) +#define ciseven(c) (qiseven((c)->real) && qiseven((c)->imag)) +#define cisodd(c) (qisodd((c)->real) || qisodd((c)->imag)) +#define clink(c) ((c)->links++, (c)) /* diff --git a/codegen.c b/codegen.c index 6040007..3a442c6 100644 --- a/codegen.c +++ b/codegen.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:13 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:13 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -52,10 +52,10 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -STATIC bool rdonce; /* true => do not reread this file */ +STATIC bool rdonce; /* true => do not reread this file */ FUNC *curfunc; @@ -66,12 +66,12 @@ S_FUNC void getshowstatement(void); S_FUNC void getfunction(void); S_FUNC void ungetfunction(void); S_FUNC void getbody(LABEL *contlabel, LABEL *breaklabel, - LABEL *nextcaselabel, LABEL *defaultlabel); + LABEL *nextcaselabel, LABEL *defaultlabel); S_FUNC int getdeclarations(int symtype); S_FUNC int getsimpledeclaration (int symtype); S_FUNC int getonevariable (int symtype); S_FUNC void getstatement(LABEL *contlabel, LABEL *breaklabel, - LABEL *nextcaselabel, LABEL *defaultlabel); + LABEL *nextcaselabel, LABEL *defaultlabel); S_FUNC void getobjdeclaration(int symtype); S_FUNC void getoneobj(long index, int symtype); S_FUNC void getobjvars(char *name, int symtype); @@ -123,182 +123,182 @@ STATIC int maxindices; void getcommands(bool toplevel) { - char name[MAXCMD+1+1]; /* program name */ + char name[MAXCMD+1+1]; /* program name */ - /* firewall */ - name[0] = '\0'; - name[MAXCMD+1] = '\0'; - abort_now = false; + /* firewall */ + name[0] = '\0'; + name[MAXCMD+1] = '\0'; + abort_now = false; - /* getcommands */ - if (!toplevel) - enterfilescope(); - for (;;) { - int i; - (void) tokenmode(TM_NEWLINES); - switch (gettoken()) { + /* getcommands */ + if (!toplevel) + enterfilescope(); + for (;;) { + int i; + (void) tokenmode(TM_NEWLINES); + switch (gettoken()) { - case T_DEFINE: - getfunction(); - break; + case T_DEFINE: + getfunction(); + break; - case T_EOF: - if (!toplevel) - exitfilescope(); - return; + case T_EOF: + if (!toplevel) + exitfilescope(); + return; - case T_HELP: - for (i=1;;i++) { - switch(getfilename(name, MAXCMD+1, NULL)) { - case 1: - case -1: - if(i == 1) { - strlcpy(name, - DEFAULTCALCHELP, - MAXCMD+1); - givehelp(name); - } - break; - case 0: - givehelp(name); - continue; - default: - break; - } - break; - } - break; + case T_HELP: + for (i=1;;i++) { + switch(getfilename(name, MAXCMD+1, NULL)) { + case 1: + case -1: + if(i == 1) { + strlcpy(name, + DEFAULTCALCHELP, + MAXCMD+1); + givehelp(name); + } + break; + case 0: + givehelp(name); + continue; + default: + break; + } + break; + } + break; - case T_READ: - if (!allow_read) { - scanerror(T_NULL, - "read command disallowed by -m mode\n"); - break; - } - for (;;) { - int open_ret; + case T_READ: + if (!allow_read) { + scanerror(T_NULL, + "read command disallowed by -m mode\n"); + break; + } + for (;;) { + int open_ret; - if (getfilename(name, MAXCMD+1, &rdonce)) - break; - open_ret = opensearchfile(name,calcpath, - CALCEXT,rdonce); - switch (open_ret) { - case 0: - getcommands(false); - closeinput(); - continue; - case 1: - /* prev read and -once was given */ - continue; - case -2: - scanerror(T_NULL, - "Maximum input depth reached"); - break; - default: - scanerror(T_NULL, - "Cannot open \"%s\"", name); - continue; - } - break; - } - break; + if (getfilename(name, MAXCMD+1, &rdonce)) + break; + open_ret = opensearchfile(name,calcpath, + CALCEXT,rdonce); + switch (open_ret) { + case 0: + getcommands(false); + closeinput(); + continue; + case 1: + /* prev read and -once was given */ + continue; + case -2: + scanerror(T_NULL, + "Maximum input depth reached"); + break; + default: + scanerror(T_NULL, + "Cannot open \"%s\"", name); + continue; + } + break; + } + break; - case T_WRITE: - if (!allow_write) { - scanerror(T_NULL, - "write command disallowed by -m mode\n"); - break; - } - if (getfilename(name, MAXCMD+1, NULL)) - break; - if (writeglobals(name)) { - scanerror(T_NULL, - "Error writing \"%s\"\n", name); - } - break; + case T_WRITE: + if (!allow_write) { + scanerror(T_NULL, + "write command disallowed by -m mode\n"); + break; + } + if (getfilename(name, MAXCMD+1, NULL)) + break; + if (writeglobals(name)) { + scanerror(T_NULL, + "Error writing \"%s\"\n", name); + } + break; - case T_CD: - do_changedir(); - break; - case T_NEWLINE: - case T_SEMICOLON: - break; + case T_CD: + do_changedir(); + break; + case T_NEWLINE: + case T_SEMICOLON: + break; - default: - rescantoken(); - initstack(); - if (evaluate(false)) - updateoldvalue(curfunc); - freefunc(curfunc); - if (abort_now) { - if (!stdin_tty) - run_state = RUN_EXIT; - else if (run_state < RUN_PRE_TOP_LEVEL) - run_state = RUN_PRE_TOP_LEVEL; - if (calc_use_scanerr_jmpbuf != 0) { - longjmp(calc_scanerr_jmpbuf, 30); - } else { - fprintf(stderr, - "calc_scanerr_jmpbuf not setup, exiting code 30\n"); - libcalc_call_me_last(); - exit(30); - } - } - } - } + default: + rescantoken(); + initstack(); + if (evaluate(false)) + updateoldvalue(curfunc); + freefunc(curfunc); + if (abort_now) { + if (!stdin_tty) + run_state = RUN_EXIT; + else if (run_state < RUN_PRE_TOP_LEVEL) + run_state = RUN_PRE_TOP_LEVEL; + if (calc_use_scanerr_jmpbuf != 0) { + longjmp(calc_scanerr_jmpbuf, 30); + } else { + fprintf(stderr, + "calc_scanerr_jmpbuf not setup, exiting code 30\n"); + libcalc_call_me_last(); + exit(30); + } + } + } + } } /* * Evaluate a line of statements. * This is done by treating the current line as a function body, - * compiling it, and then executing it. Returns true if the line - * successfully compiled and executed. The last expression result + * compiling it, and then executing it. Returns true if the line + * successfully compiled and executed. The last expression result * is saved in the f_savedvalue element of the current function. * The nestflag variable should be false for the outermost evaluation * level, and true for all other calls (such as the 'eval' function). * The function name begins with an asterisk to indicate specialness. * * given: - * nestflag true if this is a nested evaluation + * nestflag true if this is a nested evaluation */ bool evaluate(bool nestflag) { - char *funcname; - int loop = 1; /* 0 => end the main while loop */ + char *funcname; + int loop = 1; /* 0 => end the main while loop */ - funcname = (nestflag ? "**" : "*"); - beginfunc(funcname, nestflag); - if (gettoken() == T_LEFTBRACE) { - getbody(NULL_LABEL, NULL_LABEL, NULL_LABEL, NULL_LABEL); - } else { - if (nestflag) - (void) tokenmode(TM_DEFAULT); - rescantoken(); - while (loop) { - switch (gettoken()) { - case T_SEMICOLON: - break; - case T_NEWLINE: - case T_EOF: - loop = 0; - break; + funcname = (nestflag ? "**" : "*"); + beginfunc(funcname, nestflag); + if (gettoken() == T_LEFTBRACE) { + getbody(NULL_LABEL, NULL_LABEL, NULL_LABEL, NULL_LABEL); + } else { + if (nestflag) + (void) tokenmode(TM_DEFAULT); + rescantoken(); + while (loop) { + switch (gettoken()) { + case T_SEMICOLON: + break; + case T_NEWLINE: + case T_EOF: + loop = 0; + break; - default: - rescantoken(); - getstatement(NULL_LABEL, NULL_LABEL, - NULL_LABEL, NULL_LABEL); - } - } - } - addop(OP_UNDEF); - addop(OP_RETURN); - checklabels(); - if (errorcount) - return false; - calculate(curfunc, 0); - return true; + default: + rescantoken(); + getstatement(NULL_LABEL, NULL_LABEL, + NULL_LABEL, NULL_LABEL); + } + } + } + addop(OP_UNDEF); + addop(OP_RETURN); + checklabels(); + if (errorcount) + return false; + calculate(curfunc, 0); + return true; } /* @@ -307,136 +307,136 @@ evaluate(bool nestflag) S_FUNC void ungetfunction(void) { - char *name; - int type; + char *name; + int type; - for (;;) { - switch (gettoken()) { - case T_COMMA: - continue; - case T_SYMBOL: - name = tokensymbol(); - type = getbuiltinfunc(name); - if (type >= 0) { - warning( - "Cannot undefine builtin function \"%s\"", name); - continue; - } - rmuserfunc(name); - continue; - case T_MULT: - rmalluserfunc(); - continue; - case T_STATIC: - if (gettoken() != T_SYMBOL) { - scanerror(T_SEMICOLON, - "Non-identifier following \"undefine static\""); - return; - } - name = tokensymbol(); - endscope(name, false); - continue; + for (;;) { + switch (gettoken()) { + case T_COMMA: + continue; + case T_SYMBOL: + name = tokensymbol(); + type = getbuiltinfunc(name); + if (type >= 0) { + warning( + "Cannot undefine builtin function \"%s\"", name); + continue; + } + rmuserfunc(name); + continue; + case T_MULT: + rmalluserfunc(); + continue; + case T_STATIC: + if (gettoken() != T_SYMBOL) { + scanerror(T_SEMICOLON, + "Non-identifier following \"undefine static\""); + return; + } + name = tokensymbol(); + endscope(name, false); + continue; - case T_NEWLINE: - case T_SEMICOLON: - case T_EOF: - rescantoken(); - return; - default: - scanerror(T_SEMICOLON, "Non-name arg for undefine"); - return; - } - } + case T_NEWLINE: + case T_SEMICOLON: + case T_EOF: + rescantoken(); + return; + default: + scanerror(T_SEMICOLON, "Non-name arg for undefine"); + return; + } + } } /* * Get a function declaration. * func = name '(' '' | name [ ',' name] ... ')' simplebody - * | name '(' '' | name [ ',' name] ... ')' body. + * | name '(' '' | name [ ',' name] ... ')' body. */ S_FUNC void getfunction(void) { - char *name; /* parameter name */ - int type; /* type of token read */ - LABEL label; - long index; + char *name; /* parameter name */ + int type; /* type of token read */ + LABEL label; + long index; - (void) tokenmode(TM_DEFAULT); - if (gettoken() != T_SYMBOL) { - scanerror(T_NULL, "Function name was expected"); - return; - } - name = tokensymbol(); - type = getbuiltinfunc(name); - if (type >= 0) { - scanerror(T_SEMICOLON, "Using builtin function name"); - return; - } - beginfunc(name, false); - enterfuncscope(); - if (gettoken() != T_LEFTPAREN) { - scanerror(T_SEMICOLON, - "Left parenthesis expected for function"); - return; - } - index = 0; - for (;;) { - type = gettoken(); - if (type == T_RIGHTPAREN) - break; - if (type != T_SYMBOL) { - scanerror(T_COMMA, - "Using non-identifier as function parameter"); - return; - } - name = tokensymbol(); - switch (symboltype(name)) { - case SYM_UNDEFINED: - case SYM_GLOBAL: - case SYM_STATIC: - index = addparam(name); - break; - default: - scanerror(T_NULL, - "Parameter \"%s\" is already defined", - name); - } - type = gettoken(); - if (type == T_ASSIGN) { - clearlabel(&label); - addopone(OP_PARAMADDR, index); - addoplabel(OP_JUMPNN, &label); - getopassignment(); - addop(OP_ASSIGNPOP); - setlabel(&label); - type = gettoken(); - } + (void) tokenmode(TM_DEFAULT); + if (gettoken() != T_SYMBOL) { + scanerror(T_NULL, "Function name was expected"); + return; + } + name = tokensymbol(); + type = getbuiltinfunc(name); + if (type >= 0) { + scanerror(T_SEMICOLON, "Using builtin function name"); + return; + } + beginfunc(name, false); + enterfuncscope(); + if (gettoken() != T_LEFTPAREN) { + scanerror(T_SEMICOLON, + "Left parenthesis expected for function"); + return; + } + index = 0; + for (;;) { + type = gettoken(); + if (type == T_RIGHTPAREN) + break; + if (type != T_SYMBOL) { + scanerror(T_COMMA, + "Using non-identifier as function parameter"); + return; + } + name = tokensymbol(); + switch (symboltype(name)) { + case SYM_UNDEFINED: + case SYM_GLOBAL: + case SYM_STATIC: + index = addparam(name); + break; + default: + scanerror(T_NULL, + "Parameter \"%s\" is already defined", + name); + } + type = gettoken(); + if (type == T_ASSIGN) { + clearlabel(&label); + addopone(OP_PARAMADDR, index); + addoplabel(OP_JUMPNN, &label); + getopassignment(); + addop(OP_ASSIGNPOP); + setlabel(&label); + type = gettoken(); + } - if (type == T_RIGHTPAREN) - break; - if (type != T_COMMA) { - scanerror(T_COMMA, - "Using other than comma to separate parameters"); - return; - } - } - switch (gettoken()) { - case T_ASSIGN: - getsimplebody(); - break; - case T_LEFTBRACE: - getbody(NULL_LABEL, NULL_LABEL, NULL_LABEL, - NULL_LABEL); - break; - default: - scanerror(T_NULL, - "Left brace or equals sign expected for function"); - return; - } - endfunc(); - exitfuncscope(); + if (type == T_RIGHTPAREN) + break; + if (type != T_COMMA) { + scanerror(T_COMMA, + "Using other than comma to separate parameters"); + return; + } + } + switch (gettoken()) { + case T_ASSIGN: + getsimplebody(); + break; + case T_LEFTBRACE: + getbody(NULL_LABEL, NULL_LABEL, NULL_LABEL, + NULL_LABEL); + break; + default: + scanerror(T_NULL, + "Left brace or equals sign expected for function"); + return; + } + endfunc(); + exitfuncscope(); } @@ -447,122 +447,122 @@ getfunction(void) S_FUNC void getsimplebody(void) { - (void) tokenmode(TM_NEWLINES); - (void) getexprlist(); - addop(OP_RETURN); + (void) tokenmode(TM_NEWLINES); + (void) getexprlist(); + addop(OP_RETURN); } /* * Get the body of a function, or a sub-body of a function. * body = '{' [ declarations ] ... [ statement ] ... '}' - * | [ declarations ] ... [statement ] ... '\n' + * | [ declarations ] ... [statement ] ... '\n' */ /*ARGSUSED*/ S_FUNC void getbody(LABEL *contlabel, LABEL *breaklabel, LABEL *nextcaselabel, LABEL *defaultlabel) { - int oldmode; + int oldmode; - oldmode = tokenmode(TM_DEFAULT); - while (true) { - switch (gettoken()) { - case T_RIGHTBRACE: - (void) tokenmode(oldmode); - return; + oldmode = tokenmode(TM_DEFAULT); + while (true) { + switch (gettoken()) { + case T_RIGHTBRACE: + (void) tokenmode(oldmode); + return; - case T_EOF: - scanerror(T_NULL, "End-of-file in function body"); - return; + case T_EOF: + scanerror(T_NULL, "End-of-file in function body"); + return; - default: - rescantoken(); - getstatement(contlabel, breaklabel, - nextcaselabel, defaultlabel); - } - } + default: + rescantoken(); + getstatement(contlabel, breaklabel, + nextcaselabel, defaultlabel); + } + } } /* * Get a line of possible local, global, or static variable declarations. * declarations = { LOCAL | GLOBAL | STATIC } onedeclaration - * [ ',' onedeclaration ] ... ';'. + * [ ',' onedeclaration ] ... ';'. */ S_FUNC int getdeclarations(int symtype) { - int res = 0; + int res = 0; - while (true) { - switch (gettoken()) { - case T_COMMA: - continue; + while (true) { + switch (gettoken()) { + case T_COMMA: + continue; - case T_NEWLINE: - case T_SEMICOLON: - case T_RIGHTBRACE: - case T_EOF: - rescantoken(); - return res; + case T_NEWLINE: + case T_SEMICOLON: + case T_RIGHTBRACE: + case T_EOF: + rescantoken(); + return res; - case T_SYMBOL: - addopone(OP_DEBUG, linenumber()); - rescantoken(); - if (getsimpledeclaration(symtype)) - res = 1; - break; + case T_SYMBOL: + addopone(OP_DEBUG, linenumber()); + rescantoken(); + if (getsimpledeclaration(symtype)) + res = 1; + break; - case T_MAT: - addopone(OP_DEBUG, linenumber()); - getmatdeclaration(symtype); - res = 1; - break; + case T_MAT: + addopone(OP_DEBUG, linenumber()); + getmatdeclaration(symtype); + res = 1; + break; - case T_OBJ: - addopone(OP_DEBUG, linenumber()); - getobjdeclaration(symtype); - addop(OP_POP); - res = 1; - break; + case T_OBJ: + addopone(OP_DEBUG, linenumber()); + getobjdeclaration(symtype); + addop(OP_POP); + res = 1; + break; - default: - scanerror(T_SEMICOLON, - "Bad syntax in declaration statement"); - return res; - } - } + default: + scanerror(T_SEMICOLON, + "Bad syntax in declaration statement"); + return res; + } + } } /* * Get declaration of a sequence of simple identifiers, as in - * global a, b = 1, c d = 2, d; + * global a, b = 1, c d = 2, d; * Subsequences end with "," or at end of line; spaces indicate * repeated assignment, e.g. "c d = 2" has the effect of "c = 2, d = 2". */ S_FUNC int getsimpledeclaration(int symtype) { - int res = 0; + int res = 0; - for (;;) { - switch (gettoken()) { - case T_SYMBOL: - rescantoken(); - if (getonevariable(symtype)) { - res = 1; - addop(OP_POP); - } - continue; - case T_COMMA: - continue; - default: - rescantoken(); - return res; - } - } + for (;;) { + switch (gettoken()) { + case T_SYMBOL: + rescantoken(); + if (getonevariable(symtype)) { + res = 1; + addop(OP_POP); + } + continue; + case T_COMMA: + continue; + default: + rescantoken(); + return res; + } + } } @@ -570,508 +570,508 @@ getsimpledeclaration(int symtype) * Get one variable in a sequence of simple identifiers. * Returns 1 if the subsequence in which the variable occurs ends with * an assignment, e.g. for the variables b, c, d, in - * S_FUNC a, b = 1, c d = 2, d; + * S_FUNC a, b = 1, c d = 2, d; */ S_FUNC int getonevariable(int symtype) { - char *name; - int res = 0; + char *name; + int res = 0; - switch(gettoken()) { - case T_SYMBOL: - name = addliteral(tokensymbol()); - res = getonevariable(symtype); - definesymbol(name, symtype); - if (res) { - usesymbol(name, 0); - addop(OP_ASSIGNBACK); - } - return res; - case T_ASSIGN: - getopassignment(); - rescantoken(); - return 1; - default: - rescantoken(); - return 0; - } + switch(gettoken()) { + case T_SYMBOL: + name = addliteral(tokensymbol()); + res = getonevariable(symtype); + definesymbol(name, symtype); + if (res) { + usesymbol(name, 0); + addop(OP_ASSIGNBACK); + } + return res; + case T_ASSIGN: + getopassignment(); + rescantoken(); + return 1; + default: + rescantoken(); + return 0; + } } /* * Get a statement. * statement = IF condition statement [ELSE statement] - * | FOR '(' [assignment] ';' [assignment] ';' [assignment] ')' statement - * | WHILE condition statement - * | DO statement WHILE condition ';' - * | SWITCH condition '{' [caseclause] ... '}' - * | CONTINUE ';' - * | BREAK ';' - * | RETURN assignment ';' - * | GOTO label ';' - * | PRINT assignment [, assignment ] ... ';' - * | QUIT [ string ] ';' - * | ABORT [ string ] ';' - * | SHOW item ';' - * | body - * | assignment ';' - * | label ':' statement - * | ';'. + * | FOR '(' [assignment] ';' [assignment] ';' [assignment] ')' statement + * | WHILE condition statement + * | DO statement WHILE condition ';' + * | SWITCH condition '{' [caseclause] ... '}' + * | CONTINUE ';' + * | BREAK ';' + * | RETURN assignment ';' + * | GOTO label ';' + * | PRINT assignment [, assignment ] ... ';' + * | QUIT [ string ] ';' + * | ABORT [ string ] ';' + * | SHOW item ';' + * | body + * | assignment ';' + * | label ':' statement + * | ';'. * * given: - * contlabel label for continue statement - * breaklabel label for break statement - * nextcaselabel label for next case statement - * defaultlabel label for default case + * contlabel label for continue statement + * breaklabel label for break statement + * nextcaselabel label for next case statement + * defaultlabel label for default case */ S_FUNC void getstatement(LABEL *contlabel, LABEL *breaklabel, - LABEL *nextcaselabel, LABEL *defaultlabel) + LABEL *nextcaselabel, LABEL *defaultlabel) { - LABEL label; - LABEL label1, label2, label3, label4; /* locations for jumps */ - int type; - bool printeol; - int oldmode; + LABEL label; + LABEL label1, label2, label3, label4; /* locations for jumps */ + int type; + bool printeol; + int oldmode; - addopone(OP_DEBUG, linenumber()); - switch (gettoken()) { - case T_NEWLINE: - case T_SEMICOLON: - return; + addopone(OP_DEBUG, linenumber()); + switch (gettoken()) { + case T_NEWLINE: + case T_SEMICOLON: + return; - case T_GLOBAL: - (void) getdeclarations(SYM_GLOBAL); - break; + case T_GLOBAL: + (void) getdeclarations(SYM_GLOBAL); + break; - case T_STATIC: - clearlabel(&label); - addoplabel(OP_INITSTATIC, &label); - if (getdeclarations(SYM_STATIC)) - setlabel(&label); - else - curfunc->f_opcodecount -= 2; - break; + case T_STATIC: + clearlabel(&label); + addoplabel(OP_INITSTATIC, &label); + if (getdeclarations(SYM_STATIC)) + setlabel(&label); + else + curfunc->f_opcodecount -= 2; + break; - case T_LOCAL: - (void) getdeclarations(SYM_LOCAL); - break; + case T_LOCAL: + (void) getdeclarations(SYM_LOCAL); + break; - case T_UNDEFINE: - ungetfunction(); - break; + case T_UNDEFINE: + ungetfunction(); + break; - case T_RIGHTBRACE: - scanerror(T_NULL, "Extraneous right brace"); - return; + case T_RIGHTBRACE: + scanerror(T_NULL, "Extraneous right brace"); + return; - case T_CONTINUE: - if (contlabel == NULL_LABEL) { - scanerror(T_SEMICOLON, - "CONTINUE not within FOR, WHILE, or DO"); - return; - } - addoplabel(OP_JUMP, contlabel); - break; + case T_CONTINUE: + if (contlabel == NULL_LABEL) { + scanerror(T_SEMICOLON, + "CONTINUE not within FOR, WHILE, or DO"); + return; + } + addoplabel(OP_JUMP, contlabel); + break; - case T_BREAK: - if (breaklabel == NULL_LABEL) { - scanerror(T_SEMICOLON, - "BREAK not within FOR, WHILE, or DO"); - return; - } - addoplabel(OP_JUMP, breaklabel); - break; + case T_BREAK: + if (breaklabel == NULL_LABEL) { + scanerror(T_SEMICOLON, + "BREAK not within FOR, WHILE, or DO"); + return; + } + addoplabel(OP_JUMP, breaklabel); + break; - case T_GOTO: - if (gettoken() != T_SYMBOL) { - scanerror(T_SEMICOLON, "Missing label in goto"); - return; - } - addop(OP_JUMP); - addlabel(tokensymbol()); - break; + case T_GOTO: + if (gettoken() != T_SYMBOL) { + scanerror(T_SEMICOLON, "Missing label in goto"); + return; + } + addop(OP_JUMP); + addlabel(tokensymbol()); + break; - case T_RETURN: - switch (gettoken()) { - case T_NEWLINE: - case T_SEMICOLON: - addop(OP_UNDEF); - addop(OP_RETURN); - return; - default: - rescantoken(); - (void) getexprlist(); - if (curfunc->f_name[0] == '*') - addop(OP_SAVE); - addop(OP_RETURN); - } - break; + case T_RETURN: + switch (gettoken()) { + case T_NEWLINE: + case T_SEMICOLON: + addop(OP_UNDEF); + addop(OP_RETURN); + return; + default: + rescantoken(); + (void) getexprlist(); + if (curfunc->f_name[0] == '*') + addop(OP_SAVE); + addop(OP_RETURN); + } + break; - case T_LEFTBRACE: - getbody(contlabel, breaklabel, nextcaselabel, defaultlabel); - return; + case T_LEFTBRACE: + getbody(contlabel, breaklabel, nextcaselabel, defaultlabel); + return; - case T_IF: - clearlabel(&label1); - clearlabel(&label2); - getcondition(); - switch(gettoken()) { - case T_CONTINUE: - if (contlabel == NULL_LABEL) { - scanerror(T_SEMICOLON, - "CONTINUE not within FOR, " - "WHILE, or DO"); - return; - } - addoplabel(OP_JUMPNZ, contlabel); - break; - case T_BREAK: - if (breaklabel == NULL_LABEL) { - scanerror(T_SEMICOLON, - "BREAK not within FOR, " - "WHILE, or DO"); - return; - } - addoplabel(OP_JUMPNZ, breaklabel); - break; - case T_GOTO: - if (gettoken() != T_SYMBOL) { - scanerror(T_SEMICOLON, - "Missing label in goto"); - return; - } - addop(OP_JUMPNZ); - addlabel(tokensymbol()); - break; - default: - addoplabel(OP_JUMPZ, &label1); - rescantoken(); - getstatement(contlabel, breaklabel, - NULL_LABEL, NULL_LABEL); - if (gettoken() != T_ELSE) { - setlabel(&label1); - rescantoken(); - return; - } - addoplabel(OP_JUMP, &label2); - setlabel(&label1); - getstatement(contlabel, breaklabel, - NULL_LABEL, NULL_LABEL); - setlabel(&label2); - return; - } - if (gettoken() != T_SEMICOLON) /* This makes ';' optional */ - rescantoken(); - if (gettoken() != T_ELSE) { - rescantoken(); - return; - } - getstatement(contlabel, breaklabel, NULL_LABEL, NULL_LABEL); - return; + case T_IF: + clearlabel(&label1); + clearlabel(&label2); + getcondition(); + switch(gettoken()) { + case T_CONTINUE: + if (contlabel == NULL_LABEL) { + scanerror(T_SEMICOLON, + "CONTINUE not within FOR, " + "WHILE, or DO"); + return; + } + addoplabel(OP_JUMPNZ, contlabel); + break; + case T_BREAK: + if (breaklabel == NULL_LABEL) { + scanerror(T_SEMICOLON, + "BREAK not within FOR, " + "WHILE, or DO"); + return; + } + addoplabel(OP_JUMPNZ, breaklabel); + break; + case T_GOTO: + if (gettoken() != T_SYMBOL) { + scanerror(T_SEMICOLON, + "Missing label in goto"); + return; + } + addop(OP_JUMPNZ); + addlabel(tokensymbol()); + break; + default: + addoplabel(OP_JUMPZ, &label1); + rescantoken(); + getstatement(contlabel, breaklabel, + NULL_LABEL, NULL_LABEL); + if (gettoken() != T_ELSE) { + setlabel(&label1); + rescantoken(); + return; + } + addoplabel(OP_JUMP, &label2); + setlabel(&label1); + getstatement(contlabel, breaklabel, + NULL_LABEL, NULL_LABEL); + setlabel(&label2); + return; + } + if (gettoken() != T_SEMICOLON) /* This makes ';' optional */ + rescantoken(); + if (gettoken() != T_ELSE) { + rescantoken(); + return; + } + getstatement(contlabel, breaklabel, NULL_LABEL, NULL_LABEL); + return; - case T_FOR: /* for (a; b; c) x */ - oldmode = tokenmode(TM_DEFAULT); - clearlabel(&label1); - clearlabel(&label2); - clearlabel(&label3); - clearlabel(&label4); - contlabel = NULL_LABEL; - breaklabel = &label4; - if (gettoken() != T_LEFTPAREN) { - (void) tokenmode(oldmode); - scanerror(T_SEMICOLON, "Left parenthesis expected"); - return; - } - if (gettoken() != T_SEMICOLON) { /* have 'a' part */ - rescantoken(); - (void) getexprlist(); - addop(OP_POP); - if (gettoken() != T_SEMICOLON) { - (void) tokenmode(oldmode); - scanerror(T_SEMICOLON, "Missing semicolon"); - return; - } - } - if (gettoken() != T_SEMICOLON) { /* have 'b' part */ - setlabel(&label1); - contlabel = &label1; - rescantoken(); - (void) getexprlist(); - addoplabel(OP_JUMPNZ, &label3); - addoplabel(OP_JUMP, breaklabel); - if (gettoken() != T_SEMICOLON) { - (void) tokenmode(oldmode); - scanerror(T_SEMICOLON, "Missing semicolon"); - return; - } - } - if (gettoken() != T_RIGHTPAREN) { /* have 'c' part */ - if (label1.l_offset < 0) - addoplabel(OP_JUMP, &label3); - setlabel(&label2); - contlabel = &label2; - rescantoken(); - (void) getexprlist(); - addop(OP_POP); - if (label1.l_offset >= 0) - addoplabel(OP_JUMP, &label1); - if (gettoken() != T_RIGHTPAREN) { - (void) tokenmode(oldmode); - scanerror(T_SEMICOLON, - "Right parenthesis expected"); - return; - } - } - setlabel(&label3); - if (contlabel == NULL_LABEL) - contlabel = &label3; - (void) tokenmode(oldmode); - getstatement(contlabel, breaklabel, NULL_LABEL, NULL_LABEL); - addoplabel(OP_JUMP, contlabel); - setlabel(breaklabel); - return; + case T_FOR: /* for (a; b; c) x */ + oldmode = tokenmode(TM_DEFAULT); + clearlabel(&label1); + clearlabel(&label2); + clearlabel(&label3); + clearlabel(&label4); + contlabel = NULL_LABEL; + breaklabel = &label4; + if (gettoken() != T_LEFTPAREN) { + (void) tokenmode(oldmode); + scanerror(T_SEMICOLON, "Left parenthesis expected"); + return; + } + if (gettoken() != T_SEMICOLON) { /* have 'a' part */ + rescantoken(); + (void) getexprlist(); + addop(OP_POP); + if (gettoken() != T_SEMICOLON) { + (void) tokenmode(oldmode); + scanerror(T_SEMICOLON, "Missing semicolon"); + return; + } + } + if (gettoken() != T_SEMICOLON) { /* have 'b' part */ + setlabel(&label1); + contlabel = &label1; + rescantoken(); + (void) getexprlist(); + addoplabel(OP_JUMPNZ, &label3); + addoplabel(OP_JUMP, breaklabel); + if (gettoken() != T_SEMICOLON) { + (void) tokenmode(oldmode); + scanerror(T_SEMICOLON, "Missing semicolon"); + return; + } + } + if (gettoken() != T_RIGHTPAREN) { /* have 'c' part */ + if (label1.l_offset < 0) + addoplabel(OP_JUMP, &label3); + setlabel(&label2); + contlabel = &label2; + rescantoken(); + (void) getexprlist(); + addop(OP_POP); + if (label1.l_offset >= 0) + addoplabel(OP_JUMP, &label1); + if (gettoken() != T_RIGHTPAREN) { + (void) tokenmode(oldmode); + scanerror(T_SEMICOLON, + "Right parenthesis expected"); + return; + } + } + setlabel(&label3); + if (contlabel == NULL_LABEL) + contlabel = &label3; + (void) tokenmode(oldmode); + getstatement(contlabel, breaklabel, NULL_LABEL, NULL_LABEL); + addoplabel(OP_JUMP, contlabel); + setlabel(breaklabel); + return; - case T_WHILE: - oldmode = tokenmode(TM_DEFAULT); - contlabel = &label1; - clearlabel(contlabel); - setlabel(contlabel); - getcondition(); - (void) tokenmode(oldmode); - if (gettoken() != T_SEMICOLON) { - breaklabel = &label2; - clearlabel(breaklabel); - addoplabel(OP_JUMPZ, breaklabel); - rescantoken(); - getstatement(contlabel, breaklabel, - NULL_LABEL, NULL_LABEL); - addoplabel(OP_JUMP, contlabel); - setlabel(breaklabel); - } else { - addoplabel(OP_JUMPNZ, contlabel); - } - return; + case T_WHILE: + oldmode = tokenmode(TM_DEFAULT); + contlabel = &label1; + clearlabel(contlabel); + setlabel(contlabel); + getcondition(); + (void) tokenmode(oldmode); + if (gettoken() != T_SEMICOLON) { + breaklabel = &label2; + clearlabel(breaklabel); + addoplabel(OP_JUMPZ, breaklabel); + rescantoken(); + getstatement(contlabel, breaklabel, + NULL_LABEL, NULL_LABEL); + addoplabel(OP_JUMP, contlabel); + setlabel(breaklabel); + } else { + addoplabel(OP_JUMPNZ, contlabel); + } + return; - case T_DO: - oldmode = tokenmode(TM_DEFAULT); - contlabel = &label1; - breaklabel = &label2; - clearlabel(contlabel); - clearlabel(breaklabel); - clearlabel(&label3); - setlabel(&label3); - getstatement(contlabel, breaklabel, NULL_LABEL, NULL_LABEL); - if (gettoken() != T_WHILE) { - (void) tokenmode(oldmode); - scanerror(T_SEMICOLON, - "WHILE keyword expected for DO statement"); - return; - } - setlabel(contlabel); - getcondition(); - addoplabel(OP_JUMPNZ, &label3); - setlabel(breaklabel); - (void) tokenmode(oldmode); - return; + case T_DO: + oldmode = tokenmode(TM_DEFAULT); + contlabel = &label1; + breaklabel = &label2; + clearlabel(contlabel); + clearlabel(breaklabel); + clearlabel(&label3); + setlabel(&label3); + getstatement(contlabel, breaklabel, NULL_LABEL, NULL_LABEL); + if (gettoken() != T_WHILE) { + (void) tokenmode(oldmode); + scanerror(T_SEMICOLON, + "WHILE keyword expected for DO statement"); + return; + } + setlabel(contlabel); + getcondition(); + addoplabel(OP_JUMPNZ, &label3); + setlabel(breaklabel); + (void) tokenmode(oldmode); + return; - case T_SWITCH: - oldmode = tokenmode(TM_DEFAULT); - breaklabel = &label1; - nextcaselabel = &label2; - defaultlabel = &label3; - clearlabel(breaklabel); - clearlabel(nextcaselabel); - clearlabel(defaultlabel); - getcondition(); - if (gettoken() != T_LEFTBRACE) { - (void) tokenmode(oldmode); - scanerror(T_SEMICOLON, - "Missing left brace for switch statement"); - return; - } - addoplabel(OP_JUMP, nextcaselabel); - rescantoken(); - getstatement(contlabel, breaklabel, - nextcaselabel, defaultlabel); - addoplabel(OP_JUMP, breaklabel); - setlabel(nextcaselabel); - if (defaultlabel->l_offset > 0) - addoplabel(OP_JUMP, defaultlabel); - else - addop(OP_POP); - setlabel(breaklabel); - (void) tokenmode(oldmode); - return; + case T_SWITCH: + oldmode = tokenmode(TM_DEFAULT); + breaklabel = &label1; + nextcaselabel = &label2; + defaultlabel = &label3; + clearlabel(breaklabel); + clearlabel(nextcaselabel); + clearlabel(defaultlabel); + getcondition(); + if (gettoken() != T_LEFTBRACE) { + (void) tokenmode(oldmode); + scanerror(T_SEMICOLON, + "Missing left brace for switch statement"); + return; + } + addoplabel(OP_JUMP, nextcaselabel); + rescantoken(); + getstatement(contlabel, breaklabel, + nextcaselabel, defaultlabel); + addoplabel(OP_JUMP, breaklabel); + setlabel(nextcaselabel); + if (defaultlabel->l_offset > 0) + addoplabel(OP_JUMP, defaultlabel); + else + addop(OP_POP); + setlabel(breaklabel); + (void) tokenmode(oldmode); + return; - case T_CASE: - if (nextcaselabel == NULL_LABEL) { - scanerror(T_SEMICOLON, - "CASE not within SWITCH statement"); - return; - } - clearlabel(&label1); - addoplabel(OP_JUMP, &label1); - setlabel(nextcaselabel); - clearlabel(nextcaselabel); - (void) getexprlist(); - if (gettoken() != T_COLON) { - scanerror(T_SEMICOLON, - "Colon expected after CASE expression"); - return; - } - addoplabel(OP_CASEJUMP, nextcaselabel); - setlabel(&label1); - getstatement(contlabel, breaklabel, - nextcaselabel, defaultlabel); - return; + case T_CASE: + if (nextcaselabel == NULL_LABEL) { + scanerror(T_SEMICOLON, + "CASE not within SWITCH statement"); + return; + } + clearlabel(&label1); + addoplabel(OP_JUMP, &label1); + setlabel(nextcaselabel); + clearlabel(nextcaselabel); + (void) getexprlist(); + if (gettoken() != T_COLON) { + scanerror(T_SEMICOLON, + "Colon expected after CASE expression"); + return; + } + addoplabel(OP_CASEJUMP, nextcaselabel); + setlabel(&label1); + getstatement(contlabel, breaklabel, + nextcaselabel, defaultlabel); + return; - case T_DEFAULT: - if (gettoken() != T_COLON) { - scanerror(T_SEMICOLON, - "Colon expected after DEFAULT keyword"); - return; - } - if (defaultlabel == NULL_LABEL) { - scanerror(T_SEMICOLON, - "DEFAULT not within SWITCH statement"); - return; - } - if (defaultlabel->l_offset > 0) { - scanerror(T_SEMICOLON, - "Multiple DEFAULT clauses in SWITCH"); - return; - } - clearlabel(&label1); - addoplabel(OP_JUMP, &label1); - setlabel(defaultlabel); - addop(OP_POP); - setlabel(&label1); - getstatement(contlabel, breaklabel, - nextcaselabel, defaultlabel); - return; + case T_DEFAULT: + if (gettoken() != T_COLON) { + scanerror(T_SEMICOLON, + "Colon expected after DEFAULT keyword"); + return; + } + if (defaultlabel == NULL_LABEL) { + scanerror(T_SEMICOLON, + "DEFAULT not within SWITCH statement"); + return; + } + if (defaultlabel->l_offset > 0) { + scanerror(T_SEMICOLON, + "Multiple DEFAULT clauses in SWITCH"); + return; + } + clearlabel(&label1); + addoplabel(OP_JUMP, &label1); + setlabel(defaultlabel); + addop(OP_POP); + setlabel(&label1); + getstatement(contlabel, breaklabel, + nextcaselabel, defaultlabel); + return; - case T_ELSE: - scanerror(T_SEMICOLON, "ELSE without preceding IF"); - return; + case T_ELSE: + scanerror(T_SEMICOLON, "ELSE without preceding IF"); + return; - case T_SHOW: - getshowstatement(); - break; + case T_SHOW: + getshowstatement(); + break; - case T_PRINT: - printeol = true; - for (;;) { - switch (gettoken()) { - case T_RIGHTPAREN: - case T_RIGHTBRACKET: - case T_RIGHTBRACE: - case T_NEWLINE: - case T_ELSE: - case T_EOF: - rescantoken(); - /*FALLTHRU*/ - case T_SEMICOLON: - if (printeol) - addop(OP_PRINTEOL); - return; - case T_COMMA: - addop(OP_PRINTSPACE); - /*FALLTHRU*/ - case T_COLON: - printeol = false; - break; - case T_STRING: - printeol = true; - addopone(OP_PRINTSTRING, tokenstring()); - break; - default: - printeol = true; - rescantoken(); - (void) getopassignment(); - addopone(OP_PRINT, (long) PRINT_NORMAL); - } - } + case T_PRINT: + printeol = true; + for (;;) { + switch (gettoken()) { + case T_RIGHTPAREN: + case T_RIGHTBRACKET: + case T_RIGHTBRACE: + case T_NEWLINE: + case T_ELSE: + case T_EOF: + rescantoken(); + /*FALLTHRU*/ + case T_SEMICOLON: + if (printeol) + addop(OP_PRINTEOL); + return; + case T_COMMA: + addop(OP_PRINTSPACE); + /*FALLTHRU*/ + case T_COLON: + printeol = false; + break; + case T_STRING: + printeol = true; + addopone(OP_PRINTSTRING, tokenstring()); + break; + default: + printeol = true; + rescantoken(); + (void) getopassignment(); + addopone(OP_PRINT, (long) PRINT_NORMAL); + } + } - case T_QUIT: - switch (gettoken()) { - case T_STRING: - addopone(OP_QUIT, tokenstring()); - break; - default: - addopone(OP_QUIT, -1); - rescantoken(); - } - break; + case T_QUIT: + switch (gettoken()) { + case T_STRING: + addopone(OP_QUIT, tokenstring()); + break; + default: + addopone(OP_QUIT, -1); + rescantoken(); + } + break; - case T_ABORT: - switch (gettoken()) { - case T_STRING: - addopone(OP_ABORT, tokenstring()); - break; - default: - addopone(OP_ABORT, -1); - rescantoken(); - } - break; + case T_ABORT: + switch (gettoken()) { + case T_STRING: + addopone(OP_ABORT, tokenstring()); + break; + default: + addopone(OP_ABORT, -1); + rescantoken(); + } + break; - case T_SYMBOL: - if (nextchar() == ':') { /****HACK HACK****/ - definelabel(tokensymbol()); - if (gettoken() == T_RIGHTBRACE) { - rescantoken(); - return; - } - rescantoken(); - getstatement(contlabel, breaklabel, - NULL_LABEL, NULL_LABEL); - return; - } - reread(); - /*FALLTHRU*/ + case T_SYMBOL: + if (nextchar() == ':') { /****HACK HACK****/ + definelabel(tokensymbol()); + if (gettoken() == T_RIGHTBRACE) { + rescantoken(); + return; + } + rescantoken(); + getstatement(contlabel, breaklabel, + NULL_LABEL, NULL_LABEL); + return; + } + reread(); + /*FALLTHRU*/ - default: - rescantoken(); - type = getexprlist(); - if (contlabel || breaklabel || (curfunc->f_name[0] != '*')) { - addop(OP_POP); - break; - } - addop(OP_SAVE); - if (isassign(type) || (curfunc->f_name[1] != '\0')) { - addop(OP_POP); - break; - } - addop(OP_PRINTRESULT); - break; - } - for (;;) { - switch (gettoken()) { - case T_RIGHTBRACE: - case T_NEWLINE: - case T_EOF: - case T_ELSE: - rescantoken(); - return; - case T_SEMICOLON: - return; - case T_NUMBER: - case T_IMAGINARY: - addopone(OP_NUMBER, tokennumber()); - scanerror(T_NULL, "Unexpected number"); - continue; - default: - scanerror(T_NULL, "Semicolon expected"); - return; - } - } + default: + rescantoken(); + type = getexprlist(); + if (contlabel || breaklabel || (curfunc->f_name[0] != '*')) { + addop(OP_POP); + break; + } + addop(OP_SAVE); + if (isassign(type) || (curfunc->f_name[1] != '\0')) { + addop(OP_POP); + break; + } + addop(OP_PRINTRESULT); + break; + } + for (;;) { + switch (gettoken()) { + case T_RIGHTBRACE: + case T_NEWLINE: + case T_EOF: + case T_ELSE: + rescantoken(); + return; + case T_SEMICOLON: + return; + case T_NUMBER: + case T_IMAGINARY: + addopone(OP_NUMBER, tokennumber()); + scanerror(T_NULL, "Unexpected number"); + continue; + default: + scanerror(T_NULL, "Semicolon expected"); + return; + } + } } /* * Read in an object declaration. * This is of the following form: - * OBJ type [ '{' id [ ',' id ] ... '}' ] [ objlist ]. + * OBJ type [ '{' id [ ',' id ] ... '}' ] [ objlist ]. * The OBJ keyword has already been read. Symtype is SYM_UNDEFINED if this * is an OBJ statement, otherwise this is part of a declaration which will * define new symbols with the specified type. @@ -1079,137 +1079,137 @@ getstatement(LABEL *contlabel, LABEL *breaklabel, S_FUNC void getobjdeclaration(int symtype) { - char *name; /* name of object type */ - int count; /* number of elements */ - int index; /* current index */ - int i; /* loop counter */ - int oldmode; + char *name; /* name of object type */ + int count; /* number of elements */ + int index; /* current index */ + int i; /* loop counter */ + int oldmode; - if (gettoken() != T_SYMBOL) { - scanerror(T_SEMICOLON, "Object type name missing"); - return; - } - name = addliteral(tokensymbol()); - if (gettoken() != T_LEFTBRACE) { - rescantoken(); - getobjvars(name, symtype); - return; - } - /* - * Read in the definition of the elements of the object. - */ - count = 0; - indices = quickindices; - maxindices = INDICALLOC; + if (gettoken() != T_SYMBOL) { + scanerror(T_SEMICOLON, "Object type name missing"); + return; + } + name = addliteral(tokensymbol()); + if (gettoken() != T_LEFTBRACE) { + rescantoken(); + getobjvars(name, symtype); + return; + } + /* + * Read in the definition of the elements of the object. + */ + count = 0; + indices = quickindices; + maxindices = INDICALLOC; - oldmode = tokenmode(TM_DEFAULT); + oldmode = tokenmode(TM_DEFAULT); - for (;;) { - switch (gettoken()) { - case T_SYMBOL: - if (count == maxindices) { - if (maxindices == INDICALLOC) { - maxindices += INDICALLOC; - newindices = (int *) malloc(maxindices * - sizeof(int)); - if (newindices == NULL) { - scanerror(T_SEMICOLON, - "Out of memory for indices malloc"); - (void) tokenmode(oldmode); - return; - } - memcpy(newindices, quickindices, - INDICALLOC * sizeof(int)); - indices = newindices; - } else { - maxindices += INDICALLOC; - newindices = (int *) realloc(indices, - maxindices * sizeof(int)); - if (newindices == NULL) { - free(indices); - scanerror(T_SEMICOLON, - "Out of memory for indices realloc"); - (void) tokenmode(oldmode); - return; - } - indices = newindices; - } - } - index = addelement(tokensymbol()); - for (i = 0; i < count; i++) { - if (indices[i] == index) { - if (indices != quickindices) - free(indices); - scanerror(T_SEMICOLON, - "Duplicate element name \"%s\"", - tokensymbol()); - (void) tokenmode(oldmode); - return; - } - } - indices[count++] = index; - if (gettoken() == T_COMMA) - continue; - rescantoken(); - if (gettoken() != T_RIGHTBRACE) { - if (indices != quickindices) - free(indices); - scanerror(T_SEMICOLON, - "Bad object type definition"); - (void) tokenmode(oldmode); - return; - } - /*FALLTHRU*/ - case T_RIGHTBRACE: - (void) tokenmode(oldmode); - if (defineobject(name, indices, count)) { - if (indices != quickindices) - free(indices); - scanerror(T_NULL, - "Object type \"%s\" is already defined", name); - return; - } - if (indices != quickindices) - free(indices); - getobjvars(name, symtype); - return; - case T_NEWLINE: - continue; - default: - if (indices != quickindices) - free(indices); - scanerror(T_SEMICOLON, "Bad object type definition"); - (void) tokenmode(oldmode); - return; + for (;;) { + switch (gettoken()) { + case T_SYMBOL: + if (count == maxindices) { + if (maxindices == INDICALLOC) { + maxindices += INDICALLOC; + newindices = (int *) malloc(maxindices * + sizeof(int)); + if (newindices == NULL) { + scanerror(T_SEMICOLON, + "Out of memory for indices malloc"); + (void) tokenmode(oldmode); + return; + } + memcpy(newindices, quickindices, + INDICALLOC * sizeof(int)); + indices = newindices; + } else { + maxindices += INDICALLOC; + newindices = (int *) realloc(indices, + maxindices * sizeof(int)); + if (newindices == NULL) { + free(indices); + scanerror(T_SEMICOLON, + "Out of memory for indices realloc"); + (void) tokenmode(oldmode); + return; + } + indices = newindices; + } + } + index = addelement(tokensymbol()); + for (i = 0; i < count; i++) { + if (indices[i] == index) { + if (indices != quickindices) + free(indices); + scanerror(T_SEMICOLON, + "Duplicate element name \"%s\"", + tokensymbol()); + (void) tokenmode(oldmode); + return; + } + } + indices[count++] = index; + if (gettoken() == T_COMMA) + continue; + rescantoken(); + if (gettoken() != T_RIGHTBRACE) { + if (indices != quickindices) + free(indices); + scanerror(T_SEMICOLON, + "Bad object type definition"); + (void) tokenmode(oldmode); + return; + } + /*FALLTHRU*/ + case T_RIGHTBRACE: + (void) tokenmode(oldmode); + if (defineobject(name, indices, count)) { + if (indices != quickindices) + free(indices); + scanerror(T_NULL, + "Object type \"%s\" is already defined", name); + return; + } + if (indices != quickindices) + free(indices); + getobjvars(name, symtype); + return; + case T_NEWLINE: + continue; + default: + if (indices != quickindices) + free(indices); + scanerror(T_SEMICOLON, "Bad object type definition"); + (void) tokenmode(oldmode); + return; - } - } + } + } } S_FUNC void getoneobj(long index, int symtype) { - char *symname; + char *symname; - if (gettoken() == T_SYMBOL) { - if (symtype == SYM_UNDEFINED) { - rescantoken(); - (void) getidexpr(true, 1); - } else { - symname = tokensymbol(); - definesymbol(symname, symtype); - usesymbol(symname, 0); - } - getoneobj(index, symtype); - addop(OP_ASSIGN); - return; - } - rescantoken(); - addopone(OP_OBJCREATE, index); - while (gettoken() == T_ASSIGN) - (void) getinitlist(); - rescantoken(); + if (gettoken() == T_SYMBOL) { + if (symtype == SYM_UNDEFINED) { + rescantoken(); + (void) getidexpr(true, 1); + } else { + symname = tokensymbol(); + definesymbol(symname, symtype); + usesymbol(symname, 0); + } + getoneobj(index, symtype); + addop(OP_ASSIGN); + return; + } + rescantoken(); + addopone(OP_OBJCREATE, index); + while (gettoken() == T_ASSIGN) + (void) getinitlist(); + rescantoken(); } /* @@ -1219,259 +1219,259 @@ getoneobj(long index, int symtype) * type. * * given: - * name object name - * symtype declaration type + * name object name + * symtype declaration type */ S_FUNC void getobjvars(char *name, int symtype) { - long index; /* index for object */ + long index; /* index for object */ - index = checkobject(name); - if (index < 0) { - scanerror(T_SEMICOLON, - "Object %s has not been defined yet", name); - return; - } - for (;;) { - getoneobj(index, symtype); - if (symtype == SYM_UNDEFINED) - return; - if (gettoken() != T_COMMA) { - rescantoken(); - return; - } - addop(OP_POP); - } + index = checkobject(name); + if (index < 0) { + scanerror(T_SEMICOLON, + "Object %s has not been defined yet", name); + return; + } + for (;;) { + getoneobj(index, symtype); + if (symtype == SYM_UNDEFINED) + return; + if (gettoken() != T_COMMA) { + rescantoken(); + return; + } + addop(OP_POP); + } } S_FUNC void getmatdeclaration(int symtype) { - for (;;) { - switch (gettoken()) { - case T_SYMBOL: - rescantoken(); - getonematrix(symtype); - addop(OP_POP); - continue; - case T_COMMA: - continue; - default: - rescantoken(); - return; - } - } + for (;;) { + switch (gettoken()) { + case T_SYMBOL: + rescantoken(); + getonematrix(symtype); + addop(OP_POP); + continue; + case T_COMMA: + continue; + default: + rescantoken(); + return; + } + } } S_FUNC void getonematrix(int symtype) { - long dim; - long index; - long count; - unsigned long patchpc; - char *name; + long dim; + long index; + long count; + unsigned long patchpc; + char *name; - if (gettoken() == T_SYMBOL) { - if (symtype == SYM_UNDEFINED) { - rescantoken(); - (void) getidexpr(false, 1); - } else { - name = tokensymbol(); - definesymbol(name, symtype); - usesymbol(name, 0); - } - while (gettoken() == T_COMMA); - rescantoken(); - getonematrix(symtype); - addop(OP_ASSIGN); - return; - } - rescantoken(); + if (gettoken() == T_SYMBOL) { + if (symtype == SYM_UNDEFINED) { + rescantoken(); + (void) getidexpr(false, 1); + } else { + name = tokensymbol(); + definesymbol(name, symtype); + usesymbol(name, 0); + } + while (gettoken() == T_COMMA); + rescantoken(); + getonematrix(symtype); + addop(OP_ASSIGN); + return; + } + rescantoken(); - if (gettoken() == T_LEFTPAREN) { - if (isrvalue(getexprlist())) { - scanerror(T_SEMICOLON, "Lvalue expected"); - return; - } - if (gettoken() != T_RIGHTPAREN) { - scanerror(T_SEMICOLON, "Missing right parenthesis"); - return; - } - getonematrix(symtype); - addop(OP_ASSIGN); - return; - } - rescantoken(); + if (gettoken() == T_LEFTPAREN) { + if (isrvalue(getexprlist())) { + scanerror(T_SEMICOLON, "Lvalue expected"); + return; + } + if (gettoken() != T_RIGHTPAREN) { + scanerror(T_SEMICOLON, "Missing right parenthesis"); + return; + } + getonematrix(symtype); + addop(OP_ASSIGN); + return; + } + rescantoken(); - if (gettoken() != T_LEFTBRACKET) { - rescantoken(); - scanerror(T_SEMICOLON, "Left-bracket expected"); - return; - } - dim = 1; + if (gettoken() != T_LEFTBRACKET) { + rescantoken(); + scanerror(T_SEMICOLON, "Left-bracket expected"); + return; + } + dim = 1; - /* - * If there are no bounds given for the matrix, then they must be - * implicitly defined by a list of initialization values. Put in - * a dummy number in the opcode stream for the bounds and remember - * its location. After we know how many values are in the list, we - * will patch the correct value back into the opcode. - */ - if (gettoken() == T_RIGHTBRACKET) { - if (gettoken() == T_ASSIGN) { - clearopt(); - patchpc = curfunc->f_opcodecount + 1; - addopone(OP_NUMBER, (long) -1); - clearopt(); - addop(OP_ZERO); - addopone(OP_MATCREATE, dim); - addop(OP_ZERO); - addop(OP_INITFILL); - count = 0; - count = getinitlist(); - index = addqconstant(itoq(count)); - if (index < 0) - math_error("Cannot allocate constant"); - curfunc->f_opcodes[patchpc] = index; - return; - } - rescantoken(); - addopone(OP_MATCREATE, 0); - if (gettoken() == T_LEFTBRACKET) { - creatematrix(); - } else { - rescantoken(); - addop(OP_ZERO); - } - addop(OP_INITFILL); - return; - } + /* + * If there are no bounds given for the matrix, then they must be + * implicitly defined by a list of initialization values. Put in + * a dummy number in the opcode stream for the bounds and remember + * its location. After we know how many values are in the list, we + * will patch the correct value back into the opcode. + */ + if (gettoken() == T_RIGHTBRACKET) { + if (gettoken() == T_ASSIGN) { + clearopt(); + patchpc = curfunc->f_opcodecount + 1; + addopone(OP_NUMBER, (long) -1); + clearopt(); + addop(OP_ZERO); + addopone(OP_MATCREATE, dim); + addop(OP_ZERO); + addop(OP_INITFILL); + count = 0; + count = getinitlist(); + index = addqconstant(itoq(count)); + if (index < 0) + math_error("Cannot allocate constant"); + curfunc->f_opcodes[patchpc] = index; + return; + } + rescantoken(); + addopone(OP_MATCREATE, 0); + if (gettoken() == T_LEFTBRACKET) { + creatematrix(); + } else { + rescantoken(); + addop(OP_ZERO); + } + addop(OP_INITFILL); + return; + } - /* - * This isn't implicit, so we expect expressions for the bounds. - */ - rescantoken(); - creatematrix(); - while (gettoken() == T_ASSIGN) - (void) getinitlist(); - rescantoken(); + /* + * This isn't implicit, so we expect expressions for the bounds. + */ + rescantoken(); + creatematrix(); + while (gettoken() == T_ASSIGN) + (void) getinitlist(); + rescantoken(); } S_FUNC void creatematrix(void) { - long dim; + long dim; - dim = 0; + dim = 0; - for (;;) { - if (gettoken() == T_RIGHTBRACKET) { - addopone(OP_MATCREATE, dim); - if (gettoken() == T_LEFTBRACKET) { - creatematrix(); - } else { - rescantoken(); - addop(OP_ZERO); - } - addop(OP_INITFILL); - return; - } - rescantoken(); - if (++dim > MAXDIM) { - scanerror(T_SEMICOLON, - "Only %d dimensions allowed", MAXDIM); - return; - } - (void) getopassignment(); - switch (gettoken()) { - case T_RIGHTBRACKET: - rescantoken(); - /*FALLTHRU*/ - case T_COMMA: - addop(OP_ONE); - addop(OP_SUB); - addop(OP_ZERO); - break; - case T_COLON: - (void) getopassignment(); - switch(gettoken()) { - case T_RIGHTBRACKET: - rescantoken(); - /*FALLTHRU*/ - case T_COMMA: - continue; - } - /*FALLTHRU*/ - default: - rescantoken(); - scanerror(T_SEMICOLON, - "Illegal matrix definition"); - return; - } - } + for (;;) { + if (gettoken() == T_RIGHTBRACKET) { + addopone(OP_MATCREATE, dim); + if (gettoken() == T_LEFTBRACKET) { + creatematrix(); + } else { + rescantoken(); + addop(OP_ZERO); + } + addop(OP_INITFILL); + return; + } + rescantoken(); + if (++dim > MAXDIM) { + scanerror(T_SEMICOLON, + "Only %d dimensions allowed", MAXDIM); + return; + } + (void) getopassignment(); + switch (gettoken()) { + case T_RIGHTBRACKET: + rescantoken(); + /*FALLTHRU*/ + case T_COMMA: + addop(OP_ONE); + addop(OP_SUB); + addop(OP_ZERO); + break; + case T_COLON: + (void) getopassignment(); + switch(gettoken()) { + case T_RIGHTBRACKET: + rescantoken(); + /*FALLTHRU*/ + case T_COMMA: + continue; + } + /*FALLTHRU*/ + default: + rescantoken(); + scanerror(T_SEMICOLON, + "Illegal matrix definition"); + return; + } + } } /* * Get an optional initialization list for a matrix or object definition. * Returns the number of elements that are in the list, or -1 on parse error. - * initlist = { assignment [ , assignment ] ... }. + * initlist = { assignment [ , assignment ] ... }. */ S_FUNC long getinitlist(void) { - long index; - int oldmode; + long index; + int oldmode; - oldmode = tokenmode(TM_DEFAULT); + oldmode = tokenmode(TM_DEFAULT); - if (gettoken() != T_LEFTBRACE) { - scanerror(T_SEMICOLON, - "Missing left brace for initialization list"); - (void) tokenmode(oldmode); - return -1; - } + if (gettoken() != T_LEFTBRACE) { + scanerror(T_SEMICOLON, + "Missing left brace for initialization list"); + (void) tokenmode(oldmode); + return -1; + } - for (index = 0; ; index++) { - switch(gettoken()) { - case T_COMMA: - case T_NEWLINE: - continue; - case T_RIGHTBRACE: - (void) tokenmode(oldmode); - return index; - case T_LEFTBRACE: - rescantoken(); - addop(OP_DUPLICATE); - addopone(OP_ELEMADDR, index); - (void) getinitlist(); - break; - default: - rescantoken(); - getopassignment(); - } - addopone(OP_ELEMINIT, index); - switch (gettoken()) { - case T_COMMA: - case T_NEWLINE: - continue; + for (index = 0; ; index++) { + switch(gettoken()) { + case T_COMMA: + case T_NEWLINE: + continue; + case T_RIGHTBRACE: + (void) tokenmode(oldmode); + return index; + case T_LEFTBRACE: + rescantoken(); + addop(OP_DUPLICATE); + addopone(OP_ELEMADDR, index); + (void) getinitlist(); + break; + default: + rescantoken(); + getopassignment(); + } + addopone(OP_ELEMINIT, index); + switch (gettoken()) { + case T_COMMA: + case T_NEWLINE: + continue; - case T_RIGHTBRACE: - (void) tokenmode(oldmode); - return index; + case T_RIGHTBRACE: + (void) tokenmode(oldmode); + return index; - default: - scanerror(T_SEMICOLON, - "Missing right brace for initialization list"); - (void) tokenmode(oldmode); - return -1; - } - } + default: + scanerror(T_SEMICOLON, + "Missing right brace for initialization list"); + (void) tokenmode(oldmode); + return -1; + } + } } @@ -1482,23 +1482,23 @@ getinitlist(void) S_FUNC void getcondition(void) { - if (gettoken() != T_LEFTPAREN) { - scanerror(T_SEMICOLON, - "Missing left parenthesis for condition"); - return; - } - (void) getexprlist(); - if (gettoken() != T_RIGHTPAREN) { - scanerror(T_SEMICOLON, - "Missing right parenthesis for condition"); - return; - } + if (gettoken() != T_LEFTPAREN) { + scanerror(T_SEMICOLON, + "Missing left parenthesis for condition"); + return; + } + (void) getexprlist(); + if (gettoken() != T_RIGHTPAREN) { + scanerror(T_SEMICOLON, + "Missing right parenthesis for condition"); + return; + } } /* * Get an expression list consisting of one or more expressions, - * separated by commas. The value of the list is that of the final expression. + * separated by commas. The value of the list is that of the final expression. * This is the top level routine for parsing expressions. * Returns flags describing the type of the last assignment or expression found. * exprlist = assignment [ ',' assignment ] ... @@ -1506,15 +1506,15 @@ getcondition(void) S_FUNC int getexprlist(void) { - int type; + int type; - type = getopassignment(); - while (gettoken() == T_COMMA) { - addop(OP_POP); - type = getopassignment(); - } - rescantoken(); - return type; + type = getopassignment(); + while (gettoken() == T_COMMA) { + addop(OP_POP); + type = getopassignment(); + } + rescantoken(); + return type; } @@ -1522,89 +1522,89 @@ getexprlist(void) * Get an op-assignment or possibly just an assignment or expression. * Returns flags describing the type of assignment or expression found. * assignment = lvalue '=' assignment - * | lvalue '+=' assignment - * | lvalue '-=' assignment - * | lvalue '*=' assignment - * | lvalue '/=' assignment - * | lvalue '%=' assignment - * | lvalue '//=' assignment - * | lvalue '&=' assignment - * | lvalue '|=' assignment - * | lvalue '<<=' assignment - * | lvalue '>>=' assignment - * | lvalue '^=' assignment - * | lvalue '**=' assignment - * | orcond. + * | lvalue '+=' assignment + * | lvalue '-=' assignment + * | lvalue '*=' assignment + * | lvalue '/=' assignment + * | lvalue '%=' assignment + * | lvalue '//=' assignment + * | lvalue '&=' assignment + * | lvalue '|=' assignment + * | lvalue '<<=' assignment + * | lvalue '>>=' assignment + * | lvalue '^=' assignment + * | lvalue '**=' assignment + * | orcond. */ S_FUNC int getopassignment(void) { - int type; /* type of expression */ - long op; /* opcode to generate */ + int type; /* type of expression */ + long op; /* opcode to generate */ - type = getassignment(); - switch (gettoken()) { - case T_PLUSEQUALS: op = OP_ADD; break; - case T_MINUSEQUALS: op = OP_SUB; break; - case T_MULTEQUALS: op = OP_MUL; break; - case T_DIVEQUALS: op = OP_DIV; break; - case T_SLASHSLASHEQUALS: op = OP_QUO; break; - case T_MODEQUALS: op = OP_MOD; break; - case T_ANDEQUALS: op = OP_AND; break; - case T_OREQUALS: op = OP_OR; break; - case T_LSHIFTEQUALS: op = OP_LEFTSHIFT; break; - case T_RSHIFTEQUALS: op = OP_RIGHTSHIFT; break; - case T_POWEREQUALS: op = OP_POWER; break; - case T_HASHEQUALS: op = OP_HASHOP; break; - case T_TILDEEQUALS: op = OP_XOR; break; - case T_BACKSLASHEQUALS: op = OP_SETMINUS; break; + type = getassignment(); + switch (gettoken()) { + case T_PLUSEQUALS: op = OP_ADD; break; + case T_MINUSEQUALS: op = OP_SUB; break; + case T_MULTEQUALS: op = OP_MUL; break; + case T_DIVEQUALS: op = OP_DIV; break; + case T_SLASHSLASHEQUALS: op = OP_QUO; break; + case T_MODEQUALS: op = OP_MOD; break; + case T_ANDEQUALS: op = OP_AND; break; + case T_OREQUALS: op = OP_OR; break; + case T_LSHIFTEQUALS: op = OP_LEFTSHIFT; break; + case T_RSHIFTEQUALS: op = OP_RIGHTSHIFT; break; + case T_POWEREQUALS: op = OP_POWER; break; + case T_HASHEQUALS: op = OP_HASHOP; break; + case T_TILDEEQUALS: op = OP_XOR; break; + case T_BACKSLASHEQUALS: op = OP_SETMINUS; break; - default: - rescantoken(); - return type; - } - if (isrvalue(type)) { - scanerror(T_NULL, "Illegal assignment"); - (void) getopassignment(); - return (EXPR_RVALUE | EXPR_ASSIGN); - } - writeindexop(); - for(;;) { - addop(OP_DUPLICATE); - if (gettoken() == T_LEFTBRACE) { - rescantoken(); - addop(OP_DUPVALUE); - getinitlist(); - while (gettoken() == T_ASSIGN) - getinitlist(); - rescantoken(); - } else { - rescantoken(); - (void) getassignment(); - } - addop(op); - addop(OP_ASSIGN); - switch (gettoken()) { - case T_PLUSEQUALS: op = OP_ADD; break; - case T_MINUSEQUALS: op = OP_SUB; break; - case T_MULTEQUALS: op = OP_MUL; break; - case T_DIVEQUALS: op = OP_DIV; break; - case T_SLASHSLASHEQUALS: op = OP_QUO; break; - case T_MODEQUALS: op = OP_MOD; break; - case T_ANDEQUALS: op = OP_AND; break; - case T_OREQUALS: op = OP_OR; break; - case T_LSHIFTEQUALS: op = OP_LEFTSHIFT; break; - case T_RSHIFTEQUALS: op = OP_RIGHTSHIFT; break; - case T_POWEREQUALS: op = OP_POWER; break; - case T_HASHEQUALS: op = OP_HASHOP; break; - case T_TILDEEQUALS: op = OP_XOR; break; - case T_BACKSLASHEQUALS: op = OP_SETMINUS; break; + default: + rescantoken(); + return type; + } + if (isrvalue(type)) { + scanerror(T_NULL, "Illegal assignment"); + (void) getopassignment(); + return (EXPR_RVALUE | EXPR_ASSIGN); + } + writeindexop(); + for(;;) { + addop(OP_DUPLICATE); + if (gettoken() == T_LEFTBRACE) { + rescantoken(); + addop(OP_DUPVALUE); + getinitlist(); + while (gettoken() == T_ASSIGN) + getinitlist(); + rescantoken(); + } else { + rescantoken(); + (void) getassignment(); + } + addop(op); + addop(OP_ASSIGN); + switch (gettoken()) { + case T_PLUSEQUALS: op = OP_ADD; break; + case T_MINUSEQUALS: op = OP_SUB; break; + case T_MULTEQUALS: op = OP_MUL; break; + case T_DIVEQUALS: op = OP_DIV; break; + case T_SLASHSLASHEQUALS: op = OP_QUO; break; + case T_MODEQUALS: op = OP_MOD; break; + case T_ANDEQUALS: op = OP_AND; break; + case T_OREQUALS: op = OP_OR; break; + case T_LSHIFTEQUALS: op = OP_LEFTSHIFT; break; + case T_RSHIFTEQUALS: op = OP_RIGHTSHIFT; break; + case T_POWEREQUALS: op = OP_POWER; break; + case T_HASHEQUALS: op = OP_HASHOP; break; + case T_TILDEEQUALS: op = OP_XOR; break; + case T_BACKSLASHEQUALS: op = OP_SETMINUS; break; - default: - rescantoken(); - return EXPR_ASSIGN; - } - } + default: + rescantoken(); + return EXPR_ASSIGN; + } + } } @@ -1615,65 +1615,65 @@ getopassignment(void) S_FUNC int getassignment (void) { - int type; /* type of expression */ + int type; /* type of expression */ - switch(gettoken()) { - case T_COMMA: - case T_SEMICOLON: - case T_NEWLINE: - case T_RIGHTPAREN: - case T_RIGHTBRACKET: - case T_RIGHTBRACE: - case T_EOF: - addop(OP_UNDEF); - rescantoken(); - return EXPR_RVALUE; - } + switch(gettoken()) { + case T_COMMA: + case T_SEMICOLON: + case T_NEWLINE: + case T_RIGHTPAREN: + case T_RIGHTBRACKET: + case T_RIGHTBRACE: + case T_EOF: + addop(OP_UNDEF); + rescantoken(); + return EXPR_RVALUE; + } - rescantoken(); + rescantoken(); - type = getaltcond(); + type = getaltcond(); - switch (gettoken()) { - case T_NUMBER: - case T_IMAGINARY: - addopone(OP_NUMBER, tokennumber()); - type = (EXPR_RVALUE | EXPR_CONST); - /*FALLTHRU*/ - case T_STRING: - case T_SYMBOL: - case T_OLDVALUE: - case T_LEFTPAREN: - case T_PLUSPLUS: - case T_MINUSMINUS: - case T_NOT: - scanerror(T_NULL, "Missing operator"); - return type; - case T_ASSIGN: - break; + switch (gettoken()) { + case T_NUMBER: + case T_IMAGINARY: + addopone(OP_NUMBER, tokennumber()); + type = (EXPR_RVALUE | EXPR_CONST); + /*FALLTHRU*/ + case T_STRING: + case T_SYMBOL: + case T_OLDVALUE: + case T_LEFTPAREN: + case T_PLUSPLUS: + case T_MINUSMINUS: + case T_NOT: + scanerror(T_NULL, "Missing operator"); + return type; + case T_ASSIGN: + break; - default: - rescantoken(); - return type; - } - if (isrvalue(type)) { - scanerror(T_SEMICOLON, "Illegal assignment"); - (void) getassignment(); - return (EXPR_RVALUE | EXPR_ASSIGN); - } - writeindexop(); - if (gettoken() == T_LEFTBRACE) { - rescantoken(); - getinitlist(); - while (gettoken() == T_ASSIGN) - getinitlist(); - rescantoken(); - return EXPR_ASSIGN; - } - rescantoken(); - (void) getassignment(); - addop(OP_ASSIGN); - return EXPR_ASSIGN; + default: + rescantoken(); + return type; + } + if (isrvalue(type)) { + scanerror(T_SEMICOLON, "Illegal assignment"); + (void) getassignment(); + return (EXPR_RVALUE | EXPR_ASSIGN); + } + writeindexop(); + if (gettoken() == T_LEFTBRACE) { + rescantoken(); + getinitlist(); + while (gettoken() == T_ASSIGN) + getinitlist(); + rescantoken(); + return EXPR_ASSIGN; + } + rescantoken(); + (void) getassignment(); + addop(OP_ASSIGN); + return EXPR_ASSIGN; } @@ -1685,29 +1685,29 @@ getassignment (void) S_FUNC int getaltcond(void) { - int type; /* type of expression */ - LABEL donelab; /* label for done */ - LABEL altlab; /* label for alternate expression */ + int type; /* type of expression */ + LABEL donelab; /* label for done */ + LABEL altlab; /* label for alternate expression */ - type = getorcond(); - if (gettoken() != T_QUESTIONMARK) { - rescantoken(); - return type; - } - clearlabel(&donelab); - clearlabel(&altlab); - addoplabel(OP_JUMPZ, &altlab); - type = getaltcond(); - if (gettoken() != T_COLON) { - scanerror(T_SEMICOLON, - "Missing colon for conditional expression"); - return EXPR_RVALUE; - } - addoplabel(OP_JUMP, &donelab); - setlabel(&altlab); - type |= getaltcond(); - setlabel(&donelab); - return type; + type = getorcond(); + if (gettoken() != T_QUESTIONMARK) { + rescantoken(); + return type; + } + clearlabel(&donelab); + clearlabel(&altlab); + addoplabel(OP_JUMPZ, &altlab); + type = getaltcond(); + if (gettoken() != T_COLON) { + scanerror(T_SEMICOLON, + "Missing colon for conditional expression"); + return EXPR_RVALUE; + } + addoplabel(OP_JUMP, &donelab); + setlabel(&altlab); + type |= getaltcond(); + setlabel(&donelab); + return type; } @@ -1719,19 +1719,19 @@ getaltcond(void) S_FUNC int getorcond(void) { - int type; /* type of expression */ - LABEL donelab; /* label for done */ + int type; /* type of expression */ + LABEL donelab; /* label for done */ - clearlabel(&donelab); - type = getandcond(); - while (gettoken() == T_OROR) { - addoplabel(OP_CONDORJUMP, &donelab); - type |= getandcond(); - } - rescantoken(); - if (donelab.l_chain >= 0) - setlabel(&donelab); - return type; + clearlabel(&donelab); + type = getandcond(); + while (gettoken() == T_OROR) { + addoplabel(OP_CONDORJUMP, &donelab); + type |= getandcond(); + } + rescantoken(); + if (donelab.l_chain >= 0) + setlabel(&donelab); + return type; } @@ -1743,19 +1743,19 @@ getorcond(void) S_FUNC int getandcond(void) { - int type; /* type of expression */ - LABEL donelab; /* label for done */ + int type; /* type of expression */ + LABEL donelab; /* label for done */ - clearlabel(&donelab); - type = getrelation(); - while (gettoken() == T_ANDAND) { - addoplabel(OP_CONDANDJUMP, &donelab); - type |= getrelation(); - } - rescantoken(); - if (donelab.l_chain >= 0) - setlabel(&donelab); - return type; + clearlabel(&donelab); + type = getrelation(); + while (gettoken() == T_ANDAND) { + addoplabel(OP_CONDANDJUMP, &donelab); + type |= getrelation(); + } + rescantoken(); + if (donelab.l_chain >= 0) + setlabel(&donelab); + return type; } @@ -1763,36 +1763,36 @@ getandcond(void) * Get a possible relation (equality or inequality), or just an expression. * Flags are returned indicating the type of relation found. * relation = sum '==' sum - * | sum '!=' sum - * | sum '<=' sum - * | sum '>=' sum - * | sum '<' sum - * | sum '>' sum - * | sum. + * | sum '!=' sum + * | sum '<=' sum + * | sum '>=' sum + * | sum '<' sum + * | sum '>' sum + * | sum. */ S_FUNC int getrelation(void) { - int type; /* type of expression */ - long op; /* opcode to generate */ + int type; /* type of expression */ + long op; /* opcode to generate */ - type = getsum(); - switch (gettoken()) { - case T_EQ: op = OP_EQ; break; - case T_NE: op = OP_NE; break; - case T_LT: op = OP_LT; break; - case T_GT: op = OP_GT; break; - case T_LE: op = OP_LE; break; - case T_GE: op = OP_GE; break; - default: - rescantoken(); - return type; - } - if (islvalue(type)) - addop(OP_GETVALUE); - (void) getsum(); - addop(op); - return EXPR_RVALUE; + type = getsum(); + switch (gettoken()) { + case T_EQ: op = OP_EQ; break; + case T_NE: op = OP_NE; break; + case T_LT: op = OP_LT; break; + case T_GT: op = OP_GT; break; + case T_LE: op = OP_LE; break; + case T_GE: op = OP_GE; break; + default: + rescantoken(); + return type; + } + if (islvalue(type)) + addop(OP_GETVALUE); + (void) getsum(); + addop(op); + return EXPR_RVALUE; } @@ -1804,38 +1804,38 @@ getrelation(void) S_FUNC int getsum(void) { - int type; /* type of expression found */ - long op; /* opcode to generate */ + int type; /* type of expression found */ + long op; /* opcode to generate */ - type = EXPR_RVALUE; - switch(gettoken()) { - case T_PLUS: - (void) getproduct(); - addop(OP_PLUS); - break; - case T_MINUS: - (void) getproduct(); - addop(OP_NEGATE); - break; - default: - rescantoken(); - type = getproduct(); - } - for (;;) { - switch (gettoken()) { - case T_PLUS: op = OP_ADD; break; - case T_MINUS: op = OP_SUB; break; - case T_HASH: op = OP_HASHOP; break; - default: - rescantoken(); - return type; - } - if (islvalue(type)) - addop(OP_GETVALUE); - (void) getproduct(); - addop(op); - type = EXPR_RVALUE; - } + type = EXPR_RVALUE; + switch(gettoken()) { + case T_PLUS: + (void) getproduct(); + addop(OP_PLUS); + break; + case T_MINUS: + (void) getproduct(); + addop(OP_NEGATE); + break; + default: + rescantoken(); + type = getproduct(); + } + for (;;) { + switch (gettoken()) { + case T_PLUS: op = OP_ADD; break; + case T_MINUS: op = OP_SUB; break; + case T_HASH: op = OP_HASHOP; break; + default: + rescantoken(); + return type; + } + if (islvalue(type)) + addop(OP_GETVALUE); + (void) getproduct(); + addop(op); + type = EXPR_RVALUE; + } } @@ -1847,26 +1847,26 @@ getsum(void) S_FUNC int getproduct(void) { - int type; /* type of value found */ - long op; /* opcode to generate */ + int type; /* type of value found */ + long op; /* opcode to generate */ - type = getorexpr(); - for (;;) { - switch (gettoken()) { - case T_MULT: op = OP_MUL; break; - case T_DIV: op = OP_DIV; break; - case T_MOD: op = OP_MOD; break; - case T_SLASHSLASH: op = OP_QUO; break; - default: - rescantoken(); - return type; - } - if (islvalue(type)) - addop(OP_GETVALUE); - (void) getorexpr(); - addop(op); - type = EXPR_RVALUE; - } + type = getorexpr(); + for (;;) { + switch (gettoken()) { + case T_MULT: op = OP_MUL; break; + case T_DIV: op = OP_DIV; break; + case T_MOD: op = OP_MOD; break; + case T_SLASHSLASH: op = OP_QUO; break; + default: + rescantoken(); + return type; + } + if (islvalue(type)) + addop(OP_GETVALUE); + (void) getorexpr(); + addop(op); + type = EXPR_RVALUE; + } } @@ -1878,18 +1878,18 @@ getproduct(void) S_FUNC int getorexpr(void) { - int type; /* type of value found */ + int type; /* type of value found */ - type = getandexpr(); - while (gettoken() == T_OR) { - if (islvalue(type)) - addop(OP_GETVALUE); - (void) getandexpr(); - addop(OP_OR); - type = EXPR_RVALUE; - } - rescantoken(); - return type; + type = getandexpr(); + while (gettoken() == T_OR) { + if (islvalue(type)) + addop(OP_GETVALUE); + (void) getandexpr(); + addop(OP_OR); + type = EXPR_RVALUE; + } + rescantoken(); + return type; } @@ -1901,25 +1901,25 @@ getorexpr(void) S_FUNC int getandexpr(void) { - int type; /* type of value found */ - long op; + int type; /* type of value found */ + long op; - type = getshiftexpr(); - for (;;) { - switch (gettoken()) { - case T_AND: op = OP_AND; break; - case T_TILDE: op = OP_XOR; break; - case T_BACKSLASH: op = OP_SETMINUS; break; - default: - rescantoken(); - return type; - } - if (islvalue(type)) - addop(OP_GETVALUE); - (void) getshiftexpr(); - addop(op); - type = EXPR_RVALUE; - } + type = getshiftexpr(); + for (;;) { + switch (gettoken()) { + case T_AND: op = OP_AND; break; + case T_TILDE: op = OP_XOR; break; + case T_BACKSLASH: op = OP_SETMINUS; break; + default: + rescantoken(); + return type; + } + if (islvalue(type)) + addop(OP_GETVALUE); + (void) getshiftexpr(); + addop(op); + type = EXPR_RVALUE; + } } @@ -1927,52 +1927,52 @@ getandexpr(void) * Get a shift or power expression. * Flags indicating the type of expression found are returned. * shift = '+' shift - * | '-' shift - * | '/' shift - * | '\' shift - * | '~' shift - * | '#' shift - * | reference '^' shiftexpr - * | reference '<<' shiftexpr - * | reference '>>' shiftexpr - * | reference. + * | '-' shift + * | '/' shift + * | '\' shift + * | '~' shift + * | '#' shift + * | reference '^' shiftexpr + * | reference '<<' shiftexpr + * | reference '>>' shiftexpr + * | reference. */ S_FUNC int getshiftexpr(void) { - int type; /* type of value found */ - long op; /* opcode to generate */ + int type; /* type of value found */ + long op; /* opcode to generate */ - op = 0; - switch (gettoken()) { - case T_PLUS: op = OP_PLUS; break; - case T_MINUS: op = OP_NEGATE; break; - case T_NOT: op = OP_NOT; break; - case T_DIV: op = OP_INVERT; break; - case T_BACKSLASH: op = OP_BACKSLASH; break; - case T_TILDE: op = OP_COMP; break; - case T_HASH: op = OP_CONTENT; break; - } - if (op) { - (void) getshiftexpr(); - addop(op); - return EXPR_RVALUE; - } - rescantoken(); - type = getreference(); - switch (gettoken()) { - case T_POWER: op = OP_POWER; break; - case T_LEFTSHIFT: op = OP_LEFTSHIFT; break; - case T_RIGHTSHIFT: op = OP_RIGHTSHIFT; break; - default: - rescantoken(); - return type; - } - if (islvalue(type)) - addop(OP_GETVALUE); - (void) getshiftexpr(); - addop(op); - return EXPR_RVALUE; + op = 0; + switch (gettoken()) { + case T_PLUS: op = OP_PLUS; break; + case T_MINUS: op = OP_NEGATE; break; + case T_NOT: op = OP_NOT; break; + case T_DIV: op = OP_INVERT; break; + case T_BACKSLASH: op = OP_BACKSLASH; break; + case T_TILDE: op = OP_COMP; break; + case T_HASH: op = OP_CONTENT; break; + } + if (op) { + (void) getshiftexpr(); + addop(op); + return EXPR_RVALUE; + } + rescantoken(); + type = getreference(); + switch (gettoken()) { + case T_POWER: op = OP_POWER; break; + case T_LEFTSHIFT: op = OP_LEFTSHIFT; break; + case T_RIGHTSHIFT: op = OP_RIGHTSHIFT; break; + default: + rescantoken(); + return type; + } + if (islvalue(type)) + addop(OP_GETVALUE); + (void) getshiftexpr(); + addop(op); + return EXPR_RVALUE; } @@ -1984,33 +1984,33 @@ getshiftexpr(void) S_FUNC int getreference(void) { - int type; + int type; - switch(gettoken()) { - case T_ANDAND: - scanerror(T_NULL, "&& used as prefix operator"); - /*FALLTHRU*/ - case T_AND: - type = getreference(); - addop(OP_PTR); - type = EXPR_RVALUE; - break; - case T_MULT: - (void) getreference(); - addop(OP_DEREF); - type = 0; - break; - case T_POWER: /* '**' or '^' */ - (void) getreference(); - addop(OP_DEREF); - addop(OP_DEREF); - type = 0; - break; - default: - rescantoken(); - type = getincdecexpr(); - } - return type; + switch(gettoken()) { + case T_ANDAND: + scanerror(T_NULL, "&& used as prefix operator"); + /*FALLTHRU*/ + case T_AND: + type = getreference(); + addop(OP_PTR); + type = EXPR_RVALUE; + break; + case T_MULT: + (void) getreference(); + addop(OP_DEREF); + type = 0; + break; + case T_POWER: /* '**' or '^' */ + (void) getreference(); + addop(OP_DEREF); + addop(OP_DEREF); + type = 0; + break; + default: + rescantoken(); + type = getincdecexpr(); + } + return type; } @@ -2021,43 +2021,43 @@ getreference(void) S_FUNC int getincdecexpr(void) { - int type; - int tok; + int type; + int tok; - type = getterm(); - tok = gettoken(); - if (tok == T_PLUSPLUS || tok == T_MINUSMINUS) { - if (isrvalue(type)) - scanerror(T_NULL, "Bad ++ usage"); - writeindexop(); - if (tok == T_PLUSPLUS) - addop(OP_POSTINC); - else - addop(OP_POSTDEC); - for (;;) { - tok = gettoken(); - switch(tok) { - case T_PLUSPLUS: - addop(OP_PREINC); - continue; - case T_MINUSMINUS: - addop(OP_PREDEC); - continue; - default: - addop(OP_POP); - break; - } - break; - } - type = EXPR_RVALUE | EXPR_ASSIGN; - } - if (tok == T_NOT) { - addopfunction(OP_CALL, getbuiltinfunc("fact"), 1); - tok = gettoken(); - type = EXPR_RVALUE; - } - rescantoken(); - return type; + type = getterm(); + tok = gettoken(); + if (tok == T_PLUSPLUS || tok == T_MINUSMINUS) { + if (isrvalue(type)) + scanerror(T_NULL, "Bad ++ usage"); + writeindexop(); + if (tok == T_PLUSPLUS) + addop(OP_POSTINC); + else + addop(OP_POSTDEC); + for (;;) { + tok = gettoken(); + switch(tok) { + case T_PLUSPLUS: + addop(OP_PREINC); + continue; + case T_MINUSMINUS: + addop(OP_PREDEC); + continue; + default: + addop(OP_POP); + break; + } + break; + } + type = EXPR_RVALUE | EXPR_ASSIGN; + } + if (tok == T_NOT) { + addopfunction(OP_CALL, getbuiltinfunc("fact"), 1); + tok = gettoken(); + type = EXPR_RVALUE; + } + rescantoken(); + return type; } @@ -2065,169 +2065,169 @@ getincdecexpr(void) * Get a single term. * Flags indicating the type of value found are returned. * term = lvalue - * | lvalue '[' assignment ']' - * | lvalue '++' - * | lvalue '--' - * | real_number - * | imaginary_number - * | '.' - * | string - * | '(' assignment ')' - * | function [ '(' [assignment [',' assignment] ] ')' ] - * | '!' term + * | lvalue '[' assignment ']' + * | lvalue '++' + * | lvalue '--' + * | real_number + * | imaginary_number + * | '.' + * | string + * | '(' assignment ')' + * | function [ '(' [assignment [',' assignment] ] ')' ] + * | '!' term */ S_FUNC int getterm(void) { - int type; /* type of term found */ - int oldmode; + int type; /* type of term found */ + int oldmode; - type = 0; - switch (gettoken()) { - case T_NUMBER: - addopone(OP_NUMBER, tokennumber()); - type = (EXPR_RVALUE | EXPR_CONST); - break; + type = 0; + switch (gettoken()) { + case T_NUMBER: + addopone(OP_NUMBER, tokennumber()); + type = (EXPR_RVALUE | EXPR_CONST); + break; - case T_IMAGINARY: - addopone(OP_IMAGINARY, tokennumber()); - type = (EXPR_RVALUE | EXPR_CONST); - break; + case T_IMAGINARY: + addopone(OP_IMAGINARY, tokennumber()); + type = (EXPR_RVALUE | EXPR_CONST); + break; - case T_OLDVALUE: - addop(OP_OLDVALUE); - type = 0; - break; + case T_OLDVALUE: + addop(OP_OLDVALUE); + type = 0; + break; - case T_STRING: - addopone(OP_STRING, tokenstring()); - type = EXPR_RVALUE; - break; + case T_STRING: + addopone(OP_STRING, tokenstring()); + type = EXPR_RVALUE; + break; - case T_PLUSPLUS: - if (isrvalue(getterm())) - scanerror(T_NULL, "Bad ++ usage"); - writeindexop(); - addop(OP_PREINC); - type = EXPR_ASSIGN; - break; + case T_PLUSPLUS: + if (isrvalue(getterm())) + scanerror(T_NULL, "Bad ++ usage"); + writeindexop(); + addop(OP_PREINC); + type = EXPR_ASSIGN; + break; - case T_MINUSMINUS: - if (isrvalue(getterm())) - scanerror(T_NULL, "Bad -- usage"); - writeindexop(); - addop(OP_PREDEC); - type = EXPR_ASSIGN; - break; + case T_MINUSMINUS: + if (isrvalue(getterm())) + scanerror(T_NULL, "Bad -- usage"); + writeindexop(); + addop(OP_PREDEC); + type = EXPR_ASSIGN; + break; - case T_LEFTPAREN: - oldmode = tokenmode(TM_DEFAULT); - type = getexprlist(); - if (gettoken() != T_RIGHTPAREN) - scanerror(T_SEMICOLON, - "Missing right parenthesis"); - (void) tokenmode(oldmode); - break; + case T_LEFTPAREN: + oldmode = tokenmode(TM_DEFAULT); + type = getexprlist(); + if (gettoken() != T_RIGHTPAREN) + scanerror(T_SEMICOLON, + "Missing right parenthesis"); + (void) tokenmode(oldmode); + break; - case T_MAT: - getonematrix(SYM_UNDEFINED); - type = EXPR_ASSIGN; - break; + case T_MAT: + getonematrix(SYM_UNDEFINED); + type = EXPR_ASSIGN; + break; - case T_OBJ: - getobjdeclaration(SYM_UNDEFINED); - type = EXPR_ASSIGN; - break; + case T_OBJ: + getobjdeclaration(SYM_UNDEFINED); + type = EXPR_ASSIGN; + break; - case T_SYMBOL: - rescantoken(); - type = getidexpr(true, 0); - break; + case T_SYMBOL: + rescantoken(); + type = getidexpr(true, 0); + break; - case T_MULT: - (void) getterm(); - addop(OP_DEREF); - type = 0; - break; + case T_MULT: + (void) getterm(); + addop(OP_DEREF); + type = 0; + break; - case T_POWER: /* '**' or '^' */ - (void) getterm(); - addop(OP_DEREF); - addop(OP_DEREF); - type = 0; - break; + case T_POWER: /* '**' or '^' */ + (void) getterm(); + addop(OP_DEREF); + addop(OP_DEREF); + type = 0; + break; - case T_GLOBAL: - if (gettoken() != T_SYMBOL) { - scanerror(T_NULL, - "No identifier after global specifier"); - break; - } - rescantoken(); - type = getidexpr(true, T_GLOBAL); - break; + case T_GLOBAL: + if (gettoken() != T_SYMBOL) { + scanerror(T_NULL, + "No identifier after global specifier"); + break; + } + rescantoken(); + type = getidexpr(true, T_GLOBAL); + break; - case T_LOCAL: - if (gettoken() != T_SYMBOL) { - scanerror(T_NULL, - "No identifier after local specifier"); - break; - } - rescantoken(); - type = getidexpr(true, T_LOCAL); - break; + case T_LOCAL: + if (gettoken() != T_SYMBOL) { + scanerror(T_NULL, + "No identifier after local specifier"); + break; + } + rescantoken(); + type = getidexpr(true, T_LOCAL); + break; - case T_STATIC: - if (gettoken() != T_SYMBOL) { - scanerror(T_NULL, - "No identifier after static specifier"); - break; - } - rescantoken(); - type = getidexpr(true, T_STATIC); - break; + case T_STATIC: + if (gettoken() != T_SYMBOL) { + scanerror(T_NULL, + "No identifier after static specifier"); + break; + } + rescantoken(); + type = getidexpr(true, T_STATIC); + break; - case T_LEFTBRACKET: - scanerror(T_NULL, "Left bracket with no preceding lvalue"); - break; + case T_LEFTBRACKET: + scanerror(T_NULL, "Left bracket with no preceding lvalue"); + break; - case T_PERIOD: - scanerror(T_NULL, "Period with no preceding lvalue"); - break; + case T_PERIOD: + scanerror(T_NULL, "Period with no preceding lvalue"); + break; - default: - if (iskeyword(type)) { - scanerror(T_NULL, - "Expression contains reserved keyword"); - break; - } - rescantoken(); - scanerror(T_COMMA, "Missing expression"); - } - if (type == 0) { - for (;;) { - switch (gettoken()) { - case T_LEFTBRACKET: - rescantoken(); - getmatargs(); - type = 0; - break; - case T_PERIOD: - getelement(); - type = 0; - break; - case T_LEFTPAREN: - scanerror(T_NULL, - "Function calls not allowed " - "as expressions"); - /*FALLTHRU*/ - default: - rescantoken(); - return type; - } - } - } - return type; + default: + if (iskeyword(type)) { + scanerror(T_NULL, + "Expression contains reserved keyword"); + break; + } + rescantoken(); + scanerror(T_COMMA, "Missing expression"); + } + if (type == 0) { + for (;;) { + switch (gettoken()) { + case T_LEFTBRACKET: + rescantoken(); + getmatargs(); + type = 0; + break; + case T_PERIOD: + getelement(); + type = 0; + break; + case T_LEFTPAREN: + scanerror(T_NULL, + "Function calls not allowed " + "as expressions"); + /*FALLTHRU*/ + default: + rescantoken(); + return type; + } + } + } + return type; } @@ -2240,59 +2240,59 @@ getterm(void) S_FUNC int getidexpr(bool okmat, int autodef) { - int type; - char name[SYMBOLSIZE+1]; /* symbol name */ - int oldmode; + int type; + char name[SYMBOLSIZE+1]; /* symbol name */ + int oldmode; - type = 0; - if (!getid(name)) - return type; - switch (gettoken()) { - case T_LEFTPAREN: - oldmode = tokenmode(TM_DEFAULT); - getcallargs(name); - (void) tokenmode(oldmode); - type = 0; - break; - case T_ASSIGN: - if (autodef != T_GLOBAL && autodef != T_LOCAL && - autodef != T_STATIC) - autodef = 1; - /*FALLTHRU*/ - default: - rescantoken(); - usesymbol(name, autodef); - } - /* - * Now collect as many element references and matrix index operations - * as there are following the id. - */ - for (;;) { - switch (gettoken()) { - case T_LEFTBRACKET: - rescantoken(); - if (!okmat) - return type; - getmatargs(); - type = 0; - break; - case T_ARROW: - addop(OP_DEREF); - /*FALLTHRU*/ - case T_PERIOD: - getelement(); - type = 0; - break; - case T_LEFTPAREN: - scanerror(T_NULL, - "Function calls not allowed " - "as expressions"); - /*FALLTHRU*/ - default: - rescantoken(); - return type; - } - } + type = 0; + if (!getid(name)) + return type; + switch (gettoken()) { + case T_LEFTPAREN: + oldmode = tokenmode(TM_DEFAULT); + getcallargs(name); + (void) tokenmode(oldmode); + type = 0; + break; + case T_ASSIGN: + if (autodef != T_GLOBAL && autodef != T_LOCAL && + autodef != T_STATIC) + autodef = 1; + /*FALLTHRU*/ + default: + rescantoken(); + usesymbol(name, autodef); + } + /* + * Now collect as many element references and matrix index operations + * as there are following the id. + */ + for (;;) { + switch (gettoken()) { + case T_LEFTBRACKET: + rescantoken(); + if (!okmat) + return type; + getmatargs(); + type = 0; + break; + case T_ARROW: + addop(OP_DEREF); + /*FALLTHRU*/ + case T_PERIOD: + getelement(); + type = 0; + break; + case T_LEFTPAREN: + scanerror(T_NULL, + "Function calls not allowed " + "as expressions"); + /*FALLTHRU*/ + default: + rescantoken(); + return type; + } + } } @@ -2300,38 +2300,38 @@ getidexpr(bool okmat, int autodef) * getsymvalue - return the VALUE of a symbol * * given: - * name symbol name - * v_p pointer to value return + * name symbol name + * v_p pointer to value return * * returns: - * symbol type found: + * symbol type found: * - * SYM_UNDEFINED no such symbol - * SYM_GLOBAL global symbol found + * SYM_UNDEFINED no such symbol + * SYM_GLOBAL global symbol found * * NOTE: This is a special hack to allow some special code in getfilename() - * to get the value of a symbol. It should NOT be used in the - * general op code generation / calc code parsing case. + * to get the value of a symbol. It should NOT be used in the + * general op code generation / calc code parsing case. */ S_FUNC int getsymvalue(char *name, VALUE *v_p) { - GLOBAL *g_ret; /* global return from findglobal() */ + GLOBAL *g_ret; /* global return from findglobal() */ - /* firewall */ - if (name == NULL || v_p == NULL) { - return SYM_UNDEFINED; - } + /* firewall */ + if (name == NULL || v_p == NULL) { + return SYM_UNDEFINED; + } - /* look for a global */ - g_ret = findglobal(name); - if (g_ret != NULL) { - *v_p = g_ret->g_value; - return SYM_GLOBAL; - } + /* look for a global */ + g_ret = findglobal(name); + if (g_ret != NULL) { + *v_p = g_ret->g_value; + return SYM_GLOBAL; + } - /* no such symbol */ - return SYM_UNDEFINED; + /* no such symbol */ + return SYM_UNDEFINED; } @@ -2342,86 +2342,86 @@ getsymvalue(char *name, VALUE *v_p) * Returns true if the filename was successfully parsed. * * given: - * name filename to read - * namelen length of filename buffer including NUL byte - * once non-NULL => set to true of -once read + * name filename to read + * namelen length of filename buffer including NUL byte + * once non-NULL => set to true of -once read */ S_FUNC int getfilename(char *name, size_t namelen, bool *once) { - STRING *s; - char *symstr; /* symbol string */ - VALUE val; /* value of the symbol */ - int i; + STRING *s; + char *symstr; /* symbol string */ + VALUE val; /* value of the symbol */ + int i; - (void) tokenmode(TM_NEWLINES | TM_ALLSYMS); - for (i = 2; i > 0; i--) { - switch (gettoken()) { - case T_STRING: + (void) tokenmode(TM_NEWLINES | TM_ALLSYMS); + for (i = 2; i > 0; i--) { + switch (gettoken()) { + case T_STRING: - /* use the value of the literal string */ - s = findstring(tokenstring()); - strlcpy(name, s->s_str, namelen); - sfree(s); - break; + /* use the value of the literal string */ + s = findstring(tokenstring()); + strlcpy(name, s->s_str, namelen); + sfree(s); + break; - case T_SYMBOL: + case T_SYMBOL: - /* get the symbol name */ - symstr = tokensymbol(); + /* get the symbol name */ + symstr = tokensymbol(); - /* - * special hack - symbols starting with $ are - * treated as a global variable - * instead of a literal string. - */ - if (symstr[0] == '$') { - ++symstr; - if (getsymvalue(symstr, &val)) { - if (val.v_type == V_STR) { - /* use symbol VALUE string */ - symstr = val.v_str->s_str; - if (symstr == NULL) { - math_error( - "string value pointer is NULL!!"); - not_reached(); - } - } else { - math_error( - "a filename variable must be a string"); - not_reached(); - } - } else { - math_error("no such global variable"); - not_reached(); - } - } + /* + * special hack - symbols starting with $ are + * treated as a global variable + * instead of a literal string. + */ + if (symstr[0] == '$') { + ++symstr; + if (getsymvalue(symstr, &val)) { + if (val.v_type == V_STR) { + /* use symbol VALUE string */ + symstr = val.v_str->s_str; + if (symstr == NULL) { + math_error( + "string value pointer is NULL!!"); + not_reached(); + } + } else { + math_error( + "a filename variable must be a string"); + not_reached(); + } + } else { + math_error("no such global variable"); + not_reached(); + } + } - /* return symbol name or value of global var string */ - strlcpy(name, symstr, namelen); - break; + /* return symbol name or value of global var string */ + strlcpy(name, symstr, namelen); + break; - case T_NEWLINE: + case T_NEWLINE: - /* found newline */ - rescantoken(); - return 1; + /* found newline */ + rescantoken(); + return 1; - default: + default: - /* found something unexpected */ - rescantoken(); - return -1; - } + /* found something unexpected */ + rescantoken(); + return -1; + } - /* deal with -once */ - if (i == 2 && once != NULL) { - if ((*once = !strcmp(name, "-once"))) - continue; - } - break; - } - return 0; + /* deal with -once */ + if (i == 2 && once != NULL) { + if ((*once = !strcmp(name, "-once"))) + continue; + } + break; + } + return 0; } @@ -2431,67 +2431,67 @@ getfilename(char *name, size_t namelen, bool *once) S_FUNC void getshowstatement(void) { - char name[5]; - long arg, index; + char name[5]; + long arg, index; - switch (gettoken()) { - case T_SYMBOL: - strlcpy(name, tokensymbol(), sizeof(name)); - name[4] = '\0'; - /* Yuck! */ - arg = stringindex("buil\000" - "real\000" - "func\000" - "objf\000" - "conf\000" - "objt\000" - "file\000" - "size\000" - "erro\000" - "cust\000" - "bloc\000" - "cons\000" - "glob\000" - "stat\000" - "numb\000" - "redc\000" - "stri\000" - "lite\000" - "opco\000", name); - break; - case T_GLOBAL: - arg = 13; break; - case T_STATIC: - arg = 14; break; - default: - printf("SHOW command to be followed by at least "); - printf("four letters of one of:\n"); - printf("\tblocks, builtin, config, constants, "); - printf("custom, errors, files, functions,\n"); - printf("\tglobaltypes, objfunctions, objtypes, " - "opcodes, sizes, "); - printf("realglobals,\n"); - printf("\tstatics, numbers, redcdata, " - "strings, literals\n"); - rescantoken(); - return; + switch (gettoken()) { + case T_SYMBOL: + strlcpy(name, tokensymbol(), sizeof(name)); + name[4] = '\0'; + /* Yuck! */ + arg = stringindex("buil\000" + "real\000" + "func\000" + "objf\000" + "conf\000" + "objt\000" + "file\000" + "size\000" + "erro\000" + "cust\000" + "bloc\000" + "cons\000" + "glob\000" + "stat\000" + "numb\000" + "redc\000" + "stri\000" + "lite\000" + "opco\000", name); + break; + case T_GLOBAL: + arg = 13; break; + case T_STATIC: + arg = 14; break; + default: + printf("SHOW command to be followed by at least "); + printf("four letters of one of:\n"); + printf("\tblocks, builtin, config, constants, "); + printf("custom, errors, files, functions,\n"); + printf("\tglobaltypes, objfunctions, objtypes, " + "opcodes, sizes, "); + printf("realglobals,\n"); + printf("\tstatics, numbers, redcdata, " + "strings, literals\n"); + rescantoken(); + return; - } - if (arg == 19) { - if (gettoken() != T_SYMBOL) { - rescantoken(); - scanerror(T_SEMICOLON, - "Function name expected for show statement"); - return; - } - index = adduserfunc(tokensymbol()); - addopone(OP_SHOW, index + 19); - return; - } - if (arg > 0) - addopone(OP_SHOW, arg); - else - warning("Unknown parameter for show statement"); + } + if (arg == 19) { + if (gettoken() != T_SYMBOL) { + rescantoken(); + scanerror(T_SEMICOLON, + "Function name expected for show statement"); + return; + } + index = adduserfunc(tokensymbol()); + addopone(OP_SHOW, index + 19); + return; + } + if (arg > 0) + addopone(OP_SHOW, arg); + else + warning("Unknown parameter for show statement"); } @@ -2502,58 +2502,58 @@ getshowstatement(void) S_FUNC void getmatargs(void) { - int dim; + int dim; - if (gettoken() != T_LEFTBRACKET) { - scanerror(T_NULL, "Matrix indexing expected"); - return; - } - /* - * Parse all levels of the array reference - * Look for the 'fast index' first. - */ - if (gettoken() == T_LEFTBRACKET) { - (void) getopassignment(); - if ((gettoken() != T_RIGHTBRACKET) || - (gettoken() != T_RIGHTBRACKET)) { - scanerror(T_NULL, "Bad fast index usage"); - return; - } - addop(OP_FIADDR); - return; - } - rescantoken(); - /* - * Normal indexing with the indexes separated by commas. - * Initialize the flag in the opcode to assume that the array - * element will only be referenced for reading. If the parser - * finds that the element will be referenced for writing, then - * it will call writeindexop to change the flag in the opcode. - */ - dim = 0; - if (gettoken() == T_RIGHTBRACKET) { - addoptwo(OP_INDEXADDR, (long) dim, (long) false); - return; - } - rescantoken(); - for (;;) { - ++dim; - (void) getopassignment(); - switch (gettoken()) { - case T_RIGHTBRACKET: - addoptwo(OP_INDEXADDR, (long) dim, - (long) false); - return; - case T_COMMA: - break; - default: - rescantoken(); - scanerror(T_NULL, - "Missing right bracket in " - "array reference"); - return; - } - } + if (gettoken() != T_LEFTBRACKET) { + scanerror(T_NULL, "Matrix indexing expected"); + return; + } + /* + * Parse all levels of the array reference + * Look for the 'fast index' first. + */ + if (gettoken() == T_LEFTBRACKET) { + (void) getopassignment(); + if ((gettoken() != T_RIGHTBRACKET) || + (gettoken() != T_RIGHTBRACKET)) { + scanerror(T_NULL, "Bad fast index usage"); + return; + } + addop(OP_FIADDR); + return; + } + rescantoken(); + /* + * Normal indexing with the indexes separated by commas. + * Initialize the flag in the opcode to assume that the array + * element will only be referenced for reading. If the parser + * finds that the element will be referenced for writing, then + * it will call writeindexop to change the flag in the opcode. + */ + dim = 0; + if (gettoken() == T_RIGHTBRACKET) { + addoptwo(OP_INDEXADDR, (long) dim, (long) false); + return; + } + rescantoken(); + for (;;) { + ++dim; + (void) getopassignment(); + switch (gettoken()) { + case T_RIGHTBRACKET: + addoptwo(OP_INDEXADDR, (long) dim, + (long) false); + return; + case T_COMMA: + break; + default: + rescantoken(); + scanerror(T_NULL, + "Missing right bracket in " + "array reference"); + return; + } + } } @@ -2564,17 +2564,17 @@ getmatargs(void) S_FUNC void getelement(void) { - long index; - char name[SYMBOLSIZE+1]; + long index; + char name[SYMBOLSIZE+1]; - if (!getid(name)) - return; - index = findelement(name); - if (index < 0) { - scanerror(T_NULL, "Element \"%s\" is undefined", name); - return; - } - addopone(OP_ELEMADDR, index); + if (!getid(name)) + return; + index = findelement(name); + if (index < 0) { + scanerror(T_NULL, "Element \"%s\" is undefined", name); + return; + } + addopone(OP_ELEMADDR, index); } @@ -2585,23 +2585,23 @@ getelement(void) S_FUNC bool getid(char *buf) { - int type; + int type; - type = gettoken(); - if (iskeyword(type)) { - scanerror(T_NULL, "Reserved keyword used as symbol name"); - type = T_SYMBOL; - *buf = '\0'; - return false; - } - if (type != T_SYMBOL) { - rescantoken(); - scanerror(T_NULL, "Symbol name expected"); - *buf = '\0'; - return false; - } - strlcpy(buf, tokensymbol(), SYMBOLSIZE+1); - return true; + type = gettoken(); + if (iskeyword(type)) { + scanerror(T_NULL, "Reserved keyword used as symbol name"); + type = T_SYMBOL; + *buf = '\0'; + return false; + } + if (type != T_SYMBOL) { + rescantoken(); + scanerror(T_NULL, "Symbol name expected"); + *buf = '\0'; + return false; + } + strlcpy(buf, tokensymbol(), SYMBOLSIZE+1); + return true; } @@ -2616,53 +2616,53 @@ getid(char *buf) S_FUNC void definesymbol(char *name, int symtype) { - switch (symboltype(name)) { - case SYM_STATIC: - if (symtype == SYM_GLOBAL || symtype == SYM_STATIC) - endscope(name, symtype == SYM_GLOBAL); - break; - case SYM_GLOBAL: - if (symtype == SYM_GLOBAL && conf->redecl_warn) { - warning("redeclaration of global \"%s\"", - name); - return; - } - break; + switch (symboltype(name)) { + case SYM_STATIC: + if (symtype == SYM_GLOBAL || symtype == SYM_STATIC) + endscope(name, symtype == SYM_GLOBAL); + break; + case SYM_GLOBAL: + if (symtype == SYM_GLOBAL && conf->redecl_warn) { + warning("redeclaration of global \"%s\"", + name); + return; + } + break; - case SYM_LOCAL: - if (symtype == SYM_LOCAL && conf->redecl_warn) { - warning("redeclaration of local \"%s\"", - name); - return; - } - if (symtype == SYM_GLOBAL && conf->dupvar_warn) { - warning("both local and global \"%s\" defined", name); - break; - } - if (conf->dupvar_warn) { - warning("both local and static \"%s\" defined", name); - } - break; - case SYM_PARAM: - if (symtype == SYM_LOCAL && conf->dupvar_warn) { - warning("both local and parameter \"%s\" defined", - name); - break; - } - if (symtype == SYM_GLOBAL && conf->dupvar_warn) { - warning("both global and parameter \"%s\" defined", - name); - break; - } - if (conf->dupvar_warn) { - warning("both static and parameter \"%s\" defined", - name); - } - } - if (symtype == SYM_LOCAL) - (void) addlocal(name); - else - (void) addglobal(name, (symtype == SYM_STATIC)); + case SYM_LOCAL: + if (symtype == SYM_LOCAL && conf->redecl_warn) { + warning("redeclaration of local \"%s\"", + name); + return; + } + if (symtype == SYM_GLOBAL && conf->dupvar_warn) { + warning("both local and global \"%s\" defined", name); + break; + } + if (conf->dupvar_warn) { + warning("both local and static \"%s\" defined", name); + } + break; + case SYM_PARAM: + if (symtype == SYM_LOCAL && conf->dupvar_warn) { + warning("both local and parameter \"%s\" defined", + name); + break; + } + if (symtype == SYM_GLOBAL && conf->dupvar_warn) { + warning("both global and parameter \"%s\" defined", + name); + break; + } + if (conf->dupvar_warn) { + warning("both static and parameter \"%s\" defined", + name); + } + } + if (symtype == SYM_LOCAL) + (void) addlocal(name); + else + (void) addglobal(name, (symtype == SYM_STATIC)); } @@ -2673,56 +2673,56 @@ definesymbol(char *name, int symtype) * if it is not yet known. * * given: - * name symbol name to be checked - * autodef 1 => define if symbol is not known - * T_GLOBAL => get global, define if necessary + * name symbol name to be checked + * autodef 1 => define if symbol is not known + * T_GLOBAL => get global, define if necessary */ S_FUNC void usesymbol(char *name, int autodef) { - int type; + int type; - type = symboltype(name); - if (autodef == T_GLOBAL) { - if (type == SYM_GLOBAL) { - warning("Unnecessary global specifier"); - } - addopptr(OP_GLOBALADDR, (char *) addglobal(name, false)); - return; - } - if (autodef == T_STATIC) { - addopptr(OP_GLOBALADDR, (char *) addglobal(name, true)); - return; - } - if (autodef == T_LOCAL) { - if (type == SYM_LOCAL) { - warning("Unnecessary local specifier"); - } - addopone(OP_LOCALADDR, addlocal(name)); - return; - } - switch (type) { - case SYM_LOCAL: - addopone(OP_LOCALADDR, (long) findlocal(name)); - return; - case SYM_PARAM: - addopone(OP_PARAMADDR, (long) findparam(name)); - return; - case SYM_GLOBAL: - case SYM_STATIC: - addopptr(OP_GLOBALADDR, (char *) findglobal(name)); - return; - } - /* - * The symbol is not yet defined. - * If we are at the top level and we are allowed to, then define it. - */ - if ((curfunc->f_name[0] != '*') || !autodef) { - scanerror(T_NULL, "\"%s\" is undefined", name); - return; - } - (void) addglobal(name, false); - addopptr(OP_GLOBALADDR, (char *) findglobal(name)); + type = symboltype(name); + if (autodef == T_GLOBAL) { + if (type == SYM_GLOBAL) { + warning("Unnecessary global specifier"); + } + addopptr(OP_GLOBALADDR, (char *) addglobal(name, false)); + return; + } + if (autodef == T_STATIC) { + addopptr(OP_GLOBALADDR, (char *) addglobal(name, true)); + return; + } + if (autodef == T_LOCAL) { + if (type == SYM_LOCAL) { + warning("Unnecessary local specifier"); + } + addopone(OP_LOCALADDR, addlocal(name)); + return; + } + switch (type) { + case SYM_LOCAL: + addopone(OP_LOCALADDR, (long) findlocal(name)); + return; + case SYM_PARAM: + addopone(OP_PARAMADDR, (long) findparam(name)); + return; + case SYM_GLOBAL: + case SYM_STATIC: + addopptr(OP_GLOBALADDR, (char *) findglobal(name)); + return; + } + /* + * The symbol is not yet defined. + * If we are at the top level and we are allowed to, then define it. + */ + if ((curfunc->f_name[0] != '*') || !autodef) { + scanerror(T_NULL, "\"%s\" is undefined", name); + return; + } + (void) addglobal(name, false); + addopptr(OP_GLOBALADDR, (char *) findglobal(name)); } @@ -2732,71 +2732,71 @@ usesymbol(char *name, int autodef) * callargs = [ [ '&' ] assignment [',' [ '&' ] assignment] ] ')'. * * given: - * name name of function + * name name of function */ S_FUNC void getcallargs(char *name) { - long index; /* function index */ - long op; /* opcode to add */ - int argcount; /* number of arguments */ - bool addrflag; + long index; /* function index */ + long op; /* opcode to add */ + int argcount; /* number of arguments */ + bool addrflag; - op = OP_CALL; - index = getbuiltinfunc(name); - if (index < 0) { - op = OP_USERCALL; - index = adduserfunc(name); - } - if (gettoken() == T_RIGHTPAREN) { - if (op == OP_CALL) - builtincheck(index, 0); - addopfunction(op, index, 0); - return; - } - rescantoken(); - argcount = 0; - for (;;) { - argcount++; - if (gettoken() == T_RIGHTPAREN) { - addop(OP_UNDEF); - if (op == OP_CALL) - builtincheck(index, argcount); - addopfunction(op, index, argcount); - return; - } - rescantoken(); - if (gettoken() == T_COMMA) { - addop(OP_UNDEF); - continue; - } - rescantoken(); - addrflag = (gettoken() == T_BACKQUOTE); - if (!addrflag) - rescantoken(); - (void) getopassignment(); - if (addrflag) { - writeindexop(); - } - if (!addrflag && (op != OP_CALL)) - addop(OP_GETVALUE); - if (!strcmp(name, "quomod") && argcount > 2) - writeindexop(); - switch (gettoken()) { - case T_RIGHTPAREN: - if (op == OP_CALL) - builtincheck(index, argcount); - addopfunction(op, index, argcount); - return; - case T_COMMA: - break; - default: - scanerror(T_SEMICOLON, - "Missing right parenthesis " - "in function call"); - return; - } - } + op = OP_CALL; + index = getbuiltinfunc(name); + if (index < 0) { + op = OP_USERCALL; + index = adduserfunc(name); + } + if (gettoken() == T_RIGHTPAREN) { + if (op == OP_CALL) + builtincheck(index, 0); + addopfunction(op, index, 0); + return; + } + rescantoken(); + argcount = 0; + for (;;) { + argcount++; + if (gettoken() == T_RIGHTPAREN) { + addop(OP_UNDEF); + if (op == OP_CALL) + builtincheck(index, argcount); + addopfunction(op, index, argcount); + return; + } + rescantoken(); + if (gettoken() == T_COMMA) { + addop(OP_UNDEF); + continue; + } + rescantoken(); + addrflag = (gettoken() == T_BACKQUOTE); + if (!addrflag) + rescantoken(); + (void) getopassignment(); + if (addrflag) { + writeindexop(); + } + if (!addrflag && (op != OP_CALL)) + addop(OP_GETVALUE); + if (!strcmp(name, "quomod") && argcount > 2) + writeindexop(); + switch (gettoken()) { + case T_RIGHTPAREN: + if (op == OP_CALL) + builtincheck(index, argcount); + addopfunction(op, index, argcount); + return; + case T_COMMA: + break; + default: + scanerror(T_SEMICOLON, + "Missing right parenthesis " + "in function call"); + return; + } + } } @@ -2806,36 +2806,36 @@ getcallargs(char *name) S_FUNC void do_changedir(void) { - char *p; - STRING *s; + char *p; + STRING *s; - /* look at the next token */ - (void) tokenmode(TM_NEWLINES | TM_ALLSYMS); + /* look at the next token */ + (void) tokenmode(TM_NEWLINES | TM_ALLSYMS); - /* determine the new directory */ - s = NULL; - switch (gettoken()) { - case T_STRING: - s = findstring(tokenstring()); - p = s->s_str; - break; - case T_SYMBOL: - p = tokensymbol(); - break; - default: - p = home; - } + /* determine the new directory */ + s = NULL; + switch (gettoken()) { + case T_STRING: + s = findstring(tokenstring()); + p = s->s_str; + break; + case T_SYMBOL: + p = tokensymbol(); + break; + default: + p = home; + } - if (p == NULL) { - fprintf(stderr, "Cannot determine HOME directory\n"); - } + if (p == NULL) { + fprintf(stderr, "Cannot determine HOME directory\n"); + } - /* change to that directory */ - if (chdir(p)) { - perror(p); - } - if (s != NULL) - sfree(s); + /* change to that directory */ + if (chdir(p)) { + perror(p); + } + if (s != NULL) + sfree(s); } diff --git a/comfunc.c b/comfunc.c index d7ae7c3..5747225 100644 --- a/comfunc.c +++ b/comfunc.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:13 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:13 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -31,7 +31,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* @@ -52,95 +52,95 @@ COMPLEX _ctwo_ = { &_q2_, &_q0_, 1 }; * Compute the result of raising a complex number to an integer power. * * given: - * c complex number to be raised - * q power to raise it to + * c complex number to be raised + * q power to raise it to */ COMPLEX * c_powi(COMPLEX *c, NUMBER *q) { - COMPLEX *tmp, *res; /* temporary values */ - long power; /* power to raise to */ - FULL bit; /* current bit value */ - int sign; + COMPLEX *tmp, *res; /* temporary values */ + long power; /* power to raise to */ + FULL bit; /* current bit value */ + int sign; - if (qisfrac(q)) { - math_error("Raising number to non-integral power"); - not_reached(); - } - if (zge31b(q->num)) { - math_error("Raising number to very large power"); - not_reached(); - } - power = ztolong(q->num); - if (ciszero(c) && (power == 0)) { - math_error("Raising zero to zeroth power"); - not_reached(); - } - sign = 1; - if (qisneg(q)) - sign = -1; - /* - * Handle some low powers specially - */ - if (power <= 4) { - switch ((int) (power * sign)) { - case 0: - return clink(&_cone_); - case 1: - return clink(c); - case -1: - return c_inv(c); - case 2: - return c_square(c); - case -2: - tmp = c_square(c); - res = c_inv(tmp); - comfree(tmp); - return res; - case 3: - tmp = c_square(c); - res = c_mul(c, tmp); - comfree(tmp); - return res; - case 4: - tmp = c_square(c); - res = c_square(tmp); - comfree(tmp); - return res; - } - } - /* - * Compute the power by squaring and multiplying. - * This uses the left to right method of power raising. - */ - bit = TOPFULL; - while ((bit & power) == 0) - bit >>= 1L; - bit >>= 1L; - res = c_square(c); - if (bit & power) { - tmp = c_mul(res, c); - comfree(res); - res = tmp; - } - bit >>= 1L; - while (bit) { - tmp = c_square(res); - comfree(res); - res = tmp; - if (bit & power) { - tmp = c_mul(res, c); - comfree(res); - res = tmp; - } - bit >>= 1L; - } - if (sign < 0) { - tmp = c_inv(res); - comfree(res); - res = tmp; - } - return res; + if (qisfrac(q)) { + math_error("Raising number to non-integral power"); + not_reached(); + } + if (zge31b(q->num)) { + math_error("Raising number to very large power"); + not_reached(); + } + power = ztolong(q->num); + if (ciszero(c) && (power == 0)) { + math_error("Raising zero to zeroth power"); + not_reached(); + } + sign = 1; + if (qisneg(q)) + sign = -1; + /* + * Handle some low powers specially + */ + if (power <= 4) { + switch ((int) (power * sign)) { + case 0: + return clink(&_cone_); + case 1: + return clink(c); + case -1: + return c_inv(c); + case 2: + return c_square(c); + case -2: + tmp = c_square(c); + res = c_inv(tmp); + comfree(tmp); + return res; + case 3: + tmp = c_square(c); + res = c_mul(c, tmp); + comfree(tmp); + return res; + case 4: + tmp = c_square(c); + res = c_square(tmp); + comfree(tmp); + return res; + } + } + /* + * Compute the power by squaring and multiplying. + * This uses the left to right method of power raising. + */ + bit = TOPFULL; + while ((bit & power) == 0) + bit >>= 1L; + bit >>= 1L; + res = c_square(c); + if (bit & power) { + tmp = c_mul(res, c); + comfree(res); + res = tmp; + } + bit >>= 1L; + while (bit) { + tmp = c_square(res); + comfree(res); + res = tmp; + if (bit & power) { + tmp = c_mul(res, c); + comfree(res); + res = tmp; + } + bit >>= 1L; + } + if (sign < 0) { + tmp = c_inv(res); + comfree(res); + res = tmp; + } + return res; } @@ -151,225 +151,225 @@ c_powi(COMPLEX *c, NUMBER *q) COMPLEX * c_sqrt(COMPLEX *c, NUMBER *epsilon, long R) { - COMPLEX *r; - NUMBER *es, *aes, *bes, *u, *v, qtemp; - NUMBER *ntmp; - ZVALUE g, a, b, d, aa, cc; - ZVALUE tmp1, tmp2, tmp3, mul1, mul2; - long s1, s2, s3, up1, up2; - int imsign, sign; + COMPLEX *r; + NUMBER *es, *aes, *bes, *u, *v, qtemp; + NUMBER *ntmp; + ZVALUE g, a, b, d, aa, cc; + ZVALUE tmp1, tmp2, tmp3, mul1, mul2; + long s1, s2, s3, up1, up2; + int imsign, sign; - if (ciszero(c)) - return clink(c); - if (cisreal(c)) { - r = comalloc(); - if (!qisneg(c->real)) { - qfree(r->real); - r->real = qsqrt(c->real, epsilon, R); - return r; - } - ntmp = qneg(c->real); - qfree(r->imag); - r->imag = qsqrt(ntmp, epsilon, R); - qfree(ntmp); - return r; - } + if (ciszero(c)) + return clink(c); + if (cisreal(c)) { + r = comalloc(); + if (!qisneg(c->real)) { + qfree(r->real); + r->real = qsqrt(c->real, epsilon, R); + return r; + } + ntmp = qneg(c->real); + qfree(r->imag); + r->imag = qsqrt(ntmp, epsilon, R); + qfree(ntmp); + return r; + } - up1 = up2 = 0; - sign = (R & 64) != 0; - imsign = c->imag->num.sign; - es = qsquare(epsilon); - aes = qqdiv(c->real, es); - bes = qqdiv(c->imag, es); - qfree(es); - zgcd(aes->den, bes->den, &g); - zequo(bes->den, g, &tmp1); - zmul(aes->num, tmp1, &a); - zmul(aes->den, tmp1, &tmp2); - zshift(tmp2, 1, &d); - zfree(tmp1); - zfree(tmp2); - zequo(aes->den, g, &tmp1); - zmul(bes->num, tmp1, &b); - zfree(tmp1); - zfree(g); - qfree(aes); - qfree(bes); - zsquare(a, &tmp1); - zsquare(b, &tmp2); - zfree(b); - zadd(tmp1, tmp2, &tmp3); - zfree(tmp1); - zfree(tmp2); - if (R & 16) { - zshift(tmp3, 4, &tmp1); - zfree(tmp3); - zshift(a, 2, &aa); - zfree(a); - s1 = zsqrt(tmp1, &cc, 16); - zfree(tmp1); - zadd(cc, aa, &tmp1); - if (s1 == 0 && R & 32) { - zmul(tmp1, d, &tmp2); - zfree(tmp1); - s2 = zsqrt(tmp2, &tmp3, 16); - zfree(tmp2); - if (s2 == 0) { - aes = qalloc(); - zshift(d, 1, &tmp1); - zreduce(tmp3, tmp1, &aes->num, &aes->den); - zfree(tmp1); - zfree(tmp3); - zfree(aa); - zfree(cc); - zfree(d); - r = comalloc(); - qtemp = *aes; - qtemp.num.sign = sign; - qfree(r->real); - r->real = qmul(&qtemp, epsilon); - qfree(aes); - bes = qscale(r->real, 1); - qtemp = *bes; - qtemp.num.sign = sign ^ imsign; - qfree(r->imag); - r->imag = qqdiv(c->imag, &qtemp); - qfree(bes); - return r; - } - s3 = zquo(tmp3, d, &tmp1, s2 < 0); - } else { - s2 = zquo(tmp1, d, &tmp3, s1 ? (s1 < 0) : 16); - zfree(tmp1); - s3 = zsqrt(tmp3,&tmp1,(s1||s2) ? (s1<0 || s2<0) : 16); - } - zfree(tmp3); - zshift(tmp1, -1, &mul1); - if (*tmp1.v & 1) - up1 = s1 + s2 + s3; - else - up1 = -1; - zfree(tmp1); - zsub(cc, aa, &tmp1); - s2 = zquo(tmp1, d, &tmp2, s1 ? (s1 < 0) : 16); - zfree(tmp1); - s3 = zsqrt(tmp2, &tmp1, (s1 || s2) ? (s1 < 0 || s2 < 0) : 16); - zfree(tmp2); - zshift(tmp1, -1, &mul2); - if (*tmp1.v & 1) - up2 = s1 + s2 + s3; - else - up2 = -1; - zfree(tmp1); - zfree(aa); - } else { - s1 = zsqrt(tmp3, &cc, 0); - zfree(tmp3); - zadd(cc, a, &tmp1); - if (s1 == 0 && R & 32) { - zmul(tmp1, d, &tmp2); - zfree(tmp1); - s2 = zsqrt(tmp2, &tmp3, 0); - zfree(tmp2); - if (s2 == 0) { - aes = qalloc(); - zreduce(tmp3, d, &aes->num, &aes->den); - zfree(tmp3); - zfree(a); - zfree(cc); - zfree(d); - r = comalloc(); - qtemp = *aes; - qtemp.num.sign = sign; - qfree(r->real); - r->real = qmul(&qtemp, epsilon); - qfree(aes); - bes = qscale(r->real, 1); - qtemp = *bes; - qtemp.num.sign = sign ^ imsign; - qfree(r->imag); - r->imag = qqdiv(c->imag, &qtemp); - qfree(bes); - return r; - } - s3 = zquo(tmp3, d, &mul1, 0); - } else { - s2 = zquo(tmp1, d, &tmp3, 0); - zfree(tmp1); - s3 = zsqrt(tmp3, &mul1, 0); - } - up1 = (s1 + s2 + s3) ? 0 : -1; - zfree(tmp3); - zsub(cc, a, &tmp1); - s2 = zquo(tmp1, d, &tmp2, 0); - zfree(tmp1); - s3 = zsqrt(tmp2, &mul2, 0); - up2 = (s1 + s2 + s3) ? 0 : -1; - zfree(tmp2); - zfree(a); - } - zfree(cc); zfree(d); - if (up1 == 0) { - if (R & 8) - up1 = (long)((R ^ *mul1.v) & 1); - else - up1 = (R ^ epsilon->num.sign ^ sign) & 1; - if (R & 2) - up1 ^= epsilon->num.sign ^ sign; - if (R & 4) - up1 ^= epsilon->num.sign; - } - if (up2 == 0) { - if (R & 8) - up2 = (long)((R ^ *mul2.v) & 1); - else - up2 = (R ^ epsilon->num.sign ^ sign ^ imsign) & 1; - if (R & 2) - up2 ^= epsilon->num.sign ^ imsign ^ sign; - if (R & 4) - up2 ^= epsilon->num.sign; - } - if (up1 > 0) { - zadd(mul1, _one_, &tmp1); - zfree(mul1); - mul1 = tmp1; - } - if (up2 > 0) { - zadd(mul2, _one_, &tmp2); - zfree(mul2); - mul2 = tmp2; - } - if (ziszero(mul1)) { - u = qlink(&_qzero_); - } else { - mul1.sign = sign ^ epsilon->num.sign; - u = qalloc(); - zreduce(mul1, epsilon->den, &tmp2, &u->den); - zmul(tmp2, epsilon->num, &u->num); - zfree(tmp2); - } - zfree(mul1); - if (ziszero(mul2)) { - v = qlink(&_qzero_); - } else { - mul2.sign = imsign ^ sign ^ epsilon->num.sign; - v = qalloc(); - zreduce(mul2, epsilon->den, &tmp2, &v->den); - zmul(tmp2, epsilon->num, &v->num); - zfree(tmp2); - } - zfree(mul2); - if (qiszero(u) && qiszero(v)) { - qfree(u); - qfree(v); - return clink(&_czero_); - } - r = comalloc(); - qfree(r->real); - qfree(r->imag); - r->real = u; - r->imag = v; - return r; + up1 = up2 = 0; + sign = (R & 64) != 0; + imsign = c->imag->num.sign; + es = qsquare(epsilon); + aes = qqdiv(c->real, es); + bes = qqdiv(c->imag, es); + qfree(es); + zgcd(aes->den, bes->den, &g); + zequo(bes->den, g, &tmp1); + zmul(aes->num, tmp1, &a); + zmul(aes->den, tmp1, &tmp2); + zshift(tmp2, 1, &d); + zfree(tmp1); + zfree(tmp2); + zequo(aes->den, g, &tmp1); + zmul(bes->num, tmp1, &b); + zfree(tmp1); + zfree(g); + qfree(aes); + qfree(bes); + zsquare(a, &tmp1); + zsquare(b, &tmp2); + zfree(b); + zadd(tmp1, tmp2, &tmp3); + zfree(tmp1); + zfree(tmp2); + if (R & 16) { + zshift(tmp3, 4, &tmp1); + zfree(tmp3); + zshift(a, 2, &aa); + zfree(a); + s1 = zsqrt(tmp1, &cc, 16); + zfree(tmp1); + zadd(cc, aa, &tmp1); + if (s1 == 0 && R & 32) { + zmul(tmp1, d, &tmp2); + zfree(tmp1); + s2 = zsqrt(tmp2, &tmp3, 16); + zfree(tmp2); + if (s2 == 0) { + aes = qalloc(); + zshift(d, 1, &tmp1); + zreduce(tmp3, tmp1, &aes->num, &aes->den); + zfree(tmp1); + zfree(tmp3); + zfree(aa); + zfree(cc); + zfree(d); + r = comalloc(); + qtemp = *aes; + qtemp.num.sign = sign; + qfree(r->real); + r->real = qmul(&qtemp, epsilon); + qfree(aes); + bes = qscale(r->real, 1); + qtemp = *bes; + qtemp.num.sign = sign ^ imsign; + qfree(r->imag); + r->imag = qqdiv(c->imag, &qtemp); + qfree(bes); + return r; + } + s3 = zquo(tmp3, d, &tmp1, s2 < 0); + } else { + s2 = zquo(tmp1, d, &tmp3, s1 ? (s1 < 0) : 16); + zfree(tmp1); + s3 = zsqrt(tmp3,&tmp1,(s1||s2) ? (s1<0 || s2<0) : 16); + } + zfree(tmp3); + zshift(tmp1, -1, &mul1); + if (*tmp1.v & 1) + up1 = s1 + s2 + s3; + else + up1 = -1; + zfree(tmp1); + zsub(cc, aa, &tmp1); + s2 = zquo(tmp1, d, &tmp2, s1 ? (s1 < 0) : 16); + zfree(tmp1); + s3 = zsqrt(tmp2, &tmp1, (s1 || s2) ? (s1 < 0 || s2 < 0) : 16); + zfree(tmp2); + zshift(tmp1, -1, &mul2); + if (*tmp1.v & 1) + up2 = s1 + s2 + s3; + else + up2 = -1; + zfree(tmp1); + zfree(aa); + } else { + s1 = zsqrt(tmp3, &cc, 0); + zfree(tmp3); + zadd(cc, a, &tmp1); + if (s1 == 0 && R & 32) { + zmul(tmp1, d, &tmp2); + zfree(tmp1); + s2 = zsqrt(tmp2, &tmp3, 0); + zfree(tmp2); + if (s2 == 0) { + aes = qalloc(); + zreduce(tmp3, d, &aes->num, &aes->den); + zfree(tmp3); + zfree(a); + zfree(cc); + zfree(d); + r = comalloc(); + qtemp = *aes; + qtemp.num.sign = sign; + qfree(r->real); + r->real = qmul(&qtemp, epsilon); + qfree(aes); + bes = qscale(r->real, 1); + qtemp = *bes; + qtemp.num.sign = sign ^ imsign; + qfree(r->imag); + r->imag = qqdiv(c->imag, &qtemp); + qfree(bes); + return r; + } + s3 = zquo(tmp3, d, &mul1, 0); + } else { + s2 = zquo(tmp1, d, &tmp3, 0); + zfree(tmp1); + s3 = zsqrt(tmp3, &mul1, 0); + } + up1 = (s1 + s2 + s3) ? 0 : -1; + zfree(tmp3); + zsub(cc, a, &tmp1); + s2 = zquo(tmp1, d, &tmp2, 0); + zfree(tmp1); + s3 = zsqrt(tmp2, &mul2, 0); + up2 = (s1 + s2 + s3) ? 0 : -1; + zfree(tmp2); + zfree(a); + } + zfree(cc); zfree(d); + if (up1 == 0) { + if (R & 8) + up1 = (long)((R ^ *mul1.v) & 1); + else + up1 = (R ^ epsilon->num.sign ^ sign) & 1; + if (R & 2) + up1 ^= epsilon->num.sign ^ sign; + if (R & 4) + up1 ^= epsilon->num.sign; + } + if (up2 == 0) { + if (R & 8) + up2 = (long)((R ^ *mul2.v) & 1); + else + up2 = (R ^ epsilon->num.sign ^ sign ^ imsign) & 1; + if (R & 2) + up2 ^= epsilon->num.sign ^ imsign ^ sign; + if (R & 4) + up2 ^= epsilon->num.sign; + } + if (up1 > 0) { + zadd(mul1, _one_, &tmp1); + zfree(mul1); + mul1 = tmp1; + } + if (up2 > 0) { + zadd(mul2, _one_, &tmp2); + zfree(mul2); + mul2 = tmp2; + } + if (ziszero(mul1)) { + u = qlink(&_qzero_); + } else { + mul1.sign = sign ^ epsilon->num.sign; + u = qalloc(); + zreduce(mul1, epsilon->den, &tmp2, &u->den); + zmul(tmp2, epsilon->num, &u->num); + zfree(tmp2); + } + zfree(mul1); + if (ziszero(mul2)) { + v = qlink(&_qzero_); + } else { + mul2.sign = imsign ^ sign ^ epsilon->num.sign; + v = qalloc(); + zreduce(mul2, epsilon->den, &tmp2, &v->den); + zmul(tmp2, epsilon->num, &v->num); + zfree(tmp2); + } + zfree(mul2); + if (qiszero(u) && qiszero(v)) { + qfree(u); + qfree(v); + return clink(&_czero_); + } + r = comalloc(); + qfree(r->real); + qfree(r->imag); + r->real = u; + r->imag = v; + return r; } @@ -380,501 +380,501 @@ c_sqrt(COMPLEX *c, NUMBER *epsilon, long R) COMPLEX * c_root(COMPLEX *c, NUMBER *q, NUMBER *epsilon) { - COMPLEX *r; - NUMBER *a2pb2, *root, *tmp1, *tmp2, *epsilon2; - long n, m; + COMPLEX *r; + NUMBER *a2pb2, *root, *tmp1, *tmp2, *epsilon2; + long n, m; - if (qisneg(q) || qiszero(q) || qisfrac(q)) { - math_error("Taking bad root of complex number"); - not_reached(); - } - if (cisone(c) || qisone(q)) - return clink(c); - if (qistwo(q)) - return c_sqrt(c, epsilon, conf->triground); - if (cisreal(c) && !qisneg(c->real)) { - tmp1 = qroot(c->real, q, epsilon); - if (tmp1 == NULL) - return NULL; - r = comalloc(); - qfree(r->real); - r->real = tmp1; - return r; - } - /* - * Calculate the root using the formula: - * c_root(a + bi, n) = - * c_polar(qroot(a^2 + b^2, 2 * n), qatan2(b, a) / n). - */ - n = qilog2(epsilon); - epsilon2 = qbitvalue(n - 4); - tmp1 = qsquare(c->real); - tmp2 = qsquare(c->imag); - a2pb2 = qqadd(tmp1, tmp2); - qfree(tmp1); - qfree(tmp2); - tmp1 = qscale(q, 1L); - root = qroot(a2pb2, tmp1, epsilon2); - qfree(a2pb2); - qfree(tmp1); - qfree(epsilon2); - if (root == NULL) - return NULL; - m = qilog2(root); - if (m < n) { - qfree(root); - return clink(&_czero_); - } - epsilon2 = qbitvalue(n - m - 4); - tmp1 = qatan2(c->imag, c->real, epsilon2); - qfree(epsilon2); - tmp2 = qqdiv(tmp1, q); - qfree(tmp1); - r = c_polar(root, tmp2, epsilon); - qfree(root); - qfree(tmp2); - return r; + if (qisneg(q) || qiszero(q) || qisfrac(q)) { + math_error("Taking bad root of complex number"); + not_reached(); + } + if (cisone(c) || qisone(q)) + return clink(c); + if (qistwo(q)) + return c_sqrt(c, epsilon, conf->triground); + if (cisreal(c) && !qisneg(c->real)) { + tmp1 = qroot(c->real, q, epsilon); + if (tmp1 == NULL) + return NULL; + r = comalloc(); + qfree(r->real); + r->real = tmp1; + return r; + } + /* + * Calculate the root using the formula: + * c_root(a + bi, n) = + * c_polar(qroot(a^2 + b^2, 2 * n), qatan2(b, a) / n). + */ + n = qilog2(epsilon); + epsilon2 = qbitvalue(n - 4); + tmp1 = qsquare(c->real); + tmp2 = qsquare(c->imag); + a2pb2 = qqadd(tmp1, tmp2); + qfree(tmp1); + qfree(tmp2); + tmp1 = qscale(q, 1L); + root = qroot(a2pb2, tmp1, epsilon2); + qfree(a2pb2); + qfree(tmp1); + qfree(epsilon2); + if (root == NULL) + return NULL; + m = qilog2(root); + if (m < n) { + qfree(root); + return clink(&_czero_); + } + epsilon2 = qbitvalue(n - m - 4); + tmp1 = qatan2(c->imag, c->real, epsilon2); + qfree(epsilon2); + tmp2 = qqdiv(tmp1, q); + qfree(tmp1); + r = c_polar(root, tmp2, epsilon); + qfree(root); + qfree(tmp2); + return r; } /* * Calculate the complex exponential function to the desired accuracy. * We use the formula: - * exp(a + bi) = exp(a) * (cos(b) + i * sin(b)). + * exp(a + bi) = exp(a) * (cos(b) + i * sin(b)). */ COMPLEX * c_exp(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; - NUMBER *sin, *cos, *tmp1, *tmp2, *epsilon1; - long k, n; + COMPLEX *r; + NUMBER *sin, *cos, *tmp1, *tmp2, *epsilon1; + long k, n; - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon value for complex exp"); - not_reached(); - } - if (cisreal(c)) { - tmp1 = qexp(c->real, epsilon); - if (tmp1 == NULL) - return NULL; - r = comalloc(); - qfree(r->real); - r->real = qexp(c->real, epsilon); - return r; - } - n = qilog2(epsilon); - epsilon1 = qbitvalue(n - 2); - tmp1 = qexp(c->real, epsilon1); - qfree(epsilon1); - if (tmp1 == NULL) - return NULL; - if (qiszero(tmp1)) { - qfree(tmp1); - return clink(&_czero_); - } - k = qilog2(tmp1) + 1; - if (k < n) { - qfree(tmp1); - return clink(&_czero_); - } - qsincos(c->imag, k - n + 2, &sin, &cos); - tmp2 = qmul(tmp1, cos); - qfree(cos); - r = comalloc(); - qfree(r->real); - r->real = qmappr(tmp2, epsilon, conf->triground); - qfree(tmp2); - tmp2 = qmul(tmp1, sin); - qfree(tmp1); - qfree(sin); - qfree(r->imag); - r->imag = qmappr(tmp2, epsilon, conf->triground); - qfree(tmp2); - return r; + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon value for complex exp"); + not_reached(); + } + if (cisreal(c)) { + tmp1 = qexp(c->real, epsilon); + if (tmp1 == NULL) + return NULL; + r = comalloc(); + qfree(r->real); + r->real = qexp(c->real, epsilon); + return r; + } + n = qilog2(epsilon); + epsilon1 = qbitvalue(n - 2); + tmp1 = qexp(c->real, epsilon1); + qfree(epsilon1); + if (tmp1 == NULL) + return NULL; + if (qiszero(tmp1)) { + qfree(tmp1); + return clink(&_czero_); + } + k = qilog2(tmp1) + 1; + if (k < n) { + qfree(tmp1); + return clink(&_czero_); + } + qsincos(c->imag, k - n + 2, &sin, &cos); + tmp2 = qmul(tmp1, cos); + qfree(cos); + r = comalloc(); + qfree(r->real); + r->real = qmappr(tmp2, epsilon, conf->triground); + qfree(tmp2); + tmp2 = qmul(tmp1, sin); + qfree(tmp1); + qfree(sin); + qfree(r->imag); + r->imag = qmappr(tmp2, epsilon, conf->triground); + qfree(tmp2); + return r; } /* * Calculate the natural logarithm of a complex number within the specified * error. We use the formula: - * ln(a + bi) = ln(a^2 + b^2) / 2 + i * atan2(b, a). + * ln(a + bi) = ln(a^2 + b^2) / 2 + i * atan2(b, a). */ COMPLEX * c_ln(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; - NUMBER *a2b2, *tmp1, *tmp2, *epsilon1; + COMPLEX *r; + NUMBER *a2b2, *tmp1, *tmp2, *epsilon1; - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon value for complex ln"); - not_reached(); - } - if (cisone(c)) - return clink(&_czero_); - r = comalloc(); - if (cisreal(c) && !qisneg(c->real)) { - qfree(r->real); - r->real = qln(c->real, epsilon); - return r; - } - tmp1 = qsquare(c->real); - tmp2 = qsquare(c->imag); - a2b2 = qqadd(tmp1, tmp2); - qfree(tmp1); - qfree(tmp2); - epsilon1 = qscale(epsilon, 1L); - tmp1 = qln(a2b2, epsilon1); - qfree(a2b2); - qfree(epsilon1); - qfree(r->real); - r->real = qscale(tmp1, -1L); - qfree(tmp1); - qfree(r->imag); - r->imag = qatan2(c->imag, c->real, epsilon); - return r; + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon value for complex ln"); + not_reached(); + } + if (cisone(c)) + return clink(&_czero_); + r = comalloc(); + if (cisreal(c) && !qisneg(c->real)) { + qfree(r->real); + r->real = qln(c->real, epsilon); + return r; + } + tmp1 = qsquare(c->real); + tmp2 = qsquare(c->imag); + a2b2 = qqadd(tmp1, tmp2); + qfree(tmp1); + qfree(tmp2); + epsilon1 = qscale(epsilon, 1L); + tmp1 = qln(a2b2, epsilon1); + qfree(a2b2); + qfree(epsilon1); + qfree(r->real); + r->real = qscale(tmp1, -1L); + qfree(tmp1); + qfree(r->imag); + r->imag = qatan2(c->imag, c->real, epsilon); + return r; } /* * Calculate base 10 logarithm by: * - * log(c) = ln(c) / ln(10) + * log(c) = ln(c) / ln(10) */ COMPLEX * c_log(COMPLEX *c, NUMBER *epsilon) { - int need_new_cln_10 = true; /* false => use cached cln_10 value */ - COMPLEX *ln_c; /* ln(x) */ - COMPLEX *ret; /* base 10 logarithm of x */ + int need_new_cln_10 = true; /* false => use cached cln_10 value */ + COMPLEX *ln_c; /* ln(x) */ + COMPLEX *ret; /* base 10 logarithm of x */ - /* - * compute ln(c) first - */ - ln_c = c_ln(c, epsilon); - /* quick return for log(1) == 0 */ - if (ciszero(ln_c)) { - return ln_c; - } + /* + * compute ln(c) first + */ + ln_c = c_ln(c, epsilon); + /* quick return for log(1) == 0 */ + if (ciszero(ln_c)) { + return ln_c; + } - /* - * save epsilon for ln(10) if needed - */ - if (cln_10_epsilon == NULL) { - /* first time call */ - cln_10_epsilon = qcopy(epsilon); - } else if (qcmp(cln_10_epsilon, epsilon) == true) { - /* replaced cached value with epsilon arg */ - qfree(cln_10_epsilon); - cln_10_epsilon = qcopy(epsilon); - } else if (cln_10 != NULL) { - /* the previously computed ln(2) is OK to use */ - need_new_cln_10 = false; - } + /* + * save epsilon for ln(10) if needed + */ + if (cln_10_epsilon == NULL) { + /* first time call */ + cln_10_epsilon = qcopy(epsilon); + } else if (qcmp(cln_10_epsilon, epsilon) == true) { + /* replaced cached value with epsilon arg */ + qfree(cln_10_epsilon); + cln_10_epsilon = qcopy(epsilon); + } else if (cln_10 != NULL) { + /* the previously computed ln(2) is OK to use */ + need_new_cln_10 = false; + } - /* - * compute ln(10) if needed - */ - if (need_new_cln_10 == true) { - if (cln_10 != NULL) { - comfree(cln_10); - } - cln_10 = c_ln(&_cten_, cln_10_epsilon); - } + /* + * compute ln(10) if needed + */ + if (need_new_cln_10 == true) { + if (cln_10 != NULL) { + comfree(cln_10); + } + cln_10 = c_ln(&_cten_, cln_10_epsilon); + } - /* - * return ln(c) / ln(10) - */ - ret = c_div(ln_c, cln_10); - comfree(ln_c); - return ret; + /* + * return ln(c) / ln(10) + */ + ret = c_div(ln_c, cln_10); + comfree(ln_c); + return ret; } /* * Calculate base 2 logarithm by: * - * log(c) = ln(c) / ln(2) + * log(c) = ln(c) / ln(2) */ COMPLEX * c_log2(COMPLEX *c, NUMBER *epsilon) { - int need_new_cln_2 = true; /* false => use cached cln_2 value */ - COMPLEX *ln_c; /* ln(x) */ - COMPLEX *ret; /* base 2 of x */ + int need_new_cln_2 = true; /* false => use cached cln_2 value */ + COMPLEX *ln_c; /* ln(x) */ + COMPLEX *ret; /* base 2 of x */ - /* - * compute ln(c) first - */ - ln_c = c_ln(c, epsilon); - /* quick return for log(1) == 0 */ - if (ciszero(ln_c)) { - return ln_c; - } + /* + * compute ln(c) first + */ + ln_c = c_ln(c, epsilon); + /* quick return for log(1) == 0 */ + if (ciszero(ln_c)) { + return ln_c; + } - /* - * save epsilon for ln(2) if needed - */ - if (cln_2_epsilon == NULL) { - /* first time call */ - cln_2_epsilon = qcopy(epsilon); - } else if (qcmp(cln_2_epsilon, epsilon) == true) { - /* replaced cached value with epsilon arg */ - qfree(cln_2_epsilon); - cln_2_epsilon = qcopy(epsilon); - } else if (cln_2 != NULL) { - /* the previously computed ln(2) is OK to use */ - need_new_cln_2 = false; - } + /* + * save epsilon for ln(2) if needed + */ + if (cln_2_epsilon == NULL) { + /* first time call */ + cln_2_epsilon = qcopy(epsilon); + } else if (qcmp(cln_2_epsilon, epsilon) == true) { + /* replaced cached value with epsilon arg */ + qfree(cln_2_epsilon); + cln_2_epsilon = qcopy(epsilon); + } else if (cln_2 != NULL) { + /* the previously computed ln(2) is OK to use */ + need_new_cln_2 = false; + } - /* - * compute ln(2) if needed - */ - if (need_new_cln_2 == true) { - if (cln_2 != NULL) { - comfree(cln_2); - } - cln_2 = c_ln(&_ctwo_, cln_2_epsilon); - } + /* + * compute ln(2) if needed + */ + if (need_new_cln_2 == true) { + if (cln_2 != NULL) { + comfree(cln_2); + } + cln_2 = c_ln(&_ctwo_, cln_2_epsilon); + } - /* - * return ln(c) / ln(2) - */ - ret = c_div(ln_c, cln_2); - comfree(ln_c); - return ret; + /* + * return ln(c) / ln(2) + */ + ret = c_div(ln_c, cln_2); + comfree(ln_c); + return ret; } /* * Calculate the complex cosine within the specified accuracy. * This uses the formula: - * cos(x) = (exp(1i * x) + exp(-1i * x))/2; + * cos(x) = (exp(1i * x) + exp(-1i * x))/2; */ COMPLEX * c_cos(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r, *ctmp1, *ctmp2, *ctmp3; - NUMBER *epsilon1; - long n; - bool neg; + COMPLEX *r, *ctmp1, *ctmp2, *ctmp3; + NUMBER *epsilon1; + long n; + bool neg; - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon value for complex cos"); - not_reached(); - } - n = qilog2(epsilon); - ctmp1 = comalloc(); - qfree(ctmp1->real); - qfree(ctmp1->imag); - neg = qisneg(c->imag); - ctmp1->real = neg ? qneg(c->imag) : qlink(c->imag); - ctmp1->imag = neg ? qlink(c->real) : qneg(c->real); - epsilon1 = qbitvalue(n - 2); - ctmp2 = c_exp(ctmp1, epsilon1); - comfree(ctmp1); - qfree(epsilon1); - if (ctmp2 == NULL) - return NULL; - if (ciszero(ctmp2)) { - comfree(ctmp2); - return clink(&_czero_); - } - ctmp1 = c_inv(ctmp2); - ctmp3 = c_add(ctmp2, ctmp1); - comfree(ctmp1); - comfree(ctmp2); - ctmp1 = c_scale(ctmp3, -1); - comfree(ctmp3); - r = comalloc(); - qfree(r->real); - r->real = qmappr(ctmp1->real, epsilon, conf->triground); - qfree(r->imag); - r->imag = qmappr(ctmp1->imag, epsilon, conf->triground); - comfree(ctmp1); - return r; + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon value for complex cos"); + not_reached(); + } + n = qilog2(epsilon); + ctmp1 = comalloc(); + qfree(ctmp1->real); + qfree(ctmp1->imag); + neg = qisneg(c->imag); + ctmp1->real = neg ? qneg(c->imag) : qlink(c->imag); + ctmp1->imag = neg ? qlink(c->real) : qneg(c->real); + epsilon1 = qbitvalue(n - 2); + ctmp2 = c_exp(ctmp1, epsilon1); + comfree(ctmp1); + qfree(epsilon1); + if (ctmp2 == NULL) + return NULL; + if (ciszero(ctmp2)) { + comfree(ctmp2); + return clink(&_czero_); + } + ctmp1 = c_inv(ctmp2); + ctmp3 = c_add(ctmp2, ctmp1); + comfree(ctmp1); + comfree(ctmp2); + ctmp1 = c_scale(ctmp3, -1); + comfree(ctmp3); + r = comalloc(); + qfree(r->real); + r->real = qmappr(ctmp1->real, epsilon, conf->triground); + qfree(r->imag); + r->imag = qmappr(ctmp1->imag, epsilon, conf->triground); + comfree(ctmp1); + return r; } /* * Calculate the complex sine within the specified accuracy. * This uses the formula: - * sin(x) = (exp(1i * x) - exp(-i1*x))/(2i). + * sin(x) = (exp(1i * x) - exp(-i1*x))/(2i). */ COMPLEX * c_sin(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r, *ctmp1, *ctmp2, *ctmp3; - NUMBER *qtmp, *epsilon1; - long n; - bool neg; + COMPLEX *r, *ctmp1, *ctmp2, *ctmp3; + NUMBER *qtmp, *epsilon1; + long n; + bool neg; - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon value for complex sin"); - not_reached(); - } - if (ciszero(c)) { - return clink(&_czero_); - } - n = qilog2(epsilon); - ctmp1 = comalloc(); - neg = qisneg(c->imag); - qfree(ctmp1->real); - qfree(ctmp1->imag); - ctmp1->real = neg ? qneg(c->imag) : qlink(c->imag); - ctmp1->imag = neg ? qlink(c->real) : qneg(c->real); - epsilon1 = qbitvalue(n - 2); - ctmp2 = c_exp(ctmp1, epsilon1); - comfree(ctmp1); - qfree(epsilon1); - if (ctmp2 == NULL) { - return NULL; - } - if (ciszero(ctmp2)) { - comfree(ctmp2); - return clink(&_czero_); - } - ctmp1 = c_inv(ctmp2); - ctmp3 = c_sub(ctmp2, ctmp1); - comfree(ctmp1); - comfree(ctmp2); - ctmp1 = c_scale(ctmp3, -1); - comfree(ctmp3); - r = comalloc(); - qtmp = neg ? qlink(ctmp1->imag) : qneg(ctmp1->imag); - qfree(r->real); - r->real = qmappr(qtmp, epsilon, conf->triground); - qfree(qtmp); - qtmp = neg ? qneg(ctmp1->real) : qlink(ctmp1->real); - qfree(r->imag); - r->imag = qmappr(qtmp, epsilon, conf->triground); - qfree(qtmp); - comfree(ctmp1); - return r; + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon value for complex sin"); + not_reached(); + } + if (ciszero(c)) { + return clink(&_czero_); + } + n = qilog2(epsilon); + ctmp1 = comalloc(); + neg = qisneg(c->imag); + qfree(ctmp1->real); + qfree(ctmp1->imag); + ctmp1->real = neg ? qneg(c->imag) : qlink(c->imag); + ctmp1->imag = neg ? qlink(c->real) : qneg(c->real); + epsilon1 = qbitvalue(n - 2); + ctmp2 = c_exp(ctmp1, epsilon1); + comfree(ctmp1); + qfree(epsilon1); + if (ctmp2 == NULL) { + return NULL; + } + if (ciszero(ctmp2)) { + comfree(ctmp2); + return clink(&_czero_); + } + ctmp1 = c_inv(ctmp2); + ctmp3 = c_sub(ctmp2, ctmp1); + comfree(ctmp1); + comfree(ctmp2); + ctmp1 = c_scale(ctmp3, -1); + comfree(ctmp3); + r = comalloc(); + qtmp = neg ? qlink(ctmp1->imag) : qneg(ctmp1->imag); + qfree(r->real); + r->real = qmappr(qtmp, epsilon, conf->triground); + qfree(qtmp); + qtmp = neg ? qneg(ctmp1->real) : qlink(ctmp1->real); + qfree(r->imag); + r->imag = qmappr(qtmp, epsilon, conf->triground); + qfree(qtmp); + comfree(ctmp1); + return r; } COMPLEX * c_cosh(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2, *tmp3; + COMPLEX *tmp1, *tmp2, *tmp3; - tmp1 = c_exp(c, epsilon); - if (tmp1 == NULL) - return NULL; - tmp2 = c_neg(c); - tmp3 = c_exp(tmp2, epsilon); - comfree(tmp2); - if (tmp3 == NULL) - return NULL; - tmp2 = c_add(tmp1, tmp3); - comfree(tmp1); - comfree(tmp3); - tmp1 = c_scale(tmp2, -1); - comfree(tmp2); - return tmp1; + tmp1 = c_exp(c, epsilon); + if (tmp1 == NULL) + return NULL; + tmp2 = c_neg(c); + tmp3 = c_exp(tmp2, epsilon); + comfree(tmp2); + if (tmp3 == NULL) + return NULL; + tmp2 = c_add(tmp1, tmp3); + comfree(tmp1); + comfree(tmp3); + tmp1 = c_scale(tmp2, -1); + comfree(tmp2); + return tmp1; } COMPLEX * c_sinh(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2, *tmp3; + COMPLEX *tmp1, *tmp2, *tmp3; - tmp1 = c_exp(c, epsilon); - if (tmp1 == NULL) - return NULL; - tmp2 = c_neg(c); - tmp3 = c_exp(tmp2, epsilon); - comfree(tmp2); - if (tmp3 == NULL) - return NULL; - tmp2 = c_sub(tmp1, tmp3); - comfree(tmp1); - comfree(tmp3); - tmp1 = c_scale(tmp2, -1); - comfree(tmp2); - return tmp1; + tmp1 = c_exp(c, epsilon); + if (tmp1 == NULL) + return NULL; + tmp2 = c_neg(c); + tmp3 = c_exp(tmp2, epsilon); + comfree(tmp2); + if (tmp3 == NULL) + return NULL; + tmp2 = c_sub(tmp1, tmp3); + comfree(tmp1); + comfree(tmp3); + tmp1 = c_scale(tmp2, -1); + comfree(tmp2); + return tmp1; } COMPLEX * c_asin(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2; + COMPLEX *tmp1, *tmp2; - tmp1 = c_mul(&_conei_, c); - tmp2 = c_asinh(tmp1, epsilon); - comfree(tmp1); - tmp1 = c_div(tmp2, &_conei_); - comfree(tmp2); - return tmp1; + tmp1 = c_mul(&_conei_, c); + tmp2 = c_asinh(tmp1, epsilon); + comfree(tmp1); + tmp1 = c_div(tmp2, &_conei_); + comfree(tmp2); + return tmp1; } COMPLEX * c_acos(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2; + COMPLEX *tmp1, *tmp2; - tmp1 = c_square(c); - tmp2 = c_sub(&_cone_, tmp1); - comfree(tmp1); - tmp1 = c_sqrt(tmp2, epsilon, conf->triground); - comfree(tmp2); - tmp2 = c_mul(&_conei_, tmp1); - comfree(tmp1); - tmp1 = c_add(c, tmp2); - comfree(tmp2); - tmp2 = c_ln(tmp1, epsilon); - comfree(tmp1); - tmp1 = c_div(tmp2, &_conei_); - comfree(tmp2); - return tmp1; + tmp1 = c_square(c); + tmp2 = c_sub(&_cone_, tmp1); + comfree(tmp1); + tmp1 = c_sqrt(tmp2, epsilon, conf->triground); + comfree(tmp2); + tmp2 = c_mul(&_conei_, tmp1); + comfree(tmp1); + tmp1 = c_add(c, tmp2); + comfree(tmp2); + tmp2 = c_ln(tmp1, epsilon); + comfree(tmp1); + tmp1 = c_div(tmp2, &_conei_); + comfree(tmp2); + return tmp1; } COMPLEX * c_asinh(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2, *tmp3; - bool neg; + COMPLEX *tmp1, *tmp2, *tmp3; + bool neg; - neg = qisneg(c->real); - tmp1 = neg ? c_neg(c) : clink(c); - tmp2 = c_square(tmp1); - tmp3 = c_add(&_cone_, tmp2); - comfree(tmp2); - tmp2 = c_sqrt(tmp3, epsilon, conf->triground); - comfree(tmp3); - tmp3 = c_add(tmp2, tmp1); - comfree(tmp1); - comfree(tmp2); - tmp1 = c_ln(tmp3, epsilon); - comfree(tmp3); - if (neg) { - tmp2 = c_neg(tmp1); - comfree(tmp1); - return tmp2; - } - return tmp1; + neg = qisneg(c->real); + tmp1 = neg ? c_neg(c) : clink(c); + tmp2 = c_square(tmp1); + tmp3 = c_add(&_cone_, tmp2); + comfree(tmp2); + tmp2 = c_sqrt(tmp3, epsilon, conf->triground); + comfree(tmp3); + tmp3 = c_add(tmp2, tmp1); + comfree(tmp1); + comfree(tmp2); + tmp1 = c_ln(tmp3, epsilon); + comfree(tmp3); + if (neg) { + tmp2 = c_neg(tmp1); + comfree(tmp1); + return tmp2; + } + return tmp1; } COMPLEX * c_acosh(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2; + COMPLEX *tmp1, *tmp2; - tmp1 = c_square(c); - tmp2 = c_sub(tmp1, &_cone_); - comfree(tmp1); - tmp1 = c_sqrt(tmp2, epsilon, conf->triground); - comfree(tmp2); - tmp2 = c_add(c, tmp1); - comfree(tmp1); - tmp1 = c_ln(tmp2, epsilon); - comfree(tmp2); - return tmp1; + tmp1 = c_square(c); + tmp2 = c_sub(tmp1, &_cone_); + comfree(tmp1); + tmp1 = c_sqrt(tmp2, epsilon, conf->triground); + comfree(tmp2); + tmp2 = c_add(c, tmp1); + comfree(tmp1); + tmp1 = c_ln(tmp2, epsilon); + comfree(tmp2); + return tmp1; } @@ -883,110 +883,110 @@ c_acosh(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * tan(x) = sin(x) / cos(x) + * tan(x) = sin(x) / cos(x) * * given: - * c argument to the trigonometric function - * epsilon precision of the trigonometric calculation + * c argument to the trigonometric function + * epsilon precision of the trigonometric calculation * * returns: - * != NULL ==> allocated pointer to COMPLEX result - * NULL ==> invalid trigonometric argument + * != NULL ==> allocated pointer to COMPLEX result + * NULL ==> invalid trigonometric argument * * NOTE: When the trigonometric result is returned as non-NULL result, - * the value may be a real value. The caller may wish to: + * the value may be a real value. The caller may wish to: * - * COMPLEX *c; (* return result of this function *) - * NUMBER *q; (* COMPLEX result when c is a real number *) + * COMPLEX *c; (* return result of this function *) + * NUMBER *q; (* COMPLEX result when c is a real number *) * - * if (c == NULL) { - * math_error("... some error message"); - * not_reached(); - * } - * if (cisreal(c)) { - * q = c_to_q(c, ok_to_free); - * } + * if (c == NULL) { + * math_error("... some error message"); + * not_reached(); + * } + * if (cisreal(c)) { + * q = c_to_q(c, ok_to_free); + * } */ COMPLEX * c_tan(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *denom; /* trigonometric identity numerator */ - COMPLEX *numer; /* trigonometric identity denominator */ - COMPLEX *res; /* trigonometric result */ + COMPLEX *denom; /* trigonometric identity numerator */ + COMPLEX *numer; /* trigonometric identity denominator */ + COMPLEX *res; /* trigonometric result */ - /* - * firewall - check args - */ - if (c == NULL) { - return NULL; - } - if (check_epsilon(epsilon) == false) { - return NULL; - } + /* + * firewall - check args + */ + if (c == NULL) { + return NULL; + } + if (check_epsilon(epsilon) == false) { + return NULL; + } - /* - * evaluate the cos(x) denominator - * - * Return NULL if cos(x) failed or we otherwise divide by zero. - */ - denom = c_cos(c, epsilon); - if (denom == NULL || ciszero(denom)) { - return NULL; - } + /* + * evaluate the cos(x) denominator + * + * Return NULL if cos(x) failed or we otherwise divide by zero. + */ + denom = c_cos(c, epsilon); + if (denom == NULL || ciszero(denom)) { + return NULL; + } - /* - * evaluate the sin(x) numerator - * - * Return NULL if sin(x) failed. - */ - numer = c_sin(c, epsilon); - if (numer == NULL) { - comfree(denom); - return NULL; - } + /* + * evaluate the sin(x) numerator + * + * Return NULL if sin(x) failed. + */ + numer = c_sin(c, epsilon); + if (numer == NULL) { + comfree(denom); + return NULL; + } - /* - * catch the special case of numerator of 0 - */ - if (ciszero(numer)) { - comfree(denom); - comfree(numer); - return clink(&_czero_); - } + /* + * catch the special case of numerator of 0 + */ + if (ciszero(numer)) { + comfree(denom); + comfree(numer); + return clink(&_czero_); + } - /* - * compute the trigonometric function value - */ - res = c_div(numer, denom); - comfree(denom); - comfree(numer); + /* + * compute the trigonometric function value + */ + res = c_div(numer, denom); + comfree(denom); + comfree(numer); - /* - * return the trigonometric result - */ - return res; + /* + * return the trigonometric result + */ + return res; } COMPLEX * c_atan(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2, *tmp3; + COMPLEX *tmp1, *tmp2, *tmp3; - if (qiszero(c->real) && qisunit(c->imag)) - return NULL; - tmp1 = c_sub(&_conei_, c); - tmp2 = c_add(&_conei_, c); - tmp3 = c_div(tmp1, tmp2); - comfree(tmp1); - comfree(tmp2); - tmp1 = c_ln(tmp3, epsilon); - comfree(tmp3); - tmp2 = c_scale(tmp1, -1); - comfree(tmp1); - tmp1 = c_div(tmp2, &_conei_); - comfree(tmp2); - return tmp1; + if (qiszero(c->real) && qisunit(c->imag)) + return NULL; + tmp1 = c_sub(&_conei_, c); + tmp2 = c_add(&_conei_, c); + tmp3 = c_div(tmp1, tmp2); + comfree(tmp1); + comfree(tmp2); + tmp1 = c_ln(tmp3, epsilon); + comfree(tmp3); + tmp2 = c_scale(tmp1, -1); + comfree(tmp1); + tmp1 = c_div(tmp2, &_conei_); + comfree(tmp2); + return tmp1; } @@ -995,110 +995,110 @@ c_atan(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * cot(x) = cos(x) / sin(x) + * cot(x) = cos(x) / sin(x) * * given: - * c argument to the trigonometric function - * epsilon precision of the trigonometric calculation + * c argument to the trigonometric function + * epsilon precision of the trigonometric calculation * * returns: - * != NULL ==> allocated pointer to COMPLEX result - * NULL ==> invalid trigonometric argument + * != NULL ==> allocated pointer to COMPLEX result + * NULL ==> invalid trigonometric argument * * NOTE: When the trigonometric result is returned as non-NULL result, - * the value may be a real value. The caller may wish to: + * the value may be a real value. The caller may wish to: * - * COMPLEX *c; (* return result of this function *) - * NUMBER *q; (* COMPLEX result when c is a real number *) + * COMPLEX *c; (* return result of this function *) + * NUMBER *q; (* COMPLEX result when c is a real number *) * - * if (c == NULL) { - * math_error("... some error message"); - * not_reached(); - * } - * if (cisreal(c)) { - * q = c_to_q(c, ok_to_free); - * } + * if (c == NULL) { + * math_error("... some error message"); + * not_reached(); + * } + * if (cisreal(c)) { + * q = c_to_q(c, ok_to_free); + * } */ COMPLEX * c_cot(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *denom; /* trigonometric identity numerator */ - COMPLEX *numer; /* trigonometric identity denominator */ - COMPLEX *res; /* trigonometric result */ + COMPLEX *denom; /* trigonometric identity numerator */ + COMPLEX *numer; /* trigonometric identity denominator */ + COMPLEX *res; /* trigonometric result */ - /* - * firewall - check args - */ - if (c == NULL) { - return NULL; - } - if (check_epsilon(epsilon) == false) { - return NULL; - } + /* + * firewall - check args + */ + if (c == NULL) { + return NULL; + } + if (check_epsilon(epsilon) == false) { + return NULL; + } - /* - * evaluate the sin(x) denominator - * - * Return NULL if sin(x) failed or we otherwise divide by zero. - */ - denom = c_sin(c, epsilon); - if (denom == NULL || ciszero(denom)) { - return NULL; - } + /* + * evaluate the sin(x) denominator + * + * Return NULL if sin(x) failed or we otherwise divide by zero. + */ + denom = c_sin(c, epsilon); + if (denom == NULL || ciszero(denom)) { + return NULL; + } - /* - * evaluate the cos(x) numerator - * - * Return NULL if cos(x) failed. - */ - numer = c_cos(c, epsilon); - if (numer == NULL) { - comfree(denom); - return NULL; - } + /* + * evaluate the cos(x) numerator + * + * Return NULL if cos(x) failed. + */ + numer = c_cos(c, epsilon); + if (numer == NULL) { + comfree(denom); + return NULL; + } - /* - * catch the special case of numerator of 0 - */ - if (ciszero(numer)) { - comfree(denom); - comfree(numer); - return clink(&_czero_); - } + /* + * catch the special case of numerator of 0 + */ + if (ciszero(numer)) { + comfree(denom); + comfree(numer); + return clink(&_czero_); + } - /* - * compute the trigonometric function value - */ - res = c_div(numer, denom); - comfree(denom); - comfree(numer); + /* + * compute the trigonometric function value + */ + res = c_div(numer, denom); + comfree(denom); + comfree(numer); - /* - * return the trigonometric result - */ - return res; + /* + * return the trigonometric result + */ + return res; } COMPLEX * c_acot(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2, *tmp3; + COMPLEX *tmp1, *tmp2, *tmp3; - if (qiszero(c->real) && qisunit(c->imag)) - return NULL; - tmp1 = c_add(c, &_conei_); - tmp2 = c_sub(c, &_conei_); - tmp3 = c_div(tmp1, tmp2); - comfree(tmp1); - comfree(tmp2); - tmp1 = c_ln(tmp3, epsilon); - comfree(tmp3); - tmp2 = c_scale(tmp1, -1); - comfree(tmp1); - tmp1 = c_div(tmp2, &_conei_); - comfree(tmp2); - return tmp1; + if (qiszero(c->real) && qisunit(c->imag)) + return NULL; + tmp1 = c_add(c, &_conei_); + tmp2 = c_sub(c, &_conei_); + tmp3 = c_div(tmp1, tmp2); + comfree(tmp1); + comfree(tmp2); + tmp1 = c_ln(tmp3, epsilon); + comfree(tmp3); + tmp2 = c_scale(tmp1, -1); + comfree(tmp1); + tmp1 = c_div(tmp2, &_conei_); + comfree(tmp2); + return tmp1; } @@ -1107,78 +1107,78 @@ c_acot(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * sec(x) = 1 / cos(x) + * sec(x) = 1 / cos(x) * * given: - * c argument to the trigonometric function - * epsilon precision of the trigonometric calculation + * c argument to the trigonometric function + * epsilon precision of the trigonometric calculation * * returns: - * != NULL ==> allocated pointer to COMPLEX result - * NULL ==> invalid trigonometric argument + * != NULL ==> allocated pointer to COMPLEX result + * NULL ==> invalid trigonometric argument * * NOTE: When the trigonometric result is returned as non-NULL result, - * the value may be a real value. The caller may wish to: + * the value may be a real value. The caller may wish to: * - * COMPLEX *c; (* return result of this function *) - * NUMBER *q; (* COMPLEX result when c is a real number *) + * COMPLEX *c; (* return result of this function *) + * NUMBER *q; (* COMPLEX result when c is a real number *) * - * if (c == NULL) { - * math_error("... some error message"); - * not_reached(); - * } - * if (cisreal(c)) { - * q = c_to_q(c, ok_to_free); - * } + * if (c == NULL) { + * math_error("... some error message"); + * not_reached(); + * } + * if (cisreal(c)) { + * q = c_to_q(c, ok_to_free); + * } */ COMPLEX * c_sec(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *denom; /* trigonometric identity numerator */ - COMPLEX *res; /* trigonometric result */ + COMPLEX *denom; /* trigonometric identity numerator */ + COMPLEX *res; /* trigonometric result */ - /* - * firewall - check args - */ - if (c == NULL) { - return NULL; - } - if (check_epsilon(epsilon) == false) { - return NULL; - } + /* + * firewall - check args + */ + if (c == NULL) { + return NULL; + } + if (check_epsilon(epsilon) == false) { + return NULL; + } - /* - * evaluate the cos(x) denominator - * - * Return NULL if cos(x) failed or we otherwise divide by zero. - */ - denom = c_cos(c, epsilon); - if (denom == NULL || ciszero(denom)) { - return NULL; - } + /* + * evaluate the cos(x) denominator + * + * Return NULL if cos(x) failed or we otherwise divide by zero. + */ + denom = c_cos(c, epsilon); + if (denom == NULL || ciszero(denom)) { + return NULL; + } - /* - * compute the trigonometric function value - */ - res = c_div(&_cone_, denom); - comfree(denom); + /* + * compute the trigonometric function value + */ + res = c_div(&_cone_, denom); + comfree(denom); - /* - * return the trigonometric result - */ - return res; + /* + * return the trigonometric result + */ + return res; } COMPLEX * c_asec(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2; + COMPLEX *tmp1, *tmp2; - tmp1 = c_inv(c); - tmp2 = c_acos(tmp1, epsilon); - comfree(tmp1); - return tmp2; + tmp1 = c_inv(c); + tmp2 = c_acos(tmp1, epsilon); + comfree(tmp1); + return tmp2; } @@ -1187,300 +1187,300 @@ c_asec(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * csc(x) = 1 / sin(x) + * csc(x) = 1 / sin(x) * * given: - * c argument to the trigonometric function - * epsilon precision of the trigonometric calculation + * c argument to the trigonometric function + * epsilon precision of the trigonometric calculation * * returns: - * != NULL ==> allocated pointer to COMPLEX result - * NULL ==> invalid trigonometric argument + * != NULL ==> allocated pointer to COMPLEX result + * NULL ==> invalid trigonometric argument * * NOTE: When the trigonometric result is returned as non-NULL result, - * the value may be a real value. The caller may wish to: + * the value may be a real value. The caller may wish to: * - * COMPLEX *c; (* return result of this function *) - * NUMBER *q; (* COMPLEX result when c is a real number *) + * COMPLEX *c; (* return result of this function *) + * NUMBER *q; (* COMPLEX result when c is a real number *) * - * if (c == NULL) { - * math_error("... some error message"); - * not_reached(); - * } - * if (cisreal(c)) { - * q = c_to_q(c, ok_to_free); - * } + * if (c == NULL) { + * math_error("... some error message"); + * not_reached(); + * } + * if (cisreal(c)) { + * q = c_to_q(c, ok_to_free); + * } */ COMPLEX * c_csc(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *denom; /* trigonometric identity numerator */ - COMPLEX *res; /* trigonometric result */ + COMPLEX *denom; /* trigonometric identity numerator */ + COMPLEX *res; /* trigonometric result */ - /* - * firewall - check args - */ - if (c == NULL) { - return NULL; - } - if (check_epsilon(epsilon) == false) { - return NULL; - } + /* + * firewall - check args + */ + if (c == NULL) { + return NULL; + } + if (check_epsilon(epsilon) == false) { + return NULL; + } - /* - * evaluate the sin(x) denominator - * - * Return NULL if sin(x) failed or we otherwise divide by zero. - */ - denom = c_sin(c, epsilon); - if (denom == NULL || ciszero(denom)) { - return NULL; - } + /* + * evaluate the sin(x) denominator + * + * Return NULL if sin(x) failed or we otherwise divide by zero. + */ + denom = c_sin(c, epsilon); + if (denom == NULL || ciszero(denom)) { + return NULL; + } - /* - * compute the trigonometric function value - */ - res = c_div(&_cone_, denom); - comfree(denom); + /* + * compute the trigonometric function value + */ + res = c_div(&_cone_, denom); + comfree(denom); - /* - * return the trigonometric result - */ - return res; + /* + * return the trigonometric result + */ + return res; } COMPLEX * c_acsc(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2; + COMPLEX *tmp1, *tmp2; - tmp1 = c_inv(c); - tmp2 = c_asin(tmp1, epsilon); - comfree(tmp1); - return tmp2; + tmp1 = c_inv(c); + tmp2 = c_asin(tmp1, epsilon); + comfree(tmp1); + return tmp2; } COMPLEX * c_atanh(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2, *tmp3; + COMPLEX *tmp1, *tmp2, *tmp3; - if (qiszero(c->imag) && qisunit(c->real)) - return NULL; - tmp1 = c_add(&_cone_, c); - tmp2 = c_sub(&_cone_, c); - tmp3 = c_div(tmp1, tmp2); - comfree(tmp1); - comfree(tmp2); - tmp1 = c_ln(tmp3, epsilon); - comfree(tmp3); - tmp2 = c_scale(tmp1, -1); - comfree(tmp1); - return tmp2; + if (qiszero(c->imag) && qisunit(c->real)) + return NULL; + tmp1 = c_add(&_cone_, c); + tmp2 = c_sub(&_cone_, c); + tmp3 = c_div(tmp1, tmp2); + comfree(tmp1); + comfree(tmp2); + tmp1 = c_ln(tmp3, epsilon); + comfree(tmp3); + tmp2 = c_scale(tmp1, -1); + comfree(tmp1); + return tmp2; } COMPLEX * c_acoth(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2, *tmp3; + COMPLEX *tmp1, *tmp2, *tmp3; - if (qiszero(c->imag) && qisunit(c->real)) - return NULL; - tmp1 = c_add(c, &_cone_); - tmp2 = c_sub(c, &_cone_); - tmp3 = c_div(tmp1, tmp2); - comfree(tmp1); - comfree(tmp2); - tmp1 = c_ln(tmp3, epsilon); - comfree(tmp3); - tmp2 = c_scale(tmp1, -1); - comfree(tmp1); - return tmp2; + if (qiszero(c->imag) && qisunit(c->real)) + return NULL; + tmp1 = c_add(c, &_cone_); + tmp2 = c_sub(c, &_cone_); + tmp3 = c_div(tmp1, tmp2); + comfree(tmp1); + comfree(tmp2); + tmp1 = c_ln(tmp3, epsilon); + comfree(tmp3); + tmp2 = c_scale(tmp1, -1); + comfree(tmp1); + return tmp2; } COMPLEX * c_asech(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2; + COMPLEX *tmp1, *tmp2; - tmp1 = c_inv(c); - tmp2 = c_acosh(tmp1, epsilon); - comfree(tmp1); - return tmp2; + tmp1 = c_inv(c); + tmp2 = c_acosh(tmp1, epsilon); + comfree(tmp1); + return tmp2; } COMPLEX * c_acsch(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2; + COMPLEX *tmp1, *tmp2; - tmp1 = c_inv(c); - tmp2 = c_asinh(tmp1, epsilon); - comfree(tmp1); - return tmp2; + tmp1 = c_inv(c); + tmp2 = c_asinh(tmp1, epsilon); + comfree(tmp1); + return tmp2; } COMPLEX * c_gd(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2, *tmp3; - NUMBER *q1, *q2; - NUMBER *sin, *cos; - NUMBER *eps; - int n, n1; - bool neg; + COMPLEX *tmp1, *tmp2, *tmp3; + NUMBER *q1, *q2; + NUMBER *sin, *cos; + NUMBER *eps; + int n, n1; + bool neg; - if (cisreal(c)) { - q1 = qscale(c->real, -1); - eps = qscale(epsilon, -1); - q2 = qtanh(q1, eps); - qfree(q1); - q1 = qatan(q2, eps); - qfree(eps); - qfree(q2); - tmp1 = comalloc(); - qfree(tmp1->real); - tmp1->real = qscale(q1, 1); - qfree(q1); - return tmp1; - } - if (qiszero(c->real)) { - n = - qilog2(epsilon); - qsincos(c->imag, n + 8, &sin, &cos); - if (qiszero(cos) || (n1 = -qilog2(cos)) > n) { - qfree(sin); - qfree(cos); - return NULL; - } - neg = qisneg(sin); - q1 = neg ? qsub(&_qone_, sin) : qqadd(&_qone_, sin); - qfree(sin); - if (n1 > 8) { - qfree(q1); - qfree(cos); - qsincos(c->imag, n + n1, &sin, &cos); - q1 = neg ? qsub(&_qone_, sin) : qqadd(&_qone_, sin); - qfree(sin); - } - q2 = qqdiv(q1, cos); - qfree(q1); - q1 = qln(q2, epsilon); - qfree(q2); - if (neg) { - q2 = qneg(q1); - qfree(q1); - q1 = q2; - } - tmp1 = comalloc(); - qfree(tmp1->imag); - tmp1->imag = q1; - if (qisneg(cos)) { - qfree(tmp1->real); - q1 = qpi(epsilon); - if (qisneg(c->imag)) { - q2 = qneg(q1); - qfree(q1); - q1 = q2; - } - tmp1->real = q1; - } - qfree(cos); - return tmp1; - } - neg = qisneg(c->real); - tmp1 = neg ? c_neg(c) : clink(c); - tmp2 = c_exp(tmp1, epsilon); - comfree(tmp1); - if (tmp2 == NULL) - return NULL; - tmp1 = c_mul(&_conei_, tmp2); - tmp3 = c_add(&_conei_, tmp2); - comfree(tmp2); - tmp2 = c_add(tmp1, &_cone_); - comfree(tmp1); - if (ciszero(tmp2) || ciszero(tmp3)) { - comfree(tmp2); - comfree(tmp3); - return NULL; - } - tmp1 = c_div(tmp2, tmp3); - comfree(tmp2); - comfree(tmp3); - tmp2 = c_ln(tmp1, epsilon); - comfree(tmp1); - tmp1 = c_div(tmp2, &_conei_); - comfree(tmp2); - if (neg) { - tmp2 = c_neg(tmp1); - comfree(tmp1); - return tmp2; - } - return tmp1; + if (cisreal(c)) { + q1 = qscale(c->real, -1); + eps = qscale(epsilon, -1); + q2 = qtanh(q1, eps); + qfree(q1); + q1 = qatan(q2, eps); + qfree(eps); + qfree(q2); + tmp1 = comalloc(); + qfree(tmp1->real); + tmp1->real = qscale(q1, 1); + qfree(q1); + return tmp1; + } + if (qiszero(c->real)) { + n = - qilog2(epsilon); + qsincos(c->imag, n + 8, &sin, &cos); + if (qiszero(cos) || (n1 = -qilog2(cos)) > n) { + qfree(sin); + qfree(cos); + return NULL; + } + neg = qisneg(sin); + q1 = neg ? qsub(&_qone_, sin) : qqadd(&_qone_, sin); + qfree(sin); + if (n1 > 8) { + qfree(q1); + qfree(cos); + qsincos(c->imag, n + n1, &sin, &cos); + q1 = neg ? qsub(&_qone_, sin) : qqadd(&_qone_, sin); + qfree(sin); + } + q2 = qqdiv(q1, cos); + qfree(q1); + q1 = qln(q2, epsilon); + qfree(q2); + if (neg) { + q2 = qneg(q1); + qfree(q1); + q1 = q2; + } + tmp1 = comalloc(); + qfree(tmp1->imag); + tmp1->imag = q1; + if (qisneg(cos)) { + qfree(tmp1->real); + q1 = qpi(epsilon); + if (qisneg(c->imag)) { + q2 = qneg(q1); + qfree(q1); + q1 = q2; + } + tmp1->real = q1; + } + qfree(cos); + return tmp1; + } + neg = qisneg(c->real); + tmp1 = neg ? c_neg(c) : clink(c); + tmp2 = c_exp(tmp1, epsilon); + comfree(tmp1); + if (tmp2 == NULL) + return NULL; + tmp1 = c_mul(&_conei_, tmp2); + tmp3 = c_add(&_conei_, tmp2); + comfree(tmp2); + tmp2 = c_add(tmp1, &_cone_); + comfree(tmp1); + if (ciszero(tmp2) || ciszero(tmp3)) { + comfree(tmp2); + comfree(tmp3); + return NULL; + } + tmp1 = c_div(tmp2, tmp3); + comfree(tmp2); + comfree(tmp3); + tmp2 = c_ln(tmp1, epsilon); + comfree(tmp1); + tmp1 = c_div(tmp2, &_conei_); + comfree(tmp2); + if (neg) { + tmp2 = c_neg(tmp1); + comfree(tmp1); + return tmp2; + } + return tmp1; } COMPLEX * c_agd(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *tmp1, *tmp2; + COMPLEX *tmp1, *tmp2; - tmp1 = c_mul(&_conei_, c); - tmp2 = c_gd(tmp1, epsilon); - comfree(tmp1); - if (tmp2 == NULL) - return NULL; - tmp1 = c_div(tmp2, &_conei_); - comfree(tmp2); - return tmp1; + tmp1 = c_mul(&_conei_, c); + tmp2 = c_gd(tmp1, epsilon); + comfree(tmp1); + if (tmp2 == NULL) + return NULL; + tmp1 = c_div(tmp2, &_conei_); + comfree(tmp2); + return tmp1; } /* * Convert a number from polar coordinates to normal complex number form * within the specified accuracy. This produces the value: - * q1 * cos(q2) + q1 * sin(q2) * i. + * q1 * cos(q2) + q1 * sin(q2) * i. */ COMPLEX * c_polar(NUMBER *q1, NUMBER *q2, NUMBER *epsilon) { - COMPLEX *r; - NUMBER *tmp, *cos, *sin; - long m, n; + COMPLEX *r; + NUMBER *tmp, *cos, *sin; + long m, n; - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon value for complex polar"); - not_reached(); - } - if (qiszero(q1)) - return clink(&_czero_); - m = qilog2(q1) + 1; - n = qilog2(epsilon); - if (m < n) - return clink(&_czero_); - r = comalloc(); - if (qiszero(q2)) { - qfree(r->real); - r->real = qlink(q1); - return r; - } - qsincos(q2, m - n + 2, &sin, &cos); - tmp = qmul(q1, cos); - qfree(cos); - qfree(r->real); - r->real = qmappr(tmp, epsilon, conf->triground); - qfree(tmp); - tmp = qmul(q1, sin); - qfree(sin); - qfree(r->imag); - r->imag = qmappr(tmp, epsilon, conf->triground); - qfree(tmp); - return r; + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon value for complex polar"); + not_reached(); + } + if (qiszero(q1)) + return clink(&_czero_); + m = qilog2(q1) + 1; + n = qilog2(epsilon); + if (m < n) + return clink(&_czero_); + r = comalloc(); + if (qiszero(q2)) { + qfree(r->real); + r->real = qlink(q1); + return r; + } + qsincos(q2, m - n + 2, &sin, &cos); + tmp = qmul(q1, cos); + qfree(cos); + qfree(r->real); + r->real = qmappr(tmp, epsilon, conf->triground); + qfree(tmp); + tmp = qmul(q1, sin); + qfree(sin); + qfree(r->imag); + r->imag = qmappr(tmp, epsilon, conf->triground); + qfree(tmp); + return r; } @@ -1491,68 +1491,68 @@ c_polar(NUMBER *q1, NUMBER *q2, NUMBER *epsilon) COMPLEX * c_power(COMPLEX *c1, COMPLEX *c2, NUMBER *epsilon) { - COMPLEX *ctmp1, *ctmp2; - long k1, k2, k, m1, m2, m, n; - NUMBER *a2b2, *qtmp1, *qtmp2, *epsilon1; + COMPLEX *ctmp1, *ctmp2; + long k1, k2, k, m1, m2, m, n; + NUMBER *a2b2, *qtmp1, *qtmp2, *epsilon1; - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon value for complex power"); - not_reached(); - } - if (ciszero(c1)) { - if (cisreal(c2) && qisneg(c2->real)) { - math_error ("Non-positive real exponent of zero for complex power"); - not_reached(); - } - return clink(&_czero_); - } - n = qilog2(epsilon); - m1 = m2 = -1000000; - k1 = k2 = 0; - if (!qiszero(c2->real)) { - qtmp1 = qsquare(c1->real); - qtmp2 = qsquare(c1->imag); - a2b2 = qqadd(qtmp1, qtmp2); - qfree(qtmp1); - qfree(qtmp2); - m1 = qilog2(c2->real); - epsilon1 = qbitvalue(-m1 - 1); - qtmp1 = qln(a2b2, epsilon1); - qfree(epsilon1); - qfree(a2b2); - qtmp2 = qmul(qtmp1, c2->real); - qfree(qtmp1); - qtmp1 = qmul(qtmp2, &_qlge_); - qfree(qtmp2); - k1 = qtoi(qtmp1); - qfree(qtmp1); - } - if (!qiszero(c2->imag)) { - m2 = qilog2(c2->imag); - epsilon1 = qbitvalue(-m2 - 1); - qtmp1 = qatan2(c1->imag, c1->real, epsilon1); - qfree(epsilon1); - qtmp2 = qmul(qtmp1, c2->imag); - qfree(qtmp1); - qtmp1 = qscale(qtmp2, -1); - qfree(qtmp2); - qtmp2 = qmul(qtmp1, &_qlge_); - qfree(qtmp1); - k2 = qtoi(qtmp2); - qfree(qtmp2); - } - m = (m2 > m1) ? m2 : m1; - k = k1 - k2 + 1; - if (k < n) - return clink(&_czero_); - epsilon1 = qbitvalue(n - k - m - 2); - ctmp1 = c_ln(c1, epsilon1); - qfree(epsilon1); - ctmp2 = c_mul(ctmp1, c2); - comfree(ctmp1); - ctmp1 = c_exp(ctmp2, epsilon); - comfree(ctmp2); - return ctmp1; + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon value for complex power"); + not_reached(); + } + if (ciszero(c1)) { + if (cisreal(c2) && qisneg(c2->real)) { + math_error ("Non-positive real exponent of zero for complex power"); + not_reached(); + } + return clink(&_czero_); + } + n = qilog2(epsilon); + m1 = m2 = -1000000; + k1 = k2 = 0; + if (!qiszero(c2->real)) { + qtmp1 = qsquare(c1->real); + qtmp2 = qsquare(c1->imag); + a2b2 = qqadd(qtmp1, qtmp2); + qfree(qtmp1); + qfree(qtmp2); + m1 = qilog2(c2->real); + epsilon1 = qbitvalue(-m1 - 1); + qtmp1 = qln(a2b2, epsilon1); + qfree(epsilon1); + qfree(a2b2); + qtmp2 = qmul(qtmp1, c2->real); + qfree(qtmp1); + qtmp1 = qmul(qtmp2, &_qlge_); + qfree(qtmp2); + k1 = qtoi(qtmp1); + qfree(qtmp1); + } + if (!qiszero(c2->imag)) { + m2 = qilog2(c2->imag); + epsilon1 = qbitvalue(-m2 - 1); + qtmp1 = qatan2(c1->imag, c1->real, epsilon1); + qfree(epsilon1); + qtmp2 = qmul(qtmp1, c2->imag); + qfree(qtmp1); + qtmp1 = qscale(qtmp2, -1); + qfree(qtmp2); + qtmp2 = qmul(qtmp1, &_qlge_); + qfree(qtmp1); + k2 = qtoi(qtmp2); + qfree(qtmp2); + } + m = (m2 > m1) ? m2 : m1; + k = k1 - k2 + 1; + if (k < n) + return clink(&_czero_); + epsilon1 = qbitvalue(n - k - m - 2); + ctmp1 = c_ln(c1, epsilon1); + qfree(epsilon1); + ctmp2 = c_mul(ctmp1, c2); + comfree(ctmp1); + ctmp1 = c_exp(ctmp2, epsilon); + comfree(ctmp2); + return ctmp1; } @@ -1562,31 +1562,31 @@ c_power(COMPLEX *c1, COMPLEX *c2, NUMBER *epsilon) void comprint(COMPLEX *c) { - NUMBER qtmp; + NUMBER qtmp; - if (conf->outmode == MODE_FRAC) { - cprintfr(c); - return; - } - if (!qiszero(c->real) || qiszero(c->imag)) - qprintnum(c->real, MODE_DEFAULT, conf->outdigits); - qtmp = c->imag[0]; - if (qiszero(&qtmp)) - return; - if (conf->complex_space) { - math_chr(' '); - } - if (!qiszero(c->real) && !qisneg(&qtmp)) - math_chr('+'); - if (qisneg(&qtmp)) { - math_chr('-'); - qtmp.num.sign = 0; - } - if (conf->complex_space) { - math_chr(' '); - } - qprintnum(&qtmp, MODE_DEFAULT, conf->outdigits); - math_chr('i'); + if (conf->outmode == MODE_FRAC) { + cprintfr(c); + return; + } + if (!qiszero(c->real) || qiszero(c->imag)) + qprintnum(c->real, MODE_DEFAULT, conf->outdigits); + qtmp = c->imag[0]; + if (qiszero(&qtmp)) + return; + if (conf->complex_space) { + math_chr(' '); + } + if (!qiszero(c->real) && !qisneg(&qtmp)) + math_chr('+'); + if (qisneg(&qtmp)) { + math_chr('-'); + qtmp.num.sign = 0; + } + if (conf->complex_space) { + math_chr(' '); + } + qprintnum(&qtmp, MODE_DEFAULT, conf->outdigits); + math_chr('i'); } @@ -1597,53 +1597,53 @@ comprint(COMPLEX *c) void cprintfr(COMPLEX *c) { - NUMBER *r; - NUMBER *i; + NUMBER *r; + NUMBER *i; - r = c->real; - i = c->imag; - if (!qiszero(r) || qiszero(i)) - qprintfr(r, 0L, false); - if (qiszero(i)) - return; - if (!qiszero(r) && !qisneg(i)) - math_chr('+'); - zprintval(i->num, 0L, 0L); - math_chr('i'); - if (qisfrac(i)) { - if (conf->fraction_space) { - math_chr(' '); - } - math_chr('/'); - if (conf->fraction_space) { - math_chr(' '); - } - zprintval(i->den, 0L, 0L); - } + r = c->real; + i = c->imag; + if (!qiszero(r) || qiszero(i)) + qprintfr(r, 0L, false); + if (qiszero(i)) + return; + if (!qiszero(r) && !qisneg(i)) + math_chr('+'); + zprintval(i->num, 0L, 0L); + math_chr('i'); + if (qisfrac(i)) { + if (conf->fraction_space) { + math_chr(' '); + } + math_chr('/'); + if (conf->fraction_space) { + math_chr(' '); + } + zprintval(i->den, 0L, 0L); + } } NUMBER * c_ilog(COMPLEX *c, ZVALUE base) { - NUMBER *qr, *qi; + NUMBER *qr, *qi; - qr = qilog(c->real, base); - qi = qilog(c->imag, base); + qr = qilog(c->real, base); + qi = qilog(c->imag, base); - if (qr == NULL) { - if (qi == NULL) - return NULL; - return qi; - } - if (qi == NULL) - return qr; - if (qrel(qr, qi) >= 0) { - qfree(qi); - return qr; - } - qfree(qr); - return qi; + if (qr == NULL) { + if (qi == NULL) + return NULL; + return qi; + } + if (qi == NULL) + return qr; + if (qrel(qr, qi) >= 0) { + qfree(qi); + return qr; + } + qfree(qr); + return qi; } @@ -1652,48 +1652,48 @@ c_ilog(COMPLEX *c, ZVALUE base) * * This uses the formula: * - * versin(x) = 1 - cos(x) + * versin(x) = 1 - cos(x) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_versin(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* return COMPLEX value */ - COMPLEX *ctmp; /* complex cos(c) */ + COMPLEX *r; /* return COMPLEX value */ + COMPLEX *ctmp; /* complex cos(c) */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex trig function value - */ - ctmp = c_cos(c, epsilon); - if (ctmp == NULL) { - math_error("Failed to compute complex cosine for complex versin"); - not_reached(); - } - r = c_sub(&_cone_, ctmp); + /* + * calculate complex trig function value + */ + ctmp = c_cos(c, epsilon); + if (ctmp == NULL) { + math_error("Failed to compute complex cosine for complex versin"); + not_reached(); + } + r = c_sub(&_cone_, ctmp); - /* - * return trigonometric result - */ - comfree(ctmp); - return r; + /* + * return trigonometric result + */ + comfree(ctmp); + return r; } @@ -1702,44 +1702,44 @@ c_versin(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * aversin(x) = acos(1 - x) + * aversin(x) = acos(1 - x) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_aversin(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* inverse trig value result */ - COMPLEX *ctmp; /* argument to inverse trig function */ + COMPLEX *r; /* inverse trig value result */ + COMPLEX *ctmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex inverse trig function value - */ - ctmp = c_sub(&_cone_, c); - r = c_acos(ctmp, epsilon); - comfree(ctmp); + /* + * calculate complex inverse trig function value + */ + ctmp = c_sub(&_cone_, c); + r = c_acos(ctmp, epsilon); + comfree(ctmp); - /* - * return inverse trigonometric result - */ - return r; + /* + * return inverse trigonometric result + */ + return r; } @@ -1748,48 +1748,48 @@ c_aversin(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * coversin(x) = 1 - cos(x) + * coversin(x) = 1 - cos(x) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_coversin(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* return COMPLEX value */ - COMPLEX *ctmp; /* complex sin(c) */ + COMPLEX *r; /* return COMPLEX value */ + COMPLEX *ctmp; /* complex sin(c) */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex trig function value - */ - ctmp = c_sin(c, epsilon); - if (ctmp == NULL) { - math_error("Failed to compute complex sine for complex coversin"); - not_reached(); - } - r = c_sub(&_cone_, ctmp); - comfree(ctmp); + /* + * calculate complex trig function value + */ + ctmp = c_sin(c, epsilon); + if (ctmp == NULL) { + math_error("Failed to compute complex sine for complex coversin"); + not_reached(); + } + r = c_sub(&_cone_, ctmp); + comfree(ctmp); - /* - * return trigonometric result - */ - return r; + /* + * return trigonometric result + */ + return r; } @@ -1798,44 +1798,44 @@ c_coversin(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * acoversin(x) = asin(1 - x) + * acoversin(x) = asin(1 - x) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_acoversin(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* inverse trig value result */ - COMPLEX *ctmp; /* argument to inverse trig function */ + COMPLEX *r; /* inverse trig value result */ + COMPLEX *ctmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex inverse trig function value - */ - ctmp = c_sub(&_cone_, c); - r = c_asin(ctmp, epsilon); - comfree(ctmp); + /* + * calculate complex inverse trig function value + */ + ctmp = c_sub(&_cone_, c); + r = c_asin(ctmp, epsilon); + comfree(ctmp); - /* - * return inverse trigonometric result - */ - return r; + /* + * return inverse trigonometric result + */ + return r; } @@ -1844,48 +1844,48 @@ c_acoversin(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * vercos(x) = 1 + cos(x) + * vercos(x) = 1 + cos(x) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_vercos(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* return COMPLEX value */ - COMPLEX *ctmp; /* complex cos(c) */ + COMPLEX *r; /* return COMPLEX value */ + COMPLEX *ctmp; /* complex cos(c) */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex trig function value - */ - ctmp = c_cos(c, epsilon); - if (ctmp == NULL) { - math_error("Failed to compute complex cosine for complex vercos"); - not_reached(); - } - r = c_add(&_cone_, ctmp); - comfree(ctmp); + /* + * calculate complex trig function value + */ + ctmp = c_cos(c, epsilon); + if (ctmp == NULL) { + math_error("Failed to compute complex cosine for complex vercos"); + not_reached(); + } + r = c_add(&_cone_, ctmp); + comfree(ctmp); - /* - * return trigonometric result - */ - return r; + /* + * return trigonometric result + */ + return r; } @@ -1894,44 +1894,44 @@ c_vercos(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * avercos(x) = acos(x - 1) + * avercos(x) = acos(x - 1) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_avercos(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* inverse trig value result */ - COMPLEX *ctmp; /* argument to inverse trig function */ + COMPLEX *r; /* inverse trig value result */ + COMPLEX *ctmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex inverse trig function value - */ - ctmp = c_sub(c, &_cone_); - r = c_acos(ctmp, epsilon); - comfree(ctmp); + /* + * calculate complex inverse trig function value + */ + ctmp = c_sub(c, &_cone_); + r = c_acos(ctmp, epsilon); + comfree(ctmp); - /* - * return inverse trigonometric result - */ - return r; + /* + * return inverse trigonometric result + */ + return r; } @@ -1940,48 +1940,48 @@ c_avercos(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * covercos(x) = 1 + sin(x) + * covercos(x) = 1 + sin(x) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_covercos(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* return COMPLEX value */ - COMPLEX *ctmp; /* complex sin(c) */ + COMPLEX *r; /* return COMPLEX value */ + COMPLEX *ctmp; /* complex sin(c) */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex trig function value - */ - ctmp = c_sin(c, epsilon); - if (ctmp == NULL) { - math_error("Failed to compute complex sine for complex covercos"); - not_reached(); - } - r = c_add(&_cone_, ctmp); - comfree(ctmp); + /* + * calculate complex trig function value + */ + ctmp = c_sin(c, epsilon); + if (ctmp == NULL) { + math_error("Failed to compute complex sine for complex covercos"); + not_reached(); + } + r = c_add(&_cone_, ctmp); + comfree(ctmp); - /* - * return trigonometric result - */ - return r; + /* + * return trigonometric result + */ + return r; } @@ -1990,44 +1990,44 @@ c_covercos(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * acovercos(x) = asin(x - 1) + * acovercos(x) = asin(x - 1) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_acovercos(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* inverse trig value result */ - COMPLEX *ctmp; /* argument to inverse trig function */ + COMPLEX *r; /* inverse trig value result */ + COMPLEX *ctmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex inverse trig function value - */ - ctmp = c_sub(c, &_cone_); - r = c_asin(ctmp, epsilon); - comfree(ctmp); + /* + * calculate complex inverse trig function value + */ + ctmp = c_sub(c, &_cone_); + r = c_asin(ctmp, epsilon); + comfree(ctmp); - /* - * return inverse trigonometric result - */ - return r; + /* + * return inverse trigonometric result + */ + return r; } @@ -2036,48 +2036,48 @@ c_acovercos(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * haversin(x) = versin(x) / 2 + * haversin(x) = versin(x) / 2 * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_haversin(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* return COMPLEX value */ - COMPLEX *ctmp; /* complex cos(c) */ + COMPLEX *r; /* return COMPLEX value */ + COMPLEX *ctmp; /* complex cos(c) */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex trig function value - */ - ctmp = c_versin(c, epsilon); - if (ctmp == NULL) { - math_error("Failed to compute complex versed sine for complex haversin"); - not_reached(); - } - r = c_divq(ctmp, &_qtwo_); - comfree(ctmp); + /* + * calculate complex trig function value + */ + ctmp = c_versin(c, epsilon); + if (ctmp == NULL) { + math_error("Failed to compute complex versed sine for complex haversin"); + not_reached(); + } + r = c_divq(ctmp, &_qtwo_); + comfree(ctmp); - /* - * return trigonometric result - */ - return r; + /* + * return trigonometric result + */ + return r; } @@ -2086,47 +2086,47 @@ c_haversin(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * ahaversin(x) = acos(1 - 2*x) + * ahaversin(x) = acos(1 - 2*x) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_ahaversin(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* inverse trig value result */ - COMPLEX *ctmp; /* argument to inverse trig function */ - COMPLEX *x2; /* twice x */ + COMPLEX *r; /* inverse trig value result */ + COMPLEX *ctmp; /* argument to inverse trig function */ + COMPLEX *x2; /* twice x */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex inverse trig function value - */ - x2 = c_mulq(c, &_qtwo_); - ctmp = c_sub(&_cone_, x2); - comfree(x2); - r = c_acos(ctmp, epsilon); - comfree(ctmp); + /* + * calculate complex inverse trig function value + */ + x2 = c_mulq(c, &_qtwo_); + ctmp = c_sub(&_cone_, x2); + comfree(x2); + r = c_acos(ctmp, epsilon); + comfree(ctmp); - /* - * return inverse trigonometric result - */ - return r; + /* + * return inverse trigonometric result + */ + return r; } @@ -2135,48 +2135,48 @@ c_ahaversin(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * hacoversin(x) = coversin(x) / 2 + * hacoversin(x) = coversin(x) / 2 * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_hacoversin(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* return COMPLEX value */ - COMPLEX *ctmp; /* complex sin(c) */ + COMPLEX *r; /* return COMPLEX value */ + COMPLEX *ctmp; /* complex sin(c) */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex trig function value - */ - ctmp = c_coversin(c, epsilon); - if (ctmp == NULL) { - math_error("Failed to compute complex coversed sine for complex hacoversin"); - not_reached(); - } - r = c_divq(ctmp, &_qtwo_); - comfree(ctmp); + /* + * calculate complex trig function value + */ + ctmp = c_coversin(c, epsilon); + if (ctmp == NULL) { + math_error("Failed to compute complex coversed sine for complex hacoversin"); + not_reached(); + } + r = c_divq(ctmp, &_qtwo_); + comfree(ctmp); - /* - * return trigonometric result - */ - return r; + /* + * return trigonometric result + */ + return r; } @@ -2185,47 +2185,47 @@ c_hacoversin(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * ahacoversin(x) = asin(1 - 2*x) + * ahacoversin(x) = asin(1 - 2*x) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_ahacoversin(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* inverse trig value result */ - COMPLEX *ctmp; /* argument to inverse trig function */ - COMPLEX *x2; /* twice x */ + COMPLEX *r; /* inverse trig value result */ + COMPLEX *ctmp; /* argument to inverse trig function */ + COMPLEX *x2; /* twice x */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex inverse trig function value - */ - x2 = c_mulq(c, &_qtwo_); - ctmp = c_sub(&_cone_, x2); - comfree(x2); - r = c_asin(ctmp, epsilon); - comfree(ctmp); + /* + * calculate complex inverse trig function value + */ + x2 = c_mulq(c, &_qtwo_); + ctmp = c_sub(&_cone_, x2); + comfree(x2); + r = c_asin(ctmp, epsilon); + comfree(ctmp); - /* - * return inverse trigonometric result - */ - return r; + /* + * return inverse trigonometric result + */ + return r; } @@ -2234,48 +2234,48 @@ c_ahacoversin(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * havercos(x) = vercos(x) / 2 + * havercos(x) = vercos(x) / 2 * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_havercos(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* return COMPLEX value */ - COMPLEX *ctmp; /* complex sin(c) */ + COMPLEX *r; /* return COMPLEX value */ + COMPLEX *ctmp; /* complex sin(c) */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex trig function value - */ - ctmp = c_vercos(c, epsilon); - if (ctmp == NULL) { - math_error("Failed to compute complex versed cosine for complex havercos"); - not_reached(); - } - r = c_divq(ctmp, &_qtwo_); - comfree(ctmp); + /* + * calculate complex trig function value + */ + ctmp = c_vercos(c, epsilon); + if (ctmp == NULL) { + math_error("Failed to compute complex versed cosine for complex havercos"); + not_reached(); + } + r = c_divq(ctmp, &_qtwo_); + comfree(ctmp); - /* - * return trigonometric result - */ - return r; + /* + * return trigonometric result + */ + return r; } @@ -2284,47 +2284,47 @@ c_havercos(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * ahavercos(x) = acos(2*x - 1) + * ahavercos(x) = acos(2*x - 1) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_ahavercos(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* inverse trig value result */ - COMPLEX *ctmp; /* argument to inverse trig function */ - COMPLEX *x2; /* twice x */ + COMPLEX *r; /* inverse trig value result */ + COMPLEX *ctmp; /* argument to inverse trig function */ + COMPLEX *x2; /* twice x */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex inverse trig function value - */ - x2 = c_mulq(c, &_qtwo_); - ctmp = c_sub(&_cone_, x2); - comfree(x2); - r = c_acos(ctmp, epsilon); - comfree(ctmp); + /* + * calculate complex inverse trig function value + */ + x2 = c_mulq(c, &_qtwo_); + ctmp = c_sub(&_cone_, x2); + comfree(x2); + r = c_acos(ctmp, epsilon); + comfree(ctmp); - /* - * return inverse trigonometric result - */ - return r; + /* + * return inverse trigonometric result + */ + return r; } @@ -2333,48 +2333,48 @@ c_ahavercos(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * hacovercos(x) = covercos(x) / 2 + * hacovercos(x) = covercos(x) / 2 * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_hacovercos(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* return COMPLEX value */ - COMPLEX *ctmp; /* complex sin(c) */ + COMPLEX *r; /* return COMPLEX value */ + COMPLEX *ctmp; /* complex sin(c) */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex trig function value - */ - ctmp = c_covercos(c, epsilon); - if (ctmp == NULL) { - math_error("Failed to compute complex coversed cosine for complex hacovercos"); - not_reached(); - } - r = c_divq(ctmp, &_qtwo_); - comfree(ctmp); + /* + * calculate complex trig function value + */ + ctmp = c_covercos(c, epsilon); + if (ctmp == NULL) { + math_error("Failed to compute complex coversed cosine for complex hacovercos"); + not_reached(); + } + r = c_divq(ctmp, &_qtwo_); + comfree(ctmp); - /* - * return trigonometric result - */ - return r; + /* + * return trigonometric result + */ + return r; } @@ -2383,47 +2383,47 @@ c_hacovercos(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * ahacovercos(x) = asin(2*x - 1) + * ahacovercos(x) = asin(2*x - 1) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_ahacovercos(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* inverse trig value result */ - COMPLEX *ctmp; /* argument to inverse trig function */ - COMPLEX *x2; /* twice x */ + COMPLEX *r; /* inverse trig value result */ + COMPLEX *ctmp; /* argument to inverse trig function */ + COMPLEX *x2; /* twice x */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex inverse trig function value - */ - x2 = c_mulq(c, &_qtwo_); - ctmp = c_sub(&_cone_, x2); - comfree(x2); - r = c_asin(ctmp, epsilon); - comfree(ctmp); + /* + * calculate complex inverse trig function value + */ + x2 = c_mulq(c, &_qtwo_); + ctmp = c_sub(&_cone_, x2); + comfree(x2); + r = c_asin(ctmp, epsilon); + comfree(ctmp); - /* - * return inverse trigonometric result - */ - return r; + /* + * return inverse trigonometric result + */ + return r; } @@ -2432,48 +2432,48 @@ c_ahacovercos(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * exsec(x) = sec(x) - 1 + * exsec(x) = sec(x) - 1 * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_exsec(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* return COMPLEX value */ - COMPLEX *ctmp; /* complex sec(c) */ + COMPLEX *r; /* return COMPLEX value */ + COMPLEX *ctmp; /* complex sec(c) */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex trig function value - */ - ctmp = c_sec(c, epsilon); - if (ctmp == NULL) { - math_error("Failed to compute complex cosine for complex exsec"); - not_reached(); - } - r = c_sub(ctmp, &_cone_); - comfree(ctmp); + /* + * calculate complex trig function value + */ + ctmp = c_sec(c, epsilon); + if (ctmp == NULL) { + math_error("Failed to compute complex cosine for complex exsec"); + not_reached(); + } + r = c_sub(ctmp, &_cone_); + comfree(ctmp); - /* - * return trigonometric result - */ - return r; + /* + * return trigonometric result + */ + return r; } @@ -2482,44 +2482,44 @@ c_exsec(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * aexsec(x) = asec(x + 1) + * aexsec(x) = asec(x + 1) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_aexsec(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* inverse trig value result */ - COMPLEX *ctmp; /* argument to inverse trig function */ + COMPLEX *r; /* inverse trig value result */ + COMPLEX *ctmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex inverse trig function value - */ - ctmp = c_addq(c, &_qone_); - r = c_asec(ctmp, epsilon); - comfree(ctmp); + /* + * calculate complex inverse trig function value + */ + ctmp = c_addq(c, &_qone_); + r = c_asec(ctmp, epsilon); + comfree(ctmp); - /* - * return inverse trigonometric result - */ - return r; + /* + * return inverse trigonometric result + */ + return r; } @@ -2528,48 +2528,48 @@ c_aexsec(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * excsc(x) = csc(x) - 1 + * excsc(x) = csc(x) - 1 * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_excsc(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* return COMPLEX value */ - COMPLEX *ctmp; /* complex sin(c) */ + COMPLEX *r; /* return COMPLEX value */ + COMPLEX *ctmp; /* complex sin(c) */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex trig function value - */ - ctmp = c_csc(c, epsilon); - if (ctmp == NULL) { - math_error("Failed to compute complex sine for complex excsc"); - not_reached(); - } - r = c_sub(ctmp, &_cone_); - comfree(ctmp); + /* + * calculate complex trig function value + */ + ctmp = c_csc(c, epsilon); + if (ctmp == NULL) { + math_error("Failed to compute complex sine for complex excsc"); + not_reached(); + } + r = c_sub(ctmp, &_cone_); + comfree(ctmp); - /* - * return trigonometric result - */ - return r; + /* + * return trigonometric result + */ + return r; } @@ -2578,44 +2578,44 @@ c_excsc(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * aexcsc(x) = acsc(x + 1) + * aexcsc(x) = acsc(x + 1) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_aexcsc(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* inverse trig value result */ - COMPLEX *ctmp; /* argument to inverse trig function */ + COMPLEX *r; /* inverse trig value result */ + COMPLEX *ctmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex inverse trig function value - */ - ctmp = c_addq(c, &_qone_); - r = c_acsc(ctmp, epsilon); - comfree(ctmp); + /* + * calculate complex inverse trig function value + */ + ctmp = c_addq(c, &_qone_); + r = c_acsc(ctmp, epsilon); + comfree(ctmp); - /* - * return inverse trigonometric result - */ - return r; + /* + * return inverse trigonometric result + */ + return r; } @@ -2624,51 +2624,51 @@ c_aexcsc(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * crd(x) = 2 * sin(x / 2) + * crd(x) = 2 * sin(x / 2) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_crd(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* return COMPLEX value */ - COMPLEX *cdiv2; /* complex c/2 */ - COMPLEX *ctmp; /* complex sin(c/2) */ + COMPLEX *r; /* return COMPLEX value */ + COMPLEX *cdiv2; /* complex c/2 */ + COMPLEX *ctmp; /* complex sin(c/2) */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex trig function value - */ - cdiv2 = c_divq(c, &_qtwo_); - ctmp = c_sin(cdiv2, epsilon); - comfree(cdiv2); - if (ctmp == NULL) { - math_error("Failed to compute complex sine for complex crd"); - not_reached(); - } - r = c_mulq(ctmp, &_qtwo_); - comfree(ctmp); + /* + * calculate complex trig function value + */ + cdiv2 = c_divq(c, &_qtwo_); + ctmp = c_sin(cdiv2, epsilon); + comfree(cdiv2); + if (ctmp == NULL) { + math_error("Failed to compute complex sine for complex crd"); + not_reached(); + } + r = c_mulq(ctmp, &_qtwo_); + comfree(ctmp); - /* - * return trigonometric result - */ - return r; + /* + * return trigonometric result + */ + return r; } @@ -2677,47 +2677,47 @@ c_crd(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * acrd(x) = 2 * asin(x / 2) + * acrd(x) = 2 * asin(x / 2) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_acrd(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* inverse trig value result */ - COMPLEX *cdiv2; /* complex c/2 */ - COMPLEX *ctmp; /* complex asin(c/2) */ + COMPLEX *r; /* inverse trig value result */ + COMPLEX *cdiv2; /* complex c/2 */ + COMPLEX *ctmp; /* complex asin(c/2) */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex inverse trig function value - */ - cdiv2 = c_divq(c, &_qtwo_); - ctmp = c_asin(cdiv2, epsilon); - comfree(cdiv2); - r = c_mulq(ctmp, &_qtwo_); - comfree(ctmp); + /* + * calculate complex inverse trig function value + */ + cdiv2 = c_divq(c, &_qtwo_); + ctmp = c_asin(cdiv2, epsilon); + comfree(cdiv2); + r = c_mulq(ctmp, &_qtwo_); + comfree(ctmp); - /* - * return inverse trigonometric result - */ - return r; + /* + * return inverse trigonometric result + */ + return r; } @@ -2726,56 +2726,56 @@ c_acrd(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * cas(x) = cos(x) + sin(x) + * cas(x) = cos(x) + sin(x) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_cas(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* return COMPLEX value */ - COMPLEX *csin; /* complex sin(c) */ - COMPLEX *ccos; /* complex cos(c) */ + COMPLEX *r; /* return COMPLEX value */ + COMPLEX *csin; /* complex sin(c) */ + COMPLEX *ccos; /* complex cos(c) */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex trig function value - */ - csin = c_sin(c, epsilon); - if (csin == NULL) { - math_error("Failed to compute complex sine for complex cas"); - not_reached(); - } - ccos = c_cos(c, epsilon); - if (ccos == NULL) { - comfree(csin); - math_error("Failed to compute complex cosine for complex cas"); - not_reached(); - } - r = c_add(csin, ccos); - comfree(csin); - comfree(ccos); + /* + * calculate complex trig function value + */ + csin = c_sin(c, epsilon); + if (csin == NULL) { + math_error("Failed to compute complex sine for complex cas"); + not_reached(); + } + ccos = c_cos(c, epsilon); + if (ccos == NULL) { + comfree(csin); + math_error("Failed to compute complex cosine for complex cas"); + not_reached(); + } + r = c_add(csin, ccos); + comfree(csin); + comfree(ccos); - /* - * return trigonometric result - */ - return r; + /* + * return trigonometric result + */ + return r; } @@ -2784,47 +2784,47 @@ c_cas(COMPLEX *c, NUMBER *epsilon) * * This uses the formula: * - * cis(x) = cos(x) + 1i*sin(x) - * cis(x) = exp(1i * x) + * cis(x) = cos(x) + 1i*sin(x) + * cis(x) = exp(1i * x) * * given: - * c complex value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * c complex value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * complex value result of trig function on q with error epsilon + * complex value result of trig function on q with error epsilon */ COMPLEX * c_cis(COMPLEX *c, NUMBER *epsilon) { - COMPLEX *r; /* return COMPLEX value */ - COMPLEX *ctmp; /* 1i * c */ + COMPLEX *r; /* return COMPLEX value */ + COMPLEX *ctmp; /* 1i * c */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate complex trig function value - */ - ctmp = c_mul(c, &_conei_); - r = c_exp(ctmp, epsilon); - comfree(ctmp); - if (r == NULL) { - math_error("Failed to compute complex exp for complex cis"); - not_reached(); - } + /* + * calculate complex trig function value + */ + ctmp = c_mul(c, &_conei_); + r = c_exp(ctmp, epsilon); + comfree(ctmp); + if (r == NULL) { + math_error("Failed to compute complex exp for complex cis"); + not_reached(); + } - /* - * return trigonometric result - */ - return r; + /* + * return trigonometric result + */ + return r; } diff --git a/commath.c b/commath.c index 2425d6d..0a922a5 100644 --- a/commath.c +++ b/commath.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:10 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:10 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,14 +28,14 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -COMPLEX _czero_ = { &_qzero_, &_qzero_, 1 }; -COMPLEX _cone_ = { &_qone_, &_qzero_, 1 }; -COMPLEX _conei_ = { &_qzero_, &_qone_, 1 }; +COMPLEX _czero_ = { &_qzero_, &_qzero_, 1 }; +COMPLEX _cone_ = { &_qone_, &_qzero_, 1 }; +COMPLEX _conei_ = { &_qzero_, &_qone_, 1 }; -STATIC COMPLEX _cnegone_ = { &_qnegone_, &_qzero_, 1 }; +STATIC COMPLEX _cnegone_ = { &_qnegone_, &_qzero_, 1 }; /* @@ -46,64 +46,64 @@ STATIC COMPLEX _cnegone_ = { &_qnegone_, &_qzero_, 1 }; * * This function is useful to round a result to the nearest epsilon: * - * COMPLEX *c; (* complex number to round to nearest epsilon *) - * NUMBER *eps; (* epsilon rounding precision *) - * COMPLEX *res; (* c rounded to nearest epsilon *) - * long rnd = 24L; (* a common rounding mode *) - * bool ok_to_free; (* true ==> free c, false ==> do not free c *) + * COMPLEX *c; (* complex number to round to nearest epsilon *) + * NUMBER *eps; (* epsilon rounding precision *) + * COMPLEX *res; (* c rounded to nearest epsilon *) + * long rnd = 24L; (* a common rounding mode *) + * bool ok_to_free; (* true ==> free c, false ==> do not free c *) * - * ... + * ... * - * res = cmappr(c, eps, ok_to_free); + * res = cmappr(c, eps, ok_to_free); * * given: - * c pointer to COMPLEX value to round - * e pointer to NUMBER multiple - * rnd rounding mode - * cfree true ==> free c, false ==> do not free c + * c pointer to COMPLEX value to round + * e pointer to NUMBER multiple + * rnd rounding mode + * cfree true ==> free c, false ==> do not free c * * returns: - * allocated pointer to COMPLEX multiple of e approximation of c + * allocated pointer to COMPLEX multiple of e approximation of c */ COMPLEX * cmappr(COMPLEX *c, NUMBER *e, long rnd, bool cfree) { - COMPLEX *r; /* COMPLEX multiple of e approximation of c */ + COMPLEX *r; /* COMPLEX multiple of e approximation of c */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } - if (e == NULL) { - math_error("%s: e is NULL", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } + if (e == NULL) { + math_error("%s: e is NULL", __func__); + not_reached(); + } - /* - * allocate return result - */ - r = comalloc(); + /* + * allocate return result + */ + r = comalloc(); - /* - * round c to multiple of e - */ - qfree(r->real); - r->real = qmappr(c->real, e, rnd); - qfree(r->imag); - r->imag = qmappr(c->imag, e, rnd); + /* + * round c to multiple of e + */ + qfree(r->real); + r->real = qmappr(c->real, e, rnd); + qfree(r->imag); + r->imag = qmappr(c->imag, e, rnd); - /* - * free c if requested - */ - if (cfree == true) { - comfree(c); - } + /* + * free c if requested + */ + if (cfree == true) { + comfree(c); + } - /* - * return the allocated multiple of e approximation of c + /* + * return the allocated multiple of e approximation of c */ return r; } @@ -115,22 +115,22 @@ cmappr(COMPLEX *c, NUMBER *e, long rnd, bool cfree) COMPLEX * c_add(COMPLEX *c1, COMPLEX *c2) { - COMPLEX *r; + COMPLEX *r; - if (ciszero(c1)) - return clink(c2); - if (ciszero(c2)) - return clink(c1); - r = comalloc(); - if (!qiszero(c1->real) || !qiszero(c2->real)) { - qfree(r->real); - r->real = qqadd(c1->real, c2->real); - } - if (!qiszero(c1->imag) || !qiszero(c2->imag)) { - qfree(r->imag); - r->imag = qqadd(c1->imag, c2->imag); - } - return r; + if (ciszero(c1)) + return clink(c2); + if (ciszero(c2)) + return clink(c1); + r = comalloc(); + if (!qiszero(c1->real) || !qiszero(c2->real)) { + qfree(r->real); + r->real = qqadd(c1->real, c2->real); + } + if (!qiszero(c1->imag) || !qiszero(c2->imag)) { + qfree(r->imag); + r->imag = qqadd(c1->imag, c2->imag); + } + return r; } @@ -140,71 +140,71 @@ c_add(COMPLEX *c1, COMPLEX *c2) COMPLEX * c_sub(COMPLEX *c1, COMPLEX *c2) { - COMPLEX *r; + COMPLEX *r; - if ((c1->real == c2->real) && (c1->imag == c2->imag)) - return clink(&_czero_); - if (ciszero(c2)) - return clink(c1); - r = comalloc(); - if (!qiszero(c1->real) || !qiszero(c2->real)) { - qfree(r->real); - r->real = qsub(c1->real, c2->real); - } - if (!qiszero(c1->imag) || !qiszero(c2->imag)) { - qfree(r->imag); - r->imag = qsub(c1->imag, c2->imag); - } - return r; + if ((c1->real == c2->real) && (c1->imag == c2->imag)) + return clink(&_czero_); + if (ciszero(c2)) + return clink(c1); + r = comalloc(); + if (!qiszero(c1->real) || !qiszero(c2->real)) { + qfree(r->real); + r->real = qsub(c1->real, c2->real); + } + if (!qiszero(c1->imag) || !qiszero(c2->imag)) { + qfree(r->imag); + r->imag = qsub(c1->imag, c2->imag); + } + return r; } /* * Multiply two complex numbers. * This saves one multiplication over the obvious algorithm by - * trading it for several extra additions, as follows. Let - * q1 = (a + b) * (c + d) - * q2 = a * c - * q3 = b * d + * trading it for several extra additions, as follows. Let + * q1 = (a + b) * (c + d) + * q2 = a * c + * q3 = b * d * Then (a+bi) * (c+di) = (q2 - q3) + (q1 - q2 - q3)i. */ COMPLEX * c_mul(COMPLEX *c1, COMPLEX *c2) { - COMPLEX *r; - NUMBER *q1, *q2, *q3, *q4; + COMPLEX *r; + NUMBER *q1, *q2, *q3, *q4; - if (ciszero(c1) || ciszero(c2)) - return clink(&_czero_); - if (cisone(c1)) - return clink(c2); - if (cisone(c2)) - return clink(c1); - if (cisreal(c2)) - return c_mulq(c1, c2->real); - if (cisreal(c1)) - return c_mulq(c2, c1->real); - /* - * Need to do the full calculation. - */ - r = comalloc(); - q2 = qqadd(c1->real, c1->imag); - q3 = qqadd(c2->real, c2->imag); - q1 = qmul(q2, q3); - qfree(q2); - qfree(q3); - q2 = qmul(c1->real, c2->real); - q3 = qmul(c1->imag, c2->imag); - q4 = qqadd(q2, q3); - qfree(r->real); - r->real = qsub(q2, q3); - qfree(r->imag); - r->imag = qsub(q1, q4); - qfree(q1); - qfree(q2); - qfree(q3); - qfree(q4); - return r; + if (ciszero(c1) || ciszero(c2)) + return clink(&_czero_); + if (cisone(c1)) + return clink(c2); + if (cisone(c2)) + return clink(c1); + if (cisreal(c2)) + return c_mulq(c1, c2->real); + if (cisreal(c1)) + return c_mulq(c2, c1->real); + /* + * Need to do the full calculation. + */ + r = comalloc(); + q2 = qqadd(c1->real, c1->imag); + q3 = qqadd(c2->real, c2->imag); + q1 = qmul(q2, q3); + qfree(q2); + qfree(q3); + q2 = qmul(c1->real, c2->real); + q3 = qmul(c1->imag, c2->imag); + q4 = qqadd(q2, q3); + qfree(r->real); + r->real = qsub(q2, q3); + qfree(r->imag); + r->imag = qsub(q1, q4); + qfree(q1); + qfree(q2); + qfree(q3); + qfree(q4); + return r; } @@ -214,39 +214,39 @@ c_mul(COMPLEX *c1, COMPLEX *c2) COMPLEX * c_square(COMPLEX *c) { - COMPLEX *r; - NUMBER *q1, *q2; + COMPLEX *r; + NUMBER *q1, *q2; - if (ciszero(c)) - return clink(&_czero_); - if (cisrunit(c)) - return clink(&_cone_); - if (cisiunit(c)) - return clink(&_cnegone_); - r = comalloc(); - if (cisreal(c)) { - qfree(r->real); - r->real = qsquare(c->real); - return r; - } - if (cisimag(c)) { - qfree(r->real); - q1 = qsquare(c->imag); - r->real = qneg(q1); - qfree(q1); - return r; - } - q1 = qsquare(c->real); - q2 = qsquare(c->imag); - qfree(r->real); - r->real = qsub(q1, q2); - qfree(q1); - qfree(q2); - qfree(r->imag); - q1 = qmul(c->real, c->imag); - r->imag = qscale(q1, 1L); - qfree(q1); - return r; + if (ciszero(c)) + return clink(&_czero_); + if (cisrunit(c)) + return clink(&_cone_); + if (cisiunit(c)) + return clink(&_cnegone_); + r = comalloc(); + if (cisreal(c)) { + qfree(r->real); + r->real = qsquare(c->real); + return r; + } + if (cisimag(c)) { + qfree(r->real); + q1 = qsquare(c->imag); + r->real = qneg(q1); + qfree(q1); + return r; + } + q1 = qsquare(c->real); + q2 = qsquare(c->imag); + qfree(r->real); + r->real = qsub(q1, q2); + qfree(q1); + qfree(q2); + qfree(r->imag); + q1 = qmul(c->real, c->imag); + r->imag = qscale(q1, 1L); + qfree(q1); + return r; } @@ -256,68 +256,68 @@ c_square(COMPLEX *c) COMPLEX * c_div(COMPLEX *c1, COMPLEX *c2) { - COMPLEX *r; - NUMBER *q1, *q2, *q3, *den; + COMPLEX *r; + NUMBER *q1, *q2, *q3, *den; - if (ciszero(c2)) { - math_error("Division by zero"); - not_reached(); - } - if ((c1->real == c2->real) && (c1->imag == c2->imag)) - return clink(&_cone_); - r = comalloc(); - if (cisreal(c1) && cisreal(c2)) { - qfree(r->real); - r->real = qqdiv(c1->real, c2->real); - return r; - } - if (cisimag(c1) && cisimag(c2)) { - qfree(r->real); - r->real = qqdiv(c1->imag, c2->imag); - return r; - } - if (cisimag(c1) && cisreal(c2)) { - qfree(r->imag); - r->imag = qqdiv(c1->imag, c2->real); - return r; - } - if (cisreal(c1) && cisimag(c2)) { - qfree(r->imag); - q1 = qqdiv(c1->real, c2->imag); - r->imag = qneg(q1); - qfree(q1); - return r; - } - if (cisreal(c2)) { - qfree(r->real); - qfree(r->imag); - r->real = qqdiv(c1->real, c2->real); - r->imag = qqdiv(c1->imag, c2->real); - return r; - } - q1 = qsquare(c2->real); - q2 = qsquare(c2->imag); - den = qqadd(q1, q2); - qfree(q1); - qfree(q2); - q1 = qmul(c1->real, c2->real); - q2 = qmul(c1->imag, c2->imag); - q3 = qqadd(q1, q2); - qfree(q1); - qfree(q2); - qfree(r->real); - r->real = qqdiv(q3, den); - qfree(q3); - q1 = qmul(c1->real, c2->imag); - q2 = qmul(c1->imag, c2->real); - q3 = qsub(q2, q1); - qfree(q1); - qfree(q2); - qfree(r->imag); - r->imag = qqdiv(q3, den); - qfree(q3); - qfree(den); - return r; + if (ciszero(c2)) { + math_error("Division by zero"); + not_reached(); + } + if ((c1->real == c2->real) && (c1->imag == c2->imag)) + return clink(&_cone_); + r = comalloc(); + if (cisreal(c1) && cisreal(c2)) { + qfree(r->real); + r->real = qqdiv(c1->real, c2->real); + return r; + } + if (cisimag(c1) && cisimag(c2)) { + qfree(r->real); + r->real = qqdiv(c1->imag, c2->imag); + return r; + } + if (cisimag(c1) && cisreal(c2)) { + qfree(r->imag); + r->imag = qqdiv(c1->imag, c2->real); + return r; + } + if (cisreal(c1) && cisimag(c2)) { + qfree(r->imag); + q1 = qqdiv(c1->real, c2->imag); + r->imag = qneg(q1); + qfree(q1); + return r; + } + if (cisreal(c2)) { + qfree(r->real); + qfree(r->imag); + r->real = qqdiv(c1->real, c2->real); + r->imag = qqdiv(c1->imag, c2->real); + return r; + } + q1 = qsquare(c2->real); + q2 = qsquare(c2->imag); + den = qqadd(q1, q2); + qfree(q1); + qfree(q2); + q1 = qmul(c1->real, c2->real); + q2 = qmul(c1->imag, c2->imag); + q3 = qqadd(q1, q2); + qfree(q1); + qfree(q2); + qfree(r->real); + r->real = qqdiv(q3, den); + qfree(q3); + q1 = qmul(c1->real, c2->imag); + q2 = qmul(c1->imag, c2->real); + q3 = qsub(q2, q1); + qfree(q1); + qfree(q2); + qfree(r->imag); + r->imag = qqdiv(q3, den); + qfree(q3); + qfree(den); + return r; } @@ -327,39 +327,39 @@ c_div(COMPLEX *c1, COMPLEX *c2) COMPLEX * c_inv(COMPLEX *c) { - COMPLEX *r; - NUMBER *q1, *q2, *den; + COMPLEX *r; + NUMBER *q1, *q2, *den; - if (ciszero(c)) { - math_error("Inverting zero"); - not_reached(); - } - r = comalloc(); - if (cisreal(c)) { - qfree(r->real); - r->real = qinv(c->real); - return r; - } - if (cisimag(c)) { - q1 = qinv(c->imag); - qfree(r->imag); - r->imag = qneg(q1); - qfree(q1); - return r; - } - q1 = qsquare(c->real); - q2 = qsquare(c->imag); - den = qqadd(q1, q2); - qfree(q1); - qfree(q2); - qfree(r->real); - r->real = qqdiv(c->real, den); - q1 = qqdiv(c->imag, den); - qfree(r->imag); - r->imag = qneg(q1); - qfree(q1); - qfree(den); - return r; + if (ciszero(c)) { + math_error("Inverting zero"); + not_reached(); + } + r = comalloc(); + if (cisreal(c)) { + qfree(r->real); + r->real = qinv(c->real); + return r; + } + if (cisimag(c)) { + q1 = qinv(c->imag); + qfree(r->imag); + r->imag = qneg(q1); + qfree(q1); + return r; + } + q1 = qsquare(c->real); + q2 = qsquare(c->imag); + den = qqadd(q1, q2); + qfree(q1); + qfree(q2); + qfree(r->real); + r->real = qqdiv(c->real, den); + q1 = qqdiv(c->imag, den); + qfree(r->imag); + r->imag = qneg(q1); + qfree(q1); + qfree(den); + return r; } @@ -369,20 +369,20 @@ c_inv(COMPLEX *c) COMPLEX * c_neg(COMPLEX *c) { - COMPLEX *r; + COMPLEX *r; - if (ciszero(c)) - return clink(&_czero_); - r = comalloc(); - if (!qiszero(c->real)) { - qfree(r->real); - r->real = qneg(c->real); - } - if (!qiszero(c->imag)) { - qfree(r->imag); - r->imag = qneg(c->imag); - } - return r; + if (ciszero(c)) + return clink(&_czero_); + r = comalloc(); + if (!qiszero(c->real)) { + qfree(r->real); + r->real = qneg(c->real); + } + if (!qiszero(c->imag)) { + qfree(r->imag); + r->imag = qneg(c->imag); + } + return r; } @@ -393,16 +393,16 @@ c_neg(COMPLEX *c) COMPLEX * c_int(COMPLEX *c) { - COMPLEX *r; + COMPLEX *r; - if (cisint(c)) - return clink(c); - r = comalloc(); - qfree(r->real); - r->real = qint(c->real); - qfree(r->imag); - r->imag = qint(c->imag); - return r; + if (cisint(c)) + return clink(c); + r = comalloc(); + qfree(r->real); + r->real = qint(c->real); + qfree(r->imag); + r->imag = qint(c->imag); + return r; } @@ -413,16 +413,16 @@ c_int(COMPLEX *c) COMPLEX * c_frac(COMPLEX *c) { - COMPLEX *r; + COMPLEX *r; - if (cisint(c)) - return clink(&_czero_); - r = comalloc(); - qfree(r->real); - r->real = qfrac(c->real); - qfree(r->imag); - r->imag = qfrac(c->imag); - return r; + if (cisint(c)) + return clink(&_czero_); + r = comalloc(); + qfree(r->real); + r->real = qfrac(c->real); + qfree(r->imag); + r->imag = qfrac(c->imag); + return r; } @@ -433,18 +433,18 @@ c_frac(COMPLEX *c) COMPLEX * c_conj(COMPLEX *c) { - COMPLEX *r; + COMPLEX *r; - if (cisreal(c)) - return clink(c); - r = comalloc(); - if (!qiszero(c->real)) { - qfree(r->real); - r->real = qlink(c->real); - } - qfree(r->imag); - r->imag = qneg(c->imag); - return r; + if (cisreal(c)) + return clink(c); + r = comalloc(); + if (!qiszero(c->real)) { + qfree(r->real); + r->real = qlink(c->real); + } + qfree(r->imag); + r->imag = qneg(c->imag); + return r; } @@ -454,16 +454,16 @@ c_conj(COMPLEX *c) COMPLEX * c_real(COMPLEX *c) { - COMPLEX *r; + COMPLEX *r; - if (cisreal(c)) - return clink(c); - r = comalloc(); - if (!qiszero(c->real)) { - qfree(r->real); - r->real = qlink(c->real); - } - return r; + if (cisreal(c)) + return clink(c); + r = comalloc(); + if (!qiszero(c->real)) { + qfree(r->real); + r->real = qlink(c->real); + } + return r; } @@ -471,58 +471,58 @@ c_real(COMPLEX *c) * c_to_q - convert a real part of a COMPLEX to a NUMBER * * given: - * c complex number for which the real part will be used - * cfree true ==> free c, false ==> do not free c + * c complex number for which the real part will be used + * cfree true ==> free c, false ==> do not free c * * returns: - * allocated NUMBER that the equivalent of the real part of a complex number + * allocated NUMBER that the equivalent of the real part of a complex number * * NOTE: Any imaginary part of the COMPLEX value is ignored. * * NOTE: To avoid a loss of value, test with cisreal(c) first: * - * COMPLEX *c; - * NUMBER *q; - * bool ok_to_free; + * COMPLEX *c; + * NUMBER *q; + * bool ok_to_free; * - * if (cisreal(c)) { - * q = c_to_q(c, ok_to_free); - * } + * if (cisreal(c)) { + * q = c_to_q(c, ok_to_free); + * } */ NUMBER * c_to_q(COMPLEX *c, bool cfree) { - NUMBER *r; /* allocated NUMBER equivalent to return */ + NUMBER *r; /* allocated NUMBER equivalent to return */ - /* - * firewall - */ - if (c == NULL) { - math_error("%s: c is NULL", __func__); - not_reached(); - } + /* + * firewall + */ + if (c == NULL) { + math_error("%s: c is NULL", __func__); + not_reached(); + } - /* - * allocate a new NUMBER - */ - r = qalloc(); + /* + * allocate a new NUMBER + */ + r = qalloc(); - /* - * link in the real part of the COMPLEX value - */ - r = qlink(c->real); + /* + * link in the real part of the COMPLEX value + */ + r = qlink(c->real); - /* - * free c if requested - */ - if (cfree == true) { - comfree(c); - } + /* + * free c if requested + */ + if (cfree == true) { + comfree(c); + } - /* - * return the allocated equivalent NUMBER - */ - return r; + /* + * return the allocated equivalent NUMBER + */ + return r; } @@ -530,31 +530,31 @@ c_to_q(COMPLEX *c, bool cfree) * q_to_c - convert a NUMBER into an allocated COMPLEX * * given: - * q NUMBER to be converted + * q NUMBER to be converted * * returns: - * allocated COMPLEX number whose real part is NUMBER and imag part is 0 + * allocated COMPLEX number whose real part is NUMBER and imag part is 0 */ COMPLEX * q_to_c(NUMBER *q) { - COMPLEX *res; /* COMPLEX number to return */ + COMPLEX *res; /* COMPLEX number to return */ - /* - * allocate complex number - */ - res = comalloc(); + /* + * allocate complex number + */ + res = comalloc(); - /* - * assign NUMBER to real part - */ - qfree(res->real); - res->real = qlink(q); + /* + * assign NUMBER to real part + */ + qfree(res->real); + res->real = qlink(q); - /* - * return the allocated equivalent COMPLEX - */ - return res; + /* + * return the allocated equivalent COMPLEX + */ + return res; } @@ -564,14 +564,14 @@ q_to_c(NUMBER *q) COMPLEX * c_imag(COMPLEX *c) { - COMPLEX *r; + COMPLEX *r; - if (cisreal(c)) - return clink(&_czero_); - r = comalloc(); - qfree(r->real); - r->real = qlink(c->imag); - return r; + if (cisreal(c)) + return clink(&_czero_); + r = comalloc(); + qfree(r->real); + r->real = qlink(c->imag); + return r; } @@ -581,16 +581,16 @@ c_imag(COMPLEX *c) COMPLEX * c_addq(COMPLEX *c, NUMBER *q) { - COMPLEX *r; + COMPLEX *r; - if (qiszero(q)) - return clink(c); - r = comalloc(); - qfree(r->real); - qfree(r->imag); - r->real = qqadd(c->real, q); - r->imag = qlink(c->imag); - return r; + if (qiszero(q)) + return clink(c); + r = comalloc(); + qfree(r->real); + qfree(r->imag); + r->real = qqadd(c->real, q); + r->imag = qlink(c->imag); + return r; } @@ -600,16 +600,16 @@ c_addq(COMPLEX *c, NUMBER *q) COMPLEX * c_subq(COMPLEX *c, NUMBER *q) { - COMPLEX *r; + COMPLEX *r; - if (qiszero(q)) - return clink(c); - r = comalloc(); - qfree(r->real); - qfree(r->imag); - r->real = qsub(c->real, q); - r->imag = qlink(c->imag); - return r; + if (qiszero(q)) + return clink(c); + r = comalloc(); + qfree(r->real); + qfree(r->imag); + r->real = qsub(c->real, q); + r->imag = qlink(c->imag); + return r; } @@ -620,16 +620,16 @@ c_subq(COMPLEX *c, NUMBER *q) COMPLEX * c_shift(COMPLEX *c, long n) { - COMPLEX *r; + COMPLEX *r; - if (ciszero(c) || (n == 0)) - return clink(c); - r = comalloc(); - qfree(r->real); - qfree(r->imag); - r->real = qshift(c->real, n); - r->imag = qshift(c->imag, n); - return r; + if (ciszero(c) || (n == 0)) + return clink(c); + r = comalloc(); + qfree(r->real); + qfree(r->imag); + r->real = qshift(c->real, n); + r->imag = qshift(c->imag, n); + return r; } @@ -639,16 +639,16 @@ c_shift(COMPLEX *c, long n) COMPLEX * c_scale(COMPLEX *c, long n) { - COMPLEX *r; + COMPLEX *r; - if (ciszero(c) || (n == 0)) - return clink(c); - r = comalloc(); - qfree(r->real); - qfree(r->imag); - r->real = qscale(c->real, n); - r->imag = qscale(c->imag, n); - return r; + if (ciszero(c) || (n == 0)) + return clink(c); + r = comalloc(); + qfree(r->real); + qfree(r->imag); + r->real = qscale(c->real, n); + r->imag = qscale(c->imag, n); + return r; } @@ -658,20 +658,20 @@ c_scale(COMPLEX *c, long n) COMPLEX * c_mulq(COMPLEX *c, NUMBER *q) { - COMPLEX *r; + COMPLEX *r; - if (qiszero(q)) - return clink(&_czero_); - if (qisone(q)) - return clink(c); - if (qisnegone(q)) - return c_neg(c); - r = comalloc(); - qfree(r->real); - qfree(r->imag); - r->real = qmul(c->real, q); - r->imag = qmul(c->imag, q); - return r; + if (qiszero(q)) + return clink(&_czero_); + if (qisone(q)) + return clink(c); + if (qisnegone(q)) + return c_neg(c); + r = comalloc(); + qfree(r->real); + qfree(r->imag); + r->real = qmul(c->real, q); + r->imag = qmul(c->imag, q); + return r; } @@ -681,22 +681,22 @@ c_mulq(COMPLEX *c, NUMBER *q) COMPLEX * c_divq(COMPLEX *c, NUMBER *q) { - COMPLEX *r; + COMPLEX *r; - if (qiszero(q)) { - math_error("Division by zero"); - not_reached(); - } - if (qisone(q)) - return clink(c); - if (qisnegone(q)) - return c_neg(c); - r = comalloc(); - qfree(r->real); - qfree(r->imag); - r->real = qqdiv(c->real, q); - r->imag = qqdiv(c->imag, q); - return r; + if (qiszero(q)) { + math_error("Division by zero"); + not_reached(); + } + if (qisone(q)) + return clink(c); + if (qisnegone(q)) + return c_neg(c); + r = comalloc(); + qfree(r->real); + qfree(r->imag); + r->real = qqdiv(c->real, q); + r->imag = qqdiv(c->imag, q); + return r; } @@ -708,16 +708,16 @@ c_divq(COMPLEX *c, NUMBER *q) COMPLEX * qqtoc(NUMBER *q1, NUMBER *q2) { - COMPLEX *r; + COMPLEX *r; - if (qiszero(q1) && qiszero(q2)) - return clink(&_czero_); - r = comalloc(); - qfree(r->real); - qfree(r->imag); - r->real = qlink(q1); - r->imag = qlink(q2); - return r; + if (qiszero(q1) && qiszero(q2)) + return clink(&_czero_); + r = comalloc(); + qfree(r->real); + qfree(r->imag); + r->real = qlink(q1); + r->imag = qlink(q2); + return r; } @@ -728,12 +728,12 @@ qqtoc(NUMBER *q1, NUMBER *q2) bool c_cmp(COMPLEX *c1, COMPLEX *c2) { - bool i; + bool i; - i = qcmp(c1->real, c2->real); - if (!i) - i = qcmp(c1->imag, c2->imag); - return i; + i = qcmp(c1->real, c2->real); + if (!i) + i = qcmp(c1->imag, c2->imag); + return i; } @@ -745,15 +745,15 @@ c_cmp(COMPLEX *c1, COMPLEX *c2) COMPLEX * c_rel(COMPLEX *c1, COMPLEX *c2) { - COMPLEX *c; + COMPLEX *c; - c = comalloc(); - qfree(c->real); - qfree(c->imag); - c->real = itoq((long) qrel(c1->real, c2->real)); - c->imag = itoq((long) qrel(c1->imag, c2->imag)); + c = comalloc(); + qfree(c->real); + qfree(c->imag); + c->real = itoq((long) qrel(c1->real, c2->real)); + c->imag = itoq((long) qrel(c1->imag, c2->imag)); - return c; + return c; } @@ -763,17 +763,17 @@ c_rel(COMPLEX *c1, COMPLEX *c2) COMPLEX * comalloc(void) { - COMPLEX *r; + COMPLEX *r; - r = (COMPLEX *) malloc(sizeof(COMPLEX)); - if (r == NULL) { - math_error("Cannot allocate complex number"); - not_reached(); - } - r->links = 1; - r->real = qlink(&_qzero_); - r->imag = qlink(&_qzero_); - return r; + r = (COMPLEX *) malloc(sizeof(COMPLEX)); + if (r == NULL) { + math_error("Cannot allocate complex number"); + not_reached(); + } + r->links = 1; + r->real = qlink(&_qzero_); + r->imag = qlink(&_qzero_); + return r; } @@ -783,9 +783,9 @@ comalloc(void) void comfree(COMPLEX *c) { - if (--(c->links) > 0) - return; - qfree(c->real); - qfree(c->imag); - free(c); + if (--(c->links) > 0) + return; + qfree(c->real); + qfree(c->imag); + free(c); } diff --git a/config.c b/config.c index 62fbb44..b1040e4 100644 --- a/config.c +++ b/config.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1991/07/20 00:21:56 - * File existed as early as: 1991 + * Under source code control: 1991/07/20 00:21:56 + * File existed as early as: 1991 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -63,7 +63,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* @@ -72,7 +72,7 @@ #if defined(CLK_TCK) # define CALC_HZ ((long)(CLK_TCK)) #else -# define CALC_HZ (0L) /* no defined clock tick rate */ +# define CALC_HZ (0L) /* no defined clock tick rate */ #endif @@ -80,224 +80,224 @@ * Table of configuration types that can be set or read. */ NAMETYPE configs[] = { - {"all", CONFIG_ALL}, - {"mode", CONFIG_MODE}, - {"mode2", CONFIG_MODE2}, - {"display", CONFIG_DISPLAY}, - {"epsilon", CONFIG_EPSILON}, - /*epsilonprec -- tied to epsilon not a configuration type*/ - {"trace", CONFIG_TRACE}, - {"maxprint", CONFIG_MAXPRINT}, - {"mul2", CONFIG_MUL2}, - {"sq2", CONFIG_SQ2}, - {"pow2", CONFIG_POW2}, - {"redc2", CONFIG_REDC2}, - {"tilde", CONFIG_TILDE}, - {"tilde_space", CONFIG_TILDE_SPACE}, - {"fraction_space", CONFIG_FRACTION_SPACE}, - {"complex_space", CONFIG_COMPLEX_SPACE}, - {"tab", CONFIG_TAB}, - {"quomod", CONFIG_QUOMOD}, - {"quo", CONFIG_QUO}, - {"mod", CONFIG_MOD}, - {"sqrt", CONFIG_SQRT}, - {"appr", CONFIG_APPR}, - {"cfappr", CONFIG_CFAPPR}, - {"cfsim", CONFIG_CFSIM}, - {"outround", CONFIG_OUTROUND}, - {"round", CONFIG_ROUND}, - {"triground", CONFIG_TRIGROUND}, - {"leadzero", CONFIG_LEADZERO}, - {"fullzero", CONFIG_FULLZERO}, - {"maxscan", CONFIG_MAXSCAN}, - {"maxerr", CONFIG_MAXSCAN}, /* old name for maxscan */ - {"prompt", CONFIG_PROMPT}, - {"more", CONFIG_MORE}, - {"blkmaxprint", CONFIG_BLKMAXPRINT}, - {"blkverbose", CONFIG_BLKVERBOSE}, - {"blkbase", CONFIG_BLKBASE}, - {"blkfmt", CONFIG_BLKFMT}, - {"resource_debug", CONFIG_RESOURCE_DEBUG}, - {"lib_debug", CONFIG_RESOURCE_DEBUG}, - {"calc_debug", CONFIG_CALC_DEBUG}, - {"user_debug", CONFIG_USER_DEBUG}, - {"verbose_quit",CONFIG_VERBOSE_QUIT}, - {"ctrl_d", CONFIG_CTRL_D}, - {"ctrl-d", CONFIG_CTRL_D}, /* alias for ctrl_d */ - {"program", CONFIG_PROGRAM}, - {"basename", CONFIG_BASENAME}, - {"windows", CONFIG_WINDOWS}, - {"cygwin", CONFIG_CYGWIN}, - {"compile_custom", CONFIG_COMPILE_CUSTOM}, - {"allow_custom", CONFIG_ALLOW_CUSTOM}, - {"version", CONFIG_VERSION}, - {"baseb", CONFIG_BASEB}, - {"redecl_warn", CONFIG_REDECL_WARN}, - {"dupvar_warn", CONFIG_DUPVAR_WARN}, - {"hz", CONFIG_HZ}, - {NULL, 0} + {"all", CONFIG_ALL}, + {"mode", CONFIG_MODE}, + {"mode2", CONFIG_MODE2}, + {"display", CONFIG_DISPLAY}, + {"epsilon", CONFIG_EPSILON}, + /*epsilonprec -- tied to epsilon not a configuration type*/ + {"trace", CONFIG_TRACE}, + {"maxprint", CONFIG_MAXPRINT}, + {"mul2", CONFIG_MUL2}, + {"sq2", CONFIG_SQ2}, + {"pow2", CONFIG_POW2}, + {"redc2", CONFIG_REDC2}, + {"tilde", CONFIG_TILDE}, + {"tilde_space", CONFIG_TILDE_SPACE}, + {"fraction_space", CONFIG_FRACTION_SPACE}, + {"complex_space", CONFIG_COMPLEX_SPACE}, + {"tab", CONFIG_TAB}, + {"quomod", CONFIG_QUOMOD}, + {"quo", CONFIG_QUO}, + {"mod", CONFIG_MOD}, + {"sqrt", CONFIG_SQRT}, + {"appr", CONFIG_APPR}, + {"cfappr", CONFIG_CFAPPR}, + {"cfsim", CONFIG_CFSIM}, + {"outround", CONFIG_OUTROUND}, + {"round", CONFIG_ROUND}, + {"triground", CONFIG_TRIGROUND}, + {"leadzero", CONFIG_LEADZERO}, + {"fullzero", CONFIG_FULLZERO}, + {"maxscan", CONFIG_MAXSCAN}, + {"maxerr", CONFIG_MAXSCAN}, /* old name for maxscan */ + {"prompt", CONFIG_PROMPT}, + {"more", CONFIG_MORE}, + {"blkmaxprint", CONFIG_BLKMAXPRINT}, + {"blkverbose", CONFIG_BLKVERBOSE}, + {"blkbase", CONFIG_BLKBASE}, + {"blkfmt", CONFIG_BLKFMT}, + {"resource_debug", CONFIG_RESOURCE_DEBUG}, + {"lib_debug", CONFIG_RESOURCE_DEBUG}, + {"calc_debug", CONFIG_CALC_DEBUG}, + {"user_debug", CONFIG_USER_DEBUG}, + {"verbose_quit",CONFIG_VERBOSE_QUIT}, + {"ctrl_d", CONFIG_CTRL_D}, + {"ctrl-d", CONFIG_CTRL_D}, /* alias for ctrl_d */ + {"program", CONFIG_PROGRAM}, + {"basename", CONFIG_BASENAME}, + {"windows", CONFIG_WINDOWS}, + {"cygwin", CONFIG_CYGWIN}, + {"compile_custom", CONFIG_COMPILE_CUSTOM}, + {"allow_custom", CONFIG_ALLOW_CUSTOM}, + {"version", CONFIG_VERSION}, + {"baseb", CONFIG_BASEB}, + {"redecl_warn", CONFIG_REDECL_WARN}, + {"dupvar_warn", CONFIG_DUPVAR_WARN}, + {"hz", CONFIG_HZ}, + {NULL, 0} }; /* * configurations */ -CONFIG oldstd = { /* backward compatible standard configuration */ - MODE_INITIAL, /* current output mode */ - MODE2_INITIAL, /* current secondary output mode */ - 20, /* current output digits for float or exp */ - NULL, /* loaded in at startup - default error for real functions */ - EPSILONPREC_DEFAULT, /* binary precision of epsilon */ - false, /* tracing flags */ - MAXPRINT_DEFAULT, /* number of elements to print */ - MUL_ALG2, /* size of number to use multiply alg 2 */ - SQ_ALG2, /* size of number to use square alg 2 */ - POW_ALG2, /* size of modulus to use REDC for powers */ - REDC_ALG2, /* size of modulus to use REDC algorithm 2 */ - true, /* true ==> print a tilde on approximations */ - false, /* true ==> print a space after tilde on approximations */ - false, /* true ==> print spaces around / in fractions */ - false, /* true ==> print spaces around + or - in complex values */ - true, /* true ==> print tab before numeric values */ - 0, /* quomod() default rounding mode */ - 2, /* quotient // default rounding mode */ - 0, /* mod % default rounding mode */ - 24, /* sqrt() default rounding mode */ - 24, /* appr() default rounding mode */ - 0, /* cfappr() default rounding mode */ - 8, /* cfsim() default rounding mode */ - 2, /* output default rounding mode */ - 24, /* round()/bround() default rounding mode */ - 24, /* trigonometric and hyperbolic function rounding mode */ - false, /* true ==> print leading 0 before decimal pt */ - 0, /* true ==> print trailing 0's */ - MAXSCANCOUNT, /* max scan errors before abort */ - PROMPT1, /* normal prompt */ - PROMPT2, /* prompt when inside multi-line input */ - BLK_DEF_MAXPRINT, /* number of octets of a block to print */ - false, /* skip duplicate block output lines */ - BLK_BASE_HEX, /* block octet print base */ - BLK_FMT_HD_STYLE, /* block output format */ - 0, /* internal calc debug level */ - 3, /* calc resource file debug level */ - 0, /* user defined debug level */ - false, /* true ==> print Quit or abort executed messages */ - CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */ - NULL, /* our name */ - NULL, /* basename of our name */ +CONFIG oldstd = { /* backward compatible standard configuration */ + MODE_INITIAL, /* current output mode */ + MODE2_INITIAL, /* current secondary output mode */ + 20, /* current output digits for float or exp */ + NULL, /* loaded in at startup - default error for real functions */ + EPSILONPREC_DEFAULT, /* binary precision of epsilon */ + false, /* tracing flags */ + MAXPRINT_DEFAULT, /* number of elements to print */ + MUL_ALG2, /* size of number to use multiply alg 2 */ + SQ_ALG2, /* size of number to use square alg 2 */ + POW_ALG2, /* size of modulus to use REDC for powers */ + REDC_ALG2, /* size of modulus to use REDC algorithm 2 */ + true, /* true ==> print a tilde on approximations */ + false, /* true ==> print a space after tilde on approximations */ + false, /* true ==> print spaces around / in fractions */ + false, /* true ==> print spaces around + or - in complex values */ + true, /* true ==> print tab before numeric values */ + 0, /* quomod() default rounding mode */ + 2, /* quotient // default rounding mode */ + 0, /* mod % default rounding mode */ + 24, /* sqrt() default rounding mode */ + 24, /* appr() default rounding mode */ + 0, /* cfappr() default rounding mode */ + 8, /* cfsim() default rounding mode */ + 2, /* output default rounding mode */ + 24, /* round()/bround() default rounding mode */ + 24, /* trigonometric and hyperbolic function rounding mode */ + false, /* true ==> print leading 0 before decimal pt */ + 0, /* true ==> print trailing 0's */ + MAXSCANCOUNT, /* max scan errors before abort */ + PROMPT1, /* normal prompt */ + PROMPT2, /* prompt when inside multi-line input */ + BLK_DEF_MAXPRINT, /* number of octets of a block to print */ + false, /* skip duplicate block output lines */ + BLK_BASE_HEX, /* block octet print base */ + BLK_FMT_HD_STYLE, /* block output format */ + 0, /* internal calc debug level */ + 3, /* calc resource file debug level */ + 0, /* user defined debug level */ + false, /* true ==> print Quit or abort executed messages */ + CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */ + NULL, /* our name */ + NULL, /* basename of our name */ #if defined(_WIN32) || defined(_WIN64) - true, /* true ==> running under windows */ + true, /* true ==> running under windows */ #else - false, /* false ==> not using windows */ + false, /* false ==> not using windows */ #endif #if defined(__CYGWIN__) - true, /* true ==> compiled under cygwin */ + true, /* true ==> compiled under cygwin */ #else - false, /* false ==> not compiled with cygwin */ + false, /* false ==> not compiled with cygwin */ #endif #if defined(CUSTOM) - true, /* true ==> compiled with -DCUSTOM */ + true, /* true ==> compiled with -DCUSTOM */ #else - false, /* false ==> compiled without -DCUSTOM */ + false, /* false ==> compiled without -DCUSTOM */ #endif - &allow_custom, /* *true=> custom functions are enabled */ - NULL, /* version */ - BASEB, /* base for calculations */ - true, /* true ==> warn when redeclaring */ - true, /* true ==> warn when variable names collide */ + &allow_custom, /* *true=> custom functions are enabled */ + NULL, /* version */ + BASEB, /* base for calculations */ + true, /* true ==> warn when redeclaring */ + true, /* true ==> warn when variable names collide */ }; -CONFIG newstd = { /* new non-backward compatible configuration */ - MODE_INITIAL, /* current output mode */ - MODE2_INITIAL, /* current output mode */ - 20, /* current output digits for float or exp */ - NULL, /* loaded in at startup - default error for real functions */ - EPSILONPREC_DEFAULT, /* binary precision of epsilon */ - false, /* tracing flags */ - MAXPRINT_DEFAULT, /* number of elements to print */ - MUL_ALG2, /* size of number to use multiply alg 2 */ - SQ_ALG2, /* size of number to use square alg 2 */ - POW_ALG2, /* size of modulus to use REDC for powers */ - REDC_ALG2, /* size of modulus to use REDC algorithm 2 */ - true, /* true ==> print a tilde on approximations */ - false, /* true ==> print spaces around / in fractions */ - false, /* true ==> print a space after tilde on approximations */ - false, /* true ==> print spaces around + or - in complex values */ - true, /* true ==> print tab before numeric values */ - 0, /* quomod() default rounding mode */ - 2, /* quotient // default rounding mode */ - 0, /* mod % default rounding mode */ - 24, /* sqrt() default rounding mode */ - 24, /* appr() default rounding mode */ - 0, /* cfappr() default rounding mode */ - 8, /* cfsim() default rounding mode */ - 24, /* output default rounding mode */ - 24, /* round()/bround() default rounding mode */ - 24, /* trigonometric and hyperbolic function rounding mode */ - true, /* true ==> print leading 0 before decimal pt */ - 0, /* true ==> print trailing 0's */ - MAXSCANCOUNT, /* max scan errors before abort */ - "; ", /* normal prompt */ - ";; ", /* prompt when inside multi-line input */ - BLK_DEF_MAXPRINT, /* number of octets of a block to print */ - false, /* skip duplicate block output lines */ - BLK_BASE_HEX, /* block octet print base */ - BLK_FMT_HD_STYLE, /* block output format */ - 0, /* internal calc debug level */ - 3, /* calc resource file debug level */ - 0, /* user defined debug level */ - false, /* true ==> print Quit or abort executed messages */ - CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */ - NULL, /* our name */ - NULL, /* basename of our name */ +CONFIG newstd = { /* new non-backward compatible configuration */ + MODE_INITIAL, /* current output mode */ + MODE2_INITIAL, /* current output mode */ + 20, /* current output digits for float or exp */ + NULL, /* loaded in at startup - default error for real functions */ + EPSILONPREC_DEFAULT, /* binary precision of epsilon */ + false, /* tracing flags */ + MAXPRINT_DEFAULT, /* number of elements to print */ + MUL_ALG2, /* size of number to use multiply alg 2 */ + SQ_ALG2, /* size of number to use square alg 2 */ + POW_ALG2, /* size of modulus to use REDC for powers */ + REDC_ALG2, /* size of modulus to use REDC algorithm 2 */ + true, /* true ==> print a tilde on approximations */ + false, /* true ==> print spaces around / in fractions */ + false, /* true ==> print a space after tilde on approximations */ + false, /* true ==> print spaces around + or - in complex values */ + true, /* true ==> print tab before numeric values */ + 0, /* quomod() default rounding mode */ + 2, /* quotient // default rounding mode */ + 0, /* mod % default rounding mode */ + 24, /* sqrt() default rounding mode */ + 24, /* appr() default rounding mode */ + 0, /* cfappr() default rounding mode */ + 8, /* cfsim() default rounding mode */ + 24, /* output default rounding mode */ + 24, /* round()/bround() default rounding mode */ + 24, /* trigonometric and hyperbolic function rounding mode */ + true, /* true ==> print leading 0 before decimal pt */ + 0, /* true ==> print trailing 0's */ + MAXSCANCOUNT, /* max scan errors before abort */ + "; ", /* normal prompt */ + ";; ", /* prompt when inside multi-line input */ + BLK_DEF_MAXPRINT, /* number of octets of a block to print */ + false, /* skip duplicate block output lines */ + BLK_BASE_HEX, /* block octet print base */ + BLK_FMT_HD_STYLE, /* block output format */ + 0, /* internal calc debug level */ + 3, /* calc resource file debug level */ + 0, /* user defined debug level */ + false, /* true ==> print Quit or abort executed messages */ + CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */ + NULL, /* our name */ + NULL, /* basename of our name */ #if defined(_WIN32) || defined(_WIN64) - true, /* true ==> running under windows */ + true, /* true ==> running under windows */ #else - false, /* false ==> not using windows */ + false, /* false ==> not using windows */ #endif #if defined(__CYGWIN__) - true, /* true ==> compiled under cygwin */ + true, /* true ==> compiled under cygwin */ #else - false, /* false ==> not compiled with cygwin */ + false, /* false ==> not compiled with cygwin */ #endif #if defined(CUSTOM) - true, /* true ==> compiled with -DCUSTOM */ + true, /* true ==> compiled with -DCUSTOM */ #else - false, /* false ==> compiled without -DCUSTOM */ + false, /* false ==> compiled without -DCUSTOM */ #endif - &allow_custom, /* *true ==> custom functions are enabled */ - NULL, /* version */ - BASEB, /* base for calculations */ - true, /* true ==> warn when redeclaring */ - true, /* true ==> warn when variable names collide */ + &allow_custom, /* *true ==> custom functions are enabled */ + NULL, /* version */ + BASEB, /* base for calculations */ + true, /* true ==> warn when redeclaring */ + true, /* true ==> warn when variable names collide */ }; -CONFIG *conf = NULL; /* loaded in at startup - current configuration */ +CONFIG *conf = NULL; /* loaded in at startup - current configuration */ /* * Possible output modes. */ STATIC NAMETYPE modes[] = { - {"fraction", MODE_FRAC}, - {"frac", MODE_FRAC}, - {"integer", MODE_INT}, - {"int", MODE_INT}, - {"real", MODE_REAL}, - {"float", MODE_REAL}, - {"default", MODE_INITIAL}, /* MODE_REAL */ - {"scientific", MODE_EXP}, - {"sci", MODE_EXP}, - {"exp", MODE_EXP}, - {"engineering", MODE_ENG}, - {"eng", MODE_ENG}, - {"hexadecimal", MODE_HEX}, - {"hex", MODE_HEX}, - {"octal", MODE_OCTAL}, - {"oct", MODE_OCTAL}, - {"binary", MODE_BINARY}, - {"bin", MODE_BINARY}, - {"float-auto", MODE_REAL_AUTO}, - {"off", MODE2_OFF}, - {NULL, 0} + {"fraction", MODE_FRAC}, + {"frac", MODE_FRAC}, + {"integer", MODE_INT}, + {"int", MODE_INT}, + {"real", MODE_REAL}, + {"float", MODE_REAL}, + {"default", MODE_INITIAL}, /* MODE_REAL */ + {"scientific", MODE_EXP}, + {"sci", MODE_EXP}, + {"exp", MODE_EXP}, + {"engineering", MODE_ENG}, + {"eng", MODE_ENG}, + {"hexadecimal", MODE_HEX}, + {"hex", MODE_HEX}, + {"octal", MODE_OCTAL}, + {"oct", MODE_OCTAL}, + {"binary", MODE_BINARY}, + {"bin", MODE_BINARY}, + {"float-auto", MODE_REAL_AUTO}, + {"off", MODE2_OFF}, + {NULL, 0} }; @@ -305,18 +305,18 @@ STATIC NAMETYPE modes[] = { * Possible block base output modes */ STATIC NAMETYPE blk_base[] = { - {"hexadecimal", BLK_BASE_HEX}, - {"hex", BLK_BASE_HEX}, - {"default", BLK_BASE_HEX}, - {"octal", BLK_BASE_OCT}, - {"oct", BLK_BASE_OCT}, - {"character", BLK_BASE_CHAR}, - {"char", BLK_BASE_CHAR}, - {"binary", BLK_BASE_BINARY}, - {"bin", BLK_BASE_BINARY}, - {"raw", BLK_BASE_RAW}, - {"none", BLK_BASE_RAW}, - {NULL, 0} + {"hexadecimal", BLK_BASE_HEX}, + {"hex", BLK_BASE_HEX}, + {"default", BLK_BASE_HEX}, + {"octal", BLK_BASE_OCT}, + {"oct", BLK_BASE_OCT}, + {"character", BLK_BASE_CHAR}, + {"char", BLK_BASE_CHAR}, + {"binary", BLK_BASE_BINARY}, + {"bin", BLK_BASE_BINARY}, + {"raw", BLK_BASE_RAW}, + {"none", BLK_BASE_RAW}, + {NULL, 0} }; @@ -324,19 +324,19 @@ STATIC NAMETYPE blk_base[] = { * Possible block output formats */ STATIC NAMETYPE blk_fmt[] = { - {"lines", BLK_FMT_LINE}, - {"line", BLK_FMT_LINE}, - {"strings", BLK_FMT_STRING}, - {"string", BLK_FMT_STRING}, - {"str", BLK_FMT_STRING}, - {"od_style", BLK_FMT_OD_STYLE}, - {"odstyle", BLK_FMT_OD_STYLE}, - {"od", BLK_FMT_OD_STYLE}, - {"hd_style", BLK_FMT_HD_STYLE}, - {"hdstyle", BLK_FMT_HD_STYLE}, - {"hd", BLK_FMT_HD_STYLE}, - {"default", BLK_FMT_HD_STYLE}, - {NULL, 0} + {"lines", BLK_FMT_LINE}, + {"line", BLK_FMT_LINE}, + {"strings", BLK_FMT_STRING}, + {"string", BLK_FMT_STRING}, + {"str", BLK_FMT_STRING}, + {"od_style", BLK_FMT_OD_STYLE}, + {"odstyle", BLK_FMT_OD_STYLE}, + {"od", BLK_FMT_OD_STYLE}, + {"hd_style", BLK_FMT_HD_STYLE}, + {"hdstyle", BLK_FMT_HD_STYLE}, + {"hd", BLK_FMT_HD_STYLE}, + {"default", BLK_FMT_HD_STYLE}, + {NULL, 0} }; @@ -344,41 +344,41 @@ STATIC NAMETYPE blk_fmt[] = { * Possible ctrl_d styles */ STATIC NAMETYPE ctrl_d[] = { - {"virgin_eof", CTRL_D_VIRGIN_EOF}, - {"virgineof", CTRL_D_VIRGIN_EOF}, - {"virgin", CTRL_D_VIRGIN_EOF}, - {"default", CTRL_D_VIRGIN_EOF}, - {"never_eof", CTRL_D_NEVER_EOF}, - {"nevereof", CTRL_D_NEVER_EOF}, - {"never", CTRL_D_NEVER_EOF}, - {"empty_eof", CTRL_D_EMPTY_EOF}, - {"emptyeof", CTRL_D_EMPTY_EOF}, - {"empty", CTRL_D_EMPTY_EOF}, - {NULL, 0} + {"virgin_eof", CTRL_D_VIRGIN_EOF}, + {"virgineof", CTRL_D_VIRGIN_EOF}, + {"virgin", CTRL_D_VIRGIN_EOF}, + {"default", CTRL_D_VIRGIN_EOF}, + {"never_eof", CTRL_D_NEVER_EOF}, + {"nevereof", CTRL_D_NEVER_EOF}, + {"never", CTRL_D_NEVER_EOF}, + {"empty_eof", CTRL_D_EMPTY_EOF}, + {"emptyeof", CTRL_D_EMPTY_EOF}, + {"empty", CTRL_D_EMPTY_EOF}, + {NULL, 0} }; /* * Possible binary config state values */ -#define true_STRING "true" -#define false_STRING "false" +#define true_STRING "true" +#define false_STRING "false" STATIC NAMETYPE truth[] = { - {true_STRING, true}, - {"t", true}, - {"on", true}, - {"yes", true}, - {"y", true}, - {"set", true}, - {"1", true}, - {false_STRING, false}, - {"f", false}, - {"off", false}, - {"no", false}, - {"n", false}, - {"unset", false}, - {"0", false}, - {NULL, 0} + {true_STRING, true}, + {"t", true}, + {"on", true}, + {"yes", true}, + {"y", true}, + {"set", true}, + {"1", true}, + {false_STRING, false}, + {"f", false}, + {"off", false}, + {"no", false}, + {"n", false}, + {"unset", false}, + {"0", false}, + {NULL, 0} }; @@ -396,18 +396,18 @@ S_FUNC int getlen(VALUE *vp, LEN *lp); * the string is unknown. * * given: - * name configuration name + * name configuration name */ int configtype(char *name) { - NAMETYPE *cp; /* current config pointer */ + NAMETYPE *cp; /* current config pointer */ - for (cp = configs; cp->name; cp++) { - if (strcmp(cp->name, name) == 0) - return cp->type; - } - return -1; + for (cp = configs; cp->name; cp++) { + if (strcmp(cp->name, name) == 0) + return cp->type; + } + return -1; } @@ -415,22 +415,22 @@ configtype(char *name) * lookup_long - given a name and a NAMETYPE, return the int * * given: - * set the NAMESET array of name/int pairs - * name mode name + * set the NAMESET array of name/int pairs + * name mode name * * returns: - * numeric value of the name or -1 if not found + * numeric value of the name or -1 if not found */ S_FUNC long lookup_long(NAMETYPE *set, char *name) { - NAMETYPE *cp; /* current config pointer */ + NAMETYPE *cp; /* current config pointer */ - for (cp = set; cp->name; cp++) { - if (strcmp(cp->name, name) == 0) - return cp->type; - } - return -1; + for (cp = set; cp->name; cp++) { + if (strcmp(cp->name, name) == 0) + return cp->type; + } + return -1; } @@ -438,22 +438,22 @@ lookup_long(NAMETYPE *set, char *name) * lookup_name - given numeric value and a NAMETYPE, return the name * * given: - * set the NAMESET array of name/int pairs - * val numeric value to lookup + * set the NAMESET array of name/int pairs + * val numeric value to lookup * * returns: - * name of the value found of NULL + * name of the value found of NULL */ S_FUNC char * lookup_name(NAMETYPE *set, long val) { - NAMETYPE *cp; /* current config pointer */ + NAMETYPE *cp; /* current config pointer */ - for (cp = set; cp->name; cp++) { - if (val == cp->type) - return cp->name; - } - return NULL; + for (cp = set; cp->name; cp++) { + if (val == cp->type) + return cp->name; + } + return NULL; } @@ -467,14 +467,14 @@ lookup_name(NAMETYPE *set, long val) S_FUNC int getlen(VALUE *vp, LEN *lp) { - if (vp->v_type != V_NUM || !qisint(vp->v_num)) - return 1; - if (zge31b(vp->v_num->num)) - return 2; - *lp = ztoi(vp->v_num->num); - if (*lp < 0) - return -1; - return 0; + if (vp->v_type != V_NUM || !qisint(vp->v_num)) + return 1; + if (zge31b(vp->v_num->num)) + return 2; + *lp = ztoi(vp->v_num->num); + if (*lp < 0) + return -1; + return 0; } @@ -485,577 +485,577 @@ getlen(VALUE *vp, LEN *lp) void setconfig(int type, VALUE *vp) { - NUMBER *q; - CONFIG *newconf; /* new configuration to set */ - long temp; - LEN len = 0; - char *p; + NUMBER *q; + CONFIG *newconf; /* new configuration to set */ + long temp; + LEN len = 0; + char *p; - switch (type) { - case CONFIG_ALL: - newconf = NULL; /* firewall */ - if (vp->v_type == V_STR) { - if (strcmp(vp->v_str->s_str, "oldstd") == 0) { - newconf = &oldstd; - } else if (strcmp(vp->v_str->s_str, "newstd") == 0) { - newconf = &newstd; - } else { - math_error("CONFIG alias not oldstd or newstd"); - not_reached(); - } - } else if (vp->v_type != V_CONFIG) { - math_error("non-CONFIG for all"); - not_reached(); - } else { - newconf = vp->v_config; - } + switch (type) { + case CONFIG_ALL: + newconf = NULL; /* firewall */ + if (vp->v_type == V_STR) { + if (strcmp(vp->v_str->s_str, "oldstd") == 0) { + newconf = &oldstd; + } else if (strcmp(vp->v_str->s_str, "newstd") == 0) { + newconf = &newstd; + } else { + math_error("CONFIG alias not oldstd or newstd"); + not_reached(); + } + } else if (vp->v_type != V_CONFIG) { + math_error("non-CONFIG for all"); + not_reached(); + } else { + newconf = vp->v_config; + } - /* free the current configuration */ - config_free(conf); + /* free the current configuration */ + config_free(conf); - /* set the new configuration */ - conf = config_copy(newconf); - break; + /* set the new configuration */ + conf = config_copy(newconf); + break; - case CONFIG_TRACE: - if (vp->v_type != V_NUM) { - math_error("Non-numeric for trace"); - not_reached(); - } - q = vp->v_num; - temp = qtoi(q); - if (qisfrac(q) || !zistiny(q->num) || - ((unsigned long) temp > TRACE_MAX)) { - math_error("Bad trace value"); - not_reached(); - } - conf->traceflags = (FLAG)temp; - break; + case CONFIG_TRACE: + if (vp->v_type != V_NUM) { + math_error("Non-numeric for trace"); + not_reached(); + } + q = vp->v_num; + temp = qtoi(q); + if (qisfrac(q) || !zistiny(q->num) || + ((unsigned long) temp > TRACE_MAX)) { + math_error("Bad trace value"); + not_reached(); + } + conf->traceflags = (FLAG)temp; + break; - case CONFIG_DISPLAY: - if (getlen(vp, &len)) { - math_error("Bad value for display"); - not_reached(); - } - math_setdigits(len); - break; + case CONFIG_DISPLAY: + if (getlen(vp, &len)) { + math_error("Bad value for display"); + not_reached(); + } + math_setdigits(len); + break; - case CONFIG_MODE: - if (vp->v_type != V_STR) { - math_error("Non-string for mode"); - not_reached(); - } - temp = lookup_long(modes, vp->v_str->s_str); - if (temp < 0) { - math_error("Unknown mode \"%s\"", vp->v_str->s_str); - not_reached(); - } - math_setmode((int) temp); - break; + case CONFIG_MODE: + if (vp->v_type != V_STR) { + math_error("Non-string for mode"); + not_reached(); + } + temp = lookup_long(modes, vp->v_str->s_str); + if (temp < 0) { + math_error("Unknown mode \"%s\"", vp->v_str->s_str); + not_reached(); + } + math_setmode((int) temp); + break; - case CONFIG_MODE2: - if (vp->v_type != V_STR) { - math_error("Non-string for mode"); - not_reached(); - } - temp = lookup_long(modes, vp->v_str->s_str); - if (temp < 0) { - math_error("Unknown mode \"%s\"", vp->v_str->s_str); - not_reached(); - } - math_setmode2((int) temp); - break; + case CONFIG_MODE2: + if (vp->v_type != V_STR) { + math_error("Non-string for mode"); + not_reached(); + } + temp = lookup_long(modes, vp->v_str->s_str); + if (temp < 0) { + math_error("Unknown mode \"%s\"", vp->v_str->s_str); + not_reached(); + } + math_setmode2((int) temp); + break; - case CONFIG_EPSILON: - if (vp->v_type != V_NUM) { - math_error("Non-numeric for epsilon"); - not_reached(); - } - setepsilon(vp->v_num); - break; + case CONFIG_EPSILON: + if (vp->v_type != V_NUM) { + math_error("Non-numeric for epsilon"); + not_reached(); + } + setepsilon(vp->v_num); + break; - case CONFIG_MAXPRINT: - if (getlen(vp, &len)) { - math_error("Bad value for maxprint"); - not_reached(); - } - conf->maxprint = len; - break; + case CONFIG_MAXPRINT: + if (getlen(vp, &len)) { + math_error("Bad value for maxprint"); + not_reached(); + } + conf->maxprint = len; + break; - case CONFIG_MUL2: - if (getlen(vp, &len) || len < 0 || len == 1) { - math_error("Bad value for mul2"); - not_reached(); - } - if (len == 0) - len = MUL_ALG2; - conf->mul2 = len; - break; + case CONFIG_MUL2: + if (getlen(vp, &len) || len < 0 || len == 1) { + math_error("Bad value for mul2"); + not_reached(); + } + if (len == 0) + len = MUL_ALG2; + conf->mul2 = len; + break; - case CONFIG_SQ2: - if (getlen(vp, &len) || len < 0 || len == 1) { - math_error("Bad value for sq2"); - not_reached(); - } - if (len == 0) - len = SQ_ALG2; - conf->sq2 = len; - break; + case CONFIG_SQ2: + if (getlen(vp, &len) || len < 0 || len == 1) { + math_error("Bad value for sq2"); + not_reached(); + } + if (len == 0) + len = SQ_ALG2; + conf->sq2 = len; + break; - case CONFIG_POW2: - if (getlen(vp, &len) || len < 0 || len == 1) { - math_error("Bad value for pow2"); - not_reached(); - } - if (len == 0) - len = POW_ALG2; - conf->pow2 = len; - break; + case CONFIG_POW2: + if (getlen(vp, &len) || len < 0 || len == 1) { + math_error("Bad value for pow2"); + not_reached(); + } + if (len == 0) + len = POW_ALG2; + conf->pow2 = len; + break; - case CONFIG_REDC2: - if (getlen(vp, &len) || len < 0 || len == 1) { - math_error("Bad value for redc2"); - not_reached(); - } - if (len == 0) - len = REDC_ALG2; - conf->redc2 = len; - break; + case CONFIG_REDC2: + if (getlen(vp, &len) || len < 0 || len == 1) { + math_error("Bad value for redc2"); + not_reached(); + } + if (len == 0) + len = REDC_ALG2; + conf->redc2 = len; + break; - case CONFIG_TILDE: - if (vp->v_type == V_NUM) { - q = vp->v_num; - conf->tilde_ok = !qiszero(q); - } else if (vp->v_type == V_STR) { - temp = lookup_long(truth, vp->v_str->s_str); - if (temp < 0) { - math_error("Illegal truth value for tilde"); - not_reached(); - } - conf->tilde_ok = (int)temp; - } - break; + case CONFIG_TILDE: + if (vp->v_type == V_NUM) { + q = vp->v_num; + conf->tilde_ok = !qiszero(q); + } else if (vp->v_type == V_STR) { + temp = lookup_long(truth, vp->v_str->s_str); + if (temp < 0) { + math_error("Illegal truth value for tilde"); + not_reached(); + } + conf->tilde_ok = (int)temp; + } + break; - case CONFIG_TILDE_SPACE: - if (vp->v_type == V_NUM) { - q = vp->v_num; - conf->tilde_space = !qiszero(q); - } else if (vp->v_type == V_STR) { - temp = lookup_long(truth, vp->v_str->s_str); - if (temp < 0) { - math_error("Illegal truth value for tilde_space"); - not_reached(); - } - conf->tilde_space = (int)temp; - } - break; + case CONFIG_TILDE_SPACE: + if (vp->v_type == V_NUM) { + q = vp->v_num; + conf->tilde_space = !qiszero(q); + } else if (vp->v_type == V_STR) { + temp = lookup_long(truth, vp->v_str->s_str); + if (temp < 0) { + math_error("Illegal truth value for tilde_space"); + not_reached(); + } + conf->tilde_space = (int)temp; + } + break; - case CONFIG_FRACTION_SPACE: - if (vp->v_type == V_NUM) { - q = vp->v_num; - conf->fraction_space = !qiszero(q); - } else if (vp->v_type == V_STR) { - temp = lookup_long(truth, vp->v_str->s_str); - if (temp < 0) { - math_error("Illegal truth value for fraction_space"); - not_reached(); - } - conf->fraction_space = (int)temp; - } - break; + case CONFIG_FRACTION_SPACE: + if (vp->v_type == V_NUM) { + q = vp->v_num; + conf->fraction_space = !qiszero(q); + } else if (vp->v_type == V_STR) { + temp = lookup_long(truth, vp->v_str->s_str); + if (temp < 0) { + math_error("Illegal truth value for fraction_space"); + not_reached(); + } + conf->fraction_space = (int)temp; + } + break; - case CONFIG_COMPLEX_SPACE: - if (vp->v_type == V_NUM) { - q = vp->v_num; - conf->complex_space = !qiszero(q); - } else if (vp->v_type == V_STR) { - temp = lookup_long(truth, vp->v_str->s_str); - if (temp < 0) { - math_error("Illegal truth value for complex_space"); - not_reached(); - } - conf->complex_space = (int)temp; - } - break; + case CONFIG_COMPLEX_SPACE: + if (vp->v_type == V_NUM) { + q = vp->v_num; + conf->complex_space = !qiszero(q); + } else if (vp->v_type == V_STR) { + temp = lookup_long(truth, vp->v_str->s_str); + if (temp < 0) { + math_error("Illegal truth value for complex_space"); + not_reached(); + } + conf->complex_space = (int)temp; + } + break; - case CONFIG_TAB: - if (vp->v_type == V_NUM) { - q = vp->v_num; - conf->tab_ok = !qiszero(q); - } else if (vp->v_type == V_STR) { - temp = lookup_long(truth, vp->v_str->s_str); - if (temp < 0) { - math_error("Illegal truth value for tab"); - not_reached(); - } - conf->tab_ok = (int)temp; - } - break; + case CONFIG_TAB: + if (vp->v_type == V_NUM) { + q = vp->v_num; + conf->tab_ok = !qiszero(q); + } else if (vp->v_type == V_STR) { + temp = lookup_long(truth, vp->v_str->s_str); + if (temp < 0) { + math_error("Illegal truth value for tab"); + not_reached(); + } + conf->tab_ok = (int)temp; + } + break; - case CONFIG_QUOMOD: - if (getlen(vp, &len)) { - math_error("Illegal value for quomod"); - not_reached(); - } - conf->quomod = len; - break; + case CONFIG_QUOMOD: + if (getlen(vp, &len)) { + math_error("Illegal value for quomod"); + not_reached(); + } + conf->quomod = len; + break; - case CONFIG_QUO: - if (getlen(vp, &len)) { - math_error("Illegal value for quo"); - not_reached(); - } - conf->quo = len; - break; + case CONFIG_QUO: + if (getlen(vp, &len)) { + math_error("Illegal value for quo"); + not_reached(); + } + conf->quo = len; + break; - case CONFIG_MOD: - if (getlen(vp, &len)) { - math_error("Illegal value for mod"); - not_reached(); - } - conf->mod = len; - break; + case CONFIG_MOD: + if (getlen(vp, &len)) { + math_error("Illegal value for mod"); + not_reached(); + } + conf->mod = len; + break; - case CONFIG_SQRT: - if (getlen(vp, &len)) { - math_error("Illegal value for sqrt"); - not_reached(); - } - conf->sqrt = len; - break; + case CONFIG_SQRT: + if (getlen(vp, &len)) { + math_error("Illegal value for sqrt"); + not_reached(); + } + conf->sqrt = len; + break; - case CONFIG_APPR: - if (getlen(vp, &len)) { - math_error("Illegal value for appr"); - not_reached(); - } - conf->appr = len; - break; + case CONFIG_APPR: + if (getlen(vp, &len)) { + math_error("Illegal value for appr"); + not_reached(); + } + conf->appr = len; + break; - case CONFIG_CFAPPR: - if (getlen(vp, &len)) { - math_error("Illegal value for cfappr"); - not_reached(); - } - conf->cfappr = len; - break; + case CONFIG_CFAPPR: + if (getlen(vp, &len)) { + math_error("Illegal value for cfappr"); + not_reached(); + } + conf->cfappr = len; + break; - case CONFIG_CFSIM: - if (getlen(vp, &len)) { - math_error("Illegal value for cfsim"); - not_reached(); - } - conf->cfsim = len; - break; + case CONFIG_CFSIM: + if (getlen(vp, &len)) { + math_error("Illegal value for cfsim"); + not_reached(); + } + conf->cfsim = len; + break; - case CONFIG_OUTROUND: - if (getlen(vp, &len)) { - math_error("Illegal value for outround"); - not_reached(); - } - conf->outround = len; - break; + case CONFIG_OUTROUND: + if (getlen(vp, &len)) { + math_error("Illegal value for outround"); + not_reached(); + } + conf->outround = len; + break; - case CONFIG_ROUND: - if (getlen(vp, &len)) { - math_error("Illegal value for round"); - not_reached(); - } - conf->round = len; - break; + case CONFIG_ROUND: + if (getlen(vp, &len)) { + math_error("Illegal value for round"); + not_reached(); + } + conf->round = len; + break; - case CONFIG_TRIGROUND: - if (getlen(vp, &len)) { - math_error("Illegal value for triground"); - not_reached(); - } - conf->triground = len; - break; + case CONFIG_TRIGROUND: + if (getlen(vp, &len)) { + math_error("Illegal value for triground"); + not_reached(); + } + conf->triground = len; + break; - case CONFIG_LEADZERO: - if (vp->v_type == V_NUM) { - q = vp->v_num; - conf->leadzero = !qiszero(q); - } else if (vp->v_type == V_STR) { - temp = lookup_long(truth, vp->v_str->s_str); - if (temp < 0) { - math_error("Illegal truth value for leadzero"); - not_reached(); - } - conf->leadzero = (int)temp; - } - break; + case CONFIG_LEADZERO: + if (vp->v_type == V_NUM) { + q = vp->v_num; + conf->leadzero = !qiszero(q); + } else if (vp->v_type == V_STR) { + temp = lookup_long(truth, vp->v_str->s_str); + if (temp < 0) { + math_error("Illegal truth value for leadzero"); + not_reached(); + } + conf->leadzero = (int)temp; + } + break; - case CONFIG_FULLZERO: - if (vp->v_type == V_NUM) { - q = vp->v_num; - conf->fullzero = !qiszero(q); - } else if (vp->v_type == V_STR) { - temp = lookup_long(truth, vp->v_str->s_str); - if (temp < 0) { { - math_error("Illegal truth value for fullzero"); - not_reached(); - } - } - conf->fullzero = (int)temp; - } - break; + case CONFIG_FULLZERO: + if (vp->v_type == V_NUM) { + q = vp->v_num; + conf->fullzero = !qiszero(q); + } else if (vp->v_type == V_STR) { + temp = lookup_long(truth, vp->v_str->s_str); + if (temp < 0) { { + math_error("Illegal truth value for fullzero"); + not_reached(); + } + } + conf->fullzero = (int)temp; + } + break; - case CONFIG_MAXSCAN: - if (vp->v_type != V_NUM) { - math_error("Non-numeric for maxscancount"); - not_reached(); - } - q = vp->v_num; - temp = qtoi(q); - if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) - temp = -1; - if (temp < 0) { - math_error("Maxscan value is out of range"); - not_reached(); - } - conf->maxscancount = temp; - break; + case CONFIG_MAXSCAN: + if (vp->v_type != V_NUM) { + math_error("Non-numeric for maxscancount"); + not_reached(); + } + q = vp->v_num; + temp = qtoi(q); + if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) + temp = -1; + if (temp < 0) { + math_error("Maxscan value is out of range"); + not_reached(); + } + conf->maxscancount = temp; + break; - case CONFIG_PROMPT: - if (vp->v_type != V_STR) { - math_error("Non-string for prompt"); - not_reached(); - } - p = (char *)malloc(vp->v_str->s_len + 1); - if (p == NULL) { - math_error("Cannot duplicate new prompt"); - not_reached(); - } - strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1); - free(conf->prompt1); - conf->prompt1 = p; - break; + case CONFIG_PROMPT: + if (vp->v_type != V_STR) { + math_error("Non-string for prompt"); + not_reached(); + } + p = (char *)malloc(vp->v_str->s_len + 1); + if (p == NULL) { + math_error("Cannot duplicate new prompt"); + not_reached(); + } + strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1); + free(conf->prompt1); + conf->prompt1 = p; + break; - case CONFIG_MORE: - if (vp->v_type != V_STR) { - math_error("Non-string for more prompt"); - not_reached(); - } - p = (char *)malloc(vp->v_str->s_len + 1); - if (p == NULL) { - math_error("Cannot duplicate new more prompt"); - not_reached(); - } - strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1); - free(conf->prompt2); - conf->prompt2 = p; - break; + case CONFIG_MORE: + if (vp->v_type != V_STR) { + math_error("Non-string for more prompt"); + not_reached(); + } + p = (char *)malloc(vp->v_str->s_len + 1); + if (p == NULL) { + math_error("Cannot duplicate new more prompt"); + not_reached(); + } + strlcpy(p, vp->v_str->s_str, vp->v_str->s_len + 1); + free(conf->prompt2); + conf->prompt2 = p; + break; - case CONFIG_BLKMAXPRINT: - if (vp->v_type != V_NUM) { - math_error("Non-numeric for blkmaxprint"); - not_reached(); - } - q = vp->v_num; - temp = qtoi(q); - if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) - temp = -1; - if (temp < 0) { - math_error("Blkmaxprint value is out of range"); - not_reached(); - } - conf->blkmaxprint = temp; - break; + case CONFIG_BLKMAXPRINT: + if (vp->v_type != V_NUM) { + math_error("Non-numeric for blkmaxprint"); + not_reached(); + } + q = vp->v_num; + temp = qtoi(q); + if (qisfrac(q) || qisneg(q) || !zistiny(q->num)) + temp = -1; + if (temp < 0) { + math_error("Blkmaxprint value is out of range"); + not_reached(); + } + conf->blkmaxprint = temp; + break; - case CONFIG_BLKVERBOSE: - if (vp->v_type == V_NUM) { - q = vp->v_num; - conf->blkverbose = !qiszero(q); - } else if (vp->v_type == V_STR) { - temp = lookup_long(truth, vp->v_str->s_str); - if (temp < 0) { - math_error("Illegal truth value for blkverbose"); - not_reached(); - } - conf->blkverbose = (int)temp; - } - break; + case CONFIG_BLKVERBOSE: + if (vp->v_type == V_NUM) { + q = vp->v_num; + conf->blkverbose = !qiszero(q); + } else if (vp->v_type == V_STR) { + temp = lookup_long(truth, vp->v_str->s_str); + if (temp < 0) { + math_error("Illegal truth value for blkverbose"); + not_reached(); + } + conf->blkverbose = (int)temp; + } + break; - case CONFIG_BLKBASE: - if (vp->v_type != V_STR) { - math_error("Non-string for blkbase"); - not_reached(); - } - temp = lookup_long(blk_base, vp->v_str->s_str); - if (temp < 0) { - math_error("Unknown mode \"%s\" for blkbase", - vp->v_str->s_str); - not_reached(); - } - conf->blkbase = temp; - break; + case CONFIG_BLKBASE: + if (vp->v_type != V_STR) { + math_error("Non-string for blkbase"); + not_reached(); + } + temp = lookup_long(blk_base, vp->v_str->s_str); + if (temp < 0) { + math_error("Unknown mode \"%s\" for blkbase", + vp->v_str->s_str); + not_reached(); + } + conf->blkbase = temp; + break; - case CONFIG_BLKFMT: - if (vp->v_type != V_STR) { - math_error("Non-string for blkfmt"); - not_reached(); - } - temp = lookup_long(blk_fmt, vp->v_str->s_str); - if (temp < 0) { - math_error("Unknown mode \"%s\" for blkfmt", - vp->v_str->s_str); - not_reached(); - } - conf->blkfmt = temp; - break; + case CONFIG_BLKFMT: + if (vp->v_type != V_STR) { + math_error("Non-string for blkfmt"); + not_reached(); + } + temp = lookup_long(blk_fmt, vp->v_str->s_str); + if (temp < 0) { + math_error("Unknown mode \"%s\" for blkfmt", + vp->v_str->s_str); + not_reached(); + } + conf->blkfmt = temp; + break; - case CONFIG_CALC_DEBUG: - if (vp->v_type != V_NUM) { - math_error("Non numeric for calc_debug"); - not_reached(); - } - q = vp->v_num; - temp = qtoi(q); - if (qisfrac(q) || !zistiny(q->num)) { - math_error("Illegal calc_debug parameter value"); - not_reached(); - } - conf->calc_debug = temp; - break; + case CONFIG_CALC_DEBUG: + if (vp->v_type != V_NUM) { + math_error("Non numeric for calc_debug"); + not_reached(); + } + q = vp->v_num; + temp = qtoi(q); + if (qisfrac(q) || !zistiny(q->num)) { + math_error("Illegal calc_debug parameter value"); + not_reached(); + } + conf->calc_debug = temp; + break; - case CONFIG_RESOURCE_DEBUG: - if (vp->v_type != V_NUM) { - math_error("Non numeric for resource_debug"); - not_reached(); - } - q = vp->v_num; - temp = qtoi(q); - if (qisfrac(q) || !zistiny(q->num)) { - math_error("Illegal resource_debug parameter value"); - not_reached(); - } - conf->resource_debug = temp; - break; + case CONFIG_RESOURCE_DEBUG: + if (vp->v_type != V_NUM) { + math_error("Non numeric for resource_debug"); + not_reached(); + } + q = vp->v_num; + temp = qtoi(q); + if (qisfrac(q) || !zistiny(q->num)) { + math_error("Illegal resource_debug parameter value"); + not_reached(); + } + conf->resource_debug = temp; + break; - case CONFIG_USER_DEBUG: - if (vp->v_type != V_NUM) { - math_error("Non numeric for user_debug"); - not_reached(); - } - q = vp->v_num; - temp = qtoi(q); - if (qisfrac(q) || !zistiny(q->num)) { - math_error("Illegal user_debug parameter value"); - not_reached(); - } - conf->user_debug = temp; - break; + case CONFIG_USER_DEBUG: + if (vp->v_type != V_NUM) { + math_error("Non numeric for user_debug"); + not_reached(); + } + q = vp->v_num; + temp = qtoi(q); + if (qisfrac(q) || !zistiny(q->num)) { + math_error("Illegal user_debug parameter value"); + not_reached(); + } + conf->user_debug = temp; + break; - case CONFIG_VERBOSE_QUIT: - if (vp->v_type == V_NUM) { - q = vp->v_num; - conf->verbose_quit = !qiszero(q); - } else if (vp->v_type == V_STR) { - temp = lookup_long(truth, vp->v_str->s_str); - if (temp < 0) { - math_error("Illegal truth value " - "for verbose_quit"); - not_reached(); - } - conf->verbose_quit = (int)temp; - } - break; + case CONFIG_VERBOSE_QUIT: + if (vp->v_type == V_NUM) { + q = vp->v_num; + conf->verbose_quit = !qiszero(q); + } else if (vp->v_type == V_STR) { + temp = lookup_long(truth, vp->v_str->s_str); + if (temp < 0) { + math_error("Illegal truth value " + "for verbose_quit"); + not_reached(); + } + conf->verbose_quit = (int)temp; + } + break; - case CONFIG_CTRL_D: - if (vp->v_type != V_STR) { - math_error("Non-string for ctrl_d"); - not_reached(); - } - temp = lookup_long(ctrl_d, vp->v_str->s_str); - if (temp < 0) { - math_error("Unknown mode \"%s\" for ctrl_d", - vp->v_str->s_str); - not_reached(); - } - conf->ctrl_d = temp; - break; + case CONFIG_CTRL_D: + if (vp->v_type != V_STR) { + math_error("Non-string for ctrl_d"); + not_reached(); + } + temp = lookup_long(ctrl_d, vp->v_str->s_str); + if (temp < 0) { + math_error("Unknown mode \"%s\" for ctrl_d", + vp->v_str->s_str); + not_reached(); + } + conf->ctrl_d = temp; + break; - case CONFIG_PROGRAM: - math_error("The program config parameter is read-only"); - not_reached(); - break; + case CONFIG_PROGRAM: + math_error("The program config parameter is read-only"); + not_reached(); + break; - case CONFIG_BASENAME: - math_error("The basename config parameter is read-only"); - not_reached(); - break; + case CONFIG_BASENAME: + math_error("The basename config parameter is read-only"); + not_reached(); + break; - case CONFIG_WINDOWS: - math_error("The windows config parameter is read-only"); - not_reached(); - break; + case CONFIG_WINDOWS: + math_error("The windows config parameter is read-only"); + not_reached(); + break; - case CONFIG_CYGWIN: - math_error("The cygwin config parameter is read-only"); - not_reached(); - break; + case CONFIG_CYGWIN: + math_error("The cygwin config parameter is read-only"); + not_reached(); + break; - case CONFIG_COMPILE_CUSTOM: - math_error("The custom config parameter is read-only"); - not_reached(); - break; + case CONFIG_COMPILE_CUSTOM: + math_error("The custom config parameter is read-only"); + not_reached(); + break; - case CONFIG_ALLOW_CUSTOM: - math_error("The allow_custom config parameter is read-only"); - not_reached(); - break; + case CONFIG_ALLOW_CUSTOM: + math_error("The allow_custom config parameter is read-only"); + not_reached(); + break; - case CONFIG_VERSION: - math_error("The version config parameter is read-only"); - not_reached(); - break; + case CONFIG_VERSION: + math_error("The version config parameter is read-only"); + not_reached(); + break; - case CONFIG_BASEB: - math_error("The baseb config parameter is read-only"); - not_reached(); - break; + case CONFIG_BASEB: + math_error("The baseb config parameter is read-only"); + not_reached(); + break; - case CONFIG_REDECL_WARN: - if (vp->v_type == V_NUM) { - q = vp->v_num; - conf->redecl_warn = !qiszero(q); - } else if (vp->v_type == V_STR) { - temp = lookup_long(truth, vp->v_str->s_str); - if (temp < 0) { - math_error("Illegal truth value for " - "redecl_warn"); - not_reached(); - } - conf->redecl_warn = (int)temp; - } - break; + case CONFIG_REDECL_WARN: + if (vp->v_type == V_NUM) { + q = vp->v_num; + conf->redecl_warn = !qiszero(q); + } else if (vp->v_type == V_STR) { + temp = lookup_long(truth, vp->v_str->s_str); + if (temp < 0) { + math_error("Illegal truth value for " + "redecl_warn"); + not_reached(); + } + conf->redecl_warn = (int)temp; + } + break; - case CONFIG_DUPVAR_WARN: - if (vp->v_type == V_NUM) { - q = vp->v_num; - conf->dupvar_warn = !qiszero(q); - } else if (vp->v_type == V_STR) { - temp = lookup_long(truth, vp->v_str->s_str); - if (temp < 0) { - math_error("Illegal truth value for " - "dupvar_warn"); - not_reached(); - } - conf->dupvar_warn = (int)temp; - } - break; + case CONFIG_DUPVAR_WARN: + if (vp->v_type == V_NUM) { + q = vp->v_num; + conf->dupvar_warn = !qiszero(q); + } else if (vp->v_type == V_STR) { + temp = lookup_long(truth, vp->v_str->s_str); + if (temp < 0) { + math_error("Illegal truth value for " + "dupvar_warn"); + not_reached(); + } + conf->dupvar_warn = (int)temp; + } + break; - case CONFIG_HZ: - math_error("The clock tick rate config parameter is read-only"); - not_reached(); - break; + case CONFIG_HZ: + math_error("The clock tick rate config parameter is read-only"); + not_reached(); + break; - default: - math_error("Setting illegal config parameter"); - not_reached(); - break; - } + default: + math_error("Setting illegal config parameter"); + not_reached(); + break; + } } @@ -1063,66 +1063,66 @@ setconfig(int type, VALUE *vp) * config_copy - copy the configuration from one value to another * * given: - * src copy this configuration + * src copy this configuration * * returns: - * pointer to the configuration copy + * pointer to the configuration copy */ CONFIG * config_copy(CONFIG *src) { - CONFIG *dest; /* the new CONFIG to return */ + CONFIG *dest; /* the new CONFIG to return */ - /* - * firewall - */ - if (src == NULL || src->epsilon == NULL || src->prompt1 == NULL || - src->prompt2 == NULL) { - math_error("bad CONFIG value"); - not_reached(); - } + /* + * firewall + */ + if (src == NULL || src->epsilon == NULL || src->prompt1 == NULL || + src->prompt2 == NULL) { + math_error("bad CONFIG value"); + not_reached(); + } - /* - * malloc the storage - */ - dest = (CONFIG *)malloc(sizeof(CONFIG)); - if (dest == NULL) { - math_error("malloc of CONFIG failed"); - not_reached(); - } + /* + * malloc the storage + */ + dest = (CONFIG *)malloc(sizeof(CONFIG)); + if (dest == NULL) { + math_error("malloc of CONFIG failed"); + not_reached(); + } - /* - * copy over the values - */ - memcpy((void *)dest, (void *)src, sizeof(CONFIG)); + /* + * copy over the values + */ + memcpy((void *)dest, (void *)src, sizeof(CONFIG)); - /* - * clone the pointer values - */ - dest->epsilon = qlink(src->epsilon); - dest->prompt1 = strdup(src->prompt1); - dest->prompt2 = strdup(src->prompt2); - if (src->program == NULL) { - dest->program = strdup(program); - } else { - dest->program = strdup(src->program); - } - if (src->base_name == NULL) { - dest->base_name = strdup(base_name); - } else { - dest->base_name = strdup(src->base_name); - } - /* NOTE: allow_custom points to a global variable, so do not clone it */ - if (src->version == NULL) { - dest->version = strdup(version()); - } else { - dest->version = strdup(src->version); - } + /* + * clone the pointer values + */ + dest->epsilon = qlink(src->epsilon); + dest->prompt1 = strdup(src->prompt1); + dest->prompt2 = strdup(src->prompt2); + if (src->program == NULL) { + dest->program = strdup(program); + } else { + dest->program = strdup(src->program); + } + if (src->base_name == NULL) { + dest->base_name = strdup(base_name); + } else { + dest->base_name = strdup(src->base_name); + } + /* NOTE: allow_custom points to a global variable, so do not clone it */ + if (src->version == NULL) { + dest->version = strdup(version()); + } else { + dest->version = strdup(src->version); + } - /* - * return the new value - */ - return dest; + /* + * return the new value + */ + return dest; } @@ -1130,46 +1130,46 @@ config_copy(CONFIG *src) * config_free - free a CONFIG value * * given: - * cfg the CONFIG value to free + * cfg the CONFIG value to free */ void config_free(CONFIG *cfg) { - /* - * firewall - */ - if (cfg == NULL) { - return; - } + /* + * firewall + */ + if (cfg == NULL) { + return; + } - /* - * free pointer values - */ - if (cfg->epsilon != NULL) { - qfree(cfg->epsilon); - } - if (cfg->prompt1 != NULL) { - free(cfg->prompt1); - } - if (cfg->prompt2 != NULL) { - free(cfg->prompt2); - } - if (cfg->program != NULL) { - free(cfg->program); - } - if (cfg->base_name != NULL) { - free(cfg->base_name); - } - /* NOTE: allow_custom points to a global variable, so do not free it */ - if (cfg->version != NULL) { - free(cfg->version); - } + /* + * free pointer values + */ + if (cfg->epsilon != NULL) { + qfree(cfg->epsilon); + } + if (cfg->prompt1 != NULL) { + free(cfg->prompt1); + } + if (cfg->prompt2 != NULL) { + free(cfg->prompt2); + } + if (cfg->program != NULL) { + free(cfg->program); + } + if (cfg->base_name != NULL) { + free(cfg->base_name); + } + /* NOTE: allow_custom points to a global variable, so do not free it */ + if (cfg->version != NULL) { + free(cfg->version); + } - /* - * free the CONFIG value itself - */ - free(cfg); - return; + /* + * free the CONFIG value itself + */ + free(cfg); + return; } @@ -1177,301 +1177,301 @@ config_free(CONFIG *cfg) * config_value - return a CONFIG element as a value * * given: - * cfg CONFIG from which an element will be returned - * type the type of CONFIG element to print - * ret where to return the value + * cfg CONFIG from which an element will be returned + * type the type of CONFIG element to print + * ret where to return the value * * returns: - * ret points to the VALUE returned + * ret points to the VALUE returned */ void config_value(CONFIG *cfg, int type, VALUE *vp) { - long i=0; - char *p; + long i=0; + char *p; - /* - * firewall - */ - if (cfg == NULL || cfg->epsilon == NULL || cfg->prompt1 == NULL || - cfg->prompt2 == NULL) { - math_error("bad CONFIG value"); - not_reached(); - } + /* + * firewall + */ + if (cfg == NULL || cfg->epsilon == NULL || cfg->prompt1 == NULL || + cfg->prompt2 == NULL) { + math_error("bad CONFIG value"); + not_reached(); + } - /* - * convert element to value - */ - vp->v_type = V_NUM; - vp->v_subtype = V_NOSUBTYPE; - switch (type) { - case CONFIG_ALL: - vp->v_type = V_CONFIG; - vp->v_config = config_copy(conf); - return; + /* + * convert element to value + */ + vp->v_type = V_NUM; + vp->v_subtype = V_NOSUBTYPE; + switch (type) { + case CONFIG_ALL: + vp->v_type = V_CONFIG; + vp->v_config = config_copy(conf); + return; - case CONFIG_TRACE: - i = cfg->traceflags; - break; + case CONFIG_TRACE: + i = cfg->traceflags; + break; - case CONFIG_DISPLAY: - i = cfg->outdigits; - break; + case CONFIG_DISPLAY: + i = cfg->outdigits; + break; - case CONFIG_MODE: - vp->v_type = V_STR; - p = lookup_name(modes, cfg->outmode); - if (p == NULL) { - math_error("invalid output mode: %d", cfg->outmode); - not_reached(); - } - vp->v_str = makenewstring(p); - return; + case CONFIG_MODE: + vp->v_type = V_STR; + p = lookup_name(modes, cfg->outmode); + if (p == NULL) { + math_error("invalid output mode: %d", cfg->outmode); + not_reached(); + } + vp->v_str = makenewstring(p); + return; - case CONFIG_MODE2: - vp->v_type = V_STR; - p = lookup_name(modes, cfg->outmode2); - if (p == NULL) { - math_error("invalid secondary output mode: %d", - cfg->outmode2); - not_reached(); - } - vp->v_str = makenewstring(p); - return; + case CONFIG_MODE2: + vp->v_type = V_STR; + p = lookup_name(modes, cfg->outmode2); + if (p == NULL) { + math_error("invalid secondary output mode: %d", + cfg->outmode2); + not_reached(); + } + vp->v_str = makenewstring(p); + return; - case CONFIG_EPSILON: - vp->v_num = qlink(cfg->epsilon); - return; + case CONFIG_EPSILON: + vp->v_num = qlink(cfg->epsilon); + return; - case CONFIG_MAXPRINT: - i = cfg->maxprint; - break; + case CONFIG_MAXPRINT: + i = cfg->maxprint; + break; - case CONFIG_MUL2: - i = cfg->mul2; - break; + case CONFIG_MUL2: + i = cfg->mul2; + break; - case CONFIG_SQ2: - i = cfg->sq2; - break; + case CONFIG_SQ2: + i = cfg->sq2; + break; - case CONFIG_POW2: - i = cfg->pow2; - break; + case CONFIG_POW2: + i = cfg->pow2; + break; - case CONFIG_REDC2: - i = cfg->redc2; - break; + case CONFIG_REDC2: + i = cfg->redc2; + break; - case CONFIG_TILDE: - i = (cfg->tilde_ok ? 1 : 0); - break; + case CONFIG_TILDE: + i = (cfg->tilde_ok ? 1 : 0); + break; - case CONFIG_TILDE_SPACE: - i = (cfg->tilde_space ? 1 : 0); - break; + case CONFIG_TILDE_SPACE: + i = (cfg->tilde_space ? 1 : 0); + break; - case CONFIG_FRACTION_SPACE: - i = (cfg->fraction_space ? 1 : 0); - break; + case CONFIG_FRACTION_SPACE: + i = (cfg->fraction_space ? 1 : 0); + break; - case CONFIG_COMPLEX_SPACE: - i = (cfg->complex_space ? 1 : 0); - break; + case CONFIG_COMPLEX_SPACE: + i = (cfg->complex_space ? 1 : 0); + break; - case CONFIG_TAB: - i = (cfg->tab_ok ? 1 : 0); - break; + case CONFIG_TAB: + i = (cfg->tab_ok ? 1 : 0); + break; - case CONFIG_QUOMOD: - i = cfg->quomod; - break; + case CONFIG_QUOMOD: + i = cfg->quomod; + break; - case CONFIG_QUO: - i = cfg->quo; - break; + case CONFIG_QUO: + i = cfg->quo; + break; - case CONFIG_MOD: - i = cfg->mod; - break; + case CONFIG_MOD: + i = cfg->mod; + break; - case CONFIG_SQRT: - i = cfg->sqrt; - break; + case CONFIG_SQRT: + i = cfg->sqrt; + break; - case CONFIG_APPR: - i = cfg->appr; - break; + case CONFIG_APPR: + i = cfg->appr; + break; - case CONFIG_CFAPPR: - i = cfg->cfappr; - break; + case CONFIG_CFAPPR: + i = cfg->cfappr; + break; - case CONFIG_CFSIM: - i = cfg->cfsim; - break; + case CONFIG_CFSIM: + i = cfg->cfsim; + break; - case CONFIG_OUTROUND: - i = cfg->outround; - break; + case CONFIG_OUTROUND: + i = cfg->outround; + break; - case CONFIG_ROUND: - i = cfg->round; - break; + case CONFIG_ROUND: + i = cfg->round; + break; - case CONFIG_TRIGROUND: - i = cfg->triground; - break; + case CONFIG_TRIGROUND: + i = cfg->triground; + break; - case CONFIG_LEADZERO: - i = (cfg->leadzero ? 1 : 0); - break; + case CONFIG_LEADZERO: + i = (cfg->leadzero ? 1 : 0); + break; - case CONFIG_FULLZERO: - i = (cfg->fullzero ? 1 : 0); - break; + case CONFIG_FULLZERO: + i = (cfg->fullzero ? 1 : 0); + break; - case CONFIG_MAXSCAN: - i = cfg->maxscancount; - break; + case CONFIG_MAXSCAN: + i = cfg->maxscancount; + break; - case CONFIG_PROMPT: - vp->v_type = V_STR; - vp->v_str = makenewstring(cfg->prompt1); - return; + case CONFIG_PROMPT: + vp->v_type = V_STR; + vp->v_str = makenewstring(cfg->prompt1); + return; - case CONFIG_MORE: - vp->v_type = V_STR; - vp->v_str = makenewstring(cfg->prompt2); - return; + case CONFIG_MORE: + vp->v_type = V_STR; + vp->v_str = makenewstring(cfg->prompt2); + return; - case CONFIG_BLKMAXPRINT: - i = cfg->blkmaxprint; - break; + case CONFIG_BLKMAXPRINT: + i = cfg->blkmaxprint; + break; - case CONFIG_BLKVERBOSE: - i = (cfg->blkverbose ? 1 : 0); - break; + case CONFIG_BLKVERBOSE: + i = (cfg->blkverbose ? 1 : 0); + break; - case CONFIG_BLKBASE: - vp->v_type = V_STR; - p = lookup_name(blk_base, cfg->blkbase); - if (p == NULL) { - math_error("invalid block base: %d", cfg->blkbase); - not_reached(); - } - vp->v_str = makenewstring(p); - return; + case CONFIG_BLKBASE: + vp->v_type = V_STR; + p = lookup_name(blk_base, cfg->blkbase); + if (p == NULL) { + math_error("invalid block base: %d", cfg->blkbase); + not_reached(); + } + vp->v_str = makenewstring(p); + return; - case CONFIG_BLKFMT: - vp->v_type = V_STR; - p = lookup_name(blk_fmt, cfg->blkfmt); - if (p == NULL) { - math_error("invalid block format: %d", cfg->blkfmt); - not_reached(); - } - vp->v_str = makenewstring(p); - return; + case CONFIG_BLKFMT: + vp->v_type = V_STR; + p = lookup_name(blk_fmt, cfg->blkfmt); + if (p == NULL) { + math_error("invalid block format: %d", cfg->blkfmt); + not_reached(); + } + vp->v_str = makenewstring(p); + return; - case CONFIG_CALC_DEBUG: - i = cfg->calc_debug; - break; + case CONFIG_CALC_DEBUG: + i = cfg->calc_debug; + break; - case CONFIG_RESOURCE_DEBUG: - i = cfg->resource_debug; - break; + case CONFIG_RESOURCE_DEBUG: + i = cfg->resource_debug; + break; - case CONFIG_USER_DEBUG: - i = cfg->user_debug; - break; + case CONFIG_USER_DEBUG: + i = cfg->user_debug; + break; - case CONFIG_VERBOSE_QUIT: - i = (cfg->verbose_quit ? 1 : 0); - break; + case CONFIG_VERBOSE_QUIT: + i = (cfg->verbose_quit ? 1 : 0); + break; - case CONFIG_CTRL_D: - vp->v_type = V_STR; - p = lookup_name(ctrl_d, cfg->ctrl_d); - if (p == NULL) { - math_error("invalid Control-D: %d", cfg->ctrl_d); - not_reached(); - } - vp->v_str = makenewstring(p); - return; + case CONFIG_CTRL_D: + vp->v_type = V_STR; + p = lookup_name(ctrl_d, cfg->ctrl_d); + if (p == NULL) { + math_error("invalid Control-D: %d", cfg->ctrl_d); + not_reached(); + } + vp->v_str = makenewstring(p); + return; - case CONFIG_PROGRAM: - vp->v_type = V_STR; - if (cfg->base_name == NULL) { - vp->v_str = makestring(strdup(program)); - } else { - vp->v_str = makenewstring(cfg->program); - } - return; + case CONFIG_PROGRAM: + vp->v_type = V_STR; + if (cfg->base_name == NULL) { + vp->v_str = makestring(strdup(program)); + } else { + vp->v_str = makenewstring(cfg->program); + } + return; - case CONFIG_BASENAME: - vp->v_type = V_STR; - if (cfg->base_name == NULL) { - vp->v_str = makestring(strdup(base_name)); - } else { - vp->v_str = makenewstring(cfg->base_name); - } - return; + case CONFIG_BASENAME: + vp->v_type = V_STR; + if (cfg->base_name == NULL) { + vp->v_str = makestring(strdup(base_name)); + } else { + vp->v_str = makenewstring(cfg->base_name); + } + return; - case CONFIG_WINDOWS: - i = (cfg->windows ? 1 : 0); - break; + case CONFIG_WINDOWS: + i = (cfg->windows ? 1 : 0); + break; - case CONFIG_CYGWIN: - i = (cfg->cygwin ? 1 : 0); - break; + case CONFIG_CYGWIN: + i = (cfg->cygwin ? 1 : 0); + break; - case CONFIG_COMPILE_CUSTOM: - i = (cfg->compile_custom ? 1 : 0); - break; + case CONFIG_COMPILE_CUSTOM: + i = (cfg->compile_custom ? 1 : 0); + break; - case CONFIG_ALLOW_CUSTOM: - /* firewall */ - if (cfg->allow_custom == NULL) { - cfg->allow_custom = &allow_custom; - } - i = (*(cfg->allow_custom) ? 1 : 0); - break; + case CONFIG_ALLOW_CUSTOM: + /* firewall */ + if (cfg->allow_custom == NULL) { + cfg->allow_custom = &allow_custom; + } + i = (*(cfg->allow_custom) ? 1 : 0); + break; - case CONFIG_VERSION: - vp->v_type = V_STR; - if (cfg->version == NULL) { - vp->v_str = makestring(strdup(version())); - } else { - vp->v_str = makenewstring(cfg->version); - } - return; + case CONFIG_VERSION: + vp->v_type = V_STR; + if (cfg->version == NULL) { + vp->v_str = makestring(strdup(version())); + } else { + vp->v_str = makenewstring(cfg->version); + } + return; - case CONFIG_BASEB: - i = BASEB; - break; + case CONFIG_BASEB: + i = BASEB; + break; - case CONFIG_REDECL_WARN: - i = (cfg->redecl_warn ? 1 : 0); - break; + case CONFIG_REDECL_WARN: + i = (cfg->redecl_warn ? 1 : 0); + break; - case CONFIG_DUPVAR_WARN: - i = (cfg->dupvar_warn ? 1 : 0); - break; + case CONFIG_DUPVAR_WARN: + i = (cfg->dupvar_warn ? 1 : 0); + break; - case CONFIG_HZ: - i = CALC_HZ; - break; + case CONFIG_HZ: + i = CALC_HZ; + break; - default: - math_error("Getting illegal CONFIG element"); - not_reached(); - } + default: + math_error("Getting illegal CONFIG element"); + not_reached(); + } - /* - * if we got this far, we have a V_NUM in i - */ - vp->v_num = itoq(i); - return; + /* + * if we got this far, we have a V_NUM in i + */ + vp->v_num = itoq(i); + return; } @@ -1479,95 +1479,95 @@ config_value(CONFIG *cfg, int type, VALUE *vp) * config_cmp - compare two CONFIG states * * given: - * cfg1 - 1st CONFIG to compare - * cfg2 - 2nd CONFIG to compare + * cfg1 - 1st CONFIG to compare + * cfg2 - 2nd CONFIG to compare * * return: - * true if configurations differ + * true if configurations differ */ bool config_cmp(CONFIG *cfg1, CONFIG *cfg2) { - /* - * firewall - */ - if (cfg1 == NULL || cfg1->epsilon == NULL || cfg1->prompt1 == NULL || - cfg1->prompt2 == NULL) { - math_error("CONFIG #1 value is invalid"); - not_reached(); - } - if (cfg2 == NULL || cfg2->epsilon == NULL || cfg2->prompt1 == NULL || - cfg2->prompt2 == NULL) { - math_error("CONFIG #2 value is invalid"); - not_reached(); - } + /* + * firewall + */ + if (cfg1 == NULL || cfg1->epsilon == NULL || cfg1->prompt1 == NULL || + cfg1->prompt2 == NULL) { + math_error("CONFIG #1 value is invalid"); + not_reached(); + } + if (cfg2 == NULL || cfg2->epsilon == NULL || cfg2->prompt1 == NULL || + cfg2->prompt2 == NULL) { + math_error("CONFIG #2 value is invalid"); + not_reached(); + } - /* - * compare - */ - return cfg1->traceflags != cfg2->traceflags || - cfg1->outdigits != cfg2->outdigits || - cfg1->outmode != cfg2->outmode || - cfg1->outmode2 != cfg2->outmode2 || - qcmp(cfg1->epsilon, cfg2->epsilon) || - cfg1->epsilonprec != cfg2->epsilonprec || - cfg1->maxprint != cfg2->maxprint || - cfg1->mul2 != cfg2->mul2 || - cfg1->sq2 != cfg2->sq2 || - cfg1->pow2 != cfg2->pow2 || - cfg1->redc2 != cfg2->redc2 || - cfg1->tilde_ok != cfg2->tilde_ok || - cfg1->tab_ok != cfg2->tab_ok || - cfg1->quomod != cfg2->quomod || - cfg1->quo != cfg2->quo || - cfg1->mod != cfg2->mod || - cfg1->sqrt != cfg2->sqrt || - cfg1->appr != cfg2->appr || - cfg1->cfappr != cfg2->cfappr || - cfg1->cfsim != cfg2->cfsim || - cfg1->outround != cfg2->outround || - cfg1->round != cfg2->round || - cfg1->triground != cfg2->triground || - cfg1->leadzero != cfg2->leadzero || - cfg1->fullzero != cfg2->fullzero || - cfg1->maxscancount != cfg2->maxscancount || - strcmp(cfg1->prompt1, cfg2->prompt1) != 0 || - strcmp(cfg1->prompt2, cfg2->prompt2) != 0 || - cfg1->blkmaxprint != cfg2->blkmaxprint || - cfg1->blkverbose != cfg2->blkverbose || - cfg1->blkbase != cfg2->blkbase || - cfg1->blkfmt != cfg2->blkfmt || - cfg1->calc_debug != cfg2->calc_debug || - cfg1->resource_debug != cfg2->resource_debug || - cfg1->user_debug != cfg2->user_debug || - cfg1->verbose_quit != cfg2->verbose_quit || - cfg1->ctrl_d != cfg2->ctrl_d || + /* + * compare + */ + return cfg1->traceflags != cfg2->traceflags || + cfg1->outdigits != cfg2->outdigits || + cfg1->outmode != cfg2->outmode || + cfg1->outmode2 != cfg2->outmode2 || + qcmp(cfg1->epsilon, cfg2->epsilon) || + cfg1->epsilonprec != cfg2->epsilonprec || + cfg1->maxprint != cfg2->maxprint || + cfg1->mul2 != cfg2->mul2 || + cfg1->sq2 != cfg2->sq2 || + cfg1->pow2 != cfg2->pow2 || + cfg1->redc2 != cfg2->redc2 || + cfg1->tilde_ok != cfg2->tilde_ok || + cfg1->tab_ok != cfg2->tab_ok || + cfg1->quomod != cfg2->quomod || + cfg1->quo != cfg2->quo || + cfg1->mod != cfg2->mod || + cfg1->sqrt != cfg2->sqrt || + cfg1->appr != cfg2->appr || + cfg1->cfappr != cfg2->cfappr || + cfg1->cfsim != cfg2->cfsim || + cfg1->outround != cfg2->outround || + cfg1->round != cfg2->round || + cfg1->triground != cfg2->triground || + cfg1->leadzero != cfg2->leadzero || + cfg1->fullzero != cfg2->fullzero || + cfg1->maxscancount != cfg2->maxscancount || + strcmp(cfg1->prompt1, cfg2->prompt1) != 0 || + strcmp(cfg1->prompt2, cfg2->prompt2) != 0 || + cfg1->blkmaxprint != cfg2->blkmaxprint || + cfg1->blkverbose != cfg2->blkverbose || + cfg1->blkbase != cfg2->blkbase || + cfg1->blkfmt != cfg2->blkfmt || + cfg1->calc_debug != cfg2->calc_debug || + cfg1->resource_debug != cfg2->resource_debug || + cfg1->user_debug != cfg2->user_debug || + cfg1->verbose_quit != cfg2->verbose_quit || + cfg1->ctrl_d != cfg2->ctrl_d || - (cfg1->program == NULL && cfg2->program != NULL) || - (cfg1->program != NULL && cfg2->program == NULL) || - (cfg1->program != NULL && cfg2->program != NULL && - strcmp(cfg1->program, cfg2->program) != 0) || + (cfg1->program == NULL && cfg2->program != NULL) || + (cfg1->program != NULL && cfg2->program == NULL) || + (cfg1->program != NULL && cfg2->program != NULL && + strcmp(cfg1->program, cfg2->program) != 0) || - (cfg1->base_name == NULL && cfg2->base_name != NULL) || - (cfg1->base_name != NULL && cfg2->base_name == NULL) || - (cfg1->base_name != NULL && cfg2->base_name != NULL && - strcmp(cfg1->base_name, cfg2->base_name) != 0) || + (cfg1->base_name == NULL && cfg2->base_name != NULL) || + (cfg1->base_name != NULL && cfg2->base_name == NULL) || + (cfg1->base_name != NULL && cfg2->base_name != NULL && + strcmp(cfg1->base_name, cfg2->base_name) != 0) || - cfg1->windows != cfg2->windows || + cfg1->windows != cfg2->windows || - cfg1->cygwin != cfg2->cygwin || + cfg1->cygwin != cfg2->cygwin || - cfg1->compile_custom != cfg2->compile_custom || + cfg1->compile_custom != cfg2->compile_custom || - (cfg1->allow_custom == NULL && cfg2->allow_custom != NULL) || - (cfg1->allow_custom != NULL && cfg2->allow_custom == NULL) || - (cfg1->allow_custom != NULL && cfg2->allow_custom != NULL && - *(cfg1->allow_custom) != *(cfg2->allow_custom)) || + (cfg1->allow_custom == NULL && cfg2->allow_custom != NULL) || + (cfg1->allow_custom != NULL && cfg2->allow_custom == NULL) || + (cfg1->allow_custom != NULL && cfg2->allow_custom != NULL && + *(cfg1->allow_custom) != *(cfg2->allow_custom)) || - (cfg1->version == NULL && cfg2->version != NULL) || - (cfg1->version != NULL && cfg2->version == NULL) || - (cfg1->version != NULL && cfg2->version != NULL && - strcmp(cfg1->version, cfg2->version) != 0) || + (cfg1->version == NULL && cfg2->version != NULL) || + (cfg1->version != NULL && cfg2->version == NULL) || + (cfg1->version != NULL && cfg2->version != NULL && + strcmp(cfg1->version, cfg2->version) != 0) || - cfg1->baseb != cfg2->baseb; + cfg1->baseb != cfg2->baseb; } diff --git a/config.h b/config.h index 79938a8..ccde49d 100644 --- a/config.h +++ b/config.h @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,11 +19,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/11/01 22:20:17 - * File existed as early as: 1995 + * Under source code control: 1995/11/01 22:20:17 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -31,7 +31,7 @@ #define INCLUDE_CONFIG_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "decl.h" # include "nametype.h" # include "qmath.h" @@ -45,69 +45,69 @@ /* * configuration element types */ -#define CONFIG_ALL 0 /* not a real configuration parameter */ -#define CONFIG_MODE 1 /* types of configuration parameters */ -#define CONFIG_DISPLAY 2 -#define CONFIG_EPSILON 3 -#define CONFIG_EPSILONPREC 3 /* not a real type -- tied to CONFIG_EPSILON */ -#define CONFIG_TRACE 4 +#define CONFIG_ALL 0 /* not a real configuration parameter */ +#define CONFIG_MODE 1 /* types of configuration parameters */ +#define CONFIG_DISPLAY 2 +#define CONFIG_EPSILON 3 +#define CONFIG_EPSILONPREC 3 /* not a real type -- tied to CONFIG_EPSILON */ +#define CONFIG_TRACE 4 #define CONFIG_MAXPRINT 5 -#define CONFIG_MUL2 6 -#define CONFIG_SQ2 7 -#define CONFIG_POW2 8 -#define CONFIG_REDC2 9 -#define CONFIG_TILDE 10 -#define CONFIG_TAB 11 -#define CONFIG_QUOMOD 12 -#define CONFIG_QUO 13 -#define CONFIG_MOD 14 -#define CONFIG_SQRT 15 -#define CONFIG_APPR 16 -#define CONFIG_CFAPPR 17 -#define CONFIG_CFSIM 18 +#define CONFIG_MUL2 6 +#define CONFIG_SQ2 7 +#define CONFIG_POW2 8 +#define CONFIG_REDC2 9 +#define CONFIG_TILDE 10 +#define CONFIG_TAB 11 +#define CONFIG_QUOMOD 12 +#define CONFIG_QUO 13 +#define CONFIG_MOD 14 +#define CONFIG_SQRT 15 +#define CONFIG_APPR 16 +#define CONFIG_CFAPPR 17 +#define CONFIG_CFSIM 18 #define CONFIG_OUTROUND 19 -#define CONFIG_ROUND 20 +#define CONFIG_ROUND 20 #define CONFIG_LEADZERO 21 #define CONFIG_FULLZERO 22 -#define CONFIG_MAXSCAN 23 -#define CONFIG_PROMPT 24 -#define CONFIG_MORE 25 +#define CONFIG_MAXSCAN 23 +#define CONFIG_PROMPT 24 +#define CONFIG_MORE 25 #define CONFIG_BLKMAXPRINT 26 #define CONFIG_BLKVERBOSE 27 -#define CONFIG_BLKBASE 28 -#define CONFIG_BLKFMT 29 +#define CONFIG_BLKBASE 28 +#define CONFIG_BLKFMT 29 #define CONFIG_RESOURCE_DEBUG 30 #define CONFIG_LIB_DEBUG CONFIG_RESOURCE_DEBUG #define CONFIG_CALC_DEBUG 31 #define CONFIG_USER_DEBUG 32 #define CONFIG_VERBOSE_QUIT 33 -#define CONFIG_CTRL_D 34 -#define CONFIG_PROGRAM 35 -#define CONFIG_BASENAME 36 -#define CONFIG_VERSION 37 -#define CONFIG_WINDOWS 38 -#define CONFIG_MODE2 39 -#define CONFIG_CYGWIN 40 -#define CONFIG_COMPILE_CUSTOM 41 -#define CONFIG_ALLOW_CUSTOM 42 -#define CONFIG_BASEB 43 -#define CONFIG_REDECL_WARN 44 -#define CONFIG_DUPVAR_WARN 45 -#define CONFIG_HZ 46 -#define CONFIG_TILDE_SPACE 47 -#define CONFIG_FRACTION_SPACE 48 -#define CONFIG_COMPLEX_SPACE 49 -#define CONFIG_TRIGROUND 50 +#define CONFIG_CTRL_D 34 +#define CONFIG_PROGRAM 35 +#define CONFIG_BASENAME 36 +#define CONFIG_VERSION 37 +#define CONFIG_WINDOWS 38 +#define CONFIG_MODE2 39 +#define CONFIG_CYGWIN 40 +#define CONFIG_COMPILE_CUSTOM 41 +#define CONFIG_ALLOW_CUSTOM 42 +#define CONFIG_BASEB 43 +#define CONFIG_REDECL_WARN 44 +#define CONFIG_DUPVAR_WARN 45 +#define CONFIG_HZ 46 +#define CONFIG_TILDE_SPACE 47 +#define CONFIG_FRACTION_SPACE 48 +#define CONFIG_COMPLEX_SPACE 49 +#define CONFIG_TRIGROUND 50 /* * config default symbols */ -#define DISPLAY_DEFAULT 20 /* default digits for float display */ +#define DISPLAY_DEFAULT 20 /* default digits for float display */ #define EPSILON_DEFAULT "1e-20" /* allowed error for float calculations */ -#define EPSILONPREC_DEFAULT 67 /* 67 ==> 2^-67 <= EPSILON_DEFAULT < 2^-66 */ -#define MAXPRINT_DEFAULT 16 /* default number of elements printed */ -#define MAXSCANCOUNT 20 /* default max scan errors before an abort */ +#define EPSILONPREC_DEFAULT 67 /* 67 ==> 2^-67 <= EPSILON_DEFAULT < 2^-66 */ +#define MAXPRINT_DEFAULT 16 /* default number of elements printed */ +#define MAXSCANCOUNT 20 /* default max scan errors before an abort */ /* @@ -115,65 +115,65 @@ * * If you add elements to this structure, you need to also update: * - * quickhash.c - config_hash() - * hash.c - hash_value() - * config.c - configs[], oldstd, newstd, setconfig(), - * config_value(), config_cmp(), - * and perhaps config_copy(), config_free() - * config.h - CONFIG_XYZ_SYMBOL (see above) - * help/config - document new config option + * quickhash.c - config_hash() + * hash.c - hash_value() + * config.c - configs[], oldstd, newstd, setconfig(), + * config_value(), config_cmp(), + * and perhaps config_copy(), config_free() + * config.h - CONFIG_XYZ_SYMBOL (see above) + * help/config - document new config option */ struct config { - int outmode; /* current output mode */ - int outmode2; /* current secondary output mode */ - LEN outdigits; /* current output digits for float or exp */ - NUMBER *epsilon; /* default error for real functions */ - long epsilonprec; /* epsilon binary precision (tied to epsilon) */ - FLAG traceflags; /* tracing flags */ - LEN maxprint; /* number of elements to print */ - LEN mul2; /* size of number to use multiply algorithm 2 */ - LEN sq2; /* size of number to use square algorithm 2 */ - LEN pow2; /* size of modulus to use REDC for powers */ - LEN redc2; /* size of modulus to use REDC algorithm 2 */ - bool tilde_ok; /* OK to print a tilde on approximations */ - bool tilde_space; /* print space after tilde on approximations */ - bool fraction_space; /* true => print spaces around / in fractions */ - bool complex_space; /* true => print spaces around + or - in complex values */ - bool tab_ok; /* OK to print tab before numeric values */ - LEN quomod; /* quomod() default rounding mode */ - LEN quo; /* quotient // default rounding mode */ - LEN mod; /* mod % default rounding mode */ - LEN sqrt; /* sqrt() default rounding mode */ - LEN appr; /* appr() default rounding mode */ - LEN cfappr; /* cfappr() default rounding mode */ - LEN cfsim; /* cfsim() default rounding mode */ - LEN outround; /* output default rounding mode */ - LEN round; /* round()/bround() default rounding mode */ - LEN triground; /* trigonometric and hyperbolic function rounding mode */ - bool leadzero; /* OK to print leading 0 before decimal pt */ - bool fullzero; /* OK to print trailing 0's */ - long maxscancount; /* max scan errors before abort */ - char *prompt1; /* normal prompt */ - char *prompt2; /* prompt when inside multi-line input */ - int blkmaxprint; /* octets of a block to print, 0 => all */ - bool blkverbose; /* true => print all lines if a block */ - int blkbase; /* block output base */ - int blkfmt; /* block output style */ - long calc_debug; /* internal debug, see CALC_DEBUG_XYZ below */ - long resource_debug; /* resource debug, see RSCDBG_XYZ below */ - long user_debug; /* user defined debug value: 0 default */ - bool verbose_quit; /* true => print Quit or abort executed msg */ - int ctrl_d; /* see CTRL_D_xyz below */ - char *program; /* our name */ - char *base_name; /* basename of our name */ - bool windows; /* true => running under MS windows */ - bool cygwin; /* true => compiled with cygwin */ - bool compile_custom; /* true => compiled with -DCUSTOM */ - bool *allow_custom; /* ptr to if custom functions are allowed */ - char *version; /* calc version string */ - int baseb; /* base for calculations */ - bool redecl_warn; /* true => warn of redeclaring variables */ - bool dupvar_warn; /* true => warn of var name collisions */ + int outmode; /* current output mode */ + int outmode2; /* current secondary output mode */ + LEN outdigits; /* current output digits for float or exp */ + NUMBER *epsilon; /* default error for real functions */ + long epsilonprec; /* epsilon binary precision (tied to epsilon) */ + FLAG traceflags; /* tracing flags */ + LEN maxprint; /* number of elements to print */ + LEN mul2; /* size of number to use multiply algorithm 2 */ + LEN sq2; /* size of number to use square algorithm 2 */ + LEN pow2; /* size of modulus to use REDC for powers */ + LEN redc2; /* size of modulus to use REDC algorithm 2 */ + bool tilde_ok; /* OK to print a tilde on approximations */ + bool tilde_space; /* print space after tilde on approximations */ + bool fraction_space; /* true => print spaces around / in fractions */ + bool complex_space; /* true => print spaces around + or - in complex values */ + bool tab_ok; /* OK to print tab before numeric values */ + LEN quomod; /* quomod() default rounding mode */ + LEN quo; /* quotient // default rounding mode */ + LEN mod; /* mod % default rounding mode */ + LEN sqrt; /* sqrt() default rounding mode */ + LEN appr; /* appr() default rounding mode */ + LEN cfappr; /* cfappr() default rounding mode */ + LEN cfsim; /* cfsim() default rounding mode */ + LEN outround; /* output default rounding mode */ + LEN round; /* round()/bround() default rounding mode */ + LEN triground; /* trigonometric and hyperbolic function rounding mode */ + bool leadzero; /* OK to print leading 0 before decimal pt */ + bool fullzero; /* OK to print trailing 0's */ + long maxscancount; /* max scan errors before abort */ + char *prompt1; /* normal prompt */ + char *prompt2; /* prompt when inside multi-line input */ + int blkmaxprint; /* octets of a block to print, 0 => all */ + bool blkverbose; /* true => print all lines if a block */ + int blkbase; /* block output base */ + int blkfmt; /* block output style */ + long calc_debug; /* internal debug, see CALC_DEBUG_XYZ below */ + long resource_debug; /* resource debug, see RSCDBG_XYZ below */ + long user_debug; /* user defined debug value: 0 default */ + bool verbose_quit; /* true => print Quit or abort executed msg */ + int ctrl_d; /* see CTRL_D_xyz below */ + char *program; /* our name */ + char *base_name; /* basename of our name */ + bool windows; /* true => running under MS windows */ + bool cygwin; /* true => compiled with cygwin */ + bool compile_custom; /* true => compiled with -DCUSTOM */ + bool *allow_custom; /* ptr to if custom functions are allowed */ + char *version; /* calc version string */ + int baseb; /* base for calculations */ + bool redecl_warn; /* true => warn of redeclaring variables */ + bool dupvar_warn; /* true => warn of var name collisions */ }; typedef struct config CONFIG; @@ -185,39 +185,39 @@ typedef struct config CONFIG; #define RSCDBG_FILE_FUNC (0x00000002) /* file read func define debug */ #define RSCDBG_FUNC_INFO (0x00000004) /* print extra info for show func */ #define RSCDBG_PRINT_DBG (0x00000008) /* print debug messages */ -#define RSCDBG_MASK (0x0000000f) +#define RSCDBG_MASK (0x0000000f) /* * calc_debug bit masks */ -#define CALCDBG_SYSTEM (0x00000001) /* print system cmd prior to exec */ +#define CALCDBG_SYSTEM (0x00000001) /* print system cmd prior to exec */ #define CALCDBG_FUNC_QUIT (0x00000002) /* active functions when quit */ #define CALCDBG_HASH_STATE (0x00000004) /* hash state details */ -#define CALCDBG_BLOCK (0x00000008) /* block debug */ -#define CALCDBG_TTY (0x00000010) /* report TTY state changes */ +#define CALCDBG_BLOCK (0x00000008) /* block debug */ +#define CALCDBG_TTY (0x00000010) /* report TTY state changes */ #define CALCDBG_RUNSTATE (0x00000020) /* report run_state changes */ -#define CALCDBG_RAND (0x00000040) /* report rand() activity */ -#define CALCDBG_CUSTOM (0x00000080) /* custom function debug */ -#define CALCDBG_MASK (0x000000ff) +#define CALCDBG_RAND (0x00000040) /* report rand() activity */ +#define CALCDBG_CUSTOM (0x00000080) /* custom function debug */ +#define CALCDBG_MASK (0x000000ff) /* * ctrl-d meanings */ -#define CTRL_D_VIRGIN_EOF (0) /* ^D only exits on virgin command lines */ -#define CTRL_D_NEVER_EOF (1) /* ^D never exits, emacs binding meaning only */ -#define CTRL_D_EMPTY_EOF (2) /* ^D always exits at start of line */ +#define CTRL_D_VIRGIN_EOF (0) /* ^D only exits on virgin command lines */ +#define CTRL_D_NEVER_EOF (1) /* ^D never exits, emacs binding meaning only */ +#define CTRL_D_EMPTY_EOF (2) /* ^D always exits at start of line */ /* * global configuration states and aliases */ -EXTERN CONFIG *conf; /* current configuration */ -EXTERN CONFIG oldstd; /* old classic standard configuration */ -EXTERN CONFIG newstd; /* default compatible configuration */ -E_FUNC char *calc_debug; /* !=NULL => value of config("calc_debug") */ +EXTERN CONFIG *conf; /* current configuration */ +EXTERN CONFIG oldstd; /* old classic standard configuration */ +EXTERN CONFIG newstd; /* default compatible configuration */ +E_FUNC char *calc_debug; /* !=NULL => value of config("calc_debug") */ E_FUNC char *resource_debug; /* !=NULL => config("resource_debug") value */ -E_FUNC char *user_debug; /* !=NULL => value of config("user_debug") */ +E_FUNC char *user_debug; /* !=NULL => value of config("user_debug") */ /* diff --git a/const.c b/const.c index 3af3a74..ac41b17 100644 --- a/const.c +++ b/const.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:14 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:14 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -30,31 +30,31 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define CONSTALLOCSIZE 400 /* number of constants to allocate */ +#define CONSTALLOCSIZE 400 /* number of constants to allocate */ STATIC unsigned long constcount;/* number of constants defined */ -STATIC long constavail; /* number of constants available */ -STATIC NUMBER **consttable; /* table of constants */ +STATIC long constavail; /* number of constants available */ +STATIC NUMBER **consttable; /* table of constants */ void initconstants(void) { - int i; + int i; - consttable = (NUMBER **) calloc(sizeof(NUMBER *), CONSTALLOCSIZE); - if (consttable == NULL) { - math_error("Unable to allocate constant table"); - not_reached(); - } - for (i = 0; initnumbs[i] != NULL; i++) { - consttable[i] = initnumbs[i]; - } - constcount = i-1; - constavail = CONSTALLOCSIZE - constcount; + consttable = (NUMBER **) calloc(sizeof(NUMBER *), CONSTALLOCSIZE); + if (consttable == NULL) { + math_error("Unable to allocate constant table"); + not_reached(); + } + for (i = 0; initnumbs[i] != NULL; i++) { + consttable[i] = initnumbs[i]; + } + constcount = i-1; + constavail = CONSTALLOCSIZE - constcount; } @@ -65,15 +65,15 @@ initconstants(void) * Returns the index of the number in the constant table. * * given: - * str string representation of number + * str string representation of number */ long addnumber(char *str) { - NUMBER *q; + NUMBER *q; - q = str2q(str); - return addqconstant(q); + q = str2q(str); + return addqconstant(q); } @@ -86,87 +86,87 @@ addnumber(char *str) * XXX - we should hash the constant table * * given: - * q number to be added + * q number to be added */ long addqconstant(NUMBER *q) { - register NUMBER **tp; /* pointer to current number */ - register NUMBER *t; /* number being tested */ - unsigned long index; /* index into constant table */ - long numlen; /* numerator length */ - long denlen; /* denominator length */ - HALF numlow; /* bottom value of numerator */ - HALF denlow; /* bottom value of denominator */ - long first; /* first non-null position found */ - bool havefirst; + register NUMBER **tp; /* pointer to current number */ + register NUMBER *t; /* number being tested */ + unsigned long index; /* index into constant table */ + long numlen; /* numerator length */ + long denlen; /* denominator length */ + HALF numlow; /* bottom value of numerator */ + HALF denlow; /* bottom value of denominator */ + long first; /* first non-null position found */ + bool havefirst; - if (constavail <= 0) { - if (consttable == NULL) { - initconstants(); - } else { - tp = (NUMBER **) realloc((char *) consttable, - sizeof(NUMBER *) * (constcount + CONSTALLOCSIZE)); - if (tp == NULL) { - math_error("Unable to reallocate const table"); - not_reached(); - } - consttable = tp; - constavail = CONSTALLOCSIZE; - } - } - numlen = q->num.len; - denlen = q->den.len; - numlow = q->num.v[0]; - denlow = q->den.v[0]; - first = 0; - havefirst = false; - tp = consttable; - for (index = 0; index < constcount; index++, tp++) { - t = *tp; - if (t == NULL) { /* paranoia */ - break; - } - if (t->links == 0) { - if (!havefirst) { - havefirst = true; - first = index; - } - continue; - } - if (q == t) { - if (q->links == 1) { - if (havefirst) { - *tp = consttable[first]; - consttable[first] = q; - } else { - havefirst = true; - first = index; - } - continue; - } - return index; - } + if (constavail <= 0) { + if (consttable == NULL) { + initconstants(); + } else { + tp = (NUMBER **) realloc((char *) consttable, + sizeof(NUMBER *) * (constcount + CONSTALLOCSIZE)); + if (tp == NULL) { + math_error("Unable to reallocate const table"); + not_reached(); + } + consttable = tp; + constavail = CONSTALLOCSIZE; + } + } + numlen = q->num.len; + denlen = q->den.len; + numlow = q->num.v[0]; + denlow = q->den.v[0]; + first = 0; + havefirst = false; + tp = consttable; + for (index = 0; index < constcount; index++, tp++) { + t = *tp; + if (t == NULL) { /* paranoia */ + break; + } + if (t->links == 0) { + if (!havefirst) { + havefirst = true; + first = index; + } + continue; + } + if (q == t) { + if (q->links == 1) { + if (havefirst) { + *tp = consttable[first]; + consttable[first] = q; + } else { + havefirst = true; + first = index; + } + continue; + } + return index; + } - if ((numlen != t->num.len) || (numlow != t->num.v[0])) - continue; - if ((denlen != t->den.len) || (denlow != t->den.v[0])) - continue; - if (q->num.sign != t->num.sign) - continue; - if (qcmp(q, t) == 0) { - t->links++; - qfree(q); - return index; - } - } - if (havefirst) { - consttable[first] = q; - return first; - } - constavail--; - consttable[constcount++] = q; - return index; + if ((numlen != t->num.len) || (numlow != t->num.v[0])) + continue; + if ((denlen != t->den.len) || (denlow != t->den.v[0])) + continue; + if (q->num.sign != t->num.sign) + continue; + if (qcmp(q, t) == 0) { + t->links++; + qfree(q); + return index; + } + } + if (havefirst) { + consttable[first] = q; + return first; + } + constavail--; + consttable[constcount++] = q; + return index; } @@ -178,70 +178,70 @@ addqconstant(NUMBER *q) NUMBER * constvalue(unsigned long index) { - if (index >= constcount) { - math_error("Bad index value for constvalue"); - not_reached(); - } - if (consttable[index]->links == 0) { - math_error("Constvalue has been freed!!!"); - not_reached(); - } - return consttable[index]; + if (index >= constcount) { + math_error("Bad index value for constvalue"); + not_reached(); + } + if (consttable[index]->links == 0) { + math_error("Constvalue has been freed!!!"); + not_reached(); + } + return consttable[index]; } void freeconstant(unsigned long index) { - NUMBER *q; + NUMBER *q; - if (index >= constcount) { - math_error("Bad index value for freeconst"); - not_reached(); - } - q = consttable[index]; - if (q->links == 0) { - math_error("Attempting to free freed const location"); - not_reached(); - } - qfree(q); - if (index == constcount - 1) { - trimconstants(); - } + if (index >= constcount) { + math_error("Bad index value for freeconst"); + not_reached(); + } + q = consttable[index]; + if (q->links == 0) { + math_error("Attempting to free freed const location"); + not_reached(); + } + qfree(q); + if (index == constcount - 1) { + trimconstants(); + } } void trimconstants(void) { - while (constcount > 0 && - (consttable[constcount-1] == NULL || - consttable[constcount-1]->links == 0)) { - constcount--; - constavail++; - } + while (constcount > 0 && + (consttable[constcount-1] == NULL || + consttable[constcount-1]->links == 0)) { + constcount--; + constavail++; + } } void showconstants(void) { - unsigned long index; - NUMBER **qp; - long count; + unsigned long index; + NUMBER **qp; + long count; - qp = consttable; - count = 0; - for (index = 0; index < constcount; index++, qp++) { - if ((*qp)->links) { - if (!count) { - printf("\n Index Links Value\n"); - } - count++; - printf("\n%8ld%8ld ", index, (*qp)->links); - fitprint(*qp, 40); - } - } - printf("\n\nNumber = %ld\n", count); + qp = consttable; + count = 0; + for (index = 0; index < constcount; index++, qp++) { + if ((*qp)->links) { + if (!count) { + printf("\n Index Links Value\n"); + } + count++; + printf("\n%8ld%8ld ", index, (*qp)->links); + fitprint(*qp, 40); + } + } + printf("\n\nNumber = %ld\n", count); } diff --git a/cscript/4dsphere.calc b/cscript/4dsphere.calc index 912807d..2baf75f 100644 --- a/cscript/4dsphere.calc +++ b/cscript/4dsphere.calc @@ -7,10 +7,10 @@ * usage: * 4dsphere x0 y0 z0 w0 x1 y1 z1 w1 ... x5 y5 z5 w5 * - * x0 y0 z0 w0 point 0 in R^4 - * x1 y1 z1 w1 point 1 in R^4 - * ... ... - * x5 y5 z5 w5 point 5 in R^4 + * x0 y0 z0 w0 point 0 in R^4 + * x1 y1 z1 w1 point 1 in R^4 + * ... ... + * x5 y5 z5 w5 point 5 in R^4 * * 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 @@ -41,7 +41,7 @@ stderr = files(2); program = argv(0); if (argc != 24) { fprintf(stderr, "usage: %s x0 y0 z0 w0 x1 y1 z1 w1 ... x5 y5 z5 w5\n", - program); + program); exit; } x0 = eval(argv(1)); @@ -83,22 +83,22 @@ print "(":x5:",":y5:",":z5:",":w5:") ":; * * Given the 5 points: * - * (x0,y1,z1,w1) - * (x1,y1,z1,w1) - * (x2,y2,z2,w2) - * (x3,y3,z3,w3) - * (x4,y4,z4,w4) - * (x5,y5,z5,w5) + * (x0,y1,z1,w1) + * (x1,y1,z1,w1) + * (x2,y2,z2,w2) + * (x3,y3,z3,w3) + * (x4,y4,z4,w4) + * (x5,y5,z5,w5) * * we can determine if they lie in the surface of 4D sphere in R^4 if the * following matrix is 0: * - * | x0^2+y0^2+z0^2+w0^2 x0 y0 z0 w0 1 | - * | x1^2+y1^2+z1^2+w1^2 x1 y1 z1 w1 1 | - * | x2^2+y2^2+z2^2+w2^2 x2 y2 z2 w2 1 | = 0 - * | x3^2+y3^2+z3^2+w3^2 x3 y3 z3 w3 1 | - * | x4^2+y4^2+z4^2+w4^2 x4 y4 z4 w4 1 | - * | x5^2+y5^2+z5^2+w5^2 x5 y5 z5 w5 1 | + * | x0^2+y0^2+z0^2+w0^2 x0 y0 z0 w0 1 | + * | x1^2+y1^2+z1^2+w1^2 x1 y1 z1 w1 1 | + * | x2^2+y2^2+z2^2+w2^2 x2 y2 z2 w2 1 | = 0 + * | x3^2+y3^2+z3^2+w3^2 x3 y3 z3 w3 1 | + * | x4^2+y4^2+z4^2+w4^2 x4 y4 z4 w4 1 | + * | x5^2+y5^2+z5^2+w5^2 x5 y5 z5 w5 1 | */ if ((w0*(-x1*(-y2*(-z4*(z5^2+y5^2+x5^2+w5^2) -z3*(-z5^2+z4^2-y5^2+y4^2-x5^2+x4^2-w5^2+w4^2) + diff --git a/cscript/README.src b/cscript/README.src index 767fb24..e930a8c 100644 --- a/cscript/README.src +++ b/cscript/README.src @@ -26,7 +26,7 @@ This is the correct way to form a calc shell script: /* * another correct comment */ - print "2+2 =", 2+2; ## yet another comment + print "2+2 =", 2+2; ## yet another comment The first argument after the path to calc executable must be an -S. The next arguments are optional. The -q is often recommended because @@ -58,10 +58,10 @@ For more info, see: 4dsphere x0 y0 z0 w0 x1 y1 z1 w1 ... x5 y5 z5 w5 - x0 y0 z0 w0 point 0 in R^4 - x1 y1 z1 w1 point 1 in R^4 - ... ... - x5 y5 z5 w5 point 5 in R^4 + x0 y0 z0 w0 point 0 in R^4 + x1 y1 z1 w1 point 1 in R^4 + ... ... + x5 y5 z5 w5 point 5 in R^4 fproduct filename term ... @@ -102,7 +102,7 @@ simple ## ## 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 +## 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 @@ -110,8 +110,8 @@ simple ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1999/12/17 10:23:40 -## File existed as early as: 1999 +## Under source code control: 1999/12/17 10:23:40 +## File existed as early as: 1999 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/cscript/fproduct.calc b/cscript/fproduct.calc index 22327bf..e0f20d0 100644 --- a/cscript/fproduct.calc +++ b/cscript/fproduct.calc @@ -5,10 +5,10 @@ * Copyright (C) 2001,2014,2019,2021 Landon Curt Noll * * usage: - * fproduct filename term [term ...] + * fproduct filename term [term ...] * - * filename where to write the product, use - for stdout - * term ... terms to multiply + * filename where to write the product, use - for stdout + * term ... terms to multiply * * 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 @@ -73,7 +73,7 @@ if (filename == "-") { if (product > 0) { octlen = int((highbit(product)+8) / 8); for (i=octlen-1; i >= 0; --i) { - fputc(fd, char(product >> (i*8))); + fputc(fd, char(product >> (i*8))); } } diff --git a/cscript/mersenne.calc b/cscript/mersenne.calc index 0f04446..b288279 100644 --- a/cscript/mersenne.calc +++ b/cscript/mersenne.calc @@ -10,7 +10,7 @@ * * 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 + * 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 @@ -18,14 +18,14 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/11/30 00:09:01; - * File existed as early as: 1999 + * Under source code control: 1999/11/30 00:09:01; + * File existed as early as: 1999 * - * chongo /\oo/\ http://www.isthe.com/chongo/ + * chongo /\oo/\ http://www.isthe.com/chongo/ * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ * * usage: - * mersenne exp + * mersenne exp */ diff --git a/cscript/piforever.calc b/cscript/piforever.calc index bb721d6..2c81b5f 100644 --- a/cscript/piforever.calc +++ b/cscript/piforever.calc @@ -10,7 +10,7 @@ * * 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 + * 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 @@ -18,14 +18,14 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/11/30 00:11:36 - * File existed as early as: 1999 + * Under source code control: 1999/11/30 00:11:36 + * File existed as early as: 1999 * - * chongo /\oo/\ http://www.isthe.com/chongo/ + * chongo /\oo/\ http://www.isthe.com/chongo/ * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ * * usage: - * piforever + * piforever */ diff --git a/cscript/plus.calc b/cscript/plus.calc index 1c0aa4d..9c49b7f 100644 --- a/cscript/plus.calc +++ b/cscript/plus.calc @@ -10,7 +10,7 @@ * * 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 + * 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 @@ -18,14 +18,14 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/11/29 10:22:37 - * File existed as early as: 1999 + * Under source code control: 1999/11/29 10:22:37 + * File existed as early as: 1999 * - * chongo /\oo/\ http://www.isthe.com/chongo/ + * chongo /\oo/\ http://www.isthe.com/chongo/ * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ * * usage: - * plus val ... + * plus val ... */ diff --git a/cscript/powerterm.calc b/cscript/powerterm.calc index 131d613..fc72831 100644 --- a/cscript/powerterm.calc +++ b/cscript/powerterm.calc @@ -7,16 +7,16 @@ * usage: * powerterm [base_limit] value * - * base_limit largest base we will consider (def: 10000) - * value value to convert into sums of powers of integers + * base_limit largest base we will consider (def: 10000) + * value value to convert into sums of powers of integers * * Example: * - * powerterm 5 1000000 + * powerterm 5 1000000 * * prints: * - * 4^10 - 3^10 + 5^6 - 4^6 - 4^5 - 2^5 + * 4^10 - 3^10 + 5^6 - 4^6 - 4^5 - 2^5 * * Calc is open software; you can redistribute it and/or modify it under * the powerterm of the version 2.1 of the GNU Lesser General Public License @@ -47,7 +47,7 @@ argc = argv(); stderr = files(2); program = argv(0); config("verbose_quit", 0),; -base_lim = 10000; /* default: highest base we will consider */ +base_lim = 10000; /* default: highest base we will consider */ if (argc < 2 || argc > 3) { fprintf(stderr, "usage: %s [base_limit] value\n", program); exit; @@ -75,20 +75,20 @@ if (base_lim <= 1) { /* * setup loop variables */ -term = 0; /* number of powerterm found */ +term = 0; /* number of powerterm found */ /* * log constants */ -if (base_lim <= 2^20+1) { /* 2^20 requires ~96 Megs of memory */ - mat lni[base_lim]; /* log of integers */ +if (base_lim <= 2^20+1) { /* 2^20 requires ~96 Megs of memory */ + mat lni[base_lim]; /* log of integers */ for (i=2; i < base_lim; ++i) { - lni[i] = ln(i); + lni[i] = ln(i); } - have_lni = 1; /* have lni[x] array */ + have_lni = 1; /* have lni[x] array */ } else { - mat lni[1]; /* not used */ - have_lni = 0; /* base_lim too large for array */ + mat lni[1]; /* not used */ + have_lni = 0; /* base_lim too large for array */ } /* @@ -99,82 +99,82 @@ while (abs(x) >= base_lim) { /* * look for the nearest power */ - lnx = ln(abs(x)); /* log of the remaining co-factor */ + lnx = ln(abs(x)); /* log of the remaining co-factor */ closest = 0.5; base = 1; exponent = 0; if (have_lni) { - /* - * use pre-calculated log array when looking for the nearest power - */ - for (i = 2; i < base_lim; ++i) { + /* + * use pre-calculated log array when looking for the nearest power + */ + for (i = 2; i < base_lim; ++i) { - /* - * determine exponent closeness to an integer - */ - ex = lnx / lni[i]; - power = int(ex + 0.5); - diff = ex - power; + /* + * determine exponent closeness to an integer + */ + ex = lnx / lni[i]; + power = int(ex + 0.5); + diff = ex - power; - /* - * look for a closer power - */ - if (abs(diff) < closest) { - closest = abs(diff); - base = i; - exponent = power; - } - } + /* + * look for a closer power + */ + if (abs(diff) < closest) { + closest = abs(diff); + base = i; + exponent = power; + } + } } else { - /* - * re-calculate logs when looking for the nearest power - */ - for (i = 2; i < base_lim; ++i) { + /* + * re-calculate logs when looking for the nearest power + */ + for (i = 2; i < base_lim; ++i) { - /* - * determine exponent closeness to an integer - */ - ex = lnx / ln(i); - power = int(ex + 0.5); - diff = ex - power; + /* + * determine exponent closeness to an integer + */ + ex = lnx / ln(i); + power = int(ex + 0.5); + diff = ex - power; - /* - * look for a closer power - */ - if (abs(diff) < closest) { - closest = abs(diff); - base = i; - exponent = power; - } - } + /* + * look for a closer power + */ + if (abs(diff) < closest) { + closest = abs(diff); + base = i; + exponent = power; + } + } } /* * output current term and then subtract it */ if (x != 0) { - if (x < 0) { - print "-",; - } else if (term > 0) { - print "+",; - } - if (exponent > 1) { - print base: "^": exponent,; - } else { - print base,; - } + if (x < 0) { + print "-",; + } else if (term > 0) { + print "+",; + } + if (exponent > 1) { + print base: "^": exponent,; + } else { + print base,; + } } /* * subtract (or add) this near power */ if (x < 0) { - x = x + base^exponent; + x = x + base^exponent; } else { - x = x - base^exponent; + x = x - base^exponent; } ++term; } diff --git a/cscript/simple.calc b/cscript/simple.calc index a30618a..b434abc 100644 --- a/cscript/simple.calc +++ b/cscript/simple.calc @@ -10,7 +10,7 @@ * * 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 + * 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 @@ -18,10 +18,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/11/29 10:22:37 - * File existed as early as: 1999 + * Under source code control: 1999/11/29 10:22:37 + * File existed as early as: 1999 * - * chongo /\oo/\ http://www.isthe.com/chongo/ + * chongo /\oo/\ http://www.isthe.com/chongo/ * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ diff --git a/cscript/square.calc b/cscript/square.calc index fe0e848..7758c4f 100644 --- a/cscript/square.calc +++ b/cscript/square.calc @@ -10,7 +10,7 @@ * * 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 + * 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 @@ -18,8 +18,8 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2000/12/15 06:52:01 - * File existed as early as: 2000 + * Under source code control: 2000/12/15 06:52:01 + * File existed as early as: 2000 * * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -48,8 +48,8 @@ * 1522756 * ln(2) * ~.48045301391820142467 - * 2i - * -4 + * 2i + * -4 * config("mode","frac"), bernoulli(10) * 25/4356 * config("mode", "hex"), 0xff @@ -58,5 +58,5 @@ while (s = fgetline(files(0))) { - print "\t":eval(s)^2; + print "\t":eval(s)^2; } diff --git a/custom.c b/custom.c index 7305f3e..0e92306 100644 --- a/custom.c +++ b/custom.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/03/03 04:53:08 - * File existed as early as: 1997 + * Under source code control: 1997/03/03 04:53:08 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -41,7 +41,7 @@ # include #endif -EXTERN CONST struct custom cust[]; /* custom interface table */ +EXTERN CONST struct custom cust[]; /* custom interface table */ #else /* CUSTOM */ @@ -51,10 +51,10 @@ EXTERN CONST struct custom cust[]; /* custom interface table */ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -bool allow_custom = false; /* true => custom builtins allowed */ +bool allow_custom = false; /* true => custom builtins allowed */ /* @@ -66,70 +66,70 @@ custom(char *name, int count, VALUE **vals) { #if defined(CUSTOM) - CONST struct custom *p; /* current function */ + CONST struct custom *p; /* current function */ - /* - * error if libcustcalc was compiled with CUSTOM undefined - */ - if (custom_compiled() != true) { - math_error("libcustcalc was compiled with CUSTOM undefined " - "custom_compiled() returned: %d != %d", - custom_compiled(), true); - not_reached(); - } + /* + * error if libcustcalc was compiled with CUSTOM undefined + */ + if (custom_compiled() != true) { + math_error("libcustcalc was compiled with CUSTOM undefined " + "custom_compiled() returned: %d != %d", + custom_compiled(), true); + not_reached(); + } - /* - * search the custom interface table for a function - */ - for (p = cust; p->name != NULL; ++p) { + /* + * search the custom interface table for a function + */ + for (p = cust; p->name != NULL; ++p) { - /* look for the first match */ - if (strcmp(name, p->name) == 0) { + /* look for the first match */ + if (strcmp(name, p->name) == 0) { - /* arg count check */ - if (count < p->minargs) { - math_error("Too few arguments for custom " - "function \"%s\"", p->name); - not_reached(); - } - if (count > p->maxargs) { - math_error("Too many arguments for custom " - "function \"%s\"", p->name); - not_reached(); - } + /* arg count check */ + if (count < p->minargs) { + math_error("Too few arguments for custom " + "function \"%s\"", p->name); + not_reached(); + } + if (count > p->maxargs) { + math_error("Too many arguments for custom " + "function \"%s\"", p->name); + not_reached(); + } - /* call the custom function */ - return p->func(name, count, vals); - } - } + /* call the custom function */ + return p->func(name, count, vals); + } + } - /* - * no such custom function - */ - return error_value(E_UNK_CUSTOM); + /* + * no such custom function + */ + return error_value(E_UNK_CUSTOM); #else /* CUSTOM */ - /* - * error if libcustcalc was compiled with CUSTOM defined - */ - if (custom_compiled() != false) { - math_error("libcustcalc was compiled with CUSTOM defined " - "custom_compiled() returned: %d != %d", - custom_compiled(), false); - not_reached(); - } + /* + * error if libcustcalc was compiled with CUSTOM defined + */ + if (custom_compiled() != false) { + math_error("libcustcalc was compiled with CUSTOM defined " + "custom_compiled() returned: %d != %d", + custom_compiled(), false); + not_reached(); + } - fprintf(stderr, - "%sCalc was built with custom functions disabled\n", - (conf->tab_ok ? "\t" : "")); - if (conf->calc_debug & CALCDBG_CUSTOM) { - fprintf(stderr, - "%scustom function %s with %d args, %s vals not executed\n", - (conf->tab_ok ? "\t" : ""), name, count, - (vals == NULL) ? "NULL" : "non-NULL"); - } - return error_value(E_NO_CUSTOM); + fprintf(stderr, + "%sCalc was built with custom functions disabled\n", + (conf->tab_ok ? "\t" : "")); + if (conf->calc_debug & CALCDBG_CUSTOM) { + fprintf(stderr, + "%scustom function %s with %d args, %s vals not executed\n", + (conf->tab_ok ? "\t" : ""), name, count, + (vals == NULL) ? "NULL" : "non-NULL"); + } + return error_value(E_NO_CUSTOM); #endif /* CUSTOM */ } @@ -144,40 +144,40 @@ showcustom(void) { #if defined(CUSTOM) - CONST struct custom *p; /* current function */ + CONST struct custom *p; /* current function */ - /* - * disable custom functions unless -C was given - */ - if (!allow_custom) { - fprintf(stderr, - "%sCalc must be run with a -C argument to " - "show custom functions\n", - (conf->tab_ok ? "\t" : "")); - return; - } + /* + * disable custom functions unless -C was given + */ + if (!allow_custom) { + fprintf(stderr, + "%sCalc must be run with a -C argument to " + "show custom functions\n", + (conf->tab_ok ? "\t" : "")); + return; + } - /* - * print header - */ - printf("\nName\tArgs\tDescription\n\n"); - for (p = cust; p->name != NULL; ++p) { - printf("%-9s ", p->name); - if (p->maxargs == MAX_CUSTOM_ARGS) - printf("%d+ ", p->minargs); - else if (p->minargs == p->maxargs) - printf("%-6d", p->minargs); - else - printf("%d-%-4d", p->minargs, p->maxargs); - printf("%s\n", p->desc); - } - printf("\n"); + /* + * print header + */ + printf("\nName\tArgs\tDescription\n\n"); + for (p = cust; p->name != NULL; ++p) { + printf("%-9s ", p->name); + if (p->maxargs == MAX_CUSTOM_ARGS) + printf("%d+ ", p->minargs); + else if (p->minargs == p->maxargs) + printf("%-6d", p->minargs); + else + printf("%d-%-4d", p->minargs, p->maxargs); + printf("%s\n", p->desc); + } + printf("\n"); #else /* CUSTOM */ - fprintf(stderr, - "%sCalc was built with custom functions disabled\n", - (conf->tab_ok ? "\t" : "")); + fprintf(stderr, + "%sCalc was built with custom functions disabled\n", + (conf->tab_ok ? "\t" : "")); #endif /* CUSTOM */ } @@ -198,7 +198,7 @@ showcustom(void) * and HELPDIR file and work directly with the custom help file. * * given: - * name name of the custom help file to directly access + * name name of the custom help file to directly access */ /*ARGSUSED*/ void @@ -206,48 +206,48 @@ customhelp(char *name) { #if defined(CUSTOM) - char *customname; /* a string of the form: custom/name */ - size_t snprintf_len; /* malloced snprintf buffer length */ + char *customname; /* a string of the form: custom/name */ + size_t snprintf_len; /* malloced snprintf buffer length */ - /* - * firewall - */ - if (name == NULL) { - name = "help"; - } + /* + * firewall + */ + if (name == NULL) { + name = "help"; + } - /* - * form the custom help name - */ - snprintf_len = sizeof("custhelp")+1+strlen(name)+1; - customname = (char *)malloc(snprintf_len+1); - if (customname == NULL) { - math_error("bad malloc of customname"); - not_reached(); - } - snprintf(customname, snprintf_len, "custhelp/%s", name); - customname[snprintf_len] = '\0'; /* paranoia */ + /* + * form the custom help name + */ + snprintf_len = sizeof("custhelp")+1+strlen(name)+1; + customname = (char *)malloc(snprintf_len+1); + if (customname == NULL) { + math_error("bad malloc of customname"); + not_reached(); + } + snprintf(customname, snprintf_len, "custhelp/%s", name); + customname[snprintf_len] = '\0'; /* paranoia */ - /* - * give help directly to the custom file - */ - givehelp(customname); + /* + * give help directly to the custom file + */ + givehelp(customname); - /* - * all done - */ - free(customname); + /* + * all done + */ + free(customname); #else /* CUSTOM */ - fprintf(stderr, - "%sCalc was built with custom functions disabled\n", - (conf->tab_ok ? "\t" : "")); - if (conf->calc_debug & CALCDBG_CUSTOM) { - fprintf(stderr, "%scustom help for %s unavailable\n", - (conf->tab_ok ? "\t" : ""), - ((name == NULL) ? "((NULL))" : name)); - } + fprintf(stderr, + "%sCalc was built with custom functions disabled\n", + (conf->tab_ok ? "\t" : "")); + if (conf->calc_debug & CALCDBG_CUSTOM) { + fprintf(stderr, "%scustom help for %s unavailable\n", + (conf->tab_ok ? "\t" : ""), + ((name == NULL) ? "((NULL))" : name)); + } #endif /* CUSTOM */ } diff --git a/custom.h b/custom.h index f2b1f63..cc5e0c2 100644 --- a/custom.h +++ b/custom.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/03/03 04:53:08 - * File existed as early as: 1997 + * Under source code control: 1997/03/03 04:53:08 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -30,8 +30,8 @@ * * Don't include anything, let the including .c file bring in: * - * have_const.h - * value.h + * have_const.h + * value.h * * before they include this file. * @@ -47,24 +47,24 @@ /* * arg count definitions */ -#define MAX_CUSTOM_ARGS 100 /* maximum number of custom arguments */ +#define MAX_CUSTOM_ARGS 100 /* maximum number of custom arguments */ /* * register count */ -#define CUSTOM_REG_MAX 31 /* maximum custom register number */ +#define CUSTOM_REG_MAX 31 /* maximum custom register number */ /* * custom function interface */ struct custom { - char *name; /* name of the custom builtin */ - char *desc; /* very brief description of custom builtin */ - short minargs; /* minimum number of arguments */ - short maxargs; /* maximum number of arguments */ - VALUE (*func)(char *name, int argc, VALUE **argv); /* custom func */ + char *name; /* name of the custom builtin */ + char *desc; /* very brief description of custom builtin */ + short minargs; /* minimum number of arguments */ + short maxargs; /* maximum number of arguments */ + VALUE (*func)(char *name, int argc, VALUE **argv); /* custom func */ }; @@ -73,11 +73,11 @@ struct custom { * * These are the required interfaces. The dummy.c stubs these interfaces too. */ -E_FUNC bool custom_compiled(void); /* return true if libcustcalc compiled CUSTOM defined, false otherwise */ -E_FUNC VALUE custom(char*, int, VALUE**); /* master custom interface */ -EXTERN bool allow_custom; /* true => custom builtins allowed */ -E_FUNC void showcustom(void); /* print custom functions */ -E_FUNC void customhelp(char *); /* direct custom help */ -E_FUNC void init_custreg(void); /* initialize custom registers */ +E_FUNC bool custom_compiled(void); /* return true if libcustcalc compiled CUSTOM defined, false otherwise */ +E_FUNC VALUE custom(char*, int, VALUE**); /* master custom interface */ +EXTERN bool allow_custom; /* true => custom builtins allowed */ +E_FUNC void showcustom(void); /* print custom functions */ +E_FUNC void customhelp(char *); /* direct custom help */ +E_FUNC void init_custreg(void); /* initialize custom registers */ #endif /* !CUSTOM_H */ diff --git a/custom/CUSTOM_CAL b/custom/CUSTOM_CAL index 6673662..0ffcc54 100644 --- a/custom/CUSTOM_CAL +++ b/custom/CUSTOM_CAL @@ -10,18 +10,18 @@ resource files are shipped with calc to provide you with examples. By default, the custom builtin returns an error. Calc have been built with: - ALLOW_CUSTOM= -DCUSTOM + ALLOW_CUSTOM= -DCUSTOM in the top level Makefile (this is the shipped default) and calc must be invoked with a -C argument: - calc -C + calc -C when it is run. To disable custom even if -C is given, calc must be built with: - ALLOW_CUSTOM="-UCUSTOM" + ALLOW_CUSTOM="-UCUSTOM" See the ../cal/README or "help resource" for information about calc resource standards and guidelines. @@ -53,7 +53,7 @@ pzasusb8.cal ## ## 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 +## 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 @@ -61,8 +61,8 @@ pzasusb8.cal ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/03/08 20:51:32 -## File existed as early as: 1997 +## Under source code control: 1997/03/08 20:51:32 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/custom/HOW_TO_ADD b/custom/HOW_TO_ADD index 1da2aa2..1862de2 100644 --- a/custom/HOW_TO_ADD +++ b/custom/HOW_TO_ADD @@ -7,7 +7,7 @@ Step 0: Determine if is should it be done? multi-precision calculations in a C-like environment. You should consider implementing algorithms in the calc language as a first choice. Sometimes an algorithm requires use of special hardware, a - non-portable OS or pre-compiled C library. In these cases a custom + non-portable OS or pre-compiled C library. In these cases a custom interface may be needed. The custom function interface is intended to make is easy for @@ -18,16 +18,16 @@ Step 0: Determine if is should it be done? So before you go to step 1, ask yourself: - + Can I implement this as a calc resource file or calc shell script? + + Can I implement this as a calc resource file or calc shell script? - If Yes, write the shell script or resource file and be done with it. - If No, continue to the next question ... + If Yes, write the shell script or resource file and be done with it. + If No, continue to the next question ... - + Does it require the use of non-portable features, - OS specific support or special hardware? + + Does it require the use of non-portable features, + OS specific support or special hardware? - If No, write it as a regular builtin function. - If Yes, continue to step 1 ... + If No, write it as a regular builtin function. + If Yes, continue to step 1 ... Step 1: Do some background work @@ -39,18 +39,18 @@ Step 1: Do some background work you look at some examples of custom functions. Look at the the following source files: - custom.c - custom.h - custom/custtbl.c - custom/c_*.[ch] - custom/*.cal - help/custom (or run: calc help custom) + custom.c + custom.h + custom/custtbl.c + custom/c_*.[ch] + custom/*.cal + help/custom (or run: calc help custom) You would be well advised to look at a more recent calc source such as one available in from the calc version archive. See the following for more details: - help/archive (or run: calc help archive) + help/archive (or run: calc help archive) Step 2: Name your custom function @@ -84,16 +84,16 @@ Step 3: Document your custom function Take a look at one of the example custom help files: - custom/devnull - custom/argv - custom/help - custom/sysinfo + custom/devnull + custom/argv + custom/help + custom/sysinfo You can save time by using one of the custom help files as a template. Copy one of these files to your own help file: - cd custom - cp sysinfo curds + cd custom + cp sysinfo curds and edit it accordingly. @@ -113,24 +113,24 @@ Step 4: Write your test code You can use one of the following as a template: - custom/argv.cal - custom/halflen.cal + custom/argv.cal + custom/halflen.cal Copy one of these to your own file: - cd custom - cp halflen.cal curds.cal + cd custom + cp halflen.cal curds.cal and exit it accordingly. In particular you will want to: - remove our header disclaimer (or put your own on) + remove our header disclaimer (or put your own on) - change the name from halflen() to curds() + change the name from halflen() to curds() - change the comment from 'halflen - determine the length ...' to - 'curds - brief description about ...' + change the comment from 'halflen - determine the length ...' to + 'curds - brief description about ...' - change other code as needed. + change other code as needed. Step 5: Write your custom function @@ -138,145 +138,145 @@ Step 5: Write your custom function By convention, the files we ship that contain custom function interface code in filenames of the form: - c_*.c + c_*.c We suggest that you use filenames of the form: - u_*.c + u_*.c to avoid filename conflicts. We recommend that you use one of the c_*.c files as a template. Copy an appropriate file to your file: - cd custom - cp c_argv.c u_curds.c + cd custom + cp c_argv.c u_curds.c Before you edit it, you should note that there are several important features of this file. - a) All of the code in the file is found between #if ... #endif: + a) All of the code in the file is found between #if ... #endif: - /* - * only comments and blank lines at the top - */ + /* + * only comments and blank lines at the top + */ - #if defined(CUSTOM) + #if defined(CUSTOM) - ... all code, #includes, #defines etc. + ... all code, #includes, #defines etc. - #endif /* CUSTOM */ + #endif /* CUSTOM */ - This allows this code to 'go away' when the upper Makefile - disables the custom code when CUSTOM is not defined. + This allows this code to 'go away' when the upper Makefile + disables the custom code when CUSTOM is not defined. - b) The function type must be: + b) The function type must be: - /*ARGSUSED*/ - VALUE - u_curds(char *name, int count, VALUE **vals) + /*ARGSUSED*/ + VALUE + u_curds(char *name, int count, VALUE **vals) - The 3 args are passed in by the custom interface - and have the following meaning: + The 3 args are passed in by the custom interface + and have the following meaning: - name The name of the custom function that - was called. In particular, this is the first - string arg that was given to the custom() - builtin. This is the equivalent of argv[0] for - main() in C programming. + name The name of the custom function that + was called. In particular, this is the first + string arg that was given to the custom() + builtin. This is the equivalent of argv[0] for + main() in C programming. - The same code can be used for multiple custom - functions by processing off of this value. + The same code can be used for multiple custom + functions by processing off of this value. - count This is the number of additional args that - was given to the custom() builtin. Note - that count does NOT include the name arg. - This is similar to argc except that count - is one less than the main() argc interface. + count This is the number of additional args that + was given to the custom() builtin. Note + that count does NOT include the name arg. + This is similar to argc except that count + is one less than the main() argc interface. - For example, a call of: + For example, a call of: - custom("curds", a, b, c) + custom("curds", a, b, c) - would cause count to be passed as 3. + would cause count to be passed as 3. - vals This is a pointer to an array of VALUEs. - This is the equivalent of argv+1 for - main() in C programming. The difference - here is that vals[0] refers to the 1st - parameter AFTER the same. + vals This is a pointer to an array of VALUEs. + This is the equivalent of argv+1 for + main() in C programming. The difference + here is that vals[0] refers to the 1st + parameter AFTER the same. - For example, a call of: + For example, a call of: - custom("curds", a, b, c) + custom("curds", a, b, c) - would cause vals to point to the following array: + would cause vals to point to the following array: - vals[0] points to a - vals[1] points to b - vals[2] points to c + vals[0] points to a + vals[1] points to b + vals[2] points to c - NOTE: If you do not use any of the 3 function parameters, - then you should declare that function parameter to be UNUSED. - For example, if the count and vals parameters were not used - in your custom function, then your declaration should be: + NOTE: If you do not use any of the 3 function parameters, + then you should declare that function parameter to be UNUSED. + For example, if the count and vals parameters were not used + in your custom function, then your declaration should be: - /*ARGSUSED*/ - VALUE - u_curds(char *name, int UNUSED count, VALUE UNUSED **vals) + /*ARGSUSED*/ + VALUE + u_curds(char *name, int UNUSED count, VALUE UNUSED **vals) - c) The return value is the function must be a VALUE. + c) The return value is the function must be a VALUE. - The typical way to form a VALUE to return is by declaring - the following local variable: + The typical way to form a VALUE to return is by declaring + the following local variable: - VALUE result; /* what we will return */ + VALUE result; /* what we will return */ - d) You will need to include: + d) You will need to include: - #if defined(CUSTOM) + #if defined(CUSTOM) - /* any #include here */ + /* any #include here */ - #include "../have_const.h" - #include "../value.h" - #include "custom.h" + #include "../have_const.h" + #include "../value.h" + #include "custom.h" - #include "../have_unused.h" + #include "../have_unused.h" - Typically these will be included just below any system - includes and just below the #if defined(CUSTOM) line. + Typically these will be included just below any system + includes and just below the #if defined(CUSTOM) line. To better understand the VALUE type, read: - ../value.h + ../value.h The VALUE is a union of major value types found inside calc. The v_type VALUE element determines which union element is - being used. Assume that we have: + being used. Assume that we have: - VALUE *vp; + VALUE *vp; Then the value is determined according to v_type: - vp->v_type the value is which is a type defined in - ---------- ------------ ---------- --------------- - V_NULL (none) n/a n/a - V_INT vp->v_int long n/a - V_NUM vp->v_num NUMBER * ../qmath.h - V_COM vp->v_com COMPLEX * ../cmath.h - V_ADDR vp->v_addr VALUE * ../value.h - V_STR vp->v_str char * n/a - V_MAT vp->v_mat MATRIX * ../value.h - V_LIST vp->v_list LIST * ../value.h - V_ASSOC vp->v_assoc ASSOC * ../value.h - V_OBJ vp->v_obj OBJECT * ../value.h - V_FILE vp->v_file FILEID ../value.h - V_RAND vp->v_rand RAND * ../zrand.h - V_RANDOM vp->v_random RANDOM * ../zrandom.h - V_CONFIG vp->v_config CONFIG * ../config.h - V_HASH vp->v_hash HASH * ../hash.h - V_BLOCK vp->v_block BLOCK * ../block.h + vp->v_type the value is which is a type defined in + ---------- ------------ ---------- --------------- + V_NULL (none) n/a n/a + V_INT vp->v_int long n/a + V_NUM vp->v_num NUMBER * ../qmath.h + V_COM vp->v_com COMPLEX * ../cmath.h + V_ADDR vp->v_addr VALUE * ../value.h + V_STR vp->v_str char * n/a + V_MAT vp->v_mat MATRIX * ../value.h + V_LIST vp->v_list LIST * ../value.h + V_ASSOC vp->v_assoc ASSOC * ../value.h + V_OBJ vp->v_obj OBJECT * ../value.h + V_FILE vp->v_file FILEID ../value.h + V_RAND vp->v_rand RAND * ../zrand.h + V_RANDOM vp->v_random RANDOM * ../zrandom.h + V_CONFIG vp->v_config CONFIG * ../config.h + V_HASH vp->v_hash HASH * ../hash.h + V_BLOCK vp->v_block BLOCK * ../block.h The V_OCTET is under review and should not be used at this time. @@ -285,100 +285,100 @@ Step 5: Write your custom function you might also want to read the following to understand some of the numerical types of ZVALUE, NUMBER and COMPLEX: - ../zmath.h - ../qmath.h - ../cmath.h + ../zmath.h + ../qmath.h + ../cmath.h While we cannot go into full detail here are some cookbook code for manipulating VALUEs. For these examples assume that we will manipulate the return value: - VALUE result; /* what we will return */ + VALUE result; /* what we will return */ To return NULL: - result.v_type = V_NULL; - return result; + result.v_type = V_NULL; + return result; To return a long you need to convert it to a NUMBER: - long variable; + long variable; - result.v_type = V_NUM; - result.v_num = itoq(variable); /* see ../qmath.c */ - return result; + result.v_type = V_NUM; + result.v_num = itoq(variable); /* see ../qmath.c */ + return result; To return a FULL you need to convert it to a NUMBER: - FULL variable; + FULL variable; - result.v_type = V_NUM; - result.v_num = utoq(variable); /* see ../qmath.c */ - return result; + result.v_type = V_NUM; + result.v_num = utoq(variable); /* see ../qmath.c */ + return result; To convert a ZVALUE to a NUMBER*: - ZVALUE variable; + ZVALUE variable; - result.v_type = V_NUM; - result.v_num = qalloc(); /* see ../qmath.c */ - result.v_num->num = variable; - return result; + result.v_type = V_NUM; + result.v_num = qalloc(); /* see ../qmath.c */ + result.v_num->num = variable; + return result; To convert a small NUMBER* into a long: - NUMBER *num; - long variable; + NUMBER *num; + long variable; - variable = qtoi(num); + variable = qtoi(num); To obtain a ZVALUE from a NUMBER*, extract the numerator: - NUMBER *num; - ZVALUE z_variable; + NUMBER *num; + ZVALUE z_variable; - if (qisint(num)) { - z_variable = num->num; - } + if (qisint(num)) { + z_variable = num->num; + } To be sure that the value will fit, use the ZVALUE test macros: - ZVALUE z_num; - long variable; - unsigned long u_variable; - FULL f_variable; - short very_tiny_variable; + ZVALUE z_num; + long variable; + unsigned long u_variable; + FULL f_variable; + short very_tiny_variable; - if (zgtmaxlong(z_num)) { /* see ../zmath.h */ - variable = ztolong(z_num); - } - if (zgtmaxulong(z_num)) { - u_variable = ztoulong(z_num); - } - if (zgtmaxufull(z_num)) { - f_variable = ztofull(z_num); - } - if (zistiny(z_num)) { - very_tiny_variable = z1tol(z_num); - } + if (zgtmaxlong(z_num)) { /* see ../zmath.h */ + variable = ztolong(z_num); + } + if (zgtmaxulong(z_num)) { + u_variable = ztoulong(z_num); + } + if (zgtmaxufull(z_num)) { + f_variable = ztofull(z_num); + } + if (zistiny(z_num)) { + very_tiny_variable = z1tol(z_num); + } You can (and should) add debugging statements to your custom code by examining bit 8 of the calc_debug config flag: - if (conf->calc_debug & CALCDBG_CUSTOM) { - fprintf(stderr, "%ssome custom debug note: msg\n", - (conf->tab_ok ? "\t" : ""), - ((msg == NULL) ? "((NULL))" : msg)); - } + if (conf->calc_debug & CALCDBG_CUSTOM) { + fprintf(stderr, "%ssome custom debug note: msg\n", + (conf->tab_ok ? "\t" : ""), + ((msg == NULL) ? "((NULL))" : msg)); + } One is able to set bit 8 by way of the calc command line: - calc -D 128 + calc -D 128 See the calc man page for details. One may also set that bit while running calc by way of the config() builtin function: - config("calc_debug", 128); + config("calc_debug", 128); See the help/config file for details on calc_debug. @@ -388,81 +388,81 @@ Step 6: Register the function in the custom interface table you need to add an entry into the CONST struct custom cust table found in custom/custtbl.c: - /* - * custom interface table - * - * The order of the elements in struct custom are: - * - * { "xyz", "brief description of the xyz custom function", - * minimum_args, maximum_args, c_xyz }, - * - * where: - * - * minimum_args an int >= 0 - * maximum_args an int >= minimum_args and <= MAX_CUSTOM_ARGS - * - * Use MAX_CUSTOM_ARGS for maximum_args is the maximum number of args - * is potentially 'unlimited'. - * - * If the brief description cannot fit on the same line as the name - * without wrapping on a 80 col window, the description is probably - * too long and will not look nice in the show custom output. - */ - CONST struct custom cust[] = { + /* + * custom interface table + * + * The order of the elements in struct custom are: + * + * { "xyz", "brief description of the xyz custom function", + * minimum_args, maximum_args, c_xyz }, + * + * where: + * + * minimum_args an int >= 0 + * maximum_args an int >= minimum_args and <= MAX_CUSTOM_ARGS + * + * Use MAX_CUSTOM_ARGS for maximum_args is the maximum number of args + * is potentially 'unlimited'. + * + * If the brief description cannot fit on the same line as the name + * without wrapping on a 80 col window, the description is probably + * too long and will not look nice in the show custom output. + */ + CONST struct custom cust[] = { - #if defined(CUSTOM) + #if defined(CUSTOM) - /* - * add your own custom functions here - * - * We suggest that you sort the entries below by name - * so that show custom will produce a nice sorted list. - */ + /* + * add your own custom functions here + * + * We suggest that you sort the entries below by name + * so that show custom will produce a nice sorted list. + */ - { "argv", "information about its args, returns arg count", - 0, MAX_CUSTOM_ARGS, c_argv }, + { "argv", "information about its args, returns arg count", + 0, MAX_CUSTOM_ARGS, c_argv }, - { "devnull", "does nothing", - 0, MAX_CUSTOM_ARGS, c_devnull }, + { "devnull", "does nothing", + 0, MAX_CUSTOM_ARGS, c_devnull }, - { "help", "help for custom functions", - 1, 1, c_help }, + { "help", "help for custom functions", + 1, 1, c_help }, - { "sysinfo", "return a calc #define value", - 0, 1, c_sysinfo }, + { "sysinfo", "return a calc #define value", + 0, 1, c_sysinfo }, - #endif /* CUSTOM */ + #endif /* CUSTOM */ - /* - * This must be at the end of this table!!! - */ - {NULL, NULL, - 0, 0, NULL} - }; + /* + * This must be at the end of this table!!! + */ + {NULL, NULL, + 0, 0, NULL} + }; The definition of struct custom may be found in custom.h. It is important that your entry be placed inside the: - #if defined(CUSTOM) ... #endif /* CUSTOM */ + #if defined(CUSTOM) ... #endif /* CUSTOM */ lines so that when the custom interface is disabled by the upper level Makefile, one does not have unsatisfied symbols. The brief description should be brief so that 'show custom' looks well - formatted. If the brief description cannot fit on the same line as + formatted. If the brief description cannot fit on the same line as the name without wrapping on a 80 col window, the description is probably too long and will not look nice in the show custom output. The minargs places a lower bound on the number of args that - must be supplied to the interface. This does NOT count + must be supplied to the interface. This does NOT count the name argument given to custom(). So if minargs is 2: - custom("curds") /* call blocked at high level interface */ - custom("curds", a) /* call blocked at high level interface */ - custom("curds", a, b) /* call passed down to "curds" interface */ + custom("curds") /* call blocked at high level interface */ + custom("curds", a) /* call blocked at high level interface */ + custom("curds", a, b) /* call passed down to "curds" interface */ The maxargs sets a limit on the number of args that may be passed. If minargs == maxargs, then the call requires a fixed number of @@ -471,39 +471,39 @@ Step 6: Register the function in the custom interface table Note that one must have: - 0 <= minargs <= maxargs <= MAX_CUSTOM_ARGS + 0 <= minargs <= maxargs <= MAX_CUSTOM_ARGS To allow the curds function to take at least 2 args and up to 5 args, one would add the following entry to cust[]: - { "curds", "brief description about curds interface", - 2, 5, u_curds }, + { "curds", "brief description about curds interface", + 2, 5, u_curds }, It is recommended that the cust[] remain in alphabetical order, so one would place it before the "devnull" and after "argv". Last, you must forward declare the u_curds near the top of the file: - #if defined(CUSTOM) + #if defined(CUSTOM) - /* - * add your forward custom function declarations here - * - * Declare custom functions as follows: - * - * E_FUNC VALUE c_xyz(char*, int, VALUE**); - * - * We suggest that you sort the entries below by name. - */ - E_FUNC VALUE c_argv(char*, int, VALUE**); - E_FUNC VALUE c_devnull(char*, int, VALUE**); - E_FUNC VALUE c_help(char*, int, VALUE**); - E_FUNC VALUE c_sysinfo(char*, int, VALUE**); + /* + * add your forward custom function declarations here + * + * Declare custom functions as follows: + * + * E_FUNC VALUE c_xyz(char*, int, VALUE**); + * + * We suggest that you sort the entries below by name. + */ + E_FUNC VALUE c_argv(char*, int, VALUE**); + E_FUNC VALUE c_devnull(char*, int, VALUE**); + E_FUNC VALUE c_help(char*, int, VALUE**); + E_FUNC VALUE c_sysinfo(char*, int, VALUE**); For u_curds we would add the line: - E_FUNC VALUE u_curds(char*, int, VALUE**); + E_FUNC VALUE u_curds(char*, int, VALUE**); Step 7: Add the required information to the custom/Makefile.head @@ -511,26 +511,26 @@ Step 7: Add the required information to the custom/Makefile.head The calc test script, curds.cal, should be added to the CUSTOM_CALC_FILES Makefile variable found in custom/Makefile.head: - CUSTOM_CALC_FILES= argv.cal halflen.cal curds.cal + CUSTOM_CALC_FILES= argv.cal halflen.cal curds.cal The help file, curds, should be added to the CUSTOM_HELP custom/Makefile.head variable: - CUSTOM_HELP= argv devnull help sysinfo curds + CUSTOM_HELP= argv devnull help sysinfo curds If you needed to create any .h files to support u_curds.c, these files should be added to the CUSTOM_H_SRC custom/Makefile.head variable: - CUSTOM_H_SRC= u_curds.h otherfile.h + CUSTOM_H_SRC= u_curds.h otherfile.h Your u_curds.c file MUST be added to the CUSTOM_SRC custom/Makefile.head variable: - CUSTOM_SRC= c_argv.c c_devnull.c c_help.c c_sysinfo.c u_curds.c + CUSTOM_SRC= c_argv.c c_devnull.c c_help.c c_sysinfo.c u_curds.c and so must the associated .o file: - CUSTOM_OBJ= c_argv.o c_devnull.o c_help.o c_sysinfo.o u_curds.o + CUSTOM_OBJ= c_argv.o c_devnull.o c_help.o c_sysinfo.o u_curds.o Step 8: Compile and link in your code @@ -540,25 +540,25 @@ Step 8: Compile and link in your code the custom Makefile) should have the following Makefile variable defined: - ALLOW_CUSTOM= -DCUSTOM + ALLOW_CUSTOM= -DCUSTOM It is recommended that you build your code from the top level Makefile. It saves having to sync the other Makefile values. To try and build the new libcustcalc.a that contains u_curds.c: - (cd ..; make custom/libcustcalc.a) + (cd ..; make custom/libcustcalc.a) Fix any compile and syntax errors as needed. :-) Once libcustcalc.a successfully builds, compile calc: - cd .. - make calc + cd .. + make calc And check to be sure that the regression test suite still works without errors: - make check + make check Step 9: Add the Make dependency tools @@ -567,66 +567,66 @@ Step 9: Add the Make dependency tools the Makefile. Given the required include files, you will at least have the following entries placed at the bottom of the Makefile: - u_curds.o: ../alloc.h - u_curds.o: ../block.h - u_curds.o: ../byteswap.h - u_curds.o: ../cmath.h - u_curds.o: ../config.h - u_curds.o: ../endian_calc.h - u_curds.o: ../errsym.h - u_curds.o: ../hash.h - u_curds.o: ../have_const.h - u_curds.o: ../have_malloc.h - u_curds.o: ../have_newstr.h - u_curds.o: ../have_stdlib.h - u_curds.o: ../have_string.h - u_curds.o: ../longbits.h - u_curds.o: ../nametype.h - u_curds.o: ../qmath.h - u_curds.o: ../shs.h - u_curds.o: ../value.h - u_curds.o: ../zmath.h - u_curds.o: u_curds.c - u_curds.o: ../custom.h + u_curds.o: ../alloc.h + u_curds.o: ../block.h + u_curds.o: ../byteswap.h + u_curds.o: ../cmath.h + u_curds.o: ../config.h + u_curds.o: ../endian_calc.h + u_curds.o: ../errsym.h + u_curds.o: ../hash.h + u_curds.o: ../have_const.h + u_curds.o: ../have_malloc.h + u_curds.o: ../have_newstr.h + u_curds.o: ../have_stdlib.h + u_curds.o: ../have_string.h + u_curds.o: ../longbits.h + u_curds.o: ../nametype.h + u_curds.o: ../qmath.h + u_curds.o: ../shs.h + u_curds.o: ../value.h + u_curds.o: ../zmath.h + u_curds.o: u_curds.c + u_curds.o: ../custom.h If you have the makedepend tool from the X11 development environment (by Todd Brunhoff, Tektronix, Inc. and MIT Project Athena), you can use the following to update your dependencies: - # cd to the top level calc directory if you are not there already + # cd to the top level calc directory if you are not there already - rm -f Makefile.bak custom/Makefile.bak - make depend + rm -f Makefile.bak custom/Makefile.bak + make depend - diff -c Makefile.bak Makefile # look at the changes - diff -c custom/Makefile.bak custom/Makefile # look at the changes + diff -c Makefile.bak Makefile # look at the changes + diff -c custom/Makefile.bak custom/Makefile # look at the changes - rm -f Makefile.bak custom/Makefile.bak # cleanup + rm -f Makefile.bak custom/Makefile.bak # cleanup Step 10: Test Now that you have built calc with your new custom function, test it: - ./calc -C # run the new calc with the -C arg + ./calc -C # run the new calc with the -C arg And then try out our test suite: - C-style arbitrary precision calculator (version 2.10.3t5.1) - [Type "exit" to exit, or "help" for help.] + C-style arbitrary precision calculator (version 2.10.3t5.1) + [Type "exit" to exit, or "help" for help.] - > read custom/curds.cal - curds(a, b, [c, d, e]) defined + > read custom/curds.cal + curds(a, b, [c, d, e]) defined - > custom("curds", 2, 3, 4) + > custom("curds", 2, 3, 4) Step 11: Install Once you are satisfied that everything works, install the new code: - # cd to the top level calc directory if you are not there already + # cd to the top level calc directory if you are not there already - make install + make install Although calc does not run setuid, you may need to be root to install the directories into which calc installs may be write protected. @@ -639,7 +639,7 @@ Step 12: Contribute Read the file: - help/contrib (or run: calc help contrib) + help/contrib (or run: calc help contrib) and consider submitting your custom function for possible inclusion in later versions of calc. @@ -652,7 +652,7 @@ Step 12: Contribute ## ## 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 +## 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 @@ -660,8 +660,8 @@ Step 12: Contribute ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/03/10 03:03:21 -## File existed as early as: 1997 +## Under source code control: 1997/03/10 03:03:21 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/custom/argv b/custom/argv index 57dff48..0522e13 100644 --- a/custom/argv +++ b/custom/argv @@ -5,17 +5,17 @@ SYNOPSIS custom("argv" [, arg ...]) TYPES - arg any + arg any - return int + return int DESCRIPTION This custom function will, for each arg given print: - arg number - arg type - number of elements (size()) - memory size (sizeof()) + arg number + arg type + number of elements (size()) + memory size (sizeof()) The number of args passed, not counting the initial "argv" name arg is returned. @@ -23,12 +23,12 @@ DESCRIPTION EXAMPLE > foo=5^713; bar=17; baz=list(2,3,4); > custom("argv", foo, bar, baz, 3+4.5i, pi()) - arg[0] rational_value size=1 sizeof=272 - arg[1] rational_value size=1 sizeof=68 - arg[2] list size=3 sizeof=256 - arg[3] complex_value size=1 sizeof=140 - arg[4] rational_value size=1 sizeof=84 - 5 + arg[0] rational_value size=1 sizeof=272 + arg[1] rational_value size=1 sizeof=68 + arg[2] list size=3 sizeof=256 + arg[3] complex_value size=1 sizeof=140 + arg[4] rational_value size=1 sizeof=84 + 5 LIMITS calc must be built with ALLOW_CUSTOM= -DCUSTOM @@ -48,7 +48,7 @@ SEE ALSO ## ## 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 +## 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 @@ -56,8 +56,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/03/09 20:28:01 -## File existed as early as: 1997 +## Under source code control: 1997/03/09 20:28:01 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/custom/argv.cal b/custom/argv.cal index 0e29a42..37e6869 100644 --- a/custom/argv.cal +++ b/custom/argv.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,41 +17,41 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/03/10 00:27:17 - * File existed as early as: 1997 + * Under source code control: 1997/03/10 00:27:17 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * This file is part of the custom sample calc files. * * NOTE: You must use a calc that was compiled with ALLOW_CUSTOM= -DCUSTOM - * and run with a -C arg. + * and run with a -C arg. */ if (config("compile_custom") == 0) { - quit "calc compiled without -DCUSTOM"; + quit "calc compiled without -DCUSTOM"; } else if (config("allow_custom") == 0) { - quit "calc was run without the -D command line option"; + quit "calc was run without the -D command line option"; } define argv_test() { - local i; /* arg number */ - local junk; /* throw away value */ + local i; /* arg number */ + local junk; /* throw away value */ - /* - * process each arg passed to us - */ - for (i = 1; i <= param(0); ++i) { - /* - * This won't really work because all the arg numbers - * will be reported as arg[0] ... but what the heck - * this is only a demo! - */ - junk = custom("argv", param(i)); - } - return i-1; + /* + * process each arg passed to us + */ + for (i = 1; i <= param(0); ++i) { + /* + * This won't really work because all the arg numbers + * will be reported as arg[0] ... but what the heck + * this is only a demo! + */ + junk = custom("argv", param(i)); + } + return i-1; } diff --git a/custom/c_argv.c b/custom/c_argv.c index 8497eaa..7cafc1b 100644 --- a/custom/c_argv.c +++ b/custom/c_argv.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/03/09 20:27:37 - * File existed as early as: 1997 + * Under source code control: 1997/03/09 20:27:37 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -30,9 +30,9 @@ * so we declare a global variable whose value is based on if CUSTOM is defined. */ #if defined(CUSTOM) -int c_argv_allowed = 1; /* CUSTOM defined */ +int c_argv_allowed = 1; /* CUSTOM defined */ #else /* CUSTOM */ -int c_argv_allowed = 0; /* CUSTOM undefined */ +int c_argv_allowed = 0; /* CUSTOM undefined */ #endif /* CUSTOM */ @@ -50,129 +50,129 @@ int c_argv_allowed = 0; /* CUSTOM undefined */ #include "../have_unused.h" -#include "../banned.h" /* include after system header <> includes */ +#include "../banned.h" /* include after system header <> includes */ /* * c_argv - a custom function display info about its args * * given: - * vals[i] and arg to display information about + * vals[i] and arg to display information about * * returns: - * count + * count */ /*ARGSUSED*/ VALUE c_argv(char *UNUSED(name), int count, VALUE **vals) { - VALUE result; /* what we will return */ - ZVALUE zfilelen; /* length of a file as a ZVALUE */ - NUMBER *filelen; /* pointer to length of a file as a NUMBER */ - char *type; /* the name of the arg type */ - int i; + VALUE result; /* what we will return */ + ZVALUE zfilelen; /* length of a file as a ZVALUE */ + NUMBER *filelen; /* pointer to length of a file as a NUMBER */ + char *type; /* the name of the arg type */ + int i; - /* - * print info on each arg - */ - for (i=0; i < count; ++i) { + /* + * print info on each arg + */ + for (i=0; i < count; ++i) { - /* - * print arg number with leading tab as configured - */ - printf("%sarg[%d]", (conf->tab_ok ? "\t" : ""), i); + /* + * print arg number with leading tab as configured + */ + printf("%sarg[%d]", (conf->tab_ok ? "\t" : ""), i); - /* - * print the arg type - */ - switch (vals[i]->v_type) { - case V_NULL: /* null value */ - type = "null"; - break; - case V_INT: /* normal integer */ - type = "int"; - break; - case V_NUM: /* number */ - type = "rational_value"; - break; - case V_COM: /* complex number */ - type = "complex_value"; - break; - case V_ADDR: /* address of variable value */ - type = "address"; - break; - case V_STR: /* address of string */ - type = "string"; - break; - case V_MAT: /* address of matrix structure */ - type = "matrix"; - break; - case V_LIST: /* address of list structure */ - type = "list"; - break; - case V_ASSOC: /* address of association structure */ - type = "assoc"; - break; - case V_OBJ: /* address of object structure */ - type = "object"; - break; - case V_FILE: /* opened file id */ - type = "file"; - break; - case V_RAND: /* subtractive 100 random state */ - type = "rand_state"; - break; - case V_RANDOM: /* address of Blum random state */ - type = "random_state"; - break; - case V_CONFIG: /* configuration state */ - type = "config_state"; - break; - case V_HASH: /* hash state */ - type = "hash_state"; - break; - case V_BLOCK: /* memory block */ - type = "octet_block"; - break; - case V_OCTET: /* octet (unsigned char) */ - type = "octet"; - break; - default: - type = "unknown"; - break; - } - printf("\t%-16s", type); + /* + * print the arg type + */ + switch (vals[i]->v_type) { + case V_NULL: /* null value */ + type = "null"; + break; + case V_INT: /* normal integer */ + type = "int"; + break; + case V_NUM: /* number */ + type = "rational_value"; + break; + case V_COM: /* complex number */ + type = "complex_value"; + break; + case V_ADDR: /* address of variable value */ + type = "address"; + break; + case V_STR: /* address of string */ + type = "string"; + break; + case V_MAT: /* address of matrix structure */ + type = "matrix"; + break; + case V_LIST: /* address of list structure */ + type = "list"; + break; + case V_ASSOC: /* address of association structure */ + type = "assoc"; + break; + case V_OBJ: /* address of object structure */ + type = "object"; + break; + case V_FILE: /* opened file id */ + type = "file"; + break; + case V_RAND: /* subtractive 100 random state */ + type = "rand_state"; + break; + case V_RANDOM: /* address of Blum random state */ + type = "random_state"; + break; + case V_CONFIG: /* configuration state */ + type = "config_state"; + break; + case V_HASH: /* hash state */ + type = "hash_state"; + break; + case V_BLOCK: /* memory block */ + type = "octet_block"; + break; + case V_OCTET: /* octet (unsigned char) */ + type = "octet"; + break; + default: + type = "unknown"; + break; + } + printf("\t%-16s", type); - /* - * print size and sizeof information - * - * We have to treat files in a special way - * because their length can be very long. - */ - if (vals[i]->v_type == V_FILE) { - /* get the file length */ - if (getsize(vals[i]->v_file, &zfilelen) == 0) { - filelen = qalloc(); - filelen->num = zfilelen; - qprintfd(filelen, 0L); - qfree(filelen); - } else { - /* getsize error */ - printf("\tsize=unknown"); - } - printf("\tsizeof=%ld\n", (long int)lsizeof(vals[i])); - } else { - printf("\tsize=%ld\tsizeof=%ld\n", - elm_count(vals[i]), (long int)lsizeof(vals[i])); - } - } + /* + * print size and sizeof information + * + * We have to treat files in a special way + * because their length can be very long. + */ + if (vals[i]->v_type == V_FILE) { + /* get the file length */ + if (getsize(vals[i]->v_file, &zfilelen) == 0) { + filelen = qalloc(); + filelen->num = zfilelen; + qprintfd(filelen, 0L); + qfree(filelen); + } else { + /* getsize error */ + printf("\tsize=unknown"); + } + printf("\tsizeof=%ld\n", (long int)lsizeof(vals[i])); + } else { + printf("\tsize=%ld\tsizeof=%ld\n", + elm_count(vals[i]), (long int)lsizeof(vals[i])); + } + } - /* - * return count - */ - result.v_type = V_NUM; - result.v_num = itoq(count); - return result; + /* + * return count + */ + result.v_type = V_NUM; + result.v_num = itoq(count); + return result; } #endif /* CUSTOM */ diff --git a/custom/c_devnull.c b/custom/c_devnull.c index dbb11b5..8a62b2c 100644 --- a/custom/c_devnull.c +++ b/custom/c_devnull.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/03/09 17:49:12 - * File existed as early as: 1997 + * Under source code control: 1997/03/09 17:49:12 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -30,9 +30,9 @@ * so we declare a global variable whose value is based on if CUSTOM is defined. */ #if defined(CUSTOM) -int c_devnull_allowed = 1; /* CUSTOM defined */ +int c_devnull_allowed = 1; /* CUSTOM defined */ #else /* CUSTOM */ -int c_devnull_allowed = 0; /* CUSTOM undefined */ +int c_devnull_allowed = 0; /* CUSTOM undefined */ #endif /* CUSTOM */ @@ -50,7 +50,7 @@ int c_devnull_allowed = 0; /* CUSTOM undefined */ #include "../have_unused.h" -#include "../banned.h" /* include after system header <> includes */ +#include "../banned.h" /* include after system header <> includes */ /* @@ -63,13 +63,13 @@ int c_devnull_allowed = 0; /* CUSTOM undefined */ VALUE c_devnull(char *UNUSED(name), int UNUSED(count), VALUE **UNUSED(vals)) { - VALUE result; /* what we will return */ + VALUE result; /* what we will return */ - /* - * return NULL - */ - result.v_type = V_NULL; - return result; + /* + * return NULL + */ + result.v_type = V_NULL; + return result; } #endif /* CUSTOM */ diff --git a/custom/c_help.c b/custom/c_help.c index 21cca12..4a76974 100644 --- a/custom/c_help.c +++ b/custom/c_help.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/03/09 05:25:41 - * File existed as early as: 1997 + * Under source code control: 1997/03/09 05:25:41 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -30,9 +30,9 @@ * so we declare a global variable whose value is based on if CUSTOM is defined. */ #if defined(CUSTOM) -int c_help_allowed = 1; /* CUSTOM defined */ +int c_help_allowed = 1; /* CUSTOM defined */ #else /* CUSTOM */ -int c_help_allowed = 0; /* CUSTOM undefined */ +int c_help_allowed = 0; /* CUSTOM undefined */ #endif /* CUSTOM */ @@ -51,7 +51,7 @@ int c_help_allowed = 0; /* CUSTOM undefined */ #include "../errtbl.h" -#include "../banned.h" /* include after system header <> includes */ +#include "../banned.h" /* include after system header <> includes */ /* @@ -69,32 +69,32 @@ int c_help_allowed = 0; /* CUSTOM undefined */ * and HELPDIR file and work directly with the custom help file. * * given: - * vals[0] name of the custom help file to directly access + * vals[0] name of the custom help file to directly access */ /*ARGSUSED*/ VALUE c_help(char *UNUSED(name), int UNUSED(count), VALUE **vals) { - VALUE result; /* what we will return */ + VALUE result; /* what we will return */ - /* - * parse args - */ - if (vals[0]->v_type != V_STR) { - math_error("custom help arg 1 must be a string"); - not_reached(); - } + /* + * parse args + */ + if (vals[0]->v_type != V_STR) { + math_error("custom help arg 1 must be a string"); + not_reached(); + } - /* - * give the help - */ - customhelp((char *)vals[0]->v_str); + /* + * give the help + */ + customhelp((char *)vals[0]->v_str); - /* - * return NULL - */ - result.v_type = V_NULL; - return result; + /* + * return NULL + */ + result.v_type = V_NULL; + return result; } #endif /* CUSTOM */ diff --git a/custom/c_pmodm127.c b/custom/c_pmodm127.c index 9ca3934..67ad55f 100644 --- a/custom/c_pmodm127.c +++ b/custom/c_pmodm127.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2004/07/28 22:12:25 - * File existed as early as: 2004 + * Under source code control: 2004/07/28 22:12:25 + * File existed as early as: 2004 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -29,9 +29,9 @@ * so we declare a global variable whose value is based on if CUSTOM is defined. */ #if defined(CUSTOM) -int c_pmodm127_allowed = 1; /* CUSTOM defined */ +int c_pmodm127_allowed = 1; /* CUSTOM defined */ #else /* CUSTOM */ -int c_pmodm127_allowed = 0; /* CUSTOM undefined */ +int c_pmodm127_allowed = 0; /* CUSTOM undefined */ #endif /* CUSTOM */ @@ -48,19 +48,19 @@ int c_pmodm127_allowed = 0; /* CUSTOM undefined */ #include "../errtbl.h" -#include "../banned.h" /* include after system header <> includes */ +#include "../banned.h" /* include after system header <> includes */ /* 2^255 */ STATIC HALF h255[] = { #if BASEB == 32 - (HALF)0x00000000, (HALF)0x00000000, (HALF)0x00000000, (HALF)0x00000000, - (HALF)0x00000000, (HALF)0x00000000, (HALF)0x00000000, (HALF)0x80000000 + (HALF)0x00000000, (HALF)0x00000000, (HALF)0x00000000, (HALF)0x00000000, + (HALF)0x00000000, (HALF)0x00000000, (HALF)0x00000000, (HALF)0x80000000 #else /* BASEB == 32 */ - (HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x0000, - (HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x0000, - (HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x0000, - (HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x8000 + (HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x0000, + (HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x0000, + (HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x0000, + (HALF)0x0000, (HALF)0x0000, (HALF)0x0000, (HALF)0x8000 #endif /* BASEB == 32 */ }; ZVALUE p255 = { @@ -80,109 +80,109 @@ STATIC ZVALUE lastmodinv[1]; * * given: * count = 1; - * vals[0] real number; (q - potential factor) + * vals[0] real number; (q - potential factor) * * returns: - * result real number; (q mod 2^(2^127-1)) + * result real number; (q mod 2^(2^127-1)) */ /*ARGSUSED*/ VALUE c_pmodm127(char *UNUSED(name), int UNUSED(count), VALUE **vals) { - VALUE result; /* what we will return */ - ZVALUE q; /* test factor */ - ZVALUE temp; /* temp calculation value */ - int i; /* exponent value */ + VALUE result; /* what we will return */ + ZVALUE q; /* test factor */ + ZVALUE temp; /* temp calculation value */ + int i; /* exponent value */ - /* - * arg check - */ - result.v_type = V_NULL; - if (vals[0]->v_type != V_NUM) { - math_error("Non-numeric argument for pmodm127"); - not_reached(); - } - if (qisfrac(vals[0]->v_num)) { - math_error("Non-integer argument for pmodm127"); - not_reached(); - } - if (qisneg(vals[0]->v_num) || qiszero(vals[0]->v_num)) { - math_error("argument for pmodm127 <= 0"); - not_reached(); - } + /* + * arg check + */ + result.v_type = V_NULL; + if (vals[0]->v_type != V_NUM) { + math_error("Non-numeric argument for pmodm127"); + not_reached(); + } + if (qisfrac(vals[0]->v_num)) { + math_error("Non-integer argument for pmodm127"); + not_reached(); + } + if (qisneg(vals[0]->v_num) || qiszero(vals[0]->v_num)) { + math_error("argument for pmodm127 <= 0"); + not_reached(); + } - /* - * look at the numerator - */ - q = vals[0]->v_num->num; + /* + * look at the numerator + */ + q = vals[0]->v_num->num; - /* - * setup lastmod with q - */ - if (havelastmod && zcmp(q, *lastmod)) { - zfree(*lastmod); - zfree(*lastmodinv); - havelastmod = false; - } - if (!havelastmod) { - zcopy(q, lastmod); - zbitvalue(2 * q.len * BASEB, &temp); - zquo(temp, q, lastmodinv, 0); - zfree(temp); - havelastmod = true; - } + /* + * setup lastmod with q + */ + if (havelastmod && zcmp(q, *lastmod)) { + zfree(*lastmod); + zfree(*lastmodinv); + havelastmod = false; + } + if (!havelastmod) { + zcopy(q, lastmod); + zbitvalue(2 * q.len * BASEB, &temp); + zquo(temp, q, lastmodinv, 0); + zfree(temp); + havelastmod = true; + } - /* - * start with 2^255 - */ - result.v_num = qalloc(); - zcopy(p255, &result.v_num->num); - result.v_type = V_NUM; + /* + * start with 2^255 + */ + result.v_num = qalloc(); + zcopy(p255, &result.v_num->num); + result.v_type = V_NUM; - /* - * compute 2^(2^127-1) mod q by modular exponentiation - * - * We implement the following calc code in C: - * - * (* given q, our test factor, as the arg to this function *) - * result = 2^255; - * for (i=8; i < 127; ++i) { - * result %= q; (* mod *) - * result *= result; (* square *) - * result <<= 1; (* times 2 *) - * } - * result %= q; (* result is now 2^(2^127-1) % q *) - */ - for (i=8; i<127; ++i) { + /* + * compute 2^(2^127-1) mod q by modular exponentiation + * + * We implement the following calc code in C: + * + * (* given q, our test factor, as the arg to this function *) + * result = 2^255; + * for (i=8; i < 127; ++i) { + * result %= q; (* mod *) + * result *= result; (* square *) + * result <<= 1; (* times 2 *) + * } + * result %= q; (* result is now 2^(2^127-1) % q *) + */ + for (i=8; i<127; ++i) { #if 0 - /* use of zmod is a bit slower than zmod5_or_zmod */ - (void) zmod(result.v_num->num, *lastmod, &temp, 0); - zfree(result.v_num->num); - result.v_num->num = temp; + /* use of zmod is a bit slower than zmod5_or_zmod */ + (void) zmod(result.v_num->num, *lastmod, &temp, 0); + zfree(result.v_num->num); + result.v_num->num = temp; #else - zmod5_or_zmod(&result.v_num->num); /* mod */ + zmod5_or_zmod(&result.v_num->num); /* mod */ #endif #if 0 - /* use of zmul is slightly slower than zsquare */ - zmul(result.v_num->num, result.v_num->num, &temp); /* square */ + /* use of zmul is slightly slower than zsquare */ + zmul(result.v_num->num, result.v_num->num, &temp); /* square */ #else - zsquare(result.v_num->num, &temp); /* square */ + zsquare(result.v_num->num, &temp); /* square */ #endif - /* - * We could manually shift here, but this would o speed - * up the operation only a very tiny bit at the expense - * of a bunch of special code. - */ - zfree(result.v_num->num); - zshift(temp, 1, &result.v_num->num); /* times 2 */ - zfree(temp); - } - zmod5_or_zmod(&result.v_num->num); /* result = 2^(2^127-1) % q */ + /* + * We could manually shift here, but this would o speed + * up the operation only a very tiny bit at the expense + * of a bunch of special code. + */ + zfree(result.v_num->num); + zshift(temp, 1, &result.v_num->num); /* times 2 */ + zfree(temp); + } + zmod5_or_zmod(&result.v_num->num); /* result = 2^(2^127-1) % q */ - /* - * cleanup and return result - */ - return result; + /* + * cleanup and return result + */ + return result; } @@ -202,87 +202,87 @@ c_pmodm127(char *UNUSED(name), int UNUSED(count), VALUE **vals) S_FUNC void zmod5_or_zmod(ZVALUE *zp) { - LEN len, modlen, j; - ZVALUE tmp1, tmp2; - ZVALUE z1, z2, z3; - HALF *a, *b; - FULL f; - HALF u; + LEN len, modlen, j; + ZVALUE tmp1, tmp2; + ZVALUE z1, z2, z3; + HALF *a, *b; + FULL f; + HALF u; - int subcount = 0; + int subcount = 0; - if (zrel(*zp, *lastmod) < 0) - return; - modlen = lastmod->len; - len = zp->len; - z1.v = zp->v + modlen - 1; - z1.len = len - modlen + 1; - z1.sign = z2.sign = z3.sign = 0; - if (z1.len > modlen + 1) { - /* in ../zmod.c we did a math_error("Bad call to zmod5!!!"); */ - /* here we just call the slower zmod and return the result */ - (void) zmod(*zp, *lastmod, &tmp1, 0); - /* replace zp with tmp1 mod result */ - zfree(*zp); - *zp = tmp1; - return; - } - z2.v = lastmodinv->v + modlen + 1 - z1.len; - z2.len = lastmodinv->len - modlen - 1 + z1.len; - zmul(z1, z2, &tmp1); - z3.v = tmp1.v + z1.len; - z3.len = tmp1.len - z1.len; - if (z3.len > 0) { - zmul(z3, *lastmod, &tmp2); - j = modlen; - a = zp->v; - b = tmp2.v; - u = 0; - len = modlen; - while (j-- > 0) { - f = (FULL) *a - (FULL) *b++ - (FULL) u; - *a++ = (HALF) f; - u = - (HALF) (f >> BASEB); - } - if (z1.len > 1) { - len++; - if (tmp2.len > modlen) - f = (FULL) *a - (FULL) *b - (FULL) u; - else - f = (FULL) *a - (FULL) u; - *a++ = (HALF) f; - } - while (len > 0 && *--a == 0) - len--; - zp->len = len; - zfree(tmp2); - } - zfree(tmp1); - while (len > 0 && zrel(*zp, *lastmod) >= 0) { - subcount++; - if (subcount > 2) { - math_error("Too many subtractions in zmod5_or_zmod"); - not_reached(); - } - j = modlen; - a = zp->v; - b = lastmod->v; - u = 0; - while (j-- > 0) { - f = (FULL) *a - (FULL) *b++ - (FULL) u; - *a++ = (HALF) f; - u = - (HALF) (f >> BASEB); - } - if (len > modlen) { - f = (FULL) *a - (FULL) u; - *a++ = (HALF) f; - } - while (len > 0 && *--a == 0) - len--; - zp->len = len; - } - if (len == 0) - zp->len = 1; + if (zrel(*zp, *lastmod) < 0) + return; + modlen = lastmod->len; + len = zp->len; + z1.v = zp->v + modlen - 1; + z1.len = len - modlen + 1; + z1.sign = z2.sign = z3.sign = 0; + if (z1.len > modlen + 1) { + /* in ../zmod.c we did a math_error("Bad call to zmod5!!!"); */ + /* here we just call the slower zmod and return the result */ + (void) zmod(*zp, *lastmod, &tmp1, 0); + /* replace zp with tmp1 mod result */ + zfree(*zp); + *zp = tmp1; + return; + } + z2.v = lastmodinv->v + modlen + 1 - z1.len; + z2.len = lastmodinv->len - modlen - 1 + z1.len; + zmul(z1, z2, &tmp1); + z3.v = tmp1.v + z1.len; + z3.len = tmp1.len - z1.len; + if (z3.len > 0) { + zmul(z3, *lastmod, &tmp2); + j = modlen; + a = zp->v; + b = tmp2.v; + u = 0; + len = modlen; + while (j-- > 0) { + f = (FULL) *a - (FULL) *b++ - (FULL) u; + *a++ = (HALF) f; + u = - (HALF) (f >> BASEB); + } + if (z1.len > 1) { + len++; + if (tmp2.len > modlen) + f = (FULL) *a - (FULL) *b - (FULL) u; + else + f = (FULL) *a - (FULL) u; + *a++ = (HALF) f; + } + while (len > 0 && *--a == 0) + len--; + zp->len = len; + zfree(tmp2); + } + zfree(tmp1); + while (len > 0 && zrel(*zp, *lastmod) >= 0) { + subcount++; + if (subcount > 2) { + math_error("Too many subtractions in zmod5_or_zmod"); + not_reached(); + } + j = modlen; + a = zp->v; + b = lastmod->v; + u = 0; + while (j-- > 0) { + f = (FULL) *a - (FULL) *b++ - (FULL) u; + *a++ = (HALF) f; + u = - (HALF) (f >> BASEB); + } + if (len > modlen) { + f = (FULL) *a - (FULL) u; + *a++ = (HALF) f; + } + while (len > 0 && *--a == 0) + len--; + zp->len = len; + } + if (len == 0) + zp->len = 1; } #endif /* CUSTOM */ diff --git a/custom/c_pzasusb8.c b/custom/c_pzasusb8.c index bab280e..76d0fab 100644 --- a/custom/c_pzasusb8.c +++ b/custom/c_pzasusb8.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/10/06 03:12:25 - * File existed as early as: 1999 + * Under source code control: 1999/10/06 03:12:25 + * File existed as early as: 1999 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -29,9 +29,9 @@ * so we declare a global variable whose value is based on if CUSTOM is defined. */ #if defined(CUSTOM) -int c_pzasusb8_allowed = 1; /* CUSTOM defined */ +int c_pzasusb8_allowed = 1; /* CUSTOM defined */ #else /* CUSTOM */ -int c_pzasusb8_allowed = 0; /* CUSTOM undefined */ +int c_pzasusb8_allowed = 0; /* CUSTOM undefined */ #endif /* CUSTOM */ @@ -48,7 +48,7 @@ int c_pzasusb8_allowed = 0; /* CUSTOM undefined */ #include "../errtbl.h" -#include "../banned.h" /* include after system header <> includes */ +#include "../banned.h" /* include after system header <> includes */ /* @@ -56,7 +56,7 @@ int c_pzasusb8_allowed = 0; /* CUSTOM undefined */ * * given: * count = 1; - * vals[0] real number; + * vals[0] real number; * * returns: * null @@ -65,42 +65,42 @@ int c_pzasusb8_allowed = 0; /* CUSTOM undefined */ VALUE c_pzasusb8(char *UNUSED(name), int UNUSED(count), VALUE **vals) { - VALUE result; /* what we will return */ - ZVALUE z; /* numerator of the value */ - long half_cnt; /* number of HALFs in the numerator */ - USB8 *h; /* octet pointer */ - long half_len; /* length of a half in octets */ - long i; - long j; + VALUE result; /* what we will return */ + ZVALUE z; /* numerator of the value */ + long half_cnt; /* number of HALFs in the numerator */ + USB8 *h; /* octet pointer */ + long half_len; /* length of a half in octets */ + long i; + long j; - /* - * arg check - */ - result.v_type = V_NULL; - if (vals[0]->v_type != V_NUM) { - math_error("Non-real argument for pzasusb8"); - not_reached(); - } + /* + * arg check + */ + result.v_type = V_NULL; + if (vals[0]->v_type != V_NUM) { + math_error("Non-real argument for pzasusb8"); + not_reached(); + } - /* - * look at the numerator - */ - z = vals[0]->v_num->num; - half_len = sizeof(HALF); - half_cnt = z.len; + /* + * look at the numerator + */ + z = vals[0]->v_num->num; + half_len = sizeof(HALF); + half_cnt = z.len; - /* - * print the octets - */ - h = (USB8 *) z.v; - for (i=0; i < half_cnt; ++i) { - printf("%ld:\t", i); - for (j=0; j < half_len; ++j) { - printf("%02x", (int)(*h++)); - } - putchar('\n'); - } - return result; + /* + * print the octets + */ + h = (USB8 *) z.v; + for (i=0; i < half_cnt; ++i) { + printf("%ld:\t", i); + for (j=0; j < half_len; ++j) { + printf("%02x", (int)(*h++)); + } + putchar('\n'); + } + return result; } #endif /* CUSTOM */ diff --git a/custom/c_register.c b/custom/c_register.c index 3b13ddb..acfbcf3 100644 --- a/custom/c_register.c +++ b/custom/c_register.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2007/07/14 20:23:46 - * File existed as early as: 2007 + * Under source code control: 2007/07/14 20:23:46 + * File existed as early as: 2007 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -30,9 +30,9 @@ * so we declare a global variable whose value is based on if CUSTOM is defined. */ #if defined(CUSTOM) -int c_register_allowed = 1; /* CUSTOM defined */ +int c_register_allowed = 1; /* CUSTOM defined */ #else /* CUSTOM */ -int c_register_allowed = 0; /* CUSTOM undefined */ +int c_register_allowed = 0; /* CUSTOM undefined */ #endif /* CUSTOM */ @@ -51,7 +51,7 @@ int c_register_allowed = 0; /* CUSTOM undefined */ #include "../errtbl.h" -#include "../banned.h" /* include after system header <> includes */ +#include "../banned.h" /* include after system header <> includes */ /* @@ -66,17 +66,17 @@ STATIC VALUE custom_reg[CUSTOM_REG_MAX+1]; void init_custreg(void) { - int i; + int i; - /* - * set the registers to zero - */ - for (i=0; i < CUSTOM_REG_MAX+1; ++i) { - custom_reg[i].v_type = V_NUM; - custom_reg[i].v_subtype = V_NOSUBTYPE; - custom_reg[i].v_num = itoq(0); - } - return; + /* + * set the registers to zero + */ + for (i=0; i < CUSTOM_REG_MAX+1; ++i) { + custom_reg[i].v_type = V_NUM; + custom_reg[i].v_subtype = V_NOSUBTYPE; + custom_reg[i].v_num = itoq(0); + } + return; } @@ -84,58 +84,58 @@ init_custreg(void) * c_register - set or print a custom register value * * given: - * vals[i] and arg to display information about + * vals[i] and arg to display information about * * returns: - * count + * count */ /*ARGSUSED*/ VALUE c_register(char *UNUSED(name), int count, VALUE **vals) { - VALUE result; /* what we will return */ - long reg; /* register number */ + VALUE result; /* what we will return */ + long reg; /* register number */ - /* - * arg check - */ - result.v_type = V_NULL; - if (vals[0]->v_type != V_NUM) { - math_error("Non-numeric register number"); - not_reached(); - } - if (qisfrac(vals[0]->v_num)) { - math_error("Non-integer register number"); - not_reached(); - } - if (qisneg(vals[0]->v_num)) { - math_error("register number < 0"); - not_reached(); - } - if (! qistiny(vals[0]->v_num)) { - math_error("register is huge"); - not_reached(); - } - reg = qtoi(vals[0]->v_num); - if (reg > CUSTOM_REG_MAX) { - math_error("register is larger than CUSTOM_REG_MAX"); - not_reached(); - } + /* + * arg check + */ + result.v_type = V_NULL; + if (vals[0]->v_type != V_NUM) { + math_error("Non-numeric register number"); + not_reached(); + } + if (qisfrac(vals[0]->v_num)) { + math_error("Non-integer register number"); + not_reached(); + } + if (qisneg(vals[0]->v_num)) { + math_error("register number < 0"); + not_reached(); + } + if (! qistiny(vals[0]->v_num)) { + math_error("register is huge"); + not_reached(); + } + reg = qtoi(vals[0]->v_num); + if (reg > CUSTOM_REG_MAX) { + math_error("register is larger than CUSTOM_REG_MAX"); + not_reached(); + } - /* - * print info on each arg - */ - /* save previous value */ - copyvalue(&custom_reg[reg], &result); - /* set the new value if a 2nd arg was given */ - if (count == 2) { - copyvalue(vals[1], &custom_reg[reg]); - } + /* + * print info on each arg + */ + /* save previous value */ + copyvalue(&custom_reg[reg], &result); + /* set the new value if a 2nd arg was given */ + if (count == 2) { + copyvalue(vals[1], &custom_reg[reg]); + } - /* - * return result - */ - return result; + /* + * return result + */ + return result; } #endif /* CUSTOM */ diff --git a/custom/c_sysinfo.c b/custom/c_sysinfo.c index 5b52ce6..42f94e3 100644 --- a/custom/c_sysinfo.c +++ b/custom/c_sysinfo.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/03/09 23:14:40 - * File existed as early as: 1997 + * Under source code control: 1997/03/09 23:14:40 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -30,9 +30,9 @@ * so we declare a global variable whose value is based on if CUSTOM is defined. */ #if defined(CUSTOM) -int c_sysinfo_allowed = 1; /* CUSTOM defined */ +int c_sysinfo_allowed = 1; /* CUSTOM defined */ #else /* CUSTOM */ -int c_sysinfo_allowed = 0; /* CUSTOM undefined */ +int c_sysinfo_allowed = 0; /* CUSTOM undefined */ #endif /* CUSTOM */ @@ -68,17 +68,17 @@ int c_sysinfo_allowed = 0; /* CUSTOM undefined */ #include "../errtbl.h" -#include "../banned.h" /* include after system header <> includes */ +#include "../banned.h" /* include after system header <> includes */ /* * sys_info - names and values of selected #defines */ struct infoname { - char *name; /* name of #define converted to all UPPER_CASE */ - char *meaning; /* brief explanation of the #define */ - char *str; /* non-NULL ==> value of #define is a string */ - FULL nmbr; /* if str==NULL ==> value fo #define as a FULL */ + char *name; /* name of #define converted to all UPPER_CASE */ + char *meaning; /* brief explanation of the #define */ + char *str; /* non-NULL ==> value of #define is a string */ + FULL nmbr; /* if str==NULL ==> value fo #define as a FULL */ }; STATIC struct infoname sys_info[] = { {"S100", "slots in an subtractive 100 table", NULL, @@ -254,130 +254,130 @@ STATIC struct infoname sys_info[] = { /* * forward declarations */ -S_FUNC void dump_name_meaning(void); /* custom("sysinfo", 0) */ -S_FUNC void dump_name_value(void); /* custom("sysinfo", 1) */ -S_FUNC void dump_mening_value(void); /* custom("sysinfo", 2) */ +S_FUNC void dump_name_meaning(void); /* custom("sysinfo", 0) */ +S_FUNC void dump_name_value(void); /* custom("sysinfo", 1) */ +S_FUNC void dump_mening_value(void); /* custom("sysinfo", 2) */ /* * c_sysinfo - return a calc #define value * * given: - * vals[0] if given, name of #define to print - * otherwise a list of #defines are printed + * vals[0] if given, name of #define to print + * otherwise a list of #defines are printed * * returns: - * value of #define if given (int or string) - * null if no #define arg was given + * value of #define if given (int or string) + * null if no #define arg was given */ /*ARGSUSED*/ VALUE c_sysinfo(char *UNUSED(name), int count, VALUE **vals) { - VALUE result; /* what we will return */ - struct infoname *p; /* current infoname */ - char *buf; /* upper case value of vals[0] */ - char *q; /* to upper case converter */ - char *r; /* to upper case converter */ + VALUE result; /* what we will return */ + struct infoname *p; /* current infoname */ + char *buf; /* upper case value of vals[0] */ + char *q; /* to upper case converter */ + char *r; /* to upper case converter */ - /* - * we will return NULL if a value was not found - */ - result.v_type = V_NULL; - result.v_subtype = V_NOSUBTYPE; + /* + * we will return NULL if a value was not found + */ + result.v_type = V_NULL; + result.v_subtype = V_NOSUBTYPE; - /* - * case 0: if no args, then dump the table with no values - */ - if (count == 0) { + /* + * case 0: if no args, then dump the table with no values + */ + if (count == 0) { - /* dump the entire table */ - dump_name_meaning(); + /* dump the entire table */ + dump_name_meaning(); - /* - * case 1: numeric arg is given - */ - } else if (vals[0]->v_type == V_NUM) { + /* + * case 1: numeric arg is given + */ + } else if (vals[0]->v_type == V_NUM) { - /* firewall - must be a tiny non-negative integer */ - if (qisneg(vals[0]->v_num) || - qisfrac(vals[0]->v_num) || - zge31b(vals[0]->v_num->num)) { - math_error("sysinfo: arg must be string, 0, 1 or 2"); - not_reached(); - } + /* firewall - must be a tiny non-negative integer */ + if (qisneg(vals[0]->v_num) || + qisfrac(vals[0]->v_num) || + zge31b(vals[0]->v_num->num)) { + math_error("sysinfo: arg must be string, 0, 1 or 2"); + not_reached(); + } - /* - * select action based on numeric value of arg - */ - switch (z1tol(vals[0]->v_num->num)) { - case 0: /* print all infonames and meanings */ - dump_name_meaning(); - break; - case 1: /* print all infonames and values */ - dump_name_value(); - break; - case 2: /* print all values and meanings */ - dump_mening_value(); - break; - default: - math_error("sysinfo: arg must be string, 0, 1 or 2"); - not_reached(); - } + /* + * select action based on numeric value of arg + */ + switch (z1tol(vals[0]->v_num->num)) { + case 0: /* print all infonames and meanings */ + dump_name_meaning(); + break; + case 1: /* print all infonames and values */ + dump_name_value(); + break; + case 2: /* print all values and meanings */ + dump_mening_value(); + break; + default: + math_error("sysinfo: arg must be string, 0, 1 or 2"); + not_reached(); + } - /* - * case 2: string arg is given - * - * The string is taken to be the infoname we want to print. - */ - } else if (vals[0]->v_type == V_STR) { + /* + * case 2: string arg is given + * + * The string is taken to be the infoname we want to print. + */ + } else if (vals[0]->v_type == V_STR) { - /* convert vals[0] to upper case string */ - buf = (char *)malloc(strlen((char *)vals[0]->v_str->s_str)+1); - for (q = (char *)vals[0]->v_str->s_str, r = buf; *q; ++q, ++r) - { - if (isascii((int)*q) && islower((int)*q)) { - *r = *q - 'a' + 'A'; - } else { - *r = *q; - } - } - *r = '\0'; + /* convert vals[0] to upper case string */ + buf = (char *)malloc(strlen((char *)vals[0]->v_str->s_str)+1); + for (q = (char *)vals[0]->v_str->s_str, r = buf; *q; ++q, ++r) + { + if (isascii((int)*q) && islower((int)*q)) { + *r = *q - 'a' + 'A'; + } else { + *r = *q; + } + } + *r = '\0'; - /* search the table for the infoname */ - for (p = sys_info; p->name != NULL; ++p) { + /* search the table for the infoname */ + for (p = sys_info; p->name != NULL; ++p) { - if (strcmp(p->name, buf) == 0) { + if (strcmp(p->name, buf) == 0) { - /* found the infoname */ - if (p->str == NULL) { - /* return value as integer */ - result.v_type = V_NUM; - result.v_num = utoq( p->nmbr); - } else { - /* return value as string */ - result.v_type = V_STR; - result.v_subtype = V_NOSUBTYPE; - result.v_str = makestring(p->str); - } + /* found the infoname */ + if (p->str == NULL) { + /* return value as integer */ + result.v_type = V_NUM; + result.v_num = utoq( p->nmbr); + } else { + /* return value as string */ + result.v_type = V_STR; + result.v_subtype = V_NOSUBTYPE; + result.v_str = makestring(p->str); + } - /* return found infotype as value */ - break; - } - } + /* return found infotype as value */ + break; + } + } - /* - * bad arg given - */ - } else { - math_error("sysinfo: arg must be string, 0, 1 or 2"); - not_reached(); - } + /* + * bad arg given + */ + } else { + math_error("sysinfo: arg must be string, 0, 1 or 2"); + not_reached(); + } - /* - * return what we found or didn't find - */ - return result; + /* + * return what we found or didn't find + */ + return result; } @@ -387,13 +387,13 @@ c_sysinfo(char *UNUSED(name), int count, VALUE **vals) S_FUNC void dump_name_meaning(void) { - struct infoname *p; /* current infoname */ + struct infoname *p; /* current infoname */ - /* dump the entire table */ - for (p = sys_info; p->name != NULL; ++p) { - printf("%s%-23s\t%s\n", - (conf->tab_ok ? "\t" : ""), p->name, p->meaning); - } + /* dump the entire table */ + for (p = sys_info; p->name != NULL; ++p) { + printf("%s%-23s\t%s\n", + (conf->tab_ok ? "\t" : ""), p->name, p->meaning); + } } @@ -404,27 +404,27 @@ dump_name_meaning(void) S_FUNC void dump_name_value(void) { - struct infoname *p; /* current infoname */ + struct infoname *p; /* current infoname */ - /* dump the entire table */ - for (p = sys_info; p->name != NULL; ++p) { - if (p->str == NULL) { + /* dump the entire table */ + for (p = sys_info; p->name != NULL; ++p) { + if (p->str == NULL) { #if LONG_BITS == FULL_BITS || FULL_BITS == 32 - printf("%s%-23s\t%-8lu\t(0x%lx)\n", - (conf->tab_ok ? "\t" : ""), p->name, - (unsigned long)p->nmbr, - (unsigned long)p->nmbr); + printf("%s%-23s\t%-8lu\t(0x%lx)\n", + (conf->tab_ok ? "\t" : ""), p->name, + (unsigned long)p->nmbr, + (unsigned long)p->nmbr); #else - printf("%s%-23s\t%-8llu\t(0x%llx)\n", - (conf->tab_ok ? "\t" : ""), p->name, - (unsigned long long)p->nmbr, - (unsigned long long)p->nmbr); + printf("%s%-23s\t%-8llu\t(0x%llx)\n", + (conf->tab_ok ? "\t" : ""), p->name, + (unsigned long long)p->nmbr, + (unsigned long long)p->nmbr); #endif - } else { - printf("%s%-23s\t\"%s\"\n", - (conf->tab_ok ? "\t" : ""), p->name, p->str); - } - } + } else { + printf("%s%-23s\t\"%s\"\n", + (conf->tab_ok ? "\t" : ""), p->name, p->str); + } + } } @@ -435,27 +435,27 @@ dump_name_value(void) S_FUNC void dump_mening_value(void) { - struct infoname *p; /* current infoname */ + struct infoname *p; /* current infoname */ - /* dump the entire table */ - for (p = sys_info; p->name != NULL; ++p) { - if (p->str == NULL) { + /* dump the entire table */ + for (p = sys_info; p->name != NULL; ++p) { + if (p->str == NULL) { #if LONG_BITS == FULL_BITS || FULL_BITS == 32 - printf("%s%-36.36s\t%-8lu\t(0x%lx)\n", - (conf->tab_ok ? "\t" : ""), p->meaning, - (unsigned long)p->nmbr, - (unsigned long)p->nmbr); + printf("%s%-36.36s\t%-8lu\t(0x%lx)\n", + (conf->tab_ok ? "\t" : ""), p->meaning, + (unsigned long)p->nmbr, + (unsigned long)p->nmbr); #else - printf("%s%-36.36s\t%-8llu\t(0x%llx)\n", - (conf->tab_ok ? "\t" : ""), p->meaning, - (unsigned long long)p->nmbr, - (unsigned long long)p->nmbr); + printf("%s%-36.36s\t%-8llu\t(0x%llx)\n", + (conf->tab_ok ? "\t" : ""), p->meaning, + (unsigned long long)p->nmbr, + (unsigned long long)p->nmbr); #endif - } else { - printf("%s%-36.36s\t\"%s\"\n", - (conf->tab_ok ? "\t" : ""), p->meaning, p->str); - } - } + } else { + printf("%s%-36.36s\t\"%s\"\n", + (conf->tab_ok ? "\t" : ""), p->meaning, p->str); + } + } } diff --git a/custom/custtbl.c b/custom/custtbl.c index 6d0b018..5b2f89e 100644 --- a/custom/custtbl.c +++ b/custom/custtbl.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/03/09 02:28:54 - * File existed as early as: 1997 + * Under source code control: 1997/03/09 02:28:54 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -33,23 +33,23 @@ #include "../errtbl.h" -#include "../banned.h" /* include after system header <> includes */ +#include "../banned.h" /* include after system header <> includes */ /* * custom_compiled - determine if custom functions are compiled into libcustcalc * * returns: -s* true ==> libcustcalc was compiled with CUSTOM defined - * false ==> libcustcalc was compiled with CUSTOM undefined +s* true ==> libcustcalc was compiled with CUSTOM defined + * false ==> libcustcalc was compiled with CUSTOM undefined */ E_FUNC bool custom_compiled(void) { #if defined(CUSTOM) - return true; + return true; #else /* CUSTOM */ - return false; + return false; #endif /* CUSTOM */ } @@ -67,7 +67,7 @@ custom_compiled(void) * * Declare custom functions as follows: * - * E_FUNC VALUE c_xyz(char*, int, VALUE**); + * E_FUNC VALUE c_xyz(char*, int, VALUE**); * * We suggest that you sort the entries below by name. */ @@ -88,13 +88,13 @@ E_FUNC VALUE c_register(char*, int, VALUE**); * * The order of the elements in struct custom are: * - * { "xyz", "brief description of the xyz custom function", - * minimum_args, maximum_args, c_xyz }, + * { "xyz", "brief description of the xyz custom function", + * minimum_args, maximum_args, c_xyz }, * * where: * - * minimum_args an int >= 0 - * maximum_args an int >= minimum_args and <= MAX_CUSTOM_ARGS + * minimum_args an int >= 0 + * maximum_args an int >= minimum_args and <= MAX_CUSTOM_ARGS * * Use MAX_CUSTOM_ARGS for maximum_args is the maximum number of args * is potentially 'unlimited'. @@ -108,40 +108,40 @@ CONST struct custom cust[] = { #if defined(CUSTOM) - /* - * add your own custom functions here - * - * We suggest that you sort the entries below by name - * so that show custom will produce a nice sorted list. - */ + /* + * add your own custom functions here + * + * We suggest that you sort the entries below by name + * so that show custom will produce a nice sorted list. + */ - { "argv", "information about its args, returns arg count", - 0, MAX_CUSTOM_ARGS, c_argv }, + { "argv", "information about its args, returns arg count", + 0, MAX_CUSTOM_ARGS, c_argv }, - { "devnull", "does nothing", - 0, MAX_CUSTOM_ARGS, c_devnull }, + { "devnull", "does nothing", + 0, MAX_CUSTOM_ARGS, c_devnull }, - { "help", "help for custom functions", - 1, 1, c_help }, + { "help", "help for custom functions", + 1, 1, c_help }, - { "sysinfo", "return a calc #define value", - 0, 1, c_sysinfo }, + { "sysinfo", "return a calc #define value", + 0, 1, c_sysinfo }, - { "pzasusb8", "print ZVALUE as USB8", - 0, 1, c_pzasusb8 }, + { "pzasusb8", "print ZVALUE as USB8", + 0, 1, c_pzasusb8 }, - { "pmodm127", "calculate q mod 2^(2^127-1)", - 1, 1, c_pmodm127 }, + { "pmodm127", "calculate q mod 2^(2^127-1)", + 1, 1, c_pmodm127 }, - { "register", "get or set customer registers", - 1, 2, c_register }, + { "register", "get or set customer registers", + 1, 2, c_register }, #endif /* CUSTOM */ - /* - * This must be at the end of this table!!! - */ - {NULL, NULL, - 0, 0, NULL} + /* + * This must be at the end of this table!!! + */ + {NULL, NULL, + 0, 0, NULL} }; diff --git a/custom/devnull b/custom/devnull index 9522424..184d32b 100644 --- a/custom/devnull +++ b/custom/devnull @@ -5,12 +5,12 @@ SYNOPSIS custom("devnull" [, arg ...]) TYPES - arg any + arg any - return null + return null DESCRIPTION - This custom function does nothing. It is intended for testing + This custom function does nothing. It is intended for testing of the general custom interface. EXAMPLE @@ -34,7 +34,7 @@ SEE ALSO ## ## 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 +## 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 @@ -42,8 +42,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/03/09 17:49:12 -## File existed as early as: 1997 +## Under source code control: 1997/03/09 17:49:12 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/custom/halflen.cal b/custom/halflen.cal index 9642be2..538242a 100644 --- a/custom/halflen.cal +++ b/custom/halflen.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,55 +17,55 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/03/08 20:51:32 - * File existed as early as: 1997 + * Under source code control: 1997/03/08 20:51:32 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * This file is part of the custom sample calc files. * * NOTE: You must use a calc that was compiled with ALLOW_CUSTOM= -DCUSTOM - * and run with a -C arg. + * and run with a -C arg. */ if (config("compile_custom") == 0) { - quit "calc compiled without -DCUSTOM"; + quit "calc compiled without -DCUSTOM"; } else if (config("allow_custom") == 0) { - quit "calc was run without the -D command line option"; + quit "calc was run without the -D command line option"; } define halflen(num) { - local baseb; /* bit len of a HALF */ + local baseb; /* bit len of a HALF */ - /* - * firewall - */ - if (!isnum(num)) { - return newerror("halflen only works on numeric values"); - } + /* + * firewall + */ + if (!isnum(num)) { + return newerror("halflen only works on numeric values"); + } - /* - * determine baseb - */ - baseb = custom("sysinfo","BASEB"); + /* + * determine baseb + */ + baseb = custom("sysinfo","BASEB"); - /* - * determine the HALF length of a numeric value - */ - if (num == 0) { - /* consider 0 to be 1 HALF long */ - return 1; - } else if (isint(num)) { - return (highbit(num)+baseb-1)/baseb; - } else if (isreal(num)) { - return halflen(num(num)) + halflen(den(num)); - } else if (isnum(num)) { - return halflen(re(num)) + halflen(im(num)); - } else { - return newerror("halflen only works on numeric values"); - } + /* + * determine the HALF length of a numeric value + */ + if (num == 0) { + /* consider 0 to be 1 HALF long */ + return 1; + } else if (isint(num)) { + return (highbit(num)+baseb-1)/baseb; + } else if (isreal(num)) { + return halflen(num(num)) + halflen(den(num)); + } else if (isnum(num)) { + return halflen(re(num)) + halflen(im(num)); + } else { + return newerror("halflen only works on numeric values"); + } } diff --git a/custom/help b/custom/help index ae14330..391759b 100644 --- a/custom/help +++ b/custom/help @@ -5,9 +5,9 @@ SYNOPSIS custom("help", name) TYPES - name string + name string - return null + return null DESCRIPTION This custom function will display the help for the builtin function @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/03/09 06:03:58 -## File existed as early as: 1997 +## Under source code control: 1997/03/09 06:03:58 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/custom/pmodm127 b/custom/pmodm127 index 0017118..3ec151d 100644 --- a/custom/pmodm127 +++ b/custom/pmodm127 @@ -5,40 +5,40 @@ SYNOPSIS custom("pmodm127", q) TYPES - q int > 0 + q int > 0 - return int + return int DESCRIPTION This custom function will return the value: - q mod 2^(2^127-1) + q mod 2^(2^127-1) This custom function serves as a demonstration of how to write a custom function. It performs the equivalent of: - pmod(2, 2^127-1, q) + pmod(2, 2^127-1, q) The return value is integer in the half open range: [0, q). SPECIAL NOTE: - Can you find a value, q, for which this custom function returns 1? - If you do, send the value of q to chongo using the Email address - found at: + Can you find a value, q, for which this custom function returns 1? + If you do, send the value of q to chongo using the Email address + found at: - http://www.isthe.com/chongo/address.html + http://www.isthe.com/chongo/address.html EXAMPLE > custom("pmodm127", 65537) - 32769 + 32769 > custom("pmodm127", 2^31-1) - 8 + 8 > custom("pmodm127", 7^51+2) - 11228202966269457258557496419097462731193173 + 11228202966269457258557496419097462731193173 LIMITS calc must be built with ALLOW_CUSTOM= -DCUSTOM @@ -59,7 +59,7 @@ SEE ALSO ## ## 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 +## 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 @@ -67,8 +67,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2004/02/25 07:13:15 -## File existed as early as: 2004 +## Under source code control: 2004/02/25 07:13:15 +## File existed as early as: 2004 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/custom/pmodm127.cal b/custom/pmodm127.cal index b7c9d19..b855de2 100644 --- a/custom/pmodm127.cal +++ b/custom/pmodm127.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,116 +17,116 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2004/02/25 14:25:32 - * File existed as early as: 2004 + * Under source code control: 2004/02/25 14:25:32 + * File existed as early as: 2004 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * This file is part of the custom sample calc files. * * NOTE: You must use a calc that was compiled with ALLOW_CUSTOM= -DCUSTOM - * and run with a -C arg. + * and run with a -C arg. */ if (config("compile_custom") == 0) { - quit "calc compiled without -DCUSTOM"; + quit "calc compiled without -DCUSTOM"; } else if (config("allow_custom") == 0) { - quit "calc was run without the -D command line option"; + quit "calc was run without the -D command line option"; } define pmodm127_test1(testcnt) { - local q; /* test factor */ - local m127; /* 2^127-1 */ - local i; + local q; /* test factor */ + local m127; /* 2^127-1 */ + local i; - /* - * firewall - */ - if (!isint(testcnt) || testcnt <= 0) { - return newerror("pmodm127_test1 must have an integer count>0"); - } + /* + * firewall + */ + if (!isint(testcnt) || testcnt <= 0) { + return newerror("pmodm127_test1 must have an integer count>0"); + } - /* - * perform testcnt divisor tests for primes of form 2*k*(2^127-1)+1 - * - * NOTE: Since this is just a test, we do not need to be optimal. - */ - m127 = 2^127 - 1; - q = 2*4949132165849*m127+1; - for (i=0; i < testcnt; ++i) { + /* + * perform testcnt divisor tests for primes of form 2*k*(2^127-1)+1 + * + * NOTE: Since this is just a test, we do not need to be optimal. + */ + m127 = 2^127 - 1; + q = 2*4949132165849*m127+1; + for (i=0; i < testcnt; ++i) { - /* - * determine next prime divisor - */ - q = nextcand(q, -1, 0, 1, 2*m127); + /* + * determine next prime divisor + */ + q = nextcand(q, -1, 0, 1, 2*m127); - /* compare custom function with its pmod() equivalent */ - if (config("resource_debug") & 8) { - print "testing", q; - } - if (pmod(2, m127, q) != custom("pmodm127", q)) { - print "ERROR: pmodm127 failed for ", str(q); - return newerror("pmodm127 failed for " + str(q)); - } - } + /* compare custom function with its pmod() equivalent */ + if (config("resource_debug") & 8) { + print "testing", q; + } + if (pmod(2, m127, q) != custom("pmodm127", q)) { + print "ERROR: pmodm127 failed for ", str(q); + return newerror("pmodm127 failed for " + str(q)); + } + } - /* return success count */ - if (config("resource_debug") & 8) { - print "passed", testcnt, "tests"; - } - return testcnt; + /* return success count */ + if (config("resource_debug") & 8) { + print "passed", testcnt, "tests"; + } + return testcnt; } define pmodm127_test2(testcnt, seed) { - local q; /* test factor */ - local m127; /* 2^127-1 */ - local i; + local q; /* test factor */ + local m127; /* 2^127-1 */ + local i; - /* - * firewall - */ - if (!isint(testcnt) || testcnt <= 0) { - return newerror("pmodm127_test2 must have an integer count>0"); - } - if (!isint(seed)) { - return newerror("pmodm127_test2 must an integer seed"); - } + /* + * firewall + */ + if (!isint(testcnt) || testcnt <= 0) { + return newerror("pmodm127_test2 must have an integer count>0"); + } + if (!isint(seed)) { + return newerror("pmodm127_test2 must an integer seed"); + } - /* - * perform testcnt divisor tests random integers over [1e51, 1e52) - * - * NOTE: Since this is just a test, we do not need to be optimal. - */ - m127 = 2^127 - 1; - for (i=0; i < testcnt; ++i) { + /* + * perform testcnt divisor tests random integers over [1e51, 1e52) + * + * NOTE: Since this is just a test, we do not need to be optimal. + */ + m127 = 2^127 - 1; + for (i=0; i < testcnt; ++i) { - /* - * determine next prime divisor - */ - q = rand(1e51, 1e52) | 0x1; - if (config("resource_debug") & 8) { - print "testing", q; - } + /* + * determine next prime divisor + */ + q = rand(1e51, 1e52) | 0x1; + if (config("resource_debug") & 8) { + print "testing", q; + } - /* compare custom function with its pmod() equivalent */ - if (pmod(2, m127, q) != custom("pmodm127", q)) { - print "ERROR: pmodm127 failed for ", str(q); - print "ERROR: ", pmod(2,m127,q), " != ", - custom("pmodm127", q); - return newerror("pmodm127 failed for " + str(q)); - } - } + /* compare custom function with its pmod() equivalent */ + if (pmod(2, m127, q) != custom("pmodm127", q)) { + print "ERROR: pmodm127 failed for ", str(q); + print "ERROR: ", pmod(2,m127,q), " != ", + custom("pmodm127", q); + return newerror("pmodm127 failed for " + str(q)); + } + } - /* return success count */ - if (config("resource_debug") & 8) { - print "passed", testcnt, "tests"; - } - return testcnt; + /* return success count */ + if (config("resource_debug") & 8) { + print "passed", testcnt, "tests"; + } + return testcnt; } if ((config("resource_debug") & 3) && !(config("resource_debug") & 8)) { diff --git a/custom/pzasusb8 b/custom/pzasusb8 index 3f50733..61511eb 100644 --- a/custom/pzasusb8 +++ b/custom/pzasusb8 @@ -5,19 +5,19 @@ SYNOPSIS custom("pzasusb8", arg) TYPES - arg real + arg real - return null + return null DESCRIPTION This custom function prints out the numerator of a real value - in octets. Each HALF value is printed in a separate line. + in octets. Each HALF value is printed in a separate line. NOTE: The output will vary depending on the size of a HALF - and the byte order of the system. See: + and the byte order of the system. See: - custom("sysinfo", "BASEB") - custom("sysinfo", "CALC_BYTE_ORDER") + custom("sysinfo", "BASEB") + custom("sysinfo", "CALC_BYTE_ORDER") for details. @@ -26,15 +26,15 @@ DESCRIPTION EXAMPLE > custom("pzasusb8", 0x01020304050607080910111213141516); - 0: 13141516 - 1: 09101112 - 2: 05060708 - 3: 01020304 + 0: 13141516 + 1: 09101112 + 2: 05060708 + 3: 01020304 > custom("pzasusb8", 10^25) - 0: 4a000000 - 1: 16140148 - 2: 00084595 + 0: 4a000000 + 1: 16140148 + 2: 00084595 > printf("%x\n", 10^25); 0x84595161401484a000000 @@ -57,7 +57,7 @@ SEE ALSO ## ## 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 +## 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 @@ -65,8 +65,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1999/10/06 04:05:43 -## File existed as early as: 1999 +## Under source code control: 1999/10/06 04:05:43 +## File existed as early as: 1999 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/custom/pzasusb8.cal b/custom/pzasusb8.cal index 6b4f88e..beaf50b 100644 --- a/custom/pzasusb8.cal +++ b/custom/pzasusb8.cal @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,11 +19,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/10/06 03:11:12 - * File existed as early as: 1998 + * Under source code control: 1999/10/06 03:11:12 + * File existed as early as: 1998 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -31,9 +31,9 @@ * firewall */ if (config("compile_custom") == 0) { - quit "calc compiled without -DCUSTOM"; + quit "calc compiled without -DCUSTOM"; } else if (config("allow_custom") == 0) { - quit "calc was run without the -D command line option"; + quit "calc was run without the -D command line option"; } print "p(n) prints array in which numerator of n is stored as a"; diff --git a/custom/register b/custom/register index 75002c4..edeb658 100644 --- a/custom/register +++ b/custom/register @@ -5,10 +5,10 @@ SYNOPSIS custom("register", regnum[, value]) TYPES - regnum int - value any, &any + regnum int + value any, &any - return any + return any DESCRIPTION This custom function reads or sets a value of a custom register. @@ -22,7 +22,7 @@ DESCRIPTION There will be at least 32 registers although there could be more added in the future. It may be determined by: - custom("sysinfo", "REGNUM_MAX") + custom("sysinfo", "REGNUM_MAX") The custom registers are initialized to 0 by the internal function libcalc_call_me_first() during calc startup. @@ -32,16 +32,16 @@ DESCRIPTION EXAMPLE > custom("register", 3) - 0 + 0 > custom("register", 3, 45) - 0 + 0 > custom("register", 3) - 45 + 45 > custom("register", 7, 2i), > custom("register", 8, 3i), > custom("register", 7) * custom("register", 8) - -6 + -6 LIMITS calc must be built with ALLOW_CUSTOM= -DCUSTOM @@ -63,7 +63,7 @@ SEE ALSO ## ## 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 +## 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 @@ -71,8 +71,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## -## Under source code control: 2005/02/04 22:39:50 -## File existed as early as: 2005 +## Under source code control: 2005/02/04 22:39:50 +## File existed as early as: 2005 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/custom/register.cal b/custom/register.cal index 8d067f7..7834c2d 100644 --- a/custom/register.cal +++ b/custom/register.cal @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,50 +17,50 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2007/07/05 11:11:11 - * File existed as early as: 2007 + * Under source code control: 2007/07/05 11:11:11 + * File existed as early as: 2007 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * This file is part of the custom sample calc files. * * NOTE: You must use a calc that was compiled with ALLOW_CUSTOM= -DCUSTOM - * and run with a -C arg. + * and run with a -C arg. */ if (config("compile_custom") == 0) { - quit "calc compiled without -DCUSTOM"; + quit "calc compiled without -DCUSTOM"; } else if (config("allow_custom") == 0) { - quit "calc was run without the -D command line option"; + quit "calc was run without the -D command line option"; } define register(num) { - local reg_max; /* number of registers */ + local reg_max; /* number of registers */ - /* - * firewall - */ - if (!isnum(num)) { - return newerror("register only works on numeric values"); - } + /* + * firewall + */ + if (!isnum(num)) { + return newerror("register only works on numeric values"); + } - /* - * determine register count - */ - reg_max = custom("sysinfo", "REGNUM_MAX"); + /* + * determine register count + */ + reg_max = custom("sysinfo", "REGNUM_MAX"); - /* - * determine the HALF length of a numeric value - */ - if (num < 0) { - return newerror("register number must be >= 0"); - } else if (num > reg_max) { - return newerror("register number must be < REGNUM_MAX"); - } else { - return custom("register", num); - } + /* + * determine the HALF length of a numeric value + */ + if (num < 0) { + return newerror("register number must be >= 0"); + } else if (num > reg_max) { + return newerror("register number must be < REGNUM_MAX"); + } else { + return custom("register", num); + } } diff --git a/custom/sysinfo b/custom/sysinfo index b35a8a6..d4ba133 100644 --- a/custom/sysinfo +++ b/custom/sysinfo @@ -5,9 +5,9 @@ SYNOPSIS custom("sysinfo" [, infoname]); TYPES - infoname string or int + infoname string or int - return int, string or null + return int, string or null DESCRIPTION @@ -24,13 +24,13 @@ DESCRIPTION If infoname is a number, then it is interpreted as follows: - 0 print all infonames and meanings (same as no infoname) - 1 print all infonames and values - 2 print all infoname meanings and values + 0 print all infonames and meanings (same as no infoname) + 1 print all infonames and values + 2 print all infoname meanings and values EXAMPLE > custom("sysinfo", "baseb") - 32 + 32 > custom("sysinfo") ... a list of infonames and meanings are printed ... @@ -61,7 +61,7 @@ SEE ALSO ## ## 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 +## 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 @@ -69,8 +69,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/03/09 23:14:40 -## File existed as early as: 1997 +## Under source code control: 1997/03/09 23:14:40 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/decl.h b/decl.h index 930101a..569af3b 100644 --- a/decl.h +++ b/decl.h @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2007/02/09 05:24:25 - * File existed as early as: 2007 + * Under source code control: 2007/02/09 05:24:25 + * File existed as early as: 2007 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -37,7 +37,7 @@ * Thread Local Storage macros * * NOTE: The use of -DWITH_TLS is extremely experimental. Calc may not - * compile with WITH_TLS defined. + * compile with WITH_TLS defined. */ #if defined(WITH_TLS) diff --git a/endian.c b/endian.c index 135fbe8..36ba136 100644 --- a/endian.c +++ b/endian.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,15 +17,15 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1993/11/15 04:32:58 - * File existed as early as: 1993 + * Under source code control: 1993/11/15 04:32:58 + * File existed as early as: 1993 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* - * Big Endian: Amdahl, 68k, Pyramid, MIPS, Sparc, ... + * Big Endian: Amdahl, 68k, Pyramid, MIPS, Sparc, ... * Little Endian: Vax, 32k, Spim (Dec Mips), i386, i486, ... */ @@ -43,63 +43,63 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* byte order array */ char byte[8] = { (char)0x12, (char)0x36, (char)0x48, (char)0x59, - (char)0x01, (char)0x23, (char)0x45, (char)0x67 }; + (char)0x01, (char)0x23, (char)0x45, (char)0x67 }; int main(void) { - /* pointers into the byte order array */ + /* pointers into the byte order array */ #if defined(DEBUG) || (!defined(BIG_ENDIAN) && !defined(BIG_ENDIAN)) - int *intp = (int *)byte; + int *intp = (int *)byte; #endif #if defined(DEBUG) - short *shortp = (short *)byte; - long *longp = (long *)byte; + short *shortp = (short *)byte; + long *longp = (long *)byte; - printf("byte: %02x %02x %02x %02x %02x %02x %02x %02x\n", - byte[0], byte[1], byte[2], byte[3], - byte[4], byte[5], byte[6], byte[7]); - printf("short: %04x %04x %04x %04x\n", - shortp[0], shortp[1], shortp[2], shortp[3]); - printf("int: %08x %08x\n", - intp[0], intp[1]); - printf("long: %08x %08x\n", - longp[0], longp[1]); + printf("byte: %02x %02x %02x %02x %02x %02x %02x %02x\n", + byte[0], byte[1], byte[2], byte[3], + byte[4], byte[5], byte[6], byte[7]); + printf("short: %04x %04x %04x %04x\n", + shortp[0], shortp[1], shortp[2], shortp[3]); + printf("int: %08x %08x\n", + intp[0], intp[1]); + printf("long: %08x %08x\n", + longp[0], longp[1]); #endif - /* Print the standard defines */ - printf("#undef BIG_ENDIAN\n"); - printf("#define BIG_ENDIAN\t4321\n"); - printf("#undef LITTLE_ENDIAN\n"); - printf("#define LITTLE_ENDIAN\t1234\n"); - printf("#undef CALC_BYTE_ORDER\n"); + /* Print the standard defines */ + printf("#undef BIG_ENDIAN\n"); + printf("#define BIG_ENDIAN\t4321\n"); + printf("#undef LITTLE_ENDIAN\n"); + printf("#define LITTLE_ENDIAN\t1234\n"); + printf("#undef CALC_BYTE_ORDER\n"); #if defined(BIG_ENDIAN) - printf("#define CALC_BYTE_ORDER\tBIG_ENDIAN\n"); + printf("#define CALC_BYTE_ORDER\tBIG_ENDIAN\n"); #elif defined(LITTLE_ENDIAN) - printf("#define CALC_BYTE_ORDER\tLITTLW_ENDIAN\n"); + printf("#define CALC_BYTE_ORDER\tLITTLW_ENDIAN\n"); #else - /* Determine byte order */ - if (intp[0] == 0x12364859) { - /* Most Significant Byte first */ - printf("#define CALC_BYTE_ORDER\tBIG_ENDIAN\n"); - } else if (intp[0] == 0x59483612) { - /* Least Significant Byte first */ - printf("#define CALC_BYTE_ORDER\tLITTLE_ENDIAN\n"); - } else { - fprintf(stderr, "@=-=@ Fatal build error - cannot @=-=@\n"); - fprintf(stderr, "@=-=@ determine byte order. Set @=-=@\n"); - fprintf(stderr, "@=-=@ ${CALC_BYTE_ORDER} in the Makefile @=-=@\n"); - fprintf(stderr, "@=-=@ to be either -DBIG_ENDIAN or @=-=@\n"); - fprintf(stderr, "@=-=@ to be -DLITTLE_ENDIAN @=-=@\n"); - exit(1); - } + /* Determine byte order */ + if (intp[0] == 0x12364859) { + /* Most Significant Byte first */ + printf("#define CALC_BYTE_ORDER\tBIG_ENDIAN\n"); + } else if (intp[0] == 0x59483612) { + /* Least Significant Byte first */ + printf("#define CALC_BYTE_ORDER\tLITTLE_ENDIAN\n"); + } else { + fprintf(stderr, "@=-=@ Fatal build error - cannot @=-=@\n"); + fprintf(stderr, "@=-=@ determine byte order. Set @=-=@\n"); + fprintf(stderr, "@=-=@ ${CALC_BYTE_ORDER} in the Makefile @=-=@\n"); + fprintf(stderr, "@=-=@ to be either -DBIG_ENDIAN or @=-=@\n"); + fprintf(stderr, "@=-=@ to be -DLITTLE_ENDIAN @=-=@\n"); + exit(1); + } #endif - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/errtbl.c b/errtbl.c index 3df861f..4f44e36 100644 --- a/errtbl.c +++ b/errtbl.c @@ -12,7 +12,7 @@ * * 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 + * 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 @@ -20,18 +20,18 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1996/05/23 17:38:44 - * File existed as early as: 1996 + * Under source code control: 1996/05/23 17:38:44 + * File existed as early as: 1996 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ * * HISTORIC NOTE: * * This file was once called calcerr.tbl. It once was a simple table of: * - * SYMBOL meaning + * SYMBOL meaning * - * until 2023 when the new calc computation error code system was introduced. + * until 2023 when the new calc computation error code system was introduced. */ @@ -80,18 +80,18 @@ * * The INV_ERRNUM must be < 0, AND != NULL_ERRNUM */ -#define INV_ERRNUM (-2) /* errnum is waiting to be replaced by E__HIGHEST */ +#define INV_ERRNUM (-2) /* errnum is waiting to be replaced by E__HIGHEST */ /************************************************************************/ -/* */ -/* WARNING: The order of ierror_table[] arrays critical! If you */ -/* change the order, you will break code that depends on the */ -/* return value of the errno() builtin function. */ -/* */ -/* When adding entries to this table add then just before */ -/* the NULL pointer (* must be last *) entry. */ -/* */ +/* */ +/* WARNING: The order of ierror_table[] arrays critical! If you */ +/* change the order, you will break code that depends on the */ +/* return value of the errno() builtin function. */ +/* */ +/* When adding entries to this table add then just before */ +/* the NULL pointer (* must be last *) entry. */ +/* */ /************************************************************************/ /* @@ -109,14 +109,14 @@ * With exception to the 1st E__BASE entry, all other errsym strings * must match the following regular expression: * - * ^E_[A-Z][A-Z0-9_]+$ + * ^E_[A-Z][A-Z0-9_]+$ * * NOTE: The above regular expression is more restrictive them the - * E_STRING regular expression from help/errno, help/error, - * and help/strerror. This is because errsym strings that - * start with "E__" are special symbols that #define-d in errtbl.h, - * AND because errsym strings that are "^E_[0-9]+$" reserved for - * numeric aliases for errnum. + * E_STRING regular expression from help/errno, help/error, + * and help/strerror. This is because errsym strings that + * start with "E__" are special symbols that #define-d in errtbl.h, + * AND because errsym strings that are "^E_[0-9]+$" reserved for + * numeric aliases for errnum. * * If multiple computation error codes are needed for a similar purpose, * use E_STRING errsym codes followed by _digit(s). @@ -148,621 +148,621 @@ CONST struct errtbl error_table[] = { - /* The E__BASE entry below must start with 10000 and must be first!! */ - { 10000, "E__BASE", "No error" }, - { 10001, "E_DIVBYZERO", "Division by zero" }, - { 10002, "E_ZERODIVZERO", "Indeterminate (0/0)" }, - { 10003, "E_ADD", "Bad arguments for +" }, - { 10004, "E_SUB", "Bad arguments for binary -" }, - { 10005, "E_MUL", "Bad arguments for *" }, - { 10006, "E_DIV", "Bad arguments for /" }, - { 10007, "E_NEG", "Bad argument for unary -" }, - { 10008, "E_SQUARE", "Bad argument for squaring" }, - { 10009, "E_INV", "Bad argument for inverse" }, - { 10010, "E_INCV", "Bad argument for ++" }, - { 10011, "E_DECV", "Bad argument for --" }, - { 10012, "E_INT", "Bad argument for int" }, - { 10013, "E_FRAC", "Bad argument for frac" }, - { 10014, "E_CONJ", "Bad argument for conj" }, - { 10015, "E_APPR_1", "Bad first argument for appr" }, - { 10016, "E_APPR_2", "Bad second argument for appr" }, - { 10017, "E_APPR_3", "Bad third argument for appr" }, - { 10018, "E_ROUND_1", "Bad first argument for round" }, - { 10019, "E_ROUND_2", "Bad second argument for round" }, - { 10020, "E_ROUND_3", "Bad third argument for round" }, - { 10021, "E_BROUND_1", "Bad first argument for bround" }, - { 10022, "E_BROUND_2", "Bad second argument for bround" }, - { 10023, "E_BROUND_3", "Bad third argument for bround" }, - { 10024, "E_SQRT_1", "Bad first argument for sqrt" }, - { 10025, "E_SQRT_2", "Bad second argument for sqrt" }, - { 10026, "E_SQRT_3", "Bad third argument for sqrt" }, - { 10027, "E_ROOT_1", "Bad first argument for root" }, - { 10028, "E_ROOT_2", "Bad second argument for root" }, - { 10029, "E_ROOT_3", "Bad third argument for root" }, - { 10030, "E_NORM", "Bad argument for norm" }, - { 10031, "E_SHIFT_1", "Bad first argument for << or >>" }, - { 10032, "E_SHIFT_2", "Bad second argument for << or >>" }, - { 10033, "E_SCALE_1", "Bad first argument for scale" }, - { 10034, "E_SCALE_2", "Bad second argument for scale" }, - { 10035, "E_POWI_1", "Bad first argument for ^" }, - { 10036, "E_POWI_2", "Bad second argument for ^" }, - { 10037, "E_POWER_1", "Bad first argument for power" }, - { 10038, "E_POWER_2", "Bad second argument for power" }, - { 10039, "E_POWER_3", "Bad third argument for power" }, - { 10040, "E_QUO_1", "Bad first argument for quo or //" }, - { 10041, "E_QUO_2", "Bad second argument for quo or //" }, - { 10042, "E_QUO_3", "Bad third argument for quo" }, - { 10043, "E_MOD_1", "Bad first argument for mod or %" }, - { 10044, "E_MOD_2", "Bad second argument for mod or %" }, - { 10045, "E_MOD_3", "Bad third argument for mod" }, - { 10046, "E_SGN", "Bad argument for sgn" }, - { 10047, "E_ABS_1", "Bad first argument for abs" }, - { 10048, "E_ABS_2", "Bad second argument for abs" }, - { 10049, "E_EVAL", "Scan error in argument for eval" }, - { 10050, "E_STR", "Non-simple type for str" }, - { 10051, "E_EXP_1", "Non-real epsilon for exp" }, - { 10052, "E_EXP_2", "Bad first argument for exp" }, - { 10053, "E_FPUTC_1", "Non-file first argument for fputc" }, - { 10054, "E_FPUTC_2", "Bad second argument for fputc" }, - { 10055, "E_FPUTC_3", "File not open for writing for fputc" }, - { 10056, "E_FGETC_1", "Non-file first argument for fgetc" }, - { 10057, "E_FGETC_2", "File not open for reading for fgetc" }, - { 10058, "E_FOPEN_1", "Non-string arguments for fopen" }, - { 10059, "E_FOPEN_2", "Unrecognized mode for fopen" }, - { 10060, "E_FREOPEN_1", "Non-file first argument for freopen" }, - { 10061, "E_FREOPEN_2", "Non-string or unrecognized mode for freopen" }, - { 10062, "E_FREOPEN_3", "Non-string third argument for freopen" }, - { 10063, "E_FCLOSE_1", "Non-file argument for fclose" }, - { 10064, "E_FFLUSH", "Non-file argument for fflush" }, - { 10065, "E_FPUTS_1", "Non-file first argument for fputs" }, - { 10066, "E_FPUTS_2", "Non-string argument after first for fputs" }, - { 10067, "E_FPUTS_3", "File not open for writing for fputs" }, - { 10068, "E_FGETS_1", "Non-file argument for fgets" }, - { 10069, "E_FGETS_2", "File not open for reading for fgets" }, - { 10070, "E_FPUTSTR_1", "Non-file first argument for fputstr" }, - { 10071, "E_FPUTSTR_2", "Non-string argument after first for fputstr" }, - { 10072, "E_FPUTSTR_3", "File not open for writing for fputstr" }, - { 10073, "E_FGETSTR_1", "Non-file first argument for fgetstr" }, - { 10074, "E_FGETSTR_2", "File not open for reading for fgetstr" }, - { 10075, "E_FGETLINE_1", "Non-file argument for fgetline" }, - { 10076, "E_FGETLINE_2", "File not open for reading for fgetline" }, - { 10077, "E_FGETFIELD_1", "Non-file argument for fgetfield" }, - { 10078, "E_FGETFIELD_2", "File not open for reading for fgetfield" }, - { 10079, "E_REWIND_1", "Non-file argument for rewind" }, - { 10080, "E_FILES", "Non-integer argument for files" }, - { 10081, "E_PRINTF_1", "Non-string fmt argument for fprint" }, - { 10082, "E_PRINTF_2", "Stdout not open for writing to ???" }, - { 10083, "E_FPRINTF_1", "Non-file first argument for fprintf" }, - { 10084, "E_FPRINTF_2", "Non-string second (fmt) argument for fprintf" }, - { 10085, "E_FPRINTF_3", "File not open for writing for fprintf" }, - { 10086, "E_STRPRINTF_1", "Non-string first (fmt) argument for strprintf" }, - { 10087, "E_STRPRINTF_2", "Error in attempting strprintf ???" }, - { 10088, "E_FSCAN_1", "Non-file first argument for fscan" }, - { 10089, "E_FSCAN_2", "File not open for reading for fscan" }, - { 10090, "E_STRSCAN", "Non-string first argument for strscan" }, - { 10091, "E_FSCANF_1", "Non-file first argument for fscanf" }, - { 10092, "E_FSCANF_2", "Non-string second (fmt) argument for fscanf" }, - { 10093, "E_FSCANF_3", "Non-lvalue argument after second for fscanf" }, - { 10094, "E_FSCANF_4", "File not open for reading or other error for fscanf" }, - { 10095, "E_STRSCANF_1", "Non-string first argument for strscanf" }, - { 10096, "E_STRSCANF_2", "Non-string second (fmt) argument for strscanf" }, - { 10097, "E_STRSCANF_3", "Non-lvalue argument after second for strscanf" }, - { 10098, "E_STRSCANF_4", "Some error in attempting strscanf ???" }, - { 10099, "E_SCANF_1", "Non-string first (fmt) argument for scanf" }, - { 10100, "E_SCANF_2", "Non-lvalue argument after first for scanf" }, - { 10101, "E_SCANF_3", "Some error in attempting scanf ???" }, - { 10102, "E_FTELL_1", "Non-file argument for ftell" }, - { 10103, "E_FTELL_2", "File not open or other error for ftell" }, - { 10104, "E_FSEEK_1", "Non-file first argument for fseek" }, - { 10105, "E_FSEEK_2", "Non-integer or negative second argument for fseek" }, - { 10106, "E_FSEEK_3", "File not open or other error for fseek" }, - { 10107, "E_FSIZE_1", "Non-file argument for fsize" }, - { 10108, "E_FSIZE_2", "File not open or other error for fsize" }, - { 10109, "E_FEOF_1", "Non-file argument for feof" }, - { 10110, "E_FEOF_2", "File not open or other error for feof" }, - { 10111, "E_FERROR_1", "Non-file argument for ferror" }, - { 10112, "E_FERROR_2", "File not open or other error for ferror" }, - { 10113, "E_UNGETC_1", "Non-file argument for ungetc" }, - { 10114, "E_UNGETC_2", "File not open for reading for ungetc" }, - { 10115, "E_UNGETC_3", "Bad second argument or other error for ungetc" }, - { 10116, "E_BIGEXP", "Exponent too big in scanning" }, - { 10117, "E_ISATTY_1", "UNUSED ERROR: E_ISATTY_1 is no longer used" }, - { 10118, "E_ISATTY_2", "UNUSED ERROR: E_ISATTY_2 is no longer used" }, - { 10119, "E_ACCESS_1", "Non-string first argument for access" }, - { 10120, "E_ACCESS_2", "Bad second argument for access" }, - { 10121, "E_SEARCH_1", "Bad first argument for search" }, - { 10122, "E_SEARCH_2", "Bad second argument for search" }, - { 10123, "E_SEARCH_3", "Bad third argument for search" }, - { 10124, "E_SEARCH_4", "Bad fourth argument for search" }, - { 10125, "E_SEARCH_5", "Cannot find fsize or fpos for search" }, - { 10126, "E_SEARCH_6", "File not readable for search" }, - { 10127, "E_RSEARCH_1", "Bad first argument for rsearch" }, - { 10128, "E_RSEARCH_2", "Bad second argument for rsearch" }, - { 10129, "E_RSEARCH_3", "Bad third argument for rsearch" }, - { 10130, "E_RSEARCH_4", "Bad fourth argument for rsearch" }, - { 10131, "E_RSEARCH_5", "Cannot find fsize or fpos for rsearch" }, - { 10132, "E_RSEARCH_6", "File not readable for rsearch" }, - { 10133, "E_MANYOPEN", "Too many open files" }, - { 10134, "E_REWIND_2", "Attempt to rewind a file that is not open" }, - { 10135, "E_STRERROR_1", "Bad argument type for strerror" }, - { 10136, "E_STRERROR_2", "Numeric argument is outside valid errnum range for strerror" }, - { 10137, "E_COS_1", "Bad epsilon for cos" }, - { 10138, "E_COS_2", "Bad first argument for cos" }, - { 10139, "E_SIN_1", "Bad epsilon for sin" }, - { 10140, "E_SIN_2", "Bad first argument for sin" }, - { 10141, "E_EVAL_2", "Non-string argument for eval" }, - { 10142, "E_ARG_1", "Bad epsilon for arg" }, - { 10143, "E_ARG_2", "Bad first argument for arg" }, - { 10144, "E_POLAR_1", "Non-real argument for polar" }, - { 10145, "E_POLAR_2", "Bad epsilon for polar" }, - { 10146, "E_FCNT", "UNUSED ERROR: Non-integral argument for fcnt" }, - { 10147, "E_MATFILL_1", "Non-variable first argument for matfill" }, - { 10148, "E_MATFILL_2", "Non-matrix first argument-value for matfill" }, - { 10149, "E_MATDIM", "Non-matrix argument for matdim" }, - { 10150, "E_MATSUM", "Non-matrix argument for matsum" }, - { 10151, "E_ISIDENT", "UNUSED ERROR: E_ISIDENT is no longer used" }, - { 10152, "E_MATTRANS_1", "Non-matrix argument for mattrans" }, - { 10153, "E_MATTRANS_2", "Non-two-dimensional matrix for mattrans" }, - { 10154, "E_DET_1", "Non-matrix argument for det" }, - { 10155, "E_DET_2", "Matrix for det not of dimension 2" }, - { 10156, "E_DET_3", "Non-square matrix for det" }, - { 10157, "E_MATMIN_1", "Non-matrix first argument for matmin" }, - { 10158, "E_MATMIN_2", "Non-positive-integer second argument for matmin" }, - { 10159, "E_MATMIN_3", "Second argument for matmin exceeds dimension" }, - { 10160, "E_MATMAX_1", "Non-matrix first argument for matmin" }, - { 10161, "E_MATMAX_2", "Second argument for matmax not positive integer" }, - { 10162, "E_MATMAX_3", "Second argument for matmax exceeds dimension" }, - { 10163, "E_CP_1", "Non-matrix argument for cp" }, - { 10164, "E_CP_2", "Non-one-dimensional matrix for cp" }, - { 10165, "E_CP_3", "Matrix size not 3 for cp" }, - { 10166, "E_DP_1", "Non-matrix argument for dp" }, - { 10167, "E_DP_2", "Non-one-dimensional matrix for dp" }, - { 10168, "E_DP_3", "Different-size matrices for dp" }, - { 10169, "E_STRLEN", "Non-string argument for strlen" }, - { 10170, "E_STRCAT", "Non-string argument for strcat" }, - { 10171, "E_SUBSTR_1", "Non-string first argument for strcat" }, - { 10172, "E_SUBSTR_2", "Non-non-negative integer second argument for strcat" }, - { 10173, "E_CHAR", "Bad argument for char" }, - { 10174, "E_ORD", "Non-string argument for ord" }, - { 10175, "E_INSERT_1", "Non-list-variable first argument for insert" }, - { 10176, "E_INSERT_2", "Non-integral second argument for insert" }, - { 10177, "E_PUSH", "Non-list-variable first argument for push" }, - { 10178, "E_APPEND", "Non-list-variable first argument for append" }, - { 10179, "E_DELETE_1", "Non-list-variable first argument for delete" }, - { 10180, "E_DELETE_2", "Non-integral second argument for delete" }, - { 10181, "E_POP", "Non-list-variable argument for pop" }, - { 10182, "E_REMOVE", "Non-list-variable argument for remove" }, - { 10183, "E_LN_1", "Bad epsilon argument for ln" }, - { 10184, "E_LN_2", "Non-numeric first argument for ln" }, - { 10185, "E_ERROR_1", "Invalid argument type for error" }, - { 10186, "E_ERROR_2", "Numeric argument is outside valid errnum range for error" }, - { 10187, "E_EVAL_3", "Attempt to eval at maximum input depth" }, - { 10188, "E_EVAL_4", "Unable to open string for reading" }, - { 10189, "E_RM_1", "First argument for rm is not a non-empty string" }, - { 10190, "E_RM_2", "UNUSED ERROR: Unable to remove a file" }, - { 10191, "E_RDPERM", "UNUSED ERROR: Operation allowed because calc mode disallows read operations" }, - { 10192, "E_WRPERM", "Operation allowed because calc mode disallows write operations" }, - { 10193, "E_EXPERM", "UNUSED ERROR: Operation allowed because calc mode disallows exec operations" }, - { 10194, "E_MIN", "Unordered arguments for min" }, - { 10195, "E_MAX", "Unordered arguments for max" }, - { 10196, "E_LISTMIN", "Unordered items for minimum of list" }, - { 10197, "E_LISTMAX", "Unordered items for maximum of list" }, - { 10198, "E_SIZE", "Size undefined for argument type" }, - { 10199, "E_NO_C_ARG", "Calc must be run with a -C argument to use custom function" }, - { 10200, "E_NO_CUSTOM", "Calc was built with custom functions disabled" }, - { 10201, "E_UNK_CUSTOM", "Custom function unknown, try: show custom" }, - { 10202, "E_BLK_1", "Non-integral length for block" }, - { 10203, "E_BLK_2", "Negative or too-large length for block" }, - { 10204, "E_BLK_3", "Non-integral chunksize for block" }, - { 10205, "E_BLK_4", "Negative or too-large chunksize for block" }, - { 10206, "E_BLKFREE_1", "Named block does not exist for blkfree" }, - { 10207, "E_BLKFREE_2", "Non-integral id specification for blkfree" }, - { 10208, "E_BLKFREE_3", "Block with specified id does not exist" }, - { 10209, "E_BLKFREE_4", "Block already freed" }, - { 10210, "E_BLKFREE_5", "No-realloc protection prevents blkfree" }, - { 10211, "E_BLOCKS_1", "Non-integer argument for blocks" }, - { 10212, "E_BLOCKS_2", "Non-allocated index number for blocks" }, - { 10213, "E_COPY_01", "Non-integer or negative source index for copy" }, - { 10214, "E_COPY_02", "Source index too large for copy" }, - { 10215, "E_COPY_03", "UNUSED ERROR: E_COPY_03 is no longer used" }, - { 10216, "E_COPY_04", "Non-integer or negative number for copy" }, - { 10217, "E_COPY_05", "Number too large for copy" }, - { 10218, "E_COPY_06", "Non-integer or negative destination index for copy" }, - { 10219, "E_COPY_07", "Destination index too large for copy" }, - { 10220, "E_COPY_08", "Freed block source for copy" }, - { 10221, "E_COPY_09", "Unsuitable source type for copy" }, - { 10222, "E_COPY_10", "Freed block destination for copy" }, - { 10223, "E_COPY_11", "Unsuitable destination type for copy" }, - { 10224, "E_COPY_12", "Incompatible source and destination for copy" }, - { 10225, "E_COPY_13", "No-copy-from source variable" }, - { 10226, "E_COPY_14", "No-copy-to destination variable" }, - { 10227, "E_COPY_15", "No-copy-from source named block" }, - { 10228, "E_COPY_16", "No-copy-to destination named block" }, - { 10229, "E_COPY_17", "No-relocate destination for copy" }, - { 10230, "E_COPYF_1", "File not open for copy" }, - { 10231, "E_COPYF_2", "fseek or fsize failure for copy" }, - { 10232, "E_COPYF_3", "fwrite error for copy" }, - { 10233, "E_COPYF_4", "fread error for copy" }, - { 10234, "E_PROTECT_1", "Non-variable first argument for protect" }, - { 10235, "E_PROTECT_2", "Bad second argument for protect" }, - { 10236, "E_PROTECT_3", "Bad third argument for protect" }, - { 10237, "E_MATFILL_3", "No-copy-to destination for matfill" }, - { 10238, "E_MATFILL_4", "No-assign-from source for matfill" }, - { 10239, "E_MATTRACE_1", "Non-matrix argument for mattrace" }, - { 10240, "E_MATTRACE_2", "Non-two-dimensional argument for mattrace" }, - { 10241, "E_MATTRACE_3", "Non-square argument for mattrace" }, - { 10242, "E_TAN_1", "Bad epsilon for tan" }, - { 10243, "E_TAN_2", "Bad argument for tan" }, - { 10244, "E_COT_1", "Bad epsilon for cot" }, - { 10245, "E_COT_2", "Bad argument for cot" }, - { 10246, "E_SEC_1", "Bad epsilon for sec" }, - { 10247, "E_SEC_2", "Bad argument for sec" }, - { 10248, "E_CSC_1", "Bad epsilon for csc" }, - { 10249, "E_CSC_2", "Bad argument for csc" }, - { 10250, "E_SINH_1", "Bad epsilon for sinh" }, - { 10251, "E_SINH_2", "Bad argument for sinh" }, - { 10252, "E_COSH_1", "Bad epsilon for cosh" }, - { 10253, "E_COSH_2", "Bad argument for cosh" }, - { 10254, "E_TANH_1", "Bad epsilon for tanh" }, - { 10255, "E_TANH_2", "Bad argument for tanh" }, - { 10256, "E_COTH_1", "Bad epsilon for coth" }, - { 10257, "E_COTH_2", "Bad argument for coth" }, - { 10258, "E_SECH_1", "Bad epsilon for sech" }, - { 10259, "E_SECH_2", "Bad argument for sech" }, - { 10260, "E_CSCH_1", "Bad epsilon for csch" }, - { 10261, "E_CSCH_2", "Bad argument for csch" }, - { 10262, "E_ASIN_1", "Bad epsilon for asin" }, - { 10263, "E_ASIN_2", "Bad argument for asin" }, - { 10264, "E_ACOS_1", "Bad epsilon for acos" }, - { 10265, "E_ACOS_2", "Bad argument for acos" }, - { 10266, "E_ATAN_1", "Bad epsilon for atan" }, - { 10267, "E_ATAN_2", "Bad argument for atan" }, - { 10268, "E_ACOT_1", "Bad epsilon for acot" }, - { 10269, "E_ACOT_2", "Bad argument for acot" }, - { 10270, "E_ASEC_1", "Bad epsilon for asec" }, - { 10271, "E_ASEC_2", "Bad argument for asec" }, - { 10272, "E_ACSC_1", "Bad epsilon for acsc" }, - { 10273, "E_ACSC_2", "Bad argument for acsc" }, - { 10274, "E_ASINH_1", "Bad epsilon for asin" }, - { 10275, "E_ASINH_2", "Bad argument for asinh" }, - { 10276, "E_ACOSH_1", "Bad epsilon for acosh" }, - { 10277, "E_ACOSH_2", "Bad argument for acosh" }, - { 10278, "E_ATANH_1", "Bad epsilon for atanh" }, - { 10279, "E_ATANH_2", "Bad argument for atanh" }, - { 10280, "E_ACOTH_1", "Bad epsilon for acoth" }, - { 10281, "E_ACOTH_2", "Bad argument for acoth" }, - { 10282, "E_ASECH_1", "UNUSED ERROR: Bad epsilon for asech" }, - { 10283, "E_ASECH_2", "Bad argument for asech" }, - { 10284, "E_ACSCH_1", "Bad epsilon for acsch" }, - { 10285, "E_ACSCH_2", "Bad argument for acsch" }, - { 10286, "E_GD_1", "Bad epsilon for gd" }, - { 10287, "E_GD_2", "Bad argument for gd" }, - { 10288, "E_AGD_1", "Bad epsilon for agd" }, - { 10289, "E_AGD_2", "Bad argument for agd" }, - { 10290, "E_LOGINF", "Log of zero or infinity" }, - { 10291, "E_STRADD", "String addition failure" }, - { 10292, "E_STRMUL", "String multiplication failure" }, - { 10293, "E_STRNEG", "String reversal failure" }, - { 10294, "E_STRSUB", "String subtraction failure" }, - { 10295, "E_BIT_1", "Bad argument type for bit" }, - { 10296, "E_BIT_2", "Index too large for bit" }, - { 10297, "E_SETBIT_1", "Non-integer second argument for setbit" }, - { 10298, "E_SETBIT_2", "Out-of-range index for setbit" }, - { 10299, "E_SETBIT_3", "Non-string first argument for setbit" }, - { 10300, "E_OR", "Bad argument for or" }, - { 10301, "E_AND", "Bad argument for and" }, - { 10302, "E_STROR", "Allocation failure for string or" }, - { 10303, "E_STRAND", "Allocation failure for string and" }, - { 10304, "E_XOR", "Bad argument for xorvalue" }, - { 10305, "E_COMP", "Bad argument for comp" }, - { 10306, "E_STRDIFF", "Allocation failure for string diff" }, - { 10307, "E_STRCOMP", "Allocation failure for string comp" }, - { 10308, "E_SEG_1", "Bad first argument for segment" }, - { 10309, "E_SEG_2", "Bad second argument for segment" }, - { 10310, "E_SEG_3", "Bad third argument for segment" }, - { 10311, "E_STRSEG", "Failure for string segment" }, - { 10312, "E_HIGHBIT_1", "Bad argument type for highbit" }, - { 10313, "E_HIGHBIT_2", "Non-integer argument for highbit" }, - { 10314, "E_LOWBIT_1", "Bad argument type for lowbit" }, - { 10315, "E_LOWBIT_2", "Non-integer argument for lowbit" }, - { 10316, "E_CONTENT", "Bad argument type for unary hash op" }, - { 10317, "E_HASHOP", "Bad argument type for binary hash op" }, - { 10318, "E_HEAD_1", "Bad first argument for head" }, - { 10319, "E_HEAD_2", "Bad second argument for head" }, - { 10320, "E_STRHEAD", "Failure for strhead" }, - { 10321, "E_TAIL_1", "Bad first argument for tail" }, - { 10322, "E_TAIL_2", "UNUSED ERROR: Bad second argument for tail" }, - { 10323, "E_STRTAIL", "Failure for strtail" }, - { 10324, "E_STRSHIFT", "Failure for strshift" }, - { 10325, "E_STRCMP", "Non-string argument for strcmp" }, - { 10326, "E_STRNCMP", "Bad argument type for strncmp" }, - { 10327, "E_XOR_1", "Varying types of argument for xor" }, - { 10328, "E_XOR_2", "Bad argument type for xor" }, - { 10329, "E_STRCPY", "Bad argument type for strcpy" }, - { 10330, "E_STRNCPY", "Bad argument type for strncpy" }, - { 10331, "E_BACKSLASH", "Bad argument type for unary backslash" }, - { 10332, "E_SETMINUS", "Bad argument type for setminus" }, - { 10333, "E_INDICES_1", "Bad first argument type for indices" }, - { 10334, "E_INDICES_2", "Bad second argument for indices" }, - { 10335, "E_EXP_3", "Too-large re(argument) for exp" }, - { 10336, "E_SINH_3", "Too-large re(argument) for sinh" }, - { 10337, "E_COSH_3", "Too-large re(argument) for cosh" }, - { 10338, "E_SIN_3", "Too-large im(argument) for sin" }, - { 10339, "E_COS_3", "Too-large im(argument) for cos" }, - { 10340, "E_GD_3", "Infinite or too-large result for gd" }, - { 10341, "E_AGD_3", "Infinite or too-large result for agd" }, - { 10342, "E_POWER_4", "Too-large value for power" }, - { 10343, "E_ROOT_4", "Too-large value for root" }, - { 10344, "E_DGT_1", "Non-real first arg for digit" }, - { 10345, "E_DGT_2", "Non-integral second arg for digit" }, - { 10346, "E_DGT_3", "Bad third arg for digit" }, - { 10347, "E_PLCS_1", "Bad first argument for places" }, - { 10348, "E_PLCS_2", "Bad second argument for places" }, - { 10349, "E_DGTS_1", "Bad first argument for digits" }, - { 10350, "E_DGTS_2", "Bad second argument for digits" }, - { 10351, "E_ILOG", "Bad first argument for ilog" }, - { 10352, "E_ILOGB", "Bad second argument for ilog" }, - { 10353, "E_IBASE10_LOG", "Bad argument for ilog10" }, - { 10354, "E_IBASE2_LOG", "Bad argument for ilog2" }, - { 10355, "E_COMB_1", "Non-integer second arg for comb" }, - { 10356, "E_COMB_2", "Too-large second arg for comb" }, - { 10357, "E_CTLN", "Bad argument for catalan" }, - { 10358, "E_BERN", "Bad argument for bern" }, - { 10359, "E_EULER", "Bad argument for euler" }, - { 10360, "E_SLEEP", "Bad argument for sleep" }, - { 10361, "E_TTY", "calc_tty failure" }, - { 10362, "E_ASSIGN_1", "No-copy-to destination for octet assign" }, - { 10363, "E_ASSIGN_2", "No-copy-from source for octet assign" }, - { 10364, "E_ASSIGN_3", "No-change destination for octet assign" }, - { 10365, "E_ASSIGN_4", "Non-variable destination for assign" }, - { 10366, "E_ASSIGN_5", "No-assign-to destination for assign" }, - { 10367, "E_ASSIGN_6", "No-assign-from source for assign" }, - { 10368, "E_ASSIGN_7", "No-change destination for assign" }, - { 10369, "E_ASSIGN_8", "No-type-change destination for assign" }, - { 10370, "E_ASSIGN_9", "No-error-value destination for assign" }, - { 10371, "E_SWAP_1", "No-copy argument for octet swap" }, - { 10372, "E_SWAP_2", "No-assign-to-or-from argument for swap" }, - { 10373, "E_SWAP_3", "Non-lvalue argument for swap" }, - { 10374, "E_QUOMOD_1", "Non-lvalue argument 3 or 4 for quomod" }, - { 10375, "E_QUOMOD_2", "Non-real-number arg 1 or 2 or bad arg 5 for quomod" }, - { 10376, "E_QUOMOD_3", "No-assign-to argument 3 or 4 for quomod" }, - { 10377, "E_PREINC_1", "No-copy-to or no-change argument for octet preinc" }, - { 10378, "E_PREINC_2", "Non-variable argument for preinc" }, - { 10379, "E_PREINC_3", "No-assign-to or no-change argument for preinc" }, - { 10380, "E_PREDEC_1", "No-copy-to or no-change argument for octet predec" }, - { 10381, "E_PREDEC_2", "Non-variable argument for predec" }, - { 10382, "E_PREDEC_3", "No-assign-to or no-change argument for predec" }, - { 10383, "E_POSTINC_1", "No-copy-to or no-change argument for octet postinc" }, - { 10384, "E_POSTINC_2", "Non-variable argument for postinc" }, - { 10385, "E_POSTINC_3", "No-assign-to or no-change argument for postinc" }, - { 10386, "E_POSTDEC_1", "No-copy-to or no-change argument for octet postdec" }, - { 10387, "E_POSTDEC_2", "Non-variable argument for postdec" }, - { 10388, "E_POSTDEC_3", "No-assign-to or no-change argument for postdec" }, - { 10389, "E_INIT_01", "Error-type structure for initialization" }, - { 10390, "E_INIT_02", "No-copy-to structure for initialization" }, - { 10391, "E_INIT_03", "Too many initializer values" }, - { 10392, "E_INIT_04", "Attempt to initialize freed named block" }, - { 10393, "E_INIT_05", "Bad structure type for initialization" }, - { 10394, "E_INIT_06", "No-assign-to element for initialization" }, - { 10395, "E_INIT_07", "No-change element for initialization" }, - { 10396, "E_INIT_08", "No-type-change element for initialization" }, - { 10397, "E_INIT_09", "No-error-value element for initialization" }, - { 10398, "E_INIT_10", "No-assign-or-copy-from source for initialization" }, - { 10399, "E_LIST_1", "No-relocate for list insert" }, - { 10400, "E_LIST_2", "No-relocate for list delete" }, - { 10401, "E_LIST_3", "No-relocate for list push" }, - { 10402, "E_LIST_4", "No-relocate for list append" }, - { 10403, "E_LIST_5", "No-relocate for list pop" }, - { 10404, "E_LIST_6", "No-relocate for list remove" }, - { 10405, "E_MODIFY_1", "Non-variable first argument for modify" }, - { 10406, "E_MODIFY_2", "Non-string second argument for modify" }, - { 10407, "E_MODIFY_3", "No-change first argument for modify" }, - { 10408, "E_MODIFY_4", "Undefined function for modify" }, - { 10409, "E_MODIFY_5", "Unacceptable type first argument for modify" }, - { 10410, "E_FPATHOPEN_1", "Non-string arguments for fpathopen" }, - { 10411, "E_FPATHOPEN_2", "Unrecognized mode for fpathopen" }, - { 10412, "E_LOG_1", "Bad epsilon argument for log" }, - { 10413, "E_LOG_2", "Non-numeric first argument for log" }, - { 10414, "E_LOG_3", "Cannot calculate log for this value" }, - { 10415, "E_FGETFILE_1", "Non-file argument for fgetfile" }, - { 10416, "E_FGETFILE_2", "File argument for fgetfile not open for reading" }, - { 10417, "E_FGETFILE_3", "Unable to set file position in fgetfile" }, - { 10418, "E_ESTR", "UNUSED ERROR: Non-representable type for estr" }, - { 10419, "E_STRCASECMP", "Non-string argument for strcasecmp" }, - { 10420, "E_STRNCASECMP", "Bad argument type for strncasecmp" }, - { 10421, "E_ISUPPER", "Bad argument for isupper" }, - { 10422, "E_ISLOWER", "Bad argument for islower" }, - { 10423, "E_ISALNUM", "Bad argument for isalnum" }, - { 10424, "E_ISALPHA", "Bad argument for isalpha" }, - { 10425, "E_ISASCII", "Bad argument for isascii" }, - { 10426, "E_ISCNTRL", "Bad argument for iscntrl" }, - { 10427, "E_ISDIGIT", "Bad argument for isdigit" }, - { 10428, "E_ISGRAPH", "Bad argument for isgraph" }, - { 10429, "E_ISPRINT", "Bad argument for isprint" }, - { 10430, "E_ISPUNCT", "Bad argument for ispunct" }, - { 10431, "E_ISSPACE", "Bad argument for isspace" }, - { 10432, "E_ISXDIGIT", "Bad argument for isxdigit" }, - { 10433, "E_STRTOUPPER", "Bad argument type for strtoupper" }, - { 10434, "E_STRTOLOWER", "Bad argument type for strtolower" }, - { 10435, "E_TAN_3", "UNUSED ERROR: Invalid value for calculating the sin numerator for tan" }, - { 10436, "E_TAN_4", "UNUSED ERROR: Invalid value for calculating the cos denominator for tan" }, - { 10437, "E_COT_3", "UNUSED ERROR: Invalid value for calculating the sin numerator for cot" }, - { 10438, "E_COT_4", "UNUSED ERROR: Invalid value for calculating the cos denominator for cot" }, - { 10439, "E_SEC_3", "UNUSED ERROR: Invalid value for calculating the cos reciprocal for sec" }, - { 10440, "E_CSC_3", "UNUSED ERROR: Invalid value for calculating the sin reciprocal for csc" }, - { 10441, "E_TANH_3", "Invalid value for calculating the sinh numerator for tanh" }, - { 10442, "E_TANH_4", "Invalid value for calculating the cosh denominator for tanh" }, - { 10443, "E_COTH_3", "Invalid value for calculating the sinh numerator for coth" }, - { 10444, "E_COTH_4", "Invalid value for calculating the cosh denominator for coth" }, - { 10445, "E_SECH_3", "Invalid value for calculating the cosh reciprocal for sech" }, - { 10446, "E_CSCH_3", "Invalid value for calculating the sinh reciprocal for csch" }, - { 10447, "E_ASIN_3", "Invalid value for calculating asin" }, - { 10448, "E_ACOS_3", "Invalid value for calculating acos" }, - { 10449, "E_ASINH_3", "Invalid value for calculating asinh" }, - { 10450, "E_ACOSH_3", "Invalid value for calculating acosn" }, - { 10451, "E_ATAN_3", "Invalid value for calculating atan" }, - { 10452, "E_ACOT_3", "Invalid value for calculating acot" }, - { 10453, "E_ASEC_3", "Invalid value for calculating asec" }, - { 10454, "E_ACSC_3", "Invalid value for calculating acsc" }, - { 10455, "E_ATANH_3", "Invalid value for calculating atan" }, - { 10456, "E_ACOTH_3", "Invalid value for calculating acot" }, - { 10457, "E_ASECH_3", "Invalid value for calculating asec" }, - { 10458, "E_ACSCH_3", "Invalid value for calculating acsc" }, - { 10459, "E_D2R_1", "Bad epsilon for converting degrees to radians" }, - { 10460, "E_D2R_2", "Bad first argument converting degrees to radians" }, - { 10461, "E_R2D_1", "Bad epsilon for converting radians to degrees" }, - { 10462, "E_R2D_2", "Bad first argument converting radians to degrees" }, - { 10463, "E_G2R_1", "Bad epsilon for converting gradians to radians" }, - { 10464, "E_G2R_2", "Bad first argument converting gradians to radians" }, - { 10465, "E_R2G_1", "Bad epsilon for converting radians to gradians" }, - { 10466, "E_R2G_2", "Bad first argument converting radians to gradians" }, - { 10467, "E_D2G_1", "Bad first argument converting degrees to gradians" }, - { 10468, "E_G2D_1", "Bad first argument converting gradians to degrees" }, - { 10469, "E_D2DMS_1", "Non-lvalue arguments 2, 3 or 4 for d2dms" }, - { 10470, "E_D2DMS_2", "Non-real-number arg 1 for d2dms" }, - { 10471, "E_D2DMS_3", "No-assign-to argument 2, 3 or 4 for d2dms" }, - { 10472, "E_D2DMS_4", "Invalid rounding arg 5 for d2dms" }, - { 10473, "E_D2DM_1", "Non-lvalue arguments 2 or 3 for d2dm" }, - { 10474, "E_D2DM_2", "Non-real-number arg 1 for d2dm" }, - { 10475, "E_D2DM_3", "No-assign-to argument 2 or 3 for d2dm" }, - { 10476, "E_D2DM_4", "Invalid rounding arg 4 for d2dm" }, - { 10477, "E_G2GMS_1", "Non-lvalue arguments 2, 3 or 4 for g2gms" }, - { 10478, "E_G2GMS_2", "Non-real-number arg 1 for g2gms" }, - { 10479, "E_G2GMS_3", "No-assign-to argument 2 or 3 for g2gms" }, - { 10480, "E_G2GMS_4", "Invalid rounding arg 5 for g2gms" }, - { 10481, "E_G2GM_1", "Non-lvalue arguments 2 or 3 for g2gm" }, - { 10482, "E_G2GM_2", "Non-real-number arg 1 for g2gm" }, - { 10483, "E_G2GM_3", "No-assign-to argument 2, 3 or 4 for g2gm" }, - { 10484, "E_G2GM_4", "Invalid rounding arg 4 for g2gm" }, - { 10485, "E_H2HMS_1", "Non-lvalue arguments 2, 3 or 4 for h2hms" }, - { 10486, "E_H2HMS_2", "Non-real-number arg 1 for h2hms" }, - { 10487, "E_H2HMS_3", "No-assign-to argument 2, 3 or 4 for h2hms" }, - { 10488, "E_H2HMS_4", "Invalid rounding arg 5 for h2hms" }, - { 10489, "E_H2HM_1", "Non-lvalue arguments 2 or 3 for h2hm" }, - { 10490, "E_H2HM_2", "Non-real-number arg 1 for h2hm" }, - { 10491, "E_H2HM_3", "No-assign-to argument 2 or 3 for h2hm" }, - { 10492, "E_H2HM_4", "Invalid rounding arg 4 for h2hm" }, - { 10493, "E_DMS2D_1", "Non-real-number arguments 1, 2 or 3 for dms2d" }, - { 10494, "E_DMS2D_2", "Invalid rounding arg 4 for dms2d" }, - { 10495, "E_DM2D_1", "Non-real-number arguments 1 or 2 for dm2d" }, - { 10496, "E_DM2D_2", "Invalid rounding arg 4 for dm2d" }, - { 10497, "E_GMS2G_1", "Non-real-number arguments 1, 2 or 3 for gms2g" }, - { 10498, "E_GMS2G_2", "Invalid rounding arg 4 for gms2g" }, - { 10499, "E_GM2G_1", "Non-real-number arguments 1 or 2 for gm2g" }, - { 10500, "E_GM2G_2", "Invalid rounding arg 4 for gm2g" }, - { 10501, "E_HMS2H_1", "Non-real-number arguments 1, 2 or 3 for hms2h" }, - { 10502, "E_HMS2H_2", "Invalid rounding arg 4 for hms2h" }, - { 10503, "E_HM2H_1", "UNUSED ERROR: Non-real-number arguments 1 or 2 for hm2h" }, - { 10504, "E_HM2H_2", "UNUSED ERROR: Invalid rounding arg 4 for hm2h" }, - { 10505, "E_LOG2_1", "Bad epsilon argument for log2" }, - { 10506, "E_LOG2_2", "Non-numeric first argument for log2" }, - { 10507, "E_LOG2_3", "Cannot calculate log2 for this value" }, - { 10508, "E_LOGN_1", "Bad epsilon argument for logn" }, - { 10509, "E_LOGN_2", "Non-numeric first argument for logn" }, - { 10510, "E_LOGN_3", "Cannot calculate logn for this value" }, - { 10511, "E_LOGN_4", "Cannot calculate logn for this log base" }, - { 10512, "E_LOGN_5", "Non-numeric second argument for logn" }, - { 10513, "E_VERSIN_1", "Bad epsilon for versin" }, - { 10514, "E_VERSIN_2", "Bad first argument for versin" }, - { 10515, "E_VERSIN_3", "Too-large im(argument) for versin" }, - { 10516, "E_AVERSIN_1", "Bad epsilon for aversin" }, - { 10517, "E_AVERSIN_2", "Bad first argument for aversin" }, - { 10518, "E_AVERSIN_3", "Too-large im(argument) for aversin" }, - { 10519, "E_COVERSIN_1", "Bad epsilon for coversin" }, - { 10520, "E_COVERSIN_2", "Bad first argument for coversin" }, - { 10521, "E_COVERSIN_3", "Too-large im(argument) for coversin" }, - { 10522, "E_ACOVERSIN_1", "Bad epsilon for acoversin" }, - { 10523, "E_ACOVERSIN_2", "Bad first argument for acoversin" }, - { 10524, "E_ACOVERSIN_3", "Too-large im(argument) for acoversin" }, - { 10525, "E_VERCOS_1", "Bad epsilon for vercos" }, - { 10526, "E_VERCOS_2", "Bad first argument for vercos" }, - { 10527, "E_VERCOS_3", "Too-large im(argument) for vercos" }, - { 10528, "E_AVERCOS_1", "Bad epsilon for avercos" }, - { 10529, "E_AVERCOS_2", "Bad first argument for avercos" }, - { 10530, "E_AVERCOS_3", "Too-large im(argument) for avercos" }, - { 10531, "E_COVERCOS_1", "Bad epsilon for covercos" }, - { 10532, "E_COVERCOS_2", "Bad first argument for covercos" }, - { 10533, "E_COVERCOS_3", "Too-large im(argument) for covercos" }, - { 10534, "E_ACOVERCOS_1", "Bad epsilon for acovercos" }, - { 10535, "E_ACOVERCOS_2", "Bad first argument for acovercos" }, - { 10536, "E_ACOVERCOS_3", "Too-large im(argument) for acovercos" }, - { 10537, "E_TAN_5", "Invalid complex argument for tan" }, - { 10538, "E_COT_5", "Invalid zero argument for cot" }, - { 10539, "E_COT_6", "Invalid complex argument for cot" }, - { 10540, "E_SEC_5", "Invalid complex argument for sec" }, - { 10541, "E_CSC_5", "Invalid zero argument for csc" }, - { 10542, "E_CSC_6", "Invalid complex argument for csc" }, - { 10543, "E_ERROR_3", "String argument is not a valid E_STRING for error" }, - { 10544, "E_ERROR_4", "Numeric argument is not an integer for error" }, - { 10545, "E_STRERROR_3", "String argument is not a valid E_STRING for strerror" }, - { 10546, "E_STRERROR_4", "errnum_2_errmsg returned NULL as called from strerror" }, - { 10547, "E_STRERROR_5", "Numeric argument is not an integer for strerror" }, - { 10548, "E_ERRNO_1", "Invalid argument type for errno" }, - { 10549, "E_ERRNO_2", "Numeric argument is outside valid errnum range for errno" }, - { 10550, "E_ERRNO_3", "String argument is not a valid E_STRING for errno" }, - { 10551, "E_ERRNO_4", "Numeric argument is not an integer for errno" }, - { 10552, "E_ERRSYM_1", "Invalid argument type for errsym" }, - { 10553, "E_ERRSYM_2", "Numeric argument is outside valid errnum range for errsym" }, - { 10554, "E_ERRSYM_3", "String argument is not a valid E_STRING for errsym" }, - { 10555, "E_ERRSYM_4", "Numeric argument is not an integer for errsym" }, - { 10556, "E_ERRSYM_5", "Unable to create a valid E_STRING from the errnum for errsym" }, - { 10557, "E_HAVERSIN_1", "Bad epsilon for haversin" }, - { 10558, "E_HAVERSIN_2", "Bad first argument for haversin" }, - { 10559, "E_HAVERSIN_3", "Too-large im(argument) for haversin" }, - { 10560, "E_AHAVERSIN_1", "Bad epsilon for ahaversin" }, - { 10561, "E_AHAVERSIN_2", "Bad first argument for ahaversin" }, - { 10562, "E_AHAVERSIN_3", "Too-large im(argument) for ahaversin" }, - { 10563, "E_HACOVERSIN_1", "Bad epsilon for hacoversin" }, - { 10564, "E_HACOVERSIN_2", "Bad first argument for hacoversin" }, - { 10565, "E_HACOVERSIN_3", "Too-large im(argument) for hacoversin" }, - { 10566, "E_AHACOVERSIN_1", "Bad epsilon for ahacoversin" }, - { 10567, "E_AHACOVERSIN_2", "Bad first argument for achaoversin" }, - { 10568, "E_AHACOVERSIN_3", "Too-large im(argument) for ahacoversin" }, - { 10569, "E_HAVERCOS_1", "Bad epsilon for havercos" }, - { 10570, "E_HAVERCOS_2", "Bad first argument for havercos" }, - { 10571, "E_HAVERCOS_3", "Too-large im(argument) for havercos" }, - { 10572, "E_AHAVERCOS_1", "Bad epsilon for ahavercos" }, - { 10573, "E_AHAVERCOS_2", "Bad first argument for ahavercos" }, - { 10574, "E_AHAVERCOS_3", "Too-large im(argument) for ahavercos" }, - { 10575, "E_HACOVERCOS_1", "Bad epsilon for hacovercos" }, - { 10576, "E_HACOVERCOS_2", "Bad first argument for hacovercos" }, - { 10577, "E_HACOVERCOS_3", "Too-large im(argument) for hacovercos" }, - { 10578, "E_AHACOVERCOS_1", "Bad epsilon for ahacovercos" }, - { 10579, "E_AHACOVERCOS_2", "Bad first argument for achaovercos" }, - { 10580, "E_AHACOVERCOS_3", "Too-large im(argument) for ahacovercos" }, - { 10581, "E_EXSEC_1", "Bad epsilon for exsec" }, - { 10582, "E_EXSEC_2", "Bad argument for exsec" }, - { 10583, "E_EXSEC_3", "Invalid complex argument for exsec" }, - { 10584, "E_AEXSEC_1", "Bad epsilon for aexsec" }, - { 10585, "E_AEXSEC_2", "Bad argument for aexsec" }, - { 10586, "E_AEXSEC_3", "Invalid value for calculating aexsec" }, - { 10587, "E_EXCSC_1", "Bad epsilon for excsc" }, - { 10588, "E_EXCSC_2", "Bad argument for excsc" }, - { 10589, "E_EXCSC_3", "Invalid zero argument for excsc" }, - { 10590, "E_EXCSC_4", "Invalid complex argument for excsc" }, - { 10591, "E_AEXCSC_1", "Bad epsilon for aexcsc" }, - { 10592, "E_AEXCSC_2", "Bad argument for aexcsc" }, - { 10593, "E_AEXCSC_3", "Invalid value for calculating aexcsc" }, - { 10594, "E_CRD_1", "Bad epsilon for crd" }, - { 10595, "E_CRD_2", "Bad argument for crd" }, - { 10596, "E_CRD_3", "Invalid complex argument for crd" }, - { 10597, "E_ACRD_1", "Bad epsilon for acrd" }, - { 10598, "E_ACRD_2", "Bad argument for acrd" }, - { 10599, "E_ACRD_3", "Invalid value for calculating acrd" }, - { 10600, "E_CAS_1", "Bad epsilon for cas" }, - { 10601, "E_CAS_2", "Bad argument for cas" }, - { 10602, "E_CAS_3", "Invalid complex argument for cas" }, - { 10603, "E_CIS_1", "Non-real epsilon for cis" }, - { 10604, "E_CIS_2", "Bad first argument for cis" }, - { 10605, "E_CIS_3", "Too-large re(argument) for cis" }, - { 10606, "E_LN_3", "Cannot calculate ln of 0" }, - { 10607, "E_LOG_5", "Cannot calculate log of 0" }, - { 10608, "E_LOG2_4", "Cannot calculate log base 2 of 0" }, - { 10609, "E_LOGN_6", "Cannot calculate log base n of 0" }, - /* IMPORTANT NOTE: add new entries above here and be sure their errnum numeric value is consecutive! */ + /* The E__BASE entry below must start with 10000 and must be first!! */ + { 10000, "E__BASE", "No error" }, + { 10001, "E_DIVBYZERO", "Division by zero" }, + { 10002, "E_ZERODIVZERO", "Indeterminate (0/0)" }, + { 10003, "E_ADD", "Bad arguments for +" }, + { 10004, "E_SUB", "Bad arguments for binary -" }, + { 10005, "E_MUL", "Bad arguments for *" }, + { 10006, "E_DIV", "Bad arguments for /" }, + { 10007, "E_NEG", "Bad argument for unary -" }, + { 10008, "E_SQUARE", "Bad argument for squaring" }, + { 10009, "E_INV", "Bad argument for inverse" }, + { 10010, "E_INCV", "Bad argument for ++" }, + { 10011, "E_DECV", "Bad argument for --" }, + { 10012, "E_INT", "Bad argument for int" }, + { 10013, "E_FRAC", "Bad argument for frac" }, + { 10014, "E_CONJ", "Bad argument for conj" }, + { 10015, "E_APPR_1", "Bad first argument for appr" }, + { 10016, "E_APPR_2", "Bad second argument for appr" }, + { 10017, "E_APPR_3", "Bad third argument for appr" }, + { 10018, "E_ROUND_1", "Bad first argument for round" }, + { 10019, "E_ROUND_2", "Bad second argument for round" }, + { 10020, "E_ROUND_3", "Bad third argument for round" }, + { 10021, "E_BROUND_1", "Bad first argument for bround" }, + { 10022, "E_BROUND_2", "Bad second argument for bround" }, + { 10023, "E_BROUND_3", "Bad third argument for bround" }, + { 10024, "E_SQRT_1", "Bad first argument for sqrt" }, + { 10025, "E_SQRT_2", "Bad second argument for sqrt" }, + { 10026, "E_SQRT_3", "Bad third argument for sqrt" }, + { 10027, "E_ROOT_1", "Bad first argument for root" }, + { 10028, "E_ROOT_2", "Bad second argument for root" }, + { 10029, "E_ROOT_3", "Bad third argument for root" }, + { 10030, "E_NORM", "Bad argument for norm" }, + { 10031, "E_SHIFT_1", "Bad first argument for << or >>" }, + { 10032, "E_SHIFT_2", "Bad second argument for << or >>" }, + { 10033, "E_SCALE_1", "Bad first argument for scale" }, + { 10034, "E_SCALE_2", "Bad second argument for scale" }, + { 10035, "E_POWI_1", "Bad first argument for ^" }, + { 10036, "E_POWI_2", "Bad second argument for ^" }, + { 10037, "E_POWER_1", "Bad first argument for power" }, + { 10038, "E_POWER_2", "Bad second argument for power" }, + { 10039, "E_POWER_3", "Bad third argument for power" }, + { 10040, "E_QUO_1", "Bad first argument for quo or //" }, + { 10041, "E_QUO_2", "Bad second argument for quo or //" }, + { 10042, "E_QUO_3", "Bad third argument for quo" }, + { 10043, "E_MOD_1", "Bad first argument for mod or %" }, + { 10044, "E_MOD_2", "Bad second argument for mod or %" }, + { 10045, "E_MOD_3", "Bad third argument for mod" }, + { 10046, "E_SGN", "Bad argument for sgn" }, + { 10047, "E_ABS_1", "Bad first argument for abs" }, + { 10048, "E_ABS_2", "Bad second argument for abs" }, + { 10049, "E_EVAL", "Scan error in argument for eval" }, + { 10050, "E_STR", "Non-simple type for str" }, + { 10051, "E_EXP_1", "Non-real epsilon for exp" }, + { 10052, "E_EXP_2", "Bad first argument for exp" }, + { 10053, "E_FPUTC_1", "Non-file first argument for fputc" }, + { 10054, "E_FPUTC_2", "Bad second argument for fputc" }, + { 10055, "E_FPUTC_3", "File not open for writing for fputc" }, + { 10056, "E_FGETC_1", "Non-file first argument for fgetc" }, + { 10057, "E_FGETC_2", "File not open for reading for fgetc" }, + { 10058, "E_FOPEN_1", "Non-string arguments for fopen" }, + { 10059, "E_FOPEN_2", "Unrecognized mode for fopen" }, + { 10060, "E_FREOPEN_1", "Non-file first argument for freopen" }, + { 10061, "E_FREOPEN_2", "Non-string or unrecognized mode for freopen" }, + { 10062, "E_FREOPEN_3", "Non-string third argument for freopen" }, + { 10063, "E_FCLOSE_1", "Non-file argument for fclose" }, + { 10064, "E_FFLUSH", "Non-file argument for fflush" }, + { 10065, "E_FPUTS_1", "Non-file first argument for fputs" }, + { 10066, "E_FPUTS_2", "Non-string argument after first for fputs" }, + { 10067, "E_FPUTS_3", "File not open for writing for fputs" }, + { 10068, "E_FGETS_1", "Non-file argument for fgets" }, + { 10069, "E_FGETS_2", "File not open for reading for fgets" }, + { 10070, "E_FPUTSTR_1", "Non-file first argument for fputstr" }, + { 10071, "E_FPUTSTR_2", "Non-string argument after first for fputstr" }, + { 10072, "E_FPUTSTR_3", "File not open for writing for fputstr" }, + { 10073, "E_FGETSTR_1", "Non-file first argument for fgetstr" }, + { 10074, "E_FGETSTR_2", "File not open for reading for fgetstr" }, + { 10075, "E_FGETLINE_1", "Non-file argument for fgetline" }, + { 10076, "E_FGETLINE_2", "File not open for reading for fgetline" }, + { 10077, "E_FGETFIELD_1", "Non-file argument for fgetfield" }, + { 10078, "E_FGETFIELD_2", "File not open for reading for fgetfield" }, + { 10079, "E_REWIND_1", "Non-file argument for rewind" }, + { 10080, "E_FILES", "Non-integer argument for files" }, + { 10081, "E_PRINTF_1", "Non-string fmt argument for fprint" }, + { 10082, "E_PRINTF_2", "Stdout not open for writing to ???" }, + { 10083, "E_FPRINTF_1", "Non-file first argument for fprintf" }, + { 10084, "E_FPRINTF_2", "Non-string second (fmt) argument for fprintf" }, + { 10085, "E_FPRINTF_3", "File not open for writing for fprintf" }, + { 10086, "E_STRPRINTF_1", "Non-string first (fmt) argument for strprintf" }, + { 10087, "E_STRPRINTF_2", "Error in attempting strprintf ???" }, + { 10088, "E_FSCAN_1", "Non-file first argument for fscan" }, + { 10089, "E_FSCAN_2", "File not open for reading for fscan" }, + { 10090, "E_STRSCAN", "Non-string first argument for strscan" }, + { 10091, "E_FSCANF_1", "Non-file first argument for fscanf" }, + { 10092, "E_FSCANF_2", "Non-string second (fmt) argument for fscanf" }, + { 10093, "E_FSCANF_3", "Non-lvalue argument after second for fscanf" }, + { 10094, "E_FSCANF_4", "File not open for reading or other error for fscanf" }, + { 10095, "E_STRSCANF_1", "Non-string first argument for strscanf" }, + { 10096, "E_STRSCANF_2", "Non-string second (fmt) argument for strscanf" }, + { 10097, "E_STRSCANF_3", "Non-lvalue argument after second for strscanf" }, + { 10098, "E_STRSCANF_4", "Some error in attempting strscanf ???" }, + { 10099, "E_SCANF_1", "Non-string first (fmt) argument for scanf" }, + { 10100, "E_SCANF_2", "Non-lvalue argument after first for scanf" }, + { 10101, "E_SCANF_3", "Some error in attempting scanf ???" }, + { 10102, "E_FTELL_1", "Non-file argument for ftell" }, + { 10103, "E_FTELL_2", "File not open or other error for ftell" }, + { 10104, "E_FSEEK_1", "Non-file first argument for fseek" }, + { 10105, "E_FSEEK_2", "Non-integer or negative second argument for fseek" }, + { 10106, "E_FSEEK_3", "File not open or other error for fseek" }, + { 10107, "E_FSIZE_1", "Non-file argument for fsize" }, + { 10108, "E_FSIZE_2", "File not open or other error for fsize" }, + { 10109, "E_FEOF_1", "Non-file argument for feof" }, + { 10110, "E_FEOF_2", "File not open or other error for feof" }, + { 10111, "E_FERROR_1", "Non-file argument for ferror" }, + { 10112, "E_FERROR_2", "File not open or other error for ferror" }, + { 10113, "E_UNGETC_1", "Non-file argument for ungetc" }, + { 10114, "E_UNGETC_2", "File not open for reading for ungetc" }, + { 10115, "E_UNGETC_3", "Bad second argument or other error for ungetc" }, + { 10116, "E_BIGEXP", "Exponent too big in scanning" }, + { 10117, "E_ISATTY_1", "UNUSED ERROR: E_ISATTY_1 is no longer used" }, + { 10118, "E_ISATTY_2", "UNUSED ERROR: E_ISATTY_2 is no longer used" }, + { 10119, "E_ACCESS_1", "Non-string first argument for access" }, + { 10120, "E_ACCESS_2", "Bad second argument for access" }, + { 10121, "E_SEARCH_1", "Bad first argument for search" }, + { 10122, "E_SEARCH_2", "Bad second argument for search" }, + { 10123, "E_SEARCH_3", "Bad third argument for search" }, + { 10124, "E_SEARCH_4", "Bad fourth argument for search" }, + { 10125, "E_SEARCH_5", "Cannot find fsize or fpos for search" }, + { 10126, "E_SEARCH_6", "File not readable for search" }, + { 10127, "E_RSEARCH_1", "Bad first argument for rsearch" }, + { 10128, "E_RSEARCH_2", "Bad second argument for rsearch" }, + { 10129, "E_RSEARCH_3", "Bad third argument for rsearch" }, + { 10130, "E_RSEARCH_4", "Bad fourth argument for rsearch" }, + { 10131, "E_RSEARCH_5", "Cannot find fsize or fpos for rsearch" }, + { 10132, "E_RSEARCH_6", "File not readable for rsearch" }, + { 10133, "E_MANYOPEN", "Too many open files" }, + { 10134, "E_REWIND_2", "Attempt to rewind a file that is not open" }, + { 10135, "E_STRERROR_1", "Bad argument type for strerror" }, + { 10136, "E_STRERROR_2", "Numeric argument is outside valid errnum range for strerror" }, + { 10137, "E_COS_1", "Bad epsilon for cos" }, + { 10138, "E_COS_2", "Bad first argument for cos" }, + { 10139, "E_SIN_1", "Bad epsilon for sin" }, + { 10140, "E_SIN_2", "Bad first argument for sin" }, + { 10141, "E_EVAL_2", "Non-string argument for eval" }, + { 10142, "E_ARG_1", "Bad epsilon for arg" }, + { 10143, "E_ARG_2", "Bad first argument for arg" }, + { 10144, "E_POLAR_1", "Non-real argument for polar" }, + { 10145, "E_POLAR_2", "Bad epsilon for polar" }, + { 10146, "E_FCNT", "UNUSED ERROR: Non-integral argument for fcnt" }, + { 10147, "E_MATFILL_1", "Non-variable first argument for matfill" }, + { 10148, "E_MATFILL_2", "Non-matrix first argument-value for matfill" }, + { 10149, "E_MATDIM", "Non-matrix argument for matdim" }, + { 10150, "E_MATSUM", "Non-matrix argument for matsum" }, + { 10151, "E_ISIDENT", "UNUSED ERROR: E_ISIDENT is no longer used" }, + { 10152, "E_MATTRANS_1", "Non-matrix argument for mattrans" }, + { 10153, "E_MATTRANS_2", "Non-two-dimensional matrix for mattrans" }, + { 10154, "E_DET_1", "Non-matrix argument for det" }, + { 10155, "E_DET_2", "Matrix for det not of dimension 2" }, + { 10156, "E_DET_3", "Non-square matrix for det" }, + { 10157, "E_MATMIN_1", "Non-matrix first argument for matmin" }, + { 10158, "E_MATMIN_2", "Non-positive-integer second argument for matmin" }, + { 10159, "E_MATMIN_3", "Second argument for matmin exceeds dimension" }, + { 10160, "E_MATMAX_1", "Non-matrix first argument for matmin" }, + { 10161, "E_MATMAX_2", "Second argument for matmax not positive integer" }, + { 10162, "E_MATMAX_3", "Second argument for matmax exceeds dimension" }, + { 10163, "E_CP_1", "Non-matrix argument for cp" }, + { 10164, "E_CP_2", "Non-one-dimensional matrix for cp" }, + { 10165, "E_CP_3", "Matrix size not 3 for cp" }, + { 10166, "E_DP_1", "Non-matrix argument for dp" }, + { 10167, "E_DP_2", "Non-one-dimensional matrix for dp" }, + { 10168, "E_DP_3", "Different-size matrices for dp" }, + { 10169, "E_STRLEN", "Non-string argument for strlen" }, + { 10170, "E_STRCAT", "Non-string argument for strcat" }, + { 10171, "E_SUBSTR_1", "Non-string first argument for strcat" }, + { 10172, "E_SUBSTR_2", "Non-non-negative integer second argument for strcat" }, + { 10173, "E_CHAR", "Bad argument for char" }, + { 10174, "E_ORD", "Non-string argument for ord" }, + { 10175, "E_INSERT_1", "Non-list-variable first argument for insert" }, + { 10176, "E_INSERT_2", "Non-integral second argument for insert" }, + { 10177, "E_PUSH", "Non-list-variable first argument for push" }, + { 10178, "E_APPEND", "Non-list-variable first argument for append" }, + { 10179, "E_DELETE_1", "Non-list-variable first argument for delete" }, + { 10180, "E_DELETE_2", "Non-integral second argument for delete" }, + { 10181, "E_POP", "Non-list-variable argument for pop" }, + { 10182, "E_REMOVE", "Non-list-variable argument for remove" }, + { 10183, "E_LN_1", "Bad epsilon argument for ln" }, + { 10184, "E_LN_2", "Non-numeric first argument for ln" }, + { 10185, "E_ERROR_1", "Invalid argument type for error" }, + { 10186, "E_ERROR_2", "Numeric argument is outside valid errnum range for error" }, + { 10187, "E_EVAL_3", "Attempt to eval at maximum input depth" }, + { 10188, "E_EVAL_4", "Unable to open string for reading" }, + { 10189, "E_RM_1", "First argument for rm is not a non-empty string" }, + { 10190, "E_RM_2", "UNUSED ERROR: Unable to remove a file" }, + { 10191, "E_RDPERM", "UNUSED ERROR: Operation allowed because calc mode disallows read operations" }, + { 10192, "E_WRPERM", "Operation allowed because calc mode disallows write operations" }, + { 10193, "E_EXPERM", "UNUSED ERROR: Operation allowed because calc mode disallows exec operations" }, + { 10194, "E_MIN", "Unordered arguments for min" }, + { 10195, "E_MAX", "Unordered arguments for max" }, + { 10196, "E_LISTMIN", "Unordered items for minimum of list" }, + { 10197, "E_LISTMAX", "Unordered items for maximum of list" }, + { 10198, "E_SIZE", "Size undefined for argument type" }, + { 10199, "E_NO_C_ARG", "Calc must be run with a -C argument to use custom function" }, + { 10200, "E_NO_CUSTOM", "Calc was built with custom functions disabled" }, + { 10201, "E_UNK_CUSTOM", "Custom function unknown, try: show custom" }, + { 10202, "E_BLK_1", "Non-integral length for block" }, + { 10203, "E_BLK_2", "Negative or too-large length for block" }, + { 10204, "E_BLK_3", "Non-integral chunksize for block" }, + { 10205, "E_BLK_4", "Negative or too-large chunksize for block" }, + { 10206, "E_BLKFREE_1", "Named block does not exist for blkfree" }, + { 10207, "E_BLKFREE_2", "Non-integral id specification for blkfree" }, + { 10208, "E_BLKFREE_3", "Block with specified id does not exist" }, + { 10209, "E_BLKFREE_4", "Block already freed" }, + { 10210, "E_BLKFREE_5", "No-realloc protection prevents blkfree" }, + { 10211, "E_BLOCKS_1", "Non-integer argument for blocks" }, + { 10212, "E_BLOCKS_2", "Non-allocated index number for blocks" }, + { 10213, "E_COPY_01", "Non-integer or negative source index for copy" }, + { 10214, "E_COPY_02", "Source index too large for copy" }, + { 10215, "E_COPY_03", "UNUSED ERROR: E_COPY_03 is no longer used" }, + { 10216, "E_COPY_04", "Non-integer or negative number for copy" }, + { 10217, "E_COPY_05", "Number too large for copy" }, + { 10218, "E_COPY_06", "Non-integer or negative destination index for copy" }, + { 10219, "E_COPY_07", "Destination index too large for copy" }, + { 10220, "E_COPY_08", "Freed block source for copy" }, + { 10221, "E_COPY_09", "Unsuitable source type for copy" }, + { 10222, "E_COPY_10", "Freed block destination for copy" }, + { 10223, "E_COPY_11", "Unsuitable destination type for copy" }, + { 10224, "E_COPY_12", "Incompatible source and destination for copy" }, + { 10225, "E_COPY_13", "No-copy-from source variable" }, + { 10226, "E_COPY_14", "No-copy-to destination variable" }, + { 10227, "E_COPY_15", "No-copy-from source named block" }, + { 10228, "E_COPY_16", "No-copy-to destination named block" }, + { 10229, "E_COPY_17", "No-relocate destination for copy" }, + { 10230, "E_COPYF_1", "File not open for copy" }, + { 10231, "E_COPYF_2", "fseek or fsize failure for copy" }, + { 10232, "E_COPYF_3", "fwrite error for copy" }, + { 10233, "E_COPYF_4", "fread error for copy" }, + { 10234, "E_PROTECT_1", "Non-variable first argument for protect" }, + { 10235, "E_PROTECT_2", "Bad second argument for protect" }, + { 10236, "E_PROTECT_3", "Bad third argument for protect" }, + { 10237, "E_MATFILL_3", "No-copy-to destination for matfill" }, + { 10238, "E_MATFILL_4", "No-assign-from source for matfill" }, + { 10239, "E_MATTRACE_1", "Non-matrix argument for mattrace" }, + { 10240, "E_MATTRACE_2", "Non-two-dimensional argument for mattrace" }, + { 10241, "E_MATTRACE_3", "Non-square argument for mattrace" }, + { 10242, "E_TAN_1", "Bad epsilon for tan" }, + { 10243, "E_TAN_2", "Bad argument for tan" }, + { 10244, "E_COT_1", "Bad epsilon for cot" }, + { 10245, "E_COT_2", "Bad argument for cot" }, + { 10246, "E_SEC_1", "Bad epsilon for sec" }, + { 10247, "E_SEC_2", "Bad argument for sec" }, + { 10248, "E_CSC_1", "Bad epsilon for csc" }, + { 10249, "E_CSC_2", "Bad argument for csc" }, + { 10250, "E_SINH_1", "Bad epsilon for sinh" }, + { 10251, "E_SINH_2", "Bad argument for sinh" }, + { 10252, "E_COSH_1", "Bad epsilon for cosh" }, + { 10253, "E_COSH_2", "Bad argument for cosh" }, + { 10254, "E_TANH_1", "Bad epsilon for tanh" }, + { 10255, "E_TANH_2", "Bad argument for tanh" }, + { 10256, "E_COTH_1", "Bad epsilon for coth" }, + { 10257, "E_COTH_2", "Bad argument for coth" }, + { 10258, "E_SECH_1", "Bad epsilon for sech" }, + { 10259, "E_SECH_2", "Bad argument for sech" }, + { 10260, "E_CSCH_1", "Bad epsilon for csch" }, + { 10261, "E_CSCH_2", "Bad argument for csch" }, + { 10262, "E_ASIN_1", "Bad epsilon for asin" }, + { 10263, "E_ASIN_2", "Bad argument for asin" }, + { 10264, "E_ACOS_1", "Bad epsilon for acos" }, + { 10265, "E_ACOS_2", "Bad argument for acos" }, + { 10266, "E_ATAN_1", "Bad epsilon for atan" }, + { 10267, "E_ATAN_2", "Bad argument for atan" }, + { 10268, "E_ACOT_1", "Bad epsilon for acot" }, + { 10269, "E_ACOT_2", "Bad argument for acot" }, + { 10270, "E_ASEC_1", "Bad epsilon for asec" }, + { 10271, "E_ASEC_2", "Bad argument for asec" }, + { 10272, "E_ACSC_1", "Bad epsilon for acsc" }, + { 10273, "E_ACSC_2", "Bad argument for acsc" }, + { 10274, "E_ASINH_1", "Bad epsilon for asin" }, + { 10275, "E_ASINH_2", "Bad argument for asinh" }, + { 10276, "E_ACOSH_1", "Bad epsilon for acosh" }, + { 10277, "E_ACOSH_2", "Bad argument for acosh" }, + { 10278, "E_ATANH_1", "Bad epsilon for atanh" }, + { 10279, "E_ATANH_2", "Bad argument for atanh" }, + { 10280, "E_ACOTH_1", "Bad epsilon for acoth" }, + { 10281, "E_ACOTH_2", "Bad argument for acoth" }, + { 10282, "E_ASECH_1", "UNUSED ERROR: Bad epsilon for asech" }, + { 10283, "E_ASECH_2", "Bad argument for asech" }, + { 10284, "E_ACSCH_1", "Bad epsilon for acsch" }, + { 10285, "E_ACSCH_2", "Bad argument for acsch" }, + { 10286, "E_GD_1", "Bad epsilon for gd" }, + { 10287, "E_GD_2", "Bad argument for gd" }, + { 10288, "E_AGD_1", "Bad epsilon for agd" }, + { 10289, "E_AGD_2", "Bad argument for agd" }, + { 10290, "E_LOGINF", "Log of zero or infinity" }, + { 10291, "E_STRADD", "String addition failure" }, + { 10292, "E_STRMUL", "String multiplication failure" }, + { 10293, "E_STRNEG", "String reversal failure" }, + { 10294, "E_STRSUB", "String subtraction failure" }, + { 10295, "E_BIT_1", "Bad argument type for bit" }, + { 10296, "E_BIT_2", "Index too large for bit" }, + { 10297, "E_SETBIT_1", "Non-integer second argument for setbit" }, + { 10298, "E_SETBIT_2", "Out-of-range index for setbit" }, + { 10299, "E_SETBIT_3", "Non-string first argument for setbit" }, + { 10300, "E_OR", "Bad argument for or" }, + { 10301, "E_AND", "Bad argument for and" }, + { 10302, "E_STROR", "Allocation failure for string or" }, + { 10303, "E_STRAND", "Allocation failure for string and" }, + { 10304, "E_XOR", "Bad argument for xorvalue" }, + { 10305, "E_COMP", "Bad argument for comp" }, + { 10306, "E_STRDIFF", "Allocation failure for string diff" }, + { 10307, "E_STRCOMP", "Allocation failure for string comp" }, + { 10308, "E_SEG_1", "Bad first argument for segment" }, + { 10309, "E_SEG_2", "Bad second argument for segment" }, + { 10310, "E_SEG_3", "Bad third argument for segment" }, + { 10311, "E_STRSEG", "Failure for string segment" }, + { 10312, "E_HIGHBIT_1", "Bad argument type for highbit" }, + { 10313, "E_HIGHBIT_2", "Non-integer argument for highbit" }, + { 10314, "E_LOWBIT_1", "Bad argument type for lowbit" }, + { 10315, "E_LOWBIT_2", "Non-integer argument for lowbit" }, + { 10316, "E_CONTENT", "Bad argument type for unary hash op" }, + { 10317, "E_HASHOP", "Bad argument type for binary hash op" }, + { 10318, "E_HEAD_1", "Bad first argument for head" }, + { 10319, "E_HEAD_2", "Bad second argument for head" }, + { 10320, "E_STRHEAD", "Failure for strhead" }, + { 10321, "E_TAIL_1", "Bad first argument for tail" }, + { 10322, "E_TAIL_2", "UNUSED ERROR: Bad second argument for tail" }, + { 10323, "E_STRTAIL", "Failure for strtail" }, + { 10324, "E_STRSHIFT", "Failure for strshift" }, + { 10325, "E_STRCMP", "Non-string argument for strcmp" }, + { 10326, "E_STRNCMP", "Bad argument type for strncmp" }, + { 10327, "E_XOR_1", "Varying types of argument for xor" }, + { 10328, "E_XOR_2", "Bad argument type for xor" }, + { 10329, "E_STRCPY", "Bad argument type for strcpy" }, + { 10330, "E_STRNCPY", "Bad argument type for strncpy" }, + { 10331, "E_BACKSLASH", "Bad argument type for unary backslash" }, + { 10332, "E_SETMINUS", "Bad argument type for setminus" }, + { 10333, "E_INDICES_1", "Bad first argument type for indices" }, + { 10334, "E_INDICES_2", "Bad second argument for indices" }, + { 10335, "E_EXP_3", "Too-large re(argument) for exp" }, + { 10336, "E_SINH_3", "Too-large re(argument) for sinh" }, + { 10337, "E_COSH_3", "Too-large re(argument) for cosh" }, + { 10338, "E_SIN_3", "Too-large im(argument) for sin" }, + { 10339, "E_COS_3", "Too-large im(argument) for cos" }, + { 10340, "E_GD_3", "Infinite or too-large result for gd" }, + { 10341, "E_AGD_3", "Infinite or too-large result for agd" }, + { 10342, "E_POWER_4", "Too-large value for power" }, + { 10343, "E_ROOT_4", "Too-large value for root" }, + { 10344, "E_DGT_1", "Non-real first arg for digit" }, + { 10345, "E_DGT_2", "Non-integral second arg for digit" }, + { 10346, "E_DGT_3", "Bad third arg for digit" }, + { 10347, "E_PLCS_1", "Bad first argument for places" }, + { 10348, "E_PLCS_2", "Bad second argument for places" }, + { 10349, "E_DGTS_1", "Bad first argument for digits" }, + { 10350, "E_DGTS_2", "Bad second argument for digits" }, + { 10351, "E_ILOG", "Bad first argument for ilog" }, + { 10352, "E_ILOGB", "Bad second argument for ilog" }, + { 10353, "E_IBASE10_LOG", "Bad argument for ilog10" }, + { 10354, "E_IBASE2_LOG", "Bad argument for ilog2" }, + { 10355, "E_COMB_1", "Non-integer second arg for comb" }, + { 10356, "E_COMB_2", "Too-large second arg for comb" }, + { 10357, "E_CTLN", "Bad argument for catalan" }, + { 10358, "E_BERN", "Bad argument for bern" }, + { 10359, "E_EULER", "Bad argument for euler" }, + { 10360, "E_SLEEP", "Bad argument for sleep" }, + { 10361, "E_TTY", "calc_tty failure" }, + { 10362, "E_ASSIGN_1", "No-copy-to destination for octet assign" }, + { 10363, "E_ASSIGN_2", "No-copy-from source for octet assign" }, + { 10364, "E_ASSIGN_3", "No-change destination for octet assign" }, + { 10365, "E_ASSIGN_4", "Non-variable destination for assign" }, + { 10366, "E_ASSIGN_5", "No-assign-to destination for assign" }, + { 10367, "E_ASSIGN_6", "No-assign-from source for assign" }, + { 10368, "E_ASSIGN_7", "No-change destination for assign" }, + { 10369, "E_ASSIGN_8", "No-type-change destination for assign" }, + { 10370, "E_ASSIGN_9", "No-error-value destination for assign" }, + { 10371, "E_SWAP_1", "No-copy argument for octet swap" }, + { 10372, "E_SWAP_2", "No-assign-to-or-from argument for swap" }, + { 10373, "E_SWAP_3", "Non-lvalue argument for swap" }, + { 10374, "E_QUOMOD_1", "Non-lvalue argument 3 or 4 for quomod" }, + { 10375, "E_QUOMOD_2", "Non-real-number arg 1 or 2 or bad arg 5 for quomod" }, + { 10376, "E_QUOMOD_3", "No-assign-to argument 3 or 4 for quomod" }, + { 10377, "E_PREINC_1", "No-copy-to or no-change argument for octet preinc" }, + { 10378, "E_PREINC_2", "Non-variable argument for preinc" }, + { 10379, "E_PREINC_3", "No-assign-to or no-change argument for preinc" }, + { 10380, "E_PREDEC_1", "No-copy-to or no-change argument for octet predec" }, + { 10381, "E_PREDEC_2", "Non-variable argument for predec" }, + { 10382, "E_PREDEC_3", "No-assign-to or no-change argument for predec" }, + { 10383, "E_POSTINC_1", "No-copy-to or no-change argument for octet postinc" }, + { 10384, "E_POSTINC_2", "Non-variable argument for postinc" }, + { 10385, "E_POSTINC_3", "No-assign-to or no-change argument for postinc" }, + { 10386, "E_POSTDEC_1", "No-copy-to or no-change argument for octet postdec" }, + { 10387, "E_POSTDEC_2", "Non-variable argument for postdec" }, + { 10388, "E_POSTDEC_3", "No-assign-to or no-change argument for postdec" }, + { 10389, "E_INIT_01", "Error-type structure for initialization" }, + { 10390, "E_INIT_02", "No-copy-to structure for initialization" }, + { 10391, "E_INIT_03", "Too many initializer values" }, + { 10392, "E_INIT_04", "Attempt to initialize freed named block" }, + { 10393, "E_INIT_05", "Bad structure type for initialization" }, + { 10394, "E_INIT_06", "No-assign-to element for initialization" }, + { 10395, "E_INIT_07", "No-change element for initialization" }, + { 10396, "E_INIT_08", "No-type-change element for initialization" }, + { 10397, "E_INIT_09", "No-error-value element for initialization" }, + { 10398, "E_INIT_10", "No-assign-or-copy-from source for initialization" }, + { 10399, "E_LIST_1", "No-relocate for list insert" }, + { 10400, "E_LIST_2", "No-relocate for list delete" }, + { 10401, "E_LIST_3", "No-relocate for list push" }, + { 10402, "E_LIST_4", "No-relocate for list append" }, + { 10403, "E_LIST_5", "No-relocate for list pop" }, + { 10404, "E_LIST_6", "No-relocate for list remove" }, + { 10405, "E_MODIFY_1", "Non-variable first argument for modify" }, + { 10406, "E_MODIFY_2", "Non-string second argument for modify" }, + { 10407, "E_MODIFY_3", "No-change first argument for modify" }, + { 10408, "E_MODIFY_4", "Undefined function for modify" }, + { 10409, "E_MODIFY_5", "Unacceptable type first argument for modify" }, + { 10410, "E_FPATHOPEN_1", "Non-string arguments for fpathopen" }, + { 10411, "E_FPATHOPEN_2", "Unrecognized mode for fpathopen" }, + { 10412, "E_LOG_1", "Bad epsilon argument for log" }, + { 10413, "E_LOG_2", "Non-numeric first argument for log" }, + { 10414, "E_LOG_3", "Cannot calculate log for this value" }, + { 10415, "E_FGETFILE_1", "Non-file argument for fgetfile" }, + { 10416, "E_FGETFILE_2", "File argument for fgetfile not open for reading" }, + { 10417, "E_FGETFILE_3", "Unable to set file position in fgetfile" }, + { 10418, "E_ESTR", "UNUSED ERROR: Non-representable type for estr" }, + { 10419, "E_STRCASECMP", "Non-string argument for strcasecmp" }, + { 10420, "E_STRNCASECMP", "Bad argument type for strncasecmp" }, + { 10421, "E_ISUPPER", "Bad argument for isupper" }, + { 10422, "E_ISLOWER", "Bad argument for islower" }, + { 10423, "E_ISALNUM", "Bad argument for isalnum" }, + { 10424, "E_ISALPHA", "Bad argument for isalpha" }, + { 10425, "E_ISASCII", "Bad argument for isascii" }, + { 10426, "E_ISCNTRL", "Bad argument for iscntrl" }, + { 10427, "E_ISDIGIT", "Bad argument for isdigit" }, + { 10428, "E_ISGRAPH", "Bad argument for isgraph" }, + { 10429, "E_ISPRINT", "Bad argument for isprint" }, + { 10430, "E_ISPUNCT", "Bad argument for ispunct" }, + { 10431, "E_ISSPACE", "Bad argument for isspace" }, + { 10432, "E_ISXDIGIT", "Bad argument for isxdigit" }, + { 10433, "E_STRTOUPPER", "Bad argument type for strtoupper" }, + { 10434, "E_STRTOLOWER", "Bad argument type for strtolower" }, + { 10435, "E_TAN_3", "UNUSED ERROR: Invalid value for calculating the sin numerator for tan" }, + { 10436, "E_TAN_4", "UNUSED ERROR: Invalid value for calculating the cos denominator for tan" }, + { 10437, "E_COT_3", "UNUSED ERROR: Invalid value for calculating the sin numerator for cot" }, + { 10438, "E_COT_4", "UNUSED ERROR: Invalid value for calculating the cos denominator for cot" }, + { 10439, "E_SEC_3", "UNUSED ERROR: Invalid value for calculating the cos reciprocal for sec" }, + { 10440, "E_CSC_3", "UNUSED ERROR: Invalid value for calculating the sin reciprocal for csc" }, + { 10441, "E_TANH_3", "Invalid value for calculating the sinh numerator for tanh" }, + { 10442, "E_TANH_4", "Invalid value for calculating the cosh denominator for tanh" }, + { 10443, "E_COTH_3", "Invalid value for calculating the sinh numerator for coth" }, + { 10444, "E_COTH_4", "Invalid value for calculating the cosh denominator for coth" }, + { 10445, "E_SECH_3", "Invalid value for calculating the cosh reciprocal for sech" }, + { 10446, "E_CSCH_3", "Invalid value for calculating the sinh reciprocal for csch" }, + { 10447, "E_ASIN_3", "Invalid value for calculating asin" }, + { 10448, "E_ACOS_3", "Invalid value for calculating acos" }, + { 10449, "E_ASINH_3", "Invalid value for calculating asinh" }, + { 10450, "E_ACOSH_3", "Invalid value for calculating acosn" }, + { 10451, "E_ATAN_3", "Invalid value for calculating atan" }, + { 10452, "E_ACOT_3", "Invalid value for calculating acot" }, + { 10453, "E_ASEC_3", "Invalid value for calculating asec" }, + { 10454, "E_ACSC_3", "Invalid value for calculating acsc" }, + { 10455, "E_ATANH_3", "Invalid value for calculating atan" }, + { 10456, "E_ACOTH_3", "Invalid value for calculating acot" }, + { 10457, "E_ASECH_3", "Invalid value for calculating asec" }, + { 10458, "E_ACSCH_3", "Invalid value for calculating acsc" }, + { 10459, "E_D2R_1", "Bad epsilon for converting degrees to radians" }, + { 10460, "E_D2R_2", "Bad first argument converting degrees to radians" }, + { 10461, "E_R2D_1", "Bad epsilon for converting radians to degrees" }, + { 10462, "E_R2D_2", "Bad first argument converting radians to degrees" }, + { 10463, "E_G2R_1", "Bad epsilon for converting gradians to radians" }, + { 10464, "E_G2R_2", "Bad first argument converting gradians to radians" }, + { 10465, "E_R2G_1", "Bad epsilon for converting radians to gradians" }, + { 10466, "E_R2G_2", "Bad first argument converting radians to gradians" }, + { 10467, "E_D2G_1", "Bad first argument converting degrees to gradians" }, + { 10468, "E_G2D_1", "Bad first argument converting gradians to degrees" }, + { 10469, "E_D2DMS_1", "Non-lvalue arguments 2, 3 or 4 for d2dms" }, + { 10470, "E_D2DMS_2", "Non-real-number arg 1 for d2dms" }, + { 10471, "E_D2DMS_3", "No-assign-to argument 2, 3 or 4 for d2dms" }, + { 10472, "E_D2DMS_4", "Invalid rounding arg 5 for d2dms" }, + { 10473, "E_D2DM_1", "Non-lvalue arguments 2 or 3 for d2dm" }, + { 10474, "E_D2DM_2", "Non-real-number arg 1 for d2dm" }, + { 10475, "E_D2DM_3", "No-assign-to argument 2 or 3 for d2dm" }, + { 10476, "E_D2DM_4", "Invalid rounding arg 4 for d2dm" }, + { 10477, "E_G2GMS_1", "Non-lvalue arguments 2, 3 or 4 for g2gms" }, + { 10478, "E_G2GMS_2", "Non-real-number arg 1 for g2gms" }, + { 10479, "E_G2GMS_3", "No-assign-to argument 2 or 3 for g2gms" }, + { 10480, "E_G2GMS_4", "Invalid rounding arg 5 for g2gms" }, + { 10481, "E_G2GM_1", "Non-lvalue arguments 2 or 3 for g2gm" }, + { 10482, "E_G2GM_2", "Non-real-number arg 1 for g2gm" }, + { 10483, "E_G2GM_3", "No-assign-to argument 2, 3 or 4 for g2gm" }, + { 10484, "E_G2GM_4", "Invalid rounding arg 4 for g2gm" }, + { 10485, "E_H2HMS_1", "Non-lvalue arguments 2, 3 or 4 for h2hms" }, + { 10486, "E_H2HMS_2", "Non-real-number arg 1 for h2hms" }, + { 10487, "E_H2HMS_3", "No-assign-to argument 2, 3 or 4 for h2hms" }, + { 10488, "E_H2HMS_4", "Invalid rounding arg 5 for h2hms" }, + { 10489, "E_H2HM_1", "Non-lvalue arguments 2 or 3 for h2hm" }, + { 10490, "E_H2HM_2", "Non-real-number arg 1 for h2hm" }, + { 10491, "E_H2HM_3", "No-assign-to argument 2 or 3 for h2hm" }, + { 10492, "E_H2HM_4", "Invalid rounding arg 4 for h2hm" }, + { 10493, "E_DMS2D_1", "Non-real-number arguments 1, 2 or 3 for dms2d" }, + { 10494, "E_DMS2D_2", "Invalid rounding arg 4 for dms2d" }, + { 10495, "E_DM2D_1", "Non-real-number arguments 1 or 2 for dm2d" }, + { 10496, "E_DM2D_2", "Invalid rounding arg 4 for dm2d" }, + { 10497, "E_GMS2G_1", "Non-real-number arguments 1, 2 or 3 for gms2g" }, + { 10498, "E_GMS2G_2", "Invalid rounding arg 4 for gms2g" }, + { 10499, "E_GM2G_1", "Non-real-number arguments 1 or 2 for gm2g" }, + { 10500, "E_GM2G_2", "Invalid rounding arg 4 for gm2g" }, + { 10501, "E_HMS2H_1", "Non-real-number arguments 1, 2 or 3 for hms2h" }, + { 10502, "E_HMS2H_2", "Invalid rounding arg 4 for hms2h" }, + { 10503, "E_HM2H_1", "UNUSED ERROR: Non-real-number arguments 1 or 2 for hm2h" }, + { 10504, "E_HM2H_2", "UNUSED ERROR: Invalid rounding arg 4 for hm2h" }, + { 10505, "E_LOG2_1", "Bad epsilon argument for log2" }, + { 10506, "E_LOG2_2", "Non-numeric first argument for log2" }, + { 10507, "E_LOG2_3", "Cannot calculate log2 for this value" }, + { 10508, "E_LOGN_1", "Bad epsilon argument for logn" }, + { 10509, "E_LOGN_2", "Non-numeric first argument for logn" }, + { 10510, "E_LOGN_3", "Cannot calculate logn for this value" }, + { 10511, "E_LOGN_4", "Cannot calculate logn for this log base" }, + { 10512, "E_LOGN_5", "Non-numeric second argument for logn" }, + { 10513, "E_VERSIN_1", "Bad epsilon for versin" }, + { 10514, "E_VERSIN_2", "Bad first argument for versin" }, + { 10515, "E_VERSIN_3", "Too-large im(argument) for versin" }, + { 10516, "E_AVERSIN_1", "Bad epsilon for aversin" }, + { 10517, "E_AVERSIN_2", "Bad first argument for aversin" }, + { 10518, "E_AVERSIN_3", "Too-large im(argument) for aversin" }, + { 10519, "E_COVERSIN_1", "Bad epsilon for coversin" }, + { 10520, "E_COVERSIN_2", "Bad first argument for coversin" }, + { 10521, "E_COVERSIN_3", "Too-large im(argument) for coversin" }, + { 10522, "E_ACOVERSIN_1", "Bad epsilon for acoversin" }, + { 10523, "E_ACOVERSIN_2", "Bad first argument for acoversin" }, + { 10524, "E_ACOVERSIN_3", "Too-large im(argument) for acoversin" }, + { 10525, "E_VERCOS_1", "Bad epsilon for vercos" }, + { 10526, "E_VERCOS_2", "Bad first argument for vercos" }, + { 10527, "E_VERCOS_3", "Too-large im(argument) for vercos" }, + { 10528, "E_AVERCOS_1", "Bad epsilon for avercos" }, + { 10529, "E_AVERCOS_2", "Bad first argument for avercos" }, + { 10530, "E_AVERCOS_3", "Too-large im(argument) for avercos" }, + { 10531, "E_COVERCOS_1", "Bad epsilon for covercos" }, + { 10532, "E_COVERCOS_2", "Bad first argument for covercos" }, + { 10533, "E_COVERCOS_3", "Too-large im(argument) for covercos" }, + { 10534, "E_ACOVERCOS_1", "Bad epsilon for acovercos" }, + { 10535, "E_ACOVERCOS_2", "Bad first argument for acovercos" }, + { 10536, "E_ACOVERCOS_3", "Too-large im(argument) for acovercos" }, + { 10537, "E_TAN_5", "Invalid complex argument for tan" }, + { 10538, "E_COT_5", "Invalid zero argument for cot" }, + { 10539, "E_COT_6", "Invalid complex argument for cot" }, + { 10540, "E_SEC_5", "Invalid complex argument for sec" }, + { 10541, "E_CSC_5", "Invalid zero argument for csc" }, + { 10542, "E_CSC_6", "Invalid complex argument for csc" }, + { 10543, "E_ERROR_3", "String argument is not a valid E_STRING for error" }, + { 10544, "E_ERROR_4", "Numeric argument is not an integer for error" }, + { 10545, "E_STRERROR_3", "String argument is not a valid E_STRING for strerror" }, + { 10546, "E_STRERROR_4", "errnum_2_errmsg returned NULL as called from strerror" }, + { 10547, "E_STRERROR_5", "Numeric argument is not an integer for strerror" }, + { 10548, "E_ERRNO_1", "Invalid argument type for errno" }, + { 10549, "E_ERRNO_2", "Numeric argument is outside valid errnum range for errno" }, + { 10550, "E_ERRNO_3", "String argument is not a valid E_STRING for errno" }, + { 10551, "E_ERRNO_4", "Numeric argument is not an integer for errno" }, + { 10552, "E_ERRSYM_1", "Invalid argument type for errsym" }, + { 10553, "E_ERRSYM_2", "Numeric argument is outside valid errnum range for errsym" }, + { 10554, "E_ERRSYM_3", "String argument is not a valid E_STRING for errsym" }, + { 10555, "E_ERRSYM_4", "Numeric argument is not an integer for errsym" }, + { 10556, "E_ERRSYM_5", "Unable to create a valid E_STRING from the errnum for errsym" }, + { 10557, "E_HAVERSIN_1", "Bad epsilon for haversin" }, + { 10558, "E_HAVERSIN_2", "Bad first argument for haversin" }, + { 10559, "E_HAVERSIN_3", "Too-large im(argument) for haversin" }, + { 10560, "E_AHAVERSIN_1", "Bad epsilon for ahaversin" }, + { 10561, "E_AHAVERSIN_2", "Bad first argument for ahaversin" }, + { 10562, "E_AHAVERSIN_3", "Too-large im(argument) for ahaversin" }, + { 10563, "E_HACOVERSIN_1", "Bad epsilon for hacoversin" }, + { 10564, "E_HACOVERSIN_2", "Bad first argument for hacoversin" }, + { 10565, "E_HACOVERSIN_3", "Too-large im(argument) for hacoversin" }, + { 10566, "E_AHACOVERSIN_1", "Bad epsilon for ahacoversin" }, + { 10567, "E_AHACOVERSIN_2", "Bad first argument for achaoversin" }, + { 10568, "E_AHACOVERSIN_3", "Too-large im(argument) for ahacoversin" }, + { 10569, "E_HAVERCOS_1", "Bad epsilon for havercos" }, + { 10570, "E_HAVERCOS_2", "Bad first argument for havercos" }, + { 10571, "E_HAVERCOS_3", "Too-large im(argument) for havercos" }, + { 10572, "E_AHAVERCOS_1", "Bad epsilon for ahavercos" }, + { 10573, "E_AHAVERCOS_2", "Bad first argument for ahavercos" }, + { 10574, "E_AHAVERCOS_3", "Too-large im(argument) for ahavercos" }, + { 10575, "E_HACOVERCOS_1", "Bad epsilon for hacovercos" }, + { 10576, "E_HACOVERCOS_2", "Bad first argument for hacovercos" }, + { 10577, "E_HACOVERCOS_3", "Too-large im(argument) for hacovercos" }, + { 10578, "E_AHACOVERCOS_1", "Bad epsilon for ahacovercos" }, + { 10579, "E_AHACOVERCOS_2", "Bad first argument for achaovercos" }, + { 10580, "E_AHACOVERCOS_3", "Too-large im(argument) for ahacovercos" }, + { 10581, "E_EXSEC_1", "Bad epsilon for exsec" }, + { 10582, "E_EXSEC_2", "Bad argument for exsec" }, + { 10583, "E_EXSEC_3", "Invalid complex argument for exsec" }, + { 10584, "E_AEXSEC_1", "Bad epsilon for aexsec" }, + { 10585, "E_AEXSEC_2", "Bad argument for aexsec" }, + { 10586, "E_AEXSEC_3", "Invalid value for calculating aexsec" }, + { 10587, "E_EXCSC_1", "Bad epsilon for excsc" }, + { 10588, "E_EXCSC_2", "Bad argument for excsc" }, + { 10589, "E_EXCSC_3", "Invalid zero argument for excsc" }, + { 10590, "E_EXCSC_4", "Invalid complex argument for excsc" }, + { 10591, "E_AEXCSC_1", "Bad epsilon for aexcsc" }, + { 10592, "E_AEXCSC_2", "Bad argument for aexcsc" }, + { 10593, "E_AEXCSC_3", "Invalid value for calculating aexcsc" }, + { 10594, "E_CRD_1", "Bad epsilon for crd" }, + { 10595, "E_CRD_2", "Bad argument for crd" }, + { 10596, "E_CRD_3", "Invalid complex argument for crd" }, + { 10597, "E_ACRD_1", "Bad epsilon for acrd" }, + { 10598, "E_ACRD_2", "Bad argument for acrd" }, + { 10599, "E_ACRD_3", "Invalid value for calculating acrd" }, + { 10600, "E_CAS_1", "Bad epsilon for cas" }, + { 10601, "E_CAS_2", "Bad argument for cas" }, + { 10602, "E_CAS_3", "Invalid complex argument for cas" }, + { 10603, "E_CIS_1", "Non-real epsilon for cis" }, + { 10604, "E_CIS_2", "Bad first argument for cis" }, + { 10605, "E_CIS_3", "Too-large re(argument) for cis" }, + { 10606, "E_LN_3", "Cannot calculate ln of 0" }, + { 10607, "E_LOG_5", "Cannot calculate log of 0" }, + { 10608, "E_LOG2_4", "Cannot calculate log base 2 of 0" }, + { 10609, "E_LOGN_6", "Cannot calculate log base n of 0" }, + /* IMPORTANT NOTE: add new entries above here and be sure their errnum numeric value is consecutive! */ - /* The next NULL entry must be last */ - { NULL_ERRNUM, NULL, NULL } + /* The next NULL entry must be last */ + { NULL_ERRNUM, NULL, NULL } }; @@ -780,30 +780,30 @@ CONST struct errtbl error_table[] = * * In this table the E_STRING related errsym must match the regular expression: * - * ^E__[A-Z][A-Z0-9_]+$ + * ^E__[A-Z][A-Z0-9_]+$ * * IMPORTANT: DO NOT ADD NEW calc computation TO THIS TABLE!!! - * Add new calc computation to the error_table[] above. + * Add new calc computation to the error_table[] above. */ STATIC struct errtbl private_error_alias[] = { - /* The E__NONE entry below must start with E__NONE (0) and must be first!! */ - { E__NONE, "E__NONE", "calc_errno cleared: libc errno codes above here" }, - { E__BASE, "E__BASE", "calc computation error codes start above here" }, - /* In the next E__HIGHEST entry, errnum and errmsg are changed when verify_error_table() is called */ - { INV_ERRNUM, "E__HIGHEST", "replace this with the E__HIGHEST errmsg" }, - { E__USERDEF, "E__USERDEF", "user defined error codes start here" }, - { E__USERMAX, "E__USERMAX", "maximum user defined error code" }, + /* The E__NONE entry below must start with E__NONE (0) and must be first!! */ + { E__NONE, "E__NONE", "calc_errno cleared: libc errno codes above here" }, + { E__BASE, "E__BASE", "calc computation error codes start above here" }, + /* In the next E__HIGHEST entry, errnum and errmsg are changed when verify_error_table() is called */ + { INV_ERRNUM, "E__HIGHEST", "replace this with the E__HIGHEST errmsg" }, + { E__USERDEF, "E__USERDEF", "user defined error codes start here" }, + { E__USERMAX, "E__USERMAX", "maximum user defined error code" }, - /* The next NULL entry must be last */ - { NULL_ERRNUM, NULL, NULL } + /* The next NULL entry must be last */ + { NULL_ERRNUM, NULL, NULL } }; /* * external values */ -EXTERN char *program; /* our name */ +EXTERN char *program; /* our name */ /* @@ -811,7 +811,7 @@ EXTERN char *program; /* our name */ * * This function determines of errsym matches the regular expression: * - * ^E_[0-9][0-9]*$ + * ^E_[0-9][0-9]*$ * * There is NO attempt to determine if the number type of digits * that follow the E_ forms a valid numeric E_STRING. @@ -819,51 +819,51 @@ EXTERN char *program; /* our name */ * NOTE: See also e_digits_2_errnum() below. * * given: - * errsym E_STRING to check + * errsym E_STRING to check * * returns: - * true ==> E_STRING is of the form E_ followed by digits - * false ==> E_STRING is NULL and/or not E_ followed by digits + * true ==> E_STRING is of the form E_ followed by digits + * false ==> E_STRING is NULL and/or not E_ followed by digits */ bool is_e_digits(CONST char *errsym) { - CONST char *p; + CONST char *p; - /* - * firewall - */ - if (errsym == NULL) { - return false; - } + /* + * firewall + */ + if (errsym == NULL) { + return false; + } - /* - * must start with E_ - */ - if (strncmp(errsym, "E_", 2) != 0) { - return false; - } + /* + * must start with E_ + */ + if (strncmp(errsym, "E_", 2) != 0) { + return false; + } - /* - * length must be >= 3 - */ - if (errsym[2] == '\0') { - return false; - } + /* + * length must be >= 3 + */ + if (errsym[2] == '\0') { + return false; + } - /* - * check for only digits remaining - */ - for (p = errsym+2; *p != '\0'; ++p) { - if (!isascii((int)*p) || !isdigit((int)*p)) { - return false; - } - } + /* + * check for only digits remaining + */ + for (p = errsym+2; *p != '\0'; ++p) { + if (!isascii((int)*p) || !isdigit((int)*p)) { + return false; + } + } - /* - * errsym matches: ^E_[0-9][0-9]*$ - */ - return true; + /* + * errsym matches: ^E_[0-9][0-9]*$ + */ + return true; } @@ -872,32 +872,32 @@ is_e_digits(CONST char *errsym) * * A valid errnum must be: * - * E__NONE <= errnum <= E__USERMAX + * E__NONE <= errnum <= E__USERMAX * * NOTE: This functions does NOT check of the errnum is in * some struct errtbl array. For that see find_errsym_in_errtbl(). * * given: - * errnum errnum to check + * errnum errnum to check * * returns: - * true ==> errnum is valid - * false ==> errnum is NOT valid + * true ==> errnum is valid + * false ==> errnum is NOT valid */ bool is_valid_errnum(int errnum) { - /* - * check for range - */ - if (errnum < E__NONE) { - return false; - } - if (errnum > E__USERMAX) { - return false; - } - /* errnum is valid */ - return true; + /* + * check for range + */ + if (errnum < E__NONE) { + return false; + } + if (errnum > E__USERMAX) { + return false; + } + /* errnum is valid */ + return true; } @@ -909,40 +909,40 @@ is_valid_errnum(int errnum) * lookup within the error_table[] array, only a errnum value range check. * * returns: - * true ==> errnum falls within the error_table[] array bounds - * false ==> errnum does NOT fall within the error_table[] array bounds + * true ==> errnum falls within the error_table[] array bounds + * false ==> errnum does NOT fall within the error_table[] array bounds */ bool is_errnum_in_error_table(int errnum) { - /* - * firewall - errnum must be valid - */ - if (is_valid_errnum(errnum) == false) { - /* errnum is not a valid value */ - return false; - } + /* + * firewall - errnum must be valid + */ + if (is_valid_errnum(errnum) == false) { + /* errnum is not a valid value */ + return false; + } - /* - * case: errnum is too low for error_table[] array - */ - if (errnum < E__BASE) { - /* errnum is too low */ - return false; - } + /* + * case: errnum is too low for error_table[] array + */ + if (errnum < E__BASE) { + /* errnum is too low */ + return false; + } - /* - * case: errnum is too high for error_table[] array - */ - if ((unsigned long)errnum > MY_E__HIGHEST) { - /* errnum is too high */ - return false; - } + /* + * case: errnum is too high for error_table[] array + */ + if ((unsigned long)errnum > MY_E__HIGHEST) { + /* errnum is too high */ + return false; + } - /* - * return error_table[] array matching the errnum value - */ - return true; + /* + * return error_table[] array matching the errnum value + */ + return true; } @@ -951,88 +951,88 @@ is_errnum_in_error_table(int errnum) * * Given an E_STRING errsym matching the regular expression: * - * ^E_[0-9][0-9]*$ + * ^E_[0-9][0-9]*$ * * this function attempts to convert those digits into an errnum, and * if successful, that the resulting errnum is valid: * - * E__NONE <= errnum <= E__USERMAX + * E__NONE <= errnum <= E__USERMAX * * NOTE: Leading zeros in digits are not allowed. So the E_STRING errsym - * must match the regular expression: + * must match the regular expression: * - * ^(0|[1-9][0-9]*)$ + * ^(0|[1-9][0-9]*)$ * * This function calls is_e_digits() first to determine that E_STRING * is E_ followed by digits. * * given: - * errsym E_STRING to convert + * errsym E_STRING to convert * * returns: - * == NULL_ERRNUM ==> errsym is NULL, or not E_STRING of digits, or - * the resulting errnum would be invald - * != NULL_ERRNUM == valid errnum corresponding to errsym + * == NULL_ERRNUM ==> errsym is NULL, or not E_STRING of digits, or + * the resulting errnum would be invald + * != NULL_ERRNUM == valid errnum corresponding to errsym */ int e_digits_2_errnum(CONST char *errsym) { - long errnum; /* digits converted into a possible errnum */ + long errnum; /* digits converted into a possible errnum */ - /* - * firewall - */ - if (errsym == NULL) { - /* errsym is NULL */ - return NULL_ERRNUM; - } + /* + * firewall + */ + if (errsym == NULL) { + /* errsym is NULL */ + return NULL_ERRNUM; + } - /* - * must be an E_STRING of digits - */ - if (is_e_digits(errsym) == false) { - /* errsym doesn't match: ^E_[0-9][0-9]*$ */ - return NULL_ERRNUM; - } + /* + * must be an E_STRING of digits + */ + if (is_e_digits(errsym) == false) { + /* errsym doesn't match: ^E_[0-9][0-9]*$ */ + return NULL_ERRNUM; + } - /* - * case: for E_0, return E__NONE - */ - if (strcmp(errsym, "E_0") == 0) { - /* quick return for E_0 */ - return E__NONE; - } + /* + * case: for E_0, return E__NONE + */ + if (strcmp(errsym, "E_0") == 0) { + /* quick return for E_0 */ + return E__NONE; + } - /* - * errnum is not E_0, digits cannot start with "0" - */ - if (errsym[2] == '0') { - /* digits cannot start with 0 unless it is E_0 */ - return NULL_ERRNUM; - } + /* + * errnum is not E_0, digits cannot start with "0" + */ + if (errsym[2] == '0') { + /* digits cannot start with 0 unless it is E_0 */ + return NULL_ERRNUM; + } - /* - * try to convert digits into long - */ - errno = 0; - errnum = strtol(errsym+2, NULL, 10); - if (errno != 0) { - /* failed to convert digits in base 10 */ - return NULL_ERRNUM; - } + /* + * try to convert digits into long + */ + errno = 0; + errnum = strtol(errsym+2, NULL, 10); + if (errno != 0) { + /* failed to convert digits in base 10 */ + return NULL_ERRNUM; + } - /* - * errnum, to be valid, just be in the range [E__NONE,E__USERMAX] - */ - if (is_valid_errnum(errnum) == false) { - /* errnum is out of range */ - return NULL_ERRNUM; - } + /* + * errnum, to be valid, just be in the range [E__NONE,E__USERMAX] + */ + if (is_valid_errnum(errnum) == false) { + /* errnum is out of range */ + return NULL_ERRNUM; + } - /* - * return converted errnum - */ - return errnum; + /* + * return converted errnum + */ + return errnum; } @@ -1041,64 +1041,64 @@ e_digits_2_errnum(CONST char *errsym) * * This function determines of errsym matches the regular expression: * - * ^E_[A-Z][A-Z0-9_]+$ + * ^E_[A-Z][A-Z0-9_]+$ * * This function will not match the special E_STRING is of the form E__ followed by * letters and digits and underscores. For that see is_e_2string(). * * given: - * errsym E_STRING to check + * errsym E_STRING to check * * returns: - * true ==> E_STRING matches the regular expression: ^E_[A-Z][A-Z0-9_]+$ - * false ==> E_STRING is NULL and/or does not match expression: ^E_[A-Z][A-Z0-9_]+$ + * true ==> E_STRING matches the regular expression: ^E_[A-Z][A-Z0-9_]+$ + * false ==> E_STRING is NULL and/or does not match expression: ^E_[A-Z][A-Z0-9_]+$ */ bool is_e_1string(CONST char *errsym) { - CONST char *p; + CONST char *p; - /* - * firewall - */ - if (errsym == NULL) { - return false; - } + /* + * firewall + */ + if (errsym == NULL) { + return false; + } - /* - * must start with E_ - */ - if (strncmp(errsym, "E_", 2) != 0) { - return false; - } + /* + * must start with E_ + */ + if (strncmp(errsym, "E_", 2) != 0) { + return false; + } - /* - * length must be >= 3 - */ - if (errsym[2] == '\0') { - return false; - } + /* + * length must be >= 3 + */ + if (errsym[2] == '\0') { + return false; + } - /* - * errsym, after E_, must be an UPPER case letter - */ - if (!isascii(errsym[2]) || !isupper(errsym[2])) { - return false; - } + /* + * errsym, after E_, must be an UPPER case letter + */ + if (!isascii(errsym[2]) || !isupper(errsym[2])) { + return false; + } - /* - * must match regular expression: ^E_[A-Z][A-Z0-9_]+$ - */ - for (p = errsym+3; *p != '\0'; ++p) { - if (!isascii((int)*p) || !(isupper((int)*p) || isdigit((int)*p) || *p == '_')) { - return false; - } - } + /* + * must match regular expression: ^E_[A-Z][A-Z0-9_]+$ + */ + for (p = errsym+3; *p != '\0'; ++p) { + if (!isascii((int)*p) || !(isupper((int)*p) || isdigit((int)*p) || *p == '_')) { + return false; + } + } - /* - * errsym matches: ^E_[A-Z][A-Z0-9_]+$ - */ - return true; + /* + * errsym matches: ^E_[A-Z][A-Z0-9_]+$ + */ + return true; } @@ -1107,64 +1107,64 @@ is_e_1string(CONST char *errsym) * * This function determines of errsym matches the regular expression: * - * ^E__[A-Z][A-Z0-9_]+$ + * ^E__[A-Z][A-Z0-9_]+$ * * This function will not match the special E_STRING is of the form E_ followed by * letters and digits and underscores. For that see is_e_1string(). * * given: - * errsym E_STRING to check + * errsym E_STRING to check * * returns: - * true ==> E_STRING matches the regular expression: ^E__[A-Z][A-Z0-9_]+$ - * false ==> E_STRING is NULL and/or does not match expression: ^E__[A-Z][A-Z0-9_]+$ + * true ==> E_STRING matches the regular expression: ^E__[A-Z][A-Z0-9_]+$ + * false ==> E_STRING is NULL and/or does not match expression: ^E__[A-Z][A-Z0-9_]+$ */ bool is_e_2string(CONST char *errsym) { - CONST char *p; + CONST char *p; - /* - * firewall - */ - if (errsym == NULL) { - return false; - } + /* + * firewall + */ + if (errsym == NULL) { + return false; + } - /* - * must start with E_ - */ - if (strncmp(errsym, "E__", 3) != 0) { - return false; - } + /* + * must start with E_ + */ + if (strncmp(errsym, "E__", 3) != 0) { + return false; + } - /* - * length must be >= 4 - */ - if (errsym[3] == '\0') { - return false; - } + /* + * length must be >= 4 + */ + if (errsym[3] == '\0') { + return false; + } - /* - * errsym, after E__, must be an UPPER case letter - */ - if (!isascii(errsym[3]) || !isupper(errsym[3])) { - return false; - } + /* + * errsym, after E__, must be an UPPER case letter + */ + if (!isascii(errsym[3]) || !isupper(errsym[3])) { + return false; + } - /* - * must match regular expression: ^E__[A-Z][A-Z0-9_]+$ - */ - for (p = errsym+4; *p != '\0'; ++p) { - if (!isascii(*p) || !(isupper(*p) || isdigit(*p) || *p == '_')) { - return false; - } - } + /* + * must match regular expression: ^E__[A-Z][A-Z0-9_]+$ + */ + for (p = errsym+4; *p != '\0'; ++p) { + if (!isascii(*p) || !(isupper(*p) || isdigit(*p) || *p == '_')) { + return false; + } + } - /* - * errsym matches: ^E__[A-Z][A-Z0-9_]+$ - */ - return true; + /* + * errsym matches: ^E__[A-Z][A-Z0-9_]+$ + */ + return true; } @@ -1172,37 +1172,37 @@ is_e_2string(CONST char *errsym) * find_errsym_in_errtbl - given an E_STRING find it in a struct errtbl array * * given: - * errsym E_STRING to check - * tbl pointer to a NULL an array of struct errtbl with a final NULL entry + * errsym E_STRING to check + * tbl pointer to a NULL an array of struct errtbl with a final NULL entry * * returns: - * != NULL ==> pointer to entry in tbl struct errtbl entry with matching errsym - * NULL ==> NULL arg, or errsym not found + * != NULL ==> pointer to entry in tbl struct errtbl entry with matching errsym + * NULL ==> NULL arg, or errsym not found */ struct errtbl * find_errsym_in_errtbl(CONST char *errsym, CONST struct errtbl *tbl) { - CONST struct errtbl *ret; /* pointer to struct errtbl entry with matching errsym */ + CONST struct errtbl *ret; /* pointer to struct errtbl entry with matching errsym */ - /* - * firewall - */ - if (errsym == NULL || tbl == NULL) { - /* invalid NULL arg(s) */ - return NULL; - } + /* + * firewall + */ + if (errsym == NULL || tbl == NULL) { + /* invalid NULL arg(s) */ + return NULL; + } - /* - * scan tbl until final NULL entry - */ - for (ret = tbl; ret->errsym != NULL; ++ret) { - if (strcmp(ret->errsym, errsym) == 0) { - /* found matching errsym */ - return (struct errtbl *)ret; - } - } - /* no match */ - return NULL; + /* + * scan tbl until final NULL entry + */ + for (ret = tbl; ret->errsym != NULL; ++ret) { + if (strcmp(ret->errsym, errsym) == 0) { + /* found matching errsym */ + return (struct errtbl *)ret; + } + } + /* no match */ + return NULL; } @@ -1215,52 +1215,52 @@ find_errsym_in_errtbl(CONST char *errsym, CONST struct errtbl *tbl) * * See also lookup_errnum_in_error_table() for a faster way to do: * - * find_errnum_in_errtbl(errnum, error_table); (* use lookup_errnum_in_error_table() instead *) + * find_errnum_in_errtbl(errnum, error_table); (* use lookup_errnum_in_error_table() instead *) * * given: - * errnum the errnum code to seach for - * tbl pointer to a NULL an array of struct errtbl with a final NULL entry + * errnum the errnum code to seach for + * tbl pointer to a NULL an array of struct errtbl with a final NULL entry * * returns: - * != NULL ==> pointer to entry in tbl struct errtbl entry with matching - * NULL ==> NULL arg, or matching errnum not foun + * != NULL ==> pointer to entry in tbl struct errtbl entry with matching + * NULL ==> NULL arg, or matching errnum not foun */ struct errtbl * find_errnum_in_errtbl(int errnum, CONST struct errtbl *tbl) { - CONST struct errtbl *ret; /* pointer to struct errtbl entry with matching errsym */ + CONST struct errtbl *ret; /* pointer to struct errtbl entry with matching errsym */ - /* - * firewall - */ - if (tbl == NULL) { - /* invalid NULL arg */ - return NULL; - } - if (is_valid_errnum(errnum) == false) { - /* invalid errnum */ - return NULL; - } + /* + * firewall + */ + if (tbl == NULL) { + /* invalid NULL arg */ + return NULL; + } + if (is_valid_errnum(errnum) == false) { + /* invalid errnum */ + return NULL; + } - /* - * scan tbl until final NULL entry - */ - for (ret = tbl; ret->errsym != NULL; ++ret) { + /* + * scan tbl until final NULL entry + */ + for (ret = tbl; ret->errsym != NULL; ++ret) { - /* case: found errnum match */ - if (ret->errnum == errnum) { - /* found matching errnum */ - return (struct errtbl *)ret; - } + /* case: found errnum match */ + if (ret->errnum == errnum) { + /* found matching errnum */ + return (struct errtbl *)ret; + } - /* case: we passed errnum in struct errtbl array */ - if (ret->errnum > errnum) { - /* we have searched beyond errnum: everthing else is > errnum */ - return NULL; - } - } - /* no match */ - return NULL; + /* case: we passed errnum in struct errtbl array */ + if (ret->errnum > errnum) { + /* we have searched beyond errnum: everthing else is > errnum */ + return NULL; + } + } + /* no match */ + return NULL; } @@ -1273,55 +1273,55 @@ find_errnum_in_errtbl(int errnum, CONST struct errtbl *tbl) * * This function performs the equivalent of: * - * find_errnum_in_errtbl(errnum, error_table); (* use lookup_errnum_in_error_table() instead *) + * find_errnum_in_errtbl(errnum, error_table); (* use lookup_errnum_in_error_table() instead *) * * given: - * errnum the errnum code to seach for + * errnum the errnum code to seach for * * returns: - * != NULL ==> pointer to entry in error_table[] array with matching errnum - * NULL ==> NULL arg, or no matching errnum in error_table[] array + * != NULL ==> pointer to entry in error_table[] array with matching errnum + * NULL ==> NULL arg, or no matching errnum in error_table[] array */ CONST struct errtbl * lookup_errnum_in_error_table(int errnum) { - CONST struct errtbl *ret; /* pointer to struct errtbl entry with matching errsym */ - int offset; /* offset within the error_table[] array */ + CONST struct errtbl *ret; /* pointer to struct errtbl entry with matching errsym */ + int offset; /* offset within the error_table[] array */ - /* - * firewall - errnum must be valid - */ - if (is_errnum_in_error_table(errnum) == false) { - /* errnum is not a valid or not within the error_table[] array range */ - return NULL; - } + /* + * firewall - errnum must be valid + */ + if (is_errnum_in_error_table(errnum) == false) { + /* errnum is not a valid or not within the error_table[] array range */ + return NULL; + } - /* - * paranoia - */ - if (errnum < E__BASE || errnum > (long)MY_E__HIGHEST) { - /* errnum is outside of the error_table[] array range */ - return NULL; - } - offset = errnum - E__BASE; - if (offset < 0 || offset > (long)(sizeof(error_table)/sizeof(error_table[0]))) { - /* offset is outside of the error_table[] array */ - return NULL; - } + /* + * paranoia + */ + if (errnum < E__BASE || errnum > (long)MY_E__HIGHEST) { + /* errnum is outside of the error_table[] array range */ + return NULL; + } + offset = errnum - E__BASE; + if (offset < 0 || offset > (long)(sizeof(error_table)/sizeof(error_table[0]))) { + /* offset is outside of the error_table[] array */ + return NULL; + } - /* - * fetch entry from error_table[] array that should have the errnum value - */ - ret = &error_table[offset]; - if (ret->errnum != errnum) { - /* error_table[] entry has the wrong errnum */ - return NULL; - } + /* + * fetch entry from error_table[] array that should have the errnum value + */ + ret = &error_table[offset]; + if (ret->errnum != errnum) { + /* error_table[] entry has the wrong errnum */ + return NULL; + } - /* - * return error_table[] array matching the errnum value - */ - return ret; + /* + * return error_table[] array matching the errnum value + */ + return ret; } @@ -1330,334 +1330,334 @@ lookup_errnum_in_error_table(int errnum) * * For error_table[]: * - * The errnum must start with E__BASE and be consecutive until the final entry. + * The errnum must start with E__BASE and be consecutive until the final entry. * - * With the exception of the 1st "E__BASE" entry, the errsym must be a non-NULL string that - * matches, up until the last entry, the regular expression: + * With the exception of the 1st "E__BASE" entry, the errsym must be a non-NULL string that + * matches, up until the last entry, the regular expression: * - * ^E_[A-Z][A-Z0-9_]+$ + * ^E_[A-Z][A-Z0-9_]+$ * - * The errmsg must be a non-NULL non-empty string until the last entry. + * The errmsg must be a non-NULL non-empty string until the last entry. * - * The final entry must have an errnum of NULL_ERRNUM (-1), errsym of NULL and errmsg of NULL. + * The final entry must have an errnum of NULL_ERRNUM (-1), errsym of NULL and errmsg of NULL. * * For private_error_alias[]: * - * This function also verifies the private_error_alias[] array. + * This function also verifies the private_error_alias[] array. * - * With the exception of the last entry, the errsym must be a non-NULL string that - * matches regular expression: + * With the exception of the last entry, the errsym must be a non-NULL string that + * matches regular expression: * - * ^E__[A-Z][A-Z0-9_]+$ + * ^E__[A-Z][A-Z0-9_]+$ * - * The errmsg of the E__HIGHEST errsym entry points to the - * corresponding error_table[] entry's MY_E__HIGHEST errsym - * so that E__HIGHEST becomes an alias for the highest assigned - * calc computation error code. + * The errmsg of the E__HIGHEST errsym entry points to the + * corresponding error_table[] entry's MY_E__HIGHEST errsym + * so that E__HIGHEST becomes an alias for the highest assigned + * calc computation error code. * - * The errmsg must be a non-NULL non-empty string until the last entry. + * The errmsg must be a non-NULL non-empty string until the last entry. * - * The final entry must have an errnum of NULL_ERRNUM (-1), errsym of NULL and errmsg of NULL. + * The final entry must have an errnum of NULL_ERRNUM (-1), errsym of NULL and errmsg of NULL. * * This function does not return on error or if the error_table is invalid. * * Use the seqcexit tool to keep the exit codes for this function unique, starting with 10. * Apply the following command in this soure code: * - * seqcexit errtbl.c + * seqcexit errtbl.c * * For more information on the seqcexit tool, see: * - * https://github.com/lcn2/seqcexit + * https://github.com/lcn2/seqcexit */ void verify_error_table(void) { - size_t len; /* length of the error_table[] */ - size_t e__count; /* computed ECOUNT value */ - size_t priv_len; /* length of the private_error_alias[] */ - size_t priv_e__count; /* computed MY_PRIV_ECOUNT value */ - struct errtbl *found; /* pointer to E__HIGHEST errsym entry in private_error_alias[] or NULL */ - int prev_errnum; /* previous errnum found in private_error_alias[] */ - long ten; /* used to try an compute 10^USERMAX_DIGITS */ - VALUE test; /* value to test if E__USERMAX fits into a v_type */ - size_t i; + size_t len; /* length of the error_table[] */ + size_t e__count; /* computed ECOUNT value */ + size_t priv_len; /* length of the private_error_alias[] */ + size_t priv_e__count; /* computed MY_PRIV_ECOUNT value */ + struct errtbl *found; /* pointer to E__HIGHEST errsym entry in private_error_alias[] or NULL */ + int prev_errnum; /* previous errnum found in private_error_alias[] */ + long ten; /* used to try an compute 10^USERMAX_DIGITS */ + VALUE test; /* value to test if E__USERMAX fits into a v_type */ + size_t i; - /* - * verify error_table[] size - */ - len = sizeof(error_table) / sizeof(error_table[0]); - e__count = len - 2; - if (e__count != MY_ECOUNT) { - fprintf(stderr, "**** %s ERROR: error_table length: %zu != MY_ECOUNT+2: %lu\n", - program, len, (unsigned long)MY_ECOUNT+2); - exit(10); /*coo*/ - } + /* + * verify error_table[] size + */ + len = sizeof(error_table) / sizeof(error_table[0]); + e__count = len - 2; + if (e__count != MY_ECOUNT) { + fprintf(stderr, "**** %s ERROR: error_table length: %zu != MY_ECOUNT+2: %lu\n", + program, len, (unsigned long)MY_ECOUNT+2); + exit(10); /*coo*/ + } - /* - * verify the initial errnum of the 1st error_table[] entry - */ - if (error_table[0].errnum != E__BASE) { - fprintf(stderr, "**** %s ERROR: initial entry error_table[0].errnum: %d must == E__BASE: %d\n", - program, error_table[0].errnum, E__BASE); - exit(11); - } - if (error_table[0].errsym == NULL) { - fprintf(stderr, "**** %s ERROR: error_table[0].errsym must != NULL\n", - program); - exit(12); - } - if (strcmp(error_table[0].errsym, "E__BASE") != 0) { - fprintf(stderr, "**** %s ERROR: error_table[0].errsym: %s must be E__BASE\n", - program, error_table[0].errsym); - exit(13); - } - if (error_table[0].errmsg == NULL) { - fprintf(stderr, "**** %s ERROR: error_table[0].errmsg must != NULL\n", - program); - exit(14); - } - if (strlen(error_table[0].errmsg) <= 0) { - fprintf(stderr, "**** %s ERROR: error_table[0].errmsg length: %zu must be > 0\n", - program, strlen(error_table[0].errmsg)); - exit(15); - } + /* + * verify the initial errnum of the 1st error_table[] entry + */ + if (error_table[0].errnum != E__BASE) { + fprintf(stderr, "**** %s ERROR: initial entry error_table[0].errnum: %d must == E__BASE: %d\n", + program, error_table[0].errnum, E__BASE); + exit(11); + } + if (error_table[0].errsym == NULL) { + fprintf(stderr, "**** %s ERROR: error_table[0].errsym must != NULL\n", + program); + exit(12); + } + if (strcmp(error_table[0].errsym, "E__BASE") != 0) { + fprintf(stderr, "**** %s ERROR: error_table[0].errsym: %s must be E__BASE\n", + program, error_table[0].errsym); + exit(13); + } + if (error_table[0].errmsg == NULL) { + fprintf(stderr, "**** %s ERROR: error_table[0].errmsg must != NULL\n", + program); + exit(14); + } + if (strlen(error_table[0].errmsg) <= 0) { + fprintf(stderr, "**** %s ERROR: error_table[0].errmsg length: %zu must be > 0\n", + program, strlen(error_table[0].errmsg)); + exit(15); + } - /* - * verify 2nd thru end to last entry of error_table[] - */ - for (i=1; i < len-1; ++i) { + /* + * verify 2nd thru end to last entry of error_table[] + */ + for (i=1; i < len-1; ++i) { - /* - * check errnum - must be consecutive starting with E__BASE - */ - if ((size_t)error_table[i].errnum != E__BASE+i) { - fprintf(stderr, "**** %s ERROR: error_table[%zu].errnum: %d != %lu\n", - program, i, error_table[i].errnum, (unsigned long)E__BASE+i); - exit(16); - } + /* + * check errnum - must be consecutive starting with E__BASE + */ + if ((size_t)error_table[i].errnum != E__BASE+i) { + fprintf(stderr, "**** %s ERROR: error_table[%zu].errnum: %d != %lu\n", + program, i, error_table[i].errnum, (unsigned long)E__BASE+i); + exit(16); + } - /* - * check if errsym is non-NULL - */ - if (error_table[i].errsym == NULL) { - fprintf(stderr, "**** %s ERROR: error_table[%zu]..errsym must != NULL\n", - program, i); - exit(17); - } + /* + * check if errsym is non-NULL + */ + if (error_table[i].errsym == NULL) { + fprintf(stderr, "**** %s ERROR: error_table[%zu]..errsym must != NULL\n", + program, i); + exit(17); + } - /* - * check if errsym is matches the regular expression: ^E_[A-Z][A-Z0-9_]+$ - */ - if (is_e_1string(error_table[i].errsym) == false) { - fprintf(stderr, "**** %s ERROR: error_table[%zu].errsym: %s " - "must match the regular expression: %s\n", - program, i, error_table[i].errsym, "^E_[A-Z][A-Z0-9_]+$"); - exit(18); - } + /* + * check if errsym is matches the regular expression: ^E_[A-Z][A-Z0-9_]+$ + */ + if (is_e_1string(error_table[i].errsym) == false) { + fprintf(stderr, "**** %s ERROR: error_table[%zu].errsym: %s " + "must match the regular expression: %s\n", + program, i, error_table[i].errsym, "^E_[A-Z][A-Z0-9_]+$"); + exit(18); + } - /* - * verify error_table[] entry errmsg is not NULL - */ - if (error_table[i].errmsg == NULL) { - fprintf(stderr, "**** %s ERROR: error_table[%zu].errmsg must != NULL\n", - program, i); - exit(19); - } + /* + * verify error_table[] entry errmsg is not NULL + */ + if (error_table[i].errmsg == NULL) { + fprintf(stderr, "**** %s ERROR: error_table[%zu].errmsg must != NULL\n", + program, i); + exit(19); + } - /* - * verify error_table[] entry errmsg is not empty - */ - if (error_table[i].errmsg[0] == '\0') { - fprintf(stderr, "**** %s ERROR: error_table[%zu].errmsg length: %zu must be > 0\n", - program, i, strlen(error_table[i].errmsg)); - exit(20); - } - } + /* + * verify error_table[] entry errmsg is not empty + */ + if (error_table[i].errmsg[0] == '\0') { + fprintf(stderr, "**** %s ERROR: error_table[%zu].errmsg length: %zu must be > 0\n", + program, i, strlen(error_table[i].errmsg)); + exit(20); + } + } - /* - * verify 2nd to last error_table[] entry has the MY_E__HIGHEST errnum - */ - if (error_table[len-2].errnum != MY_E__HIGHEST) { - fprintf(stderr, "**** %s ERROR: highest assigned calc computation error code entry " - "error_table[%zu].errnum: %d must == %lu\n", - program, len-2, error_table[len-2].errnum, (unsigned long)MY_E__HIGHEST); - exit(21); - } + /* + * verify 2nd to last error_table[] entry has the MY_E__HIGHEST errnum + */ + if (error_table[len-2].errnum != MY_E__HIGHEST) { + fprintf(stderr, "**** %s ERROR: highest assigned calc computation error code entry " + "error_table[%zu].errnum: %d must == %lu\n", + program, len-2, error_table[len-2].errnum, (unsigned long)MY_E__HIGHEST); + exit(21); + } - /* - * verify the last error_table[] entry - */ - if (error_table[len-1].errnum != NULL_ERRNUM) { - fprintf(stderr, "**** %s ERROR: final NULL entry error_table[%zu].errnum: %d must == %d\n", - program, len-1, error_table[len-1].errnum, NULL_ERRNUM); - exit(22); - } - if (error_table[len-1].errsym != NULL) { - fprintf(stderr, "**** %s ERROR: final NULL entry error_table[%zu].errsym must == NULL\n", - program, len-1); - exit(23); - } - if (error_table[len-1].errmsg != NULL) { - fprintf(stderr, "**** %s ERROR: final NULL entry error_table[%zu].errmsg must == NULL\n", - program, len-1); - exit(24); - } + /* + * verify the last error_table[] entry + */ + if (error_table[len-1].errnum != NULL_ERRNUM) { + fprintf(stderr, "**** %s ERROR: final NULL entry error_table[%zu].errnum: %d must == %d\n", + program, len-1, error_table[len-1].errnum, NULL_ERRNUM); + exit(22); + } + if (error_table[len-1].errsym != NULL) { + fprintf(stderr, "**** %s ERROR: final NULL entry error_table[%zu].errsym must == NULL\n", + program, len-1); + exit(23); + } + if (error_table[len-1].errmsg != NULL) { + fprintf(stderr, "**** %s ERROR: final NULL entry error_table[%zu].errmsg must == NULL\n", + program, len-1); + exit(24); + } - /* - * verify private_error_alias[] size - */ - priv_len = sizeof(private_error_alias) / sizeof(private_error_alias[0]); - priv_e__count = priv_len - 1; - if (priv_e__count != MY_PRIV_ECOUNT) { - fprintf(stderr, "**** %s ERROR: private_error_alias length: %zu must == MY_PRIV_ECOUNT+1: %lu\n", - program, priv_len, (unsigned long)MY_PRIV_ECOUNT+1); - exit(25); - } + /* + * verify private_error_alias[] size + */ + priv_len = sizeof(private_error_alias) / sizeof(private_error_alias[0]); + priv_e__count = priv_len - 1; + if (priv_e__count != MY_PRIV_ECOUNT) { + fprintf(stderr, "**** %s ERROR: private_error_alias length: %zu must == MY_PRIV_ECOUNT+1: %lu\n", + program, priv_len, (unsigned long)MY_PRIV_ECOUNT+1); + exit(25); + } - /* - * setup the E__HIGHEST entry in private_error_alias[] to be an alias for - * the highest assigned calc computation error code from error_table[]. - */ - found = find_errsym_in_errtbl("E__HIGHEST", private_error_alias); - if (found == NULL) { - fprintf(stderr, "**** %s ERROR: private_error_alias missing E__HIGHEST errsym entry", - program); - exit(26); - } - found->errnum = error_table[len-2].errnum; - found->errmsg = error_table[len-2].errmsg; + /* + * setup the E__HIGHEST entry in private_error_alias[] to be an alias for + * the highest assigned calc computation error code from error_table[]. + */ + found = find_errsym_in_errtbl("E__HIGHEST", private_error_alias); + if (found == NULL) { + fprintf(stderr, "**** %s ERROR: private_error_alias missing E__HIGHEST errsym entry", + program); + exit(26); + } + found->errnum = error_table[len-2].errnum; + found->errmsg = error_table[len-2].errmsg; - /* - * verify 1st private_error_alias[] entry == (E__NONE) 0 - */ - if (private_error_alias[0].errnum != 0) { - fprintf(stderr, "**** %s ERROR: initial entry error_table[0].errnum: %d myst == 0\n", - program, error_table[0].errnum); - exit(27); - } - if (private_error_alias[0].errnum != E__NONE) { - fprintf(stderr, "**** %s ERROR: initial entry error_table[0].errnum: %d must == E__NONE: %d\n", - program, error_table[0].errnum, E__NONE); - exit(28); - } + /* + * verify 1st private_error_alias[] entry == (E__NONE) 0 + */ + if (private_error_alias[0].errnum != 0) { + fprintf(stderr, "**** %s ERROR: initial entry error_table[0].errnum: %d myst == 0\n", + program, error_table[0].errnum); + exit(27); + } + if (private_error_alias[0].errnum != E__NONE) { + fprintf(stderr, "**** %s ERROR: initial entry error_table[0].errnum: %d must == E__NONE: %d\n", + program, error_table[0].errnum, E__NONE); + exit(28); + } - /* - * verify all but the final private_error_alias[] entry - */ - prev_errnum = INV_ERRNUM; /* preset previous errnum to INV_ERRNUM, and <0 value */ - for (i=0; i < priv_len-1; ++i) { + /* + * verify all but the final private_error_alias[] entry + */ + prev_errnum = INV_ERRNUM; /* preset previous errnum to INV_ERRNUM, and <0 value */ + for (i=0; i < priv_len-1; ++i) { - /* - * The private_error_alias[] entry errnum must be >= 0 - */ - if (private_error_alias[i].errnum < 0) { - fprintf(stderr, "**** %s ERROR: entry private_error_alias[%zu].errnum: %d must be >= 0\n", - program, i, private_error_alias[i].errnum); - exit(29); - } - if (i > 0) { - if (private_error_alias[i].errnum <= prev_errnum) { - fprintf(stderr, "**** %s ERROR: entry private_error_alias[%zu].errnum: %d " - "must be > private_error_alias[%zu].errnum: %d\n", - program, i, private_error_alias[i].errnum, i-1, prev_errnum); - exit(30); - } - } - prev_errnum = private_error_alias[i].errnum; + /* + * The private_error_alias[] entry errnum must be >= 0 + */ + if (private_error_alias[i].errnum < 0) { + fprintf(stderr, "**** %s ERROR: entry private_error_alias[%zu].errnum: %d must be >= 0\n", + program, i, private_error_alias[i].errnum); + exit(29); + } + if (i > 0) { + if (private_error_alias[i].errnum <= prev_errnum) { + fprintf(stderr, "**** %s ERROR: entry private_error_alias[%zu].errnum: %d " + "must be > private_error_alias[%zu].errnum: %d\n", + program, i, private_error_alias[i].errnum, i-1, prev_errnum); + exit(30); + } + } + prev_errnum = private_error_alias[i].errnum; - /* - * The private_error_alias[] entry errsym must not be NULL - */ - if (private_error_alias[i].errsym == NULL) { - fprintf(stderr, "**** %s ERROR: entry private_error_alias[%zu].errsym must != NULL\n", - program, i); - exit(31); - } + /* + * The private_error_alias[] entry errsym must not be NULL + */ + if (private_error_alias[i].errsym == NULL) { + fprintf(stderr, "**** %s ERROR: entry private_error_alias[%zu].errsym must != NULL\n", + program, i); + exit(31); + } - /* - * check errsym that is string matching the regular expression: ^E__[A-Z][A-Z0-9_]+$ - */ - if (is_e_2string(private_error_alias[i].errsym) == false) { - fprintf(stderr, "**** %s ERROR: private_error_alias[%zu].errsym: %s " - "E_STRING must match the regular expression: %s\n", - program, i, private_error_alias[i].errsym, "^E__[A-Z][A-Z0-9_]+$"); - exit(32); - } + /* + * check errsym that is string matching the regular expression: ^E__[A-Z][A-Z0-9_]+$ + */ + if (is_e_2string(private_error_alias[i].errsym) == false) { + fprintf(stderr, "**** %s ERROR: private_error_alias[%zu].errsym: %s " + "E_STRING must match the regular expression: %s\n", + program, i, private_error_alias[i].errsym, "^E__[A-Z][A-Z0-9_]+$"); + exit(32); + } - /* - * verify private_error_alias[] entry errmsg is not NULL - */ - if (private_error_alias[i].errmsg == NULL) { - fprintf(stderr, "**** %s ERROR: private_error_alias[%zu].errmsg must != NULL\n", - program, i); - exit(33); - } + /* + * verify private_error_alias[] entry errmsg is not NULL + */ + if (private_error_alias[i].errmsg == NULL) { + fprintf(stderr, "**** %s ERROR: private_error_alias[%zu].errmsg must != NULL\n", + program, i); + exit(33); + } - /* - * verify private_error_alias[] entry errmsg is not empty - */ - if (private_error_alias[i].errmsg[0] == '\0') { - fprintf(stderr, "**** %s ERROR: private_error_alias[%zu].errmsg length: %zu must be > 0\n", - program, i, strlen(private_error_alias[i].errmsg)); - exit(34); - } - } + /* + * verify private_error_alias[] entry errmsg is not empty + */ + if (private_error_alias[i].errmsg[0] == '\0') { + fprintf(stderr, "**** %s ERROR: private_error_alias[%zu].errmsg length: %zu must be > 0\n", + program, i, strlen(private_error_alias[i].errmsg)); + exit(34); + } + } - /* - * verify the last private_error_alias[] entry - */ - if (private_error_alias[priv_len-1].errnum != NULL_ERRNUM) { - fprintf(stderr, "**** %s ERROR: final NULL entry private_error_alias[%zu].errnum: %d must == %d\n", - program, priv_len-1, private_error_alias[priv_len-1].errnum, NULL_ERRNUM); - exit(35); - } - if (private_error_alias[priv_len-1].errsym != NULL) { - fprintf(stderr, "**** %s ERROR: final NULL entry private_error_alias[%zu].errsym must == NULL\n", - program, priv_len-1); - exit(36); - } - if (private_error_alias[priv_len-1].errmsg != NULL) { - fprintf(stderr, "**** %s ERROR: final NULL entry private_error_alias[%zu].errmsg must == NULL\n", - program, priv_len-1); - exit(37); - } + /* + * verify the last private_error_alias[] entry + */ + if (private_error_alias[priv_len-1].errnum != NULL_ERRNUM) { + fprintf(stderr, "**** %s ERROR: final NULL entry private_error_alias[%zu].errnum: %d must == %d\n", + program, priv_len-1, private_error_alias[priv_len-1].errnum, NULL_ERRNUM); + exit(35); + } + if (private_error_alias[priv_len-1].errsym != NULL) { + fprintf(stderr, "**** %s ERROR: final NULL entry private_error_alias[%zu].errsym must == NULL\n", + program, priv_len-1); + exit(36); + } + if (private_error_alias[priv_len-1].errmsg != NULL) { + fprintf(stderr, "**** %s ERROR: final NULL entry private_error_alias[%zu].errmsg must == NULL\n", + program, priv_len-1); + exit(37); + } - /* - * verify USERMAX_DIGITS is correct with respect to the size of E__USERMAX - */ - if (USERMAX_DIGITS <= 0) { - fprintf(stderr, "**** %s ERROR: USERMAX_DIGITS: %d must be > 0\n", - program, USERMAX_DIGITS); - exit(38); - } - if (USERMAX_DIGITS > 20) { - fprintf(stderr, "**** %s ERROR: USERMAX_DIGITS: %d must be <= 20\n", - program, USERMAX_DIGITS); - exit(39); - } - for (i = 0, ten = 1; ten > 0 && ten <= E__USERMAX; ++i) { - ten *= 10; - } - if (i != USERMAX_DIGITS) { - fprintf(stderr, "**** %s ERROR: USERMAX_DIGITS: %d must be == %ld\n", - program, USERMAX_DIGITS, (unsigned long)i); - exit(40); - } + /* + * verify USERMAX_DIGITS is correct with respect to the size of E__USERMAX + */ + if (USERMAX_DIGITS <= 0) { + fprintf(stderr, "**** %s ERROR: USERMAX_DIGITS: %d must be > 0\n", + program, USERMAX_DIGITS); + exit(38); + } + if (USERMAX_DIGITS > 20) { + fprintf(stderr, "**** %s ERROR: USERMAX_DIGITS: %d must be <= 20\n", + program, USERMAX_DIGITS); + exit(39); + } + for (i = 0, ten = 1; ten > 0 && ten <= E__USERMAX; ++i) { + ten *= 10; + } + if (i != USERMAX_DIGITS) { + fprintf(stderr, "**** %s ERROR: USERMAX_DIGITS: %d must be == %ld\n", + program, USERMAX_DIGITS, (unsigned long)i); + exit(40); + } - /* - * verify that E__USERMAX can fit into a value.v_type - * - * When a VALUE indicates an error, value.v_type is set to < 0. - * So we need to test if -E__USERMAX can be stored into a test.v_type. - */ - test.v_type = -E__USERMAX; - if (-E__USERMAX != test.v_type) { - fprintf(stderr, "**** %s ERROR: E__USERMAX: %d cannot fit into a value.v_type of size: %lu\n", - program, E__USERMAX, (unsigned long)sizeof(test.v_type)); - exit(41); - } - return; + /* + * verify that E__USERMAX can fit into a value.v_type + * + * When a VALUE indicates an error, value.v_type is set to < 0. + * So we need to test if -E__USERMAX can be stored into a test.v_type. + */ + test.v_type = -E__USERMAX; + if (-E__USERMAX != test.v_type) { + fprintf(stderr, "**** %s ERROR: E__USERMAX: %d cannot fit into a value.v_type of size: %lu\n", + program, E__USERMAX, (unsigned long)sizeof(test.v_type)); + exit(41); + } + return; } @@ -1670,78 +1670,78 @@ verify_error_table(void) * otherwise we will return NULL_ERRNUM. * * given: - * errsym pointer to a E_STRING + * errsym pointer to a E_STRING * * returns: - * != NULL_ERRNUM ==> valid errnum corresponding to a valid E_STRING errsym - * == NULL_ERRNUM ==> errsym is NULL, not valid E_STRING errsym, - * or no corresponding errnum found + * != NULL_ERRNUM ==> valid errnum corresponding to a valid E_STRING errsym + * == NULL_ERRNUM ==> errsym is NULL, not valid E_STRING errsym, + * or no corresponding errnum found */ int errsym_2_errnum(CONST char *errsym) { - struct errtbl *found; /* pointer to entry in struct errtbl array with matching errsym */ - int errnum; /* errnum to return */ + struct errtbl *found; /* pointer to entry in struct errtbl array with matching errsym */ + int errnum; /* errnum to return */ - /* - * firewall - */ - if (errsym == NULL) { - /* errsym is NULL */ - return NULL_ERRNUM; - } + /* + * firewall + */ + if (errsym == NULL) { + /* errsym is NULL */ + return NULL_ERRNUM; + } - /* - * case: E_STRING is a E_digits errsym - */ - errnum = e_digits_2_errnum(errsym); - if (is_valid_errnum(errnum) == true) { - /* digits of E_digits is a valid errnum */ - return errnum; - } + /* + * case: E_STRING is a E_digits errsym + */ + errnum = e_digits_2_errnum(errsym); + if (is_valid_errnum(errnum) == true) { + /* digits of E_digits is a valid errnum */ + return errnum; + } - /* - * case: E_STRING is a E_digits but errnum is not valid - */ - if (is_e_digits(errsym) == true) { - /* E_digits but digits to not form a valid errnum */ - return NULL_ERRNUM; - } + /* + * case: E_STRING is a E_digits but errnum is not valid + */ + if (is_e_digits(errsym) == true) { + /* E_digits but digits to not form a valid errnum */ + return NULL_ERRNUM; + } - /* - * case: E_STRING is a known E__ errsym - */ - if (is_e_2string(errsym) == true) { + /* + * case: E_STRING is a known E__ errsym + */ + if (is_e_2string(errsym) == true) { - /* - * look in private_error_alias[] for E__ errsym - */ - found = find_errsym_in_errtbl(errsym, private_error_alias); - if (found != NULL) { - /* return matching errnum */ - return found->errnum; - } - } + /* + * look in private_error_alias[] for E__ errsym + */ + found = find_errsym_in_errtbl(errsym, private_error_alias); + if (found != NULL) { + /* return matching errnum */ + return found->errnum; + } + } - /* - * case: E_STRING is a known E_ errsym - */ - if (is_e_1string(errsym) == true) { + /* + * case: E_STRING is a known E_ errsym + */ + if (is_e_1string(errsym) == true) { - /* - * look in error_table[] for E_ errsym - */ - found = find_errsym_in_errtbl(errsym, error_table); - if (found != NULL) { - /* return matching errnum */ - return found->errnum; - } - } + /* + * look in error_table[] for E_ errsym + */ + found = find_errsym_in_errtbl(errsym, error_table); + if (found != NULL) { + /* return matching errnum */ + return found->errnum; + } + } - /* - * cannot convert errsym to a valid errnum - */ - return NULL_ERRNUM; + /* + * cannot convert errsym to a valid errnum + */ + return NULL_ERRNUM; } @@ -1755,73 +1755,73 @@ errsym_2_errnum(CONST char *errsym) * errnum_2_errsym - convert an errnum value into an errsym E_STRING, possibly malloced * * given: - * errnum errnum code to convert - * palloced pointer to bool to be set if errsym E_STRING was malloced + * errnum errnum code to convert + * palloced pointer to bool to be set if errsym E_STRING was malloced * * return: - * != NULL ==> E_STRING for errnum (malloced if *palloced == true, static is not) - * == NULL ==> errnum is not valid, or palloced is NULL + * != NULL ==> E_STRING for errnum (malloced if *palloced == true, static is not) + * == NULL ==> errnum is not valid, or palloced is NULL */ char * errnum_2_errsym(int errnum, bool *palloced) { - char *ret; /* return string, possibly malloced */ - CONST struct errtbl *entry; /* struct errtbl entry lookup found or NULL */ - size_t snprintf_len; /* malloced snprintf buffer length */ + char *ret; /* return string, possibly malloced */ + CONST struct errtbl *entry; /* struct errtbl entry lookup found or NULL */ + size_t snprintf_len; /* malloced snprintf buffer length */ - /* - * firewall - */ - if (palloced == NULL) { - /* palloced is NULL */ - return NULL; - } - if (is_valid_errnum(errnum) == false) { - /* errnum is not a valid code */ - *palloced = false; - return NULL; - } + /* + * firewall + */ + if (palloced == NULL) { + /* palloced is NULL */ + return NULL; + } + if (is_valid_errnum(errnum) == false) { + /* errnum is not a valid code */ + *palloced = false; + return NULL; + } - /* - * case: errnum is within in the error_table[] array bounds - */ - if (is_errnum_in_error_table(errnum) == true) { + /* + * case: errnum is within in the error_table[] array bounds + */ + if (is_errnum_in_error_table(errnum) == true) { - /* - * struct errtbl entry found - */ - entry = lookup_errnum_in_error_table(errnum); - if (entry == NULL) { - /* lookup failed, return NULL */ - *palloced = false; - return NULL; - } + /* + * struct errtbl entry found + */ + entry = lookup_errnum_in_error_table(errnum); + if (entry == NULL) { + /* lookup failed, return NULL */ + *palloced = false; + return NULL; + } - /* - * return non-malloced errsym - */ - *palloced = false; - ret = entry->errsym; - return ret; - } + /* + * return non-malloced errsym + */ + *palloced = false; + ret = entry->errsym; + return ret; + } - /* - * case: form a malloced E_STRING of E_digits - */ - snprintf_len = sizeof("E_")-1 + USERMAX_DIGITS + 1; /* + 1 for trailing NUL */ - ret = calloc(snprintf_len+1, 1); /* +1 for paranoia */ - if (ret == NULL) { - math_error("Out of memory for errnum_2_errsym"); - not_reached(); - } - *palloced = true; - snprintf(ret, snprintf_len, "E_%d", errnum); - ret[snprintf_len] = '\0'; /* paranoia */ + /* + * case: form a malloced E_STRING of E_digits + */ + snprintf_len = sizeof("E_")-1 + USERMAX_DIGITS + 1; /* + 1 for trailing NUL */ + ret = calloc(snprintf_len+1, 1); /* +1 for paranoia */ + if (ret == NULL) { + math_error("Out of memory for errnum_2_errsym"); + not_reached(); + } + *palloced = true; + snprintf(ret, snprintf_len, "E_%d", errnum); + ret[snprintf_len] = '\0'; /* paranoia */ - /* - * return alloced E_STRING of E_digits - */ - return ret; + /* + * return alloced E_STRING of E_digits + */ + return ret; } @@ -1829,128 +1829,128 @@ errnum_2_errsym(int errnum, bool *palloced) * errnum_2_errmsg - convert an errnum value into an errmsg string, possibly malloced * * given: - * errnum errnum code to convert - * palloced pointer to bool to be set if errmsg string was malloced + * errnum errnum code to convert + * palloced pointer to bool to be set if errmsg string was malloced * * return: - * != NULL ==> errmsg string for errnum (malloced if *palloced == true, static is not) - * == NULL ==> errnum is not valid, or palloced is NULL + * != NULL ==> errmsg string for errnum (malloced if *palloced == true, static is not) + * == NULL ==> errnum is not valid, or palloced is NULL */ char * errnum_2_errmsg(int errnum, bool *palloced) { - char *ret; /* return string, possibly malloced */ - CONST struct errtbl *entry; /* struct errtbl entry lookup found or NULL */ - size_t snprintf_len; /* malloced snprintf buffer length */ + char *ret; /* return string, possibly malloced */ + CONST struct errtbl *entry; /* struct errtbl entry lookup found or NULL */ + size_t snprintf_len; /* malloced snprintf buffer length */ - /* - * firewall - */ - if (palloced == NULL) { - /* palloced is NULL */ - return NULL; - } - if (is_valid_errnum(errnum) == false) { - /* errnum is not a valid code */ - *palloced = false; - return NULL; - } + /* + * firewall + */ + if (palloced == NULL) { + /* palloced is NULL */ + return NULL; + } + if (is_valid_errnum(errnum) == false) { + /* errnum is not a valid code */ + *palloced = false; + return NULL; + } - /* - * case: errnum is within in the error_table[] array bounds - */ - if (is_errnum_in_error_table(errnum) == true) { + /* + * case: errnum is within in the error_table[] array bounds + */ + if (is_errnum_in_error_table(errnum) == true) { - /* - * struct errtbl entry found - */ - entry = lookup_errnum_in_error_table(errnum); - if (entry == NULL) { - /* lookup failed, return NULL */ - *palloced = false; - return NULL; - } + /* + * struct errtbl entry found + */ + entry = lookup_errnum_in_error_table(errnum); + if (entry == NULL) { + /* lookup failed, return NULL */ + *palloced = false; + return NULL; + } - /* - * return non-malloced errmsg - */ - *palloced = false; - ret = entry->errmsg; + /* + * return non-malloced errmsg + */ + *palloced = false; + ret = entry->errmsg; - /* - * case: errnum is a user-described errno - */ - } else if (errnum >= E__USERDEF && errnum <= E__USERMAX) { + /* + * case: errnum is a user-described errno + */ + } else if (errnum >= E__USERDEF && errnum <= E__USERMAX) { - /* - * return non-malloced errmsg - */ - *palloced = false; - ret = name_newerrorstr(errnum); - if (ret == NULL) { - snprintf_len = sizeof("Unknown user error ")-1 + USERMAX_DIGITS + 1; /* + 1 for trailing NUL */ - ret = calloc(snprintf_len+1, 1); /* +1 for paranoia */ - if (ret == NULL) { - math_error("Out of memory #0 for errnum_2_errmsg"); - not_reached(); - } - *palloced = true; - snprintf(ret, snprintf_len, "Unknown user error %d", errnum); - ret[snprintf_len] = '\0'; /* paranoia */ - } + /* + * return non-malloced errmsg + */ + *palloced = false; + ret = name_newerrorstr(errnum); + if (ret == NULL) { + snprintf_len = sizeof("Unknown user error ")-1 + USERMAX_DIGITS + 1; /* + 1 for trailing NUL */ + ret = calloc(snprintf_len+1, 1); /* +1 for paranoia */ + if (ret == NULL) { + math_error("Out of memory #0 for errnum_2_errmsg"); + not_reached(); + } + *palloced = true; + snprintf(ret, snprintf_len, "Unknown user error %d", errnum); + ret[snprintf_len] = '\0'; /* paranoia */ + } - /* - * case: errnum is 0 - */ - } else if (errnum == E__NONE) { + /* + * case: errnum is 0 + */ + } else if (errnum == E__NONE) { - /* - * return "No error" - */ - *palloced = false; - ret = "No error"; + /* + * return "No error" + */ + *palloced = false; + ret = "No error"; - /* - * case: errnum is a system errno - */ - } else if (errnum > E__NONE && errnum < E__BASE) { + /* + * case: errnum is a system errno + */ + } else if (errnum > E__NONE && errnum < E__BASE) { - /* - * return non-malloced result of strerror() - */ - *palloced = false; - ret = strerror(errnum); - if (ret == NULL) { - snprintf_len = sizeof("Unknown system error ")-1 + USERMAX_DIGITS + 1; /* + 1 for trailing NUL */ - ret = calloc(snprintf_len+1, 1); /* +1 for paranoia */ - if (ret == NULL) { - math_error("Out of memory #1 for errnum_2_errmsg"); - not_reached(); - } - *palloced = true; - snprintf(ret, snprintf_len, "Unknown system error %d", errnum); - ret[snprintf_len] = '\0'; /* paranoia */ - } + /* + * return non-malloced result of strerror() + */ + *palloced = false; + ret = strerror(errnum); + if (ret == NULL) { + snprintf_len = sizeof("Unknown system error ")-1 + USERMAX_DIGITS + 1; /* + 1 for trailing NUL */ + ret = calloc(snprintf_len+1, 1); /* +1 for paranoia */ + if (ret == NULL) { + math_error("Out of memory #1 for errnum_2_errmsg"); + not_reached(); + } + *palloced = true; + snprintf(ret, snprintf_len, "Unknown system error %d", errnum); + ret[snprintf_len] = '\0'; /* paranoia */ + } - /* - * case: unknown errnum - */ - } else { - snprintf_len = sizeof("Unknown error ")-1 + USERMAX_DIGITS + 1; /* + 1 for trailing NUL */ - ret = calloc(snprintf_len+1, 1); /* +1 for paranoia */ - if (ret == NULL) { - math_error("Out of memory #2 for errnum_2_errmsg"); - not_reached(); - } - *palloced = true; - snprintf(ret, snprintf_len, "Unknown error %d", errnum); - ret[snprintf_len] = '\0'; /* paranoia */ - } + /* + * case: unknown errnum + */ + } else { + snprintf_len = sizeof("Unknown error ")-1 + USERMAX_DIGITS + 1; /* + 1 for trailing NUL */ + ret = calloc(snprintf_len+1, 1); /* +1 for paranoia */ + if (ret == NULL) { + math_error("Out of memory #2 for errnum_2_errmsg"); + not_reached(); + } + *palloced = true; + snprintf(ret, snprintf_len, "Unknown error %d", errnum); + ret[snprintf_len] = '\0'; /* paranoia */ + } - /* - * return possibly allocated errmsg string - */ - return ret; + /* + * return possibly allocated errmsg string + */ + return ret; } @@ -1958,47 +1958,47 @@ errnum_2_errmsg(int errnum, bool *palloced) * errsym_2_errmsg - convert convert an E_STRING into an errmsg string, possibly malloced * * given: - * errsym E_STRING to convert - * palloced pointer to bool to be set if errmsg string was malloced + * errsym E_STRING to convert + * palloced pointer to bool to be set if errmsg string was malloced * * return: - * != NULL ==> errmsg string for errsym (malloced if *palloced == true, static is not) - * == NULL ==> errsym is not valid, or palloced is NULL, or errsym is NULL + * != NULL ==> errmsg string for errsym (malloced if *palloced == true, static is not) + * == NULL ==> errsym is not valid, or palloced is NULL, or errsym is NULL */ char * errsym_2_errmsg(CONST char *errsym, bool *palloced) { - int errnum; /* errsym E_STRING converted to errnum code or NULL_ERRNUM */ - char *ret; /* errmsg string, possibly malloced, or NULL */ + int errnum; /* errsym E_STRING converted to errnum code or NULL_ERRNUM */ + char *ret; /* errmsg string, possibly malloced, or NULL */ - /* - * firewall - */ - if (palloced == NULL) { - /* palloced is NULL */ - return NULL; - } - if (errsym == NULL) { - /* errsym is NULL */ - *palloced = false; - return NULL; - } + /* + * firewall + */ + if (palloced == NULL) { + /* palloced is NULL */ + return NULL; + } + if (errsym == NULL) { + /* errsym is NULL */ + *palloced = false; + return NULL; + } - /* - * convert errsym E_STRING to errnum - */ - errnum = errsym_2_errnum(errsym); - if (is_valid_errnum(errnum) == false) { - /* errsym did not convert into a valid errnum code */ - *palloced = false; - return NULL; - } + /* + * convert errsym E_STRING to errnum + */ + errnum = errsym_2_errnum(errsym); + if (is_valid_errnum(errnum) == false) { + /* errsym did not convert into a valid errnum code */ + *palloced = false; + return NULL; + } - /* - * return errnum value into an errmsg string, possibly malloced or return NULL - */ - ret = errnum_2_errmsg(errnum, palloced); - return ret; + /* + * return errnum value into an errmsg string, possibly malloced or return NULL + */ + ret = errnum_2_errmsg(errnum, palloced); + return ret; } @@ -2015,20 +2015,20 @@ errsym_2_errmsg(CONST char *errsym, bool *palloced) * errcode command line */ CONST char *usage = - "usage: %s [-h] [-e | -d]\n" - "\n" - "\t-h\tprint help and exit\n" - "\t-e\tprint the contents of help/errorcodes\n" - "\t-d\tprint the contents of errsym.h\n" - "\n" - "Exit codes:\n" - " 0\t\tall is OK\n" - " 2\t\t-h and help string\n" - " 3\t\tcommand line error\n" - " >=10\t\terror_table[] and/or private_error_alias[] is invalid\n"; + "usage: %s [-h] [-e | -d]\n" + "\n" + "\t-h\tprint help and exit\n" + "\t-e\tprint the contents of help/errorcodes\n" + "\t-d\tprint the contents of errsym.h\n" + "\n" + "Exit codes:\n" + " 0\t\tall is OK\n" + " 2\t\t-h and help string\n" + " 3\t\tcommand line error\n" + " >=10\t\terror_table[] and/or private_error_alias[] is invalid\n"; -char *program = "((NULL))"; /* our name */ +char *program = "((NULL))"; /* our name */ /* @@ -2037,72 +2037,72 @@ char *program = "((NULL))"; /* our name */ S_FUNC void print_errorcodes(void) { - /* - * print the help/errorcodes file header - */ - size_t len; /* length of the error_table */ - size_t i; + /* + * print the help/errorcodes file header + */ + size_t len; /* length of the error_table */ + size_t i; - /* - * print the help/errorcodes file header - */ - printf("## DO NOT EDIT - This file was generated by errcode -e via the Makefile\n" - "Calc computation error codes\n" - "\n" - "\"E_STRING\"\terrnum\tCalc computation error message\n" - "----------\t------\t------------------------------\n" - "\n" - "\"E__NONE\"\t%d\tcalc_errno cleared: libc errno codes above here\n" - "\"E__BASE\"\t%d\tReserved for \"No error\" calc internal state\n" - "\n", - E__NONE, E__BASE); + /* + * print the help/errorcodes file header + */ + printf("## DO NOT EDIT - This file was generated by errcode -e via the Makefile\n" + "Calc computation error codes\n" + "\n" + "\"E_STRING\"\terrnum\tCalc computation error message\n" + "----------\t------\t------------------------------\n" + "\n" + "\"E__NONE\"\t%d\tcalc_errno cleared: libc errno codes above here\n" + "\"E__BASE\"\t%d\tReserved for \"No error\" calc internal state\n" + "\n", + E__NONE, E__BASE); - /* - * print the error message lines - */ - len = sizeof(error_table) / sizeof(error_table[0]); - for (i=1; i < len-1; ++i) { - if (strlen(error_table[i].errsym) < 6) { - printf("\"%s\"\t\t%d\t%s\n", - error_table[i].errsym, error_table[i].errnum, error_table[i].errmsg); - } else { - printf("\"%s\"\t%d\t%s\n", - error_table[i].errsym, error_table[i].errnum, error_table[i].errmsg); - } - } + /* + * print the error message lines + */ + len = sizeof(error_table) / sizeof(error_table[0]); + for (i=1; i < len-1; ++i) { + if (strlen(error_table[i].errsym) < 6) { + printf("\"%s\"\t\t%d\t%s\n", + error_table[i].errsym, error_table[i].errnum, error_table[i].errmsg); + } else { + printf("\"%s\"\t%d\t%s\n", + error_table[i].errsym, error_table[i].errnum, error_table[i].errmsg); + } + } - /* - * print the help/errorcodes file trailer - */ - printf("\n" - "\"E__HIGHEST\"\t%lu\thighest assigned calc computation error code\n" - "\"E__USERDEF\"\t%lu\tuser defined error codes start here\n" - "\"E__USERMAX\"\t%lu\tmaximum user defined error code\n", - (unsigned long)MY_E__HIGHEST, (unsigned long)E__USERDEF, (unsigned long)E__USERMAX); - printf("\n" - "## Copyright (C) %d Landon Curt Noll\n" - "##\n" - "## Calc is open software; you can redistribute it and/or modify it under\n" - "## the terms of the version 2.1 of the GNU Lesser General Public License\n" - "## as published by the Free Software Foundation.\n" - "##\n" - "## Calc is distributed in the hope that it will be useful, but WITHOUT\n" - "## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n" - "## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General\n" - "## Public License for more details.\n" - "##\n" - "## A copy of version 2.1 of the GNU Lesser General Public License is\n" - "## distributed with calc under the filename COPYING-LGPL. You should have\n" - "## received a copy with calc; if not, write to Free Software Foundation, Inc.\n" - "## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n" - "##\n" - "## Under source code control: n/a\n" - "## File existed as early as: n/a\n" - "##\n" - "## chongo /\\oo/\\ http://www.isthe.com/chongo/\n" - "## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/\n", - ERRTBL_COPYRIGHT_YEAR); - return; + /* + * print the help/errorcodes file trailer + */ + printf("\n" + "\"E__HIGHEST\"\t%lu\thighest assigned calc computation error code\n" + "\"E__USERDEF\"\t%lu\tuser defined error codes start here\n" + "\"E__USERMAX\"\t%lu\tmaximum user defined error code\n", + (unsigned long)MY_E__HIGHEST, (unsigned long)E__USERDEF, (unsigned long)E__USERMAX); + printf("\n" + "## Copyright (C) %d Landon Curt Noll\n" + "##\n" + "## Calc is open software; you can redistribute it and/or modify it under\n" + "## the terms of the version 2.1 of the GNU Lesser General Public License\n" + "## as published by the Free Software Foundation.\n" + "##\n" + "## Calc is distributed in the hope that it will be useful, but WITHOUT\n" + "## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n" + "## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General\n" + "## Public License for more details.\n" + "##\n" + "## A copy of version 2.1 of the GNU Lesser General Public License is\n" + "## distributed with calc under the filename COPYING-LGPL. You should have\n" + "## received a copy with calc; if not, write to Free Software Foundation, Inc.\n" + "## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n" + "##\n" + "## Under source code control: n/a\n" + "## File existed as early as: n/a\n" + "##\n" + "## chongo /\\oo/\\ http://www.isthe.com/chongo/\n" + "## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/\n", + ERRTBL_COPYRIGHT_YEAR); + return; } @@ -2112,133 +2112,133 @@ print_errorcodes(void) S_FUNC void print_errsym(void) { - size_t len; /* length of the error_table */ - size_t i; + size_t len; /* length of the error_table */ + size_t i; - /* - * print the errsym.h file header - */ - printf("/*\n" - " * DO NOT EDIT - This file was generated by errcode -d via the Makefile\n" - " *\n" - " * Copyright (C) %d Landon Curt Noll\n" - " *\n" - " * Calc is open software; you can redistribute it and/or modify it under\n" - " * the terms of the version 2.1 of the GNU Lesser General Public License\n" - " * as published by the Free Software Foundation.\n" - " *\n" - " * Calc is distributed in the hope that it will be useful, but WITHOUT\n" - " * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n" - " * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General\n" - " * Public License for more details.\n" - " *\n" - " * A copy of version 2.1 of the GNU Lesser General Public License is\n" - " * distributed with calc under the filename COPYING-LGPL. You should have\n" - " * received a copy with calc; if not, write to Free Software Foundation, Inc.\n" - " * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n" - " *\n" - " * Under source code control: n/a\n" - " * File existed as early as: n/a\n" - " *\n" - " * chongo /\\oo/\\ http://www.isthe.com/chongo/\n" - " * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/\n" - " */\n" - "\n" - "\n" - "#if !defined(INCLUDE_ERRSYM_H)\n" - "#define INCLUDE_ERRSYM_H\n" - "\n" - "\n", - ERRTBL_COPYRIGHT_YEAR); + /* + * print the errsym.h file header + */ + printf("/*\n" + " * DO NOT EDIT - This file was generated by errcode -d via the Makefile\n" + " *\n" + " * Copyright (C) %d Landon Curt Noll\n" + " *\n" + " * Calc is open software; you can redistribute it and/or modify it under\n" + " * the terms of the version 2.1 of the GNU Lesser General Public License\n" + " * as published by the Free Software Foundation.\n" + " *\n" + " * Calc is distributed in the hope that it will be useful, but WITHOUT\n" + " * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n" + " * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General\n" + " * Public License for more details.\n" + " *\n" + " * A copy of version 2.1 of the GNU Lesser General Public License is\n" + " * distributed with calc under the filename COPYING-LGPL. You should have\n" + " * received a copy with calc; if not, write to Free Software Foundation, Inc.\n" + " * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n" + " *\n" + " * Under source code control: n/a\n" + " * File existed as early as: n/a\n" + " *\n" + " * chongo /\\oo/\\ http://www.isthe.com/chongo/\n" + " * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/\n" + " */\n" + "\n" + "\n" + "#if !defined(INCLUDE_ERRSYM_H)\n" + "#define INCLUDE_ERRSYM_H\n" + "\n" + "\n", + ERRTBL_COPYRIGHT_YEAR); - /* - * print the #define lines - */ - len = sizeof(error_table) / sizeof(error_table[0]); - for (i=1; i < len-1; ++i) { - if (strlen(error_table[i].errsym) < 8) { - printf("#define %s\t\t%d\t/* %s */\n", - error_table[i].errsym, error_table[i].errnum, error_table[i].errmsg); - } else { - printf("#define %s\t%d\t/* %s */\n", - error_table[i].errsym, error_table[i].errnum, error_table[i].errmsg); - } - } + /* + * print the #define lines + */ + len = sizeof(error_table) / sizeof(error_table[0]); + for (i=1; i < len-1; ++i) { + if (strlen(error_table[i].errsym) < 8) { + printf("#define %s\t\t%d\t/* %s */\n", + error_table[i].errsym, error_table[i].errnum, error_table[i].errmsg); + } else { + printf("#define %s\t%d\t/* %s */\n", + error_table[i].errsym, error_table[i].errnum, error_table[i].errmsg); + } + } - /* - * print the errsym.h file trailer - */ - printf("\n" - "#define E__HIGHEST\t%lu\t/* highest assigned calc computation error code */\n" - "\n" - "#define ECOUNT\t%lu\t/* number of calc computation error codes w/o E__BASE */\n", - (unsigned long)MY_E__HIGHEST, (unsigned long)MY_ECOUNT); - printf("\n" - "\n" - "#endif /* !INCLUDE_ERRSYM_H */\n"); - return; + /* + * print the errsym.h file trailer + */ + printf("\n" + "#define E__HIGHEST\t%lu\t/* highest assigned calc computation error code */\n" + "\n" + "#define ECOUNT\t%lu\t/* number of calc computation error codes w/o E__BASE */\n", + (unsigned long)MY_E__HIGHEST, (unsigned long)MY_ECOUNT); + printf("\n" + "\n" + "#endif /* !INCLUDE_ERRSYM_H */\n"); + return; } int main(int argc, char *argv[]) { - EXTERN char *optarg; /* argv index of the next arg */ - EXTERN int optind; /* argv index of the next arg */ - int e_flag = 0; /* 1 ==> -e flag was used */ - int d_flag = 0; /* 1 ==> -s flag was used */ - int i; + EXTERN char *optarg; /* argv index of the next arg */ + EXTERN int optind; /* argv index of the next arg */ + int e_flag = 0; /* 1 ==> -e flag was used */ + int d_flag = 0; /* 1 ==> -s flag was used */ + int i; - /* - * parse args - */ - program = argv[0]; - while ((i = getopt(argc, argv, "hed")) != -1) { - switch (i) { - case 'h': - fprintf(stderr, usage, program); - exit(2); /*ooo*/ - case 'e': - e_flag = 1; - break; - case 'd': - d_flag = 1; - break; - default: - fprintf(stderr, "**** %s ERROR: invalid command line\n", program); - fprintf(stderr, usage, program); - exit(3); /*ooo*/ - } - } - if (e_flag && d_flag) { - fprintf(stderr, "**** %s ERROR: -e and -d conflict\n", program); - fprintf(stderr, usage, program); - exit(3); /*ooo*/ - } + /* + * parse args + */ + program = argv[0]; + while ((i = getopt(argc, argv, "hed")) != -1) { + switch (i) { + case 'h': + fprintf(stderr, usage, program); + exit(2); /*ooo*/ + case 'e': + e_flag = 1; + break; + case 'd': + d_flag = 1; + break; + default: + fprintf(stderr, "**** %s ERROR: invalid command line\n", program); + fprintf(stderr, usage, program); + exit(3); /*ooo*/ + } + } + if (e_flag && d_flag) { + fprintf(stderr, "**** %s ERROR: -e and -d conflict\n", program); + fprintf(stderr, usage, program); + exit(3); /*ooo*/ + } - /* - * verify the consistency of the error_table - */ - verify_error_table(); + /* + * verify the consistency of the error_table + */ + verify_error_table(); - /* - * -e - print the contents of help/errorcodes - */ - if (e_flag) { - print_errorcodes(); - } + /* + * -e - print the contents of help/errorcodes + */ + if (e_flag) { + print_errorcodes(); + } - /* - * -d - print the contents of errsym.h - */ - if (d_flag) { - print_errsym(); - } + /* + * -d - print the contents of errsym.h + */ + if (d_flag) { + print_errsym(); + } - /* - * All Done!!! -- Jessica Noll, Age 2 - */ - exit(0); /*ooo*/ + /* + * All Done!!! -- Jessica Noll, Age 2 + */ + exit(0); /*ooo*/ } diff --git a/errtbl.h b/errtbl.h index 3481f89..1d1210a 100644 --- a/errtbl.h +++ b/errtbl.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2023/09/12 20:55:14 - * File existed as early as: 2023 + * Under source code control: 2023/09/12 20:55:14 + * File existed as early as: 2023 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -47,33 +47,33 @@ /* * primary error code defines */ -#define E__NONE 0 /* calc_errno cleared: libc errno codes above here */ -#define E__BASE 10000 /* calc computation error codes start above here */ -#define E__USERDEF 20000 /* user defined error codes start here */ -#define E__USERMAX 32767 /* maximum user defined error code */ +#define E__NONE 0 /* calc_errno cleared: libc errno codes above here */ +#define E__BASE 10000 /* calc computation error codes start above here */ +#define E__USERDEF 20000 /* user defined error codes start here */ +#define E__USERMAX 32767 /* maximum user defined error code */ -#define USERMAX_DIGITS 5 /* number of decimal digits in E__USERMAX */ +#define USERMAX_DIGITS 5 /* number of decimal digits in E__USERMAX */ /* * invalid errnum */ -#define NULL_ERRNUM (-1) /* errnum for the final table terminating NULL entry */ +#define NULL_ERRNUM (-1) /* errnum for the final table terminating NULL entry */ /* * The error routine. */ E_FUNC void math_error(char *, ...) \ - __attribute__((format(printf, 1, 2))) __attribute__((noreturn)); + __attribute__((format(printf, 1, 2))) __attribute__((noreturn)); /* * calc error code, error symbol and error message */ struct errtbl { - int errnum; /* calc computation error codes or -1 */ - char *errsym; /* E_STRING - must match regexp: ^E_[A-Z0-9_]+$ or NULL */ - char *errmsg; /* calc error message or NULL */ + int errnum; /* calc computation error codes or -1 */ + char *errsym; /* E_STRING - must match regexp: ^E_[A-Z0-9_]+$ or NULL */ + char *errmsg; /* calc error message or NULL */ }; @@ -88,7 +88,7 @@ struct errtbl { * * The final entry must have an errnum of -1, errsym of NULL and errmsg of NULL. */ -EXTERN CONST struct errtbl error_table[]; /* calc error codes, error symbols and error messages */ +EXTERN CONST struct errtbl error_table[]; /* calc error codes, error symbols and error messages */ /* diff --git a/file.c b/file.c index 131c979..2424073 100644 --- a/file.c +++ b/file.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,11 +19,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1991/07/20 00:21:56 - * File existed as early as: 1991 + * Under source code control: 1991/07/20 00:21:56 + * File existed as early as: 1991 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -51,10 +51,10 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define READSIZE 1024 /* buffer size for reading */ +#define READSIZE 1024 /* buffer size for reading */ #define MIN(a,b) (((a) <= (b)) ? (a) : (b)) @@ -71,18 +71,18 @@ E_FUNC FILE *f_open(char *name, char *mode); * and cannot be closed. Their file ids are always 0, 1, and 2. */ STATIC FILEIO files[MAXFILES] = { - {FILEID_STDIN, NULL, (dev_t)0, (ino_t)0, - "(stdin)", true, false, false, false, 'r', "r"}, - {FILEID_STDOUT, NULL, (dev_t)0, (ino_t)0, - "(stdout)", false, true, false, false, 'w', "w"}, - {FILEID_STDERR, NULL, (dev_t)0, (ino_t)0, - "(stderr)", false, true, false, false, 'w', "w"} + {FILEID_STDIN, NULL, (dev_t)0, (ino_t)0, + "(stdin)", true, false, false, false, 'r', "r"}, + {FILEID_STDOUT, NULL, (dev_t)0, (ino_t)0, + "(stdout)", false, true, false, false, 'w', "w"}, + {FILEID_STDERR, NULL, (dev_t)0, (ino_t)0, + "(stderr)", false, true, false, false, 'w', "w"} }; STATIC int ioindex[MAXFILES] = {0,1,2}; /* Indices for FILEIO table */ -STATIC FILEID lastid = FILEID_STDERR; /* Last allocated file id */ -STATIC int idnum = 3; /* Number of allocated file ids */ +STATIC FILEID lastid = FILEID_STDERR; /* Last allocated file id */ +STATIC int idnum = 3; /* Number of allocated file ids */ /* forward static declarations */ @@ -94,9 +94,9 @@ S_FUNC ZVALUE off_t2z(off_t siz); S_FUNC ZVALUE dev2z(dev_t dev); S_FUNC ZVALUE inode2z(ino_t inode); S_FUNC void getscanfield(FILE *fp, bool skip, unsigned int width, - int scannum, char *scanptr, char **strptr); + int scannum, char *scanptr, char **strptr); S_FUNC void getscanwhite(FILE *fp, bool skip, unsigned int width, - int scannum, char **strptr); + int scannum, char **strptr); S_FUNC int fscanfile(FILE *fp, char *fmt, int count, VALUE **vals); S_FUNC void freadnum(FILE *fp, VALUE *valptr); S_FUNC void freadsum(FILE *fp, VALUE *valptr); @@ -116,85 +116,85 @@ S_FUNC void fskipnum(FILE *fp); void file_init(void) { - STATIC int done = 0; /* 1 => routine already called */ - struct stat sbuf; /* file status */ + STATIC int done = 0; /* 1 => routine already called */ + struct stat sbuf; /* file status */ FILEIO *fiop; FILE *fp; int i; if (!done) { - /* - * setup the default set - */ - files[0].fp = stdin; - files[1].fp = stdout; - files[2].fp = stderr; - for (i = 0; i < 3; ++i) { - if (fstat(i, &sbuf) >= 0) { - files[i].dev = sbuf.st_dev; - files[i].inode = sbuf.st_ino; - } - } + /* + * setup the default set + */ + files[0].fp = stdin; + files[1].fp = stdout; + files[2].fp = stderr; + for (i = 0; i < 3; ++i) { + if (fstat(i, &sbuf) >= 0) { + files[i].dev = sbuf.st_dev; + files[i].inode = sbuf.st_ino; + } + } - /* - * note any other files that we can find - */ - fiop = &files[3]; - for (i = 3; i < MAXFILES; fiop++, ++i) { - char *tname; + /* + * note any other files that we can find + */ + fiop = &files[3]; + for (i = 3; i < MAXFILES; fiop++, ++i) { + char *tname; - fiop->name = NULL; - files[idnum].reading = true; - files[idnum].writing = true; - files[idnum].action = 0; - memset(files[idnum].mode, 0, MODE_LEN+1); - /* - * stat the descriptor to see what we have - */ - if (fstat(i, &sbuf) >= 0) { - size_t snprintf_len; /* malloced snprintf length */ - fp = (FILE *) fdopen(i,"r+"); /*guess mode*/ - if (fp) { - strlcpy(files[idnum].mode, "r+", - sizeof(files[idnum].mode)); - } else { - fp = (FILE *) fdopen(i, "r"); - if (fp) { - strlcpy(files[idnum].mode, "r", - sizeof(files[idnum].mode)); - files[idnum].writing = false; - } else { - fp = (FILE *) fdopen(i, "w"); - if (fp) { - strlcpy(files[idnum].mode, "w", - sizeof(files[idnum].mode)); - files[idnum].reading = false; - } - else - continue; - } - } - snprintf_len = - sizeof("descriptor[12345678901234567890]") + 1; - tname = (char *)malloc(snprintf_len+1); - if (tname == NULL) { - math_error("Out of memory for init_file"); - not_reached(); - } - snprintf(tname, snprintf_len, "descriptor[%d]", i); - tname[snprintf_len] = '\0'; /* paranoia */ - files[idnum].name = tname; - files[idnum].id = idnum; - files[idnum].fp = fp; - files[idnum].dev = sbuf.st_dev; - files[idnum].inode = sbuf.st_ino; - ioindex[idnum] = idnum; - idnum++; - lastid++; - } - } + fiop->name = NULL; + files[idnum].reading = true; + files[idnum].writing = true; + files[idnum].action = 0; + memset(files[idnum].mode, 0, MODE_LEN+1); + /* + * stat the descriptor to see what we have + */ + if (fstat(i, &sbuf) >= 0) { + size_t snprintf_len; /* malloced snprintf length */ + fp = (FILE *) fdopen(i,"r+"); /*guess mode*/ + if (fp) { + strlcpy(files[idnum].mode, "r+", + sizeof(files[idnum].mode)); + } else { + fp = (FILE *) fdopen(i, "r"); + if (fp) { + strlcpy(files[idnum].mode, "r", + sizeof(files[idnum].mode)); + files[idnum].writing = false; + } else { + fp = (FILE *) fdopen(i, "w"); + if (fp) { + strlcpy(files[idnum].mode, "w", + sizeof(files[idnum].mode)); + files[idnum].reading = false; + } + else + continue; + } + } + snprintf_len = + sizeof("descriptor[12345678901234567890]") + 1; + tname = (char *)malloc(snprintf_len+1); + if (tname == NULL) { + math_error("Out of memory for init_file"); + not_reached(); + } + snprintf(tname, snprintf_len, "descriptor[%d]", i); + tname[snprintf_len] = '\0'; /* paranoia */ + files[idnum].name = tname; + files[idnum].id = idnum; + files[idnum].fp = fp; + files[idnum].dev = sbuf.st_dev; + files[idnum].inode = sbuf.st_ino; + ioindex[idnum] = idnum; + idnum++; + lastid++; + } + } - done = 1; + done = 1; } } @@ -207,120 +207,120 @@ file_init(void) * It will canonicalize the file open mode string. * * given: - * fiop pointer to FILEIO structure to initialize - * name associated filename (NULL => caller will setup filename) - * mode open mode (one of {r,w,a}{,b}{,+}) - * sbufp pointer to stat of open file - * id calc file ID - * fp open file stream + * fiop pointer to FILEIO structure to initialize + * name associated filename (NULL => caller will setup filename) + * mode open mode (one of {r,w,a}{,b}{,+}) + * sbufp pointer to stat of open file + * id calc file ID + * fp open file stream */ S_FUNC void init_fileio(FILEIO *fiop, char *name, char *mode, - struct stat *sbufp, FILEID id, FILE *fp) + struct stat *sbufp, FILEID id, FILE *fp) { - char modestr[MODE_LEN+1]; /* mode [rwa]b?\+? */ - size_t namelen; /* length of name */ + char modestr[MODE_LEN+1]; /* mode [rwa]b?\+? */ + size_t namelen; /* length of name */ - /* clear modestr */ - memset(modestr, 0, sizeof(modestr)); + /* clear modestr */ + memset(modestr, 0, sizeof(modestr)); - /* allocate filename if requested */ - namelen = 0; - if (name != NULL) { - namelen = strlen(name); - fiop->name = (char *)malloc(namelen + 1); - if (fiop->name == NULL) { - math_error("No memory for filename"); - not_reached(); - } - } + /* allocate filename if requested */ + namelen = 0; + if (name != NULL) { + namelen = strlen(name); + fiop->name = (char *)malloc(namelen + 1); + if (fiop->name == NULL) { + math_error("No memory for filename"); + not_reached(); + } + } - /* initialize FILEIO structure */ - if (name != NULL) { - strlcpy(fiop->name, name, namelen+1); - } - fiop->id = id; - fiop->fp = fp; - fiop->dev = sbufp->st_dev; - fiop->inode = sbufp->st_ino; - fiop->reading = false; - fiop->writing = false; - fiop->appending = false; - fiop->binary = false; - fiop->action = 0; - memset(fiop->mode, 0, sizeof(fiop->mode)); + /* initialize FILEIO structure */ + if (name != NULL) { + strlcpy(fiop->name, name, namelen+1); + } + fiop->id = id; + fiop->fp = fp; + fiop->dev = sbufp->st_dev; + fiop->inode = sbufp->st_ino; + fiop->reading = false; + fiop->writing = false; + fiop->appending = false; + fiop->binary = false; + fiop->action = 0; + memset(fiop->mode, 0, sizeof(fiop->mode)); - /* - * determine file open mode - * - * While a leading 'r' is for reading and a leading 'w' is - * for writing, the presence of a '+' in the string means - * both reading and writing. A leading 'a' means append - * which is writing. - */ - /* canonicalize read modes */ - if (mode[0] == 'r') { + /* + * determine file open mode + * + * While a leading 'r' is for reading and a leading 'w' is + * for writing, the presence of a '+' in the string means + * both reading and writing. A leading 'a' means append + * which is writing. + */ + /* canonicalize read modes */ + if (mode[0] == 'r') { - /* note read mode */ - strlcpy(modestr, "r", sizeof(modestr)); - fiop->reading = true; + /* note read mode */ + strlcpy(modestr, "r", sizeof(modestr)); + fiop->reading = true; - /* note binary mode even though mode is not used / ignored */ - if (strchr(mode, 'b') != NULL) { - strlcat(modestr, "b", sizeof(modestr)); - } + /* note binary mode even though mode is not used / ignored */ + if (strchr(mode, 'b') != NULL) { + strlcat(modestr, "b", sizeof(modestr)); + } - /* note if reading and writing */ - if (strchr(mode, '+') != NULL) { - fiop->writing = true; - strlcat(modestr, "+", sizeof(modestr)); - } + /* note if reading and writing */ + if (strchr(mode, '+') != NULL) { + fiop->writing = true; + strlcat(modestr, "+", sizeof(modestr)); + } - /* canonicalize write modes */ - } else if (mode[0] == 'w') { + /* canonicalize write modes */ + } else if (mode[0] == 'w') { - /* note write mode */ - strlcpy(modestr, "w", sizeof(modestr)); - fiop->writing = true; + /* note write mode */ + strlcpy(modestr, "w", sizeof(modestr)); + fiop->writing = true; - /* note binary mode even though mode is not used / ignored */ - if (strchr(mode, 'b') != NULL) { - strlcat(modestr, "b", sizeof(modestr)); - } + /* note binary mode even though mode is not used / ignored */ + if (strchr(mode, 'b') != NULL) { + strlcat(modestr, "b", sizeof(modestr)); + } - /* note if reading and writing */ - if (strchr(mode, '+') != NULL) { - fiop->reading = true; - strlcat(modestr, "+", sizeof(modestr)); - } + /* note if reading and writing */ + if (strchr(mode, '+') != NULL) { + fiop->reading = true; + strlcat(modestr, "+", sizeof(modestr)); + } - /* canonicalize append modes */ - } else if (mode[0] == 'a') { + /* canonicalize append modes */ + } else if (mode[0] == 'a') { - /* note append mode */ - strlcpy(modestr, "a", sizeof(modestr)); - fiop->writing = true; - fiop->appending = true; + /* note append mode */ + strlcpy(modestr, "a", sizeof(modestr)); + fiop->writing = true; + fiop->appending = true; - /* note binary mode even though mode is not used / ignored */ - if (strchr(mode, 'b') != NULL) { - strlcat(modestr, "b", sizeof(modestr)); - } + /* note binary mode even though mode is not used / ignored */ + if (strchr(mode, 'b') != NULL) { + strlcat(modestr, "b", sizeof(modestr)); + } - /* note if reading and writing */ - if (strchr(mode, '+') != NULL) { - fiop->reading = true; - strlcat(modestr, "+", sizeof(modestr)); - } + /* note if reading and writing */ + if (strchr(mode, '+') != NULL) { + fiop->reading = true; + strlcat(modestr, "+", sizeof(modestr)); + } - /* canonicalize no I/O modes */ - } else { - modestr[0] = '\0'; - } - modestr[MODE_LEN] = '\0'; /* firewall */ + /* canonicalize no I/O modes */ + } else { + modestr[0] = '\0'; + } + modestr[MODE_LEN] = '\0'; /* firewall */ - /* record canonical open mode string */ - strlcpy(fiop->mode, modestr, sizeof(fiop->mode)); + /* record canonical open mode string */ + strlcpy(fiop->mode, modestr, sizeof(fiop->mode)); } @@ -328,132 +328,132 @@ init_fileio(FILEIO *fiop, char *name, char *mode, * openid - open the specified file name for reading or writing * * given: - * name file name - * mode open mode (one of {r,w,a}{,b}{,+}) + * name file name + * mode open mode (one of {r,w,a}{,b}{,+}) * * returns: - * >=3 FILEID which can be used to do I/O to the file - * <0 if the open failed + * >=3 FILEID which can be used to do I/O to the file + * <0 if the open failed * * NOTE: This function will not return 0, 1 or 2 since they are - * reserved for stdin, stdout, stderr. In fact, it must not - * return 0, 1, or 2 because it will confuse those who call - * the opensearchfile() function + * reserved for stdin, stdout, stderr. In fact, it must not + * return 0, 1, or 2 because it will confuse those who call + * the opensearchfile() function */ FILEID openid(char *name, char *mode) { - FILEIO *fiop; /* file structure */ - FILEID id; /* new file id */ - FILE *fp; - struct stat sbuf; /* file status */ - int i; + FILEIO *fiop; /* file structure */ + FILEID id; /* new file id */ + FILE *fp; + struct stat sbuf; /* file status */ + int i; - /* find the next open slot in the files array */ - if (idnum >= MAXFILES) - return -E_MANYOPEN; - fiop = &files[3]; - for (i = 3; i < MAXFILES; fiop++,i++) { - if (fiop->name == NULL) - break; - } - if (i == MAXFILES) - math_error("This should not happen in openid()!!!"); + /* find the next open slot in the files array */ + if (idnum >= MAXFILES) + return -E_MANYOPEN; + fiop = &files[3]; + for (i = 3; i < MAXFILES; fiop++,i++) { + if (fiop->name == NULL) + break; + } + if (i == MAXFILES) + math_error("This should not happen in openid()!!!"); - /* open the file */ - fp = f_open(name, mode); - if (fp == NULL) { - return FILEID_NONE; - } - if (fstat(fileno(fp), &sbuf) < 0) { - math_error("bad fstat"); - not_reached(); - } + /* open the file */ + fp = f_open(name, mode); + if (fp == NULL) { + return FILEID_NONE; + } + if (fstat(fileno(fp), &sbuf) < 0) { + math_error("bad fstat"); + not_reached(); + } - /* get a new FILEID */ - id = ++lastid; - ioindex[idnum++] = i; + /* get a new FILEID */ + id = ++lastid; + ioindex[idnum++] = i; - /* initialize FILEIO structure */ - init_fileio(fiop, name, mode, &sbuf, id, fp); + /* initialize FILEIO structure */ + init_fileio(fiop, name, mode, &sbuf, id, fp); - /* return calc open file ID */ - return id; + /* return calc open file ID */ + return id; } /* * openpathid - open the specified base filename, or - * relative filename along a search path + * relative filename along a search path * * given: - * name file name - * mode open mode (one of {r,w,a}{,b}{,+}) - * pathlist list of colon separated paths (or NULL) + * name file name + * mode open mode (one of {r,w,a}{,b}{,+}) + * pathlist list of colon separated paths (or NULL) * * returns: - * >=3 FILEID which can be used to do I/O to the file - * <0 if the open failed + * >=3 FILEID which can be used to do I/O to the file + * <0 if the open failed * * NOTE: This function will not return 0, 1 or 2 since they are - * reserved for stdin, stdout, stderr. In fact, it must not - * return 0, 1, or 2 because it will confuse those who call - * the opensearchfile() function + * reserved for stdin, stdout, stderr. In fact, it must not + * return 0, 1, or 2 because it will confuse those who call + * the opensearchfile() function */ FILEID openpathid(char *name, char *mode, char *pathlist) { - FILEIO *fiop; /* file structure */ - FILEID id; /* new file id */ - FILE *fp; - struct stat sbuf; /* file status */ - char *openpath; /* malloc copy of path that was opened */ - int i; + FILEIO *fiop; /* file structure */ + FILEID id; /* new file id */ + FILE *fp; + struct stat sbuf; /* file status */ + char *openpath; /* malloc copy of path that was opened */ + int i; - /* find the next open slot in the files array */ - if (idnum >= MAXFILES) - return -E_MANYOPEN; - fiop = &files[3]; - for (i = 3; i < MAXFILES; fiop++,i++) { - if (fiop->name == NULL) - break; - } - if (i == MAXFILES) - math_error("This should not happen in openpathid()!!!"); + /* find the next open slot in the files array */ + if (idnum >= MAXFILES) + return -E_MANYOPEN; + fiop = &files[3]; + for (i = 3; i < MAXFILES; fiop++,i++) { + if (fiop->name == NULL) + break; + } + if (i == MAXFILES) + math_error("This should not happen in openpathid()!!!"); - /* open a file - searching along a path */ - openpath = NULL; - fp = f_pathopen(name, mode, pathlist, &openpath); - if (fp == NULL) { - if (openpath != NULL) { - /* should not happen, but just in case */ - free(openpath); - } - return FILEID_NONE; - } - if (fstat(fileno(fp), &sbuf) < 0) { - if (openpath != NULL) { - free(openpath); - } - math_error("bad fstat"); - not_reached(); - } - if (openpath == NULL) { - fclose(fp); - math_error("bad openpath"); - not_reached(); - } + /* open a file - searching along a path */ + openpath = NULL; + fp = f_pathopen(name, mode, pathlist, &openpath); + if (fp == NULL) { + if (openpath != NULL) { + /* should not happen, but just in case */ + free(openpath); + } + return FILEID_NONE; + } + if (fstat(fileno(fp), &sbuf) < 0) { + if (openpath != NULL) { + free(openpath); + } + math_error("bad fstat"); + not_reached(); + } + if (openpath == NULL) { + fclose(fp); + math_error("bad openpath"); + not_reached(); + } - /* get a new FILEID */ - id = ++lastid; - ioindex[idnum++] = i; + /* get a new FILEID */ + id = ++lastid; + ioindex[idnum++] = i; - /* initialize FILEIO structure */ - init_fileio(fiop, NULL, mode, &sbuf, id, fp); - fiop->name = openpath; /* already malloced by f_pathopen */ + /* initialize FILEIO structure */ + init_fileio(fiop, NULL, mode, &sbuf, id, fp); + fiop->name = openpath; /* already malloced by f_pathopen */ - /* return calc open file ID */ - return id; + /* return calc open file ID */ + return id; } @@ -461,93 +461,93 @@ openpathid(char *name, char *mode, char *pathlist) * reopenid - reopen a FILEID * * given: - * id FILEID to reopen - * mode new mode to open as - * mode new mode to open as (one of "r", "w", "a", "r+", "w+", "a+") - * name name of new file + * id FILEID to reopen + * mode new mode to open as + * mode new mode to open as (one of "r", "w", "a", "r+", "w+", "a+") + * name name of new file * * returns: - * FILEID which can be used to do I/O to the file - * <0 if the open failed + * FILEID which can be used to do I/O to the file + * <0 if the open failed */ FILEID reopenid(FILEID id, char *mode, char *name) { - FILEIO *fiop; /* file structure */ - FILE *fp; - struct stat sbuf; - int i; + FILEIO *fiop; /* file structure */ + FILE *fp; + struct stat sbuf; + int i; - /* firewall */ - if ((id == FILEID_STDIN) || (id == FILEID_STDOUT) || - (id == FILEID_STDERR)) { - math_error("Cannot freopen stdin, stdout, or stderr"); - not_reached(); - } + /* firewall */ + if ((id == FILEID_STDIN) || (id == FILEID_STDOUT) || + (id == FILEID_STDERR)) { + math_error("Cannot freopen stdin, stdout, or stderr"); + not_reached(); + } - /* reopen the file */ - fiop = NULL; - for (i = 3; i < idnum; i++) { - fiop = &files[ioindex[i]]; - if (fiop->id == id) - break; - } - if (i == idnum) { - if (name == NULL) { - fprintf(stderr, "File not open, need file name\n"); - return FILEID_NONE; - } - if (idnum >= MAXFILES) { - fprintf(stderr, "Too many open files\n"); - return FILEID_NONE; - } - for (fiop = &files[3], i = 3; i < MAXFILES; fiop++, i++) { - if (fiop->name == NULL) - break; - } - if (i >= MAXFILES) { - math_error("This should not happen in reopenid"); - not_reached(); - } - fp = f_open(name, mode); - if (fp == NULL) { - fprintf(stderr, "Cannot open file\n"); - return FILEID_NONE; - } - ioindex[idnum++] = i; - fiop->id = id; - } else { - if (name == NULL) - fp = freopen(fiop->name, mode, fiop->fp); - else - fp = freopen(name, mode, fiop->fp); - if (fp == NULL) { - free(fiop->name); - fiop->name = NULL; - idnum--; - for (; i < idnum; i++) - ioindex[i] = ioindex[i + 1]; - return FILEID_NONE; - } - } - if (fstat(fileno(fp), &sbuf) < 0) { - math_error("bad fstat"); - not_reached(); - } + /* reopen the file */ + fiop = NULL; + for (i = 3; i < idnum; i++) { + fiop = &files[ioindex[i]]; + if (fiop->id == id) + break; + } + if (i == idnum) { + if (name == NULL) { + fprintf(stderr, "File not open, need file name\n"); + return FILEID_NONE; + } + if (idnum >= MAXFILES) { + fprintf(stderr, "Too many open files\n"); + return FILEID_NONE; + } + for (fiop = &files[3], i = 3; i < MAXFILES; fiop++, i++) { + if (fiop->name == NULL) + break; + } + if (i >= MAXFILES) { + math_error("This should not happen in reopenid"); + not_reached(); + } + fp = f_open(name, mode); + if (fp == NULL) { + fprintf(stderr, "Cannot open file\n"); + return FILEID_NONE; + } + ioindex[idnum++] = i; + fiop->id = id; + } else { + if (name == NULL) + fp = freopen(fiop->name, mode, fiop->fp); + else + fp = freopen(name, mode, fiop->fp); + if (fp == NULL) { + free(fiop->name); + fiop->name = NULL; + idnum--; + for (; i < idnum; i++) + ioindex[i] = ioindex[i + 1]; + return FILEID_NONE; + } + } + if (fstat(fileno(fp), &sbuf) < 0) { + math_error("bad fstat"); + not_reached(); + } - /* initialize FILEIO structure */ - if (name == NULL) { - if (fiop->name == NULL) { - math_error("old and new reopen filenames are NULL"); - } - } else if (fiop->name != NULL) { - free(fiop->name); - fiop->name = NULL; - } - init_fileio(fiop, name, mode, &sbuf, id, fp); + /* initialize FILEIO structure */ + if (name == NULL) { + if (fiop->name == NULL) { + math_error("old and new reopen filenames are NULL"); + } + } else if (fiop->name != NULL) { + free(fiop->name); + fiop->name = NULL; + } + init_fileio(fiop, name, mode, &sbuf, id, fp); - /* return calc open file ID */ - return id; + /* return calc open file ID */ + return id; } @@ -560,30 +560,30 @@ reopenid(FILEID id, char *mode, char *name) FILEIO * findid(FILEID id, int writable) { - FILEIO *fiop; /* file structure */ - int i; + FILEIO *fiop; /* file structure */ + int i; - fiop = NULL; + fiop = NULL; - if ((id < 0) || (id > lastid)) - return NULL; + if ((id < 0) || (id > lastid)) + return NULL; - for (i = 0; i < idnum; i++) { - fiop = &files[ioindex[i]]; - if (fiop->id == id) - break; - } + for (i = 0; i < idnum; i++) { + fiop = &files[ioindex[i]]; + if (fiop->id == id) + break; + } - if (i == idnum) - return NULL; + if (i == idnum) + return NULL; - if (writable >= 0) { - if ((writable && !fiop->writing) || - (!writable && !fiop->reading)) { - return NULL; - } - } - return fiop; + if (writable >= 0) { + if ((writable && !fiop->writing) || + (!writable && !fiop->reading)) { + return NULL; + } + } + return fiop; } @@ -593,7 +593,7 @@ findid(FILEID id, int writable) bool validid(FILEID id) { - return (findid(id, -1) != NULL); + return (findid(id, -1) != NULL); } @@ -604,80 +604,80 @@ validid(FILEID id) FILEID indexid(long index) { - FILEID id; + FILEID id; - id = (FILEID) index; + id = (FILEID) index; - if ((index < 0) || (id > lastid)) - return FILEID_NONE; - return id; + if ((index < 0) || (id > lastid)) + return FILEID_NONE; + return id; } /* - * Close the specified file id. Returns true if there was an error. + * Close the specified file id. Returns true if there was an error. * Closing of stdin, stdout, or stderr is illegal, but closing of already * closed files is allowed. */ int closeid(FILEID id) { - FILEIO *fiop; /* file structure */ - int i; - int err; + FILEIO *fiop; /* file structure */ + int i; + int err; - fiop = NULL; + fiop = NULL; - /* firewall */ - if ((id == FILEID_STDIN) || (id == FILEID_STDOUT) || - (id == FILEID_STDERR)) { - math_error("Cannot close stdin, stdout, or stderr"); - not_reached(); - } + /* firewall */ + if ((id == FILEID_STDIN) || (id == FILEID_STDOUT) || + (id == FILEID_STDERR)) { + math_error("Cannot close stdin, stdout, or stderr"); + not_reached(); + } - /* get file structure */ - for (i = 3; i < idnum; i++) { - fiop = &files[ioindex[i]]; - if (fiop->id == id) - break; - } - if (i == idnum) - return 1; /* File not open */ - idnum--; - for (; i < idnum; i++) - ioindex[i] = ioindex[i + 1]; + /* get file structure */ + for (i = 3; i < idnum; i++) { + fiop = &files[ioindex[i]]; + if (fiop->id == id) + break; + } + if (i == idnum) + return 1; /* File not open */ + idnum--; + for (; i < idnum; i++) + ioindex[i] = ioindex[i + 1]; - free(fiop->name); - fiop->name = NULL; + free(fiop->name); + fiop->name = NULL; - /* close file and note error state */ - err = ferror(fiop->fp); - err |= fclose(fiop->fp); - fiop->fp = NULL; + /* close file and note error state */ + err = ferror(fiop->fp); + err |= fclose(fiop->fp); + fiop->fp = NULL; - /* return success or failure */ - return (err ? EOF : 0); + /* return success or failure */ + return (err ? EOF : 0); } int closeall(void) { - FILEIO *fiop; - int i; - int err; + FILEIO *fiop; + int i; + int err; - err = 0; - for (i = 3; i < idnum; i++) { - fiop = &files[ioindex[i]]; - if (fiop->fp) { - free(fiop->name); - fiop->name = NULL; - err |= fclose(fiop->fp); - } - } - idnum = 3; - return err; + err = 0; + for (i = 3; i < idnum; i++) { + fiop = &files[ioindex[i]]; + if (fiop->fp) { + free(fiop->name); + fiop->name = NULL; + err |= fclose(fiop->fp); + } + } + idnum = 3; + return err; } @@ -687,12 +687,12 @@ closeall(void) bool errorid(FILEID id) { - FILEIO *fiop; /* file structure */ + FILEIO *fiop; /* file structure */ - fiop = findid(id, -1); - if (fiop == NULL) - return EOF; - return (ferror(fiop->fp) != 0); + fiop = findid(id, -1); + if (fiop == NULL) + return EOF; + return (ferror(fiop->fp) != 0); } @@ -702,12 +702,12 @@ errorid(FILEID id) bool eofid(FILEID id) { - FILEIO *fiop; /* file structure */ + FILEIO *fiop; /* file structure */ - fiop = findid(id, -1); - if (fiop == NULL) - return EOF; - return (feof(fiop->fp) != 0); + fiop = findid(id, -1); + if (fiop == NULL) + return EOF; + return (feof(fiop->fp) != 0); } @@ -717,14 +717,14 @@ eofid(FILEID id) int flushid(FILEID id) { - FILEIO *fiop; /* file structure */ + FILEIO *fiop; /* file structure */ - fiop = findid(id, -1); - if (fiop == NULL) - return 0; - if (!fiop->writing || fiop->action == 'r') - return 0; - return fflush(fiop->fp); + fiop = findid(id, -1); + if (fiop == NULL) + return 0; + if (!fiop->writing || fiop->action == 'r') + return 0; + return fflush(fiop->fp); } @@ -732,17 +732,17 @@ flushid(FILEID id) int flushall(void) { - FILEIO *fiop; - int i; - int err; + FILEIO *fiop; + int i; + int err; - err = 0; - for (i = 3; i < idnum; i++) { - fiop = &files[ioindex[i]]; - if (fiop->writing && fiop->action != 'r') - err |= fflush(fiop->fp); - } - return err; + err = 0; + for (i = 3; i < idnum; i++) { + fiop = &files[ioindex[i]]; + if (fiop->writing && fiop->action != 'r') + err |= fflush(fiop->fp); + } + return err; } #endif /* Windows free systems */ @@ -753,107 +753,107 @@ flushall(void) * or newline terminated string. Where reading stops is controlled by * flags: * - * bit 0: at newline - * bit 1: at null character - * bit 2: at white space (also skips leading white space) + * bit 0: at newline + * bit 1: at null character + * bit 2: at white space (also skips leading white space) * * If neither '\n' nor '\0' is encountered reading continues until EOF. * If bit 3 is set the stop character is removed. * * given: - * id file to read from - * flags read flags (see above) - * retstr returned pointer to string + * id file to read from + * flags read flags (see above) + * retstr returned pointer to string */ int readid(FILEID id, int flags, STRING **retstr) { - FILEIO *fiop; /* file structure */ - FILE *fp; - char *str; /* current string */ - unsigned long n; /* current number characters read into buf */ - unsigned long totlen; /* total length of string copied from buf */ - char buf[READSIZE]; /* temporary buffer */ - char *b; - int c; - bool nlstop, nullstop, wsstop, rmstop, done; - FILEPOS fpos; - STRING *newstr; + FILEIO *fiop; /* file structure */ + FILE *fp; + char *str; /* current string */ + unsigned long n; /* current number characters read into buf */ + unsigned long totlen; /* total length of string copied from buf */ + char buf[READSIZE]; /* temporary buffer */ + char *b; + int c; + bool nlstop, nullstop, wsstop, rmstop, done; + FILEPOS fpos; + STRING *newstr; - totlen = 0; - str = NULL; + totlen = 0; + str = NULL; - fiop = findid(id, false); - if (fiop == NULL) - return 1; - nlstop = (flags & 1); - nullstop = (flags & 2); - wsstop = (flags & 4); - rmstop = (flags & 8); + fiop = findid(id, false); + if (fiop == NULL) + return 1; + nlstop = (flags & 1); + nullstop = (flags & 2); + wsstop = (flags & 4); + rmstop = (flags & 8); - fp = fiop->fp; + fp = fiop->fp; - if (fiop->action == 'w') { - f_tell(fp, &fpos); - fflush(fp); - if (f_seek_set(fp, &fpos) < 0) - return 3; - } - fiop->action = 'r'; + if (fiop->action == 'w') { + f_tell(fp, &fpos); + fflush(fp); + if (f_seek_set(fp, &fpos) < 0) + return 3; + } + fiop->action = 'r'; - if (wsstop) { - while (isspace(c = fgetc(fp))); - ungetc(c, fp); - } + if (wsstop) { + while (isspace(c = fgetc(fp))); + ungetc(c, fp); + } - for (;;) { - b = buf; - n = 0; - do { - c = fgetc(fp); - if (c == EOF) - break; - n++; - if (nlstop && c == '\n') - break; - if (nullstop && c == '\0') - break; - if (wsstop && isspace(c)) - break; - *b++ = c; - } while (n < READSIZE); - done = ((nlstop && c == '\n') || (nullstop && c == '\0') || - (wsstop && isspace(c)) || c == EOF); - if (done && rmstop && c != EOF) - n--; - if (totlen) - str = (char *)realloc(str, totlen + n + 1); - else - str = (char *)malloc(n + 1); - if (str == NULL) { - math_error("Out of memory for readid"); - not_reached(); - } - if (n > 0) - memcpy(&str[totlen], buf, n); - totlen += n; - if (done) - break; - } - if (totlen == 0 && c == EOF) { - free(str); - return EOF; - } - if ((nlstop && c == '\n') && !rmstop) - str[totlen - 1] = '\n'; - if ((nullstop && c == '\0') && !rmstop) - str[totlen - 1] = '\0'; - str[totlen] = '\0'; - newstr = stralloc(); - newstr->s_len = totlen; - newstr->s_str = str; - *retstr = newstr; - return 0; + for (;;) { + b = buf; + n = 0; + do { + c = fgetc(fp); + if (c == EOF) + break; + n++; + if (nlstop && c == '\n') + break; + if (nullstop && c == '\0') + break; + if (wsstop && isspace(c)) + break; + *b++ = c; + } while (n < READSIZE); + done = ((nlstop && c == '\n') || (nullstop && c == '\0') || + (wsstop && isspace(c)) || c == EOF); + if (done && rmstop && c != EOF) + n--; + if (totlen) + str = (char *)realloc(str, totlen + n + 1); + else + str = (char *)malloc(n + 1); + if (str == NULL) { + math_error("Out of memory for readid"); + not_reached(); + } + if (n > 0) + memcpy(&str[totlen], buf, n); + totlen += n; + if (done) + break; + } + if (totlen == 0 && c == EOF) { + free(str); + return EOF; + } + if ((nlstop && c == '\n') && !rmstop) + str[totlen - 1] = '\n'; + if ((nullstop && c == '\0') && !rmstop) + str[totlen - 1] = '\0'; + str[totlen] = '\0'; + newstr = stralloc(); + newstr->s_len = totlen; + newstr->s_str = str; + *retstr = newstr; + return 0; } @@ -864,21 +864,21 @@ readid(FILEID id, int flags, STRING **retstr) int getcharid(FILEID id) { - FILEIO *fiop; - FILEPOS fpos; + FILEIO *fiop; + FILEPOS fpos; - fiop = findid(id, false); - if (fiop == NULL) - return -2; - if (fiop->action == 'w') { - f_tell(fiop->fp, &fpos); - fflush(fiop->fp); - if (f_seek_set(fiop->fp, &fpos) < 0) - return -3; - } - fiop->action = 'r'; + fiop = findid(id, false); + if (fiop == NULL) + return -2; + if (fiop->action == 'w') { + f_tell(fiop->fp, &fpos); + fflush(fiop->fp); + if (f_seek_set(fiop->fp, &fpos) < 0) + return -3; + } + fiop->action = 'r'; - return fgetc(fiop->fp); + return fgetc(fiop->fp); } @@ -891,309 +891,309 @@ getcharid(FILEID id) int printid(FILEID id, int flags) { - FILEIO *fiop; /* file structure */ - FILE *fp; - ZVALUE pos; /* file position */ + FILEIO *fiop; /* file structure */ + FILE *fp; + ZVALUE pos; /* file position */ - /* - * filewall - file is closed - */ - fiop = findid(id, -1); - if (fiop == NULL) { - if (flags & PRINT_UNAMBIG) - math_fmt("FILE %ld closed", id); - else - math_str("\"\""); - return 1; - } + /* + * filewall - file is closed + */ + fiop = findid(id, -1); + if (fiop == NULL) { + if (flags & PRINT_UNAMBIG) + math_fmt("FILE %ld closed", id); + else + math_str("\"\""); + return 1; + } - /* - * print quoted filename and mode - */ - if ((flags & PRINT_UNAMBIG) == 0) { - math_chr('"'); - math_str(fiop->name); - math_chr('"'); - return 0; - } - math_fmt("FILE %ld \"%s\" (%s", id, fiop->name, fiop->mode); + /* + * print quoted filename and mode + */ + if ((flags & PRINT_UNAMBIG) == 0) { + math_chr('"'); + math_str(fiop->name); + math_chr('"'); + return 0; + } + math_fmt("FILE %ld \"%s\" (%s", id, fiop->name, fiop->mode); - /* - * print file position - */ + /* + * print file position + */ - fp = fiop->fp; + fp = fiop->fp; - if (get_open_pos(fp, &pos) < 0) { - if (fileno(fp) > 2) - math_str("Error while determining file position!"); - math_chr(')'); - return 0; - } + if (get_open_pos(fp, &pos) < 0) { + if (fileno(fp) > 2) + math_str("Error while determining file position!"); + math_chr(')'); + return 0; + } - math_str(", pos "); - zprintval(pos, 0, 0); - zfree(pos); + math_str(", pos "); + zprintval(pos, 0, 0); + zfree(pos); - /* - * report special status - */ - if (ferror(fp)) - math_str(", error"); - if (feof(fp)) - math_str(", eof"); - math_chr(')'); + /* + * report special status + */ + if (ferror(fp)) + math_str(", error"); + if (feof(fp)) + math_str(", eof"); + math_chr(')'); - printf(" fileno: %d ", fileno(fp)); - return 0; + printf(" fileno: %d ", fileno(fp)); + return 0; } /* - * Print a formatted string similar to printf. Various formats of output + * Print a formatted string similar to printf. Various formats of output * are possible, depending on the format string AND the actual types of the * values. Mismatches do not cause errors, instead something reasonable is * printed instead. The output goes to the file with the specified id. * * given: - * id file id to print to - * count print count - * fmt standard format string - * vals table of values to print + * id file id to print to + * count print count + * fmt standard format string + * vals table of values to print */ int idprintf(FILEID id, char *fmt, int count, VALUE **vals) { - FILEIO *fiop; - VALUE *vp; - char *str; - int ch; - size_t len; - int oldmode, newmode; - long olddigits, newdigits; - long width, precision; - bool didneg, didprecision; - FILEPOS fpos; - bool printstring; - bool printchar; + FILEIO *fiop; + VALUE *vp; + char *str; + int ch; + size_t len; + int oldmode, newmode; + long olddigits, newdigits; + long width, precision; + bool didneg, didprecision; + FILEPOS fpos; + bool printstring; + bool printchar; - fiop = findid(id, true); - if (fiop == NULL) - return 1; - if (fiop->action == 'r') { - f_tell(fiop->fp, &fpos); - if (f_seek_set(fiop->fp, &fpos) < 0) - return 3; - } + fiop = findid(id, true); + if (fiop == NULL) + return 1; + if (fiop->action == 'r') { + f_tell(fiop->fp, &fpos); + if (f_seek_set(fiop->fp, &fpos) < 0) + return 3; + } - fiop->action = 'w'; + fiop->action = 'w'; - printstring = false; - printchar = false; + printstring = false; + printchar = false; - math_setfp(fiop->fp); + math_setfp(fiop->fp); - while ((ch = *fmt++) != '\0') { - if (ch != '%') { - math_chr(ch); - continue; - } + while ((ch = *fmt++) != '\0') { + if (ch != '%') { + math_chr(ch); + continue; + } - /* - * Here to handle formats. - */ - didneg = false; - didprecision = false; - width = 0; - precision = 0; + /* + * Here to handle formats. + */ + didneg = false; + didprecision = false; + width = 0; + precision = 0; - ch = *fmt++; - if (ch == '-') { - didneg = true; - ch = *fmt++; - } - while ((ch >= '0') && (ch <= '9')) { - width = width * 10 + (ch - '0'); - ch = *fmt++; - } - if (ch == '.') { - didprecision = true; - ch = *fmt++; - while ((ch >= '0') && (ch <= '9')) { - precision = precision * 10 + (ch - '0'); - ch = *fmt++; - } - } - if (ch == 'l') - ch = *fmt++; + ch = *fmt++; + if (ch == '-') { + didneg = true; + ch = *fmt++; + } + while ((ch >= '0') && (ch <= '9')) { + width = width * 10 + (ch - '0'); + ch = *fmt++; + } + if (ch == '.') { + didprecision = true; + ch = *fmt++; + while ((ch >= '0') && (ch <= '9')) { + precision = precision * 10 + (ch - '0'); + ch = *fmt++; + } + } + if (ch == 'l') + ch = *fmt++; - oldmode = conf->outmode; - newmode = oldmode; - olddigits = conf->outdigits; - newdigits = olddigits; - if (didprecision) - newdigits = precision; + oldmode = conf->outmode; + newmode = oldmode; + olddigits = conf->outdigits; + newdigits = olddigits; + if (didprecision) + newdigits = precision; - switch (ch) { - case 's': - printstring = true; - /*FALLTHRU*/ - case 'c': - printchar = true; - case 'd': - break; - case 'f': - newmode = MODE_REAL; - break; - case 'e': - newmode = MODE_EXP; - break; - case 'n': - newmode = MODE_ENG; - break; - case 'g': - newmode = MODE_REAL_AUTO; - break; - case 'r': - newmode = MODE_FRAC; - break; - case 'o': - newmode = MODE_OCTAL; - break; - case 'x': - newmode = MODE_HEX; - break; - case 'b': - newmode = MODE_BINARY; - break; - case 0: - math_setfp(stdout); - return 0; - default: - math_chr(ch); - continue; - } + switch (ch) { + case 's': + printstring = true; + /*FALLTHRU*/ + case 'c': + printchar = true; + case 'd': + break; + case 'f': + newmode = MODE_REAL; + break; + case 'e': + newmode = MODE_EXP; + break; + case 'n': + newmode = MODE_ENG; + break; + case 'g': + newmode = MODE_REAL_AUTO; + break; + case 'r': + newmode = MODE_FRAC; + break; + case 'o': + newmode = MODE_OCTAL; + break; + case 'x': + newmode = MODE_HEX; + break; + case 'b': + newmode = MODE_BINARY; + break; + case 0: + math_setfp(stdout); + return 0; + default: + math_chr(ch); + continue; + } - if (--count < 0) { - while (width-- > 0) - math_chr(' '); - continue; - } - vp = *vals++; + if (--count < 0) { + while (width-- > 0) + math_chr(' '); + continue; + } + vp = *vals++; - math_setdigits(newdigits); - math_setmode(newmode); + math_setdigits(newdigits); + math_setmode(newmode); - /* - * If there is no width specification, or if the type of - * value requires multiple lines, then just output the - * value directly. - */ - if ((width == 0) || - (vp->v_type == V_MAT) || (vp->v_type == V_LIST)) { - switch(vp->v_type) { - case V_OCTET: - if (printstring) - math_str((char *)vp->v_octet); - else if (printchar) - math_chr(*vp->v_octet); - else - printvalue(vp, PRINT_NORMAL); - break; - case V_BLOCK: - if (printstring) - math_str((char *) - vp->v_block->data); - else if (printchar) - math_chr(*vp->v_block->data); - else - printvalue(vp, PRINT_NORMAL); - break; - case V_NBLOCK: - if (printstring) { - if (vp->v_nblock->blk->data != - NULL) - math_str((char *) - vp->v_nblock - ->blk->data); - } else if (printchar) { - if (vp->v_nblock->blk->data != - NULL) - math_chr(*vp->v_nblock-> - blk->data); - } else { - printvalue(vp, PRINT_NORMAL); - } - break; - default: - printvalue(vp, PRINT_NORMAL); - } + /* + * If there is no width specification, or if the type of + * value requires multiple lines, then just output the + * value directly. + */ + if ((width == 0) || + (vp->v_type == V_MAT) || (vp->v_type == V_LIST)) { + switch(vp->v_type) { + case V_OCTET: + if (printstring) + math_str((char *)vp->v_octet); + else if (printchar) + math_chr(*vp->v_octet); + else + printvalue(vp, PRINT_NORMAL); + break; + case V_BLOCK: + if (printstring) + math_str((char *) + vp->v_block->data); + else if (printchar) + math_chr(*vp->v_block->data); + else + printvalue(vp, PRINT_NORMAL); + break; + case V_NBLOCK: + if (printstring) { + if (vp->v_nblock->blk->data != + NULL) + math_str((char *) + vp->v_nblock + ->blk->data); + } else if (printchar) { + if (vp->v_nblock->blk->data != + NULL) + math_chr(*vp->v_nblock-> + blk->data); + } else { + printvalue(vp, PRINT_NORMAL); + } + break; + default: + printvalue(vp, PRINT_NORMAL); + } - math_setmode(oldmode); - math_setdigits(olddigits); - continue; - } + math_setmode(oldmode); + math_setdigits(olddigits); + continue; + } - /* - * There is a field width. Collect the output in a string, - * print it padded appropriately with spaces, and free it. - * However, if the output contains a newline, then ignore - * the field width. - */ - math_divertio(); - switch(vp->v_type) { - case V_OCTET: - if (printstring) - math_str((char *)vp->v_octet); - else if (printchar) - math_chr(*vp->v_octet); - else - printvalue(vp, PRINT_NORMAL); - break; - case V_BLOCK: - if (printstring) - math_str((char *)vp->v_block->data); - else if (printchar) - math_chr(*vp->v_block->data); - else - printvalue(vp, PRINT_NORMAL); - break; - case V_NBLOCK: - if (printstring) { - if (vp->v_nblock->blk->data != NULL) - math_str((char *) - vp->v_nblock->blk->data); - } - else if (printchar) { - if (vp->v_nblock->blk->data != NULL) - math_chr(*vp->v_nblock->blk->data); - } - else - printvalue(vp, PRINT_NORMAL); - break; - default: - printvalue(vp, PRINT_NORMAL); - } - str = math_getdivertedio(); - if (strchr(str, '\n')) - width = 0; - len = strlen(str); - while (!didneg && ((size_t)width > len)) { - width--; - math_chr(' '); - } - math_str(str); - free(str); - while (didneg && ((size_t)width > len)) { - width--; - math_chr(' '); - } - math_setmode(oldmode); - math_setdigits(olddigits); - } - math_setfp(stdout); - return 0; + /* + * There is a field width. Collect the output in a string, + * print it padded appropriately with spaces, and free it. + * However, if the output contains a newline, then ignore + * the field width. + */ + math_divertio(); + switch(vp->v_type) { + case V_OCTET: + if (printstring) + math_str((char *)vp->v_octet); + else if (printchar) + math_chr(*vp->v_octet); + else + printvalue(vp, PRINT_NORMAL); + break; + case V_BLOCK: + if (printstring) + math_str((char *)vp->v_block->data); + else if (printchar) + math_chr(*vp->v_block->data); + else + printvalue(vp, PRINT_NORMAL); + break; + case V_NBLOCK: + if (printstring) { + if (vp->v_nblock->blk->data != NULL) + math_str((char *) + vp->v_nblock->blk->data); + } + else if (printchar) { + if (vp->v_nblock->blk->data != NULL) + math_chr(*vp->v_nblock->blk->data); + } + else + printvalue(vp, PRINT_NORMAL); + break; + default: + printvalue(vp, PRINT_NORMAL); + } + str = math_getdivertedio(); + if (strchr(str, '\n')) + width = 0; + len = strlen(str); + while (!didneg && ((size_t)width > len)) { + width--; + math_chr(' '); + } + math_str(str); + free(str); + while (didneg && ((size_t)width > len)) { + width--; + math_chr(' '); + } + math_setmode(oldmode); + math_setdigits(olddigits); + } + math_setfp(stdout); + return 0; } @@ -1201,36 +1201,36 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals) * Write a character to a file. * * given: - * id file id to print to - * ch character to write + * id file id to print to + * ch character to write */ int idfputc(FILEID id, int ch) { - FILEIO *fiop; - FILEPOS fpos; + FILEIO *fiop; + FILEPOS fpos; - /* get the file info pointer */ - fiop = findid(id, true); - if (fiop == NULL) - return 1; - if (fiop->action == 'r') { - f_tell(fiop->fp, &fpos); - if (f_seek_set(fiop->fp, &fpos) < 0) - return 2; - } + /* get the file info pointer */ + fiop = findid(id, true); + if (fiop == NULL) + return 1; + if (fiop->action == 'r') { + f_tell(fiop->fp, &fpos); + if (f_seek_set(fiop->fp, &fpos) < 0) + return 2; + } - fiop->action = 'w'; + fiop->action = 'w'; - /* set output to file */ - math_setfp(fiop->fp); + /* set output to file */ + math_setfp(fiop->fp); - /* write char */ - math_chr(ch); + /* write char */ + math_chr(ch); - /* restore output to stdout */ - math_setfp(stdout); - return 0; + /* restore output to stdout */ + math_setfp(stdout); + return 0; } @@ -1238,20 +1238,20 @@ idfputc(FILEID id, int ch) * Unget a character read from a file. * * given: - * id file id to print to - * ch character to write + * id file id to print to + * ch character to write */ int idungetc(FILEID id, int ch) { - FILEIO *fiop; + FILEIO *fiop; - fiop = findid(id, false); - if (fiop == NULL) - return -2; - if (fiop->action != 'r') - return -2; - return ungetc(ch, fiop->fp); + fiop = findid(id, false); + if (fiop == NULL) + return -2; + if (fiop->action != 'r') + return -2; + return ungetc(ch, fiop->fp); } @@ -1259,39 +1259,39 @@ idungetc(FILEID id, int ch) * Write a string to a file. * * given: - * id file id to print to - * str string to write + * id file id to print to + * str string to write */ int idfputs(FILEID id, STRING *str) { - FILEIO *fiop; - FILEPOS fpos; - FILE *fp; - char *c; - long len; + FILEIO *fiop; + FILEPOS fpos; + FILE *fp; + char *c; + long len; - /* get the file info pointer */ - fiop = findid(id, true); - if (fiop == NULL) - return 1; + /* get the file info pointer */ + fiop = findid(id, true); + if (fiop == NULL) + return 1; - if (fiop->action == 'r') { - f_tell(fiop->fp, &fpos); - if (f_seek_set(fiop->fp, &fpos) < 0) - return 2; - } + if (fiop->action == 'r') { + f_tell(fiop->fp, &fpos); + if (f_seek_set(fiop->fp, &fpos) < 0) + return 2; + } - fiop->action = 'w'; + fiop->action = 'w'; - fp = fiop->fp; - len = str->s_len; - c = str->s_str; + fp = fiop->fp; + len = str->s_len; + c = str->s_str; - while (len-- > 0) - fputc(*c++, fp); + while (len-- > 0) + fputc(*c++, fp); - return 0; + return 0; } @@ -1299,68 +1299,68 @@ idfputs(FILEID id, STRING *str) * Same as idfputs but writes a terminating null character * * given: - * id file id to print to - * str string to write + * id file id to print to + * str string to write */ int idfputstr(FILEID id, char *str) { - FILEIO *fiop; - FILEPOS fpos; + FILEIO *fiop; + FILEPOS fpos; - /* get the file info pointer */ - fiop = findid(id, true); - if (fiop == NULL) - return 1; + /* get the file info pointer */ + fiop = findid(id, true); + if (fiop == NULL) + return 1; - if (fiop->action == 'r') { - f_tell(fiop->fp, &fpos); - if (f_seek_set(fiop->fp, &fpos) < 0) - return 2; - } + if (fiop->action == 'r') { + f_tell(fiop->fp, &fpos); + if (f_seek_set(fiop->fp, &fpos) < 0) + return 2; + } - fiop->action = 'w'; + fiop->action = 'w'; - /* set output to file */ - math_setfp(fiop->fp); + /* set output to file */ + math_setfp(fiop->fp); - /* write the string */ - math_str(str); + /* write the string */ + math_str(str); - math_chr('\0'); + math_chr('\0'); - /* restore output to stdout */ - math_setfp(stdout); - return 0; + /* restore output to stdout */ + math_setfp(stdout); + return 0; } int rewindid(FILEID id) { - FILEIO *fiop; - fiop = findid(id, -1); - if (fiop == NULL) - return 1; - rewind(fiop->fp); - fiop->action = 0; - return 0; + FILEIO *fiop; + fiop = findid(id, -1); + if (fiop == NULL) + return 1; + rewind(fiop->fp); + fiop->action = 0; + return 0; } void rewindall(void) { - FILEIO *fiop; - int i; + FILEIO *fiop; + int i; - for (i = 3; i < idnum; i++) { - fiop = &files[ioindex[i]]; - if (fiop != NULL) { - (void) rewind(fiop->fp); - fiop->action = 0; - } - } + for (i = 3; i < idnum; i++) { + fiop = &files[ioindex[i]]; + if (fiop != NULL) { + (void) rewind(fiop->fp); + fiop->action = 0; + } + } } @@ -1368,10 +1368,10 @@ rewindall(void) * filepos2z - convert a positive file position into a ZVALUE * * given: - * pos file position + * pos file position * * returns: - * file position as a ZVALUE + * file position as a ZVALUE * * NOTE: Does not support negative file positions. */ @@ -1379,22 +1379,22 @@ rewindall(void) S_FUNC ZVALUE filepos2z(FILEPOS pos) { - ZVALUE ret; /* ZVALUE file position to return */ + ZVALUE ret; /* ZVALUE file position to return */ - /* - * store FILEPOS in a ZVALUE as a positive value - */ - ret.len = FILEPOS_BITS/BASEB; - ret.v = alloc(ret.len); - zclearval(ret); - SWAP_HALF_IN_FILEPOS(ret.v, (HALF *)&pos); - ret.sign = 0; - ztrim(&ret); + /* + * store FILEPOS in a ZVALUE as a positive value + */ + ret.len = FILEPOS_BITS/BASEB; + ret.v = alloc(ret.len); + zclearval(ret); + SWAP_HALF_IN_FILEPOS(ret.v, (HALF *)&pos); + ret.sign = 0; + ztrim(&ret); - /* - * return our result - */ - return ret; + /* + * return our result + */ + return ret; } @@ -1402,10 +1402,10 @@ filepos2z(FILEPOS pos) * z2filepos - convert a positive ZVALUE file position to a FILEPOS * * given: - * zpos file position as a ZVALUE + * zpos file position as a ZVALUE * * returns: - * file position as a FILEPOS + * file position as a FILEPOS * * NOTE: Does not support negative file positions. */ @@ -1413,65 +1413,65 @@ S_FUNC FILEPOS z2filepos(ZVALUE zpos) { #if FILEPOS_BITS > FULL_BITS - FILEPOS tmp; /* temp file position as a FILEPOS */ + FILEPOS tmp; /* temp file position as a FILEPOS */ #endif - FILEPOS ret; /* file position as a FILEPOS */ + FILEPOS ret; /* file position as a FILEPOS */ #if FILEPOS_BITS < FULL_BITS - long pos; /* zpos as a long */ + long pos; /* zpos as a long */ #else - FULL pos; /* zpos as a FULL */ + FULL pos; /* zpos as a FULL */ #endif - /* - * firewall - */ - zpos.sign = 0; /* deal only with the absolute value */ + /* + * firewall + */ + zpos.sign = 0; /* deal only with the absolute value */ - /* - * quick return if the position can fit into a long - */ + /* + * quick return if the position can fit into a long + */ #if FILEPOS_BITS == FULL_BITS - /* ztofull puts the value into native byte order */ - pos = ztofull(zpos); - memset(&ret, 0, sizeof(ret)); /* FILEPOS could be non-scalar */ - memcpy((void *)&ret, (void *)&pos, MIN(sizeof(ret), sizeof(pos))); - return ret; + /* ztofull puts the value into native byte order */ + pos = ztofull(zpos); + memset(&ret, 0, sizeof(ret)); /* FILEPOS could be non-scalar */ + memcpy((void *)&ret, (void *)&pos, MIN(sizeof(ret), sizeof(pos))); + return ret; #elif FILEPOS_BITS < FULL_BITS - /* ztofull puts the value into native byte order */ - pos = ztolong(zpos); - memset(&ret, 0, sizeof(ret)); /* FILEPOS could be non-scalar */ - memcpy((void *)&ret, (void *)&pos, MIN(sizeof(ret), sizeof(pos))); - return ret; + /* ztofull puts the value into native byte order */ + pos = ztolong(zpos); + memset(&ret, 0, sizeof(ret)); /* FILEPOS could be non-scalar */ + memcpy((void *)&ret, (void *)&pos, MIN(sizeof(ret), sizeof(pos))); + return ret; #else /* FILEPOS_BITS > FULL_BITS */ - if (!zgtmaxfull(zpos)) { - /* ztofull puts the value into native byte order */ - pos = ztofull(zpos); - memset(&ret, 0, sizeof(ret)); /* FILEPOS could be non-scalar */ - memcpy((void *)&ret, (void *)&pos, - MIN(sizeof(ret), sizeof(pos))); - return ret; - } + if (!zgtmaxfull(zpos)) { + /* ztofull puts the value into native byte order */ + pos = ztofull(zpos); + memset(&ret, 0, sizeof(ret)); /* FILEPOS could be non-scalar */ + memcpy((void *)&ret, (void *)&pos, + MIN(sizeof(ret), sizeof(pos))); + return ret; + } - /* - * copy (and swap if needed) lower part of the ZVALUE as needed - */ - if (zpos.len >= FILEPOS_BITS/BASEB) { - /* copy the lower FILEPOS_BITS of the ZVALUE */ - memset(&tmp, 0, sizeof(tmp)); /* FILEPOS could be non-scalar */ - memcpy(&tmp, zpos.v, MIN(sizeof(tmp), FILEPOS_LEN)); - } else { - /* copy what bits we can into the temp value */ - memset(&tmp, 0, sizeof(tmp)); /* FILEPOS could be non-scalar */ - memcpy(&tmp, zpos.v, MIN(sizeof(tmp), - MIN(zpos.len*BASEB/8, FILEPOS_LEN))); - } - /* swap into native byte order */ - SWAP_HALF_IN_FILEPOS(&ret, &tmp); + /* + * copy (and swap if needed) lower part of the ZVALUE as needed + */ + if (zpos.len >= FILEPOS_BITS/BASEB) { + /* copy the lower FILEPOS_BITS of the ZVALUE */ + memset(&tmp, 0, sizeof(tmp)); /* FILEPOS could be non-scalar */ + memcpy(&tmp, zpos.v, MIN(sizeof(tmp), FILEPOS_LEN)); + } else { + /* copy what bits we can into the temp value */ + memset(&tmp, 0, sizeof(tmp)); /* FILEPOS could be non-scalar */ + memcpy(&tmp, zpos.v, MIN(sizeof(tmp), + MIN(zpos.len*BASEB/8, FILEPOS_LEN))); + } + /* swap into native byte order */ + SWAP_HALF_IN_FILEPOS(&ret, &tmp); - /* - * return our result - */ - return ret; + /* + * return our result + */ + return ret; #endif /* FILEPOS_BITS <= FULL_BITS */ } @@ -1480,31 +1480,31 @@ z2filepos(ZVALUE zpos) * get_open_pos - get a an open file position * * given: - * fp open file stream - * res where to place the file position (ZVALUE) + * fp open file stream + * res where to place the file position (ZVALUE) * * returns: - * 0 res points to the file position - * -1 error + * 0 res points to the file position + * -1 error */ S_FUNC int get_open_pos(FILE *fp, ZVALUE *res) { - FILEPOS pos; /* current file position */ + FILEPOS pos; /* current file position */ - /* - * get the file position - */ - if (f_tell(fp, &pos) < 0) { - /* cannot get file position, return -1 */ - return -1; - } + /* + * get the file position + */ + if (f_tell(fp, &pos) < 0) { + /* cannot get file position, return -1 */ + return -1; + } - /* - * update file position and return success - */ - *res = filepos2z(pos); - return 0; + /* + * update file position and return success + */ + *res = filepos2z(pos); + return 0; } @@ -1512,124 +1512,124 @@ get_open_pos(FILE *fp, ZVALUE *res) * getloc - get the current position of the file * * given: - * id file id of the file - * loc pointer to result + * id file id of the file + * loc pointer to result * * returns: - * 0 able to get file position - * -1 unable to get file position + * 0 able to get file position + * -1 unable to get file position */ int getloc(FILEID id, ZVALUE *res) { - FILEIO *fiop; /* file structure */ - FILE *fp; + FILEIO *fiop; /* file structure */ + FILE *fp; - /* - * convert id to stream - */ - fiop = findid(id, -1); - if (fiop == NULL) { - /* file not open */ - return -1; - } - fp = fiop->fp; - if (fp == NULL) { - math_error("Bogus internal file pointer!"); - not_reached(); - } + /* + * convert id to stream + */ + fiop = findid(id, -1); + if (fiop == NULL) { + /* file not open */ + return -1; + } + fp = fiop->fp; + if (fp == NULL) { + math_error("Bogus internal file pointer!"); + not_reached(); + } - /* - * return result - */ - return get_open_pos(fp, res); + /* + * return result + */ + return get_open_pos(fp, res); } int ftellid(FILEID id, ZVALUE *res) { - FILEIO *fiop; - FILEPOS fpos; /* current file position */ + FILEIO *fiop; + FILEPOS fpos; /* current file position */ - /* get FILEIO */ - fiop = findid(id, -1); - if (fiop == NULL) - return -2; + /* get FILEIO */ + fiop = findid(id, -1); + if (fiop == NULL) + return -2; - /* get the file position */ - if (f_tell(fiop->fp, &fpos) < 0) - return -3; + /* get the file position */ + if (f_tell(fiop->fp, &fpos) < 0) + return -3; - /* convert file position to ZVALUE */ - *res = filepos2z(fpos); - return 0; + /* convert file position to ZVALUE */ + *res = filepos2z(fpos); + return 0; } int fseekid(FILEID id, ZVALUE offset, int whence) { - FILEIO *fiop; /* FILEIO of file */ - FILEPOS off; /* offset as a FILEPOS */ - ZVALUE cur, tmp; /* current or end of file location */ - int ret = 0; /* return code */ + FILEIO *fiop; /* FILEIO of file */ + FILEPOS off; /* offset as a FILEPOS */ + ZVALUE cur, tmp; /* current or end of file location */ + int ret = 0; /* return code */ - /* setup */ - fiop = findid(id, -1); - if (fiop == NULL) - return -2; + /* setup */ + fiop = findid(id, -1); + if (fiop == NULL) + return -2; - /* seek depending on whence */ - switch (whence) { - case 0: - /* construct seek position, off = offset */ - if (zisneg(offset)) - return -3; - off = z2filepos(offset); + /* seek depending on whence */ + switch (whence) { + case 0: + /* construct seek position, off = offset */ + if (zisneg(offset)) + return -3; + off = z2filepos(offset); - /* seek there */ - ret = f_seek_set(fiop->fp, &off); - break; + /* seek there */ + ret = f_seek_set(fiop->fp, &off); + break; - case 1: - /* construct seek position, off = cur+offset */ - f_tell(fiop->fp, &off); - cur = filepos2z(off); - zadd(cur, offset, &tmp); - zfree(cur); - if (zisneg(tmp)) { - zfree(tmp); - return -3; - } - off = z2filepos(tmp); - zfree(tmp); + case 1: + /* construct seek position, off = cur+offset */ + f_tell(fiop->fp, &off); + cur = filepos2z(off); + zadd(cur, offset, &tmp); + zfree(cur); + if (zisneg(tmp)) { + zfree(tmp); + return -3; + } + off = z2filepos(tmp); + zfree(tmp); - /* seek there */ - ret = f_seek_set(fiop->fp, &off); - break; + /* seek there */ + ret = f_seek_set(fiop->fp, &off); + break; - case 2: - /* construct seek position, off = len+offset */ - if (get_open_siz(fiop->fp, &cur) < 0) - return -4; - zadd(cur, offset, &tmp); - zfree(cur); - if (zisneg(tmp)) { - zfree(tmp); - return -3; - } - off = z2filepos(tmp); - zfree(tmp); + case 2: + /* construct seek position, off = len+offset */ + if (get_open_siz(fiop->fp, &cur) < 0) + return -4; + zadd(cur, offset, &tmp); + zfree(cur); + if (zisneg(tmp)) { + zfree(tmp); + return -3; + } + off = z2filepos(tmp); + zfree(tmp); - /* seek there */ - ret = f_seek_set(fiop->fp, &off); - break; + /* seek there */ + ret = f_seek_set(fiop->fp, &off); + break; - default: - return -5; - } - return ret; + default: + return -5; + } + return ret; } @@ -1637,38 +1637,38 @@ fseekid(FILEID id, ZVALUE offset, int whence) * set_open_pos - set a an open file position * * given: - * fp open file stream - * zpos file position (ZVALUE) to set + * fp open file stream + * zpos file position (ZVALUE) to set * * returns: - * 0 res points to the file position - * -1 error + * 0 res points to the file position + * -1 error * * NOTE: Due to fsetpos limitation, position is set relative to only - * the beginning of the file. + * the beginning of the file. */ S_FUNC int set_open_pos(FILE *fp, ZVALUE zpos) { - FILEPOS pos; /* current file position */ + FILEPOS pos; /* current file position */ - /* - * convert ZVALUE to file position - */ - pos = z2filepos(zpos); + /* + * convert ZVALUE to file position + */ + pos = z2filepos(zpos); - /* - * set the file position - */ - if (f_seek_set(fp, &pos) < 0) { - /* cannot set file position, return -1 */ - return -1; - } + /* + * set the file position + */ + if (f_seek_set(fp, &pos) < 0) { + /* cannot set file position, return -1 */ + return -1; + } - /* - * return success - */ - return 0; + /* + * return success + */ + return 0; } @@ -1676,48 +1676,48 @@ set_open_pos(FILE *fp, ZVALUE zpos) * setloc - set the current position of the file * * given: - * id file id of the file - * zpos file position (ZVALUE) to set + * id file id of the file + * zpos file position (ZVALUE) to set * * returns: - * 0 able to set file position - * -1 unable to set file position + * 0 able to set file position + * -1 unable to set file position */ int setloc(FILEID id, ZVALUE zpos) { - FILEIO *fiop; /* file structure */ - FILE *fp; + FILEIO *fiop; /* file structure */ + FILE *fp; - /* - * firewall - */ - if ((id == FILEID_STDIN) || (id == FILEID_STDOUT) || - (id == FILEID_STDERR)) { - math_error("Cannot fseek stdin, stdout, or stderr"); - not_reached(); - } + /* + * firewall + */ + if ((id == FILEID_STDIN) || (id == FILEID_STDOUT) || + (id == FILEID_STDERR)) { + math_error("Cannot fseek stdin, stdout, or stderr"); + not_reached(); + } - /* - * convert id to stream - */ - fiop = findid(id, -1); - if (fiop == NULL) { - /* file not open */ - return -1; - } - fp = fiop->fp; - if (fp == NULL) { - math_error("Bogus internal file pointer!"); - not_reached(); - } + /* + * convert id to stream + */ + fiop = findid(id, -1); + if (fiop == NULL) { + /* file not open */ + return -1; + } + fp = fiop->fp; + if (fp == NULL) { + math_error("Bogus internal file pointer!"); + not_reached(); + } - fiop->action = 0; + fiop->action = 0; - /* - * return result - */ - return set_open_pos(fp, zpos); + /* + * return result + */ + return set_open_pos(fp, zpos); } @@ -1725,31 +1725,31 @@ setloc(FILEID id, ZVALUE zpos) * off_t2z - convert an off_t into a ZVALUE * * given: - * siz file size + * siz file size * * returns: - * file size as a ZVALUE + * file size as a ZVALUE */ /*ARGSUSED*/ S_FUNC ZVALUE off_t2z(off_t siz) { - ZVALUE ret; /* ZVALUE file size to return */ + ZVALUE ret; /* ZVALUE file size to return */ - /* - * store off_t in a ZVALUE as a positive value - */ - ret.len = OFF_T_BITS/BASEB; - ret.v = alloc(ret.len); - zclearval(ret); - SWAP_HALF_IN_OFF_T(ret.v, &siz); - ret.sign = 0; - ztrim(&ret); + /* + * store off_t in a ZVALUE as a positive value + */ + ret.len = OFF_T_BITS/BASEB; + ret.v = alloc(ret.len); + zclearval(ret); + SWAP_HALF_IN_OFF_T(ret.v, &siz); + ret.sign = 0; + ztrim(&ret); - /* - * return our result - */ - return ret; + /* + * return our result + */ + return ret; } @@ -1757,30 +1757,30 @@ off_t2z(off_t siz) * dev2z - convert a stat.st_dev into a ZVALUE * * given: - * dev device + * dev device * * returns: - * file size as a ZVALUE + * file size as a ZVALUE */ S_FUNC ZVALUE dev2z(dev_t dev) { - ZVALUE ret; /* ZVALUE file size to return */ + ZVALUE ret; /* ZVALUE file size to return */ - /* - * store off_t in a ZVALUE as a positive value - */ - ret.len = DEV_BITS/BASEB; - ret.v = alloc(ret.len); - zclearval(ret); - SWAP_HALF_IN_DEV(ret.v, &dev); - ret.sign = 0; - ztrim(&ret); + /* + * store off_t in a ZVALUE as a positive value + */ + ret.len = DEV_BITS/BASEB; + ret.v = alloc(ret.len); + zclearval(ret); + SWAP_HALF_IN_DEV(ret.v, &dev); + ret.sign = 0; + ztrim(&ret); - /* - * return our result - */ - return ret; + /* + * return our result + */ + return ret; } @@ -1788,31 +1788,31 @@ dev2z(dev_t dev) * inode2z - convert a stat.st_ino into a ZVALUE * * given: - * inode file size + * inode file size * * returns: - * file size as a ZVALUE + * file size as a ZVALUE */ /*ARGSUSED*/ S_FUNC ZVALUE inode2z(ino_t inode) { - ZVALUE ret; /* ZVALUE file size to return */ + ZVALUE ret; /* ZVALUE file size to return */ - /* - * store off_t in a ZVALUE as a positive value - */ - ret.len = INODE_BITS/BASEB; - ret.v = alloc(ret.len); - zclearval(ret); - SWAP_HALF_IN_INODE(ret.v, &inode); - ret.sign = 0; - ztrim(&ret); + /* + * store off_t in a ZVALUE as a positive value + */ + ret.len = INODE_BITS/BASEB; + ret.v = alloc(ret.len); + zclearval(ret); + SWAP_HALF_IN_INODE(ret.v, &inode); + ret.sign = 0; + ztrim(&ret); - /* - * return our result - */ - return ret; + /* + * return our result + */ + return ret; } @@ -1820,31 +1820,31 @@ inode2z(ino_t inode) * get_open_siz - get a an open file size * * given: - * fp open file stream - * res where to place the file size (ZVALUE) + * fp open file stream + * res where to place the file size (ZVALUE) * * returns: - * 0 res points to the file size - * -1 error + * 0 res points to the file size + * -1 error */ int get_open_siz(FILE *fp, ZVALUE *res) { - struct stat buf; /* file status */ + struct stat buf; /* file status */ - /* - * get the file size - */ - if (fstat(fileno(fp), &buf) < 0) { - /* stat error */ - return -1; - } + /* + * get the file size + */ + if (fstat(fileno(fp), &buf) < 0) { + /* stat error */ + return -1; + } - /* - * update file size and return success - */ - *res = off_t2z(buf.st_size); - return 0; + /* + * update file size and return success + */ + *res = off_t2z(buf.st_size); + return 0; } @@ -1852,37 +1852,37 @@ get_open_siz(FILE *fp, ZVALUE *res) * getsize - get the current size of the file * * given: - * id file id of the file - * res pointer to result + * id file id of the file + * res pointer to result * * returns: - * 0 able to get file size - * EOF system error - * other nonzero file not open or other problem + * 0 able to get file size + * EOF system error + * other nonzero file not open or other problem */ int getsize(FILEID id, ZVALUE *res) { - FILEIO *fiop; /* file structure */ - FILE *fp; + FILEIO *fiop; /* file structure */ + FILE *fp; - /* - * convert id to stream - */ - fiop = findid(id, -1); - if (fiop == NULL) { - /* file not open */ - return 1; - } - fp = fiop->fp; - if (fp == NULL) { - return 2; - } + /* + * convert id to stream + */ + fiop = findid(id, -1); + if (fiop == NULL) { + /* file not open */ + return 1; + } + fp = fiop->fp; + if (fp == NULL) { + return 2; + } - /* - * return result - */ - return get_open_siz(fp, res); + /* + * return result + */ + return get_open_siz(fp, res); } @@ -1890,32 +1890,32 @@ getsize(FILEID id, ZVALUE *res) * getdevice - get the device of the file * * given: - * id file id of the file - * dev pointer to the result + * id file id of the file + * dev pointer to the result * * returns: - * 0 able to get device - * -1 unable to get device + * 0 able to get device + * -1 unable to get device */ int get_device(FILEID id, ZVALUE *dev) { - FILEIO *fiop; /* file structure */ + FILEIO *fiop; /* file structure */ - /* - * convert id to stream - */ - fiop = findid(id, -1); - if (fiop == NULL) { - /* file not open */ - return -1; - } + /* + * convert id to stream + */ + fiop = findid(id, -1); + if (fiop == NULL) { + /* file not open */ + return -1; + } - /* - * return result - */ - *dev = dev2z(fiop->dev); - return 0; + /* + * return result + */ + *dev = dev2z(fiop->dev); + return 0; } @@ -1923,119 +1923,119 @@ get_device(FILEID id, ZVALUE *dev) * getinode - get the inode of the file * * given: - * id file id of the file - * inode pointer to the result + * id file id of the file + * inode pointer to the result * * returns: - * 0 able to get inode - * -1 unable to get inode + * 0 able to get inode + * -1 unable to get inode */ int get_inode(FILEID id, ZVALUE *inode) { - FILEIO *fiop; /* file structure */ + FILEIO *fiop; /* file structure */ - /* - * convert id to stream - */ - fiop = findid(id, -1); - if (fiop == NULL) { - /* file not open */ - return -1; - } + /* + * convert id to stream + */ + fiop = findid(id, -1); + if (fiop == NULL) { + /* file not open */ + return -1; + } - /* - * return result - */ - *inode = inode2z(fiop->inode); - return 0; + /* + * return result + */ + *inode = inode2z(fiop->inode); + return 0; } S_FUNC off_t filesize(FILEIO *fiop) { - struct stat sbuf; + struct stat sbuf; - /* return length */ - if (fstat(fileno(fiop->fp), &sbuf) < 0) { - math_error("bad fstat"); - not_reached(); - } - return sbuf.st_size; + /* return length */ + if (fstat(fileno(fiop->fp), &sbuf) < 0) { + math_error("bad fstat"); + not_reached(); + } + return sbuf.st_size; } ZVALUE zfilesize(FILEID id) { - FILEIO *fiop; - off_t len; /* file length */ - ZVALUE ret; /* file size as a ZVALUE return value */ + FILEIO *fiop; + off_t len; /* file length */ + ZVALUE ret; /* file size as a ZVALUE return value */ - /* file FILEIO */ - fiop = findid(id, -1); - if (fiop == NULL) { - /* return neg value for non-file error */ - itoz(-1, &ret); - return ret; - } + /* file FILEIO */ + fiop = findid(id, -1); + if (fiop == NULL) { + /* return neg value for non-file error */ + itoz(-1, &ret); + return ret; + } - /* get length */ - len = filesize(fiop); - ret = off_t2z(len); - return ret; + /* get length */ + len = filesize(fiop); + ret = off_t2z(len); + return ret; } void showfiles(void) { - bool listed[MAXFILES]; - FILEIO *fiop; - FILE *fp; - struct stat sbuf; - ino_t inodes[MAXFILES]; - off_t sizes[MAXFILES]; - int i, j; + bool listed[MAXFILES]; + FILEIO *fiop; + FILE *fp; + struct stat sbuf; + ino_t inodes[MAXFILES]; + off_t sizes[MAXFILES]; + int i, j; - for (i = 0; i < idnum; i++) { - listed[i] = false; - fiop = &files[ioindex[i]]; - fp = fiop->fp; - if (fstat(fileno(fp), &sbuf) < 0) { - printf("Bad fstat for file %d\n", (int) fiop->id); - sizes[i] = -1; - } else { - inodes[i] = sbuf.st_ino; - sizes[i] = sbuf.st_size; - } - } - for (i = 0; i < idnum; i++) { - if (listed[i]) - continue; - fiop = &files[ioindex[i]]; - printf("\t"); - printid(fiop->id, PRINT_UNAMBIG); - if (sizes[i] == -1) { - math_chr('\n'); - continue; - } - printf(" size = %ld\n", (long int)sizes[i]); - for (j = i + 1; j < idnum; j++) { - if (listed[j] || sizes[j] == -1) - continue; - if (inodes[j] == inodes[i]) { - listed[j] = true; - fiop = &files[ioindex[j]]; - printf("\t = "); - printid(fiop->id, PRINT_UNAMBIG); - printf("\n"); - } - } - } - printf("\tNumber open = %d\n", idnum); - printf("\tLastid = %d\n", (int) lastid); + for (i = 0; i < idnum; i++) { + listed[i] = false; + fiop = &files[ioindex[i]]; + fp = fiop->fp; + if (fstat(fileno(fp), &sbuf) < 0) { + printf("Bad fstat for file %d\n", (int) fiop->id); + sizes[i] = -1; + } else { + inodes[i] = sbuf.st_ino; + sizes[i] = sbuf.st_size; + } + } + for (i = 0; i < idnum; i++) { + if (listed[i]) + continue; + fiop = &files[ioindex[i]]; + printf("\t"); + printid(fiop->id, PRINT_UNAMBIG); + if (sizes[i] == -1) { + math_chr('\n'); + continue; + } + printf(" size = %ld\n", (long int)sizes[i]); + for (j = i + 1; j < idnum; j++) { + if (listed[j] || sizes[j] == -1) + continue; + if (inodes[j] == inodes[i]) { + listed[j] = true; + fiop = &files[ioindex[j]]; + printf("\t = "); + printid(fiop->id, PRINT_UNAMBIG); + printf("\n"); + } + } + } + printf("\tNumber open = %d\n", idnum); + printf("\tLastid = %d\n", (int) lastid); } @@ -2043,79 +2043,79 @@ showfiles(void) * getscanfield - scan a field separated by some characters * * given: - * fp FILEID to scan - * skip - * width max field width - * scannum Number of characters in scanset - * scanptr string of characters considered separators - * strptr pointer to where the new field pointer may be found + * fp FILEID to scan + * skip + * width max field width + * scannum Number of characters in scanset + * scanptr string of characters considered separators + * strptr pointer to where the new field pointer may be found */ S_FUNC void getscanfield(FILE *fp, bool skip, unsigned int width, int scannum, - char *scanptr, char **strptr) + char *scanptr, char **strptr) { - char *str; /* current string */ - unsigned long len; /* current length of string */ - unsigned long totlen; /* total length of string */ - char buf[READSIZE]; /* temporary buffer */ - int c; - char *b; - bool comp; /* Use complement of scanset */ - unsigned int chnum; + char *str; /* current string */ + unsigned long len; /* current length of string */ + unsigned long totlen; /* total length of string */ + char buf[READSIZE]; /* temporary buffer */ + int c; + char *b; + bool comp; /* Use complement of scanset */ + unsigned int chnum; - totlen = 0; - str = NULL; + totlen = 0; + str = NULL; - comp = (scannum < 0); - if (comp) - scannum = -scannum; + comp = (scannum < 0); + if (comp) + scannum = -scannum; - chnum = 0; + chnum = 0; - for (;;) { - len = 0; - b = buf; - for(;;) { - c = fgetc(fp); - if (c == EOF || c == '\0') - break; - chnum++; - if(scannum && - ((memchr(scanptr,c,scannum)==NULL) ^ comp)) - break; - if (!skip) { - *b++ = c; - len++; - if (len >= READSIZE) - break; - } - if (chnum == width) - break; - } - if (!skip) { - if (totlen) - str = (char *) realloc(str, totlen + len + 1); - else - str = (char *) malloc(len + 1); - if (str == NULL) { - math_error("Out of memory for scanning"); - not_reached(); - } - if (len) - memcpy(&str[totlen], buf, len); - totlen += len; - } - if (len < READSIZE) - break; - } + for (;;) { + len = 0; + b = buf; + for(;;) { + c = fgetc(fp); + if (c == EOF || c == '\0') + break; + chnum++; + if(scannum && + ((memchr(scanptr,c,scannum)==NULL) ^ comp)) + break; + if (!skip) { + *b++ = c; + len++; + if (len >= READSIZE) + break; + } + if (chnum == width) + break; + } + if (!skip) { + if (totlen) + str = (char *) realloc(str, totlen + len + 1); + else + str = (char *) malloc(len + 1); + if (str == NULL) { + math_error("Out of memory for scanning"); + not_reached(); + } + if (len) + memcpy(&str[totlen], buf, len); + totlen += len; + } + if (len < READSIZE) + break; + } - if (!(width && chnum == width) && c != '\0') - ungetc(c, fp); + if (!(width && chnum == width) && c != '\0') + ungetc(c, fp); - if (!skip) { - str[totlen] = '\0'; - *strptr = str; - } + if (!skip) { + str[totlen] = '\0'; + *strptr = str; + } } @@ -2123,266 +2123,266 @@ getscanfield(FILE *fp, bool skip, unsigned int width, int scannum, * getscanwhite - scan a field separated by whitespace * * given: - * fp FILEID to scan - * skip - * width max field width - * scannum Number of characters in scanset - * strptr pointer to where the new field pointer may be found + * fp FILEID to scan + * skip + * width max field width + * scannum Number of characters in scanset + * strptr pointer to where the new field pointer may be found */ S_FUNC void getscanwhite(FILE *fp, bool skip, unsigned int width, int scannum, - char **strptr) + char **strptr) { - char *str; /* current string */ - unsigned long len; /* current length of string */ - unsigned long totlen; /* total length of string */ - char buf[READSIZE]; /* temporary buffer */ - int c; - char *b; - bool comp; /* Use complement of scanset */ - unsigned int chnum; + char *str; /* current string */ + unsigned long len; /* current length of string */ + unsigned long totlen; /* total length of string */ + char buf[READSIZE]; /* temporary buffer */ + int c; + char *b; + bool comp; /* Use complement of scanset */ + unsigned int chnum; - totlen = 0; - str = NULL; + totlen = 0; + str = NULL; - comp = (scannum < 0); - if (comp) - scannum = -scannum; + comp = (scannum < 0); + if (comp) + scannum = -scannum; - chnum = 0; + chnum = 0; - for (;;) { - len = 0; - b = buf; - for(;;) { - c = fgetc(fp); - if (c == EOF || c == '\0') - break; - chnum++; - if(scannum && (!isspace(c) ^ comp)) - break; - if (!skip) { - *b++ = c; - len++; - if (len >= READSIZE) - break; - } - if (chnum == width) - break; - } - if (!skip) { - if (totlen) - str = (char *) realloc(str, totlen + len + 1); - else - str = (char *) malloc(len + 1); - if (str == NULL) { - math_error("Out of memory for scanning"); - not_reached(); - } - if (len) - memcpy(&str[totlen], buf, len); - totlen += len; - } - if (len < READSIZE) - break; - } + for (;;) { + len = 0; + b = buf; + for(;;) { + c = fgetc(fp); + if (c == EOF || c == '\0') + break; + chnum++; + if(scannum && (!isspace(c) ^ comp)) + break; + if (!skip) { + *b++ = c; + len++; + if (len >= READSIZE) + break; + } + if (chnum == width) + break; + } + if (!skip) { + if (totlen) + str = (char *) realloc(str, totlen + len + 1); + else + str = (char *) malloc(len + 1); + if (str == NULL) { + math_error("Out of memory for scanning"); + not_reached(); + } + if (len) + memcpy(&str[totlen], buf, len); + totlen += len; + } + if (len < READSIZE) + break; + } - if (!(width && chnum == width) && c != '\0') - ungetc(c, fp); + if (!(width && chnum == width) && c != '\0') + ungetc(c, fp); - if (!skip) { - str[totlen] = '\0'; - *strptr = str; - } + if (!skip) { + str[totlen] = '\0'; + *strptr = str; + } } S_FUNC int fscanfile(FILE *fp, char *fmt, int count, VALUE **vals) { - int assnum; /* Number of assignments made */ - int c; /* Character read from file */ - char f; /* Character read from format string */ - int scannum; /* Number of characters in scanlist */ - char *scanptr; /* Start of scanlist */ - char *str; - bool comp; /* True scanset is complementary */ - bool skip; /* True if string to be skipped rather than read */ - int width; - VALUE *var; /* lvalue to be assigned to */ - unsigned short subtype; /* for var->v_subtype */ - FILEPOS cur; /* current location */ + int assnum; /* Number of assignments made */ + int c; /* Character read from file */ + char f; /* Character read from format string */ + int scannum; /* Number of characters in scanlist */ + char *scanptr; /* Start of scanlist */ + char *str; + bool comp; /* True scanset is complementary */ + bool skip; /* True if string to be skipped rather than read */ + int width; + VALUE *var; /* lvalue to be assigned to */ + unsigned short subtype; /* for var->v_subtype */ + FILEPOS cur; /* current location */ - if (feof(fp)) - return EOF; + if (feof(fp)) + return EOF; - assnum = 0; + assnum = 0; - for (;;) { - for (;;) { - f = *fmt++; - if (isspace((int)f)) { - getscanwhite(fp,1,0,6,NULL); - do { - f = *fmt++; - } while (isspace((int)f)); - } - c = fgetc(fp); - if (c == EOF) - return assnum; - if (f == '%') { - f = *fmt++; - if (f != '%' && f != '\0') - break; - } - if (f != c || f == '\0') { - ungetc(c, fp); - return assnum; - } - } - ungetc(c, fp); - skip = (f == '*'); - if (!skip && count == 0) { - return assnum; - } - if (skip) - f = *fmt++; - width = 0; - while (f >= '0' && f <= '9') { - width = 10 * width + f - '0'; - f = *fmt++; - } - switch (f) { - case 'c': - if (width == 0) - width = 1; - getscanfield(fp,skip,width,0,NULL,&str); - break; - case 's': - getscanwhite(fp,1,0,6,NULL); - if (feof(fp)) - return assnum; - getscanwhite(fp,skip,width,-6,&str); - break; - case '[': - f = *fmt; - comp = (f == '^'); - if (comp) - f = *++fmt; - scanptr = fmt; - if (f == '\0') - return assnum; - fmt = strchr((f == ']' ? fmt + 1 : fmt), ']'); - if (fmt == NULL) - return assnum; - scannum = fmt - scanptr; - if (comp) - scannum = -scannum; - fmt++; - getscanfield(fp,skip, - width,scannum,scanptr,&str); - break; - case 'f': - case 'e': - case 'r': - case 'i': - getscanwhite(fp,1,0,6, NULL); - if (feof(fp)) - return assnum; - if (skip) { - fskipnum(fp); - continue; - } - assnum++; - var = *vals++; - if (var->v_type != V_ADDR) - math_error("This should not happen!!"); - var = var->v_addr; - subtype = var->v_subtype; - freevalue(var); - count--; - freadsum(fp, var); - var->v_subtype = subtype; - continue; - case 'n': - assnum++; - var = *vals++; - count--; - if (var->v_type != V_ADDR) - math_error("This should not happen!!"); - var = var->v_addr; - subtype = var->v_subtype; - freevalue(var); - var->v_type = V_NUM; - var->v_num = qalloc(); - f_tell(fp, &cur); - var->v_num->num = filepos2z(cur); - var->v_subtype = subtype; - continue; - default: - fprintf(stderr, "Unsupported scan specifier"); - return assnum; - } - if (!skip) { - assnum++; - var = *vals++; - count--; - if (var->v_type != V_ADDR) - math_error("Assigning to non-variable"); - var = var->v_addr; - subtype = var->v_subtype; - freevalue(var); - var->v_type = V_STR; - var->v_str = makestring(str); - } - } + for (;;) { + for (;;) { + f = *fmt++; + if (isspace((int)f)) { + getscanwhite(fp,1,0,6,NULL); + do { + f = *fmt++; + } while (isspace((int)f)); + } + c = fgetc(fp); + if (c == EOF) + return assnum; + if (f == '%') { + f = *fmt++; + if (f != '%' && f != '\0') + break; + } + if (f != c || f == '\0') { + ungetc(c, fp); + return assnum; + } + } + ungetc(c, fp); + skip = (f == '*'); + if (!skip && count == 0) { + return assnum; + } + if (skip) + f = *fmt++; + width = 0; + while (f >= '0' && f <= '9') { + width = 10 * width + f - '0'; + f = *fmt++; + } + switch (f) { + case 'c': + if (width == 0) + width = 1; + getscanfield(fp,skip,width,0,NULL,&str); + break; + case 's': + getscanwhite(fp,1,0,6,NULL); + if (feof(fp)) + return assnum; + getscanwhite(fp,skip,width,-6,&str); + break; + case '[': + f = *fmt; + comp = (f == '^'); + if (comp) + f = *++fmt; + scanptr = fmt; + if (f == '\0') + return assnum; + fmt = strchr((f == ']' ? fmt + 1 : fmt), ']'); + if (fmt == NULL) + return assnum; + scannum = fmt - scanptr; + if (comp) + scannum = -scannum; + fmt++; + getscanfield(fp,skip, + width,scannum,scanptr,&str); + break; + case 'f': + case 'e': + case 'r': + case 'i': + getscanwhite(fp,1,0,6, NULL); + if (feof(fp)) + return assnum; + if (skip) { + fskipnum(fp); + continue; + } + assnum++; + var = *vals++; + if (var->v_type != V_ADDR) + math_error("This should not happen!!"); + var = var->v_addr; + subtype = var->v_subtype; + freevalue(var); + count--; + freadsum(fp, var); + var->v_subtype = subtype; + continue; + case 'n': + assnum++; + var = *vals++; + count--; + if (var->v_type != V_ADDR) + math_error("This should not happen!!"); + var = var->v_addr; + subtype = var->v_subtype; + freevalue(var); + var->v_type = V_NUM; + var->v_num = qalloc(); + f_tell(fp, &cur); + var->v_num->num = filepos2z(cur); + var->v_subtype = subtype; + continue; + default: + fprintf(stderr, "Unsupported scan specifier"); + return assnum; + } + if (!skip) { + assnum++; + var = *vals++; + count--; + if (var->v_type != V_ADDR) + math_error("Assigning to non-variable"); + var = var->v_addr; + subtype = var->v_subtype; + freevalue(var); + var->v_type = V_STR; + var->v_str = makestring(str); + } + } } int fscanfid(FILEID id, char *fmt, int count, VALUE **vals) { - FILEIO *fiop; - FILE *fp; - FILEPOS fpos; + FILEIO *fiop; + FILE *fp; + FILEPOS fpos; - fiop = findid(id, false); - if (fiop == NULL) - return -2; + fiop = findid(id, false); + if (fiop == NULL) + return -2; - fp = fiop->fp; + fp = fiop->fp; - if (fiop->action == 'w') { - f_tell(fp, &fpos); - fflush(fp); - if (f_seek_set(fp, &fpos) < 0) - return -4; - } - fiop->action = 'r'; + if (fiop->action == 'w') { + f_tell(fp, &fpos); + fflush(fp); + if (f_seek_set(fp, &fpos) < 0) + return -4; + } + fiop->action = 'r'; - return fscanfile(fp, fmt, count, vals); + return fscanfile(fp, fmt, count, vals); } int scanfstr(char *str, char *fmt, int count, VALUE **vals) { - FILE *fp; - int i; + FILE *fp; + int i; - fp = tmpfile(); - if (fp == NULL) - return EOF; - fputs(str, fp); - rewind(fp); - i = fscanfile(fp, fmt, count, vals); - fclose(fp); - return i; + fp = tmpfile(); + if (fp == NULL) + return EOF; + fputs(str, fp); + rewind(fp); + i = fscanfile(fp, fmt, count, vals); + fclose(fp); + return i; } /* - * Read a number in floating-point format from a file. The first dot, + * Read a number in floating-point format from a file. The first dot, * if any, is considered as the decimal point; later dots are ignored. * For example, -23.45..67. is interpreted as -23.4567 * An optional 'e' or 'E' indicates multiplication by a power or 10, @@ -2394,226 +2394,226 @@ scanfstr(char *str, char *fmt, int count, VALUE **vals) S_FUNC void freadnum(FILE *fp, VALUE *valptr) { - ZVALUE num, zden, newnum, newden, div, tmp; - NUMBER *q; - COMPLEX *c; - VALUE val; - char ch; - LEN i; - HALF *a; - FULL f; - long decimals, exp; - bool sign, negexp, havedp, imag, exptoobig; + ZVALUE num, zden, newnum, newden, div, tmp; + NUMBER *q; + COMPLEX *c; + VALUE val; + char ch; + LEN i; + HALF *a; + FULL f; + long decimals, exp; + bool sign, negexp, havedp, imag, exptoobig; - decimals = 0; - exp = 0; - sign = false; - negexp = false; - havedp = false; - imag = false; - exptoobig = false; + decimals = 0; + exp = 0; + sign = false; + negexp = false; + havedp = false; + imag = false; + exptoobig = false; - ch = fgetc(fp); - if (ch == '+' || ch == '-') { - if (ch == '-') - sign = true; - ch = fgetc(fp); - } - num.v = alloc(1); - *num.v = 0; - num.len = 1; - num.sign = sign; - for (;;) { - if (ch >= '0' && ch <= '9') { - f = (FULL) (ch - '0'); - a = num.v; - i = num.len; - while (i-- > 0) { - f = 10 * (FULL) *a + f; - *a++ = (HALF) f; - f >>= BASEB; - } - if (f) { - a = alloc(num.len + 1); - memcpy(a, num.v, num.len * sizeof(HALF)); - a[num.len] = (HALF) f; - num.len++; - freeh(num.v); - num.v = a; - } - if (havedp) - decimals++; - } - else if (ch == '.') - havedp = true; - else - break; - ch = fgetc(fp); - } - if (ch == 'e' || ch == 'E') { - ch = fgetc(fp); - if (ch == '+' || ch == '-') { - if (ch == '-') - negexp = true; - ch = fgetc(fp); - } - while (ch >= '0' && ch <= '9') { - if (!exptoobig) { - exp = (exp * 10) + ch - '0'; - if (exp > 1000000) - exptoobig = true; - } - ch = fgetc(fp); - } - } - if (ch == 'i' || ch == 'I') { - imag = true; - } else { - ungetc(ch, fp); - } + ch = fgetc(fp); + if (ch == '+' || ch == '-') { + if (ch == '-') + sign = true; + ch = fgetc(fp); + } + num.v = alloc(1); + *num.v = 0; + num.len = 1; + num.sign = sign; + for (;;) { + if (ch >= '0' && ch <= '9') { + f = (FULL) (ch - '0'); + a = num.v; + i = num.len; + while (i-- > 0) { + f = 10 * (FULL) *a + f; + *a++ = (HALF) f; + f >>= BASEB; + } + if (f) { + a = alloc(num.len + 1); + memcpy(a, num.v, num.len * sizeof(HALF)); + a[num.len] = (HALF) f; + num.len++; + freeh(num.v); + num.v = a; + } + if (havedp) + decimals++; + } + else if (ch == '.') + havedp = true; + else + break; + ch = fgetc(fp); + } + if (ch == 'e' || ch == 'E') { + ch = fgetc(fp); + if (ch == '+' || ch == '-') { + if (ch == '-') + negexp = true; + ch = fgetc(fp); + } + while (ch >= '0' && ch <= '9') { + if (!exptoobig) { + exp = (exp * 10) + ch - '0'; + if (exp > 1000000) + exptoobig = true; + } + ch = fgetc(fp); + } + } + if (ch == 'i' || ch == 'I') { + imag = true; + } else { + ungetc(ch, fp); + } - if (ziszero(num)) { - zfree(num); - val.v_type = V_NUM; - val.v_subtype = V_NOSUBTYPE; - val.v_num = qlink(&_qzero_); - *valptr = val; - return; - } - if (exptoobig) { - zfree(num); - *valptr = error_value(E_BIGEXP); - return; - } - ztenpow(decimals, &zden); - if (exp) { - ztenpow(exp, &tmp); - if (negexp) { - zmul(zden, tmp, &newden); - zfree(zden); - zden = newden; - } else { - zmul(num, tmp, &newnum); - zfree(num); - num = newnum; - } - zfree(tmp); - } - if (!zisunit(num) && !zisunit(zden)) { - zgcd(num, zden, &div); - if (!zisunit(div)) { - zequo(num, div, &newnum); - zfree(num); - zequo(zden, div, &newden); - zfree(zden); - num = newnum; - zden = newden; - } - zfree(div); - } - q = qalloc(); - q->num = num; - q->den = zden; - if (imag) { - c = comalloc(); - qfree(c->imag); - c->imag = q; - val.v_type = V_COM; - val.v_com = c; - } else { - val.v_type = V_NUM; - val.v_num = q; - } - val.v_subtype = V_NOSUBTYPE; - *valptr = val; + if (ziszero(num)) { + zfree(num); + val.v_type = V_NUM; + val.v_subtype = V_NOSUBTYPE; + val.v_num = qlink(&_qzero_); + *valptr = val; + return; + } + if (exptoobig) { + zfree(num); + *valptr = error_value(E_BIGEXP); + return; + } + ztenpow(decimals, &zden); + if (exp) { + ztenpow(exp, &tmp); + if (negexp) { + zmul(zden, tmp, &newden); + zfree(zden); + zden = newden; + } else { + zmul(num, tmp, &newnum); + zfree(num); + num = newnum; + } + zfree(tmp); + } + if (!zisunit(num) && !zisunit(zden)) { + zgcd(num, zden, &div); + if (!zisunit(div)) { + zequo(num, div, &newnum); + zfree(num); + zequo(zden, div, &newden); + zfree(zden); + num = newnum; + zden = newden; + } + zfree(div); + } + q = qalloc(); + q->num = num; + q->den = zden; + if (imag) { + c = comalloc(); + qfree(c->imag); + c->imag = q; + val.v_type = V_COM; + val.v_com = c; + } else { + val.v_type = V_NUM; + val.v_num = q; + } + val.v_subtype = V_NOSUBTYPE; + *valptr = val; } S_FUNC void freadsum(FILE *fp, VALUE *valptr) { - VALUE v1, v2, v3; - char ch; + VALUE v1, v2, v3; + char ch; - freadprod(fp, &v1); + freadprod(fp, &v1); - ch = fgetc(fp); - while (ch == '+' || ch == '-') { - freadprod(fp, &v2); - if (ch == '+') - addvalue(&v1, &v2, &v3); - else - subvalue(&v1, &v2, &v3); - freevalue(&v1); - freevalue(&v2); - v1 = v3; - ch = fgetc(fp); - } - ungetc(ch, fp); - *valptr = v1; + ch = fgetc(fp); + while (ch == '+' || ch == '-') { + freadprod(fp, &v2); + if (ch == '+') + addvalue(&v1, &v2, &v3); + else + subvalue(&v1, &v2, &v3); + freevalue(&v1); + freevalue(&v2); + v1 = v3; + ch = fgetc(fp); + } + ungetc(ch, fp); + *valptr = v1; } S_FUNC void freadprod(FILE *fp, VALUE *valptr) { - VALUE v1, v2, v3; - char ch; + VALUE v1, v2, v3; + char ch; - freadnum(fp, &v1); - ch = fgetc(fp); - while (ch == '*' || ch == '/') { - freadnum(fp, &v2); - if (ch == '*') - mulvalue(&v1, &v2, &v3); - else - divvalue(&v1, &v2, &v3); - freevalue(&v1); - freevalue(&v2); - v1 = v3; - ch = fgetc(fp); - } - ungetc(ch, fp); - *valptr = v1; + freadnum(fp, &v1); + ch = fgetc(fp); + while (ch == '*' || ch == '/') { + freadnum(fp, &v2); + if (ch == '*') + mulvalue(&v1, &v2, &v3); + else + divvalue(&v1, &v2, &v3); + freevalue(&v1); + freevalue(&v2); + v1 = v3; + ch = fgetc(fp); + } + ungetc(ch, fp); + *valptr = v1; } S_FUNC void fskipnum(FILE *fp) { - char ch; + char ch; - do { - ch = fgetc(fp); - if (ch == '+' || ch == '-') - ch = fgetc(fp); - while ((ch >= '0' && ch <= '9') || ch == '.') - ch = fgetc(fp); - if (ch == 'e' || ch == 'E') { - ch = fgetc(fp); - if (ch == '+' || ch == '-') - ch = fgetc(fp); - while (ch >= '0' && ch <= '9') - ch = fgetc(fp); - } - if (ch == 'i' || ch == 'I') - ch = fgetc(fp); - } while (ch == '/' || ch == '*' || ch == '+' || ch == '-'); + do { + ch = fgetc(fp); + if (ch == '+' || ch == '-') + ch = fgetc(fp); + while ((ch >= '0' && ch <= '9') || ch == '.') + ch = fgetc(fp); + if (ch == 'e' || ch == 'E') { + ch = fgetc(fp); + if (ch == '+' || ch == '-') + ch = fgetc(fp); + while (ch >= '0' && ch <= '9') + ch = fgetc(fp); + } + if (ch == 'i' || ch == 'I') + ch = fgetc(fp); + } while (ch == '/' || ch == '*' || ch == '+' || ch == '-'); - ungetc(ch, fp); + ungetc(ch, fp); } int isattyid(FILEID id) { - FILEIO *fiop; + FILEIO *fiop; - fiop = findid(id, -1); - if (fiop == NULL) - return -2; - return isatty(fileno(fiop->fp)); + fiop = findid(id, -1); + if (fiop == NULL) + return -2; + return isatty(fileno(fiop->fp)); } @@ -2621,117 +2621,117 @@ isattyid(FILEID id) * fsearch - search for a string in a file * * given: - * id FILEID to search - * str string to look for - * pos file position to start at (NULL => current position) + * id FILEID to search + * str string to look for + * pos file position to start at (NULL => current position) * * returns: - * EOF if system error - * other negative integer if file not open, etc. - * positive integer if string not found - * zero if string found, position stored at res + * EOF if system error + * other negative integer if file not open, etc. + * positive integer if string not found + * zero if string found, position stored at res * * XXX - This search is a translation of the original search that did not - * work with large files. The search algorithm used is slow and - * should be speed up much more. + * work with large files. The search algorithm used is slow and + * should be speed up much more. */ int fsearch(FILEID id, char *str, ZVALUE start, ZVALUE end, ZVALUE *res) { - FILEIO *fiop; /* FILEIO of file id */ - FILEPOS cur; /* current file position */ - ZVALUE tmp, tmp2; /* temporary ZVALUEs */ - char c; /* str comparison character */ - int r; /* character read from file */ - char *s; /* str comparison pointer */ - long k = 0; + FILEIO *fiop; /* FILEIO of file id */ + FILEPOS cur; /* current file position */ + ZVALUE tmp, tmp2; /* temporary ZVALUEs */ + char c; /* str comparison character */ + int r; /* character read from file */ + char *s; /* str comparison pointer */ + long k = 0; - /* get FILEIO */ - fiop = findid(id, false); - if (fiop == NULL) - return -2; + /* get FILEIO */ + fiop = findid(id, false); + if (fiop == NULL) + return -2; - /* - * file setup - */ - if (fiop->action == 'w') - fflush(fiop->fp); + /* + * file setup + */ + if (fiop->action == 'w') + fflush(fiop->fp); - zsub(end, start, &tmp2); + zsub(end, start, &tmp2); - if (zisneg(tmp2)) { - zfree(tmp2); - return 1; - } + if (zisneg(tmp2)) { + zfree(tmp2); + return 1; + } - tmp.sign = 0; - tmp.len = tmp2.len; - tmp.v = alloc(tmp.len); - zcopyval(tmp2, tmp); - zfree(tmp2); + tmp.sign = 0; + tmp.len = tmp2.len; + tmp.v = alloc(tmp.len); + zcopyval(tmp2, tmp); + zfree(tmp2); - cur = z2filepos(start); + cur = z2filepos(start); - if (f_seek_set(fiop->fp, &cur) < 0) { - zfree(tmp); - return EOF; - } + if (f_seek_set(fiop->fp, &cur) < 0) { + zfree(tmp); + return EOF; + } - /* - * search setup - */ - /* note the first str search character */ - c = *str++; + /* + * search setup + */ + /* note the first str search character */ + c = *str++; - if (c == '\0') { - zfree(tmp); - return 2; - } - clearerr(fiop->fp); - while ((r = fgetc(fiop->fp)) != EOF) { - if ((char)r == c) { - (void) f_tell(fiop->fp, &cur); - s = str; - while (*s) { - r = fgetc(fiop->fp); - if ((char)r != *s) - break; - s++; - } - if (r == EOF) - break; - if (*s == '\0') { - zfree(tmp); - tmp = filepos2z(cur); - zsub(tmp, _one_, res); - zfree(tmp); - return 0; - } - (void) f_seek_set(fiop->fp, &cur); - } - if (*tmp.v) { - (*tmp.v)--; - } else { - if (tmp.len == 1) - break; - k = 0; - do { - tmp.v[k++] = BASE1; - } - while (k < tmp.len && tmp.v[k] == 0); - if (k == tmp.len) { - math_error("This should not happen"); - not_reached(); - } - tmp.v[k]--; - if (tmp.v[tmp.len - 1] == 0) - tmp.len--; - } - } - zfree(tmp); - if (ferror(fiop->fp)) - return EOF; - return 1; + if (c == '\0') { + zfree(tmp); + return 2; + } + clearerr(fiop->fp); + while ((r = fgetc(fiop->fp)) != EOF) { + if ((char)r == c) { + (void) f_tell(fiop->fp, &cur); + s = str; + while (*s) { + r = fgetc(fiop->fp); + if ((char)r != *s) + break; + s++; + } + if (r == EOF) + break; + if (*s == '\0') { + zfree(tmp); + tmp = filepos2z(cur); + zsub(tmp, _one_, res); + zfree(tmp); + return 0; + } + (void) f_seek_set(fiop->fp, &cur); + } + if (*tmp.v) { + (*tmp.v)--; + } else { + if (tmp.len == 1) + break; + k = 0; + do { + tmp.v[k++] = BASE1; + } + while (k < tmp.len && tmp.v[k] == 0); + if (k == tmp.len) { + math_error("This should not happen"); + not_reached(); + } + tmp.v[k]--; + if (tmp.v[tmp.len - 1] == 0) + tmp.len--; + } + } + zfree(tmp); + if (ferror(fiop->fp)) + return EOF; + return 1; } @@ -2739,114 +2739,114 @@ fsearch(FILEID id, char *str, ZVALUE start, ZVALUE end, ZVALUE *res) * frsearch - reverse search for a string in a file * * given: - * id FILEID to search - * str string to look for - * search starts at pos = first and continues for decreasing - * pos >= last + * id FILEID to search + * str string to look for + * search starts at pos = first and continues for decreasing + * pos >= last * * returns: - * EOF if system error - * other negative integer if file not open, etc. - * positive integer if string not found - * zero if string found, position stored at res + * EOF if system error + * other negative integer if file not open, etc. + * positive integer if string not found + * zero if string found, position stored at res * * XXX - This search is a translation of the original search that did not - * work with large files. The search algorithm used is so slow - * as to be painful to the user and needs to be sped up much more. + * work with large files. The search algorithm used is so slow + * as to be painful to the user and needs to be sped up much more. */ int frsearch(FILEID id, char *str, ZVALUE first, ZVALUE last, ZVALUE *res) { - FILEIO *fiop; /* FILEIO of file id */ - FILEPOS cur; /* current file position */ - ZVALUE pos; /* current file position as ZVALUE */ - ZVALUE tmp; /* temporary ZVALUEs */ - char c; /* str comparison character */ - int r; /* character read from file */ - char *s; /* str comparison pointer */ + FILEIO *fiop; /* FILEIO of file id */ + FILEPOS cur; /* current file position */ + ZVALUE pos; /* current file position as ZVALUE */ + ZVALUE tmp; /* temporary ZVALUEs */ + char c; /* str comparison character */ + int r; /* character read from file */ + char *s; /* str comparison pointer */ - /* get FILEIO */ - fiop = findid(id, false); - if (fiop == NULL) - return -2; + /* get FILEIO */ + fiop = findid(id, false); + if (fiop == NULL) + return -2; - /* - * file setup - */ - if (fiop->action == 'w') - fflush(fiop->fp); + /* + * file setup + */ + if (fiop->action == 'w') + fflush(fiop->fp); - zcopy(first, &pos); + zcopy(first, &pos); - /* - * search setup - */ - /* note the first str search character */ - c = *str++; + /* + * search setup + */ + /* note the first str search character */ + c = *str++; - if (c == '\0') { - cur = z2filepos(pos); - if (f_seek_set(fiop->fp, &cur) < 0) { - zfree(pos); - return EOF; - } - *res = pos; - return 0; - } + if (c == '\0') { + cur = z2filepos(pos); + if (f_seek_set(fiop->fp, &cur) < 0) { + zfree(pos); + return EOF; + } + *res = pos; + return 0; + } - clearerr(fiop->fp); + clearerr(fiop->fp); - while(zrel(pos, last) >= 0) { - cur = z2filepos(pos); - if (f_seek_set(fiop->fp, &cur) < 0) { - zfree(pos); - return EOF; - } - r = fgetc(fiop->fp); - if (r == EOF) { - zfree(pos); - return EOF; - } - if ((char) r == c) { - s = str; - while (*s) { - r = fgetc(fiop->fp); - if ((char)r != *s) - break; - s++; - } - if (r == EOF) { - zfree(pos); - return EOF; - } - if (*s == '\0') { - *res = pos; - ungetc(r, fiop->fp); - return 0; - } - } - zsub(pos, _one_, &tmp); - zfree(pos); - pos = tmp; - } - cur = z2filepos(last); - f_seek_set(fiop->fp, &cur); - zfree(pos); - if (ferror(fiop->fp)) - return EOF; - return 1; + while(zrel(pos, last) >= 0) { + cur = z2filepos(pos); + if (f_seek_set(fiop->fp, &cur) < 0) { + zfree(pos); + return EOF; + } + r = fgetc(fiop->fp); + if (r == EOF) { + zfree(pos); + return EOF; + } + if ((char) r == c) { + s = str; + while (*s) { + r = fgetc(fiop->fp); + if ((char)r != *s) + break; + s++; + } + if (r == EOF) { + zfree(pos); + return EOF; + } + if (*s == '\0') { + *res = pos; + ungetc(r, fiop->fp); + return 0; + } + } + zsub(pos, _one_, &tmp); + zfree(pos); + pos = tmp; + } + cur = z2filepos(last); + f_seek_set(fiop->fp, &cur); + zfree(pos); + if (ferror(fiop->fp)) + return EOF; + return 1; } char * findfname(FILEID id) { - FILEIO *fiop; + FILEIO *fiop; - fiop = findid(id, -1); + fiop = findid(id, -1); - if (fiop == NULL) - return NULL; + if (fiop == NULL) + return NULL; - return fiop->name; + return fiop->name; } diff --git a/file.h b/file.h index d03d1fa..ed7a04e 100644 --- a/file.h +++ b/file.h @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,11 +19,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1996/05/24 05:55:58 - * File existed as early as: 1996 + * Under source code control: 1996/05/24 05:55:58 + * File existed as early as: 1996 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -31,7 +31,7 @@ #define INCLUDE_FILE_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "have_fgetsetpos.h" #else # include @@ -43,17 +43,17 @@ */ #define MODE_LEN (sizeof("rb+")-1) typedef struct { - FILEID id; /* id to identify this file */ - FILE *fp; /* real file structure for I/O */ - dev_t dev; /* file device */ - ino_t inode; /* file inode */ - char *name; /* file name */ - bool reading; /* true if opened for reading */ - bool writing; /* true if opened for writing */ - bool appending; /* true if also opened for appending */ - bool binary; /* true if binary mode - mode ignored/unused */ - char action; /* most recent use for 'r', 'w' or 0 */ - char mode[MODE_LEN+1]; /* open mode */ + FILEID id; /* id to identify this file */ + FILE *fp; /* real file structure for I/O */ + dev_t dev; /* file device */ + ino_t inode; /* file inode */ + char *name; /* file name */ + bool reading; /* true if opened for reading */ + bool writing; /* true if opened for writing */ + bool appending; /* true if also opened for appending */ + bool binary; /* true if binary mode - mode ignored/unused */ + char action; /* most recent use for 'r', 'w' or 0 */ + char mode[MODE_LEN+1]; /* open mode */ } FILEIO; @@ -61,15 +61,15 @@ typedef struct { * fgetpos/fsetpos vs fseek/ftell interface * * f_seek_set(FILE *stream, FILEPOS *loc) - * Seek loc bytes from the beginning of the open file, stream. + * Seek loc bytes from the beginning of the open file, stream. * * f_tell(FILE *stream, FILEPOS *loc) - * Set loc to bytes from the beginning of the open file, stream. + * Set loc to bytes from the beginning of the open file, stream. * * We assume that if your system does not have fgetpos/fsetpos, * then it will have a FILEPOS that is a scalar type (e.g., long). * Some obscure systems without fgetpos/fsetpos may not have a simple - * scalar type. In these cases the f_tell macro below will fail. + * scalar type. In these cases the f_tell macro below will fail. */ #if defined(HAVE_FGETSETPOS) @@ -78,8 +78,8 @@ typedef struct { #else -#define f_seek_set(stream, loc) \ - fseek((FILE*)(stream), *(FILEPOS*)(loc), SEEK_SET) +#define f_seek_set(stream, loc) \ + fseek((FILE*)(stream), *(FILEPOS*)(loc), SEEK_SET) #define f_tell(stream, loc) (*((FILEPOS*)(loc)) = ftell((FILE*)(stream))) #endif @@ -94,7 +94,7 @@ E_FUNC int fsetposid(FILEID id, FILEPOS *ptr); E_FUNC int get_open_siz(FILE *fp, ZVALUE *res); E_FUNC char* findfname(FILEID); E_FUNC FILE *f_pathopen(char *name, char *mode, char *pathlist, - char **openpath); + char **openpath); #endif /* !INCLUDE_FILE_H */ diff --git a/fposval.c b/fposval.c index 91a339e..8875520 100644 --- a/fposval.c +++ b/fposval.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1994/11/05 03:19:52 - * File existed as early as: 1994 + * Under source code control: 1994/11/05 03:19:52 + * File existed as early as: 1994 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -36,18 +36,18 @@ * * We will #define of 8 symbols: * - * FILEPOS_BITS length in bits of the type FILEPOS - * FILEPOS_LEN length in octets of the type FILEPOS - * SWAP_HALF_IN_FILEPOS will copy/swap FILEPOS into an HALF array - * OFF_T_BITS length in bits of the st_size stat element - * OFF_T_LEN length in octets of the st_size stat element - * SWAP_HALF_IN_OFF_T will copy/swap st_size into an HALF array - * DEV_BITS length in bits of the st_dev stat element - * DEV_LEN length in bits of the st_dev stat element - * SWAP_HALF_IN_DEV will copy/swap st_dev into an HALF array - * INODE_BITS length in bits of the st_ino stat element - * INODE_LEN length in octets of the st_ino stat element - * SWAP_HALF_IN_INODE will copy/swap st_ino into an HALF array + * FILEPOS_BITS length in bits of the type FILEPOS + * FILEPOS_LEN length in octets of the type FILEPOS + * SWAP_HALF_IN_FILEPOS will copy/swap FILEPOS into an HALF array + * OFF_T_BITS length in bits of the st_size stat element + * OFF_T_LEN length in octets of the st_size stat element + * SWAP_HALF_IN_OFF_T will copy/swap st_size into an HALF array + * DEV_BITS length in bits of the st_dev stat element + * DEV_LEN length in bits of the st_dev stat element + * SWAP_HALF_IN_DEV will copy/swap st_dev into an HALF array + * INODE_BITS length in bits of the st_ino stat element + * INODE_LEN length in octets of the st_ino stat element + * SWAP_HALF_IN_INODE will copy/swap st_ino into an HALF array * * With regards to 'will copy/swap ... into an HALF array'. Such macros * will either be a copy or a copy with HALFs swapped depending on the @@ -75,213 +75,213 @@ #include "zmath.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -char *program; /* our name */ +char *program; /* our name */ int main(int UNUSED(argc), char **argv) { - int stsizelen; /* bit length of st_size in buf */ - int fileposlen; /* bit length of FILEPOS */ - int devlen; /* bit length of st_dev in buf */ - int inodelen; /* bit length of st_ino in buf */ - struct stat buf; /* file status */ + int stsizelen; /* bit length of st_size in buf */ + int fileposlen; /* bit length of FILEPOS */ + int devlen; /* bit length of st_dev in buf */ + int inodelen; /* bit length of st_ino in buf */ + struct stat buf; /* file status */ - /* - * parse args - */ - program = argv[0]; + /* + * parse args + */ + program = argv[0]; - /* - * print the file position information - */ + /* + * print the file position information + */ #if defined(HAVE_FPOS_POS) && defined(FPOS_POS_BITS) - fileposlen = FPOS_POS_BITS; + fileposlen = FPOS_POS_BITS; #else /* ! HAVE_FPOS_POS */ # if defined(FPOS_BITS) - fileposlen = FPOS_BITS; + fileposlen = FPOS_BITS; # else - fileposlen = sizeof(FILEPOS)*8; + fileposlen = sizeof(FILEPOS)*8; # endif #endif /* ! HAVE_FPOS_POS */ - printf("#undef FILEPOS_BITS\n"); - printf("#define FILEPOS_BITS %d\n", fileposlen); - printf("#undef FILEPOS_LEN\n"); - printf("#define FILEPOS_LEN %d\n", fileposlen/8); + printf("#undef FILEPOS_BITS\n"); + printf("#define FILEPOS_BITS %d\n", fileposlen); + printf("#undef FILEPOS_LEN\n"); + printf("#define FILEPOS_LEN %d\n", fileposlen/8); #if CALC_BYTE_ORDER == BIG_ENDIAN - /* - * Big Endian - */ - /* - * Use casts to (HALF *) because SWAP_HALF_IN_B* might expand to - * a simple assignment and SWAP_HALF_IN_FILEPOS might get a - * (HALF *) and a (FILEPOS *) which are not assignment-compatible. - */ - if (fileposlen == 64) { - printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n" - "\tSWAP_HALF_IN_B64((HALF *)dest, (HALF *)src)\n"); - } else if (fileposlen == 32) { - printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n" - "\tSWAP_HALF_IN_B32((HALF *)dest, (HALF *)src)\n"); - } else if (fileposlen%BASEB == 0) { - printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n" - "\tswap_HALFs((HALF *)dest, (HALF *)src, %d)\n", - fileposlen/BASEB); - } else { - fprintf(stderr, "%s: unexpected BIG_ENDIAN FILEPOS bit size: %d\n", - program, fileposlen); - exit(1); - } + /* + * Big Endian + */ + /* + * Use casts to (HALF *) because SWAP_HALF_IN_B* might expand to + * a simple assignment and SWAP_HALF_IN_FILEPOS might get a + * (HALF *) and a (FILEPOS *) which are not assignment-compatible. + */ + if (fileposlen == 64) { + printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n" + "\tSWAP_HALF_IN_B64((HALF *)dest, (HALF *)src)\n"); + } else if (fileposlen == 32) { + printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n" + "\tSWAP_HALF_IN_B32((HALF *)dest, (HALF *)src)\n"); + } else if (fileposlen%BASEB == 0) { + printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n" + "\tswap_HALFs((HALF *)dest, (HALF *)src, %d)\n", + fileposlen/BASEB); + } else { + fprintf(stderr, "%s: unexpected BIG_ENDIAN FILEPOS bit size: %d\n", + program, fileposlen); + exit(1); + } #else /* CALC_BYTE_ORDER == BIG_ENDIAN */ - /* - * Little Endian - */ + /* + * Little Endian + */ #if defined(HAVE_FILEPOS_SCALAR) - printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n" - "\t(*((HALF *)(dest)) = *((HALF *)(src)))\n"); + printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n" + "\t(*((HALF *)(dest)) = *((HALF *)(src)))\n"); #else /* HAVE_FILEPOS_SCALAR */ - /* - * Normally a "(*(dest) = *(src))" would do, but on some - * systems a FILEPOS is not a scalar hence we must memcpy. - */ - printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n" - "\tmemcpy((void *)(dest), (void *)(src), FILEPOS_LEN)\n"); + /* + * Normally a "(*(dest) = *(src))" would do, but on some + * systems a FILEPOS is not a scalar hence we must memcpy. + */ + printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n" + "\tmemcpy((void *)(dest), (void *)(src), FILEPOS_LEN)\n"); #endif /* HAVE_FILEPOS_SCALAR */ #endif /* CALC_BYTE_ORDER == BIG_ENDIAN */ - putchar('\n'); + putchar('\n'); - /* - * print the stat file size information - */ + /* + * print the stat file size information + */ #if defined(OFF_T_BITS) - stsizelen = OFF_T_BITS; + stsizelen = OFF_T_BITS; #else - stsizelen = sizeof(buf.st_size)*8; + stsizelen = sizeof(buf.st_size)*8; #endif - printf("#undef OFF_T_BITS\n"); - printf("#define OFF_T_BITS %d\n", stsizelen); - printf("#undef OFF_T_LEN\n"); - printf("#define OFF_T_LEN %d\n", stsizelen/8); + printf("#undef OFF_T_BITS\n"); + printf("#define OFF_T_BITS %d\n", stsizelen); + printf("#undef OFF_T_LEN\n"); + printf("#define OFF_T_LEN %d\n", stsizelen/8); #if CALC_BYTE_ORDER == BIG_ENDIAN - /* - * Big Endian - */ - if (stsizelen == 64) { - printf("#define SWAP_HALF_IN_OFF_T(dest, src)\t\t%s\n", - "SWAP_HALF_IN_B64(dest, src)"); - } else if (stsizelen == 32) { - printf("#define SWAP_HALF_IN_OFF_T(dest, src)\t\t%s\n", - "SWAP_HALF_IN_B32(dest, src)"); - } else { - fprintf(stderr, "%s: unexpected st_size bit size: %d\n", - program, stsizelen); - exit(2); - } + /* + * Big Endian + */ + if (stsizelen == 64) { + printf("#define SWAP_HALF_IN_OFF_T(dest, src)\t\t%s\n", + "SWAP_HALF_IN_B64(dest, src)"); + } else if (stsizelen == 32) { + printf("#define SWAP_HALF_IN_OFF_T(dest, src)\t\t%s\n", + "SWAP_HALF_IN_B32(dest, src)"); + } else { + fprintf(stderr, "%s: unexpected st_size bit size: %d\n", + program, stsizelen); + exit(2); + } #else /* CALC_BYTE_ORDER == BIG_ENDIAN */ - /* - * Little Endian - * - * Normally a "(*(dest) = *(src))" would do, but on some - * systems an off_t is not a scalar hence we must memcpy. - */ + /* + * Little Endian + * + * Normally a "(*(dest) = *(src))" would do, but on some + * systems an off_t is not a scalar hence we must memcpy. + */ #if defined(HAVE_OFF_T_SCALAR) - printf("#define SWAP_HALF_IN_OFF_T(dest, src)\t\t%s\n", - "(*(dest) = *(src))"); + printf("#define SWAP_HALF_IN_OFF_T(dest, src)\t\t%s\n", + "(*(dest) = *(src))"); #else /* HAVE_OFF_T_SCALAR */ - /* - * Normally a "(*(dest) = *(src))" would do, but on some - * systems, a off_t is not a scalar hence we must memcpy. - */ - printf("#define SWAP_HALF_IN_OFF_T(dest, src)\t%s%d%s\n", - "memcpy((void *)(dest), (void *)(src), ", stsizelen/8, ")"); + /* + * Normally a "(*(dest) = *(src))" would do, but on some + * systems, a off_t is not a scalar hence we must memcpy. + */ + printf("#define SWAP_HALF_IN_OFF_T(dest, src)\t%s%d%s\n", + "memcpy((void *)(dest), (void *)(src), ", stsizelen/8, ")"); #endif /* HAVE_OFF_T_SCALAR */ #endif /* CALC_BYTE_ORDER == BIG_ENDIAN */ - putchar('\n'); + putchar('\n'); - /* - * print the dev_t size - */ + /* + * print the dev_t size + */ #if defined(DEV_BITS) - devlen = DEV_BITS; + devlen = DEV_BITS; #else - devlen = sizeof(buf.st_dev)*8; + devlen = sizeof(buf.st_dev)*8; #endif - printf("#undef DEV_BITS\n"); - printf("#define DEV_BITS %d\n", devlen); - printf("#undef DEV_LEN\n"); - printf("#define DEV_LEN %d\n", devlen/8); + printf("#undef DEV_BITS\n"); + printf("#define DEV_BITS %d\n", devlen); + printf("#undef DEV_LEN\n"); + printf("#define DEV_LEN %d\n", devlen/8); #if CALC_BYTE_ORDER == BIG_ENDIAN - /* - * Big Endian - */ - if (devlen == 64) { - printf("#define SWAP_HALF_IN_DEV(dest, src)\t\t%s\n", - "SWAP_HALF_IN_B64(dest, src)"); - } else if (devlen == 32) { - printf("#define SWAP_HALF_IN_DEV(dest, src)\t\t%s\n", - "SWAP_HALF_IN_B32(dest, src)"); - } else if (devlen == 16) { - printf("#define SWAP_HALF_IN_DEV(dest, src)\t\t%s\n", - "(*(dest) = *(src))"); - } else { - fprintf(stderr, "%s: unexpected st_dev bit size: %d\n", - program, devlen); - exit(3); - } + /* + * Big Endian + */ + if (devlen == 64) { + printf("#define SWAP_HALF_IN_DEV(dest, src)\t\t%s\n", + "SWAP_HALF_IN_B64(dest, src)"); + } else if (devlen == 32) { + printf("#define SWAP_HALF_IN_DEV(dest, src)\t\t%s\n", + "SWAP_HALF_IN_B32(dest, src)"); + } else if (devlen == 16) { + printf("#define SWAP_HALF_IN_DEV(dest, src)\t\t%s\n", + "(*(dest) = *(src))"); + } else { + fprintf(stderr, "%s: unexpected st_dev bit size: %d\n", + program, devlen); + exit(3); + } #else /* CALC_BYTE_ORDER == BIG_ENDIAN */ - /* - * Little Endian - * - * Normally a "(*(dest) = *(src))" would do, but on some - * systems, a DEV is not a scalar hence we must memcpy. - */ - printf("#define SWAP_HALF_IN_DEV(dest, src)\t%s%d%s\n", - "memcpy((void *)(dest), (void *)(src), ", devlen/8, ")"); + /* + * Little Endian + * + * Normally a "(*(dest) = *(src))" would do, but on some + * systems, a DEV is not a scalar hence we must memcpy. + */ + printf("#define SWAP_HALF_IN_DEV(dest, src)\t%s%d%s\n", + "memcpy((void *)(dest), (void *)(src), ", devlen/8, ")"); #endif /* CALC_BYTE_ORDER == BIG_ENDIAN */ - putchar('\n'); + putchar('\n'); - /* - * print the ino_t size - */ + /* + * print the ino_t size + */ #if defined(INODE_BITS) - inodelen = INODE_BITS; + inodelen = INODE_BITS; #else - inodelen = sizeof(buf.st_ino)*8; + inodelen = sizeof(buf.st_ino)*8; #endif - printf("#undef INODE_BITS\n"); - printf("#define INODE_BITS %d\n", inodelen); - printf("#undef INODE_LEN\n"); - printf("#define INODE_LEN %d\n", inodelen/8); + printf("#undef INODE_BITS\n"); + printf("#define INODE_BITS %d\n", inodelen); + printf("#undef INODE_LEN\n"); + printf("#define INODE_LEN %d\n", inodelen/8); #if CALC_BYTE_ORDER == BIG_ENDIAN - /* - * Big Endian - */ - if (inodelen == 64) { - printf("#define SWAP_HALF_IN_INODE(dest, src)\t\t%s\n", - "SWAP_HALF_IN_B64(dest, src)"); - } else if (inodelen == 32) { - printf("#define SWAP_HALF_IN_INODE(dest, src)\t\t%s\n", - "SWAP_HALF_IN_B32(dest, src)"); - } else if (inodelen == 16) { - printf("#define SWAP_HALF_IN_INODE(dest, src)\t\t%s\n", - "(*(dest) = *(src))"); - } else { - fprintf(stderr, "%s: unexpected st_ino bit size: %d\n", - program, inodelen); - exit(4); - } + /* + * Big Endian + */ + if (inodelen == 64) { + printf("#define SWAP_HALF_IN_INODE(dest, src)\t\t%s\n", + "SWAP_HALF_IN_B64(dest, src)"); + } else if (inodelen == 32) { + printf("#define SWAP_HALF_IN_INODE(dest, src)\t\t%s\n", + "SWAP_HALF_IN_B32(dest, src)"); + } else if (inodelen == 16) { + printf("#define SWAP_HALF_IN_INODE(dest, src)\t\t%s\n", + "(*(dest) = *(src))"); + } else { + fprintf(stderr, "%s: unexpected st_ino bit size: %d\n", + program, inodelen); + exit(4); + } #else /* CALC_BYTE_ORDER == BIG_ENDIAN */ - /* - * Little Endian - * - * Normally a "(*(dest) = *(src))" would do, but on some - * systems, a INODE is not a scalar hence we must memcpy. - */ - printf("#define SWAP_HALF_IN_INODE(dest, src)\t%s%d%s\n", - "memcpy((void *)(dest), (void *)(src), ", inodelen/8, ")"); + /* + * Little Endian + * + * Normally a "(*(dest) = *(src))" would do, but on some + * systems, a INODE is not a scalar hence we must memcpy. + */ + printf("#define SWAP_HALF_IN_INODE(dest, src)\t%s%d%s\n", + "memcpy((void *)(dest), (void *)(src), ", inodelen/8, ")"); #endif /* CALC_BYTE_ORDER == BIG_ENDIAN */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/fposval.h.def b/fposval.h.def index c9bee60..5e16250 100644 --- a/fposval.h.def +++ b/fposval.h.def @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,15 +17,15 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2021/03/10 22;14:26 - * File existed as early as: 2021 + * Under source code control: 2021/03/10 22;14:26 + * File existed as early as: 2021 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * WARNING: For some reason fposval failed to generate values - * so we choose these values that are hopefully OK + * so we choose these values that are hopefully OK */ /* what are our file position & size types? */ @@ -33,22 +33,22 @@ #define FILEPOS_BITS 64 #undef FILEPOS_LEN #define FILEPOS_LEN 8 -#define SWAP_HALF_IN_FILEPOS(dest, src) (*(dest) = *(src)) +#define SWAP_HALF_IN_FILEPOS(dest, src) (*(dest) = *(src)) #undef OFF_T_BITS #define OFF_T_BITS 64 #undef OFF_T_LEN #define OFF_T_LEN 8 -#define SWAP_HALF_IN_OFF_T(dest, src) (*(dest) = *(src)) +#define SWAP_HALF_IN_OFF_T(dest, src) (*(dest) = *(src)) #undef DEV_BITS #define DEV_BITS 32 #undef DEV_LEN #define DEV_LEN 4 -#define SWAP_HALF_IN_DEV(dest, src) memcpy((void *)(dest), (void *)(src), 4) +#define SWAP_HALF_IN_DEV(dest, src) memcpy((void *)(dest), (void *)(src), 4) #undef INODE_BITS #define INODE_BITS 64 #undef INODE_LEN #define INODE_LEN 8 -#define SWAP_HALF_IN_INODE(dest, src) memcpy((void *)(dest), (void *)(src), 8) +#define SWAP_HALF_IN_INODE(dest, src) memcpy((void *)(dest), (void *)(src), 8) diff --git a/func.c b/func.c index 8c21c81..89c1094 100644 --- a/func.c +++ b/func.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:15 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:15 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -113,7 +113,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* @@ -130,7 +130,7 @@ S_FUNC int malloced_putenv(char *str); /* * external declarations */ -EXTERN char cmdbuf[]; /* command line expression */ +EXTERN char cmdbuf[]; /* command line expression */ E_FUNC void matrandperm(MATRIX *M); E_FUNC void listrandperm(LIST *lp); E_FUNC int idungetc(FILEID id, int ch); @@ -141,14 +141,14 @@ E_FUNC LIST* matindices(MATRIX *mp, long index); /* * malloced environment storage */ -#define ENV_POOL_CHUNK (1<8) /* env_pool elements to allocate at a time */ +#define ENV_POOL_CHUNK (1<8) /* env_pool elements to allocate at a time */ struct env_pool { - char *getenv; /* what getenv() would return, NULL => unused */ - char *putenv; /* pointer given to putenv() */ + char *getenv; /* what getenv() would return, NULL => unused */ + char *putenv; /* pointer given to putenv() */ }; -STATIC int env_pool_cnt = 0; /* number of env_pool elements in use */ -STATIC int env_pool_max = 0; /* number of env_pool elements allocated */ -STATIC struct env_pool *e_pool = NULL; /* env_pool elements */ +STATIC int env_pool_cnt = 0; /* number of env_pool elements in use */ +STATIC int env_pool_max = 0; /* number of env_pool elements allocated */ +STATIC struct env_pool *e_pool = NULL; /* env_pool elements */ /* @@ -159,15 +159,15 @@ STATIC HALF _twentyfourval_[] = { 24 }; STATIC HALF _threesixtyval_[] = { 360 }; STATIC HALF _fourhundredval_[] = { 400 }; STATIC NUMBER _qtendivnine_ = { { _tenval_, 1, 0 }, - { _nineval_, 1, 0 }, 1, NULL }; + { _nineval_, 1, 0 }, 1, NULL }; STATIC NUMBER _qninedivten_ = { { _nineval_, 1, 0 }, - { _tenval_, 1, 0 }, 1, NULL }; + { _tenval_, 1, 0 }, 1, NULL }; STATIC NUMBER _qtwentyfour = { { _twentyfourval_, 1, 0 }, - { _oneval_, 1, 0 }, 1, NULL }; + { _oneval_, 1, 0 }, 1, NULL }; STATIC NUMBER _qthreesixty = { { _threesixtyval_, 1, 0 }, - { _oneval_, 1, 0 }, 1, NULL }; + { _oneval_, 1, 0 }, 1, NULL }; STATIC NUMBER _qfourhundred = { { _fourhundredval_, 1, 0 }, - { _oneval_, 1, 0 }, 1, NULL }; + { _oneval_, 1, 0 }, 1, NULL }; /* @@ -182,9 +182,9 @@ STATIC STRINGHEAD newerrorstr; /* * arg count definitions */ -#define IN 1024 /* maximum number of arguments */ -#define FE 0x01 /* flag to indicate default epsilon argument */ -#define FA 0x02 /* preserve addresses of variables */ +#define IN 1024 /* maximum number of arguments */ +#define FE 0x01 /* flag to indicate default epsilon argument */ +#define FA 0x02 /* preserve addresses of variables */ /* @@ -192,38 +192,38 @@ STATIC STRINGHEAD newerrorstr; */ typedef union { - char *null; /* no b_numfunc function */ - NUMBER *(*numfunc_0)(void); + char *null; /* no b_numfunc function */ + NUMBER *(*numfunc_0)(void); #if !defined(FUNCLIST) - NUMBER *(*numfunc_1)(NUMBER *); - NUMBER *(*numfunc_2)(NUMBER *, NUMBER *); - NUMBER *(*numfunc_3)(NUMBER *, NUMBER *, NUMBER *); - NUMBER *(*numfunc_4)(NUMBER *, NUMBER *, NUMBER *, NUMBER *); - NUMBER *(*numfunc_cnt)(int, NUMBER **); + NUMBER *(*numfunc_1)(NUMBER *); + NUMBER *(*numfunc_2)(NUMBER *, NUMBER *); + NUMBER *(*numfunc_3)(NUMBER *, NUMBER *, NUMBER *); + NUMBER *(*numfunc_4)(NUMBER *, NUMBER *, NUMBER *, NUMBER *); + NUMBER *(*numfunc_cnt)(int, NUMBER **); #endif /* !FUNCLIST */ } numfunc; typedef union { - char *null; /* no b_valfunc function */ - VALUE (*valfunc_0)(void); + char *null; /* no b_valfunc function */ + VALUE (*valfunc_0)(void); #if !defined(FUNCLIST) - VALUE (*valfunc_1)(VALUE *); - VALUE (*valfunc_2)(VALUE *, VALUE *); - VALUE (*valfunc_3)(VALUE *, VALUE *, VALUE *); - VALUE (*valfunc_4)(VALUE *, VALUE *, VALUE *, VALUE *); - VALUE (*valfunc_cnt)(int, VALUE **); + VALUE (*valfunc_1)(VALUE *); + VALUE (*valfunc_2)(VALUE *, VALUE *); + VALUE (*valfunc_3)(VALUE *, VALUE *, VALUE *); + VALUE (*valfunc_4)(VALUE *, VALUE *, VALUE *, VALUE *); + VALUE (*valfunc_cnt)(int, VALUE **); #endif /* !FUNCLIST */ } valfunc; struct builtin { - char *b_name; /* name of built-in function */ - short b_minargs; /* minimum number of arguments */ - short b_maxargs; /* maximum number of arguments */ - short b_flags; /* special handling flags */ - short b_opcode; /* opcode which makes the call quick */ - numfunc b_numfunc; /* routine to calculate numeric function */ - valfunc b_valfunc; /* routine to calculate general values */ - char *b_desc; /* description of function */ + char *b_name; /* name of built-in function */ + short b_minargs; /* minimum number of arguments */ + short b_maxargs; /* maximum number of arguments */ + short b_flags; /* special handling flags */ + short b_opcode; /* opcode which makes the call quick */ + numfunc b_numfunc; /* routine to calculate numeric function */ + valfunc b_valfunc; /* routine to calculate general values */ + char *b_desc; /* description of function */ }; @@ -236,42 +236,42 @@ struct builtin { * The eps argument, when given to a builtin function, overrides * the global epsilon value. As such, the numeric value of eps must be: * - * 0 < eps < 1 + * 0 < eps < 1 * * given: - * veps a eps VALUE passed to a builtin function + * veps a eps VALUE passed to a builtin function * * returns: - * true veps is a non-NULL pointer to a VALUE, and - * VALUE type is V_NUM, - * eps value is 0 < eps < 1 - * false otherwise + * true veps is a non-NULL pointer to a VALUE, and + * VALUE type is V_NUM, + * eps value is 0 < eps < 1 + * false otherwise */ S_FUNC bool verify_eps(VALUE CONST *veps) { - NUMBER *eps; /* VALUE as a NUMBER */ + NUMBER *eps; /* VALUE as a NUMBER */ - /* - * firewall - must be a non-NULL VALUE ptr for a V_NUM - */ - if (veps == NULL) { - return false; - } - if (veps->v_type != V_NUM) { - return false; - } + /* + * firewall - must be a non-NULL VALUE ptr for a V_NUM + */ + if (veps == NULL) { + return false; + } + if (veps->v_type != V_NUM) { + return false; + } - /* - * numeric value must be valid for an epsilon value - * - * 0 < eps < 1 - */ - eps = veps->v_num; - if (check_epsilon(eps) == false) { - return false; - } - return true; + /* + * numeric value must be valid for an epsilon value + * + * 0 < eps < 1 + */ + eps = veps->v_num; + if (check_epsilon(eps) == false) { + return false; + } + return true; } @@ -279,170 +279,170 @@ verify_eps(VALUE CONST *veps) * name_newerrorstr - obtain the name string for a user-described error code * * given: - * errnum errnum code to convert + * errnum errnum code to convert * * returns: - * != NULL ==> non-empty name string for a user-described error - * == NULL ==> errnum is not valid, or name string is empty, or name string not found + * != NULL ==> non-empty name string for a user-described error + * == NULL ==> errnum is not valid, or name string is empty, or name string not found */ char * name_newerrorstr(int errnum) { - char *cp; /* name string lookup result */ + char *cp; /* name string lookup result */ - /* - * firewall - */ - if (is_valid_errnum(errnum) == false) { - /* errnum is not a valid code */ + /* + * firewall + */ + if (is_valid_errnum(errnum) == false) { + /* errnum is not a valid code */ return NULL; - } + } - /* - * case: errnum is not a user-described code - */ - if (errnum < E__USERDEF || errnum > E__USERMAX) { - /* errnum is not a user-described code */ + /* + * case: errnum is not a user-described code + */ + if (errnum < E__USERDEF || errnum > E__USERMAX) { + /* errnum is not a user-described code */ return NULL; - } + } - /* - * case: errnum is outside the current range of user-described codes - */ - if (errnum >= nexterrnum) { - /* errnum is refers to an unassigned user-described code */ - return NULL; - } + /* + * case: errnum is outside the current range of user-described codes + */ + if (errnum >= nexterrnum) { + /* errnum is refers to an unassigned user-described code */ + return NULL; + } - /* - * attempt to fetch the name string for a user-described error code - */ - cp = namestr(&newerrorstr, errnum - E__USERDEF); - if (cp == NULL || cp[0] == '\0') { - /* name string was not found or was empty for the user-described error code */ - return NULL; - } + /* + * attempt to fetch the name string for a user-described error code + */ + cp = namestr(&newerrorstr, errnum - E__USERDEF); + if (cp == NULL || cp[0] == '\0') { + /* name string was not found or was empty for the user-described error code */ + return NULL; + } - /* - * return the name string for the user-described error code - */ - return cp; + /* + * return the name string for the user-described error code + */ + return cp; } S_FUNC VALUE f_eval(VALUE *vp) { - FUNC *oldfunc; - FUNC *newfunc; - VALUE result; - char *str; - size_t num; - long temp_stoponerror; /* temp value of stoponerror */ + FUNC *oldfunc; + FUNC *newfunc; + VALUE result; + char *str; + size_t num; + long temp_stoponerror; /* temp value of stoponerror */ - if (vp->v_type != V_STR) - return error_value(E_EVAL_2); - str = vp->v_str->s_str; - num = vp->v_str->s_len; - switch (openstring(str, num)) { - case -2: - return error_value(E_EVAL_3); - case -1: - return error_value(E_EVAL_4); - } - oldfunc = curfunc; - enterfilescope(); - temp_stoponerror = stoponerror; - stoponerror = -1; - if (evaluate(true)) { - stoponerror = temp_stoponerror; - closeinput(); - exitfilescope(); - freevalue(stack--); - newfunc = curfunc; - curfunc = oldfunc; - result = newfunc->f_savedvalue; - newfunc->f_savedvalue.v_type = V_NULL; - newfunc->f_savedvalue.v_subtype = V_NOSUBTYPE; - freenumbers(newfunc); - if (newfunc != oldfunc) - free(newfunc); - return result; - } - stoponerror = temp_stoponerror; - closeinput(); - exitfilescope(); - newfunc = curfunc; - curfunc = oldfunc; - freevalue(&newfunc->f_savedvalue); - newfunc->f_savedvalue.v_type = V_NULL; - newfunc->f_savedvalue.v_subtype = V_NOSUBTYPE; - freenumbers(newfunc); - if (newfunc != oldfunc) - free(newfunc); - return error_value(E_EVAL); + if (vp->v_type != V_STR) + return error_value(E_EVAL_2); + str = vp->v_str->s_str; + num = vp->v_str->s_len; + switch (openstring(str, num)) { + case -2: + return error_value(E_EVAL_3); + case -1: + return error_value(E_EVAL_4); + } + oldfunc = curfunc; + enterfilescope(); + temp_stoponerror = stoponerror; + stoponerror = -1; + if (evaluate(true)) { + stoponerror = temp_stoponerror; + closeinput(); + exitfilescope(); + freevalue(stack--); + newfunc = curfunc; + curfunc = oldfunc; + result = newfunc->f_savedvalue; + newfunc->f_savedvalue.v_type = V_NULL; + newfunc->f_savedvalue.v_subtype = V_NOSUBTYPE; + freenumbers(newfunc); + if (newfunc != oldfunc) + free(newfunc); + return result; + } + stoponerror = temp_stoponerror; + closeinput(); + exitfilescope(); + newfunc = curfunc; + curfunc = oldfunc; + freevalue(&newfunc->f_savedvalue); + newfunc->f_savedvalue.v_type = V_NULL; + newfunc->f_savedvalue.v_subtype = V_NOSUBTYPE; + freenumbers(newfunc); + if (newfunc != oldfunc) + free(newfunc); + return error_value(E_EVAL); } S_FUNC VALUE f_prompt(VALUE *vp) { - VALUE result; - char *cp; - char *newcp; - size_t len; + VALUE result; + char *cp; + char *newcp; + size_t len; - /* initialize VALUE */ - result.v_type = V_STR; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_STR; + result.v_subtype = V_NOSUBTYPE; - openterminal(); - printvalue(vp, PRINT_SHORT); - math_flush(); - cp = nextline(); - closeinput(); - if (cp == NULL) { - result.v_type = V_NULL; - return result; - } - if (*cp == '\0') { - result.v_str = slink(&_nullstring_); - return result; - } - len = strlen(cp); - newcp = (char *) malloc(len + 1); - if (newcp == NULL) { - math_error("Cannot allocate string"); - not_reached(); - } - strlcpy(newcp, cp, len+1); - result.v_str = makestring(newcp); - return result; + openterminal(); + printvalue(vp, PRINT_SHORT); + math_flush(); + cp = nextline(); + closeinput(); + if (cp == NULL) { + result.v_type = V_NULL; + return result; + } + if (*cp == '\0') { + result.v_str = slink(&_nullstring_); + return result; + } + len = strlen(cp); + newcp = (char *) malloc(len + 1); + if (newcp == NULL) { + math_error("Cannot allocate string"); + not_reached(); + } + strlcpy(newcp, cp, len+1); + result.v_str = makestring(newcp); + return result; } S_FUNC VALUE f_display(int count, VALUE **vals) { - LEN oldvalue; - VALUE res; + LEN oldvalue; + VALUE res; - /* initialize VALUE */ - res.v_type = V_NUM; - res.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + res.v_type = V_NUM; + res.v_subtype = V_NOSUBTYPE; - oldvalue = conf->outdigits; + oldvalue = conf->outdigits; - if (count > 0) { - if (vals[0]->v_type != V_NUM || qisfrac(vals[0]->v_num) || - qisneg(vals[0]->v_num) || zge31b(vals[0]->v_num->num)) - fprintf(stderr, - "Out-of-range arg for display ignored\n"); - else - conf->outdigits = (LEN) qtoi(vals[0]->v_num); - } - res.v_num = itoq((long) oldvalue); - return res; + if (count > 0) { + if (vals[0]->v_type != V_NUM || qisfrac(vals[0]->v_num) || + qisneg(vals[0]->v_num) || zge31b(vals[0]->v_num->num)) + fprintf(stderr, + "Out-of-range arg for display ignored\n"); + else + conf->outdigits = (LEN) qtoi(vals[0]->v_num); + } + res.v_num = itoq((long) oldvalue); + return res; } @@ -450,105 +450,105 @@ f_display(int count, VALUE **vals) S_FUNC VALUE f_null(int UNUSED(count), VALUE **UNUSED(vals)) { - VALUE res; + VALUE res; - /* initialize VALUE */ - res.v_type = V_NULL; - res.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + res.v_type = V_NULL; + res.v_subtype = V_NOSUBTYPE; - return res; + return res; } S_FUNC VALUE f_str(VALUE *vp) { - VALUE result; - char *cp; + VALUE result; + char *cp; - /* initialize VALUE */ - result.v_type = V_STR; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_STR; + result.v_subtype = V_NOSUBTYPE; - switch (vp->v_type) { - case V_STR: - result.v_str = makenewstring(vp->v_str->s_str); - break; - case V_NULL: - result.v_str = slink(&_nullstring_); - break; - case V_OCTET: - result.v_str = charstring(*vp->v_octet); - break; - case V_NUM: - math_divertio(); - qprintnum(vp->v_num, MODE_DEFAULT, conf->outdigits); - cp = math_getdivertedio(); - result.v_str = makestring(cp); - break; - case V_COM: - math_divertio(); - comprint(vp->v_com); - cp = math_getdivertedio(); - result.v_str = makestring(cp); - break; - default: - return error_value(E_STR); - } - return result; + switch (vp->v_type) { + case V_STR: + result.v_str = makenewstring(vp->v_str->s_str); + break; + case V_NULL: + result.v_str = slink(&_nullstring_); + break; + case V_OCTET: + result.v_str = charstring(*vp->v_octet); + break; + case V_NUM: + math_divertio(); + qprintnum(vp->v_num, MODE_DEFAULT, conf->outdigits); + cp = math_getdivertedio(); + result.v_str = makestring(cp); + break; + case V_COM: + math_divertio(); + comprint(vp->v_com); + cp = math_getdivertedio(); + result.v_str = makestring(cp); + break; + default: + return error_value(E_STR); + } + return result; } S_FUNC VALUE f_estr(VALUE *vp) { - VALUE result; - char *cp; + VALUE result; + char *cp; - /* initialize result */ - result.v_type = V_STR; - result.v_subtype = V_NOSUBTYPE; + /* initialize result */ + result.v_type = V_STR; + result.v_subtype = V_NOSUBTYPE; - math_divertio(); - printestr(vp); - cp = math_getdivertedio(); - result.v_str = makestring(cp); - return result; + math_divertio(); + printestr(vp); + cp = math_getdivertedio(); + result.v_str = makestring(cp); + return result; } S_FUNC VALUE f_name(VALUE *vp) { - VALUE result; - char *cp; - char *name; + VALUE result; + char *cp; + char *name; - /* initialize VALUE */ - result.v_type = V_STR; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_STR; + result.v_subtype = V_NOSUBTYPE; - switch (vp->v_type) { - case V_NBLOCK: - result.v_type = V_STR; - result.v_str = makenewstring(vp->v_nblock->name); - return result; - case V_FILE: - name = findfname(vp->v_file); - if (name == NULL) { - result.v_type = V_NULL; - return result; - } - math_divertio(); - math_str(name); - cp = math_getdivertedio(); - break; - default: - result.v_type = V_NULL; - return result; - } - result.v_str = makestring(cp); - return result; + switch (vp->v_type) { + case V_NBLOCK: + result.v_type = V_STR; + result.v_str = makenewstring(vp->v_nblock->name); + return result; + case V_FILE: + name = findfname(vp->v_file); + if (name == NULL) { + result.v_type = V_NULL; + return result; + } + math_divertio(); + math_str(name); + cp = math_getdivertedio(); + break; + default: + result.v_type = V_NULL; + return result; + } + result.v_str = makestring(cp); + return result; } @@ -556,2203 +556,2203 @@ f_name(VALUE *vp) S_FUNC VALUE f_poly(int count, VALUE **vals) { - VALUE *x; - VALUE result, tmp; - LIST *clist, *lp; + VALUE *x; + VALUE result, tmp; + LIST *clist, *lp; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; - tmp.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; + tmp.v_subtype = V_NOSUBTYPE; - if (vals[0]->v_type == V_LIST) { - clist = vals[0]->v_list; - lp = listalloc(); - while (--count > 0) { - if ((*++vals)->v_type == V_LIST) - insertitems(lp, (*vals)->v_list); - else - insertlistlast(lp, *vals); - } - if (!evalpoly(clist, lp->l_first, &result)) { - result.v_type = V_NUM; - result.v_num = qlink(&_qzero_); - } - listfree(lp); - return result; - } - x = vals[--count]; - copyvalue(*vals++, &result); - while (--count > 0) { - mulvalue(&result, x, &tmp); - freevalue(&result); - addvalue(*vals++, &tmp, &result); - freevalue(&tmp); - } - return result; + if (vals[0]->v_type == V_LIST) { + clist = vals[0]->v_list; + lp = listalloc(); + while (--count > 0) { + if ((*++vals)->v_type == V_LIST) + insertitems(lp, (*vals)->v_list); + else + insertlistlast(lp, *vals); + } + if (!evalpoly(clist, lp->l_first, &result)) { + result.v_type = V_NUM; + result.v_num = qlink(&_qzero_); + } + listfree(lp); + return result; + } + x = vals[--count]; + copyvalue(*vals++, &result); + while (--count > 0) { + mulvalue(&result, x, &tmp); + freevalue(&result); + addvalue(*vals++, &tmp, &result); + freevalue(&tmp); + } + return result; } S_FUNC NUMBER * f_mne(NUMBER *val1, NUMBER *val2, NUMBER *val3) { - NUMBER *tmp, *res; + NUMBER *tmp, *res; - tmp = qsub(val1, val2); - res = itoq((long) !qdivides(tmp, val3)); - qfree(tmp); - return res; + tmp = qsub(val1, val2); + res = itoq((long) !qdivides(tmp, val3)); + qfree(tmp); + return res; } S_FUNC NUMBER * f_isrel(NUMBER *val1, NUMBER *val2) { - if (qisfrac(val1) || qisfrac(val2)) { - math_error("Non-integer for isrel"); - not_reached(); - } - return itoq((long) zrelprime(val1->num, val2->num)); + if (qisfrac(val1) || qisfrac(val2)) { + math_error("Non-integer for isrel"); + not_reached(); + } + return itoq((long) zrelprime(val1->num, val2->num)); } S_FUNC NUMBER * f_issquare(NUMBER *vp) { - return itoq((long) qissquare(vp)); + return itoq((long) qissquare(vp)); } S_FUNC NUMBER * f_isprime(int count, NUMBER **vals) { - NUMBER *err; /* error return, NULL => use math_error */ + NUMBER *err; /* error return, NULL => use math_error */ - /* determine the way we report problems */ - if (count == 2) { - if (qisfrac(vals[1])) { - math_error("2nd isprime arg must be an integer"); - not_reached(); - } - err = vals[1]; - } else { - err = NULL; - } + /* determine the way we report problems */ + if (count == 2) { + if (qisfrac(vals[1])) { + math_error("2nd isprime arg must be an integer"); + not_reached(); + } + err = vals[1]; + } else { + err = NULL; + } - /* firewall - must be an integer */ - if (qisfrac(vals[0])) { - if (err) { - return qlink(err); - } - math_error("non-integral arg for builtin function isprime"); - not_reached(); - } + /* firewall - must be an integer */ + if (qisfrac(vals[0])) { + if (err) { + return qlink(err); + } + math_error("non-integral arg for builtin function isprime"); + not_reached(); + } - /* test the integer */ - switch (zisprime(vals[0]->num)) { - case 0: return qlink(&_qzero_); - case 1: return qlink(&_qone_); - } + /* test the integer */ + switch (zisprime(vals[0]->num)) { + case 0: return qlink(&_qzero_); + case 1: return qlink(&_qone_); + } - /* error return */ - if (!err) { - math_error("isprime argument is an odd value > 2^32"); - not_reached(); - } - return qlink(err); + /* error return */ + if (!err) { + math_error("isprime argument is an odd value > 2^32"); + not_reached(); + } + return qlink(err); } S_FUNC NUMBER * f_nprime(int count, NUMBER **vals) { - NUMBER *err; /* error return, NULL => use math_error */ - FULL nxt_prime; /* next prime or 0 */ + NUMBER *err; /* error return, NULL => use math_error */ + FULL nxt_prime; /* next prime or 0 */ - /* determine the way we report problems */ - if (count == 2) { - if (qisfrac(vals[1])) { - math_error("2nd nextprime arg must be an integer"); - not_reached(); - } - err = vals[1]; - } else { - err = NULL; - } + /* determine the way we report problems */ + if (count == 2) { + if (qisfrac(vals[1])) { + math_error("2nd nextprime arg must be an integer"); + not_reached(); + } + err = vals[1]; + } else { + err = NULL; + } - /* firewall - must be an integer */ - if (qisfrac(vals[0])) { - if (err) { - return qlink(err); - } - math_error("non-integral arg 1 for builtin function nextprime"); - not_reached(); - } + /* firewall - must be an integer */ + if (qisfrac(vals[0])) { + if (err) { + return qlink(err); + } + math_error("non-integral arg 1 for builtin function nextprime"); + not_reached(); + } - /* test the integer */ - nxt_prime = znprime(vals[0]->num); - if (nxt_prime > 1) { - return utoq(nxt_prime); - } else if (nxt_prime == 0) { - /* return 2^32+15 */ - return qlink(&_nxtprime_); - } + /* test the integer */ + nxt_prime = znprime(vals[0]->num); + if (nxt_prime > 1) { + return utoq(nxt_prime); + } else if (nxt_prime == 0) { + /* return 2^32+15 */ + return qlink(&_nxtprime_); + } - /* error return */ - if (!err) { - math_error("nextprime arg 1 is >= 2^32"); - not_reached(); - } - return qlink(err); + /* error return */ + if (!err) { + math_error("nextprime arg 1 is >= 2^32"); + not_reached(); + } + return qlink(err); } S_FUNC NUMBER * f_pprime(int count, NUMBER **vals) { - NUMBER *err; /* error return, NULL => use math_error */ - FULL prev_prime; /* previous prime or 0 */ + NUMBER *err; /* error return, NULL => use math_error */ + FULL prev_prime; /* previous prime or 0 */ - /* determine the way we report problems */ - if (count == 2) { - if (qisfrac(vals[1])) { - math_error("2nd prevprime arg must be an integer"); - not_reached(); - } - err = vals[1]; - } else { - err = NULL; - } + /* determine the way we report problems */ + if (count == 2) { + if (qisfrac(vals[1])) { + math_error("2nd prevprime arg must be an integer"); + not_reached(); + } + err = vals[1]; + } else { + err = NULL; + } - /* firewall - must be an integer */ - if (qisfrac(vals[0])) { - if (err) { - return qlink(err); - } - math_error("non-integral arg 1 for builtin function prevprime"); - not_reached(); - } + /* firewall - must be an integer */ + if (qisfrac(vals[0])) { + if (err) { + return qlink(err); + } + math_error("non-integral arg 1 for builtin function prevprime"); + not_reached(); + } - /* test the integer */ - prev_prime = zpprime(vals[0]->num); - if (prev_prime > 1) { - return utoq(prev_prime); - } - if (prev_prime == 0) { - return qlink(&_qzero_); - } - /* error return */ - if (!err) { - if (prev_prime == 0) { - math_error("prevprime arg 1 is <= 2"); - not_reached(); - } else { - math_error("prevprime arg 1 is >= 2^32"); - not_reached(); - } - } - return qlink(err); + /* test the integer */ + prev_prime = zpprime(vals[0]->num); + if (prev_prime > 1) { + return utoq(prev_prime); + } + if (prev_prime == 0) { + return qlink(&_qzero_); + } + /* error return */ + if (!err) { + if (prev_prime == 0) { + math_error("prevprime arg 1 is <= 2"); + not_reached(); + } else { + math_error("prevprime arg 1 is >= 2^32"); + not_reached(); + } + } + return qlink(err); } S_FUNC NUMBER * f_factor(int count, NUMBER **vals) { - NUMBER *err; /* error return, NULL => use math_error */ - ZVALUE limit; /* highest prime factor in search */ - ZVALUE n; /* number to factor */ - NUMBER *factor; /* the prime factor found */ - int res; /* -1 => error, 0 => not found, 1 => factor found */ + NUMBER *err; /* error return, NULL => use math_error */ + ZVALUE limit; /* highest prime factor in search */ + ZVALUE n; /* number to factor */ + NUMBER *factor; /* the prime factor found */ + int res; /* -1 => error, 0 => not found, 1 => factor found */ - /* - * parse args - */ - if (count == 3) { - if (qisfrac(vals[2])) { - math_error("3rd factor arg must be an integer"); - not_reached(); - } - err = vals[2]; - } else { - err = NULL; - } - if (count >= 2) { - if (qisfrac(vals[1])) { - if (err) { - return qlink(err); - } - math_error("non-integral arg 2 for builtin factor"); - not_reached(); - } - limit = vals[1]->num; - } else { - /* default limit is 2^32-1 */ - utoz((FULL)0xffffffff, &limit); - } - if (qisfrac(vals[0])) { - if (count < 2) - zfree(limit); - if (err) { - return qlink(err); - } - math_error("non-integral arg 1 for builtin pfactor"); - not_reached(); - } - n = vals[0]->num; + /* + * parse args + */ + if (count == 3) { + if (qisfrac(vals[2])) { + math_error("3rd factor arg must be an integer"); + not_reached(); + } + err = vals[2]; + } else { + err = NULL; + } + if (count >= 2) { + if (qisfrac(vals[1])) { + if (err) { + return qlink(err); + } + math_error("non-integral arg 2 for builtin factor"); + not_reached(); + } + limit = vals[1]->num; + } else { + /* default limit is 2^32-1 */ + utoz((FULL)0xffffffff, &limit); + } + if (qisfrac(vals[0])) { + if (count < 2) + zfree(limit); + if (err) { + return qlink(err); + } + math_error("non-integral arg 1 for builtin pfactor"); + not_reached(); + } + n = vals[0]->num; - /* - * find the smallest prime factor in the range - */ - factor = qalloc(); - res = zfactor(n, limit, &(factor->num)); - if (res < 0) { - /* error processing */ - if (err) { - return qlink(err); - } - math_error("limit >= 2^32 for builtin factor"); - not_reached(); - } else if (res == 0) { - if (count < 2) - zfree(limit); - /* no factor found - qalloc set factor to 1, return 1 */ - return factor; - } + /* + * find the smallest prime factor in the range + */ + factor = qalloc(); + res = zfactor(n, limit, &(factor->num)); + if (res < 0) { + /* error processing */ + if (err) { + return qlink(err); + } + math_error("limit >= 2^32 for builtin factor"); + not_reached(); + } else if (res == 0) { + if (count < 2) + zfree(limit); + /* no factor found - qalloc set factor to 1, return 1 */ + return factor; + } - /* - * return the factor found - */ - if (count < 2) - zfree(limit); - return factor; + /* + * return the factor found + */ + if (count < 2) + zfree(limit); + return factor; } S_FUNC NUMBER * f_pix(int count, NUMBER **vals) { - NUMBER *err; /* error return, NULL => use math_error */ - long value; /* primes <= x, or 0 ==> error */ + NUMBER *err; /* error return, NULL => use math_error */ + long value; /* primes <= x, or 0 ==> error */ - /* determine the way we report problems */ - if (count == 2) { - if (qisfrac(vals[1])) { - math_error("2nd pix arg must be an integer"); - not_reached(); - } - err = vals[1]; - } else { - err = NULL; - } + /* determine the way we report problems */ + if (count == 2) { + if (qisfrac(vals[1])) { + math_error("2nd pix arg must be an integer"); + not_reached(); + } + err = vals[1]; + } else { + err = NULL; + } - /* firewall - must be an integer */ - if (qisfrac(vals[0])) { - if (err) { - return qlink(err); - } - math_error("non-integral arg 1 for builtin function pix"); - not_reached(); - } + /* firewall - must be an integer */ + if (qisfrac(vals[0])) { + if (err) { + return qlink(err); + } + math_error("non-integral arg 1 for builtin function pix"); + not_reached(); + } - /* determine the number of primes <= x */ - value = zpix(vals[0]->num); - if (value >= 0) { - return utoq(value); - } + /* determine the number of primes <= x */ + value = zpix(vals[0]->num); + if (value >= 0) { + return utoq(value); + } - /* error return */ - if (!err) { - math_error("pix arg 1 is >= 2^32"); - not_reached(); - } - return qlink(err); + /* error return */ + if (!err) { + math_error("pix arg 1 is >= 2^32"); + not_reached(); + } + return qlink(err); } S_FUNC NUMBER * f_prevcand(int count, NUMBER **vals) { - ZVALUE zmodulus; - ZVALUE zresidue; - ZVALUE zskip; - ZVALUE *zcount = NULL; /* ptest trial count */ - ZVALUE tmp; - NUMBER *ans; /* candidate for primality */ + ZVALUE zmodulus; + ZVALUE zresidue; + ZVALUE zskip; + ZVALUE *zcount = NULL; /* ptest trial count */ + ZVALUE tmp; + NUMBER *ans; /* candidate for primality */ - zmodulus = _one_; - zresidue = _zero_; - zskip = _one_; - /* - * check on the number of args passed and that args passed are ints - */ - switch (count) { - case 5: - if (!qisint(vals[4])) { - math_error( "prevcand 5th arg must both be integer"); - not_reached(); - } - zmodulus = vals[4]->num; - /*FALLTHRU*/ - case 4: - if (!qisint(vals[3])) { - math_error( "prevcand 4th arg must both be integer"); - not_reached(); - } - zresidue = vals[3]->num; - /*FALLTHRU*/ - case 3: - if (!qisint(vals[2])) { - math_error( - "prevcand skip arg (3rd) must be an integer or omitted"); - not_reached(); - } - zskip = vals[2]->num; - /*FALLTHRU*/ - case 2: - if (!qisint(vals[1])) { - math_error( - "prevcand count arg (2nd) must be an integer or omitted"); - not_reached(); - } - zcount = &vals[1]->num; - /*FALLTHRU*/ - case 1: - if (!qisint(vals[0])) { - math_error( - "prevcand search arg (1st) must be an integer"); - not_reached(); - } - break; - default: - math_error("invalid number of args passed to prevcand"); - not_reached(); - break; - } + zmodulus = _one_; + zresidue = _zero_; + zskip = _one_; + /* + * check on the number of args passed and that args passed are ints + */ + switch (count) { + case 5: + if (!qisint(vals[4])) { + math_error( "prevcand 5th arg must both be integer"); + not_reached(); + } + zmodulus = vals[4]->num; + /*FALLTHRU*/ + case 4: + if (!qisint(vals[3])) { + math_error( "prevcand 4th arg must both be integer"); + not_reached(); + } + zresidue = vals[3]->num; + /*FALLTHRU*/ + case 3: + if (!qisint(vals[2])) { + math_error( + "prevcand skip arg (3rd) must be an integer or omitted"); + not_reached(); + } + zskip = vals[2]->num; + /*FALLTHRU*/ + case 2: + if (!qisint(vals[1])) { + math_error( + "prevcand count arg (2nd) must be an integer or omitted"); + not_reached(); + } + zcount = &vals[1]->num; + /*FALLTHRU*/ + case 1: + if (!qisint(vals[0])) { + math_error( + "prevcand search arg (1st) must be an integer"); + not_reached(); + } + break; + default: + math_error("invalid number of args passed to prevcand"); + not_reached(); + break; + } - if (zcount == NULL) { - count = 1; /* default is 1 ptest */ - } else { - if (zge24b(*zcount)) { - math_error("prevcand count arg (2nd) must be < 2^24"); - not_reached(); - } - count = ztoi(*zcount); - } + if (zcount == NULL) { + count = 1; /* default is 1 ptest */ + } else { + if (zge24b(*zcount)) { + math_error("prevcand count arg (2nd) must be < 2^24"); + not_reached(); + } + count = ztoi(*zcount); + } - /* - * find the candidate - */ - if (zprevcand(vals[0]->num, count, zskip, zresidue, zmodulus, &tmp)) { - ans = qalloc(); - ans->num = tmp; - return ans; - } - return qlink(&_qzero_); + /* + * find the candidate + */ + if (zprevcand(vals[0]->num, count, zskip, zresidue, zmodulus, &tmp)) { + ans = qalloc(); + ans->num = tmp; + return ans; + } + return qlink(&_qzero_); } S_FUNC NUMBER * f_nextcand(int count, NUMBER **vals) { - ZVALUE zmodulus; - ZVALUE zresidue; - ZVALUE zskip; - ZVALUE *zcount = NULL; /* ptest trial count */ - ZVALUE tmp; - NUMBER *ans; /* candidate for primality */ + ZVALUE zmodulus; + ZVALUE zresidue; + ZVALUE zskip; + ZVALUE *zcount = NULL; /* ptest trial count */ + ZVALUE tmp; + NUMBER *ans; /* candidate for primality */ - zmodulus = _one_; - zresidue = _zero_; - zskip = _one_; - /* - * check on the number of args passed and that args passed are ints - */ - switch (count) { - case 5: - if (!qisint(vals[4])) { - math_error( - "nextcand 5th args must be integer"); - not_reached(); - } - zmodulus = vals[4]->num; - /*FALLTHRU*/ - case 4: - if (!qisint(vals[3])) { - math_error( - "nextcand 5th args must be integer"); - not_reached(); - } - zresidue = vals[3]->num; - /*FALLTHRU*/ - case 3: - if (!qisint(vals[2])) { - math_error( - "nextcand skip arg (3rd) must be an integer or omitted"); - not_reached(); - } - zskip = vals[2]->num; - /*FALLTHRU*/ - case 2: - if (!qisint(vals[1])) { - math_error( - "nextcand count arg (2nd) must be an integer or omitted"); - not_reached(); - } - zcount = &vals[1]->num; - /*FALLTHRU*/ - case 1: - if (!qisint(vals[0])) { - math_error( - "nextcand search arg (1st) must be an integer"); - not_reached(); - } - break; - default: - math_error("invalid number of args passed to nextcand"); - not_reached(); - } + zmodulus = _one_; + zresidue = _zero_; + zskip = _one_; + /* + * check on the number of args passed and that args passed are ints + */ + switch (count) { + case 5: + if (!qisint(vals[4])) { + math_error( + "nextcand 5th args must be integer"); + not_reached(); + } + zmodulus = vals[4]->num; + /*FALLTHRU*/ + case 4: + if (!qisint(vals[3])) { + math_error( + "nextcand 5th args must be integer"); + not_reached(); + } + zresidue = vals[3]->num; + /*FALLTHRU*/ + case 3: + if (!qisint(vals[2])) { + math_error( + "nextcand skip arg (3rd) must be an integer or omitted"); + not_reached(); + } + zskip = vals[2]->num; + /*FALLTHRU*/ + case 2: + if (!qisint(vals[1])) { + math_error( + "nextcand count arg (2nd) must be an integer or omitted"); + not_reached(); + } + zcount = &vals[1]->num; + /*FALLTHRU*/ + case 1: + if (!qisint(vals[0])) { + math_error( + "nextcand search arg (1st) must be an integer"); + not_reached(); + } + break; + default: + math_error("invalid number of args passed to nextcand"); + not_reached(); + } - /* - * check ranges on integers passed - */ - if (zcount == NULL) { - count = 1; /* default is 1 ptest */ - } else { - if (zge24b(*zcount)) { - math_error("prevcand count arg (2nd) must be < 2^24"); - not_reached(); - } - count = ztoi(*zcount); - } + /* + * check ranges on integers passed + */ + if (zcount == NULL) { + count = 1; /* default is 1 ptest */ + } else { + if (zge24b(*zcount)) { + math_error("prevcand count arg (2nd) must be < 2^24"); + not_reached(); + } + count = ztoi(*zcount); + } - /* - * find the candidate - */ - if (znextcand(vals[0]->num, count, zskip, zresidue, zmodulus, &tmp)) { - ans = qalloc(); - ans->num = tmp; - return ans; - } - return qlink(&_qzero_); + /* + * find the candidate + */ + if (znextcand(vals[0]->num, count, zskip, zresidue, zmodulus, &tmp)) { + ans = qalloc(); + ans->num = tmp; + return ans; + } + return qlink(&_qzero_); } S_FUNC NUMBER * f_seed(void) { - return pseudo_seed(); + return pseudo_seed(); } S_FUNC NUMBER * f_rand(int count, NUMBER **vals) { - NUMBER *ans; + NUMBER *ans; - /* parse args */ - switch (count) { - case 0: /* rand() == rand(2^64) */ - /* generate an subtractive 100 shuffle pseudo-random number */ - ans = qalloc(); - zrand(SBITS, &ans->num); - break; + /* parse args */ + switch (count) { + case 0: /* rand() == rand(2^64) */ + /* generate an subtractive 100 shuffle pseudo-random number */ + ans = qalloc(); + zrand(SBITS, &ans->num); + break; - case 1: /* rand(limit) */ - if (!qisint(vals[0])) { - math_error("rand limit must be an integer"); - not_reached(); - } - if (zislezero(vals[0]->num)) { - math_error("rand limit must > 0"); - not_reached(); - } - ans = qalloc(); - zrandrange(_zero_, vals[0]->num, &ans->num); - break; + case 1: /* rand(limit) */ + if (!qisint(vals[0])) { + math_error("rand limit must be an integer"); + not_reached(); + } + if (zislezero(vals[0]->num)) { + math_error("rand limit must > 0"); + not_reached(); + } + ans = qalloc(); + zrandrange(_zero_, vals[0]->num, &ans->num); + break; - case 2: /* rand(low, limit) */ - /* firewall */ - if (!qisint(vals[0]) || !qisint(vals[1])) { - math_error("rand range must be integers"); - not_reached(); - } - ans = qalloc(); - zrandrange(vals[0]->num, vals[1]->num, &ans->num); - break; + case 2: /* rand(low, limit) */ + /* firewall */ + if (!qisint(vals[0]) || !qisint(vals[1])) { + math_error("rand range must be integers"); + not_reached(); + } + ans = qalloc(); + zrandrange(vals[0]->num, vals[1]->num, &ans->num); + break; - default: - math_error("invalid number of args passed to rand"); - not_reached(); - return NULL; - } + default: + math_error("invalid number of args passed to rand"); + not_reached(); + return NULL; + } - /* return the subtractive 100 shuffle pseudo-random number */ - return ans; + /* return the subtractive 100 shuffle pseudo-random number */ + return ans; } S_FUNC NUMBER * f_randbit(int count, NUMBER **vals) { - NUMBER *ans; - ZVALUE ztmp; - long cnt; /* bits needed or skipped */ + NUMBER *ans; + ZVALUE ztmp; + long cnt; /* bits needed or skipped */ - /* parse args */ - if (count == 0) { - zrand(1, &ztmp); - ans = ziszero(ztmp) ? qlink(&_qzero_) : qlink(&_qone_); - zfree(ztmp); - return ans; - } + /* parse args */ + if (count == 0) { + zrand(1, &ztmp); + ans = ziszero(ztmp) ? qlink(&_qzero_) : qlink(&_qone_); + zfree(ztmp); + return ans; + } - /* - * firewall - */ - if (!qisint(vals[0])) { - math_error("rand bit count must be an integer"); - not_reached(); - } - if (zge31b(vals[0]->num)) { - math_error("huge rand bit count"); - not_reached(); - } + /* + * firewall + */ + if (!qisint(vals[0])) { + math_error("rand bit count must be an integer"); + not_reached(); + } + if (zge31b(vals[0]->num)) { + math_error("huge rand bit count"); + not_reached(); + } - /* - * generate an subtractive 100 shuffle pseudo-random number or skip random bits - */ - ans = qalloc(); - cnt = ztolong(vals[0]->num); - if (zisneg(vals[0]->num)) { - /* skip bits */ - zrandskip(cnt); - itoz(cnt, &ans->num); - } else { - /* generate bits */ - zrand(cnt, &ans->num); - } + /* + * generate an subtractive 100 shuffle pseudo-random number or skip random bits + */ + ans = qalloc(); + cnt = ztolong(vals[0]->num); + if (zisneg(vals[0]->num)) { + /* skip bits */ + zrandskip(cnt); + itoz(cnt, &ans->num); + } else { + /* generate bits */ + zrand(cnt, &ans->num); + } - /* - * return the subtractive 100 shuffle pseudo-random number - */ - return ans; + /* + * return the subtractive 100 shuffle pseudo-random number + */ + return ans; } S_FUNC VALUE f_srand(int count, VALUE **vals) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_type = V_RAND; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_RAND; + result.v_subtype = V_NOSUBTYPE; - /* parse args */ - switch (count) { - case 0: - /* get the current subtractive 100 shuffle pseudo-random number generator state */ - result.v_rand = zsrand(NULL, NULL); - break; + /* parse args */ + switch (count) { + case 0: + /* get the current subtractive 100 shuffle pseudo-random number generator state */ + result.v_rand = zsrand(NULL, NULL); + break; - case 1: - switch (vals[0]->v_type) { - case V_NUM: /* srand(seed) */ - /* seed subtractive 100 shuffle pseudo-random number generator and return previous state */ - if (!qisint(vals[0]->v_num)) { - math_error( - "srand number seed must be an integer"); - not_reached(); - } - result.v_rand = zsrand(&vals[0]->v_num->num, NULL); - break; + case 1: + switch (vals[0]->v_type) { + case V_NUM: /* srand(seed) */ + /* seed subtractive 100 shuffle pseudo-random number generator and return previous state */ + if (!qisint(vals[0]->v_num)) { + math_error( + "srand number seed must be an integer"); + not_reached(); + } + result.v_rand = zsrand(&vals[0]->v_num->num, NULL); + break; - case V_RAND: /* srand(state) */ - /* set subtractive 100 shuffle pseudo-random number generator state and return previous state */ - result.v_rand = zsetrand(vals[0]->v_rand); - break; + case V_RAND: /* srand(state) */ + /* set subtractive 100 shuffle pseudo-random number generator state and return previous state */ + result.v_rand = zsetrand(vals[0]->v_rand); + break; - case V_MAT: - /* load subtractive 100 table and return prev state */ - result.v_rand = zsrand(NULL, vals[0]->v_mat); - break; + case V_MAT: + /* load subtractive 100 table and return prev state */ + result.v_rand = zsrand(NULL, vals[0]->v_mat); + break; - default: - math_error("illegal type of arg passed to srand()"); - not_reached(); - break; - } - break; + default: + math_error("illegal type of arg passed to srand()"); + not_reached(); + break; + } + break; - default: - math_error("bad arg count to srand()"); - not_reached(); - break; - } + default: + math_error("bad arg count to srand()"); + not_reached(); + break; + } - /* return the current state */ - return result; + /* return the current state */ + return result; } S_FUNC NUMBER * f_random(int count, NUMBER **vals) { - NUMBER *ans; + NUMBER *ans; - /* parse args */ - switch (count) { - case 0: /* random() == random(2^64) */ - /* generate a Blum-Blum-Shub random number */ - ans = qalloc(); - zrandom(SBITS, &ans->num); - break; + /* parse args */ + switch (count) { + case 0: /* random() == random(2^64) */ + /* generate a Blum-Blum-Shub random number */ + ans = qalloc(); + zrandom(SBITS, &ans->num); + break; - case 1: /* random(limit) */ - if (!qisint(vals[0])) { - math_error("random limit must be an integer"); - not_reached(); - } - if (zislezero(vals[0]->num)) { - math_error("random limit must > 0"); - not_reached(); - } - ans = qalloc(); - zrandomrange(_zero_, vals[0]->num, &ans->num); - break; + case 1: /* random(limit) */ + if (!qisint(vals[0])) { + math_error("random limit must be an integer"); + not_reached(); + } + if (zislezero(vals[0]->num)) { + math_error("random limit must > 0"); + not_reached(); + } + ans = qalloc(); + zrandomrange(_zero_, vals[0]->num, &ans->num); + break; - case 2: /* random(low, limit) */ - /* firewall */ - if (!qisint(vals[0]) || !qisint(vals[1])) { - math_error("random range must be integers"); - not_reached(); - } - ans = qalloc(); - zrandomrange(vals[0]->num, vals[1]->num, &ans->num); - break; + case 2: /* random(low, limit) */ + /* firewall */ + if (!qisint(vals[0]) || !qisint(vals[1])) { + math_error("random range must be integers"); + not_reached(); + } + ans = qalloc(); + zrandomrange(vals[0]->num, vals[1]->num, &ans->num); + break; - default: - math_error("invalid number of args passed to random"); - not_reached(); - return NULL; - } + default: + math_error("invalid number of args passed to random"); + not_reached(); + return NULL; + } - /* return the Blum-Blum-Shub random number */ - return ans; + /* return the Blum-Blum-Shub random number */ + return ans; } S_FUNC NUMBER * f_randombit(int count, NUMBER **vals) { - NUMBER *ans; - ZVALUE ztmp; - long cnt; /* bits needed or skipped */ + NUMBER *ans; + ZVALUE ztmp; + long cnt; /* bits needed or skipped */ - /* parse args */ - ztmp.len = 0; /* paranoia */ - ztmp.v = NULL; - ztmp.sign = 0; - if (count == 0) { - zrandom(1, &ztmp); - ans = ziszero(ztmp) ? qlink(&_qzero_) : qlink(&_qone_); - zfree(ztmp); - return ans; - } + /* parse args */ + ztmp.len = 0; /* paranoia */ + ztmp.v = NULL; + ztmp.sign = 0; + if (count == 0) { + zrandom(1, &ztmp); + ans = ziszero(ztmp) ? qlink(&_qzero_) : qlink(&_qone_); + zfree(ztmp); + return ans; + } - /* - * firewall - */ - if (!qisint(vals[0])) { - math_error("random bit count must be an integer"); - not_reached(); - } - if (zge31b(vals[0]->num)) { - math_error("huge random bit count"); - not_reached(); - } + /* + * firewall + */ + if (!qisint(vals[0])) { + math_error("random bit count must be an integer"); + not_reached(); + } + if (zge31b(vals[0]->num)) { + math_error("huge random bit count"); + not_reached(); + } - /* - * generate a Blum-Blum-Shub random number or skip random bits - */ - ans = qalloc(); - cnt = ztolong(vals[0]->num); - if (zisneg(vals[0]->num)) { - /* skip bits */ - zrandomskip(cnt); - itoz(cnt, &ans->num); - } else { - /* generate bits */ - zrandom(cnt, &ans->num); - } + /* + * generate a Blum-Blum-Shub random number or skip random bits + */ + ans = qalloc(); + cnt = ztolong(vals[0]->num); + if (zisneg(vals[0]->num)) { + /* skip bits */ + zrandomskip(cnt); + itoz(cnt, &ans->num); + } else { + /* generate bits */ + zrandom(cnt, &ans->num); + } - /* - * return the Blum-Blum-Shub random number - */ - return ans; + /* + * return the Blum-Blum-Shub random number + */ + return ans; } S_FUNC VALUE f_srandom(int count, VALUE **vals) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_type = V_RANDOM; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_RANDOM; + result.v_subtype = V_NOSUBTYPE; - /* parse args */ - switch (count) { - case 0: /* srandom() */ - /* get the current random state */ - result.v_random = zsetrandom(NULL); - break; + /* parse args */ + switch (count) { + case 0: /* srandom() */ + /* get the current random state */ + result.v_random = zsetrandom(NULL); + break; - case 1: /* srandom(seed) or srandom(state) */ - switch (vals[0]->v_type) { - case V_NUM: /* srand(seed) */ - /* seed Blum and return previous state */ - if (!qisint(vals[0]->v_num)) { - math_error( - "srandom number seed must be an integer"); - not_reached(); - } - result.v_random = zsrandom1(vals[0]->v_num->num, true); - break; + case 1: /* srandom(seed) or srandom(state) */ + switch (vals[0]->v_type) { + case V_NUM: /* srand(seed) */ + /* seed Blum and return previous state */ + if (!qisint(vals[0]->v_num)) { + math_error( + "srandom number seed must be an integer"); + not_reached(); + } + result.v_random = zsrandom1(vals[0]->v_num->num, true); + break; - case V_RANDOM: /* srandom(state) */ - /* set subtractive 100 shuffle pseudo-random number generator state and return previous state */ - result.v_random = zsetrandom(vals[0]->v_random); - break; + case V_RANDOM: /* srandom(state) */ + /* set subtractive 100 shuffle pseudo-random number generator state and return previous state */ + result.v_random = zsetrandom(vals[0]->v_random); + break; - default: - math_error("illegal type of arg passed to srandom()"); - not_reached(); - break; - } - break; + default: + math_error("illegal type of arg passed to srandom()"); + not_reached(); + break; + } + break; - case 2: /* srandom(seed, newn) */ - if (vals[0]->v_type != V_NUM || !qisint(vals[0]->v_num)) { - math_error("srandom seed must be an integer"); - not_reached(); - } - if (vals[1]->v_type != V_NUM || !qisint(vals[1]->v_num)) { - math_error("srandom Blum modulus must be an integer"); - not_reached(); - } - result.v_random = zsrandom2(vals[0]->v_num->num, - vals[1]->v_num->num); - break; + case 2: /* srandom(seed, newn) */ + if (vals[0]->v_type != V_NUM || !qisint(vals[0]->v_num)) { + math_error("srandom seed must be an integer"); + not_reached(); + } + if (vals[1]->v_type != V_NUM || !qisint(vals[1]->v_num)) { + math_error("srandom Blum modulus must be an integer"); + not_reached(); + } + result.v_random = zsrandom2(vals[0]->v_num->num, + vals[1]->v_num->num); + break; - case 4: /* srandom(seed, ip, iq, trials) */ - if (vals[0]->v_type != V_NUM || !qisint(vals[0]->v_num)) { - math_error("srandom seed must be an integer"); - not_reached(); - } - if (vals[1]->v_type != V_NUM || !qisint(vals[1]->v_num)) { - math_error("srandom 2nd arg must be an integer"); - not_reached(); - } - if (vals[2]->v_type != V_NUM || !qisint(vals[2]->v_num)) { - math_error("srandom 3rd arg must be an integer"); - not_reached(); - } - if (vals[3]->v_type != V_NUM || !qisint(vals[3]->v_num)) { - math_error("srandom 4th arg must be an integer"); - not_reached(); - } - if (zge24b(vals[3]->v_num->num)) { - math_error("srandom trials count is excessive"); - not_reached(); - } - result.v_random = zsrandom4(vals[0]->v_num->num, - vals[1]->v_num->num, - vals[2]->v_num->num, - ztoi(vals[3]->v_num->num)); - break; + case 4: /* srandom(seed, ip, iq, trials) */ + if (vals[0]->v_type != V_NUM || !qisint(vals[0]->v_num)) { + math_error("srandom seed must be an integer"); + not_reached(); + } + if (vals[1]->v_type != V_NUM || !qisint(vals[1]->v_num)) { + math_error("srandom 2nd arg must be an integer"); + not_reached(); + } + if (vals[2]->v_type != V_NUM || !qisint(vals[2]->v_num)) { + math_error("srandom 3rd arg must be an integer"); + not_reached(); + } + if (vals[3]->v_type != V_NUM || !qisint(vals[3]->v_num)) { + math_error("srandom 4th arg must be an integer"); + not_reached(); + } + if (zge24b(vals[3]->v_num->num)) { + math_error("srandom trials count is excessive"); + not_reached(); + } + result.v_random = zsrandom4(vals[0]->v_num->num, + vals[1]->v_num->num, + vals[2]->v_num->num, + ztoi(vals[3]->v_num->num)); + break; - default: - math_error("bad arg count to srandom()"); - not_reached(); - break; - } + default: + math_error("bad arg count to srandom()"); + not_reached(); + break; + } - /* return the current state */ - return result; + /* return the current state */ + return result; } S_FUNC NUMBER * f_primetest(int count, NUMBER **vals) { - /* parse args */ - switch (count) { - case 1: qlink(&_qone_); - qlink(&_qone_); - return itoq((long) qprimetest(vals[0], &_qone_, &_qone_)); - case 2: qlink(&_qone_); - return itoq((long) qprimetest(vals[0], vals[1], &_qone_)); - default: return itoq((long) qprimetest(vals[0], vals[1], vals[2])); - } + /* parse args */ + switch (count) { + case 1: qlink(&_qone_); + qlink(&_qone_); + return itoq((long) qprimetest(vals[0], &_qone_, &_qone_)); + case 2: qlink(&_qone_); + return itoq((long) qprimetest(vals[0], vals[1], &_qone_)); + default: return itoq((long) qprimetest(vals[0], vals[1], vals[2])); + } } S_FUNC VALUE f_setbit(int count, VALUE **vals) { - bool r; - long index; - VALUE result; + bool r; + long index; + VALUE result; - /* initialize VALUE */ - result.v_type = V_NULL; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NULL; + result.v_subtype = V_NOSUBTYPE; - r = (count == 3) ? testvalue(vals[2]) : 1; + r = (count == 3) ? testvalue(vals[2]) : 1; - if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num)) - return error_value(E_SETBIT_1); - if (zge31b(vals[1]->v_num->num)) - return error_value(E_SETBIT_2); - if (vals[0]->v_type != V_STR) - return error_value(E_SETBIT_3); - index = qtoi(vals[1]->v_num); - if (stringsetbit(vals[0]->v_str, index, r)) - return error_value(E_SETBIT_2); - return result; + if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num)) + return error_value(E_SETBIT_1); + if (zge31b(vals[1]->v_num->num)) + return error_value(E_SETBIT_2); + if (vals[0]->v_type != V_STR) + return error_value(E_SETBIT_3); + index = qtoi(vals[1]->v_num); + if (stringsetbit(vals[0]->v_str, index, r)) + return error_value(E_SETBIT_2); + return result; } S_FUNC VALUE f_digit(int count, VALUE **vals) { - VALUE res; - ZVALUE base; + VALUE res; + ZVALUE base; - if (vals[0]->v_type != V_NUM) - return error_value(E_DGT_1); + if (vals[0]->v_type != V_NUM) + return error_value(E_DGT_1); - if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num)) - return error_value(E_DGT_2); + if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num)) + return error_value(E_DGT_2); - if (count == 3) { - if (vals[2]->v_type != V_NUM || qisfrac(vals[2]->v_num)) - return error_value(E_DGT_3); - base = vals[2]->v_num->num; - } else { - base = _ten_; - } - res.v_type = V_NUM; - res.v_subtype = V_NOSUBTYPE; - res.v_num = qdigit(vals[0]->v_num, vals[1]->v_num->num, base); - if (res.v_num == NULL) - return error_value(E_DGT_3); + if (count == 3) { + if (vals[2]->v_type != V_NUM || qisfrac(vals[2]->v_num)) + return error_value(E_DGT_3); + base = vals[2]->v_num->num; + } else { + base = _ten_; + } + res.v_type = V_NUM; + res.v_subtype = V_NOSUBTYPE; + res.v_num = qdigit(vals[0]->v_num, vals[1]->v_num->num, base); + if (res.v_num == NULL) + return error_value(E_DGT_3); - return res; + return res; } S_FUNC VALUE f_digits(int count, VALUE **vals) { - ZVALUE base; - VALUE res; + ZVALUE base; + VALUE res; - if (vals[0]->v_type != V_NUM) - return error_value(E_DGTS_1); - if (count > 1) { - if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num) - || qiszero(vals[1]->v_num) || qisunit(vals[1]->v_num)) - return error_value(E_DGTS_2); - base = vals[1]->v_num->num; - } else { - base = _ten_; - } - res.v_type = V_NUM; - res.v_subtype = V_NOSUBTYPE; - res.v_num = itoq(qdigits(vals[0]->v_num, base)); - return res; + if (vals[0]->v_type != V_NUM) + return error_value(E_DGTS_1); + if (count > 1) { + if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num) + || qiszero(vals[1]->v_num) || qisunit(vals[1]->v_num)) + return error_value(E_DGTS_2); + base = vals[1]->v_num->num; + } else { + base = _ten_; + } + res.v_type = V_NUM; + res.v_subtype = V_NOSUBTYPE; + res.v_num = itoq(qdigits(vals[0]->v_num, base)); + return res; } S_FUNC VALUE f_places(int count, VALUE **vals) { - long places; - VALUE res; + long places; + VALUE res; - if (vals[0]->v_type != V_NUM) - return error_value(E_PLCS_1); - if (count > 1) { - if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num)) - return error_value(E_PLCS_2); - places = qplaces(vals[0]->v_num, vals[1]->v_num->num); - if (places == -2) - return error_value(E_PLCS_2); - } else - places = qdecplaces(vals[0]->v_num); + if (vals[0]->v_type != V_NUM) + return error_value(E_PLCS_1); + if (count > 1) { + if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num)) + return error_value(E_PLCS_2); + places = qplaces(vals[0]->v_num, vals[1]->v_num->num); + if (places == -2) + return error_value(E_PLCS_2); + } else + places = qdecplaces(vals[0]->v_num); - res.v_type = V_NUM; - res.v_subtype = V_NOSUBTYPE; - res.v_num = itoq(places); - return res; + res.v_type = V_NUM; + res.v_subtype = V_NOSUBTYPE; + res.v_num = itoq(places); + return res; } S_FUNC NUMBER * f_popcnt(int count, NUMBER **vals) { - int bitval = 1; + int bitval = 1; - /* - * parse args - */ - if (count == 2 && qiszero(vals[1])) { - bitval = 0; - } + /* + * parse args + */ + if (count == 2 && qiszero(vals[1])) { + bitval = 0; + } - /* - * count bit values - */ - if (qisint(vals[0])) { - return itoq(zpopcnt(vals[0]->num, bitval)); - } else { - return itoq(zpopcnt(vals[0]->num, bitval) + - zpopcnt(vals[0]->den, bitval)); - } + /* + * count bit values + */ + if (qisint(vals[0])) { + return itoq(zpopcnt(vals[0]->num, bitval)); + } else { + return itoq(zpopcnt(vals[0]->num, bitval) + + zpopcnt(vals[0]->den, bitval)); + } } S_FUNC VALUE f_xor(int count, VALUE **vals) { - NUMBER *q, *qtmp; - STRING *s, *stmp; - VALUE result; - int i; - int type; + NUMBER *q, *qtmp; + STRING *s, *stmp; + VALUE result; + int i; + int type; - type = vals[0]->v_type; - result.v_type = type; - result.v_subtype = vals[0]->v_subtype; - for (i = 1; i < count; i++) { - if (vals[i]->v_type != type) - return error_value(E_XOR_1); - } - switch (type) { - case V_NUM: - q = qlink(vals[0]->v_num); - for (i = 1; i < count; i++) { - qtmp = qxor(q, vals[i]->v_num); - qfree(q); - q = qtmp; - } - result.v_num = q; - break; - case V_STR: - s = slink(vals[0]->v_str); - for (i = 1; i < count; i++) { - stmp = stringxor(s, vals[i]->v_str); - sfree(s); - s = stmp; - } - result.v_str = s; - break; - default: - return error_value(E_XOR_2); - } - return result; + type = vals[0]->v_type; + result.v_type = type; + result.v_subtype = vals[0]->v_subtype; + for (i = 1; i < count; i++) { + if (vals[i]->v_type != type) + return error_value(E_XOR_1); + } + switch (type) { + case V_NUM: + q = qlink(vals[0]->v_num); + for (i = 1; i < count; i++) { + qtmp = qxor(q, vals[i]->v_num); + qfree(q); + q = qtmp; + } + result.v_num = q; + break; + case V_STR: + s = slink(vals[0]->v_str); + for (i = 1; i < count; i++) { + stmp = stringxor(s, vals[i]->v_str); + sfree(s); + s = stmp; + } + result.v_str = s; + break; + default: + return error_value(E_XOR_2); + } + return result; } VALUE minlistitems(LIST *lp) { - LISTELEM *ep; - VALUE *vp; - VALUE term; - VALUE rel; - VALUE min; + LISTELEM *ep; + VALUE *vp; + VALUE term; + VALUE rel; + VALUE min; - /* initialize VALUEs */ - min.v_type = V_NULL; - min.v_subtype = V_NOSUBTYPE; - term.v_type = V_NULL; - term.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + min.v_type = V_NULL; + min.v_subtype = V_NOSUBTYPE; + term.v_type = V_NULL; + term.v_subtype = V_NOSUBTYPE; - for (ep = lp->l_first; ep; ep = ep->e_next) { - vp = &ep->e_value; - switch(vp->v_type) { - case V_LIST: - term = minlistitems(vp->v_list); - break; - case V_OBJ: - term = objcall(OBJ_MIN, vp, - NULL_VALUE, NULL_VALUE); - break; - default: - copyvalue(vp, &term); - } - if (min.v_type == V_NULL) { - min = term; - continue; - } - if (term.v_type == V_NULL) - continue; - relvalue(&term, &min, &rel); - if (rel.v_type != V_NUM) { - freevalue(&term); - freevalue(&min); - freevalue(&rel); - return error_value(E_LISTMIN); - } - if (qisneg(rel.v_num)) { - freevalue(&min); - min = term; - } - else - freevalue(&term); - freevalue(&rel); - } - return min; + for (ep = lp->l_first; ep; ep = ep->e_next) { + vp = &ep->e_value; + switch(vp->v_type) { + case V_LIST: + term = minlistitems(vp->v_list); + break; + case V_OBJ: + term = objcall(OBJ_MIN, vp, + NULL_VALUE, NULL_VALUE); + break; + default: + copyvalue(vp, &term); + } + if (min.v_type == V_NULL) { + min = term; + continue; + } + if (term.v_type == V_NULL) + continue; + relvalue(&term, &min, &rel); + if (rel.v_type != V_NUM) { + freevalue(&term); + freevalue(&min); + freevalue(&rel); + return error_value(E_LISTMIN); + } + if (qisneg(rel.v_num)) { + freevalue(&min); + min = term; + } + else + freevalue(&term); + freevalue(&rel); + } + return min; } VALUE maxlistitems(LIST *lp) { - LISTELEM *ep; - VALUE *vp; - VALUE term; - VALUE rel; - VALUE max; + LISTELEM *ep; + VALUE *vp; + VALUE term; + VALUE rel; + VALUE max; - /* initialize VALUEs */ - max.v_type = V_NULL; - max.v_subtype = V_NOSUBTYPE; - term.v_type = V_NULL; - term.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + max.v_type = V_NULL; + max.v_subtype = V_NOSUBTYPE; + term.v_type = V_NULL; + term.v_subtype = V_NOSUBTYPE; - for (ep = lp->l_first; ep; ep = ep->e_next) { - vp = &ep->e_value; - switch(vp->v_type) { - case V_LIST: - term = maxlistitems(vp->v_list); - break; - case V_OBJ: - term = objcall(OBJ_MAX, vp, - NULL_VALUE, NULL_VALUE); - break; - default: - copyvalue(vp, &term); - } - if (max.v_type == V_NULL) { - max = term; - continue; - } - if (term.v_type == V_NULL) - continue; - relvalue(&max, &term, &rel); - if (rel.v_type != V_NUM) { - freevalue(&max); - freevalue(&term); - freevalue(&rel); - return error_value(E_LISTMAX); - } - if (qisneg(rel.v_num)) { - freevalue(&max); - max = term; - } - else - freevalue(&term); - freevalue(&rel); - } - return max; + for (ep = lp->l_first; ep; ep = ep->e_next) { + vp = &ep->e_value; + switch(vp->v_type) { + case V_LIST: + term = maxlistitems(vp->v_list); + break; + case V_OBJ: + term = objcall(OBJ_MAX, vp, + NULL_VALUE, NULL_VALUE); + break; + default: + copyvalue(vp, &term); + } + if (max.v_type == V_NULL) { + max = term; + continue; + } + if (term.v_type == V_NULL) + continue; + relvalue(&max, &term, &rel); + if (rel.v_type != V_NUM) { + freevalue(&max); + freevalue(&term); + freevalue(&rel); + return error_value(E_LISTMAX); + } + if (qisneg(rel.v_num)) { + freevalue(&max); + max = term; + } + else + freevalue(&term); + freevalue(&rel); + } + return max; } S_FUNC VALUE f_min(int count, VALUE **vals) { - VALUE min; - VALUE term; - VALUE *vp; - VALUE rel; + VALUE min; + VALUE term; + VALUE *vp; + VALUE rel; - /* initialize VALUEs */ - min.v_type = V_NULL; - min.v_subtype = V_NOSUBTYPE; - term.v_type = V_NULL; - term.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + min.v_type = V_NULL; + min.v_subtype = V_NOSUBTYPE; + term.v_type = V_NULL; + term.v_subtype = V_NOSUBTYPE; - while (count-- > 0) { - vp = *vals++; - switch(vp->v_type) { - case V_LIST: - term = minlistitems(vp->v_list); - break; - case V_OBJ: - term = objcall(OBJ_MIN, vp, - NULL_VALUE, NULL_VALUE); - break; - default: - copyvalue(vp, &term); - } - if (min.v_type == V_NULL) { - min = term; - continue; - } - if (term.v_type == V_NULL) - continue; - if (term.v_type < 0) { - freevalue(&min); - return term; - } - relvalue(&term, &min, &rel); - if (rel.v_type != V_NUM) { - freevalue(&min); - freevalue(&term); - freevalue(&rel); - return error_value(E_MIN); - } - if (qisneg(rel.v_num)) { - freevalue(&min); - min = term; - } else { - freevalue(&term); - } - freevalue(&rel); - } - return min; + while (count-- > 0) { + vp = *vals++; + switch(vp->v_type) { + case V_LIST: + term = minlistitems(vp->v_list); + break; + case V_OBJ: + term = objcall(OBJ_MIN, vp, + NULL_VALUE, NULL_VALUE); + break; + default: + copyvalue(vp, &term); + } + if (min.v_type == V_NULL) { + min = term; + continue; + } + if (term.v_type == V_NULL) + continue; + if (term.v_type < 0) { + freevalue(&min); + return term; + } + relvalue(&term, &min, &rel); + if (rel.v_type != V_NUM) { + freevalue(&min); + freevalue(&term); + freevalue(&rel); + return error_value(E_MIN); + } + if (qisneg(rel.v_num)) { + freevalue(&min); + min = term; + } else { + freevalue(&term); + } + freevalue(&rel); + } + return min; } S_FUNC VALUE f_max(int count, VALUE **vals) { - VALUE max; - VALUE term; - VALUE *vp; - VALUE rel; + VALUE max; + VALUE term; + VALUE *vp; + VALUE rel; - /* initialize VALUEs */ - max.v_type = V_NULL; - max.v_subtype = V_NOSUBTYPE; - term.v_type = V_NULL; - term.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + max.v_type = V_NULL; + max.v_subtype = V_NOSUBTYPE; + term.v_type = V_NULL; + term.v_subtype = V_NOSUBTYPE; - while (count-- > 0) { - vp = *vals++; - switch(vp->v_type) { - case V_LIST: - term = maxlistitems(vp->v_list); - break; - case V_OBJ: - term = objcall(OBJ_MAX, vp, - NULL_VALUE, NULL_VALUE); - break; - default: - copyvalue(vp, &term); - } - if (max.v_type == V_NULL) { - max = term; - continue; - } - if (term.v_type == V_NULL) - continue; - if (term.v_type < 0) { - freevalue(&max); - return term; - } - relvalue(&max, &term, &rel); - if (rel.v_type != V_NUM) { - freevalue(&max); - freevalue(&term); - freevalue(&rel); - return error_value(E_MAX); - } - if (qisneg(rel.v_num)) { - freevalue(&max); - max = term; - } else { - freevalue(&term); - } - freevalue(&rel); - } - return max; + while (count-- > 0) { + vp = *vals++; + switch(vp->v_type) { + case V_LIST: + term = maxlistitems(vp->v_list); + break; + case V_OBJ: + term = objcall(OBJ_MAX, vp, + NULL_VALUE, NULL_VALUE); + break; + default: + copyvalue(vp, &term); + } + if (max.v_type == V_NULL) { + max = term; + continue; + } + if (term.v_type == V_NULL) + continue; + if (term.v_type < 0) { + freevalue(&max); + return term; + } + relvalue(&max, &term, &rel); + if (rel.v_type != V_NUM) { + freevalue(&max); + freevalue(&term); + freevalue(&rel); + return error_value(E_MAX); + } + if (qisneg(rel.v_num)) { + freevalue(&max); + max = term; + } else { + freevalue(&term); + } + freevalue(&rel); + } + return max; } S_FUNC NUMBER * f_gcd(int count, NUMBER **vals) { - NUMBER *val, *tmp; + NUMBER *val, *tmp; - val = qqabs(*vals); - while (--count > 0) { - tmp = qgcd(val, *++vals); - qfree(val); - val = tmp; - } - return val; + val = qqabs(*vals); + while (--count > 0) { + tmp = qgcd(val, *++vals); + qfree(val); + val = tmp; + } + return val; } S_FUNC NUMBER * f_lcm(int count, NUMBER **vals) { - NUMBER *val, *tmp; + NUMBER *val, *tmp; - val = qqabs(*vals); - while (--count > 0) { - tmp = qlcm(val, *++vals); - qfree(val); - val = tmp; - if (qiszero(val)) - break; - } - return val; + val = qqabs(*vals); + while (--count > 0) { + tmp = qlcm(val, *++vals); + qfree(val); + val = tmp; + if (qiszero(val)) + break; + } + return val; } S_FUNC VALUE f_hash(int count, VALUE **vals) { - QCKHASH hash; - VALUE result; + QCKHASH hash; + VALUE result; - /* initialize VALUE */ - result.v_type = V_NUM; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NUM; + result.v_subtype = V_NOSUBTYPE; - hash = QUICKHASH_BASIS; - while (count-- > 0) - hash = hashvalue(*vals++, hash); - result.v_num = utoq((FULL) hash); - return result; + hash = QUICKHASH_BASIS; + while (count-- > 0) + hash = hashvalue(*vals++, hash); + result.v_num = utoq((FULL) hash); + return result; } VALUE sumlistitems(LIST *lp) { - LISTELEM *ep; - VALUE *vp; - VALUE term; - VALUE tmp; - VALUE sum; + LISTELEM *ep; + VALUE *vp; + VALUE term; + VALUE tmp; + VALUE sum; - /* initialize VALUEs */ - term.v_type = V_NULL; - term.v_subtype = V_NOSUBTYPE; - tmp.v_type = V_NULL; - tmp.v_subtype = V_NOSUBTYPE; - sum.v_type = V_NULL; - sum.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + term.v_type = V_NULL; + term.v_subtype = V_NOSUBTYPE; + tmp.v_type = V_NULL; + tmp.v_subtype = V_NOSUBTYPE; + sum.v_type = V_NULL; + sum.v_subtype = V_NOSUBTYPE; - for (ep = lp->l_first; ep; ep = ep->e_next) { - vp = &ep->e_value; - switch(vp->v_type) { - case V_LIST: - term = sumlistitems(vp->v_list); - break; - case V_OBJ: - term = objcall(OBJ_SUM, vp, - NULL_VALUE, NULL_VALUE); - break; - default: - addvalue(&sum, vp, &tmp); - freevalue(&sum); - if (tmp.v_type < 0) - return tmp; - sum = tmp; - continue; - } - addvalue(&sum, &term, &tmp); - freevalue(&sum); - freevalue(&term); - sum = tmp; - if (sum.v_type < 0) - break; - } - return sum; + for (ep = lp->l_first; ep; ep = ep->e_next) { + vp = &ep->e_value; + switch(vp->v_type) { + case V_LIST: + term = sumlistitems(vp->v_list); + break; + case V_OBJ: + term = objcall(OBJ_SUM, vp, + NULL_VALUE, NULL_VALUE); + break; + default: + addvalue(&sum, vp, &tmp); + freevalue(&sum); + if (tmp.v_type < 0) + return tmp; + sum = tmp; + continue; + } + addvalue(&sum, &term, &tmp); + freevalue(&sum); + freevalue(&term); + sum = tmp; + if (sum.v_type < 0) + break; + } + return sum; } S_FUNC VALUE f_sum(int count, VALUE **vals) { - VALUE tmp; - VALUE sum; - VALUE term; - VALUE *vp; + VALUE tmp; + VALUE sum; + VALUE term; + VALUE *vp; - /* initialize VALUEs */ - tmp.v_type = V_NULL; - tmp.v_subtype = V_NOSUBTYPE; - sum.v_type = V_NULL; - sum.v_subtype = V_NOSUBTYPE; - term.v_type = V_NULL; - term.v_subtype = V_NOSUBTYPE; - while (count-- > 0) { - vp = *vals++; - switch(vp->v_type) { - case V_LIST: - term = sumlistitems(vp->v_list); - break; - case V_OBJ: - term = objcall(OBJ_SUM, vp, - NULL_VALUE, NULL_VALUE); - break; - default: - addvalue(&sum, vp, &tmp); - freevalue(&sum); - if (tmp.v_type < 0) - return tmp; - sum = tmp; - continue; - } - addvalue(&sum, &term, &tmp); - freevalue(&term); - freevalue(&sum); - sum = tmp; - if (sum.v_type < 0) - break; - } - return sum; + /* initialize VALUEs */ + tmp.v_type = V_NULL; + tmp.v_subtype = V_NOSUBTYPE; + sum.v_type = V_NULL; + sum.v_subtype = V_NOSUBTYPE; + term.v_type = V_NULL; + term.v_subtype = V_NOSUBTYPE; + while (count-- > 0) { + vp = *vals++; + switch(vp->v_type) { + case V_LIST: + term = sumlistitems(vp->v_list); + break; + case V_OBJ: + term = objcall(OBJ_SUM, vp, + NULL_VALUE, NULL_VALUE); + break; + default: + addvalue(&sum, vp, &tmp); + freevalue(&sum); + if (tmp.v_type < 0) + return tmp; + sum = tmp; + continue; + } + addvalue(&sum, &term, &tmp); + freevalue(&term); + freevalue(&sum); + sum = tmp; + if (sum.v_type < 0) + break; + } + return sum; } S_FUNC VALUE f_avg(int count, VALUE **vals) { - VALUE tmp; - VALUE sum; - VALUE div; - long n; + VALUE tmp; + VALUE sum; + VALUE div; + long n; - /* initialize VALUEs */ - tmp.v_type = V_NULL; - tmp.v_subtype = V_NOSUBTYPE; - sum.v_type = V_NULL; - sum.v_subtype = V_NOSUBTYPE; - div.v_type = V_NULL; - div.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + tmp.v_type = V_NULL; + tmp.v_subtype = V_NOSUBTYPE; + sum.v_type = V_NULL; + sum.v_subtype = V_NOSUBTYPE; + div.v_type = V_NULL; + div.v_subtype = V_NOSUBTYPE; - n = 0; - while (count-- > 0) { - if ((*vals)->v_type == V_LIST) { - addlistitems((*vals)->v_list, &sum); - n += countlistitems((*vals++)->v_list); - } else { - addvalue(&sum, *vals++, &tmp); - freevalue(&sum); - sum = tmp; - n++; - } - if (sum.v_type < 0) - return sum; - } - if (n < 2) - return sum; - div.v_num = itoq(n); - div.v_type = V_NUM; - div.v_subtype = V_NOSUBTYPE; - divvalue(&sum, &div, &tmp); - freevalue(&sum); - qfree(div.v_num); - return tmp; + n = 0; + while (count-- > 0) { + if ((*vals)->v_type == V_LIST) { + addlistitems((*vals)->v_list, &sum); + n += countlistitems((*vals++)->v_list); + } else { + addvalue(&sum, *vals++, &tmp); + freevalue(&sum); + sum = tmp; + n++; + } + if (sum.v_type < 0) + return sum; + } + if (n < 2) + return sum; + div.v_num = itoq(n); + div.v_type = V_NUM; + div.v_subtype = V_NOSUBTYPE; + divvalue(&sum, &div, &tmp); + freevalue(&sum); + qfree(div.v_num); + return tmp; } S_FUNC VALUE f_fact(VALUE *vp) { - VALUE res; + VALUE res; - /* initialize VALUE */ - res.v_type = V_NUM; - res.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + res.v_type = V_NUM; + res.v_subtype = V_NOSUBTYPE; - if (vp->v_type == V_OBJ) { - return objcall(OBJ_FACT, vp, NULL_VALUE, NULL_VALUE); - } - if (vp->v_type != V_NUM) { - math_error("Non-real argument for fact()"); - not_reached(); - } - res.v_num = qfact(vp->v_num); - return res; + if (vp->v_type == V_OBJ) { + return objcall(OBJ_FACT, vp, NULL_VALUE, NULL_VALUE); + } + if (vp->v_type != V_NUM) { + math_error("Non-real argument for fact()"); + not_reached(); + } + res.v_num = qfact(vp->v_num); + return res; } S_FUNC VALUE f_hmean(int count, VALUE **vals) { - VALUE sum, tmp1, tmp2; - long n = 0; + VALUE sum, tmp1, tmp2; + long n = 0; - /* initialize VALUEs */ - sum.v_type = V_NULL; - sum.v_subtype = V_NOSUBTYPE; - tmp1.v_type = V_NULL; - tmp1.v_subtype = V_NOSUBTYPE; - tmp2.v_type = V_NULL; - tmp2.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + sum.v_type = V_NULL; + sum.v_subtype = V_NOSUBTYPE; + tmp1.v_type = V_NULL; + tmp1.v_subtype = V_NOSUBTYPE; + tmp2.v_type = V_NULL; + tmp2.v_subtype = V_NOSUBTYPE; - while (count-- > 0) { - if ((*vals)->v_type == V_LIST) { - addlistinv((*vals)->v_list, &sum); - n += countlistitems((*vals++)->v_list); - } else { - invertvalue(*vals++, &tmp1); - addvalue(&sum, &tmp1, &tmp2); - freevalue(&tmp1); - freevalue(&sum); - sum = tmp2; - n++; - } - } - if (n == 0) - return sum; - tmp1.v_type = V_NUM; - tmp1.v_subtype = V_NOSUBTYPE; - tmp1.v_num = itoq(n); - divvalue(&tmp1, &sum, &tmp2); - qfree(tmp1.v_num); - freevalue(&sum); - return tmp2; + while (count-- > 0) { + if ((*vals)->v_type == V_LIST) { + addlistinv((*vals)->v_list, &sum); + n += countlistitems((*vals++)->v_list); + } else { + invertvalue(*vals++, &tmp1); + addvalue(&sum, &tmp1, &tmp2); + freevalue(&tmp1); + freevalue(&sum); + sum = tmp2; + n++; + } + } + if (n == 0) + return sum; + tmp1.v_type = V_NUM; + tmp1.v_subtype = V_NOSUBTYPE; + tmp1.v_num = itoq(n); + divvalue(&tmp1, &sum, &tmp2); + qfree(tmp1.v_num); + freevalue(&sum); + return tmp2; } S_FUNC NUMBER * f_hnrmod(NUMBER *val1, NUMBER *val2, NUMBER *val3, NUMBER *val4) { - ZVALUE answer; /* v mod h*2^n+r */ - NUMBER *res; /* v mod h*2^n+r */ + ZVALUE answer; /* v mod h*2^n+r */ + NUMBER *res; /* v mod h*2^n+r */ - /* - * firewall - */ - if (qisfrac(val1)) { - math_error("1st arg of hnrmod (v) must be an integer"); - not_reached(); - } - if (qisfrac(val2) || qisneg(val2) || qiszero(val2)) { - math_error("2nd arg of hnrmod (h) must be an integer > 0"); - not_reached(); - } - if (qisfrac(val3) || qisneg(val3) || qiszero(val3)) { - math_error("3rd arg of hnrmod (n) must be an integer > 0"); - not_reached(); - } - if (qisfrac(val4) || !zisabsleone(val4->num)) { - math_error("4th arg of hnrmod (r) must be -1, 0 or 1"); - not_reached(); - } + /* + * firewall + */ + if (qisfrac(val1)) { + math_error("1st arg of hnrmod (v) must be an integer"); + not_reached(); + } + if (qisfrac(val2) || qisneg(val2) || qiszero(val2)) { + math_error("2nd arg of hnrmod (h) must be an integer > 0"); + not_reached(); + } + if (qisfrac(val3) || qisneg(val3) || qiszero(val3)) { + math_error("3rd arg of hnrmod (n) must be an integer > 0"); + not_reached(); + } + if (qisfrac(val4) || !zisabsleone(val4->num)) { + math_error("4th arg of hnrmod (r) must be -1, 0 or 1"); + not_reached(); + } - /* - * perform the val1 mod (val2 * 2^val3 + val4) operation - */ - zhnrmod(val1->num, val2->num, val3->num, val4->num, &answer); + /* + * perform the val1 mod (val2 * 2^val3 + val4) operation + */ + zhnrmod(val1->num, val2->num, val3->num, val4->num, &answer); - /* - * return the answer - */ - res = qalloc(); - res->num = answer; - return res; + /* + * return the answer + */ + res = qalloc(); + res->num = answer; + return res; } VALUE ssqlistitems(LIST *lp) { - LISTELEM *ep; - VALUE *vp; - VALUE term; - VALUE tmp; - VALUE sum; + LISTELEM *ep; + VALUE *vp; + VALUE term; + VALUE tmp; + VALUE sum; - /* initialize VALUEs */ - term.v_type = V_NULL; - term.v_subtype = V_NOSUBTYPE; - tmp.v_type = V_NULL; - tmp.v_subtype = V_NOSUBTYPE; - sum.v_type = V_NULL; - sum.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + term.v_type = V_NULL; + term.v_subtype = V_NOSUBTYPE; + tmp.v_type = V_NULL; + tmp.v_subtype = V_NOSUBTYPE; + sum.v_type = V_NULL; + sum.v_subtype = V_NOSUBTYPE; - for (ep = lp->l_first; ep; ep = ep->e_next) { - vp = &ep->e_value; - if (vp->v_type == V_LIST) { - term = ssqlistitems(vp->v_list); - } else { - squarevalue(vp, &term); - } - addvalue(&sum, &term, &tmp); - freevalue(&sum); - freevalue(&term); - sum = tmp; - if (sum.v_type < 0) - break; - } - return sum; + for (ep = lp->l_first; ep; ep = ep->e_next) { + vp = &ep->e_value; + if (vp->v_type == V_LIST) { + term = ssqlistitems(vp->v_list); + } else { + squarevalue(vp, &term); + } + addvalue(&sum, &term, &tmp); + freevalue(&sum); + freevalue(&term); + sum = tmp; + if (sum.v_type < 0) + break; + } + return sum; } S_FUNC VALUE f_ssq(int count, VALUE **vals) { - VALUE tmp; - VALUE sum; - VALUE term; - VALUE *vp; + VALUE tmp; + VALUE sum; + VALUE term; + VALUE *vp; - /* initialize VALUEs */ - tmp.v_type = V_NULL; - tmp.v_subtype = V_NOSUBTYPE; - sum.v_type = V_NULL; - sum.v_subtype = V_NOSUBTYPE; - term.v_type = V_NULL; - term.v_subtype = V_NOSUBTYPE; - while (count-- > 0) { - vp = *vals++; - if (vp->v_type == V_LIST) { - term = ssqlistitems(vp->v_list); - } else { - squarevalue(vp, &term); - } - addvalue(&sum, &term, &tmp); - freevalue(&term); - freevalue(&sum); - sum = tmp; - if (sum.v_type < 0) - break; - } - return sum; + /* initialize VALUEs */ + tmp.v_type = V_NULL; + tmp.v_subtype = V_NOSUBTYPE; + sum.v_type = V_NULL; + sum.v_subtype = V_NOSUBTYPE; + term.v_type = V_NULL; + term.v_subtype = V_NOSUBTYPE; + while (count-- > 0) { + vp = *vals++; + if (vp->v_type == V_LIST) { + term = ssqlistitems(vp->v_list); + } else { + squarevalue(vp, &term); + } + addvalue(&sum, &term, &tmp); + freevalue(&term); + freevalue(&sum); + sum = tmp; + if (sum.v_type < 0) + break; + } + return sum; } S_FUNC NUMBER * f_ismult(NUMBER *val1, NUMBER *val2) { - return itoq((long) qdivides(val1, val2)); + return itoq((long) qdivides(val1, val2)); } S_FUNC NUMBER * f_meq(NUMBER *val1, NUMBER *val2, NUMBER *val3) { - NUMBER *tmp, *res; + NUMBER *tmp, *res; - tmp = qsub(val1, val2); - res = itoq((long) qdivides(tmp, val3)); - qfree(tmp); - return res; + tmp = qsub(val1, val2); + res = itoq((long) qdivides(tmp, val3)); + qfree(tmp); + return res; } S_FUNC VALUE f_exp(int count, VALUE **vals) { - VALUE result; - NUMBER *eps; - NUMBER *q; - COMPLEX *c; + VALUE result; + NUMBER *eps; + NUMBER *q; + COMPLEX *c; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_EXP_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_EXP_1); + } + eps = vals[1]->v_num; + } - /* - * compute e^x to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - q = qexp(vals[0]->v_num, eps); - if (q == NULL) - return error_value(E_EXP_3); - result.v_num = q; - result.v_type = V_NUM; - break; - case V_COM: - c = c_exp(vals[0]->v_com, eps); - if (c == NULL) - return error_value(E_EXP_3); - result.v_com = c; - result.v_type = V_COM; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_EXP_2); - } - return result; + /* + * compute e^x to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + q = qexp(vals[0]->v_num, eps); + if (q == NULL) + return error_value(E_EXP_3); + result.v_num = q; + result.v_type = V_NUM; + break; + case V_COM: + c = c_exp(vals[0]->v_com, eps); + if (c == NULL) + return error_value(E_EXP_3); + result.v_com = c; + result.v_type = V_COM; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_EXP_2); + } + return result; } S_FUNC VALUE f_ln(int count, VALUE **vals) { - VALUE result; - COMPLEX ctmp, *c; - NUMBER *err; + VALUE result; + COMPLEX ctmp, *c; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_LN_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_LN_1); + } + err = vals[1]->v_num; + } - /* - * compute natural logarithm to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) { - return error_value(E_LN_3); - } - if (!qisneg(vals[0]->v_num)) { - result.v_num = qln(vals[0]->v_num, err); - result.v_type = V_NUM; - return result; - } - ctmp.real = vals[0]->v_num; - ctmp.imag = qlink(&_qzero_); - ctmp.links = 1; - c = c_ln(&ctmp, err); - break; - case V_COM: - if (ciszero(vals[0]->v_com)) { - return error_value(E_LN_3); - } - c = c_ln(vals[0]->v_com, err); - break; - default: - return error_value(E_LN_2); - } + /* + * compute natural logarithm to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) { + return error_value(E_LN_3); + } + if (!qisneg(vals[0]->v_num)) { + result.v_num = qln(vals[0]->v_num, err); + result.v_type = V_NUM; + return result; + } + ctmp.real = vals[0]->v_num; + ctmp.imag = qlink(&_qzero_); + ctmp.links = 1; + c = c_ln(&ctmp, err); + break; + case V_COM: + if (ciszero(vals[0]->v_com)) { + return error_value(E_LN_3); + } + c = c_ln(vals[0]->v_com, err); + break; + default: + return error_value(E_LN_2); + } - /* determine if we will return a numeric or complex value */ - result.v_type = V_COM; - result.v_com = c; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - return result; + /* determine if we will return a numeric or complex value */ + result.v_type = V_COM; + result.v_com = c; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + return result; } S_FUNC VALUE f_log(int count, VALUE **vals) { - VALUE result; - COMPLEX ctmp, *c; - NUMBER *err; + VALUE result; + COMPLEX ctmp, *c; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_LOG_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_LOG_1); + } + err = vals[1]->v_num; + } - /* - * compute logarithm base 10 to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) { - return error_value(E_LOG_5); - } - if (!qisneg(vals[0]->v_num)) { - result.v_num = qlog(vals[0]->v_num, err); - result.v_type = V_NUM; - return result; - } - ctmp.real = vals[0]->v_num; - ctmp.imag = qlink(&_qzero_); - ctmp.links = 1; - c = c_log(&ctmp, err); - break; - case V_COM: - if (ciszero(vals[0]->v_com)) { - return error_value(E_LOG_5); - } - c = c_log(vals[0]->v_com, err); - break; - default: - return error_value(E_LOG_2); - } - if (c == NULL) { - return error_value(E_LOG_3); - } + /* + * compute logarithm base 10 to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) { + return error_value(E_LOG_5); + } + if (!qisneg(vals[0]->v_num)) { + result.v_num = qlog(vals[0]->v_num, err); + result.v_type = V_NUM; + return result; + } + ctmp.real = vals[0]->v_num; + ctmp.imag = qlink(&_qzero_); + ctmp.links = 1; + c = c_log(&ctmp, err); + break; + case V_COM: + if (ciszero(vals[0]->v_com)) { + return error_value(E_LOG_5); + } + c = c_log(vals[0]->v_com, err); + break; + default: + return error_value(E_LOG_2); + } + if (c == NULL) { + return error_value(E_LOG_3); + } - /* determine if we will return a numeric or complex value */ - result.v_type = V_COM; - result.v_com = c; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - return result; + /* determine if we will return a numeric or complex value */ + result.v_type = V_COM; + result.v_com = c; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + return result; } S_FUNC VALUE f_log2(int count, VALUE **vals) { - VALUE result; - COMPLEX ctmp, *c; - NUMBER *err; + VALUE result; + COMPLEX ctmp, *c; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_LOG2_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_LOG2_1); + } + err = vals[1]->v_num; + } - /* - * compute base 2 logarithm to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) { - return error_value(E_LOG2_4); - } - if (!qisneg(vals[0]->v_num) && - !qiszero(vals[0]->v_num)) { - result.v_num = qlog2(vals[0]->v_num, err); - result.v_type = V_NUM; - return result; - } - ctmp.real = vals[0]->v_num; - ctmp.imag = qlink(&_qzero_); - ctmp.links = 1; - c = c_log2(&ctmp, err); - break; - case V_COM: - if (ciszero(vals[0]->v_com)) { - return error_value(E_LOG2_4); - } - c = c_log2(vals[0]->v_com, err); - break; - default: - return error_value(E_LOG2_2); - } - if (c == NULL) { - return error_value(E_LOG2_3); - } + /* + * compute base 2 logarithm to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) { + return error_value(E_LOG2_4); + } + if (!qisneg(vals[0]->v_num) && + !qiszero(vals[0]->v_num)) { + result.v_num = qlog2(vals[0]->v_num, err); + result.v_type = V_NUM; + return result; + } + ctmp.real = vals[0]->v_num; + ctmp.imag = qlink(&_qzero_); + ctmp.links = 1; + c = c_log2(&ctmp, err); + break; + case V_COM: + if (ciszero(vals[0]->v_com)) { + return error_value(E_LOG2_4); + } + c = c_log2(vals[0]->v_com, err); + break; + default: + return error_value(E_LOG2_2); + } + if (c == NULL) { + return error_value(E_LOG2_3); + } - /* determine if we will return a numeric or complex value */ - result.v_type = V_COM; - result.v_com = c; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - return result; + /* determine if we will return a numeric or complex value */ + result.v_type = V_COM; + result.v_com = c; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + return result; } S_FUNC VALUE f_logn(int count, VALUE **vals) { - VALUE result; /* return value */ - COMPLEX ctmp; /* intermediate COMPLEX temporary value */ - COMPLEX *p_cval; /* pointer to a COMPLEX value */ - NUMBER *err; /* epsilon error value */ - bool ln_of_x_is_complex = false; /* taking to value of a COMPLEX x */ - COMPLEX *ln_x_c; /* ln(x) where ln_of_x_is_complex is true */ - NUMBER *ln_x_r; /* ln(x) where ln_of_x_is_complex is false */ - bool ln_of_n_is_complex = false; /* taking to value of a COMPLEX base n */ - COMPLEX *ln_n_c; /* ln(n) where ln_of_n_is_complex is true */ - NUMBER *ln_n_r; /* ln(n) where ln_of_n_is_complex is false */ + VALUE result; /* return value */ + COMPLEX ctmp; /* intermediate COMPLEX temporary value */ + COMPLEX *p_cval; /* pointer to a COMPLEX value */ + NUMBER *err; /* epsilon error value */ + bool ln_of_x_is_complex = false; /* taking to value of a COMPLEX x */ + COMPLEX *ln_x_c; /* ln(x) where ln_of_x_is_complex is true */ + NUMBER *ln_x_r; /* ln(x) where ln_of_x_is_complex is false */ + bool ln_of_n_is_complex = false; /* taking to value of a COMPLEX base n */ + COMPLEX *ln_n_c; /* ln(n) where ln_of_n_is_complex is true */ + NUMBER *ln_n_r; /* ln(n) where ln_of_n_is_complex is false */ - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 3) { - if (verify_eps(vals[2]) == false) { - return error_value(E_LOGN_1); - } - err = vals[2]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 3) { + if (verify_eps(vals[2]) == false) { + return error_value(E_LOGN_1); + } + err = vals[2]->v_num; + } - /* - * special case: x and n are both integer powers of 2 and n log 2 != 0 - * - * If this is the case, we return the integer formed by log2(n) / log2(x). - */ - ln_x_r = qalloc(); - ln_n_r = qalloc(); - if (vals[0]->v_type == V_NUM && qispowerof2(vals[0]->v_num, &ln_x_r) == true) { - if (vals[1]->v_type == V_NUM && qispowerof2(vals[1]->v_num, &ln_n_r) == true) { - if (!qiszero(ln_n_r)) { - result.v_num = qqdiv(ln_x_r, ln_n_r); - if (result.v_num == NULL) { - return error_value(E_LOGN_4); - } - result.v_type = V_NUM; - qfree(ln_x_r); - qfree(ln_n_r); - return result; - } else { - qfree(ln_x_r); - qfree(ln_n_r); - return error_value(E_LOGN_4); - } - } - } - qfree(ln_x_r); - qfree(ln_n_r); + /* + * special case: x and n are both integer powers of 2 and n log 2 != 0 + * + * If this is the case, we return the integer formed by log2(n) / log2(x). + */ + ln_x_r = qalloc(); + ln_n_r = qalloc(); + if (vals[0]->v_type == V_NUM && qispowerof2(vals[0]->v_num, &ln_x_r) == true) { + if (vals[1]->v_type == V_NUM && qispowerof2(vals[1]->v_num, &ln_n_r) == true) { + if (!qiszero(ln_n_r)) { + result.v_num = qqdiv(ln_x_r, ln_n_r); + if (result.v_num == NULL) { + return error_value(E_LOGN_4); + } + result.v_type = V_NUM; + qfree(ln_x_r); + qfree(ln_n_r); + return result; + } else { + qfree(ln_x_r); + qfree(ln_n_r); + return error_value(E_LOGN_4); + } + } + } + qfree(ln_x_r); + qfree(ln_n_r); - /* - * take the natural log of x (value) - * - * Look for the case where the natural log of x complex is a real. - */ - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) { - return error_value(E_LOGN_6); - } - if (qisneg(vals[0]->v_num)) { - ctmp.real = vals[0]->v_num; - ctmp.imag = qlink(&_qzero_); - ctmp.links = 1; - ln_x_c = c_ln(&ctmp, err); - if (ln_x_c == NULL) { - return error_value(E_LOGN_3); - } - if (cisreal(ln_x_c)) { - ln_x_r = c_to_q(ln_x_c, true); - } else { - ln_of_x_is_complex = true; - } - } else { - ln_x_c = NULL; /* avoid ln_x_c may be uninitialized warning later on */ - ln_x_r = qln(vals[0]->v_num, err); - if (ln_x_r == NULL) { - return error_value(E_LOGN_3); - } - } - break; - case V_COM: - if (ciszero(vals[0]->v_com)) { - return error_value(E_LOGN_6); - } - ln_x_c = c_ln(vals[0]->v_com, err); - if (ln_x_c == NULL) { - return error_value(E_LOGN_3); - } - if (cisreal(ln_x_c)) { - ln_x_r = c_to_q(ln_x_c, true); - } else { - ln_of_x_is_complex = true; - } - break; - default: - return error_value(E_LOGN_2); - } + /* + * take the natural log of x (value) + * + * Look for the case where the natural log of x complex is a real. + */ + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) { + return error_value(E_LOGN_6); + } + if (qisneg(vals[0]->v_num)) { + ctmp.real = vals[0]->v_num; + ctmp.imag = qlink(&_qzero_); + ctmp.links = 1; + ln_x_c = c_ln(&ctmp, err); + if (ln_x_c == NULL) { + return error_value(E_LOGN_3); + } + if (cisreal(ln_x_c)) { + ln_x_r = c_to_q(ln_x_c, true); + } else { + ln_of_x_is_complex = true; + } + } else { + ln_x_c = NULL; /* avoid ln_x_c may be uninitialized warning later on */ + ln_x_r = qln(vals[0]->v_num, err); + if (ln_x_r == NULL) { + return error_value(E_LOGN_3); + } + } + break; + case V_COM: + if (ciszero(vals[0]->v_com)) { + return error_value(E_LOGN_6); + } + ln_x_c = c_ln(vals[0]->v_com, err); + if (ln_x_c == NULL) { + return error_value(E_LOGN_3); + } + if (cisreal(ln_x_c)) { + ln_x_r = c_to_q(ln_x_c, true); + } else { + ln_of_x_is_complex = true; + } + break; + default: + return error_value(E_LOGN_2); + } - /* - * take the natural log of n (base) - * - * Look for the case where the natural log of n complex is a real. - * Also report an error if the case where the natural log of n is zero. - */ - switch (vals[1]->v_type) { - case V_NUM: - if (qiszero(vals[1]->v_num)) { - if (ln_of_x_is_complex == true) { - comfree(ln_x_c); - } else { - qfree(ln_x_r); - } - return error_value(E_LOGN_4); - } - if (qisneg(vals[1]->v_num)) { - ctmp.real = vals[1]->v_num; - ctmp.imag = qlink(&_qzero_); - ctmp.links = 1; - ln_n_c = c_ln(&ctmp, err); - if (ln_n_c == NULL) { - if (ln_of_x_is_complex == true) { - comfree(ln_x_c); - } else { - qfree(ln_x_r); - } - return error_value(E_LOGN_4); - } - if (ciszero(ln_n_c)) { - comfree(ln_n_c); - if (ln_of_x_is_complex == true) { - comfree(ln_x_c); - } else { - qfree(ln_x_r); - } - return error_value(E_LOGN_4); - } - if (cisreal(ln_n_c)) { - ln_n_r = c_to_q(ln_n_c, true); - } else { - ln_of_n_is_complex = true; - } - } else { - ln_n_r = qln(vals[1]->v_num, err); - if (ln_n_r == NULL) { - if (ln_of_x_is_complex == true) { - comfree(ln_x_c); - } else { - qfree(ln_x_r); - } - return error_value(E_LOGN_4); - } - if (qiszero(ln_n_r)) { - qfree(ln_n_r); - if (ln_of_x_is_complex == true) { - comfree(ln_x_c); - } else { - qfree(ln_x_r); - } - return error_value(E_LOGN_4); - } - } - break; - case V_COM: - if (ciszero(vals[1]->v_com)) { - if (ln_of_x_is_complex == true) { - comfree(ln_x_c); - } else { - qfree(ln_x_r); - } - return error_value(E_LOGN_4); - } - ln_n_c = c_ln(vals[1]->v_com, err); - if (ln_n_c == NULL) { - if (ln_of_x_is_complex == true) { - comfree(ln_x_c); - } else { - qfree(ln_x_r); - } - return error_value(E_LOGN_4); - } - if (ciszero(ln_n_c)) { - comfree(ln_n_c); - if (ln_of_x_is_complex == true) { - comfree(ln_x_c); - } else { - qfree(ln_x_r); - } - return error_value(E_LOGN_4); - } - if (cisreal(ln_n_c)) { - ln_n_r = c_to_q(ln_n_c, true); - } else { - ln_of_n_is_complex = true; - } - break; - default: - if (ln_of_x_is_complex == true) { - comfree(ln_x_c); - } else { - qfree(ln_x_r); - } - return error_value(E_LOGN_5); - } + /* + * take the natural log of n (base) + * + * Look for the case where the natural log of n complex is a real. + * Also report an error if the case where the natural log of n is zero. + */ + switch (vals[1]->v_type) { + case V_NUM: + if (qiszero(vals[1]->v_num)) { + if (ln_of_x_is_complex == true) { + comfree(ln_x_c); + } else { + qfree(ln_x_r); + } + return error_value(E_LOGN_4); + } + if (qisneg(vals[1]->v_num)) { + ctmp.real = vals[1]->v_num; + ctmp.imag = qlink(&_qzero_); + ctmp.links = 1; + ln_n_c = c_ln(&ctmp, err); + if (ln_n_c == NULL) { + if (ln_of_x_is_complex == true) { + comfree(ln_x_c); + } else { + qfree(ln_x_r); + } + return error_value(E_LOGN_4); + } + if (ciszero(ln_n_c)) { + comfree(ln_n_c); + if (ln_of_x_is_complex == true) { + comfree(ln_x_c); + } else { + qfree(ln_x_r); + } + return error_value(E_LOGN_4); + } + if (cisreal(ln_n_c)) { + ln_n_r = c_to_q(ln_n_c, true); + } else { + ln_of_n_is_complex = true; + } + } else { + ln_n_r = qln(vals[1]->v_num, err); + if (ln_n_r == NULL) { + if (ln_of_x_is_complex == true) { + comfree(ln_x_c); + } else { + qfree(ln_x_r); + } + return error_value(E_LOGN_4); + } + if (qiszero(ln_n_r)) { + qfree(ln_n_r); + if (ln_of_x_is_complex == true) { + comfree(ln_x_c); + } else { + qfree(ln_x_r); + } + return error_value(E_LOGN_4); + } + } + break; + case V_COM: + if (ciszero(vals[1]->v_com)) { + if (ln_of_x_is_complex == true) { + comfree(ln_x_c); + } else { + qfree(ln_x_r); + } + return error_value(E_LOGN_4); + } + ln_n_c = c_ln(vals[1]->v_com, err); + if (ln_n_c == NULL) { + if (ln_of_x_is_complex == true) { + comfree(ln_x_c); + } else { + qfree(ln_x_r); + } + return error_value(E_LOGN_4); + } + if (ciszero(ln_n_c)) { + comfree(ln_n_c); + if (ln_of_x_is_complex == true) { + comfree(ln_x_c); + } else { + qfree(ln_x_r); + } + return error_value(E_LOGN_4); + } + if (cisreal(ln_n_c)) { + ln_n_r = c_to_q(ln_n_c, true); + } else { + ln_of_n_is_complex = true; + } + break; + default: + if (ln_of_x_is_complex == true) { + comfree(ln_x_c); + } else { + qfree(ln_x_r); + } + return error_value(E_LOGN_5); + } - /* - * compute ln(x) / ln(n) - */ - if (ln_of_x_is_complex == true) { - if (ln_of_n_is_complex == true) { + /* + * compute ln(x) / ln(n) + */ + if (ln_of_x_is_complex == true) { + if (ln_of_n_is_complex == true) { - /* - * case: ln(x) is COMPLEX, ln(n) is COMPLEX - */ - p_cval = c_div(ln_x_c, ln_n_c); - comfree(ln_x_c); - comfree(ln_n_c); - if (p_cval == NULL) { - return error_value(E_LOGN_3); - } - /* check for COMPLEX or NUMBER division */ - if (cisreal(p_cval)) { - /* ln(x) / ln(n) was NUMBER, not COMPLEX */ - result.v_num = c_to_q(p_cval, true); - result.v_type = V_NUM; - } else { - /* ln(x) / ln(n) is COMPLEX */ - result.v_type = V_COM; - result.v_com = p_cval; - } + /* + * case: ln(x) is COMPLEX, ln(n) is COMPLEX + */ + p_cval = c_div(ln_x_c, ln_n_c); + comfree(ln_x_c); + comfree(ln_n_c); + if (p_cval == NULL) { + return error_value(E_LOGN_3); + } + /* check for COMPLEX or NUMBER division */ + if (cisreal(p_cval)) { + /* ln(x) / ln(n) was NUMBER, not COMPLEX */ + result.v_num = c_to_q(p_cval, true); + result.v_type = V_NUM; + } else { + /* ln(x) / ln(n) is COMPLEX */ + result.v_type = V_COM; + result.v_com = p_cval; + } - } else { + } else { - /* - * case: ln(x) is COMPLEX, ln(n) is NUMBER - */ - p_cval = c_divq(ln_x_c, ln_n_r); - comfree(ln_x_c); - qfree(ln_n_r); - if (p_cval == NULL) { - return error_value(E_LOGN_3); - } - /* check for COMPLEX or NUMBER division */ - if (cisreal(p_cval)) { - /* ln(x) / ln(n) was NUMBER, not COMPLEX */ - result.v_num = c_to_q(p_cval, true); - result.v_type = V_NUM; - } else { - /* ln(x) / ln(n) is COMPLEX */ - result.v_type = V_COM; - result.v_com = p_cval; - } - } + /* + * case: ln(x) is COMPLEX, ln(n) is NUMBER + */ + p_cval = c_divq(ln_x_c, ln_n_r); + comfree(ln_x_c); + qfree(ln_n_r); + if (p_cval == NULL) { + return error_value(E_LOGN_3); + } + /* check for COMPLEX or NUMBER division */ + if (cisreal(p_cval)) { + /* ln(x) / ln(n) was NUMBER, not COMPLEX */ + result.v_num = c_to_q(p_cval, true); + result.v_type = V_NUM; + } else { + /* ln(x) / ln(n) is COMPLEX */ + result.v_type = V_COM; + result.v_com = p_cval; + } + } - } else { - if (ln_of_n_is_complex == true) { + } else { + if (ln_of_n_is_complex == true) { - /* - * case: ln(x) is NUMBER, ln(n) is COMPLEX - */ - /* convert ln_x_r into COMPLEX so we can divide */ - ctmp.real = ln_x_r; - ctmp.imag = qlink(&_qzero_); - ctmp.links = 1; - p_cval = c_div(&ctmp, ln_n_c); - comfree(&ctmp); - comfree(ln_n_c); - if (p_cval == NULL) { - return error_value(E_LOGN_3); - } - /* check for COMPLEX or NUMBER division */ - if (cisreal(p_cval)) { - /* ln(x) / ln(n) was NUMBER, not COMPLEX */ - result.v_num = c_to_q(p_cval, true); - result.v_type = V_NUM; - } else { - /* ln(x) / ln(n) is COMPLEX result */ - result.v_type = V_COM; - result.v_com = p_cval; - } + /* + * case: ln(x) is NUMBER, ln(n) is COMPLEX + */ + /* convert ln_x_r into COMPLEX so we can divide */ + ctmp.real = ln_x_r; + ctmp.imag = qlink(&_qzero_); + ctmp.links = 1; + p_cval = c_div(&ctmp, ln_n_c); + comfree(&ctmp); + comfree(ln_n_c); + if (p_cval == NULL) { + return error_value(E_LOGN_3); + } + /* check for COMPLEX or NUMBER division */ + if (cisreal(p_cval)) { + /* ln(x) / ln(n) was NUMBER, not COMPLEX */ + result.v_num = c_to_q(p_cval, true); + result.v_type = V_NUM; + } else { + /* ln(x) / ln(n) is COMPLEX result */ + result.v_type = V_COM; + result.v_com = p_cval; + } - } else { + } else { - /* - * case: ln(x) is NUMBER, ln(n) is NUMBER - */ - result.v_num = qqdiv(ln_x_r, ln_n_r); - qfree(ln_x_r); - qfree(ln_n_r); - if (result.v_com == NULL) { - return error_value(E_LOGN_3); - } - /* ln(x) / ln(n) is NUMBER result */ - result.v_type = V_NUM; - } - } + /* + * case: ln(x) is NUMBER, ln(n) is NUMBER + */ + result.v_num = qqdiv(ln_x_r, ln_n_r); + qfree(ln_x_r); + qfree(ln_n_r); + if (result.v_com == NULL) { + return error_value(E_LOGN_3); + } + /* ln(x) / ln(n) is NUMBER result */ + result.v_type = V_NUM; + } + } - /* return the resulting logarithm */ - return result; + /* return the resulting logarithm */ + return result; } S_FUNC VALUE f_cos(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *eps; + VALUE result; + COMPLEX *c; + NUMBER *eps; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_COS_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_COS_1); + } + eps = vals[1]->v_num; + } - /* - * compute cosine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qcos(vals[0]->v_num, eps); - result.v_type = V_NUM; - break; - case V_COM: - c = c_cos(vals[0]->v_com, eps); - if (c == NULL) - return error_value(E_COS_3); - result.v_com = c; - result.v_type = V_COM; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_COS_2); - } - return result; + /* + * compute cosine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qcos(vals[0]->v_num, eps); + result.v_type = V_NUM; + break; + case V_COM: + c = c_cos(vals[0]->v_com, eps); + if (c == NULL) + return error_value(E_COS_3); + result.v_com = c; + result.v_type = V_COM; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_COS_2); + } + return result; } @@ -2762,46 +2762,46 @@ f_cos(int count, VALUE **vals) S_FUNC VALUE f_d2r(int count, VALUE **vals) { - VALUE result; - NUMBER *eps; - NUMBER *pidiv180; + VALUE result; + NUMBER *eps; + NUMBER *pidiv180; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_D2R_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_D2R_1); + } + eps = vals[1]->v_num; + } - /* - * compute argument*(pi/180) to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - pidiv180 = qpidiv180(eps); - result.v_num = qmul(vals[0]->v_num, pidiv180); - result.v_type = V_NUM; - qfree(pidiv180); - break; - case V_COM: - pidiv180 = qpidiv180(eps); - result.v_com = c_mulq(vals[0]->v_com, pidiv180); - result.v_type = V_COM; - qfree(pidiv180); - break; - default: - return error_value(E_D2R_2); - } - return result; + /* + * compute argument*(pi/180) to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + pidiv180 = qpidiv180(eps); + result.v_num = qmul(vals[0]->v_num, pidiv180); + result.v_type = V_NUM; + qfree(pidiv180); + break; + case V_COM: + pidiv180 = qpidiv180(eps); + result.v_com = c_mulq(vals[0]->v_com, pidiv180); + result.v_type = V_COM; + qfree(pidiv180); + break; + default: + return error_value(E_D2R_2); + } + return result; } @@ -2811,46 +2811,46 @@ f_d2r(int count, VALUE **vals) S_FUNC VALUE f_r2d(int count, VALUE **vals) { - VALUE result; - NUMBER *eps; - NUMBER *pidiv180; + VALUE result; + NUMBER *eps; + NUMBER *pidiv180; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_R2D_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_R2D_1); + } + eps = vals[1]->v_num; + } - /* - * compute argument/(pi/180) to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - pidiv180 = qpidiv180(eps); - result.v_num = qqdiv(vals[0]->v_num, pidiv180); - result.v_type = V_NUM; - qfree(pidiv180); - break; - case V_COM: - pidiv180 = qpidiv180(eps); - result.v_com = c_divq(vals[0]->v_com, pidiv180); - result.v_type = V_COM; - qfree(pidiv180); - break; - default: - return error_value(E_R2D_2); - } - return result; + /* + * compute argument/(pi/180) to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + pidiv180 = qpidiv180(eps); + result.v_num = qqdiv(vals[0]->v_num, pidiv180); + result.v_type = V_NUM; + qfree(pidiv180); + break; + case V_COM: + pidiv180 = qpidiv180(eps); + result.v_com = c_divq(vals[0]->v_com, pidiv180); + result.v_type = V_COM; + qfree(pidiv180); + break; + default: + return error_value(E_R2D_2); + } + return result; } @@ -2860,46 +2860,46 @@ f_r2d(int count, VALUE **vals) S_FUNC VALUE f_g2r(int count, VALUE **vals) { - VALUE result; - NUMBER *eps; - NUMBER *pidiv200; + VALUE result; + NUMBER *eps; + NUMBER *pidiv200; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_G2R_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_G2R_1); + } + eps = vals[1]->v_num; + } - /* - * compute argument*(pi/200) to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - pidiv200 = qpidiv200(eps); - result.v_num = qmul(vals[0]->v_num, pidiv200); - result.v_type = V_NUM; - qfree(pidiv200); - break; - case V_COM: - pidiv200 = qpidiv200(eps); - result.v_com = c_mulq(vals[0]->v_com, pidiv200); - result.v_type = V_COM; - qfree(pidiv200); - break; - default: - return error_value(E_G2R_2); - } - return result; + /* + * compute argument*(pi/200) to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + pidiv200 = qpidiv200(eps); + result.v_num = qmul(vals[0]->v_num, pidiv200); + result.v_type = V_NUM; + qfree(pidiv200); + break; + case V_COM: + pidiv200 = qpidiv200(eps); + result.v_com = c_mulq(vals[0]->v_com, pidiv200); + result.v_type = V_COM; + qfree(pidiv200); + break; + default: + return error_value(E_G2R_2); + } + return result; } @@ -2909,46 +2909,46 @@ f_g2r(int count, VALUE **vals) S_FUNC VALUE f_r2g(int count, VALUE **vals) { - VALUE result; - NUMBER *eps; - NUMBER *pidiv200; + VALUE result; + NUMBER *eps; + NUMBER *pidiv200; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_R2G_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_R2G_1); + } + eps = vals[1]->v_num; + } - /* - * compute argument/(pi/200) to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - pidiv200 = qpidiv200(eps); - result.v_num = qqdiv(vals[0]->v_num, pidiv200); - result.v_type = V_NUM; - qfree(pidiv200); - break; - case V_COM: - pidiv200 = qpidiv200(eps); - result.v_com = c_divq(vals[0]->v_com, pidiv200); - result.v_type = V_COM; - qfree(pidiv200); - break; - default: - return error_value(E_R2G_2); - } - return result; + /* + * compute argument/(pi/200) to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + pidiv200 = qpidiv200(eps); + result.v_num = qqdiv(vals[0]->v_num, pidiv200); + result.v_type = V_NUM; + qfree(pidiv200); + break; + case V_COM: + pidiv200 = qpidiv200(eps); + result.v_com = c_divq(vals[0]->v_com, pidiv200); + result.v_type = V_COM; + qfree(pidiv200); + break; + default: + return error_value(E_R2G_2); + } + return result; } @@ -2961,27 +2961,27 @@ f_r2g(int count, VALUE **vals) S_FUNC VALUE f_d2g(int UNUSED(count), VALUE **vals) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* NOTE: the epsilon (vals[1]->v_num) argument is ignored */ + /* NOTE: the epsilon (vals[1]->v_num) argument is ignored */ - /* calculate argument * (10/9) */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qmul(vals[0]->v_num, &_qtendivnine_); - result.v_type = V_NUM; - break; - case V_COM: - result.v_com = c_mulq(vals[0]->v_com, &_qtendivnine_); - result.v_type = V_COM; - break; - default: - return error_value(E_D2G_1); - } - return result; + /* calculate argument * (10/9) */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qmul(vals[0]->v_num, &_qtendivnine_); + result.v_type = V_NUM; + break; + case V_COM: + result.v_com = c_mulq(vals[0]->v_com, &_qtendivnine_); + result.v_type = V_COM; + break; + default: + return error_value(E_D2G_1); + } + return result; } @@ -2994,3502 +2994,3502 @@ f_d2g(int UNUSED(count), VALUE **vals) S_FUNC VALUE f_g2d(int UNUSED(count), VALUE **vals) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* NOTE: the epsilon (vals[1]->v_num) argument is ignored */ + /* NOTE: the epsilon (vals[1]->v_num) argument is ignored */ - /* calculate argument * (9/10) */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qmul(vals[0]->v_num, &_qninedivten_); - result.v_type = V_NUM; - break; - case V_COM: - result.v_com = c_mulq(vals[0]->v_com, &_qninedivten_); - result.v_type = V_COM; - break; - default: - return error_value(E_G2D_1); - } - return result; + /* calculate argument * (9/10) */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qmul(vals[0]->v_num, &_qninedivten_); + result.v_type = V_NUM; + break; + case V_COM: + result.v_com = c_mulq(vals[0]->v_com, &_qninedivten_); + result.v_type = V_COM; + break; + default: + return error_value(E_G2D_1); + } + return result; } S_FUNC VALUE f_sin(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *eps; + VALUE result; + COMPLEX *c; + NUMBER *eps; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_SIN_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_SIN_1); + } + eps = vals[1]->v_num; + } - /* - * compute sine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qsin(vals[0]->v_num, eps); - result.v_type = V_NUM; - break; - case V_COM: - c = c_sin(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_SIN_3); - } - result.v_com = c; - result.v_type = V_COM; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_SIN_2); - } - return result; + /* + * compute sine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qsin(vals[0]->v_num, eps); + result.v_type = V_NUM; + break; + case V_COM: + c = c_sin(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_SIN_3); + } + result.v_com = c; + result.v_type = V_COM; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_SIN_2); + } + return result; } S_FUNC VALUE f_tan(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *err; + VALUE result; + COMPLEX *c; + NUMBER *err; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use err VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_TAN_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use err VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_TAN_1); + } + err = vals[1]->v_num; + } - /* - * compute tangent to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qtan(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - c = c_tan(vals[0]->v_com, err); - if (c == NULL) { - return error_value(E_TAN_5); - } - result.v_com = c; - result.v_type = V_COM; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_TAN_2); - } - return result; + /* + * compute tangent to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qtan(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + c = c_tan(vals[0]->v_com, err); + if (c == NULL) { + return error_value(E_TAN_5); + } + result.v_com = c; + result.v_type = V_COM; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_TAN_2); + } + return result; } S_FUNC VALUE f_cot(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *err; + VALUE result; + COMPLEX *c; + NUMBER *err; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use err VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_COT_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use err VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_COT_1); + } + err = vals[1]->v_num; + } - /* - * compute cotangent to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) { - return error_value(E_COT_5); - } - result.v_num = qcot(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - if (ciszero(vals[0]->v_com)) { - return error_value(E_COT_5); - } - c = c_cot(vals[0]->v_com, err); - if (c == NULL) { - return error_value(E_COT_6); - } - result.v_com = c; - result.v_type = V_COM; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_COT_2); - } - return result; + /* + * compute cotangent to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) { + return error_value(E_COT_5); + } + result.v_num = qcot(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + if (ciszero(vals[0]->v_com)) { + return error_value(E_COT_5); + } + c = c_cot(vals[0]->v_com, err); + if (c == NULL) { + return error_value(E_COT_6); + } + result.v_com = c; + result.v_type = V_COM; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_COT_2); + } + return result; } S_FUNC VALUE f_sec(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *err; + VALUE result; + COMPLEX *c; + NUMBER *err; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use err VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_SEC_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use err VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_SEC_1); + } + err = vals[1]->v_num; + } - /* - * compute secant to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qsec(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - c = c_sec(vals[0]->v_com, err); - if (c == NULL) { - return error_value(E_SEC_5); - } - result.v_com = c; - result.v_type = V_COM; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_SEC_2); - } - return result; + /* + * compute secant to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qsec(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + c = c_sec(vals[0]->v_com, err); + if (c == NULL) { + return error_value(E_SEC_5); + } + result.v_com = c; + result.v_type = V_COM; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_SEC_2); + } + return result; } S_FUNC VALUE f_csc(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *err; + VALUE result; + COMPLEX *c; + NUMBER *err; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use err VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_CSC_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use err VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_CSC_1); + } + err = vals[1]->v_num; + } - /* - * compute cosecant to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) { - return error_value(E_CSC_5); - } - result.v_num = qcsc(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - if (ciszero(vals[0]->v_com)) { - return error_value(E_CSC_5); - } - c = c_csc(vals[0]->v_com, err); - if (c == NULL) { - return error_value(E_CSC_6); - } - result.v_com = c; - result.v_type = V_COM; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_CSC_2); - } - return result; + /* + * compute cosecant to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) { + return error_value(E_CSC_5); + } + result.v_num = qcsc(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + if (ciszero(vals[0]->v_com)) { + return error_value(E_CSC_5); + } + c = c_csc(vals[0]->v_com, err); + if (c == NULL) { + return error_value(E_CSC_6); + } + result.v_com = c; + result.v_type = V_COM; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_CSC_2); + } + return result; } S_FUNC VALUE f_sinh(int count, VALUE **vals) { - VALUE result; - NUMBER *eps; - NUMBER *q; - COMPLEX *c; + VALUE result; + NUMBER *eps; + NUMBER *q; + COMPLEX *c; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_SINH_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_SINH_1); + } + eps = vals[1]->v_num; + } - /* - * compute hyperbolic sine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - q = qsinh(vals[0]->v_num, eps); - if (q == NULL) - return error_value(E_SINH_3); - result.v_num = q; - result.v_type = V_NUM; - break; - case V_COM: - c = c_sinh(vals[0]->v_com, eps); - if (c == NULL) - return error_value(E_SINH_3); - result.v_com = c; - result.v_type = V_COM; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_SINH_2); - } - return result; + /* + * compute hyperbolic sine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + q = qsinh(vals[0]->v_num, eps); + if (q == NULL) + return error_value(E_SINH_3); + result.v_num = q; + result.v_type = V_NUM; + break; + case V_COM: + c = c_sinh(vals[0]->v_com, eps); + if (c == NULL) + return error_value(E_SINH_3); + result.v_com = c; + result.v_type = V_COM; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_SINH_2); + } + return result; } S_FUNC VALUE f_cosh(int count, VALUE **vals) { - VALUE result; - NUMBER *eps; - NUMBER *q; - COMPLEX *c; + VALUE result; + NUMBER *eps; + NUMBER *q; + COMPLEX *c; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_COSH_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_COSH_1); + } + eps = vals[1]->v_num; + } - /* - * compute hyperbolic cosine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - q = qcosh(vals[0]->v_num, eps); - if (q == NULL) - return error_value(E_COSH_3); - result.v_num = q; - result.v_type = V_NUM; - break; - case V_COM: - c = c_cosh(vals[0]->v_com, eps); - if (c == NULL) - return error_value(E_COSH_3); - result.v_com = c; - result.v_type = V_COM; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_COSH_2); - } - return result; + /* + * compute hyperbolic cosine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + q = qcosh(vals[0]->v_num, eps); + if (q == NULL) + return error_value(E_COSH_3); + result.v_num = q; + result.v_type = V_NUM; + break; + case V_COM: + c = c_cosh(vals[0]->v_com, eps); + if (c == NULL) + return error_value(E_COSH_3); + result.v_com = c; + result.v_type = V_COM; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_COSH_2); + } + return result; } S_FUNC VALUE f_tanh(int count, VALUE **vals) { - VALUE result; - VALUE tmp1, tmp2; - NUMBER *err; + VALUE result; + VALUE tmp1, tmp2; + NUMBER *err; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; - tmp1.v_subtype = V_NOSUBTYPE; - tmp2.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; + tmp1.v_subtype = V_NOSUBTYPE; + tmp2.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_TANH_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_TANH_1); + } + err = vals[1]->v_num; + } - /* - * compute hyperbolic tangent to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qtanh(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - tmp1.v_type = V_COM; - tmp1.v_com = c_sinh(vals[0]->v_com, err); - if (tmp1.v_com == NULL) { - return error_value(E_TANH_3); - } - tmp2.v_type = V_COM; - tmp2.v_com = c_cosh(vals[0]->v_com, err); - if (tmp2.v_com == NULL) { - comfree(tmp1.v_com); - return error_value(E_TANH_4); - } - divvalue(&tmp1, &tmp2, &result); - comfree(tmp1.v_com); - comfree(tmp2.v_com); - break; - default: - return error_value(E_TANH_2); - } - return result; + /* + * compute hyperbolic tangent to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qtanh(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + tmp1.v_type = V_COM; + tmp1.v_com = c_sinh(vals[0]->v_com, err); + if (tmp1.v_com == NULL) { + return error_value(E_TANH_3); + } + tmp2.v_type = V_COM; + tmp2.v_com = c_cosh(vals[0]->v_com, err); + if (tmp2.v_com == NULL) { + comfree(tmp1.v_com); + return error_value(E_TANH_4); + } + divvalue(&tmp1, &tmp2, &result); + comfree(tmp1.v_com); + comfree(tmp2.v_com); + break; + default: + return error_value(E_TANH_2); + } + return result; } S_FUNC VALUE f_coth(int count, VALUE **vals) { - VALUE result; - VALUE tmp1, tmp2; - NUMBER *err; + VALUE result; + VALUE tmp1, tmp2; + NUMBER *err; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; - tmp1.v_subtype = V_NOSUBTYPE; - tmp2.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; + tmp1.v_subtype = V_NOSUBTYPE; + tmp2.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_COTH_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_COTH_1); + } + err = vals[1]->v_num; + } - /* - * compute hyperbolic cotangent to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) - return error_value(E_DIVBYZERO); - result.v_num = qcoth(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - tmp1.v_type = V_COM; - tmp1.v_com = c_cosh(vals[0]->v_com, err); - if (tmp1.v_com == NULL) { - return error_value(E_COTH_3); - } - tmp2.v_type = V_COM; - tmp2.v_com = c_sinh(vals[0]->v_com, err); - if (tmp2.v_com == NULL) { - comfree(tmp1.v_com); - return error_value(E_COTH_4); - } - divvalue(&tmp1, &tmp2, &result); - comfree(tmp1.v_com); - comfree(tmp2.v_com); - break; - default: - return error_value(E_COTH_2); - } - return result; + /* + * compute hyperbolic cotangent to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) + return error_value(E_DIVBYZERO); + result.v_num = qcoth(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + tmp1.v_type = V_COM; + tmp1.v_com = c_cosh(vals[0]->v_com, err); + if (tmp1.v_com == NULL) { + return error_value(E_COTH_3); + } + tmp2.v_type = V_COM; + tmp2.v_com = c_sinh(vals[0]->v_com, err); + if (tmp2.v_com == NULL) { + comfree(tmp1.v_com); + return error_value(E_COTH_4); + } + divvalue(&tmp1, &tmp2, &result); + comfree(tmp1.v_com); + comfree(tmp2.v_com); + break; + default: + return error_value(E_COTH_2); + } + return result; } S_FUNC VALUE f_sech(int count, VALUE **vals) { - VALUE result; - VALUE tmp; - NUMBER *err; + VALUE result; + VALUE tmp; + NUMBER *err; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; - tmp.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; + tmp.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_SECH_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_SECH_1); + } + err = vals[1]->v_num; + } - /* - * compute hyperbolic secant to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qsech(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - tmp.v_type = V_COM; - tmp.v_com = c_cosh(vals[0]->v_com, err); - if (tmp.v_com == NULL) { - return error_value(E_SECH_3); - } - invertvalue(&tmp, &result); - comfree(tmp.v_com); - break; - default: - return error_value(E_SECH_2); - } - return result; + /* + * compute hyperbolic secant to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qsech(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + tmp.v_type = V_COM; + tmp.v_com = c_cosh(vals[0]->v_com, err); + if (tmp.v_com == NULL) { + return error_value(E_SECH_3); + } + invertvalue(&tmp, &result); + comfree(tmp.v_com); + break; + default: + return error_value(E_SECH_2); + } + return result; } S_FUNC VALUE f_csch(int count, VALUE **vals) { - VALUE result; - VALUE tmp; - NUMBER *err; + VALUE result; + VALUE tmp; + NUMBER *err; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; - tmp.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; + tmp.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_CSCH_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_CSCH_1); + } + err = vals[1]->v_num; + } - /* - * compute hyperbolic cosecant to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) - return error_value(E_DIVBYZERO); - result.v_num = qcsch(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - tmp.v_type = V_COM; - tmp.v_com = c_sinh(vals[0]->v_com, err); - if (tmp.v_com == NULL) { - return error_value(E_CSCH_3); - } - invertvalue(&tmp, &result); - comfree(tmp.v_com); - break; - default: - return error_value(E_CSCH_2); - } - return result; + /* + * compute hyperbolic cosecant to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) + return error_value(E_DIVBYZERO); + result.v_num = qcsch(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + tmp.v_type = V_COM; + tmp.v_com = c_sinh(vals[0]->v_com, err); + if (tmp.v_com == NULL) { + return error_value(E_CSCH_3); + } + invertvalue(&tmp, &result); + comfree(tmp.v_com); + break; + default: + return error_value(E_CSCH_2); + } + return result; } S_FUNC VALUE f_atan(int count, VALUE **vals) { - VALUE result; - COMPLEX *tmp; - NUMBER *err; + VALUE result; + COMPLEX *tmp; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_ATAN_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_ATAN_1); + } + err = vals[1]->v_num; + } - /* - * compute inverse tangent to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qatan(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - tmp = c_atan(vals[0]->v_com, err); - if (tmp == NULL) - return error_value(E_ATAN_3); - result.v_type = V_COM; - result.v_com = tmp; - if (cisreal(tmp)) { - result.v_num = c_to_q(tmp, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_ATAN_2); - } - return result; + /* + * compute inverse tangent to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qatan(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + tmp = c_atan(vals[0]->v_com, err); + if (tmp == NULL) + return error_value(E_ATAN_3); + result.v_type = V_COM; + result.v_com = tmp; + if (cisreal(tmp)) { + result.v_num = c_to_q(tmp, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_ATAN_2); + } + return result; } S_FUNC VALUE f_acot(int count, VALUE **vals) { - VALUE result; - COMPLEX *tmp; - NUMBER *err; + VALUE result; + COMPLEX *tmp; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_ACOT_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_ACOT_1); + } + err = vals[1]->v_num; + } - /* - * compute inverse cotangent to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qacot(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - tmp = c_acot(vals[0]->v_com, err); - if (tmp == NULL) - return error_value(E_ACOT_3); - result.v_type = V_COM; - result.v_com = tmp; - if (cisreal(tmp)) { - result.v_num = c_to_q(tmp, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_ACOT_2); - } - return result; + /* + * compute inverse cotangent to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qacot(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + tmp = c_acot(vals[0]->v_com, err); + if (tmp == NULL) + return error_value(E_ACOT_3); + result.v_type = V_COM; + result.v_com = tmp; + if (cisreal(tmp)) { + result.v_num = c_to_q(tmp, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_ACOT_2); + } + return result; } S_FUNC VALUE f_asin(int count, VALUE **vals) { - VALUE result; - COMPLEX *tmp; - NUMBER *err; + VALUE result; + COMPLEX *tmp; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_ASIN_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_ASIN_1); + } + err = vals[1]->v_num; + } - /* - * compute inverse sine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qasin(vals[0]->v_num, err); - result.v_type = V_NUM; - if (result.v_num == NULL) { - tmp = comalloc(); - qfree(tmp->real); - tmp->real = qlink(vals[0]->v_num); - result.v_type = V_COM; - result.v_com = c_asin(tmp, err); - comfree(tmp); - } - break; - case V_COM: - result.v_com = c_asin(vals[0]->v_com, err); - result.v_type = V_COM; - break; - default: - return error_value(E_ASIN_2); - } - if (result.v_com == NULL) { - return error_value(E_ASIN_3); - } - if (result.v_type == V_COM && cisreal(result.v_com)) { - result.v_num = c_to_q(result.v_com, true); - result.v_type = V_NUM; - } - return result; + /* + * compute inverse sine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qasin(vals[0]->v_num, err); + result.v_type = V_NUM; + if (result.v_num == NULL) { + tmp = comalloc(); + qfree(tmp->real); + tmp->real = qlink(vals[0]->v_num); + result.v_type = V_COM; + result.v_com = c_asin(tmp, err); + comfree(tmp); + } + break; + case V_COM: + result.v_com = c_asin(vals[0]->v_com, err); + result.v_type = V_COM; + break; + default: + return error_value(E_ASIN_2); + } + if (result.v_com == NULL) { + return error_value(E_ASIN_3); + } + if (result.v_type == V_COM && cisreal(result.v_com)) { + result.v_num = c_to_q(result.v_com, true); + result.v_type = V_NUM; + } + return result; } S_FUNC VALUE f_acos(int count, VALUE **vals) { - VALUE result; - COMPLEX *tmp; - NUMBER *err; + VALUE result; + COMPLEX *tmp; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_ACOS_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_ACOS_1); + } + err = vals[1]->v_num; + } - /* - * compute inverse cosine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qacos(vals[0]->v_num, err); - result.v_type = V_NUM; - if (result.v_num == NULL) { - tmp = comalloc(); - qfree(tmp->real); - tmp->real = qlink(vals[0]->v_num); - result.v_type = V_COM; - result.v_com = c_acos(tmp, err); - comfree(tmp); - } - break; - case V_COM: - result.v_com = c_acos(vals[0]->v_com, err); - result.v_type = V_COM; - break; - default: - return error_value(E_ACOS_2); - } - if (result.v_com == NULL) { - return error_value(E_ACOS_3); - } - if (result.v_type == V_COM && cisreal(result.v_com)) { - result.v_num = c_to_q(result.v_com, true); - result.v_type = V_NUM; - } - return result; + /* + * compute inverse cosine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qacos(vals[0]->v_num, err); + result.v_type = V_NUM; + if (result.v_num == NULL) { + tmp = comalloc(); + qfree(tmp->real); + tmp->real = qlink(vals[0]->v_num); + result.v_type = V_COM; + result.v_com = c_acos(tmp, err); + comfree(tmp); + } + break; + case V_COM: + result.v_com = c_acos(vals[0]->v_com, err); + result.v_type = V_COM; + break; + default: + return error_value(E_ACOS_2); + } + if (result.v_com == NULL) { + return error_value(E_ACOS_3); + } + if (result.v_type == V_COM && cisreal(result.v_com)) { + result.v_num = c_to_q(result.v_com, true); + result.v_type = V_NUM; + } + return result; } S_FUNC VALUE f_asec(int count, VALUE **vals) { - VALUE result; - COMPLEX *tmp; - NUMBER *err; + VALUE result; + COMPLEX *tmp; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_ASEC_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_ASEC_1); + } + err = vals[1]->v_num; + } - /* - * compute inverse secant to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) - return error_value(E_ASEC_3); - result.v_num = qasec(vals[0]->v_num, err); - result.v_type = V_NUM; - if (result.v_num == NULL) { - tmp = comalloc(); - qfree(tmp->real); - tmp->real = qlink(vals[0]->v_num); - result.v_com = c_asec(tmp, err); - result.v_type = V_COM; - comfree(tmp); - } - break; - case V_COM: - result.v_com = c_asec(vals[0]->v_com, err); - result.v_type = V_COM; - break; - default: - return error_value(E_ASEC_2); - } - if (result.v_com == NULL) { - return error_value(E_ASEC_3); - } - if (result.v_type == V_COM) { - if (cisreal(result.v_com)) { - result.v_num = c_to_q(result.v_com, true); - result.v_type = V_NUM; - } - } - return result; + /* + * compute inverse secant to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) + return error_value(E_ASEC_3); + result.v_num = qasec(vals[0]->v_num, err); + result.v_type = V_NUM; + if (result.v_num == NULL) { + tmp = comalloc(); + qfree(tmp->real); + tmp->real = qlink(vals[0]->v_num); + result.v_com = c_asec(tmp, err); + result.v_type = V_COM; + comfree(tmp); + } + break; + case V_COM: + result.v_com = c_asec(vals[0]->v_com, err); + result.v_type = V_COM; + break; + default: + return error_value(E_ASEC_2); + } + if (result.v_com == NULL) { + return error_value(E_ASEC_3); + } + if (result.v_type == V_COM) { + if (cisreal(result.v_com)) { + result.v_num = c_to_q(result.v_com, true); + result.v_type = V_NUM; + } + } + return result; } S_FUNC VALUE f_acsc(int count, VALUE **vals) { - VALUE result; - COMPLEX *tmp; - NUMBER *err; + VALUE result; + COMPLEX *tmp; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_ACSC_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_ACSC_1); + } + err = vals[1]->v_num; + } - /* - * compute inverse cosecant to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) - return error_value(E_ACSC_3); - result.v_num = qacsc(vals[0]->v_num, err); - result.v_type = V_NUM; - if (result.v_num == NULL) { - tmp = comalloc(); - qfree(tmp->real); - tmp->real = qlink(vals[0]->v_num); - result.v_com = c_acsc(tmp, err); - result.v_type = V_COM; - comfree(tmp); - } - break; - case V_COM: - result.v_com = c_acsc(vals[0]->v_com, err); - result.v_type = V_COM; - break; - default: - return error_value(E_ACSC_2); - } - if (result.v_com == NULL) { - return error_value(E_ACSC_3); - } - if (result.v_type == V_COM) { - if (cisreal(result.v_com)) { - result.v_num = c_to_q(result.v_com, true); - result.v_type = V_NUM; - } - } - return result; + /* + * compute inverse cosecant to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) + return error_value(E_ACSC_3); + result.v_num = qacsc(vals[0]->v_num, err); + result.v_type = V_NUM; + if (result.v_num == NULL) { + tmp = comalloc(); + qfree(tmp->real); + tmp->real = qlink(vals[0]->v_num); + result.v_com = c_acsc(tmp, err); + result.v_type = V_COM; + comfree(tmp); + } + break; + case V_COM: + result.v_com = c_acsc(vals[0]->v_com, err); + result.v_type = V_COM; + break; + default: + return error_value(E_ACSC_2); + } + if (result.v_com == NULL) { + return error_value(E_ACSC_3); + } + if (result.v_type == V_COM) { + if (cisreal(result.v_com)) { + result.v_num = c_to_q(result.v_com, true); + result.v_type = V_NUM; + } + } + return result; } S_FUNC VALUE f_asinh(int count, VALUE **vals) { - VALUE result; - COMPLEX *tmp; - NUMBER *err; + VALUE result; + COMPLEX *tmp; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_ASINH_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_ASINH_1); + } + err = vals[1]->v_num; + } - /* - * compute inverse hyperbolic sine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qasinh(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - tmp = c_asinh(vals[0]->v_com, err); - if (tmp == NULL) { - return error_value(E_ASINH_3); - } - result.v_type = V_COM; - result.v_com = tmp; - if (cisreal(tmp)) { - result.v_num = c_to_q(tmp, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_ASINH_2); - } - return result; + /* + * compute inverse hyperbolic sine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qasinh(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + tmp = c_asinh(vals[0]->v_com, err); + if (tmp == NULL) { + return error_value(E_ASINH_3); + } + result.v_type = V_COM; + result.v_com = tmp; + if (cisreal(tmp)) { + result.v_num = c_to_q(tmp, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_ASINH_2); + } + return result; } S_FUNC VALUE f_acosh(int count, VALUE **vals) { - VALUE result; - COMPLEX *tmp; - NUMBER *err; + VALUE result; + COMPLEX *tmp; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_ACOSH_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_ACOSH_1); + } + err = vals[1]->v_num; + } - /* - * compute inverse hyperbolic cosine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qacosh(vals[0]->v_num, err); - result.v_type = V_NUM; - if (result.v_num == NULL) { - tmp = comalloc(); - qfree(tmp->real); - tmp->real = qlink(vals[0]->v_num); - result.v_com = c_acosh(tmp, err); - result.v_type = V_COM; - comfree(tmp); - } - break; - case V_COM: - result.v_com = c_acosh(vals[0]->v_com, err); - result.v_type = V_COM; - break; - default: - return error_value(E_ACOSH_2); - } - if (result.v_com == NULL) { - return error_value(E_ACOSH_3); - } - if (result.v_type == V_COM && cisreal(result.v_com)) { - result.v_num = c_to_q(result.v_com, true); - result.v_type = V_NUM; - } - return result; + /* + * compute inverse hyperbolic cosine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qacosh(vals[0]->v_num, err); + result.v_type = V_NUM; + if (result.v_num == NULL) { + tmp = comalloc(); + qfree(tmp->real); + tmp->real = qlink(vals[0]->v_num); + result.v_com = c_acosh(tmp, err); + result.v_type = V_COM; + comfree(tmp); + } + break; + case V_COM: + result.v_com = c_acosh(vals[0]->v_com, err); + result.v_type = V_COM; + break; + default: + return error_value(E_ACOSH_2); + } + if (result.v_com == NULL) { + return error_value(E_ACOSH_3); + } + if (result.v_type == V_COM && cisreal(result.v_com)) { + result.v_num = c_to_q(result.v_com, true); + result.v_type = V_NUM; + } + return result; } S_FUNC VALUE f_atanh(int count, VALUE **vals) { - VALUE result; - COMPLEX *tmp; - NUMBER *err; + VALUE result; + COMPLEX *tmp; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_ATANH_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_ATANH_1); + } + err = vals[1]->v_num; + } - /* - * compute inverse hyperbolic tangent to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qatanh(vals[0]->v_num, err); - result.v_type = V_NUM; - if (result.v_num == NULL) { - tmp = comalloc(); - qfree(tmp->real); - tmp->real = qlink(vals[0]->v_num); - result.v_com = c_atanh(tmp, err); - result.v_type = V_COM; - comfree(tmp); - } - break; - case V_COM: - result.v_com = c_atanh(vals[0]->v_com, err); - result.v_type = V_COM; - break; - default: - return error_value(E_ATANH_2); - } - if (result.v_com == NULL) { - return error_value(E_ATANH_3); - } - if (result.v_type == V_COM) { - if (cisreal(result.v_com)) { - result.v_num = c_to_q(result.v_com, true); - result.v_type = V_NUM; - } - } - return result; + /* + * compute inverse hyperbolic tangent to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qatanh(vals[0]->v_num, err); + result.v_type = V_NUM; + if (result.v_num == NULL) { + tmp = comalloc(); + qfree(tmp->real); + tmp->real = qlink(vals[0]->v_num); + result.v_com = c_atanh(tmp, err); + result.v_type = V_COM; + comfree(tmp); + } + break; + case V_COM: + result.v_com = c_atanh(vals[0]->v_com, err); + result.v_type = V_COM; + break; + default: + return error_value(E_ATANH_2); + } + if (result.v_com == NULL) { + return error_value(E_ATANH_3); + } + if (result.v_type == V_COM) { + if (cisreal(result.v_com)) { + result.v_num = c_to_q(result.v_com, true); + result.v_type = V_NUM; + } + } + return result; } S_FUNC VALUE f_acoth(int count, VALUE **vals) { - VALUE result; - COMPLEX *tmp; - NUMBER *err; + VALUE result; + COMPLEX *tmp; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_ACOTH_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_ACOTH_1); + } + err = vals[1]->v_num; + } - /* - * compute inverse hyperbolic cotangent to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qacoth(vals[0]->v_num, err); - result.v_type = V_NUM; - if (result.v_num == NULL) { - tmp = comalloc(); - qfree(tmp->real); - tmp->real = qlink(vals[0]->v_num); - result.v_com = c_acoth(tmp, err); - result.v_type = V_COM; - comfree(tmp); - } - break; - case V_COM: - result.v_com = c_acoth(vals[0]->v_com, err); - result.v_type = V_COM; - break; - default: - return error_value(E_ACOTH_2); - } - if (result.v_com == NULL) { - return error_value(E_ACOTH_3); - } - if (result.v_type == V_COM) { - if (cisreal(result.v_com)) { - result.v_num = c_to_q(result.v_com, true); - result.v_type = V_NUM; - } - } - return result; + /* + * compute inverse hyperbolic cotangent to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qacoth(vals[0]->v_num, err); + result.v_type = V_NUM; + if (result.v_num == NULL) { + tmp = comalloc(); + qfree(tmp->real); + tmp->real = qlink(vals[0]->v_num); + result.v_com = c_acoth(tmp, err); + result.v_type = V_COM; + comfree(tmp); + } + break; + case V_COM: + result.v_com = c_acoth(vals[0]->v_com, err); + result.v_type = V_COM; + break; + default: + return error_value(E_ACOTH_2); + } + if (result.v_com == NULL) { + return error_value(E_ACOTH_3); + } + if (result.v_type == V_COM) { + if (cisreal(result.v_com)) { + result.v_num = c_to_q(result.v_com, true); + result.v_type = V_NUM; + } + } + return result; } S_FUNC VALUE f_asech(int count, VALUE **vals) { - VALUE result; - COMPLEX *tmp; - NUMBER *err; + VALUE result; + COMPLEX *tmp; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_SECH_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_SECH_1); + } + err = vals[1]->v_num; + } - /* - * compute inverse hyperbolic secant to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) - return error_value(E_ASECH_3); - result.v_num = qasech(vals[0]->v_num, err); - result.v_type = V_NUM; - if (result.v_num == NULL) { - tmp = comalloc(); - qfree(tmp->real); - tmp->real = qlink(vals[0]->v_num); - result.v_com = c_asech(tmp, err); - result.v_type = V_COM; - comfree(tmp); - } - break; - case V_COM: - result.v_com = c_asech(vals[0]->v_com, err); - result.v_type = V_COM; - break; - default: - return error_value(E_ASECH_2); - } - if (result.v_com == NULL) { - return error_value(E_ASECH_3); - } - if (result.v_type == V_COM) { - if (cisreal(result.v_com)) { - result.v_num = c_to_q(result.v_com, true); - result.v_type = V_NUM; - } - } - return result; + /* + * compute inverse hyperbolic secant to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) + return error_value(E_ASECH_3); + result.v_num = qasech(vals[0]->v_num, err); + result.v_type = V_NUM; + if (result.v_num == NULL) { + tmp = comalloc(); + qfree(tmp->real); + tmp->real = qlink(vals[0]->v_num); + result.v_com = c_asech(tmp, err); + result.v_type = V_COM; + comfree(tmp); + } + break; + case V_COM: + result.v_com = c_asech(vals[0]->v_com, err); + result.v_type = V_COM; + break; + default: + return error_value(E_ASECH_2); + } + if (result.v_com == NULL) { + return error_value(E_ASECH_3); + } + if (result.v_type == V_COM) { + if (cisreal(result.v_com)) { + result.v_num = c_to_q(result.v_com, true); + result.v_type = V_NUM; + } + } + return result; } S_FUNC VALUE f_acsch(int count, VALUE **vals) { - VALUE result; - COMPLEX *tmp; - NUMBER *err; + VALUE result; + COMPLEX *tmp; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_ACSCH_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_ACSCH_1); + } + err = vals[1]->v_num; + } - /* - * compute inverse hyperbolic cosecant to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) - return error_value(E_ACSCH_3); - result.v_num = qacsch(vals[0]->v_num, err); - result.v_type = V_NUM; - if (result.v_num == NULL) { - tmp = comalloc(); - qfree(tmp->real); - tmp->real = qlink(vals[0]->v_num); - result.v_com = c_acsch(tmp, err); - result.v_type = V_COM; - comfree(tmp); - } - break; - case V_COM: - result.v_com = c_acsch(vals[0]->v_com, err); - result.v_type = V_COM; - break; - default: - return error_value(E_ACSCH_2); - } - if (result.v_com == NULL) { - return error_value(E_ACSCH_3); - } - if (result.v_type == V_COM) { - if (cisreal(result.v_com)) { - result.v_num = c_to_q(result.v_com, true); - result.v_type = V_NUM; - } - } - return result; + /* + * compute inverse hyperbolic cosecant to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) + return error_value(E_ACSCH_3); + result.v_num = qacsch(vals[0]->v_num, err); + result.v_type = V_NUM; + if (result.v_num == NULL) { + tmp = comalloc(); + qfree(tmp->real); + tmp->real = qlink(vals[0]->v_num); + result.v_com = c_acsch(tmp, err); + result.v_type = V_COM; + comfree(tmp); + } + break; + case V_COM: + result.v_com = c_acsch(vals[0]->v_com, err); + result.v_type = V_COM; + break; + default: + return error_value(E_ACSCH_2); + } + if (result.v_com == NULL) { + return error_value(E_ACSCH_3); + } + if (result.v_type == V_COM) { + if (cisreal(result.v_com)) { + result.v_num = c_to_q(result.v_com, true); + result.v_type = V_NUM; + } + } + return result; } S_FUNC VALUE f_gd(int count, VALUE **vals) { - VALUE result; - NUMBER *eps; - COMPLEX *tmp; + VALUE result; + NUMBER *eps; + COMPLEX *tmp; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_GD_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_GD_1); + } + eps = vals[1]->v_num; + } - /* - * compute Gudermannian function to a given error tolerance - */ - result.v_type = V_COM; - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) { - result.v_type = V_NUM; - result.v_num = qlink(&_qzero_); - return result; - } - tmp = comalloc(); - qfree(tmp->real); - tmp->real = qlink(vals[0]->v_num); - result.v_com = c_gd(tmp, eps); - comfree(tmp); - break; - case V_COM: - result.v_com = c_gd(vals[0]->v_com, eps); - break; - default: - return error_value(E_GD_2); - } - if (result.v_com == NULL) - return error_value(E_GD_3); - if (cisreal(result.v_com)) { - result.v_num = c_to_q(result.v_com, true); - result.v_type = V_NUM; - } - return result; + /* + * compute Gudermannian function to a given error tolerance + */ + result.v_type = V_COM; + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) { + result.v_type = V_NUM; + result.v_num = qlink(&_qzero_); + return result; + } + tmp = comalloc(); + qfree(tmp->real); + tmp->real = qlink(vals[0]->v_num); + result.v_com = c_gd(tmp, eps); + comfree(tmp); + break; + case V_COM: + result.v_com = c_gd(vals[0]->v_com, eps); + break; + default: + return error_value(E_GD_2); + } + if (result.v_com == NULL) + return error_value(E_GD_3); + if (cisreal(result.v_com)) { + result.v_num = c_to_q(result.v_com, true); + result.v_type = V_NUM; + } + return result; } S_FUNC VALUE f_agd(int count, VALUE **vals) { - VALUE result; - NUMBER *eps; - COMPLEX *tmp; + VALUE result; + NUMBER *eps; + COMPLEX *tmp; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given as a NUMBER and != 0. - */ - eps = conf->epsilon; - if (count == 2) { - if (vals[1]->v_type != V_NUM || qiszero(vals[1]->v_num)) { - return error_value(E_AGD_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given as a NUMBER and != 0. + */ + eps = conf->epsilon; + if (count == 2) { + if (vals[1]->v_type != V_NUM || qiszero(vals[1]->v_num)) { + return error_value(E_AGD_1); + } + eps = vals[1]->v_num; + } - /* - * compute inverse Gudermannian function to a given error tolerance - */ - result.v_type = V_COM; - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) { - result.v_type = V_NUM; - result.v_num = qlink(&_qzero_); - return result; - } - tmp = comalloc(); - qfree(tmp->real); - tmp->real = qlink(vals[0]->v_num); - result.v_com = c_agd(tmp, eps); - comfree(tmp); - break; - case V_COM: - result.v_com = c_agd(vals[0]->v_com, eps); - break; - default: - return error_value(E_AGD_2); - } - if (result.v_com == NULL) - return error_value(E_AGD_3); - if (cisreal(result.v_com)) { - result.v_num = c_to_q(result.v_com, true); - result.v_type = V_NUM; - } - return result; + /* + * compute inverse Gudermannian function to a given error tolerance + */ + result.v_type = V_COM; + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) { + result.v_type = V_NUM; + result.v_num = qlink(&_qzero_); + return result; + } + tmp = comalloc(); + qfree(tmp->real); + tmp->real = qlink(vals[0]->v_num); + result.v_com = c_agd(tmp, eps); + comfree(tmp); + break; + case V_COM: + result.v_com = c_agd(vals[0]->v_com, eps); + break; + default: + return error_value(E_AGD_2); + } + if (result.v_com == NULL) + return error_value(E_AGD_3); + if (cisreal(result.v_com)) { + result.v_num = c_to_q(result.v_com, true); + result.v_type = V_NUM; + } + return result; } S_FUNC VALUE f_comb(VALUE *v1, VALUE *v2) { - long n; - VALUE result; - VALUE tmp1, tmp2, div; + long n; + VALUE result; + VALUE tmp1, tmp2, div; - if (v2->v_type != V_NUM || qisfrac(v2->v_num)) - return error_value(E_COMB_1); - result.v_subtype = V_NOSUBTYPE; - result.v_type = V_NUM; - if (qisneg(v2->v_num)) { - result.v_num = qlink(&_qzero_); - return result; - } - if (qiszero(v2->v_num)) { - result.v_num = qlink(&_qone_); - return result; - } - if (qisone(v2->v_num)) { - copyvalue(v1, &result); - return result; - } - if (v1->v_type == V_NUM) { - result.v_num = qcomb(v1->v_num, v2->v_num); - if (result.v_num == NULL) - return error_value(E_COMB_2); - return result; - } - if (zge24b(v2->v_num->num)) - return error_value(E_COMB_2); - n = qtoi(v2->v_num); - copyvalue(v1, &result); - decvalue(v1, &tmp1); - div.v_type = V_NUM; - div.v_subtype = V_NOSUBTYPE; - div.v_num = qlink(&_qtwo_); - n--; - for (;;) { - mulvalue(&result, &tmp1, &tmp2); - freevalue(&result); - divvalue(&tmp2, &div, &result); - freevalue(&tmp2); - if (--n == 0 || !testvalue(&result) || result.v_type < 0) { - freevalue(&tmp1); - freevalue(&div); - return result; - } - decvalue(&tmp1, &tmp2); - freevalue(&tmp1); - tmp1 = tmp2; - incvalue(&div, &tmp2); - freevalue(&div); - div = tmp2; - } + if (v2->v_type != V_NUM || qisfrac(v2->v_num)) + return error_value(E_COMB_1); + result.v_subtype = V_NOSUBTYPE; + result.v_type = V_NUM; + if (qisneg(v2->v_num)) { + result.v_num = qlink(&_qzero_); + return result; + } + if (qiszero(v2->v_num)) { + result.v_num = qlink(&_qone_); + return result; + } + if (qisone(v2->v_num)) { + copyvalue(v1, &result); + return result; + } + if (v1->v_type == V_NUM) { + result.v_num = qcomb(v1->v_num, v2->v_num); + if (result.v_num == NULL) + return error_value(E_COMB_2); + return result; + } + if (zge24b(v2->v_num->num)) + return error_value(E_COMB_2); + n = qtoi(v2->v_num); + copyvalue(v1, &result); + decvalue(v1, &tmp1); + div.v_type = V_NUM; + div.v_subtype = V_NOSUBTYPE; + div.v_num = qlink(&_qtwo_); + n--; + for (;;) { + mulvalue(&result, &tmp1, &tmp2); + freevalue(&result); + divvalue(&tmp2, &div, &result); + freevalue(&tmp2); + if (--n == 0 || !testvalue(&result) || result.v_type < 0) { + freevalue(&tmp1); + freevalue(&div); + return result; + } + decvalue(&tmp1, &tmp2); + freevalue(&tmp1); + tmp1 = tmp2; + incvalue(&div, &tmp2); + freevalue(&div); + div = tmp2; + } } S_FUNC VALUE f_bern(VALUE *vp) { - VALUE res; + VALUE res; - if (vp->v_type != V_NUM || qisfrac(vp->v_num)) - return error_value(E_BERN); + if (vp->v_type != V_NUM || qisfrac(vp->v_num)) + return error_value(E_BERN); - res.v_subtype = V_NOSUBTYPE; - res.v_type = V_NUM; - res.v_num = qbern(vp->v_num->num); - if (res.v_num == NULL) - return error_value(E_BERN); - return res; + res.v_subtype = V_NOSUBTYPE; + res.v_type = V_NUM; + res.v_num = qbern(vp->v_num->num); + if (res.v_num == NULL) + return error_value(E_BERN); + return res; } S_FUNC VALUE f_freebern(void) { - VALUE res; + VALUE res; - qfreebern(); - res.v_type = V_NULL; - res.v_subtype = V_NOSUBTYPE; - return res; + qfreebern(); + res.v_type = V_NULL; + res.v_subtype = V_NOSUBTYPE; + return res; } S_FUNC VALUE f_euler(VALUE *vp) { - VALUE res; + VALUE res; - if (vp->v_type!=V_NUM || qisfrac(vp->v_num)) - return error_value(E_EULER); - res.v_subtype = V_NOSUBTYPE; - res.v_type = V_NUM; - res.v_num = qeuler(vp->v_num->num); - if (res.v_num == NULL) - return error_value(E_EULER); - return res; + if (vp->v_type!=V_NUM || qisfrac(vp->v_num)) + return error_value(E_EULER); + res.v_subtype = V_NOSUBTYPE; + res.v_type = V_NUM; + res.v_num = qeuler(vp->v_num->num); + if (res.v_num == NULL) + return error_value(E_EULER); + return res; } S_FUNC VALUE f_freeeuler(void) { - VALUE res; + VALUE res; - qfreeeuler(); - res.v_type = V_NULL; - res.v_subtype = V_NOSUBTYPE; - return res; + qfreeeuler(); + res.v_type = V_NULL; + res.v_subtype = V_NOSUBTYPE; + return res; } S_FUNC VALUE f_catalan(VALUE *vp) { - VALUE res; + VALUE res; - if (vp->v_type!=V_NUM || qisfrac(vp->v_num) || zge31b(vp->v_num->num)) - return error_value(E_CTLN); - res.v_type = V_NUM; - res.v_subtype = V_NOSUBTYPE; - res.v_num = qcatalan(vp->v_num); - if (res.v_num == NULL) - return error_value(E_CTLN); - return res; + if (vp->v_type!=V_NUM || qisfrac(vp->v_num) || zge31b(vp->v_num->num)) + return error_value(E_CTLN); + res.v_type = V_NUM; + res.v_subtype = V_NOSUBTYPE; + res.v_num = qcatalan(vp->v_num); + if (res.v_num == NULL) + return error_value(E_CTLN); + return res; } S_FUNC VALUE f_arg(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *err; + VALUE result; + COMPLEX *c; + NUMBER *err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given as a NUMBER and != 0. - */ - err = conf->epsilon; - if (count == 2) { - if (vals[1]->v_type != V_NUM || qiszero(vals[1]->v_num)) { - return error_value(E_ARG_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given as a NUMBER and != 0. + */ + err = conf->epsilon; + if (count == 2) { + if (vals[1]->v_type != V_NUM || qiszero(vals[1]->v_num)) { + return error_value(E_ARG_1); + } + err = vals[1]->v_num; + } - /* - * compute argument (the angle or phase) of a complex number to a given error tolerance - */ - result.v_type = V_NUM; - switch (vals[0]->v_type) { - case V_NUM: - if (qisneg(vals[0]->v_num)) - result.v_num = qpi(err); - else - result.v_num = qlink(&_qzero_); - break; - case V_COM: - c = vals[0]->v_com; - if (ciszero(c)) - result.v_num = qlink(&_qzero_); - else - result.v_num = qatan2(c->imag, c->real, err); - break; - default: - return error_value(E_ARG_2); - } - return result; + /* + * compute argument (the angle or phase) of a complex number to a given error tolerance + */ + result.v_type = V_NUM; + switch (vals[0]->v_type) { + case V_NUM: + if (qisneg(vals[0]->v_num)) + result.v_num = qpi(err); + else + result.v_num = qlink(&_qzero_); + break; + case V_COM: + c = vals[0]->v_com; + if (ciszero(c)) + result.v_num = qlink(&_qzero_); + else + result.v_num = qatan2(c->imag, c->real, err); + break; + default: + return error_value(E_ARG_2); + } + return result; } S_FUNC NUMBER * f_legtoleg(NUMBER *val1, NUMBER *val2) { - /* qlegtoleg() performs the val2 != 0 check */ - return qlegtoleg(val1, val2, false); + /* qlegtoleg() performs the val2 != 0 check */ + return qlegtoleg(val1, val2, false); } S_FUNC NUMBER * f_trunc(int count, NUMBER **vals) { - NUMBER *val; + NUMBER *val; - val = qlink(&_qzero_); - if (count == 2) - val = vals[1]; - return qtrunc(*vals, val); + val = qlink(&_qzero_); + if (count == 2) + val = vals[1]; + return qtrunc(*vals, val); } S_FUNC VALUE f_bround(int count, VALUE **vals) { - VALUE tmp1, tmp2, res; + VALUE tmp1, tmp2, res; - /* initialize VALUEs */ - res.v_subtype = V_NOSUBTYPE; - tmp1.v_subtype = V_NOSUBTYPE; - tmp2.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + res.v_subtype = V_NOSUBTYPE; + tmp1.v_subtype = V_NOSUBTYPE; + tmp2.v_subtype = V_NOSUBTYPE; - if (count > 2) - tmp2 = *vals[2]; - else - tmp2.v_type = V_NULL; - if (count > 1) - tmp1 = *vals[1]; - else - tmp1.v_type = V_NULL; - broundvalue(vals[0], &tmp1, &tmp2, &res); - return res; + if (count > 2) + tmp2 = *vals[2]; + else + tmp2.v_type = V_NULL; + if (count > 1) + tmp1 = *vals[1]; + else + tmp1.v_type = V_NULL; + broundvalue(vals[0], &tmp1, &tmp2, &res); + return res; } S_FUNC VALUE f_appr(int count, VALUE **vals) { - VALUE tmp1, tmp2, res; + VALUE tmp1, tmp2, res; - /* initialize VALUEs */ - res.v_subtype = V_NOSUBTYPE; - tmp1.v_subtype = V_NOSUBTYPE; - tmp2.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + res.v_subtype = V_NOSUBTYPE; + tmp1.v_subtype = V_NOSUBTYPE; + tmp2.v_subtype = V_NOSUBTYPE; - if (count > 2) - copyvalue(vals[2], &tmp2); - else - tmp2.v_type = V_NULL; - if (count > 1) - copyvalue(vals[1], &tmp1); - else - tmp1.v_type = V_NULL; - apprvalue(vals[0], &tmp1, &tmp2, &res); - freevalue(&tmp1); - freevalue(&tmp2); - return res; + if (count > 2) + copyvalue(vals[2], &tmp2); + else + tmp2.v_type = V_NULL; + if (count > 1) + copyvalue(vals[1], &tmp1); + else + tmp1.v_type = V_NULL; + apprvalue(vals[0], &tmp1, &tmp2, &res); + freevalue(&tmp1); + freevalue(&tmp2); + return res; } S_FUNC VALUE f_round(int count, VALUE **vals) { - VALUE tmp1, tmp2, res; + VALUE tmp1, tmp2, res; - /* initialize VALUEs */ - res.v_subtype = V_NOSUBTYPE; - tmp1.v_subtype = V_NOSUBTYPE; - tmp2.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + res.v_subtype = V_NOSUBTYPE; + tmp1.v_subtype = V_NOSUBTYPE; + tmp2.v_subtype = V_NOSUBTYPE; - if (count > 2) - tmp2 = *vals[2]; - else - tmp2.v_type = V_NULL; - if (count > 1) - tmp1 = *vals[1]; - else - tmp1.v_type = V_NULL; - roundvalue(vals[0], &tmp1, &tmp2, &res); - return res; + if (count > 2) + tmp2 = *vals[2]; + else + tmp2.v_type = V_NULL; + if (count > 1) + tmp1 = *vals[1]; + else + tmp1.v_type = V_NULL; + roundvalue(vals[0], &tmp1, &tmp2, &res); + return res; } S_FUNC NUMBER * f_btrunc(int count, NUMBER **vals) { - NUMBER *val; + NUMBER *val; - val = qlink(&_qzero_); - if (count == 2) - val = vals[1]; - return qbtrunc(*vals, val); + val = qlink(&_qzero_); + if (count == 2) + val = vals[1]; + return qbtrunc(*vals, val); } S_FUNC VALUE f_quo(int count, VALUE **vals) { - VALUE tmp, res; + VALUE tmp, res; - /* initialize VALUEs */ - res.v_subtype = V_NOSUBTYPE; - tmp.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + res.v_subtype = V_NOSUBTYPE; + tmp.v_subtype = V_NOSUBTYPE; - if (count > 2) - tmp = *vals[2]; - else - tmp.v_type = V_NULL; - quovalue(vals[0], vals[1], &tmp, &res); - return res; + if (count > 2) + tmp = *vals[2]; + else + tmp.v_type = V_NULL; + quovalue(vals[0], vals[1], &tmp, &res); + return res; } S_FUNC VALUE f_mod(int count, VALUE **vals) { - VALUE tmp, res; + VALUE tmp, res; - /* initialize VALUEs */ - res.v_subtype = V_NOSUBTYPE; - tmp.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + res.v_subtype = V_NOSUBTYPE; + tmp.v_subtype = V_NOSUBTYPE; - if (count > 2) - tmp = *vals[2]; - else - tmp.v_type = V_NULL; - modvalue(vals[0], vals[1], &tmp, &res); - return res; + if (count > 2) + tmp = *vals[2]; + else + tmp.v_type = V_NULL; + modvalue(vals[0], vals[1], &tmp, &res); + return res; } S_FUNC VALUE f_quomod(int count, VALUE **vals) { - VALUE *v1, *v2, *v3, *v4, *v5; - VALUE result; - long rnd; - bool res; - short s3, s4; /* to preserve subtypes of v3, v4 */ + VALUE *v1, *v2, *v3, *v4, *v5; + VALUE result; + long rnd; + bool res; + short s3, s4; /* to preserve subtypes of v3, v4 */ - v1 = vals[0]; - v2 = vals[1]; - v3 = vals[2]; - v4 = vals[3]; + v1 = vals[0]; + v2 = vals[1]; + v3 = vals[2]; + v4 = vals[3]; - if (v3->v_type != V_ADDR || v4->v_type != V_ADDR || - v3->v_addr == v4->v_addr) - return error_value(E_QUOMOD_1); - if (count == 5) { - v5 = vals[4]; - if (v5->v_type == V_ADDR) - v5 = v5->v_addr; - if (v5->v_type != V_NUM || qisfrac(v5->v_num) || - qisneg(v5->v_num) || zge31b(v5->v_num->num)) - return error_value(E_QUOMOD_2); - rnd = qtoi(v5->v_num); - } else - rnd = conf->quomod; + if (v3->v_type != V_ADDR || v4->v_type != V_ADDR || + v3->v_addr == v4->v_addr) + return error_value(E_QUOMOD_1); + if (count == 5) { + v5 = vals[4]; + if (v5->v_type == V_ADDR) + v5 = v5->v_addr; + if (v5->v_type != V_NUM || qisfrac(v5->v_num) || + qisneg(v5->v_num) || zge31b(v5->v_num->num)) + return error_value(E_QUOMOD_2); + rnd = qtoi(v5->v_num); + } else + rnd = conf->quomod; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - v3 = v3->v_addr; - v4 = v4->v_addr; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + v3 = v3->v_addr; + v4 = v4->v_addr; - if (v1->v_type != V_NUM || v2->v_type != V_NUM || - (v3->v_type != V_NUM && v3->v_type != V_NULL) || - (v4->v_type != V_NUM && v4->v_type != V_NULL)) - return error_value(E_QUOMOD_2); + if (v1->v_type != V_NUM || v2->v_type != V_NUM || + (v3->v_type != V_NUM && v3->v_type != V_NULL) || + (v4->v_type != V_NUM && v4->v_type != V_NULL)) + return error_value(E_QUOMOD_2); - s3 = v3->v_subtype; - s4 = v4->v_subtype; + s3 = v3->v_subtype; + s4 = v4->v_subtype; - if ((s3 | s4) & V_NOASSIGNTO) - return error_value(E_QUOMOD_3); + if ((s3 | s4) & V_NOASSIGNTO) + return error_value(E_QUOMOD_3); - freevalue(v3); - freevalue(v4); + freevalue(v3); + freevalue(v4); - v3->v_type = V_NUM; - v4->v_type = V_NUM; + v3->v_type = V_NUM; + v4->v_type = V_NUM; - v3->v_subtype = s3; - v4->v_subtype = s4; + v3->v_subtype = s3; + v4->v_subtype = s4; - res = qquomod(v1->v_num, v2->v_num, &v3->v_num, &v4->v_num, rnd); - result.v_type = V_NUM; - result.v_subtype = V_NOSUBTYPE; - result.v_num = res ? qlink(&_qone_) : qlink(&_qzero_); - return result; + res = qquomod(v1->v_num, v2->v_num, &v3->v_num, &v4->v_num, rnd); + result.v_type = V_NUM; + result.v_subtype = V_NOSUBTYPE; + result.v_num = res ? qlink(&_qone_) : qlink(&_qzero_); + return result; } S_FUNC VALUE f_d2dms(int count, VALUE **vals) { - VALUE *v1, *v2, *v3, *v4, *v5; - NUMBER *tmp, *tmp_m; - VALUE result; - long rnd; - short s2, s3, s4; /* to preserve subtypes of v2, v3, v4 */ + VALUE *v1, *v2, *v3, *v4, *v5; + NUMBER *tmp, *tmp_m; + VALUE result; + long rnd; + short s2, s3, s4; /* to preserve subtypes of v2, v3, v4 */ - /* collect required args */ - v1 = vals[0]; - v2 = vals[1]; - v3 = vals[2]; - v4 = vals[3]; + /* collect required args */ + v1 = vals[0]; + v2 = vals[1]; + v3 = vals[2]; + v4 = vals[3]; - /* determine rounding mode */ - if (count == 5) { - v5 = vals[4]; - if (v5->v_type == V_ADDR) { - v5 = v5->v_addr; - } - if (v5->v_type != V_NUM || qisfrac(v5->v_num) || - qisneg(v5->v_num) || zge31b(v5->v_num->num)) { - return error_value(E_D2DMS_4); - } - rnd = qtoi(v5->v_num); - } else { - rnd = conf->quomod; - } + /* determine rounding mode */ + if (count == 5) { + v5 = vals[4]; + if (v5->v_type == V_ADDR) { + v5 = v5->v_addr; + } + if (v5->v_type != V_NUM || qisfrac(v5->v_num) || + qisneg(v5->v_num) || zge31b(v5->v_num->num)) { + return error_value(E_D2DMS_4); + } + rnd = qtoi(v5->v_num); + } else { + rnd = conf->quomod; + } - /* type parse args */ - if (v2->v_type != V_ADDR || v3->v_type != V_ADDR || - v4->v_type != V_ADDR) { - return error_value(E_D2DMS_1); - } - if (v1->v_type == V_ADDR) { - v1 = v1->v_addr; - } - v2 = v2->v_addr; - v3 = v3->v_addr; - v4 = v4->v_addr; - if (v1->v_type != V_NUM || - (v2->v_type != V_NUM && v2->v_type != V_NULL) || - (v3->v_type != V_NUM && v3->v_type != V_NULL) || - (v4->v_type != V_NUM && v4->v_type != V_NULL)) { - return error_value(E_D2DMS_2); - } + /* type parse args */ + if (v2->v_type != V_ADDR || v3->v_type != V_ADDR || + v4->v_type != V_ADDR) { + return error_value(E_D2DMS_1); + } + if (v1->v_type == V_ADDR) { + v1 = v1->v_addr; + } + v2 = v2->v_addr; + v3 = v3->v_addr; + v4 = v4->v_addr; + if (v1->v_type != V_NUM || + (v2->v_type != V_NUM && v2->v_type != V_NULL) || + (v3->v_type != V_NUM && v3->v_type != V_NULL) || + (v4->v_type != V_NUM && v4->v_type != V_NULL)) { + return error_value(E_D2DMS_2); + } - /* remember arg subtypes */ - s2 = v2->v_subtype; - s3 = v3->v_subtype; - s4 = v4->v_subtype; - if ((s2 | s3 | s4) & V_NOASSIGNTO) { - return error_value(E_D2DMS_3); - } + /* remember arg subtypes */ + s2 = v2->v_subtype; + s3 = v3->v_subtype; + s4 = v4->v_subtype; + if ((s2 | s3 | s4) & V_NOASSIGNTO) { + return error_value(E_D2DMS_3); + } - /* free old args that will be modified */ - freevalue(v2); - freevalue(v3); - freevalue(v4); + /* free old args that will be modified */ + freevalue(v2); + freevalue(v3); + freevalue(v4); - /* set args that will be modified */ - v2->v_type = V_NUM; - v3->v_type = V_NUM; - v4->v_type = V_NUM; + /* set args that will be modified */ + v2->v_type = V_NUM; + v3->v_type = V_NUM; + v4->v_type = V_NUM; - /* restore arg subtypes */ - v2->v_subtype = s2; - v3->v_subtype = s3; - v4->v_subtype = s4; + /* restore arg subtypes */ + v2->v_subtype = s2; + v3->v_subtype = s3; + v4->v_subtype = s4; - /* - * calculate the normalized return value - * - * return_value = mod(degs, 360, rnd); - */ - result.v_type = v1->v_type; - result.v_subtype = v1->v_subtype; - result.v_num = qmod(v1->v_num, &_qthreesixty, rnd); + /* + * calculate the normalized return value + * + * return_value = mod(degs, 360, rnd); + */ + result.v_type = v1->v_type; + result.v_subtype = v1->v_subtype; + result.v_num = qmod(v1->v_num, &_qthreesixty, rnd); - /* - * integer number of degrees - * - * d = int(return_value); - */ - v2->v_num = qint(result.v_num); + /* + * integer number of degrees + * + * d = int(return_value); + */ + v2->v_num = qint(result.v_num); - /* - * integer number of minutes - * - * tmp = return_value - d; - * tmp_m = tmp * 60; - * free(tmp); - * m = int(tmp_m); - */ - tmp = qsub(result.v_num, v2->v_num); - tmp_m = qmuli(tmp, 60); - qfree(tmp); - v3->v_num = qint(tmp_m); + /* + * integer number of minutes + * + * tmp = return_value - d; + * tmp_m = tmp * 60; + * free(tmp); + * m = int(tmp_m); + */ + tmp = qsub(result.v_num, v2->v_num); + tmp_m = qmuli(tmp, 60); + qfree(tmp); + v3->v_num = qint(tmp_m); - /* - * number of seconds - * - * tmp = tmp_m - m; - * free(tmp_m); - * s = tmp * 60; - * free(tmp); - */ - tmp = qsub(tmp_m, v3->v_num); - qfree(tmp_m); - v4->v_num = qmuli(tmp, 60); - qfree(tmp); + /* + * number of seconds + * + * tmp = tmp_m - m; + * free(tmp_m); + * s = tmp * 60; + * free(tmp); + */ + tmp = qsub(tmp_m, v3->v_num); + qfree(tmp_m); + v4->v_num = qmuli(tmp, 60); + qfree(tmp); - /* - * return the normalized value previously calculated - */ - return result; + /* + * return the normalized value previously calculated + */ + return result; } S_FUNC VALUE f_d2dm(int count, VALUE **vals) { - VALUE *v1, *v2, *v3, *v4; - NUMBER *tmp; - VALUE result; - long rnd; - short s2, s3; /* to preserve subtypes of v2, v3 */ + VALUE *v1, *v2, *v3, *v4; + NUMBER *tmp; + VALUE result; + long rnd; + short s2, s3; /* to preserve subtypes of v2, v3 */ - /* collect required args */ - v1 = vals[0]; - v2 = vals[1]; - v3 = vals[2]; + /* collect required args */ + v1 = vals[0]; + v2 = vals[1]; + v3 = vals[2]; - /* determine rounding mode */ - if (count == 4) { - v4 = vals[3]; - if (v4->v_type == V_ADDR) { - v4 = v4->v_addr; - } - if (v4->v_type != V_NUM || qisfrac(v4->v_num) || - qisneg(v4->v_num) || zge31b(v4->v_num->num)) { - return error_value(E_D2DM_4); - } - rnd = qtoi(v4->v_num); - } else { - rnd = conf->quomod; - } + /* determine rounding mode */ + if (count == 4) { + v4 = vals[3]; + if (v4->v_type == V_ADDR) { + v4 = v4->v_addr; + } + if (v4->v_type != V_NUM || qisfrac(v4->v_num) || + qisneg(v4->v_num) || zge31b(v4->v_num->num)) { + return error_value(E_D2DM_4); + } + rnd = qtoi(v4->v_num); + } else { + rnd = conf->quomod; + } - /* type parse args */ - if (v2->v_type != V_ADDR || v3->v_type != V_ADDR) { - return error_value(E_D2DM_1); - } - if (v1->v_type == V_ADDR) { - v1 = v1->v_addr; - } - v2 = v2->v_addr; - v3 = v3->v_addr; - if (v1->v_type != V_NUM || - (v2->v_type != V_NUM && v2->v_type != V_NULL) || - (v3->v_type != V_NUM && v3->v_type != V_NULL)) { - return error_value(E_D2DM_2); - } + /* type parse args */ + if (v2->v_type != V_ADDR || v3->v_type != V_ADDR) { + return error_value(E_D2DM_1); + } + if (v1->v_type == V_ADDR) { + v1 = v1->v_addr; + } + v2 = v2->v_addr; + v3 = v3->v_addr; + if (v1->v_type != V_NUM || + (v2->v_type != V_NUM && v2->v_type != V_NULL) || + (v3->v_type != V_NUM && v3->v_type != V_NULL)) { + return error_value(E_D2DM_2); + } - /* remember arg subtypes */ - s2 = v2->v_subtype; - s3 = v3->v_subtype; - if ((s2 | s3) & V_NOASSIGNTO) { - return error_value(E_D2DM_3); - } + /* remember arg subtypes */ + s2 = v2->v_subtype; + s3 = v3->v_subtype; + if ((s2 | s3) & V_NOASSIGNTO) { + return error_value(E_D2DM_3); + } - /* free old args that will be modified */ - freevalue(v2); - freevalue(v3); + /* free old args that will be modified */ + freevalue(v2); + freevalue(v3); - /* set args that will be modified */ - v2->v_type = V_NUM; - v3->v_type = V_NUM; + /* set args that will be modified */ + v2->v_type = V_NUM; + v3->v_type = V_NUM; - /* restore arg subtypes */ - v2->v_subtype = s2; - v3->v_subtype = s3; + /* restore arg subtypes */ + v2->v_subtype = s2; + v3->v_subtype = s3; - /* - * calculate the normalized return value - * - * return_value = mod(degs, 360, rnd); - */ - result.v_type = v1->v_type; - result.v_subtype = v1->v_subtype; - result.v_num = qmod(v1->v_num, &_qthreesixty, rnd); + /* + * calculate the normalized return value + * + * return_value = mod(degs, 360, rnd); + */ + result.v_type = v1->v_type; + result.v_subtype = v1->v_subtype; + result.v_num = qmod(v1->v_num, &_qthreesixty, rnd); - /* - * integer number of degrees - * - * d = int(return_value); - */ - v2->v_num = qint(result.v_num); + /* + * integer number of degrees + * + * d = int(return_value); + */ + v2->v_num = qint(result.v_num); - /* - * integer number of minutes - * - * tmp = return_value - d; - * m = tmp * 60; - * free(tmp); - */ - tmp = qsub(result.v_num, v2->v_num); - v3->v_num = qmuli(tmp, 60); - qfree(tmp); + /* + * integer number of minutes + * + * tmp = return_value - d; + * m = tmp * 60; + * free(tmp); + */ + tmp = qsub(result.v_num, v2->v_num); + v3->v_num = qmuli(tmp, 60); + qfree(tmp); - /* - * return the normalized value previously calculated - */ - return result; + /* + * return the normalized value previously calculated + */ + return result; } S_FUNC VALUE f_g2gms(int count, VALUE **vals) { - VALUE *v1, *v2, *v3, *v4, *v5; - NUMBER *tmp, *tmp_m; - VALUE result; - long rnd; - short s2, s3, s4; /* to preserve subtypes of v2, v3, v4 */ + VALUE *v1, *v2, *v3, *v4, *v5; + NUMBER *tmp, *tmp_m; + VALUE result; + long rnd; + short s2, s3, s4; /* to preserve subtypes of v2, v3, v4 */ - /* collect required args */ - v1 = vals[0]; - v2 = vals[1]; - v3 = vals[2]; - v4 = vals[3]; + /* collect required args */ + v1 = vals[0]; + v2 = vals[1]; + v3 = vals[2]; + v4 = vals[3]; - /* determine rounding mode */ - if (count == 5) { - v5 = vals[4]; - if (v5->v_type == V_ADDR) { - v5 = v5->v_addr; - } - if (v5->v_type != V_NUM || qisfrac(v5->v_num) || - qisneg(v5->v_num) || zge31b(v5->v_num->num)) { - return error_value(E_G2GMS_4); - } - rnd = qtoi(v5->v_num); - } else { - rnd = conf->quomod; - } + /* determine rounding mode */ + if (count == 5) { + v5 = vals[4]; + if (v5->v_type == V_ADDR) { + v5 = v5->v_addr; + } + if (v5->v_type != V_NUM || qisfrac(v5->v_num) || + qisneg(v5->v_num) || zge31b(v5->v_num->num)) { + return error_value(E_G2GMS_4); + } + rnd = qtoi(v5->v_num); + } else { + rnd = conf->quomod; + } - /* type parse args */ - if (v2->v_type != V_ADDR || v3->v_type != V_ADDR || - v4->v_type != V_ADDR) { - return error_value(E_G2GMS_1); - } - if (v1->v_type == V_ADDR) { - v1 = v1->v_addr; - } - v2 = v2->v_addr; - v3 = v3->v_addr; - v4 = v4->v_addr; - if (v1->v_type != V_NUM || - (v2->v_type != V_NUM && v2->v_type != V_NULL) || - (v3->v_type != V_NUM && v3->v_type != V_NULL) || - (v4->v_type != V_NUM && v4->v_type != V_NULL)) { - return error_value(E_G2GMS_2); - } + /* type parse args */ + if (v2->v_type != V_ADDR || v3->v_type != V_ADDR || + v4->v_type != V_ADDR) { + return error_value(E_G2GMS_1); + } + if (v1->v_type == V_ADDR) { + v1 = v1->v_addr; + } + v2 = v2->v_addr; + v3 = v3->v_addr; + v4 = v4->v_addr; + if (v1->v_type != V_NUM || + (v2->v_type != V_NUM && v2->v_type != V_NULL) || + (v3->v_type != V_NUM && v3->v_type != V_NULL) || + (v4->v_type != V_NUM && v4->v_type != V_NULL)) { + return error_value(E_G2GMS_2); + } - /* remember arg subtypes */ - s2 = v2->v_subtype; - s3 = v3->v_subtype; - s4 = v4->v_subtype; - if ((s2 | s3 | s4) & V_NOASSIGNTO) { - return error_value(E_G2GMS_3); - } + /* remember arg subtypes */ + s2 = v2->v_subtype; + s3 = v3->v_subtype; + s4 = v4->v_subtype; + if ((s2 | s3 | s4) & V_NOASSIGNTO) { + return error_value(E_G2GMS_3); + } - /* free old args that will be modified */ - freevalue(v2); - freevalue(v3); - freevalue(v4); + /* free old args that will be modified */ + freevalue(v2); + freevalue(v3); + freevalue(v4); - /* set args that will be modified */ - v2->v_type = V_NUM; - v3->v_type = V_NUM; - v4->v_type = V_NUM; + /* set args that will be modified */ + v2->v_type = V_NUM; + v3->v_type = V_NUM; + v4->v_type = V_NUM; - /* restore arg subtypes */ - v2->v_subtype = s2; - v3->v_subtype = s3; - v4->v_subtype = s4; + /* restore arg subtypes */ + v2->v_subtype = s2; + v3->v_subtype = s3; + v4->v_subtype = s4; - /* - * calculate the normalized return value - * - * return_value = mod(grads, 400, rnd); - */ - result.v_type = v1->v_type; - result.v_subtype = v1->v_subtype; - result.v_num = qmod(v1->v_num, &_qfourhundred, rnd); + /* + * calculate the normalized return value + * + * return_value = mod(grads, 400, rnd); + */ + result.v_type = v1->v_type; + result.v_subtype = v1->v_subtype; + result.v_num = qmod(v1->v_num, &_qfourhundred, rnd); - /* - * integer number of gradians - * - * g = int(return_value); - */ - v2->v_num = qint(result.v_num); + /* + * integer number of gradians + * + * g = int(return_value); + */ + v2->v_num = qint(result.v_num); - /* - * integer number of minutes - * - * tmp = return_value - g; - * tmp_m = tmp * 60; - * free(tmp); - * m = int(tmp_m); - */ - tmp = qsub(result.v_num, v2->v_num); - tmp_m = qmuli(tmp, 60); - qfree(tmp); - v3->v_num = qint(tmp_m); + /* + * integer number of minutes + * + * tmp = return_value - g; + * tmp_m = tmp * 60; + * free(tmp); + * m = int(tmp_m); + */ + tmp = qsub(result.v_num, v2->v_num); + tmp_m = qmuli(tmp, 60); + qfree(tmp); + v3->v_num = qint(tmp_m); - /* - * number of seconds - * - * tmp = tmp_m - m; - * free(tmp_m); - * s = tmp * 60; - * free(tmp); - */ - tmp = qsub(tmp_m, v3->v_num); - qfree(tmp_m); - v4->v_num = qmuli(tmp, 60); - qfree(tmp); + /* + * number of seconds + * + * tmp = tmp_m - m; + * free(tmp_m); + * s = tmp * 60; + * free(tmp); + */ + tmp = qsub(tmp_m, v3->v_num); + qfree(tmp_m); + v4->v_num = qmuli(tmp, 60); + qfree(tmp); - /* - * return the normalized value previously calculated - */ - return result; + /* + * return the normalized value previously calculated + */ + return result; } S_FUNC VALUE f_g2gm(int count, VALUE **vals) { - VALUE *v1, *v2, *v3, *v4; - NUMBER *tmp; - VALUE result; - long rnd; - short s2, s3; /* to preserve subtypes of v2, v3 */ + VALUE *v1, *v2, *v3, *v4; + NUMBER *tmp; + VALUE result; + long rnd; + short s2, s3; /* to preserve subtypes of v2, v3 */ - /* collect required args */ - v1 = vals[0]; - v2 = vals[1]; - v3 = vals[2]; + /* collect required args */ + v1 = vals[0]; + v2 = vals[1]; + v3 = vals[2]; - /* determine rounding mode */ - if (count == 4) { - v4 = vals[3]; - if (v4->v_type == V_ADDR) { - v4 = v4->v_addr; - } - if (v4->v_type != V_NUM || qisfrac(v4->v_num) || - qisneg(v4->v_num) || zge31b(v4->v_num->num)) { - return error_value(E_G2GM_4); - } - rnd = qtoi(v4->v_num); - } else { - rnd = conf->quomod; - } + /* determine rounding mode */ + if (count == 4) { + v4 = vals[3]; + if (v4->v_type == V_ADDR) { + v4 = v4->v_addr; + } + if (v4->v_type != V_NUM || qisfrac(v4->v_num) || + qisneg(v4->v_num) || zge31b(v4->v_num->num)) { + return error_value(E_G2GM_4); + } + rnd = qtoi(v4->v_num); + } else { + rnd = conf->quomod; + } - /* type parse args */ - if (v2->v_type != V_ADDR || v3->v_type != V_ADDR) { - return error_value(E_G2GM_1); - } - if (v1->v_type == V_ADDR) { - v1 = v1->v_addr; - } - v2 = v2->v_addr; - v3 = v3->v_addr; - if (v1->v_type != V_NUM || - (v2->v_type != V_NUM && v2->v_type != V_NULL) || - (v3->v_type != V_NUM && v3->v_type != V_NULL)) { - return error_value(E_G2GM_2); - } + /* type parse args */ + if (v2->v_type != V_ADDR || v3->v_type != V_ADDR) { + return error_value(E_G2GM_1); + } + if (v1->v_type == V_ADDR) { + v1 = v1->v_addr; + } + v2 = v2->v_addr; + v3 = v3->v_addr; + if (v1->v_type != V_NUM || + (v2->v_type != V_NUM && v2->v_type != V_NULL) || + (v3->v_type != V_NUM && v3->v_type != V_NULL)) { + return error_value(E_G2GM_2); + } - /* remember arg subtypes */ - s2 = v2->v_subtype; - s3 = v3->v_subtype; - if ((s2 | s3) & V_NOASSIGNTO) { - return error_value(E_G2GM_3); - } + /* remember arg subtypes */ + s2 = v2->v_subtype; + s3 = v3->v_subtype; + if ((s2 | s3) & V_NOASSIGNTO) { + return error_value(E_G2GM_3); + } - /* free old args that will be modified */ - freevalue(v2); - freevalue(v3); + /* free old args that will be modified */ + freevalue(v2); + freevalue(v3); - /* set args that will be modified */ - v2->v_type = V_NUM; - v3->v_type = V_NUM; + /* set args that will be modified */ + v2->v_type = V_NUM; + v3->v_type = V_NUM; - /* restore arg subtypes */ - v2->v_subtype = s2; - v3->v_subtype = s3; + /* restore arg subtypes */ + v2->v_subtype = s2; + v3->v_subtype = s3; - /* - * calculate the normalized return value - * - * return_value = mod(grads, 400, rnd); - */ - result.v_type = v1->v_type; - result.v_subtype = v1->v_subtype; - result.v_num = qmod(v1->v_num, &_qfourhundred, rnd); + /* + * calculate the normalized return value + * + * return_value = mod(grads, 400, rnd); + */ + result.v_type = v1->v_type; + result.v_subtype = v1->v_subtype; + result.v_num = qmod(v1->v_num, &_qfourhundred, rnd); - /* - * integer number of gradians - * - * g = int(return_value); - */ - v2->v_num = qint(result.v_num); + /* + * integer number of gradians + * + * g = int(return_value); + */ + v2->v_num = qint(result.v_num); - /* - * integer number of minutes - * - * tmp = return_value - g; - * m = tmp * 60; - * free(tmp); - */ - tmp = qsub(result.v_num, v2->v_num); - v3->v_num = qmuli(tmp, 60); - qfree(tmp); + /* + * integer number of minutes + * + * tmp = return_value - g; + * m = tmp * 60; + * free(tmp); + */ + tmp = qsub(result.v_num, v2->v_num); + v3->v_num = qmuli(tmp, 60); + qfree(tmp); - /* - * return the normalized value previously calculated - */ - return result; + /* + * return the normalized value previously calculated + */ + return result; } S_FUNC VALUE f_h2hms(int count, VALUE **vals) { - VALUE *v1, *v2, *v3, *v4, *v5; - NUMBER *tmp, *tmp_m; - VALUE result; - long rnd; - short s2, s3, s4; /* to preserve subtypes of v2, v3, v4 */ + VALUE *v1, *v2, *v3, *v4, *v5; + NUMBER *tmp, *tmp_m; + VALUE result; + long rnd; + short s2, s3, s4; /* to preserve subtypes of v2, v3, v4 */ - /* collect required args */ - v1 = vals[0]; - v2 = vals[1]; - v3 = vals[2]; - v4 = vals[3]; + /* collect required args */ + v1 = vals[0]; + v2 = vals[1]; + v3 = vals[2]; + v4 = vals[3]; - /* determine rounding mode */ - if (count == 5) { - v5 = vals[4]; - if (v5->v_type == V_ADDR) { - v5 = v5->v_addr; - } - if (v5->v_type != V_NUM || qisfrac(v5->v_num) || - qisneg(v5->v_num) || zge31b(v5->v_num->num)) { - return error_value(E_H2HMS_4); - } - rnd = qtoi(v5->v_num); - } else { - rnd = conf->quomod; - } + /* determine rounding mode */ + if (count == 5) { + v5 = vals[4]; + if (v5->v_type == V_ADDR) { + v5 = v5->v_addr; + } + if (v5->v_type != V_NUM || qisfrac(v5->v_num) || + qisneg(v5->v_num) || zge31b(v5->v_num->num)) { + return error_value(E_H2HMS_4); + } + rnd = qtoi(v5->v_num); + } else { + rnd = conf->quomod; + } - /* type parse args */ - if (v2->v_type != V_ADDR || v3->v_type != V_ADDR || - v4->v_type != V_ADDR) { - return error_value(E_H2HMS_1); - } - if (v1->v_type == V_ADDR) { - v1 = v1->v_addr; - } - v2 = v2->v_addr; - v3 = v3->v_addr; - v4 = v4->v_addr; - if (v1->v_type != V_NUM || - (v2->v_type != V_NUM && v2->v_type != V_NULL) || - (v3->v_type != V_NUM && v3->v_type != V_NULL) || - (v4->v_type != V_NUM && v4->v_type != V_NULL)) { - return error_value(E_H2HMS_2); - } + /* type parse args */ + if (v2->v_type != V_ADDR || v3->v_type != V_ADDR || + v4->v_type != V_ADDR) { + return error_value(E_H2HMS_1); + } + if (v1->v_type == V_ADDR) { + v1 = v1->v_addr; + } + v2 = v2->v_addr; + v3 = v3->v_addr; + v4 = v4->v_addr; + if (v1->v_type != V_NUM || + (v2->v_type != V_NUM && v2->v_type != V_NULL) || + (v3->v_type != V_NUM && v3->v_type != V_NULL) || + (v4->v_type != V_NUM && v4->v_type != V_NULL)) { + return error_value(E_H2HMS_2); + } - /* remember arg subtypes */ - s2 = v2->v_subtype; - s3 = v3->v_subtype; - s4 = v4->v_subtype; - if ((s2 | s3 | s4) & V_NOASSIGNTO) { - return error_value(E_H2HMS_3); - } + /* remember arg subtypes */ + s2 = v2->v_subtype; + s3 = v3->v_subtype; + s4 = v4->v_subtype; + if ((s2 | s3 | s4) & V_NOASSIGNTO) { + return error_value(E_H2HMS_3); + } - /* free old args that will be modified */ - freevalue(v2); - freevalue(v3); - freevalue(v4); + /* free old args that will be modified */ + freevalue(v2); + freevalue(v3); + freevalue(v4); - /* set args that will be modified */ - v2->v_type = V_NUM; - v3->v_type = V_NUM; - v4->v_type = V_NUM; + /* set args that will be modified */ + v2->v_type = V_NUM; + v3->v_type = V_NUM; + v4->v_type = V_NUM; - /* restore arg subtypes */ - v2->v_subtype = s2; - v3->v_subtype = s3; - v4->v_subtype = s4; + /* restore arg subtypes */ + v2->v_subtype = s2; + v3->v_subtype = s3; + v4->v_subtype = s4; - /* - * calculate the normalized return value - * - * return_value = mod(hours, 24, rnd); - */ - result.v_type = v1->v_type; - result.v_subtype = v1->v_subtype; - result.v_num = qmod(v1->v_num, &_qtwentyfour, rnd); + /* + * calculate the normalized return value + * + * return_value = mod(hours, 24, rnd); + */ + result.v_type = v1->v_type; + result.v_subtype = v1->v_subtype; + result.v_num = qmod(v1->v_num, &_qtwentyfour, rnd); - /* - * integer number of hours - * - * h = int(return_value); - */ - v2->v_num = qint(result.v_num); + /* + * integer number of hours + * + * h = int(return_value); + */ + v2->v_num = qint(result.v_num); - /* - * integer number of minutes - * - * tmp = return_value - h; - * tmp_m = tmp * 60; - * free(tmp); - * m = int(tmp_m); - */ - tmp = qsub(result.v_num, v2->v_num); - tmp_m = qmuli(tmp, 60); - qfree(tmp); - v3->v_num = qint(tmp_m); + /* + * integer number of minutes + * + * tmp = return_value - h; + * tmp_m = tmp * 60; + * free(tmp); + * m = int(tmp_m); + */ + tmp = qsub(result.v_num, v2->v_num); + tmp_m = qmuli(tmp, 60); + qfree(tmp); + v3->v_num = qint(tmp_m); - /* - * number of seconds - * - * tmp = tmp_m - m; - * free(tmp_m); - * s = tmp * 60; - * free(tmp); - */ - tmp = qsub(tmp_m, v3->v_num); - qfree(tmp_m); - v4->v_num = qmuli(tmp, 60); - qfree(tmp); + /* + * number of seconds + * + * tmp = tmp_m - m; + * free(tmp_m); + * s = tmp * 60; + * free(tmp); + */ + tmp = qsub(tmp_m, v3->v_num); + qfree(tmp_m); + v4->v_num = qmuli(tmp, 60); + qfree(tmp); - /* - * return the normalized value previously calculated - */ - return result; + /* + * return the normalized value previously calculated + */ + return result; } S_FUNC VALUE f_h2hm(int count, VALUE **vals) { - VALUE *v1, *v2, *v3, *v4; - NUMBER *tmp; - VALUE result; - long rnd; - short s2, s3; /* to preserve subtypes of v2, v3 */ + VALUE *v1, *v2, *v3, *v4; + NUMBER *tmp; + VALUE result; + long rnd; + short s2, s3; /* to preserve subtypes of v2, v3 */ - /* collect required args */ - v1 = vals[0]; - v2 = vals[1]; - v3 = vals[2]; + /* collect required args */ + v1 = vals[0]; + v2 = vals[1]; + v3 = vals[2]; - /* determine rounding mode */ - if (count == 4) { - v4 = vals[3]; - if (v4->v_type == V_ADDR) { - v4 = v4->v_addr; - } - if (v4->v_type != V_NUM || qisfrac(v4->v_num) || - qisneg(v4->v_num) || zge31b(v4->v_num->num)) { - return error_value(E_H2HM_4); - } - rnd = qtoi(v4->v_num); - } else { - rnd = conf->quomod; - } + /* determine rounding mode */ + if (count == 4) { + v4 = vals[3]; + if (v4->v_type == V_ADDR) { + v4 = v4->v_addr; + } + if (v4->v_type != V_NUM || qisfrac(v4->v_num) || + qisneg(v4->v_num) || zge31b(v4->v_num->num)) { + return error_value(E_H2HM_4); + } + rnd = qtoi(v4->v_num); + } else { + rnd = conf->quomod; + } - /* type parse args */ - if (v2->v_type != V_ADDR || v3->v_type != V_ADDR) { - return error_value(E_H2HM_1); - } - if (v1->v_type == V_ADDR) { - v1 = v1->v_addr; - } - v2 = v2->v_addr; - v3 = v3->v_addr; - if (v1->v_type != V_NUM || - (v2->v_type != V_NUM && v2->v_type != V_NULL) || - (v3->v_type != V_NUM && v3->v_type != V_NULL)) { - return error_value(E_H2HM_2); - } + /* type parse args */ + if (v2->v_type != V_ADDR || v3->v_type != V_ADDR) { + return error_value(E_H2HM_1); + } + if (v1->v_type == V_ADDR) { + v1 = v1->v_addr; + } + v2 = v2->v_addr; + v3 = v3->v_addr; + if (v1->v_type != V_NUM || + (v2->v_type != V_NUM && v2->v_type != V_NULL) || + (v3->v_type != V_NUM && v3->v_type != V_NULL)) { + return error_value(E_H2HM_2); + } - /* remember arg subtypes */ - s2 = v2->v_subtype; - s3 = v3->v_subtype; - if ((s2 | s3) & V_NOASSIGNTO) { - return error_value(E_H2HM_3); - } + /* remember arg subtypes */ + s2 = v2->v_subtype; + s3 = v3->v_subtype; + if ((s2 | s3) & V_NOASSIGNTO) { + return error_value(E_H2HM_3); + } - /* free old args that will be modified */ - freevalue(v2); - freevalue(v3); + /* free old args that will be modified */ + freevalue(v2); + freevalue(v3); - /* set args that will be modified */ - v2->v_type = V_NUM; - v3->v_type = V_NUM; + /* set args that will be modified */ + v2->v_type = V_NUM; + v3->v_type = V_NUM; - /* restore arg subtypes */ - v2->v_subtype = s2; - v3->v_subtype = s3; + /* restore arg subtypes */ + v2->v_subtype = s2; + v3->v_subtype = s3; - /* - * calculate the normalized return value - * - * return_value = mod(hours, 24, rnd); - */ - result.v_type = v1->v_type; - result.v_subtype = v1->v_subtype; - result.v_num = qmod(v1->v_num, &_qtwentyfour, rnd); + /* + * calculate the normalized return value + * + * return_value = mod(hours, 24, rnd); + */ + result.v_type = v1->v_type; + result.v_subtype = v1->v_subtype; + result.v_num = qmod(v1->v_num, &_qtwentyfour, rnd); - /* - * integer number of gradians - * - * h = int(return_value); - */ - v2->v_num = qint(result.v_num); + /* + * integer number of gradians + * + * h = int(return_value); + */ + v2->v_num = qint(result.v_num); - /* - * integer number of minutes - * - * tmp = return_value - h; - * m = tmp * 60; - * free(tmp); - */ - tmp = qsub(result.v_num, v2->v_num); - v3->v_num = qmuli(tmp, 60); - qfree(tmp); + /* + * integer number of minutes + * + * tmp = return_value - h; + * m = tmp * 60; + * free(tmp); + */ + tmp = qsub(result.v_num, v2->v_num); + v3->v_num = qmuli(tmp, 60); + qfree(tmp); - /* - * return the normalized value previously calculated - */ - return result; + /* + * return the normalized value previously calculated + */ + return result; } S_FUNC VALUE f_dms2d(int count, VALUE **vals) { - VALUE *v1, *v2, *v3, *v4; - NUMBER *tmp, *tmp2, *tmp3, *tmp4; - VALUE result; - long rnd; + VALUE *v1, *v2, *v3, *v4; + NUMBER *tmp, *tmp2, *tmp3, *tmp4; + VALUE result; + long rnd; - /* collect required args */ - v1 = vals[0]; - v2 = vals[1]; - v3 = vals[2]; + /* collect required args */ + v1 = vals[0]; + v2 = vals[1]; + v3 = vals[2]; - /* determine rounding mode */ - if (count == 4) { - v4 = vals[3]; - if (v4->v_type == V_ADDR) { - v4 = v4->v_addr; - } - if (v4->v_type != V_NUM || qisfrac(v4->v_num) || - qisneg(v4->v_num) || zge31b(v4->v_num->num)) { - return error_value(E_DMS2D_2); - } - rnd = qtoi(v4->v_num); - } else { - rnd = conf->quomod; - } + /* determine rounding mode */ + if (count == 4) { + v4 = vals[3]; + if (v4->v_type == V_ADDR) { + v4 = v4->v_addr; + } + if (v4->v_type != V_NUM || qisfrac(v4->v_num) || + qisneg(v4->v_num) || zge31b(v4->v_num->num)) { + return error_value(E_DMS2D_2); + } + rnd = qtoi(v4->v_num); + } else { + rnd = conf->quomod; + } - /* type parse args */ - if (v1->v_type != V_NUM || v2->v_type != V_NUM || - v3->v_type != V_NUM) { - return error_value(E_DMS2D_1); - } + /* type parse args */ + if (v1->v_type != V_NUM || v2->v_type != V_NUM || + v3->v_type != V_NUM) { + return error_value(E_DMS2D_1); + } - /* - * compute s/3600 - */ - tmp = qdivi(v3->v_num, 3600); + /* + * compute s/3600 + */ + tmp = qdivi(v3->v_num, 3600); - /* - * compute m/60 - */ - tmp2 = qdivi(v2->v_num, 60); + /* + * compute m/60 + */ + tmp2 = qdivi(v2->v_num, 60); - /* - * compute m/60 + s/3600 - */ - tmp3 = qqadd(tmp2, tmp); - qfree(tmp); - qfree(tmp2); + /* + * compute m/60 + s/3600 + */ + tmp3 = qqadd(tmp2, tmp); + qfree(tmp); + qfree(tmp2); - /* - * compute d + m/60 + s/3600 - */ - tmp4 = qqadd(v1->v_num, tmp3); - qfree(tmp3); + /* + * compute d + m/60 + s/3600 + */ + tmp4 = qqadd(v1->v_num, tmp3); + qfree(tmp3); - /* - * compute mod(d + m/60 + s/3600, 360, rnd); - */ - result.v_type = v1->v_type; - result.v_subtype = v1->v_subtype; - result.v_num = qmod(tmp4, &_qthreesixty, rnd); - qfree(tmp4); + /* + * compute mod(d + m/60 + s/3600, 360, rnd); + */ + result.v_type = v1->v_type; + result.v_subtype = v1->v_subtype; + result.v_num = qmod(tmp4, &_qthreesixty, rnd); + qfree(tmp4); - /* - * return mod(d + m/60 + s/3600, 360, rnd); - */ - return result; + /* + * return mod(d + m/60 + s/3600, 360, rnd); + */ + return result; } S_FUNC VALUE f_dm2d(int count, VALUE **vals) { - VALUE *v1, *v2, *v3; - NUMBER *tmp, *tmp2; - VALUE result; - long rnd; + VALUE *v1, *v2, *v3; + NUMBER *tmp, *tmp2; + VALUE result; + long rnd; - /* collect required args */ - v1 = vals[0]; - v2 = vals[1]; + /* collect required args */ + v1 = vals[0]; + v2 = vals[1]; - /* determine rounding mode */ - if (count == 3) { - v3 = vals[2]; - if (v3->v_type == V_ADDR) { - v3 = v3->v_addr; - } - if (v3->v_type != V_NUM || qisfrac(v3->v_num) || - qisneg(v3->v_num) || zge31b(v3->v_num->num)) { - return error_value(E_DM2D_2); - } - rnd = qtoi(v3->v_num); - } else { - rnd = conf->quomod; - } + /* determine rounding mode */ + if (count == 3) { + v3 = vals[2]; + if (v3->v_type == V_ADDR) { + v3 = v3->v_addr; + } + if (v3->v_type != V_NUM || qisfrac(v3->v_num) || + qisneg(v3->v_num) || zge31b(v3->v_num->num)) { + return error_value(E_DM2D_2); + } + rnd = qtoi(v3->v_num); + } else { + rnd = conf->quomod; + } - /* type parse args */ - if (v1->v_type != V_NUM || v2->v_type != V_NUM) { - return error_value(E_DM2D_1); - } + /* type parse args */ + if (v1->v_type != V_NUM || v2->v_type != V_NUM) { + return error_value(E_DM2D_1); + } - /* - * compute m/60 - */ - tmp = qdivi(v2->v_num, 60); + /* + * compute m/60 + */ + tmp = qdivi(v2->v_num, 60); - /* - * compute d + m/60 - */ - tmp2 = qqadd(v1->v_num, tmp); - qfree(tmp); + /* + * compute d + m/60 + */ + tmp2 = qqadd(v1->v_num, tmp); + qfree(tmp); - /* - * compute mod(d + m/60, 360, rnd); - */ - result.v_type = v1->v_type; - result.v_subtype = v1->v_subtype; - result.v_num = qmod(tmp2, &_qthreesixty, rnd); - qfree(tmp2); + /* + * compute mod(d + m/60, 360, rnd); + */ + result.v_type = v1->v_type; + result.v_subtype = v1->v_subtype; + result.v_num = qmod(tmp2, &_qthreesixty, rnd); + qfree(tmp2); - /* - * return mod(d + m/60, 360, rnd); - */ - return result; + /* + * return mod(d + m/60, 360, rnd); + */ + return result; } S_FUNC VALUE f_gms2g(int count, VALUE **vals) { - VALUE *v1, *v2, *v3, *v4; - NUMBER *tmp, *tmp2, *tmp3, *tmp4; - VALUE result; - long rnd; + VALUE *v1, *v2, *v3, *v4; + NUMBER *tmp, *tmp2, *tmp3, *tmp4; + VALUE result; + long rnd; - /* collect required args */ - v1 = vals[0]; - v2 = vals[1]; - v3 = vals[2]; + /* collect required args */ + v1 = vals[0]; + v2 = vals[1]; + v3 = vals[2]; - /* determine rounding mode */ - if (count == 4) { - v4 = vals[3]; - if (v4->v_type == V_ADDR) { - v4 = v4->v_addr; - } - if (v4->v_type != V_NUM || qisfrac(v4->v_num) || - qisneg(v4->v_num) || zge31b(v4->v_num->num)) { - return error_value(E_GMS2G_2); - } - rnd = qtoi(v4->v_num); - } else { - rnd = conf->quomod; - } + /* determine rounding mode */ + if (count == 4) { + v4 = vals[3]; + if (v4->v_type == V_ADDR) { + v4 = v4->v_addr; + } + if (v4->v_type != V_NUM || qisfrac(v4->v_num) || + qisneg(v4->v_num) || zge31b(v4->v_num->num)) { + return error_value(E_GMS2G_2); + } + rnd = qtoi(v4->v_num); + } else { + rnd = conf->quomod; + } - /* type parse args */ - if (v1->v_type != V_NUM || v2->v_type != V_NUM || - v3->v_type != V_NUM) { - return error_value(E_GMS2G_1); - } + /* type parse args */ + if (v1->v_type != V_NUM || v2->v_type != V_NUM || + v3->v_type != V_NUM) { + return error_value(E_GMS2G_1); + } - /* - * compute s/3600 - */ - tmp = qdivi(v3->v_num, 3600); + /* + * compute s/3600 + */ + tmp = qdivi(v3->v_num, 3600); - /* - * compute m/60 - */ - tmp2 = qdivi(v2->v_num, 60); + /* + * compute m/60 + */ + tmp2 = qdivi(v2->v_num, 60); - /* - * compute m/60 + s/3600 - */ - tmp3 = qqadd(tmp2, tmp); - qfree(tmp); - qfree(tmp2); + /* + * compute m/60 + s/3600 + */ + tmp3 = qqadd(tmp2, tmp); + qfree(tmp); + qfree(tmp2); - /* - * compute g + m/60 + s/3600 - */ - tmp4 = qqadd(v1->v_num, tmp3); - qfree(tmp3); + /* + * compute g + m/60 + s/3600 + */ + tmp4 = qqadd(v1->v_num, tmp3); + qfree(tmp3); - /* - * compute mod(g + m/60 + s/3600, 400, rnd); - */ - result.v_type = v1->v_type; - result.v_subtype = v1->v_subtype; - result.v_num = qmod(tmp4, &_qfourhundred, rnd); - qfree(tmp4); + /* + * compute mod(g + m/60 + s/3600, 400, rnd); + */ + result.v_type = v1->v_type; + result.v_subtype = v1->v_subtype; + result.v_num = qmod(tmp4, &_qfourhundred, rnd); + qfree(tmp4); - /* - * return mod(g + m/60 + s/3600, 400, rnd); - */ - return result; + /* + * return mod(g + m/60 + s/3600, 400, rnd); + */ + return result; } S_FUNC VALUE f_gm2g(int count, VALUE **vals) { - VALUE *v1, *v2, *v3; - NUMBER *tmp, *tmp2; - VALUE result; - long rnd; + VALUE *v1, *v2, *v3; + NUMBER *tmp, *tmp2; + VALUE result; + long rnd; - /* collect required args */ - v1 = vals[0]; - v2 = vals[1]; + /* collect required args */ + v1 = vals[0]; + v2 = vals[1]; - /* determine rounding mode */ - if (count == 3) { - v3 = vals[2]; - if (v3->v_type == V_ADDR) { - v3 = v3->v_addr; - } - if (v3->v_type != V_NUM || qisfrac(v3->v_num) || - qisneg(v3->v_num) || zge31b(v3->v_num->num)) { - return error_value(E_GM2G_2); - } - rnd = qtoi(v3->v_num); - } else { - rnd = conf->quomod; - } + /* determine rounding mode */ + if (count == 3) { + v3 = vals[2]; + if (v3->v_type == V_ADDR) { + v3 = v3->v_addr; + } + if (v3->v_type != V_NUM || qisfrac(v3->v_num) || + qisneg(v3->v_num) || zge31b(v3->v_num->num)) { + return error_value(E_GM2G_2); + } + rnd = qtoi(v3->v_num); + } else { + rnd = conf->quomod; + } - /* type parse args */ - if (v1->v_type != V_NUM || v2->v_type != V_NUM) { - return error_value(E_GM2G_1); - } + /* type parse args */ + if (v1->v_type != V_NUM || v2->v_type != V_NUM) { + return error_value(E_GM2G_1); + } - /* - * compute m/60 - */ - tmp = qdivi(v2->v_num, 60); + /* + * compute m/60 + */ + tmp = qdivi(v2->v_num, 60); - /* - * compute g + m/60 - */ - tmp2 = qqadd(v1->v_num, tmp); - qfree(tmp); + /* + * compute g + m/60 + */ + tmp2 = qqadd(v1->v_num, tmp); + qfree(tmp); - /* - * compute mod(g + m/60, 400, rnd); - */ - result.v_type = v1->v_type; - result.v_subtype = v1->v_subtype; - result.v_num = qmod(tmp2, &_qfourhundred, rnd); - qfree(tmp2); + /* + * compute mod(g + m/60, 400, rnd); + */ + result.v_type = v1->v_type; + result.v_subtype = v1->v_subtype; + result.v_num = qmod(tmp2, &_qfourhundred, rnd); + qfree(tmp2); - /* - * return mod(g + m/60, 400, rnd); - */ - return result; + /* + * return mod(g + m/60, 400, rnd); + */ + return result; } S_FUNC VALUE f_hms2h(int count, VALUE **vals) { - VALUE *v1, *v2, *v3, *v4; - NUMBER *tmp, *tmp2, *tmp3, *tmp4; - VALUE result; - long rnd; + VALUE *v1, *v2, *v3, *v4; + NUMBER *tmp, *tmp2, *tmp3, *tmp4; + VALUE result; + long rnd; - /* collect required args */ - v1 = vals[0]; - v2 = vals[1]; - v3 = vals[2]; + /* collect required args */ + v1 = vals[0]; + v2 = vals[1]; + v3 = vals[2]; - /* determine rounding mode */ - if (count == 4) { - v4 = vals[3]; - if (v4->v_type == V_ADDR) { - v4 = v4->v_addr; - } - if (v4->v_type != V_NUM || qisfrac(v4->v_num) || - qisneg(v4->v_num) || zge31b(v4->v_num->num)) { - return error_value(E_HMS2H_2); - } - rnd = qtoi(v4->v_num); - } else { - rnd = conf->quomod; - } + /* determine rounding mode */ + if (count == 4) { + v4 = vals[3]; + if (v4->v_type == V_ADDR) { + v4 = v4->v_addr; + } + if (v4->v_type != V_NUM || qisfrac(v4->v_num) || + qisneg(v4->v_num) || zge31b(v4->v_num->num)) { + return error_value(E_HMS2H_2); + } + rnd = qtoi(v4->v_num); + } else { + rnd = conf->quomod; + } - /* type parse args */ - if (v1->v_type != V_NUM || v2->v_type != V_NUM || - v3->v_type != V_NUM) { - return error_value(E_HMS2H_1); - } + /* type parse args */ + if (v1->v_type != V_NUM || v2->v_type != V_NUM || + v3->v_type != V_NUM) { + return error_value(E_HMS2H_1); + } - /* - * compute s/3600 - */ - tmp = qdivi(v3->v_num, 3600); + /* + * compute s/3600 + */ + tmp = qdivi(v3->v_num, 3600); - /* - * compute m/60 - */ - tmp2 = qdivi(v2->v_num, 60); + /* + * compute m/60 + */ + tmp2 = qdivi(v2->v_num, 60); - /* - * compute m/60 + s/3600 - */ - tmp3 = qqadd(tmp2, tmp); - qfree(tmp); - qfree(tmp2); + /* + * compute m/60 + s/3600 + */ + tmp3 = qqadd(tmp2, tmp); + qfree(tmp); + qfree(tmp2); - /* - * compute h + m/60 + s/3600 - */ - tmp4 = qqadd(v1->v_num, tmp3); - qfree(tmp3); + /* + * compute h + m/60 + s/3600 + */ + tmp4 = qqadd(v1->v_num, tmp3); + qfree(tmp3); - /* - * compute mod(h + m/60 + s/3600, 24, rnd); - */ - result.v_type = v1->v_type; - result.v_subtype = v1->v_subtype; - result.v_num = qmod(tmp4, &_qtwentyfour, rnd); - qfree(tmp4); + /* + * compute mod(h + m/60 + s/3600, 24, rnd); + */ + result.v_type = v1->v_type; + result.v_subtype = v1->v_subtype; + result.v_num = qmod(tmp4, &_qtwentyfour, rnd); + qfree(tmp4); - /* - * return mod(d + m/60 + s/3600, 24, rnd); - */ - return result; + /* + * return mod(d + m/60 + s/3600, 24, rnd); + */ + return result; } S_FUNC VALUE f_hm2h(int count, VALUE **vals) { - VALUE *v1, *v2, *v3; - NUMBER *tmp, *tmp2; - VALUE result; - long rnd; + VALUE *v1, *v2, *v3; + NUMBER *tmp, *tmp2; + VALUE result; + long rnd; - /* collect required args */ - v1 = vals[0]; - v2 = vals[1]; + /* collect required args */ + v1 = vals[0]; + v2 = vals[1]; - /* determine rounding mode */ - if (count == 3) { - v3 = vals[2]; - if (v3->v_type == V_ADDR) { - v3 = v3->v_addr; - } - if (v3->v_type != V_NUM || qisfrac(v3->v_num) || - qisneg(v3->v_num) || zge31b(v3->v_num->num)) { - return error_value(E_H2HM_2); - } - rnd = qtoi(v3->v_num); - } else { - rnd = conf->quomod; - } + /* determine rounding mode */ + if (count == 3) { + v3 = vals[2]; + if (v3->v_type == V_ADDR) { + v3 = v3->v_addr; + } + if (v3->v_type != V_NUM || qisfrac(v3->v_num) || + qisneg(v3->v_num) || zge31b(v3->v_num->num)) { + return error_value(E_H2HM_2); + } + rnd = qtoi(v3->v_num); + } else { + rnd = conf->quomod; + } - /* type parse args */ - if (v1->v_type != V_NUM || v2->v_type != V_NUM) { - return error_value(E_H2HM_1); - } + /* type parse args */ + if (v1->v_type != V_NUM || v2->v_type != V_NUM) { + return error_value(E_H2HM_1); + } - /* - * compute m/60 - */ - tmp = qdivi(v2->v_num, 60); + /* + * compute m/60 + */ + tmp = qdivi(v2->v_num, 60); - /* - * compute d + m/60 - */ - tmp2 = qqadd(v1->v_num, tmp); - qfree(tmp); + /* + * compute d + m/60 + */ + tmp2 = qqadd(v1->v_num, tmp); + qfree(tmp); - /* - * compute mod(h + m/60, 24, rnd); - */ - result.v_type = v1->v_type; - result.v_subtype = v1->v_subtype; - result.v_num = qmod(tmp2, &_qtwentyfour, rnd); - qfree(tmp2); + /* + * compute mod(h + m/60, 24, rnd); + */ + result.v_type = v1->v_type; + result.v_subtype = v1->v_subtype; + result.v_num = qmod(tmp2, &_qtwentyfour, rnd); + qfree(tmp2); - /* - * return mod(h + m/60, 24, rnd); - */ - return result; + /* + * return mod(h + m/60, 24, rnd); + */ + return result; } S_FUNC VALUE f_mmin(VALUE *v1, VALUE *v2) { - VALUE sixteen, res; + VALUE sixteen, res; - /* initialize VALUEs */ - sixteen.v_subtype = V_NOSUBTYPE; - res.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + sixteen.v_subtype = V_NOSUBTYPE; + res.v_subtype = V_NOSUBTYPE; - sixteen.v_type = V_NUM; - sixteen.v_num = itoq(16); - modvalue(v1, v2, &sixteen, &res); - qfree(sixteen.v_num); - return res; + sixteen.v_type = V_NUM; + sixteen.v_num = itoq(16); + modvalue(v1, v2, &sixteen, &res); + qfree(sixteen.v_num); + return res; } S_FUNC NUMBER * f_near(int count, NUMBER **vals) { - NUMBER *err; /* epsilon error tolerance */ - FLAG near; /* qnear() return value */ - NUMBER *ret; /* return value as NUMBER */ + NUMBER *err; /* epsilon error tolerance */ + FLAG near; /* qnear() return value */ + NUMBER *ret; /* return value as NUMBER */ - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 3) { - if (check_epsilon(vals[2]) == false) { - math_error("Invalid value for near epsilon: must be: 0 < epsilon < 1"); - not_reached(); - } - err = vals[2]; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 3) { + if (check_epsilon(vals[2]) == false) { + math_error("Invalid value for near epsilon: must be: 0 < epsilon < 1"); + not_reached(); + } + err = vals[2]; + } - /* - * compute compare nearness of two numbers to a given error tolerance - */ - near = qnear(vals[0], vals[1], err); - ret = itoq((long) near); - return ret; + /* + * compute compare nearness of two numbers to a given error tolerance + */ + near = qnear(vals[0], vals[1], err); + ret = itoq((long) near); + return ret; } S_FUNC NUMBER * f_cfsim(int count, NUMBER **vals) { - long R; + long R; - R = (count > 1) ? qtoi(vals[1]) : conf->cfsim; - return qcfsim(vals[0], R); + R = (count > 1) ? qtoi(vals[1]) : conf->cfsim; + return qcfsim(vals[0], R); } S_FUNC NUMBER * f_cfappr(int count, NUMBER **vals) { - long R; - NUMBER *q; /* approximation limit */ + long R; + NUMBER *q; /* approximation limit */ - /* - * determine epsilon or and approximation limit - * - * NOTE: q is not purely an err (epsilon) value. - * When q is >= 1, it is approximation limit. - * Moreover q can be < 0. No value check on q is needed. - */ - q = (count > 1) ? vals[1] : conf->epsilon; + /* + * determine epsilon or and approximation limit + * + * NOTE: q is not purely an err (epsilon) value. + * When q is >= 1, it is approximation limit. + * Moreover q can be < 0. No value check on q is needed. + */ + q = (count > 1) ? vals[1] : conf->epsilon; - /* - * compute approximation using continued fractions - */ - R = (count > 2) ? qtoi(vals[2]) : conf->cfappr; - return qcfappr(vals[0], q, R); + /* + * compute approximation using continued fractions + */ + R = (count > 2) ? qtoi(vals[2]) : conf->cfappr; + return qcfappr(vals[0], q, R); } S_FUNC VALUE f_ceil(VALUE *val) { - VALUE tmp, res; + VALUE tmp, res; - /* initialize VALUEs */ - res.v_subtype = V_NOSUBTYPE; - tmp.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + res.v_subtype = V_NOSUBTYPE; + tmp.v_subtype = V_NOSUBTYPE; - tmp.v_type = V_NUM; - tmp.v_num = qlink(&_qone_); - apprvalue(val, &tmp, &tmp, &res); - return res; + tmp.v_type = V_NUM; + tmp.v_num = qlink(&_qone_); + apprvalue(val, &tmp, &tmp, &res); + return res; } S_FUNC VALUE f_floor(VALUE *val) { - VALUE tmp1, tmp2, res; + VALUE tmp1, tmp2, res; - /* initialize VALUEs */ - res.v_subtype = V_NOSUBTYPE; - tmp1.v_subtype = V_NOSUBTYPE; - tmp2.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + res.v_subtype = V_NOSUBTYPE; + tmp1.v_subtype = V_NOSUBTYPE; + tmp2.v_subtype = V_NOSUBTYPE; - tmp1.v_type = V_NUM; - tmp1.v_num = qlink(&_qone_); - tmp2.v_type = V_NUM; - tmp2.v_num = qlink(&_qzero_); - apprvalue(val, &tmp1, &tmp2, &res); - return res; + tmp1.v_type = V_NUM; + tmp1.v_num = qlink(&_qone_); + tmp2.v_type = V_NUM; + tmp2.v_num = qlink(&_qzero_); + apprvalue(val, &tmp1, &tmp2, &res); + return res; } S_FUNC VALUE f_sqrt(int count, VALUE **vals) { - VALUE tmp1, tmp2, result; + VALUE tmp1, tmp2, result; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; - tmp1.v_subtype = V_NOSUBTYPE; - tmp2.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; + tmp1.v_subtype = V_NOSUBTYPE; + tmp2.v_subtype = V_NOSUBTYPE; - if (count > 2) - tmp2 = *vals[2]; - else - tmp2.v_type = V_NULL; - if (count > 1) - tmp1 = *vals[1]; - else - tmp1.v_type = V_NULL; - sqrtvalue(vals[0], &tmp1, &tmp2, &result); - return result; + if (count > 2) + tmp2 = *vals[2]; + else + tmp2.v_type = V_NULL; + if (count > 1) + tmp1 = *vals[1]; + else + tmp1.v_type = V_NULL; + sqrtvalue(vals[0], &tmp1, &tmp2, &result); + return result; } S_FUNC VALUE f_root(int count, VALUE **vals) { - VALUE *vp, err, result; + VALUE *vp, err, result; - /* initialize VALUEs */ - err.v_subtype = V_NOSUBTYPE; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + err.v_subtype = V_NOSUBTYPE; + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is != 0. - */ - if (count > 2) { - vp = vals[2]; - } else { - err.v_num = conf->epsilon; - err.v_type = V_NUM; - vp = &err; - } - if (vp->v_type != V_NUM || qiszero(vp->v_num)) { - return error_value(E_ROOT_3); - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is != 0. + */ + if (count > 2) { + vp = vals[2]; + } else { + err.v_num = conf->epsilon; + err.v_type = V_NUM; + vp = &err; + } + if (vp->v_type != V_NUM || qiszero(vp->v_num)) { + return error_value(E_ROOT_3); + } - /* - * compute root of a number to a given error tolerance - */ - rootvalue(vals[0], vals[1], vp, &result); - return result; + /* + * compute root of a number to a given error tolerance + */ + rootvalue(vals[0], vals[1], vp, &result); + return result; } S_FUNC VALUE f_power(int count, VALUE **vals) { - VALUE *vp, err, result; + VALUE *vp, err, result; - /* initialize VALUEs */ - err.v_subtype = V_NOSUBTYPE; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + err.v_subtype = V_NOSUBTYPE; + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is != 0. - */ - if (count > 2) { - vp = vals[2]; - } else { - err.v_num = conf->epsilon; - err.v_type = V_NUM; - vp = &err; - } - if ((vp->v_type != V_NUM) || qisneg(vp->v_num) || qiszero(vp->v_num)) { - return error_value(E_POWER_3); - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is != 0. + */ + if (count > 2) { + vp = vals[2]; + } else { + err.v_num = conf->epsilon; + err.v_type = V_NUM; + vp = &err; + } + if ((vp->v_type != V_NUM) || qisneg(vp->v_num) || qiszero(vp->v_num)) { + return error_value(E_POWER_3); + } - /* - * compute evaluate a numerical power to a given error tolerance - */ - powervalue(vals[0], vals[1], vp, &result); - return result; + /* + * compute evaluate a numerical power to a given error tolerance + */ + powervalue(vals[0], vals[1], vp, &result); + return result; } S_FUNC VALUE f_polar(int count, VALUE **vals) { - VALUE *vp, err, result; - COMPLEX *c; + VALUE *vp, err, result; + COMPLEX *c; - /* initialize VALUEs */ - err.v_subtype = V_NOSUBTYPE; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + err.v_subtype = V_NOSUBTYPE; + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is != 0. - */ - if (count > 2) { - vp = vals[2]; - if ((vp->v_type != V_NUM) || qisneg(vp->v_num) || qiszero(vp->v_num)) { - return error_value(E_POLAR_2); - } - } else { - err.v_num = conf->epsilon; - err.v_type = V_NUM; - vp = &err; - } - if ((vp->v_type != V_NUM) || qisneg(vp->v_num) || qiszero(vp->v_num)) { - return error_value(E_POLAR_2); - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is != 0. + */ + if (count > 2) { + vp = vals[2]; + if ((vp->v_type != V_NUM) || qisneg(vp->v_num) || qiszero(vp->v_num)) { + return error_value(E_POLAR_2); + } + } else { + err.v_num = conf->epsilon; + err.v_type = V_NUM; + vp = &err; + } + if ((vp->v_type != V_NUM) || qisneg(vp->v_num) || qiszero(vp->v_num)) { + return error_value(E_POLAR_2); + } - /* - * compute complex number by modulus (radius) and argument (angle) to a given error tolerance - */ - if ((vals[0]->v_type != V_NUM) || (vals[1]->v_type != V_NUM)) - return error_value(E_POLAR_1); - c = c_polar(vals[0]->v_num, vals[1]->v_num, vp->v_num); - result.v_com = c; - result.v_type = V_COM; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - return result; + /* + * compute complex number by modulus (radius) and argument (angle) to a given error tolerance + */ + if ((vals[0]->v_type != V_NUM) || (vals[1]->v_type != V_NUM)) + return error_value(E_POLAR_1); + c = c_polar(vals[0]->v_num, vals[1]->v_num, vp->v_num); + result.v_com = c; + result.v_type = V_COM; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + return result; } S_FUNC VALUE f_ilog(VALUE *v1, VALUE *v2) { - VALUE res; + VALUE res; - if (v2->v_type != V_NUM || qisfrac(v2->v_num) || qiszero(v2->v_num) || - qisunit(v2->v_num)) - return error_value(E_ILOGB); + if (v2->v_type != V_NUM || qisfrac(v2->v_num) || qiszero(v2->v_num) || + qisunit(v2->v_num)) + return error_value(E_ILOGB); - switch(v1->v_type) { - case V_NUM: - res.v_num = qilog(v1->v_num, v2->v_num->num); - break; - case V_COM: - res.v_num = c_ilog(v1->v_com, v2->v_num->num); - break; - default: - return error_value(E_ILOG); - } + switch(v1->v_type) { + case V_NUM: + res.v_num = qilog(v1->v_num, v2->v_num->num); + break; + case V_COM: + res.v_num = c_ilog(v1->v_com, v2->v_num->num); + break; + default: + return error_value(E_ILOG); + } - if (res.v_num == NULL) - return error_value(E_LOGINF); + if (res.v_num == NULL) + return error_value(E_LOGINF); - res.v_type = V_NUM; - res.v_subtype = V_NOSUBTYPE; - return res; + res.v_type = V_NUM; + res.v_subtype = V_NOSUBTYPE; + return res; } S_FUNC VALUE f_ilog2(VALUE *vp) { - VALUE res; + VALUE res; - switch(vp->v_type) { - case V_NUM: - res.v_num = qilog(vp->v_num, _two_); - break; - case V_COM: - res.v_num = c_ilog(vp->v_com, _two_); - break; - default: - return error_value(E_IBASE2_LOG); - } + switch(vp->v_type) { + case V_NUM: + res.v_num = qilog(vp->v_num, _two_); + break; + case V_COM: + res.v_num = c_ilog(vp->v_com, _two_); + break; + default: + return error_value(E_IBASE2_LOG); + } - if (res.v_num == NULL) - return error_value(E_LOGINF); + if (res.v_num == NULL) + return error_value(E_LOGINF); - res.v_type = V_NUM; - res.v_subtype = V_NOSUBTYPE; - return res; + res.v_type = V_NUM; + res.v_subtype = V_NOSUBTYPE; + return res; } S_FUNC VALUE f_ilog10(VALUE *vp) { - VALUE res; + VALUE res; - switch(vp->v_type) { - case V_NUM: - res.v_num = qilog(vp->v_num, _ten_); - break; - case V_COM: - res.v_num = c_ilog(vp->v_com, _ten_); - break; - default: - return error_value(E_IBASE10_LOG); - } + switch(vp->v_type) { + case V_NUM: + res.v_num = qilog(vp->v_num, _ten_); + break; + case V_COM: + res.v_num = c_ilog(vp->v_com, _ten_); + break; + default: + return error_value(E_IBASE10_LOG); + } - if (res.v_num == NULL) - return error_value(E_LOGINF); + if (res.v_num == NULL) + return error_value(E_LOGINF); - res.v_type = V_NUM; - res.v_subtype = V_NOSUBTYPE; - return res; + res.v_type = V_NUM; + res.v_subtype = V_NOSUBTYPE; + return res; } S_FUNC NUMBER * f_faccnt(NUMBER *val1, NUMBER *val2) { - if (qisfrac(val1) || qisfrac(val2)) - math_error("Non-integral argument for fcnt"); - return itoq(zdivcount(val1->num, val2->num)); + if (qisfrac(val1) || qisfrac(val2)) + math_error("Non-integral argument for fcnt"); + return itoq(zdivcount(val1->num, val2->num)); } S_FUNC VALUE f_matfill(int count, VALUE **vals) { - VALUE *v1, *v2, *v3; - VALUE result; + VALUE *v1, *v2, *v3; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - v1 = vals[0]; - v2 = vals[1]; - if (v1->v_type != V_ADDR) - return error_value(E_MATFILL_1); - v1 = v1->v_addr; - if (v1->v_subtype & V_NOCOPYTO) - return error_value(E_MATFILL_3); - if (v1->v_type != V_MAT) - return error_value(E_MATFILL_2); - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if (v2->v_subtype & V_NOASSIGNFROM) - return error_value(E_MATFILL_4); - if (count == 3) { - v3 = vals[2]; - if (v3->v_type == V_ADDR) - v3 = v3->v_addr; - if (v3->v_subtype & V_NOASSIGNFROM) - return error_value(E_MATFILL_4); - } - else - v3 = NULL; - matfill(v1->v_mat, v2, v3); - result.v_type = V_NULL; - return result; + v1 = vals[0]; + v2 = vals[1]; + if (v1->v_type != V_ADDR) + return error_value(E_MATFILL_1); + v1 = v1->v_addr; + if (v1->v_subtype & V_NOCOPYTO) + return error_value(E_MATFILL_3); + if (v1->v_type != V_MAT) + return error_value(E_MATFILL_2); + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if (v2->v_subtype & V_NOASSIGNFROM) + return error_value(E_MATFILL_4); + if (count == 3) { + v3 = vals[2]; + if (v3->v_type == V_ADDR) + v3 = v3->v_addr; + if (v3->v_subtype & V_NOASSIGNFROM) + return error_value(E_MATFILL_4); + } + else + v3 = NULL; + matfill(v1->v_mat, v2, v3); + result.v_type = V_NULL; + return result; } S_FUNC VALUE f_matsum(VALUE *vp) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* firewall */ - if (vp->v_type != V_MAT) - return error_value(E_MATSUM); + /* firewall */ + if (vp->v_type != V_MAT) + return error_value(E_MATSUM); - /* sum matrix */ - matsum(vp->v_mat, &result); - return result; + /* sum matrix */ + matsum(vp->v_mat, &result); + return result; } S_FUNC VALUE f_isident(VALUE *vp) { - VALUE result; + VALUE result; - /* initialize VALUEs */ - result.v_type = V_NUM; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_type = V_NUM; + result.v_subtype = V_NOSUBTYPE; - if (vp->v_type == V_MAT) { - result.v_num = itoq((long) matisident(vp->v_mat)); - } else { - result.v_num = itoq(0); - } - return result; + if (vp->v_type == V_MAT) { + result.v_num = itoq((long) matisident(vp->v_mat)); + } else { + result.v_num = itoq(0); + } + return result; } S_FUNC VALUE f_mattrace(VALUE *vp) { - if (vp->v_type != V_MAT) - return error_value(E_MATTRACE_1); - return mattrace(vp->v_mat); + if (vp->v_type != V_MAT) + return error_value(E_MATTRACE_1); + return mattrace(vp->v_mat); } S_FUNC VALUE f_mattrans(VALUE *vp) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vp->v_type != V_MAT) - return error_value(E_MATTRANS_1); - if (vp->v_mat->m_dim > 2) - return error_value(E_MATTRANS_2); - result.v_type = V_MAT; - result.v_mat = mattrans(vp->v_mat); - return result; + if (vp->v_type != V_MAT) + return error_value(E_MATTRANS_1); + if (vp->v_mat->m_dim > 2) + return error_value(E_MATTRANS_2); + result.v_type = V_MAT; + result.v_mat = mattrans(vp->v_mat); + return result; } S_FUNC VALUE f_det(VALUE *vp) { - if (vp->v_type != V_MAT) - return error_value(E_DET_1); + if (vp->v_type != V_MAT) + return error_value(E_DET_1); - return matdet(vp->v_mat); + return matdet(vp->v_mat); } S_FUNC VALUE f_matdim(VALUE *vp) { - VALUE result; + VALUE result; - /* initialize VALUEs */ - result.v_type = V_NUM; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_type = V_NUM; + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_OBJ: - result.v_num = itoq(vp->v_obj->o_actions->oa_count); - break; - case V_MAT: - result.v_num = itoq((long) vp->v_mat->m_dim); - break; - default: - return error_value(E_MATDIM); - } - return result; + switch(vp->v_type) { + case V_OBJ: + result.v_num = itoq(vp->v_obj->o_actions->oa_count); + break; + case V_MAT: + result.v_num = itoq((long) vp->v_mat->m_dim); + break; + default: + return error_value(E_MATDIM); + } + return result; } S_FUNC VALUE f_matmin(VALUE *v1, VALUE *v2) { - VALUE result; - NUMBER *q; - long i; + VALUE result; + NUMBER *q; + long i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (v1->v_type != V_MAT) - return error_value(E_MATMIN_1); - if (v2->v_type != V_NUM) - return error_value(E_MATMIN_2); - q = v2->v_num; - if (qisfrac(q) || qisneg(q) || qiszero(q)) - return error_value(E_MATMIN_2); - i = qtoi(q); - if (i > v1->v_mat->m_dim) - return error_value(E_MATMIN_3); - result.v_type = V_NUM; - result.v_num = itoq(v1->v_mat->m_min[i - 1]); - return result; + if (v1->v_type != V_MAT) + return error_value(E_MATMIN_1); + if (v2->v_type != V_NUM) + return error_value(E_MATMIN_2); + q = v2->v_num; + if (qisfrac(q) || qisneg(q) || qiszero(q)) + return error_value(E_MATMIN_2); + i = qtoi(q); + if (i > v1->v_mat->m_dim) + return error_value(E_MATMIN_3); + result.v_type = V_NUM; + result.v_num = itoq(v1->v_mat->m_min[i - 1]); + return result; } S_FUNC VALUE f_matmax(VALUE *v1, VALUE *v2) { - VALUE result; - NUMBER *q; - long i; + VALUE result; + NUMBER *q; + long i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (v1->v_type != V_MAT) - return error_value(E_MATMAX_1); - if (v2->v_type != V_NUM) - return error_value(E_MATMAX_2); - q = v2->v_num; - if (qisfrac(q) || qisneg(q) || qiszero(q)) - return error_value(E_MATMAX_2); - i = qtoi(q); - if (i > v1->v_mat->m_dim) - return error_value(E_MATMAX_3); - result.v_type = V_NUM; - result.v_num = itoq(v1->v_mat->m_max[i - 1]); - return result; + if (v1->v_type != V_MAT) + return error_value(E_MATMAX_1); + if (v2->v_type != V_NUM) + return error_value(E_MATMAX_2); + q = v2->v_num; + if (qisfrac(q) || qisneg(q) || qiszero(q)) + return error_value(E_MATMAX_2); + i = qtoi(q); + if (i > v1->v_mat->m_dim) + return error_value(E_MATMAX_3); + result.v_type = V_NUM; + result.v_num = itoq(v1->v_mat->m_max[i - 1]); + return result; } S_FUNC VALUE f_cp(VALUE *v1, VALUE *v2) { - MATRIX *m1, *m2; - VALUE result; + MATRIX *m1, *m2; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if ((v1->v_type != V_MAT) || (v2->v_type != V_MAT)) - return error_value(E_CP_1); - m1 = v1->v_mat; - m2 = v2->v_mat; - if ((m1->m_dim != 1) || (m2->m_dim != 1)) - return error_value(E_CP_2); - if ((m1->m_size != 3) || (m2->m_size != 3)) - return error_value(E_CP_3); - result.v_type = V_MAT; - result.v_mat = matcross(m1, m2); - return result; + if ((v1->v_type != V_MAT) || (v2->v_type != V_MAT)) + return error_value(E_CP_1); + m1 = v1->v_mat; + m2 = v2->v_mat; + if ((m1->m_dim != 1) || (m2->m_dim != 1)) + return error_value(E_CP_2); + if ((m1->m_size != 3) || (m2->m_size != 3)) + return error_value(E_CP_3); + result.v_type = V_MAT; + result.v_mat = matcross(m1, m2); + return result; } S_FUNC VALUE f_dp(VALUE *v1, VALUE *v2) { - MATRIX *m1, *m2; + MATRIX *m1, *m2; - if ((v1->v_type != V_MAT) || (v2->v_type != V_MAT)) - return error_value(E_DP_1); - m1 = v1->v_mat; - m2 = v2->v_mat; - if ((m1->m_dim != 1) || (m2->m_dim != 1)) - return error_value(E_DP_2); - if (m1->m_size != m2->m_size) - return error_value(E_DP_3); - return matdot(m1, m2); + if ((v1->v_type != V_MAT) || (v2->v_type != V_MAT)) + return error_value(E_DP_1); + m1 = v1->v_mat; + m2 = v2->v_mat; + if ((m1->m_dim != 1) || (m2->m_dim != 1)) + return error_value(E_DP_2); + if (m1->m_size != m2->m_size) + return error_value(E_DP_3); + return matdot(m1, m2); } S_FUNC VALUE f_strlen(VALUE *vp) { - VALUE result; - long len = 0; - char *c; + VALUE result; + long len = 0; + char *c; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vp->v_type != V_STR) - return error_value(E_STRLEN); - c = vp->v_str->s_str; - while (*c++) - len++; - result.v_type = V_NUM; - result.v_num = itoq(len); - return result; + if (vp->v_type != V_STR) + return error_value(E_STRLEN); + c = vp->v_str->s_str; + while (*c++) + len++; + result.v_type = V_NUM; + result.v_num = itoq(len); + return result; } S_FUNC VALUE f_strcmp(VALUE *v1, VALUE *v2) { - VALUE result; - FLAG flag; + VALUE result; + FLAG flag; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (v1->v_type != V_STR || v2->v_type != V_STR) - return error_value(E_STRCMP); + if (v1->v_type != V_STR || v2->v_type != V_STR) + return error_value(E_STRCMP); - flag = stringrel(v1->v_str, v2->v_str); + flag = stringrel(v1->v_str, v2->v_str); - result.v_type = V_NUM; - result.v_num = itoq((long) flag); - return result; + result.v_type = V_NUM; + result.v_num = itoq((long) flag); + return result; } S_FUNC VALUE f_strcasecmp(VALUE *v1, VALUE *v2) { - VALUE result; - FLAG flag; + VALUE result; + FLAG flag; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (v1->v_type != V_STR || v2->v_type != V_STR) - return error_value(E_STRCASECMP); + if (v1->v_type != V_STR || v2->v_type != V_STR) + return error_value(E_STRCASECMP); - flag = stringcaserel(v1->v_str, v2->v_str); + flag = stringcaserel(v1->v_str, v2->v_str); - result.v_type = V_NUM; - result.v_num = itoq((long) flag); - return result; + result.v_type = V_NUM; + result.v_num = itoq((long) flag); + return result; } S_FUNC VALUE f_strncmp(VALUE *v1, VALUE *v2, VALUE *v3) { - long n1, n2, n; - FLAG flag; - VALUE result; + long n1, n2, n; + FLAG flag; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (v1->v_type != V_STR || v2->v_type != V_STR || - v3->v_type != V_NUM || qisneg(v3->v_num) || - qisfrac(v3->v_num) || zge31b(v3->v_num->num)) - return error_value(E_STRNCMP); - n1 = v1->v_str->s_len; - n2 = v2->v_str->s_len; - n = qtoi(v3->v_num); - if (n < n1) - v1->v_str->s_len = n; - if (n < n2) - v2->v_str->s_len = n; + if (v1->v_type != V_STR || v2->v_type != V_STR || + v3->v_type != V_NUM || qisneg(v3->v_num) || + qisfrac(v3->v_num) || zge31b(v3->v_num->num)) + return error_value(E_STRNCMP); + n1 = v1->v_str->s_len; + n2 = v2->v_str->s_len; + n = qtoi(v3->v_num); + if (n < n1) + v1->v_str->s_len = n; + if (n < n2) + v2->v_str->s_len = n; - flag = stringrel(v1->v_str, v2->v_str); + flag = stringrel(v1->v_str, v2->v_str); - v1->v_str->s_len = n1; - v2->v_str->s_len = n2; + v1->v_str->s_len = n1; + v2->v_str->s_len = n2; - result.v_type = V_NUM; - result.v_num = itoq((long) flag); - return result; + result.v_type = V_NUM; + result.v_num = itoq((long) flag); + return result; } S_FUNC VALUE f_strncasecmp(VALUE *v1, VALUE *v2, VALUE *v3) { - long n1, n2, n; - FLAG flag; - VALUE result; + long n1, n2, n; + FLAG flag; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (v1->v_type != V_STR || v2->v_type != V_STR || - v3->v_type != V_NUM || qisneg(v3->v_num) || - qisfrac(v3->v_num) || zge31b(v3->v_num->num)) - return error_value(E_STRNCASECMP); - n1 = v1->v_str->s_len; - n2 = v2->v_str->s_len; - n = qtoi(v3->v_num); - if (n < n1) - v1->v_str->s_len = n; - if (n < n2) - v2->v_str->s_len = n; + if (v1->v_type != V_STR || v2->v_type != V_STR || + v3->v_type != V_NUM || qisneg(v3->v_num) || + qisfrac(v3->v_num) || zge31b(v3->v_num->num)) + return error_value(E_STRNCASECMP); + n1 = v1->v_str->s_len; + n2 = v2->v_str->s_len; + n = qtoi(v3->v_num); + if (n < n1) + v1->v_str->s_len = n; + if (n < n2) + v2->v_str->s_len = n; - flag = stringcaserel(v1->v_str, v2->v_str); + flag = stringcaserel(v1->v_str, v2->v_str); - v1->v_str->s_len = n1; - v2->v_str->s_len = n2; + v1->v_str->s_len = n1; + v2->v_str->s_len = n2; - result.v_type = V_NUM; - result.v_num = itoq((long) flag); - return result; + result.v_type = V_NUM; + result.v_num = itoq((long) flag); + return result; } S_FUNC VALUE @@ -6528,972 +6528,972 @@ f_strtolower(VALUE *vp) S_FUNC VALUE f_strcat(int count, VALUE **vals) { - VALUE **vp; - char *c, *c1; - int i; - long len; - VALUE result; + VALUE **vp; + char *c, *c1; + int i; + long len; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - len = 0; - result.v_type = V_STR; - vp = vals; - for (i = 0; i < count; i++, vp++) { - if ((*vp)->v_type != V_STR) - return error_value(E_STRCAT); - c = (*vp)->v_str->s_str; - while (*c++) - len++; - } - if (len == 0) { - result.v_str = slink(&_nullstring_); - return result; - } - c = (char *) malloc(len + 1) ; - if (c == NULL) { - math_error("No memory for strcat"); - not_reached(); - } - result.v_str = stralloc(); - result.v_str->s_str = c; - result.v_str->s_len = len; - for (vp = vals; count-- > 0; vp++) { - c1 = (*vp)->v_str->s_str; - while (*c1) - *c++ = *c1++; - } - *c = '\0'; - return result; + len = 0; + result.v_type = V_STR; + vp = vals; + for (i = 0; i < count; i++, vp++) { + if ((*vp)->v_type != V_STR) + return error_value(E_STRCAT); + c = (*vp)->v_str->s_str; + while (*c++) + len++; + } + if (len == 0) { + result.v_str = slink(&_nullstring_); + return result; + } + c = (char *) malloc(len + 1) ; + if (c == NULL) { + math_error("No memory for strcat"); + not_reached(); + } + result.v_str = stralloc(); + result.v_str->s_str = c; + result.v_str->s_len = len; + for (vp = vals; count-- > 0; vp++) { + c1 = (*vp)->v_str->s_str; + while (*c1) + *c++ = *c1++; + } + *c = '\0'; + return result; } S_FUNC VALUE f_strcpy(VALUE *v1, VALUE *v2) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (v1->v_type != V_STR || v2->v_type != V_STR) - return error_value(E_STRCPY); - result.v_str = stringcpy(v1->v_str, v2->v_str); - result.v_type = V_STR; - return result; + if (v1->v_type != V_STR || v2->v_type != V_STR) + return error_value(E_STRCPY); + result.v_str = stringcpy(v1->v_str, v2->v_str); + result.v_type = V_STR; + return result; } S_FUNC VALUE f_strncpy(VALUE *v1, VALUE *v2, VALUE *v3) { - VALUE result; - long num; + VALUE result; + long num; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (v1->v_type != V_STR || v2->v_type != V_STR || - v3->v_type != V_NUM || qisfrac(v3->v_num) || qisneg(v3->v_num)) - return error_value(E_STRNCPY); - if (zge31b(v3->v_num->num)) - num = v2->v_str->s_len; - else - num = qtoi(v3->v_num); - result.v_str = stringncpy(v1->v_str, v2->v_str, num); - result.v_type = V_STR; - return result; + if (v1->v_type != V_STR || v2->v_type != V_STR || + v3->v_type != V_NUM || qisfrac(v3->v_num) || qisneg(v3->v_num)) + return error_value(E_STRNCPY); + if (zge31b(v3->v_num->num)) + num = v2->v_str->s_len; + else + num = qtoi(v3->v_num); + result.v_str = stringncpy(v1->v_str, v2->v_str, num); + result.v_type = V_STR; + return result; } S_FUNC VALUE f_substr(VALUE *v1, VALUE *v2, VALUE *v3) { - NUMBER *q1, *q2; - size_t start, len; - char *cp; - char *ccp; - VALUE result; + NUMBER *q1, *q2; + size_t start, len; + char *cp; + char *ccp; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (v1->v_type != V_STR) - return error_value(E_SUBSTR_1); - if ((v2->v_type != V_NUM) || (v3->v_type != V_NUM)) - return error_value(E_SUBSTR_2); - q1 = v2->v_num; - q2 = v3->v_num; - if (qisfrac(q1) || qisneg(q1) || qisfrac(q2) || qisneg(q2)) - return error_value(E_SUBSTR_2); - start = qtoi(q1); - len = qtoi(q2); - if (start > 0) - start--; - result.v_type = V_STR; - if (start >= v1->v_str->s_len || len == 0) { - result.v_str = slink(&_nullstring_); - return result; - } - if (len > v1->v_str->s_len - start) - len = v1->v_str->s_len - start; - cp = v1->v_str->s_str + start; - ccp = (char *) malloc(len + 1); - if (ccp == NULL) { - math_error("No memory for substr"); - not_reached(); - } - result.v_str = stralloc(); - result.v_str->s_len = len; - result.v_str->s_str = ccp; - while (len-- > 0) - *ccp++ = *cp++; - *ccp = '\0'; - return result; + if (v1->v_type != V_STR) + return error_value(E_SUBSTR_1); + if ((v2->v_type != V_NUM) || (v3->v_type != V_NUM)) + return error_value(E_SUBSTR_2); + q1 = v2->v_num; + q2 = v3->v_num; + if (qisfrac(q1) || qisneg(q1) || qisfrac(q2) || qisneg(q2)) + return error_value(E_SUBSTR_2); + start = qtoi(q1); + len = qtoi(q2); + if (start > 0) + start--; + result.v_type = V_STR; + if (start >= v1->v_str->s_len || len == 0) { + result.v_str = slink(&_nullstring_); + return result; + } + if (len > v1->v_str->s_len - start) + len = v1->v_str->s_len - start; + cp = v1->v_str->s_str + start; + ccp = (char *) malloc(len + 1); + if (ccp == NULL) { + math_error("No memory for substr"); + not_reached(); + } + result.v_str = stralloc(); + result.v_str->s_len = len; + result.v_str->s_str = ccp; + while (len-- > 0) + *ccp++ = *cp++; + *ccp = '\0'; + return result; } S_FUNC VALUE f_char(VALUE *vp) { - char ch; - VALUE result; + char ch; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_NUM: - if (qisfrac(vp->v_num)) - return error_value(E_CHAR); - ch = (char) vp->v_num->num.v[0]; - if (qisneg(vp->v_num)) - ch = -ch; - break; - case V_OCTET: - ch = *vp->v_octet; - break; - case V_STR: - ch = *vp->v_str->s_str; - break; - default: - return error_value(E_CHAR); - } - result.v_type = V_STR; - result.v_str = charstring(ch); - return result; + switch(vp->v_type) { + case V_NUM: + if (qisfrac(vp->v_num)) + return error_value(E_CHAR); + ch = (char) vp->v_num->num.v[0]; + if (qisneg(vp->v_num)) + ch = -ch; + break; + case V_OCTET: + ch = *vp->v_octet; + break; + case V_STR: + ch = *vp->v_str->s_str; + break; + default: + return error_value(E_CHAR); + } + result.v_type = V_STR; + result.v_str = charstring(ch); + return result; } S_FUNC VALUE f_ord(VALUE *vp) { - OCTET *c; - VALUE result; + OCTET *c; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_STR: - c = (OCTET *)vp->v_str->s_str; - break; - case V_OCTET: - c = vp->v_octet; - break; - default: - return error_value(E_ORD); - } + switch(vp->v_type) { + case V_STR: + c = (OCTET *)vp->v_str->s_str; + break; + case V_OCTET: + c = vp->v_octet; + break; + default: + return error_value(E_ORD); + } - result.v_type = V_NUM; - result.v_num = itoq((long) (*c & 0xff)); - return result; + result.v_type = V_NUM; + result.v_num = itoq((long) (*c & 0xff)); + return result; } S_FUNC VALUE f_isupper(VALUE *vp) { - char c; - VALUE result; + char c; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_STR: - c = *vp->v_str->s_str; - break; - case V_OCTET: - c = *vp->v_octet; - break; - default: - return error_value(E_ISUPPER); - } + switch(vp->v_type) { + case V_STR: + c = *vp->v_str->s_str; + break; + case V_OCTET: + c = *vp->v_octet; + break; + default: + return error_value(E_ISUPPER); + } - result.v_type = V_NUM; - result.v_num = itoq( (isupper( c ))?1l:0l); - return result; + result.v_type = V_NUM; + result.v_num = itoq( (isupper( c ))?1l:0l); + return result; } S_FUNC VALUE f_islower(VALUE *vp) { - char c; - VALUE result; + char c; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_STR: - c = *vp->v_str->s_str; - break; - case V_OCTET: - c = *vp->v_octet; - break; - default: - return error_value(E_ISLOWER); - } + switch(vp->v_type) { + case V_STR: + c = *vp->v_str->s_str; + break; + case V_OCTET: + c = *vp->v_octet; + break; + default: + return error_value(E_ISLOWER); + } - result.v_type = V_NUM; - result.v_num = itoq( (islower( c ))?1l:0l); - return result; + result.v_type = V_NUM; + result.v_num = itoq( (islower( c ))?1l:0l); + return result; } S_FUNC VALUE f_isalnum(VALUE *vp) { - char c; - VALUE result; + char c; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_STR: - c = *vp->v_str->s_str; - break; - case V_OCTET: - c = *vp->v_octet; - break; - default: - return error_value(E_ISALNUM); - } + switch(vp->v_type) { + case V_STR: + c = *vp->v_str->s_str; + break; + case V_OCTET: + c = *vp->v_octet; + break; + default: + return error_value(E_ISALNUM); + } - result.v_type = V_NUM; - result.v_num = itoq( (isalnum( c ))?1l:0l); - return result; + result.v_type = V_NUM; + result.v_num = itoq( (isalnum( c ))?1l:0l); + return result; } S_FUNC VALUE f_isalpha(VALUE *vp) { - char c; - VALUE result; + char c; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_STR: - c = *vp->v_str->s_str; - break; - case V_OCTET: - c = *vp->v_octet; - break; - default: - return error_value(E_ISALPHA); - } + switch(vp->v_type) { + case V_STR: + c = *vp->v_str->s_str; + break; + case V_OCTET: + c = *vp->v_octet; + break; + default: + return error_value(E_ISALPHA); + } - result.v_type = V_NUM; - result.v_num = itoq( (isalpha( c ))?1l:0l); - return result; + result.v_type = V_NUM; + result.v_num = itoq( (isalpha( c ))?1l:0l); + return result; } #if 0 /* XXX - add isascii builtin funcion - XXX */ S_FUNC VALUE f_isascii(VALUE *vp) { - char c; - VALUE result; + char c; + VALUE result; - result.v_subtype = V_NOSUBTYPE; + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_STR: - c = *vp->v_str->s_str; - break; - case V_OCTET: - c = *vp->v_octet; - break; - default: - return error_value(E_ISASCII); - } + switch(vp->v_type) { + case V_STR: + c = *vp->v_str->s_str; + break; + case V_OCTET: + c = *vp->v_octet; + break; + default: + return error_value(E_ISASCII); + } - result.v_type = V_NUM; - result.v_num = itoq( (isascii( c ))?1l:0l); - return result; + result.v_type = V_NUM; + result.v_num = itoq( (isascii( c ))?1l:0l); + return result; } #endif /* 0 */ S_FUNC VALUE f_iscntrl(VALUE *vp) { - char c; - VALUE result; + char c; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_STR: - c = *vp->v_str->s_str; - break; - case V_OCTET: - c = *vp->v_octet; - break; - default: - return error_value(E_ISCNTRL); - } + switch(vp->v_type) { + case V_STR: + c = *vp->v_str->s_str; + break; + case V_OCTET: + c = *vp->v_octet; + break; + default: + return error_value(E_ISCNTRL); + } - result.v_type = V_NUM; - result.v_num = itoq( (iscntrl( c ))?1l:0l); - return result; + result.v_type = V_NUM; + result.v_num = itoq( (iscntrl( c ))?1l:0l); + return result; } S_FUNC VALUE f_isdigit(VALUE *vp) { - char c; - VALUE result; + char c; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_STR: - c = *vp->v_str->s_str; - break; - case V_OCTET: - c = *vp->v_octet; - break; - default: - return error_value(E_ISDIGIT); - } + switch(vp->v_type) { + case V_STR: + c = *vp->v_str->s_str; + break; + case V_OCTET: + c = *vp->v_octet; + break; + default: + return error_value(E_ISDIGIT); + } - result.v_type = V_NUM; - result.v_num = itoq( (isdigit( c ))?1l:0l); - return result; + result.v_type = V_NUM; + result.v_num = itoq( (isdigit( c ))?1l:0l); + return result; } S_FUNC VALUE f_isgraph(VALUE *vp) { - char c; - VALUE result; + char c; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_STR: - c = *vp->v_str->s_str; - break; - case V_OCTET: - c = *vp->v_octet; - break; - default: - return error_value(E_ISGRAPH); - } + switch(vp->v_type) { + case V_STR: + c = *vp->v_str->s_str; + break; + case V_OCTET: + c = *vp->v_octet; + break; + default: + return error_value(E_ISGRAPH); + } - result.v_type = V_NUM; - result.v_num = itoq( (isgraph( c ))?1l:0l); - return result; + result.v_type = V_NUM; + result.v_num = itoq( (isgraph( c ))?1l:0l); + return result; } S_FUNC VALUE f_isprint(VALUE *vp) { - char c; - VALUE result; + char c; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_STR: - c = *vp->v_str->s_str; - break; - case V_OCTET: - c = *vp->v_octet; - break; - default: - return error_value(E_ISPRINT); - } + switch(vp->v_type) { + case V_STR: + c = *vp->v_str->s_str; + break; + case V_OCTET: + c = *vp->v_octet; + break; + default: + return error_value(E_ISPRINT); + } - result.v_type = V_NUM; - result.v_num = itoq( (isprint( c ))?1l:0l); - return result; + result.v_type = V_NUM; + result.v_num = itoq( (isprint( c ))?1l:0l); + return result; } S_FUNC VALUE f_ispunct(VALUE *vp) { - char c; - VALUE result; + char c; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_STR: - c = *vp->v_str->s_str; - break; - case V_OCTET: - c = *vp->v_octet; - break; - default: - return error_value(E_ISPUNCT); - } + switch(vp->v_type) { + case V_STR: + c = *vp->v_str->s_str; + break; + case V_OCTET: + c = *vp->v_octet; + break; + default: + return error_value(E_ISPUNCT); + } - result.v_type = V_NUM; - result.v_num = itoq( (ispunct( c ))?1l:0l); - return result; + result.v_type = V_NUM; + result.v_num = itoq( (ispunct( c ))?1l:0l); + return result; } S_FUNC VALUE f_isspace(VALUE *vp) { - char c; - VALUE result; + char c; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_STR: - c = *vp->v_str->s_str; - break; - case V_OCTET: - c = *vp->v_octet; - break; - default: - return error_value(E_ISSPACE); - } + switch(vp->v_type) { + case V_STR: + c = *vp->v_str->s_str; + break; + case V_OCTET: + c = *vp->v_octet; + break; + default: + return error_value(E_ISSPACE); + } - result.v_type = V_NUM; - result.v_num = itoq( (isspace( c ))?1l:0l); - return result; + result.v_type = V_NUM; + result.v_num = itoq( (isspace( c ))?1l:0l); + return result; } S_FUNC VALUE f_isxdigit(VALUE *vp) { - char c; - VALUE result; + char c; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - switch(vp->v_type) { - case V_STR: - c = *vp->v_str->s_str; - break; - case V_OCTET: - c = *vp->v_octet; - break; - default: - return error_value(E_ISXDIGIT); - } + switch(vp->v_type) { + case V_STR: + c = *vp->v_str->s_str; + break; + case V_OCTET: + c = *vp->v_octet; + break; + default: + return error_value(E_ISXDIGIT); + } - result.v_type = V_NUM; - result.v_num = itoq( (isxdigit( c ))?1l:0l); - return result; + result.v_type = V_NUM; + result.v_num = itoq( (isxdigit( c ))?1l:0l); + return result; } S_FUNC VALUE f_protect(int count, VALUE **vals) { - int i, depth; - VALUE *v1, *v2, *v3; + int i, depth; + VALUE *v1, *v2, *v3; - VALUE result; - bool have_nblock; + VALUE result; + bool have_nblock; - /* initialize VALUE */ - result.v_type = V_NULL; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NULL; + result.v_subtype = V_NOSUBTYPE; - v1 = vals[0]; - have_nblock = (v1->v_type == V_NBLOCK); - if (!have_nblock) { - if (v1->v_type != V_ADDR) - return error_value(E_PROTECT_1); - v1 = v1->v_addr; - } - if (count == 1) { - result.v_type = V_NUM; - if (have_nblock) - result.v_num = itoq(v1->v_nblock->subtype); - else - result.v_num = itoq(v1->v_subtype); - return result; - } - v2 = vals[1]; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if (v2->v_type != V_NUM||qisfrac(v2->v_num)||zge16b(v2->v_num->num)) - return error_value(E_PROTECT_2); - i = qtoi(v2->v_num); - depth = 0; - if (count > 2) { - v3 = vals[2]; - if (v3->v_type == V_ADDR) - v3 = v3->v_addr; - if (v3->v_type != V_NUM || qisfrac(v3->v_num) || - qisneg(v3->v_num) || zge31b(v3->v_num->num)) - return error_value(E_PROTECT_3); - depth = qtoi(v3->v_num); - } - protecttodepth(v1, i, depth); - return result; + v1 = vals[0]; + have_nblock = (v1->v_type == V_NBLOCK); + if (!have_nblock) { + if (v1->v_type != V_ADDR) + return error_value(E_PROTECT_1); + v1 = v1->v_addr; + } + if (count == 1) { + result.v_type = V_NUM; + if (have_nblock) + result.v_num = itoq(v1->v_nblock->subtype); + else + result.v_num = itoq(v1->v_subtype); + return result; + } + v2 = vals[1]; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if (v2->v_type != V_NUM||qisfrac(v2->v_num)||zge16b(v2->v_num->num)) + return error_value(E_PROTECT_2); + i = qtoi(v2->v_num); + depth = 0; + if (count > 2) { + v3 = vals[2]; + if (v3->v_type == V_ADDR) + v3 = v3->v_addr; + if (v3->v_type != V_NUM || qisfrac(v3->v_num) || + qisneg(v3->v_num) || zge31b(v3->v_num->num)) + return error_value(E_PROTECT_3); + depth = qtoi(v3->v_num); + } + protecttodepth(v1, i, depth); + return result; } S_FUNC VALUE f_size(VALUE *vp) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * return information about the number of elements - * - * This is not the sizeof, see f_sizeof() for that information. - * This is not the memsize, see f_memsize() for that information. - * - * The size of a file is treated in a special way ... we do - * not use the number of elements, but rather the length - * of the file as would be reported by fsize(). - */ - if (vp->v_type == V_FILE) { - return f_fsize(vp); - } else { - result.v_type = V_NUM; - result.v_num = itoq(elm_count(vp)); - } - return result; + /* + * return information about the number of elements + * + * This is not the sizeof, see f_sizeof() for that information. + * This is not the memsize, see f_memsize() for that information. + * + * The size of a file is treated in a special way ... we do + * not use the number of elements, but rather the length + * of the file as would be reported by fsize(). + */ + if (vp->v_type == V_FILE) { + return f_fsize(vp); + } else { + result.v_type = V_NUM; + result.v_num = itoq(elm_count(vp)); + } + return result; } S_FUNC VALUE f_sizeof(VALUE *vp) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_type = V_NUM; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NUM; + result.v_subtype = V_NOSUBTYPE; - /* - * return information about memory footprint - * - * This is not the number of elements, see f_size() for that info. - * This is not the memsize, see f_memsize() for that information. - */ - result.v_num = itoq(lsizeof(vp)); - return result; + /* + * return information about memory footprint + * + * This is not the number of elements, see f_size() for that info. + * This is not the memsize, see f_memsize() for that information. + */ + result.v_num = itoq(lsizeof(vp)); + return result; } S_FUNC VALUE f_memsize(VALUE *vp) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_type = V_NUM; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NUM; + result.v_subtype = V_NOSUBTYPE; - /* - * return information about memory footprint - * - * This is not the number of elements, see f_size() for that info. - * This is not the sizeof, see f_sizeof() for that information. - */ - result.v_num = itoq(memsize(vp)); - return result; + /* + * return information about memory footprint + * + * This is not the number of elements, see f_size() for that info. + * This is not the sizeof, see f_sizeof() for that information. + */ + result.v_num = itoq(memsize(vp)); + return result; } S_FUNC VALUE f_search(int count, VALUE **vals) { - VALUE *v1, *v2, *v3, *v4; - NUMBER *start, *end; - VALUE vsize; - NUMBER *size; - ZVALUE pos; - ZVALUE indx; - long len; - ZVALUE zlen, tmp; - VALUE result; - long l_start = 0, l_end = 0; - int i = 0; + VALUE *v1, *v2, *v3, *v4; + NUMBER *start, *end; + VALUE vsize; + NUMBER *size; + ZVALUE pos; + ZVALUE indx; + long len; + ZVALUE zlen, tmp; + VALUE result; + long l_start = 0, l_end = 0; + int i = 0; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; - vsize.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; + vsize.v_subtype = V_NOSUBTYPE; - v1 = *vals++; - v2 = *vals++; - if ((v1->v_type == V_FILE || v1->v_type == V_STR) && - v2->v_type != V_STR) - return error_value(E_SEARCH_2); - start = end = NULL; - if (count > 2) { - v3 = *vals++; - if (v3->v_type != V_NUM && v3->v_type != V_NULL) - return error_value(E_SEARCH_3); - if (v3->v_type == V_NUM) { - start = v3->v_num; - if (qisfrac(start)) - return error_value(E_SEARCH_3); - } - } - if (count > 3) { - v4 = *vals; - if (v4->v_type != V_NUM && v4->v_type != V_NULL) - return error_value(E_SEARCH_4); - if (v4->v_type == V_NUM) { - end = v4->v_num; - if (qisfrac(end)) - return error_value(E_SEARCH_4); - } - } - result.v_type = V_NULL; - vsize = f_size(v1); - if (vsize.v_type != V_NUM) - return error_value(E_SEARCH_5); - size = vsize.v_num; - if (start) { - if (qisneg(start)) { - start = qqadd(size, start); - if (qisneg(start)) { - qfree(start); - start = qlink(&_qzero_); - } - } else { - start = qlink(start); - } - } - if (end) { - if (!qispos(end)) { - end = qqadd(size, end); - } else { - if (qrel(end, size) > 0) - end = qlink(size); - else - end = qlink(end); - } - } - if (v1->v_type == V_FILE) { - if (count == 2|| (count == 4 && - (start == NULL || end == NULL))) { - i = ftellid(v1->v_file, &pos); - if (i < 0) { - qfree(size); - if (start) - qfree(start); - if (end) - qfree(end); - return error_value(E_SEARCH_5); - } - if (count == 2 || (count == 4 && end != NULL)) { - start = qalloc(); - start->num = pos; - } else { - end = qalloc(); - end->num = pos; - } - } - if (start == NULL) - start = qlink(&_qzero_); - if (end == NULL) - end = size; - else - qfree(size); - len = v2->v_str->s_len; - utoz(len, &zlen); - zsub(end->num, zlen, &tmp); - zfree(zlen); - i = fsearch(v1->v_file, v2->v_str->s_str, - start->num, tmp, &indx); - zfree(tmp); - if (i == 2) { - result.v_type = V_NUM; - result.v_num = start; - qfree(end); - return result; - } - qfree(start); - qfree(end); - if (i == EOF) - return error_value(errno); - if (i < 0) - return error_value(E_SEARCH_6); - if (i == 0) { - result.v_type = V_NUM; - result.v_num = qalloc(); - result.v_num->num = indx; - } - return result; - } - if (start == NULL) - start = qlink(&_qzero_); - if (end == NULL) - end = qlink(size); - if (qrel(start, end) >= 0) { - qfree(size); - qfree(start); - qfree(end); - return result; - } - qfree(size); - l_start = ztolong(start->num); - l_end = ztolong(end->num); - switch (v1->v_type) { - case V_MAT: - i = matsearch(v1->v_mat, v2, l_start, l_end, &indx); - break; - case V_LIST: - i = listsearch(v1->v_list, v2, l_start, l_end, &indx); - break; - case V_ASSOC: - i = assocsearch(v1->v_assoc, v2, l_start, l_end, &indx); - break; - case V_STR: - i = stringsearch(v1->v_str, v2->v_str, l_start, l_end, - &indx); - break; - default: - qfree(start); - qfree(end); - return error_value(E_SEARCH_1); - } - qfree(start); - qfree(end); - if (i == 0) { - result.v_type = V_NUM; - result.v_num = qalloc(); - result.v_num->num = indx; - } - return result; + v1 = *vals++; + v2 = *vals++; + if ((v1->v_type == V_FILE || v1->v_type == V_STR) && + v2->v_type != V_STR) + return error_value(E_SEARCH_2); + start = end = NULL; + if (count > 2) { + v3 = *vals++; + if (v3->v_type != V_NUM && v3->v_type != V_NULL) + return error_value(E_SEARCH_3); + if (v3->v_type == V_NUM) { + start = v3->v_num; + if (qisfrac(start)) + return error_value(E_SEARCH_3); + } + } + if (count > 3) { + v4 = *vals; + if (v4->v_type != V_NUM && v4->v_type != V_NULL) + return error_value(E_SEARCH_4); + if (v4->v_type == V_NUM) { + end = v4->v_num; + if (qisfrac(end)) + return error_value(E_SEARCH_4); + } + } + result.v_type = V_NULL; + vsize = f_size(v1); + if (vsize.v_type != V_NUM) + return error_value(E_SEARCH_5); + size = vsize.v_num; + if (start) { + if (qisneg(start)) { + start = qqadd(size, start); + if (qisneg(start)) { + qfree(start); + start = qlink(&_qzero_); + } + } else { + start = qlink(start); + } + } + if (end) { + if (!qispos(end)) { + end = qqadd(size, end); + } else { + if (qrel(end, size) > 0) + end = qlink(size); + else + end = qlink(end); + } + } + if (v1->v_type == V_FILE) { + if (count == 2|| (count == 4 && + (start == NULL || end == NULL))) { + i = ftellid(v1->v_file, &pos); + if (i < 0) { + qfree(size); + if (start) + qfree(start); + if (end) + qfree(end); + return error_value(E_SEARCH_5); + } + if (count == 2 || (count == 4 && end != NULL)) { + start = qalloc(); + start->num = pos; + } else { + end = qalloc(); + end->num = pos; + } + } + if (start == NULL) + start = qlink(&_qzero_); + if (end == NULL) + end = size; + else + qfree(size); + len = v2->v_str->s_len; + utoz(len, &zlen); + zsub(end->num, zlen, &tmp); + zfree(zlen); + i = fsearch(v1->v_file, v2->v_str->s_str, + start->num, tmp, &indx); + zfree(tmp); + if (i == 2) { + result.v_type = V_NUM; + result.v_num = start; + qfree(end); + return result; + } + qfree(start); + qfree(end); + if (i == EOF) + return error_value(errno); + if (i < 0) + return error_value(E_SEARCH_6); + if (i == 0) { + result.v_type = V_NUM; + result.v_num = qalloc(); + result.v_num->num = indx; + } + return result; + } + if (start == NULL) + start = qlink(&_qzero_); + if (end == NULL) + end = qlink(size); + if (qrel(start, end) >= 0) { + qfree(size); + qfree(start); + qfree(end); + return result; + } + qfree(size); + l_start = ztolong(start->num); + l_end = ztolong(end->num); + switch (v1->v_type) { + case V_MAT: + i = matsearch(v1->v_mat, v2, l_start, l_end, &indx); + break; + case V_LIST: + i = listsearch(v1->v_list, v2, l_start, l_end, &indx); + break; + case V_ASSOC: + i = assocsearch(v1->v_assoc, v2, l_start, l_end, &indx); + break; + case V_STR: + i = stringsearch(v1->v_str, v2->v_str, l_start, l_end, + &indx); + break; + default: + qfree(start); + qfree(end); + return error_value(E_SEARCH_1); + } + qfree(start); + qfree(end); + if (i == 0) { + result.v_type = V_NUM; + result.v_num = qalloc(); + result.v_num->num = indx; + } + return result; } S_FUNC VALUE f_rsearch(int count, VALUE **vals) { - VALUE *v1, *v2, *v3, *v4; - NUMBER *start, *end; - VALUE vsize; - NUMBER *size; - NUMBER *qlen; - NUMBER *qtmp; - ZVALUE pos; - ZVALUE indx; - VALUE result; - long l_start = 0, l_end = 0; - int i; + VALUE *v1, *v2, *v3, *v4; + NUMBER *start, *end; + VALUE vsize; + NUMBER *size; + NUMBER *qlen; + NUMBER *qtmp; + ZVALUE pos; + ZVALUE indx; + VALUE result; + long l_start = 0, l_end = 0; + int i; - /* initialize VALUEs */ - vsize.v_subtype = V_NOSUBTYPE; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + vsize.v_subtype = V_NOSUBTYPE; + result.v_subtype = V_NOSUBTYPE; - v1 = *vals++; - v2 = *vals++; - if ((v1->v_type == V_FILE || v1->v_type == V_STR) && - v2->v_type != V_STR) - return error_value(E_RSEARCH_2); - start = end = NULL; - if (count > 2) { - v3 = *vals++; - if (v3->v_type != V_NUM && v3->v_type != V_NULL) - return error_value(E_RSEARCH_3); - if (v3->v_type == V_NUM) { - start = v3->v_num; - if (qisfrac(start)) - return error_value(E_RSEARCH_3); - } - } - if (count > 3) { - v4 = *vals; - if (v4->v_type != V_NUM && v4->v_type != V_NULL) - return error_value(E_RSEARCH_4); - if (v4->v_type == V_NUM) { - end = v4->v_num; - if (qisfrac(end)) - return error_value(E_RSEARCH_3); - } - } - result.v_type = V_NULL; - vsize = f_size(v1); - if (vsize.v_type != V_NUM) - return error_value(E_RSEARCH_5); - size = vsize.v_num; - if (start) { - if (qisneg(start)) { - start = qqadd(size, start); - if (qisneg(start)) { - qfree(start); - start = qlink(&_qzero_); - } - } - else - start = qlink(start); - } - if (end) { - if (!qispos(end)) { - end = qqadd(size, end); - } else { - if (qrel(end, size) > 0) - end = qlink(size); - else - end = qlink(end); - } - } - if (v1->v_type == V_FILE) { - if (count == 2 || (count == 4 && - (start == NULL || end == NULL))) { - i = ftellid(v1->v_file, &pos); - if (i < 0) { - qfree(size); - if (start) - qfree(start); - if (end) - qfree(end); - return error_value(E_RSEARCH_5); - } - if (count == 2 || (count == 4 && end != NULL)) { - start = qalloc(); - start->num = pos; - } else { - end = qalloc(); - end->num = pos; - } - } - qlen = utoq(v2->v_str->s_len); - qtmp = qsub(size, qlen); - qfree(size); - size = qtmp; - if (count < 4) { - end = start; - start = NULL; - } else { - qtmp = qsub(end, qlen); - qfree(end); - end = qtmp; - } - if (end == NULL) - end = qlink(size); - if (start == NULL) - start = qlink(&_qzero_); - if (qrel(end, size) > 0) { - qfree(end); - end = qlink(size); - } - qfree(qlen); - qfree(size); - if (qrel(start, end) > 0) { - qfree(start); - qfree(end); - return result; - } - i = frsearch(v1->v_file, v2->v_str->s_str, - end->num,start->num, &indx); - qfree(start); - qfree(end); - if (i == EOF) - return error_value(errno); - if (i < 0) - return error_value(E_RSEARCH_6); - if (i == 0) { - result.v_type = V_NUM; - result.v_num = qalloc(); - result.v_num->num = indx; - } - return result; - } - if (count < 4) { - if (start) { - end = qinc(start); - qfree(start); - } - else - end = qlink(size); - start = qlink(&_qzero_); - } else { - if (start == NULL) - start = qlink(&_qzero_); - if (end == NULL) - end = qlink(size); - } + v1 = *vals++; + v2 = *vals++; + if ((v1->v_type == V_FILE || v1->v_type == V_STR) && + v2->v_type != V_STR) + return error_value(E_RSEARCH_2); + start = end = NULL; + if (count > 2) { + v3 = *vals++; + if (v3->v_type != V_NUM && v3->v_type != V_NULL) + return error_value(E_RSEARCH_3); + if (v3->v_type == V_NUM) { + start = v3->v_num; + if (qisfrac(start)) + return error_value(E_RSEARCH_3); + } + } + if (count > 3) { + v4 = *vals; + if (v4->v_type != V_NUM && v4->v_type != V_NULL) + return error_value(E_RSEARCH_4); + if (v4->v_type == V_NUM) { + end = v4->v_num; + if (qisfrac(end)) + return error_value(E_RSEARCH_3); + } + } + result.v_type = V_NULL; + vsize = f_size(v1); + if (vsize.v_type != V_NUM) + return error_value(E_RSEARCH_5); + size = vsize.v_num; + if (start) { + if (qisneg(start)) { + start = qqadd(size, start); + if (qisneg(start)) { + qfree(start); + start = qlink(&_qzero_); + } + } + else + start = qlink(start); + } + if (end) { + if (!qispos(end)) { + end = qqadd(size, end); + } else { + if (qrel(end, size) > 0) + end = qlink(size); + else + end = qlink(end); + } + } + if (v1->v_type == V_FILE) { + if (count == 2 || (count == 4 && + (start == NULL || end == NULL))) { + i = ftellid(v1->v_file, &pos); + if (i < 0) { + qfree(size); + if (start) + qfree(start); + if (end) + qfree(end); + return error_value(E_RSEARCH_5); + } + if (count == 2 || (count == 4 && end != NULL)) { + start = qalloc(); + start->num = pos; + } else { + end = qalloc(); + end->num = pos; + } + } + qlen = utoq(v2->v_str->s_len); + qtmp = qsub(size, qlen); + qfree(size); + size = qtmp; + if (count < 4) { + end = start; + start = NULL; + } else { + qtmp = qsub(end, qlen); + qfree(end); + end = qtmp; + } + if (end == NULL) + end = qlink(size); + if (start == NULL) + start = qlink(&_qzero_); + if (qrel(end, size) > 0) { + qfree(end); + end = qlink(size); + } + qfree(qlen); + qfree(size); + if (qrel(start, end) > 0) { + qfree(start); + qfree(end); + return result; + } + i = frsearch(v1->v_file, v2->v_str->s_str, + end->num,start->num, &indx); + qfree(start); + qfree(end); + if (i == EOF) + return error_value(errno); + if (i < 0) + return error_value(E_RSEARCH_6); + if (i == 0) { + result.v_type = V_NUM; + result.v_num = qalloc(); + result.v_num->num = indx; + } + return result; + } + if (count < 4) { + if (start) { + end = qinc(start); + qfree(start); + } + else + end = qlink(size); + start = qlink(&_qzero_); + } else { + if (start == NULL) + start = qlink(&_qzero_); + if (end == NULL) + end = qlink(size); + } - qfree(size); - if (qrel(start, end) >= 0) { - qfree(start); - qfree(end); - return result; - } - l_start = ztolong(start->num); - l_end = ztolong(end->num); - switch (v1->v_type) { - case V_MAT: - i = matrsearch(v1->v_mat, v2, l_start, l_end, &indx); - break; - case V_LIST: - i = listrsearch(v1->v_list, v2, l_start, l_end, &indx); - break; - case V_ASSOC: - i = assocrsearch(v1->v_assoc, v2, l_start, - l_end, &indx); - break; - case V_STR: - i = stringrsearch(v1->v_str, v2->v_str, l_start, - l_end, &indx); - break; - default: - qfree(start); - qfree(end); - return error_value(E_RSEARCH_1); - } - qfree(start); - qfree(end); - if (i == 0) { - result.v_type = V_NUM; - result.v_num = qalloc(); - result.v_num->num = indx; - } - return result; + qfree(size); + if (qrel(start, end) >= 0) { + qfree(start); + qfree(end); + return result; + } + l_start = ztolong(start->num); + l_end = ztolong(end->num); + switch (v1->v_type) { + case V_MAT: + i = matrsearch(v1->v_mat, v2, l_start, l_end, &indx); + break; + case V_LIST: + i = listrsearch(v1->v_list, v2, l_start, l_end, &indx); + break; + case V_ASSOC: + i = assocrsearch(v1->v_assoc, v2, l_start, + l_end, &indx); + break; + case V_STR: + i = stringrsearch(v1->v_str, v2->v_str, l_start, + l_end, &indx); + break; + default: + qfree(start); + qfree(end); + return error_value(E_RSEARCH_1); + } + qfree(start); + qfree(end); + if (i == 0) { + result.v_type = V_NUM; + result.v_num = qalloc(); + result.v_num->num = indx; + } + return result; } S_FUNC VALUE f_list(int count, VALUE **vals) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_type = V_LIST; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_LIST; + result.v_subtype = V_NOSUBTYPE; - result.v_list = listalloc(); - while (count-- > 0) - insertlistlast(result.v_list, *vals++); - return result; + result.v_list = listalloc(); + while (count-- > 0) + insertlistlast(result.v_list, *vals++); + return result; } @@ -7501,184 +7501,184 @@ f_list(int count, VALUE **vals) S_FUNC VALUE f_assoc(int UNUSED(count), VALUE **UNUSED(vals)) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_type = V_ASSOC; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_ASSOC; + result.v_subtype = V_NOSUBTYPE; - result.v_assoc = assocalloc(0L); - return result; + result.v_assoc = assocalloc(0L); + return result; } S_FUNC VALUE f_indices(VALUE *v1, VALUE *v2) { - VALUE result; - LIST *lp; + VALUE result; + LIST *lp; - if (v2->v_type != V_NUM || zge31b(v2->v_num->num)) - return error_value(E_INDICES_2); + if (v2->v_type != V_NUM || zge31b(v2->v_num->num)) + return error_value(E_INDICES_2); - switch (v1->v_type) { - case V_ASSOC: - lp = associndices(v1->v_assoc, qtoi(v2->v_num)); - break; - case V_MAT: - lp = matindices(v1->v_mat, qtoi(v2->v_num)); - break; - default: - return error_value(E_INDICES_1); - } + switch (v1->v_type) { + case V_ASSOC: + lp = associndices(v1->v_assoc, qtoi(v2->v_num)); + break; + case V_MAT: + lp = matindices(v1->v_mat, qtoi(v2->v_num)); + break; + default: + return error_value(E_INDICES_1); + } - result.v_type = V_NULL; - result.v_subtype = V_NOSUBTYPE; - if (lp) { - result.v_type = V_LIST; - result.v_list = lp; - } - return result; + result.v_type = V_NULL; + result.v_subtype = V_NOSUBTYPE; + if (lp) { + result.v_type = V_LIST; + result.v_list = lp; + } + return result; } S_FUNC VALUE f_listinsert(int count, VALUE **vals) { - VALUE *v1, *v2, *v3; - VALUE result; - long pos; + VALUE *v1, *v2, *v3; + VALUE result; + long pos; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - v1 = *vals++; - if ((v1->v_type != V_ADDR) || (v1->v_addr->v_type != V_LIST)) - return error_value(E_INSERT_1); - if (v1->v_addr->v_subtype & V_NOREALLOC) - return error_value(E_LIST_1); + v1 = *vals++; + if ((v1->v_type != V_ADDR) || (v1->v_addr->v_type != V_LIST)) + return error_value(E_INSERT_1); + if (v1->v_addr->v_subtype & V_NOREALLOC) + return error_value(E_LIST_1); - v2 = *vals++; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if ((v2->v_type != V_NUM) || qisfrac(v2->v_num)) - return error_value(E_INSERT_2); - pos = qtoi(v2->v_num); - count--; - while (--count > 0) { - v3 = *vals++; - if (v3->v_type == V_ADDR) - v3 = v3->v_addr; - insertlistmiddle(v1->v_addr->v_list, pos++, v3); - } - result.v_type = V_NULL; - return result; + v2 = *vals++; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if ((v2->v_type != V_NUM) || qisfrac(v2->v_num)) + return error_value(E_INSERT_2); + pos = qtoi(v2->v_num); + count--; + while (--count > 0) { + v3 = *vals++; + if (v3->v_type == V_ADDR) + v3 = v3->v_addr; + insertlistmiddle(v1->v_addr->v_list, pos++, v3); + } + result.v_type = V_NULL; + return result; } S_FUNC VALUE f_listpush(int count, VALUE **vals) { - VALUE result; - VALUE *v1, *v2; + VALUE result; + VALUE *v1, *v2; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - v1 = *vals++; - if ((v1->v_type != V_ADDR) || (v1->v_addr->v_type != V_LIST)) - return error_value(E_PUSH); - if (v1->v_addr->v_subtype & V_NOREALLOC) - return error_value(E_LIST_3); + v1 = *vals++; + if ((v1->v_type != V_ADDR) || (v1->v_addr->v_type != V_LIST)) + return error_value(E_PUSH); + if (v1->v_addr->v_subtype & V_NOREALLOC) + return error_value(E_LIST_3); - while (--count > 0) { - v2 = *vals++; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - insertlistfirst(v1->v_addr->v_list, v2); - } - result.v_type = V_NULL; - return result; + while (--count > 0) { + v2 = *vals++; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + insertlistfirst(v1->v_addr->v_list, v2); + } + result.v_type = V_NULL; + return result; } S_FUNC VALUE f_listappend(int count, VALUE **vals) { - VALUE *v1, *v2; - VALUE result; + VALUE *v1, *v2; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - v1 = *vals++; - if ((v1->v_type != V_ADDR) || (v1->v_addr->v_type != V_LIST)) - return error_value(E_APPEND); - if (v1->v_addr->v_subtype & V_NOREALLOC) - return error_value(E_LIST_4); + v1 = *vals++; + if ((v1->v_type != V_ADDR) || (v1->v_addr->v_type != V_LIST)) + return error_value(E_APPEND); + if (v1->v_addr->v_subtype & V_NOREALLOC) + return error_value(E_LIST_4); - while (--count > 0) { - v2 = *vals++; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - insertlistlast(v1->v_addr->v_list, v2); - } - result.v_type = V_NULL; - return result; + while (--count > 0) { + v2 = *vals++; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + insertlistlast(v1->v_addr->v_list, v2); + } + result.v_type = V_NULL; + return result; } S_FUNC VALUE f_listdelete(VALUE *v1, VALUE *v2) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if ((v1->v_type != V_ADDR) || (v1->v_addr->v_type != V_LIST)) - return error_value(E_DELETE_1); - if (v1->v_addr->v_subtype & V_NOREALLOC) - return error_value(E_LIST_2); + if ((v1->v_type != V_ADDR) || (v1->v_addr->v_type != V_LIST)) + return error_value(E_DELETE_1); + if (v1->v_addr->v_subtype & V_NOREALLOC) + return error_value(E_LIST_2); - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if ((v2->v_type != V_NUM) || qisfrac(v2->v_num)) - return error_value(E_DELETE_2); - removelistmiddle(v1->v_addr->v_list, qtoi(v2->v_num), &result); - return result; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if ((v2->v_type != V_NUM) || qisfrac(v2->v_num)) + return error_value(E_DELETE_2); + removelistmiddle(v1->v_addr->v_list, qtoi(v2->v_num), &result); + return result; } S_FUNC VALUE f_listpop(VALUE *vp) { - VALUE result; + VALUE result; - if ((vp->v_type != V_ADDR) || (vp->v_addr->v_type != V_LIST)) - return error_value(E_POP); + if ((vp->v_type != V_ADDR) || (vp->v_addr->v_type != V_LIST)) + return error_value(E_POP); - if (vp->v_addr->v_subtype & V_NOREALLOC) - return error_value(E_LIST_5); + if (vp->v_addr->v_subtype & V_NOREALLOC) + return error_value(E_LIST_5); - removelistfirst(vp->v_addr->v_list, &result); - return result; + removelistfirst(vp->v_addr->v_list, &result); + return result; } S_FUNC VALUE f_listremove(VALUE *vp) { - VALUE result; + VALUE result; - if ((vp->v_type != V_ADDR) || (vp->v_addr->v_type != V_LIST)) - return error_value(E_REMOVE); + if ((vp->v_type != V_ADDR) || (vp->v_addr->v_type != V_LIST)) + return error_value(E_REMOVE); - if (vp->v_addr->v_subtype & V_NOREALLOC) - return error_value(E_LIST_6); + if (vp->v_addr->v_subtype & V_NOREALLOC) + return error_value(E_LIST_6); - removelistlast(vp->v_addr->v_list, &result); - return result; + removelistlast(vp->v_addr->v_list, &result); + return result; } @@ -7689,33 +7689,33 @@ S_FUNC NUMBER * f_usertime(void) { #if defined(HAVE_GETRUSAGE) - struct rusage usage; /* system resource usage */ - int who = RUSAGE_SELF; /* obtain time for just this process */ - int status; /* getrusage() return code */ - NUMBER *ret; /* CPU time to return */ - NUMBER *secret; /* whole seconds of CPU time to return */ - NUMBER *usecret; /* microseconds of CPU time to return */ + struct rusage usage; /* system resource usage */ + int who = RUSAGE_SELF; /* obtain time for just this process */ + int status; /* getrusage() return code */ + NUMBER *ret; /* CPU time to return */ + NUMBER *secret; /* whole seconds of CPU time to return */ + NUMBER *usecret; /* microseconds of CPU time to return */ - /* get the resource information for ourself */ - status = getrusage(who, &usage); - if (status < 0) { - /* system call error, so return 0 */ - return qlink(&_qzero_); - } + /* get the resource information for ourself */ + status = getrusage(who, &usage); + if (status < 0) { + /* system call error, so return 0 */ + return qlink(&_qzero_); + } - /* add user time */ - secret = stoq(usage.ru_utime.tv_sec); - usecret = iitoq((long)usage.ru_utime.tv_usec, 1000000L); - ret = qqadd(secret, usecret); - qfree(secret); - qfree(usecret); + /* add user time */ + secret = stoq(usage.ru_utime.tv_sec); + usecret = iitoq((long)usage.ru_utime.tv_usec, 1000000L); + ret = qqadd(secret, usecret); + qfree(secret); + qfree(usecret); - /* return user CPU time */ - return ret; + /* return user CPU time */ + return ret; #else /* HAVE_GETRUSAGE */ - /* not a POSIX system */ - return qlink(&_qzero_); + /* not a POSIX system */ + return qlink(&_qzero_); #endif /* HAVE_GETRUSAGE */ } @@ -7728,33 +7728,33 @@ S_FUNC NUMBER * f_systime(void) { #if defined(HAVE_GETRUSAGE) - struct rusage usage; /* system resource usage */ - int who = RUSAGE_SELF; /* obtain time for just this process */ - int status; /* getrusage() return code */ - NUMBER *ret; /* CPU time to return */ - NUMBER *secret; /* whole seconds of CPU time to return */ - NUMBER *usecret; /* microseconds of CPU time to return */ + struct rusage usage; /* system resource usage */ + int who = RUSAGE_SELF; /* obtain time for just this process */ + int status; /* getrusage() return code */ + NUMBER *ret; /* CPU time to return */ + NUMBER *secret; /* whole seconds of CPU time to return */ + NUMBER *usecret; /* microseconds of CPU time to return */ - /* get the resource information for ourself */ - status = getrusage(who, &usage); - if (status < 0) { - /* system call error, so return 0 */ - return qlink(&_qzero_); - } + /* get the resource information for ourself */ + status = getrusage(who, &usage); + if (status < 0) { + /* system call error, so return 0 */ + return qlink(&_qzero_); + } - /* add kernel time */ - secret = stoq(usage.ru_stime.tv_sec); - usecret = iitoq((long)usage.ru_stime.tv_usec, 1000000L); - ret = qqadd(secret, usecret); - qfree(secret); - qfree(usecret); + /* add kernel time */ + secret = stoq(usage.ru_stime.tv_sec); + usecret = iitoq((long)usage.ru_stime.tv_usec, 1000000L); + ret = qqadd(secret, usecret); + qfree(secret); + qfree(usecret); - /* return kernel CPU time */ - return ret; + /* return kernel CPU time */ + return ret; #else /* HAVE_GETRUSAGE */ - /* not a POSIX system */ - return qlink(&_qzero_); + /* not a POSIX system */ + return qlink(&_qzero_); #endif /* HAVE_GETRUSAGE */ } @@ -7766,47 +7766,47 @@ S_FUNC NUMBER * f_runtime(void) { #if defined(HAVE_GETRUSAGE) - struct rusage usage; /* system resource usage */ - int who = RUSAGE_SELF; /* obtain time for just this process */ - int status; /* getrusage() return code */ - NUMBER *user; /* user CPU time to return */ - NUMBER *sys; /* kernel CPU time to return */ - NUMBER *ret; /* total CPU time to return */ - NUMBER *secret; /* whole seconds of CPU time to return */ - NUMBER *usecret; /* microseconds of CPU time to return */ + struct rusage usage; /* system resource usage */ + int who = RUSAGE_SELF; /* obtain time for just this process */ + int status; /* getrusage() return code */ + NUMBER *user; /* user CPU time to return */ + NUMBER *sys; /* kernel CPU time to return */ + NUMBER *ret; /* total CPU time to return */ + NUMBER *secret; /* whole seconds of CPU time to return */ + NUMBER *usecret; /* microseconds of CPU time to return */ - /* get the resource information for ourself */ - status = getrusage(who, &usage); - if (status < 0) { - /* system call error, so return 0 */ - return qlink(&_qzero_); - } + /* get the resource information for ourself */ + status = getrusage(who, &usage); + if (status < 0) { + /* system call error, so return 0 */ + return qlink(&_qzero_); + } - /* add kernel time */ - secret = stoq(usage.ru_stime.tv_sec); - usecret = iitoq((long)usage.ru_stime.tv_usec, 1000000L); - sys = qqadd(secret, usecret); - qfree(secret); - qfree(usecret); + /* add kernel time */ + secret = stoq(usage.ru_stime.tv_sec); + usecret = iitoq((long)usage.ru_stime.tv_usec, 1000000L); + sys = qqadd(secret, usecret); + qfree(secret); + qfree(usecret); - /* add user time */ - secret = stoq(usage.ru_utime.tv_sec); - usecret = iitoq((long)usage.ru_utime.tv_usec, 1000000L); - user = qqadd(secret, usecret); - qfree(secret); - qfree(usecret); + /* add user time */ + secret = stoq(usage.ru_utime.tv_sec); + usecret = iitoq((long)usage.ru_utime.tv_usec, 1000000L); + user = qqadd(secret, usecret); + qfree(secret); + qfree(usecret); - /* total time is user + kernel */ - ret = qqadd(user, sys); - qfree(user); - qfree(sys); + /* total time is user + kernel */ + ret = qqadd(user, sys); + qfree(user); + qfree(sys); - /* return CPU time */ - return ret; + /* return CPU time */ + return ret; #else /* HAVE_GETRUSAGE */ - /* not a POSIX system */ - return qlink(&_qzero_); + /* not a POSIX system */ + return qlink(&_qzero_); #endif /* HAVE_GETRUSAGE */ } @@ -7817,7 +7817,7 @@ f_runtime(void) S_FUNC NUMBER * f_time(void) { - return itoq((long) time(0)); + return itoq((long) time(0)); } @@ -7827,2349 +7827,2349 @@ f_time(void) S_FUNC VALUE f_ctime(void) { - VALUE res; - time_t now; /* the current time */ + VALUE res; + time_t now; /* the current time */ - /* initialize VALUE */ - res.v_subtype = V_NOSUBTYPE; - res.v_type = V_STR; + /* initialize VALUE */ + res.v_subtype = V_NOSUBTYPE; + res.v_type = V_STR; - /* get the time */ - now = time(NULL); - res.v_str = makenewstring(ctime(&now)); - return res; + /* get the time */ + now = time(NULL); + res.v_str = makenewstring(ctime(&now)); + return res; } S_FUNC VALUE f_fopen(VALUE *v1, VALUE *v2) { - VALUE result; - FILEID id; - char *mode; + VALUE result; + FILEID id; + char *mode; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* check for a valid mode [rwa][b+\0][b+\0] */ - if (v1->v_type != V_STR || v2->v_type != V_STR) - return error_value(E_FOPEN_1); - mode = v2->v_str->s_str; - if ((*mode != 'r') && (*mode != 'w') && (*mode != 'a')) - return error_value(E_FOPEN_2); - if (mode[1] != '\0') { - if (mode[1] != '+' && mode[1] != 'b') - return error_value(E_FOPEN_2); - if (mode[2] != '\0') { - if ((mode[2] != '+' && mode[2] != 'b') || - mode[1] == mode[2]) - return error_value(E_FOPEN_2); - if (mode[3] != '\0') - return error_value(E_FOPEN_2); - } - } + /* check for a valid mode [rwa][b+\0][b+\0] */ + if (v1->v_type != V_STR || v2->v_type != V_STR) + return error_value(E_FOPEN_1); + mode = v2->v_str->s_str; + if ((*mode != 'r') && (*mode != 'w') && (*mode != 'a')) + return error_value(E_FOPEN_2); + if (mode[1] != '\0') { + if (mode[1] != '+' && mode[1] != 'b') + return error_value(E_FOPEN_2); + if (mode[2] != '\0') { + if ((mode[2] != '+' && mode[2] != 'b') || + mode[1] == mode[2]) + return error_value(E_FOPEN_2); + if (mode[3] != '\0') + return error_value(E_FOPEN_2); + } + } - /* try to open */ - errno = 0; - id = openid(v1->v_str->s_str, v2->v_str->s_str); - if (id == FILEID_NONE) - return error_value(errno); - if (id < 0) - return error_value(-id); - result.v_type = V_FILE; - result.v_file = id; - return result; + /* try to open */ + errno = 0; + id = openid(v1->v_str->s_str, v2->v_str->s_str); + if (id == FILEID_NONE) + return error_value(errno); + if (id < 0) + return error_value(-id); + result.v_type = V_FILE; + result.v_file = id; + return result; } S_FUNC VALUE f_fpathopen(int count, VALUE **vals) { - VALUE result; - FILEID id; - char *mode; + VALUE result; + FILEID id; + char *mode; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* check for valid strong */ - if (vals[0]->v_type != V_STR || vals[1]->v_type != V_STR) { - return error_value(E_FPATHOPEN_1); - } - if (count == 3 && vals[2]->v_type != V_STR) { - return error_value(E_FPATHOPEN_1); - } + /* check for valid strong */ + if (vals[0]->v_type != V_STR || vals[1]->v_type != V_STR) { + return error_value(E_FPATHOPEN_1); + } + if (count == 3 && vals[2]->v_type != V_STR) { + return error_value(E_FPATHOPEN_1); + } - /* check for a valid mode [rwa][b+\0][b+\0] */ - mode = vals[1]->v_str->s_str; - if ((*mode != 'r') && (*mode != 'w') && (*mode != 'a')) - return error_value(E_FPATHOPEN_2); - if (mode[1] != '\0') { - if (mode[1] != '+' && mode[1] != 'b') - return error_value(E_FPATHOPEN_2); - if (mode[2] != '\0') { - if ((mode[2] != '+' && mode[2] != 'b') || - mode[1] == mode[2]) - return error_value(E_FPATHOPEN_2); - if (mode[3] != '\0') - return error_value(E_FPATHOPEN_2); - } - } + /* check for a valid mode [rwa][b+\0][b+\0] */ + mode = vals[1]->v_str->s_str; + if ((*mode != 'r') && (*mode != 'w') && (*mode != 'a')) + return error_value(E_FPATHOPEN_2); + if (mode[1] != '\0') { + if (mode[1] != '+' && mode[1] != 'b') + return error_value(E_FPATHOPEN_2); + if (mode[2] != '\0') { + if ((mode[2] != '+' && mode[2] != 'b') || + mode[1] == mode[2]) + return error_value(E_FPATHOPEN_2); + if (mode[3] != '\0') + return error_value(E_FPATHOPEN_2); + } + } - /* try to open along a path */ - errno = 0; - if (count == 2) { - id = openpathid(vals[0]->v_str->s_str, - vals[1]->v_str->s_str, - calcpath); - } else { - id = openpathid(vals[0]->v_str->s_str, - vals[1]->v_str->s_str, - vals[2]->v_str->s_str); - } - if (id == FILEID_NONE) - return error_value(errno); - if (id < 0) - return error_value(-id); - result.v_type = V_FILE; - result.v_file = id; - return result; + /* try to open along a path */ + errno = 0; + if (count == 2) { + id = openpathid(vals[0]->v_str->s_str, + vals[1]->v_str->s_str, + calcpath); + } else { + id = openpathid(vals[0]->v_str->s_str, + vals[1]->v_str->s_str, + vals[2]->v_str->s_str); + } + if (id == FILEID_NONE) + return error_value(errno); + if (id < 0) + return error_value(-id); + result.v_type = V_FILE; + result.v_file = id; + return result; } S_FUNC VALUE f_freopen(int count, VALUE **vals) { - VALUE result; - FILEID id; - char *mode; + VALUE result; + FILEID id; + char *mode; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* check for a valid mode [rwa][b+\0][b+\0] */ - if (vals[0]->v_type != V_FILE) - return error_value(E_FREOPEN_1); - if (vals[1]->v_type != V_STR) - return error_value(E_FREOPEN_2); - mode = vals[1]->v_str->s_str; - if ((*mode != 'r') && (*mode != 'w') && (*mode != 'a')) - return error_value(E_FREOPEN_2); - if (mode[1] != '\0') { - if (mode[1] != '+' && mode[1] != 'b') - return error_value(E_FREOPEN_2); - if (mode[2] != '\0') { - if ((mode[2] != '+' && mode[2] != 'b') || - mode[1] == mode[2]) - return error_value(E_FOPEN_2); - if (mode[3] != '\0') - return error_value(E_FREOPEN_2); - } - } + /* check for a valid mode [rwa][b+\0][b+\0] */ + if (vals[0]->v_type != V_FILE) + return error_value(E_FREOPEN_1); + if (vals[1]->v_type != V_STR) + return error_value(E_FREOPEN_2); + mode = vals[1]->v_str->s_str; + if ((*mode != 'r') && (*mode != 'w') && (*mode != 'a')) + return error_value(E_FREOPEN_2); + if (mode[1] != '\0') { + if (mode[1] != '+' && mode[1] != 'b') + return error_value(E_FREOPEN_2); + if (mode[2] != '\0') { + if ((mode[2] != '+' && mode[2] != 'b') || + mode[1] == mode[2]) + return error_value(E_FOPEN_2); + if (mode[3] != '\0') + return error_value(E_FREOPEN_2); + } + } - /* try to reopen */ - errno = 0; - if (count == 2) { - id = reopenid(vals[0]->v_file, mode, NULL); - } else { - if (vals[2]->v_type != V_STR) - return error_value(E_FREOPEN_3); - id = reopenid(vals[0]->v_file, mode, - vals[2]->v_str->s_str); - } + /* try to reopen */ + errno = 0; + if (count == 2) { + id = reopenid(vals[0]->v_file, mode, NULL); + } else { + if (vals[2]->v_type != V_STR) + return error_value(E_FREOPEN_3); + id = reopenid(vals[0]->v_file, mode, + vals[2]->v_str->s_str); + } - if (id == FILEID_NONE) - return error_value(errno); - result.v_type = V_NULL; - return result; + if (id == FILEID_NONE) + return error_value(errno); + result.v_type = V_NULL; + return result; } S_FUNC VALUE f_fclose(int count, VALUE **vals) { - VALUE result; - VALUE *vp; - int n, i=0; + VALUE result; + VALUE *vp; + int n, i=0; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - errno = 0; - if (count == 0) { - i = closeall(); - } else { - for (n = 0; n < count; n++) { - vp = vals[n]; - if (vp->v_type != V_FILE) - return error_value(E_FCLOSE_1); - } - for (n = 0; n < count; n++) { - vp = vals[n]; - i = closeid(vp->v_file); - if (i < 0) - return error_value(E_REWIND_2); - } - } - if (i < 0) - return error_value(errno); - result.v_type = V_NULL; - return result; + errno = 0; + if (count == 0) { + i = closeall(); + } else { + for (n = 0; n < count; n++) { + vp = vals[n]; + if (vp->v_type != V_FILE) + return error_value(E_FCLOSE_1); + } + for (n = 0; n < count; n++) { + vp = vals[n]; + i = closeid(vp->v_file); + if (i < 0) + return error_value(E_REWIND_2); + } + } + if (i < 0) + return error_value(errno); + result.v_type = V_NULL; + return result; } S_FUNC VALUE f_rm(int count, VALUE **vals) { - VALUE result; - int force; /* true -> -f was given as 1st arg */ - int i; - int j; + VALUE result; + int force; /* true -> -f was given as 1st arg */ + int i; + int j; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * firewall - */ - if (!allow_write) - return error_value(E_WRPERM); + /* + * firewall + */ + if (!allow_write) + return error_value(E_WRPERM); - /* - * check on each arg - */ - for (i=0; i < count; ++i) { - if (vals[i]->v_type != V_STR) - return error_value(E_RM_1); - if (vals[i]->v_str->s_str[0] == '\0') - return error_value(E_RM_1); - } + /* + * check on each arg + */ + for (i=0; i < count; ++i) { + if (vals[i]->v_type != V_STR) + return error_value(E_RM_1); + if (vals[i]->v_str->s_str[0] == '\0') + return error_value(E_RM_1); + } - /* - * look for a leading -f option - */ - force = (strcmp(vals[0]->v_str->s_str, "-f") == 0); - if (force) { - --count; - ++vals; - } + /* + * look for a leading -f option + */ + force = (strcmp(vals[0]->v_str->s_str, "-f") == 0); + if (force) { + --count; + ++vals; + } - /* - * remove file(s) - */ - for (i=0; i < count; ++i) { - j = remove(vals[i]->v_str->s_str); - if (!force && j < 0) - return error_value(errno); - } - result.v_type = V_NULL; - result.v_subtype = V_NOSUBTYPE; - return result; + /* + * remove file(s) + */ + for (i=0; i < count; ++i) { + j = remove(vals[i]->v_str->s_str); + if (!force && j < 0) + return error_value(errno); + } + result.v_type = V_NULL; + result.v_subtype = V_NOSUBTYPE; + return result; } S_FUNC VALUE f_error(int count, VALUE **vals) { - VALUE *vp; - long newerr; + VALUE *vp; + long newerr; - /* - * case: error() no args - */ - if (count == 0) { + /* + * case: error() no args + */ + if (count == 0) { - /* fetch but do NOT set errno */ - newerr = set_errno(NULL_ERRNUM); + /* fetch but do NOT set errno */ + newerr = set_errno(NULL_ERRNUM); - /* - * case: 1 arg - */ - } else { - vp = vals[0]; /* get 1st arg */ + /* + * case: 1 arg + */ + } else { + vp = vals[0]; /* get 1st arg */ - /* - * case: negative or 0 v_type - */ - if (vp->v_type <= 0) { - newerr = (long) -vp->v_type; - if (is_valid_errnum(newerr) == false) { - return error_value(E_ERROR_2); - } + /* + * case: negative or 0 v_type + */ + if (vp->v_type <= 0) { + newerr = (long) -vp->v_type; + if (is_valid_errnum(newerr) == false) { + return error_value(E_ERROR_2); + } - /* - * case: error(errnum | "E_STRING") arg - */ - } else { - switch (vp->v_type) { + /* + * case: error(errnum | "E_STRING") arg + */ + } else { + switch (vp->v_type) { - /* - * case: error("E_STRING") - */ - case V_STR: - newerr = errsym_2_errnum(vp->v_str->s_str); - if (is_valid_errnum(newerr) == false) { - return error_value(E_ERROR_3); - } - break; + /* + * case: error("E_STRING") + */ + case V_STR: + newerr = errsym_2_errnum(vp->v_str->s_str); + if (is_valid_errnum(newerr) == false) { + return error_value(E_ERROR_3); + } + break; - /* - * case: error(errnum) - */ - case V_NUM: - if (qisfrac(vp->v_num)) { - return error_value(E_ERROR_4); - } - newerr = qtoi(vp->v_num); - if (is_valid_errnum(newerr) == false) { - return error_value(E_ERROR_2); - } - break; + /* + * case: error(errnum) + */ + case V_NUM: + if (qisfrac(vp->v_num)) { + return error_value(E_ERROR_4); + } + newerr = qtoi(vp->v_num); + if (is_valid_errnum(newerr) == false) { + return error_value(E_ERROR_2); + } + break; - /* - * case: invalid type - */ - default: - return error_value(E_ERROR_1); - } - } - } + /* + * case: invalid type + */ + default: + return error_value(E_ERROR_1); + } + } + } - /* - * return error - */ - return error_value(newerr); + /* + * return error + */ + return error_value(newerr); } S_FUNC VALUE f_errno(int count, VALUE **vals) { - int olderr; /* previous errno value */ - int newerr = NULL_ERRNUM; /* new errno to set */ - VALUE *vp; /* arg[1] */ - VALUE result; /* errno as a VALUE */ + int olderr; /* previous errno value */ + int newerr = NULL_ERRNUM; /* new errno to set */ + VALUE *vp; /* arg[1] */ + VALUE result; /* errno as a VALUE */ - /* initialize VALUE */ - result.v_type = V_NUM; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NUM; + result.v_subtype = V_NOSUBTYPE; - /* - * case: errno() no args - */ - if (count == 0) { + /* + * case: errno() no args + */ + if (count == 0) { - /* fetch but do NOT set errno */ - olderr = set_errno(NULL_ERRNUM); + /* fetch but do NOT set errno */ + olderr = set_errno(NULL_ERRNUM); - /* - * case: 1 arg - */ - } else { - vp = vals[0]; /* get 1st arg */ + /* + * case: 1 arg + */ + } else { + vp = vals[0]; /* get 1st arg */ - /* - * case: negative or 0 v_type - */ - if (vp->v_type <= 0) { - newerr = (int) -vp->v_type; - if (is_valid_errnum(newerr) == false) { - return error_value(E_ERRNO_2); - } + /* + * case: negative or 0 v_type + */ + if (vp->v_type <= 0) { + newerr = (int) -vp->v_type; + if (is_valid_errnum(newerr) == false) { + return error_value(E_ERRNO_2); + } - /* - * case: errno(errnum | "E_STRING") arg - */ - } else { - switch (vp->v_type) { + /* + * case: errno(errnum | "E_STRING") arg + */ + } else { + switch (vp->v_type) { - /* - * case: errno("E_STRING") - */ - case V_STR: - newerr = errsym_2_errnum(vp->v_str->s_str); - if (is_valid_errnum(newerr) == false) { - return error_value(E_ERRNO_3); - } - break; + /* + * case: errno("E_STRING") + */ + case V_STR: + newerr = errsym_2_errnum(vp->v_str->s_str); + if (is_valid_errnum(newerr) == false) { + return error_value(E_ERRNO_3); + } + break; - /* - * case: errno(errnum) - */ - case V_NUM: - if (qisfrac(vp->v_num)) { - return error_value(E_ERRNO_4); - } - newerr = qtoi(vp->v_num); - if (is_valid_errnum(newerr) == false) { - return error_value(E_ERRNO_2); - } - break; + /* + * case: errno(errnum) + */ + case V_NUM: + if (qisfrac(vp->v_num)) { + return error_value(E_ERRNO_4); + } + newerr = qtoi(vp->v_num); + if (is_valid_errnum(newerr) == false) { + return error_value(E_ERRNO_2); + } + break; - /* - * case: invalid type - */ - default: - return error_value(E_ERRNO_1); - } - } - } + /* + * case: invalid type + */ + default: + return error_value(E_ERRNO_1); + } + } + } - /* - * return errno - */ - olderr = set_errno(newerr); - result.v_num = itoq((long) olderr); - return result; + /* + * return errno + */ + olderr = set_errno(newerr); + result.v_num = itoq((long) olderr); + return result; } S_FUNC VALUE f_strerror(int count, VALUE **vals) { - int errnum = NULL_ERRNUM; /* errnum to convert */ - char *errmsg; /* errnum converted into errmsg string, or NULL */ - bool alloced = false; /* true ==> errmsg was allocated, false ==> errmsg is static */ - VALUE *vp; /* arg[1] */ - VALUE result; /* errmsg string as a VALUE */ + int errnum = NULL_ERRNUM; /* errnum to convert */ + char *errmsg; /* errnum converted into errmsg string, or NULL */ + bool alloced = false; /* true ==> errmsg was allocated, false ==> errmsg is static */ + VALUE *vp; /* arg[1] */ + VALUE result; /* errmsg string as a VALUE */ - /* initialize VALUE */ - result.v_type = V_STR; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_STR; + result.v_subtype = V_NOSUBTYPE; - /* - * case: strerror() no args - */ - if (count == 0) { + /* + * case: strerror() no args + */ + if (count == 0) { - /* fetch but do NOT set errno */ - errnum = set_errno(NULL_ERRNUM); + /* fetch but do NOT set errno */ + errnum = set_errno(NULL_ERRNUM); - /* - * case: 1 arg - */ - } else { - vp = vals[0]; /* get 1st arg */ + /* + * case: 1 arg + */ + } else { + vp = vals[0]; /* get 1st arg */ - /* - * case: negative or 0 v_type - */ - if (vp->v_type <= 0) { - errnum = (int) -vp->v_type; - if (is_valid_errnum(errnum) == false) { - return error_value(E_STRERROR_2); - } + /* + * case: negative or 0 v_type + */ + if (vp->v_type <= 0) { + errnum = (int) -vp->v_type; + if (is_valid_errnum(errnum) == false) { + return error_value(E_STRERROR_2); + } - /* - * case: strerror(errnum | "E_STRING") arg - */ - } else { - switch (vp->v_type) { + /* + * case: strerror(errnum | "E_STRING") arg + */ + } else { + switch (vp->v_type) { - /* - * case: strerror("E_STRING") - */ - case V_STR: - errnum = errsym_2_errnum(vp->v_str->s_str); - if (is_valid_errnum(errnum) == false) { - return error_value(E_STRERROR_3); - } - break; + /* + * case: strerror("E_STRING") + */ + case V_STR: + errnum = errsym_2_errnum(vp->v_str->s_str); + if (is_valid_errnum(errnum) == false) { + return error_value(E_STRERROR_3); + } + break; - /* - * case: strerror(errnum) - */ - case V_NUM: - if (qisfrac(vp->v_num)) { - return error_value(E_STRERROR_5); - } - errnum = qtoi(vp->v_num); - if (is_valid_errnum(errnum) == false) { - return error_value(E_STRERROR_2); - } - break; + /* + * case: strerror(errnum) + */ + case V_NUM: + if (qisfrac(vp->v_num)) { + return error_value(E_STRERROR_5); + } + errnum = qtoi(vp->v_num); + if (is_valid_errnum(errnum) == false) { + return error_value(E_STRERROR_2); + } + break; - /* - * case: invalid type - */ - default: - return error_value(E_STRERROR_1); - } - } - } + /* + * case: invalid type + */ + default: + return error_value(E_STRERROR_1); + } + } + } - /* - * convert errnum into errmsg string - */ - errmsg = errnum_2_errmsg(errnum, &alloced); - if (errmsg == NULL) { - /* this should not happen: but in case it does we will throw an error */ - return error_value(E_STRERROR_4); - } - result.v_str = makenewstring(errmsg); + /* + * convert errnum into errmsg string + */ + errmsg = errnum_2_errmsg(errnum, &alloced); + if (errmsg == NULL) { + /* this should not happen: but in case it does we will throw an error */ + return error_value(E_STRERROR_4); + } + result.v_str = makenewstring(errmsg); - /* - * free errmsg is it was allocated - */ - if (alloced == true) { - free(errmsg); - alloced = false; - errmsg = NULL; - } + /* + * free errmsg is it was allocated + */ + if (alloced == true) { + free(errmsg); + alloced = false; + errmsg = NULL; + } - /* - * return errmsg result as a V_STR - */ - return result; + /* + * return errmsg result as a V_STR + */ + return result; } S_FUNC VALUE f_errsym(VALUE *vp) { - int errnum = NULL_ERRNUM; /* global calc_errno value */ - bool alloced = false; /* true ==> errsym is allocated, false ==> errsym is static */ - char *errsym; /* converted errsym or NULL */ - VALUE result; /* errno as a VALUE */ + int errnum = NULL_ERRNUM; /* global calc_errno value */ + bool alloced = false; /* true ==> errsym is allocated, false ==> errsym is static */ + char *errsym; /* converted errsym or NULL */ + VALUE result; /* errno as a VALUE */ - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * case: negative or 0 v_type OR errno(errnum) - */ - if (vp->v_type <= 0 || vp->v_type == V_NUM) { + /* + * case: negative or 0 v_type OR errno(errnum) + */ + if (vp->v_type <= 0 || vp->v_type == V_NUM) { - /* - * case: negative or 0 v_type - */ - if (vp->v_type <= 0) { + /* + * case: negative or 0 v_type + */ + if (vp->v_type <= 0) { - /* convert negative type into a errnum calc_errno-like value */ - errnum = (int) -vp->v_type; + /* convert negative type into a errnum calc_errno-like value */ + errnum = (int) -vp->v_type; - /* - * case: errno(errnum) - */ - } else { + /* + * case: errno(errnum) + */ + } else { - /* use arg[1] integer */ - if (qisfrac(vp->v_num)) { - return error_value(E_ERRSYM_4); - } - errnum = qtoi(vp->v_num); - } + /* use arg[1] integer */ + if (qisfrac(vp->v_num)) { + return error_value(E_ERRSYM_4); + } + errnum = qtoi(vp->v_num); + } - /* - * case: invalid errnum - */ - if (is_valid_errnum(errnum) == false) { - return error_value(E_ERRSYM_2); - } + /* + * case: invalid errnum + */ + if (is_valid_errnum(errnum) == false) { + return error_value(E_ERRSYM_2); + } - /* - * convert errnum code into errsym "E_STRING" - */ - errsym = errnum_2_errsym(errnum, &alloced); - if (errsym == NULL) { - return error_value(E_ERRSYM_5); - } - result.v_type = V_STR; - result.v_str = makenewstring(errsym); - if (alloced == true) { - free(errsym); - errsym = NULL; - alloced = false; - } + /* + * convert errnum code into errsym "E_STRING" + */ + errsym = errnum_2_errsym(errnum, &alloced); + if (errsym == NULL) { + return error_value(E_ERRSYM_5); + } + result.v_type = V_STR; + result.v_str = makenewstring(errsym); + if (alloced == true) { + free(errsym); + errsym = NULL; + alloced = false; + } - /* - * case: errno("E_STRING") arg - */ - } else if (vp->v_type == V_STR) { + /* + * case: errno("E_STRING") arg + */ + } else if (vp->v_type == V_STR) { - /* - * convert E_STRING errsym to errno - */ - errnum = errsym_2_errnum(vp->v_str->s_str); - if (is_valid_errnum(errnum) == false) { - return error_value(E_ERRSYM_3); - } - result.v_type = V_NUM; - result.v_num = itoq((long) errnum); - } + /* + * convert E_STRING errsym to errno + */ + errnum = errsym_2_errnum(vp->v_str->s_str); + if (is_valid_errnum(errnum) == false) { + return error_value(E_ERRSYM_3); + } + result.v_type = V_NUM; + result.v_num = itoq((long) errnum); + } - /* - * return result - */ - return result; + /* + * return result + */ + return result; } S_FUNC VALUE f_errcount(int count, VALUE **vals) { - int newcount, oldcount; - VALUE *vp; - VALUE result; + int newcount, oldcount; + VALUE *vp; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - newcount = -1; - if (count > 0) { - vp = vals[0]; + newcount = -1; + if (count > 0) { + vp = vals[0]; - /* arg must be an integer */ - if (vp->v_type != V_NUM || qisfrac(vp->v_num) || - qisneg(vp->v_num) || zge31b(vp->v_num->num)) { - math_error("errcount argument out of range"); - not_reached(); - } - newcount = (int) ztoi(vp->v_num->num); - } - oldcount = set_errcount(newcount); + /* arg must be an integer */ + if (vp->v_type != V_NUM || qisfrac(vp->v_num) || + qisneg(vp->v_num) || zge31b(vp->v_num->num)) { + math_error("errcount argument out of range"); + not_reached(); + } + newcount = (int) ztoi(vp->v_num->num); + } + oldcount = set_errcount(newcount); - result.v_type = V_NUM; - result.v_num = itoq((long) oldcount); - return result; + result.v_type = V_NUM; + result.v_num = itoq((long) oldcount); + return result; } S_FUNC VALUE f_errmax(int count, VALUE **vals) { - long oldmax; - VALUE *vp; - VALUE result; + long oldmax; + VALUE *vp; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - oldmax = errmax; - if (count > 0) { - vp = vals[0]; + oldmax = errmax; + if (count > 0) { + vp = vals[0]; - if (vp->v_type != V_NUM || qisfrac(vp->v_num) || - zge31b(vp->v_num->num) || zltnegone(vp->v_num->num)) { - fprintf(stderr, - "Out-of-range arg for errmax ignored\n"); - } else { - errmax = ztoi(vp->v_num->num); - } - } + if (vp->v_type != V_NUM || qisfrac(vp->v_num) || + zge31b(vp->v_num->num) || zltnegone(vp->v_num->num)) { + fprintf(stderr, + "Out-of-range arg for errmax ignored\n"); + } else { + errmax = ztoi(vp->v_num->num); + } + } - result.v_type = V_NUM; - result.v_num = itoq((long) oldmax); - return result; + result.v_type = V_NUM; + result.v_num = itoq((long) oldmax); + return result; } S_FUNC VALUE f_stoponerror(int count, VALUE **vals) { - long oldval; - VALUE *vp; - VALUE result; + long oldval; + VALUE *vp; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - oldval = stoponerror; - if (count > 0) { - vp = vals[0]; + oldval = stoponerror; + if (count > 0) { + vp = vals[0]; - if (vp->v_type != V_NUM || qisfrac(vp->v_num) || - zge31b(vp->v_num->num) || zltnegone(vp->v_num->num)) { - fprintf(stderr, - "Out-of-range arg for stoponerror ignored\n"); - } else { - stoponerror = ztoi(vp->v_num->num); - } - } + if (vp->v_type != V_NUM || qisfrac(vp->v_num) || + zge31b(vp->v_num->num) || zltnegone(vp->v_num->num)) { + fprintf(stderr, + "Out-of-range arg for stoponerror ignored\n"); + } else { + stoponerror = ztoi(vp->v_num->num); + } + } - result.v_type = V_NUM; - result.v_num = itoq((long) oldval); - return result; + result.v_type = V_NUM; + result.v_num = itoq((long) oldval); + return result; } S_FUNC VALUE f_iserror(VALUE *vp) { - VALUE res; + VALUE res; - /* initialize VALUE */ - res.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + res.v_subtype = V_NOSUBTYPE; - res.v_type = V_NUM; - res.v_num = itoq((long)((vp->v_type < 0) ? - vp->v_type : 0)); - return res; + res.v_type = V_NUM; + res.v_num = itoq((long)((vp->v_type < 0) ? - vp->v_type : 0)); + return res; } S_FUNC VALUE f_newerror(int count, VALUE **vals) { - char *str; - int index; - int errnum; + char *str; + int index; + int errnum; - str = NULL; - if (count > 0 && vals[0]->v_type == V_STR) - str = vals[0]->v_str->s_str; - if (str == NULL || str[0] == '\0') - str = "???"; - if (nexterrnum == E__USERDEF) - initstr(&newerrorstr); - index = findstr(&newerrorstr, str); - if (index >= 0) { - errnum = E__USERDEF + index; - } else { - if (nexterrnum == E__USERMAX) - math_error("Too many new error values"); - errnum = nexterrnum++; - addstr(&newerrorstr, str); - } - return error_value(errnum); + str = NULL; + if (count > 0 && vals[0]->v_type == V_STR) + str = vals[0]->v_str->s_str; + if (str == NULL || str[0] == '\0') + str = "???"; + if (nexterrnum == E__USERDEF) + initstr(&newerrorstr); + index = findstr(&newerrorstr, str); + if (index >= 0) { + errnum = E__USERDEF + index; + } else { + if (nexterrnum == E__USERMAX) + math_error("Too many new error values"); + errnum = nexterrnum++; + addstr(&newerrorstr, str); + } + return error_value(errnum); } S_FUNC VALUE f_ferror(VALUE *vp) { - VALUE result; - int i; + VALUE result; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vp->v_type != V_FILE) - return error_value(E_FERROR_1); - i = errorid(vp->v_file); - if (i < 0) - return error_value(E_FERROR_2); - result.v_type = V_NUM; - result.v_num = itoq((long) i); - return result; + if (vp->v_type != V_FILE) + return error_value(E_FERROR_1); + i = errorid(vp->v_file); + if (i < 0) + return error_value(E_FERROR_2); + result.v_type = V_NUM; + result.v_num = itoq((long) i); + return result; } S_FUNC VALUE f_feof(VALUE *vp) { - VALUE result; - int i; + VALUE result; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vp->v_type != V_FILE) - return error_value(E_FEOF_1); - i = eofid(vp->v_file); - if (i < 0) - return error_value(E_FEOF_2); - result.v_type = V_NUM; - result.v_num = itoq((long) i); - return result; + if (vp->v_type != V_FILE) + return error_value(E_FEOF_1); + i = eofid(vp->v_file); + if (i < 0) + return error_value(E_FEOF_2); + result.v_type = V_NUM; + result.v_num = itoq((long) i); + return result; } S_FUNC VALUE f_fflush(int count, VALUE **vals) { - VALUE result; - int i, n; + VALUE result; + int i, n; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - i = 0; - errno = 0; - if (count == 0) { + i = 0; + errno = 0; + if (count == 0) { #if !defined(_WIN32) && !defined(_WIN64) - i = flushall(); + i = flushall(); #endif /* Windows free systems */ - } else { - for (n = 0; n < count; n++) { - if (vals[n]->v_type != V_FILE) - return error_value(E_FFLUSH); - } - for (n = 0; n < count; n++) { - i |= flushid(vals[n]->v_file); - } - } - if (i == EOF) - return error_value(errno); - result.v_type = V_NULL; - return result; + } else { + for (n = 0; n < count; n++) { + if (vals[n]->v_type != V_FILE) + return error_value(E_FFLUSH); + } + for (n = 0; n < count; n++) { + i |= flushid(vals[n]->v_file); + } + } + if (i == EOF) + return error_value(errno); + result.v_type = V_NULL; + return result; } S_FUNC VALUE f_fsize(VALUE *vp) { - VALUE result; - ZVALUE len; /* file length */ - int i; + VALUE result; + ZVALUE len; /* file length */ + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vp->v_type != V_FILE) - return error_value(E_FSIZE_1); - i = getsize(vp->v_file, &len); - if (i == EOF) - return error_value(errno); - if (i) - return error_value(E_FSIZE_2); - result.v_type = V_NUM; - result.v_num = qalloc(); - result.v_num->num = len; - return result; + if (vp->v_type != V_FILE) + return error_value(E_FSIZE_1); + i = getsize(vp->v_file, &len); + if (i == EOF) + return error_value(errno); + if (i) + return error_value(E_FSIZE_2); + result.v_type = V_NUM; + result.v_num = qalloc(); + result.v_num->num = len; + return result; } S_FUNC VALUE f_fseek(int count, VALUE **vals) { - VALUE result; - int whence; - int i; + VALUE result; + int whence; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* firewalls */ - errno = 0; - if (vals[0]->v_type != V_FILE) - return error_value(E_FSEEK_1); - if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num)) - return error_value(E_FSEEK_2); - if (count == 2) { - whence = 0; - } else { - if (vals[2]->v_type != V_NUM || qisfrac(vals[2]->v_num) || - qisneg(vals[2]->v_num)) - return error_value(E_FSEEK_2); - if (vals[2]->v_num->num.len > 1) - return error_value (E_FSEEK_2); - whence = (int)(unsigned int)(vals[2]->v_num->num.v[0]); - if (whence > 2) - return error_value (E_FSEEK_2); - } + /* firewalls */ + errno = 0; + if (vals[0]->v_type != V_FILE) + return error_value(E_FSEEK_1); + if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num)) + return error_value(E_FSEEK_2); + if (count == 2) { + whence = 0; + } else { + if (vals[2]->v_type != V_NUM || qisfrac(vals[2]->v_num) || + qisneg(vals[2]->v_num)) + return error_value(E_FSEEK_2); + if (vals[2]->v_num->num.len > 1) + return error_value (E_FSEEK_2); + whence = (int)(unsigned int)(vals[2]->v_num->num.v[0]); + if (whence > 2) + return error_value (E_FSEEK_2); + } - i = fseekid(vals[0]->v_file, vals[1]->v_num->num, whence); - result.v_type = V_NULL; - if (i == EOF) - return error_value(errno); - if (i < 0) - return error_value(E_FSEEK_3); - return result; + i = fseekid(vals[0]->v_file, vals[1]->v_num->num, whence); + result.v_type = V_NULL; + if (i == EOF) + return error_value(errno); + if (i < 0) + return error_value(E_FSEEK_3); + return result; } S_FUNC VALUE f_ftell(VALUE *vp) { - VALUE result; - ZVALUE pos; /* current file position */ - int i; + VALUE result; + ZVALUE pos; /* current file position */ + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - errno = 0; - if (vp->v_type != V_FILE) - return error_value(E_FTELL_1); - i = ftellid(vp->v_file, &pos); - if (i < 0) - return error_value(E_FTELL_2); + errno = 0; + if (vp->v_type != V_FILE) + return error_value(E_FTELL_1); + i = ftellid(vp->v_file, &pos); + if (i < 0) + return error_value(E_FTELL_2); - result.v_type = V_NUM; - result.v_num = qalloc(); - result.v_num->num = pos; - return result; + result.v_type = V_NUM; + result.v_num = qalloc(); + result.v_num->num = pos; + return result; } S_FUNC VALUE f_rewind(int count, VALUE **vals) { - VALUE result; - int n; + VALUE result; + int n; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (count == 0) { - rewindall(); + if (count == 0) { + rewindall(); - } else { - for (n = 0; n < count; n++) { - if (vals[n]->v_type != V_FILE) - return error_value(E_REWIND_1); - } - for (n = 0; n < count; n++) { - if (rewindid(vals[n]->v_file) != 0) { - return error_value(E_REWIND_2); - } - } - } - result.v_type = V_NULL; - return result; + } else { + for (n = 0; n < count; n++) { + if (vals[n]->v_type != V_FILE) + return error_value(E_REWIND_1); + } + for (n = 0; n < count; n++) { + if (rewindid(vals[n]->v_file) != 0) { + return error_value(E_REWIND_2); + } + } + } + result.v_type = V_NULL; + return result; } S_FUNC VALUE f_fprintf(int count, VALUE **vals) { - VALUE result; - int i; + VALUE result; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vals[0]->v_type != V_FILE) - return error_value(E_FPRINTF_1); - if (vals[1]->v_type != V_STR) - return error_value(E_FPRINTF_2); - i = idprintf(vals[0]->v_file, vals[1]->v_str->s_str, - count - 2, vals + 2); - if (i > 0) - return error_value(E_FPRINTF_3); - result.v_type = V_NULL; - return result; + if (vals[0]->v_type != V_FILE) + return error_value(E_FPRINTF_1); + if (vals[1]->v_type != V_STR) + return error_value(E_FPRINTF_2); + i = idprintf(vals[0]->v_file, vals[1]->v_str->s_str, + count - 2, vals + 2); + if (i > 0) + return error_value(E_FPRINTF_3); + result.v_type = V_NULL; + return result; } S_FUNC int strscan(char *s, int count, VALUE **vals) { - char ch, chtmp; - char *s0; - int n = 0; - VALUE val, result; - VALUE *var; + char ch, chtmp; + char *s0; + int n = 0; + VALUE val, result; + VALUE *var; - /* initialize VALUEs */ - val.v_subtype = V_NOSUBTYPE; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + val.v_subtype = V_NOSUBTYPE; + result.v_subtype = V_NOSUBTYPE; - val.v_type = V_STR; - while (*s != '\0') { - s--; - while ((ch = *++s)) { - if (!isspace((int)ch)) - break; - } - if (ch == '\0' || count-- == 0) - return n; - s0 = s; - while ((ch = *++s)) { - if (isspace((int)ch)) - break; - } - chtmp = ch; - *s = '\0'; - n++; - val.v_str = makenewstring(s0); - result = f_eval(&val); - var = *vals++; - if (var->v_type == V_ADDR) { - var = var->v_addr; - freevalue(var); - *var = result; - } - *s = chtmp; - } - return n; + val.v_type = V_STR; + while (*s != '\0') { + s--; + while ((ch = *++s)) { + if (!isspace((int)ch)) + break; + } + if (ch == '\0' || count-- == 0) + return n; + s0 = s; + while ((ch = *++s)) { + if (isspace((int)ch)) + break; + } + chtmp = ch; + *s = '\0'; + n++; + val.v_str = makenewstring(s0); + result = f_eval(&val); + var = *vals++; + if (var->v_type == V_ADDR) { + var = var->v_addr; + freevalue(var); + *var = result; + } + *s = chtmp; + } + return n; } S_FUNC int filescan(FILEID id, int count, VALUE **vals) { - STRING *str; - int i; - int n = 0; - VALUE val; - VALUE result; - VALUE *var; + STRING *str; + int i; + int n = 0; + VALUE val; + VALUE result; + VALUE *var; - /* initialize VALUEs */ - val.v_type = V_STR; - val.v_subtype = V_NOSUBTYPE; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + val.v_type = V_STR; + val.v_subtype = V_NOSUBTYPE; + result.v_subtype = V_NOSUBTYPE; - while (count-- > 0) { + while (count-- > 0) { - i = readid(id, 6, &str); + i = readid(id, 6, &str); - if (i == EOF) - break; - if (i > 0) - return EOF; - n++; - val.v_str = str; - result = f_eval(&val); - var = *vals++; - if (var->v_type == V_ADDR) { - var = var->v_addr; - freevalue(var); - *var = result; - } - } - return n; + if (i == EOF) + break; + if (i > 0) + return EOF; + n++; + val.v_str = str; + result = f_eval(&val); + var = *vals++; + if (var->v_type == V_ADDR) { + var = var->v_addr; + freevalue(var); + *var = result; + } + } + return n; } S_FUNC VALUE f_scan(int count, VALUE **vals) { - char *cp; - VALUE result; - int i; + char *cp; + VALUE result; + int i; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; - cp = nextline(); - if (cp == NULL) { - result.v_type = V_NULL; - return result; - } + cp = nextline(); + if (cp == NULL) { + result.v_type = V_NULL; + return result; + } - i = strscan(cp, count, vals); - result.v_type = V_NUM; - result.v_num = itoq((long) i); - return result; + i = strscan(cp, count, vals); + result.v_type = V_NUM; + result.v_num = itoq((long) i); + return result; } S_FUNC VALUE f_strscan(int count, VALUE **vals) { - VALUE *vp; - VALUE result; - int i; + VALUE *vp; + VALUE result; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - vp = *vals; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type != V_STR) - return error_value(E_STRSCAN); + vp = *vals; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type != V_STR) + return error_value(E_STRSCAN); - i = strscan(vp->v_str->s_str, count - 1, vals + 1); + i = strscan(vp->v_str->s_str, count - 1, vals + 1); - result.v_type = V_NUM; - result.v_num = itoq((long) i); - return result; + result.v_type = V_NUM; + result.v_num = itoq((long) i); + return result; } S_FUNC VALUE f_fscan(int count, VALUE **vals) { - VALUE *vp; - VALUE result; - int i; + VALUE *vp; + VALUE result; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - errno = 0; - vp = *vals; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type != V_FILE) - return error_value(E_FSCAN_1); + errno = 0; + vp = *vals; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type != V_FILE) + return error_value(E_FSCAN_1); - i = filescan(vp->v_file, count - 1, vals + 1); + i = filescan(vp->v_file, count - 1, vals + 1); - if (i == EOF) - return error_value(errno); - if (i < 0) - return error_value(E_FSCAN_2); + if (i == EOF) + return error_value(errno); + if (i < 0) + return error_value(E_FSCAN_2); - result.v_type = V_NUM; - result.v_num = itoq((long) i); - return result; + result.v_type = V_NUM; + result.v_num = itoq((long) i); + return result; } S_FUNC VALUE f_scanf(int count, VALUE **vals) { - VALUE *vp; - VALUE result; - int i; + VALUE *vp; + VALUE result; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - vp = *vals; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type != V_STR) - return error_value(E_SCANF_1); - for (i = 1; i < count; i++) { - if (vals[i]->v_type != V_ADDR) - return error_value(E_SCANF_2); - } - i = fscanfid(FILEID_STDIN, vp->v_str->s_str, count - 1, vals + 1); - if (i < 0) - return error_value(E_SCANF_3); - result.v_type = V_NUM; - result.v_num = itoq((long) i); - return result; + vp = *vals; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type != V_STR) + return error_value(E_SCANF_1); + for (i = 1; i < count; i++) { + if (vals[i]->v_type != V_ADDR) + return error_value(E_SCANF_2); + } + i = fscanfid(FILEID_STDIN, vp->v_str->s_str, count - 1, vals + 1); + if (i < 0) + return error_value(E_SCANF_3); + result.v_type = V_NUM; + result.v_num = itoq((long) i); + return result; } S_FUNC VALUE f_strscanf(int count, VALUE **vals) { - VALUE *vp, *vq; - VALUE result; - int i; + VALUE *vp, *vq; + VALUE result; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - errno = 0; - vp = vals[0]; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type != V_STR) - return error_value(E_STRSCANF_1); - vq = vals[1]; - if (vq->v_type == V_ADDR) - vq = vq->v_addr; - if (vq->v_type != V_STR) - return error_value(E_STRSCANF_2); - for (i = 2; i < count; i++) { - if (vals[i]->v_type != V_ADDR) - return error_value(E_STRSCANF_3); - } - i = scanfstr(vp->v_str->s_str, vq->v_str->s_str, - count - 2, vals + 2); - if (i == EOF) - return error_value(errno); - if (i < 0) - return error_value(E_STRSCANF_4); - result.v_type = V_NUM; - result.v_num = itoq((long) i); - return result; + errno = 0; + vp = vals[0]; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type != V_STR) + return error_value(E_STRSCANF_1); + vq = vals[1]; + if (vq->v_type == V_ADDR) + vq = vq->v_addr; + if (vq->v_type != V_STR) + return error_value(E_STRSCANF_2); + for (i = 2; i < count; i++) { + if (vals[i]->v_type != V_ADDR) + return error_value(E_STRSCANF_3); + } + i = scanfstr(vp->v_str->s_str, vq->v_str->s_str, + count - 2, vals + 2); + if (i == EOF) + return error_value(errno); + if (i < 0) + return error_value(E_STRSCANF_4); + result.v_type = V_NUM; + result.v_num = itoq((long) i); + return result; } S_FUNC VALUE f_fscanf(int count, VALUE **vals) { - VALUE *vp, *sp; - VALUE result; - int i; + VALUE *vp, *sp; + VALUE result; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - vp = *vals++; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type != V_FILE) - return error_value(E_FSCANF_1); - sp = *vals++; - if (sp->v_type == V_ADDR) - sp = sp->v_addr; - if (sp->v_type != V_STR) - return error_value(E_FSCANF_2); - for (i = 0; i < count - 2; i++) { - if (vals[i]->v_type != V_ADDR) - return error_value(E_FSCANF_3); - } - i = fscanfid(vp->v_file, sp->v_str->s_str, count - 2, vals); - if (i == EOF) { - result.v_type = V_NULL; - return result; - } - if (i < 0) - return error_value(E_FSCANF_4); - result.v_type = V_NUM; - result.v_num = itoq((long) i); - return result; + vp = *vals++; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type != V_FILE) + return error_value(E_FSCANF_1); + sp = *vals++; + if (sp->v_type == V_ADDR) + sp = sp->v_addr; + if (sp->v_type != V_STR) + return error_value(E_FSCANF_2); + for (i = 0; i < count - 2; i++) { + if (vals[i]->v_type != V_ADDR) + return error_value(E_FSCANF_3); + } + i = fscanfid(vp->v_file, sp->v_str->s_str, count - 2, vals); + if (i == EOF) { + result.v_type = V_NULL; + return result; + } + if (i < 0) + return error_value(E_FSCANF_4); + result.v_type = V_NUM; + result.v_num = itoq((long) i); + return result; } S_FUNC VALUE f_fputc(VALUE *v1, VALUE *v2) { - VALUE result; - NUMBER *q; - int ch; - int i; + VALUE result; + NUMBER *q; + int ch; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (v1->v_type != V_FILE) - return error_value(E_FPUTC_1); - switch (v2->v_type) { - case V_STR: - ch = v2->v_str->s_str[0]; - break; - case V_NUM: - q = v2->v_num; - if (!qisint(q)) - return error_value(E_FPUTC_2); + if (v1->v_type != V_FILE) + return error_value(E_FPUTC_1); + switch (v2->v_type) { + case V_STR: + ch = v2->v_str->s_str[0]; + break; + case V_NUM: + q = v2->v_num; + if (!qisint(q)) + return error_value(E_FPUTC_2); - ch = qisneg(q) ? (int)(-q->num.v[0] & 0xff) : - (int)(q->num.v[0] & 0xff); - break; - case V_NULL: - ch = 0; - break; - default: - return error_value(E_FPUTC_2); - } - i = idfputc(v1->v_file, ch); - if (i > 0) - return error_value(E_FPUTC_3); - result.v_type = V_NULL; - return result; + ch = qisneg(q) ? (int)(-q->num.v[0] & 0xff) : + (int)(q->num.v[0] & 0xff); + break; + case V_NULL: + ch = 0; + break; + default: + return error_value(E_FPUTC_2); + } + i = idfputc(v1->v_file, ch); + if (i > 0) + return error_value(E_FPUTC_3); + result.v_type = V_NULL; + return result; } S_FUNC VALUE f_fputs(int count, VALUE **vals) { - VALUE result; - int i, err; + VALUE result; + int i, err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vals[0]->v_type != V_FILE) - return error_value(E_FPUTS_1); - for (i = 1; i < count; i++) { - if (vals[i]->v_type != V_STR) - return error_value(E_FPUTS_2); - } - for (i = 1; i < count; i++) { - err = idfputs(vals[0]->v_file, vals[i]->v_str); - if (err > 0) - return error_value(E_FPUTS_3); - } - result.v_type = V_NULL; - return result; + if (vals[0]->v_type != V_FILE) + return error_value(E_FPUTS_1); + for (i = 1; i < count; i++) { + if (vals[i]->v_type != V_STR) + return error_value(E_FPUTS_2); + } + for (i = 1; i < count; i++) { + err = idfputs(vals[0]->v_file, vals[i]->v_str); + if (err > 0) + return error_value(E_FPUTS_3); + } + result.v_type = V_NULL; + return result; } S_FUNC VALUE f_fputstr(int count, VALUE **vals) { - VALUE result; - int i, err; + VALUE result; + int i, err; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vals[0]->v_type != V_FILE) - return error_value(E_FPUTSTR_1); - for (i = 1; i < count; i++) { - if (vals[i]->v_type != V_STR) - return error_value(E_FPUTSTR_2); - } - for (i = 1; i < count; i++) { - err = idfputstr(vals[0]->v_file, - vals[i]->v_str->s_str); - if (err > 0) - return error_value(E_FPUTSTR_3); - } - result.v_type = V_NULL; - return result; + if (vals[0]->v_type != V_FILE) + return error_value(E_FPUTSTR_1); + for (i = 1; i < count; i++) { + if (vals[i]->v_type != V_STR) + return error_value(E_FPUTSTR_2); + } + for (i = 1; i < count; i++) { + err = idfputstr(vals[0]->v_file, + vals[i]->v_str->s_str); + if (err > 0) + return error_value(E_FPUTSTR_3); + } + result.v_type = V_NULL; + return result; } S_FUNC VALUE f_printf(int count, VALUE **vals) { - VALUE result; - int i; + VALUE result; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vals[0]->v_type != V_STR) - return error_value(E_PRINTF_1); - i = idprintf(FILEID_STDOUT, vals[0]->v_str->s_str, - count - 1, vals + 1); - if (i) - return error_value(E_PRINTF_2); - result.v_type = V_NULL; - return result; + if (vals[0]->v_type != V_STR) + return error_value(E_PRINTF_1); + i = idprintf(FILEID_STDOUT, vals[0]->v_str->s_str, + count - 1, vals + 1); + if (i) + return error_value(E_PRINTF_2); + result.v_type = V_NULL; + return result; } S_FUNC VALUE f_strprintf(int count, VALUE **vals) { - VALUE result; - int i; - char *cp; + VALUE result; + int i; + char *cp; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vals[0]->v_type != V_STR) - return error_value(E_STRPRINTF_1); - math_divertio(); - i = idprintf(FILEID_STDOUT, vals[0]->v_str->s_str, - count - 1, vals + 1); - if (i) { - free(math_getdivertedio()); - return error_value(E_STRPRINTF_2); - } - cp = math_getdivertedio(); - result.v_type = V_STR; - result.v_str = makenewstring(cp); - free(cp); - return result; + if (vals[0]->v_type != V_STR) + return error_value(E_STRPRINTF_1); + math_divertio(); + i = idprintf(FILEID_STDOUT, vals[0]->v_str->s_str, + count - 1, vals + 1); + if (i) { + free(math_getdivertedio()); + return error_value(E_STRPRINTF_2); + } + cp = math_getdivertedio(); + result.v_type = V_STR; + result.v_str = makenewstring(cp); + free(cp); + return result; } S_FUNC VALUE f_fgetc(VALUE *vp) { - VALUE result; - int ch; + VALUE result; + int ch; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vp->v_type != V_FILE) - return error_value(E_FGETC_1); - ch = getcharid(vp->v_file); - if (ch == -2) - return error_value(E_FGETC_2); - result.v_type = V_NULL; - if (ch != EOF) { - result.v_type = V_STR; - result.v_str = charstring(ch); - } - return result; + if (vp->v_type != V_FILE) + return error_value(E_FGETC_1); + ch = getcharid(vp->v_file); + if (ch == -2) + return error_value(E_FGETC_2); + result.v_type = V_NULL; + if (ch != EOF) { + result.v_type = V_STR; + result.v_str = charstring(ch); + } + return result; } S_FUNC VALUE f_ungetc(VALUE *v1, VALUE *v2) { - VALUE result; - NUMBER *q; - int ch; - int i; + VALUE result; + NUMBER *q; + int ch; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - errno = 0; - if (v1->v_type != V_FILE) - return error_value(E_UNGETC_1); - switch (v2->v_type) { - case V_STR: - ch = v2->v_str->s_str[0]; - break; - case V_NUM: - q = v2->v_num; - if (!qisint(q)) - return error_value(E_UNGETC_2); - ch = qisneg(q) ? (int)(-q->num.v[0] & 0xff) : - (int)(q->num.v[0] & 0xff); - break; - default: - return error_value(E_UNGETC_2); - } - i = idungetc(v1->v_file, ch); - if (i == EOF) - return error_value(errno); - if (i == -2) - return error_value(E_UNGETC_3); - result.v_type = V_NULL; - return result; + errno = 0; + if (v1->v_type != V_FILE) + return error_value(E_UNGETC_1); + switch (v2->v_type) { + case V_STR: + ch = v2->v_str->s_str[0]; + break; + case V_NUM: + q = v2->v_num; + if (!qisint(q)) + return error_value(E_UNGETC_2); + ch = qisneg(q) ? (int)(-q->num.v[0] & 0xff) : + (int)(q->num.v[0] & 0xff); + break; + default: + return error_value(E_UNGETC_2); + } + i = idungetc(v1->v_file, ch); + if (i == EOF) + return error_value(errno); + if (i == -2) + return error_value(E_UNGETC_3); + result.v_type = V_NULL; + return result; } S_FUNC VALUE f_fgetline(VALUE *vp) { - VALUE result; - STRING *str; - int i; + VALUE result; + STRING *str; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vp->v_type != V_FILE) - return error_value(E_FGETLINE_1); - i = readid(vp->v_file, 9, &str); - if (i > 0) - return error_value(E_FGETLINE_2); - result.v_type = V_NULL; - if (i == 0) { - result.v_type = V_STR; - result.v_str = str; - } - return result; + if (vp->v_type != V_FILE) + return error_value(E_FGETLINE_1); + i = readid(vp->v_file, 9, &str); + if (i > 0) + return error_value(E_FGETLINE_2); + result.v_type = V_NULL; + if (i == 0) { + result.v_type = V_STR; + result.v_str = str; + } + return result; } S_FUNC VALUE f_fgets(VALUE *vp) { - VALUE result; - STRING *str; - int i; + VALUE result; + STRING *str; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vp->v_type != V_FILE) - return error_value(E_FGETS_1); - i = readid(vp->v_file, 1, &str); - if (i > 0) - return error_value(E_FGETS_2); - result.v_type = V_NULL; - if (i == 0) { - result.v_type = V_STR; - result.v_str = str; - } - return result; + if (vp->v_type != V_FILE) + return error_value(E_FGETS_1); + i = readid(vp->v_file, 1, &str); + if (i > 0) + return error_value(E_FGETS_2); + result.v_type = V_NULL; + if (i == 0) { + result.v_type = V_STR; + result.v_str = str; + } + return result; } S_FUNC VALUE f_fgetstr(VALUE *vp) { - VALUE result; - STRING *str; - int i; + VALUE result; + STRING *str; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vp->v_type != V_FILE) - return error_value(E_FGETSTR_1); - i = readid(vp->v_file, 10, &str); - if (i > 0) - return error_value(E_FGETSTR_2); - result.v_type = V_NULL; - if (i == 0) { - result.v_type = V_STR; - result.v_str = str; - } - return result; + if (vp->v_type != V_FILE) + return error_value(E_FGETSTR_1); + i = readid(vp->v_file, 10, &str); + if (i > 0) + return error_value(E_FGETSTR_2); + result.v_type = V_NULL; + if (i == 0) { + result.v_type = V_STR; + result.v_str = str; + } + return result; } S_FUNC VALUE f_fgetfield(VALUE *vp) { - VALUE result; - STRING *str; - int i; + VALUE result; + STRING *str; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vp->v_type != V_FILE) - return error_value(E_FGETFIELD_1); - i = readid(vp->v_file, 14, &str); - if (i > 0) - return error_value(E_FGETFIELD_2); - result.v_type = V_NULL; - if (i == 0) { - result.v_type = V_STR; - result.v_str = str; - } - return result; + if (vp->v_type != V_FILE) + return error_value(E_FGETFIELD_1); + i = readid(vp->v_file, 14, &str); + if (i > 0) + return error_value(E_FGETFIELD_2); + result.v_type = V_NULL; + if (i == 0) { + result.v_type = V_STR; + result.v_str = str; + } + return result; } S_FUNC VALUE f_fgetfile(VALUE *vp) { - VALUE result; - STRING *str; - int i; + VALUE result; + STRING *str; + int i; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (vp->v_type != V_FILE) - return error_value(E_FGETFILE_1); - i = readid(vp->v_file, 0, &str); - if (i == 1) - return error_value(E_FGETFILE_2); - if (i == 3) - return error_value(E_FGETFILE_3); - result.v_type = V_NULL; - if (i == 0) { - result.v_type = V_STR; - result.v_str = str; - } - return result; + if (vp->v_type != V_FILE) + return error_value(E_FGETFILE_1); + i = readid(vp->v_file, 0, &str); + if (i == 1) + return error_value(E_FGETFILE_2); + if (i == 3) + return error_value(E_FGETFILE_3); + result.v_type = V_NULL; + if (i == 0) { + result.v_type = V_STR; + result.v_str = str; + } + return result; } S_FUNC VALUE f_files(int count, VALUE **vals) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (count == 0) { - result.v_type = V_NUM; - result.v_num = itoq((long) MAXFILES); - return result; - } - if ((vals[0]->v_type != V_NUM) || qisfrac(vals[0]->v_num)) - return error_value(E_FILES); - result.v_type = V_NULL; - result.v_file = indexid(qtoi(vals[0]->v_num)); - if (result.v_file != FILEID_NONE) - result.v_type = V_FILE; - return result; + if (count == 0) { + result.v_type = V_NUM; + result.v_num = itoq((long) MAXFILES); + return result; + } + if ((vals[0]->v_type != V_NUM) || qisfrac(vals[0]->v_num)) + return error_value(E_FILES); + result.v_type = V_NULL; + result.v_file = indexid(qtoi(vals[0]->v_num)); + if (result.v_file != FILEID_NONE) + result.v_type = V_FILE; + return result; } S_FUNC VALUE f_reverse(VALUE *val) { - VALUE res; + VALUE res; - res.v_type = val->v_type; - res.v_subtype = val->v_subtype; - switch(val->v_type) { - case V_MAT: - res.v_mat = matcopy(val->v_mat); - matreverse(res.v_mat); - break; - case V_LIST: - res.v_list = listcopy(val->v_list); - listreverse(res.v_list); - break; - case V_STR: - res.v_str = stringneg(val->v_str); - if (res.v_str == NULL) - return error_value(E_STRNEG); - break; - default: - math_error("Bad argument type for reverse"); - not_reached(); - } - return res; + res.v_type = val->v_type; + res.v_subtype = val->v_subtype; + switch(val->v_type) { + case V_MAT: + res.v_mat = matcopy(val->v_mat); + matreverse(res.v_mat); + break; + case V_LIST: + res.v_list = listcopy(val->v_list); + listreverse(res.v_list); + break; + case V_STR: + res.v_str = stringneg(val->v_str); + if (res.v_str == NULL) + return error_value(E_STRNEG); + break; + default: + math_error("Bad argument type for reverse"); + not_reached(); + } + return res; } S_FUNC VALUE f_sort(VALUE *val) { - VALUE res; + VALUE res; - res.v_type = val->v_type; - res.v_subtype = val->v_subtype; - switch (val->v_type) { - case V_MAT: - res.v_mat = matcopy(val->v_mat); - matsort(res.v_mat); - break; - case V_LIST: - res.v_list = listcopy(val->v_list); - listsort(res.v_list); - break; - default: - math_error("Bad argument type for sort"); - not_reached(); - } - return res; + res.v_type = val->v_type; + res.v_subtype = val->v_subtype; + switch (val->v_type) { + case V_MAT: + res.v_mat = matcopy(val->v_mat); + matsort(res.v_mat); + break; + case V_LIST: + res.v_list = listcopy(val->v_list); + listsort(res.v_list); + break; + default: + math_error("Bad argument type for sort"); + not_reached(); + } + return res; } S_FUNC VALUE f_join(int count, VALUE **vals) { - LIST *lp; - LISTELEM *ep; - VALUE res; + LIST *lp; + LISTELEM *ep; + VALUE res; - /* initialize VALUE */ - res.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + res.v_subtype = V_NOSUBTYPE; - lp = listalloc(); - while (count-- > 0) { - if (vals[0]->v_type != V_LIST) { - listfree(lp); - printf("Non-list argument for join\n"); - res.v_type = V_NULL; - return res; - } - for (ep = vals[0]->v_list->l_first; ep; ep = ep->e_next) - insertlistlast(lp, &ep->e_value); - vals++; - } - res.v_type = V_LIST; - res.v_list = lp; - return res; + lp = listalloc(); + while (count-- > 0) { + if (vals[0]->v_type != V_LIST) { + listfree(lp); + printf("Non-list argument for join\n"); + res.v_type = V_NULL; + return res; + } + for (ep = vals[0]->v_list->l_first; ep; ep = ep->e_next) + insertlistlast(lp, &ep->e_value); + vals++; + } + res.v_type = V_LIST; + res.v_list = lp; + return res; } S_FUNC VALUE f_head(VALUE *v1, VALUE *v2) { - VALUE res; - long n; + VALUE res; + long n; - /* initialize VALUE */ - res.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + res.v_subtype = V_NOSUBTYPE; - if (v2->v_type != V_NUM || qisfrac(v2->v_num) || - zge31b(v2->v_num->num)) - return error_value(E_HEAD_2); - n = qtoi(v2->v_num); + if (v2->v_type != V_NUM || qisfrac(v2->v_num) || + zge31b(v2->v_num->num)) + return error_value(E_HEAD_2); + n = qtoi(v2->v_num); - res.v_type = v1->v_type; - switch (v1->v_type) { - case V_LIST: - if (n == 0) - res.v_list = listalloc(); - else if (n > 0) - res.v_list = listsegment(v1->v_list,0,n-1); - else - res.v_list = listsegment(v1->v_list,-n-1,0); - return res; - case V_STR: - if (n == 0) - res.v_str = slink(&_nullstring_); - else if (n > 0) - res.v_str = stringsegment(v1->v_str,0,n-1); - else - res.v_str = stringsegment(v1->v_str,-n-1,0); - if (res.v_str == NULL) - return error_value(E_STRHEAD); - return res; - default: - return error_value(E_HEAD_1); - } + res.v_type = v1->v_type; + switch (v1->v_type) { + case V_LIST: + if (n == 0) + res.v_list = listalloc(); + else if (n > 0) + res.v_list = listsegment(v1->v_list,0,n-1); + else + res.v_list = listsegment(v1->v_list,-n-1,0); + return res; + case V_STR: + if (n == 0) + res.v_str = slink(&_nullstring_); + else if (n > 0) + res.v_str = stringsegment(v1->v_str,0,n-1); + else + res.v_str = stringsegment(v1->v_str,-n-1,0); + if (res.v_str == NULL) + return error_value(E_STRHEAD); + return res; + default: + return error_value(E_HEAD_1); + } } S_FUNC VALUE f_tail(VALUE *v1, VALUE *v2) { - long n; - VALUE res; + long n; + VALUE res; - /* initialize VALUE */ - res.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + res.v_subtype = V_NOSUBTYPE; - if (v2->v_type != V_NUM || qisfrac(v2->v_num) || - zge31b(v2->v_num->num)) - return error_value(E_TAIL_1); - n = qtoi(v2->v_num); - res.v_type = v1->v_type; - switch (v1->v_type) { - case V_LIST: - if (n == 0) { - res.v_list = listalloc(); - } else if (n > 0) { - res.v_list = listsegment(v1->v_list, - v1->v_list->l_count - n, - v1->v_list->l_count - 1); - } else { - res.v_list = listsegment(v1->v_list, - v1->v_list->l_count - 1, - v1->v_list->l_count + n); - } - return res; - case V_STR: - if (n == 0) { - res.v_str = slink(&_nullstring_); - } else if (n > 0) { - res.v_str = stringsegment(v1->v_str, - v1->v_str->s_len - n, - v1->v_str->s_len - 1); - } else { - res.v_str = stringsegment(v1->v_str, - v1->v_str->s_len - 1, - v1->v_str->s_len + n); - } - if (res.v_str == V_NULL) - return error_value(E_STRTAIL); - return res; - default: - return error_value(E_TAIL_1); - } + if (v2->v_type != V_NUM || qisfrac(v2->v_num) || + zge31b(v2->v_num->num)) + return error_value(E_TAIL_1); + n = qtoi(v2->v_num); + res.v_type = v1->v_type; + switch (v1->v_type) { + case V_LIST: + if (n == 0) { + res.v_list = listalloc(); + } else if (n > 0) { + res.v_list = listsegment(v1->v_list, + v1->v_list->l_count - n, + v1->v_list->l_count - 1); + } else { + res.v_list = listsegment(v1->v_list, + v1->v_list->l_count - 1, + v1->v_list->l_count + n); + } + return res; + case V_STR: + if (n == 0) { + res.v_str = slink(&_nullstring_); + } else if (n > 0) { + res.v_str = stringsegment(v1->v_str, + v1->v_str->s_len - n, + v1->v_str->s_len - 1); + } else { + res.v_str = stringsegment(v1->v_str, + v1->v_str->s_len - 1, + v1->v_str->s_len + n); + } + if (res.v_str == V_NULL) + return error_value(E_STRTAIL); + return res; + default: + return error_value(E_TAIL_1); + } } S_FUNC VALUE f_segment(int count, VALUE **vals) { - VALUE *vp; - long n1, n2; - VALUE result; + VALUE *vp; + long n1, n2; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - vp = vals[1]; + vp = vals[1]; - if (vp->v_type != V_NUM || qisfrac(vp->v_num) || zge31b(vp->v_num->num)) - return error_value(E_SEG_2); - n1 = qtoi(vp->v_num); - n2 = n1; - if (count == 3) { - vp = vals[2]; - if (vp->v_type != V_NUM || qisfrac(vp->v_num) || - zge31b(vp->v_num->num)) - return error_value(E_SEG_3); - n2 = qtoi(vp->v_num); - } - vp = vals[0]; - result.v_type = vp->v_type; - switch (vp->v_type) { - case V_LIST: - result.v_list = listsegment(vp->v_list, n1, n2); - return result; - case V_STR: - result.v_str = stringsegment(vp->v_str, n1, n2); - if (result.v_str == NULL) - return error_value(E_STRSEG); - return result; - default: - return error_value(E_SEG_1); - } + if (vp->v_type != V_NUM || qisfrac(vp->v_num) || zge31b(vp->v_num->num)) + return error_value(E_SEG_2); + n1 = qtoi(vp->v_num); + n2 = n1; + if (count == 3) { + vp = vals[2]; + if (vp->v_type != V_NUM || qisfrac(vp->v_num) || + zge31b(vp->v_num->num)) + return error_value(E_SEG_3); + n2 = qtoi(vp->v_num); + } + vp = vals[0]; + result.v_type = vp->v_type; + switch (vp->v_type) { + case V_LIST: + result.v_list = listsegment(vp->v_list, n1, n2); + return result; + case V_STR: + result.v_str = stringsegment(vp->v_str, n1, n2); + if (result.v_str == NULL) + return error_value(E_STRSEG); + return result; + default: + return error_value(E_SEG_1); + } } S_FUNC VALUE f_modify(VALUE *v1, VALUE *v2) { - FUNC *fp; - LISTELEM *ep; - long s; - VALUE res; - VALUE *vp; - unsigned short subtype; + FUNC *fp; + LISTELEM *ep; + long s; + VALUE res; + VALUE *vp; + unsigned short subtype; - if (v1->v_type != V_ADDR) - return error_value(E_MODIFY_1); - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if (v2->v_type != V_STR) - return error_value(E_MODIFY_2); - if (v1->v_subtype & V_NONEWVALUE) - return error_value(E_MODIFY_3); - fp = findfunc(adduserfunc(v2->v_str->s_str)); - if (!fp) - return error_value(E_MODIFY_4); - switch (v1->v_type) { - case V_LIST: - for (ep = v1->v_list->l_first; ep; ep = ep->e_next) { - subtype = ep->e_value.v_subtype; - *++stack = ep->e_value; - calculate(fp, 1); - stack->v_subtype |= subtype; - ep->e_value = *stack--; - } - break; - case V_MAT: - vp = v1->v_mat->m_table; - s = v1->v_mat->m_size; - while (s-- > 0) { - subtype = vp->v_subtype; - *++stack = *vp; - calculate(fp, 1); - stack->v_subtype |= subtype; - *vp++ = *stack--; - } - break; - case V_OBJ: - vp = v1->v_obj->o_table; - s = v1->v_obj->o_actions->oa_count; - while (s-- > 0) { - subtype = vp->v_subtype; - *++stack = *vp; - calculate(fp, 1); - stack->v_subtype |= subtype; - *vp++ = *stack--; - } - break; - default: - return error_value(E_MODIFY_5); - } - res.v_type = V_NULL; - res.v_subtype = V_NOSUBTYPE; - return res; + if (v1->v_type != V_ADDR) + return error_value(E_MODIFY_1); + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if (v2->v_type != V_STR) + return error_value(E_MODIFY_2); + if (v1->v_subtype & V_NONEWVALUE) + return error_value(E_MODIFY_3); + fp = findfunc(adduserfunc(v2->v_str->s_str)); + if (!fp) + return error_value(E_MODIFY_4); + switch (v1->v_type) { + case V_LIST: + for (ep = v1->v_list->l_first; ep; ep = ep->e_next) { + subtype = ep->e_value.v_subtype; + *++stack = ep->e_value; + calculate(fp, 1); + stack->v_subtype |= subtype; + ep->e_value = *stack--; + } + break; + case V_MAT: + vp = v1->v_mat->m_table; + s = v1->v_mat->m_size; + while (s-- > 0) { + subtype = vp->v_subtype; + *++stack = *vp; + calculate(fp, 1); + stack->v_subtype |= subtype; + *vp++ = *stack--; + } + break; + case V_OBJ: + vp = v1->v_obj->o_table; + s = v1->v_obj->o_actions->oa_count; + while (s-- > 0) { + subtype = vp->v_subtype; + *++stack = *vp; + calculate(fp, 1); + stack->v_subtype |= subtype; + *vp++ = *stack--; + } + break; + default: + return error_value(E_MODIFY_5); + } + res.v_type = V_NULL; + res.v_subtype = V_NOSUBTYPE; + return res; } S_FUNC VALUE f_forall(VALUE *v1, VALUE *v2) { - FUNC *fp; - LISTELEM *ep; - long s; - VALUE res; - VALUE *vp; + FUNC *fp; + LISTELEM *ep; + long s; + VALUE res; + VALUE *vp; - /* initialize VALUE */ - res.v_type = V_NULL; - res.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + res.v_type = V_NULL; + res.v_subtype = V_NOSUBTYPE; - if (v2->v_type != V_STR) { - math_error("Non-string second argument for forall"); - not_reached(); - } - fp = findfunc(adduserfunc(v2->v_str->s_str)); - if (!fp) { - math_error("Undefined function for forall"); - not_reached(); - } - switch (v1->v_type) { - case V_LIST: - for (ep = v1->v_list->l_first; ep; ep = ep->e_next) { - copyvalue(&ep->e_value, ++stack); - calculate(fp, 1); - stack--; - } - break; - case V_MAT: - vp = v1->v_mat->m_table; - s = v1->v_mat->m_size; - while (s-- > 0) { - copyvalue(vp++, ++stack); - calculate(fp, 1); - stack--; - } - break; - default: - math_error("Non list or matrix first argument for forall"); - not_reached(); - } - return res; + if (v2->v_type != V_STR) { + math_error("Non-string second argument for forall"); + not_reached(); + } + fp = findfunc(adduserfunc(v2->v_str->s_str)); + if (!fp) { + math_error("Undefined function for forall"); + not_reached(); + } + switch (v1->v_type) { + case V_LIST: + for (ep = v1->v_list->l_first; ep; ep = ep->e_next) { + copyvalue(&ep->e_value, ++stack); + calculate(fp, 1); + stack--; + } + break; + case V_MAT: + vp = v1->v_mat->m_table; + s = v1->v_mat->m_size; + while (s-- > 0) { + copyvalue(vp++, ++stack); + calculate(fp, 1); + stack--; + } + break; + default: + math_error("Non list or matrix first argument for forall"); + not_reached(); + } + return res; } S_FUNC VALUE f_select(VALUE *v1, VALUE *v2) { - LIST *lp; - LISTELEM *ep; - FUNC *fp; - VALUE res; + LIST *lp; + LISTELEM *ep; + FUNC *fp; + VALUE res; - /* initialize VALUE */ - res.v_type = V_LIST; - res.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + res.v_type = V_LIST; + res.v_subtype = V_NOSUBTYPE; - if (v1->v_type != V_LIST) { - math_error("Non-list first argument for select"); - not_reached(); - } - if (v2->v_type != V_STR) { - math_error("Non-string second argument for select"); - not_reached(); - } - fp = findfunc(adduserfunc(v2->v_str->s_str)); - if (!fp) { - math_error("Undefined function for select"); - not_reached(); - } - lp = listalloc(); - for (ep = v1->v_list->l_first; ep; ep = ep->e_next) { - copyvalue(&ep->e_value, ++stack); - calculate(fp, 1); - if (testvalue(stack)) - insertlistlast(lp, &ep->e_value); - freevalue(stack--); - } - res.v_list = lp; - return res; + if (v1->v_type != V_LIST) { + math_error("Non-list first argument for select"); + not_reached(); + } + if (v2->v_type != V_STR) { + math_error("Non-string second argument for select"); + not_reached(); + } + fp = findfunc(adduserfunc(v2->v_str->s_str)); + if (!fp) { + math_error("Undefined function for select"); + not_reached(); + } + lp = listalloc(); + for (ep = v1->v_list->l_first; ep; ep = ep->e_next) { + copyvalue(&ep->e_value, ++stack); + calculate(fp, 1); + if (testvalue(stack)) + insertlistlast(lp, &ep->e_value); + freevalue(stack--); + } + res.v_list = lp; + return res; } S_FUNC VALUE f_count(VALUE *v1, VALUE *v2) { - LISTELEM *ep; - FUNC *fp; - long s; - long n = 0; - VALUE res; - VALUE *vp; + LISTELEM *ep; + FUNC *fp; + long s; + long n = 0; + VALUE res; + VALUE *vp; - /* initialize VALUE */ - res.v_type = V_NUM; - res.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + res.v_type = V_NUM; + res.v_subtype = V_NOSUBTYPE; - if (v2->v_type != V_STR) { - math_error("Non-string second argument for select"); - not_reached(); - } - fp = findfunc(adduserfunc(v2->v_str->s_str)); - if (!fp) { - math_error("Undefined function for select"); - not_reached(); - } - switch (v1->v_type) { - case V_LIST: - for (ep = v1->v_list->l_first; ep; ep = ep->e_next) { - copyvalue(&ep->e_value, ++stack); - calculate(fp, 1); - if (testvalue(stack)) - n++; - freevalue(stack--); - } - break; - case V_MAT: - s = v1->v_mat->m_size; - vp = v1->v_mat->m_table; - while (s-- > 0) { - copyvalue(vp++, ++stack); - calculate(fp, 1); - if (testvalue(stack)) - n++; - freevalue(stack--); - } - break; - default: - math_error("Bad argument type for count"); - not_reached(); - break; - } - res.v_num = itoq(n); - return res; + if (v2->v_type != V_STR) { + math_error("Non-string second argument for select"); + not_reached(); + } + fp = findfunc(adduserfunc(v2->v_str->s_str)); + if (!fp) { + math_error("Undefined function for select"); + not_reached(); + } + switch (v1->v_type) { + case V_LIST: + for (ep = v1->v_list->l_first; ep; ep = ep->e_next) { + copyvalue(&ep->e_value, ++stack); + calculate(fp, 1); + if (testvalue(stack)) + n++; + freevalue(stack--); + } + break; + case V_MAT: + s = v1->v_mat->m_size; + vp = v1->v_mat->m_table; + while (s-- > 0) { + copyvalue(vp++, ++stack); + calculate(fp, 1); + if (testvalue(stack)) + n++; + freevalue(stack--); + } + break; + default: + math_error("Bad argument type for count"); + not_reached(); + break; + } + res.v_num = itoq(n); + return res; } S_FUNC VALUE f_makelist(VALUE *v1) { - LIST *lp; - VALUE res; - long n; + LIST *lp; + VALUE res; + long n; - /* initialize VALUE */ - res.v_type = V_NULL; - res.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + res.v_type = V_NULL; + res.v_subtype = V_NOSUBTYPE; - if (v1->v_type != V_NUM || qisfrac(v1->v_num) || qisneg(v1->v_num)) { - math_error("Bad argument for makelist"); - not_reached(); - } - if (zge31b(v1->v_num->num)) { - math_error("makelist count >= 2^31"); - not_reached(); - } - n = qtoi(v1->v_num); - lp = listalloc(); - while (n-- > 0) - insertlistlast(lp, &res); - res.v_type = V_LIST; - res.v_list = lp; - return res; + if (v1->v_type != V_NUM || qisfrac(v1->v_num) || qisneg(v1->v_num)) { + math_error("Bad argument for makelist"); + not_reached(); + } + if (zge31b(v1->v_num->num)) { + math_error("makelist count >= 2^31"); + not_reached(); + } + n = qtoi(v1->v_num); + lp = listalloc(); + while (n-- > 0) + insertlistlast(lp, &res); + res.v_type = V_LIST; + res.v_list = lp; + return res; } S_FUNC VALUE f_randperm(VALUE *val) { - VALUE res; + VALUE res; - /* initialize VALUE */ - res.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + res.v_subtype = V_NOSUBTYPE; - res.v_type = val->v_type; - switch (val->v_type) { - case V_MAT: - res.v_mat = matcopy(val->v_mat); - matrandperm(res.v_mat); - break; - case V_LIST: - res.v_list = listcopy(val->v_list); - listrandperm(res.v_list); - break; - default: - math_error("Bad argument type for randperm"); - not_reached(); - } - return res; + res.v_type = val->v_type; + switch (val->v_type) { + case V_MAT: + res.v_mat = matcopy(val->v_mat); + matrandperm(res.v_mat); + break; + case V_LIST: + res.v_list = listcopy(val->v_list); + listrandperm(res.v_list); + break; + default: + math_error("Bad argument type for randperm"); + not_reached(); + } + return res; } S_FUNC VALUE f_cmdbuf(void) { - VALUE result; - char *newcp; - size_t cmdbuf_len; /* length of cmdbuf string */ + VALUE result; + char *newcp; + size_t cmdbuf_len; /* length of cmdbuf string */ - /* initialize VALUE */ - result.v_type = V_STR; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_STR; + result.v_subtype = V_NOSUBTYPE; - cmdbuf_len = strlen(cmdbuf); - newcp = (char *)malloc(cmdbuf_len+1); - if (newcp == NULL) { - math_error("Cannot allocate string in cmdbuf"); - not_reached(); - } - strlcpy(newcp, cmdbuf, cmdbuf_len+1); - result.v_str = makestring(newcp); - return result; + cmdbuf_len = strlen(cmdbuf); + newcp = (char *)malloc(cmdbuf_len+1); + if (newcp == NULL) { + math_error("Cannot allocate string in cmdbuf"); + not_reached(); + } + strlcpy(newcp, cmdbuf, cmdbuf_len+1); + result.v_str = makestring(newcp); + return result; } S_FUNC VALUE f_getenv(VALUE *v1) { - VALUE result; - char *str; + VALUE result; + char *str; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (v1->v_type != V_STR) { - math_error("Non-string argument for getenv"); - not_reached(); - } - result.v_type = V_STR; - str = getenv(v1->v_str->s_str); - if (str == NULL) - result.v_type = V_NULL; - else - result.v_str = makenewstring(str); - return result; + if (v1->v_type != V_STR) { + math_error("Non-string argument for getenv"); + not_reached(); + } + result.v_type = V_STR; + str = getenv(v1->v_str->s_str); + if (str == NULL) + result.v_type = V_NULL; + else + result.v_str = makenewstring(str); + return result; } S_FUNC VALUE f_isatty(VALUE *vp) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - result.v_type = V_NUM; - if (vp->v_type == V_FILE && isattyid(vp->v_file) == 1) { - result.v_num = itoq(1); - } else { - result.v_num = itoq(0); - } - return result; + result.v_type = V_NUM; + if (vp->v_type == V_FILE && isattyid(vp->v_file) == 1) { + result.v_num = itoq(1); + } else { + result.v_num = itoq(0); + } + return result; } S_FUNC VALUE f_calc_tty(void) { - VALUE res; + VALUE res; - if (!calc_tty(FILEID_STDIN)) - return error_value(E_TTY); - res.v_type = V_NULL; - res.v_subtype = V_NOSUBTYPE; - return res; + if (!calc_tty(FILEID_STDIN)) + return error_value(E_TTY); + res.v_type = V_NULL; + res.v_subtype = V_NOSUBTYPE; + return res; } S_FUNC VALUE f_inputlevel (void) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_type = V_NUM; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NUM; + result.v_subtype = V_NOSUBTYPE; - result.v_num = itoq((long) inputlevel()); - return result; + result.v_num = itoq((long) inputlevel()); + return result; } S_FUNC VALUE f_calclevel(void) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_type = V_NUM; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NUM; + result.v_subtype = V_NOSUBTYPE; - result.v_num = itoq(calclevel()); - return result; + result.v_num = itoq(calclevel()); + return result; } S_FUNC VALUE f_calcpath(void) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_type = V_STR; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_STR; + result.v_subtype = V_NOSUBTYPE; - result.v_str = makenewstring(calcpath); - return result; + result.v_str = makenewstring(calcpath); + return result; } S_FUNC VALUE f_access(int count, VALUE **vals) { - NUMBER *q; - int m; - char *s, *fname; - VALUE result; - size_t len; - int i; + NUMBER *q; + int m; + char *s, *fname; + VALUE result; + size_t len; + int i; - /* initialize VALUE */ - result.v_type = V_NULL; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NULL; + result.v_subtype = V_NOSUBTYPE; - errno = 0; - if (vals[0]->v_type != V_STR) - return error_value(E_ACCESS_1); - fname = vals[0]->v_str->s_str; - m = 0; - if (count == 2) { - switch (vals[1]->v_type) { - case V_NUM: - q = vals[1]->v_num; - if (qisfrac(q) || qisneg(q)) - return error_value(E_ACCESS_2); - m = (int)(q->num.v[0] & 7); - break; - case V_STR: - s = vals[1]->v_str->s_str; - len = (long)strlen(s); - while (len-- > 0) { - switch (*s++) { - case 'r': m |= 4; break; - case 'w': m |= 2; break; - case 'x': m |= 1; break; - default: return error_value(E_ACCESS_2); - } - } - break; - case V_NULL: - break; - default: - return error_value(E_ACCESS_2); - } - } - i = access(fname, m); - if (i) - return error_value(errno); - return result; + errno = 0; + if (vals[0]->v_type != V_STR) + return error_value(E_ACCESS_1); + fname = vals[0]->v_str->s_str; + m = 0; + if (count == 2) { + switch (vals[1]->v_type) { + case V_NUM: + q = vals[1]->v_num; + if (qisfrac(q) || qisneg(q)) + return error_value(E_ACCESS_2); + m = (int)(q->num.v[0] & 7); + break; + case V_STR: + s = vals[1]->v_str->s_str; + len = (long)strlen(s); + while (len-- > 0) { + switch (*s++) { + case 'r': m |= 4; break; + case 'w': m |= 2; break; + case 'x': m |= 1; break; + default: return error_value(E_ACCESS_2); + } + } + break; + case V_NULL: + break; + default: + return error_value(E_ACCESS_2); + } + } + i = access(fname, m); + if (i) + return error_value(errno); + return result; } S_FUNC VALUE f_putenv(int count, VALUE **vals) { - VALUE result; - char *putenv_str; + VALUE result; + char *putenv_str; - /* initialize VALUE */ - result.v_type = V_NUM; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NUM; + result.v_subtype = V_NOSUBTYPE; - /* - * parse args - */ - if (count == 2) { - size_t snprintf_len; /* malloced snprintf buffer length */ + /* + * parse args + */ + if (count == 2) { + size_t snprintf_len; /* malloced snprintf buffer length */ - /* firewall */ - if (vals[0]->v_type != V_STR || vals[1]->v_type != V_STR) { - math_error("Non-string argument for putenv"); - not_reached(); - } + /* firewall */ + if (vals[0]->v_type != V_STR || vals[1]->v_type != V_STR) { + math_error("Non-string argument for putenv"); + not_reached(); + } - /* convert putenv("foo","bar") into putenv("foo=bar") */ - snprintf_len = vals[0]->v_str->s_len + 1 + + /* convert putenv("foo","bar") into putenv("foo=bar") */ + snprintf_len = vals[0]->v_str->s_len + 1 + vals[1]->v_str->s_len; - putenv_str = (char *)malloc(snprintf_len+1); - if (putenv_str == NULL) { - math_error("Cannot allocate string in putenv"); - not_reached(); - } - /* - * The next statement could be: - * - * snprintf(putenv_str, snprintf_len, - * "%s=%s", vals[0]->v_str->s_str, - * vals[1]->v_str->s_str); - * - * however compilers like gcc would issue warnings such as: - * - * null destination pointer - * - * even though we check that putenv_str is non-NULL - * above before using it. Therefore we call strlcpy() - * twice and make an assignment instead to avoid such warnings. - */ - strlcpy(putenv_str, - vals[0]->v_str->s_str, - vals[0]->v_str->s_len+1); - putenv_str[vals[0]->v_str->s_len] = '='; - strlcpy(putenv_str + vals[0]->v_str->s_len + 1, - vals[1]->v_str->s_str, - vals[1]->v_str->s_len+1); - putenv_str[snprintf_len] = '\0'; + putenv_str = (char *)malloc(snprintf_len+1); + if (putenv_str == NULL) { + math_error("Cannot allocate string in putenv"); + not_reached(); + } + /* + * The next statement could be: + * + * snprintf(putenv_str, snprintf_len, + * "%s=%s", vals[0]->v_str->s_str, + * vals[1]->v_str->s_str); + * + * however compilers like gcc would issue warnings such as: + * + * null destination pointer + * + * even though we check that putenv_str is non-NULL + * above before using it. Therefore we call strlcpy() + * twice and make an assignment instead to avoid such warnings. + */ + strlcpy(putenv_str, + vals[0]->v_str->s_str, + vals[0]->v_str->s_len+1); + putenv_str[vals[0]->v_str->s_len] = '='; + strlcpy(putenv_str + vals[0]->v_str->s_len + 1, + vals[1]->v_str->s_str, + vals[1]->v_str->s_len+1); + putenv_str[snprintf_len] = '\0'; - } else { - /* firewall */ - if (vals[0]->v_type != V_STR) { - math_error("Non-string argument for putenv"); - not_reached(); - } + } else { + /* firewall */ + if (vals[0]->v_type != V_STR) { + math_error("Non-string argument for putenv"); + not_reached(); + } - /* putenv(arg) must be of the form "foo=bar" */ - if ((char *)strchr(vals[0]->v_str->s_str, '=') == NULL) { - math_error("putenv single arg string missing ="); - not_reached(); - } + /* putenv(arg) must be of the form "foo=bar" */ + if ((char *)strchr(vals[0]->v_str->s_str, '=') == NULL) { + math_error("putenv single arg string missing ="); + not_reached(); + } - /* - * make a copy of the arg because subsequent changes - * would change the environment. - */ - putenv_str = (char *)malloc(vals[0]->v_str->s_len + 1); - if (putenv_str == NULL) { - math_error("Cannot allocate string in putenv"); - not_reached(); - } - strlcpy(putenv_str, vals[0]->v_str->s_str, - vals[0]->v_str->s_len+1); - } + /* + * make a copy of the arg because subsequent changes + * would change the environment. + */ + putenv_str = (char *)malloc(vals[0]->v_str->s_len + 1); + if (putenv_str == NULL) { + math_error("Cannot allocate string in putenv"); + not_reached(); + } + strlcpy(putenv_str, vals[0]->v_str->s_str, + vals[0]->v_str->s_len+1); + } - /* return putenv result */ - result.v_num = itoq((long) malloced_putenv(putenv_str)); - return result; + /* return putenv result */ + result.v_num = itoq((long) malloced_putenv(putenv_str)); + return result; } S_FUNC VALUE f_strpos(VALUE *haystack, VALUE *needle) { - VALUE result; - char *cpointer; - int cindex; + VALUE result; + char *cpointer; + int cindex; - /* initialize VALUE */ - result.v_type = V_NUM; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NUM; + result.v_subtype = V_NOSUBTYPE; - if (haystack->v_type != V_STR || needle->v_type != V_STR) { - math_error("Non-string argument for index"); - not_reached(); - } - cpointer = strstr(haystack->v_str->s_str, - needle->v_str->s_str); - if (cpointer == NULL) - cindex = 0; - else - cindex = cpointer - haystack->v_str->s_str + 1; - result.v_num = itoq((long) cindex); - return result; + if (haystack->v_type != V_STR || needle->v_type != V_STR) { + math_error("Non-string argument for index"); + not_reached(); + } + cpointer = strstr(haystack->v_str->s_str, + needle->v_str->s_str); + if (cpointer == NULL) + cindex = 0; + else + cindex = cpointer - haystack->v_str->s_str + 1; + result.v_num = itoq((long) cindex); + return result; } S_FUNC VALUE f_system(VALUE *vp) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_type = V_NUM; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NUM; + result.v_subtype = V_NOSUBTYPE; - if (vp->v_type != V_STR) { - math_error("Non-string argument for system"); - not_reached(); - } - if (!allow_exec) { - math_error("execution disallowed by -m"); - not_reached(); - } - if (conf->calc_debug & CALCDBG_SYSTEM) { - printf("%s\n", vp->v_str->s_str); - } + if (vp->v_type != V_STR) { + math_error("Non-string argument for system"); + not_reached(); + } + if (!allow_exec) { + math_error("execution disallowed by -m"); + not_reached(); + } + if (conf->calc_debug & CALCDBG_SYSTEM) { + printf("%s\n", vp->v_str->s_str); + } #if defined(_WIN32) || defined(_WIN64) - /* if the execute length is 0 then just return 0 */ - if (vp->v_str->s_len == 0) { - result.v_num = itoq((long)0); - } else { - result.v_num = itoq((long)system(vp->v_str->s_str)); - } + /* if the execute length is 0 then just return 0 */ + if (vp->v_str->s_len == 0) { + result.v_num = itoq((long)0); + } else { + result.v_num = itoq((long)system(vp->v_str->s_str)); + } #else /* Windows free systems */ - result.v_num = itoq((long)system(vp->v_str->s_str)); + result.v_num = itoq((long)system(vp->v_str->s_str)); #endif /* Windows free systems */ - return result; + return result; } S_FUNC VALUE f_sleep(int count, VALUE **vals) { - long time; - VALUE res; - NUMBER *q1, *q2; + long time; + VALUE res; + NUMBER *q1, *q2; - res.v_type = V_NULL; - res.v_subtype = V_NOSUBTYPE; + res.v_type = V_NULL; + res.v_subtype = V_NOSUBTYPE; #if !defined(_WIN32) && !defined(_WIN64) - if (count > 0) { - if (vals[0]->v_type != V_NUM || qisneg(vals[0]->v_num)) - return error_value(E_SLEEP); - if (qisint(vals[0]->v_num)) { - if (zge31b(vals[0]->v_num->num)) - return error_value(E_SLEEP); - time = ztoi(vals[0]->v_num->num); - time = sleep(time); - } - else { - q1 = qscale(vals[0]->v_num, 20); - q2 = qint(q1); - qfree(q1); - if (zge31b(q2->num)) { - qfree(q2); - return error_value(E_SLEEP); - } - time = ztoi(q2->num); - qfree(q2); - /* BSD 4.3 usleep has void return */ - usleep(time); - return res; - } - } else { - time = sleep(1); - } - if (time) { - res.v_type = V_NUM; - res.v_num = itoq(time); - } + if (count > 0) { + if (vals[0]->v_type != V_NUM || qisneg(vals[0]->v_num)) + return error_value(E_SLEEP); + if (qisint(vals[0]->v_num)) { + if (zge31b(vals[0]->v_num->num)) + return error_value(E_SLEEP); + time = ztoi(vals[0]->v_num->num); + time = sleep(time); + } + else { + q1 = qscale(vals[0]->v_num, 20); + q2 = qint(q1); + qfree(q1); + if (zge31b(q2->num)) { + qfree(q2); + return error_value(E_SLEEP); + } + time = ztoi(q2->num); + qfree(q2); + /* BSD 4.3 usleep has void return */ + usleep(time); + return res; + } + } else { + time = sleep(1); + } + if (time) { + res.v_type = V_NUM; + res.v_num = itoq(time); + } #endif /* Windows free systems */ - return res; + return res; } @@ -10179,51 +10179,51 @@ f_sleep(int count, VALUE **vals) S_FUNC NUMBER * f_base(int count, NUMBER **vals) { - long base; /* output base/mode */ - long oldbase=0; /* output base/mode */ + long base; /* output base/mode */ + long oldbase=0; /* output base/mode */ - /* deal with just a query */ - if (count != 1) { - return base_value(conf->outmode, conf->outmode); - } + /* deal with just a query */ + if (count != 1) { + return base_value(conf->outmode, conf->outmode); + } - /* deal with the special modes first */ - if (qisfrac(vals[0])) { - return base_value(math_setmode(MODE_FRAC), conf->outmode); - } - if (vals[0]->num.len > 64/BASEB) { - return base_value(math_setmode(MODE_EXP), conf->outmode); - } + /* deal with the special modes first */ + if (qisfrac(vals[0])) { + return base_value(math_setmode(MODE_FRAC), conf->outmode); + } + if (vals[0]->num.len > 64/BASEB) { + return base_value(math_setmode(MODE_EXP), conf->outmode); + } - /* set the base, if possible */ - base = qtoi(vals[0]); - switch (base) { - case -10: - oldbase = math_setmode(MODE_INT); - break; - case 2: - oldbase = math_setmode(MODE_BINARY); - break; - case 8: - oldbase = math_setmode(MODE_OCTAL); - break; - case 10: - oldbase = math_setmode(MODE_REAL); - break; - case 16: - oldbase = math_setmode(MODE_HEX); - break; + /* set the base, if possible */ + base = qtoi(vals[0]); + switch (base) { + case -10: + oldbase = math_setmode(MODE_INT); + break; + case 2: + oldbase = math_setmode(MODE_BINARY); + break; + case 8: + oldbase = math_setmode(MODE_OCTAL); + break; + case 10: + oldbase = math_setmode(MODE_REAL); + break; + case 16: + oldbase = math_setmode(MODE_HEX); + break; case 1000: - oldbase = math_setmode(MODE_ENG); - break; - default: - math_error("Unsupported base"); - not_reached(); - break; - } + oldbase = math_setmode(MODE_ENG); + break; + default: + math_error("Unsupported base"); + not_reached(); + break; + } - /* return the old base */ - return base_value(oldbase, conf->outmode); + /* return the old base */ + return base_value(oldbase, conf->outmode); } @@ -10233,54 +10233,54 @@ f_base(int count, NUMBER **vals) S_FUNC NUMBER * f_base2(int count, NUMBER **vals) { - long base; /* output base/mode */ - long oldbase=0; /* output base/mode */ + long base; /* output base/mode */ + long oldbase=0; /* output base/mode */ - /* deal with just a query */ - if (count != 1) { - return base_value(conf->outmode2, conf->outmode2); - } + /* deal with just a query */ + if (count != 1) { + return base_value(conf->outmode2, conf->outmode2); + } - /* deal with the special modes first */ - if (qisfrac(vals[0])) { - return base_value(math_setmode2(MODE_FRAC), conf->outmode2); - } - if (vals[0]->num.len > 64/BASEB) { - return base_value(math_setmode2(MODE_EXP), conf->outmode2); - } + /* deal with the special modes first */ + if (qisfrac(vals[0])) { + return base_value(math_setmode2(MODE_FRAC), conf->outmode2); + } + if (vals[0]->num.len > 64/BASEB) { + return base_value(math_setmode2(MODE_EXP), conf->outmode2); + } - /* set the base, if possible */ - base = qtoi(vals[0]); - switch (base) { - case 0: - oldbase = math_setmode2(MODE2_OFF); - break; - case -10: - oldbase = math_setmode2(MODE_INT); - break; - case 2: - oldbase = math_setmode2(MODE_BINARY); - break; - case 8: - oldbase = math_setmode2(MODE_OCTAL); - break; - case 10: - oldbase = math_setmode2(MODE_REAL); - break; - case 16: - oldbase = math_setmode2(MODE_HEX); - break; + /* set the base, if possible */ + base = qtoi(vals[0]); + switch (base) { + case 0: + oldbase = math_setmode2(MODE2_OFF); + break; + case -10: + oldbase = math_setmode2(MODE_INT); + break; + case 2: + oldbase = math_setmode2(MODE_BINARY); + break; + case 8: + oldbase = math_setmode2(MODE_OCTAL); + break; + case 10: + oldbase = math_setmode2(MODE_REAL); + break; + case 16: + oldbase = math_setmode2(MODE_HEX); + break; case 1000: - oldbase = math_setmode2(MODE_ENG); - break; - default: - math_error("Unsupported base"); - not_reached(); - break; - } + oldbase = math_setmode2(MODE_ENG); + break; + default: + math_error("Unsupported base"); + not_reached(); + break; + } - /* return the old base */ - return base_value(oldbase, conf->outmode2); + /* return the old base */ + return base_value(oldbase, conf->outmode2); } @@ -10290,344 +10290,344 @@ f_base2(int count, NUMBER **vals) S_FUNC NUMBER * base_value(long mode, int defval) { - NUMBER *result; + NUMBER *result; - /* return the old base */ - switch (mode) { - case MODE_DEFAULT: - switch (defval) { - case MODE_DEFAULT: - result = itoq(10); - break; - case MODE_FRAC: - result = qalloc(); - itoz(3, &result->den); - break; - case MODE_INT: - result = itoq(-10); - break; - case MODE_REAL: - result = itoq(10); - break; - case MODE_EXP: - result = qalloc(); - ztenpow(20, &result->num); - break; - case MODE_ENG: - result = itoq(1000); - break; - case MODE_HEX: - result = itoq(16); - break; - case MODE_OCTAL: - result = itoq(8); - break; - case MODE_BINARY: - result = itoq(2); - break; - case MODE2_OFF: - result = itoq(0); - break; - default: - result = itoq(0); - break; - } - break; - case MODE_FRAC: - result = qalloc(); - itoz(3, &result->den); - break; - case MODE_INT: - result = itoq(-10); - break; - case MODE_REAL: - result = itoq(10); - break; - case MODE_EXP: - result = qalloc(); - ztenpow(20, &result->num); - break; - case MODE_ENG: - result = itoq(1000); - break; - case MODE_HEX: - result = itoq(16); - break; - case MODE_OCTAL: - result = itoq(8); - break; - case MODE_BINARY: - result = itoq(2); - break; - case MODE2_OFF: - result = itoq(0); - break; - default: - result = itoq(0); - break; - } - return result; + /* return the old base */ + switch (mode) { + case MODE_DEFAULT: + switch (defval) { + case MODE_DEFAULT: + result = itoq(10); + break; + case MODE_FRAC: + result = qalloc(); + itoz(3, &result->den); + break; + case MODE_INT: + result = itoq(-10); + break; + case MODE_REAL: + result = itoq(10); + break; + case MODE_EXP: + result = qalloc(); + ztenpow(20, &result->num); + break; + case MODE_ENG: + result = itoq(1000); + break; + case MODE_HEX: + result = itoq(16); + break; + case MODE_OCTAL: + result = itoq(8); + break; + case MODE_BINARY: + result = itoq(2); + break; + case MODE2_OFF: + result = itoq(0); + break; + default: + result = itoq(0); + break; + } + break; + case MODE_FRAC: + result = qalloc(); + itoz(3, &result->den); + break; + case MODE_INT: + result = itoq(-10); + break; + case MODE_REAL: + result = itoq(10); + break; + case MODE_EXP: + result = qalloc(); + ztenpow(20, &result->num); + break; + case MODE_ENG: + result = itoq(1000); + break; + case MODE_HEX: + result = itoq(16); + break; + case MODE_OCTAL: + result = itoq(8); + break; + case MODE_BINARY: + result = itoq(2); + break; + case MODE2_OFF: + result = itoq(0); + break; + default: + result = itoq(0); + break; + } + return result; } S_FUNC VALUE f_custom(int count, VALUE **vals) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_type = V_NULL; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NULL; + result.v_subtype = V_NOSUBTYPE; - /* - * disable custom functions unless -C was given - */ - if (!allow_custom) { - fprintf(stderr, + /* + * disable custom functions unless -C was given + */ + if (!allow_custom) { + fprintf(stderr, #if defined(CUSTOM) - "%sCalc must be run with a -C argument to " - "use custom function\n", + "%sCalc must be run with a -C argument to " + "use custom function\n", #else /* CUSTOM */ - "%sCalc was built with custom functions disabled\n", + "%sCalc was built with custom functions disabled\n", #endif /* CUSTOM */ - (conf->tab_ok ? "\t" : "")); - return error_value(E_CUSTOM_ERROR); - } + (conf->tab_ok ? "\t" : "")); + return error_value(E_CUSTOM_ERROR); + } - /* - * perform the custom operation - */ - if (count <= 0) { - /* perform the usage function function */ - showcustom(); - } else { - /* firewall */ - if (vals[0]->v_type != V_STR) { - math_error("custom: 1st arg not a string name"); - not_reached(); - } + /* + * perform the custom operation + */ + if (count <= 0) { + /* perform the usage function function */ + showcustom(); + } else { + /* firewall */ + if (vals[0]->v_type != V_STR) { + math_error("custom: 1st arg not a string name"); + not_reached(); + } - /* perform the custom function */ - result = custom(vals[0]->v_str->s_str, count-1, vals+1); - } + /* perform the custom function */ + result = custom(vals[0]->v_str->s_str, count-1, vals+1); + } - /* - * return the custom result - */ - return result; + /* + * return the custom result + */ + return result; } S_FUNC VALUE f_blk(int count, VALUE **vals) { - int len; /* number of octets to malloc */ - int chunk; /* block chunk size */ - VALUE result; - int id; - VALUE *vp = NULL; - int type; + int len; /* number of octets to malloc */ + int chunk; /* block chunk size */ + VALUE result; + int id; + VALUE *vp = NULL; + int type; - /* initialize VALUE */ - result.v_type = V_BLOCK; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_BLOCK; + result.v_subtype = V_NOSUBTYPE; - type = V_NULL; - if (count > 0) { - vp = *vals; - type = vp->v_type; - if (type == V_STR || type == V_NBLOCK || type == V_BLOCK) { - vals++; - count--; - } - } + type = V_NULL; + if (count > 0) { + vp = *vals; + type = vp->v_type; + if (type == V_STR || type == V_NBLOCK || type == V_BLOCK) { + vals++; + count--; + } + } - len = -1; /* signal to use old or zero len */ - chunk = -1; /* signal to use old or default chunksize */ - if (count > 0 && vals[0]->v_type != V_NULL) { - /* parse len */ - if (vals[0]->v_type != V_NUM || qisfrac(vals[0]->v_num)) - return error_value(E_BLK_1); - if (qisneg(vals[0]->v_num) || zge31b(vals[0]->v_num->num)) - return error_value(E_BLK_2); - len = qtoi(vals[0]->v_num); - } - if (count > 1 && vals[1]->v_type != V_NULL) { - /* parse chunk */ - if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num)) - return error_value(E_BLK_3); - if (qisneg(vals[1]->v_num) || zge31b(vals[1]->v_num->num)) - return error_value(E_BLK_4); - chunk = qtoi(vals[1]->v_num); - } + len = -1; /* signal to use old or zero len */ + chunk = -1; /* signal to use old or default chunksize */ + if (count > 0 && vals[0]->v_type != V_NULL) { + /* parse len */ + if (vals[0]->v_type != V_NUM || qisfrac(vals[0]->v_num)) + return error_value(E_BLK_1); + if (qisneg(vals[0]->v_num) || zge31b(vals[0]->v_num->num)) + return error_value(E_BLK_2); + len = qtoi(vals[0]->v_num); + } + if (count > 1 && vals[1]->v_type != V_NULL) { + /* parse chunk */ + if (vals[1]->v_type != V_NUM || qisfrac(vals[1]->v_num)) + return error_value(E_BLK_3); + if (qisneg(vals[1]->v_num) || zge31b(vals[1]->v_num->num)) + return error_value(E_BLK_4); + chunk = qtoi(vals[1]->v_num); + } - if (type == V_STR) { - result.v_type = V_NBLOCK; - id = findnblockid(vp->v_str->s_str); - if (id < 0) { - /* create new named block */ - result.v_nblock = createnblock(vp->v_str->s_str, - len, chunk); - return result; - } - /* reallocate nblock */ - result.v_nblock = reallocnblock(id, len, chunk); - return result; - } + if (type == V_STR) { + result.v_type = V_NBLOCK; + id = findnblockid(vp->v_str->s_str); + if (id < 0) { + /* create new named block */ + result.v_nblock = createnblock(vp->v_str->s_str, + len, chunk); + return result; + } + /* reallocate nblock */ + result.v_nblock = reallocnblock(id, len, chunk); + return result; + } - if (type == V_NBLOCK) { - /* reallocate nblock */ - result.v_type = V_NBLOCK; - id = vp->v_nblock->id; - result.v_nblock = reallocnblock(id, len, chunk); - return result; - } - if (type == V_BLOCK) { - /* reallocate block */ - result.v_type = V_BLOCK; - result.v_block = copyrealloc(vp->v_block, len, chunk); - return result; - } + if (type == V_NBLOCK) { + /* reallocate nblock */ + result.v_type = V_NBLOCK; + id = vp->v_nblock->id; + result.v_nblock = reallocnblock(id, len, chunk); + return result; + } + if (type == V_BLOCK) { + /* reallocate block */ + result.v_type = V_BLOCK; + result.v_block = copyrealloc(vp->v_block, len, chunk); + return result; + } - /* allocate block */ - result.v_block = blkalloc(len, chunk); - return result; + /* allocate block */ + result.v_block = blkalloc(len, chunk); + return result; } S_FUNC VALUE f_blkfree(VALUE *vp) { - int id; - VALUE result; + int id; + VALUE result; - /* initialize VALUE */ - result.v_type = V_NULL; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NULL; + result.v_subtype = V_NOSUBTYPE; - id = 0; - switch (vp->v_type) { - case V_NBLOCK: - id = vp->v_nblock->id; - break; - case V_STR: - id = findnblockid(vp->v_str->s_str); - if (id < 0) - return error_value(E_BLKFREE_1); - break; - case V_NUM: - if (qisfrac(vp->v_num) || qisneg(vp->v_num)) - return error_value(E_BLKFREE_2); - if (zge31b(vp->v_num->num)) - return error_value(E_BLKFREE_3); - id = qtoi(vp->v_num); - break; - default: - return error_value(E_BLKFREE_4); - } - id = removenblock(id); - if (id) - return error_value(id); - return result; + id = 0; + switch (vp->v_type) { + case V_NBLOCK: + id = vp->v_nblock->id; + break; + case V_STR: + id = findnblockid(vp->v_str->s_str); + if (id < 0) + return error_value(E_BLKFREE_1); + break; + case V_NUM: + if (qisfrac(vp->v_num) || qisneg(vp->v_num)) + return error_value(E_BLKFREE_2); + if (zge31b(vp->v_num->num)) + return error_value(E_BLKFREE_3); + id = qtoi(vp->v_num); + break; + default: + return error_value(E_BLKFREE_4); + } + id = removenblock(id); + if (id) + return error_value(id); + return result; } S_FUNC VALUE f_blocks(int count, VALUE **vals) { - NBLOCK *nblk; - VALUE result; - int id; + NBLOCK *nblk; + VALUE result; + int id; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - if (count == 0) { - result.v_type = V_NUM; - result.v_num = itoq((long) countnblocks()); - return result; - } - if (vals[0]->v_type != V_NUM || qisfrac(vals[0]->v_num)) - return error_value(E_BLOCKS_1); - id = (int) qtoi(vals[0]->v_num); + if (count == 0) { + result.v_type = V_NUM; + result.v_num = itoq((long) countnblocks()); + return result; + } + if (vals[0]->v_type != V_NUM || qisfrac(vals[0]->v_num)) + return error_value(E_BLOCKS_1); + id = (int) qtoi(vals[0]->v_num); - nblk = findnblock(id); + nblk = findnblock(id); - if (nblk == NULL) { - return error_value(E_BLOCKS_2); - } else { - result.v_type = V_NBLOCK; - result.v_nblock = nblk; - } - return result; + if (nblk == NULL) { + return error_value(E_BLOCKS_2); + } else { + result.v_type = V_NBLOCK; + result.v_nblock = nblk; + } + return result; } S_FUNC VALUE f_free(int count, VALUE **vals) { - VALUE result; - VALUE *val; + VALUE result; + VALUE *val; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - result.v_type = V_NULL; - while (count-- > 0) { - val = *vals++; - if (val->v_type == V_ADDR) - freevalue(val->v_addr); - } - return result; + result.v_type = V_NULL; + while (count-- > 0) { + val = *vals++; + if (val->v_type == V_ADDR) + freevalue(val->v_addr); + } + return result; } S_FUNC VALUE f_freeglobals(void) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_type = V_NULL; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NULL; + result.v_subtype = V_NOSUBTYPE; - freeglobals(); - return result; + freeglobals(); + return result; } S_FUNC VALUE f_freeredc(void) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_type = V_NULL; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NULL; + result.v_subtype = V_NOSUBTYPE; - freeredcdata(); - return result; + freeredcdata(); + return result; } S_FUNC VALUE f_freestatics(void) { - VALUE result; + VALUE result; - /* initialize VALUE */ - result.v_type = V_NULL; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NULL; + result.v_subtype = V_NOSUBTYPE; - freestatics(); - return result; + freestatics(); + return result; } /* * f_copy - copy consecutive items between values * - * copy(src, dst [, ssi [, num [, dsi]]]) + * copy(src, dst [, ssi [, num [, dsi]]]) * * Copy 'num' consecutive items from 'src' with index 'ssi' to * 'dest', starting at position with index 'dsi'. @@ -10635,80 +10635,80 @@ f_freestatics(void) S_FUNC VALUE f_copy(int count, VALUE **vals) { - long ssi = 0; /* source start index */ - long num = -1; /* number of items to copy (-1 ==> all) */ - long dsi = -1; /* destination start index, -1 ==> default */ - int errtype; /* error type if unable to perform copy */ - VALUE result; /* null if successful */ + long ssi = 0; /* source start index */ + long num = -1; /* number of items to copy (-1 ==> all) */ + long dsi = -1; /* destination start index, -1 ==> default */ + int errtype; /* error type if unable to perform copy */ + VALUE result; /* null if successful */ - /* initialize VALUE */ - result.v_type = V_NULL; - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_type = V_NULL; + result.v_subtype = V_NOSUBTYPE; - /* - * parse args - */ - switch(count) { - case 5: - /* parse dsi */ - if (vals[4]->v_type != V_NULL) { - if (vals[4]->v_type != V_NUM || - qisfrac(vals[4]->v_num) || - qisneg(vals[4]->v_num)) { - return error_value(E_COPY_06); - } - if (zge31b(vals[4]->v_num->num)) { - return error_value(E_COPY_07); - } - dsi = qtoi(vals[4]->v_num); - } - /*FALLTHRU*/ + /* + * parse args + */ + switch(count) { + case 5: + /* parse dsi */ + if (vals[4]->v_type != V_NULL) { + if (vals[4]->v_type != V_NUM || + qisfrac(vals[4]->v_num) || + qisneg(vals[4]->v_num)) { + return error_value(E_COPY_06); + } + if (zge31b(vals[4]->v_num->num)) { + return error_value(E_COPY_07); + } + dsi = qtoi(vals[4]->v_num); + } + /*FALLTHRU*/ - case 4: - /* parse num */ - if (vals[3]->v_type != V_NULL) { - if (vals[3]->v_type != V_NUM || - qisfrac(vals[3]->v_num) || - qisneg(vals[3]->v_num)) { - return error_value(E_COPY_01); - } - if (zge31b(vals[3]->v_num->num)) { - return error_value(E_COPY_02); - } - num = qtoi(vals[3]->v_num); - } - /*FALLTHRU*/ + case 4: + /* parse num */ + if (vals[3]->v_type != V_NULL) { + if (vals[3]->v_type != V_NUM || + qisfrac(vals[3]->v_num) || + qisneg(vals[3]->v_num)) { + return error_value(E_COPY_01); + } + if (zge31b(vals[3]->v_num->num)) { + return error_value(E_COPY_02); + } + num = qtoi(vals[3]->v_num); + } + /*FALLTHRU*/ - case 3: - /* parse ssi */ - if (vals[2]->v_type != V_NULL) { - if (vals[2]->v_type != V_NUM || - qisfrac(vals[2]->v_num) || - qisneg(vals[2]->v_num)) { - return error_value(E_COPY_04); - } - if (zge31b(vals[2]->v_num->num)) { - return error_value(E_COPY_05); - } - ssi = qtoi(vals[2]->v_num); - } - break; - } + case 3: + /* parse ssi */ + if (vals[2]->v_type != V_NULL) { + if (vals[2]->v_type != V_NUM || + qisfrac(vals[2]->v_num) || + qisneg(vals[2]->v_num)) { + return error_value(E_COPY_04); + } + if (zge31b(vals[2]->v_num->num)) { + return error_value(E_COPY_05); + } + ssi = qtoi(vals[2]->v_num); + } + break; + } - /* - * copy - */ - errtype = copystod(vals[0], ssi, num, vals[1], dsi); - if (errtype > 0) - return error_value(errtype); - return result; + /* + * copy + */ + errtype = copystod(vals[0], ssi, num, vals[1], dsi); + if (errtype > 0) + return error_value(errtype); + return result; } /* * f_blkcpy - copy consecutive items between values * - * copy(dst, src [, num [, dsi [, ssi]]]) + * copy(dst, src [, num [, dsi [, ssi]]]) * * Copy 'num' consecutive items from 'src' with index 'ssi' to * 'dest', starting at position with index 'dsi'. @@ -10716,178 +10716,178 @@ f_copy(int count, VALUE **vals) S_FUNC VALUE f_blkcpy(int count, VALUE **vals) { - VALUE *args[5]; /* args to re-order */ - VALUE null_value; /* dummy argument */ + VALUE *args[5]; /* args to re-order */ + VALUE null_value; /* dummy argument */ - /* initialize VALUE */ - null_value.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + null_value.v_subtype = V_NOSUBTYPE; - /* - * parse args into f_copy order - */ - args[0] = vals[1]; - args[1] = vals[0]; - null_value.v_type = V_NULL; - args[2] = &null_value; - args[3] = &null_value; - args[4] = &null_value; - switch(count) { - case 5: - args[2] = vals[4]; - args[4] = vals[3]; - args[3] = vals[2]; - break; - case 4: - count = 5; - args[4] = vals[3]; - args[3] = vals[2]; - break; - case 3: - count = 4; - args[3] = vals[2]; - break; - } + /* + * parse args into f_copy order + */ + args[0] = vals[1]; + args[1] = vals[0]; + null_value.v_type = V_NULL; + args[2] = &null_value; + args[3] = &null_value; + args[4] = &null_value; + switch(count) { + case 5: + args[2] = vals[4]; + args[4] = vals[3]; + args[3] = vals[2]; + break; + case 4: + count = 5; + args[4] = vals[3]; + args[3] = vals[2]; + break; + case 3: + count = 4; + args[3] = vals[2]; + break; + } - /* - * copy - */ - return f_copy(count, args); + /* + * copy + */ + return f_copy(count, args); } S_FUNC VALUE f_sha1(int count, VALUE **vals) { - VALUE result; - HASH *state; /* pointer to hash state to use */ - int i; /* vals[i] to hash */ + VALUE result; + HASH *state; /* pointer to hash state to use */ + int i; /* vals[i] to hash */ - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * arg check - */ - if (count == 0) { + /* + * arg check + */ + if (count == 0) { - /* return an initial hash state */ - result.v_type = V_HASH; - result.v_hash = hash_init(SHA1_HASH_TYPE, NULL); + /* return an initial hash state */ + result.v_type = V_HASH; + result.v_hash = hash_init(SHA1_HASH_TYPE, NULL); - } else if (count == 1 && vals[0]->v_type == V_HASH && - vals[0]->v_hash->hashtype == SHA1_HASH_TYPE) { + } else if (count == 1 && vals[0]->v_type == V_HASH && + vals[0]->v_hash->hashtype == SHA1_HASH_TYPE) { - /* if just a hash value, finalize it */ - state = hash_copy(vals[0]->v_hash); - result.v_type = V_NUM; - result.v_num = qalloc(); - result.v_num->num = hash_final(state); - hash_free(state); + /* if just a hash value, finalize it */ + state = hash_copy(vals[0]->v_hash); + result.v_type = V_NUM; + result.v_num = qalloc(); + result.v_num->num = hash_final(state); + hash_free(state); - } else { + } else { - /* - * If the first value is a hash, use that as - * the initial hash state - */ - if (vals[0]->v_type == V_HASH && - vals[0]->v_hash->hashtype == SHA1_HASH_TYPE) { - state = hash_copy(vals[0]->v_hash); - i = 1; + /* + * If the first value is a hash, use that as + * the initial hash state + */ + if (vals[0]->v_type == V_HASH && + vals[0]->v_hash->hashtype == SHA1_HASH_TYPE) { + state = hash_copy(vals[0]->v_hash); + i = 1; - /* - * otherwise use the default initial state - */ - } else { - state = hash_init(SHA1_HASH_TYPE, NULL); - i = 0; - } + /* + * otherwise use the default initial state + */ + } else { + state = hash_init(SHA1_HASH_TYPE, NULL); + i = 0; + } - /* - * hash the remaining values - */ - do { - state = hash_value(SHA1_HASH_TYPE, vals[i], state); - } while (++i < count); + /* + * hash the remaining values + */ + do { + state = hash_value(SHA1_HASH_TYPE, vals[i], state); + } while (++i < count); - /* - * return the current hash state - */ - result.v_type = V_HASH; - result.v_hash = state; - } + /* + * return the current hash state + */ + result.v_type = V_HASH; + result.v_hash = state; + } - /* return the result */ - return result; + /* return the result */ + return result; } S_FUNC VALUE f_argv(int count, VALUE **vals) { - int arg; /* the argv_value string index */ - VALUE result; + int arg; /* the argv_value string index */ + VALUE result; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * arg check - */ - if (count == 0) { + /* + * arg check + */ + if (count == 0) { - /* return the argc count */ - result.v_type = V_NUM; - result.v_num = itoq((long) argc_value); + /* return the argc count */ + result.v_type = V_NUM; + result.v_num = itoq((long) argc_value); - } else { + } else { - /* firewall */ - if (vals[0]->v_type != V_NUM || qisfrac(vals[0]->v_num) || - qisneg(vals[0]->v_num) || zge31b(vals[0]->v_num->num)) { + /* firewall */ + if (vals[0]->v_type != V_NUM || qisfrac(vals[0]->v_num) || + qisneg(vals[0]->v_num) || zge31b(vals[0]->v_num->num)) { - math_error("argv argument must be a integer [0,2^31)"); - not_reached(); - } + math_error("argv argument must be a integer [0,2^31)"); + not_reached(); + } - /* determine the arg value of the argv() function */ - arg = qtoi(vals[0]->v_num); + /* determine the arg value of the argv() function */ + arg = qtoi(vals[0]->v_num); - /* argv(0) is program or script_name if -f filename was used */ - if (arg == 0) { - if (script_name == NULL) { - /* paranoia */ - result.v_type = V_NULL; - } else { - result.v_type = V_STR; - result.v_str = makenewstring(script_name); - } + /* argv(0) is program or script_name if -f filename was used */ + if (arg == 0) { + if (script_name == NULL) { + /* paranoia */ + result.v_type = V_NULL; + } else { + result.v_type = V_STR; + result.v_str = makenewstring(script_name); + } - /* return the n-th argv string */ - } else if (arg < argc_value && argv_value[arg-1] != NULL) { - result.v_type = V_STR; - result.v_str = makestring(strdup(argv_value[arg-1])); - } else { - result.v_type = V_NULL; - } - } + /* return the n-th argv string */ + } else if (arg < argc_value && argv_value[arg-1] != NULL) { + result.v_type = V_STR; + result.v_str = makestring(strdup(argv_value[arg-1])); + } else { + result.v_type = V_NULL; + } + } - /* return the result */ - return result; + /* return the result */ + return result; } S_FUNC VALUE f_version(void) { - VALUE result; + VALUE result; - /* return the calc version string */ - result.v_type = V_STR; - result.v_subtype = V_NOSUBTYPE; - result.v_str = makestring(strdup(version())); + /* return the calc version string */ + result.v_type = V_STR; + result.v_subtype = V_NOSUBTYPE; + result.v_str = makestring(strdup(version())); - return result; + return result; } @@ -10897,54 +10897,54 @@ f_version(void) S_FUNC VALUE f_versin(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *eps; + VALUE result; + COMPLEX *c; + NUMBER *eps; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_VERSIN_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_VERSIN_1); + } + eps = vals[1]->v_num; + } - /* - * compute versed trigonometric sine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qversin(vals[0]->v_num, eps); - result.v_type = V_NUM; - break; - case V_COM: - c = c_versin(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_VERSIN_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * compute versed trigonometric sine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qversin(vals[0]->v_num, eps); + result.v_type = V_NUM; + break; + case V_COM: + c = c_versin(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_VERSIN_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_VERSIN_2); - } - return result; + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_VERSIN_2); + } + return result; } @@ -10954,78 +10954,78 @@ f_versin(int count, VALUE **vals) S_FUNC VALUE f_aversin(int count, VALUE **vals) { - VALUE result; /* value to return */ - COMPLEX *c; /* COMPLEX trig result */ - NUMBER *eps; /* epsilon error tolerance */ + VALUE result; /* value to return */ + COMPLEX *c; /* COMPLEX trig result */ + NUMBER *eps; /* epsilon error tolerance */ - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_AVERSIN_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_AVERSIN_1); + } + eps = vals[1]->v_num; + } - /* - * compute inverse versed trigonometric sine to a given error tolerance - */ - if (vals[0]->v_type == V_NUM) { + /* + * compute inverse versed trigonometric sine to a given error tolerance + */ + if (vals[0]->v_type == V_NUM) { - /* try to compute result using real trig function */ - result.v_num = qaversin_or_NULL(vals[0]->v_num, eps); + /* try to compute result using real trig function */ + result.v_num = qaversin_or_NULL(vals[0]->v_num, eps); - /* - * case: trig function returned a NUMBER - */ - if (result.v_num != NULL) { - result.v_type = V_NUM; + /* + * case: trig function returned a NUMBER + */ + if (result.v_num != NULL) { + result.v_type = V_NUM; - /* - * case: trig function returned NULL - need to try COMPLEX trig function - */ - } else { - /* convert NUMBER argument from NUMBER to COMPLEX */ - vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); - vals[0]->v_type = V_COM; - } - } - if (vals[0]->v_type == V_COM) { + /* + * case: trig function returned NULL - need to try COMPLEX trig function + */ + } else { + /* convert NUMBER argument from NUMBER to COMPLEX */ + vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); + vals[0]->v_type = V_COM; + } + } + if (vals[0]->v_type == V_COM) { - /* - * case: argument was COMPLEX or - * trig function returned NULL and argument was converted to COMPLEX - */ - c = c_aversin(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_AVERSIN_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * case: argument was COMPLEX or + * trig function returned NULL and argument was converted to COMPLEX + */ + c = c_aversin(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_AVERSIN_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - } - if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + } + if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { - /* - * case: argument type is not valid for this function - */ - return error_value(E_AVERSIN_2); - } - return result; + /* + * case: argument type is not valid for this function + */ + return error_value(E_AVERSIN_2); + } + return result; } @@ -11035,54 +11035,54 @@ f_aversin(int count, VALUE **vals) S_FUNC VALUE f_coversin(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *eps; + VALUE result; + COMPLEX *c; + NUMBER *eps; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_COVERSIN_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_COVERSIN_1); + } + eps = vals[1]->v_num; + } - /* - * compute coversed trigonometric sine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qcoversin(vals[0]->v_num, eps); - result.v_type = V_NUM; - break; - case V_COM: - c = c_coversin(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_COVERSIN_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * compute coversed trigonometric sine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qcoversin(vals[0]->v_num, eps); + result.v_type = V_NUM; + break; + case V_COM: + c = c_coversin(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_COVERSIN_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_COVERSIN_2); - } - return result; + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_COVERSIN_2); + } + return result; } @@ -11092,78 +11092,78 @@ f_coversin(int count, VALUE **vals) S_FUNC VALUE f_acoversin(int count, VALUE **vals) { - VALUE result; /* value to return */ - COMPLEX *c; /* COMPLEX trig result */ - NUMBER *eps; /* epsilon error tolerance */ + VALUE result; /* value to return */ + COMPLEX *c; /* COMPLEX trig result */ + NUMBER *eps; /* epsilon error tolerance */ - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_ACOVERSIN_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_ACOVERSIN_1); + } + eps = vals[1]->v_num; + } - /* - * compute inverse coversed trigonometric sine to a given error tolerance - */ - if (vals[0]->v_type == V_NUM) { + /* + * compute inverse coversed trigonometric sine to a given error tolerance + */ + if (vals[0]->v_type == V_NUM) { - /* try to compute result using real trig function */ - result.v_num = qacoversin_or_NULL(vals[0]->v_num, eps); + /* try to compute result using real trig function */ + result.v_num = qacoversin_or_NULL(vals[0]->v_num, eps); - /* - * case: trig function returned a NUMBER - */ - if (result.v_num != NULL) { - result.v_type = V_NUM; + /* + * case: trig function returned a NUMBER + */ + if (result.v_num != NULL) { + result.v_type = V_NUM; - /* - * case: trig function returned NULL - need to try COMPLEX trig function - */ - } else { - /* convert NUMBER argument from NUMBER to COMPLEX */ - vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); - vals[0]->v_type = V_COM; - } - } - if (vals[0]->v_type == V_COM) { + /* + * case: trig function returned NULL - need to try COMPLEX trig function + */ + } else { + /* convert NUMBER argument from NUMBER to COMPLEX */ + vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); + vals[0]->v_type = V_COM; + } + } + if (vals[0]->v_type == V_COM) { - /* - * case: argument was COMPLEX or - * trig function returned NULL and argument was converted to COMPLEX - */ - c = c_acoversin(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_ACOVERSIN_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * case: argument was COMPLEX or + * trig function returned NULL and argument was converted to COMPLEX + */ + c = c_acoversin(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_ACOVERSIN_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - } - if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + } + if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { - /* - * case: argument type is not valid for this function - */ - return error_value(E_ACOVERSIN_2); - } - return result; + /* + * case: argument type is not valid for this function + */ + return error_value(E_ACOVERSIN_2); + } + return result; } @@ -11173,54 +11173,54 @@ f_acoversin(int count, VALUE **vals) S_FUNC VALUE f_vercos(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *eps; + VALUE result; + COMPLEX *c; + NUMBER *eps; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_VERCOS_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_VERCOS_1); + } + eps = vals[1]->v_num; + } - /* - * compute versed trigonometric cosine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qvercos(vals[0]->v_num, eps); - result.v_type = V_NUM; - break; - case V_COM: - c = c_vercos(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_VERCOS_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * compute versed trigonometric cosine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qvercos(vals[0]->v_num, eps); + result.v_type = V_NUM; + break; + case V_COM: + c = c_vercos(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_VERCOS_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_VERCOS_2); - } - return result; + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_VERCOS_2); + } + return result; } @@ -11230,78 +11230,78 @@ f_vercos(int count, VALUE **vals) S_FUNC VALUE f_avercos(int count, VALUE **vals) { - VALUE result; /* value to return */ - COMPLEX *c; /* COMPLEX trig result */ - NUMBER *eps; /* epsilon error tolerance */ + VALUE result; /* value to return */ + COMPLEX *c; /* COMPLEX trig result */ + NUMBER *eps; /* epsilon error tolerance */ - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_AVERCOS_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_AVERCOS_1); + } + eps = vals[1]->v_num; + } - /* - * compute inverse versed trigonometric cosine to a given error tolerance - */ - if (vals[0]->v_type == V_NUM) { + /* + * compute inverse versed trigonometric cosine to a given error tolerance + */ + if (vals[0]->v_type == V_NUM) { - /* try to compute result using real trig function */ - result.v_num = qavercos_or_NULL(vals[0]->v_num, eps); + /* try to compute result using real trig function */ + result.v_num = qavercos_or_NULL(vals[0]->v_num, eps); - /* - * case: trig function returned a NUMBER - */ - if (result.v_num != NULL) { - result.v_type = V_NUM; + /* + * case: trig function returned a NUMBER + */ + if (result.v_num != NULL) { + result.v_type = V_NUM; - /* - * case: trig function returned NULL - need to try COMPLEX trig function - */ - } else { - /* convert NUMBER argument from NUMBER to COMPLEX */ - vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); - vals[0]->v_type = V_COM; - } - } - if (vals[0]->v_type == V_COM) { + /* + * case: trig function returned NULL - need to try COMPLEX trig function + */ + } else { + /* convert NUMBER argument from NUMBER to COMPLEX */ + vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); + vals[0]->v_type = V_COM; + } + } + if (vals[0]->v_type == V_COM) { - /* - * case: argument was COMPLEX or - * trig function returned NULL and argument was converted to COMPLEX - */ - c = c_avercos(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_AVERCOS_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * case: argument was COMPLEX or + * trig function returned NULL and argument was converted to COMPLEX + */ + c = c_avercos(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_AVERCOS_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - } - if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + } + if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { - /* - * case: argument type is not valid for this function - */ - return error_value(E_AVERCOS_2); - } - return result; + /* + * case: argument type is not valid for this function + */ + return error_value(E_AVERCOS_2); + } + return result; } @@ -11311,54 +11311,54 @@ f_avercos(int count, VALUE **vals) S_FUNC VALUE f_covercos(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *eps; + VALUE result; + COMPLEX *c; + NUMBER *eps; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_COVERCOS_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_COVERCOS_1); + } + eps = vals[1]->v_num; + } - /* - * compute coversed trigonometric cosine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qcovercos(vals[0]->v_num, eps); - result.v_type = V_NUM; - break; - case V_COM: - c = c_covercos(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_COVERCOS_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * compute coversed trigonometric cosine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qcovercos(vals[0]->v_num, eps); + result.v_type = V_NUM; + break; + case V_COM: + c = c_covercos(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_COVERCOS_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_COVERCOS_2); - } - return result; + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_COVERCOS_2); + } + return result; } @@ -11368,78 +11368,78 @@ f_covercos(int count, VALUE **vals) S_FUNC VALUE f_acovercos(int count, VALUE **vals) { - VALUE result; /* value to return */ - COMPLEX *c; /* COMPLEX trig result */ - NUMBER *eps; /* epsilon error tolerance */ + VALUE result; /* value to return */ + COMPLEX *c; /* COMPLEX trig result */ + NUMBER *eps; /* epsilon error tolerance */ - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_ACOVERCOS_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_ACOVERCOS_1); + } + eps = vals[1]->v_num; + } - /* - * compute inverse coversed trigonometric cosine to a given error tolerance - */ - if (vals[0]->v_type == V_NUM) { + /* + * compute inverse coversed trigonometric cosine to a given error tolerance + */ + if (vals[0]->v_type == V_NUM) { - /* try to compute result using real trig function */ - result.v_num = qacovercos_or_NULL(vals[0]->v_num, eps); + /* try to compute result using real trig function */ + result.v_num = qacovercos_or_NULL(vals[0]->v_num, eps); - /* - * case: trig function returned a NUMBER - */ - if (result.v_num != NULL) { - result.v_type = V_NUM; + /* + * case: trig function returned a NUMBER + */ + if (result.v_num != NULL) { + result.v_type = V_NUM; - /* - * case: trig function returned NULL - need to try COMPLEX trig function - */ - } else { - /* convert NUMBER argument from NUMBER to COMPLEX */ - vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); - vals[0]->v_type = V_COM; - } - } - if (vals[0]->v_type == V_COM) { + /* + * case: trig function returned NULL - need to try COMPLEX trig function + */ + } else { + /* convert NUMBER argument from NUMBER to COMPLEX */ + vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); + vals[0]->v_type = V_COM; + } + } + if (vals[0]->v_type == V_COM) { - /* - * case: argument was COMPLEX or - * trig function returned NULL and argument was converted to COMPLEX - */ - c = c_acovercos(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_ACOVERCOS_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * case: argument was COMPLEX or + * trig function returned NULL and argument was converted to COMPLEX + */ + c = c_acovercos(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_ACOVERCOS_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - } - if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + } + if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { - /* - * case: argument type is not valid for this function - */ - return error_value(E_ACOVERCOS_2); - } - return result; + /* + * case: argument type is not valid for this function + */ + return error_value(E_ACOVERCOS_2); + } + return result; } @@ -11449,54 +11449,54 @@ f_acovercos(int count, VALUE **vals) S_FUNC VALUE f_haversin(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *eps; + VALUE result; + COMPLEX *c; + NUMBER *eps; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_HAVERSIN_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_HAVERSIN_1); + } + eps = vals[1]->v_num; + } - /* - * compute half versed trigonometric sine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qhaversin(vals[0]->v_num, eps); - result.v_type = V_NUM; - break; - case V_COM: - c = c_haversin(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_HAVERSIN_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * compute half versed trigonometric sine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qhaversin(vals[0]->v_num, eps); + result.v_type = V_NUM; + break; + case V_COM: + c = c_haversin(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_HAVERSIN_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_HAVERSIN_2); - } - return result; + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_HAVERSIN_2); + } + return result; } @@ -11506,78 +11506,78 @@ f_haversin(int count, VALUE **vals) S_FUNC VALUE f_ahaversin(int count, VALUE **vals) { - VALUE result; /* value to return */ - COMPLEX *c; /* COMPLEX trig result */ - NUMBER *eps; /* epsilon error tolerance */ + VALUE result; /* value to return */ + COMPLEX *c; /* COMPLEX trig result */ + NUMBER *eps; /* epsilon error tolerance */ - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_AHAVERSIN_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_AHAVERSIN_1); + } + eps = vals[1]->v_num; + } - /* - * compute inverse half versed trigonometric sine to a given error tolerance - */ - if (vals[0]->v_type == V_NUM) { + /* + * compute inverse half versed trigonometric sine to a given error tolerance + */ + if (vals[0]->v_type == V_NUM) { - /* try to compute result using real trig function */ - result.v_num = qahaversin_or_NULL(vals[0]->v_num, eps); + /* try to compute result using real trig function */ + result.v_num = qahaversin_or_NULL(vals[0]->v_num, eps); - /* - * case: trig function returned a NUMBER - */ - if (result.v_num != NULL) { - result.v_type = V_NUM; + /* + * case: trig function returned a NUMBER + */ + if (result.v_num != NULL) { + result.v_type = V_NUM; - /* - * case: trig function returned NULL - need to try COMPLEX trig function - */ - } else { - /* convert NUMBER argument from NUMBER to COMPLEX */ - vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); - vals[0]->v_type = V_COM; - } - } - if (vals[0]->v_type == V_COM) { + /* + * case: trig function returned NULL - need to try COMPLEX trig function + */ + } else { + /* convert NUMBER argument from NUMBER to COMPLEX */ + vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); + vals[0]->v_type = V_COM; + } + } + if (vals[0]->v_type == V_COM) { - /* - * case: argument was COMPLEX or - * trig function returned NULL and argument was converted to COMPLEX - */ - c = c_ahaversin(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_AHAVERSIN_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * case: argument was COMPLEX or + * trig function returned NULL and argument was converted to COMPLEX + */ + c = c_ahaversin(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_AHAVERSIN_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - } - if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + } + if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { - /* - * case: argument type is not valid for this function - */ - return error_value(E_AHAVERSIN_2); - } - return result; + /* + * case: argument type is not valid for this function + */ + return error_value(E_AHAVERSIN_2); + } + return result; } @@ -11587,54 +11587,54 @@ f_ahaversin(int count, VALUE **vals) S_FUNC VALUE f_hacoversin(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *eps; + VALUE result; + COMPLEX *c; + NUMBER *eps; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_HACOVERSIN_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_HACOVERSIN_1); + } + eps = vals[1]->v_num; + } - /* - * compute half coversed trigonometric sine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qhacoversin(vals[0]->v_num, eps); - result.v_type = V_NUM; - break; - case V_COM: - c = c_hacoversin(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_HACOVERSIN_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * compute half coversed trigonometric sine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qhacoversin(vals[0]->v_num, eps); + result.v_type = V_NUM; + break; + case V_COM: + c = c_hacoversin(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_HACOVERSIN_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_HACOVERSIN_2); - } - return result; + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_HACOVERSIN_2); + } + return result; } @@ -11644,78 +11644,78 @@ f_hacoversin(int count, VALUE **vals) S_FUNC VALUE f_ahacoversin(int count, VALUE **vals) { - VALUE result; /* value to return */ - COMPLEX *c; /* COMPLEX trig result */ - NUMBER *eps; /* epsilon error tolerance */ + VALUE result; /* value to return */ + COMPLEX *c; /* COMPLEX trig result */ + NUMBER *eps; /* epsilon error tolerance */ - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_AHACOVERSIN_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_AHACOVERSIN_1); + } + eps = vals[1]->v_num; + } - /* - * compute inverse half coversed trigonometric sine to a given error tolerance - */ - if (vals[0]->v_type == V_NUM) { + /* + * compute inverse half coversed trigonometric sine to a given error tolerance + */ + if (vals[0]->v_type == V_NUM) { - /* try to compute result using real trig function */ - result.v_num = qahacoversin_or_NULL(vals[0]->v_num, eps); + /* try to compute result using real trig function */ + result.v_num = qahacoversin_or_NULL(vals[0]->v_num, eps); - /* - * case: trig function returned a NUMBER - */ - if (result.v_num != NULL) { - result.v_type = V_NUM; + /* + * case: trig function returned a NUMBER + */ + if (result.v_num != NULL) { + result.v_type = V_NUM; - /* - * case: trig function returned NULL - need to try COMPLEX trig function - */ - } else { - /* convert NUMBER argument from NUMBER to COMPLEX */ - vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); - vals[0]->v_type = V_COM; - } - } - if (vals[0]->v_type == V_COM) { + /* + * case: trig function returned NULL - need to try COMPLEX trig function + */ + } else { + /* convert NUMBER argument from NUMBER to COMPLEX */ + vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); + vals[0]->v_type = V_COM; + } + } + if (vals[0]->v_type == V_COM) { - /* - * case: argument was COMPLEX or - * trig function returned NULL and argument was converted to COMPLEX - */ - c = c_ahacoversin(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_AHACOVERSIN_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * case: argument was COMPLEX or + * trig function returned NULL and argument was converted to COMPLEX + */ + c = c_ahacoversin(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_AHACOVERSIN_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - } - if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + } + if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { - /* - * case: argument type is not valid for this function - */ - return error_value(E_AHACOVERSIN_2); - } - return result; + /* + * case: argument type is not valid for this function + */ + return error_value(E_AHACOVERSIN_2); + } + return result; } @@ -11725,54 +11725,54 @@ f_ahacoversin(int count, VALUE **vals) S_FUNC VALUE f_havercos(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *eps; + VALUE result; + COMPLEX *c; + NUMBER *eps; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_HAVERCOS_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_HAVERCOS_1); + } + eps = vals[1]->v_num; + } - /* - * compute half versed trigonometric cosine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qhavercos(vals[0]->v_num, eps); - result.v_type = V_NUM; - break; - case V_COM: - c = c_havercos(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_HAVERCOS_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * compute half versed trigonometric cosine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qhavercos(vals[0]->v_num, eps); + result.v_type = V_NUM; + break; + case V_COM: + c = c_havercos(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_HAVERCOS_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_HAVERCOS_2); - } - return result; + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_HAVERCOS_2); + } + return result; } @@ -11782,78 +11782,78 @@ f_havercos(int count, VALUE **vals) S_FUNC VALUE f_ahavercos(int count, VALUE **vals) { - VALUE result; /* value to return */ - COMPLEX *c; /* COMPLEX trig result */ - NUMBER *eps; /* epsilon error tolerance */ + VALUE result; /* value to return */ + COMPLEX *c; /* COMPLEX trig result */ + NUMBER *eps; /* epsilon error tolerance */ - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_AHAVERCOS_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_AHAVERCOS_1); + } + eps = vals[1]->v_num; + } - /* - * compute inverse half versed trigonometric cosine to a given error tolerance - */ - if (vals[0]->v_type == V_NUM) { + /* + * compute inverse half versed trigonometric cosine to a given error tolerance + */ + if (vals[0]->v_type == V_NUM) { - /* try to compute result using real trig function */ - result.v_num = qahavercos_or_NULL(vals[0]->v_num, eps); + /* try to compute result using real trig function */ + result.v_num = qahavercos_or_NULL(vals[0]->v_num, eps); - /* - * case: trig function returned a NUMBER - */ - if (result.v_num != NULL) { - result.v_type = V_NUM; + /* + * case: trig function returned a NUMBER + */ + if (result.v_num != NULL) { + result.v_type = V_NUM; - /* - * case: trig function returned NULL - need to try COMPLEX trig function - */ - } else { - /* convert NUMBER argument from NUMBER to COMPLEX */ - vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); - vals[0]->v_type = V_COM; - } - } - if (vals[0]->v_type == V_COM) { + /* + * case: trig function returned NULL - need to try COMPLEX trig function + */ + } else { + /* convert NUMBER argument from NUMBER to COMPLEX */ + vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); + vals[0]->v_type = V_COM; + } + } + if (vals[0]->v_type == V_COM) { - /* - * case: argument was COMPLEX or - * trig function returned NULL and argument was converted to COMPLEX - */ - c = c_ahavercos(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_AHAVERCOS_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * case: argument was COMPLEX or + * trig function returned NULL and argument was converted to COMPLEX + */ + c = c_ahavercos(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_AHAVERCOS_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - } - if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + } + if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { - /* - * case: argument type is not valid for this function - */ - return error_value(E_AHAVERCOS_2); - } - return result; + /* + * case: argument type is not valid for this function + */ + return error_value(E_AHAVERCOS_2); + } + return result; } @@ -11863,54 +11863,54 @@ f_ahavercos(int count, VALUE **vals) S_FUNC VALUE f_hacovercos(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *eps; + VALUE result; + COMPLEX *c; + NUMBER *eps; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_HACOVERCOS_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_HACOVERCOS_1); + } + eps = vals[1]->v_num; + } - /* - * compute half coversed trigonometric cosine to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qhacovercos(vals[0]->v_num, eps); - result.v_type = V_NUM; - break; - case V_COM: - c = c_hacovercos(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_HACOVERCOS_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * compute half coversed trigonometric cosine to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qhacovercos(vals[0]->v_num, eps); + result.v_type = V_NUM; + break; + case V_COM: + c = c_hacovercos(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_HACOVERCOS_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_HACOVERCOS_2); - } - return result; + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_HACOVERCOS_2); + } + return result; } @@ -11920,78 +11920,78 @@ f_hacovercos(int count, VALUE **vals) S_FUNC VALUE f_ahacovercos(int count, VALUE **vals) { - VALUE result; /* value to return */ - COMPLEX *c; /* COMPLEX trig result */ - NUMBER *eps; /* epsilon error tolerance */ + VALUE result; /* value to return */ + COMPLEX *c; /* COMPLEX trig result */ + NUMBER *eps; /* epsilon error tolerance */ - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_AHACOVERCOS_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_AHACOVERCOS_1); + } + eps = vals[1]->v_num; + } - /* - * compute inverse half coversed trigonometric cosine to a given error tolerance - */ - if (vals[0]->v_type == V_NUM) { + /* + * compute inverse half coversed trigonometric cosine to a given error tolerance + */ + if (vals[0]->v_type == V_NUM) { - /* try to compute result using real trig function */ - result.v_num = qahacovercos_or_NULL(vals[0]->v_num, eps); + /* try to compute result using real trig function */ + result.v_num = qahacovercos_or_NULL(vals[0]->v_num, eps); - /* - * case: trig function returned a NUMBER - */ - if (result.v_num != NULL) { - result.v_type = V_NUM; + /* + * case: trig function returned a NUMBER + */ + if (result.v_num != NULL) { + result.v_type = V_NUM; - /* - * case: trig function returned NULL - need to try COMPLEX trig function - */ - } else { - /* convert NUMBER argument from NUMBER to COMPLEX */ - vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); - vals[0]->v_type = V_COM; - } - } - if (vals[0]->v_type == V_COM) { + /* + * case: trig function returned NULL - need to try COMPLEX trig function + */ + } else { + /* convert NUMBER argument from NUMBER to COMPLEX */ + vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); + vals[0]->v_type = V_COM; + } + } + if (vals[0]->v_type == V_COM) { - /* - * case: argument was COMPLEX or - * trig function returned NULL and argument was converted to COMPLEX - */ - c = c_ahacovercos(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_AHACOVERCOS_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * case: argument was COMPLEX or + * trig function returned NULL and argument was converted to COMPLEX + */ + c = c_ahacovercos(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_AHACOVERCOS_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - } - if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + } + if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { - /* - * case: argument type is not valid for this function - */ - return error_value(E_AHACOVERCOS_2); - } - return result; + /* + * case: argument type is not valid for this function + */ + return error_value(E_AHACOVERCOS_2); + } + return result; } @@ -12001,50 +12001,50 @@ f_ahacovercos(int count, VALUE **vals) S_FUNC VALUE f_exsec(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *err; + VALUE result; + COMPLEX *c; + NUMBER *err; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use err VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_EXSEC_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use err VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_EXSEC_1); + } + err = vals[1]->v_num; + } - /* - * compute exterior trigonometric secant to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qexsec(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - c = c_exsec(vals[0]->v_com, err); - if (c == NULL) { - return error_value(E_EXSEC_3); - } - result.v_com = c; - result.v_type = V_COM; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_EXSEC_2); - } - return result; + /* + * compute exterior trigonometric secant to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qexsec(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + c = c_exsec(vals[0]->v_com, err); + if (c == NULL) { + return error_value(E_EXSEC_3); + } + result.v_com = c; + result.v_type = V_COM; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_EXSEC_2); + } + return result; } @@ -12054,83 +12054,83 @@ f_exsec(int count, VALUE **vals) S_FUNC VALUE f_aexsec(int count, VALUE **vals) { - VALUE result; /* value to return */ - COMPLEX *c; /* COMPLEX trig result */ - NUMBER *eps; /* epsilon error tolerance */ + VALUE result; /* value to return */ + COMPLEX *c; /* COMPLEX trig result */ + NUMBER *eps; /* epsilon error tolerance */ - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_AEXSEC_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_AEXSEC_1); + } + eps = vals[1]->v_num; + } - /* - * compute inverse exterior trigonometric secant to a given error tolerance - */ - if (vals[0]->v_type == V_NUM) { + /* + * compute inverse exterior trigonometric secant to a given error tolerance + */ + if (vals[0]->v_type == V_NUM) { - /* firewall */ - if (qisnegone(vals[0]->v_num)) { - return error_value(E_AEXSEC_3); - } + /* firewall */ + if (qisnegone(vals[0]->v_num)) { + return error_value(E_AEXSEC_3); + } - /* try to compute result using real trig function */ - result.v_num = qaexsec_or_NULL(vals[0]->v_num, eps); + /* try to compute result using real trig function */ + result.v_num = qaexsec_or_NULL(vals[0]->v_num, eps); - /* - * case: trig function returned a NUMBER - */ - if (result.v_num != NULL) { - result.v_type = V_NUM; + /* + * case: trig function returned a NUMBER + */ + if (result.v_num != NULL) { + result.v_type = V_NUM; - /* - * case: trig function returned NULL - need to try COMPLEX trig function - */ - } else { - /* convert NUMBER argument from NUMBER to COMPLEX */ - vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); - vals[0]->v_type = V_COM; - } - } - if (vals[0]->v_type == V_COM) { + /* + * case: trig function returned NULL - need to try COMPLEX trig function + */ + } else { + /* convert NUMBER argument from NUMBER to COMPLEX */ + vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); + vals[0]->v_type = V_COM; + } + } + if (vals[0]->v_type == V_COM) { - /* - * case: argument was COMPLEX or - * trig function returned NULL and argument was converted to COMPLEX - */ - c = c_aexsec(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_AEXSEC_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * case: argument was COMPLEX or + * trig function returned NULL and argument was converted to COMPLEX + */ + c = c_aexsec(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_AEXSEC_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - } - if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + } + if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { - /* - * case: argument type is not valid for this function - */ - return error_value(E_AEXSEC_2); - } - return result; + /* + * case: argument type is not valid for this function + */ + return error_value(E_AEXSEC_2); + } + return result; } @@ -12140,56 +12140,56 @@ f_aexsec(int count, VALUE **vals) S_FUNC VALUE f_excsc(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *err; + VALUE result; + COMPLEX *c; + NUMBER *err; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use err VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_EXCSC_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use err VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_EXCSC_1); + } + err = vals[1]->v_num; + } - /* - * compute exterior trigonometric cosecant to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - if (qiszero(vals[0]->v_num)) { - return error_value(E_EXCSC_3); - } - result.v_num = qexcsc(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - if (ciszero(vals[0]->v_com)) { - return error_value(E_EXCSC_3); - } - c = c_excsc(vals[0]->v_com, err); - if (c == NULL) { - return error_value(E_EXCSC_4); - } - result.v_com = c; - result.v_type = V_COM; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_EXCSC_2); - } - return result; + /* + * compute exterior trigonometric cosecant to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + if (qiszero(vals[0]->v_num)) { + return error_value(E_EXCSC_3); + } + result.v_num = qexcsc(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + if (ciszero(vals[0]->v_com)) { + return error_value(E_EXCSC_3); + } + c = c_excsc(vals[0]->v_com, err); + if (c == NULL) { + return error_value(E_EXCSC_4); + } + result.v_com = c; + result.v_type = V_COM; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_EXCSC_2); + } + return result; } @@ -12199,83 +12199,83 @@ f_excsc(int count, VALUE **vals) S_FUNC VALUE f_aexcsc(int count, VALUE **vals) { - VALUE result; /* value to return */ - COMPLEX *c; /* COMPLEX trig result */ - NUMBER *eps; /* epsilon error tolerance */ + VALUE result; /* value to return */ + COMPLEX *c; /* COMPLEX trig result */ + NUMBER *eps; /* epsilon error tolerance */ - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_AEXCSC_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_AEXCSC_1); + } + eps = vals[1]->v_num; + } - /* - * compute inverse exterior trigonometric cosecant to a given error tolerance - */ - if (vals[0]->v_type == V_NUM) { + /* + * compute inverse exterior trigonometric cosecant to a given error tolerance + */ + if (vals[0]->v_type == V_NUM) { - /* firewall */ - if (qisnegone(vals[0]->v_num)) { - return error_value(E_AEXCSC_3); - } + /* firewall */ + if (qisnegone(vals[0]->v_num)) { + return error_value(E_AEXCSC_3); + } - /* try to compute result using real trig function */ - result.v_num = qaexcsc_or_NULL(vals[0]->v_num, eps); + /* try to compute result using real trig function */ + result.v_num = qaexcsc_or_NULL(vals[0]->v_num, eps); - /* - * case: trig function returned a NUMBER - */ - if (result.v_num != NULL) { - result.v_type = V_NUM; + /* + * case: trig function returned a NUMBER + */ + if (result.v_num != NULL) { + result.v_type = V_NUM; - /* - * case: trig function returned NULL - need to try COMPLEX trig function - */ - } else { - /* convert NUMBER argument from NUMBER to COMPLEX */ - vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); - vals[0]->v_type = V_COM; - } - } - if (vals[0]->v_type == V_COM) { + /* + * case: trig function returned NULL - need to try COMPLEX trig function + */ + } else { + /* convert NUMBER argument from NUMBER to COMPLEX */ + vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); + vals[0]->v_type = V_COM; + } + } + if (vals[0]->v_type == V_COM) { - /* - * case: argument was COMPLEX or - * trig function returned NULL and argument was converted to COMPLEX - */ - c = c_aexcsc(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_AEXCSC_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * case: argument was COMPLEX or + * trig function returned NULL and argument was converted to COMPLEX + */ + c = c_aexcsc(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_AEXCSC_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - } - if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + } + if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { - /* - * case: argument type is not valid for this function - */ - return error_value(E_AEXCSC_2); - } - return result; + /* + * case: argument type is not valid for this function + */ + return error_value(E_AEXCSC_2); + } + return result; } @@ -12285,50 +12285,50 @@ f_aexcsc(int count, VALUE **vals) S_FUNC VALUE f_crd(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *err; + VALUE result; + COMPLEX *c; + NUMBER *err; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use err VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_CRD_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use err VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_CRD_1); + } + err = vals[1]->v_num; + } - /* - * compute chord of a unit circle to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qcrd(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - c = c_crd(vals[0]->v_com, err); - if (c == NULL) { - return error_value(E_CRD_3); - } - result.v_com = c; - result.v_type = V_COM; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_CRD_2); - } - return result; + /* + * compute chord of a unit circle to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qcrd(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + c = c_crd(vals[0]->v_com, err); + if (c == NULL) { + return error_value(E_CRD_3); + } + result.v_com = c; + result.v_type = V_COM; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_CRD_2); + } + return result; } @@ -12338,78 +12338,78 @@ f_crd(int count, VALUE **vals) S_FUNC VALUE f_acrd(int count, VALUE **vals) { - VALUE result; /* value to return */ - COMPLEX *c; /* COMPLEX trig result */ - NUMBER *eps; /* epsilon error tolerance */ + VALUE result; /* value to return */ + COMPLEX *c; /* COMPLEX trig result */ + NUMBER *eps; /* epsilon error tolerance */ - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_ACRD_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_ACRD_1); + } + eps = vals[1]->v_num; + } - /* - * compute inverse trigonometric chord of a unit circle to a given error tolerance - */ - if (vals[0]->v_type == V_NUM) { + /* + * compute inverse trigonometric chord of a unit circle to a given error tolerance + */ + if (vals[0]->v_type == V_NUM) { - /* try to compute result using real trig function */ - result.v_num = qacrd_or_NULL(vals[0]->v_num, eps); + /* try to compute result using real trig function */ + result.v_num = qacrd_or_NULL(vals[0]->v_num, eps); - /* - * case: trig function returned a NUMBER - */ - if (result.v_num != NULL) { - result.v_type = V_NUM; + /* + * case: trig function returned a NUMBER + */ + if (result.v_num != NULL) { + result.v_type = V_NUM; - /* - * case: trig function returned NULL - need to try COMPLEX trig function - */ - } else { - /* convert NUMBER argument from NUMBER to COMPLEX */ - vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); - vals[0]->v_type = V_COM; - } - } - if (vals[0]->v_type == V_COM) { + /* + * case: trig function returned NULL - need to try COMPLEX trig function + */ + } else { + /* convert NUMBER argument from NUMBER to COMPLEX */ + vals[0]->v_com = qqtoc(vals[0]->v_num, &_qzero_); + vals[0]->v_type = V_COM; + } + } + if (vals[0]->v_type == V_COM) { - /* - * case: argument was COMPLEX or - * trig function returned NULL and argument was converted to COMPLEX - */ - c = c_acrd(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_ACRD_3); - } - result.v_com = c; - result.v_type = V_COM; + /* + * case: argument was COMPLEX or + * trig function returned NULL and argument was converted to COMPLEX + */ + c = c_acrd(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_ACRD_3); + } + result.v_com = c; + result.v_type = V_COM; - /* - * case: complex trig function returned real, convert result to NUMBER - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - } - if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { + /* + * case: complex trig function returned real, convert result to NUMBER + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + } + if (vals[0]->v_type != V_NUM && vals[0]->v_type != V_COM) { - /* - * case: argument type is not valid for this function - */ - return error_value(E_ACRD_2); - } - return result; + /* + * case: argument type is not valid for this function + */ + return error_value(E_ACRD_2); + } + return result; } @@ -12419,50 +12419,50 @@ f_acrd(int count, VALUE **vals) S_FUNC VALUE f_cas(int count, VALUE **vals) { - VALUE result; - COMPLEX *c; - NUMBER *err; + VALUE result; + COMPLEX *c; + NUMBER *err; - /* initialize VALUEs */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use err VALUE arg if given and value is in a valid range. - */ - err = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_CAS_1); - } - err = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use err VALUE arg if given and value is in a valid range. + */ + err = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_CAS_1); + } + err = vals[1]->v_num; + } - /* - * compute chord of a unit circle to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - result.v_num = qcas(vals[0]->v_num, err); - result.v_type = V_NUM; - break; - case V_COM: - c = c_cas(vals[0]->v_com, err); - if (c == NULL) { - return error_value(E_CAS_3); - } - result.v_com = c; - result.v_type = V_COM; - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - } - break; - default: - return error_value(E_CAS_2); - } - return result; + /* + * compute chord of a unit circle to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + result.v_num = qcas(vals[0]->v_num, err); + result.v_type = V_NUM; + break; + case V_COM: + c = c_cas(vals[0]->v_com, err); + if (c == NULL) { + return error_value(E_CAS_3); + } + result.v_com = c; + result.v_type = V_COM; + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + } + break; + default: + return error_value(E_CAS_2); + } + return result; } @@ -12472,75 +12472,75 @@ f_cas(int count, VALUE **vals) S_FUNC VALUE f_cis(int count, VALUE **vals) { - VALUE result; - NUMBER *eps; - COMPLEX *c; - COMPLEX *ctmp; + VALUE result; + NUMBER *eps; + COMPLEX *c; + COMPLEX *ctmp; - /* initialize VALUE */ - result.v_subtype = V_NOSUBTYPE; + /* initialize VALUE */ + result.v_subtype = V_NOSUBTYPE; - /* - * set error tolerance for builtin function - * - * Use eps VALUE arg if given and value is in a valid range. - */ - eps = conf->epsilon; - if (count == 2) { - if (verify_eps(vals[1]) == false) { - return error_value(E_CIS_1); - } - eps = vals[1]->v_num; - } + /* + * set error tolerance for builtin function + * + * Use eps VALUE arg if given and value is in a valid range. + */ + eps = conf->epsilon; + if (count == 2) { + if (verify_eps(vals[1]) == false) { + return error_value(E_CIS_1); + } + eps = vals[1]->v_num; + } - /* - * compute Euler's formula to a given error tolerance - */ - switch (vals[0]->v_type) { - case V_NUM: - /* - * convert arg to COMPLEX - */ - ctmp = q_to_c(vals[0]->v_num); + /* + * compute Euler's formula to a given error tolerance + */ + switch (vals[0]->v_type) { + case V_NUM: + /* + * convert arg to COMPLEX + */ + ctmp = q_to_c(vals[0]->v_num); - /* - * compute cis of argument - */ - c = c_cis(ctmp, eps); - comfree(ctmp); - if (c == NULL) { - return error_value(E_CIS_3); - } - break; - case V_COM: + /* + * compute cis of argument + */ + c = c_cis(ctmp, eps); + comfree(ctmp); + if (c == NULL) { + return error_value(E_CIS_3); + } + break; + case V_COM: - /* - * compute cis of argument - */ - c = c_cis(vals[0]->v_com, eps); - if (c == NULL) { - return error_value(E_CIS_3); - } - break; - default: - return error_value(E_CIS_2); - } + /* + * compute cis of argument + */ + c = c_cis(vals[0]->v_com, eps); + if (c == NULL) { + return error_value(E_CIS_3); + } + break; + default: + return error_value(E_CIS_2); + } - /* - * case: return NUMBER value - */ - if (cisreal(c)) { - result.v_num = c_to_q(c, true); - result.v_type = V_NUM; - return result; - } + /* + * case: return NUMBER value + */ + if (cisreal(c)) { + result.v_num = c_to_q(c, true); + result.v_type = V_NUM; + return result; + } - /* - * case: return COMPLEX value - */ - result.v_com = c; - result.v_type = V_COM; - return result; + /* + * case: return COMPLEX value + */ + result.v_com = c; + result.v_type = V_COM; + return result; } @@ -12551,757 +12551,757 @@ f_cis(int count, VALUE **vals) * builtins - List of primitive built-in functions * * NOTE: This table is also used by the help/Makefile builtin rule to - * form the builtin help file. This rule will cause a sed script - * to strip this table down into a just the information needed - * to print builtin function list: b_name, b_minargs, b_maxargs - * and b_desc. All other struct elements will be converted to 0. - * The sed script expects to find entries of the form: + * form the builtin help file. This rule will cause a sed script + * to strip this table down into a just the information needed + * to print builtin function list: b_name, b_minargs, b_maxargs + * and b_desc. All other struct elements will be converted to 0. + * The sed script expects to find entries of the form: * - * {"...", number, number, stuff, stuff, stuff, stuff, - * "...."}, + * {"...", number, number, stuff, stuff, stuff, stuff, + * "...."}, * - * please keep this table in that form. + * please keep this table in that form. * - * For nice output, when the description of function (b_desc) - * gets too long (extends into col 79) you should chop the - * line and add "\n\t\t\t", that's newline and 3 tabs. - * For example the description: + * For nice output, when the description of function (b_desc) + * gets too long (extends into col 79) you should chop the + * line and add "\n\t\t\t", that's newline and 3 tabs. + * For example the description: * - * ... very long description that goes beyond col 79 + * ... very long description that goes beyond col 79 * - * should be written as: + * should be written as: * - * "... very long description that\n\t\t\tgoes beyond col 79"}, + * "... very long description that\n\t\t\tgoes beyond col 79"}, * * fields: - * b_name name of built-in function - * b_minargs minimum number of arguments - * b_maxargs maximum number of arguments - * b_flags special handling flags - * b_opcode opcode which makes the call quick - * b_numfunc routine to calculate numeric function - * b_valfunc routine to calculate general values - * b_desc description of function + * b_name name of built-in function + * b_minargs minimum number of arguments + * b_maxargs maximum number of arguments + * b_flags special handling flags + * b_opcode opcode which makes the call quick + * b_numfunc routine to calculate numeric function + * b_valfunc routine to calculate general values + * b_desc description of function */ STATIC CONST struct builtin builtins[] = { - {"abs", 1, 2, 0, OP_ABS, {.null = NULL}, {.null = NULL}, - "absolute value, within accuracy b"}, - {"access", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_access}, - "determine accessibility of file a for mode b"}, - {"acos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acos}, - "inverse cosine of a, within accuracy b"}, - {"acosh", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acosh}, - "inverse hyperbolic cosine of a, within accuracy b"}, - {"acot", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acot}, - "inverse cotangent of a, within accuracy b"}, - {"acoth", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acoth}, - "inverse hyperbolic cotangent of a, within accuracy b"}, - {"acovercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acovercos}, - "inverse coversed cosine of a, within accuracy b"}, - {"acoversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acoversin}, - "inverse coversed sine of a, within accuracy b"}, - {"acrd", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acrd}, - "angle of unit circle chord with length a, within accuracy b"}, - {"acsc", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acsc}, - "inverse cosecant of a, within accuracy b"}, - {"acsch", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acsch}, - "inverse csch of a, within accuracy b"}, - {"aexcsc", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_aexcsc}, - "inverse exterior cosecant of a, within accuracy b"}, - {"aexsec", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_aexsec}, - "inverse exterior secant of a, within accuracy b"}, - {"agd", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_agd}, - "inverse Gudermannian function"}, - {"ahacovercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_ahacovercos}, - "inverse half coversed cosine of a, within accuracy b"}, - {"ahacoversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_ahacoversin}, - "inverse half coversed sine of a, within accuracy b"}, - {"ahavercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_ahavercos}, - "inverse half versed cosine of a, within accuracy b"}, - {"ahaversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_ahaversin}, - "inverse half versed sine of a, within accuracy b"}, - {"append", 1, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_listappend}, - "append values to end of list"}, - {"appr", 1, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_appr}, - "approximate a by multiple of b using rounding c"}, - {"arg", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_arg}, - "argument (the angle) of complex number"}, - {"argv", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_argv}, - "calc argc or argv string"}, - {"asec", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_asec}, - "inverse secant of a, within accuracy b"}, - {"asech", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_asech}, - "inverse hyperbolic secant of a, within accuracy b"}, - {"asin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_asin}, - "inverse sine of a, within accuracy b"}, - {"asinh", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_asinh}, - "inverse hyperbolic sine of a, within accuracy b"}, - {"assoc", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_assoc}, - "create new association array"}, - {"atan", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_atan}, - "inverse tangent of a, within accuracy b"}, - {"atan2", 2, 3, FE, OP_NOP, {.numfunc_3 = qatan2}, {.null = NULL}, - "angle to point (b,a) within accuracy c"}, - {"atanh", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_atanh}, - "inverse hyperbolic tangent of a, within accuracy b"}, - {"avercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_avercos}, - "inverse versed cosine of a, within accuracy b"}, - {"aversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_aversin}, - "inverse versed sine of a, within accuracy b"}, - {"avg", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_avg}, - "arithmetic mean of values"}, - {"base", 0, 1, 0, OP_NOP, {.numfunc_cnt = f_base}, {.null = NULL}, - "set default output base"}, - {"base2", 0, 1, 0, OP_NOP, {.numfunc_cnt = f_base2}, {.null = NULL}, - "set default secondary output base"}, - {"bernoulli", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_bern}, - "Bernoulli number for index a"}, - {"bit", 2, 2, 0, OP_BIT, {.null = NULL}, {.null = NULL}, - "whether bit b in value a is set"}, - {"blk", 0, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_blk}, - "block with or without name, octet number, chunksize"}, - {"blkcpy", 2, 5, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_blkcpy}, - "copy value to/from a block: blkcpy(d,s,len,di,si)"}, - {"blkfree", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_blkfree}, - "free all storage from a named block"}, - {"blocks", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_blocks}, - "named block with specified index, or null value"}, - {"bround", 1, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_bround}, - "round value a to b number of binary places"}, - {"btrunc", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_btrunc}, {.null = NULL}, - "truncate a to b number of binary places"}, - {"calclevel", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_calclevel}, - "current calculation level"}, - {"calcpath", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_calcpath}, - "current CALCPATH search path value"}, - {"calc_tty", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_calc_tty}, - "set tty for interactivity"}, - {"cas", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_cas}, - "cosine plus sine, within accuracy b"}, - {"catalan", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_catalan}, - "catalan number for index a"}, - {"ceil", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ceil}, - "smallest integer greater than or equal to number"}, - {"cfappr", 1, 3, 0, OP_NOP, {.numfunc_cnt = f_cfappr}, {.null = NULL}, - "approximate a, within accuracy b using\n" - "\t\t\tcontinued fractions"}, - {"cfsim", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_cfsim}, {.null = NULL}, - "simplify number using continued fractions"}, - {"char", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_char}, - "character corresponding to integer value"}, - {"cis", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_cis}, - "Euler's formula, within accuracy b"}, - {"cmdbuf", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_cmdbuf}, - "command buffer"}, - {"cmp", 2, 2, 0, OP_CMP, {.null = NULL}, {.null = NULL}, - "compare values returning -1, 0, or 1"}, - {"comb", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_comb}, - "combinatorial number a!/b!(a-b)!"}, - {"config", 1, 2, 0, OP_SETCONFIG, {.null = NULL}, {.null = NULL}, - "set or read configuration value"}, - {"conj", 1, 1, 0, OP_CONJUGATE, {.null = NULL}, {.null = NULL}, - "complex conjugate of value"}, - {"copy", 2, 5, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_copy}, - "copy value to/from a block: copy(s,d,len,si,di)"}, - {"cos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_cos}, - "cosine of value a, within accuracy b"}, - {"cosh", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_cosh}, - "hyperbolic cosine of a, within accuracy b"}, - {"cot", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_cot}, - "cotangent of a, within accuracy b"}, - {"coth", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_coth}, - "hyperbolic cotangent of a, within accuracy b"}, - {"count", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_count}, - "count listr/matrix elements satisfying some condition"}, - {"covercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_covercos}, - "coversed cosine of value a, within accuracy b"}, - {"coversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_coversin}, - "coversed sine of value a, within accuracy b"}, - {"cp", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_cp}, - "cross product of two vectors"}, - {"crd", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_crd}, - "length of unit circle chord with angle a, within accuracy b"}, - {"csc", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_csc}, - "cosecant of a, within accuracy b"}, - {"csch", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_csch}, - "hyperbolic cosecant of a, within accuracy b"}, - {"ctime", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_ctime}, - "date and time as string"}, - {"custom", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_custom}, - "custom builtin function interface"}, - {"d2dm", 3, 4, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_d2dm}, - "convert a to b deg, c min, rounding type d\n"}, - {"d2dms", 4, 5, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_d2dms}, - "convert a to b deg, c min, d sec, rounding type e\n"}, - {"d2g", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_d2g}, - "convert degrees to gradians"}, - {"d2r", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_d2r}, - "convert degrees to radians"}, - {"delete", 2, 2, FA, OP_NOP, {.null = NULL}, {.valfunc_2 = f_listdelete}, - "delete element from list a at position b"}, - {"den", 1, 1, 0, OP_DENOMINATOR, {.numfunc_1 = qden}, {.null = NULL}, - "denominator of fraction"}, - {"det", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_det}, - "determinant of matrix"}, - {"digit", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_digit}, - "digit at specified decimal place of number"}, - {"digits", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_digits}, - "number of digits in base b representation of a"}, - {"display", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_display}, - "number of decimal digits for displaying numbers"}, - {"dm2d", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_dm2d}, - "convert a deg, b min to degrees, rounding type c\n"}, - {"dms2d", 3, 4, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_dms2d}, - "convert a deg, b min, c sec to degrees, rounding type d\n"}, - {"dp", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_dp}, - "dot product of two vectors"}, - {"epsilon", 0, 1, 0, OP_SETEPSILON, {.null = NULL}, {.null = NULL}, - "set or read allowed error for real calculations"}, - {"errcount", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_errcount}, - "set or read error count"}, - {"errmax", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_errmax}, - "set or read maximum for error count"}, - {"errno", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_errno}, - "set or read calc_errno"}, - {"error", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_error}, - "generate error value"}, - {"errsym", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_errsym}, - "convert between E_STRING errsym into a errnum number"}, - {"estr", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_estr}, - "exact text string representation of value"}, - {"euler", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_euler}, - "Euler number"}, - {"eval", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_eval}, - "evaluate expression from string to value"}, - {"excsc", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_excsc}, - "exterior cosecant of a, within accuracy b"}, - {"exp", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_exp}, - "exponential of value a, within accuracy b"}, - {"exsec", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_exsec}, - "exterior secant of a, within accuracy b"}, - {"fact", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fact}, - "factorial"}, - {"factor", 1, 3, 0, OP_NOP, {.numfunc_cnt = f_factor}, {.null = NULL}, - "lowest prime factor < b of a, return c if error"}, - {"fclose", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fclose}, - "close file"}, - {"fcnt", 2, 2, 0, OP_NOP, {.numfunc_2 = f_faccnt}, {.null = NULL}, - "count of times one number divides another"}, - {"feof", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_feof}, - "whether EOF reached for file"}, - {"ferror", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ferror}, - "whether error occurred for file"}, - {"fflush", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fflush}, - "flush output to file(s)"}, - {"fgetc", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fgetc}, - "read next char from file"}, - {"fgetfield", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fgetfield}, - "read next white-space delimited field from file"}, - {"fgetfile", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fgetfile}, - "read to end of file"}, - {"fgetline", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fgetline}, - "read next line from file, newline removed"}, - {"fgets", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fgets}, - "read next line from file, newline is kept"}, - {"fgetstr", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fgetstr}, - "read next null-terminated string from file, null\n" - "\t\t\tcharacter is kept"}, - {"fib", 1, 1, 0, OP_NOP, {.numfunc_1 = qfib}, {.null = NULL}, - "Fibonacci number F(n)"}, - {"files", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_files}, - "return opened file or max number of opened files"}, - {"floor", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_floor}, - "greatest integer less than or equal to number"}, - {"fopen", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_fopen}, - "open file name a in mode b"}, - {"forall", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_forall}, - "do function for all elements of list or matrix"}, - {"fpathopen", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fpathopen}, - "open file name a in mode b, search for a along\n" - "\t\t\tCALCPATH or path c"}, - {"fprintf", 2, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fprintf}, - "print formatted output to opened file"}, - {"fputc", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_fputc}, - "write a character to a file"}, - {"fputs", 2, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fputs}, - "write one or more strings to a file"}, - {"fputstr", 2, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fputstr}, - "write one or more null-terminated strings to a file"}, - {"frac", 1, 1, 0, OP_FRAC, {.numfunc_1 = qfrac}, {.null = NULL}, - "fractional part of value"}, - {"free", 0, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_free}, - "free listed or all global variables"}, - {"freebernoulli", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_freebern}, - "free stored Bernoulli numbers"}, - {"freeeuler", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_freeeuler}, - "free stored Euler numbers"}, - {"freeglobals", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_freeglobals}, - "free all global and visible static variables"}, - {"freeredc", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_freeredc}, - "free redc data cache"}, - {"freestatics", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_freestatics}, - "free all un-scoped static variables"}, - {"frem", 2, 2, 0, OP_NOP, {.numfunc_2 = qfacrem}, {.null = NULL}, - "number with all occurrences of factor removed"}, - {"freopen", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_freopen}, - "reopen a file stream to a named file"}, - {"fscan", 2, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fscan}, - "scan a file for assignments to one or\n" - "\t\t\tmore variables"}, - {"fscanf", 2, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fscanf}, - "formatted scan of a file for assignment to one\n" - "\t\t\tor more variables"}, - {"fseek", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fseek}, - "seek to position b (offset from c) in file a"}, - {"fsize", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fsize}, - "return the size of the file"}, - {"ftell", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ftell}, - "return the file position"}, - {"g2d", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_g2d}, - "convert gradians to degrees"}, - {"g2gm", 3, 4, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_g2gm}, - "convert a to b grads, c min, rounding type d\n"}, - {"g2gms", 4, 5, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_g2gms}, - "convert a to b grads, c min, d sec, rounding type e\n"}, - {"g2r", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_g2r}, - "convert gradians to radians"}, - {"gcd", 1, IN, 0, OP_NOP, {.numfunc_cnt = f_gcd}, {.null = NULL}, - "greatest common divisor"}, - {"gcdrem", 2, 2, 0, OP_NOP, {.numfunc_2 = qgcdrem}, {.null = NULL}, - "a divided repeatedly by gcd with b"}, - {"gd", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_gd}, - "Gudermannian function"}, - {"getenv", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_getenv}, - "value of environment variable (or NULL)"}, - {"gm2g", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_gm2g}, - "convert a grads, b min to grads, rounding type c\n"}, - {"gms2g", 3, 4, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_gms2g}, - "convert a grads, b min, c sec to grads, rounding type d\n"}, - {"h2hm", 3, 4, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_h2hm}, - "convert a to b hours, c min, rounding type d\n"}, - {"h2hms", 4, 5, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_h2hms}, - "convert a to b hours, c min, d sec, rounding type e\n"}, - {"hacovercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_hacovercos}, - "half coversed cosine of value a, within accuracy b"}, - {"hacoversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_hacoversin}, - "half coversed sine of value a, within accuracy b"}, - {"hash", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_hash}, - "return non-negative hash value for one or\n" - "\t\t\tmore values"}, - {"havercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_havercos}, - "half versed cosine of value a, within accuracy b"}, - {"haversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_haversin}, - "half versed sine of value a, within accuracy b"}, - {"head", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_head}, - "return list of specified number at head of a list"}, - {"highbit", 1, 1, 0, OP_HIGHBIT, {.null = NULL}, {.null = NULL}, - "high bit number in base 2 representation"}, - {"hm2h", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_hm2h}, - "convert a hours, b min to hours, rounding type c\n"}, - {"hmean", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_hmean}, - "harmonic mean of values"}, - {"hms2h", 3, 4, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_hms2h}, - "convert a hours, b min, c sec to hours, rounding type d\n"}, - {"hnrmod", 4, 4, 0, OP_NOP, {.numfunc_4 = f_hnrmod}, {.null = NULL}, - "v mod h*2^n+r, h>0, n>0, r = -1, 0 or 1"}, - {"hypot", 2, 3, FE, OP_NOP, {.numfunc_3 = qhypot}, {.null = NULL}, - "hypotenuse of right triangle, within accuracy c"}, - {"ilog", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_ilog}, - "integral log of a to integral base b"}, - {"ilog10", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ilog10}, - "integral log of a number base 10"}, - {"ilog2", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ilog2}, - "integral log of a number base 2"}, - {"ilogn", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_ilog}, - "same is ilog"}, - {"im", 1, 1, 0, OP_IM, {.null = NULL}, {.null = NULL}, - "imaginary part of complex number"}, - {"indices", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_indices}, - "indices of a specified assoc or mat value"}, - {"inputlevel", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_inputlevel}, - "current input depth"}, - {"insert", 2, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_listinsert}, - "insert values c ... into list a at position b"}, - {"int", 1, 1, 0, OP_INT, {.numfunc_1 = qint}, {.null = NULL}, - "integer part of value"}, - {"inverse", 1, 1, 0, OP_INVERT, {.null = NULL}, {.null = NULL}, - "multiplicative inverse of value"}, - {"iroot", 2, 2, 0, OP_NOP, {.numfunc_2 = qiroot}, {.null = NULL}, - "integer b'th root of a"}, - {"isalnum", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isalnum}, - "whether character is alpha-numeric"}, - {"isalpha", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isalpha}, - "whether character is alphabetic"}, - {"isassoc", 1, 1, 0, OP_ISASSOC, {.null = NULL}, {.null = NULL}, - "whether a value is an association"}, - {"isatty", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isatty}, - "whether a file is a tty"}, - {"isblk", 1, 1, 0, OP_ISBLK, {.null = NULL}, {.null = NULL}, - "whether a value is a block"}, - {"iscntrl", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_iscntrl}, - "whether character is a control character"}, - {"isconfig", 1, 1, 0, OP_ISCONFIG, {.null = NULL}, {.null = NULL}, - "whether a value is a config state"}, - {"isdefined", 1, 1, 0, OP_ISDEFINED, {.null = NULL}, {.null = NULL}, - "whether a string names a function"}, - {"isdigit", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isdigit}, - "whether character is a digit"}, - {"iserror", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_iserror}, - "where a value is an error"}, - {"iseven", 1, 1, 0, OP_ISEVEN, {.null = NULL}, {.null = NULL}, - "whether a value is an even integer"}, - {"isfile", 1, 1, 0, OP_ISFILE, {.null = NULL}, {.null = NULL}, - "whether a value is a file"}, - {"isgraph", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isgraph}, - "whether character is a graphical character"}, - {"ishash", 1, 1, 0, OP_ISHASH, {.null = NULL}, {.null = NULL}, - "whether a value is a hash state"}, - {"isident", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isident}, - "returns 1 if identity matrix"}, - {"isint", 1, 1, 0, OP_ISINT, {.null = NULL}, {.null = NULL}, - "whether a value is an integer"}, - {"islist", 1, 1, 0, OP_ISLIST, {.null = NULL}, {.null = NULL}, - "whether a value is a list"}, - {"islower", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_islower}, - "whether character is lower case"}, - {"ismat", 1, 1, 0, OP_ISMAT, {.null = NULL}, {.null = NULL}, - "whether a value is a matrix"}, - {"ismult", 2, 2, 0, OP_NOP, {.numfunc_2 = f_ismult}, {.null = NULL}, - "whether a is a multiple of b"}, - {"isnull", 1, 1, 0, OP_ISNULL, {.null = NULL}, {.null = NULL}, - "whether a value is the null value"}, - {"isnum", 1, 1, 0, OP_ISNUM, {.null = NULL}, {.null = NULL}, - "whether a value is a number"}, - {"isobj", 1, 1, 0, OP_ISOBJ, {.null = NULL}, {.null = NULL}, - "whether a value is an object"}, - {"isobjtype", 1, 1, 0, OP_ISOBJTYPE, {.null = NULL}, {.null = NULL}, - "whether a string names an object type"}, - {"isoctet", 1, 1, 0, OP_ISOCTET, {.null = NULL}, {.null = NULL}, - "whether a value is an octet"}, - {"isodd", 1, 1, 0, OP_ISODD, {.null = NULL}, {.null = NULL}, - "whether a value is an odd integer"}, - {"isprime", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_isprime}, {.null = NULL}, - "whether a is a small prime, return b if error"}, - {"isprint", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isprint}, - "whether character is printable"}, - {"isptr", 1, 1, 0, OP_ISPTR, {.null = NULL}, {.null = NULL}, - "whether a value is a pointer"}, - {"ispunct", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ispunct}, - "whether character is a punctuation"}, - {"isqrt", 1, 1, 0, OP_NOP, {.numfunc_1 = qisqrt}, {.null = NULL}, - "integer part of square root"}, - {"isrand", 1, 1, 0, OP_ISRAND, {.null = NULL}, {.null = NULL}, - "whether a value is a subtractive 100 state"}, - {"israndom", 1, 1, 0, OP_ISRANDOM, {.null = NULL}, {.null = NULL}, - "whether a value is a Blum state"}, - {"isreal", 1, 1, 0, OP_ISREAL, {.null = NULL}, {.null = NULL}, - "whether a value is a real number"}, - {"isrel", 2, 2, 0, OP_NOP, {.numfunc_2 = f_isrel}, {.null = NULL}, - "whether two numbers are relatively prime"}, - {"issimple", 1, 1, 0, OP_ISSIMPLE, {.null = NULL}, {.null = NULL}, - "whether value is a simple type"}, - {"isspace", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isspace}, - "whether character is a space character"}, - {"issq", 1, 1, 0, OP_NOP, {.numfunc_1 = f_issquare}, {.null = NULL}, - "whether or not number is a square"}, - {"isstr", 1, 1, 0, OP_ISSTR, {.null = NULL}, {.null = NULL}, - "whether a value is a string"}, - {"istype", 2, 2, 0, OP_ISTYPE, {.null = NULL}, {.null = NULL}, - "whether the type of a is same as the type of b"}, - {"isupper", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isupper}, - "whether character is upper case"}, - {"isxdigit", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isxdigit}, - "whether character is a hexadecimal digit"}, - {"jacobi", 2, 2, 0, OP_NOP, {.numfunc_2 = qjacobi}, {.null = NULL}, - "-1 = > a is not quadratic residue mod b\n" - "\t\t\t1 = > b is composite, or a is quad residue of b"}, - {"join", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_join}, - "join one or more lists into one list"}, - {"lcm", 1, IN, 0, OP_NOP, {.numfunc_cnt = f_lcm}, {.null = NULL}, - "least common multiple"}, - {"lcmfact", 1, 1, 0, OP_NOP, {.numfunc_1 = qlcmfact}, {.null = NULL}, - "lcm of all integers up till number"}, - {"lfactor", 2, 2, 0, OP_NOP, {.numfunc_2 = qlowfactor}, {.null = NULL}, - "lowest prime factor of a in first b primes"}, - {"links", 1, 1, 0, OP_LINKS, {.null = NULL}, {.null = NULL}, - "links to number or string value"}, - {"list", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_list}, - "create list of specified values"}, - {"ln", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_ln}, - "natural logarithm of value a, within accuracy b"}, - {"log", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_log}, - "base 10 logarithm of value a, within accuracy b"}, - {"log2", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_log2}, - "base 2 logarithm of value a, within accuracy b"}, - {"logn", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_logn}, - "base b logarithm of value a, within accuracy c"}, - {"lowbit", 1, 1, 0, OP_LOWBIT, {.null = NULL}, {.null = NULL}, - "low bit number in base 2 representation"}, - {"ltol", 1, 2, FE, OP_NOP, {.numfunc_2 = f_legtoleg}, {.null = NULL}, - "leg-to-leg of unit right triangle (sqrt(1 - a^2))"}, - {"makelist", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_makelist}, - "create a list with a null elements"}, - {"matdim", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_matdim}, - "number of dimensions of matrix"}, - {"matfill", 2, 3, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_matfill}, - "fill matrix with value b (value c on diagonal)"}, - {"matmax", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_matmax}, - "maximum index of matrix a dim b"}, - {"matmin", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_matmin}, - "minimum index of matrix a dim b"}, - {"matsum", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_matsum}, - "sum the numeric values in a matrix"}, - {"mattrace", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_mattrace}, - "return the trace of a square matrix"}, - {"mattrans", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_mattrans}, - "transpose of matrix"}, - {"max", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_max}, - "maximum value"}, - {"memsize", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_memsize}, - "number of octets used by the value, including overhead"}, - {"meq", 3, 3, 0, OP_NOP, {.numfunc_3 = f_meq}, {.null = NULL}, - "whether a and b are equal modulo c"}, - {"min", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_min}, - "minimum value"}, - {"minv", 2, 2, 0, OP_NOP, {.numfunc_2 = qminv}, {.null = NULL}, - "inverse of a modulo b"}, - {"mmin", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_mmin}, - "a mod b value with smallest abs value"}, - {"mne", 3, 3, 0, OP_NOP, {.numfunc_3 = f_mne}, {.null = NULL}, - "whether a and b are not equal modulo c"}, - {"mod", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_mod}, - "residue of a modulo b, rounding type c"}, - {"modify", 2, 2, FA, OP_NOP, {.null = NULL}, {.valfunc_2 = f_modify}, - "modify elements of a list or matrix"}, - {"name", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_name}, - "name assigned to block or file"}, - {"near", 2, 3, 0, OP_NOP, {.numfunc_cnt = f_near}, {.null = NULL}, - "sign of (abs(a-b) - c)"}, - {"newerror", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_newerror}, - "create new error type with message a"}, - {"nextcand", 1, 5, 0, OP_NOP, {.numfunc_cnt = f_nextcand}, {.null = NULL}, - "smallest value = = d mod e > a, ptest(a,b,c) true"}, - {"nextprime", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_nprime}, {.null = NULL}, - "return next small prime, return b if err"}, - {"norm", 1, 1, 0, OP_NORM, {.null = NULL}, {.null = NULL}, - "norm of a value (square of absolute value)"}, - {"null", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_null}, - "null value"}, - {"num", 1, 1, 0, OP_NUMERATOR, {.numfunc_1 = qnum}, {.null = NULL}, - "numerator of fraction"}, - {"ord", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ord}, - "integer corresponding to character value"}, - {"param", 1, 1, 0, OP_ARGVALUE, {.null = NULL}, {.null = NULL}, - "value of parameter n (or parameter count if n\n" - "\t\t\tis zero)"}, - {"perm", 2, 2, 0, OP_NOP, {.numfunc_2 = qperm}, {.null = NULL}, - "permutation number a!/(a-b)!"}, - {"pfact", 1, 1, 0, OP_NOP, {.numfunc_1 = qpfact}, {.null = NULL}, - "product of primes up till number"}, - {"pi", 0, 1, FE, OP_NOP, {.numfunc_1 = qpi}, {.null = NULL}, - "value of pi, within accuracy a"}, - {"pix", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_pix}, {.null = NULL}, - "number of primes < = a < 2^32, return b if error"}, - {"places", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_places}, - "places after \"decimal\" point (-1 if infinite)"}, - {"pmod", 3, 3, 0, OP_NOP, {.numfunc_3 = qpowermod}, {.null = NULL}, - "mod of a power (a ^ b (mod c))"}, - {"polar", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_polar}, - "complex value of polar coordinate (a * exp(b*1i))"}, - {"poly", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_poly}, - "evaluates a polynomial given its coefficients\n" - "\t\t\tor coefficient-list"}, - {"pop", 1, 1, FA, OP_NOP, {.null = NULL}, {.valfunc_1 = f_listpop}, - "pop value from front of list"}, - {"popcnt", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_popcnt}, {.null = NULL}, - "number of bits in a that match b (or 1)"}, - {"power", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_power}, - "value a raised to the power b, within accuracy c"}, - {"prevcand", 1, 5, 0, OP_NOP, {.numfunc_cnt = f_prevcand}, {.null = NULL}, - "largest value = = d mod e < a, ptest(a,b,c) true"}, - {"prevprime", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_pprime}, {.null = NULL}, - "return previous small prime, return b if err"}, - {"printf", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_printf}, - "print formatted output to stdout"}, - {"prompt", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_prompt}, - "prompt for input line using value a"}, - {"protect", 1, 3, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_protect}, - "read or set protection level for variable"}, - {"ptest", 1, 3, 0, OP_NOP, {.numfunc_cnt = f_primetest}, {.null = NULL}, - "probabilistic primality test"}, - {"push", 1, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_listpush}, - "push values onto front of list"}, - {"putenv", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_putenv}, - "define an environment variable"}, - {"quo", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_quo}, - "integer quotient of a by b, rounding type c"}, - {"quomod", 4, 5, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_quomod}, - "set c and d to quotient and remainder of a\n" - "\t\t\tdivided by b"}, - {"r2d", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_r2d}, - "convert radians to degrees"}, - {"r2g", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_r2g}, - "convert radians to gradians"}, - {"rand", 0, 2, 0, OP_NOP, {.numfunc_cnt = f_rand}, {.null = NULL}, - "subtractive 100 random number [0,2^64), [0,a), or [a,b)"}, - {"randbit", 0, 1, 0, OP_NOP, {.numfunc_cnt = f_randbit}, {.null = NULL}, - "subtractive 100 random number [0,2^a)"}, - {"random", 0, 2, 0, OP_NOP, {.numfunc_cnt = f_random}, {.null = NULL}, - "Blum-Blum-Shub random number [0,2^64), [0,a), or [a,b)"}, - {"randombit", 0, 1, 0, OP_NOP, {.numfunc_cnt = f_randombit}, {.null = NULL}, - "Blum-Blum-Sub random number [0,2^a)"}, - {"randperm", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_randperm}, - "random permutation of a list or matrix"}, - {"rcin", 2, 2, 0, OP_NOP, {.numfunc_2 = qredcin}, {.null = NULL}, - "convert normal number a to REDC number mod b"}, - {"rcmul", 3, 3, 0, OP_NOP, {.numfunc_3 = qredcmul}, {.null = NULL}, - "multiply REDC numbers a and b mod c"}, - {"rcout", 2, 2, 0, OP_NOP, {.numfunc_2 = qredcout}, {.null = NULL}, - "convert REDC number a mod b to normal number"}, - {"rcpow", 3, 3, 0, OP_NOP, {.numfunc_3 = qredcpower}, {.null = NULL}, - "raise REDC number a to power b mod c"}, - {"rcsq", 2, 2, 0, OP_NOP, {.numfunc_2 = qredcsquare}, {.null = NULL}, - "square REDC number a mod b"}, - {"re", 1, 1, 0, OP_RE, {.null = NULL}, {.null = NULL}, - "real part of complex number"}, - {"remove", 1, 1, FA, OP_NOP, {.null = NULL}, {.valfunc_1 = f_listremove}, - "remove value from end of list"}, - {"reverse", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_reverse}, - "reverse a copy of a matrix or list"}, - {"rewind", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_rewind}, - "rewind file(s)"}, - {"rm", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_rm}, - "remove file(s), -f turns off no-such-file errors"}, - {"root", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_root}, - "value a taken to the b'th root, within accuracy c"}, - {"round", 1, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_round}, - "round value a to b number of decimal places"}, - {"rsearch", 2, 4, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_rsearch}, - "reverse search matrix or list for value b\n" - "\t\t\tstarting at index c"}, - {"runtime", 0, 0, 0, OP_NOP, {.numfunc_0 = f_runtime}, {.null = NULL}, - "user and kernel mode CPU time in seconds"}, - {"saveval", 1, 1, 0, OP_SAVEVAL, {.null = NULL}, {.null = NULL}, - "set flag for saving values"}, - {"scale", 2, 2, 0, OP_SCALE, {.null = NULL}, {.null = NULL}, - "scale value up or down by a power of two"}, - {"scan", 1, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_scan}, - "scan standard input for assignment to one\n" - "\t\t\tor more variables"}, - {"scanf", 2, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_scanf}, - "formatted scan of standard input for assignment\n" - "\t\t\tto variables"}, - {"search", 2, 4, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_search}, - "search matrix or list for value b starting\n" - "\t\t\tat index c"}, - {"sec", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sec}, - "secant of a, within accuracy b"}, - {"sech", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sech}, - "hyperbolic secant of a, within accuracy b"}, - {"seed", 0, 0, 0, OP_NOP, {.numfunc_0 = f_seed}, {.null = NULL}, - "return a 64 bit seed for a pseudo-random generator"}, - {"segment", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_segment}, - "specified segment of specified list"}, - {"select", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_select}, - "form sublist of selected elements from list"}, - {"setbit", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_setbit}, - "set specified bit in string"}, - {"sgn", 1, 1, 0, OP_SGN, {.numfunc_1 = qsign}, {.null = NULL}, - "sign of value (-1, 0, 1)"}, - {"sha1", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sha1}, - "Secure Hash Algorithm (SHS-1 FIPS Pub 180-1)"}, - {"sin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sin}, - "sine of value a, within accuracy b"}, - {"sinh", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sinh}, - "hyperbolic sine of a, within accuracy b"}, - {"size", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_size}, - "total number of elements in value"}, - {"sizeof", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_sizeof}, - "number of octets used to hold the value"}, - {"sleep", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sleep}, - "suspend operation for a seconds"}, - {"sort", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_sort}, - "sort a copy of a matrix or list"}, - {"sqrt", 1, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sqrt}, - "square root of value a, within accuracy b"}, - {"srand", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_srand}, - "seed the rand() function"}, - {"srandom", 0, 4, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_srandom}, - "seed the random() function"}, - {"ssq", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_ssq}, - "sum of squares of values"}, - {"stoponerror", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_stoponerror}, - "assign value to stoponerror flag"}, - {"str", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_str}, - "simple value converted to string"}, - {"strcasecmp", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_strcasecmp}, - "compare two strings case independent"}, - {"strcat", 1,IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_strcat}, - "concatenate strings together"}, - {"strcmp", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_strcmp}, - "compare two strings"}, - {"strcpy", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_strcpy}, - "copy string to string"}, - {"strerror", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_strerror}, - "string describing error type"}, - {"strlen", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_strlen}, - "length of string"}, - {"strncasecmp", 3, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_3 = f_strncasecmp}, - "compare strings a, b to c characters case independent"}, - {"strncmp", 3, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_3 = f_strncmp}, - "compare strings a, b to c characters"}, - {"strncpy", 3, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_3 = f_strncpy}, - "copy up to c characters from string to string"}, - {"strpos", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_strpos}, - "index of first occurrence of b in a"}, - {"strprintf", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_strprintf}, - "return formatted output as a string"}, - {"strscan", 2, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_strscan}, - "scan a string for assignments to one or more variables"}, - {"strscanf", 2, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_strscanf}, - "formatted scan of string for assignments to variables"}, + {"abs", 1, 2, 0, OP_ABS, {.null = NULL}, {.null = NULL}, + "absolute value, within accuracy b"}, + {"access", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_access}, + "determine accessibility of file a for mode b"}, + {"acos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acos}, + "inverse cosine of a, within accuracy b"}, + {"acosh", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acosh}, + "inverse hyperbolic cosine of a, within accuracy b"}, + {"acot", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acot}, + "inverse cotangent of a, within accuracy b"}, + {"acoth", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acoth}, + "inverse hyperbolic cotangent of a, within accuracy b"}, + {"acovercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acovercos}, + "inverse coversed cosine of a, within accuracy b"}, + {"acoversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acoversin}, + "inverse coversed sine of a, within accuracy b"}, + {"acrd", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acrd}, + "angle of unit circle chord with length a, within accuracy b"}, + {"acsc", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acsc}, + "inverse cosecant of a, within accuracy b"}, + {"acsch", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_acsch}, + "inverse csch of a, within accuracy b"}, + {"aexcsc", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_aexcsc}, + "inverse exterior cosecant of a, within accuracy b"}, + {"aexsec", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_aexsec}, + "inverse exterior secant of a, within accuracy b"}, + {"agd", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_agd}, + "inverse Gudermannian function"}, + {"ahacovercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_ahacovercos}, + "inverse half coversed cosine of a, within accuracy b"}, + {"ahacoversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_ahacoversin}, + "inverse half coversed sine of a, within accuracy b"}, + {"ahavercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_ahavercos}, + "inverse half versed cosine of a, within accuracy b"}, + {"ahaversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_ahaversin}, + "inverse half versed sine of a, within accuracy b"}, + {"append", 1, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_listappend}, + "append values to end of list"}, + {"appr", 1, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_appr}, + "approximate a by multiple of b using rounding c"}, + {"arg", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_arg}, + "argument (the angle) of complex number"}, + {"argv", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_argv}, + "calc argc or argv string"}, + {"asec", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_asec}, + "inverse secant of a, within accuracy b"}, + {"asech", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_asech}, + "inverse hyperbolic secant of a, within accuracy b"}, + {"asin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_asin}, + "inverse sine of a, within accuracy b"}, + {"asinh", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_asinh}, + "inverse hyperbolic sine of a, within accuracy b"}, + {"assoc", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_assoc}, + "create new association array"}, + {"atan", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_atan}, + "inverse tangent of a, within accuracy b"}, + {"atan2", 2, 3, FE, OP_NOP, {.numfunc_3 = qatan2}, {.null = NULL}, + "angle to point (b,a) within accuracy c"}, + {"atanh", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_atanh}, + "inverse hyperbolic tangent of a, within accuracy b"}, + {"avercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_avercos}, + "inverse versed cosine of a, within accuracy b"}, + {"aversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_aversin}, + "inverse versed sine of a, within accuracy b"}, + {"avg", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_avg}, + "arithmetic mean of values"}, + {"base", 0, 1, 0, OP_NOP, {.numfunc_cnt = f_base}, {.null = NULL}, + "set default output base"}, + {"base2", 0, 1, 0, OP_NOP, {.numfunc_cnt = f_base2}, {.null = NULL}, + "set default secondary output base"}, + {"bernoulli", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_bern}, + "Bernoulli number for index a"}, + {"bit", 2, 2, 0, OP_BIT, {.null = NULL}, {.null = NULL}, + "whether bit b in value a is set"}, + {"blk", 0, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_blk}, + "block with or without name, octet number, chunksize"}, + {"blkcpy", 2, 5, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_blkcpy}, + "copy value to/from a block: blkcpy(d,s,len,di,si)"}, + {"blkfree", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_blkfree}, + "free all storage from a named block"}, + {"blocks", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_blocks}, + "named block with specified index, or null value"}, + {"bround", 1, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_bround}, + "round value a to b number of binary places"}, + {"btrunc", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_btrunc}, {.null = NULL}, + "truncate a to b number of binary places"}, + {"calclevel", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_calclevel}, + "current calculation level"}, + {"calcpath", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_calcpath}, + "current CALCPATH search path value"}, + {"calc_tty", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_calc_tty}, + "set tty for interactivity"}, + {"cas", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_cas}, + "cosine plus sine, within accuracy b"}, + {"catalan", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_catalan}, + "catalan number for index a"}, + {"ceil", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ceil}, + "smallest integer greater than or equal to number"}, + {"cfappr", 1, 3, 0, OP_NOP, {.numfunc_cnt = f_cfappr}, {.null = NULL}, + "approximate a, within accuracy b using\n" + "\t\t\tcontinued fractions"}, + {"cfsim", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_cfsim}, {.null = NULL}, + "simplify number using continued fractions"}, + {"char", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_char}, + "character corresponding to integer value"}, + {"cis", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_cis}, + "Euler's formula, within accuracy b"}, + {"cmdbuf", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_cmdbuf}, + "command buffer"}, + {"cmp", 2, 2, 0, OP_CMP, {.null = NULL}, {.null = NULL}, + "compare values returning -1, 0, or 1"}, + {"comb", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_comb}, + "combinatorial number a!/b!(a-b)!"}, + {"config", 1, 2, 0, OP_SETCONFIG, {.null = NULL}, {.null = NULL}, + "set or read configuration value"}, + {"conj", 1, 1, 0, OP_CONJUGATE, {.null = NULL}, {.null = NULL}, + "complex conjugate of value"}, + {"copy", 2, 5, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_copy}, + "copy value to/from a block: copy(s,d,len,si,di)"}, + {"cos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_cos}, + "cosine of value a, within accuracy b"}, + {"cosh", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_cosh}, + "hyperbolic cosine of a, within accuracy b"}, + {"cot", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_cot}, + "cotangent of a, within accuracy b"}, + {"coth", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_coth}, + "hyperbolic cotangent of a, within accuracy b"}, + {"count", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_count}, + "count listr/matrix elements satisfying some condition"}, + {"covercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_covercos}, + "coversed cosine of value a, within accuracy b"}, + {"coversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_coversin}, + "coversed sine of value a, within accuracy b"}, + {"cp", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_cp}, + "cross product of two vectors"}, + {"crd", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_crd}, + "length of unit circle chord with angle a, within accuracy b"}, + {"csc", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_csc}, + "cosecant of a, within accuracy b"}, + {"csch", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_csch}, + "hyperbolic cosecant of a, within accuracy b"}, + {"ctime", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_ctime}, + "date and time as string"}, + {"custom", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_custom}, + "custom builtin function interface"}, + {"d2dm", 3, 4, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_d2dm}, + "convert a to b deg, c min, rounding type d\n"}, + {"d2dms", 4, 5, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_d2dms}, + "convert a to b deg, c min, d sec, rounding type e\n"}, + {"d2g", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_d2g}, + "convert degrees to gradians"}, + {"d2r", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_d2r}, + "convert degrees to radians"}, + {"delete", 2, 2, FA, OP_NOP, {.null = NULL}, {.valfunc_2 = f_listdelete}, + "delete element from list a at position b"}, + {"den", 1, 1, 0, OP_DENOMINATOR, {.numfunc_1 = qden}, {.null = NULL}, + "denominator of fraction"}, + {"det", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_det}, + "determinant of matrix"}, + {"digit", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_digit}, + "digit at specified decimal place of number"}, + {"digits", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_digits}, + "number of digits in base b representation of a"}, + {"display", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_display}, + "number of decimal digits for displaying numbers"}, + {"dm2d", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_dm2d}, + "convert a deg, b min to degrees, rounding type c\n"}, + {"dms2d", 3, 4, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_dms2d}, + "convert a deg, b min, c sec to degrees, rounding type d\n"}, + {"dp", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_dp}, + "dot product of two vectors"}, + {"epsilon", 0, 1, 0, OP_SETEPSILON, {.null = NULL}, {.null = NULL}, + "set or read allowed error for real calculations"}, + {"errcount", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_errcount}, + "set or read error count"}, + {"errmax", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_errmax}, + "set or read maximum for error count"}, + {"errno", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_errno}, + "set or read calc_errno"}, + {"error", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_error}, + "generate error value"}, + {"errsym", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_errsym}, + "convert between E_STRING errsym into a errnum number"}, + {"estr", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_estr}, + "exact text string representation of value"}, + {"euler", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_euler}, + "Euler number"}, + {"eval", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_eval}, + "evaluate expression from string to value"}, + {"excsc", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_excsc}, + "exterior cosecant of a, within accuracy b"}, + {"exp", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_exp}, + "exponential of value a, within accuracy b"}, + {"exsec", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_exsec}, + "exterior secant of a, within accuracy b"}, + {"fact", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fact}, + "factorial"}, + {"factor", 1, 3, 0, OP_NOP, {.numfunc_cnt = f_factor}, {.null = NULL}, + "lowest prime factor < b of a, return c if error"}, + {"fclose", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fclose}, + "close file"}, + {"fcnt", 2, 2, 0, OP_NOP, {.numfunc_2 = f_faccnt}, {.null = NULL}, + "count of times one number divides another"}, + {"feof", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_feof}, + "whether EOF reached for file"}, + {"ferror", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ferror}, + "whether error occurred for file"}, + {"fflush", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fflush}, + "flush output to file(s)"}, + {"fgetc", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fgetc}, + "read next char from file"}, + {"fgetfield", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fgetfield}, + "read next white-space delimited field from file"}, + {"fgetfile", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fgetfile}, + "read to end of file"}, + {"fgetline", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fgetline}, + "read next line from file, newline removed"}, + {"fgets", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fgets}, + "read next line from file, newline is kept"}, + {"fgetstr", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fgetstr}, + "read next null-terminated string from file, null\n" + "\t\t\tcharacter is kept"}, + {"fib", 1, 1, 0, OP_NOP, {.numfunc_1 = qfib}, {.null = NULL}, + "Fibonacci number F(n)"}, + {"files", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_files}, + "return opened file or max number of opened files"}, + {"floor", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_floor}, + "greatest integer less than or equal to number"}, + {"fopen", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_fopen}, + "open file name a in mode b"}, + {"forall", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_forall}, + "do function for all elements of list or matrix"}, + {"fpathopen", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fpathopen}, + "open file name a in mode b, search for a along\n" + "\t\t\tCALCPATH or path c"}, + {"fprintf", 2, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fprintf}, + "print formatted output to opened file"}, + {"fputc", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_fputc}, + "write a character to a file"}, + {"fputs", 2, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fputs}, + "write one or more strings to a file"}, + {"fputstr", 2, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fputstr}, + "write one or more null-terminated strings to a file"}, + {"frac", 1, 1, 0, OP_FRAC, {.numfunc_1 = qfrac}, {.null = NULL}, + "fractional part of value"}, + {"free", 0, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_free}, + "free listed or all global variables"}, + {"freebernoulli", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_freebern}, + "free stored Bernoulli numbers"}, + {"freeeuler", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_freeeuler}, + "free stored Euler numbers"}, + {"freeglobals", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_freeglobals}, + "free all global and visible static variables"}, + {"freeredc", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_freeredc}, + "free redc data cache"}, + {"freestatics", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_freestatics}, + "free all un-scoped static variables"}, + {"frem", 2, 2, 0, OP_NOP, {.numfunc_2 = qfacrem}, {.null = NULL}, + "number with all occurrences of factor removed"}, + {"freopen", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_freopen}, + "reopen a file stream to a named file"}, + {"fscan", 2, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fscan}, + "scan a file for assignments to one or\n" + "\t\t\tmore variables"}, + {"fscanf", 2, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fscanf}, + "formatted scan of a file for assignment to one\n" + "\t\t\tor more variables"}, + {"fseek", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_fseek}, + "seek to position b (offset from c) in file a"}, + {"fsize", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_fsize}, + "return the size of the file"}, + {"ftell", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ftell}, + "return the file position"}, + {"g2d", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_g2d}, + "convert gradians to degrees"}, + {"g2gm", 3, 4, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_g2gm}, + "convert a to b grads, c min, rounding type d\n"}, + {"g2gms", 4, 5, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_g2gms}, + "convert a to b grads, c min, d sec, rounding type e\n"}, + {"g2r", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_g2r}, + "convert gradians to radians"}, + {"gcd", 1, IN, 0, OP_NOP, {.numfunc_cnt = f_gcd}, {.null = NULL}, + "greatest common divisor"}, + {"gcdrem", 2, 2, 0, OP_NOP, {.numfunc_2 = qgcdrem}, {.null = NULL}, + "a divided repeatedly by gcd with b"}, + {"gd", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_gd}, + "Gudermannian function"}, + {"getenv", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_getenv}, + "value of environment variable (or NULL)"}, + {"gm2g", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_gm2g}, + "convert a grads, b min to grads, rounding type c\n"}, + {"gms2g", 3, 4, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_gms2g}, + "convert a grads, b min, c sec to grads, rounding type d\n"}, + {"h2hm", 3, 4, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_h2hm}, + "convert a to b hours, c min, rounding type d\n"}, + {"h2hms", 4, 5, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_h2hms}, + "convert a to b hours, c min, d sec, rounding type e\n"}, + {"hacovercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_hacovercos}, + "half coversed cosine of value a, within accuracy b"}, + {"hacoversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_hacoversin}, + "half coversed sine of value a, within accuracy b"}, + {"hash", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_hash}, + "return non-negative hash value for one or\n" + "\t\t\tmore values"}, + {"havercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_havercos}, + "half versed cosine of value a, within accuracy b"}, + {"haversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_haversin}, + "half versed sine of value a, within accuracy b"}, + {"head", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_head}, + "return list of specified number at head of a list"}, + {"highbit", 1, 1, 0, OP_HIGHBIT, {.null = NULL}, {.null = NULL}, + "high bit number in base 2 representation"}, + {"hm2h", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_hm2h}, + "convert a hours, b min to hours, rounding type c\n"}, + {"hmean", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_hmean}, + "harmonic mean of values"}, + {"hms2h", 3, 4, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_hms2h}, + "convert a hours, b min, c sec to hours, rounding type d\n"}, + {"hnrmod", 4, 4, 0, OP_NOP, {.numfunc_4 = f_hnrmod}, {.null = NULL}, + "v mod h*2^n+r, h>0, n>0, r = -1, 0 or 1"}, + {"hypot", 2, 3, FE, OP_NOP, {.numfunc_3 = qhypot}, {.null = NULL}, + "hypotenuse of right triangle, within accuracy c"}, + {"ilog", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_ilog}, + "integral log of a to integral base b"}, + {"ilog10", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ilog10}, + "integral log of a number base 10"}, + {"ilog2", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ilog2}, + "integral log of a number base 2"}, + {"ilogn", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_ilog}, + "same is ilog"}, + {"im", 1, 1, 0, OP_IM, {.null = NULL}, {.null = NULL}, + "imaginary part of complex number"}, + {"indices", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_indices}, + "indices of a specified assoc or mat value"}, + {"inputlevel", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_inputlevel}, + "current input depth"}, + {"insert", 2, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_listinsert}, + "insert values c ... into list a at position b"}, + {"int", 1, 1, 0, OP_INT, {.numfunc_1 = qint}, {.null = NULL}, + "integer part of value"}, + {"inverse", 1, 1, 0, OP_INVERT, {.null = NULL}, {.null = NULL}, + "multiplicative inverse of value"}, + {"iroot", 2, 2, 0, OP_NOP, {.numfunc_2 = qiroot}, {.null = NULL}, + "integer b'th root of a"}, + {"isalnum", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isalnum}, + "whether character is alpha-numeric"}, + {"isalpha", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isalpha}, + "whether character is alphabetic"}, + {"isassoc", 1, 1, 0, OP_ISASSOC, {.null = NULL}, {.null = NULL}, + "whether a value is an association"}, + {"isatty", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isatty}, + "whether a file is a tty"}, + {"isblk", 1, 1, 0, OP_ISBLK, {.null = NULL}, {.null = NULL}, + "whether a value is a block"}, + {"iscntrl", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_iscntrl}, + "whether character is a control character"}, + {"isconfig", 1, 1, 0, OP_ISCONFIG, {.null = NULL}, {.null = NULL}, + "whether a value is a config state"}, + {"isdefined", 1, 1, 0, OP_ISDEFINED, {.null = NULL}, {.null = NULL}, + "whether a string names a function"}, + {"isdigit", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isdigit}, + "whether character is a digit"}, + {"iserror", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_iserror}, + "where a value is an error"}, + {"iseven", 1, 1, 0, OP_ISEVEN, {.null = NULL}, {.null = NULL}, + "whether a value is an even integer"}, + {"isfile", 1, 1, 0, OP_ISFILE, {.null = NULL}, {.null = NULL}, + "whether a value is a file"}, + {"isgraph", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isgraph}, + "whether character is a graphical character"}, + {"ishash", 1, 1, 0, OP_ISHASH, {.null = NULL}, {.null = NULL}, + "whether a value is a hash state"}, + {"isident", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isident}, + "returns 1 if identity matrix"}, + {"isint", 1, 1, 0, OP_ISINT, {.null = NULL}, {.null = NULL}, + "whether a value is an integer"}, + {"islist", 1, 1, 0, OP_ISLIST, {.null = NULL}, {.null = NULL}, + "whether a value is a list"}, + {"islower", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_islower}, + "whether character is lower case"}, + {"ismat", 1, 1, 0, OP_ISMAT, {.null = NULL}, {.null = NULL}, + "whether a value is a matrix"}, + {"ismult", 2, 2, 0, OP_NOP, {.numfunc_2 = f_ismult}, {.null = NULL}, + "whether a is a multiple of b"}, + {"isnull", 1, 1, 0, OP_ISNULL, {.null = NULL}, {.null = NULL}, + "whether a value is the null value"}, + {"isnum", 1, 1, 0, OP_ISNUM, {.null = NULL}, {.null = NULL}, + "whether a value is a number"}, + {"isobj", 1, 1, 0, OP_ISOBJ, {.null = NULL}, {.null = NULL}, + "whether a value is an object"}, + {"isobjtype", 1, 1, 0, OP_ISOBJTYPE, {.null = NULL}, {.null = NULL}, + "whether a string names an object type"}, + {"isoctet", 1, 1, 0, OP_ISOCTET, {.null = NULL}, {.null = NULL}, + "whether a value is an octet"}, + {"isodd", 1, 1, 0, OP_ISODD, {.null = NULL}, {.null = NULL}, + "whether a value is an odd integer"}, + {"isprime", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_isprime}, {.null = NULL}, + "whether a is a small prime, return b if error"}, + {"isprint", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isprint}, + "whether character is printable"}, + {"isptr", 1, 1, 0, OP_ISPTR, {.null = NULL}, {.null = NULL}, + "whether a value is a pointer"}, + {"ispunct", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ispunct}, + "whether character is a punctuation"}, + {"isqrt", 1, 1, 0, OP_NOP, {.numfunc_1 = qisqrt}, {.null = NULL}, + "integer part of square root"}, + {"isrand", 1, 1, 0, OP_ISRAND, {.null = NULL}, {.null = NULL}, + "whether a value is a subtractive 100 state"}, + {"israndom", 1, 1, 0, OP_ISRANDOM, {.null = NULL}, {.null = NULL}, + "whether a value is a Blum state"}, + {"isreal", 1, 1, 0, OP_ISREAL, {.null = NULL}, {.null = NULL}, + "whether a value is a real number"}, + {"isrel", 2, 2, 0, OP_NOP, {.numfunc_2 = f_isrel}, {.null = NULL}, + "whether two numbers are relatively prime"}, + {"issimple", 1, 1, 0, OP_ISSIMPLE, {.null = NULL}, {.null = NULL}, + "whether value is a simple type"}, + {"isspace", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isspace}, + "whether character is a space character"}, + {"issq", 1, 1, 0, OP_NOP, {.numfunc_1 = f_issquare}, {.null = NULL}, + "whether or not number is a square"}, + {"isstr", 1, 1, 0, OP_ISSTR, {.null = NULL}, {.null = NULL}, + "whether a value is a string"}, + {"istype", 2, 2, 0, OP_ISTYPE, {.null = NULL}, {.null = NULL}, + "whether the type of a is same as the type of b"}, + {"isupper", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isupper}, + "whether character is upper case"}, + {"isxdigit", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_isxdigit}, + "whether character is a hexadecimal digit"}, + {"jacobi", 2, 2, 0, OP_NOP, {.numfunc_2 = qjacobi}, {.null = NULL}, + "-1 = > a is not quadratic residue mod b\n" + "\t\t\t1 = > b is composite, or a is quad residue of b"}, + {"join", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_join}, + "join one or more lists into one list"}, + {"lcm", 1, IN, 0, OP_NOP, {.numfunc_cnt = f_lcm}, {.null = NULL}, + "least common multiple"}, + {"lcmfact", 1, 1, 0, OP_NOP, {.numfunc_1 = qlcmfact}, {.null = NULL}, + "lcm of all integers up till number"}, + {"lfactor", 2, 2, 0, OP_NOP, {.numfunc_2 = qlowfactor}, {.null = NULL}, + "lowest prime factor of a in first b primes"}, + {"links", 1, 1, 0, OP_LINKS, {.null = NULL}, {.null = NULL}, + "links to number or string value"}, + {"list", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_list}, + "create list of specified values"}, + {"ln", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_ln}, + "natural logarithm of value a, within accuracy b"}, + {"log", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_log}, + "base 10 logarithm of value a, within accuracy b"}, + {"log2", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_log2}, + "base 2 logarithm of value a, within accuracy b"}, + {"logn", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_logn}, + "base b logarithm of value a, within accuracy c"}, + {"lowbit", 1, 1, 0, OP_LOWBIT, {.null = NULL}, {.null = NULL}, + "low bit number in base 2 representation"}, + {"ltol", 1, 2, FE, OP_NOP, {.numfunc_2 = f_legtoleg}, {.null = NULL}, + "leg-to-leg of unit right triangle (sqrt(1 - a^2))"}, + {"makelist", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_makelist}, + "create a list with a null elements"}, + {"matdim", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_matdim}, + "number of dimensions of matrix"}, + {"matfill", 2, 3, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_matfill}, + "fill matrix with value b (value c on diagonal)"}, + {"matmax", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_matmax}, + "maximum index of matrix a dim b"}, + {"matmin", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_matmin}, + "minimum index of matrix a dim b"}, + {"matsum", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_matsum}, + "sum the numeric values in a matrix"}, + {"mattrace", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_mattrace}, + "return the trace of a square matrix"}, + {"mattrans", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_mattrans}, + "transpose of matrix"}, + {"max", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_max}, + "maximum value"}, + {"memsize", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_memsize}, + "number of octets used by the value, including overhead"}, + {"meq", 3, 3, 0, OP_NOP, {.numfunc_3 = f_meq}, {.null = NULL}, + "whether a and b are equal modulo c"}, + {"min", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_min}, + "minimum value"}, + {"minv", 2, 2, 0, OP_NOP, {.numfunc_2 = qminv}, {.null = NULL}, + "inverse of a modulo b"}, + {"mmin", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_mmin}, + "a mod b value with smallest abs value"}, + {"mne", 3, 3, 0, OP_NOP, {.numfunc_3 = f_mne}, {.null = NULL}, + "whether a and b are not equal modulo c"}, + {"mod", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_mod}, + "residue of a modulo b, rounding type c"}, + {"modify", 2, 2, FA, OP_NOP, {.null = NULL}, {.valfunc_2 = f_modify}, + "modify elements of a list or matrix"}, + {"name", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_name}, + "name assigned to block or file"}, + {"near", 2, 3, 0, OP_NOP, {.numfunc_cnt = f_near}, {.null = NULL}, + "sign of (abs(a-b) - c)"}, + {"newerror", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_newerror}, + "create new error type with message a"}, + {"nextcand", 1, 5, 0, OP_NOP, {.numfunc_cnt = f_nextcand}, {.null = NULL}, + "smallest value = = d mod e > a, ptest(a,b,c) true"}, + {"nextprime", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_nprime}, {.null = NULL}, + "return next small prime, return b if err"}, + {"norm", 1, 1, 0, OP_NORM, {.null = NULL}, {.null = NULL}, + "norm of a value (square of absolute value)"}, + {"null", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_null}, + "null value"}, + {"num", 1, 1, 0, OP_NUMERATOR, {.numfunc_1 = qnum}, {.null = NULL}, + "numerator of fraction"}, + {"ord", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_ord}, + "integer corresponding to character value"}, + {"param", 1, 1, 0, OP_ARGVALUE, {.null = NULL}, {.null = NULL}, + "value of parameter n (or parameter count if n\n" + "\t\t\tis zero)"}, + {"perm", 2, 2, 0, OP_NOP, {.numfunc_2 = qperm}, {.null = NULL}, + "permutation number a!/(a-b)!"}, + {"pfact", 1, 1, 0, OP_NOP, {.numfunc_1 = qpfact}, {.null = NULL}, + "product of primes up till number"}, + {"pi", 0, 1, FE, OP_NOP, {.numfunc_1 = qpi}, {.null = NULL}, + "value of pi, within accuracy a"}, + {"pix", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_pix}, {.null = NULL}, + "number of primes < = a < 2^32, return b if error"}, + {"places", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_places}, + "places after \"decimal\" point (-1 if infinite)"}, + {"pmod", 3, 3, 0, OP_NOP, {.numfunc_3 = qpowermod}, {.null = NULL}, + "mod of a power (a ^ b (mod c))"}, + {"polar", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_polar}, + "complex value of polar coordinate (a * exp(b*1i))"}, + {"poly", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_poly}, + "evaluates a polynomial given its coefficients\n" + "\t\t\tor coefficient-list"}, + {"pop", 1, 1, FA, OP_NOP, {.null = NULL}, {.valfunc_1 = f_listpop}, + "pop value from front of list"}, + {"popcnt", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_popcnt}, {.null = NULL}, + "number of bits in a that match b (or 1)"}, + {"power", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_power}, + "value a raised to the power b, within accuracy c"}, + {"prevcand", 1, 5, 0, OP_NOP, {.numfunc_cnt = f_prevcand}, {.null = NULL}, + "largest value = = d mod e < a, ptest(a,b,c) true"}, + {"prevprime", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_pprime}, {.null = NULL}, + "return previous small prime, return b if err"}, + {"printf", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_printf}, + "print formatted output to stdout"}, + {"prompt", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_prompt}, + "prompt for input line using value a"}, + {"protect", 1, 3, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_protect}, + "read or set protection level for variable"}, + {"ptest", 1, 3, 0, OP_NOP, {.numfunc_cnt = f_primetest}, {.null = NULL}, + "probabilistic primality test"}, + {"push", 1, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_listpush}, + "push values onto front of list"}, + {"putenv", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_putenv}, + "define an environment variable"}, + {"quo", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_quo}, + "integer quotient of a by b, rounding type c"}, + {"quomod", 4, 5, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_quomod}, + "set c and d to quotient and remainder of a\n" + "\t\t\tdivided by b"}, + {"r2d", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_r2d}, + "convert radians to degrees"}, + {"r2g", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_r2g}, + "convert radians to gradians"}, + {"rand", 0, 2, 0, OP_NOP, {.numfunc_cnt = f_rand}, {.null = NULL}, + "subtractive 100 random number [0,2^64), [0,a), or [a,b)"}, + {"randbit", 0, 1, 0, OP_NOP, {.numfunc_cnt = f_randbit}, {.null = NULL}, + "subtractive 100 random number [0,2^a)"}, + {"random", 0, 2, 0, OP_NOP, {.numfunc_cnt = f_random}, {.null = NULL}, + "Blum-Blum-Shub random number [0,2^64), [0,a), or [a,b)"}, + {"randombit", 0, 1, 0, OP_NOP, {.numfunc_cnt = f_randombit}, {.null = NULL}, + "Blum-Blum-Sub random number [0,2^a)"}, + {"randperm", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_randperm}, + "random permutation of a list or matrix"}, + {"rcin", 2, 2, 0, OP_NOP, {.numfunc_2 = qredcin}, {.null = NULL}, + "convert normal number a to REDC number mod b"}, + {"rcmul", 3, 3, 0, OP_NOP, {.numfunc_3 = qredcmul}, {.null = NULL}, + "multiply REDC numbers a and b mod c"}, + {"rcout", 2, 2, 0, OP_NOP, {.numfunc_2 = qredcout}, {.null = NULL}, + "convert REDC number a mod b to normal number"}, + {"rcpow", 3, 3, 0, OP_NOP, {.numfunc_3 = qredcpower}, {.null = NULL}, + "raise REDC number a to power b mod c"}, + {"rcsq", 2, 2, 0, OP_NOP, {.numfunc_2 = qredcsquare}, {.null = NULL}, + "square REDC number a mod b"}, + {"re", 1, 1, 0, OP_RE, {.null = NULL}, {.null = NULL}, + "real part of complex number"}, + {"remove", 1, 1, FA, OP_NOP, {.null = NULL}, {.valfunc_1 = f_listremove}, + "remove value from end of list"}, + {"reverse", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_reverse}, + "reverse a copy of a matrix or list"}, + {"rewind", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_rewind}, + "rewind file(s)"}, + {"rm", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_rm}, + "remove file(s), -f turns off no-such-file errors"}, + {"root", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_root}, + "value a taken to the b'th root, within accuracy c"}, + {"round", 1, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_round}, + "round value a to b number of decimal places"}, + {"rsearch", 2, 4, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_rsearch}, + "reverse search matrix or list for value b\n" + "\t\t\tstarting at index c"}, + {"runtime", 0, 0, 0, OP_NOP, {.numfunc_0 = f_runtime}, {.null = NULL}, + "user and kernel mode CPU time in seconds"}, + {"saveval", 1, 1, 0, OP_SAVEVAL, {.null = NULL}, {.null = NULL}, + "set flag for saving values"}, + {"scale", 2, 2, 0, OP_SCALE, {.null = NULL}, {.null = NULL}, + "scale value up or down by a power of two"}, + {"scan", 1, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_scan}, + "scan standard input for assignment to one\n" + "\t\t\tor more variables"}, + {"scanf", 2, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_scanf}, + "formatted scan of standard input for assignment\n" + "\t\t\tto variables"}, + {"search", 2, 4, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_search}, + "search matrix or list for value b starting\n" + "\t\t\tat index c"}, + {"sec", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sec}, + "secant of a, within accuracy b"}, + {"sech", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sech}, + "hyperbolic secant of a, within accuracy b"}, + {"seed", 0, 0, 0, OP_NOP, {.numfunc_0 = f_seed}, {.null = NULL}, + "return a 64 bit seed for a pseudo-random generator"}, + {"segment", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_segment}, + "specified segment of specified list"}, + {"select", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_select}, + "form sublist of selected elements from list"}, + {"setbit", 2, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_setbit}, + "set specified bit in string"}, + {"sgn", 1, 1, 0, OP_SGN, {.numfunc_1 = qsign}, {.null = NULL}, + "sign of value (-1, 0, 1)"}, + {"sha1", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sha1}, + "Secure Hash Algorithm (SHS-1 FIPS Pub 180-1)"}, + {"sin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sin}, + "sine of value a, within accuracy b"}, + {"sinh", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sinh}, + "hyperbolic sine of a, within accuracy b"}, + {"size", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_size}, + "total number of elements in value"}, + {"sizeof", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_sizeof}, + "number of octets used to hold the value"}, + {"sleep", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sleep}, + "suspend operation for a seconds"}, + {"sort", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_sort}, + "sort a copy of a matrix or list"}, + {"sqrt", 1, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sqrt}, + "square root of value a, within accuracy b"}, + {"srand", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_srand}, + "seed the rand() function"}, + {"srandom", 0, 4, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_srandom}, + "seed the random() function"}, + {"ssq", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_ssq}, + "sum of squares of values"}, + {"stoponerror", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_stoponerror}, + "assign value to stoponerror flag"}, + {"str", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_str}, + "simple value converted to string"}, + {"strcasecmp", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_strcasecmp}, + "compare two strings case independent"}, + {"strcat", 1,IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_strcat}, + "concatenate strings together"}, + {"strcmp", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_strcmp}, + "compare two strings"}, + {"strcpy", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_strcpy}, + "copy string to string"}, + {"strerror", 0, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_strerror}, + "string describing error type"}, + {"strlen", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_strlen}, + "length of string"}, + {"strncasecmp", 3, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_3 = f_strncasecmp}, + "compare strings a, b to c characters case independent"}, + {"strncmp", 3, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_3 = f_strncmp}, + "compare strings a, b to c characters"}, + {"strncpy", 3, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_3 = f_strncpy}, + "copy up to c characters from string to string"}, + {"strpos", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_strpos}, + "index of first occurrence of b in a"}, + {"strprintf", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_strprintf}, + "return formatted output as a string"}, + {"strscan", 2, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_strscan}, + "scan a string for assignments to one or more variables"}, + {"strscanf", 2, IN, FA, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_strscanf}, + "formatted scan of string for assignments to variables"}, {"strtolower", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_strtolower}, "Make string lower case"}, {"strtoupper", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_strtoupper}, "Make string upper case"}, - {"substr", 3, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_3 = f_substr}, - "substring of a from position b for c chars"}, - {"sum", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sum}, - "sum of list or object sums and/or other terms"}, - {"swap", 2, 2, 0, OP_SWAP, {.null = NULL}, {.null = NULL}, - "swap values of variables a and b (can be dangerous)"}, - {"system", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_system}, - "call Unix command"}, - {"systime", 0, 0, 0, OP_NOP, {.numfunc_0 = f_systime}, {.null = NULL}, - "kernel mode CPU time in seconds"}, - {"tail", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_tail}, - "retain list of specified number at tail of list"}, - {"tan", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_tan}, - "tangent of a, within accuracy b"}, - {"tanh", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_tanh}, - "hyperbolic tangent of a, within accuracy b"}, - {"test", 1, 1, 0, OP_TEST, {.null = NULL}, {.null = NULL}, - "test that value is nonzero"}, - {"time", 0, 0, 0, OP_NOP, {.numfunc_0 = f_time}, {.null = NULL}, - "number of seconds since 00:00:00 1 Jan 1970 UTC"}, - {"trunc", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_trunc}, {.null = NULL}, - "truncate a to b number of decimal places"}, - {"ungetc", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_ungetc}, - "unget char read from file"}, - {"usertime", 0, 0, 0, OP_NOP, {.numfunc_0 = f_usertime}, {.null = NULL}, - "user mode CPU time in seconds"}, - {"vercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_vercos}, - "versed cosine of value a, within accuracy b"}, - {"versin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_versin}, - "versed sine of value a, within accuracy b"}, - {"version", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_version}, - "calc version string"}, - {"xor", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_xor}, - "logical xor"}, + {"substr", 3, 3, 0, OP_NOP, {.null = NULL}, {.valfunc_3 = f_substr}, + "substring of a from position b for c chars"}, + {"sum", 0, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_sum}, + "sum of list or object sums and/or other terms"}, + {"swap", 2, 2, 0, OP_SWAP, {.null = NULL}, {.null = NULL}, + "swap values of variables a and b (can be dangerous)"}, + {"system", 1, 1, 0, OP_NOP, {.null = NULL}, {.valfunc_1 = f_system}, + "call Unix command"}, + {"systime", 0, 0, 0, OP_NOP, {.numfunc_0 = f_systime}, {.null = NULL}, + "kernel mode CPU time in seconds"}, + {"tail", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_tail}, + "retain list of specified number at tail of list"}, + {"tan", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_tan}, + "tangent of a, within accuracy b"}, + {"tanh", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_tanh}, + "hyperbolic tangent of a, within accuracy b"}, + {"test", 1, 1, 0, OP_TEST, {.null = NULL}, {.null = NULL}, + "test that value is nonzero"}, + {"time", 0, 0, 0, OP_NOP, {.numfunc_0 = f_time}, {.null = NULL}, + "number of seconds since 00:00:00 1 Jan 1970 UTC"}, + {"trunc", 1, 2, 0, OP_NOP, {.numfunc_cnt = f_trunc}, {.null = NULL}, + "truncate a to b number of decimal places"}, + {"ungetc", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_ungetc}, + "unget char read from file"}, + {"usertime", 0, 0, 0, OP_NOP, {.numfunc_0 = f_usertime}, {.null = NULL}, + "user mode CPU time in seconds"}, + {"vercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_vercos}, + "versed cosine of value a, within accuracy b"}, + {"versin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_versin}, + "versed sine of value a, within accuracy b"}, + {"version", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_version}, + "calc version string"}, + {"xor", 1, IN, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_xor}, + "logical xor"}, - /* end of table */ - {NULL, 0, 0, 0, 0, {.null = NULL}, {.null = NULL}, - NULL} + /* end of table */ + {NULL, 0, 0, 0, 0, {.null = NULL}, {.null = NULL}, + NULL} }; @@ -13318,46 +13318,46 @@ STATIC CONST struct builtin builtins[] = { int main(void) { - CONST struct builtin *bp; /* current function */ + CONST struct builtin *bp; /* current function */ - printf("\nName\tArgs\tDescription\n\n"); - for (bp = builtins; bp->b_name; bp++) { - printf("%-9s ", bp->b_name); - if (bp->b_maxargs == IN) - printf("%d+ ", bp->b_minargs); - else if (bp->b_minargs == bp->b_maxargs) - printf("%-6d", bp->b_minargs); - else - printf("%d-%-4d", bp->b_minargs, bp->b_maxargs); - printf("%s\n", bp->b_desc); - } - printf("\n"); - return 0; /* exit(0); */ + printf("\nName\tArgs\tDescription\n\n"); + for (bp = builtins; bp->b_name; bp++) { + printf("%-9s ", bp->b_name); + if (bp->b_maxargs == IN) + printf("%d+ ", bp->b_minargs); + else if (bp->b_minargs == bp->b_maxargs) + printf("%-6d", bp->b_minargs); + else + printf("%d-%-4d", bp->b_minargs, bp->b_maxargs); + printf("%s\n", bp->b_desc); + } + printf("\n"); + return 0; /* exit(0); */ } #else /* FUNCLIST */ void showbuiltins(void) { - CONST struct builtin *bp; /* current function */ - int i; + CONST struct builtin *bp; /* current function */ + int i; - printf("\nName\tArgs\tDescription\n\n"); - for (bp = builtins, i = 0; bp->b_name; bp++, i++) { - printf("%-14s ", bp->b_name); - if (bp->b_maxargs == IN) - printf("%d+ ", bp->b_minargs); - else if (bp->b_minargs == bp->b_maxargs) - printf("%-6d", bp->b_minargs); - else - printf("%d-%-4d", bp->b_minargs, bp->b_maxargs); - printf("%s\n", bp->b_desc); - if (i == 32) { - i = 0; - if (getchar() == 27) - break; - } - } - printf("\n"); + printf("\nName\tArgs\tDescription\n\n"); + for (bp = builtins, i = 0; bp->b_name; bp++, i++) { + printf("%-14s ", bp->b_name); + if (bp->b_maxargs == IN) + printf("%d+ ", bp->b_minargs); + else if (bp->b_minargs == bp->b_maxargs) + printf("%-6d", bp->b_minargs); + else + printf("%d-%-4d", bp->b_minargs, bp->b_maxargs); + printf("%s\n", bp->b_desc); + if (i == 32) { + i = 0; + if (getchar() == 27) + break; + } + } + printf("\n"); } #endif /* FUNCLIST */ @@ -13370,114 +13370,114 @@ showbuiltins(void) * Functions are either purely numeric, or else can take any value type. * * given: - * index index on where to scan in builtin table - * argcount number of args - * stck arguments on the stack + * index index on where to scan in builtin table + * argcount number of args + * stck arguments on the stack */ VALUE builtinfunc(long index, int argcount, VALUE *stck) { - VALUE *sp; /* pointer to stack entries */ - VALUE **vpp; /* pointer to current value address */ - CONST struct builtin *bp; /* builtin function to be called */ - NUMBER *numargs[IN]; /* numeric arguments for function */ - VALUE *valargs[IN]; /* addresses of actual arguments */ - VALUE result; /* general result of function */ - long i; + VALUE *sp; /* pointer to stack entries */ + VALUE **vpp; /* pointer to current value address */ + CONST struct builtin *bp; /* builtin function to be called */ + NUMBER *numargs[IN]; /* numeric arguments for function */ + VALUE *valargs[IN]; /* addresses of actual arguments */ + VALUE result; /* general result of function */ + long i; - if ((unsigned long)index >= - (sizeof(builtins) / sizeof(builtins[0])) - 1) { - math_error("Bad built-in function index"); - not_reached(); - } - bp = &builtins[index]; - if (argcount < bp->b_minargs) { - math_error("Too few arguments for builtin function \"%s\"", - bp->b_name); - not_reached(); - } - if ((argcount > bp->b_maxargs) || (argcount > IN)) { - math_error("Too many arguments for builtin function \"%s\"", - bp->b_name); - not_reached(); - } - /* - * If an address was passed, then point at the real variable, - * otherwise point at the stack value itself (unless the function - * is very special). - */ - sp = stck - argcount + 1; - vpp = valargs; - for (i = argcount; i > 0; i--) { - if ((sp->v_type != V_ADDR) || (bp->b_flags & FA)) - *vpp = sp; - else - *vpp = sp->v_addr; - sp++; - vpp++; - } - /* - * Handle general values if the function accepts them. - */ - if (bp->b_valfunc.null != NULL) { - vpp = valargs; - if ((bp->b_minargs == 1) && (bp->b_maxargs == 1)) - result = (*bp->b_valfunc.valfunc_1)(vpp[0]); - else if ((bp->b_minargs == 2) && (bp->b_maxargs == 2)) - result = (*bp->b_valfunc.valfunc_2)(vpp[0], vpp[1]); - else if ((bp->b_minargs == 3) && (bp->b_maxargs == 3)) - result = (*bp->b_valfunc.valfunc_3)(vpp[0], vpp[1], vpp[2]); - else if ((bp->b_minargs == 4) && (bp->b_maxargs == 4)) - result = (*bp->b_valfunc.valfunc_4)(vpp[0],vpp[1],vpp[2],vpp[3]); - else - result = (*bp->b_valfunc.valfunc_cnt)(argcount, vpp); - return result; - } - /* - * Function must be purely numeric, so handle that. - */ - vpp = valargs; - for (i = 0; i < argcount; i++) { - if ((*vpp)->v_type != V_NUM) { - math_error("Non-real argument for builtin function %s", - bp->b_name); - not_reached(); - } - numargs[i] = (*vpp)->v_num; - vpp++; - } - result.v_type = V_NUM; - result.v_subtype = V_NOSUBTYPE; - if (!(bp->b_flags & FE) && (bp->b_minargs != bp->b_maxargs)) { - result.v_num = (*bp->b_numfunc.numfunc_cnt)(argcount, numargs); - return result; - } - if ((bp->b_flags & FE) && (argcount < bp->b_maxargs)) - numargs[argcount++] = conf->epsilon; + if ((unsigned long)index >= + (sizeof(builtins) / sizeof(builtins[0])) - 1) { + math_error("Bad built-in function index"); + not_reached(); + } + bp = &builtins[index]; + if (argcount < bp->b_minargs) { + math_error("Too few arguments for builtin function \"%s\"", + bp->b_name); + not_reached(); + } + if ((argcount > bp->b_maxargs) || (argcount > IN)) { + math_error("Too many arguments for builtin function \"%s\"", + bp->b_name); + not_reached(); + } + /* + * If an address was passed, then point at the real variable, + * otherwise point at the stack value itself (unless the function + * is very special). + */ + sp = stck - argcount + 1; + vpp = valargs; + for (i = argcount; i > 0; i--) { + if ((sp->v_type != V_ADDR) || (bp->b_flags & FA)) + *vpp = sp; + else + *vpp = sp->v_addr; + sp++; + vpp++; + } + /* + * Handle general values if the function accepts them. + */ + if (bp->b_valfunc.null != NULL) { + vpp = valargs; + if ((bp->b_minargs == 1) && (bp->b_maxargs == 1)) + result = (*bp->b_valfunc.valfunc_1)(vpp[0]); + else if ((bp->b_minargs == 2) && (bp->b_maxargs == 2)) + result = (*bp->b_valfunc.valfunc_2)(vpp[0], vpp[1]); + else if ((bp->b_minargs == 3) && (bp->b_maxargs == 3)) + result = (*bp->b_valfunc.valfunc_3)(vpp[0], vpp[1], vpp[2]); + else if ((bp->b_minargs == 4) && (bp->b_maxargs == 4)) + result = (*bp->b_valfunc.valfunc_4)(vpp[0],vpp[1],vpp[2],vpp[3]); + else + result = (*bp->b_valfunc.valfunc_cnt)(argcount, vpp); + return result; + } + /* + * Function must be purely numeric, so handle that. + */ + vpp = valargs; + for (i = 0; i < argcount; i++) { + if ((*vpp)->v_type != V_NUM) { + math_error("Non-real argument for builtin function %s", + bp->b_name); + not_reached(); + } + numargs[i] = (*vpp)->v_num; + vpp++; + } + result.v_type = V_NUM; + result.v_subtype = V_NOSUBTYPE; + if (!(bp->b_flags & FE) && (bp->b_minargs != bp->b_maxargs)) { + result.v_num = (*bp->b_numfunc.numfunc_cnt)(argcount, numargs); + return result; + } + if ((bp->b_flags & FE) && (argcount < bp->b_maxargs)) + numargs[argcount++] = conf->epsilon; - switch (argcount) { - case 0: - result.v_num = (*bp->b_numfunc.numfunc_0)(); - break; - case 1: - result.v_num = (*bp->b_numfunc.numfunc_1)(numargs[0]); - break; - case 2: - result.v_num = (*bp->b_numfunc.numfunc_2)(numargs[0], numargs[1]); - break; - case 3: - result.v_num = (*bp->b_numfunc.numfunc_3)(numargs[0], - numargs[1], numargs[2]); - break; - case 4: - result.v_num = (*bp->b_numfunc.numfunc_4)(numargs[0], numargs[1], - numargs[2], numargs[3]); - break; - default: - math_error("Bad builtin function call"); - not_reached(); - } - return result; + switch (argcount) { + case 0: + result.v_num = (*bp->b_numfunc.numfunc_0)(); + break; + case 1: + result.v_num = (*bp->b_numfunc.numfunc_1)(numargs[0]); + break; + case 2: + result.v_num = (*bp->b_numfunc.numfunc_2)(numargs[0], numargs[1]); + break; + case 3: + result.v_num = (*bp->b_numfunc.numfunc_3)(numargs[0], + numargs[1], numargs[2]); + break; + case 4: + result.v_num = (*bp->b_numfunc.numfunc_4)(numargs[0], numargs[1], + numargs[2], numargs[3]); + break; + default: + math_error("Bad builtin function call"); + not_reached(); + } + return result; } @@ -13488,13 +13488,13 @@ builtinfunc(long index, int argcount, VALUE *stck) int getbuiltinfunc(char *name) { - CONST struct builtin *bp; + CONST struct builtin *bp; - for (bp = builtins; bp->b_name; bp++) { - if ((*name == *bp->b_name) && (strcmp(name, bp->b_name) == 0)) - return (bp - builtins); - } - return -1; + for (bp = builtins; bp->b_name; bp++) { + if ((*name == *bp->b_name) && (strcmp(name, bp->b_name) == 0)) + return (bp - builtins); + } + return -1; } @@ -13504,10 +13504,10 @@ getbuiltinfunc(char *name) char * builtinname(long index) { - if ((unsigned long)index >= - (sizeof(builtins) / sizeof(builtins[0])) - 1) - return ""; - return builtins[index].b_name; + if ((unsigned long)index >= + (sizeof(builtins) / sizeof(builtins[0])) - 1) + return ""; + return builtins[index].b_name; } @@ -13519,22 +13519,22 @@ builtinname(long index) void builtincheck(long index, int count) { - CONST struct builtin *bp; + CONST struct builtin *bp; - if ((unsigned long)index >= - (sizeof(builtins) / sizeof(builtins[0])) - 1) { - math_error("Unknown built in index"); - not_reached(); - } - bp = &builtins[index]; - if (count < bp->b_minargs) - scanerror(T_NULL, - "Too few arguments for builtin function \"%s\"", - bp->b_name); - if (count > bp->b_maxargs) - scanerror(T_NULL, - "Too many arguments for builtin function \"%s\"", - bp->b_name); + if ((unsigned long)index >= + (sizeof(builtins) / sizeof(builtins[0])) - 1) { + math_error("Unknown built in index"); + not_reached(); + } + bp = &builtins[index]; + if (count < bp->b_minargs) + scanerror(T_NULL, + "Too few arguments for builtin function \"%s\"", + bp->b_name); + if (count > bp->b_maxargs) + scanerror(T_NULL, + "Too many arguments for builtin function \"%s\"", + bp->b_name); } @@ -13545,10 +13545,10 @@ builtincheck(long index, int count) int builtinopcode(long index) { - if ((unsigned long)index >= - (sizeof(builtins) / sizeof(builtins[0])) - 1) - return OP_NOP; - return builtins[index].b_opcode; + if ((unsigned long)index >= + (sizeof(builtins) / sizeof(builtins[0])) - 1) + return OP_NOP; + return builtins[index].b_opcode; } /* @@ -13557,13 +13557,13 @@ builtinopcode(long index) void showerrors(void) { - int i; + int i; - if (nexterrnum == E__USERDEF) - printf("No new error-values created\n"); - for (i = E__USERDEF; i < nexterrnum; i++) - printf("%d: %s\n", i, - namestr(&newerrorstr, i - E__USERDEF)); + if (nexterrnum == E__USERDEF) + printf("No new error-values created\n"); + for (i = E__USERDEF; i < nexterrnum; i++) + printf("%d: %s\n", i, + namestr(&newerrorstr, i - E__USERDEF)); } @@ -13571,140 +13571,140 @@ showerrors(void) * malloced_putenv - Keep track of malloced environment variable storage * * given: - * str a malloced string which will be given to putenv + * str a malloced string which will be given to putenv * * returns: - * putenv() return value + * putenv() return value * * NOTE: The caller MUST pass a string that the caller has previously malloced. */ S_FUNC int malloced_putenv(char *str) { - char *value; /* location of the value part of the str argument */ - char *old_val; /* previously stored (or inherited) env value */ - int found_cnt; /* number of active env_pool entries found */ - struct env_pool *new; /* new e_pool */ - int i; + char *value; /* location of the value part of the str argument */ + char *old_val; /* previously stored (or inherited) env value */ + int found_cnt; /* number of active env_pool entries found */ + struct env_pool *new; /* new e_pool */ + int i; - /* - * firewall - */ - if (str == NULL) { - math_error("malloced_putenv given a NULL pointer!!"); - not_reached(); - } - if (str[0] == '=') { - math_error("malloced_putenv = is first character in string!!"); - not_reached(); - } + /* + * firewall + */ + if (str == NULL) { + math_error("malloced_putenv given a NULL pointer!!"); + not_reached(); + } + if (str[0] == '=') { + math_error("malloced_putenv = is first character in string!!"); + not_reached(); + } - /* - * determine the place where getenv would return - */ - value = strchr(str, '='); - if (value == NULL) { - math_error("malloced_putenv = not found in string!!"); - not_reached(); - } - ++value; + /* + * determine the place where getenv would return + */ + value = strchr(str, '='); + if (value == NULL) { + math_error("malloced_putenv = not found in string!!"); + not_reached(); + } + ++value; - /* - * lookup for an existing environment value - */ - *(value-1) = '\0'; - old_val = getenv(str); - *(value-1) = '='; + /* + * lookup for an existing environment value + */ + *(value-1) = '\0'; + old_val = getenv(str); + *(value-1) = '='; - /* - * If we have the value in our environment, look for a - * previously malloced string and free it - */ - if (old_val != NULL && env_pool_cnt > 0) { - for (i=0, found_cnt=0; - i < env_pool_max && found_cnt < env_pool_cnt; - ++i) { + /* + * If we have the value in our environment, look for a + * previously malloced string and free it + */ + if (old_val != NULL && env_pool_cnt > 0) { + for (i=0, found_cnt=0; + i < env_pool_max && found_cnt < env_pool_cnt; + ++i) { - /* skip an unused entry */ - if (e_pool[i].getenv == NULL) { - continue; - } - ++found_cnt; + /* skip an unused entry */ + if (e_pool[i].getenv == NULL) { + continue; + } + ++found_cnt; - /* look for the 1st match */ - if (e_pool[i].getenv == value) { + /* look for the 1st match */ + if (e_pool[i].getenv == value) { - /* found match, free the storage */ - if (e_pool[i].putenv != NULL) { - free(e_pool[i].putenv); - } - e_pool[i].getenv = NULL; - --env_pool_cnt; - break; - } - } - } + /* found match, free the storage */ + if (e_pool[i].putenv != NULL) { + free(e_pool[i].putenv); + } + e_pool[i].getenv = NULL; + --env_pool_cnt; + break; + } + } + } - /* - * ensure that we have room in the e_pool - */ - if (env_pool_max == 0) { + /* + * ensure that we have room in the e_pool + */ + if (env_pool_max == 0) { - /* allocate an initial pool (with one extra guard value) */ - new = (struct env_pool *)malloc((ENV_POOL_CHUNK+1) * - sizeof(struct env_pool)); - if (new == NULL) { - math_error("malloced_putenv malloc failed"); - not_reached(); - } - e_pool = new; - env_pool_max = ENV_POOL_CHUNK; - for (i=0; i <= ENV_POOL_CHUNK; ++i) { - e_pool[i].getenv = NULL; - } + /* allocate an initial pool (with one extra guard value) */ + new = (struct env_pool *)malloc((ENV_POOL_CHUNK+1) * + sizeof(struct env_pool)); + if (new == NULL) { + math_error("malloced_putenv malloc failed"); + not_reached(); + } + e_pool = new; + env_pool_max = ENV_POOL_CHUNK; + for (i=0; i <= ENV_POOL_CHUNK; ++i) { + e_pool[i].getenv = NULL; + } - } else if (env_pool_cnt >= env_pool_max) { + } else if (env_pool_cnt >= env_pool_max) { - /* expand the current pool (with one extra guard value) */ - new = (struct env_pool *)realloc(e_pool, - (env_pool_max+ENV_POOL_CHUNK+1) * - sizeof(struct env_pool)); - if (new == NULL) { - math_error("malloced_putenv realloc failed"); - not_reached(); - } - e_pool = new; - for (i=env_pool_max; i <= env_pool_max + ENV_POOL_CHUNK; ++i) { - e_pool[i].getenv = NULL; - } - env_pool_max += ENV_POOL_CHUNK; - } + /* expand the current pool (with one extra guard value) */ + new = (struct env_pool *)realloc(e_pool, + (env_pool_max+ENV_POOL_CHUNK+1) * + sizeof(struct env_pool)); + if (new == NULL) { + math_error("malloced_putenv realloc failed"); + not_reached(); + } + e_pool = new; + for (i=env_pool_max; i <= env_pool_max + ENV_POOL_CHUNK; ++i) { + e_pool[i].getenv = NULL; + } + env_pool_max += ENV_POOL_CHUNK; + } - /* - * store our data into the first e_pool entry - */ - for (i=0; i < env_pool_max; ++i) { + /* + * store our data into the first e_pool entry + */ + for (i=0; i < env_pool_max; ++i) { - /* skip used entries */ - if (e_pool[i].getenv != NULL) { - continue; - } + /* skip used entries */ + if (e_pool[i].getenv != NULL) { + continue; + } - /* store in this free entry and stop looping */ - e_pool[i].getenv = value; - e_pool[i].putenv = str; - ++env_pool_cnt; - break; - } - if (i >= env_pool_max) { - math_error("malloced_putenv missed unused entry!!"); - not_reached(); - } + /* store in this free entry and stop looping */ + e_pool[i].getenv = value; + e_pool[i].putenv = str; + ++env_pool_cnt; + break; + } + if (i >= env_pool_max) { + math_error("malloced_putenv missed unused entry!!"); + not_reached(); + } - /* - * finally, do the putenv action - */ - return putenv(str); + /* + * finally, do the putenv action + */ + return putenv(str); } diff --git a/func.h b/func.h index f35a58f..f601c17 100644 --- a/func.h +++ b/func.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:33 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:33 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,7 +28,7 @@ #define INCLUDE_FUNC_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "calc.h" # include "label.h" #else @@ -43,13 +43,13 @@ */ typedef struct func FUNC; struct func { - FUNC *f_next; /* next function in list */ - unsigned long f_opcodecount; /* size of opcode array */ - unsigned int f_localcount; /* number of local variables */ - unsigned int f_paramcount; /* max number of parameters */ - char *f_name; /* function name */ - VALUE f_savedvalue; /* saved value of last expression */ - unsigned long f_opcodes[1]; /* array of opcodes (variable length) */ + FUNC *f_next; /* next function in list */ + unsigned long f_opcodecount; /* size of opcode array */ + unsigned int f_localcount; /* number of local variables */ + unsigned int f_paramcount; /* max number of parameters */ + char *f_name; /* function name */ + VALUE f_savedvalue; /* saved value of last expression */ + unsigned long f_opcodes[1]; /* array of opcodes (variable length) */ }; @@ -68,7 +68,7 @@ struct func { /* * The current function being compiled. */ -E_FUNC FUNC *curfunc; /* NOTE: This is a function pointer, we need E_FUNC */ +E_FUNC FUNC *curfunc; /* NOTE: This is a function pointer, we need E_FUNC */ /* diff --git a/hash.c b/hash.c index fbccb06..304c29f 100644 --- a/hash.c +++ b/hash.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/11/23 05:13:11 - * File existed as early as: 1995 + * Under source code control: 1995/11/23 05:13:11 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -41,7 +41,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* @@ -65,11 +65,11 @@ E_FUNC void MD5_init_state(HASH*); * hash_setup - setup the hash state for a given hash */ STATIC struct hash_setup { - int type; /* hash type (see XYZ_HASH_TYPE below) */ - void (*init_state)(HASH*); /* initialize a hash state */ + int type; /* hash type (see XYZ_HASH_TYPE below) */ + void (*init_state)(HASH*); /* initialize a hash state */ } htbl[] = { - { SHA1_HASH_TYPE, sha1_init_state }, /* SHA-1 / SHA-1 */ - { -1, NULL } /* must be last */ + { SHA1_HASH_TYPE, sha1_init_state }, /* SHA-1 / SHA-1 */ + { -1, NULL } /* must be last */ }; @@ -77,60 +77,60 @@ STATIC struct hash_setup { * hash_init - initialize a hash state * * given: - * type - hash type (see hash.h) - * state - the state to initialize, or NULL to malloc it + * type - hash type (see hash.h) + * state - the state to initialize, or NULL to malloc it * * returns: - * initialized state + * initialized state */ HASH * hash_init(int type, HASH *state) { - int i; + int i; - /* - * malloc if needed - */ - if (state == NULL) { - state = (HASH *)malloc(sizeof(HASH)); - if (state == NULL) { - math_error("hash_init: cannot malloc HASH"); - not_reached(); - } - } + /* + * malloc if needed + */ + if (state == NULL) { + state = (HASH *)malloc(sizeof(HASH)); + if (state == NULL) { + math_error("hash_init: cannot malloc HASH"); + not_reached(); + } + } - /* - * clear hash value - */ - memset((void*)state, 0, sizeof(HASH)); - state->bytes = true; + /* + * clear hash value + */ + memset((void*)state, 0, sizeof(HASH)); + state->bytes = true; - /* - * search for the hash_setup function - */ - for (i=0; htbl[i].init_state != NULL; ++i) { + /* + * search for the hash_setup function + */ + for (i=0; htbl[i].init_state != NULL; ++i) { - /* if we found the state that we were looking for */ - if (type == htbl[i].type) { + /* if we found the state that we were looking for */ + if (type == htbl[i].type) { - /* initialize state and return */ - (htbl[i].init_state)(state); + /* initialize state and return */ + (htbl[i].init_state)(state); - /* firewall - MAX_CHUNKSIZE must be >= chunksize */ - if (state->chunksize > MAX_CHUNKSIZE) { - math_error( - "internal error: MAX_CHUNKSIZE is too small"); - not_reached(); - } - return state; - } - } + /* firewall - MAX_CHUNKSIZE must be >= chunksize */ + if (state->chunksize > MAX_CHUNKSIZE) { + math_error( + "internal error: MAX_CHUNKSIZE is too small"); + not_reached(); + } + return state; + } + } - /* - * no such hash state - */ - math_error("internal error: hash type not found in htbl[]"); - return NULL; + /* + * no such hash state + */ + math_error("internal error: hash type not found in htbl[]"); + return NULL; } @@ -140,18 +140,18 @@ hash_init(int type, HASH *state) void hash_free(HASH *state) { - /* - * do nothing if state is NULL - */ - if (state == NULL) { - return; - } + /* + * do nothing if state is NULL + */ + if (state == NULL) { + return; + } - /* - * free main state and return - */ - free(state); - return; + /* + * free main state and return + */ + free(state); + return; } @@ -159,30 +159,30 @@ hash_free(HASH *state) * hash_copy - copy a hash state * * given: - * state - the state to copy + * state - the state to copy * * returns: - * pointer to copy of state + * pointer to copy of state */ HASH * hash_copy(HASH *state) { - HASH *hnew; /* copy of state */ + HASH *hnew; /* copy of state */ - /* - * malloc new state - */ - hnew = (HASH *)malloc(sizeof(HASH)); - if (hnew == NULL) { - math_error("hash_init: cannot malloc HASH"); - not_reached(); - } + /* + * malloc new state + */ + hnew = (HASH *)malloc(sizeof(HASH)); + if (hnew == NULL) { + math_error("hash_init: cannot malloc HASH"); + not_reached(); + } - /* - * duplicate state - */ - memcpy((void *)hnew, (void *)state, sizeof(HASH)); - return hnew; + /* + * duplicate state + */ + memcpy((void *)hnew, (void *)state, sizeof(HASH)); + return hnew; } @@ -190,44 +190,44 @@ hash_copy(HASH *state) * hash_cmp - compare hash values * * given: - * a first hash state - * b second hash state + * a first hash state + * b second hash state * * returns: - * true => hash states are different - * false => hash states are the same + * true => hash states are different + * false => hash states are the same */ int hash_cmp(HASH *a, HASH *b) { - /* - * firewall and quick check - */ - if (a == b) { - /* pointers to the same object */ - return false; - } - if (a == NULL || b == NULL) { - /* one pointer is NULL, so they differ */ - return true; - } - if (a->cmp == NULL || b->cmp == NULL) { - /* one cmp function is NULL, so they differ */ - return true; - } + /* + * firewall and quick check + */ + if (a == b) { + /* pointers to the same object */ + return false; + } + if (a == NULL || b == NULL) { + /* one pointer is NULL, so they differ */ + return true; + } + if (a->cmp == NULL || b->cmp == NULL) { + /* one cmp function is NULL, so they differ */ + return true; + } - /* - * compare hash types - */ - if (a->hashtype != b->hashtype) { - /* different hash types are different */ - return true; - } + /* + * compare hash types + */ + if (a->hashtype != b->hashtype) { + /* different hash types are different */ + return true; + } - /* - * perform the hash specific comparison - */ - return ((a->cmp)(a,b)); + /* + * perform the hash specific comparison + */ + return ((a->cmp)(a,b)); } @@ -235,14 +235,14 @@ hash_cmp(HASH *a, HASH *b) * hash_print - print the name and value of a hash * * given: - * state the hash state to print name and value of + * state the hash state to print name and value of */ void hash_print(HASH *state) { - /* print the hash */ - (state->print)(state); - return; + /* print the hash */ + (state->print)(state); + return; } @@ -250,16 +250,16 @@ hash_print(HASH *state) * hash_final - finalize the state of a hash and return a ZVALUE * * given: - * state the hash state to finalize + * state the hash state to finalize * * returns: - * hash state as a ZVALUE + * hash state as a ZVALUE */ ZVALUE hash_final(HASH *state) { - /* return the finalized the hash value */ - return (state->final)(state); + /* return the finalized the hash value */ + return (state->final)(state); } @@ -267,15 +267,15 @@ hash_final(HASH *state) * hash_long - note a long value * * given: - * type - hash type (see hash.h) - * longval - a long value - * state - the state to hash + * type - hash type (see hash.h) + * longval - a long value + * state - the state to hash * * returns: - * the new state + * the new state * * This function will hash a long value as if it were a 64 bit value. - * The input is a long. If a long is smaller than 64 bits, we will + * The input is a long. If a long is smaller than 64 bits, we will * hash a final 32 bits of zeros. * * This function is OK to hash bool's, unsigned long's, unsigned int's @@ -284,46 +284,46 @@ hash_final(HASH *state) HASH * hash_long(int type, long longval, HASH *state) { - long lval[64/LONG_BITS]; /* 64 bits of longs */ + long lval[64/LONG_BITS]; /* 64 bits of longs */ - /* - * initialize if state is NULL - */ - if (state == NULL) { - state = hash_init(type, NULL); - } + /* + * initialize if state is NULL + */ + if (state == NULL) { + state = hash_init(type, NULL); + } - /* - * setup for the hash_long - */ - (state->chkpt)(state); - state->bytes = false; /* data to be read as words */ + /* + * setup for the hash_long + */ + (state->chkpt)(state); + state->bytes = false; /* data to be read as words */ - /* - * catch the zero numeric value special case - */ - if (longval == 0) { - /* note a zero numeric value and return */ - (state->note)(HASH_ZERO(state->base), state); - return state; - } + /* + * catch the zero numeric value special case + */ + if (longval == 0) { + /* note a zero numeric value and return */ + (state->note)(HASH_ZERO(state->base), state); + return state; + } - /* - * prep for a long value hash - */ - (state->note)(state->base, state); + /* + * prep for a long value hash + */ + (state->note)(state->base, state); - /* - * hash as if we have a 64 bit value - */ - memset((char *)lval, 0, sizeof(lval)); - lval[0] = longval; - (state->update)(state, (USB8 *)lval, sizeof(lval)); + /* + * hash as if we have a 64 bit value + */ + memset((char *)lval, 0, sizeof(lval)); + lval[0] = longval; + (state->update)(state, (USB8 *)lval, sizeof(lval)); - /* - * all done - */ - return state; + /* + * all done + */ + return state; } @@ -331,127 +331,127 @@ hash_long(int type, long longval, HASH *state) * hash_zvalue - hash a ZVALUE * * given: - * type - hash type (see hash.h) - * zval - the ZVALUE - * state - the state to hash or NULL + * type - hash type (see hash.h) + * zval - the ZVALUE + * state - the state to hash or NULL * * returns: - * the new state + * the new state */ HASH * hash_zvalue(int type, ZVALUE zval, HASH *state) { #if CALC_BYTE_ORDER == BIG_ENDIAN && BASEB == 16 - int full_lim; /* HALFs in whole chunks in zval */ - int chunkhalf; /* size of half buffer in HALFs */ - int i; - int j; + int full_lim; /* HALFs in whole chunks in zval */ + int chunkhalf; /* size of half buffer in HALFs */ + int i; + int j; #endif #if BASEB == 16 - HALF half[MAX_CHUNKSIZE]; /* For endian reversal */ + HALF half[MAX_CHUNKSIZE]; /* For endian reversal */ #endif - /* - * initialize if state is NULL - */ - if (state == NULL) { - state = hash_init(type, NULL); - } + /* + * initialize if state is NULL + */ + if (state == NULL) { + state = hash_init(type, NULL); + } - /* - * setup for the ZVALUE hash - */ - (state->chkpt)(state); - state->bytes = false; /* data to be read as words */ + /* + * setup for the ZVALUE hash + */ + (state->chkpt)(state); + state->bytes = false; /* data to be read as words */ - /* - * catch the zero numeric value special case - */ - if (ziszero(zval)) { - /* note a zero numeric value and return */ - (state->note)(HASH_ZERO(state->base), state); - return state; - } + /* + * catch the zero numeric value special case + */ + if (ziszero(zval)) { + /* note a zero numeric value and return */ + (state->note)(HASH_ZERO(state->base), state); + return state; + } - /* - * prep for a ZVALUE hash - */ - (state->note)(HASH_ZVALUE(state->base), state); - /* note if we have a negative value */ - if (zisneg(zval)) { - (state->note)(HASH_NEG(state->base), state); - } + /* + * prep for a ZVALUE hash + */ + (state->note)(HASH_ZVALUE(state->base), state); + /* note if we have a negative value */ + if (zisneg(zval)) { + (state->note)(HASH_NEG(state->base), state); + } #if CALC_BYTE_ORDER == BIG_ENDIAN && BASEB == 16 - /* - * hash full chunks - * - * We need to convert the array of HALFs into canonical architectural - * independent form -- 32 bit arrays. Because we have 16 bit values - * in Big Endian form, we need to swap 16 bit values so that they - * appear as 32 bit Big Endian values. - */ - chunkhalf = state->chunksize/sizeof(HALF); - full_lim = (zval.len / chunkhalf) * chunkhalf; - for (i=0; i < full_lim; i += chunkhalf) { - /* HALF swap copy a chunk into a data buffer */ - for (j=0; j < chunkhalf; j += 2) { - half[j] = zval.v[i+j+1]; - half[j+1] = zval.v[i+j]; - } - (state->update)(state, (USB8*) half, state->chunksize); - } + /* + * hash full chunks + * + * We need to convert the array of HALFs into canonical architectural + * independent form -- 32 bit arrays. Because we have 16 bit values + * in Big Endian form, we need to swap 16 bit values so that they + * appear as 32 bit Big Endian values. + */ + chunkhalf = state->chunksize/sizeof(HALF); + full_lim = (zval.len / chunkhalf) * chunkhalf; + for (i=0; i < full_lim; i += chunkhalf) { + /* HALF swap copy a chunk into a data buffer */ + for (j=0; j < chunkhalf; j += 2) { + half[j] = zval.v[i+j+1]; + half[j+1] = zval.v[i+j]; + } + (state->update)(state, (USB8*) half, state->chunksize); + } - /* - * hash the final partial chunk (if any) - * - * We need to convert the array of HALFs into canonical architectural - * independent form -- 32 bit arrays. Because we have 16 bit values - * in Big Endian form, we need to swap 16 bit values so that they - * appear as 32 bit Big Endian values. - */ - if (zval.len > full_lim) { - for (j=0; j < zval.len-full_lim-1; j += 2) { - half[j] = zval.v[full_lim+j+1]; - half[j+1] = zval.v[full_lim+j]; - } - if (j < zval.len-full_lim) { - half[j] = (HALF)0; - half[j+1] = zval.v[zval.len-1]; - --full_lim; - } - (state->update)(state, (USB8 *) half, - (zval.len-full_lim)*sizeof(HALF)); - } + /* + * hash the final partial chunk (if any) + * + * We need to convert the array of HALFs into canonical architectural + * independent form -- 32 bit arrays. Because we have 16 bit values + * in Big Endian form, we need to swap 16 bit values so that they + * appear as 32 bit Big Endian values. + */ + if (zval.len > full_lim) { + for (j=0; j < zval.len-full_lim-1; j += 2) { + half[j] = zval.v[full_lim+j+1]; + half[j+1] = zval.v[full_lim+j]; + } + if (j < zval.len-full_lim) { + half[j] = (HALF)0; + half[j+1] = zval.v[zval.len-1]; + --full_lim; + } + (state->update)(state, (USB8 *) half, + (zval.len-full_lim)*sizeof(HALF)); + } #else - /* - * hash the array of HALFs - * - * The array of HALFs is equivalent to the canonical architectural - * independent form. We either have 32 bit HALFs (in which case - * we do not case the byte order) or we have 16 bit HALFs in Little - * Endian order (which happens to be laid out in the same order as - * 32 bit values). - */ - (state->update)(state, (USB8 *)zval.v, zval.len*sizeof(HALF)); + /* + * hash the array of HALFs + * + * The array of HALFs is equivalent to the canonical architectural + * independent form. We either have 32 bit HALFs (in which case + * we do not case the byte order) or we have 16 bit HALFs in Little + * Endian order (which happens to be laid out in the same order as + * 32 bit values). + */ + (state->update)(state, (USB8 *)zval.v, zval.len*sizeof(HALF)); #if BASEB == 16 - if (zval.len & 1) { /* padding to complete word */ - half[0] = 0; - (state->update)(state, (USB8 *) half, 2); - } + if (zval.len & 1) { /* padding to complete word */ + half[0] = 0; + (state->update)(state, (USB8 *) half, 2); + } #endif #endif - /* - * all done - */ - return state; + /* + * all done + */ + return state; } @@ -459,60 +459,60 @@ hash_zvalue(int type, ZVALUE zval, HASH *state) * hash_number - hash a NUMBER * * given: - * type - hash type (see hash.h) - * n - the NUMBER - * state - the state to hash or NULL + * type - hash type (see hash.h) + * n - the NUMBER + * state - the state to hash or NULL * * returns: - * the new state + * the new state */ HASH * hash_number(int type, void *n, HASH *state) { - NUMBER *number = (NUMBER *)n; /* n as a NUMBER pointer */ - bool sign; /* sign of the denominator */ + NUMBER *number = (NUMBER *)n; /* n as a NUMBER pointer */ + bool sign; /* sign of the denominator */ - /* - * initialize if state is NULL - */ - if (state == NULL) { - state = hash_init(type, NULL); - } + /* + * initialize if state is NULL + */ + if (state == NULL) { + state = hash_init(type, NULL); + } - /* - * setup for the NUMBER hash - */ - (state->chkpt)(state); - state->bytes = false; + /* + * setup for the NUMBER hash + */ + (state->chkpt)(state); + state->bytes = false; - /* - * process the numerator - */ - state = hash_zvalue(type, number->num, state); + /* + * process the numerator + */ + state = hash_zvalue(type, number->num, state); - /* - * if the NUMBER is not an integer, process the denominator - */ - if (qisfrac(number)) { + /* + * if the NUMBER is not an integer, process the denominator + */ + if (qisfrac(number)) { - /* note the division */ - (state->note)(HASH_DIV(state->base), state); + /* note the division */ + (state->note)(HASH_DIV(state->base), state); - /* hash denominator as positive -- just in case */ - sign = number->den.sign; - number->den.sign = 0; + /* hash denominator as positive -- just in case */ + sign = number->den.sign; + number->den.sign = 0; - /* hash the denominator */ - state = hash_zvalue(type, number->den, state); + /* hash the denominator */ + state = hash_zvalue(type, number->den, state); - /* restore the sign */ - number->den.sign = sign; - } + /* restore the sign */ + number->den.sign = sign; + } - /* - * all done - */ - return state; + /* + * all done + */ + return state; } @@ -520,67 +520,67 @@ hash_number(int type, void *n, HASH *state) * hash_complex - hash a COMPLEX * * given: - * type - hash type (see hash.h) - * c - the COMPLEX - * state - the state to hash or NULL + * type - hash type (see hash.h) + * c - the COMPLEX + * state - the state to hash or NULL * * returns: - * the new state + * the new state */ HASH * hash_complex(int type, void *c, HASH *state) { - COMPLEX *complex = (COMPLEX *)c; /* c as a COMPLEX pointer */ + COMPLEX *complex = (COMPLEX *)c; /* c as a COMPLEX pointer */ - /* - * initialize if state is NULL - */ - if (state == NULL) { - state = hash_init(type, NULL); - } + /* + * initialize if state is NULL + */ + if (state == NULL) { + state = hash_init(type, NULL); + } - /* - * setup for the COMPLEX hash - */ - (state->chkpt)(state); - state->bytes = false; + /* + * setup for the COMPLEX hash + */ + (state->chkpt)(state); + state->bytes = false; - /* - * catch the zero special case - */ - if (ciszero(complex)) { - /* note a zero numeric value and return */ - (state->note)(HASH_ZERO(state->base), state); - return state; - } + /* + * catch the zero special case + */ + if (ciszero(complex)) { + /* note a zero numeric value and return */ + (state->note)(HASH_ZERO(state->base), state); + return state; + } - /* - * process the real value if not pure imaginary - * - * We will ignore the real part if the value is of the form 0+xi. - */ - if (!qiszero(complex->real)) { - state = hash_number(type, complex->real, state); - } + /* + * process the real value if not pure imaginary + * + * We will ignore the real part if the value is of the form 0+xi. + */ + if (!qiszero(complex->real)) { + state = hash_number(type, complex->real, state); + } - /* - * if the NUMBER is not real, process the imaginary value - * - * We will ignore the imaginary part of the value is of the form x+0i. - */ - if (!cisreal(complex)) { + /* + * if the NUMBER is not real, process the imaginary value + * + * We will ignore the imaginary part of the value is of the form x+0i. + */ + if (!cisreal(complex)) { - /* note the sqrt(-1) */ - (state->note)(HASH_COMPLEX(state->base), state); + /* note the sqrt(-1) */ + (state->note)(HASH_COMPLEX(state->base), state); - /* hash the imaginary value */ - state = hash_number(type, complex->imag, state); - } + /* hash the imaginary value */ + state = hash_number(type, complex->imag, state); + } - /* - * all done - */ - return state; + /* + * all done + */ + return state; } @@ -588,44 +588,44 @@ hash_complex(int type, void *c, HASH *state) * hash_str - hash a null-terminated string * * given: - * type - hash type (see hash.h) - * str - the string - * state - the state to hash or NULL + * type - hash type (see hash.h) + * str - the string + * state - the state to hash or NULL * * returns: - * the new state + * the new state */ HASH * hash_str(int type, char *str, HASH *state) { - size_t len; /* string length */ + size_t len; /* string length */ - /* - * initialize if state is NULL - */ - if (state == NULL) { - state = hash_init(type, NULL); - } + /* + * initialize if state is NULL + */ + if (state == NULL) { + state = hash_init(type, NULL); + } - /* - * setup for the string hash - */ - if (!state->bytes) { - (state->chkpt)(state); - state->bytes = true; - } + /* + * setup for the string hash + */ + if (!state->bytes) { + (state->chkpt)(state); + state->bytes = true; + } - len = strlen(str); + len = strlen(str); - /* - * hash the string - */ - (state->update)(state, (USB8*)str, len); + /* + * hash the string + */ + (state->update)(state, (USB8*)str, len); - /* - * all done - */ - return state; + /* + * all done + */ + return state; } @@ -633,40 +633,40 @@ hash_str(int type, char *str, HASH *state) * hash_STR - hash a STRING * * given: - * type - hash type (see hash.h) - * str - the STRING - * state - the state to hash or NULL + * type - hash type (see hash.h) + * str - the STRING + * state - the state to hash or NULL * * returns: - * the new state + * the new state */ HASH * hash_STR(int type, STRING *str, HASH *state) { - /* - * initialize if state is NULL - */ - if (state == NULL) { - state = hash_init(type, NULL); - } + /* + * initialize if state is NULL + */ + if (state == NULL) { + state = hash_init(type, NULL); + } - /* - * setup for the string hash - */ - if (!state->bytes) { - (state->chkpt)(state); - state->bytes = true; - } + /* + * setup for the string hash + */ + if (!state->bytes) { + (state->chkpt)(state); + state->bytes = true; + } - /* - * hash the string - */ - (state->update)(state, (USB8*) str->s_str, (USB32) str->s_len); + /* + * hash the string + */ + (state->update)(state, (USB8*) str->s_str, (USB32) str->s_len); - /* - * all done - */ - return state; + /* + * all done + */ + return state; } @@ -674,41 +674,41 @@ hash_STR(int type, STRING *str, HASH *state) * hash_usb8 - hash an array of USB8s * * given: - * type - hash type (see hash.h) - * byte - pointer to an array of USB8s - * len - number of USB8s to hash - * state - the state to hash or NULL + * type - hash type (see hash.h) + * byte - pointer to an array of USB8s + * len - number of USB8s to hash + * state - the state to hash or NULL * * returns: - * the new state + * the new state */ HASH * hash_usb8(int type, USB8 *byte, int len, HASH *state) { - /* - * initialize if state is NULL - */ - if (state == NULL) { - state = hash_init(type, NULL); - } + /* + * initialize if state is NULL + */ + if (state == NULL) { + state = hash_init(type, NULL); + } - /* - * setup for the string hash - */ - if (!state->bytes) { - (state->chkpt)(state); - state->bytes = true; - } + /* + * setup for the string hash + */ + if (!state->bytes) { + (state->chkpt)(state); + state->bytes = true; + } - /* - * hash the array of octets - */ - (state->update)(state, byte, (USB32)len); + /* + * hash the array of octets + */ + (state->update)(state, byte, (USB32)len); - /* - * all done - */ - return state; + /* + * all done + */ + return state; } @@ -716,343 +716,343 @@ hash_usb8(int type, USB8 *byte, int len, HASH *state) * hash_value - hash a value * * given: - * type - hash type (see hash.h) - * v - the value - * state - the state to hash or NULL + * type - hash type (see hash.h) + * v - the value + * state - the state to hash or NULL * * returns: - * the new state + * the new state */ HASH * hash_value(int type, void *v, HASH *state) { - LISTELEM *ep; /* list element pointer */ - ASSOCELEM **assochead; /* association chain head */ - ASSOCELEM *aep; /* current association value */ - ASSOCELEM *nextaep; /* next association value */ - VALUE *value = (VALUE *)v; /* v cast to a VALUE */ - VALUE *vp; /* pointer to next OBJ table value */ - ZVALUE fileval; /* size, position, dev, inode of a file */ - int i; + LISTELEM *ep; /* list element pointer */ + ASSOCELEM **assochead; /* association chain head */ + ASSOCELEM *aep; /* current association value */ + ASSOCELEM *nextaep; /* next association value */ + VALUE *value = (VALUE *)v; /* v cast to a VALUE */ + VALUE *vp; /* pointer to next OBJ table value */ + ZVALUE fileval; /* size, position, dev, inode of a file */ + int i; - /* - * initialize if state is NULL - */ - if (state == NULL) { - state = hash_init(type, NULL); - } + /* + * initialize if state is NULL + */ + if (state == NULL) { + state = hash_init(type, NULL); + } - /* - * process the value type - */ - switch (value->v_type) { - case V_NULL: - (state->chkpt)(state); - state->bytes = true; - break; + /* + * process the value type + */ + switch (value->v_type) { + case V_NULL: + (state->chkpt)(state); + state->bytes = true; + break; - case V_INT: - /* setup for the this value type */ - (state->chkpt)(state); - (state->type)(value->v_type, state); + case V_INT: + /* setup for the this value type */ + (state->chkpt)(state); + (state->type)(value->v_type, state); - /* hash as if we have a 64 bit value */ - state = hash_int(type, value->v_int, state); - break; + /* hash as if we have a 64 bit value */ + state = hash_int(type, value->v_int, state); + break; - case V_NUM: - /* hash this type */ - state = hash_number(type, value->v_num, state); - break; + case V_NUM: + /* hash this type */ + state = hash_number(type, value->v_num, state); + break; - case V_COM: - /* setup for the this value type */ - (state->chkpt)(state); - (state->type)(value->v_type, state); + case V_COM: + /* setup for the this value type */ + (state->chkpt)(state); + (state->type)(value->v_type, state); - /* hash this type */ - state = hash_complex(type, value->v_com, state); - break; + /* hash this type */ + state = hash_complex(type, value->v_com, state); + break; - case V_ADDR: - /* there is nothing to setup, simply hash what we point at */ - state = hash_value(type, value->v_addr, state); - break; + case V_ADDR: + /* there is nothing to setup, simply hash what we point at */ + state = hash_value(type, value->v_addr, state); + break; - case V_STR: - /* strings have no setup */ + case V_STR: + /* strings have no setup */ - /* hash this type */ - state = hash_STR(type, value->v_str, state); - break; + /* hash this type */ + state = hash_STR(type, value->v_str, state); + break; - case V_MAT: - /* setup for the this value type */ - (state->chkpt)(state); - (state->type)(value->v_type, state); - state->bytes = true; + case V_MAT: + /* setup for the this value type */ + (state->chkpt)(state); + (state->type)(value->v_type, state); + state->bytes = true; - /* hash all the elements of the matrix */ - for (i=0; i < value->v_mat->m_size; ++i) { + /* hash all the elements of the matrix */ + for (i=0; i < value->v_mat->m_size; ++i) { - /* hash the next matrix value */ - state = hash_value(type, - value->v_mat->m_table+i, state); - state->bytes = false; /* as if reading words */ - } - break; + /* hash the next matrix value */ + state = hash_value(type, + value->v_mat->m_table+i, state); + state->bytes = false; /* as if reading words */ + } + break; - case V_LIST: - /* setup for the this value type */ - (state->chkpt)(state); - (state->type)(value->v_type, state); + case V_LIST: + /* setup for the this value type */ + (state->chkpt)(state); + (state->type)(value->v_type, state); - /* hash all the elements of the list */ - for (i=0, ep = value->v_list->l_first; - ep != NULL && i < value->v_list->l_count; - ++i, ep = ep->e_next) { + /* hash all the elements of the list */ + for (i=0, ep = value->v_list->l_first; + ep != NULL && i < value->v_list->l_count; + ++i, ep = ep->e_next) { - /* hash the next list value */ - state = hash_value(type, &ep->e_value, state); - state->bytes = false; /* as if reading words */ - } - break; + /* hash the next list value */ + state = hash_value(type, &ep->e_value, state); + state->bytes = false; /* as if reading words */ + } + break; - case V_ASSOC: - /* setup for the this value type */ - (state->chkpt)(state); - (state->type)(value->v_type, state); - state->bytes = true; + case V_ASSOC: + /* setup for the this value type */ + (state->chkpt)(state); + (state->type)(value->v_type, state); + state->bytes = true; - /* hash the association */ - assochead = value->v_assoc->a_table; - for (i = 0; i < value->v_assoc->a_size; i++) { - nextaep = *assochead; - while (nextaep) { - aep = nextaep; - nextaep = aep->e_next; + /* hash the association */ + assochead = value->v_assoc->a_table; + for (i = 0; i < value->v_assoc->a_size; i++) { + nextaep = *assochead; + while (nextaep) { + aep = nextaep; + nextaep = aep->e_next; - /* hash the next association value */ - state = hash_value(type, &aep->e_value, state); - state->bytes = false; /* as if reading words */ - } - assochead++; - } - break; + /* hash the next association value */ + state = hash_value(type, &aep->e_value, state); + state->bytes = false; /* as if reading words */ + } + assochead++; + } + break; - case V_OBJ: - /* setup for the this value type */ - (state->chkpt)(state); - (state->type)(value->v_type, state); - state->bytes = true; /* reading bytes */ + case V_OBJ: + /* setup for the this value type */ + (state->chkpt)(state); + (state->type)(value->v_type, state); + state->bytes = true; /* reading bytes */ - /* hash the object name and then the element values */ + /* hash the object name and then the element values */ - state = hash_str(type, objtypename( - value->v_obj->o_actions->oa_index), state); - (state->chkpt)(state); + state = hash_str(type, objtypename( + value->v_obj->o_actions->oa_index), state); + (state->chkpt)(state); - for (i=value->v_obj->o_actions->oa_count, - vp=value->v_obj->o_table; - i-- > 0; - vp++) { + for (i=value->v_obj->o_actions->oa_count, + vp=value->v_obj->o_table; + i-- > 0; + vp++) { - /* hash the next object value */ - state = hash_value(type, vp, state); - state->bytes = false; /* as if reading words */ - } - break; + /* hash the next object value */ + state = hash_value(type, vp, state); + state->bytes = false; /* as if reading words */ + } + break; - case V_FILE: - /* setup for the this value type */ - (state->chkpt)(state); - (state->type)(value->v_type, state); + case V_FILE: + /* setup for the this value type */ + (state->chkpt)(state); + (state->type)(value->v_type, state); - /* hash file length if possible */ - if (getsize(value->v_file, &fileval) == 0) { - state = hash_zvalue(type, fileval, state); - zfree(fileval); - } else { - /* hash -1 for invalid length */ - state = hash_long(type, (long)-1, state); - } - /* hash the file position if possible */ - if (getloc(value->v_file, &fileval) == 0) { - state = hash_zvalue(type, fileval, state); - zfree(fileval); - } else { - /* hash -1 for invalid location */ - state = hash_long(type, (long)-1, state); - } - /* hash the file device if possible */ - if (get_device(value->v_file, &fileval) == 0) { - state = hash_zvalue(type, fileval, state); - zfree(fileval); - } else { - /* hash -1 for invalid device */ - state = hash_long(type, (long)-1, state); - } - /* hash the file inode if possible */ - if (get_inode(value->v_file, &fileval) == 0) { - state = hash_zvalue(type, fileval, state); - zfree(fileval); - } else { - /* hash -1 for invalid inode */ - state = hash_long(type, (long)-1, state); - } - break; + /* hash file length if possible */ + if (getsize(value->v_file, &fileval) == 0) { + state = hash_zvalue(type, fileval, state); + zfree(fileval); + } else { + /* hash -1 for invalid length */ + state = hash_long(type, (long)-1, state); + } + /* hash the file position if possible */ + if (getloc(value->v_file, &fileval) == 0) { + state = hash_zvalue(type, fileval, state); + zfree(fileval); + } else { + /* hash -1 for invalid location */ + state = hash_long(type, (long)-1, state); + } + /* hash the file device if possible */ + if (get_device(value->v_file, &fileval) == 0) { + state = hash_zvalue(type, fileval, state); + zfree(fileval); + } else { + /* hash -1 for invalid device */ + state = hash_long(type, (long)-1, state); + } + /* hash the file inode if possible */ + if (get_inode(value->v_file, &fileval) == 0) { + state = hash_zvalue(type, fileval, state); + zfree(fileval); + } else { + /* hash -1 for invalid inode */ + state = hash_long(type, (long)-1, state); + } + break; - case V_RAND: - /* setup for the this value type */ - (state->chkpt)(state); - (state->type)(value->v_type, state); + case V_RAND: + /* setup for the this value type */ + (state->chkpt)(state); + (state->type)(value->v_type, state); - /* hash the RAND state */ - state = hash_int(type, value->v_rand->seeded, state); - state = hash_int(type, value->v_rand->bits, state); - (state->update)(state, - (USB8 *)value->v_rand->buffer, SLEN*FULL_BITS/8); - state = hash_int(type, value->v_rand->j, state); - state = hash_int(type, value->v_rand->k, state); - state = hash_int(type, value->v_rand->need_to_skip, state); - (state->update)(state, - (USB8 *)value->v_rand->slot, SCNT*FULL_BITS/8); - (state->update)(state, - (USB8*)value->v_rand->shuf, SHUFLEN*FULL_BITS/8); - state->bytes = false; /* as if reading words */ - break; + /* hash the RAND state */ + state = hash_int(type, value->v_rand->seeded, state); + state = hash_int(type, value->v_rand->bits, state); + (state->update)(state, + (USB8 *)value->v_rand->buffer, SLEN*FULL_BITS/8); + state = hash_int(type, value->v_rand->j, state); + state = hash_int(type, value->v_rand->k, state); + state = hash_int(type, value->v_rand->need_to_skip, state); + (state->update)(state, + (USB8 *)value->v_rand->slot, SCNT*FULL_BITS/8); + (state->update)(state, + (USB8*)value->v_rand->shuf, SHUFLEN*FULL_BITS/8); + state->bytes = false; /* as if reading words */ + break; - case V_RANDOM: - /* setup for the this value type */ - (state->chkpt)(state); - (state->type)(value->v_type, state); + case V_RANDOM: + /* setup for the this value type */ + (state->chkpt)(state); + (state->type)(value->v_type, state); - /* hash the RANDOM state */ - state = hash_int(type, value->v_random->seeded, state); - state = hash_int(type, value->v_random->bits, state); - (state->update)(state, - (USB8 *)&(value->v_random->buffer), BASEB/8); - state = hash_zvalue(type, value->v_random->r, state); - state = hash_zvalue(type, value->v_random->n, state); - state->bytes = false; /* as if reading words */ - break; + /* hash the RANDOM state */ + state = hash_int(type, value->v_random->seeded, state); + state = hash_int(type, value->v_random->bits, state); + (state->update)(state, + (USB8 *)&(value->v_random->buffer), BASEB/8); + state = hash_zvalue(type, value->v_random->r, state); + state = hash_zvalue(type, value->v_random->n, state); + state->bytes = false; /* as if reading words */ + break; - case V_CONFIG: - /* setup for the this value type */ - (state->chkpt)(state); - (state->type)(value->v_type, state); + case V_CONFIG: + /* setup for the this value type */ + (state->chkpt)(state); + (state->type)(value->v_type, state); - /* hash the CONFIG state */ - state = hash_int(type, value->v_config->outmode, state); - state = hash_int(type, value->v_config->outmode2, state); - state = hash_long(type,(long)value->v_config->outdigits, state); - state = hash_number(type, value->v_config->epsilon, state); - state = hash_long(type, - (long)value->v_config->epsilonprec, state); - state = hash_flag(type, value->v_config->traceflags, state); - state = hash_long(type, (long)value->v_config->maxprint, state); - state = hash_len(type, value->v_config->mul2, state); - state = hash_len(type, value->v_config->sq2, state); - state = hash_len(type, value->v_config->pow2, state); - state = hash_len(type, value->v_config->redc2, state); - state = hash_bool(type, value->v_config->tilde_ok, state); - state = hash_bool(type, value->v_config->tilde_space, state); - state = hash_bool(type, value->v_config->tab_ok, state); - state = hash_long(type, (long)value->v_config->quomod, state); - state = hash_long(type, (long)value->v_config->quo, state); - state = hash_long(type, (long)value->v_config->mod, state); - state = hash_long(type, (long)value->v_config->sqrt, state); - state = hash_long(type, (long)value->v_config->appr, state); - state = hash_long(type, (long)value->v_config->cfappr, state); - state = hash_long(type, (long)value->v_config->cfsim, state); - state = hash_long(type, (long)value->v_config->outround, state); - state = hash_long(type, (long)value->v_config->round, state); - state = hash_long(type, (long)value->v_config->triground, state); - state = hash_bool(type, value->v_config->leadzero, state); - state = hash_bool(type, value->v_config->fullzero, state); - state = hash_long(type, - (long)value->v_config->maxscancount, state); - state = hash_str(type, value->v_config->prompt1, state); - state->bytes = false; /* as if just read words */ - state = hash_str(type, value->v_config->prompt2, state); - state->bytes = false; /* as if just read words */ - state = hash_int(type, value->v_config->blkmaxprint, state); - state = hash_bool(type, value->v_config->blkverbose, state); - state = hash_int(type, value->v_config->blkbase, state); - state = hash_int(type, value->v_config->blkfmt, state); - state = hash_long(type, - (long)value->v_config->resource_debug, state); - state = hash_long(type, - (long)value->v_config->calc_debug, state); - state = hash_long(type, - (long)value->v_config->user_debug, state); - state = hash_bool(type, value->v_config->verbose_quit, state); - state = hash_int(type, value->v_config->ctrl_d, state); - state = hash_str(type, value->v_config->program, state); - state = hash_str(type, value->v_config->base_name, state); - state = hash_bool(type, value->v_config->windows, state); - state = hash_bool(type, value->v_config->cygwin, state); - state = hash_bool(type, value->v_config->compile_custom, state); - if (value->v_config->allow_custom != NULL && - *(value->v_config->allow_custom)) { - state = hash_bool(type, true, state); - } else { - state = hash_bool(type, false, state); - } - state = hash_str(type, value->v_config->version, state); - state = hash_int(type, value->v_config->baseb, state); - state = hash_bool(type, value->v_config->redecl_warn, state); - state = hash_bool(type, value->v_config->dupvar_warn, state); - state = hash_bool(type, value->v_config->fraction_space, state); - break; + /* hash the CONFIG state */ + state = hash_int(type, value->v_config->outmode, state); + state = hash_int(type, value->v_config->outmode2, state); + state = hash_long(type,(long)value->v_config->outdigits, state); + state = hash_number(type, value->v_config->epsilon, state); + state = hash_long(type, + (long)value->v_config->epsilonprec, state); + state = hash_flag(type, value->v_config->traceflags, state); + state = hash_long(type, (long)value->v_config->maxprint, state); + state = hash_len(type, value->v_config->mul2, state); + state = hash_len(type, value->v_config->sq2, state); + state = hash_len(type, value->v_config->pow2, state); + state = hash_len(type, value->v_config->redc2, state); + state = hash_bool(type, value->v_config->tilde_ok, state); + state = hash_bool(type, value->v_config->tilde_space, state); + state = hash_bool(type, value->v_config->tab_ok, state); + state = hash_long(type, (long)value->v_config->quomod, state); + state = hash_long(type, (long)value->v_config->quo, state); + state = hash_long(type, (long)value->v_config->mod, state); + state = hash_long(type, (long)value->v_config->sqrt, state); + state = hash_long(type, (long)value->v_config->appr, state); + state = hash_long(type, (long)value->v_config->cfappr, state); + state = hash_long(type, (long)value->v_config->cfsim, state); + state = hash_long(type, (long)value->v_config->outround, state); + state = hash_long(type, (long)value->v_config->round, state); + state = hash_long(type, (long)value->v_config->triground, state); + state = hash_bool(type, value->v_config->leadzero, state); + state = hash_bool(type, value->v_config->fullzero, state); + state = hash_long(type, + (long)value->v_config->maxscancount, state); + state = hash_str(type, value->v_config->prompt1, state); + state->bytes = false; /* as if just read words */ + state = hash_str(type, value->v_config->prompt2, state); + state->bytes = false; /* as if just read words */ + state = hash_int(type, value->v_config->blkmaxprint, state); + state = hash_bool(type, value->v_config->blkverbose, state); + state = hash_int(type, value->v_config->blkbase, state); + state = hash_int(type, value->v_config->blkfmt, state); + state = hash_long(type, + (long)value->v_config->resource_debug, state); + state = hash_long(type, + (long)value->v_config->calc_debug, state); + state = hash_long(type, + (long)value->v_config->user_debug, state); + state = hash_bool(type, value->v_config->verbose_quit, state); + state = hash_int(type, value->v_config->ctrl_d, state); + state = hash_str(type, value->v_config->program, state); + state = hash_str(type, value->v_config->base_name, state); + state = hash_bool(type, value->v_config->windows, state); + state = hash_bool(type, value->v_config->cygwin, state); + state = hash_bool(type, value->v_config->compile_custom, state); + if (value->v_config->allow_custom != NULL && + *(value->v_config->allow_custom)) { + state = hash_bool(type, true, state); + } else { + state = hash_bool(type, false, state); + } + state = hash_str(type, value->v_config->version, state); + state = hash_int(type, value->v_config->baseb, state); + state = hash_bool(type, value->v_config->redecl_warn, state); + state = hash_bool(type, value->v_config->dupvar_warn, state); + state = hash_bool(type, value->v_config->fraction_space, state); + break; - case V_HASH: - /* setup for the this value type */ - (state->chkpt)(state); - (state->type)(value->v_type, state); + case V_HASH: + /* setup for the this value type */ + (state->chkpt)(state); + (state->type)(value->v_type, state); - /* hash the HASH state */ - state = hash_int(type, value->v_hash->type, state); - state = hash_bool(type, value->v_hash->bytes,state); - state = hash_int(type, value->v_hash->base, state); - state = hash_int(type, value->v_hash->chunksize, state); - state = hash_int(type, value->v_hash->unionsize, state); - (state->update)(state, - value->v_hash->h_union.data, state->unionsize); - state->bytes = false; /* as if reading words */ - break; + /* hash the HASH state */ + state = hash_int(type, value->v_hash->type, state); + state = hash_bool(type, value->v_hash->bytes,state); + state = hash_int(type, value->v_hash->base, state); + state = hash_int(type, value->v_hash->chunksize, state); + state = hash_int(type, value->v_hash->unionsize, state); + (state->update)(state, + value->v_hash->h_union.data, state->unionsize); + state->bytes = false; /* as if reading words */ + break; - case V_BLOCK: - /* there is no setup for a BLOCK */ + case V_BLOCK: + /* there is no setup for a BLOCK */ - /* hash the octets in the BLOCK */ - if (value->v_block->datalen > 0) { - state = hash_usb8(type, value->v_block->data, - value->v_block->datalen, state); - } - break; + /* hash the octets in the BLOCK */ + if (value->v_block->datalen > 0) { + state = hash_usb8(type, value->v_block->data, + value->v_block->datalen, state); + } + break; - case V_OCTET: - /* there is no setup for an OCTET */ + case V_OCTET: + /* there is no setup for an OCTET */ - /* hash the OCTET */ - state = hash_usb8(type, value->v_octet, 1, state); - break; + /* hash the OCTET */ + state = hash_usb8(type, value->v_octet, 1, state); + break; - case V_NBLOCK: - /* there is no setup for a NBLOCK */ + case V_NBLOCK: + /* there is no setup for a NBLOCK */ - /* hash the octets in the NBLOCK */ - if (value->v_nblock->blk->datalen > 0) { - state = hash_usb8(type, value->v_nblock->blk->data, - value->v_nblock->blk->datalen, - state); - } - break; + /* hash the octets in the NBLOCK */ + if (value->v_nblock->blk->datalen > 0) { + state = hash_usb8(type, value->v_nblock->blk->data, + value->v_nblock->blk->datalen, + state); + } + break; - default: - math_error("hashing an unknown value"); - not_reached(); - } - return state; + default: + math_error("hashing an unknown value"); + not_reached(); + } + return state; } diff --git a/hash.h b/hash.h index ec0b16a..63a0bfe 100644 --- a/hash.h +++ b/hash.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/11/14 23:57:45 - * File existed as early as: 1995 + * Under source code control: 1995/11/14 23:57:45 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -29,7 +29,7 @@ #define INCLUDE_HASH_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "sha1.h" # include "zmath.h" #else @@ -59,22 +59,22 @@ */ typedef struct hashstate HASH; struct hashstate { - int hashtype; /* XYZ_HASH_TYPE debug value */ - bool bytes; /* true => reading bytes rather than words */ - void (*update)(HASH*, USB8*, USB32); /* update arbitrary length */ - void (*chkpt)(HASH*); /* checkpoint a state */ - void (*note)(int, HASH*); /* note a special value */ - void (*type)(int, HASH*); /* note a VALUE type */ - ZVALUE (*final)(HASH*); /* complete hash state */ - int (*cmp)(HASH*,HASH*); /* compare to states, true => a!=b */ - void (*print)(HASH*); /* print the value of a hash */ - int base; /* XYZ_BASE special hash value */ - int chunksize; /* XYZ_CHUNKSIZE input chunk size */ - int unionsize; /* h_union element size */ - union { /* hash dependent states */ - USB8 data[1]; /* used by hash_value to hash below */ - SHA1_INFO h_sha1; /* new SHA-1 internal state */ - } h_union; + int hashtype; /* XYZ_HASH_TYPE debug value */ + bool bytes; /* true => reading bytes rather than words */ + void (*update)(HASH*, USB8*, USB32); /* update arbitrary length */ + void (*chkpt)(HASH*); /* checkpoint a state */ + void (*note)(int, HASH*); /* note a special value */ + void (*type)(int, HASH*); /* note a VALUE type */ + ZVALUE (*final)(HASH*); /* complete hash state */ + int (*cmp)(HASH*,HASH*); /* compare to states, true => a!=b */ + void (*print)(HASH*); /* print the value of a hash */ + int base; /* XYZ_BASE special hash value */ + int chunksize; /* XYZ_CHUNKSIZE input chunk size */ + int unionsize; /* h_union element size */ + union { /* hash dependent states */ + USB8 data[1]; /* used by hash_value to hash below */ + SHA1_INFO h_sha1; /* new SHA-1 internal state */ + } h_union; }; @@ -82,12 +82,12 @@ struct hashstate { * what to xor to digest value when hashing special values * * IMPORTANT: To avoid overlap due to the HASH_XYZ macros below, the - * XYZ_BASE values should be unique random hex values - * that end in 00 (i.e., 0 mod 256). + * XYZ_BASE values should be unique random hex values + * that end in 00 (i.e., 0 mod 256). */ -#define SHA_BASE 0x12face00 /* old SHA / SHA - no longer used */ -#define SHA1_BASE 0x23cafe00 /* new SHA-1 / SHA-1 */ -#define MD5_BASE 0x34feed00 /* MD5 - no longer used */ +#define SHA_BASE 0x12face00 /* old SHA / SHA - no longer used */ +#define SHA1_BASE 0x23cafe00 /* new SHA-1 / SHA-1 */ +#define MD5_BASE 0x34feed00 /* MD5 - no longer used */ /* @@ -95,19 +95,19 @@ struct hashstate { * * we support these hash types */ -#define SHA_HASH_TYPE 1 /* no longer used */ +#define SHA_HASH_TYPE 1 /* no longer used */ #define SHA1_HASH_TYPE 2 -#define MD5_HASH_TYPE 3 /* no longer used */ +#define MD5_HASH_TYPE 3 /* no longer used */ /* * Note a special value given the base value */ -#define HASH_NEG(base) (1+base) /* note a negative value */ -#define HASH_COMPLEX(base) (2+base) /* note a complex value */ -#define HASH_DIV(base) (4+base) /* note a division by a value */ -#define HASH_ZERO(base) (8+base) /* note a zero numeric value */ -#define HASH_ZVALUE(base) (16+base) /* note a ZVALUE */ +#define HASH_NEG(base) (1+base) /* note a negative value */ +#define HASH_COMPLEX(base) (2+base) /* note a complex value */ +#define HASH_DIV(base) (4+base) /* note a division by a value */ +#define HASH_ZERO(base) (8+base) /* note a zero numeric value */ +#define HASH_ZVALUE(base) (16+base) /* note a ZVALUE */ /* diff --git a/have_arc4random.c b/have_arc4random.c index 436cc13..983ca7a 100644 --- a/have_arc4random.c +++ b/have_arc4random.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,25 +17,25 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2021/12/06 23:58:51 - * File existed as early as: 2021 + * Under source code control: 2021/12/06 23:58:51 + * File existed as early as: 2021 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_arc4random + * have_arc4random * * Not all enviroments have the arc4random_buf() function, * so this may not compile on your system. * * This prog outputs: * - * HAVE_ARC4RANDOM - * defined ==> have arc4random_buf() call - * undefined ==> do not have arc4random_buf() call + * HAVE_ARC4RANDOM + * defined ==> have arc4random_buf() call + * undefined ==> do not have arc4random_buf() call */ #include "have_stdlib.h" @@ -45,10 +45,10 @@ #include -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define BUFLEN (32) /* length of the buffer to fill */ +#define BUFLEN (32) /* length of the buffer to fill */ int @@ -56,18 +56,18 @@ main(void) { #if defined(HAVE_NO_ARC4RANDOM) - printf("#undef HAVE_ARC4RANDOM /* no */\n"); + printf("#undef HAVE_ARC4RANDOM /* no */\n"); #else /* HAVE_NO_ARC4RANDOM */ - /* buffer for arc4random_buf() to fill */ - static char buf[BUFLEN]; + /* buffer for arc4random_buf() to fill */ + static char buf[BUFLEN]; - arc4random_buf(buf, BUFLEN); - printf("#define HAVE_ARC4RANDOM /* yes */\n"); + arc4random_buf(buf, BUFLEN); + printf("#define HAVE_ARC4RANDOM /* yes */\n"); #endif /* HAVE_NO_ARC4RANDOM */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_ban_pragma.c b/have_ban_pragma.c index 988b0bd..c3fc3b8 100644 --- a/have_ban_pragma.c +++ b/have_ban_pragma.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,28 +17,28 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2021/03/08 01:02:34 - * File existed as early as: 2021 + * Under source code control: 2021/03/08 01:02:34 + * File existed as early as: 2021 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_ban_pragma + * have_ban_pragma * * Not all systems have #pragma GCC poison func_name, so this may not * compile on your system. * * This prog outputs several defines: * - * HAVE_PRAGMA_GCC_POSION - * defined ==> use #pragma GCC poison func_name - * undefined ==> do not use #pragma GCC poison func_name + * HAVE_PRAGMA_GCC_POSION + * defined ==> use #pragma GCC poison func_name + * undefined ==> do not use #pragma GCC poison func_name * * NOTE: Modern clang compilers allow for 'pragma GCC poison func_name'. - * This is NOT simply a GCC feature. + * This is NOT simply a GCC feature. */ #include @@ -50,7 +50,7 @@ /* prevent banned.h from including have_ban_pragma.h */ #define PRE_HAVE_BAN_PRAGMA_H -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int @@ -58,14 +58,14 @@ main(void) { #if defined(HAVE_NO_PRAGMA_GCC_POSION) - printf("#undef HAVE_PRAGMA_GCC_POSION /* no */\n"); + printf("#undef HAVE_PRAGMA_GCC_POSION /* no */\n"); #else /* HAVE_NO_PRAGMA_GCC_POSION */ - printf("#define HAVE_PRAGMA_GCC_POSION /* yes */\n"); + printf("#define HAVE_PRAGMA_GCC_POSION /* yes */\n"); #endif /* HAVE_NO_PRAGMA_GCC_POSION */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_const.c b/have_const.c index 4f608f3..32f4e8f 100644 --- a/have_const.c +++ b/have_const.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,34 +17,34 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/04/22 13:18:44 - * File existed as early as: 1995 + * Under source code control: 1995/04/22 13:18:44 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_const + * have_const * * Not all compilers support const, so this may not compile on your system. * * This prog outputs several defines: * - * HAVE_CONST - * defined ==> OK to use const - * undefined ==> do not use const + * HAVE_CONST + * defined ==> OK to use const + * undefined ==> do not use const * - * CONST - * const ==> use const - * (nothing) ==> const not used + * CONST + * const ==> use const + * (nothing) ==> const not used */ #include -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int @@ -52,20 +52,20 @@ main(void) { #if defined(HAVE_NO_CONST) - printf("#undef HAVE_CONST /* no */\n"); - printf("#undef CONST\n"); - printf("#define CONST /* no */\n"); + printf("#undef HAVE_CONST /* no */\n"); + printf("#undef CONST\n"); + printf("#define CONST /* no */\n"); #else /* HAVE_NO_CONST */ - const char * const str = "const"; + const char * const str = "const"; - printf("#define HAVE_CONST /* yes */\n"); - printf("#undef CONST\n"); - printf("#define CONST %s /* yes */\n", str); + printf("#define HAVE_CONST /* yes */\n"); + printf("#undef CONST\n"); + printf("#define CONST %s /* yes */\n", str); #endif /* HAVE_NO_CONST */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_environ.c b/have_environ.c index 56a16c2..06f7e05 100644 --- a/have_environ.c +++ b/have_environ.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,34 +17,34 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2021/12/06 19:34:32 - * File existed as early as: 2021 + * Under source code control: 2021/12/06 19:34:32 + * File existed as early as: 2021 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_environ + * have_environ * * Not all enviroments have the user environment external: * - * extern char **environ; + * extern char **environ; * * so this may not compile on your system. * * This prog outputs: * - * HAVE_ENVIRON - * defined ==> environ is an non-NULL extern symbol - * undefined ==> environ is NOT an extern symbol or is NULL + * HAVE_ENVIRON + * defined ==> environ is an non-NULL extern symbol + * undefined ==> environ is NOT an extern symbol or is NULL */ #include -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int @@ -52,20 +52,20 @@ main(void) { #if defined(HAVE_NO_ENVIRON) - printf("#undef HAVE_ENVIRON /* no */\n"); + printf("#undef HAVE_ENVIRON /* no */\n"); #else /* HAVE_NO_ENVIRON */ - extern char **environ; + extern char **environ; - if (environ == NULL) { - printf("#define HAVE_ENVIRON /* no */\n"); - } else { - printf("#define HAVE_ENVIRON /* yes */\n"); - } + if (environ == NULL) { + printf("#define HAVE_ENVIRON /* no */\n"); + } else { + printf("#define HAVE_ENVIRON /* yes */\n"); + } #endif /* HAVE_NO_ENVIRON */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_fgetsetpos.c b/have_fgetsetpos.c index 495f346..15044cc 100644 --- a/have_fgetsetpos.c +++ b/have_fgetsetpos.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1994/11/05 03:19:52 - * File existed as early as: 1994 + * Under source code control: 1994/11/05 03:19:52 + * File existed as early as: 1994 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -34,26 +34,26 @@ #include -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int main(void) { #if !defined(HAVE_NO_FGETSETPOS) - fpos_t pos; /* file position */ + fpos_t pos; /* file position */ - /* get the current position */ - (void) fgetpos(stdin, &pos); + /* get the current position */ + (void) fgetpos(stdin, &pos); - /* set the current position */ - (void) fsetpos(stdin, &pos); + /* set the current position */ + (void) fsetpos(stdin, &pos); - /* print a have_fgetsetpos.h body that says we have the functions */ - printf("#undef HAVE_FGETSETPOS\n"); - printf("#define HAVE_FGETSETPOS 1 /* yes */\n\n"); - printf("typedef fpos_t FILEPOS;\n"); + /* print a have_fgetsetpos.h body that says we have the functions */ + printf("#undef HAVE_FGETSETPOS\n"); + printf("#define HAVE_FGETSETPOS 1 /* yes */\n\n"); + printf("typedef fpos_t FILEPOS;\n"); #endif - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_fpos_pos.c b/have_fpos_pos.c index 0527905..0f41514 100644 --- a/have_fpos_pos.c +++ b/have_fpos_pos.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2000/12/17 01:23 - * File existed as early as: 2000 + * Under source code control: 2000/12/17 01:23 + * File existed as early as: 2000 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -34,7 +34,7 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int @@ -42,42 +42,42 @@ main(void) { #if defined(HAVE_FILEPOS_SCALAR) - printf("/* HAVE_FILEPOS_SCALAR is defined, we assume FILEPOS is scalar */\n"); - printf("/* we assume we have no __pos in FILEPOS */\n"); - printf("#undef HAVE_FPOS_POS\t/* no */\n"); - printf("#undef FPOS_POS_BITS\n"); - printf("#undef FPOS_POS_LEN\n"); + printf("/* HAVE_FILEPOS_SCALAR is defined, we assume FILEPOS is scalar */\n"); + printf("/* we assume we have no __pos in FILEPOS */\n"); + printf("#undef HAVE_FPOS_POS\t/* no */\n"); + printf("#undef FPOS_POS_BITS\n"); + printf("#undef FPOS_POS_LEN\n"); #else - printf("/* HAVE_FILEPOS_SCALAR is undefined, we assume FILEPOS is not scalar */\n"); + printf("/* HAVE_FILEPOS_SCALAR is undefined, we assume FILEPOS is not scalar */\n"); # if defined(HAVE_NO_FPOS_POS) - printf("/* HAVE_NO_FPOS_POS defiled, we assume we have no __pos in FILEPOS */\n"); - printf("#undef HAVE_FPOS_POS\t/* no */\n"); - printf("#undef FPOS_POS_BITS\n"); - printf("#undef FPOS_POS_LEN\n"); + printf("/* HAVE_NO_FPOS_POS defiled, we assume we have no __pos in FILEPOS */\n"); + printf("#undef HAVE_FPOS_POS\t/* no */\n"); + printf("#undef FPOS_POS_BITS\n"); + printf("#undef FPOS_POS_LEN\n"); # elif defined(FPOS_POS_BITS) - printf("/* FPOS_POS_BITS defiled, assume we have __pos in FILEPOS */\n"); - printf("#undef HAVE_FPOS_POS\n"); - printf("#define HAVE_FPOS_POS 1 /* yes */\n"); - printf("#undef FPOS_POS_BITS\n"); - printf("#define FPOS_POS_BITS %d\n", FPOS_POS_BITS); - printf("#undef FPOS_POS_LEN\n"); - printf("#define FPOS_POS_LEN %d\n", int(FPOS_POS_BITS/8)); + printf("/* FPOS_POS_BITS defiled, assume we have __pos in FILEPOS */\n"); + printf("#undef HAVE_FPOS_POS\n"); + printf("#define HAVE_FPOS_POS 1 /* yes */\n"); + printf("#undef FPOS_POS_BITS\n"); + printf("#define FPOS_POS_BITS %d\n", FPOS_POS_BITS); + printf("#undef FPOS_POS_LEN\n"); + printf("#define FPOS_POS_LEN %d\n", int(FPOS_POS_BITS/8)); # else - fpos_t pos; /* file position */ + fpos_t pos; /* file position */ - memset(&pos, 0, sizeof(pos)); /* zeroize pos to "set it" */ - printf("/* we successfully compiled with a fpos_t type wit an __pos element */\n"); - printf("#undef HAVE_FPOS_POS\n"); - printf("#define HAVE_FPOS_POS 1 /* yes */\n"); - printf("#undef FPOS_POS_BITS\n"); - printf("#define FPOS_POS_BITS %lu\n", sizeof(pos.__pos)*8); - printf("#undef FPOS_POS_LEN\n"); - printf("#define FPOS_POS_LEN %lu\n", sizeof(pos.__pos)); + memset(&pos, 0, sizeof(pos)); /* zeroize pos to "set it" */ + printf("/* we successfully compiled with a fpos_t type wit an __pos element */\n"); + printf("#undef HAVE_FPOS_POS\n"); + printf("#define HAVE_FPOS_POS 1 /* yes */\n"); + printf("#undef FPOS_POS_BITS\n"); + printf("#define FPOS_POS_BITS %lu\n", sizeof(pos.__pos)*8); + printf("#undef FPOS_POS_LEN\n"); + printf("#define FPOS_POS_LEN %lu\n", sizeof(pos.__pos)); # endif #endif - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_getpgid.c b/have_getpgid.c index 59aaaca..e5a762c 100644 --- a/have_getpgid.c +++ b/have_getpgid.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,25 +17,25 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/10/20 22:51:13 - * File existed as early as: 1999 + * Under source code control: 1999/10/20 22:51:13 + * File existed as early as: 1999 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_getpgid + * have_getpgid * * Not all systems have the getpgid() function, so this may not * compile on your system. * * This prog outputs several defines: * - * HAVE_GETPGID - * defined ==> use getpgid() - * undefined ==> do not or cannot call getpgid() + * HAVE_GETPGID + * defined ==> use getpgid() + * undefined ==> do not or cannot call getpgid() */ #include @@ -46,7 +46,7 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int @@ -54,16 +54,16 @@ main(void) { #if defined(HAVE_NO_GETPGID) - printf("#undef HAVE_GETPGID /* no */\n"); + printf("#undef HAVE_GETPGID /* no */\n"); #else /* HAVE_NO_GETPGID */ - (void) getpgid((pid_t)0); + (void) getpgid((pid_t)0); - printf("#define HAVE_GETPGID /* yes */\n"); + printf("#define HAVE_GETPGID /* yes */\n"); #endif /* HAVE_NO_GETPGID */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_getprid.c b/have_getprid.c index f350f82..0b350ee 100644 --- a/have_getprid.c +++ b/have_getprid.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,25 +17,25 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/10/20 23:43:42 - * File existed as early as: 1999 + * Under source code control: 1999/10/20 23:43:42 + * File existed as early as: 1999 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_getprid + * have_getprid * * Not all systems have the getprid() function, so this may not * compile on your system. * * This prog outputs several defines: * - * HAVE_GETPRID - * defined ==> use getprid() - * undefined ==> do not or cannot call getprid() + * HAVE_GETPRID + * defined ==> use getprid() + * undefined ==> do not or cannot call getprid() */ #include @@ -46,7 +46,7 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int @@ -54,15 +54,15 @@ main(void) { #if defined(HAVE_NO_GETPRID) - printf("#undef HAVE_GETPRID /* no */\n"); + printf("#undef HAVE_GETPRID /* no */\n"); #else /* HAVE_NO_GETPRID */ - (void) getprid(); - printf("#define HAVE_GETPRID /* yes */\n"); + (void) getprid(); + printf("#define HAVE_GETPRID /* yes */\n"); #endif /* HAVE_NO_GETPRID */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_getsid.c b/have_getsid.c index ecdbda9..1780d13 100644 --- a/have_getsid.c +++ b/have_getsid.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,25 +17,25 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/10/20 22:51:13 - * File existed as early as: 1999 + * Under source code control: 1999/10/20 22:51:13 + * File existed as early as: 1999 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_getsid + * have_getsid * * Not all systems have the getsid() function, so this may not * compile on your system. * * This prog outputs several defines: * - * HAVE_GETSID - * defined ==> use getsid() - * undefined ==> do not call or cannot call getsid() + * HAVE_GETSID + * defined ==> use getsid() + * undefined ==> do not call or cannot call getsid() */ #include @@ -46,7 +46,7 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int @@ -54,16 +54,16 @@ main(void) { #if defined(HAVE_NO_GETSID) - printf("#undef HAVE_GETSID /* no */\n"); + printf("#undef HAVE_GETSID /* no */\n"); #else /* HAVE_NO_GETSID */ - (void) getsid((pid_t)0); + (void) getsid((pid_t)0); - printf("#define HAVE_GETSID /* yes */\n"); + printf("#define HAVE_GETSID /* yes */\n"); #endif /* HAVE_NO_GETSID */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_gettime.c b/have_gettime.c index 83fc890..4ef51a6 100644 --- a/have_gettime.c +++ b/have_gettime.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,33 +17,33 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/10/20 23:43:42 - * File existed as early as: 1999 + * Under source code control: 1999/10/20 23:43:42 + * File existed as early as: 1999 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_gettime + * have_gettime * * Not all systems have the clock_gettime() function, so this may not * compile on your system. * * This prog outputs several defines: * - * HAVE_GETTIME - * defined ==> use clock_gettime() from CLOCK_REALTIME - * undefined ==> clock_gettime() is not available from - * CLOCK_REALTIME + * HAVE_GETTIME + * defined ==> use clock_gettime() from CLOCK_REALTIME + * undefined ==> clock_gettime() is not available from + * CLOCK_REALTIME */ #include #include -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int @@ -51,23 +51,23 @@ main(void) { #if defined(HAVE_NO_GETTIME) || defined(_WIN32) || defined(_WIN64) - printf("#undef HAVE_GETTIME /* no */\n"); + printf("#undef HAVE_GETTIME /* no */\n"); #else /* HAVE_NO_GETTIME */ # if defined(CLOCK_REALTIME) - struct timespec realtime; /* POSIX realtime clock */ - (void) clock_gettime(CLOCK_REALTIME, &realtime); - printf("#define HAVE_GETTIME /* yes - CLOCK_REALTIME only */\n"); + struct timespec realtime; /* POSIX realtime clock */ + (void) clock_gettime(CLOCK_REALTIME, &realtime); + printf("#define HAVE_GETTIME /* yes - CLOCK_REALTIME only */\n"); # else - printf("#undef HAVE_GETTIME /* no - no CLOCK_REALTIME */\n"); + printf("#undef HAVE_GETTIME /* no - no CLOCK_REALTIME */\n"); # endif /* CLOCK_REALTIME */ #endif /* HAVE_NO_GETTIME */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_memmv.c b/have_memmv.c index 9339aea..ae03673 100644 --- a/have_memmv.c +++ b/have_memmv.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,25 +17,25 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/04/16 02:02:34 - * File existed as early as: 1997 + * Under source code control: 1997/04/16 02:02:34 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_memmv + * have_memmv * * Not all systems with memcpy() have memmove() functions, so this may not * compile on your system. * * This prog outputs several defines: * - * HAVE_MEMMOVE - * defined ==> use memmove() - * undefined ==> use internal slow memmove() instead + * HAVE_MEMMOVE + * defined ==> use memmove() + * undefined ==> use internal slow memmove() instead */ #include @@ -45,7 +45,7 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ #define MOVELEN 3 @@ -58,16 +58,16 @@ main(void) { #if defined(HAVE_NO_MEMMOVE) - printf("#undef HAVE_MEMMOVE /* no */\n"); + printf("#undef HAVE_MEMMOVE /* no */\n"); #else /* HAVE_NO_MEMMOVE */ - (void) memmove(dest, src, MOVELEN); + (void) memmove(dest, src, MOVELEN); - printf("#define HAVE_MEMMOVE /* yes */\n"); + printf("#define HAVE_MEMMOVE /* yes */\n"); #endif /* HAVE_NO_MEMMOVE */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_newstr.c b/have_newstr.c index cdff2c8..9b68ee7 100644 --- a/have_newstr.c +++ b/have_newstr.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,27 +17,27 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/05/02 03:55:08 - * File existed as early as: 1995 + * Under source code control: 1995/05/02 03:55:08 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_newstr + * have_newstr * * Not all systems support all ANSI C string functions, so this may not * compile on your system. * * This prog outputs several defines: * - * HAVE_NEWSTR - * defined ==> use memcpy(), memset(), strchr() - * undefined ==> use bcopy() instead of memcpy(), - * use bfill() instead of memset(), - * use index() instead of strchr() + * HAVE_NEWSTR + * defined ==> use memcpy(), memset(), strchr() + * undefined ==> use bcopy() instead of memcpy(), + * use bfill() instead of memset(), + * use index() instead of strchr() */ #include @@ -47,7 +47,7 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ #define MOVELEN 3 @@ -60,18 +60,18 @@ main(void) { #if defined(HAVE_NO_NEWSTR) - printf("#undef HAVE_NEWSTR /* no */\n"); + printf("#undef HAVE_NEWSTR /* no */\n"); #else /* HAVE_NO_NEWSTR */ - (void) memcpy(dest, src, MOVELEN); - (void) memset(dest, 0, MOVELEN); - (void) strchr(src, 'e'); + (void) memcpy(dest, src, MOVELEN); + (void) memset(dest, 0, MOVELEN); + (void) strchr(src, 'e'); - printf("#define HAVE_NEWSTR /* yes */\n"); + printf("#define HAVE_NEWSTR /* yes */\n"); #endif /* HAVE_NO_NEWSTR */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_offscl.c b/have_offscl.c index 105991e..65bc027 100644 --- a/have_offscl.c +++ b/have_offscl.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,19 +17,19 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1996/07/13 12:57:22 - * File existed as early as: 1996 + * Under source code control: 1996/07/13 12:57:22 + * File existed as early as: 1996 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_offscl + * have_offscl * * On some systems, off_t is a scalar value on which one can perform - * arithmetic operations, assignments and comparisons. On some systems + * arithmetic operations, assignments and comparisons. On some systems * off_t is some sort of union or struct which must be converted into * a ZVALUE in order to perform arithmetic operations, assignments and * comparisons. @@ -37,9 +37,9 @@ * * This prog outputs several defines: * - * HAVE_OFF_T_SCALAR - * defined ==> OK to perform arithmetic ops, = and comparisons - * undefined ==> convert to ZVALUE first + * HAVE_OFF_T_SCALAR + * defined ==> OK to perform arithmetic ops, = and comparisons + * undefined ==> convert to ZVALUE first */ #include @@ -51,45 +51,45 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int main(void) { #if !defined(OFF_T_NON_SCALAR) - off_t value; /* an off_t to perform arithmetic on */ - off_t value2; /* an off_t to perform arithmetic on */ + off_t value; /* an off_t to perform arithmetic on */ + off_t value2; /* an off_t to perform arithmetic on */ - /* - * do some math opts on an off_t - */ - value = (off_t)getpid(); - value2 = (off_t)-1; - if (value > (off_t)1) { - --value; - } + /* + * do some math opts on an off_t + */ + value = (off_t)getpid(); + value2 = (off_t)-1; + if (value > (off_t)1) { + --value; + } #if !defined(_WIN32) && !defined(_WIN64) - if (value <= (off_t)getppid()) { - --value; - } + if (value <= (off_t)getppid()) { + --value; + } #endif - if (value == value2) { - value += value2; - } - value <<= 1; - if (!value) { - printf("/* something for the off_t to do */\n"); - } + if (value == value2) { + value += value2; + } + value <<= 1; + if (!value) { + printf("/* something for the off_t to do */\n"); + } - /* - * report off_t as a scalar - */ - printf("#undef HAVE_OFF_T_SCALAR\n"); - printf("#define HAVE_OFF_T_SCALAR /* off_t is a simple value */\n"); + /* + * report off_t as a scalar + */ + printf("#undef HAVE_OFF_T_SCALAR\n"); + printf("#define HAVE_OFF_T_SCALAR /* off_t is a simple value */\n"); #else - printf("#undef HAVE_OFF_T_SCALAR /* off_t is not a simple value */\n"); + printf("#undef HAVE_OFF_T_SCALAR /* off_t is not a simple value */\n"); #endif - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_posscl.c b/have_posscl.c index 50b04f0..2028195 100644 --- a/have_posscl.c +++ b/have_posscl.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,28 +17,28 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1996/07/13 12:57:22 - * File existed as early as: 1996 + * Under source code control: 1996/07/13 12:57:22 + * File existed as early as: 1996 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_posscl + * have_posscl * * On some systems, FILEPOS is a scalar value on which one can perform - * arithmetic operations, assignments and comparisons. On some systems + * arithmetic operations, assignments and comparisons. On some systems * FILEPOS is some sort of union or struct which must be converted into * a ZVALUE in order to perform arithmetic operations, assignments and * comparisons. * * This prog outputs several defines: * - * HAVE_FILEPOS_SCALAR - * defined ==> OK to perform arithmetic ops, = and comparisons - * undefined ==> convert to ZVALUE first + * HAVE_FILEPOS_SCALAR + * defined ==> OK to perform arithmetic ops, = and comparisons + * undefined ==> convert to ZVALUE first */ #include @@ -51,46 +51,46 @@ #include "have_fgetsetpos.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int main(void) { #if !defined(FILEPOS_NON_SCALAR) - FILEPOS value; /* an FILEPOS to perform arithmetic on */ - FILEPOS value2; /* an FILEPOS to perform arithmetic on */ + FILEPOS value; /* an FILEPOS to perform arithmetic on */ + FILEPOS value2; /* an FILEPOS to perform arithmetic on */ - /* - * do some math opts on an FILEPOS - */ - value = (FILEPOS)getpid(); - value2 = (FILEPOS)-1; - if (value > (FILEPOS)1) { - --value; - } + /* + * do some math opts on an FILEPOS + */ + value = (FILEPOS)getpid(); + value2 = (FILEPOS)-1; + if (value > (FILEPOS)1) { + --value; + } #if !defined(_WIN32) && !defined(_WIN64) - if (value <= (FILEPOS)getppid()) { - --value; - } + if (value <= (FILEPOS)getppid()) { + --value; + } #endif - if (value == value2) { - value += value2; - } - value <<= 1; - if (!value) { - printf("/* something for the FILEPOS to do */\n"); - } + if (value == value2) { + value += value2; + } + value <<= 1; + if (!value) { + printf("/* something for the FILEPOS to do */\n"); + } - /* - * report FILEPOS as a scalar - */ - printf("#undef HAVE_FILEPOS_SCALAR\n"); - printf("#define HAVE_FILEPOS_SCALAR /* FILEPOS is a simple value */\n"); + /* + * report FILEPOS as a scalar + */ + printf("#undef HAVE_FILEPOS_SCALAR\n"); + printf("#define HAVE_FILEPOS_SCALAR /* FILEPOS is a simple value */\n"); #else - printf("#undef HAVE_FILEPOS_SCALAR " - "/* FILEPOS is not a simple value */\n"); + printf("#undef HAVE_FILEPOS_SCALAR " + "/* FILEPOS is not a simple value */\n"); #endif - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_rusage.c b/have_rusage.c index 7afb165..b86760f 100644 --- a/have_rusage.c +++ b/have_rusage.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,25 +17,25 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/11/05 11:28:15 - * File existed as early as: 1999 + * Under source code control: 1999/11/05 11:28:15 + * File existed as early as: 1999 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_rusage + * have_rusage * * Not all systems have the getrusage() function, so this may not * compile on your system. * * This prog outputs several defines: * - * HAVE_GETRUSAGE - * defined ==> use getrusage() - * undefined ==> do not call or cannot call getrusage() + * HAVE_GETRUSAGE + * defined ==> use getrusage() + * undefined ==> do not call or cannot call getrusage() */ #include @@ -43,7 +43,7 @@ #include -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int @@ -51,18 +51,18 @@ main(void) { #if defined(HAVE_NO_GETRUSAGE) - printf("#undef HAVE_GETRUSAGE /* no */\n"); + printf("#undef HAVE_GETRUSAGE /* no */\n"); #else /* HAVE_NO_GETRUSAGE */ - struct rusage rusage; /* resource utilization */ + struct rusage rusage; /* resource utilization */ - (void) getrusage(RUSAGE_SELF, &rusage); + (void) getrusage(RUSAGE_SELF, &rusage); - printf("#define HAVE_GETRUSAGE /* yes */\n"); + printf("#define HAVE_GETRUSAGE /* yes */\n"); #endif /* HAVE_NO_GETRUSAGE */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_statfs.c b/have_statfs.c index eacb66a..a655696 100644 --- a/have_statfs.c +++ b/have_statfs.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,25 +17,25 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2023/03/06 00:51:53 - * File existed as early as: 2023 + * Under source code control: 2023/03/06 00:51:53 + * File existed as early as: 2023 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_statfs + * have_statfs * * Not all systems have the statfs() function, so this may not * compile on your system. * * This prog outputs several defines: * - * HAVE_STATFS - * defined ==> use statfs() - * undefined ==> do not call or cannot call statfs() + * HAVE_STATFS + * defined ==> use statfs() + * undefined ==> do not call or cannot call statfs() */ #include @@ -57,7 +57,7 @@ # include #endif /* HAVE_SYS_MOUNT_H */ -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int @@ -65,18 +65,18 @@ main(void) { #if defined(HAVE_NO_STATFS) - printf("#undef HAVE_STATFS /* no */\n"); + printf("#undef HAVE_STATFS /* no */\n"); #else /* HAVE_NO_STATFS */ - struct statfs statfs_dot; /* usage stat of "." */ + struct statfs statfs_dot; /* usage stat of "." */ - (void) statfs(".", &statfs_dot); + (void) statfs(".", &statfs_dot); - printf("#define HAVE_STATFS /* yes */\n"); + printf("#define HAVE_STATFS /* yes */\n"); #endif /* HAVE_NO_STATFS */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_stdvs.c b/have_stdvs.c index 7522d8f..3e1d5d9 100644 --- a/have_stdvs.c +++ b/have_stdvs.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/09/09 22:41:10 - * File existed as early as: 1995 + * Under source code control: 1995/09/09 22:41:10 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -33,7 +33,7 @@ * as if it were vsnprintf() and hope for the best. * * This program will output #defines and exits 0 if vsnprintf() (or snprintf()) - * produces the results that we expect. This program exits 1 if vsnprintf() + * produces the results that we expect. This program exits 1 if vsnprintf() * (or snprintf()) produces unexpected results while using the * include file. */ @@ -65,7 +65,7 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ char buf[BUFSIZ+1]; @@ -74,91 +74,91 @@ char buf[BUFSIZ+1]; void try_nthis(char *fmt, VSNPRINTF_SIZE_T size, ...) { - va_list ap; + va_list ap; - va_start(ap, size); + va_start(ap, size); #if !defined(DONT_HAVE_VSNPRINTF) - vsnprintf(buf, size, fmt, ap); + vsnprintf(buf, size, fmt, ap); #else - snprintf(buf, size, fmt, ap); + snprintf(buf, size, fmt, ap); #endif - va_end(ap); + va_end(ap); } int main(void) { - /* - * setup - */ - buf[0] = '\0'; + /* + * setup + */ + buf[0] = '\0'; - /* - * test variable args and vsnprintf/snprintf - */ - try_nthis("@%d:%s:%d@", sizeof(buf)-1, 1, "hello", 5); - if (strcmp(buf, "@1:hello:5@") != 0) { + /* + * test variable args and vsnprintf/snprintf + */ + try_nthis("@%d:%s:%d@", sizeof(buf)-1, 1, "hello", 5); + if (strcmp(buf, "@1:hello:5@") != 0) { #if !defined(DONT_HAVE_VSNPRINTF) - /* with vsnprintf() didn't work */ + /* with vsnprintf() didn't work */ #else - /* with snprintf() simulating vsnprintf() didn't work */ + /* with snprintf() simulating vsnprintf() didn't work */ #endif - exit(1); - } - try_nthis("%s %d%s%d%d %s", sizeof(buf)-1, - "Landon Noll 1st proved that", 2, "^", 23209, -1, "was prime"); - if (strcmp(buf, - "Landon Noll 1st proved that 2^23209-1 was prime") != 0) { + exit(1); + } + try_nthis("%s %d%s%d%d %s", sizeof(buf)-1, + "Landon Noll 1st proved that", 2, "^", 23209, -1, "was prime"); + if (strcmp(buf, + "Landon Noll 1st proved that 2^23209-1 was prime") != 0) { #if !defined(DONT_HAVE_VSNPRINTF) - /* with vsnprintf() didn't work */ + /* with vsnprintf() didn't work */ #else - /* with snprintf() simulating vsnprintf() didn't work */ + /* with snprintf() simulating vsnprintf() didn't work */ #endif - exit(1); - } + exit(1); + } - /* - * report the result - */ - puts("/* what type of variable args do we have? */"); + /* + * report the result + */ + puts("/* what type of variable args do we have? */"); #if defined(DONT_HAVE_VSNPRINTF) - puts("/*"); - puts(" * SIMULATE_STDARG"); - puts(" *"); - puts(" * WARNING: This type of stdarg makes assumptions " - "about the stack"); - puts(" * that may not be true on your system. " - "You may want to"); - puts(" * define STDARG (if using ANSI C) or VARARGS."); - puts(" */"); - puts("typedef char *va_list;"); - puts("#define va_start(ap,parmn) (void)((ap) = (char*)(&(parmn) + 1))"); - puts("#define va_end(ap) (void)((ap) = 0)"); - puts("#define va_arg(ap, type) \\"); - puts(" (((type*)((ap) = ((ap) + sizeof(type))))[-1])"); - puts("#define SIMULATE_STDARG " - "/* use std_arg.h to simulate */"); + puts("/*"); + puts(" * SIMULATE_STDARG"); + puts(" *"); + puts(" * WARNING: This type of stdarg makes assumptions " + "about the stack"); + puts(" * that may not be true on your system. " + "You may want to"); + puts(" * define STDARG (if using ANSI C) or VARARGS."); + puts(" */"); + puts("typedef char *va_list;"); + puts("#define va_start(ap,parmn) (void)((ap) = (char*)(&(parmn) + 1))"); + puts("#define va_end(ap) (void)((ap) = 0)"); + puts("#define va_arg(ap, type) \\"); + puts(" (((type*)((ap) = ((ap) + sizeof(type))))[-1])"); + puts("#define SIMULATE_STDARG " + "/* use std_arg.h to simulate */"); #else - puts("#define STDARG /* use */"); - puts("#include "); + puts("#define STDARG /* use */"); + puts("#include "); #endif - puts("\n/* should we use vsnprintf() and vsnprintf()? */"); + puts("\n/* should we use vsnprintf() and vsnprintf()? */"); #if !defined(DONT_HAVE_VSNPRINTF) - puts("#define HAVE_VSNPRINTF /* yes */"); + puts("#define HAVE_VSNPRINTF /* yes */"); #else - puts("/*"); - puts(" * Hack aleart!!!"); - puts(" *"); - puts(" * Systems that do not have vsnprintf() need something. In some"); - puts(" * cases the snprintf function will deal correctly with the"); - puts(" * va_alist 4th arg. Same goes for a lack of an vsnprintf()"); - puts(" * function. In either case we use the #defines below and"); - puts(" * hope for the best!"); - puts(" */"); - puts("#define vsnprintf snprintf"); - puts("#undef HAVE_VSNPRINTF"); + puts("/*"); + puts(" * Hack aleart!!!"); + puts(" *"); + puts(" * Systems that do not have vsnprintf() need something. In some"); + puts(" * cases the snprintf function will deal correctly with the"); + puts(" * va_alist 4th arg. Same goes for a lack of an vsnprintf()"); + puts(" * function. In either case we use the #defines below and"); + puts(" * hope for the best!"); + puts(" */"); + puts("#define vsnprintf snprintf"); + puts("#undef HAVE_VSNPRINTF"); #endif - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_strdup.c b/have_strdup.c index f6312a0..61a0f79 100644 --- a/have_strdup.c +++ b/have_strdup.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,25 +17,25 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/11/09 12:46:54 - * File existed as early as: 1999 + * Under source code control: 1999/11/09 12:46:54 + * File existed as early as: 1999 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_strdup + * have_strdup * * Not all systems have the strdup() function, so this may not * compile on your system. * * This prog outputs several defines: * - * HAVE_STRDUP - * defined ==> use strdup() - * undefined ==> do not call or cannot call strdup() + * HAVE_STRDUP + * defined ==> use strdup() + * undefined ==> do not call or cannot call strdup() */ #include @@ -45,7 +45,7 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int @@ -53,19 +53,19 @@ main(void) { #if defined(HAVE_NO_STRDUP) - printf("#undef HAVE_STRDUP /* no */\n"); + printf("#undef HAVE_STRDUP /* no */\n"); #else /* HAVE_NO_STRDUP */ - char *p; + char *p; - p = strdup("#define HAVE_STRDUP /* yes */"); - if (p != NULL) { - printf("%s\n", p); - } + p = strdup("#define HAVE_STRDUP /* yes */"); + if (p != NULL) { + printf("%s\n", p); + } #endif /* HAVE_NO_STRDUP */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_strlcat.c b/have_strlcat.c index 534bca3..965cd99 100644 --- a/have_strlcat.c +++ b/have_strlcat.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,25 +17,25 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2021/03/08 20:34:13 - * File existed as early as: 2021 + * Under source code control: 2021/03/08 20:34:13 + * File existed as early as: 2021 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_strlcat + * have_strlcat * * Not all systems have the strlcat() function, so this may not * compile on your system. * * This prog outputs several defines: * - * HAVE_STRLCAT - * defined ==> use strlcat() - * undefined ==> do not or cannot call strlcat() + * HAVE_STRLCAT + * defined ==> use strlcat() + * undefined ==> do not or cannot call strlcat() */ #include @@ -45,7 +45,7 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ #define BUF_SIZ 5 @@ -58,19 +58,19 @@ main(void) { #if defined(HAVE_NO_STRLCAT) - printf("#undef HAVE_STRLCAT /* no */\n"); + printf("#undef HAVE_STRLCAT /* no */\n"); #else /* HAVE_NO_STRLCAT */ - char dst[BUF_SIZ+1+1]; + char dst[BUF_SIZ+1+1]; - dst[0] = 'S'; - dst[1] = '\0'; - (void) strlcat(dst, src, sizeof(dst)); + dst[0] = 'S'; + dst[1] = '\0'; + (void) strlcat(dst, src, sizeof(dst)); - printf("#define HAVE_STRLCAT /* yes */\n"); + printf("#define HAVE_STRLCAT /* yes */\n"); #endif /* HAVE_NO_STRLCAT */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_strlcpy.c b/have_strlcpy.c index f77bd63..827dcc1 100644 --- a/have_strlcpy.c +++ b/have_strlcpy.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,25 +17,25 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2021/03/08 20:34:13 - * File existed as early as: 2021 + * Under source code control: 2021/03/08 20:34:13 + * File existed as early as: 2021 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_strlcpy + * have_strlcpy * * Not all systems have the strlcpy() function, so this may not * compile on your system. * * This prog outputs several defines: * - * HAVE_STRLCPY - * defined ==> use strlcpy() - * undefined ==> do not or cannot call strlcpy() + * HAVE_STRLCPY + * defined ==> use strlcpy() + * undefined ==> do not or cannot call strlcpy() */ #include @@ -45,7 +45,7 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ #define BUF_SIZ (sizeof("abcde")-1) @@ -58,17 +58,17 @@ main(void) { #if defined(HAVE_NO_STRLCPY) - printf("#undef HAVE_STRLCPY /* no */\n"); + printf("#undef HAVE_STRLCPY /* no */\n"); #else /* HAVE_NO_STRLCPY */ - char dst[BUF_SIZ+1]; + char dst[BUF_SIZ+1]; - (void) strlcpy(dst, src, sizeof(dst)); + (void) strlcpy(dst, src, sizeof(dst)); - printf("#define HAVE_STRLCPY /* yes */\n"); + printf("#define HAVE_STRLCPY /* yes */\n"); #endif /* HAVE_NO_STRLCPY */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_uid_t.c b/have_uid_t.c index f014344..3aa1039 100644 --- a/have_uid_t.c +++ b/have_uid_t.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,24 +17,24 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/05/02 03:03:24 - * File existed as early as: 1995 + * Under source code control: 1995/05/02 03:03:24 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_uid_t + * have_uid_t * * Not all compilers support uid_t, so this may not compile on your system. * * This prog outputs several defines: * - * HAVE_UID_T - * defined ==> OK to use uid_t - * undefined ==> do not use uid_t + * HAVE_UID_T + * defined ==> OK to use uid_t + * undefined ==> do not use uid_t */ #include @@ -49,7 +49,7 @@ #endif /* ! HAVE_NO_UID_T */ -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int @@ -57,21 +57,21 @@ main(void) { #if defined(HAVE_NO_UID_T) - printf("#undef HAVE_UID_T /* no */\n"); + printf("#undef HAVE_UID_T /* no */\n"); #else /* HAVE_NO_UID_T */ - uid_t curds; - extern uid_t geteuid(); + uid_t curds; + extern uid_t geteuid(); - curds = geteuid(); - /* force curds to be used, but do not print much info about our UID */ - printf("/* geteuid() mod 2 == %ld */\n", ((long)curds) & 0x1); + curds = geteuid(); + /* force curds to be used, but do not print much info about our UID */ + printf("/* geteuid() mod 2 == %ld */\n", ((long)curds) & 0x1); - printf("#define HAVE_UID_T /* yes */\n"); + printf("#define HAVE_UID_T /* yes */\n"); #endif /* HAVE_NO_UID_T */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_unused.c b/have_unused.c index f90a598..30eb56e 100644 --- a/have_unused.c +++ b/have_unused.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,35 +17,35 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2004/02/22 22:36:10 - * File existed as early as: 2004 + * Under source code control: 2004/02/22 22:36:10 + * File existed as early as: 2004 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_unused + * have_unused * * Not all compilers support the unused attribute, so this may not compile * on your system. * * This prog outputs several defines: * - * HAVE_UNUSED - * defined ==> OK to use unused - * undefined ==> do not use unused + * HAVE_UNUSED + * defined ==> OK to use unused + * undefined ==> do not use unused * - * UNUSED - * unused ==> use unused - * (nothing) ==> unused not used + * UNUSED + * unused ==> use unused + * (nothing) ==> unused not used */ #include -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ #if !defined(HAVE_NO_UNUSED) @@ -71,20 +71,20 @@ main(void) { #if defined(HAVE_NO_UNUSED) - printf("#undef UNUSED\n"); - printf("#if defined(__LCLINT__)\n"); - printf("# define UNUSED(x) /*@unused@*/ x\n"); - printf("#else\n"); - printf("# define UNUSED(x) x\n"); - printf("#endif\n"); + printf("#undef UNUSED\n"); + printf("#if defined(__LCLINT__)\n"); + printf("# define UNUSED(x) /*@unused@*/ x\n"); + printf("#else\n"); + printf("# define UNUSED(x) x\n"); + printf("#endif\n"); #else /* HAVE_NO_UNUSED */ - printf("#undef UNUSED\n"); - printf("#define UNUSED(x) %s\n", unused_str(NULL)); + printf("#undef UNUSED\n"); + printf("#define UNUSED(x) %s\n", unused_str(NULL)); #endif /* HAVE_NO_UNUSED */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_ustat.c b/have_ustat.c index eb5fa4c..c6eee9c 100644 --- a/have_ustat.c +++ b/have_ustat.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,25 +17,25 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/10/20 22:51:13 - * File existed as early as: 1999 + * Under source code control: 1999/10/20 22:51:13 + * File existed as early as: 1999 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * have_ustat + * have_ustat * * Not all systems have the ustat() function, so this may not * compile on your system. * * This prog outputs several defines: * - * HAVE_USTAT - * defined ==> use ustat() - * undefined ==> do not call or cannot call ustat() + * HAVE_USTAT + * defined ==> use ustat() + * undefined ==> do not call or cannot call ustat() */ #include @@ -44,7 +44,7 @@ #include -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ int @@ -52,20 +52,20 @@ main(void) { #if defined(HAVE_NO_USTAT) - printf("#undef HAVE_USTAT /* no */\n"); + printf("#undef HAVE_USTAT /* no */\n"); #else /* HAVE_NO_USTAT */ - struct stat stat_dot; /* stat of "." */ - struct ustat ustat_dot; /* usage stat of "." */ + struct stat stat_dot; /* stat of "." */ + struct ustat ustat_dot; /* usage stat of "." */ - (void) stat(".", &stat_dot); - (void) ustat(stat_dot.st_dev, &ustat_dot); + (void) stat(".", &stat_dot); + (void) ustat(stat_dot.st_dev, &ustat_dot); - printf("#define HAVE_USTAT /* yes */\n"); + printf("#define HAVE_USTAT /* yes */\n"); #endif /* HAVE_NO_USTAT */ - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/have_varvs.c b/have_varvs.c index c85850f..1846884 100644 --- a/have_varvs.c +++ b/have_varvs.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/09/09 22:41:10 - * File existed as early as: 1995 + * Under source code control: 1995/09/09 22:41:10 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -30,7 +30,7 @@ * vsnprintf() and hope for the best. * * This program will output #defines and exits 0 if vsnprintf() (or snprintf()) - * produces the results that we expect. This program exits 1 if vsnprintf() + * produces the results that we expect. This program exits 1 if vsnprintf() * (or snprintf()) produces unexpected results while using the * include file. */ @@ -60,7 +60,7 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ char buf[BUFSIZ+1]; @@ -97,57 +97,57 @@ try_nthis(char *a, VSNPRINTF_SIZE_T size, int b, char *c, int d) int main(void) { - /* - * setup - */ - buf[0] = '\0'; + /* + * setup + */ + buf[0] = '\0'; - /* - * test variable args and vsnprintf/snprintf - */ - try_nthis("@%d:%s:%d@", sizeof(buf)-1, 1, "hello", 5); - if (strcmp(buf, "@1:hello:5@") != 0) { + /* + * test variable args and vsnprintf/snprintf + */ + try_nthis("@%d:%s:%d@", sizeof(buf)-1, 1, "hello", 5); + if (strcmp(buf, "@1:hello:5@") != 0) { #if !defined(DONT_HAVE_VSNPRINTF) - /* with vsnprintf() didn't work */ + /* with vsnprintf() didn't work */ #else - /* with snprintf() simulating vsnprintf() didn't work */ + /* with snprintf() simulating vsnprintf() didn't work */ #endif - exit(1); - } - try_nthis("%s %d%s%d%d %s", sizeof(buf)-1, - "Landon Noll 1st proved that", 2, "^", 23209, -1, "was prime"); - if (strcmp(buf, - "Landon Noll 1st proved that 2^23209-1 was prime") != 0) { + exit(1); + } + try_nthis("%s %d%s%d%d %s", sizeof(buf)-1, + "Landon Noll 1st proved that", 2, "^", 23209, -1, "was prime"); + if (strcmp(buf, + "Landon Noll 1st proved that 2^23209-1 was prime") != 0) { #if !defined(DONT_HAVE_VSNPRINTF) - /* with vsnprintf() didn't work */ + /* with vsnprintf() didn't work */ #else - /* with snprintf() simulating vsnprintf() didn't work */ + /* with snprintf() simulating vsnprintf() didn't work */ #endif - exit(1); - } + exit(1); + } - /* - * report the result - */ - puts("/* what type of variable args do we have? */"); - puts("#define VARARGS /* use */"); - puts("#include "); - puts("\n/* should we use vsnprintf() and vsnprintf()? */"); + /* + * report the result + */ + puts("/* what type of variable args do we have? */"); + puts("#define VARARGS /* use */"); + puts("#include "); + puts("\n/* should we use vsnprintf() and vsnprintf()? */"); #if !defined(DONT_HAVE_VSNPRINTF) - puts("#define HAVE_VSNPRINTF /* yes */"); + puts("#define HAVE_VSNPRINTF /* yes */"); #else - puts("/*"); - puts(" * Hack aleart!!!"); - puts(" *"); - puts(" * Systems that do not have vsnprintf() need something. In some"); - puts(" * cases the snprintf() function will deal correctly with the"); - puts(" * va_alist 4th arg. Same goes for a lack of an vsnprintf()"); - puts(" * function. In either case we use the #defines below and"); - puts(" * hope for the best!"); - puts(" */"); - puts("#define vsnprintf snprintf"); - puts("#undef HAVE_VSNPRINTF"); + puts("/*"); + puts(" * Hack aleart!!!"); + puts(" *"); + puts(" * Systems that do not have vsnprintf() need something. In some"); + puts(" * cases the snprintf() function will deal correctly with the"); + puts(" * va_alist 4th arg. Same goes for a lack of an vsnprintf()"); + puts(" * function. In either case we use the #defines below and"); + puts(" * hope for the best!"); + puts(" */"); + puts("#define vsnprintf snprintf"); + puts("#undef HAVE_VSNPRINTF"); #endif - /* exit(0); */ - return 0; + /* exit(0); */ + return 0; } diff --git a/help.c b/help.c index 7c53fbf..b204c23 100644 --- a/help.c +++ b/help.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/09/14 10:58:30 - * File existed as early as: 1997 + * Under source code control: 1997/09/14 10:58:30 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -46,59 +46,59 @@ #endif -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* * some help topics are symbols, so we alias them to nice filenames */ STATIC struct help_alias { - char *topic; - char *filename; + char *topic; + char *filename; } halias[] = { - /* We sort the list below via: sort -d -u */ - {"=", "address"}, - {"->", "arrow"}, - {"=", "assign"}, - {"*", "dereference"}, - {"%", "mod"}, - {".", "oldvalue"}, - {"#", "pound"}, - {"//", "quo"}, - {"COPYING_LGPL", "COPYING-LGPL"}, - {"COPYLEFT", "copyright"}, - {"COPYRIGHT", "copyright"}, - {"Copyleft", "copyright"}, - {"Copyright", "copyright"}, - {"abort", "command"}, - {"cd", "command"}, - {"copy", "blkcpy"}, - {"copying", "COPYING"}, - {"copying-lgpl", "COPYING-LGPL"}, - {"define", "command"}, - {"dm2d", "dms2d"}, - {"exit", "command"}, - {"gm2g", "gms2g"}, - {"hm2d", "hms2d"}, - {"man", "calc"}, - {"question", "questions"}, - {"quit", "command"}, - {"read", "command"}, - {"release", "releases"}, - {"show", "command"}, - {"stdlib", "resource"}, - {"usage", "calc"}, - {"write", "command"}, + /* We sort the list below via: sort -d -u */ + {"=", "address"}, + {"->", "arrow"}, + {"=", "assign"}, + {"*", "dereference"}, + {"%", "mod"}, + {".", "oldvalue"}, + {"#", "pound"}, + {"//", "quo"}, + {"COPYING_LGPL", "COPYING-LGPL"}, + {"COPYLEFT", "copyright"}, + {"COPYRIGHT", "copyright"}, + {"Copyleft", "copyright"}, + {"Copyright", "copyright"}, + {"abort", "command"}, + {"cd", "command"}, + {"copy", "blkcpy"}, + {"copying", "COPYING"}, + {"copying-lgpl", "COPYING-LGPL"}, + {"define", "command"}, + {"dm2d", "dms2d"}, + {"exit", "command"}, + {"gm2g", "gms2g"}, + {"hm2d", "hms2d"}, + {"man", "calc"}, + {"question", "questions"}, + {"quit", "command"}, + {"read", "command"}, + {"release", "releases"}, + {"show", "command"}, + {"stdlib", "resource"}, + {"usage", "calc"}, + {"write", "command"}, - /* MUST BE LAST! */ - {NULL, NULL} + /* MUST BE LAST! */ + {NULL, NULL} }; /* * external values */ -EXTERN char *pager; /* $PAGER or default */ +EXTERN char *pager; /* $PAGER or default */ /* @@ -111,75 +111,75 @@ EXTERN char *pager; /* $PAGER or default */ * to open the help file for reading as well as to exec the pager! * * given: - * stream open file stream of the file to send to the pager + * stream open file stream of the file to send to the pager */ S_FUNC void page_file(FILE *stream) { - FILE *cmd; /* pager command */ - char buf[BUFSIZ+1]; /* I/O buffer */ - char *fgets_ret; /* fgets() return value */ + FILE *cmd; /* pager command */ + char buf[BUFSIZ+1]; /* I/O buffer */ + char *fgets_ret; /* fgets() return value */ - /* - * flush any pending I/O - */ - fflush(stderr); - fflush(stdout); - fflush(stdin); + /* + * flush any pending I/O + */ + fflush(stderr); + fflush(stdout); + fflush(stdin); - /* - * form a write pipe to a pager - */ - if (pager == NULL || pager[0] == '\0') { - cmd = stdout; - } else { - cmd = popen(pager, "w"); - } - if (cmd == NULL) { - fprintf(stderr, "unable form pipe to pager: %s", pager); - return; - } + /* + * form a write pipe to a pager + */ + if (pager == NULL || pager[0] == '\0') { + cmd = stdout; + } else { + cmd = popen(pager, "w"); + } + if (cmd == NULL) { + fprintf(stderr, "unable form pipe to pager: %s", pager); + return; + } - /* - * read the help file and send non-## lines to the pager - * until EOF or error - */ - buf[BUFSIZ] = '\0'; - do { + /* + * read the help file and send non-## lines to the pager + * until EOF or error + */ + buf[BUFSIZ] = '\0'; + do { - /* - * read the next line that does not begin with ## - */ - buf[0] = '\0'; - while ((fgets_ret = fgets(buf, BUFSIZ, stream)) != NULL && - buf[0] == '#' && buf[1] == '#') { - } + /* + * read the next line that does not begin with ## + */ + buf[0] = '\0'; + while ((fgets_ret = fgets(buf, BUFSIZ, stream)) != NULL && + buf[0] == '#' && buf[1] == '#') { + } - /* - * stop reading when we reach EOF (or error) on help file - */ - if (fgets_ret == NULL) { - fflush(cmd); - break; - } + /* + * stop reading when we reach EOF (or error) on help file + */ + if (fgets_ret == NULL) { + fflush(cmd); + break; + } - /* - * write the line to pager, if possible - * - * We have to use fprintf() instead of fputs() because - * on NetBSD, fputs() function returns 0 on success and - # EOF on error. *sigh* - */ - } while (fprintf(cmd, "%s", buf) > 0); + /* + * write the line to pager, if possible + * + * We have to use fprintf() instead of fputs() because + * on NetBSD, fputs() function returns 0 on success and + # EOF on error. *sigh* + */ + } while (fprintf(cmd, "%s", buf) > 0); - /* - * all done, EOF or error, so just clean up - */ - (void) pclose(cmd); - fflush(stderr); - fflush(stdout); - fflush(stdin); - return; + /* + * all done, EOF or error, so just clean up + */ + (void) pclose(cmd); + fflush(stderr); + fflush(stdout); + fflush(stdin); + return; } @@ -187,144 +187,144 @@ page_file(FILE *stream) * givehelp - display a help file * * given: - * type the type of help to give, NULL => index + * type the type of help to give, NULL => index */ void givehelp(char *type) { - struct help_alias *p; /* help alias being considered */ - FILE *stream; /* help file stream */ - char *helppath; /* path to the help file */ - char *c; - size_t snprintf_len; /* malloced snprintf buffer length */ + struct help_alias *p; /* help alias being considered */ + FILE *stream; /* help file stream */ + char *helppath; /* path to the help file */ + char *c; + size_t snprintf_len; /* malloced snprintf buffer length */ - /* - * check permissions to see if we are allowed to help - */ - if (!allow_exec || !allow_read) { - fprintf(stderr, - "sorry, help is only allowed with -m mode 5 or 7\n"); - return; - } + /* + * check permissions to see if we are allowed to help + */ + if (!allow_exec || !allow_read) { + fprintf(stderr, + "sorry, help is only allowed with -m mode 5 or 7\n"); + return; + } - /* catch the case where we just print the index */ - if (type == NULL) { - type = DEFAULTCALCHELP; /* the help index file */ - } + /* catch the case where we just print the index */ + if (type == NULL) { + type = DEFAULTCALCHELP; /* the help index file */ + } - /* alias the type of help, if needed */ - for (p=halias; p->topic; ++p) { - if (strcmp(type, p->topic) == 0) { - type = p->filename; - break; - } - } + /* alias the type of help, if needed */ + for (p=halias; p->topic; ++p) { + if (strcmp(type, p->topic) == 0) { + type = p->filename; + break; + } + } - /* - * sanity check on name - */ - /* look for /. or a leading . */ - if (strstr(type, "/.") != NULL || type[0] == '.') { - fprintf(stderr, "bad help name\n"); - return; - } - /* look for chars that could be shell meta chars */ - for (c = type; *c; ++c) { - switch ((int)*c) { - case '+': - case ',': - case '-': - case '.': - case '/': - case '_': - break; - default: - if (!isascii((int)*c) || !isalnum((int)*c)) { - fprintf(stderr, "bogus char in help name\n"); - return; - } - break; - } - } + /* + * sanity check on name + */ + /* look for /. or a leading . */ + if (strstr(type, "/.") != NULL || type[0] == '.') { + fprintf(stderr, "bad help name\n"); + return; + } + /* look for chars that could be shell meta chars */ + for (c = type; *c; ++c) { + switch ((int)*c) { + case '+': + case ',': + case '-': + case '.': + case '/': + case '_': + break; + default: + if (!isascii((int)*c) || !isalnum((int)*c)) { + fprintf(stderr, "bogus char in help name\n"); + return; + } + break; + } + } - /* - * special case for Copyright and Copyleft - */ - if (strcmp(type, "copyright") == 0) { - fputs(Copyright, stdout); - fflush(stdout); - return; - } + /* + * special case for Copyright and Copyleft + */ + if (strcmp(type, "copyright") == 0) { + fputs(Copyright, stdout); + fflush(stdout); + return; + } - /* - * open the helpfile (looking in HELPDIR first) - */ - snprintf_len = strlen(calc_helpdir)+1+strlen(type) + 1; - helppath = (char *)malloc(snprintf_len+1); - if (helppath == NULL) { - fprintf(stderr, "malloc failure in givehelp #0\n"); - return; - } - snprintf(helppath, snprintf_len, "%s/%s", calc_helpdir, type); - helppath[snprintf_len] = '\0'; /* paranoia */ - errno = 0; - stream = fopen(helppath, "r"); - if (stream != NULL) { + /* + * open the helpfile (looking in HELPDIR first) + */ + snprintf_len = strlen(calc_helpdir)+1+strlen(type) + 1; + helppath = (char *)malloc(snprintf_len+1); + if (helppath == NULL) { + fprintf(stderr, "malloc failure in givehelp #0\n"); + return; + } + snprintf(helppath, snprintf_len, "%s/%s", calc_helpdir, type); + helppath[snprintf_len] = '\0'; /* paranoia */ + errno = 0; + stream = fopen(helppath, "r"); + if (stream != NULL) { - /* - * we have the help file open, now display it - */ - page_file(stream); - (void) fclose(stream); + /* + * we have the help file open, now display it + */ + page_file(stream); + (void) fclose(stream); #if defined(CUSTOM) - /* - * open the helpfile (looking in CUSTOMHELPDIR last) - */ - } else { - char *cust_helppath; /* path to the custom help file */ - size_t cust_snprintf_len; /* malloced custom snprintf buf len */ + /* + * open the helpfile (looking in CUSTOMHELPDIR last) + */ + } else { + char *cust_helppath; /* path to the custom help file */ + size_t cust_snprintf_len; /* malloced custom snprintf buf len */ - cust_snprintf_len = - strlen(calc_customhelpdir)+1+strlen(type) + 1; - cust_helppath = (char *)malloc(cust_snprintf_len+1); - if (cust_helppath == NULL) { - fprintf(stderr, "malloc failure for givehelp #1\n"); - return; - } - snprintf(cust_helppath, cust_snprintf_len, - "%s/%s", calc_customhelpdir, type); - cust_helppath[cust_snprintf_len] = '\0'; /* paranoia */ - errno = 0; - stream = fopen(cust_helppath, "r"); - if (stream != NULL) { + cust_snprintf_len = + strlen(calc_customhelpdir)+1+strlen(type) + 1; + cust_helppath = (char *)malloc(cust_snprintf_len+1); + if (cust_helppath == NULL) { + fprintf(stderr, "malloc failure for givehelp #1\n"); + return; + } + snprintf(cust_helppath, cust_snprintf_len, + "%s/%s", calc_customhelpdir, type); + cust_helppath[cust_snprintf_len] = '\0'; /* paranoia */ + errno = 0; + stream = fopen(cust_helppath, "r"); + if (stream != NULL) { - /* - * we have the help file open, now display it - */ - page_file(stream); - (void) fclose(stream); + /* + * we have the help file open, now display it + */ + page_file(stream); + (void) fclose(stream); - /* unable to open help file */ - } else { - fprintf(stderr, "unable to open help file: %s - %s\n", - type, strerror(errno)); - } - free(cust_helppath); - cust_helppath = NULL; + /* unable to open help file */ + } else { + fprintf(stderr, "unable to open help file: %s - %s\n", + type, strerror(errno)); + } + free(cust_helppath); + cust_helppath = NULL; #else /* CUSTOM */ - /* unable to open help file */ - } else { - fprintf(stderr, "unable to open help file: %s - %s\n", - type, strerror(errno)); + /* unable to open help file */ + } else { + fprintf(stderr, "unable to open help file: %s - %s\n", + type, strerror(errno)); #endif /* CUSTOM */ - } + } - /* - * cleanup - */ - free(helppath); - helppath = NULL; - return; + /* + * cleanup + */ + free(helppath); + helppath = NULL; + return; } diff --git a/help/abs b/help/abs index f57ade7..fe449aa 100644 --- a/help/abs +++ b/help/abs @@ -11,11 +11,11 @@ TYPES For non-object x and eps: - x number (real or complex) - eps ignored if x is real, nonzero real for complex x, - defaults to epsilon(). + x number (real or complex) + eps ignored if x is real, nonzero real for complex x, + defaults to epsilon(). - return non-negative real + return non-negative real DESCRIPTION If x is real, returns the absolute value of x, i.e. x if x >= 0, @@ -52,7 +52,7 @@ SEE ALSO ## ## 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 +## 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 @@ -60,8 +60,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 01:40:22 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 01:40:22 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/access b/help/access index aee4645..4a99046 100644 --- a/help/access +++ b/help/access @@ -5,10 +5,10 @@ SYNOPSIS access(name [, mode]) TYPES - name string - mode integer or string containing only 'r', 'w', 'x' characters + name string + mode integer or string containing only 'r', 'w', 'x' characters - return null value or error + return null value or error DESCRIPTION access(name) or access(name, 0) or access(name, "") returns the null @@ -25,18 +25,18 @@ EXAMPLE ; !rm -f junk ; access("junk") - System error 2 + System error 2 ; strerror(.) - "No such file or directory" + "No such file or directory" ; f = fopen("junk", "w") ; access("junk") ; fputs(f, "Alpha") ; fclose(f) ; !chmod u-w junk ; access("junk", "w") - System error 13 + System error 13 ; strerror(.) - "Permission denied" + "Permission denied" LIMITS There may be implementation-dependent limits inherited from the @@ -56,7 +56,7 @@ SEE ALSO ## ## 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 +## 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 @@ -64,8 +64,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:36:20 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:36:20 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/acos b/help/acos index 3e87e7d..f086b4b 100644 --- a/help/acos +++ b/help/acos @@ -5,10 +5,10 @@ SYNOPSIS acos(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the inverse trigonometric cosine of x to a multiple of eps with error less in @@ -61,14 +61,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 1999,2023 Landon Curt Noll ## @@ -78,7 +78,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -86,8 +86,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 01:40:23 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 01:40:23 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/acosh b/help/acosh index 9339d73..ebf62b4 100644 --- a/help/acosh +++ b/help/acosh @@ -5,10 +5,10 @@ SYNOPSIS acosh(x [,eps]) TYPES - x real, x >= 1 - eps 0 < real < 1, defaults to epsilon() + x real, x >= 1 + eps 0 < real < 1, defaults to epsilon() - return nonnegative real + return nonnegative real DESCRIPTION Returns the acosh of x to a multiple of eps with error less in @@ -17,7 +17,7 @@ DESCRIPTION acosh(x) is the nonnegative real number v for which cosh(v) = x. It is given by - acosh(x) = ln(x + sqrt(x^2 - 1)) + acosh(x) = ln(x + sqrt(x^2 - 1)) EXAMPLE ; print acosh(2, 1e-5), acosh(2, 1e-10), acosh(2, 1e-15), acosh(2, 1e-20) @@ -42,7 +42,7 @@ SEE ALSO ## ## 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 +## 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 @@ -50,8 +50,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 01:40:24 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 01:40:24 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/acot b/help/acot index 873c41c..875e119 100644 --- a/help/acot +++ b/help/acot @@ -5,10 +5,10 @@ SYNOPSIS acot(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the inverse trigonometric cotangent of x to a multiple of eps with error less in @@ -61,14 +61,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 1999,2021,2023 Landon Curt Noll ## @@ -78,7 +78,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -86,8 +86,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/13 03:49:00 -## File existed as early as: 1995 +## Under source code control: 1995/11/13 03:49:00 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/acoth b/help/acoth index 7f17f13..26790f9 100644 --- a/help/acoth +++ b/help/acoth @@ -5,10 +5,10 @@ SYNOPSIS acoth(x [,eps]) TYPES - x real, with abs(x) > 1 - eps 0 < real < 1, defaults to epsilon() + x real, with abs(x) > 1 + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the acoth of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION acoth(x) is the real number v for which coth(v) = x. It is given by - acoth(x) = ln((x + 1)/(x - 1))/2 + acoth(x) = ln((x + 1)/(x - 1))/2 EXAMPLE ; print acoth(2, 1e-5), acoth(2, 1e-10), acoth(2, 1e-15), acoth(2, 1e-20) @@ -41,7 +41,7 @@ SEE ALSO ## ## 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 +## 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 @@ -49,8 +49,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/13 03:49:01 -## File existed as early as: 1995 +## Under source code control: 1995/11/13 03:49:01 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/acovercos b/help/acovercos index 2d4ebbf..dc1afcf 100644 --- a/help/acovercos +++ b/help/acovercos @@ -5,10 +5,10 @@ SYNOPSIS acovercos(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the inverse coversed trigonometric cosine of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called acvc, or arccovercos, is equivalent to: - acovercos(x) = asin(x - 1) + acovercos(x) = asin(x - 1) EXAMPLE ; print acovercos(0), acovercos(0.5), acovercos(1) @@ -60,14 +60,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -77,7 +77,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -85,8 +85,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/05 23:30:08 -## File existed as early as: 2023 +## Under source code control: 2023/09/05 23:30:08 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/acoversin b/help/acoversin index 4d7dd4c..8e59fb6 100644 --- a/help/acoversin +++ b/help/acoversin @@ -5,10 +5,10 @@ SYNOPSIS acoversin(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the inverse coversed trigonometric sine of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called acovers, or acvs, or arccoversin, is equivalent to: - acoversin(x) = asin(1 - x) + acoversin(x) = asin(1 - x) EXAMPLE ; print acoversin(0), acoversin(0.5), acoversin(1) @@ -60,14 +60,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -77,7 +77,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -85,8 +85,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/08/31 23:07:08 -## File existed as early as: 2023 +## Under source code control: 2023/08/31 23:07:08 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/acrd b/help/acrd index a61c637..0ce4b70 100644 --- a/help/acrd +++ b/help/acrd @@ -5,10 +5,10 @@ SYNOPSIS acrd(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate angle of unit circle chord of length x to a multiple of eps with error less in @@ -19,7 +19,7 @@ DESCRIPTION This function is sometimes called chord, is equivalent to: - acrd(x) = 2 * asin(x / 2) + acrd(x) = 2 * asin(x / 2) EXAMPLE ; print acrd(1/2), acrd(5/7), acrd(42/7) @@ -57,14 +57,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -74,7 +74,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -82,8 +82,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/10/02 16:49:42 -## File existed as early as: 2023 +## Under source code control: 2023/10/02 16:49:42 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/acsc b/help/acsc index d6f4e12..83bae0f 100644 --- a/help/acsc +++ b/help/acsc @@ -5,10 +5,10 @@ SYNOPSIS acsc(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the inverse trigonometric cosecant of x to a multiple of eps with error less in @@ -64,14 +64,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 1999,2021,2023 Landon Curt Noll ## @@ -81,7 +81,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -89,8 +89,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/13 03:49:00 -## File existed as early as: 1995 +## Under source code control: 1995/11/13 03:49:00 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/acsch b/help/acsch index 9ac26a3..5fc505d 100644 --- a/help/acsch +++ b/help/acsch @@ -5,10 +5,10 @@ SYNOPSIS acsch(x [,eps]) TYPES - x nonzero real - eps 0 < real < 1, defaults to epsilon() + x nonzero real + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the acsch of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION acsch(x) is the real number v for which csch(v) = x. It is given by - acsch(x) = ln((1 + sqrt(1 + x^2))/x) + acsch(x) = ln((1 + sqrt(1 + x^2))/x) EXAMPLE ; print acsch(2, 1e-5), acsch(2, 1e-10), acsch(2, 1e-15), acsch(2, 1e-20) @@ -41,7 +41,7 @@ SEE ALSO ## ## 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 +## 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 @@ -49,8 +49,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/13 03:49:01 -## File existed as early as: 1995 +## Under source code control: 1995/11/13 03:49:01 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/address b/help/address index 4a943b2..5a499aa 100644 --- a/help/address +++ b/help/address @@ -5,9 +5,9 @@ SYNOPSIS &X TYPES - X expression specifying an octet, lvalue, string or number + X expression specifying an octet, lvalue, string or number - return pointer + return pointer DESCRIPTION &X returns the address at which information for determining the current @@ -20,7 +20,7 @@ DESCRIPTION otherwise accessing, such a vacated address may be catastrophic. An octet is normally expressed by B[i] where B is a block and - 0 <= i < sizeof(B). &B[i] then returns the address at which this + 0 <= i < sizeof(B). &B[i] then returns the address at which this octet is located until the block is freed or relocated. Freeing of an unnamed block B occurs when a new value is assigned to B or when B ceases to exist; a named block B is freed by blkfree(B). @@ -38,7 +38,7 @@ DESCRIPTION &X with that component or element depends only on the continued existence of the matrix or object. For example, after - ; mat A[3] + ; mat A[3] the addresses &A[0], &A[1], &A[2] locate the three elements of the matrix specified by A until another value is assigned to A, etc. @@ -60,15 +60,15 @@ DESCRIPTION results refer to octets in the same block or existing components of the same matrix or object. For example, immediately after - ; mat A[10] - ; p = &A[5] + ; mat A[10] + ; p = &A[5] it is permitted to use expressions like p + 4, p - 5, p++ . Strings defined literally have fixed addresses, e.g., after - ; p = &"abc" - ; A = "abc" + ; p = &"abc" + ; A = "abc" the address &*A of the value of A will be equal to p. @@ -78,7 +78,7 @@ DESCRIPTION be usable only while the variables retain these defined values. For example, after - ; B = C = strcat("a", "bc"); + ; B = C = strcat("a", "bc"); &*B and &*C will be different. If p is defined by p = &*B, p should not be used after a new value is assigned to B, or B ceases to exist, @@ -91,12 +91,12 @@ DESCRIPTION so long as the number remains associated with at least one function or lvalue. For example, after - ; x = 27; - ; y = 3 * 9; - ; define f(a) = 27 + a; + ; x = 27; + ; y = 3 * 9; + ; define f(a) = 27 + a; the three occurrences of 27 have the same address which may be displayed - by any of &27, &*x, &*y and &f(0). If x and y are assigned + by any of &27, &*x, &*y and &f(0). If x and y are assigned other values and f is redefined or undefined and the 27 has not been stored elsewhere (e.g. as the "old value" or in another function definition or as an element in an association), the address assigned at @@ -105,17 +105,17 @@ DESCRIPTION When a function returns a number value, that number value is usually placed at a newly allocated address, even if an equal number is stored - elsewhere. For example calls to f(a), as defined above, with the same + elsewhere. For example calls to f(a), as defined above, with the same non-zero value for a will be assigned to different addresses as can be seen from printing &*A, &*B, &*C after - ; A = f(2); B = f(2); C = f(2); + ; A = f(2); B = f(2); C = f(2); (the case of f(0) is exceptional since 27 + 0 simply copies the 27 rather than creating a new number value). Here it is clearly more efficient to use - ; A = B = C = f(2); + ; A = B = C = f(2); which, not only performs the addition in f() only once, but stores the number values for A, B and C at the same address. @@ -168,7 +168,7 @@ SEE ALSO ## ## 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 +## 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 @@ -176,8 +176,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/09/06 20:03:34 -## File existed as early as: 1997 +## Under source code control: 1997/09/06 20:03:34 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/aexcsc b/help/aexcsc index adb14fe..f4f5941 100644 --- a/help/aexcsc +++ b/help/aexcsc @@ -5,10 +5,10 @@ SYNOPSIS aexcsc(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the inverse exterior trigonometric cscant of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called arcexcsc, is equivalent to: - aexcsc(x) = acsc(x + 1) + aexcsc(x) = acsc(x + 1) EXAMPLE ; print aexcsc(0), aexcsc(0.5), aexcsc(1) @@ -66,14 +66,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -83,7 +83,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -91,8 +91,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/30 23:22:21 -## File existed as early as: 2023 +## Under source code control: 2023/09/30 23:22:21 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/aexsec b/help/aexsec index 521c980..ec18120 100644 --- a/help/aexsec +++ b/help/aexsec @@ -5,10 +5,10 @@ SYNOPSIS aexsec(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the inverse trigonometric secant of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called arcexsec, is equivalent to: - aexsec(x) = asec(x + 1) + aexsec(x) = asec(x + 1) EXAMPLE ; print aexsec(0), aexsec(0.5), aexsec(1) @@ -63,14 +63,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -80,7 +80,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -88,8 +88,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/10/01 00:20:20 -## File existed as early as: 2023 +## Under source code control: 2023/10/01 00:20:20 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/agd b/help/agd index 25d9d07..6d9f4e2 100644 --- a/help/agd +++ b/help/agd @@ -5,10 +5,10 @@ SYNOPSIS agd(z [,eps]) TYPES - z number (real or complex) - eps nonzero real, defaults to epsilon() + z number (real or complex) + eps nonzero real, defaults to epsilon() - return number or infinite error value + return number or infinite error value DESCRIPTION Calculate the inverse Gudermannian of z to a multiple of eps with @@ -19,11 +19,11 @@ DESCRIPTION agd(z) is usually defined initially for real z with abs(z) < pi/2 by one of the formulae - agd(z) = ln(sec(z) + tan(z)) + agd(z) = ln(sec(z) + tan(z)) - = 2 * atanh(tan(z/2)) + = 2 * atanh(tan(z/2)) - = asinh(tan(z)), + = asinh(tan(z)), or as the integral from 0 to z of (1/cos(t))dt. For complex z, the principal branch, approximated by gd(z, eps), has cuts along the real @@ -31,7 +31,7 @@ DESCRIPTION If z = x + i * y and abs(x) < pi/2, agd(z) is given by - agd(z) = atanh(sin(x)/cosh(y)) + i * atan(sinh(y)/cos(x)> + agd(z) = atanh(sin(x)/cosh(y)) + i * atan(sinh(y)/cos(x)> EXAMPLE ; print agd(1, 1e-5), agd(1, 1e-10), agd(1, 1e-15) @@ -63,7 +63,7 @@ SEE ALSO ## ## 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 +## 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 @@ -71,8 +71,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/09/06 20:03:34 -## File existed as early as: 1997 +## Under source code control: 1997/09/06 20:03:34 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ahacovercos b/help/ahacovercos index 9262dba..eb52563 100644 --- a/help/ahacovercos +++ b/help/ahacovercos @@ -5,10 +5,10 @@ SYNOPSIS ahacovercos(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the inverse half coversed trigonometric cosine of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called ahacvc, or archacovercos, or archacovercosine, is equivalent to: - ahacovercos(x) = asin(2*x - 1) + ahacovercos(x) = asin(2*x - 1) EXAMPLE ; print ahacovercos(0), ahacovercos(0.5), ahacovercos(1) @@ -63,14 +63,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -80,7 +80,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -88,8 +88,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/24 11:16:08 -## File existed as early as: 2023 +## Under source code control: 2023/09/24 11:16:08 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ahacoversin b/help/ahacoversin index 2229935..12ba3d8 100644 --- a/help/ahacoversin +++ b/help/ahacoversin @@ -5,10 +5,10 @@ SYNOPSIS ahacoversin(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the inverse half coversed trigonometric sine of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called ahacovers, or ahacvs, or archacoversin, is equivalent to: - ahacoversin(x) = asin(1 - 2*x) + ahacoversin(x) = asin(1 - 2*x) EXAMPLE ; print ahacoversin(0), ahacoversin(0.5), ahacoversin(1) @@ -63,14 +63,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -80,7 +80,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -88,8 +88,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/24 11:17:28 -## File existed as early as: 2023 +## Under source code control: 2023/09/24 11:17:28 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ahavercos b/help/ahavercos index 9f6e4af..23ccd22 100644 --- a/help/ahavercos +++ b/help/ahavercos @@ -5,10 +5,10 @@ SYNOPSIS ahavercos(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the inverse half versed trigonometric cosine of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called ahaverc, or archavercos, or archavercosine, is equivalent to: - ahavercos(x) = acos(2*x - 1) + ahavercos(x) = acos(2*x - 1) EXAMPLE ; print ahavercos(0), ahavercos(0.5), ahavercos(1) @@ -64,14 +64,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -81,7 +81,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -89,8 +89,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/24 11:18:04 -## File existed as early as: 2023 +## Under source code control: 2023/09/24 11:18:04 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ahaversin b/help/ahaversin index eb23265..8581e9b 100644 --- a/help/ahaversin +++ b/help/ahaversin @@ -5,10 +5,10 @@ SYNOPSIS ahaversin(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the inverse half versed trigonometric sine of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called ahavers, or archaversin, is equivalent to: - ahaversin(x) = acos(1 - 2*x) + ahaversin(x) = acos(1 - 2*x) EXAMPLE ; print ahaversin(0), ahaversin(0.5), ahaversin(1) @@ -64,14 +64,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -81,7 +81,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -89,8 +89,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/24 11:19:54 -## File existed as early as: 2023 +## Under source code control: 2023/09/24 11:19:54 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/append b/help/append index e510c43..b3891fc 100644 --- a/help/append +++ b/help/append @@ -5,10 +5,10 @@ SYNOPSIS append(x, y_0, y_1, ...) TYPES - x lvalue whose value is a list - y_0, ... any + x lvalue whose value is a list + y_0, ... any - return null value + return null value DESCRIPTION If after evaluation of y_0, y_1, ..., x is a list with contents @@ -68,7 +68,7 @@ SEE ALSO ## ## 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 +## 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 @@ -76,8 +76,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 03:13:17 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 03:13:17 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/appr b/help/appr index 2302001..f70842a 100644 --- a/help/appr +++ b/help/appr @@ -5,11 +5,11 @@ SYNOPSIS appr(x [,y [,z]]) TYPES - x real, complex, matrix, list - y real - z integer + x real, complex, matrix, list + y real + z integer - return same type as x except that complex x may return a real number + return same type as x except that complex x may return a real number DESCRIPTION Return the approximate value of x as specified by a specific error @@ -24,77 +24,77 @@ DESCRIPTION In the following it is assumed y is nonzero and x is not a multiple of y. For real x: - appr(x,y,z) is either the nearest multiple of y greater - than x or the nearest multiple of y less than x. Thus, if - we write a = appr(x,y,z) and r = x - a, then a/y is an integer - and abs(r) < abs(y). If r > 0, we say x has been "rounded down" - to a; if r < 0, the rounding is "up". For particular x and y, - whether the rounding is down or up is determined by z. + appr(x,y,z) is either the nearest multiple of y greater + than x or the nearest multiple of y less than x. Thus, if + we write a = appr(x,y,z) and r = x - a, then a/y is an integer + and abs(r) < abs(y). If r > 0, we say x has been "rounded down" + to a; if r < 0, the rounding is "up". For particular x and y, + whether the rounding is down or up is determined by z. - Only the 5 lowest bits of z are used, so we may assume z has been - replaced by its value modulo 32. The type of rounding depends on - z as follows: + Only the 5 lowest bits of z are used, so we may assume z has been + replaced by its value modulo 32. The type of rounding depends on + z as follows: - z = 0 round down or up according as y is positive or negative, - sgn(r) = sgn(y) + z = 0 round down or up according as y is positive or negative, + sgn(r) = sgn(y) - z = 1 round up or down according as y is positive or negative, - sgn(r) = -sgn(y) + z = 1 round up or down according as y is positive or negative, + sgn(r) = -sgn(y) - z = 2 round towards zero, sgn(r) = sgn(x) + z = 2 round towards zero, sgn(r) = sgn(x) - z = 3 round away from zero, sgn(r) = -sgn(x) + z = 3 round away from zero, sgn(r) = -sgn(x) - z = 4 round down, r > 0 + z = 4 round down, r > 0 - z = 5 round up, r < 0 + z = 5 round up, r < 0 - z = 6 round towards or from zero according as y is positive or - negative, sgn(r) = sgn(x/y) + z = 6 round towards or from zero according as y is positive or + negative, sgn(r) = sgn(x/y) - z = 7 round from or towards zero according as y is positive or - negative, sgn(r) = -sgn(x/y) + z = 7 round from or towards zero according as y is positive or + negative, sgn(r) = -sgn(x/y) - z = 8 a/y is even + z = 8 a/y is even - z = 9 a/y is odd + z = 9 a/y is odd - z = 10 a/y is even or odd according as x/y is positive or negative + z = 10 a/y is even or odd according as x/y is positive or negative - z = 11 a/y is odd or even according as x/y is positive or negative + z = 11 a/y is odd or even according as x/y is positive or negative - z = 12 a/y is even or odd according as y is positive or negative + z = 12 a/y is even or odd according as y is positive or negative - z = 13 a/y is odd or even according as y is positive or negative + z = 13 a/y is odd or even according as y is positive or negative - z = 14 a/y is even or odd according as x is positive or negative + z = 14 a/y is even or odd according as x is positive or negative - z = 15 a/y is odd or even according as x is positive or negative + z = 15 a/y is odd or even according as x is positive or negative - z = 16 to 31 abs(r) <= abs(y)/2; if there is a unique multiple - of y that is nearest x, appr(x,y,z) is that multiple of y - and then abs(r) < abs(y)/2. If x is midway between - successive multiples of y, then abs(r) = abs(y)/2 and - the value of a is as given by appr(x, y, z-16). + z = 16 to 31 abs(r) <= abs(y)/2; if there is a unique multiple + of y that is nearest x, appr(x,y,z) is that multiple of y + and then abs(r) < abs(y)/2. If x is midway between + successive multiples of y, then abs(r) = abs(y)/2 and + the value of a is as given by appr(x, y, z-16). Matrix or List x: - appr(x,y,z) returns the matrix or list indexed in the same way as x, - in which each element t has been replaced by appr(t,y,z). + appr(x,y,z) returns the matrix or list indexed in the same way as x, + in which each element t has been replaced by appr(t,y,z). Complex x: - Returns appr(re(x), y, z) + appr(im(x), y, z) * 1i + Returns appr(re(x), y, z) + appr(im(x), y, z) * 1i PROPERTIES - If appr(x,y,z) != x, then abs(x - appr(x,y,z)) < abs(y). + If appr(x,y,z) != x, then abs(x - appr(x,y,z)) < abs(y). - If appr(x,y,z) != x and 16 <= z <= 31, abs(x - appr(x,y,z)) <= abs(y)/2. + If appr(x,y,z) != x and 16 <= z <= 31, abs(x - appr(x,y,z)) <= abs(y)/2. - For z = 0, 1, 4, 5, 16, 17, 20 or 21, and any integer n, - appr(x + n*y, y, z) = appr(x, y, z) + n * y. + For z = 0, 1, 4, 5, 16, 17, 20 or 21, and any integer n, + appr(x + n*y, y, z) = appr(x, y, z) + n * y. - If y is nonzero, appr(x,y,8)/y = an odd integer n only if x = n * y. + If y is nonzero, appr(x,y,8)/y = an odd integer n only if x = n * y. EXAMPLE ; print appr(-5.44,0.1,0), appr(5.44,0.1,0), appr(5.7,1,0), appr(-5.7,1,0) @@ -159,7 +159,7 @@ SEE ALSO ## ## 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 +## 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 @@ -167,8 +167,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/25 17:18:21 -## File existed as early as: 1994 +## Under source code control: 1994/09/25 17:18:21 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/archive b/help/archive index acd4415..5bd5e39 100644 --- a/help/archive +++ b/help/archive @@ -2,11 +2,11 @@ Where to get the latest versions of calc Official calc source is maintained on GitHub: - https://github.com/lcn2/calc + https://github.com/lcn2/calc Calc releases may be found as GitHub tagged releases: - https://github.com/lcn2/calc/releases?page=2 + https://github.com/lcn2/calc/releases?page=2 At the bottom of a given release is a "> Assets" that may be opened to reveal down-loadable files such as source @@ -14,7 +14,7 @@ Where to get the latest versions of calc Landon Noll also maintains a calc home page at: - http://www.isthe.com/chongo/tech/comp/calc/ + http://www.isthe.com/chongo/tech/comp/calc/ Landon Curt Noll http://www.isthe.com/chongo/ @@ -29,7 +29,7 @@ chongo /\../\ ## ## 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 +## 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 @@ -37,8 +37,8 @@ chongo /\../\ ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/06/13 02:51:48 -## File existed as early as: 1996 +## Under source code control: 1996/06/13 02:51:48 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/arg b/help/arg index 12aaf05..a27bed1 100644 --- a/help/arg +++ b/help/arg @@ -5,10 +5,10 @@ SYNOPSIS arg(x [,eps]) TYPES - x number - eps nonzero real, defaults to epsilon() + x number + eps nonzero real, defaults to epsilon() - return real + return real DESCRIPTION Returns the argument of x to the nearest or next to nearest multiple of @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/25 20:22:31 -## File existed as early as: 1994 +## Under source code control: 1994/09/25 20:22:31 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/argv b/help/argv index aeb009a..99e79d6 100644 --- a/help/argv +++ b/help/argv @@ -5,9 +5,9 @@ SYNOPSIS argv([n]) TYPES - n nonnegative integer + n nonnegative integer - return any + return any DESCRIPTION Without args, this builtin returns the number of calc command line @@ -22,16 +22,16 @@ DESCRIPTION assuming the calc is located in /usr/local/bin/calc, the first line of a calc script would be: - #!/usr/local/bin/calc -f - ... + #!/usr/local/bin/calc -f + ... then argv(0) will refer to the filename of the script. As it is common to use -q in a calc script, and using that same /usr/local/bin/calc location: - #!/usr/local/bin/calc -q -f - ... + #!/usr/local/bin/calc -q -f + ... and again, argv(0) will refer to the filename of the script. @@ -43,14 +43,14 @@ DESCRIPTION However, if calc is invoked with -s, all non-dashed options will be left as unevaluated strings. Thus: - calc -i 2+2 + calc -i 2+2 will cause calc to print 4 and enter interactive mode. In this case argv() will return 1. On the other hand: - calc -i -s 2+2 + calc -i -s 2+2 will cause calc to interactive mode. The argv() builtin will return 2 and argv(1) will return the string "2+2". @@ -84,7 +84,7 @@ SEE ALSO ## ## 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 +## 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 @@ -92,8 +92,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1999/11/23 19:45:05 -## File existed as early as: 1999 +## Under source code control: 1999/11/23 19:45:05 +## File existed as early as: 1999 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/arrow b/help/arrow index 887cccd..0aaec9a 100644 --- a/help/arrow +++ b/help/arrow @@ -1,14 +1,14 @@ SYMBOL and NAME - -> - arrow operator + -> - arrow operator SYNOPSIS p -> X TYPES - p pointer to an lvalue - X identifier + p pointer to an lvalue + X identifier - return lvalue + return lvalue DESCRIPTION p->X returns the same as (*p).X. Thus the current value of *p is @@ -28,17 +28,17 @@ EXAMPLE ; p = &A ; p->one = 1; p->two = 2 ; A - obj pair {1, 2} + obj pair {1, 2} ; A->two = &B ; p->one = 3; p->two = 4 ; *p - obj pair {3, 4} + obj pair {3, 4} ; B = {5,6} ; *p->two - 4 + 4 LIMITS none @@ -57,7 +57,7 @@ SEE ALSO ## ## 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 +## 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 @@ -65,8 +65,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/09/06 20:03:34 -## File existed as early as: 1997 +## Under source code control: 1997/09/06 20:03:34 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/asec b/help/asec index 6676817..8c40ad6 100644 --- a/help/asec +++ b/help/asec @@ -5,10 +5,10 @@ SYNOPSIS asec(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the inverse trigonometric secant of x to a multiple of eps with error less in @@ -61,14 +61,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 1999,2021,2023 Landon Curt Noll ## @@ -78,7 +78,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -86,8 +86,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/13 03:49:00 -## File existed as early as: 1995 +## Under source code control: 1995/11/13 03:49:00 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/asech b/help/asech index 3b31ff2..3d91087 100644 --- a/help/asech +++ b/help/asech @@ -5,10 +5,10 @@ SYNOPSIS asech(x [,eps]) TYPES - x real, 0 < x <= 1 - eps 0 < real < 1, defaults to epsilon() + x real, 0 < x <= 1 + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the asech of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION asech(x) is the real number v for which sech(v) = x. It is given by - asech(x) = ln((1 + sqrt(1 - x^2))/x) + asech(x) = ln((1 + sqrt(1 - x^2))/x) EXAMPLE ; print asech(.5,1e-5), asech(.5,1e-10), asech(.5,1e-15), asech(.5,1e-20) @@ -41,7 +41,7 @@ SEE ALSO ## ## 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 +## 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 @@ -49,8 +49,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/13 03:49:00 -## File existed as early as: 1995 +## Under source code control: 1995/11/13 03:49:00 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/asin b/help/asin index 429b28a..5300a52 100644 --- a/help/asin +++ b/help/asin @@ -5,10 +5,10 @@ SYNOPSIS asin(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the inverse trigonometric sine of x to a multiple of eps with error less in @@ -61,14 +61,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 1999,2021,2023 Landon Curt Noll ## @@ -78,7 +78,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -86,8 +86,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 01:40:24 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 01:40:24 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/asinh b/help/asinh index 25b5ec0..f1bce43 100644 --- a/help/asinh +++ b/help/asinh @@ -5,10 +5,10 @@ SYNOPSIS asinh(x [,eps]) TYPES - x real - eps 0 < real < 1, defaults to epsilon() + x real + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the asinh of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION asinh(x) is the real number v for which sinh(v) = x. It is given by - asinh(x) = ln(x + sqrt(1 + x^2)) + asinh(x) = ln(x + sqrt(1 + x^2)) EXAMPLE ; print asinh(2, 1e-5), asinh(2, 1e-10), asinh(2, 1e-15), asinh(2, 1e-20) @@ -41,7 +41,7 @@ SEE ALSO ## ## 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 +## 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 @@ -49,8 +49,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 01:40:25 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 01:40:25 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/assign b/help/assign index 32640c7..9c075b3 100644 --- a/help/assign +++ b/help/assign @@ -6,14 +6,14 @@ SYNOPSIS a = {e_1, e_2, ...[ { ... } ] } TYPES - a lvalue, current value a structure in { } case + a lvalue, current value a structure in { } case - b expression + b expression - e_0, e_1, ... expressions, blanks, or initializer lists + e_0, e_1, ... expressions, blanks, or initializer lists - return lvalue (a) + return lvalue (a) DESCRIPTION Here an lvalue is either a simple variable specified by an identifier, @@ -22,7 +22,7 @@ DESCRIPTION An initializer list is a comma-separated list enclosed in braces as in - {e_0, e_1, ... } + {e_0, e_1, ... } where each e_i is an expression, blank or initializer list. @@ -44,7 +44,7 @@ DESCRIPTION In simple assignments, = associates from right to left so that, for example, - a = b = c + a = b = c has the effect of a = (b = c) and results in assigning the value of c to both a and b. The expression (a = b) = c is acceptable, but has the @@ -54,7 +54,7 @@ DESCRIPTION In initializations, = { ...} associates from left to right so that, for example, - a = {e_0, ... } = {v_0, ...} + a = {e_0, ... } = {v_0, ...} first assigns e_0, ... to the elements of a, and then assigns v_0, ... to the result. @@ -66,10 +66,10 @@ DESCRIPTION that of A[0] = A[1]. If, in execution of a = b, a is changed by the evaluation of b, the - value of b may be stored in an unintended or inaccessible location. For + value of b may be stored in an unintended or inaccessible location. For example, - mat A[2]= {1,2}; - A[0] = (A = 3); + mat A[2]= {1,2}; + A[0] = (A = 3); results in the value 3 being stored not only as the new value for A but also at the now unnamed location earlier used for A[0]. @@ -87,8 +87,8 @@ EXAMPLE ; print A[1] list (2 elements, 2 nonzero): - [[0]] = 6 - [[1]] = 3 + [[0]] = 6 + [[1]] = 3 ; print A[2] obj point {7, 5} @@ -104,8 +104,8 @@ EXAMPLE print A[1] list (2 elements, 2 nonzero): - [[0]] = 2 - [[1]] = 3 + [[0]] = 2 + [[1]] = 3 LIMITS none @@ -124,7 +124,7 @@ SEE ALSO ## ## 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 +## 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 @@ -132,8 +132,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/05/11 21:03:23 -## File existed as early as: 1995 +## Under source code control: 1995/05/11 21:03:23 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/assoc b/help/assoc index 74eccc0..122fcb4 100644 --- a/help/assoc +++ b/help/assoc @@ -5,7 +5,7 @@ SYNOPSIS assoc() TYPES - return association + return association DESCRIPTION This function returns an empty association array. @@ -13,10 +13,10 @@ DESCRIPTION After A = assoc(), elements can be added to the association by assignments of the forms - A[a_1] = v_1 - A[a_1, a_2] = v_2 - A[a_1, a_2, a_3] = v_3 - A[a_1, a_2, a_3, a_4] = v_4 + A[a_1] = v_1 + A[a_1, a_2] = v_2 + A[a_1, a_2, a_3] = v_3 + A[a_1, a_2, a_3, a_4] = v_4 There are no restrictions on the values of the "indices" a_i or the "values" v_i. @@ -52,7 +52,7 @@ DESCRIPTION a sequential scan through the elements difficult. The search and rsearch functions can search for an element in an - association which has the specified value. They return the index + association which has the specified value. They return the index of the found element, or a NULL value if the value was not found. Associations can be copied by an assignment, and can be compared @@ -90,7 +90,7 @@ SEE ALSO ## ## 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 +## 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 @@ -98,8 +98,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/25 20:22:31 -## File existed as early as: 1994 +## Under source code control: 1994/09/25 20:22:31 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/atan b/help/atan index 5b89eef..1d59919 100644 --- a/help/atan +++ b/help/atan @@ -5,10 +5,10 @@ SYNOPSIS atan(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the inverse trigonometric tangent of x to a multiple of eps with error less in @@ -61,14 +61,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 1999,2023 Landon Curt Noll ## @@ -78,7 +78,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -86,8 +86,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 01:40:25 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 01:40:25 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/atan2 b/help/atan2 index 7298b6d..f99e648 100644 --- a/help/atan2 +++ b/help/atan2 @@ -5,11 +5,11 @@ SYNOPSIS atan2(y, x, [,eps]) TYPES - y real - x real - eps nonzero real, defaults to epsilon() + y real + x real + eps nonzero real, defaults to epsilon() - return real + return real DESCRIPTION If x and y are not both zero, atan2(y, x, eps) returns, as a multiple of @@ -44,7 +44,7 @@ SEE ALSO ## ## 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 +## 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 @@ -52,8 +52,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 01:40:26 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 01:40:26 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/atanh b/help/atanh index 252433b..9bb0647 100644 --- a/help/atanh +++ b/help/atanh @@ -5,10 +5,10 @@ SYNOPSIS atanh(x [,eps]) TYPES - x real - eps 0 < real < 1, defaults to epsilon() + x real + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the atanh of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION atanh(x) is the real number v for which tanh(v) = x. It is given by - atanh(x) = ln((1 + x)/(1 - x))/2 + atanh(x) = ln((1 + x)/(1 - x))/2 EXAMPLE ; print atanh(.5,1e-5), atanh(.5,1e-10), atanh(.5,1e-15), atanh(.5,1e-20) @@ -41,7 +41,7 @@ SEE ALSO ## ## 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 +## 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 @@ -49,8 +49,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 01:40:27 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 01:40:27 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/avercos b/help/avercos index 1f87699..289632a 100644 --- a/help/avercos +++ b/help/avercos @@ -5,10 +5,10 @@ SYNOPSIS avercos(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the inverse versed trigonometric cosine of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called averc, or arcvercos, is equivalent to: - avercos(x) = acos(x - 1) + avercos(x) = acos(x - 1) EXAMPLE ; print avercos(0), avercos(0.5), avercos(1) @@ -61,14 +61,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -78,7 +78,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -86,8 +86,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/05 23:40:24 -## File existed as early as: 2023 +## Under source code control: 2023/09/05 23:40:24 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/aversin b/help/aversin index 2bdc808..83e989f 100644 --- a/help/aversin +++ b/help/aversin @@ -5,10 +5,10 @@ SYNOPSIS aversin(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns the inverse versed trigonometric sine of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called avers, or arcversin, is equivalent to: - aversin(x) = acos(1 - x) + aversin(x) = acos(1 - x) EXAMPLE ; print aversin(0), aversin(0.5), aversin(1) @@ -61,14 +61,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -78,7 +78,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -86,8 +86,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/03 00:26:24 -## File existed as early as: 2023 +## Under source code control: 2023/09/03 00:26:24 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/avg b/help/avg index 87d1023..5099739 100644 --- a/help/avg +++ b/help/avg @@ -5,16 +5,16 @@ SYNOPSIS avg(x_1, x_2, ...) TYPES - x_1, ... arithmetic or list + x_1, ... arithmetic or list - return as determined by types of items averaged + return as determined by types of items averaged DESCRIPTION If there are n non-list arguments x_1, x_2, ..., x_n, for which the required additions and division by n are defined, avg(x_1, x_2, ..., x_n) returns the value of: - (x_1 + x_2 + ... + x_n)/n. + (x_1 + x_2 + ... + x_n)/n. If the x_i are real, the result will be a real number; if the x_i are real or complex numbers, the result will be a real or complex @@ -35,10 +35,10 @@ EXAMPLE ; avg(x,y) mat [2,2] (4 elements, 4 nonzero): - [0,0] = 1 - [0,1] = 2 - [1,0] = 3.5 - [1,1] = 6 + [0,0] = 1 + [0,1] = 2 + [1,0] = 3.5 + [1,1] = 6 LIMITS The number of arguments is not to exceed 1024. @@ -57,7 +57,7 @@ SEE ALSO ## ## 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 +## 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 @@ -65,8 +65,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/25 20:22:31 -## File existed as early as: 1994 +## Under source code control: 1994/09/25 20:22:31 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/base b/help/base index 15cf5ac..f295211 100644 --- a/help/base +++ b/help/base @@ -5,9 +5,9 @@ SYNOPSIS base([mode]) TYPES - mode real + mode real - return real + return real DESCRIPTION The base function allows one to specify how numbers should be @@ -18,34 +18,34 @@ DESCRIPTION The following convention is used to declare modes: - base equivalent - config("mode")'s + base equivalent + config("mode")'s - 2 "binary" base 2 fractions - "bin" + 2 "binary" base 2 fractions + "bin" - 8 "octal" base 8 fractions - "oct" + 8 "octal" base 8 fractions + "oct" - 10 "real" base 10 floating point - "float" - "default" + 10 "real" base 10 floating point + "float" + "default" - -10 "integer" base 10 integers - "int" + -10 "integer" base 10 integers + "int" - 16 "hexadecimal" base 16 fractions - "hex" + 16 "hexadecimal" base 16 fractions + "hex" - 1/3 "fraction" base 10 fractions - "frac" + 1/3 "fraction" base 10 fractions + "frac" - 1e20 "scientific" base 10 scientific notation - "sci" - "exp" + 1e20 "scientific" base 10 scientific notation + "sci" + "exp" - 1000 "engineering" base 10 notation with exponent - "eng" multiple of 3 + 1000 "engineering" base 10 notation with exponent + "eng" multiple of 3 For convenience, any non-integer value is assumed to mean base 10 fractions and any integer >= 2^64 is assumed to mean base 10 @@ -53,21 +53,21 @@ DESCRIPTION These base() calls have the same meaning as config("mode", "fraction"): - base(1/3) base(0.1415) base(16/37) + base(1/3) base(0.1415) base(16/37) These base() calls have the same meaning as config("mode", "scientific"): - base(1e20) base(2^64) base(2^8191-1) + base(1e20) base(2^64) base(2^8191-1) However the base() function will only return one of the base values listed in the table above. EXAMPLE ; base() - 10 + 10 ; base(8) - 012 + 012 ; print 10 012 @@ -79,7 +79,7 @@ LINK LIBRARY int math_setmode(int newmode) NOTE: newmode must be one of MODE_DEFAULT, MODE_FRAC, MODE_INT, - MODE_REAL, MODE_EXP, MODE_ENG, MODE_HEX, MODE_OCTAL, MODE_BINARY + MODE_REAL, MODE_EXP, MODE_ENG, MODE_HEX, MODE_OCTAL, MODE_BINARY SEE ALSO base2, config, str @@ -92,7 +92,7 @@ SEE ALSO ## ## 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 +## 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 @@ -100,8 +100,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/30 00:09:39 -## File existed as early as: 1994 +## Under source code control: 1994/09/30 00:09:39 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/base2 b/help/base2 index 96987d7..3fd739f 100644 --- a/help/base2 +++ b/help/base2 @@ -5,9 +5,9 @@ SYNOPSIS base2([mode]) TYPES - mode real + mode real - return real + return real DESCRIPTION By default, calc will output values according to the default base @@ -19,41 +19,41 @@ DESCRIPTION to base2(). In double base output mode, the second time a value is displayed, it is displayed within comments: - 21701 /* 0x54c5 */ + 21701 /* 0x54c5 */ The arguments for base2() are identical to base() with the addition of the 0 value: - base2 equivalent - config("mode2")'s + base2 equivalent + config("mode2")'s - 2 "binary" base 2 fractions - "bin" + 2 "binary" base 2 fractions + "bin" - 8 "octal" base 8 fractions - "oct" + 8 "octal" base 8 fractions + "oct" - 10 "real" base 10 floating point - "float" - "default" + 10 "real" base 10 floating point + "float" + "default" - -10 "integer" base 10 integers - "int" + -10 "integer" base 10 integers + "int" - 16 "hexadecimal" base 16 fractions - "hex" + 16 "hexadecimal" base 16 fractions + "hex" - 1/3 "fraction" base 10 fractions - "frac" + 1/3 "fraction" base 10 fractions + "frac" - 1e20 "scientific" base 10 scientific notation - "sci" - "exp" + 1e20 "scientific" base 10 scientific notation + "sci" + "exp" - 1000 "engineering" base 10 notation with exponent - "eng" multiple of 3 + 1000 "engineering" base 10 notation with exponent + "eng" multiple of 3 - 0 "off" disable double base output + 0 "off" disable double base output For convenience, any non-integer non-zero value is assumed to mean base 10 fractions and any integer >= 2^64 is assumed to mean base 10 @@ -61,27 +61,27 @@ DESCRIPTION These base2() calls have the same meaning as config("mode2", "fraction"): - base2(1/3) base2(0.1415) base2(16/37) + base2(1/3) base2(0.1415) base2(16/37) These base2() calls have the same meaning as config("mode2", "scientific"): - base2(1e20) base2(2^64) base2(2^8191-1) + base2(1e20) base2(2^64) base2(2^8191-1) However the base2() function will only return one of the base values listed in the table above. EXAMPLE ; base2() - 0 + 0 ; base2(8) - 0 /* 0 */ + 0 /* 0 */ ; print 10 10 /* 012 */ ; base2(16), ; 131072 - 131072 /* 0x20000 */ + 131072 /* 0x20000 */ ; 2345 - 2345 /* 0x929 */ + 2345 /* 0x929 */ LIMITS none @@ -90,8 +90,8 @@ LINK LIBRARY int math_setmode2(int newmode) NOTE: newmode must be one of MODE_DEFAULT, MODE_FRAC, MODE_INT, - MODE_REAL, MODE_EXP, MODE_ENG, MODE_HEX, MODE_OCTAL, MODE_BINARY, - MODE2_OFF + MODE_REAL, MODE_EXP, MODE_ENG, MODE_HEX, MODE_OCTAL, MODE_BINARY, + MODE2_OFF SEE ALSO base, config, str @@ -104,7 +104,7 @@ SEE ALSO ## ## 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 +## 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 @@ -112,8 +112,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2002/12/29 00:21:07 -## File existed as early as: 2002 +## Under source code control: 2002/12/29 00:21:07 +## File existed as early as: 2002 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/bernoulli b/help/bernoulli index 8363051..3d9750e 100644 --- a/help/bernoulli +++ b/help/bernoulli @@ -5,15 +5,15 @@ SYNOPSIS bernoulli(n) TYPES - n integer, n < 2^31 if even + n integer, n < 2^31 if even - return rational + return rational DESCRIPTION Returns the Bernoulli number with index n, i.e. the coefficient B_n in the expansion - t/(exp(t) - 1) = Sum B_n * t^n/n! + t/(exp(t) - 1) = Sum B_n * t^n/n! bernoulli(n) is zero both for n < 0 and for n odd and > 2. When bernoulli(n) is computed for positive even n, the values for @@ -49,7 +49,7 @@ SEE ALSO ## ## 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 +## 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 @@ -57,7 +57,7 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2000/07/13 01:33:00 -## File existed as early as: 2000 +## Under source code control: 2000/07/13 01:33:00 +## File existed as early as: 2000 ## -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/bit b/help/bit index 8d1ccd4..668b3b0 100644 --- a/help/bit +++ b/help/bit @@ -5,17 +5,17 @@ SYNOPSIS bit(x, y) TYPES - x real - y int + x real + y int - return int + return int DESCRIPTION - Determine if the binary bit y is set in x. If: + Determine if the binary bit y is set in x. If: - x - int(---) mod 2 == 1 - 2^y + x + int(---) mod 2 == 1 + 2^y return 1, otherwise return 0. @@ -50,7 +50,7 @@ SEE ALSO ## ## 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 +## 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 @@ -58,8 +58,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:30 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:30 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/blk b/help/blk index 973c514..e9cc2d3 100644 --- a/help/blk +++ b/help/blk @@ -6,11 +6,11 @@ SYNOPSIS blk(val [, len, chunk]); TYPES - len null or integer - chunk null or integer - val non-null string, block, or named block + len null or integer + chunk null or integer + val non-null string, block, or named block - return block or named block + return block or named block DESCRIPTION With only integer arguments, blk(len, chunk) attempts to @@ -26,23 +26,23 @@ DESCRIPTION ... , B[len-1], these all initially having zero value. The octets B[i] for i >= len always have zero value. If B[i] with - some i >= len is referenced, size(B) is increased to i + 1. For example: + some i >= len is referenced, size(B) is increased to i + 1. For example: - B[i] = x + B[i] = x has an effect like that of two operations on a file stream fs: - fseek(fs, pos); - fputc(fs, x). + fseek(fs, pos); + fputc(fs, x). Similarly: - x = B[i] + x = B[i] is like: - fseek(fs, pos); - x = fgetc(fs). + fseek(fs, pos); + x = fgetc(fs). The value of chunk is stored as the "chunksize" for B. @@ -51,7 +51,7 @@ DESCRIPTION value. Also size(B) is analogous to the length of a file stream in that if size(B) < sizeof(B): - B[size(B)] = x + B[size(B)] = x will append one octet to B and increment size(B). @@ -70,14 +70,14 @@ DESCRIPTION If a block value B created by B = blk(len, chunk) is assigned to another variable by C = B, a new block of the same structure as B is created to become the value of C, and the octets in B are copied - to this new block. A block with possibly different length or + to this new block. A block with possibly different length or chunksize is created by C = blk(B, newlen, newchunk), only the first min(len, newlen) octets being copied from B; later octets are assigned zero value. If omitted, newlen and newchunk default to the current datalen and chunk-size for B. The current datalen, chunksize and number of allocated octets for B may be changed by: - B = blk(B, newlen, newchunk). + B = blk(B, newlen, newchunk). No data is lost if newlen is greater than or equal to the old size(B). @@ -99,38 +99,38 @@ DESCRIPTION is that in assignments, a named block is not copied. Thus, if a block A has been created by: - A = blk("foo") + A = blk("foo") any subsequent: - B = A + B = A or: - B = blk("foo") + B = blk("foo") will give a second variable B referring to the same block as A. Either A[i] = x or B[i] = x may then be used to assign a value to an octet in the block. Its length or chunksize may be changed by instructions like: - blk(A, len, chunk); + blk(A, len, chunk); - A = blk(A, len, chunk); + A = blk(A, len, chunk); - null(blk(A, len, chunk)). + null(blk(A, len, chunk)). These have the same effect on A; when working interactively, the last two avoid printing of the new value for A. Named blocks are assigned index numbers 0, 1, 2, ..., in the order - of their creation. The block with index id is returned by blocks(id). + of their creation. The block with index id is returned by blocks(id). With no argument, blocks() returns the number of current unfreed named blocks. The memory allocated to a named block is freed by the blkfree() function with argument the named block, its name, or its id number. The block remains in existence but with a null data pointer, - its length and size being reduced to zero. A new block of memory + its length and size being reduced to zero. A new block of memory may be allocated to it, with possibly new length and chunksize by: - blk(val [, len, chunk]) + blk(val [, len, chunk]) where val is either the named block or its name. @@ -141,7 +141,7 @@ DESCRIPTION The identifying numbers and names of the current named blocks are displayed by: - show blocks + show blocks If A and B are named blocks, A == B will be true only if they refer to the same block of memory. Thus, blocks with the same data and @@ -158,13 +158,13 @@ EXAMPLE ; B[7] = 0xff ; B - chunksize = 10, maxsize = 20, datalen = 15 - 00000000000000ff00000000000000 + chunksize = 10, maxsize = 20, datalen = 15 + 00000000000000ff00000000000000 ; B[18] = 127 ; B - chunksize = 10, maxsize = 20, datalen = 18 - 00000000000000ff0000000000000000007f + chunksize = 10, maxsize = 20, datalen = 18 + 00000000000000ff0000000000000000007f ; B[20] = 2 Index out of bounds for block @@ -174,38 +174,38 @@ EXAMPLE ; B = blk(B, 100, 20) ; B - chunksize = 20, maxsize = 120, datalen = 100 - 00000000000000ff0000000000000000007f000000000000000000000000... + chunksize = 20, maxsize = 120, datalen = 100 + 00000000000000ff0000000000000000007f000000000000000000000000... ; C = blk(B, 10} = {1,2,3} ; C - chunksize = 20, maxsize = 20, datalen = 10 - 01020300000000ff0000 + chunksize = 20, maxsize = 20, datalen = 10 + 01020300000000ff0000 ; A1 = blk("alpha") ; A1 - block 0: alpha - chunksize = 256, maxsize = 256, datalen = 0 + block 0: alpha + chunksize = 256, maxsize = 256, datalen = 0 ; A1[7] = 0xff ; A2 = A1 ; A2[17] = 127 ; A1 - block 0: alpha - chunksize = 256, maxsize = 256, datalen = 18 - 00000000000000ff0000000000000000007f + block 0: alpha + chunksize = 256, maxsize = 256, datalen = 18 + 00000000000000ff0000000000000000007f ; A1 = blk(A1, 1000) ; A1 - block 0: alpha - chunksize = 256, maxsize = 1024, datalen = 1000 - 00000000000000ff0000000000000000007f000000000000000000000000... + block 0: alpha + chunksize = 256, maxsize = 1024, datalen = 1000 + 00000000000000ff0000000000000000007f000000000000000000000000... ; A1 = blk(A1, , 16) ; A1 - block 0: alpha - chunksize = 16, maxsize = 1008, datalen = 1000 - 00000000000000ff0000000000000000007f000000000000000000000000... + block 0: alpha + chunksize = 16, maxsize = 1008, datalen = 1000 + 00000000000000ff0000000000000000007f000000000000000000000000... LIMITS 0 <= len < 2^31 @@ -241,7 +241,7 @@ SEE ALSO ## ## 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 +## 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 @@ -249,8 +249,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/04/05 13:07:13 -## File existed as early as: 1997 +## Under source code control: 1997/04/05 13:07:13 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/blkcpy b/help/blkcpy index e30fb49..094f53c 100644 --- a/help/blkcpy +++ b/help/blkcpy @@ -6,20 +6,20 @@ SYNOPSIS copy(src, dest [, [ssi [, num [, dsi]]]) TYPES - src block, file, string, matrix, or list - dest block, file, matrix or list - compatible with src + src block, file, string, matrix, or list + dest block, file, matrix or list - compatible with src - ssi nonnegative integer, defaults to zero - num nonnegative integer, defaults to maximum possible - dsi nonnegative integer, defaults to datalen for a block, filepos - for a file, zero for other structures + ssi nonnegative integer, defaults to zero + num nonnegative integer, defaults to maximum possible + dsi nonnegative integer, defaults to datalen for a block, filepos + for a file, zero for other structures - return null if successful, error value otherwise + return null if successful, error value otherwise DESCRIPTION A call to: - blkcpy(dst, src, num, dsi, ssi) + blkcpy(dst, src, num, dsi, ssi) attempts to copy 'num' consecutive items (octets or values) starting from the source item 'src' with index 'ssi'. By default, 'num' @@ -27,7 +27,7 @@ DESCRIPTION A call to: - copy(src, dst, ssi, num, dsi) + copy(src, dst, ssi, num, dsi) does the same thing, but with a different arg order. @@ -40,30 +40,30 @@ DESCRIPTION The following pairs of source-type, destination-type are permitted: - block to - int - block - matrix - file + block to + int + block + matrix + file - matrix to - block - matrix - list + matrix to + block + matrix + list - string to - block - file + string to + block + file - list to - list - matrix + list to + list + matrix - file to - block + file to + block - int to - block + int to + block In the above table, int refers to integer values. However if a rational value is supplied, only the numerator is copied. @@ -79,18 +79,18 @@ DESCRIPTION sufficient memory allocated for the copying. For example, to copy a matrix M of size 100 to a newly created list, one may use: - ; L = makelist(100); - ; copy(M, L); + ; L = makelist(100); + ; copy(M, L); or: - ; L = makelist(100); - ; blkcpy(L, M); + ; L = makelist(100); + ; blkcpy(L, M); For copying from a block B (named or unnamed), the total number of octets available for copying is taken to the datalen for that block, so that num can be at most size(B) - ssi. For copying to a block B (named or unnamed), reallocation will be - required if dsi + num > sizeof(B). (This will not be permitted if + required if dsi + num > sizeof(B). (This will not be permitted if protect(B) has bit 4 set.) For copying from a file stream fs, num can be at most size(fs) - ssi. @@ -111,74 +111,74 @@ EXAMPLE ; B = blk() ; blkcpy(B,A) ; B - chunksize = 256, maxsize = 256, datalen = 4 - 01020304 + chunksize = 256, maxsize = 256, datalen = 4 + 01020304 ; blkcpy(B,A) ; B - chunksize = 256, maxsize = 256, datalen = 8 - 0102030401020304 + chunksize = 256, maxsize = 256, datalen = 8 + 0102030401020304 ; blkcpy(B, A, 2, 10) ; B - chunksize = 256, maxsize = 256, datalen = 12 - 010203040102030400000102 + chunksize = 256, maxsize = 256, datalen = 12 + 010203040102030400000102 ; blkcpy(B,32767) ; B - chunksize = 256, maxsize = 256, datalen = 16 - 010203040102030400000102ff7f0000 + chunksize = 256, maxsize = 256, datalen = 16 + 010203040102030400000102ff7f0000 ; mat M[2,2] ; blkcpy(M, A) ; M - mat [2,2] (4 elements, 4 nonzero): - [0,0] = 1 - [0,1] = 2 - [1,0] = 3 - [1,1] = 4 + mat [2,2] (4 elements, 4 nonzero): + [0,0] = 1 + [0,1] = 2 + [1,0] = 3 + [1,1] = 4 ; blkcpy(M, A, 2, 2) ; M - mat [2,2] (4 elements, 4 nonzero): - [0,0] = 1 - [0,1] = 2 - [1,0] = 1 - [1,1] = 2 + mat [2,2] (4 elements, 4 nonzero): + [0,0] = 1 + [0,1] = 2 + [1,0] = 1 + [1,1] = 2 ; A = blk() = {1,2,3,4} ; B = blk() ; copy(A,B) ; B - chunksize = 256, maxsize = 256, datalen = 4 - 01020304 + chunksize = 256, maxsize = 256, datalen = 4 + 01020304 ; copy(A,B) ; B - chunksize = 256, maxsize = 256, datalen = 8 - 0102030401020304 + chunksize = 256, maxsize = 256, datalen = 8 + 0102030401020304 ; copy(A,B,1,2) ; B - chunksize = 256, maxsize = 256, datalen = 10 - 01020304010203040203 + chunksize = 256, maxsize = 256, datalen = 10 + 01020304010203040203 ; mat M[2,2] ; copy(A,M) ; M - mat [2,2] (4 elements, 4 nonzero): - [0,0] = 1 - [0,1] = 2 - [1,0] = 3 - [1,1] = 4 + mat [2,2] (4 elements, 4 nonzero): + [0,0] = 1 + [0,1] = 2 + [1,0] = 3 + [1,1] = 4 ; copy(A,M,2) ; M - mat [2,2] (4 elements, 4 nonzero): - [0,0] = 3 - [0,1] = 4 - [1,0] = 3 - [1,1] = 4 + mat [2,2] (4 elements, 4 nonzero): + [0,0] = 3 + [0,1] = 4 + [1,0] = 3 + [1,1] = 4 ; copy(A,M,0,2,2) ; M - mat [2,2] (4 elements, 4 nonzero): - [0,0] = 3 - [0,1] = 4 - [1,0] = 1 - [1,1] = 2 + mat [2,2] (4 elements, 4 nonzero): + [0,0] = 3 + [0,1] = 4 + [1,0] = 1 + [1,1] = 2 LIMITS none @@ -197,7 +197,7 @@ SEE ALSO ## ## 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 +## 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 @@ -205,8 +205,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/04/05 14:08:50 -## File existed as early as: 1997 +## Under source code control: 1997/04/05 14:08:50 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/blkfree b/help/blkfree index 8b8938a..612e10f 100644 --- a/help/blkfree +++ b/help/blkfree @@ -5,14 +5,14 @@ SYNOPSIS blkfree(val) TYPES - val named block, string, or integer + val named block, string, or integer - return null value + return null value DESCRIPTION If val is a named block, or the name of a named block, or the identifying index for a named block, blkfree(val) frees the - memory block allocated to this named block. The block remains + memory block allocated to this named block. The block remains in existence with the same name, identifying index, and chunksize, but its size and maxsize becomes zero and the pointer for the start of its data block null. @@ -26,27 +26,27 @@ EXAMPLE ; B1 = blk("foo") ; B2 = blk("Second block") show blocks - id name + id name ---- ----- - 0 foo - 1 Second block + 0 foo + 1 Second block ; blkfree(B1) ; show blocks - id name + id name ---- ----- - 1 Second block + 1 Second block ; B1 - block 0: foo - chunksize = 256, maxsize = 0, datalen = 0 - NULL + block 0: foo + chunksize = 256, maxsize = 0, datalen = 0 + NULL ; blk(B1); B[7] = 5 ; B1 - block 0: foo - chunksize = 256, maxsize = 256, datalen = 8 - 0000000000000005 + block 0: foo + chunksize = 256, maxsize = 256, datalen = 8 + 0000000000000005 LIMITS none @@ -65,7 +65,7 @@ SEE ALSO ## ## 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 +## 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 @@ -73,8 +73,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/04/05 13:07:13 -## File existed as early as: 1997 +## Under source code control: 1997/04/05 13:07:13 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/blocks b/help/blocks index 3d3710c..a393da1 100644 --- a/help/blocks +++ b/help/blocks @@ -5,9 +5,9 @@ SYNOPSIS blocks([id]) TYPES - id non-negative integer + id non-negative integer - return named block or null value + return named block or null value DESCRIPTION With no argument blocks() returns the number of blocks that have @@ -22,15 +22,15 @@ EXAMPLE ; A = blk("alpha") ; B = blk("beta") = {1,2,3} ; blocks() - 2 + 2 ; blocks(1) - block 1: beta - chunksize = 256, maxsize = 256, datalen = 3 - 010203 + block 1: beta + chunksize = 256, maxsize = 256, datalen = 3 + 010203 ; blocks(2) - Error E_BLOCKS_2 + Error E_BLOCKS_2 ; strerror() - "Non-allocated index number for blocks" + "Non-allocated index number for blocks" LIMITS none @@ -49,7 +49,7 @@ SEE ALSO ## ## 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 +## 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 @@ -57,8 +57,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/04/05 13:07:13 -## File existed as early as: 1997 +## Under source code control: 1997/04/05 13:07:13 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/bround b/help/bround index bcf729f..a2468f4 100644 --- a/help/bround +++ b/help/bround @@ -12,16 +12,16 @@ TYPES Otherwise, if x is an object of type tt, or if x is not an object or number but y is an object of type tt, and the function tt_bround has to be defined; the types for x, plcs, rnd, and the returned value, - if any, are as required for specified in tt_bround. For the object + if any, are as required for specified in tt_bround. For the object case, plcs and rnd default to the null value. For other cases: - x number (real or complex) - plcs integer, defaults to zero - rnd integer, defaults to config("round") + x number (real or complex) + plcs integer, defaults to zero + rnd integer, defaults to config("round") - return number + return number DESCRIPTION For real x, bround(x, plcs, rnd) returns x rounded to either @@ -31,39 +31,39 @@ DESCRIPTION If the number of binary places is n and eps = 10^-n, the result is the same as for appr(x, eps, rnd). This will be exactly x if x is a multiple of eps; otherwise rounding occurs - to one of the nearest multiples of eps on either side of x. Which + to one of the nearest multiples of eps on either side of x. Which of these multiples is returned is determined by z = rnd & 31, i.e. the five low order bits of rnd, as follows: - z = 0 or 4: round down, i.e. towards minus infinity - z = 1 or 5: round up, i.e. towards plus infinity - z = 2 or 6: round towards zero - z = 3 or 7: round away from zero - z = 8 or 12: round to the nearest even multiple of eps - z = 9 or 13: round to the nearest odd multiple of eps - z = 10 or 14: round to nearest even or odd multiple of eps - according as x > or < 0 - z = 11 or 15: round to nearest odd or even multiple of eps - according as x > or < 0 - z = 16 to 31: round to the nearest multiple of eps when - this is uniquely determined. Otherwise - rounding is as if z is replaced by z - 16 + z = 0 or 4: round down, i.e. towards minus infinity + z = 1 or 5: round up, i.e. towards plus infinity + z = 2 or 6: round towards zero + z = 3 or 7: round away from zero + z = 8 or 12: round to the nearest even multiple of eps + z = 9 or 13: round to the nearest odd multiple of eps + z = 10 or 14: round to nearest even or odd multiple of eps + according as x > or < 0 + z = 11 or 15: round to nearest odd or even multiple of eps + according as x > or < 0 + z = 16 to 31: round to the nearest multiple of eps when + this is uniquely determined. Otherwise + rounding is as if z is replaced by z - 16 For complex x: - The real and imaginary parts are rounded as for real x; if the - imaginary part rounds to zero, the result is real. + The real and imaginary parts are rounded as for real x; if the + imaginary part rounds to zero, the result is real. For matrix or list x: - The returned values has element bround(x[[i]], plcs, rnd) in - the same position as x[[i]] in x. + The returned values has element bround(x[[i]], plcs, rnd) in + the same position as x[[i]] in x. For object x or plcs: - When bround(x, plcs, rnd) is called, x is passed by address so may be - changed by assignments; plcs and rnd are copied to temporary - variables, so their values are not changed by the call. + When bround(x, plcs, rnd) is called, x is passed by address so may be + changed by assignments; plcs and rnd are copied to temporary + variables, so their values are not changed by the call. EXAMPLE ; a = 7/32, b = -7/32 @@ -100,18 +100,18 @@ EXAMPLE ; print round(A,2,24) list(7 elements, 7 nonzero): - [[0]] = 0.12 - [[1]] = 0.25 - [[3]] = 0.38 - [[4]] = 0.5 - [[5]] = 0.62 - [[6]] = 0.75 - [[7]] = 0.88 + [[0]] = 0.12 + [[1]] = 0.25 + [[3]] = 0.38 + [[4]] = 0.5 + [[5]] = 0.62 + [[6]] = 0.75 + [[7]] = 0.88 LIMITS For non-object case: - 0 <= abs(plcs) < 2^31 - 0 <= abs(rnd) < 2^31 + 0 <= abs(plcs) < 2^31 + 0 <= abs(rnd) < 2^31 LINK LIBRARY void broundvalue(VALUE *x, VALUE *plcs, VALUE *rnd, VALUE *result) @@ -130,7 +130,7 @@ SEE ALSO ## ## 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 +## 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 @@ -138,8 +138,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/30 00:22:35 -## File existed as early as: 1994 +## Under source code control: 1994/09/30 00:22:35 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/btrunc b/help/btrunc index 38b4bb1..077eddb 100644 --- a/help/btrunc +++ b/help/btrunc @@ -5,10 +5,10 @@ SYNOPSIS btrunc(x [,plcs]) TYPES - x real - plcs integer, defaults to zero + x real + plcs integer, defaults to zero - return real + return real DESCRIPTION Truncate x to plcs binary places, rounding if necessary towards zero, @@ -51,7 +51,7 @@ SEE ALSO ## ## 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 +## 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 @@ -59,8 +59,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/30 00:44:27 -## File existed as early as: 1994 +## Under source code control: 1994/09/30 00:44:27 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/builtin.end b/help/builtin.end index edcd1c8..50d8a1e 100644 --- a/help/builtin.end +++ b/help/builtin.end @@ -1,203 +1,203 @@ - The config function sets or reads the value of a configuration - parameter. The first argument is a string which names the parameter - to be set or read. If only one argument is given, then the current - value of the named parameter is returned. If two arguments are given, - then the named parameter is set to the value of the second argument, - and the old value of the parameter is returned. Therefore you can - change a parameter and restore its old value later. The possible - parameters are explained in the next section. + The config function sets or reads the value of a configuration + parameter. The first argument is a string which names the parameter + to be set or read. If only one argument is given, then the current + value of the named parameter is returned. If two arguments are given, + then the named parameter is set to the value of the second argument, + and the old value of the parameter is returned. Therefore you can + change a parameter and restore its old value later. The possible + parameters are explained in the next section. - The scale function multiplies or divides a number by a power of 2. - This is used for fractional calculations, unlike the << and >> - operators, which are only defined for integers. For example, - scale(6, -3) is 3/4. + The scale function multiplies or divides a number by a power of 2. + This is used for fractional calculations, unlike the << and >> + operators, which are only defined for integers. For example, + scale(6, -3) is 3/4. - The quomod function is used to obtain both the quotient and remainder - of a division in one operation. The first two arguments a and b are - the numbers to be divided. The last two arguments c and d are two - variables which will be assigned the quotient and remainder. For - nonnegative arguments, the results are equivalent to computing a//b - and a%b. If a is negative and the remainder is nonzero, then the - quotient will be one less than a//b. This makes the following three - properties always hold: The quotient c is always an integer. The - remainder d is always 0 <= d < b. The equation a = b * c + d always - holds. This function returns 0 if there is no remainder, and 1 if - there is a remainder. For examples, quomod(10, 3, x, y) sets x to 3, - y to 1, and returns the value 1, and quomod(-4, 3.14159, x, y) sets x - to -2, y to 2.28318, and returns the value 1. + The quomod function is used to obtain both the quotient and remainder + of a division in one operation. The first two arguments a and b are + the numbers to be divided. The last two arguments c and d are two + variables which will be assigned the quotient and remainder. For + nonnegative arguments, the results are equivalent to computing a//b + and a%b. If a is negative and the remainder is nonzero, then the + quotient will be one less than a//b. This makes the following three + properties always hold: The quotient c is always an integer. The + remainder d is always 0 <= d < b. The equation a = b * c + d always + holds. This function returns 0 if there is no remainder, and 1 if + there is a remainder. For examples, quomod(10, 3, x, y) sets x to 3, + y to 1, and returns the value 1, and quomod(-4, 3.14159, x, y) sets x + to -2, y to 2.28318, and returns the value 1. - The eval function accepts a string argument and evaluates the - expression represented by the string and returns its value. - The expression can include function calls and variable references. - For example, eval("fact(3) + 7") returns 13. When combined with - the prompt function, this allows the calculator to read values from - the user. For example, x=eval(prompt("Number: ")) sets x to the - value input by the user. + The eval function accepts a string argument and evaluates the + expression represented by the string and returns its value. + The expression can include function calls and variable references. + For example, eval("fact(3) + 7") returns 13. When combined with + the prompt function, this allows the calculator to read values from + the user. For example, x=eval(prompt("Number: ")) sets x to the + value input by the user. - The digit and bit functions return individual digits of a number, - either in base 10 or in base 2, where the lowest digit of a number - is at digit position 0. For example, digit(5678, 3) is 5, and - bit(0b1000100, 2) is 1. Negative digit positions indicate places - to the right of the decimal or binary point, so that for example, - digit(3.456, -1) is 4. + The digit and bit functions return individual digits of a number, + either in base 10 or in base 2, where the lowest digit of a number + is at digit position 0. For example, digit(5678, 3) is 5, and + bit(0b1000100, 2) is 1. Negative digit positions indicate places + to the right of the decimal or binary point, so that for example, + digit(3.456, -1) is 4. - The ptest builtin is a primality testing function. The - 1st argument is the suspected prime to be tested. The - absolute value of the 2nd argument is an iteration count. + The ptest builtin is a primality testing function. The + 1st argument is the suspected prime to be tested. The + absolute value of the 2nd argument is an iteration count. - If ptest is called with only 2 args, the 3rd argument is - assumed to be 0. If ptest is called with only 1 arg, the - 2nd argument is assumed to be 1. Thus, the following - calls are equivalent: + If ptest is called with only 2 args, the 3rd argument is + assumed to be 0. If ptest is called with only 1 arg, the + 2nd argument is assumed to be 1. Thus, the following + calls are equivalent: - ptest(a) - ptest(a,1) - ptest(a,1,0) + ptest(a) + ptest(a,1) + ptest(a,1,0) - Normally ptest performs a some checks to determine if the - value is divisible by some trivial prime. If the 2nd - argument is < 0, then the trivial check is omitted. + Normally ptest performs a some checks to determine if the + value is divisible by some trivial prime. If the 2nd + argument is < 0, then the trivial check is omitted. - For example, ptest(a,10) performs the same work as: + For example, ptest(a,10) performs the same work as: - ptest(a,-3) (7 tests without trivial check) - ptest(a,-7,3) (3 more tests without the trivial check) + ptest(a,-3) (7 tests without trivial check) + ptest(a,-7,3) (3 more tests without the trivial check) - The ptest function returns 0 if the number is definitely not - prime, and 1 is the number is probably prime. The chance - of a number which is probably prime being actually composite - is less than 1/4 raised to the power of the iteration count. - For example, for a random number p, ptest(p, 10) incorrectly - returns 1 less than once in every million numbers, and you - will probably never find a number where ptest(p, 20) gives - the wrong answer. + The ptest function returns 0 if the number is definitely not + prime, and 1 is the number is probably prime. The chance + of a number which is probably prime being actually composite + is less than 1/4 raised to the power of the iteration count. + For example, for a random number p, ptest(p, 10) incorrectly + returns 1 less than once in every million numbers, and you + will probably never find a number where ptest(p, 20) gives + the wrong answer. - The first 3 args of nextcand and prevcand functions are the same - arguments as ptest. But unlike ptest, nextcand and prevcand return - the next and previous values for which ptest is true. + The first 3 args of nextcand and prevcand functions are the same + arguments as ptest. But unlike ptest, nextcand and prevcand return + the next and previous values for which ptest is true. - For example, nextcand(2^1000) returns 2^1000+297 because - 2^1000+297 is the smallest value x > 2^1000 for which - ptest(x,1) is true. And for example, prevcand(2^31-1,10,5) - returns 2147483629 (2^31-19) because 2^31-19 is the largest - value y < 2^31-1 for which ptest(y,10,5) is true. + For example, nextcand(2^1000) returns 2^1000+297 because + 2^1000+297 is the smallest value x > 2^1000 for which + ptest(x,1) is true. And for example, prevcand(2^31-1,10,5) + returns 2147483629 (2^31-19) because 2^31-19 is the largest + value y < 2^31-1 for which ptest(y,10,5) is true. - The nextcand and prevcand functions also have a 5 argument form: + The nextcand and prevcand functions also have a 5 argument form: - nextcand(num, count, skip, modval, modulus) - prevcand(num, count, skip, modval, modulus) + nextcand(num, count, skip, modval, modulus) + prevcand(num, count, skip, modval, modulus) - return the smallest (or largest) value ans > num (or < num) that - is also == modval % modulus for which ptest(ans,count,skip) is true. + return the smallest (or largest) value ans > num (or < num) that + is also == modval % modulus for which ptest(ans,count,skip) is true. - The builtins nextprime(x) and prevprime(x) return the - next and previous primes with respect to x respectively. - As of this release, x must be < 2^32. With one argument, they - will return an error if x is out of range. With two arguments, - they will not generate an error but instead will return y. + The builtins nextprime(x) and prevprime(x) return the + next and previous primes with respect to x respectively. + As of this release, x must be < 2^32. With one argument, they + will return an error if x is out of range. With two arguments, + they will not generate an error but instead will return y. - The builtin function pix(x) returns the number of primes <= x. - As of this release, x must be < 2^32. With one argument, pix(x) - will return an error if x is out of range. With two arguments, - pix(x,y) will not generate an error but instead will return y. + The builtin function pix(x) returns the number of primes <= x. + As of this release, x must be < 2^32. With one argument, pix(x) + will return an error if x is out of range. With two arguments, + pix(x,y) will not generate an error but instead will return y. - The builtin function factor may be used to search for the - smallest factor of a given number. The call factor(x,y) - will attempt to find the smallest factor of x < min(x,y). - As of this release, y must be < 2^32. If y is omitted, y - is assumed to be 2^32-1. + The builtin function factor may be used to search for the + smallest factor of a given number. The call factor(x,y) + will attempt to find the smallest factor of x < min(x,y). + As of this release, y must be < 2^32. If y is omitted, y + is assumed to be 2^32-1. - If x < 0, factor(x,y) will return -1. If no factor < - min(x,y) is found, factor(x,y) will return 1. In all other - cases, factor(x,y) will return the smallest prime factor - of x. Note except for the case when abs(x) == 1, factor(x,y) - will not return x. + If x < 0, factor(x,y) will return -1. If no factor < + min(x,y) is found, factor(x,y) will return 1. In all other + cases, factor(x,y) will return the smallest prime factor + of x. Note except for the case when abs(x) == 1, factor(x,y) + will not return x. - If factor is called with y that is too large, or if x or y - is not an integer, calc will report an error. If a 3rd argument - is given, factor will return that value instead. For example, - factor(1/2,b,c) will return c instead of issuing an error. + If factor is called with y that is too large, or if x or y + is not an integer, calc will report an error. If a 3rd argument + is given, factor will return that value instead. For example, + factor(1/2,b,c) will return c instead of issuing an error. - The builtin lfactor(x,y) searches a number of primes instead - of below a limit. As of this release, y must be <= 203280221 - (y <= pix(2^32-1)). In all other cases, lfactor is operates - in the same way as factor. + The builtin lfactor(x,y) searches a number of primes instead + of below a limit. As of this release, y must be <= 203280221 + (y <= pix(2^32-1)). In all other cases, lfactor is operates + in the same way as factor. - If lfactor is called with y that is too large, or if x or y - is not an integer, calc will report an error. If a 3rd argument - is given, lfactor will return that value instead. For example, - lfactor(1/2,b,c) will return c instead of issuing an error. + If lfactor is called with y that is too large, or if x or y + is not an integer, calc will report an error. If a 3rd argument + is given, lfactor will return that value instead. For example, + lfactor(1/2,b,c) will return c instead of issuing an error. - The lfactor function is slower than factor. If possible factor - should be used instead of lfactor. + The lfactor function is slower than factor. If possible factor + should be used instead of lfactor. - The builtin isprime(x) will attempt to determine if x is prime. - As of this release, x must be < 2^32. With one argument, isprime(x) - will return an error if x is out of range. With two arguments, - isprime(x,y) will not generate an error but instead will return y. + The builtin isprime(x) will attempt to determine if x is prime. + As of this release, x must be < 2^32. With one argument, isprime(x) + will return an error if x is out of range. With two arguments, + isprime(x,y) will not generate an error but instead will return y. - The functions rcin, rcmul, rcout, rcpow, and rcsq are used to - perform modular arithmetic calculations for large odd numbers - faster than the usual methods. To do this, you first use the - rcin function to convert all input values into numbers which are - in a format called REDC format. Then you use rcmul, rcsq, and - rcpow to multiply such numbers together to produce results also - in REDC format. Finally, you use rcout to convert a number in - REDC format back to a normal number. The addition, subtraction, - negation, and equality comparison between REDC numbers are done - using the normal modular methods. For example, to calculate the - value 13 * 17 + 1 (mod 11), you could use: + The functions rcin, rcmul, rcout, rcpow, and rcsq are used to + perform modular arithmetic calculations for large odd numbers + faster than the usual methods. To do this, you first use the + rcin function to convert all input values into numbers which are + in a format called REDC format. Then you use rcmul, rcsq, and + rcpow to multiply such numbers together to produce results also + in REDC format. Finally, you use rcout to convert a number in + REDC format back to a normal number. The addition, subtraction, + negation, and equality comparison between REDC numbers are done + using the normal modular methods. For example, to calculate the + value 13 * 17 + 1 (mod 11), you could use: - p = 11; - t1 = rcin(13, p); - t2 = rcin(17, p); - t3 = rcin(1, p); - t4 = rcmul(t1, t2, p); - t5 = (t4 + t3) % p; - answer = rcout(t5, p); + p = 11; + t1 = rcin(13, p); + t2 = rcin(17, p); + t3 = rcin(1, p); + t4 = rcmul(t1, t2, p); + t5 = (t4 + t3) % p; + answer = rcout(t5, p); - The swap function exchanges the values of two variables without - performing copies. For example, after: + The swap function exchanges the values of two variables without + performing copies. For example, after: - x = 17; - y = 19; - swap(x, y); + x = 17; + y = 19; + swap(x, y); - then x is 19 and y is 17. This function should not be used to - swap a value which is contained within another one. If this is - done, then some memory will be lost. For example, the following - should not be done: + then x is 19 and y is 17. This function should not be used to + swap a value which is contained within another one. If this is + done, then some memory will be lost. For example, the following + should not be done: - mat x[5]; - swap(x, x[0]); + mat x[5]; + swap(x, x[0]); - The hash function returns a relatively small non-negative integer - for one or more input values. The hash values should not be used - across runs of the calculator, since the algorithms used to generate - the hash value may change with different versions of the calculator. + The hash function returns a relatively small non-negative integer + for one or more input values. The hash values should not be used + across runs of the calculator, since the algorithms used to generate + the hash value may change with different versions of the calculator. - The base function allows one to specify how numbers should be - printed. The base function provides a numeric shorthand to the - config("mode") interface. With no args, base() will return the - current mode. With 1 arg, base(val) will set the mode according to - the arg and return the previous mode. + The base function allows one to specify how numbers should be + printed. The base function provides a numeric shorthand to the + config("mode") interface. With no args, base() will return the + current mode. With 1 arg, base(val) will set the mode according to + the arg and return the previous mode. - The following convention is used to declare modes: + The following convention is used to declare modes: - base config - value string + base config + value string - 2 "binary" binary fractions - 8 "octal" octal fractions - 10 "real" decimal floating point - 16 "hex" hexadecimal fractions - -10 "int" decimal integer - 1/3 "frac" decimal fractions - 1e20 "exp" decimal exponential + 2 "binary" binary fractions + 8 "octal" octal fractions + 10 "real" decimal floating point + 16 "hex" hexadecimal fractions + -10 "int" decimal integer + 1/3 "frac" decimal fractions + 1e20 "exp" decimal exponential - For convenience, any non-integer value is assumed to mean "frac", - and any integer >= 2^64 is assumed to mean "exp". + For convenience, any non-integer value is assumed to mean "frac", + and any integer >= 2^64 is assumed to mean "exp". ## Copyright (C) 1999-2017,2021 Landon Curt Noll ## @@ -207,7 +207,7 @@ ## ## 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 +## 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 @@ -215,8 +215,8 @@ ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/10 01:17:53 -## File existed as early as: 1995 +## Under source code control: 1995/07/10 01:17:53 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/builtin.top b/help/builtin.top index c13a9b0..2490dcf 100644 --- a/help/builtin.top +++ b/help/builtin.top @@ -1,11 +1,11 @@ Builtin functions - There is a large number of built-in functions. Many of the - functions work on several types of arguments, whereas some only - work for the correct types (e.g., numbers or strings). In the - following description, this is indicated by whether or not the - description refers to values or numbers. This display is generated - by the 'show builtin' command. + There is a large number of built-in functions. Many of the + functions work on several types of arguments, whereas some only + work for the correct types (e.g., numbers or strings). In the + following description, this is indicated by whether or not the + description refers to values or numbers. This display is generated + by the 'show builtin' command. ## Copyright (C) 1999 Landon Curt Noll ## @@ -15,7 +15,7 @@ Builtin functions ## ## 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 +## 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 @@ -23,8 +23,8 @@ Builtin functions ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/10 01:17:53 -## File existed as early as: 1995 +## Under source code control: 1995/07/10 01:17:53 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/calc_tty b/help/calc_tty index e228aab..25b4e33 100644 --- a/help/calc_tty +++ b/help/calc_tty @@ -5,7 +5,7 @@ SYNOPSIS calc_tty() TYPES - return none if appears to be successful, error-value otherwise + return none if appears to be successful, error-value otherwise DESCRIPTION This may enable a return to normal operation if abnormal activity @@ -13,9 +13,9 @@ DESCRIPTION may occur when activity is resumed by an fg command after a ctrl-Z interrupt, or by any of the three commands: - ; !stty echo - ; !stty -cbreak - ; !stty echo -cbreak + ; !stty echo + ; !stty -cbreak + ; !stty echo -cbreak EXAMPLE ; calc_tty(); @@ -34,7 +34,7 @@ SEE ALSO ## ## 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 +## 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 @@ -42,7 +42,7 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2000/12/14 01:33:00 -## File existed as early as: 2000 +## Under source code control: 2000/12/14 01:33:00 +## File existed as early as: 2000 ## -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/calclevel b/help/calclevel index 4f37b43..824a504 100644 --- a/help/calclevel +++ b/help/calclevel @@ -5,12 +5,12 @@ SYNOPSIS calclevel() TYPES - return nonnegative integer + return nonnegative integer DESCRIPTION This function returns the calculation level at which it is called. When a command is being read from a terminal or from a file, - calc is at calculation level zero. The level is increased + calc is at calculation level zero. The level is increased by 1 each time calculation starts of a user-defined function or of eval(S) for some expression S which evaluates to a string. It decreases to zero if an error occurs or a quit or abort statement @@ -45,7 +45,7 @@ SEE ALSO ## ## 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 +## 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 @@ -53,8 +53,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1999/10/31 06:01:21 -## File existed as early as: 1999 +## Under source code control: 1999/10/31 06:01:21 +## File existed as early as: 1999 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/calcpath b/help/calcpath index 0ba8d69..7699e67 100644 --- a/help/calcpath +++ b/help/calcpath @@ -5,7 +5,7 @@ SYNOPSIS calcpath() TYPES - return string + return string DESCRIPTION This function returns the current value of the CALCPATH search path. @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## -## Under source code control: 2006/05/07 23:56:04 -## File existed as early as: 2006 +## Under source code control: 2006/05/07 23:56:04 +## File existed as early as: 2006 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/cas b/help/cas index deb81c4..9a50a7f 100644 --- a/help/cas +++ b/help/cas @@ -5,10 +5,10 @@ SYNOPSIS cas(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the trigonometric cosine plus sine of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called cosine and sine, is equivalent to: - cas(x) = cos(x) + sin(x) + cas(x) = cos(x) + sin(x) EXAMPLE ; print cas(1/2), cas(5/7), cas(42/7) @@ -54,14 +54,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -71,7 +71,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -79,8 +79,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/10/02 23:11:18 -## File existed as early as: 2023 +## Under source code control: 2023/10/02 23:11:18 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/catalan b/help/catalan index 7ec854f..08922e3 100644 --- a/help/catalan +++ b/help/catalan @@ -5,14 +5,14 @@ SYNOPSIS catalan(n) TYPES - n integer + n integer - return integer + return integer DESCRIPTION If n >= 0, this returns the Catalan number for index n: - catalan(n) = comb(2*n,n)/(n + 1) + catalan(n) = comb(2*n,n)/(n + 1) Zero is returned for negative n. @@ -45,7 +45,7 @@ SEE ALSO ## ## 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 +## 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 @@ -53,7 +53,7 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2000/12/14 01:33:00 -## File existed as early as: 2000 +## Under source code control: 2000/12/14 01:33:00 +## File existed as early as: 2000 ## -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ceil b/help/ceil index b0c52e8..64c9ae4 100644 --- a/help/ceil +++ b/help/ceil @@ -5,9 +5,9 @@ SYNOPSIS ceil(x) TYPES - x real, complex, list, matrix + x real, complex, list, matrix - return real or complex, list, matrix + return real or complex, list, matrix DESCRIPTION For real x, ceil(x) is the least integer not less than x. @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/30 01:12:01 -## File existed as early as: 1994 +## Under source code control: 1994/09/30 01:12:01 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/cfappr b/help/cfappr index a970d85..ef40e63 100644 --- a/help/cfappr +++ b/help/cfappr @@ -5,12 +5,12 @@ SYNOPSIS cfappr(x [,eps [,rnd]]) or cfappr(x, n [,rnd]) TYPES - x real - eps real with abs(eps) < 1, defaults to epsilon() - n real with n >= 1 - rnd integer, defaults to config("cfappr") + x real + eps real with abs(eps) < 1, defaults to epsilon() + n real with n >= 1 + rnd integer, defaults to config("cfappr") - return real + return real DESCRIPTION If x is an integer or eps is zero, either form returns x. @@ -21,23 +21,23 @@ DESCRIPTION If n >= 1 and den(x) > n, cfappr(x, n) returns the nearest above, nearest below, or nearest, approximation to x with denominator less - than or equal to n. If den(x) <= n, cfappr(x,n) returns x. + than or equal to n. If den(x) <= n, cfappr(x,n) returns x. In either case when the result v is not x, how v relates to x is determined by bits 0, 1, 2 and 4 of the argument rnd in the same way as these bits are used in the functions round() and appr(). In the following y is either eps or n. - rnd sign of remainder x - v + rnd sign of remainder x - v - 0 sgn(y) - 1 -sgn(y - 2 sgn(x), "rounding to zero" - 3 -sgn(x), "rounding from zero" - 4 +, "rounding down" - 5 -, "rounding up" - 6 sgn(x/y) - 7 -sgn(x/y) + 0 sgn(y) + 1 -sgn(y + 2 sgn(x), "rounding to zero" + 3 -sgn(x), "rounding from zero" + 4 +, "rounding down" + 5 -, "rounding up" + 6 sgn(x/y) + 7 -sgn(x/y) If bit 4 of rnd is set, the other bits are irrelevant for the eps case; thus for 16 <= rnd < 24, cfappr(x, eps, rnd) is the smallest-denominator @@ -96,7 +96,7 @@ SEE ALSO ## ## 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 +## 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 @@ -104,8 +104,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/30 01:23:59 -## File existed as early as: 1994 +## Under source code control: 1994/09/30 01:23:59 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/cfsim b/help/cfsim index 24d4ca6..731ab44 100644 --- a/help/cfsim +++ b/help/cfsim @@ -5,10 +5,10 @@ SYNOPSIS cfsim(x [,rnd]) TYPES - x real - rnd integer, defaults to config("cfsim") + x real + rnd integer, defaults to config("cfsim") - return real + return real DESCRIPTION If x is not an integer, cfsim(x, rnd) returns either the nearest @@ -20,23 +20,23 @@ DESCRIPTION For 0 <= rnd < 4, the sign of the remainder x - cfsim(x, rnd) is as follows: - rnd sign of x - cfsim(x, rnd) + rnd sign of x - cfsim(x, rnd) - 0 +, as if rounding down - 1 -. as if rounding up - 2 sgn(x), as if rounding to zero - 3 -sgn(x), as if rounding from zero + 0 +, as if rounding down + 1 -. as if rounding up + 2 sgn(x), as if rounding to zero + 3 -sgn(x), as if rounding from zero This corresponds to the use of rnd for functions like round(x, n, rnd). If bit 3 or 4 of rnd is set, the lower order bits are ignored; bit 3 - is ignored if bit 4 is set. Thus, for rnd > 3, it sufficient to + is ignored if bit 4 is set. Thus, for rnd > 3, it sufficient to consider the two cases rnd = 8 and rnd = 16. If den(x) > 2, cfsim(x, 8) returns the value of the penultimate simple continued-fraction approximate to x, i.e. if: - x = a_0 + 1/(a_1 + 1/(a_2 + ... + 1/a_n) ...)), + x = a_0 + 1/(a_1 + 1/(a_2 + ... + 1/a_n) ...)), where a_0 is an integer, a_1, ..., a_n are positive integers, and a_n >= 2, the value returned is that of the continued fraction @@ -53,10 +53,10 @@ DESCRIPTION In summary, for cfsim(x, rnd) when rnd = 8 or 16, the results are: - rnd integer x half-integer x den(x) > 2 + rnd integer x half-integer x den(x) > 2 - 8 0 x - sgn(x)/2 approximate - 16 x - sgn(x) x + sgn(x)/2 nearest + 8 0 x - sgn(x)/2 approximate + 16 x - sgn(x) x + sgn(x)/2 nearest From either cfsim(x, 0) and cfsim(x, 1), the other is easily determined: if one of them has value w, the other has value @@ -72,7 +72,7 @@ DESCRIPTION Iteration of cfsim(x,8) until an integer is obtained gives a sequence of "good" approximations to x with decreasing denominators and correspondingly decreasing accuracy; each denominator is less than half - the preceding denominator. (Unlike the "forward" sequence of + the preceding denominator. (Unlike the "forward" sequence of continued-fraction approximates these are not necessarily alternately greater than and less than x.) @@ -80,19 +80,19 @@ DESCRIPTION For rnd = 0 or 1 and any x, or rnd = 8 or 16 and x with den(x) > 2: - cfsim(n + x, rnd) = n + cfsim(x, rnd). + cfsim(n + x, rnd) = n + cfsim(x, rnd). This equation also holds for the other values of rnd if n + x and x have the same sign. For rnd = 2, 3, 8 or 16, and any x: - cfsim(-x, rnd) = -cfsim(x, rnd). + cfsim(-x, rnd) = -cfsim(x, rnd). If rnd = 8 or 16, except for integer x or 1/x for rnd = 8, and zero x for rnd = 16: - cfsim(1/x, rnd) = 1/cfsim(x, rnd). + cfsim(1/x, rnd) = 1/cfsim(x, rnd). EXAMPLE ; c = config("mode", "frac"); @@ -121,7 +121,7 @@ SEE ALSO ## ## 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 +## 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 @@ -129,8 +129,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/30 01:29:45 -## File existed as early as: 1994 +## Under source code control: 1994/09/30 01:29:45 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/char b/help/char index 48b4e75..0e13667 100644 --- a/help/char +++ b/help/char @@ -5,9 +5,9 @@ SYNOPSIS char(j) TYPES - j integer, 0 <= j < 256 + j integer, 0 <= j < 256 - return string + return string DESCRIPTION For j > 0, returns a string of length 1 with a character that has @@ -34,7 +34,7 @@ SEE ALSO ## ## 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 +## 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 @@ -42,8 +42,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/30 01:45:45 -## File existed as early as: 1994 +## Under source code control: 1994/09/30 01:45:45 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/cis b/help/cis index c66cd65..04d6fdc 100644 --- a/help/cis +++ b/help/cis @@ -5,10 +5,10 @@ SYNOPSIS cis(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the Euler's formula value of x to a multiple of eps with error less in @@ -16,8 +16,8 @@ DESCRIPTION This function is sometimes called cosine and sine, is equivalent to: - cis(x) = cos(x) + 1i*sin(x) - cis(x) = exp(1i * x) + cis(x) = cos(x) + 1i*sin(x) + cis(x) = exp(1i * x) EXAMPLE ; print cis(1/2), cis(5/7) @@ -60,14 +60,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -77,7 +77,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -85,8 +85,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/10/02 23:11:18 -## File existed as early as: 2023 +## Under source code control: 2023/10/02 23:11:18 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/cmdbuf b/help/cmdbuf index c4acfd7..01d3d2e 100644 --- a/help/cmdbuf +++ b/help/cmdbuf @@ -5,7 +5,7 @@ SYNOPSIS cmdbuf() TYPES - return str + return str DESCRIPTION This function returns the command string that was formed by calc based @@ -37,7 +37,7 @@ SEE ALSO ## ## 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 +## 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 @@ -45,8 +45,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/09 04:05:58 -## File existed as early as: 1995 +## Under source code control: 1995/07/09 04:05:58 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/cmp b/help/cmp index 32ae502..b2a33a5 100644 --- a/help/cmp +++ b/help/cmp @@ -12,79 +12,79 @@ TYPES For non-object x and y: - x any - y any + x any + y any - return if x and y are both real: -1, 0, or 1 - if x and y are both numbers but not both real: - -1, 0, 1, -1+1i, 1i, 1+1i, -1-1i, -1i, or 1-1i - if x and y are both strings: -1, 0, or 1 - all other cases: the null value + return if x and y are both real: -1, 0, or 1 + if x and y are both numbers but not both real: + -1, 0, 1, -1+1i, 1i, 1+1i, -1-1i, -1i, or 1-1i + if x and y are both strings: -1, 0, or 1 + all other cases: the null value DESCRIPTION x and y both real: cmp(x, y) = sgn(x - y), i.e. -1, 0, or 1 - according as x < y, x == y, or x > y + according as x < y, x == y, or x > y x and y both numbers, at least one being complex: - cmp(x,y) = sgn(re(x) - re(y)) + sgn(im(x) - im(y)) * 1i + cmp(x,y) = sgn(re(x) - re(y)) + sgn(im(x) - im(y)) * 1i x and y both strings: successive characters are compared until either - different characters are encountered or at least one string is - completed. If the comparison ends because of different characters, - cmp(x,y) = 1 or -1 according as the greater character is in x or y. - If all characters compared in both strings are equal, then - cmp(x,y) = -1, 0 or 1 according as the length of x is less than, - equal to, or greater than the length of y. (This comparison - is performed via the strcmp() libc function.) + different characters are encountered or at least one string is + completed. If the comparison ends because of different characters, + cmp(x,y) = 1 or -1 according as the greater character is in x or y. + If all characters compared in both strings are equal, then + cmp(x,y) = -1, 0 or 1 according as the length of x is less than, + equal to, or greater than the length of y. (This comparison + is performed via the strcmp() libc function.) objects: comparisons of objects are usually intended for some total or - partial ordering and appropriate definitions of cmp(a,b) may - make use of comparison of numerical or string components. - definitions using comparison of numbers or strings are usually - appropriate. For example, after + partial ordering and appropriate definitions of cmp(a,b) may + make use of comparison of numerical or string components. + definitions using comparison of numbers or strings are usually + appropriate. For example, after - obj point {x,y}; + obj point {x,y}; - if points with real components are to be partially ordered by their - Euclidean distance from the origin, an appropriate point_rel - function may be that given by + if points with real components are to be partially ordered by their + Euclidean distance from the origin, an appropriate point_rel + function may be that given by - define point_rel(a,b) = sgn(a.x^2 + a.y^2 - b.x^2 - b.y^2); + define point_rel(a,b) = sgn(a.x^2 + a.y^2 - b.x^2 - b.y^2); - A total "lexicographic" ordering is that given by: + A total "lexicographic" ordering is that given by: - define point_rel(a,b) { - if (a.y != b.y) - return sgn(a.y - b.y); - return (a.x - b.x); - } + define point_rel(a,b) { + if (a.y != b.y) + return sgn(a.y - b.y); + return (a.x - b.x); + } - A comparison function that compares points analogously to - cmp(a,b) for real and complex numbers is that given by + A comparison function that compares points analogously to + cmp(a,b) for real and complex numbers is that given by - define point_rel(P1, P2) { - return obj point = {sgn(P1.x-P2.x), sgn(P1.y-P2.y)}; - } + define point_rel(P1, P2) { + return obj point = {sgn(P1.x-P2.x), sgn(P1.y-P2.y)}; + } - The range of this function is the set of nine points with zero - or unit components. + The range of this function is the set of nine points with zero + or unit components. Some properties of cmp(a,b) for real or complex a and b are: - cmp(a + c, b + c) = cmp(a, b) + cmp(a + c, b + c) = cmp(a, b) - cmp(a, b) == 0 if and only if a == b + cmp(a, b) == 0 if and only if a == b - cmp(b, a) = -cmp(a, b) + cmp(b, a) = -cmp(a, b) - if c is real or pure imaginary, cmp(c * a, c * b) = c * cmp(a,b) + if c is real or pure imaginary, cmp(c * a, c * b) = c * cmp(a,b) Then a function that defines "b is between a and c" in an often useful sense is - define between(a,b,c) = (cmp(a,b) == cmp(b,c)). + define between(a,b,c) = (cmp(a,b) == cmp(b,c)). For example, in this sense, 3 + 4i is between 1 + 5i and 4 + 2i. @@ -122,7 +122,7 @@ SEE ALSO ## ## 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 +## 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 @@ -130,8 +130,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/20 02:52:30 -## File existed as early as: 1994 +## Under source code control: 1994/10/20 02:52:30 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/comb b/help/comb index 4310007..9ab5050 100644 --- a/help/comb +++ b/help/comb @@ -5,17 +5,17 @@ SYNOPSIS comb(x, y) TYPES - x integer - y integer + x integer + y integer - return integer + return integer DESCRIPTION Return the combinatorial number C(x,y) which is defined as: - x! - --------- - y!*(x-y)! + x! + --------- + y!*(x-y)! This function computes the number of combinations in which y things may be chosen from x items ignoring the order in which they are chosen. @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/20 04:03:02 -## File existed as early as: 1994 +## Under source code control: 1994/10/20 04:03:02 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/command b/help/command index ccb0cc4..6b87df1 100644 --- a/help/command +++ b/help/command @@ -3,7 +3,7 @@ Command sequence This is a sequence of any the following command formats, where each command is terminated by a semicolon or newline. Long command lines can be extended by using a back-slash followed by a newline - character. When this is done, the prompt shows a double angle + character. When this is done, the prompt shows a double angle bracket to indicate that the line is still in progress. Certain cases will automatically prompt for more input in a similar manner, even without the back-slash. The most common case for this is when @@ -19,26 +19,26 @@ Command sequence define function(params) { body } define function(params) = expression - This first form defines a full function which can consist - of declarations followed by many statements which implement - the function. + This first form defines a full function which can consist + of declarations followed by many statements which implement + the function. - The second form defines a simple function which calculates - the specified expression value from the specified parameters. - The expression cannot be a statement. However, the comma - and question mark operators can be useful. Examples of - simple functions are: + The second form defines a simple function which calculates + the specified expression value from the specified parameters. + The expression cannot be a statement. However, the comma + and question mark operators can be useful. Examples of + simple functions are: - define sumcubes(a, b) = a^3 + b^3 - define pimod(a) = a % pi() - define printnum(a, n, p) - { - if (p == 0) { - print a: "^": n, "=", a^n; - } else { - print a: "^": n, "mod", p, "=", pmod(a,n,p); - } - } + define sumcubes(a, b) = a^3 + b^3 + define pimod(a) = a % pi() + define printnum(a, n, p) + { + if (p == 0) { + print a: "^": n, "=", a^n; + } else { + print a: "^": n, "mod", p, "=", pmod(a,n,p); + } + } read calc commands @@ -48,70 +48,70 @@ Command sequence read filename read -once filename - This reads definitions from the specified calc resource filename. + This reads definitions from the specified calc resource filename. - In the 1st and 2nd forms, if var is a global variable string - value, then the value of that variable is used as a filename. + In the 1st and 2nd forms, if var is a global variable string + value, then the value of that variable is used as a filename. - The following is equivalent to read lucas.cal or read "lucas.cal": + The following is equivalent to read lucas.cal or read "lucas.cal": - global var = "lucas.cal"; - read $var; + global var = "lucas.cal"; + read $var; - In the 3rd or 4th forms, the filename argument is treated - as a literal string, not a variable. In these forms, the - name can be quoted if desired. + In the 3rd or 4th forms, the filename argument is treated + as a literal string, not a variable. In these forms, the + name can be quoted if desired. - The calculator uses the CALCPATH environment variable to - search through the specified directories for the filename, - similarly to the use of the PATH environment variable. - If CALCPATH is not defined, then a default path which is - usually ":/usr/local/lib/calc" is used. + The calculator uses the CALCPATH environment variable to + search through the specified directories for the filename, + similarly to the use of the PATH environment variable. + If CALCPATH is not defined, then a default path which is + usually ":/usr/local/lib/calc" is used. - The ".cal" extension is defaulted for input files, so that - if "filename" is not found, then "filename.cal" is then - searched for. The contents of the filename are command - sequences which can consist of expressions to evaluate or - functions to define, just like at the top level command level. + The ".cal" extension is defaulted for input files, so that + if "filename" is not found, then "filename.cal" is then + searched for. The contents of the filename are command + sequences which can consist of expressions to evaluate or + functions to define, just like at the top level command level. - When -once is given, the read command acts like the regular - read expect that it will ignore filename if is has been - previously read. + When -once is given, the read command acts like the regular + read expect that it will ignore filename if is has been + previously read. - The read -once form is particularly useful in a resource - file that needs to read a 2nd resource file. By using the - READ -once command, one will not reread that 2nd resource - file, nor will once risk entering into a infinite READ loop - (where that 2nd resource file directly or indirectly does - a READ of the first resource file). + The read -once form is particularly useful in a resource + file that needs to read a 2nd resource file. By using the + READ -once command, one will not reread that 2nd resource + file, nor will once risk entering into a infinite READ loop + (where that 2nd resource file directly or indirectly does + a READ of the first resource file). - If the -m mode disallows opening of files for reading, - this command will be disabled. + If the -m mode disallows opening of files for reading, + this command will be disabled. - To read a calc resource file without printing various - messages about defined functions, the "resource_debug" - config should be set to zero. For example: + To read a calc resource file without printing various + messages about defined functions, the "resource_debug" + config should be set to zero. For example: - read lucas; + read lucas; - will, by default, print messages such as: + will, by default, print messages such as: - lucas(h,n) defined - gen_u2(h,n,v1) defined - gen_u0(h,n,v1) defined - rodseth_xhn(x,h,n) defined - gen_v1(h,n) defined - ldebug(funct,str) defined - legacy_gen_v1(h,n) defined + lucas(h,n) defined + gen_u2(h,n,v1) defined + gen_u0(h,n,v1) defined + rodseth_xhn(x,h,n) defined + gen_v1(h,n) defined + ldebug(funct,str) defined + legacy_gen_v1(h,n) defined When "resource_debug" is zero, such messages are silenced. - config("resource_debug", 0),; - read lucas; + config("resource_debug", 0),; + read lucas; - To silence such messages on the calc command line, try: + To silence such messages on the calc command line, try: - calc -p -D :0 'read -once lucas; lucas(1, 23209);' + calc -p -D :0 'read -once lucas; lucas(1, 23209);' write calc commands @@ -119,29 +119,29 @@ Command sequence write $var write filename - This writes the values of all global variables to the - specified filename, in such a way that the file can be - later read in order to recreate the variable values. - For speed reasons, values are written as hex fractions. - This command currently only saves simple types, so that - matrices, lists, and objects are not saved. Function - definitions are also not saved. + This writes the values of all global variables to the + specified filename, in such a way that the file can be + later read in order to recreate the variable values. + For speed reasons, values are written as hex fractions. + This command currently only saves simple types, so that + matrices, lists, and objects are not saved. Function + definitions are also not saved. - In the 1st form, if var is a global variable string - value, then the value of that variable is used as a filename. + In the 1st form, if var is a global variable string + value, then the value of that variable is used as a filename. - The following is equivalent to write dump.out or - write "dump.out": + The following is equivalent to write dump.out or + write "dump.out": - global var = "dump.out"; - write $var; + global var = "dump.out"; + write $var; - In the 2nd form, the filename argument is treated as a literal - string, not a variable. In this form, the name can be quoted - if desired. + In the 2nd form, the filename argument is treated as a literal + string, not a variable. In this form, the name can be quoted + if desired. - If the -m mode disallows opening of files for writing, - this command will be disabled. + If the -m mode disallows opening of files for writing, + this command will be disabled. quit or exit @@ -151,35 +151,35 @@ Command sequence exit exit string - The action of these commands depends on where they are used. - At the interactive level, they will cause calc to exit. - This is the normal way to leave the calculator. In any - other use, they will stop the current calculation as if - an error had occurred. + The action of these commands depends on where they are used. + At the interactive level, they will cause calc to exit. + This is the normal way to leave the calculator. In any + other use, they will stop the current calculation as if + an error had occurred. - If a string is given, then the string is printed as the reason - for quitting, otherwise a general quit message is printed. - The routine name and line number which executed the quit is - also printed in either case. + If a string is given, then the string is printed as the reason + for quitting, otherwise a general quit message is printed. + The routine name and line number which executed the quit is + also printed in either case. - Exit is an alias for quit. + Exit is an alias for quit. - Quit is useful when a routine detects invalid arguments, - in order to stop a calculation cleanly. For example, - for a square root routine, an error can be given if the - supplied parameter was a negative number, as in: + Quit is useful when a routine detects invalid arguments, + in order to stop a calculation cleanly. For example, + for a square root routine, an error can be given if the + supplied parameter was a negative number, as in: - define mysqrt(n) - { - if (! isnum(n)) - quit "non-numeric argument"; - if (n < 0) - quit "Negative argument"; - return sqrt(n); - } + define mysqrt(n) + { + if (! isnum(n)) + quit "non-numeric argument"; + if (n < 0) + quit "Negative argument"; + return sqrt(n); + } - See 'more information about abort and quit' below for - more information. + See 'more information about abort and quit' below for + more information. abort @@ -187,12 +187,12 @@ Command sequence abort abort string - This command behaves like QUIT except that it will attempt - to return to the interactive level if permitted, otherwise - calc exit. + This command behaves like QUIT except that it will attempt + to return to the interactive level if permitted, otherwise + calc exit. - See 'more information about abort and quit' below for - more information. + See 'more information about abort and quit' below for + more information. change current directory @@ -200,45 +200,45 @@ Command sequence cd cd dir - Change the current directory to 'dir'. If 'dir' is omitted, - change the current directory to the home directory, if $HOME - is set in the environment. + Change the current directory to 'dir'. If 'dir' is omitted, + change the current directory to the home directory, if $HOME + is set in the environment. show information ---------------- show item - This command displays some information where 'item' is - one of the following: + This command displays some information where 'item' is + one of the following: - blocks unfreed named blocks - builtin built in functions - config config parameters and values - constants cache of numeric constants - custom custom functions if calc -C was used - errors new error-values created - files open files, file position and sizes - function user-defined functions - globaltypes global variables - objfunctions possible object functions - objtypes defined objects - opcodes internal opcodes for function `func' - sizes size in octets of calc value types - realglobals numeric global variables - statics un-scoped static variables - numbers calc number cache - redcdata REDC data defined - strings calc string cache - literals calc literal cache + blocks unfreed named blocks + builtin built in functions + config config parameters and values + constants cache of numeric constants + custom custom functions if calc -C was used + errors new error-values created + files open files, file position and sizes + function user-defined functions + globaltypes global variables + objfunctions possible object functions + objtypes defined objects + opcodes internal opcodes for function `func' + sizes size in octets of calc value types + realglobals numeric global variables + statics un-scoped static variables + numbers calc number cache + redcdata REDC data defined + strings calc string cache + literals calc literal cache - Only the first 4 characters of item are examined, so: + Only the first 4 characters of item are examined, so: - show globals - show global - show glob + show globals + show global + show glob - do the same thing. + do the same thing. calc help @@ -246,20 +246,20 @@ Command sequence help $var help name - This displays a help related to 'name' or general - help of none is given. + This displays a help related to 'name' or general + help of none is given. - In the 1st form, if var is a global variable string - value, then the value of that variable is used as a name. + In the 1st form, if var is a global variable string + value, then the value of that variable is used as a name. - The following is equivalent to help command or help "command": + The following is equivalent to help command or help "command": - global var = "command"; - help $var; + global var = "command"; + help $var; - In the 2nd form, the filename argument is treated as a literal - string, not a variable. In this form, the name can be quoted - if desired. + In the 2nd form, the filename argument is treated as a literal + string, not a variable. In this form, the name can be quoted + if desired. =-= @@ -269,28 +269,28 @@ Command sequence Consider the following calc file called myfile.cal: - print "start of myfile.cal"; - define q() {quit "quit from q()"; print "end of q()"} - define a() {abort "abort from a()"} - x = 3; - {print "start #1"; if (x > 1) q()} print "after #1"; - {print "start #2"; if (x > 1) a()} print "after #2"; - {print "start #3"; if (x > 1) quit "quit from 3rd statement"} - print "end of myfile.cal"; + print "start of myfile.cal"; + define q() {quit "quit from q()"; print "end of q()"} + define a() {abort "abort from a()"} + x = 3; + {print "start #1"; if (x > 1) q()} print "after #1"; + {print "start #2"; if (x > 1) a()} print "after #2"; + {print "start #3"; if (x > 1) quit "quit from 3rd statement"} + print "end of myfile.cal"; The command: - calc read myfile + calc read myfile will produce: - q() defined - a() defined - start statement #1 - quit from q() - after statement #1 - start statement #2 - abort from a() + q() defined + a() defined + start statement #1 + quit from q() + after statement #1 + start statement #2 + abort from a() The QUIT within the q() function prevented the ``end of q()'' statement from being evaluated. This QUIT command caused @@ -303,38 +303,38 @@ Command sequence The command: - calc -i read myfile + calc -i read myfile will produce: - q() defined - a() defined - start statement #1 - quit from q() - after statement #1 - start statement #2 - abort from a() - ; <==== calc interactive prompt + q() defined + a() defined + start statement #1 + quit from q() + after statement #1 + start statement #2 + abort from a() + ; <==== calc interactive prompt because the '-i' calc causes ABORT to drop into an - interactive prompt. However typing a QUIT or ABORT + interactive prompt. However typing a QUIT or ABORT at the interactive prompt level will always calc to exit, even when calc is invoked with '-i'. Also observe that both of these commands: - cat myfile.cal | calc - cat myfile.cal | calc -i + cat myfile.cal | calc + cat myfile.cal | calc -i will produce: - q() defined - a() defined - start statement #1 - quit from q() - after statement #1 - start statement #2 - abort from a() + q() defined + a() defined + start statement #1 + quit from q() + after statement #1 + start statement #2 + abort from a() The ABORT inside function a() halts the processing of statements from the input source (standard input). Because standard input @@ -344,23 +344,23 @@ Command sequence If one were to type in the contents of myfile.cal interactively, calc will produce: - ; print "start of myfile.cal"; - start of myfile.cal - ; define q() {quit "quit from q()"; print "end of q()"} - q() defined - ; define a() {abort "abort from a()"} - a() defined - ; x = 3; - ; {print "start #1"; if (x > 1) q()} print "after #1"; - start statement #1 - quit from q() - after statement #1 - ; {print "start #2"; if (x > 1) a()} print "after #2"; - start statement #2 - abort from a() - ; {print "start #3"; if (x > 1) quit "quit from 3rd statement"} - start #3 - quit from 3rd statement + ; print "start of myfile.cal"; + start of myfile.cal + ; define q() {quit "quit from q()"; print "end of q()"} + q() defined + ; define a() {abort "abort from a()"} + a() defined + ; x = 3; + ; {print "start #1"; if (x > 1) q()} print "after #1"; + start statement #1 + quit from q() + after statement #1 + ; {print "start #2"; if (x > 1) a()} print "after #2"; + start statement #2 + abort from a() + ; {print "start #3"; if (x > 1) quit "quit from 3rd statement"} + start #3 + quit from 3rd statement The ABORT from within the a() function returned control to the interactive level. @@ -372,8 +372,8 @@ Command sequence Also see the help topic: - statement flow control and declaration statements - usage how to invoke the calc command and calc -options + statement flow control and declaration statements + usage how to invoke the calc command and calc -options ## Copyright (C) 1999-2006,2018,2021 Landon Curt Noll ## @@ -383,7 +383,7 @@ Command sequence ## ## 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 +## 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 @@ -391,8 +391,8 @@ Command sequence ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:17 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:17 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/config b/help/config index ad8636a..cdad9b1 100644 --- a/help/config +++ b/help/config @@ -5,102 +5,102 @@ SYNOPSIS config(parameter [,value]) TYPES - parameter string - value int, string, config state + parameter string + value int, string, config state - return config state + return config state DESCRIPTION The config() builtin affects how the calculator performs certain - operations. Among features that are controlled by these parameters + operations. Among features that are controlled by these parameters are the accuracy of some calculations, the displayed format of results, the choice from possible alternative algorithms, and whether or not - debugging information is displayed. The parameters are + debugging information is displayed. The parameters are read or set using the "config" built-in function; they remain in effect until their values are changed by a config or equivalent instruction. The following parameters can be specified: - "all" all configuration values listed below + "all" all configuration values listed below - "trace" turns tracing features on or off - "display" sets number of digits in prints. - "epsilon" sets error value for transcendental. - "maxprint" sets maximum number of elements printed. - "mode" sets printout mode. - "mode2" sets 2nd base printout mode. - "mul2" sets size for alternative multiply. - "sq2" sets size for alternative squaring. - "pow2" sets size for alternate powering. - "redc2" sets size for alternate REDC. - "tilde" enable/disable printing of the roundoff '~' - "tilde_space" enable/disable printing space after roundoff tilde '~ ' - "tab" enable/disable printing of leading tabs - "quomod" sets rounding mode for quomod - "quo" sets rounding mode for //, default for quo - "mod" sets "rounding" mode for %, default for mod - "sqrt" sets rounding mode for sqrt - "appr" sets rounding mode for appr - "cfappr" sets rounding mode for cfappr - "cfsim" sets rounding mode for cfsim - "round" sets rounding mode for round and bround - "triground" sets rounding mode for trigonometric and hyperbolic functions - "outround" sets rounding mode for printing of numbers - "leadzero" enables/disables printing of 0 as in 0.5 - "fullzero" enables/disables padding zeros as in 0.5000 - "maxscan" maximum number of scan errors before abort - "prompt" default interactive prompt - "more" default interactive multi-line input prompt - "blkmaxprint" number of block octets to print, 0 means all - "blkverbose" TRUE => print all lines, FALSE=>skip duplicates - "blkbase" block output base - "blkfmt" block output format - "calc_debug" controls internal calc debug information - "resource_debug" controls resource file debug information - "user_debug" for user defined debug information - "verbose_quit" TRUE => print message on empty quit or abort - "ctrl_d" The interactive meaning of ^D (Control D) - "program" Read-only calc program or shell script path - "basename" Read-only basename of the program value - "windows" Read-only indicator of MS windows - "cygwin" TRUE=>calc compiled with cygwin, Read-only - "compile_custom" TRUE=>calc was compiled with custom functions - "allow_custom" TRUE=>custom functions are enabled - "version" Read-only calc version - "baseb" bits in calculation base, a read-only value - "redecl_warn" TRUE => warn when redeclaring - "dupvar_warn" TRUE => warn when variable names collide - "hz" Read-only operating system tick rate or 0 + "trace" turns tracing features on or off + "display" sets number of digits in prints. + "epsilon" sets error value for transcendental. + "maxprint" sets maximum number of elements printed. + "mode" sets printout mode. + "mode2" sets 2nd base printout mode. + "mul2" sets size for alternative multiply. + "sq2" sets size for alternative squaring. + "pow2" sets size for alternate powering. + "redc2" sets size for alternate REDC. + "tilde" enable/disable printing of the roundoff '~' + "tilde_space" enable/disable printing space after roundoff tilde '~ ' + "tab" enable/disable printing of leading tabs + "quomod" sets rounding mode for quomod + "quo" sets rounding mode for //, default for quo + "mod" sets "rounding" mode for %, default for mod + "sqrt" sets rounding mode for sqrt + "appr" sets rounding mode for appr + "cfappr" sets rounding mode for cfappr + "cfsim" sets rounding mode for cfsim + "round" sets rounding mode for round and bround + "triground" sets rounding mode for trigonometric and hyperbolic functions + "outround" sets rounding mode for printing of numbers + "leadzero" enables/disables printing of 0 as in 0.5 + "fullzero" enables/disables padding zeros as in 0.5000 + "maxscan" maximum number of scan errors before abort + "prompt" default interactive prompt + "more" default interactive multi-line input prompt + "blkmaxprint" number of block octets to print, 0 means all + "blkverbose" TRUE => print all lines, FALSE=>skip duplicates + "blkbase" block output base + "blkfmt" block output format + "calc_debug" controls internal calc debug information + "resource_debug" controls resource file debug information + "user_debug" for user defined debug information + "verbose_quit" TRUE => print message on empty quit or abort + "ctrl_d" The interactive meaning of ^D (Control D) + "program" Read-only calc program or shell script path + "basename" Read-only basename of the program value + "windows" Read-only indicator of MS windows + "cygwin" TRUE=>calc compiled with cygwin, Read-only + "compile_custom" TRUE=>calc was compiled with custom functions + "allow_custom" TRUE=>custom functions are enabled + "version" Read-only calc version + "baseb" bits in calculation base, a read-only value + "redecl_warn" TRUE => warn when redeclaring + "dupvar_warn" TRUE => warn when variable names collide + "hz" Read-only operating system tick rate or 0 The "all" config value allows one to save/restore the configuration set of values. The return of: - config("all") + config("all") is a CONFIG type which may be used as the 2rd arg in a later call. One may save, modify and restore the configuration state as follows: - oldstate = config("all") - ... - config("tab", 0) - config("mod", 10) - ... - config("all", oldstate) + oldstate = config("all") + ... + config("tab", 0) + config("mod", 10) + ... + config("all", oldstate) This save/restore method is useful within functions. It allows functions to control their configuration without impacting the calling function. - There are two configuration state aliases that may be set. To + There are two configuration state aliases that may be set. To set the backward compatible standard configuration: - config("all", "oldstd") + config("all", "oldstd") The "oldstd" will restore the configuration to the default at startup. A new configuration that some people prefer may be set by: - config("all", "newstd") + config("all", "newstd") The "newstd" is not backward compatible with the historic configuration. Even so, some people prefer this configuration @@ -110,34 +110,34 @@ DESCRIPTION The following are synonyms for true: - "on" - "true" - "t" - "yes" - "y" - "set" - "1" - any non-zero number + "on" + "true" + "t" + "yes" + "y" + "set" + "1" + any non-zero number The following are synonyms for false: - "off" - "false" - "f" - "no" - "n" - "unset" - "0" - the number zero (0) + "off" + "false" + "f" + "no" + "n" + "unset" + "0" + the number zero (0) Examples of setting some parameters are: - config("mode", "exp"); exponential output - config("display", 50); 50 digits of output - epsilon(epsilon() / 8); 3 bits more accuracy - config("tilde", 0) disable roundoff tilde printing - config("tilde_space", 1) enable printing space after roundoff tilde - config("tab", "off") disable leading tab printing + config("mode", "exp"); exponential output + config("display", 50); 50 digits of output + epsilon(epsilon() / 8); 3 bits more accuracy + config("tilde", 0) disable roundoff tilde printing + config("tilde_space", 1) enable printing space after roundoff tilde + config("tab", "off") disable leading tab printing =-= @@ -147,18 +147,18 @@ DESCRIPTION that may be useful for debugging. These features correspond to powers of 2 which contribute additively to config("trace"): - 1: opcodes are displayed as functions are evaluated + 1: opcodes are displayed as functions are evaluated - 2: disables the inclusion of debug lines in opcodes for functions - whose definitions are introduced with a left-brace. + 2: disables the inclusion of debug lines in opcodes for functions + whose definitions are introduced with a left-brace. - 4: the number of links for real and complex numbers are displayed - when the numbers are printed; for real numbers "#" or for - complex numbers "##", followed by the number of links, are - printed immediately after the number. + 4: the number of links for real and complex numbers are displayed + when the numbers are printed; for real numbers "#" or for + complex numbers "##", followed by the number of links, are + printed immediately after the number. - 8: the opcodes for a new functions are displayed when the function - is successfully defined. + 8: the opcodes for a new functions are displayed when the function + is successfully defined. See also resource_debug, calc_debug and user_debug below for more debug levels. @@ -171,7 +171,7 @@ DESCRIPTION the decimal point to be printed in real, exponential or engineering mode in normal unformatted printing (print, strprint, fprint) or in formatted printing (printf, strprintf, fprintf) when precision is not - specified. The initial value for oldstd is 20, for newstd 10. + specified. The initial value for oldstd is 20, for newstd 10. The parameter may be changed to the value d by either config("display", d) or by display (d). This parameter does not change the stored value of a number. Where rounding is necessary to @@ -187,7 +187,7 @@ DESCRIPTION calculation of functions for which exact values are not possible or not desired. For most functions, the - remainder = exact value - calculated value + remainder = exact value - calculated value has absolute value less than epsilon, but, except when the sign of the remainder is controlled by an appropriate parameter, the @@ -209,36 +209,36 @@ DESCRIPTION The "mode" parameter is a string specifying the mode for printing of numbers by the unformatted print functions, and the default ("%d" specifier) for formatted print functions. The initial mode - is "real". The available modes are: + is "real". The available modes are: - config("mode") meaning equivalent - string base() call + config("mode") meaning equivalent + string base() call - "binary" base 2 fractions base(2) - "bin" + "binary" base 2 fractions base(2) + "bin" - "octal" base 8 fractions base(8) - "oct" + "octal" base 8 fractions base(8) + "oct" - "real" base 10 floating point base(10) - "float" - "default" + "real" base 10 floating point base(10) + "float" + "default" - "integer" base 10 integer base(-10) - "int" + "integer" base 10 integer base(-10) + "int" - "hexadecimal" base 16 fractions base(16) - "hex" + "hexadecimal" base 16 fractions base(16) + "hex" - "fraction" base 10 fractions base(1/3) - "frac" + "fraction" base 10 fractions base(1/3) + "frac" - "scientific" base 10 scientific notation base(1e20) - "sci" - "exp" + "scientific" base 10 scientific notation base(1e20) + "sci" + "exp" - "engineering" base 10 notation with exponent base(10e6) - "eng" multiple of 3 + "engineering" base 10 notation with exponent base(10e6) + "eng" multiple of 3 Where multiple strings are given, the first string listed is what config("mode") will return. @@ -248,7 +248,7 @@ DESCRIPTION well as the "base2" mode. The "mode2" value may be any of the "mode" values with the addition of: - "off" disable 2nd base output mode base2(0) + "off" disable 2nd base output mode base2(0) The base() builtin function sets and returns the "mode" value. The base2() builtin function sets and returns the "mode2" value. @@ -276,7 +276,7 @@ DESCRIPTION second algorithm begins to be used. The minimum value is 2, and the maximum value is very large. If 2 is used, then the recursive algorithm is used all the way down to single digits, which becomes - slow since the recursion overhead is high. If a number such as + slow since the recursion overhead is high. If a number such as 1000000 is used, then the recursive algorithm is almost never used, causing calculations for large numbers to slow down. @@ -340,9 +340,9 @@ DESCRIPTION The "redc2" specifies the sizes of numbers at which calc switches from its first to its second algorithm when using the REDC algorithm. The first algorithm performs a multiply and a modular reduction - together in one loop which runs in O(N^2). The second algorithm + together in one loop which runs in O(N^2). The second algorithm does the REDC calculation using three multiplies, and runs in - O(N^1.585). The argument for redc2 is the size of the modulus at + O(N^1.585). The argument for redc2 is the size of the modulus at which the second algorithm begins to be used. Units refer to internal calculation digits where each digit @@ -384,7 +384,7 @@ DESCRIPTION If config("tilde") is false, then config("tilde_space") has no effect. NOTE: Use of config("tilde_space", 1) can break printing and scanning - of complex values via "%c". + of complex values via "%c". The initial "tilde_space" value is 0 (off) @@ -396,10 +396,10 @@ DESCRIPTION printed both before and after '/' when printing a fraction. NOTE: Use of config("fraction_space", 1) can break printing and scanning - of fractional values via "%r". + of fractional values via "%r". NOTE: Use of config("fraction_space", 1) can break printing and scanning - of complex values via "%c". + of complex values via "%c". The initial "fraction_space" value is 0 (off). @@ -408,7 +408,7 @@ DESCRIPTION config("tab", boolean) config("tab") controls the printing of a tab before results - automatically displayed when working interactively. It does not + automatically displayed when working interactively. It does not affect the printing by the functions print, printf, etc. The initial "tab" value is 1. @@ -445,9 +445,9 @@ DESCRIPTION and for round to the nearest even "last decimal place". The effects of the 3 lowest bits of the parameter value are as follows: - Bit 0: Unconditional reversal (down to up, even to odd, etc.) - Bit 1: Reversal if the exact value is negative - Bit 2: Reversal if the divisor or epsilon is negative + Bit 0: Unconditional reversal (down to up, even to odd, etc.) + Bit 1: Reversal if the exact value is negative + Bit 2: Reversal if the divisor or epsilon is negative (Bit 2 is irrelevant for the functions round and bround since the equivalent epsilon (a power of 1/10 or 1/2) is always positive.) @@ -472,40 +472,40 @@ DESCRIPTION The C language method of modulus and integer division is: - config("quomod", 2) - config("quo", 2) - config("mod", 2) + config("quomod", 2) + config("quo", 2) + config("mod", 2) The config("triground") controls rounding for the following trigonometric and hyperbolic functions: - sin, cos, tan, cot, sec, csc - asin, acos, atan, acot, asec, acsc - versin, coversin, vercos, covercos - aversin, acoversin, avercos, acovercos - haversin, hacoversin, havercos, hacovercos - ahaversin, hacoversin, havercos, ahacovercos - exsec, aexsec, excsc, aexcsc - crd, acrd - cas, cis - sinh, cosh, tanh, coth, sech, csch - asinh, acosh, atanh, acoth, asech, acsch + sin, cos, tan, cot, sec, csc + asin, acos, atan, acot, asec, acsc + versin, coversin, vercos, covercos + aversin, acoversin, avercos, acovercos + haversin, hacoversin, havercos, hacovercos + ahaversin, hacoversin, havercos, ahacovercos + exsec, aexsec, excsc, aexcsc + crd, acrd + cas, cis + sinh, cosh, tanh, coth, sech, csch + asinh, acosh, atanh, acoth, asech, acsch In addition to taking a complex root (such as via the power function on a complex value), "triground" is used for: - exp, polar + exp, polar For the above mentioned functions, the rounding mode used to round the result to the nearest epsilon value is controlled by, and defaults to: - config("triground", 24) + config("triground", 24) As with other config options, the call returns the previous mode, without a 2nd argument, returns the current mode without changing it: - config("triground") + config("triground") =-= @@ -542,7 +542,7 @@ DESCRIPTION The default prompt when in interactive mode is "> ". One may change this prompt to a more cut-and-paste friendly prompt by: - config("prompt", "; ") + config("prompt", "; ") On windowing systems that support cut/paste of a line, one may cut/copy an input line and paste it directly into input. The @@ -555,7 +555,7 @@ DESCRIPTION When inside multi-line input, the more prompt is used. One may change it by: - config("more", ";; ") + config("more", ";; ") =-= @@ -572,7 +572,7 @@ DESCRIPTION config("blkverbose", boolean) The "blkverbose" determines if all lines, including duplicates - should be printed. If TRUE, then all lines are printed. If false, + should be printed. If TRUE, then all lines are printed. If false, duplicate lines are skipped and only a "*" is printed in a style similar to od. This config value has not meaning if "blkfmt" is "str". @@ -586,21 +586,21 @@ DESCRIPTION The "blkbase" determines the base in which octets of a block are printed. Possible values are: - "hexadecimal" Octets printed in 2 digit hex - "hex" - "default" + "hexadecimal" Octets printed in 2 digit hex + "hex" + "default" - "octal" Octets printed in 3 digit octal - "oct" + "octal" Octets printed in 3 digit octal + "oct" - "character" Octets printed as chars with non-printing - "char" chars as \123 or \n, \t, \r + "character" Octets printed as chars with non-printing + "char" chars as \123 or \n, \t, \r - "binary" Octets printed as 0 or 1 chars - "bin" + "binary" Octets printed as 0 or 1 chars + "bin" - "raw" Octets printed as is, i.e. raw binary - "none" + "raw" Octets printed as is, i.e. raw binary + "none" Where multiple strings are given, the first string listed is what config("blkbase") will return. @@ -613,21 +613,21 @@ DESCRIPTION The "blkfmt" determines for format of how block are printed: - "lines" print in lines of up to 79 chars + newline - "line" + "lines" print in lines of up to 79 chars + newline + "line" - "strings" print as one long string - "string" - "str" + "strings" print as one long string + "string" + "str" - "od_style" print in od-like format, with leading offset, - "odstyle" followed by octets in the given base - "od" + "od_style" print in od-like format, with leading offset, + "odstyle" followed by octets in the given base + "od" - "hd_style" print in hex dump format, with leading offset, - "hdstyle" followed by octets in the given base, followed - "hd" by chars or '.' if no-printable or blank - "default" + "hd_style" print in hex dump format, with leading offset, + "hdstyle" followed by octets in the given base, followed + "hd" by chars or '.' if no-printable or blank + "default" Where multiple strings are given, the first string listed is what config("blkfmt") will return. @@ -640,37 +640,37 @@ DESCRIPTION The "calc_debug" is intended for controlling internal calc routines that test its operation, or collect or display information that - might be useful for debug purposes. Much of the output from these + might be useful for debug purposes. Much of the output from these will make sense only to calc wizards. Zero value (the default for both oldstd and newstd) of config("resource_debug") corresponds to switching off all these routines. For nonzero value, particular bits currently have the following meanings: - n Meaning of bit n of config("calc_debug") + n Meaning of bit n of config("calc_debug") - 0 outputs shell commands prior to execution + 0 outputs shell commands prior to execution - 1 outputs currently active functions when a quit instruction - is executed + 1 outputs currently active functions when a quit instruction + is executed - 2 some details of hash states are included in the output - when these are printed + 2 some details of hash states are included in the output + when these are printed - 3 when a function constructs a block value, tests are - made that the result has the properties required for use of - that block, e.g. that the pointer to the start of the - block is not NULL, and that its "length" is not negative. - A failure will result in a runtime error. + 3 when a function constructs a block value, tests are + made that the result has the properties required for use of + that block, e.g. that the pointer to the start of the + block is not NULL, and that its "length" is not negative. + A failure will result in a runtime error. - 4 Report on changes to the state of stdin as well as changes - to internal variables that control the setting and restoring - of stdin. + 4 Report on changes to the state of stdin as well as changes + to internal variables that control the setting and restoring + of stdin. - 5 Report on changes to the run state of calc. + 5 Report on changes to the run state of calc. - 6 Report on rand() subtractive 100 shuffle generator issues. + 6 Report on rand() subtractive 100 shuffle generator issues. - 7 Report on custom function issues. + 7 Report on custom function issues. Bits >= 8 are reserved for future use and should not be used at this time. @@ -689,21 +689,21 @@ DESCRIPTION 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 - is displayed. + 0 When a function is defined, redefined or undefined at + interactive level, a message saying what has been done + is displayed. - 1 When a function is defined, redefined or undefined during - the reading of a file, a message saying what has been done - is displayed. + 1 When a function is defined, redefined or undefined during + 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 and argument summary information. + 2 Show func will display more information about a functions + arguments and argument summary information. - 3 During execution, allow calc standard resource files - to output additional debugging 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 @@ -715,7 +715,7 @@ DESCRIPTION The name config("lib_debug") is equivalent to config("resource_debug") and is included for backward compatibility. - By default, "resource_debug" is 3. The -d flag changes this default to 0. + By default, "resource_debug" is 3. The -d flag changes this default to 0. The initial value may be overridden by the -D command line option. =-= @@ -724,7 +724,7 @@ DESCRIPTION The "user_debug" is provided for use by users. Calc ignores this value other than to set it to 0 by default (for both "oldstd" and "newstd"). - No calc code or standard resource should change this value. Users + No calc code or standard resource should change this value. Users should feel free to use it in any way. In particular they may use particular bits for special purposes as with "calc_debug", or they may use it to indicate a debug level with larger values @@ -741,7 +741,7 @@ DESCRIPTION The "verbose_quit" controls the print of the message: - quit or abort executed + quit or abort executed when a non-interactive quit or abort without an argument is encountered. A quit of abort without an argument does not display a message when @@ -755,84 +755,84 @@ DESCRIPTION For calc that is using the calc binding (not GNU-readline) facility: - The "ctrl_d" controls the interactive meaning of ^D (Control D): + The "ctrl_d" controls the interactive meaning of ^D (Control D): - "virgin_eof" If ^D is the only character that has been typed - "virgineof" on a line, then calc will exit. Otherwise ^D - "virgin" will act according to the calc binding, which - "default" by default is a Emacs-style delete-char. + "virgin_eof" If ^D is the only character that has been typed + "virgineof" on a line, then calc will exit. Otherwise ^D + "virgin" will act according to the calc binding, which + "default" by default is a Emacs-style delete-char. - "never_eof" The ^D never exits calc and only acts according - "nevereof" calc binding, which by default is a Emacs-style - "never" delete-char. + "never_eof" The ^D never exits calc and only acts according + "nevereof" calc binding, which by default is a Emacs-style + "never" delete-char. - "empty_eof" The ^D always exits calc if typed on an empty line. - "emptyeof" This condition occurs when ^D either the first - "empty" character typed, or when all other characters on - the line have been removed (say by deleting them). + "empty_eof" The ^D always exits calc if typed on an empty line. + "emptyeof" This condition occurs when ^D either the first + "empty" character typed, or when all other characters on + the line have been removed (say by deleting them). - Where multiple strings are given, the first string listed is what - config("ctrl_d") will return. + Where multiple strings are given, the first string listed is what + config("ctrl_d") will return. - Note that config("ctrl_d") actually controls each and every character - that is bound to ``delete_char''. By default, ``delete_char'' is - Control D. Any character(s) bound to ``delete_char'' will cause calc - to exit (or not exit) as directed by config("ctrl_d"). + Note that config("ctrl_d") actually controls each and every character + that is bound to ``delete_char''. By default, ``delete_char'' is + Control D. Any character(s) bound to ``delete_char'' will cause calc + to exit (or not exit) as directed by config("ctrl_d"). - See the ``binding'' help for information on the default calc bindings. + See the ``binding'' help for information on the default calc bindings. - The default "ctrl_d", without GNU-readline is "virgin_eof". + The default "ctrl_d", without GNU-readline is "virgin_eof". For calc that was compiled with the GNU-readline facility: - The "ctrl_d" controls the interactive meaning of ^D (Control D): + The "ctrl_d" controls the interactive meaning of ^D (Control D): - "virgin_eof" Same as "empty_eof" - "virgineof" - "virgin" - "default" + "virgin_eof" Same as "empty_eof" + "virgineof" + "virgin" + "default" - "never_eof" The ^D never exits calc and only acts according - "nevereof" calc binding, which by default is a Emacs-style - "never" delete-char. + "never_eof" The ^D never exits calc and only acts according + "nevereof" calc binding, which by default is a Emacs-style + "never" delete-char. - "empty_eof" The ^D always exits calc if typed on an empty line. - "emptyeof" This condition occurs when ^D either the first - "empty" character typed, or when all other characters on + "empty_eof" The ^D always exits calc if typed on an empty line. + "emptyeof" This condition occurs when ^D either the first + "empty" character typed, or when all other characters on - Where multiple strings are given, the first string listed is what - config("ctrl_d") will return. + Where multiple strings are given, the first string listed is what + config("ctrl_d") will return. - The default "ctrl_d", with GNU-readline is effectively "empty_eof". + The default "ctrl_d", with GNU-readline is effectively "empty_eof". - Literally it is "virgin_eof", but since "virgin_eof" is the - same as "empty_eof", the default is effectively "empty_eof". + Literally it is "virgin_eof", but since "virgin_eof" is the + same as "empty_eof", the default is effectively "empty_eof". Emacs users may find the default behavior objectionable, particularly when using the GNU-readline facility. Such users may want to add the line: - config("ctrl_d", "never_eof"),; + config("ctrl_d", "never_eof"),; to their ~/.calcrc startup file to prevent ^D from causing calc to exit. =-= - config("program") <== NOTE: This is a read-only config value + config("program") <== NOTE: This is a read-only config value The full path to the calc program, or the calc shell script can be obtained by: - config("program") + config("program") This config parameter is read-only and cannot be set. =-= - config("basename") <== NOTE: This is a read-only config value + config("basename") <== NOTE: This is a read-only config value The calc program, or the calc shell script basename can be obtained by: - config("basename") + config("basename") The config("basename") is the config("program") without any leading path. If config("program") has a / in it, config("basename") is @@ -843,7 +843,7 @@ DESCRIPTION =-= - config("windows") <== NOTE: This is a read-only config value + config("windows") <== NOTE: This is a read-only config value Returns TRUE if you are running on a MS windows system, false if you are running on an operating system that does not hate you. @@ -852,7 +852,7 @@ DESCRIPTION =-= - config("cygwin") <== NOTE: This is a read-only config value + config("cygwin") <== NOTE: This is a read-only config value Returns TRUE if you calc was compiled with cygwin, false otherwise. @@ -860,7 +860,7 @@ DESCRIPTION =-= - config("compile_custom") <== NOTE: This is a read-only config value + config("compile_custom") <== NOTE: This is a read-only config value Returns TRUE if you calc was compiled with -DCUSTOM. By default, the calc Makefile uses ALLOW_CUSTOM= -DCUSTOM so by default @@ -877,7 +877,7 @@ DESCRIPTION =-= - config("allow_custom") <== NOTE: This is a read-only config value + config("allow_custom") <== NOTE: This is a read-only config value Returns TRUE if you custom functions are enabled. To allow the use of custom functions, calc must be compiled with -DCUSTOM (which it @@ -894,17 +894,17 @@ DESCRIPTION =-= - config("version") <== NOTE: This is a read-only config value + config("version") <== NOTE: This is a read-only config value The version string of the calc program can be obtained by: - config("version") + config("version") This config parameter is read-only and cannot be set. =-= - config("baseb") <== NOTE: This is a read-only config value + config("baseb") <== NOTE: This is a read-only config value Returns the number of bits in the fundamental base in which internal calculations are performed. For example, a value of @@ -933,16 +933,16 @@ DESCRIPTION when a variable name collides with an exist name of a higher scope. Examples of collisions are when: - * both local and static variables have the same name - * both local and global variables have the same name - * both function parameter and local variables have the same name - * both function parameter and global variables have the same name + * both local and static variables have the same name + * both local and global variables have the same name + * both function parameter and local variables have the same name + * both function parameter and global variables have the same name The initial "redecl_warn" value is 1. =-= - config("hz") <== NOTE: This is a read-only config value + config("hz") <== NOTE: This is a read-only config value Returns the rate at which the operating system advances the clock on POSIX based systems. Returns 0 on non-POSIX based systems. @@ -955,70 +955,70 @@ EXAMPLE ; config("tilde", off),; ; config("calc_debug", 15),; ; config("all") == current_cfg - 0 + 0 ; config("all", current_cfg),; ; config("all") == current_cfg - 1 + 1 ; config("version") - "2.12.0" + "2.12.0" ; config("all") - mode "real" - mode2 "off" - display 20 - epsilon 0.00000000000000000001 - trace 0 - maxprint 16 - mul2 20 - sq2 20 - pow2 40 - redc2 50 - tilde 1 - tilde_space 0 - tab 1 - quomod 0 - quo 2 - mod 0 - sqrt 24 - appr 24 - cfappr 0 - cfsim 8 - outround 24 - round 24 - leadzero 1 - fullzero 0 - maxscan 20 - prompt "; " - more ";; " - blkmaxprint 256 - blkverbose 0 - blkbase "hexadecimal" - blkfmt "hd_style" - resource_debug 3 - lib_debug 3 - calc_debug 0 - user_debug 0 - verbose_quit 0 - ctrl_d "virgin_eof" - program "calc" - basename "calc" - windows 0 - cygwin 0 - compile_custom 1 - allow_custom 0 - version "2.12.0" - baseb 32 - redecl_warn 1 - dupvar_warn 1 - hz 100 - fraction_space 0 + mode "real" + mode2 "off" + display 20 + epsilon 0.00000000000000000001 + trace 0 + maxprint 16 + mul2 20 + sq2 20 + pow2 40 + redc2 50 + tilde 1 + tilde_space 0 + tab 1 + quomod 0 + quo 2 + mod 0 + sqrt 24 + appr 24 + cfappr 0 + cfsim 8 + outround 24 + round 24 + leadzero 1 + fullzero 0 + maxscan 20 + prompt "; " + more ";; " + blkmaxprint 256 + blkverbose 0 + blkbase "hexadecimal" + blkfmt "hd_style" + resource_debug 3 + lib_debug 3 + calc_debug 0 + user_debug 0 + verbose_quit 0 + ctrl_d "virgin_eof" + program "calc" + basename "calc" + windows 0 + cygwin 0 + compile_custom 1 + allow_custom 0 + version "2.12.0" + baseb 32 + redecl_warn 1 + dupvar_warn 1 + hz 100 + fraction_space 0 ; display() - 20 + 20 ; config("display", 50),; ; display() - 50 + 50 ; /* * NOTE: When displaying many digits after the decimal point @@ -1032,37 +1032,37 @@ EXAMPLE ; ## NOTE: display has too few digits and epsilon is not small enough - ; config("display", 12),; /* or display(12),; */ + ; config("display", 12),; /* or display(12),; */ ; printf("%f\n", pi(1e-10)); 3.1415926536 - ; config("epsilon", 1e-10),; /* or epsilon(1e-10),; */ + ; config("epsilon", 1e-10),; /* or epsilon(1e-10),; */ ; printf("%f\n", pi()); 3.1415926536 ; ## NOTE: display has too few digits yet epsilon is small enough - ; config("display", 12),; /* or display(12),; */ + ; config("display", 12),; /* or display(12),; */ ; printf("%f\n", pi(1e-72)); ~3.141592653590 - ; config("epsilon", 1e-72),; /* or epsilon(1e-72),; */ + ; config("epsilon", 1e-72),; /* or epsilon(1e-72),; */ ; printf("%f\n", pi()); ~3.141592653590 ; ## NOTE: display has enough digits but epsilon is not small enough - ; config("display", 72),; /* or display(72),; */ + ; config("display", 72),; /* or display(72),; */ ; printf("%f\n", pi(1e-10)); 3.1415926536 - ; config("epsilon", 1e-10),; /* or epsilon(1e-10),; */ + ; config("epsilon", 1e-10),; /* or epsilon(1e-10),; */ ; printf("%f\n", pi()); 3.1415926536 ; ## NOTE: display has enough digits and epsilon is small enough - ; config("display", 72),; /* or display(72),; */ + ; config("display", 72),; /* or display(72),; */ ; printf("%f\n", pi(1e-72)); 3.141592653589793238462643383279502884197169399375105820974944592307816406 - ; config("epsilon", 1e-72),; /* or epsilon(1e-72),; */ + ; config("epsilon", 1e-72),; /* or epsilon(1e-72),; */ ; printf("%f\n", pi()); 3.141592653589793238462643383279502884197169399375105820974944592307816406 @@ -1083,7 +1083,7 @@ SEE ALSO ## ## 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 +## 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 @@ -1091,8 +1091,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:17 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:17 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/conj b/help/conj index d0e769f..80090a8 100644 --- a/help/conj +++ b/help/conj @@ -9,9 +9,9 @@ TYPES For non-object x: - x real, complex, or matrix + x real, complex, or matrix - return real, complex, or matrix + return real, complex, or matrix DESCRIPTION @@ -48,7 +48,7 @@ SEE ALSO ## ## 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 +## 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 @@ -56,8 +56,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/03 10:40:01 -## File existed as early as: 1995 +## Under source code control: 1995/10/03 10:40:01 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/cos b/help/cos index f579e33..b957f84 100644 --- a/help/cos +++ b/help/cos @@ -5,10 +5,10 @@ SYNOPSIS cos(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the trigonometric cosine of x to a multiple of eps with error less in @@ -50,14 +50,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 1999,2021,2023 Landon Curt Noll ## @@ -67,7 +67,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -75,8 +75,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 01:40:27 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 01:40:27 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/cosh b/help/cosh index 72c52ba..2612703 100644 --- a/help/cosh +++ b/help/cosh @@ -5,10 +5,10 @@ SYNOPSIS cosh(x [,eps]) TYPES - x real - eps 0 < real < 1, defaults to epsilon() + x real + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Calculate the cosh of x to the nearest or next to nearest multiple of @@ -39,7 +39,7 @@ SEE ALSO ## ## 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 +## 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 @@ -47,8 +47,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 01:40:28 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 01:40:28 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/cot b/help/cot index df75cc4..64d5325 100644 --- a/help/cot +++ b/help/cot @@ -5,10 +5,10 @@ SYNOPSIS cot(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Calculate the trigonometric cotangent of x to a multiple of eps, with error less @@ -16,7 +16,7 @@ DESCRIPTION This function is equivalent to: - cot(x) = cos(x) / sin(x) + cot(x) = cos(x) / sin(x) EXAMPLE ; print cot(1/2), cot(5/7), cot(42/7) @@ -56,14 +56,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 1999,2021,2023 Landon Curt Noll ## @@ -73,7 +73,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -81,8 +81,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/13 03:49:00 -## File existed as early as: 1995 +## Under source code control: 1995/11/13 03:49:00 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/coth b/help/coth index 37a618e..986f0bd 100644 --- a/help/coth +++ b/help/coth @@ -5,10 +5,10 @@ SYNOPSIS coth(x [,eps]) TYPES - x nonzero real - eps 0 < real < 1, defaults to epsilon() + x nonzero real + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Calculate the coth of x to a multiple of eps with error less in @@ -39,7 +39,7 @@ SEE ALSO ## ## 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 +## 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 @@ -47,8 +47,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/13 03:49:00 -## File existed as early as: 1995 +## Under source code control: 1995/11/13 03:49:00 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/count b/help/count index 1592b53..38806dc 100644 --- a/help/count +++ b/help/count @@ -5,10 +5,10 @@ SYNOPSIS count(x, y) TYPES - x list or matrix - y string + x list or matrix + y string - return integer + return integer DESCRIPTION For count(x, y), y is to be the name of a user-defined function; @@ -19,7 +19,7 @@ EXAMPLE ; define f(a) = (a < 5) ; A = list(1,2,7,6,4,8) ; count(A, "f") - 3 + 3 LIMITS none @@ -38,7 +38,7 @@ SEE ALSO ## ## 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 +## 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 @@ -46,8 +46,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/10 02:09:31 -## File existed as early as: 1995 +## Under source code control: 1995/07/10 02:09:31 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/covercos b/help/covercos index 7bbd9a9..15611d5 100644 --- a/help/covercos +++ b/help/covercos @@ -5,10 +5,10 @@ SYNOPSIS covercos(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the coversed trigonometric cosine of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called cvc, or covercosine, is equivalent to: - covercos(x) = 1 + sin(x) + covercos(x) = 1 + sin(x) EXAMPLE ; print covercos(1/2), covercos(5/7), covercos(42/7) @@ -54,14 +54,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -71,7 +71,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -79,8 +79,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/05 23:31:08 -## File existed as early as: 2023 +## Under source code control: 2023/09/05 23:31:08 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/coversin b/help/coversin index bb79769..405766b 100644 --- a/help/coversin +++ b/help/coversin @@ -5,10 +5,10 @@ SYNOPSIS coversin(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the coversed trigonometric sine of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called covers, or cvs, is equivalent to: - coversin(x) = 1 - sin(x) + coversin(x) = 1 - sin(x) EXAMPLE ; print coversin(1/2), coversin(5/7), coversin(42/7) @@ -54,14 +54,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -71,7 +71,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -79,8 +79,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/08/31 23:07:08 -## File existed as early as: 2023 +## Under source code control: 2023/08/31 23:07:08 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/cp b/help/cp index eb42ebe..8ad090a 100644 --- a/help/cp +++ b/help/cp @@ -5,16 +5,16 @@ SYNOPSIS cp(x, y) TYPES - x, y 1-dimensional matrices with 3 elements + x, y 1-dimensional matrices with 3 elements - return 1-dimensional matrix with 3 elements + return 1-dimensional matrix with 3 elements DESCRIPTION Calculate the product of two 3 1-dimensional matrices. If x has elements (x0, x1, x2), and y has elements (y0, y1, y2), cp(x,y) returns the matrix of type [0:2] with elements: - {x1 * y2 - x2 * y1, x3 * y1 - x1 * y3, x1 * y2 - x2 * y1} + {x1 * y2 - x2 * y1, x3 * y1 - x1 * y3, x1 * y2 - x2 * y1} EXAMPLE ; mat x[3] = {2,3,4} @@ -44,7 +44,7 @@ SEE ALSO ## ## 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 +## 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 @@ -52,8 +52,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## -## Under source code control: 1995/10/05 04:52:26 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:26 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/crd b/help/crd index 3e4ae5f..91d7055 100644 --- a/help/crd +++ b/help/crd @@ -5,10 +5,10 @@ SYNOPSIS crd(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate length of unit circle chord with angle x to a multiple of eps with error less in @@ -19,7 +19,7 @@ DESCRIPTION This function is sometimes called chord, is equivalent to: - crd(x) = 2 * sin(x / 2) + crd(x) = 2 * sin(x / 2) EXAMPLE ; print crd(1/2), crd(5/7), crd(42/7) @@ -57,14 +57,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -74,7 +74,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -82,8 +82,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/10/02 16:49:42 -## File existed as early as: 2023 +## Under source code control: 2023/10/02 16:49:42 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/credit b/help/credit index 1235fcb..7008e74 100644 --- a/help/credit +++ b/help/credit @@ -15,7 +15,7 @@ Credits hist.c which is used to do the command line editing. Thanks to Ernest W. Bowen for supplying many improvements in - accuracy and generality for some numeric functions. Much of + accuracy and generality for some numeric functions. Much of this was in terms of actual code which I gratefully accepted. Ernest also supplied the original text for many of the help files. @@ -26,17 +26,17 @@ Credits Most of this source and binary has one of the following copyrights: - Copyright (C) year David I. Bell - Copyright (C) year David I. Bell and Landon Curt Noll - Copyright (C) year David I. Bell and Ernest Bowen - Copyright (C) year David I. Bell, Landon Curt Noll and Ernest Bowen - Copyright (C) year Landon Curt Noll - Copyright (C) year Ernest Bowen and Landon Curt Noll - Copyright (C) year Ernest Bowen - Copyright (C) year Petteri Kettunen and Landon Curt Noll - Copyright (C) year Christoph Zurnieden - Copyright (C) year Landon Curt Noll and Thomas Jones-Low - Copyright (C) year Klaus Alexander Seistrup and Landon Curt Noll + Copyright (C) year David I. Bell + Copyright (C) year David I. Bell and Landon Curt Noll + Copyright (C) year David I. Bell and Ernest Bowen + Copyright (C) year David I. Bell, Landon Curt Noll and Ernest Bowen + Copyright (C) year Landon Curt Noll + Copyright (C) year Ernest Bowen and Landon Curt Noll + Copyright (C) year Ernest Bowen + Copyright (C) year Petteri Kettunen and Landon Curt Noll + Copyright (C) year Christoph Zurnieden + Copyright (C) year Landon Curt Noll and Thomas Jones-Low + Copyright (C) year Klaus Alexander Seistrup and Landon Curt Noll A few files in calc are covered under "The Unlicense". For more information on this license, see: @@ -50,8 +50,8 @@ Copying / Calc GNU Lesser General Public License Lesser General Public License. You are welcome to change it and/or distribute copies of it under certain conditions. The calc commands: - help copying - help copying-lgpl + help copying + help copying-lgpl should display the contents of the COPYING and COPYING-LGPL files. Those files contain information about the calc's GNU Lesser General @@ -62,17 +62,17 @@ Copying / Calc GNU Lesser General Public License Lesser General Public License. If you do not have these files, write to: - Free Software Foundation, Inc. - 51 Franklin Street - Fifth Floor - Boston, MA 02110-1301 - USA + Free Software Foundation, Inc. + 51 Franklin Street + Fifth Floor + Boston, MA 02110-1301 + USA See also: - help copyright - help copying - help copying-lgpl + help copyright + help copying + help copying-lgpl ## Copyright (C) 1999,2023 Landon Curt Noll ## @@ -82,7 +82,7 @@ See also: ## ## 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 +## 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 @@ -90,8 +90,8 @@ See also: ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/23 05:47:24 -## File existed as early as: 1991 +## Under source code control: 1991/07/23 05:47:24 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/csc b/help/csc index 1b8a7c4..478fa1b 100644 --- a/help/csc +++ b/help/csc @@ -5,10 +5,10 @@ SYNOPSIS csc(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Calculate the trigonometric cosecant of x to a multiple of eps, with error less @@ -16,7 +16,7 @@ DESCRIPTION This function is equivalent to: - csc(x) = 1 / sin(x) + csc(x) = 1 / sin(x) EXAMPLE ; print csc(1/2), csc(5/7), csc(42/7) @@ -56,14 +56,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 1999,2023 Landon Curt Noll ## @@ -73,7 +73,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -81,8 +81,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/13 03:49:00 -## File existed as early as: 1995 +## Under source code control: 1995/11/13 03:49:00 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/csch b/help/csch index 8013ccb..d5a6168 100644 --- a/help/csch +++ b/help/csch @@ -5,10 +5,10 @@ SYNOPSIS csch(x [,eps]) TYPES - x nonzero real - eps 0 < real < 1, defaults to epsilon() + x nonzero real + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Calculate the csch of x to a multiple of epsilon, with error less in @@ -39,7 +39,7 @@ SEE ALSO ## ## 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 +## 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 @@ -47,8 +47,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/13 03:49:00 -## File existed as early as: 1995 +## Under source code control: 1995/11/13 03:49:00 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ctime b/help/ctime index 492a78e..303cfc6 100644 --- a/help/ctime +++ b/help/ctime @@ -5,13 +5,13 @@ SYNOPSIS ctime() TYPES - return string + return string DESCRIPTION The ctime() builtin returns the string formed by the characters returned by the C library function, ctime(): E.g. - "Mon Oct 28 00:47:00 1996\n" + "Mon Oct 28 00:47:00 1996\n" EXAMPLE ; ## NOTE: Your output will likely vary: @@ -37,7 +37,7 @@ SEE ALSO ## ## 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 +## 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 @@ -45,8 +45,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:05:18 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:05:18 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/custom b/help/custom index 27fef12..eede455 100644 --- a/help/custom +++ b/help/custom @@ -5,10 +5,10 @@ SYNOPSIS custom([custname [, arg ...]]) TYPES - custname string - arg any + custname string + arg any - return any + return any DESCRIPTION This function will invoke the custom function interface. Custom @@ -19,16 +19,16 @@ DESCRIPTION In order to use the custom interface, two things must happen: - 1) Calc must be built to allow custom functions. By default, - the master Makefile is shipped with ALLOW_CUSTOM= -DCUSTOM - which causes custom functions to be compiled in. + 1) Calc must be built to allow custom functions. By default, + the master Makefile is shipped with ALLOW_CUSTOM= -DCUSTOM + which causes custom functions to be compiled in. - 2) Calc must be invoked with an argument of -C as in: + 2) Calc must be invoked with an argument of -C as in: - calc -C + calc -C In other words, explicit action must be taken in order to - enable the use of custom functions. By default (no -C arg) + enable the use of custom functions. By default (no -C arg) custom functions are compiled in but disabled so that only portable calc scripts may be used. @@ -36,7 +36,7 @@ DESCRIPTION multi-precision calculations in a C-like environment. You should consider implementing algorithms in the calc language as a first choice. Sometimes an algorithm requires use of special hardware, a - non-portable OS or pre-compiled C library. In these cases a custom + non-portable OS or pre-compiled C library. In these cases a custom interface may be needed. The custom function interface is intended to make is easy for @@ -48,16 +48,16 @@ DESCRIPTION To add a new custom function requires access to calc source. For information on how to add a new custom function, try: - help new_custom + help new_custom To serve as examples, calc is shipped with a few custom functions. If calc if invoked with -C, then either of the following will display information about the custom functions that are available: - show custom + show custom or: - custom() + custom() A few resource files that uses these function are also provided to serve as usage examples. @@ -65,20 +65,20 @@ DESCRIPTION We welcome submissions for new custom functions. For information on how to submit new custom functions for general distribution, see: - help contrib + help contrib EXAMPLE If calc compiled with ALLOW_CUSTOM="-UCUSTOM", the custom system is disabled, even when -C is used on the command line: ; print custom("sysinfo", "baseb") - Calc was built with custom functions disabled + Calc was built with custom functions disabled Error E_NO_C_ARG If calc compiled with ALLOW_CUSTOM= -DCUSTOM and is invoked without -C: ; print custom("sysinfo", "baseb") - Calc must be run with a -C argument to use custom function + Calc must be run with a -C argument to use custom function Error E_NO_C_ARG If calc compiled with ALLOW_CUSTOM= -DCUSTOM and is invoked with -C: @@ -103,7 +103,7 @@ SEE ALSO ## ## 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 +## 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 @@ -111,8 +111,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/03/09 16:33:22 -## File existed as early as: 1997 +## Under source code control: 1997/03/09 16:33:22 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/d2dm b/help/d2dm index 10cd73f..6e4013f 100644 --- a/help/d2dm +++ b/help/d2dm @@ -5,12 +5,12 @@ SYNOPSIS d2dm(degs, d, m [,rnd]) TYPES - degs real - d null-or-real-valued lvalue with assign-to permission - m null-or-real-valued lvalue with assign-to permission - rnd nonnegative integer, defaults to config("mod") + degs real + d null-or-real-valued lvalue with assign-to permission + m null-or-real-valued lvalue with assign-to permission + rnd nonnegative integer, defaults to config("mod") - return mod(degs, 360, rnd) + return mod(degs, 360, rnd) DESCRIPTION Convert degs degrees into d degrees, and m minutes. @@ -18,7 +18,7 @@ DESCRIPTION The return value is a normalized number of degrees, and is equivalent to the following: - return_value = mod(degs, 360, rnd); + return_value = mod(degs, 360, rnd); The argument rnd, if not given, defaults to config("mod"). For more information on the effects of rnd, see "help mod". @@ -31,7 +31,7 @@ DESCRIPTION The value d will be set as if the following were used: - d = int(return_value); + d = int(return_value); For some rounding modes, d will be an integer in the interval [0, 360). For other rounding modes, d will be an integer in the interval (-360, 0]. @@ -41,9 +41,9 @@ DESCRIPTION The value m will be set as if the following were used: - tmp = return_value - d; - m = tmp * 60; - free(tmp); + tmp = return_value - d; + m = tmp * 60; + free(tmp); For some rounding modes, m will be a real value in the interval [0, 60). For other rounding modes, m will be a real value in the interval (-60, 0]. @@ -52,7 +52,7 @@ DESCRIPTION The following shows relationship between the return value and the resulting d, and m values: - return_value == d + m/60; + return_value == d + m/60; EXAMPLE ; ## if args are undefined, pre-declare them or assign them as args @@ -100,7 +100,7 @@ SEE ALSO ## ## 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 +## 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 @@ -108,8 +108,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/25 17:24:51 -## File existed as early as: 2021 +## Under source code control: 2021/09/25 17:24:51 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/d2dms b/help/d2dms index d6b3cc8..bdaa2c2 100644 --- a/help/d2dms +++ b/help/d2dms @@ -5,13 +5,13 @@ SYNOPSIS d2dms(degs, d, m, s [,rnd]) TYPES - degs real - d null-or-real-valued lvalue with assign-to permission - m null-or-real-valued lvalue with assign-to permission - s null-or-real-valued lvalue with assign-to permission - rnd nonnegative integer, defaults to config("mod") + degs real + d null-or-real-valued lvalue with assign-to permission + m null-or-real-valued lvalue with assign-to permission + s null-or-real-valued lvalue with assign-to permission + rnd nonnegative integer, defaults to config("mod") - return mod(degs, 360, rnd) + return mod(degs, 360, rnd) DESCRIPTION Convert degs degrees into d degrees, m minutes, and s seconds. @@ -19,7 +19,7 @@ DESCRIPTION The return value is a normalized number of degrees, and is equivalent to the following: - return_value = mod(degs, 360, rnd); + return_value = mod(degs, 360, rnd); The argument rnd, if not given, defaults to config("mod"). For more information on the effects of rnd, see "help mod". @@ -32,7 +32,7 @@ DESCRIPTION The value d will be set as if the following were used: - d = int(return_value); + d = int(return_value); For some rounding modes, d will be an integer in the interval [0, 360). For other rounding modes, d will be an integer in the interval (-360, 0]. @@ -42,10 +42,10 @@ DESCRIPTION The value m will be set as if the following were used: - tmp = return_value - d; - tmp_m = tmp * 60; - free(tmp); - m = int(tmp_m); + tmp = return_value - d; + tmp_m = tmp * 60; + free(tmp); + m = int(tmp_m); For some rounding modes, m will be an integer in the interval [0, 60). For other rounding modes, m will be an integer in the interval (-60, 0]. @@ -55,10 +55,10 @@ DESCRIPTION The value s will be set as if the following were used: - tmp = tmp_m - m; - free(tmp_m); - s = tmp * 60; - free(tmp); + tmp = tmp_m - m; + free(tmp_m); + s = tmp * 60; + free(tmp); For some rounding modes, s will be a real value in the interval [0, 60). For other rounding modes, s will be a real value in the interval (-60, 0]. @@ -67,7 +67,7 @@ DESCRIPTION The following shows relationship between the return value and the resulting d, m, and s values: - return_value == d + m/60 + s/3600; + return_value == d + m/60 + s/3600; EXAMPLE ; ## if args are undefined, pre-declare them or assign them as args @@ -115,7 +115,7 @@ SEE ALSO ## ## 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 +## 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 @@ -123,8 +123,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/25 17:24:51 -## File existed as early as: 2021 +## Under source code control: 2021/09/25 17:24:51 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/d2g b/help/d2g index 7eae474..37fcb1a 100644 --- a/help/d2g +++ b/help/d2g @@ -5,10 +5,10 @@ SYNOPSIS d2g(x [,eps]) TYPES - x number (real or complex) - eps eps value is ignored + x number (real or complex) + eps eps value is ignored - return number + return number DESCRIPTION Given x degrees, return the equivalent number of gradians. @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/07 12:04:28 -## File existed as early as: 2021 +## Under source code control: 2021/09/07 12:04:28 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/d2r b/help/d2r index e1f343a..a022f7d 100644 --- a/help/d2r +++ b/help/d2r @@ -5,10 +5,10 @@ SYNOPSIS d2r(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Given x degrees, return the equivalent number of radians. @@ -44,7 +44,7 @@ SEE ALSO ## ## 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 +## 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 @@ -52,8 +52,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/07 12:04:28 -## File existed as early as: 2021 +## Under source code control: 2021/09/07 12:04:28 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/define b/help/define index 794297f..f8784fc 100644 --- a/help/define +++ b/help/define @@ -6,11 +6,11 @@ SYNTAX define fname([param_1 [= default_1], ...]) { [statement_1 ... ] } TYPES - fname identifier, not a builtin function name - param_1, ... identifiers, no two the same - default_1, ... expressions - expr expression - statement_1, ... statements + fname identifier, not a builtin function name + param_1, ... identifiers, no two the same + default_1, ... expressions + expr expression + statement_1, ... statements DESCRIPTION The intention of a function definition is that the identifier fname @@ -30,17 +30,17 @@ DESCRIPTION For example, suppose a function f and a global variable A have been defined by: - ; define f(x) = (x = 3); - ; global mat A[3]; + ; define f(x) = (x = 3); + ; global mat A[3]; If g() is a function that evaluates to 2: - ; f(A[g()]); + ; f(A[g()]); assigns the value of A[2] to the parameter x and then assigns the value 3 to x: - ; f(`A[g()]); + ; f(`A[g()]); has essentially the effect of assigning A[2] as an lvalue to x and then assigning the value 3 to A[2]. (Very old versions of calc @@ -79,7 +79,7 @@ DESCRIPTION If the expr is omitted from an expression definition, as in: - ; define h() = ; + ; define h() = ; any call to the function will evaluate the arguments and return the null value. @@ -105,11 +105,11 @@ DESCRIPTION After fname has been defined, the definition may be removed by the command: - ; undefine fname + ; undefine fname The definitions of all user-defined functions may be removed by: - ; undefine * + ; undefine * If bit 0 of config("resource_debug") is set and the define command is at interactive level, a message saying that fname has been defined @@ -120,8 +120,8 @@ DESCRIPTION The identifiers used for the parameters in a function definition do not form part of the completed definition. For example, - ; define f(a,b) = a + b; - ; define g(alpha, beta) = alpha + beta; + ; define f(a,b) = a + b; + ; define g(alpha, beta) = alpha + beta; result in identical code for the functions f, g. @@ -129,22 +129,22 @@ DESCRIPTION function are displayed on completion of its definition, parameters being specified by names used in the definition. For example: - ; config("trace", 8), - ; define f(a,b) = a + b - 0: PARAMADDR a - 2: PARAMADDR b - 4: ADD - 5: RETURN - f(a,b) defined + ; config("trace", 8), + ; define f(a,b) = a + b + 0: PARAMADDR a + 2: PARAMADDR b + 4: ADD + 5: RETURN + f(a,b) defined The opcodes may also be displayed later using the show opcodes command; parameters will be specified by indices instead of by names. For example: - ; show opco f - 0: PARAMADDR 0 - 2: PARAMADDR 1 - 4: ADD - 5: RETURN + ; show opco f + 0: PARAMADDR 0 + 2: PARAMADDR 1 + 4: ADD + 5: RETURN When a function is defined by the statement mode, the opcodes normally include DEBUG opcodes which specify statement boundaries at which @@ -169,17 +169,17 @@ EXAMPLE ; define f(a,b) = 2*a + b; ; define g(alpha, beta) ;; { - ;; local a, pi2; + ;; local a, pi2; ;; - ;; pi2 = 2 * pi(); - ;; a = sin(alpha % pi2); - ;; if (a > 0.0) { - ;; return a*beta; - ;; } - ;; if (beta > 0.0) { - ;; a *= cos(-beta % pi2); - ;; } - ;; return a; + ;; pi2 = 2 * pi(); + ;; a = sin(alpha % pi2); + ;; if (a > 0.0) { + ;; return a*beta; + ;; } + ;; if (beta > 0.0) { + ;; a *= cos(-beta % pi2); + ;; } + ;; return a; ;; } LIMITS @@ -192,7 +192,7 @@ SEE ALSO param, variable, undefine, show ## Copyright (C) 2000-2006,2021 David I. Bell, Landon Curt Noll -## and Ernest Bowen +## and Ernest Bowen ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License @@ -200,7 +200,7 @@ SEE ALSO ## ## 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 +## 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 @@ -209,8 +209,8 @@ SEE ALSO ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## -## Under source code control: 1991/07/21 04:37:18 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:18 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/delete b/help/delete index 5467f64..5d9c34e 100644 --- a/help/delete +++ b/help/delete @@ -5,10 +5,10 @@ SYNOPSIS delete(lst, index) TYPES - lst list - index nonnegative integer less than the size of the list + lst list + index nonnegative integer less than the size of the list - return type of the deleted element + return type of the deleted element DESCRIPTION Deletes element at the specified index from list lst, and returns @@ -24,7 +24,7 @@ EXAMPLE [[3]] = 5 ; delete(lst, 2) - 4 + 4 ; print lst list (3 elements, 3 nonzero): @@ -50,7 +50,7 @@ SEE ALSO ## ## 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 +## 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 @@ -58,8 +58,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 03:13:18 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 03:13:18 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/den b/help/den index c51e578..c24cf54 100644 --- a/help/den +++ b/help/den @@ -5,23 +5,23 @@ SYNOPSIS den(x) TYPES - x real + x real - return integer + return integer DESCRIPTION For real x, den(x) returns the denominator of x when x is expressed - in lowest terms with positive denominator. In calc, + in lowest terms with positive denominator. In calc, real values are actually rational values. Each calc real value can be uniquely expressed as: - n / d + n / d where: - n and d are integers - gcd(n,d) == 1 - d > 0 + n and d are integers + gcd(n,d) == 1 + d > 0 The denominator for this n/d is d. @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:26 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:26 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/dereference b/help/dereference index 6a41ab4..9c96bcf 100644 --- a/help/dereference +++ b/help/dereference @@ -5,9 +5,9 @@ SYNOPSIS * X TYPES - X address or lvalue + X address or lvalue - return any + return any DESCRIPTION When used as a binary operator, '*' performs multiplication. When @@ -33,17 +33,17 @@ DESCRIPTION structure rather than the structure identified by X. For example, suppose B has been created by - ; mat B[3] = {1,2,3} + ; mat B[3] = {1,2,3} then - ; A = *B = {4,5,6} + ; A = *B = {4,5,6} will assign the values 4,5,6 to the elements of a copy of B, which will then become the value of A, so that the values of A and B will be different. On the other hand, - ; A = B = {4,5,6} + ; A = B = {4,5,6} will result in A and B having the same value. @@ -52,9 +52,9 @@ DESCRIPTION The * operator may be iterated with suitable sequences of pointer-valued lvalues. For example, after - ; global a, b, c; - ; b = &a; - ; c = &b; + ; global a, b, c; + ; b = &a; + ; c = &b; **c returns the lvalue a; ***c returns the value of a. @@ -90,7 +90,7 @@ SEE ALSO ## ## 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 +## 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 @@ -98,8 +98,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/09/06 20:03:34 -## File existed as early as: 1997 +## Under source code control: 1997/09/06 20:03:34 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/det b/help/det index f1e0e85..97176e5 100644 --- a/help/det +++ b/help/det @@ -5,14 +5,14 @@ SYNOPSIS det(m) TYPES - m square matrix with elements of suitable type + m square matrix with elements of suitable type - return zero or value of type determined by types of elements + return zero or value of type determined by types of elements DESCRIPTION The matrix m has to be square, i.e. of dimension 2 with: - matmax(m,1) - matmin(m,1) == matmax(m,2) - matmin(m,2). + matmax(m,1) - matmin(m,1) == matmax(m,2) - matmin(m,2). If the elements of m are numbers (real or complex), det(m) returns the value of the determinant of m. @@ -26,15 +26,15 @@ DESCRIPTION If m is a 2 x 2 matrix with elements a, b, c, d, where a tests as nonzero, det(m) is evaluated by - det(m) = (a * d) - (c * b). + det(m) = (a * d) - (c * b). If a tests as zero, det(m) = - ((c * b) - (a * d)) is used. If m is 3 * 3 with elements a, b, c, d, e, f, g, h, i, where a and a * e - d * b test as nonzero, det(m) is evaluated by - det(m) = ((a * e - d * b) * (a * i - g * c) - - (a * h - g * b) * (a * f - d * c))/a. + det(m) = ((a * e - d * b) * (a * i - g * c) + - (a * h - g * b) * (a * f - d * c))/a. EXAMPLE ; mat A[3,3] = {2, 3, 5, 7, 11, 13, 17, 19, 23} @@ -83,7 +83,7 @@ SEE ALSO ## ## 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 +## 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 @@ -91,8 +91,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/28 11:17:47 -## File existed as early as: 1995 +## Under source code control: 1995/11/28 11:17:47 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/digit b/help/digit index 473ff7b..f8719d7 100644 --- a/help/digit +++ b/help/digit @@ -5,11 +5,11 @@ SYNOPSIS digit(x, n [, b]) TYPES - x real - n integer - b integer >= 2, default = 10 + x real + n integer + b integer >= 2, default = 10 - return integer + return integer DESCRIPTION @@ -28,11 +28,11 @@ DESCRIPTION left of the "decimal" point; the digit d_n at position n contributes additively d_n * b^n to the value of x. For example, - ; d_2 d_1 d_0 . d_-1 d_-2 + ; d_2 d_1 d_0 . d_-1 d_-2 represents the number - ; d_2 * b^2 + d_1 * b + d0 + d_-1 * b^-1 + d_-2 * b^-2 + ; d_2 * b^2 + d_1 * b + d0 + d_-1 * b^-1 + d_-2 * b^-2 The sequence of digits has to be infinite if den(x) has a prime factor which is not a factor of the base b. In cases where the representation @@ -53,30 +53,30 @@ DESCRIPTION With base-b digits for x as explained above, the integer whose base-b representation is - ; b_n+k-1 b_n_k-2 ... b_n, + ; b_n+k-1 b_n_k-2 ... b_n, i.e. the k digits with last digit b_n, is given by - ; digit(b^-r * x, q, b^k) + ; digit(b^-r * x, q, b^k) if r and q satisfy n = q * b + r. EXAMPLE - ; a = 123456.789 - ; for (n = 6; n >= -6; n++) print digit(a, n),; print - 0 1 2 3 4 5 6 7 8 9 0 0 0 + ; a = 123456.789 + ; for (n = 6; n >= -6; n++) print digit(a, n),; print + 0 1 2 3 4 5 6 7 8 9 0 0 0 - ; for (n = 6; n >= -6; n--) print digit(a, n, 100),; print - 0 0 0 0 12 34 56 78 90 0 0 0 0 + ; for (n = 6; n >= -6; n--) print digit(a, n, 100),; print + 0 0 0 0 12 34 56 78 90 0 0 0 0 - ; for (n = 6; n >= -6; n--) print digit(a, n, 256),; print - 0 0 0 0 1 226 64 201 251 231 108 139 67 + ; for (n = 6; n >= -6; n--) print digit(a, n, 256),; print + 0 0 0 0 1 226 64 201 251 231 108 139 67 - ; for (n = 1; n >= -12; n++) print digit(10/7, n),; print - ; 0 1 4 2 8 5 7 1 4 2 8 5 7 1 + ; for (n = 1; n >= -12; n++) print digit(10/7, n),; print + ; 0 1 4 2 8 5 7 1 4 2 8 5 7 1 - ; print digit(10/7, -7e1000, 1e6) - 428571 + ; print digit(10/7, -7e1000, 1e6) + 428571 LIMITS @@ -99,7 +99,7 @@ SEE ALSO ## ## 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 +## 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 @@ -107,8 +107,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/03 10:40:01 -## File existed as early as: 1995 +## Under source code control: 1995/10/03 10:40:01 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/digits b/help/digits index e3ef480..5d79293 100644 --- a/help/digits +++ b/help/digits @@ -5,10 +5,10 @@ SYNOPSIS digits(x [,b]) TYPES - x real - b integer >= 2, defaults to 10 + x real + b integer >= 2, defaults to 10 - return integer + return integer DESCRIPTION Returns number of digits in the standard base-b representation @@ -23,10 +23,10 @@ DESCRIPTION One should remember these special cases: - digits(12.3456) == 2 computes with the integer part only - digits(-1234) == 4 computes with the absolute value only - digits(0) == 1 special case - digits(-0.123) == 1 combination of all of the above + digits(12.3456) == 2 computes with the integer part only + digits(-1234) == 4 computes with the absolute value only + digits(0) == 1 special case + digits(-0.123) == 1 combination of all of the above EXAMPLE ; print digits(100), digits(23209), digits(2^72) @@ -58,7 +58,7 @@ SEE ALSO ## ## 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 +## 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 @@ -66,8 +66,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/03 10:40:01 -## File existed as early as: 1995 +## Under source code control: 1995/10/03 10:40:01 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/display b/help/display index 09de4b2..8b511ad 100644 --- a/help/display +++ b/help/display @@ -5,9 +5,9 @@ SYNOPSIS display([d]) TYPES - d integer >= 0 + d integer >= 0 - return integer + return integer DESCRIPTION When given an argument, this function sets the maximum number of @@ -21,13 +21,13 @@ DESCRIPTION The builtin function: - display(d) - display() + display(d) + display() is an alias for: - config("display", d) - config("display") + config("display", d) + config("display") The display digit value does not change the stored value of a number. It only changes how a stored value is displayed. @@ -108,7 +108,7 @@ SEE ALSO ## ## 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 +## 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 @@ -116,8 +116,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2004/07/25 23:50:40 -## File existed as early as: 2004 +## Under source code control: 2004/07/25 23:50:40 +## File existed as early as: 2004 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/dms2d b/help/dms2d index 77d8e3d..2cb01e3 100644 --- a/help/dms2d +++ b/help/dms2d @@ -6,19 +6,19 @@ SYNOPSIS dms2d(d, m, s [,rnd]) TYPES - d real - m real - s real (defaults to 0) - rnd nonnegative integer, defaults to config("mod") + d real + m real + s real (defaults to 0) + rnd nonnegative integer, defaults to config("mod") - return degrees + return degrees DESCRIPTION Convert degrees, m minutes, and s seconds returning degrees. The return value in degrees, is equivalent to the following: - mod(d + m/60 + s/3600, 360, rnd); + mod(d + m/60 + s/3600, 360, rnd); Depending on the rounding mode, the return could be a real value in the interval [0, 360) or a real value in the interval (-360, 0]. @@ -67,7 +67,7 @@ SEE ALSO ## ## 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 +## 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 @@ -75,8 +75,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/25 17:24:51 -## File existed as early as: 2021 +## Under source code control: 2021/09/25 17:24:51 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/dp b/help/dp index 38ad5dc..7fc6cc7 100644 --- a/help/dp +++ b/help/dp @@ -5,21 +5,21 @@ SYNOPSIS dp(x, y) TYPES - x, y 1-dimensional matrices of the same size + x, y 1-dimensional matrices of the same size - return depends on the nature of the elements of x and y + return depends on the nature of the elements of x and y DESCRIPTION Compute the dot product of two 1-dimensional matrices. Let: - x = {x0, x1, ... xn} - y = {y0, y1, ... yn} + x = {x0, x1, ... xn} + y = {y0, y1, ... yn} Then dp(x,y) returns the result of the calculation: - x0*y0 + x1*y1 + ... + xn*yn + x0*y0 + x1*y1 + ... + xn*yn EXAMPLE ; mat x[3] = {2,3,4} @@ -44,7 +44,7 @@ SEE ALSO ## ## 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 +## 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 @@ -52,8 +52,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:26 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:26 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/environment b/help/environment index 8e51b19..227b04a 100644 --- a/help/environment +++ b/help/environment @@ -2,119 +2,119 @@ Environment variables CALCPATH - A :-separated list of directories used to search for - resource filenames (*.cal files) that do not begin with: + A :-separated list of directories used to search for + resource filenames (*.cal files) that do not begin with: - / ./ ../ ~ + / ./ ../ ~ - If this variable does not exist, or if this - variable is an empty string, a compiled value - is used. Typically compiled in value is: + If this variable does not exist, or if this + variable is an empty string, a compiled value + is used. Typically compiled in value is: - .:./cal:~/cal:${CALC_SHAREDIR}:${CUSTOMCALDIR} + .:./cal:~/cal:${CALC_SHAREDIR}:${CUSTOMCALDIR} - which is usually: + which is usually: - .:./cal:~/cal:/usr/share/calc:/usr/share/calc/custom + .:./cal:~/cal:/usr/share/calc:/usr/share/calc/custom - This value is used by the READ command. It is an error - if no such readable file is found. + This value is used by the READ command. It is an error + if no such readable file is found. - The CALCBINDINGS file searches the CALCPATH as well. + The CALCBINDINGS file searches the CALCPATH as well. CALCRC - On startup (unless -h or -q was given on the command - line), calc searches for files along the :-separated - $CALCRC environment variable. + On startup (unless -h or -q was given on the command + line), calc searches for files along the :-separated + $CALCRC environment variable. - If this variable does not exist, or if this + If this variable does not exist, or if this variable is an empty string, a compiled value - is used. Typically compiled in value is: + is used. Typically compiled in value is: - ${CALC_SHAREDIR}/startup:~/.calcrc:./.calcinit + ${CALC_SHAREDIR}/startup:~/.calcrc:./.calcinit - which is usually: + which is usually: - /usr/share/calc/startup:~/.calcrc:./.calcinit + /usr/share/calc/startup:~/.calcrc:./.calcinit - Missing files along the $CALCRC path are silently ignored. + Missing files along the $CALCRC path are silently ignored. CALCBINDINGS - On startup (unless -h or -q was given on the command - line), calc reads key bindings from the filename specified - in the $CALCRC environment variable. These key bindings - are used for command line editing and the command history. + On startup (unless -h or -q was given on the command + line), calc reads key bindings from the filename specified + in the $CALCRC environment variable. These key bindings + are used for command line editing and the command history. - If this variable does not exist, a compiled value is used. - Typically compiled in value is: + If this variable does not exist, a compiled value is used. + Typically compiled in value is: - bindings + bindings - The bindings file is searched along the CALCPATH. Unlike - the READ command, a .cal extension is not added. + The bindings file is searched along the CALCPATH. Unlike + the READ command, a .cal extension is not added. - If the file could not be opened, or if standard input is not - a terminal, then calc will still run, but fancy command line - editing is disabled. + If the file could not be opened, or if standard input is not + a terminal, then calc will still run, but fancy command line + editing is disabled. - NOTE: If calc was compiled with GNU-readline support, the - CALCBINDINGS facility is ignored and the standard - readline mechanisms (see readline(3)) are used. + NOTE: If calc was compiled with GNU-readline support, the + CALCBINDINGS facility is ignored and the standard + readline mechanisms (see readline(3)) are used. HOME - This value is taken to be the home directory of the - current user. It is used when files begin with '~/'. + This value is taken to be the home directory of the + current user. It is used when files begin with '~/'. - If this variable does not exist, or if this - variable is an empty string, the home directory password - entry of the current user is used. If that information - is not available, '.' is used. + If this variable does not exist, or if this + variable is an empty string, the home directory password + entry of the current user is used. If that information + is not available, '.' is used. PAGER - When invoking help, this environment variable is used - to display a help file. + When invoking help, this environment variable is used + to display a help file. - If this variable does not exist, or if this - variable is an empty string, a compiled value - is used. Typically compiled in value is something - such as 'more', 'less', 'pg' or 'cat'. + If this variable does not exist, or if this + variable is an empty string, a compiled value + is used. Typically compiled in value is something + such as 'more', 'less', 'pg' or 'cat'. SHELL - When a !-command is used, the program indicated by - this environment variable is used. + When a !-command is used, the program indicated by + this environment variable is used. - If this variable does not exist, or if this - variable is an empty string, a compiled value - is used. Typically compiled in value is something - such as 'sh' is used. + If this variable does not exist, or if this + variable is an empty string, a compiled value + is used. Typically compiled in value is something + such as 'sh' is used. CALCHISTFILE - This value is taken to be the calc history file. + This value is taken to be the calc history file. - If this variable does not exist, or if this - variable is an empty string, then ~/.calc_history - is used. + If this variable does not exist, or if this + variable is an empty string, then ~/.calc_history + is used. CALCHELP - Location of the calc help directory. + Location of the calc help directory. - If this variable does not exist, or if this - variable is an empty string, then ${HELPDIR} + If this variable does not exist, or if this + variable is an empty string, then ${HELPDIR} CALCCUSTOMHELP - Location of the calc custom help directory. + Location of the calc custom help directory. - If this variable does not exist, or if this - variable is an empty string, then ${CUSTOMHELPDIR} - is used. + If this variable does not exist, or if this + variable is an empty string, then ${CUSTOMHELPDIR} + is used. ## Copyright (C) 1999,2021 Landon Curt Noll ## @@ -124,7 +124,7 @@ Environment variables ## ## 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 +## 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 @@ -132,8 +132,8 @@ Environment variables ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/23 05:47:25 -## File existed as early as: 1991 +## Under source code control: 1991/07/23 05:47:25 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/epsilon b/help/epsilon index 6fc7a5d..858ff8f 100644 --- a/help/epsilon +++ b/help/epsilon @@ -5,9 +5,9 @@ SYNOPSIS epsilon([eps]) TYPES - eps 0 < real < 1, defaults to epsilon() + eps 0 < real < 1, defaults to epsilon() - return real number greater than 0 and less than 1 + return real number greater than 0 and less than 1 DESCRIPTION Without args, epsilon() returns the current epsilon value. @@ -89,7 +89,7 @@ SEE ALSO ## ## 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 +## 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 @@ -97,8 +97,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:26 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:26 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/errcount b/help/errcount index 56b4a50..08e5d39 100644 --- a/help/errcount +++ b/help/errcount @@ -5,9 +5,9 @@ SYNOPSIS errcount([num]) TYPES - num integer + num integer - return integer + return integer DESCRIPTION An internal variable keeps count of the number of functions @@ -22,7 +22,7 @@ DESCRIPTION If an error value is assigned to a variable as in: - infty = 1/0; + infty = 1/0; then a function returning that variable does not contribute to errcount. @@ -31,9 +31,9 @@ EXAMPLE ; ## NOTE: Your output may vary: ; errmax(10) - 0 + 0 ; errcount() - 0 + 0 ; a = 1/0; b = 2 + ""; c = error(27); d = newerror("a"); ; print errcount(), a, errcount(), errmax(); 4 Error E_DIVBYZERO 4 10 @@ -55,7 +55,7 @@ SEE ALSO ## ## 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 +## 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 @@ -63,8 +63,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/03/08 08:51:14 -## File existed as early as: 1997 +## Under source code control: 1997/03/08 08:51:14 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/errmax b/help/errmax index d050ed2..500eca7 100644 --- a/help/errmax +++ b/help/errmax @@ -5,9 +5,9 @@ SYNOPSIS errmax([num]) TYPES - num integer + num integer - return integer + return integer DESCRIPTION Without an argument, errmax() returns the current value of an @@ -20,9 +20,9 @@ DESCRIPTION EXAMPLE ; errmax(2) - 20 + 20 ; errcount() - 0 + 0 ; a = 1/0; b = 2 + ""; c = error(27); d = newerror("alpha"); Error 27 caused errcount to exceed errmax @@ -33,7 +33,7 @@ EXAMPLE 0 0 ; errmax(-1) - 2 + 2 LIMITS -1 <= num <= 2147483647 @@ -52,7 +52,7 @@ SEE ALSO ## ## 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 +## 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 @@ -60,8 +60,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/03/08 08:51:14 -## File existed as early as: 1997 +## Under source code control: 1997/03/08 08:51:14 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/errno b/help/errno index 94daa66..bb849d2 100644 --- a/help/errno +++ b/help/errno @@ -5,55 +5,55 @@ SYNOPSIS errno([errnum | "E_STRING"]) TYPES - errnum integer - E_STRING string + errnum integer + E_STRING string - return integer + return integer DESCRIPTION With errno(errnum) numeric argument: - For 0 < errnum <= 32767: + For 0 < errnum <= 32767: - errno(errnum) sets "global calc_errno value" to the value - errnum and returns its previous value. Unlike error(errnum) - calling errno(errnum) does NOT increment the global calc - error count (see help errcount). + errno(errnum) sets "global calc_errno value" to the value + errnum and returns its previous value. Unlike error(errnum) + calling errno(errnum) does NOT increment the global calc + error count (see help errcount). - For all other errnum values: + For all other errnum values: - An error error condition is raised about the valid errnum. + An error error condition is raised about the valid errnum. With errno("E_STRING") string argument: - If E_STRING is a valid errsym code, then the E_STRING errsym - is converted into an equivalent errnum and errno is set to errnum. + If E_STRING is a valid errsym code, then the E_STRING errsym + is converted into an equivalent errnum and errno is set to errnum. - If E_STRING is not a valid errsym code, an error error condition - is raised about the invalid E_STRING. + If E_STRING is not a valid errsym code, an error error condition + is raised about the invalid E_STRING. - For example, these two calls are equivalent: + For example, these two calls are equivalent: - errno(10003); /* error 10003 has a E_STRING of "E_ADD" */ - errno("E_ADD"); /* error 10003 has a E_STRING of "E_ADD" */ + errno(10003); /* error 10003 has a E_STRING of "E_ADD" */ + errno("E_ADD"); /* error 10003 has a E_STRING of "E_ADD" */ - See help errsym for information on E_STRING errsym codes. + See help errsym for information on E_STRING errsym codes. - For a list of the E_STRING associated with calc computation error - codes, see help errorcodes. + For a list of the E_STRING associated with calc computation error + codes, see help errorcodes. With errno() no argument: - errno() returns the current value of "global calc_errno - value". Unlike error() calling errno() does NOT increment - the global calc error count (see help errcount). + errno() returns the current value of "global calc_errno + value". Unlike error() calling errno() does NOT increment + the global calc error count (see help errcount). NOTE: - The errno() builtin should not be confused with the errno - used by libc in C. The range of errnum extend beyond the - C's libc errno. See help error for information on the mean - of various errnum ranges. + The errno() builtin should not be confused with the errno + used by libc in C. The range of errnum extend beyond the + C's libc errno. See help error for information on the mean + of various errnum ranges. Unlike error() calling errno() does NOT increment the global calc error count (see help errcount). @@ -97,10 +97,10 @@ LIMITS E_STRING is string that must match the regular expression: ^E_[A-Z0-9_]+$ LINK LIBRARY - int calc_errno; /* global calc_errno value */ + int calc_errno; /* global calc_errno value */ int set_errno(int e); - CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */ + CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */ bool is_e_digits(CONST char *errsym); bool is_valid_errnum(int errnum); @@ -126,7 +126,7 @@ SEE ALSO ## ## 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 +## 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 @@ -134,8 +134,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/27 03:05:08 -## File existed as early as: 1994 +## Under source code control: 1994/10/27 03:05:08 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/error b/help/error index 6999b59..688f66e 100644 --- a/help/error +++ b/help/error @@ -5,63 +5,63 @@ SYNOPSIS error([errnum | "E_STRING"]) TYPES - errnum integer, defaults to errno() - E_STRING string + errnum integer, defaults to errno() + E_STRING string - return null value or error value + return null value or error value DESCRIPTION If errnum == 0: - error(errnum) returns the null value. + error(errnum) returns the null value. - The "global calc_errno value" is set to 0. + The "global calc_errno value" is set to 0. - The global calc error count is not changed. + The global calc error count is not changed. With error(errnum) numeric argument: - For 0 < errnum <= 32767: + For 0 < errnum <= 32767: - error(errnum) returns a value that is of a special type called - "error". The "error" return value, when given to iserror() - will cause that function to return a true value that happens - to match the "global calc_errno value". + error(errnum) returns a value that is of a special type called + "error". The "error" return value, when given to iserror() + will cause that function to return a true value that happens + to match the "global calc_errno value". - The "global calc_errno value" is then set to errnum. + The "global calc_errno value" is then set to errnum. - For all other errnum values: + For all other errnum values: - An error error condition is raised about the valid errnum. + An error error condition is raised about the valid errnum. - The global calc error count (see help errcount) is incremented. - If the global calc error count exceeds the maximum count - (see help errmax), any ongoing calc execution is aborted. + The global calc error count (see help errcount) is incremented. + If the global calc error count exceeds the maximum count + (see help errmax), any ongoing calc execution is aborted. With error("E_STRING") string argument: - If E_STRING is a valid errsym code, then the E_STRING errsym - is converted into an equivalent errnum and respective calc - error condition is raised. + If E_STRING is a valid errsym code, then the E_STRING errsym + is converted into an equivalent errnum and respective calc + error condition is raised. - If E_STRING is not a valid errsym code, an error error condition - is raised about the invalid E_STRING. + If E_STRING is not a valid errsym code, an error error condition + is raised about the invalid E_STRING. - For example, these two calls are equivalent: + For example, these two calls are equivalent: - error(10003); /* error 10003 has a E_STRING of "E_ADD" */ - error("E_ADD"); /* error 10003 has a E_STRING of "E_ADD" */ + error(10003); /* error 10003 has a E_STRING of "E_ADD" */ + error("E_ADD"); /* error 10003 has a E_STRING of "E_ADD" */ - See help errsym for information on E_STRING errsym codes. + See help errsym for information on E_STRING errsym codes. - For a list of the E_STRING associated with calc computation error - codes, see help errorcodes. + For a list of the E_STRING associated with calc computation error + codes, see help errorcodes. For no errnum arg: - Calling error() without an argument will return the current - "global calc_errno value" AND will also increment the - global calc error count. + Calling error() without an argument will return the current + "global calc_errno value" AND will also increment the + global calc error count. All other values of errnum are reserved for future use and currently will generate an error. @@ -81,23 +81,23 @@ DESCRIPTION By convention, the "global calc_errno value" has the following ranges: - errnum < 0 Reserved for future use - errnum == 0 calc_errno cleared: libc errno codes above here - 1 <= errnum <= 9999 system error and libc errno codes - errnum == 10000 Reserved for "No error" calc internal state - 10001 <= errnum <= E__HIGHEST calc computation error codes - E__HIGHEST < errnum < 20000 Reserved for future calc error codes - 20000 < errnum <= 32767 User defined error codes start here - errnum >= 32768 Reserved for future use + errnum < 0 Reserved for future use + errnum == 0 calc_errno cleared: libc errno codes above here + 1 <= errnum <= 9999 system error and libc errno codes + errnum == 10000 Reserved for "No error" calc internal state + 10001 <= errnum <= E__HIGHEST calc computation error codes + E__HIGHEST < errnum < 20000 Reserved for future calc error codes + 20000 < errnum <= 32767 User defined error codes start here + errnum >= 32768 Reserved for future use The following constants are part of the calc error code mechanism: - E__BASE == 10000 1 less than the 1st calc computation error code - E__HIGHEST highest assigned calc computation error code - E__USERDEF == 20000 user defined error codes start here - E__USERMAX == 32767 maximum user defined error code + E__BASE == 10000 1 less than the 1st calc computation error code + E__HIGHEST highest assigned calc computation error code + E__USERDEF == 20000 user defined error codes start here + E__USERMAX == 32767 maximum user defined error code - ECOUNT number of calc computation error codes (not including E__BASE) + ECOUNT number of calc computation error codes (not including E__BASE) See help errorcodes for the actual values of the above constants. @@ -134,9 +134,9 @@ LIMITS E_STRING is string that must match the regular expression: ^E_[A-Z0-9_]+$ LINK LIBRARY - int calc_errno; /* global calc_errno value */ + int calc_errno; /* global calc_errno value */ - CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */ + CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */ bool is_e_digits(CONST char *errsym); bool is_valid_errnum(int errnum); @@ -163,7 +163,7 @@ SEE ALSO ## ## 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 +## 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 @@ -171,8 +171,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 03:30:59 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 03:30:59 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/errsym b/help/errsym index 37f60f4..4c28d9f 100644 --- a/help/errsym +++ b/help/errsym @@ -5,96 +5,96 @@ SYNOPSIS errsym(errnum | "E_STRING") TYPES - errnum integer - E_STRING string + errnum integer + E_STRING string - return integer or string or error value + return integer or string or error value DESCRIPTION When called with in integer errnum argument: - When E__BASE < errnum <= E__HIGHEST, the corresponding errsym E_STRING - from the error_table[] array is returned. + When E__BASE < errnum <= E__HIGHEST, the corresponding errsym E_STRING + from the error_table[] array is returned. - For example: + For example: - ; print errsym(10003) - E_ADD + ; print errsym(10003) + E_ADD - When an errnum that matches one of the following errtbl.h #define, - then the #define string is returned: + When an errnum that matches one of the following errtbl.h #define, + then the #define string is returned: - E__NONE - E__BASE - E__USERDEF - E__USERMAX + E__NONE + E__BASE + E__USERDEF + E__USERMAX - NOTE: For errnum == E__HIGHEST, the corresponding E_STRING that - is returned is NOT "E__HIGHEST". Instead the E_STRING corresponding - to the highest errnum number from the error_table[] array is returned. + NOTE: For errnum == E__HIGHEST, the corresponding E_STRING that + is returned is NOT "E__HIGHEST". Instead the E_STRING corresponding + to the highest errnum number from the error_table[] array is returned. - For example: + For example: - ; print errsym(0) - E_NONE + ; print errsym(0) + E_NONE - When E__NONE <= errnum < E__BASE, or when E__USERDEF <= errnum <= E__USERMAX, - an "E_STRING" errsym of the form "E_digits" is returned where "digits" - are the ASCII digits of the decimal value of errnum. + When E__NONE <= errnum < E__BASE, or when E__USERDEF <= errnum <= E__USERMAX, + an "E_STRING" errsym of the form "E_digits" is returned where "digits" + are the ASCII digits of the decimal value of errnum. - For example: + For example: - ; print errsym(123) - E_123 + ; print errsym(123) + E_123 - For all other errnum values, an error is returned. + For all other errnum values, an error is returned. When called with E_STRING string argument: When the E_STRING starts with "E_" followed by only decimal digits: - If E_STRING is "E_0", 0 is returned. + If E_STRING is "E_0", 0 is returned. - If E_STRING matches the regular expression: + If E_STRING matches the regular expression: - ^E_[1-9][0-9]+$ + ^E_[1-9][0-9]+$ - where digits 0 < errnum <= 32767, the errnum value is returned. + where digits 0 < errnum <= 32767, the errnum value is returned. - For all other cases of "E_" by only decimal digits, an error is returned. + For all other cases of "E_" by only decimal digits, an error is returned. - When the E_STRING matches one of the following special - symbols, the symbol's numeric value as #define-d in errsym.h - or errtbl.h is returned: + When the E_STRING matches one of the following special + symbols, the symbol's numeric value as #define-d in errsym.h + or errtbl.h is returned: - E__NONE - E__BASE - E__HIGHEST - E__USERDEF - E__USERMAX + E__NONE + E__BASE + E__HIGHEST + E__USERDEF + E__USERMAX - For example: + For example: - ; print errsym("E_NONE") - 0 + ; print errsym("E_NONE") + 0 - For all other E_STRING strings that start with "E__", an error is returned. + For all other E_STRING strings that start with "E__", an error is returned. - When the E_STRING starts with "E_" followed by an UPPER CASE LETTER that - also matches the regular expression: + When the E_STRING starts with "E_" followed by an UPPER CASE LETTER that + also matches the regular expression: - ^E_[A-Z][A-Z0-9_]+$ + ^E_[A-Z][A-Z0-9_]+$ - The error_table[] is searched for an errsym that exactly matches - the E_STRING. If a match is found, the corresponding errnum number - is returned. If no match is found, an error is returned. + The error_table[] is searched for an errsym that exactly matches + the E_STRING. If a match is found, the corresponding errnum number + is returned. If no match is found, an error is returned. - For example: + For example: - ; print errsym("E_ADD") - 10003 + ; print errsym("E_ADD") + 10003 - For all other string arguments, an error is returned. + For all other string arguments, an error is returned. When errsym returns an integer, the global calc error count (see help errcount) is NOT changed. And of course, when errsym("E_STRING") returns an error, the @@ -102,30 +102,30 @@ DESCRIPTION Consider the E_MUL calc error condition: - Given a E_STRING errsym, errsym("E_STRING") will return the errnum integer - error code that is associated with the E_STRING errsym. + Given a E_STRING errsym, errsym("E_STRING") will return the errnum integer + error code that is associated with the E_STRING errsym. - The 4th entry of struct errtbl error_table is: + The 4th entry of struct errtbl error_table is: - { 10005, "E_MUL", "Bad arguments for +" }, + { 10005, "E_MUL", "Bad arguments for +" }, - And errcode -d produces a errsym.h with the following #define: + And errcode -d produces a errsym.h with the following #define: - #define E_MUL 10005 /* Bad arguments for * */ + #define E_MUL 10005 /* Bad arguments for * */ - Thus 10005 is the errnum, "E_MUL" is the E_STRING errsym that is - associated with the errmsg error message: "Bad arguments for +". + Thus 10005 is the errnum, "E_MUL" is the E_STRING errsym that is + associated with the errmsg error message: "Bad arguments for +". - In the above example, errsym("E_MUL") will return 10005. - Also errsym("E_10005") will also return 10005. + In the above example, errsym("E_MUL") will return 10005. + Also errsym("E_10005") will also return 10005. - To complete the E_STRING use in the above example: + To complete the E_STRING use in the above example: - Both error(10005) and error("E_MUL") both raise the E_MUL calc error condition + Both error(10005) and error("E_MUL") both raise the E_MUL calc error condition - Both errno(10005) and errno("E_MUL") both return 10005 + Both errno(10005) and errno("E_MUL") both return 10005 - Both strerror(10005) and strerror("E_MUL") both return "Bad arguments for *" + Both strerror(10005) and strerror("E_MUL") both return "Bad arguments for *" EXAMPLE ; print errsym("E_ADD"), errsym("E_SUB"), errsym("E_MUL"), errsym("E_DIV") @@ -146,9 +146,9 @@ LIMITS E_STRING is string that must match the regular expression: ^E_[A-Z0-9_]+$ LINK LIBRARY - int calc_errno; /* global calc_errno value */ + int calc_errno; /* global calc_errno value */ - CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */ + CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */ bool is_e_digits(CONST char *errsym); bool is_valid_errnum(int errnum); @@ -174,7 +174,7 @@ SEE ALSO ## ## 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 +## 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 @@ -182,8 +182,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 03:30:59 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 03:30:59 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/estr b/help/estr index aae0002..d58500d 100644 --- a/help/estr +++ b/help/estr @@ -5,10 +5,10 @@ SYNOPSIS estr(x) TYPES - x null, string, real or complex number, list, matrix, - object. block, named block, error + x null, string, real or complex number, list, matrix, + object. block, named block, error - return string + return string DESCRIPTION This function attempts to represent x exactly by a string s of @@ -26,11 +26,11 @@ DESCRIPTION EXAMPLE ; estr("abc\0xyz\00023\n\xa5\r\n") - ""abc\0xyz\00023\n\xa5\r\n"" + ""abc\0xyz\00023\n\xa5\r\n"" ; estr(1.67) - "167/100" + "167/100" ; estr(mat[3] = {2, list(3,5), "abc"}) - "mat[3]={2,list(3,5),"abc"" + "mat[3]={2,list(3,5),"abc"" LIMITS none @@ -49,7 +49,7 @@ SEE ALSO ## ## 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 +## 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 @@ -57,8 +57,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2006/08/20 14:45:13 -## File existed as early as: 2006 +## Under source code control: 2006/08/20 14:45:13 +## File existed as early as: 2006 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/euler b/help/euler index 1434e47..2d7b4f4 100644 --- a/help/euler +++ b/help/euler @@ -5,15 +5,15 @@ SYNOPSIS euler(n) TYPES - n integer, n <= 1000000 if even + n integer, n <= 1000000 if even - return integer + return integer DESCRIPTION Returns the Euler number with index n, i.e. the coefficient E_n in the expansion - sech(t) = Sigma E_n * t^n/n! + sech(t) = Sigma E_n * t^n/n! When euler(n) is computed for positive even n, the values for n and smaller positive even indices are stored in a table so that @@ -45,7 +45,7 @@ SEE ALSO ## ## 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 +## 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 @@ -53,7 +53,7 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2000/12/14 01:33:00 -## File existed as early as: 2000 +## Under source code control: 2000/12/14 01:33:00 +## File existed as early as: 2000 ## -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/eval b/help/eval index e1aaeed..b0a7fa3 100644 --- a/help/eval +++ b/help/eval @@ -5,13 +5,13 @@ SYNOPSIS eval(str) TYPES - str string + str string - return any + return any DESCRIPTION For eval(str), the value of str is to be a string that could be the body - of the definition of a function f(). This string may declare local + of the definition of a function f(). This string may declare local variables and include keywords (while, for, ...) other than the reserved keywords (define, show, help, read, write, show, cd) intended for interactive use or for reading from a file. @@ -43,12 +43,12 @@ EXAMPLE ; eval("2 + "); Missing expression - 49 + 49 LIMITS The string str in eval(str) should not include a call to itself as in - str = "2 + eval(str)" + str = "2 + eval(str)" For this str, eval(str) causes an "Evaluation stack depth exceeded" error. Similarly, if str1 = "2 + eval(str2)", str2 should not include a call @@ -68,7 +68,7 @@ SEE ALSO ## ## 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 +## 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 @@ -76,8 +76,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 03:30:59 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 03:30:59 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/excsc b/help/excsc index 4fc4b2e..0572005 100644 --- a/help/excsc +++ b/help/excsc @@ -5,10 +5,10 @@ SYNOPSIS excsc(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Calculate the exterior trigonometric secant of x to a multiple of eps, with error less @@ -16,7 +16,7 @@ DESCRIPTION This function is equivalent to: - excsc(x) = csc(x) - 1 + excsc(x) = csc(x) - 1 EXAMPLE ; print excsc(1/2), excsc(5/7), excsc(42/7) @@ -56,14 +56,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -73,7 +73,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -81,8 +81,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/30 23:19:00 -## File existed as early as: 2023 +## Under source code control: 2023/09/30 23:19:00 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/exp b/help/exp index 38f4f38..3b0f4a7 100644 --- a/help/exp +++ b/help/exp @@ -5,10 +5,10 @@ SYNOPSIS exp(x [,eps]) TYPES - x real or complex - eps 0 < real < 1, defaults to epsilon() + x real or complex + eps 0 < real < 1, defaults to epsilon() - return real or complex + return real or complex DESCRIPTION Approximate the exponential function of x by a multiple of epsilon, @@ -49,7 +49,7 @@ SEE ALSO ## ## 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 +## 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 @@ -57,8 +57,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/11 04:41:26 -## File existed as early as: 1995 +## Under source code control: 1995/10/11 04:41:26 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/expression b/help/expression index 69d9199..a930362 100644 --- a/help/expression +++ b/help/expression @@ -9,20 +9,20 @@ Expression sequences then the value of '.' is set to the value of the last expression. Also, if an expression is a non-assignment, then the value of the expression is automatically printed if its value is not NULL. - Some operations such as pre-increment and plus-equals are also + Some operations such as pre-increment and plus-equals are also treated as assignments. Examples of this are the following: - expression sets '.' to prints - ---------- ----------- ------ - 3+4 7 7 - 2*4; 8+1; fact(3) 6 8, 9, and 6 - x=3^2 9 - - if (3 < 2) 5; else 6 6 6 - x++ old x - - print fact(4) - 24 - null() null() - + expression sets '.' to prints + ---------- ----------- ------ + 3+4 7 7 + 2*4; 8+1; fact(3) 6 8, 9, and 6 + x=3^2 9 - + if (3 < 2) 5; else 6 6 6 + x++ old x - + print fact(4) - 24 + null() null() - Variables can be defined at the beginning of an expression sequence. This is most useful for local variables, as in the following example, @@ -42,7 +42,7 @@ Expression sequences ## ## 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 +## 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 @@ -50,8 +50,8 @@ Expression sequences ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:18 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:18 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/exsec b/help/exsec index ea23222..38534b0 100644 --- a/help/exsec +++ b/help/exsec @@ -5,10 +5,10 @@ SYNOPSIS exsec(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Calculate the exterior trigonometric secant of x to a multiple of eps, with error less @@ -16,7 +16,7 @@ DESCRIPTION This function is equivalent to: - exsec(x) = sec(x) - 1 + exsec(x) = sec(x) - 1 EXAMPLE ; print exsec(1/2), exsec(5/7), exsec(42/7) @@ -56,14 +56,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -73,7 +73,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -81,8 +81,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/10/01 00:19:00 -## File existed as early as: 2023 +## Under source code control: 2023/10/01 00:19:00 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fact b/help/fact index 7f3c594..9a95b7d 100644 --- a/help/fact +++ b/help/fact @@ -5,15 +5,15 @@ SYNOPSIS fact(x) TYPES - x int + x int - return int + return int DESCRIPTION Return the factorial of a number. Factorial is defined as: - x! = 1 * 2 * 3 * ... * x-1 * x - 0! = 1 + x! = 1 * 2 * 3 * ... * x-1 * x + 0! = 1 EXAMPLE ; print fact(10), fact(5), fact(2), fact(1), fact(0) @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/20 04:03:02 -## File existed as early as: 1994 +## Under source code control: 1994/10/20 04:03:02 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/factor b/help/factor index 2bbcb80..83f3061 100644 --- a/help/factor +++ b/help/factor @@ -5,11 +5,11 @@ SYNOPSIS factor(n [, limit [, err]]) TYPES - n integer - limit integer with abs(limit) < 2^32, defaults to 2^32 - 1 - err integer + n integer + limit integer with abs(limit) < 2^32, defaults to 2^32 - 1 + err integer - return positive integer or err + return positive integer or err DESCRIPTION This function ignores the signs of n and limit, so here we shall @@ -19,9 +19,9 @@ DESCRIPTION factor(n, limit) returns the smallest such factor, or 1 if no factor was found below the limit. - NOTE: A proper factor of n>1 is a factor < n. In other words, - for n>1 is not a proper factor of itself. The value 1 - is a special case because 1 is a proper factor of 1. + NOTE: A proper factor of n>1 is a factor < n. In other words, + for n>1 is not a proper factor of itself. The value 1 + is a special case because 1 is a proper factor of 1. When every prime proper factor of n is greater than limit, 1 is returned. In particular, if limit < 2, factor(n, limit) always @@ -59,7 +59,7 @@ SEE ALSO ## ## 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 +## 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 @@ -67,8 +67,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 12:34:57 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 12:34:57 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fclose b/help/fclose index e68e46d..b94cfb0 100644 --- a/help/fclose +++ b/help/fclose @@ -5,15 +5,15 @@ SYNOPSIS fclose(fd) TYPES - fd file + fd file - return nul or int + return nul or int DESCRIPTION This function closes the open file associated with the descriptor fd. When this is done, the file value associated with the file remains a file value, but appears 'closed', and cannot be used in further - file-related calls (except fclose) without causing errors. This same + file-related calls (except fclose) without causing errors. This same action occurs to all copies of the file value. You do not need to explicitly close all the copies of a file value. @@ -26,7 +26,7 @@ DESCRIPTION there had been an error using the file, or the null value if there was no error. - Closing a closed file is permitted. Fclose returns null in + Closing a closed file is permitted. Fclose returns null in this case. EXAMPLE @@ -59,7 +59,7 @@ SEE ALSO ## ## 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 +## 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 @@ -67,8 +67,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/27 03:04:16 -## File existed as early as: 1994 +## Under source code control: 1994/10/27 03:04:16 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fcnt b/help/fcnt index 35aba11..b695ba2 100644 --- a/help/fcnt +++ b/help/fcnt @@ -5,10 +5,10 @@ SYNOPSIS fcnt(x,y) TYPES - x integer - y integer + x integer + y integer - return non-negative integer + return non-negative integer DESCRIPTION If x is nonzero and abs(y) > 1, fcnt(x,y) returns the greatest @@ -38,7 +38,7 @@ SEE ALSO ## ## 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 +## 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 @@ -46,8 +46,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 12:03:02 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 12:03:02 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/feof b/help/feof index 495c9ef..d2366ff 100644 --- a/help/feof +++ b/help/feof @@ -5,16 +5,16 @@ SYNOPSIS feof(fd) TYPES - fd file stream open for reading + fd file stream open for reading - return 0 or 1 + return 0 or 1 DESCRIPTION The function feof(fd) returns 1 or 0 according as the end-of-file flag is set or clear. The end-of-file flag for the stream fd is set if reading at the - end-of-file position is attempted. The flag is cleared by + end-of-file position is attempted. The flag is cleared by positioning operations (fseek, rewind, fsetpos) and by freopen. EXAMPLE @@ -23,14 +23,14 @@ EXAMPLE ; fflush(fd1) ; fd2 = fopen("/tmp/newfile", "r") ; feof(fd2) - 0 + 0 ; fgetline(fd2) - "Chongo was here" + "Chongo was here" ; feof(fd2) - 0 + 0 ; fgetline(fd2) ; feof(fd2) - 1 + 1 LIMITS none @@ -51,7 +51,7 @@ SEE ALSO ## ## 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 +## 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 @@ -59,8 +59,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/27 03:04:17 -## File existed as early as: 1994 +## Under source code control: 1994/10/27 03:04:17 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ferror b/help/ferror index 95b2b59..c4a2ffd 100644 --- a/help/ferror +++ b/help/ferror @@ -5,9 +5,9 @@ SYNOPSIS ferror(fd) TYPES - fd file + fd file - return int + return int DESCRIPTION This function determines whether the error condition was detected @@ -20,7 +20,7 @@ DESCRIPTION EXAMPLE ; fd = fopen("/etc/motd", "r") ; ferror(fd) - 0 + 0 LIMITS fd must be associated with an open file @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/27 03:04:17 -## File existed as early as: 1994 +## Under source code control: 1994/10/27 03:04:17 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fflush b/help/fflush index b55f6d9..c3c1062 100644 --- a/help/fflush +++ b/help/fflush @@ -5,9 +5,9 @@ SYNOPSIS fflush(fd) TYPES - fd file + fd file - return nil + return nil DESCRIPTION This function forces a buffered output to the file associated with fd. @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/27 03:04:17 -## File existed as early as: 1994 +## Under source code control: 1994/10/27 03:04:17 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fgetc b/help/fgetc index 5e9928c..aeb543b 100644 --- a/help/fgetc +++ b/help/fgetc @@ -5,16 +5,16 @@ SYNOPSIS fgetc(fd) TYPES - fd file + fd file - return str or nil + return str or nil DESCRIPTION This function reads the next character from the open file associated with fd. If there is a next character, this function returns a 1 - character string containing that character. In the case + character string containing that character. In the case of EOF or error, nil is returned. EXAMPLE @@ -22,7 +22,7 @@ EXAMPLE ; fputs(fd, "chongo was here\n") ; fd2 = fopen("/tmp/newfile", "r") ; fgetc(fd2) - "c" + "c" LIMITS fd must be associated with an open file @@ -42,7 +42,7 @@ SEE ALSO ## ## 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 +## 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 @@ -50,8 +50,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/03/04 11:33:19 -## File existed as early as: 1995 +## Under source code control: 1995/03/04 11:33:19 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fgetfield b/help/fgetfield index dd32c1c..30177f6 100644 --- a/help/fgetfield +++ b/help/fgetfield @@ -5,9 +5,9 @@ SYNOPSIS fgetfield(fs) TYPES - fs file stream open for reading + fs file stream open for reading - return string or null + return string or null DESCRIPTION @@ -25,20 +25,20 @@ EXAMPLE ; fputs(f, " Alpha Beta \n") ; freopen(f, "r") ; fgetfield(f) - "Alpha" + "Alpha" ; fgetfield(f) - "Beta" + "Beta" ; fgetfield(f) ; freopen(f, "w") ; fputstr(f, " Alpha ", "Beta") ; freopen(f, "r") ; fgetfield(f) - "Alpha" + "Alpha" ; fgetfield(f) - "" + "" ; fgetfield(f) - "Beta" + "Beta" LIMITS none @@ -57,7 +57,7 @@ SEE ALSO ## ## 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 +## 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 @@ -65,8 +65,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:05:17 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:05:17 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fgetfile b/help/fgetfile index f34ed81..17f1711 100644 --- a/help/fgetfile +++ b/help/fgetfile @@ -5,9 +5,9 @@ SYNOPSIS fgetfile(fs) TYPES - fs file stream open for reading + fs file stream open for reading - return string or null value + return string or null value DESCRIPTION @@ -20,19 +20,19 @@ DESCRIPTION If the content of the file "newfile" is a sequence of statements that could form the body of function definition, the statement sequence - fs = fopen("newfile", "r"); - eval(fgetfile(fs)); + fs = fopen("newfile", "r"); + eval(fgetfile(fs)); achieves the same as the command - read newfile; + read newfile; EXAMPLE ; f = fopen("/tmp/newfile", "w") ; fputs(f, "abc\0xyz\n\t\xb0\0\r\v123" ; freopen(f, "r") ; estr(fgetfile(f)) - ""abc\0xyz\n\t\xb0\0\r\v123"" + ""abc\0xyz\n\t\xb0\0\r\v123"" LIMITS none @@ -51,7 +51,7 @@ SEE ALSO ## ## 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 +## 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 @@ -59,8 +59,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:05:17 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:05:17 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fgetline b/help/fgetline index b7952c4..fe99440 100644 --- a/help/fgetline +++ b/help/fgetline @@ -5,16 +5,16 @@ SYNOPSIS fgetline(fd) TYPES - fd file + fd file - return str or nil + return str or nil DESCRIPTION This function reads the next line, including any trailing newline from the open file associated with fd. Unlike fgets, the trailing newline is removed from the return string. - Empty lines return the null string. When the end of file is reached, + Empty lines return the null string. When the end of file is reached, fgetline returns the null value. (Note the distinction between a null string and a null value.) @@ -30,15 +30,15 @@ EXAMPLE ; fputs(fd, "123\n") ; fd2 = fopen("/tmp/newfile", "r") ; fgets(fd2) - "chongo was here + "chongo was here " ; fclose(fd2) ; fd2 = fopen("/tmp/newfile", "r") ; fgetline(fd2) - "chongo was here" + "chongo was here" ; eval(fgetline(fd2)) - 123 + 123 LIMITS fd must be associated with an open file @@ -58,7 +58,7 @@ SEE ALSO ## ## 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 +## 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 @@ -66,8 +66,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/03/04 11:33:19 -## File existed as early as: 1995 +## Under source code control: 1995/03/04 11:33:19 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fgets b/help/fgets index 898902c..ba58e61 100644 --- a/help/fgets +++ b/help/fgets @@ -5,9 +5,9 @@ SYNOPSIS fgets(fd) TYPES - fd file + fd file - return str or nil + return str or nil DESCRIPTION This function reads the next line, including any trailing newline from @@ -21,13 +21,13 @@ EXAMPLE ; fputs(fd, "chongo was here\n") ; fd2 = fopen("/tmp/newfile", "r") ; fgets(fd2) - "chongo was here + "chongo was here " ; fclose(fd2) ; fd2 = fopen("/tmp/newfile", "r") ; fgetline(fd2) - "chongo was here" + "chongo was here" LIMITS fd must be associated with an open file @@ -47,7 +47,7 @@ SEE ALSO ## ## 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 +## 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 @@ -55,8 +55,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/03/04 11:33:19 -## File existed as early as: 1995 +## Under source code control: 1995/03/04 11:33:19 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fgetstr b/help/fgetstr index e7e9378..1c5043e 100644 --- a/help/fgetstr +++ b/help/fgetstr @@ -5,9 +5,9 @@ SYNOPSIS fgetstr(fs) TYPES - fs file stream open for reading + fs file stream open for reading - return string, null or error value + return string, null or error value DESCRIPTION If the stream is at end of file, the null value is returned. @@ -29,12 +29,12 @@ EXAMPLE ; fputstr(f, " Alpha Beta ", "", "Gamma\n\tDelta") ; freopen(f, "r") ; fgetstr(f) - " Alpha Beta " + " Alpha Beta " ; fgetstr(f) - "" + "" ; fgetstr(f) - "Gamma - Delta" + "Gamma + Delta" ; fgetstr(f) LIMITS @@ -54,7 +54,7 @@ SEE ALSO ## ## 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 +## 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 @@ -62,8 +62,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:05:17 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:05:17 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fib b/help/fib index 2cf922c..b0bb806 100644 --- a/help/fib +++ b/help/fib @@ -5,9 +5,9 @@ SYNOPSIS fib(n) TYPES - n integer + n integer - return integer + return integer DESCRIPTION For any integer n, fib(n) returns the Fibonacci number with index n. @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:45 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:45 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/file b/help/file index ec8e179..15e3aa8 100644 --- a/help/file +++ b/help/file @@ -6,24 +6,24 @@ Using files Some differences do occur, as will be explained here. Names of files are subject to ~ expansion just like the C or - Korn shell. For example, the file name: + Korn shell. For example, the file name: - ~/.rc.cal + ~/.rc.cal refers to the file '.rc.cal' under your home directory. The file name: - ~chongo/.rc.cal + ~chongo/.rc.cal refers to the a file 'rc.cal' under the home directory of 'chongo'. A file can be opened for either reading, writing, or appending. To do this, the 'fopen' function is used, which accepts a filename - and an open mode, both as strings. You use 'r' for reading, 'w' - for writing, and 'a' for appending. For example, to open the file + and an open mode, both as strings. You use 'r' for reading, 'w' + for writing, and 'a' for appending. For example, to open the file 'foo' for reading, the following could be used: - fd = fopen('foo', 'r'); + fd = fopen('foo', 'r'); If the open is unsuccessful, the numeric value of errno is returned. If the open is successful, a value of type 'file' will be returned. @@ -48,21 +48,21 @@ Using files of using 'files', if you wanted to assign a file value which is equivalent to stdout, you could use: - stdout = files(1); + stdout = files(1); Or for example, if you wanted to assign a file value which is equivalent to stdin, you could use: - stdout = files(0); + stdout = files(0); And for stderr: - stderr = files(2); + stderr = files(2); The 'fclose' function is used to close a file which had been opened. When this is done, the file value associated with the file remains a file value, but appears 'closed', and cannot be used in further - file-related calls (except fclose) without causing errors. This same + file-related calls (except fclose) without causing errors. This same action occurs to all copies of the file value. You do not need to explicitly close all the copies of a file value. The 'fclose' function returns the numeric value of errno if there had been an @@ -71,12 +71,12 @@ Using files The builtin 'strerror' can be use to convert an errno number into a slightly more meaningful error message: - badfile = fopen("not_a_file", "r"); - if (!isfile(badfile)) { - print "error #" : badfile : ":", strerror(badfile); - } + badfile = fopen("not_a_file", "r"); + if (!isfile(badfile)) { + print "error #" : badfile : ":", strerror(badfile); + } - File values can be printed. When this is done, the filename of the + File values can be printed. When this is done, the filename of the opened file is printed inside of quote marks. If the file value had been closed, then the null string is printed. If a file value is the result of a top-level expression, then in addition to the filename, @@ -84,23 +84,23 @@ Using files status is also displayed. File values can be used inside of 'if' tests. When this is done, - an opened file is TRUE, and a closed file is FALSE. As an example + an opened file is TRUE, and a closed file is FALSE. As an example of this, the following loop will print the names of all the currently opened non-standard files with their indexes, and then close them: - for (i = 3; i < files(); i++) { - if (files(i)) { - print i, files(i); - fclose(files(i)); - } - } + for (i = 3; i < files(); i++) { + if (files(i)) { + print i, files(i); + fclose(files(i)); + } + } The functions to read from files are 'fgetline' and 'fgetc'. The 'fgetline' function accepts a file value, and returns the next input line from a file. The line is returned as a string value, and - does not contain the end of line character. Empty lines return the + does not contain the end of line character. Empty lines return the null string. When the end of file is reached, fgetline returns the - null value. (Note the distinction between a null string and a null + null value. (Note the distinction between a null string and a null value.) If the line contained a numeric value, then the 'eval' function can then be used to convert the string to a numeric value. Care should be used when doing this, however, since eval will @@ -113,15 +113,15 @@ Using files as long as the -p flag is given to calc. For example, this will print "chongo was here": - echo chongo was here | calc -p 'print fgetline(files(0));' + echo chongo was here | calc -p 'print fgetline(files(0));' while this does not: - echo chongo was here | calc 'print fgetline(files(0));' + echo chongo was here | calc 'print fgetline(files(0));' nor will this print "chongo was here": - echo chongo was here | calc -i 'print fgetline(files(0));' + echo chongo was here | calc -i 'print fgetline(files(0));' This is because without -p, the interactive parser, in an effort to parse interactive commands, flushes data on standard input. @@ -129,20 +129,20 @@ Using files On the other hand, once interactive mode is entered, reading from standard input works as expected. For example, this works: - $ calc - C-style arbitrary precision calculator (version 2.12.6.0) - Calc is open software. For license details type: help copyright - [Type "exit" to exit, or "help" for help.] + $ calc + C-style arbitrary precision calculator (version 2.12.6.0) + Calc is open software. For license details type: help copyright + [Type "exit" to exit, or "help" for help.] - ; str = fgetline(files(0)) - this text was typed into stdin - ; print str - this text was typed into stdin + ; str = fgetline(files(0)) + this text was typed into stdin + ; print str + this text was typed into stdin The 'printf' and 'fprintf' functions are used to print results to a file (which could be stdout or stderr). The 'fprintf' function accepts a file variable, whereas the 'printf' function assumes the - use of 'files(1)' (stdout). They both require a format string, which + use of 'files(1)' (stdout). They both require a format string, which is used in almost the same way as in normal C. The differences come in the interpretation of values to be printed for various formats. Unlike in C, where an unmatched format type and value will cause @@ -152,7 +152,7 @@ Using files use %s or %d in your format strings, even if you are printing a non- string or non-numeric value. For example, the following is valid: - printf("Two values are %d and %s\n", "fred", 4567); + printf("Two values are %d and %s\n", "fred", 4567); and will print "Two values are fred and 4567". @@ -161,13 +161,13 @@ Using files you wish to print numbers in a particular format. The following is a list of the possible numeric formats: - %d print in currently defined numeric format - %f print as floating point - %e print as exponential - %r print as decimal fractions - %x print as hex fractions - %o print as octal fractions - %b print as binary fractions + %d print in currently defined numeric format + %f print as floating point + %e print as exponential + %r print as decimal fractions + %x print as hex fractions + %o print as octal fractions + %b print as binary fractions Note then, that using %d in the format makes the output configurable by using the 'config' function to change the output mode, whereas @@ -177,7 +177,7 @@ Using files Using the precision argument will override the 'config' function to set the number of decimal places printed. For example: - printf("The number is %.100f\n", 1/3); + printf("The number is %.100f\n", 1/3); will print 100 decimal places no matter what the display configuration value is set to. @@ -213,7 +213,7 @@ Using files ## ## 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 +## 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 @@ -221,8 +221,8 @@ Using files ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:19 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:19 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/files b/help/files index 144735a..a60a7c0 100644 --- a/help/files +++ b/help/files @@ -5,9 +5,9 @@ SYNOPSIS files([fnum]) TYPES - fnum int + fnum int - return files, int or null + return files, int or null DESCRIPTION This function, when given the argument fnum, will use it as an @@ -25,28 +25,28 @@ DESCRIPTION files are already open by the calculator and cannot be closed. When calc starts up, it scans for open file descriptors above - stderr (2) and below MAXFILES (20). Any open descriptor found + stderr (2) and below MAXFILES (20). Any open descriptor found is assumed to be an open file opened in an unknown mode. Calc will try to read and write to this file when directed. Consider the following commands shell commands: - echo "A line of text in the file on descriptor 5" > datafile - calc 5 datafile + calc 5 /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/floor b/help/floor index 4fd359f..320265c 100644 --- a/help/floor +++ b/help/floor @@ -5,9 +5,9 @@ SYNOPSIS floor(x) TYPES - x real, complex, list, matrix + x real, complex, list, matrix - return real or complex, list, matrix + return real or complex, list, matrix DESCRIPTION For real x, floor(x) is the greatest integer not greater than x. @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/30 01:12:01 -## File existed as early as: 1994 +## Under source code control: 1994/09/30 01:12:01 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fopen b/help/fopen index 697815e..8d91540 100644 --- a/help/fopen +++ b/help/fopen @@ -5,59 +5,59 @@ SYNOPSIS fopen(filename, mode) TYPES - filename string - mode string + filename string + mode string - return file + return file DESCRIPTION This function opens the file named filename. A file can be opened for either reading, writing, or appending. The mode is controlled by the mode flag as follows: - allow allow file is positioned file(*) - mode reading writing truncated at mode - ---- ------- ------- --------- --------- ---- - r Y N N beginning text - rb Y N N beginning binary - r+ Y N N beginning text - r+b Y N N beginning binary - rb+ Y N N beginning binary + allow allow file is positioned file(*) + mode reading writing truncated at mode + ---- ------- ------- --------- --------- ---- + r Y N N beginning text + rb Y N N beginning binary + r+ Y N N beginning text + r+b Y N N beginning binary + rb+ Y N N beginning binary - w N Y Y beginning text - wb N Y Y beginning binary - w+ Y Y Y beginning text - w+b Y Y Y beginning binary - wb+ Y Y Y beginning binary + w N Y Y beginning text + wb N Y Y beginning binary + w+ Y Y Y beginning text + w+b Y Y Y beginning binary + wb+ Y Y Y beginning binary - a N Y Y end text - ab N Y Y end binary - a+ Y Y Y end text - a+b Y Y Y end binary - ab+ Y Y Y end binary + a N Y Y end text + ab N Y Y end binary + a+ Y Y Y end text + a+b Y Y Y end binary + ab+ Y Y Y end binary (*) NOTE on 'b' / binary/text mode: - The 'b' or fopen binary mode has no effect on POSIX / Linux - / Un*x-like systems. On those systems a text file is the - same as a binary file (as it should be for any modern-day - operating system). Adding 'b' to an fopen has no effect - and is ignored. + The 'b' or fopen binary mode has no effect on POSIX / Linux + / Un*x-like systems. On those systems a text file is the + same as a binary file (as it should be for any modern-day + operating system). Adding 'b' to an fopen has no effect + and is ignored. - Some non-POSIX systems such as MS Windows treat text files - and binary files differently. In text mode MS Windows consider - "\r\n" an end-of-line character. On an Apple MAC, the - text mode end-of-line character is "\r". + Some non-POSIX systems such as MS Windows treat text files + and binary files differently. In text mode MS Windows consider + "\r\n" an end-of-line character. On an Apple MAC, the + text mode end-of-line character is "\r". Names of files are subject to ~ expansion just like the C or - Korn shell. For example, the file name: + Korn shell. For example, the file name: - ~/lib/fizzbin + ~/lib/fizzbin refers to the file 'fizzbin' under the directory lib located in your home directory. The file name: - ~chongo/was_here + ~chongo/was_here refers to the a file 'was_here' under the home directory of the user 'chongo'. @@ -82,13 +82,13 @@ EXAMPLE ; print fd "/etc/motd" ; fd - FILE 3 "/etc/motd" (reading, pos 0) + FILE 3 "/etc/motd" (reading, pos 0) ; outfile = fopen("~/tmp/output", "w") ; print outfile "~/tmp/output" ; outfile - FILE 4 "~/tmp/output" (writing, pos 0) + FILE 4 "~/tmp/output" (writing, pos 0) ; badfile = fopen("not_a_file", "r"); ; if (!isfile(badfile)) { @@ -115,7 +115,7 @@ SEE ALSO ## ## 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 +## 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 @@ -123,8 +123,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/27 03:04:17 -## File existed as early as: 1994 +## Under source code control: 1994/10/27 03:04:17 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/forall b/help/forall index 6d6b88f..5855c9c 100644 --- a/help/forall +++ b/help/forall @@ -5,10 +5,10 @@ SYNOPSIS forall(x, y) TYPES - x list or matrix - y string + x list or matrix + y string - return null value + return null value DESCRIPTION In forall(x,y), y is the name of a function; that function @@ -21,12 +21,12 @@ EXAMPLE ; A = list(1,2,3,4) ; forall(A, "s") ; n - 10 + 10 ; define e(a) {if (iseven(a)) print a;} ; forall(A, "e") - 2 - 4 + 2 + 4 LIMITS none @@ -45,7 +45,7 @@ SEE ALSO ## ## 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 +## 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 @@ -53,8 +53,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/10 02:09:31 -## File existed as early as: 1995 +## Under source code control: 1995/07/10 02:09:31 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fpathopen b/help/fpathopen index 2184e74..58c1329 100644 --- a/help/fpathopen +++ b/help/fpathopen @@ -5,11 +5,11 @@ SYNOPSIS fpathopen(filename, mode [,searchpath]) TYPES - filename string - mode string - searchpath string + filename string + mode string + searchpath string - return file + return file DESCRIPTION This function opens the file named filename, potentially searching @@ -21,24 +21,24 @@ DESCRIPTION Absolute filenames, and filenames with an implied path are files that begin with: - / # absolute path - ./ # implied path through the current working directory - ../ # implied path through the current working directory parent - ~ # absolute path going through a home directory + / # absolute path + ./ # implied path through the current working directory + ../ # implied path through the current working directory parent + ~ # absolute path going through a home directory A search path is a :-separated list of directories used to search for a filename. For example: - fpathopen("whey", "r", ".:/tmp:/var/tmp:~chongo/pub:~/tmp"); + fpathopen("whey", "r", ".:/tmp:/var/tmp:~chongo/pub:~/tmp"); will cause this function to open the first readable file it files while searching through these paths in order: - ./whey - /tmp/whey - /var/tmp/whey - ~chongo/pub/whey - ~/tmp/whey + ./whey + /tmp/whey + /var/tmp/whey + ~chongo/pub/whey + ~/tmp/whey IMPORTANT NOTE: @@ -49,13 +49,13 @@ DESCRIPTION This call open "./fizzbin" for writing if the current directory is writable, even if "./fizzbin" did not previously exist: - fpathopen("fizzbin", "r", ".:/tmp:/var/tmp:~chongo/pub:~/tmp"); + fpathopen("fizzbin", "r", ".:/tmp:/var/tmp:~chongo/pub:~/tmp"); This call will likely open (and create if needed) for appending, the file "/tmp/log" assuming that the user is not allowed to create files in the previous system directories: - fpathopen("log", "a", "/:/etc:/bin:/usr/bin:/tmp"); + fpathopen("log", "a", "/:/etc:/bin:/usr/bin:/tmp"); The CALCPATH search path is taken from the $CALCPATH environment variable or if no such variable exists, a compiled in default search @@ -69,49 +69,49 @@ DESCRIPTION A file can be opened for either reading, writing, or appending. The mode is controlled by the mode flag as follows: - allow allow file is positioned file(*) - mode reading writing truncated at mode - ---- ------- ------- --------- --------- ---- - r Y N N beginning text - rb Y N N beginning binary - r+ Y N N beginning text - r+b Y N N beginning binary - rb+ Y N N beginning binary + allow allow file is positioned file(*) + mode reading writing truncated at mode + ---- ------- ------- --------- --------- ---- + r Y N N beginning text + rb Y N N beginning binary + r+ Y N N beginning text + r+b Y N N beginning binary + rb+ Y N N beginning binary - w N Y Y beginning text - wb N Y Y beginning binary - w+ Y Y Y beginning text - w+b Y Y Y beginning binary - wb+ Y Y Y beginning binary + w N Y Y beginning text + wb N Y Y beginning binary + w+ Y Y Y beginning text + w+b Y Y Y beginning binary + wb+ Y Y Y beginning binary - a N Y Y end text - ab N Y Y end binary - a+ Y Y Y end text - a+b Y Y Y end binary - ab+ Y Y Y end binary + a N Y Y end text + ab N Y Y end binary + a+ Y Y Y end text + a+b Y Y Y end binary + ab+ Y Y Y end binary (*) NOTE on 'b' / binary/text mode: - The 'b' or fopen binary mode has no effect on POSIX / Linux - / Un*x-like systems. On those systems a text file is the - same as a binary file (as it should be for any modern-day - operating system). Adding 'b' to an fopen has no effect - and is ignored. + The 'b' or fopen binary mode has no effect on POSIX / Linux + / Un*x-like systems. On those systems a text file is the + same as a binary file (as it should be for any modern-day + operating system). Adding 'b' to an fopen has no effect + and is ignored. - Some non-POSIX systems such as MS Windows treat text files - and binary files differently. In text mode MS Windows consider - "\r\n" an end-of-line character. On an Apple MAC, the - text mode end-of-line character is "\r". + Some non-POSIX systems such as MS Windows treat text files + and binary files differently. In text mode MS Windows consider + "\r\n" an end-of-line character. On an Apple MAC, the + text mode end-of-line character is "\r". Names of files are subject to ~ expansion just like the C or - Korn shell. For example, the file name: + Korn shell. For example, the file name: - ~/lib/fizbin + ~/lib/fizbin refers to the file 'fizbin' under the directory lib located in your home directory. The file name: - ~chongo/was_here + ~chongo/was_here refers to the a file 'was_here' under the home directory of the user 'chongo'. @@ -136,25 +136,25 @@ EXAMPLE ; print fd "/etc/motd" ; fd - FILE 3 "/etc/motd" (reading, pos 0) + FILE 3 "/etc/motd" (reading, pos 0) ; fd2 = fpathopen("lucas.cal", "r") ; print fd2 "/usr/share/calc/lucas.cal" ; fd2 - FILE 4 "/usr/share/calc/lucas.cal" (reading, pos 0) + FILE 4 "/usr/share/calc/lucas.cal" (reading, pos 0) ; fd3 = fpathopen("randmprime.cal", "r", calcpath()) ; print fd3 "/usr/share/calc/randmprime.cal" ; fd3 - FILE 5 "/usr/share/calc/randmprime.cal" (reading, pos 0) + FILE 5 "/usr/share/calc/randmprime.cal" (reading, pos 0) ; fd4 = fpathopen("output", "w", "~/tmp:/tmp:/var/tmp") ; print fd4 "/home/chongo/tmp/output" ; fd4 - FILE 6 "/home/chongo/tmp/output" (writing, pos 0) + FILE 6 "/home/chongo/tmp/output" (writing, pos 0) ; !mkdir -p /tmp/log ; !touch /tmp/log/file @@ -162,7 +162,7 @@ EXAMPLE ; print logfile "/tmp/log/file" ; logfile - FILE 7 "/home/chongo/tmp/output" (writing, pos 0) + FILE 7 "/home/chongo/tmp/output" (writing, pos 0) ; badfile = fpathopen("no_such_file", "r") ; if (!isfile(badfile)) print "error #" errno(badfile) : \ @@ -188,7 +188,7 @@ SEE ALSO ## ## 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 +## 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 @@ -196,8 +196,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2006/05/07 23:56:04 -## File existed as early as: 2006 +## Under source code control: 2006/05/07 23:56:04 +## File existed as early as: 2006 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fprintf b/help/fprintf index 9b9576b..036caca 100644 --- a/help/fprintf +++ b/help/fprintf @@ -5,15 +5,15 @@ SYNOPSIS fprintf(fd, fmt, x_1, x_2, ...) TYPES - fd file - fmt string - x_1, x_2, ... any + fd file + fmt string + x_1, x_2, ... any - return null + return null DESCRIPTION This prints to the file fd exactly what would be printed to - the standard output by printf(fmt, x_1, x_2, ...). + the standard output by printf(fmt, x_1, x_2, ...). EXAMPLE ; fprintf(files(1), "h=%d, i=%d\n", 2, 3); @@ -108,7 +108,7 @@ SEE ALSO ## ## 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 +## 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 @@ -116,8 +116,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/03/12 22:50:41 -## File existed as early as: 1996 +## Under source code control: 1996/03/12 22:50:41 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fputc b/help/fputc index 1e380f2..767e18c 100644 --- a/help/fputc +++ b/help/fputc @@ -5,10 +5,10 @@ SYNOPSIS fputc(fd, data) TYPES - fd file - data str + fd file + data str - return nil + return nil DESCRIPTION This function writes the first character in data to the file @@ -19,7 +19,7 @@ EXAMPLE ; fputc(fd, "c") ; fd2 = fopen("/tmp/newfile", "r") ; fgetc(fd2) - "c" + "c" LIMITS fd must be associated with an open file @@ -39,7 +39,7 @@ SEE ALSO ## ## 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 +## 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 @@ -47,8 +47,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/03/04 11:33:20 -## File existed as early as: 1995 +## Under source code control: 1995/03/04 11:33:20 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fputs b/help/fputs index acf5eb7..91872c0 100644 --- a/help/fputs +++ b/help/fputs @@ -5,10 +5,10 @@ SYNOPSIS fputs(fd, s1, s2, ...) TYPES - fd file stream open for writing - s1, s2, ... strings + fd file stream open for writing + s1, s2, ... strings - return null value + return null value DESCRIPTION This function writes in succession the strings s1, s2, ..., to the @@ -19,7 +19,7 @@ EXAMPLE ; fputs(fd, "chongo was", " here\n") ; fd2 = fopen("/tmp/newfile", "r") ; fgetline(fd2) - "chongo was here" + "chongo was here" LIMITS The number of arguments is not to exceed 1024 @@ -39,7 +39,7 @@ SEE ALSO ## ## 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 +## 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 @@ -47,8 +47,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/03/04 11:33:20 -## File existed as early as: 1995 +## Under source code control: 1995/03/04 11:33:20 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fputstr b/help/fputstr index ec5cccf..ec58ac8 100644 --- a/help/fputstr +++ b/help/fputstr @@ -5,10 +5,10 @@ SYNOPSIS fputstr(fs, s_1, s_2, ...) TYPES - fs file stream open for writing - s_1, ... string + fs file stream open for writing + s_1, ... string - return null or error value + return null or error value DESCRIPTION If the stream cannot be written to or an argument is of the wrong @@ -22,13 +22,13 @@ EXAMPLE ; fputstr(f, "Alpha", "Beta") ; freopen(f, "r") ; fgetstr(f) - "Alpha" + "Alpha" ; fgetstr(f) - "Beta" + "Beta" ; fgetstr(f) ; fputstr(f, "Gamma") - Error E_FPUTSTR_3 + Error E_FPUTSTR_3 LIMITS none @@ -47,7 +47,7 @@ SEE ALSO ## ## 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 +## 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 @@ -55,8 +55,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:05:18 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:05:18 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/frac b/help/frac index 79a2119..540b6a8 100644 --- a/help/frac +++ b/help/frac @@ -11,9 +11,9 @@ TYPES For other x: - x number (real or complex), matrix + x number (real or complex), matrix - return number or matrix + return number or matrix DESCRIPTION If x is an integer, frac(x) returns zero. For other real values of x, @@ -49,7 +49,7 @@ SEE ALSO ## ## 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 +## 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 @@ -57,8 +57,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 03:30:59 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 03:30:59 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/free b/help/free index ababa03..c5cd1e3 100644 --- a/help/free +++ b/help/free @@ -5,14 +5,14 @@ SYNOPSIS free(a, b, ...) TYPES - a, b, ... any + a, b, ... any - return null value + return null value DESCRIPTION Those of the arguments a, b, ... that specify lvalues are assigned the null value, effectively freeing whatever memory is used to - store their current values. Other arguments are ignored. + store their current values. Other arguments are ignored. free(.) frees the current "old value". @@ -43,7 +43,7 @@ SEE ALSO ## ## 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 +## 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 @@ -51,8 +51,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/09/06 20:03:35 -## File existed as early as: 1997 +## Under source code control: 1997/09/06 20:03:35 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/freebernoulli b/help/freebernoulli index 88be063..8376dc7 100644 --- a/help/freebernoulli +++ b/help/freebernoulli @@ -5,7 +5,7 @@ SYNOPSIS freebernoulli() TYPES - return none + return none DESCRIPTION The memory used to store calculated bernoulli numbers is freed by @@ -31,7 +31,7 @@ SEE ALSO ## ## 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 +## 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 @@ -39,7 +39,7 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2000/07/13 -## File existed as early as: 2000 +## Under source code control: 2000/07/13 +## File existed as early as: 2000 ## -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/freeeuler b/help/freeeuler index c69c6d6..99746d2 100644 --- a/help/freeeuler +++ b/help/freeeuler @@ -5,7 +5,7 @@ SYNOPSIS freeeuler() TYPES - return none + return none DESCRIPTION The memory used to store calculated Euler numbers is freed by @@ -31,7 +31,7 @@ SEE ALSO ## ## 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 +## 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 @@ -39,7 +39,7 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2000/12/14 01:33:00 -## File existed as early as: 2000 +## Under source code control: 2000/12/14 01:33:00 +## File existed as early as: 2000 ## -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/freeglobals b/help/freeglobals index 85c1479..8d5a574 100644 --- a/help/freeglobals +++ b/help/freeglobals @@ -5,7 +5,7 @@ SYNOPSIS freeglobals() TYPES - return null value + return null value DESCRIPTION This function frees the memory used for the values of all global @@ -19,10 +19,10 @@ EXAMPLE Name Level Type ---- ----- ----- - a 1 real = 2 - a 0 real = 1 - b 0 list - c 0 matrix + a 1 real = 2 + a 0 real = 1 + b 0 list + c 0 matrix Number: 4 ; freeglobals() @@ -30,10 +30,10 @@ EXAMPLE Name Level Type ---- ----- ----- - a 1 null - a 0 null - b 0 null - c 0 null + a 1 null + a 0 null + b 0 null + c 0 null Number: 4 @@ -54,7 +54,7 @@ SEE ALSO ## ## 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 +## 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 @@ -62,8 +62,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/09/06 20:03:35 -## File existed as early as: 1997 +## Under source code control: 1997/09/06 20:03:35 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/freeredc b/help/freeredc index d88ee0a..d491b1e 100644 --- a/help/freeredc +++ b/help/freeredc @@ -5,7 +5,7 @@ SYNOPSIS freeredc() TYPES - return null value + return null value DESCRIPTION This function frees the memory used for any redc data currently stored by @@ -15,8 +15,8 @@ EXAMPLE ; a = rcin(10,27) ; b = rcin(10,15) ; show redc - 0 1 27 - 1 2 15 + 0 1 27 + 1 2 15 ; freeredc() ; show redc @@ -37,7 +37,7 @@ SEE ALSO ## ## 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 +## 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 @@ -45,8 +45,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/09/06 20:03:35 -## File existed as early as: 1997 +## Under source code control: 1997/09/06 20:03:35 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/freestatics b/help/freestatics index 84b5e31..15030ae 100644 --- a/help/freestatics +++ b/help/freestatics @@ -6,7 +6,7 @@ SYNOPSIS TYPES - return null value + return null value DESCRIPTION This function frees the memory used for the values of all unscoped @@ -21,19 +21,19 @@ EXAMPLE f() defined ; global a ; f(1) - 5 + 5 ; show statics Name Scopes Type ---- ------ ----- - a 1 0 real = 6 + a 1 0 real = 6 Number: 1 ; freestatics() ; f(1) - Error E_MUL + Error E_MUL ; strerror(.) - "Bad arguments for *" + "Bad arguments for *" LIMITS none @@ -52,7 +52,7 @@ SEE ALSO ## ## 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 +## 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 @@ -60,8 +60,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/09/06 20:03:35 -## File existed as early as: 1997 +## Under source code control: 1997/09/06 20:03:35 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/frem b/help/frem index 3bc57f8..08020e2 100644 --- a/help/frem +++ b/help/frem @@ -5,16 +5,16 @@ SYNOPSIS frem(x,y) TYPES - x integer - y integer + x integer + y integer - return non-negative integer + return non-negative integer DESCRIPTION If x and y are not zero and n is the largest non-negative integer for which y^n is a divisor of x, frem(x,y) returns abs(x/y^n). In particular, abs(x) is returned if x is not divisible by - y or if abs(y) = 1. If abs(y) > 1, frem(x,y) is the greatest + y or if abs(y) = 1. If abs(y) > 1, frem(x,y) is the greatest divisor of x not divisible by y. For all x, frem(x,0) is defined to equal abs(x). @@ -44,7 +44,7 @@ SEE ALSO ## ## 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 +## 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 @@ -52,8 +52,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 12:03:02 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 12:03:02 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/freopen b/help/freopen index 8d56ed2..67b48f4 100644 --- a/help/freopen +++ b/help/freopen @@ -5,11 +5,11 @@ SYNOPSIS freopen(fs, mode [,filename]) TYPES - fs open or closed file stream - mode one of the strings "r", "w", "a", "r+", "w+, "a+" - filename string + fs open or closed file stream + mode one of the strings "r", "w", "a", "r+", "w+, "a+" + filename string - return null or error value + return null or error value DESCRIPTION With two arguments, this function closes the file stream fs and @@ -18,17 +18,17 @@ DESCRIPTION With three arguments, fs, if open, is closed, and an attempt is made to open the file with the specified name and assign it to the stream - fs. A non-null value is returned only if the attempt fails. + fs. A non-null value is returned only if the attempt fails. EXAMPLE ; f = fopen("/tmp/junk", "w") ; fputs(f, "Leonard Euler") ; freopen(f, "r") ; fgets(f) - "Leonard Euler" + "Leonard Euler" ; !chmod u-w /tmp/junk ; freopen(f, "w") - Error E_FRAC + Error E_FRAC LIMITS none @@ -48,7 +48,7 @@ SEE ALSO ## ## 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 +## 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 @@ -56,8 +56,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:05:18 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:05:18 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fscan b/help/fscan index d4a666d..5d54133 100644 --- a/help/fscan +++ b/help/fscan @@ -5,10 +5,10 @@ SYNOPSIS fscan(fs, x_1, x_2, ..., x_n) TYPES - fs file stream open for reading - x_1, x_2, ... any + fs file stream open for reading + x_1, x_2, ... any - return integer + return integer DESCRIPTION Starting at the current position on fs and while values remain in the @@ -25,7 +25,7 @@ EXAMPLE ; fputs(f, "\t3+4\t\ta-2i d=a^2 'word'") ; rewind(f) ; fscan(f, a, b, , c) - 4 + 4 ; print a, b, c, d 7 a-2i word 49 @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:05:18 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:05:18 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fscanf b/help/fscanf index cd9d34b..0f1f818 100644 --- a/help/fscanf +++ b/help/fscanf @@ -5,11 +5,11 @@ SYNOPSIS fscanf(fs, fmt, x_1, x_2, ...) TYPES - fs file stream open for reading - fmt string - x_1, x_2, ... lvalues + fs file stream open for reading + fmt string + x_1, x_2, ... lvalues - return null, nonnegative integer, or error value + return null, nonnegative integer, or error value DESCRIPTION If the current position for fs is EOF, the null value is returned. @@ -31,16 +31,16 @@ DESCRIPTION '%'. A single '%' read from fmt is taken to indicate the beginning of a conversion specification field consisting in succession of: - an optional '*', - optional decimal digits, - one of 'c', 's', 'n', 'f', 'e', 'i' or a scanset specifier. + an optional '*', + optional decimal digits, + one of 'c', 's', 'n', 'f', 'e', 'i' or a scanset specifier. A scanset specifier starts with '[' and an optional '^', then an optional ']', then optional other characters, and ends with ']'. If any other sequence of characters follows the '%', characters before the first exceptional character (which could be the terminating null character of the fmt string) are ignored, e.g. the sequence " %*3d " does - the same as " d ". If there is no '*' at the beginning of the specifier, + the same as " d ". If there is no '*' at the beginning of the specifier, and the list x_1, x_2, ... has not been exhausted, a value will be assigned to the next lvalue in the list; if no lvalue remains, the reading of fs stops and the function returns the number @@ -68,7 +68,7 @@ DESCRIPTION The cases 'f', 'e', 'r', 'i' may be considered to indicate expectation of floating-point, exponential, ratio, or integer representation of the - number to be read. For example, 'i' + number to be read. For example, 'i' might be taken to suggest a number like +2345; 'r' might suggest a representation like -27/49; 'e' might suggest a representation like 1.24e-7; 'f' might suggest a representation like 27.145. However, there @@ -80,9 +80,9 @@ DESCRIPTION for + and -, and for * and /. Also acceptable is a trailing i to indicate an imaginary number. For example the expression - 2+3/4*7i+3.15e7 + 2+3/4*7i+3.15e7 - would be interpreted as for an ordinary evaluation. A decimal fraction + would be interpreted as for an ordinary evaluation. A decimal fraction may have more than one dot: dots after the first, which is taken to be the decimal point, are ignored. Thus "12.3..45e6.7" is interpreted as if it were "12.345e67". @@ -102,23 +102,23 @@ EXAMPLE ; rewind(f) ; fscanf(f, "Alpha Gamma") ; fgets(f) - "Beta Gamma" + "Beta Gamma" ; rewind(f) ; fscanf(f, "%5c", a) - 1 + 1 ; a - "Alpha" + "Alpha" ; fgets(f) - " Beta Gamma" + " Beta Gamma" ; rewind(f) ; fscanf(f, "%3c%s%[^m]", a, b, c) - 3 + 3 ; print a, b Alp ha ; print c Beta Ga ; fgets(f) - "mma" + "mma" LIMITS The number of arguments is not to exceed 1024. @@ -137,7 +137,7 @@ SEE ALSO ## ## 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 +## 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 @@ -145,8 +145,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:05:18 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:05:18 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fseek b/help/fseek index d78ee05..6001d8e 100644 --- a/help/fseek +++ b/help/fseek @@ -5,11 +5,11 @@ SYNOPSIS fseek(fd, offset [, whence]) TYPES - fd open file stream - pos integer - whence 0, 1 or 2, defaulting to 0 + fd open file stream + pos integer + whence 0, 1 or 2, defaulting to 0 - return null or error value + return null or error value DESCRIPTION This function sets the file position indicator for the stream by @@ -34,25 +34,25 @@ EXAMPLE ; fputs(fd, "0123456789abcdef") ; freopen(fd, "r") ; fsize(fd) - 16 + 16 ; fseek(fd, 5) ; fgets(fd) - "56789abcdef" + "56789abcdef" ; fseek(fd, 0) ; fscanf(fd, "%*5c") - 0 + 0 ; fseek(fd, 5, 1) ; fgets(fd) - "abcdef" + "abcdef" ; ftell(fd) - 16 + 16 ; fseek(fd, -5, 2) ; fgets(fd) - "bcdef" + "bcdef" ; fseek(fd, -2) - System error 22 + System error 22 ; ftell(fd) - 16 + 16 The results for the last four lines may be different for different systems. @@ -74,7 +74,7 @@ SEE ALSO ## ## 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 +## 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 @@ -82,8 +82,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/03/04 11:33:20 -## File existed as early as: 1995 +## Under source code control: 1995/03/04 11:33:20 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/fsize b/help/fsize index 8333ef7..dff2b27 100644 --- a/help/fsize +++ b/help/fsize @@ -5,9 +5,9 @@ SYNOPSIS fsize(fd) TYPES - fd file + fd file - return int + return int DESCRIPTION This function returns the number of bytes in a file. When at @@ -17,7 +17,7 @@ DESCRIPTION EXAMPLE ; fd = fopen("/etc/motd", "r") ; fsize(fd) - 784 + 784 LIMITS fd must be associated with an open file @@ -37,7 +37,7 @@ SEE ALSO ## ## 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 +## 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 @@ -45,8 +45,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/03/04 11:33:20 -## File existed as early as: 1995 +## Under source code control: 1995/03/04 11:33:20 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ftell b/help/ftell index 2cf8dfe..263219e 100644 --- a/help/ftell +++ b/help/ftell @@ -5,9 +5,9 @@ SYNOPSIS ftell(fd) TYPES - fd open file stream + fd open file stream - return non-negative integer or error value + return non-negative integer or error value DESCRIPTION This function attempts to return the current value of the file position @@ -21,21 +21,21 @@ EXAMPLE ; fd = fopen("/tmp/curds", "w") ; fputs(fd, "0123456789") ; ftell(fd) - 10 + 10 ; fputs(fd, "abcdef") ; ftell(fd) - 16 + 16 ; fseek(fd, 20, 0) ; ftell(fd) - 20 + 20 ; fputs(fd, "01234") ; ftell(fd) - 25 + 25 ; freopen(fd, "r") ; fscanf(fd, "%*5c") - 0 + 0 ; ftell(fd) - 5 + 5 LIMITS none @@ -54,7 +54,7 @@ SEE ALSO ## ## 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 +## 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 @@ -62,8 +62,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/03/04 11:33:21 -## File existed as early as: 1995 +## Under source code control: 1995/03/04 11:33:21 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/funclist.sed b/help/funclist.sed index 9fc9933..39c04c6 100644 --- a/help/funclist.sed +++ b/help/funclist.sed @@ -1,9 +1,9 @@ s/VALUE/int/ -s/NUMBER[ ]*\*/int / +s/NUMBER[ ]*\*/int / s/NUMBER/int/ s/STRINGHEAD/int/ s/\(".*",.*,.*\),.*,.*,.*,.*,/\1, 0, 0, {.null = NULL}, {.null = NULL},/ -s/[ ][ ]*$// +s/[ ][ ]*$// p ## Copyright (C) 1999,2023 Landon Curt Noll @@ -14,7 +14,7 @@ p ## ## 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 +## 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 @@ -22,8 +22,8 @@ p ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/10 01:33:06 -## File existed as early as: 1995 +## Under source code control: 1995/07/10 01:33:06 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/g2d b/help/g2d index fcbdc83..c84a46d 100644 --- a/help/g2d +++ b/help/g2d @@ -5,10 +5,10 @@ SYNOPSIS g2d(x [,eps]) TYPES - x number (real or complex) - eps eps value is ignored + x number (real or complex) + eps eps value is ignored - return number + return number DESCRIPTION Given x gradians, return the equivalent number of degrees. @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/07 12:04:28 -## File existed as early as: 2021 +## Under source code control: 2021/09/07 12:04:28 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/g2gm b/help/g2gm index 5aa4fd2..32a0a67 100644 --- a/help/g2gm +++ b/help/g2gm @@ -5,12 +5,12 @@ SYNOPSIS g2gm(grads, g, m [,rnd]) TYPES - grads real - g null-or-real-valued lvalue with assign-to permission - m null-or-real-valued lvalue with assign-to permission - rnd nonnegative integer, defaults to config("mod") + grads real + g null-or-real-valued lvalue with assign-to permission + m null-or-real-valued lvalue with assign-to permission + rnd nonnegative integer, defaults to config("mod") - return mod(grads, 400, rnd) + return mod(grads, 400, rnd) DESCRIPTION Convert grads gradians into g gradians, and m minutes. @@ -18,7 +18,7 @@ DESCRIPTION The return value is a normalized number of gradians, and is equivalent to the following: - return_value = mod(grads, 400, rnd); + return_value = mod(grads, 400, rnd); The argument rnd, if not given, defaults to config("mod"). For more information on the effects of rnd, see "help mod". @@ -31,7 +31,7 @@ DESCRIPTION The value g will be set as if the following were used: - g = int(return_value); + g = int(return_value); For some rounding modes, g will be an integer in the interval [0, 400). For other rounding modes, g will be an integer in the interval (-400, 0]. @@ -41,9 +41,9 @@ DESCRIPTION The value m will be set as if the following were used: - tmp = return_value - g; - m = tmp * 60; - free(tmp); + tmp = return_value - g; + m = tmp * 60; + free(tmp); For some rounding modes, m will be a real value in the interval [0, 60). For other rounding modes, m will be a real value in the interval (-60, 0]. @@ -52,7 +52,7 @@ DESCRIPTION The following shows relationship between the return value and the resulting g, and m values: - return_value == g + m/60; + return_value == g + m/60; EXAMPLE ; ## if args are undefined, pre-declare them or assign them as args @@ -100,7 +100,7 @@ SEE ALSO ## ## 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 +## 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 @@ -108,8 +108,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/25 17:24:51 -## File existed as early as: 2021 +## Under source code control: 2021/09/25 17:24:51 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/g2gms b/help/g2gms index f188684..1baed38 100644 --- a/help/g2gms +++ b/help/g2gms @@ -5,13 +5,13 @@ SYNOPSIS g2gms(grads, g, m, s [,rnd]) TYPES - grads real - g null-or-real-valued lvalue with assign-to permission - m null-or-real-valued lvalue with assign-to permission - s null-or-real-valued lvalue with assign-to permission - rnd nonnegative integer, defaults to config("mod") + grads real + g null-or-real-valued lvalue with assign-to permission + m null-or-real-valued lvalue with assign-to permission + s null-or-real-valued lvalue with assign-to permission + rnd nonnegative integer, defaults to config("mod") - return mod(grads, 400, rnd) + return mod(grads, 400, rnd) DESCRIPTION Convert grads gradians into g gradians, m minutes, and s seconds. @@ -19,7 +19,7 @@ DESCRIPTION The return value is a normalized number of gradians, and is equivalent to the following: - return_value = mod(grads, 400, rnd); + return_value = mod(grads, 400, rnd); The argument rnd, if not given, defaults to config("mod"). For more information on the effects of rnd, see "help mod". @@ -32,7 +32,7 @@ DESCRIPTION The value g will be set as if the following were used: - g = int(return_value); + g = int(return_value); For some rounding modes, g will be an integer in the interval [0, 400). For other rounding modes, g will be an integer in the interval (-400, 0]. @@ -42,10 +42,10 @@ DESCRIPTION The value m will be set as if the following were used: - tmp = return_value - g; - tmp_m = tmp * 60; - free(tmp); - m = int(tmp_m); + tmp = return_value - g; + tmp_m = tmp * 60; + free(tmp); + m = int(tmp_m); For some rounding modes, m will be an integer in the interval [0, 60). For other rounding modes, m will be an integer in the interval (-60, 0]. @@ -55,10 +55,10 @@ DESCRIPTION The value s will be set as if the following were used: - tmp = tmp_m - m; - free(tmp_m); - s = tmp * 60; - free(tmp); + tmp = tmp_m - m; + free(tmp_m); + s = tmp * 60; + free(tmp); For some rounding modes, s will be a real value in the interval [0, 60). For other rounding modes, s will be a real value in the interval (-60, 0]. @@ -67,7 +67,7 @@ DESCRIPTION The following shows relationship between the return value and the resulting g, m, and s values: - return_value == g + m/60 + s/3600; + return_value == g + m/60 + s/3600; EXAMPLE ; ## if args are undefined, pre-declare them or assign them as args @@ -115,7 +115,7 @@ SEE ALSO ## ## 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 +## 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 @@ -123,8 +123,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/25 17:24:51 -## File existed as early as: 2021 +## Under source code control: 2021/09/25 17:24:51 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/g2r b/help/g2r index 0768392..9b1940f 100644 --- a/help/g2r +++ b/help/g2r @@ -5,10 +5,10 @@ SYNOPSIS g2r(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Given x gradians, return the equivalent number of radians. @@ -44,7 +44,7 @@ SEE ALSO ## ## 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 +## 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 @@ -52,8 +52,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/07 12:04:28 -## File existed as early as: 2021 +## Under source code control: 2021/09/07 12:04:28 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/gcd b/help/gcd index fe6d0de..4a768fa 100644 --- a/help/gcd +++ b/help/gcd @@ -7,7 +7,7 @@ SYNOPSIS TYPES x1, x2, ... rational number - return rational number + return rational number DESCRIPTION If at least one xi is nonzero, gcd(x1, x2, ...) is the @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:26 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:26 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/gcdrem b/help/gcdrem index f09cd6a..251da01 100644 --- a/help/gcdrem +++ b/help/gcdrem @@ -5,10 +5,10 @@ SYNOPSIS gcdrem(x, y) TYPES - x integer - y integer + x integer + y integer - return non-negative integer + return non-negative integer DESCRIPTION @@ -29,13 +29,13 @@ PROPERTIES For fixed nonzero x, gcdrem(x,y) is periodic with period abs(x). gcdrem(x,y) = 1 if and only if every prime divisor of x - is a divisor of y. + is a divisor of y. If x is not zero, gcdrem(x,y) == abs(x) if and only if gcd(x,y) = 1. If y is not zero and p_1, p_2, ..., p_k are the prime divisors of y, - gcdrem(x,y) = frem(...(frem(frem(x,p_1),p_2)...,p_k) + gcdrem(x,y) = frem(...(frem(frem(x,p_1),p_2)...,p_k) EXAMPLE ; print gcdrem(6,15), gcdrem(15,6), gcdrem(72,6), gcdrem(6,72) @@ -61,7 +61,7 @@ SEE ALSO ## ## 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 +## 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 @@ -69,8 +69,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 12:03:02 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 12:03:02 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/gd b/help/gd index 2731766..a86f0bc 100644 --- a/help/gd +++ b/help/gd @@ -5,10 +5,10 @@ SYNOPSIS gd(z [,eps]) TYPES - z number (real or complex) - eps 0 < real < 1, defaults to epsilon() + z number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number or "Log of zero or infinity" error value + return number or "Log of zero or infinity" error value DESCRIPTION Calculate the Gudermannian of z to a multiple of eps with errors in @@ -18,11 +18,11 @@ DESCRIPTION gd(z) is usually defined initially for real z by one of the formulae - gd(z) = 2 * atan(exp(z)) - pi/2 + gd(z) = 2 * atan(exp(z)) - pi/2 - = 2 * atan(tanh(z/2)) + = 2 * atan(tanh(z/2)) - = atan(sinh(z)), + = atan(sinh(z)), or as the integral from 0 to z of (1/cosh(t))dt. For complex z, the principal branch, approximated by gd(z, eps), has the cut: @@ -32,7 +32,7 @@ DESCRIPTION If z = x + y*i and abs(y) < pi/2, gd(z) is given by - gd(z) = atan(sinh(x)/cos(y)) + i * atanh(sin(y)/cosh(x)). + gd(z) = atan(sinh(x)/cos(y)) + i * atanh(sin(y)/cosh(x)). EXAMPLE ; print gd(1, 1e-5), gd(1, 1e-10), gd(1, 1e-15) @@ -58,7 +58,7 @@ SEE ALSO ## ## 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 +## 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 @@ -66,8 +66,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/09/06 20:03:35 -## File existed as early as: 1997 +## Under source code control: 1997/09/06 20:03:35 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/getenv b/help/getenv index 3673717..2b379c1 100644 --- a/help/getenv +++ b/help/getenv @@ -5,9 +5,9 @@ SYNOPSIS getenv(env) TYPES - env str + env str - return str or nil + return str or nil DESCRIPTION This function returns the value of the environment variable named by @@ -15,15 +15,15 @@ DESCRIPTION EXAMPLE ; putenv("name", "value") - 0 + 0 ; getenv("name") - "value" + "value" ; putenv("name=val2") - 0 + 0 ; getenv("name") - "val2" + "val2" ; isnull(getenv("unknown")) - 1 + 1 LIMITS none @@ -42,7 +42,7 @@ SEE ALSO ## ## 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 +## 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 @@ -50,8 +50,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/09 03:48:57 -## File existed as early as: 1995 +## Under source code control: 1995/07/09 03:48:57 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/gms2g b/help/gms2g index 06cfc3c..55aeda3 100644 --- a/help/gms2g +++ b/help/gms2g @@ -6,19 +6,19 @@ SYNOPSIS gms2g(d, m, s [,rnd]) TYPES - d real - m real - s real (default to 0) - rnd nonnegative integer, defaults to config("mod") + d real + m real + s real (default to 0) + rnd nonnegative integer, defaults to config("mod") - return gradians + return gradians DESCRIPTION Convert gradians, m minutes, and s seconds returning gradians. The return value in gradians, is equivalent to the following: - mod(d + m/60 + s/4000, 400, rnd); + mod(d + m/60 + s/4000, 400, rnd); Depending on the rounding mode, the return could be a real value in the interval [0, 400) or a real value in the interval (-400, 0]. @@ -67,7 +67,7 @@ SEE ALSO ## ## 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 +## 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 @@ -75,8 +75,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/25 17:24:51 -## File existed as early as: 2021 +## Under source code control: 2021/09/25 17:24:51 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/h2hm b/help/h2hm index 2bc4a3d..ad00a51 100644 --- a/help/h2hm +++ b/help/h2hm @@ -5,12 +5,12 @@ SYNOPSIS h2hm(hours, h, m [,rnd]) TYPES - hours real - h null-or-real-valued lvalue with assign-to permission - m null-or-real-valued lvalue with assign-to permission - rnd nonnegative integer, defaults to config("mod") + hours real + h null-or-real-valued lvalue with assign-to permission + m null-or-real-valued lvalue with assign-to permission + rnd nonnegative integer, defaults to config("mod") - return mod(hours, 24, rnd) + return mod(hours, 24, rnd) DESCRIPTION Convert hours hours into h hours, and m minutes. @@ -18,7 +18,7 @@ DESCRIPTION The return value is a normalized number of hours, and is equivalent to the following: - return_value = mod(hours, 24, rnd); + return_value = mod(hours, 24, rnd); The argument rnd, if not given, defaults to config("mod"). For more information on the effects of rnd, see "help mod". @@ -31,7 +31,7 @@ DESCRIPTION The value h will be set as if the following were used: - h = int(return_value); + h = int(return_value); For some rounding modes, h will be an integer in the interval [0, 24). For other rounding modes, h will be an integer in the interval (-24, 0]. @@ -41,9 +41,9 @@ DESCRIPTION The value m will be set as if the following were used: - tmp = return_value - h; - m = tmp * 60; - free(tmp); + tmp = return_value - h; + m = tmp * 60; + free(tmp); For some rounding modes, m will be a real value in the interval [0, 60). For other rounding modes, m will be a real value in the interval (-60, 0]. @@ -52,7 +52,7 @@ DESCRIPTION The following shows relationship between the return value and the resulting h, and m values: - return_value == h + m/60; + return_value == h + m/60; EXAMPLE ; ## if args are undefined, pre-declare them or assign them as args @@ -100,7 +100,7 @@ SEE ALSO ## ## 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 +## 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 @@ -108,8 +108,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/25 17:24:51 -## File existed as early as: 2021 +## Under source code control: 2021/09/25 17:24:51 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/h2hms b/help/h2hms index 3f544d9..c4c57b6 100644 --- a/help/h2hms +++ b/help/h2hms @@ -5,13 +5,13 @@ SYNOPSIS h2hms(hours, h, m, s [,rnd]) TYPES - hours real - h null-or-real-valued lvalue with assign-to permission - m null-or-real-valued lvalue with assign-to permission - s null-or-real-valued lvalue with assign-to permission - rnd nonnegative integer, defaults to config("mod") + hours real + h null-or-real-valued lvalue with assign-to permission + m null-or-real-valued lvalue with assign-to permission + s null-or-real-valued lvalue with assign-to permission + rnd nonnegative integer, defaults to config("mod") - return mod(hours, 24, rnd) + return mod(hours, 24, rnd) DESCRIPTION Convert hours hours into h hours, m minutes, and s seconds. @@ -19,7 +19,7 @@ DESCRIPTION The return value is a normalized number of hours, and is equivalent to the following: - return_value = mod(hours, 24, rnd); + return_value = mod(hours, 24, rnd); The argument rnd, if not given, defaults to config("mod"). For more information on the effects of rnd, see "help mod". @@ -32,7 +32,7 @@ DESCRIPTION The value h will be set as if the following were used: - h = int(return_value); + h = int(return_value); For some rounding modes, h will be an integer in the interval [0, 24). For other rounding modes, h will be an integer in the interval (-24, 0]. @@ -42,10 +42,10 @@ DESCRIPTION The value m will be set as if the following were used: - tmp = return_value - h; - tmp_m = tmp * 60; - free(tmp); - m = int(tmp_m); + tmp = return_value - h; + tmp_m = tmp * 60; + free(tmp); + m = int(tmp_m); For some rounding modes, m will be an integer in the interval [0, 60). For other rounding modes, m will be an integer in the interval (-60, 0]. @@ -55,10 +55,10 @@ DESCRIPTION The value s will be set as if the following were used: - tmp = tmp_m - m; - free(tmp_m); - s = tmp * 60; - free(tmp); + tmp = tmp_m - m; + free(tmp_m); + s = tmp * 60; + free(tmp); For some rounding modes, s will be a real value in the interval [0, 60). For other rounding modes, s will be a real value in the interval (-60, 0]. @@ -67,7 +67,7 @@ DESCRIPTION The following shows relationship between the return value and the resulting h, m, and s values: - return_value == h + m/60 + s/3600; + return_value == h + m/60 + s/3600; EXAMPLE ; ## if args are undefined, pre-declare them or assign them as args @@ -115,7 +115,7 @@ SEE ALSO ## ## 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 +## 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 @@ -123,8 +123,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/25 17:24:51 -## File existed as early as: 2021 +## Under source code control: 2021/09/25 17:24:51 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/hacovercos b/help/hacovercos index 9546ab5..1a86262 100644 --- a/help/hacovercos +++ b/help/hacovercos @@ -5,10 +5,10 @@ SYNOPSIS hacovercos(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the half coversed trigonometric cosine of x to a multiple of eps with error less in @@ -16,8 +16,8 @@ DESCRIPTION This function is sometimes called hacvc, or hacovercosine, is equivalent to: - hacovercos(x) = covercos(x) / 2 - hacovercos(x) = (1 + sin(x)) / 2 + hacovercos(x) = covercos(x) / 2 + hacovercos(x) = (1 + sin(x)) / 2 EXAMPLE ; print hacovercos(1/2), hacovercos(5/7), hacovercos(42/7) @@ -55,14 +55,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -72,7 +72,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -80,8 +80,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/24 11:10:08 -## File existed as early as: 2023 +## Under source code control: 2023/09/24 11:10:08 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/hacoversin b/help/hacoversin index 8a6debf..a9267e5 100644 --- a/help/hacoversin +++ b/help/hacoversin @@ -5,10 +5,10 @@ SYNOPSIS hacoversin(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the half coversed trigonometric sine of x to a multiple of eps with error less in @@ -16,8 +16,8 @@ DESCRIPTION This function is sometimes called hacovers, or hacvs, is equivalent to: - hacoversin(x) = coversin(x) / 2 - hacoversin(x) = (1 - sin(x)) / 2 + hacoversin(x) = coversin(x) / 2 + hacoversin(x) = (1 - sin(x)) / 2 EXAMPLE ; print hacoversin(1/2), hacoversin(5/7), hacoversin(42/7) @@ -55,14 +55,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -72,7 +72,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -80,8 +80,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/24 11:11:11 -## File existed as early as: 2023 +## Under source code control: 2023/09/24 11:11:11 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/hash b/help/hash index c81c956..50a1fdf 100644 --- a/help/hash +++ b/help/hash @@ -5,9 +5,9 @@ SYNOPSIS hash(x_1 [, x_2, x_3, ...]) TYPES - x_1, x_1, ... any + x_1, x_1, ... any - return integer v, 0 <= v < 2^32 + return integer v, 0 <= v < 2^32 DESCRIPTION Returns a hash value for one or more values of arbitrary types. @@ -18,25 +18,25 @@ DESCRIPTION takes into account more abstract concepts such as data types. WARNING: Use of FNV-0 is NOT recommended for general purposes. - Calc uses FNV-0 for internal objects such as associative - arrays as well as other internal processes. Calc - maintains the use of FNV-0 for backwards compatibility. + Calc uses FNV-0 for internal objects such as associative + arrays as well as other internal processes. Calc + maintains the use of FNV-0 for backwards compatibility. - You should use the FNV-1a hash instead!!!!! + You should use the FNV-1a hash instead!!!!! Use the fnv() builtin function for general quick, non-cryptographic hash purposes. See also: - http://www.isthe.com/chongo/tech/comp/fnv/ + http://www.isthe.com/chongo/tech/comp/fnv/ information about the Fowler/Noll/Vo (FNV) hash. EXAMPLE ; a = isqrt(2e1000); s = "xyz"; ; hash(a,s) - 2378490456 + 2378490456 LIMITS The number of arguments is not to exceed 1024. @@ -55,7 +55,7 @@ SEE ALSO ## ## 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 +## 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 @@ -63,8 +63,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/24 11:12:16 -## File existed as early as: 2023 +## Under source code control: 2023/09/24 11:12:16 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/havercos b/help/havercos index dc85e15..861fdc2 100644 --- a/help/havercos +++ b/help/havercos @@ -5,10 +5,10 @@ SYNOPSIS havercos(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the half versed trigonometric cosine of x to a multiple of eps with error less in @@ -16,8 +16,8 @@ DESCRIPTION This function is sometimes called haverc, or haverconsine, is equivalent to: - havercos(x) = vercos(x) / 2 - havercos(x) = (1 + cos(x)) / 2 + havercos(x) = vercos(x) / 2 + havercos(x) = (1 + cos(x)) / 2 EXAMPLE ; print havercos(1/2), havercos(5/7), havercos(42/7) @@ -55,14 +55,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -72,7 +72,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -80,8 +80,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/24 11:13:28 -## File existed as early as: 2023 +## Under source code control: 2023/09/24 11:13:28 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/haversin b/help/haversin index c885d64..69066ec 100644 --- a/help/haversin +++ b/help/haversin @@ -5,10 +5,10 @@ SYNOPSIS haversin(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the half versed trigonometric sine of x to a multiple of eps with error less in @@ -16,8 +16,8 @@ DESCRIPTION This function is sometimes called havers, is equivalent to: - haversin(x) = versin(x) / 2 - haversin(x) = (1 - cos(x)) / 2 + haversin(x) = versin(x) / 2 + haversin(x) = (1 - cos(x)) / 2 EXAMPLE ; print haversin(1/2), haversin(5/7), haversin(42/7) @@ -55,14 +55,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -72,7 +72,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -80,8 +80,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/24 11:14:48 -## File existed as early as: 2023 +## Under source code control: 2023/09/24 11:14:48 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/head b/help/head index a28c82c..552d933 100644 --- a/help/head +++ b/help/head @@ -5,10 +5,10 @@ SYNOPSIS head(x, y) TYPES - x list - y int + x list + y int - return list + return list DESCRIPTION If 0 <= y <= size(x), head(x,y) returns a list of size y whose @@ -29,15 +29,15 @@ EXAMPLE ; head(A, 2) list (2 members, 2 nonzero): - [[0]] = 2 - [[1]] = 3 + [[0]] = 2 + [[1]] = 3 ; head(A, -2) list (3 members, 3 nonzero): - [[0]] = 2 - [[1]] = 3 - [[2]] = 5 + [[0]] = 2 + [[1]] = 3 + [[2]] = 5 LIMITS none @@ -56,7 +56,7 @@ SEE ALSO ## ## 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 +## 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 @@ -64,8 +64,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/10 02:09:30 -## File existed as early as: 1995 +## Under source code control: 1995/07/10 02:09:30 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/help b/help/help index 3b8894f..f77b3a6 100644 --- a/help/help +++ b/help/help @@ -1,63 +1,63 @@ For more information while running calc, type help followed by one of the following topics: - topic description - ----- ----------- - intro introduction to calc - overview overview of calc - calc calc man page, how to invoke the calc command + topic description + ----- ----------- + intro introduction to calc + overview overview of calc + calc calc man page, how to invoke the calc command - assoc using associations - builtin builtin functions - command top level commands - config configuration parameters - custom information about the custom builtin interface - define how to define functions - environment how environment variables affect calc - errorcodes calc generated error codes - expression expression sequences - file using files - history command history - interrupt how interrupts are handled - list using lists - mat using matrices - obj user defined data types - operator math, relational, logic and variable access operators - resource standard calc resource files - script using calc shell scripts - statement flow control and declaration statements - types builtin data types - unexpected unexpected syntax/usage surprises for C programmers - variable variables and variable declarations + assoc using associations + builtin builtin functions + command top level commands + config configuration parameters + custom information about the custom builtin interface + define how to define functions + environment how environment variables affect calc + errorcodes calc generated error codes + expression expression sequences + file using files + history command history + interrupt how interrupts are handled + list using lists + mat using matrices + obj user defined data types + operator math, relational, logic and variable access operators + resource standard calc resource files + script using calc shell scripts + statement flow control and declaration statements + types builtin data types + unexpected unexpected syntax/usage surprises for C programmers + variable variables and variable declarations - bindings input & history character bindings - custom_cal information about custom calc resource files - libcalc using the arbitrary precision routines in a C program - new_custom information about how to add new custom functions - cscript info on the calc shell scripts supplied with calc + bindings input & history character bindings + custom_cal information about custom calc resource files + libcalc using the arbitrary precision routines in a C program + new_custom information about how to add new custom functions + cscript info on the calc shell scripts supplied with calc - archive where to get the latest versions of calc - bugs known bugs and mis-features - changes recent changes to calc - contrib how to contribute scripts, code or custom functions - todo list of priority action items for calc - wishlist wish list of future enhancements of calc + archive where to get the latest versions of calc + bugs known bugs and mis-features + changes recent changes to calc + contrib how to contribute scripts, code or custom functions + todo list of priority action items for calc + wishlist wish list of future enhancements of calc - credit who wrote calc and who helped - copyright calc copyright and the GNU LGPL - copying details on the Calc GNU Lesser General Public License - copying-lgpl calc GNU Lesser General Public License text - questions how to ask simple general question about calc - release on calc versions and releases + credit who wrote calc and who helped + copyright calc copyright and the GNU LGPL + copying details on the Calc GNU Lesser General Public License + copying-lgpl calc GNU Lesser General Public License text + questions how to ask simple general question about calc + release on calc versions and releases - help this file - full all of the above (in the above order) + help this file + full all of the above (in the above order) For example: help usage -will print the calc command usage information. One can obtain calc help +will print the calc command usage information. One can obtain calc help without invoking any startup code by running calc as follows: calc -q help topic @@ -94,7 +94,7 @@ for details of the -m mode. The help command is able to display installed help files for custom builtin functions. However, if the custom name is the same as a standard help -file, the standard help file will be displayed instead. The custom help +file, the standard help file will be displayed instead. The custom help builtin should be used to directly access the custom help file. For example, the custom help builtin has the same name as the standard @@ -133,7 +133,7 @@ calc help files. ## ## 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 +## 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 @@ -141,8 +141,8 @@ calc help files. ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:20 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:20 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/highbit b/help/highbit index 1967b3c..681a9bb 100644 --- a/help/highbit +++ b/help/highbit @@ -5,13 +5,13 @@ SYNOPSIS highbit(x) TYPES - x nonzero integer + x nonzero integer - return integer + return integer DESCRIPTION If x is a nonzero integer, highbit(x) returns the index of the - highest bit in the binary representation of abs(x). Equivalently, + highest bit in the binary representation of abs(x). Equivalently, highbit(x) = n if 2^n <= abs(x) < 2^(n + 1); the binary representation of x then has n + 1 digits. @@ -36,7 +36,7 @@ SEE ALSO ## ## 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 +## 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 @@ -44,8 +44,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/03 10:40:02 -## File existed as early as: 1995 +## Under source code control: 1995/10/03 10:40:02 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/history b/help/history index 94832a2..127024d 100644 --- a/help/history +++ b/help/history @@ -11,7 +11,7 @@ Command history for future recall. Before the return key is typed, the current line can be edited - using emacs-like editing commands. As examples, ^A moves to + using emacs-like editing commands. As examples, ^A moves to the beginning of the line, ^F moves forwards through the line, backspace removes characters from the line, and ^K kills the rest of the line. @@ -24,7 +24,7 @@ Command history Typing h lists all of the commands in the command history and numbers the lines. The most recently executed line is always - number 1, the next most recent number 2, and so on. The numbering + number 1, the next most recent number 2, and so on. The numbering for a particular command therefore changes as lines are entered. Typing a number at the beginning of a line followed by g @@ -51,13 +51,13 @@ Command history The actual keys used for editing are defined in a bindings file, usually called /usr/local/lib/calc/bindings. Changing the entries - in this file will change the key bindings used for editing. If the + in this file will change the key bindings used for editing. If the file is not readable, then a message will be output and command line editing is disabled. In this case you can only edit each line as provided by the terminal driver in the operating system. A shell command can be executed by typing '!cmd', where cmd - is the command to execute. If cmd is not given, then a shell + is the command to execute. If cmd is not given, then a shell command level is started. ## Copyright (C) 1999 Landon Curt Noll @@ -68,7 +68,7 @@ Command history ## ## 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 +## 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 @@ -76,8 +76,8 @@ Command history ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:20 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:20 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/hmean b/help/hmean index 372792a..39409d2 100644 --- a/help/hmean +++ b/help/hmean @@ -5,9 +5,9 @@ SYNOPSIS hmean(x_1, x_2, ...) TYPES - x_1, ... arithmetic or list + x_1, ... arithmetic or list - return determined by types of arguments, or null + return determined by types of arguments, or null DESCRIPTION The null value is returned if there are no arguments. @@ -16,7 +16,7 @@ DESCRIPTION required operations are defined, hmean(x_1, x_2, ...) returns the value of: - n/(inverse(x_1) + inverse(x_2) + ... + inverse(x_n)). + n/(inverse(x_1) + inverse(x_2) + ... + inverse(x_n)). If an argument x_i is a list as defined by list(y_1, ..., y_m) this is treated as if in (x_1, x_2, ...), x_i is replaced by @@ -45,7 +45,7 @@ SEE ALSO ## ## 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 +## 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 @@ -53,8 +53,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 03:30:59 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 03:30:59 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/hms2h b/help/hms2h index ef0b6cd..39ab072 100644 --- a/help/hms2h +++ b/help/hms2h @@ -6,19 +6,19 @@ SYNOPSIS hms2h(h, m, s [,rnd]) TYPES - h real - m real - s real (defaults to 0) - rnd nonnegative integer, defaults to config("mod") + h real + m real + s real (defaults to 0) + rnd nonnegative integer, defaults to config("mod") - return hours + return hours DESCRIPTION Convert hours, m minutes, and s seconds returning hours. The return value in hours, is equivalent to the following: - mod(h + m/60 + s/3600, 24, rnd); + mod(h + m/60 + s/3600, 24, rnd); Depending on the rounding mode, the return could be a real value in the interval [0, 24) or a real value in the interval (-24, 0]. @@ -67,7 +67,7 @@ SEE ALSO ## ## 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 +## 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 @@ -75,8 +75,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/25 17:24:51 -## File existed as early as: 2021 +## Under source code control: 2021/09/25 17:24:51 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/hnrmod b/help/hnrmod index 74135fe..057cce7 100644 --- a/help/hnrmod +++ b/help/hnrmod @@ -5,23 +5,23 @@ SYNOPSIS hnrmod(v, h, n, r) TYPES - v integer - h integer - n integer - r integer + v integer + h integer + n integer + r integer - return integer + return integer DESCRIPTION Compute the value: - v % (h * 2^n +r) + v % (h * 2^n +r) where: - h > 0 - n > 0 - r == -1, 0 or 1 + h > 0 + n > 0 + r == -1, 0 or 1 This builtin in faster than the standard mod in that is makes use of shifts and additions when h == 1. When h > 1, a division by h @@ -50,7 +50,7 @@ SEE ALSO ## ## 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 +## 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 @@ -58,8 +58,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/07/02 07:10:43 -## File existed as early as: 1997 +## Under source code control: 1997/07/02 07:10:43 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/hypot b/help/hypot index f29b9c4..24f3e6e 100644 --- a/help/hypot +++ b/help/hypot @@ -5,10 +5,10 @@ SYNOPSIS hypot(x, y [,eps]) TYPES - x, y real - eps nonzero real, defaults to epsilon() + x, y real + eps nonzero real, defaults to epsilon() - return real + return real DESCRIPTION Returns sqrt(x^2 + y^2) to the nearest multiple of eps. @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:26 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:26 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ilog b/help/ilog index a559543..cfbcd27 100644 --- a/help/ilog +++ b/help/ilog @@ -7,10 +7,10 @@ SYNOPSIS ilogn(x, b) TYPES - x nonzero real - b integer greater than 1 + x nonzero real + b integer greater than 1 - return integer + return integer DESCRIPTION Returns the greatest integer n for which b^n <= abs(x). @@ -42,7 +42,7 @@ SEE ALSO ## ## 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 +## 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 @@ -50,8 +50,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:45 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:45 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ilog10 b/help/ilog10 index f309e21..f0233de 100644 --- a/help/ilog10 +++ b/help/ilog10 @@ -5,9 +5,9 @@ SYNOPSIS ilog10(x) TYPES - x nonzero real + x nonzero real - return integer + return integer DESCRIPTION Returns the greatest integer n for which 10^n <= x. @@ -33,7 +33,7 @@ SEE ALSO ## ## 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 +## 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 @@ -41,8 +41,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/03 10:40:02 -## File existed as early as: 1995 +## Under source code control: 1995/10/03 10:40:02 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ilog2 b/help/ilog2 index 7d0b353..dbcea49 100644 --- a/help/ilog2 +++ b/help/ilog2 @@ -5,9 +5,9 @@ SYNOPSIS ilog2(x) TYPES - x nonzero real + x nonzero real - return integer + return integer DESCRIPTION Returns the greatest integer n for which 2^n <= abs(x). @@ -33,7 +33,7 @@ SEE ALSO ## ## 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 +## 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 @@ -41,8 +41,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/03 10:40:02 -## File existed as early as: 1995 +## Under source code control: 1995/10/03 10:40:02 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/im b/help/im index 597f537..8d39617 100644 --- a/help/im +++ b/help/im @@ -5,9 +5,9 @@ SYNOPSIS im(x) TYPES - x real or complex + x real or complex - return real + return real DESCRIPTION If x = u + v * 1i where u and v are real, im(x) returns v. @@ -33,7 +33,7 @@ SEE ALSO ## ## 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 +## 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 @@ -41,8 +41,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:26 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:26 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/indices b/help/indices index 9b8f544..e9d15b7 100644 --- a/help/indices +++ b/help/indices @@ -5,10 +5,10 @@ SYNOPSIS indices(V, index) TYPES - V matrix or association - index integer + V matrix or association + index integer - return list with up to 4 elements + return list with up to 4 elements DESCRIPTION For 0 <= index < size(V), indices(V, index) returns list(i_0, i_1, ...) @@ -17,7 +17,7 @@ DESCRIPTION For other values of index, a null value is returned. This function can be useful for determining those elements for which - the indices satisfy some condition. This is particularly so for + the indices satisfy some condition. This is particularly so for associations since these have no simple relation between the double-bracket index and the single-bracket indices, which may be non-integer numbers or strings or other types of value. The @@ -30,9 +30,9 @@ EXAMPLE ; indices(M, 11) list (3 elements, 2 nonzero): - [[0]] = 0 - [[1]] = 2 - [[2]] = 2 + [[0]] = 0 + [[1]] = 2 + [[2]] = 2 ; A = assoc(); @@ -42,10 +42,10 @@ EXAMPLE ; indices(A, search(A, "primes")) list (4 elements, 4 nonzero): - [[0]] = 2 - [[1]] = 3 - [[2]] = 5 - [[3]] = 7 + [[0]] = 2 + [[1]] = 3 + [[2]] = 5 + [[3]] = 7 LIMITS abs(index) < 2^31 @@ -65,7 +65,7 @@ SEE ALSO ## ## 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 +## 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 @@ -73,8 +73,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1999/11/16 08:02:03 -## File existed as early as: 1999 +## Under source code control: 1999/11/16 08:02:03 +## File existed as early as: 1999 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/inputlevel b/help/inputlevel index 03e447f..0bd7b41 100644 --- a/help/inputlevel +++ b/help/inputlevel @@ -5,16 +5,16 @@ SYNOPSIS inputlevel() TYPES - return nonnegative integer + return nonnegative integer DESCRIPTION This function returns the input level at which it is called. When calc starts, it is at level zero. The level is increased by 1 each time execution starts of a read file command or a call to - eval(S) for some expression S which evaluates to a string. It + eval(S) for some expression S which evaluates to a string. It decreases by 1 when a file being read reaches EOF or a string being eval-ed reaches '\0', or earlier if a quit statement is - encountered at top calculation-level in the file or string. It + encountered at top calculation-level in the file or string. It decreases to zero if an abort statement is encountered at any function-level in the file or string. If a quit or abort statement is encountered at top calculation-level at top input-level, @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1999/10/31 06:01:21 -## File existed as early as: 1999 +## Under source code control: 1999/10/31 06:01:21 +## File existed as early as: 1999 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/insert b/help/insert index 3982c4b..061c4fb 100644 --- a/help/insert +++ b/help/insert @@ -5,11 +5,11 @@ SYNOPSIS insert(x, y, z_0, z_1, ...) TYPES - x lvalue whose value is a list - y int - z_0, ... any + x lvalue whose value is a list + y int + z_0, ... any - return null value + return null value DESCRIPTION If after evaluation of z_0, z_1, ..., x is a list with contents @@ -67,7 +67,7 @@ SEE ALSO ## ## 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 +## 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 @@ -75,8 +75,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 03:13:18 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 03:13:18 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/int b/help/int index 58407b2..7d1d96b 100644 --- a/help/int +++ b/help/int @@ -11,9 +11,9 @@ TYPES For other x: - x number (real or complex), matrix + x number (real or complex), matrix - return number or matrix + return number or matrix DESCRIPTION If x is an integer, int(x) returns x. For other real values of x, @@ -48,7 +48,7 @@ SEE ALSO ## ## 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 +## 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 @@ -56,8 +56,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/30 00:57:18 -## File existed as early as: 1994 +## Under source code control: 1994/09/30 00:57:18 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/interrupt b/help/interrupt index 5af3ebf..8b13496 100644 --- a/help/interrupt +++ b/help/interrupt @@ -9,12 +9,12 @@ Interrupts You can generate the SIGINT signal multiple times if necessary, and each time the calculator will abort the calculation at a more - risky place within the calculation. Each new interrupt prints a + risky place within the calculation. Each new interrupt prints a message of the form: - [Abort level n] + [Abort level n] - where n ranges from 1 to 3. For n equal to 1, the calculator will + where n ranges from 1 to 3. For n equal to 1, the calculator will abort calculations at the next statement boundary specified by an ABORT opcode as described below. For n equal to 2, the calculator will abort calculations at the next opcode boundary. For n equal to 3, @@ -42,24 +42,24 @@ ABORT opcodes the calculation is never completed and to stop it, an interruption (on many systems, by ctrl-C) will be necessary. - ; config("trace", 8), - ; define f(x) {local s; while (x) {s += x--} return s} - 0: DEBUG line 2 - 2: PARAMADDR x - 4: JUMPZ 19 - 6: DEBUG line 2 - 8: LOCALADDR s - 10: DUPLICATE - 11: PARAMADDR x - 13: POSTDEC - 14: POP - 15: ADD - 16: ASSIGNPOP - 17: JUMP 2 - 19: DEBUG line 2 - 21: LOCALADDR s - 23: RETURN - f(x) defined + ; config("trace", 8), + ; define f(x) {local s; while (x) {s += x--} return s} + 0: DEBUG line 2 + 2: PARAMADDR x + 4: JUMPZ 19 + 6: DEBUG line 2 + 8: LOCALADDR s + 10: DUPLICATE + 11: PARAMADDR x + 13: POSTDEC + 14: POP + 15: ADD + 16: ASSIGNPOP + 17: JUMP 2 + 19: DEBUG line 2 + 21: LOCALADDR s + 23: RETURN + f(x) defined (The line number following DEBUG refers to the line in the file from which the definition is read.) If an attempt is made to @@ -68,38 +68,38 @@ ABORT opcodes {s += x--} loop. In interactive mode, with ^C indicating input of ctrl-C, the displayed output is as in: - ; f(-1) - ^C - [Abort level 1] - "f": line 2: Calculation aborted at statement boundary + ; f(-1) + ^C + [Abort level 1] + "f": line 2: Calculation aborted at statement boundary The DEBUG opcodes are disabled by nonzero config("trace") & 2. Changing config("trace") to achieve this, and defining g(x) with the same definition as for f(x) gives: - ; define g(x) {local s; while (x) {s += x--} return s} - 0: PARAMADDR x - 2: JUMPZ 15 - 4: LOCALADDR s - 6: DUPLICATE - 7: PARAMADDR x - 9: POSTDEC - 10: POP - 11: ADD - 12: ASSIGNPOP - 13: JUMP 0 - 15: LOCALADDR s - 17: RETURN - g(x) defined + ; define g(x) {local s; while (x) {s += x--} return s} + 0: PARAMADDR x + 2: JUMPZ 15 + 4: LOCALADDR s + 6: DUPLICATE + 7: PARAMADDR x + 9: POSTDEC + 10: POP + 11: ADD + 12: ASSIGNPOP + 13: JUMP 0 + 15: LOCALADDR s + 17: RETURN + g(x) defined If g(-1) is called, two interrupts are necessary, as in: - ; g(-1) - ^C - [Abort level 1] - ^C - [Abort level 2] - "g": Calculation aborted in opcode + ; g(-1) + ^C + [Abort level 1] + ^C + [Abort level 2] + "g": Calculation aborted in opcode ## Copyright (C) 1999-2006 David I. Bell, Landon Curt Noll and Ernest Bowen ## @@ -109,7 +109,7 @@ ABORT opcodes ## ## 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 +## 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 @@ -117,8 +117,8 @@ ABORT opcodes ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:21 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:21 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/intro b/help/intro index effb24c..7326a91 100644 --- a/help/intro +++ b/help/intro @@ -2,36 +2,36 @@ What is calc? Calc is an interactive calculator which provides for easy large numeric calculations, but which also can be easily programmed - for difficult or long calculations. It can accept a command line + for difficult or long calculations. It can accept a command line argument, in which case it executes that single command and exits. Otherwise, it enters interactive mode. In this mode, it accepts commands one at a time, processes them, and displays the answers. In the simplest case, commands are simply expressions which are - evaluated. For example, the following line can be input: + evaluated. For example, the following line can be input: - 3 * (4 + 1) + 3 * (4 + 1) and the calculator will print: - 15 + 15 Calc has the usual collection of arithmetic operators +, -, /, * as well as ^ (exponentiation), % (modulus) and // (integer divide). For example: - 3 * 19^43 - 1 + 3 * 19^43 - 1 will produce: - 29075426613099201338473141505176993450849249622191102976 + 29075426613099201338473141505176993450849249622191102976 Notice that calc values can be very large. For example: - 2^23209-1 + 2^23209-1 will print: - 402874115778988778181873329071 ... many digits ... 3779264511 + 402874115778988778181873329071 ... many digits ... 3779264511 The special '.' symbol (called dot), represents the result of the last command expression, if any. This is of great use when a series @@ -39,62 +39,62 @@ What is calc? and the last result needs to be redisplayed. For example, the above result (2^23209-1) can be modified by typing: - . % (2^127-1) + . % (2^127-1) and the calculator will print: - 39614081257132168796771975167 + 39614081257132168796771975167 For more complex calculations, variables can be used to save the intermediate results. For example, the result of adding 7 to the previous result can be saved by typing: - curds = 15 - whey = 7 + 2*curds + curds = 15 + whey = 7 + 2*curds Functions can be used in expressions. There are a great number of pre-defined functions. For example, the following will calculate the factorial of the value of 'whey': - fact(whey) + fact(whey) and the calculator prints: - 13763753091226345046315979581580902400000000 + 13763753091226345046315979581580902400000000 The calculator also knows about complex numbers, so that typing: - (2+3i) * (4-3i) - cos(.) + (2+3i) * (4-3i) + cos(.) will print: - 17+6i - -55.50474777265624667147+193.9265235748927986537i + 17+6i + -55.50474777265624667147+193.9265235748927986537i The calculator can calculate transcendental functions, and accept and display numbers in real or exponential format. For example, typing: - config("display", 70) - epsilon(1e-70) - sin(1) + config("display", 70) + epsilon(1e-70) + sin(1) prints: - 0.8414709848078965066525023216302989996225630607983710656727517099919104 + 0.8414709848078965066525023216302989996225630607983710656727517099919104 Calc can output values in terms of fractions, octal or hexadecimal. For example: - config("mode", "fraction"), - (17/19)^23 - base(16), - (19/17)^29 + config("mode", "fraction"), + (17/19)^23 + base(16), + (19/17)^29 will print: - 19967568900859523802559065713/257829627945307727248226067259 - 0x9201e65bdbb801eaf403f657efcf863/0x5cd2e2a01291ffd73bee6aa7dcf7d1 + 19967568900859523802559065713/257829627945307727248226067259 + 0x9201e65bdbb801eaf403f657efcf863/0x5cd2e2a01291ffd73bee6aa7dcf7d1 All numbers are represented as fractions with arbitrarily large numerators and denominators which are always reduced to lowest terms. @@ -116,43 +116,43 @@ What is calc? Many useful built-in mathematical functions are available. Use the: - help builtin + help builtin command to list them. You can also define your own functions by using the 'define' keyword, followed by a function declaration very similar to C. - define f2(n) - { - local ans; + define f2(n) + { + local ans; - ans = 1; - while (n > 1) - ans *= (n -= 2); - return ans; - } + ans = 1; + while (n > 1) + ans *= (n -= 2); + return ans; + } Thus the input: - f2(79) + f2(79) will produce: - 1009847364737869270905302433221592504062302663202724609375 + 1009847364737869270905302433221592504062302663202724609375 Functions which only need to return a simple expression can be defined using an equals sign, as in the example: - define sc(a,b) = a^3 + b^3 + define sc(a,b) = a^3 + b^3 Thus the input: - sc(31, 61) + sc(31, 61) will produce: - 256772 + 256772 Variables in functions can be defined as either 'global', 'local', or 'static'. Global variables are common to all functions and the @@ -164,7 +164,7 @@ What is calc? For more information about the calc language and features, try: - help overview + help overview In particular, check out the other help functions listed in the overview help file. @@ -177,7 +177,7 @@ What is calc? ## ## 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 +## 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 @@ -185,8 +185,8 @@ What is calc? ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:21 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:21 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/inverse b/help/inverse index 3c3c692..41ddcde 100644 --- a/help/inverse +++ b/help/inverse @@ -11,9 +11,9 @@ TYPES For non-object x: - x nonzero number (real or complex) or nonsingular matrix + x nonzero number (real or complex) or nonsingular matrix - return number or matrix + return number or matrix DESCRIPTION For real or complex x, inverse(x) returns the value of 1/x. @@ -31,10 +31,10 @@ EXAMPLE ; print inverse(A) mat [2,2] (4 elements, 4 nonzero): - [0,0] = -7 - [0,1] = 3 - [1,0] = 5 - [1,1] = -2 + [0,0] = -7 + [0,1] = 3 + [1,0] = 5 + [1,1] = -2 LIMITS none @@ -55,7 +55,7 @@ SEE ALSO ## ## 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 +## 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 @@ -63,8 +63,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/03/12 23:10:01 -## File existed as early as: 1996 +## Under source code control: 1996/03/12 23:10:01 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/iroot b/help/iroot index fba5dd5..00380d9 100644 --- a/help/iroot +++ b/help/iroot @@ -5,10 +5,10 @@ SYNOPSIS iroot(x, n) TYPES - x nonnegative real - n positive integer + x nonnegative real + n positive integer - return nonnegative real + return nonnegative real DESCRIPTION Return the greatest integer v for which v^n <= x. @@ -34,7 +34,7 @@ SEE ALSO ## ## 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 +## 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 @@ -42,8 +42,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:45 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:45 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isalnum b/help/isalnum index 7d4b6c5..e075c86 100644 --- a/help/isalnum +++ b/help/isalnum @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2013/09/01 18:10:53 -## File existed as early as: 2013 +## Under source code control: 2013/09/01 18:10:53 +## File existed as early as: 2013 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isalpha b/help/isalpha index 7195950..9925b99 100644 --- a/help/isalpha +++ b/help/isalpha @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2013/09/01 18:10:53 -## File existed as early as: 2013 +## Under source code control: 2013/09/01 18:10:53 +## File existed as early as: 2013 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isassoc b/help/isassoc index 37ad234..c0bd739 100644 --- a/help/isassoc +++ b/help/isassoc @@ -5,9 +5,9 @@ SYNOPSIS isassoc(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION Determine if x is an association. This function will return 1 if x is @@ -39,7 +39,7 @@ SEE ALSO ## ## 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 +## 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 @@ -47,8 +47,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:27 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:27 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isatty b/help/isatty index edf6757..59f5042 100644 --- a/help/isatty +++ b/help/isatty @@ -5,9 +5,9 @@ SYNOPSIS isatty(fd) TYPES - fd any + fd any - return int + return int DESCRIPTION This function returns 1 if fd is associated with a tty, 0 otherwise. @@ -15,10 +15,10 @@ DESCRIPTION EXAMPLE ; print isatty(files(0)), isatty(files(1)), isatty(files(2)) - 1 1 1 + 1 1 1 ; fd = fopen("/dev/null", "r") ; isatty(fd) - 0 + 0 LIMITS none @@ -42,7 +42,7 @@ SEE ALSO ## ## 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 +## 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 @@ -50,8 +50,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/09 03:49:34 -## File existed as early as: 1995 +## Under source code control: 1995/07/09 03:49:34 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isblk b/help/isblk index 0d8bc67..df95fa0 100644 --- a/help/isblk +++ b/help/isblk @@ -5,30 +5,30 @@ SYNOPSIS isblk(val) TYPES - val any + val any - return 0, 1, or 2 + return 0, 1, or 2 DESCRIPTION isblk(val) returns 1 if val is an unnamed block, 2 if val is a named block, 0 otherwise. Note that a named block B retains its name after its data block is - freed by rmblk(B). That a named block B has null data block may be + freed by rmblk(B). That a named block B has null data block may be tested using sizeof(B); this returns 0 if and only if the memory has been freed. EXAMPLE ; A = blk() ; isblk(A) - 1 + 1 ; B = blk("beta") ; isblk(B) - 2 + 2 ; isblk(3) - 0 + 0 LIMITS none @@ -51,7 +51,7 @@ SEE ALSO ## ## 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 +## 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 @@ -59,8 +59,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/04/06 03:03:23 -## File existed as early as: 1997 +## Under source code control: 1997/04/06 03:03:23 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/iscntrl b/help/iscntrl index eb0f1b3..434ca1c 100644 --- a/help/iscntrl +++ b/help/iscntrl @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2013/09/01 18:10:53 -## File existed as early as: 2013 +## Under source code control: 2013/09/01 18:10:53 +## File existed as early as: 2013 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isconfig b/help/isconfig index 8ba1079..53bbe9b 100644 --- a/help/isconfig +++ b/help/isconfig @@ -5,9 +5,9 @@ SYNOPSIS isconfig(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION Determine if x is a configuration state. This function will return @@ -39,7 +39,7 @@ SEE ALSO ## ## 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 +## 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 @@ -47,8 +47,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/11 05:09:41 -## File existed as early as: 1995 +## Under source code control: 1995/11/11 05:09:41 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isdefined b/help/isdefined index 27aa9cc..4349255 100644 --- a/help/isdefined +++ b/help/isdefined @@ -5,9 +5,9 @@ SYNOPSIS isdefined(str) TYPES - str string + str string - return 0, 1, or 2 + return 0, 1, or 2 DESCRIPTION isdefined(str) returns 1 if str is the name of a builtin function, @@ -15,20 +15,20 @@ DESCRIPTION EXAMPLE ; isdefined("abs") - 1 + 1 ; isdefined("fun") - 0 + 0 ; define fun() { } fun() defined ; isdefined("fun") - 2 + 2 ; undefine fun ; isdefined("fun") - 0 + 0 LIMITS none @@ -51,7 +51,7 @@ SEE ALSO ## ## 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 +## 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 @@ -59,8 +59,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/04/05 14:10:17 -## File existed as early as: 1997 +## Under source code control: 1997/04/05 14:10:17 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isdigit b/help/isdigit index 54f32ef..a272b57 100644 --- a/help/isdigit +++ b/help/isdigit @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2013/09/01 18:10:53 -## File existed as early as: 2013 +## Under source code control: 2013/09/01 18:10:53 +## File existed as early as: 2013 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/iserror b/help/iserror index 0730388..1d3f471 100644 --- a/help/iserror +++ b/help/iserror @@ -5,9 +5,9 @@ SYNOPSIS iserror(x) TYPES - x any + x any - return zero or positive integer < 32768 + return zero or positive integer < 32768 DESCRIPTION If x is not an error value, zero is returned. @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 03:30:59 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 03:30:59 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/iseven b/help/iseven index a1223e5..a95d22b 100644 --- a/help/iseven +++ b/help/iseven @@ -5,12 +5,12 @@ SYNOPSIS iseven(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION - Determine if x is an even integer. This function will return 1 if x is + Determine if x is an even integer. This function will return 1 if x is even integer, 0 otherwise. EXAMPLE @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:27 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:27 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isfile b/help/isfile index 8db2a4a..37fa653 100644 --- a/help/isfile +++ b/help/isfile @@ -5,9 +5,9 @@ SYNOPSIS isfile(x) TYPES - x any + x any - return int + return int DESCRIPTION Determine if x is a file. This function will return 1 if x is @@ -38,7 +38,7 @@ SEE ALSO ## ## 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 +## 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 @@ -46,8 +46,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:27 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:27 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isgraph b/help/isgraph index f662059..cd803e8 100644 --- a/help/isgraph +++ b/help/isgraph @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2013/09/01 18:10:53 -## File existed as early as: 2013 +## Under source code control: 2013/09/01 18:10:53 +## File existed as early as: 2013 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ishash b/help/ishash index 228d868..208600f 100644 --- a/help/ishash +++ b/help/ishash @@ -5,15 +5,15 @@ SYNOPSIS ishash(x) TYPES - x any + x any - return integer + return integer DESCRIPTION The value returned by ishash(x) is: - 0 if x is not a hash state, - 2 if x is a sha1 hash state, + 0 if x is not a hash state, + 2 if x is a sha1 hash state, EXAMPLE ; a = 1; b = sha1(0); c = sha1(a) @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/11 05:09:41 -## File existed as early as: 1995 +## Under source code control: 1995/11/11 05:09:41 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isident b/help/isident index 7564a44..7ebb736 100644 --- a/help/isident +++ b/help/isident @@ -5,9 +5,9 @@ SYNOPSIS isident(m) TYPES - m any + m any - return int + return int DESCRIPTION This function returns 1 if m is an 2 dimensional identity matrix, @@ -16,7 +16,7 @@ DESCRIPTION EXAMPLE ; mat x[3,3] = {1,0,0,0,1,0,0,0,1}; ; isident(x) - 1 + 1 LIMITS none @@ -39,7 +39,7 @@ SEE ALSO ## ## 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 +## 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 @@ -47,8 +47,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/09 18:25:36 -## File existed as early as: 1995 +## Under source code control: 1995/07/09 18:25:36 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isint b/help/isint index 10bde38..4fe7e46 100644 --- a/help/isint +++ b/help/isint @@ -5,9 +5,9 @@ SYNOPSIS isint(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION Determine if x is an integer. This function will return 1 if x is @@ -41,7 +41,7 @@ SEE ALSO ## ## 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 +## 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 @@ -49,8 +49,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:27 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:27 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/islist b/help/islist index 0618f42..de69aae 100644 --- a/help/islist +++ b/help/islist @@ -5,9 +5,9 @@ SYNOPSIS islist(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION Determine if x is a list. This function will return 1 if x is @@ -41,7 +41,7 @@ SEE ALSO ## ## 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 +## 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 @@ -49,8 +49,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 03:13:19 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 03:13:19 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/islower b/help/islower index d1a3fde..72d3744 100644 --- a/help/islower +++ b/help/islower @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2013/09/01 18:10:53 -## File existed as early as: 2013 +## Under source code control: 2013/09/01 18:10:53 +## File existed as early as: 2013 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ismat b/help/ismat index 4897fd1..4ddef1c 100644 --- a/help/ismat +++ b/help/ismat @@ -5,12 +5,12 @@ SYNOPSIS ismat(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION - Determine if x is a matrix. This function will return 1 if x is + Determine if x is a matrix. This function will return 1 if x is a matrix, 0 otherwise. EXAMPLE @@ -39,7 +39,7 @@ SEE ALSO ## ## 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 +## 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 @@ -47,8 +47,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:28 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:28 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ismult b/help/ismult index 871c11e..a1098e2 100644 --- a/help/ismult +++ b/help/ismult @@ -5,16 +5,16 @@ SYNOPSIS ismult(x, y) TYPES - x real - y real + x real + y real - return int + return int DESCRIPTION Determine if x exactly divides y. If there exists an integer k such that: - x == y * k + x == y * k then return 1, otherwise return 0. @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:28 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:28 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isnull b/help/isnull index 92b0c00..3d66def 100644 --- a/help/isnull +++ b/help/isnull @@ -5,9 +5,9 @@ SYNOPSIS isnull(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION Determine if x is a null value. This function will return 1 if x is @@ -38,7 +38,7 @@ SEE ALSO ## ## 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 +## 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 @@ -46,8 +46,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:28 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:28 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isnum b/help/isnum index 3481e13..63e1d88 100644 --- a/help/isnum +++ b/help/isnum @@ -5,12 +5,12 @@ SYNOPSIS isnum(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION - Determine if x is a numeric value. This function will return 1 if x + Determine if x is a numeric value. This function will return 1 if x is a a numeric value, 0 otherwise. EXAMPLE @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:28 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:28 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isobj b/help/isobj index 79494cb..3ad1b32 100644 --- a/help/isobj +++ b/help/isobj @@ -5,9 +5,9 @@ SYNOPSIS isobj(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION Determine if x is an object. This function will return 1 if x is @@ -39,7 +39,7 @@ SEE ALSO ## ## 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 +## 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 @@ -47,8 +47,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:29 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:29 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isobjtype b/help/isobjtype index 49531bc..a274c29 100644 --- a/help/isobjtype +++ b/help/isobjtype @@ -5,9 +5,9 @@ SYNOPSIS isobjtype(str) TYPES - str string + str string - return 0 or 1 + return 0 or 1 DESCRIPTION isobjtype(str) returns 1 or 0 according as an object type with name @@ -15,11 +15,11 @@ DESCRIPTION EXAMPLE ; isobjtype("xy") - 0 + 0 ; obj xy {x, y} ; isobjtype("xy") - 1 + 1 LIMITS none @@ -42,7 +42,7 @@ SEE ALSO ## ## 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 +## 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 @@ -50,8 +50,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/04/05 14:10:17 -## File existed as early as: 1997 +## Under source code control: 1997/04/05 14:10:17 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isodd b/help/isodd index 5e1ae5a..6744a58 100644 --- a/help/isodd +++ b/help/isodd @@ -5,9 +5,9 @@ SYNOPSIS isodd(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION Determine if x is an odd integer. This function will return 1 if x is @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:29 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:29 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isprime b/help/isprime index ac5ca89..a3e52a0 100644 --- a/help/isprime +++ b/help/isprime @@ -5,13 +5,13 @@ SYNOPSIS isprime(x [,err]) TYPES - x int - err int + x int + err int - return int + return int DESCRIPTION - Determine if x is is a small prime. This function will return + Determine if x is is a small prime. This function will return 1 if x is a small prime. If x is even, this function will return 0. If x is negative or a small composite (non-prime), 0 will be returned. @@ -39,10 +39,10 @@ EXAMPLE -1 2 0 LIMITS - err not given and (y is even or y < 2^32) + err not given and (y is even or y < 2^32) LINK LIBRARY - FLAG zisprime(ZVALUE x) (return 1 if prime, 0 not prime, -1 if >= 2^32) + FLAG zisprime(ZVALUE x) (return 1 if prime, 0 not prime, -1 if >= 2^32) SEE ALSO factor, lfactor, nextcand, nextprime, prevcand, prevprime, @@ -56,7 +56,7 @@ SEE ALSO ## ## 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 +## 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 @@ -64,8 +64,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:29 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:29 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isprint b/help/isprint index 13e9537..d7c9003 100644 --- a/help/isprint +++ b/help/isprint @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2013/09/01 18:10:53 -## File existed as early as: 2013 +## Under source code control: 2013/09/01 18:10:53 +## File existed as early as: 2013 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isptr b/help/isptr index 1790a1e..b0d32d9 100644 --- a/help/isptr +++ b/help/isptr @@ -5,18 +5,18 @@ SYNOPSIS isptr(x) TYPES - x any + x any - return 0, 1, 2, 3, or 4 + return 0, 1, 2, 3, or 4 DESCRIPTION isptr(x) returns: - 0 if x is a not pointer - 1 if x is an octet-pointer - 2 if x is a value-pointer - 3 if x is a string-pointer - 4 if x is a number-pointer + 0 if x is a not pointer + 1 if x is an octet-pointer + 2 if x is a value-pointer + 3 if x is a string-pointer + 4 if x is a number-pointer Pointers are initially defined by using the address (&) operator with an "addressable" value; currently, these are octets, lvalues, @@ -48,7 +48,7 @@ SEE ALSO ## ## 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 +## 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 @@ -56,8 +56,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/09/06 20:03:35 -## File existed as early as: 1997 +## Under source code control: 1997/09/06 20:03:35 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ispunct b/help/ispunct index 900987d..d0e135b 100644 --- a/help/ispunct +++ b/help/ispunct @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2013/09/01 18:10:53 -## File existed as early as: 2013 +## Under source code control: 2013/09/01 18:10:53 +## File existed as early as: 2013 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isqrt b/help/isqrt index 555b9c1..56d4552 100644 --- a/help/isqrt +++ b/help/isqrt @@ -5,9 +5,9 @@ SYNOPSIS isqrt(x) TYPES - x nonnegative real + x nonnegative real - return nonnegative real + return nonnegative real DESCRIPTION Return the greatest integer n for which n^2 <= x. @@ -33,7 +33,7 @@ SEE ALSO ## ## 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 +## 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 @@ -41,8 +41,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:45 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:45 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isrand b/help/isrand index 9a9415a..09d6118 100644 --- a/help/isrand +++ b/help/isrand @@ -5,9 +5,9 @@ SYNOPSIS isrand(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION Determine if x is an subtractive 100 pseudo-random number @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/11 05:09:41 -## File existed as early as: 1995 +## Under source code control: 1995/11/11 05:09:41 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/israndom b/help/israndom index bd2994d..a18939e 100644 --- a/help/israndom +++ b/help/israndom @@ -5,9 +5,9 @@ SYNOPSIS israndom(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION Determine if x is a Blum-Blum-Shub pseudo-random number generator state. @@ -39,7 +39,7 @@ SEE ALSO ## ## 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 +## 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 @@ -47,8 +47,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/11 05:09:41 -## File existed as early as: 1995 +## Under source code control: 1995/11/11 05:09:41 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isreal b/help/isreal index 15dde26..f5e8587 100644 --- a/help/isreal +++ b/help/isreal @@ -5,9 +5,9 @@ SYNOPSIS isreal(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION Determine if x is a real value. This function will return 1 if x @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:30 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:30 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isrel b/help/isrel index 1612431..9a89467 100644 --- a/help/isrel +++ b/help/isrel @@ -5,13 +5,13 @@ SYNOPSIS isrel(x, y) TYPES - x int - y int + x int + y int - return int + return int DESCRIPTION - Determine if x and y are relatively prime. If gcd(x,y) == 1, then + Determine if x and y are relatively prime. If gcd(x,y) == 1, then return 1, otherwise return 0. EXAMPLE @@ -42,7 +42,7 @@ SEE ALSO ## ## 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 +## 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 @@ -50,8 +50,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:30 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:30 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/issimple b/help/issimple index 797f22d..ca31da9 100644 --- a/help/issimple +++ b/help/issimple @@ -5,9 +5,9 @@ SYNOPSIS issimple(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION Determine if x is a simple type. This function will return 1 if x @@ -48,7 +48,7 @@ SEE ALSO ## ## 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 +## 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 @@ -56,8 +56,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:30 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:30 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isspace b/help/isspace index f52ce96..b2cdfc5 100644 --- a/help/isspace +++ b/help/isspace @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2013/09/01 18:10:53 -## File existed as early as: 2013 +## Under source code control: 2013/09/01 18:10:53 +## File existed as early as: 2013 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/issq b/help/issq index aee795d..ae95632 100644 --- a/help/issq +++ b/help/issq @@ -5,25 +5,25 @@ SYNOPSIS issq(x) TYPES - x real + x real - return int + return int DESCRIPTION - Determine if x is a square. If there exists integers a, b such that: + Determine if x is a square. If there exists integers a, b such that: - x == a^2 / b^2 (b != 0) + x == a^2 / b^2 (b != 0) return 1, otherwise return 0. Note that issq() works on rational values, so: - issq(25/16) == 1 + issq(25/16) == 1 If you want to test for prefect square integers, you need to exclude non-integer values before you test: - isint(curds) && issq(curds) + isint(curds) && issq(curds) EXAMPLE ; print issq(25), issq(3), issq(0) @@ -53,7 +53,7 @@ SEE ALSO ## ## 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 +## 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 @@ -61,8 +61,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:31 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:31 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isstr b/help/isstr index fb4d05f..e918fc1 100644 --- a/help/isstr +++ b/help/isstr @@ -5,12 +5,12 @@ SYNOPSIS isstr(x) TYPES - x any, &any + x any, &any - return int + return int DESCRIPTION - Determine if x is a string. This function will return 1 if x is + Determine if x is a string. This function will return 1 if x is a string, 0 otherwise. EXAMPLE @@ -37,7 +37,7 @@ SEE ALSO ## ## 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 +## 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 @@ -45,8 +45,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:31 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:31 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/istype b/help/istype index a6d860f..08a03d1 100644 --- a/help/istype +++ b/help/istype @@ -5,10 +5,10 @@ SYNOPSIS istype(x, y) TYPES - x any, &any - y any, &any + x any, &any + y any, &any - return int + return int DESCRIPTION Determine if x has the same type as y. This function will return 1 @@ -48,7 +48,7 @@ SEE ALSO ## ## 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 +## 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 @@ -56,8 +56,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/21 02:21:31 -## File existed as early as: 1994 +## Under source code control: 1994/10/21 02:21:31 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isupper b/help/isupper index 3c5d829..7c7ed58 100644 --- a/help/isupper +++ b/help/isupper @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2013/09/01 18:10:53 -## File existed as early as: 2013 +## Under source code control: 2013/09/01 18:10:53 +## File existed as early as: 2013 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/isxdigit b/help/isxdigit index 9cb6c0b..90f7e93 100644 --- a/help/isxdigit +++ b/help/isxdigit @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2013/09/01 18:10:53 -## File existed as early as: 2013 +## Under source code control: 2013/09/01 18:10:53 +## File existed as early as: 2013 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/jacobi b/help/jacobi index 8550810..df3c71e 100644 --- a/help/jacobi +++ b/help/jacobi @@ -5,10 +5,10 @@ SYNOPSIS jacobi(x, y) TYPES - x integer - y integer + x integer + y integer - return 1, -1, or 0 + return 1, -1, or 0 DESCRIPTION The jacobi builtin function of calc returns the value of the @@ -16,19 +16,19 @@ DESCRIPTION If y is an odd prime, then the Legendre symbol (x/y) returns: - (x/y) == 0 x is divisible by y (0 == x % y) - (x/y) == 1 if x is a quadratic residue modulo y - (x/y) == -1 if x is not a quadratic residue modulo y + (x/y) == 0 x is divisible by y (0 == x % y) + (x/y) == 1 if x is a quadratic residue modulo y + (x/y) == -1 if x is not a quadratic residue modulo y Legendre symbol often denoted as (x/y) as if x/y were a fraction. If there exists an integer u such that: - x == u^2 modulo y (i.e., x == u^2 % y) + x == u^2 modulo y (i.e., x == u^2 % y) then x is a quadratic residue modulo y. However, if for all integers u: - x != u^2 modulo y (i.e., x != u^2 % y) + x != u^2 modulo y (i.e., x != u^2 % y) x is said to be a quadratic non-residue modulo y. @@ -36,21 +36,21 @@ DESCRIPTION That is, Jacobi symbol satisfies the same rules as the Legendre symbol. Therefore, when y is an odd prime: - jacobi(x,y) == 0 x is divisible by y (x == 0 % y) - jacobi(x,y) == 1 if x is a quadratic residue modulo y - jacobi(x,y) == -1 if x is a quadratic non-residue modulo y + jacobi(x,y) == 0 x is divisible by y (x == 0 % y) + jacobi(x,y) == 1 if x is a quadratic residue modulo y + jacobi(x,y) == -1 if x is a quadratic non-residue modulo y When y is even or y <= 0: - jacobi(x,y) == 0 + jacobi(x,y) == 0 When y is not prime, we may express y as the product of primes: - y == p0^a0 * p1^a1 * .. * pn^an + y == p0^a0 * p1^a1 * .. * pn^an When y is odd and NOT prime, then: - jacobi(x,y) == (x/p0)^a0 * (x/p1)^a1 * .. * (x/pn)^an + jacobi(x,y) == (x/p0)^a0 * (x/p1)^a1 * .. * (x/pn)^an where (x/y) is Legendre symbol. @@ -73,113 +73,113 @@ DESCRIPTION We have these identities: - jacobi(x,y) == 0 if x <= 0 - jacobi(x,y) == 0 if y <= 0 - jacobi(x,y) == 0 if y is even + jacobi(x,y) == 0 if x <= 0 + jacobi(x,y) == 0 if y <= 0 + jacobi(x,y) == 0 if y is even - jacobi(x,b) == 0 if gcd(x,b) > 1 + jacobi(x,b) == 0 if gcd(x,b) > 1 - jacobi(0,b) == 0 - jacobi(1,b) == 1 + jacobi(0,b) == 0 + jacobi(1,b) == 1 - jacobi(x,b) == jacobi(y,b) if x == y % b + jacobi(x,b) == jacobi(y,b) if x == y % b - jacobi(a,b) == jacobi(2*a,b) if b == 1 % 8 OR b == 7 % 8 - jacobi(a,b) == -jacobi(2*a,b) if b != 1 & 8 AND b != 7 % 8 + jacobi(a,b) == jacobi(2*a,b) if b == 1 % 8 OR b == 7 % 8 + jacobi(a,b) == -jacobi(2*a,b) if b != 1 & 8 AND b != 7 % 8 - jacobi(a,b) == jacobi(b,a) if a == 3 % 4 AND b == 3 % 4 - jacobi(a,b) == -jacobi(b,a) if a != 3 % 4 OR b != 3 % 4 + jacobi(a,b) == jacobi(b,a) if a == 3 % 4 AND b == 3 % 4 + jacobi(a,b) == -jacobi(b,a) if a != 3 % 4 OR b != 3 % 4 - jacobi(-1,b) == 1 if b == 1 % 4 - jacobi(-1,b) == -1 if b == 3 % 4 + jacobi(-1,b) == 1 if b == 1 % 4 + jacobi(-1,b) == -1 if b == 3 % 4 - jacobi(x,b) * jacobi(y,b) == jacobi(x*y,b) - jacobi(x,a) * jacobi(x,b) == jacobi(x,a*b) + jacobi(x,b) * jacobi(y,b) == jacobi(x*y,b) + jacobi(x,a) * jacobi(x,b) == jacobi(x,a*b) Technically the Jacobi symbol jacobi(x,y) is not defined when x == 0, x < 0, y is even, y == 0, and when y < 0. So by convention: - jacobi(x,y) == 0 if x <= 0 - jacobi(x,y) == 0 if y <= 0 - jacobi(x,y) == 0 if y == 0 % 2 + jacobi(x,y) == 0 if x <= 0 + jacobi(x,y) == 0 if y <= 0 + jacobi(x,y) == 0 if y == 0 % 2 It is also worth noting that: - jacobi(x,y) == 0 if gcd(y,x) != 1 - jacobi(y,y) == 0 if y > 1 + jacobi(x,y) == 0 if gcd(y,x) != 1 + jacobi(y,y) == 0 if y > 1 Based on the generalization of the quadratic reciprocity theorem, when a and b are odd, b >= 3, and gcd(a,b) == 1: - jacobi(a,b) == jacobi(b,a) * ((-1) ^ ((a-1) * (b-1) / 4)) + jacobi(a,b) == jacobi(b,a) * ((-1) ^ ((a-1) * (b-1) / 4)) Therefore, when a and b are odd, b >= 3, and gcd(a,b) == 1: - jacobi(a,b) == jacobi(b,a) if a == 1 % 4 OR b == 1 % 4 - jacobi(a,b) == -jacobi(b,a) if a == 3 % 4 AND b == 3 % 4 + jacobi(a,b) == jacobi(b,a) if a == 1 % 4 OR b == 1 % 4 + jacobi(a,b) == -jacobi(b,a) if a == 3 % 4 AND b == 3 % 4 Jacobi symbol satisfies the same rules as the Legendre symbol such as: - jacobi(x,y0*y1) == jacobi(x,y0) * jacobi(x,y1) - jacobi(x0*x1,y) == jacobi(x0,y) * jacobi(x1,y) + jacobi(x,y0*y1) == jacobi(x,y0) * jacobi(x,y1) + jacobi(x0*x1,y) == jacobi(x0,y) * jacobi(x1,y) When b is odd: - jacobi(x^2,b) == 1 if gcd(x,b) == 1 - jacobi(x,b^2) == 1 if gcd(x,b) == 1 + jacobi(x^2,b) == 1 if gcd(x,b) == 1 + jacobi(x,b^2) == 1 if gcd(x,b) == 1 - jacobi(x0,b) == jacobi(x1,b) if x0 == x1 % b + jacobi(x0,b) == jacobi(x1,b) if x0 == x1 % b - jacobi(-1,b) == (-1) ^ ((b-1) / 2) == 1 if b == 1 % 4 - jacobi(-1,b) == (-1) ^ ((b-1) / 2) == -1 if b == 3 % 4 + jacobi(-1,b) == (-1) ^ ((b-1) / 2) == 1 if b == 1 % 4 + jacobi(-1,b) == (-1) ^ ((b-1) / 2) == -1 if b == 3 % 4 - jacobi(2,b) == (-1) ^ ((b^2 - 1) / 8) == 1 if b == 1 % 8 OR - b == 7 % 8 - jacobi(2,b) == (-1) ^ ((b^2 - 1) / 8) == -1 if b == 3 % 8 OR - b == 5 % 8 + jacobi(2,b) == (-1) ^ ((b^2 - 1) / 8) == 1 if b == 1 % 8 OR + b == 7 % 8 + jacobi(2,b) == (-1) ^ ((b^2 - 1) / 8) == -1 if b == 3 % 8 OR + b == 5 % 8 - jacobi(-3,b) == 1 if b == 1 % 6 - jacobi(-3,b) == -1 if b == 5 % 6 + jacobi(-3,b) == 1 if b == 1 % 6 + jacobi(-3,b) == -1 if b == 5 % 6 - jacobi(5,b) == 1 if b == 1 % 10 OR - b == 9 % 10 - jacobi(5,b) == -1 if b == 3 % 10 OR - b == 7 % 10 + jacobi(5,b) == 1 if b == 1 % 10 OR + b == 9 % 10 + jacobi(5,b) == -1 if b == 3 % 10 OR + b == 7 % 10 If a and b are both odd primes, OR if gcd(a,b) = 1 and, a > 0, and a is odd: - jacobi(a,b) == jacobi(b,a) * ((-1) ^ (((a-1)/2) * ((b-1)/2))) - jacobi(a,b) * jacobi(b,a) == ((-1) ^ (((a-1)/2) * ((b-1)/2))) + jacobi(a,b) == jacobi(b,a) * ((-1) ^ (((a-1)/2) * ((b-1)/2))) + jacobi(a,b) * jacobi(b,a) == ((-1) ^ (((a-1)/2) * ((b-1)/2))) If b is an odd prime: - jacobi(a,b) == (a ^ ((b-1)/2)) % b + jacobi(a,b) == (a ^ ((b-1)/2)) % b Combining all of the above, computing jacobi(x,b) may be expressed in the following algorithm when b is odd and 0 < x < b: - j = 1; - while (x != 0) { - while (iseven(x)) { - x = x / 2; - t = b % 8; - if (t == 3 || t == 5) { - j = -j; - } - } - swap(x,b); - if (((x % 4) == 3) && ((b % 4) == 3)) { - j = -j; - } - x = x % b; - } + j = 1; + while (x != 0) { + while (iseven(x)) { + x = x / 2; + t = b % 8; + if (t == 3 || t == 5) { + j = -j; + } + } + swap(x,b); + if (((x % 4) == 3) && ((b % 4) == 3)) { + j = -j; + } + x = x % b; + } - if (b == 1) { - return j; - } else { - return 0; - } + if (b == 1) { + return j; + } else { + return 0; + } The above calc pseudo code is provided to help illustrate the properties of the jacobi symbol only. The use of calc's jacobi @@ -188,9 +188,9 @@ DESCRIPTION For more information on the Legendre symbol and the Jacobi symbol: - http://mathworld.wolfram.com/LegendreSymbol.html - http://mathworld.wolfram.com/JacobiSymbol.html - http://primes.utm.edu/glossary/xpage/JacobiSymbol.html + http://mathworld.wolfram.com/LegendreSymbol.html + http://mathworld.wolfram.com/JacobiSymbol.html + http://primes.utm.edu/glossary/xpage/JacobiSymbol.html EXAMPLE ; print jacobi(2,3), jacobi(2,5), jacobi(2,15) @@ -216,7 +216,7 @@ SEE ALSO ## ## 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 +## 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 @@ -224,8 +224,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 12:34:57 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 12:34:57 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/join b/help/join index 9d324fa..71983fb 100644 --- a/help/join +++ b/help/join @@ -5,9 +5,9 @@ SYNOPSIS join(x, y, ...) TYPES - x, y, ... lists + x, y, ... lists - return list or null + return list or null DESCRIPTION For lists x, y, ..., join(x, y, ...) returns the list whose length @@ -23,11 +23,11 @@ EXAMPLE ; join(A, B) list (5 elements, 5 nonzero): - [[0]] = 1 - [[1]] = 2 - [[2]] = 3 - [[3]] = 4 - [[4]] = 5 + [[0]] = 1 + [[1]] = 2 + [[2]] = 3 + [[3]] = 4 + [[4]] = 5 LIMITS none @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/09 19:41:40 -## File existed as early as: 1995 +## Under source code control: 1995/07/09 19:41:40 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/lcm b/help/lcm index 30c231c..bd5f46e 100644 --- a/help/lcm +++ b/help/lcm @@ -7,7 +7,7 @@ SYNOPSIS TYPES x1, x2, ... rational number - return rational number + return rational number DESCRIPTION Compute the least common multiple of one or more rational numbers. @@ -37,7 +37,7 @@ SEE ALSO ## ## 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 +## 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 @@ -45,8 +45,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:26 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:26 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/lcmfact b/help/lcmfact index 399b573..f79597f 100644 --- a/help/lcmfact +++ b/help/lcmfact @@ -5,9 +5,9 @@ SYNOPSIS lcmfact(n) TYPES - n positive integer + n positive integer - return positive integer + return positive integer DESCRIPTION Returns the lcm of the integers 1, 2, ..., n. @@ -34,7 +34,7 @@ SEE ALSO ## ## 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 +## 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 @@ -42,8 +42,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 12:34:57 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 12:34:57 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/lfactor b/help/lfactor index 9d48cab..21c9b7d 100644 --- a/help/lfactor +++ b/help/lfactor @@ -5,10 +5,10 @@ SYNOPSIS lfactor(n, m) TYPES - n integer - m nonnegative integer <= 203280221 (= number of primes < 2^32) + n integer + m nonnegative integer <= 203280221 (= number of primes < 2^32) - return positive integer + return positive integer DESCRIPTION This function ignores the signs of n and m, so here we shall @@ -51,7 +51,7 @@ SEE ALSO ## ## 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 +## 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 @@ -59,8 +59,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 12:34:57 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 12:34:57 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/list b/help/list index 587f055..62d1762 100644 --- a/help/list +++ b/help/list @@ -5,9 +5,9 @@ SYNOPSIS list([x, [x, ... ]]) TYPES - x any, &any + x any, &any - return list + return list DESCRIPTION This function returns a list that is composed of the arguments x. @@ -18,24 +18,24 @@ DESCRIPTION The function 'list' creates a list with possible initial elements. For example, - x = list(4, 6, 7); + x = list(4, 6, 7); creates a list in the variable x of three elements, in the order 4, 6, and 7. The 'push' and 'pop' functions insert or remove an element from - the beginning of the list. The 'append' and 'remove' functions + the beginning of the list. The 'append' and 'remove' functions insert or remove an element from the end of the list. The 'insert' and 'delete' functions insert or delete an element from the middle (or ends) of a list. The functions which insert elements return the null value, but the functions which remove an element return - the element as their value. The 'size' function returns the number + the element as their value. The 'size' function returns the number of elements in the list. Note that these functions manipulate the actual list argument, instead of returning a new list. Thus in the example: - push(x, 9); + push(x, 9); x becomes a list of four elements, in the order 9, 4, 6, and 7. Lists can be copied by assigning them to another variable. @@ -43,11 +43,11 @@ DESCRIPTION An arbitrary element of a linked list can be accessed by using the double-bracket operator. The beginning of the list has index 0. Thus in the new list x above, the expression x[[0]] returns the - value of the first element of the list, which is 9. Note that this + value of the first element of the list, which is 9. Note that this indexing does not remove elements from the list. Since lists are doubly linked in memory, random access to arbitrary - elements can be slow if the list is large. However, for each list + elements can be slow if the list is large. However, for each list a pointer is kept to the latest indexed element, thus relatively sequential accesses to the elements in a list will not be slow. @@ -65,7 +65,7 @@ EXAMPLE [[2]] = 4i ; list() - list (0 elements, 0 nonzero) + list (0 elements, 0 nonzero) LIMITS none @@ -84,7 +84,7 @@ SEE ALSO ## ## 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 +## 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 @@ -92,8 +92,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 03:13:19 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 03:13:19 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ln b/help/ln index 98eb4b7..72ca8fb 100644 --- a/help/ln +++ b/help/ln @@ -1,14 +1,14 @@ NAME - ln - logarithm function + ln - logarithm function SYNOPSIS ln(x [,eps]) TYPES - x nonzero real or complex - eps 0 < real < 1, defaults to epsilon() + x nonzero real or complex + eps 0 < real < 1, defaults to epsilon() - return real or complex + return real or complex DESCRIPTION Approximate the natural logarithm function of x by a multiple of @@ -42,7 +42,7 @@ SEE ALSO ## ## 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 +## 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 @@ -50,8 +50,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/11 04:41:26 -## File existed as early as: 1995 +## Under source code control: 1995/10/11 04:41:26 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/log b/help/log index 5cd23d3..a393018 100644 --- a/help/log +++ b/help/log @@ -1,14 +1,14 @@ NAME - log - base 10 logarithm + log - base 10 logarithm SYNOPSIS log(x [,eps]) TYPES - x nonzero real or complex - eps 0 < real < 1, defaults to epsilon() + x nonzero real or complex + eps 0 < real < 1, defaults to epsilon() - return real or complex + return real or complex DESCRIPTION Approximate the base 10 logarithm function of x by a multiple of @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2006/05/06 23:56:04 -## File existed as early as: 2006 +## Under source code control: 2006/05/06 23:56:04 +## File existed as early as: 2006 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/log2 b/help/log2 index 913b94e..96f47d8 100644 --- a/help/log2 +++ b/help/log2 @@ -5,10 +5,10 @@ SYNOPSIS log2(x [,eps]) TYPES - x nonzero real or complex - eps 0 < real < 1, defaults to epsilon() + x nonzero real or complex + eps 0 < real < 1, defaults to epsilon() - return real or complex + return real or complex DESCRIPTION Approximate the base 2 logarithm function of x by a multiple of @@ -58,7 +58,7 @@ SEE ALSO ## ## 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 +## 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 @@ -66,8 +66,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/08/19 09:14:04 -## File existed as early as: 2023 +## Under source code control: 2023/08/19 09:14:04 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/logn b/help/logn index 4b51c89..2270101 100644 --- a/help/logn +++ b/help/logn @@ -5,11 +5,11 @@ SYNOPSIS logn(x, n [,eps]) TYPES - x nonzero real or complex - n nonzero real or complex - eps 0 < real < 1, defaults to epsilon() + x nonzero real or complex + n nonzero real or complex + eps 0 < real < 1, defaults to epsilon() - return real or complex + return real or complex DESCRIPTION Approximate the base n logarithm function of x by a multiple of @@ -72,7 +72,7 @@ SEE ALSO ## ## 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 +## 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 @@ -80,8 +80,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/08/19 09:14:04 -## File existed as early as: 2023 +## Under source code control: 2023/08/19 09:14:04 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/lowbit b/help/lowbit index bf27428..a1dff2c 100644 --- a/help/lowbit +++ b/help/lowbit @@ -5,13 +5,13 @@ SYNOPSIS lowbit(x) TYPES - x nonzero integer + x nonzero integer - return integer + return integer DESCRIPTION If x is a nonzero integer, lowbit(x) returns the index of the - lowest nonzero bit in the binary representation of abs(x). Equivalently, + lowest nonzero bit in the binary representation of abs(x). Equivalently, lowbit(x) is the greatest integer for which x/2^n is an integer; the binary representation of x then ends with n zero bits. @@ -36,7 +36,7 @@ SEE ALSO ## ## 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 +## 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 @@ -44,8 +44,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/03 10:40:02 -## File existed as early as: 1995 +## Under source code control: 1995/10/03 10:40:02 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ltol b/help/ltol index 0c45093..192108d 100644 --- a/help/ltol +++ b/help/ltol @@ -1,15 +1,15 @@ NAME ltol - "leg to leg", third side of a right-angled triangle with - unit hypotenuse, given one other side + unit hypotenuse, given one other side SYNOPSIS ltol(x, [,eps]) TYPES - x real - eps nonzero real, defaults to epsilon() + x real + eps nonzero real, defaults to epsilon() - return real + return real DESCRIPTION Returns sqrt(1 - x^2) to the nearest multiple of eps. @@ -37,7 +37,7 @@ SEE ALSO ## ## 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 +## 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 @@ -45,8 +45,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:27 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:27 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/makelist b/help/makelist index 7a4a8e8..4c6323d 100644 --- a/help/makelist +++ b/help/makelist @@ -5,9 +5,9 @@ SYNOPSIS makelist(x) TYPES - x int + x int - return list + return list DESCRIPTION For non-negative integer x, makelist(x) returns a list of size x @@ -18,10 +18,10 @@ EXAMPLE ; A list (4 members, 4 nonzero): - [[0]] = NULL - [[1]] = NULL - [[2]] = NULL - [[3]] = NULL + [[0]] = NULL + [[1]] = NULL + [[2]] = NULL + [[3]] = NULL LIMITS 0 <= x < 2^31 @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/10 02:09:31 -## File existed as early as: 1995 +## Under source code control: 1995/07/10 02:09:31 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/mat b/help/mat index 8351269..16e9562 100644 --- a/help/mat +++ b/help/mat @@ -12,27 +12,27 @@ SYNOPSIS decl id_1 id_2 ... [index-range-list] ... TYPES - index-range-list range_1 [, range_2, ...] up to 4 ranges - range_1, ... integer, or integer_1 : integer_2 - value, value_1, ... any - variable_1 ... lvalue - decl declarator = global, static or local - id_1, ... identifier + index-range-list range_1 [, range_2, ...] up to 4 ranges + range_1, ... integer, or integer_1 : integer_2 + value, value_1, ... any + variable_1 ... lvalue + decl declarator = global, static or local + id_1, ... identifier DESCRIPTION The expression mat [index-range-list] returns a matrix value. This may be assigned to one or more lvalues A, B, ... by either - mat A B ... [index-range-list] + mat A B ... [index-range-list] or - A = B = ... = mat[index-range-list] + A = B = ... = mat[index-range-list] If a variable is specified by an expression that is not a symbol with possibly object element specifiers, the expression should be enclosed in parentheses. For example, parentheses are required in - mat (A[2]) [3] and mat (*p) [3] but mat P.x [3] is acceptable. + mat (A[2]) [3] and mat (*p) [3] but mat P.x [3] is acceptable. When an index-range is specified as integer_1 : integer_2, where integer_1 and integer_2 are expressions which evaluate to integers, @@ -56,7 +56,7 @@ DESCRIPTION For example, in order of location, the six element of A = mat [2,3] are: - A[0,0], A[0,1], A[0,2], A[1,0], A[1,1], and A[1,2]. + A[0,0], A[0,1], A[0,2], A[1,0], A[1,1], and A[1,2]. These elements may also be specified using the double-bracket operator with a single integer index as in A[[0]], A[[1]], ..., A[[5]]. @@ -64,35 +64,35 @@ DESCRIPTION is p + i as long as A exists and a new value is not assigned to A. When a matrix is created, each element is initially assigned the - value zero. Other values may be assigned then or later using the + value zero. Other values may be assigned then or later using the "= {...}" assignment operation. Thus - A = {value_0, value_1, ...} + A = {value_0, value_1, ...} assigns the values value_0, value_1, ... to the elements A[[0]], - A[[1]], ... Any blank "value" is passed over. For example, + A[[1]], ... Any blank "value" is passed over. For example, - A = {1, , 2} + A = {1, , 2} will assign the value 1 to A[[0]], 2 to A[[2]] and leave all other - elements unchanged. Values may also be assigned to elements by + elements unchanged. Values may also be assigned to elements by simple assignments, as in A[0,0] = 1, A[0,2] = 2; If the index-range is left blank but an initializer list is specified as in: - ; mat A[] = {1, 2 } - ; B = mat[] = {1, , 3, } + ; mat A[] = {1, 2 } + ; B = mat[] = {1, , 3, } the matrix created is one-dimensional. If the list contains a positive number n of values or blanks, the result is as if the range were specified by [n], i.e. the range of indices is from - 0 to n - 1. In the above examples, A is of size 2 with A[0] = 1 + 0 to n - 1. In the above examples, A is of size 2 with A[0] = 1 and A[1] = 2; B is of size 4 with B[0] = 1, B[1] = B[3] = 0, B[2] = 3. The specification mat[] = { } creates the same as mat[1]. If the index-range is left blank and no initializer list is specified, - as in mat C[] or C = mat[], the matrix assigned to C has zero + as in mat C[] or C = mat[], the matrix assigned to C has zero dimension; this has one element C[]. To assign a value using "= { ...}" at the same time as creating C, @@ -112,21 +112,21 @@ DESCRIPTION For example, one may have an expressions like: - ; A[1,2][3].alpha[2]; + ; A[1,2][3].alpha[2]; if A[1,2][3].alpha is a list with at least three elements, A[1,2][3] is an object of a type like obj {alpha, beta}, A[1,2] is a matrix of type mat[4] and A is a mat[2,3] matrix. When an element of a matrix is a matrix and the total number of indices does not exceed 4, the indices can be combined into one list, e.g. the A[1,2][3] in the - above example can be shortened to A[1,2,3]. (Unlike C, A[1,2] cannot + above example can be shortened to A[1,2,3]. (Unlike C, A[1,2] cannot be expressed as A[1][2].) The function ismat(V) returns 1 if V is a matrix, 0 otherwise. isident(V) returns 1 if V is a square matrix with diagonal elements 1, off-diagonal elements zero, or a zero- or one-dimensional matrix with - every element 1; otherwise zero is returned. Thus isident(V) = 1 + every element 1; otherwise zero is returned. Thus isident(V) = 1 indicates that for V * A and A * V where A is any matrix of for which either product is defined and the elements of A are real or complex numbers, that product will equal A. @@ -153,31 +153,31 @@ DESCRIPTION function mat_print(M); for example, for a not too big 2-dimensional matrix A it is a common practice to use a loop like: - define mat_print(A) { - local i,j; + define mat_print(A) { + local i,j; - for (i = matmin(A,1); i <= matmax(A,1); i++) { - if (i != matmin(A,1)) - printf("\t"); - for (j = matmin(A,2); j <= matmax(A,2); j++) - printf(" [%d,%d]: %e", i, j, A[i,j]); - if (i != matmax(A,1)) - printf("\n"); - } - } + for (i = matmin(A,1); i <= matmax(A,1); i++) { + if (i != matmin(A,1)) + printf("\t"); + for (j = matmin(A,2); j <= matmax(A,2); j++) + printf(" [%d,%d]: %e", i, j, A[i,j]); + if (i != matmax(A,1)) + printf("\n"); + } + } So that when one defines a 2D matrix such as: - ; mat X[2,3] = {1,2,3,4,5,6} + ; mat X[2,3] = {1,2,3,4,5,6} then printing X results in: - [0,0]: 1 [0,1]: 2 [0,2]: 3 - [1,0]: 4 [1,1]: 5 [1,2]: 6 + [0,0]: 1 [0,1]: 2 [0,2]: 3 + [1,0]: 4 [1,1]: 5 [1,2]: 6 The default printing may be restored by - ; undefine mat_print; + ; undefine mat_print; The keyword "mat" followed by two or more index-range-lists returns a matrix with indices specified by the first list, whose elements are @@ -186,11 +186,11 @@ DESCRIPTION as its value a 3-element matrix. Values may be assigned to the elements of the innermost matrices by nested = {...} operations as in - ; mat [2][3] = {{1,2,3},{4,5,6}} + ; mat [2][3] = {{1,2,3},{4,5,6}} An example of the use of mat with a declarator is - ; global mat A B [2,3], C [4] + ; global mat A B [2,3], C [4] This creates, if they do not already exist, three global variables with names A, B, C, and assigns to A and B the value mat[2,3] and to C mat[4]. @@ -198,138 +198,138 @@ DESCRIPTION Some operations are defined for matrices. A == B - Returns 1 if A and B are of the same "shape" and "corresponding" - elements are equal; otherwise 0 is returned. Being of the same - shape means they have the same dimension d, and for each i <= d, + Returns 1 if A and B are of the same "shape" and "corresponding" + elements are equal; otherwise 0 is returned. Being of the same + shape means they have the same dimension d, and for each i <= d, - matmax(A,i) - matmin(A,i) == matmax(B,i) - matmin(B,i), + matmax(A,i) - matmin(A,i) == matmax(B,i) - matmin(B,i), - One consequence of being the same shape is that the matrices will - have the same size. Elements "correspond" if they have the same - double-bracket indices; thus A == B implies that A[[i]] == B[[i]] - for 0 <= i < size(A) == size(B). + One consequence of being the same shape is that the matrices will + have the same size. Elements "correspond" if they have the same + double-bracket indices; thus A == B implies that A[[i]] == B[[i]] + for 0 <= i < size(A) == size(B). A + B A - B - These are defined A and B have the same shape, the element - with double-bracket index j being evaluated by A[[j]] + B[[j]] and - A[[j]] - B[[j]], respectively. The index-ranges for the results - are those for the matrix A. + These are defined A and B have the same shape, the element + with double-bracket index j being evaluated by A[[j]] + B[[j]] and + A[[j]] - B[[j]], respectively. The index-ranges for the results + are those for the matrix A. A[i,j] - If A is two-dimensional, it is customary to speak of the indices - i, j in A[i,j] as referring to rows and columns; the number of - rows is matmax(A,1) - matmin(A,1) + 1; the number of columns if - matmax(A,2) - matmin(A,2) + 1. A matrix is said to be square - if it is two-dimensional and the number of rows is equal to the - number of columns. + If A is two-dimensional, it is customary to speak of the indices + i, j in A[i,j] as referring to rows and columns; the number of + rows is matmax(A,1) - matmin(A,1) + 1; the number of columns if + matmax(A,2) - matmin(A,2) + 1. A matrix is said to be square + if it is two-dimensional and the number of rows is equal to the + number of columns. A * B - Multiplication is defined provided certain conditions by the - dimensions and shapes of A and B are satisfied. If both have - dimension 2 and the column-index-list for A is the same as - the row-index-list for B, C = A * B is defined in the usual - way so that for i in the row-index-list of A and j in the - column-index-list for B, + Multiplication is defined provided certain conditions by the + dimensions and shapes of A and B are satisfied. If both have + dimension 2 and the column-index-list for A is the same as + the row-index-list for B, C = A * B is defined in the usual + way so that for i in the row-index-list of A and j in the + column-index-list for B, - C[i,j] = Sum A[i,k] * B[k,j] + C[i,j] = Sum A[i,k] * B[k,j] - the sum being over k in the column-index-list of A. The same - formula is used so long as the number of columns in A is the same - as the number of rows in B and k is taken to refer to the offset - from matmin(A,2) and matmin(B,1), respectively, for A and B. - If the multiplications and additions required cannot be performed, - an execution error may occur or the result for C may contain - one or more error-values as elements. + the sum being over k in the column-index-list of A. The same + formula is used so long as the number of columns in A is the same + as the number of rows in B and k is taken to refer to the offset + from matmin(A,2) and matmin(B,1), respectively, for A and B. + If the multiplications and additions required cannot be performed, + an execution error may occur or the result for C may contain + one or more error-values as elements. - If A or B has dimension zero, the result for A * B is simply - that of multiplying the elements of the other matrix on the - left by A[] or on the right by B[]. + If A or B has dimension zero, the result for A * B is simply + that of multiplying the elements of the other matrix on the + left by A[] or on the right by B[]. - If both A and B have dimension 1, A * B is defined if A and B - have the same size; the result has the same index-list as A - and each element is the product of corresponding elements of - A and B. If A and B have the same index-list, this multiplication - is consistent with multiplication of 2D matrices if A and B are - taken to represent 2D matrices for which the off-diagonal elements - are zero and the diagonal elements are those of A and B. - the real and complex numbers. + If both A and B have dimension 1, A * B is defined if A and B + have the same size; the result has the same index-list as A + and each element is the product of corresponding elements of + A and B. If A and B have the same index-list, this multiplication + is consistent with multiplication of 2D matrices if A and B are + taken to represent 2D matrices for which the off-diagonal elements + are zero and the diagonal elements are those of A and B. + the real and complex numbers. - If A is of dimension 1 and B is of dimension 2, A * B is defined - if the number of rows in B is the same as the size of A. The - result has the same index-lists as B; each row of B is multiplied - on the left by the corresponding element of A. + If A is of dimension 1 and B is of dimension 2, A * B is defined + if the number of rows in B is the same as the size of A. The + result has the same index-lists as B; each row of B is multiplied + on the left by the corresponding element of A. - If A is of dimension 2 and B is of dimension 1, A * B is defined - if number of columns in A is the same as the size of A. The - result has the same index-lists as A; each column of A is - multiplied on the right by the corresponding element of B. + If A is of dimension 2 and B is of dimension 1, A * B is defined + if number of columns in A is the same as the size of A. The + result has the same index-lists as A; each column of A is + multiplied on the right by the corresponding element of B. - The algebra of additions and multiplications involving both one- - and two-dimensional matrices is particularly simple when all the - elements are real or complex numbers and all the index-lists are - the same, as occurs, for example, if for some positive integer n, - all the matrices start as mat [n] or mat [n,n]. + The algebra of additions and multiplications involving both one- + and two-dimensional matrices is particularly simple when all the + elements are real or complex numbers and all the index-lists are + the same, as occurs, for example, if for some positive integer n, + all the matrices start as mat [n] or mat [n,n]. det(A) - If A is a square, det(A) is evaluated by an algorithm that returns - the determinant of A if the elements of A are real or complex - numbers, and if such an A is non-singular, inverse(A) returns - the inverse of A indexed in the same way as A. For matrix A of - dimension 0 or 1, det(A) is defined as the product of the elements - of A in the order in which they occur in A, inverse(A) returns - a matrix indexed in the same way as A with each element inverted. + If A is a square, det(A) is evaluated by an algorithm that returns + the determinant of A if the elements of A are real or complex + numbers, and if such an A is non-singular, inverse(A) returns + the inverse of A indexed in the same way as A. For matrix A of + dimension 0 or 1, det(A) is defined as the product of the elements + of A in the order in which they occur in A, inverse(A) returns + a matrix indexed in the same way as A with each element inverted. The following functions are defined to return matrices with the same - index-ranges as A and the specified operations performed on all - elements of A. Here num is an arbitrary complex number (nonzero - when it is a divisor), int an integer, rnd a rounding-type - specifier integer, real a real number. + index-ranges as A and the specified operations performed on all + elements of A. Here num is an arbitrary complex number (nonzero + when it is a divisor), int an integer, rnd a rounding-type + specifier integer, real a real number. - num * A - A * num - A / num - - A - conj(A) - A << int, A >> int - scale(A, int) - round(A, int, rnd) - bround(A, int, rnd) - appr(A, real, rnd) - int(A) - frac(A) - A // real - A % real - A ^ int + num * A + A * num + A / num + - A + conj(A) + A << int, A >> int + scale(A, int) + round(A, int, rnd) + bround(A, int, rnd) + appr(A, real, rnd) + int(A) + frac(A) + A // real + A % real + A ^ int If A and B are one-dimensional of the same size dp(A, B) returns - their dot-product, i.e. the sum of the products of corresponding - elements. + their dot-product, i.e. the sum of the products of corresponding + elements. If A and B are one-dimension and of size 3, cp(A, B) returns their - cross-product. + cross-product. randperm(A) returns a matrix indexed the same as A in which the elements - of A have been randomly permuted. + of A have been randomly permuted. sort(A) returns a matrix indexed the same as A in which the elements - of A have been sorted. + of A have been sorted. If A is an lvalue whose current value is a matrix, matfill(A, v) - assigns the value v to every element of A, and if also, A is - square, matfill(A, v1, v2) assigns v1 to the off-diagonal elements, - v2 to the diagonal elements. To create and assign to A the unit - n * n matrix, one may use matfill(mat A[n,n], 0, 1). + assigns the value v to every element of A, and if also, A is + square, matfill(A, v1, v2) assigns v1 to the off-diagonal elements, + v2 to the diagonal elements. To create and assign to A the unit + n * n matrix, one may use matfill(mat A[n,n], 0, 1). For a square matrix A, mattrace(A) returns the trace of A, i.e. the - sum of the diagonal elements. For zero- or one-dimensional A, - mattrace(A) returns the sum of the elements of A. + sum of the diagonal elements. For zero- or one-dimensional A, + mattrace(A) returns the sum of the elements of A. For a two-dimensional matrix A, mattrans(A) returns the transpose - of A, i.e. if A is mat[m,n], it returns a mat[n,m] matrix with - [i,j] element equal to A[j,i]. For zero- or one-dimensional A, - mattrace(A) returns a matrix with the same value as A. + of A, i.e. if A is mat[m,n], it returns a mat[n,m] matrix with + [i,j] element equal to A[j,i]. For zero- or one-dimensional A, + mattrace(A) returns a matrix with the same value as A. The functions search(A, value, start, end]) and rsearch(A, value, start, end]) return the first or last index i @@ -422,7 +422,7 @@ SEE ALSO ## ## 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 +## 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 @@ -430,8 +430,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:22 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:22 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/matdim b/help/matdim index ab033fc..d867883 100644 --- a/help/matdim +++ b/help/matdim @@ -5,9 +5,9 @@ SYNOPSIS matdim(m) TYPES - m matrix + m matrix - return 1, 2, 3, or 4 + return 1, 2, 3, or 4 DESCRIPTION Returns the number of indices required to specify elements of the matrix. @@ -36,7 +36,7 @@ SEE ALSO ## ## 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 +## 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 @@ -44,8 +44,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:45 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:45 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/matfill b/help/matfill index 466ebf4..43ee0d2 100644 --- a/help/matfill +++ b/help/matfill @@ -5,11 +5,11 @@ SYNOPSIS matfill(m, x [, y]) TYPES - m matrix - x any - y any + m matrix + x any + y any - return null + return null DESCRIPTION For any matrix m, matfill(m, x) assigns to every element of m the @@ -19,16 +19,16 @@ DESCRIPTION EXAMPLE ; mat A[3]; matfill(A, 2); print A mat [3] (3 elements, 3 nonzero): - [0] = 2 - [1] = 2 - [2] = 2 + [0] = 2 + [1] = 2 + [2] = 2 ; mat B[2, 1:2]; matfill(B,3,4); print B mat [2,1:2] (4 elements, 4 nonzero): - [0,1] = 4 - [0,2] = 3 - [1,1] = 3 - [1,2] = 4 + [0,1] = 4 + [0,2] = 3 + [1,1] = 3 + [1,2] = 4 LIMITS none @@ -49,7 +49,7 @@ SEE ALSO ## ## 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 +## 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 @@ -57,8 +57,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:45 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:45 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/matmax b/help/matmax index 589c6fd..2ddb8ff 100644 --- a/help/matmax +++ b/help/matmax @@ -5,10 +5,10 @@ SYNOPSIS matmax(m, i) TYPES - m matrix - i 0, 1, 2, 3 + m matrix + i 0, 1, 2, 3 - return integer + return integer DESCRIPTION Returns the maximum value for i-th index (i counting from zero) @@ -38,7 +38,7 @@ SEE ALSO ## ## 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 +## 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 @@ -46,8 +46,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:45 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:45 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/matmin b/help/matmin index 29d9677..7ad165d 100644 --- a/help/matmin +++ b/help/matmin @@ -5,10 +5,10 @@ SYNOPSIS matmin(m, i) TYPES - m matrix - i 0, 1, 2, 3 + m matrix + i 0, 1, 2, 3 - return integer + return integer DESCRIPTION Returns the minimum value for i-th index (i counting from zero) @@ -38,7 +38,7 @@ SEE ALSO ## ## 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 +## 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 @@ -46,8 +46,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:45 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:45 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/matsum b/help/matsum index db48872..30769de 100644 --- a/help/matsum +++ b/help/matsum @@ -5,9 +5,9 @@ SYNOPSIS matsum(m) TYPES - m matrix with any types of elements + m matrix with any types of elements - return number + return number DESCRIPTION Returns the sum of the numeric (real or complex) elements of m. @@ -37,7 +37,7 @@ SEE ALSO ## ## 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 +## 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 @@ -45,8 +45,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:46 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:46 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/mattrace b/help/mattrace index 83f4b05..685a4bf 100644 --- a/help/mattrace +++ b/help/mattrace @@ -5,16 +5,16 @@ SYNOPSIS mattrace(m) TYPES - m square matrix with summable diagonal elements + m square matrix with summable diagonal elements - return determined by addition of elements + return determined by addition of elements DESCRIPTION For a two-dimensional square matrix, mattrace(m) returns the sum of the elements on the principal diagonal. In particular, if m has been created by mat m[N,N] where N > 0, mattrace(m) returns - m[0,0] + m{1,1] + ... + m[N-1,N-1] + m[0,0] + m{1,1] + ... + m[N-1,N-1] EXAMPLE ; mat m[2,2] = {1,2,3,4} @@ -38,7 +38,7 @@ SEE ALSO ## ## 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 +## 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 @@ -46,8 +46,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/09/06 20:03:35 -## File existed as early as: 1997 +## Under source code control: 1997/09/06 20:03:35 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/mattrans b/help/mattrans index d155349..c20b1e8 100644 --- a/help/mattrans +++ b/help/mattrans @@ -5,9 +5,9 @@ SYNOPSIS mattrans(m) TYPES - m 2-dimensional matrix + m 2-dimensional matrix - return 2-dimensional matrix + return 2-dimensional matrix DESCRIPTION Returns the matrix whose [i,j] element is the [j,1] element of m. @@ -43,7 +43,7 @@ SEE ALSO ## ## 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 +## 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 @@ -51,8 +51,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:46 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:46 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/max b/help/max index 084051d..f1fca4c 100644 --- a/help/max +++ b/help/max @@ -5,9 +5,9 @@ SYNOPSIS max(x_1, x_2, ...) TYPES - x_1, x_2, ... any + x_1, x_2, ... any - return any + return any DESCRIPTION If an argument x_i is a list with elements e_1, e_2, ..., e_n, it @@ -18,7 +18,7 @@ DESCRIPTION xx_max(x_i) if the function xx_max() has been defined. If the type xx has been defined by: - obj xx = {x, y, z}, + obj xx = {x, y, z}, an appropriate definition of xx_max(a) is sometimes max(a.x, a.y, a.z). max(a) then returns the maximum of the elements of a. @@ -34,9 +34,9 @@ DESCRIPTION and returns a real-number value for any comparison that has to be made, max(x_1, x_2, ...) returns the value determined by max(x_1) = x_1, and successively for later arguments, by the use of the equivalent of - max(a,b) = (a < b) ? b : a. If the ordering determined by < is total, + max(a,b) = (a < b) ? b : a. If the ordering determined by < is total, max(x_1, ...) will be the maximum value among the arguments. For a - pre-order relation it may be one of several maximal values. For + pre-order relation it may be one of several maximal values. For other relations, it may be difficult to predict the result. EXAMPLE @@ -78,7 +78,7 @@ SEE ALSO ## ## 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 +## 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 @@ -86,8 +86,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:27 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:27 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/memsize b/help/memsize index 33d0ca3..b133446 100644 --- a/help/memsize +++ b/help/memsize @@ -5,12 +5,12 @@ SYNOPSIS memsize(x) TYPES - x any + x any - return integer + return integer DESCRIPTION - This is analogous to the C operator sizeof. It attempts to assess + This is analogous to the C operator sizeof. It attempts to assess the number of bytes in memory used to store a value and all its components plus all of the related structure overhead. Unlike sizeof(x), this builtin includes overhead. @@ -19,7 +19,7 @@ DESCRIPTION end of strings. Unlike sizeof(x), this builtin includes the size denominator for integers - and the imaginary part for complex values. Storage for holding + and the imaginary part for complex values. Storage for holding 0, 1 and -1 values are also included. The number returned by memsize(x) may be less than the actual number @@ -32,15 +32,15 @@ DESCRIPTION substantially greater) than the number of bytes actually used. For example, after: - a = sqrt(2); - mat A[3] = {a, a, a}; + a = sqrt(2); + mat A[3] = {a, a, a}; the numerical information for a, A[0], A[1], A[2] are stored in the same memory, so the memory used for A is the same as if its 3 elements were null values. The value returned by memsize(A) is calculated as A were defined by: - mat A[3] = {sqrt(2), sqrt(2), sqrt(2)}. + mat A[3] = {sqrt(2), sqrt(2), sqrt(2)}. Similar sharing of memory occurs with literal strings. @@ -98,7 +98,7 @@ SEE ALSO ## ## 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 +## 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 @@ -106,8 +106,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/03/23 20:28:02 -## File existed as early as: 1997 +## Under source code control: 1997/03/23 20:28:02 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/meq b/help/meq index a5cd516..8e8173d 100644 --- a/help/meq +++ b/help/meq @@ -5,11 +5,11 @@ SYNOPSIS meq(x, y, md) TYPES - x real - y real - md real + x real + y real + md real - return 0 or 1 + return 0 or 1 DESCRIPTION Returns 1 if and only if for some integer n, x - y = n * md, i.e. @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/09 03:27:51 -## File existed as early as: 1995 +## Under source code control: 1995/11/09 03:27:51 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/min b/help/min index 8da96c7..0fd8d4d 100644 --- a/help/min +++ b/help/min @@ -5,9 +5,9 @@ SYNOPSIS min(x_1, x_2, ...) TYPES - x_1, x_2, ... any + x_1, x_2, ... any - return any + return any DESCRIPTION If an argument x_i is a list with elements e_1, e_2, ..., e_n, it @@ -18,7 +18,7 @@ DESCRIPTION xx_min(x_i) if the function xx_min() has been defined. If the type xx has been defined by: - obj xx = {x, y, z}, + obj xx = {x, y, z}, an appropriate definition of xx_min(a) is sometimes min(a.x, a.y, a.z). min(a) then returns the minimum of the elements of a. @@ -34,9 +34,9 @@ DESCRIPTION and returns a real-number value for any comparison that has to be made, min(x_1, x_2, ...) returns the value determined by min(x_1) = x_1, and successively for later arguments, by the use of the equivalent of - min(a,b) = (a < b) ? a : b. If the ordering determined by < is total, + min(a,b) = (a < b) ? a : b. If the ordering determined by < is total, min(x_1, ...) will be the minimum value among the arguments. For a - pre-order relation it may be one of several minimal values. For other + pre-order relation it may be one of several minimal values. For other relations, it may be difficult to predict the result. EXAMPLE @@ -78,7 +78,7 @@ SEE ALSO ## ## 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 +## 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 @@ -86,8 +86,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:27 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:27 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/minv b/help/minv index 4519dc3..83c495b 100644 --- a/help/minv +++ b/help/minv @@ -5,10 +5,10 @@ SYNOPSIS minv(x, md) TYPES - x integer - md integer + x integer + md integer - return integer + return integer DESCRIPTION If x and md are not relatively prime, zero is returned. @@ -17,16 +17,16 @@ DESCRIPTION residues modulo md are determined as follows by md and bits 0, 2 and 4 of config("mod") (other bits are ignored). - config("mod") md > 0 md < 0 + config("mod") md > 0 md < 0 - 0 0 < v < md md < v < 0 - 1 -md < v < 0 0 < v < -md - 4 0 < v < md 0 < v < -md - 5 -md < v < 0 md < v < 0 - 16 -md/2 < v <= md/2 md/2 <= v < -md/2 - 17 -md/2 <= v < md/2 md/2 < v <= -md/2 - 20 -md/2 < v <= md/2 md/2 < v <= -md/2 - 21 -md/2 <= v < md/2 md/2 <= v < -md/2 + 0 0 < v < md md < v < 0 + 1 -md < v < 0 0 < v < -md + 4 0 < v < md 0 < v < -md + 5 -md < v < 0 md < v < 0 + 16 -md/2 < v <= md/2 md/2 <= v < -md/2 + 17 -md/2 <= v < md/2 md/2 < v <= -md/2 + 20 -md/2 < v <= md/2 md/2 < v <= -md/2 + 21 -md/2 <= v < md/2 md/2 <= v < -md/2 EXAMPLE ; c = config("mod", 0) @@ -54,7 +54,7 @@ SEE ALSO ## ## 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 +## 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 @@ -62,8 +62,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/09 03:27:51 -## File existed as early as: 1995 +## Under source code control: 1995/11/09 03:27:51 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/mmin b/help/mmin index 3dec3ae..62d4e1b 100644 --- a/help/mmin +++ b/help/mmin @@ -5,10 +5,10 @@ SYNOPSIS mmin(x, md) TYPES - x number (real or complex), matrix, list, object - md real + x number (real or complex), matrix, list, object + md real - return real + return real DESCRIPTION If x is real and md is nonzero, mmin(x, md) returns the real @@ -44,7 +44,7 @@ SEE ALSO ## ## 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 +## 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 @@ -52,8 +52,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 03:30:59 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 03:30:59 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/mne b/help/mne index d4d101e..3c42bd6 100644 --- a/help/mne +++ b/help/mne @@ -5,11 +5,11 @@ SYNOPSIS mne(x, y, md) TYPES - x real number - y real number - md real number + x real number + y real number + md real number - return 0 or 1 + return 0 or 1 DESCRIPTION Returns 1 if and only if x is not congruent to y modulo md, i.e. @@ -36,7 +36,7 @@ SEE ALSO ## ## 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 +## 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 @@ -44,8 +44,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/09 03:27:51 -## File existed as early as: 1995 +## Under source code control: 1995/11/09 03:27:51 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/mod b/help/mod index 33ae81c..59e9537 100644 --- a/help/mod +++ b/help/mod @@ -16,35 +16,35 @@ TYPES If neither x nor y is an object, or x is not a matrix or list: - x number (real or complex) - y real - rnd integer, defaults to config("mod") + x number (real or complex) + y real + rnd integer, defaults to config("mod") - return number + return number DESCRIPTION The expression: - x % y + x % y is equivalent to call: - mod(x, y) + mod(x, y) The function: - mod(x, y, rnd) + mod(x, y, rnd) is equivalent to: - config("mod", rnd), x % y + config("mod", rnd), x % y except that the global config("mod") value does not change. If x is real or complex and y is zero, mod(x, y, rnd) returns x. If x is complex, mod(x, y, rnd) returns - mod(re(x), y, rnd) + mod(im(x), y, rnd) * 1i. + mod(re(x), y, rnd) + mod(im(x), y, rnd) * 1i. In the following it is assumed x is real and y is nonzero. @@ -60,40 +60,40 @@ DESCRIPTION set and abs(r) = abs(y)/2, or if bit 4 of r is not set, the result for r depends on rnd as in the following table: - rnd & 15 sign of r parity of q + rnd & 15 sign of r parity of q - 0 sgn(y) - 1 -sgn(y) - 2 sgn(x) - 3 -sgn(x) - 4 + - 5 - - 6 sgn(x/y) - 7 -sgn(x/y) - 8 even - 9 odd - 10 even if x/y > 0, otherwise odd - 11 odd if x/y > 0, otherwise even - 12 even if y > 0, otherwise odd - 13 odd if y > 0, otherwise even - 14 even if x > 0, otherwise odd - 15 odd if x > 0, otherwise even + 0 sgn(y) + 1 -sgn(y) + 2 sgn(x) + 3 -sgn(x) + 4 + + 5 - + 6 sgn(x/y) + 7 -sgn(x/y) + 8 even + 9 odd + 10 even if x/y > 0, otherwise odd + 11 odd if x/y > 0, otherwise even + 12 even if y > 0, otherwise odd + 13 odd if y > 0, otherwise even + 14 even if x > 0, otherwise odd + 15 odd if x > 0, otherwise even - NOTE: Blank entries in the table above indicate that the - description would be complicated and probably not of - much interest. + NOTE: Blank entries in the table above indicate that the + description would be complicated and probably not of + much interest. The C language method of modulus and integer division is: - config("quomod", 2) - config("quo", 2) - config("mod", 2) + config("quomod", 2) + config("quo", 2) + config("mod", 2) This dependence on rnd is consistent with quo(x, y, rnd) and appr(x, y, rnd) in that for any real x and y and any integer rnd, - x = y * quo(x, y, rnd) + mod(x, y, rnd). - mod(x, y, rnd) = x - appr(x, y, rnd) + x = y * quo(x, y, rnd) + mod(x, y, rnd). + mod(x, y, rnd) = x - appr(x, y, rnd) If y and rnd are fixed and mod(x, y, rnd) is to be considered as a canonical residue of x % y, bits 1 and 3 of rnd should be @@ -101,11 +101,11 @@ DESCRIPTION 20, or 21, that the set of possible values for mod(x, y, rnd) form an interval of length y, and for any x1, x2, - mod(x1, y, rnd) = mod(x2, y, rnd) + mod(x1, y, rnd) = mod(x2, y, rnd) is equivalent to: - x1 is congruent to x2 modulo y. + x1 is congruent to x2 modulo y. This is particularly relevant when working with the ring of integers modulo an integer y. @@ -121,11 +121,11 @@ EXAMPLE ; print mod(A,10,0) list (5 elements, 5 nonzero): - [[0]] = 1 - [[1]] = 3 - [[2]] = 7 - [[3]] = 3 - [[4]] = 9 + [[0]] = 1 + [[1]] = 3 + [[2]] = 7 + [[3]] = 3 + [[4]] = 9 LIMITS none @@ -145,7 +145,7 @@ SEE ALSO ## ## 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 +## 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 @@ -153,8 +153,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/09/18 02:09:31 -## File existed as early as: 1995 +## Under source code control: 1995/09/18 02:09:31 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/modify b/help/modify index 323050c..6b69106 100644 --- a/help/modify +++ b/help/modify @@ -5,17 +5,17 @@ SYNOPSIS modify(A, fname) TYPES - A lvalue with list, matrix or object value - fname string, the name of a user-defined function + A lvalue with list, matrix or object value + fname string, the name of a user-defined function - return null value if successful, otherwise an error value + return null value if successful, otherwise an error value DESCRIPTION The value of each element of A is replaced by the value at that value of the user-defined function with name fname. Thus, modify(A, "f") has the effect of - for (i = 0; i < size(A); i++) A[[i]] = f(A[[i]]); + for (i = 0; i < size(A); i++) A[[i]] = f(A[[i]]); An error value is returned if A is not of acceptable type, if A has no-change protection, or if there is no user-defined function with @@ -28,11 +28,11 @@ DESCRIPTION To obtain a modified copy of A without changing values in A, one may use - Amod = A; modify(A, fname) + Amod = A; modify(A, fname) or more simply - modify(Amod = A, fname). + modify(Amod = A, fname). EXAMPLE ; define f(x) = x^2 @@ -41,9 +41,9 @@ EXAMPLE ; print A list (3 elements, 3 nonzero): - [[0]] = 4 - [[1]] = 16 - [[3]] = 36 + [[0]] = 4 + [[1]] = 16 + [[3]] = 36 LIMITS none @@ -62,7 +62,7 @@ SEE ALSO ## ## 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 +## 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 @@ -70,8 +70,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/10 02:09:31 -## File existed as early as: 1995 +## Under source code control: 1995/07/10 02:09:31 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/name b/help/name index 05172ca..897e2a4 100644 --- a/help/name +++ b/help/name @@ -5,9 +5,9 @@ SYNOPSIS name(val) TYPES - val any + val any - return string or null value + return string or null value DESCRIPTION If val is a named block or open file stream, name(val) returns the @@ -20,14 +20,14 @@ DESCRIPTION EXAMPLE ; A = blk("alpha"); ; name(A) - "alpha" + "alpha" ; f = fopen("/tmp/beta", "w") ; name(f) - "/tmp/beta" + "/tmp/beta" ; name(files(0)) - "(stdin)" + "(stdin)" LIMITS none @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/04/05 14:12:44 -## File existed as early as: 1997 +## Under source code control: 1997/04/05 14:12:44 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/near b/help/near index 2f81c6c..a244e61 100644 --- a/help/near +++ b/help/near @@ -5,17 +5,17 @@ SYNOPSIS near(x, y [,eps]) TYPES - x real - y real - eps 0 < real < 1, defaults to epsilon() + x real + y real + eps 0 < real < 1, defaults to epsilon() - return -1, 0 or 1 + return -1, 0 or 1 DESCRIPTION Returns: - -1 if abs(x - y) < abs(eps) - 0 if abs(x - y) = abs(eps) - 1 if abs(x - y) > abs(eps) + -1 if abs(x - y) < abs(eps) + 0 if abs(x - y) = abs(eps) + 1 if abs(x - y) > abs(eps) EXAMPLE ; print near(22/7, 3.15, .01), near(22/7, 3.15, .005) @@ -38,7 +38,7 @@ SEE ALSO ## ## 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 +## 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 @@ -46,8 +46,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:46 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:46 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/newerror b/help/newerror index 00b8f5e..4828928 100644 --- a/help/newerror +++ b/help/newerror @@ -5,9 +5,9 @@ SYNOPSIS newerror([str]) TYPES - str string + str string - return error-value + return error-value DESCRIPTION If str is not "" and has not earlier been used as an argument for @@ -35,25 +35,25 @@ EXAMPLE Error 20000 caused errcount to exceed errmax ; errmax(errcount()+5) - 0 + 0 ; e1 = newerror("triangle side length <= 0") ; iserror(e1) - 20000 + 20000 ; error(20000) - Error E_20000 + Error E_20000 ; strerror(error(20000)) - "triangle side length <= 0" + "triangle side length <= 0" ; strerror(e1); - "triangle side length <= 0" + "triangle side length <= 0" ; strerror(error(iserror(e1))) - "triangle side length <= 0" + "triangle side length <= 0" ; define area(a,b,c) { - ;; local s; - ;; if (!(a > 0) || !(b > 0) || !(c > 0)) return e1; - ;; s = (a + b + c)/2; - ;; if (s <= a || s <= b || s <= c) return newerror("Non-triangle sides"); - ;; return sqrt(s * (s - a) * (s - b) * (s - c)); + ;; local s; + ;; if (!(a > 0) || !(b > 0) || !(c > 0)) return e1; + ;; s = (a + b + c)/2; + ;; if (s <= a || s <= b || s <= c) return newerror("Non-triangle sides"); + ;; return sqrt(s * (s - a) * (s - b) * (s - c)); ;; } "area" defined @@ -83,7 +83,7 @@ SEE ALSO ## ## 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 +## 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 @@ -91,8 +91,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:39:56 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:39:56 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/nextcand b/help/nextcand index 2d19d3a..35977fc 100644 --- a/help/nextcand +++ b/help/nextcand @@ -5,13 +5,13 @@ SYNOPSIS nextcand(n [,count [, skip [, residue [,modulus]]]]) TYPES - n integer - count integer with absolute value less than 2^24, defaults to 1 - skip integer. defaults to 1 - residue integer, defaults to 0 - modulus integer, defaults to 1 + n integer + count integer with absolute value less than 2^24, defaults to 1 + skip integer. defaults to 1 + residue integer, defaults to 0 + modulus integer, defaults to 1 - return integer + return integer DESCRIPTION If modulus is nonzero, nextcand(n, count, skip, residue, modulus) @@ -43,7 +43,7 @@ DESCRIPTION RUNTIME The runtime for v = nextcand(n, ...) will depend strongly on the - number and nature of the integers between n and v. If this number + number and nature of the integers between n and v. If this number is reasonably large the size of count is largely irrelevant as the compositeness of the numbers between n and v will usually be determined by the test for small prime factors or one pseudoprime @@ -71,7 +71,7 @@ LIMITS LINK LIBRARY int znextcand(ZVALUE n, long count, long skip, ZVALUE res, ZVALUE mod, - ZVALUE *cand) + ZVALUE *cand) SEE ALSO factor, isprime, lfactor, nextprime, prevcand, prevprime, @@ -85,7 +85,7 @@ SEE ALSO ## ## 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 +## 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 @@ -93,8 +93,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/02/25 00:27:43 -## File existed as early as: 1996 +## Under source code control: 1996/02/25 00:27:43 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/nextprime b/help/nextprime index bb5cce4..753feef 100644 --- a/help/nextprime +++ b/help/nextprime @@ -5,10 +5,10 @@ SYNOPSIS nextprime(n [,err]) TYPES - n real - err integer + n real + err integer - return positive integer or err + return positive integer or err DESCRIPTION If n is an integer less than 2^32, nextprime(n) returns the @@ -44,7 +44,7 @@ SEE ALSO ## ## 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 +## 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 @@ -52,8 +52,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 12:34:57 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 12:34:57 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/norm b/help/norm index 26d1d01..c8ede78 100644 --- a/help/norm +++ b/help/norm @@ -10,18 +10,18 @@ TYPES For non-object x: - x number (real or complex) + x number (real or complex) - return real + return real DESCRIPTION For real x, norm(x) returns: - x^2. + x^2. For complex x, norm(x) returns: - re(x)^2 + im(x)^2. + re(x)^2 + im(x)^2. EXAMPLE ; print norm(3.4), norm(-3.4), norm(3 + 4i), norm(4 - 5i) @@ -44,7 +44,7 @@ SEE ALSO ## ## 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 +## 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 @@ -52,8 +52,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:46 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:46 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/null b/help/null index dd33dcc..d7f8f55 100644 --- a/help/null +++ b/help/null @@ -5,8 +5,8 @@ SYNOPSIS null([v_1, v_2,...]) TYPES - v_1, v_2,... any - return null + v_1, v_2,... any + return null DESCRIPTION After evaluating in order any arguments it may have, null(...) @@ -27,9 +27,9 @@ DESCRIPTION Missing expressions in argument lists are assigned the null value. For example, after - define f(a,b,c) = ... + define f(a,b,c) = ... calling - f(1,2) + f(1,2) is as if c == null(). Similarly, f(1,,2) is as if b == null(). (Note that this does not occur in initialization lists; missing expressions there indicate no change.) @@ -54,16 +54,16 @@ EXAMPLE ; print L list (5 elements, 5 nonzero): - [[0]] = NULL - [[1]] = 1 - [[2]] = NULL - [[3]] = 2 - [[4]] = NULL + [[0]] = NULL + [[1]] = 1 + [[2]] = NULL + [[3]] = 2 + [[4]] = NULL ; a = 27 ; null(pi = pi(1e-1000)) ; . - 27 + 27 LIMITS The number of arguments is not to exceed 1024. @@ -82,7 +82,7 @@ SEE ALSO ## ## 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 +## 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 @@ -90,8 +90,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/03/12 23:10:01 -## File existed as early as: 1996 +## Under source code control: 1996/03/12 23:10:01 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/num b/help/num index 9902994..35a972d 100644 --- a/help/num +++ b/help/num @@ -5,22 +5,22 @@ SYNOPSIS num(x) TYPES - x real + x real - return integer + return integer DESCRIPTION For real x, den(x) returns the denominator of x. In calc, real values are actually rational values. Each calc real value can be uniquely expressed as: - n / d + n / d where: - n and d are integers - gcd(n,d) == 1 - d > 0 + n and d are integers + gcd(n,d) == 1 + d > 0 If x = n/x, then den(x) == n. @@ -45,7 +45,7 @@ SEE ALSO ## ## 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 +## 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 @@ -53,8 +53,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:27 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:27 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/obj.file b/help/obj.file index 8dd8600..cd00b4a 100644 --- a/help/obj.file +++ b/help/obj.file @@ -10,12 +10,12 @@ Using objects An example object type is "surd", which represents numbers of the form - a + b*sqrt(D), + a + b*sqrt(D), where D is a fixed integer, and 'a' and 'b' are arbitrary rational numbers. Addition, subtraction, multiplication, and division can be performed on such numbers, and the result can be put unambiguously - into the same form. (Complex numbers are an example of surds, where + into the same form. (Complex numbers are an example of surds, where D is -1.) The "obj" statement defines either an object type or an actual @@ -23,7 +23,7 @@ Using objects its elements are specified inside of a pair of braces. To define the surd object type, the following could be used: - obj surd {a, b}; + obj surd {a, b}; Here a and b are the element names for the two components of the surd object. An object type can be defined more than once as long @@ -35,15 +35,15 @@ Using objects 'surd', a function called 'surd' can be defined to set the two components as follows: - define surd(a, b) - { - local x; + define surd(a, b) + { + local x; - obj surd x; - x.a = a; - x.b = b; - return x; - } + obj surd x; + x.a = a; + x.b = b; + return x; + } When an operation is attempted for an object, user functions with particular names are automatically called to perform the operation. @@ -53,8 +53,8 @@ Using objects called. The user function is called with the necessary arguments for that - operation. For example, for "surd_mul", there are two arguments, - which are the two numbers. The order of the arguments is always + operation. For example, for "surd_mul", there are two arguments, + which are the two numbers. The order of the arguments is always the order of the binary operands. If only one of the operands to a binary operator is an object, then the user function for that object type is still called. If the two operands are of different @@ -64,47 +64,47 @@ Using objects The above rules mean that for full generality, user functions should detect that one of their arguments is not of its own object type by using the 'istype' function, and then handle these cases - specially. In this way, users can mix normal numbers with object + specially. In this way, users can mix normal numbers with object types. (Functions which only have one operand don't have to worry about this.) The following example of "surd_mul" demonstrates how to handle regular numbers when used together with surds: - define surd_mul(a, b) - { - local x; + define surd_mul(a, b) + { + local x; - obj surd x; - if (!istype(a, x)) { - /* a not of type surd */ - x.a = b.a * a; - x.b = b.b * a; - } else if (!istype(b, x)) { - /* b not of type surd */ - x.a = a.a * b; - x.b = a.b * b; - } else { - /* both are surds */ - x.a = a.a * b.a + D * a.b * b.b; - x.b = a.a * b.b + a.b * b.a; - } - if (x.b == 0) - return x.a; /* normal number */ - return x; /* return surd */ - } + obj surd x; + if (!istype(a, x)) { + /* a not of type surd */ + x.a = b.a * a; + x.b = b.b * a; + } else if (!istype(b, x)) { + /* b not of type surd */ + x.a = a.a * b; + x.b = a.b * b; + } else { + /* both are surds */ + x.a = a.a * b.a + D * a.b * b.b; + x.b = a.a * b.b + a.b * b.a; + } + if (x.b == 0) + return x.a; /* normal number */ + return x; /* return surd */ + } In order to print the value of an object nicely, a user defined routine can be provided. For small amounts of output, the print - routine should not print a newline. Also, it is most convenient + routine should not print a newline. Also, it is most convenient if the printed object looks like the call to the creation routine. For output to be correctly collected within nested output calls, output should only go to stdout. This means use the 'print' statement, the 'printf' function, or the 'fprintf' function with 'files(1)' as the output file. For example, for the "surd" object: - define surd_print(a) - { - print "surd(" : a.a : "," : a.b : ")" : ; - } + define surd_print(a) + { + print "surd(" : a.a : "," : a.b : ")" : ; + } It is not necessary to provide routines for all possible operations for an object, if those operations can be defaulted or do not make @@ -121,80 +121,80 @@ Using objects in order to make object calls quicker in general. The double-bracket operator can be used to reference the elements - of any object in a generic manner. When this is done, index 0 + of any object in a generic manner. When this is done, index 0 corresponds to the first element name, index 1 to the second name, - and so on. The 'size' function will return the number of elements + and so on. The 'size' function will return the number of elements in an object. The following is a list of the operations possible for objects. The 'xx' in each function name is replaced with the actual object - type name. This table is displayed by the 'show objfunctions' command. + type name. This table is displayed by the 'show objfunctions' command. - Name Args Comments + Name Args Comments - xx_print 1 print value, default prints elements - xx_one 1 multiplicative identity, default is 1 - xx_test 1 logical test (false,true => 0,1), - default tests elements - xx_add 2 - xx_sub 2 - xx_neg 1 negative - xx_mul 2 - xx_div 2 non-integral division - xx_inv 1 multiplicative inverse - xx_abs 2 absolute value within given error - xx_norm 1 square of absolute value - xx_conj 1 conjugate - xx_pow 2 integer power, default does multiply, - square, inverse - xx_sgn 1 sign of value (-1, 0, 1) - xx_cmp 2 equality (equal,nonequal => 0,1), - default tests elements - xx_rel 2 relative order, positive for >, etc. - xx_quo 3 integer quotient - xx_mod 3 remainder of division - xx_int 1 integer part - xx_frac 1 fractional part - xx_inc 1 increment, default adds 1 - xx_dec 1 decrement, default subtracts 1 - xx_square 1 default multiplies by itself - xx_scale 2 multiply by power of 2 - xx_shift 2 shift left by n bits (right if negative) - xx_round 3 round to given number of decimal places - xx_bround 3 round to given number of binary places - xx_root 3 root of value within given error - xx_sqrt 3 square root within given error - xx_or 2 bitwise or - xx_and 2 bitwise and - xx_not 1 logical not - xx_fact 1 factorial or postfix ! - xx_min 1 value for min(...) - xx_max 1 value for max(...) - xx_sum 1 value for sum(...) - xx_assign 2 assign, defaults to a = b - xx_xor 2 value for binary ~ - xx_comp 1 value for unary ~ - xx_content 1 unary hash op - xx_hashop 2 binary hash op - xx_backslash 1 unary backslash op - xx_setminus 2 binary backslash op - xx_plus 1 unary + op + xx_print 1 print value, default prints elements + xx_one 1 multiplicative identity, default is 1 + xx_test 1 logical test (false,true => 0,1), + default tests elements + xx_add 2 + xx_sub 2 + xx_neg 1 negative + xx_mul 2 + xx_div 2 non-integral division + xx_inv 1 multiplicative inverse + xx_abs 2 absolute value within given error + xx_norm 1 square of absolute value + xx_conj 1 conjugate + xx_pow 2 integer power, default does multiply, + square, inverse + xx_sgn 1 sign of value (-1, 0, 1) + xx_cmp 2 equality (equal,nonequal => 0,1), + default tests elements + xx_rel 2 relative order, positive for >, etc. + xx_quo 3 integer quotient + xx_mod 3 remainder of division + xx_int 1 integer part + xx_frac 1 fractional part + xx_inc 1 increment, default adds 1 + xx_dec 1 decrement, default subtracts 1 + xx_square 1 default multiplies by itself + xx_scale 2 multiply by power of 2 + xx_shift 2 shift left by n bits (right if negative) + xx_round 3 round to given number of decimal places + xx_bround 3 round to given number of binary places + xx_root 3 root of value within given error + xx_sqrt 3 square root within given error + xx_or 2 bitwise or + xx_and 2 bitwise and + xx_not 1 logical not + xx_fact 1 factorial or postfix ! + xx_min 1 value for min(...) + xx_max 1 value for max(...) + xx_sum 1 value for sum(...) + xx_assign 2 assign, defaults to a = b + xx_xor 2 value for binary ~ + xx_comp 1 value for unary ~ + xx_content 1 unary hash op + xx_hashop 2 binary hash op + xx_backslash 1 unary backslash op + xx_setminus 2 binary backslash op + xx_plus 1 unary + op Also see the standard resource files: - deg.cal - dms.cal - ellip.cal - hms.cal - mod.cal - natnumset.cal - poly.cal - quat.cal - regress.cal - set8700.cal - surd.cal - test2300.cal - test3100.cal + deg.cal + dms.cal + ellip.cal + hms.cal + mod.cal + natnumset.cal + poly.cal + quat.cal + regress.cal + set8700.cal + surd.cal + test2300.cal + test3100.cal ## Copyright (C) 1999,2010,2021 Landon Curt Noll ## @@ -204,7 +204,7 @@ Using objects ## ## 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 +## 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 @@ -212,8 +212,8 @@ Using objects ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:22 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:22 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/oldvalue b/help/oldvalue index 07dc3f0..d04f7a8 100644 --- a/help/oldvalue +++ b/help/oldvalue @@ -5,14 +5,14 @@ SYNOPSIS . (with no adjacent letters or digits or _ or .) TYPES - return any + return any DESCRIPTION The "old value" is essentially a global variable with identifier "." which at top level when directly from a file or keyboard is automatically assigned the saved value for a line of statements when evaluation of that line is completed and this saved - value is not null. A line of statements is normally completed by a + value is not null. A line of statements is normally completed by a '\n' not within a block bounded by braces or an expression bounded by parentheses. @@ -26,7 +26,7 @@ EXAMPLE ; saveval(1); ; a = 2 ; . - 2 + 2 ; . += 3; b = . + 4 ; print ., b 9 9 @@ -36,9 +36,9 @@ EXAMPLE ; list(a, b, a + b) list (3 elements, 3 nonzero): - [[0]] = 2 - [[1]] = 16 - [[2]] = 18 + [[0]] = 2 + [[1]] = 16 + [[2]] = 18 ; saveval(0) ; print pop(.), .[[1]] @@ -61,7 +61,7 @@ SEE ALSO ## ## 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 +## 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 @@ -69,8 +69,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/09/06 20:03:35 -## File existed as early as: 1997 +## Under source code control: 1997/09/06 20:03:35 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/operator b/help/operator index 2c09bb4..c8f4168 100644 --- a/help/operator +++ b/help/operator @@ -1,7 +1,7 @@ operators The operators are similar to C, but there are some differences in - the associativity and precedence rules for some operators. In + the associativity and precedence rules for some operators. In addition, there are several operators not in C, and some C operators are missing. A more detailed discussion of situations that may be unexpected for the C programmer may be found in @@ -18,35 +18,35 @@ operators skipping of terms may occur for ||, && and ? : . For example, an expression of the form: - A * B + C * D + A * B + C * D is evaluated in the following order: - A - B - A * B - C - D - C * D - A * B + C * D + A + B + A * B + C + D + C * D + A * B + C * D This order of evaluation is significant if evaluation of a term changes a variable on which a later term depends. For example: - x++ * x++ + x++ * x++ + x++ * x++ + x++ * x++ returns the value of: - x * (x + 1) + (x + 2) * (x + 3) + x * (x + 1) + (x + 2) * (x + 3) and increments x as if by x += 4. Similarly, for functions f, g, the expression: - f(x++, x++) + g(x++) + f(x++, x++) + g(x++) evaluates to: - f(x, x + 1) + g(x + 2) + f(x, x + 1) + g(x + 2) and increments x three times. @@ -56,153 +56,153 @@ operators it returns x + 1 and increments x twice. - , Comma operator. - a, b returns the value of b. - For situations in which a comma is used for another purpose - (function arguments, array indexing, and the print statement), - parenthesis must be used around the comma operator expression. - E.g., if A is a matrix, A[(a, b), c] evaluates a, b, and c, and - returns the value of A[b, c]. + , Comma operator. + a, b returns the value of b. + For situations in which a comma is used for another purpose + (function arguments, array indexing, and the print statement), + parenthesis must be used around the comma operator expression. + E.g., if A is a matrix, A[(a, b), c] evaluates a, b, and c, and + returns the value of A[b, c]. - += -= *= /= %= //= &= |= <<= >>= ^= **= - Operator-with-assignments. - These associate from left to right, e.g. a += b *= c has the - effect of a = (a + b) * c, where only a is required to be an - lvalue. For the effect of b *= c; a += b; when both a and b - are lvalues, use a += (b *= c). + += -= *= /= %= //= &= |= <<= >>= ^= **= + Operator-with-assignments. + These associate from left to right, e.g. a += b *= c has the + effect of a = (a + b) * c, where only a is required to be an + lvalue. For the effect of b *= c; a += b; when both a and b + are lvalues, use a += (b *= c). - = Assignment. - As in C, this, when repeated, this associates from right to left, - e.g. a = b = c has the effect of a = (b = c). Here both a and b - are to be lvalues. + = Assignment. + As in C, this, when repeated, this associates from right to left, + e.g. a = b = c has the effect of a = (b = c). Here both a and b + are to be lvalues. ? : Conditional value. - a ? b : c returns b if a tests as true (i.e. nonzero if - a is a number), c otherwise. Thus it is equivalent to: - if (a) return b; else return c;. - All that is required of the arguments in this function - is that the "is-it-true?" test is meaningful for a. - As in C, this operator associates from right to left, - i.e. a ? b : c ? d : e is evaluated as a ? b : (c ? d : e). + a ? b : c returns b if a tests as true (i.e. nonzero if + a is a number), c otherwise. Thus it is equivalent to: + if (a) return b; else return c;. + All that is required of the arguments in this function + is that the "is-it-true?" test is meaningful for a. + As in C, this operator associates from right to left, + i.e. a ? b : c ? d : e is evaluated as a ? b : (c ? d : e). - || Logical OR. - Unlike C, the result for a || b is one of the operands - a, b rather than one of the numbers 0 and 1. - a || b is equivalent to a ? a : b, i.e. if a tests as - true, a is returned, otherwise b. The effect in a - test like "if (a || b) ... " is the same as in C. + || Logical OR. + Unlike C, the result for a || b is one of the operands + a, b rather than one of the numbers 0 and 1. + a || b is equivalent to a ? a : b, i.e. if a tests as + true, a is returned, otherwise b. The effect in a + test like "if (a || b) ... " is the same as in C. - && Logical AND. - Unlike C, the result for a && b is one of the operands - a, b rather than one of the numbers 0 and 1. - a && b is equivalent to a ? b : a, i.e. if a tests as - true, b is returned, otherwise a. The effect in a - test like "if (a && b) ... " is the same as in C. + && Logical AND. + Unlike C, the result for a && b is one of the operands + a, b rather than one of the numbers 0 and 1. + a && b is equivalent to a ? b : a, i.e. if a tests as + true, b is returned, otherwise a. The effect in a + test like "if (a && b) ... " is the same as in C. - == != <= >= < > - Relations. + == != <= >= < > + Relations. + - - Binary plus and minus and unary plus and minus when applied to - a first or only term. + Binary plus and minus and unary plus and minus when applied to + a first or only term. * / // % - Multiply, divide, and modulo. - Please Note: The '/' operator is a fractional divide, - whereas the '//' is an integral divide. Thus think of '/' - as division of real numbers, and think of '//' as division - of integers (e.g., 8 / 3 is 8/3 whereas 8 // 3 is 2). - The '%' is integral or fractional modulus (e.g., 11%4 is 3, - and 10%pi() is ~0.575222). + Multiply, divide, and modulo. + Please Note: The '/' operator is a fractional divide, + whereas the '//' is an integral divide. Thus think of '/' + as division of real numbers, and think of '//' as division + of integers (e.g., 8 / 3 is 8/3 whereas 8 // 3 is 2). + The '%' is integral or fractional modulus (e.g., 11%4 is 3, + and 10%pi() is ~0.575222). - | Bitwise OR. - In a | b, both a and b are to be real integers; - the signs of a and b are ignored, i.e. - a | b = abs(a) | abs(b) and the result will - be a non-negative integer. + | Bitwise OR. + In a | b, both a and b are to be real integers; + the signs of a and b are ignored, i.e. + a | b = abs(a) | abs(b) and the result will + be a non-negative integer. - & Bitwise AND. - In a & b, both a and b are to be real integers; - the signs of a and b are ignored as for a | b. + & Bitwise AND. + In a & b, both a and b are to be real integers; + the signs of a and b are ignored as for a | b. ^ ** << >> - Powers and shifts. - The '^' and '**' are both exponentiation, e.g. 2^3 - returns 8, 2^-3 returns 0.125. Note that in a^b, if - 'a' == 0 and 'b' is real, then is must be >= 0 as well. - Also 0^0 and 0**0 return the value 1. + Powers and shifts. + The '^' and '**' are both exponentiation, e.g. 2^3 + returns 8, 2^-3 returns 0.125. Note that in a^b, if + 'a' == 0 and 'b' is real, then is must be >= 0 as well. + Also 0^0 and 0**0 return the value 1. - For the shift operators both arguments are to be - integers, or if the first is complex, it is to have - integral real and imaginary parts. Changing the - sign of the second argument reverses the shift, e.g. - a >> -b = a << b. The result has the same sign as - the first argument except that a nonzero value is - reduced to zero by a sufficiently long shift to the - right. These operators associate right to left, - e.g. a << b ^ c = a << (b ^ c). + For the shift operators both arguments are to be + integers, or if the first is complex, it is to have + integral real and imaginary parts. Changing the + sign of the second argument reverses the shift, e.g. + a >> -b = a << b. The result has the same sign as + the first argument except that a nonzero value is + reduced to zero by a sufficiently long shift to the + right. These operators associate right to left, + e.g. a << b ^ c = a << (b ^ c). + - ! - Plus (+) and minus (-) have their usual meanings as unary - prefix operators at this level of precedence when applied to - other than a first or only term. + Plus (+) and minus (-) have their usual meanings as unary + prefix operators at this level of precedence when applied to + other than a first or only term. - As a prefix operator, '!' is the logical NOT: !a returns 0 if - a tests as nonzero, and 1 if a tests as zero, i.e. it is - equivalent to a ? 0 : 1. Be careful about - using this as the first character of a top level command, - since it is also used for executing shell commands. + As a prefix operator, '!' is the logical NOT: !a returns 0 if + a tests as nonzero, and 1 if a tests as zero, i.e. it is + equivalent to a ? 0 : 1. Be careful about + using this as the first character of a top level command, + since it is also used for executing shell commands. - As a postfix operator ! gives the factorial function, i.e. - a! = fact(a). + As a postfix operator ! gives the factorial function, i.e. + a! = fact(a). - ++ -- - Pre or post incrementing or decrementing. - These are applicable only to variables. + ++ -- + Pre or post incrementing or decrementing. + These are applicable only to variables. - [ ] [[ ]] . ( ) - Indexing, double-bracket indexing, element references, - and function calls. Indexing can only be applied to matrices, - element references can only be applied to objects, but - double-bracket indexing can be applied to matrices, objects, - or lists. + [ ] [[ ]] . ( ) + Indexing, double-bracket indexing, element references, + and function calls. Indexing can only be applied to matrices, + element references can only be applied to objects, but + double-bracket indexing can be applied to matrices, objects, + or lists. variables constants . ( ) - These are variable names and constants, the special '.' symbol, - or a parenthesized expression. Variable names begin with a - letter, but then can contain letters, digits, or underscores. - Constants are numbers in various formats, or strings inside - either single or double quote marks. + These are variable names and constants, the special '.' symbol, + or a parenthesized expression. Variable names begin with a + letter, but then can contain letters, digits, or underscores. + Constants are numbers in various formats, or strings inside + either single or double quote marks. The most significant difference from the order of precedence in C is that | and & have higher precedence than ==, +, -, *, / and %. For example, in C a == b | c * d is interpreted as: - (a == b) | (c * d) + (a == b) | (c * d) and calc it is: - a == ((b | c) * d) + a == ((b | c) * d) Most of the operators will accept any real or complex numbers as arguments. The exceptions are: / // % - Second argument must be nonzero. + Second argument must be nonzero. ^ - The exponent must be an integer. When raising zero - to a power, the exponent must be non-negative. + The exponent must be an integer. When raising zero + to a power, the exponent must be non-negative. | & - Both both arguments must be integers. + Both both arguments must be integers. - << >> - The shift amount must be an integer. The value being - shifted must be an integer or a complex number with - integral real and imaginary parts. + << >> + The shift amount must be an integer. The value being + shifted must be an integer or a complex number with + integral real and imaginary parts. See the 'unexpected' help file for a list of unexpected @@ -217,7 +217,7 @@ operators ## ## 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 +## 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 @@ -225,8 +225,8 @@ operators ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:23 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:23 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ord b/help/ord index 29b5f49..2867c86 100644 --- a/help/ord +++ b/help/ord @@ -5,9 +5,9 @@ SYNOPSIS ord(c) TYPES - c string + c string - return int + return int DESCRIPTION Return the integer value of the first character of a string. @@ -33,7 +33,7 @@ SEE ALSO ## ## 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 +## 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 @@ -41,8 +41,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/30 01:45:46 -## File existed as early as: 1994 +## Under source code control: 1994/09/30 01:45:46 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/overview b/help/overview index 5fc064b..ab0c08c 100644 --- a/help/overview +++ b/help/overview @@ -1,18 +1,18 @@ - CALC - An arbitrary precision calculator. - by David I. Bell + CALC - An arbitrary precision calculator. + by David I. Bell This is a calculator program with arbitrary precision arithmetic. All numbers are represented as fractions with arbitrarily large numerators and denominators which are always reduced to lowest terms. Real or exponential format numbers can be input and are converted - to the equivalent fraction. Hex, binary, or octal numbers can be + to the equivalent fraction. Hex, binary, or octal numbers can be input by using numbers with leading '0x', '0b' or '0' characters. Complex numbers can be input using a trailing 'i', as in '2+3i'. Strings and characters are input by using single or double quotes. Commands are statements in a C-like language, where each input - line is treated as the body of a procedure. Thus the command + line is treated as the body of a procedure. Thus the command line can contain variable declarations, expressions, labels, conditional tests, and loops. Assignments to any variable name will automatically define that name as a global variable. The @@ -20,7 +20,7 @@ which are evaluated are automatically printed. Thus, you can evaluate an expression's value by simply typing it in. - Many useful built-in mathematical functions are available. Use + Many useful built-in mathematical functions are available. Use the 'show builtins' command to list them. You can also define your own functions by using the 'define' keyword, followed by a function declaration very similar to C. Functions which only @@ -29,7 +29,7 @@ Variables in functions can be defined as either 'global', 'local', or 'static'. Global variables are common to all functions and the command line, whereas local variables are unique to each function - level, and are destroyed when the function returns. Static variables + level, and are destroyed when the function returns. Static variables are scoped within single input files, or within functions, and are never destroyed. Variables are not typed at definition time, but dynamically change as they are used. So you must supply the correct @@ -40,57 +40,57 @@ every builtin function, command as well as a number of other aspects of calc usage. Try the command: - help help + help help for and overview of the help system. The command: - help builtin + help builtin provides information on built-in mathematical functions, whereas: - help asinh + help asinh will provides information a specific function. The following help files: - help command - help define - help operator - help statement - help variable + help command + help define + help operator + help statement + help variable provide a good overview of the calc language. If you are familiar with C, you should also try: - help unexpected + help unexpected It contains information about differences between C and calc that may surprise you. To learn about calc standard resource files, try: - help resource + help resource To learn how to invoke the calc command and about calc -flags, try: - help usage + help usage To learn about calc shell scripts, try: - help script + help script A full and extensive overview of calc may be obtained by: - help full + help full The man command is an alias for the help command. Try: - man jacobi + man jacobi Only calc help files may be displayed by the help and man commands. By default, arguments to functions are passed by value (even - matrices). For speed, you can put an ampersand before any + matrices). For speed, you can put an ampersand before any variable argument in a function call, and that variable will be passed by reference instead. However, if the function changes its argument, the variable will change. Arguments to built-in @@ -127,17 +127,17 @@ example 'x.real'. All user-defined routines have names composed of the object type and the action to perform separated by an underscore, as in the example 'complex_add'. The command 'show - objfuncs' lists all the definable routines. Object routines + objfuncs' lists all the definable routines. Object routines which accept two arguments should be prepared to handle cases in which either one of the arguments is not of the expected object type. These are the differences between the normal C operators and - the ones defined by the calculator. The '/' operator divides + the ones defined by the calculator. The '/' operator divides fractions, so that '7 / 2' evaluates to 7/2. The '//' operator is an integer divide, so that '7 // 2' evaluates to 3. The '^' operator is a integral power function, so that 3^4 evaluates to - 81. Matrices of any dimension can be treated as a zero based + 81. Matrices of any dimension can be treated as a zero based linear array using double square brackets, as in 'foo[[3]]'. Matrices can be indexed by using commas between the indices, as in foo[3,4]. Object and list elements can be referenced by @@ -149,32 +149,32 @@ output values. A trailing colon suppresses printing of the end of line. An example of printing is - print "The square of", x, "is", x^2 + print "The square of", x, "is", x^2 The 'config' function is used to modify certain parameters that affect calculations or the display of values. For example, the output display mode can be set using: - config("mode", type) + config("mode", type) where 'type' is one of 'frac', 'int', 'real', 'exp', 'hex', - 'oct', or 'bin'. The default output mode is real. For the + 'oct', or 'bin'. The default output mode is real. For the integer, real, or exponential formats, a leading '~' indicates that the number was truncated to the number of decimal places - specified by the default precision. If the '~' does not + specified by the default precision. If the '~' does not appear, then the displayed number is the exact value. The number of decimal places printed is set by using: - config("display", n) + config("display", n) The default precision for real-valued functions can be set by using 'epsilon(x)', where x is the required precision (such as 1e-50). For example: - config("display", 70) - epsilon(1e-70) - sin(1) + config("display", 70) + epsilon(1e-70) + sin(1) There is a command stack feature so that you can easily re-execute previous commands and expressions from the terminal. @@ -194,7 +194,7 @@ ## ## 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 +## 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 @@ -202,8 +202,8 @@ ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:23 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:23 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/param b/help/param index 0497a06..514d13c 100644 --- a/help/param +++ b/help/param @@ -5,9 +5,9 @@ SYNOPSIS param([n]) TYPES - n nonnegative integer + n nonnegative integer - return any + return any DESCRIPTION The function param(n) can be used only within the body of the @@ -15,27 +15,27 @@ DESCRIPTION If that function is f() - [[ which may have been defined with named arguments as in f(x,y,z)) + [[ which may have been defined with named arguments as in f(x,y,z)) and either the number of arguments or the value of an argument in an anticipated call to f() is to be used, the number of arguments in that call will then be returned by: - param(0) + param(0) and the value of the n-th argument by: - param(n) + param(n) Note that unlike the argv() builtin, param(1) is the 1st parameter and param(param(0) is the last. EXAMPLE ; define f() { - ;; local n, v = 0; - ;; for (n = 1; n <= param(0); n++) - ;; v += param(n)^2; - ;; return v; + ;; local n, v = 0; + ;; for (n = 1; n <= param(0); n++) + ;; v += param(n)^2; + ;; return v; ;; } ; print f(), f(1), f(1,2), f(1,2,3) @@ -58,7 +58,7 @@ SEE ALSO ## ## 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 +## 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 @@ -66,8 +66,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/03/12 23:10:01 -## File existed as early as: 1996 +## Under source code control: 1996/03/12 23:10:01 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/perm b/help/perm index ddf57a3..7640db2 100644 --- a/help/perm +++ b/help/perm @@ -5,17 +5,17 @@ SYNOPSIS perm(x, y) TYPES - x int - y int + x int + y int - return int + return int DESCRIPTION Return the permutation number P(x,y) which is defined as: - x! - -------- - (x-y)! + x! + -------- + (x-y)! This function computes the number of permutations in which y things may be chosen from x items where order in which they are chosen matters. @@ -45,7 +45,7 @@ SEE ALSO ## ## 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 +## 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 @@ -53,8 +53,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/10/20 04:03:02 -## File existed as early as: 1994 +## Under source code control: 1994/10/20 04:03:02 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/pfact b/help/pfact index 74177c7..98f55c1 100644 --- a/help/pfact +++ b/help/pfact @@ -5,9 +5,9 @@ SYNOPSIS pfact(n) TYPES - n nonnegative integer + n nonnegative integer - return positive integer + return positive integer DESCRIPTION Returns the product of primes p_i for which p_i <= n. @@ -35,7 +35,7 @@ SEE ALSO ## ## 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 +## 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 @@ -43,8 +43,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 12:34:57 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 12:34:57 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/pi b/help/pi index f77b0a2..28a22e2 100644 --- a/help/pi +++ b/help/pi @@ -5,9 +5,9 @@ SYNOPSIS pi([eps]) TYPES - eps 0 < real < 1, defaults to epsilon() + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Returns a multiple of eps differing from the true value of pi by @@ -34,7 +34,7 @@ SEE ALSO ## ## 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 +## 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 @@ -42,8 +42,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:46 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:46 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/pix b/help/pix index 469e236..e94bf37 100644 --- a/help/pix +++ b/help/pix @@ -5,10 +5,10 @@ SYNOPSIS pix(n [,err]) TYPES - n real - err integer + n real + err integer - return nonnegative integer, or err + return nonnegative integer, or err DESCRIPTION If n is fractional or n >= 2^32, pix(n) causes an error, @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 12:34:58 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 12:34:58 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/places b/help/places index 10a7f2d..2e9abe1 100644 --- a/help/places +++ b/help/places @@ -5,10 +5,10 @@ SYNOPSIS places(x [,b]) TYPES - x real - b integer >= 2, defaults to 10 + x real + b integer >= 2, defaults to 10 - return integer + return integer DESCRIPTION Returns the least non-negative integer n for which b^n * x is an @@ -48,7 +48,7 @@ SEE ALSO ## ## 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 +## 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 @@ -56,8 +56,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/03 10:40:02 -## File existed as early as: 1995 +## Under source code control: 1995/10/03 10:40:02 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/pmod b/help/pmod index 37981d5..7568407 100644 --- a/help/pmod +++ b/help/pmod @@ -5,11 +5,11 @@ SYNOPSIS pmod(x, n, md) TYPES - x integer - n nonnegative integer - md integer + x integer + n nonnegative integer + md integer - return integer + return integer DESCRIPTION pmod(x, n, md) returns the integer value of the canonical residue @@ -20,16 +20,16 @@ DESCRIPTION For nonzero md, the canonical residues v modulo md are as follows: - config("mod") md > 0 md < 0 + config("mod") md > 0 md < 0 - 0 0 < v < md md < v < 0 - 1 -md < v < 0 0 < v < -md - 4 0 < v < md 0 < v < -md - 5 -md < v < 0 md < v < 0 - 16 -md/2 < v <= md/2 md/2 <= v < -md/2 - 17 -md/2 <= v < md/2 md/2 < v <= -md/2 - 20 -md/2 < v <= md/2 md/2 < v <= -md/2 - 21 -md/2 <= v < md/2 md/2 <= v < -md/2 + 0 0 < v < md md < v < 0 + 1 -md < v < 0 0 < v < -md + 4 0 < v < md 0 < v < -md + 5 -md < v < 0 md < v < 0 + 16 -md/2 < v <= md/2 md/2 <= v < -md/2 + 17 -md/2 <= v < md/2 md/2 < v <= -md/2 + 20 -md/2 < v <= md/2 md/2 < v <= -md/2 + 21 -md/2 <= v < md/2 md/2 <= v < -md/2 EXAMPLE ; c = config("mod",0) @@ -57,7 +57,7 @@ SEE ALSO ## ## 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 +## 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 @@ -65,8 +65,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/09 03:27:51 -## File existed as early as: 1995 +## Under source code control: 1995/11/09 03:27:51 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/polar b/help/polar index 50519ae..65a5598 100644 --- a/help/polar +++ b/help/polar @@ -5,11 +5,11 @@ SYNOPSIS polar(r, t [, eps]) TYPES - r real - t real - eps nonzero real, defaults to epsilon() + r real + t real + eps nonzero real, defaults to epsilon() - return number (real or complex) + return number (real or complex) DESCRIPTION Returns the real or complex number with real and imaginary parts @@ -42,7 +42,7 @@ SEE ALSO ## ## 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 +## 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 @@ -50,8 +50,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:46 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:46 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/poly b/help/poly index be3e491..e1c4c39 100644 --- a/help/poly +++ b/help/poly @@ -8,65 +8,65 @@ SYNOPSIS TYPES For first case: - a, b, ... Arithmetic + a, b, ... Arithmetic - x Arithmetic + x Arithmetic - return Depends on argument types + return Depends on argument types For second case: - clist List of coefficients + clist List of coefficients - x, y, ... Coefficients + x, y, ... Coefficients - return Depends on argument types + return Depends on argument types Here an arithmetic type is one for which the required + and * operations are defined, e.g. real or complex numbers or square - matrices of the same size. A coefficient is either of arithmetic + matrices of the same size. A coefficient is either of arithmetic type or a list of coefficients. DESCRIPTION If the first argument is not a list, and the necessary operations are defined: - poly(a_0, a_1, ..., a_n, x) + poly(a_0, a_1, ..., a_n, x) returns the value of: - a_n + (a_n-1 + ... + (a_1 + a_0 * x) * x ...) * x + a_n + (a_n-1 + ... + (a_1 + a_0 * x) * x ...) * x If the coefficients a_0, a_1, ..., a_n and x are elements of a commutative ring, e.g. if the coefficients and x are real or complex numbers, this is the value of the polynomial: - a_0 * x^n + a_1 * x^(n-1) + ... + a_(n-1) * x + a_n. + a_0 * x^n + a_1 * x^(n-1) + ... + a_(n-1) * x + a_n. For other structures (e.g. if addition is not commutative), the order of operations may be relevant. In particular: - poly(a, x) returns the value of a. + poly(a, x) returns the value of a. - poly(a, b, x) returns the value of b + a * x + poly(a, b, x) returns the value of b + a * x - poly(a, b, c, x) returns the value of c + (b + a * x) * x + poly(a, b, c, x) returns the value of c + (b + a * x) * x If the first argument is a list as if defined by: - clist = list(a_0, a_1, ..., a_n) + clist = list(a_0, a_1, ..., a_n) and the coefficients a_i and x are are of arithmetic type, poly(clist, x) returns: - a_0 + (a_1 + (a_2 + ... + a_n * x) * x) + a_0 + (a_1 + (a_2 + ... + a_n * x) * x) which for a commutative ring, expands to: - a_0 + a_1 * x + ... + a_n * x^n. + a_0 + a_1 * x + ... + a_n * x^n. If clist is the empty list, the value returned is the number 0. @@ -78,36 +78,36 @@ DESCRIPTION to such an element is the value of poly for that list and the next argument in x, y, ... For example: - poly(list(list(a,b,c), list(d,e), f), x, y) + poly(list(list(a,b,c), list(d,e), f), x, y) returns: - (a + b * y + c * y^2) + (d + e * y) * x + f * x^2. + (a + b * y + c * y^2) + (d + e * y) * x + f * x^2. Arguments in excess of those required for clist are ignored, e.g.: - poly(list(1,2,3), x, y) + poly(list(1,2,3), x, y) returns the same as poly(list(1,2,3), x). If the number of arguments is less than greatest depth of lists in clist, the - "missing" arguments are deemed to be zero. E.g.: + "missing" arguments are deemed to be zero. E.g.: - poly(list(list(1,2), list(3,4), 5), x) + poly(list(list(1,2), list(3,4), 5), x) returns the same as: - poly(list(1, 3, 5), x). + poly(list(1, 3, 5), x). If in the clist case, one or more of x, y, ... is a list, the arguments to be applied to the polynomial are the successive non-list values in the list or sublists. For example, if the x_i are not lists: - poly(clist, list(x_0, x_1), x_2, list(list(x_3, x_4), x_5)) + poly(clist, list(x_0, x_1), x_2, list(list(x_3, x_4), x_5)) returns the same as: - poly(clist, x_0, x_1, x_2, x_3, x_4, x_5). + poly(clist, x_0, x_1, x_2, x_3, x_4, x_5). EXAMPLE ; print poly(2, 3, 5, 7), poly(list(5, 3, 2), 7), 5 + 3 * 7 + 2 * 7^2 @@ -144,7 +144,7 @@ SEE ALSO ## ## 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 +## 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 @@ -152,8 +152,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/02 02:40:43 -## File existed as early as: 1995 +## Under source code control: 1995/12/02 02:40:43 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/pop b/help/pop index 9f26662..68afbb6 100644 --- a/help/pop +++ b/help/pop @@ -5,9 +5,9 @@ SYNOPSIS pop(lst) TYPES - lst list, &list + lst list, &list - return any + return any DESCRIPTION This function removes index 0 and returns it. @@ -22,14 +22,14 @@ EXAMPLE [[1]] = "three" ; pop(lst) - 2 + 2 ; print lst list (1 elements, 1 nonzero): [[0]] = "three" ; pop(lst) - "three" + "three" ; print lst list (0 elements, 0 nonzero) ; pop(lst) @@ -54,7 +54,7 @@ SEE ALSO ## ## 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 +## 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 @@ -62,8 +62,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 03:13:20 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 03:13:20 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/popcnt b/help/popcnt index 1f66c0e..8fb4d5c 100644 --- a/help/popcnt +++ b/help/popcnt @@ -5,10 +5,10 @@ SYNOPSIS popcnt(x [,bitval]) TYPES - x number (real or integer) - bitval 0 or 1 + x number (real or integer) + bitval 0 or 1 - return number + return number DESCRIPTION Count the number of bits in abs(x) that match bitval. The default @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/09/11 04:20:02 -## File existed as early as: 1997 +## Under source code control: 1997/09/11 04:20:02 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/pound b/help/pound index afa9255..bc35c30 100644 --- a/help/pound +++ b/help/pound @@ -8,17 +8,17 @@ SYNOPSIS ## comment TYPES - x, y integer or real + x, y integer or real - return integer (unary operator case) - integer or real (binary operator case) + return integer (unary operator case) + integer or real (binary operator case) DESCRIPTION The pound sign or sharp sign "#" has special meaning in calc. As a unary operator: - # value + # value returns the number of 1 bits, or pop-count of the absolute value of the numerator (abs(num(value))). Therefore when x is a non-negative @@ -28,20 +28,20 @@ DESCRIPTION As a binary operator: - x # y + x # y returns abs(x-y), the absolute value of the difference. When two or more pound signs in a row start a comment: - ## this is a comment - ### this is also a comment - print "this will print"; ## but this will not because it is a comment + ## this is a comment + ### this is also a comment + print "this will print"; ## but this will not because it is a comment A pound sign followed by a bang also starts a comment: - #! strictly speaking, this is a comment - print "this is correct but not recommended" #! acts like ## + #! strictly speaking, this is a comment + print "this is correct but not recommended" #! acts like ## On POSIX / Un*X / Linux / BSD conforming systems, when an executable starts with the two bytes # and !, the remainder of the 1st line @@ -52,15 +52,15 @@ DESCRIPTION For example, of an executable file contains: - #!/usr/local/src/bin/calc/calc -q -f - /* NOTE: The #! above must start in column 1 of the 1st line */ - /* The 1st line must end with -f */ - ## Single # shell comments don't work, use two or more - print "2+2 =", 2+2; + #!/usr/local/src/bin/calc/calc -q -f + /* NOTE: The #! above must start in column 1 of the 1st line */ + /* The 1st line must end with -f */ + ## Single # shell comments don't work, use two or more + print "2+2 =", 2+2; When the above file it is executed by the kernel, it will print: - 2+2 = 4 + 2+2 = 4 Such files are known to calc as cscripts. See "help cscript" for examples. @@ -76,18 +76,18 @@ DESCRIPTION EXAMPLE ; #3 - 2 + 2 ; #3.5 - 3 + 3 ; 4 # 5 - 1 + 1 ; 5 # 4 - 1 + 1 ; pi() # exp(1) - 0.4233108251307480031 + 0.4233108251307480031 ; exp(1) # pi() - 0.4233108251307480031 + 0.4233108251307480031 ; ## this is a comment @@ -108,7 +108,7 @@ SEE ALSO ## ## 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 +## 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 @@ -116,8 +116,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2007/02/06 14:09 -## File existed as early as: 2007 +## Under source code control: 2007/02/06 14:09 +## File existed as early as: 2007 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/power b/help/power index 0a94590..bc9e984 100644 --- a/help/power +++ b/help/power @@ -5,11 +5,11 @@ SYNOPSIS power(x, y, [, eps]) TYPES - x number - y number - eps nonzero real, defaults to epsilon() + x number + y number + eps nonzero real, defaults to epsilon() - return number + return number DESCRIPTION For real or complex x and y, power(x,y,eps) returns a real or @@ -63,7 +63,7 @@ SEE ALSO ## ## 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 +## 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 @@ -71,8 +71,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:46 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:46 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/prevcand b/help/prevcand index fed1d71..d3a6f61 100644 --- a/help/prevcand +++ b/help/prevcand @@ -5,13 +5,13 @@ SYNOPSIS prevcand(n [,count [, skip [, residue [, modulus]]]]) TYPES - n integer - count integer with absolute value less than 2^24, defaults to 1 - skip integer, defaults to 1 - residue integer, defaults to 0 - modulus integer, defaults to 1 + n integer + count integer with absolute value less than 2^24, defaults to 1 + skip integer, defaults to 1 + residue integer, defaults to 0 + modulus integer, defaults to 1 - return integer + return integer DESCRIPTION The sign of n is ignored; in the following it is assumed that n >= 0. @@ -45,7 +45,7 @@ DESCRIPTION RUNTIME The runtime for v = prevcand(n, ...) will depend strongly on the - number and nature of the integers between n and v. If this number + number and nature of the integers between n and v. If this number is reasonably large the size of count is largely irrelevant as the compositeness of the numbers between n and v will usually be determined by the test for small prime factors or one pseudoprime @@ -79,7 +79,7 @@ LIMITS LINK LIBRARY int zprevcand(ZVALUE n, long count, long skip, ZVALUE res, ZVALUE mod, - ZVALUE *cand) + ZVALUE *cand) SEE ALSO factor, isprime, lfactor, nextcand, nextprime, prevprime, @@ -93,7 +93,7 @@ SEE ALSO ## ## 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 +## 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 @@ -101,8 +101,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/02/25 00:27:43 -## File existed as early as: 1996 +## Under source code control: 1996/02/25 00:27:43 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/prevprime b/help/prevprime index 100868f..a4d8bba 100644 --- a/help/prevprime +++ b/help/prevprime @@ -5,10 +5,10 @@ SYNOPSIS prevprime(n [,err]) TYPES - n real - err integer + n real + err integer - return positive integer or err + return positive integer or err DESCRIPTION If n is an integer and 2 < n < 2^32, prevprime(n) returns the @@ -47,7 +47,7 @@ SEE ALSO ## ## 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 +## 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 @@ -55,8 +55,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 12:34:58 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 12:34:58 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/printf b/help/printf index 58b355f..a25220d 100644 --- a/help/printf +++ b/help/printf @@ -5,10 +5,10 @@ SYNOPSIS printf(fmt, x_1, x_2, ...) TYPES - fmt string - x_1, x_2, ... any + fmt string + x_1, x_2, ... any - return null + return null DESCRIPTION The function printf() is similar to the C function with the same name. @@ -24,11 +24,11 @@ DESCRIPTION a '%' indicates the intention to build a format specifier. This is completed by a succession of characters as follows: - an optional '-' - zero or more decimal digits - an optional '. followed by zero or more decimal digits - an optional 'l' - one of the letters: d, s, c, f, e, g, r, o, x, b, + an optional '-' + zero or more decimal digits + an optional '. followed by zero or more decimal digits + an optional 'l' + one of the letters: d, s, c, f, e, g, r, o, x, b, If any other character is read, the '%' and any characters between '%' and the character are ignored and no specifier is @@ -37,25 +37,25 @@ DESCRIPTION The characters in a format specifier are interpreted as follows: - a minus sign sets the right-pad flag; - the first group of digits determines the width w; - w = 0 if there are no digits - a dot indicates the precision is to be read from the - following digits; if there is no dot, - precision = config("display"). - any digits following the . determines the precision p; - p = 0 if there are no digits - any 'l' before the final letter is ignored - the final letter determines the mode as follows: + a minus sign sets the right-pad flag; + the first group of digits determines the width w; + w = 0 if there are no digits + a dot indicates the precision is to be read from the + following digits; if there is no dot, + precision = config("display"). + any digits following the . determines the precision p; + p = 0 if there are no digits + any 'l' before the final letter is ignored + the final letter determines the mode as follows: - d, s, c current config("mode") - f real (decimal, floating point) - e exponential - g general format (real or exponential) - r fractional - o octal - x hexadecimal - b binary + d, s, c current config("mode") + f real (decimal, floating point) + e exponential + g general format (real or exponential) + r fractional + o octal + x hexadecimal + b binary If the number of arguments after fmt is less than the number of format specifiers in fmt, the "missing" arguments may be @@ -67,13 +67,13 @@ DESCRIPTION the \ character. The following control charter escape sequences are recognized: - \a audible bell byte 0x07 in ASCII encoding - \b backspace byte 0x08 in ASCII encoding - \f form feed byte 0x0c in ASCII encoding - \n newline byte 0x0b in ASCII encoding - \r return byte 0x0a in ASCII encoding - \t tab byte 0x0d in ASCII encoding - \v vertical tab byte 0x09 in ASCII encoding + \a audible bell byte 0x07 in ASCII encoding + \b backspace byte 0x08 in ASCII encoding + \f form feed byte 0x0c in ASCII encoding + \n newline byte 0x0b in ASCII encoding + \r return byte 0x0a in ASCII encoding + \t tab byte 0x0d in ASCII encoding + \v vertical tab byte 0x09 in ASCII encoding If i <= the number of specifiers in fmt, the value of argument x_i is printed in the format specified by the i-th specifier. @@ -92,7 +92,7 @@ DESCRIPTION If the i-th specifier is of numerical type, any numbers in the printing of x_i will be printed in the specified format, unless - this is modified by the printing procedure for x_i's type. Any + this is modified by the printing procedure for x_i's type. Any specified precision will be ignored except for floating-point mode. @@ -112,8 +112,8 @@ DESCRIPTION config("mode"). Therefore this will print the entire "1.2345" value: - ; printf("%d\n", 1.2345); - 1.2345 + ; printf("%d\n", 1.2345); + 1.2345 assuming printing of 4 or more digits is allowed by the current @@ -121,49 +121,49 @@ DESCRIPTION See also: - ; help printf - ; help display - ; help mode + ; help printf + ; help display + ; help mode In calc, %x formats in base 16. A non-integer numeric values such as 1/3 is represented as a fraction. When fractions are printed in %x format, both the numerator and denominator are printed as is mode("fraction"): - ; printf("%x\n", 1.2345); - 0x9a5/0x7d0 + ; printf("%x\n", 1.2345); + 0x9a5/0x7d0 See also: - ; help printf - ; help display - ; help mode + ; help printf + ; help display + ; help mode Because calc is capable of of printing very large values, some people may be surprised when this does not print the entire value of M(23209): - fprintf(fd, "%d\n", 2^23209-1); - /* the entire value may not be printed yet */ + fprintf(fd, "%d\n", 2^23209-1); + /* the entire value may not be printed yet */ Because I/O is usually buffered to files, the above fprintf() may print only the initial 4096 characters. One needs to also flush (or close the stream) to be sure that the entire value as been printed to the file: - ; fflush(fd); + ; fflush(fd); A similar problem an arise when printing many digits after the decimal point: - ; display(10000),; - ; fprintf(fd, "%d\n", pi(1e-10000)); - ; fflush(fd); + ; display(10000),; + ; fprintf(fd, "%d\n", pi(1e-10000)); + ; fflush(fd); The buffer will also be flushed during a call to fclose(): - ; fclose(fd); + ; fclose(fd); EXAMPLE ; config("epsilon", 1e-6),; @@ -318,7 +318,7 @@ SEE ALSO ## ## 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 +## 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 @@ -326,8 +326,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/03/12 22:50:41 -## File existed as early as: 1996 +## Under source code control: 1996/03/12 22:50:41 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/prompt b/help/prompt index 23b440c..edba81f 100644 --- a/help/prompt +++ b/help/prompt @@ -5,9 +5,9 @@ SYNOPSIS prompt(str) TYPES - str string + str string - return string + return string DESCRIPTION When prompt(str) is called and input is from a terminal, the string @@ -24,41 +24,41 @@ DESCRIPTION The following shell script will always print "got null" because stdin will be closed by calc during startup: - #!/usr/bin/calc -q -f + #!/usr/bin/calc -q -f - # The prompt will ALWAYS FAIL and return a null value - n = prompt("Test> "); - if (isnull(n)) { - print("got null"); - } else { - print("got " + n); - } + # The prompt will ALWAYS FAIL and return a null value + n = prompt("Test> "); + if (isnull(n)) { + print("got null"); + } else { + print("got " + n); + } However the following shell script (note the -p before the -f in the 1st line) will be interactive, prompt with "Test> " and print the "got" result as expected: - #!/usr/bin/calc -q -p -f + #!/usr/bin/calc -q -p -f - n = prompt("Test> "); - if (isnull(n)) { - print("got null"); - } else { - print("got " + n); - } + n = prompt("Test> "); + if (isnull(n)) { + print("got null"); + } else { + print("got " + n); + } EXAMPLE ; x = prompt("? "); ? 273 ; x - "273" + "273" ; for (;;) {s = prompt("? "); if (s=="end") break; print "\t":eval(s)^2;} ? 3 - 9 + 9 ? 2 + 3 - 25 + 25 ? end LIMITS @@ -78,7 +78,7 @@ SEE ALSO ## ## 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 +## 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 @@ -86,8 +86,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 12:34:58 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 12:34:58 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/protect b/help/protect index 054f8d8..4569db6 100644 --- a/help/protect +++ b/help/protect @@ -6,12 +6,12 @@ SYNOPSIS protect(nblk [, N [, depth]]) TYPES - var lvalue - nblk named block - N integer, abs(N) < 65536 - depth nonnegative integer + var lvalue + nblk named block + N integer, abs(N) < 65536 + depth nonnegative integer - return null value + return null value DESCRIPTION The protection status of the association of an lvalue A with @@ -20,16 +20,16 @@ DESCRIPTION Each nonzero bit of the low eight bits of sts corresponds to a builtin kind of protection as follows: - bit value protection + bit value protection - 1 no assign to A - 2 no change of A by assignment - 4 no change of type value of A - 8 no error value for A - 16 no copy to A - 32 no relocation for A or its elements - 64 no assign from A - 128 no copy from A + 1 no assign to A + 2 no change of A by assignment + 4 no change of type value of A + 8 no error value for A + 16 no copy to A + 32 no relocation for A or its elements + 64 no assign from A + 128 no copy from A For example, A having protection status 65 = 1 + 64 prevents execution of assignments of the forms A = expression and V = A @@ -57,8 +57,8 @@ DESCRIPTION matrix, object or association, its elements have depth d + 1. For example, after: - ; obj point {x,y} - ; X = mat[3] = {1, list(2,3), mat[2] = {obj point, obj point} } + ; obj point {x,y} + ; X = mat[3] = {1, list(2,3), mat[2] = {obj point, obj point} } X has depth 0; X[0], X[1] and X[2] have depth 1; X[1][0], X[1][1], X[2][0] and X[2][1] have depth 2; X[2][0].x, X[2][0].y, X[2][1].x @@ -85,14 +85,14 @@ DESCRIPTION Users may define functions that return values with positive status, e.g. - ; define noassigntovalue(x) {protect(x,1); return x}; - ; S = noassigntovalue(42); + ; define noassigntovalue(x) {protect(x,1); return x}; + ; S = noassigntovalue(42); will result in S having the value 42 and no-assign-to protection. By using a backquote with a variable as argument, an even simpler function: - ; define noassignto(x) = protect(x, 1); + ; define noassignto(x) = protect(x, 1); gives no-assign-to protection to the variable; i.e. noassignto(`A) achieves the same as protect(A,1). @@ -130,7 +130,7 @@ DESCRIPTION memory used by a block and the freeing of a named block, For example, if a block B has maxsize 256, then after: - ; protect(B, 32); + ; protect(B, 32); copy(A, B) will fail if the copying would cause size(B) to equal or exceed 256; if B is a named block, blkfree(B) will not be permitted. @@ -175,10 +175,10 @@ DESCRIPTION to have positive value. Then code for evaluating a function might include lines like - ; if (protect(A) & 1024 && B <= 0) { - ;; return newerror("Prohibited assignment"); - ;; } - ; A = B; + ; if (protect(A) & 1024 && B <= 0) { + ;; return newerror("Prohibited assignment"); + ;; } + ; A = B; When an operation forbidden by a particular bit in the protection status of A is attempted, an error value is created but unless this @@ -204,71 +204,71 @@ EXAMPLE ; protect(A,1) ; A = 45 ; A - 27 + 27 ; strerror() - "No-assign-to destination for assign" + "No-assign-to destination for assign" ; protect(A,64) ; protect(A) - 65 + 65 ; X = A ; X - 0 + 0 ; strerror() - "No-assign-from source for assign" + "No-assign-from source for assign" ; protect(A,-1) ; protect(A) - 64 + 64 ; protect(A,4) ; protect(A) - 68 + 68 ; A = "abc" ; A - 27 + 27 ; strerror() - "No-type-change destination for assign" + "No-type-change destination for assign" ; B = 45 ; swap(A,B) - Error E_SWAP_2 + Error E_SWAP_2 ; strerror() - "No-assign-to-or-from argument for swap" + "No-assign-to-or-from argument for swap" ; protect(A,-64) ; protect(A) - 4 + 4 ; swap(A,B) ; A - 45 + 45 ; B - 27 + 27 ; A = mat[4] = {1,2,3,4} ; B = list(5,6,7,8) ; protect(A,16) ; copy(B,A) - Error E_COPY_14 + Error E_COPY_14 ; strerror() - "No-copy-to destination variable" + "No-copy-to destination variable" ; A = list(1,2,3) ; protect(A,32) ; append(A,4) - Error E_LIST_4 + Error E_LIST_4 ; strerror() - "No-relocate for list append" + "No-relocate for list append" ; A = blk(0,5) ; copy("abc", A) ; copy("de",A) - Error E_COPY_17 + Error E_COPY_17 ; strerror() - "No-relocate destination variable" + "No-relocate destination variable" ; A = blk("alpha") = {1,2,3,4,5} ; protect(A,0) ; protect(*A, 16) ; copy("abc", A) - Error E_COPY_16 + Error E_COPY_16 ; strerror() - "No-copy-to destination named block" + "No-copy-to destination named block" LIMITS none @@ -287,7 +287,7 @@ SEE ALSO ## ## 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 +## 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 @@ -295,8 +295,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/07/10 22:38:44 -## File existed as early as: 1997 +## Under source code control: 1997/07/10 22:38:44 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ptest b/help/ptest index af48287..7787877 100644 --- a/help/ptest +++ b/help/ptest @@ -5,11 +5,11 @@ SYNOPSIS ptest(n [,count [,skip]]) TYPES - n integer - count integer with absolute value less than 2^24, defaults to 1 - skip integer, defaults to 1 + n integer + count integer with absolute value less than 2^24, defaults to 1 + skip integer, defaults to 1 - return 0 or 1 + return 0 or 1 DESCRIPTION In ptest(n, ...) the sign of n is ignored; here we assume n >= 0. @@ -49,11 +49,11 @@ DESCRIPTION The bases for ptest(n, count, skip) are selected as follows: - skip = 0: random in [2, n-2] - skip = 1: successive primes 2, 3, 5, ... - not exceeding min(n, 65536) - otherwise: successive integers skip, skip + 1, ..., - skip+abs(count)-1 + skip = 0: random in [2, n-2] + skip = 1: successive primes 2, 3, 5, ... + not exceeding min(n, 65536) + otherwise: successive integers skip, skip + 1, ..., + skip+abs(count)-1 In particular, if m > 0, ptest(n, -m, 2) == 1 shows that n is either prime or a strong pseudoprime for all positive integer bases <= m + 1. @@ -63,7 +63,7 @@ DESCRIPTION For the random case (skip = 0), the probability that any one test with random base b will return 1 if n is composite is always less than 1/4, so with count = k, the probability is less - than 1/4^k. For most values of n the probability is much + than 1/4^k. For most values of n the probability is much smaller (possibly zero). RUNTIME @@ -85,7 +85,7 @@ RUNTIME If the word-count for n is less than conf("redc2"), REDC algorithms are used in evaluating ptest(n, count, skip) when small-factor - cases have been eliminated. For small word-counts (say < 10) + cases have been eliminated. For small word-counts (say < 10) this may more than double the speed of evaluation compared with the standard algorithms. @@ -122,7 +122,7 @@ EXAMPLE These results show that a is a strong pseudoprime for all 11 prime bases less than or equal to 31, and for all positive integer bases - less than or equal to 21, but not for the bases 37 and 22. The + less than or equal to 21, but not for the bases 37 and 22. The probability that ptest(a,-1,0) (or ptest(a,1,0)) will return 1 is about 0.19. @@ -145,7 +145,7 @@ SEE ALSO ## ## 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 +## 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 @@ -153,8 +153,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/02/25 00:27:43 -## File existed as early as: 1996 +## Under source code control: 1996/02/25 00:27:43 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/push b/help/push index aebf66c..0fcb6ae 100644 --- a/help/push +++ b/help/push @@ -5,10 +5,10 @@ SYNOPSIS push(x, y_0, y_1, ...) TYPES - x lvalue whose value is a list - y_0, ... any + x lvalue whose value is a list + y_0, ... any - return null value + return null value DESCRIPTION If after evaluation of y_0, y_1, ..., x is a list with @@ -63,7 +63,7 @@ SEE ALSO ## ## 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 +## 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 @@ -71,8 +71,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 03:13:20 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 03:13:20 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/putenv b/help/putenv index 5577d27..8a21260 100644 --- a/help/putenv +++ b/help/putenv @@ -5,10 +5,10 @@ SYNOPSIS putenv(env [,val]) TYPES - env str - val str + env str + val str - return int + return int DESCRIPTION This function will set or change the value of an environment variable. @@ -17,25 +17,25 @@ DESCRIPTION When called with 1 arg, env must be a string of the form: - "envname=envval" + "envname=envval" This sets the environment variable "envname" to the value "envval". The 2 arg form is equivalent to: - putenv(strcat(env, "=", val)) + putenv(strcat(env, "=", val)) EXAMPLE ; putenv("name", "value") - 0 + 0 ; getenv("name") - "value" + "value" ; putenv("name=val2") - 0 + 0 ; getenv("name") - "val2" + "val2" ; isnull(getenv("unknown")) - 1 + 1 LIMITS With 1 arg, env must contain at least 1 '=' character. @@ -54,7 +54,7 @@ SEE ALSO ## ## 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 +## 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 @@ -62,8 +62,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/09 03:48:57 -## File existed as early as: 1995 +## Under source code control: 1995/07/09 03:48:57 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/quo b/help/quo index 9153a57..6382fa3 100644 --- a/help/quo +++ b/help/quo @@ -15,17 +15,17 @@ TYPES If neither x nor y is an object, and x is not a matrix or list: - x number (real or complex) - y real - rnd integer, defaults to config("quo") + x number (real or complex) + y real + rnd integer, defaults to config("quo") - return number + return number DESCRIPTION If x is real or complex and y is zero, quo(x, y, rnd) returns zero. If x is complex, quo(x, y, rnd) returns - quo(re(x), y, rnd) + quo(im(x), y, rnd) * 1i. + quo(re(x), y, rnd) + quo(im(x), y, rnd) * 1i. In the following it is assumed that x is real and y is nonzero. @@ -35,40 +35,40 @@ DESCRIPTION one of the two integers v for which abs(x/y - v) < 1. Which integer is returned is controlled by rnd as follows: - rnd sign of x/y - v Description of rounding + rnd sign of x/y - v Description of rounding - 0 + down, towards minus infinity - 1 - up, towards infinity - 2 sgn(x/y) towards zero - 3 -sgn(x/y) from zero - 4 sgn(y) - 5 -sgn(y) - 6 sgn(x) - 7 -sgn(x) - 8 to nearest even integer - 9 to nearest odd integer - 10 even if x/y > 0, otherwise odd - 11 odd if x/y > 0, otherwise even - 12 even if y > 0, otherwise odd - 13 odd if y > 0, otherwise even - 14 even if x > 0, otherwise odd - 15 odd if x > 0, otherwise even + 0 + down, towards minus infinity + 1 - up, towards infinity + 2 sgn(x/y) towards zero + 3 -sgn(x/y) from zero + 4 sgn(y) + 5 -sgn(y) + 6 sgn(x) + 7 -sgn(x) + 8 to nearest even integer + 9 to nearest odd integer + 10 even if x/y > 0, otherwise odd + 11 odd if x/y > 0, otherwise even + 12 even if y > 0, otherwise odd + 13 odd if y > 0, otherwise even + 14 even if x > 0, otherwise odd + 15 odd if x > 0, otherwise even - 16-31 to nearest integer when this - is uniquely determined; - otherwise, when x/y is a - half-integer, as if - rnd replaced by rnd & 15 + 16-31 to nearest integer when this + is uniquely determined; + otherwise, when x/y is a + half-integer, as if + rnd replaced by rnd & 15 - NOTE: Blank entries in the table above indicate that the - description would be complicated and probably not of - much interest. + NOTE: Blank entries in the table above indicate that the + description would be complicated and probably not of + much interest. The C language method of modulus and integer division is: - config("quomod", 2) - config("quo", 2) - config("mod", 2) + config("quomod", 2) + config("quo", 2) + config("mod", 2) EXAMPLE print quo(11,5,0), quo(11,5,1), quo(-11,5,2), quo(-11,-5,3) @@ -95,7 +95,7 @@ SEE ALSO ## ## 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 +## 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 @@ -103,8 +103,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/09/18 04:01:44 -## File existed as early as: 1995 +## Under source code control: 1995/09/18 04:01:44 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/quomod b/help/quomod index 74436a1..a864f8b 100644 --- a/help/quomod +++ b/help/quomod @@ -5,13 +5,13 @@ SYNOPSIS quomod(x, y, Q, R [, rnd]) TYPES - x real - y real - Q null-or-real-valued lvalue with assign-to permission - R null-or-real-valued lvalue with assign-to permission - rnd nonnegative integer, defaults to config("quomod") + x real + y real + Q null-or-real-valued lvalue with assign-to permission + R null-or-real-valued lvalue with assign-to permission + rnd nonnegative integer, defaults to config("quomod") - return 0 or 1 + return 0 or 1 DESCRIPTION If y is nonzero and x/y is an integer q, this function assigns @@ -31,19 +31,19 @@ DESCRIPTION smallest, etc. The effects of the most commonly used values of rnd are described in the following table: - rnd q r + rnd q r - 0 round down. q = floor(x/y) same sign as y - 1 round up, q = ceil(x/y) opposite sign to y - 2 round to zero, q = int(x/y) same sign as x, r = y * frac(x/y) - 3 round from zero opposite sign to x - 4 positive - 5 negative - 6 same sign as x/y - 7 opposite sigh to x/y + 0 round down. q = floor(x/y) same sign as y + 1 round up, q = ceil(x/y) opposite sign to y + 2 round to zero, q = int(x/y) same sign as x, r = y * frac(x/y) + 3 round from zero opposite sign to x + 4 positive + 5 negative + 6 same sign as x/y + 7 opposite sigh to x/y - 8 to nearest even - 9 to nearest odd + 8 to nearest even + 9 to nearest odd For 16 <= rnd < 32, the rounding is to the nearest integer and r is the smallest (in absolute value) remainder except when x/y is @@ -96,7 +96,7 @@ LINK LIBRARY BOOL qquomod(NUMBER *q1, NUMBER *q2, NUMBER **quo, NUMBER **mod) SEE ALSO - //, %, quo, mod, floor. ceil, int. frac + //, %, quo, mod, floor. ceil, int. frac ## Copyright (C) 1999-2006,2021 Landon Curt Noll ## @@ -106,7 +106,7 @@ SEE ALSO ## ## 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 +## 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 @@ -114,8 +114,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/05/07 03:17:03 -## File existed as early as: 1995 +## Under source code control: 1995/05/07 03:17:03 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/r2d b/help/r2d index 78ec638..46ea34a 100644 --- a/help/r2d +++ b/help/r2d @@ -5,10 +5,10 @@ SYNOPSIS r2d(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Given x radians, return the equivalent number of degrees. @@ -42,7 +42,7 @@ SEE ALSO ## ## 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 +## 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 @@ -50,8 +50,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/07 12:04:28 -## File existed as early as: 2021 +## Under source code control: 2021/09/07 12:04:28 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/r2g b/help/r2g index 6fa4af5..cda80dc 100644 --- a/help/r2g +++ b/help/r2g @@ -5,10 +5,10 @@ SYNOPSIS r2g(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Given x radians, return the equivalent number of gradians. @@ -42,7 +42,7 @@ SEE ALSO ## ## 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 +## 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 @@ -50,8 +50,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2021/09/07 12:04:28 -## File existed as early as: 2021 +## Under source code control: 2021/09/07 12:04:28 +## File existed as early as: 2021 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/rand b/help/rand index 318cf29..c6ff0e9 100644 --- a/help/rand +++ b/help/rand @@ -5,16 +5,16 @@ SYNOPSIS rand([[min, ] beyond]) TYPES - min integer - beyond integer + min integer + beyond integer - return integer + return integer DESCRIPTION Generate a pseudo-random number using an subtractive 100 shuffle generator. We return a pseudo-random number over the half closed interval: - [min,beyond) ((min <= return < beyond)) + [min,beyond) ((min <= return < beyond)) By default, min is 0 and beyond is 2^64. @@ -28,24 +28,24 @@ DESCRIPTION Other arg forms: - rand() Same as rand(0, 2^64) - rand(beyond) Same as rand(0, beyond) + rand() Same as rand(0, 2^64) + rand(beyond) Same as rand(0, beyond) The rand generator generates the highest order bit first. Thus: - rand(256) + rand(256) will produce the save value as: - (rand(8) << 5) + rand(32) + (rand(8) << 5) + rand(32) when seeded with the same seed. The rand generator has two distinct parts, the subtractive 100 method and the shuffle method. The subtractive 100 method is described in: - "The Art of Computer Programming - Seminumerical Algorithms", - Vol 2, 3rd edition (1998), Section 3.6, page 186, formula (2). + "The Art of Computer Programming - Seminumerical Algorithms", + Vol 2, 3rd edition (1998), Section 3.6, page 186, formula (2). The "use only the first 100 our of every 1009" is described in Knuth's "The Art of Computer Programming - Seminumerical Algorithms", @@ -57,43 +57,43 @@ DESCRIPTION The shuffle method is feed values by the subtractive 100 method. The shuffle method is described in: - "The Art of Computer Programming - Seminumerical Algorithms", - Vol 2, 3rd edition (1998), Section 3.2.2, page 34, Algorithm B. + "The Art of Computer Programming - Seminumerical Algorithms", + Vol 2, 3rd edition (1998), Section 3.2.2, page 34, Algorithm B. - The rand generator has a good period, and is fast. It is reasonable as + The rand generator has a good period, and is fast. It is reasonable as generators go, though there are better ones available. The shuffle - method has a very good period, and is fast. It is fairly good as + method has a very good period, and is fast. It is fairly good as generators go, particularly when it is feed reasonably random numbers. Because of this, we use feed values from the subtractive 100 method into the shuffle method. The rand generator uses two internal tables: - additive table - 100 entries of 64 bits used by the subtractive - 100 method + additive table - 100 entries of 64 bits used by the subtractive + 100 method - shuffle table - 256 entries of 64 bits used by the shuffle method - feed by the subtractive 100 method from the - subtractive table + shuffle table - 256 entries of 64 bits used by the shuffle method + feed by the subtractive 100 method from the + subtractive table The goals of this generator are: - * all magic numbers are explained + * all magic numbers are explained - I (Landon Curt Noll) distrust systems with constants (magic - numbers) and tables that have no justification (e.g., - DES). I believe that I have done my best to justify all of - the magic numbers used. + I (Landon Curt Noll) distrust systems with constants (magic + numbers) and tables that have no justification (e.g., + DES). I believe that I have done my best to justify all of + the magic numbers used. - * full documentation + * full documentation - You have this source file, plus background publications, - what more could you ask? + You have this source file, plus background publications, + what more could you ask? - * large selection of seeds + * large selection of seeds - Seeds are not limited to a small number of bits. A seed - may be of any size. + Seeds are not limited to a small number of bits. A seed + may be of any size. Most of the magic constants used by this generator ultimately are based on the Rand book of random numbers. The Rand book contains @@ -127,7 +127,7 @@ DESCRIPTION perceptions that are noted above. It should be noted that the purpose of randreseed64 is to scramble a - seed ONLY. We do not care if these generators produce good random + seed ONLY. We do not care if these generators produce good random numbers. We only want to help eliminate the human factors & perceptions noted above. @@ -135,64 +135,64 @@ DESCRIPTION mapping [0,2^64) into [0,2^64). This map is one-to-one and onto. Mapping is performed using a linear congruence generator of the form: - X1 <-- (a*X0 + c) % m + X1 <-- (a*X0 + c) % m with the exception that: - 0 ==> 0 (so that srand(0) acts as default) + 0 ==> 0 (so that srand(0) acts as default) while maintaining a 1-to-1 and onto map. The randreseed64 constants 'a' and 'c' based on the linear congruential generators found in: - "The Art of Computer Programming - Seminumerical Algorithms" - by Knuth, Vol 2, 2nd edition (1981), Section 3.6, pages 170-171. + "The Art of Computer Programming - Seminumerical Algorithms" + by Knuth, Vol 2, 2nd edition (1981), Section 3.6, pages 170-171. We will select the randreseed64 multiplier 'a' such that: - a mod 8 == 5 (based on note iii) - 0.01*m < a < 0.99*m (based on note iv) - 0.01*2^64 < a < 0.99*2^64 - a is prime (help keep the generators independent) + a mod 8 == 5 (based on note iii) + 0.01*m < a < 0.99*m (based on note iv) + 0.01*2^64 < a < 0.99*2^64 + a is prime (help keep the generators independent) The choice of the randreseed64 adder 'c' is considered immaterial according (based in note v). Knuth suggests 'c==1' or 'c==a'. We elect to select 'c' using the same process as we used to select 'a'. The choice is 'immaterial' after all, and as long as: - gcd(c, m) == 1 (based on note v) - gcd(c, 2^64) == 1 - gcd(a, c) == 1 (adders & multipliers will be more independent) + gcd(c, m) == 1 (based on note v) + gcd(c, 2^64) == 1 + gcd(a, c) == 1 (adders & multipliers will be more independent) The values 'a' and 'c for randreseed64 are taken from the Rand book - of numbers. Because m=2^64 is 20 decimal digits long, we will + of numbers. Because m=2^64 is 20 decimal digits long, we will search the Rand book of numbers 20 at a time. We will skip any of the 100 values that were used to initialize the subtractive 100 - generators. The values obtained from the Rand book are: + generators. The values obtained from the Rand book are: - a = 6316878969928993981 - c = 1363042948800878693 + a = 6316878969928993981 + c = 1363042948800878693 As we stated before, we must map 0 ==> 0 so that srand(0) does the default thing. The randreseed64 would normally map as follows: - 0 ==> 1363042948800878693 (0 ==> c) + 0 ==> 1363042948800878693 (0 ==> c) To overcome this, and preserve the 1-to-1 and onto map, we force: - 0 ==> 0 - 10239951819489363767 ==> 1363042948800878693 + 0 ==> 0 + 10239951819489363767 ==> 1363042948800878693 One might object to the complexity of the seed scramble/mapping via the randreseed64 process. Calling srand(0) with the randreseed64 process would be the same as calling srand(10239951819489363767) - without it. No extra security is gained or reduced by using the + without it. No extra security is gained or reduced by using the randreseed64 process. The meaning of seeds are exchanged, but not lost or favored (used by more than one input seed). The randreseed64 process does not reduce the security of the rand - generator. Every seed is converted into a different unique seed. + generator. Every seed is converted into a different unique seed. No seed is ignored or favored. The two constants that were picked from the Rand Book of Random Numbers @@ -245,7 +245,7 @@ SEE ALSO ## ## 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 +## 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 @@ -253,8 +253,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/01/01 02:16:09 -## File existed as early as: 1996 +## Under source code control: 1996/01/01 02:16:09 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/randbit b/help/randbit index 3b4d792..874097a 100644 --- a/help/randbit +++ b/help/randbit @@ -5,15 +5,15 @@ SYNOPSIS randbit([x]) TYPES - x integer + x integer - return integer + return integer DESCRIPTION If x > 0, randbit(x) returns a pseudo-random integer in [0, 2^x), - i.e. the same as rand(2^x). If the integer returned is + i.e. the same as rand(2^x). If the integer returned is - b_1 * 2^(x-1) + b_2 * 2^(x-2) + ... + b_n, + b_1 * 2^(x-1) + b_2 * 2^(x-2) + ... + b_n, where each b_i is 0 or 1, then b_1, b_2, ..., b_n may be considered as a sequence of x random bits. @@ -50,7 +50,7 @@ SEE ALSO ## ## 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 +## 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 @@ -58,8 +58,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/01/01 03:17:22 -## File existed as early as: 1996 +## Under source code control: 1996/01/01 03:17:22 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/random b/help/random index 221d430..9808848 100644 --- a/help/random +++ b/help/random @@ -5,16 +5,16 @@ SYNOPSIS random([[min, ] beyond]) TYPES - min integer - beyond integer + min integer + beyond integer - return integer + return integer DESCRIPTION Generate a pseudo-random number using a Blum-Blum-Shub generator. We return a pseudo-random number over the half closed interval: - [min,beyond) ((min <= return < beyond)) + [min,beyond) ((min <= return < beyond)) By default, min is 0 and beyond is 2^64. @@ -25,56 +25,56 @@ DESCRIPTION Other arg forms: - random() Same as random(0, 2^64) - random(beyond) Same as random(0, beyond) + random() Same as random(0, 2^64) + random(beyond) Same as random(0, beyond) - The random generator generates the highest order bit first. Thus: + The random generator generates the highest order bit first. Thus: - random(256) + random(256) will produce the save value as: - (random(8) << 5) + random(32) + (random(8) << 5) + random(32) when seeded with the same seed. The basic idea behind the Blum-Blum-Shub generator is to use the low bit bits of quadratic residues modulo a product of - two 3 mod 4 primes. The lowest int(log2(log2(p*q))) bits are used + two 3 mod 4 primes. The lowest int(log2(log2(p*q))) bits are used where log2() is log base 2 and p,q are two primes 3 mod 4. The Blum-Blum-Shub generator is described in the papers: - Blum, Blum, and Shub, "Comparison of Two Pseudorandom Number - Generators", in Chaum, D. et. al., "Advances in Cryptology: - Proceedings Crypto 82", pp. 61-79, Plenum Press, 1983. + Blum, Blum, and Shub, "Comparison of Two Pseudorandom Number + Generators", in Chaum, D. et. al., "Advances in Cryptology: + Proceedings Crypto 82", pp. 61-79, Plenum Press, 1983. - Blum, Blum, and Shub, "A Simple Unpredictable Pseudo-Random - Number Generator", SIAM Journal of Computing, v. 15, n. 2, - 1986, pp. 364-383. + Blum, Blum, and Shub, "A Simple Unpredictable Pseudo-Random + Number Generator", SIAM Journal of Computing, v. 15, n. 2, + 1986, pp. 364-383. - U. V. Vazirani and V. V. Vazirani, "Trapdoor Pseudo-Random - Number Generators with Applications to Protocol Design", - Proceedings of the 24th IEEE Symposium on the Foundations - of Computer Science, 1983, pp. 23-30. + U. V. Vazirani and V. V. Vazirani, "Trapdoor Pseudo-Random + Number Generators with Applications to Protocol Design", + Proceedings of the 24th IEEE Symposium on the Foundations + of Computer Science, 1983, pp. 23-30. - U. V. Vazirani and V. V. Vazirani, "Efficient and Secure - Pseudo-Random Number Generation", Proceedings of the 24th - IEEE Symposium on the Foundations of Computer Science, - 1984, pp. 458-463. + U. V. Vazirani and V. V. Vazirani, "Efficient and Secure + Pseudo-Random Number Generation", Proceedings of the 24th + IEEE Symposium on the Foundations of Computer Science, + 1984, pp. 458-463. - U. V. Vazirani and V. V. Vazirani, "Efficient and Secure - Pseudo-Random Number Generation", Advances in Cryptology - - Proceedings of CRYPTO '84, Berlin: Springer-Verlag, 1985, - pp. 193-202. + U. V. Vazirani and V. V. Vazirani, "Efficient and Secure + Pseudo-Random Number Generation", Advances in Cryptology - + Proceedings of CRYPTO '84, Berlin: Springer-Verlag, 1985, + pp. 193-202. - Sciences 28, pp. 270-299. + Sciences 28, pp. 270-299. - Bruce Schneier, "Applied Cryptography", John Wiley & Sons, - 1st edition (1994), pp 365-366. + Bruce Schneier, "Applied Cryptography", John Wiley & Sons, + 1st edition (1994), pp 365-366. This generator is considered 'strong' in that it passes all - polynomial-time statistical tests. The sequences produced are + polynomial-time statistical tests. The sequences produced are random in an absolutely precise way. There is absolutely no better way to predict the sequence than by tossing a coin (as with TRULY random numbers) EVEN IF YOU KNOW THE MODULUS! Furthermore, having @@ -89,7 +89,7 @@ DESCRIPTION To compromise the generator, an adversary must either factor the modulus or perform an exhaustive search just to determine the next - (or previous) bit. If we make the modulus hard to factor (such as + (or previous) bit. If we make the modulus hard to factor (such as the product of two large well chosen primes) breaking the sequence could be intractable for todays computers and methods. @@ -105,27 +105,27 @@ DESCRIPTION The goals of this package are: - all magic numbers are explained + all magic numbers are explained - I distrust systems with constants (magic numbers) and tables - that have no justification (e.g., DES). I believe that I have - done my best to justify all of the magic numbers used. + I distrust systems with constants (magic numbers) and tables + that have no justification (e.g., DES). I believe that I have + done my best to justify all of the magic numbers used. - full documentation + full documentation - You have this source file, plus background publications, - what more could you ask? + You have this source file, plus background publications, + what more could you ask? - large selection of seeds + large selection of seeds - Seeds are not limited to a small number of bits. A seed - may be of any size. + Seeds are not limited to a small number of bits. A seed + may be of any size. - the strength of the generators may be tuned to meet the need + the strength of the generators may be tuned to meet the need - By using the appropriate seed and other arguments, one may - increase the strength of the generator to suit the need of - the application. One does not have just a few levels. + By using the appropriate seed and other arguments, one may + increase the strength of the generator to suit the need of + the application. One does not have just a few levels. For a detailed discussion on seeds, see the srandom help page. @@ -133,7 +133,7 @@ DESCRIPTION is given in the source. While this does not reduce the quality of the generator, knowing the factors of the Blum modulus would help someone determine the next or previous bit when they did - not know the seed. If this bothers you, feel free to use one + not know the seed. If this bothers you, feel free to use one of the other compiled in Blum moduli or provide your own. See the srandom help page for details. @@ -166,7 +166,7 @@ SEE ALSO ## ## 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 +## 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 @@ -174,8 +174,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/02/17 01:18:22 -## File existed as early as: 1997 +## Under source code control: 1997/02/17 01:18:22 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/randombit b/help/randombit index 7fdec97..4945a63 100644 --- a/help/randombit +++ b/help/randombit @@ -5,15 +5,15 @@ SYNOPSIS randombit([x]) TYPES - x integer + x integer - return integer + return integer DESCRIPTION If x > 0, randombit(x) returns a pseudo-random integer in [0, 2^x), - i.e. the same as rand(2^x). If the integer returned is + i.e. the same as rand(2^x). If the integer returned is - b_1 * 2^(x-1) + b_2 * 2^(x-2) + ... + b_n, + b_1 * 2^(x-1) + b_2 * 2^(x-2) + ... + b_n, where each b_i is 0 or 1, then b_1, b_2, ..., b_n may be considered as a sequence of x random bits. @@ -49,7 +49,7 @@ SEE ALSO ## ## 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 +## 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 @@ -57,8 +57,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/02/17 01:18:22 -## File existed as early as: 1997 +## Under source code control: 1997/02/17 01:18:22 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/randperm b/help/randperm index 4d07ad0..c96968a 100644 --- a/help/randperm +++ b/help/randperm @@ -5,9 +5,9 @@ SYNOPSIS randperm(x) TYPES - x list or matrix + x list or matrix - return same as x + return same as x DESCRIPTION For a list or matrix x, randperm(x) returns a copy of x in which @@ -22,20 +22,20 @@ EXAMPLE ; randperm(A) list (5 elements, 5 nonzero): - [[0]] = 4 - [[1]] = 1 - [[2]] = 2 - [[3]] = 3 - [[4]] = 2 + [[0]] = 4 + [[1]] = 1 + [[2]] = 2 + [[3]] = 3 + [[4]] = 2 ; randperm(A) list (5 elements, 5 nonzero): - [[0]] = 2 - [[1]] = 1 - [[2]] = 4 - [[3]] = 2 - [[4]] = 3 + [[0]] = 2 + [[1]] = 1 + [[2]] = 4 + [[3]] = 2 + [[4]] = 3 LIMITS none @@ -54,7 +54,7 @@ SEE ALSO ## ## 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 +## 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 @@ -62,8 +62,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/10 02:09:31 -## File existed as early as: 1995 +## Under source code control: 1995/07/10 02:09:31 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/rcin b/help/rcin index 999c230..8131500 100644 --- a/help/rcin +++ b/help/rcin @@ -5,15 +5,15 @@ SYNOPSIS rcin(x, m) TYPES - x integer - m odd positive integer + x integer + m odd positive integer - return integer v, 0 <= v < m. + return integer v, 0 <= v < m. DESCRIPTION Let B be the base calc uses for representing integers internally (B = 2^16 for 32-bit machines, 2^32 for 64-bit machines) and N the - number of words (base-B digits) in the representation of m. Then + number of words (base-B digits) in the representation of m. Then rcin(x,m) returns the value of B^N * x % m, where the modulus operator % here gives the least nonnegative residue. @@ -23,17 +23,17 @@ DESCRIPTION evaluating products, squares and powers modulo m correspond to the formulae: - rcin(x * y, m) = rcmul(rcin(x,m), rcin(y,m), m); + rcin(x * y, m) = rcmul(rcin(x,m), rcin(y,m), m); - rcin(x^2, m) = rcsq(rcin(x,m), m); + rcin(x^2, m) = rcsq(rcin(x,m), m); - rcin(x^k, m) = rcpow(rcin(x,m), k, m). + rcin(x^k, m) = rcpow(rcin(x,m), k, m). - Here k is any nonnegative integer. Using these formulae may be + Here k is any nonnegative integer. Using these formulae may be faster than direct evaluation of x * y % m, x^2 % m, x^k % m. Some encoding and decoding may be bypassed by formulae like: - x * y % m = rcin(rcmul(x, y, m), m). + x * y % m = rcin(rcmul(x, y, m), m). If m is a divisor of B^N - h for some integer h, rcin(x,m) may be computed by using rcin(x,m) = h * x % m. In particular, if @@ -80,7 +80,7 @@ SEE ALSO ## ## 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 +## 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 @@ -88,8 +88,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/02/25 02:22:21 -## File existed as early as: 1996 +## Under source code control: 1996/02/25 02:22:21 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/rcmul b/help/rcmul index f8025bc..56f61cb 100644 --- a/help/rcmul +++ b/help/rcmul @@ -5,11 +5,11 @@ SYNOPSIS rcmul(x, y, m) TYPES - x integer - y integer - m odd positive integer + x integer + y integer + m odd positive integer - return integer v, 0 <= v < m. + return integer v, 0 <= v < m. DESCRIPTION Let B be the base calc uses for representing integers internally @@ -22,18 +22,18 @@ DESCRIPTION The normal use of rcmul() may be said to be that of multiplying modulo m values encoded by rcin() and REDC functions, as in: - rcin(x * y, m) = rcmul(rcin(x,m), rcin(y,m), m), + rcin(x * y, m) = rcmul(rcin(x,m), rcin(y,m), m), or with only one factor encoded: - x * y % m = rcmul(rcin(x,m), y, m). + x * y % m = rcmul(rcin(x,m), y, m). RUNTIME If the value of m in rcmul(x,y,m) is being used for the first time in a REDC function, the information required for the REDC algorithms is calculated and stored for future use, possibly replacing an already stored valued, in a table covering up to 5 - (i.e. MAXREDC) values of m. The runtime required for this is about + (i.e. MAXREDC) values of m. The runtime required for this is about two times that required for multiplying two N-word integers. Two algorithms are available for evaluating rcmul(x,y,m), the one @@ -69,7 +69,7 @@ SEE ALSO ## ## 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 +## 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 @@ -77,8 +77,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/02/25 02:22:21 -## File existed as early as: 1996 +## Under source code control: 1996/02/25 02:22:21 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/rcout b/help/rcout index 3f3fefd..141a4c7 100644 --- a/help/rcout +++ b/help/rcout @@ -5,30 +5,30 @@ SYNOPSIS rcout(x, m) TYPES - x integer - m odd positive integer + x integer + m odd positive integer - return integer v, 0 <= v < m. + return integer v, 0 <= v < m. DESCRIPTION Let B be the base calc uses for representing integers internally (B = 2^16 for 32-bit machines, 2^32 for 64-bit machines) and N the - number of words (base-B digits) in the representation of m. Then + number of words (base-B digits) in the representation of m. Then rcout(x,m) returns the value of B^-N * x % m, where the inverse implicit in B^-N is modulo m and the modulus operator % gives the - least non-negative residue. The functions rcin() and rcout() are + least non-negative residue. The functions rcin() and rcout() are inverses of each other for all x: - rcout(rcin(x,m), m) = rcin(rcout(x,m),m) = x % m. + rcout(rcin(x,m), m) = rcin(rcout(x,m),m) = x % m. The normal use of rcout() may be said to be that of decoding values encoded by rcin() and REDC functions, as in: - x * y % m = rcout(rcmul(rcin(x,m),rcin(y,m),m),m), + x * y % m = rcout(rcmul(rcin(x,m),rcin(y,m),m),m), - x^2 % m = rcout(rcsq(rcin(x,m),m),m), + x^2 % m = rcout(rcsq(rcin(x,m),m),m), - x ^ k % m = rcout(rcpow(rcin(x,m),k,m),m). + x ^ k % m = rcout(rcpow(rcin(x,m),k,m),m). RUNTIME If the value of m in rcout(x,m) is being used for the first time in @@ -71,7 +71,7 @@ SEE ALSO ## ## 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 +## 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 @@ -79,8 +79,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/02/25 02:22:21 -## File existed as early as: 1996 +## Under source code control: 1996/02/25 02:22:21 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/rcpow b/help/rcpow index 2ff6434..20929a4 100644 --- a/help/rcpow +++ b/help/rcpow @@ -5,16 +5,16 @@ SYNOPSIS rcpow(x, k, m) TYPES - x integer - k nonnegative integer - m odd positive integer + x integer + k nonnegative integer + m odd positive integer - return integer v, 0 <= v < m. + return integer v, 0 <= v < m. DESCRIPTION Let B be the base calc uses for representing integers internally (B = 2^16 for 32-bit machines, 2^32 for 64-bit machines) and N the - number of words (base-B digits) in the representation of m. Then + number of words (base-B digits) in the representation of m. Then rcpow(x,k,m) returns the value of B^-N * (B^N * x)^k % m, w here the inverse implicit in B^-N is modulo m and the modulus operator % gives the least nonnegative residue. Note that rcpow(x,0,m) = @@ -23,27 +23,27 @@ DESCRIPTION The normal use of rcpow() may be said to be that of finding the encoded value of the k-th power of an integer modulo m: - rcin(x^k, m) = rcpow(rcin(x,m), k, m), + rcin(x^k, m) = rcpow(rcin(x,m), k, m), from which one gets: - x^k % m = rcout(rcpow(rcin(x,m), k, m), m). + x^k % m = rcout(rcpow(rcin(x,m), k, m), m). If x^k % m is to be evaluated for the same k and m and several values of x, it may be worth while to first evaluate: - a = minv(rcpow(1, k, m), m); + a = minv(rcpow(1, k, m), m); and use: - x^k % m = a * rcpow(x, k, m) % m. + x^k % m = a * rcpow(x, k, m) % m. RUNTIME If the value of m in rcpow(x,k,m) is being used for the first time in a REDC function, the information required for the REDC algorithms is calculated and stored for future use, possibly replacing an already stored valued, in a table covering up to 5 - (i.e. MAXREDC) values of m. The runtime required for this is about + (i.e. MAXREDC) values of m. The runtime required for this is about two times that required for multiplying two N-word integers. Two algorithms are available for evaluating rcpow(x,k,m), the one @@ -80,7 +80,7 @@ SEE ALSO ## ## 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 +## 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 @@ -88,8 +88,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/02/25 02:22:21 -## File existed as early as: 1996 +## Under source code control: 1996/02/25 02:22:21 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/rcsq b/help/rcsq index 363fe29..20e67aa 100644 --- a/help/rcsq +++ b/help/rcsq @@ -5,10 +5,10 @@ SYNOPSIS rcsq(x, m) TYPES - x integer - m odd positive integer + x integer + m odd positive integer - return integer v, 0 <= v < m. + return integer v, 0 <= v < m. DESCRIPTION Let B be the base calc uses for representing integers internally @@ -21,15 +21,15 @@ DESCRIPTION The normal use of rcsq() may be said to be that of squaring modulo m a value encoded by rcin() and REDC functions, as in: - rcin(x^2, m) = rcsq(rcin(x,m), m) + rcin(x^2, m) = rcsq(rcin(x,m), m) from which we get: - x^2 % m = rcout(rcsq(rcin(x,m), m), m) + x^2 % m = rcout(rcsq(rcin(x,m), m), m) Alternatively, x^2 % m may be evaluated usually more quickly by: - x^2 % m = rcin(rcsq(x,m), m). + x^2 % m = rcin(rcsq(x,m), m). RUNTIME If the value of m in rcsq(x,m) is being used for the first time in @@ -74,7 +74,7 @@ SEE ALSO ## ## 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 +## 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 @@ -82,8 +82,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/02/25 02:22:21 -## File existed as early as: 1996 +## Under source code control: 1996/02/25 02:22:21 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/re b/help/re index 5cdff85..6174435 100644 --- a/help/re +++ b/help/re @@ -5,9 +5,9 @@ SYNOPSIS re(x) TYPES - x real or complex + x real or complex - return real + return real DESCRIPTION If x = u + v * 1i where u and v are real, re(x) returns u. @@ -33,7 +33,7 @@ SEE ALSO ## ## 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 +## 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 @@ -41,8 +41,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:27 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:27 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/remove b/help/remove index b72c996..6ba425f 100644 --- a/help/remove +++ b/help/remove @@ -5,9 +5,9 @@ SYNOPSIS remove(lst) TYPES - lst lvalue whose current value is a list + lst lvalue whose current value is a list - return any + return any DESCRIPTION If lst has no members, remove(lst) returns the null value and does @@ -26,14 +26,14 @@ EXAMPLE [[1]] = "three" ; remove(lst) - "three" + "three" ; print lst list (1 elements, 1 nonzero): [[0]] = 2 ; remove(lst) - 2 + 2 ; print lst list (0 elements, 0 nonzero) ; remove(lst) @@ -58,7 +58,7 @@ SEE ALSO ## ## 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 +## 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 @@ -66,8 +66,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/03/12 23:10:01 -## File existed as early as: 1996 +## Under source code control: 1996/03/12 23:10:01 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/reverse b/help/reverse index 936ac36..03a09a8 100644 --- a/help/reverse +++ b/help/reverse @@ -5,13 +5,13 @@ SYNOPSIS reverse(x) TYPES - x list or matrix + x list or matrix - return same type as x + return same type as x DESCRIPTION For a list or matrix x, reverse(x) returns a list or matrix in - which the order of the elements has been reversed. The original + which the order of the elements has been reversed. The original list or matrix x is unchanged. In the case of matrix x, the returned value is a matrix with @@ -23,11 +23,11 @@ EXAMPLE ; print reverse(A) list (5 elements, 5 nonzero): - [[0]] = 2 - [[1]] = 4 - [[2]] = 2 - [[3]] = 7 - [[4]] = 1 + [[0]] = 2 + [[1]] = 4 + [[2]] = 2 + [[3]] = 7 + [[4]] = 1 ; mat B[2,3] = {1,2,3,4,5,6} ; print reverse(B) @@ -57,7 +57,7 @@ SEE ALSO ## ## 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 +## 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 @@ -65,8 +65,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/09 19:41:26 -## File existed as early as: 1995 +## Under source code control: 1995/07/09 19:41:26 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/rewind b/help/rewind index dd3c5ff..dfd8101 100644 --- a/help/rewind +++ b/help/rewind @@ -5,9 +5,9 @@ SYNOPSIS rewind([f_1, f_2, ...]) TYPES - f_1, f_2, ... open file streams + f_1, f_2, ... open file streams - return null value or error + return null value or error DESCRIPTION With one or more arguments f_1, ..., this function sets the @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:05:18 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:05:18 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/rm b/help/rm index c774ddd..028acdc 100644 --- a/help/rm +++ b/help/rm @@ -5,12 +5,12 @@ SYNOPSIS rm(["-f",] name, ...) TYPES - name name of a file(s) + name name of a file(s) - return nil + return nil DESCRIPTION - Removes one or more files. If the first arg is "-f", then a forced + Removes one or more files. If the first arg is "-f", then a forced removal is performed and "no such file" errors are ignored. EXAMPLE @@ -34,7 +34,7 @@ SEE ALSO ## ## 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 +## 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 @@ -42,8 +42,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/06/30 22:02:58 -## File existed as early as: 1996 +## Under source code control: 1996/06/30 22:02:58 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/root b/help/root index 56c88ba..db6c1b4 100644 --- a/help/root +++ b/help/root @@ -5,11 +5,11 @@ SYNOPSIS root(x, n, [, eps]) TYPES - x number - n positive integer - eps nonzero real, defaults to epsilon() + x number + n positive integer + eps nonzero real, defaults to epsilon() - return real number + return real number DESCRIPTION For real x and positive integer n, n being odd if x is negative, @@ -60,7 +60,7 @@ SEE ALSO ## ## 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 +## 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 @@ -68,8 +68,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:46 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:46 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/round b/help/round index bde3139..7f458ca 100644 --- a/help/round +++ b/help/round @@ -17,11 +17,11 @@ TYPES For other cases: - x number (real or complex) - plcs integer, defaults to zero - rnd integer, defaults to config("round") + x number (real or complex) + plcs integer, defaults to zero + rnd integer, defaults to config("round") - return number + return number DESCRIPTION For real x, round(x, plcs, rnd) returns x rounded to either @@ -31,39 +31,39 @@ DESCRIPTION If the number of decimal places is n and eps = 10^-n, the result is the same as for appr(x, eps, rnd). This will be exactly x if x is a multiple of eps; otherwise rounding occurs - to one of the nearest multiples of eps on either side of x. Which + to one of the nearest multiples of eps on either side of x. Which of these multiples is returned is determined by z = rnd & 31, i.e. the five low order bits of rnd, as follows: - z = 0 or 4: round down, i.e. towards minus infinity - z = 1 or 5: round up, i.e. towards plus infinity - z = 2 or 6: round towards zero - z = 3 or 7: round away from zero - z = 8 or 12: round to the nearest even multiple of eps - z = 9 or 13: round to the nearest odd multiple of eps - z = 10 or 14: round to nearest even or odd multiple of eps - according as x > or < 0 - z = 11 or 15: round to nearest odd or even multiple of eps - according as x > or < 0 - z = 16 to 31: round to the nearest multiple of eps when - this is uniquely determined. Otherwise - rounding is as if z is replaced by z - 16 + z = 0 or 4: round down, i.e. towards minus infinity + z = 1 or 5: round up, i.e. towards plus infinity + z = 2 or 6: round towards zero + z = 3 or 7: round away from zero + z = 8 or 12: round to the nearest even multiple of eps + z = 9 or 13: round to the nearest odd multiple of eps + z = 10 or 14: round to nearest even or odd multiple of eps + according as x > or < 0 + z = 11 or 15: round to nearest odd or even multiple of eps + according as x > or < 0 + z = 16 to 31: round to the nearest multiple of eps when + this is uniquely determined. Otherwise + rounding is as if z is replaced by z - 16 For complex x: - The real and imaginary parts are rounded as for real x; if the - imaginary part rounds to zero, the result is real. + The real and imaginary parts are rounded as for real x; if the + imaginary part rounds to zero, the result is real. For matrix or list x: - The returned values has element round(x[[i]], plcs, rnd) in - the same position as x[[i]] in x. + The returned values has element round(x[[i]], plcs, rnd) in + the same position as x[[i]] in x. For object x or plcs: - When round(x, plcs, rnd) is called, x is passed by address so may be - changed by assignments; plcs and rnd are copied to temporary - variables, so their values are not changed by the call. + When round(x, plcs, rnd) is called, x is passed by address so may be + changed by assignments; plcs and rnd are copied to temporary + variables, so their values are not changed by the call. EXAMPLE ; a = 7/32, b = -7/32 @@ -100,18 +100,18 @@ EXAMPLE ; print round(A,2,24) list(7 elements, 7 nonzero): - [[0]] = 0.12 - [[1]] = 0.25 - [[3]] = 0.38 - [[4]] = 0.5 - [[5]] = 0.62 - [[6]] = 0.75 - [[7]] = 0.88 + [[0]] = 0.12 + [[1]] = 0.25 + [[3]] = 0.38 + [[4]] = 0.5 + [[5]] = 0.62 + [[6]] = 0.75 + [[7]] = 0.88 LIMITS For non-object case: - 0 <= abs(plcs) < 2^31 - 0 <= abs(rnd) < 2^31 + 0 <= abs(plcs) < 2^31 + 0 <= abs(rnd) < 2^31 LINK LIBRARY void roundvalue(VALUE *x, VALUE *plcs, VALUE *rnd, VALUE *result) @@ -130,7 +130,7 @@ SEE ALSO ## ## 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 +## 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 @@ -138,8 +138,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/30 00:52:38 -## File existed as early as: 1994 +## Under source code control: 1994/09/30 00:52:38 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/rsearch b/help/rsearch index 6dd0f5d..5f852f7 100644 --- a/help/rsearch +++ b/help/rsearch @@ -5,12 +5,12 @@ SYNOPSIS rsearch(a, b [, [c] [, [d] ] ]) TYPES - a matrix, list, association, or file open for reading - b string if a is a file, otherwise any - c integer, defaults to zero, size(a) or the current file-position - d integer, defaults to size(a) or current file-position + a matrix, list, association, or file open for reading + b string if a is a file, otherwise any + c integer, defaults to zero, size(a) or the current file-position + d integer, defaults to size(a) or current file-position - return nonnegative integer or null + return nonnegative integer or null DESCRIPTION @@ -38,7 +38,7 @@ Four argument case: For non-file a, the search is for a[[i]] == b, except that if the function accept() as been defined, it is for i such that - accept(a[[i]], b) tests as nonzero. Since the addresses (rather than + accept(a[[i]], b) tests as nonzero. Since the addresses (rather than values) of a[[i]] and b are passed to accept(), the values of one or both of a[[i]] and b may be changed during a call to rsearch(). @@ -74,28 +74,28 @@ Four argument case: EXAMPLE ; L = list(2,"three",4i) ; rsearch(L,"three") - 1 + 1 ; rsearch(L,"threes") ; rsearch(L, 4i, 4) ; rsearch(L, 4i, 1) - 2 + 2 ; f = fopen("foo", "w+") ; fputs(f, "This file has 28 characters.") ; fflush(f) ; rsearch(f, "ha") - 18 + 18 ; ftell(f) - 19 + 19 ; rsearch(f, "ha", 17) - 10 + 10 ; rsearch(f, "ha", 9) ; ftell(f) - 0 + 0 ; rsearch(f, "ha") - 18 + 18 ; rsearch(f, "ha", 5, 500) - 18 + 18 LIMITS none @@ -117,7 +117,7 @@ SEE ALSO ## ## 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 +## 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 @@ -125,8 +125,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 03:13:21 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 03:13:21 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/runtime b/help/runtime index dfa9f8d..af161e0 100644 --- a/help/runtime +++ b/help/runtime @@ -5,7 +5,7 @@ SYNOPSIS runtime() TYPES - return nonnegative real + return nonnegative real DESCRIPTION In POSIX based systems, this function will return the CPU seconds @@ -25,7 +25,7 @@ EXAMPLE ; t = runtime(); ; x = ptest(2^4253-1); ; runtime() - t; - 1.288804 + 1.288804 LIMITS On non-POSIX based systems, this function always returns 0. @@ -44,7 +44,7 @@ SEE ALSO ## ## 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 +## 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 @@ -52,8 +52,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/03/12 23:10:01 -## File existed as early as: 1996 +## Under source code control: 1996/03/12 23:10:01 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/saveval b/help/saveval index 47fbfa7..60366a6 100644 --- a/help/saveval +++ b/help/saveval @@ -5,9 +5,9 @@ SYNOPSIS saveval(arg) TYPES - arg any + arg any - return null value + return null value DESCRIPTION When evaluation of a line of statements at top level starts, a @@ -28,15 +28,15 @@ EXAMPLE ; saveval(1); ; a = 27; . - 27 + 27 ; saveval(0); ; a = 45 . - 27 + 27 ; saveval(1); ; a = 63 . - 63 + 63 LIMITS none @@ -55,7 +55,7 @@ SEE ALSO ## ## 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 +## 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 @@ -63,8 +63,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/09/06 20:03:35 -## File existed as early as: 1997 +## Under source code control: 1997/09/06 20:03:35 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/scale b/help/scale index 79e32df..4cd3930 100644 --- a/help/scale +++ b/help/scale @@ -11,10 +11,10 @@ TYPES For other x: - x number (real or complex) or matrix - n integer + x number (real or complex) or matrix + n integer - return same type as x + return same type as x DESCRIPTION Returns the value of 2^n * x. @@ -45,7 +45,7 @@ SEE ALSO ## ## 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 +## 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 @@ -53,8 +53,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 12:34:58 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 12:34:58 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/scan b/help/scan index 58be95d..eae2edc 100644 --- a/help/scan +++ b/help/scan @@ -5,13 +5,13 @@ SYNOPSIS scan(x_1, x_2, ..., x_n) TYPES - x_1, x_2, ... any + x_1, x_2, ... any - return integer + return integer DESCRIPTION When input is from a terminal, execution is halted and input is read - until a newline is entered. Strings of non-whitespace characters + until a newline is entered. Strings of non-whitespace characters are evaluated in succession and if the corresponding x_i is an lvalue, the resulting value is assigned to x_i. If the number of strings read exceeds n, only the first n strings are evaluated. If the number @@ -20,9 +20,9 @@ DESCRIPTION EXAMPLE ; global a, b, c, d; ; scan(a, 0, c, d) - ; 2+3 b=a^2 3+4i 3+"a" + ; 2+3 b=a^2 3+4i 3+"a" ; print a,b,c,d - 5 25 3+4i Error E_ADD + 5 25 3+4i Error E_ADD LIMITS The number of arguments is not to exceed 1024. @@ -41,7 +41,7 @@ SEE ALSO ## ## 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 +## 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 @@ -49,8 +49,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:05:18 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:05:18 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/scanf b/help/scanf index 28933ad..e5bc333 100644 --- a/help/scanf +++ b/help/scanf @@ -5,10 +5,10 @@ SYNOPSIS scanf(fmt, x_1, x_2, ...) TYPES - fmt string - x_1, x_2, ... lvalues + fmt string + x_1, x_2, ... lvalues - return null, nonnegative integer, or error value + return null, nonnegative integer, or error value DESCRIPTION This does the same as fscanf(files(0), fmt, x_1, x_2, ...). @@ -17,9 +17,9 @@ DESCRIPTION EXAMPLE ; global a, b, c ; scanf("%5c", a) - 1 + 1 ; a - "Alpha" + "Alpha" LIMITS The number of arguments is not to exceed 1024. @@ -38,7 +38,7 @@ SEE ALSO ## ## 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 +## 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 @@ -46,8 +46,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:05:18 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:05:18 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/script b/help/script index ef0c3f0..537f3a8 100644 --- a/help/script +++ b/help/script @@ -10,15 +10,15 @@ Calc shell scripts As a simple example, assuming a C or Bourne shell, let add be a file containing just one line: - calc -q -- $1 + $2 + calc -q -- $1 + $2 Then: - ./add 1.23 4.56 + ./add 1.23 4.56 should respond with the display of: - 5.9 + 5.9 The "-q" was included in the command to avoid reading of any start-up calc files which could contain commands not wanted @@ -30,11 +30,11 @@ Calc shell scripts By making add executable by a command like: - chmod u+x add + chmod u+x add the command used here may be simplified to: - ./add 1.23 4.56 + ./add 1.23 4.56 Here we shall assume that any script we refer to has been made executable in this way. @@ -55,63 +55,63 @@ Calc shell scripts For example, the add script should have no problem with commands like: - ./add "sqrt(2)" "3 * 4" + ./add "sqrt(2)" "3 * 4" - ./add "mat A[2,2] = {1,2,3,4}" "A^2" + ./add "mat A[2,2] = {1,2,3,4}" "A^2" - ./add "2 + 3i" "(3 + 4i)^2" + ./add "2 + 3i" "(3 + 4i)^2" If the shell arguments are to be integers, one could use scripts like the following with arithmetic expansion for the bash and ksh: - declare -i a=$1 - declare -i b=$2 - calc -q -- $a + $b + declare -i a=$1 + declare -i b=$2 + calc -q -- $a + $b and for csh: - @ a = $1 - @ b = $2 - calc -q -- $a + $b + @ a = $1 + @ b = $2 + calc -q -- $a + $b Specifying the shell for a script may be done by including in the script a first line with the "magic number" "#!" and the full file path for the shell as in: - #!/bin/bash - declare -i a=$1 - declare -i b=$2 - calc -q -- $a + $b + #!/bin/bash + declare -i a=$1 + declare -i b=$2 + calc -q -- $a + $b For a script to multiply rather than add two expressions, one could have a file mul with the one line: - calc -q -- $1 \* $2 + calc -q -- $1 \* $2 or: - calc -q -- "$1 * $2" + calc -q -- "$1 * $2" which will work so long as $1 and $2 are literal numbers, but will not work for: - ./mul 2+3 4 + ./mul 2+3 4 or: - ./mul "2 + 3" 4 + ./mul "2 + 3" 4 both of which calc interprets as evaluating 2 + 3 * 4. What should work for most shells is: - calc -q -- "($1) * ($2)" + calc -q -- "($1) * ($2)" For adding an arbitrary number of expressions that evaluate to rational numbers expressible with at most 20 decimal places, simple shell script could be used: - s=0 - for i do - s=`calc -q -- $s + $i` - done - echo sum = $s + s=0 + for i do + s=`calc -q -- $s + $i` + done + echo sum = $s This is not particularly efficient since it calls calc once for each argument. Also, a more serious script would permit more @@ -120,17 +120,17 @@ Calc shell scripts Another way of handling a sum of several expressions is with the script addall2 with a here document: - calc "-q -s" $* << + - global i, n, s; - n = argv(); - for (i = 1; i < n; i++) - s += eval(argv(i)); - print "sum =", s; - + + calc "-q -s" $* << + + global i, n, s; + n = argv(); + for (i = 1; i < n; i++) + s += eval(argv(i)); + print "sum =", s; + + In executing the command: - ./addall2 2 3 4 + ./addall2 2 3 4 the $* in this script expands to 2 3 4, and because of the "-s" in the options, calc starts with argv(1) = "2", argv(2) = "3", @@ -150,55 +150,55 @@ Calc shell scripts interpreter. Assuming the full path for calc is /usr/local/bin/calc, one could use the file addall3 with contents - #!/usr/bin/calc -q -f - global i, n, s; - n = argv(); - for (i = 1; i < n; i++) - s += eval(argv(i)); - print "sum =", s; + #!/usr/bin/calc -q -f + global i, n, s; + n = argv(); + for (i = 1; i < n; i++) + s += eval(argv(i)); + print "sum =", s; - IMPORTANT NOTE: + IMPORTANT NOTE: - The -f flag must be at the very end of the #! line. - The #! line must be the first line of the executable file. - The path after the #! must be the full path to the calc executable. + The -f flag must be at the very end of the #! line. + The #! line must be the first line of the executable file. + The path after the #! must be the full path to the calc executable. After the command: - ./addall3 2 3 4 + ./addall3 2 3 4 the arguments calc receives are argv(0) = "./addall3", argv(1) = "2", argv(3) = "3", argv(4) = "4". Another kind of script that can be useful is sqrts1: - calc -q 'global s; while (scanf("%s", s) == 1) print sqrt(eval(s));' + calc -q 'global s; while (scanf("%s", s) == 1) print sqrt(eval(s));' or what is essentially an interpreter equivalent sqrts2: - #!/usr/local/bin/calc -q -f - global s; - while (scanf('%s', s) == 1) - print sqrt(eval(s)); + #!/usr/local/bin/calc -q -f + global s; + while (scanf('%s', s) == 1) + print sqrt(eval(s)); If sqrts is either of these scripts, the command: - echo 27 2+3i | sqrts + echo 27 2+3i | sqrts or, if datafile contains the one line: - 27 2+3i + 27 2+3i or the two lines: - 27 - 2+3i + 27 + 2+3i either: - cat datafile | ./sqrts + cat datafile | ./sqrts or: - ./sqrts < datafile + ./sqrts < datafile should display the square-roots of 27 and 2+3i. The output could be piped to another command by | or directed to a file by use of @@ -214,7 +214,7 @@ Calc shell scripts options, but neither "-s" nor "--" in its first line) is that it can be invoked with further options as in - echo 2 3 4 | ./sqrts2 -i -D 32 + echo 2 3 4 | ./sqrts2 -i -D 32 An advantage of non-interpreter files is that they can use shell features. For example, for unquoted arguments or arguments in @@ -223,23 +223,23 @@ Calc shell scripts compiled by calc. For example, if "doit" is an executable script with contents - calc -q -- "$1($2)" + calc -q -- "$1($2)" it may be used as in: - ./doit sqrt 7 + ./doit sqrt 7 and: - ./doit exp 7 + ./doit exp 7 to display the values of sqrt(7) and exp(7). The "--" prevents a leading '-' in the $1 argument as indicating one or more additional options. E.g., without the "--" in doit, - ./doit -sqrt 7 + ./doit -sqrt 7 would be interpreted as: - calc -q "-sqrt(7)" + calc -q "-sqrt(7)" in which the dash in the quoted part would be taken as indicating a list of options -s, -q, -r, etc.; this would give an "illegal option" @@ -249,26 +249,26 @@ Calc shell scripts calc function name and $2 to an expression; all that is required is that: - $1($2) + $1($2) expands to a string that calc will recognize as a command. E.g.: - ./doit "define f(x) = x^2; 2 + mod" "f(7), 6" + ./doit "define f(x) = x^2; 2 + mod" "f(7), 6" does the same as: - calc -q -- "define f(x) = x^2; 2 + mod(f(7), 6)" + calc -q -- "define f(x) = x^2; 2 + mod(f(7), 6)" Essentially the same is achieved by the contents of doit is changed to: - calc -q -p -- << + - $1($2) - + + calc -q -p -- << + + $1($2) + + The "-p" stops calc going interactive; without it the effect would be be the same as that of a script with the one line: - calc -q -i -- "$1($2)" + calc -q -i -- "$1($2)" For more information use the following calc commands: @@ -285,7 +285,7 @@ For more information use the following calc commands: ## ## 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 +## 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 @@ -293,9 +293,9 @@ For more information use the following calc commands: ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1999/11/30 05:29:48 -## File existed as early as: 1999 +## Under source code control: 1999/11/30 05:29:48 +## File existed as early as: 1999 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/search b/help/search index 77986ee..365214d 100644 --- a/help/search +++ b/help/search @@ -5,12 +5,12 @@ SYNOPSIS search(a, b [, [c] [, [d] ] ]) TYPES - a matrix, list, association or file - b string if a is a file, otherwise any - c integer, defaults to zero or current file-position - d integer, defaults to size(a) or current file-position + a matrix, list, association or file + b string if a is a file, otherwise any + c integer, defaults to zero or current file-position + d integer, defaults to size(a) or current file-position - return nonnegative integer or null value + return nonnegative integer or null value DESCRIPTION @@ -24,24 +24,24 @@ DESCRIPTION For a matrix, list, or association a, search(a, b, c, d) returns, if it exists, the least index i for which - c <= i < d, 0 <= i < size(a), and, if accept() has not been defined, + c <= i < d, 0 <= i < size(a), and, if accept() has not been defined, a[[i]] == b, or if accept() has been defined, accept(a[[i]], b) tests as nonzero. The null value is returned if there is no such i. For example, to search for the first a[[i]] > b an appropriate accept() function is given by: - define accept(v,b) = (v > b); + define accept(v,b) = (v > b); To restore the original behavior of search(), one may then use - define accept(v, b) = (v == b). + define accept(v, b) = (v == b). Since the addresses (rather than values) of a and b are passed, the values of v = x[[i]] and b may be changed during execution of search(a, b, c, d), e.g. if accept(v,b) has been defined by - define accept(v,b) = (v > b ? v-- : b++); + define accept(v,b) = (v > b ? v-- : b++); For a is a file-stream: @@ -81,37 +81,37 @@ DESCRIPTION EXAMPLE ; L = list(2,"three",4i) ; search(L,"three") - 1 + 1 ; search(L,"threes") ; search(L, 4i, 4) ; search(L, 4i, 1) - 2 + 2 ; f = fopen("foo", "w+") ; fputs(f, "This file has 28 characters.") ; rewind(f) ; search(f, "ha") - 10 + 10 ; ftell(f) - 12 + 12 ; search(f, "ha") - 18 + 18 ; search(f, "ha") ; search(f, "ha",) - 10 + 10 ; search(f, "ha", 12) - 18 + 18 ; search(f, "ha", -10) - 18 + 18 ; search(f, "ha", ,) - 10 + 10 ; search(f, "ha", 11, 19) ; ftell(f) - 18 + 18 ; search(f, "ha", 11, 20) - 18 + 18 ; search(f, "ha", 5, 500) - 10 + 10 LIMITS none @@ -133,7 +133,7 @@ SEE ALSO ## ## 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 +## 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 @@ -141,8 +141,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 03:13:21 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 03:13:21 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/sec b/help/sec index 7d93cb3..6d76f4a 100644 --- a/help/sec +++ b/help/sec @@ -5,10 +5,10 @@ SYNOPSIS sec(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Calculate the trigonometric secant of x to a multiple of eps, with error less @@ -16,7 +16,7 @@ DESCRIPTION This function is equivalent to: - sec(x) = 1 / cos(x) + sec(x) = 1 / cos(x) EXAMPLE ; print sec(1/2), sec(5/7), sec(42/7) @@ -56,14 +56,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 1999,2023 Landon Curt Noll ## @@ -73,7 +73,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -81,8 +81,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/13 03:49:00 -## File existed as early as: 1995 +## Under source code control: 1995/11/13 03:49:00 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/sech b/help/sech index c381d85..f1d92a9 100644 --- a/help/sech +++ b/help/sech @@ -5,10 +5,10 @@ SYNOPSIS sech(x [,eps]) TYPES - x real - eps 0 < real < 1, defaults to epsilon() + x real + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Calculate the sech of x to the nearest or next to nearest multiple of @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/11/13 03:49:00 -## File existed as early as: 1995 +## Under source code control: 1995/11/13 03:49:00 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/seed b/help/seed index 1116158..2b8ada7 100644 --- a/help/seed +++ b/help/seed @@ -5,20 +5,20 @@ SYNOPSIS seed() TYPES - return integer + return integer DESCRIPTION Generate a pseudo-random seed based on a collection of system and process information. The seed() builtin function returns a value: - 0 <= seed < 2^64 + 0 <= seed < 2^64 IMPORTANT WARNING: - It should be pointed out that the information collected by seed - is almost certainly non-chaotic. This function is likely not - suitable for applications (such as cryptographic applications) - where the unpredictability of seeds is critical. + It should be pointed out that the information collected by seed + is almost certainly non-chaotic. This function is likely not + suitable for applications (such as cryptographic applications) + where the unpredictability of seeds is critical. Given the above warning, this builtin function produces a seed that is suitable for most applications that desire a different pseudo-random @@ -52,7 +52,7 @@ SEE ALSO ## ## 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 +## 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 @@ -60,8 +60,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1999/10/03 10:04:29 -## File existed as early as: 1999 +## Under source code control: 1999/10/03 10:04:29 +## File existed as early as: 1999 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/segment b/help/segment index 9565c20..b952e21 100644 --- a/help/segment +++ b/help/segment @@ -5,15 +5,15 @@ SYNOPSIS segment(x, y, z) TYPES - x list - y, z int + x list + y, z int - return list + return list DESCRIPTION For 0 <= y < size(x) and 0 <= z < size(x), segment(x, y, z) returns a list for which the values of the elements are those - of the segment of x from x[[y]] to x[[z]]. If y < z, the + of the segment of x from x[[y]] to x[[z]]. If y < z, the new list is in the same order as x; if y > z, the order is reversed. @@ -24,16 +24,16 @@ EXAMPLE ; segment(A, 1, 3) list (3 members, 3 nonzero): - [[0]] = 3 - [[1]] = 5 - [[2]] = 7 + [[0]] = 3 + [[1]] = 5 + [[2]] = 7 ; segment(A, 3, 1) list (3 members, 3 nonzero): - [[0]] = 7 - [[1]] = 5 - [[2]] = 3 + [[0]] = 7 + [[1]] = 5 + [[2]] = 3 LIMITS 0 <= y < size(x) @@ -53,7 +53,7 @@ SEE ALSO ## ## 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 +## 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 @@ -61,8 +61,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/10 02:09:31 -## File existed as early as: 1995 +## Under source code control: 1995/07/10 02:09:31 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/select b/help/select index 9f5d0e7..78776dc 100644 --- a/help/select +++ b/help/select @@ -5,16 +5,16 @@ SYNOPSIS select(x, y) TYPES - x list - y string + x list + y string - return list + return list DESCRIPTION If y is to be the name of a user-defined function, select(x, y) returns a list whose members are the values z of elements of x for which the function at z tests as nonzero. - The list x is not changed. The order of the returned list is + The list x is not changed. The order of the returned list is the same as in x. EXAMPLE @@ -23,9 +23,9 @@ EXAMPLE ; print select(A, "f") list (3 elements, 3 nonzero): - [[0]] = 6 - [[1]] = 8 - [[2]] = 7 + [[0]] = 6 + [[1]] = 8 + [[2]] = 7 LIMITS none @@ -45,7 +45,7 @@ SEE ALSO ## ## 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 +## 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 @@ -53,8 +53,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/10 02:09:31 -## File existed as early as: 1995 +## Under source code control: 1995/07/10 02:09:31 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/sgn b/help/sgn index 996691f..164c401 100644 --- a/help/sgn +++ b/help/sgn @@ -5,22 +5,22 @@ SYNOPSIS sgn(x) TYPES - x real or complex + x real or complex - return -1, 0, 1 (real) - -1, 0, 1, -1+1i, 1i, 1+1i, -1-1i, -1i or 1-1i (complex) + return -1, 0, 1 (real) + -1, 0, 1, -1+1i, 1i, 1+1i, -1-1i, -1i or 1-1i (complex) DESCRIPTION Return the value of cmp(a,0). For real x, sgn(x) returns: - -1 if x < 0 - 0 if x == 9 - 1 if x > 0 + -1 if x < 0 + 0 if x == 9 + 1 if x > 0 For complex, sgn(x) returns: - sgn(re(x)) + sgn(im(x))*1i + sgn(re(x)) + sgn(im(x))*1i EXAMPLE ; print sgn(27), sgn(1e-20), sgn(0), sgn(-45) @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:46 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:46 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/sha1 b/help/sha1 index 6c2712f..ccddc0c 100644 --- a/help/sha1 +++ b/help/sha1 @@ -5,10 +5,10 @@ SYNOPSIS sha1([arg1 [, val ...]]) TYPES - arg1 any - val any + arg1 any + val any - return HASH or number + return HASH or number DESCRIPTION The sha1() builtin implements the old Secure Hash Algorithm @@ -25,58 +25,58 @@ DESCRIPTION The new arg1 HASH state is returned. If arg1 is not a a HASH state, then the initial HASH is - used and modified by arg1 and any val args supplied. The + used and modified by arg1 and any val args supplied. The return value is the new HASH state. The following table gives a summary of actions and return values. Here, assume that 'h' is a HASH state: - sha1() HASH returns initial HASH state + sha1() HASH returns initial HASH state - sha1(h) number h is put into final form and the - numeric value of the hash state + sha1(h) number h is put into final form and the + numeric value of the hash state - sha1(x) HASH modify the initial state by hashing 'x' + sha1(x) HASH modify the initial state by hashing 'x' - sha1(sha1(), x) HASH the same as sha1(x) + sha1(sha1(), x) HASH the same as sha1(x) - sha1(x, y) HASH the same as sha1(sha1(x), y) + sha1(x, y) HASH the same as sha1(sha1(x), y) - sha1(h, x, y) HASH modify state 'h' by 'x' and then 'y' + sha1(h, x, y) HASH modify state 'h' by 'x' and then 'y' - sha1(sha1(h,x,y)) number numeric value of the above call + sha1(sha1(h,x,y)) number numeric value of the above call EXAMPLE ; base(16) - 0xa + 0xa ; sha1() - sha1 hash state + sha1 hash state ; sha1(sha1()) - 0xda39a3ee5e6b4b0d3255bfef95601890afd80709 + 0xda39a3ee5e6b4b0d3255bfef95601890afd80709 ; sha1("x", "y", "z") == sha1("xyz") - 1 + 1 ; sha1("x", "y", "z") == sha1("xy") - 0 + 0 ; sha1(sha1("this is", 7^19-8, "a composite", 3i+4.5, "hash")) - 0xc3e1b562bf45b3bcfc055ac65b5b39cdeb6a6c55 + 0xc3e1b562bf45b3bcfc055ac65b5b39cdeb6a6c55 ; x = sha1(list(1,2,3), "curds and whey", 2^21701-1, pi()) ; x - sha1 hash state + sha1 hash state ; sha1(x) - 0x988d2de4584b7536aa9a50a5749707a37affa1b5 + 0x988d2de4584b7536aa9a50a5749707a37affa1b5 ; y = sha1() ; y = sha1(y, list(1,2,3), "curds and whey") ; y = sha1(y, 2^21701-1) ; y = sha1(y, pi()) ; y - sha1 hash state + sha1 hash state ; sha1(y) - 0x988d2de4584b7536aa9a50a5749707a37affa1b5 + 0x988d2de4584b7536aa9a50a5749707a37affa1b5 LIMITS none @@ -107,7 +107,7 @@ SEE ALSO ## ## 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 +## 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 @@ -115,8 +115,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/03/23 00:01:18 -## File existed as early as: 1997 +## Under source code control: 1997/03/23 00:01:18 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/sin b/help/sin index 6445a04..6ba7107 100644 --- a/help/sin +++ b/help/sin @@ -5,10 +5,10 @@ SYNOPSIS sin(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the trigonometric sine of x to a multiple of eps with error less in @@ -50,14 +50,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 1999,2021,2023 Landon Curt Noll ## @@ -67,7 +67,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -75,8 +75,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 01:40:28 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 01:40:28 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/sinh b/help/sinh index 9eec087..4aea7d8 100644 --- a/help/sinh +++ b/help/sinh @@ -5,10 +5,10 @@ SYNOPSIS sinh(x [,eps]) TYPES - x real - eps 0 < real < 1, defaults to epsilon() + x real + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Calculate the sinh of x to the nearest or next to nearest multiple of @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 01:40:29 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 01:40:29 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/size b/help/size index a4c7250..441fb50 100644 --- a/help/size +++ b/help/size @@ -5,29 +5,29 @@ SYNOPSIS size(x) TYPES - x any + x any - return integer + return integer DESCRIPTION For the different types of value x may have, size(x) is defined as follows: - null 0 - real number 1 - complex number 1 - string length of string (not including the trailing \0) - matrix number of elements - list number of members - association number of (elements, value) pairs - object value returned by xx_size(x) if x of type xx - file length of the file in octets - rand state 1 - random state 1 - config state 1 - hash state 1 - block number of octets of data it currently holds - octet 1 - named block number of octets of data it currently holds + null 0 + real number 1 + complex number 1 + string length of string (not including the trailing \0) + matrix number of elements + list number of members + association number of (elements, value) pairs + object value returned by xx_size(x) if x of type xx + file length of the file in octets + rand state 1 + random state 1 + config state 1 + hash state 1 + block number of octets of data it currently holds + octet 1 + named block number of octets of data it currently holds EXAMPLE ; print size(null()), size(3), size(2 - 7i), size("abc") @@ -65,7 +65,7 @@ SEE ALSO ## ## 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 +## 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 @@ -73,8 +73,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 03:13:22 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 03:13:22 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/sizeof b/help/sizeof index 945eb6e..b268962 100644 --- a/help/sizeof +++ b/help/sizeof @@ -5,21 +5,21 @@ SYNOPSIS sizeof(x) TYPES - x any + x any - return integer + return integer DESCRIPTION This is analogous to the C operator sizeof for the value only. It attempts to assess the number of bytes in memory used to store - a value and all of its components. Unlike memsize(x), this + a value and all of its components. Unlike memsize(x), this builtin does not include the size of the overhead. Unlike size(x), this builtin includes the trailing \0 byte on the end of strings. For numeric values, sizeof(x) ignores the denominator if 'x' is - an integer. For complex values, sizeof(x) ignores the imaginary + an integer. For complex values, sizeof(x) ignores the imaginary part if 'x' is real. Because the 0, 1 and -1 numeric values are shared static values, sizeof(x) reports such values as having 0 bytes of storage. @@ -34,15 +34,15 @@ DESCRIPTION substantially greater) than the number of bytes actually used. For example, after: - a = sqrt(2); - mat A[3] = {a, a, a}; + a = sqrt(2); + mat A[3] = {a, a, a}; the numerical information for a, A[0], A[1], A[2] are stored in the same memory, so the memory used for A is the same as if its 3 elements were null values. The value returned by sizeof(A) is calculated as A were defined by: - mat A[3] = {sqrt(2), sqrt(2), sqrt(2)}. + mat A[3] = {sqrt(2), sqrt(2), sqrt(2)}. Similar sharing of memory occurs with literal strings. @@ -93,7 +93,7 @@ SEE ALSO ## ## 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 +## 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 @@ -101,8 +101,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/05/24 02:04:04 -## File existed as early as: 1996 +## Under source code control: 1996/05/24 02:04:04 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/sleep b/help/sleep index 3cfa398..2aaebc8 100644 --- a/help/sleep +++ b/help/sleep @@ -5,9 +5,9 @@ SYNOPSIS sleep([n]) TYPES - n non-negative real, defaults to 1 + n non-negative real, defaults to 1 - return integer or null value + return integer or null value DESCRIPTION This uses the C-library sleep (if n is integral) or usleep (for @@ -18,18 +18,18 @@ DESCRIPTION One kind of use is to slow down output to permit easier reading of results, as in: - ; for (i = 0; i < 100; i++) { - ;; print sqrt(i); - ;; sleep(1/2); - ;; } + ; for (i = 0; i < 100; i++) { + ;; print sqrt(i); + ;; sleep(1/2); + ;; } The following illustrates what happens if ctrl-C is hit 5 seconds after the first command: - ; print sleep(20) + ; print sleep(20) - [Abort level 1] - 15 + [Abort level 1] + 15 EXAMPLE ; sleep(1/3); @@ -49,7 +49,7 @@ SEE ALSO ## ## 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 +## 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 @@ -57,7 +57,7 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2000/12/14 01:33:00 -## File existed as early as: 2000 +## Under source code control: 2000/12/14 01:33:00 +## File existed as early as: 2000 ## -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/sort b/help/sort index aad855f..9612502 100644 --- a/help/sort +++ b/help/sort @@ -5,9 +5,9 @@ SYNOPSIS sort(x) TYPES - x list or matrix + x list or matrix - return same type as x + return same type as x DESCRIPTION For a list or matrix x, sort(x) returns a list or @@ -23,22 +23,22 @@ DESCRIPTION If x is a matrix, the matrix returned by sort(x) has the same dimension and index limits as x, but for the sorting, x is treated as a one-dimensional array indexed only by the double- bracket - notation. Then for both lists and matrices, if x has size n, it + notation. Then for both lists and matrices, if x has size n, it may be identified with the array: - (x[[0]], x[[1]], ..., x[[n-1]]) + (x[[0]], x[[1]], ..., x[[n-1]]) which we will here display as: - (x_0, x_1, ..., x_n-1). + (x_0, x_1, ..., x_n-1). The value y = sort(x) will similarly be identified with: - (y_0, y_1, ..., x_n-1), + (y_0, y_1, ..., x_n-1), where, for some permutation p() of the integers (0, 1, ..., n-1): - y_p(i) = x_i. + y_p(i) = x_i. In the following i1 and i2 will be taken to refer to different indices for x, and j1 and j2 will denote p(i1) and p(i2). @@ -49,7 +49,7 @@ DESCRIPTION with earlier values b using the integer-valued function precedes(); if precedes(a,b) is nonzero, which we may consider as "true", a is "moved" to just before b; if precedes(a,b) is zero, i.e. "false", - a remains after b. Until the sorting is completed, other similar + a remains after b. Until the sorting is completed, other similar pairs (a,b) are compared and if and only if precedes(a,b) is true, a is moved to before b or b is moved to after a. We may say that the intention of precedes(a,b) being nonzero is that a should @@ -83,7 +83,7 @@ DESCRIPTION result satisfying the intentions of nonzero and zero values of precedes() as described above. For example, consider: - precedes(a,b) = a is a proper divisor of b, + precedes(a,b) = a is a proper divisor of b, and x = list(4, 3, 2). The only pair for which precedes(a,b) is nonzero is (2,4), but x cannot be rearranged so that 2 is before @@ -95,44 +95,44 @@ DESCRIPTION not y_j1 precedes or follows y_j2 will be determined by the sorting algorithm by methods that are difficult to describe; such a situation may be acceptable to a user not concerned with - the order of occurrences of a and b in the result. To permit + the order of occurrences of a and b in the result. To permit this, we may now describe the role of precedes(a,b) by the rules: - precedes(a,b) && !precedes(b,a): a is to precede b; + precedes(a,b) && !precedes(b,a): a is to precede b; - !precedes(a,b) && !precedes(b,a): order of a and b not to be changed; + !precedes(a,b) && !precedes(b,a): order of a and b not to be changed; - precedes(a,b) && precedes(b,a): order of a and b may be changed. + precedes(a,b) && precedes(b,a): order of a and b may be changed. Under the condition (1), the result of sort(x) will accord with these rules. Default precedes(): - If precedes(a,b) has not been defined by a define command, - the effect is as if precedes(a,b) were determined by: + If precedes(a,b) has not been defined by a define command, + the effect is as if precedes(a,b) were determined by: - If a and b are are not of the same type, they are ordered by + If a and b are are not of the same type, they are ordered by - null values < numbers < strings < objects. + null values < numbers < strings < objects. - If a and b are of the same type, this type being - null, numbers or strings, precedes(a,b) is given by (a < b). - (If a and b are both null, they are considered to be equal, so - a < b then returns zero.) For null values, numbers and - strings, this definition has the properties (1) and (2) - discussed above. + If a and b are of the same type, this type being + null, numbers or strings, precedes(a,b) is given by (a < b). + (If a and b are both null, they are considered to be equal, so + a < b then returns zero.) For null values, numbers and + strings, this definition has the properties (1) and (2) + discussed above. - If a and b are both xx-objects, a < b is defined to mean - xx_rel(a,b) < 0; such a definition does not - necessarily give < the properties usually expected - - transitivity and antisymmetry. In such cases, sort(x) - may not give the results expected by the "intentions" of - the comparisons expressed by "a < b". + If a and b are both xx-objects, a < b is defined to mean + xx_rel(a,b) < 0; such a definition does not + necessarily give < the properties usually expected - + transitivity and antisymmetry. In such cases, sort(x) + may not give the results expected by the "intentions" of + the comparisons expressed by "a < b". In many sorting applications, appropriate precedes() functions have definitions equivalent to: - define precedes(a,b) = (key(a) < key(b)) + define precedes(a,b) = (key(a) < key(b)) where key() maps possible values to a set totally ordered by <. Such a precedes() function has the properties (1) and (2), @@ -144,14 +144,14 @@ DESCRIPTION key1() and elements with equal key1-values then sorted by key2(), an appropriate precedes() function is given by: - define precedes(a,b) = (key(a) < key(b)) || - (key(a) == key(b)) && (key2(a) < key2(b)). + define precedes(a,b) = (key(a) < key(b)) || + (key(a) == key(b)) && (key2(a) < key2(b)). When precedes(a.b) is called, the addresses of a and b rather than their values are passed to the function. This permits a and b to be changed when they are being compared, as in: - define precedes(a,b) = ((a = round(a)) < (b = round(b))); + define precedes(a,b) = ((a = round(a)) < (b = round(b))); (A more efficient way of achieving the same result would be to use sort(round(x)).) @@ -159,86 +159,86 @@ DESCRIPTION Examples of effects of various precedes functions for sorting lists of integers: - a > b Sorts into non-increasing order. + a > b Sorts into non-increasing order. - abs(a) < abs(b) Sorts into nondecreasing order of - absolute values, numbers with the - same absolute value retaining - their order. + abs(a) < abs(b) Sorts into nondecreasing order of + absolute values, numbers with the + same absolute value retaining + their order. - abs(a) <= abs(b) Sorts into nondecreasing order of - absolute values, possibly - changing the order of numbers - with the same absolute value. + abs(a) <= abs(b) Sorts into nondecreasing order of + absolute values, possibly + changing the order of numbers + with the same absolute value. - abs(a) < abs(b) || abs(a) == abs(b) && a < b - Sorts into nondecreasing order of - absolute values, numbers with the - same absolute value being in - nondecreasing order. + abs(a) < abs(b) || abs(a) == abs(b) && a < b + Sorts into nondecreasing order of + absolute values, numbers with the + same absolute value being in + nondecreasing order. - iseven(a) Even numbers in possibly changed order - before odd numbers in unchanged order. + iseven(a) Even numbers in possibly changed order + before odd numbers in unchanged order. - iseven(a) && isoddd(b) Even numbers in unchanged order before - odd numbers in unchanged order. + iseven(a) && isoddd(b) Even numbers in unchanged order before + odd numbers in unchanged order. - iseven(a) ? iseven(b) ? a < b : 1 : 0 - Even numbers in nondecreasing order - before odd numbers in unchanged order. + iseven(a) ? iseven(b) ? a < b : 1 : 0 + Even numbers in nondecreasing order + before odd numbers in unchanged order. - a < b && a < 10 Numbers less than 10 in nondecreasing - order before numbers not less than 10 - in unchanged order. + a < b && a < 10 Numbers less than 10 in nondecreasing + order before numbers not less than 10 + in unchanged order. - !ismult(a,b) Divisors d of any integer i for which - i is not also a divisor of d will - precede occurrences of i; the order of - integers which divide each other will - remain the same; the order of pairs of - integers neither of which divides the - other may be changed. Thus occurrences - of 1 and -1 will precede all other - integers; 2 and -2 will precede all - even integers; the order of occurrences - of 2 and 3 may change; occurrences of 0 - will follow all other integers. + !ismult(a,b) Divisors d of any integer i for which + i is not also a divisor of d will + precede occurrences of i; the order of + integers which divide each other will + remain the same; the order of pairs of + integers neither of which divides the + other may be changed. Thus occurrences + of 1 and -1 will precede all other + integers; 2 and -2 will precede all + even integers; the order of occurrences + of 2 and 3 may change; occurrences of 0 + will follow all other integers. - 1 The order of the elements is reversed + 1 The order of the elements is reversed EXAMPLE ; A = list(1, 7, 2, 4, 2) ; print sort(A) list (5 elements, 5 nonzero): - [[0]] = 1 - [[1]] = 2 - [[2]] = 2 - [[3]] = 4 - [[4]] = 7 + [[0]] = 1 + [[1]] = 2 + [[2]] = 2 + [[3]] = 4 + [[4]] = 7 ; B = list("pear", 2, null(), -3, "orange", null(), "apple", 0) ; print sort(B) list (8 elements, 7 nonzero): - [[0]] = NULL - [[1]] = NULL - [[2]] = -3 - [[3]] = 0 - [[4]] = 2 - [[5]] = "apple" - [[6]] = "orange" - [[7]] = "pear" + [[0]] = NULL + [[1]] = NULL + [[2]] = -3 + [[3]] = 0 + [[4]] = 2 + [[5]] = "apple" + [[6]] = "orange" + [[7]] = "pear" ; define precedes(a,b) = (iseven(a) && isodd(b)) ; print sort(A) list (5 elements, 5 nonzero): - [[0]] = 2 - [[1]] = 4 - [[2]] = 2 - [[3]] = 1 - [[4]] = 7 + [[0]] = 2 + [[1]] = 4 + [[2]] = 2 + [[3]] = 1 + [[4]] = 7 LIMITS none @@ -257,7 +257,7 @@ SEE ALSO ## ## 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 +## 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 @@ -265,8 +265,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/09 19:41:26 -## File existed as early as: 1995 +## Under source code control: 1995/07/09 19:41:26 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/sqrt b/help/sqrt index 1e187ae..d64693c 100644 --- a/help/sqrt +++ b/help/sqrt @@ -14,11 +14,11 @@ TYPES For other argument types: - x real or complex - eps 0 < real < 1, defaults to epsilon() - z integer + x real or complex + eps 0 < real < 1, defaults to epsilon() + z integer - return real or complex + return real or complex DESCRIPTION For real or complex x, sqrt(x, y, z) returns either the exact @@ -35,60 +35,60 @@ DESCRIPTION z bit 6 ((z & 64) > 0) - 0: principal square root + 0: principal square root - 1: negative principal square root + 1: negative principal square root z bit 5 ((z & 32) > 0) - 0: return an approximation square root + 0: return an approximation square root - 1: return exact square root when real & imaginary are rational + 1: return exact square root when real & imaginary are rational - z bits 5-0 (z & 31) + z bits 5-0 (z & 31) - 0: round down or up according as y is positive or negative, - sgn(r) = sgn(y) + 0: round down or up according as y is positive or negative, + sgn(r) = sgn(y) - 1: round up or down according as y is positive or negative, - sgn(r) = -sgn(y) + 1: round up or down according as y is positive or negative, + sgn(r) = -sgn(y) - 2: round towards zero, sgn(r) = sgn(x) + 2: round towards zero, sgn(r) = sgn(x) - 3: round away from zero, sgn(r) = -sgn(x) + 3: round away from zero, sgn(r) = -sgn(x) - 4: round down + 4: round down - 5: round up + 5: round up - 6: round towards or from zero according as y is positive or - negative, sgn(r) = sgn(x/y) + 6: round towards or from zero according as y is positive or + negative, sgn(r) = sgn(x/y) - 7: round from or towards zero according as y is positive or - negative, sgn(r) = -sgn(x/y) + 7: round from or towards zero according as y is positive or + negative, sgn(r) = -sgn(x/y) - 8: a/y is even + 8: a/y is even - 9: a/y is odd + 9: a/y is odd - 10: a/y is even or odd according as x/y is positive or negative + 10: a/y is even or odd according as x/y is positive or negative - 11: a/y is odd or even according as x/y is positive or negative + 11: a/y is odd or even according as x/y is positive or negative - 12: a/y is even or odd according as y is positive or negative + 12: a/y is even or odd according as y is positive or negative - 13: a/y is odd or even according as y is positive or negative + 13: a/y is odd or even according as y is positive or negative - 14: a/y is even or odd according as x is positive or negative + 14: a/y is even or odd according as x is positive or negative - 15: a/y is odd or even according as x is positive or negative + 15: a/y is odd or even according as x is positive or negative The value of y and lowest 5 bits of z are used in the same way as y and z in appr(x, y, z): for either the real or imaginary part of the square root, if this is a multiple of y, it is returned exactly; otherwise the value returned for the part is the multiple of y nearest below or nearest above the true value. - For z = 0, the remainder has the sign of y; changing bit 0 + For z = 0, the remainder has the sign of y; changing bit 0 changes to the other possibility; for z = 2, the remainder has the sign of the true value, i.e. the rounding is towards zero; for z = 4, the remainder is always positive, i.e. the rounding is down; @@ -138,7 +138,7 @@ SEE ALSO ## ## 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 +## 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 @@ -146,8 +146,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/09/18 03:54:32 -## File existed as early as: 1995 +## Under source code control: 1995/09/18 03:54:32 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/srand b/help/srand index abbbf3a..ba16e7f 100644 --- a/help/srand +++ b/help/srand @@ -5,9 +5,9 @@ SYNOPSIS srand([seed]) TYPES - seed integer, matrix of integers or rand state + seed integer, matrix of integers or rand state - return rand state + return rand state DESCRIPTION Seed the pseudo-random number using an subtractive 100 shuffle generator. @@ -15,120 +15,120 @@ DESCRIPTION It you want a quick and effective way to seed the generator, we recommended that you call srand() with the seed() value: - srand(seed()) + srand(seed()) For integer seed != 0: - Any buffered rand generator bits are flushed. The subtractive table - for the rand generator is loaded with the default subtractive table. - The low order 64 bits of seed is xor-ed against each table value. - The subtractive table is shuffled according to seed/2^64. + Any buffered rand generator bits are flushed. The subtractive table + for the rand generator is loaded with the default subtractive table. + The low order 64 bits of seed is xor-ed against each table value. + The subtractive table is shuffled according to seed/2^64. - The following calc code produces the same effect on the internal - subtractive table: + The following calc code produces the same effect on the internal + subtractive table: - /* reload default subtractive table xor-ed with low 64 seed bits */ - seed_xor = seed & ((1<<64)-1); - for (i=0; i < 100; ++i) { - subtractive[i] = xor(default_subtractive[i], seed_xor); - } + /* reload default subtractive table xor-ed with low 64 seed bits */ + seed_xor = seed & ((1<<64)-1); + for (i=0; i < 100; ++i) { + subtractive[i] = xor(default_subtractive[i], seed_xor); + } - /* shuffle the subtractive table */ - seed >>= 64; - for (i=100; seed > 0 && i > 0; --i) { - quomod(seed, i+1, seed, j); - swap(subtractive[i], subtractive[j]); - } + /* shuffle the subtractive table */ + seed >>= 64; + for (i=100; seed > 0 && i > 0; --i) { + quomod(seed, i+1, seed, j); + swap(subtractive[i], subtractive[j]); + } - Seed must be >= 0. All seed values < 0 are reserved for future use. + Seed must be >= 0. All seed values < 0 are reserved for future use. - The subtractive table pointers are reset to subtractive[36] - and subtractive[99]. Last the shuffle table is loaded with - successive values from the subtractive 100 generator. + The subtractive table pointers are reset to subtractive[36] + and subtractive[99]. Last the shuffle table is loaded with + successive values from the subtractive 100 generator. - There is no limit on the size of a seed. On the other hand, - extremely large seeds require large tables and long seed times. - Using a seed in the range of [2^64, 2^64 * 100!) should be - sufficient for most purposes. An easy way to stay within this - range to to use seeds that are between 21 and 178 digits, or - 64 to 588 bits long. + There is no limit on the size of a seed. On the other hand, + extremely large seeds require large tables and long seed times. + Using a seed in the range of [2^64, 2^64 * 100!) should be + sufficient for most purposes. An easy way to stay within this + range to to use seeds that are between 21 and 178 digits, or + 64 to 588 bits long. - To help make the generator produced by seed S, significantly - different from S+1, seeds are scrambled prior to use. The - internal function randreseed64 maps [0,2^64) into [0,2^64) in a - 1-to-1 and onto fashion for every 64 bits of S. + To help make the generator produced by seed S, significantly + different from S+1, seeds are scrambled prior to use. The + internal function randreseed64 maps [0,2^64) into [0,2^64) in a + 1-to-1 and onto fashion for every 64 bits of S. - The purpose of the randreseed64() is not to add security. It - simply helps remove the human perception of the relationship - between the seed and the production of the generator. + The purpose of the randreseed64() is not to add security. It + simply helps remove the human perception of the relationship + between the seed and the production of the generator. - The randreseed64 process does not reduce the security of the - rand generator. Every seed is converted into a different - unique seed. No seed is ignored or favored. See the rand - help file for details. + The randreseed64 process does not reduce the security of the + rand generator. Every seed is converted into a different + unique seed. No seed is ignored or favored. See the rand + help file for details. For integer seed == 0: - Restore the initial state and modulus of the rand generator. - After this call, the rand generator is restored to its initial - state after calc started. + Restore the initial state and modulus of the rand generator. + After this call, the rand generator is restored to its initial + state after calc started. - The subtractive 100 pointers are reset to subtractive[36] - and subtractive[99]. Last the shuffle table is loaded with - successive values from the subtractive 100 generator. + The subtractive 100 pointers are reset to subtractive[36] + and subtractive[99]. Last the shuffle table is loaded with + successive values from the subtractive 100 generator. - The call: + The call: - srand(0) + srand(0) - restores the rand generator to the initial conditions at calc startup. + restores the rand generator to the initial conditions at calc startup. For matrix arg: - Any buffered random bits are flushed. The subtractive table with the - first 100 entries of the matrix mod 2^64. + Any buffered random bits are flushed. The subtractive table with the + first 100 entries of the matrix mod 2^64. - The subtractive 100 pointers are reset to subtractive[36] - and subtractive[99]. Last the shuffle table is loaded with - successive values from the subtractive 100 generator. + The subtractive 100 pointers are reset to subtractive[36] + and subtractive[99]. Last the shuffle table is loaded with + successive values from the subtractive 100 generator. - This form allows one to load the internal subtractive 100 generator - with user supplied values. + This form allows one to load the internal subtractive 100 generator + with user supplied values. - The randreseed64 process is NOT applied to the matrix values. + The randreseed64 process is NOT applied to the matrix values. For rand state arg: - Restore the rand state and return the previous state. Note that - the argument state is a rand state value (isrand(state) is true). - Any internally buffered random bits are restored. + Restore the rand state and return the previous state. Note that + the argument state is a rand state value (isrand(state) is true). + Any internally buffered random bits are restored. - All calls to srand(seed) return the previous state or current - state in case of srand(). Their return value can be supplied - to srand in restore the generator to that previous state: + All calls to srand(seed) return the previous state or current + state in case of srand(). Their return value can be supplied + to srand in restore the generator to that previous state: - state = srand(123456789); - newstate = srand(); /* save state */ + state = srand(123456789); + newstate = srand(); /* save state */ - x = rand(); - ... - srand(newstate); /* restore state to after srand(123456789) */ - x1 = rand(); /* produces the same value as x */ - ... - srand(state); /* restore original state */ + x = rand(); + ... + srand(newstate); /* restore state to after srand(123456789) */ + x1 = rand(); /* produces the same value as x */ + ... + srand(state); /* restore original state */ For no arg given: - Return current s100 generator state. This call does not alter - the generator state. + Return current s100 generator state. This call does not alter + the generator state. - This call allows one to take a snapshot of the current generator state. + This call allows one to take a snapshot of the current generator state. See the rand help file for details on the generator. EXAMPLE ; srand(0x8d2dcb2bed3212844f4ad31) - RAND state + RAND state ; state = srand(); ; print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123); 80 95 41 78 100 27 @@ -163,7 +163,7 @@ SEE ALSO ## ## 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 +## 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 @@ -171,8 +171,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/01/01 04:19:07 -## File existed as early as: 1996 +## Under source code control: 1996/01/01 04:19:07 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/srandom b/help/srandom index 47b61cf..0b6a8ca 100644 --- a/help/srandom +++ b/help/srandom @@ -8,14 +8,14 @@ SYNOPSIS srandom(seed, ip, iq, trials) TYPES - state random state - seed integer - newn integer - ip integer - iq integer - trails integer + state random state + seed integer + newn integer + ip integer + iq integer + trails integer - return random state + return random state DESCRIPTION Seed the pseudo-random number using the Blum-Blum-Shub generator. @@ -23,17 +23,17 @@ DESCRIPTION It you want a quick and effective way to seed the generator, we recommended that you call srandom() with the seed() value: - srandom(seed()) + srandom(seed()) There are two primary values contained inside generator state: - Blum modulus: + Blum modulus: - A product of two primes. Each prime is 3 mod 4. + A product of two primes. Each prime is 3 mod 4. - Quadratic residue: + Quadratic residue: - Some integer squared modulo the Blum modulus. + Some integer squared modulo the Blum modulus. Seeding the generator involves changing the Quadratic residue and in most cases the Blum modulus as well. @@ -46,273 +46,273 @@ DESCRIPTION of the generator. Depending on what args are supplied, a new generator state is established. The exception is the no-arg state. - 0 args: srandom() + 0 args: srandom() - Returns the current generator state. Unlike all of the other - srandom calls, this call does not modify the generator, nor - does it flush the internal bits. + Returns the current generator state. Unlike all of the other + srandom calls, this call does not modify the generator, nor + does it flush the internal bits. - 1 arg (state arg): srandom(state) + 1 arg (state arg): srandom(state) - sets the generator to 'state', where 'state' is a previous - return of srandom(). + sets the generator to 'state', where 'state' is a previous + return of srandom(). - 1 arg (0 seed): srandom(0) + 1 arg (0 seed): srandom(0) - Sets the generator to the initial startup state. This a - call of srandom(0) will restore the generator to the state - found when calc starts. + Sets the generator to the initial startup state. This a + call of srandom(0) will restore the generator to the state + found when calc starts. - 1 arg (seed >= 2^32): srandom(seed()) + 1 arg (seed >= 2^32): srandom(seed()) - The seed value is used to compute the new quadratic residue. - The seed passed will be successively squared mod the Blum - modulus until we get a smaller value (modulus wrap). The - calc resource file produces an equivalent effect: + The seed value is used to compute the new quadratic residue. + The seed passed will be successively squared mod the Blum + modulus until we get a smaller value (modulus wrap). The + calc resource file produces an equivalent effect: - /* assume n is the current Blum modulus */ - r = seed; - do { - last_r = r; - r = pmod(r, 2, n); - } while (r > last_r); - /* r is the new Quadratic residue */ + /* assume n is the current Blum modulus */ + r = seed; + do { + last_r = r; + r = pmod(r, 2, n); + } while (r > last_r); + /* r is the new Quadratic residue */ - In this form of srandom, the Blum modulus is not changed. + In this form of srandom, the Blum modulus is not changed. - NOTE: [1,2^32) seed values and seed<0 values - are reserved for future use. + NOTE: [1,2^32) seed values and seed<0 values + are reserved for future use. - 2 args (seed, newn>=2^32): srandom(seed, newn) + 2 args (seed, newn>=2^32): srandom(seed, newn) - The newn value is used as the new Blum modulus. This modulus - is assumed to be a product of two primes that are both 3 mod - 4. The newn value is not factored, it is only checked to see - if it is 1 mod 4. + The newn value is used as the new Blum modulus. This modulus + is assumed to be a product of two primes that are both 3 mod + 4. The newn value is not factored, it is only checked to see + if it is 1 mod 4. - In this call form, newn value must be >= 2^32. + In this call form, newn value must be >= 2^32. - The seed arg is used to establish the initial quadratic value - once newn has been made the Blum moduli. The seed must - be either 0 or >= 2^32. If seed == 0, the initial quadratic - residue used with srandom(0) is used with the new Blum moduli. - If seed >= 2^32, then srandom(seed, newn) has the same effect as: + The seed arg is used to establish the initial quadratic value + once newn has been made the Blum moduli. The seed must + be either 0 or >= 2^32. If seed == 0, the initial quadratic + residue used with srandom(0) is used with the new Blum moduli. + If seed >= 2^32, then srandom(seed, newn) has the same effect as: - srandom(0, newn); /* set Blum modulus & def quad res */ - srandom(seed); /* set quadratic residue */ + srandom(0, newn); /* set Blum modulus & def quad res */ + srandom(seed); /* set quadratic residue */ - Use of newn values that are not the product of two 3 mod 4 - primes will result in a non-cryptographically strong generator. - While the generator will produce values, their quality will - be suspect. + Use of newn values that are not the product of two 3 mod 4 + primes will result in a non-cryptographically strong generator. + While the generator will produce values, their quality will + be suspect. - The period of the generator determines how many bits will - be produced before it repeats. The period is determined - by the Blum modulus. Some newn values (that are a product - of two 3 mod 4 primes) can produce a generator with a - very short period making is useless for most applications. + The period of the generator determines how many bits will + be produced before it repeats. The period is determined + by the Blum modulus. Some newn values (that are a product + of two 3 mod 4 primes) can produce a generator with a + very short period making is useless for most applications. - When Blum modulus is p*q, the period of a generator is: + When Blum modulus is p*q, the period of a generator is: - lcm(factors of p-1 and q-1) + lcm(factors of p-1 and q-1) - One can construct a generator with a maximal period when 'p' - and 'q' have the fewest possible factors in common. The - quickest way to select such primes is only use 'p' and 'q' when - '(p-1)/2' and '(q-1)/2' are both primes. Assuming that - fp=(p-1)/2, fq=(q-1)/2, p and q are all primes 3 mod 4, the - period of the generator is the longest possible: + One can construct a generator with a maximal period when 'p' + and 'q' have the fewest possible factors in common. The + quickest way to select such primes is only use 'p' and 'q' when + '(p-1)/2' and '(q-1)/2' are both primes. Assuming that + fp=(p-1)/2, fq=(q-1)/2, p and q are all primes 3 mod 4, the + period of the generator is the longest possible: - lcm(factors of p-1 and q-1) == lcm(2,fp,2,fq) = 2*fp*fq = ~n/2 + lcm(factors of p-1 and q-1) == lcm(2,fp,2,fq) = 2*fp*fq = ~n/2 - The following calc resource file: + The following calc resource file: - /* find first Blum prime: p */ - fp = int((ip-1)/2); - do { - do { - fp = nextcand(fp+2, 1, 0, 3, 4); - p = 2*fp+1; - } while (ptest(p, 1, 0) == 0); - } while (ptest(p, trials) == 0 || ptest(fp, trials)); + /* find first Blum prime: p */ + fp = int((ip-1)/2); + do { + do { + fp = nextcand(fp+2, 1, 0, 3, 4); + p = 2*fp+1; + } while (ptest(p, 1, 0) == 0); + } while (ptest(p, trials) == 0 || ptest(fp, trials)); - /* find second Blum prime: q */ - fq = int((iq-1)/2); - do { - do { - fq = nextcand(fq+2, 1, 0, 3, 4); - q = 2*fq+1; - } while (ptest(q, 1, 0) == 0); - } while (ptest(q, trials) == 0 || ptest(fq, trials)); + /* find second Blum prime: q */ + fq = int((iq-1)/2); + do { + do { + fq = nextcand(fq+2, 1, 0, 3, 4); + q = 2*fq+1; + } while (ptest(q, 1, 0) == 0); + } while (ptest(q, trials) == 0 || ptest(fq, trials)); - /* seed the generator */ - srandom(ir, p*q); + /* seed the generator */ + srandom(ir, p*q); - Where: - ip - initial search location for the Blum prime 'p' - iq - initial search location for the Blum prime 'q' - ir - initial Blum quadratic residue generator. The 'ir' - must be 0 or >= 2^32, preferably large some random - value < p*q. The following may be useful to set ir: + Where: + ip + initial search location for the Blum prime 'p' + iq + initial search location for the Blum prime 'q' + ir + initial Blum quadratic residue generator. The 'ir' + must be 0 or >= 2^32, preferably large some random + value < p*q. The following may be useful to set ir: - srand(p+q); - ir = randbit(highbit(p)+highbit(q)) - trials - number of pseudo prime tests that a candidate must pass - before being considered a probable prime (must be >0, try 25) + srand(p+q); + ir = randbit(highbit(p)+highbit(q)) + trials + number of pseudo prime tests that a candidate must pass + before being considered a probable prime (must be >0, try 25) - The calc standard resource file seedrandom.cal will produce a - seed a generator. If the config value custom("resource_debug") - is 0 or 1, then the selected Blum modulus and quadratic residue - will be printed. If the global value is 1, then p and q are - also printed. The resource file defines the function: + The calc standard resource file seedrandom.cal will produce a + seed a generator. If the config value custom("resource_debug") + is 0 or 1, then the selected Blum modulus and quadratic residue + will be printed. If the global value is 1, then p and q are + also printed. The resource file defines the function: - seedrandom(seed1, seed2, size [, trials]) + seedrandom(seed1, seed2, size [, trials]) - Where: - seed1 - A random number >= 10^20 and perhaps < 10^93. - seed2 - A random number >= 10^20 and perhaps < 10^93. - size - Minimal Blum modulus size in bits, This must be >= 32. - A value of 512 might be a good choice. - trials - number of pseudo prime tests that a candidate must pass - before being considered a probable prime (must be >0, try 25). - Using the default value of 25 might be a good choice. + Where: + seed1 + A random number >= 10^20 and perhaps < 10^93. + seed2 + A random number >= 10^20 and perhaps < 10^93. + size + Minimal Blum modulus size in bits, This must be >= 32. + A value of 512 might be a good choice. + trials + number of pseudo prime tests that a candidate must pass + before being considered a probable prime (must be >0, try 25). + Using the default value of 25 might be a good choice. - Unfortunately finding optimal values can be very slow for large - values of 'p' and 'q'. On a 200Mhz r4k, it can take as long as - 1 minute at 512 bits, and 5 minutes at 1024 bits. + Unfortunately finding optimal values can be very slow for large + values of 'p' and 'q'. On a 200Mhz r4k, it can take as long as + 1 minute at 512 bits, and 5 minutes at 1024 bits. - For the sake of speed, you may want to use to use one of the - pre-compiled in Blum moduli via the [1 - If you don't want to use a pre-compiled in Blum moduli you can - compute your own values ahead of time. This can be done by a - method of your own choosing, or by using the seedrandom.cal - resource file in the following way: + For the sake of speed, you may want to use to use one of the + pre-compiled in Blum moduli via the [1 + If you don't want to use a pre-compiled in Blum moduli you can + compute your own values ahead of time. This can be done by a + method of your own choosing, or by using the seedrandom.cal + resource file in the following way: - 1) calc # run calc - 2) read seedrandom # load seedrandom - 3) config("resource_debug",0) # we want the modulus & quad res only - 4) seedrandom( ~pound out 20-93 random digits on the keyboard~, - ~pound out 20-93 random digits on the keyboard~, - 512 ) - 5) save the seed and newn values for later use + 1) calc # run calc + 2) read seedrandom # load seedrandom + 3) config("resource_debug",0) # we want the modulus & quad res only + 4) seedrandom( ~pound out 20-93 random digits on the keyboard~, + ~pound out 20-93 random digits on the keyboard~, + 512 ) + 5) save the seed and newn values for later use - NOTE: [1,2^32) seed values, seed<0 values, [21,2^32) newn values - and newn<=0 values are reserved for future use. + NOTE: [1,2^32) seed values, seed<0 values, [21,2^32) newn values + and newn<=0 values are reserved for future use. - 2 args (seed, 1>=newn>=20): srandom(seed, newn) + 2 args (seed, 1>=newn>=20): srandom(seed, newn) - The newn is used to select one of 20 pre-computed Blum moduli. + The newn is used to select one of 20 pre-computed Blum moduli. - The seed arg is used to establish the initial quadratic value - once newn has been made the Blum moduli. The seed must be - either 0 or >= 2^32. If seed == 0, the pre-compiled quadratic - residue for the given newn is selected. If seed >= 2^32, then - srandom(seed, newn) has the same effect as: + The seed arg is used to establish the initial quadratic value + once newn has been made the Blum moduli. The seed must be + either 0 or >= 2^32. If seed == 0, the pre-compiled quadratic + residue for the given newn is selected. If seed >= 2^32, then + srandom(seed, newn) has the same effect as: - srandom(0, newn); /* set Blum modulus & def quad res */ - srandom(seed); /* set quadratic residue */ + srandom(0, newn); /* set Blum modulus & def quad res */ + srandom(seed); /* set quadratic residue */ - Note that unlike the newn>=2^32 case, a seed if 0 uses the - pre-compiled quadratic residue for the selected pre-compiled - Blum moduli. + Note that unlike the newn>=2^32 case, a seed if 0 uses the + pre-compiled quadratic residue for the selected pre-compiled + Blum moduli. - The pre-defined Blum moduli and quadratic residues were selected - by LavaRnd, a hardware random number generator. See the URL: + The pre-defined Blum moduli and quadratic residues were selected + by LavaRnd, a hardware random number generator. See the URL: - http://www.LavaRnd.org/ + http://www.LavaRnd.org/ - for an explanation of how the LavaRnd random number generator works. - For more information, see the comments at the top of the calc - source file, zrandom.c. + for an explanation of how the LavaRnd random number generator works. + For more information, see the comments at the top of the calc + source file, zrandom.c. - The purpose of these pre-defined Blum moduli is to provide users with - an easy way to use a generator where the individual Blum primes used - are not well known. True, these values are in some way "MAGIC", on - the other hand that is their purpose! If this bothers you, don't - use them. + The purpose of these pre-defined Blum moduli is to provide users with + an easy way to use a generator where the individual Blum primes used + are not well known. True, these values are in some way "MAGIC", on + the other hand that is their purpose! If this bothers you, don't + use them. - The value 'newn' determines which pre-defined generator is used. + The value 'newn' determines which pre-defined generator is used. - newn == 1: (Blum modulus bit length 130) - newn == 2: (Blum modulus bit length 137) - newn == 3: (Blum modulus bit length 147) - newn == 4: (Blum modulus bit length 157) - newn == 5: (Blum modulus bit length 257) - newn == 6: (Blum modulus bit length 259) - newn == 7: (Blum modulus bit length 286) - newn == 8: (Blum modulus bit length 294) - newn == 9: (Blum modulus bit length 533) - newn == 10: (Blum modulus bit length 537) - newn == 11: (Blum modulus bit length 542) - newn == 12: (Blum modulus bit length 549) - newn == 13: (Blum modulus bit length 1048) - newn == 14: (Blum modulus bit length 1054) - newn == 15: (Blum modulus bit length 1055) - newn == 16: (Blum modulus bit length 1062) - newn == 17: (Blum modulus bit length 2062) - newn == 18: (Blum modulus bit length 2074) - newn == 19: (Blum modulus bit length 2133) - newn == 20: (Blum modulus bit length 2166) + newn == 1: (Blum modulus bit length 130) + newn == 2: (Blum modulus bit length 137) + newn == 3: (Blum modulus bit length 147) + newn == 4: (Blum modulus bit length 157) + newn == 5: (Blum modulus bit length 257) + newn == 6: (Blum modulus bit length 259) + newn == 7: (Blum modulus bit length 286) + newn == 8: (Blum modulus bit length 294) + newn == 9: (Blum modulus bit length 533) + newn == 10: (Blum modulus bit length 537) + newn == 11: (Blum modulus bit length 542) + newn == 12: (Blum modulus bit length 549) + newn == 13: (Blum modulus bit length 1048) + newn == 14: (Blum modulus bit length 1054) + newn == 15: (Blum modulus bit length 1055) + newn == 16: (Blum modulus bit length 1062) + newn == 17: (Blum modulus bit length 2062) + newn == 18: (Blum modulus bit length 2074) + newn == 19: (Blum modulus bit length 2133) + newn == 20: (Blum modulus bit length 2166) - See the comments near the top of the source file, zrandom.c, for the - actual pre-compiled values. + See the comments near the top of the source file, zrandom.c, for the + actual pre-compiled values. - The Blum moduli associated with 1 <= newn < 9 are subject - to having their Blum moduli factored, depending in their size, - by small PCs in a reasonable to large supercomputers/highly - parallel processors over a long time. Their value lies in their - speed relative the default Blum generator. As of Feb 1997, - the Blum moduli associated with 13 <= newn < 20 appear to - be well beyond the scope of hardware and algorithms, - and 9 <= newn < 12 might be factor-able with extreme difficulty. + The Blum moduli associated with 1 <= newn < 9 are subject + to having their Blum moduli factored, depending in their size, + by small PCs in a reasonable to large supercomputers/highly + parallel processors over a long time. Their value lies in their + speed relative the default Blum generator. As of Feb 1997, + the Blum moduli associated with 13 <= newn < 20 appear to + be well beyond the scope of hardware and algorithms, + and 9 <= newn < 12 might be factor-able with extreme difficulty. - The following table may be useful as a guide for how easy it - is to factor the modulus: + The following table may be useful as a guide for how easy it + is to factor the modulus: - 1 <= newn <= 4 PC using ECM in a short amount of time - 5 <= newn <= 8 Workstation using MPQS in a short amount of time - 8 <= newn <= 12 High end supercomputer or high parallel processor - using state of the art factoring over a long time - 12 <= newn <= 16 Beyond Feb 1997 systems and factoring methods - 17 <= newn <= 20 Well beyond Feb 1997 systems and factoring methods + 1 <= newn <= 4 PC using ECM in a short amount of time + 5 <= newn <= 8 Workstation using MPQS in a short amount of time + 8 <= newn <= 12 High end supercomputer or high parallel processor + using state of the art factoring over a long time + 12 <= newn <= 16 Beyond Feb 1997 systems and factoring methods + 17 <= newn <= 20 Well beyond Feb 1997 systems and factoring methods - In other words, use of newn == 9, 10, 11 and 12 is likely to - work just fine for all but the truly paranoid. + In other words, use of newn == 9, 10, 11 and 12 is likely to + work just fine for all but the truly paranoid. - NOTE: [1,2^32) seed values, seed<0 values, [21,2^32) newn values - and newn<=0 values are reserved for future use. + NOTE: [1,2^32) seed values, seed<0 values, [21,2^32) newn values + and newn<=0 values are reserved for future use. - 4 args (seed, ip>=2^16, iq>=2^16, trials): srandom(seed, ip, iq, 25) + 4 args (seed, ip>=2^16, iq>=2^16, trials): srandom(seed, ip, iq, 25) - The 'ip' and 'iq' args are used to find simples prime 3 mod 4 + The 'ip' and 'iq' args are used to find simples prime 3 mod 4 - The call srandom(seed, ip, iq, trials) has the same effect as: + The call srandom(seed, ip, iq, trials) has the same effect as: - srandom(seed, - nextcand(ip, trials,0, 3,4)*nextcand(iq, trials,0, 3,4)); + srandom(seed, + nextcand(ip, trials,0, 3,4)*nextcand(iq, trials,0, 3,4)); - Note that while the newn is very likely to be a product of - two primes both 3 mod 4, there is no guarantee that the period - of the generator will be long. The likelihood is that the - period will be long, however. See one of the 2 arg srandom - calls above for more information on this issue. + Note that while the newn is very likely to be a product of + two primes both 3 mod 4, there is no guarantee that the period + of the generator will be long. The likelihood is that the + period will be long, however. See one of the 2 arg srandom + calls above for more information on this issue. - NOTE: [1,2^32) seed values, seed<0 values, [21,2^32) newn values, - newn<=0 values, ip<2^16 and iq<2^16 are reserved for future use. + NOTE: [1,2^32) seed values, seed<0 values, [21,2^32) newn values, + newn<=0 values, ip<2^16 and iq<2^16 are reserved for future use. See the random help file for details on the generator. EXAMPLE ; srandom(0x8d2dcb2bed3212844f4ad31) - RANDOM state + RANDOM state ; state = srandom(); ; print random(123), random(123), random(123), random(123), random(123) 42 58 57 82 15 @@ -351,7 +351,7 @@ SEE ALSO ## ## 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 +## 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 @@ -359,8 +359,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/02/17 01:18:22 -## File existed as early as: 1997 +## Under source code control: 1997/02/17 01:18:22 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/ssq b/help/ssq index f8d57bf..17a3137 100644 --- a/help/ssq +++ b/help/ssq @@ -7,13 +7,13 @@ SYNOPSIS TYPES x1, x2, ... lists or values for which required operations are defined - return as determined by the operations on x1, x2, ... + return as determined by the operations on x1, x2, ... DESCRIPTION Null values are ignored; ssq() returns the null value. If no argument is a list, returns x1^2 + x2^2 + ... If an argument = list(t1, t2, ...) it contributes ssq(t1, t2, ...) - to the result. + to the result. EXAMPLE ; print ssq(1,2,3), ssq(1+2i, 3-4i, 5 +6i) 14 -21+40i @@ -28,12 +28,12 @@ EXAMPLE [1,1] = 352 ; ssq(list(2,3,5),7) - 87 + 87 ; ssq(1,2,3,4,5,6,7,8) - 204 + 204 ; ssq(1,2, list(3,4,list(5,6)), list(), 7, 8) - 204 + 204 LIMITS The number of arguments is not to exceed 1024. @@ -52,7 +52,7 @@ SEE ALSO ## ## 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 +## 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 @@ -60,8 +60,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/25 04:03:46 -## File existed as early as: 1995 +## Under source code control: 1995/10/25 04:03:46 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/statement b/help/statement index 30a6d60..e142075 100644 --- a/help/statement +++ b/help/statement @@ -1,6 +1,6 @@ Statements - Statements are very much like C statements. Most statements act + Statements are very much like C statements. Most statements act identically to those in C, but there are minor differences and some additions. The following is a list of the statement types, with explanation of the non-C statements. @@ -21,54 +21,54 @@ Statements while (expr) statement do statement while (expr) - These all work like in normal C. + These all work like in normal C. - IMPORTANT NOTE: When statement is of the form { ... }, - the leading { must be on the same line as the if, for, - while or do keyword. + IMPORTANT NOTE: When statement is of the form { ... }, + the leading { must be on the same line as the if, for, + while or do keyword. - This works as expected: + This works as expected: - if (expr) { - ... - } + if (expr) { + ... + } - However this WILL NOT WORK AS EXPECTED: + However this WILL NOT WORK AS EXPECTED: - if (expr) - { - ... - } + if (expr) + { + ... + } - because calc will parse the if being terminated by - an empty statement followed by a + because calc will parse the if being terminated by + an empty statement followed by a - if (expr) ; - { - ... - } + if (expr) ; + { + ... + } - In the same way, use these forms: + In the same way, use these forms: - for (optionalexpr ; optionalexpr ; optionalexpr) { - ... - } + for (optionalexpr ; optionalexpr ; optionalexpr) { + ... + } - while (expr) { - ... - } + while (expr) { + ... + } - do { - ... - while (expr); + do { + ... + while (expr); - where the initial { is on the SAME LINE as the if, while, - for or do. + where the initial { is on the SAME LINE as the if, while, + for or do. - See 'help expression' for details on expressions. - See 'help builtin' for details on calc builtin functions. - See 'help unexpanded' for things C programmers do not expect. - See also 'help todo' and 'help bugs'. + See 'help expression' for details on expressions. + See 'help builtin' for details on calc builtin functions. + See 'help unexpanded' for things C programmers do not expect. + See also 'help todo' and 'help bugs'. C-like flow breaks @@ -76,10 +76,10 @@ Statements continue break goto label - These all work like in normal C. + These all work like in normal C. - See 'help expression' for details on expressions. - See 'help builtin' for details on calc builtin functions. + See 'help expression' for details on expressions. + See 'help builtin' for details on calc builtin functions. return @@ -87,25 +87,25 @@ Statements return return expr return ( expr ) - This returns a value from a function. Functions always - have a return value, even if this statement is not used. - If no return statement is executed, or if no expression - is specified in the return statement, then the return - value from the function is the null type. + This returns a value from a function. Functions always + have a return value, even if this statement is not used. + If no return statement is executed, or if no expression + is specified in the return statement, then the return + value from the function is the null type. switch ------ switch (expr) { caseclauses } - Switch statements work similarly to C, except for the - following. A switch can be done on any type of value, - and the case statements can be of any type of values. - The case statements can also be expressions calculated - at runtime. The calculator compares the switch value - with each case statement in the order specified, and - selects the first case which matches. The default case - is the exception, and only matches once all other cases - have been tested. + Switch statements work similarly to C, except for the + following. A switch can be done on any type of value, + and the case statements can be of any type of values. + The case statements can also be expressions calculated + at runtime. The calculator compares the switch value + with each case statement in the order specified, and + selects the first case which matches. The default case + is the exception, and only matches once all other cases + have been tested. matrix @@ -113,138 +113,138 @@ Statements mat variable [dimension] [dimension] ... mat variable [dimension, dimension, ...] mat variable [] = { value, ... } - This creates a matrix variable with the specified dimensions. - Matrices can have from 1 to 4 dimensions. When specifying - multiple dimensions, you can use either the standard C syntax, - or else you can use commas for separating the dimensions. - For example, the following two statements are equivalent, - and so will create the same two dimensional matrix: + This creates a matrix variable with the specified dimensions. + Matrices can have from 1 to 4 dimensions. When specifying + multiple dimensions, you can use either the standard C syntax, + or else you can use commas for separating the dimensions. + For example, the following two statements are equivalent, + and so will create the same two dimensional matrix: - mat foo[3][6]; - mat foo[3,6]; + mat foo[3][6]; + mat foo[3,6]; - By default, each dimension is indexed starting at zero, - as in normal C, and contains the specified number of - elements. However, this can be changed if a colon is - used to separate two values. If this is done, then the - two values become the lower and upper bounds for indexing. - This is convenient, for example, to create matrices whose - first row and column begin at 1. Examples of matrix - definitions are: + By default, each dimension is indexed starting at zero, + as in normal C, and contains the specified number of + elements. However, this can be changed if a colon is + used to separate two values. If this is done, then the + two values become the lower and upper bounds for indexing. + This is convenient, for example, to create matrices whose + first row and column begin at 1. Examples of matrix + definitions are: - mat x[3] one dimension, bounds are 0-2 - mat foo[4][5] two dimensions, bounds are 0-3 and 0-4 - mat a[-7:7] one dimension, bounds are (-7)-7 - mat s[1:9,1:9] two dimensions, bounds are 1-9 and 1-9 + mat x[3] one dimension, bounds are 0-2 + mat foo[4][5] two dimensions, bounds are 0-3 and 0-4 + mat a[-7:7] one dimension, bounds are (-7)-7 + mat s[1:9,1:9] two dimensions, bounds are 1-9 and 1-9 - Note that the MAT statement is not a declaration, but is - executed at runtime. Within a function, the specified - variable must already be defined, and is just converted to - a matrix of the specified size, and all elements are set - to the value of zero. For convenience, at the top level - command level, the MAT command automatically defines a - global variable of the specified name if necessary. + Note that the MAT statement is not a declaration, but is + executed at runtime. Within a function, the specified + variable must already be defined, and is just converted to + a matrix of the specified size, and all elements are set + to the value of zero. For convenience, at the top level + command level, the MAT command automatically defines a + global variable of the specified name if necessary. - Since the MAT statement is executed, the bounds on the - matrix can be full expressions, and so matrices can be - dynamically allocated. For example: + Since the MAT statement is executed, the bounds on the + matrix can be full expressions, and so matrices can be + dynamically allocated. For example: - size = 20; - mat data[size*2]; + size = 20; + mat data[size*2]; - allocates a matrix which can be indexed from 0 to 39. + allocates a matrix which can be indexed from 0 to 39. - Initial values for the elements of a matrix can be specified - by following the bounds information with an equals sign and - then a list of values enclosed in a pair of braces. Even if - the matrix has more than one dimension, the elements must be - specified as a linear list. If too few values are specified, - the remaining values are set to zero. If too many values are - specified, a runtime error will result. Examples of some - initializations are: + Initial values for the elements of a matrix can be specified + by following the bounds information with an equals sign and + then a list of values enclosed in a pair of braces. Even if + the matrix has more than one dimension, the elements must be + specified as a linear list. If too few values are specified, + the remaining values are set to zero. If too many values are + specified, a runtime error will result. Examples of some + initializations are: - mat table1[5] = {77, 44, 22}; - mat table2[2,2] = {1, 2, 3, 4}; + mat table1[5] = {77, 44, 22}; + mat table2[2,2] = {1, 2, 3, 4}; - When an initialization is done, the bounds of the matrix - can optionally be left out of the square brackets, and the - correct bounds (zero based) will be set. This can only be - done for one-dimensional matrices. An example of this is: + When an initialization is done, the bounds of the matrix + can optionally be left out of the square brackets, and the + correct bounds (zero based) will be set. This can only be + done for one-dimensional matrices. An example of this is: - mat fred[] = {99, 98, 97}; + mat fred[] = {99, 98, 97}; - The MAT statement can also be used in declarations to set - variables as being matrices from the beginning. For example: + The MAT statement can also be used in declarations to set + variables as being matrices from the beginning. For example: - local mat temp[5]; - static mat strtable[] = {"hi", "there", "folks"); + local mat temp[5]; + static mat strtable[] = {"hi", "there", "folks"); object ------ obj type { elementnames } optionalvariables obj type variable - These create a new object type, or create one or more - variables of the specified type. For this calculator, - an object is just a structure which is implicitly acted - on by user defined routines. The user defined routines - implement common operations for the object, such as plus - and minus, multiply and divide, comparison and printing. - The calculator will automatically call these routines in - order to perform many operations. + These create a new object type, or create one or more + variables of the specified type. For this calculator, + an object is just a structure which is implicitly acted + on by user defined routines. The user defined routines + implement common operations for the object, such as plus + and minus, multiply and divide, comparison and printing. + The calculator will automatically call these routines in + order to perform many operations. - To create an object type, the data elements used in - implementing the object are specified within a pair - of braces, separated with commas. For example, to - define an object will will represent points in 3-space, - whose elements are the three coordinate values, the - following could be used: + To create an object type, the data elements used in + implementing the object are specified within a pair + of braces, separated with commas. For example, to + define an object will will represent points in 3-space, + whose elements are the three coordinate values, the + following could be used: - obj point {x, y, z}; + obj point {x, y, z}; - This defines an object type called point, whose elements - have the names x, y, and z. The elements are accessed - similarly to structure element accesses, by using a period. - For example, given a variable 'v' which is a point object, - the three coordinates of the point can be referenced by: + This defines an object type called point, whose elements + have the names x, y, and z. The elements are accessed + similarly to structure element accesses, by using a period. + For example, given a variable 'v' which is a point object, + the three coordinates of the point can be referenced by: - v.x - v.y - v.z + v.x + v.y + v.z - A particular object type can only be defined once, and - is global throughout all functions. However, different - object types can be used at the same time. + A particular object type can only be defined once, and + is global throughout all functions. However, different + object types can be used at the same time. - In order to create variables of an object type, they - can either be named after the right brace of the object - creation statement, or else can be defined later with - another obj statement. To create two points using the - second (and most common) method, the following is used: + In order to create variables of an object type, they + can either be named after the right brace of the object + creation statement, or else can be defined later with + another obj statement. To create two points using the + second (and most common) method, the following is used: - obj point p1, p2; + obj point p1, p2; - This statement is executed, and is not a declaration. - Thus within a function, the variables p1 and p2 must have - been previously defined, and are just changed to be the - new object type. For convenience, at the top level command - level, object variables are automatically defined as being - global when necessary. + This statement is executed, and is not a declaration. + Thus within a function, the variables p1 and p2 must have + been previously defined, and are just changed to be the + new object type. For convenience, at the top level command + level, object variables are automatically defined as being + global when necessary. - Initial values for an object can be specified by following - the variable name by an equals sign and a list of values - enclosed in a pair of braces. For example: + Initial values for an object can be specified by following + the variable name by an equals sign and a list of values + enclosed in a pair of braces. For example: - obj point pt = {5, 6}; + obj point pt = {5, 6}; - The OBJ statement can also be used in declarations to set - variables as being objects from the beginning. If multiple - variables are specified, then each one is defined as the - specified object type. Examples of declarations are: + The OBJ statement can also be used in declarations to set + variables as being objects from the beginning. If multiple + variables are specified, then each one is defined as the + specified object type. Examples of declarations are: - local obj point temp1; - static obj point temp2 = {4, 3}; - global obj point p1, p2, p3; + local obj point temp1; + static obj point temp2 = {4, 3}; + global obj point p1, p2, p3; print expressions @@ -252,76 +252,76 @@ Statements print expr print expr, ... expr print expr: ... expr - For interactive expression evaluation, the values of all - typed-in expressions are automatically displayed to the - user. However, within a function or loop, the printing of - results must be done explicitly. This can be done using - the 'printf' or 'fprintf' functions, as in standard C, or - else by using the built-in 'print' statement. The advantage - of the print statement is that a format string is not needed. - Instead, the given values are simply printed with zero or one - spaces between each value. + For interactive expression evaluation, the values of all + typed-in expressions are automatically displayed to the + user. However, within a function or loop, the printing of + results must be done explicitly. This can be done using + the 'printf' or 'fprintf' functions, as in standard C, or + else by using the built-in 'print' statement. The advantage + of the print statement is that a format string is not needed. + Instead, the given values are simply printed with zero or one + spaces between each value. - Print accepts a list of expressions, separated either by - commas or colons. Each expression is evaluated in order - and printed, with no other output, except for the following - special cases. The comma which separates expressions prints - a single space, and a newline is printed after the last - expression unless the statement ends with a colon. As - examples: + Print accepts a list of expressions, separated either by + commas or colons. Each expression is evaluated in order + and printed, with no other output, except for the following + special cases. The comma which separates expressions prints + a single space, and a newline is printed after the last + expression unless the statement ends with a colon. As + examples: - print 3, 4; prints "3 4" and newline. - print 5:; prints "5" with no newline. - print 'a' : 'b' , 'c'; prints "ab c" and newline. - print; prints a newline. + print 3, 4; prints "3 4" and newline. + print 5:; prints "5" with no newline. + print 'a' : 'b' , 'c'; prints "ab c" and newline. + print; prints a newline. - For numeric values, the format of the number depends on the - current "mode" configuration parameter. The initial mode - is to print real numbers, but it can be changed to other - modes such as exponential, decimal fractions, or hex. + For numeric values, the format of the number depends on the + current "mode" configuration parameter. The initial mode + is to print real numbers, but it can be changed to other + modes such as exponential, decimal fractions, or hex. - If a matrix or list is printed, then the elements contained - within the matrix or list will also be printed, up to the - maximum number specified by the "maxprint" configuration - parameter. If an element is also a matrix or a list, then - their values are not recursively printed. Objects are printed - using their user-defined routine. Printing a file value - prints the name of the file that was opened. + If a matrix or list is printed, then the elements contained + within the matrix or list will also be printed, up to the + maximum number specified by the "maxprint" configuration + parameter. If an element is also a matrix or a list, then + their values are not recursively printed. Objects are printed + using their user-defined routine. Printing a file value + prints the name of the file that was opened. Also see the help topic: - help command top level commands - help expression calc expression syntax - help builtin calc builtin functions - help usage how to invoke the calc command and calc -options + help command top level commands + help expression calc expression syntax + help builtin calc builtin functions + help usage how to invoke the calc command and calc -options You may obtain help on individual builtin functions. For example: - help asinh - help round + help asinh + help round See: - help builtin + help builtin for a list of builtin functions. Some calc operators have their own help pages: - help -> - help * - help . - help % - help // - help # + help -> + help * + help . + help % + help // + help # See also: - help help + help help The man command is an alias for the help command. For example: - man jacobi + man jacobi Only calc help files may be displayed by the help and man commands. @@ -333,7 +333,7 @@ Statements ## ## 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 +## 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 @@ -341,8 +341,8 @@ Statements ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:23 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:23 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/stoponerror b/help/stoponerror index 97a22ba..66a4af9 100644 --- a/help/stoponerror +++ b/help/stoponerror @@ -5,18 +5,18 @@ SYNOPSIS stoponerror([n]) TYPES - n integer + n integer - return null value or error value + return null value or error value DESCRIPTION The stoponerror controls when or if calc stops based on the number of errors: - n == -1 do not stop - n == 0 stop on error unless calc was invoked with -c - n > 0 stop when n errors are encountered + n == -1 do not stop + n == 0 stop on error unless calc was invoked with -c + n > 0 stop when n errors are encountered When no arguments are given, stoponerror() returns the current stoponerror value. When 1 argument is given, stoponerror() returns @@ -27,7 +27,7 @@ DESCRIPTION EXAMPLE ; stoponerror() - 0 + 0 LIMITS -1 <= stoponerror < 2147483647 @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## -## Under source code control: 2006/05/21 00:50:59 -## File existed as early as: 2006 +## Under source code control: 2006/05/21 00:50:59 +## File existed as early as: 2006 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/str b/help/str index 34fb247..cbb97b2 100644 --- a/help/str +++ b/help/str @@ -5,9 +5,9 @@ SYNOPSIS str(x) TYPES - x null, string, real or complex number + x null, string, real or complex number - return string + return string DESCRIPTION Convert a value into a string. @@ -22,9 +22,9 @@ DESCRIPTION EXAMPLE ; str("") - "" + "" ; str(null()) - "" + "" ; print str(123), str("+"), str(4i), str("is the same as"), str(123+4i) 123 + 4i is the same as 3+4i @@ -55,7 +55,7 @@ SEE ALSO ## ## 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 +## 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 @@ -63,8 +63,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:27 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:27 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/strcasecmp b/help/strcasecmp index c327d4d..ed68dbe 100644 --- a/help/strcasecmp +++ b/help/strcasecmp @@ -49,7 +49,7 @@ SEE ALSO ## ## 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 +## 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 @@ -57,8 +57,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2013/09/01 18:10:53 -## File existed as early as: 2013 +## Under source code control: 2013/09/01 18:10:53 +## File existed as early as: 2013 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/strcat b/help/strcat index aa2e873..ae3b147 100644 --- a/help/strcat +++ b/help/strcat @@ -5,9 +5,9 @@ SYNOPSIS strcat(x1, x2, ...) TYPES - x1, x2, ... strings + x1, x2, ... strings - return string + return string DESCRIPTION strcat(x1, x2, ...) forms a string starting with a copy of @@ -44,7 +44,7 @@ SEE ALSO ## ## 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 +## 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 @@ -52,8 +52,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:27 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:27 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/strcmp b/help/strcmp index 3e144d7..2e6b71c 100644 --- a/help/strcmp +++ b/help/strcmp @@ -5,10 +5,10 @@ SYNOPSIS strcmp(s1, s2) TYPES - s1 string - s2 string + s1 string + s2 string - return integer (1, 0 or -1) + return integer (1, 0 or -1) DESCRIPTION Let n1 = size(s1), n2 = size(s2) and m = min(n1, n2). @@ -49,7 +49,7 @@ SEE ALSO ## ## 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 +## 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 @@ -57,8 +57,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## -## Under source code control: 2006/03/03 03:32:44 -## File existed as early as: 2006 +## Under source code control: 2006/03/03 03:32:44 +## File existed as early as: 2006 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/strcpy b/help/strcpy index 018e3bd..3ac1361 100644 --- a/help/strcpy +++ b/help/strcpy @@ -5,10 +5,10 @@ SYNOPSIS strcpy(s1, s2) TYPES - s1 string - s2 string + s1 string + s2 string - return string + return string DESCRIPTION Let n1 = size(s1), n2 = size(n2), and m = min(n1, n2). @@ -49,7 +49,7 @@ SEE ALSO ## ## 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 +## 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 @@ -57,8 +57,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## -## Under source code control: 2006/03/03 03:32:44 -## File existed as early as: 2006 +## Under source code control: 2006/03/03 03:32:44 +## File existed as early as: 2006 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/strerror b/help/strerror index ca44d36..3b27b16 100644 --- a/help/strerror +++ b/help/strerror @@ -5,42 +5,42 @@ SYNOPSIS strerror([errnum | "E_STRING"]) TYPES - errnum integer - E_STRING string + errnum integer + E_STRING string - return string + return string DESCRIPTION With errno(errnum) numeric argument: - strerror(errnum) will return one of: + strerror(errnum) will return one of: - * system error and libc errno value related string - * calc computation error code string - * user-defined description string created by newerror(str) - * "Unknown error errnum" (where errnum is in decimal) + * system error and libc errno value related string + * calc computation error code string + * user-defined description string created by newerror(str) + * "Unknown error errnum" (where errnum is in decimal) With strerror("E_STRING") string argument: - If E_STRING is a valid errsym code, then the E_STRING errsym - is converted into strerror(errnum). + If E_STRING is a valid errsym code, then the E_STRING errsym + is converted into strerror(errnum). - If E_STRING is not a valid errsym code, an error error condition - is raised about the invalid E_STRING. + If E_STRING is not a valid errsym code, an error error condition + is raised about the invalid E_STRING. - For example, these two calls are equivalent: + For example, these two calls are equivalent: - cstrerror(10003); /* error 10003 has a E_STRING of "E_ADD" */ - cstrerror("E_ADD"); /* error 10003 has a E_STRING of "E_ADD" */ + cstrerror(10003); /* error 10003 has a E_STRING of "E_ADD" */ + cstrerror("E_ADD"); /* error 10003 has a E_STRING of "E_ADD" */ - See help errsym for information on E_STRING errsym codes. + See help errsym for information on E_STRING errsym codes. - For a list of the E_STRING associated with calc computation error - codes, see help errorcodes. + For a list of the E_STRING associated with calc computation error + codes, see help errorcodes. Without a argument, strerror() returns as if it were called with: - strerror(errno()) + strerror(errno()) That is, the string associated with the "global calc_errno value" is returned. @@ -53,18 +53,18 @@ DESCRIPTION For users of libcalc: - The libcalc array error_table[] contains the hard coded - calc-generated error array of ECOUNT+2 pointers to strings - starting with E__BASE, ending with E__HIGHEST and terminated - by a NULL pointer. + The libcalc array error_table[] contains the hard coded + calc-generated error array of ECOUNT+2 pointers to strings + starting with E__BASE, ending with E__HIGHEST and terminated + by a NULL pointer. - The error_table[0] is for errnum of E__BASE, and is the - string "No error". + The error_table[0] is for errnum of E__BASE, and is the + string "No error". - The error_table[ECOUNT] is string associated with the - highest calc-generated error message. + The error_table[ECOUNT] is string associated with the + highest calc-generated error message. - The error_table[ECOUNT+1] is a NULL pointer. + The error_table[ECOUNT+1] is a NULL pointer. See help error for more information on the ranges of errnum and the meaning of the above mentioned constants. @@ -102,9 +102,9 @@ LIMITS E_STRING is string that must match the regular expression: ^E_[A-Z0-9_]+$ LINK LIBRARY - int calc_errno; /* global calc_errno value */ + int calc_errno; /* global calc_errno value */ - CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */ + CONST struct errtbl error_table[ECOUNT+2]; /* calc error codes, error symbols and error messages */ bool is_e_digits(CONST char *errsym); bool is_valid_errnum(int errnum); @@ -133,7 +133,7 @@ SEE ALSO ## ## 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 +## 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 @@ -141,8 +141,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:05:18 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:05:18 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/strlen b/help/strlen index df14143..664da81 100644 --- a/help/strlen +++ b/help/strlen @@ -5,9 +5,9 @@ SYNOPSIS strlen(x) TYPES - x string + x string - return integer + return integer DESCRIPTION strlen(x) returns the number of characters in x @@ -34,7 +34,7 @@ SEE ALSO ## ## 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 +## 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 @@ -42,8 +42,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:27 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:27 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/strncasecmp b/help/strncasecmp index 8de8b72..7169133 100644 --- a/help/strncasecmp +++ b/help/strncasecmp @@ -51,7 +51,7 @@ SEE ALSO ## ## 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 +## 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 @@ -59,8 +59,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2013/09/01 20:04:02 -## File existed as early as: 2013 +## Under source code control: 2013/09/01 20:04:02 +## File existed as early as: 2013 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/strncmp b/help/strncmp index 19c0756..677f3f0 100644 --- a/help/strncmp +++ b/help/strncmp @@ -5,11 +5,11 @@ SYNOPSIS strncmp(s1, s2, n) TYPES - s1 string - s2 string - n nonnegative integer + s1 string + s2 string + n nonnegative integer - return integer (1, 0 or -1) + return integer (1, 0 or -1) DESCRIPTION Let n1 = size(s1), n2 = size(s2) and m = min(n1, n2, n). @@ -50,7 +50,7 @@ SEE ALSO ## ## 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 +## 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 @@ -58,8 +58,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## -## Under source code control: 2006/03/03 03:32:44 -## File existed as early as: 2006 +## Under source code control: 2006/03/03 03:32:44 +## File existed as early as: 2006 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/strncpy b/help/strncpy index d528b7b..28df30a 100644 --- a/help/strncpy +++ b/help/strncpy @@ -1,16 +1,16 @@ NAME strncpy - copy a number of characters from head or all of a string - to head or all of a string + to head or all of a string SYNOPSIS strncpy(s1, s2, n) TYPES - s1 string - s2 string - n nonnegative integer + s1 string + s2 string + n nonnegative integer - return string + return string DESCRIPTION Let n1 = size(s1), n2 = size(n2), and m = min(n1, n2, n). @@ -47,7 +47,7 @@ SEE ALSO ## ## 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 +## 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 @@ -55,8 +55,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## -## Under source code control: 2006/03/03 03:32:44 -## File existed as early as: 2006 +## Under source code control: 2006/03/03 03:32:44 +## File existed as early as: 2006 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/strpos b/help/strpos index b488507..d64d66a 100644 --- a/help/strpos +++ b/help/strpos @@ -5,10 +5,10 @@ SYNOPSIS strpos(s, t) TYPES - s str - t str + s str + t str - return int + return int DESCRIPTION This function returns the location of the first occurrence of the string t @@ -17,17 +17,17 @@ DESCRIPTION EXAMPLE ; strpos("abcdefg", "c") - 3 + 3 ; strpos("abcdefg", "def") - 4 + 4 ; strpos("abcdefg", "defg") - 4 + 4 ; strpos("abcdefg", "defgh") - 0 + 0 ; strpos("abcdefg", "abc") - 1 + 1 ; strpos("abcdefg", "xyz") - 0 + 0 LIMITS none @@ -47,7 +47,7 @@ SEE ALSO ## ## 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 +## 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 @@ -55,8 +55,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/09 03:48:57 -## File existed as early as: 1995 +## Under source code control: 1995/07/09 03:48:57 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/strprintf b/help/strprintf index 9f0edb9..7de6ab8 100644 --- a/help/strprintf +++ b/help/strprintf @@ -5,10 +5,10 @@ SYNOPSIS strprintf(fmt, x_1, x_2, ...) TYPES - fmt string - x_1, x_2, ... any + fmt string + x_1, x_2, ... any - return string + return string DESCRIPTION This function returns the string formed from the characters that @@ -16,7 +16,7 @@ DESCRIPTION EXAMPLE ; strprintf("h=%d, i=%d", 2, 3); - "h=2, i=3" + "h=2, i=3" ; config("epsilon", 1e-6),; ; config("display", 6),; @@ -26,13 +26,13 @@ EXAMPLE ; fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n"; ; a = sqrt(3); ; strprintf(fmt,a,a,a,a,a,a); - "1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1. + "1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1. " ; config("display", 50),; ; fmt2 = "%g %g\n%g %g\n" ; strprintf(fmt2, 1e5, 1e49, 1e50, 1e500); - "100000 100000000000000000000000000000000000000000000000000 + "100000 100000000000000000000000000000000000000000000000000 1e50 1e500 " @@ -103,7 +103,7 @@ SEE ALSO ## ## 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 +## 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 @@ -111,8 +111,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/03/12 22:50:41 -## File existed as early as: 1996 +## Under source code control: 1996/03/12 22:50:41 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/strscan b/help/strscan index 4d7227c..b1f32b0 100644 --- a/help/strscan +++ b/help/strscan @@ -5,10 +5,10 @@ SYNOPSIS strscan(str, x_1, x_2, ..., x_n) TYPES - str string - x_1, x_2, ... any + str string + x_1, x_2, ... any - return integer + return integer DESCRIPTION Successive fields of str separated by white space are read and @@ -22,7 +22,7 @@ EXAMPLE ; global a,b ; strscan(" 2+3 a^2 print(b)", a, b, 0); 25 - 3 + 3 ; print a,b 5 25 @@ -44,7 +44,7 @@ SEE ALSO ## ## 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 +## 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 @@ -52,8 +52,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:05:18 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:05:18 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/strscanf b/help/strscanf index ae54ecb..0e6a0dc 100644 --- a/help/strscanf +++ b/help/strscanf @@ -5,11 +5,11 @@ SYNOPSIS strscanf(str, fmt, x_1, x_2, ...) TYPES - str string - fmt string - x_1, x_2, ... lvalues + str string + fmt string + x_1, x_2, ... lvalues - return null, nonnegative integer, or error value + return null, nonnegative integer, or error value DESCRIPTION If the str is "", the null value is returned. @@ -17,7 +17,7 @@ DESCRIPTION Otherwise, until the terminating null character of either fmt or str is reached, characters other than '%' and whitespace are read from fmt and compared with the corresponding characters read from str. - If the characters match, reading continues. If they do not match + If the characters match, reading continues. If they do not match an integer value is returned. If whitespace is encountered in fmt, starting at the current positions in fmt and str, any whitespace characters are skipped and reading and comparison begins as before @@ -29,16 +29,16 @@ DESCRIPTION '%'. A single '%' read from fmt is taken to indicate the beginning of a conversion specification field consisting in succession of: - an optional '*', - optional decimal digits, - one of 'c', 's', 'n', 'f', 'e', 'i' or a scanset specifier. + an optional '*', + optional decimal digits, + one of 'c', 's', 'n', 'f', 'e', 'i' or a scanset specifier. A scanset specifier starts with '[' and an optional '^', then an optional ']', then optional other characters, and ends with ']'. If any other sequence of characters follows the '%', characters before the first exceptional character (which could be the terminating null character of the fmt string) are ignored, e.g. the sequence " %*3d " does - the same as " d ". If there is no '*' at the beginning of the specifier, + the same as " d ". If there is no '*' at the beginning of the specifier, and the list x_1, x_2, ... has not been exhausted, a value will be assigned to the next lvalue in the list; if no lvalue remains, the reading of fs stops and the function returns the number @@ -65,7 +65,7 @@ DESCRIPTION The cases 'f', 'e', 'r', 'i' may be considered to indicate expectation of floating-point, exponential, ratio, or integer representation of the - number to be read. For example, 'i' + number to be read. For example, 'i' might be taken to suggest a number like +2345; 'r' might suggest a representation like -27/49; 'e' might suggest a representation like 1.24e-7; 'f' might suggest a representation like 27.145. However, there @@ -77,9 +77,9 @@ DESCRIPTION for + and -, and for * and /. Also acceptable is a trailing i to indicate an imaginary number. For example the expression - 2+3/4*7i+3.15e7 + 2+3/4*7i+3.15e7 - would be interpreted as for an ordinary evaluation. A decimal fraction + would be interpreted as for an ordinary evaluation. A decimal fraction may have more than one dot: dots after the first, which is taken to be the decimal point, are ignored. Thus "12.3..45e6.7" is interpreted as if it were "12.345e67". @@ -95,12 +95,12 @@ EXAMPLE ; global a, b, c, d ; A = "abc xyz 234.6 alpha" ; strscanf(A, "%s%*[^0123456789]%f%n", a, b, c) - 3 + 3 ; print a, b, c ; abc 234.6 13 ; strscanf(A, "%*13c%s", d); - 1 + 1 ; print d ; alpha @@ -122,7 +122,7 @@ SEE ALSO ## ## 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 +## 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 @@ -130,8 +130,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/04/30 03:05:18 -## File existed as early as: 1996 +## Under source code control: 1996/04/30 03:05:18 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/strtolower b/help/strtolower index caed821..2f604b9 100644 --- a/help/strtolower +++ b/help/strtolower @@ -18,7 +18,7 @@ DESCRIPTION EXAMPLE ; strtolower(" GNU Lesser General Public License"); - " gnu lesser general public license" + " gnu lesser general public license" LIMITS none. diff --git a/help/strtoupper b/help/strtoupper index 852bede..812cc3f 100644 --- a/help/strtoupper +++ b/help/strtoupper @@ -18,7 +18,7 @@ DESCRIPTION EXAMPLE ; strtoupper(" GNU Lesser General Public License"); - " GNU LESSER GENERAL PUBLIC LICENSE" + " GNU LESSER GENERAL PUBLIC LICENSE" LIMITS none. diff --git a/help/substr b/help/substr index 47e0f83..026421b 100644 --- a/help/substr +++ b/help/substr @@ -5,11 +5,11 @@ SYNOPSIS substr(str, pos, len) TYPES - str string - pos nonnegative integer - len nonnegative integer + str string + pos nonnegative integer + len nonnegative integer - return string + return string DESCRIPTION If pos > length of str or len is zero, the null string "" is returned. @@ -18,7 +18,7 @@ DESCRIPTION string of length min(strlen(str) - pos + 1, len) formed by consecutive characters of str starting at position pos, i.e. the string has length len if this is possible, otherwise it ends with - the last character of str. (The first character has pos = 1, the + the last character of str. (The first character has pos = 1, the second pos = 2, etc.) If pos = 0, the result is the same as for pos = 1. @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:27 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:27 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/sum b/help/sum index 174033c..8d6aeb2 100644 --- a/help/sum +++ b/help/sum @@ -5,9 +5,9 @@ SYNOPSIS sum(x_1, x_2, ...) TYPES - x_1, x_2, ... any + x_1, x_2, ... any - return any + return any DESCRIPTION If an argument x_i is a list with elements e_1, e_2, ..., e_n, it @@ -18,7 +18,7 @@ DESCRIPTION xx_sum(x_i) if the function xx_sum() has been defined. If the type xx has been defined by: - obj xx = {x, y, z}, + obj xx = {x, y, z}, an appropriate definition of xx_sum(a) is sometimes a.x + a.y + a.z. sum(a) then returns the sum of the elements of a. @@ -66,7 +66,7 @@ SEE ALSO ## ## 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 +## 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 @@ -74,8 +74,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/03/10 03:59:59 -## File existed as early as: 1997 +## Under source code control: 1997/03/10 03:59:59 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/swap b/help/swap index 730e7e9..10272cf 100644 --- a/help/swap +++ b/help/swap @@ -5,9 +5,9 @@ SYNOPSIS swap(x,y) TYPES - x, y lvalues, any type + x, y lvalues, any type - return null value + return null value DESCRIPTION swap(x,y) assigns the value of x to a temporary location, temp say, @@ -16,7 +16,7 @@ DESCRIPTION swap(x,y) should not be used if the current value of one of the variables is a component of the value of the other; for example, after: - A = list(1,2,3); swap(A, A[[1]]); + A = list(1,2,3); swap(A, A[[1]]); A will have the value 2, but a three-member list remains in memory with no method within calc of recalling the list or freeing the @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/12/18 12:34:58 -## File existed as early as: 1995 +## Under source code control: 1995/12/18 12:34:58 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/system b/help/system index f81e1ea..3117721 100644 --- a/help/system +++ b/help/system @@ -5,9 +5,9 @@ SYNOPSIS system(cmd) TYPES - cmd str + cmd str - return int + return int DESCRIPTION This function executes the shell command found in the string, cmd. @@ -20,19 +20,19 @@ DESCRIPTION and other waitpid values will change the return value. On POSIX P1003.1 compliant systems, if cmd is empty then this function - will determine if the shell is executable. If the shell is executable, + will determine if the shell is executable. If the shell is executable, 0 is returned otherwise non-zero is returned. EXAMPLE ; system("") - 0 + 0 ; system("true") - 0 + 0 ; system("exit 2") - 512 + 512 ; system("date") Sun Jul 9 03:21:48 PDT 1995 - 0 + 0 LIMITS none @@ -51,7 +51,7 @@ SEE ALSO ## ## 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 +## 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 @@ -59,8 +59,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/09 03:48:57 -## File existed as early as: 1995 +## Under source code control: 1995/07/09 03:48:57 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/systime b/help/systime index 6fcb7b0..3f913fc 100644 --- a/help/systime +++ b/help/systime @@ -5,7 +5,7 @@ SYNOPSIS systime() TYPES - return nonnegative real + return nonnegative real DESCRIPTION In POSIX based systems, this function will return the CPU seconds @@ -27,7 +27,7 @@ EXAMPLE ; t = systime(); ; system("true"), ; systime() - t; - 0.001 + 0.001 LIMITS On non-POSIX based systems, this function always returns 0. @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2006/12/16 10:31:08 -## File existed as early as: 2006 +## Under source code control: 2006/12/16 10:31:08 +## File existed as early as: 2006 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/tail b/help/tail index fbaead5..412849b 100644 --- a/help/tail +++ b/help/tail @@ -5,10 +5,10 @@ SYNOPSIS tail(x, y) TYPES - x list - y int + x list + y int - return list + return list DESCRIPTION If 0 <= y <= size(x) == n, tail(x,y) returns a list of size y whose @@ -30,15 +30,15 @@ EXAMPLE ; tail(A, 2) list (2 members, 2 nonzero): - [[0]] = 7 - [[1]] = 11 + [[0]] = 7 + [[1]] = 11 ; tail(A, -2) list (3 members, 3 nonzero): - [[0]] = 5 - [[1]] = 7 - [[2]] = 11 + [[0]] = 5 + [[1]] = 7 + [[2]] = 11 LIMITS none @@ -57,7 +57,7 @@ SEE ALSO ## ## 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 +## 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 @@ -65,8 +65,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/07/10 02:09:30 -## File existed as early as: 1995 +## Under source code control: 1995/07/10 02:09:30 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/tan b/help/tan index a4051ab..beda7f9 100644 --- a/help/tan +++ b/help/tan @@ -5,10 +5,10 @@ SYNOPSIS tan(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Calculate the trigonometric tangent of x to a multiple of eps, with error less @@ -16,7 +16,7 @@ DESCRIPTION This function is equivalent to: - tan(x) = sin(x) / cos(x) + tan(x) = sin(x) / cos(x) EXAMPLE ; print tan(1/2), tan(5/7), tan(42/7) @@ -56,14 +56,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 1999,2023 Landon Curt Noll ## @@ -73,7 +73,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -81,8 +81,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 01:40:29 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 01:40:29 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/tanh b/help/tanh index 7745cbe..0fa09ab 100644 --- a/help/tanh +++ b/help/tanh @@ -5,10 +5,10 @@ SYNOPSIS tanh(x [,eps]) TYPES - x real - eps 0 < real < 1, defaults to epsilon() + x real + eps 0 < real < 1, defaults to epsilon() - return real + return real DESCRIPTION Calculate the tanh of x to the nearest or next to nearest multiple of @@ -40,7 +40,7 @@ SEE ALSO ## ## 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 +## 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 @@ -48,8 +48,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/03/19 01:40:30 -## File existed as early as: 1994 +## Under source code control: 1994/03/19 01:40:30 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/test b/help/test index 7b1dfe1..46ee4ed 100644 --- a/help/test +++ b/help/test @@ -5,34 +5,34 @@ SYNOPSIS test(x) TYPES - x any + x any - return 0 or 1 + return 0 or 1 DESCRIPTION This function returns 1 or 0 according as x tests as "true" or "false". Conditions under which a value x is considered to be false are: - Numbers (real or complex): x is zero + Numbers (real or complex): x is zero - String: x == "" + String: x == "" - Matrix: every component of x tests as false + Matrix: every component of x tests as false - List: every element of x tests as false + List: every element of x tests as false - Association: x has no element + Association: x has no element - File: x is not open + File: x is not open - Null: always + Null: always - Object of type xx: if xx_test has been defined, xx_test(x) - returns zero; if xx_test has not been defined, - every element of x tests as false. + Object of type xx: if xx_test has been defined, xx_test(x) + returns zero; if xx_test has not been defined, + every element of x tests as false. - Error-value or other types: never + Error-value or other types: never EXAMPLE ; print test(27), test(0), test("abc"), test("") @@ -63,7 +63,7 @@ SEE ALSO ## ## 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 +## 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 @@ -71,8 +71,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/07/11 01:05:13 -## File existed as early as: 1996 +## Under source code control: 1996/07/11 01:05:13 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/time b/help/time index 8ff5e41..13d1f8b 100644 --- a/help/time +++ b/help/time @@ -5,13 +5,13 @@ SYNOPSIS time() TYPES - return int + return int DESCRIPTION The time() builtin returns the number of seconds since the Epoch, which according to POSIX is: - Thr Jan 1 00:00:00 UTC 1970 + Thr Jan 1 00:00:00 UTC 1970 EXAMPLE ; print time(); @@ -34,7 +34,7 @@ SEE ALSO ## ## 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 +## 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 @@ -42,8 +42,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1996/05/01 16:57:20 -## File existed as early as: 1996 +## Under source code control: 1996/05/01 16:57:20 +## File existed as early as: 1996 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/todo b/help/todo index e201bc3..71962bf 100644 --- a/help/todo +++ b/help/todo @@ -7,24 +7,24 @@ High priority items: * Improve the way that calc parses statements such as if, for, while and do so that when a C programmer does. This works as expected: - if (expr) { - ... - } + if (expr) { + ... + } However this WILL NOT WORK AS EXPECTED: - if (expr) - { - ... - } + if (expr) + { + ... + } because calc will parse the if being terminated by an empty statement followed by a - if (expr) ; - { - ... - } + if (expr) ; + { + ... + } See also "help statement", "help unexpected", "help todo", and "help bugs". @@ -71,22 +71,22 @@ Low priority items: * Complete the use of CONST where appropriate: - CONST is beginning to be used with read-only tables and some - function arguments. This allows certain compilers to better - optimize the code as well as alerts one to when some value - is being changed inappropriately. Use of CONST as in: + CONST is beginning to be used with read-only tables and some + function arguments. This allows certain compilers to better + optimize the code as well as alerts one to when some value + is being changed inappropriately. Use of CONST as in: - int foo(CONST int curds, char *CONST whey) + int foo(CONST int curds, char *CONST whey) - while legal C is not as useful because the caller is protected - by the fact that args are passed by value. However, the - in the following: + while legal C is not as useful because the caller is protected + by the fact that args are passed by value. However, the + in the following: - int bar(CONST char *fizbin, CONST HALF *data) + int bar(CONST char *fizbin, CONST HALF *data) - is useful because it calls the compiler that the string pointed - at by 'fizbin' and the HALF array pointer at by 'data' should be - treated as read-only. + is useful because it calls the compiler that the string pointed + at by 'fizbin' and the HALF array pointer at by 'data' should be + treated as read-only. One should make available a the fundamental math operations on ZVALUE, NUMBER and perhaps COMPLEX (without all of the @@ -101,16 +101,16 @@ Low priority items: Calc bug reports and calc bug fixes should be sent to: -NOTE: calc-bug-report Email address no longer in use +NOTE: calc-bug-report Email address no longer in use - NOTE: Remove spaces and replace 'at' with @, 'dot' with . + NOTE: Remove spaces and replace 'at' with @, 'dot' with . This replaces the old calc-bugs Email address. To be sure we see your Email reporting a calc bug, please use the following phase in your Email Subject line: - calc bug report + calc bug report That phrase in your subject line will help ensure your request will get past our anti-spam filters. You may have @@ -137,7 +137,7 @@ The calc web site is located at: ## ## 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 +## 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 @@ -145,8 +145,8 @@ The calc web site is located at: ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1999/10/20 07:42:55 -## File existed as early as: 1999 +## Under source code control: 1999/10/20 07:42:55 +## File existed as early as: 1999 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/trunc b/help/trunc index 4db40a3..37bb245 100644 --- a/help/trunc +++ b/help/trunc @@ -5,10 +5,10 @@ SYNOPSIS trunc(x [,j]) TYPES - x real - j int + x real + j int - return real + return real DESCRIPTION Truncate x to j decimal places. If j is omitted, 0 places is assumed. @@ -43,7 +43,7 @@ SEE ALSO ## ## 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 +## 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 @@ -51,8 +51,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1994/09/30 00:52:38 -## File existed as early as: 1994 +## Under source code control: 1994/09/30 00:52:38 +## File existed as early as: 1994 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/types b/help/types index 99bdc38..78bc623 100644 --- a/help/types +++ b/help/types @@ -3,116 +3,116 @@ Builtin types The calculator has the following built-in types: null value - This is the undefined value type. The function 'null' - returns this value. Functions which do not explicitly - return a value return this type. If a function is called - with fewer parameters than it is defined for, then the - missing parameters have the null type. The null value is - false if used in an IF test. + This is the undefined value type. The function 'null' + returns this value. Functions which do not explicitly + return a value return this type. If a function is called + with fewer parameters than it is defined for, then the + missing parameters have the null type. The null value is + false if used in an IF test. rational numbers - This is the basic data type of the calculator. - These are fractions whose numerators and denominators - can be arbitrarily large. The fractions are always - in lowest terms. Integers have a denominator of 1. - The numerator of the number contains the sign, so that - the denominator is always positive. When a number is - entered in floating point or exponential notation, it is - immediately converted to the appropriate fractional value. - Printing a value as a floating point or exponential value - involves a conversion from the fractional representation. + This is the basic data type of the calculator. + These are fractions whose numerators and denominators + can be arbitrarily large. The fractions are always + in lowest terms. Integers have a denominator of 1. + The numerator of the number contains the sign, so that + the denominator is always positive. When a number is + entered in floating point or exponential notation, it is + immediately converted to the appropriate fractional value. + Printing a value as a floating point or exponential value + involves a conversion from the fractional representation. - Numbers are stored in binary format, so that in general, - bit tests and shifts are quicker than multiplies and divides. - Similarly, entering or displaying of numbers in binary, - octal, or hex formats is quicker than in decimal. The - sign of a number does not affect the bit representation - of a number. + Numbers are stored in binary format, so that in general, + bit tests and shifts are quicker than multiplies and divides. + Similarly, entering or displaying of numbers in binary, + octal, or hex formats is quicker than in decimal. The + sign of a number does not affect the bit representation + of a number. complex numbers - Complex numbers are composed of real and imaginary parts, - which are both fractions as defined above. An integer which - is followed by an 'i' character is a pure imaginary number. - Complex numbers such as "2+3i" when typed in, are processed - as the sum of a real and pure imaginary number, resulting - in the desired complex number. Therefore, parenthesis are - sometimes necessary to avoid confusion, as in the two values: + Complex numbers are composed of real and imaginary parts, + which are both fractions as defined above. An integer which + is followed by an 'i' character is a pure imaginary number. + Complex numbers such as "2+3i" when typed in, are processed + as the sum of a real and pure imaginary number, resulting + in the desired complex number. Therefore, parenthesis are + sometimes necessary to avoid confusion, as in the two values: - 1+2i ^2 (which is -3) - (1+2i) ^2 (which is -3+4i) + 1+2i ^2 (which is -3) + (1+2i) ^2 (which is -3+4i) - Similar care is required when entering fractional complex - numbers. Note the differences below: + Similar care is required when entering fractional complex + numbers. Note the differences below: - 3/4i (which is -(3/4)i) - 3i/4 (which is (3/4)i) + 3/4i (which is -(3/4)i) + 3i/4 (which is (3/4)i) - The imaginary unit itself is input using "1i". + The imaginary unit itself is input using "1i". strings - Strings are a sequence of zero or more characters. - They are input using either of the single or double - quote characters. The quote mark which starts the - string also ends it. Various special characters can - also be inserted using back-slash. Example strings: + Strings are a sequence of zero or more characters. + They are input using either of the single or double + quote characters. The quote mark which starts the + string also ends it. Various special characters can + also be inserted using back-slash. Example strings: - "hello\n" - "that's all" - 'lots of """"' - 'a' - "" + "hello\n" + "that's all" + 'lots of """"' + 'a' + "" - There is no distinction between single character and - multi-character strings. The 'str' and 'ord' functions - will convert between a single character string and its - numeric value. The 'str' and 'eval' functions will - convert between longer strings and the corresponding - numeric value (if legal). The 'strcat', 'strlen', and - 'substr' functions are also useful. + There is no distinction between single character and + multi-character strings. The 'str' and 'ord' functions + will convert between a single character string and its + numeric value. The 'str' and 'eval' functions will + convert between longer strings and the corresponding + numeric value (if legal). The 'strcat', 'strlen', and + 'substr' functions are also useful. matrices - These are one to four dimensional matrices, whose minimum - and maximum bounds can be specified at runtime. Unlike C, - the minimum bounds of a matrix do not have to start at 0. - The elements of a matrix can be of any type. There are - several built-in functions for matrices. Matrices are - created using the 'mat' statement. + These are one to four dimensional matrices, whose minimum + and maximum bounds can be specified at runtime. Unlike C, + the minimum bounds of a matrix do not have to start at 0. + The elements of a matrix can be of any type. There are + several built-in functions for matrices. Matrices are + created using the 'mat' statement. associations - These are one to four dimensional matrices which can be - indexed by arbitrary values, instead of just integers. - These are also known as associative arrays. The elements of - an association can be of any type. Very few operations are - permitted on an association except for indexing. Associations - are created using the 'assoc' function. + These are one to four dimensional matrices which can be + indexed by arbitrary values, instead of just integers. + These are also known as associative arrays. The elements of + an association can be of any type. Very few operations are + permitted on an association except for indexing. Associations + are created using the 'assoc' function. lists - These are a sequence of values, which are linked together - so that elements can be easily be inserted or removed - anywhere in the list. The values can be of any type. - Lists are created using the 'list' function. + These are a sequence of values, which are linked together + so that elements can be easily be inserted or removed + anywhere in the list. The values can be of any type. + Lists are created using the 'list' function. files - These are text files opened using stdio. Files may be opened - for sequential reading, writing, or appending. Opening a - file using the 'fopen' function returns a value which can - then be used to perform I/O to that file. File values can - be copied by normal assignments between variables, or by - using the result of the 'files' function. Such copies are - indistinguishable from each other. + These are text files opened using stdio. Files may be opened + for sequential reading, writing, or appending. Opening a + file using the 'fopen' function returns a value which can + then be used to perform I/O to that file. File values can + be copied by normal assignments between variables, or by + using the result of the 'files' function. Such copies are + indistinguishable from each other. The calculator also has a number of special types that as used by some special builtin functions: rand - A subtractive 100 shuffle pseudo-random number generator - state. This state is used by functions such as isrand() - and srand(). + A subtractive 100 shuffle pseudo-random number generator + state. This state is used by functions such as isrand() + and srand(). random - A Blum-Blum-Shub pseudo-random number generator state. - This state is used by functions such as israndom() and - srandom(). + A Blum-Blum-Shub pseudo-random number generator state. + This state is used by functions such as israndom() and + srandom(). ## Copyright (C) 1999,2018 Landon Curt Noll ## @@ -122,7 +122,7 @@ Builtin types ## ## 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 +## 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 @@ -130,8 +130,8 @@ Builtin types ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:24 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:24 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/unexpected b/help/unexpected index cbfee04..a444b63 100644 --- a/help/unexpected +++ b/help/unexpected @@ -1,7 +1,7 @@ Unexpected While calc is C-like, users of C will find some unexpected - surprises in calc syntax and usage. Persons familiar with C should + surprises in calc syntax and usage. Persons familiar with C should review this file. Persons familiar with shell scripting may want to review this file @@ -16,26 +16,26 @@ Unexpected expressions and for separation of expressions to be used for arguments or values in function calls or initialization lists. The precedence order of these different uses is: continuation, - separator, comma operator. For example, assuming the variables a, + separator, comma operator. For example, assuming the variables a, b, c, d, e, and object type xx have been defined, the arguments passed to f in: - f(a, b, c, obj xx d, e) + f(a, b, c, obj xx d, e) are a, b, c, and e, with e having the value of a newly created xx object. In: - f((a, b), c, (obj xx d), e) + f((a, b), c, (obj xx d), e) the arguments of f are b, c, d, e, with only d being a newly created xx object. In combination with other operators, the continuation use of the comma has the same precedence as [] and ., the separator use the - same as the comma operator. For example, assuming xx.mul() has + same as the comma operator. For example, assuming xx.mul() has been defined: - f(a = b, obj xx c, d = {1,2} * obj xx e = {3,4}) + f(a = b, obj xx c, d = {1,2} * obj xx e = {3,4}) passes two arguments: a (with value b) and the product d * e of two initialized xx objects. @@ -47,45 +47,45 @@ Unexpected In C, ^ is the xor operator. The expression: - a ^ b + a ^ b yields "a to the b power", NOT "a xor b". Unlike in C, calc evaluates the expression: - a ** b + a ** b also yields "a to the b power". Here "a" and "b" can be a real value or a complex value: - 2^3 3i^4 - 2.5 ^ 3.5 0.5i ^ 0.25 - 2.5 ^ 2.718i 3.13145i ^ 0.30103i + 2^3 3i^4 + 2.5 ^ 3.5 0.5i ^ 0.25 + 2.5 ^ 2.718i 3.13145i ^ 0.30103i In addition, "a" can be matrix. In this case "b" must be an integer: - mat a[2,2] = {1,2,3,4}; - a^3 + mat a[2,2] = {1,2,3,4}; + a^3 Note that 'a' == 0 and 'b' is real, then is must be >= 0 as well. Also 0^0 and 0**0 return the value 1. Be careful about the precedence of operators. Note that: - -1 ^ 0.5 == -1 + -1 ^ 0.5 == -1 whereas: - (-1) ^ 0.5 == 1i + (-1) ^ 0.5 == 1i because the above expression in parsed as: - -(1 ^ 0.5) == -1 + -(1 ^ 0.5) == -1 whereas: - (-1) ^ 0.5 == 1i + (-1) ^ 0.5 == 1i op= operators associate left to right @@ -93,24 +93,24 @@ Unexpected Operator-with-assignments: - += -= *= /= %= //= &= |= <<= >>= ^= **= + += -= *= /= %= //= &= |= <<= >>= ^= **= associate from left to right instead of right to left as in C. For example: - a += b *= c + a += b *= c has the effect of: - a = (a + b) * c + a = (a + b) * c - where only 'a' is required to be an lvalue. For the effect of: + where only 'a' is required to be an lvalue. For the effect of: - b *= c; a += b + b *= c; a += b when both 'a' and 'b' are lvalues, use: - a += (b *= c) + a += (b *= c) || yields values other than 0 or 1 @@ -118,13 +118,13 @@ Unexpected In C: - a || b + a || b will produce 0 or 1 depending on the logical evaluation - of the expression. In calc, this expression will produce + of the expression. In calc, this expression will produce either 'a' or 'b' and is equivalent to the expression: - a ? a : b + a ? a : b In other words, if 'a' is true, then 'a' is returned, otherwise 'b' is returned. @@ -135,13 +135,13 @@ Unexpected In C: - a && b + a && b will produce 0 or 1 depending on the logical evaluation - of the expression. In calc, this expression will produce + of the expression. In calc, this expression will produce either 'a' or 'b' and is equivalent to the expression: - a ? b : a + a ? b : a In other words, if 'a' is true, then 'b' is returned, otherwise 'a' is returned. @@ -152,18 +152,18 @@ Unexpected In C: - x/y + x/y performs integer division when 'x' and 'y' are integer types. In calc, this expression yields a rational number. Calc uses: - x//y + x//y to perform division with integer truncation and is the equivalent to: - int(x/y) + int(x/y) | and & have higher precedence than ==, +, -, *, / and % @@ -171,15 +171,15 @@ Unexpected Is C: - a == b | c * d + a == b | c * d is interpreted as: - (a == b) | (c * d) + (a == b) | (c * d) and calc it is interpreted as: - a == ((b | c) * d) + a == ((b | c) * d) calc always evaluates terms from left to right @@ -192,41 +192,41 @@ Unexpected Consider, for example: - A * B + C * D + A * B + C * D In calc above expression is evaluated in the following order: - A - B - A * B - C - D - C * D - A * B + C * D + A + B + A * B + C + D + C * D + A * B + C * D This order of evaluation is significant if evaluation of a term changes a variable on which a later term depends. For example: - x++ * x++ + x++ * x++ + x++ * x++ + x++ * x++ in calc returns the value: - x * (x + 1) + (x + 2) * (x + 3) + x * (x + 1) + (x + 2) * (x + 3) and increments x as if by x += 4. Similarly, for functions f, g, the expression: - f(x++, x++) + g(x++) + f(x++, x++) + g(x++) evaluates to: - f(x, x + 1) + g(x + 2) + f(x, x + 1) + g(x + 2) and increments x three times. In an other example, this expression: - 1<<8/2 + 1<<8/2 evaluates to 128, not 16, because <<8 is performed before the /2. @@ -256,13 +256,13 @@ Unexpected Along the same lines: - undefine * + undefine * undefines all current user-defined functions. After executing all the above freeing functions (and if necessary free(.) to free the current "old value"), the only remaining numbers as displayed by - show numbers + show numbers should be those associated with epsilon(), and if it has been called, qpi(). @@ -277,23 +277,23 @@ Unexpected A single # is an calc operator, not a comment. However two or more ##'s in a row is a comment. See "help pound" for more information. - #!/usr/local/src/bin/calc/calc -q -f + #!/usr/local/src/bin/calc/calc -q -f - /* a correct comment */ - ## another correct comment - ### two or more together is also a comment - /* - * another correct comment - */ - print "2+2 =", 2+2; ## yet another comment + /* a correct comment */ + ## another correct comment + ### two or more together is also a comment + /* + * another correct comment + */ + print "2+2 =", 2+2; ## yet another comment This next example is WRONG: - #!/usr/local/src/bin/calc/calc -q -f + #!/usr/local/src/bin/calc/calc -q -f - # This is not a calc calc comment because it has only a single # - # You must to start comments with ## or /* - print "This example has invalid comments" + # This is not a calc calc comment because it has only a single # + # You must to start comments with ## or /* + print "This example has invalid comments" See "help cscript" and "help usage" for more information. @@ -306,38 +306,38 @@ Unexpected This works as expected: - if (expr) { - ... - } + if (expr) { + ... + } However this WILL NOT WORK AS EXPECTED: - if (expr) - { - ... - } + if (expr) + { + ... + } because calc will parse the if being terminated by an empty statement followed by { ... }. As in: - if (expr) ; - { - ... - } + if (expr) ; + { + ... + } In the same way, use these forms: - for (optionalexpr ; optionalexpr ; optionalexpr) { - ... - } + for (optionalexpr ; optionalexpr ; optionalexpr) { + ... + } - while (expr) { - ... - } + while (expr) { + ... + } - do { - ... - while (expr); + do { + ... + while (expr); where the initial { is on the SAME LINE as the if, while, for or do keyword. @@ -350,7 +350,7 @@ Unexpected In most interactive shells: - calc 2 * 3 + calc 2 * 3 will frequently produce a "Missing operator" error because the '*' is evaluated as a "shell glob". To avoid this you must quote or escape @@ -358,11 +358,11 @@ Unexpected For example, bash / ksh / sh shell users should use: - calc '2 * 3' + calc '2 * 3' or: - calc 2 \* 3 + calc 2 \* 3 or some other form of shell meta-character escaping. @@ -372,19 +372,19 @@ Unexpected The shell command: - seq 5 | while read i; do calc "($i+3)^2"; done + seq 5 | while read i; do calc "($i+3)^2"; done - FYI: The command "seq 5" will write 1 through 5 on separate - lines on standard output, while read i sets $i to - the value of each line that is read from stdin. + FYI: The command "seq 5" will write 1 through 5 on separate + lines on standard output, while read i sets $i to + the value of each line that is read from stdin. will produce: 16 - 2 - 3 - 4 - 5 + 2 + 3 + 4 + 5 The reason why the last 4 lines of output are 2 through 5 is that after calc evaluates the first line and prints (1+3)^2 @@ -393,15 +393,15 @@ Unexpected To avoid this problem, use: - seq 5 | while read i; do calc "($i+3)^2" "); - if (isnull(n)) { - print("got null"); - } else { - print("got " + n); - } + n = prompt("Test> "); + if (isnull(n)) { + print("got null"); + } else { + print("got " + n); + } However the following shell script (note the -p before the -f in the 1st line) will be interactive, prompt with "Test> " and print the "got" result as expected: - #!/usr/bin/calc -q -p -f + #!/usr/bin/calc -q -p -f - n = prompt("Test> "); - if (isnull(n)) { - print("got null"); - } else { - print("got " + n); - } + n = prompt("Test> "); + if (isnull(n)) { + print("got null"); + } else { + print("got " + n); + } Note in the example above, the -p flag must be given before the final -f command line flag. @@ -622,7 +622,7 @@ Unexpected ## ## 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 +## 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 @@ -630,8 +630,8 @@ Unexpected ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/03/21 13:15:18 -## File existed as early as: 1997 +## Under source code control: 1997/03/21 13:15:18 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/usertime b/help/usertime index 8111422..7d75c5f 100644 --- a/help/usertime +++ b/help/usertime @@ -5,7 +5,7 @@ SYNOPSIS usertime() TYPES - return nonnegative real + return nonnegative real DESCRIPTION In POSIX based systems, this function will return the CPU seconds @@ -23,7 +23,7 @@ EXAMPLE ; t = usertime(); ; x = ptest(2^4253-1); ; usertime() - t; - 1.287804 + 1.287804 LIMITS On non-POSIX based systems, this function always returns 0. @@ -42,7 +42,7 @@ SEE ALSO ## ## 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 +## 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 @@ -50,8 +50,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2006/12/16 10:31:08 -## File existed as early as: 2006 +## Under source code control: 2006/12/16 10:31:08 +## File existed as early as: 2006 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/variable b/help/variable index 09918fd..73f78c8 100644 --- a/help/variable +++ b/help/variable @@ -4,7 +4,7 @@ Variable declarations Global variables are visible to all functions and on the command line, and are permanent. Local variables are visible only within a single function or command sequence. When the function or command - sequence returns, the local variables are deleted. Static variables + sequence returns, the local variables are deleted. Static variables are permanent like global variables, but are only visible within the same input file or function where they are defined. @@ -13,12 +13,12 @@ Variable declarations separated by commas. The definition is terminated with a semicolon. Examples of declarations are: - local x, y, z; - global fred; - local foo, bar; - static var1, var2, var3; + local x, y, z; + global fred; + local foo, bar; + static var1, var2, var3; - Variables may have initializations applied to them. This is done + Variables may have initializations applied to them. This is done by following the variable name by an equals sign and an expression. Global and local variables are initialized each time that control reaches them (e.g., at the entry to a function which contains them). @@ -28,23 +28,23 @@ Variable declarations contain function calls and refer to variables. Examples of such initializations are: - local a1 = 7, a2 = 3; - static b = a1 + sin(a2); + local a1 = 7, a2 = 3; + static b = a1 + sin(a2); Within function declarations, all variables must be defined. But on the top level command line, assignments automatically define - global variables as needed. For example, on the top level command + global variables as needed. For example, on the top level command line, the following defines the global variable x if it had not already been defined: - x = 7 + x = 7 The static keyword may be used at the top level command level to define a variable which is only accessible interactively, or within functions defined interactively. Variables have no fixed type, thus there is no need or way to - specify the types of variables as they are defined. Instead, the + specify the types of variables as they are defined. Instead, the types of variables change as they are assigned to or are specified in special statements such as 'mat' and 'obj'. When a variable is first defined using 'local', 'global', or 'static', it has the @@ -61,15 +61,15 @@ Variable declarations of these variables are also allowed. Examples of such declarations are: - static mat table[3] = {5, 6, 7}; - local obj point p1, p2; + static mat table[3] = {5, 6, 7}; + local obj point p1, p2; When working with user-defined functions, the syntax for passing an lvalue by reference rather than by value is to precede an expression for the lvalue by a backquote. For example, if the function invert is defined by: - define invert(x) {x = inverse(x)} + define invert(x) {x = inverse(x)} then invert(`A) achieves the effect of A = inverse(A). In other words, passing and argument of `variable (with a back-quote) @@ -81,14 +81,14 @@ Variable declarations In an argument, a backquote before other than an lvalue is ignored. Consider, for example: - ; define logplus(x,y,z) {return log(++x + ++y + ++z);} + ; define logplus(x,y,z) {return log(++x + ++y + ++z);} - ; eh = 55; - ; mi = 25; - ; answer = logplus(eh, `mi, `17); + ; eh = 55; + ; mi = 25; + ; answer = logplus(eh, `mi, `17); - ; print eh, mi, answer; - 55 26 2 + ; print eh, mi, answer; + 55 26 2 The value of eh is was not changed because eh was used as an argument without a back-quote (`). However, mi was incremented @@ -102,27 +102,27 @@ Variable declarations use the indirection operator * (star) to refer to the lvalue in the function body. Consider the following function: - ; define ten(a) { *a = 10; } + ; define ten(a) { *a = 10; } - ; n = 17; - ; ten(n); - ; print n; - 17 + ; n = 17; + ; ten(n); + ; print n; + 17 - ; ten(`n); - ; print n; - 17 + ; ten(`n); + ; print n; + 17 - ; ten(&n); - ; print n; - 10 + ; ten(&n); + ; print n; + 10 Passing an argument with a & (ampersand) allows the tenmore() function to modify the calling variable: - ; wa = tenmore(&vx); - ; print vx, wa; - 65 65 + ; wa = tenmore(&vx); + ; print vx, wa; + 65 65 Great care should be taken when using a pointer to a local variable or element of a matrix, list or object, since the lvalue pointed to @@ -147,7 +147,7 @@ Variable declarations ## ## 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 +## 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 @@ -155,8 +155,8 @@ Variable declarations ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:25 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:25 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/vercos b/help/vercos index 72d83ad..766e494 100644 --- a/help/vercos +++ b/help/vercos @@ -5,10 +5,10 @@ SYNOPSIS vercos(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the versed trigonometric cosine of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called verc, or vercosin, is equivalent to: - vercos(x) = 1 + cos(x) + vercos(x) = 1 + cos(x) EXAMPLE ; print vercos(1/2), vercos(5/7), vercos(42/7) @@ -55,14 +55,14 @@ EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -72,7 +72,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -80,8 +80,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/09/05 23:25:28 -## File existed as early as: 2023 +## Under source code control: 2023/09/05 23:25:28 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/versin b/help/versin index 9fafa2a..5e320c1 100644 --- a/help/versin +++ b/help/versin @@ -5,10 +5,10 @@ SYNOPSIS versin(x [,eps]) TYPES - x number (real or complex) - eps 0 < real < 1, defaults to epsilon() + x number (real or complex) + eps 0 < real < 1, defaults to epsilon() - return number + return number DESCRIPTION Calculate the versed trigonometric sine of x to a multiple of eps with error less in @@ -16,7 +16,7 @@ DESCRIPTION This function is sometimes called vers, is equivalent to: - versin(x) = 1 - cos(x) + versin(x) = 1 - cos(x) EXAMPLE ; print versin(1/2), versin(5/7), versin(42/7) @@ -54,14 +54,14 @@ SEE ALSO EXTERNAL RESOURCES For general information on trigonometric functions, see: - https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions - https://en.wikipedia.org/wiki/Versine - https://en.wikipedia.org/wiki/Exsecant - https://en.wikipedia.org/wiki/Inverse_trigonometric_functions - https://en.wikipedia.org/wiki/Chord_(geometry) - https://en.wikipedia.org/wiki/Secant_line - https://en.wikipedia.org/wiki/Hartley_transform#cas - https://en.wikipedia.org/wiki/Cis_(mathematics) + https://en.wikipedia.org/wiki/Trigonometric_functions#Unit-circle_definitions + https://en.wikipedia.org/wiki/Versine + https://en.wikipedia.org/wiki/Exsecant + https://en.wikipedia.org/wiki/Inverse_trigonometric_functions + https://en.wikipedia.org/wiki/Chord_(geometry) + https://en.wikipedia.org/wiki/Secant_line + https://en.wikipedia.org/wiki/Hartley_transform#cas + https://en.wikipedia.org/wiki/Cis_(mathematics) ## Copyright (C) 2023 Landon Curt Noll ## @@ -71,7 +71,7 @@ EXTERNAL RESOURCES ## ## 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 +## 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 @@ -79,8 +79,8 @@ EXTERNAL RESOURCES ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2023/08/31 23:05:28 -## File existed as early as: 2023 +## Under source code control: 2023/08/31 23:05:28 +## File existed as early as: 2023 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/version b/help/version index af06226..c015a3a 100644 --- a/help/version +++ b/help/version @@ -5,16 +5,16 @@ SYNOPSIS version() TYPES - return string + return string DESCRIPTION Returns the calc version string. Calc version strings can be of the form: - x.y.z.w - x.y.z - x.y + x.y.z.w + x.y.z + x.y where x, y, z, w, v are integers (without leading 0's) and, t is the literal character 't'. @@ -42,7 +42,7 @@ SEE ALSO ## ## 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 +## 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 @@ -50,8 +50,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 2001/05/28 17:38:01 -## File existed as early as: 2001 +## Under source code control: 2001/05/28 17:38:01 +## File existed as early as: 2001 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/wishlist b/help/wishlist index fadd8a6..c1d40d9 100644 --- a/help/wishlist +++ b/help/wishlist @@ -28,7 +28,7 @@ Please read CONTRIB-CODE or run the following calc command: 'eval' function, division by zeroes, and so on can be caught. This should be done using syntax similar to: - ONERROR statement DO statement; + ONERROR statement DO statement; Something like signal isn't versatile enough. @@ -47,7 +47,7 @@ Please read CONTRIB-CODE or run the following calc command: * Allow results of a command (or all commands) to be re-directed to a file or piped into a command. - * Add some kind of #include and #define facility. Perhaps use + * Add some kind of #include and #define facility. Perhaps use the C pre-processor itself? * Support a more general input and output base mode other than @@ -57,10 +57,10 @@ Please read CONTRIB-CODE or run the following calc command: begun. This will use backquotes to define expressions, and new functions will be able to act on expressions. For example: - x = `hello * strlen(mom)`; - x = sub(x, `hello`, `hello + 1`); - x = sub(x, `hello`, 10, `mom`, "curds"); - eval(x); + x = `hello * strlen(mom)`; + x = sub(x, `hello`, `hello + 1`); + x = sub(x, `hello`, 10, `mom`, "curds"); + eval(x); prints 55. @@ -91,12 +91,12 @@ Please read CONTRIB-CODE or run the following calc command: * Add a builtin that returns a value from the history list. As an example: - histval(-10) + histval(-10) returns the 10th value on the history value list, if such - a value is in the history list (null otherwise). And: + a value is in the history list (null otherwise). And: - histval(23) + histval(23) return the value of the 23rd command given to calc, if such a value is in the history list (null otherwise). @@ -107,13 +107,13 @@ Please read CONTRIB-CODE or run the following calc command: * Add a builtin that returns command as a string from the history list. As an example: - history(-10) + history(-10) returns a string containing the 10th command on the history list, if a such a value is in the history list (empty string otherwise). And: - history(23) + history(23) return the string containing the 23rd command given to calc, if such a value is in the history list (empty string otherwise). @@ -121,37 +121,37 @@ Please read CONTRIB-CODE or run the following calc command: One could use the eval() function to re-evaluate the command. * Allow one to optionally restore the command number to calc - prompts. When going back in the history list, indicate the + prompts. When going back in the history list, indicate the command number that is being examined. The command number was a useful item. When one is scanning the - history list, knowing where you are is hard without it. It can + history list, knowing where you are is hard without it. It can get confusing when the history list wraps or when you use - search bindings. Command numbers would be useful in + search bindings. Command numbers would be useful in conjunction with positive args for the history() and histval() functions as suggested above. * Add a builtin that returns the current command number. For example: - cmdnum() + cmdnum() returns the current command number. - This would allow one to tag a value in the history list. One + This would allow one to tag a value in the history list. One could save the result of cmdnum() in a variable and later use it as an arg to the histval() or history() functions. * Add a factoring builtin functions. Provide functions that perform multiple polynomial quadratic sieves, elliptic curve, difference - of two squares, N-1 factoring as so on. Provide a easy general + of two squares, N-1 factoring as so on. Provide a easy general factoring builtin (say factor(foo)) that would attempt to apply whatever process was needed based on the value. Factoring builtins would return a matrix of factors. It would be handy to configure, via config(), the maximum time - that one should try to factor a number. By default the time + that one should try to factor a number. By default the time should be infinite. If one set the time limit to a finite value and the time limit was exceeded, the factoring builtin would return whatever if had found thus far, even if no new @@ -187,16 +187,16 @@ Please read CONTRIB-CODE or run the following calc command: Calc bug reports and calc bug fixes should be sent to: -NOTE: calc-bug-report Email address no longer in use +NOTE: calc-bug-report Email address no longer in use - NOTE: Remove spaces and replace 'at' with @, 'dot' with . + NOTE: Remove spaces and replace 'at' with @, 'dot' with . This replaces the old calc-bugs Email address. To be sure we see your Email reporting a calc bug, please use the following phase in your Email Subject line: - calc bug report + calc bug report That phrase in your subject line will help ensure your request will get past our anti-spam filters. You may have @@ -223,7 +223,7 @@ The calc web site is located at: ## ## 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 +## 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 @@ -231,8 +231,8 @@ The calc web site is located at: ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1991/07/21 04:37:24 -## File existed as early as: 1991 +## Under source code control: 1991/07/21 04:37:24 +## File existed as early as: 1991 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/help/xor b/help/xor index 830358e..6d5baf8 100644 --- a/help/xor +++ b/help/xor @@ -7,7 +7,7 @@ SYNOPSIS TYPES x1, x2, ... integer - return integer + return integer DESCRIPTION Compute the bitwise exclusive or of a set of integers. @@ -16,14 +16,14 @@ DESCRIPTION xor(x1,x2) returns the bitwise exclusive or of x1 and x2. For each bit pair: - 0 0 xor returns 0 - 0 1 xor returns 1 - 1 0 xor returns 1 - 1 1 xor returns 0 + 0 0 xor returns 0 + 0 1 xor returns 1 + 1 0 xor returns 1 + 1 1 xor returns 0 For more than two arguments, xor(x1,x2,x3, ..., xn) returns: - xor(...xor(xor(x1,x2), x3), ... xn) + xor(...xor(xor(x1,x2), x3), ... xn) EXAMPLE ; print xor(2), xor(5, 3, -7, 2, 9) @@ -46,7 +46,7 @@ SEE ALSO ## ## 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 +## 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 @@ -54,8 +54,8 @@ SEE ALSO ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1995/10/05 04:52:27 -## File existed as early as: 1995 +## Under source code control: 1995/10/05 04:52:27 +## File existed as early as: 1995 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/hist.c b/hist.c index c05c88e..b2b97e3 100644 --- a/hist.c +++ b/hist.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1993/05/02 20:09:19 - * File existed as early as: 1993 + * Under source code control: 1993/05/02 20:09:19 + * File existed as early as: 1993 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -28,7 +28,7 @@ * * GNU readline support added by Martin Buck * - * Interactive readline module. This is called to read lines of input, + * Interactive readline module. This is called to read lines of input, * while using emacs-like editing commands within a command stack. * The key bindings for the editing commands are (slightly) configurable. */ @@ -70,7 +70,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ #define MIN(a,b) (((a) <= (b)) ? (a) : (b)) @@ -79,32 +79,32 @@ E_FUNC FILE *curstream(void); -#define STDIN 0 -#define SAVE_SIZE 256 /* size of save buffer */ -#define MAX_KEYS 60 /* number of key bindings */ +#define STDIN 0 +#define SAVE_SIZE 256 /* size of save buffer */ +#define MAX_KEYS 60 /* number of key bindings */ -#define CONTROL(x) ((char)(((int)(x)) & 0x1f)) +#define CONTROL(x) ((char)(((int)(x)) & 0x1f)) -STATIC struct { - char *prompt; - char *buf; - char *pos; - char *end; - char *mark; - int bufsize; - int linelen; - int histcount; /* valid history entries */ - int curhist; - bool virgin_line; /* 1 => never typed chars, 0 => chars typed */ +STATIC struct { + char *prompt; + char *buf; + char *pos; + char *end; + char *mark; + int bufsize; + int linelen; + int histcount; /* valid history entries */ + int curhist; + bool virgin_line; /* 1 => never typed chars, 0 => chars typed */ } HS; typedef void (*FUNCPTR)(int); typedef struct { - char *name; - FUNCPTR func; + char *name; + FUNCPTR func; } FUNC; /* declare binding functions */ @@ -142,116 +142,116 @@ S_FUNC void arrow_key(int key); S_FUNC void quit_calc(int key) __attribute__((noreturn)); -STATIC FUNC funcs[] = +STATIC FUNC funcs[] = { - {"ignore-char", ignore_char}, - {"flush-input", flush_input}, - {"start-of-line", start_of_line}, - {"end-of-line", end_of_line}, - {"forward-char", forward_char}, - {"backward-char", backward_char}, - {"forward-word", forward_word}, - {"backward-word", backward_word}, - {"delete-char", delete_char}, - {"forward-kill-char", forward_kill_char}, - {"backward-kill-char", backward_kill_char}, - {"forward-kill-word", forward_kill_word}, - {"uppercase-word", uppercase_word}, - {"lowercase-word", lowercase_word}, - {"kill-line", kill_line}, - {"goto-line", goto_line}, - {"new-line", new_line}, - {"save-line", save_line}, - {"forward-history", forward_history}, - {"backward-history", backward_history}, - {"insert-char", insert_char}, - {"list-history", list_history}, - {"refresh-line", refresh_line}, - {"swap-chars", swap_chars}, - {"set-mark", set_mark}, - {"yank", yank}, - {"save-region", save_region}, - {"kill-region", kill_region}, - {"reverse-search", reverse_search}, - {"quote-char", quote_char}, - {"arrow-key", arrow_key}, - {"quit", quit_calc}, - {NULL, NULL} + {"ignore-char", ignore_char}, + {"flush-input", flush_input}, + {"start-of-line", start_of_line}, + {"end-of-line", end_of_line}, + {"forward-char", forward_char}, + {"backward-char", backward_char}, + {"forward-word", forward_word}, + {"backward-word", backward_word}, + {"delete-char", delete_char}, + {"forward-kill-char", forward_kill_char}, + {"backward-kill-char", backward_kill_char}, + {"forward-kill-word", forward_kill_word}, + {"uppercase-word", uppercase_word}, + {"lowercase-word", lowercase_word}, + {"kill-line", kill_line}, + {"goto-line", goto_line}, + {"new-line", new_line}, + {"save-line", save_line}, + {"forward-history", forward_history}, + {"backward-history", backward_history}, + {"insert-char", insert_char}, + {"list-history", list_history}, + {"refresh-line", refresh_line}, + {"swap-chars", swap_chars}, + {"set-mark", set_mark}, + {"yank", yank}, + {"save-region", save_region}, + {"kill-region", kill_region}, + {"reverse-search", reverse_search}, + {"quote-char", quote_char}, + {"arrow-key", arrow_key}, + {"quit", quit_calc}, + {NULL, NULL} }; -typedef struct key_ent KEY_ENT; -typedef struct key_map KEY_MAP; +typedef struct key_ent KEY_ENT; +typedef struct key_map KEY_MAP; -struct key_ent { - FUNCPTR func; - KEY_MAP *next; +struct key_ent { + FUNCPTR func; + KEY_MAP *next; }; struct key_map { - char *name; - KEY_ENT default_ent; - KEY_ENT *map[256]; + char *name; + KEY_ENT default_ent; + KEY_ENT *map[256]; }; -STATIC char base_map_name[] = "base-map"; -STATIC char esc_map_name[] = "esc-map"; +STATIC char base_map_name[] = "base-map"; +STATIC char esc_map_name[] = "esc-map"; -STATIC KEY_MAP maps[] = { - {base_map_name, {NULL, NULL}, {NULL, NULL}}, - {esc_map_name, {NULL, NULL}, {NULL, NULL}}, +STATIC KEY_MAP maps[] = { + {base_map_name, {NULL, NULL}, {NULL, NULL}}, + {esc_map_name, {NULL, NULL}, {NULL, NULL}}, }; typedef struct history_entry { - int len; /* length of data */ - char *data; /* varying length data */ + int len; /* length of data */ + char *data; /* varying length data */ struct history_entry* prev; struct history_entry* next; } HIST; -STATIC int inited; -STATIC int canedit; -STATIC int key_count; -STATIC int save_len; -STATIC KEY_MAP *cur_map; -STATIC KEY_MAP *base_map; -STATIC KEY_ENT key_table[MAX_KEYS]; -STATIC HIST* hist_first = NULL; -STATIC HIST* hist_last = NULL; -STATIC char save_buffer[SAVE_SIZE]; +STATIC int inited; +STATIC int canedit; +STATIC int key_count; +STATIC int save_len; +STATIC KEY_MAP *cur_map; +STATIC KEY_MAP *base_map; +STATIC KEY_ENT key_table[MAX_KEYS]; +STATIC HIST* hist_first = NULL; +STATIC HIST* hist_last = NULL; +STATIC char save_buffer[SAVE_SIZE]; /* declare other static functions */ -S_FUNC FUNCPTR find_func(char *name); -S_FUNC HIST *get_event(int n); -S_FUNC HIST *find_event(char *pat, int len); -S_FUNC void read_key(void); -S_FUNC void erasechar(void); -S_FUNC void newline(void); -S_FUNC void backspace(void); -S_FUNC void beep(void); -S_FUNC void echo_char(int ch); -S_FUNC void echo_string(char *str, int len); -S_FUNC void savetext(char *str, int len); -S_FUNC void memrcpy(char *dest, char *src, int len); -S_FUNC int read_bindings(FILE *fp); -S_FUNC int in_word(int ch); -S_FUNC KEY_MAP *find_map(char *map); -S_FUNC void unbind_key(KEY_MAP *map, int key); -S_FUNC void raw_bind_key(KEY_MAP *map, int key, - FUNCPTR func, KEY_MAP *next_map); -S_FUNC KEY_MAP *do_map_line(char *line); -S_FUNC void do_default_line(KEY_MAP *map, char *line); -S_FUNC void do_bind_line(KEY_MAP *map, char *line); -S_FUNC void back_over_char(int ch); -S_FUNC void echo_rest_of_line(void); -S_FUNC void goto_start_of_line(void); -S_FUNC void goto_end_of_line(void); -S_FUNC void remove_char(int ch); -S_FUNC void decrement_end(int n); -S_FUNC void insert_string(char *str, int len); +S_FUNC FUNCPTR find_func(char *name); +S_FUNC HIST *get_event(int n); +S_FUNC HIST *find_event(char *pat, int len); +S_FUNC void read_key(void); +S_FUNC void erasechar(void); +S_FUNC void newline(void); +S_FUNC void backspace(void); +S_FUNC void beep(void); +S_FUNC void echo_char(int ch); +S_FUNC void echo_string(char *str, int len); +S_FUNC void savetext(char *str, int len); +S_FUNC void memrcpy(char *dest, char *src, int len); +S_FUNC int read_bindings(FILE *fp); +S_FUNC int in_word(int ch); +S_FUNC KEY_MAP *find_map(char *map); +S_FUNC void unbind_key(KEY_MAP *map, int key); +S_FUNC void raw_bind_key(KEY_MAP *map, int key, + FUNCPTR func, KEY_MAP *next_map); +S_FUNC KEY_MAP *do_map_line(char *line); +S_FUNC void do_default_line(KEY_MAP *map, char *line); +S_FUNC void do_bind_line(KEY_MAP *map, char *line); +S_FUNC void back_over_char(int ch); +S_FUNC void echo_rest_of_line(void); +S_FUNC void goto_start_of_line(void); +S_FUNC void goto_end_of_line(void); +S_FUNC void remove_char(int ch); +S_FUNC void decrement_end(int n); +S_FUNC void insert_string(char *str, int len); /* @@ -263,55 +263,55 @@ S_FUNC void insert_string(char *str, int len); size_t hist_getline(char *prompt, char *buf, size_t len) { - /* - * initialize if we have not already done so - */ - if (!inited) - (void) hist_init(calcbindings); + /* + * initialize if we have not already done so + */ + if (!inited) + (void) hist_init(calcbindings); - /* - * establish the beginning of a line condition - */ - HS.prompt = prompt; - HS.bufsize = len - 2; - HS.buf = buf; - HS.pos = buf; - HS.end = buf; - HS.mark = NULL; - HS.linelen = -1; - HS.virgin_line = true; + /* + * establish the beginning of a line condition + */ + HS.prompt = prompt; + HS.bufsize = len - 2; + HS.buf = buf; + HS.pos = buf; + HS.end = buf; + HS.mark = NULL; + HS.linelen = -1; + HS.virgin_line = true; - /* - * prep the I/O - */ - fputs(prompt, stdout); - fflush(stdout); + /* + * prep the I/O + */ + fputs(prompt, stdout); + fflush(stdout); - /* - * special case: non-interactive editing - */ - if (!canedit) { - if (fgets(buf, len, stdin) == NULL) - return 0; - return strlen(buf); - } + /* + * special case: non-interactive editing + */ + if (!canedit) { + if (fgets(buf, len, stdin) == NULL) + return 0; + return strlen(buf); + } - /* - * get the line - */ - while (HS.linelen < 0) { + /* + * get the line + */ + while (HS.linelen < 0) { - /* get the next char */ - read_key(); + /* get the next char */ + read_key(); - /* chars typed, no longer virgin */ - HS.virgin_line = false; - } + /* chars typed, no longer virgin */ + HS.virgin_line = false; + } - /* - * return the line - */ - return HS.linelen; + /* + * return the line + */ + return HS.linelen; } @@ -328,54 +328,54 @@ hist_getline(char *prompt, char *buf, size_t len) int hist_init(char *filename) { - /* - * prevent multiple initializations - */ - if (inited) { - if (conf->calc_debug & CALCDBG_TTY) - printf("hist_init: inited already set\n"); - return HIST_INITED; - } + /* + * prevent multiple initializations + */ + if (inited) { + if (conf->calc_debug & CALCDBG_TTY) + printf("hist_init: inited already set\n"); + return HIST_INITED; + } - /* - * setup - */ - inited = 1; - canedit = 0; - if (conf->calc_debug & CALCDBG_TTY) - printf("hist_init: Set inited, cleared canedit\n"); + /* + * setup + */ + inited = 1; + canedit = 0; + if (conf->calc_debug & CALCDBG_TTY) + printf("hist_init: Set inited, cleared canedit\n"); - /* - * open the bindings file - */ - if (filename == NULL) - filename = HIST_BINDING_FILE; - if (opensearchfile(filename, calcpath, NULL, false) > 0) - return HIST_NOFILE; + /* + * open the bindings file + */ + if (filename == NULL) + filename = HIST_BINDING_FILE; + if (opensearchfile(filename, calcpath, NULL, false) > 0) + return HIST_NOFILE; - /* - * load the bindings - */ - if (read_bindings(curstream())) - return HIST_NOFILE; + /* + * load the bindings + */ + if (read_bindings(curstream())) + return HIST_NOFILE; - /* - * close the bindings - */ - closeinput(); + /* + * close the bindings + */ + closeinput(); - /* - * setup the calc TTY on STDIN - */ - if (!calc_tty(STDIN)) { - return HIST_NOTTY; - } + /* + * setup the calc TTY on STDIN + */ + if (!calc_tty(STDIN)) { + return HIST_NOTTY; + } - canedit = 1; - if (conf->calc_debug & CALCDBG_TTY) - printf("hist_init: Set canedit\n"); + canedit = 1; + if (conf->calc_debug & CALCDBG_TTY) + printf("hist_init: Set canedit\n"); - return HIST_SUCCESS; + return HIST_SUCCESS; } @@ -385,209 +385,209 @@ hist_init(char *filename) void hist_term(void) { - if (!inited || !canedit) { - if (conf->calc_debug & CALCDBG_TTY) { - if (!inited) - printf("hist_term: inited already cleared\n"); - if (!canedit) - printf("hist_term: canedit already cleared\n"); - } - inited = 0; - if (conf->calc_debug & CALCDBG_TTY) - printf("hist_term: Cleared inited\n"); - return; - } + if (!inited || !canedit) { + if (conf->calc_debug & CALCDBG_TTY) { + if (!inited) + printf("hist_term: inited already cleared\n"); + if (!canedit) + printf("hist_term: canedit already cleared\n"); + } + inited = 0; + if (conf->calc_debug & CALCDBG_TTY) + printf("hist_term: Cleared inited\n"); + return; + } - if (hist_first) { - HIST* hp = hist_first; - HIST* next; - while(hp) { - next = hp->next; - free(hp->data); - free(hp); - hp = next; - } - } - hist_first = NULL; - hist_last = NULL; + if (hist_first) { + HIST* hp = hist_first; + HIST* next; + while(hp) { + next = hp->next; + free(hp->data); + free(hp); + hp = next; + } + } + hist_first = NULL; + hist_last = NULL; - /* - * restore original tty state - */ - (void) orig_tty(STDIN); + /* + * restore original tty state + */ + (void) orig_tty(STDIN); } S_FUNC KEY_MAP * find_map(char *map) { - unsigned int i; + unsigned int i; - for (i = 0; i < sizeof(maps) / sizeof(maps[0]); i++) { - if (strcmp(map, maps[i].name) == 0) - return &maps[i]; - } - return NULL; + for (i = 0; i < sizeof(maps) / sizeof(maps[0]); i++) { + if (strcmp(map, maps[i].name) == 0) + return &maps[i]; + } + return NULL; } S_FUNC void unbind_key(KEY_MAP *map, int key) { - map->map[key] = NULL; + map->map[key] = NULL; } S_FUNC void raw_bind_key(KEY_MAP *map, int key, FUNCPTR func, KEY_MAP *next_map) { - if (map->map[key] == NULL) { - if (key_count >= MAX_KEYS) - return; - map->map[key] = &key_table[key_count++]; - } - map->map[key]->func = func; - map->map[key]->next = next_map; + if (map->map[key] == NULL) { + if (key_count >= MAX_KEYS) + return; + map->map[key] = &key_table[key_count++]; + } + map->map[key]->func = func; + map->map[key]->next = next_map; } S_FUNC KEY_MAP * do_map_line(char *line) { - char *cp; - char *map_name; + char *cp; + char *map_name; - cp = line; - while (isspace((int)*cp)) - cp++; - if (*cp == '\0') - return NULL; - map_name = cp; - while ((*cp != '\0') && !isspace((int)*cp)) - cp++; - *cp = '\0'; - return find_map(map_name); + cp = line; + while (isspace((int)*cp)) + cp++; + if (*cp == '\0') + return NULL; + map_name = cp; + while ((*cp != '\0') && !isspace((int)*cp)) + cp++; + *cp = '\0'; + return find_map(map_name); } S_FUNC void do_bind_line(KEY_MAP *map, char *line) { - char *cp; - char key; - char *func_name; - char *next_name; - KEY_MAP *next; - FUNCPTR func; + char *cp; + char key; + char *func_name; + char *next_name; + KEY_MAP *next; + FUNCPTR func; - if (map == NULL) - return; - cp = line; - key = *cp++; - if (*cp == '\0') { - unbind_key(map, key); - return; - } - if (key == '^') { - if (*cp == '?') { - key = 0177; - cp++; - } else { - key = CONTROL(*cp++); - } - } else if (key == '\\') { - key = *cp++; - } + if (map == NULL) + return; + cp = line; + key = *cp++; + if (*cp == '\0') { + unbind_key(map, key); + return; + } + if (key == '^') { + if (*cp == '?') { + key = 0177; + cp++; + } else { + key = CONTROL(*cp++); + } + } else if (key == '\\') { + key = *cp++; + } - while (isspace((int)*cp)) - cp++; - if (*cp == '\0') { - unbind_key(map, key); - return; - } + while (isspace((int)*cp)) + cp++; + if (*cp == '\0') { + unbind_key(map, key); + return; + } - func_name = cp; - while ((*cp != '\0') && !isspace((int)*cp)) - cp++; - if (*cp) { - *cp++ = '\0'; - while (isspace((int)*cp)) - cp++; - } - func = find_func(func_name); - if (func == NULL) { - fprintf(stderr, "Unknown function \"%s\"\n", func_name); - return; - } + func_name = cp; + while ((*cp != '\0') && !isspace((int)*cp)) + cp++; + if (*cp) { + *cp++ = '\0'; + while (isspace((int)*cp)) + cp++; + } + func = find_func(func_name); + if (func == NULL) { + fprintf(stderr, "Unknown function \"%s\"\n", func_name); + return; + } - if (*cp == '\0') { - next = map->default_ent.next; - if (next == NULL) - next = base_map; - } else { - next_name = cp; - while ((*cp != '\0') && !isspace((int)*cp)) - cp++; - if (*cp) { - *cp++ = '\0'; - while (isspace((int)*cp)) - cp++; - } - next = find_map(next_name); - if (next == NULL) - return; - } - raw_bind_key(map, key, func, next); + if (*cp == '\0') { + next = map->default_ent.next; + if (next == NULL) + next = base_map; + } else { + next_name = cp; + while ((*cp != '\0') && !isspace((int)*cp)) + cp++; + if (*cp) { + *cp++ = '\0'; + while (isspace((int)*cp)) + cp++; + } + next = find_map(next_name); + if (next == NULL) + return; + } + raw_bind_key(map, key, func, next); } S_FUNC void do_default_line(KEY_MAP *map, char *line) { - char *cp; - char *func_name; - char *next_name; - KEY_MAP *next; - FUNCPTR func; + char *cp; + char *func_name; + char *next_name; + KEY_MAP *next; + FUNCPTR func; - if (map == NULL) - return; - cp = line; - while (isspace((int)*cp)) - cp++; - if (*cp == '\0') - return; + if (map == NULL) + return; + cp = line; + while (isspace((int)*cp)) + cp++; + if (*cp == '\0') + return; - func_name = cp; - while ((*cp != '\0') && !isspace((int)*cp)) - cp++; - if (*cp != '\0') { - *cp++ = '\0'; - while (isspace((int)*cp)) - cp++; - } - func = find_func(func_name); - if (func == NULL) - return; + func_name = cp; + while ((*cp != '\0') && !isspace((int)*cp)) + cp++; + if (*cp != '\0') { + *cp++ = '\0'; + while (isspace((int)*cp)) + cp++; + } + func = find_func(func_name); + if (func == NULL) + return; - if (*cp == '\0') { - next = map; - } else { - next_name = cp; - while ((*cp != '\0') && !isspace((int)*cp)) - cp++; - if (*cp != '\0') { - *cp++ = '\0'; - while (isspace((int)*cp)) - cp++; - } - next = find_map(next_name); - if (next == NULL) - return; - } + if (*cp == '\0') { + next = map; + } else { + next_name = cp; + while ((*cp != '\0') && !isspace((int)*cp)) + cp++; + if (*cp != '\0') { + *cp++ = '\0'; + while (isspace((int)*cp)) + cp++; + } + next = find_map(next_name); + if (next == NULL) + return; + } - map->default_ent.func = func; - map->default_ent.next = next; + map->default_ent.func = func; + map->default_ent.next = next; } @@ -599,64 +599,64 @@ do_default_line(KEY_MAP *map, char *line) S_FUNC int read_bindings(FILE *fp) { - char *cp; - KEY_MAP *input_map; - char line[BUFSIZ+1]; + char *cp; + KEY_MAP *input_map; + char line[BUFSIZ+1]; - base_map = find_map(base_map_name); - cur_map = base_map; - input_map = base_map; + base_map = find_map(base_map_name); + cur_map = base_map; + input_map = base_map; - if (fp == NULL) - return 1; + if (fp == NULL) + return 1; - while (fgets(line, sizeof(line) - 1, fp)) { - line[BUFSIZ] = '\0'; - cp = line; - while (isspace((int)*cp)) - cp++; + while (fgets(line, sizeof(line) - 1, fp)) { + line[BUFSIZ] = '\0'; + cp = line; + while (isspace((int)*cp)) + cp++; - if ((*cp == '\0') || (*cp == '#') || (*cp == '\n')) - continue; + if ((*cp == '\0') || (*cp == '#') || (*cp == '\n')) + continue; - if (cp[strlen(cp) - 1] == '\n') - cp[strlen(cp) - 1] = '\0'; + if (cp[strlen(cp) - 1] == '\n') + cp[strlen(cp) - 1] = '\0'; - if (memcmp(cp, "map", 3) == 0) - input_map = do_map_line(&cp[3]); - else if (memcmp(cp, "default", 7) == 0) - do_default_line(input_map, &cp[7]); - else - do_bind_line(input_map, cp); - } - return 0; + if (memcmp(cp, "map", 3) == 0) + input_map = do_map_line(&cp[3]); + else if (memcmp(cp, "default", 7) == 0) + do_default_line(input_map, &cp[7]); + else + do_bind_line(input_map, cp); + } + return 0; } S_FUNC void read_key(void) { - KEY_ENT *ent; - int key; + KEY_ENT *ent; + int key; - fflush(stdout); - key = fgetc(stdin); - if (key == EOF) { - HS.linelen = 0; - HS.buf[0] = '\0'; - return; - } + fflush(stdout); + key = fgetc(stdin); + if (key == EOF) { + HS.linelen = 0; + HS.buf[0] = '\0'; + return; + } - ent = cur_map->map[key]; - if (ent == NULL) - ent = &cur_map->default_ent; - if (ent->next) - cur_map = ent->next; - if (ent->func != NULL) { - (*ent->func)(key); - } else { - insert_char(key); - } + ent = cur_map->map[key]; + if (ent == NULL) + ent = &cur_map->default_ent; + if (ent->next) + cur_map = ent->next; + if (ent->func != NULL) { + (*ent->func)(key); + } else { + insert_char(key); + } } @@ -667,18 +667,18 @@ read_key(void) S_FUNC HIST * get_event(int n) { - register HIST * hp = hist_first; - int i = 0; + register HIST * hp = hist_first; + int i = 0; - do { - if(!hp) - break; - if(i == n) - return hp; - ++i; - hp = hp->next; - } while(hp); - return NULL; + do { + if(!hp) + break; + if(i == n) + return hp; + ++i; + hp = hp->next; + } while(hp); + return NULL; } @@ -689,13 +689,13 @@ get_event(int n) S_FUNC HIST * find_event(char *pat, int len) { - register HIST * hp = hist_first; + register HIST * hp = hist_first; - for(hp = hist_first; hp != NULL; hp = hp->next) { - if ((hp->len == len) && (memcmp(hp->data, pat, len) == 0)) - return hp; - } - return NULL; + for(hp = hist_first; hp != NULL; hp = hp->next) { + if ((hp->len == len) && (memcmp(hp->data, pat, len) == 0)) + return hp; + } + return NULL; } @@ -708,76 +708,76 @@ find_event(char *pat, int len) void hist_saveline(char *line, int len) { - HIST * hp; + HIST * hp; - if ((len > 0) && (line[len - 1] == '\n')) - len--; - if (len <= 0) - return; + if ((len > 0) && (line[len - 1] == '\n')) + len--; + if (len <= 0) + return; - /* - * See if the line is already present in the history table. - * If so, and it is already at the end, then we are all done. - * Otherwise delete it since we will reinsert it at the end. - */ - hp = find_event(line, len); - if (hp) { - if (hp == hist_last) - return; - if (hp->prev) - hp->prev->next = hp->next; - hp->next->prev = hp->prev; + /* + * See if the line is already present in the history table. + * If so, and it is already at the end, then we are all done. + * Otherwise delete it since we will reinsert it at the end. + */ + hp = find_event(line, len); + if (hp) { + if (hp == hist_last) + return; + if (hp->prev) + hp->prev->next = hp->next; + hp->next->prev = hp->prev; - hist_last->next = hp; - hp->next = NULL; - hp->prev = hist_last; - hist_last = hp; - return; - } + hist_last->next = hp; + hp->next = NULL; + hp->prev = hist_last; + hist_last = hp; + return; + } - /* - * If there is not enough room left in the history buffer to add - * the new command, then repeatedly delete the earliest command - * as many times as necessary in order to make enough room. - */ - if (HS.histcount >= HIST_SIZE) { - HIST *new_first = hist_first->next; - free(hist_first->data); - free(hist_first); - new_first->prev = NULL; - hist_first = new_first; - HS.histcount--; - } + /* + * If there is not enough room left in the history buffer to add + * the new command, then repeatedly delete the earliest command + * as many times as necessary in order to make enough room. + */ + if (HS.histcount >= HIST_SIZE) { + HIST *new_first = hist_first->next; + free(hist_first->data); + free(hist_first); + new_first->prev = NULL; + hist_first = new_first; + HS.histcount--; + } - /* - * Add the line to the end of the history table. - */ - hp = malloc(sizeof(HIST)); - if (hp == NULL) { - fprintf(stderr, - "Out of memory adding line to the history table #0\n"); - return; - } - hp->next = NULL; - hp->prev = NULL; - hp->len = len; - hp->data = malloc(len); - if (hp->data == NULL) { - fprintf(stderr, - "Out of memory adding line to the history table #1\n"); - return; - } - memcpy(hp->data, line, len); - HS.curhist = ++HS.histcount; - if (!hist_first) - hist_first = hp; - if (!hist_last) - hist_last = hp; - else { - hist_last->next = hp; - hp->prev = hist_last; - hist_last = hp; - } + /* + * Add the line to the end of the history table. + */ + hp = malloc(sizeof(HIST)); + if (hp == NULL) { + fprintf(stderr, + "Out of memory adding line to the history table #0\n"); + return; + } + hp->next = NULL; + hp->prev = NULL; + hp->len = len; + hp->data = malloc(len); + if (hp->data == NULL) { + fprintf(stderr, + "Out of memory adding line to the history table #1\n"); + return; + } + memcpy(hp->data, line, len); + HS.curhist = ++HS.histcount; + if (!hist_first) + hist_first = hp; + if (!hist_last) + hist_last = hp; + else { + hist_last->next = hp; + hp->prev = hist_last; + hist_last = hp; + } } @@ -787,83 +787,83 @@ hist_saveline(char *line, int len) S_FUNC FUNCPTR find_func(char *name) { - FUNC *fp; + FUNC *fp; - for (fp = funcs; fp->name; fp++) { - if (strcmp(fp->name, name) == 0) - return fp->func; - } - return NULL; + for (fp = funcs; fp->name; fp++) { + if (strcmp(fp->name, name) == 0) + return fp->func; + } + return NULL; } S_FUNC void arrow_key(int UNUSED(key)) { - switch (fgetc(stdin)) { - case 'A': - backward_history(0); - break; - case 'B': - forward_history(0); - break; - case 'C': - forward_char(0); - break; - case 'D': - backward_char(0); - break; - } + switch (fgetc(stdin)) { + case 'A': + backward_history(0); + break; + case 'B': + forward_history(0); + break; + case 'C': + forward_char(0); + break; + case 'D': + backward_char(0); + break; + } } S_FUNC void back_over_char(int ch) { - backspace(); - if (!isprint(ch)) - backspace(); + backspace(); + if (!isprint(ch)) + backspace(); } S_FUNC void remove_char(int ch) { - erasechar(); - if (!isprint(ch)) - erasechar(); + erasechar(); + if (!isprint(ch)) + erasechar(); } S_FUNC void echo_rest_of_line(void) { - echo_string(HS.pos, HS.end - HS.pos); + echo_string(HS.pos, HS.end - HS.pos); } S_FUNC void goto_start_of_line(void) { - while (HS.pos > HS.buf) - back_over_char((int)(*--HS.pos)); + while (HS.pos > HS.buf) + back_over_char((int)(*--HS.pos)); } S_FUNC void goto_end_of_line(void) { - echo_rest_of_line(); - HS.pos = HS.end; + echo_rest_of_line(); + HS.pos = HS.end; } S_FUNC void decrement_end(int n) { - HS.end -= n; - if (HS.mark && (HS.mark > HS.end)) - HS.mark = NULL; + HS.end -= n; + if (HS.mark && (HS.mark > HS.end)) + HS.mark = NULL; } @@ -876,184 +876,184 @@ ignore_char(int UNUSED(key)) S_FUNC void flush_input(int UNUSED(key)) { - echo_rest_of_line(); - while (HS.end > HS.buf) - remove_char((int)(*--HS.end)); - HS.pos = HS.buf; - HS.mark = NULL; + echo_rest_of_line(); + while (HS.end > HS.buf) + remove_char((int)(*--HS.end)); + HS.pos = HS.buf; + HS.mark = NULL; } S_FUNC void start_of_line(int UNUSED(key)) { - goto_start_of_line(); + goto_start_of_line(); } S_FUNC void end_of_line(int UNUSED(key)) { - goto_end_of_line(); + goto_end_of_line(); } S_FUNC void forward_char(int UNUSED(key)) { - if (HS.pos < HS.end) - echo_char(*HS.pos++); + if (HS.pos < HS.end) + echo_char(*HS.pos++); } S_FUNC void backward_char(int UNUSED(key)) { - if (HS.pos > HS.buf) - back_over_char((int)(*--HS.pos)); + if (HS.pos > HS.buf) + back_over_char((int)(*--HS.pos)); } S_FUNC void uppercase_word(int UNUSED(key)) { - while ((HS.pos < HS.end) && !in_word((int)(*HS.pos))) - echo_char(*HS.pos++); - while ((HS.pos < HS.end) && in_word((int)(*HS.pos))) { - if ((*HS.pos >= 'a') && (*HS.pos <= 'z')) - *HS.pos += 'A' - 'a'; - echo_char(*HS.pos++); - } + while ((HS.pos < HS.end) && !in_word((int)(*HS.pos))) + echo_char(*HS.pos++); + while ((HS.pos < HS.end) && in_word((int)(*HS.pos))) { + if ((*HS.pos >= 'a') && (*HS.pos <= 'z')) + *HS.pos += 'A' - 'a'; + echo_char(*HS.pos++); + } } S_FUNC void lowercase_word(int UNUSED(key)) { - while ((HS.pos < HS.end) && !in_word((int)(*HS.pos))) - echo_char(*HS.pos++); - while ((HS.pos < HS.end) && in_word((int)(*HS.pos))) { - if ((*HS.pos >= 'A') && (*HS.pos <= 'Z')) - *HS.pos += 'a' - 'A'; - echo_char(*HS.pos++); - } + while ((HS.pos < HS.end) && !in_word((int)(*HS.pos))) + echo_char(*HS.pos++); + while ((HS.pos < HS.end) && in_word((int)(*HS.pos))) { + if ((*HS.pos >= 'A') && (*HS.pos <= 'Z')) + *HS.pos += 'a' - 'A'; + echo_char(*HS.pos++); + } } S_FUNC void forward_word(int UNUSED(key)) { - while ((HS.pos < HS.end) && !in_word((int)(*HS.pos))) - echo_char(*HS.pos++); - while ((HS.pos < HS.end) && in_word((int)(*HS.pos))) - echo_char(*HS.pos++); + while ((HS.pos < HS.end) && !in_word((int)(*HS.pos))) + echo_char(*HS.pos++); + while ((HS.pos < HS.end) && in_word((int)(*HS.pos))) + echo_char(*HS.pos++); } S_FUNC void backward_word(int UNUSED(key)) { - if ((HS.pos > HS.buf) && in_word((int)(*HS.pos))) - back_over_char((int)(*--HS.pos)); - while ((HS.pos > HS.buf) && !in_word((int)(*HS.pos))) - back_over_char((int)(*--HS.pos)); - while ((HS.pos > HS.buf) && in_word((int)(*HS.pos))) - back_over_char((int)(*--HS.pos)); - if ((HS.pos < HS.end) && !in_word((int)(*HS.pos))) - echo_char(*HS.pos++); + if ((HS.pos > HS.buf) && in_word((int)(*HS.pos))) + back_over_char((int)(*--HS.pos)); + while ((HS.pos > HS.buf) && !in_word((int)(*HS.pos))) + back_over_char((int)(*--HS.pos)); + while ((HS.pos > HS.buf) && in_word((int)(*HS.pos))) + back_over_char((int)(*--HS.pos)); + if ((HS.pos < HS.end) && !in_word((int)(*HS.pos))) + echo_char(*HS.pos++); } S_FUNC void forward_kill_char(int UNUSED(key)) { - int rest; - char ch; + int rest; + char ch; - rest = HS.end - HS.pos; - if (rest-- <= 0) - return; - ch = *HS.pos; - if (rest > 0) { - memcpy(HS.pos, HS.pos + 1, rest); - *(HS.end - 1) = ch; - } - echo_rest_of_line(); - remove_char((int)ch); - decrement_end(1); - while (rest > 0) - back_over_char((int)(HS.pos[--rest])); + rest = HS.end - HS.pos; + if (rest-- <= 0) + return; + ch = *HS.pos; + if (rest > 0) { + memcpy(HS.pos, HS.pos + 1, rest); + *(HS.end - 1) = ch; + } + echo_rest_of_line(); + remove_char((int)ch); + decrement_end(1); + while (rest > 0) + back_over_char((int)(HS.pos[--rest])); } S_FUNC void delete_char(int UNUSED(key)) { - /* - * quit delete_char (usually ^D) is at start of line and we are allowed - * - * We exit of start of line and config("ctrl_d", "empty") or - * if config("ctrl_d", "virgin") and we have never typed on the line. - */ - if ((HS.end == HS.buf) && - (conf->ctrl_d == CTRL_D_EMPTY_EOF || - (conf->ctrl_d == CTRL_D_VIRGIN_EOF && HS.virgin_line == true))) { - quit_calc(0); - } + /* + * quit delete_char (usually ^D) is at start of line and we are allowed + * + * We exit of start of line and config("ctrl_d", "empty") or + * if config("ctrl_d", "virgin") and we have never typed on the line. + */ + if ((HS.end == HS.buf) && + (conf->ctrl_d == CTRL_D_EMPTY_EOF || + (conf->ctrl_d == CTRL_D_VIRGIN_EOF && HS.virgin_line == true))) { + quit_calc(0); + } - /* - * normal case: just forward_kill_char - */ - if (HS.end > HS.buf) - forward_kill_char(0); + /* + * normal case: just forward_kill_char + */ + if (HS.end > HS.buf) + forward_kill_char(0); } S_FUNC void backward_kill_char(int UNUSED(key)) { - if (HS.pos > HS.buf) { - HS.pos--; - back_over_char((int)(*HS.pos)); - forward_kill_char(0); - } + if (HS.pos > HS.buf) { + HS.pos--; + back_over_char((int)(*HS.pos)); + forward_kill_char(0); + } } S_FUNC void forward_kill_word(int UNUSED(key)) { - char *cp; + char *cp; - if (HS.pos >= HS.end) - return; - echo_rest_of_line(); - for (cp = HS.end; cp > HS.pos;) - remove_char((int)(*--cp)); - cp = HS.pos; - while ((cp < HS.end) && !in_word((int)(*cp))) - cp++; - while ((cp < HS.end) && in_word((int)(*cp))) - cp++; - savetext(HS.pos, cp - HS.pos); - memcpy(HS.pos, cp, HS.end - cp); - decrement_end(cp - HS.pos); - echo_rest_of_line(); - for (cp = HS.end; cp > HS.pos;) - back_over_char((int)(*--cp)); + if (HS.pos >= HS.end) + return; + echo_rest_of_line(); + for (cp = HS.end; cp > HS.pos;) + remove_char((int)(*--cp)); + cp = HS.pos; + while ((cp < HS.end) && !in_word((int)(*cp))) + cp++; + while ((cp < HS.end) && in_word((int)(*cp))) + cp++; + savetext(HS.pos, cp - HS.pos); + memcpy(HS.pos, cp, HS.end - cp); + decrement_end(cp - HS.pos); + echo_rest_of_line(); + for (cp = HS.end; cp > HS.pos;) + back_over_char((int)(*--cp)); } S_FUNC void kill_line(int UNUSED(key)) { - if (HS.end <= HS.pos) - return; - savetext(HS.pos, HS.end - HS.pos); - echo_rest_of_line(); - while (HS.end > HS.pos) - remove_char((int)(*--HS.end)); - decrement_end(0); + if (HS.end <= HS.pos) + return; + savetext(HS.pos, HS.end - HS.pos); + echo_rest_of_line(); + while (HS.end > HS.pos) + remove_char((int)(*--HS.end)); + decrement_end(0); } @@ -1066,303 +1066,303 @@ kill_line(int UNUSED(key)) S_FUNC void new_line(int UNUSED(key)) { - int len; + int len; - newline(); - fflush(stdout); + newline(); + fflush(stdout); - HS.mark = NULL; - HS.end[0] = '\n'; - HS.end[1] = '\0'; - len = HS.end - HS.buf + 1; - if (len <= 1) { - HS.curhist = HS.histcount; - HS.linelen = 1; - return; - } - HS.curhist = HS.histcount; - HS.pos = HS.buf; - HS.end = HS.buf; - HS.linelen = len; + HS.mark = NULL; + HS.end[0] = '\n'; + HS.end[1] = '\0'; + len = HS.end - HS.buf + 1; + if (len <= 1) { + HS.curhist = HS.histcount; + HS.linelen = 1; + return; + } + HS.curhist = HS.histcount; + HS.pos = HS.buf; + HS.end = HS.buf; + HS.linelen = len; } S_FUNC void save_line(int UNUSED(key)) { - int len; + int len; - len = HS.end - HS.buf; - if (len > 0) { - hist_saveline(HS.buf, len); - flush_input(0); - } - HS.curhist = HS.histcount; + len = HS.end - HS.buf; + if (len > 0) { + hist_saveline(HS.buf, len); + flush_input(0); + } + HS.curhist = HS.histcount; } S_FUNC void goto_line(int UNUSED(key)) { - int num; - char *cp; - HIST *hp; + int num; + char *cp; + HIST *hp; - num = 0; - cp = HS.buf; - while ((*cp >= '0') && (*cp <= '9') && (cp < HS.pos)) - num = num * 10 + (*cp++ - '0'); - if ((num <= 0) || (num > HS.histcount) || (cp != HS.pos)) { - beep(); - return; - } - flush_input(0); - HS.curhist = HS.histcount - num; - hp = get_event(HS.curhist); - memcpy(HS.buf, hp->data, hp->len); - HS.end = &HS.buf[hp->len]; - goto_end_of_line(); + num = 0; + cp = HS.buf; + while ((*cp >= '0') && (*cp <= '9') && (cp < HS.pos)) + num = num * 10 + (*cp++ - '0'); + if ((num <= 0) || (num > HS.histcount) || (cp != HS.pos)) { + beep(); + return; + } + flush_input(0); + HS.curhist = HS.histcount - num; + hp = get_event(HS.curhist); + memcpy(HS.buf, hp->data, hp->len); + HS.end = &HS.buf[hp->len]; + goto_end_of_line(); } S_FUNC void forward_history(int UNUSED(key)) { - HIST *hp; + HIST *hp; - flush_input(0); - if (++HS.curhist >= HS.histcount) - HS.curhist = 0; - hp = get_event(HS.curhist); - if (hp) { - memcpy(HS.buf, hp->data, hp->len); - HS.end = &HS.buf[hp->len]; - } - goto_end_of_line(); + flush_input(0); + if (++HS.curhist >= HS.histcount) + HS.curhist = 0; + hp = get_event(HS.curhist); + if (hp) { + memcpy(HS.buf, hp->data, hp->len); + HS.end = &HS.buf[hp->len]; + } + goto_end_of_line(); } S_FUNC void backward_history(int UNUSED(key)) { - HIST *hp; + HIST *hp; - flush_input(0); - if (--HS.curhist < 0) - HS.curhist = HS.histcount - 1; - hp = get_event(HS.curhist); - if (hp) { - memcpy(HS.buf, hp->data, hp->len); - HS.end = &HS.buf[hp->len]; - } - goto_end_of_line(); + flush_input(0); + if (--HS.curhist < 0) + HS.curhist = HS.histcount - 1; + hp = get_event(HS.curhist); + if (hp) { + memcpy(HS.buf, hp->data, hp->len); + HS.end = &HS.buf[hp->len]; + } + goto_end_of_line(); } S_FUNC void insert_char(int key) { - int len; - int rest; + int len; + int rest; - len = HS.end - HS.buf; - if (len >= HS.bufsize) { - beep(); - return; - } - rest = HS.end - HS.pos; - if (rest > 0) - memrcpy(HS.pos + 1, HS.pos, rest); - HS.end++; - *HS.pos++ = key; - echo_char(key); - echo_rest_of_line(); - while (rest > 0) - back_over_char((int)(HS.pos[--rest])); + len = HS.end - HS.buf; + if (len >= HS.bufsize) { + beep(); + return; + } + rest = HS.end - HS.pos; + if (rest > 0) + memrcpy(HS.pos + 1, HS.pos, rest); + HS.end++; + *HS.pos++ = key; + echo_char(key); + echo_rest_of_line(); + while (rest > 0) + back_over_char((int)(HS.pos[--rest])); } S_FUNC void insert_string(char *str, int len) { - int rest; - int totallen; + int rest; + int totallen; - if (len <= 0) - return; - totallen = (HS.end - HS.buf) + len; - if (totallen > HS.bufsize) { - beep(); - return; - } - rest = HS.end - HS.pos; - if (rest > 0) - memrcpy(HS.pos + len, HS.pos, rest); - HS.end += len; - memcpy(HS.pos, str, len); - HS.pos += len; - echo_string(str, len); - echo_rest_of_line(); - while (rest > 0) - back_over_char((int)(HS.pos[--rest])); + if (len <= 0) + return; + totallen = (HS.end - HS.buf) + len; + if (totallen > HS.bufsize) { + beep(); + return; + } + rest = HS.end - HS.pos; + if (rest > 0) + memrcpy(HS.pos + len, HS.pos, rest); + HS.end += len; + memcpy(HS.pos, str, len); + HS.pos += len; + echo_string(str, len); + echo_rest_of_line(); + while (rest > 0) + back_over_char((int)(HS.pos[--rest])); } S_FUNC void list_history(int UNUSED(key)) { - HIST *hp; - int hnum; + HIST *hp; + int hnum; - for (hnum = 0; hnum < HS.histcount; hnum++) { - hp = get_event(hnum); - printf("\n%3d: ", HS.histcount - hnum); - echo_string(hp->data, hp->len); - } - refresh_line(0); + for (hnum = 0; hnum < HS.histcount; hnum++) { + hp = get_event(hnum); + printf("\n%3d: ", HS.histcount - hnum); + echo_string(hp->data, hp->len); + } + refresh_line(0); } S_FUNC void refresh_line(int UNUSED(key)) { - char *cp; + char *cp; - newline(); - fputs(HS.prompt, stdout); - if (HS.end > HS.buf) { - echo_string(HS.buf, HS.end - HS.buf); - cp = HS.end; - while (cp > HS.pos) - back_over_char((int)(*--cp)); - } + newline(); + fputs(HS.prompt, stdout); + if (HS.end > HS.buf) { + echo_string(HS.buf, HS.end - HS.buf); + cp = HS.end; + while (cp > HS.pos) + back_over_char((int)(*--cp)); + } } S_FUNC void swap_chars(int UNUSED(key)) { - char ch1; - char ch2; + char ch1; + char ch2; - if ((HS.pos <= HS.buf) || (HS.pos >= HS.end)) - return; - ch1 = *HS.pos--; - ch2 = *HS.pos; - *HS.pos++ = ch1; - *HS.pos = ch2; - back_over_char((int)ch2); - echo_char(ch1); - echo_char(ch2); - back_over_char((int)ch2); + if ((HS.pos <= HS.buf) || (HS.pos >= HS.end)) + return; + ch1 = *HS.pos--; + ch2 = *HS.pos; + *HS.pos++ = ch1; + *HS.pos = ch2; + back_over_char((int)ch2); + echo_char(ch1); + echo_char(ch2); + back_over_char((int)ch2); } S_FUNC void set_mark(int UNUSED(key)) { - HS.mark = HS.pos; + HS.mark = HS.pos; } S_FUNC void save_region(int UNUSED(key)) { - int len; + int len; - if (HS.mark == NULL) - return; - len = HS.mark - HS.pos; - if (len > 0) - savetext(HS.pos, len); - if (len < 0) - savetext(HS.mark, -len); + if (HS.mark == NULL) + return; + len = HS.mark - HS.pos; + if (len > 0) + savetext(HS.pos, len); + if (len < 0) + savetext(HS.mark, -len); } S_FUNC void kill_region(int UNUSED(key)) { - char *cp; - char *left; - char *right; + char *cp; + char *left; + char *right; - if ((HS.mark == NULL) || (HS.mark == HS.pos)) - return; + if ((HS.mark == NULL) || (HS.mark == HS.pos)) + return; - echo_rest_of_line(); - if (HS.mark < HS.pos) { - left = HS.mark; - right = HS.pos; - HS.pos = HS.mark; - } else { - left = HS.pos; - right = HS.mark; - HS.mark = HS.pos; - } - savetext(left, right - left); - for (cp = HS.end; cp > left;) - remove_char((int)(*--cp)); - if (right < HS.end) - memcpy(left, right, HS.end - right); - decrement_end(right - left); - echo_rest_of_line(); - for (cp = HS.end; cp > HS.pos;) - back_over_char((int)(*--cp)); + echo_rest_of_line(); + if (HS.mark < HS.pos) { + left = HS.mark; + right = HS.pos; + HS.pos = HS.mark; + } else { + left = HS.pos; + right = HS.mark; + HS.mark = HS.pos; + } + savetext(left, right - left); + for (cp = HS.end; cp > left;) + remove_char((int)(*--cp)); + if (right < HS.end) + memcpy(left, right, HS.end - right); + decrement_end(right - left); + echo_rest_of_line(); + for (cp = HS.end; cp > HS.pos;) + back_over_char((int)(*--cp)); } S_FUNC void yank(int UNUSED(key)) { - insert_string(save_buffer, save_len); + insert_string(save_buffer, save_len); } S_FUNC void reverse_search(int UNUSED(key)) { - int len; - int count; - int testhist; - HIST *hp; - char *save_pos; + int len; + int count; + int testhist; + HIST *hp; + char *save_pos; - count = HS.histcount; - len = HS.pos - HS.buf; - if (len <= 0) - count = 0; - testhist = HS.curhist; - do { - if (--count < 0) { - beep(); - return; - } - if (--testhist < 0) - testhist = HS.histcount - 1; - hp = get_event(testhist); - } while ((hp == NULL) || (hp->len < len) || - memcmp(hp->data, HS.buf, len)); + count = HS.histcount; + len = HS.pos - HS.buf; + if (len <= 0) + count = 0; + testhist = HS.curhist; + do { + if (--count < 0) { + beep(); + return; + } + if (--testhist < 0) + testhist = HS.histcount - 1; + hp = get_event(testhist); + } while ((hp == NULL) || (hp->len < len) || + memcmp(hp->data, HS.buf, len)); - HS.curhist = testhist; - save_pos = HS.pos; - flush_input(0); - memcpy(HS.buf, hp->data, hp->len); - HS.end = &HS.buf[hp->len]; - goto_end_of_line(); - while (HS.pos > save_pos) - back_over_char((int)(*--HS.pos)); + HS.curhist = testhist; + save_pos = HS.pos; + flush_input(0); + memcpy(HS.buf, hp->data, hp->len); + HS.end = &HS.buf[hp->len]; + goto_end_of_line(); + while (HS.pos > save_pos) + back_over_char((int)(*--HS.pos)); } S_FUNC void quote_char(int UNUSED(key)) { - int ch; + int ch; - ch = fgetc(stdin); - if (ch != EOF) - insert_char(ch); + ch = fgetc(stdin); + if (ch != EOF) + insert_char(ch); } @@ -1372,13 +1372,13 @@ quote_char(int UNUSED(key)) S_FUNC void savetext(char *str, int len) { - save_len = 0; - if (len <= 0) - return; - if (len > SAVE_SIZE) - len = SAVE_SIZE; - memcpy(save_buffer, str, len); - save_len = len; + save_len = 0; + if (len <= 0) + return; + if (len > SAVE_SIZE) + len = SAVE_SIZE; + memcpy(save_buffer, str, len); + save_len = len; } @@ -1388,65 +1388,65 @@ savetext(char *str, int len) S_FUNC int in_word(int ch) { - return (isalnum(ch) || (ch == '_')); + return (isalnum(ch) || (ch == '_')); } S_FUNC void erasechar(void) { - fputs("\b \b", stdout); + fputs("\b \b", stdout); } S_FUNC void newline(void) { - fputc('\n', stdout); + fputc('\n', stdout); } S_FUNC void backspace(void) { - fputc('\b', stdout); + fputc('\b', stdout); } S_FUNC void beep(void) { - fputc('\007', stdout); + fputc('\007', stdout); } S_FUNC void echo_char(int ch) { - if (isprint(ch)) { - putchar(ch); - } else { - putchar('^'); - putchar((ch + '@') & 0x7f); - } + if (isprint(ch)) { + putchar(ch); + } else { + putchar('^'); + putchar((ch + '@') & 0x7f); + } } S_FUNC void echo_string(char *str, int len) { - while (len-- > 0) - echo_char(*str++); + while (len-- > 0) + echo_char(*str++); } S_FUNC void memrcpy(char *dest, char *src, int len) { - dest += len - 1; - src += len - 1; - while (len-- > 0) - *dest-- = *src--; + dest += len - 1; + src += len - 1; + while (len-- > 0) + *dest-- = *src--; } #endif /* !USE_READLINE */ @@ -1454,16 +1454,16 @@ memrcpy(char *dest, char *src, int len) S_FUNC void quit_calc(int UNUSED(ch)) { - hist_term(); - putchar('\n'); - libcalc_call_me_last(); - exit(0); + hist_term(); + putchar('\n'); + libcalc_call_me_last(); + exit(0); } #if defined(USE_READLINE) -#define HISTORY_LEN (1024) /* number of entries to save */ +#define HISTORY_LEN (1024) /* number of entries to save */ #include @@ -1488,55 +1488,55 @@ quit_calc(int UNUSED(ch)) size_t hist_getline(char *prompt, char *buf, size_t len) { - STATIC char *rlbuf, *rlcur; + STATIC char *rlbuf, *rlcur; - if (!rlbuf) { - rlbuf = rlcur = readline(prompt); - if (!rlbuf) { - buf[0] = '\0'; - switch (conf->ctrl_d) { - case CTRL_D_NEVER_EOF: - return 0; - case CTRL_D_VIRGIN_EOF: - case CTRL_D_EMPTY_EOF: - default: - quit_calc(0); - not_reached(); - } - } - } + if (!rlbuf) { + rlbuf = rlcur = readline(prompt); + if (!rlbuf) { + buf[0] = '\0'; + switch (conf->ctrl_d) { + case CTRL_D_NEVER_EOF: + return 0; + case CTRL_D_VIRGIN_EOF: + case CTRL_D_EMPTY_EOF: + default: + quit_calc(0); + not_reached(); + } + } + } - /* eol: pointer to trailing newline (if there is one) or \0 */ - char *eol = strchr(rlcur, '\n'); - if (!eol) { - eol = rlcur + strlen(rlcur); - } - /* len: length of line in target buffer including (possibly added) - * newline, truncated if buffer is too small. Note that we reduce - * the available buffer size by 1 so that we can safely add the - * newline below. - */ - len = MIN(len - 1, (size_t)(eol - rlcur + 1)); - strlcpy(buf, rlcur, len); - /* make sure we have a newline and NUL */ - buf[len - 1] = '\n'; - buf[len] = '\0'; + /* eol: pointer to trailing newline (if there is one) or \0 */ + char *eol = strchr(rlcur, '\n'); + if (!eol) { + eol = rlcur + strlen(rlcur); + } + /* len: length of line in target buffer including (possibly added) + * newline, truncated if buffer is too small. Note that we reduce + * the available buffer size by 1 so that we can safely add the + * newline below. + */ + len = MIN(len - 1, (size_t)(eol - rlcur + 1)); + strlcpy(buf, rlcur, len); + /* make sure we have a newline and NUL */ + buf[len - 1] = '\n'; + buf[len] = '\0'; - /* skip over newline in readline buffer */ - if (*eol) { - eol++; - } - /* prepare for next invocation: point to next line or free readline - * buffer if we've reached EOL - */ - if (*eol) { - rlcur = eol; - } else { - free(rlbuf); - rlbuf = rlcur = NULL; - } + /* skip over newline in readline buffer */ + if (*eol) { + eol++; + } + /* prepare for next invocation: point to next line or free readline + * buffer if we've reached EOL + */ + if (*eol) { + rlcur = eol; + } else { + free(rlbuf); + rlbuf = rlcur = NULL; + } - return len; + return len; } @@ -1549,56 +1549,56 @@ hist_term(void) S_FUNC void my_stifle_history (void) { - /* only save last number of entries */ - stifle_history(HISTORY_LEN); + /* only save last number of entries */ + stifle_history(HISTORY_LEN); - if (calc_history) - write_history(calc_history); + if (calc_history) + write_history(calc_history); } int hist_init(char *UNUSED(filename)) { - /* used when parsing conditionals in ~/.inputrc */ - rl_readline_name = "calc"; + /* used when parsing conditionals in ~/.inputrc */ + rl_readline_name = "calc"; - /* initialize interactive variables */ - using_history(); + /* initialize interactive variables */ + using_history(); - /* name of history file */ - if (calc_history == NULL) { - calc_history = tilde_expand("~/.calc_history"); - } + /* name of history file */ + if (calc_history == NULL) { + calc_history = tilde_expand("~/.calc_history"); + } - /* read previous history */ - read_history(calc_history); + /* read previous history */ + read_history(calc_history); - atexit(my_stifle_history); + atexit(my_stifle_history); - return HIST_SUCCESS; + return HIST_SUCCESS; } void hist_saveline(char *line, int len) { - STATIC char *prev = NULL; + STATIC char *prev = NULL; - if (len <= 1) - return; + if (len <= 1) + return; - /* ignore if identical with previous line */ - if (prev != NULL && strcmp(prev, line) == 0) - return; + /* ignore if identical with previous line */ + if (prev != NULL && strcmp(prev, line) == 0) + return; - free(prev); + free(prev); - /* fail silently */ - prev = strdup(line); + /* fail silently */ + prev = strdup(line); - line[len - 1] = '\0'; - add_history(line); - line[len - 1] = '\n'; + line[len - 1] = '\0'; + add_history(line); + line[len - 1] = '\n'; } @@ -1613,38 +1613,38 @@ hist_saveline(char *line, int len) int main(int argc, char **argv) { - char *filename; - int len; - char buf[BUFSIZ+1]; + char *filename; + int len; + char buf[BUFSIZ+1]; - filename = NULL; - if (argc > 1) - filename = argv[1]; + filename = NULL; + if (argc > 1) + filename = argv[1]; - switch (hist_init(filename)) { - case HIST_SUCCESS: - break; - case HIST_NOFILE: - fprintf(stderr, "Binding file was not found\n"); - break; - case HIST_NOTTY: - fprintf(stderr, "Cannot set terminal parameters\n"); - break; - case HIST_INITED: - fprintf(stderr, "Hist is already inited\n"); - break; - default: - fprintf(stderr, "Unknown error from hist_init\n"); - break; - } + switch (hist_init(filename)) { + case HIST_SUCCESS: + break; + case HIST_NOFILE: + fprintf(stderr, "Binding file was not found\n"); + break; + case HIST_NOTTY: + fprintf(stderr, "Cannot set terminal parameters\n"); + break; + case HIST_INITED: + fprintf(stderr, "Hist is already inited\n"); + break; + default: + fprintf(stderr, "Unknown error from hist_init\n"); + break; + } - do { - len = hist_getline("HIST> ", buf, sizeof(buf)); - hist_saveline(buf, len); - } while (len && (buf[0] != 'q')); + do { + len = hist_getline("HIST> ", buf, sizeof(buf)); + hist_saveline(buf, len); + } while (len && (buf[0] != 'q')); - hist_term(); - exit(0); + hist_term(); + exit(0); } #endif /* HIST_TEST */ diff --git a/hist.h b/hist.h index 7965513..7e7c855 100644 --- a/hist.h +++ b/hist.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1993/05/02 20:09:20 - * File existed as early as: 1993 + * Under source code control: 1993/05/02 20:09:20 + * File existed as early as: 1993 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -32,24 +32,24 @@ * Default binding file and history size. */ #ifndef HIST_BINDING_FILE -#define HIST_BINDING_FILE "/usr/lib/hist.bind" +#define HIST_BINDING_FILE "/usr/lib/hist.bind" #endif #ifndef HIST_SIZE -#define HIST_SIZE (1024*32) +#define HIST_SIZE (1024*32) #endif /* * path search defines */ -#define HOMECHAR '~' /* char which indicates home directory */ -#define DOTCHAR '.' /* char which indicates current directory */ -#define PATHCHAR '/' /* char which separates path components */ +#define HOMECHAR '~' /* char which indicates home directory */ +#define DOTCHAR '.' /* char which indicates current directory */ +#define PATHCHAR '/' /* char which separates path components */ #if defined(_WIN32) || defined(_WIN64) -#define LISTCHAR ';' /* char which separates paths in a list */ +#define LISTCHAR ';' /* char which separates paths in a list */ #else -#define LISTCHAR ':' /* char which separates paths in a list */ +#define LISTCHAR ':' /* char which separates paths in a list */ #endif @@ -58,16 +58,16 @@ * not prevent calling the other routines, but fancy command line editing * is then disabled. */ -#define HIST_SUCCESS 0 /* successfully initialized */ -#define HIST_INITED 1 /* initialization is already done */ -#define HIST_NOFILE 2 /* bindings file could not be read */ -#define HIST_NOTTY 3 /* terminal modes could not be set */ +#define HIST_SUCCESS 0 /* successfully initialized */ +#define HIST_INITED 1 /* initialization is already done */ +#define HIST_NOFILE 2 /* bindings file could not be read */ +#define HIST_NOTTY 3 /* terminal modes could not be set */ -E_FUNC int hist_init(char *filename); -E_FUNC void hist_term(void); -E_FUNC size_t hist_getline(char *prompt, char *buf, size_t len); -E_FUNC void hist_saveline(char *line, int len); +E_FUNC int hist_init(char *filename); +E_FUNC void hist_term(void); +E_FUNC size_t hist_getline(char *prompt, char *buf, size_t len); +E_FUNC void hist_saveline(char *line, int len); #endif /* !INCLUDE_HIST_H */ diff --git a/input.c b/input.c index aa1ca14..9d3e81f 100644 --- a/input.c +++ b/input.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:16 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:16 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -56,54 +56,54 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -EXTERN int stdin_tty; /* TRUE if stdin is a tty */ +EXTERN int stdin_tty; /* TRUE if stdin is a tty */ E_FUNC FILE *f_open(char *name, char *mode); E_FUNC FILE *curstream(void); -#define TTYSIZE 8191 /* reallocation size for terminal buffers */ -#define MAXDEPTH 255 /* maximum depth of input */ -#define IS_READ 1 /* reading normally */ -#define IS_REREAD 2 /* reread current character */ -#define chartoint(ch) ((ch) & 0xff) /* make sure char is not negative */ -#define READSET_ALLOC 8 /* readset to allocate chunk size */ +#define TTYSIZE 8191 /* reallocation size for terminal buffers */ +#define MAXDEPTH 255 /* maximum depth of input */ +#define IS_READ 1 /* reading normally */ +#define IS_REREAD 2 /* reread current character */ +#define chartoint(ch) ((ch) & 0xff) /* make sure char is not negative */ +#define READSET_ALLOC 8 /* readset to allocate chunk size */ typedef struct { - int i_state; /* state (read, reread) */ - int i_char; /* currently read char */ - long i_line; /* line number */ - char *i_cp; /* pointer to string character to be read */ - char *i_str; /* start of string copy to be read, or NULL */ - long i_num; /* number of string characters remaining */ - char *i_ttystr; /* current character of tty line (or NULL) */ - FILE *i_fp; /* current file for input (if not NULL) */ - char *i_name; /* file name if known */ + int i_state; /* state (read, reread) */ + int i_char; /* currently read char */ + long i_line; /* line number */ + char *i_cp; /* pointer to string character to be read */ + char *i_str; /* start of string copy to be read, or NULL */ + long i_num; /* number of string characters remaining */ + char *i_ttystr; /* current character of tty line (or NULL) */ + FILE *i_fp; /* current file for input (if not NULL) */ + char *i_name; /* file name if known */ } INPUT; /* files that calc has read or included */ typedef struct { - int active; /* != 0 => active entry, 0 => unused entry */ - char *name; /* name used to read file */ - char *path; /* real path used to open file */ - struct stat inode; /* inode information for file */ + int active; /* != 0 => active entry, 0 => unused entry */ + char *name; /* name used to read file */ + char *path; /* real path used to open file */ + struct stat inode; /* inode information for file */ } READSET; -STATIC READSET *readset = NULL; /* array of files read */ -STATIC int maxreadset = 0; /* length of readset */ +STATIC READSET *readset = NULL; /* array of files read */ +STATIC int maxreadset = 0; /* length of readset */ -STATIC int linesize; /* current max size of input line */ -STATIC char *linebuf; /* current input line buffer */ -STATIC char *prompt; /* current prompt for terminal */ -STATIC BOOL noprompt; /* TRUE if should not print prompt */ +STATIC int linesize; /* current max size of input line */ +STATIC char *linebuf; /* current input line buffer */ +STATIC char *prompt; /* current prompt for terminal */ +STATIC BOOL noprompt; /* TRUE if should not print prompt */ -STATIC int depth; /* current input depth */ -STATIC INPUT *cip; /* current input source */ -STATIC INPUT inputs[MAXDEPTH]; /* input sources */ +STATIC int depth; /* current input depth */ +STATIC INPUT *cip; /* current input source */ +STATIC INPUT inputs[MAXDEPTH]; /* input sources */ S_FUNC int openfile(char *name); @@ -116,149 +116,149 @@ S_FUNC char *homeexpand(char *name); /* * Open an input file by possibly searching through a path list - * and also possibly applying the specified extension. For example: + * and also possibly applying the specified extension. For example: * - * opensearchfile("barf", ".:/tmp", ".c", rd_once) + * opensearchfile("barf", ".:/tmp", ".c", rd_once) * * searches in order for the files: * - * "./barf", "./barf.c", "/tmp/barf", and "/tmp/barf.c". + * "./barf", "./barf.c", "/tmp/barf", and "/tmp/barf.c". * * Returns -1 if we could not open a file or error. * Returns 1 if file was opened and added to/updated in the readset * Returns 0 if file was already in the readset and reopen was 0. * * given: - * name file name to be read - * pathlist list of colon separated paths (or NULL) - * extension extra extension to try (or NULL) - * rd_once TRUE => do not reread a file + * name file name to be read + * pathlist list of colon separated paths (or NULL) + * extension extra extension to try (or NULL) + * rd_once TRUE => do not reread a file */ int opensearchfile(char *name, char *pathlist, char *extension, int rd_once) { - int i; - char *cp; - char *path; /* name being searched for */ - size_t path_alloc; /* length of malloced path */ - struct stat statbuf; /* stat of the path */ - size_t namelen; /* length of name */ - size_t extlen; /* length of the extension if non-NULL or 0 */ - size_t pathlen; /* length of the pathlist if non-NULL or 0 */ + int i; + char *cp; + char *path; /* name being searched for */ + size_t path_alloc; /* length of malloced path */ + struct stat statbuf; /* stat of the path */ + size_t namelen; /* length of name */ + size_t extlen; /* length of the extension if non-NULL or 0 */ + size_t pathlen; /* length of the pathlist if non-NULL or 0 */ - /* firewall */ - if (name == NULL) { - math_error("NULL name given to opensearchfile"); - not_reached(); - } + /* firewall */ + if (name == NULL) { + math_error("NULL name given to opensearchfile"); + not_reached(); + } - /* - * We ignore the pathlist of the file is absolute, dot-relative - * or tilde-relative or if there is no search path. - */ - if (name[0] == PATHCHAR || - name[0] == HOMECHAR || - (name[0] == DOTCHAR && name[1] == '\0') || - (name[0] == DOTCHAR && name[1] == DOTCHAR && name[2] == '\0') || - (name[0] == DOTCHAR && name[1] == PATHCHAR) || - (name[0] == DOTCHAR && name[1] == DOTCHAR && name[2] == PATHCHAR) || - pathlist == NULL) { - pathlist = ""; - } + /* + * We ignore the pathlist of the file is absolute, dot-relative + * or tilde-relative or if there is no search path. + */ + if (name[0] == PATHCHAR || + name[0] == HOMECHAR || + (name[0] == DOTCHAR && name[1] == '\0') || + (name[0] == DOTCHAR && name[1] == DOTCHAR && name[2] == '\0') || + (name[0] == DOTCHAR && name[1] == PATHCHAR) || + (name[0] == DOTCHAR && name[1] == DOTCHAR && name[2] == PATHCHAR) || + pathlist == NULL) { + pathlist = ""; + } - /* - * allocate storage for the longest name being searched for - * - * We will allocate more than we could ever want/need. - * The longest we could ever need would be: - * - * pathlist (as a single long string) - * / - * name - * . - * extension - * \0 - * guard byte - */ - namelen = strlen(name); - if (extension != NULL) { - extlen = strlen(extension); - } else { - extlen = 0; - } - pathlen = strlen(pathlist); - path_alloc = pathlen+1 + 1 + namelen+1 + extlen+1 + 1 + 1; - path = malloc(path_alloc+1); - if (path == NULL) { - math_error("Cannot allocate filename path buffer"); - not_reached(); - } - path[0] = '\0'; /* paranoia */ - path[path_alloc] = '\0'; /* paranoia */ + /* + * allocate storage for the longest name being searched for + * + * We will allocate more than we could ever want/need. + * The longest we could ever need would be: + * + * pathlist (as a single long string) + * / + * name + * . + * extension + * \0 + * guard byte + */ + namelen = strlen(name); + if (extension != NULL) { + extlen = strlen(extension); + } else { + extlen = 0; + } + pathlen = strlen(pathlist); + path_alloc = pathlen+1 + 1 + namelen+1 + extlen+1 + 1 + 1; + path = malloc(path_alloc+1); + if (path == NULL) { + math_error("Cannot allocate filename path buffer"); + not_reached(); + } + path[0] = '\0'; /* paranoia */ + path[path_alloc] = '\0'; /* paranoia */ - /* - * Don't try the extension if the filename already contains it. - */ - if (extension != NULL && namelen >= extlen && - strcmp(&name[namelen-extlen], extension) == 0) { - extension = NULL; - } + /* + * Don't try the extension if the filename already contains it. + */ + if (extension != NULL && namelen >= extlen && + strcmp(&name[namelen-extlen], extension) == 0) { + extension = NULL; + } - /* - * Search through the path list for the file - */ - pathlist--; - do { - pathlist++; - cp = path; - while (*pathlist && (*pathlist != LISTCHAR)) - *cp++ = *pathlist++; - if (cp != path) - *cp++ = PATHCHAR; - strlcpy(cp, name, namelen+1); - i = openfile(path); - if ((i < 0) && - (extension != NULL && extension[0] != '\0')) { - strlcat(path, extension, path_alloc+1); - i = openfile(path); - } - } while ((i < 0) && *pathlist); + /* + * Search through the path list for the file + */ + pathlist--; + do { + pathlist++; + cp = path; + while (*pathlist && (*pathlist != LISTCHAR)) + *cp++ = *pathlist++; + if (cp != path) + *cp++ = PATHCHAR; + strlcpy(cp, name, namelen+1); + i = openfile(path); + if ((i < 0) && + (extension != NULL && extension[0] != '\0')) { + strlcat(path, extension, path_alloc+1); + i = openfile(path); + } + } while ((i < 0) && *pathlist); - /* examine what our search produced */ - if (i < 0) { - free(path); - return i; - } - if (cip->i_fp == NULL) { - /* cannot find a file to open */ - free(path); - return -3; - } - if (fstat(fileno(cip->i_fp), &statbuf) < 0) { - /* unable to fstat the open file */ - free(path); - return -4; - } + /* examine what our search produced */ + if (i < 0) { + free(path); + return i; + } + if (cip->i_fp == NULL) { + /* cannot find a file to open */ + free(path); + return -3; + } + if (fstat(fileno(cip->i_fp), &statbuf) < 0) { + /* unable to fstat the open file */ + free(path); + return -4; + } - /* note if we will reopen a file and if that is allowed */ - if (rd_once == TRUE && isinoderead(&statbuf) >= 0) { - /* file is in readset and reopen is false */ - closeinput(); - free(path); - return 1; - } + /* note if we will reopen a file and if that is allowed */ + if (rd_once == TRUE && isinoderead(&statbuf) >= 0) { + /* file is in readset and reopen is false */ + closeinput(); + free(path); + return 1; + } - /* add this name to the readset if allowed */ - if (addreadset(name, path, &statbuf) < 0) { - /* cannot add to readset */ - closeinput(); - free(path); - return -1; - } + /* add this name to the readset if allowed */ + if (addreadset(name, path, &statbuf) < 0) { + /* cannot add to readset */ + closeinput(); + free(path); + return -1; + } - /* file was added to/updated in readset */ - free(path); - return 0; + /* file was added to/updated in readset */ + free(path); + return 0; } @@ -267,13 +267,13 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once) * * Open a file by possibly searching through a path list. For example: * - * f_pathopen("curds", ".:/tmp:~/pub", "r", NULL) + * f_pathopen("curds", ".:/tmp:~/pub", "r", NULL) * * searches in order for a file that it can open for reading: * - * "./curds", "/tmp/curds", "~/pub/curds" + * "./curds", "/tmp/curds", "~/pub/curds" * - * NOTE: ~ is expanded accordingly (see homeexpand() below). + * NOTE: ~ is expanded accordingly (see homeexpand() below). * * However is the file is /absolue/path/name or a ./dot/relative/name, or * a ~/home/dir/name, or a ~user/home/name, then the pathlist is ignored @@ -281,108 +281,108 @@ opensearchfile(char *name, char *pathlist, char *extension, int rd_once) * * and opens the first one that exists and allows the mode. * - * name file name to be read - * mode fopen() mode argument - * (one of "r", "w", "a", "r+", "w+", "a+") - * pathlist list of colon separated paths (or NULL) - * openpath if non-NULL, and file was opened, set to malloced - * path used to open + * name file name to be read + * mode fopen() mode argument + * (one of "r", "w", "a", "r+", "w+", "a+") + * pathlist list of colon separated paths (or NULL) + * openpath if non-NULL, and file was opened, set to malloced + * path used to open * * returns: - * open file stream, NULL ==> file was not found or error - * If file was open and openpath was non-NULL, changed to point - * to path used to open + * open file stream, NULL ==> file was not found or error + * If file was open and openpath was non-NULL, changed to point + * to path used to open */ FILE * f_pathopen(char *name, char *mode, char *pathlist, char **openpath) { - char *cp; - char *path; /* name being searched for */ - size_t namelen; /* length of name */ - size_t pathlen; /* length of the pathlist if non-NULL or 0 */ - FILE *ret; /* return open stream or NULL */ + char *cp; + char *path; /* name being searched for */ + size_t namelen; /* length of name */ + size_t pathlen; /* length of the pathlist if non-NULL or 0 */ + FILE *ret; /* return open stream or NULL */ - /* firewall */ - if (name == NULL) { - math_error("NULL name given to f_pathopen"); - not_reached(); - } - if (mode == NULL) { - math_error("NULL mode given to f_pathopen"); - not_reached(); - } + /* firewall */ + if (name == NULL) { + math_error("NULL name given to f_pathopen"); + not_reached(); + } + if (mode == NULL) { + math_error("NULL mode given to f_pathopen"); + not_reached(); + } - /* - * We ignore the pathlist of the file is absolute, dot-relative - * or tilde-relative or if there is no search path. - */ - if (name[0] == PATHCHAR || - name[0] == HOMECHAR || - (name[0] == DOTCHAR && name[1] == '\0') || - (name[0] == DOTCHAR && name[1] == DOTCHAR && name[2] == '\0') || - (name[0] == DOTCHAR && name[1] == PATHCHAR) || - (name[0] == DOTCHAR && name[1] == DOTCHAR && name[2] == PATHCHAR) || - pathlist == NULL) { - pathlist = ""; - } + /* + * We ignore the pathlist of the file is absolute, dot-relative + * or tilde-relative or if there is no search path. + */ + if (name[0] == PATHCHAR || + name[0] == HOMECHAR || + (name[0] == DOTCHAR && name[1] == '\0') || + (name[0] == DOTCHAR && name[1] == DOTCHAR && name[2] == '\0') || + (name[0] == DOTCHAR && name[1] == PATHCHAR) || + (name[0] == DOTCHAR && name[1] == DOTCHAR && name[2] == PATHCHAR) || + pathlist == NULL) { + pathlist = ""; + } - /* - * allocate storage for the longest name being searched for - * - * We will allocate more than we could ever want/need. - * The longest we could ever need would be: - * - * pathlist (as a single long string) - * / - * name - * \0 - * guard byte - */ - namelen = strlen(name); - pathlen = strlen(pathlist); - path = malloc(pathlen+1 + 1 + namelen+1 + 1 + 1); - if (path == NULL) { - math_error("Cannot allocate f_pathopen buffer"); - not_reached(); - } + /* + * allocate storage for the longest name being searched for + * + * We will allocate more than we could ever want/need. + * The longest we could ever need would be: + * + * pathlist (as a single long string) + * / + * name + * \0 + * guard byte + */ + namelen = strlen(name); + pathlen = strlen(pathlist); + path = malloc(pathlen+1 + 1 + namelen+1 + 1 + 1); + if (path == NULL) { + math_error("Cannot allocate f_pathopen buffer"); + not_reached(); + } - /* - * Search through the path list for the file - */ - pathlist--; - do { - pathlist++; - cp = path; - while (*pathlist && (*pathlist != LISTCHAR)) - *cp++ = *pathlist++; - if (cp != path) - *cp++ = PATHCHAR; - strlcpy(cp, name, namelen+1); - ret = f_open(path, mode); - } while ((ret == NULL) && *pathlist); + /* + * Search through the path list for the file + */ + pathlist--; + do { + pathlist++; + cp = path; + while (*pathlist && (*pathlist != LISTCHAR)) + *cp++ = *pathlist++; + if (cp != path) + *cp++ = PATHCHAR; + strlcpy(cp, name, namelen+1); + ret = f_open(path, mode); + } while ((ret == NULL) && *pathlist); - /* if caller wants to know the path, malloc it and return it */ - if (openpath != NULL && ret != NULL) { - if (path[0] == HOMECHAR) { - *openpath = homeexpand(path); - } else { - *openpath = strdup(path); - } - if (*openpath == NULL) { - free(path); - if ((conf->calc_debug & CALCDBG_TTY) && ret == stdin) { - printf("f_pathopen: closing stdin " - "on malloc return error\n"); - } - fclose(ret); - math_error("cannot malloc return openpath buffer"); - not_reached(); - } - } - free(path); + /* if caller wants to know the path, malloc it and return it */ + if (openpath != NULL && ret != NULL) { + if (path[0] == HOMECHAR) { + *openpath = homeexpand(path); + } else { + *openpath = strdup(path); + } + if (*openpath == NULL) { + free(path); + if ((conf->calc_debug & CALCDBG_TTY) && ret == stdin) { + printf("f_pathopen: closing stdin " + "on malloc return error\n"); + } + fclose(ret); + math_error("cannot malloc return openpath buffer"); + not_reached(); + } + } + free(path); - /* return open file or NULL */ - return ret; + /* return open file or NULL */ + return ret; } @@ -402,87 +402,87 @@ f_pathopen(char *name, char *mode, char *pathlist, char **openpath) * a NULL pointer is returned. * * given: - * name a filename with a leading ~ + * name a filename with a leading ~ */ S_FUNC char * homeexpand(char *name) { #if defined(_WIN32) || defined(_WIN64) - return NULL; + return NULL; #else /* Windows free systems */ - struct passwd *ent; /* password entry */ - char *home2; /* fullpath of the home directory */ - char *fullpath; /* the malloced expanded path */ - char *after; /* after the ~user or ~ */ - char *username; /* extracted username */ - size_t fullpath_len; /* length of fullpath */ - size_t snprintf_len; /* malloced snprintf buffer length */ + struct passwd *ent; /* password entry */ + char *home2; /* fullpath of the home directory */ + char *fullpath; /* the malloced expanded path */ + char *after; /* after the ~user or ~ */ + char *username; /* extracted username */ + size_t fullpath_len; /* length of fullpath */ + size_t snprintf_len; /* malloced snprintf buffer length */ - /* firewall */ - if (name[0] != HOMECHAR) - return NULL; + /* firewall */ + if (name[0] != HOMECHAR) + return NULL; - /* - * obtain the home directory component - */ - switch (name[1]) { - case PATHCHAR: /* ~/... */ - case '\0': /* ~ */ - home2 = home; - after = name+1; - break; - default: /* ~username or ~username/... */ + /* + * obtain the home directory component + */ + switch (name[1]) { + case PATHCHAR: /* ~/... */ + case '\0': /* ~ */ + home2 = home; + after = name+1; + break; + default: /* ~username or ~username/... */ - /* extract the username after the ~ */ - after = (char *)strchr(name+2, PATHCHAR); - if (after == NULL) { - /* path is just ~username */ - ent = (struct passwd *)getpwnam(name+1); - if (ent == NULL) { - /* unknown user */ - return NULL; - } - /* just malloc the home directory and return it */ - fullpath_len = strlen(ent->pw_dir); - fullpath = (char *)malloc(fullpath_len+1); - if (fullpath == NULL) { - return NULL; - } - strlcpy(fullpath, ent->pw_dir, fullpath_len+1); - return fullpath; - } - username = (char *) malloc(after-name + 1 + 1); - if (username == NULL) { - /* failed to malloc username */ - return NULL; - } - strlcpy(username, name+1, after-name+1+1); + /* extract the username after the ~ */ + after = (char *)strchr(name+2, PATHCHAR); + if (after == NULL) { + /* path is just ~username */ + ent = (struct passwd *)getpwnam(name+1); + if (ent == NULL) { + /* unknown user */ + return NULL; + } + /* just malloc the home directory and return it */ + fullpath_len = strlen(ent->pw_dir); + fullpath = (char *)malloc(fullpath_len+1); + if (fullpath == NULL) { + return NULL; + } + strlcpy(fullpath, ent->pw_dir, fullpath_len+1); + return fullpath; + } + username = (char *) malloc(after-name + 1 + 1); + if (username == NULL) { + /* failed to malloc username */ + return NULL; + } + strlcpy(username, name+1, after-name+1+1); - /* get that user's home directory */ - ent = (struct passwd *)getpwnam(username); - free(username); - if (ent == NULL) { - /* unknown user */ - return NULL; - } - home2 = ent->pw_dir; - break; - } + /* get that user's home directory */ + ent = (struct passwd *)getpwnam(username); + free(username); + if (ent == NULL) { + /* unknown user */ + return NULL; + } + home2 = ent->pw_dir; + break; + } - /* - * build the fullpath given the home directory - */ - snprintf_len = strlen(home2)+strlen(after) + 1; - fullpath = (char *)malloc(snprintf_len+1); - if (fullpath == NULL) { - return NULL; - } - snprintf(fullpath, snprintf_len, "%s%s", home2, after); - fullpath[snprintf_len] = '\0'; /* paranoia */ - return fullpath; + /* + * build the fullpath given the home directory + */ + snprintf_len = strlen(home2)+strlen(after) + 1; + fullpath = (char *)malloc(snprintf_len+1); + if (fullpath == NULL) { + return NULL; + } + snprintf(fullpath, snprintf_len, "%s%s", home2, after); + fullpath[snprintf_len] = '\0'; /* paranoia */ + return fullpath; #endif /* Windows free systems */ } @@ -491,61 +491,61 @@ homeexpand(char *name) * f_open - ~-expand a filename and fopen() it * * given: - * name the filename to open - * mode fopen() mode argument - * (one of "r", "w", "a", "r+", "w+", "a+") + * name the filename to open + * mode fopen() mode argument + * (one of "r", "w", "a", "r+", "w+", "a+") */ FILE * f_open(char *name, char *mode) { - FILE *fp; /* open file descriptor */ - char *fullname; /* file name with HOMECHAR expansion */ + FILE *fp; /* open file descriptor */ + char *fullname; /* file name with HOMECHAR expansion */ - /* - * be sore we are allowed to open a file in this mode - */ - if (!allow_read && !allow_write) { - /* no reads and no writes means no opens! */ - if (run_state > RUN_BEGIN) { - fprintf(stderr, - "open of %s mode %s - %s\n", name, mode, - "open for read or write disallowed by -m\n"); - } - return NULL; - } else if (!allow_read && strchr(mode, 'r') != NULL) { - /* reading new files disallowed */ - if (run_state > RUN_BEGIN) { - fprintf(stderr, - "open of %s mode %s - %s\n", name, mode, - "open for read disallowed by -m\n"); - } - return NULL; - } else if (!allow_write && - (strchr(mode, 'w') != NULL || - strchr(mode, 'a') != NULL || - strchr(mode, '+') != NULL)) { - /* writing new files disallowed */ - if (run_state > RUN_BEGIN) { - fprintf(stderr, - "open of %s mode %s - %s\n", name, mode, - "open for write disallowed by -m\n"); - } - return NULL; - } + /* + * be sore we are allowed to open a file in this mode + */ + if (!allow_read && !allow_write) { + /* no reads and no writes means no opens! */ + if (run_state > RUN_BEGIN) { + fprintf(stderr, + "open of %s mode %s - %s\n", name, mode, + "open for read or write disallowed by -m\n"); + } + return NULL; + } else if (!allow_read && strchr(mode, 'r') != NULL) { + /* reading new files disallowed */ + if (run_state > RUN_BEGIN) { + fprintf(stderr, + "open of %s mode %s - %s\n", name, mode, + "open for read disallowed by -m\n"); + } + return NULL; + } else if (!allow_write && + (strchr(mode, 'w') != NULL || + strchr(mode, 'a') != NULL || + strchr(mode, '+') != NULL)) { + /* writing new files disallowed */ + if (run_state > RUN_BEGIN) { + fprintf(stderr, + "open of %s mode %s - %s\n", name, mode, + "open for write disallowed by -m\n"); + } + return NULL; + } - /* - * expand ~ if needed - */ - if (name[0] == HOMECHAR) { - fullname = homeexpand(name); - if (fullname == NULL) - return NULL; - fp = fopen(fullname, mode); - free(fullname); - } else { - fp = fopen(name, mode); - } - return fp; + /* + * expand ~ if needed + */ + if (name[0] == HOMECHAR) { + fullname = homeexpand(name); + if (fullname == NULL) + return NULL; + fp = fopen(fullname, mode); + free(fullname); + } else { + fp = fopen(name, mode); + } + return fp; } @@ -554,33 +554,33 @@ f_open(char *name, char *mode) * Returns -1 if file could not be opened. * * given: - * name file name to be read + * name file name to be read */ S_FUNC int openfile(char *name) { - FILE *fp; /* open file descriptor */ - size_t namelen; + FILE *fp; /* open file descriptor */ + size_t namelen; - if (depth >= MAXDEPTH) - return -2; - fp = f_open(name, "r"); - if (fp == NULL) - return -1; - cip = inputs + depth++; - cip->i_state = IS_READ; - cip->i_char = '\0'; - cip->i_str = NULL; - cip->i_ttystr = NULL; - cip->i_fp = fp; - cip->i_line = 1; - namelen = strlen(name); - cip->i_name = (char *)malloc(namelen+1); - if (cip->i_name == NULL) { - return -1; - } - strlcpy(cip->i_name, name, namelen+1); - return 0; + if (depth >= MAXDEPTH) + return -2; + fp = f_open(name, "r"); + if (fp == NULL) + return -1; + cip = inputs + depth++; + cip->i_state = IS_READ; + cip->i_char = '\0'; + cip->i_str = NULL; + cip->i_ttystr = NULL; + cip->i_fp = fp; + cip->i_line = 1; + namelen = strlen(name); + cip->i_name = (char *)malloc(namelen+1); + if (cip->i_name == NULL) { + return -1; + } + strlcpy(cip->i_name, name, namelen+1); + return 0; } @@ -590,9 +590,9 @@ openfile(char *name) FILE * curstream(void) { - if (depth <= 0 || depth > MAXDEPTH) - return NULL; - return cip->i_fp; + if (depth <= 0 || depth > MAXDEPTH) + return NULL; + return cip->i_fp; } @@ -602,31 +602,31 @@ curstream(void) * Returns -1 if cannot open string. * * given: - * str string to be opened - * num length of string to open + * str string to be opened + * num length of string to open */ int openstring(char *str, size_t num) { - char *cp; /* copied string */ + char *cp; /* copied string */ - if ((depth >= MAXDEPTH) || (str == NULL)) - return -2; - cp = (char *) malloc(num + 1); - if (cp == NULL) - return -1; - strlcpy(cp, str, num+1); - cip = inputs + depth++; - cip->i_state = IS_READ; - cip->i_char = '\0'; - cip->i_cp = cp; - cip->i_str = cp; - cip->i_num = num; - cip->i_fp = NULL; - cip->i_name = NULL; - cip->i_ttystr = NULL; - cip->i_line = 1; - return 0; + if ((depth >= MAXDEPTH) || (str == NULL)) + return -2; + cp = (char *) malloc(num + 1); + if (cp == NULL) + return -1; + strlcpy(cp, str, num+1); + cip = inputs + depth++; + cip->i_state = IS_READ; + cip->i_char = '\0'; + cip->i_cp = cp; + cip->i_str = cp; + cip->i_num = num; + cip->i_fp = NULL; + cip->i_name = NULL; + cip->i_ttystr = NULL; + cip->i_line = 1; + return 0; } @@ -637,17 +637,17 @@ openstring(char *str, size_t num) int openterminal(void) { - if (depth >= MAXDEPTH) - return -2; - cip = inputs + depth++; - cip->i_state = IS_READ; - cip->i_char = '\0'; - cip->i_str = NULL; - cip->i_ttystr = NULL; - cip->i_fp = NULL; - cip->i_name = NULL; - cip->i_line = 1; - return 0; + if (depth >= MAXDEPTH) + return -2; + cip = inputs + depth++; + cip->i_state = IS_READ; + cip->i_char = '\0'; + cip->i_str = NULL; + cip->i_ttystr = NULL; + cip->i_fp = NULL; + cip->i_name = NULL; + cip->i_line = 1; + return 0; } @@ -657,21 +657,21 @@ openterminal(void) void closeinput(void) { - if (depth <= 0) - return; - if (cip->i_str) - free(cip->i_str); - if (cip->i_fp) { - if ((conf->calc_debug & CALCDBG_TTY) && cip->i_fp == stdin) { - printf("closeinput: closing stdin " - "at depth: %d\n", depth); - } - fclose(cip->i_fp); - } - if (cip->i_name) - free(cip->i_name); - depth--; - cip = depth ? &inputs[depth - 1] : NULL; + if (depth <= 0) + return; + if (cip->i_str) + free(cip->i_str); + if (cip->i_fp) { + if ((conf->calc_debug & CALCDBG_TTY) && cip->i_fp == stdin) { + printf("closeinput: closing stdin " + "at depth: %d\n", depth); + } + fclose(cip->i_fp); + } + if (cip->i_name) + free(cip->i_name); + depth--; + cip = depth ? &inputs[depth - 1] : NULL; } @@ -681,9 +681,9 @@ closeinput(void) void resetinput(void) { - while (depth > 0) - closeinput(); - noprompt = FALSE; + while (depth > 0) + closeinput(); + noprompt = FALSE; } @@ -693,8 +693,8 @@ resetinput(void) void setprompt(char *str) { - prompt = str; - noprompt = FALSE; + prompt = str; + noprompt = FALSE; } @@ -705,87 +705,87 @@ setprompt(char *str) int nextchar(void) { - int ch; /* current input character */ + int ch; /* current input character */ - if (depth == 0) /* input finished */ - return EOF; - if (cip->i_state == IS_REREAD) { /* rereading current char */ - ch = cip->i_char; - cip->i_state = IS_READ; - if (ch == '\n') - cip->i_line++; - return ch; - } - if (cip->i_str) { /* from string */ - if (cip->i_num) { - ch = chartoint(*cip->i_cp++); - cip->i_num--; - } else { - ch = EOF; - } - } else if (cip->i_fp) { /* from file */ - ch = fgetc(cip->i_fp); - } else if (!stdin_tty) { /* from file */ - ch = fgetc(stdin); - } else { /* from terminal */ - ch = ttychar(); - } - if (depth > 0) - cip->i_char = ch; /* save for rereads */ - if (ch == '\n') - cip->i_line++; - return ch; + if (depth == 0) /* input finished */ + return EOF; + if (cip->i_state == IS_REREAD) { /* rereading current char */ + ch = cip->i_char; + cip->i_state = IS_READ; + if (ch == '\n') + cip->i_line++; + return ch; + } + if (cip->i_str) { /* from string */ + if (cip->i_num) { + ch = chartoint(*cip->i_cp++); + cip->i_num--; + } else { + ch = EOF; + } + } else if (cip->i_fp) { /* from file */ + ch = fgetc(cip->i_fp); + } else if (!stdin_tty) { /* from file */ + ch = fgetc(stdin); + } else { /* from terminal */ + ch = ttychar(); + } + if (depth > 0) + cip->i_char = ch; /* save for rereads */ + if (ch == '\n') + cip->i_line++; + return ch; } /* * Read in the next line of input from the current input source. * The line is terminated with a null character, and does not contain - * the final newline character. The returned string is only valid + * the final newline character. The returned string is only valid * until the next such call, and so must be copied if necessary. * Returns NULL on end of file. */ char * nextline(void) { - char *cp; - int ch; - int len; + char *cp; + int ch; + int len; - cp = linebuf; - if (linesize == 0) { - cp = (char *)malloc(TTYSIZE + 1); - if (cp == NULL) { - math_error("Cannot allocate line buffer"); - not_reached(); - } - linebuf = cp; - linesize = TTYSIZE; - } - len = 0; - for (;;) { - noprompt = TRUE; - ch = nextchar(); - noprompt = FALSE; - if (ch == EOF) - return NULL; - if (ch == '\0') - continue; - if (ch == '\n') - break; - if (len >= linesize) { - cp = (char *)realloc(cp, linesize + TTYSIZE + 1); - if (cp == NULL) { - math_error("Cannot realloc line buffer"); - not_reached(); - } - linebuf = cp; - linesize += TTYSIZE; - } - cp[len++] = (char)ch; - } - cp[len] = '\0'; - return linebuf; + cp = linebuf; + if (linesize == 0) { + cp = (char *)malloc(TTYSIZE + 1); + if (cp == NULL) { + math_error("Cannot allocate line buffer"); + not_reached(); + } + linebuf = cp; + linesize = TTYSIZE; + } + len = 0; + for (;;) { + noprompt = TRUE; + ch = nextchar(); + noprompt = FALSE; + if (ch == EOF) + return NULL; + if (ch == '\0') + continue; + if (ch == '\n') + break; + if (len >= linesize) { + cp = (char *)realloc(cp, linesize + TTYSIZE + 1); + if (cp == NULL) { + math_error("Cannot realloc line buffer"); + not_reached(); + } + linebuf = cp; + linesize += TTYSIZE; + } + cp[len++] = (char)ch; + } + cp[len] = '\0'; + return linebuf; } @@ -797,67 +797,67 @@ nextline(void) S_FUNC int ttychar(void) { - int ch; /* current char */ - int len; /* length of current command */ - STATIC char charbuf[256*1024]; + int ch; /* current char */ + int len; /* length of current command */ + STATIC char charbuf[256*1024]; - /* - * If we have more to read from the saved command line, then do that. - * When we see a newline character, then clear the pointer so we will - * read a new line on the next call. - */ - if (cip->i_ttystr) { - ch = chartoint(*cip->i_ttystr++); - if (ch == '\n') - cip->i_ttystr = NULL; - return ch; - } + /* + * If we have more to read from the saved command line, then do that. + * When we see a newline character, then clear the pointer so we will + * read a new line on the next call. + */ + if (cip->i_ttystr) { + ch = chartoint(*cip->i_ttystr++); + if (ch == '\n') + cip->i_ttystr = NULL; + return ch; + } - /* - * We need another complete line. - */ - abortlevel = 0; - inputwait = TRUE; - len = hist_getline(noprompt ? "" : prompt, charbuf, sizeof(charbuf)); - if (len == 0) { - inputwait = FALSE; - return EOF; - } - inputwait = FALSE; + /* + * We need another complete line. + */ + abortlevel = 0; + inputwait = TRUE; + len = hist_getline(noprompt ? "" : prompt, charbuf, sizeof(charbuf)); + if (len == 0) { + inputwait = FALSE; + return EOF; + } + inputwait = FALSE; - /* - * Handle shell escape if present - */ - if (charbuf[0] == '!') { /* do a shell command */ - char *cmd; - int ret; + /* + * Handle shell escape if present + */ + if (charbuf[0] == '!') { /* do a shell command */ + char *cmd; + int ret; - cmd = charbuf + 1; - if (*cmd == '\0' || *cmd == '\n') - cmd = shell; - if (allow_exec) { - if (conf->calc_debug & CALCDBG_SYSTEM) { - printf("%s\n", cmd); - } - ret = system(cmd); - if (ret < 0) { - fprintf(stderr, "error in cmd: %s\n", cmd); - } - } else { - fprintf(stderr, "execution disallowed by -m flag\n"); - } - return '\n'; - } - hist_saveline(charbuf, len); + cmd = charbuf + 1; + if (*cmd == '\0' || *cmd == '\n') + cmd = shell; + if (allow_exec) { + if (conf->calc_debug & CALCDBG_SYSTEM) { + printf("%s\n", cmd); + } + ret = system(cmd); + if (ret < 0) { + fprintf(stderr, "error in cmd: %s\n", cmd); + } + } else { + fprintf(stderr, "execution disallowed by -m flag\n"); + } + return '\n'; + } + hist_saveline(charbuf, len); - /* - * Return the first character of the line, and set up to - * return the rest of it with later calls. - */ - ch = chartoint(charbuf[0]); - if (ch != '\n') - cip->i_ttystr = charbuf + 1; - return ch; + /* + * Return the first character of the line, and set up to + * return the rest of it with later calls. + */ + ch = chartoint(charbuf[0]); + if (ch != '\n') + cip->i_ttystr = charbuf + 1; + return ch; } @@ -867,7 +867,7 @@ ttychar(void) BOOL inputisterminal(void) { - return ((depth <= 0) || ((cip->i_str == NULL) && (cip->i_fp == NULL))); + return ((depth <= 0) || ((cip->i_str == NULL) && (cip->i_fp == NULL))); } @@ -877,7 +877,7 @@ inputisterminal(void) int inputlevel(void) { - return depth - 1; + return depth - 1; } @@ -888,9 +888,9 @@ inputlevel(void) char * inputname(void) { - if (depth <= 0) - return NULL; - return cip->i_name; + if (depth <= 0) + return NULL; + return cip->i_name; } @@ -900,9 +900,9 @@ inputname(void) long linenumber(void) { - if (depth > 0) - return cip->i_line; - return 1; + if (depth > 0) + return cip->i_line; + return 1; } @@ -912,11 +912,11 @@ linenumber(void) void reread(void) { - if ((depth <= 0) || (cip->i_state == IS_REREAD)) - return; - cip->i_state = IS_REREAD; - if (cip->i_char == '\n') - cip->i_line--; + if ((depth <= 0) || (cip->i_state == IS_REREAD)) + return; + cip->i_state = IS_REREAD; + if (cip->i_char == '\n') + cip->i_line--; } @@ -926,39 +926,39 @@ reread(void) void runrcfiles(void) { - char path[MAX_CALCRC+1+1]; /* name being searched for */ - char *cp; - char *p; + char path[MAX_CALCRC+1+1]; /* name being searched for */ + char *cp; + char *p; - /* execute each file in the list */ - while (calcrc != NULL && *calcrc) { - cp = calcrc; - calcrc = (char *) strchr(calcrc + 1, LISTCHAR); + /* execute each file in the list */ + while (calcrc != NULL && *calcrc) { + cp = calcrc; + calcrc = (char *) strchr(calcrc + 1, LISTCHAR); - /* load file name into the path */ - if (calcrc == NULL) { - strlcpy(path, cp, MAX_CALCRC+1); - } else { - strlcpy(path, cp, calcrc - cp + 1); - } + /* load file name into the path */ + if (calcrc == NULL) { + strlcpy(path, cp, MAX_CALCRC+1); + } else { + strlcpy(path, cp, calcrc - cp + 1); + } - /* find the start of the path */ - p = (path[0] == ':') ? path + 1 : path; - if (p[0] == '\0') { - continue; - } + /* find the start of the path */ + p = (path[0] == ':') ? path + 1 : path; + if (p[0] == '\0') { + continue; + } - /* process the current file in the list */ - if (openfile(p) < 0) { - /* Unable to open rcfile */ - if (c_flag && !d_flag) - fprintf(stderr, - "Unable to open rcfile \"%s\"\n", p); - continue; - } - getcommands(FALSE); - closeinput(); - } + /* process the current file in the list */ + if (openfile(p) < 0) { + /* Unable to open rcfile */ + if (c_flag && !d_flag) + fprintf(stderr, + "Unable to open rcfile \"%s\"\n", p); + continue; + } + getcommands(FALSE); + closeinput(); + } } @@ -971,51 +971,51 @@ runrcfiles(void) * * _WIN32 and _WIN64 NOTE: * - * This function likely will not work under _WIN32 or _WIN64. + * This function likely will not work under _WIN32 or _WIN64. * - * The sbuf->st_ino is always zero because the FAT and NTFS filesystems - * do not support inodes. Those filesystems don't support links, which - * is why you need this function under UNIX. For _WIN32 or _WIN64, use - * _fullpath() to determine if you have already opened a file. + * The sbuf->st_ino is always zero because the FAT and NTFS filesystems + * do not support inodes. Those filesystems don't support links, which + * is why you need this function under UNIX. For _WIN32 or _WIN64, use + * _fullpath() to determine if you have already opened a file. * * given: - * sbuf stat of the inode in question + * sbuf stat of the inode in question */ S_FUNC int isinoderead(struct stat *sbuf) { - int i; + int i; - /* deal with the empty case */ - if (readset == NULL || maxreadset <= 0) { - /* readset is empty */ - return -1; - } + /* deal with the empty case */ + if (readset == NULL || maxreadset <= 0) { + /* readset is empty */ + return -1; + } - /* scan the entire readset */ - for (i=0; i < maxreadset; ++i) { + /* scan the entire readset */ + for (i=0; i < maxreadset; ++i) { #if defined(_WIN32) || defined(_WIN64) - char tmp[MAX_PATH+1]; - tmp[MAX_PATH] = '\0'; - if (_fullpath(tmp, cip->i_name, MAX_PATH) && - readset[i].active && - strcasecmp(readset[i].path, tmp) == 0) { - /* found a match */ - return i; - } + char tmp[MAX_PATH+1]; + tmp[MAX_PATH] = '\0'; + if (_fullpath(tmp, cip->i_name, MAX_PATH) && + readset[i].active && + strcasecmp(readset[i].path, tmp) == 0) { + /* found a match */ + return i; + } #else /* Windows free systems */ - if (readset[i].active && - sbuf->st_dev == readset[i].inode.st_dev && - sbuf->st_ino == readset[i].inode.st_ino) { - /* found a match */ - return i; - } + if (readset[i].active && + sbuf->st_dev == readset[i].inode.st_dev && + sbuf->st_ino == readset[i].inode.st_ino) { + /* found a match */ + return i; + } #endif /* Windows free systems */ - } + } - /* no match found */ - return -1; + /* no match found */ + return -1; } @@ -1030,46 +1030,46 @@ isinoderead(struct stat *sbuf) S_FUNC int findfreeread(void) { - int i; + int i; - /* deal with an empty readset case */ - if (readset == NULL || maxreadset <= 0) { + /* deal with an empty readset case */ + if (readset == NULL || maxreadset <= 0) { - /* malloc a new readset */ - readset = (READSET *)malloc((READSET_ALLOC+1)*sizeof(READSET)); - if (readset == NULL) { - return -1; - } - maxreadset = READSET_ALLOC; - for (i=0; i < READSET_ALLOC; ++i) { - readset[i].active = 0; - } + /* malloc a new readset */ + readset = (READSET *)malloc((READSET_ALLOC+1)*sizeof(READSET)); + if (readset == NULL) { + return -1; + } + maxreadset = READSET_ALLOC; + for (i=0; i < READSET_ALLOC; ++i) { + readset[i].active = 0; + } - /* return first entry */ - return 0; - } + /* return first entry */ + return 0; + } - /* try to find a free readset entry */ - for (i=0; i < maxreadset; ++i) { - if (readset[i].active == 0) { - /* found a free readset entry */ - return i; - } - } + /* try to find a free readset entry */ + for (i=0; i < maxreadset; ++i) { + if (readset[i].active == 0) { + /* found a free readset entry */ + return i; + } + } - /* all readset entries are in use, allocate more */ - readset = (READSET *)realloc(readset, - (maxreadset+READSET_ALLOC) * sizeof(READSET)); - if (readset == NULL) { - return -1; - } - for (i=0; i < READSET_ALLOC; ++i) { - readset[i+maxreadset].active = 0; - } - maxreadset += READSET_ALLOC; + /* all readset entries are in use, allocate more */ + readset = (READSET *)realloc(readset, + (maxreadset+READSET_ALLOC) * sizeof(READSET)); + if (readset == NULL) { + return -1; + } + for (i=0; i < READSET_ALLOC; ++i) { + readset[i+maxreadset].active = 0; + } + maxreadset += READSET_ALLOC; - /* return the first newly allocated free entry */ - return maxreadset-READSET_ALLOC; + /* return the first newly allocated free entry */ + return maxreadset-READSET_ALLOC; } @@ -1084,67 +1084,67 @@ findfreeread(void) * This function returns the index of the readset entry, or -1 if error. * * given: - * name name given to read or include - * path full pathname of file - * sbuf stat of the path + * name name given to read or include + * path full pathname of file + * sbuf stat of the path */ S_FUNC int addreadset(char *name, char *path, struct stat *sbuf) { - int ret; /* index to return */ - size_t name_len; /* length of read set name */ - size_t path_len; /* length of path to read set name */ + int ret; /* index to return */ + size_t name_len; /* length of read set name */ + size_t path_len; /* length of path to read set name */ - /* find the inode */ - ret = isinoderead(sbuf); - if (ret < 0) { - /* not in readset, find a free node */ - ret = findfreeread(); - if (ret < 0) { - /* cannot find/form a free readset entry */ - return -1; - } - } else { - /* found an readset entry, free old readset data */ - if (readset[ret].name != NULL) { - free(readset[ret].name); - } - if (readset[ret].path != NULL) { - free(readset[ret].path); - } - } + /* find the inode */ + ret = isinoderead(sbuf); + if (ret < 0) { + /* not in readset, find a free node */ + ret = findfreeread(); + if (ret < 0) { + /* cannot find/form a free readset entry */ + return -1; + } + } else { + /* found an readset entry, free old readset data */ + if (readset[ret].name != NULL) { + free(readset[ret].name); + } + if (readset[ret].path != NULL) { + free(readset[ret].path); + } + } - /* load our information into the readset entry */ - name_len = strlen(name); - readset[ret].name = (char *)malloc(name_len+1); - if (readset[ret].name == NULL) { - return -1; - } - strlcpy(readset[ret].name, name, name_len+1); + /* load our information into the readset entry */ + name_len = strlen(name); + readset[ret].name = (char *)malloc(name_len+1); + if (readset[ret].name == NULL) { + return -1; + } + strlcpy(readset[ret].name, name, name_len+1); #if defined(_WIN32) || defined(_WIN64) - /* - * For _WIN32 or _WIN64, _fullpath expands the path to a fully qualified - * path name, which under _WIN32 or _WIN64 FAT and NTFS is unique, just - * like UNIX inodes. _fullpath also allocated the memory for - * this new longer path name. - */ - { - readset[ret].path = _fullpath(NULL, path, MAX_PATH); - if (readset[ret].path == NULL) { - return -1; - } - } + /* + * For _WIN32 or _WIN64, _fullpath expands the path to a fully qualified + * path name, which under _WIN32 or _WIN64 FAT and NTFS is unique, just + * like UNIX inodes. _fullpath also allocated the memory for + * this new longer path name. + */ + { + readset[ret].path = _fullpath(NULL, path, MAX_PATH); + if (readset[ret].path == NULL) { + return -1; + } + } #else /* Windows free systems */ - path_len = strlen(path); - readset[ret].path = (char *)malloc(path_len+1); - if (readset[ret].path == NULL) { - return -1; - } - strlcpy(readset[ret].path, path, path_len+1); + path_len = strlen(path); + readset[ret].path = (char *)malloc(path_len+1); + if (readset[ret].path == NULL) { + return -1; + } + strlcpy(readset[ret].path, path, path_len+1); #endif /* Windows free systems */ - readset[ret].inode = *sbuf; - readset[ret].active = 1; + readset[ret].inode = *sbuf; + readset[ret].active = 1; - /* return index of the newly added entry */ - return ret; + /* return index of the newly added entry */ + return ret; } diff --git a/int.h b/int.h index d610cab..9796e58 100644 --- a/int.h +++ b/int.h @@ -3,8 +3,8 @@ * * For general information on C integers, see: * - * https://en.cppreference.com/w/c/language/arithmetic_types - * https://en.cppreference.com/w/c/types/integer + * https://en.cppreference.com/w/c/language/arithmetic_types + * https://en.cppreference.com/w/c/types/integer * * Copyright (C) 2023 Landon Curt Noll * @@ -16,7 +16,7 @@ * * 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 + * 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 @@ -24,10 +24,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2023/08/22 21:14:25 - * File existed as early as: 2023 + * Under source code control: 2023/08/22 21:14:25 + * File existed as early as: 2023 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -132,7 +132,7 @@ /* * calc v2 is the last version where one might be able to use an old C compiler - * and/or tolerate missing include files + * and/or tolerate missing include files */ #if MAJOR_VER < 3 diff --git a/jump.c b/jump.c index aa02778..79957da 100644 --- a/jump.c +++ b/jump.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,17 +17,17 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1994/06/29 04:03:54 - * File existed as early as: 1994 + * Under source code control: 1994/06/29 04:03:54 + * File existed as early as: 1994 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * If x is divisible by a trivial prime (2,3,5,7,11), then: * - * x + jmpindx[ (x>>1)%JMPMOD ] + * x + jmpindx[ (x>>1)%JMPMOD ] * * is the value of the smallest value > x that is not divisible by a * trivial prime. JMPMOD is the product of the odd trivial primes. @@ -37,13 +37,13 @@ * * If x is not divisible by a trivial prime, then: * - * x + jmp[ -jmpindx[(x>>1)%JMPMOD] ] + * x + jmp[ -jmpindx[(x>>1)%JMPMOD] ] * * is the value of the smallest value > x that is not divisible by a * trivial prime. * * Instead of testing successive odd values, this system allows us to - * skip odd values divisible by trivial primes. This is process on the + * skip odd values divisible by trivial primes. This is process on the * average reduces the values we need to test by a factor of at least 2.4. */ @@ -51,7 +51,7 @@ #include "jump.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* diff --git a/jump.h b/jump.h index 102569e..c2d14d0 100644 --- a/jump.h +++ b/jump.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,17 +17,17 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1994/06/29 04:03:55 - * File existed as early as: 1994 + * Under source code control: 1994/06/29 04:03:55 + * File existed as early as: 1994 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * If x is divisible by a trivial prime (2,3,5,7,11), then: * - * x + jmpindx[ (x>>1)%JMPMOD ] + * x + jmpindx[ (x>>1)%JMPMOD ] * * is the value of the smallest value > x that is not divisible by a * trivial prime. JMPMOD is the product of the odd trivial primes. @@ -37,7 +37,7 @@ * * If x is not divisible by a trivial prime, then: * - * x + jmp[ -jmpindx[(x>>1)%JMPMOD] ] + * x + jmp[ -jmpindx[(x>>1)%JMPMOD] ] * * is the value of the smallest value > x that is not divisible by a * trivial prime. @@ -53,7 +53,7 @@ * that are not divisible by trivial primes. * * Instead of testing successive odd values, this system allows us to - * skip odd values divisible by trivial primes. This is process on the + * skip odd values divisible by trivial primes. This is process on the * average reduces the values we need to test by a factor of at least 2.4. */ @@ -62,7 +62,7 @@ #define INCLUDE_JUMP_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "have_const.h" # include "decl.h" #else @@ -74,9 +74,9 @@ /* * trivial prime CONSTants */ -#define JMPMOD (3*5*7*11) /* product of odd trivial primes */ -#define JMPSIZE (2*4*6*10) /* ints mod JMPMOD not div by trivial primes */ -#define JPRIME (prime+4) /* pointer to first non-trivial prime */ +#define JMPMOD (3*5*7*11) /* product of odd trivial primes */ +#define JMPSIZE (2*4*6*10) /* ints mod JMPMOD not div by trivial primes */ +#define JPRIME (prime+4) /* pointer to first non-trivial prime */ /* given x, return the index within jmpindx that applies */ #define jmpmod(x) (((x)>>1)%JMPMOD) diff --git a/label.c b/label.c index a2ed2a2..6cd0fb3 100644 --- a/label.c +++ b/label.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:17 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:17 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -32,12 +32,12 @@ #include "func.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -STATIC long labelcount; /* number of user labels defined */ -STATIC STRINGHEAD labelnames; /* list of user label names */ -STATIC LABEL labels[MAXLABELS]; /* list of user labels */ +STATIC long labelcount; /* number of user labels defined */ +STATIC STRINGHEAD labelnames; /* list of user label names */ +STATIC LABEL labels[MAXLABELS]; /* list of user labels */ /* @@ -46,8 +46,8 @@ STATIC LABEL labels[MAXLABELS]; /* list of user labels */ void initlabels(void) { - labelcount = 0; - initstr(&labelnames); + labelcount = 0; + initstr(&labelnames); } @@ -55,34 +55,34 @@ initlabels(void) * Define a user named label to have the offset of the next opcode. * * given: - * name label name + * name label name */ void definelabel(char *name) { - register LABEL *lp; /* current label */ - long i; /* current label index */ + register LABEL *lp; /* current label */ + long i; /* current label index */ - i = findstr(&labelnames, name); - if (i >= 0) { - lp = &labels[i]; - if (lp->l_offset >= 0) { - scanerror(T_NULL, "Label \"%s\" is multiply defined", - name); - return; - } - setlabel(lp); - return; - } - if (labelcount >= MAXLABELS) { - scanerror(T_NULL, "Too many labels in use"); - return; - } - lp = &labels[labelcount++]; - lp->l_chain = -1L; - lp->l_offset = (long)curfunc->f_opcodecount; - lp->l_name = addstr(&labelnames, name); - clearopt(); + i = findstr(&labelnames, name); + if (i >= 0) { + lp = &labels[i]; + if (lp->l_offset >= 0) { + scanerror(T_NULL, "Label \"%s\" is multiply defined", + name); + return; + } + setlabel(lp); + return; + } + if (labelcount >= MAXLABELS) { + scanerror(T_NULL, "Too many labels in use"); + return; + } + lp = &labels[labelcount++]; + lp->l_chain = -1L; + lp->l_offset = (long)curfunc->f_opcodecount; + lp->l_name = addstr(&labelnames, name); + clearopt(); } @@ -93,29 +93,29 @@ definelabel(char *name) * will be fixed up when the label is defined. * * given: - * name user symbol name + * name user symbol name */ void addlabel(char *name) { - register LABEL *lp; /* current label */ - long i; /* counter */ + register LABEL *lp; /* current label */ + long i; /* counter */ - for (i = labelcount, lp = labels; --i >= 0; lp++) { - if (strcmp(name, lp->l_name)) - continue; - uselabel(lp); - return; - } - if (labelcount >= MAXLABELS) { - scanerror(T_NULL, "Too many labels in use"); - return; - } - lp = &labels[labelcount++]; - lp->l_offset = -1L; - lp->l_chain = -1L; - lp->l_name = addstr(&labelnames, name); - uselabel(lp); + for (i = labelcount, lp = labels; --i >= 0; lp++) { + if (strcmp(name, lp->l_name)) + continue; + uselabel(lp); + return; + } + if (labelcount >= MAXLABELS) { + scanerror(T_NULL, "Too many labels in use"); + return; + } + lp = &labels[labelcount++]; + lp->l_offset = -1L; + lp->l_chain = -1L; + lp->l_name = addstr(&labelnames, name); + uselabel(lp); } @@ -125,15 +125,15 @@ addlabel(char *name) void checklabels(void) { - register LABEL *lp; /* label being checked */ - long i; /* counter */ + register LABEL *lp; /* label being checked */ + long i; /* counter */ - for (i = labelcount, lp = labels; --i >= 0; lp++) { - if (lp->l_offset >= 0) - continue; - scanerror(T_NULL, "Label \"%s\" was never defined", - lp->l_name); - } + for (i = labelcount, lp = labels; --i >= 0; lp++) { + if (lp->l_offset >= 0) + continue; + scanerror(T_NULL, "Label \"%s\" was never defined", + lp->l_name); + } } @@ -141,14 +141,14 @@ checklabels(void) * Clear an internal label for use. * * given: - * lp label being cleared + * lp label being cleared */ void clearlabel(LABEL *lp) { - lp->l_offset = -1L; - lp->l_chain = -1L; - lp->l_name = NULL; + lp->l_offset = -1L; + lp->l_chain = -1L; + lp->l_name = NULL; } @@ -158,27 +158,27 @@ clearlabel(LABEL *lp) * all such references are patched up. * * given: - * lp label being set + * lp label being set */ void setlabel(LABEL *lp) { - register FUNC *fp; /* current function */ - long curfix; /* offset of current location being fixed */ - long nextfix; /* offset of next location to fix up */ - unsigned long offset; /* offset of this label */ + register FUNC *fp; /* current function */ + long curfix; /* offset of current location being fixed */ + long nextfix; /* offset of next location to fix up */ + unsigned long offset; /* offset of this label */ - fp = curfunc; - offset = fp->f_opcodecount; - nextfix = (long)lp->l_chain; - while (nextfix >= 0) { - curfix = nextfix; - nextfix = (long)fp->f_opcodes[curfix]; - fp->f_opcodes[curfix] = offset; - } - lp->l_chain = -1L; - lp->l_offset = (long)offset; - clearopt(); + fp = curfunc; + offset = fp->f_opcodecount; + nextfix = (long)lp->l_chain; + while (nextfix >= 0) { + curfix = nextfix; + nextfix = (long)fp->f_opcodes[curfix]; + fp->f_opcodes[curfix] = offset; + } + lp->l_chain = -1L; + lp->l_offset = (long)offset; + clearopt(); } @@ -189,20 +189,20 @@ setlabel(LABEL *lp) * so the reference can be fixed when the label is defined. * * given: - * lp label being used + * lp label being used */ void uselabel(LABEL *lp) { - unsigned long offset; /* offset being added */ + unsigned long offset; /* offset being added */ - offset = curfunc->f_opcodecount; - if (lp->l_offset >= 0) { - curfunc->f_opcodes[curfunc->f_opcodecount++] = lp->l_offset; - return; - } - curfunc->f_opcodes[curfunc->f_opcodecount++] = lp->l_chain; - lp->l_chain = (long)offset; + offset = curfunc->f_opcodecount; + if (lp->l_offset >= 0) { + curfunc->f_opcodes[curfunc->f_opcodecount++] = lp->l_offset; + return; + } + curfunc->f_opcodes[curfunc->f_opcodecount++] = lp->l_chain; + lp->l_chain = (long)offset; } /* END CODE */ diff --git a/label.h b/label.h index fc349ac..4a05b2f 100644 --- a/label.h +++ b/label.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:33 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:33 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,23 +28,23 @@ #define INCLUDE_LABEL_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "zmath.h" #else # include #endif -#define NULL_LABEL ((LABEL *) 0) +#define NULL_LABEL ((LABEL *) 0) /* * Label structures. */ typedef struct { - long l_offset; /* offset into code of label */ - long l_chain; /* offset into code of undefined chain */ - char *l_name; /* name of label if any */ + long l_offset; /* offset into code of label */ + long l_chain; /* offset into code of undefined chain */ + char *l_name; /* name of label if any */ } LABEL; diff --git a/lib_calc.c b/lib_calc.c index 487e8bc..ce1578b 100644 --- a/lib_calc.c +++ b/lib_calc.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1996/06/17 18:06:19 - * File existed as early as: 1996 + * Under source code control: 1996/06/17 18:06:19 + * File existed as early as: 1996 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -95,7 +95,7 @@ typedef struct {int fd;} ttystruct; #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* @@ -113,53 +113,53 @@ E_FUNC uid_t geteuid(); /* * Common definitions */ -int use_old_std = false; /* true => use old classic configuration */ -int abortlevel; /* current level of aborts */ -bool inputwait; /* true if in a terminal input wait */ -char *program = "calc"; /* our name */ -char *base_name = "calc"; /* basename of our name */ -char cmdbuf[MAXCMD+1+1+1]; /* command line expression + "\n\0" + guard */ -run run_state = RUN_ZERO; /* calc startup run state */ -char *script_name = NULL; /* program name or -f filename arg or NULL */ +int use_old_std = false; /* true => use old classic configuration */ +int abortlevel; /* current level of aborts */ +bool inputwait; /* true if in a terminal input wait */ +char *program = "calc"; /* our name */ +char *base_name = "calc"; /* basename of our name */ +char cmdbuf[MAXCMD+1+1+1]; /* command line expression + "\n\0" + guard */ +run run_state = RUN_ZERO; /* calc startup run state */ +char *script_name = NULL; /* program name or -f filename arg or NULL */ /* * global permissions */ -int allow_read = true; /* false => may not open any files for reading */ +int allow_read = true; /* false => may not open any files for reading */ int allow_write = true; /* false => may not open any files for writing */ -int allow_exec = true; /* false => may not execute any commands */ +int allow_exec = true; /* false => may not execute any commands */ /* * global flags */ -int p_flag = false; /* true => pipe mode */ -int q_flag = false; /* true => don't execute rc files */ -int u_flag = false; /* true => unbuffer stdin and stdout */ -int d_flag = false; /* true => disable heading, resource_debug == 0 */ -int c_flag = false; /* true => continue on error if permitted */ -int i_flag = false; /* true => go interactive if permitted */ -int s_flag = false; /* true => keep args as strings for argv() */ +int p_flag = false; /* true => pipe mode */ +int q_flag = false; /* true => don't execute rc files */ +int u_flag = false; /* true => unbuffer stdin and stdout */ +int d_flag = false; /* true => disable heading, resource_debug == 0 */ +int c_flag = false; /* true => continue on error if permitted */ +int i_flag = false; /* true => go interactive if permitted */ +int s_flag = false; /* true => keep args as strings for argv() */ /* * global values */ -char *calcpath = NULL; /* $CALCPATH or default */ -char *calcrc = NULL; /* $CALCRC or default */ -char *calcbindings = NULL; /* $CALCBINDINGS or default */ -char *home = NULL; /* $HOME or default */ -char *pager = NULL; /* $PAGER or default */ -char *shell = NULL; /* $SHELL or default */ -char *calc_history = NULL; /* $CALCHISTFILE or ~/.calc_history */ -char *calc_helpdir = NULL; /* $CALCHELP or /usr/local/share/calc/help */ +char *calcpath = NULL; /* $CALCPATH or default */ +char *calcrc = NULL; /* $CALCRC or default */ +char *calcbindings = NULL; /* $CALCBINDINGS or default */ +char *home = NULL; /* $HOME or default */ +char *pager = NULL; /* $PAGER or default */ +char *shell = NULL; /* $SHELL or default */ +char *calc_history = NULL; /* $CALCHISTFILE or ~/.calc_history */ +char *calc_helpdir = NULL; /* $CALCHELP or /usr/local/share/calc/help */ /* $CALCCUSTOMHELP or /usr/local/share/calc/custhelp */ char *calc_customhelpdir = NULL; -int stdin_tty = false; /* true if stdin is a tty */ -int havecommands = false; /* true if have one or more cmd args */ -long stoponerror = 0; /* >0 => stop, <0 => continue, ==0 => use -c */ -bool abort_now = false; /* true => go interactive now, if permitted */ +int stdin_tty = false; /* true if stdin is a tty */ +int havecommands = false; /* true if have one or more cmd args */ +long stoponerror = 0; /* >0 => stop, <0 => continue, ==0 => use -c */ +bool abort_now = false; /* true => go interactive now, if permitted */ /* non-zero => calc_scanerr_jmpbuf ready */ int calc_use_scanerr_jmpbuf = 0; @@ -183,17 +183,17 @@ int calc_print_scanwarn_msg = 1; /* number of parse/scan warnings found */ unsigned long calc_warn_cnt = 0; -int argc_value = 0; /* count of argv[] strings for argv() builtin */ -char **argv_value = NULL; /* argv[] strings for argv() builtin */ +int argc_value = 0; /* count of argv[] strings for argv() builtin */ +char **argv_value = NULL; /* argv[] strings for argv() builtin */ -int no_env = false; /* true (-e) => ignore env vars on startup */ -long errmax = ERRMAX; /* if >= 0, maximum value for errcount */ +int no_env = false; /* true (-e) => ignore env vars on startup */ +long errmax = ERRMAX; /* if >= 0, maximum value for errcount */ -NUMBER *epsilon_default; /* default allowed error for float calcs */ +NUMBER *epsilon_default; /* default allowed error for float calcs */ -char *calc_debug = NULL; /* !=NULL => value of config("calc_debug") */ -char *resource_debug = NULL; /* !=NULL => config("resource_debug") value */ -char *user_debug = NULL; /* !=NULL => value of config("user_debug") */ +char *calc_debug = NULL; /* !=NULL => value of config("calc_debug") */ +char *resource_debug = NULL; /* !=NULL => config("resource_debug") value */ +char *user_debug = NULL; /* !=NULL => value of config("user_debug") */ /* @@ -209,14 +209,14 @@ E_FUNC void reinitialize(void); /* * static declarations */ -STATIC int init_done = 0; /* 1 => we already initialized */ -STATIC int *fd_setup = NULL; /* fd's setup for interaction or -1 */ -STATIC int fd_setup_len = 0; /* number of fd's in fd_setup */ -STATIC ttystruct *fd_orig = NULL; /* fd original state */ -STATIC ttystruct *fd_cur = NULL; /* fd current state */ -S_FUNC void initenv(void); /* setup calc environment */ -S_FUNC int find_tty_state(int fd); /* find slot for saved tty state */ -STATIC bool initialized = false; /* true => initialize() has been run */ +STATIC int init_done = 0; /* 1 => we already initialized */ +STATIC int *fd_setup = NULL; /* fd's setup for interaction or -1 */ +STATIC int fd_setup_len = 0; /* number of fd's in fd_setup */ +STATIC ttystruct *fd_orig = NULL; /* fd original state */ +STATIC ttystruct *fd_cur = NULL; /* fd current state */ +S_FUNC void initenv(void); /* setup calc environment */ +S_FUNC int find_tty_state(int fd); /* find slot for saved tty state */ +STATIC bool initialized = false; /* true => initialize() has been run */ /* @@ -228,143 +228,143 @@ STATIC bool initialized = false; /* true => initialize() has been run */ void libcalc_call_me_first(void) { - char *p; + char *p; - /* - * do nothing if we are initialized already - */ - if (init_done) { - return; - } + /* + * do nothing if we are initialized already + */ + if (init_done) { + return; + } - /* - * Disable SIGPIPE so that the pipe to the help file pager will - * not stop calc. - */ + /* + * Disable SIGPIPE so that the pipe to the help file pager will + * not stop calc. + */ #if !defined(_WIN32) && !defined(_WIN64) - (void) signal(SIGPIPE, SIG_IGN); + (void) signal(SIGPIPE, SIG_IGN); #endif - /* - * determine the basename - */ - if (program != NULL) { - p = strrchr(program, '/'); + /* + * determine the basename + */ + if (program != NULL) { + p = strrchr(program, '/'); #if defined(_WIN32) || defined(_WIN64) - if (p == NULL) { - p = strrchr(program, '\\'); - } + if (p == NULL) { + p = strrchr(program, '\\'); + } #endif - if (p == NULL) { - base_name = program; - } else { - base_name = p+1; - } - } + if (p == NULL) { + base_name = program; + } else { + base_name = p+1; + } + } - /* - * initialize old and new configuration values - */ - newstd.epsilon = &_qonesqbase_; /* magic to fake early str2q() */ - if (program == NULL) { - fprintf(stderr, "libcalc_call_me_first: FATAL: " - "program is NULL\n"); - exit(80); - } - newstd.program = strdup(program); - if (newstd.program == NULL) { - fprintf(stderr, "libcalc_call_me_first: FATAL: " - "cannot strdup program string\n"); - exit(81); - } - if (base_name == NULL) { - fprintf(stderr, "libcalc_call_me_first: FATAL: " - "base_name is NULL\n"); - exit(82); - } - newstd.base_name = strdup(base_name); - if (newstd.base_name == NULL) { - fprintf(stderr, "libcalc_call_me_first: FATAL: " - "cannot strdup base_name string\n"); - exit(83); - } - p = version(); - if (p == NULL) { - fprintf(stderr, "libcalc_call_me_first: FATAL: " - "version() returned NULL\n"); - exit(84); - } - newstd.version = strdup(p); - if (newstd.version == NULL) { - fprintf(stderr, "libcalc_call_me_first: FATAL: " - "cannot strdup return from version()\n"); - exit(85); - } - conf = config_copy(&newstd); /* more magic to fake early str2q() */ - conf->tab_ok = false; - newstd.epsilon = str2q(EPSILON_DEFAULT); - oldstd.epsilon = str2q(EPSILON_DEFAULT); + /* + * initialize old and new configuration values + */ + newstd.epsilon = &_qonesqbase_; /* magic to fake early str2q() */ + if (program == NULL) { + fprintf(stderr, "libcalc_call_me_first: FATAL: " + "program is NULL\n"); + exit(80); + } + newstd.program = strdup(program); + if (newstd.program == NULL) { + fprintf(stderr, "libcalc_call_me_first: FATAL: " + "cannot strdup program string\n"); + exit(81); + } + if (base_name == NULL) { + fprintf(stderr, "libcalc_call_me_first: FATAL: " + "base_name is NULL\n"); + exit(82); + } + newstd.base_name = strdup(base_name); + if (newstd.base_name == NULL) { + fprintf(stderr, "libcalc_call_me_first: FATAL: " + "cannot strdup base_name string\n"); + exit(83); + } + p = version(); + if (p == NULL) { + fprintf(stderr, "libcalc_call_me_first: FATAL: " + "version() returned NULL\n"); + exit(84); + } + newstd.version = strdup(p); + if (newstd.version == NULL) { + fprintf(stderr, "libcalc_call_me_first: FATAL: " + "cannot strdup return from version()\n"); + exit(85); + } + conf = config_copy(&newstd); /* more magic to fake early str2q() */ + conf->tab_ok = false; + newstd.epsilon = str2q(EPSILON_DEFAULT); + oldstd.epsilon = str2q(EPSILON_DEFAULT); - /* - * make newstd our default config, unless -O - */ - config_free(conf); - if (use_old_std) { - conf = config_copy(&oldstd); - } else { - conf = config_copy(&newstd); - } + /* + * make newstd our default config, unless -O + */ + config_free(conf); + if (use_old_std) { + conf = config_copy(&oldstd); + } else { + conf = config_copy(&newstd); + } - /* - * -d turns off resource_debug and tilde - */ - if (d_flag) { - conf->resource_debug = 0; - conf->tilde_ok = 0; - conf->tilde_space = 0; - } + /* + * -d turns off resource_debug and tilde + */ + if (d_flag) { + conf->resource_debug = 0; + conf->tilde_ok = 0; + conf->tilde_space = 0; + } - /* - * -p turns off tab - */ - if (p_flag) { - conf->tab_ok = 0; - } + /* + * -p turns off tab + */ + if (p_flag) { + conf->tab_ok = 0; + } - /* - * -D flags can change calc_debug, resource_debug of user_debug - */ - if (calc_debug) { - conf->calc_debug = strtol(calc_debug, NULL, 0); - } - if (resource_debug) { - conf->resource_debug = strtol(resource_debug, NULL, 0); - } - if (user_debug) { - conf->user_debug = strtol(user_debug, NULL, 0); - } + /* + * -D flags can change calc_debug, resource_debug of user_debug + */ + if (calc_debug) { + conf->calc_debug = strtol(calc_debug, NULL, 0); + } + if (resource_debug) { + conf->resource_debug = strtol(resource_debug, NULL, 0); + } + if (user_debug) { + conf->user_debug = strtol(user_debug, NULL, 0); + } - /* - * initialize - */ - initialize(); + /* + * initialize + */ + initialize(); - /* - * verify error_table[] array and setup private_error_alias[] array - */ - verify_error_table(); + /* + * verify error_table[] array and setup private_error_alias[] array + */ + verify_error_table(); - /* - * ready to rock & roll .. - */ - if (conf->calc_debug & CALCDBG_RUNSTATE) { - printf("libcalc_call_me_first: run_state from %s to %s\n", - run_state_name(run_state), - run_state_name(RUN_BEGIN)); - } - run_state = RUN_BEGIN; - init_done = 1; - return; + /* + * ready to rock & roll .. + */ + if (conf->calc_debug & CALCDBG_RUNSTATE) { + printf("libcalc_call_me_first: run_state from %s to %s\n", + run_state_name(run_state), + run_state_name(RUN_BEGIN)); + } + run_state = RUN_BEGIN; + init_done = 1; + return; } @@ -374,63 +374,63 @@ libcalc_call_me_first(void) void initialize(void) { - /* - * firewall - */ - if (initialized) { - return; - } + /* + * firewall + */ + if (initialized) { + return; + } - /* - * ZVALUE io initialization - */ - zio_init(); + /* + * ZVALUE io initialization + */ + zio_init(); - /* - * process the environment - */ - initenv(); + /* + * process the environment + */ + initenv(); - /* - * initialize I/O - */ - file_init(); + /* + * initialize I/O + */ + file_init(); - /* - * initialize file I/O - */ - resetinput(); + /* + * initialize file I/O + */ + resetinput(); - /* - * initialize calc internal data structures - */ - inittokens(); - initglobals(); - initfunctions(); - initstack(); + /* + * initialize calc internal data structures + */ + inittokens(); + initglobals(); + initfunctions(); + initstack(); - /* - * initialize calc math - */ - math_cleardiversions(); - math_setfp(stdout); - math_setmode(MODE_INITIAL); - math_setdigits(DISPLAY_DEFAULT); - conf->maxprint = MAXPRINT_DEFAULT; + /* + * initialize calc math + */ + math_cleardiversions(); + math_setfp(stdout); + math_setmode(MODE_INITIAL); + math_setdigits(DISPLAY_DEFAULT); + conf->maxprint = MAXPRINT_DEFAULT; #if defined(CUSTOM) - /* - * initialize custom registers - */ - if (allow_custom) { - init_custreg(); - } + /* + * initialize custom registers + */ + if (allow_custom) { + init_custreg(); + } #endif /* CUSTOM */ - /* - * note that we are done - */ - initialized = true; + /* + * note that we are done + */ + initialized = true; } @@ -440,18 +440,18 @@ initialize(void) void reinitialize(void) { - /* - * process commands (from stdin, not the command line) - */ - abortlevel = 0; - _math_abort_ = false; - inputwait = false; - math_cleardiversions(); - math_setfp(stdout); - resetscopes(); - resetinput(); - inittokens(); - (void) openterminal(); + /* + * process commands (from stdin, not the command line) + */ + abortlevel = 0; + _math_abort_ = false; + inputwait = false; + math_cleardiversions(); + math_setfp(stdout); + resetscopes(); + resetinput(); + inittokens(); + (void) openterminal(); } @@ -459,20 +459,20 @@ reinitialize(void) * cvmalloc_error - for users of the SGI Workshop Debugger * * usage: - * message - error message passed along via libmalloc_cv.a + * message - error message passed along via libmalloc_cv.a */ void cvmalloc_error(char *message) { - /* firewall */ - if (message == NULL) { - fprintf(stderr, "cvmalloc_error message is NULL\n"); - return; - } + /* firewall */ + if (message == NULL) { + fprintf(stderr, "cvmalloc_error message is NULL\n"); + return; + } - /* print message and return */ - fprintf(stderr, "cvmalloc_error: %s\n", message); - return; + /* print message and return */ + fprintf(stderr, "cvmalloc_error: %s\n", message); + return; } @@ -489,103 +489,103 @@ S_FUNC void initenv(void) { #if !defined(_WIN32) && !defined(_WIN64) - struct passwd *ent; /* our password entry */ + struct passwd *ent; /* our password entry */ #endif - char *c; + char *c; - /* determine the $CALCPATH value */ - c = (no_env ? NULL : getenv(CALCPATH)); - calcpath = (c ? strdup(c) : NULL); - if (calcpath == NULL) - calcpath = DEFAULTCALCPATH; + /* determine the $CALCPATH value */ + c = (no_env ? NULL : getenv(CALCPATH)); + calcpath = (c ? strdup(c) : NULL); + if (calcpath == NULL) + calcpath = DEFAULTCALCPATH; - /* determine the $CALCRC value */ - c = (no_env ? NULL : getenv(CALCRC)); - calcrc = (c ? strdup(c) : NULL); - if (calcrc == NULL) - calcrc = DEFAULTCALCRC; - if (strlen(calcrc) > MAX_CALCRC) { - math_error("The $CALCRC variable is longer than %d chars", - MAX_CALCRC); - not_reached(); - } + /* determine the $CALCRC value */ + c = (no_env ? NULL : getenv(CALCRC)); + calcrc = (c ? strdup(c) : NULL); + if (calcrc == NULL) + calcrc = DEFAULTCALCRC; + if (strlen(calcrc) > MAX_CALCRC) { + math_error("The $CALCRC variable is longer than %d chars", + MAX_CALCRC); + not_reached(); + } - /* determine the $CALCBINDINGS value */ - c = (no_env ? NULL : getenv(CALCBINDINGS)); - calcbindings = (c ? strdup(c) : NULL); - if (calcbindings == NULL) - calcbindings = DEFAULTCALCBINDINGS; + /* determine the $CALCBINDINGS value */ + c = (no_env ? NULL : getenv(CALCBINDINGS)); + calcbindings = (c ? strdup(c) : NULL); + if (calcbindings == NULL) + calcbindings = DEFAULTCALCBINDINGS; - /* determine the $HOME value */ - c = (no_env ? NULL : getenv(HOME)); - home = (c ? strdup(c) : NULL); + /* determine the $HOME value */ + c = (no_env ? NULL : getenv(HOME)); + home = (c ? strdup(c) : NULL); #if defined(_WIN32) || defined(_WIN64) - if (home == NULL || home[0] == '\0') { - /* free home if it was previously allocated, but empty */ - if (home != NULL) { - free(home); - } - /* just assume . is home if all else fails */ - home = strdup("."); - } + if (home == NULL || home[0] == '\0') { + /* free home if it was previously allocated, but empty */ + if (home != NULL) { + free(home); + } + /* just assume . is home if all else fails */ + home = strdup("."); + } #else /* Windows free systems */ - if (home == NULL || home[0] == '\0') { - /* free home if it was previously allocated, but empty */ - if (home != NULL) { - free(home); - } - /* try using the home directory of current effective UID */ - ent = (struct passwd *)getpwuid(geteuid()); - if (ent == NULL || ent->pw_dir == NULL || - ent->pw_dir[0] == '\0') { - /* just assume . is home if all else fails */ - home = strdup("."); - } else { - /* use home directory of current effective UID */ - home = strdup(ent->pw_dir); - } - } + if (home == NULL || home[0] == '\0') { + /* free home if it was previously allocated, but empty */ + if (home != NULL) { + free(home); + } + /* try using the home directory of current effective UID */ + ent = (struct passwd *)getpwuid(geteuid()); + if (ent == NULL || ent->pw_dir == NULL || + ent->pw_dir[0] == '\0') { + /* just assume . is home if all else fails */ + home = strdup("."); + } else { + /* use home directory of current effective UID */ + home = strdup(ent->pw_dir); + } + } #endif /* Windows free systems */ - /* paranoia */ - if (home == NULL) { - math_error("Unable to allocate string for $HOME"); - not_reached(); - } + /* paranoia */ + if (home == NULL) { + math_error("Unable to allocate string for $HOME"); + not_reached(); + } - /* determine the $PAGER value */ - c = (no_env ? NULL : getenv(PAGER)); - pager = (c ? strdup(c) : NULL); - if (pager == NULL || *pager == '\0') - pager = DEFAULTCALCPAGER; + /* determine the $PAGER value */ + c = (no_env ? NULL : getenv(PAGER)); + pager = (c ? strdup(c) : NULL); + if (pager == NULL || *pager == '\0') + pager = DEFAULTCALCPAGER; - /* determine the $SHELL value */ - c = (no_env ? NULL : getenv(SHELL)); - shell = (c ? strdup(c) : NULL); - if (shell == NULL || *shell == '\0') - shell = DEFAULTSHELL; + /* determine the $SHELL value */ + c = (no_env ? NULL : getenv(SHELL)); + shell = (c ? strdup(c) : NULL); + if (shell == NULL || *shell == '\0') + shell = DEFAULTSHELL; - /* determine the $CALCHISTFILE value */ - c = (no_env ? NULL : getenv(CALCHISTFILE)); - calc_history = (c ? strdup(c) : NULL); - if (calc_history == NULL || *calc_history == '\0') - calc_history = NULL; /* will use ~/.calc_history */ + /* determine the $CALCHISTFILE value */ + c = (no_env ? NULL : getenv(CALCHISTFILE)); + calc_history = (c ? strdup(c) : NULL); + if (calc_history == NULL || *calc_history == '\0') + calc_history = NULL; /* will use ~/.calc_history */ - /* determine the $CALCHELP value */ - c = (no_env ? NULL : getenv(CALCHELP)); - calc_helpdir = (c ? strdup(c) : NULL); - if (calc_helpdir == NULL || *calc_helpdir == '\0') { - /* will use /usr/local/share/calc/help */ - calc_helpdir = HELPDIR; - } + /* determine the $CALCHELP value */ + c = (no_env ? NULL : getenv(CALCHELP)); + calc_helpdir = (c ? strdup(c) : NULL); + if (calc_helpdir == NULL || *calc_helpdir == '\0') { + /* will use /usr/local/share/calc/help */ + calc_helpdir = HELPDIR; + } #if defined(CUSTOM) - /* determine the $CALCCUSTOMHELP value */ - c = (no_env ? NULL : getenv(CALCCUSTOMHELP)); - calc_customhelpdir = (c ? strdup(c) : NULL); - if (calc_customhelpdir == NULL || *calc_customhelpdir == '\0') { - /* will use /usr/local/share/calc/custhelp */ - calc_customhelpdir = CUSTOMHELPDIR; - } + /* determine the $CALCCUSTOMHELP value */ + c = (no_env ? NULL : getenv(CALCCUSTOMHELP)); + calc_customhelpdir = (c ? strdup(c) : NULL); + if (calc_customhelpdir == NULL || *calc_customhelpdir == '\0') { + /* will use /usr/local/share/calc/custhelp */ + calc_customhelpdir = CUSTOMHELPDIR; + } #endif /* CUSTOM */ } @@ -598,61 +598,61 @@ initenv(void) * this function is to free storage that might otherwise go unused. * * NOTE: If, for any reason, you need to do more libcalc.a processing, - * then you will need to call libcalc_call_me_first() again. + * then you will need to call libcalc_call_me_first() again. */ void libcalc_call_me_last(void) { - int i; + int i; - /* - * firewall - */ - if (init_done == 0) { - return; - } + /* + * firewall + */ + if (init_done == 0) { + return; + } - /* - * free the configuration - */ - config_free(conf); + /* + * free the configuration + */ + config_free(conf); - /* - * free Blum generator state - */ - random_libcalc_cleanup(); + /* + * free Blum generator state + */ + random_libcalc_cleanup(); - /* - * free script_name - */ - if (script_name != NULL) { - free(script_name); - script_name = NULL; - } + /* + * free script_name + */ + if (script_name != NULL) { + free(script_name); + script_name = NULL; + } - /* - * restore all changed descriptor states - */ - for (i=0; i < fd_setup_len; ++i) { - if (fd_setup[i] >= 0) { - if (conf->calc_debug & CALCDBG_TTY) - printf("libcalc_call_me_last: fd %d " - "not in original state, " - "restoring it", fd_setup[i]); - orig_tty(fd_setup[i]); - } - } + /* + * restore all changed descriptor states + */ + for (i=0; i < fd_setup_len; ++i) { + if (fd_setup[i] >= 0) { + if (conf->calc_debug & CALCDBG_TTY) + printf("libcalc_call_me_last: fd %d " + "not in original state, " + "restoring it", fd_setup[i]); + orig_tty(fd_setup[i]); + } + } - /* - * free all globals - */ - freeglobals(); + /* + * free all globals + */ + freeglobals(); - /* - * all done - */ - init_done = 0; - return; + /* + * all done + */ + init_done = 0; + return; } @@ -662,27 +662,27 @@ libcalc_call_me_last(void) char * run_state_name(run state) { - switch (state) { - case RUN_ZERO: - return "ZERO"; - case RUN_BEGIN: - return "BEGIN"; - case RUN_RCFILES: - return "RCFILES"; - case RUN_PRE_CMD_ARGS: - return "PRE_CMD_ARGS"; - case RUN_CMD_ARGS: - return "CMD_ARGS"; - case RUN_PRE_TOP_LEVEL: - return "PRE_TOP_LEVEL"; - case RUN_TOP_LEVEL: - return "TOP_LEVEL"; - case RUN_EXIT: - return "EXIT"; - case RUN_EXIT_WITH_ERROR: - return "EXIT_WITH_ERROR"; - } - return "RUN_invalid"; + switch (state) { + case RUN_ZERO: + return "ZERO"; + case RUN_BEGIN: + return "BEGIN"; + case RUN_RCFILES: + return "RCFILES"; + case RUN_PRE_CMD_ARGS: + return "PRE_CMD_ARGS"; + case RUN_CMD_ARGS: + return "CMD_ARGS"; + case RUN_PRE_TOP_LEVEL: + return "PRE_TOP_LEVEL"; + case RUN_TOP_LEVEL: + return "TOP_LEVEL"; + case RUN_EXIT: + return "EXIT"; + case RUN_EXIT_WITH_ERROR: + return "EXIT_WITH_ERROR"; + } + return "RUN_invalid"; } @@ -694,37 +694,37 @@ calc_strdup(CONST char *s1) { #if defined(HAVE_STRDUP) - return strdup(s1); + return strdup(s1); #else /* HAVE_STRDUP */ - char *ret; /* return string */ - size_t s1_len; /* length of string to duplicate */ + char *ret; /* return string */ + size_t s1_len; /* length of string to duplicate */ - /* - * firewall - */ - if (s1 == NULL) { - return NULL; - } + /* + * firewall + */ + if (s1 == NULL) { + return NULL; + } - /* - * allocate duplicate storage - */ - s1_len = strlen(s1); - ret = (char *)malloc(s1_len+1); + /* + * allocate duplicate storage + */ + s1_len = strlen(s1); + ret = (char *)malloc(s1_len+1); - /* - * if we have storage, duplicate the string - */ - if (ret != NULL) { - strlcpy(ret, s1, s1_len+1); - } + /* + * if we have storage, duplicate the string + */ + if (ret != NULL) { + strlcpy(ret, s1, s1_len+1); + } - /* - * return the new string, or NULL if malloc failed - */ - return ret; + /* + * return the new string, or NULL if malloc failed + */ + return ret; #endif /* HAVE_STRDUP */ } @@ -734,105 +734,105 @@ calc_strdup(CONST char *s1) * find_tty_state - establish a new tty state * * Given: - * fd file descriptor to establish a new tty state for + * fd file descriptor to establish a new tty state for * * Returns: - * indx The index into fd_setup[], fd_orig[] and fd_cur[] to use or -1 + * indx The index into fd_setup[], fd_orig[] and fd_cur[] to use or -1 */ S_FUNC int find_tty_state(int fd) { - int *new_fd_setup; /* new fd_setup array */ - ttystruct *new_fd_orig; /* new fd_orig array */ - ttystruct *new_fd_cur; /* new fd_cur array */ - int i; + int *new_fd_setup; /* new fd_setup array */ + ttystruct *new_fd_orig; /* new fd_orig array */ + ttystruct *new_fd_cur; /* new fd_cur array */ + int i; - /* - * firewall: must be > 0 - */ - if (fd < 0) { - /* bad descriptor */ - return -1; - } + /* + * firewall: must be > 0 + */ + if (fd < 0) { + /* bad descriptor */ + return -1; + } - /* - * case: need to initially malloc some state - */ - if (fd_setup_len <= 0 || fd_setup == NULL || fd_orig == NULL) { + /* + * case: need to initially malloc some state + */ + if (fd_setup_len <= 0 || fd_setup == NULL || fd_orig == NULL) { - /* setup for a single descriptor */ - fd_setup = (int *)malloc(sizeof(fd_setup[0])); - if (fd_setup == NULL) { - return -1; - } - fd_setup[0] = -1; - fd_orig = (ttystruct *)malloc(sizeof(fd_orig[0])); - if (fd_orig == NULL) { - return -1; - } - fd_cur = (ttystruct *)malloc(sizeof(fd_cur[0])); - if (fd_cur == NULL) { - return -1; - } - fd_setup_len = 1; - } + /* setup for a single descriptor */ + fd_setup = (int *)malloc(sizeof(fd_setup[0])); + if (fd_setup == NULL) { + return -1; + } + fd_setup[0] = -1; + fd_orig = (ttystruct *)malloc(sizeof(fd_orig[0])); + if (fd_orig == NULL) { + return -1; + } + fd_cur = (ttystruct *)malloc(sizeof(fd_cur[0])); + if (fd_cur == NULL) { + return -1; + } + fd_setup_len = 1; + } - /* - * look for an existing tty state for the descriptor - */ - for (i=0; i < fd_setup_len; ++i) { + /* + * look for an existing tty state for the descriptor + */ + for (i=0; i < fd_setup_len; ++i) { - /* case: found existing tty state, return index */ - if (fd_setup[i] == fd) { - return i; - } - } + /* case: found existing tty state, return index */ + if (fd_setup[i] == fd) { + return i; + } + } - /* - * no tty state exists for the descriptor, look for empty slot - */ - for (i=0; i < fd_setup_len; ++i) { + /* + * no tty state exists for the descriptor, look for empty slot + */ + for (i=0; i < fd_setup_len; ++i) { - /* case: found an empty slot, so return it */ - if (fd_setup[i] < 0) { - return i; - } - } + /* case: found an empty slot, so return it */ + if (fd_setup[i] < 0) { + return i; + } + } - /* - * no empty slots exist, realloc another slot - */ - /* expand fd_orig as an original pre-modified copy of fd_setup */ - new_fd_orig = (ttystruct *)realloc(fd_orig, sizeof(fd_orig[0]) * - (fd_setup_len+1)); - if (new_fd_orig == NULL) { - return -1; - } - fd_orig = new_fd_orig; - memcpy(fd_orig, fd_setup, sizeof(fd_orig[0]) * (fd_setup_len+1)); + /* + * no empty slots exist, realloc another slot + */ + /* expand fd_orig as an original pre-modified copy of fd_setup */ + new_fd_orig = (ttystruct *)realloc(fd_orig, sizeof(fd_orig[0]) * + (fd_setup_len+1)); + if (new_fd_orig == NULL) { + return -1; + } + fd_orig = new_fd_orig; + memcpy(fd_orig, fd_setup, sizeof(fd_orig[0]) * (fd_setup_len+1)); - /* expand fd_setup */ - new_fd_setup = (int *)realloc(fd_setup, sizeof(fd_setup[0]) * - (fd_setup_len+1)); - if (new_fd_setup == NULL) { - return -1; - } - fd_setup = new_fd_setup; - new_fd_setup[fd_setup_len] = -1; + /* expand fd_setup */ + new_fd_setup = (int *)realloc(fd_setup, sizeof(fd_setup[0]) * + (fd_setup_len+1)); + if (new_fd_setup == NULL) { + return -1; + } + fd_setup = new_fd_setup; + new_fd_setup[fd_setup_len] = -1; - /* expand fd_cur */ - new_fd_cur = (ttystruct *)realloc(fd_cur, sizeof(fd_cur[0]) * - (fd_setup_len+1)); - if (new_fd_cur == NULL) { - return -1; - } - fd_cur = new_fd_cur; + /* expand fd_cur */ + new_fd_cur = (ttystruct *)realloc(fd_cur, sizeof(fd_cur[0]) * + (fd_setup_len+1)); + if (new_fd_cur == NULL) { + return -1; + } + fd_cur = new_fd_cur; - /* expand fd setup length */ - ++fd_setup_len; + /* expand fd setup length */ + ++fd_setup_len; - /* return the new slot */ - return fd_setup_len-1; + /* return the new slot */ + return fd_setup_len-1; } @@ -842,115 +842,115 @@ find_tty_state(int fd) * Calc wants, in effect, cbreak on and echo off. * * Given: - * fd the descriptor for calc's interactive use + * fd the descriptor for calc's interactive use * * Returns: - * true state change was successful - * false unable to change state of descriptor for interactive use + * true state change was successful + * false unable to change state of descriptor for interactive use */ bool calc_tty(int fd) { - int slot; /* the saved descriptor slot or -1 */ + int slot; /* the saved descriptor slot or -1 */ - /* - * grab the saved slot for this descriptor - */ - slot = find_tty_state(fd); - if (slot < 0) { - if (conf->calc_debug & CALCDBG_TTY) - printf("calc_tty: Cannot get saved descriptor slot\n"); - return false; - } + /* + * grab the saved slot for this descriptor + */ + slot = find_tty_state(fd); + if (slot < 0) { + if (conf->calc_debug & CALCDBG_TTY) + printf("calc_tty: Cannot get saved descriptor slot\n"); + return false; + } #if defined(USE_SGTTY) - /* - * USE_SGTTY tty state method - */ - /* save original state if needed */ - if (fd_setup[slot] < 0 && ioctl(fd, TIOCGETP, fd_orig+slot) < 0) { - if (conf->calc_debug & CALCDBG_TTY) - printf("calc_tty: Cannot TIOCGETP fd %d\n", fd); - return false; - } - /* setup for new state */ - fd_cur[slot] = fd_orig[slot]; - fd_cur[slot].sg_flags &= ~ECHO; - fd_cur[slot].sg_flags |= CBREAK; - /* enable new state */ - if (ioctl(fd, TIOCSETP, fd_cur+slot) < 0) { - if (conf->calc_debug & CALCDBG_TTY) - printf("calc_tty: Cannot TIOCSETP fd %d\n", fd); - return false; - } - if (conf->calc_debug & CALCDBG_TTY) - printf("calc_tty: stty -ECHO +CBREAK: fd %d\n", fd); + /* + * USE_SGTTY tty state method + */ + /* save original state if needed */ + if (fd_setup[slot] < 0 && ioctl(fd, TIOCGETP, fd_orig+slot) < 0) { + if (conf->calc_debug & CALCDBG_TTY) + printf("calc_tty: Cannot TIOCGETP fd %d\n", fd); + return false; + } + /* setup for new state */ + fd_cur[slot] = fd_orig[slot]; + fd_cur[slot].sg_flags &= ~ECHO; + fd_cur[slot].sg_flags |= CBREAK; + /* enable new state */ + if (ioctl(fd, TIOCSETP, fd_cur+slot) < 0) { + if (conf->calc_debug & CALCDBG_TTY) + printf("calc_tty: Cannot TIOCSETP fd %d\n", fd); + return false; + } + if (conf->calc_debug & CALCDBG_TTY) + printf("calc_tty: stty -ECHO +CBREAK: fd %d\n", fd); #elif defined(USE_TERMIO) - /* - * USE_TERMIO tty state method - */ - if (fd_setup[slot] < 0 && ioctl(fd, TCGETA, fd_orig+slot) < 0) { - if (conf->calc_debug & CALCDBG_TTY) - printf("calc_tty: Cannot TCGETA fd %d\n", fd); - return false; - } - /* setup for new state */ - fd_cur[slot] = fd_orig[slot]; - fd_cur[slot].c_lflag &= ~(ECHO | ECHOE | ECHOK); - fd_cur[slot].c_iflag |= ISTRIP; - fd_cur[slot].c_lflag &= ~ICANON; - fd_cur[slot].c_cc[VMIN] = 1; - fd_cur[slot].c_cc[VTIME] = 0; - /* enable new state */ - if (ioctl(fd, TCSETAW, fd_cur+slot) < 0) { - if (conf->calc_debug & CALCDBG_TTY) - printf("calc_tty: Cannot TCSETAW fd %d\n", fd); - return false; - } - if (conf->calc_debug & CALCDBG_TTY) - printf("calc_tty: stty -ECHO -ECHOE -ECHOK -ICANON +ISTRIP " - "VMIN=1 VTIME=0: fd %d\n", fd); + /* + * USE_TERMIO tty state method + */ + if (fd_setup[slot] < 0 && ioctl(fd, TCGETA, fd_orig+slot) < 0) { + if (conf->calc_debug & CALCDBG_TTY) + printf("calc_tty: Cannot TCGETA fd %d\n", fd); + return false; + } + /* setup for new state */ + fd_cur[slot] = fd_orig[slot]; + fd_cur[slot].c_lflag &= ~(ECHO | ECHOE | ECHOK); + fd_cur[slot].c_iflag |= ISTRIP; + fd_cur[slot].c_lflag &= ~ICANON; + fd_cur[slot].c_cc[VMIN] = 1; + fd_cur[slot].c_cc[VTIME] = 0; + /* enable new state */ + if (ioctl(fd, TCSETAW, fd_cur+slot) < 0) { + if (conf->calc_debug & CALCDBG_TTY) + printf("calc_tty: Cannot TCSETAW fd %d\n", fd); + return false; + } + if (conf->calc_debug & CALCDBG_TTY) + printf("calc_tty: stty -ECHO -ECHOE -ECHOK -ICANON +ISTRIP " + "VMIN=1 VTIME=0: fd %d\n", fd); #elif defined (USE_TERMIOS) - /* - * USE_TERMIOS tty state method - */ - if (fd_setup[slot] < 0 && tcgetattr(fd, fd_orig+slot) < 0) { - if (conf->calc_debug & CALCDBG_TTY) - printf("calc_tty: Cannot tcgetattr fd %d\n", fd); - return false; - } - /* setup for new state */ - fd_cur[slot] = fd_orig[slot]; - fd_cur[slot].c_lflag &= ~(ECHO | ECHOE | ECHOK); - fd_cur[slot].c_iflag |= ISTRIP; - fd_cur[slot].c_lflag &= ~ICANON; - fd_cur[slot].c_cc[VMIN] = 1; - fd_cur[slot].c_cc[VTIME] = 0; - /* enable new state */ - if (tcsetattr(fd, TCSANOW, fd_cur+slot) < 0) { - if (conf->calc_debug & CALCDBG_TTY) - printf("calc_tty: Cannot tcsetattr fd %d\n", fd); - return false; - } - if (conf->calc_debug & CALCDBG_TTY) - printf("calc_tty: stty -ECHO -ECHOE -ECHOK -ICANON +ISTRIP " - "VMIN=1 VTIME=0: fd %d\n", fd); + /* + * USE_TERMIOS tty state method + */ + if (fd_setup[slot] < 0 && tcgetattr(fd, fd_orig+slot) < 0) { + if (conf->calc_debug & CALCDBG_TTY) + printf("calc_tty: Cannot tcgetattr fd %d\n", fd); + return false; + } + /* setup for new state */ + fd_cur[slot] = fd_orig[slot]; + fd_cur[slot].c_lflag &= ~(ECHO | ECHOE | ECHOK); + fd_cur[slot].c_iflag |= ISTRIP; + fd_cur[slot].c_lflag &= ~ICANON; + fd_cur[slot].c_cc[VMIN] = 1; + fd_cur[slot].c_cc[VTIME] = 0; + /* enable new state */ + if (tcsetattr(fd, TCSANOW, fd_cur+slot) < 0) { + if (conf->calc_debug & CALCDBG_TTY) + printf("calc_tty: Cannot tcsetattr fd %d\n", fd); + return false; + } + if (conf->calc_debug & CALCDBG_TTY) + printf("calc_tty: stty -ECHO -ECHOE -ECHOK -ICANON +ISTRIP " + "VMIN=1 VTIME=0: fd %d\n", fd); #else /* Using none of the above */ - fd_cur[slot] = fd_orig[slot]; + fd_cur[slot] = fd_orig[slot]; #endif - /* - * note that the tty slot is on use - */ - fd_setup[slot] = fd; - return true; + /* + * note that the tty slot is on use + */ + fd_setup[slot] = fd; + return true; } @@ -961,80 +961,80 @@ calc_tty(int fd) * startup value if it was set for interactive use by calc_tty(). * * Given: - * fd the descriptor to restore + * fd the descriptor to restore * * Returns: - * true restore was successful - * false unable to restore descriptor to original state + * true restore was successful + * false unable to restore descriptor to original state */ bool orig_tty(int fd) { - int slot; /* the saved descriptor slot or -1 */ + int slot; /* the saved descriptor slot or -1 */ - /* - * find the saved slot for this descriptor - */ - slot = find_tty_state(fd); - if (slot < 0) { - if (conf->calc_debug & CALCDBG_TTY) - printf("orig_tty: Cannot get saved descriptor slot\n"); - return false; - } + /* + * find the saved slot for this descriptor + */ + slot = find_tty_state(fd); + if (slot < 0) { + if (conf->calc_debug & CALCDBG_TTY) + printf("orig_tty: Cannot get saved descriptor slot\n"); + return false; + } - /* - * do nothing if no state was saved for this descriptor - */ - if (fd_setup[slot] < 0) { - if (conf->calc_debug & CALCDBG_TTY) - printf("orig_tty: no state saved for fd %d\n", fd); - return false; - } + /* + * do nothing if no state was saved for this descriptor + */ + if (fd_setup[slot] < 0) { + if (conf->calc_debug & CALCDBG_TTY) + printf("orig_tty: no state saved for fd %d\n", fd); + return false; + } #if defined(USE_SGTTY) - /* - * USE_SGTTY tty state method - */ - (void) ioctl(fd, TIOCSETP, fd_orig+slot); - if (conf->calc_debug & CALCDBG_TTY) - printf("orig_tty: TIOCSETP restored fd %d\n", fd); + /* + * USE_SGTTY tty state method + */ + (void) ioctl(fd, TIOCSETP, fd_orig+slot); + if (conf->calc_debug & CALCDBG_TTY) + printf("orig_tty: TIOCSETP restored fd %d\n", fd); #elif defined(USE_TERMIO) - /* - * USE_TERMIO tty state method - */ - (void) ioctl(fd, TCSETAW, fd_orig+slot); - if (conf->calc_debug & CALCDBG_TTY) - printf("orig_tty: TCSETAW restored fd %d\n", fd); + /* + * USE_TERMIO tty state method + */ + (void) ioctl(fd, TCSETAW, fd_orig+slot); + if (conf->calc_debug & CALCDBG_TTY) + printf("orig_tty: TCSETAW restored fd %d\n", fd); #elif defined (USE_TERMIOS) - /* - * assume USE_SGTTY tty state method - */ - (void) tcsetattr(fd, TCSANOW, fd_orig+slot); - if (conf->calc_debug & CALCDBG_TTY) - printf("orig_tty: TCSANOW restored fd %d\n", fd); + /* + * assume USE_SGTTY tty state method + */ + (void) tcsetattr(fd, TCSANOW, fd_orig+slot); + if (conf->calc_debug & CALCDBG_TTY) + printf("orig_tty: TCSANOW restored fd %d\n", fd); #else /* nothing assigned */ - if (conf->calc_debug & CALCDBG_TTY) - printf ("orig_tty: nothing restored to fd %d\n", fd); + if (conf->calc_debug & CALCDBG_TTY) + printf ("orig_tty: nothing restored to fd %d\n", fd); #endif - /* - * note new current state - */ - fd_cur[slot] = fd_orig[slot]; + /* + * note new current state + */ + fd_cur[slot] = fd_orig[slot]; - /* - * Since current state is the original state, we can free up - * this slot. This also prevents functions such as the - * libcalc_call_me_last() function from re-restoring it. - */ - fd_setup[slot] = -1; - return true; + /* + * Since current state is the original state, we can free up + * this slot. This also prevents functions such as the + * libcalc_call_me_last() function from re-restoring it. + */ + fd_setup[slot] = -1; + return true; } diff --git a/lib_calc.h b/lib_calc.h index 48d7969..7ee9071 100644 --- a/lib_calc.h +++ b/lib_calc.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/03/23 18:37:10 - * File existed as early as: 1997 + * Under source code control: 1997/03/23 18:37:10 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -30,7 +30,7 @@ #include -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "decl.h" #else # include @@ -39,7 +39,7 @@ /* * error buffer definitions */ -#define MAXERROR 512 /* maximum length of error message string */ +#define MAXERROR 512 /* maximum length of error message string */ /* * calc math error control diff --git a/lib_util.c b/lib_util.c index 64c65f2..747a758 100644 --- a/lib_util.c +++ b/lib_util.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/04/19 21:38:30 - * File existed as early as: 1997 + * Under source code control: 1997/04/19 21:38:30 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -36,50 +36,50 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* * lowhex2bin - quick low order ASCII hex to binary conversion * - * We just use mod 16 for non-hex ASCII chars. We use just mod 128 + * We just use mod 16 for non-hex ASCII chars. We use just mod 128 * for non-ASCII to ASCII conversion. * * | 00 nul | 01 soh | 02 stx | 03 etx | 04 eot | 05 enq | 06 ack | 07 bel | - * | 08 bs | 09 ht | 0a nl | 0b vt | 0c np | 0d cr | 0e so | 0f si | + * | 08 bs | 09 ht | 0a nl | 0b vt | 0c np | 0d cr | 0e so | 0f si | * | 10 dle | 11 dc1 | 12 dc2 | 13 dc3 | 14 dc4 | 15 nak | 16 syn | 17 etb | * | 18 can | 19 em | 1a sub | 1b esc | 1c fs | 1d gs | 1e rs | 1f us | - * | 20 sp | 21 ! | 22 " | 23 # | 24 $ | 25 % | 26 & | 27 ' | - * | 28 ( | 29 ) | 2a * | 2b + | 2c , | 2d - | 2e . | 2f / | - * | 30 0 | 31 1 | 32 2 | 33 3 | 34 4 | 35 5 | 36 6 | 37 7 | - * | 38 8 | 39 9 | 3a : | 3b ; | 3c < | 3d = | 3e > | 3f ? | - * | 40 @ | 41 A | 42 B | 43 C | 44 D | 45 E | 46 F | 47 G | - * | 48 H | 49 I | 4a J | 4b K | 4c L | 4d M | 4e N | 4f O | - * | 50 P | 51 Q | 52 R | 53 S | 54 T | 55 U | 56 V | 57 W | - * | 58 X | 59 Y | 5a Z | 5b [ | 5c \ | 5d ] | 5e ^ | 5f _ | - * | 60 ` | 61 a | 62 b | 63 c | 64 d | 65 e | 66 f | 67 g | - * | 68 h | 69 i | 6a j | 6b k | 6c l | 6d m | 6e n | 6f o | - * | 70 p | 71 q | 72 r | 73 s | 74 t | 75 u | 76 v | 77 w | - * | 78 x | 79 y | 7a z | 7b { | 7c | | 7d } | 7e ~ | 7f del | + * | 20 sp | 21 ! | 22 " | 23 # | 24 $ | 25 % | 26 & | 27 ' | + * | 28 ( | 29 ) | 2a * | 2b + | 2c , | 2d - | 2e . | 2f / | + * | 30 0 | 31 1 | 32 2 | 33 3 | 34 4 | 35 5 | 36 6 | 37 7 | + * | 38 8 | 39 9 | 3a : | 3b ; | 3c < | 3d = | 3e > | 3f ? | + * | 40 @ | 41 A | 42 B | 43 C | 44 D | 45 E | 46 F | 47 G | + * | 48 H | 49 I | 4a J | 4b K | 4c L | 4d M | 4e N | 4f O | + * | 50 P | 51 Q | 52 R | 53 S | 54 T | 55 U | 56 V | 57 W | + * | 58 X | 59 Y | 5a Z | 5b [ | 5c \ | 5d ] | 5e ^ | 5f _ | + * | 60 ` | 61 a | 62 b | 63 c | 64 d | 65 e | 66 f | 67 g | + * | 68 h | 69 i | 6a j | 6b k | 6c l | 6d m | 6e n | 6f o | + * | 70 p | 71 q | 72 r | 73 s | 74 t | 75 u | 76 v | 77 w | + * | 78 x | 79 y | 7a z | 7b { | 7c | | 7d } | 7e ~ | 7f del | */ int lowhex2bin[256] = { - /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 0 */ - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 1 */ - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 2 */ - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 3 */ - 0x0,0xa,0xb,0xc,0xd,0xe,0xf,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 4 */ - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 5 */ - 0x0,0xa,0xb,0xc,0xd,0xe,0xf,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 6 */ - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 7 */ - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 8 */ - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 9 */ - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* a */ - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* b */ - 0x0,0xa,0xb,0xc,0xd,0xe,0xf,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* c */ - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* d */ - 0x0,0xa,0xb,0xc,0xd,0xe,0xf,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* e */ - 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf /* f */ + /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ + 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 0 */ + 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 1 */ + 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 2 */ + 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 3 */ + 0x0,0xa,0xb,0xc,0xd,0xe,0xf,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 4 */ + 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 5 */ + 0x0,0xa,0xb,0xc,0xd,0xe,0xf,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 6 */ + 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 7 */ + 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 8 */ + 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* 9 */ + 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* a */ + 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* b */ + 0x0,0xa,0xb,0xc,0xd,0xe,0xf,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* c */ + 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* d */ + 0x0,0xa,0xb,0xc,0xd,0xe,0xf,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf, /* e */ + 0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf /* f */ }; @@ -87,35 +87,35 @@ int lowhex2bin[256] = { * hex2bin - macro to convert two ASCII hex chars into binary value * * given: - * high - high order hex ASCII char - * low - low order hex ASCII char + * high - high order hex ASCII char + * low - low order hex ASCII char * * returns: - * numeric equivalent to 0x{high}{low} as an int + * numeric equivalent to 0x{high}{low} as an int */ #define hex2bin(high,low) \ - (lowhex2bin[(int)((char)(high))]<<4 | lowhex2bin[((int)(char)(low))]) + (lowhex2bin[(int)((char)(high))]<<4 | lowhex2bin[((int)(char)(low))]) /* * lowbin2hex - quick low order binary conversion to ASCII hex */ char lowbin2hex[256] = { - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' }; @@ -125,54 +125,54 @@ char lowbin2hex[256] = { * NOTE: No attempt is make to deal with byte order. * * given: - * str string to convert + * str string to convert * * returns: - * ZVALUE + * ZVALUE */ ZVALUE convstr2z(char *str) { - HALF *v; /* storage for string as HALFs */ - ZVALUE ret; /* return value */ - size_t len; /* length in HALFs of our string rounded up */ + HALF *v; /* storage for string as HALFs */ + ZVALUE ret; /* return value */ + size_t len; /* length in HALFs of our string rounded up */ - /* - * firewall - */ - if (str == NULL || *str == '\0') { - /* NULL or empty strings return 0 */ - return _zero_; - } + /* + * firewall + */ + if (str == NULL || *str == '\0') { + /* NULL or empty strings return 0 */ + return _zero_; + } - /* - * allocate HALF storage - */ - len = (strlen(str)+sizeof(HALF)-1)/sizeof(HALF); - v = (HALF *)malloc(len * sizeof(HALF)); - if (v == NULL) { - math_error("convstr2z bad malloc"); - not_reached(); - } - v[len-1] = 0; /* deal with possible partial end of string HALF */ + /* + * allocate HALF storage + */ + len = (strlen(str)+sizeof(HALF)-1)/sizeof(HALF); + v = (HALF *)malloc(len * sizeof(HALF)); + if (v == NULL) { + math_error("convstr2z bad malloc"); + not_reached(); + } + v[len-1] = 0; /* deal with possible partial end of string HALF */ - /* - * initialize HALF array with string value - */ - memcpy((void *)v, (void *)str, strlen(str)); + /* + * initialize HALF array with string value + */ + memcpy((void *)v, (void *)str, strlen(str)); - /* - * setup the rest of the ZVALUE - */ - ret.v = v; - ret.len = len; - ret.sign = 0; - ztrim(&ret); + /* + * setup the rest of the ZVALUE + */ + ret.v = v; + ret.len = len; + ret.sign = 0; + ztrim(&ret); - /* - * return our result - */ - return ret; + /* + * return our result + */ + return ret; } @@ -180,107 +180,107 @@ convstr2z(char *str) * convhex2z - convert hex string to ZVALUE * * usage: - * str hex ASCII string with optional leading 0x + * str hex ASCII string with optional leading 0x * * returns: - * ZVALUE + * ZVALUE */ ZVALUE convhex2z(char *hex) { - HALF *v; /* storage for string as HALFs */ - HALF *hp; /* HALF pointer */ - char *sp; /* string pointer */ - ZVALUE ret; /* return value */ - int len; /* length in HALFs of our string rounded up */ - size_t slen; /* hex string length */ - int i; + HALF *v; /* storage for string as HALFs */ + HALF *hp; /* HALF pointer */ + char *sp; /* string pointer */ + ZVALUE ret; /* return value */ + int len; /* length in HALFs of our string rounded up */ + size_t slen; /* hex string length */ + int i; - /* - * firewall - */ - if (hex == NULL || hex[0] == '\0') { - /* NULL or empty strings return 0 */ - return _zero_; - } + /* + * firewall + */ + if (hex == NULL || hex[0] == '\0') { + /* NULL or empty strings return 0 */ + return _zero_; + } - /* - * skip leading 0X or 0x if needed - */ - if (hex[0] == '0' && (hex[1] == 'x' || hex[1] == 'X')) { - hex += 2; - } - if (hex[0] == '\0') { - /* just 0X or 0x returns 0 */ - return _zero_; - } + /* + * skip leading 0X or 0x if needed + */ + if (hex[0] == '0' && (hex[1] == 'x' || hex[1] == 'X')) { + hex += 2; + } + if (hex[0] == '\0') { + /* just 0X or 0x returns 0 */ + return _zero_; + } - /* - * allocate HALF storage - */ - slen = strlen(hex); - len = ((slen*4)+BASEB-1)/BASEB; - v = (HALF *)malloc(len * sizeof(HALF)); - if (v == NULL) { - math_error("convhex2z bad malloc"); - not_reached(); - } - v[len-1] = 0; /* deal with possible partial end of string HALF */ + /* + * allocate HALF storage + */ + slen = strlen(hex); + len = ((slen*4)+BASEB-1)/BASEB; + v = (HALF *)malloc(len * sizeof(HALF)); + if (v == NULL) { + math_error("convhex2z bad malloc"); + not_reached(); + } + v[len-1] = 0; /* deal with possible partial end of string HALF */ - /* - * deal with the upper partial HALF value - */ - hp = v+len-1; - sp = hex; - if ((slen % (BASEB/4)) != 0) { + /* + * deal with the upper partial HALF value + */ + hp = v+len-1; + sp = hex; + if ((slen % (BASEB/4)) != 0) { - /* deal with a odd length hex string first */ - if (slen % 2 == 1) { - *hp = hex2bin('0', *sp++); - --slen; + /* deal with a odd length hex string first */ + if (slen % 2 == 1) { + *hp = hex2bin('0', *sp++); + --slen; - /* even length - top top hex char to process */ - } else { - *hp = 0; - } - /* slen is even now */ + /* even length - top top hex char to process */ + } else { + *hp = 0; + } + /* slen is even now */ - /* eat two hex chars at a time until the HALF is full */ - for (; (slen % (BASEB/4)) != 0; slen -= 2, sp += 2) { - *hp = ((*hp<<8) | hex2bin(sp[0], sp[1])); - } + /* eat two hex chars at a time until the HALF is full */ + for (; (slen % (BASEB/4)) != 0; slen -= 2, sp += 2) { + *hp = ((*hp<<8) | hex2bin(sp[0], sp[1])); + } - /* move on to the next HALF */ - --hp; - } - /* slen is now a multiple of BASEB/4 */ + /* move on to the next HALF */ + --hp; + } + /* slen is now a multiple of BASEB/4 */ - /* - * deal with full HALFs - */ - for (; slen > 0; slen -= (BASEB/4), --hp) { + /* + * deal with full HALFs + */ + for (; slen > 0; slen -= (BASEB/4), --hp) { - /* clear HALF */ - *hp = 0; + /* clear HALF */ + *hp = 0; - /* eat two hex chars at a time until the HALF is full */ - for (i=0; i < (BASEB/4); i += 2) { - *hp = ((*hp<<8) | hex2bin(sp[i], sp[i+1])); - } - } + /* eat two hex chars at a time until the HALF is full */ + for (i=0; i < (BASEB/4); i += 2) { + *hp = ((*hp<<8) | hex2bin(sp[i], sp[i+1])); + } + } - /* - * setup the rest of the ZVALUE - */ - ret.v = v; - ret.len = len; - ret.sign = 0; - ztrim(&ret); + /* + * setup the rest of the ZVALUE + */ + ret.v = v; + ret.len = len; + ret.sign = 0; + ztrim(&ret); - /* - * return our result - */ - return ret; + /* + * return our result + */ + return ret; } @@ -290,83 +290,83 @@ convhex2z(char *hex) * We will ignore the sign of the value. * * usage: - * z ZVALUE + * z ZVALUE * * returns: - * str hex ASCII malloced string (without a leading 0x) + * str hex ASCII malloced string (without a leading 0x) */ char * convz2hex(ZVALUE z) { - char *ret; /* string to return */ - int slen; /* string length (not counting \0) */ - HALF half; /* HALF value to convert */ - int seen_nz; /* 0 => we have not seen a non-zero hex char (yet) */ - char *p; - int i; - int j; + char *ret; /* string to return */ + int slen; /* string length (not counting \0) */ + HALF half; /* HALF value to convert */ + int seen_nz; /* 0 => we have not seen a non-zero hex char (yet) */ + char *p; + int i; + int j; - /* - * firewall - */ - if (z.v == NULL || ziszero(z)) { - /* malloc and return "0" */ - ret = (char *)malloc(sizeof("0")); - if (ret == NULL) { - math_error("convz2hex bad malloc of 0 value"); - not_reached(); - } - ret[0] = '0'; - ret[1] = '\0'; - return ret; - } + /* + * firewall + */ + if (z.v == NULL || ziszero(z)) { + /* malloc and return "0" */ + ret = (char *)malloc(sizeof("0")); + if (ret == NULL) { + math_error("convz2hex bad malloc of 0 value"); + not_reached(); + } + ret[0] = '0'; + ret[1] = '\0'; + return ret; + } - /* - * malloc string storage - */ - slen = (z.len * BASEB/4); - ret = (char *)calloc(slen+1+1, sizeof(char)); - if (ret == NULL) { - math_error("convz2hex bad malloc of string"); - not_reached(); - } + /* + * malloc string storage + */ + slen = (z.len * BASEB/4); + ret = (char *)calloc(slen+1+1, sizeof(char)); + if (ret == NULL) { + math_error("convz2hex bad malloc of string"); + not_reached(); + } - /* - * load in hex ASCII chars for each HALF - * - * We will not write leading '0' hex chars into the string. - */ - seen_nz = 0; - for (p=ret, i=z.len-1; i >= 0; --i) { + /* + * load in hex ASCII chars for each HALF + * + * We will not write leading '0' hex chars into the string. + */ + seen_nz = 0; + for (p=ret, i=z.len-1; i >= 0; --i) { - /* - * load in ASCII hex by ASCII hex - */ - for (half=z.v[i], j=BASEB-4; j >= 0; j-=4) { - if (seen_nz) { - /* we saw a non-zero, just load the rest */ - *p++ = lowbin2hex[(half >> j) & 0xff]; - } else { - /* all zeros so far */ - *p = lowbin2hex[(half >> j) & 0xff]; - if (*p != '0') { - /* we found our first non-zero char */ - ++p; - seen_nz = 1; - } - } - } - } - if (seen_nz) { - *p = '\0'; - } else { - /* saw nothing but 0's, so just return 0 */ - *ret = '0'; - *(ret+1) = '\0'; - } + /* + * load in ASCII hex by ASCII hex + */ + for (half=z.v[i], j=BASEB-4; j >= 0; j-=4) { + if (seen_nz) { + /* we saw a non-zero, just load the rest */ + *p++ = lowbin2hex[(half >> j) & 0xff]; + } else { + /* all zeros so far */ + *p = lowbin2hex[(half >> j) & 0xff]; + if (*p != '0') { + /* we found our first non-zero char */ + ++p; + seen_nz = 1; + } + } + } + } + if (seen_nz) { + *p = '\0'; + } else { + /* saw nothing but 0's, so just return 0 */ + *ret = '0'; + *(ret+1) = '\0'; + } - /* - * return the new string - */ - return ret; + /* + * return the new string + */ + return ret; } diff --git a/lib_util.h b/lib_util.h index 1e98e1a..35d4463 100644 --- a/lib_util.h +++ b/lib_util.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/04/19 21:38:30 - * File existed as early as: 1997 + * Under source code control: 1997/04/19 21:38:30 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* diff --git a/listfunc.c b/listfunc.c index 8fa434c..aee4ddc 100644 --- a/listfunc.c +++ b/listfunc.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:18 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:18 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -38,7 +38,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ E_FUNC long irand(long s); @@ -52,25 +52,25 @@ S_FUNC void removelistelement(LIST *lp, LISTELEM *ep); * Insert an element before the first element of a list. * * given: - * lp list to put element onto - * vp value to be inserted + * lp list to put element onto + * vp value to be inserted */ void insertlistfirst(LIST *lp, VALUE *vp) { - LISTELEM *ep; /* list element */ + LISTELEM *ep; /* list element */ - ep = elemalloc(); - copyvalue(vp, &ep->e_value); - if (lp->l_count == 0) { - lp->l_last = ep; - } else { - lp->l_cacheindex++; - lp->l_first->e_prev = ep; - ep->e_next = lp->l_first; - } - lp->l_first = ep; - lp->l_count++; + ep = elemalloc(); + copyvalue(vp, &ep->e_value); + if (lp->l_count == 0) { + lp->l_last = ep; + } else { + lp->l_cacheindex++; + lp->l_first->e_prev = ep; + ep->e_next = lp->l_first; + } + lp->l_first = ep; + lp->l_count++; } @@ -78,24 +78,24 @@ insertlistfirst(LIST *lp, VALUE *vp) * Insert an element after the last element of a list. * * given: - * lp list to put element onto - * vp value to be inserted + * lp list to put element onto + * vp value to be inserted */ void insertlistlast(LIST *lp, VALUE *vp) { - LISTELEM *ep; /* list element */ + LISTELEM *ep; /* list element */ - ep = elemalloc(); - copyvalue(vp, &ep->e_value); - if (lp->l_count == 0) { - lp->l_first = ep; - } else { - lp->l_last->e_next = ep; - ep->e_prev = lp->l_last; - } - lp->l_last = ep; - lp->l_count++; + ep = elemalloc(); + copyvalue(vp, &ep->e_value); + if (lp->l_count == 0) { + lp->l_first = ep; + } else { + lp->l_last->e_next = ep; + ep->e_prev = lp->l_last; + } + lp->l_last = ep; + lp->l_count++; } @@ -107,40 +107,40 @@ insertlistlast(LIST *lp, VALUE *vp) * case the element is appended to the list. * * given: - * lp list to put element onto - * index element number to insert in front of - * vp value to be inserted + * lp list to put element onto + * index element number to insert in front of + * vp value to be inserted */ void insertlistmiddle(LIST *lp, long index, VALUE *vp) { - LISTELEM *ep; /* list element */ - LISTELEM *oldep; /* old list element at desired index */ + LISTELEM *ep; /* list element */ + LISTELEM *oldep; /* old list element at desired index */ - if (index == 0) { - insertlistfirst(lp, vp); - return; - } - if (index == lp->l_count) { - insertlistlast(lp, vp); - return; - } - oldep = NULL; - if ((index >= 0) && (index < lp->l_count)) - oldep = listelement(lp, index); - if (oldep == NULL) { - math_error("Index out of bounds for list insertion"); - not_reached(); - } - ep = elemalloc(); - copyvalue(vp, &ep->e_value); - ep->e_next = oldep; - ep->e_prev = oldep->e_prev; - ep->e_prev->e_next = ep; - oldep->e_prev = ep; - lp->l_cache = ep; - lp->l_cacheindex = index; - lp->l_count++; + if (index == 0) { + insertlistfirst(lp, vp); + return; + } + if (index == lp->l_count) { + insertlistlast(lp, vp); + return; + } + oldep = NULL; + if ((index >= 0) && (index < lp->l_count)) + oldep = listelement(lp, index); + if (oldep == NULL) { + math_error("Index out of bounds for list insertion"); + not_reached(); + } + ep = elemalloc(); + copyvalue(vp, &ep->e_value); + ep->e_next = oldep; + ep->e_prev = oldep->e_prev; + ep->e_prev->e_next = ep; + oldep->e_prev = ep; + lp->l_cache = ep; + lp->l_cacheindex = index; + lp->l_count++; } @@ -149,21 +149,21 @@ insertlistmiddle(LIST *lp, long index, VALUE *vp) * Returns the null value if no more elements exist. * * given: - * lp list to have element removed - * vp location of the value + * lp list to have element removed + * vp location of the value */ void removelistfirst(LIST *lp, VALUE *vp) { - if (lp->l_count == 0) { - vp->v_type = V_NULL; - vp->v_subtype = V_NOSUBTYPE; - return; - } - *vp = lp->l_first->e_value; - lp->l_first->e_value.v_type = V_NULL; - lp->l_first->e_value.v_subtype = V_NOSUBTYPE; - removelistelement(lp, lp->l_first); + if (lp->l_count == 0) { + vp->v_type = V_NULL; + vp->v_subtype = V_NOSUBTYPE; + return; + } + *vp = lp->l_first->e_value; + lp->l_first->e_value.v_type = V_NULL; + lp->l_first->e_value.v_subtype = V_NOSUBTYPE; + removelistelement(lp, lp->l_first); } @@ -172,21 +172,21 @@ removelistfirst(LIST *lp, VALUE *vp) * Returns the null value if no more elements exist. * * given: - * lp list to have element removed - * vp location of the value + * lp list to have element removed + * vp location of the value */ void removelistlast(LIST *lp, VALUE *vp) { - if (lp->l_count == 0) { - vp->v_type = V_NULL; - vp->v_subtype = V_NOSUBTYPE; - return; - } - *vp = lp->l_last->e_value; - lp->l_last->e_value.v_type = V_NULL; - lp->l_last->e_value.v_subtype = V_NOSUBTYPE; - removelistelement(lp, lp->l_last); + if (lp->l_count == 0) { + vp->v_type = V_NULL; + vp->v_subtype = V_NOSUBTYPE; + return; + } + *vp = lp->l_last->e_value; + lp->l_last->e_value.v_type = V_NULL; + lp->l_last->e_value.v_subtype = V_NOSUBTYPE; + removelistelement(lp, lp->l_last); } @@ -194,26 +194,26 @@ removelistlast(LIST *lp, VALUE *vp) * Remove the element with the given index from a list, returning its value. * * given: - * lp list to have element removed - * index list element to be removed - * vp location of the value + * lp list to have element removed + * index list element to be removed + * vp location of the value */ void removelistmiddle(LIST *lp, long index, VALUE *vp) { - LISTELEM *ep; /* element being removed */ + LISTELEM *ep; /* element being removed */ - ep = NULL; - if ((index >= 0) && (index < lp->l_count)) - ep = listelement(lp, index); - if (ep == NULL) { - math_error("Index out of bounds for list deletion"); - not_reached(); - } - *vp = ep->e_value; - ep->e_value.v_type = V_NULL; - ep->e_value.v_subtype = V_NOSUBTYPE; - removelistelement(lp, ep); + ep = NULL; + if ((index >= 0) && (index < lp->l_count)) + ep = listelement(lp, index); + if (ep == NULL) { + math_error("Index out of bounds for list deletion"); + not_reached(); + } + *vp = ep->e_value; + ep->e_value.v_type = V_NULL; + ep->e_value.v_subtype = V_NOSUBTYPE; + removelistelement(lp, ep); } @@ -222,67 +222,67 @@ removelistmiddle(LIST *lp, long index, VALUE *vp) * The value contained in the element is freed. * * given: - * lp list header - * ep list element to remove + * lp list header + * ep list element to remove */ S_FUNC void removelistelement(LIST *lp, LISTELEM *ep) { - if ((ep == lp->l_cache) || ((ep != lp->l_first) && (ep != lp->l_last))) - lp->l_cache = NULL; - if (ep->e_next) - ep->e_next->e_prev = ep->e_prev; - if (ep->e_prev) - ep->e_prev->e_next = ep->e_next; - if (ep == lp->l_first) { - lp->l_first = ep->e_next; - lp->l_cacheindex--; - } - if (ep == lp->l_last) - lp->l_last = ep->e_prev; - lp->l_count--; - elemfree(ep); + if ((ep == lp->l_cache) || ((ep != lp->l_first) && (ep != lp->l_last))) + lp->l_cache = NULL; + if (ep->e_next) + ep->e_next->e_prev = ep->e_prev; + if (ep->e_prev) + ep->e_prev->e_next = ep->e_next; + if (ep == lp->l_first) { + lp->l_first = ep->e_next; + lp->l_cacheindex--; + } + if (ep == lp->l_last) + lp->l_last = ep->e_prev; + lp->l_count--; + elemfree(ep); } LIST * listsegment(LIST *lp, long n1, long n2) { - LIST *newlp; - LISTELEM *ep; - long i; + LIST *newlp; + LISTELEM *ep; + long i; - newlp = listalloc(); - if ((n1 >= lp->l_count && n2 >= lp->l_count) || (n1 < 0 && n2 < 0)) - return newlp; - if (n1 >= lp->l_count) - n1 = lp->l_count - 1; - if (n2 >= lp->l_count) - n2 = lp->l_count - 1; - if (n1 < 0) - n1 = 0; - if (n2 < 0) - n2 = 0; + newlp = listalloc(); + if ((n1 >= lp->l_count && n2 >= lp->l_count) || (n1 < 0 && n2 < 0)) + return newlp; + if (n1 >= lp->l_count) + n1 = lp->l_count - 1; + if (n2 >= lp->l_count) + n2 = lp->l_count - 1; + if (n1 < 0) + n1 = 0; + if (n2 < 0) + n2 = 0; - ep = lp->l_first; - if (n1 <= n2) { - i = n2 - n1 + 1; - while(n1-- > 0 && ep) - ep = ep->e_next; - while(i-- > 0 && ep) { - insertlistlast(newlp, &ep->e_value); - ep = ep->e_next; - } - } else { - i = n1 - n2 + 1; - while(n2-- > 0 && ep) - ep = ep->e_next; - while(i-- > 0 && ep) { - insertlistfirst(newlp, &ep->e_value); - ep = ep->e_next; - } - } - return newlp; + ep = lp->l_first; + if (n1 <= n2) { + i = n2 - n1 + 1; + while(n1-- > 0 && ep) + ep = ep->e_next; + while(i-- > 0 && ep) { + insertlistlast(newlp, &ep->e_value); + ep = ep->e_next; + } + } else { + i = n1 - n2 + 1; + while(n2-- > 0 && ep) + ep = ep->e_next; + while(i-- > 0 && ep) { + insertlistfirst(newlp, &ep->e_value); + ep = ep->e_next; + } + } + return newlp; } @@ -294,29 +294,29 @@ listsegment(LIST *lp, long n1, long n2) int listsearch(LIST *lp, VALUE *vp, long i, long j, ZVALUE *index) { - register LISTELEM *ep; + register LISTELEM *ep; - if (i < 0 || j > lp->l_count) { - math_error("This should not happen in call to listsearch"); - not_reached(); - } + if (i < 0 || j > lp->l_count) { + math_error("This should not happen in call to listsearch"); + not_reached(); + } - ep = listelement(lp, i); - while (i < j) { - if (!ep) { - math_error("This should not happen in listsearch"); - not_reached(); - } - if (acceptvalue(&ep->e_value, vp)) { - lp->l_cache = ep; - lp->l_cacheindex = i; - utoz(i, index); - return 0; - } - ep = ep->e_next; - i++; - } - return 1; + ep = listelement(lp, i); + while (i < j) { + if (!ep) { + math_error("This should not happen in listsearch"); + not_reached(); + } + if (acceptvalue(&ep->e_value, vp)) { + lp->l_cache = ep; + lp->l_cacheindex = i; + utoz(i, index); + return 0; + } + ep = ep->e_next; + i++; + } + return 1; } @@ -328,29 +328,29 @@ listsearch(LIST *lp, VALUE *vp, long i, long j, ZVALUE *index) int listrsearch(LIST *lp, VALUE *vp, long i, long j, ZVALUE *index) { - register LISTELEM *ep; + register LISTELEM *ep; - if (i < 0 || j > lp->l_count) { - math_error("This should not happen in call to listrsearch"); - not_reached(); - } + if (i < 0 || j > lp->l_count) { + math_error("This should not happen in call to listrsearch"); + not_reached(); + } - ep = listelement(lp, --j); - while (j >= i) { - if (!ep) { - math_error("This should not happen in listsearch"); - not_reached(); - } - if (acceptvalue(&ep->e_value, vp)) { - lp->l_cache = ep; - lp->l_cacheindex = j; - utoz(j, index); - return 0; - } - ep = ep->e_prev; - j--; - } - return 1; + ep = listelement(lp, --j); + while (j >= i) { + if (!ep) { + math_error("This should not happen in listsearch"); + not_reached(); + } + if (acceptvalue(&ep->e_value, vp)) { + lp->l_cache = ep; + lp->l_cacheindex = j; + utoz(j, index); + return 0; + } + ep = ep->e_prev; + j--; + } + return 1; } @@ -359,100 +359,100 @@ listrsearch(LIST *lp, VALUE *vp, long i, long j, ZVALUE *index) * to that index. Returns NULL if the element does not exist. * * given: - * lp list to index into - * index index of desired element + * lp list to index into + * index index of desired element */ VALUE * listfindex(LIST *lp, long index) { - LISTELEM *ep; + LISTELEM *ep; - ep = listelement(lp, index); - if (ep == NULL) - return NULL; - return &ep->e_value; + ep = listelement(lp, index); + if (ep == NULL) + return NULL; + return &ep->e_value; } /* * Return the element at a specified index number of a list. * The list is indexed starting at zero, and negative indices - * indicate to index from the end of the list. This routine finds + * indicate to index from the end of the list. This routine finds * the element by chaining through the list from the closest one * of the first, last, and cached elements. Returns NULL if the * element does not exist. * * given: - * lp list to index into - * index index of desired element + * lp list to index into + * index index of desired element */ LISTELEM * listelement(LIST *lp, long index) { - register LISTELEM *ep; /* current list element */ - long dist; /* distance to element */ - long temp; /* temporary distance */ - bool forward; /* true if need to walk forwards */ + register LISTELEM *ep; /* current list element */ + long dist; /* distance to element */ + long temp; /* temporary distance */ + bool forward; /* true if need to walk forwards */ - if (index < 0) - index += lp->l_count; - if ((index < 0) || (index >= lp->l_count)) - return NULL; - /* - * Check quick special cases first. - */ - if (index == 0) - return lp->l_first; - if (index == 1) - return lp->l_first->e_next; - if (index == lp->l_count - 1) - return lp->l_last; - if ((index == lp->l_cacheindex) && lp->l_cache) - return lp->l_cache; - /* - * Calculate whether it is better to go forwards from - * the first element or backwards from the last element. - */ - forward = ((index * 2) <= lp->l_count); - if (forward) { - dist = index; - ep = lp->l_first; - } else { - dist = (lp->l_count - 1) - index; - ep = lp->l_last; - } - /* - * Now see if we have a cached element and if so, whether or - * not the distance from it is better than the above distance. - */ - if (lp->l_cache) { - temp = index - lp->l_cacheindex; - if ((temp >= 0) && (temp < dist)) { - dist = temp; - ep = lp->l_cache; - forward = true; - } - if ((temp < 0) && (-temp < dist)) { - dist = -temp; - ep = lp->l_cache; - forward = false; - } - } - /* - * Now walk forwards or backwards from the selected element - * until we reach the correct element. Cache the location of - * the found element for future use. - */ - if (forward) { - while (dist-- > 0) - ep = ep->e_next; - } else { - while (dist-- > 0) - ep = ep->e_prev; - } - lp->l_cache = ep; - lp->l_cacheindex = index; - return ep; + if (index < 0) + index += lp->l_count; + if ((index < 0) || (index >= lp->l_count)) + return NULL; + /* + * Check quick special cases first. + */ + if (index == 0) + return lp->l_first; + if (index == 1) + return lp->l_first->e_next; + if (index == lp->l_count - 1) + return lp->l_last; + if ((index == lp->l_cacheindex) && lp->l_cache) + return lp->l_cache; + /* + * Calculate whether it is better to go forwards from + * the first element or backwards from the last element. + */ + forward = ((index * 2) <= lp->l_count); + if (forward) { + dist = index; + ep = lp->l_first; + } else { + dist = (lp->l_count - 1) - index; + ep = lp->l_last; + } + /* + * Now see if we have a cached element and if so, whether or + * not the distance from it is better than the above distance. + */ + if (lp->l_cache) { + temp = index - lp->l_cacheindex; + if ((temp >= 0) && (temp < dist)) { + dist = temp; + ep = lp->l_cache; + forward = true; + } + if ((temp < 0) && (-temp < dist)) { + dist = -temp; + ep = lp->l_cache; + forward = false; + } + } + /* + * Now walk forwards or backwards from the selected element + * until we reach the correct element. Cache the location of + * the found element for future use. + */ + if (forward) { + while (dist-- > 0) + ep = ep->e_next; + } else { + while (dist-- > 0) + ep = ep->e_prev; + } + lp->l_cache = ep; + lp->l_cacheindex = index; + return ep; } @@ -463,23 +463,23 @@ listelement(LIST *lp, long index) bool listcmp(LIST *lp1, LIST *lp2) { - LISTELEM *e1, *e2; - long count; + LISTELEM *e1, *e2; + long count; - if (lp1 == lp2) - return false; - if (lp1->l_count != lp2->l_count) - return true; - e1 = lp1->l_first; - e2 = lp2->l_first; - count = lp1->l_count; - while (count-- > 0) { - if (comparevalue(&e1->e_value, &e2->e_value)) - return true; - e1 = e1->e_next; - e2 = e2->e_next; - } - return false; + if (lp1 == lp2) + return false; + if (lp1->l_count != lp2->l_count) + return true; + e1 = lp1->l_first; + e2 = lp2->l_first; + count = lp1->l_count; + while (count-- > 0) { + if (comparevalue(&e1->e_value, &e2->e_value)) + return true; + e1 = e1->e_next; + e2 = e2->e_next; + } + return false; } @@ -489,16 +489,16 @@ listcmp(LIST *lp1, LIST *lp2) LIST * listcopy(LIST *oldlp) { - LIST *lp; - LISTELEM *oldep; + LIST *lp; + LISTELEM *oldep; - lp = listalloc(); - oldep = oldlp->l_first; - while (oldep) { - insertlistlast(lp, &oldep->e_value); - oldep = oldep->e_next; - } - return lp; + lp = listalloc(); + oldep = oldlp->l_first; + while (oldep) { + insertlistlast(lp, &oldep->e_value); + oldep = oldep->e_next; + } + return lp; } @@ -508,28 +508,28 @@ listcopy(LIST *oldlp) LIST * listround(LIST *oldlp, VALUE *v2, VALUE *v3) { - LIST *lp; - LISTELEM *oldep, *ep, *eq; + LIST *lp; + LISTELEM *oldep, *ep, *eq; - lp = listalloc(); - oldep = oldlp->l_first; - lp->l_count = oldlp->l_count; - if (oldep) { - ep = elemalloc(); - lp->l_first = ep; - for (;;) { - roundvalue(&oldep->e_value, v2, v3, &ep->e_value); - oldep = oldep->e_next; - if (!oldep) - break; - eq = elemalloc(); - ep->e_next = eq; - eq->e_prev = ep; - ep = eq; - } - lp->l_last = ep; - } - return lp; + lp = listalloc(); + oldep = oldlp->l_first; + lp->l_count = oldlp->l_count; + if (oldep) { + ep = elemalloc(); + lp->l_first = ep; + for (;;) { + roundvalue(&oldep->e_value, v2, v3, &ep->e_value); + oldep = oldep->e_next; + if (!oldep) + break; + eq = elemalloc(); + ep->e_next = eq; + eq->e_prev = ep; + ep = eq; + } + lp->l_last = ep; + } + return lp; } @@ -539,28 +539,28 @@ listround(LIST *oldlp, VALUE *v2, VALUE *v3) LIST * listbround(LIST *oldlp, VALUE *v2, VALUE *v3) { - LIST *lp; - LISTELEM *oldep, *ep, *eq; + LIST *lp; + LISTELEM *oldep, *ep, *eq; - lp = listalloc(); - oldep = oldlp->l_first; - lp->l_count = oldlp->l_count; - if (oldep) { - ep = elemalloc(); - lp->l_first = ep; - for (;;) { - broundvalue(&oldep->e_value, v2, v3, &ep->e_value); - oldep = oldep->e_next; - if (!oldep) - break; - eq = elemalloc(); - ep->e_next = eq; - eq->e_prev = ep; - ep = eq; - } - lp->l_last = ep; - } - return lp; + lp = listalloc(); + oldep = oldlp->l_first; + lp->l_count = oldlp->l_count; + if (oldep) { + ep = elemalloc(); + lp->l_first = ep; + for (;;) { + broundvalue(&oldep->e_value, v2, v3, &ep->e_value); + oldep = oldep->e_next; + if (!oldep) + break; + eq = elemalloc(); + ep->e_next = eq; + eq->e_prev = ep; + ep = eq; + } + lp->l_last = ep; + } + return lp; } @@ -571,28 +571,28 @@ listbround(LIST *oldlp, VALUE *v2, VALUE *v3) LIST * listappr(LIST *oldlp, VALUE *v2, VALUE *v3) { - LIST *lp; - LISTELEM *oldep, *ep, *eq; + LIST *lp; + LISTELEM *oldep, *ep, *eq; - lp = listalloc(); - oldep = oldlp->l_first; - lp->l_count = oldlp->l_count; - if (oldep) { - ep = elemalloc(); - lp->l_first = ep; - for (;;) { - apprvalue(&oldep->e_value, v2, v3, &ep->e_value); - oldep = oldep->e_next; - if (!oldep) - break; - eq = elemalloc(); - ep->e_next = eq; - eq->e_prev = ep; - ep = eq; - } - lp->l_last = ep; - } - return lp; + lp = listalloc(); + oldep = oldlp->l_first; + lp->l_count = oldlp->l_count; + if (oldep) { + ep = elemalloc(); + lp->l_first = ep; + for (;;) { + apprvalue(&oldep->e_value, v2, v3, &ep->e_value); + oldep = oldep->e_next; + if (!oldep) + break; + eq = elemalloc(); + ep->e_next = eq; + eq->e_prev = ep; + ep = eq; + } + lp->l_last = ep; + } + return lp; } @@ -603,28 +603,28 @@ listappr(LIST *oldlp, VALUE *v2, VALUE *v3) LIST * listquo(LIST *oldlp, VALUE *v2, VALUE *v3) { - LIST *lp; - LISTELEM *oldep, *ep, *eq; + LIST *lp; + LISTELEM *oldep, *ep, *eq; - lp = listalloc(); - oldep = oldlp->l_first; - lp->l_count = oldlp->l_count; - if (oldep) { - ep = elemalloc(); - lp->l_first = ep; - for (;;) { - quovalue(&oldep->e_value, v2, v3, &ep->e_value); - oldep = oldep->e_next; - if (!oldep) - break; - eq = elemalloc(); - ep->e_next = eq; - eq->e_prev = ep; - ep = eq; - } - lp->l_last = ep; - } - return lp; + lp = listalloc(); + oldep = oldlp->l_first; + lp->l_count = oldlp->l_count; + if (oldep) { + ep = elemalloc(); + lp->l_first = ep; + for (;;) { + quovalue(&oldep->e_value, v2, v3, &ep->e_value); + oldep = oldep->e_next; + if (!oldep) + break; + eq = elemalloc(); + ep->e_next = eq; + eq->e_prev = ep; + ep = eq; + } + lp->l_last = ep; + } + return lp; } @@ -635,169 +635,169 @@ listquo(LIST *oldlp, VALUE *v2, VALUE *v3) LIST * listmod(LIST *oldlp, VALUE *v2, VALUE *v3) { - LIST *lp; - LISTELEM *oldep, *ep, *eq; + LIST *lp; + LISTELEM *oldep, *ep, *eq; - lp = listalloc(); - oldep = oldlp->l_first; - lp->l_count = oldlp->l_count; - if (oldep) { - ep = elemalloc(); - lp->l_first = ep; - for (;;) { - modvalue(&oldep->e_value, v2, v3, &ep->e_value); - oldep = oldep->e_next; - if (!oldep) - break; - eq = elemalloc(); - ep->e_next = eq; - eq->e_prev = ep; - ep = eq; - } - lp->l_last = ep; - } - return lp; + lp = listalloc(); + oldep = oldlp->l_first; + lp->l_count = oldlp->l_count; + if (oldep) { + ep = elemalloc(); + lp->l_first = ep; + for (;;) { + modvalue(&oldep->e_value, v2, v3, &ep->e_value); + oldep = oldep->e_next; + if (!oldep) + break; + eq = elemalloc(); + ep->e_next = eq; + eq->e_prev = ep; + ep = eq; + } + lp->l_last = ep; + } + return lp; } void listreverse(LIST *lp) { - LISTELEM *e1, *e2; - VALUE tmp; - long s; + LISTELEM *e1, *e2; + VALUE tmp; + long s; - s = lp->l_count/2; - e1 = lp->l_first; - e2 = lp->l_last; - lp->l_cache = NULL; - while (s-- > 0) { - tmp = e1->e_value; - e1->e_value = e2->e_value; - e2->e_value = tmp; - e1 = e1->e_next; - e2 = e2->e_prev; - } + s = lp->l_count/2; + e1 = lp->l_first; + e2 = lp->l_last; + lp->l_cache = NULL; + while (s-- > 0) { + tmp = e1->e_value; + e1->e_value = e2->e_value; + e2->e_value = tmp; + e1 = e1->e_next; + e2 = e2->e_prev; + } } void listsort(LIST *lp) { - LISTELEM *start; - LISTELEM *last, *a, *a1, *b, *next; - LISTELEM *S[LONG_BITS+1]; - long len[LONG_BITS+1]; - long i, j, k; + LISTELEM *start; + LISTELEM *last, *a, *a1, *b, *next; + LISTELEM *S[LONG_BITS+1]; + long len[LONG_BITS+1]; + long i, j, k; - if (lp->l_count < 2) - return; - lp->l_cache = NULL; - start = elemalloc(); - next = lp->l_first; - last = start; - start->e_next = next; - for (k = 0; next && k < LONG_BITS; k++) { - next->e_prev = last; - last = next; - S[k] = next; - next = next->e_next; - len[k] = 1; - while (k > 0 && (!next || len[k] >= len[k - 1])) {/* merging */ - j = len[k]; - b = S[k--]; - i = len[k]; - a = S[k]; - a1 = b->e_prev; - len[k] = i + j; - if (precvalue(&b->e_value, &a->e_value)) { - S[k] = b; - a->e_prev->e_next = b; - b->e_prev = a->e_prev; - j--; - while (j > 0) { - b = b->e_next; - if (!precvalue(&b->e_value, - &a->e_value)) - break; - j--; - } - if (j == 0) { - b->e_next = a; - a->e_prev = b; - last = a1; - continue; - } - b->e_prev->e_next = a; - a->e_prev = b->e_prev; - } + if (lp->l_count < 2) + return; + lp->l_cache = NULL; + start = elemalloc(); + next = lp->l_first; + last = start; + start->e_next = next; + for (k = 0; next && k < LONG_BITS; k++) { + next->e_prev = last; + last = next; + S[k] = next; + next = next->e_next; + len[k] = 1; + while (k > 0 && (!next || len[k] >= len[k - 1])) {/* merging */ + j = len[k]; + b = S[k--]; + i = len[k]; + a = S[k]; + a1 = b->e_prev; + len[k] = i + j; + if (precvalue(&b->e_value, &a->e_value)) { + S[k] = b; + a->e_prev->e_next = b; + b->e_prev = a->e_prev; + j--; + while (j > 0) { + b = b->e_next; + if (!precvalue(&b->e_value, + &a->e_value)) + break; + j--; + } + if (j == 0) { + b->e_next = a; + a->e_prev = b; + last = a1; + continue; + } + b->e_prev->e_next = a; + a->e_prev = b->e_prev; + } - do { - i--; - while (i > 0) { - a = a->e_next; - if (precvalue(&b->e_value, - &a->e_value)) - break; - i--; - } - if (i == 0) - break; - a->e_prev->e_next = b; - b->e_prev = a->e_prev; - j--; - while (j > 0) { - b = b->e_next; - if (!precvalue(&b->e_value, - &a->e_value)) - break; - j--; - } - if (j != 0) { - b->e_prev->e_next = a; - a->e_prev = b->e_prev; - } - } while (j != 0); + do { + i--; + while (i > 0) { + a = a->e_next; + if (precvalue(&b->e_value, + &a->e_value)) + break; + i--; + } + if (i == 0) + break; + a->e_prev->e_next = b; + b->e_prev = a->e_prev; + j--; + while (j > 0) { + b = b->e_next; + if (!precvalue(&b->e_value, + &a->e_value)) + break; + j--; + } + if (j != 0) { + b->e_prev->e_next = a; + a->e_prev = b->e_prev; + } + } while (j != 0); - if (i == 0) { - a->e_next = b; - b->e_prev = a; - } else if (j == 0) { - b->e_next = a; - a->e_prev = b; - last = a1; - } - } - } - if (k >= LONG_BITS) { - /* this should never happen */ - math_error("impossible k overflow in listsort!"); - not_reached(); - } - lp->l_first = start->e_next; - lp->l_first->e_prev = NULL; - lp->l_last = last; - lp->l_last->e_next = NULL; - elemfree(start); + if (i == 0) { + a->e_next = b; + b->e_prev = a; + } else if (j == 0) { + b->e_next = a; + a->e_prev = b; + last = a1; + } + } + } + if (k >= LONG_BITS) { + /* this should never happen */ + math_error("impossible k overflow in listsort!"); + not_reached(); + } + lp->l_first = start->e_next; + lp->l_first->e_prev = NULL; + lp->l_last = last; + lp->l_last->e_next = NULL; + elemfree(start); } void listrandperm(LIST *lp) { - LISTELEM *ep, *eq; - long i, s; - VALUE val; + LISTELEM *ep, *eq; + long i, s; + VALUE val; - s = lp->l_count; - for (ep = lp->l_last; s > 1; ep = ep->e_prev) { - i = irand(s--); - if (i < s) { - eq = listelement(lp, i); - val = eq->e_value; - eq->e_value = ep->e_value; - ep->e_value = val; - } - } + s = lp->l_count; + for (ep = lp->l_last; s > 1; ep = ep->e_prev) { + i = irand(s--); + if (i < s) { + eq = listelement(lp, i); + val = eq->e_value; + eq->e_value = ep->e_value; + ep->e_value = val; + } + } } @@ -808,18 +808,18 @@ listrandperm(LIST *lp) S_FUNC LISTELEM * elemalloc(void) { - LISTELEM *ep; + LISTELEM *ep; - ep = (LISTELEM *) malloc(sizeof(LISTELEM)); - if (ep == NULL) { - math_error("Cannot allocate list element"); - not_reached(); - } - ep->e_next = NULL; - ep->e_prev = NULL; - ep->e_value.v_type = V_NULL; - ep->e_value.v_subtype = V_NOSUBTYPE; - return ep; + ep = (LISTELEM *) malloc(sizeof(LISTELEM)); + if (ep == NULL) { + math_error("Cannot allocate list element"); + not_reached(); + } + ep->e_next = NULL; + ep->e_prev = NULL; + ep->e_value.v_type = V_NULL; + ep->e_value.v_subtype = V_NOSUBTYPE; + return ep; } @@ -829,9 +829,9 @@ elemalloc(void) S_FUNC void elemfree(LISTELEM *ep) { - if (ep->e_value.v_type != V_NULL) - freevalue(&ep->e_value); - free(ep); + if (ep->e_value.v_type != V_NULL) + freevalue(&ep->e_value); + free(ep); } @@ -841,19 +841,19 @@ elemfree(LISTELEM *ep) LIST * listalloc(void) { - register LIST *lp; + register LIST *lp; - lp = (LIST *) malloc(sizeof(LIST)); - if (lp == NULL) { - math_error("Cannot allocate list header"); - not_reached(); - } - lp->l_first = NULL; - lp->l_last = NULL; - lp->l_cache = NULL; - lp->l_cacheindex = 0; - lp->l_count = 0; - return lp; + lp = (LIST *) malloc(sizeof(LIST)); + if (lp == NULL) { + math_error("Cannot allocate list header"); + not_reached(); + } + lp->l_first = NULL; + lp->l_last = NULL; + lp->l_cache = NULL; + lp->l_cacheindex = 0; + lp->l_count = 0; + return lp; } @@ -863,14 +863,14 @@ listalloc(void) void listfree(LIST *lp) { - register LISTELEM *ep; + register LISTELEM *ep; - while (lp->l_count-- > 0) { - ep = lp->l_first; - lp->l_first = ep->e_next; - elemfree(ep); - } - free(lp); + while (lp->l_count-- > 0) { + ep = lp->l_first; + lp->l_first = ep->e_next; + elemfree(ep); + } + free(lp); } @@ -881,40 +881,40 @@ listfree(LIST *lp) void listprint(LIST *lp, long max_print) { - long count; - long index; - LISTELEM *ep; + long count; + long index; + LISTELEM *ep; - if (max_print > lp->l_count) - max_print = lp->l_count; - count = 0; - ep = lp->l_first; - index = lp->l_count; - while (index-- > 0) { - if ((ep->e_value.v_type != V_NUM) || - (!qiszero(ep->e_value.v_num))) - count++; - ep = ep->e_next; - } - if (max_print > 0) - math_str("\n"); - math_fmt("list (%ld element%s, %ld nonzero)", lp->l_count, - ((lp->l_count == 1) ? "" : "s"), count); - if (max_print <= 0) - return; + if (max_print > lp->l_count) + max_print = lp->l_count; + count = 0; + ep = lp->l_first; + index = lp->l_count; + while (index-- > 0) { + if ((ep->e_value.v_type != V_NUM) || + (!qiszero(ep->e_value.v_num))) + count++; + ep = ep->e_next; + } + if (max_print > 0) + math_str("\n"); + math_fmt("list (%ld element%s, %ld nonzero)", lp->l_count, + ((lp->l_count == 1) ? "" : "s"), count); + if (max_print <= 0) + return; - /* - * Walk through the first few list elements, printing their - * value in short and unambiguous format. - */ - math_str(":\n"); - ep = lp->l_first; - for (index = 0; index < max_print; index++) { - math_fmt("\t[[%ld]] = ", index); - printvalue(&ep->e_value, PRINT_SHORT | PRINT_UNAMBIG); - math_str("\n"); - ep = ep->e_next; - } - if (max_print < lp->l_count) - math_str(" ...\n"); + /* + * Walk through the first few list elements, printing their + * value in short and unambiguous format. + */ + math_str(":\n"); + ep = lp->l_first; + for (index = 0; index < max_print; index++) { + math_fmt("\t[[%ld]] = ", index); + printvalue(&ep->e_value, PRINT_SHORT | PRINT_UNAMBIG); + math_str("\n"); + ep = ep->e_next; + } + if (max_print < lp->l_count) + math_str(" ...\n"); } diff --git a/longbits.c b/longbits.c index f41cf45..3d9041d 100644 --- a/longbits.c +++ b/longbits.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,63 +17,63 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1994/03/18 03:06:18 - * File existed as early as: 1994 + * Under source code control: 1994/03/18 03:06:18 + * File existed as early as: 1994 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * longbits [long_bit_size] + * longbits [long_bit_size] * - * long_bit_size force size of long (must be 32 or 64) + * long_bit_size force size of long (must be 32 or 64) * * NOTE: If long_bit_size arg is empty (0 chars long) or it begins with - * a whitespace character, it will be ignored and no forcing will - * be done. + * a whitespace character, it will be ignored and no forcing will + * be done. * * Not all (in fact very few) C pre-processors can do: * - * #if sizeof(long) == 8 + * #if sizeof(long) == 8 * * so we have to form LONG_BITS ahead of time. * * This prog outputs several defines and typedefs: * - * LONG_BITS - * Number of bits in a long. + * LONG_BITS + * Number of bits in a long. * - * PTR_LEN - * Length of a pointer in bytes. We use void * as a generic pointer. + * PTR_LEN + * Length of a pointer in bytes. We use void * as a generic pointer. * - * PTR_BITS - * Length of a pointer in bits. We use void * as a generic pointer. + * PTR_BITS + * Length of a pointer in bits. We use void * as a generic pointer. * - * USB8 unsigned 8 bit value - * SB8 signed 8 bit value + * USB8 unsigned 8 bit value + * SB8 signed 8 bit value * - * USB16 unsigned 16 bit value - * SB16 signed 16 bit value + * USB16 unsigned 16 bit value + * SB16 signed 16 bit value * - * USB32 unsigned 32 bit value - * SB32 signed 32 bit value + * USB32 unsigned 32 bit value + * SB32 signed 32 bit value * - * HAVE_B64 - * defined ==> OK to use USB64 (unsigned 64 bit value) - * and SB64 (signed 64 bit value) - * undefined ==> do not use USB64 nor SB64 + * HAVE_B64 + * defined ==> OK to use USB64 (unsigned 64 bit value) + * and SB64 (signed 64 bit value) + * undefined ==> do not use USB64 nor SB64 * - * BOOL_B64 - * If HAVE_B64 undefined ==> false - * If HAVE_B64 defined ==> true + * BOOL_B64 + * If HAVE_B64 undefined ==> false + * If HAVE_B64 defined ==> true * - * USB64 unsigned 64 bit value if HAVE_B64 is defined - * SB64 signed 64 bit value if HAVE_B64 is defined + * USB64 unsigned 64 bit value if HAVE_B64 is defined + * SB64 signed 64 bit value if HAVE_B64 is defined * - * L(x) form a 33 to 64 bit signed constant - * U(x) form a 33 to 64 bit unsigned constant + * L(x) form a 33 to 64 bit signed constant + * U(x) form a 33 to 64 bit unsigned constant * * We hide the comments within strings to avoid complaints from some snitty * compilers. We also hide 3 X's which is the calc symbol for "something bogus @@ -100,261 +100,261 @@ #include "charbit.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -char *program; /* our name */ +char *program; /* our name */ int main(int argc, char **argv) { - int exitcode = 0; /* how we will exit */ - size_t long_bits = 0; /* bit length of a long */ - int forced_size = 0; /* 1 => size of long was forced via arg */ - char value; /* signed or maybe unsigned character */ + int exitcode = 0; /* how we will exit */ + size_t long_bits = 0; /* bit length of a long */ + int forced_size = 0; /* 1 => size of long was forced via arg */ + char value; /* signed or maybe unsigned character */ - /* - * parse args - */ - program = argv[0]; - switch (argc) { - case 1: - long_bits = sizeof(long)*8; - break; - case 2: - /* ignore empty or leading space args */ - if (argv[1][0] == '\0' || - (isascii((int)argv[1][0]) && isspace((int)argv[1][0]))) { - long_bits = sizeof(long)*CALC_CHARBIT; - /* process the forced size arg */ - } else { - forced_size = 1; - long_bits = atoi(argv[1]); - if (long_bits != 32 && long_bits != 64) { - fprintf(stderr, - "usage: %s [32 or 64]\n", program); - exit(1); - } - } - break; - default: - fprintf(stderr, "usage: %s [32 or 64]\n", program); - exit(2); - } + /* + * parse args + */ + program = argv[0]; + switch (argc) { + case 1: + long_bits = sizeof(long)*8; + break; + case 2: + /* ignore empty or leading space args */ + if (argv[1][0] == '\0' || + (isascii((int)argv[1][0]) && isspace((int)argv[1][0]))) { + long_bits = sizeof(long)*CALC_CHARBIT; + /* process the forced size arg */ + } else { + forced_size = 1; + long_bits = atoi(argv[1]); + if (long_bits != 32 && long_bits != 64) { + fprintf(stderr, + "usage: %s [32 or 64]\n", program); + exit(1); + } + } + break; + default: + fprintf(stderr, "usage: %s [32 or 64]\n", program); + exit(2); + } - /* - * report size of a long - */ - printf("#undef LONG_BITS\n"); - printf("#define LONG_BITS %ld\t\t/%s/\n", - (long int)long_bits, "* bit length of a long *"); - putchar('\n'); + /* + * report size of a long + */ + printf("#undef LONG_BITS\n"); + printf("#define LONG_BITS %ld\t\t/%s/\n", + (long int)long_bits, "* bit length of a long *"); + putchar('\n'); - /* - * report size of a pointer - * - * We use "void *" as the size of a generic pointer. - */ - printf("#undef PTR_LEN\n"); + /* + * report size of a pointer + * + * We use "void *" as the size of a generic pointer. + */ + printf("#undef PTR_LEN\n"); #if MAJOR_VER < 3 - printf("#define PTR_LEN %ld\t\t/%s/\n", - (long int)sizeof(void *), "* length of a pointer *"); + printf("#define PTR_LEN %ld\t\t/%s/\n", + (long int)sizeof(void *), "* length of a pointer *"); #else /* MAJOR_VER < 3 */ - printf("#define PTR_LEN UINTPTR_WIDTH\t\t/%s/\n", "* length of a pointer *"); + printf("#define PTR_LEN UINTPTR_WIDTH\t\t/%s/\n", "* length of a pointer *"); #endif /* MAJOR_VER < 3 */ - printf("#undef PTR_BITS\n"); - printf("#define PTR_BITS %ld\t\t/%s/\n", - (long int)sizeof(void *)*CALC_CHARBIT, "* bit length of a pointer *"); - putchar('\n'); + printf("#undef PTR_BITS\n"); + printf("#define PTR_BITS %ld\t\t/%s/\n", + (long int)sizeof(void *)*CALC_CHARBIT, "* bit length of a pointer *"); + putchar('\n'); - /* - * If we are forcing the size of a long, then do not check - * sizes of other values but instead assume that the user - * knows what they are doing. - */ - if (forced_size) { + /* + * If we are forcing the size of a long, then do not check + * sizes of other values but instead assume that the user + * knows what they are doing. + */ + if (forced_size) { - /* - * note that the size was forced - */ - printf("/%s/\n\n", "* size of long was forced *"); + /* + * note that the size was forced + */ + printf("/%s/\n\n", "* size of long was forced *"); - /* - * forced forming of USB8, SB8, USB16 and SB16 - */ - printf("typedef unsigned char USB8;\t/%s/\n", - "* unsigned 8 bits *"); - printf("typedef signed char SB8;\t/%s/\n\n", - "* signed 8 bits *"); + /* + * forced forming of USB8, SB8, USB16 and SB16 + */ + printf("typedef unsigned char USB8;\t/%s/\n", + "* unsigned 8 bits *"); + printf("typedef signed char SB8;\t/%s/\n\n", + "* signed 8 bits *"); - printf("typedef unsigned short USB16;\t/%s/\n", - "* unsigned 16 bits *"); - printf("typedef short SB16;\t\t/%s/\n\n", - "* signed 16 bits *"); + printf("typedef unsigned short USB16;\t/%s/\n", + "* unsigned 16 bits *"); + printf("typedef short SB16;\t\t/%s/\n\n", + "* signed 16 bits *"); - /* - * forced forming of USB32 and SB32 - */ - if (long_bits == 32) { - /* forced 32 bit long mode assumptions */ - printf("typedef unsigned long USB32;\t/%s/\n", - "* unsigned 32 bits *"); - printf("typedef long SB32;\t\t/%s/\n\n", - "* signed 32 bits *"); - } else { - /* forced 64 bit long mode assumptions */ - printf("typedef unsigned int USB32;\t/%s/\n", - "* unsigned 32 bits *"); - printf("typedef int SB32;\t\t/%s/\n\n", - "* signed 32 bits *"); - } + /* + * forced forming of USB32 and SB32 + */ + if (long_bits == 32) { + /* forced 32 bit long mode assumptions */ + printf("typedef unsigned long USB32;\t/%s/\n", + "* unsigned 32 bits *"); + printf("typedef long SB32;\t\t/%s/\n\n", + "* signed 32 bits *"); + } else { + /* forced 64 bit long mode assumptions */ + printf("typedef unsigned int USB32;\t/%s/\n", + "* unsigned 32 bits *"); + printf("typedef int SB32;\t\t/%s/\n\n", + "* signed 32 bits *"); + } - /* - * forced forming of HAVE_B64, USB64, SB64, U(x) and L(x) - */ - printf("#undef HAVE_B64\n"); - printf("#define HAVE_B64\t\t/%s/\n", - "* have USB64 and SB64 types *"); - printf("typedef unsigned long long USB64;\t/%s/\n", - "* unsigned 64 bits *"); - printf("typedef long long SB64;\t\t/%s/\n", - "* signed 64 bits *"); - putchar('\n'); - printf("/%s/\n","* how to form 64 bit constants *"); + /* + * forced forming of HAVE_B64, USB64, SB64, U(x) and L(x) + */ + printf("#undef HAVE_B64\n"); + printf("#define HAVE_B64\t\t/%s/\n", + "* have USB64 and SB64 types *"); + printf("typedef unsigned long long USB64;\t/%s/\n", + "* unsigned 64 bits *"); + printf("typedef long long SB64;\t\t/%s/\n", + "* signed 64 bits *"); + putchar('\n'); + printf("/%s/\n","* how to form 64 bit constants *"); #if defined(FORCE_STDC) || (defined(__STDC__) && __STDC__ != 0) || \ defined(__cplusplus) - printf("#define U(x) x ## ULL\n"); - printf("#define L(x) x ## LL\n"); + printf("#define U(x) x ## ULL\n"); + printf("#define L(x) x ## LL\n"); #else - printf("#define U(x) ((unsigned long long)x)\n"); - printf("#define L(x) ((long long)x)\n"); + printf("#define U(x) ((unsigned long long)x)\n"); + printf("#define L(x) ((long long)x)\n"); #endif - /* - * all done - */ - exit(0); - } + /* + * all done + */ + exit(0); + } - /* - * look for 8 bit values - */ - value = (char)-1; - if (sizeof(char) != 1) { - fprintf(stderr, - "%s: OUCH!!! - char is not a single byte!\n", program); - fprintf(stderr, - "%s: fix the USB8 typedef by hand\n", program); - printf("typedef unsigned char USB8;\t/* XX%s/ -=*#*=-\n", - "X - should be 8 unsigned bits but is not *"); - if (value < 1) { - printf("typedef char SB8;\t\t/* XX%s/ -=*#*=-\n", - "X - should be 8 signed bits but is not *"); - } else { - printf("typedef signed char SB8;\t\t/* XX%s/ -=*#*=-\n", - "X - should be 8 signed bits but is not *"); - } - exitcode = 3; - } else { - printf("typedef unsigned char USB8;\t/%s/\n", - "* unsigned 8 bits *"); - if (value < 1) { - printf("typedef char SB8;\t\t/%s/\n", - "* signed 8 bits *"); - } else { - printf("typedef signed char SB8;\t\t/%s/\n", - "* signed 8 bits *"); - } - } - putchar('\n'); + /* + * look for 8 bit values + */ + value = (char)-1; + if (sizeof(char) != 1) { + fprintf(stderr, + "%s: OUCH!!! - char is not a single byte!\n", program); + fprintf(stderr, + "%s: fix the USB8 typedef by hand\n", program); + printf("typedef unsigned char USB8;\t/* XX%s/ -=*#*=-\n", + "X - should be 8 unsigned bits but is not *"); + if (value < 1) { + printf("typedef char SB8;\t\t/* XX%s/ -=*#*=-\n", + "X - should be 8 signed bits but is not *"); + } else { + printf("typedef signed char SB8;\t\t/* XX%s/ -=*#*=-\n", + "X - should be 8 signed bits but is not *"); + } + exitcode = 3; + } else { + printf("typedef unsigned char USB8;\t/%s/\n", + "* unsigned 8 bits *"); + if (value < 1) { + printf("typedef char SB8;\t\t/%s/\n", + "* signed 8 bits *"); + } else { + printf("typedef signed char SB8;\t\t/%s/\n", + "* signed 8 bits *"); + } + } + putchar('\n'); - /* - * look for 16 bit values - */ - if (sizeof(short) != 2) { - fprintf(stderr, - "%s: OUCH!!! - short is not a 2 bytes!\n", program); - fprintf(stderr, - "%s: fix the USB16 typedef by hand\n", program); - printf("typedef unsigned short USB16;\t/* XX%s/ -=*#*=-\n", - "X - should be 16 unsigned bits but is not *"); - printf("typedef signed char SB16;\t/* XX%s/ -=*#*=-\n", - "X - should be 16 signed bits but is not *"); - exitcode = 4; - } else { - printf("typedef unsigned short USB16;\t/%s/\n", - "* unsigned 16 bits *"); - printf("typedef short SB16;\t\t/%s/\n", - "* signed 16 bits *"); - } - putchar('\n'); + /* + * look for 16 bit values + */ + if (sizeof(short) != 2) { + fprintf(stderr, + "%s: OUCH!!! - short is not a 2 bytes!\n", program); + fprintf(stderr, + "%s: fix the USB16 typedef by hand\n", program); + printf("typedef unsigned short USB16;\t/* XX%s/ -=*#*=-\n", + "X - should be 16 unsigned bits but is not *"); + printf("typedef signed char SB16;\t/* XX%s/ -=*#*=-\n", + "X - should be 16 signed bits but is not *"); + exitcode = 4; + } else { + printf("typedef unsigned short USB16;\t/%s/\n", + "* unsigned 16 bits *"); + printf("typedef short SB16;\t\t/%s/\n", + "* signed 16 bits *"); + } + putchar('\n'); - /* - * look for 32 bit values - */ - if (sizeof(long) == 4) { - printf("typedef unsigned long USB32;\t/%s/\n", - "* unsigned 32 bits *"); - printf("typedef long SB32;\t\t/%s/\n", - "* signed 32 bits *"); - } else if (sizeof(int) == 4) { - printf("typedef unsigned int USB32;\t/%s/\n", - "* unsigned 32 bits *"); - printf("typedef int SB32;\t\t/%s/\n", - "* signed 32 bits *"); - } else { - fprintf(stderr, - "%s: OUCH!!! - neither int nor long are 4 bytes!\n", program); - printf("typedef unsigned int USB32;\t/* XX%s/ -=*#*=-\n", - "X - should be 32 unsigned bits but is not *"); - printf("typedef signed int SB32;\t/* XX%s/ -=*#*=-\n", - "X - should be 32 signed bits but is not *"); - exitcode = 5; - } - putchar('\n'); + /* + * look for 32 bit values + */ + if (sizeof(long) == 4) { + printf("typedef unsigned long USB32;\t/%s/\n", + "* unsigned 32 bits *"); + printf("typedef long SB32;\t\t/%s/\n", + "* signed 32 bits *"); + } else if (sizeof(int) == 4) { + printf("typedef unsigned int USB32;\t/%s/\n", + "* unsigned 32 bits *"); + printf("typedef int SB32;\t\t/%s/\n", + "* signed 32 bits *"); + } else { + fprintf(stderr, + "%s: OUCH!!! - neither int nor long are 4 bytes!\n", program); + printf("typedef unsigned int USB32;\t/* XX%s/ -=*#*=-\n", + "X - should be 32 unsigned bits but is not *"); + printf("typedef signed int SB32;\t/* XX%s/ -=*#*=-\n", + "X - should be 32 signed bits but is not *"); + exitcode = 5; + } + putchar('\n'); - /* - * look for 64 bit values - */ - if (sizeof(long) == 8) { - printf("#undef HAVE_B64\n"); - printf("#define HAVE_B64\t\t/%s/\n", - "* have USB64 and SB64 types *"); - printf("typedef unsigned long USB64;\t/%s/\n", - "* unsigned 64 bits *"); - printf("typedef long SB64;\t\t/%s/\n", - "* signed 64 bits *"); - putchar('\n'); - printf("/%s/\n","* how to form 64 bit constants *"); + /* + * look for 64 bit values + */ + if (sizeof(long) == 8) { + printf("#undef HAVE_B64\n"); + printf("#define HAVE_B64\t\t/%s/\n", + "* have USB64 and SB64 types *"); + printf("typedef unsigned long USB64;\t/%s/\n", + "* unsigned 64 bits *"); + printf("typedef long SB64;\t\t/%s/\n", + "* signed 64 bits *"); + putchar('\n'); + printf("/%s/\n","* how to form 64 bit constants *"); #if defined(FORCE_STDC) || (defined(__STDC__) && __STDC__ != 0) || \ defined(__cplusplus) - printf("#define U(x) x ## UL\n"); - printf("#define L(x) x ## L\n"); + printf("#define U(x) x ## UL\n"); + printf("#define L(x) x ## L\n"); #else - printf("#define U(x) ((unsigned long)x)\n"); - printf("#define L(x) ((long)x)\n"); + printf("#define U(x) ((unsigned long)x)\n"); + printf("#define L(x) ((long)x)\n"); #endif - } else { - printf("#undef HAVE_B64\n"); - printf("#define HAVE_B64\t\t/%s/\n", - "* have USB64 and SB64 types *"); - printf("typedef unsigned long long USB64;\t/%s/\n", - "* unsigned 64 bits *"); - printf("typedef long long SB64;\t\t/%s/\n", - "* signed 64 bits *"); - putchar('\n'); - printf("/%s/\n","* how to form 64 bit constants *"); + } else { + printf("#undef HAVE_B64\n"); + printf("#define HAVE_B64\t\t/%s/\n", + "* have USB64 and SB64 types *"); + printf("typedef unsigned long long USB64;\t/%s/\n", + "* unsigned 64 bits *"); + printf("typedef long long SB64;\t\t/%s/\n", + "* signed 64 bits *"); + putchar('\n'); + printf("/%s/\n","* how to form 64 bit constants *"); #if defined(FORCE_STDC) || (defined(__STDC__) && __STDC__ != 0) || \ defined(__cplusplus) - printf("#define U(x) x ## ULL\n"); - printf("#define L(x) x ## LL\n"); + printf("#define U(x) x ## ULL\n"); + printf("#define L(x) x ## LL\n"); #else - printf("#define U(x) ((unsigned long long)x)\n"); - printf("#define L(x) ((long long)x)\n"); + printf("#define U(x) ((unsigned long long)x)\n"); + printf("#define L(x) ((long long)x)\n"); #endif - } + } - /* all done */ - /* exit(exitcode); */ - return exitcode; + /* all done */ + /* exit(exitcode); */ + return exitcode; } diff --git a/matfunc.c b/matfunc.c index e98d865..019978d 100644 --- a/matfunc.c +++ b/matfunc.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:18 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:18 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -36,7 +36,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ E_FUNC long irand(long s); @@ -54,40 +54,40 @@ S_FUNC MATRIX *matident(MATRIX *m); MATRIX * matadd(MATRIX *m1, MATRIX *m2) { - int dim; + int dim; - long min1, min2, max1, max2, index; - VALUE *v1, *v2, *vres; - MATRIX *res; - MATRIX tmp; + long min1, min2, max1, max2, index; + VALUE *v1, *v2, *vres; + MATRIX *res; + MATRIX tmp; - if (m1->m_dim != m2->m_dim) { - math_error("Incompatible matrix dimensions for add"); - not_reached(); - } - tmp.m_dim = m1->m_dim; - tmp.m_size = m1->m_size; - for (dim = 0; dim < m1->m_dim; dim++) { - min1 = m1->m_min[dim]; - max1 = m1->m_max[dim]; - min2 = m2->m_min[dim]; - max2 = m2->m_max[dim]; - if ((min1 && min2 && (min1 != min2)) || - ((max1-min1) != (max2-min2))) { - math_error("Incompatible matrix bounds for add"); - not_reached(); - } - tmp.m_min[dim] = (min1 ? min1 : min2); - tmp.m_max[dim] = tmp.m_min[dim] + (max1 - min1); - } - res = matalloc(m1->m_size); - *res = tmp; - v1 = m1->m_table; - v2 = m2->m_table; - vres = res->m_table; - for (index = m1->m_size; index > 0; index--) - addvalue(v1++, v2++, vres++); - return res; + if (m1->m_dim != m2->m_dim) { + math_error("Incompatible matrix dimensions for add"); + not_reached(); + } + tmp.m_dim = m1->m_dim; + tmp.m_size = m1->m_size; + for (dim = 0; dim < m1->m_dim; dim++) { + min1 = m1->m_min[dim]; + max1 = m1->m_max[dim]; + min2 = m2->m_min[dim]; + max2 = m2->m_max[dim]; + if ((min1 && min2 && (min1 != min2)) || + ((max1-min1) != (max2-min2))) { + math_error("Incompatible matrix bounds for add"); + not_reached(); + } + tmp.m_min[dim] = (min1 ? min1 : min2); + tmp.m_max[dim] = tmp.m_min[dim] + (max1 - min1); + } + res = matalloc(m1->m_size); + *res = tmp; + v1 = m1->m_table; + v2 = m2->m_table; + vres = res->m_table; + for (index = m1->m_size; index > 0; index--) + addvalue(v1++, v2++, vres++); + return res; } @@ -97,39 +97,39 @@ matadd(MATRIX *m1, MATRIX *m2) MATRIX * matsub(MATRIX *m1, MATRIX *m2) { - int dim; - long min1, min2, max1, max2, index; - VALUE *v1, *v2, *vres; - MATRIX *res; - MATRIX tmp; + int dim; + long min1, min2, max1, max2, index; + VALUE *v1, *v2, *vres; + MATRIX *res; + MATRIX tmp; - if (m1->m_dim != m2->m_dim) { - math_error("Incompatible matrix dimensions for sub"); - not_reached(); - } - tmp.m_dim = m1->m_dim; - tmp.m_size = m1->m_size; - for (dim = 0; dim < m1->m_dim; dim++) { - min1 = m1->m_min[dim]; - max1 = m1->m_max[dim]; - min2 = m2->m_min[dim]; - max2 = m2->m_max[dim]; - if ((min1 && min2 && (min1 != min2)) || - ((max1-min1) != (max2-min2))) { - math_error("Incompatible matrix bounds for sub"); - not_reached(); - } - tmp.m_min[dim] = (min1 ? min1 : min2); - tmp.m_max[dim] = tmp.m_min[dim] + (max1 - min1); - } - res = matalloc(m1->m_size); - *res = tmp; - v1 = m1->m_table; - v2 = m2->m_table; - vres = res->m_table; - for (index = m1->m_size; index > 0; index--) - subvalue(v1++, v2++, vres++); - return res; + if (m1->m_dim != m2->m_dim) { + math_error("Incompatible matrix dimensions for sub"); + not_reached(); + } + tmp.m_dim = m1->m_dim; + tmp.m_size = m1->m_size; + for (dim = 0; dim < m1->m_dim; dim++) { + min1 = m1->m_min[dim]; + max1 = m1->m_max[dim]; + min2 = m2->m_min[dim]; + max2 = m2->m_max[dim]; + if ((min1 && min2 && (min1 != min2)) || + ((max1-min1) != (max2-min2))) { + math_error("Incompatible matrix bounds for sub"); + not_reached(); + } + tmp.m_min[dim] = (min1 ? min1 : min2); + tmp.m_max[dim] = tmp.m_min[dim] + (max1 - min1); + } + res = matalloc(m1->m_size); + *res = tmp; + v1 = m1->m_table; + v2 = m2->m_table; + vres = res->m_table; + for (index = m1->m_size; index > 0; index--) + subvalue(v1++, v2++, vres++); + return res; } @@ -139,17 +139,17 @@ matsub(MATRIX *m1, MATRIX *m2) MATRIX * matneg(MATRIX *m) { - register VALUE *val, *vres; - long index; - MATRIX *res; + register VALUE *val, *vres; + long index; + MATRIX *res; - res = matalloc(m->m_size); - *res = *m; - val = m->m_table; - vres = res->m_table; - for (index = m->m_size; index > 0; index--) - negvalue(val++, vres++); - return res; + res = matalloc(m->m_size); + *res = *m; + val = m->m_table; + vres = res->m_table; + for (index = m->m_size; index > 0; index--) + negvalue(val++, vres++); + return res; } @@ -159,123 +159,123 @@ matneg(MATRIX *m) MATRIX * matmul(MATRIX *m1, MATRIX *m2) { - register MATRIX *res; - long i1, i2, max1, max2, index, maxindex; - VALUE *v1, *v2, *vres; - VALUE sum, tmp1, tmp2; + register MATRIX *res; + long i1, i2, max1, max2, index, maxindex; + VALUE *v1, *v2, *vres; + VALUE sum, tmp1, tmp2; - if (m1->m_dim == 0) { - i2 = m2->m_size; - v2 = m2->m_table; - res = matalloc(i2); - *res = *m2; - vres = res->m_table; - while (i2-- > 0) - mulvalue(m1->m_table, v2++, vres++); - return res; - } - if (m2->m_dim == 0) { - i1 = m1->m_size; - v1 = m1->m_table; - res = matalloc(i1); - *res = *m1; - vres = res->m_table; - while (i1-- > 0) - mulvalue(v1++, m2->m_table, vres++); - return res; - } - if (m1->m_dim == 1 && m2->m_dim == 1) { - if (m1->m_max[0]-m1->m_min[0] != m2->m_max[0]-m2->m_min[0]) { - math_error("Incompatible bounds for 1D * 1D matmul"); - not_reached(); - } - res = matalloc(m1->m_size); - *res = *m1; - v1 = m1->m_table; - v2 = m2->m_table; - vres = res->m_table; - for (index = m1->m_size; index > 0; index--) - mulvalue(v1++, v2++, vres++); - return res; - } - if (m1->m_dim == 1 && m2->m_dim == 2) { - if (m1->m_max[0]-m1->m_min[0] != m2->m_max[0]-m2->m_min[0]) { - math_error("Incompatible bounds for 1D * 2D matmul"); - not_reached(); - } - res = matalloc(m2->m_size); - *res = *m2; - i1 = m1->m_max[0] - m1->m_min[0] + 1; - max2 = m2->m_max[1] - m2->m_min[1] + 1; - v1 = m1->m_table; - v2 = m2->m_table; - vres = res->m_table; - while (i1-- > 0) { - i2 = max2; - while (i2-- > 0) - mulvalue(v1, v2++, vres++); - v1++; - } - return res; - } - if (m1->m_dim == 2 && m2->m_dim == 1) { - if (m1->m_max[1]-m1->m_min[1] != m2->m_max[0]-m2->m_min[0]) { - math_error("Incompatible bounds for 2D * 1D matmul"); - not_reached(); - } - res = matalloc(m1->m_size); - *res = *m1; - i1 = m1->m_max[0] - m1->m_min[0] + 1; - max1 = m1->m_max[1] - m1->m_min[1] + 1; - v1 = m1->m_table; - vres = res->m_table; - while (i1-- > 0) { - v2 = m2->m_table; - i2 = max1; - while (i2-- > 0) - mulvalue(v1++, v2++, vres++); - } - return res; - } + if (m1->m_dim == 0) { + i2 = m2->m_size; + v2 = m2->m_table; + res = matalloc(i2); + *res = *m2; + vres = res->m_table; + while (i2-- > 0) + mulvalue(m1->m_table, v2++, vres++); + return res; + } + if (m2->m_dim == 0) { + i1 = m1->m_size; + v1 = m1->m_table; + res = matalloc(i1); + *res = *m1; + vres = res->m_table; + while (i1-- > 0) + mulvalue(v1++, m2->m_table, vres++); + return res; + } + if (m1->m_dim == 1 && m2->m_dim == 1) { + if (m1->m_max[0]-m1->m_min[0] != m2->m_max[0]-m2->m_min[0]) { + math_error("Incompatible bounds for 1D * 1D matmul"); + not_reached(); + } + res = matalloc(m1->m_size); + *res = *m1; + v1 = m1->m_table; + v2 = m2->m_table; + vres = res->m_table; + for (index = m1->m_size; index > 0; index--) + mulvalue(v1++, v2++, vres++); + return res; + } + if (m1->m_dim == 1 && m2->m_dim == 2) { + if (m1->m_max[0]-m1->m_min[0] != m2->m_max[0]-m2->m_min[0]) { + math_error("Incompatible bounds for 1D * 2D matmul"); + not_reached(); + } + res = matalloc(m2->m_size); + *res = *m2; + i1 = m1->m_max[0] - m1->m_min[0] + 1; + max2 = m2->m_max[1] - m2->m_min[1] + 1; + v1 = m1->m_table; + v2 = m2->m_table; + vres = res->m_table; + while (i1-- > 0) { + i2 = max2; + while (i2-- > 0) + mulvalue(v1, v2++, vres++); + v1++; + } + return res; + } + if (m1->m_dim == 2 && m2->m_dim == 1) { + if (m1->m_max[1]-m1->m_min[1] != m2->m_max[0]-m2->m_min[0]) { + math_error("Incompatible bounds for 2D * 1D matmul"); + not_reached(); + } + res = matalloc(m1->m_size); + *res = *m1; + i1 = m1->m_max[0] - m1->m_min[0] + 1; + max1 = m1->m_max[1] - m1->m_min[1] + 1; + v1 = m1->m_table; + vres = res->m_table; + while (i1-- > 0) { + v2 = m2->m_table; + i2 = max1; + while (i2-- > 0) + mulvalue(v1++, v2++, vres++); + } + return res; + } - if ((m1->m_dim != 2) || (m2->m_dim != 2)) { - math_error("Matrix dimensions not compatible for mul"); - not_reached(); - } - if ((m1->m_max[1]-m1->m_min[1]) != (m2->m_max[0]-m2->m_min[0])) { - math_error("Incompatible bounds for 2D * 2D matrix mul"); - not_reached(); - } - max1 = (m1->m_max[0] - m1->m_min[0] + 1); - max2 = (m2->m_max[1] - m2->m_min[1] + 1); - maxindex = (m1->m_max[1] - m1->m_min[1] + 1); - res = matalloc(max1 * max2); - res->m_dim = 2; - res->m_min[0] = m1->m_min[0]; - res->m_max[0] = m1->m_max[0]; - res->m_min[1] = m2->m_min[1]; - res->m_max[1] = m2->m_max[1]; - for (i1 = 0; i1 < max1; i1++) { - for (i2 = 0; i2 < max2; i2++) { - sum.v_type = V_NULL; - sum.v_subtype = V_NOSUBTYPE; - v1 = &m1->m_table[i1 * maxindex]; - v2 = &m2->m_table[i2]; - for (index = 0; index < maxindex; index++) { - mulvalue(v1, v2, &tmp1); - addvalue(&sum, &tmp1, &tmp2); - freevalue(&tmp1); - freevalue(&sum); - sum = tmp2; - v1++; - if (index+1 < maxindex) - v2 += max2; - } - index = (i1 * max2) + i2; - res->m_table[index] = sum; - } - } - return res; + if ((m1->m_dim != 2) || (m2->m_dim != 2)) { + math_error("Matrix dimensions not compatible for mul"); + not_reached(); + } + if ((m1->m_max[1]-m1->m_min[1]) != (m2->m_max[0]-m2->m_min[0])) { + math_error("Incompatible bounds for 2D * 2D matrix mul"); + not_reached(); + } + max1 = (m1->m_max[0] - m1->m_min[0] + 1); + max2 = (m2->m_max[1] - m2->m_min[1] + 1); + maxindex = (m1->m_max[1] - m1->m_min[1] + 1); + res = matalloc(max1 * max2); + res->m_dim = 2; + res->m_min[0] = m1->m_min[0]; + res->m_max[0] = m1->m_max[0]; + res->m_min[1] = m2->m_min[1]; + res->m_max[1] = m2->m_max[1]; + for (i1 = 0; i1 < max1; i1++) { + for (i2 = 0; i2 < max2; i2++) { + sum.v_type = V_NULL; + sum.v_subtype = V_NOSUBTYPE; + v1 = &m1->m_table[i1 * maxindex]; + v2 = &m2->m_table[i2]; + for (index = 0; index < maxindex; index++) { + mulvalue(v1, v2, &tmp1); + addvalue(&sum, &tmp1, &tmp2); + freevalue(&tmp1); + freevalue(&sum); + sum = tmp2; + v1++; + if (index+1 < maxindex) + v2 += max2; + } + index = (i1 * max2) + i2; + res->m_table[index] = sum; + } + } + return res; } @@ -285,55 +285,55 @@ matmul(MATRIX *m1, MATRIX *m2) MATRIX * matsquare(MATRIX *m) { - register MATRIX *res; - long i1, i2, max, index; - VALUE *v1, *v2; - VALUE sum, tmp1, tmp2; + register MATRIX *res; + long i1, i2, max, index; + VALUE *v1, *v2; + VALUE sum, tmp1, tmp2; - if (m->m_dim < 2) { - res = matalloc(m->m_size); - *res = *m; - v1 = m->m_table; - v2 = res->m_table; - for (index = m->m_size; index > 0; index--) - squarevalue(v1++, v2++); - return res; - } - if (m->m_dim != 2) { - math_error("Matrix dimension exceeds two for square"); - not_reached(); - } - if ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1])) { - math_error("Squaring non-square matrix"); - not_reached(); - } - max = (m->m_max[0] - m->m_min[0] + 1); - res = matalloc(max * max); - res->m_dim = 2; - res->m_min[0] = m->m_min[0]; - res->m_max[0] = m->m_max[0]; - res->m_min[1] = m->m_min[1]; - res->m_max[1] = m->m_max[1]; - for (i1 = 0; i1 < max; i1++) { - for (i2 = 0; i2 < max; i2++) { - sum.v_type = V_NULL; - sum.v_subtype = V_NOSUBTYPE; - v1 = &m->m_table[i1 * max]; - v2 = &m->m_table[i2]; - for (index = 0; index < max; index++) { - mulvalue(v1, v2, &tmp1); - addvalue(&sum, &tmp1, &tmp2); - freevalue(&tmp1); - freevalue(&sum); - sum = tmp2; - v1++; - v2 += max; - } - index = (i1 * max) + i2; - res->m_table[index] = sum; - } - } - return res; + if (m->m_dim < 2) { + res = matalloc(m->m_size); + *res = *m; + v1 = m->m_table; + v2 = res->m_table; + for (index = m->m_size; index > 0; index--) + squarevalue(v1++, v2++); + return res; + } + if (m->m_dim != 2) { + math_error("Matrix dimension exceeds two for square"); + not_reached(); + } + if ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1])) { + math_error("Squaring non-square matrix"); + not_reached(); + } + max = (m->m_max[0] - m->m_min[0] + 1); + res = matalloc(max * max); + res->m_dim = 2; + res->m_min[0] = m->m_min[0]; + res->m_max[0] = m->m_max[0]; + res->m_min[1] = m->m_min[1]; + res->m_max[1] = m->m_max[1]; + for (i1 = 0; i1 < max; i1++) { + for (i2 = 0; i2 < max; i2++) { + sum.v_type = V_NULL; + sum.v_subtype = V_NOSUBTYPE; + v1 = &m->m_table[i1 * max]; + v2 = &m->m_table[i2]; + for (index = 0; index < max; index++) { + mulvalue(v1, v2, &tmp1); + addvalue(&sum, &tmp1, &tmp2); + freevalue(&tmp1); + freevalue(&sum); + sum = tmp2; + v1++; + v2 += max; + } + index = (i1 * max) + i2; + res->m_table[index] = sum; + } + } + return res; } @@ -345,163 +345,163 @@ matsquare(MATRIX *m) * by using the characteristic polynomial of the matrix. * * given: - * m matrix to be raised - * q power to raise it to + * m matrix to be raised + * q power to raise it to */ MATRIX * matpowi(MATRIX *m, NUMBER *q) { - MATRIX *res, *tmp; - long power; /* power to raise to */ - FULL bit; /* current bit value */ + MATRIX *res, *tmp; + long power; /* power to raise to */ + FULL bit; /* current bit value */ - if (m->m_dim > 2) { - math_error("Matrix dimension greater than 2 for power"); - not_reached(); - } - if (m->m_dim == 2 && (m->m_max[0] - m->m_min[0] != - m->m_max[1] - m->m_min[1])) { - math_error("Raising non-square 2D matrix to a power"); - not_reached(); - } - if (qisfrac(q)) { - math_error("Raising matrix to non-integral power"); - not_reached(); - } - if (zge31b(q->num)) { - math_error("Raising matrix to very large power"); - not_reached(); - } - power = ztolong(q->num); - if (qisneg(q)) - power = -power; - /* - * Handle some low powers specially - */ - if ((power <= 4) && (power >= -2)) { - switch ((int) power) { - case 0: - return matident(m); - case 1: - return matcopy(m); - case -1: - return matinv(m); - case 2: - return matsquare(m); - case -2: - tmp = matinv(m); - res = matsquare(tmp); - matfree(tmp); - return res; - case 3: - tmp = matsquare(m); - res = matmul(m, tmp); - matfree(tmp); - return res; - case 4: - tmp = matsquare(m); - res = matsquare(tmp); - matfree(tmp); - return res; - } - } - if (power < 0) { - m = matinv(m); - power = -power; - } - /* - * Compute the power by squaring and multiplying. - * This uses the left to right method of power raising. - */ - bit = TOPFULL; - while ((bit & power) == 0) - bit >>= 1L; - bit >>= 1L; - res = matsquare(m); - if (bit & power) { - tmp = matmul(res, m); - matfree(res); - res = tmp; - } - bit >>= 1L; - while (bit) { - tmp = matsquare(res); - matfree(res); - res = tmp; - if (bit & power) { - tmp = matmul(res, m); - matfree(res); - res = tmp; - } - bit >>= 1L; - } - if (qisneg(q)) - matfree(m); - return res; + if (m->m_dim > 2) { + math_error("Matrix dimension greater than 2 for power"); + not_reached(); + } + if (m->m_dim == 2 && (m->m_max[0] - m->m_min[0] != + m->m_max[1] - m->m_min[1])) { + math_error("Raising non-square 2D matrix to a power"); + not_reached(); + } + if (qisfrac(q)) { + math_error("Raising matrix to non-integral power"); + not_reached(); + } + if (zge31b(q->num)) { + math_error("Raising matrix to very large power"); + not_reached(); + } + power = ztolong(q->num); + if (qisneg(q)) + power = -power; + /* + * Handle some low powers specially + */ + if ((power <= 4) && (power >= -2)) { + switch ((int) power) { + case 0: + return matident(m); + case 1: + return matcopy(m); + case -1: + return matinv(m); + case 2: + return matsquare(m); + case -2: + tmp = matinv(m); + res = matsquare(tmp); + matfree(tmp); + return res; + case 3: + tmp = matsquare(m); + res = matmul(m, tmp); + matfree(tmp); + return res; + case 4: + tmp = matsquare(m); + res = matsquare(tmp); + matfree(tmp); + return res; + } + } + if (power < 0) { + m = matinv(m); + power = -power; + } + /* + * Compute the power by squaring and multiplying. + * This uses the left to right method of power raising. + */ + bit = TOPFULL; + while ((bit & power) == 0) + bit >>= 1L; + bit >>= 1L; + res = matsquare(m); + if (bit & power) { + tmp = matmul(res, m); + matfree(res); + res = tmp; + } + bit >>= 1L; + while (bit) { + tmp = matsquare(res); + matfree(res); + res = tmp; + if (bit & power) { + tmp = matmul(res, m); + matfree(res); + res = tmp; + } + bit >>= 1L; + } + if (qisneg(q)) + matfree(m); + return res; } /* * Calculate the cross product of two one dimensional matrices each * with three components. - * m3 = matcross(m1, m2); + * m3 = matcross(m1, m2); */ MATRIX * matcross(MATRIX *m1, MATRIX *m2) { - MATRIX *res; - VALUE *v1, *v2, *vr; - VALUE tmp1, tmp2; + MATRIX *res; + VALUE *v1, *v2, *vr; + VALUE tmp1, tmp2; - res = matalloc(3L); - res->m_dim = 1; - res->m_min[0] = 0; - res->m_max[0] = 2; - v1 = m1->m_table; - v2 = m2->m_table; - vr = res->m_table; - mulvalue(v1 + 1, v2 + 2, &tmp1); - mulvalue(v1 + 2, v2 + 1, &tmp2); - subvalue(&tmp1, &tmp2, vr + 0); - freevalue(&tmp1); - freevalue(&tmp2); - mulvalue(v1 + 2, v2 + 0, &tmp1); - mulvalue(v1 + 0, v2 + 2, &tmp2); - subvalue(&tmp1, &tmp2, vr + 1); - freevalue(&tmp1); - freevalue(&tmp2); - mulvalue(v1 + 0, v2 + 1, &tmp1); - mulvalue(v1 + 1, v2 + 0, &tmp2); - subvalue(&tmp1, &tmp2, vr + 2); - freevalue(&tmp1); - freevalue(&tmp2); - return res; + res = matalloc(3L); + res->m_dim = 1; + res->m_min[0] = 0; + res->m_max[0] = 2; + v1 = m1->m_table; + v2 = m2->m_table; + vr = res->m_table; + mulvalue(v1 + 1, v2 + 2, &tmp1); + mulvalue(v1 + 2, v2 + 1, &tmp2); + subvalue(&tmp1, &tmp2, vr + 0); + freevalue(&tmp1); + freevalue(&tmp2); + mulvalue(v1 + 2, v2 + 0, &tmp1); + mulvalue(v1 + 0, v2 + 2, &tmp2); + subvalue(&tmp1, &tmp2, vr + 1); + freevalue(&tmp1); + freevalue(&tmp2); + mulvalue(v1 + 0, v2 + 1, &tmp1); + mulvalue(v1 + 1, v2 + 0, &tmp2); + subvalue(&tmp1, &tmp2, vr + 2); + freevalue(&tmp1); + freevalue(&tmp2); + return res; } /* * Return the dot product of two matrices. - * result = matdot(m1, m2); + * result = matdot(m1, m2); */ VALUE matdot(MATRIX *m1, MATRIX *m2) { - VALUE *v1, *v2; - VALUE result, tmp1, tmp2; - long len; + VALUE *v1, *v2; + VALUE result, tmp1, tmp2; + long len; - v1 = m1->m_table; - v2 = m2->m_table; - mulvalue(v1, v2, &result); - len = m1->m_size; - while (--len > 0) { - mulvalue(++v1, ++v2, &tmp1); - addvalue(&result, &tmp1, &tmp2); - freevalue(&tmp1); - freevalue(&result); - result = tmp2; - } - return result; + v1 = m1->m_table; + v2 = m2->m_table; + mulvalue(v1, v2, &result); + len = m1->m_size; + while (--len > 0) { + mulvalue(++v1, ++v2, &tmp1); + addvalue(&result, &tmp1, &tmp2); + freevalue(&tmp1); + freevalue(&result); + result = tmp2; + } + return result; } @@ -509,30 +509,30 @@ matdot(MATRIX *m1, MATRIX *m2) * Scale the elements of a matrix by a specified power of two. * * given: - * m matrix to be scaled - * n scale factor + * m matrix to be scaled + * n scale factor */ MATRIX * matscale(MATRIX *m, long n) { - register VALUE *val, *vres; - VALUE temp; - long index; - MATRIX *res; /* resulting matrix */ + register VALUE *val, *vres; + VALUE temp; + long index; + MATRIX *res; /* resulting matrix */ - if (n == 0) - return matcopy(m); - temp.v_type = V_NUM; - temp.v_subtype = V_NOSUBTYPE; - temp.v_num = itoq(n); - res = matalloc(m->m_size); - *res = *m; - val = m->m_table; - vres = res->m_table; - for (index = m->m_size; index > 0; index--) - scalevalue(val++, &temp, vres++); - qfree(temp.v_num); - return res; + if (n == 0) + return matcopy(m); + temp.v_type = V_NUM; + temp.v_subtype = V_NOSUBTYPE; + temp.v_num = itoq(n); + res = matalloc(m->m_size); + *res = *m; + val = m->m_table; + vres = res->m_table; + for (index = m->m_size; index > 0; index--) + scalevalue(val++, &temp, vres++); + qfree(temp.v_num); + return res; } @@ -541,30 +541,30 @@ matscale(MATRIX *m, long n) * Positive shift means leftwards, negative shift rightwards. * * given: - * m matrix to be shifted - * n shift count + * m matrix to be shifted + * n shift count */ MATRIX * matshift(MATRIX *m, long n) { - register VALUE *val, *vres; - VALUE temp; - long index; - MATRIX *res; /* resulting matrix */ + register VALUE *val, *vres; + VALUE temp; + long index; + MATRIX *res; /* resulting matrix */ - if (n == 0) - return matcopy(m); - temp.v_type = V_NUM; - temp.v_subtype = V_NOSUBTYPE; - temp.v_num = itoq(n); - res = matalloc(m->m_size); - *res = *m; - val = m->m_table; - vres = res->m_table; - for (index = m->m_size; index > 0; index--) - shiftvalue(val++, &temp, false, vres++); - qfree(temp.v_num); - return res; + if (n == 0) + return matcopy(m); + temp.v_type = V_NUM; + temp.v_subtype = V_NOSUBTYPE; + temp.v_num = itoq(n); + res = matalloc(m->m_size); + *res = *m; + val = m->m_table; + vres = res->m_table; + for (index = m->m_size; index > 0; index--) + shiftvalue(val++, &temp, false, vres++); + qfree(temp.v_num); + return res; } @@ -572,23 +572,23 @@ matshift(MATRIX *m, long n) * Multiply the elements of a matrix by a specified value. * * given: - * m matrix to be multiplied - * vp value to multiply by + * m matrix to be multiplied + * vp value to multiply by */ MATRIX * matmulval(MATRIX *m, VALUE *vp) { - register VALUE *val, *vres; - long index; - MATRIX *res; + register VALUE *val, *vres; + long index; + MATRIX *res; - res = matalloc(m->m_size); - *res = *m; - val = m->m_table; - vres = res->m_table; - for (index = m->m_size; index > 0; index--) - mulvalue(val++, vp, vres++); - return res; + res = matalloc(m->m_size); + *res = *m; + val = m->m_table; + vres = res->m_table; + for (index = m->m_size; index > 0; index--) + mulvalue(val++, vp, vres++); + return res; } @@ -597,28 +597,28 @@ matmulval(MATRIX *m, VALUE *vp) * only the integer quotient. * * given: - * m matrix to be divided - * vp value to divide by - * v3 rounding type parameter + * m matrix to be divided + * vp value to divide by + * v3 rounding type parameter */ MATRIX * matquoval(MATRIX *m, VALUE *vp, VALUE *v3) { - register VALUE *val, *vres; - long index; - MATRIX *res; + register VALUE *val, *vres; + long index; + MATRIX *res; - if ((vp->v_type == V_NUM) && qiszero(vp->v_num)) { - math_error("Division by zero"); - not_reached(); - } - res = matalloc(m->m_size); - *res = *m; - val = m->m_table; - vres = res->m_table; - for (index = m->m_size; index > 0; index--) - quovalue(val++, vp, v3, vres++); - return res; + if ((vp->v_type == V_NUM) && qiszero(vp->v_num)) { + math_error("Division by zero"); + not_reached(); + } + res = matalloc(m->m_size); + *res = *m; + val = m->m_table; + vres = res->m_table; + for (index = m->m_size; index > 0; index--) + quovalue(val++, vp, v3, vres++); + return res; } @@ -627,59 +627,59 @@ matquoval(MATRIX *m, VALUE *vp, VALUE *v3) * only the remainder of the division. * * given: - * m matrix to be divided - * vp value to divide by - * v3 rounding type parameter + * m matrix to be divided + * vp value to divide by + * v3 rounding type parameter */ MATRIX * matmodval(MATRIX *m, VALUE *vp, VALUE *v3) { - register VALUE *val, *vres; - long index; - MATRIX *res; + register VALUE *val, *vres; + long index; + MATRIX *res; - if ((vp->v_type == V_NUM) && qiszero(vp->v_num)) { - math_error("Division by zero"); - not_reached(); - } - res = matalloc(m->m_size); - *res = *m; - val = m->m_table; - vres = res->m_table; - for (index = m->m_size; index > 0; index--) - modvalue(val++, vp, v3, vres++); - return res; + if ((vp->v_type == V_NUM) && qiszero(vp->v_num)) { + math_error("Division by zero"); + not_reached(); + } + res = matalloc(m->m_size); + *res = *m; + val = m->m_table; + vres = res->m_table; + for (index = m->m_size; index > 0; index--) + modvalue(val++, vp, v3, vres++); + return res; } VALUE mattrace(MATRIX *m) { - VALUE *vp; - VALUE sum; - VALUE tmp; - long i, j; + VALUE *vp; + VALUE sum; + VALUE tmp; + long i, j; - if (m->m_dim < 2) { - matsum(m, &sum); - return sum; - } - if (m->m_dim != 2) - return error_value(E_MATTRACE_2); - i = (m->m_max[0] - m->m_min[0] + 1); - j = (m->m_max[1] - m->m_min[1] + 1); - if (i != j) - return error_value(E_MATTRACE_3); - vp = m->m_table; - copyvalue(vp, &sum); - j++; - while (--i > 0) { - vp += j; - addvalue(&sum, vp, &tmp); - freevalue(&sum); - sum = tmp; - } - return sum; + if (m->m_dim < 2) { + matsum(m, &sum); + return sum; + } + if (m->m_dim != 2) + return error_value(E_MATTRACE_2); + i = (m->m_max[0] - m->m_min[0] + 1); + j = (m->m_max[1] - m->m_min[1] + 1); + if (i != j) + return error_value(E_MATTRACE_3); + vp = m->m_table; + copyvalue(vp, &sum); + j++; + while (--i > 0) { + vp += j; + addvalue(&sum, vp, &tmp); + freevalue(&sum); + sum = tmp; + } + return sum; } @@ -689,31 +689,31 @@ mattrace(MATRIX *m) MATRIX * mattrans(MATRIX *m) { - register VALUE *v1, *v2; /* current values */ - long rows, cols; /* rows and columns in new matrix */ - long row, col; /* current row and column */ - MATRIX *res; + register VALUE *v1, *v2; /* current values */ + long rows, cols; /* rows and columns in new matrix */ + long row, col; /* current row and column */ + MATRIX *res; - if (m->m_dim < 2) - return matcopy(m); - res = matalloc(m->m_size); - res->m_dim = 2; - res->m_min[0] = m->m_min[1]; - res->m_max[0] = m->m_max[1]; - res->m_min[1] = m->m_min[0]; - res->m_max[1] = m->m_max[0]; - rows = (m->m_max[1] - m->m_min[1] + 1); - cols = (m->m_max[0] - m->m_min[0] + 1); - v1 = res->m_table; - for (row = 0; row < rows; row++) { - v2 = &m->m_table[row]; - for (col = 0; col < cols; col++) { - copyvalue(v2, v1); - v1++; - v2 += rows; - } - } - return res; + if (m->m_dim < 2) + return matcopy(m); + res = matalloc(m->m_size); + res->m_dim = 2; + res->m_min[0] = m->m_min[1]; + res->m_max[0] = m->m_max[1]; + res->m_min[1] = m->m_min[0]; + res->m_max[1] = m->m_max[0]; + rows = (m->m_max[1] - m->m_min[1] + 1); + cols = (m->m_max[0] - m->m_min[0] + 1); + v1 = res->m_table; + for (row = 0; row < rows; row++) { + v2 = &m->m_table[row]; + for (col = 0; col < cols; col++) { + copyvalue(v2, v1); + v1++; + v2 += rows; + } + } + return res; } @@ -723,17 +723,17 @@ mattrans(MATRIX *m) MATRIX * matconj(MATRIX *m) { - register VALUE *val, *vres; - long index; - MATRIX *res; + register VALUE *val, *vres; + long index; + MATRIX *res; - res = matalloc(m->m_size); - *res = *m; - val = m->m_table; - vres = res->m_table; - for (index = m->m_size; index > 0; index--) - conjvalue(val++, vres++); - return res; + res = matalloc(m->m_size); + *res = *m; + val = m->m_table; + vres = res->m_table; + for (index = m->m_size; index > 0; index--) + conjvalue(val++, vres++); + return res; } @@ -743,18 +743,18 @@ matconj(MATRIX *m) MATRIX * matround(MATRIX *m, VALUE *v2, VALUE *v3) { - VALUE *p, *q; - long s; - MATRIX *res; + VALUE *p, *q; + long s; + MATRIX *res; - s = m->m_size; - res = matalloc(s); - *res = *m; - p = m->m_table; - q = res->m_table; - while (s-- > 0) - roundvalue(p++, v2, v3, q++); - return res; + s = m->m_size; + res = matalloc(s); + *res = *m; + p = m->m_table; + q = res->m_table; + while (s-- > 0) + roundvalue(p++, v2, v3, q++); + return res; } @@ -764,18 +764,18 @@ matround(MATRIX *m, VALUE *v2, VALUE *v3) MATRIX * matbround(MATRIX *m, VALUE *v2, VALUE *v3) { - VALUE *p, *q; - long s; - MATRIX *res; + VALUE *p, *q; + long s; + MATRIX *res; - s = m->m_size; - res = matalloc(s); - *res = *m; - p = m->m_table; - q = res->m_table; - while (s-- > 0) - broundvalue(p++, v2, v3, q++); - return res; + s = m->m_size; + res = matalloc(s); + *res = *m; + p = m->m_table; + q = res->m_table; + while (s-- > 0) + broundvalue(p++, v2, v3, q++); + return res; } /* @@ -785,18 +785,18 @@ matbround(MATRIX *m, VALUE *v2, VALUE *v3) MATRIX * matappr(MATRIX *m, VALUE *v2, VALUE *v3) { - VALUE *p, *q; - long s; - MATRIX *res; + VALUE *p, *q; + long s; + MATRIX *res; - s = m->m_size; - res = matalloc(s); - *res = *m; - p = m->m_table; - q = res->m_table; - while (s-- > 0) - apprvalue(p++, v2, v3, q++); - return res; + s = m->m_size; + res = matalloc(s); + *res = *m; + p = m->m_table; + q = res->m_table; + while (s-- > 0) + apprvalue(p++, v2, v3, q++); + return res; } @@ -808,17 +808,17 @@ matappr(MATRIX *m, VALUE *v2, VALUE *v3) MATRIX * matint(MATRIX *m) { - register VALUE *val, *vres; - long index; - MATRIX *res; + register VALUE *val, *vres; + long index; + MATRIX *res; - res = matalloc(m->m_size); - *res = *m; - val = m->m_table; - vres = res->m_table; - for (index = m->m_size; index > 0; index--) - intvalue(val++, vres++); - return res; + res = matalloc(m->m_size); + *res = *m; + val = m->m_table; + vres = res->m_table; + for (index = m->m_size; index > 0; index--) + intvalue(val++, vres++); + return res; } @@ -828,17 +828,17 @@ matint(MATRIX *m) MATRIX * matfrac(MATRIX *m) { - register VALUE *val, *vres; - long index; - MATRIX *res; + register VALUE *val, *vres; + long index; + MATRIX *res; - res = matalloc(m->m_size); - *res = *m; - val = m->m_table; - vres = res->m_table; - for (index = m->m_size; index > 0; index--) - fracvalue(val++, vres++); - return res; + res = matalloc(m->m_size); + *res = *m; + val = m->m_table; + vres = res->m_table; + for (index = m->m_size; index > 0; index--) + fracvalue(val++, vres++); + return res; } @@ -849,64 +849,64 @@ matfrac(MATRIX *m) * if the element is to be written, but this is ignored here. * * given: - * mp matrix to operate on - * create true => create if element does not exist - * dim dimension of the indexing - * indices table of values being indexed by + * mp matrix to operate on + * create true => create if element does not exist + * dim dimension of the indexing + * indices table of values being indexed by */ /*ARGSUSED*/ VALUE * matindex(MATRIX *mp, bool UNUSED(create), long dim, VALUE *indices) { - NUMBER *q; /* index value */ - VALUE *vp; - long index; /* index value as an integer */ - long offset; /* current offset into array */ - int i; /* loop counter */ + NUMBER *q; /* index value */ + VALUE *vp; + long index; /* index value as an integer */ + long offset; /* current offset into array */ + int i; /* loop counter */ - if (dim < 0) { - math_error("Negative dimension %ld for matrix", dim); - not_reached(); - } - for (;;) { - if (dim < mp->m_dim) { - math_error( - "Indexing a %ldd matrix as a %ldd matrix", - mp->m_dim, dim); - not_reached(); - } - offset = 0; - for (i = 0; i < mp->m_dim; i++) { - if (indices->v_type != V_NUM) { - math_error("Non-numeric index for matrix"); - not_reached(); - } - q = indices->v_num; - if (qisfrac(q)) { - math_error("Non-integral index for matrix"); - not_reached(); - } - index = qtoi(q); - if (zge31b(q->num) || (index < mp->m_min[i]) || - (index > mp->m_max[i])) { - math_error("Index out of bounds for matrix"); - not_reached(); - } - offset *= (mp->m_max[i] - mp->m_min[i] + 1); - offset += (index - mp->m_min[i]); - indices++; - } - vp = mp->m_table + offset; - dim -= mp->m_dim; - if (dim == 0) - break; - if (vp->v_type != V_MAT) { - math_error("Non-matrix argument for matindex"); - not_reached(); - } - mp = vp->v_mat; - } - return vp; + if (dim < 0) { + math_error("Negative dimension %ld for matrix", dim); + not_reached(); + } + for (;;) { + if (dim < mp->m_dim) { + math_error( + "Indexing a %ldd matrix as a %ldd matrix", + mp->m_dim, dim); + not_reached(); + } + offset = 0; + for (i = 0; i < mp->m_dim; i++) { + if (indices->v_type != V_NUM) { + math_error("Non-numeric index for matrix"); + not_reached(); + } + q = indices->v_num; + if (qisfrac(q)) { + math_error("Non-integral index for matrix"); + not_reached(); + } + index = qtoi(q); + if (zge31b(q->num) || (index < mp->m_min[i]) || + (index > mp->m_max[i])) { + math_error("Index out of bounds for matrix"); + not_reached(); + } + offset *= (mp->m_max[i] - mp->m_min[i] + 1); + offset += (index - mp->m_min[i]); + indices++; + } + vp = mp->m_table + offset; + dim -= mp->m_dim; + if (dim == 0) + break; + if (vp->v_type != V_MAT) { + math_error("Non-matrix argument for matindex"); + not_reached(); + } + mp = vp->v_mat; + } + return vp; } @@ -917,27 +917,27 @@ matindex(MATRIX *mp, bool UNUSED(create), long dim, VALUE *indices) LIST * matindices(MATRIX *mp, long index) { - LIST *lp; - int j; - long d; - VALUE val; + LIST *lp; + int j; + long d; + VALUE val; - if (index < 0 || index >= mp->m_size) - return NULL; + if (index < 0 || index >= mp->m_size) + return NULL; - lp = listalloc(); - val.v_type = V_NUM; - val.v_subtype = V_NOSUBTYPE; - j = mp->m_dim; + lp = listalloc(); + val.v_type = V_NUM; + val.v_subtype = V_NOSUBTYPE; + j = mp->m_dim; - while (--j >= 0) { - d = mp->m_max[j] - mp->m_min[j] + 1; - val.v_num = itoq(index % d + mp->m_min[j]); - insertlistfirst(lp, &val); - qfree(val.v_num); - index /= d; - } - return lp; + while (--j >= 0) { + d = mp->m_max[j] - mp->m_min[j] + 1; + val.v_num = itoq(index % d + mp->m_min[j]); + insertlistfirst(lp, &val); + qfree(val.v_num); + index /= d; + } + return lp; } @@ -948,21 +948,21 @@ matindices(MATRIX *mp, long index) int matsearch(MATRIX *m, VALUE *vp, long i, long j, ZVALUE *index) { - register VALUE *val; + register VALUE *val; - val = &m->m_table[i]; - if (i < 0 || j > m->m_size) { - math_error("This should not happen in call to matsearch"); - not_reached(); - } - while (i < j) { - if (acceptvalue(val++, vp)) { - utoz(i, index); - return 0; - } - i++; - } - return 1; + val = &m->m_table[i]; + if (i < 0 || j > m->m_size) { + math_error("This should not happen in call to matsearch"); + not_reached(); + } + while (i < j) { + if (acceptvalue(val++, vp)) { + utoz(i, index); + return 0; + } + i++; + } + return 1; } @@ -974,21 +974,21 @@ matsearch(MATRIX *m, VALUE *vp, long i, long j, ZVALUE *index) int matrsearch(MATRIX *m, VALUE *vp, long i, long j, ZVALUE *index) { - register VALUE *val; + register VALUE *val; - if (i < 0 || j > m->m_size) { - math_error("This should not happen in call to matrsearch"); - not_reached(); - } - val = &m->m_table[--j]; - while (j >= i) { - if (acceptvalue(val--, vp)) { - utoz(j, index); - return 0; - } - j--; - } - return 1; + if (i < 0 || j > m->m_size) { + math_error("This should not happen in call to matrsearch"); + not_reached(); + } + val = &m->m_table[--j]; + while (j >= i) { + if (acceptvalue(val--, vp)) { + utoz(j, index); + return 0; + } + j--; + } + return 1; } /* @@ -999,45 +999,45 @@ matrsearch(MATRIX *m, VALUE *vp, long i, long j, ZVALUE *index) * affects the supplied matrix directly, and doesn't return a copy. * * given: - * m matrix to be filled - * v1 value to fill most of matrix with - * v2 value for diagonal entries or null + * m matrix to be filled + * v1 value to fill most of matrix with + * v2 value for diagonal entries or null */ void matfill(MATRIX *m, VALUE *v1, VALUE *v2) { - register VALUE *val; - VALUE temp1, temp2; - long rows, cols; - long i, j; + register VALUE *val; + VALUE temp1, temp2; + long rows, cols; + long i, j; - copyvalue(v1, &temp1); + copyvalue(v1, &temp1); - val = m->m_table; - if (m->m_dim != 2 || v2 == NULL) { - for (i = m->m_size; i > 0; i--) { - freevalue(val); - copyvalue(&temp1, val++); - } - freevalue(&temp1); - return; - } + val = m->m_table; + if (m->m_dim != 2 || v2 == NULL) { + for (i = m->m_size; i > 0; i--) { + freevalue(val); + copyvalue(&temp1, val++); + } + freevalue(&temp1); + return; + } - copyvalue(v2, &temp2); - rows = m->m_max[0] - m->m_min[0] + 1; - cols = m->m_max[1] - m->m_min[1] + 1; + copyvalue(v2, &temp2); + rows = m->m_max[0] - m->m_min[0] + 1; + cols = m->m_max[1] - m->m_min[1] + 1; - for (i = 0; i < rows; i++) { - for (j = 0; j < cols; j++) { - freevalue(val); - if (i == j) - copyvalue(&temp2, val++); - else - copyvalue(&temp1, val++); - } - } - freevalue(&temp1); - freevalue(&temp2); + for (i = 0; i < rows; i++) { + for (j = 0; j < cols; j++) { + freevalue(val); + if (i == j) + copyvalue(&temp2, val++); + else + copyvalue(&temp1, val++); + } + } + freevalue(&temp1); + freevalue(&temp2); } @@ -1048,34 +1048,34 @@ matfill(MATRIX *m, VALUE *v1, VALUE *v2) S_FUNC MATRIX * matident(MATRIX *m) { - register VALUE *val; /* current value */ - long row, col; /* current row and column */ - long rows; /* number of rows */ - MATRIX *res; /* resulting matrix */ + register VALUE *val; /* current value */ + long row, col; /* current row and column */ + long rows; /* number of rows */ + MATRIX *res; /* resulting matrix */ - if (m->m_dim != 2) { - math_error( - "Matrix dimension must be two for setting to identity"); - not_reached(); - } - if ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1])) { - math_error("Matrix must be square for setting to identity"); - not_reached(); - } - res = matalloc(m->m_size); - *res = *m; - val = res->m_table; - rows = (res->m_max[0] - res->m_min[0] + 1); - for (row = 0; row < rows; row++) { - for (col = 0; col < rows; col++) { - val->v_type = V_NUM; - val->v_subtype = V_NOSUBTYPE; - val->v_num = ((row == col) ? qlink(&_qone_) : - qlink(&_qzero_)); - val++; - } - } - return res; + if (m->m_dim != 2) { + math_error( + "Matrix dimension must be two for setting to identity"); + not_reached(); + } + if ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1])) { + math_error("Matrix must be square for setting to identity"); + not_reached(); + } + res = matalloc(m->m_size); + *res = *m; + val = res->m_table; + rows = (res->m_max[0] - res->m_min[0] + 1); + for (row = 0; row < rows; row++) { + for (col = 0; col < rows; col++) { + val->v_type = V_NUM; + val->v_subtype = V_NOSUBTYPE; + val->v_num = ((row == col) ? qlink(&_qone_) : + qlink(&_qzero_)); + val++; + } + } + return res; } @@ -1088,119 +1088,119 @@ matident(MATRIX *m) MATRIX * matinv(MATRIX *m) { - MATRIX *res; /* matrix to become the inverse */ - long rows; /* number of rows */ - long cur; /* current row being worked on */ - long row, col; /* temp row and column values */ - VALUE *val; /* current value in matrix*/ - VALUE *vres; /* current value in result for dim < 2 */ - VALUE mulval; /* value to multiply rows by */ - VALUE tmpval; /* temporary value */ + MATRIX *res; /* matrix to become the inverse */ + long rows; /* number of rows */ + long cur; /* current row being worked on */ + long row, col; /* temp row and column values */ + VALUE *val; /* current value in matrix*/ + VALUE *vres; /* current value in result for dim < 2 */ + VALUE mulval; /* value to multiply rows by */ + VALUE tmpval; /* temporary value */ - if (m->m_dim < 2) { - res = matalloc(m->m_size); - *res = *m; - val = m->m_table; - vres = res->m_table; - for (cur = m->m_size; cur > 0; cur--) - invertvalue(val++, vres++); - return res; - } - if (m->m_dim != 2) { - math_error("Matrix dimension exceeds two for inverse"); - not_reached(); - } - if ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1])) { - math_error("Inverting non-square matrix"); - not_reached(); - } - /* - * Begin by creating the identity matrix with the same attributes. - */ - res = matalloc(m->m_size); - *res = *m; - rows = (m->m_max[0] - m->m_min[0] + 1); - val = res->m_table; - for (row = 0; row < rows; row++) { - for (col = 0; col < rows; col++) { - if (row == col) - val->v_num = qlink(&_qone_); - else - val->v_num = qlink(&_qzero_); - val->v_type = V_NUM; - val->v_subtype = V_NOSUBTYPE; - val++; - } - } - /* - * Now loop over each row, and eliminate all entries in the - * corresponding column by using row operations. Do the same - * operations on the resulting matrix. Copy the original matrix - * so that we don't destroy it. - */ - m = matcopy(m); - for (cur = 0; cur < rows; cur++) { - /* - * Find the first nonzero value in the rest of the column - * downwards from [cur,cur]. If there is no such value, then - * the matrix is not invertible. If the first nonzero entry - * is not the current row, then swap the two rows to make the - * current one nonzero. - */ - row = cur; - val = &m->m_table[(row * rows) + row]; - while (testvalue(val) == 0) { - if (++row >= rows) { - matfree(m); - matfree(res); - math_error("Matrix is not invertible"); - not_reached(); - } - val += rows; - } - invertvalue(val, &mulval); - if (row != cur) { - matswaprow(m, row, cur); - matswaprow(res, row, cur); - } - /* - * Now for every other nonzero entry in the current column, - * subtract the appropriate multiple of the current row to - * force that entry to become zero. - */ - val = &m->m_table[cur]; - for (row = 0; row < rows; row++) { - if ((row == cur) || (testvalue(val) == 0)) { - if (row+1 < rows) - val += rows; - continue; - } - mulvalue(val, &mulval, &tmpval); - matsubrow(m, row, cur, &tmpval); - matsubrow(res, row, cur, &tmpval); - freevalue(&tmpval); - if (row+1 < rows) - val += rows; - } - freevalue(&mulval); - } - /* - * Now the original matrix has nonzero entries only on its main - * diagonal. Scale the rows of the result matrix by the inverse - * of those entries. - */ - val = m->m_table; - for (row = 0; row < rows; row++) { - if ((val->v_type != V_NUM) || !qisone(val->v_num)) { - invertvalue(val, &mulval); - matmulrow(res, row, &mulval); - freevalue(&mulval); - } - if (row+1 < rows) - val += (rows + 1); - } - matfree(m); - return res; + if (m->m_dim < 2) { + res = matalloc(m->m_size); + *res = *m; + val = m->m_table; + vres = res->m_table; + for (cur = m->m_size; cur > 0; cur--) + invertvalue(val++, vres++); + return res; + } + if (m->m_dim != 2) { + math_error("Matrix dimension exceeds two for inverse"); + not_reached(); + } + if ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1])) { + math_error("Inverting non-square matrix"); + not_reached(); + } + /* + * Begin by creating the identity matrix with the same attributes. + */ + res = matalloc(m->m_size); + *res = *m; + rows = (m->m_max[0] - m->m_min[0] + 1); + val = res->m_table; + for (row = 0; row < rows; row++) { + for (col = 0; col < rows; col++) { + if (row == col) + val->v_num = qlink(&_qone_); + else + val->v_num = qlink(&_qzero_); + val->v_type = V_NUM; + val->v_subtype = V_NOSUBTYPE; + val++; + } + } + /* + * Now loop over each row, and eliminate all entries in the + * corresponding column by using row operations. Do the same + * operations on the resulting matrix. Copy the original matrix + * so that we don't destroy it. + */ + m = matcopy(m); + for (cur = 0; cur < rows; cur++) { + /* + * Find the first nonzero value in the rest of the column + * downwards from [cur,cur]. If there is no such value, then + * the matrix is not invertible. If the first nonzero entry + * is not the current row, then swap the two rows to make the + * current one nonzero. + */ + row = cur; + val = &m->m_table[(row * rows) + row]; + while (testvalue(val) == 0) { + if (++row >= rows) { + matfree(m); + matfree(res); + math_error("Matrix is not invertible"); + not_reached(); + } + val += rows; + } + invertvalue(val, &mulval); + if (row != cur) { + matswaprow(m, row, cur); + matswaprow(res, row, cur); + } + /* + * Now for every other nonzero entry in the current column, + * subtract the appropriate multiple of the current row to + * force that entry to become zero. + */ + val = &m->m_table[cur]; + for (row = 0; row < rows; row++) { + if ((row == cur) || (testvalue(val) == 0)) { + if (row+1 < rows) + val += rows; + continue; + } + mulvalue(val, &mulval, &tmpval); + matsubrow(m, row, cur, &tmpval); + matsubrow(res, row, cur, &tmpval); + freevalue(&tmpval); + if (row+1 < rows) + val += rows; + } + freevalue(&mulval); + } + /* + * Now the original matrix has nonzero entries only on its main + * diagonal. Scale the rows of the result matrix by the inverse + * of those entries. + */ + val = m->m_table; + for (row = 0; row < rows; row++) { + if ((val->v_type != V_NUM) || !qisone(val->v_num)) { + invertvalue(val, &mulval); + matmulrow(res, row, &mulval); + freevalue(&mulval); + } + if (row+1 < rows) + val += (rows + 1); + } + matfree(m); + return res; } @@ -1211,110 +1211,110 @@ matinv(MATRIX *m) VALUE matdet(MATRIX *m) { - long n; /* original matrix is n x n */ - long k; /* working sub-matrix is k x k */ - long i, j; - VALUE *pivot, *div, *val; - VALUE *vp, *vv; - VALUE tmp1, tmp2, tmp3; - bool neg; /* whether to negate determinant */ + long n; /* original matrix is n x n */ + long k; /* working sub-matrix is k x k */ + long i, j; + VALUE *pivot, *div, *val; + VALUE *vp, *vv; + VALUE tmp1, tmp2, tmp3; + bool neg; /* whether to negate determinant */ - if (m->m_dim < 2) { - vp = m->m_table; - i = m->m_size; - copyvalue(vp, &tmp1); + if (m->m_dim < 2) { + vp = m->m_table; + i = m->m_size; + copyvalue(vp, &tmp1); - while (--i > 0) { - mulvalue(&tmp1, ++vp, &tmp2); - freevalue(&tmp1); - tmp1 = tmp2; - } - return tmp1; - } + while (--i > 0) { + mulvalue(&tmp1, ++vp, &tmp2); + freevalue(&tmp1); + tmp1 = tmp2; + } + return tmp1; + } - if (m->m_dim != 2) - return error_value(E_DET_2); - if ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1])) - return error_value(E_DET_3); + if (m->m_dim != 2) + return error_value(E_DET_2); + if ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1])) + return error_value(E_DET_3); - /* - * Loop over each row, and eliminate all lower entries in the - * corresponding column by using row operations. Copy the original - * matrix so that we don't destroy it. - */ - neg = false; - m = matcopy(m); - n = (m->m_max[0] - m->m_min[0] + 1); - pivot = div = m->m_table; - for (k = n; k > 0; k--) { - /* - * Find the first nonzero value in the rest of the column - * downwards from pivot. If there is no such value, then - * the determinant is zero. If the first nonzero entry is not - * the pivot, then swap rows in the k * k sub-matrix, and - * remember that the determinant changes sign. - */ - val = pivot; - i = k; - while (!testvalue(val)) { - if (--i <= 0) { - tmp1.v_type = V_NUM; - tmp1.v_subtype = V_NOSUBTYPE; - tmp1.v_num = qlink(&_qzero_); - matfree(m); - return tmp1; - } - val += n; - } - if (i < k) { - vp = pivot; - vv = val; - j = k; - while (j-- > 0) { - tmp1 = *vp; - *vp++ = *vv; - *vv++ = tmp1; - } - neg = !neg; - } - /* - * Now for every val below the pivot, for each entry to - * the right of val, calculate the 2 x 2 determinant - * with corners at the pivot and the entry. If - * k < n, divide by div (the previous pivot value). - */ - val = pivot; - i = k; - while (--i > 0) { - val += n; - vp = pivot; - vv = val; - j = k; - while (--j > 0) { - mulvalue(pivot, ++vv, &tmp1); - mulvalue(val, ++vp, &tmp2); - subvalue(&tmp1, &tmp2, &tmp3); - freevalue(&tmp1); - freevalue(&tmp2); - freevalue(vv); - if (k < n) { - divvalue(&tmp3, div, vv); - freevalue(&tmp3); - } - else - *vv = tmp3; - } - } - div = pivot; - if (k > 0) - pivot += n + 1; - } - if (neg) - negvalue(div, &tmp1); - else - copyvalue(div, &tmp1); - matfree(m); - return tmp1; + /* + * Loop over each row, and eliminate all lower entries in the + * corresponding column by using row operations. Copy the original + * matrix so that we don't destroy it. + */ + neg = false; + m = matcopy(m); + n = (m->m_max[0] - m->m_min[0] + 1); + pivot = div = m->m_table; + for (k = n; k > 0; k--) { + /* + * Find the first nonzero value in the rest of the column + * downwards from pivot. If there is no such value, then + * the determinant is zero. If the first nonzero entry is not + * the pivot, then swap rows in the k * k sub-matrix, and + * remember that the determinant changes sign. + */ + val = pivot; + i = k; + while (!testvalue(val)) { + if (--i <= 0) { + tmp1.v_type = V_NUM; + tmp1.v_subtype = V_NOSUBTYPE; + tmp1.v_num = qlink(&_qzero_); + matfree(m); + return tmp1; + } + val += n; + } + if (i < k) { + vp = pivot; + vv = val; + j = k; + while (j-- > 0) { + tmp1 = *vp; + *vp++ = *vv; + *vv++ = tmp1; + } + neg = !neg; + } + /* + * Now for every val below the pivot, for each entry to + * the right of val, calculate the 2 x 2 determinant + * with corners at the pivot and the entry. If + * k < n, divide by div (the previous pivot value). + */ + val = pivot; + i = k; + while (--i > 0) { + val += n; + vp = pivot; + vv = val; + j = k; + while (--j > 0) { + mulvalue(pivot, ++vv, &tmp1); + mulvalue(val, ++vp, &tmp2); + subvalue(&tmp1, &tmp2, &tmp3); + freevalue(&tmp1); + freevalue(&tmp2); + freevalue(vv); + if (k < n) { + divvalue(&tmp3, div, vv); + freevalue(&tmp3); + } + else + *vv = tmp3; + } + } + div = pivot; + if (k > 0) + pivot += n + 1; + } + if (neg) + negvalue(div, &tmp1); + else + copyvalue(div, &tmp1); + matfree(m); + return tmp1; } @@ -1325,22 +1325,22 @@ matdet(MATRIX *m) S_FUNC void matswaprow(MATRIX *m, long r1, long r2) { - register VALUE *v1, *v2; - register long rows; - VALUE tmp; + register VALUE *v1, *v2; + register long rows; + VALUE tmp; - if (r1 == r2) - return; - rows = (m->m_max[0] - m->m_min[0] + 1); - v1 = &m->m_table[r1 * rows]; - v2 = &m->m_table[r2 * rows]; - while (rows-- > 0) { - tmp = *v1; - *v1 = *v2; - *v2 = tmp; - v1++; - v2++; - } + if (r1 == r2) + return; + rows = (m->m_max[0] - m->m_min[0] + 1); + v1 = &m->m_table[r1 * rows]; + v2 = &m->m_table[r2 * rows]; + while (rows-- > 0) { + tmp = *v1; + *v1 = *v2; + *v2 = tmp; + v1++; + v2++; + } } @@ -1352,22 +1352,22 @@ matswaprow(MATRIX *m, long r1, long r2) S_FUNC void matsubrow(MATRIX *m, long oprow, long baserow, VALUE *mulval) { - register VALUE *vop, *vbase; - register long entries; - VALUE tmp1, tmp2; + register VALUE *vop, *vbase; + register long entries; + VALUE tmp1, tmp2; - entries = (m->m_max[0] - m->m_min[0] + 1); - vop = &m->m_table[oprow * entries]; - vbase = &m->m_table[baserow * entries]; - while (entries-- > 0) { - mulvalue(vbase, mulval, &tmp1); - subvalue(vop, &tmp1, &tmp2); - freevalue(&tmp1); - freevalue(vop); - *vop = tmp2; - vop++; - vbase++; - } + entries = (m->m_max[0] - m->m_min[0] + 1); + vop = &m->m_table[oprow * entries]; + vbase = &m->m_table[baserow * entries]; + while (entries-- > 0) { + mulvalue(vbase, mulval, &tmp1); + subvalue(vop, &tmp1, &tmp2); + freevalue(&tmp1); + freevalue(vop); + *vop = tmp2; + vop++; + vbase++; + } } @@ -1378,18 +1378,18 @@ matsubrow(MATRIX *m, long oprow, long baserow, VALUE *mulval) S_FUNC void matmulrow(MATRIX *m, long row, VALUE *mulval) { - register VALUE *val; - register long rows; - VALUE tmp; + register VALUE *val; + register long rows; + VALUE tmp; - rows = (m->m_max[0] - m->m_min[0] + 1); - val = &m->m_table[row * rows]; - while (rows-- > 0) { - mulvalue(val, mulval, &tmp); - freevalue(val); - *val = tmp; - val++; - } + rows = (m->m_max[0] - m->m_min[0] + 1); + val = &m->m_table[row * rows]; + while (rows-- > 0) { + mulvalue(val, mulval, &tmp); + freevalue(val); + *val = tmp; + val++; + } } @@ -1399,21 +1399,21 @@ matmulrow(MATRIX *m, long row, VALUE *mulval) MATRIX * matcopy(MATRIX *m) { - MATRIX *res; - register VALUE *v1, *v2; - register long i; + MATRIX *res; + register VALUE *v1, *v2; + register long i; - res = matalloc(m->m_size); - *res = *m; - v1 = m->m_table; - v2 = res->m_table; - i = m->m_size; - while (i-- > 0) { - copyvalue(v1, v2); - v1++; - v2++; - } - return res; + res = matalloc(m->m_size); + *res = *m; + v1 = m->m_table; + v2 = res->m_table; + i = m->m_size; + while (i-- > 0) { + copyvalue(v1, v2); + v1++; + v2++; + } + return res; } @@ -1421,57 +1421,57 @@ matcopy(MATRIX *m) * Make a matrix the same size as another and filled with a fixed value. * * given: - * m matrix to initialize - * v1 value to fill most of matrix with - * v2 value for diagonal entries (or NULL) + * m matrix to initialize + * v1 value to fill most of matrix with + * v2 value for diagonal entries (or NULL) */ MATRIX * matinit(MATRIX *m, VALUE *v1, VALUE *v2) { - MATRIX *res; - register VALUE *v; - register long i; - long row; - long rows; + MATRIX *res; + register VALUE *v; + register long i; + long row; + long rows; - /* - * clone matrix size - */ - res = matalloc(m->m_size); - *res = *m; + /* + * clone matrix size + */ + res = matalloc(m->m_size); + *res = *m; - /* - * firewall - */ - if (v2 && ((res->m_dim != 2) || - ((res->m_max[0] - res->m_min[0]) != - (res->m_max[1] - res->m_min[1])))) { - math_error("Filling diagonals of non-square matrix"); - not_reached(); - } + /* + * firewall + */ + if (v2 && ((res->m_dim != 2) || + ((res->m_max[0] - res->m_min[0]) != + (res->m_max[1] - res->m_min[1])))) { + math_error("Filling diagonals of non-square matrix"); + not_reached(); + } - /* - * fill the bulk of the matrix - */ - v = res->m_table; - if (v2 == NULL) { - i = m->m_size; - while (i-- > 0) { - copyvalue(v1, v++); - } - return res; - } + /* + * fill the bulk of the matrix + */ + v = res->m_table; + if (v2 == NULL) { + i = m->m_size; + while (i-- > 0) { + copyvalue(v1, v++); + } + return res; + } - /* - * fill the diagonal of a square matrix if requested - */ - rows = res->m_max[0] - res->m_min[0] + 1; - v = res->m_table; - for (row = 0; row < rows; row++) { - copyvalue(v2, v+row); - v += rows; - } - return res; + /* + * fill the diagonal of a square matrix if requested + */ + rows = res->m_max[0] - res->m_min[0] + 1; + v = res->m_table; + for (row = 0; row < rows; row++) { + copyvalue(v2, v+row); + v += rows; + } + return res; } @@ -1481,20 +1481,20 @@ matinit(MATRIX *m, VALUE *v1, VALUE *v2) MATRIX * matalloc(long size) { - MATRIX *m; - long i; - VALUE *vp; + MATRIX *m; + long i; + VALUE *vp; - m = (MATRIX *) malloc(matsize(size)); - if (m == NULL) { - math_error("Cannot get memory to allocate matrix of size %ld", - size); - not_reached(); - } - m->m_size = size; - for (i = size, vp = m->m_table; i > 0; i--, vp++) - vp->v_subtype = V_NOSUBTYPE; - return m; + m = (MATRIX *) malloc(matsize(size)); + if (m == NULL) { + math_error("Cannot get memory to allocate matrix of size %ld", + size); + not_reached(); + } + m->m_size = size; + for (i = size, vp = m->m_table; i > 0; i--, vp++) + vp->v_subtype = V_NOSUBTYPE; + return m; } @@ -1504,14 +1504,14 @@ matalloc(long size) void matfree(MATRIX *m) { - register VALUE *vp; - register long i; + register VALUE *vp; + register long i; - vp = m->m_table; - i = m->m_size; - while (i-- > 0) - freevalue(vp++); - free(m); + vp = m->m_table; + i = m->m_size; + while (i-- > 0) + freevalue(vp++); + free(m); } @@ -1522,16 +1522,16 @@ matfree(MATRIX *m) bool mattest(MATRIX *m) { - register VALUE *vp; - register long i; + register VALUE *vp; + register long i; - vp = m->m_table; - i = m->m_size; - while (i-- > 0) { - if (testvalue(vp++)) - return true; - } - return false; + vp = m->m_table; + i = m->m_size; + while (i-- > 0) { + if (testvalue(vp++)) + return true; + } + return false; } /* @@ -1540,21 +1540,21 @@ mattest(MATRIX *m) void matsum(MATRIX *m, VALUE *vres) { - VALUE *vp; - VALUE tmp; /* first sum value */ - VALUE sum; /* final sum value */ - long i; + VALUE *vp; + VALUE tmp; /* first sum value */ + VALUE sum; /* final sum value */ + long i; - vp = m->m_table; - i = m->m_size; - copyvalue(vp, &sum); + vp = m->m_table; + i = m->m_size; + copyvalue(vp, &sum); - while (--i > 0) { - addvalue(&sum, ++vp, &tmp); - freevalue(&sum); - sum = tmp; - } - *vres = sum; + while (--i > 0) { + addvalue(&sum, ++vp, &tmp); + freevalue(&sum); + sum = tmp; + } + *vres = sum; } @@ -1566,132 +1566,132 @@ matsum(MATRIX *m, VALUE *vres) bool matcmp(MATRIX *m1, MATRIX *m2) { - VALUE *v1, *v2; - long i; + VALUE *v1, *v2; + long i; - if (m1 == m2) - return false; - if ((m1->m_dim != m2->m_dim) || (m1->m_size != m2->m_size)) - return true; - for (i = 0; i < m1->m_dim; i++) { - if ((m1->m_max[i] - m1->m_min[i]) != - (m2->m_max[i] - m2->m_min[i])) - return true; - } - v1 = m1->m_table; - v2 = m2->m_table; - i = m1->m_size; - while (i-- > 0) { - if (comparevalue(v1++, v2++)) - return true; - } - return false; + if (m1 == m2) + return false; + if ((m1->m_dim != m2->m_dim) || (m1->m_size != m2->m_size)) + return true; + for (i = 0; i < m1->m_dim; i++) { + if ((m1->m_max[i] - m1->m_min[i]) != + (m2->m_max[i] - m2->m_min[i])) + return true; + } + v1 = m1->m_table; + v2 = m2->m_table; + i = m1->m_size; + while (i-- > 0) { + if (comparevalue(v1++, v2++)) + return true; + } + return false; } void matreverse(MATRIX *m) { - VALUE *p, *q; - VALUE tmp; + VALUE *p, *q; + VALUE tmp; - p = m->m_table; - q = m->m_table + m->m_size - 1; - while (q > p) { - tmp = *p; - *p++ = *q; - *q-- = tmp; - } + p = m->m_table; + q = m->m_table + m->m_size - 1; + while (q > p) { + tmp = *p; + *p++ = *q; + *q-- = tmp; + } } void matsort(MATRIX *m) { - VALUE *a, *b, *next, *end; - VALUE *buf, *p; - VALUE *S[LONG_BITS]; - long len[LONG_BITS]; - long i, j, k; + VALUE *a, *b, *next, *end; + VALUE *buf, *p; + VALUE *S[LONG_BITS]; + long len[LONG_BITS]; + long i, j, k; - buf = (VALUE *) malloc(m->m_size * sizeof(VALUE)); - if (buf == NULL) { - math_error("Not enough memory for matsort"); - not_reached(); - } - next = m->m_table; - end = next + m->m_size; - for (k = 0; next && k < LONG_BITS; k++) { - S[k] = next++; /* S[k] is start of a run */ - len[k] = 1; - if (next == end) - next = NULL; - while (k > 0 && (!next || len[k] >= len[k - 1])) {/* merging */ - j = len[k]; - b = S[k--]; - i = len[k]; - a = S[k]; - len[k] += j; - p = buf; - if (precvalue(b, a)) { - do { - *p++ = *b++; - j--; - } while (j > 0 && precvalue(b,a)); - if (j == 0) { - memcpy(p, a, i * sizeof(VALUE)); - memcpy(S[k], buf, - len[k] * sizeof(VALUE)); - continue; - } - } + buf = (VALUE *) malloc(m->m_size * sizeof(VALUE)); + if (buf == NULL) { + math_error("Not enough memory for matsort"); + not_reached(); + } + next = m->m_table; + end = next + m->m_size; + for (k = 0; next && k < LONG_BITS; k++) { + S[k] = next++; /* S[k] is start of a run */ + len[k] = 1; + if (next == end) + next = NULL; + while (k > 0 && (!next || len[k] >= len[k - 1])) {/* merging */ + j = len[k]; + b = S[k--]; + i = len[k]; + a = S[k]; + len[k] += j; + p = buf; + if (precvalue(b, a)) { + do { + *p++ = *b++; + j--; + } while (j > 0 && precvalue(b,a)); + if (j == 0) { + memcpy(p, a, i * sizeof(VALUE)); + memcpy(S[k], buf, + len[k] * sizeof(VALUE)); + continue; + } + } - do { - do { - *p++ = *a++; - i--; - } while (i > 0 && !precvalue(b,a)); - if (i == 0) { - break; - } - do { - *p++ = *b++; - j--; - } while (j > 0 && precvalue(b,a)); - } while (j != 0); + do { + do { + *p++ = *a++; + i--; + } while (i > 0 && !precvalue(b,a)); + if (i == 0) { + break; + } + do { + *p++ = *b++; + j--; + } while (j > 0 && precvalue(b,a)); + } while (j != 0); - if (i == 0) { - memcpy(S[k], buf, (p - buf) * sizeof(VALUE)); - } else if (j == 0) { - memcpy(p, a, i * sizeof(VALUE)); - memcpy(S[k], buf, len[k] * sizeof(VALUE)); - } - } - } - free(buf); - if (k >= LONG_BITS) { - /* this should never happen */ - math_error("impossible k overflow in matsort!"); - not_reached(); - } + if (i == 0) { + memcpy(S[k], buf, (p - buf) * sizeof(VALUE)); + } else if (j == 0) { + memcpy(p, a, i * sizeof(VALUE)); + memcpy(S[k], buf, len[k] * sizeof(VALUE)); + } + } + } + free(buf); + if (k >= LONG_BITS) { + /* this should never happen */ + math_error("impossible k overflow in matsort!"); + not_reached(); + } } void matrandperm(MATRIX *m) { - VALUE *vp; - long s, i; - VALUE val; + VALUE *vp; + long s, i; + VALUE val; - s = m->m_size; - for (vp = m->m_table; s > 1; vp++, s--) { - i = irand(s); - if (i > 0) { - val = *vp; - *vp = vp[i]; - vp[i] = val; - } - } + s = m->m_size; + for (vp = m->m_table; s > 1; vp++, s--) { + i = irand(s); + if (i > 0) { + val = *vp; + *vp = vp[i]; + vp[i] = val; + } + } } @@ -1702,44 +1702,44 @@ matrandperm(MATRIX *m) bool matisident(MATRIX *m) { - register VALUE *val; /* current value */ - long row, col; /* row and column numbers */ + register VALUE *val; /* current value */ + long row, col; /* row and column numbers */ - val = m->m_table; - if (m->m_dim == 0) { - return (val->v_type == V_NUM && qisone(val->v_num)); - } - if (m->m_dim == 1) { - for (row = m->m_min[0]; row <= m->m_max[0]; row++, val++) { - if (val->v_type != V_NUM || !qisone(val->v_num)) - return false; - } - return true; - } - if ((m->m_dim != 2) || - ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1]))) - return false; - for (row = m->m_min[0]; row <= m->m_max[0]; row++) { - /* - * We could use col = m->m_min[1]; col < m->m_max[1] - * but if m->m_min[0] != m->m_min[1] this won't work. - * We know that we have a square 2-dimensional matrix - * so we will pretend that m->m_min[0] == m->m_min[1]. - */ - for (col = m->m_min[0]; col <= m->m_max[0]; col++) { - if (val->v_type != V_NUM) - return false; - if (row == col) { - if (!qisone(val->v_num)) - return false; - } else { - if (!qiszero(val->v_num)) - return false; - } - val++; - } - } - return true; + val = m->m_table; + if (m->m_dim == 0) { + return (val->v_type == V_NUM && qisone(val->v_num)); + } + if (m->m_dim == 1) { + for (row = m->m_min[0]; row <= m->m_max[0]; row++, val++) { + if (val->v_type != V_NUM || !qisone(val->v_num)) + return false; + } + return true; + } + if ((m->m_dim != 2) || + ((m->m_max[0] - m->m_min[0]) != (m->m_max[1] - m->m_min[1]))) + return false; + for (row = m->m_min[0]; row <= m->m_max[0]; row++) { + /* + * We could use col = m->m_min[1]; col < m->m_max[1] + * but if m->m_min[0] != m->m_min[1] this won't work. + * We know that we have a square 2-dimensional matrix + * so we will pretend that m->m_min[0] == m->m_min[1]. + */ + for (col = m->m_min[0]; col <= m->m_max[0]; col++) { + if (val->v_type != V_NUM) + return false; + if (row == col) { + if (!qisone(val->v_num)) + return false; + } else { + if (!qiszero(val->v_num)) + return false; + } + val++; + } + } + return true; } @@ -1751,70 +1751,70 @@ matisident(MATRIX *m) void matprint(MATRIX *m, long max_print) { - VALUE *vp; - long fullsize, count, index; - long dim, i, j; - char *msg; - long sizes[MAXDIM]; + VALUE *vp; + long fullsize, count, index; + long dim, i, j; + char *msg; + long sizes[MAXDIM]; - dim = m->m_dim; - fullsize = 1; - for (i = dim - 1; i >= 0; i--) { - sizes[i] = fullsize; - fullsize *= (m->m_max[i] - m->m_min[i] + 1); - } - msg = ((max_print > 0) ? "\nmat [" : "mat ["); - if (dim) { - for (i = 0; i < dim; i++) { - if (m->m_min[i]) { - math_fmt("%s%ld:%ld", msg, - m->m_min[i], m->m_max[i]); - } else { - math_fmt("%s%ld", msg, m->m_max[i] + 1); - } - msg = ","; - } - } else { - math_str("mat ["); - } - if (max_print > fullsize) { - max_print = fullsize; - } - vp = m->m_table; - count = 0; - for (index = 0; index < fullsize; index++) { - if ((vp->v_type != V_NUM) || !qiszero(vp->v_num)) - count++; - vp++; - } - math_fmt("] (%ld element%s, %ld nonzero)", - fullsize, (fullsize == 1) ? "" : "s", count); - if (max_print <= 0) - return; + dim = m->m_dim; + fullsize = 1; + for (i = dim - 1; i >= 0; i--) { + sizes[i] = fullsize; + fullsize *= (m->m_max[i] - m->m_min[i] + 1); + } + msg = ((max_print > 0) ? "\nmat [" : "mat ["); + if (dim) { + for (i = 0; i < dim; i++) { + if (m->m_min[i]) { + math_fmt("%s%ld:%ld", msg, + m->m_min[i], m->m_max[i]); + } else { + math_fmt("%s%ld", msg, m->m_max[i] + 1); + } + msg = ","; + } + } else { + math_str("mat ["); + } + if (max_print > fullsize) { + max_print = fullsize; + } + vp = m->m_table; + count = 0; + for (index = 0; index < fullsize; index++) { + if ((vp->v_type != V_NUM) || !qiszero(vp->v_num)) + count++; + vp++; + } + math_fmt("] (%ld element%s, %ld nonzero)", + fullsize, (fullsize == 1) ? "" : "s", count); + if (max_print <= 0) + return; - /* - * Now print the first few elements of the matrix in short - * and unambiguous format. - */ - math_str(":\n"); - vp = m->m_table; - for (index = 0; index < max_print; index++) { - msg = " ["; - j = index; - if (dim) { - for (i = 0; i < dim; i++) { - math_fmt("%s%ld", msg, - m->m_min[i] + (j / sizes[i])); - j %= sizes[i]; - msg = ","; - } - } else { - math_str(msg); - } - math_str("] = "); - printvalue(vp++, PRINT_SHORT | PRINT_UNAMBIG); - math_str("\n"); - } - if (max_print < fullsize) - math_str(" ...\n"); + /* + * Now print the first few elements of the matrix in short + * and unambiguous format. + */ + math_str(":\n"); + vp = m->m_table; + for (index = 0; index < max_print; index++) { + msg = " ["; + j = index; + if (dim) { + for (i = 0; i < dim; i++) { + math_fmt("%s%ld", msg, + m->m_min[i] + (j / sizes[i])); + j %= sizes[i]; + msg = ","; + } + } else { + math_str(msg); + } + math_str("] = "); + printvalue(vp++, PRINT_SHORT | PRINT_UNAMBIG); + math_str("\n"); + } + if (max_print < fullsize) + math_str(" ...\n"); } diff --git a/math_error.c b/math_error.c index 41670f2..d5a183c 100644 --- a/math_error.c +++ b/math_error.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1994/08/03 05:08:22 - * File existed as early as: 1994 + * Under source code control: 1994/08/03 05:08:22 + * File existed as early as: 1994 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -39,22 +39,22 @@ * * For example: * - * #include - * #include "lib_calc.h" + * #include + * #include "lib_calc.h" * - * int error; + * int error; * - * ... + * ... * - * if ((error = setjmp(calc_matherr_jmpbuf)) != 0) { + * if ((error = setjmp(calc_matherr_jmpbuf)) != 0) { * - * (* reinitialize calc after a longjmp *) - * reinitialize(); + * (* reinitialize calc after a longjmp *) + * reinitialize(); * - * (* report the error *) - * printf("Ouch: %s\n", calc_err_msg); - * } - * calc_use_matherr_jmpbuf = 1; + * (* report the error *) + * printf("Ouch: %s\n", calc_err_msg); + * } + * calc_use_matherr_jmpbuf = 1; */ @@ -65,7 +65,7 @@ #include "lib_calc.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* @@ -74,50 +74,50 @@ void math_error(char *fmt, ...) { - va_list ap; + va_list ap; - /* - * format the error - */ + /* + * format the error + */ #ifdef VARARGS - va_start(ap); + va_start(ap); #else - va_start(ap, fmt); + va_start(ap, fmt); #endif - vsnprintf(calc_err_msg, MAXERROR, fmt, ap); - va_end(ap); - calc_err_msg[MAXERROR] = '\0'; /* paranoia */ + vsnprintf(calc_err_msg, MAXERROR, fmt, ap); + va_end(ap); + calc_err_msg[MAXERROR] = '\0'; /* paranoia */ - /* - * if we should longjmp, so do - */ - if (calc_use_matherr_jmpbuf != 0) { - if (conf->calc_debug & CALCDBG_RUNSTATE) - printf("math_error: longjmp calc_matherr_jmpbuf\n"); - longjmp(calc_matherr_jmpbuf, calc_use_matherr_jmpbuf); - } + /* + * if we should longjmp, so do + */ + if (calc_use_matherr_jmpbuf != 0) { + if (conf->calc_debug & CALCDBG_RUNSTATE) + printf("math_error: longjmp calc_matherr_jmpbuf\n"); + longjmp(calc_matherr_jmpbuf, calc_use_matherr_jmpbuf); + } - /* - * print error message and edit - */ - (void) fflush(stdout); - (void) fflush(stderr); - fprintf(stderr, "%s\n\n", calc_err_msg); + /* + * print error message and edit + */ + (void) fflush(stdout); + (void) fflush(stderr); + fprintf(stderr, "%s\n\n", calc_err_msg); - /* - * if interactive, return to main via longjmp() - */ - if (calc_use_scanerr_jmpbuf != 0) { - if (conf->calc_debug & CALCDBG_RUNSTATE) - printf("math_error: longjmp calc_scanerr_jmpbuf\n"); - longjmp(calc_scanerr_jmpbuf, calc_use_scanerr_jmpbuf); - } + /* + * if interactive, return to main via longjmp() + */ + if (calc_use_scanerr_jmpbuf != 0) { + if (conf->calc_debug & CALCDBG_RUNSTATE) + printf("math_error: longjmp calc_scanerr_jmpbuf\n"); + longjmp(calc_scanerr_jmpbuf, calc_use_scanerr_jmpbuf); + } - /* - * exit - */ - if (conf->calc_debug & CALCDBG_RUNSTATE) - printf("math_error: about to exit\n"); - libcalc_call_me_last(); - exit(40); + /* + * exit + */ + if (conf->calc_debug & CALCDBG_RUNSTATE) + printf("math_error: about to exit\n"); + libcalc_call_me_last(); + exit(40); } diff --git a/nametype.h b/nametype.h index 3e3b58d..38b57ce 100644 --- a/nametype.h +++ b/nametype.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/03/08 13:44:55 - * File existed as early as: 1997 + * Under source code control: 1997/03/08 13:44:55 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -33,8 +33,8 @@ * Configuration parameter name and type. */ typedef struct { - char *name; /* name of configuration string */ - long type; /* type for configuration */ + char *name; /* name of configuration string */ + long type; /* type for configuration */ } NAMETYPE; diff --git a/obj.c b/obj.c index 33f64e2..0a4e070 100644 --- a/obj.c +++ b/obj.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:19 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:19 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * "Object" handling primitives. @@ -39,134 +39,134 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* * Types of values returned by calling object routines. */ -#define A_VALUE 0 /* returns arbitrary value */ -#define A_INT 1 /* returns integer value */ -#define A_UNDEF 2 /* returns no value */ +#define A_VALUE 0 /* returns arbitrary value */ +#define A_INT 1 /* returns integer value */ +#define A_UNDEF 2 /* returns no value */ /* * Error handling actions for when the function is undefined. */ -#define ERR_NONE 0 /* no special action */ -#define ERR_PRINT 1 /* print element */ -#define ERR_CMP 2 /* compare two values */ -#define ERR_TEST 3 /* test value for nonzero */ -#define ERR_POW 4 /* call generic power routine */ -#define ERR_ONE 5 /* return number 1 */ -#define ERR_INC 6 /* increment by one */ -#define ERR_DEC 7 /* decrement by one */ -#define ERR_SQUARE 8 /* square value */ -#define ERR_VALUE 9 /* return value */ -#define ERR_ASSIGN 10 /* assign value */ +#define ERR_NONE 0 /* no special action */ +#define ERR_PRINT 1 /* print element */ +#define ERR_CMP 2 /* compare two values */ +#define ERR_TEST 3 /* test value for nonzero */ +#define ERR_POW 4 /* call generic power routine */ +#define ERR_ONE 5 /* return number 1 */ +#define ERR_INC 6 /* increment by one */ +#define ERR_DEC 7 /* decrement by one */ +#define ERR_SQUARE 8 /* square value */ +#define ERR_VALUE 9 /* return value */ +#define ERR_ASSIGN 10 /* assign value */ STATIC struct objectinfo { - short args; /* number of arguments */ - short retval; /* type of return value */ - short error; /* special action on errors */ - char *name; /* name of function to call */ - char *comment; /* useful comment if any */ + short args; /* number of arguments */ + short retval; /* type of return value */ + short error; /* special action on errors */ + char *name; /* name of function to call */ + char *comment; /* useful comment if any */ } objectinfo[] = { - {1, A_UNDEF, ERR_PRINT, - "print", "print value, default prints elements"}, - {1, A_VALUE, ERR_ONE, - "one", "multiplicative identity, default is 1"}, - {1, A_INT, ERR_TEST, - "test", "logical test (false,true => 0,1), default tests elements"}, - {2, A_VALUE, ERR_NONE, - "add", NULL}, - {2, A_VALUE, ERR_NONE, - "sub", NULL}, - {1, A_VALUE, ERR_NONE, - "neg", "negative"}, - {2, A_VALUE, ERR_NONE, - "mul", NULL}, - {2, A_VALUE, ERR_NONE, - "div", "non-integral division"}, - {1, A_VALUE, ERR_NONE, - "inv", "multiplicative inverse"}, - {2, A_VALUE, ERR_NONE, - "abs", "absolute value within given error"}, - {1, A_VALUE, ERR_NONE, - "norm", "square of absolute value"}, - {1, A_VALUE, ERR_NONE, - "conj", "conjugate"}, - {2, A_VALUE, ERR_POW, - "pow", "integer power, default does multiply, square, inverse"}, - {1, A_VALUE, ERR_NONE, - "sgn", "sign of value (-1, 0, 1)"}, - {2, A_INT, ERR_CMP, - "cmp", "equality (equal,nonequal => 0,1), default tests elements"}, - {2, A_VALUE, ERR_NONE, - "rel", "relative order, positive for >, etc."}, - {3, A_VALUE, ERR_NONE, - "quo", "integer quotient"}, - {3, A_VALUE, ERR_NONE, - "mod", "remainder of division"}, - {1, A_VALUE, ERR_NONE, - "int", "integer part"}, - {1, A_VALUE, ERR_NONE, - "frac", "fractional part"}, - {1, A_VALUE, ERR_INC, - "inc", "increment, default adds 1"}, - {1, A_VALUE, ERR_DEC, - "dec", "decrement, default subtracts 1"}, - {1, A_VALUE, ERR_SQUARE, - "square", "default multiplies by itself"}, - {2, A_VALUE, ERR_NONE, - "scale", "multiply by power of 2"}, - {2, A_VALUE, ERR_NONE, - "shift", "shift left by n bits (right if negative)"}, - {3, A_VALUE, ERR_NONE, - "round", "round to given number of decimal places"}, - {3, A_VALUE, ERR_NONE, - "bround", "round to given number of binary places"}, - {3, A_VALUE, ERR_NONE, - "root", "root of value within given error"}, - {3, A_VALUE, ERR_NONE, - "sqrt", "square root within given error"}, - {2, A_VALUE, ERR_NONE, - "or", "bitwise or"}, - {2, A_VALUE, ERR_NONE, - "and", "bitwise and"}, - {1, A_VALUE, ERR_NONE, - "not", "logical not"}, - {1, A_VALUE, ERR_NONE, - "fact", "factorial or postfix !"}, - {1, A_VALUE, ERR_VALUE, - "min", "value for min(...)"}, - {1, A_VALUE, ERR_VALUE, - "max", "value for max(...)"}, - {1, A_VALUE, ERR_VALUE, - "sum", "value for sum(...)"}, - {2, A_UNDEF, ERR_ASSIGN, - "assign", "assign, defaults to a = b"}, - {2, A_VALUE, ERR_NONE, - "xor", "value for binary ~"}, - {1, A_VALUE, ERR_NONE, - "comp", "value for unary ~"}, - {1, A_VALUE, ERR_NONE, - "content", "unary hash op"}, - {2, A_VALUE, ERR_NONE, - "hashop", "binary hash op"}, - {1, A_VALUE, ERR_NONE, - "backslash", "unary backslash op"}, - {2, A_VALUE, ERR_NONE, - "setminus", "binary backslash op"}, - {1, A_VALUE, ERR_NONE, - "plus", "unary + op"}, - {0, 0, 0, - NULL, NULL} + {1, A_UNDEF, ERR_PRINT, + "print", "print value, default prints elements"}, + {1, A_VALUE, ERR_ONE, + "one", "multiplicative identity, default is 1"}, + {1, A_INT, ERR_TEST, + "test", "logical test (false,true => 0,1), default tests elements"}, + {2, A_VALUE, ERR_NONE, + "add", NULL}, + {2, A_VALUE, ERR_NONE, + "sub", NULL}, + {1, A_VALUE, ERR_NONE, + "neg", "negative"}, + {2, A_VALUE, ERR_NONE, + "mul", NULL}, + {2, A_VALUE, ERR_NONE, + "div", "non-integral division"}, + {1, A_VALUE, ERR_NONE, + "inv", "multiplicative inverse"}, + {2, A_VALUE, ERR_NONE, + "abs", "absolute value within given error"}, + {1, A_VALUE, ERR_NONE, + "norm", "square of absolute value"}, + {1, A_VALUE, ERR_NONE, + "conj", "conjugate"}, + {2, A_VALUE, ERR_POW, + "pow", "integer power, default does multiply, square, inverse"}, + {1, A_VALUE, ERR_NONE, + "sgn", "sign of value (-1, 0, 1)"}, + {2, A_INT, ERR_CMP, + "cmp", "equality (equal,nonequal => 0,1), default tests elements"}, + {2, A_VALUE, ERR_NONE, + "rel", "relative order, positive for >, etc."}, + {3, A_VALUE, ERR_NONE, + "quo", "integer quotient"}, + {3, A_VALUE, ERR_NONE, + "mod", "remainder of division"}, + {1, A_VALUE, ERR_NONE, + "int", "integer part"}, + {1, A_VALUE, ERR_NONE, + "frac", "fractional part"}, + {1, A_VALUE, ERR_INC, + "inc", "increment, default adds 1"}, + {1, A_VALUE, ERR_DEC, + "dec", "decrement, default subtracts 1"}, + {1, A_VALUE, ERR_SQUARE, + "square", "default multiplies by itself"}, + {2, A_VALUE, ERR_NONE, + "scale", "multiply by power of 2"}, + {2, A_VALUE, ERR_NONE, + "shift", "shift left by n bits (right if negative)"}, + {3, A_VALUE, ERR_NONE, + "round", "round to given number of decimal places"}, + {3, A_VALUE, ERR_NONE, + "bround", "round to given number of binary places"}, + {3, A_VALUE, ERR_NONE, + "root", "root of value within given error"}, + {3, A_VALUE, ERR_NONE, + "sqrt", "square root within given error"}, + {2, A_VALUE, ERR_NONE, + "or", "bitwise or"}, + {2, A_VALUE, ERR_NONE, + "and", "bitwise and"}, + {1, A_VALUE, ERR_NONE, + "not", "logical not"}, + {1, A_VALUE, ERR_NONE, + "fact", "factorial or postfix !"}, + {1, A_VALUE, ERR_VALUE, + "min", "value for min(...)"}, + {1, A_VALUE, ERR_VALUE, + "max", "value for max(...)"}, + {1, A_VALUE, ERR_VALUE, + "sum", "value for sum(...)"}, + {2, A_UNDEF, ERR_ASSIGN, + "assign", "assign, defaults to a = b"}, + {2, A_VALUE, ERR_NONE, + "xor", "value for binary ~"}, + {1, A_VALUE, ERR_NONE, + "comp", "value for unary ~"}, + {1, A_VALUE, ERR_NONE, + "content", "unary hash op"}, + {2, A_VALUE, ERR_NONE, + "hashop", "binary hash op"}, + {1, A_VALUE, ERR_NONE, + "backslash", "unary backslash op"}, + {2, A_VALUE, ERR_NONE, + "setminus", "binary backslash op"}, + {1, A_VALUE, ERR_NONE, + "plus", "unary + op"}, + {0, 0, 0, + NULL, NULL} }; -STATIC STRINGHEAD objectnames; /* names of objects */ -STATIC STRINGHEAD elements; /* element names for parts of objects */ +STATIC STRINGHEAD objectnames; /* names of objects */ +STATIC STRINGHEAD elements; /* element names for parts of objects */ STATIC OBJECTACTIONS **objects; /* table of actions for objects */ #define OBJALLOC 16 @@ -184,16 +184,16 @@ S_FUNC void objprint(OBJECT *op); void showobjfuncs(void) { - register struct objectinfo *oip; + register struct objectinfo *oip; - printf("\nThe following object routines are definable.\n"); - printf("Note: xx represents the actual object type name.\n\n"); - printf("Name Args Comments\n"); - for (oip = objectinfo; oip->name; oip++) { - printf("xx_%-8s %d %s\n", oip->name, oip->args, - oip->comment ? oip->comment : ""); - } - printf("\n"); + printf("\nThe following object routines are definable.\n"); + printf("Note: xx represents the actual object type name.\n\n"); + printf("Name Args Comments\n"); + for (oip = objectinfo; oip->name; oip++) { + printf("xx_%-8s %d %s\n", oip->name, oip->args, + oip->comment ? oip->comment : ""); + } + printf("\n"); } @@ -204,174 +204,174 @@ showobjfuncs(void) VALUE objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3) { - FUNC *fp; /* function to call */ - STATIC OBJECTACTIONS *oap; /* object to call for */ - struct objectinfo *oip; /* information about action */ - long index; /* index of function (negative if undefined) */ - VALUE val; /* return value */ - VALUE tmp; /* temp value */ - char name[SYMBOLSIZE+1+1]; /* full name of user routine to call */ - size_t namestr_len; /* length of the namestr() return string */ - char *namestr_ret; /* namestr() return string */ - size_t opi_name_len; /* length of the oip name */ + FUNC *fp; /* function to call */ + STATIC OBJECTACTIONS *oap; /* object to call for */ + struct objectinfo *oip; /* information about action */ + long index; /* index of function (negative if undefined) */ + VALUE val; /* return value */ + VALUE tmp; /* temp value */ + char name[SYMBOLSIZE+1+1]; /* full name of user routine to call */ + size_t namestr_len; /* length of the namestr() return string */ + char *namestr_ret; /* namestr() return string */ + size_t opi_name_len; /* length of the oip name */ - /* initialize name */ - memset(name, 0, sizeof(name)); + /* initialize name */ + memset(name, 0, sizeof(name)); - /* initialize VALUEs */ - val.v_subtype = V_NOSUBTYPE; - tmp.v_subtype = V_NOSUBTYPE; + /* initialize VALUEs */ + val.v_subtype = V_NOSUBTYPE; + tmp.v_subtype = V_NOSUBTYPE; - if ((unsigned)action > OBJ_MAXFUNC) { - math_error("Illegal action for object call"); - not_reached(); - } - oip = &objectinfo[action]; - if (v1->v_type == V_OBJ) { - oap = v1->v_obj->o_actions; - } else if (v2->v_type == V_OBJ) { - oap = v2->v_obj->o_actions; - } else { - math_error("Object routine called with non-object"); - not_reached(); - } - index = oap->oa_indices[action]; - if (index < 0) { - namestr_ret = namestr(&objectnames, oap->oa_index); - if (namestr_ret == NULL) { - math_error("namestr returned NULL!!!"); - not_reached(); - } - namestr_len = strlen(namestr_ret); - opi_name_len = strlen(oip->name); - if (namestr_len > (size_t)SYMBOLSIZE-1-opi_name_len) { - math_error("namestr returned a strong too long!!!"); - not_reached(); - } - name[0] = '\0'; - strlcpy(name, namestr_ret, namestr_len+1); - strlcat(name, "_", sizeof(name)); - strlcat(name, oip->name, sizeof(name)); - index = adduserfunc(name); - oap->oa_indices[action] = index; - } - fp = NULL; - if (index >= 0) - fp = findfunc(index); - if (fp == NULL) { - switch (oip->error) { - case ERR_PRINT: - objprint(v1->v_obj); - val.v_type = V_NULL; - break; - case ERR_CMP: - val.v_type = V_INT; - if (v1->v_type != v2->v_type) { - val.v_int = 1; - return val; - } - val.v_int = objcmp(v1->v_obj, v2->v_obj); - break; - case ERR_TEST: - val.v_type = V_INT; - val.v_int = objtest(v1->v_obj); - break; - case ERR_POW: - if (v2->v_type != V_NUM) { - math_error("Non-real power"); - not_reached(); - } - val = objpowi(v1, v2->v_num); - break; - case ERR_ONE: - val.v_type = V_NUM; - val.v_num = qlink(&_qone_); - break; - case ERR_INC: - tmp.v_type = V_NUM; - tmp.v_num = &_qone_; - val = objcall(OBJ_ADD, v1, &tmp, NULL_VALUE); - break; - case ERR_DEC: - tmp.v_type = V_NUM; - tmp.v_num = &_qone_; - val = objcall(OBJ_SUB, v1, &tmp, NULL_VALUE); - break; - case ERR_SQUARE: - val = objcall(OBJ_MUL, v1, v1, NULL_VALUE); - break; - case ERR_VALUE: - copyvalue(v1, &val); - break; - case ERR_ASSIGN: - copyvalue(v2, &tmp); - tmp.v_subtype |= v1->v_subtype; - freevalue(v1); - *v1 = tmp; - val.v_type = V_NULL; - break; - default: - math_error("Function \"%s\" is undefined", - namefunc(index)); - not_reached(); - } - return val; - } - switch (oip->args) { - case 0: - break; - case 1: - ++stack; - stack->v_addr = v1; - stack->v_type = V_ADDR; - break; - case 2: - ++stack; - stack->v_addr = v1; - stack->v_type = V_ADDR; - ++stack; - stack->v_addr = v2; - stack->v_type = V_ADDR; - break; - case 3: - ++stack; - stack->v_addr = v1; - stack->v_type = V_ADDR; - ++stack; - stack->v_addr = v2; - stack->v_type = V_ADDR; - ++stack; - stack->v_addr = v3; - stack->v_type = V_ADDR; - break; - default: - math_error("Bad number of args to calculate"); - not_reached(); - } - calculate(fp, oip->args); - switch (oip->retval) { - case A_VALUE: - return *stack--; - case A_UNDEF: - freevalue(stack--); - val.v_type = V_NULL; - break; - case A_INT: - if ((stack->v_type != V_NUM) || qisfrac(stack->v_num)) { - math_error("Integer return value required"); - not_reached(); - } - index = qtoi(stack->v_num); - qfree(stack->v_num); - stack--; - val.v_type = V_INT; - val.v_int = index; - break; - default: - math_error("Bad object return"); - not_reached(); - } - return val; + if ((unsigned)action > OBJ_MAXFUNC) { + math_error("Illegal action for object call"); + not_reached(); + } + oip = &objectinfo[action]; + if (v1->v_type == V_OBJ) { + oap = v1->v_obj->o_actions; + } else if (v2->v_type == V_OBJ) { + oap = v2->v_obj->o_actions; + } else { + math_error("Object routine called with non-object"); + not_reached(); + } + index = oap->oa_indices[action]; + if (index < 0) { + namestr_ret = namestr(&objectnames, oap->oa_index); + if (namestr_ret == NULL) { + math_error("namestr returned NULL!!!"); + not_reached(); + } + namestr_len = strlen(namestr_ret); + opi_name_len = strlen(oip->name); + if (namestr_len > (size_t)SYMBOLSIZE-1-opi_name_len) { + math_error("namestr returned a strong too long!!!"); + not_reached(); + } + name[0] = '\0'; + strlcpy(name, namestr_ret, namestr_len+1); + strlcat(name, "_", sizeof(name)); + strlcat(name, oip->name, sizeof(name)); + index = adduserfunc(name); + oap->oa_indices[action] = index; + } + fp = NULL; + if (index >= 0) + fp = findfunc(index); + if (fp == NULL) { + switch (oip->error) { + case ERR_PRINT: + objprint(v1->v_obj); + val.v_type = V_NULL; + break; + case ERR_CMP: + val.v_type = V_INT; + if (v1->v_type != v2->v_type) { + val.v_int = 1; + return val; + } + val.v_int = objcmp(v1->v_obj, v2->v_obj); + break; + case ERR_TEST: + val.v_type = V_INT; + val.v_int = objtest(v1->v_obj); + break; + case ERR_POW: + if (v2->v_type != V_NUM) { + math_error("Non-real power"); + not_reached(); + } + val = objpowi(v1, v2->v_num); + break; + case ERR_ONE: + val.v_type = V_NUM; + val.v_num = qlink(&_qone_); + break; + case ERR_INC: + tmp.v_type = V_NUM; + tmp.v_num = &_qone_; + val = objcall(OBJ_ADD, v1, &tmp, NULL_VALUE); + break; + case ERR_DEC: + tmp.v_type = V_NUM; + tmp.v_num = &_qone_; + val = objcall(OBJ_SUB, v1, &tmp, NULL_VALUE); + break; + case ERR_SQUARE: + val = objcall(OBJ_MUL, v1, v1, NULL_VALUE); + break; + case ERR_VALUE: + copyvalue(v1, &val); + break; + case ERR_ASSIGN: + copyvalue(v2, &tmp); + tmp.v_subtype |= v1->v_subtype; + freevalue(v1); + *v1 = tmp; + val.v_type = V_NULL; + break; + default: + math_error("Function \"%s\" is undefined", + namefunc(index)); + not_reached(); + } + return val; + } + switch (oip->args) { + case 0: + break; + case 1: + ++stack; + stack->v_addr = v1; + stack->v_type = V_ADDR; + break; + case 2: + ++stack; + stack->v_addr = v1; + stack->v_type = V_ADDR; + ++stack; + stack->v_addr = v2; + stack->v_type = V_ADDR; + break; + case 3: + ++stack; + stack->v_addr = v1; + stack->v_type = V_ADDR; + ++stack; + stack->v_addr = v2; + stack->v_type = V_ADDR; + ++stack; + stack->v_addr = v3; + stack->v_type = V_ADDR; + break; + default: + math_error("Bad number of args to calculate"); + not_reached(); + } + calculate(fp, oip->args); + switch (oip->retval) { + case A_VALUE: + return *stack--; + case A_UNDEF: + freevalue(stack--); + val.v_type = V_NULL; + break; + case A_INT: + if ((stack->v_type != V_NUM) || qisfrac(stack->v_num)) { + math_error("Integer return value required"); + not_reached(); + } + index = qtoi(stack->v_num); + qfree(stack->v_num); + stack--; + val.v_type = V_INT; + val.v_int = index; + break; + default: + math_error("Bad object return"); + not_reached(); + } + return val; } @@ -380,22 +380,22 @@ objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3) * This is the default routine if the user's is not defined. * * given: - * op object being printed + * op object being printed */ S_FUNC void objprint(OBJECT *op) { - int count; /* number of elements */ - int i; /* index */ + int count; /* number of elements */ + int i; /* index */ - count = op->o_actions->oa_count; - math_fmt("obj %s {", namestr(&objectnames, op->o_actions->oa_index)); - for (i = 0; i < count; i++) { - if (i) - math_str(", "); - printvalue(&op->o_table[i], PRINT_SHORT | PRINT_UNAMBIG); - } - math_chr('}'); + count = op->o_actions->oa_count; + math_fmt("obj %s {", namestr(&objectnames, op->o_actions->oa_index)); + for (i = 0; i < count; i++) { + if (i) + math_str(", "); + printvalue(&op->o_table[i], PRINT_SHORT | PRINT_UNAMBIG); + } + math_chr('}'); } @@ -407,14 +407,14 @@ objprint(OBJECT *op) S_FUNC bool objtest(OBJECT *op) { - int i; /* loop counter */ + int i; /* loop counter */ - i = op->o_actions->oa_count; - while (--i >= 0) { - if (testvalue(&op->o_table[i])) - return true; - } - return false; + i = op->o_actions->oa_count; + while (--i >= 0) { + if (testvalue(&op->o_table[i])) + return true; + } + return false; } @@ -426,16 +426,16 @@ objtest(OBJECT *op) S_FUNC bool objcmp(OBJECT *op1, OBJECT *op2) { - int i; /* loop counter */ + int i; /* loop counter */ - if (op1->o_actions != op2->o_actions) - return true; - i = op1->o_actions->oa_count; - while (--i >= 0) { - if (comparevalue(&op1->o_table[i], &op2->o_table[i])) - return true; - } - return false; + if (op1->o_actions != op2->o_actions) + return true; + i = op1->o_actions->oa_count; + while (--i >= 0) { + if (comparevalue(&op1->o_table[i], &op2->o_table[i])) + return true; + } + return false; } @@ -446,79 +446,79 @@ objcmp(OBJECT *op1, OBJECT *op2) * Zero means the multiplicative identity. * * given: - * vp value to be powered - * q power to raise number to + * vp value to be powered + * q power to raise number to */ S_FUNC VALUE objpowi(VALUE *vp, NUMBER *q) { - VALUE res, tmp; - long power; /* power to raise to */ - FULL bit; /* current bit value */ + VALUE res, tmp; + long power; /* power to raise to */ + FULL bit; /* current bit value */ - if (qisfrac(q)) { - math_error("Raising object to non-integral power"); - not_reached(); - } - if (zge31b(q->num)) { - math_error("Raising object to very large power"); - not_reached(); - } - power = ztolong(q->num); - if (qisneg(q)) - power = -power; - /* - * Handle some low powers specially - */ - if ((power <= 2) && (power >= -2)) { - switch ((int) power) { - case 0: - return objcall(OBJ_ONE, vp, NULL_VALUE, NULL_VALUE); - case 1: - res.v_obj = objcopy(vp->v_obj); - res.v_type = V_OBJ; - res.v_subtype = V_NOSUBTYPE; - return res; - case -1: - return objcall(OBJ_INV, vp, NULL_VALUE, NULL_VALUE); - case 2: - return objcall(OBJ_SQUARE, vp, NULL_VALUE, NULL_VALUE); - } - } - if (power < 0) - power = -power; - /* - * Compute the power by squaring and multiplying. - * This uses the left to right method of power raising. - */ - bit = TOPFULL; - while ((bit & power) == 0) - bit >>= 1L; - bit >>= 1L; - res = objcall(OBJ_SQUARE, vp, NULL_VALUE, NULL_VALUE); - if (bit & power) { - tmp = objcall(OBJ_MUL, &res, vp, NULL_VALUE); - objfree(res.v_obj); - res = tmp; - } - bit >>= 1L; - while (bit) { - tmp = objcall(OBJ_SQUARE, &res, NULL_VALUE, NULL_VALUE); - objfree(res.v_obj); - res = tmp; - if (bit & power) { - tmp = objcall(OBJ_MUL, &res, vp, NULL_VALUE); - objfree(res.v_obj); - res = tmp; - } - bit >>= 1L; - } - if (qisneg(q)) { - tmp = objcall(OBJ_INV, &res, NULL_VALUE, NULL_VALUE); - objfree(res.v_obj); - return tmp; - } - return res; + if (qisfrac(q)) { + math_error("Raising object to non-integral power"); + not_reached(); + } + if (zge31b(q->num)) { + math_error("Raising object to very large power"); + not_reached(); + } + power = ztolong(q->num); + if (qisneg(q)) + power = -power; + /* + * Handle some low powers specially + */ + if ((power <= 2) && (power >= -2)) { + switch ((int) power) { + case 0: + return objcall(OBJ_ONE, vp, NULL_VALUE, NULL_VALUE); + case 1: + res.v_obj = objcopy(vp->v_obj); + res.v_type = V_OBJ; + res.v_subtype = V_NOSUBTYPE; + return res; + case -1: + return objcall(OBJ_INV, vp, NULL_VALUE, NULL_VALUE); + case 2: + return objcall(OBJ_SQUARE, vp, NULL_VALUE, NULL_VALUE); + } + } + if (power < 0) + power = -power; + /* + * Compute the power by squaring and multiplying. + * This uses the left to right method of power raising. + */ + bit = TOPFULL; + while ((bit & power) == 0) + bit >>= 1L; + bit >>= 1L; + res = objcall(OBJ_SQUARE, vp, NULL_VALUE, NULL_VALUE); + if (bit & power) { + tmp = objcall(OBJ_MUL, &res, vp, NULL_VALUE); + objfree(res.v_obj); + res = tmp; + } + bit >>= 1L; + while (bit) { + tmp = objcall(OBJ_SQUARE, &res, NULL_VALUE, NULL_VALUE); + objfree(res.v_obj); + res = tmp; + if (bit & power) { + tmp = objcall(OBJ_MUL, &res, vp, NULL_VALUE); + objfree(res.v_obj); + res = tmp; + } + bit >>= 1L; + } + if (qisneg(q)) { + tmp = objcall(OBJ_INV, &res, NULL_VALUE, NULL_VALUE); + objfree(res.v_obj); + return tmp; + } + return res; } @@ -528,75 +528,75 @@ objpowi(VALUE *vp, NUMBER *q) * and the number of elements defined for the object. * * given: - * name name of object type - * indices table of indices for elements - * count number of elements defined for the object + * name name of object type + * indices table of indices for elements + * count number of elements defined for the object */ int defineobject(char *name, int indices[], int count) { - OBJECTACTIONS *oap; /* object definition structure */ - STRINGHEAD *hp; - OBJECTACTIONS **newobjects; - int index; + OBJECTACTIONS *oap; /* object definition structure */ + STRINGHEAD *hp; + OBJECTACTIONS **newobjects; + int index; - hp = &objectnames; - if (hp->h_list == NULL) - initstr(hp); - index = findstr(hp, name); - if (index >= 0) { - /* - * Object is already defined. Give an error unless this - * new definition is exactly the same as the old one. - */ - oap = objects[index]; - if (oap->oa_count == count) { - for (index = 0; ; index++) { - if (index >= count) - return 0; - if (oap->oa_elements[index] != indices[index]) - break; - } - } - return 1; - } + hp = &objectnames; + if (hp->h_list == NULL) + initstr(hp); + index = findstr(hp, name); + if (index >= 0) { + /* + * Object is already defined. Give an error unless this + * new definition is exactly the same as the old one. + */ + oap = objects[index]; + if (oap->oa_count == count) { + for (index = 0; ; index++) { + if (index >= count) + return 0; + if (oap->oa_elements[index] != indices[index]) + break; + } + } + return 1; + } - if (hp->h_count >= maxobjcount) { - if (maxobjcount == 0) { - newobjects = (OBJECTACTIONS **) malloc( - OBJALLOC * sizeof(OBJECTACTIONS *)); - maxobjcount = OBJALLOC; - } else { - maxobjcount += OBJALLOC; - newobjects = (OBJECTACTIONS **) realloc(objects, - maxobjcount * sizeof(OBJECTACTIONS *)); - } - if (newobjects == NULL) { - math_error("Allocation failure for new object type"); - not_reached(); - } - objects = newobjects; - } + if (hp->h_count >= maxobjcount) { + if (maxobjcount == 0) { + newobjects = (OBJECTACTIONS **) malloc( + OBJALLOC * sizeof(OBJECTACTIONS *)); + maxobjcount = OBJALLOC; + } else { + maxobjcount += OBJALLOC; + newobjects = (OBJECTACTIONS **) realloc(objects, + maxobjcount * sizeof(OBJECTACTIONS *)); + } + if (newobjects == NULL) { + math_error("Allocation failure for new object type"); + not_reached(); + } + objects = newobjects; + } - oap = (OBJECTACTIONS *) malloc(objectactionsize(count)); - if (oap == NULL) { - math_error("Cannot allocate object type #0"); - not_reached(); - } - name = addstr(hp, name); - if (name == NULL) { - math_error("Cannot allocate object type #1"); - not_reached(); - } - oap->oa_count = count; - for (index = OBJ_MAXFUNC; index >= 0; index--) - oap->oa_indices[index] = -1; - for (index = 0; index < count; index++) - oap->oa_elements[index] = indices[index]; - index = findstr(hp, name); - oap->oa_index = index; - objects[index] = oap; - return 0; + oap = (OBJECTACTIONS *) malloc(objectactionsize(count)); + if (oap == NULL) { + math_error("Cannot allocate object type #0"); + not_reached(); + } + name = addstr(hp, name); + if (name == NULL) { + math_error("Cannot allocate object type #1"); + not_reached(); + } + oap->oa_count = count; + for (index = OBJ_MAXFUNC; index >= 0; index--) + oap->oa_indices[index] = -1; + for (index = 0; index < count; index++) + oap->oa_elements[index] = indices[index]; + index = findstr(hp, name); + oap->oa_index = index; + objects[index] = oap; + return 0; } @@ -608,12 +608,12 @@ defineobject(char *name, int indices[], int count) int checkobject(char *name) { - STRINGHEAD *hp; + STRINGHEAD *hp; - hp = &objectnames; - if (hp->h_list == NULL) - return -1; - return findstr(hp, name); + hp = &objectnames; + if (hp->h_list == NULL) + return -1; + return findstr(hp, name); } @@ -624,20 +624,20 @@ checkobject(char *name) int addelement(char *name) { - STRINGHEAD *hp; - int index; + STRINGHEAD *hp; + int index; - hp = &elements; - if (hp->h_list == NULL) - initstr(hp); - index = findstr(hp, name); - if (index >= 0) - return index; - if (addstr(hp, name) == NULL) { - math_error("Cannot allocate element name"); - not_reached(); - } - return findstr(hp, name); + hp = &elements; + if (hp->h_list == NULL) + initstr(hp); + index = findstr(hp, name); + if (index >= 0) + return index; + if (addstr(hp, name) == NULL) { + math_error("Cannot allocate element name"); + not_reached(); + } + return findstr(hp, name); } @@ -646,14 +646,14 @@ addelement(char *name) * Returns minus one if the element name is unknown. * * given: - * name element name + * name element name */ int findelement(char *name) { - if (elements.h_list == NULL) - return -1; - return findstr(&elements, name); + if (elements.h_list == NULL) + return -1; + return findstr(&elements, name); } @@ -663,27 +663,27 @@ findelement(char *name) char * objtypename(unsigned long index) { - return namestr(&objectnames, (long)index); + return namestr(&objectnames, (long)index); } /* * Return the value table offset to be used for an object element name. * This converts the element index from the element table into an offset - * into the object value array. Returns -1 if the element index is unknown. + * into the object value array. Returns -1 if the element index is unknown. */ int objoffset(OBJECT *op, long index) { - register OBJECTACTIONS *oap; - int offset; /* offset into value array */ + register OBJECTACTIONS *oap; + int offset; /* offset into value array */ - oap = op->o_actions; - for (offset = oap->oa_count - 1; offset >= 0; offset--) { - if (oap->oa_elements[offset] == index) - return offset; - } - return -1; + oap = op->o_actions; + for (offset = oap->oa_count - 1; offset >= 0; offset--) { + if (oap->oa_elements[offset] == index) + return offset; + } + return -1; } @@ -693,39 +693,39 @@ objoffset(OBJECT *op, long index) OBJECT * objalloc(long index) { - OBJECTACTIONS *oap; - OBJECT *op; - VALUE *vp; - int i; + OBJECTACTIONS *oap; + OBJECT *op; + VALUE *vp; + int i; - if (index < 0 || index > maxobjcount) { - math_error("Allocating bad object index"); - not_reached(); - } - oap = objects[index]; - if (oap == NULL) { - math_error("Object type not defined"); - not_reached(); - } - i = oap->oa_count; - if (i < USUAL_ELEMENTS) - i = USUAL_ELEMENTS; - if (i == USUAL_ELEMENTS) - op = (OBJECT *) malloc(sizeof(OBJECT)); - else - op = (OBJECT *) malloc(objectsize(i)); - if (op == NULL) { - math_error("Cannot allocate object"); - not_reached(); - } - op->o_actions = oap; - vp = op->o_table; - for (i = oap->oa_count; i-- > 0; vp++) { - vp->v_num = qlink(&_qzero_); - vp->v_type = V_NUM; - vp->v_subtype = V_NOSUBTYPE; - } - return op; + if (index < 0 || index > maxobjcount) { + math_error("Allocating bad object index"); + not_reached(); + } + oap = objects[index]; + if (oap == NULL) { + math_error("Object type not defined"); + not_reached(); + } + i = oap->oa_count; + if (i < USUAL_ELEMENTS) + i = USUAL_ELEMENTS; + if (i == USUAL_ELEMENTS) + op = (OBJECT *) malloc(sizeof(OBJECT)); + else + op = (OBJECT *) malloc(objectsize(i)); + if (op == NULL) { + math_error("Cannot allocate object"); + not_reached(); + } + op->o_actions = oap; + vp = op->o_table; + for (i = oap->oa_count; i-- > 0; vp++) { + vp->v_num = qlink(&_qzero_); + vp->v_type = V_NUM; + vp->v_subtype = V_NOSUBTYPE; + } + return op; } @@ -735,21 +735,21 @@ objalloc(long index) void objfree(OBJECT *op) { - VALUE *vp; - int i; + VALUE *vp; + int i; - vp = op->o_table; - for (i = op->o_actions->oa_count; i-- > 0; vp++) { - if (vp->v_type == V_NUM) { - qfree(vp->v_num); - } else { - freevalue(vp); - } - } - if (op->o_actions->oa_count <= USUAL_ELEMENTS) - free(op); - else - free((char *) op); + vp = op->o_table; + for (i = op->o_actions->oa_count; i-- > 0; vp++) { + if (vp->v_type == V_NUM) { + qfree(vp->v_num); + } else { + freevalue(vp); + } + } + if (op->o_actions->oa_count <= USUAL_ELEMENTS) + free(op); + else + free((char *) op); } @@ -759,28 +759,28 @@ objfree(OBJECT *op) OBJECT * objcopy(OBJECT *op) { - VALUE *v1, *v2; - OBJECT *np; - int i; + VALUE *v1, *v2; + OBJECT *np; + int i; - i = op->o_actions->oa_count; - if (i < USUAL_ELEMENTS) - i = USUAL_ELEMENTS; - if (i == USUAL_ELEMENTS) - np = (OBJECT *) malloc(sizeof(OBJECT)); - else - np = (OBJECT *) malloc(objectsize(i)); - if (np == NULL) { - math_error("Cannot allocate object"); - not_reached(); - } - np->o_actions = op->o_actions; - v1 = op->o_table; - v2 = np->o_table; - for (i = op->o_actions->oa_count; i-- > 0; v1++, v2++) { - copyvalue(v1, v2); - } - return np; + i = op->o_actions->oa_count; + if (i < USUAL_ELEMENTS) + i = USUAL_ELEMENTS; + if (i == USUAL_ELEMENTS) + np = (OBJECT *) malloc(sizeof(OBJECT)); + else + np = (OBJECT *) malloc(objectsize(i)); + if (np == NULL) { + math_error("Cannot allocate object"); + not_reached(); + } + np->o_actions = op->o_actions; + v1 = op->o_table; + v2 = np->o_table; + for (i = op->o_actions->oa_count; i-- > 0; v1++, v2++) { + copyvalue(v1, v2); + } + return np; } @@ -790,26 +790,26 @@ objcopy(OBJECT *op) void showobjtypes(void) { - STRINGHEAD *hp; - OBJECTACTIONS *oap; - STRINGHEAD *ep; - int index, i; + STRINGHEAD *hp; + OBJECTACTIONS *oap; + STRINGHEAD *ep; + int index, i; - hp = &objectnames; - ep = &elements; - if (hp->h_count == 0) { - printf("No object types defined\n"); - return; - } - for (index = 0; index < hp->h_count; index++) { - oap = objects[index]; - printf("\t%s\t{", namestr(&objectnames, index)); - for (i = 0; i < oap->oa_count; i++) { - if (i) printf(","); - printf("%s", namestr(ep, oap->oa_elements[i])); - } - printf("}\n"); - } + hp = &objectnames; + ep = &elements; + if (hp->h_count == 0) { + printf("No object types defined\n"); + return; + } + for (index = 0; index < hp->h_count; index++) { + oap = objects[index]; + printf("\t%s\t{", namestr(&objectnames, index)); + for (i = 0; i < oap->oa_count; i++) { + if (i) printf(","); + printf("%s", namestr(ep, oap->oa_elements[i])); + } + printf("}\n"); + } } diff --git a/opcodes.c b/opcodes.c index ace2fe4..eb5de71 100644 --- a/opcodes.c +++ b/opcodes.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:19 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:19 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -48,27 +48,27 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define QUICKLOCALS 20 /* local vars to handle quickly */ +#define QUICKLOCALS 20 /* local vars to handle quickly */ -STATIC VALUE stackarray[MAXSTACK]; /* storage for stack */ -STATIC VALUE oldvalue; /* previous calculation value */ -STATIC bool saveval = true; /* to enable or disable saving */ -STATIC int errcount; /* counts calls to error_value */ +STATIC VALUE stackarray[MAXSTACK]; /* storage for stack */ +STATIC VALUE oldvalue; /* previous calculation value */ +STATIC bool saveval = true; /* to enable or disable saving */ +STATIC int errcount; /* counts calls to error_value */ STATIC bool go; STATIC long calc_depth; /* * global symbols */ -VALUE *stack = NULL; /* current location of top of stack */ -int dumpnames = false; /* names if true, otherwise indices */ -char *funcname = NULL; /* function being executed */ -long funcline = 0; /* function line being executed */ -int calc_errno = 0; /* global calc_errno value */ +VALUE *stack = NULL; /* current location of top of stack */ +int dumpnames = false; /* names if true, otherwise indices */ +char *funcname = NULL; /* function being executed */ +long funcline = 0; /* function line being executed */ +int calc_errno = 0; /* global calc_errno value */ /* @@ -82,40 +82,40 @@ S_FUNC void o_getvalue(FUNC *fp); /* * Types of opcodes (depends on arguments saved after the opcode). */ -#define OPNUL 1 /* opcode has no arguments */ -#define OPONE 2 /* opcode has one integer argument */ -#define OPTWO 3 /* opcode has two integer arguments */ -#define OPJMP 4 /* opcode is a jump (with one pointer argument) */ -#define OPRET 5 /* opcode is a return (with no argument) */ -#define OPGLB 6 /* opcode has global symbol pointer argument */ -#define OPPAR 7 /* opcode has parameter index argument */ -#define OPLOC 8 /* opcode needs local variable pointer (with one arg) */ -#define OPSTR 9 /* opcode has a string constant arg */ -#define OPARG 10 /* opcode is given number of arguments */ -#define OPSTI 11 /* opcode is static initialization */ +#define OPNUL 1 /* opcode has no arguments */ +#define OPONE 2 /* opcode has one integer argument */ +#define OPTWO 3 /* opcode has two integer arguments */ +#define OPJMP 4 /* opcode is a jump (with one pointer argument) */ +#define OPRET 5 /* opcode is a return (with no argument) */ +#define OPGLB 6 /* opcode has global symbol pointer argument */ +#define OPPAR 7 /* opcode has parameter index argument */ +#define OPLOC 8 /* opcode needs local variable pointer (with one arg) */ +#define OPSTR 9 /* opcode has a string constant arg */ +#define OPARG 10 /* opcode is given number of arguments */ +#define OPSTI 11 /* opcode is static initialization */ /* * opcode - info about each opcode */ typedef union { - void (*func_nul)(FUNC *); /* OPNUL */ - void (*func_one)(FUNC *, long); /* OPONE */ - void (*func_two)(FUNC *, long, long); /* OPTWO */ - void (*func_jmp)(FUNC *, bool *); /* OPJMP */ - void (*func_ret)(FUNC *); /* OPRET */ - void (*func_glb)(FUNC *, GLOBAL *); /* OPGLB */ - void (*func_par)(FUNC *, int, VALUE *, long); /* OPPAR */ - void (*func_loc)(FUNC *, VALUE *, long); /* OPLOC */ - /* has a string constant arg is unused */ /* OPSTR */ - void (*func_arg)(FUNC *, int, VALUE *); /* OPARG */ - void (*func_sti)(FUNC *); /* OPSTI */ + void (*func_nul)(FUNC *); /* OPNUL */ + void (*func_one)(FUNC *, long); /* OPONE */ + void (*func_two)(FUNC *, long, long); /* OPTWO */ + void (*func_jmp)(FUNC *, bool *); /* OPJMP */ + void (*func_ret)(FUNC *); /* OPRET */ + void (*func_glb)(FUNC *, GLOBAL *); /* OPGLB */ + void (*func_par)(FUNC *, int, VALUE *, long); /* OPPAR */ + void (*func_loc)(FUNC *, VALUE *, long); /* OPLOC */ + /* has a string constant arg is unused */ /* OPSTR */ + void (*func_arg)(FUNC *, int, VALUE *); /* OPARG */ + void (*func_sti)(FUNC *); /* OPSTI */ } opfunc; struct opcode { - opfunc o_func; /* routine to call for opcode */ - int o_type; /* type of opcode */ - char *o_name; /* name of opcode */ + opfunc o_func; /* routine to call for opcode */ + int o_type; /* type of opcode */ + char *o_name; /* name of opcode */ }; @@ -132,25 +132,25 @@ E_FUNC void setconfig(int type, VALUE *vp); void initstack(void) { - unsigned int i; + unsigned int i; - /* on first init, setup the stack array */ - if (stack == NULL) { - for (i=0; i < sizeof(stackarray)/sizeof(stackarray[0]); ++i) { - stackarray[i].v_type = V_NULL; - stackarray[i].v_subtype = V_NOSUBTYPE; - } - stack = stackarray; + /* on first init, setup the stack array */ + if (stack == NULL) { + for (i=0; i < sizeof(stackarray)/sizeof(stackarray[0]); ++i) { + stackarray[i].v_type = V_NULL; + stackarray[i].v_subtype = V_NOSUBTYPE; + } + stack = stackarray; - /* on subsequent inits, free the old stack */ - } else { - while (stack > stackarray) { - freevalue(stack--); - } - } - /* initialize calc_depth */ + /* on subsequent inits, free the old stack */ + } else { + while (stack > stackarray) { + freevalue(stack--); + } + } + /* initialize calc_depth */ - calc_depth = 0; + calc_depth = 0; } @@ -166,377 +166,377 @@ o_nop(FUNC *UNUSED(fp)) S_FUNC void o_localaddr(FUNC *fp, VALUE *locals, long index) { - if ((unsigned long)index >= fp->f_localcount) { - math_error("Bad local variable index"); - not_reached(); - } - locals += index; - stack++; - stack->v_addr = locals; - stack->v_type = V_ADDR; - stack->v_subtype = V_NOSUBTYPE; + if ((unsigned long)index >= fp->f_localcount) { + math_error("Bad local variable index"); + not_reached(); + } + locals += index; + stack++; + stack->v_addr = locals; + stack->v_type = V_ADDR; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_globaladdr(FUNC *UNUSED(fp), GLOBAL *sp) { - if (sp == NULL) { - math_error("Global variable \"%s\" not initialized", - sp->g_name); - not_reached(); - } - stack++; - stack->v_addr = &sp->g_value; - stack->v_type = V_ADDR; - stack->v_subtype = V_NOSUBTYPE; + if (sp == NULL) { + math_error("Global variable \"%s\" not initialized", + sp->g_name); + not_reached(); + } + stack++; + stack->v_addr = &sp->g_value; + stack->v_type = V_ADDR; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_paramaddr(FUNC *UNUSED(fp), int argcount, VALUE *args, long index) { - if ((long)index >= argcount) { - math_error("Bad parameter index"); - not_reached(); - } - args += index; - stack++; - if (args->v_type == V_OCTET || args->v_type == V_ADDR) { - *stack = *args; - return; - } - stack->v_addr = args; - stack->v_type = V_ADDR; -/* stack->v_subtype = V_NOSUBTYPE; */ /* XXX ??? */ + if ((long)index >= argcount) { + math_error("Bad parameter index"); + not_reached(); + } + args += index; + stack++; + if (args->v_type == V_OCTET || args->v_type == V_ADDR) { + *stack = *args; + return; + } + stack->v_addr = args; + stack->v_type = V_ADDR; +/* stack->v_subtype = V_NOSUBTYPE; */ /* XXX ??? */ } S_FUNC void o_localvalue(FUNC *fp, VALUE *locals, long index) { - if ((unsigned long)index >= fp->f_localcount) { - math_error("Bad local variable index"); - not_reached(); - } - locals += index; - copyvalue(locals, ++stack); + if ((unsigned long)index >= fp->f_localcount) { + math_error("Bad local variable index"); + not_reached(); + } + locals += index; + copyvalue(locals, ++stack); } S_FUNC void o_globalvalue(FUNC *UNUSED(fp), GLOBAL *sp) { - if (sp == NULL) { - math_error("Global variable not defined"); - not_reached(); - } - copyvalue(&sp->g_value, ++stack); + if (sp == NULL) { + math_error("Global variable not defined"); + not_reached(); + } + copyvalue(&sp->g_value, ++stack); } S_FUNC void o_paramvalue(FUNC *UNUSED(fp), int argcount, VALUE *args, long index) { - if ((long)index >= argcount) { - math_error("Bad parameter index"); - not_reached(); - } - args += index; - if (args->v_type == V_ADDR) - args = args->v_addr; - copyvalue(args, ++stack); + if ((long)index >= argcount) { + math_error("Bad parameter index"); + not_reached(); + } + args += index; + if (args->v_type == V_ADDR) + args = args->v_addr; + copyvalue(args, ++stack); } S_FUNC void o_argvalue(FUNC *fp, int argcount, VALUE *args) { - VALUE *vp; - long index; + VALUE *vp; + long index; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if ((vp->v_type != V_NUM) || qisneg(vp->v_num) || - qisfrac(vp->v_num)) { - math_error("Illegal argument for arg function"); - not_reached(); - } - if (qiszero(vp->v_num)) { - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack->v_num = itoq((long) argcount); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - return; - } - index = qtoi(vp->v_num) - 1; - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack--; - (void) o_paramaddr(fp, argcount, args, index); + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if ((vp->v_type != V_NUM) || qisneg(vp->v_num) || + qisfrac(vp->v_num)) { + math_error("Illegal argument for arg function"); + not_reached(); + } + if (qiszero(vp->v_num)) { + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack->v_num = itoq((long) argcount); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + return; + } + index = qtoi(vp->v_num) - 1; + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack--; + (void) o_paramaddr(fp, argcount, args, index); } S_FUNC void o_number(FUNC *UNUSED(fp), long arg) { - NUMBER *q; + NUMBER *q; - q = constvalue(arg); - if (q == NULL) { - math_error("Numeric constant value not found"); - not_reached(); - } - stack++; - stack->v_num = qlink(q); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + q = constvalue(arg); + if (q == NULL) { + math_error("Numeric constant value not found"); + not_reached(); + } + stack++; + stack->v_num = qlink(q); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_imaginary(FUNC *UNUSED(fp), long arg) { - NUMBER *q; - COMPLEX *c; + NUMBER *q; + COMPLEX *c; - q = constvalue(arg); - if (q == NULL) { - math_error("Numeric constant value not found"); - not_reached(); - } - stack++; - stack->v_subtype = V_NOSUBTYPE; - if (qiszero(q)) { - stack->v_num = qlink(q); - stack->v_type = V_NUM; - return; - } - c = comalloc(); - qfree(c->imag); - c->imag = qlink(q); - stack->v_com = c; - stack->v_type = V_COM; + q = constvalue(arg); + if (q == NULL) { + math_error("Numeric constant value not found"); + not_reached(); + } + stack++; + stack->v_subtype = V_NOSUBTYPE; + if (qiszero(q)) { + stack->v_num = qlink(q); + stack->v_type = V_NUM; + return; + } + c = comalloc(); + qfree(c->imag); + c->imag = qlink(q); + stack->v_com = c; + stack->v_type = V_COM; } S_FUNC void o_string(FUNC *UNUSED(fp), long arg) { - stack++; - stack->v_str = slink(findstring(arg)); - stack->v_type = V_STR; - stack->v_subtype = V_NOSUBTYPE; + stack++; + stack->v_str = slink(findstring(arg)); + stack->v_type = V_STR; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_undef(FUNC *UNUSED(fp)) { - stack++; - stack->v_type = V_NULL; - stack->v_subtype = V_NOSUBTYPE; + stack++; + stack->v_type = V_NULL; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_matcreate(FUNC *UNUSED(fp), long dim) { - register MATRIX *mp; /* matrix being defined */ - NUMBER *num1; /* first number from stack */ - NUMBER *num2; /* second number from stack */ - VALUE *v1, *v2; - long min[MAXDIM]; /* minimum range */ - long max[MAXDIM]; /* maximum range */ - long i; /* index */ - long tmp; /* temporary */ - long size; /* size of matrix */ + register MATRIX *mp; /* matrix being defined */ + NUMBER *num1; /* first number from stack */ + NUMBER *num2; /* second number from stack */ + VALUE *v1, *v2; + long min[MAXDIM]; /* minimum range */ + long max[MAXDIM]; /* maximum range */ + long i; /* index */ + long tmp; /* temporary */ + long size; /* size of matrix */ - if ((dim < 0) || (dim > MAXDIM)) { - math_error("Bad dimension %ld for matrix", dim); - not_reached(); - } - size = 1; - for (i = dim - 1; i >= 0; i--) { - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if ((v1->v_type != V_NUM) || (v2->v_type != V_NUM)) { - math_error("Non-numeric bounds for matrix"); - not_reached(); - } - num1 = v1->v_num; - num2 = v2->v_num; - if (qisfrac(num1) || qisfrac(num2)) { - math_error("Non-integral bounds for matrix"); - not_reached(); - } - if (zge31b(num1->num) || zge31b(num2->num)) { - math_error("Very large bounds for matrix"); - not_reached(); - } - min[i] = qtoi(num1); - max[i] = qtoi(num2); - if (min[i] > max[i]) { - tmp = min[i]; - min[i] = max[i]; - max[i] = tmp; - } - size *= (max[i] - min[i] + 1); - if (size > 10000000) { - math_error("Very large size for matrix"); - not_reached(); - } - freevalue(stack--); - freevalue(stack--); - } - mp = matalloc(size); - mp->m_dim = dim; - for (i = 0; i < dim; i++) { - mp->m_min[i] = min[i]; - mp->m_max[i] = max[i]; - } - stack++; - stack->v_type = V_MAT; - stack->v_subtype = V_NOSUBTYPE; - stack->v_mat = mp; + if ((dim < 0) || (dim > MAXDIM)) { + math_error("Bad dimension %ld for matrix", dim); + not_reached(); + } + size = 1; + for (i = dim - 1; i >= 0; i--) { + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if ((v1->v_type != V_NUM) || (v2->v_type != V_NUM)) { + math_error("Non-numeric bounds for matrix"); + not_reached(); + } + num1 = v1->v_num; + num2 = v2->v_num; + if (qisfrac(num1) || qisfrac(num2)) { + math_error("Non-integral bounds for matrix"); + not_reached(); + } + if (zge31b(num1->num) || zge31b(num2->num)) { + math_error("Very large bounds for matrix"); + not_reached(); + } + min[i] = qtoi(num1); + max[i] = qtoi(num2); + if (min[i] > max[i]) { + tmp = min[i]; + min[i] = max[i]; + max[i] = tmp; + } + size *= (max[i] - min[i] + 1); + if (size > 10000000) { + math_error("Very large size for matrix"); + not_reached(); + } + freevalue(stack--); + freevalue(stack--); + } + mp = matalloc(size); + mp->m_dim = dim; + for (i = 0; i < dim; i++) { + mp->m_min[i] = min[i]; + mp->m_max[i] = max[i]; + } + stack++; + stack->v_type = V_MAT; + stack->v_subtype = V_NOSUBTYPE; + stack->v_mat = mp; } S_FUNC void o_eleminit(FUNC *UNUSED(fp), long index) { - VALUE *vp; - STATIC VALUE *oldvp; - VALUE tmp; - OCTET *ptr; - BLOCK *blk; - unsigned short subtype; + VALUE *vp; + STATIC VALUE *oldvp; + VALUE tmp; + OCTET *ptr; + BLOCK *blk; + unsigned short subtype; - vp = &stack[-1]; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type < 0) { - freevalue(stack--); - error_value(E_INIT_01); - return; - } - if (vp->v_subtype & V_NOCOPYTO) { - freevalue(stack--); - error_value(E_INIT_02); - return; - } - switch (vp->v_type) { - case V_MAT: - if ((index < 0) || (index >= vp->v_mat->m_size)) { - freevalue(stack--); - error_value(E_INIT_03); - return; - } - oldvp = &vp->v_mat->m_table[index]; - break; - case V_OBJ: - if (index < 0 || index >= vp->v_obj->o_actions->oa_count) { - freevalue(stack--); - error_value(E_INIT_03); - return; - } - oldvp = &vp->v_obj->o_table[index]; - break; - case V_LIST: - oldvp = listfindex(vp->v_list, index); - if (oldvp == NULL) { - freevalue(stack--); - error_value(E_INIT_03); - return; - } - break; - case V_STR: - if (index < 0 || (size_t)index >= vp->v_str->s_len) { - freevalue(stack--); - error_value(E_INIT_03); - return; - } - ptr = (OCTET *)(&vp->v_str->s_str[index]); - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - copy2octet(vp, ptr); - freevalue(stack--); - return; - case V_NBLOCK: - case V_BLOCK: - if (vp->v_type == V_NBLOCK) { - blk = vp->v_nblock->blk; - if (blk->data == NULL) { - freevalue(stack--); - error_value(E_INIT_04); - return; - } - } - else - blk = vp->v_block; - if (index >= blk->maxsize) { - freevalue(stack--); - error_value(E_INIT_03); - return; - } - ptr = blk->data + index; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - copy2octet(vp, ptr); - if (index >= blk->datalen) - blk->datalen = index + 1; - freevalue(stack--); - return; - default: - freevalue(stack--); - error_value(E_INIT_05); - return; - } - vp = stack--; - subtype = oldvp->v_subtype; - if (subtype & V_NOASSIGNTO) { - freevalue(vp); - error_value(E_INIT_06); - return; - } - if (vp->v_type == V_ADDR) { - vp = vp->v_addr; - if (vp == oldvp) - return; - copyvalue(vp, &tmp); - } - else - tmp = *vp; - if ((subtype & V_NONEWVALUE) && comparevalue(oldvp, &tmp)) { - freevalue(&tmp); - error_value(E_INIT_07); - return; - } - if ((subtype & V_NONEWTYPE) && oldvp->v_type != tmp.v_type) { - freevalue(&tmp); - error_value(E_INIT_08); - return; - } - if ((subtype & V_NOERROR) && tmp.v_type < 0) { - error_value(E_INIT_09); - return; - } - if (tmp.v_subtype & (V_NOASSIGNFROM | V_NOCOPYFROM)) { - freevalue(&tmp); - error_value(E_INIT_10); - return; - } - tmp.v_subtype |= oldvp->v_subtype; - freevalue(oldvp); - *oldvp = tmp; + vp = &stack[-1]; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type < 0) { + freevalue(stack--); + error_value(E_INIT_01); + return; + } + if (vp->v_subtype & V_NOCOPYTO) { + freevalue(stack--); + error_value(E_INIT_02); + return; + } + switch (vp->v_type) { + case V_MAT: + if ((index < 0) || (index >= vp->v_mat->m_size)) { + freevalue(stack--); + error_value(E_INIT_03); + return; + } + oldvp = &vp->v_mat->m_table[index]; + break; + case V_OBJ: + if (index < 0 || index >= vp->v_obj->o_actions->oa_count) { + freevalue(stack--); + error_value(E_INIT_03); + return; + } + oldvp = &vp->v_obj->o_table[index]; + break; + case V_LIST: + oldvp = listfindex(vp->v_list, index); + if (oldvp == NULL) { + freevalue(stack--); + error_value(E_INIT_03); + return; + } + break; + case V_STR: + if (index < 0 || (size_t)index >= vp->v_str->s_len) { + freevalue(stack--); + error_value(E_INIT_03); + return; + } + ptr = (OCTET *)(&vp->v_str->s_str[index]); + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + copy2octet(vp, ptr); + freevalue(stack--); + return; + case V_NBLOCK: + case V_BLOCK: + if (vp->v_type == V_NBLOCK) { + blk = vp->v_nblock->blk; + if (blk->data == NULL) { + freevalue(stack--); + error_value(E_INIT_04); + return; + } + } + else + blk = vp->v_block; + if (index >= blk->maxsize) { + freevalue(stack--); + error_value(E_INIT_03); + return; + } + ptr = blk->data + index; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + copy2octet(vp, ptr); + if (index >= blk->datalen) + blk->datalen = index + 1; + freevalue(stack--); + return; + default: + freevalue(stack--); + error_value(E_INIT_05); + return; + } + vp = stack--; + subtype = oldvp->v_subtype; + if (subtype & V_NOASSIGNTO) { + freevalue(vp); + error_value(E_INIT_06); + return; + } + if (vp->v_type == V_ADDR) { + vp = vp->v_addr; + if (vp == oldvp) + return; + copyvalue(vp, &tmp); + } + else + tmp = *vp; + if ((subtype & V_NONEWVALUE) && comparevalue(oldvp, &tmp)) { + freevalue(&tmp); + error_value(E_INIT_07); + return; + } + if ((subtype & V_NONEWTYPE) && oldvp->v_type != tmp.v_type) { + freevalue(&tmp); + error_value(E_INIT_08); + return; + } + if ((subtype & V_NOERROR) && tmp.v_type < 0) { + error_value(E_INIT_09); + return; + } + if (tmp.v_subtype & (V_NOASSIGNFROM | V_NOCOPYFROM)) { + freevalue(&tmp); + error_value(E_INIT_10); + return; + } + tmp.v_subtype |= oldvp->v_subtype; + freevalue(oldvp); + *oldvp = tmp; } @@ -544,204 +544,204 @@ o_eleminit(FUNC *UNUSED(fp), long index) * o_indexaddr * * given: - * fp function to calculate - * dim dimension of matrix - * writeflag nonzero if element will be written + * fp function to calculate + * dim dimension of matrix + * writeflag nonzero if element will be written */ S_FUNC void o_indexaddr(FUNC *UNUSED(fp), long dim, long writeflag) { - int i; - bool flag; - VALUE *val; - VALUE *vp; - VALUE indices[MAXDIM]; /* index values */ - long index; /* single dimension index for blocks */ - VALUE ret; /* OCTET from as indexed from a block */ - BLOCK *blk; + int i; + bool flag; + VALUE *val; + VALUE *vp; + VALUE indices[MAXDIM]; /* index values */ + long index; /* single dimension index for blocks */ + VALUE ret; /* OCTET from as indexed from a block */ + BLOCK *blk; - flag = (writeflag != 0); - if (dim < 0) { - math_error("Negative dimension for indexing"); - not_reached(); - } - val = &stack[-dim]; - if (val->v_type != V_NBLOCK && val->v_type != V_FILE) { - if (val->v_type != V_ADDR) { - math_error("Non-pointer for indexaddr"); - not_reached(); - } - val = val->v_addr; - } - blk = NULL; - vp = &stack[-dim + 1]; - for (i = 0; i < dim; i++) { - if (vp->v_type == V_ADDR) - indices[i] = vp->v_addr[0]; - else - indices[i] = vp[0]; - vp++; - } + flag = (writeflag != 0); + if (dim < 0) { + math_error("Negative dimension for indexing"); + not_reached(); + } + val = &stack[-dim]; + if (val->v_type != V_NBLOCK && val->v_type != V_FILE) { + if (val->v_type != V_ADDR) { + math_error("Non-pointer for indexaddr"); + not_reached(); + } + val = val->v_addr; + } + blk = NULL; + vp = &stack[-dim + 1]; + for (i = 0; i < dim; i++) { + if (vp->v_type == V_ADDR) + indices[i] = vp->v_addr[0]; + else + indices[i] = vp[0]; + vp++; + } - switch (val->v_type) { - case V_MAT: - vp = matindex(val->v_mat, flag, dim, indices); - break; - case V_ASSOC: - vp = associndex(val->v_assoc, flag, dim, indices); - break; - case V_NBLOCK: - case V_BLOCK: - if (val->v_type == V_BLOCK) - blk = val->v_block; - else - blk = val->v_nblock->blk; - if (blk->data == NULL) { - math_error("Freed block"); - not_reached(); - } + switch (val->v_type) { + case V_MAT: + vp = matindex(val->v_mat, flag, dim, indices); + break; + case V_ASSOC: + vp = associndex(val->v_assoc, flag, dim, indices); + break; + case V_NBLOCK: + case V_BLOCK: + if (val->v_type == V_BLOCK) + blk = val->v_block; + else + blk = val->v_nblock->blk; + if (blk->data == NULL) { + math_error("Freed block"); + not_reached(); + } - /* - * obtain single dimensional block index - */ - if (dim != 1) { - math_error("block has only one dimension"); - not_reached(); - } - if (indices[0].v_type != V_NUM) { - math_error("Non-numeric index for block"); - not_reached(); - } - if (qisfrac(indices[0].v_num)) { - math_error("Non-integral index for block"); - not_reached(); - } - if (zge31b(indices[0].v_num->num) || - zisneg(indices[0].v_num->num)) { - math_error("Index out of bounds for block"); - not_reached(); - } - index = ztoi(indices[0].v_num->num); + /* + * obtain single dimensional block index + */ + if (dim != 1) { + math_error("block has only one dimension"); + not_reached(); + } + if (indices[0].v_type != V_NUM) { + math_error("Non-numeric index for block"); + not_reached(); + } + if (qisfrac(indices[0].v_num)) { + math_error("Non-integral index for block"); + not_reached(); + } + if (zge31b(indices[0].v_num->num) || + zisneg(indices[0].v_num->num)) { + math_error("Index out of bounds for block"); + not_reached(); + } + index = ztoi(indices[0].v_num->num); - if (index >= blk->maxsize) { - math_error("Index out of bounds for block"); - not_reached(); - } - if (index >= blk->datalen) - blk->datalen = index + 1; - ret.v_type = V_OCTET; - ret.v_subtype = val->v_subtype; - ret.v_octet = &blk->data[index]; - freevalue(stack--); - *stack = ret; - return; - case V_STR: - if (dim != 1) { - math_error("string has only one dimension"); - not_reached(); - } - if (indices[0].v_type != V_NUM) { - math_error("Non-numeric index for string"); - not_reached(); - } - if (qisfrac(indices[0].v_num)) { - math_error("Non-integral index for string"); - not_reached(); - } - if (zge31b(indices[0].v_num->num) || - zisneg(indices[0].v_num->num)) { - math_error("Index out of bounds for string"); - not_reached(); - } - index = ztoi(indices[0].v_num->num); - if (index < 0 || (size_t)index >= val->v_str->s_len) { - math_error("Index out of bounds for string"); - not_reached(); - } - ret.v_type = V_OCTET; - ret.v_subtype = val->v_subtype; - ret.v_octet = (OCTET *)(val->v_str->s_str + index); - freevalue(stack--); - *stack = ret; - return; - case V_LIST: - if (dim != 1) { - math_error("list has only one dimension"); - not_reached(); - } - if (indices[0].v_type != V_NUM) { - math_error("Non-numeric index for list"); - not_reached(); - } - if (qisfrac(indices[0].v_num)) { - math_error("Non-integral index for list"); - not_reached(); - } - if (zge31b(indices[0].v_num->num) || - zisneg(indices[0].v_num->num)) { - math_error("Index out of bounds for list"); - not_reached(); - } - index = ztoi(indices[0].v_num->num); - vp = listfindex(val->v_list, index); - if (vp == NULL) { - math_error("Index out of bounds for list"); - not_reached(); - } - break; - default: - math_error("Illegal value for indexing"); - not_reached(); - } - while (dim-- > 0) - freevalue(stack--); - stack->v_type = V_ADDR; - stack->v_addr = vp; + if (index >= blk->maxsize) { + math_error("Index out of bounds for block"); + not_reached(); + } + if (index >= blk->datalen) + blk->datalen = index + 1; + ret.v_type = V_OCTET; + ret.v_subtype = val->v_subtype; + ret.v_octet = &blk->data[index]; + freevalue(stack--); + *stack = ret; + return; + case V_STR: + if (dim != 1) { + math_error("string has only one dimension"); + not_reached(); + } + if (indices[0].v_type != V_NUM) { + math_error("Non-numeric index for string"); + not_reached(); + } + if (qisfrac(indices[0].v_num)) { + math_error("Non-integral index for string"); + not_reached(); + } + if (zge31b(indices[0].v_num->num) || + zisneg(indices[0].v_num->num)) { + math_error("Index out of bounds for string"); + not_reached(); + } + index = ztoi(indices[0].v_num->num); + if (index < 0 || (size_t)index >= val->v_str->s_len) { + math_error("Index out of bounds for string"); + not_reached(); + } + ret.v_type = V_OCTET; + ret.v_subtype = val->v_subtype; + ret.v_octet = (OCTET *)(val->v_str->s_str + index); + freevalue(stack--); + *stack = ret; + return; + case V_LIST: + if (dim != 1) { + math_error("list has only one dimension"); + not_reached(); + } + if (indices[0].v_type != V_NUM) { + math_error("Non-numeric index for list"); + not_reached(); + } + if (qisfrac(indices[0].v_num)) { + math_error("Non-integral index for list"); + not_reached(); + } + if (zge31b(indices[0].v_num->num) || + zisneg(indices[0].v_num->num)) { + math_error("Index out of bounds for list"); + not_reached(); + } + index = ztoi(indices[0].v_num->num); + vp = listfindex(val->v_list, index); + if (vp == NULL) { + math_error("Index out of bounds for list"); + not_reached(); + } + break; + default: + math_error("Illegal value for indexing"); + not_reached(); + } + while (dim-- > 0) + freevalue(stack--); + stack->v_type = V_ADDR; + stack->v_addr = vp; } S_FUNC void o_elemaddr(FUNC *UNUSED(fp), long index) { - VALUE *vp; - MATRIX *mp; - OBJECT *op; - int offset; + VALUE *vp; + MATRIX *mp; + OBJECT *op; + int offset; - vp = stack; - if (vp->v_type == V_ADDR) - vp = stack->v_addr; - switch (vp->v_type) { - case V_MAT: - mp = vp->v_mat; - if ((index < 0) || (index >= mp->m_size)) { - math_error("Non-existent element for matrix"); - not_reached(); - } - vp = &mp->m_table[index]; - break; - case V_OBJ: - op = vp->v_obj; - offset = objoffset(op, index); - if (offset < 0) { - math_error("Non-existent element for object"); - not_reached(); - } - vp = &op->o_table[offset]; - break; - case V_LIST: - vp = listfindex(vp->v_list, index); - if (vp == NULL) { - math_error("Index out of bounds for list"); - not_reached(); - } - break; - default: - math_error("Not initializing matrix, object or list"); - not_reached(); - } - stack->v_type = V_ADDR; - stack->v_addr = vp; + vp = stack; + if (vp->v_type == V_ADDR) + vp = stack->v_addr; + switch (vp->v_type) { + case V_MAT: + mp = vp->v_mat; + if ((index < 0) || (index >= mp->m_size)) { + math_error("Non-existent element for matrix"); + not_reached(); + } + vp = &mp->m_table[index]; + break; + case V_OBJ: + op = vp->v_obj; + offset = objoffset(op, index); + if (offset < 0) { + math_error("Non-existent element for object"); + not_reached(); + } + vp = &op->o_table[offset]; + break; + case V_LIST: + vp = listfindex(vp->v_list, index); + if (vp == NULL) { + math_error("Index out of bounds for list"); + not_reached(); + } + break; + default: + math_error("Not initializing matrix, object or list"); + not_reached(); + } + stack->v_type = V_ADDR; + stack->v_addr = vp; } @@ -749,1811 +749,1811 @@ o_elemaddr(FUNC *UNUSED(fp), long index) S_FUNC void o_elemvalue(FUNC *fp, long index) { - o_elemaddr(fp, index); - copyvalue(stack->v_addr, stack); + o_elemaddr(fp, index); + copyvalue(stack->v_addr, stack); } S_FUNC void o_objcreate(FUNC *UNUSED(fp), long arg) { - stack++; - stack->v_type = V_OBJ; - stack->v_subtype = V_NOSUBTYPE; - stack->v_obj = objalloc(arg); + stack++; + stack->v_type = V_OBJ; + stack->v_subtype = V_NOSUBTYPE; + stack->v_obj = objalloc(arg); } S_FUNC void o_assign(FUNC *UNUSED(fp)) { - VALUE *var; /* variable value */ - VALUE *vp; - VALUE tmp; - unsigned short subtype; - USB8 octet; + VALUE *var; /* variable value */ + VALUE *vp; + VALUE tmp; + unsigned short subtype; + USB8 octet; - /* - * get what we will store into - */ - var = &stack[-1]; + /* + * get what we will store into + */ + var = &stack[-1]; - /* - * If what we will store into is an OCTET, we must - * handle this specially. Only the bottom 8 bits of - * certain value types will be assigned ... not the - * entire value. - */ - if (var->v_type == V_OCTET) { - if (var->v_subtype & V_NOCOPYTO) { - freevalue(stack--); - *stack = error_value(E_ASSIGN_1); - return; - } - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_subtype & V_NOCOPYFROM || vp->v_type < 0) { - freevalue(stack--); - *stack = error_value(E_ASSIGN_2); - return; - } - copy2octet(vp, &octet); - freevalue(stack--); - if ((var->v_subtype & V_NONEWVALUE) && *var->v_octet != octet) { - *stack = error_value(E_ASSIGN_3); - return; - } - *var->v_octet = octet; - return; - } - if (var->v_type != V_ADDR) { - freevalue(stack--); - *stack = error_value(E_ASSIGN_4); - return; - } + /* + * If what we will store into is an OCTET, we must + * handle this specially. Only the bottom 8 bits of + * certain value types will be assigned ... not the + * entire value. + */ + if (var->v_type == V_OCTET) { + if (var->v_subtype & V_NOCOPYTO) { + freevalue(stack--); + *stack = error_value(E_ASSIGN_1); + return; + } + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_subtype & V_NOCOPYFROM || vp->v_type < 0) { + freevalue(stack--); + *stack = error_value(E_ASSIGN_2); + return; + } + copy2octet(vp, &octet); + freevalue(stack--); + if ((var->v_subtype & V_NONEWVALUE) && *var->v_octet != octet) { + *stack = error_value(E_ASSIGN_3); + return; + } + *var->v_octet = octet; + return; + } + if (var->v_type != V_ADDR) { + freevalue(stack--); + *stack = error_value(E_ASSIGN_4); + return; + } - var = var->v_addr; - subtype = var->v_subtype; - if (subtype & V_NOASSIGNTO) { - freevalue(stack--); - *stack = error_value(E_ASSIGN_5); - return; - } + var = var->v_addr; + subtype = var->v_subtype; + if (subtype & V_NOASSIGNTO) { + freevalue(stack--); + *stack = error_value(E_ASSIGN_5); + return; + } - vp = stack; + vp = stack; - if (var->v_type == V_OBJ) { - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - (void) objcall(OBJ_ASSIGN, var, vp, NULL_VALUE); - freevalue(stack--); - return; - } + if (var->v_type == V_OBJ) { + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + (void) objcall(OBJ_ASSIGN, var, vp, NULL_VALUE); + freevalue(stack--); + return; + } - stack--; + stack--; - /* - * Get what we will store from - * If what will store from is an address, make a copy - * of the de-referenced address instead. - */ - if (vp->v_type == V_ADDR) { - vp = vp->v_addr; - if (vp == var) - return; - if (vp->v_subtype & V_NOASSIGNFROM) { - *stack = error_value(E_ASSIGN_6); - return; - } - copyvalue(vp, &tmp); - } else if (vp->v_type == V_OCTET) { - copyvalue(vp, &tmp); - } else { - tmp = *vp; - } + /* + * Get what we will store from + * If what will store from is an address, make a copy + * of the de-referenced address instead. + */ + if (vp->v_type == V_ADDR) { + vp = vp->v_addr; + if (vp == var) + return; + if (vp->v_subtype & V_NOASSIGNFROM) { + *stack = error_value(E_ASSIGN_6); + return; + } + copyvalue(vp, &tmp); + } else if (vp->v_type == V_OCTET) { + copyvalue(vp, &tmp); + } else { + tmp = *vp; + } - /* - * Check protection - */ - if ((subtype & V_NONEWVALUE) && comparevalue(var, &tmp)) { - freevalue(&tmp); - *stack = error_value(E_ASSIGN_7); - return; - } - if ((subtype & V_NONEWTYPE) && var->v_type != tmp.v_type) { - freevalue(&tmp); - *stack = error_value(E_ASSIGN_8); - return; - } - if ((subtype & V_NOERROR) && tmp.v_type < 0) { - *stack = error_value(E_ASSIGN_9); - return; - } + /* + * Check protection + */ + if ((subtype & V_NONEWVALUE) && comparevalue(var, &tmp)) { + freevalue(&tmp); + *stack = error_value(E_ASSIGN_7); + return; + } + if ((subtype & V_NONEWTYPE) && var->v_type != tmp.v_type) { + freevalue(&tmp); + *stack = error_value(E_ASSIGN_8); + return; + } + if ((subtype & V_NOERROR) && tmp.v_type < 0) { + *stack = error_value(E_ASSIGN_9); + return; + } - /* - * perform the assignment - */ - freevalue(var); - *var = tmp; - var->v_subtype |= subtype; + /* + * perform the assignment + */ + freevalue(var); + *var = tmp; + var->v_subtype |= subtype; } S_FUNC void o_assignback(FUNC *fp) { - VALUE tmp; + VALUE tmp; - tmp = stack[-1]; - stack[-1] = stack[0]; - stack[0] = tmp; - o_assign(fp); + tmp = stack[-1]; + stack[-1] = stack[0]; + stack[0] = tmp; + o_assign(fp); } S_FUNC void o_assignpop(FUNC *fp) { - o_assign(fp); - stack--; + o_assign(fp); + stack--; } S_FUNC void o_ptr(FUNC *UNUSED(fp)) { - switch (stack->v_type) { - case V_ADDR: - stack->v_type = V_VPTR; - break; - case V_OCTET: - stack->v_type = V_OPTR; - break; - case V_STR: - sfree(stack->v_str); - stack->v_type = V_SPTR; - break; - case V_NUM: - qfree(stack->v_num); - stack->v_type = V_NPTR; - break; - default: - math_error("Addressing non-addressable type"); - not_reached(); - } + switch (stack->v_type) { + case V_ADDR: + stack->v_type = V_VPTR; + break; + case V_OCTET: + stack->v_type = V_OPTR; + break; + case V_STR: + sfree(stack->v_str); + stack->v_type = V_SPTR; + break; + case V_NUM: + qfree(stack->v_num); + stack->v_type = V_NPTR; + break; + default: + math_error("Addressing non-addressable type"); + not_reached(); + } } S_FUNC void o_deref(FUNC *UNUSED(fp)) { - VALUE *vp; + VALUE *vp; - vp = stack; + vp = stack; - if (stack->v_type == V_OCTET) { - stack->v_num = itoq(*vp->v_octet); - stack->v_type = V_NUM; - return; - } - if (stack->v_type == V_OPTR) { - stack->v_type = V_OCTET; - return; - } - if (stack->v_type == V_VPTR) { - stack->v_type = V_ADDR; - return; - } - if (stack->v_type == V_SPTR) { - stack->v_type = V_STR; - return; - } - if (stack->v_type == V_NPTR) { - if (stack->v_num->links == 0) { - stack->v_type = V_NULL; - return; - } - stack->v_type = V_NUM; - stack->v_num->links++; - return; - } - if (stack->v_type != V_ADDR) { - math_error("Dereferencing a non-variable"); - not_reached(); - } - vp = vp->v_addr; - switch (vp->v_type) { - case V_ADDR: - case V_OCTET: - *stack = *vp; - break; - case V_OPTR: - *stack = *vp; - stack->v_type = V_OCTET; - break; - case V_VPTR: - *stack = *vp; - stack->v_type = V_ADDR; - break; - case V_SPTR: - *stack = *vp; - stack->v_type = V_STR; - break; - case V_NPTR: - if (vp->v_num->links == 0) { - stack->v_type = V_NULL; - break; - } - stack->v_type = V_NUM; - stack->v_num = vp->v_num; - stack->v_num->links++; - break; - default: - copyvalue(vp, stack); - } + if (stack->v_type == V_OCTET) { + stack->v_num = itoq(*vp->v_octet); + stack->v_type = V_NUM; + return; + } + if (stack->v_type == V_OPTR) { + stack->v_type = V_OCTET; + return; + } + if (stack->v_type == V_VPTR) { + stack->v_type = V_ADDR; + return; + } + if (stack->v_type == V_SPTR) { + stack->v_type = V_STR; + return; + } + if (stack->v_type == V_NPTR) { + if (stack->v_num->links == 0) { + stack->v_type = V_NULL; + return; + } + stack->v_type = V_NUM; + stack->v_num->links++; + return; + } + if (stack->v_type != V_ADDR) { + math_error("Dereferencing a non-variable"); + not_reached(); + } + vp = vp->v_addr; + switch (vp->v_type) { + case V_ADDR: + case V_OCTET: + *stack = *vp; + break; + case V_OPTR: + *stack = *vp; + stack->v_type = V_OCTET; + break; + case V_VPTR: + *stack = *vp; + stack->v_type = V_ADDR; + break; + case V_SPTR: + *stack = *vp; + stack->v_type = V_STR; + break; + case V_NPTR: + if (vp->v_num->links == 0) { + stack->v_type = V_NULL; + break; + } + stack->v_type = V_NUM; + stack->v_num = vp->v_num; + stack->v_num->links++; + break; + default: + copyvalue(vp, stack); + } } S_FUNC void o_swap(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; /* variables to be swapped */ - VALUE tmp; - USB8 usb; + VALUE *v1, *v2; /* variables to be swapped */ + VALUE tmp; + USB8 usb; - v1 = stack--; - v2 = stack; + v1 = stack--; + v2 = stack; - if (v1->v_type == V_OCTET && v2->v_type == V_OCTET) { - if (v1->v_octet != v2->v_octet && - ((v1->v_subtype | v2->v_subtype) & - (V_NOCOPYTO | V_NOCOPYFROM))) { - *stack = error_value(E_SWAP_1); - return; - } - usb = *v1->v_octet; - *v1->v_octet = *v2->v_octet; - *v2->v_octet = usb; - } else if (v1->v_type == V_ADDR && v2->v_type == V_ADDR) { - v1 = v1->v_addr; - v2 = v2->v_addr; - if (v1 != v2 && ((v1->v_subtype | v2->v_subtype) & - (V_NOASSIGNTO | V_NOASSIGNFROM))) { - *stack = error_value(E_SWAP_2); - return; - } - tmp = *v1; - *v1 = *v2; - *v2 = tmp; - } else { - *stack = error_value(E_SWAP_3); - return; - } - stack->v_type = V_NULL; - stack->v_subtype = V_NOSUBTYPE; + if (v1->v_type == V_OCTET && v2->v_type == V_OCTET) { + if (v1->v_octet != v2->v_octet && + ((v1->v_subtype | v2->v_subtype) & + (V_NOCOPYTO | V_NOCOPYFROM))) { + *stack = error_value(E_SWAP_1); + return; + } + usb = *v1->v_octet; + *v1->v_octet = *v2->v_octet; + *v2->v_octet = usb; + } else if (v1->v_type == V_ADDR && v2->v_type == V_ADDR) { + v1 = v1->v_addr; + v2 = v2->v_addr; + if (v1 != v2 && ((v1->v_subtype | v2->v_subtype) & + (V_NOASSIGNTO | V_NOASSIGNFROM))) { + *stack = error_value(E_SWAP_2); + return; + } + tmp = *v1; + *v1 = *v2; + *v2 = tmp; + } else { + *stack = error_value(E_SWAP_3); + return; + } + stack->v_type = V_NULL; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_add(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; - VALUE w1, w2; + VALUE *v1, *v2; + VALUE tmp; + VALUE w1, w2; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if (v1->v_type == V_OCTET) { - w1.v_type = V_NUM; - w1.v_subtype = V_NOSUBTYPE; - w1.v_num = itoq(*v1->v_octet); - v1 = &w1; - } - if (v2->v_type == V_OCTET) { - w2.v_type = V_NUM; - w2.v_subtype = V_NOSUBTYPE; - w2.v_num = itoq(*v2->v_octet); - v2 = &w2; - } + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if (v1->v_type == V_OCTET) { + w1.v_type = V_NUM; + w1.v_subtype = V_NOSUBTYPE; + w1.v_num = itoq(*v1->v_octet); + v1 = &w1; + } + if (v2->v_type == V_OCTET) { + w2.v_type = V_NUM; + w2.v_subtype = V_NOSUBTYPE; + w2.v_num = itoq(*v2->v_octet); + v2 = &w2; + } - addvalue(v1, v2, &tmp); - if (v1 == &w1) - qfree(w1.v_num); - if (v2 == &w2) - qfree(w2.v_num); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + addvalue(v1, v2, &tmp); + if (v1 == &w1) + qfree(w1.v_num); + if (v2 == &w2) + qfree(w2.v_num); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_sub(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; - VALUE w1, w2; + VALUE *v1, *v2; + VALUE tmp; + VALUE w1, w2; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if (v1->v_type == V_OCTET) { - w1.v_type = V_NUM; - w1.v_subtype = V_NOSUBTYPE; - w1.v_num = itoq((unsigned char) *v1->v_octet); - v1 = &w1; - } - if (v2->v_type == V_OCTET) { - w2.v_type = V_NUM; - w2.v_subtype = V_NOSUBTYPE; - w2.v_num = itoq((unsigned char) *v2->v_octet); - v2 = &w2; - } + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if (v1->v_type == V_OCTET) { + w1.v_type = V_NUM; + w1.v_subtype = V_NOSUBTYPE; + w1.v_num = itoq((unsigned char) *v1->v_octet); + v1 = &w1; + } + if (v2->v_type == V_OCTET) { + w2.v_type = V_NUM; + w2.v_subtype = V_NOSUBTYPE; + w2.v_num = itoq((unsigned char) *v2->v_octet); + v2 = &w2; + } - subvalue(v1, v2, &tmp); - if (v1 == &w1) - qfree(w1.v_num); - if (v2 == &w2) - qfree(w2.v_num); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + subvalue(v1, v2, &tmp); + if (v1 == &w1) + qfree(w1.v_num); + if (v2 == &w2) + qfree(w2.v_num); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_mul(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; - VALUE w1, w2; + VALUE *v1, *v2; + VALUE tmp; + VALUE w1, w2; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if (v1->v_type == V_OCTET) { - w1.v_type = V_NUM; - w1.v_subtype = V_NOSUBTYPE; - w1.v_num = itoq(*v1->v_octet); - v1 = &w1; - } - if (v2->v_type == V_OCTET) { - w2.v_type = V_NUM; - w2.v_subtype = V_NOSUBTYPE; - w2.v_num = itoq(*v2->v_octet); - v2 = &w2; - } - mulvalue(v1, v2, &tmp); - if (v1 == &w1) - qfree(w1.v_num); - if (v2 == &w2) - qfree(w2.v_num); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if (v1->v_type == V_OCTET) { + w1.v_type = V_NUM; + w1.v_subtype = V_NOSUBTYPE; + w1.v_num = itoq(*v1->v_octet); + v1 = &w1; + } + if (v2->v_type == V_OCTET) { + w2.v_type = V_NUM; + w2.v_subtype = V_NOSUBTYPE; + w2.v_num = itoq(*v2->v_octet); + v2 = &w2; + } + mulvalue(v1, v2, &tmp); + if (v1 == &w1) + qfree(w1.v_num); + if (v2 == &w2) + qfree(w2.v_num); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_power(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - powvalue(v1, v2, &tmp); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + powvalue(v1, v2, &tmp); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_div(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; - VALUE w1, w2; + VALUE *v1, *v2; + VALUE tmp; + VALUE w1, w2; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if (v1->v_type == V_OCTET) { - w1.v_type = V_NUM; - w1.v_subtype = V_NOSUBTYPE; - w1.v_num = itoq(*v1->v_octet); - v1 = &w1; - } - if (v2->v_type == V_OCTET) { - w2.v_type = V_NUM; - w2.v_subtype = V_NOSUBTYPE; - w2.v_num = itoq(*v2->v_octet); - v2 = &w2; - } - divvalue(v1, v2, &tmp); - if (v1 == &w1) - qfree(w1.v_num); - if (v2 == &w2) - qfree(w2.v_num); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if (v1->v_type == V_OCTET) { + w1.v_type = V_NUM; + w1.v_subtype = V_NOSUBTYPE; + w1.v_num = itoq(*v1->v_octet); + v1 = &w1; + } + if (v2->v_type == V_OCTET) { + w2.v_type = V_NUM; + w2.v_subtype = V_NOSUBTYPE; + w2.v_num = itoq(*v2->v_octet); + v2 = &w2; + } + divvalue(v1, v2, &tmp); + if (v1 == &w1) + qfree(w1.v_num); + if (v2 == &w2) + qfree(w2.v_num); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_quo(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp, null; + VALUE *v1, *v2; + VALUE tmp, null; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - null.v_type = V_NULL; - null.v_subtype = V_NOSUBTYPE; - quovalue(v1, v2, &null, &tmp); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + null.v_type = V_NULL; + null.v_subtype = V_NOSUBTYPE; + quovalue(v1, v2, &null, &tmp); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_mod(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp, null; + VALUE *v1, *v2; + VALUE tmp, null; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - null.v_type = V_NULL; - null.v_subtype = V_NOSUBTYPE; - modvalue(v1, v2, &null, &tmp); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + null.v_type = V_NULL; + null.v_subtype = V_NOSUBTYPE; + modvalue(v1, v2, &null, &tmp); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_and(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; - andvalue(v1, v2, &tmp); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + andvalue(v1, v2, &tmp); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_or(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; - orvalue(v1, v2, &tmp); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + orvalue(v1, v2, &tmp); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_xor(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; + v1 = &stack[-1]; + v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; - xorvalue(v1, v2, &tmp); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + xorvalue(v1, v2, &tmp); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_comp(FUNC *UNUSED(fp)) { - VALUE *vp; - VALUE tmp; + VALUE *vp; + VALUE tmp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - compvalue(vp, &tmp); - freevalue(stack); - *stack = tmp; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + compvalue(vp, &tmp); + freevalue(stack); + *stack = tmp; } S_FUNC void o_not(FUNC *UNUSED(fp)) { - VALUE *vp; - VALUE val; - int r = 0; + VALUE *vp; + VALUE val; + int r = 0; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type == V_OBJ) { - val = objcall(OBJ_NOT, vp, NULL_VALUE, NULL_VALUE); - freevalue(stack); - *stack = val; - return; - } - r = testvalue(vp); - freevalue(stack); - stack->v_num = (r ? qlink(&_qzero_) : qlink(&_qone_)); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type == V_OBJ) { + val = objcall(OBJ_NOT, vp, NULL_VALUE, NULL_VALUE); + freevalue(stack); + *stack = val; + return; + } + r = testvalue(vp); + freevalue(stack); + stack->v_num = (r ? qlink(&_qzero_) : qlink(&_qone_)); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_plus(FUNC *UNUSED(fp)) { - VALUE *vp; - VALUE tmp; + VALUE *vp; + VALUE tmp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; - tmp.v_type = V_NULL; - tmp.v_subtype = V_NOSUBTYPE; - switch (vp->v_type) { - case V_OBJ: - tmp = objcall(OBJ_PLUS, vp, NULL_VALUE, NULL_VALUE); - break; - case V_LIST: - addlistitems(vp->v_list, &tmp); - break; - default: - return; - } - freevalue(stack); - *stack = tmp; + tmp.v_type = V_NULL; + tmp.v_subtype = V_NOSUBTYPE; + switch (vp->v_type) { + case V_OBJ: + tmp = objcall(OBJ_PLUS, vp, NULL_VALUE, NULL_VALUE); + break; + case V_LIST: + addlistitems(vp->v_list, &tmp); + break; + default: + return; + } + freevalue(stack); + *stack = tmp; } S_FUNC void o_negate(FUNC *UNUSED(fp)) { - VALUE *vp; - NUMBER *q; - VALUE tmp; + VALUE *vp; + NUMBER *q; + VALUE tmp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type == V_NUM) { - q = qneg(vp->v_num); - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack->v_num = q; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - return; - } - negvalue(vp, &tmp); - freevalue(stack); - *stack = tmp; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type == V_NUM) { + q = qneg(vp->v_num); + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack->v_num = q; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + return; + } + negvalue(vp, &tmp); + freevalue(stack); + *stack = tmp; } S_FUNC void o_invert(FUNC *UNUSED(fp)) { - VALUE *vp; - VALUE tmp; + VALUE *vp; + VALUE tmp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; - invertvalue(vp, &tmp); - freevalue(stack); - *stack = tmp; + invertvalue(vp, &tmp); + freevalue(stack); + *stack = tmp; } S_FUNC void o_scale(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[0]; - v2 = &stack[-1]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - scalevalue(v2, v1, &tmp); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + v1 = &stack[0]; + v2 = &stack[-1]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + scalevalue(v2, v1, &tmp); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_int(FUNC *UNUSED(fp)) { - VALUE *vp; - VALUE tmp; + VALUE *vp; + VALUE tmp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - intvalue(vp, &tmp); - freevalue(stack); - *stack = tmp; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + intvalue(vp, &tmp); + freevalue(stack); + *stack = tmp; } S_FUNC void o_frac(FUNC *UNUSED(fp)) { - VALUE *vp; - VALUE tmp; + VALUE *vp; + VALUE tmp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - fracvalue(vp, &tmp); - freevalue(stack); - *stack = tmp; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + fracvalue(vp, &tmp); + freevalue(stack); + *stack = tmp; } S_FUNC void o_abs(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - NUMBER *q; - VALUE tmp; + VALUE *v1, *v2; + NUMBER *q; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if ((v1->v_type != V_NUM) || (v2->v_type != V_NUM) || - !qispos(v2->v_num)) { - absvalue(v1, v2, &tmp); - freevalue(stack--); - freevalue(stack); - *stack = tmp; - return; - } - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack--; - if ((stack->v_type == V_NUM) && !qisneg(v1->v_num)) - return; - q = qqabs(v1->v_num); - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack->v_num = q; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if ((v1->v_type != V_NUM) || (v2->v_type != V_NUM) || + !qispos(v2->v_num)) { + absvalue(v1, v2, &tmp); + freevalue(stack--); + freevalue(stack); + *stack = tmp; + return; + } + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack--; + if ((stack->v_type == V_NUM) && !qisneg(v1->v_num)) + return; + q = qqabs(v1->v_num); + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack->v_num = q; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_norm(FUNC *UNUSED(fp)) { - VALUE *vp; - NUMBER *q; - VALUE tmp; + VALUE *vp; + NUMBER *q; + VALUE tmp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type == V_NUM) { - q = qsquare(vp->v_num); - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack->v_num = q; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - return; - } - normvalue(vp, &tmp); - freevalue(stack); - *stack = tmp; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type == V_NUM) { + q = qsquare(vp->v_num); + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack->v_num = q; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + return; + } + normvalue(vp, &tmp); + freevalue(stack); + *stack = tmp; } S_FUNC void o_square(FUNC *UNUSED(fp)) { - VALUE *vp; - NUMBER *q; - VALUE tmp; + VALUE *vp; + NUMBER *q; + VALUE tmp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type == V_NUM) { - q = qsquare(vp->v_num); - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack->v_num = q; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - return; - } - squarevalue(vp, &tmp); - freevalue(stack); - *stack = tmp; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type == V_NUM) { + q = qsquare(vp->v_num); + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack->v_num = q; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + return; + } + squarevalue(vp, &tmp); + freevalue(stack); + *stack = tmp; } S_FUNC void o_test(FUNC *UNUSED(fp)) { - VALUE *vp; - int i; + VALUE *vp; + int i; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - i = testvalue(vp); - freevalue(stack); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - stack->v_num = i ? qlink(&_qone_) : qlink(&_qzero_); + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + i = testvalue(vp); + freevalue(stack); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + stack->v_num = i ? qlink(&_qone_) : qlink(&_qzero_); } S_FUNC void o_links(FUNC *UNUSED(fp)) { - VALUE *vp; - long links; - bool haveaddress; + VALUE *vp; + long links; + bool haveaddress; - vp = stack; - haveaddress = (vp->v_type == V_ADDR); - if (haveaddress) - vp = vp->v_addr; - switch (vp->v_type) { - case V_NUM: links = vp->v_num->links; break; - case V_COM: links = vp->v_com->links; break; - case V_STR: links = vp->v_str->s_links; break; - default: - freevalue(stack); - return; - } - if (links <= 0) { - math_error("Non-positive links!!!"); - not_reached(); - } - freevalue(stack); - if (!haveaddress) - links--; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - stack->v_num = itoq(links); + vp = stack; + haveaddress = (vp->v_type == V_ADDR); + if (haveaddress) + vp = vp->v_addr; + switch (vp->v_type) { + case V_NUM: links = vp->v_num->links; break; + case V_COM: links = vp->v_com->links; break; + case V_STR: links = vp->v_str->s_links; break; + default: + freevalue(stack); + return; + } + if (links <= 0) { + math_error("Non-positive links!!!"); + not_reached(); + } + freevalue(stack); + if (!haveaddress) + links--; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + stack->v_num = itoq(links); } S_FUNC void o_bit(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - long index; - int r; + VALUE *v1, *v2; + long index; + int r; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if (v2->v_type != V_NUM || qisfrac(v2->v_num)) { - freevalue(stack--); - freevalue(stack); - *stack = error_value(E_BIT_1); - return; - } - if (zge31b(v2->v_num->num)) { - freevalue(stack--); - freevalue(stack); - *stack = error_value(E_BIT_2); - return; - } - index = qtoi(v2->v_num); - switch (v1->v_type) { - case V_NUM: - r = qisset(v1->v_num, index); - break; - case V_STR: - r = stringbit(v1->v_str, index); - break; - default: - r = 2; - } - freevalue(stack--); - freevalue(stack); - if (r > 1) { - *stack = error_value(E_BIT_1); - } else if (r < 0) { - stack->v_type = V_NULL; - } else { - stack->v_type = V_NUM; - stack->v_num = itoq(r); - } - stack->v_subtype = V_NOSUBTYPE; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if (v2->v_type != V_NUM || qisfrac(v2->v_num)) { + freevalue(stack--); + freevalue(stack); + *stack = error_value(E_BIT_1); + return; + } + if (zge31b(v2->v_num->num)) { + freevalue(stack--); + freevalue(stack); + *stack = error_value(E_BIT_2); + return; + } + index = qtoi(v2->v_num); + switch (v1->v_type) { + case V_NUM: + r = qisset(v1->v_num, index); + break; + case V_STR: + r = stringbit(v1->v_str, index); + break; + default: + r = 2; + } + freevalue(stack--); + freevalue(stack); + if (r > 1) { + *stack = error_value(E_BIT_1); + } else if (r < 0) { + stack->v_type = V_NULL; + } else { + stack->v_type = V_NUM; + stack->v_num = itoq(r); + } + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_highbit(FUNC *UNUSED(fp)) { - VALUE *vp; - long index; - unsigned int u; + VALUE *vp; + long index; + unsigned int u; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - switch (vp->v_type) { - case V_NUM: - if (qiszero(vp->v_num)) { - index = -1; - break; - } - if (qisfrac(vp->v_num)) { - index = -2; - break; - } - index = zhighbit(vp->v_num->num); - break; - case V_STR: - index = stringhighbit(vp->v_str); - break; - case V_OCTET: - u = *vp->v_octet; - for (index = -1; u; u >>= 1, ++index); - break; - default: - index = -3; - } - freevalue(stack); - switch (index) { - case -3: - *stack = error_value(E_HIGHBIT_1); - return; - case -2: - *stack = error_value(E_HIGHBIT_2); - return; - default: - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - stack->v_num = itoq(index); - } + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + switch (vp->v_type) { + case V_NUM: + if (qiszero(vp->v_num)) { + index = -1; + break; + } + if (qisfrac(vp->v_num)) { + index = -2; + break; + } + index = zhighbit(vp->v_num->num); + break; + case V_STR: + index = stringhighbit(vp->v_str); + break; + case V_OCTET: + u = *vp->v_octet; + for (index = -1; u; u >>= 1, ++index); + break; + default: + index = -3; + } + freevalue(stack); + switch (index) { + case -3: + *stack = error_value(E_HIGHBIT_1); + return; + case -2: + *stack = error_value(E_HIGHBIT_2); + return; + default: + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + stack->v_num = itoq(index); + } } S_FUNC void o_lowbit(FUNC *UNUSED(fp)) { - VALUE *vp; - long index; - unsigned int u; + VALUE *vp; + long index; + unsigned int u; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - switch (vp->v_type) { - case V_NUM: - if (qiszero(vp->v_num)) { - index = -1; - break; - } - if (qisfrac(vp->v_num)) { - index = -2; - break; - } - index = zlowbit(vp->v_num->num); - break; - case V_STR: - index = stringlowbit(vp->v_str); - break; - case V_OCTET: - u = *vp->v_octet; - index = -1; - if (u) do { - ++index; - u >>= 1; - } while (!(u & 1)); - break; - default: - index = -3; - } - freevalue(stack); - switch (index) { - case -3: - *stack = error_value(E_LOWBIT_1); - return; - case -2: - *stack = error_value(E_LOWBIT_2); - return; - default: - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - stack->v_num = itoq(index); - } + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + switch (vp->v_type) { + case V_NUM: + if (qiszero(vp->v_num)) { + index = -1; + break; + } + if (qisfrac(vp->v_num)) { + index = -2; + break; + } + index = zlowbit(vp->v_num->num); + break; + case V_STR: + index = stringlowbit(vp->v_str); + break; + case V_OCTET: + u = *vp->v_octet; + index = -1; + if (u) do { + ++index; + u >>= 1; + } while (!(u & 1)); + break; + default: + index = -3; + } + freevalue(stack); + switch (index) { + case -3: + *stack = error_value(E_LOWBIT_1); + return; + case -2: + *stack = error_value(E_LOWBIT_2); + return; + default: + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + stack->v_num = itoq(index); + } } S_FUNC void o_content(FUNC *UNUSED(fp)) { - VALUE *vp; - VALUE tmp; + VALUE *vp; + VALUE tmp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - contentvalue(vp, &tmp); - freevalue(stack); - *stack = tmp; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + contentvalue(vp, &tmp); + freevalue(stack); + *stack = tmp; } S_FUNC void o_hashop(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - hashopvalue(v1, v2, &tmp); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + hashopvalue(v1, v2, &tmp); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_backslash(FUNC *UNUSED(fp)) { - VALUE *vp; - VALUE tmp; + VALUE *vp; + VALUE tmp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - backslashvalue(vp, &tmp); - freevalue(stack); - *stack = tmp; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + backslashvalue(vp, &tmp); + freevalue(stack); + *stack = tmp; } S_FUNC void o_setminus(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - setminusvalue(v1, v2, &tmp); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + setminusvalue(v1, v2, &tmp); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_istype(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - int r; + VALUE *v1, *v2; + int r; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if ((v1->v_type != V_OBJ) || (v2->v_type != V_OBJ)) - r = (v1->v_type == v2->v_type); - else - r = (v1->v_obj->o_actions == v2->v_obj->o_actions); - freevalue(stack--); - freevalue(stack); - stack->v_num = itoq((long) r); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if ((v1->v_type != V_OBJ) || (v2->v_type != V_OBJ)) + r = (v1->v_type == v2->v_type); + else + r = (v1->v_obj->o_actions == v2->v_obj->o_actions); + freevalue(stack--); + freevalue(stack); + stack->v_num = itoq((long) r); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isint(FUNC *UNUSED(fp)) { - VALUE *vp; - NUMBER *q; + VALUE *vp; + NUMBER *q; - vp = stack; - if (vp->v_type == V_ADDR) - vp = stack->v_addr; - if (vp->v_type != V_NUM) { - freevalue(stack); - stack->v_num = qlink(&_qzero_); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - return; - } - if (qisint(vp->v_num)) - q = qlink(&_qone_); - else - q = qlink(&_qzero_); - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack->v_num = q; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = stack->v_addr; + if (vp->v_type != V_NUM) { + freevalue(stack); + stack->v_num = qlink(&_qzero_); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + return; + } + if (qisint(vp->v_num)) + q = qlink(&_qone_); + else + q = qlink(&_qzero_); + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack->v_num = q; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isnum(FUNC *UNUSED(fp)) { - VALUE *vp; + VALUE *vp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - switch (vp->v_type) { - case V_NUM: - if (stack->v_type == V_NUM) - qfree(stack->v_num); - break; - case V_COM: - if (stack->v_type == V_COM) - comfree(stack->v_com); - break; - default: - freevalue(stack); - stack->v_num = qlink(&_qzero_); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - return; - } - stack->v_num = qlink(&_qone_); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + switch (vp->v_type) { + case V_NUM: + if (stack->v_type == V_NUM) + qfree(stack->v_num); + break; + case V_COM: + if (stack->v_type == V_COM) + comfree(stack->v_com); + break; + default: + freevalue(stack); + stack->v_num = qlink(&_qzero_); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + return; + } + stack->v_num = qlink(&_qone_); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_ismat(FUNC *UNUSED(fp)) { - VALUE *vp; + VALUE *vp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type != V_MAT) { - freevalue(stack); - stack->v_num = qlink(&_qzero_); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - return; - } - freevalue(stack); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - stack->v_num = qlink(&_qone_); + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type != V_MAT) { + freevalue(stack); + stack->v_num = qlink(&_qzero_); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + return; + } + freevalue(stack); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + stack->v_num = qlink(&_qone_); } S_FUNC void o_islist(FUNC *UNUSED(fp)) { - VALUE *vp; - int r; + VALUE *vp; + int r; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - r = (vp->v_type == V_LIST); - freevalue(stack); - stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + r = (vp->v_type == V_LIST); + freevalue(stack); + stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isobj(FUNC *UNUSED(fp)) { - VALUE *vp; - int r; + VALUE *vp; + int r; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - r = (vp->v_type == V_OBJ); - freevalue(stack); - stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + r = (vp->v_type == V_OBJ); + freevalue(stack); + stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isstr(FUNC *UNUSED(fp)) { - VALUE *vp; - int r; + VALUE *vp; + int r; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - r = (vp->v_type == V_STR); - freevalue(stack); - stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + r = (vp->v_type == V_STR); + freevalue(stack); + stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isfile(FUNC *UNUSED(fp)) { - VALUE *vp; - int r; + VALUE *vp; + int r; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - r = (vp->v_type == V_FILE); - freevalue(stack); - stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + r = (vp->v_type == V_FILE); + freevalue(stack); + stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isrand(FUNC *UNUSED(fp)) { - VALUE *vp; - int r; + VALUE *vp; + int r; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - r = (vp->v_type == V_RAND); - freevalue(stack); - stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + r = (vp->v_type == V_RAND); + freevalue(stack); + stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_israndom(FUNC *UNUSED(fp)) { - VALUE *vp; - int r; + VALUE *vp; + int r; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - r = (vp->v_type == V_RANDOM); - freevalue(stack); - stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + r = (vp->v_type == V_RANDOM); + freevalue(stack); + stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isconfig(FUNC *UNUSED(fp)) { - VALUE *vp; - int r; + VALUE *vp; + int r; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - r = (vp->v_type == V_CONFIG); - freevalue(stack); - stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + r = (vp->v_type == V_CONFIG); + freevalue(stack); + stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_ishash(FUNC *UNUSED(fp)) { - VALUE *vp; - int r; + VALUE *vp; + int r; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - r = (vp->v_type == V_HASH); - if (r != 0) - r = vp->v_hash->hashtype; - freevalue(stack); - stack->v_num = itoq((long) r); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + r = (vp->v_type == V_HASH); + if (r != 0) + r = vp->v_hash->hashtype; + freevalue(stack); + stack->v_num = itoq((long) r); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isassoc(FUNC *UNUSED(fp)) { - VALUE *vp; - int r; + VALUE *vp; + int r; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - r = (vp->v_type == V_ASSOC); - freevalue(stack); - stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + r = (vp->v_type == V_ASSOC); + freevalue(stack); + stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isblock(FUNC *UNUSED(fp)) { - VALUE *vp; - long r; + VALUE *vp; + long r; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - r = 0; - if (vp->v_type == V_NBLOCK) - r = 2; - else if (vp->v_type == V_BLOCK) - r = 1; - freevalue(stack); - stack->v_num = itoq(r); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + r = 0; + if (vp->v_type == V_NBLOCK) + r = 2; + else if (vp->v_type == V_BLOCK) + r = 1; + freevalue(stack); + stack->v_num = itoq(r); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isoctet(FUNC *UNUSED(fp)) { - VALUE *vp; - long r; + VALUE *vp; + long r; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - r = (vp->v_type == V_OCTET); - freevalue(stack); - stack->v_num = itoq(r); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + r = (vp->v_type == V_OCTET); + freevalue(stack); + stack->v_num = itoq(r); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isptr(FUNC *UNUSED(fp)) { - VALUE *vp; - long r; + VALUE *vp; + long r; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - r = 0; - switch(vp->v_type) { - case V_OPTR: r = 1; break; - case V_VPTR: r = 2; break; - case V_SPTR: r = 3; break; - case V_NPTR: r = 4; break; - } - freevalue(stack); - stack->v_num = itoq(r); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + r = 0; + switch(vp->v_type) { + case V_OPTR: r = 1; break; + case V_VPTR: r = 2; break; + case V_SPTR: r = 3; break; + case V_NPTR: r = 4; break; + } + freevalue(stack); + stack->v_num = itoq(r); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isdefined(FUNC *UNUSED(fp)) { - VALUE *vp; - long r; - long index; + VALUE *vp; + long r; + long index; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type != V_STR) { - math_error("Non-string argument for isdefined"); - not_reached(); - } - r = 0; - index = getbuiltinfunc(vp->v_str->s_str); - if (index >= 0) { - r = 1; - } else { - index = getuserfunc(vp->v_str->s_str); - if (index >= 0) - r = 2; - } - freevalue(stack); - stack->v_num = itoq(r); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type != V_STR) { + math_error("Non-string argument for isdefined"); + not_reached(); + } + r = 0; + index = getbuiltinfunc(vp->v_str->s_str); + if (index >= 0) { + r = 1; + } else { + index = getuserfunc(vp->v_str->s_str); + if (index >= 0) + r = 2; + } + freevalue(stack); + stack->v_num = itoq(r); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isobjtype(FUNC *UNUSED(fp)) { - VALUE *vp; - long index; + VALUE *vp; + long index; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type != V_STR) { - math_error("Non-string argument for isobjtype"); - not_reached(); - } - index = checkobject(vp->v_str->s_str); - freevalue(stack); - stack->v_num = itoq(index >= 0); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type != V_STR) { + math_error("Non-string argument for isobjtype"); + not_reached(); + } + index = checkobject(vp->v_str->s_str); + freevalue(stack); + stack->v_num = itoq(index >= 0); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_issimple(FUNC *UNUSED(fp)) { - VALUE *vp; - int r; + VALUE *vp; + int r; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - r = 0; - switch (vp->v_type) { - case V_NULL: - case V_NUM: - case V_COM: - case V_STR: - r = 1; - } - freevalue(stack); - stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + r = 0; + switch (vp->v_type) { + case V_NULL: + case V_NUM: + case V_COM: + case V_STR: + r = 1; + } + freevalue(stack); + stack->v_num = (r ? qlink(&_qone_) : qlink(&_qzero_)); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isodd(FUNC *UNUSED(fp)) { - VALUE *vp; + VALUE *vp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if ((vp->v_type == V_NUM) && qisodd(vp->v_num)) { - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack->v_num = qlink(&_qone_); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - return; - } - freevalue(stack); - stack->v_num = qlink(&_qzero_); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if ((vp->v_type == V_NUM) && qisodd(vp->v_num)) { + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack->v_num = qlink(&_qone_); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + return; + } + freevalue(stack); + stack->v_num = qlink(&_qzero_); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_iseven(FUNC *UNUSED(fp)) { - VALUE *vp; + VALUE *vp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if ((vp->v_type == V_NUM) && qiseven(vp->v_num)) { - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack->v_num = qlink(&_qone_); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - return; - } - freevalue(stack); - stack->v_num = qlink(&_qzero_); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if ((vp->v_type == V_NUM) && qiseven(vp->v_num)) { + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack->v_num = qlink(&_qone_); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + return; + } + freevalue(stack); + stack->v_num = qlink(&_qzero_); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isreal(FUNC *UNUSED(fp)) { - VALUE *vp; + VALUE *vp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type == V_NUM) { - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack->v_num = qlink(&_qone_); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - return; - } - freevalue(stack); - stack->v_num = qlink(&_qzero_); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type == V_NUM) { + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack->v_num = qlink(&_qone_); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + return; + } + freevalue(stack); + stack->v_num = qlink(&_qzero_); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_isnull(FUNC *UNUSED(fp)) { - VALUE *vp; + VALUE *vp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type != V_NULL) { - freevalue(stack); - stack->v_num = qlink(&_qzero_); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - return; - } - freevalue(stack); - stack->v_num = qlink(&_qone_); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type != V_NULL) { + freevalue(stack); + stack->v_num = qlink(&_qzero_); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + return; + } + freevalue(stack); + stack->v_num = qlink(&_qone_); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_re(FUNC *UNUSED(fp)) { - VALUE *vp; - NUMBER *q; + VALUE *vp; + NUMBER *q; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type == V_NUM) { - if (stack->v_type == V_ADDR) { - stack->v_num = qlink(vp->v_num); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - } - return; - } - if (vp->v_type != V_COM) { - math_error("Taking real part of non-number"); - not_reached(); - } - q = qlink(vp->v_com->real); - if (stack->v_type == V_COM) - comfree(stack->v_com); - stack->v_num = q; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type == V_NUM) { + if (stack->v_type == V_ADDR) { + stack->v_num = qlink(vp->v_num); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + } + return; + } + if (vp->v_type != V_COM) { + math_error("Taking real part of non-number"); + not_reached(); + } + q = qlink(vp->v_com->real); + if (stack->v_type == V_COM) + comfree(stack->v_com); + stack->v_num = q; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_im(FUNC *UNUSED(fp)) { - VALUE *vp; - NUMBER *q; + VALUE *vp; + NUMBER *q; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type == V_NUM) { - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack->v_num = qlink(&_qzero_); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - return; - } - if (vp->v_type != V_COM) { - math_error("Taking imaginary part of non-number"); - not_reached(); - } - q = qlink(vp->v_com->imag); - if (stack->v_type == V_COM) - comfree(stack->v_com); - stack->v_num = q; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type == V_NUM) { + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack->v_num = qlink(&_qzero_); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + return; + } + if (vp->v_type != V_COM) { + math_error("Taking imaginary part of non-number"); + not_reached(); + } + q = qlink(vp->v_com->imag); + if (stack->v_type == V_COM) + comfree(stack->v_com); + stack->v_num = q; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_conjugate(FUNC *UNUSED(fp)) { - VALUE *vp; - VALUE tmp; + VALUE *vp; + VALUE tmp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type == V_NUM) { - if (stack->v_type == V_ADDR) { - stack->v_num = qlink(vp->v_num); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - } - return; - } - conjvalue(vp, &tmp); - freevalue(stack); - *stack = tmp; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type == V_NUM) { + if (stack->v_type == V_ADDR) { + stack->v_num = qlink(vp->v_num); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + } + return; + } + conjvalue(vp, &tmp); + freevalue(stack); + *stack = tmp; } S_FUNC void o_fiaddr(FUNC *UNUSED(fp)) { - register MATRIX *m; /* current matrix element */ - LIST *lp; /* list header */ - ASSOC *ap; /* association header */ - VALUE *vp; /* stack value */ - long index; /* index value as an integer */ - VALUE *res; + register MATRIX *m; /* current matrix element */ + LIST *lp; /* list header */ + ASSOC *ap; /* association header */ + VALUE *vp; /* stack value */ + long index; /* index value as an integer */ + VALUE *res; - vp = stack; - res = NULL; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type != V_NUM || qisfrac(vp->v_num)) { - math_error("Fast indexing by non-integer"); - not_reached(); - } - index = qtoi(vp->v_num); - if (zge31b(vp->v_num->num) || (index < 0)) { - math_error("Index out of range for fast indexing"); - not_reached(); - } - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack--; - vp = stack; - if (vp->v_type != V_ADDR) { - math_error("Non-pointer for fast indexing"); - not_reached(); - } - vp = vp->v_addr; - switch (vp->v_type) { - case V_OBJ: - if (index >= vp->v_obj->o_actions->oa_count) { - math_error("Index out of bounds for object"); - not_reached(); - } - res = vp->v_obj->o_table + index; - break; - case V_MAT: - m = vp->v_mat; - if (index >= m->m_size) { - math_error("Index out of bounds for matrix"); - not_reached(); - } - res = m->m_table + index; - break; - case V_LIST: - lp = vp->v_list; - res = listfindex(lp, index); - if (res == NULL) { - math_error("Index out of bounds for list"); - not_reached(); - } - break; - case V_ASSOC: - ap = vp->v_assoc; - res = assocfindex(ap, index); - if (res == NULL) { - math_error("Index out of bounds for association"); - not_reached(); - } - break; - default: - math_error("Bad variable type for fast indexing"); - not_reached(); - } - stack->v_addr = res; + vp = stack; + res = NULL; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type != V_NUM || qisfrac(vp->v_num)) { + math_error("Fast indexing by non-integer"); + not_reached(); + } + index = qtoi(vp->v_num); + if (zge31b(vp->v_num->num) || (index < 0)) { + math_error("Index out of range for fast indexing"); + not_reached(); + } + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack--; + vp = stack; + if (vp->v_type != V_ADDR) { + math_error("Non-pointer for fast indexing"); + not_reached(); + } + vp = vp->v_addr; + switch (vp->v_type) { + case V_OBJ: + if (index >= vp->v_obj->o_actions->oa_count) { + math_error("Index out of bounds for object"); + not_reached(); + } + res = vp->v_obj->o_table + index; + break; + case V_MAT: + m = vp->v_mat; + if (index >= m->m_size) { + math_error("Index out of bounds for matrix"); + not_reached(); + } + res = m->m_table + index; + break; + case V_LIST: + lp = vp->v_list; + res = listfindex(lp, index); + if (res == NULL) { + math_error("Index out of bounds for list"); + not_reached(); + } + break; + case V_ASSOC: + ap = vp->v_assoc; + res = assocfindex(ap, index); + if (res == NULL) { + math_error("Index out of bounds for association"); + not_reached(); + } + break; + default: + math_error("Bad variable type for fast indexing"); + not_reached(); + } + stack->v_addr = res; } S_FUNC void o_fivalue(FUNC *fp) { - (void) o_fiaddr(fp); - (void) o_getvalue(fp); + (void) o_fiaddr(fp); + (void) o_getvalue(fp); } S_FUNC void o_sgn(FUNC *UNUSED(fp)) { - VALUE *vp; - NUMBER *q; - VALUE tmp; + VALUE *vp; + NUMBER *q; + VALUE tmp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type == V_NUM) { - q = qsign(vp->v_num); - if (stack->v_type == V_NUM) - qfree(vp->v_num); - stack->v_num = q; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - return; - } - sgnvalue(vp, &tmp); - freevalue(stack); - *stack = tmp; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type == V_NUM) { + q = qsign(vp->v_num); + if (stack->v_type == V_NUM) + qfree(vp->v_num); + stack->v_num = q; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + return; + } + sgnvalue(vp, &tmp); + freevalue(stack); + *stack = tmp; } S_FUNC void o_numerator(FUNC *UNUSED(fp)) { - VALUE *vp; - NUMBER *q; + VALUE *vp; + NUMBER *q; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type != V_NUM) { - math_error("Numerator of non-number"); - not_reached(); - } - if ((stack->v_type == V_NUM) && qisint(vp->v_num)) - return; - q = qnum(vp->v_num); - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack->v_num = q; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type != V_NUM) { + math_error("Numerator of non-number"); + not_reached(); + } + if ((stack->v_type == V_NUM) && qisint(vp->v_num)) + return; + q = qnum(vp->v_num); + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack->v_num = q; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_denominator(FUNC *UNUSED(fp)) { - VALUE *vp; - NUMBER *q; + VALUE *vp; + NUMBER *q; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type != V_NUM) { - math_error("Denominator of non-number"); - not_reached(); - } - q = qden(vp->v_num); - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack->v_num = q; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type != V_NUM) { + math_error("Denominator of non-number"); + not_reached(); + } + q = qden(vp->v_num); + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack->v_num = q; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_duplicate(FUNC *UNUSED(fp)) { - VALUE *vp; + VALUE *vp; - vp = stack++; - *stack = *vp; + vp = stack++; + *stack = *vp; } S_FUNC void o_dupvalue(FUNC *UNUSED(fp)) { - if (stack->v_type == V_ADDR) - copyvalue(stack->v_addr, stack + 1); - else - copyvalue(stack, stack + 1); - stack++; + if (stack->v_type == V_ADDR) + copyvalue(stack->v_addr, stack + 1); + else + copyvalue(stack, stack + 1); + stack++; } S_FUNC void o_pop(FUNC *UNUSED(fp)) { - freevalue(stack--); + freevalue(stack--); } @@ -2566,46 +2566,46 @@ o_return(FUNC *UNUSED(fp)) S_FUNC void o_jumpz(FUNC *UNUSED(fp), bool *dojump) { - VALUE *vp; - int i; /* result of comparison */ + VALUE *vp; + int i; /* result of comparison */ - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type == V_NUM) { - i = !qiszero(vp->v_num); - if (stack->v_type == V_NUM) - qfree(stack->v_num); - } else { - i = testvalue(vp); - freevalue(stack); - } - stack--; - if (!i) - *dojump = true; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type == V_NUM) { + i = !qiszero(vp->v_num); + if (stack->v_type == V_NUM) + qfree(stack->v_num); + } else { + i = testvalue(vp); + freevalue(stack); + } + stack--; + if (!i) + *dojump = true; } S_FUNC void o_jumpnz(FUNC *UNUSED(fp), bool *dojump) { - VALUE *vp; - int i; /* result of comparison */ + VALUE *vp; + int i; /* result of comparison */ - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type == V_NUM) { - i = !qiszero(vp->v_num); - if (stack->v_type == V_NUM) - qfree(stack->v_num); - } else { - i = testvalue(vp); - freevalue(stack); - } - stack--; - if (i) - *dojump = true; + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type == V_NUM) { + i = !qiszero(vp->v_num); + if (stack->v_type == V_NUM) + qfree(stack->v_num); + } else { + i = testvalue(vp); + freevalue(stack); + } + stack--; + if (i) + *dojump = true; } @@ -2615,60 +2615,60 @@ o_jumpnz(FUNC *UNUSED(fp), bool *dojump) S_FUNC void o_jumpnn(FUNC *UNUSED(fp), bool *dojump) { - if (stack->v_addr->v_type) { - *dojump = true; - stack--; - } + if (stack->v_addr->v_type) { + *dojump = true; + stack--; + } } S_FUNC void o_condorjump(FUNC *UNUSED(fp), bool *dojump) { - VALUE *vp; + VALUE *vp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type == V_NUM) { - if (!qiszero(vp->v_num)) { - *dojump = true; - return; - } - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack--; - return; - } - if (testvalue(vp)) - *dojump = true; - else - freevalue(stack--); + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type == V_NUM) { + if (!qiszero(vp->v_num)) { + *dojump = true; + return; + } + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack--; + return; + } + if (testvalue(vp)) + *dojump = true; + else + freevalue(stack--); } S_FUNC void o_condandjump(FUNC *UNUSED(fp), bool *dojump) { - VALUE *vp; + VALUE *vp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type == V_NUM) { - if (qiszero(vp->v_num)) { - *dojump = true; - return; - } - if (stack->v_type == V_NUM) - qfree(stack->v_num); - stack--; - return; - } - if (!testvalue(vp)) - *dojump = true; - else - freevalue(stack--); + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type == V_NUM) { + if (qiszero(vp->v_num)) { + *dojump = true; + return; + } + if (stack->v_type == V_NUM) + qfree(stack->v_num); + stack--; + return; + } + if (!testvalue(vp)) + *dojump = true; + else + freevalue(stack--); } @@ -2680,701 +2680,701 @@ o_condandjump(FUNC *UNUSED(fp), bool *dojump) S_FUNC void o_casejump(FUNC *UNUSED(fp), bool *dojump) { - VALUE *v1, *v2; - int r; + VALUE *v1, *v2; + int r; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - r = comparevalue(v1, v2); - freevalue(stack--); - if (r) - *dojump = true; - else - freevalue(stack--); + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + r = comparevalue(v1, v2); + freevalue(stack--); + if (r) + *dojump = true; + else + freevalue(stack--); } S_FUNC void o_jump(FUNC *UNUSED(fp), bool *dojump) { - *dojump = true; + *dojump = true; } S_FUNC void o_usercall(FUNC *fp, long index, long argcount) { - fp = findfunc(index); - if (fp == NULL) { - math_error("Function \"%s\" is undefined", namefunc(index)); - not_reached(); - } - calculate(fp, (int) argcount); + fp = findfunc(index); + if (fp == NULL) { + math_error("Function \"%s\" is undefined", namefunc(index)); + not_reached(); + } + calculate(fp, (int) argcount); } S_FUNC void o_call(FUNC *UNUSED(fp), long index, long argcount) { - VALUE result; + VALUE result; - result = builtinfunc(index, (int) argcount, stack); - while (--argcount >= 0) - freevalue(stack--); - stack++; - *stack = result; + result = builtinfunc(index, (int) argcount, stack); + while (--argcount >= 0) + freevalue(stack--); + stack++; + *stack = result; } S_FUNC void o_getvalue(FUNC *UNUSED(fp)) { - if (stack->v_type == V_ADDR) - copyvalue(stack->v_addr, stack); + if (stack->v_type == V_ADDR) + copyvalue(stack->v_addr, stack); } S_FUNC void o_cmp(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - relvalue(v1, v2, &tmp); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + relvalue(v1, v2, &tmp); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_eq(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - int r; + VALUE *v1, *v2; + int r; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - r = comparevalue(v1, v2); - freevalue(stack--); - freevalue(stack); - stack->v_num = itoq((long) (r == 0)); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + r = comparevalue(v1, v2); + freevalue(stack--); + freevalue(stack); + stack->v_num = itoq((long) (r == 0)); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_ne(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - int r; + VALUE *v1, *v2; + int r; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - r = comparevalue(v1, v2); - freevalue(stack--); - freevalue(stack); - stack->v_num = itoq((long) (r != 0)); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + r = comparevalue(v1, v2); + freevalue(stack--); + freevalue(stack); + stack->v_num = itoq((long) (r != 0)); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_le(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - relvalue(v1, v2, &tmp); - freevalue(stack--); - freevalue(stack); + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + relvalue(v1, v2, &tmp); + freevalue(stack--); + freevalue(stack); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - if (tmp.v_type == V_NUM) { - stack->v_num = !qispos(tmp.v_num) ? qlink(&_qone_): - qlink(&_qzero_); - } else if (tmp.v_type == V_COM) { - stack->v_num = qlink(&_qzero_); - } else { - stack->v_type = V_NULL; - } - freevalue(&tmp); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + if (tmp.v_type == V_NUM) { + stack->v_num = !qispos(tmp.v_num) ? qlink(&_qone_): + qlink(&_qzero_); + } else if (tmp.v_type == V_COM) { + stack->v_num = qlink(&_qzero_); + } else { + stack->v_type = V_NULL; + } + freevalue(&tmp); } S_FUNC void o_ge(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - relvalue(v1, v2, &tmp); - freevalue(stack--); - freevalue(stack); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - if (tmp.v_type == V_NUM) { - stack->v_num = !qisneg(tmp.v_num) ? qlink(&_qone_): - qlink(&_qzero_); - } else if (tmp.v_type == V_COM) { - stack->v_num = qlink(&_qzero_); - } else { - stack->v_type = V_NULL; - } - freevalue(&tmp); + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + relvalue(v1, v2, &tmp); + freevalue(stack--); + freevalue(stack); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + if (tmp.v_type == V_NUM) { + stack->v_num = !qisneg(tmp.v_num) ? qlink(&_qone_): + qlink(&_qzero_); + } else if (tmp.v_type == V_COM) { + stack->v_num = qlink(&_qzero_); + } else { + stack->v_type = V_NULL; + } + freevalue(&tmp); } S_FUNC void o_lt(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - relvalue(v1, v2, &tmp); - freevalue(stack--); - freevalue(stack); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - if (tmp.v_type == V_NUM) { - stack->v_num = qisneg(tmp.v_num) ? qlink(&_qone_): - qlink(&_qzero_); - } else if (tmp.v_type == V_COM) { - stack->v_num = qlink(&_qzero_); - } else { - stack->v_type = V_NULL; - } - freevalue(&tmp); + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + relvalue(v1, v2, &tmp); + freevalue(stack--); + freevalue(stack); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + if (tmp.v_type == V_NUM) { + stack->v_num = qisneg(tmp.v_num) ? qlink(&_qone_): + qlink(&_qzero_); + } else if (tmp.v_type == V_COM) { + stack->v_num = qlink(&_qzero_); + } else { + stack->v_type = V_NULL; + } + freevalue(&tmp); } S_FUNC void o_gt(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - relvalue(v1, v2, &tmp); - freevalue(stack--); - freevalue(stack); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - if (tmp.v_type == V_NUM) { - stack->v_num = qispos(tmp.v_num) ? qlink(&_qone_): - qlink(&_qzero_); - } else if (tmp.v_type == V_COM) { - stack->v_num = qlink(&_qzero_); - } else { - stack->v_type = V_NULL; - } - freevalue(&tmp); + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + relvalue(v1, v2, &tmp); + freevalue(stack--); + freevalue(stack); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + if (tmp.v_type == V_NUM) { + stack->v_num = qispos(tmp.v_num) ? qlink(&_qone_): + qlink(&_qzero_); + } else if (tmp.v_type == V_COM) { + stack->v_num = qlink(&_qzero_); + } else { + stack->v_type = V_NULL; + } + freevalue(&tmp); } S_FUNC void o_preinc(FUNC *UNUSED(fp)) { - VALUE *vp, tmp; + VALUE *vp, tmp; - if (stack->v_type == V_OCTET) { - if (stack->v_subtype & (V_NONEWVALUE | V_NOCOPYTO)) { - *stack = error_value(E_PREINC_1); - return; - } - stack->v_octet[0] = stack->v_octet[0] + 1; - return; - } - if (stack->v_type != V_ADDR) { - freevalue(stack); - *stack = error_value(E_PREINC_2); - return; - } - vp = stack->v_addr; + if (stack->v_type == V_OCTET) { + if (stack->v_subtype & (V_NONEWVALUE | V_NOCOPYTO)) { + *stack = error_value(E_PREINC_1); + return; + } + stack->v_octet[0] = stack->v_octet[0] + 1; + return; + } + if (stack->v_type != V_ADDR) { + freevalue(stack); + *stack = error_value(E_PREINC_2); + return; + } + vp = stack->v_addr; - if (vp->v_subtype & (V_NONEWVALUE | V_NOASSIGNTO)) { - *stack = error_value(E_PREINC_3); - return; - } - incvalue(vp, &tmp); - freevalue(vp); - *vp = tmp; + if (vp->v_subtype & (V_NONEWVALUE | V_NOASSIGNTO)) { + *stack = error_value(E_PREINC_3); + return; + } + incvalue(vp, &tmp); + freevalue(vp); + *vp = tmp; } S_FUNC void o_predec(FUNC *UNUSED(fp)) { - VALUE *vp, tmp; + VALUE *vp, tmp; - if (stack->v_type == V_OCTET) { - if (stack->v_subtype & (V_NONEWVALUE | V_NOCOPYTO)) { - *stack = error_value(E_PREDEC_1); - return; - } - --(*stack->v_octet); - return; - } - if (stack->v_type != V_ADDR) { - freevalue(stack); - *stack = error_value(E_PREDEC_2); - return; - } - vp = stack->v_addr; - if (vp->v_subtype & (V_NONEWVALUE | V_NOASSIGNTO)) { - *stack = error_value(E_PREDEC_3); - return; - } - decvalue(vp, &tmp); - freevalue(vp); - *vp = tmp; + if (stack->v_type == V_OCTET) { + if (stack->v_subtype & (V_NONEWVALUE | V_NOCOPYTO)) { + *stack = error_value(E_PREDEC_1); + return; + } + --(*stack->v_octet); + return; + } + if (stack->v_type != V_ADDR) { + freevalue(stack); + *stack = error_value(E_PREDEC_2); + return; + } + vp = stack->v_addr; + if (vp->v_subtype & (V_NONEWVALUE | V_NOASSIGNTO)) { + *stack = error_value(E_PREDEC_3); + return; + } + decvalue(vp, &tmp); + freevalue(vp); + *vp = tmp; } S_FUNC void o_postinc(FUNC *UNUSED(fp)) { - VALUE *vp; - VALUE tmp; + VALUE *vp; + VALUE tmp; - if (stack->v_type == V_OCTET) { - if (stack->v_subtype & (V_NONEWVALUE | V_NOCOPYTO)) { - *stack++ = error_value(E_POSTINC_1); - stack->v_type = V_NULL; - return; - } - stack[1] = stack[0]; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - stack->v_num = itoq((long) stack->v_octet[0]); - stack++; - stack->v_octet[0]++; - return; - } - if (stack->v_type != V_ADDR) { - stack[1] = *stack; - *stack = error_value(E_POSTINC_2); - stack++; - return; - } - vp = stack->v_addr; - if (vp->v_subtype & V_NONEWVALUE) { - stack[1] = *stack; - *stack = error_value(E_POSTINC_3); - stack++; - return; - } - copyvalue(vp, stack++); - incvalue(vp, &tmp); - freevalue(vp); - *vp = tmp; - stack->v_type = V_ADDR; - stack->v_subtype = V_NOSUBTYPE; - stack->v_addr = vp; + if (stack->v_type == V_OCTET) { + if (stack->v_subtype & (V_NONEWVALUE | V_NOCOPYTO)) { + *stack++ = error_value(E_POSTINC_1); + stack->v_type = V_NULL; + return; + } + stack[1] = stack[0]; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + stack->v_num = itoq((long) stack->v_octet[0]); + stack++; + stack->v_octet[0]++; + return; + } + if (stack->v_type != V_ADDR) { + stack[1] = *stack; + *stack = error_value(E_POSTINC_2); + stack++; + return; + } + vp = stack->v_addr; + if (vp->v_subtype & V_NONEWVALUE) { + stack[1] = *stack; + *stack = error_value(E_POSTINC_3); + stack++; + return; + } + copyvalue(vp, stack++); + incvalue(vp, &tmp); + freevalue(vp); + *vp = tmp; + stack->v_type = V_ADDR; + stack->v_subtype = V_NOSUBTYPE; + stack->v_addr = vp; } S_FUNC void o_postdec(FUNC *UNUSED(fp)) { - VALUE *vp; - VALUE tmp; + VALUE *vp; + VALUE tmp; - if (stack->v_type == V_OCTET) { - if (stack->v_subtype & (V_NONEWVALUE | V_NOCOPYTO)) { - *stack++ = error_value(E_POSTDEC_1); - stack->v_type = V_NULL; - return; - } - stack[1] = stack[0]; - stack->v_type = V_NUM; - stack->v_num = itoq((long) stack->v_octet[0]); - stack++; - stack->v_octet[0]--; - return; - } - if (stack->v_type != V_ADDR) { - stack[1] = *stack; - *stack = error_value(E_POSTDEC_2); - stack++; - return; - } - vp = stack->v_addr; - if (vp->v_subtype & (V_NONEWVALUE | V_NOASSIGNTO)) { - stack[1] = *stack; - *stack = error_value(E_POSTDEC_3); - stack++; - return; - } - copyvalue(vp, stack++); - decvalue(vp, &tmp); - freevalue(vp); - *vp = tmp; - stack->v_type = V_ADDR; - stack->v_subtype = V_NOSUBTYPE; - stack->v_addr = vp; + if (stack->v_type == V_OCTET) { + if (stack->v_subtype & (V_NONEWVALUE | V_NOCOPYTO)) { + *stack++ = error_value(E_POSTDEC_1); + stack->v_type = V_NULL; + return; + } + stack[1] = stack[0]; + stack->v_type = V_NUM; + stack->v_num = itoq((long) stack->v_octet[0]); + stack++; + stack->v_octet[0]--; + return; + } + if (stack->v_type != V_ADDR) { + stack[1] = *stack; + *stack = error_value(E_POSTDEC_2); + stack++; + return; + } + vp = stack->v_addr; + if (vp->v_subtype & (V_NONEWVALUE | V_NOASSIGNTO)) { + stack[1] = *stack; + *stack = error_value(E_POSTDEC_3); + stack++; + return; + } + copyvalue(vp, stack++); + decvalue(vp, &tmp); + freevalue(vp); + *vp = tmp; + stack->v_type = V_ADDR; + stack->v_subtype = V_NOSUBTYPE; + stack->v_addr = vp; } S_FUNC void o_leftshift(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - shiftvalue(v1, v2, false, &tmp); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + shiftvalue(v1, v2, false, &tmp); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_rightshift(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - VALUE tmp; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - shiftvalue(v1, v2, true, &tmp); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + shiftvalue(v1, v2, true, &tmp); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_debug(FUNC *UNUSED(fp), long line) { - funcline = line; - if (abortlevel >= ABORT_STATEMENT) { - math_error("Calculation aborted at statement boundary"); - not_reached(); - } + funcline = line; + if (abortlevel >= ABORT_STATEMENT) { + math_error("Calculation aborted at statement boundary"); + not_reached(); + } } S_FUNC void o_printresult(FUNC *UNUSED(fp)) { - VALUE *vp; + VALUE *vp; - vp = stack; + vp = stack; - /* firewall */ - if (vp == NULL) - return; + /* firewall */ + if (vp == NULL) + return; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; - /* firewall */ - if (vp == NULL) - return; + /* firewall */ + if (vp == NULL) + return; - if (vp->v_type != V_NULL) { - if (conf->tab_ok) - math_chr('\t'); - printvalue(vp, PRINT_UNAMBIG); - math_chr('\n'); - math_flush(); - } - freevalue(stack--); + if (vp->v_type != V_NULL) { + if (conf->tab_ok) + math_chr('\t'); + printvalue(vp, PRINT_UNAMBIG); + math_chr('\n'); + math_flush(); + } + freevalue(stack--); } S_FUNC void o_print(FUNC *UNUSED(fp), long flags) { - VALUE *vp; + VALUE *vp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - printvalue(vp, (int) flags); - freevalue(stack--); - if (conf->traceflags & TRACE_OPCODES) - printf("\n"); - math_flush(); + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + printvalue(vp, (int) flags); + freevalue(stack--); + if (conf->traceflags & TRACE_OPCODES) + printf("\n"); + math_flush(); } S_FUNC void o_printeol(FUNC *UNUSED(fp)) { - math_chr('\n'); - math_flush(); + math_chr('\n'); + math_flush(); } S_FUNC void o_printspace(FUNC *UNUSED(fp)) { - math_chr(' '); - if (conf->traceflags & TRACE_OPCODES) - printf("\n"); + math_chr(' '); + if (conf->traceflags & TRACE_OPCODES) + printf("\n"); } S_FUNC void o_printstring(FUNC *UNUSED(fp), long index) { - STRING *s; - char *cp; + STRING *s; + char *cp; - s = findstring(index); - cp = s->s_str; - math_str(cp); - if (conf->traceflags & TRACE_OPCODES) - printf("\n"); - math_flush(); + s = findstring(index); + cp = s->s_str; + math_str(cp); + if (conf->traceflags & TRACE_OPCODES) + printf("\n"); + math_flush(); } S_FUNC void o_zero(FUNC *UNUSED(fp)) { - stack++; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - stack->v_num = qlink(&_qzero_); + stack++; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + stack->v_num = qlink(&_qzero_); } S_FUNC void o_one(FUNC *UNUSED(fp)) { - stack++; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - stack->v_num = qlink(&_qone_); + stack++; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + stack->v_num = qlink(&_qone_); } S_FUNC void o_save(FUNC *fp) { - VALUE *vp; + VALUE *vp; - if (saveval || fp->f_name[1] == '*') { - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - freevalue(&fp->f_savedvalue); - copyvalue(vp, &fp->f_savedvalue); - } + if (saveval || fp->f_name[1] == '*') { + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + freevalue(&fp->f_savedvalue); + copyvalue(vp, &fp->f_savedvalue); + } } S_FUNC void o_oldvalue(FUNC *UNUSED(fp)) { - ++stack; - stack->v_type = V_ADDR; - stack->v_addr = &oldvalue; + ++stack; + stack->v_type = V_ADDR; + stack->v_addr = &oldvalue; } void o_setsaveval(FUNC *UNUSED(fp)) { - VALUE *vp; + VALUE *vp; - vp = stack; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - saveval = testvalue(vp); - freevalue(stack); + vp = stack; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + saveval = testvalue(vp); + freevalue(stack); } S_FUNC void o_quit(FUNC *fp, long index) { - STRING *s; - char *cp; + STRING *s; + char *cp; - cp = NULL; - if (index >= 0) { - s = findstring(index); - cp = s->s_str; - } - if (inputisterminal() && !strcmp(fp->f_name, "*")) { - if (cp) - printf("%s\n", cp); - hist_term(); - while (stack > stackarray) { - freevalue(stack--); - } - freevalue(stackarray); - run_state = RUN_EXIT; - if (calc_use_scanerr_jmpbuf != 0) { - longjmp(calc_scanerr_jmpbuf, 50); - } else { - fprintf(stderr, - "calc_scanerr_jmpbuf not setup, exiting code 50\n"); - libcalc_call_me_last(); - exit(50); - } - } - if (cp) - printf("%s\n", cp); - else if (conf->verbose_quit) - printf("quit or abort executed\n"); - if (!inputisterminal() && !strcmp(fp->f_name, "*")) - closeinput(); - go = false; + cp = NULL; + if (index >= 0) { + s = findstring(index); + cp = s->s_str; + } + if (inputisterminal() && !strcmp(fp->f_name, "*")) { + if (cp) + printf("%s\n", cp); + hist_term(); + while (stack > stackarray) { + freevalue(stack--); + } + freevalue(stackarray); + run_state = RUN_EXIT; + if (calc_use_scanerr_jmpbuf != 0) { + longjmp(calc_scanerr_jmpbuf, 50); + } else { + fprintf(stderr, + "calc_scanerr_jmpbuf not setup, exiting code 50\n"); + libcalc_call_me_last(); + exit(50); + } + } + if (cp) + printf("%s\n", cp); + else if (conf->verbose_quit) + printf("quit or abort executed\n"); + if (!inputisterminal() && !strcmp(fp->f_name, "*")) + closeinput(); + go = false; } S_FUNC void o_abort(FUNC *fp, long index) { - abort_now = true; - o_quit(fp, index); + abort_now = true; + o_quit(fp, index); } S_FUNC void o_getepsilon(FUNC *UNUSED(fp)) { - stack++; - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; - stack->v_num = qlink(conf->epsilon); + stack++; + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; + stack->v_num = qlink(conf->epsilon); } S_FUNC void o_setepsilon(FUNC *UNUSED(fp)) { - VALUE *vp; - NUMBER *newep; + VALUE *vp; + NUMBER *newep; - vp = &stack[0]; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type != V_NUM) { - math_error("Non-numeric for epsilon"); - not_reached(); - } - newep = vp->v_num; - stack->v_num = qlink(conf->epsilon); - setepsilon(newep); - if (stack->v_type == V_NUM) - qfree(newep); - stack->v_type = V_NUM; - stack->v_subtype = V_NOSUBTYPE; + vp = &stack[0]; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type != V_NUM) { + math_error("Non-numeric for epsilon"); + not_reached(); + } + newep = vp->v_num; + stack->v_num = qlink(conf->epsilon); + setepsilon(newep); + if (stack->v_type == V_NUM) + qfree(newep); + stack->v_type = V_NUM; + stack->v_subtype = V_NOSUBTYPE; } S_FUNC void o_setconfig(FUNC *UNUSED(fp)) { - int type; - VALUE *v1, *v2; - VALUE tmp; + int type; + VALUE *v1, *v2; + VALUE tmp; - v1 = &stack[-1]; - v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if (v1->v_type != V_STR) { - math_error("Non-string for config"); - not_reached(); - } - type = configtype(v1->v_str->s_str); - if (type < 0) { - math_error("Unknown config name \"%s\"", - v1->v_str->s_str); - not_reached(); - } - config_value(conf, type, &tmp); - setconfig(type, v2); - freevalue(stack--); - freevalue(stack); - *stack = tmp; + v1 = &stack[-1]; + v2 = &stack[0]; + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if (v1->v_type != V_STR) { + math_error("Non-string for config"); + not_reached(); + } + type = configtype(v1->v_str->s_str); + if (type < 0) { + math_error("Unknown config name \"%s\"", + v1->v_str->s_str); + not_reached(); + } + config_value(conf, type, &tmp); + setconfig(type, v2); + freevalue(stack--); + freevalue(stack); + *stack = tmp; } S_FUNC void o_getconfig(FUNC *UNUSED(fp)) { - int type; - VALUE *vp; + int type; + VALUE *vp; - vp = &stack[0]; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; - if (vp->v_type != V_STR) { - math_error("Non-string for config"); - not_reached(); - } - type = configtype(vp->v_str->s_str); - if (type < 0) { - math_error("Unknown config name \"%s\"", - vp->v_str->s_str); - not_reached(); - } - freevalue(stack); - config_value(conf, type, stack); + vp = &stack[0]; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; + if (vp->v_type != V_STR) { + math_error("Non-string for config"); + not_reached(); + } + type = configtype(vp->v_str->s_str); + if (type < 0) { + math_error("Unknown config name \"%s\"", + vp->v_str->s_str); + not_reached(); + } + freevalue(stack); + config_value(conf, type, stack); } @@ -3384,12 +3384,12 @@ o_getconfig(FUNC *UNUSED(fp)) void updateoldvalue(FUNC *fp) { - if (fp->f_savedvalue.v_type == V_NULL) - return; - freevalue(&oldvalue); - oldvalue = fp->f_savedvalue; - fp->f_savedvalue.v_type = V_NULL; - fp->f_savedvalue.v_subtype = V_NOSUBTYPE; + if (fp->f_savedvalue.v_type == V_NULL) + return; + freevalue(&oldvalue); + oldvalue = fp->f_savedvalue; + fp->f_savedvalue.v_type = V_NULL; + fp->f_savedvalue.v_subtype = V_NOSUBTYPE; } @@ -3399,24 +3399,24 @@ updateoldvalue(FUNC *fp) VALUE error_value(int e) { - VALUE res; + VALUE res; - if (-e > 0) - e = 0; - if (is_valid_errnum(e) == false) { - math_error("Error %d is not a valid errnum in %s", e, __func__); - not_reached(); - } - calc_errno = e; - if (e > 0) - errcount++; - if (errmax >= 0 && errcount > errmax) { - math_error("Error %d caused errcount to exceed errmax", e); - not_reached(); - } - res.v_type = (short) -e; - res.v_subtype = V_NOSUBTYPE; - return res; + if (-e > 0) + e = 0; + if (is_valid_errnum(e) == false) { + math_error("Error %d is not a valid errnum in %s", e, __func__); + not_reached(); + } + calc_errno = e; + if (e > 0) + errcount++; + if (errmax >= 0 && errcount > errmax) { + math_error("Error %d caused errcount to exceed errmax", e); + not_reached(); + } + res.v_type = (short) -e; + res.v_subtype = V_NOSUBTYPE; + return res; } /* @@ -3425,13 +3425,13 @@ error_value(int e) int set_errno(int e) { - int res; + int res; - res = calc_errno; - if (is_valid_errnum(e) == true) { - calc_errno = e; - } - return res; + res = calc_errno; + if (is_valid_errnum(e) == true) { + calc_errno = e; + } + return res; } @@ -3441,12 +3441,12 @@ set_errno(int e) int set_errcount(int e) { - int res; + int res; - res = errcount; - if (e >= 0) - errcount = e; - return res; + res = errcount; + if (e >= 0) + errcount = e; + return res; } @@ -3456,97 +3456,97 @@ set_errcount(int e) S_FUNC void o_initfill(FUNC *UNUSED(fp)) { - VALUE *v1, *v2; - int s; - VALUE *vp; + VALUE *v1, *v2; + int s; + VALUE *vp; - v1 = &stack[-1]; - v2 = &stack[0]; + v1 = &stack[-1]; + v2 = &stack[0]; - if (v1->v_type == V_ADDR) - v1 = v1->v_addr; - if (v2->v_type == V_ADDR) - v2 = v2->v_addr; - if (v1->v_type != V_MAT) { - math_error("Non-matrix argument for o_initfill"); - not_reached(); - } - s = v1->v_mat->m_size; - vp = v1->v_mat->m_table; - while (s-- > 0) - copyvalue(v2, vp++); - freevalue(stack--); + if (v1->v_type == V_ADDR) + v1 = v1->v_addr; + if (v2->v_type == V_ADDR) + v2 = v2->v_addr; + if (v1->v_type != V_MAT) { + math_error("Non-matrix argument for o_initfill"); + not_reached(); + } + s = v1->v_mat->m_size; + vp = v1->v_mat->m_table; + while (s-- > 0) + copyvalue(v2, vp++); + freevalue(stack--); } S_FUNC void o_show(FUNC *fp, long arg) { - unsigned int size; + unsigned int size; - switch((int) arg) { - case 1: showbuiltins(); return; - case 2: showglobals(); return; - case 3: showfunctions(); return; - case 4: showobjfuncs(); return; - case 5: config_print(conf); putchar('\n'); return; - case 6: showobjtypes(); return; - case 7: showfiles(); return; - case 8: showsizes(); return; - case 9: showerrors(); return; - case 10: showcustom(); return; - case 11: shownblocks(); return; - case 12: showconstants(); return; - case 13: showallglobals(); return; - case 14: showstatics(); return; - case 15: shownumbers(); return; - case 16: showredcdata(); return; - case 17: showstrings(); return; - case 18: showliterals(); return; - } - fp = findfunc(arg - 19); - if (fp == NULL) { - printf("Function not defined\n"); - return; - } - dumpnames = false; - for (size = 0; size < fp->f_opcodecount; ) { - printf("%ld: ", (long)size); - size += dumpop(&fp->f_opcodes[size]); - } + switch((int) arg) { + case 1: showbuiltins(); return; + case 2: showglobals(); return; + case 3: showfunctions(); return; + case 4: showobjfuncs(); return; + case 5: config_print(conf); putchar('\n'); return; + case 6: showobjtypes(); return; + case 7: showfiles(); return; + case 8: showsizes(); return; + case 9: showerrors(); return; + case 10: showcustom(); return; + case 11: shownblocks(); return; + case 12: showconstants(); return; + case 13: showallglobals(); return; + case 14: showstatics(); return; + case 15: shownumbers(); return; + case 16: showredcdata(); return; + case 17: showstrings(); return; + case 18: showliterals(); return; + } + fp = findfunc(arg - 19); + if (fp == NULL) { + printf("Function not defined\n"); + return; + } + dumpnames = false; + for (size = 0; size < fp->f_opcodecount; ) { + printf("%ld: ", (long)size); + size += dumpop(&fp->f_opcodes[size]); + } } S_FUNC void showsizes(void) { - printf("\tchar\t\t%4ld\n", (long)sizeof(char)); - printf("\tshort\t\t%4ld\n", (long)sizeof(short)); - printf("\tint\t\t%4ld\n", (long)sizeof(int)); - printf("\tlong\t\t%4ld\n", (long)sizeof(long)); - printf("\tpointer\t\t%4ld\n", (long)sizeof(void *)); - printf("\tFILEPOS\t\t%4ld\n", (long)sizeof(FILEPOS)); - printf("\toff_t\t\t%4ld\n", (long)sizeof(off_t)); - printf("\tHALF\t\t%4ld\n", (long)sizeof(HALF)); - printf("\tFULL\t\t%4ld\n", (long)sizeof(FULL)); - printf("\tVALUE\t\t%4ld\n", (long)sizeof(VALUE)); - printf("\tNUMBER\t\t%4ld\n", (long)sizeof(NUMBER)); - printf("\tZVALUE\t\t%4ld\n", (long)sizeof(ZVALUE)); - printf("\tCOMPLEX\t\t%4ld\n", (long)sizeof(COMPLEX)); - printf("\tSTRING\t\t%4ld\n", (long)sizeof(STRING)); - printf("\tMATRIX\t\t%4ld\n", (long)sizeof(MATRIX)); - printf("\tLIST\t\t%4ld\n", (long)sizeof(LIST)); - printf("\tLISTELEM\t%4ld\n", (long)sizeof(LISTELEM)); - printf("\tOBJECT\t\t%4ld\n", (long)sizeof(OBJECT)); - printf("\tOBJECTACTIONS\t%4ld\n", (long)sizeof(OBJECTACTIONS)); - printf("\tASSOC\t\t%4ld\n", (long)sizeof(ASSOC)); - printf("\tASSOCELEM\t%4ld\n", (long)sizeof(ASSOCELEM)); - printf("\tBLOCK\t\t%4ld\n", (long)sizeof(BLOCK)); - printf("\tNBLOCK\t\t%4ld\n", (long)sizeof(NBLOCK)); - printf("\tCONFIG\t\t%4ld\n", (long)sizeof(CONFIG)); - printf("\tFILEIO\t\t%4ld\n", (long)sizeof(FILEIO)); - printf("\tRAND\t\t%4ld\n", (long)sizeof(RAND)); - printf("\tRANDOM\t\t%4ld\n", (long)sizeof(RANDOM)); + printf("\tchar\t\t%4ld\n", (long)sizeof(char)); + printf("\tshort\t\t%4ld\n", (long)sizeof(short)); + printf("\tint\t\t%4ld\n", (long)sizeof(int)); + printf("\tlong\t\t%4ld\n", (long)sizeof(long)); + printf("\tpointer\t\t%4ld\n", (long)sizeof(void *)); + printf("\tFILEPOS\t\t%4ld\n", (long)sizeof(FILEPOS)); + printf("\toff_t\t\t%4ld\n", (long)sizeof(off_t)); + printf("\tHALF\t\t%4ld\n", (long)sizeof(HALF)); + printf("\tFULL\t\t%4ld\n", (long)sizeof(FULL)); + printf("\tVALUE\t\t%4ld\n", (long)sizeof(VALUE)); + printf("\tNUMBER\t\t%4ld\n", (long)sizeof(NUMBER)); + printf("\tZVALUE\t\t%4ld\n", (long)sizeof(ZVALUE)); + printf("\tCOMPLEX\t\t%4ld\n", (long)sizeof(COMPLEX)); + printf("\tSTRING\t\t%4ld\n", (long)sizeof(STRING)); + printf("\tMATRIX\t\t%4ld\n", (long)sizeof(MATRIX)); + printf("\tLIST\t\t%4ld\n", (long)sizeof(LIST)); + printf("\tLISTELEM\t%4ld\n", (long)sizeof(LISTELEM)); + printf("\tOBJECT\t\t%4ld\n", (long)sizeof(OBJECT)); + printf("\tOBJECTACTIONS\t%4ld\n", (long)sizeof(OBJECTACTIONS)); + printf("\tASSOC\t\t%4ld\n", (long)sizeof(ASSOC)); + printf("\tASSOCELEM\t%4ld\n", (long)sizeof(ASSOCELEM)); + printf("\tBLOCK\t\t%4ld\n", (long)sizeof(BLOCK)); + printf("\tNBLOCK\t\t%4ld\n", (long)sizeof(NBLOCK)); + printf("\tCONFIG\t\t%4ld\n", (long)sizeof(CONFIG)); + printf("\tFILEIO\t\t%4ld\n", (long)sizeof(FILEIO)); + printf("\tRAND\t\t%4ld\n", (long)sizeof(RAND)); + printf("\tRANDOM\t\t%4ld\n", (long)sizeof(RANDOM)); } @@ -3554,533 +3554,533 @@ showsizes(void) * Information about each opcode. */ STATIC struct opcode opcodes[MAX_OPCODE+1] = { - {{.func_nul = o_nop}, - OPNUL, - "NOP"}, /* no operation */ + {{.func_nul = o_nop}, + OPNUL, + "NOP"}, /* no operation */ - {{.func_loc = o_localaddr}, - OPLOC, - "LOCALADDR"}, /* address of local variable */ + {{.func_loc = o_localaddr}, + OPLOC, + "LOCALADDR"}, /* address of local variable */ - {{.func_glb = o_globaladdr}, - OPGLB, - "GLOBALADDR"}, /* address of global variable */ + {{.func_glb = o_globaladdr}, + OPGLB, + "GLOBALADDR"}, /* address of global variable */ - {{.func_par = o_paramaddr}, - OPPAR, - "PARAMADDR"}, /* address of parameter variable */ + {{.func_par = o_paramaddr}, + OPPAR, + "PARAMADDR"}, /* address of parameter variable */ - {{.func_loc = o_localvalue}, - OPLOC, - "LOCALVALUE"}, /* value of local variable */ + {{.func_loc = o_localvalue}, + OPLOC, + "LOCALVALUE"}, /* value of local variable */ - {{.func_glb = o_globalvalue}, - OPGLB, - "GLOBALVALUE"}, /* value of global variable */ + {{.func_glb = o_globalvalue}, + OPGLB, + "GLOBALVALUE"}, /* value of global variable */ - {{.func_par = o_paramvalue}, - OPPAR, - "PARAMVALUE"}, /* value of parameter variable */ + {{.func_par = o_paramvalue}, + OPPAR, + "PARAMVALUE"}, /* value of parameter variable */ - {{.func_one = o_number}, - OPONE, - "NUMBER"}, /* constant real numeric value */ + {{.func_one = o_number}, + OPONE, + "NUMBER"}, /* constant real numeric value */ - {{.func_two = o_indexaddr}, - OPTWO, - "INDEXADDR"}, /* array index address */ + {{.func_two = o_indexaddr}, + OPTWO, + "INDEXADDR"}, /* array index address */ - {{.func_nul = o_printresult}, - OPNUL, - "PRINTRESULT"}, /* print result of top-level expression */ + {{.func_nul = o_printresult}, + OPNUL, + "PRINTRESULT"}, /* print result of top-level expression */ - {{.func_nul = o_assign}, - OPNUL, - "ASSIGN"}, /* assign value to variable */ + {{.func_nul = o_assign}, + OPNUL, + "ASSIGN"}, /* assign value to variable */ - {{.func_nul = o_add}, - OPNUL, - "ADD"}, /* add top two values */ + {{.func_nul = o_add}, + OPNUL, + "ADD"}, /* add top two values */ - {{.func_nul = o_sub}, - OPNUL, - "SUB"}, /* subtract top two values */ + {{.func_nul = o_sub}, + OPNUL, + "SUB"}, /* subtract top two values */ - {{.func_nul = o_mul}, - OPNUL, - "MUL"}, /* multiply top two values */ + {{.func_nul = o_mul}, + OPNUL, + "MUL"}, /* multiply top two values */ - {{.func_nul = o_div}, - OPNUL, - "DIV"}, /* divide top two values */ + {{.func_nul = o_div}, + OPNUL, + "DIV"}, /* divide top two values */ - {{.func_nul = o_mod}, - OPNUL, - "MOD"}, /* take mod of top two values */ + {{.func_nul = o_mod}, + OPNUL, + "MOD"}, /* take mod of top two values */ - {{.func_nul = o_save}, - OPNUL, - "SAVE"}, /* save value for later use */ + {{.func_nul = o_save}, + OPNUL, + "SAVE"}, /* save value for later use */ - {{.func_nul = o_negate}, - OPNUL, - "NEGATE"}, /* negate top value */ + {{.func_nul = o_negate}, + OPNUL, + "NEGATE"}, /* negate top value */ - {{.func_nul = o_invert}, - OPNUL, - "INVERT"}, /* invert top value */ + {{.func_nul = o_invert}, + OPNUL, + "INVERT"}, /* invert top value */ - {{.func_nul = o_int}, - OPNUL, - "INT"}, /* take integer part */ + {{.func_nul = o_int}, + OPNUL, + "INT"}, /* take integer part */ - {{.func_nul = o_frac}, - OPNUL, - "FRAC"}, /* take fraction part */ + {{.func_nul = o_frac}, + OPNUL, + "FRAC"}, /* take fraction part */ - {{.func_nul = o_numerator}, - OPNUL, - "NUMERATOR"}, /* take numerator */ + {{.func_nul = o_numerator}, + OPNUL, + "NUMERATOR"}, /* take numerator */ - {{.func_nul = o_denominator}, - OPNUL, - "DENOMINATOR"}, /* take denominator */ + {{.func_nul = o_denominator}, + OPNUL, + "DENOMINATOR"}, /* take denominator */ - {{.func_nul = o_duplicate}, - OPNUL, - "DUPLICATE"}, /* duplicate top value */ + {{.func_nul = o_duplicate}, + OPNUL, + "DUPLICATE"}, /* duplicate top value */ - {{.func_nul = o_pop}, - OPNUL, - "POP"}, /* pop top value */ + {{.func_nul = o_pop}, + OPNUL, + "POP"}, /* pop top value */ - {{.func_ret = o_return}, - OPRET, - "RETURN"}, /* return value of function */ + {{.func_ret = o_return}, + OPRET, + "RETURN"}, /* return value of function */ - {{.func_jmp = o_jumpz}, - OPJMP, - "JUMPZ"}, /* jump if value zero */ + {{.func_jmp = o_jumpz}, + OPJMP, + "JUMPZ"}, /* jump if value zero */ - {{.func_jmp = o_jumpnz}, - OPJMP, - "JUMPNZ"}, /* jump if value nonzero */ + {{.func_jmp = o_jumpnz}, + OPJMP, + "JUMPNZ"}, /* jump if value nonzero */ - {{.func_jmp = o_jump}, - OPJMP, - "JUMP"}, /* jump unconditionally */ + {{.func_jmp = o_jump}, + OPJMP, + "JUMP"}, /* jump unconditionally */ - {{.func_two = o_usercall}, - OPTWO, - "USERCALL"}, /* call a user function */ + {{.func_two = o_usercall}, + OPTWO, + "USERCALL"}, /* call a user function */ - {{.func_nul = o_getvalue}, - OPNUL, - "GETVALUE"}, /* convert address to value */ + {{.func_nul = o_getvalue}, + OPNUL, + "GETVALUE"}, /* convert address to value */ - {{.func_nul = o_eq}, - OPNUL, - "EQ"}, /* test elements for equality */ + {{.func_nul = o_eq}, + OPNUL, + "EQ"}, /* test elements for equality */ - {{.func_nul = o_ne}, - OPNUL, - "NE"}, /* test elements for inequality */ + {{.func_nul = o_ne}, + OPNUL, + "NE"}, /* test elements for inequality */ - {{.func_nul = o_le}, - OPNUL, - "LE"}, /* test elements for < = */ + {{.func_nul = o_le}, + OPNUL, + "LE"}, /* test elements for < = */ - {{.func_nul = o_ge}, - OPNUL, - "GE"}, /* test elements for > = */ + {{.func_nul = o_ge}, + OPNUL, + "GE"}, /* test elements for > = */ - {{.func_nul = o_lt}, - OPNUL, - "LT"}, /* test elements for < */ + {{.func_nul = o_lt}, + OPNUL, + "LT"}, /* test elements for < */ - {{.func_nul = o_gt}, - OPNUL, - "GT"}, /* test elements for > */ + {{.func_nul = o_gt}, + OPNUL, + "GT"}, /* test elements for > */ - {{.func_nul = o_preinc}, - OPNUL, - "PREINC"}, /* add one to variable (++x) */ + {{.func_nul = o_preinc}, + OPNUL, + "PREINC"}, /* add one to variable (++x) */ - {{.func_nul = o_predec}, - OPNUL, - "PREDEC"}, /* subtract one from variable (--x) */ + {{.func_nul = o_predec}, + OPNUL, + "PREDEC"}, /* subtract one from variable (--x) */ - {{.func_nul = o_postinc}, - OPNUL, - "POSTINC"}, /* add one to variable (x++) */ + {{.func_nul = o_postinc}, + OPNUL, + "POSTINC"}, /* add one to variable (x++) */ - {{.func_nul = o_postdec}, - OPNUL, - "POSTDEC"}, /* subtract one from variable (x--) */ + {{.func_nul = o_postdec}, + OPNUL, + "POSTDEC"}, /* subtract one from variable (x--) */ - {{.func_one = o_debug}, - OPONE, - "DEBUG"}, /* debugging point */ + {{.func_one = o_debug}, + OPONE, + "DEBUG"}, /* debugging point */ - {{.func_one = o_print}, - OPONE, - "PRINT"}, /* print value */ + {{.func_one = o_print}, + OPONE, + "PRINT"}, /* print value */ - {{.func_nul = o_assignpop}, - OPNUL, - "ASSIGNPOP"}, /* assign to variable and pop it */ + {{.func_nul = o_assignpop}, + OPNUL, + "ASSIGNPOP"}, /* assign to variable and pop it */ - {{.func_nul = o_zero}, - OPNUL, - "ZERO"}, /* put zero on the stack */ + {{.func_nul = o_zero}, + OPNUL, + "ZERO"}, /* put zero on the stack */ - {{.func_nul = o_one}, - OPNUL, - "ONE"}, /* put one on the stack */ + {{.func_nul = o_one}, + OPNUL, + "ONE"}, /* put one on the stack */ - {{.func_nul = o_printeol}, - OPNUL, - "PRINTEOL"}, /* print end of line */ + {{.func_nul = o_printeol}, + OPNUL, + "PRINTEOL"}, /* print end of line */ - {{.func_nul = o_printspace}, - OPNUL, - "PRINTSPACE"}, /* print a space */ + {{.func_nul = o_printspace}, + OPNUL, + "PRINTSPACE"}, /* print a space */ - {{.func_one = o_printstring}, - OPONE, - "PRINTSTR"}, /* print constant string */ + {{.func_one = o_printstring}, + OPONE, + "PRINTSTR"}, /* print constant string */ - {{.func_nul = o_dupvalue}, - OPNUL, - "DUPVALUE"}, /* duplicate value of top value */ + {{.func_nul = o_dupvalue}, + OPNUL, + "DUPVALUE"}, /* duplicate value of top value */ - {{.func_nul = o_oldvalue}, - OPNUL, - "OLDVALUE"}, /* old value from previous calc */ + {{.func_nul = o_oldvalue}, + OPNUL, + "OLDVALUE"}, /* old value from previous calc */ - {{.func_nul = o_quo}, - OPNUL, - "QUO"}, /* integer quotient of top values */ + {{.func_nul = o_quo}, + OPNUL, + "QUO"}, /* integer quotient of top values */ - {{.func_nul = o_power}, - OPNUL, - "POWER"}, /* value raised to a power */ + {{.func_nul = o_power}, + OPNUL, + "POWER"}, /* value raised to a power */ - {{.func_one = o_quit}, - OPONE, - "QUIT"}, /* quit program */ + {{.func_one = o_quit}, + OPONE, + "QUIT"}, /* quit program */ - {{.func_two = o_call}, - OPTWO, - "CALL"}, /* call built-in routine */ + {{.func_two = o_call}, + OPTWO, + "CALL"}, /* call built-in routine */ - {{.func_nul = o_getepsilon}, - OPNUL, - "GETEPSILON"}, /* get allowed error for calculations */ + {{.func_nul = o_getepsilon}, + OPNUL, + "GETEPSILON"}, /* get allowed error for calculations */ - {{.func_nul = o_and}, - OPNUL, - "AND"}, /* arithmetic and or top two values */ + {{.func_nul = o_and}, + OPNUL, + "AND"}, /* arithmetic and or top two values */ - {{.func_nul = o_or}, - OPNUL, - "OR"}, /* arithmetic or of top two values */ + {{.func_nul = o_or}, + OPNUL, + "OR"}, /* arithmetic or of top two values */ - {{.func_nul = o_not}, - OPNUL, - "NOT"}, /* logical not or top value */ + {{.func_nul = o_not}, + OPNUL, + "NOT"}, /* logical not or top value */ - {{.func_nul = o_abs}, - OPNUL, - "ABS"}, /* absolute value of top value */ + {{.func_nul = o_abs}, + OPNUL, + "ABS"}, /* absolute value of top value */ - {{.func_nul = o_sgn}, - OPNUL, - "SGN"}, /* sign of number */ + {{.func_nul = o_sgn}, + OPNUL, + "SGN"}, /* sign of number */ - {{.func_nul = o_isint}, - OPNUL, - "ISINT"}, /* whether number is an integer */ + {{.func_nul = o_isint}, + OPNUL, + "ISINT"}, /* whether number is an integer */ - {{.func_jmp = o_condorjump}, - OPJMP, - "CONDORJUMP"}, /* conditional or jump */ + {{.func_jmp = o_condorjump}, + OPJMP, + "CONDORJUMP"}, /* conditional or jump */ - {{.func_jmp = o_condandjump}, - OPJMP, - "CONDANDJUMP"}, /* conditional and jump */ + {{.func_jmp = o_condandjump}, + OPJMP, + "CONDANDJUMP"}, /* conditional and jump */ - {{.func_nul = o_square}, - OPNUL, - "SQUARE"}, /* square top value */ + {{.func_nul = o_square}, + OPNUL, + "SQUARE"}, /* square top value */ - {{.func_one = o_string}, - OPONE, - "STRING"}, /* string constant value */ + {{.func_one = o_string}, + OPONE, + "STRING"}, /* string constant value */ - {{.func_nul = o_isnum}, - OPNUL, - "ISNUM"}, /* whether value is a number */ + {{.func_nul = o_isnum}, + OPNUL, + "ISNUM"}, /* whether value is a number */ - {{.func_nul = o_undef}, - OPNUL, - "UNDEF"}, /* load undefined value on stack */ + {{.func_nul = o_undef}, + OPNUL, + "UNDEF"}, /* load undefined value on stack */ - {{.func_nul = o_isnull}, - OPNUL, - "ISNULL"}, /* whether value is the null value */ + {{.func_nul = o_isnull}, + OPNUL, + "ISNULL"}, /* whether value is the null value */ - {{.func_arg = o_argvalue}, - OPARG, - "ARGVALUE"}, /* load value of arg (parameter) n */ + {{.func_arg = o_argvalue}, + OPARG, + "ARGVALUE"}, /* load value of arg (parameter) n */ - {{.func_one = o_matcreate}, - OPONE, - "MATCREATE"}, /* create matrix */ + {{.func_one = o_matcreate}, + OPONE, + "MATCREATE"}, /* create matrix */ - {{.func_nul = o_ismat}, - OPNUL, - "ISMAT"}, /* whether value is a matrix */ + {{.func_nul = o_ismat}, + OPNUL, + "ISMAT"}, /* whether value is a matrix */ - {{.func_nul = o_isstr}, - OPNUL, - "ISSTR"}, /* whether value is a string */ + {{.func_nul = o_isstr}, + OPNUL, + "ISSTR"}, /* whether value is a string */ - {{.func_nul = o_getconfig}, - OPNUL, - "GETCONFIG"}, /* get value of configuration parameter */ + {{.func_nul = o_getconfig}, + OPNUL, + "GETCONFIG"}, /* get value of configuration parameter */ - {{.func_nul = o_leftshift}, - OPNUL, - "LEFTSHIFT"}, /* left shift of integer */ + {{.func_nul = o_leftshift}, + OPNUL, + "LEFTSHIFT"}, /* left shift of integer */ - {{.func_nul = o_rightshift}, - OPNUL, - "RIGHTSHIFT"}, /* right shift of integer */ + {{.func_nul = o_rightshift}, + OPNUL, + "RIGHTSHIFT"}, /* right shift of integer */ - {{.func_jmp = o_casejump}, - OPJMP, - "CASEJUMP"}, /* test case and jump if not matched */ + {{.func_jmp = o_casejump}, + OPJMP, + "CASEJUMP"}, /* test case and jump if not matched */ - {{.func_nul = o_isodd}, - OPNUL, - "ISODD"}, /* whether value is odd integer */ + {{.func_nul = o_isodd}, + OPNUL, + "ISODD"}, /* whether value is odd integer */ - {{.func_nul = o_iseven}, - OPNUL, - "ISEVEN"}, /* whether value is even integer */ + {{.func_nul = o_iseven}, + OPNUL, + "ISEVEN"}, /* whether value is even integer */ - {{.func_nul = o_fiaddr}, - OPNUL, - "FIADDR"}, /* 'fast index' matrix address */ + {{.func_nul = o_fiaddr}, + OPNUL, + "FIADDR"}, /* 'fast index' matrix address */ - {{.func_nul = o_fivalue}, - OPNUL, - "FIVALUE"}, /* 'fast index' matrix value */ + {{.func_nul = o_fivalue}, + OPNUL, + "FIVALUE"}, /* 'fast index' matrix value */ - {{.func_nul = o_isreal}, - OPNUL, - "ISREAL"}, /* whether value is real number */ + {{.func_nul = o_isreal}, + OPNUL, + "ISREAL"}, /* whether value is real number */ - {{.func_one = o_imaginary}, - OPONE, - "IMAGINARY"}, /* constant imaginary numeric value */ + {{.func_one = o_imaginary}, + OPONE, + "IMAGINARY"}, /* constant imaginary numeric value */ - {{.func_nul = o_re}, - OPNUL, - "RE"}, /* real part of complex number */ + {{.func_nul = o_re}, + OPNUL, + "RE"}, /* real part of complex number */ - {{.func_nul = o_im}, - OPNUL, - "IM"}, /* imaginary part of complex number */ + {{.func_nul = o_im}, + OPNUL, + "IM"}, /* imaginary part of complex number */ - {{.func_nul = o_conjugate}, - OPNUL, - "CONJUGATE"}, /* complex conjugate */ + {{.func_nul = o_conjugate}, + OPNUL, + "CONJUGATE"}, /* complex conjugate */ - {{.func_one = o_objcreate}, - OPONE, - "OBJCREATE"}, /* create object */ + {{.func_one = o_objcreate}, + OPONE, + "OBJCREATE"}, /* create object */ - {{.func_nul = o_isobj}, - OPNUL, - "ISOBJ"}, /* whether value is an object */ + {{.func_nul = o_isobj}, + OPNUL, + "ISOBJ"}, /* whether value is an object */ - {{.func_nul = o_norm}, - OPNUL, - "NORM"}, /* norm of value (square of abs) */ + {{.func_nul = o_norm}, + OPNUL, + "NORM"}, /* norm of value (square of abs) */ - {{.func_one = o_elemaddr}, - OPONE, - "ELEMADDR"}, /* address of element of object */ + {{.func_one = o_elemaddr}, + OPONE, + "ELEMADDR"}, /* address of element of object */ - {{.func_one = o_elemvalue}, - OPONE, - "ELEMVALUE"}, /* value of element of object */ + {{.func_one = o_elemvalue}, + OPONE, + "ELEMVALUE"}, /* value of element of object */ - {{.func_nul = o_istype}, - OPNUL, - "ISTYPE"}, /* whether types are the same */ + {{.func_nul = o_istype}, + OPNUL, + "ISTYPE"}, /* whether types are the same */ - {{.func_nul = o_scale}, - OPNUL, - "SCALE"}, /* scale value by a power of two */ + {{.func_nul = o_scale}, + OPNUL, + "SCALE"}, /* scale value by a power of two */ - {{.func_nul = o_islist}, - OPNUL, - "ISLIST"}, /* whether value is a list */ + {{.func_nul = o_islist}, + OPNUL, + "ISLIST"}, /* whether value is a list */ - {{.func_nul = o_swap}, - OPNUL, - "SWAP"}, /* swap values of two variables */ + {{.func_nul = o_swap}, + OPNUL, + "SWAP"}, /* swap values of two variables */ - {{.func_nul = o_issimple}, - OPNUL, - "ISSIMPLE"}, /* whether value is simple type */ + {{.func_nul = o_issimple}, + OPNUL, + "ISSIMPLE"}, /* whether value is simple type */ - {{.func_nul = o_cmp}, - OPNUL, - "CMP"}, /* compare values returning -1, 0, 1 */ + {{.func_nul = o_cmp}, + OPNUL, + "CMP"}, /* compare values returning -1, 0, 1 */ - {{.func_nul = o_setconfig}, - OPNUL, - "SETCONFIG"}, /* set configuration parameter */ + {{.func_nul = o_setconfig}, + OPNUL, + "SETCONFIG"}, /* set configuration parameter */ - {{.func_nul = o_setepsilon}, - OPNUL, - "SETEPSILON"}, /* set allowed error for calculations */ + {{.func_nul = o_setepsilon}, + OPNUL, + "SETEPSILON"}, /* set allowed error for calculations */ - {{.func_nul = o_isfile}, - OPNUL, - "ISFILE"}, /* whether value is a file */ + {{.func_nul = o_isfile}, + OPNUL, + "ISFILE"}, /* whether value is a file */ - {{.func_nul = o_isassoc}, - OPNUL, - "ISASSOC"}, /* whether value is an association */ + {{.func_nul = o_isassoc}, + OPNUL, + "ISASSOC"}, /* whether value is an association */ - {{.func_sti = o_nop}, - OPSTI, - "INITSTATIC"}, /* once only code for static init */ + {{.func_sti = o_nop}, + OPSTI, + "INITSTATIC"}, /* once only code for static init */ - {{.func_one = o_eleminit}, - OPONE, - "ELEMINIT"}, /* assign element of matrix or object */ + {{.func_one = o_eleminit}, + OPONE, + "ELEMINIT"}, /* assign element of matrix or object */ - {{.func_nul = o_isconfig}, - OPNUL, - "ISCONFIG"}, /* whether value is a configuration state */ + {{.func_nul = o_isconfig}, + OPNUL, + "ISCONFIG"}, /* whether value is a configuration state */ - {{.func_nul = o_ishash}, - OPNUL, - "ISHASH"}, /* whether value is a hash state */ + {{.func_nul = o_ishash}, + OPNUL, + "ISHASH"}, /* whether value is a hash state */ - {{.func_nul = o_isrand}, - OPNUL, - "ISRAND"}, /* whether value is a rand element */ + {{.func_nul = o_isrand}, + OPNUL, + "ISRAND"}, /* whether value is a rand element */ - {{.func_nul = o_israndom}, - OPNUL, - "ISRANDOM"}, /* whether value is a random element */ + {{.func_nul = o_israndom}, + OPNUL, + "ISRANDOM"}, /* whether value is a random element */ - {{.func_one = o_show}, - OPONE, - "SHOW"}, /* show current state data */ + {{.func_one = o_show}, + OPONE, + "SHOW"}, /* show current state data */ - {{.func_nul = o_initfill}, - OPNUL, - "INITFILL"}, /* initially fill matrix */ + {{.func_nul = o_initfill}, + OPNUL, + "INITFILL"}, /* initially fill matrix */ - {{.func_nul = o_assignback}, - OPNUL, - "ASSIGNBACK"}, /* assign in reverse order */ + {{.func_nul = o_assignback}, + OPNUL, + "ASSIGNBACK"}, /* assign in reverse order */ - {{.func_nul = o_test}, - OPNUL, - "TEST"}, /* test that value is "nonzero" */ + {{.func_nul = o_test}, + OPNUL, + "TEST"}, /* test that value is "nonzero" */ - {{.func_nul = o_isdefined}, - OPNUL, - "ISDEFINED"}, /* whether a string names a function */ + {{.func_nul = o_isdefined}, + OPNUL, + "ISDEFINED"}, /* whether a string names a function */ - {{.func_nul = o_isobjtype}, - OPNUL, - "ISOBJTYPE"}, /* whether a string names an object type */ + {{.func_nul = o_isobjtype}, + OPNUL, + "ISOBJTYPE"}, /* whether a string names an object type */ - {{.func_nul = o_isblock}, - OPNUL, - "ISBLK"}, /* whether value is a block */ + {{.func_nul = o_isblock}, + OPNUL, + "ISBLK"}, /* whether value is a block */ - {{.func_nul = o_ptr}, - OPNUL, - "PTR"}, /* octet pointer */ + {{.func_nul = o_ptr}, + OPNUL, + "PTR"}, /* octet pointer */ - {{.func_nul = o_deref}, - OPNUL, - "DEREF"}, /* dereference an octet pointer */ + {{.func_nul = o_deref}, + OPNUL, + "DEREF"}, /* dereference an octet pointer */ - {{.func_nul = o_isoctet}, - OPNUL, - "ISOCTET"}, /* whether a value is an octet */ + {{.func_nul = o_isoctet}, + OPNUL, + "ISOCTET"}, /* whether a value is an octet */ - {{.func_nul = o_isptr}, - OPNUL, - "ISPTR"}, /* whether a value is a pointer */ + {{.func_nul = o_isptr}, + OPNUL, + "ISPTR"}, /* whether a value is a pointer */ - {{.func_nul = o_setsaveval}, - OPNUL, - "SAVEVAL"}, /* enable or disable saving */ + {{.func_nul = o_setsaveval}, + OPNUL, + "SAVEVAL"}, /* enable or disable saving */ - {{.func_nul = o_links}, - OPNUL, - "LINKS"}, /* links to number or string */ + {{.func_nul = o_links}, + OPNUL, + "LINKS"}, /* links to number or string */ - {{.func_nul = o_bit}, - OPNUL, - "BIT"}, /* whether bit is set */ + {{.func_nul = o_bit}, + OPNUL, + "BIT"}, /* whether bit is set */ - {{.func_nul = o_comp}, - OPNUL, - "COMP"}, /* complement value */ + {{.func_nul = o_comp}, + OPNUL, + "COMP"}, /* complement value */ - {{.func_nul = o_xor}, - OPNUL, - "XOR"}, /* xor (~) of values */ + {{.func_nul = o_xor}, + OPNUL, + "XOR"}, /* xor (~) of values */ - {{.func_nul = o_highbit}, - OPNUL, - "HIGHBIT"}, /* highbit of value */ + {{.func_nul = o_highbit}, + OPNUL, + "HIGHBIT"}, /* highbit of value */ - {{.func_nul = o_lowbit}, - OPNUL, - "LOWBIT"}, /* lowbit of value */ + {{.func_nul = o_lowbit}, + OPNUL, + "LOWBIT"}, /* lowbit of value */ - {{.func_nul = o_content}, - OPNUL, - "CONTENT"}, /* unary hash op */ + {{.func_nul = o_content}, + OPNUL, + "CONTENT"}, /* unary hash op */ - {{.func_nul = o_hashop}, - OPNUL, - "HASHOP"}, /* binary hash op */ + {{.func_nul = o_hashop}, + OPNUL, + "HASHOP"}, /* binary hash op */ - {{.func_nul = o_backslash}, - OPNUL, - "BACKSLASH"}, /* unary backslash op */ + {{.func_nul = o_backslash}, + OPNUL, + "BACKSLASH"}, /* unary backslash op */ - {{.func_nul = o_setminus}, - OPNUL, - "SETMINUS"}, /* binary backslash op */ + {{.func_nul = o_setminus}, + OPNUL, + "SETMINUS"}, /* binary backslash op */ - {{.func_nul = o_plus}, - OPNUL, - "PLUS"}, /* unary + op */ + {{.func_nul = o_plus}, + OPNUL, + "PLUS"}, /* unary + op */ - {{.func_jmp = o_jumpnn}, - OPJMP, - "JUMPNN"}, /* jump if non-null */ + {{.func_jmp = o_jumpnn}, + OPJMP, + "JUMPNN"}, /* jump if non-null */ - {{.func_one = o_abort}, - OPONE, - "ABORT"} /* abort operation */ + {{.func_one = o_abort}, + OPONE, + "ABORT"} /* abort operation */ }; @@ -4089,167 +4089,167 @@ STATIC struct opcode opcodes[MAX_OPCODE+1] = { * Arguments have just been pushed onto the evaluation stack. * * given: - * fp function to calculate - * argcount number of arguments called with + * fp function to calculate + * argcount number of arguments called with */ void calculate(FUNC *fp, int argcount) { - register unsigned long pc; /* current pc inside function */ - register struct opcode *op; /* current opcode pointer */ - register VALUE *locals; /* pointer to local variables */ - long oldline; /* old value of line counter */ - unsigned int opnum; /* current opcode number */ - int origargcount; /* original number of arguments */ - unsigned int i; /* loop counter */ - bool dojump; /* true if jump is to occur */ - char *oldname; /* old function name being executed */ - VALUE *beginstack; /* beginning of stack frame */ - VALUE *args; /* pointer to function arguments */ - VALUE retval; /* function return value */ - VALUE localtable[QUICKLOCALS]; /* some local variables */ + register unsigned long pc; /* current pc inside function */ + register struct opcode *op; /* current opcode pointer */ + register VALUE *locals; /* pointer to local variables */ + long oldline; /* old value of line counter */ + unsigned int opnum; /* current opcode number */ + int origargcount; /* original number of arguments */ + unsigned int i; /* loop counter */ + bool dojump; /* true if jump is to occur */ + char *oldname; /* old function name being executed */ + VALUE *beginstack; /* beginning of stack frame */ + VALUE *args; /* pointer to function arguments */ + VALUE retval; /* function return value */ + VALUE localtable[QUICKLOCALS]; /* some local variables */ - oldname = funcname; - oldline = funcline; - funcname = fp->f_name; - funcline = 0; - go = true; - ++calc_depth; - origargcount = argcount; - while ((unsigned)argcount < fp->f_paramcount) { - stack++; - stack->v_type = V_NULL; - stack->v_subtype = V_NOSUBTYPE; - argcount++; - } - locals = localtable; - if (fp->f_localcount > QUICKLOCALS) { - locals = (VALUE *) malloc(sizeof(VALUE) * fp->f_localcount); - if (locals == NULL) { - math_error("No memory for local variables"); - not_reached(); - } - } - for (i = 0; i < fp->f_localcount; i++) { - locals[i].v_num = qlink(&_qzero_); - locals[i].v_type = V_NUM; - locals[i].v_subtype = V_NOSUBTYPE; - } - pc = 0; - beginstack = stack; - args = beginstack - (argcount - 1); - while (go) { - if (abortlevel >= ABORT_OPCODE) { - math_error("Calculation aborted in opcode"); - not_reached(); - } - if (pc >= fp->f_opcodecount) { - math_error("Function pc out of range"); - not_reached(); - } - if (stack > &stackarray[MAXSTACK-3]) { - math_error("Evaluation stack depth exceeded"); - not_reached(); - } - opnum = fp->f_opcodes[pc]; - if (opnum > MAX_OPCODE) { - math_error("Function opcode out of range"); - not_reached(); - } - op = &opcodes[opnum]; - if (conf->traceflags & TRACE_OPCODES) { - dumpnames = false; - printf("%8s, pc %4ld: ", fp->f_name, pc); - (void)dumpop(&fp->f_opcodes[pc]); - } - /* - * Now call the opcode routine appropriately. - */ - pc++; - switch (op->o_type) { - case OPNUL: /* no extra arguments */ - (*op->o_func.func_nul)(fp); - break; + oldname = funcname; + oldline = funcline; + funcname = fp->f_name; + funcline = 0; + go = true; + ++calc_depth; + origargcount = argcount; + while ((unsigned)argcount < fp->f_paramcount) { + stack++; + stack->v_type = V_NULL; + stack->v_subtype = V_NOSUBTYPE; + argcount++; + } + locals = localtable; + if (fp->f_localcount > QUICKLOCALS) { + locals = (VALUE *) malloc(sizeof(VALUE) * fp->f_localcount); + if (locals == NULL) { + math_error("No memory for local variables"); + not_reached(); + } + } + for (i = 0; i < fp->f_localcount; i++) { + locals[i].v_num = qlink(&_qzero_); + locals[i].v_type = V_NUM; + locals[i].v_subtype = V_NOSUBTYPE; + } + pc = 0; + beginstack = stack; + args = beginstack - (argcount - 1); + while (go) { + if (abortlevel >= ABORT_OPCODE) { + math_error("Calculation aborted in opcode"); + not_reached(); + } + if (pc >= fp->f_opcodecount) { + math_error("Function pc out of range"); + not_reached(); + } + if (stack > &stackarray[MAXSTACK-3]) { + math_error("Evaluation stack depth exceeded"); + not_reached(); + } + opnum = fp->f_opcodes[pc]; + if (opnum > MAX_OPCODE) { + math_error("Function opcode out of range"); + not_reached(); + } + op = &opcodes[opnum]; + if (conf->traceflags & TRACE_OPCODES) { + dumpnames = false; + printf("%8s, pc %4ld: ", fp->f_name, pc); + (void)dumpop(&fp->f_opcodes[pc]); + } + /* + * Now call the opcode routine appropriately. + */ + pc++; + switch (op->o_type) { + case OPNUL: /* no extra arguments */ + (*op->o_func.func_nul)(fp); + break; - case OPONE: /* one extra integer argument */ - (*op->o_func.func_one)(fp, fp->f_opcodes[pc++]); - break; + case OPONE: /* one extra integer argument */ + (*op->o_func.func_one)(fp, fp->f_opcodes[pc++]); + break; - case OPTWO: /* two extra integer arguments */ - (*op->o_func.func_two)(fp, fp->f_opcodes[pc], - fp->f_opcodes[pc+1]); - pc += 2; - break; + case OPTWO: /* two extra integer arguments */ + (*op->o_func.func_two)(fp, fp->f_opcodes[pc], + fp->f_opcodes[pc+1]); + pc += 2; + break; - case OPJMP: /* jump opcodes (one extra pointer arg) */ - dojump = false; - (*op->o_func.func_jmp)(fp, &dojump); - if (dojump) - pc = fp->f_opcodes[pc]; - else - pc++; - break; + case OPJMP: /* jump opcodes (one extra pointer arg) */ + dojump = false; + (*op->o_func.func_jmp)(fp, &dojump); + if (dojump) + pc = fp->f_opcodes[pc]; + else + pc++; + break; - case OPGLB: /* global symbol reference (pointer arg) */ - (*op->o_func.func_glb)(fp, (GLOBAL *)(*(&fp->f_opcodes[pc]))); - pc += PTR_SIZE; - break; + case OPGLB: /* global symbol reference (pointer arg) */ + (*op->o_func.func_glb)(fp, (GLOBAL *)(*(&fp->f_opcodes[pc]))); + pc += PTR_SIZE; + break; - case OPLOC: /* local variable reference */ - (*op->o_func.func_loc)(fp, locals, fp->f_opcodes[pc++]); - break; + case OPLOC: /* local variable reference */ + (*op->o_func.func_loc)(fp, locals, fp->f_opcodes[pc++]); + break; - case OPPAR: /* parameter variable reference */ - (*op->o_func.func_par)(fp, argcount, args, fp->f_opcodes[pc++]); - break; + case OPPAR: /* parameter variable reference */ + (*op->o_func.func_par)(fp, argcount, args, fp->f_opcodes[pc++]); + break; - case OPARG: /* parameter variable reference */ - (*op->o_func.func_arg)(fp, origargcount, args); - break; + case OPARG: /* parameter variable reference */ + (*op->o_func.func_arg)(fp, origargcount, args); + break; - case OPRET: /* return from function */ - if (stack->v_type == V_ADDR) - copyvalue(stack->v_addr, stack); - for (i = 0; i < fp->f_localcount; i++) - freevalue(&locals[i]); - if (locals != localtable) - free(locals); - if (stack != &beginstack[1]) { - math_error("Misaligned stack"); - not_reached(); - } - if (argcount > 0) { - retval = *stack--; - while (--argcount >= 0) - freevalue(stack--); - *++stack = retval; - } - funcname = oldname; - funcline = oldline; - --calc_depth; - return; + case OPRET: /* return from function */ + if (stack->v_type == V_ADDR) + copyvalue(stack->v_addr, stack); + for (i = 0; i < fp->f_localcount; i++) + freevalue(&locals[i]); + if (locals != localtable) + free(locals); + if (stack != &beginstack[1]) { + math_error("Misaligned stack"); + not_reached(); + } + if (argcount > 0) { + retval = *stack--; + while (--argcount >= 0) + freevalue(stack--); + *++stack = retval; + } + funcname = oldname; + funcline = oldline; + --calc_depth; + return; - case OPSTI: /* static initialization code */ - fp->f_opcodes[pc++ - 1] = OP_JUMP; - break; + case OPSTI: /* static initialization code */ + fp->f_opcodes[pc++ - 1] = OP_JUMP; + break; - default: - math_error("Unknown opcode type: %d", op->o_type); - not_reached(); - } - } - for (i = 0; i < fp->f_localcount; i++) - freevalue(&locals[i]); - if (locals != localtable) - free(locals); - if (conf->calc_debug & CALCDBG_FUNC_QUIT) - printf("\t\"%s\": line %ld\n", funcname, funcline); - while (stack > beginstack) - freevalue(stack--); - funcname = oldname; - funcline = oldline; - --calc_depth; - return; + default: + math_error("Unknown opcode type: %d", op->o_type); + not_reached(); + } + } + for (i = 0; i < fp->f_localcount; i++) + freevalue(&locals[i]); + if (locals != localtable) + free(locals); + if (conf->calc_debug & CALCDBG_FUNC_QUIT) + printf("\t\"%s\": line %ld\n", funcname, funcline); + while (stack > beginstack) + freevalue(stack--); + funcname = oldname; + funcline = oldline; + --calc_depth; + return; } @@ -4258,79 +4258,79 @@ calculate(FUNC *fp, int argcount) * Returns the size of the opcode so that it can easily be skipped over. * * given: - * pc location of the opcode + * pc location of the opcode */ int dumpop(unsigned long *pc) { - GLOBAL *sp; - unsigned long op; /* opcode number */ + GLOBAL *sp; + unsigned long op; /* opcode number */ - op = *pc++; - if (op <= MAX_OPCODE) - printf("%s", opcodes[op].o_name); - else - printf("OP%ld", op); - switch (op) { - case OP_LOCALADDR: case OP_LOCALVALUE: - if (dumpnames) - printf(" %s\n", localname((long)*pc)); - else - printf(" %ld\n", *pc); - return 2; - case OP_GLOBALADDR: case OP_GLOBALVALUE: - sp = * (GLOBAL **) pc; - printf(" %s", sp->g_name); - if (sp->g_filescope > SCOPE_GLOBAL) - printf(" %p", (void *) &sp->g_value); - putchar('\n'); - return (1 + PTR_SIZE); - case OP_PARAMADDR: case OP_PARAMVALUE: - if (dumpnames) - printf(" %s\n", paramname((long)*pc)); - else - printf(" %ld\n", *pc); - return 2; - case OP_PRINTSTRING: case OP_STRING: - printf(" \"%s\"\n", findstring((long)(*pc))->s_str); - return 2; - case OP_QUIT: case OP_ABORT: - if ((long)(*pc) >= 0) - printf(" \"%s\"", findstring((long)(*pc))->s_str); - putchar('\n'); - return 2; - case OP_INDEXADDR: - printf(" %ld %ld\n", pc[0], pc[1]); - return 3; - case OP_PRINT: case OP_JUMPZ: case OP_JUMPNZ: case OP_JUMP: - case OP_CONDORJUMP: case OP_CONDANDJUMP: case OP_CASEJUMP: - case OP_INITSTATIC: case OP_MATCREATE: - case OP_SHOW: case OP_ELEMINIT: case OP_ELEMADDR: - case OP_ELEMVALUE: case OP_JUMPNN: - printf(" %ld\n", *pc); - return 2; - case OP_OBJCREATE: - printf(" %s\n", objtypename(*pc)); - return 2; - case OP_NUMBER: case OP_IMAGINARY: - qprintf(" %r", constvalue(*pc)); - printf("\n"); - return 2; - case OP_DEBUG: - printf(" line %ld\n", *pc); - return 2; - case OP_CALL: - printf(" %s with %ld args\n", - builtinname((long)pc[0]), (long)pc[1]); - return 3; - case OP_USERCALL: - printf(" %s with %ld args\n", - namefunc((long)pc[0]), (long)pc[1]); - return 3; - default: - printf("\n"); - return 1; - } + op = *pc++; + if (op <= MAX_OPCODE) + printf("%s", opcodes[op].o_name); + else + printf("OP%ld", op); + switch (op) { + case OP_LOCALADDR: case OP_LOCALVALUE: + if (dumpnames) + printf(" %s\n", localname((long)*pc)); + else + printf(" %ld\n", *pc); + return 2; + case OP_GLOBALADDR: case OP_GLOBALVALUE: + sp = * (GLOBAL **) pc; + printf(" %s", sp->g_name); + if (sp->g_filescope > SCOPE_GLOBAL) + printf(" %p", (void *) &sp->g_value); + putchar('\n'); + return (1 + PTR_SIZE); + case OP_PARAMADDR: case OP_PARAMVALUE: + if (dumpnames) + printf(" %s\n", paramname((long)*pc)); + else + printf(" %ld\n", *pc); + return 2; + case OP_PRINTSTRING: case OP_STRING: + printf(" \"%s\"\n", findstring((long)(*pc))->s_str); + return 2; + case OP_QUIT: case OP_ABORT: + if ((long)(*pc) >= 0) + printf(" \"%s\"", findstring((long)(*pc))->s_str); + putchar('\n'); + return 2; + case OP_INDEXADDR: + printf(" %ld %ld\n", pc[0], pc[1]); + return 3; + case OP_PRINT: case OP_JUMPZ: case OP_JUMPNZ: case OP_JUMP: + case OP_CONDORJUMP: case OP_CONDANDJUMP: case OP_CASEJUMP: + case OP_INITSTATIC: case OP_MATCREATE: + case OP_SHOW: case OP_ELEMINIT: case OP_ELEMADDR: + case OP_ELEMVALUE: case OP_JUMPNN: + printf(" %ld\n", *pc); + return 2; + case OP_OBJCREATE: + printf(" %s\n", objtypename(*pc)); + return 2; + case OP_NUMBER: case OP_IMAGINARY: + qprintf(" %r", constvalue(*pc)); + printf("\n"); + return 2; + case OP_DEBUG: + printf(" line %ld\n", *pc); + return 2; + case OP_CALL: + printf(" %s with %ld args\n", + builtinname((long)pc[0]), (long)pc[1]); + return 3; + case OP_USERCALL: + printf(" %s with %ld args\n", + namefunc((long)pc[0]), (long)pc[1]); + return 3; + default: + printf("\n"); + return 1; + } } @@ -4340,59 +4340,59 @@ dumpop(unsigned long *pc) void freenumbers(FUNC *fp) { - unsigned long pc; - unsigned int opnum; - struct opcode *op; + unsigned long pc; + unsigned int opnum; + struct opcode *op; - for (pc = 0; pc < fp->f_opcodecount; ) { - opnum = fp->f_opcodes[pc++]; - op = &opcodes[opnum]; - switch (op->o_type) { - case OPRET: - case OPARG: - case OPNUL: - continue; - case OPONE: - switch(opnum) { - case OP_NUMBER: - case OP_IMAGINARY: - freeconstant(fp->f_opcodes[pc]); - break; - case OP_PRINTSTRING: - case OP_STRING: - case OP_QUIT: - freestringconstant( - (long)fp->f_opcodes[pc]); - break; - } - /*FALLTHRU*/ - case OPLOC: - case OPPAR: - case OPJMP: - case OPSTI: - pc++; - continue; - case OPTWO: - pc += 2; - continue; - case OPGLB: - pc += PTR_SIZE; - continue; - default: - math_error("Unknown opcode type for freeing"); - not_reached(); - } - } - if (pc != fp->f_opcodecount) { - math_error("Incorrect opcodecount ???"); - not_reached(); - } - trimconstants(); + for (pc = 0; pc < fp->f_opcodecount; ) { + opnum = fp->f_opcodes[pc++]; + op = &opcodes[opnum]; + switch (op->o_type) { + case OPRET: + case OPARG: + case OPNUL: + continue; + case OPONE: + switch(opnum) { + case OP_NUMBER: + case OP_IMAGINARY: + freeconstant(fp->f_opcodes[pc]); + break; + case OP_PRINTSTRING: + case OP_STRING: + case OP_QUIT: + freestringconstant( + (long)fp->f_opcodes[pc]); + break; + } + /*FALLTHRU*/ + case OPLOC: + case OPPAR: + case OPJMP: + case OPSTI: + pc++; + continue; + case OPTWO: + pc += 2; + continue; + case OPGLB: + pc += PTR_SIZE; + continue; + default: + math_error("Unknown opcode type for freeing"); + not_reached(); + } + } + if (pc != fp->f_opcodecount) { + math_error("Incorrect opcodecount ???"); + not_reached(); + } + trimconstants(); } long calclevel(void) { - return calc_depth - 1; + return calc_depth - 1; } diff --git a/opcodes.h b/opcodes.h index 406bfee..16d020c 100644 --- a/opcodes.h +++ b/opcodes.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:35 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:35 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,7 +28,7 @@ #define INCLUDE_OPCODES_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "decl.h" #else # include @@ -38,146 +38,146 @@ /* * Opcodes */ -#define OP_NOP 0L /* no operation */ -#define OP_LOCALADDR 1L /* load address of local variable */ -#define OP_GLOBALADDR 2L /* load address of global variable */ -#define OP_PARAMADDR 3L /* load address of parameter variable */ -#define OP_LOCALVALUE 4L /* load value of local variable */ -#define OP_GLOBALVALUE 5L /* load value of global variable */ -#define OP_PARAMVALUE 6L /* load value of parameter variable */ -#define OP_NUMBER 7L /* load constant real numeric value */ -#define OP_INDEXADDR 8L /* load array index address */ -#define OP_PRINTRESULT 9L /* print result of top-level expression */ -#define OP_ASSIGN 10L /* assign value to variable */ -#define OP_ADD 11L /* add top two values */ -#define OP_SUB 12L /* subtract top two values */ -#define OP_MUL 13L /* multiply top two values */ -#define OP_DIV 14L /* divide top two values */ -#define OP_MOD 15L /* take mod of top two values */ -#define OP_SAVE 16L /* save value for later use */ -#define OP_NEGATE 17L /* negate top value */ -#define OP_INVERT 18L /* invert top value */ -#define OP_INT 19L /* take integer part of top value */ -#define OP_FRAC 20L /* take fraction part of top value */ -#define OP_NUMERATOR 21L /* take numerator of top value */ -#define OP_DENOMINATOR 22L /* take denominator of top value */ -#define OP_DUPLICATE 23L /* duplicate top value on stack */ -#define OP_POP 24L /* pop top value from stack */ -#define OP_RETURN 25L /* return value of function */ -#define OP_JUMPZ 26L /* jump if top value is zero */ -#define OP_JUMPNZ 27L /* jump if top value is nonzero */ -#define OP_JUMP 28L /* jump unconditionally */ -#define OP_USERCALL 29L /* call a user-defined function */ -#define OP_GETVALUE 30L /* convert address to value */ -#define OP_EQ 31L /* test top two elements for equality */ -#define OP_NE 32L /* test top two elements for inequality */ -#define OP_LE 33L /* test top two elements for <= */ -#define OP_GE 34L /* test top two elements for >= */ -#define OP_LT 35L /* test top two elements for < */ -#define OP_GT 36L /* test top two elements for > */ -#define OP_PREINC 37L /* add one to variable (++x) */ -#define OP_PREDEC 38L /* subtract one from variable (--x) */ -#define OP_POSTINC 39L /* add one to variable (x++) */ -#define OP_POSTDEC 40L /* subtract one from variable (x--) */ -#define OP_DEBUG 41L /* debugging point */ -#define OP_PRINT 42L /* print value */ -#define OP_ASSIGNPOP 43L /* assign to variable and remove it */ -#define OP_ZERO 44L /* put zero on the stack */ -#define OP_ONE 45L /* put one on the stack */ -#define OP_PRINTEOL 46L /* print end of line */ -#define OP_PRINTSPACE 47L /* print a space */ -#define OP_PRINTSTRING 48L /* print constant string */ -#define OP_DUPVALUE 49L /* duplicate value of top value */ -#define OP_OLDVALUE 50L /* old calculation value */ -#define OP_QUO 51L /* integer quotient of top two values */ -#define OP_POWER 52L /* number raised to a power */ -#define OP_QUIT 53L /* quit program */ -#define OP_CALL 54L /* call built-in routine */ -#define OP_GETEPSILON 55L /* get allowed error for calculations */ -#define OP_AND 56L /* arithmetic and */ -#define OP_OR 57L /* arithmetic or */ -#define OP_NOT 58L /* logical not */ -#define OP_ABS 59L /* absolute value */ -#define OP_SGN 60L /* sign of number */ -#define OP_ISINT 61L /* whether top value is integer */ -#define OP_CONDORJUMP 62L /* conditional or jump */ -#define OP_CONDANDJUMP 63L /* conditional and jump */ -#define OP_SQUARE 64L /* square top value */ -#define OP_STRING 65L /* load constant string value */ -#define OP_ISNUM 66L /* whether top value is a number */ -#define OP_UNDEF 67L /* load undefined value on stack */ -#define OP_ISNULL 68L /* whether variable is the null value */ -#define OP_ARGVALUE 69L /* load value of argument (parameter) n */ -#define OP_MATCREATE 70L /* create matrix */ -#define OP_ISMAT 71L /* whether variable is a matrix */ -#define OP_ISSTR 72L /* whether variable is a string */ -#define OP_GETCONFIG 73L /* get value of configuration parameter */ -#define OP_LEFTSHIFT 74L /* left shift of integer */ -#define OP_RIGHTSHIFT 75L /* right shift of integer */ -#define OP_CASEJUMP 76L /* test case and jump if not matched */ -#define OP_ISODD 77L /* whether value is an odd integer */ -#define OP_ISEVEN 78L /* whether value is even integer */ -#define OP_FIADDR 79L /* 'fast index' matrix value address */ -#define OP_FIVALUE 80L /* 'fast index' matrix value */ -#define OP_ISREAL 81L /* test value for real number */ -#define OP_IMAGINARY 82L /* load imaginary numeric constant */ -#define OP_RE 83L /* real part of complex number */ -#define OP_IM 84L /* imaginary part of complex number */ -#define OP_CONJUGATE 85L /* complex conjugate of complex number */ -#define OP_OBJCREATE 86L /* create object */ -#define OP_ISOBJ 87L /* whether value is an object */ -#define OP_NORM 88L /* norm of value (square of abs) */ -#define OP_ELEMADDR 89L /* address of element of object */ -#define OP_ELEMVALUE 90L /* value of element of object */ -#define OP_ISTYPE 91L /* whether two values are the same type */ -#define OP_SCALE 92L /* scale value by a power of two */ -#define OP_ISLIST 93L /* whether value is a list */ -#define OP_SWAP 94L /* swap values of two variables */ -#define OP_ISSIMPLE 95L /* whether value is a simple type */ -#define OP_CMP 96L /* compare values returning -1, 0, or 1 */ -#define OP_SETCONFIG 97L /* set configuration parameter */ -#define OP_SETEPSILON 98L /* set allowed error for calculations */ -#define OP_ISFILE 99L /* whether value is a file */ -#define OP_ISASSOC 100L /* whether value is an association */ -#define OP_INITSTATIC 101L /* once only code for static initialization */ -#define OP_ELEMINIT 102L /* assign element of matrix or object */ -#define OP_ISCONFIG 103L /* whether value is a configuration state */ -#define OP_ISHASH 104L /* whether value is a hash state */ -#define OP_ISRAND 105L /* whether value is subtractive 100 state */ -#define OP_ISRANDOM 106L /* whether value is a Blum random state */ -#define OP_SHOW 107L /* show data about current state */ -#define OP_INITFILL 108L /* fill new matrix with copies of a value */ -#define OP_ASSIGNBACK 109L /* assign in reverse order */ -#define OP_TEST 110L /* test whether value is "nonzero" */ -#define OP_ISDEFINED 111L /* whether string names a function */ -#define OP_ISOBJTYPE 112L /* whether string names an object type */ -#define OP_ISBLK 113L /* whether value is a block */ -#define OP_PTR 114L /* octet pointer */ -#define OP_DEREF 115L /* dereference an octet pointer */ -#define OP_ISOCTET 116L /* whether value is an octet */ -#define OP_ISPTR 117L /* whether value is a pointer */ -#define OP_SAVEVAL 118L /* activate updating */ -#define OP_LINKS 119L /* return links for numbers and strings */ -#define OP_BIT 120L /* whether specified bit is set */ -#define OP_COMP 121L /* complement value */ -#define OP_XOR 122L /* xor (~) of values */ -#define OP_HIGHBIT 123L /* index of high bit of value */ -#define OP_LOWBIT 124L /* index of low bit of value */ -#define OP_CONTENT 125L /* value returned by unary # */ -#define OP_HASHOP 126L /* binary # */ -#define OP_BACKSLASH 127L /* unary backslash */ -#define OP_SETMINUS 128L /* binary backslash */ -#define OP_PLUS 129L /* unary + */ -#define OP_JUMPNN 130L /* jump if top value is non-null */ -#define OP_ABORT 131L /* abort operation */ -#define MAX_OPCODE 131L /* highest legal opcode */ +#define OP_NOP 0L /* no operation */ +#define OP_LOCALADDR 1L /* load address of local variable */ +#define OP_GLOBALADDR 2L /* load address of global variable */ +#define OP_PARAMADDR 3L /* load address of parameter variable */ +#define OP_LOCALVALUE 4L /* load value of local variable */ +#define OP_GLOBALVALUE 5L /* load value of global variable */ +#define OP_PARAMVALUE 6L /* load value of parameter variable */ +#define OP_NUMBER 7L /* load constant real numeric value */ +#define OP_INDEXADDR 8L /* load array index address */ +#define OP_PRINTRESULT 9L /* print result of top-level expression */ +#define OP_ASSIGN 10L /* assign value to variable */ +#define OP_ADD 11L /* add top two values */ +#define OP_SUB 12L /* subtract top two values */ +#define OP_MUL 13L /* multiply top two values */ +#define OP_DIV 14L /* divide top two values */ +#define OP_MOD 15L /* take mod of top two values */ +#define OP_SAVE 16L /* save value for later use */ +#define OP_NEGATE 17L /* negate top value */ +#define OP_INVERT 18L /* invert top value */ +#define OP_INT 19L /* take integer part of top value */ +#define OP_FRAC 20L /* take fraction part of top value */ +#define OP_NUMERATOR 21L /* take numerator of top value */ +#define OP_DENOMINATOR 22L /* take denominator of top value */ +#define OP_DUPLICATE 23L /* duplicate top value on stack */ +#define OP_POP 24L /* pop top value from stack */ +#define OP_RETURN 25L /* return value of function */ +#define OP_JUMPZ 26L /* jump if top value is zero */ +#define OP_JUMPNZ 27L /* jump if top value is nonzero */ +#define OP_JUMP 28L /* jump unconditionally */ +#define OP_USERCALL 29L /* call a user-defined function */ +#define OP_GETVALUE 30L /* convert address to value */ +#define OP_EQ 31L /* test top two elements for equality */ +#define OP_NE 32L /* test top two elements for inequality */ +#define OP_LE 33L /* test top two elements for <= */ +#define OP_GE 34L /* test top two elements for >= */ +#define OP_LT 35L /* test top two elements for < */ +#define OP_GT 36L /* test top two elements for > */ +#define OP_PREINC 37L /* add one to variable (++x) */ +#define OP_PREDEC 38L /* subtract one from variable (--x) */ +#define OP_POSTINC 39L /* add one to variable (x++) */ +#define OP_POSTDEC 40L /* subtract one from variable (x--) */ +#define OP_DEBUG 41L /* debugging point */ +#define OP_PRINT 42L /* print value */ +#define OP_ASSIGNPOP 43L /* assign to variable and remove it */ +#define OP_ZERO 44L /* put zero on the stack */ +#define OP_ONE 45L /* put one on the stack */ +#define OP_PRINTEOL 46L /* print end of line */ +#define OP_PRINTSPACE 47L /* print a space */ +#define OP_PRINTSTRING 48L /* print constant string */ +#define OP_DUPVALUE 49L /* duplicate value of top value */ +#define OP_OLDVALUE 50L /* old calculation value */ +#define OP_QUO 51L /* integer quotient of top two values */ +#define OP_POWER 52L /* number raised to a power */ +#define OP_QUIT 53L /* quit program */ +#define OP_CALL 54L /* call built-in routine */ +#define OP_GETEPSILON 55L /* get allowed error for calculations */ +#define OP_AND 56L /* arithmetic and */ +#define OP_OR 57L /* arithmetic or */ +#define OP_NOT 58L /* logical not */ +#define OP_ABS 59L /* absolute value */ +#define OP_SGN 60L /* sign of number */ +#define OP_ISINT 61L /* whether top value is integer */ +#define OP_CONDORJUMP 62L /* conditional or jump */ +#define OP_CONDANDJUMP 63L /* conditional and jump */ +#define OP_SQUARE 64L /* square top value */ +#define OP_STRING 65L /* load constant string value */ +#define OP_ISNUM 66L /* whether top value is a number */ +#define OP_UNDEF 67L /* load undefined value on stack */ +#define OP_ISNULL 68L /* whether variable is the null value */ +#define OP_ARGVALUE 69L /* load value of argument (parameter) n */ +#define OP_MATCREATE 70L /* create matrix */ +#define OP_ISMAT 71L /* whether variable is a matrix */ +#define OP_ISSTR 72L /* whether variable is a string */ +#define OP_GETCONFIG 73L /* get value of configuration parameter */ +#define OP_LEFTSHIFT 74L /* left shift of integer */ +#define OP_RIGHTSHIFT 75L /* right shift of integer */ +#define OP_CASEJUMP 76L /* test case and jump if not matched */ +#define OP_ISODD 77L /* whether value is an odd integer */ +#define OP_ISEVEN 78L /* whether value is even integer */ +#define OP_FIADDR 79L /* 'fast index' matrix value address */ +#define OP_FIVALUE 80L /* 'fast index' matrix value */ +#define OP_ISREAL 81L /* test value for real number */ +#define OP_IMAGINARY 82L /* load imaginary numeric constant */ +#define OP_RE 83L /* real part of complex number */ +#define OP_IM 84L /* imaginary part of complex number */ +#define OP_CONJUGATE 85L /* complex conjugate of complex number */ +#define OP_OBJCREATE 86L /* create object */ +#define OP_ISOBJ 87L /* whether value is an object */ +#define OP_NORM 88L /* norm of value (square of abs) */ +#define OP_ELEMADDR 89L /* address of element of object */ +#define OP_ELEMVALUE 90L /* value of element of object */ +#define OP_ISTYPE 91L /* whether two values are the same type */ +#define OP_SCALE 92L /* scale value by a power of two */ +#define OP_ISLIST 93L /* whether value is a list */ +#define OP_SWAP 94L /* swap values of two variables */ +#define OP_ISSIMPLE 95L /* whether value is a simple type */ +#define OP_CMP 96L /* compare values returning -1, 0, or 1 */ +#define OP_SETCONFIG 97L /* set configuration parameter */ +#define OP_SETEPSILON 98L /* set allowed error for calculations */ +#define OP_ISFILE 99L /* whether value is a file */ +#define OP_ISASSOC 100L /* whether value is an association */ +#define OP_INITSTATIC 101L /* once only code for static initialization */ +#define OP_ELEMINIT 102L /* assign element of matrix or object */ +#define OP_ISCONFIG 103L /* whether value is a configuration state */ +#define OP_ISHASH 104L /* whether value is a hash state */ +#define OP_ISRAND 105L /* whether value is subtractive 100 state */ +#define OP_ISRANDOM 106L /* whether value is a Blum random state */ +#define OP_SHOW 107L /* show data about current state */ +#define OP_INITFILL 108L /* fill new matrix with copies of a value */ +#define OP_ASSIGNBACK 109L /* assign in reverse order */ +#define OP_TEST 110L /* test whether value is "nonzero" */ +#define OP_ISDEFINED 111L /* whether string names a function */ +#define OP_ISOBJTYPE 112L /* whether string names an object type */ +#define OP_ISBLK 113L /* whether value is a block */ +#define OP_PTR 114L /* octet pointer */ +#define OP_DEREF 115L /* dereference an octet pointer */ +#define OP_ISOCTET 116L /* whether value is an octet */ +#define OP_ISPTR 117L /* whether value is a pointer */ +#define OP_SAVEVAL 118L /* activate updating */ +#define OP_LINKS 119L /* return links for numbers and strings */ +#define OP_BIT 120L /* whether specified bit is set */ +#define OP_COMP 121L /* complement value */ +#define OP_XOR 122L /* xor (~) of values */ +#define OP_HIGHBIT 123L /* index of high bit of value */ +#define OP_LOWBIT 124L /* index of low bit of value */ +#define OP_CONTENT 125L /* value returned by unary # */ +#define OP_HASHOP 126L /* binary # */ +#define OP_BACKSLASH 127L /* unary backslash */ +#define OP_SETMINUS 128L /* binary backslash */ +#define OP_PLUS 129L /* unary + */ +#define OP_JUMPNN 130L /* jump if top value is non-null */ +#define OP_ABORT 131L /* abort operation */ +#define MAX_OPCODE 131L /* highest legal opcode */ /* * external declarations */ -EXTERN char *funcname; /* function being executed */ -EXTERN long funcline; /* function line being executed */ +EXTERN char *funcname; /* function being executed */ +EXTERN long funcline; /* function line being executed */ #endif /* !INCLUDE_OPCODES_H */ diff --git a/pix.c b/pix.c index 8e04ad1..bf5e31a 100644 --- a/pix.c +++ b/pix.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1994/07/01 19:44:21 - * File existed as early as: 1994 + * Under source code control: 1994/07/01 19:44:21 + * File existed as early as: 1994 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -30,13 +30,13 @@ #include "have_const.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* * pi10b - number of primes <= 2^18 in multiples of 2^10 * - * pi10b[x] == pi(x*1024) for 0 <= x <= 256 + * pi10b[x] == pi(x*1024) for 0 <= x <= 256 */ CONST unsigned short pi10b[(MAX_PI10B/1024)+1+1] = { 0, 172, 309, 439, 564, 685, 801, 916, 1028, 1142, 1254, 1362, 1469, 1580, @@ -68,7 +68,7 @@ CONST unsigned short pi10b[(MAX_PI10B/1024)+1+1] = { * pi18b - primes found in a given 2^18 interval * * i /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ #include "value.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ bool evp(LISTELEM *cp, LISTELEM *x, VALUE *vres) { - VALUE v, tmp1, tmp2; - bool s; + VALUE v, tmp1, tmp2; + bool s; - s = false; - while (cp) { - if (s) { - mulvalue(vres, &x->e_value, &tmp1); - freevalue(vres); - *vres = tmp1; - } - v = cp->e_value; - if (v.v_type == V_LIST) { - if (evalpoly(v.v_list, x->e_next, &tmp1)) { - if (s) { - addvalue(&tmp1, vres, &tmp2); - freevalue(&tmp1); - freevalue(vres); - *vres = tmp2; - } else { - s = true; - *vres = tmp1; - } - } - } else { - if (s) { - addvalue(&v, vres, &tmp1); - freevalue(vres); - *vres = tmp1; - } else { - s = true; - copyvalue(&v, vres); - } - } - cp = cp->e_prev; - } - return s; + s = false; + while (cp) { + if (s) { + mulvalue(vres, &x->e_value, &tmp1); + freevalue(vres); + *vres = tmp1; + } + v = cp->e_value; + if (v.v_type == V_LIST) { + if (evalpoly(v.v_list, x->e_next, &tmp1)) { + if (s) { + addvalue(&tmp1, vres, &tmp2); + freevalue(&tmp1); + freevalue(vres); + *vres = tmp2; + } else { + s = true; + *vres = tmp1; + } + } + } else { + if (s) { + addvalue(&v, vres, &tmp1); + freevalue(vres); + *vres = tmp1; + } else { + s = true; + copyvalue(&v, vres); + } + } + cp = cp->e_prev; + } + return s; } bool evalpoly(LIST *clist, LISTELEM *x, VALUE *vres) { - LISTELEM *cp; - VALUE v; + LISTELEM *cp; + VALUE v; - cp = clist->l_first; - if (cp == NULL) - return false; - if (x == NULL) { - v = cp->e_value; - if (v.v_type == V_LIST) - return evalpoly(v.v_list, x->e_next, vres); - copyvalue(&v, vres); - return true; - } - return evp(clist->l_last, x, vres); + cp = clist->l_first; + if (cp == NULL) + return false; + if (x == NULL) { + v = cp->e_value; + if (v.v_type == V_LIST) + return evalpoly(v.v_list, x->e_next, vres); + copyvalue(&v, vres); + return true; + } + return evp(clist->l_last, x, vres); } void insertitems(LIST *lp1, LIST *lp2) { - LISTELEM *ep; + LISTELEM *ep; - for (ep = lp2->l_first; ep; ep = ep->e_next) { - if (ep->e_value.v_type == V_LIST) - insertitems(lp1, ep->e_value.v_list); - else - insertlistlast(lp1, &ep->e_value); - } + for (ep = lp2->l_first; ep; ep = ep->e_next) { + if (ep->e_value.v_type == V_LIST) + insertitems(lp1, ep->e_value.v_list); + else + insertlistlast(lp1, &ep->e_value); + } } long countlistitems(LIST *lp) { - LISTELEM *ep; + LISTELEM *ep; - long n = 0; - for (ep = lp->l_first; ep; ep = ep->e_next) { - if (ep->e_value.v_type == V_LIST) - n += countlistitems(ep->e_value.v_list); - else - n++; - } - return n; + long n = 0; + for (ep = lp->l_first; ep; ep = ep->e_next) { + if (ep->e_value.v_type == V_LIST) + n += countlistitems(ep->e_value.v_list); + else + n++; + } + return n; } void addlistitems(LIST *lp, VALUE *vres) { - LISTELEM *ep; - VALUE tmp; + LISTELEM *ep; + VALUE tmp; - for (ep = lp->l_first; ep; ep = ep->e_next) { - addvalue(vres, &ep->e_value, &tmp); - freevalue(vres); - *vres = tmp; - if (vres->v_type < 0) - return; - } + for (ep = lp->l_first; ep; ep = ep->e_next) { + addvalue(vres, &ep->e_value, &tmp); + freevalue(vres); + *vres = tmp; + if (vres->v_type < 0) + return; + } } void addlistinv(LIST *lp, VALUE *vres) { - LISTELEM *ep; - VALUE tmp1, tmp2; + LISTELEM *ep; + VALUE tmp1, tmp2; - for (ep = lp->l_first; ep; ep = ep->e_next) { - if (ep->e_value.v_type == V_LIST) { - addlistinv(ep->e_value.v_list, vres); - } else { - invertvalue(&ep->e_value, &tmp1); - addvalue(vres, &tmp1, &tmp2); - freevalue(&tmp1); - freevalue(vres); - *vres = tmp2; - } - if (vres->v_type < 0) - return; - } + for (ep = lp->l_first; ep; ep = ep->e_next) { + if (ep->e_value.v_type == V_LIST) { + addlistinv(ep->e_value.v_list, vres); + } else { + invertvalue(&ep->e_value, &tmp1); + addvalue(vres, &tmp1, &tmp2); + freevalue(&tmp1); + freevalue(vres); + *vres = tmp2; + } + if (vres->v_type < 0) + return; + } } diff --git a/prime.c b/prime.c index d1e817a..5cc8487 100644 --- a/prime.c +++ b/prime.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1994/06/04 03:26:14 - * File existed as early as: 1994 + * Under source code control: 1994/06/04 03:26:14 + * File existed as early as: 1994 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -31,14 +31,14 @@ #include "have_const.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* * odd prime bitmap for odd values < 2^16 * - * pr_map[i] & (1< i*16 + j*2 + 1 is prime - * 0 ==> i*16 + j*2 + 1 is not prime + * pr_map[i] & (1< i*16 + j*2 + 1 is prime + * 0 ==> i*16 + j*2 + 1 is not prime * * This table is useful to quickly determine if a 16 bit odd number * is prime. Use the prime[] array to quickly walk thru the 16 bit @@ -312,18 +312,18 @@ CONST unsigned char pr_map[(MAX_MAP_VAL/8)+1] = { * * We end the list with the value 1. Thus, loops of the form: * - * FULL isqr, n; - * unsigned short *tp; + * FULL isqr, n; + * unsigned short *tp; * - * for (isqr=fsqrt(n), tp=prime; (*tp <= isqr) && (n % *tp); ++tp) { - * } + * for (isqr=fsqrt(n), tp=prime; (*tp <= isqr) && (n % *tp); ++tp) { + * } * * will terminate because *tp == 1 and thus (n % *tp) == 0. To determine if * a factor was found, one must: * - * if (*tp <= isqr && *tp != 1) { - * *tp is a factor of n - * } + * if (*tp <= isqr && *tp != 1) { + * *tp is a factor of n + * } */ CONST unsigned short prime[MAP_POPCNT+1] = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, diff --git a/prime.h b/prime.h index 9eaead6..3ccecaa 100644 --- a/prime.h +++ b/prime.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1994/06/04 03:26:15 - * File existed as early as: 1994 + * Under source code control: 1994/06/04 03:26:15 + * File existed as early as: 1994 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -29,7 +29,7 @@ #define INCLUDE_PRIME_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "qmath.h" # include "have_const.h" #else @@ -38,33 +38,33 @@ #endif -#define MAX_MAP_PRIME ((FULL)65521) /* (2^16-15) largest prime in prmap */ -#define MAX_MAP_VAL ((FULL)65535) /* (2^16-1) largest bit in pr_map */ -#define MAX_SM_PRIME ((FULL)0xfffffffb) /* (2^32-5) largest 32 bit prime */ -#define MAX_SM_VAL ((FULL)0xffffffff) /* (2^32-1) largest 32 bit value */ +#define MAX_MAP_PRIME ((FULL)65521) /* (2^16-15) largest prime in prmap */ +#define MAX_MAP_VAL ((FULL)65535) /* (2^16-1) largest bit in pr_map */ +#define MAX_SM_PRIME ((FULL)0xfffffffb) /* (2^32-5) largest 32 bit prime */ +#define MAX_SM_VAL ((FULL)0xffffffff) /* (2^32-1) largest 32 bit value */ -#define MAP_POPCNT 6541 /* number of odd primes in pr_map */ +#define MAP_POPCNT 6541 /* number of odd primes in pr_map */ -#define NXT_MAP_PRIME ((FULL)65537) /* (2^16+1) smallest prime > 2^16 */ +#define NXT_MAP_PRIME ((FULL)65537) /* (2^16+1) smallest prime > 2^16 */ -#define PIX_32B ((FULL)203280221) /* pix(2^32-1) - max pix() value */ +#define PIX_32B ((FULL)203280221) /* pix(2^32-1) - max pix() value */ /* * product of primes that fit into a long */ #if BASEB == 32 -#define MAX_PFACT_VAL 52 /* max x, for which pfact(x) is a long */ -#define NXT_PFACT_VAL 14 /* next prime for higher pfact values */ +#define MAX_PFACT_VAL 52 /* max x, for which pfact(x) is a long */ +#define NXT_PFACT_VAL 14 /* next prime for higher pfact values */ #else -#define MAX_PFACT_VAL 28 /* max x, for which pfact(x) is a long */ -#define NXT_PFACT_VAL 8 /* next prime for higher pfact values */ +#define MAX_PFACT_VAL 28 /* max x, for which pfact(x) is a long */ +#define NXT_PFACT_VAL 8 /* next prime for higher pfact values */ #endif /* * If n is odd and 1 <= n <= MAX_MAP_VAL, then: * - * pr_map_bit(n) != 0 ==> n is prime - * pr_map_bit(n) == 0 ==> n is NOT prime + * pr_map_bit(n) != 0 ==> n is prime + * pr_map_bit(n) == 0 ==> n is NOT prime */ #define pr_map_bit(n) (pr_map[(HALF)(n)>>4] & (1 << (((HALF)(n)>>1)&0x7))) @@ -72,8 +72,8 @@ * Limits for piXb tables. Do not test about this value using the * given table, even though the table has a higher sentinel value. */ -#define MAX_PI10B ((1024*256)-1) /* largest pi10b value to test */ -#define MAX_PI18B ((FULL)(0xFFFFFFFF)) /* largest pi18b value to test */ +#define MAX_PI10B ((1024*256)-1) /* largest pi10b value to test */ +#define MAX_PI18B ((FULL)(0xFFFFFFFF)) /* largest pi18b value to test */ /* * Prime related external arrays. @@ -82,9 +82,9 @@ EXTERN CONST unsigned short prime[]; EXTERN CONST unsigned char pr_map[]; EXTERN CONST unsigned short pi10b[]; EXTERN CONST unsigned short pi18b[]; -EXTERN NUMBER _nxtprime_; /* 2^32+15 - smallest prime > 2^32 */ -EXTERN CONST ZVALUE _nxt_prime_; /* 2^32+15 - smallest prime > 2^32 */ -EXTERN CONST ZVALUE _jmpmod2_; /* JMPMOD*2 as a ZVALUE */ +EXTERN NUMBER _nxtprime_; /* 2^32+15 - smallest prime > 2^32 */ +EXTERN CONST ZVALUE _nxt_prime_; /* 2^32+15 - smallest prime > 2^32 */ +EXTERN CONST ZVALUE _jmpmod2_; /* JMPMOD*2 as a ZVALUE */ #endif /* !INCLUDE_PRIME_H */ diff --git a/qfunc.c b/qfunc.c index bb1d2fe..acbebae 100644 --- a/qfunc.c +++ b/qfunc.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:20 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:20 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -32,7 +32,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ STATIC NUMBER **B_table; @@ -48,20 +48,20 @@ STATIC long E_num; * check_epsilon - verify that 0 < epsilon < 1 * * given: - * q epsilon or eps argument + * q epsilon or eps argument * * returns: - * false q is NULL or q <= 0 or q >= 1 - * true 0 < q < 1 + * false q is NULL or q <= 0 or q >= 1 + * true 0 < q < 1 */ bool check_epsilon(NUMBER *q) { /* verify that 0 < epsilon < 1 */ if (q == NULL || qisneg(q) || qiszero(q) || qisone(q) || qreli(q, 1) > 0) { - return false; - } - return true; + return false; + } + return true; } @@ -70,85 +70,85 @@ check_epsilon(NUMBER *q) * This must be greater than zero. * * given: - * q number to be set as the new epsilon + * q number to be set as the new epsilon */ void setepsilon(NUMBER *q) { - NUMBER *old; + NUMBER *old; - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(q) == false) { - math_error("Invalid value for epsilon: must be: 0 < epsilon < 1"); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(q) == false) { + math_error("Invalid value for epsilon: must be: 0 < epsilon < 1"); + not_reached(); + } - old = conf->epsilon; - conf->epsilonprec = qprecision(q); - conf->epsilon = qlink(q); - if (old) - qfree(old); + old = conf->epsilon; + conf->epsilonprec = qprecision(q); + conf->epsilon = qlink(q); + if (old) + qfree(old); } /* * Return the inverse of one number modulo another. * That is, find x such that: - * Ax = 1 (mod B) + * Ax = 1 (mod B) * Returns zero if the numbers are not relatively prime (temporary hack). */ NUMBER * qminv(NUMBER *q1, NUMBER *q2) { - NUMBER *r; - ZVALUE z1, z2, tmp; - int s, t; - long rnd; + NUMBER *r; + ZVALUE z1, z2, tmp; + int s, t; + long rnd; - if (qisfrac(q1) || qisfrac(q2)) { - math_error("Non-integers for minv"); - not_reached(); - } - if (qiszero(q2)) { - if (qisunit(q1)) - return qlink(q1); - return qlink(&_qzero_); - } - if (qisunit(q2)) - return qlink(&_qzero_); - rnd = conf->mod; - s = (rnd & 4) ? 0 : q2->num.sign; - if (rnd & 1) - s^= 1; + if (qisfrac(q1) || qisfrac(q2)) { + math_error("Non-integers for minv"); + not_reached(); + } + if (qiszero(q2)) { + if (qisunit(q1)) + return qlink(q1); + return qlink(&_qzero_); + } + if (qisunit(q2)) + return qlink(&_qzero_); + rnd = conf->mod; + s = (rnd & 4) ? 0 : q2->num.sign; + if (rnd & 1) + s^= 1; - tmp = q2->num; - tmp.sign = 0; - if (zmodinv(q1->num, tmp, &z1)) - return qlink(&_qzero_); - zsub(tmp, z1, &z2); - if (rnd & 16) { - t = zrel(z1, z2); - if (t < 0) - s = 0; - else if (t > 0) - s = 1; - } - r = qalloc(); - if (s) { - zfree(z1); - z2.sign = true; - r->num = z2; - return r; - } - zfree(z2); - r->num = z1; - return r; + tmp = q2->num; + tmp.sign = 0; + if (zmodinv(q1->num, tmp, &z1)) + return qlink(&_qzero_); + zsub(tmp, z1, &z2); + if (rnd & 16) { + t = zrel(z1, z2); + if (t < 0) + s = 0; + else if (t > 0) + s = 1; + } + r = qalloc(); + if (s) { + zfree(z1); + z2.sign = true; + r->num = z2; + return r; + } + zfree(z2); + r->num = z1; + return r; } @@ -159,143 +159,143 @@ qminv(NUMBER *q1, NUMBER *q2) NUMBER * qpowermod(NUMBER *q1, NUMBER *q2, NUMBER *q3) { - NUMBER *r; - ZVALUE z1, z2, tmp; - int s, t; - long rnd; + NUMBER *r; + ZVALUE z1, z2, tmp; + int s, t; + long rnd; - if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3)) { - math_error("Non-integers for pmod"); - not_reached(); - } - if (qisneg(q2)) { - math_error("Negative power for pmod"); - not_reached(); - } - if (qiszero(q3)) - return qpowi(q1, q2); - if (qisunit(q3)) - return qlink(&_qzero_); - rnd = conf->mod; - s = (rnd & 4) ? 0 : q3->num.sign; - if (rnd & 1) - s^= 1; - tmp = q3->num; - tmp.sign = 0; - zpowermod(q1->num, q2->num, tmp, &z1); - if (ziszero(z1)) { - zfree(z1); - return qlink(&_qzero_); - } - zsub(tmp, z1, &z2); - if (rnd & 16) { - t = zrel(z1, z2); - if (t < 0) - s = 0; - else if (t > 0) - s = 1; - } - r = qalloc(); - if (s) { - zfree(z1); - z2.sign = true; - r->num = z2; - return r; - } - zfree(z2); - r->num = z1; - return r; + if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3)) { + math_error("Non-integers for pmod"); + not_reached(); + } + if (qisneg(q2)) { + math_error("Negative power for pmod"); + not_reached(); + } + if (qiszero(q3)) + return qpowi(q1, q2); + if (qisunit(q3)) + return qlink(&_qzero_); + rnd = conf->mod; + s = (rnd & 4) ? 0 : q3->num.sign; + if (rnd & 1) + s^= 1; + tmp = q3->num; + tmp.sign = 0; + zpowermod(q1->num, q2->num, tmp, &z1); + if (ziszero(z1)) { + zfree(z1); + return qlink(&_qzero_); + } + zsub(tmp, z1, &z2); + if (rnd & 16) { + t = zrel(z1, z2); + if (t < 0) + s = 0; + else if (t > 0) + s = 1; + } + r = qalloc(); + if (s) { + zfree(z1); + z2.sign = true; + r->num = z2; + return r; + } + zfree(z2); + r->num = z1; + return r; } /* * Return the power function of one number with another. * The power must be integral. - * q3 = qpowi(q1, q2); + * q3 = qpowi(q1, q2); */ NUMBER * qpowi(NUMBER *q1, NUMBER *q2) { - register NUMBER *r; - bool invert, sign; - ZVALUE num, zden, z2; + register NUMBER *r; + bool invert, sign; + ZVALUE num, zden, z2; - if (qisfrac(q2)) { - math_error("Raising number to fractional power"); - not_reached(); - } - num = q1->num; - zden = q1->den; - z2 = q2->num; - sign = (num.sign && zisodd(z2)); - invert = z2.sign; - num.sign = 0; - z2.sign = 0; - /* - * Check for trivial cases first. - */ - if (ziszero(num) && !ziszero(z2)) { /* zero raised to a power */ - if (invert) { - math_error("Zero raised to negative power"); - not_reached(); - } - return qlink(&_qzero_); - } - if (zisunit(num) && zisunit(zden)) { /* 1 or -1 raised to a power */ - r = (sign ? q1 : &_qone_); - r->links++; - return r; - } - if (ziszero(z2)) /* raising to zeroth power */ - return qlink(&_qone_); - if (zisunit(z2)) { /* raising to power 1 or -1 */ - if (invert) - return qinv(q1); - return qlink(q1); - } - /* - * Not a trivial case. Do the real work. - */ - r = qalloc(); - if (!zisunit(num)) - zpowi(num, z2, &r->num); - if (!zisunit(zden)) - zpowi(zden, z2, &r->den); - if (invert) { - z2 = r->num; - r->num = r->den; - r->den = z2; - } - r->num.sign = sign; - return r; + if (qisfrac(q2)) { + math_error("Raising number to fractional power"); + not_reached(); + } + num = q1->num; + zden = q1->den; + z2 = q2->num; + sign = (num.sign && zisodd(z2)); + invert = z2.sign; + num.sign = 0; + z2.sign = 0; + /* + * Check for trivial cases first. + */ + if (ziszero(num) && !ziszero(z2)) { /* zero raised to a power */ + if (invert) { + math_error("Zero raised to negative power"); + not_reached(); + } + return qlink(&_qzero_); + } + if (zisunit(num) && zisunit(zden)) { /* 1 or -1 raised to a power */ + r = (sign ? q1 : &_qone_); + r->links++; + return r; + } + if (ziszero(z2)) /* raising to zeroth power */ + return qlink(&_qone_); + if (zisunit(z2)) { /* raising to power 1 or -1 */ + if (invert) + return qinv(q1); + return qlink(q1); + } + /* + * Not a trivial case. Do the real work. + */ + r = qalloc(); + if (!zisunit(num)) + zpowi(num, z2, &r->num); + if (!zisunit(zden)) + zpowi(zden, z2, &r->den); + if (invert) { + z2 = r->num; + r->num = r->den; + r->den = z2; + } + r->num.sign = sign; + return r; } /* * Given the legs of a right triangle, compute its hypotenuse within - * the specified error. This is sqrt(a^2 + b^2). + * the specified error. This is sqrt(a^2 + b^2). */ NUMBER * qhypot(NUMBER *q1, NUMBER *q2, NUMBER *epsilon) { - NUMBER *tmp1, *tmp2, *tmp3; + NUMBER *tmp1, *tmp2, *tmp3; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for hypot"); - not_reached(); - } - if (qiszero(q1)) - return qqabs(q2); - if (qiszero(q2)) - return qqabs(q1); - tmp1 = qsquare(q1); - tmp2 = qsquare(q2); - tmp3 = qqadd(tmp1, tmp2); - qfree(tmp1); - qfree(tmp2); - tmp1 = qsqrt(tmp3, epsilon, conf->triground); - qfree(tmp3); - return tmp1; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for hypot"); + not_reached(); + } + if (qiszero(q1)) + return qqabs(q2); + if (qiszero(q2)) + return qqabs(q1); + tmp1 = qsquare(q1); + tmp2 = qsquare(q2); + tmp3 = qqadd(tmp1, tmp2); + qfree(tmp1); + qfree(tmp2); + tmp1 = qsqrt(tmp3, epsilon, conf->triground); + qfree(tmp3); + return tmp1; } @@ -307,37 +307,37 @@ qhypot(NUMBER *q1, NUMBER *q2, NUMBER *epsilon) NUMBER * qlegtoleg(NUMBER *q, NUMBER *epsilon, bool wantneg) { - NUMBER *res, *qtmp1, *qtmp2; - ZVALUE num; + NUMBER *res, *qtmp1, *qtmp2; + ZVALUE num; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for ltol"); - not_reached(); - } - if (qisunit(q)) - return qlink(&_qzero_); - if (qiszero(q)) { - if (wantneg) - return qlink(&_qnegone_); - return qlink(&_qone_); - } - num = q->num; - num.sign = 0; - if (zrel(num, q->den) >= 0) { - math_error("Leg too large for ltol"); - not_reached(); - } - qtmp1 = qsquare(q); - qtmp2 = qsub(&_qone_, qtmp1); - qfree(qtmp1); - res = qsqrt(qtmp2, epsilon, conf->triground); - qfree(qtmp2); - if (wantneg) { - qtmp1 = qneg(res); - qfree(res); - res = qtmp1; - } - return res; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for ltol"); + not_reached(); + } + if (qisunit(q)) + return qlink(&_qzero_); + if (qiszero(q)) { + if (wantneg) + return qlink(&_qnegone_); + return qlink(&_qone_); + } + num = q->num; + num.sign = 0; + if (zrel(num, q->den) >= 0) { + math_error("Leg too large for ltol"); + not_reached(); + } + qtmp1 = qsquare(q); + qtmp2 = qsub(&_qone_, qtmp1); + qfree(qtmp1); + res = qsqrt(qtmp2, epsilon, conf->triground); + qfree(qtmp2); + if (wantneg) { + qtmp1 = qneg(res); + qfree(res); + res = qtmp1; + } + return res; } @@ -347,110 +347,110 @@ qlegtoleg(NUMBER *q, NUMBER *epsilon, bool wantneg) * If rnd & 32 is nonzero, result is exact for square numbers; * If rnd & 64 is nonzero, the negative square root is returned; * If rnd < 32, result is rounded to a multiple of epsilon - * up, down, etc. depending on bits 0, 2, 4 of v. + * up, down, etc. depending on bits 0, 2, 4 of v. */ NUMBER * qsqrt(NUMBER *q1, NUMBER *epsilon, long rnd) { - NUMBER *r, etemp; - ZVALUE tmp1, tmp2, quo, mul, divisor; - long s1, s2, up, RR, RS; - int sign; + NUMBER *r, etemp; + ZVALUE tmp1, tmp2, quo, mul, divisor; + long s1, s2, up, RR, RS; + int sign; - if (qisneg(q1)) { - math_error("Square root of negative number for qsqrt"); - not_reached(); - } - if (qiszero(q1)) - return qlink(&_qzero_); - sign = (rnd & 64) != 0; - if (qiszero(epsilon)) { - math_error("Zero epsilon for qsqrt"); - not_reached(); - } + if (qisneg(q1)) { + math_error("Square root of negative number for qsqrt"); + not_reached(); + } + if (qiszero(q1)) + return qlink(&_qzero_); + sign = (rnd & 64) != 0; + if (qiszero(epsilon)) { + math_error("Zero epsilon for qsqrt"); + not_reached(); + } - etemp = *epsilon; - etemp.num.sign = 0; - RS = rnd & 25; - if (!(RS & 8)) - RS ^= epsilon->num.sign; - if (rnd & 2) - RS ^= sign ^ epsilon->num.sign; - if (rnd & 4) - RS ^= epsilon->num.sign; - RR = zisunit(q1->den) && qisunit(epsilon); - if (rnd & 32 || RR) { - s1 = zsqrt(q1->num, &tmp1, RS); - if (RR) { - if (ziszero(tmp1)) { - zfree(tmp1); - return qlink(&_qzero_); - } - r = qalloc(); - tmp1.sign = sign; - r->num = tmp1; - return r; - } - if (!s1) { - s2 = zsqrt(q1->den, &tmp2, 0); - if (!s2) { - r = qalloc(); - tmp1.sign = sign; - r->num = tmp1; - r->den = tmp2; - return r; - } - zfree(tmp2); - } - zfree(tmp1); - } - up = 0; - zsquare(epsilon->den, &tmp1); - zmul(tmp1, q1->num, &tmp2); - zfree(tmp1); - zsquare(epsilon->num, &tmp1); - zmul(tmp1, q1->den, &divisor); - zfree(tmp1); - if (rnd & 16) { - zshift(tmp2, 2, &tmp1); - zfree(tmp2); - s1 = zquo(tmp1, divisor, &quo, 16); - zfree(tmp1); - s2 = zsqrt(quo, &tmp1, s1 ? s1 < 0 : 16); - zshift(tmp1, -1, &mul); - up = (*tmp1.v & 1) ? s1 + s2 : -1; - zfree(tmp1); - } else { - s1 = zquo(tmp2, divisor, &quo, 0); - zfree(tmp2); - s2 = zsqrt(quo, &mul, 0); - up = (s1 + s2) ? 0 : -1; - } - if (up == 0) { - if (rnd & 8) - up = (long)((RS ^ *mul.v) & 1); - else - up = RS ^ sign; - } - if (up > 0) { - zadd(mul, _one_, &tmp2); - zfree(mul); - mul = tmp2; - } - zfree(divisor); - zfree(quo); - if (ziszero(mul)) { - zfree(mul); - return qlink(&_qzero_); - } - r = qalloc(); - zreduce(mul, etemp.den, &tmp1, &r->den); - zfree(mul); - tmp1.sign = sign; - zmul(tmp1, etemp.num, &r->num); - zfree(tmp1); - return r; + etemp = *epsilon; + etemp.num.sign = 0; + RS = rnd & 25; + if (!(RS & 8)) + RS ^= epsilon->num.sign; + if (rnd & 2) + RS ^= sign ^ epsilon->num.sign; + if (rnd & 4) + RS ^= epsilon->num.sign; + RR = zisunit(q1->den) && qisunit(epsilon); + if (rnd & 32 || RR) { + s1 = zsqrt(q1->num, &tmp1, RS); + if (RR) { + if (ziszero(tmp1)) { + zfree(tmp1); + return qlink(&_qzero_); + } + r = qalloc(); + tmp1.sign = sign; + r->num = tmp1; + return r; + } + if (!s1) { + s2 = zsqrt(q1->den, &tmp2, 0); + if (!s2) { + r = qalloc(); + tmp1.sign = sign; + r->num = tmp1; + r->den = tmp2; + return r; + } + zfree(tmp2); + } + zfree(tmp1); + } + up = 0; + zsquare(epsilon->den, &tmp1); + zmul(tmp1, q1->num, &tmp2); + zfree(tmp1); + zsquare(epsilon->num, &tmp1); + zmul(tmp1, q1->den, &divisor); + zfree(tmp1); + if (rnd & 16) { + zshift(tmp2, 2, &tmp1); + zfree(tmp2); + s1 = zquo(tmp1, divisor, &quo, 16); + zfree(tmp1); + s2 = zsqrt(quo, &tmp1, s1 ? s1 < 0 : 16); + zshift(tmp1, -1, &mul); + up = (*tmp1.v & 1) ? s1 + s2 : -1; + zfree(tmp1); + } else { + s1 = zquo(tmp2, divisor, &quo, 0); + zfree(tmp2); + s2 = zsqrt(quo, &mul, 0); + up = (s1 + s2) ? 0 : -1; + } + if (up == 0) { + if (rnd & 8) + up = (long)((RS ^ *mul.v) & 1); + else + up = RS ^ sign; + } + if (up > 0) { + zadd(mul, _one_, &tmp2); + zfree(mul); + mul = tmp2; + } + zfree(divisor); + zfree(quo); + if (ziszero(mul)) { + zfree(mul); + return qlink(&_qzero_); + } + r = qalloc(); + zreduce(mul, etemp.den, &tmp1, &r->den); + zfree(mul); + tmp1.sign = sign; + zmul(tmp1, etemp.num, &r->num); + zfree(tmp1); + return r; } @@ -461,24 +461,24 @@ qsqrt(NUMBER *q1, NUMBER *epsilon, long rnd) NUMBER * qisqrt(NUMBER *q) { - NUMBER *r; - ZVALUE tmp; + NUMBER *r; + ZVALUE tmp; - if (qisneg(q)) { - math_error("Square root of negative number for isqrt"); - not_reached(); - } - if (qiszero(q)) - return qlink(&_qzero_); - r = qalloc(); - if (qisint(q)) { - (void) zsqrt(q->num, &r->num,0); - return r; - } - zquo(q->num, q->den, &tmp, 0); - (void) zsqrt(tmp, &r->num,0); - zfree(tmp); - return r; + if (qisneg(q)) { + math_error("Square root of negative number for isqrt"); + not_reached(); + } + if (qiszero(q)) + return qlink(&_qzero_); + r = qalloc(); + if (qisint(q)) { + (void) zsqrt(q->num, &r->num,0); + return r; + } + zquo(q->num, q->den, &tmp, 0); + (void) zsqrt(tmp, &r->num,0); + zfree(tmp); + return r; } /* @@ -487,12 +487,12 @@ qisqrt(NUMBER *q) bool qissquare(NUMBER *q) { - bool flag; + bool flag; - flag = zissquare(q->num); - if (qisint(q) || !flag) - return flag; - return zissquare(q->den); + flag = zissquare(q->num); + if (qisint(q) || !flag) + return flag; + return zissquare(q->den); } @@ -503,117 +503,117 @@ qissquare(NUMBER *q) NUMBER * qiroot(NUMBER *q1, NUMBER *q2) { - NUMBER *r; - ZVALUE tmp; + NUMBER *r; + ZVALUE tmp; - if (qisneg(q2) || qiszero(q2) || qisfrac(q2)) { - math_error("Taking number to bad root value"); - not_reached(); - } - if (qiszero(q1)) - return qlink(&_qzero_); - if (qisone(q1) || qisone(q2)) - return qlink(q1); - if (qistwo(q2)) - return qisqrt(q1); - r = qalloc(); - if (qisint(q1)) { - zroot(q1->num, q2->num, &r->num); - return r; - } - zquo(q1->num, q1->den, &tmp, 0); - zroot(tmp, q2->num, &r->num); - zfree(tmp); - return r; + if (qisneg(q2) || qiszero(q2) || qisfrac(q2)) { + math_error("Taking number to bad root value"); + not_reached(); + } + if (qiszero(q1)) + return qlink(&_qzero_); + if (qisone(q1) || qisone(q2)) + return qlink(q1); + if (qistwo(q2)) + return qisqrt(q1); + r = qalloc(); + if (qisint(q1)) { + zroot(q1->num, q2->num, &r->num); + return r; + } + zquo(q1->num, q1->den, &tmp, 0); + zroot(tmp, q2->num, &r->num); + zfree(tmp); + return r; } /* * Return the greatest integer of the base 2 log of a number. - * This is the number such that 1 <= x / log2(x) < 2. + * This is the number such that 1 <= x / log2(x) < 2. * Examples: qilog2(8) = 3, qilog2(1.3) = 1, qilog2(1/7) = -3. * * given: - * q number to take log of + * q number to take log of */ long qilog2(NUMBER *q) { - long n; /* power of two */ - int c; /* result of comparison */ - ZVALUE tmp1, tmp2; /* temporary values */ + long n; /* power of two */ + int c; /* result of comparison */ + ZVALUE tmp1, tmp2; /* temporary values */ - if (qiszero(q)) { - math_error("Zero argument for ilog2"); - not_reached(); - } - if (qisint(q)) - return zhighbit(q->num); - tmp1 = q->num; - tmp1.sign = 0; - n = zhighbit(tmp1) - zhighbit(q->den); - if (n == 0) - c = zrel(tmp1, q->den); - else if (n > 0) { - zshift(q->den, n, &tmp2); - c = zrel(tmp1, tmp2); - zfree(tmp2); - } else { - zshift(tmp1, -n, &tmp2); - c = zrel(tmp2, q->den); - zfree(tmp2); - } - if (c < 0) - n--; - return n; + if (qiszero(q)) { + math_error("Zero argument for ilog2"); + not_reached(); + } + if (qisint(q)) + return zhighbit(q->num); + tmp1 = q->num; + tmp1.sign = 0; + n = zhighbit(tmp1) - zhighbit(q->den); + if (n == 0) + c = zrel(tmp1, q->den); + else if (n > 0) { + zshift(q->den, n, &tmp2); + c = zrel(tmp1, tmp2); + zfree(tmp2); + } else { + zshift(tmp1, -n, &tmp2); + c = zrel(tmp2, q->den); + zfree(tmp2); + } + if (c < 0) + n--; + return n; } /* * Return the greatest integer of the base 10 log of a number. - * This is the number such that 1 <= x / log10(x) < 10. + * This is the number such that 1 <= x / log10(x) < 10. * Examples: qilog10(100) = 2, qilog10(12.3) = 1, qilog10(.023) = -2. * * given: - * q number to take log of + * q number to take log of */ long qilog10(NUMBER *q) { - long n; /* log value */ - ZVALUE tmp1, tmp2; /* temporary values */ + long n; /* log value */ + ZVALUE tmp1, tmp2; /* temporary values */ - if (qiszero(q)) { - math_error("Zero argument for ilog10"); - not_reached(); - } - tmp1 = q->num; - tmp1.sign = 0; - if (qisint(q)) - return zlog10(tmp1, NULL); - /* - * The number is not an integer. - * Compute the result if the number is greater than one. - */ - if (zrel(tmp1, q->den) > 0) { - zquo(tmp1, q->den, &tmp2, 0); - n = zlog10(tmp2, NULL); - zfree(tmp2); - return n; - } - /* - * Here if the number is less than one. - * If the number is the inverse of a power of ten, then the - * obvious answer will be off by one. Subtracting one if the - * number is the inverse of an integer will fix it. - */ - if (zisunit(tmp1)) - zsub(q->den, _one_, &tmp2); - else - zquo(q->den, tmp1, &tmp2, 0); - n = -zlog10(tmp2, NULL) - 1; - zfree(tmp2); - return n; + if (qiszero(q)) { + math_error("Zero argument for ilog10"); + not_reached(); + } + tmp1 = q->num; + tmp1.sign = 0; + if (qisint(q)) + return zlog10(tmp1, NULL); + /* + * The number is not an integer. + * Compute the result if the number is greater than one. + */ + if (zrel(tmp1, q->den) > 0) { + zquo(tmp1, q->den, &tmp2, 0); + n = zlog10(tmp2, NULL); + zfree(tmp2); + return n; + } + /* + * Here if the number is less than one. + * If the number is the inverse of a power of ten, then the + * obvious answer will be off by one. Subtracting one if the + * number is the inverse of an integer will fix it. + */ + if (zisunit(tmp1)) + zsub(q->den, _one_, &tmp2); + else + zquo(q->den, tmp1, &tmp2, 0); + n = -zlog10(tmp2, NULL) - 1; + zfree(tmp2); + return n; } /* @@ -623,31 +623,31 @@ qilog10(NUMBER *q) NUMBER * qilog(NUMBER *q, ZVALUE base) { - long n; - ZVALUE tmp1, tmp2; + long n; + ZVALUE tmp1, tmp2; - if (qiszero(q)) - return NULL; + if (qiszero(q)) + return NULL; - if (qisunit(q)) - return qlink(&_qzero_); - if (qisint(q)) - return itoq(zlog(q->num, base)); - tmp1 = q->num; - tmp1.sign = 0; - if (zrel(tmp1, q->den) > 0) { - zquo(tmp1, q->den, &tmp2, 0); - n = zlog(tmp2, base); - zfree(tmp2); - return itoq(n); - } - if (zisunit(tmp1)) - zsub(q->den, _one_, &tmp2); - else - zquo(q->den, tmp1, &tmp2, 0); - n = -zlog(tmp2, base) - 1; - zfree(tmp2); - return itoq(n); + if (qisunit(q)) + return qlink(&_qzero_); + if (qisint(q)) + return itoq(zlog(q->num, base)); + tmp1 = q->num; + tmp1.sign = 0; + if (zrel(tmp1, q->den) > 0) { + zquo(tmp1, q->den, &tmp2, 0); + n = zlog(tmp2, base); + zfree(tmp2); + return itoq(n); + } + if (zisunit(tmp1)) + zsub(q->den, _one_, &tmp2); + else + zquo(q->den, tmp1, &tmp2, 0); + n = -zlog(tmp2, base) - 1; + zfree(tmp2); + return itoq(n); } @@ -659,28 +659,28 @@ qilog(NUMBER *q, ZVALUE base) * * One should remember these special cases: * - * digits(12.3456) == 2 computes with the integer part only - * digits(-1234) == 4 computes with the absolute value only - * digits(0) == 1 special case - * digits(-0.123) == 1 combination of all of the above + * digits(12.3456) == 2 computes with the integer part only + * digits(-1234) == 4 computes with the absolute value only + * digits(0) == 1 special case + * digits(-0.123) == 1 combination of all of the above * * given: - * q number to count digits of + * q number to count digits of */ long qdigits(NUMBER *q, ZVALUE base) { - long n; /* number of digits */ - ZVALUE temp; /* temporary value */ + long n; /* number of digits */ + ZVALUE temp; /* temporary value */ - if (zabsrel(q->num, q->den) < 0) - return 1; - if (qisint(q)) - return 1 + zlog(q->num, base); - zquo(q->num, q->den, &temp, 2); - n = 1 + zlog(temp, base); - zfree(temp); - return n; + if (zabsrel(q->num, q->den) < 0) + return 1; + if (qisint(q)) + return 1 + zlog(q->num, base); + zquo(q->num, q->den, &temp, 2); + n = 1 + zlog(temp, base); + zfree(temp); + return n; } @@ -695,97 +695,97 @@ qdigits(NUMBER *q, ZVALUE base) NUMBER * qdigit(NUMBER *q, ZVALUE dpos, ZVALUE base) { - ZVALUE N, D; - ZVALUE K; - long k; - ZVALUE A, B, C; /* temporary integers */ - NUMBER *res; + ZVALUE N, D; + ZVALUE K; + long k; + ZVALUE A, B, C; /* temporary integers */ + NUMBER *res; - /* - * In the first stage, q is expressed as base^k * N/D where - * gcd(D, base) = 1 - * K is k as a ZVALUE - */ - base.sign = 0; - if (ziszero(base) || zisunit(base)) - return NULL; - if (qiszero(q) || (qisint(q) && zisneg(dpos)) || - (zge31b(dpos) && !zisneg(dpos))) - return qlink(&_qzero_); - k = zfacrem(q->num, base, &N); - if (k == 0) { - zfree(N); - k = zgcdrem(q->den, base, &D); - if (k > 0) { - zequo(q->den, D, &A); - itoz(k, &K); - zpowi(base, K, &B); - zfree(K); - zequo(B, A, &C); - zfree(A); - zfree(B); - zmul(C, q->num, &N); - zfree(C); - k = -k; - } - else - N = q->num; - } - if (k >= 0) - D = q->den; + /* + * In the first stage, q is expressed as base^k * N/D where + * gcd(D, base) = 1 + * K is k as a ZVALUE + */ + base.sign = 0; + if (ziszero(base) || zisunit(base)) + return NULL; + if (qiszero(q) || (qisint(q) && zisneg(dpos)) || + (zge31b(dpos) && !zisneg(dpos))) + return qlink(&_qzero_); + k = zfacrem(q->num, base, &N); + if (k == 0) { + zfree(N); + k = zgcdrem(q->den, base, &D); + if (k > 0) { + zequo(q->den, D, &A); + itoz(k, &K); + zpowi(base, K, &B); + zfree(K); + zequo(B, A, &C); + zfree(A); + zfree(B); + zmul(C, q->num, &N); + zfree(C); + k = -k; + } + else + N = q->num; + } + if (k >= 0) + D = q->den; - itoz(k, &K); - if (zrel(dpos, K) >= 0) { - zsub(dpos, K, &A); - zfree(K); - zpowi(base, A, &B); - zfree(A); - zmul(D, B, &A); - zfree(B); - zquo(N, A, &B, 0); - } else { - if (zisunit(D)) { - if (k != 0) - zfree(N); - zfree(K); - if (k < 0) - zfree(D); - return qlink(&_qzero_); - } - zsub(K, dpos, &A); - zfree(K); - zpowermod(base, A, D, &C); - zfree(A); - zmod(N, D, &A, 0); - zmul(C, A, &B); - zfree(A); - zfree(C); - zmod(B, D, &A, 0); - zfree(B); - zmodinv(D, base, &B); - zsub(base, B, &C); - zfree(B); - zmul(C, A, &B); - zfree(C); - } - zfree(A); - if (k != 0) - zfree(N); - if (k < 0) - zfree(D); - zmod(B, base, &A, 0); - zfree(B); - if (ziszero(A)) { - zfree(A); - return qlink(&_qzero_); - } - if (zisone(A)) { - zfree(A); - return qlink(&_qone_); - } - res = qalloc(); - res->num = A; - return res; + itoz(k, &K); + if (zrel(dpos, K) >= 0) { + zsub(dpos, K, &A); + zfree(K); + zpowi(base, A, &B); + zfree(A); + zmul(D, B, &A); + zfree(B); + zquo(N, A, &B, 0); + } else { + if (zisunit(D)) { + if (k != 0) + zfree(N); + zfree(K); + if (k < 0) + zfree(D); + return qlink(&_qzero_); + } + zsub(K, dpos, &A); + zfree(K); + zpowermod(base, A, D, &C); + zfree(A); + zmod(N, D, &A, 0); + zmul(C, A, &B); + zfree(A); + zfree(C); + zmod(B, D, &A, 0); + zfree(B); + zmodinv(D, base, &B); + zsub(base, B, &C); + zfree(B); + zmul(C, A, &B); + zfree(C); + } + zfree(A); + if (k != 0) + zfree(N); + if (k < 0) + zfree(D); + zmod(B, base, &A, 0); + zfree(B); + if (ziszero(A)) { + zfree(A); + return qlink(&_qzero_); + } + if (zisone(A)) { + zfree(A); + return qlink(&_qone_); + } + res = qalloc(); + res->num = A; + return res; } @@ -798,94 +798,94 @@ qdigit(NUMBER *q, ZVALUE dpos, ZVALUE base) bool qisset(NUMBER *q, long n) { - NUMBER *qtmp1, *qtmp2; - ZVALUE ztmp; - bool res; + NUMBER *qtmp1, *qtmp2; + ZVALUE ztmp; + bool res; - /* - * Zero number or negative bit position place of integer is trivial. - */ - if (qiszero(q) || (qisint(q) && (n < 0))) - return false; - /* - * For non-negative bit positions, answer is easy. - */ - if (n >= 0) { - if (qisint(q)) - return zisset(q->num, n); - zquo(q->num, q->den, &ztmp, 2); - res = zisset(ztmp, n); - zfree(ztmp); - return res; - } - /* - * Fractional value and want negative bit position, must work harder. - */ - qtmp1 = qscale(q, -n); - qtmp2 = qint(qtmp1); - qfree(qtmp1); - res = ((qtmp2->num.v[0] & 0x01) != 0); - qfree(qtmp2); - return res; + /* + * Zero number or negative bit position place of integer is trivial. + */ + if (qiszero(q) || (qisint(q) && (n < 0))) + return false; + /* + * For non-negative bit positions, answer is easy. + */ + if (n >= 0) { + if (qisint(q)) + return zisset(q->num, n); + zquo(q->num, q->den, &ztmp, 2); + res = zisset(ztmp, n); + zfree(ztmp); + return res; + } + /* + * Fractional value and want negative bit position, must work harder. + */ + qtmp1 = qscale(q, -n); + qtmp2 = qint(qtmp1); + qfree(qtmp1); + res = ((qtmp2->num.v[0] & 0x01) != 0); + qfree(qtmp2); + return res; } /* * Compute the factorial of an integer. - * q2 = qfact(q1); + * q2 = qfact(q1); */ NUMBER * qfact(NUMBER *q) { - register NUMBER *r; + register NUMBER *r; - if (qisfrac(q)) { - math_error("Non-integral factorial"); - not_reached(); - } - if (qiszero(q) || zisone(q->num)) - return qlink(&_qone_); - r = qalloc(); - zfact(q->num, &r->num); - return r; + if (qisfrac(q)) { + math_error("Non-integral factorial"); + not_reached(); + } + if (qiszero(q) || zisone(q->num)) + return qlink(&_qone_); + r = qalloc(); + zfact(q->num, &r->num); + return r; } /* * Compute the product of the primes less than or equal to a number. - * q2 = qpfact(q1); + * q2 = qpfact(q1); */ NUMBER * qpfact(NUMBER *q) { - NUMBER *r; + NUMBER *r; - if (qisfrac(q)) { - math_error("Non-integral factorial"); - not_reached(); - } - r = qalloc(); - zpfact(q->num, &r->num); - return r; + if (qisfrac(q)) { + math_error("Non-integral factorial"); + not_reached(); + } + r = qalloc(); + zpfact(q->num, &r->num); + return r; } /* * Compute the lcm of all the numbers less than or equal to a number. - * q2 = qlcmfact(q1); + * q2 = qlcmfact(q1); */ NUMBER * qlcmfact(NUMBER *q) { - NUMBER *r; + NUMBER *r; - if (qisfrac(q)) { - math_error("Non-integral lcmfact"); - not_reached(); - } - r = qalloc(); - zlcmfact(q->num, &r->num); - return r; + if (qisfrac(q)) { + math_error("Non-integral lcmfact"); + not_reached(); + } + r = qalloc(); + zlcmfact(q->num, &r->num); + return r; } @@ -895,59 +895,59 @@ qlcmfact(NUMBER *q) NUMBER * qperm(NUMBER *q1, NUMBER *q2) { - NUMBER *r; - NUMBER *qtmp1, *qtmp2; - long i; + NUMBER *r; + NUMBER *qtmp1, *qtmp2; + long i; - if (qisfrac(q2)) { - math_error("Non-integral second arg for permutation"); - not_reached(); - } - if (qiszero(q2)) - return qlink(&_qone_); - if (qisone(q2)) - return qlink(q1); - if (qisint(q1) && !qisneg(q1)) { - if (qrel(q2, q1) > 0) - return qlink(&_qzero_); - if (qispos(q2)) { - r = qalloc(); - zperm(q1->num, q2->num, &r->num); - return r; - } - } - if (zge31b(q2->num)) { - math_error("Too large arg2 for permutation"); - not_reached(); - } - i = qtoi(q2); - if (i > 0) { - q1 = qlink(q1); - r = qlink(q1); - while (--i > 0) { - qtmp1 = qdec(q1); - qtmp2 = qmul(r, qtmp1); - qfree(q1); - q1 = qtmp1; - qfree(r); - r = qtmp2; - } - qfree(q1); - return r; - } - i = -i; - qtmp1 = qinc(q1); - r = qinv(qtmp1); - while (--i > 0) { - qtmp2 = qinc(qtmp1); - qfree(qtmp1); - qtmp1 = qqdiv(r, qtmp2); - qfree(r); - r = qtmp1; - qtmp1 = qtmp2; - } - qfree(qtmp1); - return r; + if (qisfrac(q2)) { + math_error("Non-integral second arg for permutation"); + not_reached(); + } + if (qiszero(q2)) + return qlink(&_qone_); + if (qisone(q2)) + return qlink(q1); + if (qisint(q1) && !qisneg(q1)) { + if (qrel(q2, q1) > 0) + return qlink(&_qzero_); + if (qispos(q2)) { + r = qalloc(); + zperm(q1->num, q2->num, &r->num); + return r; + } + } + if (zge31b(q2->num)) { + math_error("Too large arg2 for permutation"); + not_reached(); + } + i = qtoi(q2); + if (i > 0) { + q1 = qlink(q1); + r = qlink(q1); + while (--i > 0) { + qtmp1 = qdec(q1); + qtmp2 = qmul(r, qtmp1); + qfree(q1); + q1 = qtmp1; + qfree(r); + r = qtmp2; + } + qfree(q1); + return r; + } + i = -i; + qtmp1 = qinc(q1); + r = qinv(qtmp1); + while (--i > 0) { + qtmp2 = qinc(qtmp1); + qfree(qtmp1); + qtmp1 = qqdiv(r, qtmp2); + qfree(r); + r = qtmp1; + qtmp1 = qtmp2; + } + qfree(qtmp1); + return r; } @@ -958,50 +958,50 @@ qperm(NUMBER *q1, NUMBER *q2) NUMBER * qcomb(NUMBER *q, NUMBER *n) { - NUMBER *r; - NUMBER *q1, *q2; - long i, j; - ZVALUE z; + NUMBER *r; + NUMBER *q1, *q2; + long i, j; + ZVALUE z; - if (!qisint(n) || qisneg(n)) { - math_error("Bad second arg in call to qcomb!"); - not_reached(); - } - if (qisint(q)) { - switch (zcomb(q->num, n->num, &z)) { - case 0: - return qlink(&_qzero_); - case 1: - return qlink(&_qone_); - case -1: - return qlink(&_qnegone_); - case 2: - return qlink(q); - case -2: - return NULL; - default: - r = qalloc(); - r->num = z; - return r; - } - } - if (zge31b(n->num)) - return NULL; - i = ztoi(n->num); - q = qlink(q); - r = qlink(q); - j = 1; - while (--i > 0) { - q1 = qdec(q); - qfree(q); - q = q1; - q2 = qmul(r, q); - qfree(r); - r = qdivi(q2, ++j); - qfree(q2); - } - qfree(q); - return r; + if (!qisint(n) || qisneg(n)) { + math_error("Bad second arg in call to qcomb!"); + not_reached(); + } + if (qisint(q)) { + switch (zcomb(q->num, n->num, &z)) { + case 0: + return qlink(&_qzero_); + case 1: + return qlink(&_qone_); + case -1: + return qlink(&_qnegone_); + case 2: + return qlink(q); + case -2: + return NULL; + default: + r = qalloc(); + r->num = z; + return r; + } + } + if (zge31b(n->num)) + return NULL; + i = ztoi(n->num); + q = qlink(q); + r = qlink(q); + j = 1; + while (--i > 0) { + q1 = qdec(q); + qfree(q); + q = q1; + q2 = qmul(r, q); + qfree(r); + r = qdivi(q2, ++j); + qfree(q2); + } + qfree(q); + return r; } @@ -1013,89 +1013,89 @@ qcomb(NUMBER *q, NUMBER *n) NUMBER * qbern(ZVALUE z) { - long n, i, k, m, nn, dd; - NUMBER **p; - NUMBER *s, *s1, *c, *c1, *t; - size_t sz; + long n, i, k, m, nn, dd; + NUMBER **p; + NUMBER *s, *s1, *c, *c1, *t; + size_t sz; - if (zisone(z)) - return qlink(&_qneghalf_); + if (zisone(z)) + return qlink(&_qneghalf_); - if (zisodd(z) || z.sign) - return qlink(&_qzero_); + if (zisodd(z) || z.sign) + return qlink(&_qzero_); - if (zge31b(z)) - return NULL; + if (zge31b(z)) + return NULL; - n = ztoi(z); + n = ztoi(z); - if (n == 0) + if (n == 0) - return qlink(&_qone_); + return qlink(&_qone_); - m = (n >> 1) - 1; + m = (n >> 1) - 1; - if (m < B_num) - return qlink(B_table[m]); + if (m < B_num) + return qlink(B_table[m]); - if (m >= B_allocnum) { - k = (m/QALLOCNUM + 1) * QALLOCNUM; - sz = k * sizeof(NUMBER *); - if (sz < (size_t) k) - return NULL; - if (B_allocnum == 0) - p = (NUMBER **) malloc(sz); - else - p = (NUMBER **) realloc(B_table, sz); - if (p == NULL) - return NULL; - B_allocnum = k; - B_table = p; - } - for (k = B_num; k <= m; k++) { - nn = 2 * k + 3; - dd = 1; - c1 = itoq(nn); - c = qinv(c1); - qfree(c1); - s = qsub(&_qonehalf_, c); - i = k; - for (i = 0; i < k; i++) { - c1 = qmuli(c, nn--); - qfree(c); - c = qdivi(c1, dd++); - qfree(c1); - c1 = qmuli(c, nn--); - qfree(c); - c = qdivi(c1, dd++); - qfree(c1); - t = qmul(c, B_table[i]); - s1 = qsub(s, t); - qfree(t); - qfree(s); - s = s1; - } - B_table[k] = s; - qfree(c); - } - B_num = k; - return qlink(B_table[m]); + if (m >= B_allocnum) { + k = (m/QALLOCNUM + 1) * QALLOCNUM; + sz = k * sizeof(NUMBER *); + if (sz < (size_t) k) + return NULL; + if (B_allocnum == 0) + p = (NUMBER **) malloc(sz); + else + p = (NUMBER **) realloc(B_table, sz); + if (p == NULL) + return NULL; + B_allocnum = k; + B_table = p; + } + for (k = B_num; k <= m; k++) { + nn = 2 * k + 3; + dd = 1; + c1 = itoq(nn); + c = qinv(c1); + qfree(c1); + s = qsub(&_qonehalf_, c); + i = k; + for (i = 0; i < k; i++) { + c1 = qmuli(c, nn--); + qfree(c); + c = qdivi(c1, dd++); + qfree(c1); + c1 = qmuli(c, nn--); + qfree(c); + c = qdivi(c1, dd++); + qfree(c1); + t = qmul(c, B_table[i]); + s1 = qsub(s, t); + qfree(t); + qfree(s); + s = s1; + } + B_table[k] = s; + qfree(c); + } + B_num = k; + return qlink(B_table[m]); } void qfreebern(void) { - long k; + long k; - if (B_num > 0) { - for (k = 0; k < B_num; k++) - qfree(B_table[k]); - free(B_table); - } - B_table = NULL; - B_allocnum = 0; - B_num = 0; + if (B_num > 0) { + for (k = 0; k < B_num; k++) + qfree(B_table[k]); + free(B_table); + } + B_table = NULL; + B_allocnum = 0; + B_num = 0; } @@ -1107,73 +1107,73 @@ qfreebern(void) NUMBER * qeuler(ZVALUE z) { - long i, k, m, n, nn, dd; - NUMBER **p; - NUMBER *s, *s1, *c, *c1, *t; - size_t sz; + long i, k, m, n, nn, dd; + NUMBER **p; + NUMBER *s, *s1, *c, *c1, *t; + size_t sz; - if (ziszero(z)) - return qlink(&_qone_); - if (zisodd(z) || zisneg(z)) - return qlink(&_qzero_); - if (zge31b(z)) - return NULL; - n = ztoi(z); - m = (n >> 1) - 1; - if (m < E_num) - return qlink(E_table[m]); - sz = (m + 1) * sizeof(NUMBER *); - if (sz < (size_t) m + 1) - return NULL; - if (E_num) - p = (NUMBER **) realloc(E_table, sz); - else - p = (NUMBER **) malloc(sz); - if (p == NULL) - return NULL; - E_table = p; - for (k = E_num; k <= m; k++) { - nn = 2 * k + 2; - dd = 1; - c = qlink(&_qone_); - s = qlink(&_qnegone_); - i = k; - for (i = 0; i < k; i++) { - c1 = qmuli(c, nn--); - qfree(c); - c = qdivi(c1, dd++); - qfree(c1); - c1 = qmuli(c, nn--); - qfree(c); - c = qdivi(c1, dd++); - qfree(c1); - t = qmul(c, E_table[i]); - s1 = qsub(s, t); - qfree(t); - qfree(s); - s = s1; - } - E_table[k] = s; - qfree(c); - } - E_num = k; - return qlink(E_table[m]); + if (ziszero(z)) + return qlink(&_qone_); + if (zisodd(z) || zisneg(z)) + return qlink(&_qzero_); + if (zge31b(z)) + return NULL; + n = ztoi(z); + m = (n >> 1) - 1; + if (m < E_num) + return qlink(E_table[m]); + sz = (m + 1) * sizeof(NUMBER *); + if (sz < (size_t) m + 1) + return NULL; + if (E_num) + p = (NUMBER **) realloc(E_table, sz); + else + p = (NUMBER **) malloc(sz); + if (p == NULL) + return NULL; + E_table = p; + for (k = E_num; k <= m; k++) { + nn = 2 * k + 2; + dd = 1; + c = qlink(&_qone_); + s = qlink(&_qnegone_); + i = k; + for (i = 0; i < k; i++) { + c1 = qmuli(c, nn--); + qfree(c); + c = qdivi(c1, dd++); + qfree(c1); + c1 = qmuli(c, nn--); + qfree(c); + c = qdivi(c1, dd++); + qfree(c1); + t = qmul(c, E_table[i]); + s1 = qsub(s, t); + qfree(t); + qfree(s); + s = s1; + } + E_table[k] = s; + qfree(c); + } + E_num = k; + return qlink(E_table[m]); } void qfreeeuler(void) { - long k; + long k; - if (E_num > 0) { - for (k = 0; k < E_num; k++) - qfree(E_table[k]); - free(E_table); - } - E_table = NULL; - E_num = 0; + if (E_num > 0) { + for (k = 0; k < E_num; k++) + qfree(E_table[k]); + free(E_table); + } + E_table = NULL; + E_num = 0; } @@ -1184,21 +1184,21 @@ qfreeeuler(void) NUMBER * qcatalan(NUMBER *q) { - NUMBER *A, *B; - NUMBER *res; + NUMBER *A, *B; + NUMBER *res; - if (qisneg(q)) - return qlink(&_qzero_); - A = qscale(q, 1); - B = qcomb(A, q); - if (B == NULL) - return NULL; - qfree(A); - A = qinc(q); - res = qqdiv(B, A); - qfree(A); - qfree(B); - return res; + if (qisneg(q)) + return qlink(&_qzero_); + A = qscale(q, 1); + B = qcomb(A, q); + if (B == NULL) + return NULL; + qfree(A); + A = qinc(q); + res = qqdiv(B, A); + qfree(A); + qfree(B); + return res; } /* @@ -1210,11 +1210,11 @@ qcatalan(NUMBER *q) NUMBER * qjacobi(NUMBER *q1, NUMBER *q2) { - if (qisfrac(q1) || qisfrac(q2)) { - math_error("Non-integral arguments for jacobi"); - not_reached(); - } - return itoq((long) zjacobi(q1->num, q2->num)); + if (qisfrac(q1) || qisfrac(q2)) { + math_error("Non-integral arguments for jacobi"); + not_reached(); + } + return itoq((long) zjacobi(q1->num, q2->num)); } @@ -1224,15 +1224,15 @@ qjacobi(NUMBER *q1, NUMBER *q2) NUMBER * qfib(NUMBER *q) { - register NUMBER *r; + register NUMBER *r; - if (qisfrac(q)) { - math_error("Non-integral Fibonacci number"); - not_reached(); - } - r = qalloc(); - zfib(q->num, &r->num); - return r; + if (qisfrac(q)) { + math_error("Non-integral Fibonacci number"); + not_reached(); + } + r = qalloc(); + zfib(q->num, &r->num); + return r; } @@ -1242,18 +1242,18 @@ qfib(NUMBER *q) NUMBER * qtrunc(NUMBER *q1, NUMBER *q2) { - long places; - NUMBER *r, *e; + long places; + NUMBER *r, *e; - if (qisfrac(q2) || !zistiny(q2->num)) { - math_error("Bad number of places for qtrunc"); - not_reached(); - } - places = qtoi(q2); - e = qtenpow(-places); - r = qmappr(q1, e, 2); - qfree(e); - return r; + if (qisfrac(q2) || !zistiny(q2->num)) { + math_error("Bad number of places for qtrunc"); + not_reached(); + } + places = qtoi(q2); + e = qtenpow(-places); + r = qmappr(q1, e, 2); + qfree(e); + return r; } @@ -1266,18 +1266,18 @@ qtrunc(NUMBER *q1, NUMBER *q2) NUMBER * qbtrunc(NUMBER *q1, NUMBER *q2) { - long places; - NUMBER *r, *e; + long places; + NUMBER *r, *e; - if (qisfrac(q2) || !zistiny(q2->num)) { - math_error("Bad number of places for qtrunc"); - not_reached(); - } - places = qtoi(q2); - e = qbitvalue(-places); - r = qmappr(q1, e, 2); - qfree(e); - return r; + if (qisfrac(q2) || !zistiny(q2->num)) { + math_error("Bad number of places for qtrunc"); + not_reached(); + } + places = qtoi(q2); + e = qbitvalue(-places); + r = qmappr(q1, e, 2); + qfree(e); + return r; } @@ -1287,16 +1287,16 @@ qbtrunc(NUMBER *q1, NUMBER *q2) NUMBER * qbround(NUMBER *q, long places, long rnd) { - NUMBER *e, *r; + NUMBER *e, *r; - if (qiszero(q)) - return qlink(&_qzero_); - if (rnd & 32) - places -= qilog2(q) + 1; - e = qbitvalue(-places); - r = qmappr(q, e, rnd & 31); - qfree(e); - return r; + if (qiszero(q)) + return qlink(&_qzero_); + if (rnd & 32) + places -= qilog2(q) + 1; + e = qbitvalue(-places); + r = qmappr(q, e, rnd & 31); + qfree(e); + return r; } /* @@ -1305,47 +1305,47 @@ qbround(NUMBER *q, long places, long rnd) NUMBER * qround(NUMBER *q, long places, long rnd) { - NUMBER *e, *r; + NUMBER *e, *r; - if (qiszero(q)) - return qlink(&_qzero_); - if (rnd & 32) - places -= qilog10(q) + 1; - e = qtenpow(-places); - r = qmappr(q, e, rnd & 31); - qfree(e); - return r; + if (qiszero(q)) + return qlink(&_qzero_); + if (rnd & 32) + places -= qilog10(q) + 1; + e = qtenpow(-places); + r = qmappr(q, e, rnd & 31); + qfree(e); + return r; } /* - * Approximate a number to nearest multiple of a given number. Whether + * Approximate a number to nearest multiple of a given number. Whether * rounding is down, up, etc. is determined by rnd. */ NUMBER * qmappr(NUMBER *q, NUMBER *e, long rnd) { - NUMBER *r; - ZVALUE tmp1, tmp2, mul; + NUMBER *r; + ZVALUE tmp1, tmp2, mul; - if (qiszero(e)) - return qlink(q); - if (qiszero(q)) - return qlink(&_qzero_); - zmul(q->num, e->den, &tmp1); - zmul(q->den, e->num, &tmp2); - zquo(tmp1, tmp2, &mul, rnd); - zfree(tmp1); - zfree(tmp2); - if (ziszero(mul)) { - zfree(mul); - return qlink(&_qzero_); - } - r = qalloc(); - zreduce(mul, e->den, &tmp1, &r->den); - zmul(tmp1, e->num, &r->num); - zfree(tmp1); - zfree(mul); - return r; + if (qiszero(e)) + return qlink(q); + if (qiszero(q)) + return qlink(&_qzero_); + zmul(q->num, e->den, &tmp1); + zmul(q->den, e->num, &tmp2); + zquo(tmp1, tmp2, &mul, rnd); + zfree(tmp1); + zfree(tmp2); + if (ziszero(mul)) { + zfree(mul); + return qlink(&_qzero_); + } + r = qalloc(); + zreduce(mul, e->den, &tmp1, &r->den); + zmul(tmp1, e->num, &r->num); + zfree(tmp1); + zfree(mul); + return r; } @@ -1361,167 +1361,167 @@ qmappr(NUMBER *q, NUMBER *e, long rnd) NUMBER * qcfappr(NUMBER *q, NUMBER *epsilon, long rnd) { - NUMBER *res, etemp, *epsilon1; - ZVALUE num, zden, oldnum, oldden; - ZVALUE rem, oldrem, quot; - ZVALUE tmp1, tmp2, tmp3, tmp4; - ZVALUE denbnd; - ZVALUE f, g, k; - bool esign; - int s; - bool bnddencase; - bool useold = false; + NUMBER *res, etemp, *epsilon1; + ZVALUE num, zden, oldnum, oldden; + ZVALUE rem, oldrem, quot; + ZVALUE tmp1, tmp2, tmp3, tmp4; + ZVALUE denbnd; + ZVALUE f, g, k; + bool esign; + int s; + bool bnddencase; + bool useold = false; - if (qiszero(epsilon) || qisint(q)) - return qlink(q); + if (qiszero(epsilon) || qisint(q)) + return qlink(q); - esign = epsilon->num.sign; - etemp = *epsilon; - etemp.num.sign = 0; - bnddencase = (zrel(etemp.num, etemp.den) >= 0); - if (bnddencase) { - zquo(etemp.num, etemp.den, &denbnd, 0); - if (zrel(q->den, denbnd) <= 0) { - zfree(denbnd); - return qlink(q); - } - } else { - if (rnd & 16) - epsilon1 = qscale(epsilon, -1); - else - epsilon1 = qlink(epsilon); - zreduce(q->den, epsilon1->den, &tmp1, &g); - zmul(epsilon1->num, tmp1, &f); - f.sign = 0; - zfree(tmp1); - qfree(epsilon1); - } - if (rnd & 16 && !zistwo(q->den)) { - s = 0; - } else { - s = esign ? -1 : 1; - if (rnd & 1) - s = -s; - if (rnd & 2 && q->num.sign ^ esign) - s = -s; - if (rnd & 4 && esign) - s = -s; - } - oldnum = _one_; - oldden = _zero_; - zcopy(q->den, &oldrem); - zdiv(q->num, q->den, &num, &rem, 0); - zden = _one_; - for (;;) { - if (!bnddencase) { - zmul(f, zden, &tmp1); - zmul(g, rem, &tmp2); - if (ziszero(rem) || (s >= 0 && zrel(tmp1,tmp2) >= 0)) - break; - zfree(tmp1); - zfree(tmp2); - } - zdiv(oldrem, rem, ", &tmp1, 0); - zfree(oldrem); - oldrem = rem; - rem = tmp1; - zmul(quot, zden, &tmp1); - zadd(tmp1, oldden, &tmp2); - zfree(tmp1); - zfree(oldden); - oldden = zden; - zden = tmp2; - zmul(quot, num, &tmp1); - zadd(tmp1, oldnum, &tmp2); - zfree(tmp1); - zfree(oldnum); - oldnum = num; - num = tmp2; - zfree(quot); - if (bnddencase) { - if (zrel(zden, denbnd) >= 0) - break; - } - s = -s; - } - if (bnddencase) { - if (s > 0) { - useold = true; - } else { - zsub(zden, denbnd, &tmp1); - zquo(tmp1, oldden, &k, 1); - zfree(tmp1); - } - zfree(denbnd); - } else { - if (s < 0) { - zfree(tmp1); - zfree(tmp2); - zfree(f); - zfree(g); - zfree(oldnum); - zfree(oldden); - zfree(num); - zfree(zden); - zfree(oldrem); - zfree(rem); - return qlink(q); - } - zsub(tmp1, tmp2, &tmp3); - zfree(tmp1); - zfree(tmp2); - zmul(f, oldden, &tmp1); - zmul(g, oldrem, &tmp2); - zfree(f); - zfree(g); - zadd(tmp1, tmp2, &tmp4); - zfree(tmp1); - zfree(tmp2); - zquo(tmp3, tmp4, &k, 0); - zfree(tmp3); - zfree(tmp4); - } - if (!useold && !ziszero(k)) { - zmul(k, oldnum, &tmp1); - zsub(num, tmp1, &tmp2); - zfree(tmp1); - zfree(num); - num = tmp2; - zmul(k, oldden, &tmp1); - zsub(zden, tmp1, &tmp2); - zfree(tmp1); - zfree(zden); - zden = tmp2; - } - if (bnddencase && s == 0) { - zmul(k, oldrem, &tmp1); - zadd(rem, tmp1, &tmp2); - zfree(tmp1); - zfree(rem); - rem = tmp2; - zmul(rem, oldden, &tmp1); - zmul(zden, oldrem, &tmp2); - useold = (zrel(tmp1, tmp2) >= 0); - zfree(tmp1); - zfree(tmp2); - } - if (!bnddencase || s <= 0) - zfree(k); - zfree(rem); - zfree(oldrem); - res = qalloc(); - if (useold) { - zfree(num); - zfree(zden); - res->num = oldnum; - res->den = oldden; - return res; - } - zfree(oldnum); - zfree(oldden); - res->num = num; - res->den = zden; - return res; + esign = epsilon->num.sign; + etemp = *epsilon; + etemp.num.sign = 0; + bnddencase = (zrel(etemp.num, etemp.den) >= 0); + if (bnddencase) { + zquo(etemp.num, etemp.den, &denbnd, 0); + if (zrel(q->den, denbnd) <= 0) { + zfree(denbnd); + return qlink(q); + } + } else { + if (rnd & 16) + epsilon1 = qscale(epsilon, -1); + else + epsilon1 = qlink(epsilon); + zreduce(q->den, epsilon1->den, &tmp1, &g); + zmul(epsilon1->num, tmp1, &f); + f.sign = 0; + zfree(tmp1); + qfree(epsilon1); + } + if (rnd & 16 && !zistwo(q->den)) { + s = 0; + } else { + s = esign ? -1 : 1; + if (rnd & 1) + s = -s; + if (rnd & 2 && q->num.sign ^ esign) + s = -s; + if (rnd & 4 && esign) + s = -s; + } + oldnum = _one_; + oldden = _zero_; + zcopy(q->den, &oldrem); + zdiv(q->num, q->den, &num, &rem, 0); + zden = _one_; + for (;;) { + if (!bnddencase) { + zmul(f, zden, &tmp1); + zmul(g, rem, &tmp2); + if (ziszero(rem) || (s >= 0 && zrel(tmp1,tmp2) >= 0)) + break; + zfree(tmp1); + zfree(tmp2); + } + zdiv(oldrem, rem, ", &tmp1, 0); + zfree(oldrem); + oldrem = rem; + rem = tmp1; + zmul(quot, zden, &tmp1); + zadd(tmp1, oldden, &tmp2); + zfree(tmp1); + zfree(oldden); + oldden = zden; + zden = tmp2; + zmul(quot, num, &tmp1); + zadd(tmp1, oldnum, &tmp2); + zfree(tmp1); + zfree(oldnum); + oldnum = num; + num = tmp2; + zfree(quot); + if (bnddencase) { + if (zrel(zden, denbnd) >= 0) + break; + } + s = -s; + } + if (bnddencase) { + if (s > 0) { + useold = true; + } else { + zsub(zden, denbnd, &tmp1); + zquo(tmp1, oldden, &k, 1); + zfree(tmp1); + } + zfree(denbnd); + } else { + if (s < 0) { + zfree(tmp1); + zfree(tmp2); + zfree(f); + zfree(g); + zfree(oldnum); + zfree(oldden); + zfree(num); + zfree(zden); + zfree(oldrem); + zfree(rem); + return qlink(q); + } + zsub(tmp1, tmp2, &tmp3); + zfree(tmp1); + zfree(tmp2); + zmul(f, oldden, &tmp1); + zmul(g, oldrem, &tmp2); + zfree(f); + zfree(g); + zadd(tmp1, tmp2, &tmp4); + zfree(tmp1); + zfree(tmp2); + zquo(tmp3, tmp4, &k, 0); + zfree(tmp3); + zfree(tmp4); + } + if (!useold && !ziszero(k)) { + zmul(k, oldnum, &tmp1); + zsub(num, tmp1, &tmp2); + zfree(tmp1); + zfree(num); + num = tmp2; + zmul(k, oldden, &tmp1); + zsub(zden, tmp1, &tmp2); + zfree(tmp1); + zfree(zden); + zden = tmp2; + } + if (bnddencase && s == 0) { + zmul(k, oldrem, &tmp1); + zadd(rem, tmp1, &tmp2); + zfree(tmp1); + zfree(rem); + rem = tmp2; + zmul(rem, oldden, &tmp1); + zmul(zden, oldrem, &tmp2); + useold = (zrel(tmp1, tmp2) >= 0); + zfree(tmp1); + zfree(tmp2); + } + if (!bnddencase || s <= 0) + zfree(k); + zfree(rem); + zfree(oldrem); + res = qalloc(); + if (useold) { + zfree(num); + zfree(zden); + res->num = oldnum; + res->den = oldden; + return res; + } + zfree(oldnum); + zfree(oldden); + res->num = num; + res->den = zden; + return res; } @@ -1533,64 +1533,64 @@ qcfappr(NUMBER *q, NUMBER *epsilon, long rnd) NUMBER * qcfsim(NUMBER *q, long rnd) { - NUMBER *res; - ZVALUE tmp1, tmp2, den1, den2; - int s; + NUMBER *res; + ZVALUE tmp1, tmp2, den1, den2; + int s; - if (qiszero(q) && rnd & 26) - return qlink(&_qzero_); - if (rnd & 24) { - s = q->num.sign; - } else { - s = rnd & 1; - if (rnd & 2) - s ^= q->num.sign; - } - if (qisint(q)) { - if ((rnd & 8) && !(rnd & 16)) - return qlink(&_qzero_); - if (s) - return qinc(q); - return qdec(q); - } - if (zistwo(q->den)) { - if (rnd & 16) - s ^= 1; - if (s) - zadd(q->num, _one_, &tmp1); - else - zsub(q->num, _one_, &tmp1); - res = qalloc(); - zshift(tmp1, -1, &res->num); - zfree(tmp1); - return res; - } - s = s ? 1 : -1; - if (rnd & 24) - s = 0; - res = qalloc(); - zmodinv(q->num, q->den, &den1); - if (s >= 0) { - zsub(q->den, den1, &den2); - if (s > 0 || ((zrel(den1, den2) < 0) ^ (!(rnd & 16)))) { - zfree(den1); - res->den = den2; - zmul(den2, q->num, &tmp1); - zadd(tmp1, _one_, &tmp2); - zfree(tmp1); - zequo(tmp2, q->den, &res->num); - zfree(tmp2); - return res; - } - zfree(den2); - } - res->den = den1; - zmul(den1, q->num, &tmp1); - zsub(tmp1, _one_, &tmp2); - zfree(tmp1); - zequo(tmp2, q->den, &res->num); - zfree(tmp2); - return res; + if (qiszero(q) && rnd & 26) + return qlink(&_qzero_); + if (rnd & 24) { + s = q->num.sign; + } else { + s = rnd & 1; + if (rnd & 2) + s ^= q->num.sign; + } + if (qisint(q)) { + if ((rnd & 8) && !(rnd & 16)) + return qlink(&_qzero_); + if (s) + return qinc(q); + return qdec(q); + } + if (zistwo(q->den)) { + if (rnd & 16) + s ^= 1; + if (s) + zadd(q->num, _one_, &tmp1); + else + zsub(q->num, _one_, &tmp1); + res = qalloc(); + zshift(tmp1, -1, &res->num); + zfree(tmp1); + return res; + } + s = s ? 1 : -1; + if (rnd & 24) + s = 0; + res = qalloc(); + zmodinv(q->num, q->den, &den1); + if (s >= 0) { + zsub(q->den, den1, &den2); + if (s > 0 || ((zrel(den1, den2) < 0) ^ (!(rnd & 16)))) { + zfree(den1); + res->den = den2; + zmul(den2, q->num, &tmp1); + zadd(tmp1, _one_, &tmp2); + zfree(tmp1); + zequo(tmp2, q->den, &res->num); + zfree(tmp2); + return res; + } + zfree(den2); + } + res->den = den1; + zmul(den1, q->num, &tmp1); + zsub(tmp1, _one_, &tmp2); + zfree(tmp1); + zequo(tmp2, q->den, &res->num); + zfree(tmp2); + return res; } @@ -1605,94 +1605,94 @@ qcfsim(NUMBER *q, long rnd) FLAG qnear(NUMBER *q1, NUMBER *q2, NUMBER *epsilon) { - int res; - NUMBER qtemp, etemp, *qq; + int res; + NUMBER qtemp, etemp, *qq; - etemp = *epsilon; - etemp.num.sign = 0; - if (q1 == q2) { - if (qiszero(epsilon)) - return 0; - return -1; - } - if (qiszero(epsilon)) - return qcmp(q1, q2); - if (qiszero(q2)) { - qtemp = *q1; - qtemp.num.sign = 0; - return qrel(&qtemp, &etemp); - } - if (qiszero(q1)) { - qtemp = *q2; - qtemp.num.sign = 0; - return qrel(&qtemp, &etemp); - } - qq = qsub(q1, q2); - qtemp = *qq; - qtemp.num.sign = 0; - res = qrel(&qtemp, &etemp); - qfree(qq); - return res; + etemp = *epsilon; + etemp.num.sign = 0; + if (q1 == q2) { + if (qiszero(epsilon)) + return 0; + return -1; + } + if (qiszero(epsilon)) + return qcmp(q1, q2); + if (qiszero(q2)) { + qtemp = *q1; + qtemp.num.sign = 0; + return qrel(&qtemp, &etemp); + } + if (qiszero(q1)) { + qtemp = *q2; + qtemp.num.sign = 0; + return qrel(&qtemp, &etemp); + } + qq = qsub(q1, q2); + qtemp = *qq; + qtemp.num.sign = 0; + res = qrel(&qtemp, &etemp); + qfree(qq); + return res; } /* * Compute the gcd (greatest common divisor) of two numbers. - * q3 = qgcd(q1, q2); + * q3 = qgcd(q1, q2); */ NUMBER * qgcd(NUMBER *q1, NUMBER *q2) { - ZVALUE z; - NUMBER *q; + ZVALUE z; + NUMBER *q; - if (q1 == q2) - return qqabs(q1); - if (qisfrac(q1) || qisfrac(q2)) { - q = qalloc(); - zgcd(q1->num, q2->num, &q->num); - zlcm(q1->den, q2->den, &q->den); - return q; - } - if (qiszero(q1)) - return qqabs(q2); - if (qiszero(q2)) - return qqabs(q1); - if (qisunit(q1) || qisunit(q2)) - return qlink(&_qone_); - zgcd(q1->num, q2->num, &z); - if (zisunit(z)) { - zfree(z); - return qlink(&_qone_); - } - q = qalloc(); - q->num = z; - return q; + if (q1 == q2) + return qqabs(q1); + if (qisfrac(q1) || qisfrac(q2)) { + q = qalloc(); + zgcd(q1->num, q2->num, &q->num); + zlcm(q1->den, q2->den, &q->den); + return q; + } + if (qiszero(q1)) + return qqabs(q2); + if (qiszero(q2)) + return qqabs(q1); + if (qisunit(q1) || qisunit(q2)) + return qlink(&_qone_); + zgcd(q1->num, q2->num, &z); + if (zisunit(z)) { + zfree(z); + return qlink(&_qone_); + } + q = qalloc(); + q->num = z; + return q; } /* * Compute the lcm (least common multiple) of two numbers. - * q3 = qlcm(q1, q2); + * q3 = qlcm(q1, q2); */ NUMBER * qlcm(NUMBER *q1, NUMBER *q2) { - NUMBER *q; + NUMBER *q; - if (qiszero(q1) || qiszero(q2)) - return qlink(&_qzero_); - if (q1 == q2) - return qqabs(q1); - if (qisunit(q1)) - return qqabs(q2); - if (qisunit(q2)) - return qqabs(q1); - q = qalloc(); - zlcm(q1->num, q2->num, &q->num); - if (qisfrac(q1) || qisfrac(q2)) - zgcd(q1->den, q2->den, &q->den); - return q; + if (qiszero(q1) || qiszero(q2)) + return qlink(&_qzero_); + if (q1 == q2) + return qqabs(q1); + if (qisunit(q1)) + return qqabs(q2); + if (qisunit(q2)) + return qqabs(q1); + q = qalloc(); + zlcm(q1->num, q2->num, &q->num); + if (qisfrac(q1) || qisfrac(q2)) + zgcd(q1->den, q2->den, &q->den); + return q; } @@ -1703,30 +1703,30 @@ qlcm(NUMBER *q1, NUMBER *q2) NUMBER * qfacrem(NUMBER *q1, NUMBER *q2) { - long count; - ZVALUE tmp; - NUMBER *r; + long count; + ZVALUE tmp; + NUMBER *r; - if (qisfrac(q1) || qisfrac(q2)) { - math_error("Non-integers for factor removal"); - not_reached(); - } - if (qiszero(q2)) - return qqabs(q1); - if (qiszero(q1)) - return qlink(&_qzero_); - count = zfacrem(q1->num, q2->num, &tmp); - if (zisunit(tmp)) { - zfree(tmp); - return qlink(&_qone_); - } - if (count == 0 && !qisneg(q1)) { - zfree(tmp); - return qlink(q1); - } - r = qalloc(); - r->num = tmp; - return r; + if (qisfrac(q1) || qisfrac(q2)) { + math_error("Non-integers for factor removal"); + not_reached(); + } + if (qiszero(q2)) + return qqabs(q1); + if (qiszero(q1)) + return qlink(&_qzero_); + count = zfacrem(q1->num, q2->num, &tmp); + if (zisunit(tmp)) { + zfree(tmp); + return qlink(&_qone_); + } + if (count == 0 && !qisneg(q1)) { + zfree(tmp); + return qlink(q1); + } + r = qalloc(); + r->num = tmp; + return r; } @@ -1737,30 +1737,30 @@ qfacrem(NUMBER *q1, NUMBER *q2) NUMBER * qgcdrem(NUMBER *q1, NUMBER *q2) { - ZVALUE tmp; - NUMBER *r; + ZVALUE tmp; + NUMBER *r; - if (qisfrac(q1) || qisfrac(q2)) { - math_error("Non-integers for gcdrem"); - not_reached(); - } - if (qiszero(q2)) - return qlink(&_qone_); - if (qiszero(q1)) - return qlink(&_qzero_); - if (zgcdrem(q1->num, q2->num, &tmp) == 0) - return qqabs(q1); - if (zisunit(tmp)) { - zfree(tmp); - return qlink(&_qone_); - } - if (zcmp(q1->num, tmp) == 0) { - zfree(tmp); - return qlink(q1); - } - r = qalloc(); - r->num = tmp; - return r; + if (qisfrac(q1) || qisfrac(q2)) { + math_error("Non-integers for gcdrem"); + not_reached(); + } + if (qiszero(q2)) + return qlink(&_qone_); + if (qiszero(q1)) + return qlink(&_qzero_); + if (zgcdrem(q1->num, q2->num, &tmp) == 0) + return qqabs(q1); + if (zisunit(tmp)) { + zfree(tmp); + return qlink(&_qone_); + } + if (zcmp(q1->num, tmp) == 0) { + zfree(tmp); + return qlink(q1); + } + r = qalloc(); + r->num = tmp; + return r; } @@ -1772,18 +1772,18 @@ qgcdrem(NUMBER *q1, NUMBER *q2) NUMBER * qlowfactor(NUMBER *q1, NUMBER *q2) { - unsigned long count; + unsigned long count; - if (qisfrac(q1) || qisfrac(q2)) { - math_error("Non-integers for lowfactor"); - not_reached(); - } - count = ztoi(q2->num); - if (count > PIX_32B) { - math_error("lowfactor count is too large"); - not_reached(); - } - return utoq(zlowfactor(q1->num, count)); + if (qisfrac(q1) || qisfrac(q2)) { + math_error("Non-integers for lowfactor"); + not_reached(); + } + count = ztoi(q2->num); + if (count > PIX_32B) { + math_error("lowfactor count is too large"); + not_reached(); + } + return utoq(zlowfactor(q1->num, count)); } /* @@ -1795,32 +1795,32 @@ qlowfactor(NUMBER *q1, NUMBER *q2) long qdecplaces(NUMBER *q) { - long twopow, fivepow; - HALF fiveval[2]; - ZVALUE five; - ZVALUE tmp; + long twopow, fivepow; + HALF fiveval[2]; + ZVALUE five; + ZVALUE tmp; - if (qisint(q)) /* no decimal places if number is integer */ - return 0; - /* - * The number of decimal places of a fraction in lowest terms is finite - * if an only if the denominator is of the form 2^A * 5^B, and then the - * number of decimal places is equal to MAX(A, B). - */ - five.sign = 0; - five.len = 1; - five.v = fiveval; - fiveval[0] = 5; - fivepow = zfacrem(q->den, five, &tmp); - if (!zisonebit(tmp)) { - zfree(tmp); - return -1; - } - twopow = zlowbit(tmp); - zfree(tmp); - if (twopow < fivepow) - twopow = fivepow; - return twopow; + if (qisint(q)) /* no decimal places if number is integer */ + return 0; + /* + * The number of decimal places of a fraction in lowest terms is finite + * if an only if the denominator is of the form 2^A * 5^B, and then the + * number of decimal places is equal to MAX(A, B). + */ + five.sign = 0; + five.len = 1; + five.v = fiveval; + fiveval[0] = 5; + fivepow = zfacrem(q->den, five, &tmp); + if (!zisonebit(tmp)) { + zfree(tmp); + return -1; + } + twopow = zlowbit(tmp); + zfree(tmp); + if (twopow < fivepow) + twopow = fivepow; + return twopow; } @@ -1833,27 +1833,27 @@ qdecplaces(NUMBER *q) long qplaces(NUMBER *q, ZVALUE base) { - long count; - ZVALUE tmp; + long count; + ZVALUE tmp; - if (base.len == 1 && base.v[0] == 10) - return qdecplaces(q); - if (ziszero(base) || zisunit(base)) - return -2; - if (qisint(q)) - return 0; - if (zisonebit(base)) { - if (!zisonebit(q->den)) - return -1; - return 1 + (zlowbit(q->den) - 1)/zlowbit(base); - } - count = zgcdrem(q->den, base, &tmp); - if (count == 0) - return -1; - if (!zisunit(tmp)) - count = -1; - zfree(tmp); - return count; + if (base.len == 1 && base.v[0] == 10) + return qdecplaces(q); + if (ziszero(base) || zisunit(base)) + return -2; + if (qisint(q)) + return 0; + if (zisonebit(base)) { + if (!zisonebit(q->den)) + return -1; + return 1 + (zlowbit(q->den) - 1)/zlowbit(base); + } + count = zgcdrem(q->den, base, &tmp); + if (count == 0) + return -1; + if (!zisunit(tmp)) + count = -1; + zfree(tmp); + return count; } @@ -1869,15 +1869,15 @@ qplaces(NUMBER *q, ZVALUE base) bool qprimetest(NUMBER *q1, NUMBER *q2, NUMBER *q3) { - if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3)) { - math_error("Bad arguments for ptest"); - not_reached(); - } - if (zge24b(q2->num)) { - math_error("ptest count >= 2^24"); - not_reached(); - } - return zprimetest(q1->num, ztoi(q2->num), q3->num); + if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3)) { + math_error("Bad arguments for ptest"); + not_reached(); + } + if (zge24b(q2->num)) { + math_error("ptest count >= 2^24"); + not_reached(); + } + return zprimetest(q1->num, ztoi(q2->num), q3->num); } @@ -1885,84 +1885,84 @@ qprimetest(NUMBER *q1, NUMBER *q2, NUMBER *q3) * test if a number is an integer power of 2 * * given: - * q value to check if it is a power of 2 - * qlog2 when q is an integer power of 2 (return true), set to log base 2 of q - * when q is NOT an integer power of 2 (return false), *qlog2 is not set + * q value to check if it is a power of 2 + * qlog2 when q is an integer power of 2 (return true), set to log base 2 of q + * when q is NOT an integer power of 2 (return false), *qlog2 is not set * * returns: - * true q is a power of 2 - * false q is not a power of 2 + * true q is a power of 2 + * false q is not a power of 2 */ bool qispowerof2(NUMBER *q, NUMBER **qlog2) { - FULL log2; /* base 2 logarithm as a ZVALUE */ + FULL log2; /* base 2 logarithm as a ZVALUE */ - /* firewall */ - if (q == NULL) { - math_error("%s: q is NULL", __func__); - not_reached(); - } - if (qlog2 == NULL) { - math_error("%s: qlog2 is NULL", __func__); - not_reached(); - } - if (*qlog2 == NULL) { - math_error("%s: *qlog2 is NULL", __func__); - not_reached(); - } + /* firewall */ + if (q == NULL) { + math_error("%s: q is NULL", __func__); + not_reached(); + } + if (qlog2 == NULL) { + math_error("%s: qlog2 is NULL", __func__); + not_reached(); + } + if (*qlog2 == NULL) { + math_error("%s: *qlog2 is NULL", __func__); + not_reached(); + } - /* zero and negative values are never integer powers of 2 */ - if (qiszero(q) || qisneg(q)) { - /* leave *qlog2 untouched and return false */ - return false; - } + /* zero and negative values are never integer powers of 2 */ + if (qiszero(q) || qisneg(q)) { + /* leave *qlog2 untouched and return false */ + return false; + } - /* - * case: q>0 is an integer - */ - if (qisint(q)) { + /* + * case: q>0 is an integer + */ + if (qisint(q)) { - /* - * check if q is an integer power of 2 - */ - if (zispowerof2(q->num, &log2)) { + /* + * check if q is an integer power of 2 + */ + if (zispowerof2(q->num, &log2)) { - /* - * case: q is an integer power of 2 - * - * Set *qlog2 to base 2 logarithm of q and return true. - */ - *qlog2 = utoq(log2); - return true; - } + /* + * case: q is an integer power of 2 + * + * Set *qlog2 to base 2 logarithm of q and return true. + */ + *qlog2 = utoq(log2); + return true; + } - /* - * case: q>0 is 1 over an integer - */ - } else if (qisreciprocal(q)) { + /* + * case: q>0 is 1 over an integer + */ + } else if (qisreciprocal(q)) { - /* - * check if q is 1 over an integer power of 2 - */ - if (zispowerof2(q->den, &log2)) { + /* + * check if q is 1 over an integer power of 2 + */ + if (zispowerof2(q->den, &log2)) { - /* - * case: q>0 is an integer power of 2 - * - * Set *qlog2 to base 2 logarithm of q, which will be a negative value, - * and return true. - */ - **qlog2 = *utoq(log2); - (*qlog2)->num.sign = !(*qlog2)->num.sign; /* set *qlog2 to -log2 */ - return true; - } - } + /* + * case: q>0 is an integer power of 2 + * + * Set *qlog2 to base 2 logarithm of q, which will be a negative value, + * and return true. + */ + **qlog2 = *utoq(log2); + (*qlog2)->num.sign = !(*qlog2)->num.sign; /* set *qlog2 to -log2 */ + return true; + } + } - /* - * q is not an integer power of 2 - * - * Leave *qlog2 untouched and return false. - */ - return false; + /* + * q is not an integer power of 2 + * + * Leave *qlog2 untouched and return false. + */ + return false; } diff --git a/qio.c b/qio.c index 0d3e4fe..314b230 100644 --- a/qio.c +++ b/qio.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1993/07/30 19:42:46 - * File existed as early as: 1993 + * Under source code control: 1993/07/30 19:42:46 + * File existed as early as: 1993 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -32,16 +32,16 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define PUTCHAR(ch) math_chr(ch) -#define PUTSTR(str) math_str(str) -#define PRINTF1(fmt, a1) math_fmt(fmt, a1) -#define PRINTF2(fmt, a1, a2) math_fmt(fmt, a1, a2) +#define PUTCHAR(ch) math_chr(ch) +#define PUTSTR(str) math_str(str) +#define PRINTF1(fmt, a1) math_fmt(fmt, a1) +#define PRINTF2(fmt, a1, a2) math_fmt(fmt, a1, a2) -STATIC long scalefactor; -STATIC ZVALUE scalenumber = { 0, 0, 0 }; +STATIC long scalefactor; +STATIC ZVALUE scalenumber = { 0, 0, 0 }; /* @@ -54,131 +54,131 @@ STATIC ZVALUE scalenumber = { 0, 0, 0 }; void qprintf(char *fmt, ...) { - va_list ap; - NUMBER *q; - int ch, sign = 1; - long width = 0, precision = 0; - int trigger = 0; + va_list ap; + NUMBER *q; + int ch, sign = 1; + long width = 0, precision = 0; + int trigger = 0; - va_start(ap, fmt); - while ((ch = *fmt++) != '\0') { - if (trigger == 0) { - if (ch == '\\') { - ch = *fmt++; - switch (ch) { - case 'a': ch = '\a'; break; - case 'b': ch = '\b'; break; - case 'f': ch = '\f'; break; - case 'n': ch = '\n'; break; - case 'r': ch = '\r'; break; - case 't': ch = '\t'; break; - case 'v': ch = '\v'; break; - case 0: - va_end(ap); - return; - } - PUTCHAR(ch); - continue; - } - if (ch != '%') { - PUTCHAR(ch); - continue; - } - ch = *fmt++; - width = 0; precision = 8; sign = 1; - trigger = 1; - } + va_start(ap, fmt); + while ((ch = *fmt++) != '\0') { + if (trigger == 0) { + if (ch == '\\') { + ch = *fmt++; + switch (ch) { + case 'a': ch = '\a'; break; + case 'b': ch = '\b'; break; + case 'f': ch = '\f'; break; + case 'n': ch = '\n'; break; + case 'r': ch = '\r'; break; + case 't': ch = '\t'; break; + case 'v': ch = '\v'; break; + case 0: + va_end(ap); + return; + } + PUTCHAR(ch); + continue; + } + if (ch != '%') { + PUTCHAR(ch); + continue; + } + ch = *fmt++; + width = 0; precision = 8; sign = 1; + trigger = 1; + } - switch (ch) { - case 'd': - q = va_arg(ap, NUMBER *); - qprintfd(q, width); - break; - case 'f': - q = va_arg(ap, NUMBER *); - qprintff(q, width, precision); - break; - case 'e': - q = va_arg(ap, NUMBER *); - qprintfe(q, width, precision); - break; - case 'g': - q = va_arg(ap, NUMBER *); - /* XXX - we need a qprintfg function */ -#if 0 /* XXX - we need a qprintfg() function */ - qprintfg(q, width, precision); -#else /* XXX - use qprintfe until we have a qprintfg() function */ - qprintfe(q, width, precision); -#endif /* XXX - we need a qprintfg() function */ - break; - case 'r': - case 'R': - q = va_arg(ap, NUMBER *); - qprintfr(q, width, (bool) (ch == 'R')); - break; - case 'N': - q = va_arg(ap, NUMBER *); - zprintval(q->num, 0L, width); - break; - case 'D': - q = va_arg(ap, NUMBER *); - zprintval(q->den, 0L, width); - break; - case 'o': - q = va_arg(ap, NUMBER *); - qprintfo(q, width); - break; - case 'x': - q = va_arg(ap, NUMBER *); - qprintfx(q, width); - break; - case 'b': - q = va_arg(ap, NUMBER *); - qprintfb(q, width); - break; - case 's': - PUTSTR(va_arg(ap, char *)); - break; - case 'c': - PUTCHAR(va_arg(ap, int)); - break; - case 0: - va_end(ap); - return; - case '-': - sign = -1; - ch = *fmt++; - /*FALLTHRU*/ - default: - if (('0' <= ch && ch <= '9') || - ch == '.' || ch == '*') { - if (ch == '*') { - q = va_arg(ap, NUMBER *); - width = sign * qtoi(q); - ch = *fmt++; - } else if (ch != '.') { - width = ch - '0'; - while ('0' <= (ch = *fmt++) && - ch <= '9') - width = width * 10 + ch - '0'; - width *= sign; - } - if (ch == '.') { - if ((ch = *fmt++) == '*') { - q = va_arg(ap, NUMBER *); - precision = qtoi(q); - ch = *fmt++; - } else { - precision = 0; - while ('0' <= (ch = *fmt++) && - ch <= '9') - precision *= 10+ch-'0'; - } - } - } - } - } - va_end(ap); + switch (ch) { + case 'd': + q = va_arg(ap, NUMBER *); + qprintfd(q, width); + break; + case 'f': + q = va_arg(ap, NUMBER *); + qprintff(q, width, precision); + break; + case 'e': + q = va_arg(ap, NUMBER *); + qprintfe(q, width, precision); + break; + case 'g': + q = va_arg(ap, NUMBER *); + /* XXX - we need a qprintfg function */ +#if 0 /* XXX - we need a qprintfg() function */ + qprintfg(q, width, precision); +#else /* XXX - use qprintfe until we have a qprintfg() function */ + qprintfe(q, width, precision); +#endif /* XXX - we need a qprintfg() function */ + break; + case 'r': + case 'R': + q = va_arg(ap, NUMBER *); + qprintfr(q, width, (bool) (ch == 'R')); + break; + case 'N': + q = va_arg(ap, NUMBER *); + zprintval(q->num, 0L, width); + break; + case 'D': + q = va_arg(ap, NUMBER *); + zprintval(q->den, 0L, width); + break; + case 'o': + q = va_arg(ap, NUMBER *); + qprintfo(q, width); + break; + case 'x': + q = va_arg(ap, NUMBER *); + qprintfx(q, width); + break; + case 'b': + q = va_arg(ap, NUMBER *); + qprintfb(q, width); + break; + case 's': + PUTSTR(va_arg(ap, char *)); + break; + case 'c': + PUTCHAR(va_arg(ap, int)); + break; + case 0: + va_end(ap); + return; + case '-': + sign = -1; + ch = *fmt++; + /*FALLTHRU*/ + default: + if (('0' <= ch && ch <= '9') || + ch == '.' || ch == '*') { + if (ch == '*') { + q = va_arg(ap, NUMBER *); + width = sign * qtoi(q); + ch = *fmt++; + } else if (ch != '.') { + width = ch - '0'; + while ('0' <= (ch = *fmt++) && + ch <= '9') + width = width * 10 + ch - '0'; + width *= sign; + } + if (ch == '.') { + if ((ch = *fmt++) == '*') { + q = va_arg(ap, NUMBER *); + precision = qtoi(q); + ch = *fmt++; + } else { + precision = 0; + while ('0' <= (ch = *fmt++) && + ch <= '9') + precision *= 10+ch-'0'; + } + } + } + } + } + va_end(ap); } @@ -191,138 +191,138 @@ qprintf(char *fmt, ...) void qprintnum(NUMBER *q, int outmode, LEN outdigits) { - NUMBER tmpval; - long prec, exp; - int outmode2 = MODE2_OFF; + NUMBER tmpval; + long prec, exp; + int outmode2 = MODE2_OFF; - if (outmode == MODE_DEFAULT) { - outmode = conf->outmode; - outmode2 = conf->outmode2; - } - switch (outmode) { - case MODE_INT: - if (conf->tilde_ok && qisfrac(q)) { - PUTCHAR('~'); - if (conf->tilde_space && qisfrac(q)) { - PUTCHAR(' '); - } - } - qprintfd(q, 0L); - break; + if (outmode == MODE_DEFAULT) { + outmode = conf->outmode; + outmode2 = conf->outmode2; + } + switch (outmode) { + case MODE_INT: + if (conf->tilde_ok && qisfrac(q)) { + PUTCHAR('~'); + if (conf->tilde_space && qisfrac(q)) { + PUTCHAR(' '); + } + } + qprintfd(q, 0L); + break; - case MODE_REAL: - prec = qdecplaces(q); - if ((prec < 0) || (prec > outdigits)) { - if (conf->tilde_ok) { - PUTCHAR('~'); - if (conf->tilde_space) { - PUTCHAR(' '); - } - } - } - if (conf->fullzero || (prec < 0) || - (prec > outdigits)) - prec = outdigits; - qprintff(q, 0L, prec); - break; + case MODE_REAL: + prec = qdecplaces(q); + if ((prec < 0) || (prec > outdigits)) { + if (conf->tilde_ok) { + PUTCHAR('~'); + if (conf->tilde_space) { + PUTCHAR(' '); + } + } + } + if (conf->fullzero || (prec < 0) || + (prec > outdigits)) + prec = outdigits; + qprintff(q, 0L, prec); + break; - case MODE_FRAC: - qprintfr(q, 0L, false); - break; + case MODE_FRAC: + qprintfr(q, 0L, false); + break; - case MODE_EXP: - if (qiszero(q)) { - PUTCHAR('0'); - return; - } - tmpval = *q; - tmpval.num.sign = 0; - exp = qilog10(&tmpval); - if (exp == 0) { /* in range to output as real */ - qprintnum(q, MODE_REAL, outdigits); - return; - } - tmpval.num = _one_; - tmpval.den = _one_; - if (exp > 0) - ztenpow(exp, &tmpval.den); - else - ztenpow(-exp, &tmpval.num); - q = qmul(q, &tmpval); - zfree(tmpval.num); - zfree(tmpval.den); - qprintnum(q, MODE_REAL, outdigits); - qfree(q); - PRINTF1("e%ld", exp); - break; + case MODE_EXP: + if (qiszero(q)) { + PUTCHAR('0'); + return; + } + tmpval = *q; + tmpval.num.sign = 0; + exp = qilog10(&tmpval); + if (exp == 0) { /* in range to output as real */ + qprintnum(q, MODE_REAL, outdigits); + return; + } + tmpval.num = _one_; + tmpval.den = _one_; + if (exp > 0) + ztenpow(exp, &tmpval.den); + else + ztenpow(-exp, &tmpval.num); + q = qmul(q, &tmpval); + zfree(tmpval.num); + zfree(tmpval.den); + qprintnum(q, MODE_REAL, outdigits); + qfree(q); + PRINTF1("e%ld", exp); + break; case MODE_ENG: - if (qiszero(q)) { - PUTCHAR('0'); - return; - } - tmpval = *q; - tmpval.num.sign = 0; - exp = qilog10(&tmpval); - if (exp == 0) { /* in range to output as real */ - qprintnum(q, MODE_REAL, outdigits); - return; - } - tmpval.num = _one_; - tmpval.den = _one_; - if (exp > 0) { + if (qiszero(q)) { + PUTCHAR('0'); + return; + } + tmpval = *q; + tmpval.num.sign = 0; + exp = qilog10(&tmpval); + if (exp == 0) { /* in range to output as real */ + qprintnum(q, MODE_REAL, outdigits); + return; + } + tmpval.num = _one_; + tmpval.den = _one_; + if (exp > 0) { exp -= exp % 3; - ztenpow(exp, &tmpval.den); + ztenpow(exp, &tmpval.den); } else { long remainder = exp % 3; if (remainder) exp -= remainder + 3; - ztenpow(-exp, &tmpval.num); + ztenpow(-exp, &tmpval.num); } - q = qmul(q, &tmpval); - zfree(tmpval.num); - zfree(tmpval.den); - qprintnum(q, MODE_REAL, outdigits); - qfree(q); - if (exp) PRINTF1("e%ld", exp); + q = qmul(q, &tmpval); + zfree(tmpval.num); + zfree(tmpval.den); + qprintnum(q, MODE_REAL, outdigits); + qfree(q); + if (exp) PRINTF1("e%ld", exp); break; - case MODE_REAL_AUTO: - { - const int P = conf->outdigits ? conf->outdigits : 1; - tmpval = *q; - tmpval.num.sign = 0; - exp = qilog10(&tmpval); - if (P > exp && exp >= -P) { - qprintnum(q, MODE_REAL, P - 1 - exp); - } else { - qprintnum(q, MODE_EXP, P - 1); - } - break; - } + case MODE_REAL_AUTO: + { + const int P = conf->outdigits ? conf->outdigits : 1; + tmpval = *q; + tmpval.num.sign = 0; + exp = qilog10(&tmpval); + if (P > exp && exp >= -P) { + qprintnum(q, MODE_REAL, P - 1 - exp); + } else { + qprintnum(q, MODE_EXP, P - 1); + } + break; + } - case MODE_HEX: - qprintfx(q, 0L); - break; + case MODE_HEX: + qprintfx(q, 0L); + break; - case MODE_OCTAL: - qprintfo(q, 0L); - break; + case MODE_OCTAL: + qprintfo(q, 0L); + break; - case MODE_BINARY: - qprintfb(q, 0L); - break; + case MODE_BINARY: + qprintfb(q, 0L); + break; - default: - math_error("Bad mode for print"); - not_reached(); - } + default: + math_error("Bad mode for print"); + not_reached(); + } - if (outmode2 != MODE2_OFF) { - PUTSTR(" /* "); - qprintnum(q, outmode2, outdigits); - PUTSTR(" */"); - } + if (outmode2 != MODE2_OFF) { + PUTSTR(" /* "); + qprintnum(q, outmode2, outdigits); + PUTSTR(" */"); + } } @@ -333,29 +333,29 @@ qprintnum(NUMBER *q, int outmode, LEN outdigits) void qprintff(NUMBER *q, long width, long precision) { - ZVALUE z, z1; + ZVALUE z, z1; - if (precision != scalefactor) { - if (scalenumber.v) - zfree(scalenumber); - ztenpow(precision, &scalenumber); - scalefactor = precision; - } - if (scalenumber.v) - zmul(q->num, scalenumber, &z); - else - z = q->num; - if (qisfrac(q)) { - zquo(z, q->den, &z1, conf->outround); - if (z.v != q->num.v) - zfree(z); - z = z1; - } - if (qisneg(q) && ziszero(z)) - PUTCHAR('-'); - zprintval(z, precision, width); - if (z.v != q->num.v) - zfree(z); + if (precision != scalefactor) { + if (scalenumber.v) + zfree(scalenumber); + ztenpow(precision, &scalenumber); + scalefactor = precision; + } + if (scalenumber.v) + zmul(q->num, scalenumber, &z); + else + z = q->num; + if (qisfrac(q)) { + zquo(z, q->den, &z1, conf->outround); + if (z.v != q->num.v) + zfree(z); + z = z1; + } + if (qisneg(q) && ziszero(z)) + PUTCHAR('-'); + zprintval(z, precision, width); + if (z.v != q->num.v) + zfree(z); } @@ -367,47 +367,47 @@ qprintff(NUMBER *q, long width, long precision) void qprintfe(NUMBER *q, long UNUSED(width), long precision) { - long exponent; - NUMBER q2; - ZVALUE num, zden, tenpow, tmp; + long exponent; + NUMBER q2; + ZVALUE num, zden, tenpow, tmp; - if (qiszero(q)) { - PUTSTR("0.0"); - return; - } - num = q->num; - zden = q->den; - num.sign = 0; - exponent = zdigits(num) - zdigits(zden); - if (exponent > 0) { - ztenpow(exponent, &tenpow); - zmul(zden, tenpow, &tmp); - zfree(tenpow); - zden = tmp; - } - if (exponent < 0) { - ztenpow(-exponent, &tenpow); - zmul(num, tenpow, &tmp); - zfree(tenpow); - num = tmp; - } - if (zrel(num, zden) < 0) { - zmuli(num, 10L, &tmp); - if (num.v != q->num.v) - zfree(num); - num = tmp; - exponent--; - } - q2.num = num; - q2.den = zden; - q2.num.sign = q->num.sign; - qprintff(&q2, 0L, precision); - if (exponent) - PRINTF1("e%ld", exponent); - if (num.v != q->num.v) - zfree(num); - if (zden.v != q->den.v) - zfree(zden); + if (qiszero(q)) { + PUTSTR("0.0"); + return; + } + num = q->num; + zden = q->den; + num.sign = 0; + exponent = zdigits(num) - zdigits(zden); + if (exponent > 0) { + ztenpow(exponent, &tenpow); + zmul(zden, tenpow, &tmp); + zfree(tenpow); + zden = tmp; + } + if (exponent < 0) { + ztenpow(-exponent, &tenpow); + zmul(num, tenpow, &tmp); + zfree(tenpow); + num = tmp; + } + if (zrel(num, zden) < 0) { + zmuli(num, 10L, &tmp); + if (num.v != q->num.v) + zfree(num); + num = tmp; + exponent--; + } + q2.num = num; + q2.den = zden; + q2.num.sign = q->num.sign; + qprintff(&q2, 0L, precision); + if (exponent) + PRINTF1("e%ld", exponent); + if (num.v != q->num.v) + zfree(num); + if (zden.v != q->den.v) + zfree(zden); } @@ -418,17 +418,17 @@ qprintfe(NUMBER *q, long UNUSED(width), long precision) void qprintfr(NUMBER *q, long width, bool force) { - zprintval(q->num, 0L, width); - if (force || qisfrac(q)) { - if (conf->fraction_space) { - PUTCHAR(' '); - } - PUTCHAR('/'); - if (conf->fraction_space) { - PUTCHAR(' '); - } - zprintval(q->den, 0L, width); - } + zprintval(q->num, 0L, width); + if (force || qisfrac(q)) { + if (conf->fraction_space) { + PUTCHAR(' '); + } + PUTCHAR('/'); + if (conf->fraction_space) { + PUTCHAR(' '); + } + zprintval(q->den, 0L, width); + } } @@ -439,15 +439,15 @@ qprintfr(NUMBER *q, long width, bool force) void qprintfd(NUMBER *q, long width) { - ZVALUE z; + ZVALUE z; - if (qisfrac(q)) { - zquo(q->num, q->den, &z, conf->outround); - zprintval(z, 0L, width); - zfree(z); - } else { - zprintval(q->num, 0L, width); - } + if (qisfrac(q)) { + zquo(q->num, q->den, &z, conf->outround); + zprintval(z, 0L, width); + zfree(z); + } else { + zprintval(q->num, 0L, width); + } } @@ -458,17 +458,17 @@ qprintfd(NUMBER *q, long width) void qprintfx(NUMBER *q, long width) { - zprintx(q->num, width); - if (qisfrac(q)) { - if (conf->fraction_space) { - PUTCHAR(' '); - } - PUTCHAR('/'); - if (conf->fraction_space) { - PUTCHAR(' '); - } - zprintx(q->den, 0L); - } + zprintx(q->num, width); + if (qisfrac(q)) { + if (conf->fraction_space) { + PUTCHAR(' '); + } + PUTCHAR('/'); + if (conf->fraction_space) { + PUTCHAR(' '); + } + zprintx(q->den, 0L); + } } @@ -479,17 +479,17 @@ qprintfx(NUMBER *q, long width) void qprintfb(NUMBER *q, long width) { - zprintb(q->num, width); - if (qisfrac(q)) { - if (conf->fraction_space) { - PUTCHAR(' '); - } - PUTCHAR('/'); - if (conf->fraction_space) { - PUTCHAR(' '); - } - zprintb(q->den, 0L); - } + zprintb(q->num, width); + if (qisfrac(q)) { + if (conf->fraction_space) { + PUTCHAR(' '); + } + PUTCHAR('/'); + if (conf->fraction_space) { + PUTCHAR(' '); + } + zprintb(q->den, 0L); + } } @@ -500,118 +500,118 @@ qprintfb(NUMBER *q, long width) void qprintfo(NUMBER *q, long width) { - zprinto(q->num, width); - if (qisfrac(q)) { - if (conf->fraction_space) { - PUTCHAR(' '); - } - PUTCHAR('/'); - if (conf->fraction_space) { - PUTCHAR(' '); - } - zprinto(q->den, 0L); - } + zprinto(q->num, width); + if (qisfrac(q)) { + if (conf->fraction_space) { + PUTCHAR(' '); + } + PUTCHAR('/'); + if (conf->fraction_space) { + PUTCHAR(' '); + } + zprinto(q->den, 0L); + } } /* * Convert a string to a number in rational, floating point, * exponential notation, hex, or octal. - * q = str2q(string); + * q = str2q(string); */ NUMBER * str2q(char *s) { - register NUMBER *q; - register char *t; - ZVALUE div, newnum, newden, tmp; - long decimals, exp; - bool hex, negexp; + register NUMBER *q; + register char *t; + ZVALUE div, newnum, newden, tmp; + long decimals, exp; + bool hex, negexp; - q = qalloc(); - decimals = 0; - exp = 0; - negexp = false; - hex = false; - t = s; - if ((*t == '+') || (*t == '-')) - t++; - if ((*t == '0') && ((t[1] == 'x') || (t[1] == 'X'))) { - hex = true; - t += 2; - } - while (((*t >= '0') && (*t <= '9')) || (hex && - (((*t >= 'a') && (*t <= 'f')) || ((*t >= 'A') && (*t <= 'F'))))) - t++; - if (*t == '/') { - t++; - str2z(t, &q->den); - } else if ((*t == '.') || (*t == 'e') || (*t == 'E')) { - if (*t == '.') { - t++; - while ((*t >= '0') && (*t <= '9')) { - t++; - decimals++; - } - } - /* - * Parse exponent if any - */ - if ((*t == 'e') || (*t == 'E')) { - t++; - if (*t == '+') - t++; - else if (*t == '-') { - negexp = true; - t++; - } - while ((*t >= '0') && (*t <= '9')) { - exp = (exp * 10) + *t++ - '0'; - if (exp > (MAXLONG/10L)) { - math_error("Exponent too large"); - not_reached(); - } - } - } - ztenpow(decimals, &q->den); - } - str2z(s, &q->num); - if (qiszero(q)) { - qfree(q); - return qlink(&_qzero_); - } - /* - * Apply the exponential if any - */ - if (exp) { - ztenpow(exp, &tmp); - if (negexp) { - zmul(q->den, tmp, &newden); - zfree(q->den); - q->den = newden; - } else { - zmul(q->num, tmp, &newnum); - zfree(q->num); - q->num = newnum; - } - zfree(tmp); - } - /* - * Reduce the fraction to lowest terms - */ - if (!zisunit(q->num) && !zisunit(q->den)) { - zgcd(q->num, q->den, &div); - if (!zisunit(div)) { - zequo(q->num, div, &newnum); - zfree(q->num); - zequo(q->den, div, &newden); - zfree(q->den); - q->num = newnum; - q->den = newden; - } - zfree(div); - } - return q; + q = qalloc(); + decimals = 0; + exp = 0; + negexp = false; + hex = false; + t = s; + if ((*t == '+') || (*t == '-')) + t++; + if ((*t == '0') && ((t[1] == 'x') || (t[1] == 'X'))) { + hex = true; + t += 2; + } + while (((*t >= '0') && (*t <= '9')) || (hex && + (((*t >= 'a') && (*t <= 'f')) || ((*t >= 'A') && (*t <= 'F'))))) + t++; + if (*t == '/') { + t++; + str2z(t, &q->den); + } else if ((*t == '.') || (*t == 'e') || (*t == 'E')) { + if (*t == '.') { + t++; + while ((*t >= '0') && (*t <= '9')) { + t++; + decimals++; + } + } + /* + * Parse exponent if any + */ + if ((*t == 'e') || (*t == 'E')) { + t++; + if (*t == '+') + t++; + else if (*t == '-') { + negexp = true; + t++; + } + while ((*t >= '0') && (*t <= '9')) { + exp = (exp * 10) + *t++ - '0'; + if (exp > (MAXLONG/10L)) { + math_error("Exponent too large"); + not_reached(); + } + } + } + ztenpow(decimals, &q->den); + } + str2z(s, &q->num); + if (qiszero(q)) { + qfree(q); + return qlink(&_qzero_); + } + /* + * Apply the exponential if any + */ + if (exp) { + ztenpow(exp, &tmp); + if (negexp) { + zmul(q->den, tmp, &newden); + zfree(q->den); + q->den = newden; + } else { + zmul(q->num, tmp, &newnum); + zfree(q->num); + q->num = newnum; + } + zfree(tmp); + } + /* + * Reduce the fraction to lowest terms + */ + if (!zisunit(q->num) && !zisunit(q->den)) { + zgcd(q->num, q->den, &div); + if (!zisunit(div)) { + zequo(q->num, div, &newnum); + zfree(q->num); + zequo(q->den, div, &newden); + zfree(q->den); + q->num = newnum; + q->den = newden; + } + zfree(div); + } + return q; } @@ -628,101 +628,101 @@ str2q(char *s) long qparse(char *cp, int flags) { - char *oldcp; + char *oldcp; - oldcp = cp; - if ((*cp == '+') || (*cp == '-')) - cp++; - if ((*cp == '+') || (*cp == '-')) - return -1; + oldcp = cp; + if ((*cp == '+') || (*cp == '-')) + cp++; + if ((*cp == '+') || (*cp == '-')) + return -1; - /* hex */ - if ((*cp == '0') && ((cp[1] == 'x') || (cp[1] == 'X'))) { - cp += 2; - while (((*cp >= '0') && (*cp <= '9')) || - ((*cp >= 'a') && (*cp <= 'f')) || - ((*cp >= 'A') && (*cp <= 'F'))) - cp++; - if (((*cp == 'i') || (*cp == 'I')) && (flags & QPF_IMAG)) - cp++; - if ((*cp == '.') || ((*cp == '/') && (flags & QPF_SLASH)) || - ((*cp >= '0') && (*cp <= '9')) || - ((*cp >= 'a') && (*cp <= 'z')) || - ((*cp >= 'A') && (*cp <= 'Z'))) - return -1; - return (cp - oldcp); - } + /* hex */ + if ((*cp == '0') && ((cp[1] == 'x') || (cp[1] == 'X'))) { + cp += 2; + while (((*cp >= '0') && (*cp <= '9')) || + ((*cp >= 'a') && (*cp <= 'f')) || + ((*cp >= 'A') && (*cp <= 'F'))) + cp++; + if (((*cp == 'i') || (*cp == 'I')) && (flags & QPF_IMAG)) + cp++; + if ((*cp == '.') || ((*cp == '/') && (flags & QPF_SLASH)) || + ((*cp >= '0') && (*cp <= '9')) || + ((*cp >= 'a') && (*cp <= 'z')) || + ((*cp >= 'A') && (*cp <= 'Z'))) + return -1; + return (cp - oldcp); + } - /* binary */ - if ((*cp == '0') && ((cp[1] == 'b') || (cp[1] == 'B'))) { - cp += 2; - while ((*cp == '0') || (*cp == '1')) - cp++; - if (((*cp == 'i') || (*cp == 'I')) && (flags & QPF_IMAG)) - cp++; - if ((*cp == '.') || ((*cp == '/') && (flags & QPF_SLASH)) || - ((*cp >= '0') && (*cp <= '9')) || - ((*cp >= 'a') && (*cp <= 'z')) || - ((*cp >= 'A') && (*cp <= 'Z'))) - return -1; - return (cp - oldcp); - } + /* binary */ + if ((*cp == '0') && ((cp[1] == 'b') || (cp[1] == 'B'))) { + cp += 2; + while ((*cp == '0') || (*cp == '1')) + cp++; + if (((*cp == 'i') || (*cp == 'I')) && (flags & QPF_IMAG)) + cp++; + if ((*cp == '.') || ((*cp == '/') && (flags & QPF_SLASH)) || + ((*cp >= '0') && (*cp <= '9')) || + ((*cp >= 'a') && (*cp <= 'z')) || + ((*cp >= 'A') && (*cp <= 'Z'))) + return -1; + return (cp - oldcp); + } - /* octal */ - if ((*cp == '0') && (cp[1] >= '0') && (cp[1] <= '9')) { - while ((*cp >= '0') && (*cp <= '7')) - cp++; - if (((*cp == 'i') || (*cp == 'I')) && (flags & QPF_IMAG)) - cp++; - if ((*cp == '.') || ((*cp == '/') && (flags & QPF_SLASH)) || - ((*cp >= '0') && (*cp <= '9')) || - ((*cp >= 'a') && (*cp <= 'z')) || - ((*cp >= 'A') && (*cp <= 'Z'))) - return -1; - return (cp - oldcp); - } + /* octal */ + if ((*cp == '0') && (cp[1] >= '0') && (cp[1] <= '9')) { + while ((*cp >= '0') && (*cp <= '7')) + cp++; + if (((*cp == 'i') || (*cp == 'I')) && (flags & QPF_IMAG)) + cp++; + if ((*cp == '.') || ((*cp == '/') && (flags & QPF_SLASH)) || + ((*cp >= '0') && (*cp <= '9')) || + ((*cp >= 'a') && (*cp <= 'z')) || + ((*cp >= 'A') && (*cp <= 'Z'))) + return -1; + return (cp - oldcp); + } - /* - * Number is decimal but can still be a fraction or real or exponential - */ - while ((*cp >= '0') && (*cp <= '9')) - cp++; - if (*cp == '/' && flags & QPF_SLASH) { /* fraction */ - cp++; - while ((*cp >= '0') && (*cp <= '9')) - cp++; - if (((*cp == 'i') || (*cp == 'I')) && (flags & QPF_IMAG)) - cp++; - if ((*cp == '.') || ((*cp == '/') && (flags & QPF_SLASH)) || - ((*cp >= '0') && (*cp <= '9')) || - ((*cp >= 'a') && (*cp <= 'z')) || - ((*cp >= 'A') && (*cp <= 'Z'))) - return -1; - return (cp - oldcp); - } - if (*cp == '.') { /* floating point */ - cp++; - while ((*cp >= '0') && (*cp <= '9')) - cp++; - } - if ((*cp == 'e') || (*cp == 'E')) { /* exponential */ - cp++; - if ((*cp == '+') || (*cp == '-')) - cp++; - if ((*cp == '+') || (*cp == '-')) - return -1; - while ((*cp >= '0') && (*cp <= '9')) - cp++; - } + /* + * Number is decimal but can still be a fraction or real or exponential + */ + while ((*cp >= '0') && (*cp <= '9')) + cp++; + if (*cp == '/' && flags & QPF_SLASH) { /* fraction */ + cp++; + while ((*cp >= '0') && (*cp <= '9')) + cp++; + if (((*cp == 'i') || (*cp == 'I')) && (flags & QPF_IMAG)) + cp++; + if ((*cp == '.') || ((*cp == '/') && (flags & QPF_SLASH)) || + ((*cp >= '0') && (*cp <= '9')) || + ((*cp >= 'a') && (*cp <= 'z')) || + ((*cp >= 'A') && (*cp <= 'Z'))) + return -1; + return (cp - oldcp); + } + if (*cp == '.') { /* floating point */ + cp++; + while ((*cp >= '0') && (*cp <= '9')) + cp++; + } + if ((*cp == 'e') || (*cp == 'E')) { /* exponential */ + cp++; + if ((*cp == '+') || (*cp == '-')) + cp++; + if ((*cp == '+') || (*cp == '-')) + return -1; + while ((*cp >= '0') && (*cp <= '9')) + cp++; + } - if (((*cp == 'i') || (*cp == 'I')) && (flags & QPF_IMAG)) - cp++; - if ((*cp == '.') || ((*cp == '/') && (flags & QPF_SLASH)) || - ((*cp >= '0') && (*cp <= '9')) || - ((*cp >= 'a') && (*cp <= 'z')) || - ((*cp >= 'A') && (*cp <= 'Z'))) - return -1; - return (cp - oldcp); + if (((*cp == 'i') || (*cp == 'I')) && (flags & QPF_IMAG)) + cp++; + if ((*cp == '.') || ((*cp == '/') && (flags & QPF_SLASH)) || + ((*cp >= '0') && (*cp <= '9')) || + ((*cp >= 'a') && (*cp <= 'z')) || + ((*cp >= 'A') && (*cp <= 'Z'))) + return -1; + return (cp - oldcp); } @@ -734,59 +734,59 @@ qparse(char *cp, int flags) void fitprint(NUMBER *q, long width) { - long numdigits, dendigits, digits; - long width1, width2; - long n, k; + long numdigits, dendigits, digits; + long width1, width2; + long n, k; - if (width < 8) - width = 8; - numdigits = zdigits(q->num); - n = numdigits; - k = 0; - while (++k, n) - n /= 10; - if (qisint(q)) { - width -= k; - k = 16 - k; - if (k < 2) - k = 2; - PRINTF1("(%ld)", numdigits); - while (k-- > 0) - PUTCHAR(' '); - fitzprint(q->num, numdigits, width); - return; - } - dendigits = zdigits(q->den); - PRINTF2("(%ld/%ld)", numdigits, dendigits); - digits = numdigits + dendigits; - n = dendigits; - while (++k, n) - n /= 10; - width -= k; - k = 16 - k; - if (k < 2) - k = 2; - while (k-- > 0) - PUTCHAR(' '); - if (digits <= width) { - qprintf("%r", q); - return; - } - width1 = (width * numdigits)/digits; - if (width1 < 8) - width1 = 8; - width2 = width - width1; - if (width2 < 8) { - width2 = 8; - width1 = width - width2; - } - fitzprint(q->num, numdigits, width1); - if (conf->fraction_space) { - PUTCHAR(' '); - } - PUTCHAR('/'); - if (conf->fraction_space) { - PUTCHAR(' '); - } - fitzprint(q->den, dendigits, width2); + if (width < 8) + width = 8; + numdigits = zdigits(q->num); + n = numdigits; + k = 0; + while (++k, n) + n /= 10; + if (qisint(q)) { + width -= k; + k = 16 - k; + if (k < 2) + k = 2; + PRINTF1("(%ld)", numdigits); + while (k-- > 0) + PUTCHAR(' '); + fitzprint(q->num, numdigits, width); + return; + } + dendigits = zdigits(q->den); + PRINTF2("(%ld/%ld)", numdigits, dendigits); + digits = numdigits + dendigits; + n = dendigits; + while (++k, n) + n /= 10; + width -= k; + k = 16 - k; + if (k < 2) + k = 2; + while (k-- > 0) + PUTCHAR(' '); + if (digits <= width) { + qprintf("%r", q); + return; + } + width1 = (width * numdigits)/digits; + if (width1 < 8) + width1 = 8; + width2 = width - width1; + if (width2 < 8) { + width2 = 8; + width1 = width - width2; + } + fitzprint(q->num, numdigits, width1); + if (conf->fraction_space) { + PUTCHAR(' '); + } + PUTCHAR('/'); + if (conf->fraction_space) { + PUTCHAR(' '); + } + fitzprint(q->den, dendigits, width2); } diff --git a/qmath.c b/qmath.c index 6ef905a..b240d52 100644 --- a/qmath.c +++ b/qmath.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:21 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:21 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -32,366 +32,366 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -NUMBER _qzero_ = { { _zeroval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL }; -NUMBER _qone_ = { { _oneval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL }; -NUMBER _qtwo_ = { { _twoval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL }; -NUMBER _qten_ = { { _tenval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL }; -NUMBER _qnegone_ = { { _oneval_, 1, 1 }, { _oneval_, 1, 0 }, 1, NULL }; -NUMBER _qonehalf_ = { { _oneval_, 1, 0 }, { _twoval_, 1, 0 }, 1, NULL }; -NUMBER _qneghalf_ = { { _oneval_, 1, 1 }, { _twoval_, 1, 0 }, 1, NULL }; -NUMBER _qonesqbase_ = { { _oneval_, 1, 0 }, { _sqbaseval_, 2, 0 }, 1, NULL }; +NUMBER _qzero_ = { { _zeroval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL }; +NUMBER _qone_ = { { _oneval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL }; +NUMBER _qtwo_ = { { _twoval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL }; +NUMBER _qten_ = { { _tenval_, 1, 0 }, { _oneval_, 1, 0 }, 1, NULL }; +NUMBER _qnegone_ = { { _oneval_, 1, 1 }, { _oneval_, 1, 0 }, 1, NULL }; +NUMBER _qonehalf_ = { { _oneval_, 1, 0 }, { _twoval_, 1, 0 }, 1, NULL }; +NUMBER _qneghalf_ = { { _oneval_, 1, 1 }, { _twoval_, 1, 0 }, 1, NULL }; +NUMBER _qonesqbase_ = { { _oneval_, 1, 0 }, { _sqbaseval_, 2, 0 }, 1, NULL }; NUMBER * initnumbs[] = {&_qzero_, &_qone_, &_qtwo_, - &_qten_, &_qnegone_, &_qonehalf_, &_qneghalf_, - &_qonesqbase_, - NULL /* must be last */ + &_qten_, &_qnegone_, &_qonehalf_, &_qneghalf_, + &_qonesqbase_, + NULL /* must be last */ }; /* * Create another copy of a number. - * q2 = qcopy(q1); + * q2 = qcopy(q1); */ NUMBER * qcopy(NUMBER *q) { - register NUMBER *r; + register NUMBER *r; - r = qalloc(); - r->num.sign = q->num.sign; - if (!zisunit(q->num)) { - r->num.len = q->num.len; - r->num.v = alloc(r->num.len); - zcopyval(q->num, r->num); - } - if (!zisunit(q->den)) { - r->den.len = q->den.len; - r->den.v = alloc(r->den.len); - zcopyval(q->den, r->den); - } - return r; + r = qalloc(); + r->num.sign = q->num.sign; + if (!zisunit(q->num)) { + r->num.len = q->num.len; + r->num.v = alloc(r->num.len); + zcopyval(q->num, r->num); + } + if (!zisunit(q->den)) { + r->den.len = q->den.len; + r->den.v = alloc(r->den.len); + zcopyval(q->den, r->den); + } + return r; } /* * Convert a number to a normal integer. - * i = qtoi(q); + * i = qtoi(q); */ long qtoi(NUMBER *q) { - long i; - ZVALUE res; + long i; + ZVALUE res; - if (qisint(q)) - return ztoi(q->num); - zquo(q->num, q->den, &res, 0); - i = ztoi(res); - zfree(res); - return i; + if (qisint(q)) + return ztoi(q->num); + zquo(q->num, q->den, &res, 0); + i = ztoi(res); + zfree(res); + return i; } /* * Convert a normal integer into a number. - * q = itoq(i); + * q = itoq(i); */ NUMBER * itoq(long i) { - register NUMBER *q; + register NUMBER *q; - if ((i >= -1) && (i <= 10)) { - switch ((int) i) { - case 0: q = &_qzero_; break; - case 1: q = &_qone_; break; - case 2: q = &_qtwo_; break; - case 10: q = &_qten_; break; - case -1: q = &_qnegone_; break; - default: q = NULL; - } - if (q) - return qlink(q); - } - q = qalloc(); - itoz(i, &q->num); - return q; + if ((i >= -1) && (i <= 10)) { + switch ((int) i) { + case 0: q = &_qzero_; break; + case 1: q = &_qone_; break; + case 2: q = &_qtwo_; break; + case 10: q = &_qten_; break; + case -1: q = &_qnegone_; break; + default: q = NULL; + } + if (q) + return qlink(q); + } + q = qalloc(); + itoz(i, &q->num); + return q; } /* * Convert a number to a normal unsigned integer. - * u = qtou(q); + * u = qtou(q); */ FULL qtou(NUMBER *q) { - FULL i; - ZVALUE res; + FULL i; + ZVALUE res; - if (qisint(q)) - return ztou(q->num); - zquo(q->num, q->den, &res, 0); - i = ztou(res); - zfree(res); - return i; + if (qisint(q)) + return ztou(q->num); + zquo(q->num, q->den, &res, 0); + i = ztou(res); + zfree(res); + return i; } /* * Convert a number to a normal signed integer. - * s = qtos(q); + * s = qtos(q); */ SFULL qtos(NUMBER *q) { - SFULL i; - ZVALUE res; + SFULL i; + ZVALUE res; - if (qisint(q)) - return ztos(q->num); - zquo(q->num, q->den, &res, 0); - i = ztos(res); - zfree(res); - return i; + if (qisint(q)) + return ztos(q->num); + zquo(q->num, q->den, &res, 0); + i = ztos(res); + zfree(res); + return i; } /* * Convert a normal unsigned integer into a number. - * q = utoq(i); + * q = utoq(i); */ NUMBER * utoq(FULL i) { - register NUMBER *q; + register NUMBER *q; - if (i <= 10) { - switch ((int) i) { - case 0: q = &_qzero_; break; - case 1: q = &_qone_; break; - case 2: q = &_qtwo_; break; - case 10: q = &_qten_; break; - default: q = NULL; - } - if (q) - return qlink(q); - } - q = qalloc(); - utoz(i, &q->num); - return q; + if (i <= 10) { + switch ((int) i) { + case 0: q = &_qzero_; break; + case 1: q = &_qone_; break; + case 2: q = &_qtwo_; break; + case 10: q = &_qten_; break; + default: q = NULL; + } + if (q) + return qlink(q); + } + q = qalloc(); + utoz(i, &q->num); + return q; } /* * Convert a normal signed integer into a number. - * q = stoq(s); + * q = stoq(s); */ NUMBER * stoq(SFULL i) { - register NUMBER *q; + register NUMBER *q; - if (i <= 10) { - switch ((int) i) { - case 0: q = &_qzero_; break; - case 1: q = &_qone_; break; - case 2: q = &_qtwo_; break; - case 10: q = &_qten_; break; - default: q = NULL; - } - if (q) - return qlink(q); - } - q = qalloc(); - stoz(i, &q->num); - return q; + if (i <= 10) { + switch ((int) i) { + case 0: q = &_qzero_; break; + case 1: q = &_qone_; break; + case 2: q = &_qtwo_; break; + case 10: q = &_qten_; break; + default: q = NULL; + } + if (q) + return qlink(q); + } + q = qalloc(); + stoz(i, &q->num); + return q; } /* * Create a number from the given FULL numerator and denominator. - * q = uutoq(inum, iden); + * q = uutoq(inum, iden); */ NUMBER * uutoq(FULL inum, FULL iden) { - register NUMBER *q; - FULL d; - bool sign; + register NUMBER *q; + FULL d; + bool sign; - if (iden == 0) { - math_error("Division by zero"); - not_reached(); - } - if (inum == 0) - return qlink(&_qzero_); - sign = 0; - d = uugcd(inum, iden); - inum /= d; - iden /= d; - if (iden == 1) - return utoq(inum); - q = qalloc(); - if (inum != 1) - utoz(inum, &q->num); - utoz(iden, &q->den); - q->num.sign = sign; - return q; + if (iden == 0) { + math_error("Division by zero"); + not_reached(); + } + if (inum == 0) + return qlink(&_qzero_); + sign = 0; + d = uugcd(inum, iden); + inum /= d; + iden /= d; + if (iden == 1) + return utoq(inum); + q = qalloc(); + if (inum != 1) + utoz(inum, &q->num); + utoz(iden, &q->den); + q->num.sign = sign; + return q; } /* * Create a number from the given integral numerator and denominator. - * q = iitoq(inum, iden); + * q = iitoq(inum, iden); */ NUMBER * iitoq(long inum, long iden) { - register NUMBER *q; - long d; - bool sign; + register NUMBER *q; + long d; + bool sign; - if (iden == 0) { - math_error("Division by zero"); - not_reached(); - } - if (inum == 0) - return qlink(&_qzero_); - sign = 0; - if (inum < 0) { - sign = 1; - inum = -inum; - } - if (iden < 0) { - sign = 1 - sign; - iden = -iden; - } - d = iigcd(inum, iden); - inum /= d; - iden /= d; - if (iden == 1) - return itoq(sign ? -inum : inum); - q = qalloc(); - if (inum != 1) - itoz(inum, &q->num); - itoz(iden, &q->den); - q->num.sign = sign; - return q; + if (iden == 0) { + math_error("Division by zero"); + not_reached(); + } + if (inum == 0) + return qlink(&_qzero_); + sign = 0; + if (inum < 0) { + sign = 1; + inum = -inum; + } + if (iden < 0) { + sign = 1 - sign; + iden = -iden; + } + d = iigcd(inum, iden); + inum /= d; + iden /= d; + if (iden == 1) + return itoq(sign ? -inum : inum); + q = qalloc(); + if (inum != 1) + itoz(inum, &q->num); + itoz(iden, &q->den); + q->num.sign = sign; + return q; } /* * Add two numbers to each other. - * q3 = qqadd(q1, q2); + * q3 = qqadd(q1, q2); */ NUMBER * qqadd(NUMBER *q1, NUMBER *q2) { - NUMBER *r; - ZVALUE t1, t2, temp, d1, d2, vpd1, upd1; + NUMBER *r; + ZVALUE t1, t2, temp, d1, d2, vpd1, upd1; - if (qiszero(q1)) - return qlink(q2); - if (qiszero(q2)) - return qlink(q1); - r = qalloc(); - /* - * If either number is an integer, then the result is easy. - */ - if (qisint(q1) && qisint(q2)) { - zadd(q1->num, q2->num, &r->num); - return r; - } - if (qisint(q2)) { - zmul(q1->den, q2->num, &temp); - zadd(q1->num, temp, &r->num); - zfree(temp); - zcopy(q1->den, &r->den); - return r; - } - if (qisint(q1)) { - zmul(q2->den, q1->num, &temp); - zadd(q2->num, temp, &r->num); - zfree(temp); - zcopy(q2->den, &r->den); - return r; - } - /* - * Both arguments are true fractions, so we need more work. - * If the denominators are relatively prime, then the answer is the - * straightforward cross product result with no need for reduction. - */ - zgcd(q1->den, q2->den, &d1); - if (zisunit(d1)) { - zfree(d1); - zmul(q1->num, q2->den, &t1); - zmul(q1->den, q2->num, &t2); - zadd(t1, t2, &r->num); - zfree(t1); - zfree(t2); - zmul(q1->den, q2->den, &r->den); - return r; - } - /* - * The calculation is now more complicated. - * See Knuth Vol 2 for details. - */ - zquo(q2->den, d1, &vpd1, 0); - zquo(q1->den, d1, &upd1, 0); - zmul(q1->num, vpd1, &t1); - zmul(q2->num, upd1, &t2); - zadd(t1, t2, &temp); - zfree(t1); - zfree(t2); - zfree(vpd1); - zgcd(temp, d1, &d2); - zfree(d1); - if (zisunit(d2)) { - zfree(d2); - r->num = temp; - zmul(upd1, q2->den, &r->den); - zfree(upd1); - return r; - } - zquo(temp, d2, &r->num, 0); - zfree(temp); - zquo(q2->den, d2, &temp, 0); - zfree(d2); - zmul(temp, upd1, &r->den); - zfree(temp); - zfree(upd1); - return r; + if (qiszero(q1)) + return qlink(q2); + if (qiszero(q2)) + return qlink(q1); + r = qalloc(); + /* + * If either number is an integer, then the result is easy. + */ + if (qisint(q1) && qisint(q2)) { + zadd(q1->num, q2->num, &r->num); + return r; + } + if (qisint(q2)) { + zmul(q1->den, q2->num, &temp); + zadd(q1->num, temp, &r->num); + zfree(temp); + zcopy(q1->den, &r->den); + return r; + } + if (qisint(q1)) { + zmul(q2->den, q1->num, &temp); + zadd(q2->num, temp, &r->num); + zfree(temp); + zcopy(q2->den, &r->den); + return r; + } + /* + * Both arguments are true fractions, so we need more work. + * If the denominators are relatively prime, then the answer is the + * straightforward cross product result with no need for reduction. + */ + zgcd(q1->den, q2->den, &d1); + if (zisunit(d1)) { + zfree(d1); + zmul(q1->num, q2->den, &t1); + zmul(q1->den, q2->num, &t2); + zadd(t1, t2, &r->num); + zfree(t1); + zfree(t2); + zmul(q1->den, q2->den, &r->den); + return r; + } + /* + * The calculation is now more complicated. + * See Knuth Vol 2 for details. + */ + zquo(q2->den, d1, &vpd1, 0); + zquo(q1->den, d1, &upd1, 0); + zmul(q1->num, vpd1, &t1); + zmul(q2->num, upd1, &t2); + zadd(t1, t2, &temp); + zfree(t1); + zfree(t2); + zfree(vpd1); + zgcd(temp, d1, &d2); + zfree(d1); + if (zisunit(d2)) { + zfree(d2); + r->num = temp; + zmul(upd1, q2->den, &r->den); + zfree(upd1); + return r; + } + zquo(temp, d2, &r->num, 0); + zfree(temp); + zquo(q2->den, d2, &temp, 0); + zfree(d2); + zmul(temp, upd1, &r->den); + zfree(temp); + zfree(upd1); + return r; } /* * Subtract one number from another. - * q3 = qsub(q1, q2); + * q3 = qsub(q1, q2); */ NUMBER * qsub(NUMBER *q1, NUMBER *q2) { - NUMBER *r; + NUMBER *r; - if (q1 == q2) - return qlink(&_qzero_); - if (qiszero(q2)) - return qlink(q1); - if (qisint(q1) && qisint(q2)) { - r = qalloc(); - zsub(q1->num, q2->num, &r->num); - return r; - } - q2 = qneg(q2); - if (qiszero(q1)) - return q2; - r = qqadd(q1, q2); - qfree(q2); - return r; + if (q1 == q2) + return qlink(&_qzero_); + if (qiszero(q2)) + return qlink(q1); + if (qisint(q1) && qisint(q2)) { + r = qalloc(); + zsub(q1->num, q2->num, &r->num); + return r; + } + q2 = qneg(q2); + if (qiszero(q1)) + return q2; + r = qqadd(q1, q2); + qfree(q2); + return r; } @@ -401,16 +401,16 @@ qsub(NUMBER *q1, NUMBER *q2) NUMBER * qinc(NUMBER *q) { - NUMBER *r; + NUMBER *r; - r = qalloc(); - if (qisint(q)) { - zadd(q->num, _one_, &r->num); - return r; - } - zadd(q->num, q->den, &r->num); - zcopy(q->den, &r->den); - return r; + r = qalloc(); + if (qisint(q)) { + zadd(q->num, _one_, &r->num); + return r; + } + zadd(q->num, q->den, &r->num); + zcopy(q->den, &r->den); + return r; } @@ -420,16 +420,16 @@ qinc(NUMBER *q) NUMBER * qdec(NUMBER *q) { - NUMBER *r; + NUMBER *r; - r = qalloc(); - if (qisint(q)) { - zsub(q->num, _one_, &r->num); - return r; - } - zsub(q->num, q->den, &r->num); - zcopy(q->den, &r->den); - return r; + r = qalloc(); + if (qisint(q)) { + zsub(q->num, _one_, &r->num); + return r; + } + zsub(q->num, q->den, &r->num); + zcopy(q->den, &r->den); + return r; } @@ -439,194 +439,194 @@ qdec(NUMBER *q) NUMBER * qaddi(NUMBER *q1, long n) { - NUMBER addnum; /* temporary number */ - HALF addval[2]; /* value of small number */ - bool neg; /* true if number is neg */ + NUMBER addnum; /* temporary number */ + HALF addval[2]; /* value of small number */ + bool neg; /* true if number is neg */ #if LONG_BITS > BASEB - FULL nf; + FULL nf; #endif - if (n == 0) - return qlink(q1); - if (n == 1) - return qinc(q1); - if (n == -1) - return qdec(q1); - if (qiszero(q1)) - return itoq(n); - addnum.num.sign = 0; - addnum.num.v = addval; - addnum.den = _one_; - neg = (n < 0); - if (neg) - n = -n; - addval[0] = (HALF) n; + if (n == 0) + return qlink(q1); + if (n == 1) + return qinc(q1); + if (n == -1) + return qdec(q1); + if (qiszero(q1)) + return itoq(n); + addnum.num.sign = 0; + addnum.num.v = addval; + addnum.den = _one_; + neg = (n < 0); + if (neg) + n = -n; + addval[0] = (HALF) n; #if LONG_BITS > BASEB - nf = (((FULL) n) >> BASEB); - if (nf) { - addval[1] = (HALF) nf; - addnum.num.len = 2; - } + nf = (((FULL) n) >> BASEB); + if (nf) { + addval[1] = (HALF) nf; + addnum.num.len = 2; + } #else - addnum.num.len = 1; + addnum.num.len = 1; #endif - if (neg) - return qsub(q1, &addnum); - else - return qqadd(q1, &addnum); + if (neg) + return qsub(q1, &addnum); + else + return qqadd(q1, &addnum); } /* * Multiply two numbers. - * q3 = qmul(q1, q2); + * q3 = qmul(q1, q2); */ NUMBER * qmul(NUMBER *q1, NUMBER *q2) { - NUMBER *r; /* returned value */ - ZVALUE n1, n2, d1, d2; /* numerators and denominators */ - ZVALUE tmp; + NUMBER *r; /* returned value */ + ZVALUE n1, n2, d1, d2; /* numerators and denominators */ + ZVALUE tmp; - if (qiszero(q1) || qiszero(q2)) - return qlink(&_qzero_); - if (qisone(q1)) - return qlink(q2); - if (qisone(q2)) - return qlink(q1); - if (qisint(q1) && qisint(q2)) { /* easy results if integers */ - r = qalloc(); - zmul(q1->num, q2->num, &r->num); - return r; - } - n1 = q1->num; - n2 = q2->num; - d1 = q1->den; - d2 = q2->den; - if (ziszero(d1) || ziszero(d2)) { - math_error("Division by zero"); - not_reached(); - } - if (ziszero(n1) || ziszero(n2)) - return qlink(&_qzero_); - if (!zisunit(n1) && !zisunit(d2)) { /* possibly reduce */ - zgcd(n1, d2, &tmp); - if (!zisunit(tmp)) { - zequo(q1->num, tmp, &n1); - zequo(q2->den, tmp, &d2); - } - zfree(tmp); - } - if (!zisunit(n2) && !zisunit(d1)) { /* again possibly reduce */ - zgcd(n2, d1, &tmp); - if (!zisunit(tmp)) { - zequo(q2->num, tmp, &n2); - zequo(q1->den, tmp, &d1); - } - zfree(tmp); - } - r = qalloc(); - zmul(n1, n2, &r->num); - zmul(d1, d2, &r->den); - if (q1->num.v != n1.v) - zfree(n1); - if (q1->den.v != d1.v) - zfree(d1); - if (q2->num.v != n2.v) - zfree(n2); - if (q2->den.v != d2.v) - zfree(d2); - return r; + if (qiszero(q1) || qiszero(q2)) + return qlink(&_qzero_); + if (qisone(q1)) + return qlink(q2); + if (qisone(q2)) + return qlink(q1); + if (qisint(q1) && qisint(q2)) { /* easy results if integers */ + r = qalloc(); + zmul(q1->num, q2->num, &r->num); + return r; + } + n1 = q1->num; + n2 = q2->num; + d1 = q1->den; + d2 = q2->den; + if (ziszero(d1) || ziszero(d2)) { + math_error("Division by zero"); + not_reached(); + } + if (ziszero(n1) || ziszero(n2)) + return qlink(&_qzero_); + if (!zisunit(n1) && !zisunit(d2)) { /* possibly reduce */ + zgcd(n1, d2, &tmp); + if (!zisunit(tmp)) { + zequo(q1->num, tmp, &n1); + zequo(q2->den, tmp, &d2); + } + zfree(tmp); + } + if (!zisunit(n2) && !zisunit(d1)) { /* again possibly reduce */ + zgcd(n2, d1, &tmp); + if (!zisunit(tmp)) { + zequo(q2->num, tmp, &n2); + zequo(q1->den, tmp, &d1); + } + zfree(tmp); + } + r = qalloc(); + zmul(n1, n2, &r->num); + zmul(d1, d2, &r->den); + if (q1->num.v != n1.v) + zfree(n1); + if (q1->den.v != d1.v) + zfree(d1); + if (q2->num.v != n2.v) + zfree(n2); + if (q2->den.v != d2.v) + zfree(d2); + return r; } /* * Multiply a number by a small integer. - * q2 = qmuli(q1, n); + * q2 = qmuli(q1, n); */ NUMBER * qmuli(NUMBER *q, long n) { - NUMBER *r; - long d; /* gcd of multiplier and denominator */ - int sign; + NUMBER *r; + long d; /* gcd of multiplier and denominator */ + int sign; - if ((n == 0) || qiszero(q)) - return qlink(&_qzero_); - if (n == 1) - return qlink(q); - r = qalloc(); - if (qisint(q)) { - zmuli(q->num, n, &r->num); - return r; - } - sign = 1; - if (n < 0) { - n = -n; - sign = -1; - } - d = zmodi(q->den, n); - d = iigcd(d, n); - zmuli(q->num, (n * sign) / d, &r->num); - (void) zdivi(q->den, d, &r->den); - return r; + if ((n == 0) || qiszero(q)) + return qlink(&_qzero_); + if (n == 1) + return qlink(q); + r = qalloc(); + if (qisint(q)) { + zmuli(q->num, n, &r->num); + return r; + } + sign = 1; + if (n < 0) { + n = -n; + sign = -1; + } + d = zmodi(q->den, n); + d = iigcd(d, n); + zmuli(q->num, (n * sign) / d, &r->num); + (void) zdivi(q->den, d, &r->den); + return r; } /* * Divide two numbers (as fractions). - * q3 = qqdiv(q1, q2); + * q3 = qqdiv(q1, q2); */ NUMBER * qqdiv(NUMBER *q1, NUMBER *q2) { - NUMBER temp; + NUMBER temp; - if (qiszero(q2)) { - math_error("Division by zero"); - not_reached(); - } - if ((q1 == q2) || !qcmp(q1, q2)) - return qlink(&_qone_); - if (qisone(q1)) - return qinv(q2); - temp.num = q2->den; - temp.den = q2->num; - temp.num.sign = temp.den.sign; - temp.den.sign = 0; - temp.links = 1; - return qmul(q1, &temp); + if (qiszero(q2)) { + math_error("Division by zero"); + not_reached(); + } + if ((q1 == q2) || !qcmp(q1, q2)) + return qlink(&_qone_); + if (qisone(q1)) + return qinv(q2); + temp.num = q2->den; + temp.den = q2->num; + temp.num.sign = temp.den.sign; + temp.den.sign = 0; + temp.links = 1; + return qmul(q1, &temp); } /* * Divide a number by a small integer. - * q2 = qdivi(q1, n); + * q2 = qdivi(q1, n); */ NUMBER * qdivi(NUMBER *q, long n) { - NUMBER *r; - long d; /* gcd of divisor and numerator */ - int sign; + NUMBER *r; + long d; /* gcd of divisor and numerator */ + int sign; - if (n == 0) { - math_error("Division by zero"); - not_reached(); - } - if ((n == 1) || qiszero(q)) - return qlink(q); - sign = 1; - if (n < 0) { - n = -n; - sign = -1; - } - r = qalloc(); - d = zmodi(q->num, n); - d = iigcd(d, n); - (void) zdivi(q->num, d * sign, &r->num); - zmuli(q->den, n / d, &r->den); - return r; + if (n == 0) { + math_error("Division by zero"); + not_reached(); + } + if ((n == 1) || qiszero(q)) + return qlink(q); + sign = 1; + if (n < 0) { + n = -n; + sign = -1; + } + r = qalloc(); + d = zmodi(q->num, n); + d = iigcd(d, n); + (void) zdivi(q->num, d * sign, &r->num); + zmuli(q->den, n / d, &r->den); + return r; } @@ -640,69 +640,69 @@ qdivi(NUMBER *q, long n) NUMBER * qquo(NUMBER *q1, NUMBER *q2, long rnd) { - ZVALUE tmp, tmp1, tmp2; - NUMBER *q; + ZVALUE tmp, tmp1, tmp2; + NUMBER *q; - if (qiszero(q1) || qiszero(q2)) - return qlink(&_qzero_); - if (qisint(q1) && qisint(q2)) { - zquo(q1->num, q2->num, &tmp, rnd); - } else { - zmul(q1->num, q2->den, &tmp1); - zmul(q2->num, q1->den, &tmp2); - zquo(tmp1, tmp2, &tmp, rnd); - zfree(tmp1); - zfree(tmp2); - } - if (ziszero(tmp)) { - zfree(tmp); - return qlink(&_qzero_); - } - q = qalloc(); - q->num = tmp; - return q; + if (qiszero(q1) || qiszero(q2)) + return qlink(&_qzero_); + if (qisint(q1) && qisint(q2)) { + zquo(q1->num, q2->num, &tmp, rnd); + } else { + zmul(q1->num, q2->den, &tmp1); + zmul(q2->num, q1->den, &tmp2); + zquo(tmp1, tmp2, &tmp, rnd); + zfree(tmp1); + zfree(tmp2); + } + if (ziszero(tmp)) { + zfree(tmp); + return qlink(&_qzero_); + } + q = qalloc(); + q->num = tmp; + return q; } /* * Return the absolute value of a number. - * q2 = qqabs(q1); + * q2 = qqabs(q1); */ NUMBER * qqabs(NUMBER *q) { - register NUMBER *r; + register NUMBER *r; - if (q->num.sign == 0) - return qlink(q); - r = qalloc(); - if (!zisunit(q->num)) - zcopy(q->num, &r->num); - if (!zisunit(q->den)) - zcopy(q->den, &r->den); - r->num.sign = 0; - return r; + if (q->num.sign == 0) + return qlink(q); + r = qalloc(); + if (!zisunit(q->num)) + zcopy(q->num, &r->num); + if (!zisunit(q->den)) + zcopy(q->den, &r->den); + r->num.sign = 0; + return r; } /* * Negate a number. - * q2 = qneg(q1); + * q2 = qneg(q1); */ NUMBER * qneg(NUMBER *q) { - register NUMBER *r; + register NUMBER *r; - if (qiszero(q)) - return qlink(&_qzero_); - r = qalloc(); - if (!zisunit(q->num)) - zcopy(q->num, &r->num); - if (!zisunit(q->den)) - zcopy(q->den, &r->den); - r->num.sign = !q->num.sign; - return r; + if (qiszero(q)) + return qlink(&_qzero_); + r = qalloc(); + if (!zisunit(q->num)) + zcopy(q->num, &r->num); + if (!zisunit(q->den)) + zcopy(q->den, &r->den); + r->num.sign = !q->num.sign; + return r; } @@ -712,118 +712,118 @@ qneg(NUMBER *q) NUMBER * qsign(NUMBER *q) { - if (qiszero(q)) - return qlink(&_qzero_); - if (qisneg(q)) - return qlink(&_qnegone_); - return qlink(&_qone_); + if (qiszero(q)) + return qlink(&_qzero_); + if (qisneg(q)) + return qlink(&_qnegone_); + return qlink(&_qone_); } /* * Invert a number. - * q2 = qinv(q1); + * q2 = qinv(q1); */ NUMBER * qinv(NUMBER *q) { - register NUMBER *r; + register NUMBER *r; - if (qisunit(q)) { - r = (qisneg(q) ? &_qnegone_ : &_qone_); - return qlink(r); - } - if (qiszero(q)) { - math_error("Division by zero"); - not_reached(); - } - r = qalloc(); - if (!zisunit(q->num)) - zcopy(q->num, &r->den); - if (!zisunit(q->den)) - zcopy(q->den, &r->num); - r->num.sign = q->num.sign; - r->den.sign = 0; - return r; + if (qisunit(q)) { + r = (qisneg(q) ? &_qnegone_ : &_qone_); + return qlink(r); + } + if (qiszero(q)) { + math_error("Division by zero"); + not_reached(); + } + r = qalloc(); + if (!zisunit(q->num)) + zcopy(q->num, &r->den); + if (!zisunit(q->den)) + zcopy(q->den, &r->num); + r->num.sign = q->num.sign; + r->den.sign = 0; + return r; } /* * Return just the numerator of a number. - * q2 = qnum(q1); + * q2 = qnum(q1); */ NUMBER * qnum(NUMBER *q) { - register NUMBER *r; + register NUMBER *r; - if (qisint(q)) - return qlink(q); - if (zisunit(q->num)) { - r = (qisneg(q) ? &_qnegone_ : &_qone_); - return qlink(r); - } - r = qalloc(); - zcopy(q->num, &r->num); - return r; + if (qisint(q)) + return qlink(q); + if (zisunit(q->num)) { + r = (qisneg(q) ? &_qnegone_ : &_qone_); + return qlink(r); + } + r = qalloc(); + zcopy(q->num, &r->num); + return r; } /* * Return just the denominator of a number. - * q2 = qden(q1); + * q2 = qden(q1); */ NUMBER * qden(NUMBER *q) { - register NUMBER *r; + register NUMBER *r; - if (qisint(q)) - return qlink(&_qone_); - r = qalloc(); - zcopy(q->den, &r->num); - return r; + if (qisint(q)) + return qlink(&_qone_); + r = qalloc(); + zcopy(q->den, &r->num); + return r; } /* * Return the fractional part of a number. - * q2 = qfrac(q1); + * q2 = qfrac(q1); */ NUMBER * qfrac(NUMBER *q) { - register NUMBER *r; + register NUMBER *r; - if (qisint(q)) - return qlink(&_qzero_); - if ((q->num.len < q->den.len) || ((q->num.len == q->den.len) && - (q->num.v[q->num.len - 1] < q->den.v[q->num.len - 1]))) - return qlink(q); - r = qalloc(); - zmod(q->num, q->den, &r->num, 2); - zcopy(q->den, &r->den); - return r; + if (qisint(q)) + return qlink(&_qzero_); + if ((q->num.len < q->den.len) || ((q->num.len == q->den.len) && + (q->num.v[q->num.len - 1] < q->den.v[q->num.len - 1]))) + return qlink(q); + r = qalloc(); + zmod(q->num, q->den, &r->num, 2); + zcopy(q->den, &r->den); + return r; } /* * Return the integral part of a number. - * q2 = qint(q1); + * q2 = qint(q1); */ NUMBER * qint(NUMBER *q) { - register NUMBER *r; + register NUMBER *r; - if (qisint(q)) - return qlink(q); - if ((q->num.len < q->den.len) || ((q->num.len == q->den.len) && - (q->num.v[q->num.len - 1] < q->den.v[q->num.len - 1]))) - return qlink(&_qzero_); - r = qalloc(); - zquo(q->num, q->den, &r->num, 2); - return r; + if (qisint(q)) + return qlink(q); + if ((q->num.len < q->den.len) || ((q->num.len == q->den.len) && + (q->num.v[q->num.len - 1] < q->den.v[q->num.len - 1]))) + return qlink(&_qzero_); + r = qalloc(); + zquo(q->num, q->den, &r->num, 2); + return r; } @@ -833,20 +833,20 @@ qint(NUMBER *q) NUMBER * qsquare(NUMBER *q) { - ZVALUE num, zden; + ZVALUE num, zden; - if (qiszero(q)) - return qlink(&_qzero_); - if (qisunit(q)) - return qlink(&_qone_); - num = q->num; - zden = q->den; - q = qalloc(); - if (!zisunit(num)) - zsquare(num, &q->num); - if (!zisunit(zden)) - zsquare(zden, &q->den); - return q; + if (qiszero(q)) + return qlink(&_qzero_); + if (qisunit(q)) + return qlink(&_qone_); + num = q->num; + zden = q->den; + q = qalloc(); + if (!zisunit(num)) + zsquare(num, &q->num); + if (!zisunit(zden)) + zsquare(zden, &q->den); + return q; } @@ -858,61 +858,61 @@ qsquare(NUMBER *q) NUMBER * qshift(NUMBER *q, long n) { - register NUMBER *r; + register NUMBER *r; - if (qisfrac(q)) { - math_error("Shift of non-integer"); - not_reached(); - } - if (qiszero(q) || (n == 0)) - return qlink(q); - if (n <= -(q->num.len * BASEB)) - return qlink(&_qzero_); - r = qalloc(); - zshift(q->num, n, &r->num); - return r; + if (qisfrac(q)) { + math_error("Shift of non-integer"); + not_reached(); + } + if (qiszero(q) || (n == 0)) + return qlink(q); + if (n <= -(q->num.len * BASEB)) + return qlink(&_qzero_); + r = qalloc(); + zshift(q->num, n, &r->num); + return r; } /* * Scale a number by a power of two, as in: - * ans = q * 2^n. + * ans = q * 2^n. * This is similar to shifting, except that fractions work. */ NUMBER * qscale(NUMBER *q, long pow) { - long numshift, denshift, tmp; - NUMBER *r; + long numshift, denshift, tmp; + NUMBER *r; - if (qiszero(q) || (pow == 0)) - return qlink(q); - numshift = zisodd(q->num) ? 0 : zlowbit(q->num); - denshift = zisodd(q->den) ? 0 : zlowbit(q->den); - if (pow > 0) { - tmp = pow; - if (tmp > denshift) - tmp = denshift; - denshift = -tmp; - numshift = (pow - tmp); - } else { - pow = -pow; - tmp = pow; - if (tmp > numshift) - tmp = numshift; - numshift = -tmp; - denshift = (pow - tmp); - } - r = qalloc(); - if (numshift) - zshift(q->num, numshift, &r->num); - else - zcopy(q->num, &r->num); - if (denshift) - zshift(q->den, denshift, &r->den); - else - zcopy(q->den, &r->den); - return r; + if (qiszero(q) || (pow == 0)) + return qlink(q); + numshift = zisodd(q->num) ? 0 : zlowbit(q->num); + denshift = zisodd(q->den) ? 0 : zlowbit(q->den); + if (pow > 0) { + tmp = pow; + if (tmp > denshift) + tmp = denshift; + denshift = -tmp; + numshift = (pow - tmp); + } else { + pow = -pow; + tmp = pow; + if (tmp > numshift) + tmp = numshift; + numshift = -tmp; + denshift = (pow - tmp); + } + r = qalloc(); + if (numshift) + zshift(q->num, numshift, &r->num); + else + zcopy(q->num, &r->num); + if (denshift) + zshift(q->den, denshift, &r->den); + else + zcopy(q->den, &r->den); + return r; } @@ -922,11 +922,11 @@ qscale(NUMBER *q, long pow) NUMBER * qmin(NUMBER *q1, NUMBER *q2) { - if (q1 == q2) - return qlink(q1); - if (qrel(q1, q2) > 0) - q1 = q2; - return qlink(q1); + if (q1 == q2) + return qlink(q1); + if (qrel(q1, q2) > 0) + q1 = q2; + return qlink(q1); } @@ -936,11 +936,11 @@ qmin(NUMBER *q1, NUMBER *q2) NUMBER * qmax(NUMBER *q1, NUMBER *q2) { - if (q1 == q2) - return qlink(q1); - if (qrel(q1, q2) < 0) - q1 = q2; - return qlink(q1); + if (q1 == q2) + return qlink(q1); + if (qrel(q1, q2) < 0) + q1 = q2; + return qlink(q1); } @@ -950,45 +950,45 @@ qmax(NUMBER *q1, NUMBER *q2) NUMBER * qor(NUMBER *q1, NUMBER *q2) { - register NUMBER *r; - NUMBER *q1tmp, *q2tmp, *q; + register NUMBER *r; + NUMBER *q1tmp, *q2tmp, *q; - if (qisfrac(q1) || qisfrac(q2)) { - math_error("Non-integers for bitwise or"); - not_reached(); - } - if (qcmp(q1,q2) == 0 || qiszero(q2)) - return qlink(q1); - if (qiszero(q1)) - return qlink(q2); - if (qisneg(q1)) { - q1tmp = qcomp(q1); - if (qisneg(q2)) { - q2tmp = qcomp(q2); - q = qand(q1tmp,q2tmp); - r = qcomp(q); - qfree(q1tmp); - qfree(q2tmp); - qfree(q); - return r; - } - q = qandnot(q1tmp, q2); - qfree(q1tmp); - r = qcomp(q); - qfree(q); - return r; - } - if (qisneg(q2)) { - q2tmp = qcomp(q2); - q = qandnot(q2tmp, q1); - qfree(q2tmp); - r = qcomp(q); - qfree(q); - return r; - } - r = qalloc(); - zor(q1->num, q2->num, &r->num); - return r; + if (qisfrac(q1) || qisfrac(q2)) { + math_error("Non-integers for bitwise or"); + not_reached(); + } + if (qcmp(q1,q2) == 0 || qiszero(q2)) + return qlink(q1); + if (qiszero(q1)) + return qlink(q2); + if (qisneg(q1)) { + q1tmp = qcomp(q1); + if (qisneg(q2)) { + q2tmp = qcomp(q2); + q = qand(q1tmp,q2tmp); + r = qcomp(q); + qfree(q1tmp); + qfree(q2tmp); + qfree(q); + return r; + } + q = qandnot(q1tmp, q2); + qfree(q1tmp); + r = qcomp(q); + qfree(q); + return r; + } + if (qisneg(q2)) { + q2tmp = qcomp(q2); + q = qandnot(q2tmp, q1); + qfree(q2tmp); + r = qcomp(q); + qfree(q); + return r; + } + r = qalloc(); + zor(q1->num, q2->num, &r->num); + return r; } @@ -998,47 +998,47 @@ qor(NUMBER *q1, NUMBER *q2) NUMBER * qand(NUMBER *q1, NUMBER *q2) { - register NUMBER *r; - NUMBER *q1tmp, *q2tmp, *q; - ZVALUE res; + register NUMBER *r; + NUMBER *q1tmp, *q2tmp, *q; + ZVALUE res; - if (qisfrac(q1) || qisfrac(q2)) { - math_error("Non-integers for bitwise and"); - not_reached(); - } - if (qcmp(q1, q2) == 0) - return qlink(q1); - if (qiszero(q1) || qiszero(q2)) - return qlink(&_qzero_); - if (qisneg(q1)) { - q1tmp = qcomp(q1); - if (qisneg(q2)) { - q2tmp = qcomp(q2); - q = qor(q1tmp, q2tmp); - qfree(q1tmp); - qfree(q2tmp); - r = qcomp(q); - qfree(q); - return r; - } - r = qandnot(q2, q1tmp); - qfree(q1tmp); - return r; - } - if (qisneg(q2)) { - q2tmp = qcomp(q2); - r = qandnot(q1, q2tmp); - qfree(q2tmp); - return r; - } - zand(q1->num, q2->num, &res); - if (ziszero(res)) { - zfree(res); - return qlink(&_qzero_); - } - r = qalloc(); - r->num = res; - return r; + if (qisfrac(q1) || qisfrac(q2)) { + math_error("Non-integers for bitwise and"); + not_reached(); + } + if (qcmp(q1, q2) == 0) + return qlink(q1); + if (qiszero(q1) || qiszero(q2)) + return qlink(&_qzero_); + if (qisneg(q1)) { + q1tmp = qcomp(q1); + if (qisneg(q2)) { + q2tmp = qcomp(q2); + q = qor(q1tmp, q2tmp); + qfree(q1tmp); + qfree(q2tmp); + r = qcomp(q); + qfree(q); + return r; + } + r = qandnot(q2, q1tmp); + qfree(q1tmp); + return r; + } + if (qisneg(q2)) { + q2tmp = qcomp(q2); + r = qandnot(q1, q2tmp); + qfree(q2tmp); + return r; + } + zand(q1->num, q2->num, &res); + if (ziszero(res)) { + zfree(res); + return qlink(&_qzero_); + } + r = qalloc(); + r->num = res; + return r; } @@ -1048,51 +1048,51 @@ qand(NUMBER *q1, NUMBER *q2) NUMBER * qxor(NUMBER *q1, NUMBER *q2) { - register NUMBER *r; - NUMBER *q1tmp, *q2tmp, *q; - ZVALUE res; + register NUMBER *r; + NUMBER *q1tmp, *q2tmp, *q; + ZVALUE res; - if (qisfrac(q1) || qisfrac(q2)) { - math_error("Non-integers for bitwise xor"); - not_reached(); - } - if (qcmp(q1,q2) == 0) - return qlink(&_qzero_); - if (qiszero(q1)) - return qlink(q2); - if (qiszero(q2)) - return qlink(q1); - if (qisneg(q1)) { - q1tmp = qcomp(q1); - if (qisneg(q2)) { - q2tmp = qcomp(q2); - r = qxor(q1tmp, q2tmp); - qfree(q1tmp); - qfree(q2tmp); - return r; - } - q = qxor(q1tmp, q2); - qfree(q1tmp); - r = qcomp(q); - qfree(q); - return r; - } - if (qisneg(q2)) { - q2tmp = qcomp(q2); - q = qxor(q1, q2tmp); - qfree(q2tmp); - r = qcomp(q); - qfree(q); - return r; - } - zxor(q1->num, q2->num, &res); - if (ziszero(res)) { - zfree(res); - return qlink(&_qzero_); - } - r = qalloc(); - r->num = res; - return r; + if (qisfrac(q1) || qisfrac(q2)) { + math_error("Non-integers for bitwise xor"); + not_reached(); + } + if (qcmp(q1,q2) == 0) + return qlink(&_qzero_); + if (qiszero(q1)) + return qlink(q2); + if (qiszero(q2)) + return qlink(q1); + if (qisneg(q1)) { + q1tmp = qcomp(q1); + if (qisneg(q2)) { + q2tmp = qcomp(q2); + r = qxor(q1tmp, q2tmp); + qfree(q1tmp); + qfree(q2tmp); + return r; + } + q = qxor(q1tmp, q2); + qfree(q1tmp); + r = qcomp(q); + qfree(q); + return r; + } + if (qisneg(q2)) { + q2tmp = qcomp(q2); + q = qxor(q1, q2tmp); + qfree(q2tmp); + r = qcomp(q); + qfree(q); + return r; + } + zxor(q1->num, q2->num, &res); + if (ziszero(res)) { + zfree(res); + return qlink(&_qzero_); + } + r = qalloc(); + r->num = res; + return r; } @@ -1102,63 +1102,63 @@ qxor(NUMBER *q1, NUMBER *q2) NUMBER * qandnot(NUMBER *q1, NUMBER *q2) { - register NUMBER *r; - NUMBER *q1tmp, *q2tmp, *q; + register NUMBER *r; + NUMBER *q1tmp, *q2tmp, *q; - if (qisfrac(q1) || qisfrac(q2)) { - math_error("Non-integers for bitwise xor"); - not_reached(); - } - if (qcmp(q1,q2) == 0 || qiszero(q1)) - return qlink(&_qzero_); - if (qiszero(q2)) - return qlink(q1); - if (qisneg(q1)) { - q1tmp = qcomp(q1); - if (qisneg(q2)) { - q2tmp = qcomp(q2); - r = qandnot(q2tmp, q1tmp); - qfree(q1tmp); - qfree(q2tmp); - return r; - } - q = qor(q1tmp, q2); - qfree(q1tmp); - r = qcomp(q); - qfree(q); - return r; - } - if (qisneg(q2)) { - q2tmp = qcomp(q2); - r = qand(q1, q2tmp); - qfree(q2tmp); - return r; - } - r = qalloc(); - zandnot(q1->num, q2->num, &r->num); - return r; + if (qisfrac(q1) || qisfrac(q2)) { + math_error("Non-integers for bitwise xor"); + not_reached(); + } + if (qcmp(q1,q2) == 0 || qiszero(q1)) + return qlink(&_qzero_); + if (qiszero(q2)) + return qlink(q1); + if (qisneg(q1)) { + q1tmp = qcomp(q1); + if (qisneg(q2)) { + q2tmp = qcomp(q2); + r = qandnot(q2tmp, q1tmp); + qfree(q1tmp); + qfree(q2tmp); + return r; + } + q = qor(q1tmp, q2); + qfree(q1tmp); + r = qcomp(q); + qfree(q); + return r; + } + if (qisneg(q2)) { + q2tmp = qcomp(q2); + r = qand(q1, q2tmp); + qfree(q2tmp); + return r; + } + r = qalloc(); + zandnot(q1->num, q2->num, &r->num); + return r; } /* - * Return the bitwise "complement" of a number. This is - q -1 if q is an + * Return the bitwise "complement" of a number. This is - q -1 if q is an * integer, - q otherwise. */ NUMBER * qcomp(NUMBER *q) { - NUMBER *qtmp; - NUMBER *res; + NUMBER *qtmp; + NUMBER *res; - if (qiszero(q)) - return qlink(&_qnegone_); - if (qisnegone(q)) - return qlink(&_qzero_); - qtmp = qneg(q); - if (qisfrac(q)) - return qtmp; - res = qdec(qtmp); - qfree(qtmp); - return res; + if (qiszero(q)) + return qlink(&_qnegone_); + if (qisnegone(q)) + return qlink(&_qzero_); + qtmp = qneg(q); + if (qisfrac(q)) + return qtmp; + res = qdec(qtmp); + qfree(qtmp); + return res; } @@ -1169,16 +1169,16 @@ qcomp(NUMBER *q) NUMBER * qbitvalue(long n) { - register NUMBER *r; + register NUMBER *r; - if (n == 0) - return qlink(&_qone_); - r = qalloc(); - if (n > 0) - zbitvalue(n, &r->num); - else - zbitvalue(-n, &r->den); - return r; + if (n == 0) + return qlink(&_qone_); + r = qalloc(); + if (n > 0) + zbitvalue(n, &r->num); + else + zbitvalue(-n, &r->den); + return r; } /* @@ -1187,16 +1187,16 @@ qbitvalue(long n) NUMBER * qtenpow(long n) { - register NUMBER *r; + register NUMBER *r; - if (n == 0) - return qlink(&_qone_); - r = qalloc(); - if (n > 0) - ztenpow(n, &r->num); - else - ztenpow(-n, &r->den); - return r; + if (n == 0) + return qlink(&_qone_); + r = qalloc(); + if (n > 0) + ztenpow(n, &r->num); + else + ztenpow(-n, &r->den); + return r; } @@ -1210,14 +1210,14 @@ qtenpow(long n) long qprecision(NUMBER *q) { - long r; + long r; - if (qiszero(q) || qisneg(q)) { - math_error("Non-positive number for precision"); - not_reached(); - } - r = - qilog2(q); - return (r < 0 ? 0 : r); + if (qiszero(q) || qisneg(q)) { + math_error("Non-positive number for precision"); + not_reached(); + } + r = - qilog2(q); + return (r < 0 ? 0 : r); } @@ -1228,77 +1228,77 @@ qprecision(NUMBER *q) bool qdivides(NUMBER *q1, NUMBER *q2) { - if (qiszero(q1)) - return true; - if (qisint(q1) && qisint(q2)) { - if (qisunit(q2)) - return true; - return zdivides(q1->num, q2->num); - } - return zdivides(q1->num, q2->num) && zdivides(q2->den, q1->den); + if (qiszero(q1)) + return true; + if (qisint(q1) && qisint(q2)) { + if (qisunit(q2)) + return true; + return zdivides(q1->num, q2->num); + } + return zdivides(q1->num, q2->num) && zdivides(q2->den, q1->den); } /* * Compare two numbers and return an integer indicating their relative size. - * i = qrel(q1, q2); + * i = qrel(q1, q2); */ FLAG qrel(NUMBER *q1, NUMBER *q2) { - ZVALUE z1, z2; - long wc1, wc2; - int sign; - int z1f = 0, z2f = 0; + ZVALUE z1, z2; + long wc1, wc2; + int sign; + int z1f = 0, z2f = 0; - if (q1 == q2) - return 0; - sign = q2->num.sign - q1->num.sign; - if (sign) - return sign; - if (qiszero(q2)) - return !qiszero(q1); - if (qiszero(q1)) - return -1; - /* - * Make a quick comparison by calculating the number of words - * resulting as if we multiplied through by the denominators, - * and then comparing the word counts. - */ - sign = 1; - if (qisneg(q1)) - sign = -1; - wc1 = q1->num.len + q2->den.len; - wc2 = q2->num.len + q1->den.len; - if (wc1 < wc2 - 1) - return -sign; - if (wc2 < wc1 - 1) - return sign; - /* - * Quick check failed, must actually do the full comparison. - */ - if (zisunit(q2->den)) { - z1 = q1->num; - } else if (zisone(q1->num)) { - z1 = q2->den; - } else { - z1f = 1; - zmul(q1->num, q2->den, &z1); - } - if (zisunit(q1->den)) { - z2 = q2->num; - } else if (zisone(q2->num)) { - z2 = q1->den; - } else { - z2f = 1; - zmul(q2->num, q1->den, &z2); - } - sign = zrel(z1, z2); - if (z1f) - zfree(z1); - if (z2f) - zfree(z2); - return sign; + if (q1 == q2) + return 0; + sign = q2->num.sign - q1->num.sign; + if (sign) + return sign; + if (qiszero(q2)) + return !qiszero(q1); + if (qiszero(q1)) + return -1; + /* + * Make a quick comparison by calculating the number of words + * resulting as if we multiplied through by the denominators, + * and then comparing the word counts. + */ + sign = 1; + if (qisneg(q1)) + sign = -1; + wc1 = q1->num.len + q2->den.len; + wc2 = q2->num.len + q1->den.len; + if (wc1 < wc2 - 1) + return -sign; + if (wc2 < wc1 - 1) + return sign; + /* + * Quick check failed, must actually do the full comparison. + */ + if (zisunit(q2->den)) { + z1 = q1->num; + } else if (zisone(q1->num)) { + z1 = q2->den; + } else { + z1f = 1; + zmul(q1->num, q2->den, &z1); + } + if (zisunit(q1->den)) { + z2 = q2->num; + } else if (zisone(q2->num)) { + z2 = q1->den; + } else { + z2f = 1; + zmul(q2->num, q1->den, &z2); + } + sign = zrel(z1, z2); + if (z1f) + zfree(z1); + if (z2f) + zfree(z2); + return sign; } @@ -1310,17 +1310,17 @@ qrel(NUMBER *q1, NUMBER *q2) bool qcmp(NUMBER *q1, NUMBER *q2) { - if (q1 == q2) - return false; - if ((q1->num.sign != q2->num.sign) || (q1->num.len != q2->num.len) || - (q1->den.len != q2->den.len) || (*q1->num.v != *q2->num.v) || - (*q1->den.v != *q2->den.v)) - return true; - if (zcmp(q1->num, q2->num)) - return true; - if (qisint(q1)) - return false; - return zcmp(q1->den, q2->den); + if (q1 == q2) + return false; + if ((q1->num.sign != q2->num.sign) || (q1->num.len != q2->num.len) || + (q1->den.len != q2->den.len) || (*q1->num.v != *q2->num.v) || + (*q1->den.v != *q2->den.v)) + return true; + if (zcmp(q1->num, q2->num)) + return true; + if (qisint(q1)) + return false; + return zcmp(q1->den, q2->den); } @@ -1328,34 +1328,34 @@ qcmp(NUMBER *q1, NUMBER *q2) * Compare a number against a normal small integer. * Returns 1, 0, or -1, according to whether the first number is greater, * equal, or less than the second number. - * res = qreli(q, n); + * res = qreli(q, n); */ FLAG qreli(NUMBER *q, long n) { - ZVALUE z1, z2; - FLAG res; + ZVALUE z1, z2; + FLAG res; - if (qiszero(q)) - return ((n > 0) ? -1 : (n < 0)); + if (qiszero(q)) + return ((n > 0) ? -1 : (n < 0)); - if (n == 0) - return (q->num.sign ? -1 : 0); + if (n == 0) + return (q->num.sign ? -1 : 0); - if (q->num.sign != (n < 0)) - return ((n < 0) ? 1 : -1); + if (q->num.sign != (n < 0)) + return ((n < 0) ? 1 : -1); - itoz(n, &z1); + itoz(n, &z1); - if (qisfrac(q)) { - zmul(q->den, z1, &z2); - zfree(z1); - z1 = z2; - } + if (qisfrac(q)) { + zmul(q->den, z1, &z2); + zfree(z1); + z1 = z2; + } - res = zrel(q->num, z1); - zfree(z1); - return res; + res = zrel(q->num, z1); + zfree(z1); + return res; } @@ -1366,23 +1366,23 @@ qreli(NUMBER *q, long n) bool qcmpi(NUMBER *q, long n) { - long len; + long len; #if LONG_BITS > BASEB - FULL nf; + FULL nf; #endif - len = q->num.len; - if (qisfrac(q) || (q->num.sign != (n < 0))) - return true; - if (n < 0) - n = -n; - if (((HALF)(n)) != q->num.v[0]) - return true; + len = q->num.len; + if (qisfrac(q) || (q->num.sign != (n < 0))) + return true; + if (n < 0) + n = -n; + if (((HALF)(n)) != q->num.v[0]) + return true; #if LONG_BITS > BASEB - nf = ((FULL) n) >> BASEB; - return ((nf != 0 || len > 1) && (len != 2 || nf != q->num.v[1])); + nf = ((FULL) n) >> BASEB; + return ((nf != 0 || len > 1) && (len != 2 || nf != q->num.v[1])); #else - return (len > 1); + return (len > 1); #endif } @@ -1394,110 +1394,110 @@ qcmpi(NUMBER *q, long n) #define NNALLOC 1000 -STATIC NUMBER *freeNum = NULL; -STATIC NUMBER **firstNums = NULL; -STATIC long blockcount = 0; +STATIC NUMBER *freeNum = NULL; +STATIC NUMBER **firstNums = NULL; +STATIC long blockcount = 0; NUMBER * qalloc(void) { - NUMBER *temp; - NUMBER ** newfn; + NUMBER *temp; + NUMBER ** newfn; - if (freeNum == NULL) { - freeNum = (NUMBER *) malloc(sizeof (NUMBER) * NNALLOC); - if (freeNum == NULL) { - math_error("Not enough memory"); - not_reached(); - } - freeNum[NNALLOC - 1].next = NULL; - freeNum[NNALLOC - 1].links = 0; + if (freeNum == NULL) { + freeNum = (NUMBER *) malloc(sizeof (NUMBER) * NNALLOC); + if (freeNum == NULL) { + math_error("Not enough memory"); + not_reached(); + } + freeNum[NNALLOC - 1].next = NULL; + freeNum[NNALLOC - 1].links = 0; - /* - * We prevent the temp pointer from walking behind freeNum - * by stopping one short of the end and running the loop one - * more time. - * - * We would stop the loop with just temp >= freeNum, but - * doing this helps make code checkers such as insure happy. - */ - for (temp = freeNum + NNALLOC - 2; temp > freeNum; --temp) { - temp->next = temp + 1; - temp->links = 0; - } - /* run the loop manually one last time */ - temp->next = temp + 1; - temp->links = 0; + /* + * We prevent the temp pointer from walking behind freeNum + * by stopping one short of the end and running the loop one + * more time. + * + * We would stop the loop with just temp >= freeNum, but + * doing this helps make code checkers such as insure happy. + */ + for (temp = freeNum + NNALLOC - 2; temp > freeNum; --temp) { + temp->next = temp + 1; + temp->links = 0; + } + /* run the loop manually one last time */ + temp->next = temp + 1; + temp->links = 0; - blockcount++; - if (firstNums == NULL) { - newfn = (NUMBER **) malloc(blockcount * sizeof(NUMBER *)); - } else { - newfn = (NUMBER **) - realloc(firstNums, blockcount * sizeof(NUMBER *)); - } - if (newfn == NULL) { - math_error("Cannot allocate new number block"); - not_reached(); - } - firstNums = newfn; - firstNums[blockcount - 1] = freeNum; - } - temp = freeNum; - freeNum = temp->next; - temp->links = 1; - temp->num = _one_; - temp->den = _one_; - return temp; + blockcount++; + if (firstNums == NULL) { + newfn = (NUMBER **) malloc(blockcount * sizeof(NUMBER *)); + } else { + newfn = (NUMBER **) + realloc(firstNums, blockcount * sizeof(NUMBER *)); + } + if (newfn == NULL) { + math_error("Cannot allocate new number block"); + not_reached(); + } + firstNums = newfn; + firstNums[blockcount - 1] = freeNum; + } + temp = freeNum; + freeNum = temp->next; + temp->links = 1; + temp->num = _one_; + temp->den = _one_; + return temp; } void qfreenum(NUMBER *q) { - if (q == NULL) { - math_error("Calling qfreenum with null argument!!!"); - not_reached(); - } - if (q->links != 0) { - math_error("Calling qfreenum with non-zero links!!!"); - not_reached(); - } - zfree(q->num); - zfree(q->den); - q->next = freeNum; - freeNum = q; + if (q == NULL) { + math_error("Calling qfreenum with null argument!!!"); + not_reached(); + } + if (q->links != 0) { + math_error("Calling qfreenum with non-zero links!!!"); + not_reached(); + } + zfree(q->num); + zfree(q->den); + q->next = freeNum; + freeNum = q; } void shownumbers(void) { - NUMBER *vp; - long i, j, k; - long count = 0; + NUMBER *vp; + long i, j, k; + long count = 0; - printf("Index Links Digits Value\n"); - printf("----- ----- ------ -----\n"); + printf("Index Links Digits Value\n"); + printf("----- ----- ------ -----\n"); - for (i = 0, k = 0; initnumbs[i] != NULL; i++) { - count++; - vp = initnumbs[i]; - printf("%6ld %4ld ", k++, vp->links); - fitprint(vp, 40); - printf("\n"); - } + for (i = 0, k = 0; initnumbs[i] != NULL; i++) { + count++; + vp = initnumbs[i]; + printf("%6ld %4ld ", k++, vp->links); + fitprint(vp, 40); + printf("\n"); + } - for (i = 0; i < blockcount; i++) { - vp = firstNums[i]; - for (j = 0; j < NNALLOC; j++, k++, vp++) { - if (vp->links > 0) { - count++; - printf("%6ld %4ld ", k, vp->links); - fitprint(vp, 40); - printf("\n"); - } - } - } - printf("\nNumber: %ld\n", count); + for (i = 0; i < blockcount; i++) { + vp = firstNums[i]; + for (j = 0; j < NNALLOC; j++, k++, vp++) { + if (vp->links > 0) { + count++; + printf("%6ld %4ld ", k, vp->links); + fitprint(vp, 40); + printf("\n"); + } + } + } + printf("\nNumber: %ld\n", count); } diff --git a/qmath.h b/qmath.h index 4aacff3..2cc47b2 100644 --- a/qmath.h +++ b/qmath.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1993/07/30 19:42:47 - * File existed as early as: 1993 + * Under source code control: 1993/07/30 19:42:47 + * File existed as early as: 1993 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,7 +28,7 @@ #define INCLUDE_QMATH_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "zmath.h" #else # include @@ -39,10 +39,10 @@ * Rational arithmetic definitions. */ struct number { - ZVALUE num; /* numerator (containing sign) */ - ZVALUE den; /* denominator (always positive) */ - long links; /* number of links to this value */ - struct number *next; /* pointer to next number */ + ZVALUE num; /* numerator (containing sign) */ + ZVALUE den; /* denominator (always positive) */ + long links; /* number of links to this value */ + struct number *next; /* pointer to next number */ }; typedef struct number NUMBER; @@ -160,7 +160,7 @@ E_FUNC long qilog10(NUMBER *q); E_FUNC NUMBER *qilog(NUMBER *q, ZVALUE base); E_FUNC bool qcmpmod(NUMBER *q1, NUMBER *q2, NUMBER *q3); E_FUNC bool qquomod(NUMBER *q1, NUMBER *q2, NUMBER **quo, NUMBER **mod, - long rnd); + long rnd); E_FUNC FLAG qnear(NUMBER *q1, NUMBER *q2, NUMBER *epsilon); E_FUNC NUMBER *qdigit(NUMBER *q, ZVALUE dpos, ZVALUE base); E_FUNC long qprecision(NUMBER *q); @@ -277,35 +277,35 @@ E_FUNC NUMBER *swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, bool all); /* * macro expansions to speed this thing up */ -#define qiszero(q) (ziszero((q)->num)) -#define qisneg(q) (zisneg((q)->num)) -#define qispos(q) (zispos((q)->num)) -#define qisint(q) (zisunit((q)->den)) -#define qisfrac(q) (!zisunit((q)->den)) -#define qisunit(q) (zisunit((q)->num) && zisunit((q)->den)) -#define qisone(q) (zisone((q)->num) && zisunit((q)->den)) -#define qisnegone(q) (zisnegone((q)->num) && zisunit((q)->den)) -#define qistwo(q) (zistwo((q)->num) && zisunit((q)->den)) -#define qiseven(q) (zisunit((q)->den) && ziseven((q)->num)) -#define qisodd(q) (zisunit((q)->den) && zisodd((q)->num)) -#define qistiny(q) (zistiny((q)->num)) +#define qiszero(q) (ziszero((q)->num)) +#define qisneg(q) (zisneg((q)->num)) +#define qispos(q) (zispos((q)->num)) +#define qisint(q) (zisunit((q)->den)) +#define qisfrac(q) (!zisunit((q)->den)) +#define qisunit(q) (zisunit((q)->num) && zisunit((q)->den)) +#define qisone(q) (zisone((q)->num) && zisunit((q)->den)) +#define qisnegone(q) (zisnegone((q)->num) && zisunit((q)->den)) +#define qistwo(q) (zistwo((q)->num) && zisunit((q)->den)) +#define qiseven(q) (zisunit((q)->den) && ziseven((q)->num)) +#define qisodd(q) (zisunit((q)->den) && zisodd((q)->num)) +#define qistiny(q) (zistiny((q)->num)) -#define qhighbit(q) (zhighbit((q)->num)) -#define qlowbit(q) (zlowbit((q)->num)) -#define qdivcount(q1, q2) (zdivcount((q1)->num, (q2)->num)) -#define qisreciprocal(q) (zisunit((q)->num) && !ziszero((q)->den)) +#define qhighbit(q) (zhighbit((q)->num)) +#define qlowbit(q) (zlowbit((q)->num)) +#define qdivcount(q1, q2) (zdivcount((q1)->num, (q2)->num)) +#define qisreciprocal(q) (zisunit((q)->num) && !ziszero((q)->den)) /* operation on #q may be undefined, so replace with an inline-function */ -/* was: #define qlink(q) ((q)->links++, (q)) */ +/* was: #define qlink(q) ((q)->links++, (q)) */ static inline NUMBER* qlink(NUMBER* q) { if(q) { (q)->links++; } return q; } -#define qfree(q) {if (--((q)->links) <= 0) qfreenum(q);} +#define qfree(q) {if (--((q)->links) <= 0) qfreenum(q);} /* * Flags for qparse calls */ -#define QPF_SLASH 0x1 /* allow slash for fractional number */ -#define QPF_IMAG 0x2 /* allow trailing 'i' for imaginary number */ +#define QPF_SLASH 0x1 /* allow slash for fractional number */ +#define QPF_IMAG 0x2 /* allow trailing 'i' for imaginary number */ /* diff --git a/qmod.c b/qmod.c index 58091f7..8a34260 100644 --- a/qmod.c +++ b/qmod.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1991/05/22 23:15:07 - * File existed as early as: 1991 + * Under source code control: 1991/05/22 23:15:07 + * File existed as early as: 1991 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -32,21 +32,21 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* * Structure used for caching REDC information. */ -typedef struct { - NUMBER *rnum; /* modulus being cached */ - REDC *redc; /* REDC information for modulus */ - long age; /* age counter for reallocation */ +typedef struct { + NUMBER *rnum; /* modulus being cached */ + REDC *redc; /* REDC information for modulus */ + long age; /* age counter for reallocation */ } REDC_CACHE; -STATIC long redc_age; /* current age counter */ -STATIC REDC_CACHE redc_cache[MAXREDC]; /* cached REDC info */ +STATIC long redc_age; /* current age counter */ +STATIC REDC_CACHE redc_cache[MAXREDC]; /* cached REDC info */ S_FUNC REDC *qfindredc(NUMBER *q); @@ -62,40 +62,40 @@ S_FUNC REDC *qfindredc(NUMBER *q); NUMBER * qmod(NUMBER *q1, NUMBER *q2, long rnd) { - ZVALUE tmp, tmp1, tmp2; - NUMBER *q; + ZVALUE tmp, tmp1, tmp2; + NUMBER *q; - if (qiszero(q2)) return qlink(q1); - if (qiszero(q1)) return qlink(&_qzero_); - if (qisint(q1) && qisint(q2)) { /* easy case */ - zmod(q1->num, q2->num, &tmp, rnd); - if (ziszero(tmp)) { - zfree(tmp); - return qlink(&_qzero_); - } - if(zisone(tmp)) { - zfree(tmp); - return qlink(&_qone_); - } - q = qalloc(); - q->num = tmp; - return q; - } - zmul(q1->num, q2->den, &tmp1); - zmul(q2->num, q1->den, &tmp2); - zmod(tmp1, tmp2, &tmp, rnd); - zfree(tmp1); - zfree(tmp2); - if (ziszero(tmp)) { - zfree(tmp); - return qlink(&_qzero_); - } - zmul(q1->den, q2->den, &tmp1); - q = qalloc(); - zreduce(tmp, tmp1, &q->num, &q->den); - zfree(tmp1); - zfree(tmp); - return q; + if (qiszero(q2)) return qlink(q1); + if (qiszero(q1)) return qlink(&_qzero_); + if (qisint(q1) && qisint(q2)) { /* easy case */ + zmod(q1->num, q2->num, &tmp, rnd); + if (ziszero(tmp)) { + zfree(tmp); + return qlink(&_qzero_); + } + if(zisone(tmp)) { + zfree(tmp); + return qlink(&_qone_); + } + q = qalloc(); + q->num = tmp; + return q; + } + zmul(q1->num, q2->den, &tmp1); + zmul(q2->num, q1->den, &tmp2); + zmod(tmp1, tmp2, &tmp, rnd); + zfree(tmp1); + zfree(tmp2); + if (ziszero(tmp)) { + zfree(tmp); + return qlink(&_qzero_); + } + zmul(q1->den, q2->den, &tmp1); + q = qalloc(); + zreduce(tmp, tmp1, &q->num, &q->den); + zfree(tmp1); + zfree(tmp); + return q; } @@ -114,68 +114,68 @@ qmod(NUMBER *q1, NUMBER *q2, long rnd) * nonzero or zero * * Given: - * q1 number to be divided - * q2 divisor - * quo quotient - * mod remainder - * rnd rounding-type specifier + * q1 number to be divided + * q2 divisor + * quo quotient + * mod remainder + * rnd rounding-type specifier */ bool qquomod(NUMBER *q1, NUMBER *q2, NUMBER **quo, NUMBER **mod, long rnd) { - NUMBER *qq, *qm; - ZVALUE tmp1, tmp2, tmp3, tmp4; + NUMBER *qq, *qm; + ZVALUE tmp1, tmp2, tmp3, tmp4; - if (qiszero(q2)) { /* zero divisor case */ - qq = qlink(&_qzero_); - qm = qlink(q1); - } else if (qisint(q1) && qisint(q2)) { /* integer args case */ - zdiv(q1->num, q2->num, &tmp1, &tmp2, rnd); - if (ziszero(tmp1)) { - zfree(tmp1); - zfree(tmp2); - qq = qlink(&_qzero_); - qm = qlink(q1); - } else { - qq = qalloc(); - qq->num = tmp1; - if (ziszero(tmp2)) { - zfree(tmp2); - qm = qlink(&_qzero_); - } else { - qm = qalloc(); - qm->num = tmp2; - } - } - } else { /* fractional case */ - zmul(q1->num, q2->den, &tmp1); - zmul(q2->num, q1->den, &tmp2); - zdiv(tmp1, tmp2, &tmp3, &tmp4, rnd); - zfree(tmp1); - zfree(tmp2); - if (ziszero(tmp3)) { - zfree(tmp3); - zfree(tmp4); - qq = qlink(&_qzero_); - qm = qlink(q1); - } else { - qq = qalloc(); - qq->num = tmp3; - if (ziszero(tmp4)) { - zfree(tmp4); - qm = qlink(&_qzero_); - } else { - qm = qalloc(); - zmul(q1->den, q2->den, &tmp1); - zreduce(tmp4, tmp1, &qm->num, &qm->den); - zfree(tmp1); - zfree(tmp4); - } - } - } - *quo = qq; - *mod = qm; - return !qiszero(qm); + if (qiszero(q2)) { /* zero divisor case */ + qq = qlink(&_qzero_); + qm = qlink(q1); + } else if (qisint(q1) && qisint(q2)) { /* integer args case */ + zdiv(q1->num, q2->num, &tmp1, &tmp2, rnd); + if (ziszero(tmp1)) { + zfree(tmp1); + zfree(tmp2); + qq = qlink(&_qzero_); + qm = qlink(q1); + } else { + qq = qalloc(); + qq->num = tmp1; + if (ziszero(tmp2)) { + zfree(tmp2); + qm = qlink(&_qzero_); + } else { + qm = qalloc(); + qm->num = tmp2; + } + } + } else { /* fractional case */ + zmul(q1->num, q2->den, &tmp1); + zmul(q2->num, q1->den, &tmp2); + zdiv(tmp1, tmp2, &tmp3, &tmp4, rnd); + zfree(tmp1); + zfree(tmp2); + if (ziszero(tmp3)) { + zfree(tmp3); + zfree(tmp4); + qq = qlink(&_qzero_); + qm = qlink(q1); + } else { + qq = qalloc(); + qq->num = tmp3; + if (ziszero(tmp4)) { + zfree(tmp4); + qm = qlink(&_qzero_); + } else { + qm = qalloc(); + zmul(q1->den, q2->den, &tmp1); + zreduce(tmp4, tmp1, &qm->num, &qm->den); + zfree(tmp1); + zfree(tmp4); + } + } + } + *quo = qq; + *mod = qm; + return !qiszero(qm); } @@ -186,13 +186,13 @@ qquomod(NUMBER *q1, NUMBER *q2, NUMBER **quo, NUMBER **mod, long rnd) bool qcmpmod(NUMBER *q1, NUMBER *q2, NUMBER *q3) { - if (qisneg(q3) || qiszero(q3)) - math_error("Non-positive modulus"); - if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3)) - math_error("Non-integers for qcmpmod"); - if (q1 == q2) - return false; - return zcmpmod(q1->num, q2->num, q3->num); + if (qisneg(q3) || qiszero(q3)) + math_error("Non-positive modulus"); + if (qisfrac(q1) || qisfrac(q2) || qisfrac(q3)) + math_error("Non-integers for qcmpmod"); + if (q1 == q2) + return false; + return zcmpmod(q1->num, q2->num, q3->num); } @@ -201,25 +201,25 @@ qcmpmod(NUMBER *q1, NUMBER *q2, NUMBER *q3) * The number can be negative or out of modulus range. * * given: - * q1 number to convert into REDC format - * q2 modulus + * q1 number to convert into REDC format + * q2 modulus */ NUMBER * qredcin(NUMBER *q1, NUMBER *q2) { - REDC *rp; /* REDC information */ - NUMBER *r; /* result */ + REDC *rp; /* REDC information */ + NUMBER *r; /* result */ - if (qisfrac(q1)) - math_error("Non-integer for qredcin"); - rp = qfindredc(q2); - r = qalloc(); - zredcencode(rp, q1->num, &r->num); - if (qiszero(r)) { - qfree(r); - return qlink(&_qzero_); - } - return r; + if (qisfrac(q1)) + math_error("Non-integer for qredcin"); + rp = qfindredc(q2); + r = qalloc(); + zredcencode(rp, q1->num, &r->num); + if (qiszero(r)) { + qfree(r); + return qlink(&_qzero_); + } + return r; } @@ -228,27 +228,27 @@ qredcin(NUMBER *q1, NUMBER *q2) * The resulting number is in the range 0 to the modulus - 1. * * given: - * q1 number to convert into REDC format - * q2 modulus + * q1 number to convert into REDC format + * q2 modulus */ NUMBER * qredcout(NUMBER *q1, NUMBER *q2) { - REDC *rp; /* REDC information */ - NUMBER *r; /* result */ + REDC *rp; /* REDC information */ + NUMBER *r; /* result */ - if (qisfrac(q1)) - math_error("Non-integer argument for rcout"); - rp = qfindredc(q2); - if (qiszero(q1) || qisunit(q2)) - return qlink(&_qzero_); - r = qalloc(); - zredcdecode(rp, q1->num, &r->num); - if (zisunit(r->num)) { - qfree(r); - r = qlink(&_qone_); - } - return r; + if (qisfrac(q1)) + math_error("Non-integer argument for rcout"); + rp = qfindredc(q2); + if (qiszero(q1) || qisunit(q2)) + return qlink(&_qzero_); + r = qalloc(); + zredcdecode(rp, q1->num, &r->num); + if (zisunit(r->num)) { + qfree(r); + r = qlink(&_qone_); + } + return r; } @@ -257,24 +257,24 @@ qredcout(NUMBER *q1, NUMBER *q2) * This multiplication is done modulo the specified modulus. * * given: - * q1 REDC numbers to be multiplied - * q2 REDC numbers to be multiplied - * q3 modulus + * q1 REDC numbers to be multiplied + * q2 REDC numbers to be multiplied + * q3 modulus */ NUMBER * qredcmul(NUMBER *q1, NUMBER *q2, NUMBER *q3) { - REDC *rp; /* REDC information */ - NUMBER *r; /* result */ + REDC *rp; /* REDC information */ + NUMBER *r; /* result */ - if (qisfrac(q1) || qisfrac(q2)) - math_error("Non-integer argument for rcmul"); - rp = qfindredc(q3); - if (qiszero(q1) || qiszero(q2) || qisunit(q3)) - return qlink(&_qzero_); - r = qalloc(); - zredcmul(rp, q1->num, q2->num, &r->num); - return r; + if (qisfrac(q1) || qisfrac(q2)) + math_error("Non-integer argument for rcmul"); + rp = qfindredc(q3); + if (qiszero(q1) || qiszero(q2) || qisunit(q3)) + return qlink(&_qzero_); + r = qalloc(); + zredcmul(rp, q1->num, q2->num, &r->num); + return r; } @@ -283,23 +283,23 @@ qredcmul(NUMBER *q1, NUMBER *q2, NUMBER *q3) * This squaring is done modulo the specified modulus. * * given: - * q1 REDC numbers to be squared - * q2 modulus + * q1 REDC numbers to be squared + * q2 modulus */ NUMBER * qredcsquare(NUMBER *q1, NUMBER *q2) { - REDC *rp; /* REDC information */ - NUMBER *r; /* result */ + REDC *rp; /* REDC information */ + NUMBER *r; /* result */ - if (qisfrac(q1)) - math_error("Non-integer argument for rcsq"); - rp = qfindredc(q2); - if (qiszero(q1) || qisunit(q2)) - return qlink(&_qzero_); - r = qalloc(); - zredcsquare(rp, q1->num, &r->num); - return r; + if (qisfrac(q1)) + math_error("Non-integer argument for rcsq"); + rp = qfindredc(q2); + if (qiszero(q1) || qisunit(q2)) + return qlink(&_qzero_); + r = qalloc(); + zredcsquare(rp, q1->num, &r->num); + return r; } @@ -309,122 +309,122 @@ qredcsquare(NUMBER *q1, NUMBER *q2) * power to be raised to is a normal number. * * given: - * q1 REDC number to be raised - * q2 power to be raised to - * q3 modulus + * q1 REDC number to be raised + * q2 power to be raised to + * q3 modulus */ NUMBER * qredcpower(NUMBER *q1, NUMBER *q2, NUMBER *q3) { - REDC *rp; /* REDC information */ - NUMBER *r; /* result */ + REDC *rp; /* REDC information */ + NUMBER *r; /* result */ - if (qisfrac(q1) || qisfrac(q2) || qisfrac(q2)) - math_error("Non-integer argument for rcpow"); - if (qisneg(q2)) - math_error("Negative exponent argument for rcpow"); - rp = qfindredc(q3); - r = qalloc(); - zredcpower(rp, q1->num, q2->num, &r->num); - return r; + if (qisfrac(q1) || qisfrac(q2) || qisfrac(q2)) + math_error("Non-integer argument for rcpow"); + if (qisneg(q2)) + math_error("Negative exponent argument for rcpow"); + rp = qfindredc(q3); + r = qalloc(); + zredcpower(rp, q1->num, q2->num, &r->num); + return r; } /* * Search for and return the REDC information for the specified number. * The information is cached into a local table so that future calls - * for this information will be quick. If the table fills up, then + * for this information will be quick. If the table fills up, then * the oldest cached entry is reused. * * given: - * q modulus to find REDC information of + * q modulus to find REDC information of */ S_FUNC REDC * qfindredc(NUMBER *q) { - register REDC_CACHE *rcp; - REDC_CACHE *bestrcp; + register REDC_CACHE *rcp; + REDC_CACHE *bestrcp; - /* - * First try for an exact pointer match in the table. - */ - for (rcp = redc_cache; rcp <= &redc_cache[MAXREDC-1]; rcp++) { - if (q == rcp->rnum) { - rcp->age = ++redc_age; - return rcp->redc; - } - } + /* + * First try for an exact pointer match in the table. + */ + for (rcp = redc_cache; rcp <= &redc_cache[MAXREDC-1]; rcp++) { + if (q == rcp->rnum) { + rcp->age = ++redc_age; + return rcp->redc; + } + } - /* - * Search the table again looking for a value which matches. - */ - for (rcp = redc_cache; rcp <= &redc_cache[MAXREDC-1]; rcp++) { - if (rcp->age && (qcmp(q, rcp->rnum) == 0)) { - rcp->age = ++redc_age; - return rcp->redc; - } - } + /* + * Search the table again looking for a value which matches. + */ + for (rcp = redc_cache; rcp <= &redc_cache[MAXREDC-1]; rcp++) { + if (rcp->age && (qcmp(q, rcp->rnum) == 0)) { + rcp->age = ++redc_age; + return rcp->redc; + } + } - /* - * Must invalidate an existing entry in the table. - * Find the oldest (or first unused) entry. - * But first make sure the modulus will be reasonable. - */ - if (qisfrac(q) || qisneg(q)) { - math_error("REDC modulus must be positive odd integer"); - not_reached(); - } + /* + * Must invalidate an existing entry in the table. + * Find the oldest (or first unused) entry. + * But first make sure the modulus will be reasonable. + */ + if (qisfrac(q) || qisneg(q)) { + math_error("REDC modulus must be positive odd integer"); + not_reached(); + } - bestrcp = NULL; - for (rcp = redc_cache; rcp <= &redc_cache[MAXREDC-1]; rcp++) { - if ((bestrcp == NULL) || (rcp->age < bestrcp->age)) - bestrcp = rcp; - } + bestrcp = NULL; + for (rcp = redc_cache; rcp <= &redc_cache[MAXREDC-1]; rcp++) { + if ((bestrcp == NULL) || (rcp->age < bestrcp->age)) + bestrcp = rcp; + } - /* - * Found the best entry. - * Free the old information for the entry if necessary, - * then initialize it. - */ - rcp = bestrcp; - if (rcp->age) { - rcp->age = 0; - qfree(rcp->rnum); - zredcfree(rcp->redc); - } + /* + * Found the best entry. + * Free the old information for the entry if necessary, + * then initialize it. + */ + rcp = bestrcp; + if (rcp->age) { + rcp->age = 0; + qfree(rcp->rnum); + zredcfree(rcp->redc); + } - rcp->redc = zredcalloc(q->num); - rcp->rnum = qlink(q); - rcp->age = ++redc_age; - return rcp->redc; + rcp->redc = zredcalloc(q->num); + rcp->rnum = qlink(q); + rcp->age = ++redc_age; + return rcp->redc; } void showredcdata(void) { - REDC_CACHE *rcp; - long i; + REDC_CACHE *rcp; + long i; - for (i = 0, rcp = redc_cache; i < MAXREDC; i++, rcp++) { - if (rcp->age > 0) { - printf("%-8ld%-8ld", i, rcp->age); - qprintnum(rcp->rnum, 0, conf->outdigits); - printf("\n"); - } - } + for (i = 0, rcp = redc_cache; i < MAXREDC; i++, rcp++) { + if (rcp->age > 0) { + printf("%-8ld%-8ld", i, rcp->age); + qprintnum(rcp->rnum, 0, conf->outdigits); + printf("\n"); + } + } } void freeredcdata(void) { - REDC_CACHE *rcp; - long i; + REDC_CACHE *rcp; + long i; - for (i = 0, rcp = redc_cache; i < MAXREDC; i++, rcp++) { - if (rcp->age > 0) { - rcp->age = 0; - qfree(rcp->rnum); - zredcfree(rcp->redc); - } - } + for (i = 0, rcp = redc_cache; i < MAXREDC; i++, rcp++) { + if (rcp->age > 0) { + rcp->age = 0; + qfree(rcp->rnum); + zredcfree(rcp->redc); + } + } } diff --git a/qtrans.c b/qtrans.c index e136e9b..ce7f619 100644 --- a/qtrans.c +++ b/qtrans.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:22 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:22 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -36,7 +36,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ HALF _qlgenum_[] = { 36744 }; @@ -58,30 +58,30 @@ STATIC NUMBER *ln_n_epsilon = NULL; * * pivalue[LAST_PI_EPSILON] - last epsilon used to calculate pi * pivalue[LAST_PI_VALUE] - last calculated pi - * given pivalue[LAST_PI_EPSILON] epsilon + * given pivalue[LAST_PI_EPSILON] epsilon * pivalue[LAST_PI_DIV_180_EPSILON] - last epsilon used to calculate pi/180 * pivalue[LAST_PI_DIV_180_VALUE] - last calculated pi/180 given - * pivalue[LAST_PI_DIV_180_EPSILON] epsilon + * pivalue[LAST_PI_DIV_180_EPSILON] epsilon * pivalue[LAST_PI_DIV_200_EPSILON] - last epsilon used to calculate pi/200 * pivalue[LAST_PI_DIV_200_VALUE] - last calculated pi/200 given - * pivalue[LAST_PI_DIV_200_EPSILON] epsilon + * pivalue[LAST_PI_DIV_200_EPSILON] epsilon */ enum pi_cache { - LAST_PI_EPSILON = 0, - LAST_PI_VALUE, - LAST_PI_DIV_180_EPSILON, - LAST_PI_DIV_180_VALUE, - LAST_PI_DIV_200_EPSILON, - LAST_PI_DIV_200_VALUE, - PI_CACHE_LEN /* must be last */ + LAST_PI_EPSILON = 0, + LAST_PI_VALUE, + LAST_PI_DIV_180_EPSILON, + LAST_PI_DIV_180_VALUE, + LAST_PI_DIV_200_EPSILON, + LAST_PI_DIV_200_VALUE, + PI_CACHE_LEN /* must be last */ }; STATIC NUMBER *pivalue[PI_CACHE_LEN] = { - NULL, /* LAST_PI_EPSILON */ - NULL, /* LAST_PI_VALUE */ - NULL, /* LAST_PI_DIV_180_EPSILON */ - NULL, /* LAST_PI_DIV_180_VALUE */ - NULL, /* LAST_PI_DIV_200_EPSILON */ - NULL, /* LAST_PI_DIV_200_VALUE */ + NULL, /* LAST_PI_EPSILON */ + NULL, /* LAST_PI_VALUE */ + NULL, /* LAST_PI_DIV_180_EPSILON */ + NULL, /* LAST_PI_DIV_180_VALUE */ + NULL, /* LAST_PI_DIV_200_EPSILON */ + NULL, /* LAST_PI_DIV_200_VALUE */ }; /* @@ -96,111 +96,111 @@ STATIC NUMBER *qexprel(NUMBER *q, long bitnum); void qsincos(NUMBER *q, long bitnum, NUMBER **vs, NUMBER **vc) { - long n, m, k, h, s, t, d; - NUMBER *qtmp1, *qtmp2; - ZVALUE X, cossum, sinsum, mul, ztmp1, ztmp2, ztmp3; + long n, m, k, h, s, t, d; + NUMBER *qtmp1, *qtmp2; + ZVALUE X, cossum, sinsum, mul, ztmp1, ztmp2, ztmp3; - qtmp1 = qqabs(q); - h = qilog2(qtmp1); - qfree(qtmp1); - k = bitnum + h + 1; - if (k < 0) { - *vs = qlink(&_qzero_); - *vc = qlink(&_qone_); - return; - } - s = k; - if (k) { - do { - t = s; - s = (s + k/s)/2; - } - while (t > s); - } /* s is int(sqrt(k)) */ - s++; - if (s < -h) - s = -h; - n = h + s; /* n is number of squaring that will be required */ - m = bitnum + n; - while (s > 0) { /* increasing m by ilog2(s) */ - s >>= 1; - m++; - } /* m is working number of bits */ - qtmp1 = qscale(q, m - n); - zquo(qtmp1->num, qtmp1->den, &X, conf->triground); - qfree(qtmp1); - if (ziszero(X)) { - zfree(X); - *vs = qlink(&_qzero_); - *vc = qlink(&_qone_); - return; - } - zbitvalue(m, &cossum); - zcopy(X, &sinsum); - zcopy(X, &mul); - d = 1; - for (;;) { - X.sign = !X.sign; - zmul(X, mul, &ztmp1); - zfree(X); - zshift(ztmp1, -m, &ztmp2); - zfree(ztmp1); - zdivi(ztmp2, ++d, &X); - zfree(ztmp2); - if (ziszero(X)) - break; - zadd(cossum, X, &ztmp1); - zfree(cossum); - cossum = ztmp1; - zmul(X, mul, &ztmp1); - zfree(X); - zshift(ztmp1, -m, &ztmp2); - zfree(ztmp1); - zdivi(ztmp2, ++d, &X); - zfree(ztmp2); - if (ziszero(X)) - break; - zadd(sinsum, X, &ztmp1); - zfree(sinsum); - sinsum = ztmp1; - } - zfree(X); - zfree(mul); - while (n-- > 0) { - zsquare(cossum, &ztmp1); - zsquare(sinsum, &ztmp2); - zsub(ztmp1, ztmp2, &ztmp3); - zfree(ztmp1); - zfree(ztmp2); - zmul(cossum, sinsum, &ztmp1); - zfree(cossum); - zfree(sinsum); - zshift(ztmp3, -m, &cossum); - zfree(ztmp3); - zshift(ztmp1, 1 - m, &sinsum); - zfree(ztmp1); - } - h = zlowbit(cossum); - qtmp1 = qalloc(); - if (m > h) { - zshift(cossum, -h, &qtmp1->num); - zbitvalue(m - h, &qtmp1->den); - } else { - zshift(cossum, - m, &qtmp1->num); - } - zfree(cossum); - *vc = qtmp1; - h = zlowbit(sinsum); - qtmp2 = qalloc(); - if (m > h) { - zshift(sinsum, -h, &qtmp2->num); - zbitvalue(m - h, &qtmp2->den); - } else { - zshift(sinsum, -m, &qtmp2->num); - } - zfree(sinsum); - *vs = qtmp2; - return; + qtmp1 = qqabs(q); + h = qilog2(qtmp1); + qfree(qtmp1); + k = bitnum + h + 1; + if (k < 0) { + *vs = qlink(&_qzero_); + *vc = qlink(&_qone_); + return; + } + s = k; + if (k) { + do { + t = s; + s = (s + k/s)/2; + } + while (t > s); + } /* s is int(sqrt(k)) */ + s++; + if (s < -h) + s = -h; + n = h + s; /* n is number of squaring that will be required */ + m = bitnum + n; + while (s > 0) { /* increasing m by ilog2(s) */ + s >>= 1; + m++; + } /* m is working number of bits */ + qtmp1 = qscale(q, m - n); + zquo(qtmp1->num, qtmp1->den, &X, conf->triground); + qfree(qtmp1); + if (ziszero(X)) { + zfree(X); + *vs = qlink(&_qzero_); + *vc = qlink(&_qone_); + return; + } + zbitvalue(m, &cossum); + zcopy(X, &sinsum); + zcopy(X, &mul); + d = 1; + for (;;) { + X.sign = !X.sign; + zmul(X, mul, &ztmp1); + zfree(X); + zshift(ztmp1, -m, &ztmp2); + zfree(ztmp1); + zdivi(ztmp2, ++d, &X); + zfree(ztmp2); + if (ziszero(X)) + break; + zadd(cossum, X, &ztmp1); + zfree(cossum); + cossum = ztmp1; + zmul(X, mul, &ztmp1); + zfree(X); + zshift(ztmp1, -m, &ztmp2); + zfree(ztmp1); + zdivi(ztmp2, ++d, &X); + zfree(ztmp2); + if (ziszero(X)) + break; + zadd(sinsum, X, &ztmp1); + zfree(sinsum); + sinsum = ztmp1; + } + zfree(X); + zfree(mul); + while (n-- > 0) { + zsquare(cossum, &ztmp1); + zsquare(sinsum, &ztmp2); + zsub(ztmp1, ztmp2, &ztmp3); + zfree(ztmp1); + zfree(ztmp2); + zmul(cossum, sinsum, &ztmp1); + zfree(cossum); + zfree(sinsum); + zshift(ztmp3, -m, &cossum); + zfree(ztmp3); + zshift(ztmp1, 1 - m, &sinsum); + zfree(ztmp1); + } + h = zlowbit(cossum); + qtmp1 = qalloc(); + if (m > h) { + zshift(cossum, -h, &qtmp1->num); + zbitvalue(m - h, &qtmp1->den); + } else { + zshift(cossum, - m, &qtmp1->num); + } + zfree(cossum); + *vc = qtmp1; + h = zlowbit(sinsum); + qtmp2 = qalloc(); + if (m > h) { + zshift(sinsum, -h, &qtmp2->num); + zbitvalue(m - h, &qtmp2->den); + } else { + zshift(sinsum, -m, &qtmp2->num); + } + zfree(sinsum); + *vs = qtmp2; + return; } @@ -211,23 +211,23 @@ qsincos(NUMBER *q, long bitnum, NUMBER **vs, NUMBER **vc) NUMBER * qcos(NUMBER *q, NUMBER *epsilon) { - NUMBER *sin, *cos, *res; - long n; + NUMBER *sin, *cos, *res; + long n; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for cosine"); - not_reached(); - } - if (qiszero(q)) - return qlink(&_qone_); - n = -qilog2(epsilon); - if (n < 0) - return qlink(&_qzero_); - qsincos(q, n + 2, &sin, &cos); - qfree(sin); - res = qmappr(cos, epsilon, conf->triground); - qfree(cos); - return res; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for cosine"); + not_reached(); + } + if (qiszero(q)) + return qlink(&_qone_); + n = -qilog2(epsilon); + if (n < 0) + return qlink(&_qzero_); + qsincos(q, n + 2, &sin, &cos); + qfree(sin); + res = qmappr(cos, epsilon, conf->triground); + qfree(cos); + return res; } @@ -237,21 +237,21 @@ qcos(NUMBER *q, NUMBER *epsilon) NUMBER * qsin(NUMBER *q, NUMBER *epsilon) { - NUMBER *sin, *cos, *res; - long n; + NUMBER *sin, *cos, *res; + long n; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for sine"); - not_reached(); - } - n = -qilog2(epsilon); - if (qiszero(q) || n < 0) - return qlink(&_qzero_); - qsincos(q, n + 2, &sin, &cos); - qfree(cos); - res = qmappr(sin, epsilon, conf->triground); - qfree(sin); - return res; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for sine"); + not_reached(); + } + n = -qilog2(epsilon); + if (qiszero(q) || n < 0) + return qlink(&_qzero_); + qsincos(q, n + 2, &sin, &cos); + qfree(cos); + res = qmappr(sin, epsilon, conf->triground); + qfree(sin); + return res; } @@ -261,38 +261,38 @@ qsin(NUMBER *q, NUMBER *epsilon) NUMBER * qtan(NUMBER *q, NUMBER *epsilon) { - NUMBER *sin, *cos, *tan, *res; - long n, k, m; + NUMBER *sin, *cos, *tan, *res; + long n, k, m; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for tangent"); - not_reached(); - } - if (qiszero(q)) - return qlink(q); - n = qilog2(epsilon); - k = (n > 0) ? 4 + n/2 : 4; - for (;;) { - qsincos(q, 2 * k - n, &sin, &cos); - if (qiszero(cos)) { - qfree(sin); - qfree(cos); - k = 2 * k - n + 4; - continue; - } - m = -qilog2(cos); - if (m < k) - break; - qfree(sin); - qfree(cos); - k = m + 1; - } - tan = qqdiv(sin, cos); - qfree(sin); - qfree(cos); - res = qmappr(tan, epsilon, conf->triground); - qfree(tan); - return res; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for tangent"); + not_reached(); + } + if (qiszero(q)) + return qlink(q); + n = qilog2(epsilon); + k = (n > 0) ? 4 + n/2 : 4; + for (;;) { + qsincos(q, 2 * k - n, &sin, &cos); + if (qiszero(cos)) { + qfree(sin); + qfree(cos); + k = 2 * k - n + 4; + continue; + } + m = -qilog2(cos); + if (m < k) + break; + qfree(sin); + qfree(cos); + k = m + 1; + } + tan = qqdiv(sin, cos); + qfree(sin); + qfree(cos); + res = qmappr(tan, epsilon, conf->triground); + qfree(tan); + return res; } @@ -302,43 +302,43 @@ qtan(NUMBER *q, NUMBER *epsilon) NUMBER * qcot(NUMBER *q, NUMBER *epsilon) { - NUMBER *sin, *cos, *cot, *res; - long n, k, m; + NUMBER *sin, *cos, *cot, *res; + long n, k, m; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for cotangent"); - not_reached(); - } - if (qiszero(q)) { - math_error("Zero argument for cotangent"); - not_reached(); - } - k = -qilog2(q); - n = qilog2(epsilon); - if (k < 0) - k = (n > 0) ? n/2 : 0; - k += 4; - for (;;) { - qsincos(q, 2 * k - n, &sin, &cos); - if (qiszero(sin)) { - qfree(sin); - qfree(cos); - k = 2 * k - n + 4; - continue; - } - m = -qilog2(sin); - if (m < k) - break; - qfree(sin); - qfree(cos); - k = m + 1; - } - cot = qqdiv(cos, sin); - qfree(sin); - qfree(cos); - res = qmappr(cot, epsilon, conf->triground); - qfree(cot); - return res; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for cotangent"); + not_reached(); + } + if (qiszero(q)) { + math_error("Zero argument for cotangent"); + not_reached(); + } + k = -qilog2(q); + n = qilog2(epsilon); + if (k < 0) + k = (n > 0) ? n/2 : 0; + k += 4; + for (;;) { + qsincos(q, 2 * k - n, &sin, &cos); + if (qiszero(sin)) { + qfree(sin); + qfree(cos); + k = 2 * k - n + 4; + continue; + } + m = -qilog2(sin); + if (m < k) + break; + qfree(sin); + qfree(cos); + k = m + 1; + } + cot = qqdiv(cos, sin); + qfree(sin); + qfree(cos); + res = qmappr(cot, epsilon, conf->triground); + qfree(cot); + return res; } @@ -348,36 +348,36 @@ qcot(NUMBER *q, NUMBER *epsilon) NUMBER * qsec(NUMBER *q, NUMBER *epsilon) { - NUMBER *sin, *cos, *sec, *res; - long n, k, m; + NUMBER *sin, *cos, *sec, *res; + long n, k, m; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for secant"); - not_reached(); - } - if (qiszero(q)) - return qlink(&_qone_); - n = qilog2(epsilon); - k = (n > 0) ? 4 + n/2 : 4; - for (;;) { - qsincos(q, 2 * k - n, &sin, &cos); - qfree(sin); - if (qiszero(cos)) { - qfree(cos); - k = 2 * k - n + 4; - continue; - } - m = -qilog2(cos); - if (m < k) - break; - qfree(cos); - k = m + 1; - } - sec = qinv(cos); - qfree(cos); - res = qmappr(sec, epsilon, conf->triground); - qfree(sec); - return res; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for secant"); + not_reached(); + } + if (qiszero(q)) + return qlink(&_qone_); + n = qilog2(epsilon); + k = (n > 0) ? 4 + n/2 : 4; + for (;;) { + qsincos(q, 2 * k - n, &sin, &cos); + qfree(sin); + if (qiszero(cos)) { + qfree(cos); + k = 2 * k - n + 4; + continue; + } + m = -qilog2(cos); + if (m < k) + break; + qfree(cos); + k = m + 1; + } + sec = qinv(cos); + qfree(cos); + res = qmappr(sec, epsilon, conf->triground); + qfree(sec); + return res; } @@ -387,41 +387,41 @@ qsec(NUMBER *q, NUMBER *epsilon) NUMBER * qcsc(NUMBER *q, NUMBER *epsilon) { - NUMBER *sin, *cos, *csc, *res; - long n, k, m; + NUMBER *sin, *cos, *csc, *res; + long n, k, m; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for cosecant"); - not_reached(); - } - if (qiszero(q)) { - math_error("Zero argument for cosecant"); - not_reached(); - } - k = -qilog2(q); - n = qilog2(epsilon); - if (k < 0) - k = (n > 0) ? n/2 : 0; - k += 4; - for (;;) { - qsincos(q, 2 * k - n, &sin, &cos); - qfree(cos); - if (qiszero(sin)) { - qfree(sin); - k = 2 * k - n + 4; - continue; - } - m = -qilog2(sin); - if (m < k) - break; - qfree(sin); - k = m + 1; - } - csc = qinv(sin); - qfree(sin); - res = qmappr(csc, epsilon, conf->triground); - qfree(csc); - return res; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for cosecant"); + not_reached(); + } + if (qiszero(q)) { + math_error("Zero argument for cosecant"); + not_reached(); + } + k = -qilog2(q); + n = qilog2(epsilon); + if (k < 0) + k = (n > 0) ? n/2 : 0; + k += 4; + for (;;) { + qsincos(q, 2 * k - n, &sin, &cos); + qfree(cos); + if (qiszero(sin)) { + qfree(sin); + k = 2 * k - n + 4; + continue; + } + m = -qilog2(sin); + if (m < k) + break; + qfree(sin); + k = m + 1; + } + csc = qinv(sin); + qfree(sin); + res = qmappr(csc, epsilon, conf->triground); + qfree(csc); + return res; } @@ -432,48 +432,48 @@ qcsc(NUMBER *q, NUMBER *epsilon) NUMBER * qasin(NUMBER *q, NUMBER *epsilon) { - NUMBER *qtmp1, *qtmp2, *epsilon1; - ZVALUE ztmp; - bool neg; - FLAG r; + NUMBER *qtmp1, *qtmp2, *epsilon1; + ZVALUE ztmp; + bool neg; + FLAG r; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for asin"); - not_reached(); - } - if (qiszero(q)) { - return qlink(&_qzero_); - } - ztmp = q->num; - neg = ztmp.sign; - ztmp.sign = 0; - r = zrel(ztmp, q->den); - if (r > 0) { - return NULL; - } - if (r == 0) { - epsilon1 = qscale(epsilon, 1L); - qtmp2 = qpi(epsilon1); - qtmp1 = qscale(qtmp2, -1L); - } else { - epsilon1 = qscale(epsilon, -2L); - qtmp1 = qalloc(); - zsquare(q->num, &qtmp1->num); - zsquare(q->den, &ztmp); - zsub(ztmp, qtmp1->num, &qtmp1->den); - zfree(ztmp); - qtmp2 = qsqrt(qtmp1, epsilon1, conf->triground); - qfree(qtmp1); - qtmp1 = qatan(qtmp2, epsilon); - } - qfree(qtmp2); - qfree(epsilon1); - if (neg) { - qtmp2 = qneg(qtmp1); - qfree(qtmp1); - return(qtmp2); - } - return qtmp1; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for asin"); + not_reached(); + } + if (qiszero(q)) { + return qlink(&_qzero_); + } + ztmp = q->num; + neg = ztmp.sign; + ztmp.sign = 0; + r = zrel(ztmp, q->den); + if (r > 0) { + return NULL; + } + if (r == 0) { + epsilon1 = qscale(epsilon, 1L); + qtmp2 = qpi(epsilon1); + qtmp1 = qscale(qtmp2, -1L); + } else { + epsilon1 = qscale(epsilon, -2L); + qtmp1 = qalloc(); + zsquare(q->num, &qtmp1->num); + zsquare(q->den, &ztmp); + zsub(ztmp, qtmp1->num, &qtmp1->den); + zfree(ztmp); + qtmp2 = qsqrt(qtmp1, epsilon1, conf->triground); + qfree(qtmp1); + qtmp1 = qatan(qtmp2, epsilon); + } + qfree(qtmp2); + qfree(epsilon1); + if (neg) { + qtmp2 = qneg(qtmp1); + qfree(qtmp1); + return(qtmp2); + } + return qtmp1; } @@ -485,133 +485,133 @@ qasin(NUMBER *q, NUMBER *epsilon) NUMBER * qacos(NUMBER *q, NUMBER *epsilon) { - NUMBER *q1, *q2, *epsilon1; - ZVALUE z; + NUMBER *q1, *q2, *epsilon1; + ZVALUE z; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for acos"); - not_reached(); - } - if (qisone(q)) - return qlink(&_qzero_); - if (qisnegone(q)) - return qpi(epsilon); + if (qiszero(epsilon)) { + math_error("Zero epsilon value for acos"); + not_reached(); + } + if (qisone(q)) + return qlink(&_qzero_); + if (qisnegone(q)) + return qpi(epsilon); - z = q->num; - z.sign = 0; - if (zrel(z, q->den) > 0) - return NULL; - epsilon1 = qscale(epsilon, -3L); /* ??? */ - q1 = qalloc(); - zsub(q->den, q->num, &q1->num); - zadd(q->den, q->num, &q1->den); - q2 = qsqrt(q1, epsilon1, conf->triground); - qfree(q1); - qfree(epsilon1); - epsilon1 = qscale(epsilon, -1L); - q1 = qatan(q2, epsilon1); - qfree(epsilon1); - qfree(q2); - q2 = qscale(q1, 1L); - qfree(q1) - return q2; + z = q->num; + z.sign = 0; + if (zrel(z, q->den) > 0) + return NULL; + epsilon1 = qscale(epsilon, -3L); /* ??? */ + q1 = qalloc(); + zsub(q->den, q->num, &q1->num); + zadd(q->den, q->num, &q1->den); + q2 = qsqrt(q1, epsilon1, conf->triground); + qfree(q1); + qfree(epsilon1); + epsilon1 = qscale(epsilon, -1L); + q1 = qatan(q2, epsilon1); + qfree(epsilon1); + qfree(q2); + q2 = qscale(q1, 1L); + qfree(q1) + return q2; } /* * Calculate the arctangent function to the nearest or next to nearest - * multiple of epsilon. Algorithm uses - * atan(x) = 2 * atan(x/(1 + sqrt(1+x^2))) + * multiple of epsilon. Algorithm uses + * atan(x) = 2 * atan(x/(1 + sqrt(1+x^2))) * to reduce x to a small value and then - * atan(x) = x - x^3/3 + ... + * atan(x) = x - x^3/3 + ... */ NUMBER * qatan(NUMBER *q, NUMBER *epsilon) { - long m, k, i; - FULL d; - ZVALUE X, D, DD, sum, mul, term, ztmp1, ztmp2; - NUMBER *qtmp, *res; - bool sign; + long m, k, i; + FULL d; + ZVALUE X, D, DD, sum, mul, term, ztmp1, ztmp2; + NUMBER *qtmp, *res; + bool sign; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for arctangent"); - not_reached(); - } - if (qiszero(q)) - return qlink(&_qzero_); - m = 12 - qilog2(epsilon); - /* 4 bits for 4 doublings; 8 for rounding */ - if (m < 8) - m = 8; /* m is number of working binary digits */ - qtmp = qscale(q, m); - zquo(qtmp->num, qtmp->den, &X, conf->triground); - qfree(qtmp); - zbitvalue(m, &D); /* q has become X/D */ - zsquare(D, &DD); - i = 4; /* maybe this should be larger */ - while (i-- > 0 && !ziszero(X)) { - zsquare(X, &ztmp1); - zadd(ztmp1, DD, &ztmp2); - zfree(ztmp1); - zsqrt(ztmp2, &ztmp1, conf->triground); - zfree(ztmp2); - zadd(ztmp1, D, &ztmp2); - zfree(ztmp1); - zshift(X, m, &ztmp1); - zfree(X); - zquo(ztmp1, ztmp2, &X, conf->triground); - zfree(ztmp1); - zfree(ztmp2); - } - zfree(DD); - zfree(D); - if (ziszero(X)) { - zfree(X); - return qlink(&_qzero_); - } - zcopy(X, &sum); - zsquare(X, &ztmp1); - zshift(ztmp1, -m, &mul); - zfree(ztmp1); - d = 3; - sign = !X.sign; - for (;;) { - if (d > BASE) { - math_error("Too many terms required for atan"); - not_reached(); - } - zmul(X, mul, &ztmp1); - zfree(X); - zshift(ztmp1, -m, &X); /* X now (original X)^d */ - zfree(ztmp1); - zdivi(X, d, &term); - if (ziszero(term)) { - zfree(term); - break; - } - term.sign = sign; - zadd(sum, term, &ztmp1); - zfree(sum); - zfree(term); - sum = ztmp1; - sign = !sign; - d += 2; - } - zfree(mul); - zfree(X); - qtmp = qalloc(); - k = zlowbit(sum); - if (k) { - zshift(sum, -k, &qtmp->num); - zfree(sum); - } else { - qtmp->num = sum; - } - zbitvalue(m - 4 - k, &qtmp->den); - res = qmappr(qtmp, epsilon, conf->triground); - qfree(qtmp); - return res; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for arctangent"); + not_reached(); + } + if (qiszero(q)) + return qlink(&_qzero_); + m = 12 - qilog2(epsilon); + /* 4 bits for 4 doublings; 8 for rounding */ + if (m < 8) + m = 8; /* m is number of working binary digits */ + qtmp = qscale(q, m); + zquo(qtmp->num, qtmp->den, &X, conf->triground); + qfree(qtmp); + zbitvalue(m, &D); /* q has become X/D */ + zsquare(D, &DD); + i = 4; /* maybe this should be larger */ + while (i-- > 0 && !ziszero(X)) { + zsquare(X, &ztmp1); + zadd(ztmp1, DD, &ztmp2); + zfree(ztmp1); + zsqrt(ztmp2, &ztmp1, conf->triground); + zfree(ztmp2); + zadd(ztmp1, D, &ztmp2); + zfree(ztmp1); + zshift(X, m, &ztmp1); + zfree(X); + zquo(ztmp1, ztmp2, &X, conf->triground); + zfree(ztmp1); + zfree(ztmp2); + } + zfree(DD); + zfree(D); + if (ziszero(X)) { + zfree(X); + return qlink(&_qzero_); + } + zcopy(X, &sum); + zsquare(X, &ztmp1); + zshift(ztmp1, -m, &mul); + zfree(ztmp1); + d = 3; + sign = !X.sign; + for (;;) { + if (d > BASE) { + math_error("Too many terms required for atan"); + not_reached(); + } + zmul(X, mul, &ztmp1); + zfree(X); + zshift(ztmp1, -m, &X); /* X now (original X)^d */ + zfree(ztmp1); + zdivi(X, d, &term); + if (ziszero(term)) { + zfree(term); + break; + } + term.sign = sign; + zadd(sum, term, &ztmp1); + zfree(sum); + zfree(term); + sum = ztmp1; + sign = !sign; + d += 2; + } + zfree(mul); + zfree(X); + qtmp = qalloc(); + k = zlowbit(sum); + if (k) { + zshift(sum, -k, &qtmp->num); + zfree(sum); + } else { + qtmp->num = sum; + } + zbitvalue(m - 4 - k, &qtmp->den); + res = qmappr(qtmp, epsilon, conf->triground); + qfree(qtmp); + return res; } /* @@ -620,12 +620,12 @@ qatan(NUMBER *q, NUMBER *epsilon) NUMBER * qasec(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp, *res; + NUMBER *tmp, *res; - tmp = qinv(q); - res = qacos(tmp, epsilon); - qfree(tmp); - return res; + tmp = qinv(q); + res = qacos(tmp, epsilon); + qfree(tmp); + return res; } @@ -635,12 +635,12 @@ qasec(NUMBER *q, NUMBER *epsilon) NUMBER * qacsc(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp, *res; + NUMBER *tmp, *res; - tmp = qinv(q); - res = qasin(tmp, epsilon); - qfree(tmp); - return res; + tmp = qinv(q); + res = qasin(tmp, epsilon); + qfree(tmp); + return res; } @@ -650,37 +650,37 @@ qacsc(NUMBER *q, NUMBER *epsilon) NUMBER * qacot(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp1, *tmp2, *tmp3, *epsilon1; + NUMBER *tmp1, *tmp2, *tmp3, *epsilon1; - if (qiszero(epsilon)) { - math_error("Zero epsilon for acot"); - not_reached(); - } - if (qiszero(q)) { - epsilon1 = qscale(epsilon, 1L); - tmp1 = qpi(epsilon1); - qfree(epsilon1); - tmp2 = qscale(tmp1, -1L); - qfree(tmp1); - return tmp2; - } - tmp1 = qinv(q); - if (!qisneg(q)) { - tmp2 = qatan(tmp1, epsilon); - qfree(tmp1); - return tmp2; - } - epsilon1 = qscale(epsilon, -2L); - tmp2 = qatan(tmp1, epsilon1); - qfree(tmp1); - tmp1 = qpi(epsilon1); - qfree(epsilon1); - tmp3 = qqadd(tmp1, tmp2); - qfree(tmp1); - qfree(tmp2); - tmp1 = qmappr(tmp3, epsilon, conf->triground); - qfree(tmp3); - return tmp1; + if (qiszero(epsilon)) { + math_error("Zero epsilon for acot"); + not_reached(); + } + if (qiszero(q)) { + epsilon1 = qscale(epsilon, 1L); + tmp1 = qpi(epsilon1); + qfree(epsilon1); + tmp2 = qscale(tmp1, -1L); + qfree(tmp1); + return tmp2; + } + tmp1 = qinv(q); + if (!qisneg(q)) { + tmp2 = qatan(tmp1, epsilon); + qfree(tmp1); + return tmp2; + } + epsilon1 = qscale(epsilon, -2L); + tmp2 = qatan(tmp1, epsilon1); + qfree(tmp1); + tmp1 = qpi(epsilon1); + qfree(epsilon1); + tmp3 = qqadd(tmp1, tmp2); + qfree(tmp1); + qfree(tmp2); + tmp1 = qmappr(tmp3, epsilon, conf->triground); + qfree(tmp3); + return tmp1; } @@ -693,55 +693,55 @@ qacot(NUMBER *q, NUMBER *epsilon) NUMBER * qatan2(NUMBER *qy, NUMBER *qx, NUMBER *epsilon) { - NUMBER *tmp1, *tmp2, *tmp3, *epsilon2; + NUMBER *tmp1, *tmp2, *tmp3, *epsilon2; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for atan2"); - not_reached(); - } - if (qiszero(qy) && qiszero(qx)) { - /* conform to 4.3BSD ANSI/IEEE 754-1985 math lib */ - return qlink(&_qzero_); - } - /* - * If the point is on the negative real axis, then the answer is pi. - */ - if (qiszero(qy) && qisneg(qx)) - return qpi(epsilon); - /* - * If the point is in the right half plane, then use the normal atan. - */ - if (!qisneg(qx) && !qiszero(qx)) { - if (qiszero(qy)) - return qlink(&_qzero_); - tmp1 = qqdiv(qy, qx); - tmp2 = qatan(tmp1, epsilon); - qfree(tmp1); - return tmp2; - } - /* - * The point is in the left half plane (x <= 0) with nonzero y. - * Calculate the angle by using the formula: - * atan2(y,x) = 2 * atan(sgn(y) * sqrt((x/y)^2 + 1) - x/y). - */ - epsilon2 = qscale(epsilon, -4L); - tmp1 = qqdiv(qx, qy); - tmp2 = qsquare(tmp1); - tmp3 = qqadd(tmp2, &_qone_); - qfree(tmp2); - tmp2 = qsqrt(tmp3, epsilon2, 24L | (qy->num.sign * 64)); - qfree(tmp3); - tmp3 = qsub(tmp2, tmp1); - qfree(tmp2); - qfree(tmp1); - qfree(epsilon2); - epsilon2 = qscale(epsilon, -1L); - tmp1 = qatan(tmp3, epsilon2); - qfree(epsilon2); - qfree(tmp3); - tmp2 = qscale(tmp1, 1L); - qfree(tmp1); - return tmp2; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for atan2"); + not_reached(); + } + if (qiszero(qy) && qiszero(qx)) { + /* conform to 4.3BSD ANSI/IEEE 754-1985 math lib */ + return qlink(&_qzero_); + } + /* + * If the point is on the negative real axis, then the answer is pi. + */ + if (qiszero(qy) && qisneg(qx)) + return qpi(epsilon); + /* + * If the point is in the right half plane, then use the normal atan. + */ + if (!qisneg(qx) && !qiszero(qx)) { + if (qiszero(qy)) + return qlink(&_qzero_); + tmp1 = qqdiv(qy, qx); + tmp2 = qatan(tmp1, epsilon); + qfree(tmp1); + return tmp2; + } + /* + * The point is in the left half plane (x <= 0) with nonzero y. + * Calculate the angle by using the formula: + * atan2(y,x) = 2 * atan(sgn(y) * sqrt((x/y)^2 + 1) - x/y). + */ + epsilon2 = qscale(epsilon, -4L); + tmp1 = qqdiv(qx, qy); + tmp2 = qsquare(tmp1); + tmp3 = qqadd(tmp2, &_qone_); + qfree(tmp2); + tmp2 = qsqrt(tmp3, epsilon2, 24L | (qy->num.sign * 64)); + qfree(tmp3); + tmp3 = qsub(tmp2, tmp1); + qfree(tmp2); + qfree(tmp1); + qfree(epsilon2); + epsilon2 = qscale(epsilon, -1L); + tmp1 = qatan(tmp3, epsilon2); + qfree(epsilon2); + qfree(tmp3); + tmp2 = qscale(tmp1, 1L); + qfree(tmp1); + return tmp2; } @@ -749,80 +749,80 @@ qatan2(NUMBER *qy, NUMBER *qx, NUMBER *epsilon) * Calculate the value of pi to within the required epsilon. * This uses the following formula which only needs integer calculations * except for the final operation: - * pi = 1 / SUMOF(comb(2 * N, N) ^ 3 * (42 * N + 5) / 2 ^ (12 * N + 4)), + * pi = 1 / SUMOF(comb(2 * N, N) ^ 3 * (42 * N + 5) / 2 ^ (12 * N + 4)), * where the summation runs from N=0. This formula gives about 6 bits of * accuracy per term. Since the denominator for each term is a power of two, * we can simply use shifts to sum the terms. The combinatorial numbers * in the formula are calculated recursively using the formula: - * comb(2*(N+1), N+1) = 2 * comb(2 * N, N) * (2 * N + 1) / N. + * comb(2*(N+1), N+1) = 2 * comb(2 * N, N) * (2 * N + 1) / N. */ NUMBER * qpi(NUMBER *epsilon) { - ZVALUE comb; /* current combinatorial value */ - ZVALUE sum; /* current sum */ - ZVALUE tmp1, tmp2; - NUMBER *r, *t1, qtmp; - long shift; /* current shift of result */ - long N; /* current term number */ - long bits; /* needed number of bits of precision */ - long t; + ZVALUE comb; /* current combinatorial value */ + ZVALUE sum; /* current sum */ + ZVALUE tmp1, tmp2; + NUMBER *r, *t1, qtmp; + long shift; /* current shift of result */ + long N; /* current term number */ + long bits; /* needed number of bits of precision */ + long t; - /* firewall */ - if (qiszero(epsilon)) { - math_error("zero epsilon value for pi"); - not_reached(); - } + /* firewall */ + if (qiszero(epsilon)) { + math_error("zero epsilon value for pi"); + not_reached(); + } - /* use pi cache if epsilon marches, else flush if needed */ - if (pivalue[LAST_PI_EPSILON] != NULL && - pivalue[LAST_PI_VALUE] != NULL && - epsilon == pivalue[LAST_PI_EPSILON]) { - return qlink(pivalue[LAST_PI_VALUE]); - } - if (pivalue[LAST_PI_EPSILON] != NULL) { - qfree(pivalue[LAST_PI_EPSILON]); - } - if (pivalue[LAST_PI_VALUE] != NULL) { - qfree(pivalue[LAST_PI_VALUE]); - } + /* use pi cache if epsilon marches, else flush if needed */ + if (pivalue[LAST_PI_EPSILON] != NULL && + pivalue[LAST_PI_VALUE] != NULL && + epsilon == pivalue[LAST_PI_EPSILON]) { + return qlink(pivalue[LAST_PI_VALUE]); + } + if (pivalue[LAST_PI_EPSILON] != NULL) { + qfree(pivalue[LAST_PI_EPSILON]); + } + if (pivalue[LAST_PI_VALUE] != NULL) { + qfree(pivalue[LAST_PI_VALUE]); + } - bits = -qilog2(epsilon) + 4; - if (bits < 4) - bits = 4; - comb = _one_; - itoz(5L, &sum); - N = 0; - shift = 4; - do { - t = 1 + (++N & 0x1); - (void) zdivi(comb, N / (3 - t), &tmp1); - zfree(comb); - zmuli(tmp1, t * (2 * N - 1), &comb); - zfree(tmp1); - zsquare(comb, &tmp1); - zmul(comb, tmp1, &tmp2); - zfree(tmp1); - zmuli(tmp2, 42 * N + 5, &tmp1); - zfree(tmp2); - zshift(sum, 12L, &tmp2); - zfree(sum); - zadd(tmp1, tmp2, &sum); - t = zhighbit(tmp1); - zfree(tmp1); - zfree(tmp2); - shift += 12; - } while ((shift - t) < bits); - zfree(comb); - qtmp.num = _one_; - qtmp.den = sum; - t1 = qscale(&qtmp, shift); - zfree(sum); - r = qmappr(t1, epsilon, conf->triground); - qfree(t1); - pivalue[LAST_PI_EPSILON] = qlink(epsilon); - pivalue[LAST_PI_VALUE] = qlink(r); - return r; + bits = -qilog2(epsilon) + 4; + if (bits < 4) + bits = 4; + comb = _one_; + itoz(5L, &sum); + N = 0; + shift = 4; + do { + t = 1 + (++N & 0x1); + (void) zdivi(comb, N / (3 - t), &tmp1); + zfree(comb); + zmuli(tmp1, t * (2 * N - 1), &comb); + zfree(tmp1); + zsquare(comb, &tmp1); + zmul(comb, tmp1, &tmp2); + zfree(tmp1); + zmuli(tmp2, 42 * N + 5, &tmp1); + zfree(tmp2); + zshift(sum, 12L, &tmp2); + zfree(sum); + zadd(tmp1, tmp2, &sum); + t = zhighbit(tmp1); + zfree(tmp1); + zfree(tmp2); + shift += 12; + } while ((shift - t) < bits); + zfree(comb); + qtmp.num = _one_; + qtmp.den = sum; + t1 = qscale(&qtmp, shift); + zfree(sum); + r = qmappr(t1, epsilon, conf->triground); + qfree(t1); + pivalue[LAST_PI_EPSILON] = qlink(epsilon); + pivalue[LAST_PI_VALUE] = qlink(r); + return r; } @@ -834,39 +834,39 @@ qpi(NUMBER *epsilon) NUMBER * qpidiv180(NUMBER *epsilon) { - NUMBER *pi, *pidiv180; + NUMBER *pi, *pidiv180; - /* firewall */ - if (qiszero(epsilon)) { - math_error("zero epsilon value for qpidiv180"); - not_reached(); - } + /* firewall */ + if (qiszero(epsilon)) { + math_error("zero epsilon value for qpidiv180"); + not_reached(); + } - /* use pi/180 cache if epsilon marches, else flush if needed */ - if (pivalue[LAST_PI_DIV_180_EPSILON] != NULL && - pivalue[LAST_PI_DIV_180_VALUE] != NULL && - epsilon == pivalue[LAST_PI_DIV_180_EPSILON]) { - return qlink(pivalue[LAST_PI_DIV_180_VALUE]); - } - if (pivalue[LAST_PI_DIV_180_EPSILON] != NULL) { - qfree(pivalue[LAST_PI_DIV_180_EPSILON]); - } - if (pivalue[LAST_PI_DIV_180_VALUE] != NULL) { - qfree(pivalue[LAST_PI_DIV_180_VALUE]); - } + /* use pi/180 cache if epsilon marches, else flush if needed */ + if (pivalue[LAST_PI_DIV_180_EPSILON] != NULL && + pivalue[LAST_PI_DIV_180_VALUE] != NULL && + epsilon == pivalue[LAST_PI_DIV_180_EPSILON]) { + return qlink(pivalue[LAST_PI_DIV_180_VALUE]); + } + if (pivalue[LAST_PI_DIV_180_EPSILON] != NULL) { + qfree(pivalue[LAST_PI_DIV_180_EPSILON]); + } + if (pivalue[LAST_PI_DIV_180_VALUE] != NULL) { + qfree(pivalue[LAST_PI_DIV_180_VALUE]); + } - /* let qpi() returned cached pi or calculate new as needed */ - pi = qpi(epsilon); + /* let qpi() returned cached pi or calculate new as needed */ + pi = qpi(epsilon); - /* calculate pi/180 */ - pidiv180 = qdivi(pi, 180); + /* calculate pi/180 */ + pidiv180 = qdivi(pi, 180); - /* cache epsilon and pi/180 */ - pivalue[LAST_PI_DIV_180_EPSILON] = qlink(epsilon); - pivalue[LAST_PI_DIV_180_VALUE] = qlink(pidiv180); + /* cache epsilon and pi/180 */ + pivalue[LAST_PI_DIV_180_EPSILON] = qlink(epsilon); + pivalue[LAST_PI_DIV_180_VALUE] = qlink(pidiv180); - /* return pi/180 */ - return pidiv180; + /* return pi/180 */ + return pidiv180; } @@ -878,39 +878,39 @@ qpidiv180(NUMBER *epsilon) NUMBER * qpidiv200(NUMBER *epsilon) { - NUMBER *pi, *pidiv200; + NUMBER *pi, *pidiv200; - /* firewall */ - if (qiszero(epsilon)) { - math_error("zero epsilon value for qpidiv200"); - not_reached(); - } + /* firewall */ + if (qiszero(epsilon)) { + math_error("zero epsilon value for qpidiv200"); + not_reached(); + } - /* use pi/200 cache if epsilon marches, else flush if needed */ - if (pivalue[LAST_PI_DIV_200_EPSILON] != NULL && - pivalue[LAST_PI_DIV_200_VALUE] != NULL && - epsilon == pivalue[LAST_PI_DIV_200_EPSILON]) { - return qlink(pivalue[LAST_PI_DIV_200_VALUE]); - } - if (pivalue[LAST_PI_DIV_200_EPSILON] != NULL) { - qfree(pivalue[LAST_PI_DIV_200_EPSILON]); - } - if (pivalue[LAST_PI_DIV_200_VALUE] != NULL) { - qfree(pivalue[LAST_PI_DIV_200_VALUE]); - } + /* use pi/200 cache if epsilon marches, else flush if needed */ + if (pivalue[LAST_PI_DIV_200_EPSILON] != NULL && + pivalue[LAST_PI_DIV_200_VALUE] != NULL && + epsilon == pivalue[LAST_PI_DIV_200_EPSILON]) { + return qlink(pivalue[LAST_PI_DIV_200_VALUE]); + } + if (pivalue[LAST_PI_DIV_200_EPSILON] != NULL) { + qfree(pivalue[LAST_PI_DIV_200_EPSILON]); + } + if (pivalue[LAST_PI_DIV_200_VALUE] != NULL) { + qfree(pivalue[LAST_PI_DIV_200_VALUE]); + } - /* let qpi() returned cached pi or calculate new as needed */ - pi = qpi(epsilon); + /* let qpi() returned cached pi or calculate new as needed */ + pi = qpi(epsilon); - /* calculate pi/200 */ - pidiv200 = qdivi(pi, 200); + /* calculate pi/200 */ + pidiv200 = qdivi(pi, 200); - /* cache epsilon and pi/200 */ - pivalue[LAST_PI_DIV_200_EPSILON] = qlink(epsilon); - pivalue[LAST_PI_DIV_200_VALUE] = qlink(pidiv200); + /* cache epsilon and pi/200 */ + pivalue[LAST_PI_DIV_200_EPSILON] = qlink(epsilon); + pivalue[LAST_PI_DIV_200_VALUE] = qlink(pidiv200); - /* return pi/200 */ - return pidiv200; + /* return pi/200 */ + return pidiv200; } @@ -921,38 +921,38 @@ qpidiv200(NUMBER *epsilon) NUMBER * qexp(NUMBER *q, NUMBER *epsilon) { - long m, n; - NUMBER *tmp1, *tmp2; + long m, n; + NUMBER *tmp1, *tmp2; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for exp"); - not_reached(); - } - if (qiszero(q)) - return qlink(&_qone_); - tmp1 = qmul(q, &_qlge_); - m = qtoi(tmp1); /* exp(q) < 2^(m+1) or m == MAXLONG */ - qfree(tmp1); + if (qiszero(epsilon)) { + math_error("Zero epsilon value for exp"); + not_reached(); + } + if (qiszero(q)) + return qlink(&_qone_); + tmp1 = qmul(q, &_qlge_); + m = qtoi(tmp1); /* exp(q) < 2^(m+1) or m == MAXLONG */ + qfree(tmp1); - if (m > (1 << 30)) - return NULL; + if (m > (1 << 30)) + return NULL; - n = qilog2(epsilon); /* 2^n <= epsilon < 2^(n+1) */ - if (m < n) - return qlink(&_qzero_); - tmp1 = qqabs(q); - tmp2 = qexprel(tmp1, m - n + 1); - qfree(tmp1); - if (tmp2 == NULL) - return NULL; - if (qisneg(q)) { - tmp1 = qinv(tmp2); - qfree(tmp2); - tmp2 = tmp1; - } - tmp1 = qmappr(tmp2, epsilon, conf->triground); - qfree(tmp2); - return tmp1; + n = qilog2(epsilon); /* 2^n <= epsilon < 2^(n+1) */ + if (m < n) + return qlink(&_qzero_); + tmp1 = qqabs(q); + tmp2 = qexprel(tmp1, m - n + 1); + qfree(tmp1); + if (tmp2 == NULL) + return NULL; + if (qisneg(q)) { + tmp1 = qinv(tmp2); + qfree(tmp2); + tmp2 = tmp1; + } + tmp1 = qmappr(tmp2, epsilon, conf->triground); + qfree(tmp2); + return tmp1; } @@ -965,82 +965,82 @@ qexp(NUMBER *q, NUMBER *epsilon) S_FUNC NUMBER * qexprel(NUMBER *q, long bitnum) { - long n, m, k, h, s, t, d; - NUMBER *qtmp1; - ZVALUE X, B, sum, term, ztmp1, ztmp2; + long n, m, k, h, s, t, d; + NUMBER *qtmp1; + ZVALUE X, B, sum, term, ztmp1, ztmp2; - h = qilog2(q); - k = bitnum + h + 1; - if (k < 0) - return qlink(&_qone_); - s = k; - if (k) { - do { - t = s; - s = (s + k/s)/2; - } - while (t > s); - } /* s is int(sqrt(k)) */ - s++; - if (s < -h) - s = -h; - n = h + s; /* n is number of squarings that will be required */ - m = bitnum + n; - if (m > (1 << 30)) - return NULL; - while (s > 0) { /* increasing m by ilog2(s) */ - s >>= 1; - m++; - } /* m is working number of bits */ - qtmp1 = qscale(q, m - n); - zquo(qtmp1->num, qtmp1->den, &X, conf->triground); - qfree(qtmp1); - if (ziszero(X)) { - zfree(X); - return qlink(&_qone_); - } - zbitvalue(m, &sum); - zcopy(X, &term); - d = 1; - do { - zadd(sum, term, &ztmp1); - zfree(sum); - sum = ztmp1; - zmul(term, X, &ztmp1); - zfree(term); - zshift(ztmp1, -m, &ztmp2); - zfree(ztmp1); - zdivi(ztmp2, ++d, &term); - zfree(ztmp2); - } - while (!ziszero(term)); - zfree(term); - zfree(X); - k = 0; - zbitvalue(2 * m + 1, &B); - while (n-- > 0) { - k *= 2; - zsquare(sum, &ztmp1); - zfree(sum); - if (zrel(ztmp1, B) >= 0) { - zshift(ztmp1, -m - 1, &sum); - k++; - } else { - zshift(ztmp1, -m, &sum); - } - zfree(ztmp1); - } - zfree(B); - h = zlowbit(sum); - qtmp1 = qalloc(); - if (m > h + k) { - zshift(sum, -h, &qtmp1->num); - zbitvalue(m - h - k, &qtmp1->den); - } - else - zshift(sum, k - m, &qtmp1->num); - zfree(sum); - return qtmp1; + h = qilog2(q); + k = bitnum + h + 1; + if (k < 0) + return qlink(&_qone_); + s = k; + if (k) { + do { + t = s; + s = (s + k/s)/2; + } + while (t > s); + } /* s is int(sqrt(k)) */ + s++; + if (s < -h) + s = -h; + n = h + s; /* n is number of squarings that will be required */ + m = bitnum + n; + if (m > (1 << 30)) + return NULL; + while (s > 0) { /* increasing m by ilog2(s) */ + s >>= 1; + m++; + } /* m is working number of bits */ + qtmp1 = qscale(q, m - n); + zquo(qtmp1->num, qtmp1->den, &X, conf->triground); + qfree(qtmp1); + if (ziszero(X)) { + zfree(X); + return qlink(&_qone_); + } + zbitvalue(m, &sum); + zcopy(X, &term); + d = 1; + do { + zadd(sum, term, &ztmp1); + zfree(sum); + sum = ztmp1; + zmul(term, X, &ztmp1); + zfree(term); + zshift(ztmp1, -m, &ztmp2); + zfree(ztmp1); + zdivi(ztmp2, ++d, &term); + zfree(ztmp2); + } + while (!ziszero(term)); + zfree(term); + zfree(X); + k = 0; + zbitvalue(2 * m + 1, &B); + while (n-- > 0) { + k *= 2; + zsquare(sum, &ztmp1); + zfree(sum); + if (zrel(ztmp1, B) >= 0) { + zshift(ztmp1, -m - 1, &sum); + k++; + } else { + zshift(ztmp1, -m, &sum); + } + zfree(ztmp1); + } + zfree(B); + h = zlowbit(sum); + qtmp1 = qalloc(); + if (m > h + k) { + zshift(sum, -h, &qtmp1->num); + zbitvalue(m - h - k, &qtmp1->den); + } + else + zshift(sum, k - m, &qtmp1->num); + zfree(sum); + return qtmp1; } @@ -1051,349 +1051,349 @@ qexprel(NUMBER *q, long bitnum) NUMBER * qln(NUMBER *q, NUMBER *epsilon) { - long m, n, k, h, d; - ZVALUE term, sum, mul, pow, X, D, B, ztmp; - NUMBER *qtmp, *res; - bool neg; + long m, n, k, h, d; + ZVALUE term, sum, mul, pow, X, D, B, ztmp; + NUMBER *qtmp, *res; + bool neg; - if (qiszero(q)) { - math_error("ln of 0"); - not_reached(); - } - if (qiszero(epsilon)) { - math_error("Zero epsilon value for ln"); - not_reached(); - } - if (qisunit(q)) - return qlink(&_qzero_); - q = qqabs(q); /* Ignore sign of q */ - neg = (zrel(q->num, q->den) < 0); - if (neg) { - qtmp = qinv(q); - qfree(q); - q = qtmp; - } - k = qilog2(q); - m = -qilog2(epsilon); /* m will be number of working bits */ - if (m < 0) - m = 0; - h = k; - while (h > 0) { - h /= 2; - m++; /* Add 1 for each sqrt until X < 2 */ - } - m += 18; /* 8 more sqrts, 8 for rounding, 2 for epsilon/4 */ - qtmp = qscale(q, m - k); - zquo(qtmp->num, qtmp->den, &X, conf->triground); - qfree(q); - qfree(qtmp); + if (qiszero(q)) { + math_error("ln of 0"); + not_reached(); + } + if (qiszero(epsilon)) { + math_error("Zero epsilon value for ln"); + not_reached(); + } + if (qisunit(q)) + return qlink(&_qzero_); + q = qqabs(q); /* Ignore sign of q */ + neg = (zrel(q->num, q->den) < 0); + if (neg) { + qtmp = qinv(q); + qfree(q); + q = qtmp; + } + k = qilog2(q); + m = -qilog2(epsilon); /* m will be number of working bits */ + if (m < 0) + m = 0; + h = k; + while (h > 0) { + h /= 2; + m++; /* Add 1 for each sqrt until X < 2 */ + } + m += 18; /* 8 more sqrts, 8 for rounding, 2 for epsilon/4 */ + qtmp = qscale(q, m - k); + zquo(qtmp->num, qtmp->den, &X, conf->triground); + qfree(q); + qfree(qtmp); - zbitvalue(m, &D); /* Now "q" = X/D */ - zbitvalue(m - 8, &ztmp); - zadd(D, ztmp, &B); /* Will take sqrts until X <= B */ - zfree(ztmp); + zbitvalue(m, &D); /* Now "q" = X/D */ + zbitvalue(m - 8, &ztmp); + zadd(D, ztmp, &B); /* Will take sqrts until X <= B */ + zfree(ztmp); - n = 1; /* n is to count 1 + number of sqrts */ + n = 1; /* n is to count 1 + number of sqrts */ - while (k > 0 || zrel(X, B) > 0) { - n++; - zshift(X, m + (k & 1), &ztmp); - zfree(X); - zsqrt(ztmp, &X, conf->triground); - zfree(ztmp) - k /= 2; - } - zfree(B); - zsub(X, D, &pow); /* pow, mul used as tmps */ - zadd(X, D, &mul); - zfree(X); - zfree(D); - zshift(pow, m, &ztmp); - zfree(pow); - zquo(ztmp, mul, &pow, conf->triground); /* pow now (X - D)/(X + D) */ - zfree(ztmp); - zfree(mul); + while (k > 0 || zrel(X, B) > 0) { + n++; + zshift(X, m + (k & 1), &ztmp); + zfree(X); + zsqrt(ztmp, &X, conf->triground); + zfree(ztmp) + k /= 2; + } + zfree(B); + zsub(X, D, &pow); /* pow, mul used as tmps */ + zadd(X, D, &mul); + zfree(X); + zfree(D); + zshift(pow, m, &ztmp); + zfree(pow); + zquo(ztmp, mul, &pow, conf->triground); /* pow now (X - D)/(X + D) */ + zfree(ztmp); + zfree(mul); - zcopy(pow, &sum); /* pow is first term of sum */ - zsquare(pow, &ztmp); - zshift(ztmp, -m, &mul); /* mul is now multiplier for powers */ - zfree(ztmp); + zcopy(pow, &sum); /* pow is first term of sum */ + zsquare(pow, &ztmp); + zshift(ztmp, -m, &mul); /* mul is now multiplier for powers */ + zfree(ztmp); - d = 1; - for (;;) { - zmul(pow, mul, &ztmp); - zfree(pow); - zshift(ztmp, -m, &pow); - zfree(ztmp); - d += 2; - zdivi(pow, d, &term); /* Round down div should be round off */ - if (ziszero(term)) { - zfree(term); - break; - } - zadd(sum, term, &ztmp); - zfree(term); - zfree(sum); - sum = ztmp; - } - zfree(pow); - zfree(mul); - qtmp = qalloc(); /* qtmp is to be 2^n * sum / 2^m */ - k = zlowbit(sum); - sum.sign = neg; - if (k + n >= m) { - zshift(sum, n - m, &qtmp->num); - zfree(sum); - } else { - if (k) { - zshift(sum, -k, &qtmp->num); - zfree(sum); - } else { - qtmp->num = sum; - } - zbitvalue(m - k - n, &qtmp->den); - } - res = qmappr(qtmp, epsilon, conf->triground); - qfree(qtmp); - return res; + d = 1; + for (;;) { + zmul(pow, mul, &ztmp); + zfree(pow); + zshift(ztmp, -m, &pow); + zfree(ztmp); + d += 2; + zdivi(pow, d, &term); /* Round down div should be round off */ + if (ziszero(term)) { + zfree(term); + break; + } + zadd(sum, term, &ztmp); + zfree(term); + zfree(sum); + sum = ztmp; + } + zfree(pow); + zfree(mul); + qtmp = qalloc(); /* qtmp is to be 2^n * sum / 2^m */ + k = zlowbit(sum); + sum.sign = neg; + if (k + n >= m) { + zshift(sum, n - m, &qtmp->num); + zfree(sum); + } else { + if (k) { + zshift(sum, -k, &qtmp->num); + zfree(sum); + } else { + qtmp->num = sum; + } + zbitvalue(m - k - n, &qtmp->den); + } + res = qmappr(qtmp, epsilon, conf->triground); + qfree(qtmp); + return res; } /* * Calculate the base 10 logarithm * - * log(q) = ln(q) / ln(10) + * log(q) = ln(q) / ln(10) */ NUMBER * qlog(NUMBER *q, NUMBER *epsilon) { - int need_new_ln_10 = true; /* false => use cached ln_10 value */ - NUMBER *ln_q; /* ln(x) */ - NUMBER *ret; /* base 10 logarithm of x */ + int need_new_ln_10 = true; /* false => use cached ln_10 value */ + NUMBER *ln_q; /* ln(x) */ + NUMBER *ret; /* base 10 logarithm of x */ - /* firewall */ - if (qiszero(q)) { - math_error("log of 0"); - not_reached(); - } - if (qiszero(epsilon)) { - math_error("Zero epsilon value for log"); - not_reached(); - } + /* firewall */ + if (qiszero(q)) { + math_error("log of 0"); + not_reached(); + } + if (qiszero(epsilon)) { + math_error("Zero epsilon value for log"); + not_reached(); + } - /* - * shortcut for small integer powers of 10 - */ - if (qisint(q) && qispos(q) && !zge8192b(q->num) && ziseven(q->num)) { - bool is_10_power; /* true ==> q is a power of 10 */ - long ilog_10; /* integer log base 10 */ + /* + * shortcut for small integer powers of 10 + */ + if (qisint(q) && qispos(q) && !zge8192b(q->num) && ziseven(q->num)) { + bool is_10_power; /* true ==> q is a power of 10 */ + long ilog_10; /* integer log base 10 */ - /* try for a quick small power of 10 log */ - ilog_10 = zlog10(q->num, &is_10_power ); - if (is_10_power == true) { - /* is small power of 10, return log */ - return itoq(ilog_10); - } - /* q is an even integer that is not a power of 10 */ - } + /* try for a quick small power of 10 log */ + ilog_10 = zlog10(q->num, &is_10_power ); + if (is_10_power == true) { + /* is small power of 10, return log */ + return itoq(ilog_10); + } + /* q is an even integer that is not a power of 10 */ + } - /* - * compute ln(c) first - */ - ln_q = qln(q, epsilon); - /* quick return for log(1) == 0 */ - if (qiszero(ln_q)) { - return ln_q; - } + /* + * compute ln(c) first + */ + ln_q = qln(q, epsilon); + /* quick return for log(1) == 0 */ + if (qiszero(ln_q)) { + return ln_q; + } - /* - * save epsilon for ln(10) if needed - */ - if (ln_10_epsilon == NULL) { - /* first time call */ - ln_10_epsilon = qcopy(epsilon); - } else if (qcmp(ln_10_epsilon, epsilon) == true) { - /* replaced cached value with epsilon arg */ - qfree(ln_10_epsilon); - ln_10_epsilon = qcopy(epsilon); - } else if (ln_10 != NULL) { - /* the previously computed ln(2) is OK to use */ - need_new_ln_10 = false; - } + /* + * save epsilon for ln(10) if needed + */ + if (ln_10_epsilon == NULL) { + /* first time call */ + ln_10_epsilon = qcopy(epsilon); + } else if (qcmp(ln_10_epsilon, epsilon) == true) { + /* replaced cached value with epsilon arg */ + qfree(ln_10_epsilon); + ln_10_epsilon = qcopy(epsilon); + } else if (ln_10 != NULL) { + /* the previously computed ln(2) is OK to use */ + need_new_ln_10 = false; + } - /* - * compute ln(10) if needed - */ - if (need_new_ln_10 == true) { - if (ln_10 != NULL) { - qfree(ln_10); - } - ln_10 = qln(&_qten_, ln_10_epsilon); - } + /* + * compute ln(10) if needed + */ + if (need_new_ln_10 == true) { + if (ln_10 != NULL) { + qfree(ln_10); + } + ln_10 = qln(&_qten_, ln_10_epsilon); + } - /* - * return ln(q) / ln(10) - */ - ret = qqdiv(ln_q, ln_10); - qfree(ln_q); - return ret; + /* + * return ln(q) / ln(10) + */ + ret = qqdiv(ln_q, ln_10); + qfree(ln_q); + return ret; } /* * Calculate the base 2 logarithm * - * log(q) = ln(q) / ln(2) + * log(q) = ln(q) / ln(2) */ NUMBER * qlog2(NUMBER *q, NUMBER *epsilon) { - int need_new_ln_2 = true; /* false => use cached ln_2 value */ - NUMBER *ln_q; /* ln(x) */ - NUMBER *ret; /* base 2 logarithm of x */ + int need_new_ln_2 = true; /* false => use cached ln_2 value */ + NUMBER *ln_q; /* ln(x) */ + NUMBER *ret; /* base 2 logarithm of x */ - /* firewall */ - if (qiszero(q)) { - math_error("log2 of 0"); - not_reached(); - } - if (qiszero(epsilon)) { - math_error("Zero epsilon value for log2"); - not_reached(); - } + /* firewall */ + if (qiszero(q)) { + math_error("log2 of 0"); + not_reached(); + } + if (qiszero(epsilon)) { + math_error("Zero epsilon value for log2"); + not_reached(); + } - /* - * special case: q is integer power of 2 - */ - ret = qalloc(); - if (qispowerof2(q, &ret)) { - return ret; - } - qfree(ret); + /* + * special case: q is integer power of 2 + */ + ret = qalloc(); + if (qispowerof2(q, &ret)) { + return ret; + } + qfree(ret); - /* - * compute ln(c) first - */ - ln_q = qln(q, epsilon); - /* quick return for ln(1) == 0 */ - if (qiszero(ln_q)) { - return ln_q; - } + /* + * compute ln(c) first + */ + ln_q = qln(q, epsilon); + /* quick return for ln(1) == 0 */ + if (qiszero(ln_q)) { + return ln_q; + } - /* - * save epsilon for ln(2) if needed - */ - if (ln_2_epsilon == NULL) { - /* first time call */ - ln_2_epsilon = qcopy(epsilon); - } else if (qcmp(ln_2_epsilon, epsilon) == true) { - /* replaced cached value with epsilon arg */ - qfree(ln_2_epsilon); - ln_2_epsilon = qcopy(epsilon); - } else if (ln_2 != NULL) { - /* the previously computed ln(2) is OK to use */ - need_new_ln_2 = false; - } + /* + * save epsilon for ln(2) if needed + */ + if (ln_2_epsilon == NULL) { + /* first time call */ + ln_2_epsilon = qcopy(epsilon); + } else if (qcmp(ln_2_epsilon, epsilon) == true) { + /* replaced cached value with epsilon arg */ + qfree(ln_2_epsilon); + ln_2_epsilon = qcopy(epsilon); + } else if (ln_2 != NULL) { + /* the previously computed ln(2) is OK to use */ + need_new_ln_2 = false; + } - /* - * compute ln(2) if needed - */ - if (need_new_ln_2 == true) { - if (ln_2 != NULL) { - qfree(ln_2); - } - ln_2 = qln(&_qtwo_, ln_2_epsilon); - } + /* + * compute ln(2) if needed + */ + if (need_new_ln_2 == true) { + if (ln_2 != NULL) { + qfree(ln_2); + } + ln_2 = qln(&_qtwo_, ln_2_epsilon); + } - /* - * return ln(q) / ln(2) - */ - ret = qqdiv(ln_q, ln_2); - qfree(ln_q); - return ret; + /* + * return ln(q) / ln(2) + */ + ret = qqdiv(ln_q, ln_2); + qfree(ln_q); + return ret; } /* * Calculate the base n logarithm * - * logn(q, n) = ln(q) / ln(n) + * logn(q, n) = ln(q) / ln(n) */ NUMBER * qlogn(NUMBER *q, NUMBER *n, NUMBER *epsilon) { - int need_new_ln_n = true; /* false => use cached ln_n value */ - NUMBER *ln_q; /* ln(x) */ - NUMBER *ret; /* base 2 logarithm of x */ + int need_new_ln_n = true; /* false => use cached ln_n value */ + NUMBER *ln_q; /* ln(x) */ + NUMBER *ret; /* base 2 logarithm of x */ - /* firewall */ - if (qiszero(q)) { - math_error("log base n of 0"); - not_reached(); - } - if (qiszero(epsilon)) { - math_error("Zero epsilon value for logn"); - not_reached(); - } - if (qiszero(n)) { - math_error("invalid logarithm base of 0 for logn"); - not_reached(); - } - if (qisone(n)) { - math_error("invalid logarithm base of 1 for logn"); - not_reached(); - } + /* firewall */ + if (qiszero(q)) { + math_error("log base n of 0"); + not_reached(); + } + if (qiszero(epsilon)) { + math_error("Zero epsilon value for logn"); + not_reached(); + } + if (qiszero(n)) { + math_error("invalid logarithm base of 0 for logn"); + not_reached(); + } + if (qisone(n)) { + math_error("invalid logarithm base of 1 for logn"); + not_reached(); + } - /* - * special case: q is integer power of 2 - */ - ret = qalloc(); - if (qispowerof2(q, &ret)) { - return ret; - } - /* XXX - deal with n is integer power of 2 - XXX */ - qfree(ret); + /* + * special case: q is integer power of 2 + */ + ret = qalloc(); + if (qispowerof2(q, &ret)) { + return ret; + } + /* XXX - deal with n is integer power of 2 - XXX */ + qfree(ret); - /* - * compute ln(q) first - */ - ln_q = qln(q, epsilon); - /* quick return for ln(1) == 0 */ - if (qiszero(ln_q)) { - return ln_q; - } + /* + * compute ln(q) first + */ + ln_q = qln(q, epsilon); + /* quick return for ln(1) == 0 */ + if (qiszero(ln_q)) { + return ln_q; + } - /* - * save epsilon for ln(n) if needed - */ - if (ln_n_epsilon == NULL) { - /* first time call */ - ln_n_epsilon = qcopy(epsilon); - } else if (qcmp(ln_n_epsilon, epsilon) == true) { - /* replaced cached value with epsilon arg */ - qfree(ln_n_epsilon); - ln_n_epsilon = qcopy(epsilon); - } else if (ln_n != NULL) { - /* the previously computed ln(2) is OK to use */ - need_new_ln_n = false; - } + /* + * save epsilon for ln(n) if needed + */ + if (ln_n_epsilon == NULL) { + /* first time call */ + ln_n_epsilon = qcopy(epsilon); + } else if (qcmp(ln_n_epsilon, epsilon) == true) { + /* replaced cached value with epsilon arg */ + qfree(ln_n_epsilon); + ln_n_epsilon = qcopy(epsilon); + } else if (ln_n != NULL) { + /* the previously computed ln(2) is OK to use */ + need_new_ln_n = false; + } - /* - * compute ln(n) if needed - */ - if (need_new_ln_n == true) { - if (ln_n != NULL) { - qfree(ln_n); - } - ln_n = qln(&_qtwo_, ln_n_epsilon); - } + /* + * compute ln(n) if needed + */ + if (need_new_ln_n == true) { + if (ln_n != NULL) { + qfree(ln_n); + } + ln_n = qln(&_qtwo_, ln_n_epsilon); + } - /* - * return ln(q) / ln(2) - */ - ret = qqdiv(ln_q, ln_n); - qfree(ln_q); - return ret; + /* + * return ln(q) / ln(2) + */ + ret = qqdiv(ln_q, ln_n); + qfree(ln_q); + return ret; } @@ -1405,115 +1405,115 @@ qlogn(NUMBER *q, NUMBER *n, NUMBER *epsilon) NUMBER * qpower(NUMBER *q1, NUMBER *q2, NUMBER *epsilon) { - NUMBER *tmp1, *tmp2, *epsilon2; - NUMBER *q1tmp, *q2tmp; - long m, n; + NUMBER *tmp1, *tmp2, *epsilon2; + NUMBER *q1tmp, *q2tmp; + long m, n; - if (qiszero(epsilon)) { - math_error("Zero epsilon for power"); - not_reached(); - } - if (qiszero(q1) && qisneg(q2)) { - math_error("Negative power of zero"); - not_reached(); - } - if (qiszero(q2) || qisone(q1)) - return qlink(&_qone_); - if (qiszero(q1)) - return qlink(&_qzero_); - if (qisneg(q1)) { - math_error("Negative base for qpower"); - not_reached(); - } - if (qisone(q2)) - return qmappr(q1, epsilon, conf->triground); - if (zrel(q1->num, q1->den) < 0) { - q1tmp = qinv(q1); - q2tmp = qneg(q2); - } else { - q1tmp = qlink(q1); - q2tmp = qlink(q2); - } - if (qisone(q2tmp)) { - qfree(q2tmp); - q2tmp = qmappr(q1tmp, epsilon, conf->triground); - qfree(q1tmp); - return q2tmp; - } - m = qilog2(q1tmp); - n = qilog2(epsilon); - if (qisneg(q2tmp)) { - if (m > 0) { - tmp1 = itoq(m); - tmp2 = qmul(tmp1, q2tmp); - m = qtoi(tmp2); - } else { - tmp1 = qdec(q1tmp); - tmp2 = qqdiv(tmp1, q1tmp); - qfree(tmp1); - tmp1 = qmul(tmp2, q2tmp); - qfree(tmp2); - tmp2 = qmul(tmp1, &_qlge_); - m = qtoi(tmp2); - } - } else { - if (m > 0) { - tmp1 = itoq(m + 1); - tmp2 = qmul(tmp1, q2tmp); - m = qtoi(tmp2); - } else { - tmp1 = qdec(q1tmp); - tmp2 = qmul(tmp1, q2tmp); - qfree(tmp1); - tmp1 = qmul(tmp2, &_qlge_); - m = qtoi(tmp1); - } - } - qfree(tmp1); - qfree(tmp2); - if (m > (1 << 30)) { - qfree(q1tmp); - qfree(q2tmp); - return NULL; - } - m += 1; - if (m < n) { - qfree(q1tmp); - qfree(q2tmp); - return qlink(&_qzero_); - } - tmp1 = qqdiv(epsilon, q2tmp); - tmp2 = qscale(tmp1, -m - 4); - epsilon2 = qqabs(tmp2); - qfree(tmp1); - qfree(tmp2); - tmp1 = qln(q1tmp, epsilon2); - qfree(epsilon2); - tmp2 = qmul(tmp1, q2tmp); - qfree(tmp1); - qfree(q1tmp); - qfree(q2tmp); - if (qisneg(tmp2)) { - tmp1 = qneg(tmp2); - qfree(tmp2); - tmp2 = qexprel(tmp1, m - n + 3); - if (tmp2 == NULL) { - qfree(tmp1); - return NULL; - } - qfree(tmp1); - tmp1 = qinv(tmp2); - } else { - tmp1 = qexprel(tmp2, m - n + 3) ; - if (tmp1 == NULL) { - qfree(tmp2); - return NULL; - } - } - qfree(tmp2); - tmp2 = qmappr(tmp1, epsilon, conf->triground); - qfree(tmp1); - return tmp2; + if (qiszero(epsilon)) { + math_error("Zero epsilon for power"); + not_reached(); + } + if (qiszero(q1) && qisneg(q2)) { + math_error("Negative power of zero"); + not_reached(); + } + if (qiszero(q2) || qisone(q1)) + return qlink(&_qone_); + if (qiszero(q1)) + return qlink(&_qzero_); + if (qisneg(q1)) { + math_error("Negative base for qpower"); + not_reached(); + } + if (qisone(q2)) + return qmappr(q1, epsilon, conf->triground); + if (zrel(q1->num, q1->den) < 0) { + q1tmp = qinv(q1); + q2tmp = qneg(q2); + } else { + q1tmp = qlink(q1); + q2tmp = qlink(q2); + } + if (qisone(q2tmp)) { + qfree(q2tmp); + q2tmp = qmappr(q1tmp, epsilon, conf->triground); + qfree(q1tmp); + return q2tmp; + } + m = qilog2(q1tmp); + n = qilog2(epsilon); + if (qisneg(q2tmp)) { + if (m > 0) { + tmp1 = itoq(m); + tmp2 = qmul(tmp1, q2tmp); + m = qtoi(tmp2); + } else { + tmp1 = qdec(q1tmp); + tmp2 = qqdiv(tmp1, q1tmp); + qfree(tmp1); + tmp1 = qmul(tmp2, q2tmp); + qfree(tmp2); + tmp2 = qmul(tmp1, &_qlge_); + m = qtoi(tmp2); + } + } else { + if (m > 0) { + tmp1 = itoq(m + 1); + tmp2 = qmul(tmp1, q2tmp); + m = qtoi(tmp2); + } else { + tmp1 = qdec(q1tmp); + tmp2 = qmul(tmp1, q2tmp); + qfree(tmp1); + tmp1 = qmul(tmp2, &_qlge_); + m = qtoi(tmp1); + } + } + qfree(tmp1); + qfree(tmp2); + if (m > (1 << 30)) { + qfree(q1tmp); + qfree(q2tmp); + return NULL; + } + m += 1; + if (m < n) { + qfree(q1tmp); + qfree(q2tmp); + return qlink(&_qzero_); + } + tmp1 = qqdiv(epsilon, q2tmp); + tmp2 = qscale(tmp1, -m - 4); + epsilon2 = qqabs(tmp2); + qfree(tmp1); + qfree(tmp2); + tmp1 = qln(q1tmp, epsilon2); + qfree(epsilon2); + tmp2 = qmul(tmp1, q2tmp); + qfree(tmp1); + qfree(q1tmp); + qfree(q2tmp); + if (qisneg(tmp2)) { + tmp1 = qneg(tmp2); + qfree(tmp2); + tmp2 = qexprel(tmp1, m - n + 3); + if (tmp2 == NULL) { + qfree(tmp1); + return NULL; + } + qfree(tmp1); + tmp1 = qinv(tmp2); + } else { + tmp1 = qexprel(tmp2, m - n + 3) ; + if (tmp1 == NULL) { + qfree(tmp2); + return NULL; + } + } + qfree(tmp2); + tmp2 = qmappr(tmp1, epsilon, conf->triground); + qfree(tmp1); + return tmp2; } @@ -1523,40 +1523,40 @@ qpower(NUMBER *q1, NUMBER *q2, NUMBER *epsilon) NUMBER * qroot(NUMBER *q1, NUMBER *q2, NUMBER *epsilon) { - NUMBER *tmp1, *tmp2; - int neg; + NUMBER *tmp1, *tmp2; + int neg; - if (qiszero(epsilon)) { - math_error("Zero epsilon for root"); - not_reached(); - } - if (qisneg(q2) || qiszero(q2) || qisfrac(q2)) { - math_error("Taking bad root of number"); - not_reached(); - } - if (qiszero(q1) || qisone(q1) || qisone(q2)) - return qlink(q1); - if (qistwo(q2)) - return qsqrt(q1, epsilon, conf->triground); - neg = qisneg(q1); - if (neg) { - if (ziseven(q2->num)) { - math_error("Taking even root of negative number"); - not_reached(); - } - q1 = qqabs(q1); - } - tmp2 = qinv(q2); - tmp1 = qpower(q1, tmp2, epsilon); - qfree(tmp2); - if (tmp1 == NULL) - return NULL; - if (neg) { - tmp2 = qneg(tmp1); - qfree(tmp1); - tmp1 = tmp2; - } - return tmp1; + if (qiszero(epsilon)) { + math_error("Zero epsilon for root"); + not_reached(); + } + if (qisneg(q2) || qiszero(q2) || qisfrac(q2)) { + math_error("Taking bad root of number"); + not_reached(); + } + if (qiszero(q1) || qisone(q1) || qisone(q2)) + return qlink(q1); + if (qistwo(q2)) + return qsqrt(q1, epsilon, conf->triground); + neg = qisneg(q1); + if (neg) { + if (ziseven(q2->num)) { + math_error("Taking even root of negative number"); + not_reached(); + } + q1 = qqabs(q1); + } + tmp2 = qinv(q2); + tmp1 = qpower(q1, tmp2, epsilon); + qfree(tmp2); + if (tmp1 == NULL) + return NULL; + if (neg) { + tmp2 = qneg(tmp1); + qfree(tmp1); + tmp1 = tmp2; + } + return tmp1; } @@ -1567,24 +1567,24 @@ qroot(NUMBER *q1, NUMBER *q2, NUMBER *epsilon) NUMBER * qcosh(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp1, *tmp2, *tmp3, *epsilon1; + NUMBER *tmp1, *tmp2, *tmp3, *epsilon1; - epsilon1 = qscale(epsilon, -2); - tmp1 = qqabs(q); - tmp2 = qexp(tmp1, epsilon1); - qfree(tmp1); - qfree(epsilon1); - if (tmp2 == NULL) - return NULL; - tmp1 = qinv(tmp2); - tmp3 = qqadd(tmp1, tmp2); - qfree(tmp1) - qfree(tmp2) - tmp1 = qscale(tmp3, -1); - qfree(tmp3); - tmp2 = qmappr(tmp1, epsilon, conf->triground); - qfree(tmp1); - return tmp2; + epsilon1 = qscale(epsilon, -2); + tmp1 = qqabs(q); + tmp2 = qexp(tmp1, epsilon1); + qfree(tmp1); + qfree(epsilon1); + if (tmp2 == NULL) + return NULL; + tmp1 = qinv(tmp2); + tmp3 = qqadd(tmp1, tmp2); + qfree(tmp1) + qfree(tmp2) + tmp1 = qscale(tmp3, -1); + qfree(tmp3); + tmp2 = qmappr(tmp1, epsilon, conf->triground); + qfree(tmp1); + return tmp2; } @@ -1596,26 +1596,26 @@ qcosh(NUMBER *q, NUMBER *epsilon) NUMBER * qsinh(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp1, *tmp2, *tmp3, *epsilon1; + NUMBER *tmp1, *tmp2, *tmp3, *epsilon1; - if (qiszero(q)) - return qlink(&_qzero_); - epsilon1 = qscale(epsilon, -3); - tmp1 = qqabs(q); - tmp2 = qexp(tmp1, epsilon1); - qfree(tmp1); - qfree(epsilon1); - if (tmp2 == NULL) - return NULL; - tmp1 = qinv(tmp2); - tmp3 = qispos(q) ? qsub(tmp2, tmp1) : qsub(tmp1, tmp2); - qfree(tmp1) - qfree(tmp2) - tmp1 = qscale(tmp3, -1); - qfree(tmp3); - tmp2 = qmappr(tmp1, epsilon, conf->triground); - qfree(tmp1); - return tmp2; + if (qiszero(q)) + return qlink(&_qzero_); + epsilon1 = qscale(epsilon, -3); + tmp1 = qqabs(q); + tmp2 = qexp(tmp1, epsilon1); + qfree(tmp1); + qfree(epsilon1); + if (tmp2 == NULL) + return NULL; + tmp1 = qinv(tmp2); + tmp3 = qispos(q) ? qsub(tmp2, tmp1) : qsub(tmp1, tmp2); + qfree(tmp1) + qfree(tmp2) + tmp1 = qscale(tmp3, -1); + qfree(tmp3); + tmp2 = qmappr(tmp1, epsilon, conf->triground); + qfree(tmp1); + return tmp2; } @@ -1623,53 +1623,53 @@ qsinh(NUMBER *q, NUMBER *epsilon) * Calculate the hyperbolic tangent to the nearest or next to nearest * multiple of epsilon. * This is calculated using the formulae: - * tanh(x) = 1 or -1 for very large abs(x) - * tanh(x) = (+ or -)(1 - 2 * exp(2 * x)) for large abx(x) - * tanh(x) = (exp(2*x) - 1)/(exp(2*x) + 1) otherwise + * tanh(x) = 1 or -1 for very large abs(x) + * tanh(x) = (+ or -)(1 - 2 * exp(2 * x)) for large abx(x) + * tanh(x) = (exp(2*x) - 1)/(exp(2*x) + 1) otherwise */ NUMBER * qtanh(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp1, *tmp2, *tmp3; - long n, m; + NUMBER *tmp1, *tmp2, *tmp3; + long n, m; - n = qilog2(epsilon); - if (n > 0 || qiszero(q)) - return qlink(&_qzero_); - n = -n; - tmp1 = qqabs(q); - tmp2 = qmul(tmp1, &_qlge_); - m = qtoi(tmp2); /* exp(|q|) < 2^(m+1) or m == MAXLONG */ - qfree(tmp2); - if (m > 1 + n/2) { - qfree(tmp1); - return q->num.sign ? qlink(&_qnegone_) : qlink(&_qone_); - } - tmp2 = qscale(tmp1, 1); - qfree(tmp1); - tmp1 = qexprel(tmp2, 2 + n); - qfree(tmp2); - if (m > 1 + n/4) { - tmp2 = qqdiv(&_qtwo_, tmp1); - qfree(tmp1); - tmp1 = qsub(&_qone_, tmp2); - qfree(tmp2); - } else { - tmp2 = qdec(tmp1); - tmp3 = qinc(tmp1); - qfree(tmp1); - tmp1 = qqdiv(tmp2, tmp3); - qfree(tmp2); - qfree(tmp3); - } - tmp2 = qmappr(tmp1, epsilon, conf->triground); - qfree(tmp1); - if (qisneg(q)) { - tmp1 = qneg(tmp2); - qfree(tmp2); - return tmp1; - } - return tmp2; + n = qilog2(epsilon); + if (n > 0 || qiszero(q)) + return qlink(&_qzero_); + n = -n; + tmp1 = qqabs(q); + tmp2 = qmul(tmp1, &_qlge_); + m = qtoi(tmp2); /* exp(|q|) < 2^(m+1) or m == MAXLONG */ + qfree(tmp2); + if (m > 1 + n/2) { + qfree(tmp1); + return q->num.sign ? qlink(&_qnegone_) : qlink(&_qone_); + } + tmp2 = qscale(tmp1, 1); + qfree(tmp1); + tmp1 = qexprel(tmp2, 2 + n); + qfree(tmp2); + if (m > 1 + n/4) { + tmp2 = qqdiv(&_qtwo_, tmp1); + qfree(tmp1); + tmp1 = qsub(&_qone_, tmp2); + qfree(tmp2); + } else { + tmp2 = qdec(tmp1); + tmp3 = qinc(tmp1); + qfree(tmp1); + tmp1 = qqdiv(tmp2, tmp3); + qfree(tmp2); + qfree(tmp3); + } + tmp2 = qmappr(tmp1, epsilon, conf->triground); + qfree(tmp1); + if (qisneg(q)) { + tmp1 = qneg(tmp2); + qfree(tmp2); + return tmp1; + } + return tmp2; } @@ -1680,258 +1680,258 @@ qtanh(NUMBER *q, NUMBER *epsilon) NUMBER * qcoth(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp1, *tmp2, *res; - long n, k; + NUMBER *tmp1, *tmp2, *res; + long n, k; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for coth"); - not_reached(); - } - if (qiszero(q)) { - math_error("Zero argument for coth"); - not_reached(); - } - tmp1 = qscale(q, 1); - tmp2 = qqabs(tmp1); - qfree(tmp1); - k = qilog2(tmp2); - n = qilog2(epsilon); - if (k > 0) { - tmp1 = qmul(&_qlge_, tmp2); - k = qtoi(tmp1); - qfree(tmp1); - } else { - k = 2 * k; - } - k = 4 - k - n; - if (k < 4) - k = 4; - tmp1 = qexprel(tmp2, k); - qfree(tmp2); - tmp2 = qdec(tmp1); - qfree(tmp1); - if (qiszero(tmp2)) { - math_error("This should not happen ????"); - not_reached(); - } - tmp1 = qinv(tmp2); - qfree(tmp2); - tmp2 = qscale(tmp1, 1); - qfree(tmp1); - tmp1 = qinc(tmp2); - qfree(tmp2); - if (qisneg(q)) { - tmp2 = qneg(tmp1); - qfree(tmp1); - tmp1 = tmp2; - } - res = qmappr(tmp1, epsilon, conf->triground); - qfree(tmp1); - return res; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for coth"); + not_reached(); + } + if (qiszero(q)) { + math_error("Zero argument for coth"); + not_reached(); + } + tmp1 = qscale(q, 1); + tmp2 = qqabs(tmp1); + qfree(tmp1); + k = qilog2(tmp2); + n = qilog2(epsilon); + if (k > 0) { + tmp1 = qmul(&_qlge_, tmp2); + k = qtoi(tmp1); + qfree(tmp1); + } else { + k = 2 * k; + } + k = 4 - k - n; + if (k < 4) + k = 4; + tmp1 = qexprel(tmp2, k); + qfree(tmp2); + tmp2 = qdec(tmp1); + qfree(tmp1); + if (qiszero(tmp2)) { + math_error("This should not happen ????"); + not_reached(); + } + tmp1 = qinv(tmp2); + qfree(tmp2); + tmp2 = qscale(tmp1, 1); + qfree(tmp1); + tmp1 = qinc(tmp2); + qfree(tmp2); + if (qisneg(q)) { + tmp2 = qneg(tmp1); + qfree(tmp1); + tmp1 = tmp2; + } + res = qmappr(tmp1, epsilon, conf->triground); + qfree(tmp1); + return res; } NUMBER * qsech(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp1, *tmp2, *tmp3, *res; - long n, k; + NUMBER *tmp1, *tmp2, *tmp3, *res; + long n, k; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for sech"); - not_reached(); - } - if (qiszero(q)) - return qlink(&_qone_); + if (qiszero(epsilon)) { + math_error("Zero epsilon value for sech"); + not_reached(); + } + if (qiszero(q)) + return qlink(&_qone_); - tmp1 = qqabs(q); - k = 0; - if (zrel(tmp1->num, tmp1->den) >= 0) { - tmp2 = qmul(&_qlge_, tmp1); - k = qtoi(tmp2); - qfree(tmp2); - } - n = qilog2(epsilon); - if (k + n > 1) { - qfree(tmp1); - return qlink(&_qzero_); - } - tmp2 = qexprel(tmp1, 4 - k - n); - qfree(tmp1); - tmp1 = qinv(tmp2); - tmp3 = qqadd(tmp1, tmp2); - qfree(tmp1); - qfree(tmp2); - tmp1 = qinv(tmp3); - qfree(tmp3); - tmp2 = qscale(tmp1, 1); - qfree(tmp1); - res = qmappr(tmp2, epsilon, conf->triground); - qfree(tmp2); - return res; + tmp1 = qqabs(q); + k = 0; + if (zrel(tmp1->num, tmp1->den) >= 0) { + tmp2 = qmul(&_qlge_, tmp1); + k = qtoi(tmp2); + qfree(tmp2); + } + n = qilog2(epsilon); + if (k + n > 1) { + qfree(tmp1); + return qlink(&_qzero_); + } + tmp2 = qexprel(tmp1, 4 - k - n); + qfree(tmp1); + tmp1 = qinv(tmp2); + tmp3 = qqadd(tmp1, tmp2); + qfree(tmp1); + qfree(tmp2); + tmp1 = qinv(tmp3); + qfree(tmp3); + tmp2 = qscale(tmp1, 1); + qfree(tmp1); + res = qmappr(tmp2, epsilon, conf->triground); + qfree(tmp2); + return res; } NUMBER * qcsch(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp1, *tmp2, *tmp3, *res; - long n, k; + NUMBER *tmp1, *tmp2, *tmp3, *res; + long n, k; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for csch"); - not_reached(); - } - if (qiszero(q)) { - math_error("Zero argument for csch"); - not_reached(); - } + if (qiszero(epsilon)) { + math_error("Zero epsilon value for csch"); + not_reached(); + } + if (qiszero(q)) { + math_error("Zero argument for csch"); + not_reached(); + } - n = qilog2(epsilon); - tmp1 = qqabs(q); - if (zrel(tmp1->num, tmp1->den) >= 0) { - tmp2 = qmul(&_qlge_, tmp1); - k = qtoi(tmp2); - qfree(tmp2); - } else { - k = 2 * qilog2(tmp1); - } - if (k + n >= 1) { - qfree(tmp1); - return qlink(&_qzero_); - } - tmp2 = qexprel(tmp1, 4 - k - n); - qfree(tmp1); - tmp1 = qinv(tmp2); - if (qisneg(q)) - tmp3 = qsub(tmp1, tmp2); - else - tmp3 = qsub(tmp2, tmp1); - qfree(tmp1); - qfree(tmp2); - tmp1 = qinv(tmp3); - qfree(tmp3) - tmp2 = qscale(tmp1, 1); - qfree(tmp1); - res = qmappr(tmp2, epsilon, conf->triground); - qfree(tmp2); - return res; + n = qilog2(epsilon); + tmp1 = qqabs(q); + if (zrel(tmp1->num, tmp1->den) >= 0) { + tmp2 = qmul(&_qlge_, tmp1); + k = qtoi(tmp2); + qfree(tmp2); + } else { + k = 2 * qilog2(tmp1); + } + if (k + n >= 1) { + qfree(tmp1); + return qlink(&_qzero_); + } + tmp2 = qexprel(tmp1, 4 - k - n); + qfree(tmp1); + tmp1 = qinv(tmp2); + if (qisneg(q)) + tmp3 = qsub(tmp1, tmp2); + else + tmp3 = qsub(tmp2, tmp1); + qfree(tmp1); + qfree(tmp2); + tmp1 = qinv(tmp3); + qfree(tmp3) + tmp2 = qscale(tmp1, 1); + qfree(tmp1); + res = qmappr(tmp2, epsilon, conf->triground); + qfree(tmp2); + return res; } /* * Compute the hyperbolic arccosine within the specified accuracy. * This is calculated using the formula: - * acosh(x) = ln(x + sqrt(x^2 - 1)). + * acosh(x) = ln(x + sqrt(x^2 - 1)). */ NUMBER * qacosh(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp1, *tmp2, *epsilon1; - long n; + NUMBER *tmp1, *tmp2, *epsilon1; + long n; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for acosh"); - not_reached(); - } - if (qisone(q)) - return qlink(&_qzero_); - if (zrel(q->num, q->den) < 0) - return NULL; - n = qilog2(epsilon); - epsilon1 = qbitvalue(n - 3); - tmp1 = qsquare(q); - tmp2 = qdec(tmp1); - qfree(tmp1); - tmp1 = qsqrt(tmp2, epsilon1, conf->triground); - qfree(tmp2); - tmp2 = qqadd(tmp1, q); - qfree(tmp1); - tmp1 = qln(tmp2, epsilon1); - qfree(tmp2); - qfree(epsilon1); - tmp2 = qmappr(tmp1, epsilon, conf->triground); - qfree(tmp1); - return tmp2; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for acosh"); + not_reached(); + } + if (qisone(q)) + return qlink(&_qzero_); + if (zrel(q->num, q->den) < 0) + return NULL; + n = qilog2(epsilon); + epsilon1 = qbitvalue(n - 3); + tmp1 = qsquare(q); + tmp2 = qdec(tmp1); + qfree(tmp1); + tmp1 = qsqrt(tmp2, epsilon1, conf->triground); + qfree(tmp2); + tmp2 = qqadd(tmp1, q); + qfree(tmp1); + tmp1 = qln(tmp2, epsilon1); + qfree(tmp2); + qfree(epsilon1); + tmp2 = qmappr(tmp1, epsilon, conf->triground); + qfree(tmp1); + return tmp2; } /* * Compute the hyperbolic arcsine within the specified accuracy. * This is calculated using the formula: - * asinh(x) = ln(x + sqrt(x^2 + 1)). + * asinh(x) = ln(x + sqrt(x^2 + 1)). */ NUMBER * qasinh(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp1, *tmp2, *epsilon1; - long n; - bool neg; + NUMBER *tmp1, *tmp2, *epsilon1; + long n; + bool neg; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for asinh"); - not_reached(); - } - if (qiszero(q)) - return qlink(&_qzero_); - neg = qisneg(q); - q = qqabs(q); - n = qilog2(epsilon); - epsilon1 = qbitvalue(n - 3); - tmp1 = qsquare(q); - tmp2 = qinc(tmp1); - qfree(tmp1); - tmp1 = qsqrt(tmp2, epsilon1, conf->triground); - qfree(tmp2); - tmp2 = qqadd(tmp1, q); - qfree(tmp1); - tmp1 = qln(tmp2, epsilon1); - qfree(tmp2); - qfree(q); - qfree(epsilon1); - tmp2 = qmappr(tmp1, epsilon, conf->triground); - if (neg) { - tmp1 = qneg(tmp2); - qfree(tmp2); - return tmp1; - } - return tmp2; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for asinh"); + not_reached(); + } + if (qiszero(q)) + return qlink(&_qzero_); + neg = qisneg(q); + q = qqabs(q); + n = qilog2(epsilon); + epsilon1 = qbitvalue(n - 3); + tmp1 = qsquare(q); + tmp2 = qinc(tmp1); + qfree(tmp1); + tmp1 = qsqrt(tmp2, epsilon1, conf->triground); + qfree(tmp2); + tmp2 = qqadd(tmp1, q); + qfree(tmp1); + tmp1 = qln(tmp2, epsilon1); + qfree(tmp2); + qfree(q); + qfree(epsilon1); + tmp2 = qmappr(tmp1, epsilon, conf->triground); + if (neg) { + tmp1 = qneg(tmp2); + qfree(tmp2); + return tmp1; + } + return tmp2; } /* * Compute the hyperbolic arctangent within the specified accuracy. * This is calculated using the formula: - * atanh(x) = ln((1 + x) / (1 - x)) / 2. + * atanh(x) = ln((1 + x) / (1 - x)) / 2. */ NUMBER * qatanh(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp1, *tmp2, *tmp3, *epsilon1; - ZVALUE z; + NUMBER *tmp1, *tmp2, *tmp3, *epsilon1; + ZVALUE z; - if (qiszero(epsilon)) { - math_error("Zero epsilon value for atanh"); - not_reached(); - } - if (qiszero(q)) - return qlink(&_qzero_); - z = q->num; - z.sign = 0; - if (zrel(z, q->den) >= 0) - return NULL; - tmp1 = qinc(q); - tmp2 = qsub(&_qone_, q); - tmp3 = qqdiv(tmp1, tmp2); - qfree(tmp1); - qfree(tmp2); - epsilon1 = qscale(epsilon, 1L); - tmp1 = qln(tmp3, epsilon1); - qfree(tmp3); - tmp2 = qscale(tmp1, -1L); - qfree(tmp1); - qfree(epsilon1); - return tmp2; + if (qiszero(epsilon)) { + math_error("Zero epsilon value for atanh"); + not_reached(); + } + if (qiszero(q)) + return qlink(&_qzero_); + z = q->num; + z.sign = 0; + if (zrel(z, q->den) >= 0) + return NULL; + tmp1 = qinc(q); + tmp2 = qsub(&_qone_, q); + tmp3 = qqdiv(tmp1, tmp2); + qfree(tmp1); + qfree(tmp2); + epsilon1 = qscale(epsilon, 1L); + tmp1 = qln(tmp3, epsilon1); + qfree(tmp3); + tmp2 = qscale(tmp1, -1L); + qfree(tmp1); + qfree(epsilon1); + return tmp2; } @@ -1941,12 +1941,12 @@ qatanh(NUMBER *q, NUMBER *epsilon) NUMBER * qasech(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp, *res; + NUMBER *tmp, *res; - tmp = qinv(q); - res = qacosh(tmp, epsilon); - qfree(tmp); - return res; + tmp = qinv(q); + res = qacosh(tmp, epsilon); + qfree(tmp); + return res; } @@ -1956,12 +1956,12 @@ qasech(NUMBER *q, NUMBER *epsilon) NUMBER * qacsch(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp, *res; + NUMBER *tmp, *res; - tmp = qinv(q); - res = qasinh(tmp, epsilon); - qfree(tmp); - return res; + tmp = qinv(q); + res = qasinh(tmp, epsilon); + qfree(tmp); + return res; } @@ -1971,12 +1971,12 @@ qacsch(NUMBER *q, NUMBER *epsilon) NUMBER * qacoth(NUMBER *q, NUMBER *epsilon) { - NUMBER *tmp, *res; + NUMBER *tmp, *res; - tmp = qinv(q); - res = qatanh(tmp, epsilon); - qfree(tmp); - return res; + tmp = qinv(q); + res = qatanh(tmp, epsilon); + qfree(tmp); + return res; } @@ -1985,44 +1985,44 @@ qacoth(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * versin(x) = 1 - cos(x) + * versin(x) = 1 - cos(x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qversin(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate trig function value - */ - qtmp = qcos(q, epsilon); - res = qsub(&_qone_, qtmp); - qfree(qtmp); + /* + * calculate trig function value + */ + qtmp = qcos(q, epsilon); + res = qsub(&_qone_, qtmp); + qfree(qtmp); - /* - * return trigonometric result - */ - return res; + /* + * return trigonometric result + */ + return res; } @@ -2031,52 +2031,52 @@ qversin(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * aversin(x) = acos(1 - x) + * aversin(x) = acos(1 - x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * != NULL ==> real value result of trig function on q with error epsilon, - * NULL ==> trig function value cannot be expressed as a NUMBER + * != NULL ==> real value result of trig function on q with error epsilon, + * NULL ==> trig function value cannot be expressed as a NUMBER * * NOTE: If this function returns NULL, consider calling the equivalent - * COMPLEX function from comfunc.c. See the help file for the - * related builtin for details. + * COMPLEX function from comfunc.c. See the help file for the + * related builtin for details. */ NUMBER * qaversin_or_NULL(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - qtmp = qsub(&_qone_, q); - res = qacos(qtmp, epsilon); - qfree(qtmp); - if (res == NULL) { - return NULL; - } + /* + * calculate inverse trig function value + */ + qtmp = qsub(&_qone_, q); + res = qacos(qtmp, epsilon); + qfree(qtmp); + if (res == NULL) { + return NULL; + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -2085,45 +2085,45 @@ qaversin_or_NULL(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * aversin(x) = acos(1 - x) + * aversin(x) = acos(1 - x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qaversin(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ + NUMBER *res; /* inverse trig value result */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - res = qaversin_or_NULL(q, epsilon); - if (res == NULL) { - math_error("cannot compute inverse cosine for aversin"); - not_reached(); - } + /* + * calculate inverse trig function value + */ + res = qaversin_or_NULL(q, epsilon); + if (res == NULL) { + math_error("cannot compute inverse cosine for aversin"); + not_reached(); + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -2132,44 +2132,44 @@ qaversin(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * coversin((x) = 1 - sin(x) + * coversin((x) = 1 - sin(x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qcoversin(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate trig function value - */ - qtmp = qsin(q, epsilon); - res = qsub(&_qone_, qtmp); - qfree(qtmp); + /* + * calculate trig function value + */ + qtmp = qsin(q, epsilon); + res = qsub(&_qone_, qtmp); + qfree(qtmp); - /* - * return trigonometric result - */ - return res; + /* + * return trigonometric result + */ + return res; } @@ -2178,55 +2178,55 @@ qcoversin(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * acoversin(x) = asin(1 - x) + * acoversin(x) = asin(1 - x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon * * returns: - * != NULL ==> real value result of trig function on q with error epsilon, - * NULL ==> trig function value cannot be expressed as a NUMBER + * != NULL ==> real value result of trig function on q with error epsilon, + * NULL ==> trig function value cannot be expressed as a NUMBER * * NOTE: If this function returns NULL, consider calling the equivalent - * COMPLEX function from comfunc.c. See the help file for the - * related builtin for details. + * COMPLEX function from comfunc.c. See the help file for the + * related builtin for details. */ NUMBER * qacoversin_or_NULL(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - qtmp = qsub(&_qone_, q); - res = qasin(qtmp, epsilon); - qfree(qtmp); - if (res == NULL) { - return NULL; - } + /* + * calculate inverse trig function value + */ + qtmp = qsub(&_qone_, q); + res = qasin(qtmp, epsilon); + qfree(qtmp); + if (res == NULL) { + return NULL; + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -2235,45 +2235,45 @@ qacoversin_or_NULL(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * acoversin(x) = asin(1 - x) + * acoversin(x) = asin(1 - x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qacoversin(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ + NUMBER *res; /* inverse trig value result */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - res = qacoversin_or_NULL(q, epsilon); - if (res == NULL) { - math_error("cannot compute inverse sine for acoversin"); - not_reached(); - } + /* + * calculate inverse trig function value + */ + res = qacoversin_or_NULL(q, epsilon); + if (res == NULL) { + math_error("cannot compute inverse sine for acoversin"); + not_reached(); + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -2282,44 +2282,44 @@ qacoversin(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * vercos(x) = 1 + cos(x) + * vercos(x) = 1 + cos(x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qvercos(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate trig function value - */ - qtmp = qcos(q, epsilon); - res = qqadd(&_qone_, qtmp); - qfree(qtmp); + /* + * calculate trig function value + */ + qtmp = qcos(q, epsilon); + res = qqadd(&_qone_, qtmp); + qfree(qtmp); - /* - * return trigonometric result - */ - return res; + /* + * return trigonometric result + */ + return res; } @@ -2328,52 +2328,52 @@ qvercos(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * avercos(x) = acos(x - 1) + * avercos(x) = acos(x - 1) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * != NULL ==> real value result of trig function on q with error epsilon, - * NULL ==> trig function value cannot be expressed as a NUMBER + * != NULL ==> real value result of trig function on q with error epsilon, + * NULL ==> trig function value cannot be expressed as a NUMBER * * NOTE: If this function returns NULL, consider calling the equivalent - * COMPLEX function from comfunc.c. See the help file for the - * related builtin for details. + * COMPLEX function from comfunc.c. See the help file for the + * related builtin for details. */ NUMBER * qavercos_or_NULL(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - qtmp = qsub(q, &_qone_); - res = qacos(qtmp, epsilon); - qfree(qtmp); - if (res == NULL) { - return NULL; - } + /* + * calculate inverse trig function value + */ + qtmp = qsub(q, &_qone_); + res = qacos(qtmp, epsilon); + qfree(qtmp); + if (res == NULL) { + return NULL; + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -2382,45 +2382,45 @@ qavercos_or_NULL(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * avercos(x) = acos(x - 1) + * avercos(x) = acos(x - 1) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qavercos(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ + NUMBER *res; /* inverse trig value result */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - res = qavercos_or_NULL(q, epsilon); - if (res == NULL) { - math_error("cannot compute inverse cosine for avercos"); - not_reached(); - } + /* + * calculate inverse trig function value + */ + res = qavercos_or_NULL(q, epsilon); + if (res == NULL) { + math_error("cannot compute inverse cosine for avercos"); + not_reached(); + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -2429,44 +2429,44 @@ qavercos(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * covercos((x) = 1 + sin(x) + * covercos((x) = 1 + sin(x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qcovercos(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate trig function value - */ - qtmp = qsin(q, epsilon); - res = qqadd(&_qone_, qtmp); - qfree(qtmp); + /* + * calculate trig function value + */ + qtmp = qsin(q, epsilon); + res = qqadd(&_qone_, qtmp); + qfree(qtmp); - /* - * return trigonometric result - */ - return res; + /* + * return trigonometric result + */ + return res; } @@ -2475,55 +2475,55 @@ qcovercos(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * acovercos(x) = asin(x - 1) + * acovercos(x) = asin(x - 1) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon * * returns: - * != NULL ==> real value result of trig function on q with error epsilon, - * NULL ==> trig function value cannot be expressed as a NUMBER + * != NULL ==> real value result of trig function on q with error epsilon, + * NULL ==> trig function value cannot be expressed as a NUMBER * * NOTE: If this function returns NULL, consider calling the equivalent - * COMPLEX function from comfunc.c. See the help file for the - * related builtin for details. + * COMPLEX function from comfunc.c. See the help file for the + * related builtin for details. */ NUMBER * qacovercos_or_NULL(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - qtmp = qsub(&_qone_, q); - res = qasin(qtmp, epsilon); - qfree(qtmp); - if (res == NULL) { - return NULL; - } + /* + * calculate inverse trig function value + */ + qtmp = qsub(&_qone_, q); + res = qasin(qtmp, epsilon); + qfree(qtmp); + if (res == NULL) { + return NULL; + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -2532,45 +2532,45 @@ qacovercos_or_NULL(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * acovercos(x) = asin(x - 1) + * acovercos(x) = asin(x - 1) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qacovercos(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ + NUMBER *res; /* inverse trig value result */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - res = qacovercos_or_NULL(q, epsilon); - if (res == NULL) { - math_error("cannot compute inverse sine for acovercos"); - not_reached(); - } + /* + * calculate inverse trig function value + */ + res = qacovercos_or_NULL(q, epsilon); + if (res == NULL) { + math_error("cannot compute inverse sine for acovercos"); + not_reached(); + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -2579,44 +2579,44 @@ qacovercos(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * haversin(x) = versin(x) / 2 + * haversin(x) = versin(x) / 2 * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qhaversin(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate trig function value - */ - qtmp = qversin(q, epsilon); - res = qdivi(qtmp, 2); - qfree(qtmp); + /* + * calculate trig function value + */ + qtmp = qversin(q, epsilon); + res = qdivi(qtmp, 2); + qfree(qtmp); - /* - * return trigonometric result - */ - return res; + /* + * return trigonometric result + */ + return res; } @@ -2625,55 +2625,55 @@ qhaversin(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * ahaversin(x) = acos(1 - 2*x) + * ahaversin(x) = acos(1 - 2*x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * != NULL ==> real value result of trig function on q with error epsilon, - * NULL ==> trig function value cannot be expressed as a NUMBER + * != NULL ==> real value result of trig function on q with error epsilon, + * NULL ==> trig function value cannot be expressed as a NUMBER * * NOTE: If this function returns NULL, consider calling the equivalent - * COMPLEX function from comfunc.c. See the help file for the - * related builtin for details. + * COMPLEX function from comfunc.c. See the help file for the + * related builtin for details. */ NUMBER * qahaversin_or_NULL(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ - NUMBER *x2; /* twice x */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *x2; /* twice x */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - x2 = qmuli(q, 2); - qtmp = qsub(&_qone_, x2); - qfree(x2); - res = qacos(qtmp, epsilon); - qfree(qtmp); - if (res == NULL) { - return NULL; - } + /* + * calculate inverse trig function value + */ + x2 = qmuli(q, 2); + qtmp = qsub(&_qone_, x2); + qfree(x2); + res = qacos(qtmp, epsilon); + qfree(qtmp); + if (res == NULL) { + return NULL; + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -2682,45 +2682,45 @@ qahaversin_or_NULL(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * ahaversin(x) = acos(1 - 2*x) + * ahaversin(x) = acos(1 - 2*x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qahaversin(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ + NUMBER *res; /* inverse trig value result */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - res = qahaversin_or_NULL(q, epsilon); - if (res == NULL) { - math_error("cannot compute inverse cosine for ahaversin"); - not_reached(); - } + /* + * calculate inverse trig function value + */ + res = qahaversin_or_NULL(q, epsilon); + if (res == NULL) { + math_error("cannot compute inverse cosine for ahaversin"); + not_reached(); + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -2729,44 +2729,44 @@ qahaversin(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * hacoversin((x) = coversin(x) / 2 + * hacoversin((x) = coversin(x) / 2 * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qhacoversin(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate trig function value - */ - qtmp = qcoversin(q, epsilon); - res = qdivi(qtmp, 2); - qfree(qtmp); + /* + * calculate trig function value + */ + qtmp = qcoversin(q, epsilon); + res = qdivi(qtmp, 2); + qfree(qtmp); - /* - * return trigonometric result - */ - return res; + /* + * return trigonometric result + */ + return res; } @@ -2775,55 +2775,55 @@ qhacoversin(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * ahacoversin(x) = asin(1 - 2*x) + * ahacoversin(x) = asin(1 - 2*x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon * * returns: - * != NULL ==> real value result of trig function on q with error epsilon, - * NULL ==> trig function value cannot be expressed as a NUMBER + * != NULL ==> real value result of trig function on q with error epsilon, + * NULL ==> trig function value cannot be expressed as a NUMBER * * NOTE: If this function returns NULL, consider calling the equivalent - * COMPLEX function from comfunc.c. See the help file for the - * related builtin for details. + * COMPLEX function from comfunc.c. See the help file for the + * related builtin for details. */ NUMBER * qahacoversin_or_NULL(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - qtmp = qsub(&_qone_, q); - res = qasin(qtmp, epsilon); - qfree(qtmp); - if (res == NULL) { - return NULL; - } + /* + * calculate inverse trig function value + */ + qtmp = qsub(&_qone_, q); + res = qasin(qtmp, epsilon); + qfree(qtmp); + if (res == NULL) { + return NULL; + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -2832,45 +2832,45 @@ qahacoversin_or_NULL(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * ahacoversin(x) = asin(1 - 2*x) + * ahacoversin(x) = asin(1 - 2*x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qahacoversin(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ + NUMBER *res; /* inverse trig value result */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - res = qahacoversin_or_NULL(q, epsilon); - if (res == NULL) { - math_error("cannot compute inverse sine for ahacoversin"); - not_reached(); - } + /* + * calculate inverse trig function value + */ + res = qahacoversin_or_NULL(q, epsilon); + if (res == NULL) { + math_error("cannot compute inverse sine for ahacoversin"); + not_reached(); + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -2879,44 +2879,44 @@ qahacoversin(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * havercos(x) = vercos(x) / 2 + * havercos(x) = vercos(x) / 2 * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qhavercos(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate trig function value - */ - qtmp = qvercos(q, epsilon); - res = qdivi(qtmp, 2); - qfree(qtmp); + /* + * calculate trig function value + */ + qtmp = qvercos(q, epsilon); + res = qdivi(qtmp, 2); + qfree(qtmp); - /* - * return trigonometric result - */ - return res; + /* + * return trigonometric result + */ + return res; } @@ -2925,55 +2925,55 @@ qhavercos(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * ahavercos(x) = acos(1 - 2*x) + * ahavercos(x) = acos(1 - 2*x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * != NULL ==> real value result of trig function on q with error epsilon, - * NULL ==> trig function value cannot be expressed as a NUMBER + * != NULL ==> real value result of trig function on q with error epsilon, + * NULL ==> trig function value cannot be expressed as a NUMBER * * NOTE: If this function returns NULL, consider calling the equivalent - * COMPLEX function from comfunc.c. See the help file for the - * related builtin for details. + * COMPLEX function from comfunc.c. See the help file for the + * related builtin for details. */ NUMBER * qahavercos_or_NULL(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ - NUMBER *x2; /* twice x */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *x2; /* twice x */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - x2 = qmuli(q, 2); - qtmp = qsub(&_qone_, x2); - qfree(x2); - res = qacos(qtmp, epsilon); - qfree(qtmp); - if (res == NULL) { - return NULL; - } + /* + * calculate inverse trig function value + */ + x2 = qmuli(q, 2); + qtmp = qsub(&_qone_, x2); + qfree(x2); + res = qacos(qtmp, epsilon); + qfree(qtmp); + if (res == NULL) { + return NULL; + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -2982,45 +2982,45 @@ qahavercos_or_NULL(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * ahavercos(x) = acos(1 - 2*x) + * ahavercos(x) = acos(1 - 2*x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qahavercos(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ + NUMBER *res; /* inverse trig value result */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - res = qahaversin_or_NULL(q, epsilon); - if (res == NULL) { - math_error("cannot compute inverse cocosine for ahavercos"); - not_reached(); - } + /* + * calculate inverse trig function value + */ + res = qahaversin_or_NULL(q, epsilon); + if (res == NULL) { + math_error("cannot compute inverse cocosine for ahavercos"); + not_reached(); + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -3029,44 +3029,44 @@ qahavercos(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * hacovercos((x) = covercos(x) / 2 + * hacovercos((x) = covercos(x) / 2 * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qhacovercos(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate trig function value - */ - qtmp = qcovercos(q, epsilon); - res = qdivi(qtmp, 2); - qfree(qtmp); + /* + * calculate trig function value + */ + qtmp = qcovercos(q, epsilon); + res = qdivi(qtmp, 2); + qfree(qtmp); - /* - * return trigonometric result - */ - return res; + /* + * return trigonometric result + */ + return res; } @@ -3075,55 +3075,55 @@ qhacovercos(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * ahacovercos(x) = acos(2*x - 1) + * ahacovercos(x) = acos(2*x - 1) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon * * returns: - * != NULL ==> real value result of trig function on q with error epsilon, - * NULL ==> trig function value cannot be expressed as a NUMBER + * != NULL ==> real value result of trig function on q with error epsilon, + * NULL ==> trig function value cannot be expressed as a NUMBER * * NOTE: If this function returns NULL, consider calling the equivalent - * COMPLEX function from comfunc.c. See the help file for the - * related builtin for details. + * COMPLEX function from comfunc.c. See the help file for the + * related builtin for details. */ NUMBER * qahacovercos_or_NULL(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - qtmp = qsub(&_qone_, q); - res = qacos(qtmp, epsilon); - qfree(qtmp); - if (res == NULL) { - return NULL; - } + /* + * calculate inverse trig function value + */ + qtmp = qsub(&_qone_, q); + res = qacos(qtmp, epsilon); + qfree(qtmp); + if (res == NULL) { + return NULL; + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -3132,45 +3132,45 @@ qahacovercos_or_NULL(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * ahacovercos(x) = acos(2*x - 1) + * ahacovercos(x) = acos(2*x - 1) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qahacovercos(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ + NUMBER *res; /* inverse trig value result */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - res = qahacoversin_or_NULL(q, epsilon); - if (res == NULL) { - math_error("cannot compute inverse cosine for ahacovercos"); - not_reached(); - } + /* + * calculate inverse trig function value + */ + res = qahacoversin_or_NULL(q, epsilon); + if (res == NULL) { + math_error("cannot compute inverse cosine for ahacovercos"); + not_reached(); + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -3179,44 +3179,44 @@ qahacovercos(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * exsec(x) = sec(x) - 1 + * exsec(x) = sec(x) - 1 * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qexsec(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate trig function value - */ - qtmp = qsec(q, epsilon); - res = qsub(qtmp, &_qone_); - qfree(qtmp); + /* + * calculate trig function value + */ + qtmp = qsec(q, epsilon); + res = qsub(qtmp, &_qone_); + qfree(qtmp); - /* - * return trigonometric result - */ - return res; + /* + * return trigonometric result + */ + return res; } @@ -3225,52 +3225,52 @@ qexsec(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * aexsec(x) = asec(x + 1) + * aexsec(x) = asec(x + 1) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * != NULL ==> real value result of trig function on q with error epsilon, - * NULL ==> trig function value cannot be expressed as a NUMBER + * != NULL ==> real value result of trig function on q with error epsilon, + * NULL ==> trig function value cannot be expressed as a NUMBER * * NOTE: If this function returns NULL, consider calling the equivalent - * COMPLEX function from comfunc.c. See the help file for the - * related builtin for details. + * COMPLEX function from comfunc.c. See the help file for the + * related builtin for details. */ NUMBER * qaexsec_or_NULL(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - qtmp = qaddi(q, 1); - res = qasec(qtmp, epsilon); - qfree(qtmp); - if (res == NULL) { - return NULL; - } + /* + * calculate inverse trig function value + */ + qtmp = qaddi(q, 1); + res = qasec(qtmp, epsilon); + qfree(qtmp); + if (res == NULL) { + return NULL; + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -3279,45 +3279,45 @@ qaexsec_or_NULL(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * aexsec(x) = asec(x + 1) + * aexsec(x) = asec(x + 1) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qaexsec(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ + NUMBER *res; /* inverse trig value result */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - res = qaexsec_or_NULL(q, epsilon); - if (res == NULL) { - math_error("cannot compute inverse cosine for aexsec"); - not_reached(); - } + /* + * calculate inverse trig function value + */ + res = qaexsec_or_NULL(q, epsilon); + if (res == NULL) { + math_error("cannot compute inverse cosine for aexsec"); + not_reached(); + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -3326,44 +3326,44 @@ qaexsec(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * excsc(x) = csc(x) - 1 + * excsc(x) = csc(x) - 1 * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qexcsc(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate trig function value - */ - qtmp = qcsc(q, epsilon); - res = qsub(qtmp, &_qone_); - qfree(qtmp); + /* + * calculate trig function value + */ + qtmp = qcsc(q, epsilon); + res = qsub(qtmp, &_qone_); + qfree(qtmp); - /* - * return trigonometric result - */ - return res; + /* + * return trigonometric result + */ + return res; } @@ -3372,55 +3372,55 @@ qexcsc(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * aexcsc(x) = acsc(x + 1) + * aexcsc(x) = acsc(x + 1) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon * * returns: - * != NULL ==> real value result of trig function on q with error epsilon, - * NULL ==> trig function value cannot be expressed as a NUMBER + * != NULL ==> real value result of trig function on q with error epsilon, + * NULL ==> trig function value cannot be expressed as a NUMBER * * NOTE: If this function returns NULL, consider calling the equivalent - * COMPLEX function from comfunc.c. See the help file for the - * related builtin for details. + * COMPLEX function from comfunc.c. See the help file for the + * related builtin for details. */ NUMBER * qaexcsc_or_NULL(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - qtmp = qaddi(q, 1); - res = qacsc(qtmp, epsilon); - qfree(qtmp); - if (res == NULL) { - return NULL; - } + /* + * calculate inverse trig function value + */ + qtmp = qaddi(q, 1); + res = qacsc(qtmp, epsilon); + qfree(qtmp); + if (res == NULL) { + return NULL; + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -3429,45 +3429,45 @@ qaexcsc_or_NULL(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * aexcsc(x) = acsc(x + 1) + * aexcsc(x) = acsc(x + 1) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qaexcsc(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ + NUMBER *res; /* inverse trig value result */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - res = qaexcsc_or_NULL(q, epsilon); - if (res == NULL) { - math_error("cannot compute inverse sine for aexcsc"); - not_reached(); - } + /* + * calculate inverse trig function value + */ + res = qaexcsc_or_NULL(q, epsilon); + if (res == NULL) { + math_error("cannot compute inverse sine for aexcsc"); + not_reached(); + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -3476,47 +3476,47 @@ qaexcsc(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * crd(x) = 2 * sin(x / 2) + * crd(x) = 2 * sin(x / 2) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qcrd(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qdiv2; /* q/2 */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qdiv2; /* q/2 */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate trig function value - */ - qdiv2 = qdivi(q, 2); - qtmp = qsin(qdiv2, epsilon); - qfree(qdiv2); - res = qmuli(qtmp, 2); - qfree(qtmp); + /* + * calculate trig function value + */ + qdiv2 = qdivi(q, 2); + qtmp = qsin(qdiv2, epsilon); + qfree(qdiv2); + res = qmuli(qtmp, 2); + qfree(qtmp); - /* - * return trigonometric result - */ - return res; + /* + * return trigonometric result + */ + return res; } @@ -3525,58 +3525,58 @@ qcrd(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * acrd(x) = 2 * asin(x / 2) + * acrd(x) = 2 * asin(x / 2) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon * * returns: - * != NULL ==> real value result of trig function on q with error epsilon, - * NULL ==> trig function value cannot be expressed as a NUMBER + * != NULL ==> real value result of trig function on q with error epsilon, + * NULL ==> trig function value cannot be expressed as a NUMBER * * NOTE: If this function returns NULL, consider calling the equivalent - * COMPLEX function from comfunc.c. See the help file for the - * related builtin for details. + * COMPLEX function from comfunc.c. See the help file for the + * related builtin for details. */ NUMBER * qacrd_or_NULL(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ - NUMBER *qdiv2; /* q/2 */ - NUMBER *qtmp; /* argument to inverse trig function */ + NUMBER *res; /* inverse trig value result */ + NUMBER *qdiv2; /* q/2 */ + NUMBER *qtmp; /* argument to inverse trig function */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - qdiv2 = qdivi(q, 2); - qtmp = qasin(qdiv2, epsilon); - qfree(qdiv2); - if (qtmp == NULL) { - return NULL; - } - res = qmuli(qtmp, 2); - qfree(qtmp); + /* + * calculate inverse trig function value + */ + qdiv2 = qdivi(q, 2); + qtmp = qasin(qdiv2, epsilon); + qfree(qdiv2); + if (qtmp == NULL) { + return NULL; + } + res = qmuli(qtmp, 2); + qfree(qtmp); - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -3585,45 +3585,45 @@ qacrd_or_NULL(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * acrd(x) = 2 * asin(x / 2) + * acrd(x) = 2 * asin(x / 2) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qacrd(NUMBER *q, NUMBER *epsilon) { - NUMBER *res; /* inverse trig value result */ + NUMBER *res; /* inverse trig value result */ - /* - * firewall - */ - if (q == NULL) { - math_error("q is NULL for %s", __func__); - not_reached(); - } - if (check_epsilon(epsilon) == false) { - math_error("Invalid epsilon arg for %s", __func__); - not_reached(); - } + /* + * firewall + */ + if (q == NULL) { + math_error("q is NULL for %s", __func__); + not_reached(); + } + if (check_epsilon(epsilon) == false) { + math_error("Invalid epsilon arg for %s", __func__); + not_reached(); + } - /* - * calculate inverse trig function value - */ - res = qacrd_or_NULL(q, epsilon); - if (res == NULL) { - math_error("cannot compute inverse sine for acrd"); - not_reached(); - } + /* + * calculate inverse trig function value + */ + res = qacrd_or_NULL(q, epsilon); + if (res == NULL) { + math_error("cannot compute inverse sine for acrd"); + not_reached(); + } - /* - * return inverse trigonometric result - */ - return res; + /* + * return inverse trigonometric result + */ + return res; } @@ -3632,62 +3632,62 @@ qacrd(NUMBER *q, NUMBER *epsilon) * * This uses the formula: * - * cas(x) = cos(x) + sin(x) + * cas(x) = cos(x) + sin(x) * * given: - * q real value to pass to the trig function - * epsilon error tolerance / precision for trig calculation + * q real value to pass to the trig function + * epsilon error tolerance / precision for trig calculation * * returns: - * real value result of trig function on q with error epsilon + * real value result of trig function on q with error epsilon */ NUMBER * qcas(NUMBER *q, NUMBER *epsilon) { - NUMBER *sin; /* sin(x) */ - NUMBER *tsin; /* sin(x) rounded to nearest epsilon multiple */ - NUMBER *cos; /* cos(x) */ - NUMBER *tcos; /* cos(x) rounded to nearest epsilon multiple */ - NUMBER *res; - long n; + NUMBER *sin; /* sin(x) */ + NUMBER *tsin; /* sin(x) rounded to nearest epsilon multiple */ + NUMBER *cos; /* cos(x) */ + NUMBER *tcos; /* cos(x) rounded to nearest epsilon multiple */ + NUMBER *res; + long n; - /* - * firewall - */ - if (qiszero(epsilon)) { - math_error("Zero epsilon value for cosine"); - not_reached(); - } + /* + * firewall + */ + if (qiszero(epsilon)) { + math_error("Zero epsilon value for cosine"); + not_reached(); + } - /* - * case 0: quick return 1 - */ - if (qiszero(q)) { - return qlink(&_qone_); - } + /* + * case 0: quick return 1 + */ + if (qiszero(q)) { + return qlink(&_qone_); + } - /* - * case epsilon > 1: quick return 0 - */ - n = -qilog2(epsilon); - if (n < 0) { - return qlink(&_qzero_); - } + /* + * case epsilon > 1: quick return 0 + */ + n = -qilog2(epsilon); + if (n < 0) { + return qlink(&_qzero_); + } - /* - * compute cosine and sine - */ - qsincos(q, n + 2, &sin, &cos); - tcos = qmappr(cos, epsilon, conf->triground); - qfree(cos); - tsin = qmappr(sin, epsilon, conf->triground); - qfree(sin); - res = qqadd(tcos, tsin); - qfree(tcos); - qfree(tsin); + /* + * compute cosine and sine + */ + qsincos(q, n + 2, &sin, &cos); + tcos = qmappr(cos, epsilon, conf->triground); + qfree(cos); + tsin = qmappr(sin, epsilon, conf->triground); + qfree(sin); + res = qqadd(tcos, tsin); + qfree(tcos); + qfree(tsin); - /* - * return trigonometric result - */ - return res; + /* + * return trigonometric result + */ + return res; } diff --git a/quickhash.c b/quickhash.c index a39529c..d6c5f3a 100644 --- a/quickhash.c +++ b/quickhash.c @@ -2,9 +2,9 @@ * quickhash - quickly hash a calc value using a 32-bit FNV-0 hash * * WARNING: General use of FNV-0 hash is not recommended. Calc uses FNV-0 - * for a specific You should use FNV-1a hash instead. See: + * for a specific You should use FNV-1a hash instead. See: * - * http://www.isthe.com/chongo/tech/comp/fnv/index.html + * http://www.isthe.com/chongo/tech/comp/fnv/index.html * * Copyright (C) 1999-2007,2014,2021-2023 Landon Curt Noll * @@ -14,7 +14,7 @@ * * 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 + * 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 @@ -22,16 +22,16 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/03/04 11:34:23 - * File existed as early as: 1995 + * Under source code control: 1995/03/04 11:34:23 + * File existed as early as: 1995 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * NOTE: This file does not contain a hash interface. It is used by - * associative arrays and other internal processes. + * associative arrays and other internal processes. */ @@ -41,7 +41,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* @@ -70,14 +70,14 @@ S_FUNC QCKHASH blk_hash(BLOCK *blk, QCKHASH val); * The basis of this hash algorithm was taken from an idea sent * as reviewer comments to the IEEE POSIX P1003.2 committee by: * - * Phong Vo (http://www.research.att.com/info/kpv/) - * Glenn Fowler (http://www.research.att.com/~gsf/) + * Phong Vo (http://www.research.att.com/info/kpv/) + * Glenn Fowler (http://www.research.att.com/~gsf/) * * In a subsequent ballot round: * - * Landon Curt Noll (http://www.isthe.com/chongo/) + * Landon Curt Noll (http://www.isthe.com/chongo/) * - * improved on their algorithm. Some people tried this hash + * improved on their algorithm. Some people tried this hash * and found that it worked rather well. In an Email message * to Landon, they named it ``Fowler/Noll/Vo'' or the FNV hash. * @@ -85,28 +85,28 @@ S_FUNC QCKHASH blk_hash(BLOCK *blk, QCKHASH val); * collision rate. The FNV speed allows one to quickly hash lots * of data while maintaining a reasonable collision rate. See: * - * http://www.isthe.com/chongo/tech/comp/fnv/index.html + * http://www.isthe.com/chongo/tech/comp/fnv/index.html * * for more details as well as other forms of the FNV hash. * * given: - * x the value to hash (must not be longer than 32 bits) - * val previous QCKHASH value + * x the value to hash (must not be longer than 32 bits) + * val previous QCKHASH value * * returns: - * the next 32 bit QCKHASH + * the next 32 bit QCKHASH * * Example: - * QCKHASH val; - * int x; + * QCKHASH val; + * int x; * - * quasi_fnv(x, val); + * quasi_fnv(x, val); * * NOTE: The (x) argument may be an expression such as something with - * a ++ or --. The macro must only use (x) once. + * a ++ or --. The macro must only use (x) once. * * NOTE: The (val) argument just be a lvalue / something to which - * a value can be assigned. + * a value can be assigned. * * The careful observer will note that (x) need not be a simple * octet. This is not a bug, but a feature. The FNV hash was @@ -118,7 +118,7 @@ S_FUNC QCKHASH blk_hash(BLOCK *blk, QCKHASH val); * * The 32-bit FNV-0 hash does a very good job in producing * a 32 bit hash arrays of octets in a short amount of time. - * It is not bad for hashing calc data as well. So doing a + * It is not bad for hashing calc data as well. So doing a * quick and dirty job of hashing on a part of a calc value * is all that calc really needs. * @@ -139,8 +139,8 @@ S_FUNC QCKHASH blk_hash(BLOCK *blk, QCKHASH val); #else #define quasi_fnv(x,val) ( \ ((val) += (((QCKHASH)(val)<<1) + ((QCKHASH)(val)<<4) + \ - ((QCKHASH)(val)<<7) + ((QCKHASH)(val)<<8) + \ - ((QCKHASH)(val)<<24))), \ + ((QCKHASH)(val)<<7) + ((QCKHASH)(val)<<8) + \ + ((QCKHASH)(val)<<24))), \ ((val) ^= (QCKHASH)(x)) \ ) #endif @@ -150,11 +150,11 @@ S_FUNC QCKHASH blk_hash(BLOCK *blk, QCKHASH val); * fnv_qhash - compute the next 32-bit FNV-0 hash given a NUMBER * * given: - * q pointer to a NUMBER - * val previous QCKHASH value + * q pointer to a NUMBER + * val previous QCKHASH value * * returns: - * the next 32 bit QCKHASH + * the next 32 bit QCKHASH */ #define fnv_qhash(q,val) \ (qisint(q) ? fnv_zhash((q)->num, (val)) : \ @@ -165,11 +165,11 @@ S_FUNC QCKHASH blk_hash(BLOCK *blk, QCKHASH val); * fnv_chash - compute the next 32-bit FNV-0 hash given a COMPLEX * * given: - * c pointer to a COMPLEX - * val previous QCKHASH value + * c pointer to a COMPLEX + * val previous QCKHASH value * * returns: - * the next 32 bit QCKHASH + * the next 32 bit QCKHASH */ #define fnv_chash(c,val) \ (cisreal(c) ? fnv_qhash((c)->real, (val)) : \ @@ -183,58 +183,58 @@ S_FUNC QCKHASH blk_hash(BLOCK *blk, QCKHASH val); * making associations faster. * * given: - * vp pointer to a VALUE - * val previous QCKHASH value + * vp pointer to a VALUE + * val previous QCKHASH value * * returns: - * next QCKHASH value + * next QCKHASH value */ QCKHASH hashvalue(VALUE *vp, QCKHASH val) { - switch (vp->v_type) { - case V_INT: - val += V_NUM; - return quasi_fnv(vp->v_int, val); - case V_NUM: - return fnv_qhash(vp->v_num, val); - case V_COM: - return fnv_chash(vp->v_com, val); - case V_STR: - return fnv_STRhash(vp->v_str, val); - case V_NULL: - return val; - case V_OBJ: - return objhash(vp->v_obj, val); - case V_LIST: - return listhash(vp->v_list, val); - case V_ASSOC: - return assochash(vp->v_assoc, val); - case V_MAT: - return mathash(vp->v_mat, val); - case V_FILE: - val += V_FILE; - return quasi_fnv(vp->v_file, val); - case V_RAND: - return randhash(vp->v_rand, val); - case V_RANDOM: - return randomhash(vp->v_random, val); - case V_CONFIG: - return config_hash(vp->v_config, val); - case V_HASH: - return hash_hash(vp->v_hash, val); - case V_BLOCK: - return blk_hash(vp->v_block, val); - case V_OCTET: - val += V_OCTET; - return quasi_fnv((int)*vp->v_octet, val); - case V_NBLOCK: - return blk_hash(vp->v_nblock->blk, val); - default: - math_error("Hashing unknown value"); - not_reached(); - } - return (QCKHASH)0; + switch (vp->v_type) { + case V_INT: + val += V_NUM; + return quasi_fnv(vp->v_int, val); + case V_NUM: + return fnv_qhash(vp->v_num, val); + case V_COM: + return fnv_chash(vp->v_com, val); + case V_STR: + return fnv_STRhash(vp->v_str, val); + case V_NULL: + return val; + case V_OBJ: + return objhash(vp->v_obj, val); + case V_LIST: + return listhash(vp->v_list, val); + case V_ASSOC: + return assochash(vp->v_assoc, val); + case V_MAT: + return mathash(vp->v_mat, val); + case V_FILE: + val += V_FILE; + return quasi_fnv(vp->v_file, val); + case V_RAND: + return randhash(vp->v_rand, val); + case V_RANDOM: + return randomhash(vp->v_random, val); + case V_CONFIG: + return config_hash(vp->v_config, val); + case V_HASH: + return hash_hash(vp->v_hash, val); + case V_BLOCK: + return blk_hash(vp->v_block, val); + case V_OCTET: + val += V_OCTET; + return quasi_fnv((int)*vp->v_octet, val); + case V_NBLOCK: + return blk_hash(vp->v_nblock->blk, val); + default: + math_error("Hashing unknown value"); + not_reached(); + } + return (QCKHASH)0; } @@ -244,13 +244,13 @@ hashvalue(VALUE *vp, QCKHASH val) S_FUNC QCKHASH assochash(ASSOC *ap, QCKHASH val) { - /* - * XXX - maybe we should hash the first few and last few values??? - * Perhaps we should hash associations in a different but - * fast way? - */ + /* + * XXX - maybe we should hash the first few and last few values??? + * Perhaps we should hash associations in a different but + * fast way? + */ val += V_ASSOC; - return quasi_fnv(ap->a_count, val); + return quasi_fnv(ap->a_count, val); } @@ -260,23 +260,23 @@ assochash(ASSOC *ap, QCKHASH val) S_FUNC QCKHASH listhash(LIST *lp, QCKHASH val) { - /* - * hash small lists - */ - switch (lp->l_count) { - case 0: - /* empty list hashes to just V_LIST */ - return V_LIST+val; - case 1: - /* single element list hashes just that element */ - return hashvalue(&lp->l_first->e_value, V_LIST+val); - } + /* + * hash small lists + */ + switch (lp->l_count) { + case 0: + /* empty list hashes to just V_LIST */ + return V_LIST+val; + case 1: + /* single element list hashes just that element */ + return hashvalue(&lp->l_first->e_value, V_LIST+val); + } - /* - * multi element list hashes the first and last elements - */ - return hashvalue(&lp->l_first->e_value, - hashvalue(&lp->l_last->e_value, V_LIST+val)); + /* + * multi element list hashes the first and last elements + */ + return hashvalue(&lp->l_first->e_value, + hashvalue(&lp->l_last->e_value, V_LIST+val)); } @@ -286,47 +286,47 @@ listhash(LIST *lp, QCKHASH val) S_FUNC QCKHASH mathash(MATRIX *m, QCKHASH val) { - long skip; - long i; - VALUE *vp; + long skip; + long i; + VALUE *vp; - /* - * hash size parts of the matrix - */ - val += V_MAT; - quasi_fnv(m->m_dim, val); - quasi_fnv(m->m_size, val); + /* + * hash size parts of the matrix + */ + val += V_MAT; + quasi_fnv(m->m_dim, val); + quasi_fnv(m->m_size, val); - /* - * hash the matrix index bounds - */ - for (i = m->m_dim - 1; i >= 0; i--) { - quasi_fnv(m->m_min[i], val); - quasi_fnv(m->m_max[i], val); - } + /* + * hash the matrix index bounds + */ + for (i = m->m_dim - 1; i >= 0; i--) { + quasi_fnv(m->m_min[i], val); + quasi_fnv(m->m_max[i], val); + } - /* - * hash the first 16 elements - */ - vp = m->m_table; - for (i = 0; ((i < m->m_size) && (i < 16)); i++) { - val = hashvalue(vp++, val); - } + /* + * hash the first 16 elements + */ + vp = m->m_table; + for (i = 0; ((i < m->m_size) && (i < 16)); i++) { + val = hashvalue(vp++, val); + } - /* - * hash 10 more elements if they exist - */ - i = 16; - if (i < m->m_size) { - vp = (VALUE *)&m->m_table[i]; - skip = (m->m_size / 11) + 1; - while (i < m->m_size) { - val = hashvalue(vp, val); - i += skip; - vp += skip; - } - } - return val; + /* + * hash 10 more elements if they exist + */ + i = 16; + if (i < m->m_size) { + vp = (VALUE *)&m->m_table[i]; + skip = (m->m_size / 11) + 1; + while (i < m->m_size) { + val = hashvalue(vp, val); + i += skip; + vp += skip; + } + } + return val; } @@ -336,14 +336,14 @@ mathash(MATRIX *m, QCKHASH val) S_FUNC QCKHASH objhash(OBJECT *op, QCKHASH val) { - int i; + int i; - quasi_fnv(op->o_actions->oa_index, val); + quasi_fnv(op->o_actions->oa_index, val); - i = op->o_actions->oa_count; - while (--i >= 0) - val = hashvalue(&op->o_table[i], val); - return val; + i = op->o_actions->oa_count; + while (--i >= 0) + val = hashvalue(&op->o_table[i], val); + return val; } @@ -351,31 +351,31 @@ objhash(OBJECT *op, QCKHASH val) * randhash - return a trivial hash for an s100 state * * given: - * state - state to hash + * state - state to hash * * returns: - * trivial hash integer + * trivial hash integer */ S_FUNC QCKHASH randhash(RAND *r, QCKHASH val) { - /* - * hash the RAND state - */ - if (!r->seeded) { - /* unseeded state hashes to V_RAND */ - return V_RAND+val; - } else { - /* hash control values */ - val += V_RAND; - quasi_fnv(r->j, val); - quasi_fnv(r->k, val); - quasi_fnv(r->bits, val); - quasi_fnv(r->need_to_skip, val); + /* + * hash the RAND state + */ + if (!r->seeded) { + /* unseeded state hashes to V_RAND */ + return V_RAND+val; + } else { + /* hash control values */ + val += V_RAND; + quasi_fnv(r->j, val); + quasi_fnv(r->k, val); + quasi_fnv(r->bits, val); + quasi_fnv(r->need_to_skip, val); - /* hash the state arrays */ - return fnv_fullhash(&r->buffer[0], SLEN+SCNT+SHUFLEN, val); - } + /* hash the state arrays */ + return fnv_fullhash(&r->buffer[0], SLEN+SCNT+SHUFLEN, val); + } } @@ -383,33 +383,33 @@ randhash(RAND *r, QCKHASH val) * randomhash - return a trivial hash for a Blum state * * given: - * state - state to hash + * state - state to hash * * returns: - * trivial hash integer + * trivial hash integer */ S_FUNC QCKHASH randomhash(RANDOM *state, QCKHASH val) { - /* - * unseeded RANDOM state hashes to V_RANDOM - */ - if (!state->seeded) { - return V_RANDOM+val; - } + /* + * unseeded RANDOM state hashes to V_RANDOM + */ + if (!state->seeded) { + return V_RANDOM+val; + } - /* - * hash a seeded RANDOM state - */ - val += V_RANDOM; - quasi_fnv(state->buffer+state->bits, val); - if (state->r.v != NULL) { - val = fnv_zhash(state->r, val); - } - if (state->n.v != NULL) { - val = fnv_zhash(state->n, val); - } - return val; + /* + * hash a seeded RANDOM state + */ + val += V_RANDOM; + quasi_fnv(state->buffer+state->bits, val); + if (state->r.v != NULL) { + val = fnv_zhash(state->r, val); + } + if (state->n.v != NULL) { + val = fnv_zhash(state->n, val); + } + return val; } @@ -419,99 +419,99 @@ randomhash(RANDOM *state, QCKHASH val) S_FUNC QCKHASH config_hash(CONFIG *cfg, QCKHASH val) { - USB32 value; /* value to hash from hash elements */ + USB32 value; /* value to hash from hash elements */ - /* - * build up a scalar value - * - * We will rotate a value left 5 bits and xor in each scalar element - */ - value = cfg->outmode; - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->outmode); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->outmode2); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->outdigits); - /* epsilon is handled out of order */ - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->epsilonprec); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->traceflags); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->maxprint); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->mul2); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->sq2); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->pow2); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->redc2); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->tilde_ok); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->tilde_space); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->tab_ok); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->quomod); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->quo); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->mod); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->sqrt); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->appr); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->cfappr); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->cfsim); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->outround); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->round); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->triground); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->leadzero); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->fullzero); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->maxscancount); - /* prompt1 is handled out of order */ - /* prompt2 is handled out of order */ - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkmaxprint); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkverbose); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkbase); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkfmt); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->calc_debug); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->resource_debug); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->user_debug); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->verbose_quit); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->ctrl_d); - /* program is handled out of order */ - /* basename is handled out of order */ - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->windows); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->cygwin); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->compile_custom); - if (cfg->allow_custom != NULL && *(cfg->allow_custom)) { - value = (((value>>5) | (value<<27)) ^ (USB32)true); - } else { - value = (((value>>5) | (value<<27)) ^ (USB32)false); - } - /* version is handled out of order */ + /* + * build up a scalar value + * + * We will rotate a value left 5 bits and xor in each scalar element + */ + value = cfg->outmode; + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->outmode); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->outmode2); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->outdigits); + /* epsilon is handled out of order */ + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->epsilonprec); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->traceflags); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->maxprint); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->mul2); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->sq2); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->pow2); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->redc2); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->tilde_ok); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->tilde_space); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->tab_ok); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->quomod); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->quo); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->mod); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->sqrt); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->appr); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->cfappr); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->cfsim); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->outround); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->round); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->triground); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->leadzero); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->fullzero); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->maxscancount); + /* prompt1 is handled out of order */ + /* prompt2 is handled out of order */ + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkmaxprint); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkverbose); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkbase); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkfmt); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->calc_debug); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->resource_debug); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->user_debug); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->verbose_quit); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->ctrl_d); + /* program is handled out of order */ + /* basename is handled out of order */ + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->windows); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->cygwin); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->compile_custom); + if (cfg->allow_custom != NULL && *(cfg->allow_custom)) { + value = (((value>>5) | (value<<27)) ^ (USB32)true); + } else { + value = (((value>>5) | (value<<27)) ^ (USB32)false); + } + /* version is handled out of order */ - /* - * hash the built up scalar - */ - val += V_CONFIG; - quasi_fnv(value, val); + /* + * hash the built up scalar + */ + val += V_CONFIG; + quasi_fnv(value, val); - /* - * hash the strings and pointers if possible - */ - if (cfg->prompt1) { - val = fnv_strhash(cfg->prompt1, val); - } - if (cfg->prompt2) { - val = fnv_strhash(cfg->prompt2, val); - } - if (cfg->program) { - val = fnv_strhash(cfg->program, val); - } - if (cfg->base_name) { - val = fnv_strhash(cfg->base_name, val); - } - if (cfg->version) { - val = fnv_strhash(cfg->version, val); - } - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->baseb); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->redecl_warn); - value = (((value>>5) | (value<<27)) ^ (USB32)cfg->dupvar_warn); + /* + * hash the strings and pointers if possible + */ + if (cfg->prompt1) { + val = fnv_strhash(cfg->prompt1, val); + } + if (cfg->prompt2) { + val = fnv_strhash(cfg->prompt2, val); + } + if (cfg->program) { + val = fnv_strhash(cfg->program, val); + } + if (cfg->base_name) { + val = fnv_strhash(cfg->base_name, val); + } + if (cfg->version) { + val = fnv_strhash(cfg->version, val); + } + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->baseb); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->redecl_warn); + value = (((value>>5) | (value<<27)) ^ (USB32)cfg->dupvar_warn); - /* - * hash the epsilon if possible - */ - if (cfg->epsilon) { - val = fnv_qhash(cfg->epsilon, val); - } - return val; + /* + * hash the epsilon if possible + */ + if (cfg->epsilon) { + val = fnv_qhash(cfg->epsilon, val); + } + return val; } @@ -519,50 +519,50 @@ config_hash(CONFIG *cfg, QCKHASH val) * fnv_strhash - Fowler/Noll/Vo 32 bit hash of a null-terminated string * * given: - * ch the start of the string to hash - * val initial hash value + * ch the start of the string to hash + * val initial hash value * * returns: - * a 32 bit QCKHASH value + * a 32 bit QCKHASH value */ S_FUNC QCKHASH fnv_strhash(char *ch, QCKHASH val) { - /* - * hash each character in the string - */ - while (*ch) { - quasi_fnv(*ch++, val); - } - return val; + /* + * hash each character in the string + */ + while (*ch) { + quasi_fnv(*ch++, val); + } + return val; } /* * fnv_STRhash - Fowler/Noll/Vo 32 bit hash of a STRING * * given: - * str the string to hash - * val initial hash value + * str the string to hash + * val initial hash value * * returns: - * a 32 bit QCKHASH value + * a 32 bit QCKHASH value */ S_FUNC QCKHASH fnv_STRhash(STRING *str, QCKHASH val) { - char *ch; - long n; + char *ch; + long n; - ch = str->s_str; - n = str->s_len; + ch = str->s_str; + n = str->s_len; - /* - * hash each character in the string - */ - while (n-- > 0) { - quasi_fnv(*ch++, val); - } - return val; + /* + * hash each character in the string + */ + while (n-- > 0) { + quasi_fnv(*ch++, val); + } + return val; } @@ -570,23 +570,23 @@ fnv_STRhash(STRING *str, QCKHASH val) * fnv_fullhash - Fowler/Noll/Vo 32 bit hash of an array of HALFs * * given: - * v an array of FULLs - * len length of buffer FULLs - * val initial hash value + * v an array of FULLs + * len length of buffer FULLs + * val initial hash value * * returns: - * a 32 bit QCKHASH value + * a 32 bit QCKHASH value */ S_FUNC QCKHASH fnv_fullhash(FULL *v, LEN len, QCKHASH val) { - /* - * hash each character in the string - */ - while (len-- > 0) { - quasi_fnv(*v++, val); - } - return val; + /* + * hash each character in the string + */ + while (len-- > 0) { + quasi_fnv(*v++, val); + } + return val; } @@ -594,47 +594,47 @@ fnv_fullhash(FULL *v, LEN len, QCKHASH val) * fnv_zhash - Fowler/Noll/Vo 32 bit hash of ZVALUE * * given: - * z a ZVALUE - * val initial hash value + * z a ZVALUE + * val initial hash value * * returns: - * a 32 bit QCKHASH value + * a 32 bit QCKHASH value */ S_FUNC QCKHASH fnv_zhash(ZVALUE z, QCKHASH val) { - LEN n; - HALF *hp; + LEN n; + HALF *hp; #if BASEB == 16 - FULL f; + FULL f; #endif - /* - * hash the sign - */ - val += V_NUM; - quasi_fnv(z.sign, val); + /* + * hash the sign + */ + val += V_NUM; + quasi_fnv(z.sign, val); - n = z.len; - hp = z.v; + n = z.len; + hp = z.v; #if BASEB == 16 - while (n > 1) { - f = (FULL) *hp++; - f |= (FULL) *hp++ << BASEB; - quasi_fnv(f, val); - n -= 2; - } - if (n) { - quasi_fnv(*hp, val); - } + while (n > 1) { + f = (FULL) *hp++; + f |= (FULL) *hp++ << BASEB; + quasi_fnv(f, val); + n -= 2; + } + if (n) { + quasi_fnv(*hp, val); + } #else - while (n-- > 0) { - quasi_fnv(*hp, val); - ++hp; - } + while (n-- > 0) { + quasi_fnv(*hp, val); + ++hp; + } #endif - return val; + return val; } @@ -642,24 +642,24 @@ fnv_zhash(ZVALUE z, QCKHASH val) * hash_hash - Fowler/Noll/Vo 32 bit hash of a block * * given: - * hash the HASH to quickhash - * val initial hash value + * hash the HASH to quickhash + * val initial hash value * * returns: - * a 32 bit QCKHASH value + * a 32 bit QCKHASH value */ S_FUNC QCKHASH hash_hash(HASH *hash, QCKHASH val) { - int i; + int i; - /* - * hash each USB8 in the BLOCK - */ - for (i=0; i < hash->unionsize; ++i) { - quasi_fnv(hash->h_union.data[i], val); - } - return val; + /* + * hash each USB8 in the BLOCK + */ + for (i=0; i < hash->unionsize; ++i) { + quasi_fnv(hash->h_union.data[i], val); + } + return val; } @@ -667,27 +667,27 @@ hash_hash(HASH *hash, QCKHASH val) * blk_hash - Fowler/Noll/Vo 32 bit hash of a block * * given: - * blk the BLOCK to hash - * val initial hash value + * blk the BLOCK to hash + * val initial hash value * * returns: - * a 32 bit QCKHASH value + * a 32 bit QCKHASH value */ S_FUNC QCKHASH blk_hash(BLOCK *blk, QCKHASH val) { - int i; + int i; - if (blk == NULL) /* block has no data */ - return val; + if (blk == NULL) /* block has no data */ + return val; - /* - * hash each USB8 in the BLOCK - */ - if (blk->datalen > 0) { - for (i=0; i < blk->datalen; ++i) { - quasi_fnv(blk->data[i], val); - } - } - return val; + /* + * hash each USB8 in the BLOCK + */ + if (blk->datalen > 0) { + for (i=0; i < blk->datalen; ++i) { + quasi_fnv(blk->data[i], val); + } + } + return val; } diff --git a/sample.README b/sample.README index 18fd30b..31e8a67 100644 --- a/sample.README +++ b/sample.README @@ -20,10 +20,10 @@ test_random usage: - test_random [bitlen [seed_string]] + test_random [bitlen [seed_string]] - bitlen number of random bits to generate (default: 128 bits) - seed_string seed using this ASCII string (default: use default seed) + bitlen number of random bits to generate (default: 128 bits) + seed_string seed using this ASCII string (default: use default seed) many_random @@ -32,7 +32,7 @@ many_random Generate many (100000) sets random bits using the Blum-Blum-Shub generator that is used by the random() and srandom() builtin functions. - Output is one set per line. Unlike test_random, the seed is not + Output is one set per line. Unlike test_random, the seed is not printed. There is no leading 0x on numbers and there is no prefix strings. The only thing printed (normally) is ASCII hex chars and newlines. @@ -47,10 +47,10 @@ many_random usage: - many_random [bitlen [seed_string]] + many_random [bitlen [seed_string]] - bitlen number of random bits per line set (default: 128 bits) - seed_string seed using this ASCII string (default: use default seed) + bitlen number of random bits per line set (default: 128 bits) + seed_string seed using this ASCII string (default: use default seed) ## Copyright (C) 1999-2007 Landon Curt Noll ## @@ -60,7 +60,7 @@ many_random ## ## 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 +## 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 @@ -68,8 +68,8 @@ many_random ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## -## Under source code control: 1997/04/19 23:15:42 -## File existed as early as: 1997 +## Under source code control: 1997/04/19 23:15:42 +## File existed as early as: 1997 ## -## chongo /\oo/\ http://www.isthe.com/chongo/ -## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +## chongo /\oo/\ http://www.isthe.com/chongo/ +## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ diff --git a/sample_many.c b/sample_many.c index 0189ff8..8cb47fd 100644 --- a/sample_many.c +++ b/sample_many.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,19 +17,19 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/04/19 22:46:49 - * File existed as early as: 1997 + * Under source code control: 1997/04/19 22:46:49 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * many_random [[bits] seed_string] + * many_random [[bits] seed_string] * - * seed_string something for which we can seed (def: default seed) - * bits number of bits to generate + * seed_string something for which we can seed (def: default seed) + * bits number of bits to generate */ @@ -42,133 +42,133 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define DEF_CNT 128 /* default number of bits to generate */ -#define RESEED 1000 /* number of random numbers to generate */ -#define MANY 100 /* number of random numbers to generate */ +#define DEF_CNT 128 /* default number of bits to generate */ +#define RESEED 1000 /* number of random numbers to generate */ +#define MANY 100 /* number of random numbers to generate */ -extern char *program; /* our name */ +extern char *program; /* our name */ int main(int argc, char **argv) { - RANDOM *prev_state; /* previous random number state */ - ZVALUE seed; /* seed for Blum-Blum-Shub */ - ZVALUE tmp; /* temp value */ - ZVALUE tmp2; /* temp value */ - ZVALUE random_val; /* random number produced */ - long cnt; /* number of bits to generate */ - char *hexstr; /* random number as hex string */ - int i; - int j; + RANDOM *prev_state; /* previous random number state */ + ZVALUE seed; /* seed for Blum-Blum-Shub */ + ZVALUE tmp; /* temp value */ + ZVALUE tmp2; /* temp value */ + ZVALUE random_val; /* random number produced */ + long cnt; /* number of bits to generate */ + char *hexstr; /* random number as hex string */ + int i; + int j; - /* - * parse args - */ - program = argv[0]; - switch (argc) { - case 3: - seed = convstr2z(argv[2]); - cnt = strtol(argv[1], NULL, 0); - break; - case 2: - seed = _zero_; /* use the default seed */ - cnt = strtol(argv[1], NULL, 0); - break; - case 1: - seed = _zero_; /* use the default seed */ - cnt = DEF_CNT; - break; - default: - fprintf(stderr, "usage: %s [[bits] seed_string]\n", program); - exit(1); - } - if (cnt <= 0) { - fprintf(stderr, "%s: cnt:%d must be > 0\n", program, (int)cnt); - exit(2); - } + /* + * parse args + */ + program = argv[0]; + switch (argc) { + case 3: + seed = convstr2z(argv[2]); + cnt = strtol(argv[1], NULL, 0); + break; + case 2: + seed = _zero_; /* use the default seed */ + cnt = strtol(argv[1], NULL, 0); + break; + case 1: + seed = _zero_; /* use the default seed */ + cnt = DEF_CNT; + break; + default: + fprintf(stderr, "usage: %s [[bits] seed_string]\n", program); + exit(1); + } + if (cnt <= 0) { + fprintf(stderr, "%s: cnt:%d must be > 0\n", program, (int)cnt); + exit(2); + } - /* - * libcalc setup - */ - libcalc_call_me_first(); + /* + * libcalc setup + */ + libcalc_call_me_first(); - /* - * reseed every so often - */ - for (j=0; j < RESEED; ++j) { + /* + * reseed every so often + */ + for (j=0; j < RESEED; ++j) { - /* - * seed the generator - */ - prev_state = zsrandom2(seed, _one_); - if (prev_state == NULL) { - math_error("previous random state is NULL"); - not_reached(); - } - randomfree(prev_state); + /* + * seed the generator + */ + prev_state = zsrandom2(seed, _one_); + if (prev_state == NULL) { + math_error("previous random state is NULL"); + not_reached(); + } + randomfree(prev_state); - /* - * generate random values forever - */ - for (i=0; i < MANY; ++i) { + /* + * generate random values forever + */ + for (i=0; i < MANY; ++i) { - /* - * generate random bits - */ - zrandom(cnt, &random_val); + /* + * generate random bits + */ + zrandom(cnt, &random_val); - /* - * convert into hex string - */ - hexstr = convz2hex(random_val); - printf("%s\n", hexstr); + /* + * convert into hex string + */ + hexstr = convz2hex(random_val); + printf("%s\n", hexstr); - /* - * free - */ - if (i < MANY-1) { - zfree(random_val); - } - free(hexstr); - } + /* + * free + */ + if (i < MANY-1) { + zfree(random_val); + } + free(hexstr); + } - /* - * increment the seed to better test different seeds - * - * NOTE: It is generally a bad idea to use the - * same random number generator to modify - * the seed. We only do this below to - * try different seeds for debugging. - * - * Don't do this in real life applications! - * - * We want to add at least 2^32 to the seed, so - * we do the effect of: - * - * seed += ((last_val<<32) + last_val); - */ - zshift(random_val, 32, &tmp); - zadd(tmp, random_val, &tmp2); - zfree(random_val); - zfree(tmp); - zadd(seed, tmp2, &tmp); - zfree(tmp2); - zfree(seed); - seed = tmp; - } + /* + * increment the seed to better test different seeds + * + * NOTE: It is generally a bad idea to use the + * same random number generator to modify + * the seed. We only do this below to + * try different seeds for debugging. + * + * Don't do this in real life applications! + * + * We want to add at least 2^32 to the seed, so + * we do the effect of: + * + * seed += ((last_val<<32) + last_val); + */ + zshift(random_val, 32, &tmp); + zadd(tmp, random_val, &tmp2); + zfree(random_val); + zfree(tmp); + zadd(seed, tmp2, &tmp); + zfree(tmp2); + zfree(seed); + seed = tmp; + } - /* - * libcalc shutdown - */ - libcalc_call_me_last(); + /* + * libcalc shutdown + */ + libcalc_call_me_last(); - /* - * all done - */ - /* exit(0); */ - return 0; + /* + * all done + */ + /* exit(0); */ + return 0; } diff --git a/sample_rand.c b/sample_rand.c index 7251226..cf502f0 100644 --- a/sample_rand.c +++ b/sample_rand.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,19 +17,19 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/04/19 22:46:49 - * File existed as early as: 1997 + * Under source code control: 1997/04/19 22:46:49 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * usage: - * test_random [[bits] seed_string] + * test_random [[bits] seed_string] * - * seed_string something for which we can seed (def: default seed) - * bits number of bits to generate + * seed_string something for which we can seed (def: default seed) + * bits number of bits to generate */ @@ -42,78 +42,78 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define DEF_CNT 128 /* default number of bits to generate */ +#define DEF_CNT 128 /* default number of bits to generate */ -extern char *program; /* our name */ +extern char *program; /* our name */ int main(int argc, char **argv) { - RANDOM *prev_state; /* previous random number state */ - ZVALUE seed; /* seed for Blum-Blum-Shub */ - ZVALUE random_val; /* random number produced */ - long cnt; /* number of bits to generate */ - char *hexstr; /* random number as hex string */ + RANDOM *prev_state; /* previous random number state */ + ZVALUE seed; /* seed for Blum-Blum-Shub */ + ZVALUE random_val; /* random number produced */ + long cnt; /* number of bits to generate */ + char *hexstr; /* random number as hex string */ - /* - * parse args - */ - program = argv[0]; - switch (argc) { - case 3: - seed = convstr2z(argv[2]); - cnt = strtol(argv[1], NULL, 0); - break; - case 2: - seed = _zero_; /* use the default seed */ - cnt = strtol(argv[1], NULL, 0); - break; - case 1: - seed = _zero_; /* use the default seed */ - cnt = DEF_CNT; - break; - default: - fprintf(stderr, "usage: %s [[bits] seed_string]\n", program); - exit(1); - } - if (cnt <= 0) { - fprintf(stderr, "%s: cnt:%d must be > 0\n", program, (int)cnt); - exit(2); - } - printf("seed= 0x%s\n", convz2hex(seed)); + /* + * parse args + */ + program = argv[0]; + switch (argc) { + case 3: + seed = convstr2z(argv[2]); + cnt = strtol(argv[1], NULL, 0); + break; + case 2: + seed = _zero_; /* use the default seed */ + cnt = strtol(argv[1], NULL, 0); + break; + case 1: + seed = _zero_; /* use the default seed */ + cnt = DEF_CNT; + break; + default: + fprintf(stderr, "usage: %s [[bits] seed_string]\n", program); + exit(1); + } + if (cnt <= 0) { + fprintf(stderr, "%s: cnt:%d must be > 0\n", program, (int)cnt); + exit(2); + } + printf("seed= 0x%s\n", convz2hex(seed)); - /* - * libcalc setup - */ - libcalc_call_me_first(); + /* + * libcalc setup + */ + libcalc_call_me_first(); - /* - * seed the generator - */ - prev_state = zsrandom2(seed, _ten_); - if (prev_state == NULL) { - math_error("previous random state is NULL"); - not_reached(); - } + /* + * seed the generator + */ + prev_state = zsrandom2(seed, _ten_); + if (prev_state == NULL) { + math_error("previous random state is NULL"); + not_reached(); + } - /* - * generate random bits - */ - zrandom(cnt, &random_val); + /* + * generate random bits + */ + zrandom(cnt, &random_val); - /* - * convert into hex string - */ - hexstr = convz2hex(random_val); - printf("random= 0x%s\n", hexstr); + /* + * convert into hex string + */ + hexstr = convz2hex(random_val); + printf("random= 0x%s\n", hexstr); - /* - * all done - */ - /* exit(0); */ - return 0; + /* + * all done + */ + /* exit(0); */ + return 0; } diff --git a/seed.c b/seed.c index 617de6f..7c201bd 100644 --- a/seed.c +++ b/seed.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,20 +17,20 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1999/10/03 10:06:53 - * File existed as early as: 1999 + * Under source code control: 1999/10/03 10:06:53 + * File existed as early as: 1999 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * Generate a quasi-random seed based on system and process information. * * NOTE: This is not a good source of chaotic data. The LavaRnd - * system does a much better job of that. See: + * system does a much better job of that. See: * - * http://www.LavaRnd.org/ + * http://www.LavaRnd.org/ */ @@ -54,14 +54,14 @@ /* * PORTING NOTE: - * These includes are used by pseudo_seed(). If for some - * reason some of these include files are missing or damaged - * on your system, feel free to remove them (and the related - * calls inside pseudo_seed()), add or replace them. The - * pseudo_seed() function just needs to gather a bunch of - * information about the process and system state so the - * loss or inclusion of a few other calls should not hurt - * that much. + * These includes are used by pseudo_seed(). If for some + * reason some of these include files are missing or damaged + * on your system, feel free to remove them (and the related + * calls inside pseudo_seed()), add or replace them. The + * pseudo_seed() function just needs to gather a bunch of + * information about the process and system state so the + * loss or inclusion of a few other calls should not hurt + * that much. */ #include #include @@ -87,7 +87,7 @@ # include /* NOTE: RANDOM_CNT should remain 32 to circular shift 31-bit returns */ # define RANDOM_CNT (32) /* random() call repeat and circular shift */ -# define INITSTATE_SIZE (256) /* initstate pool size */ +# define INITSTATE_SIZE (256) /* initstate pool size */ #endif /* HAVE_STDLIB_H */ #include @@ -132,7 +132,7 @@ #include "have_statfs.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* @@ -140,17 +140,17 @@ */ #if defined(HAVE_B64) typedef USB64 hash64; -static hash64 prev_hash64 = 0; /* previous pseudo_seed() return or 0 */ +static hash64 prev_hash64 = 0; /* previous pseudo_seed() return or 0 */ #else struct s_hash64 { - USB32 w32[2]; + USB32 w32[2]; }; typedef struct s_hash64 hash64; -static hash64 prev_hash64 = { 0, 0 }; /* previous pseudo_seed() return or 0 */ +static hash64 prev_hash64 = { 0, 0 }; /* previous pseudo_seed() return or 0 */ #endif #if defined(HAVE_ENVIRON) -extern char **environ; /* user environment */ +extern char **environ; /* user environment */ #endif /* HAVE_ENVIRON */ #if defined(HAVE_ARC4RANDOM) @@ -173,7 +173,7 @@ static FULL call_count = 0; * 0 hash value. The virgin value that we use below is the hash value * that we would get from following 32 ASCII characters: * - * chongo /\../\ + * chongo /\../\ * * Note that the \'s above are not back-slashing escape characters. * They are literal ASCII backslash 0x5c characters. @@ -215,26 +215,26 @@ static FULL call_count = 0; S_FUNC hash64 initial_private_hash64(void) { - hash64 hval; /* current hash value */ + hash64 hval; /* current hash value */ #if defined(HAVE_B64) - hval = PRIVATE_64_BASIS; + hval = PRIVATE_64_BASIS; #else /* HAVE_B64 */ - USB32 val[4]; /* hash value in base 2^16 */ + USB32 val[4]; /* hash value in base 2^16 */ - /* hash each octet of the buffer */ - val[0] = PRIVATE_64_BASIS_0; - val[1] = PRIVATE_64_BASIS_1; - val[2] = PRIVATE_64_BASIS_2; - val[3] = PRIVATE_64_BASIS_3; + /* hash each octet of the buffer */ + val[0] = PRIVATE_64_BASIS_0; + val[1] = PRIVATE_64_BASIS_1; + val[2] = PRIVATE_64_BASIS_2; + val[3] = PRIVATE_64_BASIS_3; - /* convert to hash64 */ - /* hval.w32[1] = 0xffff&(val[3]<<16)+val[2]; */ - hval.w32[1] = (val[3]<<16) + val[2]; - hval.w32[0] = (val[1]<<16) + val[0]; + /* convert to hash64 */ + /* hval.w32[1] = 0xffff&(val[3]<<16)+val[2]; */ + hval.w32[1] = (val[3]<<16) + val[2]; + hval.w32[0] = (val[1]<<16) + val[0]; #endif /* HAVE_B64 */ - /* return our initial hash value */ - return hval; + /* return our initial hash value */ + return hval; } @@ -246,14 +246,14 @@ initial_private_hash64(void) * The basis of this hash algorithm was taken from an idea sent * as reviewer comments to the IEEE POSIX P1003.2 committee by: * - * Phong Vo (http://www.research.att.com/info/kpv/) - * Glenn Fowler (http://www.research.att.com/~gsf/) + * Phong Vo (http://www.research.att.com/info/kpv/) + * Glenn Fowler (http://www.research.att.com/~gsf/) * * In a subsequent ballot round: * - * Landon Curt Noll (http://www.isthe.com/chongo/) + * Landon Curt Noll (http://www.isthe.com/chongo/) * - * improved on their algorithm. Some people tried this hash + * improved on their algorithm. Some people tried this hash * and found that it worked rather well. In an Email message * to Landon, they named it ``Fowler/Noll/Vo'' or the FNV hash. * @@ -261,95 +261,95 @@ initial_private_hash64(void) * collision rate. The FNV speed allows one to quickly hash lots * of data while maintaining a reasonable collision rate. See: * - * http://www.isthe.com/chongo/tech/comp/fnv/ + * http://www.isthe.com/chongo/tech/comp/fnv/ * * for more details as well as other forms of the FNV hash. * * NOTE: For general hash functions, we recommend using the - * FNV-1a hash function. The use of FNV-1 is kept - * for backwards compatibility purposes and because - * the use of FNV-1 in this special purpose, suffices. + * FNV-1a hash function. The use of FNV-1 is kept + * for backwards compatibility purposes and because + * the use of FNV-1 in this special purpose, suffices. * * input: - * buf - start of buffer to hash - * len - length of buffer in octets - * hval - the hash value to modify + * buf - start of buffer to hash + * len - length of buffer in octets + * hval - the hash value to modify * * returns: - * 64 bit hash as a static hash64 structure + * 64 bit hash as a static hash64 structure */ S_FUNC hash64 private_hash64_buf(hash64 hval, char *buf, unsigned len) { #if !defined(HAVE_B64) - USB32 val[4]; /* hash value in base 2^16 */ - USB32 tmp[4]; /* tmp 64 bit value */ + USB32 val[4]; /* hash value in base 2^16 */ + USB32 tmp[4]; /* tmp 64 bit value */ #endif /* HAVE_B64 */ - char *buf_end = buf+len; /* beyond end of hash area */ + char *buf_end = buf+len; /* beyond end of hash area */ #if defined(HAVE_B64) - /* hash each octet of the buffer */ - for (; buf < buf_end; ++buf) { + /* hash each octet of the buffer */ + for (; buf < buf_end; ++buf) { - /* multiply by 1099511628211ULL mod 2^64 using 64 bit longs */ - hval *= (hash64)1099511628211ULL; + /* multiply by 1099511628211ULL mod 2^64 using 64 bit longs */ + hval *= (hash64)1099511628211ULL; - /* xor the bottom with the current octet */ - hval ^= (hash64)(*buf); - } + /* xor the bottom with the current octet */ + hval ^= (hash64)(*buf); + } #else /* HAVE_B64 */ - /* load val array from hval argument */ - val[0] = hval.w32[0] & 0xffff; - val[1] = (hval.w32[0]>>16) & 0xffff; - val[2] = hval.w32[1] & 0xffff; - val[3] = (hval.w32[1]>>16) & 0xffff; + /* load val array from hval argument */ + val[0] = hval.w32[0] & 0xffff; + val[1] = (hval.w32[0]>>16) & 0xffff; + val[2] = hval.w32[1] & 0xffff; + val[3] = (hval.w32[1]>>16) & 0xffff; - for (; buf < buf_end; ++buf) { + for (; buf < buf_end; ++buf) { - /* - * multiply by 1099511628211 mod 2^64 using 32 bit longs - * - * Using 1099511628211, we have the following digits base 2^16: - * - * 0x0 0x100 0x0 0x1b3 - */ - /* multiply by the lowest order digit base 2^16 */ - tmp[0] = val[0] * 0x1b3; - tmp[1] = val[1] * 0x1b3; - tmp[1] = val[2] * 0x1b3; - tmp[3] = val[3] * 0x1b3; - /* multiply by the other non-zero digit */ - tmp[2] += val[0] << 8; /* tmp[2] += val[0] * 0x100 */ - tmp[3] += val[1] << 8; /* tmp[1] += val[1] * 0x100 */ - /* propagate carries */ - tmp[1] += (tmp[0] >> 16); - val[0] = tmp[0] & 0xffff; - tmp[2] += (tmp[1] >> 16); - val[1] = tmp[1] & 0xffff; - val[3] = tmp[3] + (tmp[2] >> 16); - val[2] = tmp[2] & 0xffff; - /* - * Doing a val[3] &= 0xffff; is not really needed since it simply - * removes multiples of 2^64. We can discard these excess bits - * outside of the loop when we convert to hash64. - */ + /* + * multiply by 1099511628211 mod 2^64 using 32 bit longs + * + * Using 1099511628211, we have the following digits base 2^16: + * + * 0x0 0x100 0x0 0x1b3 + */ + /* multiply by the lowest order digit base 2^16 */ + tmp[0] = val[0] * 0x1b3; + tmp[1] = val[1] * 0x1b3; + tmp[1] = val[2] * 0x1b3; + tmp[3] = val[3] * 0x1b3; + /* multiply by the other non-zero digit */ + tmp[2] += val[0] << 8; /* tmp[2] += val[0] * 0x100 */ + tmp[3] += val[1] << 8; /* tmp[1] += val[1] * 0x100 */ + /* propagate carries */ + tmp[1] += (tmp[0] >> 16); + val[0] = tmp[0] & 0xffff; + tmp[2] += (tmp[1] >> 16); + val[1] = tmp[1] & 0xffff; + val[3] = tmp[3] + (tmp[2] >> 16); + val[2] = tmp[2] & 0xffff; + /* + * Doing a val[3] &= 0xffff; is not really needed since it simply + * removes multiples of 2^64. We can discard these excess bits + * outside of the loop when we convert to hash64. + */ - /* xor the bottom with the current octet */ - val[0] ^= (USB32)(*buf); - } + /* xor the bottom with the current octet */ + val[0] ^= (USB32)(*buf); + } - /* convert to hash64 */ - /* hval.w32[1] = 0xffff&(val[3]<<16)+val[2]; */ - hval.w32[1] = (val[3]<<16) + val[2]; - hval.w32[0] = (val[1]<<16) + val[0]; + /* convert to hash64 */ + /* hval.w32[1] = 0xffff&(val[3]<<16)+val[2]; */ + hval.w32[1] = (val[3]<<16) + val[2]; + hval.w32[0] = (val[1]<<16) + val[0]; #endif /* HAVE_B64 */ - /* return our hash value */ - return hval; + /* return our hash value */ + return hval; } @@ -359,18 +359,18 @@ private_hash64_buf(hash64 hval, char *buf, unsigned len) * Generate a quasi-random seed based on system and process information. * * NOTE: This is not a good source of chaotic data. The LavaRnd - * system does a much better job of that. See: + * system does a much better job of that. See: * - * http://www.LavaRnd.org/ + * http://www.LavaRnd.org/ * * PORTING NOTE: * If when porting this code to your system and something * won't compile, just remove that line or replace it with * some other system call. We don't have to have every call - * operating below. We only want to hash the resulting data. + * operating below. We only want to hash the resulting data. * * returns: - * a pseudo-seed as a NUMBER over the range [0, 2^64) + * a pseudo-seed as a NUMBER over the range [0, 2^64) */ NUMBER * pseudo_seed(void) @@ -381,149 +381,149 @@ pseudo_seed(void) struct { #if defined(HAVE_GETTIME) # if defined(CLOCK_REALTIME) - struct timespec realtime; /* POSIX realtime clock */ + struct timespec realtime; /* POSIX realtime clock */ # endif #endif #if defined(HAVE_GETPRID) - prid_t getprid; /* project ID */ + prid_t getprid; /* project ID */ #endif #if defined(HAVE_URANDOM) - int urandom_fd; /* open descriptor for /dev/urandom */ - int urandom_ret; /* read() of /dev/random */ - char urandom_pool[DEV_URANDOM_POOL]; /* /dev/urandom data pool */ + int urandom_fd; /* open descriptor for /dev/urandom */ + int urandom_ret; /* read() of /dev/random */ + char urandom_pool[DEV_URANDOM_POOL]; /* /dev/urandom data pool */ #endif #if defined(HAVE_SYS_TIME_H) - struct timeval tp; /* time of day */ + struct timeval tp; /* time of day */ #endif - pid_t getpid; /* process ID */ + pid_t getpid; /* process ID */ #if !defined(_WIN32) && !defined(_WIN64) - pid_t getppid; /* parent process ID */ + pid_t getppid; /* parent process ID */ #endif #if defined(HAVE_UID_T) - uid_t getuid; /* real user ID */ - uid_t geteuid; /* effective user ID */ - gid_t getgid; /* real group ID */ - gid_t getegid; /* effective group ID */ + uid_t getuid; /* real user ID */ + uid_t geteuid; /* effective user ID */ + gid_t getgid; /* real group ID */ + gid_t getegid; /* effective group ID */ #endif - struct stat stat_dot; /* stat of "." */ - struct stat stat_dotdot; /* stat of ".." */ - struct stat stat_tmp; /* stat of "/tmp" */ - struct stat stat_root; /* stat of "/" */ - struct stat stat_tty; /* stat of "/dev/tty" */ - struct stat stat_console; /* stat of "/dev/console" */ - struct stat fstat_stdin; /* stat of stdin */ - struct stat fstat_stdout; /* stat of stdout */ - struct stat fstat_stderr; /* stat of stderr */ - struct stat stat_zero; /* stat of "/dev/zero" */ - struct stat stat_null; /* stat of "/dev/null" */ - struct stat stat_sh; /* stat of "/bin/sh" */ - struct stat stat_ls; /* stat of "/bin/ls" */ - /* stat of "/var/log/system.log" */ - struct stat stat_system; - /* stat of "/var/log/messages" */ - struct stat stat_messages; + struct stat stat_dot; /* stat of "." */ + struct stat stat_dotdot; /* stat of ".." */ + struct stat stat_tmp; /* stat of "/tmp" */ + struct stat stat_root; /* stat of "/" */ + struct stat stat_tty; /* stat of "/dev/tty" */ + struct stat stat_console; /* stat of "/dev/console" */ + struct stat fstat_stdin; /* stat of stdin */ + struct stat fstat_stdout; /* stat of stdout */ + struct stat fstat_stderr; /* stat of stderr */ + struct stat stat_zero; /* stat of "/dev/zero" */ + struct stat stat_null; /* stat of "/dev/null" */ + struct stat stat_sh; /* stat of "/bin/sh" */ + struct stat stat_ls; /* stat of "/bin/ls" */ + /* stat of "/var/log/system.log" */ + struct stat stat_system; + /* stat of "/var/log/messages" */ + struct stat stat_messages; #if defined(HAVE_USTAT) - struct ustat ustat_dot; /* usage stat of "." */ - struct ustat ustat_dotdot; /* usage stat of ".." */ - struct ustat ustat_tmp; /* usage stat of "/tmp" */ - struct ustat ustat_root; /* usage stat of "/" */ - struct ustat ustat_tty; /* usage stat of "/dev/tty" */ - struct ustat ustat_console; /* usage stat of "/dev/console" */ - struct ustat ustat_stdin; /* usage stat of stdin */ - struct ustat ustat_stdout; /* usage stat of stdout */ - struct ustat ustat_stderr; /* usage stat of stderr */ - struct ustat ustat_zero; /* usage stat of "/dev/zero" */ - struct ustat ustat_null; /* usage stat of "/dev/null" */ - struct ustat ustat_sh; /* usage stat of "/bin/sh" */ - struct ustat ustat_ls; /* usage stat of "/bin/ls" */ - /* usage stat of "/var/log/system.log" */ - struct ustat ustat_system; - /* usage stat of "/var/log/messages" */ - struct ustat ustat_messages; + struct ustat ustat_dot; /* usage stat of "." */ + struct ustat ustat_dotdot; /* usage stat of ".." */ + struct ustat ustat_tmp; /* usage stat of "/tmp" */ + struct ustat ustat_root; /* usage stat of "/" */ + struct ustat ustat_tty; /* usage stat of "/dev/tty" */ + struct ustat ustat_console; /* usage stat of "/dev/console" */ + struct ustat ustat_stdin; /* usage stat of stdin */ + struct ustat ustat_stdout; /* usage stat of stdout */ + struct ustat ustat_stderr; /* usage stat of stderr */ + struct ustat ustat_zero; /* usage stat of "/dev/zero" */ + struct ustat ustat_null; /* usage stat of "/dev/null" */ + struct ustat ustat_sh; /* usage stat of "/bin/sh" */ + struct ustat ustat_ls; /* usage stat of "/bin/ls" */ + /* usage stat of "/var/log/system.log" */ + struct ustat ustat_system; + /* usage stat of "/var/log/messages" */ + struct ustat ustat_messages; #endif #if defined(HAVE_STATFS) - struct statfs statfs_dot; /* filesystem stat of "." */ - struct statfs statfs_dotdot; /* filesystem stat of ".." */ - struct statfs statfs_tmp; /* filesystem stat of "/tmp" */ - struct statfs statfs_root; /* filesystem stat of "/" */ - struct statfs statfs_tty; /* filesystem stat of "/dev/tty" */ - struct statfs statfs_console; /* filesystem stat of "/dev/console" */ - struct statfs statfs_stdin; /* filesystem stat of stdin */ - struct statfs statfs_stdout; /* filesystem stat of stdout */ - struct statfs statfs_stderr; /* filesystem stat of stderr */ - struct statfs statfs_zero; /* filesystem stat of "/dev/zero" */ - struct statfs statfs_null; /* filesystem stat of "/dev/null" */ - struct statfs statfs_sh; /* filesystem stat of "/bin/sh" */ - struct statfs statfs_ls; /* filesystem stat of "/bin/ls" */ - /* filesystem stat of "/var/log/system.log" */ - struct statfs statfs_system; - /* filesystem stat of "/var/log/messages" */ - struct statfs statfs_messages; + struct statfs statfs_dot; /* filesystem stat of "." */ + struct statfs statfs_dotdot; /* filesystem stat of ".." */ + struct statfs statfs_tmp; /* filesystem stat of "/tmp" */ + struct statfs statfs_root; /* filesystem stat of "/" */ + struct statfs statfs_tty; /* filesystem stat of "/dev/tty" */ + struct statfs statfs_console; /* filesystem stat of "/dev/console" */ + struct statfs statfs_stdin; /* filesystem stat of stdin */ + struct statfs statfs_stdout; /* filesystem stat of stdout */ + struct statfs statfs_stderr; /* filesystem stat of stderr */ + struct statfs statfs_zero; /* filesystem stat of "/dev/zero" */ + struct statfs statfs_null; /* filesystem stat of "/dev/null" */ + struct statfs statfs_sh; /* filesystem stat of "/bin/sh" */ + struct statfs statfs_ls; /* filesystem stat of "/bin/ls" */ + /* filesystem stat of "/var/log/system.log" */ + struct statfs statfs_system; + /* filesystem stat of "/var/log/messages" */ + struct statfs statfs_messages; #endif #if defined(HAVE_GETSID) - pid_t getsid; /* session ID */ + pid_t getsid; /* session ID */ #endif #if defined(HAVE_GETPGID) - pid_t getpgid; /* process group ID */ + pid_t getpgid; /* process group ID */ #endif #if defined(HAVE_GETRUSAGE) - struct rusage rusage; /* resource utilization */ - struct rusage rusage_child; /* resource utilization of children */ + struct rusage rusage; /* resource utilization */ + struct rusage rusage_child; /* resource utilization of children */ #endif #if defined(HAVE_SYS_TIME_H) - struct timeval tp2; /* time of day again */ - struct tms times; /* process times */ - struct timeval times_dot[2]; /* access & mod files of "." */ - struct timeval times_dotdot[2]; /* access & mod files of ".." */ - struct timeval times_tmp[2]; /* access & mod files of "/tmp" */ - struct timeval times_root[2]; /* access & mod files of "/" */ - struct timeval times_tty[2]; /* access & mod files of "/dev/tty" */ - /* access & mod files of "/dev/console" */ - struct timeval times_console[2]; - struct timeval times_stdin[2]; /* access & mod files of "/dev/stdin" */ - /* access & mod files of "/dev/stdout" */ - struct timeval times_stdout[2]; - /* access & mod files of "/dev/stderr" */ - struct timeval times_stderr[2]; - struct timeval times_zero[2]; /* access & mod files of "/dev/zero" */ - struct timeval times_null[2]; /* access & mod files of "/dev/null" */ - struct timeval times_sh[2]; /* access & mod files of "/bin/sh" */ - struct timeval times_ls[2]; /* access & mod files of "/bin/ls" */ - /* access & mod files of "/var/log/system.log" */ - struct timeval times_system[2]; - /* access & mod files of "/var/log/messages" */ - struct timeval times_messages[2]; + struct timeval tp2; /* time of day again */ + struct tms times; /* process times */ + struct timeval times_dot[2]; /* access & mod files of "." */ + struct timeval times_dotdot[2]; /* access & mod files of ".." */ + struct timeval times_tmp[2]; /* access & mod files of "/tmp" */ + struct timeval times_root[2]; /* access & mod files of "/" */ + struct timeval times_tty[2]; /* access & mod files of "/dev/tty" */ + /* access & mod files of "/dev/console" */ + struct timeval times_console[2]; + struct timeval times_stdin[2]; /* access & mod files of "/dev/stdin" */ + /* access & mod files of "/dev/stdout" */ + struct timeval times_stdout[2]; + /* access & mod files of "/dev/stderr" */ + struct timeval times_stderr[2]; + struct timeval times_zero[2]; /* access & mod files of "/dev/zero" */ + struct timeval times_null[2]; /* access & mod files of "/dev/null" */ + struct timeval times_sh[2]; /* access & mod files of "/bin/sh" */ + struct timeval times_ls[2]; /* access & mod files of "/bin/ls" */ + /* access & mod files of "/var/log/system.log" */ + struct timeval times_system[2]; + /* access & mod files of "/var/log/messages" */ + struct timeval times_messages[2]; #endif - time_t time; /* local time */ - size_t size; /* size of this data structure */ - hash64 prev_hash64_copy; /* copy if the previous hash value */ - FULL call_count_copy; /* call count of this funcation */ - jmp_buf env; /* setjmp() context */ + time_t time; /* local time */ + size_t size; /* size of this data structure */ + hash64 prev_hash64_copy; /* copy if the previous hash value */ + FULL call_count_copy; /* call count of this funcation */ + jmp_buf env; /* setjmp() context */ #if defined(HAVE_ENVIRON) - char **environ_copy; /* copy of extern char **environ */ + char **environ_copy; /* copy of extern char **environ */ #endif /* HAVE_ENVIRON */ - char *sdata_p; /* address of this structure */ + char *sdata_p; /* address of this structure */ } sdata; /**/ #if defined(HAVE_STDLIB_H) - unsigned long tmp; /* temp holder of 31-bit random() */ - unsigned past_hash; /* prev hash or xor-folded prev hash */ - long random_before[RANDOM_CNT]; /* random() pre initstate() */ - char *initstate_ret; /* return from initstate() call */ - char initstate_tbl[INITSTATE_SIZE]; /* initstate pool */ - long random_after[RANDOM_CNT]; /* random() post initstate() */ - char *setstate_ret; /* return from setstate() call */ + unsigned long tmp; /* temp holder of 31-bit random() */ + unsigned past_hash; /* prev hash or xor-folded prev hash */ + long random_before[RANDOM_CNT]; /* random() pre initstate() */ + char *initstate_ret; /* return from initstate() call */ + char initstate_tbl[INITSTATE_SIZE]; /* initstate pool */ + long random_after[RANDOM_CNT]; /* random() post initstate() */ + char *setstate_ret; /* return from setstate() call */ int j; #endif /* HAVE_STDLIB_H */ #if defined(HAVE_ENVIRON) int i; - size_t envlen; /* length of an environment variable */ + size_t envlen; /* length of an environment variable */ #endif - hash64 hash_val; /* fnv64 hash of sdata */ - ZVALUE hash; /* hash_val as a ZVALUE */ - NUMBER *ret; /* return seed as a NUMBER */ + hash64 hash_val; /* fnv64 hash of sdata */ + ZVALUE hash; /* hash_val as a ZVALUE */ + NUMBER *ret; /* return seed as a NUMBER */ /* * initialize the Fowler/Noll/Vo-1 64 bit hash @@ -534,10 +534,10 @@ pseudo_seed(void) * pick up process/system information * * NOTE: - * We do NOT care (that much) if these calls fail. We only - * need to hash any results that might be store in the sdata structure. + * We do NOT care (that much) if these calls fail. We only + * need to hash any results that might be store in the sdata structure. */ - memset(&sdata, 0, sizeof(sdata)); /* zeroize sdata */ + memset(&sdata, 0, sizeof(sdata)); /* zeroize sdata */ #if defined(HAVE_GETTIME) # if defined(CLOCK_REALTIME) (void) clock_gettime(CLOCK_REALTIME, &sdata.realtime); @@ -549,12 +549,12 @@ pseudo_seed(void) #if defined(HAVE_URANDOM) sdata.urandom_fd = open(DEV_URANDOM, O_NONBLOCK|O_RDONLY); if (sdata.urandom_fd >= 0) { - sdata.urandom_ret = read(sdata.urandom_fd, - &sdata.urandom_pool, DEV_URANDOM_POOL); - close(sdata.urandom_fd); + sdata.urandom_ret = read(sdata.urandom_fd, + &sdata.urandom_pool, DEV_URANDOM_POOL); + close(sdata.urandom_fd); } else { - memset(&sdata.urandom_pool, EOF, DEV_URANDOM_POOL); - sdata.urandom_ret = EOF; + memset(&sdata.urandom_pool, EOF, DEV_URANDOM_POOL); + sdata.urandom_ret = EOF; } #endif /* HAVE_URANDOM */ #if defined(HAVE_SYS_TIME_H) @@ -650,8 +650,8 @@ pseudo_seed(void) #endif sdata.time = time(NULL); sdata.size = sizeof(sdata); - sdata.prev_hash64_copy = prev_hash64; /* load previous hash */ - sdata.call_count_copy = ++call_count; /* update call count */ + sdata.prev_hash64_copy = prev_hash64; /* load previous hash */ + sdata.call_count_copy = ++call_count; /* update call count */ #if defined(HAVE_ENVIRON) sdata.environ_copy = environ; #endif /* HAVE_ENVIRON */ @@ -668,13 +668,13 @@ pseudo_seed(void) */ for (i=0; environ[i] != NULL; ++i) { - /* obtain length of this next environment variable string */ - envlen = strlen(environ[i]); + /* obtain length of this next environment variable string */ + envlen = strlen(environ[i]); - /* hash any non-zero length environment variable string */ - if (envlen > 0) { - hash_val = private_hash64_buf(hash_val, environ[i], envlen); - } + /* hash any non-zero length environment variable string */ + if (envlen > 0) { + hash_val = private_hash64_buf(hash_val, environ[i], envlen); + } } #endif /* HAVE_ENVIRON */ @@ -698,7 +698,7 @@ pseudo_seed(void) /* form the xor-fold of the previous hash */ #if defined(HAVE_B64) past_hash = (unsigned)(((prev_hash64 >> 32)&0xffffffff) ^ - (prev_hash64 & 0xffffffff)); + (prev_hash64 & 0xffffffff)); #else /* HAVE_B64 */ pash_hash = (unsigned)(prev_hash64.w32[0] ^ prev_hash64.w32[1]); #endif /* HAVE_B64 */ @@ -706,28 +706,28 @@ pseudo_seed(void) /* classic 31-bit random seeded with time of day, count, prev hash */ srandom((unsigned)(sdata.time) ^ (unsigned)call_count ^ past_hash); for (j=0; j < RANDOM_CNT; ++j) { - tmp = random(); /* 31-bit value */ - /* we 32-bit circular shift to spread 31-bit returns around */ - random_before[j] = (tmp << j) | (tmp >> (RANDOM_CNT-j)); + tmp = random(); /* 31-bit value */ + /* we 32-bit circular shift to spread 31-bit returns around */ + random_before[j] = (tmp << j) | (tmp >> (RANDOM_CNT-j)); } /* init with large random state with 32-bit xor fold FNV hash of sdata */ #if defined(HAVE_B64) initstate_ret = initstate((unsigned)(((hash_val >> 32)&0xffffffff) ^ - (hash_val & 0xffffffff)), - initstate_tbl, - INITSTATE_SIZE); + (hash_val & 0xffffffff)), + initstate_tbl, + INITSTATE_SIZE); #else /* HAVE_B64 */ initstate_ret = initstate((unsigned)(hash_val.w32[0] ^ hash_val.w32[1]), - initstate_tbl, - INITSTATE_SIZE); + initstate_tbl, + INITSTATE_SIZE); #endif /* HAVE_B64 */ /* use 31-bit random some more with the new random state */ for (j=0; j < RANDOM_CNT; ++j) { - tmp = random(); /* 31-bit value */ - /* we 32-bit circular shift to spread 31-bit returns around */ - random_after[j] = (tmp << j) | (tmp >> (RANDOM_CNT-j)); + tmp = random(); /* 31-bit value */ + /* we 32-bit circular shift to spread 31-bit returns around */ + random_after[j] = (tmp << j) | (tmp >> (RANDOM_CNT-j)); } /* restore standard table sized previous state */ @@ -737,20 +737,20 @@ pseudo_seed(void) * hash all the data from random() and friends */ hash_val = private_hash64_buf(hash_val, - (char *)random_before, - sizeof(random_before)); + (char *)random_before, + sizeof(random_before)); hash_val = private_hash64_buf(hash_val, - (char *)initstate_ret, - sizeof(initstate_ret)); + (char *)initstate_ret, + sizeof(initstate_ret)); hash_val = private_hash64_buf(hash_val, - (char *)initstate_tbl, - sizeof(initstate_tbl)); + (char *)initstate_tbl, + sizeof(initstate_tbl)); hash_val = private_hash64_buf(hash_val, - (char *)random_after, - sizeof(random_after)); + (char *)random_after, + sizeof(random_after)); hash_val = private_hash64_buf(hash_val, - (char *)setstate_ret, - sizeof(setstate_ret)); + (char *)setstate_ret, + sizeof(setstate_ret)); #endif /* HAVE_STDLIB_H */ #if defined(HAVE_ARC4RANDOM) @@ -759,8 +759,8 @@ pseudo_seed(void) */ arc4random_buf(arc4_buf, ARC4_BUFLEN); hash_val = private_hash64_buf(hash_val, - (char *)arc4_buf, - ARC4_BUFLEN); + (char *)arc4_buf, + ARC4_BUFLEN); #endif /* HAVE_ARC4RANDOM */ /* @@ -772,7 +772,7 @@ pseudo_seed(void) */ hash.len = (sizeof(hash_val)+sizeof(HALF)-1) / sizeof(HALF); hash.v = alloc(hash.len); - memset(hash.v, 0, hash.len*sizeof(HALF)); /* paranoia */ + memset(hash.v, 0, hash.len*sizeof(HALF)); /* paranoia */ hash.sign = 0; memcpy((void *)hash.v, (void *)&hash_val, sizeof(hash_val)); @@ -782,10 +782,10 @@ pseudo_seed(void) * is at most 64 bits in length: this code guarantees it. * * BTW: One can safely assume that 64 is an integer multiple of BASEB: - * likely 4, 2, or 1 times BASEB. + * likely 4, 2, or 1 times BASEB. */ if (hash.len > 64/BASEB) { - hash.len = 64/BASEB; + hash.len = 64/BASEB; } ztrim(&hash); diff --git a/sha1.c b/sha1.c index 45a698e..8bc2211 100644 --- a/sha1.c +++ b/sha1.c @@ -6,7 +6,7 @@ * This file is not covered under version 2.1 of the GNU LGPL. * This file is covered under "The unlicense": * - * https://unlicense.org + * https://unlicense.org * * In particular: * @@ -48,7 +48,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* @@ -59,23 +59,23 @@ * f1: ((x&y) | (~x&z)) == (z ^ (x&(y^z))) * f3: ((x&y) | (x&z) | (y&z)) == ((x&y) | (z&(x|y))) */ -#define f1(x,y,z) (z ^ (x&(y^z))) /* Rounds 0-19 */ -#define f2(x,y,z) (x^y^z) /* Rounds 20-39 */ -#define f3(x,y,z) ((x&y) | (z&(x|y))) /* Rounds 40-59 */ -#define f4(x,y,z) (x^y^z) /* Rounds 60-79 */ +#define f1(x,y,z) (z ^ (x&(y^z))) /* Rounds 0-19 */ +#define f2(x,y,z) (x^y^z) /* Rounds 20-39 */ +#define f3(x,y,z) ((x&y) | (z&(x|y))) /* Rounds 40-59 */ +#define f4(x,y,z) (x^y^z) /* Rounds 60-79 */ /* The SHA1 Mysterious Constants */ -#define K1 0x5A827999L /* Rounds 0-19 */ -#define K2 0x6ED9EBA1L /* Rounds 20-39 */ -#define K3 0x8F1BBCDCL /* Rounds 40-59 */ -#define K4 0xCA62C1D6L /* Rounds 60-79 */ +#define K1 0x5A827999L /* Rounds 0-19 */ +#define K2 0x6ED9EBA1L /* Rounds 20-39 */ +#define K3 0x8F1BBCDCL /* Rounds 40-59 */ +#define K4 0xCA62C1D6L /* Rounds 60-79 */ /* SHA1 initial values */ -#define h0init 0x67452301L -#define h1init 0xEFCDAB89L -#define h2init 0x98BADCFEL -#define h3init 0x10325476L -#define h4init 0xC3D2E1F0L +#define h0init 0x67452301L +#define h1init 0xEFCDAB89L +#define h2init 0x98BADCFEL +#define h3init 0x10325476L +#define h4init 0xC3D2E1F0L /* 32-bit rotate left - kludged with shifts */ #define LEFT_ROT(X,n) (((X)<<(n)) | ((X)>>(32-(n)))) @@ -86,11 +86,11 @@ * 80-word expanded input array W, where the first 16 are copies of the input * data, and the remaining 64 are defined by * - * W[i] = LEFT_ROT(W[i-16] ^ W[i-14] ^ W[i-8] ^ W[i-3], 1) + * W[i] = LEFT_ROT(W[i-16] ^ W[i-14] ^ W[i-8] ^ W[i-3], 1) * * NOTE: The expanding function used in rounds 16 to 79 was changed from the - * original SHA (in FIPS Pub 180) to one that also left circular shifted - * by one bit for Secure Hash Algorithm-1 (FIPS Pub 180-1). + * original SHA (in FIPS Pub 180) to one that also left circular shifted + * by one bit for Secure Hash Algorithm-1 (FIPS Pub 180-1). */ #define exor(W,i,t) \ (t = (W[i&15] ^ W[(i-14)&15] ^ W[(i-8)&15] ^ W[(i-3)&15]), \ @@ -99,11 +99,11 @@ /* * The prototype SHA1 sub-round. The fundamental sub-round is: * - * a' = e + LEFT_ROT(a,5) + f(b,c,d) + k + data; - * b' = a; - * c' = LEFT_ROT(b,30); - * d' = c; - * e' = d; + * a' = e + LEFT_ROT(a,5) + f(b,c,d) + k + data; + * b' = a; + * c' = LEFT_ROT(b,30); + * d' = c; + * e' = d; * * but this is implemented by unrolling the loop 5 times and renaming the * variables ( e, a, b, c, d ) = ( a', b', c', d', e' ) each iteration. @@ -133,19 +133,19 @@ S_FUNC void sha1_print(HASH*); S_FUNC void sha1Init(HASH *state) { - SHA1_INFO *dig = &state->h_union.h_sha1; /* digest state */ + SHA1_INFO *dig = &state->h_union.h_sha1; /* digest state */ - /* Set the h-vars to their initial values */ - dig->digest[0] = h0init; - dig->digest[1] = h1init; - dig->digest[2] = h2init; - dig->digest[3] = h3init; - dig->digest[4] = h4init; + /* Set the h-vars to their initial values */ + dig->digest[0] = h0init; + dig->digest[1] = h1init; + dig->digest[2] = h2init; + dig->digest[3] = h3init; + dig->digest[4] = h4init; - /* Initialize bit count */ - dig->countLo = 0; - dig->countHi = 0; - dig->datalen = 0; + /* Initialize bit count */ + dig->countLo = 0; + dig->countHi = 0; + dig->datalen = 0; } @@ -159,107 +159,107 @@ sha1Init(HASH *state) S_FUNC void sha1Transform(USB32 *digest, USB32 *W) { - USB32 A, B, C, D, E; /* Local vars */ - USB32 t; /* temp storage for exor() */ + USB32 A, B, C, D, E; /* Local vars */ + USB32 t; /* temp storage for exor() */ - /* Set up first buffer and local data buffer */ - A = digest[0]; - B = digest[1]; - C = digest[2]; - D = digest[3]; - E = digest[4]; + /* Set up first buffer and local data buffer */ + A = digest[0]; + B = digest[1]; + C = digest[2]; + D = digest[3]; + E = digest[4]; - /* Heavy mangling, in 4 sub-rounds of 20 iterations each. */ - subRound(A, B, C, D, E, f1, K1, W[ 0]); - subRound(E, A, B, C, D, f1, K1, W[ 1]); - subRound(D, E, A, B, C, f1, K1, W[ 2]); - subRound(C, D, E, A, B, f1, K1, W[ 3]); - subRound(B, C, D, E, A, f1, K1, W[ 4]); - subRound(A, B, C, D, E, f1, K1, W[ 5]); - subRound(E, A, B, C, D, f1, K1, W[ 6]); - subRound(D, E, A, B, C, f1, K1, W[ 7]); - subRound(C, D, E, A, B, f1, K1, W[ 8]); - subRound(B, C, D, E, A, f1, K1, W[ 9]); - subRound(A, B, C, D, E, f1, K1, W[10]); - subRound(E, A, B, C, D, f1, K1, W[11]); - subRound(D, E, A, B, C, f1, K1, W[12]); - subRound(C, D, E, A, B, f1, K1, W[13]); - subRound(B, C, D, E, A, f1, K1, W[14]); - subRound(A, B, C, D, E, f1, K1, W[15]); - subRound(E, A, B, C, D, f1, K1, exor(W,16,t)); - subRound(D, E, A, B, C, f1, K1, exor(W,17,t)); - subRound(C, D, E, A, B, f1, K1, exor(W,18,t)); - subRound(B, C, D, E, A, f1, K1, exor(W,19,t)); + /* Heavy mangling, in 4 sub-rounds of 20 iterations each. */ + subRound(A, B, C, D, E, f1, K1, W[ 0]); + subRound(E, A, B, C, D, f1, K1, W[ 1]); + subRound(D, E, A, B, C, f1, K1, W[ 2]); + subRound(C, D, E, A, B, f1, K1, W[ 3]); + subRound(B, C, D, E, A, f1, K1, W[ 4]); + subRound(A, B, C, D, E, f1, K1, W[ 5]); + subRound(E, A, B, C, D, f1, K1, W[ 6]); + subRound(D, E, A, B, C, f1, K1, W[ 7]); + subRound(C, D, E, A, B, f1, K1, W[ 8]); + subRound(B, C, D, E, A, f1, K1, W[ 9]); + subRound(A, B, C, D, E, f1, K1, W[10]); + subRound(E, A, B, C, D, f1, K1, W[11]); + subRound(D, E, A, B, C, f1, K1, W[12]); + subRound(C, D, E, A, B, f1, K1, W[13]); + subRound(B, C, D, E, A, f1, K1, W[14]); + subRound(A, B, C, D, E, f1, K1, W[15]); + subRound(E, A, B, C, D, f1, K1, exor(W,16,t)); + subRound(D, E, A, B, C, f1, K1, exor(W,17,t)); + subRound(C, D, E, A, B, f1, K1, exor(W,18,t)); + subRound(B, C, D, E, A, f1, K1, exor(W,19,t)); - subRound(A, B, C, D, E, f2, K2, exor(W,20,t)); - subRound(E, A, B, C, D, f2, K2, exor(W,21,t)); - subRound(D, E, A, B, C, f2, K2, exor(W,22,t)); - subRound(C, D, E, A, B, f2, K2, exor(W,23,t)); - subRound(B, C, D, E, A, f2, K2, exor(W,24,t)); - subRound(A, B, C, D, E, f2, K2, exor(W,25,t)); - subRound(E, A, B, C, D, f2, K2, exor(W,26,t)); - subRound(D, E, A, B, C, f2, K2, exor(W,27,t)); - subRound(C, D, E, A, B, f2, K2, exor(W,28,t)); - subRound(B, C, D, E, A, f2, K2, exor(W,29,t)); - subRound(A, B, C, D, E, f2, K2, exor(W,30,t)); - subRound(E, A, B, C, D, f2, K2, exor(W,31,t)); - subRound(D, E, A, B, C, f2, K2, exor(W,32,t)); - subRound(C, D, E, A, B, f2, K2, exor(W,33,t)); - subRound(B, C, D, E, A, f2, K2, exor(W,34,t)); - subRound(A, B, C, D, E, f2, K2, exor(W,35,t)); - subRound(E, A, B, C, D, f2, K2, exor(W,36,t)); - subRound(D, E, A, B, C, f2, K2, exor(W,37,t)); - subRound(C, D, E, A, B, f2, K2, exor(W,38,t)); - subRound(B, C, D, E, A, f2, K2, exor(W,39,t)); + subRound(A, B, C, D, E, f2, K2, exor(W,20,t)); + subRound(E, A, B, C, D, f2, K2, exor(W,21,t)); + subRound(D, E, A, B, C, f2, K2, exor(W,22,t)); + subRound(C, D, E, A, B, f2, K2, exor(W,23,t)); + subRound(B, C, D, E, A, f2, K2, exor(W,24,t)); + subRound(A, B, C, D, E, f2, K2, exor(W,25,t)); + subRound(E, A, B, C, D, f2, K2, exor(W,26,t)); + subRound(D, E, A, B, C, f2, K2, exor(W,27,t)); + subRound(C, D, E, A, B, f2, K2, exor(W,28,t)); + subRound(B, C, D, E, A, f2, K2, exor(W,29,t)); + subRound(A, B, C, D, E, f2, K2, exor(W,30,t)); + subRound(E, A, B, C, D, f2, K2, exor(W,31,t)); + subRound(D, E, A, B, C, f2, K2, exor(W,32,t)); + subRound(C, D, E, A, B, f2, K2, exor(W,33,t)); + subRound(B, C, D, E, A, f2, K2, exor(W,34,t)); + subRound(A, B, C, D, E, f2, K2, exor(W,35,t)); + subRound(E, A, B, C, D, f2, K2, exor(W,36,t)); + subRound(D, E, A, B, C, f2, K2, exor(W,37,t)); + subRound(C, D, E, A, B, f2, K2, exor(W,38,t)); + subRound(B, C, D, E, A, f2, K2, exor(W,39,t)); - subRound(A, B, C, D, E, f3, K3, exor(W,40,t)); - subRound(E, A, B, C, D, f3, K3, exor(W,41,t)); - subRound(D, E, A, B, C, f3, K3, exor(W,42,t)); - subRound(C, D, E, A, B, f3, K3, exor(W,43,t)); - subRound(B, C, D, E, A, f3, K3, exor(W,44,t)); - subRound(A, B, C, D, E, f3, K3, exor(W,45,t)); - subRound(E, A, B, C, D, f3, K3, exor(W,46,t)); - subRound(D, E, A, B, C, f3, K3, exor(W,47,t)); - subRound(C, D, E, A, B, f3, K3, exor(W,48,t)); - subRound(B, C, D, E, A, f3, K3, exor(W,49,t)); - subRound(A, B, C, D, E, f3, K3, exor(W,50,t)); - subRound(E, A, B, C, D, f3, K3, exor(W,51,t)); - subRound(D, E, A, B, C, f3, K3, exor(W,52,t)); - subRound(C, D, E, A, B, f3, K3, exor(W,53,t)); - subRound(B, C, D, E, A, f3, K3, exor(W,54,t)); - subRound(A, B, C, D, E, f3, K3, exor(W,55,t)); - subRound(E, A, B, C, D, f3, K3, exor(W,56,t)); - subRound(D, E, A, B, C, f3, K3, exor(W,57,t)); - subRound(C, D, E, A, B, f3, K3, exor(W,58,t)); - subRound(B, C, D, E, A, f3, K3, exor(W,59,t)); + subRound(A, B, C, D, E, f3, K3, exor(W,40,t)); + subRound(E, A, B, C, D, f3, K3, exor(W,41,t)); + subRound(D, E, A, B, C, f3, K3, exor(W,42,t)); + subRound(C, D, E, A, B, f3, K3, exor(W,43,t)); + subRound(B, C, D, E, A, f3, K3, exor(W,44,t)); + subRound(A, B, C, D, E, f3, K3, exor(W,45,t)); + subRound(E, A, B, C, D, f3, K3, exor(W,46,t)); + subRound(D, E, A, B, C, f3, K3, exor(W,47,t)); + subRound(C, D, E, A, B, f3, K3, exor(W,48,t)); + subRound(B, C, D, E, A, f3, K3, exor(W,49,t)); + subRound(A, B, C, D, E, f3, K3, exor(W,50,t)); + subRound(E, A, B, C, D, f3, K3, exor(W,51,t)); + subRound(D, E, A, B, C, f3, K3, exor(W,52,t)); + subRound(C, D, E, A, B, f3, K3, exor(W,53,t)); + subRound(B, C, D, E, A, f3, K3, exor(W,54,t)); + subRound(A, B, C, D, E, f3, K3, exor(W,55,t)); + subRound(E, A, B, C, D, f3, K3, exor(W,56,t)); + subRound(D, E, A, B, C, f3, K3, exor(W,57,t)); + subRound(C, D, E, A, B, f3, K3, exor(W,58,t)); + subRound(B, C, D, E, A, f3, K3, exor(W,59,t)); - subRound(A, B, C, D, E, f4, K4, exor(W,60,t)); - subRound(E, A, B, C, D, f4, K4, exor(W,61,t)); - subRound(D, E, A, B, C, f4, K4, exor(W,62,t)); - subRound(C, D, E, A, B, f4, K4, exor(W,63,t)); - subRound(B, C, D, E, A, f4, K4, exor(W,64,t)); - subRound(A, B, C, D, E, f4, K4, exor(W,65,t)); - subRound(E, A, B, C, D, f4, K4, exor(W,66,t)); - subRound(D, E, A, B, C, f4, K4, exor(W,67,t)); - subRound(C, D, E, A, B, f4, K4, exor(W,68,t)); - subRound(B, C, D, E, A, f4, K4, exor(W,69,t)); - subRound(A, B, C, D, E, f4, K4, exor(W,70,t)); - subRound(E, A, B, C, D, f4, K4, exor(W,71,t)); - subRound(D, E, A, B, C, f4, K4, exor(W,72,t)); - subRound(C, D, E, A, B, f4, K4, exor(W,73,t)); - subRound(B, C, D, E, A, f4, K4, exor(W,74,t)); - subRound(A, B, C, D, E, f4, K4, exor(W,75,t)); - subRound(E, A, B, C, D, f4, K4, exor(W,76,t)); - subRound(D, E, A, B, C, f4, K4, exor(W,77,t)); - subRound(C, D, E, A, B, f4, K4, exor(W,78,t)); - subRound(B, C, D, E, A, f4, K4, exor(W,79,t)); + subRound(A, B, C, D, E, f4, K4, exor(W,60,t)); + subRound(E, A, B, C, D, f4, K4, exor(W,61,t)); + subRound(D, E, A, B, C, f4, K4, exor(W,62,t)); + subRound(C, D, E, A, B, f4, K4, exor(W,63,t)); + subRound(B, C, D, E, A, f4, K4, exor(W,64,t)); + subRound(A, B, C, D, E, f4, K4, exor(W,65,t)); + subRound(E, A, B, C, D, f4, K4, exor(W,66,t)); + subRound(D, E, A, B, C, f4, K4, exor(W,67,t)); + subRound(C, D, E, A, B, f4, K4, exor(W,68,t)); + subRound(B, C, D, E, A, f4, K4, exor(W,69,t)); + subRound(A, B, C, D, E, f4, K4, exor(W,70,t)); + subRound(E, A, B, C, D, f4, K4, exor(W,71,t)); + subRound(D, E, A, B, C, f4, K4, exor(W,72,t)); + subRound(C, D, E, A, B, f4, K4, exor(W,73,t)); + subRound(B, C, D, E, A, f4, K4, exor(W,74,t)); + subRound(A, B, C, D, E, f4, K4, exor(W,75,t)); + subRound(E, A, B, C, D, f4, K4, exor(W,76,t)); + subRound(D, E, A, B, C, f4, K4, exor(W,77,t)); + subRound(C, D, E, A, B, f4, K4, exor(W,78,t)); + subRound(B, C, D, E, A, f4, K4, exor(W,79,t)); - /* Build message digest */ - digest[0] += A; - digest[1] += B; - digest[2] += C; - digest[3] += D; - digest[4] += E; + /* Build message digest */ + digest[0] += A; + digest[1] += B; + digest[2] += C; + digest[3] += D; + digest[4] += E; } @@ -269,61 +269,61 @@ sha1Transform(USB32 *digest, USB32 *W) void sha1Update(HASH *state, USB8 *buffer, USB32 count) { - SHA1_INFO *dig = &state->h_union.h_sha1; /* digest state */ - USB32 datalen = dig->datalen; - USB32 cpylen; + SHA1_INFO *dig = &state->h_union.h_sha1; /* digest state */ + USB32 datalen = dig->datalen; + USB32 cpylen; #if CALC_BYTE_ORDER == LITTLE_ENDIAN - unsigned int i; + unsigned int i; #endif - /* - * Update the full count, even if some of it is buffered for later - */ - SHA1COUNT(dig, count); + /* + * Update the full count, even if some of it is buffered for later + */ + SHA1COUNT(dig, count); - /* determine the size we need to copy */ - cpylen = SHA1_CHUNKSIZE - datalen; + /* determine the size we need to copy */ + cpylen = SHA1_CHUNKSIZE - datalen; - /* case: new data will not fill the buffer */ - if (cpylen > count) { - memcpy((char *)dig->data+datalen, - (char *)buffer, count); - dig->datalen = datalen+count; - return; - } + /* case: new data will not fill the buffer */ + if (cpylen > count) { + memcpy((char *)dig->data+datalen, + (char *)buffer, count); + dig->datalen = datalen+count; + return; + } - /* case: buffer will be filled */ - memcpy((char *)dig->data + datalen, (char *)buffer, cpylen); + /* case: buffer will be filled */ + memcpy((char *)dig->data + datalen, (char *)buffer, cpylen); - /* - * Process data in SHA1_CHUNKSIZE chunks - */ - for (;;) { + /* + * Process data in SHA1_CHUNKSIZE chunks + */ + for (;;) { #if CALC_BYTE_ORDER == LITTLE_ENDIAN - if (state->bytes) { - for (i=0; i < SHA1_CHUNKWORDS; ++i) { - SWAP_B8_IN_B32(dig->data+i, dig->data+i); - } - } + if (state->bytes) { + for (i=0; i < SHA1_CHUNKWORDS; ++i) { + SWAP_B8_IN_B32(dig->data+i, dig->data+i); + } + } #endif - sha1Transform(dig->digest, dig->data); - buffer += cpylen; - count -= cpylen; - if (count < SHA1_CHUNKSIZE) - break; - cpylen = SHA1_CHUNKSIZE; - memcpy(dig->data, buffer, cpylen); - } + sha1Transform(dig->digest, dig->data); + buffer += cpylen; + count -= cpylen; + if (count < SHA1_CHUNKSIZE) + break; + cpylen = SHA1_CHUNKSIZE; + memcpy(dig->data, buffer, cpylen); + } - /* - * Handle any remaining bytes of data. - * This should only happen once on the final lot of data - */ - if (count > 0) { - memcpy((char *)dig->data, (char *)buffer, count); - } - dig->datalen = count; + /* + * Handle any remaining bytes of data. + * This should only happen once on the final lot of data + */ + if (count > 0) { + memcpy((char *)dig->data, (char *)buffer, count); + } + dig->datalen = count; } @@ -338,7 +338,7 @@ sha1Update(HASH *state, USB8 *buffer, USB32 count) * Next if we have more than 56 bytes, we will zero fill the remainder * of the chunk, transform and then zero fill the first 56 bytes. * If we have 56 or fewer bytes, we will zero fill out to the 56th - * chunk byte. Regardless, we wind up with 56 bytes data. + * chunk byte. Regardless, we wind up with 56 bytes data. * * Finally we append the 64 bit length on to the 56 bytes of data * remaining. This final chunk is transformed. @@ -347,65 +347,65 @@ sha1Update(HASH *state, USB8 *buffer, USB32 count) void sha1Final(HASH *state) { - SHA1_INFO *dig = &state->h_union.h_sha1; /* digest state */ - long count = (long)(dig->datalen); - USB32 lowBitcount; - USB32 highBitcount; - USB8 *data = (USB8 *) dig->data; + SHA1_INFO *dig = &state->h_union.h_sha1; /* digest state */ + long count = (long)(dig->datalen); + USB32 lowBitcount; + USB32 highBitcount; + USB8 *data = (USB8 *) dig->data; #if CALC_BYTE_ORDER == LITTLE_ENDIAN - unsigned int i; + unsigned int i; #endif - /* Pad to end of chunk */ + /* Pad to end of chunk */ - memset(data + count, 0, SHA1_CHUNKSIZE - count); + memset(data + count, 0, SHA1_CHUNKSIZE - count); - /* - * If processing bytes, set the first byte of padding to 0x80. - * if processing words: on a big-endian machine set the first - * byte of padding to 0x80, on a little-endian machine set - * the first four bytes to 0x00000080 - * This is safe since there is always at least one byte or word free - */ + /* + * If processing bytes, set the first byte of padding to 0x80. + * if processing words: on a big-endian machine set the first + * byte of padding to 0x80, on a little-endian machine set + * the first four bytes to 0x00000080 + * This is safe since there is always at least one byte or word free + */ - memset(data + count, 0, SHA1_CHUNKSIZE - count); + memset(data + count, 0, SHA1_CHUNKSIZE - count); #if CALC_BYTE_ORDER == LITTLE_ENDIAN - if (state->bytes) { - data[count] = 0x80; - for (i=0; i < SHA1_CHUNKWORDS; ++i) { - SWAP_B8_IN_B32(dig->data+i, dig->data+i); - } - } else { - if (count % 4) { - math_error("This should not happen in sha1Final"); - not_reached(); - } - data[count + 3] = 0x80; - } + if (state->bytes) { + data[count] = 0x80; + for (i=0; i < SHA1_CHUNKWORDS; ++i) { + SWAP_B8_IN_B32(dig->data+i, dig->data+i); + } + } else { + if (count % 4) { + math_error("This should not happen in sha1Final"); + not_reached(); + } + data[count + 3] = 0x80; + } #else - data[count] = 0x80; + data[count] = 0x80; #endif - if (count >= SHA1_CHUNKSIZE-8) { - sha1Transform(dig->digest, dig->data); + if (count >= SHA1_CHUNKSIZE-8) { + sha1Transform(dig->digest, dig->data); - /* Now load another chunk with 56 bytes of padding */ - memset(data, 0, SHA1_CHUNKSIZE-8); - } + /* Now load another chunk with 56 bytes of padding */ + memset(data, 0, SHA1_CHUNKSIZE-8); + } - /* - * Append length in bits and transform - * - * We assume that bit count is a multiple of 8 because we have - * only processed full bytes. - */ - highBitcount = dig->countHi; - lowBitcount = dig->countLo; - dig->data[SHA1_HIGH] = (highBitcount << 3) | (lowBitcount >> 29); - dig->data[SHA1_LOW] = (lowBitcount << 3); - sha1Transform(dig->digest, dig->data); - dig->datalen = 0; + /* + * Append length in bits and transform + * + * We assume that bit count is a multiple of 8 because we have + * only processed full bytes. + */ + highBitcount = dig->countHi; + lowBitcount = dig->countLo; + dig->data[SHA1_HIGH] = (highBitcount << 3) | (lowBitcount >> 29); + dig->data[SHA1_LOW] = (lowBitcount << 3); + sha1Transform(dig->digest, dig->data); + dig->datalen = 0; } @@ -413,7 +413,7 @@ sha1Final(HASH *state) * sha1_chkpt - checkpoint a SHA1 state * * given: - * state the state to checkpoint + * state the state to checkpoint * * This function will ensure that the hash chunk buffer is empty. * Any partially hashed data will be padded out with 0's and hashed. @@ -421,34 +421,34 @@ sha1Final(HASH *state) S_FUNC void sha1_chkpt(HASH *state) { - SHA1_INFO *dig = &state->h_union.h_sha1; /* digest state */ + SHA1_INFO *dig = &state->h_union.h_sha1; /* digest state */ #if CALC_BYTE_ORDER == LITTLE_ENDIAN - unsigned int i; + unsigned int i; #endif - /* - * checkpoint if partial buffer exists - */ - if (dig->datalen > 0) { + /* + * checkpoint if partial buffer exists + */ + if (dig->datalen > 0) { - /* pad to the end of the chunk */ - memset((USB8 *)dig->data + dig->datalen, 0, - SHA1_CHUNKSIZE-dig->datalen); + /* pad to the end of the chunk */ + memset((USB8 *)dig->data + dig->datalen, 0, + SHA1_CHUNKSIZE-dig->datalen); #if CALC_BYTE_ORDER == LITTLE_ENDIAN - if (state->bytes) { - for (i=0; i < SHA1_CHUNKWORDS; ++i) { - SWAP_B8_IN_B32(dig->data+i, dig->data+i); - } - } + if (state->bytes) { + for (i=0; i < SHA1_CHUNKWORDS; ++i) { + SWAP_B8_IN_B32(dig->data+i, dig->data+i); + } + } #endif - /* transform padded chunk */ - sha1Transform(dig->digest, dig->data); - SHA1COUNT(dig, SHA1_CHUNKSIZE-dig->datalen); + /* transform padded chunk */ + sha1Transform(dig->digest, dig->data); + SHA1COUNT(dig, SHA1_CHUNKSIZE-dig->datalen); - /* empty buffer */ - dig->datalen = 0; - } - return; + /* empty buffer */ + dig->datalen = 0; + } + return; } @@ -456,8 +456,8 @@ sha1_chkpt(HASH *state) * sha1_note - note a special value * * given: - * state the state to hash - * special a special value (SHA1_HASH_XYZ) to note + * state the state to hash + * special a special value (SHA1_HASH_XYZ) to note * * This function will note that a special value is about to be hashed. * Types include negative values, complex values, division, zero numeric @@ -466,17 +466,17 @@ sha1_chkpt(HASH *state) S_FUNC void sha1_note(int special, HASH *state) { - SHA1_INFO *dig = &state->h_union.h_sha1; /* digest state */ - unsigned int i; + SHA1_INFO *dig = &state->h_union.h_sha1; /* digest state */ + unsigned int i; - /* - * change state to reflect a special value - */ - dig->digest[0] ^= special; - for (i=1; i < SHA1_DIGESTWORDS; ++i) { - dig->digest[i] ^= (special + dig->digest[i-1] + i); - } - return; + /* + * change state to reflect a special value + */ + dig->digest[0] ^= special; + for (i=1; i < SHA1_DIGESTWORDS; ++i) { + dig->digest[i] ^= (special + dig->digest[i-1] + i); + } + return; } @@ -484,8 +484,8 @@ sha1_note(int special, HASH *state) * sha1_type - note a VALUE type * * given: - * state the state to hash - * type the VALUE type to note + * state the state to hash + * type the VALUE type to note * * This function will note that a type of value is about to be hashed. * The type of a VALUE will be noted. For purposes of hash comparison, @@ -497,24 +497,24 @@ sha1_note(int special, HASH *state) S_FUNC void sha1_type(int type, HASH *state) { - SHA1_INFO *dig = &state->h_union.h_sha1; /* digest state */ - unsigned int i; + SHA1_INFO *dig = &state->h_union.h_sha1; /* digest state */ + unsigned int i; - /* - * ignore NUMBER and COMPLEX - */ - if (type == V_NUM || type == V_COM || type == V_STR) { - return; - } + /* + * ignore NUMBER and COMPLEX + */ + if (type == V_NUM || type == V_COM || type == V_STR) { + return; + } - /* - * change state to reflect a VALUE type - */ - dig->digest[0] += type; - for (i=1; i < SHA1_DIGESTWORDS; ++i) { - dig->digest[i] += ((type+i) ^ dig->digest[i-1]); - } - return; + /* + * change state to reflect a VALUE type + */ + dig->digest[0] += type; + for (i=1; i < SHA1_DIGESTWORDS; ++i) { + dig->digest[i] += ((type+i) ^ dig->digest[i-1]); + } + return; } @@ -522,33 +522,33 @@ sha1_type(int type, HASH *state) * sha1_init_state - initialize a hash state structure for this hash * * given: - * state - pointer to the function element to initialize + * state - pointer to the function element to initialize */ void sha1_init_state(HASH *state) { - /* - * initialize state - */ - state->hashtype = SHA1_HASH_TYPE; - state->bytes = true; - state->update = sha1Update; - state->chkpt = sha1_chkpt; - state->note = sha1_note; - state->type = sha1_type; - state->final = sha1_final_state; - state->cmp = sha1_cmp; - state->print = sha1_print; - state->base = SHA1_BASE; - state->chunksize = SHA1_CHUNKSIZE; - state->unionsize = sizeof(SHA1_INFO); + /* + * initialize state + */ + state->hashtype = SHA1_HASH_TYPE; + state->bytes = true; + state->update = sha1Update; + state->chkpt = sha1_chkpt; + state->note = sha1_note; + state->type = sha1_type; + state->final = sha1_final_state; + state->cmp = sha1_cmp; + state->print = sha1_print; + state->base = SHA1_BASE; + state->chunksize = SHA1_CHUNKSIZE; + state->unionsize = sizeof(SHA1_INFO); - /* - * perform the internal init function - */ - memset((void *)&(state->h_union.h_sha1), 0, sizeof(SHA1_INFO)); - sha1Init(state); - return; + /* + * perform the internal init function + */ + memset((void *)&(state->h_union.h_sha1), 0, sizeof(SHA1_INFO)); + sha1Init(state); + return; } @@ -556,61 +556,61 @@ sha1_init_state(HASH *state) * sha1_final_state - complete hash state and return a ZVALUE * * given: - * state the state to complete and convert + * state the state to complete and convert * * returns: - * a ZVALUE representing the state + * a ZVALUE representing the state */ S_FUNC ZVALUE sha1_final_state(HASH *state) { - SHA1_INFO *dig = &state->h_union.h_sha1; /* digest state */ - ZVALUE ret; /* return ZVALUE of completed hash state */ - int i; + SHA1_INFO *dig = &state->h_union.h_sha1; /* digest state */ + ZVALUE ret; /* return ZVALUE of completed hash state */ + int i; - /* - * malloc and initialize if state is NULL - */ - if (state == NULL) { - state = (HASH *)malloc(sizeof(HASH)); - if (state == NULL) { - math_error("cannot malloc HASH"); - not_reached(); - } - sha1_init_state(state); - } + /* + * malloc and initialize if state is NULL + */ + if (state == NULL) { + state = (HASH *)malloc(sizeof(HASH)); + if (state == NULL) { + math_error("cannot malloc HASH"); + not_reached(); + } + sha1_init_state(state); + } - /* - * complete the hash state - */ - sha1Final(state); + /* + * complete the hash state + */ + sha1Final(state); - /* - * allocate storage for ZVALUE - */ - ret.len = SHA1_DIGESTSIZE/sizeof(HALF); - ret.sign = 0; - ret.v = alloc(ret.len); + /* + * allocate storage for ZVALUE + */ + ret.len = SHA1_DIGESTSIZE/sizeof(HALF); + ret.sign = 0; + ret.v = alloc(ret.len); - /* - * load ZVALUE - */ + /* + * load ZVALUE + */ #if BASEB == 16 && CALC_BYTE_ORDER == LITTLE_ENDIAN - for (i=0; i < ret.len; i+=2) { - ret.v[ret.len-i-1] = ((HALF*)dig->digest)[i+1]; - ret.v[ret.len-i-2] = ((HALF*)dig->digest)[i]; - } + for (i=0; i < ret.len; i+=2) { + ret.v[ret.len-i-1] = ((HALF*)dig->digest)[i+1]; + ret.v[ret.len-i-2] = ((HALF*)dig->digest)[i]; + } #else - for (i=0; i < ret.len; ++i) { - ret.v[ret.len-i-1] = ((HALF*)dig->digest)[i]; - } + for (i=0; i < ret.len; ++i) { + ret.v[ret.len-i-1] = ((HALF*)dig->digest)[i]; + } #endif - ztrim(&ret); + ztrim(&ret); - /* - * return ZVALUE - */ - return ret; + /* + * return ZVALUE + */ + return ret; } @@ -618,63 +618,63 @@ sha1_final_state(HASH *state) * sha1_cmp - compare two hash states * * given: - * a first hash state - * b second hash state + * a first hash state + * b second hash state * * returns: - * true => hash states are different - * false => hash states are the same + * true => hash states are different + * false => hash states are the same */ S_FUNC int sha1_cmp(HASH *a, HASH *b) { - /* - * firewall and quick check - */ - if (a == b) { - /* pointers to the same object */ - return false; - } - if (a == NULL || b == NULL) { - /* one is NULL, so they differ */ - return true; - } + /* + * firewall and quick check + */ + if (a == b) { + /* pointers to the same object */ + return false; + } + if (a == NULL || b == NULL) { + /* one is NULL, so they differ */ + return true; + } - /* - * compare data-reading modes - */ - if (a->bytes != b->bytes) - return true; + /* + * compare data-reading modes + */ + if (a->bytes != b->bytes) + return true; - /* - * compare bit counts - */ - if (a->h_union.h_sha1.countLo != b->h_union.h_sha1.countLo || - a->h_union.h_sha1.countHi != b->h_union.h_sha1.countHi) { - /* counts differ */ - return true; - } + /* + * compare bit counts + */ + if (a->h_union.h_sha1.countLo != b->h_union.h_sha1.countLo || + a->h_union.h_sha1.countHi != b->h_union.h_sha1.countHi) { + /* counts differ */ + return true; + } - /* - * compare pending buffers - */ - if (a->h_union.h_sha1.datalen != b->h_union.h_sha1.datalen) { - /* buffer lengths differ */ - return true; - } - if (memcmp((USB8*)a->h_union.h_sha1.data, - (USB8*)b->h_union.h_sha1.data, - a->h_union.h_sha1.datalen) != 0) { - /* buffer contents differ */ - return true; - } + /* + * compare pending buffers + */ + if (a->h_union.h_sha1.datalen != b->h_union.h_sha1.datalen) { + /* buffer lengths differ */ + return true; + } + if (memcmp((USB8*)a->h_union.h_sha1.data, + (USB8*)b->h_union.h_sha1.data, + a->h_union.h_sha1.datalen) != 0) { + /* buffer contents differ */ + return true; + } - /* - * compare digest - */ - return (memcmp((USB8*)(a->h_union.h_sha1.digest), - (USB8*)(b->h_union.h_sha1.digest), - SHA1_DIGESTSIZE) != 0); + /* + * compare digest + */ + return (memcmp((USB8*)(a->h_union.h_sha1.digest), + (USB8*)(b->h_union.h_sha1.digest), + SHA1_DIGESTSIZE) != 0); } @@ -682,36 +682,36 @@ sha1_cmp(HASH *a, HASH *b) * sha1_print - print a hash state * * given: - * state the hash state to print + * state the hash state to print */ S_FUNC void sha1_print(HASH *state) { - /* - * form the hash value - */ - if (conf->calc_debug & CALCDBG_HASH_STATE) { - char buf[DEBUG_SIZE+1]; /* hash value buffer */ + /* + * form the hash value + */ + if (conf->calc_debug & CALCDBG_HASH_STATE) { + char buf[DEBUG_SIZE+1]; /* hash value buffer */ - /* - * print numeric debug value - * - * NOTE: This value represents only the hash value as of - * the last full update or finalization. Thus it - * may NOT be the actual hash value. - */ - snprintf(buf, DEBUG_SIZE, - "sha1: 0x%08x%08x%08x%08x%08x data: %d octets", - (int)state->h_union.h_sha1.digest[0], - (int)state->h_union.h_sha1.digest[1], - (int)state->h_union.h_sha1.digest[2], - (int)state->h_union.h_sha1.digest[3], - (int)state->h_union.h_sha1.digest[4], - (int)state->h_union.h_sha1.datalen); - buf[DEBUG_SIZE] = '\0'; /* paranoia */ - math_str(buf); - } else { - math_str("sha1 hash state"); - } - return; + /* + * print numeric debug value + * + * NOTE: This value represents only the hash value as of + * the last full update or finalization. Thus it + * may NOT be the actual hash value. + */ + snprintf(buf, DEBUG_SIZE, + "sha1: 0x%08x%08x%08x%08x%08x data: %d octets", + (int)state->h_union.h_sha1.digest[0], + (int)state->h_union.h_sha1.digest[1], + (int)state->h_union.h_sha1.digest[2], + (int)state->h_union.h_sha1.digest[3], + (int)state->h_union.h_sha1.digest[4], + (int)state->h_union.h_sha1.datalen); + buf[DEBUG_SIZE] = '\0'; /* paranoia */ + math_str(buf); + } else { + math_str("sha1 hash state"); + } + return; } diff --git a/sha1.h b/sha1.h index c7ffa82..8d4d07b 100644 --- a/sha1.h +++ b/sha1.h @@ -6,7 +6,7 @@ * This file is not covered under version 2.1 of the GNU LGPL. * This file is covered under "The unlicense": * - * https://unlicense.org + * https://unlicense.org * * In particular: * @@ -61,11 +61,11 @@ * We will assume that bit count is a multiple of 8. */ typedef struct { - USB32 digest[SHA1_DIGESTWORDS]; /* message digest */ - USB32 countLo; /* 64 bit count: bits 3-34 */ - USB32 countHi; /* 64 bit count: bits 35-63 */ - USB32 datalen; /* length of data in data */ - USB32 data[SHA1_CHUNKWORDS]; /* SHA1 chunk buffer */ + USB32 digest[SHA1_DIGESTWORDS]; /* message digest */ + USB32 countLo; /* 64 bit count: bits 3-34 */ + USB32 countHi; /* 64 bit count: bits 35-63 */ + USB32 datalen; /* length of data in data */ + USB32 data[SHA1_CHUNKWORDS]; /* SHA1 chunk buffer */ } SHA1_INFO; /* @@ -74,12 +74,12 @@ typedef struct { * We will count bytes and convert to bit count during the final * transform. */ -#define SHA1COUNT(sha1info, count) { \ - USB32 tmp_countLo; \ - tmp_countLo = (sha1info)->countLo; \ - if (((sha1info)->countLo += (count)) < tmp_countLo) { \ - (sha1info)->countHi++; \ - } \ +#define SHA1COUNT(sha1info, count) { \ + USB32 tmp_countLo; \ + tmp_countLo = (sha1info)->countLo; \ + if (((sha1info)->countLo += (count)) < tmp_countLo) { \ + (sha1info)->countHi++; \ + } \ } diff --git a/size.c b/size.c index 68947ee..c96234b 100644 --- a/size.c +++ b/size.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/03/10 01:56:51 - * File existed as early as: 1997 + * Under source code control: 1997/03/10 01:56:51 + * File existed as early as: 1997 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -31,7 +31,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* @@ -55,61 +55,61 @@ S_FUNC size_t memqsize(NUMBER*); * This is not the sizeof, see lsizeof() for that information. * * given: - * vp pointer to a value + * vp pointer to a value * * return: - * number of elements + * number of elements */ long elm_count(VALUE *vp) { - long result; + long result; - /* - * return information about the number of elements - * - * This is not the sizeof, see lsizeof() for that information. - * This is does not include overhead, see memsize() for that info. - */ + /* + * return information about the number of elements + * + * This is not the sizeof, see lsizeof() for that information. + * This is does not include overhead, see memsize() for that info. + */ - switch (vp->v_type) { - case V_NULL: - case V_INT: - case V_ADDR: - case V_OCTET: - result = 0; - break; - case V_MAT: - result = vp->v_mat->m_size; - break; - case V_LIST: - result = vp->v_list->l_count; - break; - case V_ASSOC: - result = vp->v_assoc->a_count; - break; - case V_OBJ: - result = vp->v_obj->o_actions->oa_count; - break; - case V_STR: - result = vp->v_str->s_len; - break; - case V_BLOCK: - result = (long) vp->v_block->datalen; - break; - case V_NBLOCK: - result = (long) vp->v_nblock->blk->datalen; - break; - /* - * V_NUM, V_COM, V_RAND, V_RANDOM, V_CONFIG, V_HASH - * - * V_FILE (use getsize(vp->v_file, &len) for file length) - */ - default: - result = (vp->v_type > 0); - break; - } - return result; + switch (vp->v_type) { + case V_NULL: + case V_INT: + case V_ADDR: + case V_OCTET: + result = 0; + break; + case V_MAT: + result = vp->v_mat->m_size; + break; + case V_LIST: + result = vp->v_list->l_count; + break; + case V_ASSOC: + result = vp->v_assoc->a_count; + break; + case V_OBJ: + result = vp->v_obj->o_actions->oa_count; + break; + case V_STR: + result = vp->v_str->s_len; + break; + case V_BLOCK: + result = (long) vp->v_block->datalen; + break; + case V_NBLOCK: + result = (long) vp->v_nblock->blk->datalen; + break; + /* + * V_NUM, V_COM, V_RAND, V_RANDOM, V_CONFIG, V_HASH + * + * V_FILE (use getsize(vp->v_file, &len) for file length) + */ + default: + result = (vp->v_type > 0); + break; + } + return result; } @@ -119,69 +119,69 @@ elm_count(VALUE *vp) * The numeric -1, - and 1 storage values are ignored. * * given: - * z ZVALUE to examine + * z ZVALUE to examine * * returns: - * value size + * value size */ S_FUNC size_t zsize(ZVALUE z) { - /* ignore the size of 0, 1 and -1 */ - if (z.v != _zeroval_ && z.v != _oneval_ && !zisunit(z) && !ziszero(z)) { - return z.len * sizeof(HALF); - } else { - return (size_t)0; - } + /* ignore the size of 0, 1 and -1 */ + if (z.v != _zeroval_ && z.v != _oneval_ && !zisunit(z) && !ziszero(z)) { + return z.len * sizeof(HALF); + } else { + return (size_t)0; + } } /* * qsize - calculate memory footprint of a NUMBER (excluding overhead) * - * The numeric -1, - and 1 storage values are ignored. Denominator + * The numeric -1, - and 1 storage values are ignored. Denominator * parts of integers are ignored. * * given: - * q pointer to NUMBER to examine + * q pointer to NUMBER to examine * * returns: - * value size + * value size */ S_FUNC size_t qsize(NUMBER *q) { - /* ignore denominator parts of integers */ - if (qisint(q)) { - return zsize(q->num); - } else { - return (zsize(q->num) + zsize(q->den)); - } + /* ignore denominator parts of integers */ + if (qisint(q)) { + return zsize(q->num); + } else { + return (zsize(q->num) + zsize(q->den)); + } } /* * csize - calculate memory footprint of a COMPLEX (excluding overhead) * - * The numeric -1, - and 1 storage values are ignored. Denominator + * The numeric -1, - and 1 storage values are ignored. Denominator * parts of integers are ignored. Imaginary parts of pure reals * are ignored. * * given: - * c pointer to COMPLEX to examine + * c pointer to COMPLEX to examine * * returns: - * value size + * value size */ S_FUNC size_t csize(COMPLEX *c) { - /* ignore denominator parts of integers */ - if (cisreal(c)) { - return qsize(c->real); - } else { - return (qsize(c->real) + qsize(c->imag)); - } + /* ignore denominator parts of integers */ + if (cisreal(c)) { + return qsize(c->real); + } else { + return (qsize(c->real) + qsize(c->imag)); + } } @@ -189,15 +189,15 @@ csize(COMPLEX *c) * memzsize - calculate memory footprint of a ZVALUE including overhead * * given: - * z ZVALUE to examine + * z ZVALUE to examine * * returns: - * memory footprint + * memory footprint */ S_FUNC size_t memzsize(ZVALUE z) { - return sizeof(ZVALUE) + (z.len * sizeof(HALF)); + return sizeof(ZVALUE) + (z.len * sizeof(HALF)); } @@ -205,15 +205,15 @@ memzsize(ZVALUE z) * memqsize - calculate memory footprint of a NUMBER including overhead * * given: - * q pointer of NUMBER to examine + * q pointer of NUMBER to examine * * returns: - * memory footprint + * memory footprint */ S_FUNC size_t memqsize(NUMBER *q) { - return sizeof(NUMBER) + memzsize(q->num) + memzsize(q->den); + return sizeof(NUMBER) + memzsize(q->num) + memzsize(q->den); } @@ -221,106 +221,106 @@ memqsize(NUMBER *q) * lsizeof - calculate memory footprint of a VALUE (not counting overhead) * * given: - * vp pointer of VALUE to examine + * vp pointer of VALUE to examine * * returns: - * memory footprint + * memory footprint */ size_t lsizeof(VALUE *vp) { - VALUE *p; - LISTELEM *ep; - OBJECTACTIONS *oap; - ASSOCELEM *aep; - ASSOCELEM **ept; - size_t s; - long i; + VALUE *p; + LISTELEM *ep; + OBJECTACTIONS *oap; + ASSOCELEM *aep; + ASSOCELEM **ept; + size_t s; + long i; - /* - * return information about memory footprint - * - * This is not the number of elements, see elm_count() for that info. - * This is does not include overhead, see memsize() for that info. - */ - i = 0; - s = 0; - if (vp->v_type > 0) { - switch(vp->v_type) { - case V_INT: - case V_ADDR: - case V_OCTET: - break; - case V_NUM: - s = qsize(vp->v_num); - break; - case V_COM: - s = csize(vp->v_com); - break; - case V_STR: - s = vp->v_str->s_len + 1; - break; - case V_MAT: - i = vp->v_mat->m_size; - p = vp->v_mat->m_table; - while (i-- > 0) - s += lsizeof(p++); - break; - case V_LIST: - for (ep = vp->v_list->l_first; ep; ep = ep->e_next) { - s += lsizeof(&ep->e_value); - } - break; - case V_ASSOC: - i = vp->v_assoc->a_size; - ept = vp->v_assoc->a_table; - while (i-- > 0) { - for (aep = ept[i]; aep; aep = aep->e_next) { - s += lsizeof(&aep->e_value); - } - } - break; - case V_OBJ: - oap = vp->v_obj->o_actions; - i = oap->oa_count; - p = vp->v_obj->o_table; - while (i-- > 0) - s += lsizeof(p++); - break; - case V_FILE: - s = sizeof(vp->v_file); - break; - case V_RAND: - s = sizeof(RAND); - break; - case V_RANDOM: - s = sizeof(RANDOM) + - zsize(vp->v_random->n) + - zsize(vp->v_random->r); - break; - case V_CONFIG: - s = sizeof(CONFIG) + - strlen(vp->v_config->prompt1) + - strlen(vp->v_config->prompt2) + 2; - break; - case V_HASH: - /* ignore the unused part of the union */ - s = sizeof(HASH) + - vp->v_hash->unionsize - - sizeof(vp->v_hash->h_union); - break; - case V_BLOCK: - s = vp->v_block->maxsize; - break; - case V_NBLOCK: - s = vp->v_nblock->blk->maxsize; - break; - default: - math_error("sizeof not defined for value type"); - not_reached(); - } - } - return s; + /* + * return information about memory footprint + * + * This is not the number of elements, see elm_count() for that info. + * This is does not include overhead, see memsize() for that info. + */ + i = 0; + s = 0; + if (vp->v_type > 0) { + switch(vp->v_type) { + case V_INT: + case V_ADDR: + case V_OCTET: + break; + case V_NUM: + s = qsize(vp->v_num); + break; + case V_COM: + s = csize(vp->v_com); + break; + case V_STR: + s = vp->v_str->s_len + 1; + break; + case V_MAT: + i = vp->v_mat->m_size; + p = vp->v_mat->m_table; + while (i-- > 0) + s += lsizeof(p++); + break; + case V_LIST: + for (ep = vp->v_list->l_first; ep; ep = ep->e_next) { + s += lsizeof(&ep->e_value); + } + break; + case V_ASSOC: + i = vp->v_assoc->a_size; + ept = vp->v_assoc->a_table; + while (i-- > 0) { + for (aep = ept[i]; aep; aep = aep->e_next) { + s += lsizeof(&aep->e_value); + } + } + break; + case V_OBJ: + oap = vp->v_obj->o_actions; + i = oap->oa_count; + p = vp->v_obj->o_table; + while (i-- > 0) + s += lsizeof(p++); + break; + case V_FILE: + s = sizeof(vp->v_file); + break; + case V_RAND: + s = sizeof(RAND); + break; + case V_RANDOM: + s = sizeof(RANDOM) + + zsize(vp->v_random->n) + + zsize(vp->v_random->r); + break; + case V_CONFIG: + s = sizeof(CONFIG) + + strlen(vp->v_config->prompt1) + + strlen(vp->v_config->prompt2) + 2; + break; + case V_HASH: + /* ignore the unused part of the union */ + s = sizeof(HASH) + + vp->v_hash->unionsize - + sizeof(vp->v_hash->h_union); + break; + case V_BLOCK: + s = vp->v_block->maxsize; + break; + case V_NBLOCK: + s = vp->v_nblock->blk->maxsize; + break; + default: + math_error("sizeof not defined for value type"); + not_reached(); + } + } + return s; } @@ -328,117 +328,117 @@ lsizeof(VALUE *vp) * memsize - calculate memory footprint of a VALUE including overhead * * given: - * vp pointer of VALUE to examine + * vp pointer of VALUE to examine * * returns: - * memory footprint including overhead + * memory footprint including overhead */ size_t memsize(VALUE *vp) { - size_t s; - long i, j; - VALUE *p; - LISTELEM *ep; - OBJECTACTIONS *oap; - ASSOCELEM *aep; - ASSOCELEM **ept; + size_t s; + long i, j; + VALUE *p; + LISTELEM *ep; + OBJECTACTIONS *oap; + ASSOCELEM *aep; + ASSOCELEM **ept; - /* - * return information about memory footprint - * - * This is not the sizeof, see memsize() for that information. - * This is not the number of elements, see elm_count() for that info. - */ - i = j = 0; - s = sizeof(VALUE); - if (vp->v_type > 0) { - switch(vp->v_type) { - case V_INT: - case V_ADDR: - case V_OCTET: - break; - case V_NUM: - s = memqsize(vp->v_num); - break; - case V_COM: - s = sizeof(COMPLEX) + - memqsize(vp->v_com->real) + - memqsize(vp->v_com->imag); - break; - case V_STR: - s = sizeof(STRING) + vp->v_str->s_len + 1; - break; - case V_MAT: - s = sizeof(MATRIX); - i = vp->v_mat->m_size; - p = vp->v_mat->m_table; - while (i-- > 0) - s += memsize(p++); - break; - case V_LIST: - s = sizeof(LIST); - for (ep = vp->v_list->l_first; ep; ep = ep->e_next) { - s += sizeof(LISTELEM) - sizeof(VALUE) + - memsize(&ep->e_value); - } - break; - case V_ASSOC: - s = sizeof(ASSOC); - i = vp->v_assoc->a_size; - ept = vp->v_assoc->a_table; - while (i-- > 0) { - s += sizeof(ASSOCELEM *); - for (aep = *ept++; aep; aep = aep->e_next) { - s += sizeof(ASSOCELEM) - sizeof(VALUE) + - memsize(&aep->e_value); - j = aep->e_dim; - p = aep->e_indices; - while (j-- > 0) - s += memsize(p++); - } - } - break; - case V_OBJ: - s = sizeof(OBJECT); - oap = vp->v_obj->o_actions; - i = oap->oa_count; - s += (i + 3) * sizeof(int); - p = vp->v_obj->o_table; - while (i-- > 0) - s += memsize(p++); - break; - case V_FILE: - s = sizeof(vp->v_file); - break; - case V_RAND: - s = sizeof(RAND); - break; - case V_RANDOM: - s = sizeof(RANDOM) + - memzsize(vp->v_random->n) + - memzsize(vp->v_random->r); - break; - case V_CONFIG: - s = sizeof(CONFIG) + 2 + - strlen(vp->v_config->prompt1) + - strlen(vp->v_config->prompt2); - break; - case V_HASH: - s = sizeof(HASH); - break; - case V_BLOCK: - s = sizeof(BLOCK) + vp->v_block->maxsize; - break; - case V_NBLOCK: - s = sizeof(NBLOCK) + sizeof(BLOCK) + - vp->v_nblock->blk->maxsize + - strlen(vp->v_nblock->name) + 1; - break; - default: - math_error("memsize not defined for value type"); - not_reached(); - } - } - return s; + /* + * return information about memory footprint + * + * This is not the sizeof, see memsize() for that information. + * This is not the number of elements, see elm_count() for that info. + */ + i = j = 0; + s = sizeof(VALUE); + if (vp->v_type > 0) { + switch(vp->v_type) { + case V_INT: + case V_ADDR: + case V_OCTET: + break; + case V_NUM: + s = memqsize(vp->v_num); + break; + case V_COM: + s = sizeof(COMPLEX) + + memqsize(vp->v_com->real) + + memqsize(vp->v_com->imag); + break; + case V_STR: + s = sizeof(STRING) + vp->v_str->s_len + 1; + break; + case V_MAT: + s = sizeof(MATRIX); + i = vp->v_mat->m_size; + p = vp->v_mat->m_table; + while (i-- > 0) + s += memsize(p++); + break; + case V_LIST: + s = sizeof(LIST); + for (ep = vp->v_list->l_first; ep; ep = ep->e_next) { + s += sizeof(LISTELEM) - sizeof(VALUE) + + memsize(&ep->e_value); + } + break; + case V_ASSOC: + s = sizeof(ASSOC); + i = vp->v_assoc->a_size; + ept = vp->v_assoc->a_table; + while (i-- > 0) { + s += sizeof(ASSOCELEM *); + for (aep = *ept++; aep; aep = aep->e_next) { + s += sizeof(ASSOCELEM) - sizeof(VALUE) + + memsize(&aep->e_value); + j = aep->e_dim; + p = aep->e_indices; + while (j-- > 0) + s += memsize(p++); + } + } + break; + case V_OBJ: + s = sizeof(OBJECT); + oap = vp->v_obj->o_actions; + i = oap->oa_count; + s += (i + 3) * sizeof(int); + p = vp->v_obj->o_table; + while (i-- > 0) + s += memsize(p++); + break; + case V_FILE: + s = sizeof(vp->v_file); + break; + case V_RAND: + s = sizeof(RAND); + break; + case V_RANDOM: + s = sizeof(RANDOM) + + memzsize(vp->v_random->n) + + memzsize(vp->v_random->r); + break; + case V_CONFIG: + s = sizeof(CONFIG) + 2 + + strlen(vp->v_config->prompt1) + + strlen(vp->v_config->prompt2); + break; + case V_HASH: + s = sizeof(HASH); + break; + case V_BLOCK: + s = sizeof(BLOCK) + vp->v_block->maxsize; + break; + case V_NBLOCK: + s = sizeof(NBLOCK) + sizeof(BLOCK) + + vp->v_nblock->blk->maxsize + + strlen(vp->v_nblock->name) + 1; + break; + default: + math_error("memsize not defined for value type"); + not_reached(); + } + } + return s; } diff --git a/str.c b/str.c index 94d205c..394eb29 100644 --- a/str.c +++ b/str.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:10 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:10 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -39,24 +39,24 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define STR_TABLECHUNK (1<<10) /* how often to reallocate string table */ -#define STR_CHUNK (1<<16) /* size of string storage allocation */ -#define OCTET_VALUES 256 /* number of different values in a OCTET */ -#define STR_UNIQUE (1<<7) /* size of string to allocate separately */ +#define STR_TABLECHUNK (1<<10) /* how often to reallocate string table */ +#define STR_CHUNK (1<<16) /* size of string storage allocation */ +#define OCTET_VALUES 256 /* number of different values in a OCTET */ +#define STR_UNIQUE (1<<7) /* size of string to allocate separately */ STRING _nullstring_ = {"", 0, 1, NULL}; -STATIC char *chartable; /* single character string table */ +STATIC char *chartable; /* single character string table */ STATIC struct { - long l_count; /* count of strings in table */ - long l_maxcount; /* maximum strings storable in table */ - size_t l_avail; /* characters available in current string */ - char *l_alloc; /* next available string storage */ - char **l_table; /* current string table */ + long l_count; /* count of strings in table */ + long l_maxcount; /* maximum strings storable in table */ + size_t l_avail; /* characters available in current string */ + char *l_alloc; /* next available string storage */ + char **l_table; /* current string table */ } literals; @@ -64,27 +64,27 @@ STATIC struct { * Initialize or reinitialize a string header for use. * * given: - * hp structure to be inited + * hp structure to be inited */ void initstr(STRINGHEAD *hp) { - if (hp->h_list == NULL) { - /* alloc + 1 guard paranoia */ - hp->h_list = (char *)malloc(STR_CHUNK + 1); - if (hp->h_list == NULL) { - math_error("Cannot allocate string header"); - not_reached(); - } - hp->h_list[STR_CHUNK] = '\0'; /* guard paranoia */ - hp->h_avail = STR_CHUNK; - hp->h_used = 0; - } - hp->h_avail += hp->h_used; - hp->h_used = 0; - hp->h_count = 0; - hp->h_list[0] = '\0'; - hp->h_list[1] = '\0'; + if (hp->h_list == NULL) { + /* alloc + 1 guard paranoia */ + hp->h_list = (char *)malloc(STR_CHUNK + 1); + if (hp->h_list == NULL) { + math_error("Cannot allocate string header"); + not_reached(); + } + hp->h_list[STR_CHUNK] = '\0'; /* guard paranoia */ + hp->h_avail = STR_CHUNK; + hp->h_used = 0; + } + hp->h_avail += hp->h_used; + hp->h_used = 0; + hp->h_count = 0; + hp->h_list[0] = '\0'; + hp->h_list[1] = '\0'; } @@ -95,38 +95,38 @@ initstr(STRINGHEAD *hp) * The string cannot be null or have embedded nulls. * * given: - * hp header of string storage - * str string to be added + * hp header of string storage + * str string to be added */ char * addstr(STRINGHEAD *hp, char *str) { - char *retstr; /* returned string pointer */ - char *list; /* string list */ - long newsize; /* new size of string list */ - size_t len; /* length of current string */ + char *retstr; /* returned string pointer */ + char *list; /* string list */ + long newsize; /* new size of string list */ + size_t len; /* length of current string */ - if ((str == NULL) || (*str == '\0')) - return NULL; - len = strlen(str) + 1; - if (len >= hp->h_avail) { - /* alloc + 1 guard paranoia */ - newsize = len + STR_CHUNK + hp->h_used + hp->h_avail + 1; - /* alloc + 1 guard paranoia */ - list = (char *)realloc(hp->h_list, newsize + 1); - if (list == NULL) - return NULL; - list[newsize] = '\0'; /* guard paranoia */ - hp->h_list = list; - hp->h_avail = newsize - hp->h_used; - } - retstr = hp->h_list + hp->h_used; - hp->h_used += len; - hp->h_avail -= len; - hp->h_count++; - strlcpy(retstr, str, len); - retstr[len] = '\0'; - return retstr; + if ((str == NULL) || (*str == '\0')) + return NULL; + len = strlen(str) + 1; + if (len >= hp->h_avail) { + /* alloc + 1 guard paranoia */ + newsize = len + STR_CHUNK + hp->h_used + hp->h_avail + 1; + /* alloc + 1 guard paranoia */ + list = (char *)realloc(hp->h_list, newsize + 1); + if (list == NULL) + return NULL; + list[newsize] = '\0'; /* guard paranoia */ + hp->h_list = list; + hp->h_avail = newsize - hp->h_used; + } + retstr = hp->h_list + hp->h_used; + hp->h_used += len; + hp->h_avail -= len; + hp->h_count++; + strlcpy(retstr, str, len); + retstr[len] = '\0'; + return retstr; } @@ -137,59 +137,59 @@ addstr(STRINGHEAD *hp, char *str) char * charstr(int ch) { - char *cp; - int i; + char *cp; + int i; - if (chartable == NULL) { - /* alloc + 1 guard paranoia */ - cp = (char *)malloc((OCTET_VALUES + 1)*2); - if (cp == NULL) { - math_error("Cannot allocate character table"); - not_reached(); - } - for (i = 0; i < OCTET_VALUES; i++) { - *cp++ = (char)i; - *cp++ = '\0'; - } - chartable = cp - (OCTET_VALUES*2); - *cp++ = '\0'; /* guard paranoia */ - *cp++ = '\0'; /* guard paranoia */ - } - return &chartable[(ch & 0xff) * 2]; + if (chartable == NULL) { + /* alloc + 1 guard paranoia */ + cp = (char *)malloc((OCTET_VALUES + 1)*2); + if (cp == NULL) { + math_error("Cannot allocate character table"); + not_reached(); + } + for (i = 0; i < OCTET_VALUES; i++) { + *cp++ = (char)i; + *cp++ = '\0'; + } + chartable = cp - (OCTET_VALUES*2); + *cp++ = '\0'; /* guard paranoia */ + *cp++ = '\0'; /* guard paranoia */ + } + return &chartable[(ch & 0xff) * 2]; } /* * Find a string with the specified name and return its number in the - * string list. The first string is numbered zero. Minus one is returned + * string list. The first string is numbered zero. Minus one is returned * if the string is not found. * * given: - * hp header of string storage - * str string to be added + * hp header of string storage + * str string to be added */ int findstr(STRINGHEAD *hp, char *str) { - register char *test; /* string being tested */ - size_t len; /* length of string being found */ - size_t testlen; /* length of test string */ - int index; /* index of string */ + register char *test; /* string being tested */ + size_t len; /* length of string being found */ + size_t testlen; /* length of test string */ + int index; /* index of string */ - if ((hp->h_count <= 0) || (str == NULL)) - return -1; - len = strlen(str); - test = hp->h_list; - index = 0; - while (*test) { - testlen = strlen(test); - if ((testlen == len) && (*test == *str) && - (strcmp(test, str) == 0)) - return index; - test += (testlen + 1); - index++; - } - return -1; + if ((hp->h_count <= 0) || (str == NULL)) + return -1; + len = strlen(str); + test = hp->h_list; + index = 0; + while (*test) { + testlen = strlen(test); + if ((testlen == len) && (*test == *str) && + (strcmp(test, str) == 0)) + return index; + test += (testlen + 1); + index++; + } + return -1; } @@ -198,57 +198,57 @@ findstr(STRINGHEAD *hp, char *str) * If the index is illegal, a pointer to an empty string is returned. * * given: - * hp header of string storage - * n string index + * hp header of string storage + * n string index */ char * namestr(STRINGHEAD *hp, long n) { - register char *str; /* current string */ + register char *str; /* current string */ - if (n >= hp->h_count) - return ""; - str = hp->h_list; - while (*str) { - if (--n < 0) - return str; - str += (strlen(str) + 1); - } - return ""; + if (n >= hp->h_count) + return ""; + str = hp->h_list; + while (*str) { + if (--n < 0) + return str; + str += (strlen(str) + 1); + } + return ""; } /* * Useful routine to return the index of one string within another one * which has the format: "str1\000str2\000str3\000...strn\0\0". Index starts - * at one for the first string. Returns zero if the string being checked + * at one for the first string. Returns zero if the string being checked * is not contained in the formatted string. * * Be sure to use \000 instead of \0. ANSI-C compilers interpret "foo\0foo..." * as "foo\017oo...". * * given: - * format string formatted into substrings - * test string to be found in formatted string + * format string formatted into substrings + * test string to be found in formatted string */ long stringindex(char *format, char *test) { - long index; /* found index */ - size_t len; /* length of current piece of string */ - size_t testlen; /* length of test string */ + long index; /* found index */ + size_t len; /* length of current piece of string */ + size_t testlen; /* length of test string */ - testlen = strlen(test); - index = 1; - while (*format) { - len = strlen(format); - if ((len == testlen) && (*format == *test) && - (strcmp(format, test) == 0)) - return index; - format += (len + 1); - index++; - } - return 0; + testlen = strlen(test); + index = 1; + while (*format) { + len = strlen(format); + if ((len == testlen) && (*format == *test) && + (strcmp(format, test) == 0)) + return index; + format += (len + 1); + index++; + } + return 0; } @@ -260,119 +260,119 @@ stringindex(char *format, char *test) char * addliteral(char *str) { - register char **table; /* table of strings */ - char *newstr; /* newly allocated string */ - long count; /* number of strings */ - size_t len; /* length of string to allocate */ + register char **table; /* table of strings */ + char *newstr; /* newly allocated string */ + long count; /* number of strings */ + size_t len; /* length of string to allocate */ - len = strlen(str); - if (len <= 1) - return charstr(*str); - /* - * See if the string is already in the table. - */ - table = literals.l_table; - count = literals.l_count; - while (count-- > 0) { - if ((str[0] == table[0][0]) && (str[1] == table[0][1]) && - (strcmp(str, table[0]) == 0)) - return table[0]; - table++; - } - /* - * Make the table of string pointers larger if necessary. - */ - if (literals.l_count >= literals.l_maxcount) { - count = literals.l_maxcount + STR_TABLECHUNK; - if (literals.l_maxcount) { - /* alloc + 1 guard paranoia */ - table = (char **) realloc(literals.l_table, - (count + 1) * sizeof(char *)); - table[count] = NULL; /* guard paranoia */ - } else { - /* alloc + 1 guard paranoia */ - table = (char **) malloc((count + 1) * sizeof(char *)); - table[count] = NULL; /* guard paranoia */ - } - if (table == NULL) { - math_error("Cannot allocate string literal table"); - not_reached(); - } - literals.l_table = table; - literals.l_maxcount = count; - } - table = literals.l_table; - /* - * If the new string is very long, allocate it manually. - * - * Add room for trailing NUL and then round up to a - * memory chunk (in this case we pick the size of a FULL - * just because that is a nice size) for extra padded room. - */ - len = ROUNDUP(len+1, FULL_LEN); - if (len >= STR_UNIQUE) { - /* alloc + 1 guard paranoia */ - newstr = (char *)malloc(len + 1); - if (newstr == NULL) { - math_error("Cannot allocate large literal string"); - not_reached(); - } - newstr[len] = '\0'; /* guard paranoia */ - strlcpy(newstr, str, len); - table[literals.l_count++] = newstr; - return newstr; - } - /* - * If the remaining space in the allocate string is too small, - * then allocate a new one. - */ - if (literals.l_avail < len) { - /* alloc + 1 guard paranoia */ - newstr = (char *)malloc(STR_CHUNK + 1); - if (newstr == NULL) { - math_error("Cannot allocate new literal string"); - not_reached(); - } - newstr[STR_CHUNK] = '\0'; /* guard paranoia */ - literals.l_alloc = newstr; - literals.l_avail = STR_CHUNK; - } - /* - * Allocate the new string from the allocate string. - */ - newstr = literals.l_alloc; - literals.l_avail -= len; - literals.l_alloc += len; - table[literals.l_count++] = newstr; - strlcpy(newstr, str, len); - return newstr; + len = strlen(str); + if (len <= 1) + return charstr(*str); + /* + * See if the string is already in the table. + */ + table = literals.l_table; + count = literals.l_count; + while (count-- > 0) { + if ((str[0] == table[0][0]) && (str[1] == table[0][1]) && + (strcmp(str, table[0]) == 0)) + return table[0]; + table++; + } + /* + * Make the table of string pointers larger if necessary. + */ + if (literals.l_count >= literals.l_maxcount) { + count = literals.l_maxcount + STR_TABLECHUNK; + if (literals.l_maxcount) { + /* alloc + 1 guard paranoia */ + table = (char **) realloc(literals.l_table, + (count + 1) * sizeof(char *)); + table[count] = NULL; /* guard paranoia */ + } else { + /* alloc + 1 guard paranoia */ + table = (char **) malloc((count + 1) * sizeof(char *)); + table[count] = NULL; /* guard paranoia */ + } + if (table == NULL) { + math_error("Cannot allocate string literal table"); + not_reached(); + } + literals.l_table = table; + literals.l_maxcount = count; + } + table = literals.l_table; + /* + * If the new string is very long, allocate it manually. + * + * Add room for trailing NUL and then round up to a + * memory chunk (in this case we pick the size of a FULL + * just because that is a nice size) for extra padded room. + */ + len = ROUNDUP(len+1, FULL_LEN); + if (len >= STR_UNIQUE) { + /* alloc + 1 guard paranoia */ + newstr = (char *)malloc(len + 1); + if (newstr == NULL) { + math_error("Cannot allocate large literal string"); + not_reached(); + } + newstr[len] = '\0'; /* guard paranoia */ + strlcpy(newstr, str, len); + table[literals.l_count++] = newstr; + return newstr; + } + /* + * If the remaining space in the allocate string is too small, + * then allocate a new one. + */ + if (literals.l_avail < len) { + /* alloc + 1 guard paranoia */ + newstr = (char *)malloc(STR_CHUNK + 1); + if (newstr == NULL) { + math_error("Cannot allocate new literal string"); + not_reached(); + } + newstr[STR_CHUNK] = '\0'; /* guard paranoia */ + literals.l_alloc = newstr; + literals.l_avail = STR_CHUNK; + } + /* + * Allocate the new string from the allocate string. + */ + newstr = literals.l_alloc; + literals.l_avail -= len; + literals.l_alloc += len; + table[literals.l_count++] = newstr; + strlcpy(newstr, str, len); + return newstr; } STRING * stringadd(STRING *s1, STRING *s2) { - STRING *s; - char *cfrom, *c; - long len; + STRING *s; + char *cfrom, *c; + long len; - len = s1->s_len + s2->s_len; - s = stralloc(); - s->s_len = len; - s->s_str = (char *) malloc(len + 1); - if (s->s_str == NULL) - return NULL; - len = s1->s_len; - cfrom = s1->s_str; - c = s->s_str; - while (len-- > 0) - *c++ = *cfrom++; - len = s2->s_len; - cfrom = s2->s_str; - while (len-- > 0) - *c++ = *cfrom++; - *c = '\0'; - return s; + len = s1->s_len + s2->s_len; + s = stralloc(); + s->s_len = len; + s->s_str = (char *) malloc(len + 1); + if (s->s_str == NULL) + return NULL; + len = s1->s_len; + cfrom = s1->s_str; + c = s->s_str; + while (len-- > 0) + *c++ = *cfrom++; + len = s2->s_len; + cfrom = s2->s_str; + while (len-- > 0) + *c++ = *cfrom++; + *c = '\0'; + return s; } /* @@ -381,38 +381,38 @@ stringadd(STRING *s1, STRING *s2) STRING * stringneg(STRING *str) { - long len; - STRING *s; - char *c, *cfrom; + long len; + STRING *s; + char *c, *cfrom; - len = str->s_len; - if (len <= 1) - return slink(str); - c = (char *) malloc(len + 1); - if (c == NULL) - return NULL; - s = stralloc(); - s->s_len = len; - s->s_str = c; - cfrom = str->s_str + len; - while (len-- > 0) - *c++ = *--cfrom; - *c = '\0'; - return s; + len = str->s_len; + if (len <= 1) + return slink(str); + c = (char *) malloc(len + 1); + if (c == NULL) + return NULL; + s = stralloc(); + s->s_len = len; + s->s_str = c; + cfrom = str->s_str + len; + while (len-- > 0) + *c++ = *--cfrom; + *c = '\0'; + return s; } STRING * stringsub(STRING *s1, STRING *s2) { - STRING *tmp, *s; + STRING *tmp, *s; - tmp = stringneg(s2); - if (tmp == NULL) - return NULL; - s = stringadd(s1, tmp); - if (s != NULL) - sfree(tmp); - return s; + tmp = stringneg(s2); + if (tmp == NULL) + return NULL; + s = stringadd(s1, tmp); + if (s != NULL) + sfree(tmp); + return s; } /* @@ -422,298 +422,298 @@ stringsub(STRING *s1, STRING *s2) STRING * stringmul(NUMBER *q, STRING *str) { - long len; - size_t j; - NUMBER *tmp1, *tmp2; - char *c, *c1; - STRING *s; - bool neg; + long len; + size_t j; + NUMBER *tmp1, *tmp2; + char *c, *c1; + STRING *s; + bool neg; - if (str->s_len == 0) - return slink(str); - neg = qisneg(q); - q = neg ? qneg(q): qlink(q); - tmp1 = itoq(str->s_len); - tmp2 = qmul(q, tmp1); - qfree(tmp1); - tmp1 = qint(tmp2); - qfree(tmp2); - if (zge31b(tmp1->num)) { - qfree(q); - qfree(tmp1); - return NULL; - } - len = qtoi(tmp1); - qfree(tmp1); - qfree(q); - if (len == 0) - return slink(&_nullstring_); - c = (char *) malloc(len + 1); - if (c == NULL) - return NULL; - str = neg ? stringneg(str) : slink(str); - s = stralloc(); - s->s_str = c; - s->s_len = len; - j = 0; - c1 = str->s_str; - while (len-- > 0) { - *c++ = *c1++; - if (++j == str->s_len) { - j = 0; - c1 = str->s_str; - } - } - *c = '\0'; - sfree(str); - return s; + if (str->s_len == 0) + return slink(str); + neg = qisneg(q); + q = neg ? qneg(q): qlink(q); + tmp1 = itoq(str->s_len); + tmp2 = qmul(q, tmp1); + qfree(tmp1); + tmp1 = qint(tmp2); + qfree(tmp2); + if (zge31b(tmp1->num)) { + qfree(q); + qfree(tmp1); + return NULL; + } + len = qtoi(tmp1); + qfree(tmp1); + qfree(q); + if (len == 0) + return slink(&_nullstring_); + c = (char *) malloc(len + 1); + if (c == NULL) + return NULL; + str = neg ? stringneg(str) : slink(str); + s = stralloc(); + s->s_str = c; + s->s_len = len; + j = 0; + c1 = str->s_str; + while (len-- > 0) { + *c++ = *c1++; + if (++j == str->s_len) { + j = 0; + c1 = str->s_str; + } + } + *c = '\0'; + sfree(str); + return s; } STRING * stringand(STRING *s1, STRING *s2) { - STRING *s; - size_t len; - char *c1, *c2, *c; + STRING *s; + size_t len; + char *c1, *c2, *c; - if (s1->s_len == 0 || s2->s_len == 0) - return slink(&_nullstring_); - len = s1->s_len; - if (s2->s_len < len) - len = s2->s_len; - s = stralloc(); - s->s_len = len; - c = malloc(len + 1); - if (c == NULL) - return NULL; - s->s_str = c; - c1 = s1->s_str; - c2 = s2->s_str; - while (len-- > 0) - *c++ = *c1++ & *c2++; - return s; + if (s1->s_len == 0 || s2->s_len == 0) + return slink(&_nullstring_); + len = s1->s_len; + if (s2->s_len < len) + len = s2->s_len; + s = stralloc(); + s->s_len = len; + c = malloc(len + 1); + if (c == NULL) + return NULL; + s->s_str = c; + c1 = s1->s_str; + c2 = s2->s_str; + while (len-- > 0) + *c++ = *c1++ & *c2++; + return s; } STRING * stringor(STRING *s1, STRING *s2) { - STRING *s; - long len, i, j; - char *c1, *c2, *c; + STRING *s; + long len, i, j; + char *c1, *c2, *c; - if (s1->s_len < s2->s_len) { - s = s1; - s1 = s2; - s2 = s; - } /* Now len(s1) >= len(s2) */ - if (s2->s_len == 0) - return slink(s1); - i = s1->s_len; - if (i == 0) - return slink(&_nullstring_); - len = s1->s_len; - s = stralloc(); - s->s_len = len; - c = malloc(len + 1); - if (c == NULL) - return NULL; - s->s_str = c; - c1 = s1->s_str; - c2 = s2->s_str; - i = s2->s_len; - j = s1->s_len - i; - while (i-- > 0) - *c++ = *c1++ | *c2++; - while (j-- > 0) - *c++ = *c1++; - return s; + if (s1->s_len < s2->s_len) { + s = s1; + s1 = s2; + s2 = s; + } /* Now len(s1) >= len(s2) */ + if (s2->s_len == 0) + return slink(s1); + i = s1->s_len; + if (i == 0) + return slink(&_nullstring_); + len = s1->s_len; + s = stralloc(); + s->s_len = len; + c = malloc(len + 1); + if (c == NULL) + return NULL; + s->s_str = c; + c1 = s1->s_str; + c2 = s2->s_str; + i = s2->s_len; + j = s1->s_len - i; + while (i-- > 0) + *c++ = *c1++ | *c2++; + while (j-- > 0) + *c++ = *c1++; + return s; } STRING * stringxor(STRING *s1, STRING *s2) { - STRING *s; - long len, i, j; - char *c1, *c2, *c; + STRING *s; + long len, i, j; + char *c1, *c2, *c; - if (s1->s_len < s2->s_len) { - s = s1; - s1 = s2; - s2 = s; - } /* Now len(s1) >= len(s2) */ - if (s2->s_len == 0) - return slink(s1); - i = s1->s_len; - if (i == 0) - return slink(&_nullstring_); - len = s1->s_len; - s = stralloc(); - s->s_len = len; - c = malloc(len + 1); - if (c == NULL) - return NULL; - s->s_str = c; - c1 = s1->s_str; - c2 = s2->s_str; - i = s2->s_len; - j = s1->s_len - i; - while (i-- > 0) - *c++ = *c1++ ^ *c2++; - while (j-- > 0) - *c++ = *c1++; - return s; + if (s1->s_len < s2->s_len) { + s = s1; + s1 = s2; + s2 = s; + } /* Now len(s1) >= len(s2) */ + if (s2->s_len == 0) + return slink(s1); + i = s1->s_len; + if (i == 0) + return slink(&_nullstring_); + len = s1->s_len; + s = stralloc(); + s->s_len = len; + c = malloc(len + 1); + if (c == NULL) + return NULL; + s->s_str = c; + c1 = s1->s_str; + c2 = s2->s_str; + i = s2->s_len; + j = s1->s_len - i; + while (i-- > 0) + *c++ = *c1++ ^ *c2++; + while (j-- > 0) + *c++ = *c1++; + return s; } STRING * stringdiff(STRING *s1, STRING *s2) { - STRING *s; - size_t i; - char *c2, *c; + STRING *s; + size_t i; + char *c2, *c; - i = s1->s_len; - if (i == 0) - return slink(s1); - s = stringcopy(s1); - if (i > s2->s_len) - i = s2->s_len; - c = s->s_str; - c2 = s2->s_str; - while (i-- > 0) - *c++ &= ~*c2++; - return s; + i = s1->s_len; + if (i == 0) + return slink(s1); + s = stringcopy(s1); + if (i > s2->s_len) + i = s2->s_len; + c = s->s_str; + c2 = s2->s_str; + while (i-- > 0) + *c++ &= ~*c2++; + return s; } STRING * stringcomp(STRING *s1) { - long len; - STRING *s; - char *c1, *c; + long len; + STRING *s; + char *c1, *c; - len = s1->s_len; - if (len == 0) - return slink(&_nullstring_); - c = malloc(len + 1); - if (c == NULL) - return NULL; - s = stralloc(); - s->s_len = len; - s->s_str = c; - c1 = s1->s_str; - while (len-- > 0) - *c++ = ~*c1++; - *c = '\0'; - return s; + len = s1->s_len; + if (len == 0) + return slink(&_nullstring_); + c = malloc(len + 1); + if (c == NULL) + return NULL; + s = stralloc(); + s->s_len = len; + s->s_str = c; + c1 = s1->s_str; + while (len-- > 0) + *c++ = ~*c1++; + *c = '\0'; + return s; } STRING * stringsegment(STRING *s1, long n1, long n2) { - STRING *s; - char *c, *c1; - long len; + STRING *s; + char *c, *c1; + long len; - if ((n1 < 0 && n2 < 0) || - ((size_t)n1 >= s1->s_len && (size_t)n2 >= s1->s_len)) - return slink(&_nullstring_); - if (n1 < 0) - n1 = 0; - if (n2 < 0) - n2 = 0; - if ((size_t)n1 >= s1->s_len) - n1 = s1->s_len - 1; - if ((size_t)n2 >= s1->s_len) - n2 = s1->s_len - 1; - len = (n1 >= n2) ? n1 - n2 + 1 : n2 - n1 + 1; - s = stralloc(); - c = malloc(len + 1); - if (c == NULL) - return NULL; - s->s_len = len; - s->s_str = c; - c1 = s1->s_str + n1; - if (n1 >= n2) { - /* - * We prevent the c1 pointer from walking behind s1_s_str - * by stopping one short of the end and running the loop one - * more time. - * - * We could stop the loop with just len-- > 0, but stopping - * short and running the loop one last time manually helps make - * code checkers such as insure happy. - */ - while (len-- > 1) { - *c++ = *c1--; - } - /* run the loop manually one last time */ - *c++ = *c1; - } else { - while (len-- > 0) - *c++ = *c1++; - } - *c = '\0'; - return s; + if ((n1 < 0 && n2 < 0) || + ((size_t)n1 >= s1->s_len && (size_t)n2 >= s1->s_len)) + return slink(&_nullstring_); + if (n1 < 0) + n1 = 0; + if (n2 < 0) + n2 = 0; + if ((size_t)n1 >= s1->s_len) + n1 = s1->s_len - 1; + if ((size_t)n2 >= s1->s_len) + n2 = s1->s_len - 1; + len = (n1 >= n2) ? n1 - n2 + 1 : n2 - n1 + 1; + s = stralloc(); + c = malloc(len + 1); + if (c == NULL) + return NULL; + s->s_len = len; + s->s_str = c; + c1 = s1->s_str + n1; + if (n1 >= n2) { + /* + * We prevent the c1 pointer from walking behind s1_s_str + * by stopping one short of the end and running the loop one + * more time. + * + * We could stop the loop with just len-- > 0, but stopping + * short and running the loop one last time manually helps make + * code checkers such as insure happy. + */ + while (len-- > 1) { + *c++ = *c1--; + } + /* run the loop manually one last time */ + *c++ = *c1; + } else { + while (len-- > 0) + *c++ = *c1++; + } + *c = '\0'; + return s; } /* * stringshift shifts s1 n bits to left if n > 0, -n to the right if n < 0; * octets in string considered to be in decreasing order of index, as in - * ... a_3 a_2 a_1 a_0. Returned string has same length as s1. + * ... a_3 a_2 a_1 a_0. Returned string has same length as s1. * Vacated bits are filled with '\0'; bits shifted off end are lost */ STRING * stringshift(STRING *s1, long n) { - char *c1, *c; - STRING *s; - long len, i, j, k; - bool right; - char ch; + char *c1, *c; + STRING *s; + long len, i, j, k; + bool right; + char ch; - len = s1->s_len; - if (len == 0 || n == 0) - return slink(s1); - right = (n < 0); - if (right) n = -n; - j = n & 7; - k = 8 - j; - n >>= 3; - c = malloc(len + 1); - if (c == NULL) - return NULL; - s = stralloc(); - s->s_len = len; - s->s_str = c; - c[len] = '\0'; - if (n > len) - n = len; - ch = '\0'; - c1 = s1->s_str; - i = n; - if (right) { - c += len; - c1 += len; - while (i-- > 0) - *--c = '\0'; - i = len - n; - while (i-- > 0) { - *--c = ((unsigned char) *--c1 >> j) | ch; - ch = (unsigned char) *c1 << k; - } - } else { - while (i-- > 0) - *c++ = '\0'; - i = len - n; - while (i-- > 0) { - *c++ = ((unsigned char) *c1 << j) | ch; - ch = (unsigned char) *c1++ >> k; - } - } - return s; + len = s1->s_len; + if (len == 0 || n == 0) + return slink(s1); + right = (n < 0); + if (right) n = -n; + j = n & 7; + k = 8 - j; + n >>= 3; + c = malloc(len + 1); + if (c == NULL) + return NULL; + s = stralloc(); + s->s_len = len; + s->s_str = c; + c[len] = '\0'; + if (n > len) + n = len; + ch = '\0'; + c1 = s1->s_str; + i = n; + if (right) { + c += len; + c1 += len; + while (i-- > 0) + *--c = '\0'; + i = len - n; + while (i-- > 0) { + *--c = ((unsigned char) *--c1 >> j) | ch; + ch = (unsigned char) *c1 << k; + } + } else { + while (i-- > 0) + *c++ = '\0'; + i = len - n; + while (i-- > 0) { + *c++ = ((unsigned char) *c1 << j) | ch; + ch = (unsigned char) *c1++ >> k; + } + } + return s; } /* @@ -764,20 +764,20 @@ stringtolower(STRING *st) STRING * stringcpy(STRING *s1, STRING *s2) { - char *c1, *c2; - size_t num; + char *c1, *c2; + size_t num; - if (s1->s_len > 0) { - c1 = s1->s_str; - c2 = s2->s_str; - num = s1->s_len; - if (num > s2->s_len) - num = s2->s_len; - while (num-- > 0) - *c1++ = *c2++; - *c1 = '\0'; - } - return slink(s1); + if (s1->s_len > 0) { + c1 = s1->s_str; + c2 = s2->s_str; + num = s1->s_len; + if (num > s2->s_len) + num = s2->s_len; + while (num-- > 0) + *c1++ = *c2++; + *c1 = '\0'; + } + return slink(s1); } /* @@ -788,22 +788,22 @@ stringcpy(STRING *s1, STRING *s2) STRING * stringncpy(STRING *s1, STRING *s2, size_t num) { - char *c1, *c2; - size_t i; + char *c1, *c2; + size_t i; - if (num > s1->s_len) - num = s1->s_len; - i = num; - if (i > s2->s_len) - i = s2->s_len; - c1 = s1->s_str; - c2 = s2->s_str; - while (i-- > 0) - *c1++ = *c2++; - if (num > s2->s_len) { - memset(c1, 0, num - s2->s_len); - } - return slink(s1); + if (num > s1->s_len) + num = s1->s_len; + i = num; + if (i > s2->s_len) + i = s2->s_len; + c1 = s1->s_str; + c2 = s2->s_str; + while (i-- > 0) + *c1++ = *c2++; + if (num > s2->s_len) { + memset(c1, 0, num - s2->s_len); + } + return slink(s1); } @@ -813,54 +813,54 @@ stringncpy(STRING *s1, STRING *s2, size_t num) long stringcontent(STRING *s) { - char *c; - unsigned char ch; - long count; - long len; + char *c; + unsigned char ch; + long count; + long len; - len = s->s_len; - count = 0; - c = s->s_str; - while (len-- > 0) { - ch = *c++; - while (ch) { - count += (ch & 1); - ch >>= 1; - } - } - return count; + len = s->s_len; + count = 0; + c = s->s_str; + while (len-- > 0) { + ch = *c++; + while (ch) { + count += (ch & 1); + ch >>= 1; + } + } + return count; } long stringhighbit(STRING *s) { - char *c; - unsigned char ch; - long i; + char *c; + unsigned char ch; + long i; - i = s->s_len; - c = s->s_str + i; - while (--i >= 0 && *--c == '\0'); - if (i < 0) - return -1; - i <<= 3; - for (ch = *c; ch >>= 1; i++); - return i; + i = s->s_len; + c = s->s_str + i; + while (--i >= 0 && *--c == '\0'); + if (i < 0) + return -1; + i <<= 3; + for (ch = *c; ch >>= 1; i++); + return i; } long stringlowbit(STRING *s) { - char *c; - unsigned char ch; - long i; + char *c; + unsigned char ch; + long i; - for (i = s->s_len, c = s->s_str; i > 0 && *c == '\0'; i--, c++); - if (i == 0) - return -1; - i = (s->s_len - i) << 3; - for (ch = *c; !(ch & 1); ch >>= 1, i++); - return i; + for (i = s->s_len, c = s->s_str; i > 0 && *c == '\0'; i--, c++); + if (i == 0) + return -1; + i = (s->s_len - i) << 3; + for (ch = *c; !(ch & 1); ch >>= 1, i++); + return i; } @@ -872,11 +872,11 @@ stringlowbit(STRING *s) S_FUNC bool stringcompare(char *c1, char *c2, long len) { - while (len-- > 0) { - if (*c1++ != *c2++) - return true; - } - return false; + while (len-- > 0) { + if (*c1++ != *c2++) + return true; + } + return false; } /* @@ -885,9 +885,9 @@ stringcompare(char *c1, char *c2, long len) bool stringcmp(STRING *s1, STRING *s2) { - if (s1->s_len != s2->s_len) - return true; - return stringcompare(s1->s_str, s2->s_str, s1->s_len); + if (s1->s_len != s2->s_len) + return true; + return stringcompare(s1->s_str, s2->s_str, s1->s_len); } @@ -901,30 +901,30 @@ stringcmp(STRING *s1, STRING *s2) FLAG stringrel(STRING *s1, STRING *s2) { - char *c1, *c2; - long i1, i2; + char *c1, *c2; + long i1, i2; - if (s1 == s2) - return 0; + if (s1 == s2) + return 0; - i1 = s1->s_len; - i2 = s2->s_len; - if (i2 == 0) - return (i1 > 0); - if (i1 == 0) - return -1; - c1 = s1->s_str; - c2 = s2->s_str; - while (i1 > 1 && i2 > 1 && *c1 == *c2) { - i1--; - i2--; - c1++; - c2++; - } - if ((unsigned char) *c1 > (unsigned char) *c2) return 1; - if ((unsigned char) *c1 < (unsigned char) *c2) return -1; - if (i1 < i2) return -1; - return (i1 > i2); + i1 = s1->s_len; + i2 = s2->s_len; + if (i2 == 0) + return (i1 > 0); + if (i1 == 0) + return -1; + c1 = s1->s_str; + c2 = s2->s_str; + while (i1 > 1 && i2 > 1 && *c1 == *c2) { + i1--; + i2--; + c1++; + c2++; + } + if ((unsigned char) *c1 > (unsigned char) *c2) return 1; + if ((unsigned char) *c1 < (unsigned char) *c2) return -1; + if (i1 < i2) return -1; + return (i1 > i2); } /* Case independent stringrel(STRING *s1, STRING *s2) @@ -937,70 +937,70 @@ stringrel(STRING *s1, STRING *s2) FLAG stringcaserel(STRING *s1, STRING *s2) { - char *c1, *c2; - long i1, i2; + char *c1, *c2; + long i1, i2; - if (s1 == s2) - return 0; + if (s1 == s2) + return 0; - i1 = s1->s_len; - i2 = s2->s_len; - if (i2 == 0) - return (i1 > 0); - if (i1 == 0) - return -1; - c1 = s1->s_str; - c2 = s2->s_str; - while (i1 > 1 && i2 > 1 && tolower(*c1) == tolower(*c2)) { - i1--; - i2--; - c1++; - c2++; - } - if ( (tolower(*c1)) > (tolower(*c2))) - return 1; - if ( (tolower(*c1)) < (tolower(*c2))) - return -1; - if (i1 < i2) return -1; - return (i1 > i2); + i1 = s1->s_len; + i2 = s2->s_len; + if (i2 == 0) + return (i1 > 0); + if (i1 == 0) + return -1; + c1 = s1->s_str; + c2 = s2->s_str; + while (i1 > 1 && i2 > 1 && tolower(*c1) == tolower(*c2)) { + i1--; + i2--; + c1++; + c2++; + } + if ( (tolower(*c1)) > (tolower(*c2))) + return 1; + if ( (tolower(*c1)) < (tolower(*c2))) + return -1; + if (i1 < i2) return -1; + return (i1 > i2); } /* * str with characters c0, c1, ... is considered as a bitstream, 8 bits * per character; within a character the bits ordered from low order to - * high order. For 0 <= i < 8 * length of str, stringbit returns 1 or 0 + * high order. For 0 <= i < 8 * length of str, stringbit returns 1 or 0 * according as the bit with index i is set or not set; other values of i * return -1. */ int stringbit(STRING *s, long index) { - unsigned int ch; - int res; + unsigned int ch; + int res; - if (index < 0) - return -1; - res = index & 7; - index >>= 3; - if ((size_t)index >= s->s_len) - return -1; - ch = s->s_str[index]; - return (ch >> res) & 1; + if (index < 0) + return -1; + res = index & 7; + index >>= 3; + if ((size_t)index >= s->s_len) + return -1; + ch = s->s_str[index]; + return (ch >> res) & 1; } bool stringtest(STRING *s) { - long i; - char *c; + long i; + char *c; - i = s->s_len; - c = s->s_str; - while (i-- > 0) { - if (*c++) - return true; - } - return false; + i = s->s_len; + c = s->s_str; + while (i-- > 0) { + if (*c++) + return true; + } + return false; } /* @@ -1011,20 +1011,20 @@ stringtest(STRING *s) int stringsetbit(STRING *s, long index, bool val) { - char *c; - int bit; + char *c; + int bit; - if (index < 0) - return 1; - bit = 1 << (index & 7); - index >>= 3; - if ((size_t)index >= s->s_len) - return 2; - c = &s->s_str[index]; - *c &= ~bit; - if (val) - *c |= bit; - return 0; + if (index < 0) + return 1; + bit = 1 << (index & 7); + index >>= 3; + if ((size_t)index >= s->s_len) + return 2; + c = &s->s_str[index]; + *c &= ~bit; + if (val) + *c |= bit; + return 0; } /* @@ -1035,74 +1035,74 @@ stringsetbit(STRING *s, long index, bool val) int stringsearch(STRING *s1, STRING *s2, long start, long end, ZVALUE *index) { - long len2, i, j; - char *c1, *c2, *c; - char ch; + long len2, i, j; + char *c1, *c2, *c; + char ch; - len2 = s2->s_len; - if (start < 0) - start = 0; - if (end < start + len2) - return -1; - if (len2 == 0) { - itoz(start, index); - return 0; - } - i = end - start - len2; - c1 = s1->s_str + start; - ch = *s2->s_str; - while (i-- >= 0) { - if (*c1++ == ch) { - c = c1; - c2 = s2->s_str; - j = len2; - while (--j > 0 && *c++ == *++c2); - if (j == 0) { - itoz(end - len2 - i - 1, index); - return 0; - } - } - } - return -1; + len2 = s2->s_len; + if (start < 0) + start = 0; + if (end < start + len2) + return -1; + if (len2 == 0) { + itoz(start, index); + return 0; + } + i = end - start - len2; + c1 = s1->s_str + start; + ch = *s2->s_str; + while (i-- >= 0) { + if (*c1++ == ch) { + c = c1; + c2 = s2->s_str; + j = len2; + while (--j > 0 && *c++ == *++c2); + if (j == 0) { + itoz(end - len2 - i - 1, index); + return 0; + } + } + } + return -1; } int stringrsearch(STRING *s1, STRING *s2, long start, long end, ZVALUE *index) { - long len1, len2, i, j; - char *c1, *c2, *c, *c2top; - char ch; + long len1, len2, i, j; + char *c1, *c2, *c, *c2top; + char ch; - len1 = s1->s_len; - len2 = s2->s_len; - if (start < 0) - start = 0; - if (end > len1) - end = len1; - if (end < start + len2) - return -1; - if (len2 == 0) { - itoz(start, index); - return 0; - } - i = end - start - len2 + 1; - c1 = s1->s_str + end - 1; - c2top = s2->s_str + len2 - 1; - ch = *c2top; + len1 = s1->s_len; + len2 = s2->s_len; + if (start < 0) + start = 0; + if (end > len1) + end = len1; + if (end < start + len2) + return -1; + if (len2 == 0) { + itoz(start, index); + return 0; + } + i = end - start - len2 + 1; + c1 = s1->s_str + end - 1; + c2top = s2->s_str + len2 - 1; + ch = *c2top; - while (--i >= 0) { - if (*c1-- == ch) { - c = c1; - j = len2; - c2 = c2top; - while (--j > 0 && *c-- == *--c2); - if (j == 0) { - itoz(start + i, index); - return 0; - } - } - } - return -1; + while (--i >= 0) { + if (*c1-- == ch) { + c = c1; + j = len2; + c2 = c2top; + while (--j > 0 && *c-- == *--c2); + if (j == 0) { + itoz(start + i, index); + return 0; + } + } + } + return -1; } @@ -1110,73 +1110,73 @@ stringrsearch(STRING *s1, STRING *s2, long start, long end, ZVALUE *index) * String allocation routines */ -#define STRALLOC 100 +#define STRALLOC 100 -STATIC STRING *freeStr = NULL; -STATIC STRING **firstStrs = NULL; -STATIC long blockcount = 0; +STATIC STRING *freeStr = NULL; +STATIC STRING **firstStrs = NULL; +STATIC long blockcount = 0; STRING * stralloc(void) { - STRING *temp; - STRING **newfn; + STRING *temp; + STRING **newfn; - if (freeStr == NULL) { - /* alloc + 1 guard paranoia */ - freeStr = (STRING *) malloc(sizeof (STRING) * (STRALLOC + 1)); - if (freeStr == NULL) { - math_error("Unable to allocate memory for stralloc"); - not_reached(); - } - /* guard paranoia */ - memset(freeStr+STRALLOC, 0, sizeof(STRING)); - freeStr[STRALLOC - 1].s_next = NULL; - freeStr[STRALLOC - 1].s_links = 0; + if (freeStr == NULL) { + /* alloc + 1 guard paranoia */ + freeStr = (STRING *) malloc(sizeof (STRING) * (STRALLOC + 1)); + if (freeStr == NULL) { + math_error("Unable to allocate memory for stralloc"); + not_reached(); + } + /* guard paranoia */ + memset(freeStr+STRALLOC, 0, sizeof(STRING)); + freeStr[STRALLOC - 1].s_next = NULL; + freeStr[STRALLOC - 1].s_links = 0; - /* - * We prevent the temp pointer from walking behind freeStr - * by stopping one short of the end and running the loop one - * more time. - * - * We would stop the loop with just temp >= freeStr, but - * doing this helps make code checkers such as insure happy. - */ - for (temp = freeStr + STRALLOC - 2; temp > freeStr; --temp) { - temp->s_next = temp + 1; - temp->s_links = 0; - } - /* run the loop manually one last time */ - temp->s_next = temp + 1; - temp->s_links = 0; + /* + * We prevent the temp pointer from walking behind freeStr + * by stopping one short of the end and running the loop one + * more time. + * + * We would stop the loop with just temp >= freeStr, but + * doing this helps make code checkers such as insure happy. + */ + for (temp = freeStr + STRALLOC - 2; temp > freeStr; --temp) { + temp->s_next = temp + 1; + temp->s_links = 0; + } + /* run the loop manually one last time */ + temp->s_next = temp + 1; + temp->s_links = 0; - blockcount++; - if (firstStrs == NULL) { - /* alloc + 1 guard paranoia */ - newfn = (STRING **) - malloc((blockcount + 1) * sizeof(STRING *)); - newfn[blockcount] = NULL; /* guard paranoia */ - } else { - /* alloc + 1 guard paranoia */ - newfn = (STRING **) - realloc(firstStrs, - (blockcount + 1) * sizeof(STRING *)); - newfn[blockcount] = NULL; /* guard paranoia */ - } - if (newfn == NULL) { - math_error("Cannot allocate new string block"); - not_reached(); - } - firstStrs = newfn; - firstStrs[blockcount - 1] = freeStr; - } - temp = freeStr; - freeStr = temp->s_next; - temp->s_links = 1; - temp->s_str = NULL; - return temp; + blockcount++; + if (firstStrs == NULL) { + /* alloc + 1 guard paranoia */ + newfn = (STRING **) + malloc((blockcount + 1) * sizeof(STRING *)); + newfn[blockcount] = NULL; /* guard paranoia */ + } else { + /* alloc + 1 guard paranoia */ + newfn = (STRING **) + realloc(firstStrs, + (blockcount + 1) * sizeof(STRING *)); + newfn[blockcount] = NULL; /* guard paranoia */ + } + if (newfn == NULL) { + math_error("Cannot allocate new string block"); + not_reached(); + } + firstStrs = newfn; + firstStrs[blockcount - 1] = freeStr; + } + temp = freeStr; + freeStr = temp->s_next; + temp->s_links = 1; + temp->s_str = NULL; + return temp; } @@ -1186,33 +1186,33 @@ stralloc(void) STRING * makestring(char *str) { - STRING *s; - size_t len; + STRING *s; + size_t len; - len = strlen(str); - s = stralloc(); - s->s_str = str; - s->s_len = len; - return s; + len = strlen(str); + s = stralloc(); + s->s_str = str; + s->s_len = len; + return s; } STRING * charstring(int ch) { - STRING *s; - char *c; + STRING *s; + char *c; - c = (char *) malloc(2); - if (c == NULL) { - math_error("Allocation failure for charstring"); - not_reached(); - } - s = stralloc(); - s->s_len = 1; - s->s_str = c; - *c++ = (char) ch; - *c = '\0'; - return s; + c = (char *) malloc(2); + if (c == NULL) { + math_error("Allocation failure for charstring"); + not_reached(); + } + s = stralloc(); + s->s_len = 1; + s->s_str = c; + *c++ = (char) ch; + *c = '\0'; + return s; } @@ -1223,96 +1223,96 @@ charstring(int ch) STRING * makenewstring(char *str) { - STRING *s; - char *c; - size_t len; + STRING *s; + char *c; + size_t len; - len = strlen(str); - if (len == 0) - return slink(&_nullstring_); - c = (char *) malloc(len + 1); - if (c == NULL) { - math_error("malloc for makenewstring failed"); - not_reached(); - } - s = stralloc(); - s->s_str = c; - s->s_len = len; - memcpy(c, str, len); - c[len] = '\0'; - return s; + len = strlen(str); + if (len == 0) + return slink(&_nullstring_); + c = (char *) malloc(len + 1); + if (c == NULL) { + math_error("malloc for makenewstring failed"); + not_reached(); + } + s = stralloc(); + s->s_str = c; + s->s_len = len; + memcpy(c, str, len); + c[len] = '\0'; + return s; } STRING * stringcopy (STRING *s1) { - STRING *s; - char *c; - long len; + STRING *s; + char *c; + long len; - len = s1->s_len; - if (len == 0) - return slink(s1); - c = malloc(len + 1); - if (c == NULL) { - math_error("Malloc failed for stringcopy"); - not_reached(); - } - s = stralloc(); - s->s_len = len; - s->s_str = c; - memcpy(c, s1->s_str, len); - c[len] = '\0'; - return s; + len = s1->s_len; + if (len == 0) + return slink(s1); + c = malloc(len + 1); + if (c == NULL) { + math_error("Malloc failed for stringcopy"); + not_reached(); + } + s = stralloc(); + s->s_len = len; + s->s_str = c; + memcpy(c, s1->s_str, len); + c[len] = '\0'; + return s; } STRING * slink(STRING *s) { - if (s->s_links <= 0) { - math_error("Argument for slink has non-positive links!!!"); - not_reached(); - } - ++s->s_links; - return s; + if (s->s_links <= 0) { + math_error("Argument for slink has non-positive links!!!"); + not_reached(); + } + ++s->s_links; + return s; } void sfree(STRING *s) { - if (s->s_links <= 0) { - math_error("Argument for sfree has non-positive links!!!"); - not_reached(); - } - if (--s->s_links > 0 || s->s_len == 0) - return; - free(s->s_str); - s->s_next = freeStr; - freeStr = s; + if (s->s_links <= 0) { + math_error("Argument for sfree has non-positive links!!!"); + not_reached(); + } + if (--s->s_links > 0 || s->s_len == 0) + return; + free(s->s_str); + s->s_next = freeStr; + freeStr = s; } -STATIC long stringconstcount = 0; -STATIC long stringconstavail = 0; -STATIC STRING **stringconsttable; +STATIC long stringconstcount = 0; +STATIC long stringconstavail = 0; +STATIC STRING **stringconsttable; #define STRCONSTALLOC 100 void initstrings(void) { - /* alloc + 1 guard paranoia */ - stringconsttable = (STRING **) - malloc(sizeof(STRING *) * (STRCONSTALLOC + 1)); - if (stringconsttable == NULL) { - math_error("Unable to allocate constant table"); - not_reached(); - } - stringconsttable[STRCONSTALLOC] = NULL; /* guard paranoia */ - stringconsttable[0] = &_nullstring_; - stringconstcount = 1; - stringconstavail = STRCONSTALLOC - 1; + /* alloc + 1 guard paranoia */ + stringconsttable = (STRING **) + malloc(sizeof(STRING *) * (STRCONSTALLOC + 1)); + if (stringconsttable == NULL) { + math_error("Unable to allocate constant table"); + not_reached(); + } + stringconsttable[STRCONSTALLOC] = NULL; /* guard paranoia */ + stringconsttable[0] = &_nullstring_; + stringconstcount = 1; + stringconstavail = STRCONSTALLOC - 1; } /* @@ -1322,262 +1322,262 @@ initstrings(void) long addstring(char *str, size_t len) { - STRING **sp; - STRING *s; - char *c; - long index; /* index into constant table */ - long first; /* first non-null position found */ - bool havefirst; + STRING **sp; + STRING *s; + char *c; + long index; /* index into constant table */ + long first; /* first non-null position found */ + bool havefirst; - if (len < 1) { - math_error("addstring length including trailing NUL < 1"); - } - if (stringconstavail <= 0) { - if (stringconsttable == NULL) { - initstrings(); - } else { - /* alloc + 1 guard paranoia */ - sp = (STRING **) - realloc((char *) stringconsttable, - sizeof(STRING *) * - (stringconstcount + STRCONSTALLOC + 1)); - if (sp == NULL) { - math_error("Unable to reallocate string " - "const table"); - not_reached(); - } - /* guard paranoia */ - sp[stringconstcount + STRCONSTALLOC] = NULL; - stringconsttable = sp; - stringconstavail = STRCONSTALLOC; - } - } - len--; - first = 0; - havefirst = false; - sp = stringconsttable; - for (index = 0; index < stringconstcount; index++, sp++) { - s = *sp; - if (s->s_links == 0) { - if (!havefirst) { - havefirst = true; - first = index; - } - continue; - } - if (s->s_len == len && stringcompare(s->s_str, str, len) == 0) { - s->s_links++; - return index; - } - } - s = stralloc(); - c = (char *) malloc(len + 1); - if (c == NULL) { - math_error("Unable to allocate string constant memory"); - not_reached(); - } - s->s_str = c; - s->s_len = len; - memcpy(s->s_str, str, len+1); - if (havefirst) { - stringconsttable[first] = s; - return first; - } - stringconstavail--; - stringconsttable[stringconstcount++] = s; - return index; + if (len < 1) { + math_error("addstring length including trailing NUL < 1"); + } + if (stringconstavail <= 0) { + if (stringconsttable == NULL) { + initstrings(); + } else { + /* alloc + 1 guard paranoia */ + sp = (STRING **) + realloc((char *) stringconsttable, + sizeof(STRING *) * + (stringconstcount + STRCONSTALLOC + 1)); + if (sp == NULL) { + math_error("Unable to reallocate string " + "const table"); + not_reached(); + } + /* guard paranoia */ + sp[stringconstcount + STRCONSTALLOC] = NULL; + stringconsttable = sp; + stringconstavail = STRCONSTALLOC; + } + } + len--; + first = 0; + havefirst = false; + sp = stringconsttable; + for (index = 0; index < stringconstcount; index++, sp++) { + s = *sp; + if (s->s_links == 0) { + if (!havefirst) { + havefirst = true; + first = index; + } + continue; + } + if (s->s_len == len && stringcompare(s->s_str, str, len) == 0) { + s->s_links++; + return index; + } + } + s = stralloc(); + c = (char *) malloc(len + 1); + if (c == NULL) { + math_error("Unable to allocate string constant memory"); + not_reached(); + } + s->s_str = c; + s->s_len = len; + memcpy(s->s_str, str, len+1); + if (havefirst) { + stringconsttable[first] = s; + return first; + } + stringconstavail--; + stringconsttable[stringconstcount++] = s; + return index; } STRING * findstring(long index) { - if (index < 0 || index >= stringconstcount) { - math_error("Bad index for findstring"); - not_reached(); - } - return stringconsttable[index]; + if (index < 0 || index >= stringconstcount) { + math_error("Bad index for findstring"); + not_reached(); + } + return stringconsttable[index]; } void freestringconstant(long index) { - STRING *s; - STRING **sp; + STRING *s; + STRING **sp; - if (index >= 0) { - s = findstring(index); - sfree(s); - if (index == stringconstcount - 1) { - sp = &stringconsttable[index]; - while (stringconstcount > 0 && (*sp)->s_links == 0) { - stringconstcount--; - stringconstavail++; - sp--; - } - } - } + if (index >= 0) { + s = findstring(index); + sfree(s); + if (index == stringconstcount - 1) { + sp = &stringconsttable[index]; + while (stringconstcount > 0 && (*sp)->s_links == 0) { + stringconstcount--; + stringconstavail++; + sp--; + } + } + } } long printechar(char *c) { - unsigned char ch, cc; - unsigned char ech; /* for escape sequence */ + unsigned char ch, cc; + unsigned char ech; /* for escape sequence */ - ch = *c; - if (ch >= ' ' && ch < 127 && ch != '\\' && ch != '\"' && ch != '\'') { - math_chr(ch); - return 1; - } - math_chr('\\'); - ech = 0; - switch (ch) { - case '\a': ech = 'a'; break; - case '\b': ech = 'b'; break; - case '\f': ech = 'f'; break; - case '\n': ech = 'n'; break; - case '\r': ech = 'r'; break; - case '\t': ech = 't'; break; - case '\v': ech = 'v'; break; - case '\\': ech = '\\'; break; - case '\"': ech = '\"'; break; - case '\'': ech = '\''; break; - case 0: ech = '0'; break; - case 27: ech = 'e'; break; - } - if (ech == '0') { - cc = *(c + 1); - if (cc >= '0' && cc < '8') { - math_str("000"); - return 4; - } - } - if (ech) { - math_chr(ech); - return 2; - } - math_chr('x'); - cc = ch / 16; - math_chr((cc < 10) ? '0' + cc : 87 + cc); - cc = ch % 16; - math_chr((cc < 10) ? '0' + cc : 87 + cc); - return 4; + ch = *c; + if (ch >= ' ' && ch < 127 && ch != '\\' && ch != '\"' && ch != '\'') { + math_chr(ch); + return 1; + } + math_chr('\\'); + ech = 0; + switch (ch) { + case '\a': ech = 'a'; break; + case '\b': ech = 'b'; break; + case '\f': ech = 'f'; break; + case '\n': ech = 'n'; break; + case '\r': ech = 'r'; break; + case '\t': ech = 't'; break; + case '\v': ech = 'v'; break; + case '\\': ech = '\\'; break; + case '\"': ech = '\"'; break; + case '\'': ech = '\''; break; + case 0: ech = '0'; break; + case 27: ech = 'e'; break; + } + if (ech == '0') { + cc = *(c + 1); + if (cc >= '0' && cc < '8') { + math_str("000"); + return 4; + } + } + if (ech) { + math_chr(ech); + return 2; + } + math_chr('x'); + cc = ch / 16; + math_chr((cc < 10) ? '0' + cc : 87 + cc); + cc = ch % 16; + math_chr((cc < 10) ? '0' + cc : 87 + cc); + return 4; } void fitstring(char *str, long len, long width) { - long i, j, n, max; - char *c; - unsigned char ch, nch; + long i, j, n, max; + char *c; + unsigned char ch, nch; - max = (width - 3)/2; - if (len == 0) - return; - c = str; - for (i = 0, n = 0; i < len && n < max; i++) { - n += printechar(c++); - } - if (i >= len) - return; - c = str + len; - nch = '\0'; - for (n = 0, j = len ; j > i && n < max ; --j, nch = ch) { - ch = *--c; - n++; - if (ch >= ' ' && ch <= 127 && ch != '\\' && ch != '\"') - continue; - n++; - switch (ch) { - case '\a': - case '\b': - case '\f': - case '\n': - case '\r': - case '\t': - case '\v': - case '\\': - case '\"': - case '\'': - case 27: - continue; - } - if (ch >= 64 || (nch >= '0' && nch <= '7')) { - n += 2; - continue; - } - if (ch >= 8) - n++; - } - if (j > i) - math_str("..."); - while (j++ < len) - (void) printechar(c++); + max = (width - 3)/2; + if (len == 0) + return; + c = str; + for (i = 0, n = 0; i < len && n < max; i++) { + n += printechar(c++); + } + if (i >= len) + return; + c = str + len; + nch = '\0'; + for (n = 0, j = len ; j > i && n < max ; --j, nch = ch) { + ch = *--c; + n++; + if (ch >= ' ' && ch <= 127 && ch != '\\' && ch != '\"') + continue; + n++; + switch (ch) { + case '\a': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + case '\v': + case '\\': + case '\"': + case '\'': + case 27: + continue; + } + if (ch >= 64 || (nch >= '0' && nch <= '7')) { + n += 2; + continue; + } + if (ch >= 8) + n++; + } + if (j > i) + math_str("..."); + while (j++ < len) + (void) printechar(c++); } void strprint(STRING *str) { - long n; - char *c; + long n; + char *c; - c = str->s_str; - n = str->s_len; + c = str->s_str; + n = str->s_len; - while (n-- > 0) - (void) printechar(c++); + while (n-- > 0) + (void) printechar(c++); } void showstrings(void) { - STRING *sp; - long i, j, k; - long count; + STRING *sp; + long i, j, k; + long count; - printf("Index Links Length String\n"); - printf("----- ----- ------ ------\n"); - sp = &_nullstring_; - printf(" 0 %5ld 0 \"\"\n", sp->s_links); - for (i = 0, k = 1, count = 1; i < blockcount; i++) { - sp = firstStrs[i]; - for (j = 0; j < STRALLOC; j++, k++, sp++) { - if (sp->s_links > 0) { - ++count; - printf("%5ld %5ld %6ld \"", - k, sp->s_links, (long int)sp->s_len); - fitstring(sp->s_str, sp->s_len, 50); - printf("\"\n"); - } - } - } - printf("\nNumber: %ld\n", count); + printf("Index Links Length String\n"); + printf("----- ----- ------ ------\n"); + sp = &_nullstring_; + printf(" 0 %5ld 0 \"\"\n", sp->s_links); + for (i = 0, k = 1, count = 1; i < blockcount; i++) { + sp = firstStrs[i]; + for (j = 0; j < STRALLOC; j++, k++, sp++) { + if (sp->s_links > 0) { + ++count; + printf("%5ld %5ld %6ld \"", + k, sp->s_links, (long int)sp->s_len); + fitstring(sp->s_str, sp->s_len, 50); + printf("\"\n"); + } + } + } + printf("\nNumber: %ld\n", count); } void showliterals(void) { - STRING *sp; - long i; - long count = 0; + STRING *sp; + long i; + long count = 0; - printf("Index Links Length String\n"); - printf("----- ----- ------ ------\n"); - for (i = 0; i < stringconstcount; i++) { - sp = stringconsttable[i]; - if (sp->s_links > 0) { - ++count; - printf("%5ld %5ld %6ld \"", - i, sp->s_links, (long int)sp->s_len); - fitstring(sp->s_str, sp->s_len, 50); - printf("\"\n"); - } + printf("Index Links Length String\n"); + printf("----- ----- ------ ------\n"); + for (i = 0; i < stringconstcount; i++) { + sp = stringconsttable[i]; + if (sp->s_links > 0) { + ++count; + printf("%5ld %5ld %6ld \"", + i, sp->s_links, (long int)sp->s_len); + fitstring(sp->s_str, sp->s_len, 50); + printf("\"\n"); + } - } - printf("\nNumber: %ld\n", count); + } + printf("\nNumber: %ld\n", count); } diff --git a/str.h b/str.h index a4a1434..35e75fa 100644 --- a/str.h +++ b/str.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:36 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:36 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,7 +28,7 @@ #define INCLUDE_STR_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "zmath.h" #else # include @@ -37,20 +37,20 @@ struct string { - char *s_str; - size_t s_len; - long s_links; - struct string *s_next; + char *s_str; + size_t s_len; + long s_links; + struct string *s_next; }; typedef struct string STRING; typedef struct { - char *h_list; /* list of strings separated by nulls */ - size_t h_used; /* characters used so far */ - size_t h_avail; /* characters available for use */ - long h_count; /* number of strings */ + char *h_list; /* list of strings separated by nulls */ + size_t h_used; /* characters used so far */ + size_t h_avail; /* characters available for use */ + long h_count; /* number of strings */ } STRINGHEAD; EXTERN STRING _nullstring_; diff --git a/strl.c b/strl.c index 7805cb8..6c35094 100644 --- a/strl.c +++ b/strl.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2021/03/08 21;58:10 - * File existed as early as: 2021 + * Under source code control: 2021/03/08 21;58:10 + * File existed as early as: 2021 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -37,7 +37,7 @@ #endif /* STRL_TEST */ -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ #if !defined(HAVE_STRLCPY) || defined(STRL_TEST) @@ -52,17 +52,17 @@ * do not have this function in their C library. * * given: - * dst destination string - * src source string - * dstsize size of the destination string buffer including NUL + * dst destination string + * src source string + * dstsize size of the destination string buffer including NUL * * returns: - * total length of source string excluding NUL, - * 0 ==> invalid arguments + * total length of source string excluding NUL, + * 0 ==> invalid arguments * * NOTE: If return value is >= dstsize, the result was truncated. - * I.e., there was not enough room in dst and so the copy - * was stopped before it would have overflowed and was NUL terminated. + * I.e., there was not enough room in dst and so the copy + * was stopped before it would have overflowed and was NUL terminated. */ #if defined(STRL_TEST) size_t @@ -72,50 +72,50 @@ size_t strlcpy(char * dst, const char * src, size_t dstsize) #endif /* STRL_TEST */ { - size_t srclen; /* src string length not including NUL */ + size_t srclen; /* src string length not including NUL */ - /* - * firewall - */ - if (dst == NULL || src == NULL || dstsize <= 0) { - /* nothing can be copied */ + /* + * firewall + */ + if (dst == NULL || src == NULL || dstsize <= 0) { + /* nothing can be copied */ #if defined(STRL_TEST) - printf("in %s: return 0\n", __FUNCTION__); + printf("in %s: return 0\n", __FUNCTION__); #endif /* STRL_TEST */ - return 0; - } + return 0; + } - /* - * determine how much string we could copy - */ - srclen = strlen(src); + /* + * determine how much string we could copy + */ + srclen = strlen(src); - /* - * perform the size limited copy and NUL terminate - */ - if (srclen+1 > dstsize) { - memcpy(dst, src, dstsize-1); - dst[dstsize-1] = '\0'; + /* + * perform the size limited copy and NUL terminate + */ + if (srclen+1 > dstsize) { + memcpy(dst, src, dstsize-1); + dst[dstsize-1] = '\0'; #if defined(STRL_TEST) - printf("in %s: if memcpy(\"%s\", \"%s\", %zu)\n", - __FUNCTION__, dst, src, dstsize-1); + printf("in %s: if memcpy(\"%s\", \"%s\", %zu)\n", + __FUNCTION__, dst, src, dstsize-1); #endif /* STRL_TEST */ - } else { - memcpy(dst, src, srclen); - dst[srclen] = '\0'; + } else { + memcpy(dst, src, srclen); + dst[srclen] = '\0'; #if defined(STRL_TEST) - printf("in %s: else memcpy(\"%s\", \"%s\", %zu)\n", - __FUNCTION__, dst, src, srclen); + printf("in %s: else memcpy(\"%s\", \"%s\", %zu)\n", + __FUNCTION__, dst, src, srclen); #endif /* STRL_TEST */ - } + } - /* - * return the length we tried to copy, not including NUL - */ + /* + * return the length we tried to copy, not including NUL + */ #if defined(STRL_TEST) - printf("in %s: return %zu\n", __FUNCTION__, srclen); + printf("in %s: return %zu\n", __FUNCTION__, srclen); #endif /* STRL_TEST */ - return srclen; + return srclen; } #endif /* !HAVE_STRLCPY || STRL_TEST */ @@ -132,17 +132,17 @@ strlcpy(char * dst, const char * src, size_t dstsize) * do not have this function in their C library. * * given: - * dst destination string - * src source string - * dstsize size of the destination string buffer including NUL + * dst destination string + * src source string + * dstsize size of the destination string buffer including NUL * * returns: - * total length of string could have been copied excluding NUL, - * 0 ==> invalid arguments + * total length of string could have been copied excluding NUL, + * 0 ==> invalid arguments * * NOTE: If return value is >= dstsize, the output string was truncated. - * I.e., there was not enough room and so the result was truncated - * and NUL terminated. + * I.e., there was not enough room and so the result was truncated + * and NUL terminated. */ #if defined(STRL_TEST) size_t @@ -152,84 +152,84 @@ size_t strlcat(char * dst, const char * src, size_t dstsize) #endif /* STRL_TEST */ { - size_t srclen; /* src string length not including NUL */ - size_t dstlen; /* dst string length not including NUL */ - size_t catlen; /* amount from src we can copy */ + size_t srclen; /* src string length not including NUL */ + size_t dstlen; /* dst string length not including NUL */ + size_t catlen; /* amount from src we can copy */ - /* - * firewall - */ - if (dst == NULL || src == NULL || dstsize <= 0) { - /* nothing can be concatenated */ + /* + * firewall + */ + if (dst == NULL || src == NULL || dstsize <= 0) { + /* nothing can be concatenated */ #if defined(STRL_TEST) - printf("in %s: return 0\n", __FUNCTION__); + printf("in %s: return 0\n", __FUNCTION__); #endif /* STRL_TEST */ - return 0; - } + return 0; + } - /* - * prep to determine the room we have - */ - dstlen = strlen(dst); - srclen = strlen(src); + /* + * prep to determine the room we have + */ + dstlen = strlen(dst); + srclen = strlen(src); #if defined(STRL_TEST) - printf("in %s: dst = ((%s)) src = ((%s)) dstsize = %zu\n", - __FUNCTION__, dst, src, dstsize); - printf("in %s: dstlen = %zu srclen = %zu\n", - __FUNCTION__, dstlen, srclen); + printf("in %s: dst = ((%s)) src = ((%s)) dstsize = %zu\n", + __FUNCTION__, dst, src, dstsize); + printf("in %s: dstlen = %zu srclen = %zu\n", + __FUNCTION__, dstlen, srclen); #endif /* STRL_TEST */ - if (dstsize <= dstlen+1) { - /* dst is already full */ + if (dstsize <= dstlen+1) { + /* dst is already full */ #if defined(STRL_TEST) - printf("in %s: dstsize: %zu <= dstlen+1: %zu\n", - __FUNCTION__, dstsize, dstlen+1); - printf("in %s: already full return %zu\n", - __FUNCTION__, srclen+dstlen); + printf("in %s: dstsize: %zu <= dstlen+1: %zu\n", + __FUNCTION__, dstsize, dstlen+1); + printf("in %s: already full return %zu\n", + __FUNCTION__, srclen+dstlen); #endif /* STRL_TEST */ - return srclen+dstlen; - } + return srclen+dstlen; + } - /* - * determine the amount data we can copy - */ - catlen = dstsize - dstlen; + /* + * determine the amount data we can copy + */ + catlen = dstsize - dstlen; - /* - * perform the concatenation - */ - dst += dstlen; + /* + * perform the concatenation + */ + dst += dstlen; #if defined(STRL_TEST) - printf("in %s: catlen = %zu\n", __FUNCTION__, catlen); + printf("in %s: catlen = %zu\n", __FUNCTION__, catlen); #endif /* STRL_TEST */ - if (catlen > srclen+1) { - memcpy(dst, src, srclen); - dst[srclen] = '\0'; + if (catlen > srclen+1) { + memcpy(dst, src, srclen); + dst[srclen] = '\0'; #if defined(STRL_TEST) - printf("in %s: if memcpy(\"%s\", \"%s\", %zu)\n", - __FUNCTION__, dst, src, srclen); + printf("in %s: if memcpy(\"%s\", \"%s\", %zu)\n", + __FUNCTION__, dst, src, srclen); #endif /* STRL_TEST */ - } else { - memcpy(dst, src, catlen); - dst[catlen] = '\0'; + } else { + memcpy(dst, src, catlen); + dst[catlen] = '\0'; #if defined(STRL_TEST) - printf("in %s: if memcpy(\"%s\", \"%s\", %zu)\n", - __FUNCTION__, dst, src, catlen); + printf("in %s: if memcpy(\"%s\", \"%s\", %zu)\n", + __FUNCTION__, dst, src, catlen); #endif /* STRL_TEST */ - } + } - /* - * return the length, not including NUL, of what could have been formed - */ + /* + * return the length, not including NUL, of what could have been formed + */ #if defined(STRL_TEST) - printf("in %s: return %zu\n", __FUNCTION__, srclen+dstlen); + printf("in %s: return %zu\n", __FUNCTION__, srclen+dstlen); #endif /* STRL_TEST */ - return srclen+dstlen; + return srclen+dstlen; } #endif /* !HAVE_STRLCAT || STRL_TEST */ #if defined(STRL_TEST) -static char src[] = "abcde"; /* test source string */ +static char src[] = "abcde"; /* test source string */ /* * Main routine to test the strlcpy() and strlcat() functions. @@ -237,65 +237,65 @@ static char src[] = "abcde"; /* test source string */ int main(int argc, char **argv) { - char dst[sizeof(src)]; /* test destination string */ - size_t ret; /* strlcpy() or strlcat() return */ + char dst[sizeof(src)]; /* test destination string */ + size_t ret; /* strlcpy() or strlcat() return */ - /* - * normal copy - */ - memset(dst, 0, sizeof(dst)); - printf("src: %s\n", src); - ret = calc_strlcpy(dst, src, sizeof(dst)); - printf("ret: %zu\n", ret); - printf("dst: %s\n\n", dst); + /* + * normal copy + */ + memset(dst, 0, sizeof(dst)); + printf("src: %s\n", src); + ret = calc_strlcpy(dst, src, sizeof(dst)); + printf("ret: %zu\n", ret); + printf("dst: %s\n\n", dst); - /* - * truncated copy - */ - memset(dst, 0, sizeof(dst)); - printf("src: %s\n", src); - ret = calc_strlcpy(dst, src, sizeof(dst)-3); - printf("ret: %zu\n", ret); - printf("dst: %s\n\n", dst); + /* + * truncated copy + */ + memset(dst, 0, sizeof(dst)); + printf("src: %s\n", src); + ret = calc_strlcpy(dst, src, sizeof(dst)-3); + printf("ret: %zu\n", ret); + printf("dst: %s\n\n", dst); - /* - * overcat - */ - printf("src: %s\n", src); - ret = calc_strlcat(dst, src, sizeof(dst)); - printf("ret: %zu\n", ret); - printf("dst: %s\n\n", dst); + /* + * overcat + */ + printf("src: %s\n", src); + ret = calc_strlcat(dst, src, sizeof(dst)); + printf("ret: %zu\n", ret); + printf("dst: %s\n\n", dst); - /* - * fullcat - */ - printf("src: %s\n", src); - ret = calc_strlcat(dst, src, sizeof(dst)); - printf("ret: %zu\n", ret); - printf("dst: %s\n\n", dst); + /* + * fullcat + */ + printf("src: %s\n", src); + ret = calc_strlcat(dst, src, sizeof(dst)); + printf("ret: %zu\n", ret); + printf("dst: %s\n\n", dst); - /* - * nilcat - */ - dst[0] = '\0'; - printf("src: %s\n", src); - ret = calc_strlcat(dst, src, sizeof(dst)); - printf("ret: %zu\n", ret); - printf("dst: %s\n\n", dst); + /* + * nilcat + */ + dst[0] = '\0'; + printf("src: %s\n", src); + ret = calc_strlcat(dst, src, sizeof(dst)); + printf("ret: %zu\n", ret); + printf("dst: %s\n\n", dst); - /* - * shortcat - */ - dst[1] = '\0'; - printf("src: %s\n", src); - ret = calc_strlcat(dst, src, sizeof(dst)-3); - printf("ret: %zu\n", ret); - printf("dst: %s\n\n", dst); + /* + * shortcat + */ + dst[1] = '\0'; + printf("src: %s\n", src); + ret = calc_strlcat(dst, src, sizeof(dst)-3); + printf("ret: %zu\n", ret); + printf("dst: %s\n\n", dst); - /* - * all done - */ - exit(0); + /* + * all done + */ + exit(0); } #endif /* STRL_TEST */ diff --git a/strl.h b/strl.h index 56e72b0..8d91057 100644 --- a/strl.h +++ b/strl.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2021/03/08 21;58:10 - * File existed as early as: 2021 + * Under source code control: 2021/03/08 21;58:10 + * File existed as early as: 2021 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,7 +28,7 @@ #define INCLUDE_STRL_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ #include "have_string.h" #else #include @@ -37,7 +37,7 @@ # include #endif -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "have_strlcpy.h" # include "have_strlcat.h" # include "decl.h" diff --git a/symbol.c b/symbol.c index d02f541..1c8e693 100644 --- a/symbol.c +++ b/symbol.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:23 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:23 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -36,19 +36,19 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define HASHSIZE 37 /* size of hash table */ +#define HASHSIZE 37 /* size of hash table */ E_FUNC FILE *f_open(char *name, char *mode); -STATIC int filescope; /* file scope level for static variables */ -STATIC int funcscope; /* function scope level for static variables */ -STATIC STRINGHEAD localnames; /* list of local variable names */ -STATIC STRINGHEAD globalnames; /* list of global variable names */ -STATIC STRINGHEAD paramnames; /* list of parameter variable names */ -STATIC GLOBAL *globalhash[HASHSIZE]; /* hash table for globals */ +STATIC int filescope; /* file scope level for static variables */ +STATIC int funcscope; /* function scope level for static variables */ +STATIC STRINGHEAD localnames; /* list of local variable names */ +STATIC STRINGHEAD globalnames; /* list of global variable names */ +STATIC STRINGHEAD paramnames; /* list of parameter variable names */ +STATIC GLOBAL *globalhash[HASHSIZE]; /* hash table for globals */ S_FUNC void printtype(VALUE *); S_FUNC void unscope(void); @@ -63,7 +63,7 @@ STATIC GLOBAL **statictable; * Args are the symbol name and the symbol name size. */ #define HASHSYM(n, s) ((unsigned)((n)[0]*123 + (n)[s-1]*135 + (s)*157) % \ - HASHSIZE) + HASHSIZE) /* @@ -72,13 +72,13 @@ STATIC GLOBAL **statictable; void initglobals(void) { - int i; /* index counter */ + int i; /* index counter */ - for (i = 0; i < HASHSIZE; i++) - globalhash[i] = NULL; - initstr(&globalnames); - filescope = SCOPE_STATIC; - funcscope = 0; + for (i = 0; i < HASHSIZE; i++) + globalhash[i] = NULL; + initstr(&globalnames); + filescope = SCOPE_STATIC; + funcscope = 0; } @@ -88,48 +88,48 @@ initglobals(void) * The address of the global symbol structure is returned. * * given: - * name name of global variable - * isstatic true if symbol is static + * name name of global variable + * isstatic true if symbol is static */ GLOBAL * addglobal(char *name, bool isstatic) { - GLOBAL *sp; /* current symbol pointer */ - GLOBAL **hp; /* hash table head address */ - size_t len; /* length of string */ - int newfilescope; /* file scope being looked for */ - int newfuncscope; /* function scope being looked for */ + GLOBAL *sp; /* current symbol pointer */ + GLOBAL **hp; /* hash table head address */ + size_t len; /* length of string */ + int newfilescope; /* file scope being looked for */ + int newfuncscope; /* function scope being looked for */ - newfilescope = SCOPE_GLOBAL; - newfuncscope = 0; - if (isstatic) { - newfilescope = filescope; - newfuncscope = funcscope; - } - len = strlen(name); - if (len <= 0) - return NULL; - hp = &globalhash[HASHSYM(name, len)]; - for (sp = *hp; sp; sp = sp->g_next) { - if ((sp->g_len == len) && - (strncmp(sp->g_name, name, len+1) == 0) - && (sp->g_filescope == newfilescope) - && (sp->g_funcscope == newfuncscope)) - return sp; - } - sp = (GLOBAL *) malloc(sizeof(GLOBAL)); - if (sp == NULL) - return sp; - sp->g_name = addstr(&globalnames, name); - sp->g_len = len; - sp->g_filescope = newfilescope; - sp->g_funcscope = newfuncscope; - sp->g_value.v_num = qlink(&_qzero_); - sp->g_value.v_type = V_NUM; - sp->g_value.v_subtype = V_NOSUBTYPE; - sp->g_next = *hp; - *hp = sp; - return sp; + newfilescope = SCOPE_GLOBAL; + newfuncscope = 0; + if (isstatic) { + newfilescope = filescope; + newfuncscope = funcscope; + } + len = strlen(name); + if (len <= 0) + return NULL; + hp = &globalhash[HASHSYM(name, len)]; + for (sp = *hp; sp; sp = sp->g_next) { + if ((sp->g_len == len) && + (strncmp(sp->g_name, name, len+1) == 0) + && (sp->g_filescope == newfilescope) + && (sp->g_funcscope == newfuncscope)) + return sp; + } + sp = (GLOBAL *) malloc(sizeof(GLOBAL)); + if (sp == NULL) + return sp; + sp->g_name = addstr(&globalnames, name); + sp->g_len = len; + sp->g_filescope = newfilescope; + sp->g_funcscope = newfuncscope; + sp->g_value.v_num = qlink(&_qzero_); + sp->g_value.v_type = V_NUM; + sp->g_value.v_subtype = V_NOSUBTYPE; + sp->g_next = *hp; + *hp = sp; + return sp; } @@ -141,22 +141,22 @@ addglobal(char *name, bool isstatic) GLOBAL * findglobal(char *name) { - GLOBAL *sp; /* current symbol pointer */ - GLOBAL *bestsp; /* found symbol with highest scope */ - size_t len; /* length of string */ + GLOBAL *sp; /* current symbol pointer */ + GLOBAL *bestsp; /* found symbol with highest scope */ + size_t len; /* length of string */ - bestsp = NULL; - len = strlen(name); - for (sp = globalhash[HASHSYM(name, len)]; sp != NULL; sp = sp->g_next) { - if ((sp->g_len == len) && - (strncmp(sp->g_name, name, len+1) == 0)) { - if ((bestsp == NULL) || - (sp->g_filescope > bestsp->g_filescope) || - (sp->g_funcscope > bestsp->g_funcscope)) - bestsp = sp; - } - } - return bestsp; + bestsp = NULL; + len = strlen(name); + for (sp = globalhash[HASHSYM(name, len)]; sp != NULL; sp = sp->g_next) { + if ((sp->g_len == len) && + (strncmp(sp->g_name, name, len+1) == 0)) { + if ((bestsp == NULL) || + (sp->g_filescope > bestsp->g_filescope) || + (sp->g_funcscope > bestsp->g_funcscope)) + bestsp = sp; + } + } + return bestsp; } @@ -164,14 +164,14 @@ findglobal(char *name) * Return the name of a global variable given its address. * * given: - * sp address of global pointer + * sp address of global pointer */ char * globalname(GLOBAL *sp) { - if (sp) - return sp->g_name; - return ""; + if (sp) + return sp->g_name; + return ""; } @@ -183,153 +183,153 @@ globalname(GLOBAL *sp) void showglobals(void) { - GLOBAL **hp; /* hash table head address */ - register GLOBAL *sp; /* current global symbol pointer */ - long count; /* number of global variables shown */ + GLOBAL **hp; /* hash table head address */ + register GLOBAL *sp; /* current global symbol pointer */ + long count; /* number of global variables shown */ - count = 0; - for (hp = &globalhash[HASHSIZE-1]; hp >= globalhash; hp--) { - for (sp = *hp; sp; sp = sp->g_next) { - if (sp->g_value.v_type != V_NUM) - continue; - if (count++ == 0) { - printf("\nName Digits Value\n"); - printf( "---- ------ -----\n"); - } - printf("%-8s", sp->g_name); - if (sp->g_filescope != SCOPE_GLOBAL) - printf(" (s)"); - fitprint(sp->g_value.v_num, 50); - printf("\n"); - } - } - if (count == 0) { - printf("No real-valued global variables\n"); - } - putchar('\n'); + count = 0; + for (hp = &globalhash[HASHSIZE-1]; hp >= globalhash; hp--) { + for (sp = *hp; sp; sp = sp->g_next) { + if (sp->g_value.v_type != V_NUM) + continue; + if (count++ == 0) { + printf("\nName Digits Value\n"); + printf( "---- ------ -----\n"); + } + printf("%-8s", sp->g_name); + if (sp->g_filescope != SCOPE_GLOBAL) + printf(" (s)"); + fitprint(sp->g_value.v_num, 50); + printf("\n"); + } + } + if (count == 0) { + printf("No real-valued global variables\n"); + } + putchar('\n'); } void showallglobals(void) { - GLOBAL **hp; /* hash table head address */ - register GLOBAL *sp; /* current global symbol pointer */ - long count; /* number of global variables shown */ + GLOBAL **hp; /* hash table head address */ + register GLOBAL *sp; /* current global symbol pointer */ + long count; /* number of global variables shown */ - count = 0; - for (hp = &globalhash[HASHSIZE-1]; hp >= globalhash; hp--) { - for (sp = *hp; sp; sp = sp->g_next) { - if (count++ == 0) { - printf("\nName Level Type\n"); - printf( "---- ----- -----\n"); - } - printf("%-8s%4d ", sp->g_name, sp->g_filescope); - printtype(&sp->g_value); - printf("\n"); - } - } - if (count > 0) - printf("\nNumber: %ld\n", count); - else - printf("No global variables\n"); + count = 0; + for (hp = &globalhash[HASHSIZE-1]; hp >= globalhash; hp--) { + for (sp = *hp; sp; sp = sp->g_next) { + if (count++ == 0) { + printf("\nName Level Type\n"); + printf( "---- ----- -----\n"); + } + printf("%-8s%4d ", sp->g_name, sp->g_filescope); + printtype(&sp->g_value); + printf("\n"); + } + } + if (count > 0) + printf("\nNumber: %ld\n", count); + else + printf("No global variables\n"); } S_FUNC void printtype(VALUE *vp) { - int type; - char *s; - char *errsym; - bool alloced; + int type; + char *s; + char *errsym; + bool alloced; - type = vp->v_type; - if (type < 0) { - errsym = errnum_2_errsym(-type, &alloced); - if (errsym == NULL) { - printf("Error %d", -type); - } else { - printf("Error %s", errsym); - if (alloced == true) { - free(errsym); - } - } - return; - } - switch (type) { - case V_NUM: - printf("real = "); - fitprint(vp->v_num, 32); - return; - case V_COM: - printf("complex = "); - fitprint(vp->v_com->real, 8); - if (!vp->v_com->imag->num.sign) - printf("+"); - fitprint(vp->v_com->imag, 8); - printf("i"); - return; - case V_STR: - printf("string = \""); - fitstring(vp->v_str->s_str, vp->v_str->s_len, 50); - printf("\""); - return; - case V_NULL: - s = "null"; - break; - case V_MAT: - s = "matrix"; - break; - case V_LIST: - s = "list"; - break; - case V_ASSOC: - s = "association"; - break; - case V_OBJ: - printf("%s ", objtypename( - vp->v_obj->o_actions->oa_index)); - s = "object"; - break; - case V_FILE: - s = "file id"; - break; - case V_RAND: - s = "subtractive 100 random state"; - break; - case V_RANDOM: - s = "Blum random state"; - break; - case V_CONFIG: - s = "config state"; - break; - case V_HASH: - s = "hash state"; - break; - case V_BLOCK: - s = "unnamed block"; - break; - case V_NBLOCK: - s = "named block"; - break; - case V_VPTR: - s = "value pointer"; - break; - case V_OPTR: - s = "octet pointer"; - break; - case V_SPTR: - s = "string pointer"; - break; - case V_NPTR: - s = "number pointer"; - break; - default: - s = "???"; - break; - } - printf("%s", s); + type = vp->v_type; + if (type < 0) { + errsym = errnum_2_errsym(-type, &alloced); + if (errsym == NULL) { + printf("Error %d", -type); + } else { + printf("Error %s", errsym); + if (alloced == true) { + free(errsym); + } + } + return; + } + switch (type) { + case V_NUM: + printf("real = "); + fitprint(vp->v_num, 32); + return; + case V_COM: + printf("complex = "); + fitprint(vp->v_com->real, 8); + if (!vp->v_com->imag->num.sign) + printf("+"); + fitprint(vp->v_com->imag, 8); + printf("i"); + return; + case V_STR: + printf("string = \""); + fitstring(vp->v_str->s_str, vp->v_str->s_len, 50); + printf("\""); + return; + case V_NULL: + s = "null"; + break; + case V_MAT: + s = "matrix"; + break; + case V_LIST: + s = "list"; + break; + case V_ASSOC: + s = "association"; + break; + case V_OBJ: + printf("%s ", objtypename( + vp->v_obj->o_actions->oa_index)); + s = "object"; + break; + case V_FILE: + s = "file id"; + break; + case V_RAND: + s = "subtractive 100 random state"; + break; + case V_RANDOM: + s = "Blum random state"; + break; + case V_CONFIG: + s = "config state"; + break; + case V_HASH: + s = "hash state"; + break; + case V_BLOCK: + s = "unnamed block"; + break; + case V_NBLOCK: + s = "named block"; + break; + case V_VPTR: + s = "value pointer"; + break; + case V_OPTR: + s = "octet pointer"; + break; + case V_SPTR: + s = "string pointer"; + break; + case V_NPTR: + s = "number pointer"; + break; + default: + s = "???"; + break; + } + printf("%s", s); } @@ -341,37 +341,37 @@ printtype(VALUE *vp) int writeglobals(char *name) { - FILE *fp; - GLOBAL **hp; /* hash table head address */ - register GLOBAL *sp; /* current global symbol pointer */ - int savemode; /* saved output mode */ - E_FUNC void math_setfp(FILE *fp); + FILE *fp; + GLOBAL **hp; /* hash table head address */ + register GLOBAL *sp; /* current global symbol pointer */ + int savemode; /* saved output mode */ + E_FUNC void math_setfp(FILE *fp); - fp = f_open(name, "w"); - if (fp == NULL) - return 1; - math_setfp(fp); - for (hp = &globalhash[HASHSIZE-1]; hp >= globalhash; hp--) { - for (sp = *hp; sp; sp = sp->g_next) { - switch (sp->g_value.v_type) { - case V_NUM: - case V_COM: - case V_STR: - break; - default: - continue; - } - math_fmt("%s = ", sp->g_name); - savemode = math_setmode(MODE_HEX); - printvalue(&sp->g_value, PRINT_UNAMBIG); - math_setmode(savemode); - math_str(";\n"); - } - } - math_setfp(stdout); - if (fclose(fp)) - return 1; - return 0; + fp = f_open(name, "w"); + if (fp == NULL) + return 1; + math_setfp(fp); + for (hp = &globalhash[HASHSIZE-1]; hp >= globalhash; hp--) { + for (sp = *hp; sp; sp = sp->g_next) { + switch (sp->g_value.v_type) { + case V_NUM: + case V_COM: + case V_STR: + break; + default: + continue; + } + math_fmt("%s = ", sp->g_name); + savemode = math_setmode(MODE_HEX); + printvalue(&sp->g_value, PRINT_UNAMBIG); + math_setmode(savemode); + math_str(";\n"); + } + } + math_setfp(stdout); + if (fclose(fp)) + return 1; + return 0; } @@ -381,31 +381,31 @@ writeglobals(char *name) void freeglobals(void) { - GLOBAL **hp; /* hash table head address */ - GLOBAL *sp; /* current global symbol pointer */ + GLOBAL **hp; /* hash table head address */ + GLOBAL *sp; /* current global symbol pointer */ - /* - * We prevent the hp pointer from walking behind globalhash - * by stopping one short of the end and running the loop one - * more time. - * - * We could stop the loop with just hp >= globalhash, but stopping - * short and running the loop one last time manually helps make - * code checkers such as insure happy. - */ - for (hp = &globalhash[HASHSIZE-1]; hp > globalhash; hp--) { - for (sp = *hp; sp; sp = sp->g_next) { - if (sp->g_value.v_type != V_NULL) { - freevalue(&sp->g_value); - } - } - } - /* run the loop manually one last time */ - for (sp = *hp; sp; sp = sp->g_next) { - if (sp->g_value.v_type != V_NULL) { - freevalue(&sp->g_value); - } - } + /* + * We prevent the hp pointer from walking behind globalhash + * by stopping one short of the end and running the loop one + * more time. + * + * We could stop the loop with just hp >= globalhash, but stopping + * short and running the loop one last time manually helps make + * code checkers such as insure happy. + */ + for (hp = &globalhash[HASHSIZE-1]; hp > globalhash; hp--) { + for (sp = *hp; sp; sp = sp->g_next) { + if (sp->g_value.v_type != V_NULL) { + freevalue(&sp->g_value); + } + } + } + /* run the loop manually one last time */ + for (sp = *hp; sp; sp = sp->g_next) { + if (sp->g_value.v_type != V_NULL) { + freevalue(&sp->g_value); + } + } } /* @@ -414,16 +414,16 @@ freeglobals(void) void freestatics(void) { - GLOBAL **stp; - GLOBAL *sp; - long count; + GLOBAL **stp; + GLOBAL *sp; + long count; - stp = statictable; - count = staticcount; - while (count-- > 0) { - sp = *stp++; - freevalue(&sp->g_value); - } + stp = statictable; + count = staticcount; + while (count-- > 0) { + sp = *stp++; + freevalue(&sp->g_value); + } } @@ -435,23 +435,23 @@ freestatics(void) void resetscopes(void) { - filescope = SCOPE_STATIC; - funcscope = 0; - unscope(); + filescope = SCOPE_STATIC; + funcscope = 0; + unscope(); } /* * Enter a new file scope level so that newly defined static variables * will have the appropriate scope, and so that previously defined static - * variables will temporarily be unaccessible. This should only be called + * variables will temporarily be unaccessible. This should only be called * when the function scope level is zero. */ void enterfilescope(void) { - filescope++; - funcscope = 0; + filescope++; + funcscope = 0; } @@ -463,10 +463,10 @@ enterfilescope(void) void exitfilescope(void) { - if (filescope > SCOPE_STATIC) - filescope--; - funcscope = 0; - unscope(); + if (filescope > SCOPE_STATIC) + filescope--; + funcscope = 0; + unscope(); } @@ -478,7 +478,7 @@ exitfilescope(void) void enterfuncscope(void) { - funcscope++; + funcscope++; } @@ -491,9 +491,9 @@ enterfuncscope(void) void exitfuncscope(void) { - if (funcscope > 0) - funcscope--; - unscope(); + if (funcscope > 0) + funcscope--; + unscope(); } @@ -505,29 +505,29 @@ exitfuncscope(void) void endscope(char *name, bool isglobal) { - GLOBAL *sp; - GLOBAL *prevsp; - GLOBAL **hp; - size_t len; + GLOBAL *sp; + GLOBAL *prevsp; + GLOBAL **hp; + size_t len; - len = strlen(name); - prevsp = NULL; - hp = &globalhash[HASHSYM(name, len)]; - for (sp = *hp; sp; sp = sp->g_next) { - if (sp->g_len == len && !strcmp(sp->g_name, name) && - sp->g_filescope > SCOPE_GLOBAL) { - if (isglobal || (sp->g_filescope == filescope && - sp->g_funcscope == funcscope)) { - addstatic(sp); - if (prevsp) - prevsp->g_next = sp->g_next; - else - *hp = sp->g_next; - continue; - } - } - prevsp = sp; - } + len = strlen(name); + prevsp = NULL; + hp = &globalhash[HASHSYM(name, len)]; + for (sp = *hp; sp; sp = sp->g_next) { + if (sp->g_len == len && !strcmp(sp->g_name, name) && + sp->g_filescope > SCOPE_GLOBAL) { + if (isglobal || (sp->g_filescope == filescope && + sp->g_funcscope == funcscope)) { + addstatic(sp); + if (prevsp) + prevsp->g_next = sp->g_next; + else + *hp = sp->g_next; + continue; + } + } + prevsp = sp; + } } /* @@ -536,23 +536,23 @@ endscope(char *name, bool isglobal) void addstatic(GLOBAL *sp) { - GLOBAL **stp; + GLOBAL **stp; - if (staticavail <= 0) { - if (staticcount <= 0) - stp = (GLOBAL **) malloc(20 * sizeof(GLOBAL *)); - else - stp = (GLOBAL **) realloc(statictable, - (20 + staticcount) * sizeof(GLOBAL *)); - if (stp == NULL) { - math_error("Cannot allocate static-variable table"); - not_reached(); - } - statictable = stp; - staticavail = 20; - } - statictable[staticcount++] = sp; - staticavail--; + if (staticavail <= 0) { + if (staticcount <= 0) + stp = (GLOBAL **) malloc(20 * sizeof(GLOBAL *)); + else + stp = (GLOBAL **) realloc(statictable, + (20 + staticcount) * sizeof(GLOBAL *)); + if (stp == NULL) { + math_error("Cannot allocate static-variable table"); + not_reached(); + } + statictable = stp; + staticavail = 20; + } + statictable[staticcount++] = sp; + staticavail--; } /* @@ -561,26 +561,26 @@ addstatic(GLOBAL *sp) void showstatics(void) { - long count; - GLOBAL **stp; - GLOBAL *sp; + long count; + GLOBAL **stp; + GLOBAL *sp; - for (count = 0, stp = statictable; count < staticcount; count++) { - sp = *stp++; - if (count == 0) { - printf("\nName Scopes Type\n"); - printf( "---- ------ -----\n"); - } - printf("%-8s", sp->g_name); - printf("%3d", sp->g_filescope); - printf("%3d ", sp->g_funcscope); - printtype(&sp->g_value); - printf("\n"); - } - if (count > 0) - printf("\nNumber: %ld\n", count); - else - printf("No un-scoped static variables\n"); + for (count = 0, stp = statictable; count < staticcount; count++) { + sp = *stp++; + if (count == 0) { + printf("\nName Scopes Type\n"); + printf( "---- ------ -----\n"); + } + printf("%-8s", sp->g_name); + printf("%3d", sp->g_filescope); + printf("%3d ", sp->g_funcscope); + printtype(&sp->g_value); + printf("\n"); + } + if (count > 0) + printf("\nNumber: %ld\n", count); + else + printf("No un-scoped static variables\n"); } /* @@ -591,60 +591,60 @@ showstatics(void) S_FUNC void unscope(void) { - GLOBAL **hp; /* hash table head address */ - register GLOBAL *sp; /* current global symbol pointer */ - GLOBAL *prevsp; /* previous kept symbol pointer */ + GLOBAL **hp; /* hash table head address */ + register GLOBAL *sp; /* current global symbol pointer */ + GLOBAL *prevsp; /* previous kept symbol pointer */ - /* - * We prevent the hp pointer from walking behind globalhash - * by stopping one short of the end and running the loop one - * more time. - * - * We could stop the loop with just hp >= globalhash, but stopping - * short and running the loop one last time manually helps make - * code checkers such as insure happy. - */ - for (hp = &globalhash[HASHSIZE-1]; hp > globalhash; hp--) { - prevsp = NULL; - for (sp = *hp; sp; sp = sp->g_next) { - if ((sp->g_filescope == SCOPE_GLOBAL) || - (sp->g_filescope < filescope) || - ((sp->g_filescope == filescope) && - (sp->g_funcscope <= funcscope))) { - prevsp = sp; - continue; - } + /* + * We prevent the hp pointer from walking behind globalhash + * by stopping one short of the end and running the loop one + * more time. + * + * We could stop the loop with just hp >= globalhash, but stopping + * short and running the loop one last time manually helps make + * code checkers such as insure happy. + */ + for (hp = &globalhash[HASHSIZE-1]; hp > globalhash; hp--) { + prevsp = NULL; + for (sp = *hp; sp; sp = sp->g_next) { + if ((sp->g_filescope == SCOPE_GLOBAL) || + (sp->g_filescope < filescope) || + ((sp->g_filescope == filescope) && + (sp->g_funcscope <= funcscope))) { + prevsp = sp; + continue; + } - /* - * This symbol needs removing. - */ - addstatic(sp); - if (prevsp) - prevsp->g_next = sp->g_next; - else - *hp = sp->g_next; - } - } - /* run the loop manually one last time */ - prevsp = NULL; - for (sp = *hp; sp; sp = sp->g_next) { - if ((sp->g_filescope == SCOPE_GLOBAL) || - (sp->g_filescope < filescope) || - ((sp->g_filescope == filescope) && - (sp->g_funcscope <= funcscope))) { - prevsp = sp; - continue; - } + /* + * This symbol needs removing. + */ + addstatic(sp); + if (prevsp) + prevsp->g_next = sp->g_next; + else + *hp = sp->g_next; + } + } + /* run the loop manually one last time */ + prevsp = NULL; + for (sp = *hp; sp; sp = sp->g_next) { + if ((sp->g_filescope == SCOPE_GLOBAL) || + (sp->g_filescope < filescope) || + ((sp->g_filescope == filescope) && + (sp->g_funcscope <= funcscope))) { + prevsp = sp; + continue; + } - /* - * This symbol needs removing. - */ - addstatic(sp); - if (prevsp) - prevsp->g_next = sp->g_next; - else - *hp = sp->g_next; - } + /* + * This symbol needs removing. + */ + addstatic(sp); + if (prevsp) + prevsp->g_next = sp->g_next; + else + *hp = sp->g_next; + } } @@ -654,10 +654,10 @@ unscope(void) void initlocals(void) { - initstr(&localnames); - initstr(¶mnames); - curfunc->f_localcount = 0; - curfunc->f_paramcount = 0; + initstr(&localnames); + initstr(¶mnames); + curfunc->f_localcount = 0; + curfunc->f_paramcount = 0; } @@ -667,20 +667,20 @@ initlocals(void) * Minus one indicates the symbol could not be added. * * given: - * name name of local variable + * name name of local variable */ long addlocal(char *name) { - long index; /* current symbol index */ + long index; /* current symbol index */ - index = findstr(&localnames, name); - if (index >= 0) - return index; - index = localnames.h_count; - (void) addstr(&localnames, name); - curfunc->f_localcount++; - return index; + index = findstr(&localnames, name); + if (index >= 0) + return index; + index = localnames.h_count; + (void) addstr(&localnames, name); + curfunc->f_localcount++; + return index; } @@ -689,12 +689,12 @@ addlocal(char *name) * Returns minus one if the variable name is not defined. * * given: - * name name of local variable + * name name of local variable */ long findlocal(char *name) { - return findstr(&localnames, name); + return findstr(&localnames, name); } @@ -704,7 +704,7 @@ findlocal(char *name) char * localname(long n) { - return namestr(&localnames, n); + return namestr(&localnames, n); } @@ -714,20 +714,20 @@ localname(long n) * Minus one indicates the symbol could not be added. * * given: - * name name of parameter variable + * name name of parameter variable */ long addparam(char *name) { - long index; /* current symbol index */ + long index; /* current symbol index */ - index = findstr(¶mnames, name); - if (index >= 0) - return index; - index = paramnames.h_count; - (void) addstr(¶mnames, name); - curfunc->f_paramcount++; - return index; + index = findstr(¶mnames, name); + if (index >= 0) + return index; + index = paramnames.h_count; + (void) addstr(¶mnames, name); + curfunc->f_paramcount++; + return index; } @@ -736,12 +736,12 @@ addparam(char *name) * Returns minus one if the variable name is not defined. * * given: - * name name of parameter variable + * name name of parameter variable */ long findparam(char *name) { - return findstr(¶mnames, name); + return findstr(¶mnames, name); } @@ -751,7 +751,7 @@ findparam(char *name) char * paramname(long n) { - return namestr(¶mnames, n); + return namestr(¶mnames, n); } @@ -760,24 +760,24 @@ paramname(long n) * This is either local, parameter, global, static, or undefined. * * given: - * name variable name to find + * name variable name to find */ int symboltype(char *name) { - GLOBAL *sp; + GLOBAL *sp; - if (findparam(name) >= 0) - return SYM_PARAM; - if (findlocal(name) >= 0) - return SYM_LOCAL; - sp = findglobal(name); - if (sp) { - if (sp->g_filescope == SCOPE_GLOBAL) - return SYM_GLOBAL; - return SYM_STATIC; - } - return SYM_UNDEFINED; + if (findparam(name) >= 0) + return SYM_PARAM; + if (findlocal(name) >= 0) + return SYM_LOCAL; + sp = findglobal(name); + if (sp) { + if (sp->g_filescope == SCOPE_GLOBAL) + return SYM_GLOBAL; + return SYM_STATIC; + } + return SYM_UNDEFINED; } /* END CODE */ diff --git a/symbol.h b/symbol.h index ddd2d43..a8fb90d 100644 --- a/symbol.h +++ b/symbol.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:37 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:37 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,7 +28,7 @@ #define INCLUDE_SYMBOL_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "zmath.h" #else # include @@ -38,24 +38,24 @@ /* * Symbol Declarations. */ -#define SYM_UNDEFINED 0 /* undefined symbol */ -#define SYM_PARAM 1 /* parameter symbol */ -#define SYM_LOCAL 2 /* local symbol */ -#define SYM_GLOBAL 3 /* global symbol */ -#define SYM_STATIC 4 /* static symbol */ +#define SYM_UNDEFINED 0 /* undefined symbol */ +#define SYM_PARAM 1 /* parameter symbol */ +#define SYM_LOCAL 2 /* local symbol */ +#define SYM_GLOBAL 3 /* global symbol */ +#define SYM_STATIC 4 /* static symbol */ -#define SCOPE_GLOBAL 0 /* file scope level for global variables */ -#define SCOPE_STATIC 1 /* lowest file scope for static variables */ +#define SCOPE_GLOBAL 0 /* file scope level for global variables */ +#define SCOPE_STATIC 1 /* lowest file scope for static variables */ typedef struct global GLOBAL; struct global { - size_t g_len; /* length of symbol name */ - short g_filescope; /* file scope level of symbol (0 if global) */ - short g_funcscope; /* function scope level of symbol */ - char *g_name; /* global symbol name */ - VALUE g_value; /* global symbol value */ - GLOBAL *g_next; /* next symbol in hash chain */ + size_t g_len; /* length of symbol name */ + short g_filescope; /* file scope level of symbol (0 if global) */ + short g_funcscope; /* function scope level of symbol */ + char *g_name; /* global symbol name */ + VALUE g_value; /* global symbol value */ + GLOBAL *g_next; /* next symbol in hash chain */ }; diff --git a/token.c b/token.c index 503c662..5008a61 100644 --- a/token.c +++ b/token.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:25 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:25 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -38,78 +38,78 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define isletter(ch) ((((ch) >= 'a') && ((ch) <= 'z')) || \ - (((ch) >= 'A') && ((ch) <= 'Z'))) -#define isdigit(ch) (((ch) >= '0') && ((ch) <= '9')) -#define issymbol(ch) (isletter(ch) || isdigit(ch) || ((ch) == '_')) -#define isoctal(ch) (((ch) >= '0') && ((ch) <= '7')) +#define isletter(ch) ((((ch) >= 'a') && ((ch) <= 'z')) || \ + (((ch) >= 'A') && ((ch) <= 'Z'))) +#define isdigit(ch) (((ch) >= '0') && ((ch) <= '9')) +#define issymbol(ch) (isletter(ch) || isdigit(ch) || ((ch) == '_')) +#define isoctal(ch) (((ch) >= '0') && ((ch) <= '7')) -#define STRBUFSIZE 1024 +#define STRBUFSIZE 1024 /* * Current token. */ STATIC struct { - short t_type; /* type of token */ - char *t_sym; /* symbol name */ - long t_strindex; /* index of string value */ - long t_numindex; /* index of numeric value */ + short t_type; /* type of token */ + char *t_sym; /* symbol name */ + long t_strindex; /* index of string value */ + long t_numindex; /* index of numeric value */ } curtoken; -STATIC bool rescan; /* true to reread current token */ -STATIC bool newlines; /* true to return newlines as tokens */ -STATIC bool allsyms; /* true if always want a symbol token */ -STATIC STRINGHEAD strings; /* list of constant strings */ -STATIC char *numbuf; /* buffer for numeric tokens */ -STATIC long numbufsize; /* current size of numeric buffer */ +STATIC bool rescan; /* true to reread current token */ +STATIC bool newlines; /* true to return newlines as tokens */ +STATIC bool allsyms; /* true if always want a symbol token */ +STATIC STRINGHEAD strings; /* list of constant strings */ +STATIC char *numbuf; /* buffer for numeric tokens */ +STATIC long numbufsize; /* current size of numeric buffer */ -long errorcount = 0; /* number of compilation errors */ +long errorcount = 0; /* number of compilation errors */ /* * Table of keywords */ struct keyword { - char *k_name; /* keyword name */ - int k_token; /* token number */ + char *k_name; /* keyword name */ + int k_token; /* token number */ }; STATIC struct keyword keywords[] = { - {"if", T_IF}, - {"else", T_ELSE}, - {"for", T_FOR}, - {"while", T_WHILE}, - {"do", T_DO}, - {"continue", T_CONTINUE}, - {"break", T_BREAK}, - {"goto", T_GOTO}, - {"return", T_RETURN}, - {"local", T_LOCAL}, - {"global", T_GLOBAL}, - {"static", T_STATIC}, - {"switch", T_SWITCH}, - {"case", T_CASE}, - {"default", T_DEFAULT}, - {"quit", T_QUIT}, - {"exit", T_QUIT}, - {"define", T_DEFINE}, - {"read", T_READ}, - {"show", T_SHOW}, - {"help", T_HELP}, - {"man", T_HELP}, - {"write", T_WRITE}, - {"mat", T_MAT}, - {"obj", T_OBJ}, - {"print", T_PRINT}, - {"cd", T_CD}, - {"undefine", T_UNDEFINE}, - {"abort", T_ABORT}, - {NULL, 0} + {"if", T_IF}, + {"else", T_ELSE}, + {"for", T_FOR}, + {"while", T_WHILE}, + {"do", T_DO}, + {"continue", T_CONTINUE}, + {"break", T_BREAK}, + {"goto", T_GOTO}, + {"return", T_RETURN}, + {"local", T_LOCAL}, + {"global", T_GLOBAL}, + {"static", T_STATIC}, + {"switch", T_SWITCH}, + {"case", T_CASE}, + {"default", T_DEFAULT}, + {"quit", T_QUIT}, + {"exit", T_QUIT}, + {"define", T_DEFINE}, + {"read", T_READ}, + {"show", T_SHOW}, + {"help", T_HELP}, + {"man", T_HELP}, + {"write", T_WRITE}, + {"mat", T_MAT}, + {"obj", T_OBJ}, + {"print", T_PRINT}, + {"cd", T_CD}, + {"undefine", T_UNDEFINE}, + {"abort", T_ABORT}, + {NULL, 0} }; @@ -126,11 +126,11 @@ S_FUNC int eatnumber(void); void inittokens(void) { - initstr(&strings); - newlines = false; - allsyms = false; - rescan = false; - setprompt(conf->prompt1); + initstr(&strings); + newlines = false; + allsyms = false; + rescan = false; + setprompt(conf->prompt1); } @@ -141,21 +141,21 @@ inittokens(void) int tokenmode(int flag) { - int oldflag; + int oldflag; - oldflag = TM_DEFAULT; - if (newlines) - oldflag |= TM_NEWLINES; - if (allsyms) - oldflag |= TM_ALLSYMS; - newlines = false; - allsyms = false; - if (flag & TM_NEWLINES) - newlines = true; - if (flag & TM_ALLSYMS) - allsyms = true; - setprompt(newlines ? conf->prompt1 : conf->prompt2); - return oldflag; + oldflag = TM_DEFAULT; + if (newlines) + oldflag |= TM_NEWLINES; + if (allsyms) + oldflag |= TM_ALLSYMS; + newlines = false; + allsyms = false; + if (flag & TM_NEWLINES) + newlines = true; + if (flag & TM_ALLSYMS) + allsyms = true; + setprompt(newlines ? conf->prompt1 : conf->prompt2); + return oldflag; } @@ -167,215 +167,215 @@ tokenmode(int flag) int gettoken(void) { - int ch; /* current input character */ - int type; /* token type */ + int ch; /* current input character */ + int type; /* token type */ - if (rescan) { /* rescanning */ - rescan = false; - return curtoken.t_type; - } - curtoken.t_sym = NULL; - curtoken.t_strindex = 0; - curtoken.t_numindex = 0; - type = T_NULL; - while (type == T_NULL) { - ch = nextchar(); - if (allsyms && ch!=' ' && ch!=';' && ch!='"' && - ch!='\'' && ch!='\n' && ch!=EOF) { - reread(); - type = eatsymbol(); - break; - } - switch (ch) { - case ' ': - case '\a': - case '\b': - case '\f': - case '\r': - case '\t': - case '\v': - case '\0': - break; - case '\n': - if (newlines) - type = T_NEWLINE; - break; - case EOF: type = T_EOF; break; - case '{': type = T_LEFTBRACE; break; - case '}': type = T_RIGHTBRACE; break; - case '(': type = T_LEFTPAREN; break; - case ')': type = T_RIGHTPAREN; break; - case '[': type = T_LEFTBRACKET; break; - case ']': type = T_RIGHTBRACKET; break; - case ';': type = T_SEMICOLON; break; - case ':': type = T_COLON; break; - case ',': type = T_COMMA; break; - case '?': type = T_QUESTIONMARK; break; - case '@': type = T_AT; break; - case '`': type = T_BACKQUOTE; break; - case '$': type = T_DOLLAR; break; - case '"': - case '\'': - type = T_STRING; - eatstring(ch); - break; - case '^': - switch (nextchar()) { - case '=': type = T_POWEREQUALS; break; - default: type = T_POWER; reread(); - } - break; - case '=': - switch (nextchar()) { - case '=': type = T_EQ; break; - default: type = T_ASSIGN; reread(); - } - break; - case '+': - switch (nextchar()) { - case '+': type = T_PLUSPLUS; break; - case '=': type = T_PLUSEQUALS; break; - default: type = T_PLUS; reread(); - } - break; - case '-': - switch (nextchar()) { - case '-': type = T_MINUSMINUS; break; - case '=': type = T_MINUSEQUALS; break; - case '>': type = T_ARROW; break; - default: type = T_MINUS; reread(); - } - break; - case '*': - switch (nextchar()) { - case '=': type = T_MULTEQUALS; break; - case '*': - switch (nextchar()) { - case '=': - type = T_POWEREQUALS; break; - default: - type = T_POWER; reread(); - } - break; - default: type = T_MULT; reread(); - } - break; - case '/': - switch (nextchar()) { - case '/': - switch (nextchar()) { - case '=': - type = T_SLASHSLASHEQUALS; - break; - default: - reread(); - type = T_SLASHSLASH; - break; - } - break; - case '=': type = T_DIVEQUALS; break; - case '*': eatcomment(); break; - default: type = T_DIV; reread(); - } - break; - case '%': - switch (nextchar()) { - case '=': type = T_MODEQUALS; break; - default: type = T_MOD; reread(); - } - break; - case '<': - switch (nextchar()) { - case '=': type = T_LE; break; - case '<': - switch (nextchar()) { - case '=': - type = T_LSHIFTEQUALS; - break; - default: - reread(); - type = T_LEFTSHIFT; - break; - } - break; - default: type = T_LT; reread(); - } - break; - case '>': - switch (nextchar()) { - case '=': type = T_GE; break; - case '>': - switch (nextchar()) { - case '=': - type = T_RSHIFTEQUALS; - break; - default: - reread(); - type = T_RIGHTSHIFT; - break; - } - break; - default: type = T_GT; reread(); - } - break; - case '&': - switch (nextchar()) { - case '&': type = T_ANDAND; break; - case '=': type = T_ANDEQUALS; break; - default: type = T_AND; reread(); break; - } - break; - case '|': - switch (nextchar()) { - case '|': type = T_OROR; break; - case '=': type = T_OREQUALS; break; - default: type = T_OR; reread(); break; - } - break; - case '!': - switch (nextchar()) { - case '=': type = T_NE; break; - default: type = T_NOT; reread(); break; - } - break; - case '#': - switch(nextchar()) { - case '=': type = T_HASHEQUALS; break; - case '!': - case '#': eatline(); break; - case '\n': reread(); break; - default: type = T_HASH; reread(); - } - break; - case '~': - switch (nextchar()) { - case '=': type = T_TILDEEQUALS; break; - default: type = T_TILDE; reread(); - } - break; - case '\\': - switch (nextchar()) { - case '\n': setprompt(conf->prompt2); break; - case '=': type = T_BACKSLASHEQUALS; break; - default: type = T_BACKSLASH; reread(); - } - break; - default: - if (isletter(ch) || ch == '_') { - reread(); - type = eatsymbol(); - break; - } - if (isdigit(ch) || (ch == '.')) { - reread(); - type = eatnumber(); - break; - } - scanerror(T_NULL, "Unknown token character '%c'", ch); - } - } - curtoken.t_type = (short)type; - return type; + if (rescan) { /* rescanning */ + rescan = false; + return curtoken.t_type; + } + curtoken.t_sym = NULL; + curtoken.t_strindex = 0; + curtoken.t_numindex = 0; + type = T_NULL; + while (type == T_NULL) { + ch = nextchar(); + if (allsyms && ch!=' ' && ch!=';' && ch!='"' && + ch!='\'' && ch!='\n' && ch!=EOF) { + reread(); + type = eatsymbol(); + break; + } + switch (ch) { + case ' ': + case '\a': + case '\b': + case '\f': + case '\r': + case '\t': + case '\v': + case '\0': + break; + case '\n': + if (newlines) + type = T_NEWLINE; + break; + case EOF: type = T_EOF; break; + case '{': type = T_LEFTBRACE; break; + case '}': type = T_RIGHTBRACE; break; + case '(': type = T_LEFTPAREN; break; + case ')': type = T_RIGHTPAREN; break; + case '[': type = T_LEFTBRACKET; break; + case ']': type = T_RIGHTBRACKET; break; + case ';': type = T_SEMICOLON; break; + case ':': type = T_COLON; break; + case ',': type = T_COMMA; break; + case '?': type = T_QUESTIONMARK; break; + case '@': type = T_AT; break; + case '`': type = T_BACKQUOTE; break; + case '$': type = T_DOLLAR; break; + case '"': + case '\'': + type = T_STRING; + eatstring(ch); + break; + case '^': + switch (nextchar()) { + case '=': type = T_POWEREQUALS; break; + default: type = T_POWER; reread(); + } + break; + case '=': + switch (nextchar()) { + case '=': type = T_EQ; break; + default: type = T_ASSIGN; reread(); + } + break; + case '+': + switch (nextchar()) { + case '+': type = T_PLUSPLUS; break; + case '=': type = T_PLUSEQUALS; break; + default: type = T_PLUS; reread(); + } + break; + case '-': + switch (nextchar()) { + case '-': type = T_MINUSMINUS; break; + case '=': type = T_MINUSEQUALS; break; + case '>': type = T_ARROW; break; + default: type = T_MINUS; reread(); + } + break; + case '*': + switch (nextchar()) { + case '=': type = T_MULTEQUALS; break; + case '*': + switch (nextchar()) { + case '=': + type = T_POWEREQUALS; break; + default: + type = T_POWER; reread(); + } + break; + default: type = T_MULT; reread(); + } + break; + case '/': + switch (nextchar()) { + case '/': + switch (nextchar()) { + case '=': + type = T_SLASHSLASHEQUALS; + break; + default: + reread(); + type = T_SLASHSLASH; + break; + } + break; + case '=': type = T_DIVEQUALS; break; + case '*': eatcomment(); break; + default: type = T_DIV; reread(); + } + break; + case '%': + switch (nextchar()) { + case '=': type = T_MODEQUALS; break; + default: type = T_MOD; reread(); + } + break; + case '<': + switch (nextchar()) { + case '=': type = T_LE; break; + case '<': + switch (nextchar()) { + case '=': + type = T_LSHIFTEQUALS; + break; + default: + reread(); + type = T_LEFTSHIFT; + break; + } + break; + default: type = T_LT; reread(); + } + break; + case '>': + switch (nextchar()) { + case '=': type = T_GE; break; + case '>': + switch (nextchar()) { + case '=': + type = T_RSHIFTEQUALS; + break; + default: + reread(); + type = T_RIGHTSHIFT; + break; + } + break; + default: type = T_GT; reread(); + } + break; + case '&': + switch (nextchar()) { + case '&': type = T_ANDAND; break; + case '=': type = T_ANDEQUALS; break; + default: type = T_AND; reread(); break; + } + break; + case '|': + switch (nextchar()) { + case '|': type = T_OROR; break; + case '=': type = T_OREQUALS; break; + default: type = T_OR; reread(); break; + } + break; + case '!': + switch (nextchar()) { + case '=': type = T_NE; break; + default: type = T_NOT; reread(); break; + } + break; + case '#': + switch(nextchar()) { + case '=': type = T_HASHEQUALS; break; + case '!': + case '#': eatline(); break; + case '\n': reread(); break; + default: type = T_HASH; reread(); + } + break; + case '~': + switch (nextchar()) { + case '=': type = T_TILDEEQUALS; break; + default: type = T_TILDE; reread(); + } + break; + case '\\': + switch (nextchar()) { + case '\n': setprompt(conf->prompt2); break; + case '=': type = T_BACKSLASHEQUALS; break; + default: type = T_BACKSLASH; reread(); + } + break; + default: + if (isletter(ch) || ch == '_') { + reread(); + type = eatsymbol(); + break; + } + if (isdigit(ch) || (ch == '.')) { + reread(); + type = eatnumber(); + break; + } + scanerror(T_NULL, "Unknown token character '%c'", ch); + } + } + curtoken.t_type = (short)type; + return type; } @@ -386,23 +386,23 @@ gettoken(void) S_FUNC void eatcomment(void) { - int ch; - setprompt(conf->prompt2); - for (;;) { - ch = nextchar(); - if (ch == '*') { - ch = nextchar(); - if (ch == '/') - break; - reread(); - } - if (ch == EOF || ch == '\0') { - scanerror(T_NULL, "Unterminated comment"); - reread(); - break; - } - } - setprompt(conf->prompt1); + int ch; + setprompt(conf->prompt2); + for (;;) { + ch = nextchar(); + if (ch == '*') { + ch = nextchar(); + if (ch == '/') + break; + reread(); + } + if (ch == EOF || ch == '\0') { + scanerror(T_NULL, "Unterminated comment"); + reread(); + break; + } + } + setprompt(conf->prompt1); } @@ -414,12 +414,12 @@ eatcomment(void) S_FUNC void eatline(void) { - int ch; /* chars being eaten */ + int ch; /* chars being eaten */ - do { - ch = nextchar(); - } while (ch != '\n' && ch != EOF && ch != '\0'); - reread(); + do { + ch = nextchar(); + } while (ch != '\n' && ch != EOF && ch != '\0'); + reread(); } @@ -430,124 +430,124 @@ eatline(void) S_FUNC void eatstring(int quotechar) { - register char *cp; /* current character address */ - int ch, cch; /* current character */ - int i; /* index */ - char buf[STRBUFSIZE]; /* buffer for string */ - long len; /* length in buffer */ - long totlen; /* total length, including '\0' */ - char *str; - bool done; + register char *cp; /* current character address */ + int ch, cch; /* current character */ + int i; /* index */ + char buf[STRBUFSIZE]; /* buffer for string */ + long len; /* length in buffer */ + long totlen; /* total length, including '\0' */ + char *str; + bool done; - str = buf; - totlen = 0; - done = false; + str = buf; + totlen = 0; + done = false; - while (!done) { - cp = buf; - len = 0; - while (!done && len < STRBUFSIZE) { - ch = nextchar(); - switch (ch) { - case '\n': - if (!newlines) - break; - /*FALLTHRU*/ - case EOF: - reread(); - scanerror(T_NULL, - "Unterminated string constant"); - done = true; - ch = '\0'; - break; + while (!done) { + cp = buf; + len = 0; + while (!done && len < STRBUFSIZE) { + ch = nextchar(); + switch (ch) { + case '\n': + if (!newlines) + break; + /*FALLTHRU*/ + case EOF: + reread(); + scanerror(T_NULL, + "Unterminated string constant"); + done = true; + ch = '\0'; + break; - case '\\': - ch = nextchar(); - if (isoctal(ch)) { - ch = ch - '0'; - for (i = 2; i > 0; i--) { - cch = nextchar(); - if (!isoctal(cch)) - break; - ch = 8 * ch + cch - '0'; - } - ch &= 0xff; - if (i > 0) - reread(); - break; - } - switch (ch) { - case 'n': ch = '\n'; break; - case 'r': ch = '\r'; break; - case 't': ch = '\t'; break; - case 'b': ch = '\b'; break; - case 'f': ch = '\f'; break; - case 'v': ch = '\v'; break; - case 'a': ch = '\007'; break; - case 'e': ch = '\033'; break; - case '\n': - setprompt(conf->prompt2); - continue; - case EOF: - reread(); - continue; - case 'x': - ch = 0; - for (i = 2; i > 0; i--) { - cch = nextchar(); - if (isdigit(cch)) - ch = 16 * ch + cch - '0'; - else if (cch >= 'a' && cch <= 'f') - ch = 16 * ch + 10 + cch - 'a'; - else if (cch >= 'A' && cch <= 'F') - ch = 16 * ch + 10 + cch - 'A'; - else break; - } - if (i > 0) - reread(); - } - break; - case '"': - case '\'': - if (ch == quotechar) { - for (;;) { - ch = nextchar(); - if (ch != ' ' && ch != '\t' && - (ch != '\n' || - newlines)) - break; - } - if (ch == '"' || ch == '\'') { - quotechar = ch; - continue; - } - reread(); - done = true; - ch = '\0'; - } - break; - } + case '\\': + ch = nextchar(); + if (isoctal(ch)) { + ch = ch - '0'; + for (i = 2; i > 0; i--) { + cch = nextchar(); + if (!isoctal(cch)) + break; + ch = 8 * ch + cch - '0'; + } + ch &= 0xff; + if (i > 0) + reread(); + break; + } + switch (ch) { + case 'n': ch = '\n'; break; + case 'r': ch = '\r'; break; + case 't': ch = '\t'; break; + case 'b': ch = '\b'; break; + case 'f': ch = '\f'; break; + case 'v': ch = '\v'; break; + case 'a': ch = '\007'; break; + case 'e': ch = '\033'; break; + case '\n': + setprompt(conf->prompt2); + continue; + case EOF: + reread(); + continue; + case 'x': + ch = 0; + for (i = 2; i > 0; i--) { + cch = nextchar(); + if (isdigit(cch)) + ch = 16 * ch + cch - '0'; + else if (cch >= 'a' && cch <= 'f') + ch = 16 * ch + 10 + cch - 'a'; + else if (cch >= 'A' && cch <= 'F') + ch = 16 * ch + 10 + cch - 'A'; + else break; + } + if (i > 0) + reread(); + } + break; + case '"': + case '\'': + if (ch == quotechar) { + for (;;) { + ch = nextchar(); + if (ch != ' ' && ch != '\t' && + (ch != '\n' || + newlines)) + break; + } + if (ch == '"' || ch == '\'') { + quotechar = ch; + continue; + } + reread(); + done = true; + ch = '\0'; + } + break; + } - *cp++ = (char) ch; - len++; - } - if (!done || totlen) { - if (totlen) - str = (char *) realloc(str, totlen + len); - else - str = (char *) malloc(len); - if (str == NULL) { - math_error("Out of memory for reading tokens"); - not_reached(); - } - memcpy(str + totlen, buf, len); - totlen += len; - len = 0; - } - } - curtoken.t_strindex = addstring(str, totlen + len); - if (str != buf) - free(str); + *cp++ = (char) ch; + len++; + } + if (!done || totlen) { + if (totlen) + str = (char *) realloc(str, totlen + len); + else + str = (char *) malloc(len); + if (str == NULL) { + math_error("Out of memory for reading tokens"); + not_reached(); + } + memcpy(str + totlen, buf, len); + totlen += len; + len = 0; + } + } + curtoken.t_strindex = addstring(str, totlen + len); + if (str != buf) + free(str); } @@ -559,46 +559,46 @@ eatstring(int quotechar) S_FUNC int eatsymbol(void) { - register struct keyword *kp; /* pointer to current keyword */ - register char *cp; /* current character pointer */ - int ch; /* current character */ - int cc; /* character count */ - STATIC char buf[SYMBOLSIZE+1]; /* temporary buffer */ + register struct keyword *kp; /* pointer to current keyword */ + register char *cp; /* current character pointer */ + int ch; /* current character */ + int cc; /* character count */ + STATIC char buf[SYMBOLSIZE+1]; /* temporary buffer */ - cp = buf; - cc = SYMBOLSIZE; - if (allsyms) { - for (;;) { - ch = nextchar(); - if (ch == ' ' || ch == ';' || - ch == '\n' || ch == EOF) - break; - if (cc-- > 0) - *cp++ = (char) ch; - } - reread(); - *cp = '\0'; - if (cc < 0) - scanerror(T_NULL, "Symbol too long"); - curtoken.t_sym = buf; - return T_SYMBOL; - } - for (;;) { - ch = nextchar(); - if (!issymbol(ch)) - break; - if (cc-- > 0) - *cp++ = (char)ch; - } - reread(); - *cp = '\0'; - if (cc < 0) - scanerror(T_NULL, "Symbol too long"); - for (kp = keywords; kp->k_name; kp++) - if (strcmp(kp->k_name, buf) == 0) - return kp->k_token; - curtoken.t_sym = buf; - return T_SYMBOL; + cp = buf; + cc = SYMBOLSIZE; + if (allsyms) { + for (;;) { + ch = nextchar(); + if (ch == ' ' || ch == ';' || + ch == '\n' || ch == EOF) + break; + if (cc-- > 0) + *cp++ = (char) ch; + } + reread(); + *cp = '\0'; + if (cc < 0) + scanerror(T_NULL, "Symbol too long"); + curtoken.t_sym = buf; + return T_SYMBOL; + } + for (;;) { + ch = nextchar(); + if (!issymbol(ch)) + break; + if (cc-- > 0) + *cp++ = (char)ch; + } + reread(); + *cp = '\0'; + if (cc < 0) + scanerror(T_NULL, "Symbol too long"); + for (kp = keywords; kp->k_name; kp++) + if (strcmp(kp->k_name, buf) == 0) + return kp->k_token; + curtoken.t_sym = buf; + return T_SYMBOL; } @@ -612,59 +612,59 @@ eatsymbol(void) S_FUNC int eatnumber(void) { - register char *cp; /* current character pointer */ - long len; /* parsed size of number */ - long res; /* result of parsing number */ + register char *cp; /* current character pointer */ + long len; /* parsed size of number */ + long res; /* result of parsing number */ - if (numbufsize == 0) { - numbuf = (char *)malloc(128+1); - if (numbuf == NULL) - math_error("Cannot allocate number buffer"); - numbufsize = 128; - } - cp = numbuf; - len = 0; - for (;;) { - if (len >= numbufsize) { - cp = (char *)realloc(numbuf, numbufsize + 1001); - if (cp == NULL) { - math_error("Cannot reallocate number buffer"); - not_reached(); - } - numbuf = cp; - numbufsize += 1000; - cp = &numbuf[len]; - } - *cp = nextchar(); - *(++cp) = '\0'; - if ((numbuf[0] == '.') && isletter(numbuf[1])) { - reread(); - return T_PERIOD; - } - res = qparse(numbuf, QPF_IMAG); - if (res < 0) { - reread(); - scanerror(T_NULL, "Badly formatted number"); - curtoken.t_numindex = addnumber("0"); - return T_NUMBER; - } - if (res != ++len) - break; - } - cp[-1] = '\0'; - reread(); - if ((numbuf[0] == '.') && (numbuf[1] == '\0')) { - curtoken.t_numindex = 0; - return T_OLDVALUE; - } - cp -= 2; - res = T_NUMBER; - if ((*cp == 'i') || (*cp == 'I')) { - *cp = '\0'; - res = T_IMAGINARY; - } - curtoken.t_numindex = addnumber(numbuf); - return (int)res; + if (numbufsize == 0) { + numbuf = (char *)malloc(128+1); + if (numbuf == NULL) + math_error("Cannot allocate number buffer"); + numbufsize = 128; + } + cp = numbuf; + len = 0; + for (;;) { + if (len >= numbufsize) { + cp = (char *)realloc(numbuf, numbufsize + 1001); + if (cp == NULL) { + math_error("Cannot reallocate number buffer"); + not_reached(); + } + numbuf = cp; + numbufsize += 1000; + cp = &numbuf[len]; + } + *cp = nextchar(); + *(++cp) = '\0'; + if ((numbuf[0] == '.') && isletter(numbuf[1])) { + reread(); + return T_PERIOD; + } + res = qparse(numbuf, QPF_IMAG); + if (res < 0) { + reread(); + scanerror(T_NULL, "Badly formatted number"); + curtoken.t_numindex = addnumber("0"); + return T_NUMBER; + } + if (res != ++len) + break; + } + cp[-1] = '\0'; + reread(); + if ((numbuf[0] == '.') && (numbuf[1] == '\0')) { + curtoken.t_numindex = 0; + return T_OLDVALUE; + } + cp -= 2; + res = T_NUMBER; + if ((*cp == 'i') || (*cp == 'I')) { + *cp = '\0'; + res = T_IMAGINARY; + } + curtoken.t_numindex = addnumber(numbuf); + return (int)res; } @@ -674,7 +674,7 @@ eatnumber(void) long tokenstring(void) { - return curtoken.t_strindex; + return curtoken.t_strindex; } @@ -684,7 +684,7 @@ tokenstring(void) long tokennumber(void) { - return curtoken.t_numindex; + return curtoken.t_numindex; } /* @@ -693,7 +693,7 @@ tokennumber(void) char * tokensymbol(void) { - return curtoken.t_sym; + return curtoken.t_sym; } /* @@ -702,7 +702,7 @@ tokensymbol(void) void rescantoken(void) { - rescan = true; + rescan = true; } @@ -713,103 +713,103 @@ rescantoken(void) void scanerror(int skip, char *fmt, ...) { - va_list ap; - char *name; /* name of file with error */ - int len; /* length of error msg buffer */ + va_list ap; + char *name; /* name of file with error */ + int len; /* length of error msg buffer */ - /* count the error */ - errorcount++; + /* count the error */ + errorcount++; - /* form the error message */ - name = inputname(); - va_start(ap, fmt); - if (name) { - snprintf(calc_err_msg, MAXERROR, "\"%s\", line %ld: ", - name, linenumber()); - calc_err_msg[MAXERROR] = '\0'; /* paranoia */ - len = strlen(calc_err_msg); - if (len < MAXERROR) { - vsnprintf(calc_err_msg+len, MAXERROR-len, fmt, ap); - } - } else { - vsnprintf(calc_err_msg, MAXERROR, fmt, ap); - } - va_end(ap); - calc_err_msg[MAXERROR] = '\0'; /* paranoia */ + /* form the error message */ + name = inputname(); + va_start(ap, fmt); + if (name) { + snprintf(calc_err_msg, MAXERROR, "\"%s\", line %ld: ", + name, linenumber()); + calc_err_msg[MAXERROR] = '\0'; /* paranoia */ + len = strlen(calc_err_msg); + if (len < MAXERROR) { + vsnprintf(calc_err_msg+len, MAXERROR-len, fmt, ap); + } + } else { + vsnprintf(calc_err_msg, MAXERROR, fmt, ap); + } + va_end(ap); + calc_err_msg[MAXERROR] = '\0'; /* paranoia */ - /* print error message if allowed */ - if (calc_print_scanerr_msg != 0) { - fprintf(stderr, "%s\n\n", calc_err_msg); - } + /* print error message if allowed */ + if (calc_print_scanerr_msg != 0) { + fprintf(stderr, "%s\n\n", calc_err_msg); + } - /* bail out if continuation not permitted */ - if ((!c_flag && !stoponerror) || stoponerror > 0) { - if (calc_use_scanerr_jmpbuf != 0) { - longjmp(calc_scanerr_jmpbuf, 60); - not_reached(); - } else { - fprintf(stderr, - "calc_scanerr_jmpbuf not setup, exiting code 60\n"); - libcalc_call_me_last(); - exit(60); - } - } + /* bail out if continuation not permitted */ + if ((!c_flag && !stoponerror) || stoponerror > 0) { + if (calc_use_scanerr_jmpbuf != 0) { + longjmp(calc_scanerr_jmpbuf, 60); + not_reached(); + } else { + fprintf(stderr, + "calc_scanerr_jmpbuf not setup, exiting code 60\n"); + libcalc_call_me_last(); + exit(60); + } + } - /* bail out if too many errors */ - if (conf->maxscancount > 0 && errorcount > conf->maxscancount) { - fprintf(stderr, "Too many scan errors, compilation aborted.\n"); - if (calc_use_scanerr_jmpbuf != 0) { - longjmp(calc_scanerr_jmpbuf, 61); - not_reached(); - } else { - fprintf(stderr, - "calc_scanerr_jmpbuf not ready: exit 61\n"); - libcalc_call_me_last(); - exit(61); - } - } + /* bail out if too many errors */ + if (conf->maxscancount > 0 && errorcount > conf->maxscancount) { + fprintf(stderr, "Too many scan errors, compilation aborted.\n"); + if (calc_use_scanerr_jmpbuf != 0) { + longjmp(calc_scanerr_jmpbuf, 61); + not_reached(); + } else { + fprintf(stderr, + "calc_scanerr_jmpbuf not ready: exit 61\n"); + libcalc_call_me_last(); + exit(61); + } + } - /* post-error report processing */ - switch (skip) { - case T_NULL: - return; - case T_COMMA: - rescan = true; - for (;;) { - switch (gettoken()) { - case T_NEWLINE: - case T_SEMICOLON: - case T_LEFTBRACE: - case T_RIGHTBRACE: - case T_EOF: - case T_COMMA: - rescan = true; - return; - } - } - default: - snprintf(calc_err_msg, MAXERROR, - "Unknown skip token for scanerror\n"); - calc_err_msg[MAXERROR] = '\0'; /* paranoia */ - if (calc_print_scanerr_msg != 0) { - fprintf(stderr, "%s\n\n", calc_err_msg); - } - /* fall into semicolon case */ - /*FALLTHRU*/ - case T_SEMICOLON: - rescan = true; - for (;;) { - switch (gettoken()) { - case T_NEWLINE: - case T_SEMICOLON: - case T_LEFTBRACE: - case T_RIGHTBRACE: - case T_EOF: - rescan = true; - return; - } - } - } + /* post-error report processing */ + switch (skip) { + case T_NULL: + return; + case T_COMMA: + rescan = true; + for (;;) { + switch (gettoken()) { + case T_NEWLINE: + case T_SEMICOLON: + case T_LEFTBRACE: + case T_RIGHTBRACE: + case T_EOF: + case T_COMMA: + rescan = true; + return; + } + } + default: + snprintf(calc_err_msg, MAXERROR, + "Unknown skip token for scanerror\n"); + calc_err_msg[MAXERROR] = '\0'; /* paranoia */ + if (calc_print_scanerr_msg != 0) { + fprintf(stderr, "%s\n\n", calc_err_msg); + } + /* fall into semicolon case */ + /*FALLTHRU*/ + case T_SEMICOLON: + rescan = true; + for (;;) { + switch (gettoken()) { + case T_NEWLINE: + case T_SEMICOLON: + case T_LEFTBRACE: + case T_RIGHTBRACE: + case T_EOF: + rescan = true; + return; + } + } + } } /* @@ -818,33 +818,33 @@ scanerror(int skip, char *fmt, ...) void warning(char *fmt, ...) { - va_list ap; - char *name; /* name of file with error */ - int len; /* length of error msg buffer */ + va_list ap; + char *name; /* name of file with error */ + int len; /* length of error msg buffer */ - /* count this warning */ - ++calc_warn_cnt; + /* count this warning */ + ++calc_warn_cnt; - /* form the error message */ - name = inputname(); - va_start(ap, fmt); - if (name) { - snprintf(calc_warn_msg, MAXERROR, "\"%s\", line %ld: ", - name, linenumber()); - calc_warn_msg[MAXERROR] = '\0'; /* paranoia */ - len = strlen(calc_warn_msg); - if (len < MAXERROR) { - vsnprintf(calc_warn_msg+len, MAXERROR-len, fmt, ap); - } - } else { - vsnprintf(calc_warn_msg, MAXERROR, fmt, ap); - } - va_end(ap); - calc_warn_msg[MAXERROR] = '\0'; /* paranoia */ + /* form the error message */ + name = inputname(); + va_start(ap, fmt); + if (name) { + snprintf(calc_warn_msg, MAXERROR, "\"%s\", line %ld: ", + name, linenumber()); + calc_warn_msg[MAXERROR] = '\0'; /* paranoia */ + len = strlen(calc_warn_msg); + if (len < MAXERROR) { + vsnprintf(calc_warn_msg+len, MAXERROR-len, fmt, ap); + } + } else { + vsnprintf(calc_warn_msg, MAXERROR, fmt, ap); + } + va_end(ap); + calc_warn_msg[MAXERROR] = '\0'; /* paranoia */ - /* print the warning if allowed */ - if (calc_print_scanwarn_msg != 0) { - fprintf(stderr, "Warning: %s\n", calc_warn_msg); - } - return; + /* print the warning if allowed */ + if (calc_print_scanwarn_msg != 0) { + fprintf(stderr, "Warning: %s\n", calc_warn_msg); + } + return; } diff --git a/token.h b/token.h index aa76fc9..fe1a9e0 100644 --- a/token.h +++ b/token.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:37 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:37 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,7 +28,7 @@ #define INCLUDE_TOKEN_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "zmath.h" #else # include @@ -38,135 +38,135 @@ /* * Token types */ -#define T_NULL 0 /* null token */ -#define T_LEFTPAREN 1 /* left parenthesis "(" */ -#define T_RIGHTPAREN 2 /* right parenthesis ")" */ -#define T_LEFTBRACE 3 /* left brace "{" */ -#define T_RIGHTBRACE 4 /* right brace "}" */ -#define T_SEMICOLON 5 /* end of statement ";" */ -#define T_EOF 6 /* end of file */ -#define T_COLON 7 /* label character ":" */ -#define T_ASSIGN 8 /* assignment "=" */ -#define T_PLUS 9 /* plus sign "+" */ -#define T_MINUS 10 /* minus sign "-" */ -#define T_MULT 11 /* multiply sign "*" */ -#define T_DIV 12 /* divide sign "/" */ -#define T_MOD 13 /* modulo sign "%" */ -#define T_POWER 14 /* power sign "^" or "**" */ -#define T_EQ 15 /* equality "==" */ -#define T_NE 16 /* not-equal "!=" */ -#define T_LT 17 /* less than "<" */ -#define T_GT 18 /* greater than ">" */ -#define T_LE 19 /* less than or equals "<=" */ -#define T_GE 20 /* greater than or equals ">=" */ -#define T_LEFTBRACKET 21 /* left bracket "[" */ -#define T_RIGHTBRACKET 22 /* right bracket "]" */ -#define T_SYMBOL 23 /* symbol name */ -#define T_STRING 24 /* string value (double quotes) */ -#define T_NUMBER 25 /* numeric real constant */ -#define T_PLUSEQUALS 26 /* plus equals "+=" */ -#define T_MINUSEQUALS 27 /* minus equals "-=" */ -#define T_MULTEQUALS 28 /* multiply equals "*=" */ -#define T_DIVEQUALS 29 /* divide equals "/=" */ -#define T_MODEQUALS 30 /* modulo equals "%=" */ -#define T_PLUSPLUS 31 /* plus-plus "++" */ -#define T_MINUSMINUS 32 /* minus-minus "--" */ -#define T_COMMA 33 /* comma "," */ -#define T_ANDAND 34 /* logical and "&&" */ -#define T_OROR 35 /* logical or "||" */ -#define T_OLDVALUE 36 /* old value from prev calculation */ -#define T_SLASHSLASH 37 /* integer divide "//" */ -#define T_NEWLINE 38 /* newline character */ -#define T_SLASHSLASHEQUALS 39 /* integer divide equals "//=" */ -#define T_AND 40 /* arithmetic and "&" */ -#define T_OR 41 /* arithmetic or "|" */ -#define T_NOT 42 /* logical not "!" */ -#define T_LEFTSHIFT 43 /* left shift "<<" */ -#define T_RIGHTSHIFT 44 /* right shift ">>" */ -#define T_ANDEQUALS 45 /* and equals "&=" */ -#define T_OREQUALS 46 /* or equals "|= */ -#define T_LSHIFTEQUALS 47 /* left shift equals "<<=" */ -#define T_RSHIFTEQUALS 48 /* right shift equals ">>= */ -#define T_POWEREQUALS 49 /* power equals "^=" or "**=" */ -#define T_PERIOD 50 /* period "." */ -#define T_IMAGINARY 51 /* numeric imaginary constant */ -#define T_AMPERSAND 52 /* ampersand "&" */ -#define T_QUESTIONMARK 53 /* question mark "?" */ -#define T_AT 54 /* at sign "@" */ -#define T_DOLLAR 55 /* dollar sign "$" */ -#define T_HASH 56 /* hash or pound sign "#" */ -#define T_HASHEQUALS 57 /* hash equals "#=" */ -#define T_BACKQUOTE 58 /* backquote sign "`" */ -#define T_ARROW 59 /* arrow "->" */ -#define T_TILDE 60 /* tilde "~" */ -#define T_TILDEEQUALS 61 /* tilde equals "~=" */ -#define T_BACKSLASH 62 /* backslash or setminus "\" */ -#define T_BACKSLASHEQUALS 63 /* backslash equals "\=" */ -#define T_POUNDBANG 64 /* #!/usr/local/bin/calc comment */ -#define T_POUNDCOMMENT 65 /* #[whitespace] comment */ +#define T_NULL 0 /* null token */ +#define T_LEFTPAREN 1 /* left parenthesis "(" */ +#define T_RIGHTPAREN 2 /* right parenthesis ")" */ +#define T_LEFTBRACE 3 /* left brace "{" */ +#define T_RIGHTBRACE 4 /* right brace "}" */ +#define T_SEMICOLON 5 /* end of statement ";" */ +#define T_EOF 6 /* end of file */ +#define T_COLON 7 /* label character ":" */ +#define T_ASSIGN 8 /* assignment "=" */ +#define T_PLUS 9 /* plus sign "+" */ +#define T_MINUS 10 /* minus sign "-" */ +#define T_MULT 11 /* multiply sign "*" */ +#define T_DIV 12 /* divide sign "/" */ +#define T_MOD 13 /* modulo sign "%" */ +#define T_POWER 14 /* power sign "^" or "**" */ +#define T_EQ 15 /* equality "==" */ +#define T_NE 16 /* not-equal "!=" */ +#define T_LT 17 /* less than "<" */ +#define T_GT 18 /* greater than ">" */ +#define T_LE 19 /* less than or equals "<=" */ +#define T_GE 20 /* greater than or equals ">=" */ +#define T_LEFTBRACKET 21 /* left bracket "[" */ +#define T_RIGHTBRACKET 22 /* right bracket "]" */ +#define T_SYMBOL 23 /* symbol name */ +#define T_STRING 24 /* string value (double quotes) */ +#define T_NUMBER 25 /* numeric real constant */ +#define T_PLUSEQUALS 26 /* plus equals "+=" */ +#define T_MINUSEQUALS 27 /* minus equals "-=" */ +#define T_MULTEQUALS 28 /* multiply equals "*=" */ +#define T_DIVEQUALS 29 /* divide equals "/=" */ +#define T_MODEQUALS 30 /* modulo equals "%=" */ +#define T_PLUSPLUS 31 /* plus-plus "++" */ +#define T_MINUSMINUS 32 /* minus-minus "--" */ +#define T_COMMA 33 /* comma "," */ +#define T_ANDAND 34 /* logical and "&&" */ +#define T_OROR 35 /* logical or "||" */ +#define T_OLDVALUE 36 /* old value from prev calculation */ +#define T_SLASHSLASH 37 /* integer divide "//" */ +#define T_NEWLINE 38 /* newline character */ +#define T_SLASHSLASHEQUALS 39 /* integer divide equals "//=" */ +#define T_AND 40 /* arithmetic and "&" */ +#define T_OR 41 /* arithmetic or "|" */ +#define T_NOT 42 /* logical not "!" */ +#define T_LEFTSHIFT 43 /* left shift "<<" */ +#define T_RIGHTSHIFT 44 /* right shift ">>" */ +#define T_ANDEQUALS 45 /* and equals "&=" */ +#define T_OREQUALS 46 /* or equals "|= */ +#define T_LSHIFTEQUALS 47 /* left shift equals "<<=" */ +#define T_RSHIFTEQUALS 48 /* right shift equals ">>= */ +#define T_POWEREQUALS 49 /* power equals "^=" or "**=" */ +#define T_PERIOD 50 /* period "." */ +#define T_IMAGINARY 51 /* numeric imaginary constant */ +#define T_AMPERSAND 52 /* ampersand "&" */ +#define T_QUESTIONMARK 53 /* question mark "?" */ +#define T_AT 54 /* at sign "@" */ +#define T_DOLLAR 55 /* dollar sign "$" */ +#define T_HASH 56 /* hash or pound sign "#" */ +#define T_HASHEQUALS 57 /* hash equals "#=" */ +#define T_BACKQUOTE 58 /* backquote sign "`" */ +#define T_ARROW 59 /* arrow "->" */ +#define T_TILDE 60 /* tilde "~" */ +#define T_TILDEEQUALS 61 /* tilde equals "~=" */ +#define T_BACKSLASH 62 /* backslash or setminus "\" */ +#define T_BACKSLASHEQUALS 63 /* backslash equals "\=" */ +#define T_POUNDBANG 64 /* #!/usr/local/bin/calc comment */ +#define T_POUNDCOMMENT 65 /* #[whitespace] comment */ /* * Keyword tokens */ -#define T_IF 101 /* if keyword */ -#define T_ELSE 102 /* else keyword */ -#define T_WHILE 103 /* while keyword */ -#define T_CONTINUE 104 /* continue keyword */ -#define T_BREAK 105 /* break keyword */ -#define T_GOTO 106 /* goto keyword */ -#define T_RETURN 107 /* return keyword */ -#define T_LOCAL 108 /* local keyword */ -#define T_GLOBAL 109 /* global keyword */ -#define T_STATIC 110 /* static keyword */ -#define T_DO 111 /* do keyword */ -#define T_FOR 112 /* for keyword */ -#define T_SWITCH 113 /* switch keyword */ -#define T_CASE 114 /* case keyword */ -#define T_DEFAULT 115 /* default keyword */ -#define T_QUIT 116 /* quit keyword */ -#define T_DEFINE 117 /* define keyword */ -#define T_READ 118 /* read keyword */ -#define T_SHOW 119 /* show keyword */ -#define T_HELP 120 /* help keyword */ -#define T_WRITE 121 /* write keyword */ -#define T_MAT 122 /* mat keyword */ -#define T_OBJ 123 /* obj keyword */ -#define T_PRINT 124 /* print keyword */ -#define T_CD 125 /* change directory keyword */ -#define T_UNDEFINE 126 /* undefine keyword */ -#define T_ABORT 127 /* abort operation */ +#define T_IF 101 /* if keyword */ +#define T_ELSE 102 /* else keyword */ +#define T_WHILE 103 /* while keyword */ +#define T_CONTINUE 104 /* continue keyword */ +#define T_BREAK 105 /* break keyword */ +#define T_GOTO 106 /* goto keyword */ +#define T_RETURN 107 /* return keyword */ +#define T_LOCAL 108 /* local keyword */ +#define T_GLOBAL 109 /* global keyword */ +#define T_STATIC 110 /* static keyword */ +#define T_DO 111 /* do keyword */ +#define T_FOR 112 /* for keyword */ +#define T_SWITCH 113 /* switch keyword */ +#define T_CASE 114 /* case keyword */ +#define T_DEFAULT 115 /* default keyword */ +#define T_QUIT 116 /* quit keyword */ +#define T_DEFINE 117 /* define keyword */ +#define T_READ 118 /* read keyword */ +#define T_SHOW 119 /* show keyword */ +#define T_HELP 120 /* help keyword */ +#define T_WRITE 121 /* write keyword */ +#define T_MAT 122 /* mat keyword */ +#define T_OBJ 123 /* obj keyword */ +#define T_PRINT 124 /* print keyword */ +#define T_CD 125 /* change directory keyword */ +#define T_UNDEFINE 126 /* undefine keyword */ +#define T_ABORT 127 /* abort operation */ -#define iskeyword(n) ((n) > 100) /* true if token is a keyword */ +#define iskeyword(n) ((n) > 100) /* true if token is a keyword */ /* * Flags returned describing results of expression parsing. */ -#define EXPR_RVALUE 0x0001 /* result is an rvalue */ -#define EXPR_CONST 0x0002 /* result is constant */ -#define EXPR_ASSIGN 0x0004 /* result is an assignment */ +#define EXPR_RVALUE 0x0001 /* result is an rvalue */ +#define EXPR_CONST 0x0002 /* result is constant */ +#define EXPR_ASSIGN 0x0004 /* result is an assignment */ /* true if expression is rvalue */ -#define isrvalue(n) ((n) & EXPR_RVALUE) +#define isrvalue(n) ((n) & EXPR_RVALUE) /* true if expr is lvalue */ -#define islvalue(n) (((n) & EXPR_RVALUE) == 0) +#define islvalue(n) (((n) & EXPR_RVALUE) == 0) /* true if expr is constant */ -#define isconst(n) ((n) & EXPR_CONST) +#define isconst(n) ((n) & EXPR_CONST) /* true if expr is an assignment */ -#define isassign(n) ((n) & EXPR_ASSIGN) +#define isassign(n) ((n) & EXPR_ASSIGN) /* * Flags for modes for tokenizing. */ -#define TM_DEFAULT 0x0 /* normal mode */ -#define TM_NEWLINES 0x1 /* treat any newline as a token */ -#define TM_ALLSYMS 0x2 /* treat almost everything as a symbol */ +#define TM_DEFAULT 0x0 /* normal mode */ +#define TM_NEWLINES 0x1 /* treat any newline as a token */ +#define TM_ALLSYMS 0x2 /* treat almost everything as a symbol */ -EXTERN long errorcount; /* number of errors found */ +EXTERN long errorcount; /* number of errors found */ E_FUNC long tokenstring(void); E_FUNC long tokennumber(void); diff --git a/trailblank b/trailblank index e27fb8c..7d18d68 100755 --- a/trailblank +++ b/trailblank @@ -23,11 +23,11 @@ # received a copy with calc; if not, write to Free Software Foundation, Inc. # 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. # -# Under source code control: 2017/05/22 03:28:20 -# File existed as early as: 2017 +# Under source code control: 2017/05/22 03:28:20 +# File existed as early as: 2017 # -# chongo /\oo/\ http://www.isthe.com/chongo/ -# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +# chongo /\oo/\ http://www.isthe.com/chongo/ +# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ # exit code # @@ -42,7 +42,7 @@ export EXIT_CODE=0 # that end in .out, and files containing the any of the following # in any letter case: # -# foo bar baz curds whey rmme +# foo bar baz curds whey rmme # # Such files are temporary/test files and are not part of calc. # @@ -51,21 +51,21 @@ export EXIT_CODE=0 # LEADING_SPACES_BEFORE_TAB=$( find . \( -path './NOTES' -o -path './calc' -o -path './ver_calc' -o \ - -name '*.o' -o -name '*.a' -o -name '*ptch*' -o -name 'core*' -o \ - -name '*.orig' -o -name '*.rej' -o -name '*.bak' -o \ - -name '*.ptch' -o -name 'core.*' -o \ - -name '*.so*' -o -name 'calc-static' -o -name 'libcalc.*' -o \ - -name 'sample_many' -o -name 'sample_rand' -o -name 'errcode' -o \ - -path './help/funclist' -o -path './have_stdvs' -o \ - -path './endian' -o -path './no_implicit' -o -name 'chk_c' -o \ - -path './longbits' -o -name '.*.swp' -o -name 'conf.h' -o \ - -name '.git' -o -path './custom/libcustcalc*' -o -path './libcustcalc*' -o \ - -name 'sample_many-static' -o -name 'sample_rand-static' -o \ - -name 'codeql-analysis.yml' -o -name tags -o -name '*.out' -o \ - -name '?' -o -iname '*foo*' -o -iname '*bar*' -o -iname '*baz*' -o \ - -iname '*curds*' -o -iname '*whey*' -o -iname '*rmme*' \ - \) -prune -o -type f -print0 | \ - xargs -0 egrep -l '^ * * ' + -name '*.o' -o -name '*.a' -o -name '*ptch*' -o -name 'core*' -o \ + -name '*.orig' -o -name '*.rej' -o -name '*.bak' -o \ + -name '*.ptch' -o -name 'core.*' -o \ + -name '*.so*' -o -name 'calc-static' -o -name 'libcalc.*' -o \ + -name 'sample_many' -o -name 'sample_rand' -o -name 'errcode' -o \ + -path './help/funclist' -o -path './have_stdvs' -o \ + -path './endian' -o -path './no_implicit' -o -name 'chk_c' -o \ + -path './longbits' -o -name '.*.swp' -o -name 'conf.h' -o \ + -name '.git' -o -path './custom/libcustcalc*' -o -path './libcustcalc*' -o \ + -name 'sample_many-static' -o -name 'sample_rand-static' -o \ + -name 'codeql-analysis.yml' -o -name tags -o -name '*.out' -o \ + -name '?' -o -iname '*foo*' -o -iname '*bar*' -o -iname '*baz*' -o \ + -iname '*curds*' -o -iname '*whey*' -o -iname '*rmme*' \ + \) -prune -o -type f -print0 | \ + xargs -0 egrep -l '^ * * ' ) if [[ -n $LEADING_SPACES_BEFORE_TAB ]]; then echo @@ -83,7 +83,7 @@ fi # that end in .out, and files containing the any of the following # in any letter case: # -# foo bar baz curds whey rmme +# foo bar baz curds whey rmme # # Such files are temporary/test files and are not part of calc. # @@ -92,20 +92,20 @@ fi # TRAILING_WHITESPACE=$( find . \( -path './NOTES' -o -path './calc' -o -path './ver_calc' -o \ - -name '*.o' -o -name '*.a' -o -name '*ptch*' -o -name 'core*' -o \ - -name '*.orig' -o -name '*.rej' -o -name '*.bak' -o \ - -name '*.ptch' -o -name 'core.*' -o \ - -name '*.so*' -o -name 'calc-static' -o -name 'libcalc.*' -o \ - -name 'sample_many' -o -name 'sample_rand' -o -name 'errcode' -o \ - -path './help/funclist' -o -path './have_stdvs' -o \ - -path './endian' -o -path './no_implicit' -o -name 'chk_c' -o \ - -path './longbits' -o -name '.*.swp' -o -name 'conf.h' -o \ - -name '.git' -o -path './custom/libcustcalc*' -o -path './libcustcalc*' -o \ - -name 'sample_many-static' -o -name 'sample_rand-static' -o \ - -name '?' -o -iname '*foo*' -o -iname '*bar*' -o -iname '*baz*' -o \ - -iname '*curds*' -o -iname '*whey*' -o -iname '*rmme*' \ - \) -prune -o -type f -print0 | \ - xargs -0 egrep -l '[ ]$' + -name '*.o' -o -name '*.a' -o -name '*ptch*' -o -name 'core*' -o \ + -name '*.orig' -o -name '*.rej' -o -name '*.bak' -o \ + -name '*.ptch' -o -name 'core.*' -o \ + -name '*.so*' -o -name 'calc-static' -o -name 'libcalc.*' -o \ + -name 'sample_many' -o -name 'sample_rand' -o -name 'errcode' -o \ + -path './help/funclist' -o -path './have_stdvs' -o \ + -path './endian' -o -path './no_implicit' -o -name 'chk_c' -o \ + -path './longbits' -o -name '.*.swp' -o -name 'conf.h' -o \ + -name '.git' -o -path './custom/libcustcalc*' -o -path './libcustcalc*' -o \ + -name 'sample_many-static' -o -name 'sample_rand-static' -o \ + -name '?' -o -iname '*foo*' -o -iname '*bar*' -o -iname '*baz*' -o \ + -iname '*curds*' -o -iname '*whey*' -o -iname '*rmme*' \ + \) -prune -o -type f -print0 | \ + xargs -0 egrep -l '[ ]$' ) if [[ -n $TRAILING_WHITESPACE ]]; then echo @@ -120,33 +120,33 @@ fi # if [[ -x /usr/local/bin/picky ]]; then PICKY_PHASE_0A=$(/usr/local/bin/picky -w -s -v ./cal/set8700.line \ - .gitignore README.md .lldbinit 2>&1) + .gitignore README.md .lldbinit 2>&1) status="$?" if [[ $status -ne 0 ]]; then - echo - echo '# picky failed on one of the files with long lines' - echo "$PICKY_PHASE_0A" | sed -e 's/\.\///' - EXIT_CODE=3 + echo + echo '# picky failed on one of the files with long lines' + echo "$PICKY_PHASE_0A" | sed -e 's/\.\///' + EXIT_CODE=3 fi if [[ -e conf.h ]]; then - PICKY_PHASE_0B=$(/usr/local/bin/picky -w -s -v conf.h 2>&1) - status="$?" - if [[ $status -ne 0 ]]; then - echo - echo '# picky failed on conf.h' - echo "$PICKY_PHASE_0B" | sed -e 's/\.\///' - EXIT_CODE=4 - fi + PICKY_PHASE_0B=$(/usr/local/bin/picky -w -s -v conf.h 2>&1) + status="$?" + if [[ $status -ne 0 ]]; then + echo + echo '# picky failed on conf.h' + echo "$PICKY_PHASE_0B" | sed -e 's/\.\///' + EXIT_CODE=4 + fi fi if [[ -e errsym.h ]]; then - PICKY_PHASE_0C=$(/usr/local/bin/picky -w -s -v errsym.h 2>&1) - status="$?" - if [[ $status -ne 0 ]]; then - echo - echo '# picky failed on errsym.h' - echo "$PICKY_PHASE_0C" | sed -e 's/\.\///' - EXIT_CODE=5 - fi + PICKY_PHASE_0C=$(/usr/local/bin/picky -w -s -v errsym.h 2>&1) + status="$?" + if [[ $status -ne 0 ]]; then + echo + echo '# picky failed on errsym.h' + echo "$PICKY_PHASE_0C" | sed -e 's/\.\///' + EXIT_CODE=5 + fi fi else echo "# $0: WARNING: /usr/local/bin/picky not found: skipping picky phase 0 checks!" 1>&2 @@ -162,7 +162,7 @@ fi # that end in .out, and files containing the any of the following # in any letter case: # -# foo bar baz curds whey rmme +# foo bar baz curds whey rmme # # Such files are temporary/test files and are not part of calc. # @@ -171,29 +171,29 @@ fi # PICKY_PHASE_1=$( find . \( -path './NOTES' -o -path './calc' -o -path './ver_calc' -o \ - -name '*.o' -o -name '*.a' -o -name '*ptch*' -o -name 'core*' -o \ - -name '*.orig' -o -name '*.rej' -o -name '*.bak' -o \ - -name '*.ptch' -o -name 'core.*' -o \ - -name '*.so*' -o -name 'calc-static' -o -name 'libcalc.*' -o \ - -name 'sample_many' -o -name 'sample_rand' -o -name 'errcode' -o \ - -path './help/funclist' -o -path './have_stdvs' -o \ - -path './endian' -o -path './no_implicit' -o -name 'chk_c' -o \ - -path './longbits' -o -name '.*.swp' -o -name 'conf.h' -o \ - -name '.git' -o -path './custom/libcustcalc*' -o -path './libcustcalc*' -o \ - -name 'sample_many-static' -o -name 'sample_rand-static' -o \ - -name 'codeql-analysis.yml' -o -name tags -o -name '*.out' -o \ - -name '?' -o -iname '*foo*' -o -iname '*bar*' -o -iname '*baz*' -o \ - -iname '*curds*' -o -iname '*whey*' -o -iname '*rmme*' \ - \) -prune -o -type f -print0 | \ + -name '*.o' -o -name '*.a' -o -name '*ptch*' -o -name 'core*' -o \ + -name '*.orig' -o -name '*.rej' -o -name '*.bak' -o \ + -name '*.ptch' -o -name 'core.*' -o \ + -name '*.so*' -o -name 'calc-static' -o -name 'libcalc.*' -o \ + -name 'sample_many' -o -name 'sample_rand' -o -name 'errcode' -o \ + -path './help/funclist' -o -path './have_stdvs' -o \ + -path './endian' -o -path './no_implicit' -o -name 'chk_c' -o \ + -path './longbits' -o -name '.*.swp' -o -name 'conf.h' -o \ + -name '.git' -o -path './custom/libcustcalc*' -o -path './libcustcalc*' -o \ + -name 'sample_many-static' -o -name 'sample_rand-static' -o \ + -name 'codeql-analysis.yml' -o -name tags -o -name '*.out' -o \ + -name '?' -o -iname '*foo*' -o -iname '*bar*' -o -iname '*baz*' -o \ + -iname '*curds*' -o -iname '*whey*' -o -iname '*rmme*' \ + \) -prune -o -type f -print0 | \ if [[ -x /usr/local/bin/picky ]]; then - xargs -0 /usr/local/bin/picky -s -v -w132 + xargs -0 /usr/local/bin/picky -s -v -w132 else - echo "# $0: WARNING: /usr/local/bin/picky not found: skipping picky phase 1 check!" 1>&2 - echo "#" 1>&2 - echo "# $0: NOTICE: The picky tool used is from the following GitHub repo:" 1>&2 - echo "#" 1>&2 - echo "# https://github.com/lcn2/picky for the picky tool GitHub repo." 1>&2 - echo "#" 1>&2 + echo "# $0: WARNING: /usr/local/bin/picky not found: skipping picky phase 1 check!" 1>&2 + echo "#" 1>&2 + echo "# $0: NOTICE: The picky tool used is from the following GitHub repo:" 1>&2 + echo "#" 1>&2 + echo "# https://github.com/lcn2/picky for the picky tool GitHub repo." 1>&2 + echo "#" 1>&2 fi ) if [[ -n $PICKY_PHASE_1 ]]; then @@ -213,7 +213,7 @@ if [[ -n $BACKUP_MAKEILES ]]; then echo "# You need execute the following to remove backup Makefiles:" echo echo "$BACKUP_MAKEILES" | while read -r file; do - echo "rm -f $file" + echo "rm -f $file" done EXIT_CODE=7 fi diff --git a/update_ver b/update_ver index 47807bf..1dcaa2c 100755 --- a/update_ver +++ b/update_ver @@ -22,11 +22,11 @@ # received a copy with calc; if not, write to Free Software Foundation, Inc. # 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. # -# Under source code control: 2021/12/12 15:32:43 -# File existed as early as: 2021 +# Under source code control: 2021/12/12 15:32:43 +# File existed as early as: 2021 # -# chongo /\oo/\ http://www.isthe.com/chongo/ -# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ +# chongo /\oo/\ http://www.isthe.com/chongo/ +# Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ # setup # @@ -41,22 +41,22 @@ MK_SET1="Makefile.config" check_primary() { echo "check for primary Makefiles: $MK_SET1" for i in $MK_SET1; do - if [[ ! -f $i ]]; then - echo "$0: FATAL: Missing critical: $i" 1>&2 - fi - if [[ ! -s $i ]]; then - echo "$0: FATAL: empty: $i" 1>&2 - fi + if [[ ! -f $i ]]; then + echo "$0: FATAL: Missing critical: $i" 1>&2 + fi + if [[ ! -s $i ]]; then + echo "$0: FATAL: empty: $i" 1>&2 + fi done for i in $MK_SET1; do - if [[ ! -f $i ]]; then - echo "$0: FATAL: exit 1" - exit 1 - fi - if [[ ! -s $i ]]; then - echo "$0: FATAL: exit 2" - exit 2 - fi + if [[ ! -f $i ]]; then + echo "$0: FATAL: exit 1" + exit 1 + fi + if [[ ! -s $i ]]; then + echo "$0: FATAL: exit 2" + exit 2 + fi done } @@ -64,17 +64,17 @@ check_primary() { # no_bak() { for i in $MK_SET1; do - if [[ -f $i.bak ]]; then - echo "$0: FATAL: bak copy found: $i.bak" 1>&2 - echo "$0: FATAL: try: diff -u $i.bak $i" 1>&2 - echo "$0: FATAL: consider: rm -f $i.bak" 1>&2 - fi + if [[ -f $i.bak ]]; then + echo "$0: FATAL: bak copy found: $i.bak" 1>&2 + echo "$0: FATAL: try: diff -u $i.bak $i" 1>&2 + echo "$0: FATAL: consider: rm -f $i.bak" 1>&2 + fi done for i in $MK_SET1; do - if [[ -f $i.bak ]]; then - echo "$0: FATAL: exit 5" - exit 5 - fi + if [[ -f $i.bak ]]; then + echo "$0: FATAL: exit 5" + exit 5 + fi done } @@ -127,8 +127,8 @@ echo "about to modify: $MK_SET1" echo "changing version line to use VERSION= $CALC_VERSION" echo "changing major version line to use VER= $CALC_VER" perl -p -i -e \ - 's/^VERSION= .*/VERSION= '"$CALC_VERSION"'/; s/^VER= .*/VER= '"$CALC_VER"'/' \ - $MK_SET1 + 's/^VERSION= .*/VERSION= '"$CALC_VERSION"'/; s/^VER= .*/VER= '"$CALC_VER"'/' \ + $MK_SET1 status="$?" if [[ $status -ne 0 ]]; then echo "$0: FATAL: perl version change for non-zero exit code: $status" 1>&2 @@ -144,10 +144,10 @@ export VERSION_ERR= for i in $MK_SET1; do VERSION_STRING=$(egrep '^VERSION= [1-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' "$i") if [[ -z $VERSION_STRING ]]; then - echo "$0: FATAL: cannot find VERSION= in $i" - VERSION_ERR="$i" + echo "$0: FATAL: cannot find VERSION= in $i" + VERSION_ERR="$i" else - echo "$i: $VERSION_STRING" + echo "$i: $VERSION_STRING" fi done if [[ -n $VERSION_ERR ]]; then @@ -163,10 +163,10 @@ export VER_ERR= for i in $MK_SET1; do VER_STRING=$(egrep '^VER= [1-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' "$i") if [[ -z $VER_STRING ]]; then - echo "$0: FATAL: cannot find VER= in $i" - VER_ERR="$i" + echo "$0: FATAL: cannot find VER= in $i" + VER_ERR="$i" else - echo "$i: $VER_STRING" + echo "$i: $VER_STRING" fi done echo diff --git a/value.c b/value.c index 646f489..8d88f8a 100644 --- a/value.c +++ b/value.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:25 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:25 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -40,78 +40,78 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define LINELEN 80 /* length of a typical tty line */ +#define LINELEN 80 /* length of a typical tty line */ /* * Free a value and set its type to undefined. * * given: - * vp value to be freed + * vp value to be freed */ void freevalue(VALUE *vp) { - int type; /* type of value being freed */ + int type; /* type of value being freed */ - type = vp->v_type; - vp->v_type = V_NULL; - vp->v_subtype = V_NOSUBTYPE; - if (type <= 0) - return; - switch (type) { - case V_ADDR: - case V_OCTET: - case V_NBLOCK: - case V_FILE: - case V_VPTR: - case V_OPTR: - case V_SPTR: - case V_NPTR: - /* nothing to free */ - break; - case V_STR: - sfree(vp->v_str); - break; - case V_NUM: - qfree(vp->v_num); - break; - case V_COM: - comfree(vp->v_com); - break; - case V_MAT: - matfree(vp->v_mat); - break; - case V_LIST: - listfree(vp->v_list); - break; - case V_ASSOC: - assocfree(vp->v_assoc); - break; - case V_OBJ: - objfree(vp->v_obj); - break; - case V_RAND: - randfree(vp->v_rand); - break; - case V_RANDOM: - randomfree(vp->v_random); - break; - case V_CONFIG: - config_free(vp->v_config); - break; - case V_HASH: - hash_free(vp->v_hash); - break; - case V_BLOCK: - blk_free(vp->v_block); - break; - default: - math_error("Freeing unknown value type"); - not_reached(); - } + type = vp->v_type; + vp->v_type = V_NULL; + vp->v_subtype = V_NOSUBTYPE; + if (type <= 0) + return; + switch (type) { + case V_ADDR: + case V_OCTET: + case V_NBLOCK: + case V_FILE: + case V_VPTR: + case V_OPTR: + case V_SPTR: + case V_NPTR: + /* nothing to free */ + break; + case V_STR: + sfree(vp->v_str); + break; + case V_NUM: + qfree(vp->v_num); + break; + case V_COM: + comfree(vp->v_com); + break; + case V_MAT: + matfree(vp->v_mat); + break; + case V_LIST: + listfree(vp->v_list); + break; + case V_ASSOC: + assocfree(vp->v_assoc); + break; + case V_OBJ: + objfree(vp->v_obj); + break; + case V_RAND: + randfree(vp->v_rand); + break; + case V_RANDOM: + randomfree(vp->v_random); + break; + case V_CONFIG: + config_free(vp->v_config); + break; + case V_HASH: + hash_free(vp->v_hash); + break; + case V_BLOCK: + blk_free(vp->v_block); + break; + default: + math_error("Freeing unknown value type"); + not_reached(); + } } @@ -121,51 +121,51 @@ freevalue(VALUE *vp) void protecttodepth(VALUE *vp, int sts, int depth) { - VALUE *vq; - int i; - LISTELEM *ep; - ASSOC *ap; + VALUE *vq; + int i; + LISTELEM *ep; + ASSOC *ap; - if (vp->v_type == V_NBLOCK) { - if (sts > 0) - vp->v_nblock->subtype |= sts; - else if (sts < 0) - vp->v_nblock->subtype &= ~(-sts); - else vp->v_nblock->subtype = 0; - return; - } - if (sts > 0) - vp->v_subtype |= sts; - else if (sts < 0) - vp->v_subtype &= ~(-sts); - else - vp->v_subtype = 0; + if (vp->v_type == V_NBLOCK) { + if (sts > 0) + vp->v_nblock->subtype |= sts; + else if (sts < 0) + vp->v_nblock->subtype &= ~(-sts); + else vp->v_nblock->subtype = 0; + return; + } + if (sts > 0) + vp->v_subtype |= sts; + else if (sts < 0) + vp->v_subtype &= ~(-sts); + else + vp->v_subtype = 0; - if (depth > 0) { - switch(vp->v_type) { - case V_MAT: - vq = vp->v_mat->m_table; - i = vp->v_mat->m_size; - while (i-- > 0) - protecttodepth(vq++, sts, depth - 1); - break; - case V_LIST: - for (ep = vp->v_list->l_first; ep; ep = ep->e_next) - protecttodepth(&ep->e_value, sts, depth - 1); - break; - case V_OBJ: - vq = vp->v_obj->o_table; - i = vp->v_obj->o_actions->oa_count; - while (i-- > 0) - protecttodepth(vq++, sts, depth - 1); - break; - case V_ASSOC: - ap = vp->v_assoc; - for (i = 0; i < ap->a_count; i++) - protecttodepth(assocfindex(ap, i), sts, depth - 1); - } - } + if (depth > 0) { + switch(vp->v_type) { + case V_MAT: + vq = vp->v_mat->m_table; + i = vp->v_mat->m_size; + while (i-- > 0) + protecttodepth(vq++, sts, depth - 1); + break; + case V_LIST: + for (ep = vp->v_list->l_first; ep; ep = ep->e_next) + protecttodepth(&ep->e_value, sts, depth - 1); + break; + case V_OBJ: + vq = vp->v_obj->o_table; + i = vp->v_obj->o_actions->oa_count; + while (i-- > 0) + protecttodepth(vq++, sts, depth - 1); + break; + case V_ASSOC: + ap = vp->v_assoc; + for (i = 0; i < ap->a_count; i++) + protecttodepth(assocfindex(ap, i), sts, depth - 1); + } + } } @@ -174,79 +174,79 @@ protecttodepth(VALUE *vp, int sts, int depth) * This overwrites the specified new value without checking it. * * given: - * oldvp value to be copied from - * newvp value to be copied into + * oldvp value to be copied from + * newvp value to be copied into */ void copyvalue(VALUE *oldvp, VALUE *newvp) { - /* firewall */ - if (oldvp == NULL) - return; + /* firewall */ + if (oldvp == NULL) + return; - newvp->v_type = oldvp->v_type; - if (oldvp->v_type >= 0) { - switch (oldvp->v_type) { - case V_NULL: - case V_ADDR: - case V_VPTR: - case V_OPTR: - case V_SPTR: - case V_NPTR: - *newvp = *oldvp; - break; - case V_FILE: - newvp->v_file = oldvp->v_file; - break; - case V_NUM: - newvp->v_num = qlink(oldvp->v_num); - break; - case V_COM: - newvp->v_com = clink(oldvp->v_com); - break; - case V_STR: - newvp->v_str = slink(oldvp->v_str); - break; - case V_MAT: - newvp->v_mat = matcopy(oldvp->v_mat); - break; - case V_LIST: - newvp->v_list = listcopy(oldvp->v_list); - break; - case V_ASSOC: - newvp->v_assoc = assoccopy(oldvp->v_assoc); - break; - case V_OBJ: - newvp->v_obj = objcopy(oldvp->v_obj); - break; - case V_RAND: - newvp->v_rand = randcopy(oldvp->v_rand); - break; - case V_RANDOM: - newvp->v_random = randomcopy(oldvp->v_random); - break; - case V_CONFIG: - newvp->v_config = config_copy(oldvp->v_config); - break; - case V_HASH: - newvp->v_hash = hash_copy(oldvp->v_hash); - break; - case V_BLOCK: - newvp->v_block = blk_copy(oldvp->v_block); - break; - case V_OCTET: - newvp->v_type = V_NUM; - newvp->v_num = itoq((long) *oldvp->v_octet); - break; - case V_NBLOCK: - newvp->v_nblock = oldvp->v_nblock; - break; - default: - math_error("Copying unknown value type"); - not_reached(); - } - } - newvp->v_subtype = oldvp->v_subtype; + newvp->v_type = oldvp->v_type; + if (oldvp->v_type >= 0) { + switch (oldvp->v_type) { + case V_NULL: + case V_ADDR: + case V_VPTR: + case V_OPTR: + case V_SPTR: + case V_NPTR: + *newvp = *oldvp; + break; + case V_FILE: + newvp->v_file = oldvp->v_file; + break; + case V_NUM: + newvp->v_num = qlink(oldvp->v_num); + break; + case V_COM: + newvp->v_com = clink(oldvp->v_com); + break; + case V_STR: + newvp->v_str = slink(oldvp->v_str); + break; + case V_MAT: + newvp->v_mat = matcopy(oldvp->v_mat); + break; + case V_LIST: + newvp->v_list = listcopy(oldvp->v_list); + break; + case V_ASSOC: + newvp->v_assoc = assoccopy(oldvp->v_assoc); + break; + case V_OBJ: + newvp->v_obj = objcopy(oldvp->v_obj); + break; + case V_RAND: + newvp->v_rand = randcopy(oldvp->v_rand); + break; + case V_RANDOM: + newvp->v_random = randomcopy(oldvp->v_random); + break; + case V_CONFIG: + newvp->v_config = config_copy(oldvp->v_config); + break; + case V_HASH: + newvp->v_hash = hash_copy(oldvp->v_hash); + break; + case V_BLOCK: + newvp->v_block = blk_copy(oldvp->v_block); + break; + case V_OCTET: + newvp->v_type = V_NUM; + newvp->v_num = itoq((long) *oldvp->v_octet); + break; + case V_NBLOCK: + newvp->v_nblock = oldvp->v_nblock; + break; + default: + math_error("Copying unknown value type"); + not_reached(); + } + } + newvp->v_subtype = oldvp->v_subtype; } @@ -256,75 +256,75 @@ copyvalue(VALUE *oldvp, VALUE *newvp) void copy2octet(VALUE *vp, OCTET *op) { - USB8 oval; /* low order 8 bits to store into OCTET */ - NUMBER *q; - HALF h; + USB8 oval; /* low order 8 bits to store into OCTET */ + NUMBER *q; + HALF h; - if (vp->v_type == V_ADDR) - vp = vp->v_addr; + if (vp->v_type == V_ADDR) + vp = vp->v_addr; - oval = 0; + oval = 0; - /* - * we can (at the moment) only store certain types - * values into an OCTET, so get the low order 8 bits - * of these particular value types - */ - h = 0; - switch(vp->v_type) { - case V_NULL: - /* nothing to store ... so do nothing */ - return; - case V_INT: - oval = (USB8)(vp->v_int & 0xff); - break; - case V_NUM: - if (qisint(vp->v_num)) { - /* use low order 8 bits of integer value */ - h = vp->v_num->num.v[0]; - } else { - /* use low order 8 bits of int(value) */ - q = qint(vp->v_num); - h = q->num.v[0]; - qfree(q); - } - if (qisneg(vp->v_num)) - h = -h; - oval = (USB8) h; - break; - case V_COM: - if (cisint(vp->v_com)) { - /* use low order 8 bits of integer value */ - h = vp->v_com->real->num.v[0]; - } else { - /* use low order 8 bits of int(value) */ - q = qint(vp->v_com->real); - h = q->num.v[0]; - qfree(q); - } - if (qisneg(vp->v_com->real)) - h = -h; - oval = (USB8) h; - break; - case V_STR: - oval = (USB8) vp->v_str->s_str[0]; - break; - case V_BLOCK: - oval = (USB8) vp->v_block->data[0]; - break; - case V_OCTET: - oval = *vp->v_octet; - break; - case V_NBLOCK: - if (vp->v_nblock->blk->data == NULL) - return; - oval = (USB8) vp->v_nblock->blk->data[0]; - break; - default: - math_error("invalid assignment into an OCTET"); - break; - } - *op = oval; + /* + * we can (at the moment) only store certain types + * values into an OCTET, so get the low order 8 bits + * of these particular value types + */ + h = 0; + switch(vp->v_type) { + case V_NULL: + /* nothing to store ... so do nothing */ + return; + case V_INT: + oval = (USB8)(vp->v_int & 0xff); + break; + case V_NUM: + if (qisint(vp->v_num)) { + /* use low order 8 bits of integer value */ + h = vp->v_num->num.v[0]; + } else { + /* use low order 8 bits of int(value) */ + q = qint(vp->v_num); + h = q->num.v[0]; + qfree(q); + } + if (qisneg(vp->v_num)) + h = -h; + oval = (USB8) h; + break; + case V_COM: + if (cisint(vp->v_com)) { + /* use low order 8 bits of integer value */ + h = vp->v_com->real->num.v[0]; + } else { + /* use low order 8 bits of int(value) */ + q = qint(vp->v_com->real); + h = q->num.v[0]; + qfree(q); + } + if (qisneg(vp->v_com->real)) + h = -h; + oval = (USB8) h; + break; + case V_STR: + oval = (USB8) vp->v_str->s_str[0]; + break; + case V_BLOCK: + oval = (USB8) vp->v_block->data[0]; + break; + case V_OCTET: + oval = *vp->v_octet; + break; + case V_NBLOCK: + if (vp->v_nblock->blk->data == NULL) + return; + oval = (USB8) vp->v_nblock->blk->data[0]; + break; + default: + math_error("invalid assignment into an OCTET"); + break; + } + *op = oval; } @@ -335,38 +335,38 @@ copy2octet(VALUE *vp, OCTET *op) void negvalue(VALUE *vp, VALUE *vres) { - vres->v_type = vp->v_type; - vres->v_subtype = V_NOSUBTYPE; - switch (vp->v_type) { - case V_NUM: - vres->v_num = qneg(vp->v_num); - return; - case V_COM: - vres->v_com = c_neg(vp->v_com); - return; - case V_MAT: - vres->v_mat = matneg(vp->v_mat); - return; - case V_STR: - vres->v_str = stringneg(vp->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRNEG); - return; - case V_OCTET: - vres->v_type = V_NUM; - vres->v_subtype = V_NOSUBTYPE; - vres->v_num = itoq(- (long) *vp->v_octet); - return; + vres->v_type = vp->v_type; + vres->v_subtype = V_NOSUBTYPE; + switch (vp->v_type) { + case V_NUM: + vres->v_num = qneg(vp->v_num); + return; + case V_COM: + vres->v_com = c_neg(vp->v_com); + return; + case V_MAT: + vres->v_mat = matneg(vp->v_mat); + return; + case V_STR: + vres->v_str = stringneg(vp->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRNEG); + return; + case V_OCTET: + vres->v_type = V_NUM; + vres->v_subtype = V_NOSUBTYPE; + vres->v_num = itoq(- (long) *vp->v_octet); + return; - case V_OBJ: - *vres = objcall(OBJ_NEG, vp, NULL_VALUE, NULL_VALUE); - return; - default: - if (vp->v_type <= 0) - return; - *vres = error_value(E_NEG); - return; - } + case V_OBJ: + *vres = objcall(OBJ_NEG, vp, NULL_VALUE, NULL_VALUE); + return; + default: + if (vp->v_type <= 0) + return; + *vres = error_value(E_NEG); + return; + } } @@ -377,95 +377,95 @@ negvalue(VALUE *vp, VALUE *vres) void addvalue(VALUE *v1, VALUE *v2, VALUE *vres) { - unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ - COMPLEX *c; - VALUE tmp; - NUMBER *q; - long i; + unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ + COMPLEX *c; + VALUE tmp; + NUMBER *q; + long i; - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type == V_LIST) { - tmp.v_type = V_NULL; - addlistitems(v1->v_list, &tmp); - addvalue(&tmp, v2, vres); - return; - } - if (v2->v_type == V_LIST) { - copyvalue(v1, vres); - addlistitems(v2->v_list, vres); - return; - } - if (v1->v_type == V_NULL) { - copyvalue(v2, vres); - return; - } - if (v2->v_type == V_NULL) { - copyvalue(v1, vres); - return; - } - vres->v_type = v1->v_type; - twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); - switch (twoval_as_uint) { - case TWOVAL(V_NUM, V_NUM): - vres->v_num = qqadd(v1->v_num, v2->v_num); - return; - case TWOVAL(V_COM, V_NUM): - vres->v_com = c_addq(v1->v_com, v2->v_num); - return; - case TWOVAL(V_NUM, V_COM): - vres->v_com = c_addq(v2->v_com, v1->v_num); - vres->v_type = V_COM; - return; - case TWOVAL(V_COM, V_COM): - vres->v_com = c_add(v1->v_com, v2->v_com); - c = vres->v_com; - if (!cisreal(c)) - return; - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - return; - case TWOVAL(V_MAT, V_MAT): - vres->v_mat = matadd(v1->v_mat, v2->v_mat); - return; - case TWOVAL(V_STR, V_STR): - vres->v_str = stringadd(v1->v_str, v2->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRADD); - return; - case TWOVAL(V_VPTR, V_NUM): - q = v2->v_num; - if (qisfrac(q)) { - math_error("Adding non-integer to address"); - not_reached(); - } - i = qtoi(q); - vres->v_addr = v1->v_addr + i; - vres->v_type = V_VPTR; - return; - case TWOVAL(V_OPTR, V_NUM): - q = v2->v_num; - if (qisfrac(q)) { - math_error("Adding non-integer to address"); - not_reached(); - } - i = qtoi(q); - vres->v_octet = v1->v_octet + i; - vres->v_type = V_OPTR; - return; - default: - if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { - if (v1->v_type < 0) - return; - if (v2->v_type > 0) - *vres = error_value(E_ADD); - else - vres->v_type = v2->v_type; - return; - } - *vres = objcall(OBJ_ADD, v1, v2, NULL_VALUE); - return; - } + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type == V_LIST) { + tmp.v_type = V_NULL; + addlistitems(v1->v_list, &tmp); + addvalue(&tmp, v2, vres); + return; + } + if (v2->v_type == V_LIST) { + copyvalue(v1, vres); + addlistitems(v2->v_list, vres); + return; + } + if (v1->v_type == V_NULL) { + copyvalue(v2, vres); + return; + } + if (v2->v_type == V_NULL) { + copyvalue(v1, vres); + return; + } + vres->v_type = v1->v_type; + twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); + switch (twoval_as_uint) { + case TWOVAL(V_NUM, V_NUM): + vres->v_num = qqadd(v1->v_num, v2->v_num); + return; + case TWOVAL(V_COM, V_NUM): + vres->v_com = c_addq(v1->v_com, v2->v_num); + return; + case TWOVAL(V_NUM, V_COM): + vres->v_com = c_addq(v2->v_com, v1->v_num); + vres->v_type = V_COM; + return; + case TWOVAL(V_COM, V_COM): + vres->v_com = c_add(v1->v_com, v2->v_com); + c = vres->v_com; + if (!cisreal(c)) + return; + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + return; + case TWOVAL(V_MAT, V_MAT): + vres->v_mat = matadd(v1->v_mat, v2->v_mat); + return; + case TWOVAL(V_STR, V_STR): + vres->v_str = stringadd(v1->v_str, v2->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRADD); + return; + case TWOVAL(V_VPTR, V_NUM): + q = v2->v_num; + if (qisfrac(q)) { + math_error("Adding non-integer to address"); + not_reached(); + } + i = qtoi(q); + vres->v_addr = v1->v_addr + i; + vres->v_type = V_VPTR; + return; + case TWOVAL(V_OPTR, V_NUM): + q = v2->v_num; + if (qisfrac(q)) { + math_error("Adding non-integer to address"); + not_reached(); + } + i = qtoi(q); + vres->v_octet = v1->v_octet + i; + vres->v_type = V_OPTR; + return; + default: + if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { + if (v1->v_type < 0) + return; + if (v2->v_type > 0) + *vres = error_value(E_ADD); + else + vres->v_type = v2->v_type; + return; + } + *vres = objcall(OBJ_ADD, v1, v2, NULL_VALUE); + return; + } } @@ -476,86 +476,86 @@ addvalue(VALUE *v1, VALUE *v2, VALUE *vres) void subvalue(VALUE *v1, VALUE *v2, VALUE *vres) { - unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ - COMPLEX *c; - NUMBER *q; - int i; + unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ + COMPLEX *c; + NUMBER *q; + int i; - vres->v_type = v1->v_type; - vres->v_subtype = V_NOSUBTYPE; - twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); - switch (twoval_as_uint) { - case TWOVAL(V_NUM, V_NUM): - vres->v_num = qsub(v1->v_num, v2->v_num); - return; - case TWOVAL(V_COM, V_NUM): - vres->v_com = c_subq(v1->v_com, v2->v_num); - return; - case TWOVAL(V_NUM, V_COM): - c = c_subq(v2->v_com, v1->v_num); - vres->v_type = V_COM; - vres->v_com = c_neg(c); - comfree(c); - return; - case TWOVAL(V_COM, V_COM): - vres->v_com = c_sub(v1->v_com, v2->v_com); - c = vres->v_com; - if (!cisreal(c)) - return; - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - return; - case TWOVAL(V_MAT, V_MAT): - vres->v_mat = matsub(v1->v_mat, v2->v_mat); - return; - case TWOVAL(V_STR, V_STR): - vres->v_str = stringsub(v1->v_str, v2->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRSUB); - return; - case TWOVAL(V_VPTR, V_NUM): - q = v2->v_num; - if (qisfrac(q)) { - math_error("Subtracting non-integer from address"); - not_reached(); - } - i = qtoi(q); - vres->v_addr = v1->v_addr - i; - vres->v_type = V_VPTR; - return; - case TWOVAL(V_OPTR, V_NUM): - q = v2->v_num; - if (qisfrac(q)) { - math_error("Adding non-integer to address"); - not_reached(); - } - i = qtoi(q); - vres->v_octet = v1->v_octet - i; - vres->v_type = V_OPTR; - return; - case TWOVAL(V_VPTR, V_VPTR): - vres->v_type = V_NUM; - vres->v_num = itoq(v1->v_addr - v2->v_addr); - return; - case TWOVAL(V_OPTR, V_OPTR): - vres->v_type = V_NUM; - vres->v_num = itoq(v1->v_octet - v2->v_octet); - return; - default: - if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { - if (v1->v_type <= 0) - return; - if (v2->v_type <= 0) { - vres->v_type = v2->v_type; - return; - } - *vres = error_value(E_SUB); - return; - } - *vres = objcall(OBJ_SUB, v1, v2, NULL_VALUE); - return; - } + vres->v_type = v1->v_type; + vres->v_subtype = V_NOSUBTYPE; + twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); + switch (twoval_as_uint) { + case TWOVAL(V_NUM, V_NUM): + vres->v_num = qsub(v1->v_num, v2->v_num); + return; + case TWOVAL(V_COM, V_NUM): + vres->v_com = c_subq(v1->v_com, v2->v_num); + return; + case TWOVAL(V_NUM, V_COM): + c = c_subq(v2->v_com, v1->v_num); + vres->v_type = V_COM; + vres->v_com = c_neg(c); + comfree(c); + return; + case TWOVAL(V_COM, V_COM): + vres->v_com = c_sub(v1->v_com, v2->v_com); + c = vres->v_com; + if (!cisreal(c)) + return; + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + return; + case TWOVAL(V_MAT, V_MAT): + vres->v_mat = matsub(v1->v_mat, v2->v_mat); + return; + case TWOVAL(V_STR, V_STR): + vres->v_str = stringsub(v1->v_str, v2->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRSUB); + return; + case TWOVAL(V_VPTR, V_NUM): + q = v2->v_num; + if (qisfrac(q)) { + math_error("Subtracting non-integer from address"); + not_reached(); + } + i = qtoi(q); + vres->v_addr = v1->v_addr - i; + vres->v_type = V_VPTR; + return; + case TWOVAL(V_OPTR, V_NUM): + q = v2->v_num; + if (qisfrac(q)) { + math_error("Adding non-integer to address"); + not_reached(); + } + i = qtoi(q); + vres->v_octet = v1->v_octet - i; + vres->v_type = V_OPTR; + return; + case TWOVAL(V_VPTR, V_VPTR): + vres->v_type = V_NUM; + vres->v_num = itoq(v1->v_addr - v2->v_addr); + return; + case TWOVAL(V_OPTR, V_OPTR): + vres->v_type = V_NUM; + vres->v_num = itoq(v1->v_octet - v2->v_octet); + return; + default: + if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { + if (v1->v_type <= 0) + return; + if (v2->v_type <= 0) { + vres->v_type = v2->v_type; + return; + } + *vres = error_value(E_SUB); + return; + } + *vres = objcall(OBJ_SUB, v1, v2, NULL_VALUE); + return; + } } @@ -566,69 +566,69 @@ subvalue(VALUE *v1, VALUE *v2, VALUE *vres) void mulvalue(VALUE *v1, VALUE *v2, VALUE *vres) { - unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ - COMPLEX *c; + unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ + COMPLEX *c; - vres->v_type = v1->v_type; - vres->v_subtype = V_NOSUBTYPE; - twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); - switch (twoval_as_uint) { - case TWOVAL(V_NUM, V_NUM): - vres->v_num = qmul(v1->v_num, v2->v_num); - return; - case TWOVAL(V_COM, V_NUM): - vres->v_com = c_mulq(v1->v_com, v2->v_num); - break; - case TWOVAL(V_NUM, V_COM): - vres->v_com = c_mulq(v2->v_com, v1->v_num); - vres->v_type = V_COM; - break; - case TWOVAL(V_COM, V_COM): - vres->v_com = c_mul(v1->v_com, v2->v_com); - break; - case TWOVAL(V_MAT, V_MAT): - vres->v_mat = matmul(v1->v_mat, v2->v_mat); - return; - case TWOVAL(V_MAT, V_NUM): - case TWOVAL(V_MAT, V_COM): - vres->v_mat = matmulval(v1->v_mat, v2); - return; - case TWOVAL(V_NUM, V_MAT): - case TWOVAL(V_COM, V_MAT): - vres->v_mat = matmulval(v2->v_mat, v1); - vres->v_type = V_MAT; - return; - case TWOVAL(V_NUM, V_STR): - vres->v_type = V_STR; - vres->v_str = stringmul(v1->v_num, v2->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRMUL); - return; - case TWOVAL(V_STR, V_NUM): - vres->v_str= stringmul(v2->v_num, v1->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRMUL); - return; - default: - if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { - if (v1->v_type <= 0) - return; - if (v2->v_type <= 0) { - vres->v_type = v2->v_type; - return; - } - *vres = error_value(E_MUL); - return; - } - *vres = objcall(OBJ_MUL, v1, v2, NULL_VALUE); - return; - } - c = vres->v_com; - if (cisreal(c)) { - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - } + vres->v_type = v1->v_type; + vres->v_subtype = V_NOSUBTYPE; + twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); + switch (twoval_as_uint) { + case TWOVAL(V_NUM, V_NUM): + vres->v_num = qmul(v1->v_num, v2->v_num); + return; + case TWOVAL(V_COM, V_NUM): + vres->v_com = c_mulq(v1->v_com, v2->v_num); + break; + case TWOVAL(V_NUM, V_COM): + vres->v_com = c_mulq(v2->v_com, v1->v_num); + vres->v_type = V_COM; + break; + case TWOVAL(V_COM, V_COM): + vres->v_com = c_mul(v1->v_com, v2->v_com); + break; + case TWOVAL(V_MAT, V_MAT): + vres->v_mat = matmul(v1->v_mat, v2->v_mat); + return; + case TWOVAL(V_MAT, V_NUM): + case TWOVAL(V_MAT, V_COM): + vres->v_mat = matmulval(v1->v_mat, v2); + return; + case TWOVAL(V_NUM, V_MAT): + case TWOVAL(V_COM, V_MAT): + vres->v_mat = matmulval(v2->v_mat, v1); + vres->v_type = V_MAT; + return; + case TWOVAL(V_NUM, V_STR): + vres->v_type = V_STR; + vres->v_str = stringmul(v1->v_num, v2->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRMUL); + return; + case TWOVAL(V_STR, V_NUM): + vres->v_str= stringmul(v2->v_num, v1->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRMUL); + return; + default: + if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { + if (v1->v_type <= 0) + return; + if (v2->v_type <= 0) { + vres->v_type = v2->v_type; + return; + } + *vres = error_value(E_MUL); + return; + } + *vres = objcall(OBJ_MUL, v1, v2, NULL_VALUE); + return; + } + c = vres->v_com; + if (cisreal(c)) { + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + } } @@ -639,37 +639,37 @@ mulvalue(VALUE *v1, VALUE *v2, VALUE *vres) void squarevalue(VALUE *vp, VALUE *vres) { - COMPLEX *c; + COMPLEX *c; - vres->v_type = vp->v_type; - vres->v_subtype = V_NOSUBTYPE; - switch (vp->v_type) { - case V_NUM: - vres->v_num = qsquare(vp->v_num); - return; - case V_COM: - vres->v_com = c_square(vp->v_com); - c = vres->v_com; - if (!cisreal(c)) - return; - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - return; - case V_MAT: - vres->v_mat = matsquare(vp->v_mat); - return; - case V_OBJ: - *vres = objcall(OBJ_SQUARE, vp, NULL_VALUE, NULL_VALUE); - return; - default: - if (vp->v_type <= 0) { - vres->v_type = vp->v_type; - return; - } - *vres = error_value(E_SQUARE); - return; - } + vres->v_type = vp->v_type; + vres->v_subtype = V_NOSUBTYPE; + switch (vp->v_type) { + case V_NUM: + vres->v_num = qsquare(vp->v_num); + return; + case V_COM: + vres->v_com = c_square(vp->v_com); + c = vres->v_com; + if (!cisreal(c)) + return; + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + return; + case V_MAT: + vres->v_mat = matsquare(vp->v_mat); + return; + case V_OBJ: + *vres = objcall(OBJ_SQUARE, vp, NULL_VALUE, NULL_VALUE); + return; + default: + if (vp->v_type <= 0) { + vres->v_type = vp->v_type; + return; + } + *vres = error_value(E_SQUARE); + return; + } } @@ -680,48 +680,48 @@ squarevalue(VALUE *vp, VALUE *vres) void invertvalue(VALUE *vp, VALUE *vres) { - NUMBER *q1, *q2; + NUMBER *q1, *q2; - vres->v_type = vp->v_type; - vres->v_subtype = V_NOSUBTYPE; - switch (vp->v_type) { - case V_NUM: - if (qiszero(vp->v_num)) - *vres = error_value(E_DIVBYZERO); - else - vres->v_num = qinv(vp->v_num); - return; - case V_COM: - vres->v_com = c_inv(vp->v_com); - return; - case V_MAT: - vres->v_mat = matinv(vp->v_mat); - return; - case V_OCTET: - if (*vp->v_octet == 0) { - *vres = error_value(E_DIVBYZERO); - return; - } - q1 = itoq((long) *vp->v_octet); - q2 = qinv(q1); - qfree(q1); - vres->v_num = q2; - vres->v_type = V_NUM; - return; - case V_OBJ: - *vres = objcall(OBJ_INV, vp, NULL_VALUE, NULL_VALUE); - return; - default: - if (vp->v_type == -E_DIVBYZERO) { - vres->v_type = V_NUM; - vres->v_num = qlink(&_qzero_); - return; - } - if (vp->v_type <= 0) - return; - *vres = error_value(E_INV); - return; - } + vres->v_type = vp->v_type; + vres->v_subtype = V_NOSUBTYPE; + switch (vp->v_type) { + case V_NUM: + if (qiszero(vp->v_num)) + *vres = error_value(E_DIVBYZERO); + else + vres->v_num = qinv(vp->v_num); + return; + case V_COM: + vres->v_com = c_inv(vp->v_com); + return; + case V_MAT: + vres->v_mat = matinv(vp->v_mat); + return; + case V_OCTET: + if (*vp->v_octet == 0) { + *vres = error_value(E_DIVBYZERO); + return; + } + q1 = itoq((long) *vp->v_octet); + q2 = qinv(q1); + qfree(q1); + vres->v_num = q2; + vres->v_type = V_NUM; + return; + case V_OBJ: + *vres = objcall(OBJ_INV, vp, NULL_VALUE, NULL_VALUE); + return; + default: + if (vp->v_type == -E_DIVBYZERO) { + vres->v_type = V_NUM; + vres->v_num = qlink(&_qzero_); + return; + } + if (vp->v_type <= 0) + return; + *vres = error_value(E_INV); + return; + } } @@ -733,55 +733,55 @@ invertvalue(VALUE *vp, VALUE *vres) void andvalue(VALUE *v1, VALUE *v2, VALUE *vres) { - unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ + unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type == V_NULL) { - copyvalue(v2, vres); - return; - } - if (v2->v_type == V_NULL) { - copyvalue(v1, vres); - return; - } - vres->v_type = v1->v_type; - twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); - switch (twoval_as_uint) { - case TWOVAL(V_NUM, V_NUM): - vres->v_num = qand(v1->v_num, v2->v_num); - return; - case TWOVAL(V_STR, V_STR): - vres->v_str = stringand(v1->v_str, v2->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRAND); - return; - case TWOVAL(V_OCTET, V_OCTET): - vres->v_type = V_STR; - vres->v_str = charstring(*v1->v_octet & *v2->v_octet); - return; - case TWOVAL(V_STR, V_OCTET): - vres->v_str = charstring(*v1->v_str->s_str & - *v2->v_octet); - return; - case TWOVAL(V_OCTET, V_STR): - vres->v_type = V_STR; - vres->v_str = charstring(*v1->v_octet & - *v2->v_str->s_str); - return; - default: - if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { - if (v1->v_type < 0) - return; - if (v2->v_type < 0) { - vres->v_type = v2->v_type; - return; - } - *vres = error_value(E_AND); - return; - } - *vres = objcall(OBJ_AND, v1, v2, NULL_VALUE); - return; - } + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type == V_NULL) { + copyvalue(v2, vres); + return; + } + if (v2->v_type == V_NULL) { + copyvalue(v1, vres); + return; + } + vres->v_type = v1->v_type; + twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); + switch (twoval_as_uint) { + case TWOVAL(V_NUM, V_NUM): + vres->v_num = qand(v1->v_num, v2->v_num); + return; + case TWOVAL(V_STR, V_STR): + vres->v_str = stringand(v1->v_str, v2->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRAND); + return; + case TWOVAL(V_OCTET, V_OCTET): + vres->v_type = V_STR; + vres->v_str = charstring(*v1->v_octet & *v2->v_octet); + return; + case TWOVAL(V_STR, V_OCTET): + vres->v_str = charstring(*v1->v_str->s_str & + *v2->v_octet); + return; + case TWOVAL(V_OCTET, V_STR): + vres->v_type = V_STR; + vres->v_str = charstring(*v1->v_octet & + *v2->v_str->s_str); + return; + default: + if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { + if (v1->v_type < 0) + return; + if (v2->v_type < 0) { + vres->v_type = v2->v_type; + return; + } + *vres = error_value(E_AND); + return; + } + *vres = objcall(OBJ_AND, v1, v2, NULL_VALUE); + return; + } } @@ -792,55 +792,55 @@ andvalue(VALUE *v1, VALUE *v2, VALUE *vres) void orvalue(VALUE *v1, VALUE *v2, VALUE *vres) { - unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ + unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ - if (v1->v_type == V_NULL) { - copyvalue(v2, vres); - return; - } - if (v2->v_type == V_NULL) { - copyvalue(v1, vres); - return; - } - vres->v_type = v1->v_type; - vres->v_subtype = V_NOSUBTYPE; - twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); - switch (twoval_as_uint) { - case TWOVAL(V_NUM, V_NUM): - vres->v_num = qor(v1->v_num, v2->v_num); - return; - case TWOVAL(V_STR, V_STR): - vres->v_str = stringor(v1->v_str, v2->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STROR); - return; - case TWOVAL(V_OCTET, V_OCTET): - vres->v_type = V_STR; - vres->v_str = charstring(*v1->v_octet | *v2->v_octet); - return; - case TWOVAL(V_STR, V_OCTET): - vres->v_str = charstring(*v1->v_str->s_str | - *v2->v_octet); - return; - case TWOVAL(V_OCTET, V_STR): - vres->v_type = V_STR; - vres->v_str = charstring(*v1->v_octet | - *v2->v_str->s_str); - return; - default: - if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { - if (v1->v_type < 0) - return; - if (v2->v_type < 0) { - vres->v_type = v2->v_type; - return; - } - *vres = error_value(E_OR); - return; - } - *vres = objcall(OBJ_OR, v1, v2, NULL_VALUE); - return; - } + if (v1->v_type == V_NULL) { + copyvalue(v2, vres); + return; + } + if (v2->v_type == V_NULL) { + copyvalue(v1, vres); + return; + } + vres->v_type = v1->v_type; + vres->v_subtype = V_NOSUBTYPE; + twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); + switch (twoval_as_uint) { + case TWOVAL(V_NUM, V_NUM): + vres->v_num = qor(v1->v_num, v2->v_num); + return; + case TWOVAL(V_STR, V_STR): + vres->v_str = stringor(v1->v_str, v2->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STROR); + return; + case TWOVAL(V_OCTET, V_OCTET): + vres->v_type = V_STR; + vres->v_str = charstring(*v1->v_octet | *v2->v_octet); + return; + case TWOVAL(V_STR, V_OCTET): + vres->v_str = charstring(*v1->v_str->s_str | + *v2->v_octet); + return; + case TWOVAL(V_OCTET, V_STR): + vres->v_type = V_STR; + vres->v_str = charstring(*v1->v_octet | + *v2->v_str->s_str); + return; + default: + if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { + if (v1->v_type < 0) + return; + if (v2->v_type < 0) { + vres->v_type = v2->v_type; + return; + } + *vres = error_value(E_OR); + return; + } + *vres = objcall(OBJ_OR, v1, v2, NULL_VALUE); + return; + } } @@ -852,46 +852,46 @@ orvalue(VALUE *v1, VALUE *v2, VALUE *vres) void xorvalue(VALUE *v1, VALUE *v2, VALUE *vres) { - unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ + unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ - vres->v_type = v1->v_type; - vres->v_subtype = V_NOSUBTYPE; - twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); - switch (twoval_as_uint) { - case (TWOVAL(V_NUM, V_NUM)): - vres->v_num = qxor(v1->v_num, v2->v_num); - return; - case (TWOVAL(V_STR, V_STR)): - vres->v_str = stringxor(v1->v_str, v2->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRDIFF); - return; - case (TWOVAL(V_STR, V_OCTET)): - if (v1->v_str->s_len) { - vres->v_str = stringcopy(v1->v_str); - *vres->v_str->s_str ^= *v2->v_octet; - } else { - vres->v_str = charstring(*v2->v_octet); - } - return; - case (TWOVAL(V_OCTET, V_STR)): - if (v2->v_str->s_len) { - vres->v_str = stringcopy(v2->v_str); - *vres->v_str->s_str ^= *v1->v_octet; - } else { - vres->v_str = charstring(*v1->v_octet); - } - return; - case (TWOVAL(V_OCTET, V_OCTET)): - vres->v_type = V_STR; - vres->v_str = charstring(*v1->v_octet ^ *v2->v_octet); - return; - default: - if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) - *vres = objcall(OBJ_XOR, v1, v2, NULL_VALUE); - else - *vres = error_value(E_XOR); - } + vres->v_type = v1->v_type; + vres->v_subtype = V_NOSUBTYPE; + twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); + switch (twoval_as_uint) { + case (TWOVAL(V_NUM, V_NUM)): + vres->v_num = qxor(v1->v_num, v2->v_num); + return; + case (TWOVAL(V_STR, V_STR)): + vres->v_str = stringxor(v1->v_str, v2->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRDIFF); + return; + case (TWOVAL(V_STR, V_OCTET)): + if (v1->v_str->s_len) { + vres->v_str = stringcopy(v1->v_str); + *vres->v_str->s_str ^= *v2->v_octet; + } else { + vres->v_str = charstring(*v2->v_octet); + } + return; + case (TWOVAL(V_OCTET, V_STR)): + if (v2->v_str->s_len) { + vres->v_str = stringcopy(v2->v_str); + *vres->v_str->s_str ^= *v1->v_octet; + } else { + vres->v_str = charstring(*v1->v_octet); + } + return; + case (TWOVAL(V_OCTET, V_OCTET)): + vres->v_type = V_STR; + vres->v_str = charstring(*v1->v_octet ^ *v2->v_octet); + return; + default: + if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) + *vres = objcall(OBJ_XOR, v1, v2, NULL_VALUE); + else + *vres = error_value(E_XOR); + } } @@ -901,24 +901,24 @@ xorvalue(VALUE *v1, VALUE *v2, VALUE *vres) void hashopvalue(VALUE *v1, VALUE *v2, VALUE *vres) { - unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ - NUMBER *q; + unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ + NUMBER *q; - vres->v_type = v1->v_type; - vres->v_subtype = V_NOSUBTYPE; - twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); - switch (twoval_as_uint) { - case TWOVAL(V_NUM, V_NUM): - q = qsub(v1->v_num, v2->v_num); - vres->v_num = qqabs(q); - qfree(q); - return; - default: - if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) - *vres = objcall(OBJ_HASHOP, v1, v2, NULL_VALUE); - else - *vres = error_value(E_HASHOP); - } + vres->v_type = v1->v_type; + vres->v_subtype = V_NOSUBTYPE; + twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); + switch (twoval_as_uint) { + case TWOVAL(V_NUM, V_NUM): + q = qsub(v1->v_num, v2->v_num); + vres->v_num = qqabs(q); + qfree(q); + return; + default: + if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) + *vres = objcall(OBJ_HASHOP, v1, v2, NULL_VALUE); + else + *vres = error_value(E_HASHOP); + } } @@ -926,27 +926,27 @@ void compvalue(VALUE *vp, VALUE *vres) { - vres->v_type = vp->v_type; - vres->v_subtype = V_NOSUBTYPE; - switch (vp->v_type) { - case V_NUM: - vres->v_num = qcomp(vp->v_num); - return; - case V_STR: - vres->v_str = stringcomp(vp->v_str); - if (vres->v_str == NULL) - *vres = error_value(E_STRCOMP); - return; - case V_OCTET: - vres->v_type = V_STR; - vres->v_str = charstring(~*vp->v_octet); - return; - case V_OBJ: - *vres = objcall(OBJ_COMP, vp, NULL_VALUE, NULL_VALUE); - return; - default: - *vres = error_value(E_COMP); - } + vres->v_type = vp->v_type; + vres->v_subtype = V_NOSUBTYPE; + switch (vp->v_type) { + case V_NUM: + vres->v_num = qcomp(vp->v_num); + return; + case V_STR: + vres->v_str = stringcomp(vp->v_str); + if (vres->v_str == NULL) + *vres = error_value(E_STRCOMP); + return; + case V_OCTET: + vres->v_type = V_STR; + vres->v_str = charstring(~*vp->v_octet); + return; + case V_OBJ: + *vres = objcall(OBJ_COMP, vp, NULL_VALUE, NULL_VALUE); + return; + default: + *vres = error_value(E_COMP); + } } /* @@ -955,10 +955,10 @@ compvalue(VALUE *vp, VALUE *vres) void backslashvalue(VALUE *vp, VALUE *vres) { - if (vp->v_type == V_OBJ) - *vres = objcall(OBJ_BACKSLASH, vp, NULL_VALUE, NULL_VALUE); - else - *vres = error_value(E_BACKSLASH); + if (vp->v_type == V_OBJ) + *vres = objcall(OBJ_BACKSLASH, vp, NULL_VALUE, NULL_VALUE); + else + *vres = error_value(E_BACKSLASH); } @@ -969,39 +969,39 @@ backslashvalue(VALUE *vp, VALUE *vres) void setminusvalue(VALUE *v1, VALUE *v2, VALUE *vres) { - unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ + unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ - vres->v_type = v1->v_type; - vres->v_subtype = V_NOSUBTYPE; - twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); - switch (twoval_as_uint) { - case TWOVAL(V_NUM, V_NUM): - vres->v_num = qandnot(v1->v_num, v2->v_num); - return; - case TWOVAL(V_STR, V_STR): - vres->v_str = stringdiff(v1->v_str, v2->v_str); - return; - case TWOVAL(V_STR, V_OCTET): - vres->v_str = charstring(*v1->v_str->s_str & - ~*v2->v_octet); - return; - case TWOVAL(V_OCTET, V_STR): - vres->v_type = V_STR; - vres->v_str = charstring(*v1->v_octet & - ~*v2->v_str->s_str); - return; - case TWOVAL(V_OCTET, V_OCTET): - vres->v_type = V_STR; - vres->v_str = charstring(*v1->v_octet & - ~*v2->v_octet); - return; - default: - if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) - *vres = objcall(OBJ_SETMINUS, v1, v2, - NULL_VALUE); - else - *vres = error_value(E_SETMINUS); - } + vres->v_type = v1->v_type; + vres->v_subtype = V_NOSUBTYPE; + twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); + switch (twoval_as_uint) { + case TWOVAL(V_NUM, V_NUM): + vres->v_num = qandnot(v1->v_num, v2->v_num); + return; + case TWOVAL(V_STR, V_STR): + vres->v_str = stringdiff(v1->v_str, v2->v_str); + return; + case TWOVAL(V_STR, V_OCTET): + vres->v_str = charstring(*v1->v_str->s_str & + ~*v2->v_octet); + return; + case TWOVAL(V_OCTET, V_STR): + vres->v_type = V_STR; + vres->v_str = charstring(*v1->v_octet & + ~*v2->v_str->s_str); + return; + case TWOVAL(V_OCTET, V_OCTET): + vres->v_type = V_STR; + vres->v_str = charstring(*v1->v_octet & + ~*v2->v_octet); + return; + default: + if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) + *vres = objcall(OBJ_SETMINUS, v1, v2, + NULL_VALUE); + else + *vres = error_value(E_SETMINUS); + } } @@ -1012,32 +1012,32 @@ setminusvalue(VALUE *v1, VALUE *v2, VALUE *vres) void contentvalue(VALUE *vp, VALUE *vres) { - long count; - unsigned char u; + long count; + unsigned char u; - vres->v_type = V_NUM; - vres->v_subtype = V_NOSUBTYPE; - count = 0; - switch (vp->v_type) { - case V_STR: - count = stringcontent(vp->v_str); - break; - case V_OCTET: - for (u = *vp->v_octet; u; u >>= 1) - count += (u & 1); - break; - case V_NUM: - count = zpopcnt(vp->v_num->num, 1); - break; - case V_OBJ: - *vres = objcall(OBJ_CONTENT, vp, NULL_VALUE, - NULL_VALUE); - return; - default: - *vres = error_value(E_CONTENT); - return; - } - vres->v_num = itoq(count); + vres->v_type = V_NUM; + vres->v_subtype = V_NOSUBTYPE; + count = 0; + switch (vp->v_type) { + case V_STR: + count = stringcontent(vp->v_str); + break; + case V_OCTET: + for (u = *vp->v_octet; u; u >>= 1) + count += (u & 1); + break; + case V_NUM: + count = zpopcnt(vp->v_num->num, 1); + break; + case V_OBJ: + *vres = objcall(OBJ_CONTENT, vp, NULL_VALUE, + NULL_VALUE); + return; + default: + *vres = error_value(E_CONTENT); + return; + } + vres->v_num = itoq(count); } @@ -1048,74 +1048,74 @@ contentvalue(VALUE *vp, VALUE *vres) void apprvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) { - NUMBER *e; - long R = 0; - NUMBER *q1, *q2; - COMPLEX *c; + NUMBER *e; + long R = 0; + NUMBER *q1, *q2; + COMPLEX *c; - vres->v_type = v1->v_type; - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type <= 0) - return; + vres->v_type = v1->v_type; + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type <= 0) + return; - e = NULL; - switch(v2->v_type) { - case V_NUM: e = v2->v_num; - break; - case V_NULL: e = conf->epsilon; - break; - default: - *vres = error_value(E_APPR_2); - return; - } - switch(v3->v_type) { - case V_NUM: if (qisfrac(v3->v_num)) { - *vres = error_value(E_APPR_3); - return; - } - R = qtoi(v3->v_num); - break; - case V_NULL: R = conf->appr; - break; - default: - *vres = error_value(E_APPR_3); - return; - } + e = NULL; + switch(v2->v_type) { + case V_NUM: e = v2->v_num; + break; + case V_NULL: e = conf->epsilon; + break; + default: + *vres = error_value(E_APPR_2); + return; + } + switch(v3->v_type) { + case V_NUM: if (qisfrac(v3->v_num)) { + *vres = error_value(E_APPR_3); + return; + } + R = qtoi(v3->v_num); + break; + case V_NULL: R = conf->appr; + break; + default: + *vres = error_value(E_APPR_3); + return; + } - if (qiszero(e)) { - copyvalue(v1, vres); - return; - } - switch (v1->v_type) { - case V_NUM: - vres->v_num = qmappr(v1->v_num, e, R); - return; - case V_MAT: - vres->v_mat = matappr(v1->v_mat, v2, v3); - return; - case V_LIST: - vres->v_list = listappr(v1->v_list, v2, v3); - return; - case V_COM: - q1 = qmappr(v1->v_com->real, e, R); - q2 = qmappr(v1->v_com->imag, e, R); - if (qiszero(q2)) { - vres->v_type = V_NUM; - vres->v_num = q1; - qfree(q2); - return; - } - c = comalloc(); - qfree(c->real); - qfree(c->imag); - c->real = q1; - c->imag = q2; - vres->v_com = c; - return; - default: - *vres = error_value(E_APPR_1); - return; - } + if (qiszero(e)) { + copyvalue(v1, vres); + return; + } + switch (v1->v_type) { + case V_NUM: + vres->v_num = qmappr(v1->v_num, e, R); + return; + case V_MAT: + vres->v_mat = matappr(v1->v_mat, v2, v3); + return; + case V_LIST: + vres->v_list = listappr(v1->v_list, v2, v3); + return; + case V_COM: + q1 = qmappr(v1->v_com->real, e, R); + q2 = qmappr(v1->v_com->imag, e, R); + if (qiszero(q2)) { + vres->v_type = V_NUM; + vres->v_num = q1; + qfree(q2); + return; + } + c = comalloc(); + qfree(c->real); + qfree(c->imag); + c->real = q1; + c->imag = q2; + vres->v_com = c; + return; + default: + *vres = error_value(E_APPR_1); + return; + } } @@ -1126,81 +1126,81 @@ apprvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) void roundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) { - NUMBER *q1, *q2; - COMPLEX *c; - long places, rnd; + NUMBER *q1, *q2; + COMPLEX *c; + long places, rnd; - vres->v_type = v1->v_type; - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type == V_MAT) { - vres->v_mat = matround(v1->v_mat, v2, v3); - return; - } - if (v1->v_type == V_LIST) { - vres->v_list = listround(v1->v_list, v2, v3); - return; - } - if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) { - *vres = objcall(OBJ_ROUND, v1, v2, v3); - return; - } - places = 0; - switch (v2->v_type) { - case V_NUM: - if (qisfrac(v2->v_num)) { - *vres = error_value(E_ROUND_2); - return; - } - places = qtoi(v2->v_num); - break; - case V_NULL: - break; - default: - *vres = error_value(E_ROUND_2); - return; - } - rnd = 0; - switch (v3->v_type) { - case V_NUM: - if (qisfrac(v3->v_num)) { - *vres = error_value(E_ROUND_3); - return; - } - rnd = qtoi(v3->v_num); - break; - case V_NULL: - rnd = conf->round; - break; - default: - *vres = error_value(E_ROUND_3); - return; - } - switch(v1->v_type) { - case V_NUM: - vres->v_num = qround(v1->v_num, places, rnd); - return; - case V_COM: - q1 = qround(v1->v_com->real, places, rnd); - q2 = qround(v1->v_com->imag, places, rnd); - if (qiszero(q2)) { - vres->v_type = V_NUM; - vres->v_num = q1; - qfree(q2); - return; - } - c = comalloc(); - qfree(c->real); - qfree(c->imag); - c->real = q1; - c->imag = q2; - vres->v_com = c; - return; - default: - if (v1->v_type <= 0) - return; - *vres = error_value(E_ROUND_1); - return; - } + vres->v_type = v1->v_type; + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type == V_MAT) { + vres->v_mat = matround(v1->v_mat, v2, v3); + return; + } + if (v1->v_type == V_LIST) { + vres->v_list = listround(v1->v_list, v2, v3); + return; + } + if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) { + *vres = objcall(OBJ_ROUND, v1, v2, v3); + return; + } + places = 0; + switch (v2->v_type) { + case V_NUM: + if (qisfrac(v2->v_num)) { + *vres = error_value(E_ROUND_2); + return; + } + places = qtoi(v2->v_num); + break; + case V_NULL: + break; + default: + *vres = error_value(E_ROUND_2); + return; + } + rnd = 0; + switch (v3->v_type) { + case V_NUM: + if (qisfrac(v3->v_num)) { + *vres = error_value(E_ROUND_3); + return; + } + rnd = qtoi(v3->v_num); + break; + case V_NULL: + rnd = conf->round; + break; + default: + *vres = error_value(E_ROUND_3); + return; + } + switch(v1->v_type) { + case V_NUM: + vres->v_num = qround(v1->v_num, places, rnd); + return; + case V_COM: + q1 = qround(v1->v_com->real, places, rnd); + q2 = qround(v1->v_com->imag, places, rnd); + if (qiszero(q2)) { + vres->v_type = V_NUM; + vres->v_num = q1; + qfree(q2); + return; + } + c = comalloc(); + qfree(c->real); + qfree(c->imag); + c->real = q1; + c->imag = q2; + vres->v_com = c; + return; + default: + if (v1->v_type <= 0) + return; + *vres = error_value(E_ROUND_1); + return; + } } @@ -1212,81 +1212,81 @@ roundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) void broundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) { - NUMBER *q1, *q2; - COMPLEX *c; - long places, rnd; + NUMBER *q1, *q2; + COMPLEX *c; + long places, rnd; - vres->v_type = v1->v_type; - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type == V_MAT) { - vres->v_mat = matbround(v1->v_mat, v2, v3); - return; - } - if (v1->v_type == V_LIST) { - vres->v_list = listbround(v1->v_list, v2, v3); - return; - } - if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) { - *vres = objcall(OBJ_BROUND, v1, v2, v3); - return; - } - places = 0; - switch (v2->v_type) { - case V_NUM: - if (qisfrac(v2->v_num)) { - *vres = error_value(E_BROUND_2); - return; - } - places = qtoi(v2->v_num); - break; - case V_NULL: - break; - default: - *vres = error_value(E_BROUND_2); - return; - } - rnd = 0; - switch (v3->v_type) { - case V_NUM: - if (qisfrac(v3->v_num)) { - *vres = error_value(E_BROUND_3); - return; - } - rnd = qtoi(v3->v_num); - break; - case V_NULL: - rnd = conf->round; - break; - default: - *vres = error_value(E_BROUND_3); - return; - } - switch(v1->v_type) { - case V_NUM: - vres->v_num = qbround(v1->v_num, places, rnd); - return; - case V_COM: - q1 = qbround(v1->v_com->real, places, rnd); - q2 = qbround(v1->v_com->imag, places, rnd); - if (qiszero(q2)) { - vres->v_type = V_NUM; - vres->v_num = q1; - qfree(q2); - return; - } - c = comalloc(); - qfree(c->real); - qfree(c->imag); - c->real = q1; - c->imag = q2; - vres->v_com = c; - return; - default: - if (v1->v_type <= 0) - return; - *vres = error_value(E_BROUND_1); - return; - } + vres->v_type = v1->v_type; + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type == V_MAT) { + vres->v_mat = matbround(v1->v_mat, v2, v3); + return; + } + if (v1->v_type == V_LIST) { + vres->v_list = listbround(v1->v_list, v2, v3); + return; + } + if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) { + *vres = objcall(OBJ_BROUND, v1, v2, v3); + return; + } + places = 0; + switch (v2->v_type) { + case V_NUM: + if (qisfrac(v2->v_num)) { + *vres = error_value(E_BROUND_2); + return; + } + places = qtoi(v2->v_num); + break; + case V_NULL: + break; + default: + *vres = error_value(E_BROUND_2); + return; + } + rnd = 0; + switch (v3->v_type) { + case V_NUM: + if (qisfrac(v3->v_num)) { + *vres = error_value(E_BROUND_3); + return; + } + rnd = qtoi(v3->v_num); + break; + case V_NULL: + rnd = conf->round; + break; + default: + *vres = error_value(E_BROUND_3); + return; + } + switch(v1->v_type) { + case V_NUM: + vres->v_num = qbround(v1->v_num, places, rnd); + return; + case V_COM: + q1 = qbround(v1->v_com->real, places, rnd); + q2 = qbround(v1->v_com->imag, places, rnd); + if (qiszero(q2)) { + vres->v_type = V_NUM; + vres->v_num = q1; + qfree(q2); + return; + } + c = comalloc(); + qfree(c->real); + qfree(c->imag); + c->real = q1; + c->imag = q2; + vres->v_com = c; + return; + default: + if (v1->v_type <= 0) + return; + *vres = error_value(E_BROUND_1); + return; + } } /* @@ -1296,42 +1296,42 @@ broundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) void intvalue(VALUE *vp, VALUE *vres) { - COMPLEX *c; + COMPLEX *c; - vres->v_type = vp->v_type; - vres->v_subtype = V_NOSUBTYPE; - switch (vp->v_type) { - case V_NUM: - if (qisint(vp->v_num)) - vres->v_num = qlink(vp->v_num); - else - vres->v_num = qint(vp->v_num); - return; - case V_COM: - if (cisint(vp->v_com)) { - vres->v_com = clink(vp->v_com); - return; - } - vres->v_com = c_int(vp->v_com); - c = vres->v_com; - if (cisreal(c)) { - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - } - return; - case V_MAT: - vres->v_mat = matint(vp->v_mat); - return; - case V_OBJ: - *vres = objcall(OBJ_INT, vp, NULL_VALUE, NULL_VALUE); - return; - default: - if (vp->v_type <= 0) - return; - *vres = error_value(E_INT); - return; - } + vres->v_type = vp->v_type; + vres->v_subtype = V_NOSUBTYPE; + switch (vp->v_type) { + case V_NUM: + if (qisint(vp->v_num)) + vres->v_num = qlink(vp->v_num); + else + vres->v_num = qint(vp->v_num); + return; + case V_COM: + if (cisint(vp->v_com)) { + vres->v_com = clink(vp->v_com); + return; + } + vres->v_com = c_int(vp->v_com); + c = vres->v_com; + if (cisreal(c)) { + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + } + return; + case V_MAT: + vres->v_mat = matint(vp->v_mat); + return; + case V_OBJ: + *vres = objcall(OBJ_INT, vp, NULL_VALUE, NULL_VALUE); + return; + default: + if (vp->v_type <= 0) + return; + *vres = error_value(E_INT); + return; + } } @@ -1342,43 +1342,43 @@ intvalue(VALUE *vp, VALUE *vres) void fracvalue(VALUE *vp, VALUE *vres) { - COMPLEX *c; + COMPLEX *c; - vres->v_type = vp->v_type; - vres->v_subtype = V_NOSUBTYPE; - switch (vp->v_type) { - case V_NUM: - if (qisint(vp->v_num)) - vres->v_num = qlink(&_qzero_); - else - vres->v_num = qfrac(vp->v_num); - return; - case V_COM: - if (cisint(vp->v_com)) { - vres->v_num = clink(&_qzero_); - vres->v_type = V_NUM; - return; - } - vres->v_com = c_frac(vp->v_com); - c = vres->v_com; - if (cisreal(c)) { - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - } - return; - case V_MAT: - vres->v_mat = matfrac(vp->v_mat); - return; - case V_OBJ: - *vres = objcall(OBJ_FRAC, vp, NULL_VALUE, NULL_VALUE); - return; - default: - if (vp->v_type < 0) - return; - *vres = error_value(E_FRAC); - return; - } + vres->v_type = vp->v_type; + vres->v_subtype = V_NOSUBTYPE; + switch (vp->v_type) { + case V_NUM: + if (qisint(vp->v_num)) + vres->v_num = qlink(&_qzero_); + else + vres->v_num = qfrac(vp->v_num); + return; + case V_COM: + if (cisint(vp->v_com)) { + vres->v_num = clink(&_qzero_); + vres->v_type = V_NUM; + return; + } + vres->v_com = c_frac(vp->v_com); + c = vres->v_com; + if (cisreal(c)) { + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + } + return; + case V_MAT: + vres->v_mat = matfrac(vp->v_mat); + return; + case V_OBJ: + *vres = objcall(OBJ_FRAC, vp, NULL_VALUE, NULL_VALUE); + return; + default: + if (vp->v_type < 0) + return; + *vres = error_value(E_FRAC); + return; + } } @@ -1389,32 +1389,32 @@ fracvalue(VALUE *vp, VALUE *vres) void incvalue(VALUE *vp, VALUE *vres) { - vres->v_type = vp->v_type; - switch (vp->v_type) { - case V_NUM: - vres->v_num = qinc(vp->v_num); - break; - case V_COM: - vres->v_com = c_addq(vp->v_com, &_qone_); - break; - case V_OBJ: - *vres = objcall(OBJ_INC, vp, NULL_VALUE, NULL_VALUE); - break; - case V_OCTET: - *vres->v_octet = *vp->v_octet + 1; - break; - case V_OPTR: - vres->v_octet = vp->v_octet + 1; - break; - case V_VPTR: - vres->v_addr = vp->v_addr + 1; - break; - default: - if (vp->v_type > 0) - *vres = error_value(E_INCV); - break; - } - vres->v_subtype = vp->v_subtype; + vres->v_type = vp->v_type; + switch (vp->v_type) { + case V_NUM: + vres->v_num = qinc(vp->v_num); + break; + case V_COM: + vres->v_com = c_addq(vp->v_com, &_qone_); + break; + case V_OBJ: + *vres = objcall(OBJ_INC, vp, NULL_VALUE, NULL_VALUE); + break; + case V_OCTET: + *vres->v_octet = *vp->v_octet + 1; + break; + case V_OPTR: + vres->v_octet = vp->v_octet + 1; + break; + case V_VPTR: + vres->v_addr = vp->v_addr + 1; + break; + default: + if (vp->v_type > 0) + *vres = error_value(E_INCV); + break; + } + vres->v_subtype = vp->v_subtype; } @@ -1425,32 +1425,32 @@ incvalue(VALUE *vp, VALUE *vres) void decvalue(VALUE *vp, VALUE *vres) { - vres->v_type = vp->v_type; - switch (vp->v_type) { - case V_NUM: - vres->v_num = qdec(vp->v_num); - break; - case V_COM: - vres->v_com = c_addq(vp->v_com, &_qnegone_); - break; - case V_OBJ: - *vres = objcall(OBJ_DEC, vp, NULL_VALUE, NULL_VALUE); - break; - case V_OCTET: - *vres->v_octet = *vp->v_octet - 1; - break; - case V_OPTR: - vres->v_octet = vp->v_octet - 1; - break; - case V_VPTR: - vres->v_addr = vp->v_addr - 1; - break; - default: - if (vp->v_type >= 0) - *vres = error_value(E_DECV); - break; - } - vres->v_subtype = vp->v_subtype; + vres->v_type = vp->v_type; + switch (vp->v_type) { + case V_NUM: + vres->v_num = qdec(vp->v_num); + break; + case V_COM: + vres->v_com = c_addq(vp->v_com, &_qnegone_); + break; + case V_OBJ: + *vres = objcall(OBJ_DEC, vp, NULL_VALUE, NULL_VALUE); + break; + case V_OCTET: + *vres->v_octet = *vp->v_octet - 1; + break; + case V_OPTR: + vres->v_octet = vp->v_octet - 1; + break; + case V_VPTR: + vres->v_addr = vp->v_addr - 1; + break; + default: + if (vp->v_type >= 0) + *vres = error_value(E_DECV); + break; + } + vres->v_subtype = vp->v_subtype; } @@ -1462,33 +1462,33 @@ decvalue(VALUE *vp, VALUE *vres) void conjvalue(VALUE *vp, VALUE *vres) { - vres->v_type = vp->v_type; - vres->v_subtype = V_NOSUBTYPE; - switch (vp->v_type) { - case V_NUM: - vres->v_num = qlink(vp->v_num); - return; - case V_COM: - vres->v_com = comalloc(); - qfree(vres->v_com->real); - qfree(vres->v_com->imag) - vres->v_com->real = qlink(vp->v_com->real); - vres->v_com->imag = qneg(vp->v_com->imag); - return; - case V_MAT: - vres->v_mat = matconj(vp->v_mat); - return; - case V_OBJ: - *vres = objcall(OBJ_CONJ, vp, NULL_VALUE, NULL_VALUE); - return; - default: - if (vp->v_type <= 0) { - vres->v_type = vp->v_type; - return; - } - *vres = error_value(E_CONJ); - return; - } + vres->v_type = vp->v_type; + vres->v_subtype = V_NOSUBTYPE; + switch (vp->v_type) { + case V_NUM: + vres->v_num = qlink(vp->v_num); + return; + case V_COM: + vres->v_com = comalloc(); + qfree(vres->v_com->real); + qfree(vres->v_com->imag) + vres->v_com->real = qlink(vp->v_com->real); + vres->v_com->imag = qneg(vp->v_com->imag); + return; + case V_MAT: + vres->v_mat = matconj(vp->v_mat); + return; + case V_OBJ: + *vres = objcall(OBJ_CONJ, vp, NULL_VALUE, NULL_VALUE); + return; + default: + if (vp->v_type <= 0) { + vres->v_type = vp->v_type; + return; + } + *vres = error_value(E_CONJ); + return; + } } @@ -1499,65 +1499,65 @@ conjvalue(VALUE *vp, VALUE *vres) void sqrtvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) { - NUMBER *q, *tmp; - COMPLEX *c; - long R; + NUMBER *q, *tmp; + COMPLEX *c; + long R; - if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) { - *vres = objcall(OBJ_SQRT, v1, v2, v3); - return; - } - vres->v_type = v1->v_type; - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type <= 0) { - vres->v_type = v1->v_type; - return; - } - if (v2->v_type == V_NULL) { - q = conf->epsilon; - } else { - if (v2->v_type != V_NUM || qiszero(v2->v_num)) { - *vres = error_value(E_SQRT_2); - return; - } - q = v2->v_num; - } - if (v3->v_type == V_NULL) { - R = conf->sqrt; - } else { - if (v3->v_type != V_NUM || qisfrac(v3->v_num)) { - *vres = error_value(E_SQRT_3); - return; - } - R = qtoi(v3->v_num); - } - switch (v1->v_type) { - case V_NUM: - if (!qisneg(v1->v_num)) { - vres->v_num = qsqrt(v1->v_num, q, R); - return; - } - tmp = qneg(v1->v_num); - c = comalloc(); - qfree(c->imag); - c->imag = qsqrt(tmp, q, R); - qfree(tmp); - vres->v_com = c; - vres->v_type = V_COM; - break; - case V_COM: - vres->v_com = c_sqrt(v1->v_com, q, R); - break; - default: - *vres = error_value(E_SQRT_1); - return; - } - c = vres->v_com; - if (cisreal(c)) { - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - } + if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) { + *vres = objcall(OBJ_SQRT, v1, v2, v3); + return; + } + vres->v_type = v1->v_type; + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type <= 0) { + vres->v_type = v1->v_type; + return; + } + if (v2->v_type == V_NULL) { + q = conf->epsilon; + } else { + if (v2->v_type != V_NUM || qiszero(v2->v_num)) { + *vres = error_value(E_SQRT_2); + return; + } + q = v2->v_num; + } + if (v3->v_type == V_NULL) { + R = conf->sqrt; + } else { + if (v3->v_type != V_NUM || qisfrac(v3->v_num)) { + *vres = error_value(E_SQRT_3); + return; + } + R = qtoi(v3->v_num); + } + switch (v1->v_type) { + case V_NUM: + if (!qisneg(v1->v_num)) { + vres->v_num = qsqrt(v1->v_num, q, R); + return; + } + tmp = qneg(v1->v_num); + c = comalloc(); + qfree(c->imag); + c->imag = qsqrt(tmp, q, R); + qfree(tmp); + vres->v_com = c; + vres->v_type = V_COM; + break; + case V_COM: + vres->v_com = c_sqrt(v1->v_com, q, R); + break; + default: + *vres = error_value(E_SQRT_1); + return; + } + c = vres->v_com; + if (cisreal(c)) { + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + } } @@ -1566,72 +1566,72 @@ sqrtvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) * Result is placed in the indicated location. * * given: - * v1 value to take root of - * v2 value specifying root to take - * v3 value specifying error - * vres result + * v1 value to take root of + * v2 value specifying root to take + * v3 value specifying error + * vres result */ void rootvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) { - NUMBER *q2, *q3; - COMPLEX ctmp; - COMPLEX *c; + NUMBER *q2, *q3; + COMPLEX ctmp; + COMPLEX *c; - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type <= 0) { - vres->v_type = v1->v_type; - return; - } - if (v2->v_type != V_NUM) { - *vres = error_value(E_ROOT_2); - return; - } - q2 = v2->v_num; - if (qisneg(q2) || qiszero(q2) || qisfrac(q2)) { - *vres = error_value(E_ROOT_2); - return; - } - if (v3->v_type != V_NUM || qiszero(v3->v_num)) { - *vres = error_value(E_ROOT_3); - return; - } - q3 = v3->v_num; - switch (v1->v_type) { - case V_NUM: - if (!qisneg(v1->v_num)) { - vres->v_num = qroot(v1->v_num, q2, q3); - if (vres->v_num == NULL) - *vres = error_value(E_ROOT_4); - vres->v_type = V_NUM; - return; - } - ctmp.real = v1->v_num; - ctmp.imag = &_qzero_; - ctmp.links = 1; - c = c_root(&ctmp, q2, q3); - break; - case V_COM: - c = c_root(v1->v_com, q2, q3); - break; - case V_OBJ: - *vres = objcall(OBJ_ROOT, v1, v2, v3); - return; - default: - *vres = error_value(E_ROOT_1); - return; - } - if (c == NULL) { - *vres = error_value(E_ROOT_4); - return; - } - vres->v_com = c; - vres->v_type = V_COM; - if (cisreal(c)) { - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - } + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type <= 0) { + vres->v_type = v1->v_type; + return; + } + if (v2->v_type != V_NUM) { + *vres = error_value(E_ROOT_2); + return; + } + q2 = v2->v_num; + if (qisneg(q2) || qiszero(q2) || qisfrac(q2)) { + *vres = error_value(E_ROOT_2); + return; + } + if (v3->v_type != V_NUM || qiszero(v3->v_num)) { + *vres = error_value(E_ROOT_3); + return; + } + q3 = v3->v_num; + switch (v1->v_type) { + case V_NUM: + if (!qisneg(v1->v_num)) { + vres->v_num = qroot(v1->v_num, q2, q3); + if (vres->v_num == NULL) + *vres = error_value(E_ROOT_4); + vres->v_type = V_NUM; + return; + } + ctmp.real = v1->v_num; + ctmp.imag = &_qzero_; + ctmp.links = 1; + c = c_root(&ctmp, q2, q3); + break; + case V_COM: + c = c_root(v1->v_com, q2, q3); + break; + case V_OBJ: + *vres = objcall(OBJ_ROOT, v1, v2, v3); + return; + default: + *vres = error_value(E_ROOT_1); + return; + } + if (c == NULL) { + *vres = error_value(E_ROOT_4); + return; + } + vres->v_com = c; + vres->v_type = V_COM; + if (cisreal(c)) { + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + } } @@ -1642,37 +1642,37 @@ rootvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) void absvalue(VALUE *v1, VALUE *v2, VALUE *vres) { - STATIC NUMBER *q; + STATIC NUMBER *q; - if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) { - *vres = objcall(OBJ_ABS, v1, v2, NULL_VALUE); - return; - } - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type <= 0) { - vres->v_type = v1->v_type; - return; - } - switch (v1->v_type) { - case V_NUM: - if (qisneg(v1->v_num)) - q = qneg(v1->v_num); - else - q = qlink(v1->v_num); - break; - case V_COM: - if (v2->v_type != V_NUM || qiszero(v2->v_num)) { - *vres = error_value(E_ABS_2); - return; - } - q = qhypot(v1->v_com->real, v1->v_com->imag, v2->v_num); - break; - default: - *vres = error_value(E_ABS_1); - return; - } - vres->v_num = q; - vres->v_type = V_NUM; + if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) { + *vres = objcall(OBJ_ABS, v1, v2, NULL_VALUE); + return; + } + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type <= 0) { + vres->v_type = v1->v_type; + return; + } + switch (v1->v_type) { + case V_NUM: + if (qisneg(v1->v_num)) + q = qneg(v1->v_num); + else + q = qlink(v1->v_num); + break; + case V_COM: + if (v2->v_type != V_NUM || qiszero(v2->v_num)) { + *vres = error_value(E_ABS_2); + return; + } + q = qhypot(v1->v_com->real, v1->v_com->imag, v2->v_num); + break; + default: + *vres = error_value(E_ABS_1); + return; + } + vres->v_num = q; + vres->v_type = V_NUM; } @@ -1684,33 +1684,33 @@ absvalue(VALUE *v1, VALUE *v2, VALUE *vres) void normvalue(VALUE *vp, VALUE *vres) { - NUMBER *q1, *q2; + NUMBER *q1, *q2; - vres->v_type = vp->v_type; - vres->v_subtype = V_NOSUBTYPE; - if (vp->v_type <= 0) { - vres->v_type = vp->v_type; - return; - } - switch (vp->v_type) { - case V_NUM: - vres->v_num = qsquare(vp->v_num); - return; - case V_COM: - q1 = qsquare(vp->v_com->real); - q2 = qsquare(vp->v_com->imag); - vres->v_num = qqadd(q1, q2); - vres->v_type = V_NUM; - qfree(q1); - qfree(q2); - return; - case V_OBJ: - *vres = objcall(OBJ_NORM, vp, NULL_VALUE, NULL_VALUE); - return; - default: - *vres = error_value(E_NORM); - return; - } + vres->v_type = vp->v_type; + vres->v_subtype = V_NOSUBTYPE; + if (vp->v_type <= 0) { + vres->v_type = vp->v_type; + return; + } + switch (vp->v_type) { + case V_NUM: + vres->v_num = qsquare(vp->v_num); + return; + case V_COM: + q1 = qsquare(vp->v_com->real); + q2 = qsquare(vp->v_com->imag); + vres->v_num = qqadd(q1, q2); + vres->v_type = V_NUM; + qfree(q1); + qfree(q2); + return; + case V_OBJ: + *vres = objcall(OBJ_NORM, vp, NULL_VALUE, NULL_VALUE); + return; + default: + *vres = error_value(E_NORM); + return; + } } @@ -1721,93 +1721,93 @@ normvalue(VALUE *vp, VALUE *vres) * Result is placed in the indicated location. * * given: - * v1 value to shift - * v2 shift amount - * rightshift true if shift right instead of left - * vres result + * v1 value to shift + * v2 shift amount + * rightshift true if shift right instead of left + * vres result */ void shiftvalue(VALUE *v1, VALUE *v2, bool rightshift, VALUE *vres) { - COMPLEX *c; - long n = 0; - unsigned int ch; - VALUE tmp; + COMPLEX *c; + long n = 0; + unsigned int ch; + VALUE tmp; - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type <= 0) { - vres->v_type = v1->v_type; - return; - } - if ((v2->v_type != V_NUM) || (qisfrac(v2->v_num))) { - *vres = error_value(E_SHIFT_2); - return; - } - if (v1->v_type != V_OBJ) { - if (zge31b(v2->v_num->num)) { - *vres = error_value(E_SHIFT_2); - return; - } - n = qtoi(v2->v_num); - } - if (rightshift) - n = -n; - vres->v_type = v1->v_type; - switch (v1->v_type) { - case V_NUM: - if (qisfrac(v1->v_num)) { - *vres = error_value(E_SHIFT_1); - return; - } - vres->v_num = qshift(v1->v_num, n); - return; - case V_COM: - if (qisfrac(v1->v_com->real) || - qisfrac(v1->v_com->imag)) { - *vres = error_value(E_SHIFT_1); - return; - } - c = c_shift(v1->v_com, n); - if (!cisreal(c)) { - vres->v_com = c; - return; - } - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - return; - case V_MAT: - vres->v_mat = matshift(v1->v_mat, n); - return; - case V_STR: - vres->v_str = stringshift(v1->v_str, n); - if (vres->v_str == NULL) - *vres = error_value(E_STRSHIFT); - return; - case V_OCTET: - vres->v_type = V_STR; - if (n >= 8 || n <= -8) - ch = 0; - else if (n >= 0) - ch = (unsigned int) *v1->v_octet << n; - else - ch = (unsigned int) *v1->v_octet >> -n; - vres->v_str = charstring(ch); - return; - case V_OBJ: - if (!rightshift) { - *vres = objcall(OBJ_SHIFT, v1, v2, NULL_VALUE); - return; - } - tmp.v_num = qneg(v2->v_num); - tmp.v_type = V_NUM; - *vres = objcall(OBJ_SHIFT, v1, &tmp, NULL_VALUE); - qfree(tmp.v_num); - return; - default: - *vres = error_value(E_SHIFT_1); - return; - } + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type <= 0) { + vres->v_type = v1->v_type; + return; + } + if ((v2->v_type != V_NUM) || (qisfrac(v2->v_num))) { + *vres = error_value(E_SHIFT_2); + return; + } + if (v1->v_type != V_OBJ) { + if (zge31b(v2->v_num->num)) { + *vres = error_value(E_SHIFT_2); + return; + } + n = qtoi(v2->v_num); + } + if (rightshift) + n = -n; + vres->v_type = v1->v_type; + switch (v1->v_type) { + case V_NUM: + if (qisfrac(v1->v_num)) { + *vres = error_value(E_SHIFT_1); + return; + } + vres->v_num = qshift(v1->v_num, n); + return; + case V_COM: + if (qisfrac(v1->v_com->real) || + qisfrac(v1->v_com->imag)) { + *vres = error_value(E_SHIFT_1); + return; + } + c = c_shift(v1->v_com, n); + if (!cisreal(c)) { + vres->v_com = c; + return; + } + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + return; + case V_MAT: + vres->v_mat = matshift(v1->v_mat, n); + return; + case V_STR: + vres->v_str = stringshift(v1->v_str, n); + if (vres->v_str == NULL) + *vres = error_value(E_STRSHIFT); + return; + case V_OCTET: + vres->v_type = V_STR; + if (n >= 8 || n <= -8) + ch = 0; + else if (n >= 0) + ch = (unsigned int) *v1->v_octet << n; + else + ch = (unsigned int) *v1->v_octet >> -n; + vres->v_str = charstring(ch); + return; + case V_OBJ: + if (!rightshift) { + *vres = objcall(OBJ_SHIFT, v1, v2, NULL_VALUE); + return; + } + tmp.v_num = qneg(v2->v_num); + tmp.v_type = V_NUM; + *vres = objcall(OBJ_SHIFT, v1, &tmp, NULL_VALUE); + qfree(tmp.v_num); + return; + default: + *vres = error_value(E_SHIFT_1); + return; + } } @@ -1818,42 +1818,42 @@ shiftvalue(VALUE *v1, VALUE *v2, bool rightshift, VALUE *vres) void scalevalue(VALUE *v1, VALUE *v2, VALUE *vres) { - long n = 0; + long n = 0; - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type <= 0) { - vres->v_type = v1->v_type; - return; - } - if ((v2->v_type != V_NUM) || qisfrac(v2->v_num)) { - *vres = error_value(E_SCALE_2); - return; - } - if (v1->v_type != V_OBJ) { - if (zge31b(v2->v_num->num)) { - *vres = error_value(E_SCALE_2); - return; - } - n = qtoi(v2->v_num); - } - vres->v_type = v1->v_type; - switch (v1->v_type) { - case V_NUM: - vres->v_num = qscale(v1->v_num, n); - return; - case V_COM: - vres->v_com = c_scale(v1->v_com, n); - return; - case V_MAT: - vres->v_mat = matscale(v1->v_mat, n); - return; - case V_OBJ: - *vres = objcall(OBJ_SCALE, v1, v2, NULL_VALUE); - return; - default: - *vres = error_value(E_SCALE_1); - return; - } + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type <= 0) { + vres->v_type = v1->v_type; + return; + } + if ((v2->v_type != V_NUM) || qisfrac(v2->v_num)) { + *vres = error_value(E_SCALE_2); + return; + } + if (v1->v_type != V_OBJ) { + if (zge31b(v2->v_num->num)) { + *vres = error_value(E_SCALE_2); + return; + } + n = qtoi(v2->v_num); + } + vres->v_type = v1->v_type; + switch (v1->v_type) { + case V_NUM: + vres->v_num = qscale(v1->v_num, n); + return; + case V_COM: + vres->v_com = c_scale(v1->v_com, n); + return; + case V_MAT: + vres->v_mat = matscale(v1->v_mat, n); + return; + case V_OBJ: + *vres = objcall(OBJ_SCALE, v1, v2, NULL_VALUE); + return; + default: + *vres = error_value(E_SCALE_1); + return; + } } @@ -1864,161 +1864,161 @@ scalevalue(VALUE *v1, VALUE *v2, VALUE *vres) void powvalue(VALUE *v1, VALUE *v2, VALUE *vres) { - NUMBER *real_v2; /* real part of v2 */ - COMPLEX *c; + NUMBER *real_v2; /* real part of v2 */ + COMPLEX *c; - if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) { - *vres = objcall(OBJ_POW, v1, v2, NULL_VALUE); - return; - } - vres->v_type = v1->v_type; - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type <= 0 && v1->v_type != -E_DIVBYZERO) - return; - if (v2->v_type <= 0) { - vres->v_type = v2->v_type; - return; - } - real_v2 = v2->v_num; + if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) { + *vres = objcall(OBJ_POW, v1, v2, NULL_VALUE); + return; + } + vres->v_type = v1->v_type; + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type <= 0 && v1->v_type != -E_DIVBYZERO) + return; + if (v2->v_type <= 0) { + vres->v_type = v2->v_type; + return; + } + real_v2 = v2->v_num; - /* case: raising to a real power */ - switch (v2->v_type) { - case V_NUM: + /* case: raising to a real power */ + switch (v2->v_type) { + case V_NUM: - /* deal with the division by 0 value */ - if (v1->v_type == -E_DIVBYZERO) { - if (qisneg(real_v2)) { - vres->v_type = V_NUM; - vres->v_num = qlink(&_qzero_); - } else { - vres->v_type = -E_DIVBYZERO; - } - break; - } + /* deal with the division by 0 value */ + if (v1->v_type == -E_DIVBYZERO) { + if (qisneg(real_v2)) { + vres->v_type = V_NUM; + vres->v_num = qlink(&_qzero_); + } else { + vres->v_type = -E_DIVBYZERO; + } + break; + } - /* raise something with a real exponent */ - switch (v1->v_type) { - case V_NUM: - if (qiszero(v1->v_num)) { - if (qisneg(real_v2)) { - *vres = error_value(E_DIVBYZERO); - break; - } - vres->v_type = V_NUM; - if (qiszero(v2->v_num)) { - /* 0 ^ 0 is 1 */ - vres->v_num = qlink(&_qone_); - } else { - /* 0 ^ (exp>0) is 0 */ - vres->v_num = qlink(&_qzero_); - } - } else if (qisint(real_v2)) { - vres->v_num = qpowi(v1->v_num, real_v2); - } else { - vres->v_type = V_NUM; - vres->v_num = qlink(&_qzero_); - powervalue(v1, v2, NULL, vres); - } - break; - case V_COM: - if (qisint(real_v2)) { - vres->v_com = c_powi(v1->v_com, real_v2); - } else { - vres->v_type = V_NUM; - vres->v_num = qlink(&_qzero_); - powervalue(v1, v2, NULL, vres); - } - if (vres->v_type == V_COM) { - c = vres->v_com; - if (!cisreal(c)) - break; - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - } - break; - case V_MAT: - vres->v_mat = matpowi(v1->v_mat, real_v2); - break; - default: - *vres = error_value(E_POWI_1); - break; - } - break; + /* raise something with a real exponent */ + switch (v1->v_type) { + case V_NUM: + if (qiszero(v1->v_num)) { + if (qisneg(real_v2)) { + *vres = error_value(E_DIVBYZERO); + break; + } + vres->v_type = V_NUM; + if (qiszero(v2->v_num)) { + /* 0 ^ 0 is 1 */ + vres->v_num = qlink(&_qone_); + } else { + /* 0 ^ (exp>0) is 0 */ + vres->v_num = qlink(&_qzero_); + } + } else if (qisint(real_v2)) { + vres->v_num = qpowi(v1->v_num, real_v2); + } else { + vres->v_type = V_NUM; + vres->v_num = qlink(&_qzero_); + powervalue(v1, v2, NULL, vres); + } + break; + case V_COM: + if (qisint(real_v2)) { + vres->v_com = c_powi(v1->v_com, real_v2); + } else { + vres->v_type = V_NUM; + vres->v_num = qlink(&_qzero_); + powervalue(v1, v2, NULL, vres); + } + if (vres->v_type == V_COM) { + c = vres->v_com; + if (!cisreal(c)) + break; + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + } + break; + case V_MAT: + vres->v_mat = matpowi(v1->v_mat, real_v2); + break; + default: + *vres = error_value(E_POWI_1); + break; + } + break; - case V_COM: + case V_COM: - /* deal with the division by 0 value */ - if (v1->v_type == -E_DIVBYZERO) { - if (cisreal(v2->v_com) && qisneg(real_v2)) { - vres->v_type = V_NUM; - vres->v_num = qlink(&_qzero_); - } else { - vres->v_type = -E_DIVBYZERO; - } - break; - } + /* deal with the division by 0 value */ + if (v1->v_type == -E_DIVBYZERO) { + if (cisreal(v2->v_com) && qisneg(real_v2)) { + vres->v_type = V_NUM; + vres->v_num = qlink(&_qzero_); + } else { + vres->v_type = -E_DIVBYZERO; + } + break; + } - /* raise something with a real exponent */ - switch (v1->v_type) { - case V_NUM: - if (qiszero(v1->v_num)) { - if (cisreal(v2->v_com) && qisneg(real_v2)) { - *vres = error_value(E_DIVBYZERO); - break; - } - /* - * 0 ^ real non-neg is zero - * 0 ^ complex is zero - */ - vres->v_type = V_NUM; - vres->v_num = qlink(&_qzero_); - } - if (cisreal(v2->v_com) && qisint(real_v2)) { - vres->v_num = qpowi(v1->v_num, real_v2); - } else { - vres->v_type = V_NUM; - vres->v_num = qlink(&_qzero_); - powervalue(v1, v2, NULL, vres); - } - if (vres->v_type == V_COM) { - c = vres->v_com; - if (!cisreal(c)) - break; - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - } - break; - case V_COM: - if (cisreal(v2->v_com) && qisint(real_v2)) { - vres->v_com = c_powi(v1->v_com, real_v2); - } else { - vres->v_type = V_NUM; - vres->v_num = qlink(&_qzero_); - powervalue(v1, v2, NULL, vres); - } - if (vres->v_type == V_COM) { - c = vres->v_com; - if (!cisreal(c)) - break; - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - } - break; - default: - *vres = error_value(E_POWI_1); - break; - } - break; + /* raise something with a real exponent */ + switch (v1->v_type) { + case V_NUM: + if (qiszero(v1->v_num)) { + if (cisreal(v2->v_com) && qisneg(real_v2)) { + *vres = error_value(E_DIVBYZERO); + break; + } + /* + * 0 ^ real non-neg is zero + * 0 ^ complex is zero + */ + vres->v_type = V_NUM; + vres->v_num = qlink(&_qzero_); + } + if (cisreal(v2->v_com) && qisint(real_v2)) { + vres->v_num = qpowi(v1->v_num, real_v2); + } else { + vres->v_type = V_NUM; + vres->v_num = qlink(&_qzero_); + powervalue(v1, v2, NULL, vres); + } + if (vres->v_type == V_COM) { + c = vres->v_com; + if (!cisreal(c)) + break; + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + } + break; + case V_COM: + if (cisreal(v2->v_com) && qisint(real_v2)) { + vres->v_com = c_powi(v1->v_com, real_v2); + } else { + vres->v_type = V_NUM; + vres->v_num = qlink(&_qzero_); + powervalue(v1, v2, NULL, vres); + } + if (vres->v_type == V_COM) { + c = vres->v_com; + if (!cisreal(c)) + break; + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + } + break; + default: + *vres = error_value(E_POWI_1); + break; + } + break; - /* unsupported exponent type */ - default: - *vres = error_value(E_POWI_2); - break; - } - return; + /* unsupported exponent type */ + default: + *vres = error_value(E_POWI_2); + break; + } + return; } @@ -2030,86 +2030,86 @@ powvalue(VALUE *v1, VALUE *v2, VALUE *vres) void powervalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) { - unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ - NUMBER *epsilon; - COMPLEX *c, ctmp1, ctmp2; + unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ + NUMBER *epsilon; + COMPLEX *c, ctmp1, ctmp2; - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type <= 0) { - vres->v_type = v1->v_type; - return; - } - if (v1->v_type != V_NUM && v1->v_type != V_COM) { - *vres = error_value(E_POWER_1); - return; - } - if (v2->v_type != V_NUM && v2->v_type != V_COM) { - *vres = error_value(E_POWER_2); - return; - } + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type <= 0) { + vres->v_type = v1->v_type; + return; + } + if (v1->v_type != V_NUM && v1->v_type != V_COM) { + *vres = error_value(E_POWER_1); + return; + } + if (v2->v_type != V_NUM && v2->v_type != V_COM) { + *vres = error_value(E_POWER_2); + return; + } - /* NULL epsilon means use built-in epsilon value */ - if (v3 == NULL) { - epsilon = conf->epsilon; - } else { - if (v3->v_type != V_NUM || qiszero(v3->v_num)) { - *vres = error_value(E_POWER_3); - return; - } - epsilon = v3->v_num; - } - if (qiszero(epsilon)) { - *vres = error_value(E_POWER_3); - return; - } + /* NULL epsilon means use built-in epsilon value */ + if (v3 == NULL) { + epsilon = conf->epsilon; + } else { + if (v3->v_type != V_NUM || qiszero(v3->v_num)) { + *vres = error_value(E_POWER_3); + return; + } + epsilon = v3->v_num; + } + if (qiszero(epsilon)) { + *vres = error_value(E_POWER_3); + return; + } - twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); - switch (twoval_as_uint) { - case TWOVAL(V_NUM, V_NUM): - if (qisneg(v1->v_num)) { - ctmp1.real = v1->v_num; - ctmp1.imag = &_qzero_; - ctmp1.links = 1; - ctmp2.real = v2->v_num; - ctmp2.imag = &_qzero_; - ctmp2.links = 1; - c = c_power(&ctmp1, &ctmp2, epsilon); - break; - } - vres->v_num = qpower(v1->v_num, v2->v_num, epsilon); - vres->v_type = V_NUM; - if (vres->v_num == NULL) - *vres = error_value(E_POWER_4); - return; - case TWOVAL(V_NUM, V_COM): - ctmp1.real = v1->v_num; - ctmp1.imag = &_qzero_; - ctmp1.links = 1; - c = c_power(&ctmp1, v2->v_com, epsilon); - break; - case TWOVAL(V_COM, V_NUM): - ctmp2.real = v2->v_num; - ctmp2.imag = &_qzero_; - ctmp2.links = 1; - c = c_power(v1->v_com, &ctmp2, epsilon); - break; - case TWOVAL(V_COM, V_COM): - c = c_power(v1->v_com, v2->v_com, epsilon); - break; - default: - *vres = error_value(E_POWER_1); - return; - } - /* - * Here for any complex result. - */ - vres->v_type = V_COM; - vres->v_com = c; - if (cisreal(c)) { - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - } + twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); + switch (twoval_as_uint) { + case TWOVAL(V_NUM, V_NUM): + if (qisneg(v1->v_num)) { + ctmp1.real = v1->v_num; + ctmp1.imag = &_qzero_; + ctmp1.links = 1; + ctmp2.real = v2->v_num; + ctmp2.imag = &_qzero_; + ctmp2.links = 1; + c = c_power(&ctmp1, &ctmp2, epsilon); + break; + } + vres->v_num = qpower(v1->v_num, v2->v_num, epsilon); + vres->v_type = V_NUM; + if (vres->v_num == NULL) + *vres = error_value(E_POWER_4); + return; + case TWOVAL(V_NUM, V_COM): + ctmp1.real = v1->v_num; + ctmp1.imag = &_qzero_; + ctmp1.links = 1; + c = c_power(&ctmp1, v2->v_com, epsilon); + break; + case TWOVAL(V_COM, V_NUM): + ctmp2.real = v2->v_num; + ctmp2.imag = &_qzero_; + ctmp2.links = 1; + c = c_power(v1->v_com, &ctmp2, epsilon); + break; + case TWOVAL(V_COM, V_COM): + c = c_power(v1->v_com, v2->v_com, epsilon); + break; + default: + *vres = error_value(E_POWER_1); + return; + } + /* + * Here for any complex result. + */ + vres->v_type = V_COM; + vres->v_com = c; + if (cisreal(c)) { + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + } } @@ -2120,82 +2120,82 @@ powervalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) void divvalue(VALUE *v1, VALUE *v2, VALUE *vres) { - unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ - COMPLEX *c; - COMPLEX ctmp; - NUMBER *q; - VALUE tmpval; + unsigned int twoval_as_uint; /* TWOVAL(a,b) or TWOVAL_INVALID */ + COMPLEX *c; + COMPLEX ctmp; + NUMBER *q; + VALUE tmpval; - vres->v_type = v1->v_type; - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type <= 0) - return; - if (v2->v_type <= 0) { - if (testvalue(v1) && v2->v_type == -E_DIVBYZERO) { - vres->v_type = V_NUM; - vres->v_num = qlink(&_qzero_); - } - else - vres->v_type = v2->v_type; - return; - } - if (!testvalue(v2)) { - if (testvalue(v1)) - *vres = error_value(E_DIVBYZERO); - else - *vres = error_value(E_ZERODIVZERO); - return; - } - vres->v_type = v1->v_type; - twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); - switch (twoval_as_uint) { - case TWOVAL(V_NUM, V_NUM): - vres->v_num = qqdiv(v1->v_num, v2->v_num); - return; - case TWOVAL(V_COM, V_NUM): - vres->v_com = c_divq(v1->v_com, v2->v_num); - return; - case TWOVAL(V_NUM, V_COM): - if (qiszero(v1->v_num)) { - vres->v_num = qlink(&_qzero_); - return; - } - ctmp.real = v1->v_num; - ctmp.imag = &_qzero_; - ctmp.links = 1; - vres->v_com = c_div(&ctmp, v2->v_com); - vres->v_type = V_COM; - return; - case TWOVAL(V_COM, V_COM): - vres->v_com = c_div(v1->v_com, v2->v_com); - c = vres->v_com; - if (cisreal(c)) { - vres->v_num = qlink(c->real); - vres->v_type = V_NUM; - comfree(c); - } - return; - case TWOVAL(V_MAT, V_NUM): - case TWOVAL(V_MAT, V_COM): - invertvalue(v2, &tmpval); - vres->v_mat = matmulval(v1->v_mat, &tmpval); - freevalue(&tmpval); - return; - case TWOVAL(V_STR, V_NUM): - q = qinv(v2->v_num); - vres->v_str = stringmul(q, v1->v_str); - qfree(q); - if (vres->v_str == NULL) - *vres = error_value(E_DIV); - return; - default: - if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { - *vres = error_value(E_DIV); - return; - } - *vres = objcall(OBJ_DIV, v1, v2, NULL_VALUE); - return; - } + vres->v_type = v1->v_type; + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type <= 0) + return; + if (v2->v_type <= 0) { + if (testvalue(v1) && v2->v_type == -E_DIVBYZERO) { + vres->v_type = V_NUM; + vres->v_num = qlink(&_qzero_); + } + else + vres->v_type = v2->v_type; + return; + } + if (!testvalue(v2)) { + if (testvalue(v1)) + *vres = error_value(E_DIVBYZERO); + else + *vres = error_value(E_ZERODIVZERO); + return; + } + vres->v_type = v1->v_type; + twoval_as_uint = TWOVAL_AS_UINT(v1->v_type, v2->v_type); + switch (twoval_as_uint) { + case TWOVAL(V_NUM, V_NUM): + vres->v_num = qqdiv(v1->v_num, v2->v_num); + return; + case TWOVAL(V_COM, V_NUM): + vres->v_com = c_divq(v1->v_com, v2->v_num); + return; + case TWOVAL(V_NUM, V_COM): + if (qiszero(v1->v_num)) { + vres->v_num = qlink(&_qzero_); + return; + } + ctmp.real = v1->v_num; + ctmp.imag = &_qzero_; + ctmp.links = 1; + vres->v_com = c_div(&ctmp, v2->v_com); + vres->v_type = V_COM; + return; + case TWOVAL(V_COM, V_COM): + vres->v_com = c_div(v1->v_com, v2->v_com); + c = vres->v_com; + if (cisreal(c)) { + vres->v_num = qlink(c->real); + vres->v_type = V_NUM; + comfree(c); + } + return; + case TWOVAL(V_MAT, V_NUM): + case TWOVAL(V_MAT, V_COM): + invertvalue(v2, &tmpval); + vres->v_mat = matmulval(v1->v_mat, &tmpval); + freevalue(&tmpval); + return; + case TWOVAL(V_STR, V_NUM): + q = qinv(v2->v_num); + vres->v_str = stringmul(q, v1->v_str); + qfree(q); + if (vres->v_str == NULL) + *vres = error_value(E_DIV); + return; + default: + if ((v1->v_type != V_OBJ) && (v2->v_type != V_OBJ)) { + *vres = error_value(E_DIV); + return; + } + *vres = objcall(OBJ_DIV, v1, v2, NULL_VALUE); + return; + } } @@ -2206,75 +2206,75 @@ divvalue(VALUE *v1, VALUE *v2, VALUE *vres) void quovalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) { - COMPLEX *c; - NUMBER *q1, *q2; - long rnd; + COMPLEX *c; + NUMBER *q1, *q2; + long rnd; - vres->v_type = v1->v_type; - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type <= 0) - return; + vres->v_type = v1->v_type; + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type <= 0) + return; - if (v1->v_type == V_MAT) { - vres->v_mat = matquoval(v1->v_mat, v2, v3); - return; - } - if (v1->v_type == V_LIST) { - vres->v_list = listquo(v1->v_list, v2, v3); - return; - } - if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) { - *vres = objcall(OBJ_QUO, v1, v2, v3); - return; - } - if (v2->v_type <= 0) { - vres->v_type = v2->v_type; - return; - } - if (v2->v_type != V_NUM) { - *vres = error_value(E_QUO_2); - return; - } - rnd = 0; - switch (v3->v_type) { - case V_NUM: - if (qisfrac(v3->v_num)) { - *vres = error_value(E_QUO_3); - return; - } - rnd = qtoi(v3->v_num); - break; - case V_NULL: - rnd = conf->quo; - break; - default: - *vres = error_value(E_QUO_3); - return; - } - switch (v1->v_type) { - case V_NUM: - vres->v_num = qquo(v1->v_num, v2->v_num, rnd); - return; - case V_COM: - q1 = qquo(v1->v_com->real, v2->v_num, rnd); - q2 = qquo(v1->v_com->imag, v2->v_num, rnd); - if (qiszero(q2)) { - qfree(q2); - vres->v_type = V_NUM; - vres->v_num = q1; - return; - } - c = comalloc(); - qfree(c->real); - qfree(c->imag); - c->real = q1; - c->imag = q2; - vres->v_com = c; - return; - default: - *vres = error_value(E_QUO_1); - return; - } + if (v1->v_type == V_MAT) { + vres->v_mat = matquoval(v1->v_mat, v2, v3); + return; + } + if (v1->v_type == V_LIST) { + vres->v_list = listquo(v1->v_list, v2, v3); + return; + } + if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) { + *vres = objcall(OBJ_QUO, v1, v2, v3); + return; + } + if (v2->v_type <= 0) { + vres->v_type = v2->v_type; + return; + } + if (v2->v_type != V_NUM) { + *vres = error_value(E_QUO_2); + return; + } + rnd = 0; + switch (v3->v_type) { + case V_NUM: + if (qisfrac(v3->v_num)) { + *vres = error_value(E_QUO_3); + return; + } + rnd = qtoi(v3->v_num); + break; + case V_NULL: + rnd = conf->quo; + break; + default: + *vres = error_value(E_QUO_3); + return; + } + switch (v1->v_type) { + case V_NUM: + vres->v_num = qquo(v1->v_num, v2->v_num, rnd); + return; + case V_COM: + q1 = qquo(v1->v_com->real, v2->v_num, rnd); + q2 = qquo(v1->v_com->imag, v2->v_num, rnd); + if (qiszero(q2)) { + qfree(q2); + vres->v_type = V_NUM; + vres->v_num = q1; + return; + } + c = comalloc(); + qfree(c->real); + qfree(c->imag); + c->real = q1; + c->imag = q2; + vres->v_com = c; + return; + default: + *vres = error_value(E_QUO_1); + return; + } } @@ -2285,75 +2285,75 @@ quovalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) void modvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) { - COMPLEX *c; - NUMBER *q1, *q2; - long rnd; + COMPLEX *c; + NUMBER *q1, *q2; + long rnd; - vres->v_type = v1->v_type; - vres->v_subtype = V_NOSUBTYPE; - if (v1->v_type <= 0) - return; + vres->v_type = v1->v_type; + vres->v_subtype = V_NOSUBTYPE; + if (v1->v_type <= 0) + return; - if (v1->v_type == V_MAT) { - vres->v_mat = matmodval(v1->v_mat, v2, v3); - return; - } - if (v1->v_type == V_LIST) { - vres->v_list = listmod(v1->v_list, v2, v3); - return; - } - if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) { - *vres = objcall(OBJ_MOD, v1, v2, v3); - return; - } - if (v2->v_type <= 0) { - vres->v_type = v2->v_type; - return; - } - if (v2->v_type != V_NUM) { - *vres = error_value(E_MOD_2); - return; - } - rnd = 0; - switch (v3->v_type) { - case V_NUM: - if (qisfrac(v3->v_num)) { - *vres = error_value(E_MOD_3); - return; - } - rnd = qtoi(v3->v_num); - break; - case V_NULL: - rnd = conf->mod; - break; - default: - *vres = error_value(E_MOD_3); - return; - } - switch (v1->v_type) { - case V_NUM: - vres->v_num = qmod(v1->v_num, v2->v_num, rnd); - return; - case V_COM: - q1 = qmod(v1->v_com->real, v2->v_num, rnd); - q2 = qmod(v1->v_com->imag, v2->v_num, rnd); - if (qiszero(q2)) { - qfree(q2); - vres->v_type = V_NUM; - vres->v_num = q1; - return; - } - c = comalloc(); - qfree(c->real); - qfree(c->imag); - c->real = q1; - c->imag = q2; - vres->v_com = c; - return; - default: - *vres = error_value(E_MOD_1); - return; - } + if (v1->v_type == V_MAT) { + vres->v_mat = matmodval(v1->v_mat, v2, v3); + return; + } + if (v1->v_type == V_LIST) { + vres->v_list = listmod(v1->v_list, v2, v3); + return; + } + if (v1->v_type == V_OBJ || v2->v_type == V_OBJ) { + *vres = objcall(OBJ_MOD, v1, v2, v3); + return; + } + if (v2->v_type <= 0) { + vres->v_type = v2->v_type; + return; + } + if (v2->v_type != V_NUM) { + *vres = error_value(E_MOD_2); + return; + } + rnd = 0; + switch (v3->v_type) { + case V_NUM: + if (qisfrac(v3->v_num)) { + *vres = error_value(E_MOD_3); + return; + } + rnd = qtoi(v3->v_num); + break; + case V_NULL: + rnd = conf->mod; + break; + default: + *vres = error_value(E_MOD_3); + return; + } + switch (v1->v_type) { + case V_NUM: + vres->v_num = qmod(v1->v_num, v2->v_num, rnd); + return; + case V_COM: + q1 = qmod(v1->v_com->real, v2->v_num, rnd); + q2 = qmod(v1->v_com->imag, v2->v_num, rnd); + if (qiszero(q2)) { + qfree(q2); + vres->v_type = V_NUM; + vres->v_num = q1; + return; + } + c = comalloc(); + qfree(c->real); + qfree(c->imag); + c->real = q1; + c->imag = q2; + vres->v_com = c; + return; + default: + *vres = error_value(E_MOD_1); + return; + } } @@ -2366,56 +2366,56 @@ modvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres) bool testvalue(VALUE *vp) { - VALUE val; - LISTELEM *ep; - int i; + VALUE val; + LISTELEM *ep; + int i; - switch (vp->v_type) { - case V_NUM: - return !qiszero(vp->v_num); - case V_COM: - return !ciszero(vp->v_com); - case V_STR: - return stringtest(vp->v_str); - case V_MAT: - return mattest(vp->v_mat); - case V_LIST: - for (ep = vp->v_list->l_first; ep; ep = ep->e_next) { - if (testvalue(&ep->e_value)) - return true; - } - return false; - case V_ASSOC: - return (vp->v_assoc->a_count != 0); - case V_FILE: - return validid(vp->v_file); - case V_NULL: - break; - case V_OBJ: - val = objcall(OBJ_TEST, vp, NULL_VALUE, NULL_VALUE); - return (val.v_int != 0); - case V_BLOCK: - for (i=0; i < vp->v_block->datalen; ++i) { - if (vp->v_block->data[i]) { - return true; - } - } - return false; - case V_OCTET: - return (*vp->v_octet != 0); - case V_NBLOCK: - if (vp->v_nblock->blk->data == NULL) - return false; - for (i=0; i < vp->v_nblock->blk->datalen; ++i) { - if (vp->v_nblock->blk->data[i]) { - return true; - } - } - return false; - default: - return true; - } - return false; + switch (vp->v_type) { + case V_NUM: + return !qiszero(vp->v_num); + case V_COM: + return !ciszero(vp->v_com); + case V_STR: + return stringtest(vp->v_str); + case V_MAT: + return mattest(vp->v_mat); + case V_LIST: + for (ep = vp->v_list->l_first; ep; ep = ep->e_next) { + if (testvalue(&ep->e_value)) + return true; + } + return false; + case V_ASSOC: + return (vp->v_assoc->a_count != 0); + case V_FILE: + return validid(vp->v_file); + case V_NULL: + break; + case V_OBJ: + val = objcall(OBJ_TEST, vp, NULL_VALUE, NULL_VALUE); + return (val.v_int != 0); + case V_BLOCK: + for (i=0; i < vp->v_block->datalen; ++i) { + if (vp->v_block->data[i]) { + return true; + } + } + return false; + case V_OCTET: + return (*vp->v_octet != 0); + case V_NBLOCK: + if (vp->v_nblock->blk->data == NULL) + return false; + for (i=0; i < vp->v_nblock->blk->datalen; ++i) { + if (vp->v_nblock->blk->data[i]) { + return true; + } + } + return false; + default: + return true; + } + return false; } @@ -2426,166 +2426,166 @@ testvalue(VALUE *vp) bool comparevalue(VALUE *v1, VALUE *v2) { - int r = false; - VALUE val; + int r = false; + VALUE val; - if ((v1->v_type == V_OBJ) || (v2->v_type == V_OBJ)) { - val = objcall(OBJ_CMP, v1, v2, NULL_VALUE); - return (val.v_int != 0); - } - if (v1 == v2) - return false; - if (v1->v_type == V_OCTET) { - if (v2->v_type == V_OCTET) - return (*v1->v_octet != *v2->v_octet); - if (v2->v_type == V_STR) - return (*v1->v_octet != (OCTET) *v2->v_str->s_str) - || (v2->v_str->s_len != 1); - if (v2->v_type != V_NUM || qisfrac(v2->v_num) || - qisneg(v2->v_num) || v2->v_num->num.len > 1) - return true; - return (*v2->v_num->num.v != *v1->v_octet); - } - if (v2->v_type == V_OCTET) - return comparevalue(v2, v1); - if (v1->v_type != v2->v_type) - return true; - if (v1->v_type <= 0) - return false; - switch (v1->v_type) { - case V_NUM: - r = qcmp(v1->v_num, v2->v_num); - break; - case V_COM: - r = c_cmp(v1->v_com, v2->v_com); - break; - case V_STR: - r = stringcmp(v1->v_str, v2->v_str); - break; - case V_MAT: - r = matcmp(v1->v_mat, v2->v_mat); - break; - case V_LIST: - r = listcmp(v1->v_list, v2->v_list); - break; - case V_ASSOC: - r = assoccmp(v1->v_assoc, v2->v_assoc); - break; - case V_FILE: - r = (v1->v_file != v2->v_file); - break; - case V_RAND: - r = randcmp(v1->v_rand, v2->v_rand); - break; - case V_RANDOM: - r = randomcmp(v1->v_random, v2->v_random); - break; - case V_CONFIG: - r = config_cmp(v1->v_config, v2->v_config); - break; - case V_HASH: - r = hash_cmp(v1->v_hash, v2->v_hash); - break; - case V_BLOCK: - r = blk_cmp(v1->v_block, v2->v_block); - break; - case V_OCTET: - r = (v1->v_octet != v2->v_octet); - break; - case V_NBLOCK: - return (v1->v_nblock != v2->v_nblock); - case V_VPTR: - return (v1->v_addr != v2->v_addr); - case V_OPTR: - return (v1->v_octet != v2->v_octet); - case V_SPTR: - return (v1->v_str != v2->v_str); - case V_NPTR: - return (v1->v_num != v2->v_num); - default: - math_error("Illegal values for comparevalue"); - not_reached(); - } - return (r != 0); + if ((v1->v_type == V_OBJ) || (v2->v_type == V_OBJ)) { + val = objcall(OBJ_CMP, v1, v2, NULL_VALUE); + return (val.v_int != 0); + } + if (v1 == v2) + return false; + if (v1->v_type == V_OCTET) { + if (v2->v_type == V_OCTET) + return (*v1->v_octet != *v2->v_octet); + if (v2->v_type == V_STR) + return (*v1->v_octet != (OCTET) *v2->v_str->s_str) + || (v2->v_str->s_len != 1); + if (v2->v_type != V_NUM || qisfrac(v2->v_num) || + qisneg(v2->v_num) || v2->v_num->num.len > 1) + return true; + return (*v2->v_num->num.v != *v1->v_octet); + } + if (v2->v_type == V_OCTET) + return comparevalue(v2, v1); + if (v1->v_type != v2->v_type) + return true; + if (v1->v_type <= 0) + return false; + switch (v1->v_type) { + case V_NUM: + r = qcmp(v1->v_num, v2->v_num); + break; + case V_COM: + r = c_cmp(v1->v_com, v2->v_com); + break; + case V_STR: + r = stringcmp(v1->v_str, v2->v_str); + break; + case V_MAT: + r = matcmp(v1->v_mat, v2->v_mat); + break; + case V_LIST: + r = listcmp(v1->v_list, v2->v_list); + break; + case V_ASSOC: + r = assoccmp(v1->v_assoc, v2->v_assoc); + break; + case V_FILE: + r = (v1->v_file != v2->v_file); + break; + case V_RAND: + r = randcmp(v1->v_rand, v2->v_rand); + break; + case V_RANDOM: + r = randomcmp(v1->v_random, v2->v_random); + break; + case V_CONFIG: + r = config_cmp(v1->v_config, v2->v_config); + break; + case V_HASH: + r = hash_cmp(v1->v_hash, v2->v_hash); + break; + case V_BLOCK: + r = blk_cmp(v1->v_block, v2->v_block); + break; + case V_OCTET: + r = (v1->v_octet != v2->v_octet); + break; + case V_NBLOCK: + return (v1->v_nblock != v2->v_nblock); + case V_VPTR: + return (v1->v_addr != v2->v_addr); + case V_OPTR: + return (v1->v_octet != v2->v_octet); + case V_SPTR: + return (v1->v_str != v2->v_str); + case V_NPTR: + return (v1->v_num != v2->v_num); + default: + math_error("Illegal values for comparevalue"); + not_reached(); + } + return (r != 0); } bool acceptvalue(VALUE *v1, VALUE *v2) { - long index; - FUNC *fp; - bool ret; + long index; + FUNC *fp; + bool ret; - index = adduserfunc("accept"); - fp = findfunc(index); - if (fp) { - ++stack; - stack->v_type = V_ADDR; - stack->v_subtype = V_NOSUBTYPE; - stack->v_addr = v1; - ++stack; - stack->v_type = V_ADDR; - stack->v_subtype = V_NOSUBTYPE; - stack->v_addr = v2; - calculate(fp, 2); - ret = testvalue(stack); - freevalue(stack--); - return ret; - } - return (!comparevalue(v1, v2)); + index = adduserfunc("accept"); + fp = findfunc(index); + if (fp) { + ++stack; + stack->v_type = V_ADDR; + stack->v_subtype = V_NOSUBTYPE; + stack->v_addr = v1; + ++stack; + stack->v_type = V_ADDR; + stack->v_subtype = V_NOSUBTYPE; + stack->v_addr = v2; + calculate(fp, 2); + ret = testvalue(stack); + freevalue(stack--); + return ret; + } + return (!comparevalue(v1, v2)); } bool precvalue(VALUE *v1, VALUE *v2) { - VALUE val; - long index; - int r = 0; - FUNC *fp; - bool ret; + VALUE val; + long index; + int r = 0; + FUNC *fp; + bool ret; - index = adduserfunc("precedes"); - fp = findfunc(index); - if (fp) { - ++stack; - stack->v_type = V_ADDR; - stack->v_subtype = V_NOSUBTYPE; - stack->v_addr = v1; - ++stack; - stack->v_type = V_ADDR; - stack->v_subtype = V_NOSUBTYPE; - stack->v_addr = v2; - calculate(fp, 2); - ret = testvalue(stack); - freevalue(stack--); - return ret; - } - relvalue(v1, v2, &val); - if ((val.v_type == V_NUM && qisneg(val.v_num)) || - (val.v_type == V_COM && qisneg(val.v_com->imag))) - r = 1; - if (val.v_type == V_NULL) - r = (v1->v_type < v2->v_type); - freevalue(&val); - return r; + index = adduserfunc("precedes"); + fp = findfunc(index); + if (fp) { + ++stack; + stack->v_type = V_ADDR; + stack->v_subtype = V_NOSUBTYPE; + stack->v_addr = v1; + ++stack; + stack->v_type = V_ADDR; + stack->v_subtype = V_NOSUBTYPE; + stack->v_addr = v2; + calculate(fp, 2); + ret = testvalue(stack); + freevalue(stack--); + return ret; + } + relvalue(v1, v2, &val); + if ((val.v_type == V_NUM && qisneg(val.v_num)) || + (val.v_type == V_COM && qisneg(val.v_com->imag))) + r = 1; + if (val.v_type == V_NULL) + r = (v1->v_type < v2->v_type); + freevalue(&val); + return r; } VALUE signval(int r) { - VALUE val; + VALUE val; - val.v_type = V_NUM; - val.v_subtype = V_NOSUBTYPE; - if (r > 0) - val.v_num = qlink(&_qone_); - else if (r < 0) - val.v_num = qlink(&_qnegone_); - else - val.v_num = qlink(&_qzero_); - return val; + val.v_type = V_NUM; + val.v_subtype = V_NOSUBTYPE; + if (r > 0) + val.v_num = qlink(&_qone_); + else if (r < 0) + val.v_num = qlink(&_qnegone_); + else + val.v_num = qlink(&_qzero_); + return val; } @@ -2596,131 +2596,131 @@ signval(int r) void relvalue(VALUE *v1, VALUE *v2, VALUE *vres) { - int r = 0; - int i = 0; - NUMBER *q; - COMPLEX *c; + int r = 0; + int i = 0; + NUMBER *q; + COMPLEX *c; - vres->v_subtype = V_NOSUBTYPE; - vres->v_type = V_NULL; - if ((v1->v_type == V_OBJ) || (v2->v_type == V_OBJ)) { - *vres = objcall(OBJ_REL, v1, v2, NULL_VALUE); - return; - } - switch(v1->v_type) { - case V_NUM: - switch(v2->v_type) { - case V_NUM: - r = qrel(v1->v_num, v2->v_num); - break; - case V_OCTET: - q = itoq((long) *v2->v_octet); - r = qrel(v1->v_num, q); - qfree(q); - break; - case V_COM: - r = qrel(v1->v_num, v2->v_com->real); - i = qrel(&_qzero_, v2->v_com->imag); - break; - default: - return; - } - break; - case V_COM: - switch(v2->v_type) { - case V_NUM: - r = qrel(v1->v_com->real, v2->v_num); - i = qrel(v1->v_com->imag, &_qzero_); - break; - case V_COM: - r = qrel(v1->v_com->real, v2->v_com->real); - i = qrel(v1->v_com->imag, v2->v_com->imag); - break; - case V_OCTET: - q = itoq((long) *v2->v_octet); - r = qrel(v1->v_com->real, q); - qfree(q); - i = qrel(v1->v_com->imag, &_qzero_); - break; - default: - return; - } - break; - case V_STR: - switch(v2->v_type) { - case V_STR: - r = stringrel(v1->v_str, v2->v_str); - break; - case V_OCTET: - r = (unsigned char) *v1->v_str->s_str - - *v2->v_octet; - if (r == 0) { - if (v1->v_str->s_len == 0) - r = -1; - else - r = (v1->v_str->s_len > 1); - } - break; - default: - return; - } - break; - case V_OCTET: - switch(v2->v_type) { - case V_NUM: - q = itoq((long) *v1->v_octet); - r = qrel(q, v2->v_num); - qfree(q); - break; - case V_COM: - q = itoq((long) *v1->v_octet); - r = qrel(q, v2->v_com->real); - qfree(q); - i = qrel(&_qzero_, v2->v_com->imag); - break; - case V_OCTET: - r = *v1->v_octet - *v2->v_octet; - break; - case V_STR: - r = *v1->v_octet - - (unsigned char) *v2->v_str->s_str; - if (r == 0) { - if (v2->v_str->s_len == 0) - r = 1; - else - r = -(v2->v_str->s_len > 1); - } - break; - default: - return; - } - break; - case V_VPTR: - if (v2->v_type != V_VPTR) - return; - r = (v1->v_addr - v2->v_addr); - break; - case V_OPTR: - if (v2->v_type != V_OPTR) - return; - r = (v1->v_octet - v2->v_octet); - break; - default: - return; - } - vres->v_type = V_NUM; - *vres = signval(r); - if (i == 0) - return; - c = comalloc(); - qfree(c->real); - c->real = vres->v_num; - *vres = signval(i); - qfree(c->imag); - c->imag = vres->v_num; - vres->v_type = V_COM; - vres->v_com = c; - return; + vres->v_subtype = V_NOSUBTYPE; + vres->v_type = V_NULL; + if ((v1->v_type == V_OBJ) || (v2->v_type == V_OBJ)) { + *vres = objcall(OBJ_REL, v1, v2, NULL_VALUE); + return; + } + switch(v1->v_type) { + case V_NUM: + switch(v2->v_type) { + case V_NUM: + r = qrel(v1->v_num, v2->v_num); + break; + case V_OCTET: + q = itoq((long) *v2->v_octet); + r = qrel(v1->v_num, q); + qfree(q); + break; + case V_COM: + r = qrel(v1->v_num, v2->v_com->real); + i = qrel(&_qzero_, v2->v_com->imag); + break; + default: + return; + } + break; + case V_COM: + switch(v2->v_type) { + case V_NUM: + r = qrel(v1->v_com->real, v2->v_num); + i = qrel(v1->v_com->imag, &_qzero_); + break; + case V_COM: + r = qrel(v1->v_com->real, v2->v_com->real); + i = qrel(v1->v_com->imag, v2->v_com->imag); + break; + case V_OCTET: + q = itoq((long) *v2->v_octet); + r = qrel(v1->v_com->real, q); + qfree(q); + i = qrel(v1->v_com->imag, &_qzero_); + break; + default: + return; + } + break; + case V_STR: + switch(v2->v_type) { + case V_STR: + r = stringrel(v1->v_str, v2->v_str); + break; + case V_OCTET: + r = (unsigned char) *v1->v_str->s_str + - *v2->v_octet; + if (r == 0) { + if (v1->v_str->s_len == 0) + r = -1; + else + r = (v1->v_str->s_len > 1); + } + break; + default: + return; + } + break; + case V_OCTET: + switch(v2->v_type) { + case V_NUM: + q = itoq((long) *v1->v_octet); + r = qrel(q, v2->v_num); + qfree(q); + break; + case V_COM: + q = itoq((long) *v1->v_octet); + r = qrel(q, v2->v_com->real); + qfree(q); + i = qrel(&_qzero_, v2->v_com->imag); + break; + case V_OCTET: + r = *v1->v_octet - *v2->v_octet; + break; + case V_STR: + r = *v1->v_octet - + (unsigned char) *v2->v_str->s_str; + if (r == 0) { + if (v2->v_str->s_len == 0) + r = 1; + else + r = -(v2->v_str->s_len > 1); + } + break; + default: + return; + } + break; + case V_VPTR: + if (v2->v_type != V_VPTR) + return; + r = (v1->v_addr - v2->v_addr); + break; + case V_OPTR: + if (v2->v_type != V_OPTR) + return; + r = (v1->v_octet - v2->v_octet); + break; + default: + return; + } + vres->v_type = V_NUM; + *vres = signval(r); + if (i == 0) + return; + c = comalloc(); + qfree(c->real); + c->real = vres->v_num; + *vres = signval(i); + qfree(c->imag); + c->imag = vres->v_num; + vres->v_type = V_COM; + vres->v_com = c; + return; } @@ -2731,182 +2731,182 @@ relvalue(VALUE *v1, VALUE *v2, VALUE *vres) void sgnvalue(VALUE *vp, VALUE *vres) { - COMPLEX *c; + COMPLEX *c; - vres->v_type = vp->v_type; - switch (vp->v_type) { - case V_NUM: - vres->v_num = qsign(vp->v_num); - vres->v_subtype = vp->v_subtype; - return; - case V_COM: - c = comalloc(); - qfree(c->real); - qfree(c->imag); - c->real = qsign(vp->v_com->real); - c->imag = qsign(vp->v_com->imag); - vres->v_com = c; - vres->v_type = V_COM; - vres->v_subtype = V_NOSUBTYPE; - return; - case V_OCTET: - vres->v_type = V_NUM; - vres->v_subtype = V_NOSUBTYPE; - vres->v_num = itoq((long) (*vp->v_octet != 0)); - return; - case V_OBJ: - *vres = objcall(OBJ_SGN, vp, NULL_VALUE, NULL_VALUE); - return; - default: - if (vp->v_type > 0) - *vres = error_value(E_SGN); - return; - } + vres->v_type = vp->v_type; + switch (vp->v_type) { + case V_NUM: + vres->v_num = qsign(vp->v_num); + vres->v_subtype = vp->v_subtype; + return; + case V_COM: + c = comalloc(); + qfree(c->real); + qfree(c->imag); + c->real = qsign(vp->v_com->real); + c->imag = qsign(vp->v_com->imag); + vres->v_com = c; + vres->v_type = V_COM; + vres->v_subtype = V_NOSUBTYPE; + return; + case V_OCTET: + vres->v_type = V_NUM; + vres->v_subtype = V_NOSUBTYPE; + vres->v_num = itoq((long) (*vp->v_octet != 0)); + return; + case V_OBJ: + *vres = objcall(OBJ_SGN, vp, NULL_VALUE, NULL_VALUE); + return; + default: + if (vp->v_type > 0) + *vres = error_value(E_SGN); + return; + } } int userfunc(char *fname, VALUE *vp) { - FUNC *fp; + FUNC *fp; - fp = findfunc(adduserfunc(fname)); - if (fp == NULL) - return 0; - ++stack; - stack->v_addr = vp; - stack->v_type = V_ADDR; - stack->v_subtype = V_NOSUBTYPE; - calculate(fp, 1); - freevalue(stack--); - return 1; + fp = findfunc(adduserfunc(fname)); + if (fp == NULL) + return 0; + ++stack; + stack->v_addr = vp; + stack->v_type = V_ADDR; + stack->v_subtype = V_NOSUBTYPE; + calculate(fp, 1); + freevalue(stack--); + return 1; } /* * Print the value of a descriptor in one of several formats. * If flags contains PRINT_SHORT, then elements of arrays and lists - * will not be printed. If flags contains PRINT_UNAMBIG, then quotes + * will not be printed. If flags contains PRINT_UNAMBIG, then quotes * are placed around strings and the null value is explicitly printed. */ void printvalue(VALUE *vp, int flags) { - NUMBER *qtemp; - int type; - char *errsym; - bool alloced; + NUMBER *qtemp; + int type; + char *errsym; + bool alloced; - type = vp->v_type; - if (type < 0) { - if (userfunc("error_print", vp)) { - return; - } - errsym = errnum_2_errsym(-type, &alloced); - if (errsym == NULL) { - if (-type >= E__BASE) { - math_fmt("Error %d", -type); - } else { - math_fmt("System error %d", -type); - } - } else { - if (-type >= E__BASE) { - math_fmt("Error %s", errsym); - } else { - math_fmt("System error %s", errsym); - } - if (alloced == true) { - free(errsym); - } - } - return; - } - switch (type) { - case V_NUM: - qprintnum(vp->v_num, MODE_DEFAULT, conf->outdigits); - if (conf->traceflags & TRACE_LINKS) - math_fmt("#%ld", vp->v_num->links); - break; - case V_COM: - comprint(vp->v_com); - if (conf->traceflags & TRACE_LINKS) - math_fmt("##%ld", vp->v_com->links); - break; - case V_STR: - if (flags & PRINT_UNAMBIG) - math_chr('\"'); - math_str(vp->v_str->s_str); - if (flags & PRINT_UNAMBIG) - math_chr('\"'); - break; - case V_NULL: - if (flags & PRINT_UNAMBIG) - math_str("NULL"); - break; - case V_OBJ: - (void) objcall(OBJ_PRINT, vp, NULL_VALUE, NULL_VALUE); - break; - case V_LIST: - if (!userfunc("list_print", vp)) - listprint(vp->v_list, - ((flags & PRINT_SHORT) ? 0L : conf->maxprint)); - break; - case V_ASSOC: - assocprint(vp->v_assoc, - ((flags & PRINT_SHORT) ? 0L : conf->maxprint)); - break; - case V_MAT: - if (!userfunc("mat_print", vp)) - matprint(vp->v_mat, - ((flags & PRINT_SHORT) ? 0L : conf->maxprint)); - break; - case V_FILE: - if (!userfunc("file_print", vp)) - printid(vp->v_file, flags); - break; - case V_RAND: - randprint(vp->v_rand, flags); - break; - case V_RANDOM: - randomprint(vp->v_random, flags); - break; - case V_CONFIG: - config_print(vp->v_config); - break; - case V_HASH: - hash_print(vp->v_hash); - break; - case V_BLOCK: - if (!userfunc("blk_print", vp)) - blk_print(vp->v_block); - break; - case V_OCTET: - if (userfunc("octet_print", vp)) - break; - qtemp = itoq((long) *vp->v_octet); - qprintnum(qtemp, MODE_DEFAULT, conf->outdigits); - qfree(qtemp); - break; - case V_OPTR: - math_fmt("o-ptr: %p", (void *)vp->v_octet); - break; - case V_VPTR: - math_fmt("v-ptr: %p", (void *)vp->v_addr); - break; - case V_SPTR: - math_fmt("s_ptr: %p", (void *)vp->v_str); - break; - case V_NPTR: - math_fmt("n_ptr: %p", (void *)vp->v_num); - break; - case V_NBLOCK: - if (!userfunc("nblk_print", vp)) - nblock_print(vp->v_nblock); - break; - default: - math_error("Printing unrecognized type of value"); - not_reached(); - } + type = vp->v_type; + if (type < 0) { + if (userfunc("error_print", vp)) { + return; + } + errsym = errnum_2_errsym(-type, &alloced); + if (errsym == NULL) { + if (-type >= E__BASE) { + math_fmt("Error %d", -type); + } else { + math_fmt("System error %d", -type); + } + } else { + if (-type >= E__BASE) { + math_fmt("Error %s", errsym); + } else { + math_fmt("System error %s", errsym); + } + if (alloced == true) { + free(errsym); + } + } + return; + } + switch (type) { + case V_NUM: + qprintnum(vp->v_num, MODE_DEFAULT, conf->outdigits); + if (conf->traceflags & TRACE_LINKS) + math_fmt("#%ld", vp->v_num->links); + break; + case V_COM: + comprint(vp->v_com); + if (conf->traceflags & TRACE_LINKS) + math_fmt("##%ld", vp->v_com->links); + break; + case V_STR: + if (flags & PRINT_UNAMBIG) + math_chr('\"'); + math_str(vp->v_str->s_str); + if (flags & PRINT_UNAMBIG) + math_chr('\"'); + break; + case V_NULL: + if (flags & PRINT_UNAMBIG) + math_str("NULL"); + break; + case V_OBJ: + (void) objcall(OBJ_PRINT, vp, NULL_VALUE, NULL_VALUE); + break; + case V_LIST: + if (!userfunc("list_print", vp)) + listprint(vp->v_list, + ((flags & PRINT_SHORT) ? 0L : conf->maxprint)); + break; + case V_ASSOC: + assocprint(vp->v_assoc, + ((flags & PRINT_SHORT) ? 0L : conf->maxprint)); + break; + case V_MAT: + if (!userfunc("mat_print", vp)) + matprint(vp->v_mat, + ((flags & PRINT_SHORT) ? 0L : conf->maxprint)); + break; + case V_FILE: + if (!userfunc("file_print", vp)) + printid(vp->v_file, flags); + break; + case V_RAND: + randprint(vp->v_rand, flags); + break; + case V_RANDOM: + randomprint(vp->v_random, flags); + break; + case V_CONFIG: + config_print(vp->v_config); + break; + case V_HASH: + hash_print(vp->v_hash); + break; + case V_BLOCK: + if (!userfunc("blk_print", vp)) + blk_print(vp->v_block); + break; + case V_OCTET: + if (userfunc("octet_print", vp)) + break; + qtemp = itoq((long) *vp->v_octet); + qprintnum(qtemp, MODE_DEFAULT, conf->outdigits); + qfree(qtemp); + break; + case V_OPTR: + math_fmt("o-ptr: %p", (void *)vp->v_octet); + break; + case V_VPTR: + math_fmt("v-ptr: %p", (void *)vp->v_addr); + break; + case V_SPTR: + math_fmt("s_ptr: %p", (void *)vp->v_str); + break; + case V_NPTR: + math_fmt("n_ptr: %p", (void *)vp->v_num); + break; + case V_NBLOCK: + if (!userfunc("nblk_print", vp)) + nblock_print(vp->v_nblock); + break; + default: + math_error("Printing unrecognized type of value"); + not_reached(); + } } /* @@ -2915,110 +2915,110 @@ printvalue(VALUE *vp, int flags) void printestr(VALUE *vp) { - LISTELEM *ep; - MATRIX *mp; - OBJECT *op; - BLOCK *bp; - int mode; - long i, min, max; - USB8 *cp; + LISTELEM *ep; + MATRIX *mp; + OBJECT *op; + BLOCK *bp; + int mode; + long i, min, max; + USB8 *cp; - if (vp->v_type < 0) { - math_fmt("error(%d)", -vp->v_type); - return; - } - switch(vp->v_type) { - case V_NULL: - math_str("\"\""); - return; - case V_STR: - math_chr('"'); - strprint(vp->v_str); - math_chr('"'); - return; - case V_NUM: - qprintnum(vp->v_num, MODE_FRAC, conf->outdigits); - return; - case V_COM: - mode = math_setmode(MODE_FRAC); - comprint(vp->v_com); - math_setmode(mode); - return; - case V_LIST: - math_str("list("); - ep = vp->v_list->l_first; - if (ep) { - printestr(&ep->e_value); - while ((ep = ep->e_next)) { - math_chr(','); - printestr(&ep->e_value); - } - } - math_chr(')'); - return; - case V_MAT: - mp = vp->v_mat; - if (mp->m_dim == 0) - math_str("(mat[])"); - else { - math_str("mat["); - for (i = 0; i < mp->m_dim; i++) { - min = mp->m_min[i]; - max = mp->m_max[i]; - if (i > 0) - math_chr(','); - if (min) - math_fmt("%ld:%ld", min, max); - else - math_fmt("%ld", max + 1); - } - math_chr(']'); - } - i = mp->m_size; - vp = mp->m_table; - break; - case V_OBJ: - op = vp->v_obj; - math_fmt("obj %s",objtypename(op->o_actions->oa_index)); - i = op->o_actions->oa_count; - vp = op->o_table; - break; - case V_BLOCK: - case V_NBLOCK: - math_str("blk("); - if (vp->v_type == V_BLOCK) - bp = vp->v_block; - else { - math_fmt("\"%s\",", vp->v_nblock->name); - bp = vp->v_nblock->blk; - } - i = bp->datalen; - math_fmt("%ld,%d)", i, (int) bp->blkchunk); - cp = bp->data; - if (i > 0) { - math_str("={"); - math_fmt("%d", *cp); - while (--i > 0) { - math_chr(','); - math_fmt("%d", *++cp); - } - math_chr('}'); - } - return; + if (vp->v_type < 0) { + math_fmt("error(%d)", -vp->v_type); + return; + } + switch(vp->v_type) { + case V_NULL: + math_str("\"\""); + return; + case V_STR: + math_chr('"'); + strprint(vp->v_str); + math_chr('"'); + return; + case V_NUM: + qprintnum(vp->v_num, MODE_FRAC, conf->outdigits); + return; + case V_COM: + mode = math_setmode(MODE_FRAC); + comprint(vp->v_com); + math_setmode(mode); + return; + case V_LIST: + math_str("list("); + ep = vp->v_list->l_first; + if (ep) { + printestr(&ep->e_value); + while ((ep = ep->e_next)) { + math_chr(','); + printestr(&ep->e_value); + } + } + math_chr(')'); + return; + case V_MAT: + mp = vp->v_mat; + if (mp->m_dim == 0) + math_str("(mat[])"); + else { + math_str("mat["); + for (i = 0; i < mp->m_dim; i++) { + min = mp->m_min[i]; + max = mp->m_max[i]; + if (i > 0) + math_chr(','); + if (min) + math_fmt("%ld:%ld", min, max); + else + math_fmt("%ld", max + 1); + } + math_chr(']'); + } + i = mp->m_size; + vp = mp->m_table; + break; + case V_OBJ: + op = vp->v_obj; + math_fmt("obj %s",objtypename(op->o_actions->oa_index)); + i = op->o_actions->oa_count; + vp = op->o_table; + break; + case V_BLOCK: + case V_NBLOCK: + math_str("blk("); + if (vp->v_type == V_BLOCK) + bp = vp->v_block; + else { + math_fmt("\"%s\",", vp->v_nblock->name); + bp = vp->v_nblock->blk; + } + i = bp->datalen; + math_fmt("%ld,%d)", i, (int) bp->blkchunk); + cp = bp->data; + if (i > 0) { + math_str("={"); + math_fmt("%d", *cp); + while (--i > 0) { + math_chr(','); + math_fmt("%d", *++cp); + } + math_chr('}'); + } + return; - default: - math_str("\"???\""); - return; - } - if (i > 0) { - math_str("={"); - printestr(vp); - while (--i > 0) { - math_chr(','); - printestr(++vp); - } - math_chr('}'); - } + default: + math_str("\"???\""); + return; + } + if (i > 0) { + math_str("={"); + printestr(vp); + while (--i > 0) { + math_chr(','); + printestr(++vp); + } + math_chr('}'); + } } @@ -3026,54 +3026,54 @@ printestr(VALUE *vp) * config_print - print a configuration value * * given: - * cfg what to print + * cfg what to print */ void config_print(CONFIG *cfg) { - NAMETYPE *cp; - VALUE tmp; - int tab_over; /* true => OK move over one tab stop */ - size_t len; + NAMETYPE *cp; + VALUE tmp; + int tab_over; /* true => OK move over one tab stop */ + size_t len; - /* - * firewall - */ - if (cfg == NULL || cfg->epsilon == NULL || cfg->prompt1 == NULL || - cfg->prompt2 == NULL) { - math_error("CONFIG value is invalid"); - not_reached(); - } + /* + * firewall + */ + if (cfg == NULL || cfg->epsilon == NULL || cfg->prompt1 == NULL || + cfg->prompt2 == NULL) { + math_error("CONFIG value is invalid"); + not_reached(); + } - /* - * print each element - */ - tab_over = false; - for (cp = configs; cp->name; cp++) { + /* + * print each element + */ + tab_over = false; + for (cp = configs; cp->name; cp++) { - /* skip if special all or duplicate maxerr value */ - if (cp->type == CONFIG_ALL || strcmp(cp->name, "maxerr") == 0 || - strcmp(cp->name, "ctrl-d") == 0) - continue; + /* skip if special all or duplicate maxerr value */ + if (cp->type == CONFIG_ALL || strcmp(cp->name, "maxerr") == 0 || + strcmp(cp->name, "ctrl-d") == 0) + continue; - /* print tab if allowed */ - if (tab_over) { - math_str("\t"); - } else if (conf->tab_ok) { - tab_over = true; /* tab next time */ - } + /* print tab if allowed */ + if (tab_over) { + math_str("\t"); + } else if (conf->tab_ok) { + tab_over = true; /* tab next time */ + } - /* print name and spaces */ - math_fmt("%s", cp->name); - len = 16 - strlen(cp->name); - while (len-- > 0) - math_str(" "); + /* print name and spaces */ + math_fmt("%s", cp->name); + len = 16 - strlen(cp->name); + while (len-- > 0) + math_str(" "); - /* print value */ - config_value(cfg, cp->type, &tmp); - printvalue(&tmp, PRINT_SHORT | PRINT_UNAMBIG); - freevalue(&tmp); - if ((cp+1)->name) - math_str("\n"); - } + /* print value */ + config_value(cfg, cp->type, &tmp); + printvalue(&tmp, PRINT_SHORT | PRINT_UNAMBIG); + freevalue(&tmp); + if ((cp+1)->name) + math_str("\n"); + } } diff --git a/value.h b/value.h index 69aa61a..ddc2cac 100644 --- a/value.h +++ b/value.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1993/07/30 19:42:47 - * File existed as early as: 1993 + * Under source code control: 1993/07/30 19:42:47 + * File existed as early as: 1993 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -28,7 +28,7 @@ #define INCLUDE_VALUE_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "decl.h" # include "cmath.h" # include "config.h" @@ -51,17 +51,17 @@ #endif -#define MAXDIM 4 /* maximum number of dimensions in matrices */ -#define USUAL_ELEMENTS 4 /* usual number of elements for objects */ +#define MAXDIM 4 /* maximum number of dimensions in matrices */ +#define USUAL_ELEMENTS 4 /* usual number of elements for objects */ /* * Flags to modify results from the printvalue routine. * These flags are OR'd together. */ -#define PRINT_NORMAL 0x00 /* print in normal manner */ -#define PRINT_SHORT 0x01 /* print in short format (no elements) */ -#define PRINT_UNAMBIG 0x02 /* print in non-ambiguous manner */ +#define PRINT_NORMAL 0x00 /* print in normal manner */ +#define PRINT_SHORT 0x01 /* print in short format (no elements) */ +#define PRINT_UNAMBIG 0x02 /* print in non-ambiguous manner */ /* @@ -83,51 +83,51 @@ typedef struct random RANDOM; * See below for information on what needs to be added for a new type. * * NOTE: The v_type can be a negative value. This happens when - * an error is returned as a VALUE. + * an error is returned as a VALUE. */ struct value { - short v_type; /* type of value - IMPORTANT: v_type < 0 is an error code */ - unsigned short v_subtype; /* other data related to some types */ - union { /* types of values (see V_XYZ below) */ - long vv_int; /* 1: small integer value */ - NUMBER *vv_num; /* 2, 21: real number */ - COMPLEX *vv_com; /* 3: complex number */ - VALUE *vv_addr; /* 4, 18: address of variable value */ - STRING *vv_str; /* 5, 20: string value */ - MATRIX *vv_mat; /* 6: address of matrix */ - LIST *vv_list; /* 7: address of list */ - ASSOC *vv_assoc; /* 8: address of association */ - OBJECT *vv_obj; /* 9: address of object */ - FILEID vv_file; /* 10: id of opened file */ - RAND *vv_rand; /* 11: subtractive 100 random state */ - RANDOM *vv_random; /* 12: Blum random state */ - CONFIG *vv_config; /* 13: configuration state */ - HASH *vv_hash; /* 14: hash state */ - BLOCK *vv_block; /* 15: memory block */ - OCTET *vv_octet; /* 16, 19: octet addr (unsigned char) */ - NBLOCK *vv_nblock; /* 17: named memory block */ - } v_union; + short v_type; /* type of value - IMPORTANT: v_type < 0 is an error code */ + unsigned short v_subtype; /* other data related to some types */ + union { /* types of values (see V_XYZ below) */ + long vv_int; /* 1: small integer value */ + NUMBER *vv_num; /* 2, 21: real number */ + COMPLEX *vv_com; /* 3: complex number */ + VALUE *vv_addr; /* 4, 18: address of variable value */ + STRING *vv_str; /* 5, 20: string value */ + MATRIX *vv_mat; /* 6: address of matrix */ + LIST *vv_list; /* 7: address of list */ + ASSOC *vv_assoc; /* 8: address of association */ + OBJECT *vv_obj; /* 9: address of object */ + FILEID vv_file; /* 10: id of opened file */ + RAND *vv_rand; /* 11: subtractive 100 random state */ + RANDOM *vv_random; /* 12: Blum random state */ + CONFIG *vv_config; /* 13: configuration state */ + HASH *vv_hash; /* 14: hash state */ + BLOCK *vv_block; /* 15: memory block */ + OCTET *vv_octet; /* 16, 19: octet addr (unsigned char) */ + NBLOCK *vv_nblock; /* 17: named memory block */ + } v_union; }; /* * For ease in referencing */ -#define v_int v_union.vv_int -#define v_file v_union.vv_file -#define v_num v_union.vv_num -#define v_com v_union.vv_com -#define v_addr v_union.vv_addr -#define v_str v_union.vv_str -#define v_mat v_union.vv_mat -#define v_list v_union.vv_list +#define v_int v_union.vv_int +#define v_file v_union.vv_file +#define v_num v_union.vv_num +#define v_com v_union.vv_com +#define v_addr v_union.vv_addr +#define v_str v_union.vv_str +#define v_mat v_union.vv_mat +#define v_list v_union.vv_list #define v_assoc v_union.vv_assoc -#define v_obj v_union.vv_obj +#define v_obj v_union.vv_obj #define v_valid v_union.vv_int -#define v_rand v_union.vv_rand +#define v_rand v_union.vv_rand #define v_random v_union.vv_random #define v_config v_union.vv_config -#define v_hash v_union.vv_hash +#define v_hash v_union.vv_hash #define v_block v_union.vv_block #define v_octet v_union.vv_octet #define v_nblock v_union.vv_nblock @@ -138,56 +138,56 @@ struct value { * * NOTE: The following files should be checked/adjusted for a new type: * - * size.c - elm_count(), lsizeof() - * help/size - update what the size() builtin will report - * hash.c - hash_value() - * quickhash.c - hashvalue() - * value.c - freevalue(), copyvalue(), comparevalue(), - * printvalue(), - * and other as needed such as testvalue(), etc. + * size.c - elm_count(), lsizeof() + * help/size - update what the size() builtin will report + * hash.c - hash_value() + * quickhash.c - hashvalue() + * value.c - freevalue(), copyvalue(), comparevalue(), + * printvalue(), + * and other as needed such as testvalue(), etc. * * There may be others, but at is at least a start. */ -#define V_NULL 0 /* null value */ -#define V_INT 1 /* normal integer */ -#define V_NUM 2 /* number */ -#define V_COM 3 /* complex number */ -#define V_ADDR 4 /* address of variable value */ -#define V_STR 5 /* address of string */ -#define V_MAT 6 /* address of matrix structure */ -#define V_LIST 7 /* address of list structure */ -#define V_ASSOC 8 /* address of association structure */ -#define V_OBJ 9 /* address of object structure */ -#define V_FILE 10 /* opened file id */ -#define V_RAND 11 /* address of subtractive 100 random state */ -#define V_RANDOM 12 /* address of Blum random state */ -#define V_CONFIG 13 /* configuration state */ -#define V_HASH 14 /* hash state */ -#define V_BLOCK 15 /* memory block */ -#define V_OCTET 16 /* octet (unsigned char) */ -#define V_NBLOCK 17 /* named memory block */ -#define V_VPTR 18 /* value address as pointer */ -#define V_OPTR 19 /* octet address as pointer */ -#define V_SPTR 20 /* string address as pointer */ -#define V_NPTR 21 /* number address as pointer */ +#define V_NULL 0 /* null value */ +#define V_INT 1 /* normal integer */ +#define V_NUM 2 /* number */ +#define V_COM 3 /* complex number */ +#define V_ADDR 4 /* address of variable value */ +#define V_STR 5 /* address of string */ +#define V_MAT 6 /* address of matrix structure */ +#define V_LIST 7 /* address of list structure */ +#define V_ASSOC 8 /* address of association structure */ +#define V_OBJ 9 /* address of object structure */ +#define V_FILE 10 /* opened file id */ +#define V_RAND 11 /* address of subtractive 100 random state */ +#define V_RANDOM 12 /* address of Blum random state */ +#define V_CONFIG 13 /* configuration state */ +#define V_HASH 14 /* hash state */ +#define V_BLOCK 15 /* memory block */ +#define V_OCTET 16 /* octet (unsigned char) */ +#define V_NBLOCK 17 /* named memory block */ +#define V_VPTR 18 /* value address as pointer */ +#define V_OPTR 19 /* octet address as pointer */ +#define V_SPTR 20 /* string address as pointer */ +#define V_NPTR 21 /* number address as pointer */ -#define V_MAX V_NPTR /* highest legal value - must be last and match highest V_something value */ +#define V_MAX V_NPTR /* highest legal value - must be last and match highest V_something value */ /* * v_subtype values */ -#define V_NOSUBTYPE 0 /* subtype has no meaning */ -#define V_NOASSIGNTO 0x001 /* protection status 1 */ -#define V_NONEWVALUE 0x002 /* protection status 2 */ -#define V_NONEWTYPE 0x004 /* protection status 4 */ -#define V_NOERROR 0x008 /* protection status 8 */ -#define V_NOCOPYTO 0x010 /* protection status 16 */ -#define V_NOREALLOC 0x020 /* protection status 32 */ -#define V_NOASSIGNFROM 0x040 /* protection status 64 */ -#define V_NOCOPYFROM 0x080 /* protection status 128 */ -#define V_PROTECTALL 0x100 /* protection status 256 */ +#define V_NOSUBTYPE 0 /* subtype has no meaning */ +#define V_NOASSIGNTO 0x001 /* protection status 1 */ +#define V_NONEWVALUE 0x002 /* protection status 2 */ +#define V_NONEWTYPE 0x004 /* protection status 4 */ +#define V_NOERROR 0x008 /* protection status 8 */ +#define V_NOCOPYTO 0x010 /* protection status 16 */ +#define V_NOREALLOC 0x020 /* protection status 32 */ +#define V_NOASSIGNFROM 0x040 /* protection status 64 */ +#define V_NOCOPYFROM 0x080 /* protection status 128 */ +#define V_PROTECTALL 0x100 /* protection status 256 */ -#define MAXPROTECT 0x1ff /* OR of all of the above protection statuses */ +#define MAXPROTECT 0x1ff /* OR of all of the above protection statuses */ /* * At present protect(var, sts) determines bits in var->v_subtype @@ -211,35 +211,35 @@ struct value { * with one switches on that unsigned int, cases with a and/or b being * out of range will fall into the default (non-matching) case. * - * unsigned int twoval_as_uint; + * unsigned int twoval_as_uint; * - * ... + * ... * - * twoval_as_uint = TWOVAL_AS_UINT(a,b); - * switch (twoval_as_uint) { - * case TWOVAL(V_INT,V_INT): - * ... - * break; - * case TWOVAL(V_INT,V_NUM): - * ... - * break; - * default: - * ... - * break; - * } + * twoval_as_uint = TWOVAL_AS_UINT(a,b); + * switch (twoval_as_uint) { + * case TWOVAL(V_INT,V_INT): + * ... + * break; + * case TWOVAL(V_INT,V_NUM): + * ... + * break; + * default: + * ... + * break; + * } * - * If a is NOT 0 <= a <= V_MAX or if b is NOT 0 <= b <= V_MAX, - * when () macro returns -1 (all bits set) in order to - * not match and true TWOVAL() macro combination that uses - * uses a V_something defined value above. + * If a is NOT 0 <= a <= V_MAX or if b is NOT 0 <= b <= V_MAX, + * when () macro returns -1 (all bits set) in order to + * not match and true TWOVAL() macro combination that uses + * uses a V_something defined value above. */ -#define TWOVAL(a,b) ((unsigned int)(((a) << 8) | (b))) /* logical OR for switch of two V_something values */ +#define TWOVAL(a,b) ((unsigned int)(((a) << 8) | (b))) /* logical OR for switch of two V_something values */ #define TWOVAL_ARGS_OK(a,b) (((a) >= 0) && ((a) <= V_MAX) && ((b) >= 0) && ((b) <= V_MAX)) -#define TWOVAL_INVALID ((unsigned int)(-1)) /* never a valid TWOVAL(a,b) value when a and b are in range */ +#define TWOVAL_INVALID ((unsigned int)(-1)) /* never a valid TWOVAL(a,b) value when a and b are in range */ #define TWOVAL_AS_UINT(a,b) (TWOVAL_ARGS_OK(a,b) ? TWOVAL(a,b) : TWOVAL_INVALID) -#define NULL_VALUE ((VALUE *) 0) +#define NULL_VALUE ((VALUE *) 0) /* @@ -305,11 +305,11 @@ E_FUNC void set_update(int); * Structure of a matrix. */ struct matrix { - long m_dim; /* dimension of matrix */ - long m_size; /* total number of elements */ - long m_min[MAXDIM]; /* minimum bound for indices */ - long m_max[MAXDIM]; /* maximum bound for indices */ - VALUE m_table[1]; /* actually varying length table */ + long m_dim; /* dimension of matrix */ + long m_size; /* total number of elements */ + long m_min[MAXDIM]; /* minimum bound for indices */ + long m_max[MAXDIM]; /* maximum bound for indices */ + VALUE m_table[1]; /* actually varying length table */ }; #define matsize(n) (sizeof(MATRIX) - sizeof(VALUE) + ((n) * sizeof(VALUE))) @@ -342,7 +342,7 @@ E_FUNC void matsum(MATRIX *m, VALUE *vres); E_FUNC bool matcmp(MATRIX *m1, MATRIX *m2); E_FUNC int matsearch(MATRIX *m, VALUE *vp, long start, long end, ZVALUE *index); E_FUNC int matrsearch(MATRIX *m, VALUE *vp, long start, long end, - ZVALUE *index); + ZVALUE *index); E_FUNC VALUE matdet(MATRIX *m); E_FUNC VALUE matdot(MATRIX *m1, MATRIX *m2); E_FUNC void matfill(MATRIX *m, VALUE *v1, VALUE *v2); @@ -362,9 +362,9 @@ E_FUNC MATRIX *matbround(MATRIX *m, VALUE *v2, VALUE *v3); */ typedef struct listelem LISTELEM; struct listelem { - LISTELEM *e_next; /* next element in list (or NULL) */ - LISTELEM *e_prev; /* previous element in list (or NULL) */ - VALUE e_value; /* value of this element */ + LISTELEM *e_next; /* next element in list (or NULL) */ + LISTELEM *e_prev; /* previous element in list (or NULL) */ + VALUE e_value; /* value of this element */ }; @@ -372,11 +372,11 @@ struct listelem { * Structure for a list of elements. */ struct list { - LISTELEM *l_first; /* first list element (or NULL) */ - LISTELEM *l_last; /* last list element (or NULL) */ - LISTELEM *l_cache; /* cached list element (or NULL) */ - long l_cacheindex; /* index of cached element (or undefined) */ - long l_count; /* total number of elements in the list */ + LISTELEM *l_first; /* first list element (or NULL) */ + LISTELEM *l_last; /* last list element (or NULL) */ + LISTELEM *l_cache; /* cached list element (or NULL) */ + long l_cacheindex; /* index of cached element (or undefined) */ + long l_count; /* total number of elements in the list */ }; @@ -390,7 +390,7 @@ E_FUNC void listfree(LIST *lp); E_FUNC void listprint(LIST *lp, long max_print); E_FUNC int listsearch(LIST *lp, VALUE *vp, long start, long end, ZVALUE *index); E_FUNC int listrsearch(LIST *lp, VALUE *vp, long start, long end, - ZVALUE *index); + ZVALUE *index); E_FUNC bool listcmp(LIST *lp1, LIST *lp2); E_FUNC VALUE *listfindex(LIST *lp, long index); E_FUNC LIST *listalloc(void); @@ -416,18 +416,18 @@ E_FUNC LIST *listsegment(LIST *, long, long); */ typedef struct assocelem ASSOCELEM; struct assocelem { - ASSOCELEM *e_next; /* next element in list (or NULL) */ - long e_dim; /* dimension of indexing for this element */ - QCKHASH e_hash; /* hash value for this element */ - VALUE e_value; /* value of association */ - VALUE e_indices[1]; /* index values (variable length) */ + ASSOCELEM *e_next; /* next element in list (or NULL) */ + long e_dim; /* dimension of indexing for this element */ + QCKHASH e_hash; /* hash value for this element */ + VALUE e_value; /* value of association */ + VALUE e_indices[1]; /* index values (variable length) */ }; struct assoc { - long a_count; /* number of elements in the association */ - long a_size; /* current size of association hash table */ - ASSOCELEM **a_table; /* current hash table for elements */ + long a_count; /* number of elements in the association */ + long a_size; /* current size of association hash table */ + ASSOCELEM **a_table; /* current hash table for elements */ }; @@ -436,9 +436,9 @@ E_FUNC ASSOC *assoccopy(ASSOC *ap); E_FUNC void assocfree(ASSOC *ap); E_FUNC void assocprint(ASSOC *ap, long max_print); E_FUNC int assocsearch(ASSOC *ap, VALUE *vp, long start, long end, - ZVALUE *index); + ZVALUE *index); E_FUNC int assocrsearch(ASSOC *ap, VALUE *vp, long start, long end, - ZVALUE *index); + ZVALUE *index); E_FUNC bool assoccmp(ASSOC *ap1, ASSOC *ap2); E_FUNC VALUE *assocfindex(ASSOC *ap, long index); E_FUNC VALUE *associndex(ASSOC *ap, bool create, long dim, VALUE *indices); @@ -447,51 +447,51 @@ E_FUNC VALUE *associndex(ASSOC *ap, bool create, long dim, VALUE *indices); /* * Object actions. */ -#define OBJ_PRINT 0 /* print the value */ -#define OBJ_ONE 1 /* create the multiplicative identity */ -#define OBJ_TEST 2 /* test a value for "zero" */ -#define OBJ_ADD 3 /* add two values */ -#define OBJ_SUB 4 /* sub-trace one value from another */ -#define OBJ_NEG 5 /* negate a value */ -#define OBJ_MUL 6 /* multiply two values */ -#define OBJ_DIV 7 /* divide one value by another */ -#define OBJ_INV 8 /* invert a value */ -#define OBJ_ABS 9 /* take absolute value of value */ -#define OBJ_NORM 10 /* take the norm of a value */ -#define OBJ_CONJ 11 /* take the conjugate of a value */ -#define OBJ_POW 12 /* take the power function */ -#define OBJ_SGN 13 /* return the sign of a value */ -#define OBJ_CMP 14 /* compare two values for equality */ -#define OBJ_REL 15 /* compare two values for inequality */ -#define OBJ_QUO 16 /* integer quotient of values */ -#define OBJ_MOD 17 /* remainder of division of values */ -#define OBJ_INT 18 /* integer part of */ -#define OBJ_FRAC 19 /* fractional part of */ -#define OBJ_INC 20 /* increment by one */ -#define OBJ_DEC 21 /* decrement by one */ -#define OBJ_SQUARE 22 /* square value */ -#define OBJ_SCALE 23 /* scale by power of two */ -#define OBJ_SHIFT 24 /* shift left (or right) by number of bits */ -#define OBJ_ROUND 25 /* round to specified decimal places */ -#define OBJ_BROUND 26 /* round to specified binary places */ -#define OBJ_ROOT 27 /* take nth root of value */ -#define OBJ_SQRT 28 /* take square root of value */ -#define OBJ_OR 29 /* take bitwise or of values */ -#define OBJ_AND 30 /* take bitwise and of values */ -#define OBJ_NOT 31 /* take logical not of value */ -#define OBJ_FACT 32 /* factorial or postfix ! */ -#define OBJ_MIN 33 /* minimum value */ -#define OBJ_MAX 34 /* maximum value */ -#define OBJ_SUM 35 /* sum value */ -#define OBJ_ASSIGN 36 /* assign value */ -#define OBJ_XOR 37 /* ~ difference of values */ -#define OBJ_COMP 38 /* ~ complement of value */ -#define OBJ_CONTENT 39 /* unary hash op */ -#define OBJ_HASHOP 40 /* binary hash op */ -#define OBJ_BACKSLASH 41 /* unary backslash op */ -#define OBJ_SETMINUS 42 /* binary backslash op */ -#define OBJ_PLUS 43 /* unary + op */ -#define OBJ_MAXFUNC 43 /* highest function */ +#define OBJ_PRINT 0 /* print the value */ +#define OBJ_ONE 1 /* create the multiplicative identity */ +#define OBJ_TEST 2 /* test a value for "zero" */ +#define OBJ_ADD 3 /* add two values */ +#define OBJ_SUB 4 /* sub-trace one value from another */ +#define OBJ_NEG 5 /* negate a value */ +#define OBJ_MUL 6 /* multiply two values */ +#define OBJ_DIV 7 /* divide one value by another */ +#define OBJ_INV 8 /* invert a value */ +#define OBJ_ABS 9 /* take absolute value of value */ +#define OBJ_NORM 10 /* take the norm of a value */ +#define OBJ_CONJ 11 /* take the conjugate of a value */ +#define OBJ_POW 12 /* take the power function */ +#define OBJ_SGN 13 /* return the sign of a value */ +#define OBJ_CMP 14 /* compare two values for equality */ +#define OBJ_REL 15 /* compare two values for inequality */ +#define OBJ_QUO 16 /* integer quotient of values */ +#define OBJ_MOD 17 /* remainder of division of values */ +#define OBJ_INT 18 /* integer part of */ +#define OBJ_FRAC 19 /* fractional part of */ +#define OBJ_INC 20 /* increment by one */ +#define OBJ_DEC 21 /* decrement by one */ +#define OBJ_SQUARE 22 /* square value */ +#define OBJ_SCALE 23 /* scale by power of two */ +#define OBJ_SHIFT 24 /* shift left (or right) by number of bits */ +#define OBJ_ROUND 25 /* round to specified decimal places */ +#define OBJ_BROUND 26 /* round to specified binary places */ +#define OBJ_ROOT 27 /* take nth root of value */ +#define OBJ_SQRT 28 /* take square root of value */ +#define OBJ_OR 29 /* take bitwise or of values */ +#define OBJ_AND 30 /* take bitwise and of values */ +#define OBJ_NOT 31 /* take logical not of value */ +#define OBJ_FACT 32 /* factorial or postfix ! */ +#define OBJ_MIN 33 /* minimum value */ +#define OBJ_MAX 34 /* maximum value */ +#define OBJ_SUM 35 /* sum value */ +#define OBJ_ASSIGN 36 /* assign value */ +#define OBJ_XOR 37 /* ~ difference of values */ +#define OBJ_COMP 38 /* ~ complement of value */ +#define OBJ_CONTENT 39 /* unary hash op */ +#define OBJ_HASHOP 40 /* binary hash op */ +#define OBJ_BACKSLASH 41 /* unary backslash op */ +#define OBJ_SETMINUS 42 /* binary backslash op */ +#define OBJ_PLUS 43 /* unary + op */ +#define OBJ_MAXFUNC 43 /* highest function */ /* @@ -499,14 +499,14 @@ E_FUNC VALUE *associndex(ASSOC *ap, bool create, long dim, VALUE *indices); * This is actually a varying sized structure. */ typedef struct { - int oa_index; /* index of object type */ - int oa_count; /* number of elements defined */ - long oa_indices[OBJ_MAXFUNC+1]; /* function indices for actions */ - int oa_elements[1]; /* element indices (MUST BE LAST) */ + int oa_index; /* index of object type */ + int oa_count; /* number of elements defined */ + long oa_indices[OBJ_MAXFUNC+1]; /* function indices for actions */ + int oa_elements[1]; /* element indices (MUST BE LAST) */ } OBJECTACTIONS; #define objectactionsize(elements) \ - (sizeof(OBJECTACTIONS) + ((elements) - 1) * sizeof(int)) + (sizeof(OBJECTACTIONS) + ((elements) - 1) * sizeof(int)) /* @@ -515,12 +515,12 @@ typedef struct { * However, there are always at least USUAL_ELEMENTS values in the object. */ struct object { - OBJECTACTIONS *o_actions; /* action table for this object */ - VALUE o_table[USUAL_ELEMENTS]; /* object values (MUST BE LAST) */ + OBJECTACTIONS *o_actions; /* action table for this object */ + VALUE o_table[USUAL_ELEMENTS]; /* object values (MUST BE LAST) */ }; #define objectsize(elements) \ - (sizeof(OBJECT) + ((elements) - USUAL_ELEMENTS) * sizeof(VALUE)) + (sizeof(OBJECT) + ((elements) - USUAL_ELEMENTS) * sizeof(VALUE)) E_FUNC OBJECT *objcopy(OBJECT *op); @@ -543,7 +543,7 @@ E_FUNC int objoffset(OBJECT *op, long index); EXTERN NAMETYPE configs[]; E_FUNC void config_value(CONFIG *cfg, int type, VALUE *ret); E_FUNC void setconfig(int type, VALUE *vp); -E_FUNC void config_print(CONFIG *cfg); /* the CONFIG to print */ +E_FUNC void config_print(CONFIG *cfg); /* the CONFIG to print */ /* diff --git a/version.c b/version.c index 98464b1..0a3bf39 100644 --- a/version.c +++ b/version.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,11 +19,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/05/22 11:00:58 - * File existed as early as: 1990 + * Under source code control: 1990/05/22 11:00:58 + * File existed as early as: 1990 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -49,7 +49,7 @@ static char *program; #include "have_unused.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* @@ -64,7 +64,7 @@ int calc_minor_patch = MINOR_PATCH; /* * stored version */ -STATIC char *stored_version = NULL; /* version formed if != NULL */ +STATIC char *stored_version = NULL; /* version formed if != NULL */ /* @@ -74,7 +74,7 @@ char *Copyright = "\n" "calc - arbitrary precision calculator\n" "\n" "Copyright (C) 1999-2023 David I. Bell, Landon Curt Noll " - "and Ernest Bowen\n" + "and Ernest Bowen\n" "\n" "Initial author: David I. Bell\n" "\n" @@ -90,7 +90,7 @@ char *Copyright = "\n" char *Usability = "\n" "Calc is distributed in the hope that it will be useful, but WITHOUT\n" "ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n" - "or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General\n" + "or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General\n" "Public License for more details.\n"; char *COPYING_LGPL = "\n" "A copy of version 2.1 of the GNU Lesser General Public License is\n" @@ -109,44 +109,44 @@ char *COPYING_LGPL = "\n" * This function returns a malloced version string. This version * string does not contain the title, just: * - * x.y.z.w + * x.y.z.w */ char * version(void) { - char verbuf[BUFSIZ+1]; /* form version string here */ - size_t len; /* length of version string */ + char verbuf[BUFSIZ+1]; /* form version string here */ + size_t len; /* length of version string */ - /* - * return previously stored version if one exists - */ - if (stored_version) { - return stored_version; - } + /* + * return previously stored version if one exists + */ + if (stored_version) { + return stored_version; + } - /* - * form the version buffer - */ - snprintf(verbuf, BUFSIZ, - "%d.%d.%d.%d", calc_major_ver, calc_minor_ver, - calc_major_patch, calc_minor_patch); - verbuf[BUFSIZ] = '\0'; /* paranoia */ + /* + * form the version buffer + */ + snprintf(verbuf, BUFSIZ, + "%d.%d.%d.%d", calc_major_ver, calc_minor_ver, + calc_major_patch, calc_minor_patch); + verbuf[BUFSIZ] = '\0'; /* paranoia */ - /* - * save the versions string into a newly malloced buffer - */ - len = strlen(verbuf); - stored_version = (char *)calloc(len+1, sizeof(verbuf[0])); - if (stored_version == NULL) { - fprintf(stderr, "%s: cannot malloc version string\n", program); - exit(70); - } - strlcpy(stored_version, verbuf, len+1); + /* + * save the versions string into a newly malloced buffer + */ + len = strlen(verbuf); + stored_version = (char *)calloc(len+1, sizeof(verbuf[0])); + if (stored_version == NULL) { + fprintf(stderr, "%s: cannot malloc version string\n", program); + exit(70); + } + strlcpy(stored_version, verbuf, len+1); - /* - * return the newly malloced buffer - */ - return stored_version; + /* + * return the newly malloced buffer + */ + return stored_version; } @@ -158,17 +158,17 @@ version(void) * * This function prints the major part version string: * - * x.y.z + * x.y.z */ void print_3_level_version(void) { - /* - * form the version buffer - */ - printf("%d.%d.%d\n", calc_major_ver, calc_minor_ver, - calc_major_patch); - return; + /* + * form the version buffer + */ + printf("%d.%d.%d\n", calc_major_ver, calc_minor_ver, + calc_major_patch); + return; } @@ -179,32 +179,32 @@ print_3_level_version(void) int main(int argc, char *argv[]) { - program = argv[0]; - /* - * case: -V - print 3-level version - */ - if (argc == 2 && strcmp(argv[1], "-V") == 0) { - print_3_level_version(); + program = argv[0]; + /* + * case: -V - print 3-level version + */ + if (argc == 2 && strcmp(argv[1], "-V") == 0) { + print_3_level_version(); - /* - * case: no args - print 4-level version - */ - } else if (argc == 1) { - printf("%s\n", version()); + /* + * case: no args - print 4-level version + */ + } else if (argc == 1) { + printf("%s\n", version()); - /* - * case: -h or wrong number of args or invalid options - */ - } else { - fprintf(stderr, - "usage: %s [-V | -h]\n" - "\n" - " -h print this message and exit non-zero\n" - " -V print 3-level version (def: print 4-level version)\n", - program); - exit(75); - } - return 0; + /* + * case: -h or wrong number of args or invalid options + */ + } else { + fprintf(stderr, + "usage: %s [-V | -h]\n" + "\n" + " -h print this message and exit non-zero\n" + " -V print 3-level version (def: print 4-level version)\n", + program); + exit(75); + } + return 0; } #endif /* CALC_VER */ diff --git a/version.h b/version.h index 0fda403..597bfe9 100644 --- a/version.h +++ b/version.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 2023/08/19 17:32:42 - * File existed as early as: 2023 + * Under source code control: 2023/08/19 17:32:42 + * File existed as early as: 2023 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -32,13 +32,13 @@ /* * MAJOR_VER * - * The MAJOR_VER is 2 is the classical version of calc. + * The MAJOR_VER is 2 is the classical version of calc. * * One of the main reasons why MAJOR_VER might incremented is - * if fundamental calc data objects (such as when ZVALUE or NUMBER - * or COMPLEX need to change) that would cause an incompatibility + * if fundamental calc data objects (such as when ZVALUE or NUMBER + * or COMPLEX need to change) that would cause an incompatibility * with existing hardware accelerators that are using fundamental - * calc data objects. + * calc data objects. * * MINOR_VER * @@ -61,10 +61,10 @@ * Moreover, when we are working towards a new production release, * bug fix and improvement updates will cause MINOR_PATCH to increment. */ -#define MAJOR_VER 2 /* level 1: major library version */ -#define MINOR_VER 15 /* level 2: minor library version */ -#define MAJOR_PATCH 0 /* level 3: major software version level */ -#define MINOR_PATCH 7 /* level 4: minor software version level */ +#define MAJOR_VER 2 /* level 1: major library version */ +#define MINOR_VER 15 /* level 2: minor library version */ +#define MAJOR_PATCH 0 /* level 3: major software version level */ +#define MINOR_PATCH 7 /* level 4: minor software version level */ #endif /* !INCLUDE_VERSION_H*/ diff --git a/zfunc.c b/zfunc.c index a007450..437b0cc 100644 --- a/zfunc.c +++ b/zfunc.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:27 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:27 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -31,10 +31,10 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -ZVALUE _tenpowers_[TEN_MAX+1]; /* table of 10^2^n */ +ZVALUE _tenpowers_[TEN_MAX+1]; /* table of 10^2^n */ STATIC long *power10 = NULL; STATIC int max_power10_exp = 0; @@ -42,143 +42,143 @@ STATIC int max_power10_exp = 0; /* * given: * - * unsigned long x - * or: unsigned long long x - * or: long x and x >= 0 - * or: long long x and x >= 0 + * unsigned long x + * or: unsigned long long x + * or: long x and x >= 0 + * or: long long x and x >= 0 * * If issq_mod4k[x & 0xfff] == 0, then x cannot be a perfect square * else x might be a perfect square. */ STATIC USB8 issq_mod4k[1<<12] = { - 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0, }; @@ -188,59 +188,59 @@ STATIC USB8 issq_mod4k[1<<12] = { void zfact(ZVALUE z, ZVALUE *dest) { - long ptwo; /* count of powers of two */ - long n; /* current multiplication value */ - long m; /* reduced multiplication value */ - long mul; /* collected value to multiply by */ - ZVALUE res, temp; + long ptwo; /* count of powers of two */ + long n; /* current multiplication value */ + long m; /* reduced multiplication value */ + long mul; /* collected value to multiply by */ + ZVALUE res, temp; - /* firewall */ - if (dest == NULL) { - math_error("%s: dest NULL", __func__); - not_reached(); - } + /* firewall */ + if (dest == NULL) { + math_error("%s: dest NULL", __func__); + not_reached(); + } - if (zisneg(z)) { - math_error("Negative argument for factorial"); - not_reached(); - } - if (zge31b(z)) { - math_error("Very large factorial"); - not_reached(); - } - n = ztolong(z); - ptwo = 0; - mul = 1; - res = _one_; - /* - * Multiply numbers together, but squeeze out all powers of two. - * We will put them back in at the end. Also collect multiple - * numbers together until there is a risk of overflow. - */ - for (; n > 1; n--) { - for (m = n; ((m & 0x1) == 0); m >>= 1) - ptwo++; - if (mul <= MAXLONG/m) { - mul *= m; - continue; - } - zmuli(res, mul, &temp); - zfree(res); - res = temp; - mul = m; - } - /* - * Multiply by the remaining value, then scale result by - * the proper power of two. - */ - if (mul > 1) { - zmuli(res, mul, &temp); - zfree(res); - res = temp; - } - zshift(res, ptwo, &temp); - zfree(res); - *dest = temp; + if (zisneg(z)) { + math_error("Negative argument for factorial"); + not_reached(); + } + if (zge31b(z)) { + math_error("Very large factorial"); + not_reached(); + } + n = ztolong(z); + ptwo = 0; + mul = 1; + res = _one_; + /* + * Multiply numbers together, but squeeze out all powers of two. + * We will put them back in at the end. Also collect multiple + * numbers together until there is a risk of overflow. + */ + for (; n > 1; n--) { + for (m = n; ((m & 0x1) == 0); m >>= 1) + ptwo++; + if (mul <= MAXLONG/m) { + mul *= m; + continue; + } + zmuli(res, mul, &temp); + zfree(res); + res = temp; + mul = m; + } + /* + * Multiply by the remaining value, then scale result by + * the proper power of two. + */ + if (mul > 1) { + zmuli(res, mul, &temp); + zfree(res); + res = temp; + } + zshift(res, ptwo, &temp); + zfree(res); + *dest = temp; } @@ -250,40 +250,40 @@ zfact(ZVALUE z, ZVALUE *dest) void zperm(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - SFULL count; - ZVALUE cur, tmp, ans; + SFULL count; + ZVALUE cur, tmp, ans; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (zisneg(z1) || zisneg(z2)) { - math_error("Negative argument for permutation"); - not_reached(); - } - if (zrel(z1, z2) < 0) { - math_error("Second arg larger than first in permutation"); - not_reached(); - } - if (zge31b(z2)) { - math_error("Very large permutation"); - not_reached(); - } - count = ztolong(z2); - zcopy(z1, &ans); - zsub(z1, _one_, &cur); - while (--count > 0) { - zmul(ans, cur, &tmp); - zfree(ans); - ans = tmp; - zsub(cur, _one_, &tmp); - zfree(cur); - cur = tmp; - } - zfree(cur); - *res = ans; + if (zisneg(z1) || zisneg(z2)) { + math_error("Negative argument for permutation"); + not_reached(); + } + if (zrel(z1, z2) < 0) { + math_error("Second arg larger than first in permutation"); + not_reached(); + } + if (zge31b(z2)) { + math_error("Very large permutation"); + not_reached(); + } + count = ztolong(z2); + zcopy(z1, &ans); + zsub(z1, _one_, &cur); + while (--count > 0) { + zmul(ans, cur, &tmp); + zfree(ans); + ans = tmp; + zsub(cur, _one_, &tmp); + zfree(cur); + cur = tmp; + } + zfree(cur); + *res = ans; } /* @@ -292,110 +292,110 @@ zperm(ZVALUE z1, ZVALUE z2, ZVALUE *res) S_FUNC int docomb(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - ZVALUE ans; - ZVALUE mul, div, temp; - FULL count, i; + ZVALUE ans; + ZVALUE mul, div, temp; + FULL count, i; #if BASEB == 16 - HALF dh[2]; + HALF dh[2]; #else - HALF dh[1]; + HALF dh[1]; #endif - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (zrel(z2, z1) > 0) - return 0; - zsub(z1, z2, &temp); + if (zrel(z2, z1) > 0) + return 0; + zsub(z1, z2, &temp); - if (zge31b(z2) && zge31b(temp)) { - zfree(temp); - return -2; - } - if (zrel(temp, z2) < 0) - count = ztofull(temp); - else - count = ztofull(z2); - zfree(temp); - if (count == 0) - return 1; - if (count == 1) - return 2; - div.sign = 0; - div.v = dh; - div.len = 1; - zcopy(z1, &mul); - zcopy(z1, &ans); - for (i = 2; i <= count; i++) { + if (zge31b(z2) && zge31b(temp)) { + zfree(temp); + return -2; + } + if (zrel(temp, z2) < 0) + count = ztofull(temp); + else + count = ztofull(z2); + zfree(temp); + if (count == 0) + return 1; + if (count == 1) + return 2; + div.sign = 0; + div.v = dh; + div.len = 1; + zcopy(z1, &mul); + zcopy(z1, &ans); + for (i = 2; i <= count; i++) { #if BASEB == 16 - dh[0] = (HALF)(i & BASE1); - dh[1] = (HALF)(i >> BASEB); - div.len = 1 + (dh[1] != 0); + dh[0] = (HALF)(i & BASE1); + dh[1] = (HALF)(i >> BASEB); + div.len = 1 + (dh[1] != 0); #else - dh[0] = (HALF) i; + dh[0] = (HALF) i; #endif - zsub(mul, _one_, &temp); - zfree(mul); - mul = temp; - zmul(ans, mul, &temp); - zfree(ans); - zquo(temp, div, &ans, 0); - zfree(temp); - } - zfree(mul); - *res = ans; - return 3; + zsub(mul, _one_, &temp); + zfree(mul); + mul = temp; + zmul(ans, mul, &temp); + zfree(ans); + zquo(temp, div, &ans, 0); + zfree(temp); + } + zfree(mul); + *res = ans; + return 3; } /* * Compute the combinatorial function M! / ( N! * (M - N)! ). * Returns 0 if result is 0 -* 1 1 -* 2 z1 -* -1 -1 -* -2 if too complicated -* 3 result stored at res +* 1 1 +* 2 z1 +* -1 -1 +* -2 if too complicated +* 3 result stored at res */ int zcomb(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - ZVALUE z3, z4; - int r; + ZVALUE z3, z4; + int r; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (z2.sign || (!z1.sign && zrel(z2, z1) > 0)) - return 0; - if (zisone(z2)) - return 2; - if (z1.sign) { - z1.sign = 0; - zsub(z1, _one_, &z3); - zadd(z3, z2, &z4); - zfree(z3); - r = docomb(z4, z2, res); - if (r == 2) { - *res = z4; - r = 3; - } - else - zfree(z4); - if (z2.v[0] & 1) { - if (r == 1) - r = -1; - if (r == 3) - res->sign = 1; - } - return r; - } - return docomb(z1, z2, res); + if (z2.sign || (!z1.sign && zrel(z2, z1) > 0)) + return 0; + if (zisone(z2)) + return 2; + if (z1.sign) { + z1.sign = 0; + zsub(z1, _one_, &z3); + zadd(z3, z2, &z4); + zfree(z3); + r = docomb(z4, z2, res); + if (r == 2) { + *res = z4; + r = 3; + } + else + zfree(z4); + if (z2.v[0] & 1) { + if (r == 1) + r = -1; + if (r == 3) + res->sign = 1; + } + return r; + } + return docomb(z1, z2, res); } @@ -404,145 +404,145 @@ zcomb(ZVALUE z1, ZVALUE z2, ZVALUE *res) * * The property of the Jacobi function is: If n>2 is prime then * - * the result is 1 if m == x^2 (mod n) for some x. - * otherwise the result is -1. + * the result is 1 if m == x^2 (mod n) for some x. + * otherwise the result is -1. * * If n is not prime, then the result does not prove that n is not prime * when the value of the Jacobi is 1. * * Jacobi evaluation of (m / n), where n > 0 is odd AND m > 0 is odd: * - * rule 0: (0 / n) == 0 - * rule 1: (1 / n) == 1 - * rule 2: (m / n) == (a / n) if m == a % n - * rule 3: (m / n) == (2*m / n) if n == 1 % 8 OR n == 7 % 8 - * rule 4: (m / n) == -(2*m / n) if n != 1 & 8 AND n != 7 % 8 - * rule 5: (m / n) == (n / m) if m == 3 % 4 AND n == 3 % 4 - * rule 6: (m / n) == -(n / m) if m != 3 % 4 OR n != 3 % 4 + * rule 0: (0 / n) == 0 + * rule 1: (1 / n) == 1 + * rule 2: (m / n) == (a / n) if m == a % n + * rule 3: (m / n) == (2*m / n) if n == 1 % 8 OR n == 7 % 8 + * rule 4: (m / n) == -(2*m / n) if n != 1 & 8 AND n != 7 % 8 + * rule 5: (m / n) == (n / m) if m == 3 % 4 AND n == 3 % 4 + * rule 6: (m / n) == -(n / m) if m != 3 % 4 OR n != 3 % 4 * * NOTE: This function returns 0 in invalid Jacobi parameters: - * m < 0 OR n is even OR n < 1. + * m < 0 OR n is even OR n < 1. */ FLAG zjacobi(ZVALUE z1, ZVALUE z2) { - ZVALUE p, q, tmp; - long lowbit; - int val; + ZVALUE p, q, tmp; + long lowbit; + int val; - /* firewall */ - if (ziszero(z1) || zisneg(z1)) - return 0; - if (ziseven(z2) || zisneg(z2)) - return 0; + /* firewall */ + if (ziszero(z1) || zisneg(z1)) + return 0; + if (ziseven(z2) || zisneg(z2)) + return 0; - /* assume a value of 1 unless we find otherwise */ - if (zisone(z1)) - return 1; - val = 1; - zcopy(z1, &p); - zcopy(z2, &q); - for (;;) { - zmod(p, q, &tmp, 0); - zfree(p); - p = tmp; - if (ziszero(p)) { - zfree(p); - zfree(q); - return 0; - } - if (ziseven(p)) { - lowbit = zlowbit(p); - zshift(p, -lowbit, &tmp); - zfree(p); - p = tmp; - if ((lowbit & 1) && (((*q.v & 0x7) == 3) || - ((*q.v & 0x7) == 5))) - val = -val; - } - if (zisunit(p)) { - zfree(p); - zfree(q); - return val; - } - if ((*p.v & *q.v & 0x3) == 3) - val = -val; - tmp = q; - q = p; - p = tmp; - } + /* assume a value of 1 unless we find otherwise */ + if (zisone(z1)) + return 1; + val = 1; + zcopy(z1, &p); + zcopy(z2, &q); + for (;;) { + zmod(p, q, &tmp, 0); + zfree(p); + p = tmp; + if (ziszero(p)) { + zfree(p); + zfree(q); + return 0; + } + if (ziseven(p)) { + lowbit = zlowbit(p); + zshift(p, -lowbit, &tmp); + zfree(p); + p = tmp; + if ((lowbit & 1) && (((*q.v & 0x7) == 3) || + ((*q.v & 0x7) == 5))) + val = -val; + } + if (zisunit(p)) { + zfree(p); + zfree(q); + return val; + } + if ((*p.v & *q.v & 0x3) == 3) + val = -val; + tmp = q; + q = p; + p = tmp; + } } /* * Return the Fibonacci number F(n). * This is evaluated by recursively using the formulas: - * F(2N+1) = F(N+1)^2 + F(N)^2 + * F(2N+1) = F(N+1)^2 + F(N)^2 * and - * F(2N) = F(N+1)^2 - F(N-1)^2 + * F(2N) = F(N+1)^2 - F(N-1)^2 */ void zfib(ZVALUE z, ZVALUE *res) { - long n; - int sign; - ZVALUE fnm1, fn, fnp1; /* consecutive Fibonacci values */ - ZVALUE t1, t2, t3; - FULL i; + long n; + int sign; + ZVALUE fnm1, fn, fnp1; /* consecutive Fibonacci values */ + ZVALUE t1, t2, t3; + FULL i; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (zge31b(z)) { - math_error("Very large Fibonacci number"); - not_reached(); - } - n = ztolong(z); - if (n == 0) { - *res = _zero_; - return; - } - sign = z.sign && ((n & 0x1) == 0); - if (n <= 2) { - *res = _one_; - res->sign = (bool)sign; - return; - } - i = TOPFULL; - while ((i & n) == 0) - i >>= (FULL)1; - i >>= (FULL)1; - fnm1 = _zero_; - fn = _one_; - fnp1 = _one_; - while (i) { - zsquare(fnm1, &t1); - zsquare(fn, &t2); - zsquare(fnp1, &t3); - zfree(fnm1); - zfree(fn); - zfree(fnp1); - zadd(t2, t3, &fnp1); - zsub(t3, t1, &fn); - zfree(t1); - zfree(t2); - zfree(t3); - if (i & n) { - fnm1 = fn; - fn = fnp1; - zadd(fnm1, fn, &fnp1); - } else { - zsub(fnp1, fn, &fnm1); - } - i >>= (FULL)1; - } - zfree(fnm1); - zfree(fnp1); - *res = fn; - res->sign = (bool)sign; + if (zge31b(z)) { + math_error("Very large Fibonacci number"); + not_reached(); + } + n = ztolong(z); + if (n == 0) { + *res = _zero_; + return; + } + sign = z.sign && ((n & 0x1) == 0); + if (n <= 2) { + *res = _one_; + res->sign = (bool)sign; + return; + } + i = TOPFULL; + while ((i & n) == 0) + i >>= (FULL)1; + i >>= (FULL)1; + fnm1 = _zero_; + fn = _one_; + fnp1 = _one_; + while (i) { + zsquare(fnm1, &t1); + zsquare(fn, &t2); + zsquare(fnp1, &t3); + zfree(fnm1); + zfree(fn); + zfree(fnp1); + zadd(t2, t3, &fnp1); + zsub(t3, t1, &fn); + zfree(t1); + zfree(t2); + zfree(t3); + if (i & n) { + fnm1 = fn; + fn = fnp1; + zadd(fnm1, fn, &fnp1); + } else { + zsub(fnp1, fn, &fnm1); + } + i >>= (FULL)1; + } + zfree(fnm1); + zfree(fnp1); + *res = fn; + res->sign = (bool)sign; } @@ -554,131 +554,131 @@ zfib(ZVALUE z, ZVALUE *res) void zpowi(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - int sign; /* final sign of number */ - unsigned long power; /* power to raise to */ - FULL bit; /* current bit value */ - long twos; /* count of times 2 is in result */ - ZVALUE ans, temp; + int sign; /* final sign of number */ + unsigned long power; /* power to raise to */ + FULL bit; /* current bit value */ + long twos; /* count of times 2 is in result */ + ZVALUE ans, temp; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - sign = (z1.sign && zisodd(z2)); - z1.sign = 0; - z2.sign = 0; - if (ziszero(z2) && !ziszero(z1)) { /* number raised to power 0 */ - *res = _one_; - return; - } - if (zisabsleone(z1)) { /* 0, 1, or -1 raised to a power */ - ans = _one_; - ans.sign = (bool)sign; - if (*z1.v == 0) - ans = _zero_; - *res = ans; - return; - } - if (zge31b(z2)) { - math_error("Raising to very large power"); - not_reached(); - } - power = ztoulong(z2); - if (zistwo(z1)) { /* two raised to a power */ - zbitvalue((long) power, res); - return; - } - /* - * See if this is a power of ten - */ - if (zistiny(z1) && (*z1.v == 10)) { - ztenpow((long) power, res); - res->sign = (bool)sign; - return; - } - /* - * Handle low powers specially - */ - if (power <= 4) { - switch ((int) power) { - case 1: - ans.len = z1.len; - ans.v = alloc(ans.len); - zcopyval(z1, ans); - ans.sign = (bool)sign; - *res = ans; - return; - case 2: - zsquare(z1, res); - return; - case 3: - zsquare(z1, &temp); - zmul(z1, temp, res); - zfree(temp); - res->sign = (bool)sign; - return; - case 4: - zsquare(z1, &temp); - zsquare(temp, res); - zfree(temp); - return; - } - } - /* - * Shift out all powers of twos so the multiplies are smaller. - * We will shift back the right amount when done. - */ - twos = 0; - if (ziseven(z1)) { - twos = zlowbit(z1); - ans.v = alloc(z1.len); - ans.len = z1.len; - ans.sign = z1.sign; - zcopyval(z1, ans); - zshiftr(ans, twos); - ztrim(&ans); - z1 = ans; - twos *= power; - } - /* - * Compute the power by squaring and multiplying. - * This uses the left to right method of power raising. - */ - bit = TOPFULL; - while ((bit & power) == 0) - bit >>= 1; - bit >>= 1; - zsquare(z1, &ans); - if (bit & power) { - zmul(ans, z1, &temp); - zfree(ans); - ans = temp; - } - bit >>= 1; - while (bit) { - zsquare(ans, &temp); - zfree(ans); - ans = temp; - if (bit & power) { - zmul(ans, z1, &temp); - zfree(ans); - ans = temp; - } - bit >>= 1; - } - /* - * Scale back up by proper power of two - */ - if (twos) { - zshift(ans, twos, &temp); - zfree(ans); - ans = temp; - zfree(z1); - } - ans.sign = (bool)sign; - *res = ans; + sign = (z1.sign && zisodd(z2)); + z1.sign = 0; + z2.sign = 0; + if (ziszero(z2) && !ziszero(z1)) { /* number raised to power 0 */ + *res = _one_; + return; + } + if (zisabsleone(z1)) { /* 0, 1, or -1 raised to a power */ + ans = _one_; + ans.sign = (bool)sign; + if (*z1.v == 0) + ans = _zero_; + *res = ans; + return; + } + if (zge31b(z2)) { + math_error("Raising to very large power"); + not_reached(); + } + power = ztoulong(z2); + if (zistwo(z1)) { /* two raised to a power */ + zbitvalue((long) power, res); + return; + } + /* + * See if this is a power of ten + */ + if (zistiny(z1) && (*z1.v == 10)) { + ztenpow((long) power, res); + res->sign = (bool)sign; + return; + } + /* + * Handle low powers specially + */ + if (power <= 4) { + switch ((int) power) { + case 1: + ans.len = z1.len; + ans.v = alloc(ans.len); + zcopyval(z1, ans); + ans.sign = (bool)sign; + *res = ans; + return; + case 2: + zsquare(z1, res); + return; + case 3: + zsquare(z1, &temp); + zmul(z1, temp, res); + zfree(temp); + res->sign = (bool)sign; + return; + case 4: + zsquare(z1, &temp); + zsquare(temp, res); + zfree(temp); + return; + } + } + /* + * Shift out all powers of twos so the multiplies are smaller. + * We will shift back the right amount when done. + */ + twos = 0; + if (ziseven(z1)) { + twos = zlowbit(z1); + ans.v = alloc(z1.len); + ans.len = z1.len; + ans.sign = z1.sign; + zcopyval(z1, ans); + zshiftr(ans, twos); + ztrim(&ans); + z1 = ans; + twos *= power; + } + /* + * Compute the power by squaring and multiplying. + * This uses the left to right method of power raising. + */ + bit = TOPFULL; + while ((bit & power) == 0) + bit >>= 1; + bit >>= 1; + zsquare(z1, &ans); + if (bit & power) { + zmul(ans, z1, &temp); + zfree(ans); + ans = temp; + } + bit >>= 1; + while (bit) { + zsquare(ans, &temp); + zfree(ans); + ans = temp; + if (bit & power) { + zmul(ans, z1, &temp); + zfree(ans); + ans = temp; + } + bit >>= 1; + } + /* + * Scale back up by proper power of two + */ + if (twos) { + zshift(ans, twos, &temp); + zfree(ans); + ans = temp; + zfree(z1); + } + ans.sign = (bool)sign; + *res = ans; } @@ -689,39 +689,39 @@ zpowi(ZVALUE z1, ZVALUE z2, ZVALUE *res) void ztenpow(long power, ZVALUE *res) { - long i; - ZVALUE ans; - ZVALUE temp; + long i; + ZVALUE ans; + ZVALUE temp; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (power <= 0) { - *res = _one_; - return; - } - ans = _one_; - _tenpowers_[0] = _ten_; - for (i = 0; power; i++) { - if (_tenpowers_[i].len == 0) { - if (i <= TEN_MAX) { - zsquare(_tenpowers_[i-1], &_tenpowers_[i]); - } else { - math_error("cannot compute 10^2^(TEN_MAX+1)"); - not_reached(); - } - } - if (power & 0x1) { - zmul(ans, _tenpowers_[i], &temp); - zfree(ans); - ans = temp; - } - power /= 2; - } - *res = ans; + if (power <= 0) { + *res = _one_; + return; + } + ans = _one_; + _tenpowers_[0] = _ten_; + for (i = 0; power; i++) { + if (_tenpowers_[i].len == 0) { + if (i <= TEN_MAX) { + zsquare(_tenpowers_[i-1], &_tenpowers_[i]); + } else { + math_error("cannot compute 10^2^(TEN_MAX+1)"); + not_reached(); + } + } + if (power & 0x1) { + zmul(ans, _tenpowers_[i], &temp); + zfree(ans); + ans = temp; + } + power /= 2; + } + *res = ans; } @@ -735,162 +735,162 @@ ztenpow(long power, ZVALUE *res) bool zmodinv(ZVALUE u, ZVALUE v, ZVALUE *res) { - FULL q1, q2, ui3, vi3, uh, vh, A, B, C, D, T; - ZVALUE u2, u3, v2, v3, qz, tmp1, tmp2, tmp3; + FULL q1, q2, ui3, vi3, uh, vh, A, B, C, D, T; + ZVALUE u2, u3, v2, v3, qz, tmp1, tmp2, tmp3; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - v.sign = 0; - if (zisneg(u) || (zrel(u, v) >= 0)) - zmod(u, v, &v3, 0); - else - zcopy(u, &v3); - zcopy(v, &u3); - u2 = _zero_; - v2 = _one_; + v.sign = 0; + if (zisneg(u) || (zrel(u, v) >= 0)) + zmod(u, v, &v3, 0); + else + zcopy(u, &v3); + zcopy(v, &u3); + u2 = _zero_; + v2 = _one_; - /* - * Loop here while the size of the numbers remain above - * the size of a HALF. Throughout this loop u3 >= v3. - */ - while ((u3.len > 1) && !ziszero(v3)) { - vh = 0; + /* + * Loop here while the size of the numbers remain above + * the size of a HALF. Throughout this loop u3 >= v3. + */ + while ((u3.len > 1) && !ziszero(v3)) { + vh = 0; #if LONG_BITS == BASEB - uh = u3.v[u3.len - 1]; - if (v3.len == u3.len) - vh = v3.v[v3.len - 1]; + uh = u3.v[u3.len - 1]; + if (v3.len == u3.len) + vh = v3.v[v3.len - 1]; #else - uh = (((FULL) u3.v[u3.len - 1]) << BASEB) + u3.v[u3.len - 2]; - if ((v3.len + 1) >= u3.len) - vh = v3.v[v3.len - 1]; - if (v3.len == u3.len) - vh = (vh << BASEB) + v3.v[v3.len - 2]; + uh = (((FULL) u3.v[u3.len - 1]) << BASEB) + u3.v[u3.len - 2]; + if ((v3.len + 1) >= u3.len) + vh = v3.v[v3.len - 1]; + if (v3.len == u3.len) + vh = (vh << BASEB) + v3.v[v3.len - 2]; #endif - A = 1; - B = 0; - C = 0; - D = 1; + A = 1; + B = 0; + C = 0; + D = 1; - /* - * Calculate successive quotients of the continued fraction - * expansion using only single precision arithmetic until - * greater precision is required. - */ - while ((vh + C) && (vh + D)) { - q1 = (uh + A) / (vh + C); - q2 = (uh + B) / (vh + D); - if (q1 != q2) - break; - T = A - q1 * C; - A = C; - C = T; - T = B - q1 * D; - B = D; - D = T; - T = uh - q1 * vh; - uh = vh; - vh = T; - } + /* + * Calculate successive quotients of the continued fraction + * expansion using only single precision arithmetic until + * greater precision is required. + */ + while ((vh + C) && (vh + D)) { + q1 = (uh + A) / (vh + C); + q2 = (uh + B) / (vh + D); + if (q1 != q2) + break; + T = A - q1 * C; + A = C; + C = T; + T = B - q1 * D; + B = D; + D = T; + T = uh - q1 * vh; + uh = vh; + vh = T; + } - /* - * If B is zero, then we made no progress because - * the calculation requires a very large quotient. - * So we must do this step of the calculation in - * full precision - */ - if (B == 0) { - zquo(u3, v3, &qz, 0); - zmul(qz, v2, &tmp1); - zsub(u2, tmp1, &tmp2); - zfree(tmp1); - zfree(u2); - u2 = v2; - v2 = tmp2; - zmul(qz, v3, &tmp1); - zsub(u3, tmp1, &tmp2); - zfree(tmp1); - zfree(u3); - u3 = v3; - v3 = tmp2; - zfree(qz); - continue; - } - /* - * Apply the calculated A,B,C,D numbers to the current - * values to update them as if the full precision - * calculations had been carried out. - */ - zmuli(u2, (long) A, &tmp1); - zmuli(v2, (long) B, &tmp2); - zadd(tmp1, tmp2, &tmp3); - zfree(tmp1); - zfree(tmp2); - zmuli(u2, (long) C, &tmp1); - zmuli(v2, (long) D, &tmp2); - zfree(u2); - zfree(v2); - u2 = tmp3; - zadd(tmp1, tmp2, &v2); - zfree(tmp1); - zfree(tmp2); - zmuli(u3, (long) A, &tmp1); - zmuli(v3, (long) B, &tmp2); - zadd(tmp1, tmp2, &tmp3); - zfree(tmp1); - zfree(tmp2); - zmuli(u3, (long) C, &tmp1); - zmuli(v3, (long) D, &tmp2); - zfree(u3); - zfree(v3); - u3 = tmp3; - zadd(tmp1, tmp2, &v3); - zfree(tmp1); - zfree(tmp2); - } + /* + * If B is zero, then we made no progress because + * the calculation requires a very large quotient. + * So we must do this step of the calculation in + * full precision + */ + if (B == 0) { + zquo(u3, v3, &qz, 0); + zmul(qz, v2, &tmp1); + zsub(u2, tmp1, &tmp2); + zfree(tmp1); + zfree(u2); + u2 = v2; + v2 = tmp2; + zmul(qz, v3, &tmp1); + zsub(u3, tmp1, &tmp2); + zfree(tmp1); + zfree(u3); + u3 = v3; + v3 = tmp2; + zfree(qz); + continue; + } + /* + * Apply the calculated A,B,C,D numbers to the current + * values to update them as if the full precision + * calculations had been carried out. + */ + zmuli(u2, (long) A, &tmp1); + zmuli(v2, (long) B, &tmp2); + zadd(tmp1, tmp2, &tmp3); + zfree(tmp1); + zfree(tmp2); + zmuli(u2, (long) C, &tmp1); + zmuli(v2, (long) D, &tmp2); + zfree(u2); + zfree(v2); + u2 = tmp3; + zadd(tmp1, tmp2, &v2); + zfree(tmp1); + zfree(tmp2); + zmuli(u3, (long) A, &tmp1); + zmuli(v3, (long) B, &tmp2); + zadd(tmp1, tmp2, &tmp3); + zfree(tmp1); + zfree(tmp2); + zmuli(u3, (long) C, &tmp1); + zmuli(v3, (long) D, &tmp2); + zfree(u3); + zfree(v3); + u3 = tmp3; + zadd(tmp1, tmp2, &v3); + zfree(tmp1); + zfree(tmp2); + } - /* - * Here when the remaining numbers become single precision in size. - * Finish the procedure using single precision calculations. - */ - if (ziszero(v3) && !zisone(u3)) { - zfree(u3); - zfree(v3); - zfree(u2); - zfree(v2); - return true; - } - ui3 = ztofull(u3); - vi3 = ztofull(v3); - zfree(u3); - zfree(v3); - while (vi3) { - q1 = ui3 / vi3; - zmuli(v2, (long) q1, &tmp1); - zsub(u2, tmp1, &tmp2); - zfree(tmp1); - zfree(u2); - u2 = v2; - v2 = tmp2; - q2 = ui3 - q1 * vi3; - ui3 = vi3; - vi3 = q2; - } - zfree(v2); - if (ui3 != 1) { - zfree(u2); - return true; - } - if (zisneg(u2)) { - zadd(v, u2, res); - zfree(u2); - return false; - } - *res = u2; - return false; + /* + * Here when the remaining numbers become single precision in size. + * Finish the procedure using single precision calculations. + */ + if (ziszero(v3) && !zisone(u3)) { + zfree(u3); + zfree(v3); + zfree(u2); + zfree(v2); + return true; + } + ui3 = ztofull(u3); + vi3 = ztofull(v3); + zfree(u3); + zfree(v3); + while (vi3) { + q1 = ui3 / vi3; + zmuli(v2, (long) q1, &tmp1); + zsub(u2, tmp1, &tmp2); + zfree(tmp1); + zfree(u2); + u2 = v2; + v2 = tmp2; + q2 = ui3 - q1 * vi3; + ui3 = vi3; + vi3 = q2; + } + zfree(v2); + if (ui3 != 1) { + zfree(u2); + return true; + } + if (zisneg(u2)) { + zadd(v, u2, res); + zfree(u2); + return false; + } + *res = u2; + return false; } @@ -900,328 +900,328 @@ zmodinv(ZVALUE u, ZVALUE v, ZVALUE *res) void zgcd(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - int h, i, j, k; - LEN len, l, m, n, o, p, q; - HALF u, v, w, x; - HALF *a, *a0, *A, *b, *b0, *B, *c, *d; - FULL f, g; - ZVALUE gcd; - bool needw; + int h, i, j, k; + LEN len, l, m, n, o, p, q; + HALF u, v, w, x; + HALF *a, *a0, *A, *b, *b0, *B, *c, *d; + FULL f, g; + ZVALUE gcd; + bool needw; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (zisunit(z1) || zisunit(z2)) { - *res = _one_; - return; - } - z1.sign = 0; - z2.sign = 0; - if (ziszero(z1) || !zcmp(z1, z2)) { - zcopy(z2, res); - return; - } - if (ziszero(z2)) { - zcopy(z1, res); - return; - } + if (zisunit(z1) || zisunit(z2)) { + *res = _one_; + return; + } + z1.sign = 0; + z2.sign = 0; + if (ziszero(z1) || !zcmp(z1, z2)) { + zcopy(z2, res); + return; + } + if (ziszero(z2)) { + zcopy(z1, res); + return; + } - o = 0; - while (!(z1.v[o] | z2.v[o])) o++; /* Count common zero digits */ + o = 0; + while (!(z1.v[o] | z2.v[o])) o++; /* Count common zero digits */ - c = z1.v + o; - d = z2.v + o; + c = z1.v + o; + d = z2.v + o; - m = z1.len - o; - n = z2.len - o; - u = *c | *d; /* Count common zero bits */ - v = 1; - p = 0; - while (!(u & v)) { - v <<= 1; - p++; - } + m = z1.len - o; + n = z2.len - o; + u = *c | *d; /* Count common zero bits */ + v = 1; + p = 0; + while (!(u & v)) { + v <<= 1; + p++; + } - while (!*c) { /* Removing zero digits */ - c++; - m--; - } + while (!*c) { /* Removing zero digits */ + c++; + m--; + } - while (!*d) { - d++; - n--; - } + while (!*d) { + d++; + n--; + } - u = *d; /* Count zero bits for *d */ - v = 1; - q = 0; - while (!(u & v)) { - v <<= 1; - q++; - } + u = *d; /* Count zero bits for *d */ + v = 1; + q = 0; + while (!(u & v)) { + v <<= 1; + q++; + } - a0 = A = alloc(m); - b0 = B = alloc(n); + a0 = A = alloc(m); + b0 = B = alloc(n); - memcpy(A, c, m * sizeof(HALF)); /* Copy c[] to A[] */ + memcpy(A, c, m * sizeof(HALF)); /* Copy c[] to A[] */ - /* Copy d[] to B[], shifting if necessary */ - if (q) { - i = n; - b = B + n; - d += n; - f = 0; - while (i--) { - f = f << BASEB | *--d; - *--b = (HALF) (f >> q); - } - if (B[n-1] == 0) n--; - } - else memcpy(B, d, n * sizeof(HALF)); + /* Copy d[] to B[], shifting if necessary */ + if (q) { + i = n; + b = B + n; + d += n; + f = 0; + while (i--) { + f = f << BASEB | *--d; + *--b = (HALF) (f >> q); + } + if (B[n-1] == 0) n--; + } + else memcpy(B, d, n * sizeof(HALF)); - if (n == 1) { /* One digit case; use Euclid's algorithm */ - n = m; - b0 = A; - m = 1; - a0 = B; - if (m == 1) { /* a has one digit */ - v = *a0; - if (v > 1) { /* Euclid's algorithm */ - b = b0 + n; - i = n; - u = 0; - while (i--) { - f = (FULL) u << BASEB | *--b; - u = (HALF) (f % v); - } - while (u) { w = v % u; v = u; u = w; } - } - *b0 = v; - n = 1; - } - len = n + o; - gcd.v = alloc(len + 1); - /* Common zero digits */ - if (o) memset(gcd.v, 0, o * sizeof(HALF)); - /* Left shift for common zero bits */ - if (p) { - i = n; - f = 0; - b = b0; - a = gcd.v + o; - while (i--) { - f = f >> BASEB | (FULL) *b++ << p; - *a++ = (HALF) f; - } - if (f >>= BASEB) {len++; *a = (HALF) f;} - } else { - memcpy(gcd.v + o, b0, n * sizeof(HALF)); - } - gcd.len = len; - gcd.sign = 0; - freeh(A); - freeh(B); - *res = gcd; - return; - } + if (n == 1) { /* One digit case; use Euclid's algorithm */ + n = m; + b0 = A; + m = 1; + a0 = B; + if (m == 1) { /* a has one digit */ + v = *a0; + if (v > 1) { /* Euclid's algorithm */ + b = b0 + n; + i = n; + u = 0; + while (i--) { + f = (FULL) u << BASEB | *--b; + u = (HALF) (f % v); + } + while (u) { w = v % u; v = u; u = w; } + } + *b0 = v; + n = 1; + } + len = n + o; + gcd.v = alloc(len + 1); + /* Common zero digits */ + if (o) memset(gcd.v, 0, o * sizeof(HALF)); + /* Left shift for common zero bits */ + if (p) { + i = n; + f = 0; + b = b0; + a = gcd.v + o; + while (i--) { + f = f >> BASEB | (FULL) *b++ << p; + *a++ = (HALF) f; + } + if (f >>= BASEB) {len++; *a = (HALF) f;} + } else { + memcpy(gcd.v + o, b0, n * sizeof(HALF)); + } + gcd.len = len; + gcd.sign = 0; + freeh(A); + freeh(B); + *res = gcd; + return; + } - u = B[n-1]; /* Bit count for b */ - k = (n - 1) * BASEB; - while (u >>= 1) k++; + u = B[n-1]; /* Bit count for b */ + k = (n - 1) * BASEB; + while (u >>= 1) k++; - needw = true; + needw = true; - w = 0; - j = 0; - while (m) { /* START OF MAIN LOOP */ - if (m - n < 2 || needw) { - q = 0; - u = *a0; - v = 1; - while (!(u & v)) { /* count zero bits for *a0 */ - q++; - v <<= 1; - } + w = 0; + j = 0; + while (m) { /* START OF MAIN LOOP */ + if (m - n < 2 || needw) { + q = 0; + u = *a0; + v = 1; + while (!(u & v)) { /* count zero bits for *a0 */ + q++; + v <<= 1; + } - if (q) { /* right-justify a */ - a = a0 + m; - i = m; - f = 0; - while (i--) { - f = f << BASEB | *--a; - *a = (HALF) (f >> q); - } - if (!a0[m-1]) m--; /* top digit vanishes */ - } + if (q) { /* right-justify a */ + a = a0 + m; + i = m; + f = 0; + while (i--) { + f = f << BASEB | *--a; + *a = (HALF) (f >> q); + } + if (!a0[m-1]) m--; /* top digit vanishes */ + } - if (m == 1) break; + if (m == 1) break; - u = a0[m-1]; - j = (m - 1) * BASEB; - while (u >>= 1) j++; /* counting bits for a */ - h = j - k; - if (h < 0) { /* swapping to get h > 0 */ - l = m; - m = n; - n = l; - a = a0; - a0 = b0; - b0 = a; - k = j; - h = -h; - needw = true; - } - if (h > 1) { - if (needw) { /* find w = minv(*b0, h0) */ - u = 1; - v = *b0; - w = 0; - x = 1; - i = h; - while (i-- && x) { - if (u & x) { u -= v * x; w |= x;} - x <<= 1; - } - needw = false; - } - g = (FULL) (*a0 * w); - if (h < BASEB) { - g &= (FULL)lowhalf[h]; - } else { - g &= BASE1; - } - } else { - g = 1; - } - } else { - g = (FULL) (*a0 * w); - } - a = a0; - b = b0; - i = n; - if (g > 1) { /* a - g * b case */ - f = 0; - while (i--) { - f = (FULL) *a - g * *b++ - f; - *a++ = (HALF) f; - f >>= BASEB; - f = -f & BASE1; - } - if (f) { - i = m - n; - while (i-- && f) { - f = *a - f; - *a++ = (HALF) f; - f >>= BASEB; - f = -f & BASE1; - } - } - while (m && !*a0) { /* Removing trailing zeros */ - m--; - a0++; - } - if (f) { /* a - g * b < 0 */ - while (m > 1 && a0[m-1] == BASE1) m--; - *a0 = - *a0; - a = a0; - i = m; - while (--i) { - a++; - *a = ~*a; - } - } - } else { /* abs(a - b) case */ - while (i && *a++ == *b++) i--; - q = n - i; - if (m == n) { /* a and b same length */ - if (i) { /* a not equal to b */ - while (m && a0[m-1] == b0[m-1]) m--; - if (a0[m-1] < b0[m-1]) { - /* Swapping since a < b */ - a = a0; - a0 = b0; - b0 = a; - k = j; - } - a = a0 + q; - b = b0 + q; - i = m - q; - f = 0; - while (i--) { - f = (FULL) *a - *b++ - f; - *a++ = (HALF) f; - f >>= BASEB; - f = -f & BASE1; - } - } - } else { /* a has more digits than b */ - a = a0 + q; - b = b0 + q; - i = n - q; - f = 0; - while (i--) { - f = (FULL) *a - *b++ - f; - *a++ = (HALF) f; - f >>= BASEB; - f = -f & BASE1; - } - if (f) { while (!*a) *a++ = BASE1; - (*a)--; - } - } - a0 += q; - m -= q; - while (m && !*a0) { /* Removing trailing zeros */ - m--; - a0++; - } - } - while (m && !a0[m-1]) m--; /* Removing leading zeros */ - } - if (m == 1) { /* a has one digit */ - v = *a0; - if (v > 1) { /* Euclid's algorithm */ - b = b0 + n; - i = n; - u = 0; - while (i--) { - f = (FULL) u << BASEB | *--b; - u = (HALF) (f % v); - } - while (u) { w = v % u; v = u; u = w; } - } - *b0 = v; - n = 1; - } - len = n + o; - gcd.v = alloc(len + 1); - if (o) memset(gcd.v, 0, o * sizeof(HALF)); /* Common zero digits */ - if (p) { /* Left shift for common zero bits */ - i = n; - f = 0; - b = b0; - a = gcd.v + o; - while (i--) { - f = (FULL) *b++ << p | f; - *a++ = (HALF) f; - f >>= BASEB; - } - if (f) { - len++; *a = (HALF) f; - } - } else { - memcpy(gcd.v + o, b0, n * sizeof(HALF)); - } - gcd.len = len; - gcd.sign = 0; - freeh(A); - freeh(B); - *res = gcd; - return; + u = a0[m-1]; + j = (m - 1) * BASEB; + while (u >>= 1) j++; /* counting bits for a */ + h = j - k; + if (h < 0) { /* swapping to get h > 0 */ + l = m; + m = n; + n = l; + a = a0; + a0 = b0; + b0 = a; + k = j; + h = -h; + needw = true; + } + if (h > 1) { + if (needw) { /* find w = minv(*b0, h0) */ + u = 1; + v = *b0; + w = 0; + x = 1; + i = h; + while (i-- && x) { + if (u & x) { u -= v * x; w |= x;} + x <<= 1; + } + needw = false; + } + g = (FULL) (*a0 * w); + if (h < BASEB) { + g &= (FULL)lowhalf[h]; + } else { + g &= BASE1; + } + } else { + g = 1; + } + } else { + g = (FULL) (*a0 * w); + } + a = a0; + b = b0; + i = n; + if (g > 1) { /* a - g * b case */ + f = 0; + while (i--) { + f = (FULL) *a - g * *b++ - f; + *a++ = (HALF) f; + f >>= BASEB; + f = -f & BASE1; + } + if (f) { + i = m - n; + while (i-- && f) { + f = *a - f; + *a++ = (HALF) f; + f >>= BASEB; + f = -f & BASE1; + } + } + while (m && !*a0) { /* Removing trailing zeros */ + m--; + a0++; + } + if (f) { /* a - g * b < 0 */ + while (m > 1 && a0[m-1] == BASE1) m--; + *a0 = - *a0; + a = a0; + i = m; + while (--i) { + a++; + *a = ~*a; + } + } + } else { /* abs(a - b) case */ + while (i && *a++ == *b++) i--; + q = n - i; + if (m == n) { /* a and b same length */ + if (i) { /* a not equal to b */ + while (m && a0[m-1] == b0[m-1]) m--; + if (a0[m-1] < b0[m-1]) { + /* Swapping since a < b */ + a = a0; + a0 = b0; + b0 = a; + k = j; + } + a = a0 + q; + b = b0 + q; + i = m - q; + f = 0; + while (i--) { + f = (FULL) *a - *b++ - f; + *a++ = (HALF) f; + f >>= BASEB; + f = -f & BASE1; + } + } + } else { /* a has more digits than b */ + a = a0 + q; + b = b0 + q; + i = n - q; + f = 0; + while (i--) { + f = (FULL) *a - *b++ - f; + *a++ = (HALF) f; + f >>= BASEB; + f = -f & BASE1; + } + if (f) { while (!*a) *a++ = BASE1; + (*a)--; + } + } + a0 += q; + m -= q; + while (m && !*a0) { /* Removing trailing zeros */ + m--; + a0++; + } + } + while (m && !a0[m-1]) m--; /* Removing leading zeros */ + } + if (m == 1) { /* a has one digit */ + v = *a0; + if (v > 1) { /* Euclid's algorithm */ + b = b0 + n; + i = n; + u = 0; + while (i--) { + f = (FULL) u << BASEB | *--b; + u = (HALF) (f % v); + } + while (u) { w = v % u; v = u; u = w; } + } + *b0 = v; + n = 1; + } + len = n + o; + gcd.v = alloc(len + 1); + if (o) memset(gcd.v, 0, o * sizeof(HALF)); /* Common zero digits */ + if (p) { /* Left shift for common zero bits */ + i = n; + f = 0; + b = b0; + a = gcd.v + o; + while (i--) { + f = (FULL) *b++ << p | f; + *a++ = (HALF) f; + f >>= BASEB; + } + if (f) { + len++; *a = (HALF) f; + } + } else { + memcpy(gcd.v + o, b0, n * sizeof(HALF)); + } + gcd.len = len; + gcd.sign = 0; + freeh(A); + freeh(B); + *res = gcd; + return; } /* @@ -1231,19 +1231,19 @@ zgcd(ZVALUE z1, ZVALUE z2, ZVALUE *res) void zlcm(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - ZVALUE temp1, temp2; + ZVALUE temp1, temp2; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - zgcd(z1, z2, &temp1); - zequo(z1, temp1, &temp2); - zfree(temp1); - zmul(temp2, z2, res); - zfree(temp2); + zgcd(z1, z2, &temp1); + zequo(z1, temp1, &temp2); + zfree(temp1); + zmul(temp2, z2, res); + zfree(temp2); } @@ -1253,54 +1253,54 @@ zlcm(ZVALUE z1, ZVALUE z2, ZVALUE *res) bool zrelprime(ZVALUE z1, ZVALUE z2) { - FULL rem1, rem2; /* remainders */ - ZVALUE rem; - bool result; + FULL rem1, rem2; /* remainders */ + ZVALUE rem; + bool result; - z1.sign = 0; - z2.sign = 0; - if (ziseven(z1) && ziseven(z2)) /* false if both even */ - return false; - if (zisunit(z1) || zisunit(z2)) /* true if either is a unit */ - return true; - if (ziszero(z1) || ziszero(z2)) /* false if either is zero */ - return false; - if (zistwo(z1) || zistwo(z2)) /* true if either is two */ - return true; - /* - * Try reducing each number by the product of the first few odd primes - * to see if any of them are a common factor. - */ - rem1 = zmodi(z1, (FULL)3 * 5 * 7 * 11 * 13); - rem2 = zmodi(z2, (FULL)3 * 5 * 7 * 11 * 13); - if (((rem1 % 3) == 0) && ((rem2 % 3) == 0)) - return false; - if (((rem1 % 5) == 0) && ((rem2 % 5) == 0)) - return false; - if (((rem1 % 7) == 0) && ((rem2 % 7) == 0)) - return false; - if (((rem1 % 11) == 0) && ((rem2 % 11) == 0)) - return false; - if (((rem1 % 13) == 0) && ((rem2 % 13) == 0)) - return false; - /* - * Try a new batch of primes now - */ - rem1 = zmodi(z1, (FULL)17 * 19 * 23); - rem2 = zmodi(z2, (FULL)17 * 19 * 23); - if (((rem1 % 17) == 0) && ((rem2 % 17) == 0)) - return false; - if (((rem1 % 19) == 0) && ((rem2 % 19) == 0)) - return false; - if (((rem1 % 23) == 0) && ((rem2 % 23) == 0)) - return false; - /* - * Yuk, we must actually compute the gcd to know the answer - */ - zgcd(z1, z2, &rem); - result = zisunit(rem); - zfree(rem); - return result; + z1.sign = 0; + z2.sign = 0; + if (ziseven(z1) && ziseven(z2)) /* false if both even */ + return false; + if (zisunit(z1) || zisunit(z2)) /* true if either is a unit */ + return true; + if (ziszero(z1) || ziszero(z2)) /* false if either is zero */ + return false; + if (zistwo(z1) || zistwo(z2)) /* true if either is two */ + return true; + /* + * Try reducing each number by the product of the first few odd primes + * to see if any of them are a common factor. + */ + rem1 = zmodi(z1, (FULL)3 * 5 * 7 * 11 * 13); + rem2 = zmodi(z2, (FULL)3 * 5 * 7 * 11 * 13); + if (((rem1 % 3) == 0) && ((rem2 % 3) == 0)) + return false; + if (((rem1 % 5) == 0) && ((rem2 % 5) == 0)) + return false; + if (((rem1 % 7) == 0) && ((rem2 % 7) == 0)) + return false; + if (((rem1 % 11) == 0) && ((rem2 % 11) == 0)) + return false; + if (((rem1 % 13) == 0) && ((rem2 % 13) == 0)) + return false; + /* + * Try a new batch of primes now + */ + rem1 = zmodi(z1, (FULL)17 * 19 * 23); + rem2 = zmodi(z2, (FULL)17 * 19 * 23); + if (((rem1 % 17) == 0) && ((rem2 % 17) == 0)) + return false; + if (((rem1 % 19) == 0) && ((rem2 % 19) == 0)) + return false; + if (((rem1 % 23) == 0) && ((rem2 % 23) == 0)) + return false; + /* + * Yuk, we must actually compute the gcd to know the answer + */ + zgcd(z1, z2, &rem); + result = zisunit(rem); + zfree(rem); + return result; } @@ -1312,70 +1312,70 @@ zrelprime(ZVALUE z1, ZVALUE z2) long zlog(ZVALUE z, ZVALUE base) { - ZVALUE *zp; /* current square */ - long power; /* current power */ - ZVALUE temp; /* temporary */ - ZVALUE squares[32]; /* table of squares of base */ + ZVALUE *zp; /* current square */ + long power; /* current power */ + ZVALUE temp; /* temporary */ + ZVALUE squares[32]; /* table of squares of base */ - /* ignore signs */ + /* ignore signs */ - z.sign = 0; - base.sign = 0; + z.sign = 0; + base.sign = 0; - /* - * Make sure that the numbers are nonzero and the base is > 1 - */ - if (ziszero(z) || ziszero(base) || zisone(base)) { - math_error("Zero or too small argument argument for zlog!!!"); - not_reached(); - } + /* + * Make sure that the numbers are nonzero and the base is > 1 + */ + if (ziszero(z) || ziszero(base) || zisone(base)) { + math_error("Zero or too small argument argument for zlog!!!"); + not_reached(); + } - /* - * Some trivial cases. - */ - power = zrel(z, base); - if (power <= 0) - return (power + 1); + /* + * Some trivial cases. + */ + power = zrel(z, base); + if (power <= 0) + return (power + 1); - /* base - power of two */ - if (zisonebit(base)) - return (zhighbit(z) / zlowbit(base)); + /* base - power of two */ + if (zisonebit(base)) + return (zhighbit(z) / zlowbit(base)); - /* base = 10 */ - if (base.len == 1 && base.v[0] == 10) - return zlog10(z, NULL); - /* - * Now loop by squaring the base each time, and see whether or - * not each successive square is still smaller than the number. - */ - zp = &squares[0]; - *zp = base; - while (zp->len * 2 - 1 <= z.len && zrel(z, *zp) > 0) { - /* while square not too large */ - zsquare(*zp, zp + 1); - zp++; - } + /* base = 10 */ + if (base.len == 1 && base.v[0] == 10) + return zlog10(z, NULL); + /* + * Now loop by squaring the base each time, and see whether or + * not each successive square is still smaller than the number. + */ + zp = &squares[0]; + *zp = base; + while (zp->len * 2 - 1 <= z.len && zrel(z, *zp) > 0) { + /* while square not too large */ + zsquare(*zp, zp + 1); + zp++; + } - /* - * Now back down the squares, - */ - power = 0; - for (; zp > squares; zp--) { - if (zrel(z, *zp) >= 0) { - zquo(z, *zp, &temp, 0); - if (power) - zfree(z); - z = temp; - power++; - } - zfree(*zp); - power <<= 1; - } - if (zrel(z, *zp) >= 0) - power++; - if (power > 1) - zfree(z); - return power; + /* + * Now back down the squares, + */ + power = 0; + for (; zp > squares; zp--) { + if (zrel(z, *zp) >= 0) { + zquo(z, *zp, &temp, 0); + if (power) + zfree(z); + z = temp; + power++; + } + zfree(*zp); + power <<= 1; + } + if (zrel(z, *zp) >= 0) + power++; + if (power > 1) + zfree(z); + return power; } @@ -1388,136 +1388,136 @@ zlog(ZVALUE z, ZVALUE base) long zlog10(ZVALUE z, bool *was_10_power) { - ZVALUE *zp; /* current square */ - long power; /* current power */ - ZVALUE temp; /* temporary */ - ZVALUE pow10; /* power of 10 */ - FLAG rel; /* relationship */ - int i; + ZVALUE *zp; /* current square */ + long power; /* current power */ + ZVALUE temp; /* temporary */ + ZVALUE pow10; /* power of 10 */ + FLAG rel; /* relationship */ + int i; - /* NOTE: It is OK if was_10_power == NULL */ + /* NOTE: It is OK if was_10_power == NULL */ - if (ziszero(z)) { - math_error("Zero argument argument for zlog10"); - not_reached(); - } + if (ziszero(z)) { + math_error("Zero argument argument for zlog10"); + not_reached(); + } - /* Ignore sign of z */ - z.sign = 0; + /* Ignore sign of z */ + z.sign = 0; - /* preload power10 table if missing */ - if (power10 == NULL) { - long v; + /* preload power10 table if missing */ + if (power10 == NULL) { + long v; - /* determine power10 table size */ - for (v=1, max_power10_exp=0; - v <= (long)(MAXLONG/10L); - v *= 10L, ++max_power10_exp) { - } + /* determine power10 table size */ + for (v=1, max_power10_exp=0; + v <= (long)(MAXLONG/10L); + v *= 10L, ++max_power10_exp) { + } - /* create power10 table */ - power10 = calloc(max_power10_exp+1, sizeof(long)); - if (power10 == NULL) { - math_error("cannot malloc power10 table"); - not_reached(); - } + /* create power10 table */ + power10 = calloc(max_power10_exp+1, sizeof(long)); + if (power10 == NULL) { + math_error("cannot malloc power10 table"); + not_reached(); + } - /* load power10 table */ - for (i=0, v = 1L; i < max_power10_exp; ++i, v *= 10L) { - power10[i] = v; - } - } + /* load power10 table */ + for (i=0, v = 1L; i < max_power10_exp; ++i, v *= 10L) { + power10[i] = v; + } + } - /* assume not a power of ten unless we find out otherwise */ - if (was_10_power != NULL) { - *was_10_power = false; - } + /* assume not a power of ten unless we find out otherwise */ + if (was_10_power != NULL) { + *was_10_power = false; + } - /* quick exit for small values */ - if (! zgtmaxlong(z)) { - long value = ztolong(z); + /* quick exit for small values */ + if (! zgtmaxlong(z)) { + long value = ztolong(z); - for (i=0; i <= max_power10_exp; ++i) { - if (value == power10[i]) { - if (was_10_power != NULL) { - *was_10_power = true; - } - return i; - } else if (value < power10[i]) { - return i-1; - } - } - } + for (i=0; i <= max_power10_exp; ++i) { + if (value == power10[i]) { + if (was_10_power != NULL) { + *was_10_power = true; + } + return i; + } else if (value < power10[i]) { + return i-1; + } + } + } - /* - * Loop by squaring the base each time, and see whether or - * not each successive square is still smaller than the number. - */ - zp = &_tenpowers_[0]; - *zp = _ten_; - while (((zp->len * 2) - 1) <= z.len) { /* while square not too large */ - if (zp >= &_tenpowers_[TEN_MAX]) { - math_error("Maximum storable power of 10 reached!"); - not_reached(); - } - if (zp[1].len == 0) - zsquare(*zp, zp + 1); - zp++; - } + /* + * Loop by squaring the base each time, and see whether or + * not each successive square is still smaller than the number. + */ + zp = &_tenpowers_[0]; + *zp = _ten_; + while (((zp->len * 2) - 1) <= z.len) { /* while square not too large */ + if (zp >= &_tenpowers_[TEN_MAX]) { + math_error("Maximum storable power of 10 reached!"); + not_reached(); + } + if (zp[1].len == 0) + zsquare(*zp, zp + 1); + zp++; + } - /* - * Now back down the squares, and multiply them together to see - * exactly how many times the base can be raised by. - */ - /* find the tenpower table entry < z */ - do { - rel = zrel(*zp, z); - if (rel == 0) { - /* quick return - we match a tenpower entry */ - if (was_10_power != NULL) { - *was_10_power = true; - } - return (1L << (zp - _tenpowers_)); - } - } while (rel > 0 && --zp >= _tenpowers_); - if (zp < _tenpowers_) { - math_error("fell off bottom of tenpower table!"); - not_reached(); - } + /* + * Now back down the squares, and multiply them together to see + * exactly how many times the base can be raised by. + */ + /* find the tenpower table entry < z */ + do { + rel = zrel(*zp, z); + if (rel == 0) { + /* quick return - we match a tenpower entry */ + if (was_10_power != NULL) { + *was_10_power = true; + } + return (1L << (zp - _tenpowers_)); + } + } while (rel > 0 && --zp >= _tenpowers_); + if (zp < _tenpowers_) { + math_error("fell off bottom of tenpower table!"); + not_reached(); + } - /* the tenpower value is now our starting comparison value */ - zcopy(*zp, &pow10); - power = (1L << (zp - _tenpowers_)); + /* the tenpower value is now our starting comparison value */ + zcopy(*zp, &pow10); + power = (1L << (zp - _tenpowers_)); - /* try to build up a power of 10 from tenpower table entries */ - while (--zp >= _tenpowers_) { + /* try to build up a power of 10 from tenpower table entries */ + while (--zp >= _tenpowers_) { - /* try the next lower tenpower value */ - zmul(pow10, *zp, &temp); - rel = zrel(temp, z); - if (rel == 0) { - /* exact power of 10 match */ - power += (1L << (zp - _tenpowers_)); - if (was_10_power != NULL) { - *was_10_power = true; - } - zfree(pow10); - zfree(temp); - return power; + /* try the next lower tenpower value */ + zmul(pow10, *zp, &temp); + rel = zrel(temp, z); + if (rel == 0) { + /* exact power of 10 match */ + power += (1L << (zp - _tenpowers_)); + if (was_10_power != NULL) { + *was_10_power = true; + } + zfree(pow10); + zfree(temp); + return power; - /* ignore this entry if we went too large */ - } else if (rel > 0) { - zfree(temp); + /* ignore this entry if we went too large */ + } else if (rel > 0) { + zfree(temp); - /* otherwise increase power and keep going */ - } else { - power += (1L << (zp - _tenpowers_)); - zfree(pow10); - pow10 = temp; - } - } - zfree(pow10); - return power; + /* otherwise increase power and keep going */ + } else { + power += (1L << (zp - _tenpowers_)); + zfree(pow10); + pow10 = temp; + } + } + zfree(pow10); + return power; } @@ -1529,14 +1529,14 @@ zlog10(ZVALUE z, bool *was_10_power) long zdivcount(ZVALUE z1, ZVALUE z2) { - long count; /* number of factors removed */ - ZVALUE tmp; /* ignored return value */ + long count; /* number of factors removed */ + ZVALUE tmp; /* ignored return value */ - if (ziszero(z1) || ziszero(z2) || zisunit(z2)) - return 0; - count = zfacrem(z1, z2, &tmp); - zfree(tmp); - return count; + if (ziszero(z1) || ziszero(z2) || zisunit(z2)) + return 0; + count = zfacrem(z1, z2, &tmp); + zfree(tmp); + return count; } @@ -1548,134 +1548,134 @@ zdivcount(ZVALUE z1, ZVALUE z2) long zfacrem(ZVALUE z1, ZVALUE z2, ZVALUE *rem) { - register ZVALUE *zp; /* current square */ - long count; /* total count of divisions */ - long worth; /* worth of current square */ - long lowbit; /* for zlowbit(z2) */ - ZVALUE temp1, temp2, temp3; /* temporaries */ - ZVALUE squares[32]; /* table of squares of factor */ + register ZVALUE *zp; /* current square */ + long count; /* total count of divisions */ + long worth; /* worth of current square */ + long lowbit; /* for zlowbit(z2) */ + ZVALUE temp1, temp2, temp3; /* temporaries */ + ZVALUE squares[32]; /* table of squares of factor */ - /* firewall */ - if (rem == NULL) { - math_error("%s: rem NULL", __func__); - not_reached(); - } + /* firewall */ + if (rem == NULL) { + math_error("%s: rem NULL", __func__); + not_reached(); + } - z1.sign = 0; - z2.sign = 0; - /* - * Reject trivial cases. - */ - if ((z1.len < z2.len) || (zisodd(z1) && ziseven(z2)) || - ziszero(z2) || zisone(z2) || - ((z1.len == z2.len) && (z1.v[z1.len-1] < z2.v[z2.len-1]))) { - rem->v = alloc(z1.len); - rem->len = z1.len; - rem->sign = 0; - zcopyval(z1, *rem); - return 0; - } - /* - * Handle any power of two special. - */ - if (zisonebit(z2)) { - lowbit = zlowbit(z2); - count = zlowbit(z1) / lowbit; - rem->v = alloc(z1.len); - rem->len = z1.len; - rem->sign = 0; - zcopyval(z1, *rem); - zshiftr(*rem, count * lowbit); - ztrim(rem); - return count; - } - /* - * See if the factor goes in even once. - */ - zdiv(z1, z2, &temp1, &temp2, 0); - if (!ziszero(temp2)) { - zfree(temp1); - zfree(temp2); - rem->v = alloc(z1.len); - rem->len = z1.len; - rem->sign = 0; - zcopyval(z1, *rem); - return 0; - } - zfree(temp2); - z1 = temp1; - /* - * Now loop by squaring the factor each time, and see whether - * or not each successive square will still divide the number. - */ - count = 1; - worth = 1; - zp = &squares[0]; - *zp = z2; - while (((zp->len * 2) - 1) <= z1.len) { /* while square not too large */ - zsquare(*zp, &temp1); - zdiv(z1, temp1, &temp2, &temp3, 0); - if (!ziszero(temp3)) { - zfree(temp1); - zfree(temp2); - zfree(temp3); - break; - } - zfree(temp3); - zfree(z1); - z1 = temp2; - *++zp = temp1; - worth *= 2; - count += worth; - } + z1.sign = 0; + z2.sign = 0; + /* + * Reject trivial cases. + */ + if ((z1.len < z2.len) || (zisodd(z1) && ziseven(z2)) || + ziszero(z2) || zisone(z2) || + ((z1.len == z2.len) && (z1.v[z1.len-1] < z2.v[z2.len-1]))) { + rem->v = alloc(z1.len); + rem->len = z1.len; + rem->sign = 0; + zcopyval(z1, *rem); + return 0; + } + /* + * Handle any power of two special. + */ + if (zisonebit(z2)) { + lowbit = zlowbit(z2); + count = zlowbit(z1) / lowbit; + rem->v = alloc(z1.len); + rem->len = z1.len; + rem->sign = 0; + zcopyval(z1, *rem); + zshiftr(*rem, count * lowbit); + ztrim(rem); + return count; + } + /* + * See if the factor goes in even once. + */ + zdiv(z1, z2, &temp1, &temp2, 0); + if (!ziszero(temp2)) { + zfree(temp1); + zfree(temp2); + rem->v = alloc(z1.len); + rem->len = z1.len; + rem->sign = 0; + zcopyval(z1, *rem); + return 0; + } + zfree(temp2); + z1 = temp1; + /* + * Now loop by squaring the factor each time, and see whether + * or not each successive square will still divide the number. + */ + count = 1; + worth = 1; + zp = &squares[0]; + *zp = z2; + while (((zp->len * 2) - 1) <= z1.len) { /* while square not too large */ + zsquare(*zp, &temp1); + zdiv(z1, temp1, &temp2, &temp3, 0); + if (!ziszero(temp3)) { + zfree(temp1); + zfree(temp2); + zfree(temp3); + break; + } + zfree(temp3); + zfree(z1); + z1 = temp2; + *++zp = temp1; + worth *= 2; + count += worth; + } - /* - * Now back down the list of squares, and see if the lower powers - * will divide any more times. - */ - /* - * We prevent the zp pointer from walking behind squares - * by stopping one short of the end and running the loop one - * more time. - * - * We could stop the loop with just zp >= squares, but stopping - * short and running the loop one last time manually helps make - * code checkers such as insure happy. - */ - for (; zp > squares; zp--, worth /= 2) { - if (zp->len <= z1.len) { - zdiv(z1, *zp, &temp1, &temp2, 0); - if (ziszero(temp2)) { - temp3 = z1; - z1 = temp1; - temp1 = temp3; - count += worth; - } - zfree(temp1); - zfree(temp2); - } - if (zp != squares) - zfree(*zp); - } - /* run the loop manually one last time */ - if (zp == squares) { - if (zp->len <= z1.len) { - zdiv(z1, *zp, &temp1, &temp2, 0); - if (ziszero(temp2)) { - temp3 = z1; - z1 = temp1; - temp1 = temp3; - count += worth; - } - zfree(temp1); - zfree(temp2); - } - if (zp != squares) - zfree(*zp); - } + /* + * Now back down the list of squares, and see if the lower powers + * will divide any more times. + */ + /* + * We prevent the zp pointer from walking behind squares + * by stopping one short of the end and running the loop one + * more time. + * + * We could stop the loop with just zp >= squares, but stopping + * short and running the loop one last time manually helps make + * code checkers such as insure happy. + */ + for (; zp > squares; zp--, worth /= 2) { + if (zp->len <= z1.len) { + zdiv(z1, *zp, &temp1, &temp2, 0); + if (ziszero(temp2)) { + temp3 = z1; + z1 = temp1; + temp1 = temp3; + count += worth; + } + zfree(temp1); + zfree(temp2); + } + if (zp != squares) + zfree(*zp); + } + /* run the loop manually one last time */ + if (zp == squares) { + if (zp->len <= z1.len) { + zdiv(z1, *zp, &temp1, &temp2, 0); + if (ziszero(temp2)) { + temp3 = z1; + z1 = temp1; + temp1 = temp3; + count += worth; + } + zfree(temp1); + zfree(temp2); + } + if (zp != squares) + zfree(*zp); + } - *rem = z1; - return count; + *rem = z1; + return count; } @@ -1687,71 +1687,71 @@ zfacrem(ZVALUE z1, ZVALUE z2, ZVALUE *rem) long zgcdrem(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - ZVALUE tmp1, tmp2, tmp3, tmp4; - long count, onecount; - long sh; + ZVALUE tmp1, tmp2, tmp3, tmp4; + long count, onecount; + long sh; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (ziszero(z1) || ziszero(z2)) { - math_error("Zero argument in call to zgcdrem!!!"); - not_reached(); - } - /* - * Begin by taking the gcd for the first time. - * If the number is already relatively prime, then we are done. - */ - z1.sign = 0; - z2.sign = 0; - if (zisone(z2)) - return 0; - if (zisonebit(z2)) { - sh = zlowbit(z1); - if (sh == 0) - return 0; - zshift(z1, -sh, res); - return 1 + (sh - 1)/zlowbit(z2); - } - if (zisonebit(z1)) { - if (zisodd(z2)) - return 0; - *res = _one_; - return zlowbit(z1); - } + if (ziszero(z1) || ziszero(z2)) { + math_error("Zero argument in call to zgcdrem!!!"); + not_reached(); + } + /* + * Begin by taking the gcd for the first time. + * If the number is already relatively prime, then we are done. + */ + z1.sign = 0; + z2.sign = 0; + if (zisone(z2)) + return 0; + if (zisonebit(z2)) { + sh = zlowbit(z1); + if (sh == 0) + return 0; + zshift(z1, -sh, res); + return 1 + (sh - 1)/zlowbit(z2); + } + if (zisonebit(z1)) { + if (zisodd(z2)) + return 0; + *res = _one_; + return zlowbit(z1); + } - zgcd(z1, z2, &tmp1); - if (zisunit(tmp1) || ziszero(tmp1)) { - zfree(tmp1); - return 0; - } - zequo(z1, tmp1, &tmp2); - count = 1; - z1 = tmp2; - z2 = tmp1; - /* - * Now keep alternately taking the gcd and removing factors until - * the gcd becomes one. - */ - while (!zisunit(z2)) { - onecount = zfacrem(z1, z2, &tmp3); - if (onecount) { - count += onecount; - zfree(z1); - z1 = tmp3; - } else { - zfree(tmp3); - } - zgcd(z1, z2, &tmp4); - zfree(z2); - z2 = tmp4; - } - zfree(z2); - *res = z1; - return count; + zgcd(z1, z2, &tmp1); + if (zisunit(tmp1) || ziszero(tmp1)) { + zfree(tmp1); + return 0; + } + zequo(z1, tmp1, &tmp2); + count = 1; + z1 = tmp2; + z2 = tmp1; + /* + * Now keep alternately taking the gcd and removing factors until + * the gcd becomes one. + */ + while (!zisunit(z2)) { + onecount = zfacrem(z1, z2, &tmp3); + if (onecount) { + count += onecount; + zfree(z1); + z1 = tmp3; + } else { + zfree(tmp3); + } + zgcd(z1, z2, &tmp4); + zfree(z2); + z2 = tmp4; + } + zfree(z2); + *res = z1; + return count; } @@ -1761,443 +1761,443 @@ zgcdrem(ZVALUE z1, ZVALUE z2, ZVALUE *res) long zdigits(ZVALUE z1) { - long count, val; + long count, val; - z1.sign = 0; - if (!zge16b(z1)) { /* do small numbers ourself */ - count = 1; - val = 10; - while (*z1.v >= (HALF)val) { - count++; - val *= 10; - } - return count; - } - return (zlog10(z1, NULL) + 1); + z1.sign = 0; + if (!zge16b(z1)) { /* do small numbers ourself */ + count = 1; + val = 10; + while (*z1.v >= (HALF)val) { + count++; + val *= 10; + } + return count; + } + return (zlog10(z1, NULL) + 1); } /* * Return the single digit at the specified decimal place of a number, - * where 0 means the rightmost digit. Example: zdigit(1234, 1) = 3. + * where 0 means the rightmost digit. Example: zdigit(1234, 1) = 3. */ long zdigit(ZVALUE z1, long n) { - ZVALUE tmp1, tmp2; - long res; + ZVALUE tmp1, tmp2; + long res; - z1.sign = 0; - if (ziszero(z1) || (n < 0) || (n / BASEDIG >= z1.len)) - return 0; - if (n == 0) - return zmodi(z1, 10L); - if (n == 1) - return zmodi(z1, 100L) / 10; - if (n == 2) - return zmodi(z1, 1000L) / 100; - if (n == 3) - return zmodi(z1, 10000L) / 1000; - ztenpow(n, &tmp1); - zquo(z1, tmp1, &tmp2, 0); - res = zmodi(tmp2, 10L); - zfree(tmp1); - zfree(tmp2); - return res; + z1.sign = 0; + if (ziszero(z1) || (n < 0) || (n / BASEDIG >= z1.len)) + return 0; + if (n == 0) + return zmodi(z1, 10L); + if (n == 1) + return zmodi(z1, 100L) / 10; + if (n == 2) + return zmodi(z1, 1000L) / 100; + if (n == 3) + return zmodi(z1, 10000L) / 1000; + ztenpow(n, &tmp1); + zquo(z1, tmp1, &tmp2, 0); + res = zmodi(tmp2, 10L); + zfree(tmp1); + zfree(tmp2); + return res; } /* * z is to be a nonnegative integer * If z is the square of a integer stores at dest the square root of z; - * otherwise stores at z an integer differing from the square root - * by less than 1. Returns the sign of the true square root minus - * the calculated integer. Type of rounding is determined by - * rnd as follows: rnd = 0 gives round down, rnd = 1 - * rounds up, rnd = 8 rounds to even integer, rnd = 9 rounds to odd - * integer, rnd = 16 rounds to nearest integer. + * otherwise stores at z an integer differing from the square root + * by less than 1. Returns the sign of the true square root minus + * the calculated integer. Type of rounding is determined by + * rnd as follows: rnd = 0 gives round down, rnd = 1 + * rounds up, rnd = 8 rounds to even integer, rnd = 9 rounds to odd + * integer, rnd = 16 rounds to nearest integer. */ FLAG zsqrt(ZVALUE z, ZVALUE *dest, long rnd) { - HALF *a, *A, *b, *a0, u; - int i, j, j1, j2, k, k1, m, m0, m1, n, n0, o; - FULL d, e, f, g, h, s, t, x, topbit; - int remsign; - bool up, onebit; - ZVALUE sqrt; + HALF *a, *A, *b, *a0, u; + int i, j, j1, j2, k, k1, m, m0, m1, n, n0, o; + FULL d, e, f, g, h, s, t, x, topbit; + int remsign; + bool up, onebit; + ZVALUE sqrt; - /* firewall */ - if (dest == NULL) { - math_error("%s: dest NULL", __func__); - not_reached(); - } + /* firewall */ + if (dest == NULL) { + math_error("%s: dest NULL", __func__); + not_reached(); + } - if (z.sign) { - math_error("Square root of negative number"); - not_reached(); - } - if (ziszero(z)) { - *dest = _zero_; - return 0; - } - m0 = z.len; - o = m0 & 1; - m = m0 + o; /* m is smallest even number >= z.len */ - n0 = n = m / 2; - f = z.v[z.len - 1]; - k = 1; - while (f >>= 2) - k++; - if (!o) - k += BASEB/2; - j = BASEB - k; - m1 = m; - if (k == BASEB) { - m1 += 2; - n0++; - } - A = alloc(m1); - A[m1] = 0; - a0 = A + n0; - memcpy(A, z.v, m0 * sizeof(HALF)); - if (o) - A[m - 1] = 0; - if (n == 1) { - if (j) - f = (FULL) A[1] << j | A[0] >> k; - else - f = A[1]; - g = (FULL) A[0] << (j + BASEB); - d = e = topbit = (FULL)1 << (k - 1); - } else { - if (j) - f = (FULL) A[m-1] << (j + BASEB) | (FULL) A[m-2] << j | - A[m-3] >> k; - else - f = (FULL) A[m-1] << BASEB | A[m-2]; - g = (FULL) A[m-3] << (j + BASEB) | (FULL) A[m-4] << j; - d = e = topbit = (FULL)1 << (BASEB + k - 1); - } + if (z.sign) { + math_error("Square root of negative number"); + not_reached(); + } + if (ziszero(z)) { + *dest = _zero_; + return 0; + } + m0 = z.len; + o = m0 & 1; + m = m0 + o; /* m is smallest even number >= z.len */ + n0 = n = m / 2; + f = z.v[z.len - 1]; + k = 1; + while (f >>= 2) + k++; + if (!o) + k += BASEB/2; + j = BASEB - k; + m1 = m; + if (k == BASEB) { + m1 += 2; + n0++; + } + A = alloc(m1); + A[m1] = 0; + a0 = A + n0; + memcpy(A, z.v, m0 * sizeof(HALF)); + if (o) + A[m - 1] = 0; + if (n == 1) { + if (j) + f = (FULL) A[1] << j | A[0] >> k; + else + f = A[1]; + g = (FULL) A[0] << (j + BASEB); + d = e = topbit = (FULL)1 << (k - 1); + } else { + if (j) + f = (FULL) A[m-1] << (j + BASEB) | (FULL) A[m-2] << j | + A[m-3] >> k; + else + f = (FULL) A[m-1] << BASEB | A[m-2]; + g = (FULL) A[m-3] << (j + BASEB) | (FULL) A[m-4] << j; + d = e = topbit = (FULL)1 << (BASEB + k - 1); + } - s = (f & topbit); - f <<= 1; - if (g & TOPFULL) - f++; - g <<= 1; - if (s) { - f -= 4 * d; - e = 2 * d - 1; - } - else - f -= d; - while (d >>= 1) { - if (!(s | f | g)) - break; - while (d && (f & topbit) == s) { - d >>= 1; - f <<= 1; - if (g & TOPFULL) - f++; - g <<= 1; - } - if (d == 0) - break; - if (s) - f += e + 1; - else - f -= e; - t = f & topbit; - f <<= 1; - if (g & TOPFULL) - f++; - g <<= 1; - if (t == 0 && f < d) - t = topbit; - f -= d; - if (s) - e -= d - !t; - else - e += d - (t > 0); - s = t; - } - if (n0 == 1) { - A[1] = (HALF)e; - A[0] = (HALF)f; - m = 1; - goto done; - } - if (n0 == 2) { - A[3] = (HALF)(e >> BASEB); - A[2] = (HALF)e; - A[1] = (HALF)(f >> BASEB); - A[0] = (HALF)f; - m = 2; - goto done; - } - u = (HALF)(s ? BASE1 : 0); - if (k < BASEB) { - A[m1 - 1] = (HALF)(e >> (BASEB - 1)); - A[m1 - 2] = ((HALF)(e << 1) | (HALF)(s > 0)); - A[m1 - 3] = (HALF)(f >> BASEB); - A[m1 - 4] = (HALF)f; - m = m1 - 2; - k1 = k + 1; - } else { - A[m1 - 1] = 1; - A[m1 - 2] = (HALF)(e >> (BASEB - 1)); - A[m1 - 3] = ((HALF)(e << 1) | (HALF)(s > 0)); - A[m1 - 4] = u; - A[m1 - 5] = (HALF)(f >> BASEB); - A[m1 - 6] = (HALF)f; - m = m1 - 3; - k1 = 1; - } - h = e >> k; - onebit = ((e & ((FULL)1 << (k - 1))) ? true : false); - j2 = BASEB - k1; - j1 = BASEB + j2; - while (m > n0) { - a = A + m - 1; - if (j2) - f = (FULL) *a << j1 | (FULL) a[-1] << j2 | a[-2] >> k1; - else - f = (FULL) *a << BASEB | a[-1]; - if (u) - f = ~f; - x = f / h; - if (x) { - if (onebit && x > 2 * (f % h) + 2) - x--; - b = a + 1; - i = m1 - m; - a -= i + 1; - if (u) { - f = *a + x * (BASE - x); - *a++ = (HALF)f; - u = (HALF)(f >> BASEB); - while (i--) { - f = *a + x * *b++ + u; - *a++ = (HALF)f; - u = (HALF)(f >> BASEB); - } - u += *a; - x = ~x + !u; - if (!(x & TOPHALF)) - a[1] -= 1; - } else { - f = *a - x * x; - *a++ = (HALF)f; - u = -(HALF)(f >> BASEB); - while (i--) { - f = *a - x * *b++ - u; - *a++ = (HALF)f; - u = -(HALF)(f >> BASEB); - } - u = *a - u; - x = x + u; - if (x & TOPHALF) - a[1] |= 1; - } - *a = ((HALF)(x << 1) | (HALF)(u > 0)); - } else { - *a = u; - } - m--; - if (*--a == u) { - while (m > 1 && *--a == u) - m--; - } - } - i = n; - a = a0; - while (i--) { - *a >>= 1; - if (a[1] & 1) *a |= TOPHALF; - a++; - } - s = u; -done: if (s == 0) { - while (m > 0 && A[m - 1] == 0) - m--; - if (m == 0) { - remsign = 0; - sqrt.v = alloc(n); - sqrt.len = n; - sqrt.sign = 0; - memcpy(sqrt.v, a0, n * sizeof(HALF)); - freeh(A); - *dest = sqrt; - return remsign; - } - } - if (rnd & 16) { - if (s == 0) { - if (m != n) { - up = (m > n); - } else { - i = n; - b = a0 + n; - a = A + n; - while (i > 0 && *--a == *--b) - i--; - up = (i > 0 && *a > *b); - } - } else { - while (m > 1 && A[m - 1] == BASE1) - m--; - if (m != n) { - up = (m < n); - } else { - i = n; - b = a0 + n; - a = A + n; - while (i > 0 && *--a + *--b == BASE1) - i--; - up = ((FULL) *a + *b >= BASE); - } - } - } - else - if (rnd & 8) - up = (((rnd ^ *a0) & 1) ? true : false); - else - up = ((rnd & 1) ? true : false); - if (up) { - remsign = -1; - i = n; - a = a0; - while (i-- && *a == BASE1) - *a++ = 0; - if (i >= 0) { - (*a)++; - } else { - n++; - *a = 1; - } - } else { - remsign = 1; - } - sqrt.v = alloc(n); - sqrt.len = n; - sqrt.sign = 0; - memcpy(sqrt.v, a0, n * sizeof(HALF)); - freeh(A); - *dest = sqrt; - return remsign; + s = (f & topbit); + f <<= 1; + if (g & TOPFULL) + f++; + g <<= 1; + if (s) { + f -= 4 * d; + e = 2 * d - 1; + } + else + f -= d; + while (d >>= 1) { + if (!(s | f | g)) + break; + while (d && (f & topbit) == s) { + d >>= 1; + f <<= 1; + if (g & TOPFULL) + f++; + g <<= 1; + } + if (d == 0) + break; + if (s) + f += e + 1; + else + f -= e; + t = f & topbit; + f <<= 1; + if (g & TOPFULL) + f++; + g <<= 1; + if (t == 0 && f < d) + t = topbit; + f -= d; + if (s) + e -= d - !t; + else + e += d - (t > 0); + s = t; + } + if (n0 == 1) { + A[1] = (HALF)e; + A[0] = (HALF)f; + m = 1; + goto done; + } + if (n0 == 2) { + A[3] = (HALF)(e >> BASEB); + A[2] = (HALF)e; + A[1] = (HALF)(f >> BASEB); + A[0] = (HALF)f; + m = 2; + goto done; + } + u = (HALF)(s ? BASE1 : 0); + if (k < BASEB) { + A[m1 - 1] = (HALF)(e >> (BASEB - 1)); + A[m1 - 2] = ((HALF)(e << 1) | (HALF)(s > 0)); + A[m1 - 3] = (HALF)(f >> BASEB); + A[m1 - 4] = (HALF)f; + m = m1 - 2; + k1 = k + 1; + } else { + A[m1 - 1] = 1; + A[m1 - 2] = (HALF)(e >> (BASEB - 1)); + A[m1 - 3] = ((HALF)(e << 1) | (HALF)(s > 0)); + A[m1 - 4] = u; + A[m1 - 5] = (HALF)(f >> BASEB); + A[m1 - 6] = (HALF)f; + m = m1 - 3; + k1 = 1; + } + h = e >> k; + onebit = ((e & ((FULL)1 << (k - 1))) ? true : false); + j2 = BASEB - k1; + j1 = BASEB + j2; + while (m > n0) { + a = A + m - 1; + if (j2) + f = (FULL) *a << j1 | (FULL) a[-1] << j2 | a[-2] >> k1; + else + f = (FULL) *a << BASEB | a[-1]; + if (u) + f = ~f; + x = f / h; + if (x) { + if (onebit && x > 2 * (f % h) + 2) + x--; + b = a + 1; + i = m1 - m; + a -= i + 1; + if (u) { + f = *a + x * (BASE - x); + *a++ = (HALF)f; + u = (HALF)(f >> BASEB); + while (i--) { + f = *a + x * *b++ + u; + *a++ = (HALF)f; + u = (HALF)(f >> BASEB); + } + u += *a; + x = ~x + !u; + if (!(x & TOPHALF)) + a[1] -= 1; + } else { + f = *a - x * x; + *a++ = (HALF)f; + u = -(HALF)(f >> BASEB); + while (i--) { + f = *a - x * *b++ - u; + *a++ = (HALF)f; + u = -(HALF)(f >> BASEB); + } + u = *a - u; + x = x + u; + if (x & TOPHALF) + a[1] |= 1; + } + *a = ((HALF)(x << 1) | (HALF)(u > 0)); + } else { + *a = u; + } + m--; + if (*--a == u) { + while (m > 1 && *--a == u) + m--; + } + } + i = n; + a = a0; + while (i--) { + *a >>= 1; + if (a[1] & 1) *a |= TOPHALF; + a++; + } + s = u; +done: if (s == 0) { + while (m > 0 && A[m - 1] == 0) + m--; + if (m == 0) { + remsign = 0; + sqrt.v = alloc(n); + sqrt.len = n; + sqrt.sign = 0; + memcpy(sqrt.v, a0, n * sizeof(HALF)); + freeh(A); + *dest = sqrt; + return remsign; + } + } + if (rnd & 16) { + if (s == 0) { + if (m != n) { + up = (m > n); + } else { + i = n; + b = a0 + n; + a = A + n; + while (i > 0 && *--a == *--b) + i--; + up = (i > 0 && *a > *b); + } + } else { + while (m > 1 && A[m - 1] == BASE1) + m--; + if (m != n) { + up = (m < n); + } else { + i = n; + b = a0 + n; + a = A + n; + while (i > 0 && *--a + *--b == BASE1) + i--; + up = ((FULL) *a + *b >= BASE); + } + } + } + else + if (rnd & 8) + up = (((rnd ^ *a0) & 1) ? true : false); + else + up = ((rnd & 1) ? true : false); + if (up) { + remsign = -1; + i = n; + a = a0; + while (i-- && *a == BASE1) + *a++ = 0; + if (i >= 0) { + (*a)++; + } else { + n++; + *a = 1; + } + } else { + remsign = 1; + } + sqrt.v = alloc(n); + sqrt.len = n; + sqrt.sign = 0; + memcpy(sqrt.v, a0, n * sizeof(HALF)); + freeh(A); + *dest = sqrt; + return remsign; } /* * Take an arbitrary root of a number (to the greatest integer). * This uses the following iteration to get the K-th root of N: - * x = ((K-1) * x + N / x^(K-1)) / K + * x = ((K-1) * x + N / x^(K-1)) / K */ void zroot(ZVALUE z1, ZVALUE z2, ZVALUE *dest) { - ZVALUE ztry, quo, old, temp, temp2; - ZVALUE k1; /* holds k - 1 */ - int sign; - long i; - LEN highbit, k; - SIUNION sival; + ZVALUE ztry, quo, old, temp, temp2; + ZVALUE k1; /* holds k - 1 */ + int sign; + long i; + LEN highbit, k; + SIUNION sival; - /* firewall */ - if (dest == NULL) { - math_error("%s: dest NULL", __func__); - not_reached(); - } + /* firewall */ + if (dest == NULL) { + math_error("%s: dest NULL", __func__); + not_reached(); + } - sign = z1.sign; - if (sign && ziseven(z2)) { - math_error("Even root of negative number"); - not_reached(); - } - if (ziszero(z2) || zisneg(z2)) { - math_error("Non-positive root"); - not_reached(); - } - if (ziszero(z1)) { /* root of zero */ - *dest = _zero_; - return; - } - if (zisunit(z2)) { /* first root */ - zcopy(z1, dest); - return; - } - if (zge31b(z2)) { /* humongous root */ - *dest = _one_; - dest->sign = (bool)((HALF)sign); - return; - } - k = (LEN)ztolong(z2); - highbit = zhighbit(z1); - if (highbit < k) { /* too high a root */ - *dest = _one_; - dest->sign = (bool)((HALF)sign); - return; - } - sival.ivalue = k - 1; - k1.v = &sival.silow; - /* ignore Saber-C warning #112 - get ushort from uint */ - /* OK to ignore on name zroot`sival */ - k1.len = 1 + (sival.sihigh != 0); - k1.sign = 0; - z1.sign = 0; - /* - * Allocate the numbers to use for the main loop. - * The size and high bits of the final result are correctly set here. - * Notice that the remainder of the test value is rubbish, but this - * is unimportant. - */ - highbit = (highbit + k - 1) / k; - ztry.len = (highbit / BASEB) + 1; - ztry.v = alloc(ztry.len); - zclearval(ztry); - ztry.v[ztry.len-1] = ((HALF)1 << (highbit % BASEB)); - ztry.sign = 0; - old.v = alloc(ztry.len); - old.len = 1; - zclearval(old); - old.sign = 0; - /* - * Main divide and average loop - */ - for (;;) { - zpowi(ztry, k1, &temp); - zquo(z1, temp, &quo, 0); - zfree(temp); - i = zrel(ztry, quo); - if (i <= 0) { - /* - * Current try is less than or equal to the root since - * it is less than the quotient. If the quotient is - * equal to the try, we are all done. Also, if the - * try is equal to the old value, we are done since - * no improvement occurred. If not, save the improved - * value and loop some more. - */ - if ((i == 0) || (zcmp(old, ztry) == 0)) { - zfree(quo); - zfree(old); - ztry.sign = (bool)((HALF)sign); - zquicktrim(ztry); - *dest = ztry; - return; - } - old.len = ztry.len; - zcopyval(ztry, old); - } - /* average current try and quotient for the new try */ - zmul(ztry, k1, &temp); - zfree(ztry); - zadd(quo, temp, &temp2); - zfree(temp); - zfree(quo); - zquo(temp2, z2, &ztry, 0); - zfree(temp2); - } + sign = z1.sign; + if (sign && ziseven(z2)) { + math_error("Even root of negative number"); + not_reached(); + } + if (ziszero(z2) || zisneg(z2)) { + math_error("Non-positive root"); + not_reached(); + } + if (ziszero(z1)) { /* root of zero */ + *dest = _zero_; + return; + } + if (zisunit(z2)) { /* first root */ + zcopy(z1, dest); + return; + } + if (zge31b(z2)) { /* humongous root */ + *dest = _one_; + dest->sign = (bool)((HALF)sign); + return; + } + k = (LEN)ztolong(z2); + highbit = zhighbit(z1); + if (highbit < k) { /* too high a root */ + *dest = _one_; + dest->sign = (bool)((HALF)sign); + return; + } + sival.ivalue = k - 1; + k1.v = &sival.silow; + /* ignore Saber-C warning #112 - get ushort from uint */ + /* OK to ignore on name zroot`sival */ + k1.len = 1 + (sival.sihigh != 0); + k1.sign = 0; + z1.sign = 0; + /* + * Allocate the numbers to use for the main loop. + * The size and high bits of the final result are correctly set here. + * Notice that the remainder of the test value is rubbish, but this + * is unimportant. + */ + highbit = (highbit + k - 1) / k; + ztry.len = (highbit / BASEB) + 1; + ztry.v = alloc(ztry.len); + zclearval(ztry); + ztry.v[ztry.len-1] = ((HALF)1 << (highbit % BASEB)); + ztry.sign = 0; + old.v = alloc(ztry.len); + old.len = 1; + zclearval(old); + old.sign = 0; + /* + * Main divide and average loop + */ + for (;;) { + zpowi(ztry, k1, &temp); + zquo(z1, temp, &quo, 0); + zfree(temp); + i = zrel(ztry, quo); + if (i <= 0) { + /* + * Current try is less than or equal to the root since + * it is less than the quotient. If the quotient is + * equal to the try, we are all done. Also, if the + * try is equal to the old value, we are done since + * no improvement occurred. If not, save the improved + * value and loop some more. + */ + if ((i == 0) || (zcmp(old, ztry) == 0)) { + zfree(quo); + zfree(old); + ztry.sign = (bool)((HALF)sign); + zquicktrim(ztry); + *dest = ztry; + return; + } + old.len = ztry.len; + zcopyval(ztry, old); + } + /* average current try and quotient for the new try */ + zmul(ztry, k1, &temp); + zfree(ztry); + zadd(quo, temp, &temp2); + zfree(temp); + zfree(quo); + zquo(temp2, z2, &ztry, 0); + zfree(temp2); + } } @@ -2207,34 +2207,34 @@ zroot(ZVALUE z1, ZVALUE z2, ZVALUE *dest) bool zissquare(ZVALUE z) { - long n; - ZVALUE tmp; + long n; + ZVALUE tmp; - /* negative values are never perfect squares */ - if (zisneg(z)) { - return false; - } + /* negative values are never perfect squares */ + if (zisneg(z)) { + return false; + } - /* ignore trailing zero words */ - while ((z.len > 1) && (*z.v == 0)) { - z.len--; - z.v++; - } + /* ignore trailing zero words */ + while ((z.len > 1) && (*z.v == 0)) { + z.len--; + z.v++; + } - /* zero or one is a perfect square */ - if (zisabsleone(z)) { - return true; - } + /* zero or one is a perfect square */ + if (zisabsleone(z)) { + return true; + } - /* check mod 4096 values */ - if (issq_mod4k[(int)(*z.v & 0xfff)] == 0) { - return false; - } + /* check mod 4096 values */ + if (issq_mod4k[(int)(*z.v & 0xfff)] == 0) { + return false; + } - /* must do full square root test now */ - n = !zsqrt(z, &tmp, 0); - zfree(tmp); - return (n ? true : false); + /* must do full square root test now */ + n = !zsqrt(z, &tmp, 0); + zfree(tmp); + return (n ? true : false); } @@ -2242,72 +2242,72 @@ zissquare(ZVALUE z) * test if a number is an integer power of 2 * * given: - * z value to check if it is a power of 2 - * log2 when z is an integer power of 2 (true return), *log2 is set to log base 2 of z - * when z is NOT an integer power of 2 (false return), *log2 is not touched + * z value to check if it is a power of 2 + * log2 when z is an integer power of 2 (true return), *log2 is set to log base 2 of z + * when z is NOT an integer power of 2 (false return), *log2 is not touched * * returns: - * true z is a power of 2 - * false z is not a power of 2 + * true z is a power of 2 + * false z is not a power of 2 */ bool zispowerof2(ZVALUE z, FULL *log2) { - FULL ilogz; /* potential log base 2 return value or -1 */ - HALF tophalf; /* most significant HALF in z */ - LEN len; /* length of z in HALFs */ - int i; + FULL ilogz; /* potential log base 2 return value or -1 */ + HALF tophalf; /* most significant HALF in z */ + LEN len; /* length of z in HALFs */ + int i; - /* firewall */ - if (log2 == NULL) { - math_error("%s: log2 NULL", __func__); - not_reached(); - } + /* firewall */ + if (log2 == NULL) { + math_error("%s: log2 NULL", __func__); + not_reached(); + } - /* zero and negative values are never integer powers of 2 */ - if (ziszero(z) || zisneg(z)) { - return false; - } + /* zero and negative values are never integer powers of 2 */ + if (ziszero(z) || zisneg(z)) { + return false; + } - /* - * trim z just in case - * - * An untrimmed z will give incorrect results. - */ - ztrim(&z); + /* + * trim z just in case + * + * An untrimmed z will give incorrect results. + */ + ztrim(&z); - /* - * all HALFs below the top HALF must be zero - */ - len = z.len; - for (i=0, ilogz=0; i < len-1; ++i, ilogz+=BASEB) { - if (z.v[i] != 0) { - return false; - } - } + /* + * all HALFs below the top HALF must be zero + */ + len = z.len; + for (i=0, ilogz=0; i < len-1; ++i, ilogz+=BASEB) { + if (z.v[i] != 0) { + return false; + } + } - /* - * top HALF must be a power of 2 - * - * For non-zero values of tophalf, - * (tophalf & (tophalf-1)) == 0 ==> tophalf is a power of 2, - * (tophalf & (tophalf-1)) != 0 ==> tophalf is NOT a power of 2. - */ - tophalf = z.v[len-1]; - if ((tophalf == 0) || ((tophalf & (tophalf-1)) != 0)) { - return false; - } + /* + * top HALF must be a power of 2 + * + * For non-zero values of tophalf, + * (tophalf & (tophalf-1)) == 0 ==> tophalf is a power of 2, + * (tophalf & (tophalf-1)) != 0 ==> tophalf is NOT a power of 2. + */ + tophalf = z.v[len-1]; + if ((tophalf == 0) || ((tophalf & (tophalf-1)) != 0)) { + return false; + } - /* - * count the bits in the top HALF which is a power of 2 - */ - for (i=0; i < BASEB && tophalf != ((HALF)1 << i); ++i) { - ++ilogz; - } + /* + * count the bits in the top HALF which is a power of 2 + */ + for (i=0; i < BASEB && tophalf != ((HALF)1 << i); ++i) { + ++ilogz; + } - /* - * return power of 2 - */ - *log2 = ilogz; - return true; + /* + * return power of 2 + */ + *log2 = ilogz; + return true; } diff --git a/zio.c b/zio.c index b565bf8..02022b8 100644 --- a/zio.c +++ b/zio.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1993/07/30 19:42:48 - * File existed as early as: 1993 + * Under source code control: 1993/07/30 19:42:48 + * File existed as early as: 1993 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -32,17 +32,17 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define OUTBUFSIZE 200 /* realloc size for output buffers */ +#define OUTBUFSIZE 200 /* realloc size for output buffers */ -#define PUTCHAR(ch) math_chr(ch) -#define PUTSTR(str) math_str(str) -#define PRINTF1(fmt, a1) math_fmt(fmt, a1) -#define PRINTF2(fmt, a1, a2) math_fmt(fmt, a1, a2) -#define PRINTF3(fmt, a1, a2, a3) math_fmt(fmt, a1, a2, a3) -#define PRINTF4(fmt, a1, a2, a3, a4) math_fmt(fmt, a1, a2, a3, a4) +#define PUTCHAR(ch) math_chr(ch) +#define PUTSTR(str) math_str(str) +#define PRINTF1(fmt, a1) math_fmt(fmt, a1) +#define PRINTF2(fmt, a1, a2) math_fmt(fmt, a1, a2) +#define PRINTF3(fmt, a1, a2, a3) math_fmt(fmt, a1, a2, a3) +#define PRINTF4(fmt, a1, a2, a3, a4) math_fmt(fmt, a1, a2, a3, a4) /* @@ -50,24 +50,24 @@ */ typedef struct iostate IOSTATE; struct iostate { - IOSTATE *oldiostates; /* previous saved state */ - long outdigits; /* digits for output */ - int outmode; /* output mode */ - int outmode2; /* secondary output mode */ - FILE *outfp; /* file unit for output (if any) */ - char *outbuf; /* output string buffer (if any) */ - size_t outbufsize; /* current size of string buffer */ - size_t outbufused; /* space used in string buffer */ - bool outputisstring; /* true if output is to string buffer */ + IOSTATE *oldiostates; /* previous saved state */ + long outdigits; /* digits for output */ + int outmode; /* output mode */ + int outmode2; /* secondary output mode */ + FILE *outfp; /* file unit for output (if any) */ + char *outbuf; /* output string buffer (if any) */ + size_t outbufsize; /* current size of string buffer */ + size_t outbufused; /* space used in string buffer */ + bool outputisstring; /* true if output is to string buffer */ }; -STATIC IOSTATE *oldiostates = NULL; /* list of saved output states */ -STATIC FILE *outfp = NULL; /* file unit for output */ -STATIC char *outbuf = NULL; /* current diverted buffer */ -STATIC bool outputisstring = false; -STATIC size_t outbufsize; -STATIC size_t outbufused; +STATIC IOSTATE *oldiostates = NULL; /* list of saved output states */ +STATIC FILE *outfp = NULL; /* file unit for output */ +STATIC char *outbuf = NULL; /* current diverted buffer */ +STATIC bool outputisstring = false; +STATIC size_t outbufsize; +STATIC size_t outbufused; /* @@ -80,12 +80,12 @@ STATIC size_t outbufused; void zio_init(void) { - STATIC int done = 0; /* 1 => routine already called */ + STATIC int done = 0; /* 1 => routine already called */ - if (!done) { - outfp = stdout; - done = 1; - } + if (!done) { + outfp = stdout; + done = 1; + } } @@ -96,22 +96,22 @@ zio_init(void) void math_chr(int ch) { - char *cp; + char *cp; - if (!outputisstring) { - fputc(ch, outfp); - return; - } - if (outbufused >= outbufsize) { - cp = (char *)realloc(outbuf, outbufsize + OUTBUFSIZE + 1); - if (cp == NULL) { - math_error("Cannot realloc output string"); - not_reached(); - } - outbuf = cp; - outbufsize += OUTBUFSIZE; - } - outbuf[outbufused++] = (char)ch; + if (!outputisstring) { + fputc(ch, outfp); + return; + } + if (outbufused >= outbufsize) { + cp = (char *)realloc(outbuf, outbufsize + OUTBUFSIZE + 1); + if (cp == NULL) { + math_error("Cannot realloc output string"); + not_reached(); + } + outbuf = cp; + outbufsize += OUTBUFSIZE; + } + outbuf[outbufused++] = (char)ch; } @@ -122,31 +122,31 @@ math_chr(int ch) void math_str(char *str) { - char *cp; - size_t len; + char *cp; + size_t len; - /* firewall */ - if (str == NULL) { - math_error("%s: str NULL", __func__); - not_reached(); - } + /* firewall */ + if (str == NULL) { + math_error("%s: str NULL", __func__); + not_reached(); + } - if (!outputisstring) { - fputs(str, outfp); - return; - } - len = strlen(str); - if ((outbufused + len) > outbufsize) { - cp = (char *)realloc(outbuf, outbufsize + len + OUTBUFSIZE + 1); - if (cp == NULL) { - math_error("Cannot realloc output string"); - not_reached(); - } - outbuf = cp; - outbufsize += (len + OUTBUFSIZE); - } - memcpy(&outbuf[outbufused], str, len); - outbufused += len; + if (!outputisstring) { + fputs(str, outfp); + return; + } + len = strlen(str); + if ((outbufused + len) > outbufsize) { + cp = (char *)realloc(outbuf, outbufsize + len + OUTBUFSIZE + 1); + if (cp == NULL) { + math_error("Cannot realloc output string"); + not_reached(); + } + outbuf = cp; + outbufsize += (len + OUTBUFSIZE); + } + memcpy(&outbuf[outbufused], str, len); + outbufused += len; } @@ -161,23 +161,23 @@ math_str(char *str) void math_fill(char *str, long width) { - /* firewall */ - if (str == NULL) { - math_error("%s: str NULL", __func__); - not_reached(); - } + /* firewall */ + if (str == NULL) { + math_error("%s: str NULL", __func__); + not_reached(); + } - if (width > 0) { - width -= (long)strlen(str); - while (width-- > 0) - PUTCHAR(' '); - PUTSTR(str); - } else { - width += (long)strlen(str); - PUTSTR(str); - while (width++ < 0) - PUTCHAR(' '); - } + if (width > 0) { + width -= (long)strlen(str); + while (width-- > 0) + PUTCHAR(' '); + PUTSTR(str); + } else { + width += (long)strlen(str); + PUTSTR(str); + while (width++ < 0) + PUTCHAR(' '); + } } @@ -188,20 +188,20 @@ math_fill(char *str, long width) void math_fmt(char *fmt, ...) { - va_list ap; - char buf[BUFSIZ+1]; + va_list ap; + char buf[BUFSIZ+1]; - /* firewall */ - if (fmt == NULL) { - math_error("%s: fmt NULL", __func__); - not_reached(); - } + /* firewall */ + if (fmt == NULL) { + math_error("%s: fmt NULL", __func__); + not_reached(); + } - va_start(ap, fmt); - vsnprintf(buf, BUFSIZ, fmt, ap); - va_end(ap); - buf[BUFSIZ] = '\0'; /* paranoia */ - math_str(buf); + va_start(ap, fmt); + vsnprintf(buf, BUFSIZ, fmt, ap); + va_end(ap); + buf[BUFSIZ] = '\0'; /* paranoia */ + math_str(buf); } @@ -211,47 +211,47 @@ math_fmt(char *fmt, ...) void math_flush(void) { - if (!outputisstring) - fflush(outfp); + if (!outputisstring) + fflush(outfp); } /* * Divert further output so that it is saved into a string that will be * returned later when the diversion is completed. The current state of - * output is remembered for later restoration. Diversions can be nested. + * output is remembered for later restoration. Diversions can be nested. * Output diversion is only intended for saving output to "stdout". */ void math_divertio(void) { - register IOSTATE *sp; + register IOSTATE *sp; - sp = (IOSTATE *) malloc(sizeof(IOSTATE)); - if (sp == NULL) { - math_error("No memory for diverting output"); - not_reached(); - } - sp->oldiostates = oldiostates; - sp->outdigits = conf->outdigits; - sp->outmode = conf->outmode; - sp->outmode2 = conf->outmode2; - sp->outfp = outfp; - sp->outbuf = outbuf; - sp->outbufsize = outbufsize; - sp->outbufused = outbufused; - sp->outputisstring = outputisstring; + sp = (IOSTATE *) malloc(sizeof(IOSTATE)); + if (sp == NULL) { + math_error("No memory for diverting output"); + not_reached(); + } + sp->oldiostates = oldiostates; + sp->outdigits = conf->outdigits; + sp->outmode = conf->outmode; + sp->outmode2 = conf->outmode2; + sp->outfp = outfp; + sp->outbuf = outbuf; + sp->outbufsize = outbufsize; + sp->outbufused = outbufused; + sp->outputisstring = outputisstring; - outbufused = 0; - outbufsize = 0; - outbuf = (char *) malloc(OUTBUFSIZE + 1); - if (outbuf == NULL) { - math_error("Cannot allocate divert string"); - not_reached(); - } - outbufsize = OUTBUFSIZE; - outputisstring = true; - oldiostates = sp; + outbufused = 0; + outbufsize = 0; + outbuf = (char *) malloc(OUTBUFSIZE + 1); + if (outbuf == NULL) { + math_error("Cannot allocate divert string"); + not_reached(); + } + outbufsize = OUTBUFSIZE; + outputisstring = true; + oldiostates = sp; } @@ -263,28 +263,28 @@ math_divertio(void) char * math_getdivertedio(void) { - register IOSTATE *sp; - char *cp; + register IOSTATE *sp; + char *cp; - sp = oldiostates; - if (sp == NULL) { - math_error("No diverted state to restore"); - not_reached(); - } - cp = outbuf; - cp[outbufused] = '\0'; - oldiostates = sp->oldiostates; - conf->outdigits = sp->outdigits; - conf->outmode = sp->outmode; - conf->outmode2 = sp->outmode2; - outfp = sp->outfp; - outbuf = sp->outbuf; - outbufsize = sp->outbufsize; - outbufused = sp->outbufused; - outbuf = sp->outbuf; - outputisstring = sp->outputisstring; - free(sp); - return cp; + sp = oldiostates; + if (sp == NULL) { + math_error("No diverted state to restore"); + not_reached(); + } + cp = outbuf; + cp[outbufused] = '\0'; + oldiostates = sp->oldiostates; + conf->outdigits = sp->outdigits; + conf->outmode = sp->outmode; + conf->outmode2 = sp->outmode2; + outfp = sp->outfp; + outbuf = sp->outbuf; + outbufsize = sp->outbufsize; + outbufused = sp->outbufused; + outbuf = sp->outbuf; + outputisstring = sp->outputisstring; + free(sp); + return cp; } @@ -295,32 +295,32 @@ math_getdivertedio(void) void math_cleardiversions(void) { - while (oldiostates) - free(math_getdivertedio()); + while (oldiostates) + free(math_getdivertedio()); } /* * Set the output routines to output to the specified FILE stream. * This interacts with output diversion in the following manner. - * STDOUT diversion action - * ---- --------- ------ - * yes yes set output to diversion string again. - * yes no set output to stdout. - * no yes set output to specified file. - * no no set output to specified file. + * STDOUT diversion action + * ---- --------- ------ + * yes yes set output to diversion string again. + * yes no set output to stdout. + * no yes set output to specified file. + * no no set output to specified file. */ void math_setfp(FILE *newfp) { - /* firewall */ - if (newfp == NULL) { - math_error("%s: newfp NULL", __func__); - not_reached(); - } + /* firewall */ + if (newfp == NULL) { + math_error("%s: newfp NULL", __func__); + not_reached(); + } - outfp = newfp; - outputisstring = (oldiostates && (newfp == stdout)); + outfp = newfp; + outputisstring = (oldiostates && (newfp == stdout)); } @@ -331,15 +331,15 @@ math_setfp(FILE *newfp) int math_setmode(int newmode) { - int oldmode; + int oldmode; - if ((newmode <= MODE_DEFAULT) || (newmode > MODE_MAX)) { - math_error("Setting illegal output mode"); - not_reached(); - } - oldmode = conf->outmode; - conf->outmode = newmode; - return oldmode; + if ((newmode <= MODE_DEFAULT) || (newmode > MODE_MAX)) { + math_error("Setting illegal output mode"); + not_reached(); + } + oldmode = conf->outmode; + conf->outmode = newmode; + return oldmode; } @@ -350,16 +350,16 @@ math_setmode(int newmode) int math_setmode2(int newmode) { - int oldmode; + int oldmode; - if (newmode != MODE2_OFF && ((newmode <= MODE_DEFAULT) || - (newmode > MODE_MAX))) { - math_error("Setting illegal secondary output mode"); - not_reached(); - } - oldmode = conf->outmode2; - conf->outmode2 = newmode; - return oldmode; + if (newmode != MODE2_OFF && ((newmode <= MODE_DEFAULT) || + (newmode > MODE_MAX))) { + math_error("Setting illegal secondary output mode"); + not_reached(); + } + oldmode = conf->outmode2; + conf->outmode2 = newmode; + return oldmode; } @@ -370,61 +370,61 @@ math_setmode2(int newmode) LEN math_setdigits(LEN newdigits) { - LEN olddigits; + LEN olddigits; - if (newdigits < 0) { - math_error("Setting illegal number of digits"); - not_reached(); - } - olddigits = conf->outdigits; - conf->outdigits = newdigits; - return olddigits; + if (newdigits < 0) { + math_error("Setting illegal number of digits"); + not_reached(); + } + olddigits = conf->outdigits; + conf->outdigits = newdigits; + return olddigits; } /* * Print an integer value as a hex number. * Width is the number of columns to print the number in, including the - * sign if required. If zero, no extra output is done. If positive, + * sign if required. If zero, no extra output is done. If positive, * leading spaces are typed if necessary. If negative, trailing spaces are - * typed if necessary. The special characters 0x appear to indicate the + * typed if necessary. The special characters 0x appear to indicate the * number is hex. */ /*ARGSUSED*/ void zprintx(ZVALUE z, long width) { - register HALF *hp; /* current word to print */ - int len; /* number of halfwords to type */ - char *str; + register HALF *hp; /* current word to print */ + int len; /* number of halfwords to type */ + char *str; - if (width) { - math_divertio(); - zprintx(z, 0L); - str = math_getdivertedio(); - math_fill(str, width); - free(str); - return; - } - len = z.len - 1; - if (zisneg(z)) - PUTCHAR('-'); - if ((len == 0) && (*z.v <= (HALF) 9)) { - len = '0' + (int)(*z.v); - PUTCHAR(len & 0xff); - return; - } - hp = z.v + len; + if (width) { + math_divertio(); + zprintx(z, 0L); + str = math_getdivertedio(); + math_fill(str, width); + free(str); + return; + } + len = z.len - 1; + if (zisneg(z)) + PUTCHAR('-'); + if ((len == 0) && (*z.v <= (HALF) 9)) { + len = '0' + (int)(*z.v); + PUTCHAR(len & 0xff); + return; + } + hp = z.v + len; #if BASEB == 32 - PRINTF1("0x%lx", (PRINT) *hp--); - while (--len >= 0) { - PRINTF1("%08lx", (PRINT) *hp--); - } + PRINTF1("0x%lx", (PRINT) *hp--); + while (--len >= 0) { + PRINTF1("%08lx", (PRINT) *hp--); + } #else /* BASEB == 32 */ - PRINTF1("0x%lx", (FULL) *hp--); - while (--len >= 0) { - PRINTF1("%04lx", (FULL) *hp--); - } + PRINTF1("0x%lx", (FULL) *hp--); + while (--len >= 0) { + PRINTF1("%04lx", (FULL) *hp--); + } #endif /* BASEB == 32 */ } @@ -437,45 +437,45 @@ zprintx(ZVALUE z, long width) void zprintb(ZVALUE z, long width) { - register HALF *hp; /* current word to print */ - int len; /* number of halfwords to type */ - HALF val; /* current value */ - HALF mask; /* current mask */ - int didprint; /* nonzero if printed some digits */ - int ch; /* current char */ - char *str; + register HALF *hp; /* current word to print */ + int len; /* number of halfwords to type */ + HALF val; /* current value */ + HALF mask; /* current mask */ + int didprint; /* nonzero if printed some digits */ + int ch; /* current char */ + char *str; - if (width) { - math_divertio(); - zprintb(z, 0L); - str = math_getdivertedio(); - math_fill(str, width); - free(str); - return; - } - len = z.len - 1; - if (zisneg(z)) - PUTCHAR('-'); - if ((len == 0) && (*z.v <= (FULL) 1)) { - len = '0' + (int)(*z.v); - PUTCHAR(len & 0xff); - return; - } - hp = z.v + len; - didprint = 0; - PUTSTR("0b"); - while (len-- >= 0) { - val = ((len >= 0) ? *hp-- : *hp); - mask = ((HALF)1 << (BASEB - 1)); - while (mask) { - ch = '0' + ((mask & val) != 0); - if (didprint || (ch != '0')) { - PUTCHAR(ch & 0xff); - didprint = 1; - } - mask >>= 1; - } - } + if (width) { + math_divertio(); + zprintb(z, 0L); + str = math_getdivertedio(); + math_fill(str, width); + free(str); + return; + } + len = z.len - 1; + if (zisneg(z)) + PUTCHAR('-'); + if ((len == 0) && (*z.v <= (FULL) 1)) { + len = '0' + (int)(*z.v); + PUTCHAR(len & 0xff); + return; + } + hp = z.v + len; + didprint = 0; + PUTSTR("0b"); + while (len-- >= 0) { + val = ((len >= 0) ? *hp-- : *hp); + mask = ((HALF)1 << (BASEB - 1)); + while (mask) { + ch = '0' + ((mask & val) != 0); + if (didprint || (ch != '0')) { + PUTCHAR(ch & 0xff); + didprint = 1; + } + mask >>= 1; + } + } } @@ -487,115 +487,115 @@ zprintb(ZVALUE z, long width) void zprinto(ZVALUE z, long width) { - register HALF *hp; /* current word to print */ - int len; /* number of halfwords to type */ -#if BASEB == 32 /* Yes, the larger base needs a smaller type! */ - HALF num1='0'; /* numbers to type */ - HALF num2=(HALF)0; /* numbers to type */ - HALF num3; /* numbers to type */ - HALF num4; /* numbers to type */ + register HALF *hp; /* current word to print */ + int len; /* number of halfwords to type */ +#if BASEB == 32 /* Yes, the larger base needs a smaller type! */ + HALF num1='0'; /* numbers to type */ + HALF num2=(HALF)0; /* numbers to type */ + HALF num3; /* numbers to type */ + HALF num4; /* numbers to type */ #else - FULL num1='0'; /* numbers to type */ - FULL num2=(FULL)0; /* numbers to type */ + FULL num1='0'; /* numbers to type */ + FULL num2=(FULL)0; /* numbers to type */ #endif - int rem; /* remainder number of halfwords */ - char *str; + int rem; /* remainder number of halfwords */ + char *str; - if (width) { - math_divertio(); - zprinto(z, 0L); - str = math_getdivertedio(); - math_fill(str, width); - free(str); - return; - } - if (zisneg(z)) - PUTCHAR('-'); - len = z.len; - if ((len == 1) && (*z.v <= (FULL) 7)) { - num1 = '0' + (int)(*z.v); - PUTCHAR((int)(num1 & 0xff)); - return; - } - hp = z.v + len - 1; - rem = len % 3; + if (width) { + math_divertio(); + zprinto(z, 0L); + str = math_getdivertedio(); + math_fill(str, width); + free(str); + return; + } + if (zisneg(z)) + PUTCHAR('-'); + len = z.len; + if ((len == 1) && (*z.v <= (FULL) 7)) { + num1 = '0' + (int)(*z.v); + PUTCHAR((int)(num1 & 0xff)); + return; + } + hp = z.v + len - 1; + rem = len % 3; #if BASEB == 32 - switch (rem) { /* handle odd amounts first */ - case 0: - num1 = ((hp[0]) >> 8); - num2 = (((hp[0] & 0xff) << 16) + (hp[-1] >> 16)); - num3 = (((hp[-1] & 0xffff) << 8) + (hp[-2] >> 24)); - num4 = (hp[-2] & 0xffffff); - if (num1) { - PRINTF4("0%lo%08lo%08lo%08lo", - (PRINT) num1, (PRINT) num2, - (PRINT) num3, (PRINT) num4); - } else { - PRINTF3("0%lo%08lo%08lo", - (PRINT) num2, (PRINT) num3, (PRINT) num4); - } - rem = 3; - break; - case 1: - PRINTF1("0%lo", (PRINT) hp[0]); - break; - case 2: - num1 = ((hp[0]) >> 16); - num2 = (((hp[0] & 0xffff) << 8) + (hp[-1] >> 24)); - num3 = (hp[-1] & 0xffffff); - if (num1) { - PRINTF3("0%lo%08lo%08lo", - (PRINT) num1, (PRINT) num2, (PRINT) num3); - } else { - PRINTF2("0%lo%08lo", (PRINT) num2, (PRINT) num3); - } - break; - } - len -= rem; - if (len > 0) { - hp -= rem; - while (len > 0) { /* finish in groups of 3 words */ - PRINTF4("%08lo%08lo%08lo%08lo", - (PRINT) ((hp[0]) >> 8), - (PRINT) (((hp[0] & 0xff) << 16) + (hp[-1] >> 16)), - (PRINT) (((hp[-1] & 0xffff) << 8) + (hp[-2] >> 24)), - (PRINT) (hp[-2] & 0xffffff)); - hp -= 3; - len -= 3; - } - } + switch (rem) { /* handle odd amounts first */ + case 0: + num1 = ((hp[0]) >> 8); + num2 = (((hp[0] & 0xff) << 16) + (hp[-1] >> 16)); + num3 = (((hp[-1] & 0xffff) << 8) + (hp[-2] >> 24)); + num4 = (hp[-2] & 0xffffff); + if (num1) { + PRINTF4("0%lo%08lo%08lo%08lo", + (PRINT) num1, (PRINT) num2, + (PRINT) num3, (PRINT) num4); + } else { + PRINTF3("0%lo%08lo%08lo", + (PRINT) num2, (PRINT) num3, (PRINT) num4); + } + rem = 3; + break; + case 1: + PRINTF1("0%lo", (PRINT) hp[0]); + break; + case 2: + num1 = ((hp[0]) >> 16); + num2 = (((hp[0] & 0xffff) << 8) + (hp[-1] >> 24)); + num3 = (hp[-1] & 0xffffff); + if (num1) { + PRINTF3("0%lo%08lo%08lo", + (PRINT) num1, (PRINT) num2, (PRINT) num3); + } else { + PRINTF2("0%lo%08lo", (PRINT) num2, (PRINT) num3); + } + break; + } + len -= rem; + if (len > 0) { + hp -= rem; + while (len > 0) { /* finish in groups of 3 words */ + PRINTF4("%08lo%08lo%08lo%08lo", + (PRINT) ((hp[0]) >> 8), + (PRINT) (((hp[0] & 0xff) << 16) + (hp[-1] >> 16)), + (PRINT) (((hp[-1] & 0xffff) << 8) + (hp[-2] >> 24)), + (PRINT) (hp[-2] & 0xffffff)); + hp -= 3; + len -= 3; + } + } #else - switch (rem) { /* handle odd amounts first */ - case 0: - num1 = ((((FULL) hp[0]) << 8) + (((FULL) hp[-1]) >> 8)); - num2 = ((((FULL) (hp[-1] & 0xff)) << 16) + ((FULL) hp[-2])); - rem = 3; - break; - case 1: - num1 = 0; - num2 = (FULL) hp[0]; - break; - case 2: - num1 = (((FULL) hp[0]) >> 8); - num2 = ((((FULL) (hp[0] & 0xff)) << 16) + ((FULL) hp[-1])); - break; - } - if (num1) { - PRINTF2("0%lo%08lo", num1, num2); - } else { - PRINTF1("0%lo", num2); - } - len -= rem; - if (len > 0) { - hp -= rem; - while (len > 0) { /* finish in groups of 3 halfwords */ - PRINTF2("%08lo%08lo", - ((((FULL) hp[0]) << 8) + (((FULL) hp[-1]) >> 8)), - ((((FULL) (hp[-1] & 0xff))<<16) + ((FULL) hp[-2]))); - hp -= 3; - len -= 3; - } - } + switch (rem) { /* handle odd amounts first */ + case 0: + num1 = ((((FULL) hp[0]) << 8) + (((FULL) hp[-1]) >> 8)); + num2 = ((((FULL) (hp[-1] & 0xff)) << 16) + ((FULL) hp[-2])); + rem = 3; + break; + case 1: + num1 = 0; + num2 = (FULL) hp[0]; + break; + case 2: + num1 = (((FULL) hp[0]) >> 8); + num2 = ((((FULL) (hp[0] & 0xff)) << 16) + ((FULL) hp[-1])); + break; + } + if (num1) { + PRINTF2("0%lo%08lo", num1, num2); + } else { + PRINTF1("0%lo", num2); + } + len -= rem; + if (len > 0) { + hp -= rem; + while (len > 0) { /* finish in groups of 3 halfwords */ + PRINTF2("%08lo%08lo", + ((((FULL) hp[0]) << 8) + (((FULL) hp[-1]) >> 8)), + ((((FULL) (hp[-1] & 0xff))<<16) + ((FULL) hp[-2]))); + hp -= 3; + len -= 3; + } + } #endif } @@ -607,223 +607,223 @@ zprinto(ZVALUE z, long width) * Decimals supplies number of decimal places to print, with a decimal * point at the right location, with zero meaning no decimal point. * Width is the number of columns to print the number in, including the - * decimal point and sign if required. If zero, no extra output is done. + * decimal point and sign if required. If zero, no extra output is done. * If positive, leading spaces are typed if necessary. If negative, trailing * spaces are typed if necessary. As examples of the effects of these values, - * (345,0,0) = "345", (345,2,0) = "3.45", (345,5,8) = " .00345". + * (345,0,0) = "345", (345,2,0) = "3.45", (345,5,8) = " .00345". * * given: - * z number to be printed - * decimals number of decimal places - * width number of columns to print in + * z number to be printed + * decimals number of decimal places + * width number of columns to print in */ void zprintval(ZVALUE z, long decimals, long width) { - int depth; /* maximum depth */ - int n; /* current index into array */ - long i; /* number to print */ - long leadspaces; /* number of leading spaces to print */ - long putpoint; /* digits until print decimal point */ - long digits; /* number of digits of raw number */ - bool output; /* true if have output something */ - bool neg; /* true if negative */ - ZVALUE quo, rem; /* quotient and remainder */ - ZVALUE leftnums[32]; /* left parts of the number */ - ZVALUE rightnums[32]; /* right parts of the number */ + int depth; /* maximum depth */ + int n; /* current index into array */ + long i; /* number to print */ + long leadspaces; /* number of leading spaces to print */ + long putpoint; /* digits until print decimal point */ + long digits; /* number of digits of raw number */ + bool output; /* true if have output something */ + bool neg; /* true if negative */ + ZVALUE quo, rem; /* quotient and remainder */ + ZVALUE leftnums[32]; /* left parts of the number */ + ZVALUE rightnums[32]; /* right parts of the number */ - if (decimals < 0) - decimals = 0; - if (width < 0) - width = 0; - neg = (z.sign != 0); + if (decimals < 0) + decimals = 0; + if (width < 0) + width = 0; + neg = (z.sign != 0); - leadspaces = width - neg - (decimals > 0); - z.sign = 0; - /* - * Find the 2^N power of ten which is greater than or equal - * to the number, calculating it the first time if necessary. - */ - _tenpowers_[0] = _ten_; - depth = 0; - while ((_tenpowers_[depth].len < z.len) || - (zrel(_tenpowers_[depth], z) <= 0)) { - depth++; - if (_tenpowers_[depth].len == 0) { - if (depth <= TEN_MAX) { - zsquare(_tenpowers_[depth-1], - &_tenpowers_[depth]); - } else { - math_error("cannot compute 10^2^(TEN_MAX+1)"); - not_reached(); - } - } - } - /* - * Divide by smaller 2^N powers of ten until the parts are small - * enough to output. This algorithm walks through a binary tree - * where each node is a piece of the number to print, and such that - * we visit left nodes first. We do the needed recursion in line. - */ - digits = 1; - output = false; - n = 0; - putpoint = 0; - rightnums[0].len = 0; - leftnums[0] = z; - for (;;) { - while (n < depth) { - i = depth - n - 1; - zdiv(leftnums[n], _tenpowers_[i], &quo, &rem, 0); - if (!ziszero(quo)) - digits += (1L << i); - n++; - leftnums[n] = quo; - rightnums[n] = rem; - } - i = (long)(leftnums[n].v[0]); - if (output || i || (n == 0)) { - if (!output) { - output = true; - if (decimals < digits) - leadspaces -= digits; - else - leadspaces -= decimals+conf->leadzero; - while (--leadspaces >= 0) - PUTCHAR(' '); - if (neg) - PUTCHAR('-'); - if (decimals) { - putpoint = (digits - decimals); - if (putpoint <= 0) { - if (conf->leadzero) - PUTCHAR('0'); - PUTCHAR('.'); - while (++putpoint <= 0) - PUTCHAR('0'); - putpoint = 0; - } - } - } - i += '0'; - PUTCHAR((int)(i & 0xff)); - if (--putpoint == 0) - PUTCHAR('.'); - } - while (rightnums[n].len == 0) { - if (n <= 0) - return; - if (leftnums[n].len) - zfree(leftnums[n]); - n--; - } - zfree(leftnums[n]); - leftnums[n] = rightnums[n]; - rightnums[n].len = 0; - } + leadspaces = width - neg - (decimals > 0); + z.sign = 0; + /* + * Find the 2^N power of ten which is greater than or equal + * to the number, calculating it the first time if necessary. + */ + _tenpowers_[0] = _ten_; + depth = 0; + while ((_tenpowers_[depth].len < z.len) || + (zrel(_tenpowers_[depth], z) <= 0)) { + depth++; + if (_tenpowers_[depth].len == 0) { + if (depth <= TEN_MAX) { + zsquare(_tenpowers_[depth-1], + &_tenpowers_[depth]); + } else { + math_error("cannot compute 10^2^(TEN_MAX+1)"); + not_reached(); + } + } + } + /* + * Divide by smaller 2^N powers of ten until the parts are small + * enough to output. This algorithm walks through a binary tree + * where each node is a piece of the number to print, and such that + * we visit left nodes first. We do the needed recursion in line. + */ + digits = 1; + output = false; + n = 0; + putpoint = 0; + rightnums[0].len = 0; + leftnums[0] = z; + for (;;) { + while (n < depth) { + i = depth - n - 1; + zdiv(leftnums[n], _tenpowers_[i], &quo, &rem, 0); + if (!ziszero(quo)) + digits += (1L << i); + n++; + leftnums[n] = quo; + rightnums[n] = rem; + } + i = (long)(leftnums[n].v[0]); + if (output || i || (n == 0)) { + if (!output) { + output = true; + if (decimals < digits) + leadspaces -= digits; + else + leadspaces -= decimals+conf->leadzero; + while (--leadspaces >= 0) + PUTCHAR(' '); + if (neg) + PUTCHAR('-'); + if (decimals) { + putpoint = (digits - decimals); + if (putpoint <= 0) { + if (conf->leadzero) + PUTCHAR('0'); + PUTCHAR('.'); + while (++putpoint <= 0) + PUTCHAR('0'); + putpoint = 0; + } + } + } + i += '0'; + PUTCHAR((int)(i & 0xff)); + if (--putpoint == 0) + PUTCHAR('.'); + } + while (rightnums[n].len == 0) { + if (n <= 0) + return; + if (leftnums[n].len) + zfree(leftnums[n]); + n--; + } + zfree(leftnums[n]); + leftnums[n] = rightnums[n]; + rightnums[n].len = 0; + } } /* * Read an integer value in decimal, hex, octal, or binary. * Hex numbers are indicated by a leading "0x", binary with a leading "0b", - * and octal by a leading "0". Periods are skipped over, but any other + * and octal by a leading "0". Periods are skipped over, but any other * extraneous character stops the scan. */ void str2z(char *s, ZVALUE *res) { - ZVALUE z, ztmp, digit; - HALF digval; - bool minus; - long shift; + ZVALUE z, ztmp, digit; + HALF digval; + bool minus; + long shift; - /* firewall */ - if (s == NULL) { - math_error("%s: s NULL", __func__); - not_reached(); - } - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (s == NULL) { + math_error("%s: s NULL", __func__); + not_reached(); + } + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - minus = false; - shift = 0; - if (*s == '+') - s++; - else if (*s == '-') { - minus = true; - s++; - } - if (*s == '0') { /* possibly hex, octal, or binary */ - s++; - if ((*s >= '0') && (*s <= '7')) { - shift = 3; - } else if ((*s == 'x') || (*s == 'X')) { - shift = 4; - s++; - } else if ((*s == 'b') || (*s == 'B')) { - shift = 1; - s++; - } - } - digit.v = &digval; - digit.len = 1; - digit.sign = 0; - z = _zero_; - while (*s) { - digval = *s++; - if ((digval >= '0') && (digval <= '9')) - digval -= '0'; - else if ((digval >= 'a') && (digval <= 'f') && shift) - digval -= ('a' - 10); - else if ((digval >= 'A') && (digval <= 'F') && shift) - digval -= ('A' - 10); - else if (digval == '.') - continue; - else - break; - if (shift) - zshift(z, shift, &ztmp); - else - zmuli(z, 10L, &ztmp); - zfree(z); - zadd(ztmp, digit, &z); - zfree(ztmp); - } - ztrim(&z); - if (minus && !ziszero(z)) - z.sign = 1; - *res = z; + minus = false; + shift = 0; + if (*s == '+') + s++; + else if (*s == '-') { + minus = true; + s++; + } + if (*s == '0') { /* possibly hex, octal, or binary */ + s++; + if ((*s >= '0') && (*s <= '7')) { + shift = 3; + } else if ((*s == 'x') || (*s == 'X')) { + shift = 4; + s++; + } else if ((*s == 'b') || (*s == 'B')) { + shift = 1; + s++; + } + } + digit.v = &digval; + digit.len = 1; + digit.sign = 0; + z = _zero_; + while (*s) { + digval = *s++; + if ((digval >= '0') && (digval <= '9')) + digval -= '0'; + else if ((digval >= 'a') && (digval <= 'f') && shift) + digval -= ('a' - 10); + else if ((digval >= 'A') && (digval <= 'F') && shift) + digval -= ('A' - 10); + else if (digval == '.') + continue; + else + break; + if (shift) + zshift(z, shift, &ztmp); + else + zmuli(z, 10L, &ztmp); + zfree(z); + zadd(ztmp, digit, &z); + zfree(ztmp); + } + ztrim(&z); + if (minus && !ziszero(z)) + z.sign = 1; + *res = z; } void fitzprint(ZVALUE z, long digits, long show) { - ZVALUE ztmp1, ztmp2; - long i; + ZVALUE ztmp1, ztmp2; + long i; - if (digits <= show) { - zprintval(z, 0, 0); - return; - } - show /= 2; - ztenpow(digits - show, &ztmp1); - (void) zquo(z, ztmp1, &ztmp2, 1); - zprintval(ztmp2, 0, 0); - zfree(ztmp1); - zfree(ztmp2); - printf("..."); - ztenpow(show, &ztmp1); - (void) zmod(z, ztmp1, &ztmp2, 0); - i = zdigits(ztmp2); - while (i++ < show) - printf("0"); - zprintval(ztmp2, 0, 0); - zfree(ztmp1); - zfree(ztmp2); + if (digits <= show) { + zprintval(z, 0, 0); + return; + } + show /= 2; + ztenpow(digits - show, &ztmp1); + (void) zquo(z, ztmp1, &ztmp2, 1); + zprintval(ztmp2, 0, 0); + zfree(ztmp1); + zfree(ztmp2); + printf("..."); + ztenpow(show, &ztmp1); + (void) zmod(z, ztmp1, &ztmp2, 0); + i = zdigits(ztmp2); + while (i++ < show) + printf("0"); + zprintval(ztmp2, 0, 0); + zfree(ztmp1); + zfree(ztmp2); } /* END CODE */ diff --git a/zmath.c b/zmath.c index d7c61c8..63356f1 100644 --- a/zmath.c +++ b/zmath.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,10 +19,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1990/02/15 01:48:28 - * File existed as early as: before 1990 + * Under source code control: 1990/02/15 01:48:28 + * File existed as early as: before 1990 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -33,7 +33,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ HALF _zeroval_[] = { 0 }; @@ -68,7 +68,7 @@ ZVALUE _b64_ = { _pow4baseval_, 3, 0 }; ZVALUE _b32_ = { _pow4baseval_, 3, 0 }; ZVALUE _b64_ = { _pow8baseval_, 5, 0 }; #else - -=@=- BASEB not 16 or 32 -=@=- + -=@=- BASEB not 16 or 32 -=@=- #endif /* @@ -82,7 +82,7 @@ HALF *half_tbl[] = { _sqbaseval_, _pow4baseval_, _pow8baseval_, - NULL /* must be last */ + NULL /* must be last */ }; @@ -97,107 +97,107 @@ HALF *half_tbl[] = { */ HALF highhalf[BASEB+1] = { #if BASEB == 32 - 0x00000000, - 0x80000000, 0xC0000000, 0xE0000000, 0xF0000000, - 0xF8000000, 0xFC000000, 0xFE000000, 0xFF000000, - 0xFF800000, 0xFFC00000, 0xFFE00000, 0xFFF00000, - 0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000, - 0xFFFF8000, 0xFFFFC000, 0xFFFFE000, 0xFFFFF000, - 0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00, 0xFFFFFF00, - 0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0, 0xFFFFFFF0, - 0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE, 0xFFFFFFFF + 0x00000000, + 0x80000000, 0xC0000000, 0xE0000000, 0xF0000000, + 0xF8000000, 0xFC000000, 0xFE000000, 0xFF000000, + 0xFF800000, 0xFFC00000, 0xFFE00000, 0xFFF00000, + 0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000, + 0xFFFF8000, 0xFFFFC000, 0xFFFFE000, 0xFFFFF000, + 0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00, 0xFFFFFF00, + 0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0, 0xFFFFFFF0, + 0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE, 0xFFFFFFFF #elif BASEB == 16 - 0x0000, - 0x8000, 0xC000, 0xE000, 0xF000, - 0xF800, 0xFC00, 0xFE00, 0xFF00, - 0xFF80, 0xFFC0, 0xFFE0, 0xFFF0, - 0xFFF8, 0xFFFC, 0xFFFE, 0xFFFF + 0x0000, + 0x8000, 0xC000, 0xE000, 0xF000, + 0xF800, 0xFC00, 0xFE00, 0xFF00, + 0xFF80, 0xFFC0, 0xFFE0, 0xFFF0, + 0xFFF8, 0xFFFC, 0xFFFE, 0xFFFF #else - -=@=- BASEB not 16 or 32 -=@=- + -=@=- BASEB not 16 or 32 -=@=- #endif }; HALF rhighhalf[BASEB+1] = { #if BASEB == 32 - 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFC, 0xFFFFFFF8, - 0xFFFFFFF0, 0xFFFFFFE0, 0xFFFFFFC0, 0xFFFFFF80, - 0xFFFFFF00, 0xFFFFFE00, 0xFFFFFC00, 0xFFFFF800, - 0xFFFFF000, 0xFFFFE000, 0xFFFFC000, 0xFFFF8000, - 0xFFFF0000, 0xFFFE0000, 0xFFFC0000, 0xFFF80000, - 0xFFF00000, 0xFFE00000, 0xFFC00000, 0xFF800000, - 0xFF000000, 0xFE000000, 0xFC000000, 0xF8000000, - 0xF0000000, 0xE0000000, 0xC0000000, 0x80000000, - 0x00000000 + 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFC, 0xFFFFFFF8, + 0xFFFFFFF0, 0xFFFFFFE0, 0xFFFFFFC0, 0xFFFFFF80, + 0xFFFFFF00, 0xFFFFFE00, 0xFFFFFC00, 0xFFFFF800, + 0xFFFFF000, 0xFFFFE000, 0xFFFFC000, 0xFFFF8000, + 0xFFFF0000, 0xFFFE0000, 0xFFFC0000, 0xFFF80000, + 0xFFF00000, 0xFFE00000, 0xFFC00000, 0xFF800000, + 0xFF000000, 0xFE000000, 0xFC000000, 0xF8000000, + 0xF0000000, 0xE0000000, 0xC0000000, 0x80000000, + 0x00000000 #elif BASEB == 16 - 0xFFFF, 0xFFFE, 0xFFFC, 0xFFF8, - 0xFFF0, 0xFFE0, 0xFFC0, 0xFF80, - 0xFF00, 0xFE00, 0xFC00, 0xF800, - 0xF000, 0xE000, 0xC000, 0x8000, - 0x0000 + 0xFFFF, 0xFFFE, 0xFFFC, 0xFFF8, + 0xFFF0, 0xFFE0, 0xFFC0, 0xFF80, + 0xFF00, 0xFE00, 0xFC00, 0xF800, + 0xF000, 0xE000, 0xC000, 0x8000, + 0x0000 #else - -=@=- BASEB not 16 or 32 -=@=- + -=@=- BASEB not 16 or 32 -=@=- #endif }; HALF lowhalf[BASEB+1] = { - 0x0, - 0x1, 0x3, 0x7, 0xF, - 0x1F, 0x3F, 0x7F, 0xFF, - 0x1FF, 0x3FF, 0x7FF, 0xFFF, - 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF + 0x0, + 0x1, 0x3, 0x7, 0xF, + 0x1F, 0x3F, 0x7F, 0xFF, + 0x1FF, 0x3FF, 0x7FF, 0xFFF, + 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF #if BASEB == 32 ,0x1FFFF, 0x3FFFF, 0x7FFFF, 0xFFFFF, - 0x1FFFFF, 0x3FFFFF, 0x7FFFFF, 0xFFFFFF, - 0x1FFFFFF, 0x3FFFFFF, 0x7FFFFFF, 0xFFFFFFF, - 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF + 0x1FFFFF, 0x3FFFFF, 0x7FFFFF, 0xFFFFFF, + 0x1FFFFFF, 0x3FFFFFF, 0x7FFFFFF, 0xFFFFFFF, + 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF #endif }; HALF rlowhalf[BASEB+1] = { #if BASEB == 32 - 0xFFFFFFFF, 0x7FFFFFFF, 0x3FFFFFFF, 0x1FFFFFFF, - 0xFFFFFFF, 0x7FFFFFF, 0x3FFFFFF, 0x1FFFFFF, - 0xFFFFFF, 0x7FFFFF, 0x3FFFFF, 0x1FFFFF, - 0xFFFFF, 0x7FFFF, 0x3FFFF, 0x1FFFF, + 0xFFFFFFFF, 0x7FFFFFFF, 0x3FFFFFFF, 0x1FFFFFFF, + 0xFFFFFFF, 0x7FFFFFF, 0x3FFFFFF, 0x1FFFFFF, + 0xFFFFFF, 0x7FFFFF, 0x3FFFFF, 0x1FFFFF, + 0xFFFFF, 0x7FFFF, 0x3FFFF, 0x1FFFF, #endif - 0xFFFF, 0x7FFF, 0x3FFF, 0x1FFF, - 0xFFF, 0x7FF, 0x3FF, 0x1FF, - 0xFF, 0x7F, 0x3F, 0x1F, - 0xF, 0x7, 0x3, 0x1, - 0x0 + 0xFFFF, 0x7FFF, 0x3FFF, 0x1FFF, + 0xFFF, 0x7FF, 0x3FF, 0x1FF, + 0xFF, 0x7F, 0x3F, 0x1F, + 0xF, 0x7, 0x3, 0x1, + 0x0 }; HALF bitmask[(2*BASEB)+1] = { #if BASEB == 32 - 0x00000001, 0x00000002, 0x00000004, 0x00000008, - 0x00000010, 0x00000020, 0x00000040, 0x00000080, - 0x00000100, 0x00000200, 0x00000400, 0x00000800, - 0x00001000, 0x00002000, 0x00004000, 0x00008000, - 0x00010000, 0x00020000, 0x00040000, 0x00080000, - 0x00100000, 0x00200000, 0x00400000, 0x00800000, - 0x01000000, 0x02000000, 0x04000000, 0x08000000, - 0x10000000, 0x20000000, 0x40000000, 0x80000000, - 0x00000001, 0x00000002, 0x00000004, 0x00000008, - 0x00000010, 0x00000020, 0x00000040, 0x00000080, - 0x00000100, 0x00000200, 0x00000400, 0x00000800, - 0x00001000, 0x00002000, 0x00004000, 0x00008000, - 0x00010000, 0x00020000, 0x00040000, 0x00080000, - 0x00100000, 0x00200000, 0x00400000, 0x00800000, - 0x01000000, 0x02000000, 0x04000000, 0x08000000, - 0x10000000, 0x20000000, 0x40000000, 0x80000000, - 0x00000001 + 0x00000001, 0x00000002, 0x00000004, 0x00000008, + 0x00000010, 0x00000020, 0x00000040, 0x00000080, + 0x00000100, 0x00000200, 0x00000400, 0x00000800, + 0x00001000, 0x00002000, 0x00004000, 0x00008000, + 0x00010000, 0x00020000, 0x00040000, 0x00080000, + 0x00100000, 0x00200000, 0x00400000, 0x00800000, + 0x01000000, 0x02000000, 0x04000000, 0x08000000, + 0x10000000, 0x20000000, 0x40000000, 0x80000000, + 0x00000001, 0x00000002, 0x00000004, 0x00000008, + 0x00000010, 0x00000020, 0x00000040, 0x00000080, + 0x00000100, 0x00000200, 0x00000400, 0x00000800, + 0x00001000, 0x00002000, 0x00004000, 0x00008000, + 0x00010000, 0x00020000, 0x00040000, 0x00080000, + 0x00100000, 0x00200000, 0x00400000, 0x00800000, + 0x01000000, 0x02000000, 0x04000000, 0x08000000, + 0x10000000, 0x20000000, 0x40000000, 0x80000000, + 0x00000001 #elif BASEB == 16 - 0x0001, 0x0002, 0x0004, 0x0008, - 0x0010, 0x0020, 0x0040, 0x0080, - 0x0100, 0x0200, 0x0400, 0x0800, - 0x1000, 0x2000, 0x4000, 0x8000, - 0x0001, 0x0002, 0x0004, 0x0008, - 0x0010, 0x0020, 0x0040, 0x0080, - 0x0100, 0x0200, 0x0400, 0x0800, - 0x1000, 0x2000, 0x4000, 0x8000, - 0x0001 + 0x0001, 0x0002, 0x0004, 0x0008, + 0x0010, 0x0020, 0x0040, 0x0080, + 0x0100, 0x0200, 0x0400, 0x0800, + 0x1000, 0x2000, 0x4000, 0x8000, + 0x0001, 0x0002, 0x0004, 0x0008, + 0x0010, 0x0020, 0x0040, 0x0080, + 0x0100, 0x0200, 0x0400, 0x0800, + 0x1000, 0x2000, 0x4000, 0x8000, + 0x0001 #else - -=@=- BASEB not 16 or 32 -=@=- + -=@=- BASEB not 16 or 32 -=@=- #endif -}; /* actual rotation thru 8 cycles */ +}; /* actual rotation thru 8 cycles */ -bool _math_abort_; /* nonzero to abort calculations */ +bool _math_abort_; /* nonzero to abort calculations */ /* @@ -233,21 +233,21 @@ STATIC long nfree = 0; HALF * alloc(LEN len) { - HALF *hp; + HALF *hp; - if (_math_abort_) { - math_error("Calculation aborted"); - not_reached(); - } - hp = (HALF *) malloc((len+1) * sizeof(HALF)); - if (hp == 0) { - math_error("Not enough memory"); - not_reached(); - } + if (_math_abort_) { + math_error("Calculation aborted"); + not_reached(); + } + hp = (HALF *) malloc((len+1) * sizeof(HALF)); + if (hp == 0) { + math_error("Not enough memory"); + not_reached(); + } #ifdef ALLOCTEST - ++nalloc; + ++nalloc; #endif - return hp; + return hp; } @@ -255,32 +255,32 @@ alloc(LEN len) * is_const - determine if a HALF array is an pre-allocated array * * given: - * h pointer to the beginning of the HALF array + * h pointer to the beginning of the HALF array * * returns: - * true - h is found in the half_tbl array - * false - is is not found in the half_tbl array + * true - h is found in the half_tbl array + * false - is is not found in the half_tbl array */ int is_const(HALF *h) { - HALF **h_p; /* half_tbl array pointer */ + HALF **h_p; /* half_tbl array pointer */ - /* firewall */ - if (h == NULL) { - math_error("%s: h NULL", __func__); - not_reached(); - } + /* firewall */ + if (h == NULL) { + math_error("%s: h NULL", __func__); + not_reached(); + } - /* search the half_tbl for h */ - for (h_p = &half_tbl[0]; *h_p != NULL; ++h_p) { - if (h == *h_p) { - return true; /* found in the half_tbl array */ - } - } + /* search the half_tbl for h */ + for (h_p = &half_tbl[0]; *h_p != NULL; ++h_p) { + if (h == *h_p) { + return true; /* found in the half_tbl array */ + } + } - /* not found in the half_tbl array */ - return false; + /* not found in the half_tbl array */ + return false; } @@ -288,25 +288,25 @@ is_const(HALF *h) void freeh(HALF *h) { - /* firewall */ - if (h == NULL) { - math_error("%s: h NULL", __func__); - not_reached(); - } + /* firewall */ + if (h == NULL) { + math_error("%s: h NULL", __func__); + not_reached(); + } - /* free h is not a constant */ - if (!is_const(h)) { - free(h); - ++nfree; - } + /* free h is not a constant */ + if (!is_const(h)) { + free(h); + ++nfree; + } } void allocStat(void) { - fprintf(stderr, "nalloc: %ld nfree: %ld kept: %ld\n", - nalloc, nfree, nalloc - nfree); + fprintf(stderr, "nalloc: %ld nfree: %ld kept: %ld\n", + nalloc, nfree, nalloc - nfree); } #endif @@ -317,39 +317,39 @@ allocStat(void) void itoz(long i, ZVALUE *res) { - long diddle, len; + long diddle, len; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - res->len = 1; - res->sign = 0; - diddle = 0; - if (i == 0) { - res->v = _zeroval_; - return; - } - if (i < 0) { - res->sign = 1; - i = -i; - if (i < 0) { /* fix most negative number */ - diddle = 1; - i--; - } - } - if (i == 1) { - res->v = _oneval_; - return; - } - len = 1 + (((FULL) i) >= BASE); - res->len = (LEN)len; - res->v = alloc((LEN)len); - res->v[0] = (HALF) (i + diddle); - if (len == 2) - res->v[1] = (HALF) (i / BASE); + res->len = 1; + res->sign = 0; + diddle = 0; + if (i == 0) { + res->v = _zeroval_; + return; + } + if (i < 0) { + res->sign = 1; + i = -i; + if (i < 0) { /* fix most negative number */ + diddle = 1; + i--; + } + } + if (i == 1) { + res->v = _oneval_; + return; + } + len = 1 + (((FULL) i) >= BASE); + res->len = (LEN)len; + res->v = alloc((LEN)len); + res->v[0] = (HALF) (i + diddle); + if (len == 2) + res->v[1] = (HALF) (i / BASE); } @@ -360,14 +360,14 @@ itoz(long i, ZVALUE *res) long ztoi(ZVALUE z) { - long i; + long i; - if (zgtmaxlong(z)) { - i = MAXLONG; - return (z.sign ? -i : i); - } - i = ztolong(z); - return (z.sign ? -i : i); + if (zgtmaxlong(z)) { + i = MAXLONG; + return (z.sign ? -i : i); + } + i = ztolong(z); + return (z.sign ? -i : i); } @@ -377,30 +377,30 @@ ztoi(ZVALUE z) void utoz(FULL i, ZVALUE *res) { - long len; + long len; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - res->len = 1; - res->sign = 0; - if (i == 0) { - res->v = _zeroval_; - return; - } - if (i == 1) { - res->v = _oneval_; - return; - } - len = 1 + (((FULL) i) >= BASE); - res->len = (LEN)len; - res->v = alloc((LEN)len); - res->v[0] = (HALF)i; - if (len == 2) - res->v[1] = (HALF) (i / BASE); + res->len = 1; + res->sign = 0; + if (i == 0) { + res->v = _zeroval_; + return; + } + if (i == 1) { + res->v = _oneval_; + return; + } + len = 1 + (((FULL) i) >= BASE); + res->len = (LEN)len; + res->v = alloc((LEN)len); + res->v[0] = (HALF)i; + if (len == 2) + res->v[1] = (HALF) (i / BASE); } @@ -410,39 +410,39 @@ utoz(FULL i, ZVALUE *res) void stoz(SFULL i, ZVALUE *res) { - long diddle, len; + long diddle, len; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - res->len = 1; - res->sign = 0; - diddle = 0; - if (i == 0) { - res->v = _zeroval_; - return; - } - if (i < 0) { - res->sign = 1; - i = -i; - if (i < 0) { /* fix most negative number */ - diddle = 1; - i--; - } - } - if (i == 1) { - res->v = _oneval_; - return; - } - len = 1 + (((FULL) i) >= BASE); - res->len = (LEN)len; - res->v = alloc((LEN)len); - res->v[0] = (HALF) (i + diddle); - if (len == 2) - res->v[1] = (HALF) (i / BASE); + res->len = 1; + res->sign = 0; + diddle = 0; + if (i == 0) { + res->v = _zeroval_; + return; + } + if (i < 0) { + res->sign = 1; + i = -i; + if (i < 0) { /* fix most negative number */ + diddle = 1; + i--; + } + } + if (i == 1) { + res->v = _oneval_; + return; + } + len = 1 + (((FULL) i) >= BASE); + res->len = (LEN)len; + res->v = alloc((LEN)len); + res->v[0] = (HALF) (i + diddle); + if (len == 2) + res->v[1] = (HALF) (i / BASE); } @@ -454,10 +454,10 @@ stoz(SFULL i, ZVALUE *res) FULL ztou(ZVALUE z) { - if (z.len > 2) { - return MAXUFULL; - } - return ztofull(z); + if (z.len > 2) { + return MAXUFULL; + } + return ztofull(z); } @@ -470,29 +470,29 @@ ztou(ZVALUE z) SFULL ztos(ZVALUE z) { - FULL val; /* absolute value of the return value */ + FULL val; /* absolute value of the return value */ - /* negative value processing */ - if (z.sign) { - if (z.len > 2) { - return MINSFULL; - } - val = ztofull(z); - if (val > TOPFULL) { - return MINSFULL; - } - return (SFULL)(-val); - } + /* negative value processing */ + if (z.sign) { + if (z.len > 2) { + return MINSFULL; + } + val = ztofull(z); + if (val > TOPFULL) { + return MINSFULL; + } + return (SFULL)(-val); + } - /* positive value processing */ - if (z.len > 2) { - return (SFULL)MAXFULL; - } - val = ztofull(z); - if (val > MAXFULL) { - return (SFULL)MAXFULL; - } - return (SFULL)val; + /* positive value processing */ + if (z.len > 2) { + return (SFULL)MAXFULL; + } + val = ztofull(z); + if (val > MAXFULL) { + return (SFULL)MAXFULL; + } + return (SFULL)val; } @@ -502,21 +502,21 @@ ztos(ZVALUE z) void zcopy(ZVALUE z, ZVALUE *res) { - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - /* make copy */ - res->sign = z.sign; - res->len = z.len; - if (zisabsleone(z)) { /* zero or plus or minus one are easy */ - res->v = (z.v[0] ? _oneval_ : _zeroval_); - return; - } - res->v = alloc(z.len); - zcopyval(z, *res); + /* make copy */ + res->sign = z.sign; + res->len = z.len; + if (zisabsleone(z)) { /* zero or plus or minus one are easy */ + res->v = (z.v[0] ? _oneval_ : _zeroval_); + return; + } + res->v = alloc(z.len); + zcopyval(z, *res); } @@ -526,56 +526,56 @@ zcopy(ZVALUE z, ZVALUE *res) void zadd(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - ZVALUE dest; - HALF *p1, *p2, *pd; - long len; - FULL carry; - SIUNION sival; + ZVALUE dest; + HALF *p1, *p2, *pd; + long len; + FULL carry; + SIUNION sival; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (z1.sign && !z2.sign) { - z1.sign = 0; - zsub(z2, z1, res); - return; - } - if (z2.sign && !z1.sign) { - z2.sign = 0; - zsub(z1, z2, res); - return; - } - if (z2.len > z1.len) { - pd = z1.v; z1.v = z2.v; z2.v = pd; - len = z1.len; z1.len = z2.len; z2.len = (LEN)len; - } - dest.len = z1.len + 1; - dest.v = alloc(dest.len); - dest.sign = z1.sign; - carry = 0; - pd = dest.v; - p1 = z1.v; - p2 = z2.v; - len = z2.len; - while (len--) { - sival.ivalue = ((FULL) *p1++) + ((FULL) *p2++) + carry; - /* ignore Saber-C warning #112 - get ushort from uint */ - /* OK to ignore on name zadd`sival */ - *pd++ = sival.silow; - carry = sival.sihigh; - } - len = z1.len - z2.len; - while (len--) { - sival.ivalue = ((FULL) *p1++) + carry; - *pd++ = sival.silow; - carry = sival.sihigh; - } - *pd = (HALF)carry; - zquicktrim(dest); - *res = dest; + if (z1.sign && !z2.sign) { + z1.sign = 0; + zsub(z2, z1, res); + return; + } + if (z2.sign && !z1.sign) { + z2.sign = 0; + zsub(z1, z2, res); + return; + } + if (z2.len > z1.len) { + pd = z1.v; z1.v = z2.v; z2.v = pd; + len = z1.len; z1.len = z2.len; z2.len = (LEN)len; + } + dest.len = z1.len + 1; + dest.v = alloc(dest.len); + dest.sign = z1.sign; + carry = 0; + pd = dest.v; + p1 = z1.v; + p2 = z2.v; + len = z2.len; + while (len--) { + sival.ivalue = ((FULL) *p1++) + ((FULL) *p2++) + carry; + /* ignore Saber-C warning #112 - get ushort from uint */ + /* OK to ignore on name zadd`sival */ + *pd++ = sival.silow; + carry = sival.sihigh; + } + len = z1.len - z2.len; + while (len--) { + sival.ivalue = ((FULL) *p1++) + carry; + *pd++ = sival.silow; + carry = sival.sihigh; + } + *pd = (HALF)carry; + zquicktrim(dest); + *res = dest; } @@ -585,71 +585,71 @@ zadd(ZVALUE z1, ZVALUE z2, ZVALUE *res) void zsub(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - register HALF *h1, *h2, *hd; - long len1, len2; - FULL carry; - SIUNION sival; - ZVALUE dest; + register HALF *h1, *h2, *hd; + long len1, len2; + FULL carry; + SIUNION sival; + ZVALUE dest; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (z1.sign != z2.sign) { - z2.sign = z1.sign; - zadd(z1, z2, res); - return; - } - len1 = z1.len; - len2 = z2.len; - if (len1 == len2) { - h1 = z1.v + len1; - h2 = z2.v + len2; - while ((len1 > 0) && ((FULL)*--h1 == (FULL)*--h2)) { - len1--; - } - if (len1 == 0) { - *res = _zero_; - return; - } - len2 = len1; - carry = ((FULL)*h1 < (FULL)*h2); - } else { - carry = (len1 < len2); - } - dest.sign = z1.sign; - h1 = z1.v; - h2 = z2.v; - if (carry) { - carry = len1; - len1 = len2; - len2 = (long)carry; - h1 = z2.v; - h2 = z1.v; - dest.sign = !dest.sign; - } - hd = alloc((LEN)len1); - dest.v = hd; - dest.len = (LEN)len1; - len1 -= len2; - carry = 0; - while (--len2 >= 0) { - /* ignore Saber-C warning #112 - get ushort from uint */ - /* OK to ignore on name zsub`sival */ - sival.ivalue = (BASE1 - ((FULL) *h1++)) + *h2++ + carry; - *hd++ = (HALF)(BASE1 - sival.silow); - carry = sival.sihigh; - } - while (--len1 >= 0) { - sival.ivalue = (BASE1 - ((FULL) *h1++)) + carry; - *hd++ = (HALF)(BASE1 - sival.silow); - carry = sival.sihigh; - } - if (hd[-1] == 0) - ztrim(&dest); - *res = dest; + if (z1.sign != z2.sign) { + z2.sign = z1.sign; + zadd(z1, z2, res); + return; + } + len1 = z1.len; + len2 = z2.len; + if (len1 == len2) { + h1 = z1.v + len1; + h2 = z2.v + len2; + while ((len1 > 0) && ((FULL)*--h1 == (FULL)*--h2)) { + len1--; + } + if (len1 == 0) { + *res = _zero_; + return; + } + len2 = len1; + carry = ((FULL)*h1 < (FULL)*h2); + } else { + carry = (len1 < len2); + } + dest.sign = z1.sign; + h1 = z1.v; + h2 = z2.v; + if (carry) { + carry = len1; + len1 = len2; + len2 = (long)carry; + h1 = z2.v; + h2 = z1.v; + dest.sign = !dest.sign; + } + hd = alloc((LEN)len1); + dest.v = hd; + dest.len = (LEN)len1; + len1 -= len2; + carry = 0; + while (--len2 >= 0) { + /* ignore Saber-C warning #112 - get ushort from uint */ + /* OK to ignore on name zsub`sival */ + sival.ivalue = (BASE1 - ((FULL) *h1++)) + *h2++ + carry; + *hd++ = (HALF)(BASE1 - sival.silow); + carry = sival.sihigh; + } + while (--len1 >= 0) { + sival.ivalue = (BASE1 - ((FULL) *h1++)) + carry; + *hd++ = (HALF)(BASE1 - sival.silow); + carry = sival.sihigh; + } + if (hd[-1] == 0) + ztrim(&dest); + *res = dest; } @@ -659,85 +659,85 @@ zsub(ZVALUE z1, ZVALUE z2, ZVALUE *res) void zmuli(ZVALUE z, long n, ZVALUE *res) { - register HALF *h1, *sd; - FULL low; - FULL high; - FULL carry; - long len; - SIUNION sival; - ZVALUE dest; + register HALF *h1, *sd; + FULL low; + FULL high; + FULL carry; + long len; + SIUNION sival; + ZVALUE dest; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if ((n == 0) || ziszero(z)) { - *res = _zero_; - return; - } - if (n < 0) { - n = -n; - z.sign = !z.sign; - } - if (n == 1) { - zcopy(z, res); - return; - } + if ((n == 0) || ziszero(z)) { + *res = _zero_; + return; + } + if (n < 0) { + n = -n; + z.sign = !z.sign; + } + if (n == 1) { + zcopy(z, res); + return; + } #if LONG_BITS > BASEB - low = ((FULL) n) & BASE1; - high = ((FULL) n) >> BASEB; + low = ((FULL) n) & BASE1; + high = ((FULL) n) >> BASEB; #else - low = (FULL)n; - high = 0; + low = (FULL)n; + high = 0; #endif - dest.len = z.len + 2; - dest.v = alloc(dest.len); - dest.sign = z.sign; - /* - * Multiply by the low digit. - */ - h1 = z.v; - sd = dest.v; - len = z.len; - carry = 0; - while (len--) { - /* ignore Saber-C warning #112 - get ushort from uint */ - /* OK to ignore on name zmuli`sival */ - sival.ivalue = ((FULL) *h1++) * low + carry; - *sd++ = sival.silow; - carry = sival.sihigh; - } - *sd = (HALF)carry; - /* - * If there was only one digit, then we are all done except - * for trimming the number if there was no last carry. - */ - if (high == 0) { - dest.len--; - if (carry == 0) - dest.len--; - *res = dest; - return; - } - /* - * Need to multiply by the high digit and add it into the - * previous value. Clear the final word of rubbish first. - */ - *(++sd) = 0; - h1 = z.v; - sd = dest.v + 1; - len = z.len; - carry = 0; - while (len--) { - sival.ivalue = ((FULL) *h1++) * high + ((FULL) *sd) + carry; - *sd++ = sival.silow; - carry = sival.sihigh; - } - *sd = (HALF)carry; - zquicktrim(dest); - *res = dest; + dest.len = z.len + 2; + dest.v = alloc(dest.len); + dest.sign = z.sign; + /* + * Multiply by the low digit. + */ + h1 = z.v; + sd = dest.v; + len = z.len; + carry = 0; + while (len--) { + /* ignore Saber-C warning #112 - get ushort from uint */ + /* OK to ignore on name zmuli`sival */ + sival.ivalue = ((FULL) *h1++) * low + carry; + *sd++ = sival.silow; + carry = sival.sihigh; + } + *sd = (HALF)carry; + /* + * If there was only one digit, then we are all done except + * for trimming the number if there was no last carry. + */ + if (high == 0) { + dest.len--; + if (carry == 0) + dest.len--; + *res = dest; + return; + } + /* + * Need to multiply by the high digit and add it into the + * previous value. Clear the final word of rubbish first. + */ + *(++sd) = 0; + h1 = z.v; + sd = dest.v + 1; + len = z.len; + carry = 0; + while (len--) { + sival.ivalue = ((FULL) *h1++) * high + ((FULL) *sd) + carry; + *sd++ = sival.silow; + carry = sival.sihigh; + } + *sd = (HALF)carry; + zquicktrim(dest); + *res = dest; } @@ -749,30 +749,30 @@ zmuli(ZVALUE z, long n, ZVALUE *res) void zreduce(ZVALUE z1, ZVALUE z2, ZVALUE *z1res, ZVALUE *z2res) { - ZVALUE tmp; + ZVALUE tmp; - /* firewall */ - if (z1res == NULL) { - math_error("%s: z1res NULL", __func__); - not_reached(); - } - if (z2res == NULL) { - math_error("%s: z2res NULL", __func__); - not_reached(); - } + /* firewall */ + if (z1res == NULL) { + math_error("%s: z1res NULL", __func__); + not_reached(); + } + if (z2res == NULL) { + math_error("%s: z2res NULL", __func__); + not_reached(); + } - if (zisabsleone(z1) || zisabsleone(z2)) - tmp = _one_; - else - zgcd(z1, z2, &tmp); - if (zisunit(tmp)) { - zcopy(z1, z1res); - zcopy(z2, z2res); - } else { - zequo(z1, tmp, z1res); - zequo(z2, tmp, z2res); - } - zfree(tmp); + if (zisabsleone(z1) || zisabsleone(z2)) + tmp = _one_; + else + zgcd(z1, z2, &tmp); + if (zisunit(tmp)) { + zcopy(z1, z1res); + zcopy(z2, z2res); + } else { + zequo(z1, tmp, z1res); + zequo(z2, tmp, z2res); + } + zfree(tmp); } @@ -785,242 +785,242 @@ zreduce(ZVALUE z1, ZVALUE z2, ZVALUE *z1res, ZVALUE *z2res) long zdiv(ZVALUE z1, ZVALUE z2, ZVALUE *quo, ZVALUE *rem, long rnd) { - register HALF *a, *b; - HALF s, u; - HALF *A, *B, *a1, *b0; - FULL f, g, h, x; - bool adjust, onebit; - LEN m, n, len, i, p, j1, j2, k; - long t, val; + register HALF *a, *b; + HALF s, u; + HALF *A, *B, *a1, *b0; + FULL f, g, h, x; + bool adjust, onebit; + LEN m, n, len, i, p, j1, j2, k; + long t, val; - /* firewall */ - if (quo == NULL) { - math_error("%s: quo NULL", __func__); - not_reached(); - } - if (rem == NULL) { - math_error("%s: rem NULL", __func__); - not_reached(); - } + /* firewall */ + if (quo == NULL) { + math_error("%s: quo NULL", __func__); + not_reached(); + } + if (rem == NULL) { + math_error("%s: rem NULL", __func__); + not_reached(); + } - if (ziszero(z2)) { - math_error("Division by zero in zdiv"); - not_reached(); - } - m = z1.len; - n = z2.len; - B = z2.v; - s = 0; - if (m < n) { - A = alloc(n + 1); - memcpy(A, z1.v, m * sizeof(HALF)); - for (i = m; i <= n; i++) - A[i] = 0; - a1 = A + n; - len = 1; - goto done; - } - A = alloc(m + 2); - memcpy(A, z1.v, m * sizeof(HALF)); - A[m] = 0; - A[m + 1] = 0; - len = m - n + 1; /* quotient length will be len or len +/- 1 */ - a1 = A + n; /* start of digits for quotient */ - b0 = B; - p = n; - while (!*b0) { /* b0: working start for divisor */ - ++b0; - --p; - } - if (p == 1) { - u = *b0; - if (u == 1) { - for (; m >= n; m--) - A[m] = A[m - 1]; - A[m] = 0; - goto done; - } - f = 0; - a = A + m; - i = len; - while (i--) { - f = f << BASEB | *--a; - a[1] = (HALF)(f / u); - f = f % u; - } - *a = (HALF)f; - m = n; - goto done; - } - f = B[n - 1]; - k = 1; - while (f >>= 1) - k++; /* k: number of bits in top divisor digit */ - j1 = BASEB - k; - j2 = BASEB + j1; - h = j1 ? ((FULL) B[n - 1] << j1 | B[n - 2] >> k) : B[n-1]; - onebit = (bool)((B[n - 2] >> (k - 1)) & 1); - m++; - while (m > n) { - m--; - f = (FULL) A[m] << j2 | (FULL) A[m - 1] << j1; - if (j1) f |= A[m - 2] >> k; - if (s) f = ~f; - x = f / h; - if (x) { - if (onebit && x > TOPHALF + f % h) - x--; - a = A + m - p; - b = b0; - u = 0; - i = p; - if (s) { - while (i--) { - f = (FULL) *a + u + x * *b++; - *a++ = (HALF) f; - u = (HALF) (f >> BASEB); - } - s = *a + u; - A[m] = (HALF) (~x + !s); - } else { - while (i--) { - f = (FULL) *a - u - x * *b++; - *a++ = (HALF) f; - u = -(HALF)(f >> BASEB); - } - s = *a - u; - A[m] = (HALF)(x + s); - } - } - else - A[m] = s; - } -done: while (m > 0 && A[m - 1] == 0) - m--; - if (m == 0 && s == 0) { - *rem = _zero_; - val = 0; - if (a1[len - 1] == 0) - len--; - if (len == 0) { - *quo = _zero_; - } else { - quo->len = len; - quo->v = alloc(len); - memcpy(quo->v, a1, len * sizeof(HALF)); - quo->sign = z1.sign ^ z2.sign; - } - freeh(A); - return val; - } - if (rnd & 8) - adjust = (((*a1 ^ rnd) & 1) ? true : false); - else - adjust = (((rnd & 1) ^ z1.sign ^ z2.sign) ? true : false); - if (rnd & 2) - adjust ^= z1.sign ^ z2.sign; - if (rnd & 4) - adjust ^= z2.sign; - if (rnd & 16) { /* round-off case */ - a = A + n; - b = B + n; - i = n + 1; - f = g = 0; - t = -1; - if (s) { - while (--i > 0) { - g = (FULL) *--a + (*--b >> 1 | f); - f = *b & 1 ? TOPHALF : 0; - if (g != BASE1) - break; - } - if (g == BASE && f == 0) { - while ((--i > 0) && ((*--a | *--b) == 0)); - t = (i > 0); - } else if (g >= BASE) { - t = 1; - } - } else { - while (--i > 0) { - g = (FULL) *--a - (*--b >> 1 | f); - f = *b & 1 ? TOPHALF : 0; - if (g != 0) - break; - } - if (g > 0 && g < BASE) - t = 1; - else if (g == 0 && f == 0) - t = 0; - } - if (t) - adjust = (t > 0); - } - if (adjust) { - i = len; - a = a1; - while (i > 0 && *a == BASE1) { - i--; - *a++ = 0; - } - (*a)++; - if (i == 0) - len++; - } - if (s && adjust) { - i = 0; - while (A[i] == 0) - i++; - A[i] = -A[i]; - while (++i < n) - A[i] = ~A[i]; - m = n; - while (A[m - 1] == 0) - m--; - } - if (!s && adjust) { - a = A; - b = B; - i = n; - u = 0; - while (i--) { - f = (FULL) *b++ - *a - (FULL) u; - *a++ = (HALF) f; - u = -(HALF)(f >> BASEB); - } - m = n; - while (A[m - 1] == 0) - m--; - } - if (s && !adjust) { - a = A; - b = B; - i = n; - f = 0; - while (i--) { - f = (FULL) *b++ + *a + (f >> BASEB); - *a++ = (HALF) f; - } - m = n; - while (A[m-1] == 0) - m--; - } - rem->len = m; - rem->v = alloc(m); - memcpy(rem->v, A, m * sizeof(HALF)); - rem->sign = z1.sign ^ adjust; - val = rem->sign ? -1 : 1; - if (a1[len - 1] == 0) - len--; - if (len == 0) { - *quo = _zero_; - } else { - quo->len = len; - quo->v = alloc(len); - memcpy(quo->v, a1, len * sizeof(HALF)); - quo->sign = z1.sign ^ z2.sign; - } - freeh(A); - return val; + if (ziszero(z2)) { + math_error("Division by zero in zdiv"); + not_reached(); + } + m = z1.len; + n = z2.len; + B = z2.v; + s = 0; + if (m < n) { + A = alloc(n + 1); + memcpy(A, z1.v, m * sizeof(HALF)); + for (i = m; i <= n; i++) + A[i] = 0; + a1 = A + n; + len = 1; + goto done; + } + A = alloc(m + 2); + memcpy(A, z1.v, m * sizeof(HALF)); + A[m] = 0; + A[m + 1] = 0; + len = m - n + 1; /* quotient length will be len or len +/- 1 */ + a1 = A + n; /* start of digits for quotient */ + b0 = B; + p = n; + while (!*b0) { /* b0: working start for divisor */ + ++b0; + --p; + } + if (p == 1) { + u = *b0; + if (u == 1) { + for (; m >= n; m--) + A[m] = A[m - 1]; + A[m] = 0; + goto done; + } + f = 0; + a = A + m; + i = len; + while (i--) { + f = f << BASEB | *--a; + a[1] = (HALF)(f / u); + f = f % u; + } + *a = (HALF)f; + m = n; + goto done; + } + f = B[n - 1]; + k = 1; + while (f >>= 1) + k++; /* k: number of bits in top divisor digit */ + j1 = BASEB - k; + j2 = BASEB + j1; + h = j1 ? ((FULL) B[n - 1] << j1 | B[n - 2] >> k) : B[n-1]; + onebit = (bool)((B[n - 2] >> (k - 1)) & 1); + m++; + while (m > n) { + m--; + f = (FULL) A[m] << j2 | (FULL) A[m - 1] << j1; + if (j1) f |= A[m - 2] >> k; + if (s) f = ~f; + x = f / h; + if (x) { + if (onebit && x > TOPHALF + f % h) + x--; + a = A + m - p; + b = b0; + u = 0; + i = p; + if (s) { + while (i--) { + f = (FULL) *a + u + x * *b++; + *a++ = (HALF) f; + u = (HALF) (f >> BASEB); + } + s = *a + u; + A[m] = (HALF) (~x + !s); + } else { + while (i--) { + f = (FULL) *a - u - x * *b++; + *a++ = (HALF) f; + u = -(HALF)(f >> BASEB); + } + s = *a - u; + A[m] = (HALF)(x + s); + } + } + else + A[m] = s; + } +done: while (m > 0 && A[m - 1] == 0) + m--; + if (m == 0 && s == 0) { + *rem = _zero_; + val = 0; + if (a1[len - 1] == 0) + len--; + if (len == 0) { + *quo = _zero_; + } else { + quo->len = len; + quo->v = alloc(len); + memcpy(quo->v, a1, len * sizeof(HALF)); + quo->sign = z1.sign ^ z2.sign; + } + freeh(A); + return val; + } + if (rnd & 8) + adjust = (((*a1 ^ rnd) & 1) ? true : false); + else + adjust = (((rnd & 1) ^ z1.sign ^ z2.sign) ? true : false); + if (rnd & 2) + adjust ^= z1.sign ^ z2.sign; + if (rnd & 4) + adjust ^= z2.sign; + if (rnd & 16) { /* round-off case */ + a = A + n; + b = B + n; + i = n + 1; + f = g = 0; + t = -1; + if (s) { + while (--i > 0) { + g = (FULL) *--a + (*--b >> 1 | f); + f = *b & 1 ? TOPHALF : 0; + if (g != BASE1) + break; + } + if (g == BASE && f == 0) { + while ((--i > 0) && ((*--a | *--b) == 0)); + t = (i > 0); + } else if (g >= BASE) { + t = 1; + } + } else { + while (--i > 0) { + g = (FULL) *--a - (*--b >> 1 | f); + f = *b & 1 ? TOPHALF : 0; + if (g != 0) + break; + } + if (g > 0 && g < BASE) + t = 1; + else if (g == 0 && f == 0) + t = 0; + } + if (t) + adjust = (t > 0); + } + if (adjust) { + i = len; + a = a1; + while (i > 0 && *a == BASE1) { + i--; + *a++ = 0; + } + (*a)++; + if (i == 0) + len++; + } + if (s && adjust) { + i = 0; + while (A[i] == 0) + i++; + A[i] = -A[i]; + while (++i < n) + A[i] = ~A[i]; + m = n; + while (A[m - 1] == 0) + m--; + } + if (!s && adjust) { + a = A; + b = B; + i = n; + u = 0; + while (i--) { + f = (FULL) *b++ - *a - (FULL) u; + *a++ = (HALF) f; + u = -(HALF)(f >> BASEB); + } + m = n; + while (A[m - 1] == 0) + m--; + } + if (s && !adjust) { + a = A; + b = B; + i = n; + f = 0; + while (i--) { + f = (FULL) *b++ + *a + (f >> BASEB); + *a++ = (HALF) f; + } + m = n; + while (A[m-1] == 0) + m--; + } + rem->len = m; + rem->v = alloc(m); + memcpy(rem->v, A, m * sizeof(HALF)); + rem->sign = z1.sign ^ adjust; + val = rem->sign ? -1 : 1; + if (a1[len - 1] == 0) + len--; + if (len == 0) { + *quo = _zero_; + } else { + quo->len = len; + quo->v = alloc(len); + memcpy(quo->v, a1, len * sizeof(HALF)); + quo->sign = z1.sign ^ z2.sign; + } + freeh(A); + return val; } @@ -1032,20 +1032,20 @@ done: while (m > 0 && A[m - 1] == 0) long zquo(ZVALUE z1, ZVALUE z2, ZVALUE *res, long rnd) { - ZVALUE tmp; - long val; + ZVALUE tmp; + long val; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - val = zdiv(z1, z2, res, &tmp, rnd); - if (z2.sign) - val = -val; - zfree(tmp); - return val; + val = zdiv(z1, z2, res, &tmp, rnd); + if (z2.sign) + val = -val; + zfree(tmp); + return val; } @@ -1057,18 +1057,18 @@ zquo(ZVALUE z1, ZVALUE z2, ZVALUE *res, long rnd) long zmod(ZVALUE z1, ZVALUE z2, ZVALUE *res, long rnd) { - ZVALUE tmp; - long val; + ZVALUE tmp; + long val; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - val = zdiv(z1, z2, &tmp, res, rnd); - zfree(tmp); - return val; + val = zdiv(z1, z2, &tmp, res, rnd); + zfree(tmp); + return val; } @@ -1080,127 +1080,127 @@ zmod(ZVALUE z1, ZVALUE z2, ZVALUE *res, long rnd) void zequo(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - LEN i, j, k, len, m, n, o, p; - HALF *a, *a0, *A, *b, *B, u, v, w, x; - FULL f, g; + LEN i, j, k, len, m, n, o, p; + HALF *a, *a0, *A, *b, *B, u, v, w, x; + FULL f, g; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (ziszero(z1)) { - *res = _zero_; - return; - } - if (ziszero(z2)) { - math_error("Division by zero"); - not_reached(); - } - if (zisone(z2)) { - zcopy(z1, res); - return; - } - if (zhighbit(z1) < zhighbit(z2)) { - math_error("Bad call to zequo"); - not_reached(); - } - B = z2.v; - o = 0; - while (!*B) { - ++B; - ++o; - } - m = z1.len - o; - n = z2.len - o; - len = m - n + 1; /* Maximum length of quotient */ - v = *B; - A = alloc(len+1); - memcpy(A, z1.v + o, len * sizeof(HALF)); - A[len] = 0; - if (n == 1) { - if (v > 1) { - a = A + len; - i = len; - f = 0; - while (i--) { - f = f << BASEB | *--a; - *a = (HALF)(f / v); - f %= v; - } - } - } else { - k = 0; - while (!(v & 1)) { - k++; - v >>= 1; - } - j = BASEB - k; - if (n > 1 && k > 0) - v |= B[1] << j; - u = v - 1; - w = x = 1; - while (u) { /* To find w = inverse of v modulo BASE */ - do { - v <<= 1; - x <<= 1; - } - while (!(u & x)); - u += v; - w |= x; - } - a0 = A; - p = len; - while (p > 1) { - if (!*a0) { - while (!*++a0 && p > 1) - p--; - --a0; - } - if (p == 1) - break; - x = k ? w * (*a0 >> k | a0[1] << j) : w * *a0; - g = x; - if (x) { - a = a0; - b = B; - u = 0; - i = n; - if (i > p) - i = p; - while (i--) { - f = (FULL) *a - g * *b++ - (FULL) u; - *a++ = (HALF)f; - u = -(HALF)(f >> BASEB); - } - if (u && p > n) { - i = p - n; - while (u && i--) { - f = (FULL) *a - u; - *a++ = (HALF) f; - u = -(HALF)(f >> BASEB); - } - } - } - *a0++ = x; - p--; - } - if (k == 0) { - *a0 = w * *a0; - } else { - u = (HALF)(w * *a0) >> k; - x = (HALF)(((FULL) z1.v[z1.len - 1] << BASEB - | z1.v[z1.len - 2]) - /((FULL) B[n-1] << BASEB | B[n-2])); - if ((x ^ u) & 1) x--; - *a0 = x; - } - } - if (!A[len - 1]) len--; - res->v = A; - res->len = len; - res->sign = z1.sign != z2.sign; + if (ziszero(z1)) { + *res = _zero_; + return; + } + if (ziszero(z2)) { + math_error("Division by zero"); + not_reached(); + } + if (zisone(z2)) { + zcopy(z1, res); + return; + } + if (zhighbit(z1) < zhighbit(z2)) { + math_error("Bad call to zequo"); + not_reached(); + } + B = z2.v; + o = 0; + while (!*B) { + ++B; + ++o; + } + m = z1.len - o; + n = z2.len - o; + len = m - n + 1; /* Maximum length of quotient */ + v = *B; + A = alloc(len+1); + memcpy(A, z1.v + o, len * sizeof(HALF)); + A[len] = 0; + if (n == 1) { + if (v > 1) { + a = A + len; + i = len; + f = 0; + while (i--) { + f = f << BASEB | *--a; + *a = (HALF)(f / v); + f %= v; + } + } + } else { + k = 0; + while (!(v & 1)) { + k++; + v >>= 1; + } + j = BASEB - k; + if (n > 1 && k > 0) + v |= B[1] << j; + u = v - 1; + w = x = 1; + while (u) { /* To find w = inverse of v modulo BASE */ + do { + v <<= 1; + x <<= 1; + } + while (!(u & x)); + u += v; + w |= x; + } + a0 = A; + p = len; + while (p > 1) { + if (!*a0) { + while (!*++a0 && p > 1) + p--; + --a0; + } + if (p == 1) + break; + x = k ? w * (*a0 >> k | a0[1] << j) : w * *a0; + g = x; + if (x) { + a = a0; + b = B; + u = 0; + i = n; + if (i > p) + i = p; + while (i--) { + f = (FULL) *a - g * *b++ - (FULL) u; + *a++ = (HALF)f; + u = -(HALF)(f >> BASEB); + } + if (u && p > n) { + i = p - n; + while (u && i--) { + f = (FULL) *a - u; + *a++ = (HALF) f; + u = -(HALF)(f >> BASEB); + } + } + } + *a0++ = x; + p--; + } + if (k == 0) { + *a0 = w * *a0; + } else { + u = (HALF)(w * *a0) >> k; + x = (HALF)(((FULL) z1.v[z1.len - 1] << BASEB + | z1.v[z1.len - 2]) + /((FULL) B[n-1] << BASEB | B[n-2])); + if ((x ^ u) & 1) x--; + *a0 = x; + } + } + if (!A[len - 1]) len--; + res->v = A; + res->len = len; + res->sign = z1.sign != z2.sign; } @@ -1213,72 +1213,72 @@ zequo(ZVALUE z1, ZVALUE z2, ZVALUE *res) long zdivi(ZVALUE z, long n, ZVALUE *res) { - HALF *h1, *sd; - FULL val; - HALF divval[2]; - ZVALUE div; - ZVALUE dest; - LEN len; + HALF *h1, *sd; + FULL val; + HALF divval[2]; + ZVALUE div; + ZVALUE dest; + LEN len; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (n == 0) { - math_error("Division by zero"); - not_reached(); - } - if (ziszero(z)) { - *res = _zero_; - return 0; - } - if (n < 0) { - n = -n; - z.sign = !z.sign; - } - if (n == 1) { - zcopy(z, res); - return 0; - } - /* - * If the division is by a large number, then call the normal - * divide routine. - */ - if (n & ~BASE1) { - div.sign = 0; - div.v = divval; - divval[0] = (HALF) n; + if (n == 0) { + math_error("Division by zero"); + not_reached(); + } + if (ziszero(z)) { + *res = _zero_; + return 0; + } + if (n < 0) { + n = -n; + z.sign = !z.sign; + } + if (n == 1) { + zcopy(z, res); + return 0; + } + /* + * If the division is by a large number, then call the normal + * divide routine. + */ + if (n & ~BASE1) { + div.sign = 0; + div.v = divval; + divval[0] = (HALF) n; #if LONG_BITS > BASEB - divval[1] = (HALF)(((FULL) n) >> BASEB); - div.len = 2; + divval[1] = (HALF)(((FULL) n) >> BASEB); + div.len = 2; #else - div.len = 1; + div.len = 1; #endif - zdiv(z, div, res, &dest, 0); - n = ztolong(dest); - zfree(dest); - return n; - } - /* - * Division is by a small number, so we can be quick about it. - */ - len = z.len; - dest.sign = z.sign; - dest.len = len; - dest.v = alloc(len); - h1 = z.v + len; - sd = dest.v + len; - val = 0; - while (len--) { - val = ((val << BASEB) + ((FULL) *--h1)); - *--sd = (HALF)(val / n); - val %= n; - } - zquicktrim(dest); - *res = dest; - return (long)val; + zdiv(z, div, res, &dest, 0); + n = ztolong(dest); + zfree(dest); + return n; + } + /* + * Division is by a small number, so we can be quick about it. + */ + len = z.len; + dest.sign = z.sign; + dest.len = len; + dest.v = alloc(len); + h1 = z.v + len; + sd = dest.v + len; + val = 0; + while (len--) { + val = ((val << BASEB) + ((FULL) *--h1)); + *--sd = (HALF)(val / n); + val %= n; + } + zquicktrim(dest); + *res = dest; + return (long)val; } @@ -1290,55 +1290,55 @@ zdivi(ZVALUE z, long n, ZVALUE *res) long zmodi(ZVALUE z, long n) { - register HALF *h1; - FULL val; - HALF divval[2]; - ZVALUE div; - ZVALUE temp; - long len; + register HALF *h1; + FULL val; + HALF divval[2]; + ZVALUE div; + ZVALUE temp; + long len; - if (n == 0) { - math_error("Division by zero"); - not_reached(); - } - if (n < 0) { - math_error("Non-positive modulus"); - not_reached(); - } - if (ziszero(z) || (n == 1)) - return 0; - if (zisone(z)) - return 1; - /* - * If the modulus is by a large number, then call the normal - * modulo routine. - */ - if (n & ~BASE1) { - div.sign = 0; - div.v = divval; - divval[0] = (HALF) n; + if (n == 0) { + math_error("Division by zero"); + not_reached(); + } + if (n < 0) { + math_error("Non-positive modulus"); + not_reached(); + } + if (ziszero(z) || (n == 1)) + return 0; + if (zisone(z)) + return 1; + /* + * If the modulus is by a large number, then call the normal + * modulo routine. + */ + if (n & ~BASE1) { + div.sign = 0; + div.v = divval; + divval[0] = (HALF) n; #if LONG_BITS > BASEB - divval[1] = (HALF)(((FULL) n) >> BASEB); - div.len = 2; + divval[1] = (HALF)(((FULL) n) >> BASEB); + div.len = 2; #else - div.len = 1; + div.len = 1; #endif - zmod(z, div, &temp, 0); - n = ztolong(temp); - zfree(temp); - return n; - } - /* - * The modulus is by a small number, so we can do this quickly. - */ - len = z.len; - h1 = z.v + len; - val = 0; - while (len-- > 0) - val = ((val << BASEB) + ((FULL) *--h1)) % n; - if (val && z.sign) - val = n - val; - return (long)val; + zmod(z, div, &temp, 0); + n = ztolong(temp); + zfree(temp); + return n; + } + /* + * The modulus is by a small number, so we can do this quickly. + */ + len = z.len; + h1 = z.v + len; + val = 0; + while (len-- > 0) + val = ((val << BASEB) + ((FULL) *--h1)) % n; + if (val && z.sign) + val = n - val; + return (long)val; } @@ -1351,112 +1351,112 @@ zmodi(ZVALUE z, long n) bool zdivides(ZVALUE z1, ZVALUE z2) { - LEN i, j, k, m, n; - HALF u, v, w, x; - HALF *a, *a0, *A, *b, *B, *c, *d; - FULL f; - bool ans; + LEN i, j, k, m, n; + HALF u, v, w, x; + HALF *a, *a0, *A, *b, *B, *c, *d; + FULL f; + bool ans; - if (zisunit(z2) || ziszero(z1)) return true; - if (ziszero(z2)) return false; + if (zisunit(z2) || ziszero(z1)) return true; + if (ziszero(z2)) return false; - m = z1.len; - n = z2.len; - if (m < n) return false; + m = z1.len; + n = z2.len; + if (m < n) return false; - c = z1.v; - d = z2.v; + c = z1.v; + d = z2.v; - while (!*d) { - if (*c++) return false; - d++; - m--; - n--; - } + while (!*d) { + if (*c++) return false; + d++; + m--; + n--; + } - j = 0; - u = *c; - v = *d; - while (!(v & 1)) { /* Counting and checking zero bits */ - if (u & 1) return false; - u >>= 1; - v >>= 1; - j++; - } + j = 0; + u = *c; + v = *d; + while (!(v & 1)) { /* Counting and checking zero bits */ + if (u & 1) return false; + u >>= 1; + v >>= 1; + j++; + } - if (n == 1 && v == 1) return true; - if (!*c) { /* Removing any further zeros */ - while(!*++c) - m--; - c--; - } + if (n == 1 && v == 1) return true; + if (!*c) { /* Removing any further zeros */ + while(!*++c) + m--; + c--; + } - if (m < n) return false; + if (m < n) return false; - if (j) { - B = alloc((LEN)n); /* Array for shifted z2 */ - d += n; - b = B + n; - i = n; - f = 0; - while(i--) { - f = f << BASEB | *--d; - *--b = (HALF)(f >> j); - } - if (!B[n - 1]) n--; - } - else B = d; - u = *B; - v = x = 1; - w = 0; - while (x) { /* Finding minv(*B, BASE) */ - if (v & x) { - v -= x * u; - w |= x; - } - x <<= 1; - } + if (j) { + B = alloc((LEN)n); /* Array for shifted z2 */ + d += n; + b = B + n; + i = n; + f = 0; + while(i--) { + f = f << BASEB | *--d; + *--b = (HALF)(f >> j); + } + if (!B[n - 1]) n--; + } + else B = d; + u = *B; + v = x = 1; + w = 0; + while (x) { /* Finding minv(*B, BASE) */ + if (v & x) { + v -= x * u; + w |= x; + } + x <<= 1; + } - A = alloc((LEN)(m + 2)); /* Main working array */ - memcpy(A, c, m * sizeof(HALF)); - A[m + 1] = 1; - A[m] = 0; + A = alloc((LEN)(m + 2)); /* Main working array */ + memcpy(A, c, m * sizeof(HALF)); + A[m + 1] = 1; + A[m] = 0; - k = m - n + 1; /* Length of presumed quotient */ + k = m - n + 1; /* Length of presumed quotient */ - a0 = A; + a0 = A; - while (k--) { - if (*a0) { - x = w * *a0; - a = a0; - b = B; - i = n; - u = 0; - while (i--) { - f = (FULL) *a - (FULL) x * *b++ - u; - *a++ = (HALF)f; - u = -(HALF)(f >> BASEB); - } - f = (FULL) *a - u; - *a++ = (HALF)f; - u = -(HALF)(f >> BASEB); - if (u) { - while (*a == 0) *a++ = BASE1; - (*a)--; - } - } - a0++; - } - ans = false; - if (A[m + 1]) { - a = A + m; - while (--n && !*--a); - if (!n) ans = true; - } - freeh(A); - if (j) freeh(B); - return ans; + while (k--) { + if (*a0) { + x = w * *a0; + a = a0; + b = B; + i = n; + u = 0; + while (i--) { + f = (FULL) *a - (FULL) x * *b++ - u; + *a++ = (HALF)f; + u = -(HALF)(f >> BASEB); + } + f = (FULL) *a - u; + *a++ = (HALF)f; + u = -(HALF)(f >> BASEB); + if (u) { + while (*a == 0) *a++ = BASE1; + (*a)--; + } + } + a0++; + } + ans = false; + if (A[m + 1]) { + a = A + m; + while (--n && !*--a); + if (!n) ans = true; + } + freeh(A); + if (j) freeh(B); + return ans; } @@ -1466,33 +1466,33 @@ zdivides(ZVALUE z1, ZVALUE z2) void zor(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - register HALF *sp, *dp; - long len; - ZVALUE bz, lz, dest; + register HALF *sp, *dp; + long len; + ZVALUE bz, lz, dest; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (z1.len >= z2.len) { - bz = z1; - lz = z2; - } else { - bz = z2; - lz = z1; - } - dest.len = bz.len; - dest.v = alloc(dest.len); - dest.sign = 0; - zcopyval(bz, dest); - len = lz.len; - sp = lz.v; - dp = dest.v; - while (len--) - *dp++ |= *sp++; - *res = dest; + if (z1.len >= z2.len) { + bz = z1; + lz = z2; + } else { + bz = z2; + lz = z1; + } + dest.len = bz.len; + dest.v = alloc(dest.len); + dest.sign = 0; + zcopyval(bz, dest); + len = lz.len; + sp = lz.v; + dp = dest.v; + while (len--) + *dp++ |= *sp++; + *res = dest; } @@ -1502,33 +1502,33 @@ zor(ZVALUE z1, ZVALUE z2, ZVALUE *res) void zand(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - HALF *h1, *h2, *hd; - LEN len; - ZVALUE dest; + HALF *h1, *h2, *hd; + LEN len; + ZVALUE dest; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - len = ((z1.len <= z2.len) ? z1.len : z2.len); - h1 = &z1.v[len-1]; - h2 = &z2.v[len-1]; - while ((len > 1) && ((*h1 & *h2) == 0)) { - h1--; - h2--; - len--; - } - dest.len = len; - dest.v = alloc(len); - dest.sign = 0; - h1 = z1.v; - h2 = z2.v; - hd = dest.v; - while (len--) - *hd++ = (*h1++ & *h2++); - *res = dest; + len = ((z1.len <= z2.len) ? z1.len : z2.len); + h1 = &z1.v[len-1]; + h2 = &z2.v[len-1]; + while ((len > 1) && ((*h1 & *h2) == 0)) { + h1--; + h2--; + len--; + } + dest.len = len; + dest.v = alloc(len); + dest.sign = 0; + h1 = z1.v; + h2 = z2.v; + hd = dest.v; + while (len--) + *hd++ = (*h1++ & *h2++); + *res = dest; } @@ -1538,40 +1538,40 @@ zand(ZVALUE z1, ZVALUE z2, ZVALUE *res) void zxor(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - HALF *dp, *h1, *h2; - LEN len, j, k; - ZVALUE dest; + HALF *dp, *h1, *h2; + LEN len, j, k; + ZVALUE dest; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - h1 = z1.v; - h2 = z2.v; - len = z1.len; - j = z2.len; - if (z1.len < z2.len) { - len = z2.len; - j = z1.len; - h1 = z2.v; - h2 = z1.v; - } else if (z1.len == z2.len) { - while (len > 1 && z1.v[len-1] == z2.v[len-1]) - len--; - j = len; - } - k = len - j; - dest.len = len; - dest.v = alloc(len); - dest.sign = 0; - dp = dest.v; - while (j-- > 0) - *dp++ = *h1++ ^ *h2++; - while (k-- > 0) - *dp++ = *h1++; - *res = dest; + h1 = z1.v; + h2 = z2.v; + len = z1.len; + j = z2.len; + if (z1.len < z2.len) { + len = z2.len; + j = z1.len; + h1 = z2.v; + h2 = z1.v; + } else if (z1.len == z2.len) { + while (len > 1 && z1.v[len-1] == z2.v[len-1]) + len--; + j = len; + } + k = len - j; + dest.len = len; + dest.v = alloc(len); + dest.sign = 0; + dp = dest.v; + while (j-- > 0) + *dp++ = *h1++ ^ *h2++; + while (k-- > 0) + *dp++ = *h1++; + *res = dest; } @@ -1581,37 +1581,37 @@ zxor(ZVALUE z1, ZVALUE z2, ZVALUE *res) void zandnot(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - HALF *dp, *h1, *h2; - LEN len, j, k; - ZVALUE dest; + HALF *dp, *h1, *h2; + LEN len, j, k; + ZVALUE dest; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - len = z1.len; - if (z2.len >= len) { - while (len > 1 && (z1.v[len-1] & ~z2.v[len-1]) == 0) - len--; - j = len; - k = 0; - } else { - j = z2.len; - k = len - z2.len; - } - dest.len = len; - dest.v = alloc(len); - dest.sign = 0; - dp = dest.v; - h1 = z1.v; - h2 = z2.v; - while (j-- > 0) - *dp++ = *h1++ & ~*h2++; - while (k-- > 0) - *dp++ = *h1++; - *res = dest; + len = z1.len; + if (z2.len >= len) { + while (len > 1 && (z1.v[len-1] & ~z2.v[len-1]) == 0) + len--; + j = len; + k = 0; + } else { + j = z2.len; + k = len - z2.len; + } + dest.len = len; + dest.v = alloc(len); + dest.sign = 0; + dp = dest.v; + h1 = z1.v; + h2 = z2.v; + while (j-- > 0) + *dp++ = *h1++ & ~*h2++; + while (k-- > 0) + *dp++ = *h1++; + *res = dest; } @@ -1623,81 +1623,81 @@ zandnot(ZVALUE z1, ZVALUE z2, ZVALUE *res) void zshift(ZVALUE z, long n, ZVALUE *res) { - ZVALUE ans; - LEN hc; /* number of halfwords shift is by */ + ZVALUE ans; + LEN hc; /* number of halfwords shift is by */ - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (ziszero(z)) { - *res = _zero_; - return; - } - if (n == 0) { - zcopy(z, res); - return; - } - /* - * If shift value is negative, then shift right. - * Check for large shifts, and handle word-sized shifts quickly. - */ - if (n < 0) { - n = -n; - if ((n < 0) || (n >= (z.len * BASEB))) { - *res = _zero_; - return; - } - hc = (LEN)(n / BASEB); - n %= BASEB; - z.v += hc; - z.len -= hc; - ans.len = z.len; - ans.v = alloc(ans.len); - ans.sign = z.sign; - zcopyval(z, ans); - if (n > 0) { - zshiftr(ans, n); - ztrim(&ans); - } - if (ziszero(ans)) { - zfree(ans); - ans = _zero_; - } - *res = ans; - return; - } - /* - * Shift value is positive, so shift leftwards. - * Check specially for a shift of the value 1, since this is common. - * Also handle word-sized shifts quickly. - */ - if (zisunit(z)) { - zbitvalue(n, res); - res->sign = z.sign; - return; - } - hc = (LEN)(n / BASEB); - n %= BASEB; - ans.len = z.len + hc + 1; - ans.v = alloc(ans.len); - ans.sign = z.sign; - if (hc > 0) - memset((char *) ans.v, 0, hc * sizeof(HALF)); - memcpy((char *) (ans.v + hc), - (char *) z.v, z.len * sizeof(HALF)); - ans.v[ans.len - 1] = 0; - if (n > 0) { - ans.v += hc; - ans.len -= hc; - zshiftl(ans, n); - ans.v -= hc; - ans.len += hc; - } - ztrim(&ans); - *res = ans; + if (ziszero(z)) { + *res = _zero_; + return; + } + if (n == 0) { + zcopy(z, res); + return; + } + /* + * If shift value is negative, then shift right. + * Check for large shifts, and handle word-sized shifts quickly. + */ + if (n < 0) { + n = -n; + if ((n < 0) || (n >= (z.len * BASEB))) { + *res = _zero_; + return; + } + hc = (LEN)(n / BASEB); + n %= BASEB; + z.v += hc; + z.len -= hc; + ans.len = z.len; + ans.v = alloc(ans.len); + ans.sign = z.sign; + zcopyval(z, ans); + if (n > 0) { + zshiftr(ans, n); + ztrim(&ans); + } + if (ziszero(ans)) { + zfree(ans); + ans = _zero_; + } + *res = ans; + return; + } + /* + * Shift value is positive, so shift leftwards. + * Check specially for a shift of the value 1, since this is common. + * Also handle word-sized shifts quickly. + */ + if (zisunit(z)) { + zbitvalue(n, res); + res->sign = z.sign; + return; + } + hc = (LEN)(n / BASEB); + n %= BASEB; + ans.len = z.len + hc + 1; + ans.v = alloc(ans.len); + ans.sign = z.sign; + if (hc > 0) + memset((char *) ans.v, 0, hc * sizeof(HALF)); + memcpy((char *) (ans.v + hc), + (char *) z.v, z.len * sizeof(HALF)); + ans.v[ans.len - 1] = 0; + if (n > 0) { + ans.v += hc; + ans.len -= hc; + zshiftl(ans, n); + ans.v -= hc; + ans.len += hc; + } + ztrim(&ans); + *res = ans; } @@ -1709,22 +1709,22 @@ zshift(ZVALUE z, long n, ZVALUE *res) long zlowbit(ZVALUE z) { - register HALF *zp; - long n; - HALF dataval; - HALF *bitval; + register HALF *zp; + long n; + HALF dataval; + HALF *bitval; - n = 0; - for (zp = z.v; *zp == 0; zp++) - if (++n >= z.len) - return 0; - dataval = *zp; - bitval = bitmask; - /* ignore Saber-C warning #530 about empty while statement */ - /* OK to ignore in proc zlowbit */ - while ((*(bitval++) & dataval) == 0) { - } - return (n*BASEB)+(bitval-bitmask-1); + n = 0; + for (zp = z.v; *zp == 0; zp++) + if (++n >= z.len) + return 0; + dataval = *zp; + bitval = bitmask; + /* ignore Saber-C warning #530 about empty while statement */ + /* OK to ignore in proc zlowbit */ + while ((*(bitval++) & dataval) == 0) { + } + return (n*BASEB)+(bitval-bitmask-1); } @@ -1736,21 +1736,21 @@ zlowbit(ZVALUE z) LEN zhighbit(ZVALUE z) { - HALF dataval; - HALF *bitval; + HALF dataval; + HALF *bitval; - dataval = z.v[z.len-1]; - if (dataval == 0) { - return 0; - } - bitval = bitmask+BASEB; - if (dataval) { - /* ignore Saber-C warning #530 about empty while statement */ - /* OK to ignore in proc zhighbit */ - while ((*(--bitval) & dataval) == 0) { - } - } - return (z.len*BASEB)+(LEN)(bitval-bitmask-BASEB); + dataval = z.v[z.len-1]; + if (dataval == 0) { + return 0; + } + bitval = bitmask+BASEB; + if (dataval) { + /* ignore Saber-C warning #530 about empty while statement */ + /* OK to ignore in proc zhighbit */ + while ((*(--bitval) & dataval) == 0) { + } + } + return (z.len*BASEB)+(LEN)(bitval-bitmask-BASEB); } @@ -1761,9 +1761,9 @@ zhighbit(ZVALUE z) bool zisset(ZVALUE z, long n) { - if ((n < 0) || ((n / BASEB) >= z.len)) - return false; - return ((z.v[n / BASEB] & (((HALF) 1) << (n % BASEB))) != 0); + if ((n < 0) || ((n / BASEB) >= z.len)) + return false; + return ((z.v[n / BASEB] & (((HALF) 1) << (n % BASEB))) != 0); } @@ -1774,23 +1774,23 @@ zisset(ZVALUE z, long n) bool zisonebit(ZVALUE z) { - register HALF *hp; - register LEN len; + register HALF *hp; + register LEN len; - if (ziszero(z) || zisneg(z)) - return false; - hp = z.v; - len = z.len; - while (len > 4) { - len -= 4; - if (*hp++ || *hp++ || *hp++ || *hp++) - return false; - } - while (--len > 0) { - if (*hp++) - return false; - } - return ((*hp & -*hp) == *hp); /* NEEDS 2'S COMPLEMENT */ + if (ziszero(z) || zisneg(z)) + return false; + hp = z.v; + len = z.len; + while (len > 4) { + len -= 4; + if (*hp++ || *hp++ || *hp++ || *hp++) + return false; + } + while (--len > 0) { + if (*hp++) + return false; + } + return ((*hp & -*hp) == *hp); /* NEEDS 2'S COMPLEMENT */ } @@ -1802,26 +1802,26 @@ zisonebit(ZVALUE z) bool zisallbits(ZVALUE z) { - register HALF *hp; - register LEN len; - HALF digit; + register HALF *hp; + register LEN len; + HALF digit; - if (ziszero(z) || zisneg(z)) - return false; - hp = z.v; - len = z.len; - while (len > 4) { - len -= 4; - if ((*hp++ != BASE1) || (*hp++ != BASE1) || - (*hp++ != BASE1) || (*hp++ != BASE1)) - return false; - } - while (--len > 0) { - if (*hp++ != BASE1) - return false; - } - digit = (HALF)(*hp + 1); - return ((digit & -digit) == digit); /* NEEDS 2'S COMPLEMENT */ + if (ziszero(z) || zisneg(z)) + return false; + hp = z.v; + len = z.len; + while (len > 4) { + len -= 4; + if ((*hp++ != BASE1) || (*hp++ != BASE1) || + (*hp++ != BASE1) || (*hp++ != BASE1)) + return false; + } + while (--len > 0) { + if (*hp++ != BASE1) + return false; + } + digit = (HALF)(*hp + 1); + return ((digit & -digit) == digit); /* NEEDS 2'S COMPLEMENT */ } @@ -1833,21 +1833,21 @@ zisallbits(ZVALUE z) void zbitvalue(long n, ZVALUE *res) { - ZVALUE z; + ZVALUE z; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (n < 0) n = 0; - z.sign = 0; - z.len = (LEN)((n / BASEB) + 1); - z.v = alloc(z.len); - zclearval(z); - z.v[z.len-1] = (((HALF) 1) << (n % BASEB)); - *res = z; + if (n < 0) n = 0; + z.sign = 0; + z.len = (LEN)((n / BASEB) + 1); + z.v = alloc(z.len); + zclearval(z); + z.v[z.len-1] = (((HALF) 1) << (n % BASEB)); + *res = z; } @@ -1858,19 +1858,19 @@ zbitvalue(long n, ZVALUE *res) FLAG ztest(ZVALUE z) { - register int sign; - register HALF *h; - register long len; + register int sign; + register HALF *h; + register long len; - sign = 1; - if (z.sign) - sign = -sign; - h = z.v; - len = z.len; - while (len--) - if (*h++) - return sign; - return 0; + sign = 1; + if (z.sign) + sign = -sign; + h = z.v; + len = z.len; + while (len--) + if (*h++) + return sign; + return 0; } @@ -1881,31 +1881,31 @@ ztest(ZVALUE z) FLAG zrel(ZVALUE z1, ZVALUE z2) { - HALF *h1, *h2; - LEN len; - int sign; + HALF *h1, *h2; + LEN len; + int sign; - sign = 1; - if (z1.sign < z2.sign) - return 1; - if (z2.sign < z1.sign) - return -1; - if (z2.sign) - sign = -1; - if (z1.len != z2.len) - return (z1.len > z2.len) ? sign : -sign; - len = z1.len; - h1 = z1.v + len; - h2 = z2.v + len; + sign = 1; + if (z1.sign < z2.sign) + return 1; + if (z2.sign < z1.sign) + return -1; + if (z2.sign) + sign = -1; + if (z1.len != z2.len) + return (z1.len > z2.len) ? sign : -sign; + len = z1.len; + h1 = z1.v + len; + h2 = z2.v + len; - while (len > 0) { - if (*--h1 != *--h2) - break; - len--; - } - if (len > 0) - return (*h1 > *h2) ? sign : -sign; - return 0; + while (len > 0) { + if (*--h1 != *--h2) + break; + len--; + } + if (len > 0) + return (*h1 > *h2) ? sign : -sign; + return 0; } @@ -1917,23 +1917,23 @@ zrel(ZVALUE z1, ZVALUE z2) FLAG zabsrel(ZVALUE z1, ZVALUE z2) { - HALF *h1, *h2; - LEN len; + HALF *h1, *h2; + LEN len; - if (z1.len != z2.len) - return (z1.len > z2.len) ? 1 : -1; + if (z1.len != z2.len) + return (z1.len > z2.len) ? 1 : -1; - len = z1.len; - h1 = z1.v + len; - h2 = z2.v + len; - while (len > 0) { - if (*--h1 != *--h2) - break; - len--; - } - if (len > 0) - return (*h1 > *h2) ? 1 : -1; - return 0; + len = z1.len; + h1 = z1.v + len; + h2 = z2.v + len; + while (len > 0) { + if (*--h1 != *--h2) + break; + len--; + } + if (len > 0) + return (*h1 > *h2) ? 1 : -1; + return 0; } @@ -1944,19 +1944,19 @@ zabsrel(ZVALUE z1, ZVALUE z2) bool zcmp(ZVALUE z1, ZVALUE z2) { - register HALF *h1, *h2; - register long len; + register HALF *h1, *h2; + register long len; - if ((z1.sign != z2.sign) || (z1.len != z2.len) || (*z1.v != *z2.v)) - return true; - len = z1.len; - h1 = z1.v; - h2 = z2.v; - while (--len > 0) { - if (*++h1 != *++h2) - return true; - } - return false; + if ((z1.sign != z2.sign) || (z1.len != z2.len) || (*z1.v != *z2.v)) + return true; + len = z1.len; + h1 = z1.v; + h2 = z2.v; + while (--len > 0) { + if (*++h1 != *++h2) + return true; + } + return false; } @@ -1966,14 +1966,14 @@ zcmp(ZVALUE z1, ZVALUE z2) FULL uugcd(FULL f1, FULL f2) { - FULL temp; + FULL temp; - while (f1) { - temp = f2 % f1; - f2 = f1; - f1 = temp; - } - return (FULL) f2; + while (f1) { + temp = f2 % f1; + f2 = f1; + f1 = temp; + } + return (FULL) f2; } @@ -1983,38 +1983,38 @@ uugcd(FULL f1, FULL f2) long iigcd(long i1, long i2) { - FULL f1, f2, temp; + FULL f1, f2, temp; - f1 = (FULL) ((i1 >= 0) ? i1 : -i1); - f2 = (FULL) ((i2 >= 0) ? i2 : -i2); - while (f1) { - temp = f2 % f1; - f2 = f1; - f1 = temp; - } - return (long) f2; + f1 = (FULL) ((i1 >= 0) ? i1 : -i1); + f2 = (FULL) ((i2 >= 0) ? i2 : -i2); + while (f1) { + temp = f2 % f1; + f2 = f1; + f1 = temp; + } + return (long) f2; } void ztrim(ZVALUE *z) { - HALF *h; - LEN len; + HALF *h; + LEN len; - /* firewall */ - if (z == NULL) { - math_error("%s: z NULL", __func__); - not_reached(); - } + /* firewall */ + if (z == NULL) { + math_error("%s: z NULL", __func__); + not_reached(); + } - h = z->v + z->len - 1; - len = z->len; - while (*h == 0 && len > 1) { - --h; - --len; - } - z->len = len; + h = z->v + z->len - 1; + len = z->len; + while (*h == 0 && len > 1) { + --h; + --len; + } + z->len = len; } @@ -2022,39 +2022,39 @@ ztrim(ZVALUE *z) * Utility routine to shift right. * * NOTE: The ZVALUE length is not adjusted instead, the value is - * zero padded from the left. One may need to call ztrim() - * or use zshift() instead. + * zero padded from the left. One may need to call ztrim() + * or use zshift() instead. */ void zshiftr(ZVALUE z, long n) { - register HALF *h, *lim; - FULL mask, maskt; - long len; + register HALF *h, *lim; + FULL mask, maskt; + long len; - if (n >= BASEB) { - len = n / BASEB; - h = z.v; - lim = z.v + z.len - len; - while (h < lim) { - h[0] = h[len]; - ++h; - } - n -= BASEB * len; - lim = z.v + z.len; - while (h < lim) - *h++ = 0; - } - if (n) { - len = z.len; - h = z.v + len; - mask = 0; - while (len--) { - maskt = (((FULL) *--h) << (BASEB - n)) & BASE1; - *h = ((*h >> n) | (HALF)mask); - mask = maskt; - } - } + if (n >= BASEB) { + len = n / BASEB; + h = z.v; + lim = z.v + z.len - len; + while (h < lim) { + h[0] = h[len]; + ++h; + } + n -= BASEB * len; + lim = z.v + z.len; + while (h < lim) + *h++ = 0; + } + if (n) { + len = z.len; + h = z.v + len; + mask = 0; + while (len--) { + maskt = (((FULL) *--h) << (BASEB - n)) & BASE1; + *h = ((*h >> n) | (HALF)mask); + mask = maskt; + } + } } @@ -2062,44 +2062,44 @@ zshiftr(ZVALUE z, long n) * Utility routine to shift left. * * NOTE: The ZVALUE length is not adjusted. The bits in the upper - * HALF are simply tossed. You may want to use zshift() instead. + * HALF are simply tossed. You may want to use zshift() instead. */ void zshiftl(ZVALUE z, long n) { - register HALF *h; - FULL mask, i; - long len; + register HALF *h; + FULL mask, i; + long len; - if (n >= BASEB) { - len = n / BASEB; - h = z.v + z.len - 1; - while (!*h) - --h; - while (h >= z.v) { - h[len] = h[0]; - --h; - } - n -= BASEB * len; - while (len) - h[len--] = 0; - } - if (n > 0) { - len = z.len; - h = z.v; - mask = 0; - while (len--) { - i = (((FULL) *h) << n) | mask; - if (i > BASE1) { - mask = i >> BASEB; - i &= BASE1; - } else { - mask = 0; - } - *h = (HALF) i; - ++h; - } - } + if (n >= BASEB) { + len = n / BASEB; + h = z.v + z.len - 1; + while (!*h) + --h; + while (h >= z.v) { + h[len] = h[0]; + --h; + } + n -= BASEB * len; + while (len) + h[len--] = 0; + } + if (n > 0) { + len = z.len; + h = z.v; + mask = 0; + while (len--) { + i = (((FULL) *h) << n) | mask; + if (i > BASE1) { + mask = i >> BASEB; + i &= BASE1; + } else { + mask = 0; + } + *h = (HALF) i; + ++h; + } + } } @@ -2111,55 +2111,55 @@ zshiftl(ZVALUE z, long n) long zpopcnt(ZVALUE z, int bitval) { - long cnt = 0; /* number of times found */ - HALF h; /* HALF to count */ - int i; + long cnt = 0; /* number of times found */ + HALF h; /* HALF to count */ + int i; - /* - * count 1's - */ - if (bitval) { + /* + * count 1's + */ + if (bitval) { - /* - * count each HALF - */ - for (i=0; i < z.len; ++i) { - /* count each octet */ - for (h = z.v[i]; h; h >>= 8) { - cnt += (long)popcnt[h & 0xff]; - } - } + /* + * count each HALF + */ + for (i=0; i < z.len; ++i) { + /* count each octet */ + for (h = z.v[i]; h; h >>= 8) { + cnt += (long)popcnt[h & 0xff]; + } + } - /* - * count 0's - */ - } else { + /* + * count 0's + */ + } else { - /* - * count each HALF up until the last - */ - for (i=0; i < z.len-1; ++i) { + /* + * count each HALF up until the last + */ + for (i=0; i < z.len-1; ++i) { - /* count each octet */ - cnt += BASEB; - for (h = z.v[i]; h; h >>= 8) { - cnt -= (long)popcnt[h & 0xff]; - } - } + /* count each octet */ + cnt += BASEB; + for (h = z.v[i]; h; h >>= 8) { + cnt -= (long)popcnt[h & 0xff]; + } + } - /* - * count the last octet up until the highest 1 bit - */ - for (h = z.v[z.len-1]; h; h>>=1) { - /* count each 0 bit */ - if ((h & 0x1) == 0) { - ++cnt; - } - } - } + /* + * count the last octet up until the highest 1 bit + */ + for (h = z.v[z.len-1]; h; h>>=1) { + /* count each 0 bit */ + if ((h & 0x1) == 0) { + ++cnt; + } + } + } - /* - * return count - */ - return cnt; + /* + * return count + */ + return cnt; } diff --git a/zmath.h b/zmath.h index 02a30b4..7edc37c 100644 --- a/zmath.h +++ b/zmath.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1993/07/30 19:42:48 - * File existed as early as: 1993 + * Under source code control: 1993/07/30 19:42:48 + * File existed as early as: 1993 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -34,7 +34,7 @@ #define INCLUDE_ZMATH_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "version.h" # include "bool.h" # include "decl.h" @@ -67,59 +67,59 @@ /* * NOTE: FULL must be twice the storage size of a HALF - * HALF must be BASEB bits long + * HALF must be BASEB bits long */ #if defined(HAVE_B64) -#define BASEB 32 /* use base 2^32 */ -typedef USB32 HALF; /* unit of number storage */ -typedef SB32 SHALF; /* signed HALF */ -typedef USB64 FULL; /* double unit of number storage */ -typedef SB64 SFULL; /* signed FULL */ +#define BASEB 32 /* use base 2^32 */ +typedef USB32 HALF; /* unit of number storage */ +typedef SB32 SHALF; /* signed HALF */ +typedef USB64 FULL; /* double unit of number storage */ +typedef SB64 SFULL; /* signed FULL */ -#define SWAP_HALF_IN_B64(dest, src) SWAP_B32_IN_B64(dest, src) -#define SWAP_HALF_IN_B32(dest, src) (*((HALF *)(dest)) = *((HALF *)(src))) -#define SWAP_HALF_IN_FULL(dest, src) SWAP_B32_IN_B64(dest, src) -#define SWAP_HALF_IN_HASH(dest, src) SWAP_B16_IN_HASH(dest, src) -#define SWAP_HALF_IN_FLAG(dest, src) SWAP_B16_IN_FLAG(dest, src) -#define SWAP_HALF_IN_bool(dest, src) SWAP_B16_IN_bool(dest, src) -#define SWAP_HALF_IN_LEN(dest, src) SWAP_B16_IN_LEN(dest, src) -#define SWAP_B32_IN_FULL(dest, src) SWAP_B32_IN_B64(dest, src) -#define SWAP_B16_IN_FULL(dest, src) SWAP_B16_IN_B64(dest, src) -#define SWAP_B16_IN_HALF(dest, src) SWAP_B16_IN_B32(dest, src) -#define SWAP_B8_IN_FULL(dest, src) SWAP_B8_IN_B64(dest, src) -#define SWAP_B8_IN_HALF(dest, src) SWAP_B8_IN_B32(dest, src) +#define SWAP_HALF_IN_B64(dest, src) SWAP_B32_IN_B64(dest, src) +#define SWAP_HALF_IN_B32(dest, src) (*((HALF *)(dest)) = *((HALF *)(src))) +#define SWAP_HALF_IN_FULL(dest, src) SWAP_B32_IN_B64(dest, src) +#define SWAP_HALF_IN_HASH(dest, src) SWAP_B16_IN_HASH(dest, src) +#define SWAP_HALF_IN_FLAG(dest, src) SWAP_B16_IN_FLAG(dest, src) +#define SWAP_HALF_IN_bool(dest, src) SWAP_B16_IN_bool(dest, src) +#define SWAP_HALF_IN_LEN(dest, src) SWAP_B16_IN_LEN(dest, src) +#define SWAP_B32_IN_FULL(dest, src) SWAP_B32_IN_B64(dest, src) +#define SWAP_B16_IN_FULL(dest, src) SWAP_B16_IN_B64(dest, src) +#define SWAP_B16_IN_HALF(dest, src) SWAP_B16_IN_B32(dest, src) +#define SWAP_B8_IN_FULL(dest, src) SWAP_B8_IN_B64(dest, src) +#define SWAP_B8_IN_HALF(dest, src) SWAP_B8_IN_B32(dest, src) #else -#define BASEB 16 /* use base 2^16 */ -typedef USB16 HALF; /* unit of number storage */ -typedef SB16 SHALF; /* signed HALF */ -typedef USB32 FULL; /* double unit of number storage */ -typedef SB32 SFULL; /* signed FULL */ +#define BASEB 16 /* use base 2^16 */ +typedef USB16 HALF; /* unit of number storage */ +typedef SB16 SHALF; /* signed HALF */ +typedef USB32 FULL; /* double unit of number storage */ +typedef SB32 SFULL; /* signed FULL */ -#define SWAP_HALF_IN_B64(dest, src) SWAP_B16_IN_B64(dest, src) -#define SWAP_HALF_IN_B32(dest, src) SWAP_B16_IN_B32(dest, src) -#define SWAP_HALF_IN_FULL(dest, src) SWAP_B16_IN_B32(dest, src) -#define SWAP_HALF_IN_HASH(dest, src) SWAP_B16_IN_HASH(dest, src) -#define SWAP_HALF_IN_FLAG(dest, src) SWAP_B16_IN_FLAG(dest, src) -#define SWAP_HALF_IN_bool(dest, src) SWAP_B16_IN_bool(dest, src) -#define SWAP_HALF_IN_LEN(dest, src) SWAP_B16_IN_LEN(dest, src) -#define SWAP_B32_IN_FULL(dest, src) (*((FULL *)(dest)) = *((FULL *)(src))) -#define SWAP_B16_IN_FULL(dest, src) SWAP_B16_IN_B32(dest, src) -#define SWAP_B16_IN_HALF(dest, src) (*((HALF *)(dest)) = *((HALF *)(src))) -#define SWAP_B8_IN_FULL(dest, src) SWAP_B8_IN_B32(dest, src) -#define SWAP_B8_IN_HALF(dest, src) SWAP_B8_IN_B16(dest, src) +#define SWAP_HALF_IN_B64(dest, src) SWAP_B16_IN_B64(dest, src) +#define SWAP_HALF_IN_B32(dest, src) SWAP_B16_IN_B32(dest, src) +#define SWAP_HALF_IN_FULL(dest, src) SWAP_B16_IN_B32(dest, src) +#define SWAP_HALF_IN_HASH(dest, src) SWAP_B16_IN_HASH(dest, src) +#define SWAP_HALF_IN_FLAG(dest, src) SWAP_B16_IN_FLAG(dest, src) +#define SWAP_HALF_IN_bool(dest, src) SWAP_B16_IN_bool(dest, src) +#define SWAP_HALF_IN_LEN(dest, src) SWAP_B16_IN_LEN(dest, src) +#define SWAP_B32_IN_FULL(dest, src) (*((FULL *)(dest)) = *((FULL *)(src))) +#define SWAP_B16_IN_FULL(dest, src) SWAP_B16_IN_B32(dest, src) +#define SWAP_B16_IN_HALF(dest, src) (*((HALF *)(dest)) = *((HALF *)(src))) +#define SWAP_B8_IN_FULL(dest, src) SWAP_B8_IN_B32(dest, src) +#define SWAP_B8_IN_HALF(dest, src) SWAP_B8_IN_B16(dest, src) #endif -#define BASE ((FULL)1< /\../\ + * chongo /\../\ * * Note that the \'s above are not back-slashing escape characters. * They are literal ASCII backslash 0x5c characters. @@ -227,7 +227,7 @@ typedef uintptr_t LEN; /* unit of length storage */ * The largest power of 10 we will compute for our decimal conversion * internal constants is: 10^(2^TEN_MAX). */ -#define TEN_MAX 31 /* 10^2^31 requires about 1.66 * 2^29 bytes */ +#define TEN_MAX 31 /* 10^2^31 requires about 1.66 * 2^29 bytes */ /* @@ -238,9 +238,9 @@ typedef uintptr_t LEN; /* unit of length storage */ * will need 4 huge integers, plus other data, code and stack space. */ #if MAJOR_VER < 3 -#define MAXDATA (0x80000000>>3) /* calc v2 compatible supported address space */ +#define MAXDATA (0x80000000>>3) /* calc v2 compatible supported address space */ #else /* MAJOR_VER < 3 */ -#define MAXDATA ((LEN) 1<<(UINTPTR_WIDTH-4)) /* 1/16 of address space */ +#define MAXDATA ((LEN) 1<<(UINTPTR_WIDTH-4)) /* 1/16 of address space */ #endif /* MAJOR_VER < 3 */ /* @@ -249,41 +249,41 @@ typedef uintptr_t LEN; /* unit of length storage */ * We limit MAXLEN based on 1 less than the number of HALFs that * will fit into MAXDATA bytes. */ -#define MAXLEN ((LEN) ((MAXDATA / HALF_LEN) - 1)) /* longest value allowed */ +#define MAXLEN ((LEN) ((MAXDATA / HALF_LEN) - 1)) /* longest value allowed */ -#define MAXREDC 256 /* number of entries in REDC cache */ -#define SQ_ALG2 28 /* size for alternative squaring */ -#define MUL_ALG2 28 /* size for alternative multiply */ -#define POW_ALG2 20 /* size for using REDC for powers */ +#define MAXREDC 256 /* number of entries in REDC cache */ +#define SQ_ALG2 28 /* size for alternative squaring */ +#define MUL_ALG2 28 /* size for alternative multiply */ +#define POW_ALG2 20 /* size for using REDC for powers */ /* old REDC_ALG2 was 5/4 of POW_ALG2, so we will keep the same ratio */ -#define REDC_ALG2 25 /* size for using alternative REDC */ +#define REDC_ALG2 25 /* size for using alternative REDC */ typedef union { - FULL ivalue; - struct { - HALF Svalue1; - HALF Svalue2; - } sis; + FULL ivalue; + struct { + HALF Svalue1; + HALF Svalue2; + } sis; } SIUNION; #if !defined(LITTLE_ENDIAN) -#define LITTLE_ENDIAN 1234 /* Least Significant Byte first */ +#define LITTLE_ENDIAN 1234 /* Least Significant Byte first */ #endif #if !defined(BIG_ENDIAN) -#define BIG_ENDIAN 4321 /* Most Significant Byte first */ +#define BIG_ENDIAN 4321 /* Most Significant Byte first */ #endif /* PDP_ENDIAN - LSB in word, MSW in long is not supported */ #if CALC_BYTE_ORDER == LITTLE_ENDIAN -# define silow sis.Svalue1 /* low order half of full value */ -# define sihigh sis.Svalue2 /* high order half of full value */ +# define silow sis.Svalue1 /* low order half of full value */ +# define sihigh sis.Svalue2 /* high order half of full value */ #else # if CALC_BYTE_ORDER == BIG_ENDIAN -# define silow sis.Svalue2 /* low order half of full value */ -# define sihigh sis.Svalue1 /* high order half of full value */ +# define silow sis.Svalue2 /* low order half of full value */ +# define sihigh sis.Svalue1 /* high order half of full value */ # else /\oo/\ CALC_BYTE_ORDER must be BIG_ENDIAN or LITTLE_ENDIAN /\oo/\ !!! # endif @@ -295,14 +295,14 @@ typedef union { * ZVALUE - multi-prevision integer */ #if MAJOR_VER < 3 -typedef SB32 SIGN; /* calc v2 compatible sign type */ +typedef SB32 SIGN; /* calc v2 compatible sign type */ #else /* MAJOR_VER < 3 */ -typedef bool SIGN; /* sign as a C boolean */ +typedef bool SIGN; /* sign as a C boolean */ #endif /* MAJOR_VER < 3 */ typedef struct { - HALF *v; /* pointer to array of values */ - LEN len; /* number of values in array */ - SIGN sign; /* sign, nonzero is negative */ + HALF *v; /* pointer to array of values */ + LEN len; /* number of values in array */ + SIGN sign; /* sign, nonzero is negative */ } ZVALUE; @@ -312,7 +312,7 @@ typedef struct { */ E_FUNC HALF * alloc(LEN len); E_FUNC int is_const(HALF* h); -#ifdef ALLOCTEST +#ifdef ALLOCTEST E_FUNC void freeh(HALF *); #endif @@ -411,9 +411,9 @@ E_FUNC void zpfact(ZVALUE z, ZVALUE *dest); E_FUNC bool zprimetest(ZVALUE z, long count, ZVALUE skip); E_FUNC bool zredcprimetest(ZVALUE z, long count, ZVALUE skip); E_FUNC bool znextcand(ZVALUE z1, long count, ZVALUE skip, ZVALUE res, - ZVALUE mod, ZVALUE *cand); + ZVALUE mod, ZVALUE *cand); E_FUNC bool zprevcand(ZVALUE z1, long count, ZVALUE skip, ZVALUE res, - ZVALUE mod, ZVALUE *cand); + ZVALUE mod, ZVALUE *cand); E_FUNC FULL zlowfactor(ZVALUE z, long count); E_FUNC FLAG zfactor(ZVALUE z1, ZVALUE z2, ZVALUE *res); E_FUNC long zpix(ZVALUE z1); @@ -446,10 +446,10 @@ E_FUNC HALF *zalloctemp(LEN len); * Len of zero means the structure is not initialized. */ typedef struct { - LEN len; /* number of words in binary modulus */ - ZVALUE mod; /* modulus REDC is computing with */ - ZVALUE inv; /* inverse of modulus in binary modulus */ - ZVALUE one; /* REDC format for the number 1 */ + LEN len; /* number of words in binary modulus */ + ZVALUE mod; /* modulus REDC is computing with */ + ZVALUE inv; /* inverse of modulus in binary modulus */ + ZVALUE one; /* REDC format for the number 1 */ } REDC; E_FUNC REDC *zredcalloc(ZVALUE z1); @@ -464,103 +464,103 @@ E_FUNC void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res); /* * macro expansions to speed this thing up */ -#define ziseven(z) (!(*(z).v & 0x1)) -#define zisodd(z) (*(z).v & 0x1) -#define ziszero(z) ((*(z).v == 0) && ((z).len == 1)) -#define zisneg(z) ((z).sign) -#define zispos(z) (((z).sign == 0) && (*(z).v || ((z).len > 1))) -#define zisunit(z) ((*(z).v == 1) && ((z).len == 1)) -#define zisone(z) ((*(z).v == 1) && ((z).len == 1) && !(z).sign) -#define zisnegone(z) ((*(z).v == 1) && ((z).len == 1) && (z).sign) -#define zltnegone(z) (zisneg(z) && (((z).len > 1) || *(z).v > 1)) -#define zistwo(z) ((*(z).v == 2) && ((z).len == 1) && !(z).sign) -#define zisabstwo(z) ((*(z).v == 2) && ((z).len == 1)) -#define zisabsleone(z) ((*(z).v <= 1) && ((z).len == 1)) -#define zislezero(z) (zisneg(z) || ziszero(z)) -#define zisleone(z) (zisneg(z) || zisabsleone(z)) -#define zistiny(z) ((z).len == 1) +#define ziseven(z) (!(*(z).v & 0x1)) +#define zisodd(z) (*(z).v & 0x1) +#define ziszero(z) ((*(z).v == 0) && ((z).len == 1)) +#define zisneg(z) ((z).sign) +#define zispos(z) (((z).sign == 0) && (*(z).v || ((z).len > 1))) +#define zisunit(z) ((*(z).v == 1) && ((z).len == 1)) +#define zisone(z) ((*(z).v == 1) && ((z).len == 1) && !(z).sign) +#define zisnegone(z) ((*(z).v == 1) && ((z).len == 1) && (z).sign) +#define zltnegone(z) (zisneg(z) && (((z).len > 1) || *(z).v > 1)) +#define zistwo(z) ((*(z).v == 2) && ((z).len == 1) && !(z).sign) +#define zisabstwo(z) ((*(z).v == 2) && ((z).len == 1)) +#define zisabsleone(z) ((*(z).v <= 1) && ((z).len == 1)) +#define zislezero(z) (zisneg(z) || ziszero(z)) +#define zisleone(z) (zisneg(z) || zisabsleone(z)) +#define zistiny(z) ((z).len == 1) /* - * zgtmaxfull(z) true if abs(z) > MAXFULL + * zgtmaxfull(z) true if abs(z) > MAXFULL */ -#define zgtmaxfull(z) (((z).len > 2) || (((z).len == 2) && \ - (((SHALF)(z).v[1]) < 0))) +#define zgtmaxfull(z) (((z).len > 2) || (((z).len == 2) && \ + (((SHALF)(z).v[1]) < 0))) /* - * zgtmaxufull(z) true if abs(z) will not fit into a FULL (> MAXUFULL) + * zgtmaxufull(z) true if abs(z) will not fit into a FULL (> MAXUFULL) */ -#define zgtmaxufull(z) ((z).len > 2) +#define zgtmaxufull(z) ((z).len > 2) /* - * zgtmaxulong(z) true if abs(z) > MAXULONG + * zgtmaxulong(z) true if abs(z) > MAXULONG */ #if BASEB >= LONG_BITS -#define zgtmaxulong(z) ((z).len > 1) +#define zgtmaxulong(z) ((z).len > 1) #else -#define zgtmaxulong(z) zgtmaxufull(z) +#define zgtmaxulong(z) zgtmaxufull(z) #endif /* - * zgtmaxlong(z) true if abs(z) > MAXLONG + * zgtmaxlong(z) true if abs(z) > MAXLONG */ #if BASEB >= LONG_BITS -#define zgtmaxlong(z) (((z).len > 1) || (((z).len == 1) && \ - (((SHALF)(z).v[0]) < 0))) +#define zgtmaxlong(z) (((z).len > 1) || (((z).len == 1) && \ + (((SHALF)(z).v[0]) < 0))) #else -#define zgtmaxlong(z) zgtmaxfull(z) +#define zgtmaxlong(z) zgtmaxfull(z) #endif /* * Some algorithms testing for values of a certain length. Macros such as * zistiny() do this well. In other cases algorithms require tests for values - * in comparison to a given power of 2. In the later case, zistiny() compares - * against a different power of 2 on a 64 bit machine. The macros below + * in comparison to a given power of 2. In the later case, zistiny() compares + * against a different power of 2 on a 64 bit machine. The macros below * provide a tests against powers of 2 that are independent of the work size. * - * zge16b(z) true if abs(z) >= 2^16 - * zge24b(z) true if abs(z) >= 2^24 - * zge31b(z) true if abs(z) >= 2^31 - * zge32b(z) true if abs(z) >= 2^32 - * zge64b(z) true if abs(z) >= 2^64 - * zge128b(z) true if abs(z) >= 2^128 - * zge256b(z) true if abs(z) >= 2^256 - * zge512b(z) true if abs(z) >= 2^512 - * zge1024b(z) true if abs(z) >= 2^1024 - * zge2048b(z) true if abs(z) >= 2^2048 - * zge4096b(z) true if abs(z) >= 2^4096 - * zge8192b(z) true if abs(z) >= 2^8192 + * zge16b(z) true if abs(z) >= 2^16 + * zge24b(z) true if abs(z) >= 2^24 + * zge31b(z) true if abs(z) >= 2^31 + * zge32b(z) true if abs(z) >= 2^32 + * zge64b(z) true if abs(z) >= 2^64 + * zge128b(z) true if abs(z) >= 2^128 + * zge256b(z) true if abs(z) >= 2^256 + * zge512b(z) true if abs(z) >= 2^512 + * zge1024b(z) true if abs(z) >= 2^1024 + * zge2048b(z) true if abs(z) >= 2^2048 + * zge4096b(z) true if abs(z) >= 2^4096 + * zge8192b(z) true if abs(z) >= 2^8192 */ #if BASEB == 32 -#define zge16b(z) (!zistiny(z) || ((z).v[0] >= (HALF)0x10000)) -#define zge24b(z) (!zistiny(z) || ((z).v[0] >= (HALF)0x1000000)) -#define zge31b(z) (!zistiny(z) || (((SHALF)(z).v[0]) < 0)) -#define zge32b(z) (!zistiny(z)) -#define zge64b(z) ((z).len > 2) -#define zge128b(z) ((z).len > 4) -#define zge256b(z) ((z).len > 8) -#define zge512b(z) ((z).len > 16) -#define zge1024b(z) ((z).len > 32) -#define zge2048b(z) ((z).len > 64) -#define zge4096b(z) ((z).len > 128) -#define zge8192b(z) ((z).len > 256) +#define zge16b(z) (!zistiny(z) || ((z).v[0] >= (HALF)0x10000)) +#define zge24b(z) (!zistiny(z) || ((z).v[0] >= (HALF)0x1000000)) +#define zge31b(z) (!zistiny(z) || (((SHALF)(z).v[0]) < 0)) +#define zge32b(z) (!zistiny(z)) +#define zge64b(z) ((z).len > 2) +#define zge128b(z) ((z).len > 4) +#define zge256b(z) ((z).len > 8) +#define zge512b(z) ((z).len > 16) +#define zge1024b(z) ((z).len > 32) +#define zge2048b(z) ((z).len > 64) +#define zge4096b(z) ((z).len > 128) +#define zge8192b(z) ((z).len > 256) #else -#define zge16b(z) (!zistiny(z)) -#define zge24b(z) (((z).len > 2) || (((z).len == 2) && \ - ((z).v[1] >= (HALF)0x100))) -#define zge31b(z) (((z).len > 2) || (((z).len == 2) && \ - (((SHALF)(z).v[1]) < 0))) -#define zge32b(z) ((z).len > 2) -#define zge64b(z) ((z).len > 4) -#define zge128b(z) ((z).len > 8) -#define zge256b(z) ((z).len > 16) -#define zge512b(z) ((z).len > 32) -#define zge1024b(z) ((z).len > 64) -#define zge2048b(z) ((z).len > 128) -#define zge4096b(z) ((z).len > 256) -#define zge8192b(z) ((z).len > 512) +#define zge16b(z) (!zistiny(z)) +#define zge24b(z) (((z).len > 2) || (((z).len == 2) && \ + ((z).v[1] >= (HALF)0x100))) +#define zge31b(z) (((z).len > 2) || (((z).len == 2) && \ + (((SHALF)(z).v[1]) < 0))) +#define zge32b(z) ((z).len > 2) +#define zge64b(z) ((z).len > 4) +#define zge128b(z) ((z).len > 8) +#define zge256b(z) ((z).len > 16) +#define zge512b(z) ((z).len > 32) +#define zge1024b(z) ((z).len > 64) +#define zge2048b(z) ((z).len > 128) +#define zge4096b(z) ((z).len > 256) +#define zge8192b(z) ((z).len > 512) #endif @@ -571,13 +571,13 @@ E_FUNC void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res); * If the value is too large, only the low order bits that are able to * be converted into a FULL will be used. */ -#define ztofull(z) (zistiny(z) ? ((FULL)((z).v[0])) : \ - ((FULL)((z).v[0]) + \ - ((FULL)((z).v[1]) << BASEB))) +#define ztofull(z) (zistiny(z) ? ((FULL)((z).v[0])) : \ + ((FULL)((z).v[0]) + \ + ((FULL)((z).v[1]) << BASEB))) -#define z1tol(z) ((long)((z).v[0])) -#define z2tol(z) ((long)(((z).v[0]) + \ - (((z).v[1] & MAXHALF) << BASEB))) +#define z1tol(z) ((long)((z).v[0])) +#define z2tol(z) ((long)(((z).v[0]) + \ + (((z).v[1] & MAXHALF) << BASEB))) /* * ztoulong - convert an absolute value of a ZVALUE to an unsigned long @@ -586,9 +586,9 @@ E_FUNC void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res); * be converted into a long will be used. */ #if BASEB >= LONG_BITS -# define ztoulong(z) ((unsigned long)z1tol(z)) +# define ztoulong(z) ((unsigned long)z1tol(z)) #else -# define ztoulong(z) ((unsigned long)ztofull(z)) +# define ztoulong(z) ((unsigned long)ztofull(z)) #endif /* @@ -597,38 +597,38 @@ E_FUNC void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res); * If the value is too large, only the low order bits that are able to * be converted into a long will be used. */ -#define ztolong(z) ((long)(ztoulong(z) & MAXLONG)) +#define ztolong(z) ((long)(ztoulong(z) & MAXLONG)) -#define zclearval(z) memset((z).v, 0, (z).len * sizeof(HALF)) +#define zclearval(z) memset((z).v, 0, (z).len * sizeof(HALF)) #define zcopyval(z1,z2) memcpy((z2).v, (z1).v, (z1).len * sizeof(HALF)) -#define zquicktrim(z) {if (((z).len > 1) && ((z).v[(z).len-1] == 0)) \ - (z).len--;} -#define zfree(z) {if ((z).len != 0 && (z).v != NULL) { \ - freeh((z).v); \ - (z).v = NULL; \ - (z).len = 0; \ - (z).sign = 0; } \ - } +#define zquicktrim(z) {if (((z).len > 1) && ((z).v[(z).len-1] == 0)) \ + (z).len--;} +#define zfree(z) {if ((z).len != 0 && (z).v != NULL) { \ + freeh((z).v); \ + (z).v = NULL; \ + (z).len = 0; \ + (z).sign = 0; } \ + } /* * Output modes for numeric displays. */ -#define MODE_DEFAULT 0 -#define MODE_FRAC 1 -#define MODE_INT 2 -#define MODE_REAL 3 -#define MODE_EXP 4 -#define MODE_HEX 5 -#define MODE_OCTAL 6 -#define MODE_BINARY 7 -#define MODE_REAL_AUTO 8 +#define MODE_DEFAULT 0 +#define MODE_FRAC 1 +#define MODE_INT 2 +#define MODE_REAL 3 +#define MODE_EXP 4 +#define MODE_HEX 5 +#define MODE_OCTAL 6 +#define MODE_BINARY 7 +#define MODE_REAL_AUTO 8 #define MODE_ENG 9 -#define MODE_MAX 9 -#define MODE2_OFF (MODE_MAX+1) +#define MODE_MAX 9 +#define MODE2_OFF (MODE_MAX+1) -#define MODE_INITIAL MODE_REAL -#define MODE2_INITIAL MODE2_OFF +#define MODE_INITIAL MODE_REAL +#define MODE2_INITIAL MODE2_OFF /* @@ -691,18 +691,18 @@ EXTERN ZVALUE _b64_; EXTERN HALF *half_tbl[]; /* preset HALF constants, NULL terminated list */ -EXTERN bool _math_abort_; /* nonzero to abort calculations */ -EXTERN ZVALUE _tenpowers_[]; /* table of 10^2^n */ +EXTERN bool _math_abort_; /* nonzero to abort calculations */ +EXTERN ZVALUE _tenpowers_[]; /* table of 10^2^n */ /* * Bit fiddling functions and types */ -EXTERN HALF bitmask[]; /* bit rotation, norm 0 */ -EXTERN HALF lowhalf[]; /* bit masks from low end of HALF */ -EXTERN HALF rlowhalf[]; /* reversed bit masks from low end of HALF */ -EXTERN HALF highhalf[]; /* bit masks from high end of HALF */ -EXTERN HALF rhighhalf[]; /* reversed bit masks from high end of HALF */ -#define HAVE_REVERSED_MASKS /* allows old code to know libcalc.a has them */ +EXTERN HALF bitmask[]; /* bit rotation, norm 0 */ +EXTERN HALF lowhalf[]; /* bit masks from low end of HALF */ +EXTERN HALF rlowhalf[]; /* reversed bit masks from low end of HALF */ +EXTERN HALF highhalf[]; /* bit masks from high end of HALF */ +EXTERN HALF rhighhalf[]; /* reversed bit masks from high end of HALF */ +#define HAVE_REVERSED_MASKS /* allows old code to know libcalc.a has them */ /* @@ -715,9 +715,9 @@ EXTERN HALF rhighhalf[]; /* reversed bit masks from high end of HALF */ * significance may be found in previous bits and HALFs. */ typedef struct { - HALF *loc; /* half address of most significant bit */ - int bit; /* bit position within half of most significant bit */ - int len; /* length of string in bits */ + HALF *loc; /* half address of most significant bit */ + int bit; /* bit position within half of most significant bit */ + int len; /* length of string in bits */ } BITSTR; diff --git a/zmod.c b/zmod.c index 6b26992..cdcb8c2 100644 --- a/zmod.c +++ b/zmod.c @@ -11,7 +11,7 @@ * * 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 + * 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 @@ -19,16 +19,16 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1991/05/22 23:03:55 - * File existed as early as: 1991 + * Under source code control: 1991/05/22 23:03:55 + * File existed as early as: 1991 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * Routines to do modulo arithmetic both normally and also using the REDC * algorithm given by Peter L. Montgomery in Mathematics of Computation, - * volume 44, number 170 (April, 1985). For multiple multiplies using + * volume 44, number 170 (April, 1985). For multiple multiplies using * the same large modulus, the REDC algorithm avoids the usual division * by the modulus, instead replacing it with two multiplies or else a * special algorithm. When these two multiplies or the special algorithm @@ -42,17 +42,17 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -#define POWBITS 4 /* bits for power chunks (must divide BASEB) */ -#define POWNUMS (1< 0) { - z1.sign = (bool)sign; - zmod(z1, z2, &tmp1, 0); - if (tmp1.len < z2.len - 1) { - *res = tmp1; - return; - } - sign = 0; - } + /* + * Now make sure the input number is within the modulo range. + * If not, then reduce it to be within range and make the + * quick check again. + */ + sign = z1.sign; + z1.sign = 0; + cv = zrel(z1, z2); + if (cv == 0) { + *res = _zero_; + return; + } + tmp1 = z1; + if (cv > 0) { + z1.sign = (bool)sign; + zmod(z1, z2, &tmp1, 0); + if (tmp1.len < z2.len - 1) { + *res = tmp1; + return; + } + sign = 0; + } - /* - * Now calculate the difference of the modulus and the absolute - * value of the original number. Compare the original number with - * the difference, and return the one with the smallest absolute - * value, with the correct sign. If the two values are equal, then - * return the positive result. - */ - zsub(z2, tmp1, &tmp2); - cv = zrel(tmp1, tmp2); - if (cv < 0) { - zfree(tmp2); - tmp1.sign = (bool)sign; - if (tmp1.v == z1.v) - zcopy(tmp1, res); - else - *res = tmp1; - } else { - if (cv) - tmp2.sign = !sign; - if (tmp1.v != z1.v) - zfree(tmp1); - *res = tmp2; - } + /* + * Now calculate the difference of the modulus and the absolute + * value of the original number. Compare the original number with + * the difference, and return the one with the smallest absolute + * value, with the correct sign. If the two values are equal, then + * return the positive result. + */ + zsub(z2, tmp1, &tmp2); + cv = zrel(tmp1, tmp2); + if (cv < 0) { + zfree(tmp2); + tmp1.sign = (bool)sign; + if (tmp1.v == z1.v) + zcopy(tmp1, res); + else + *res = tmp1; + } else { + if (cv) + tmp2.sign = !sign; + if (tmp1.v != z1.v) + zfree(tmp1); + *res = tmp2; + } } @@ -231,122 +231,122 @@ zminmod(ZVALUE z1, ZVALUE z2, ZVALUE *res) * congruent. * * given: - * z1 first number to be compared - * z2 second number to be compared - * z3 modulus + * z1 first number to be compared + * z2 second number to be compared + * z3 modulus */ bool zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3) { - ZVALUE tmp1, tmp2, tmp3; - FULL digit; - LEN len; - int cv; + ZVALUE tmp1, tmp2, tmp3; + FULL digit; + LEN len; + int cv; - if (zisneg(z3) || ziszero(z3)) { - math_error("Non-positive modulus in zcmpmod"); - not_reached(); - } - if (zistwo(z3)) - return (((z1.v[0] + z2.v[0]) & 0x1) != 0); + if (zisneg(z3) || ziszero(z3)) { + math_error("Non-positive modulus in zcmpmod"); + not_reached(); + } + if (zistwo(z3)) + return (((z1.v[0] + z2.v[0]) & 0x1) != 0); - /* - * If the two numbers are equal, then their mods are equal. - */ - if ((z1.sign == z2.sign) && (z1.len == z2.len) && - (z1.v[0] == z2.v[0]) && (zcmp(z1, z2) == 0)) - return false; + /* + * If the two numbers are equal, then their mods are equal. + */ + if ((z1.sign == z2.sign) && (z1.len == z2.len) && + (z1.v[0] == z2.v[0]) && (zcmp(z1, z2) == 0)) + return false; - /* - * If both numbers are negative, then we can make them positive. - */ - if (zisneg(z1) && zisneg(z2)) { - z1.sign = 0; - z2.sign = 0; - } + /* + * If both numbers are negative, then we can make them positive. + */ + if (zisneg(z1) && zisneg(z2)) { + z1.sign = 0; + z2.sign = 0; + } - /* - * For small negative numbers, make them positive before comparing. - * In any case, the resulting numbers are in tmp1 and tmp2. - */ - tmp1 = z1; - tmp2 = z2; - len = z3.len; - digit = z3.v[len - 1]; + /* + * For small negative numbers, make them positive before comparing. + * In any case, the resulting numbers are in tmp1 and tmp2. + */ + tmp1 = z1; + tmp2 = z2; + len = z3.len; + digit = z3.v[len - 1]; - if (zisneg(z1) && ((z1.len < len) || - ((z1.len == len) && (z1.v[z1.len - 1] < digit)))) - zadd(z1, z3, &tmp1); + if (zisneg(z1) && ((z1.len < len) || + ((z1.len == len) && (z1.v[z1.len - 1] < digit)))) + zadd(z1, z3, &tmp1); - if (zisneg(z2) && ((z2.len < len) || - ((z2.len == len) && (z2.v[z2.len - 1] < digit)))) - zadd(z2, z3, &tmp2); + if (zisneg(z2) && ((z2.len < len) || + ((z2.len == len) && (z2.v[z2.len - 1] < digit)))) + zadd(z2, z3, &tmp2); - /* - * Now compare the two numbers for equality. - * If they are equal we are all done. - */ - if (zcmp(tmp1, tmp2) == 0) { - if (tmp1.v != z1.v) - zfree(tmp1); - if (tmp2.v != z2.v) - zfree(tmp2); - return false; - } + /* + * Now compare the two numbers for equality. + * If they are equal we are all done. + */ + if (zcmp(tmp1, tmp2) == 0) { + if (tmp1.v != z1.v) + zfree(tmp1); + if (tmp2.v != z2.v) + zfree(tmp2); + return false; + } - /* - * They are not identical. Now if both numbers are positive - * and less than the modulus, then they are definitely not equal. - */ - if ((tmp1.sign == tmp2.sign) && - ((tmp1.len < len) || (zrel(tmp1, z3) < 0)) && - ((tmp2.len < len) || (zrel(tmp2, z3) < 0))) { - if (tmp1.v != z1.v) - zfree(tmp1); - if (tmp2.v != z2.v) - zfree(tmp2); - return true; - } + /* + * They are not identical. Now if both numbers are positive + * and less than the modulus, then they are definitely not equal. + */ + if ((tmp1.sign == tmp2.sign) && + ((tmp1.len < len) || (zrel(tmp1, z3) < 0)) && + ((tmp2.len < len) || (zrel(tmp2, z3) < 0))) { + if (tmp1.v != z1.v) + zfree(tmp1); + if (tmp2.v != z2.v) + zfree(tmp2); + return true; + } - /* - * Either one of the numbers is negative or is large. - * So do the standard thing and subtract the two numbers. - * Then they are equal if the result is 0 (mod z3). - */ - zsub(tmp1, tmp2, &tmp3); - if (tmp1.v != z1.v) - zfree(tmp1); - if (tmp2.v != z2.v) - zfree(tmp2); + /* + * Either one of the numbers is negative or is large. + * So do the standard thing and subtract the two numbers. + * Then they are equal if the result is 0 (mod z3). + */ + zsub(tmp1, tmp2, &tmp3); + if (tmp1.v != z1.v) + zfree(tmp1); + if (tmp2.v != z2.v) + zfree(tmp2); - /* - * Compare the result with the modulus to see if it is equal to - * or less than the modulus. If so, we know the mod result. - */ - tmp3.sign = 0; - cv = zrel(tmp3, z3); - if (cv == 0) { - zfree(tmp3); - return false; - } - if (cv < 0) { - zfree(tmp3); - return true; - } + /* + * Compare the result with the modulus to see if it is equal to + * or less than the modulus. If so, we know the mod result. + */ + tmp3.sign = 0; + cv = zrel(tmp3, z3); + if (cv == 0) { + zfree(tmp3); + return false; + } + if (cv < 0) { + zfree(tmp3); + return true; + } - /* - * We are forced to actually do the division. - * The numbers are congruent if the result is zero. - */ - zmod(tmp3, z3, &tmp1, 0); - zfree(tmp3); - if (ziszero(tmp1)) { - zfree(tmp1); - return false; - } else { - zfree(tmp1); - return true; - } + /* + * We are forced to actually do the division. + * The numbers are congruent if the result is zero. + */ + zmod(tmp3, z3, &tmp1, 0); + zfree(tmp3); + if (ziszero(tmp1)) { + zfree(tmp1); + return false; + } else { + zfree(tmp1); + return true; + } } @@ -358,137 +358,137 @@ zcmpmod(ZVALUE z1, ZVALUE z2, ZVALUE z3) S_FUNC void zmod5(ZVALUE *zp) { - LEN len, modlen, j; - ZVALUE tmp1, tmp2; - ZVALUE z1, z2, z3; - HALF *a, *b; - FULL f; - HALF u; + LEN len, modlen, j; + ZVALUE tmp1, tmp2; + ZVALUE z1, z2, z3; + HALF *a, *b; + FULL f; + HALF u; - /* firewall */ - if (zp == NULL) { - math_error("%s: zp NULL", __func__); - not_reached(); - } + /* firewall */ + if (zp == NULL) { + math_error("%s: zp NULL", __func__); + not_reached(); + } - int subcount = 0; + int subcount = 0; - if (zrel(*zp, *lastmod) < 0) - return; - modlen = lastmod->len; - len = zp->len; - z1.v = zp->v + modlen - 1; - z1.len = len - modlen + 1; - z1.sign = z2.sign = z3.sign = 0; - if (z1.len > modlen + 1) { - math_error("Bad call to zmod5!!!"); - not_reached(); - } - z2.v = lastmodinv->v + modlen + 1 - z1.len; - z2.len = lastmodinv->len - modlen - 1 + z1.len; - zmul(z1, z2, &tmp1); - z3.v = tmp1.v + z1.len; - z3.len = tmp1.len - z1.len; - if (z3.len > 0) { - zmul(z3, *lastmod, &tmp2); - j = modlen; - a = zp->v; - b = tmp2.v; - u = 0; - len = modlen; - while (j-- > 0) { - f = (FULL) *a - (FULL) *b++ - (FULL) u; - *a++ = (HALF) f; - u = - (HALF) (f >> BASEB); - } - if (z1.len > 1) { - len++; - if (tmp2.len > modlen) - f = (FULL) *a - (FULL) *b - (FULL) u; - else - f = (FULL) *a - (FULL) u; - *a++ = (HALF) f; - } - while (len > 0 && *--a == 0) - len--; - zp->len = len; - zfree(tmp2); - } - zfree(tmp1); - while (len > 0 && zrel(*zp, *lastmod) >= 0) { - subcount++; - if (subcount > 2) { - math_error("Too many subtractions in zmod5"); - not_reached(); - } - j = modlen; - a = zp->v; - b = lastmod->v; - u = 0; - while (j-- > 0) { - f = (FULL) *a - (FULL) *b++ - (FULL) u; - *a++ = (HALF) f; - u = - (HALF) (f >> BASEB); - } - if (len > modlen) { - f = (FULL) *a - (FULL) u; - *a++ = (HALF) f; - } - while (len > 0 && *--a == 0) - len--; - zp->len = len; - } - if (len == 0) - zp->len = 1; + if (zrel(*zp, *lastmod) < 0) + return; + modlen = lastmod->len; + len = zp->len; + z1.v = zp->v + modlen - 1; + z1.len = len - modlen + 1; + z1.sign = z2.sign = z3.sign = 0; + if (z1.len > modlen + 1) { + math_error("Bad call to zmod5!!!"); + not_reached(); + } + z2.v = lastmodinv->v + modlen + 1 - z1.len; + z2.len = lastmodinv->len - modlen - 1 + z1.len; + zmul(z1, z2, &tmp1); + z3.v = tmp1.v + z1.len; + z3.len = tmp1.len - z1.len; + if (z3.len > 0) { + zmul(z3, *lastmod, &tmp2); + j = modlen; + a = zp->v; + b = tmp2.v; + u = 0; + len = modlen; + while (j-- > 0) { + f = (FULL) *a - (FULL) *b++ - (FULL) u; + *a++ = (HALF) f; + u = - (HALF) (f >> BASEB); + } + if (z1.len > 1) { + len++; + if (tmp2.len > modlen) + f = (FULL) *a - (FULL) *b - (FULL) u; + else + f = (FULL) *a - (FULL) u; + *a++ = (HALF) f; + } + while (len > 0 && *--a == 0) + len--; + zp->len = len; + zfree(tmp2); + } + zfree(tmp1); + while (len > 0 && zrel(*zp, *lastmod) >= 0) { + subcount++; + if (subcount > 2) { + math_error("Too many subtractions in zmod5"); + not_reached(); + } + j = modlen; + a = zp->v; + b = lastmod->v; + u = 0; + while (j-- > 0) { + f = (FULL) *a - (FULL) *b++ - (FULL) u; + *a++ = (HALF) f; + u = - (HALF) (f >> BASEB); + } + if (len > modlen) { + f = (FULL) *a - (FULL) u; + *a++ = (HALF) f; + } + while (len > 0 && *--a == 0) + len--; + zp->len = len; + } + if (len == 0) + zp->len = 1; } S_FUNC void zmod6(ZVALUE z1, ZVALUE *res) { - LEN len, modlen, len0; - int sign; - ZVALUE zp0, ztmp; + LEN len, modlen, len0; + int sign; + ZVALUE zp0, ztmp; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (ziszero(z1) || zisone(*lastmod)) { - *res = _zero_; - return; - } - sign = z1.sign; - z1.sign = 0; - zcopy(z1, &ztmp); - modlen = lastmod->len; - zp0.sign = 0; - while (zrel(ztmp, *lastmod) >= 0) { - len = ztmp.len; - zp0.len = len; - len0 = 0; - if (len > 2 * modlen) { - zp0.len = 2 * modlen; - len0 = len - 2 * modlen; - } - zp0.v = ztmp.v + len - zp0.len; - zmod5(&zp0); - len = len0 + zp0.len; - while (len > 0 && ztmp.v[len - 1] == 0) - len--; - if (len == 0) { - zfree(ztmp); - *res = _zero_; - return; - } - ztmp.len = len; - } - if (sign) - zsub(*lastmod, ztmp, res); - else - zcopy(ztmp, res); - zfree(ztmp); + if (ziszero(z1) || zisone(*lastmod)) { + *res = _zero_; + return; + } + sign = z1.sign; + z1.sign = 0; + zcopy(z1, &ztmp); + modlen = lastmod->len; + zp0.sign = 0; + while (zrel(ztmp, *lastmod) >= 0) { + len = ztmp.len; + zp0.len = len; + len0 = 0; + if (len > 2 * modlen) { + zp0.len = 2 * modlen; + len0 = len - 2 * modlen; + } + zp0.v = ztmp.v + len - zp0.len; + zmod5(&zp0); + len = len0 + zp0.len; + while (len > 0 && ztmp.v[len - 1] == 0) + len--; + if (len == 0) { + zfree(ztmp); + *res = _zero_; + return; + } + ztmp.len = len; + } + if (sign) + zsub(*lastmod, ztmp, res); + else + zcopy(ztmp, res); + zfree(ztmp); } @@ -499,347 +499,347 @@ zmod6(ZVALUE z1, ZVALUE *res) * This calculates the result by examining the power POWBITS bits at a time, * using a small table of POWNUMS low powers to calculate powers for those bits, * and repeated squaring and multiplying by the partial powers to generate - * the complete power. If the power being raised to is high enough, then - * this uses the REDC algorithm to avoid doing many divisions. When using + * the complete power. If the power being raised to is high enough, then + * this uses the REDC algorithm to avoid doing many divisions. When using * REDC, multiple calls to this routine using the same modulus will be * slightly faster. */ void zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res) { - HALF *hp; /* pointer to current word of the power */ - REDC *rp; /* REDC information to be used */ - ZVALUE *pp; /* pointer to low power table */ - ZVALUE ans, temp; /* calculation values */ - ZVALUE modpow; /* current small power */ - ZVALUE lowpowers[POWNUMS]; /* low powers */ - ZVALUE ztmp; - int curshift; /* shift value for word of power */ - HALF curhalf; /* current word of power */ - unsigned int curpow; /* current low power */ - unsigned int curbit; /* current bit of low power */ - bool free_z1; /* true => need to free z1 */ - int i; + HALF *hp; /* pointer to current word of the power */ + REDC *rp; /* REDC information to be used */ + ZVALUE *pp; /* pointer to low power table */ + ZVALUE ans, temp; /* calculation values */ + ZVALUE modpow; /* current small power */ + ZVALUE lowpowers[POWNUMS]; /* low powers */ + ZVALUE ztmp; + int curshift; /* shift value for word of power */ + HALF curhalf; /* current word of power */ + unsigned int curpow; /* current low power */ + unsigned int curbit; /* current bit of low power */ + bool free_z1; /* true => need to free z1 */ + int i; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (zisneg(z3) || ziszero(z3)) { - math_error("Non-positive modulus in zpowermod"); - not_reached(); - } - if (zisneg(z2)) { - math_error("Negative power in zpowermod"); - not_reached(); - } + if (zisneg(z3) || ziszero(z3)) { + math_error("Non-positive modulus in zpowermod"); + not_reached(); + } + if (zisneg(z2)) { + math_error("Negative power in zpowermod"); + not_reached(); + } - /* - * Check easy cases first. - */ - if ((ziszero(z1) && !ziszero(z2)) || zisunit(z3)) { - /* 0^(non_zero) or x^y mod 1 always produces zero */ - *res = _zero_; - return; - } - if (ziszero(z2)) { /* x^0 == 1 */ - *res = _one_; - return; - } - if (zistwo(z3)) { /* mod 2 */ - if (zisodd(z1)) - *res = _one_; - else - *res = _zero_; - return; - } - if (zisunit(z1) && (!z1.sign || ziseven(z2))) { - /* 1^x or (-1)^(2x) */ - *res = _one_; - return; - } + /* + * Check easy cases first. + */ + if ((ziszero(z1) && !ziszero(z2)) || zisunit(z3)) { + /* 0^(non_zero) or x^y mod 1 always produces zero */ + *res = _zero_; + return; + } + if (ziszero(z2)) { /* x^0 == 1 */ + *res = _one_; + return; + } + if (zistwo(z3)) { /* mod 2 */ + if (zisodd(z1)) + *res = _one_; + else + *res = _zero_; + return; + } + if (zisunit(z1) && (!z1.sign || ziseven(z2))) { + /* 1^x or (-1)^(2x) */ + *res = _one_; + return; + } - /* - * Normalize the number being raised to be non-negative and to lie - * within the modulo range. Then check for zero or one specially. - */ - ztmp.len = 0; - free_z1 = false; - if (zisneg(z1) || zrel(z1, z3) >= 0) { - zmod(z1, z3, &ztmp, 0); - zfree(z1); - z1 = ztmp; - free_z1 = true; - } - if (ziszero(z1)) { - zfree(z1); - if (ztmp.len) - zfree(ztmp); - *res = _zero_; - return; - } - if (zisone(z1)) { - zfree(z1); - if (ztmp.len) - zfree(ztmp); - *res = _one_; - return; - } + /* + * Normalize the number being raised to be non-negative and to lie + * within the modulo range. Then check for zero or one specially. + */ + ztmp.len = 0; + free_z1 = false; + if (zisneg(z1) || zrel(z1, z3) >= 0) { + zmod(z1, z3, &ztmp, 0); + zfree(z1); + z1 = ztmp; + free_z1 = true; + } + if (ziszero(z1)) { + zfree(z1); + if (ztmp.len) + zfree(ztmp); + *res = _zero_; + return; + } + if (zisone(z1)) { + zfree(z1); + if (ztmp.len) + zfree(ztmp); + *res = _one_; + return; + } - /* - * If modulus is large enough use zmod5 - */ - if (z3.len >= conf->pow2) { - if (havelastmod && zcmp(z3, *lastmod)) { - zfree(*lastmod); - zfree(*lastmodinv); - havelastmod = false; - } - if (!havelastmod) { - zcopy(z3, lastmod); - zbitvalue(2 * z3.len * BASEB, &temp); - zquo(temp, z3, lastmodinv, 0); - zfree(temp); - havelastmod = true; - } + /* + * If modulus is large enough use zmod5 + */ + if (z3.len >= conf->pow2) { + if (havelastmod && zcmp(z3, *lastmod)) { + zfree(*lastmod); + zfree(*lastmodinv); + havelastmod = false; + } + if (!havelastmod) { + zcopy(z3, lastmod); + zbitvalue(2 * z3.len * BASEB, &temp); + zquo(temp, z3, lastmodinv, 0); + zfree(temp); + havelastmod = true; + } - /* zzz */ - for (pp = &lowpowers[2]; pp <= &lowpowers[POWNUMS-1]; pp++) { - pp->len = 0; - pp->v = NULL; - } - lowpowers[0] = _one_; - lowpowers[1] = z1; - ans = _one_; + /* zzz */ + for (pp = &lowpowers[2]; pp <= &lowpowers[POWNUMS-1]; pp++) { + pp->len = 0; + pp->v = NULL; + } + lowpowers[0] = _one_; + lowpowers[1] = z1; + ans = _one_; - hp = &z2.v[z2.len - 1]; - curhalf = *hp; - curshift = BASEB - POWBITS; - while (curshift && ((curhalf >> curshift) == 0)) - curshift -= POWBITS; + hp = &z2.v[z2.len - 1]; + curhalf = *hp; + curshift = BASEB - POWBITS; + while (curshift && ((curhalf >> curshift) == 0)) + curshift -= POWBITS; - /* - * Calculate the result by examining the power POWBITS bits at - * a time, and use the table of low powers at each iteration. - */ - for (;;) { - curpow = (curhalf >> curshift) & (POWNUMS - 1); - pp = &lowpowers[curpow]; + /* + * Calculate the result by examining the power POWBITS bits at + * a time, and use the table of low powers at each iteration. + */ + for (;;) { + curpow = (curhalf >> curshift) & (POWNUMS - 1); + pp = &lowpowers[curpow]; - /* - * If the small power is not yet saved in the table, - * then calculate it and remember it in the table for - * future use. - */ - if (pp->v == NULL) { - if (curpow & 0x1) { - zcopy(z1, &modpow); - free_z1 = false; - } else { - modpow = _one_; - } + /* + * If the small power is not yet saved in the table, + * then calculate it and remember it in the table for + * future use. + */ + if (pp->v == NULL) { + if (curpow & 0x1) { + zcopy(z1, &modpow); + free_z1 = false; + } else { + modpow = _one_; + } - for (curbit = 0x2; - curbit <= curpow; - curbit *= 2) { - pp = &lowpowers[curbit]; - if (pp->v == NULL) { - zsquare(lowpowers[curbit/2], - &temp); - zmod5(&temp); - zcopy(temp, pp); - zfree(temp); - } - if (curbit & curpow) { - zmul(*pp, modpow, &temp); - zfree(modpow); - zmod5(&temp); - zcopy(temp, &modpow); - zfree(temp); - } - } - pp = &lowpowers[curpow]; - if (pp->v != NULL) { - zfree(*pp); - } - *pp = modpow; - } + for (curbit = 0x2; + curbit <= curpow; + curbit *= 2) { + pp = &lowpowers[curbit]; + if (pp->v == NULL) { + zsquare(lowpowers[curbit/2], + &temp); + zmod5(&temp); + zcopy(temp, pp); + zfree(temp); + } + if (curbit & curpow) { + zmul(*pp, modpow, &temp); + zfree(modpow); + zmod5(&temp); + zcopy(temp, &modpow); + zfree(temp); + } + } + pp = &lowpowers[curpow]; + if (pp->v != NULL) { + zfree(*pp); + } + *pp = modpow; + } - /* - * If the power is nonzero, then accumulate the small - * power into the result. - */ - if (curpow) { - zmul(ans, *pp, &temp); - zfree(ans); - zmod5(&temp); - zcopy(temp, &ans); - zfree(temp); - } + /* + * If the power is nonzero, then accumulate the small + * power into the result. + */ + if (curpow) { + zmul(ans, *pp, &temp); + zfree(ans); + zmod5(&temp); + zcopy(temp, &ans); + zfree(temp); + } - /* - * Select the next POWBITS bits of the power, if - * there is any more to generate. - */ - curshift -= POWBITS; - if (curshift < 0) { - if (hp == z2.v) - break; - curhalf = *--hp; - curshift = BASEB - POWBITS; - } + /* + * Select the next POWBITS bits of the power, if + * there is any more to generate. + */ + curshift -= POWBITS; + if (curshift < 0) { + if (hp == z2.v) + break; + curhalf = *--hp; + curshift = BASEB - POWBITS; + } - /* - * Square the result POWBITS times to make room for - * the next chunk of bits. - */ - for (i = 0; i < POWBITS; i++) { - zsquare(ans, &temp); - zfree(ans); - zmod5(&temp); - zcopy(temp, &ans); - zfree(temp); - } - } + /* + * Square the result POWBITS times to make room for + * the next chunk of bits. + */ + for (i = 0; i < POWBITS; i++) { + zsquare(ans, &temp); + zfree(ans); + zmod5(&temp); + zcopy(temp, &ans); + zfree(temp); + } + } - for (pp = &lowpowers[2]; pp <= &lowpowers[POWNUMS-1]; pp++) { - zfree(*pp); - } - *res = ans; - if (ztmp.len) - zfree(ztmp); - return; - } + for (pp = &lowpowers[2]; pp <= &lowpowers[POWNUMS-1]; pp++) { + zfree(*pp); + } + *res = ans; + if (ztmp.len) + zfree(ztmp); + return; + } - /* - * If the modulus is odd and small enough then use - * the REDC algorithm. The size where this is done is configurable. - */ - if (z3.len < conf->redc2 && zisodd(z3)) { - if (powermodredc && zcmp(powermodredc->mod, z3)) { - zredcfree(powermodredc); - powermodredc = NULL; - } - if (powermodredc == NULL) - powermodredc = zredcalloc(z3); - rp = powermodredc; - zredcencode(rp, z1, &temp); - if (free_z1 == true) { - zfree(z1); - } - zredcpower(rp, temp, z2, &z1); - zfree(temp); - zredcdecode(rp, z1, res); - zfree(z1); - return; - } + /* + * If the modulus is odd and small enough then use + * the REDC algorithm. The size where this is done is configurable. + */ + if (z3.len < conf->redc2 && zisodd(z3)) { + if (powermodredc && zcmp(powermodredc->mod, z3)) { + zredcfree(powermodredc); + powermodredc = NULL; + } + if (powermodredc == NULL) + powermodredc = zredcalloc(z3); + rp = powermodredc; + zredcencode(rp, z1, &temp); + if (free_z1 == true) { + zfree(z1); + } + zredcpower(rp, temp, z2, &z1); + zfree(temp); + zredcdecode(rp, z1, res); + zfree(z1); + return; + } - /* - * Modulus or power is small enough to perform the power raising - * directly. Initialize the table of powers. - */ - for (pp = &lowpowers[2]; pp <= &lowpowers[POWNUMS-1]; pp++) { - pp->len = 0; - pp->v = NULL; - } - lowpowers[0] = _one_; - lowpowers[1] = z1; - ans = _one_; + /* + * Modulus or power is small enough to perform the power raising + * directly. Initialize the table of powers. + */ + for (pp = &lowpowers[2]; pp <= &lowpowers[POWNUMS-1]; pp++) { + pp->len = 0; + pp->v = NULL; + } + lowpowers[0] = _one_; + lowpowers[1] = z1; + ans = _one_; - hp = &z2.v[z2.len - 1]; - curhalf = *hp; - curshift = BASEB - POWBITS; - while (curshift && ((curhalf >> curshift) == 0)) - curshift -= POWBITS; + hp = &z2.v[z2.len - 1]; + curhalf = *hp; + curshift = BASEB - POWBITS; + while (curshift && ((curhalf >> curshift) == 0)) + curshift -= POWBITS; - /* - * Calculate the result by examining the power POWBITS bits at a time, - * and use the table of low powers at each iteration. - */ - for (;;) { - curpow = (curhalf >> curshift) & (POWNUMS - 1); - pp = &lowpowers[curpow]; + /* + * Calculate the result by examining the power POWBITS bits at a time, + * and use the table of low powers at each iteration. + */ + for (;;) { + curpow = (curhalf >> curshift) & (POWNUMS - 1); + pp = &lowpowers[curpow]; - /* - * If the small power is not yet saved in the table, then - * calculate it and remember it in the table for future use. - */ - if (pp->v == NULL) { - if (curpow & 0x1) { - zcopy(z1, &modpow); - free_z1 = false; - } else { - modpow = _one_; - } + /* + * If the small power is not yet saved in the table, then + * calculate it and remember it in the table for future use. + */ + if (pp->v == NULL) { + if (curpow & 0x1) { + zcopy(z1, &modpow); + free_z1 = false; + } else { + modpow = _one_; + } - for (curbit = 0x2; curbit <= curpow; curbit *= 2) { - pp = &lowpowers[curbit]; - if (pp->v == NULL) { - zsquare(lowpowers[curbit/2], &temp); - zmod(temp, z3, pp, 0); - zfree(temp); - } - if (curbit & curpow) { - zmul(*pp, modpow, &temp); - zfree(modpow); - zmod(temp, z3, &modpow, 0); - zfree(temp); - } - } - pp = &lowpowers[curpow]; - if (pp->v != NULL) { - zfree(*pp); - } - *pp = modpow; - } + for (curbit = 0x2; curbit <= curpow; curbit *= 2) { + pp = &lowpowers[curbit]; + if (pp->v == NULL) { + zsquare(lowpowers[curbit/2], &temp); + zmod(temp, z3, pp, 0); + zfree(temp); + } + if (curbit & curpow) { + zmul(*pp, modpow, &temp); + zfree(modpow); + zmod(temp, z3, &modpow, 0); + zfree(temp); + } + } + pp = &lowpowers[curpow]; + if (pp->v != NULL) { + zfree(*pp); + } + *pp = modpow; + } - /* - * If the power is nonzero, then accumulate the small power - * into the result. - */ - if (curpow) { - zmul(ans, *pp, &temp); - zfree(ans); - zmod(temp, z3, &ans, 0); - zfree(temp); - } + /* + * If the power is nonzero, then accumulate the small power + * into the result. + */ + if (curpow) { + zmul(ans, *pp, &temp); + zfree(ans); + zmod(temp, z3, &ans, 0); + zfree(temp); + } - /* - * Select the next POWBITS bits of the power, if there is - * any more to generate. - */ - curshift -= POWBITS; - if (curshift < 0) { - if (hp-- == z2.v) - break; - curhalf = *hp; - curshift = BASEB - POWBITS; - } + /* + * Select the next POWBITS bits of the power, if there is + * any more to generate. + */ + curshift -= POWBITS; + if (curshift < 0) { + if (hp-- == z2.v) + break; + curhalf = *hp; + curshift = BASEB - POWBITS; + } - /* - * Square the result POWBITS times to make room for the next - * chunk of bits. - */ - for (i = 0; i < POWBITS; i++) { - zsquare(ans, &temp); - zfree(ans); - zmod(temp, z3, &ans, 0); - zfree(temp); - } - } + /* + * Square the result POWBITS times to make room for the next + * chunk of bits. + */ + for (i = 0; i < POWBITS; i++) { + zsquare(ans, &temp); + zfree(ans); + zmod(temp, z3, &ans, 0); + zfree(temp); + } + } - for (pp = &lowpowers[2]; pp <= &lowpowers[POWNUMS-1]; pp++) { - zfree(*pp); - } - *res = ans; - if (ztmp.len) - zfree(ztmp); - if (free_z1 == true) { - zfree(z1); - } + for (pp = &lowpowers[2]; pp <= &lowpowers[POWNUMS-1]; pp++) { + zfree(*pp); + } + *res = ans; + if (ztmp.len) + zfree(ztmp); + if (free_z1 == true) { + zfree(z1); + } } /* @@ -848,104 +848,104 @@ zpowermod(ZVALUE z1, ZVALUE z2, ZVALUE z3, ZVALUE *res) S_FUNC void zredcmodinv(ZVALUE z, ZVALUE *res) { - ZVALUE tmp; - HALF *a0, *a, *b; - HALF bit, h, inv, v; - FULL f; - LEN N, i, j, len; + ZVALUE tmp; + HALF *a0, *a, *b; + HALF bit, h, inv, v; + FULL f; + LEN N, i, j, len; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - N = z.len; - tmp.sign = 0; - tmp.len = N; - tmp.v = alloc(N); - zclearval(tmp); - *tmp.v = 1; - h = 1 + *z.v; - bit = 1; - inv = 1; - while (h) { - bit <<= 1; - if (bit & h) { - inv |= bit; - h += bit * *z.v; - } - } + N = z.len; + tmp.sign = 0; + tmp.len = N; + tmp.v = alloc(N); + zclearval(tmp); + *tmp.v = 1; + h = 1 + *z.v; + bit = 1; + inv = 1; + while (h) { + bit <<= 1; + if (bit & h) { + inv |= bit; + h += bit * *z.v; + } + } - j = N; - a0 = tmp.v; - while (j-- > 0) { - v = inv * *a0; - i = j; - a = a0; - b = z.v; - f = (FULL) v * (FULL) *b++ + (FULL) *a++; - *a0 = v; - while (i-- > 0) { - f = (FULL) v * (FULL) *b++ + (FULL) *a + (f >> BASEB); - *a++ = (HALF) f; - } - while (j > 0 && *++a0 == 0) - j--; - } - a = tmp.v + N; - len = N; - while (*--a == 0) - len--; - tmp.len = len; - zcopy(tmp, res); - zfree(tmp); + j = N; + a0 = tmp.v; + while (j-- > 0) { + v = inv * *a0; + i = j; + a = a0; + b = z.v; + f = (FULL) v * (FULL) *b++ + (FULL) *a++; + *a0 = v; + while (i-- > 0) { + f = (FULL) v * (FULL) *b++ + (FULL) *a + (f >> BASEB); + *a++ = (HALF) f; + } + while (j > 0 && *++a0 == 0) + j--; + } + a = tmp.v + N; + len = N; + while (*--a == 0) + len--; + tmp.len = len; + zcopy(tmp, res); + zfree(tmp); } /* * Initialize the REDC algorithm for a particular modulus, * returning a pointer to a structure that is used for other - * REDC calls. An error is generated if the structure cannot + * REDC calls. An error is generated if the structure cannot * be allocated. The modulus must be odd and positive. * * given: - * z1 modulus to initialize for + * z1 modulus to initialize for */ REDC * zredcalloc(ZVALUE z1) { - REDC *rp; /* REDC information */ - ZVALUE tmp; - long bit; + REDC *rp; /* REDC information */ + ZVALUE tmp; + long bit; - if (ziseven(z1) || zisneg(z1)) { - math_error("REDC requires positive odd modulus"); - not_reached(); - } + if (ziseven(z1) || zisneg(z1)) { + math_error("REDC requires positive odd modulus"); + not_reached(); + } - rp = (REDC *) malloc(sizeof(REDC)); - if (rp == NULL) { - math_error("Cannot allocate REDC structure"); - not_reached(); - } + rp = (REDC *) malloc(sizeof(REDC)); + if (rp == NULL) { + math_error("Cannot allocate REDC structure"); + not_reached(); + } - /* - * Round up the binary modulus to the next power of two - * which is at a word boundary. Then the shift and modulo - * operations mod the binary modulus can be done very cheaply. - * Calculate the REDC format for the number 1 for future use. - */ - zcopy(z1, &rp->mod); - zredcmodinv(z1, &rp->inv); - bit = zhighbit(z1) + 1; - if (bit % BASEB) - bit += (BASEB - (bit % BASEB)); - zbitvalue(bit, &tmp); - zmod(tmp, rp->mod, &rp->one, 0); - zfree(tmp); - rp->len = (LEN)(bit / BASEB); - return rp; + /* + * Round up the binary modulus to the next power of two + * which is at a word boundary. Then the shift and modulo + * operations mod the binary modulus can be done very cheaply. + * Calculate the REDC format for the number 1 for future use. + */ + zcopy(z1, &rp->mod); + zredcmodinv(z1, &rp->inv); + bit = zhighbit(z1) + 1; + if (bit % BASEB) + bit += (BASEB - (bit % BASEB)); + zbitvalue(bit, &tmp); + zmod(tmp, rp->mod, &rp->one, 0); + zfree(tmp); + rp->len = (LEN)(bit / BASEB); + return rp; } @@ -954,21 +954,21 @@ zredcalloc(ZVALUE z1) * and then the REDC structure itself. * * given: - * rp REDC information to be cleared + * rp REDC information to be cleared */ void zredcfree(REDC *rp) { - /* firewall */ - if (rp == NULL) { - math_error("%s: rp NULL", __func__); - not_reached(); - } + /* firewall */ + if (rp == NULL) { + math_error("%s: rp NULL", __func__); + not_reached(); + } - zfree(rp->mod); - zfree(rp->inv); - zfree(rp->one); - free(rp); + zfree(rp->mod); + zfree(rp->inv); + zfree(rp->one); + free(rp); } @@ -978,86 +978,86 @@ zredcfree(REDC *rp) * The resulting number can be used for multiplying, adding, subtracting, * or comparing with any other such converted numbers, as if the numbers * were being calculated modulo the number which initialized the REDC - * information. When the final value is not converted, the result is the + * information. When the final value is not converted, the result is the * same as if the usual operations were done with the original numbers. * * given: - * rp REDC information - * z1 number to be converted - * res returned converted number + * rp REDC information + * z1 number to be converted + * res returned converted number */ void zredcencode(REDC *rp, ZVALUE z1, ZVALUE *res) { - ZVALUE tmp1; + ZVALUE tmp1; - /* firewall */ - if (rp == NULL) { - math_error("%s: rp NULL", __func__); - not_reached(); - } - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (rp == NULL) { + math_error("%s: rp NULL", __func__); + not_reached(); + } + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - /* - * Confirm or initialize lastmod information when modulus is a - * big number. - */ + /* + * Confirm or initialize lastmod information when modulus is a + * big number. + */ - if (rp->len >= conf->pow2) { - if (havelastmod && zcmp(rp->mod, *lastmod)) { - zfree(*lastmod); - zfree(*lastmodinv); - havelastmod = false; - } - if (!havelastmod) { - zcopy(rp->mod, lastmod); - zbitvalue(2 * rp->len * BASEB, &tmp1); - zquo(tmp1, rp->mod, lastmodinv, 0); - zfree(tmp1); - havelastmod = true; - } - } - /* - * Handle the cases 0, 1, -1, and 2 specially since these are - * easy to calculate. Zero transforms to zero, and the others - * can be obtained from the precomputed REDC format for 1 since - * addition and subtraction act normally for REDC format numbers. - */ - if (ziszero(z1)) { - *res = _zero_; - return; - } - if (zisone(z1)) { - zcopy(rp->one, res); - return; - } - if (zisunit(z1)) { - zsub(rp->mod, rp->one, res); - return; - } - if (zistwo(z1)) { - zadd(rp->one, rp->one, &tmp1); - if (zrel(tmp1, rp->mod) < 0) { - *res = tmp1; - return; - } - zsub(tmp1, rp->mod, res); - zfree(tmp1); - return; - } + if (rp->len >= conf->pow2) { + if (havelastmod && zcmp(rp->mod, *lastmod)) { + zfree(*lastmod); + zfree(*lastmodinv); + havelastmod = false; + } + if (!havelastmod) { + zcopy(rp->mod, lastmod); + zbitvalue(2 * rp->len * BASEB, &tmp1); + zquo(tmp1, rp->mod, lastmodinv, 0); + zfree(tmp1); + havelastmod = true; + } + } + /* + * Handle the cases 0, 1, -1, and 2 specially since these are + * easy to calculate. Zero transforms to zero, and the others + * can be obtained from the precomputed REDC format for 1 since + * addition and subtraction act normally for REDC format numbers. + */ + if (ziszero(z1)) { + *res = _zero_; + return; + } + if (zisone(z1)) { + zcopy(rp->one, res); + return; + } + if (zisunit(z1)) { + zsub(rp->mod, rp->one, res); + return; + } + if (zistwo(z1)) { + zadd(rp->one, rp->one, &tmp1); + if (zrel(tmp1, rp->mod) < 0) { + *res = tmp1; + return; + } + zsub(tmp1, rp->mod, res); + zfree(tmp1); + return; + } - /* - * Not a trivial number to convert, so do the full transformation. - */ - zshift(z1, rp->len * BASEB, &tmp1); - if (rp->len < conf->pow2) - zmod(tmp1, rp->mod, res, 0); - else - zmod6(tmp1, res); - zfree(tmp1); + /* + * Not a trivial number to convert, so do the full transformation. + */ + zshift(z1, rp->len * BASEB, &tmp1); + if (rp->len < conf->pow2) + zmod(tmp1, rp->mod, res, 0); + else + zmod6(tmp1, res); + zfree(tmp1); } @@ -1069,171 +1069,171 @@ zredcencode(REDC *rp, ZVALUE z1, ZVALUE *res) * quicker than the divide, since dividing is harder than multiplying. * * given: - * rp REDC information - * z1 number to be transformed - * res returned transformed number + * rp REDC information + * z1 number to be transformed + * res returned transformed number */ void zredcdecode(REDC *rp, ZVALUE z1, ZVALUE *res) { - ZVALUE tmp1, tmp2; - ZVALUE ztmp; - ZVALUE ztop; - ZVALUE zp1; - FULL muln; - HALF *h1; - HALF *h3; - HALF *hd = NULL; - HALF Ninv; - LEN modlen; - LEN len; - FULL f; - int sign; + ZVALUE tmp1, tmp2; + ZVALUE ztmp; + ZVALUE ztop; + ZVALUE zp1; + FULL muln; + HALF *h1; + HALF *h3; + HALF *hd = NULL; + HALF Ninv; + LEN modlen; + LEN len; + FULL f; + int sign; - /* firewall */ - if (rp == NULL) { - math_error("%s: rp NULL", __func__); - not_reached(); - } - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } - int i, j; + /* firewall */ + if (rp == NULL) { + math_error("%s: rp NULL", __func__); + not_reached(); + } + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } + int i, j; - /* - * Check first for the special values for 0 and 1 that are easy. - */ - if (ziszero(z1)) { - *res = _zero_; - return; - } - if ((z1.len == rp->one.len) && (z1.v[0] == rp->one.v[0]) && - (zcmp(z1, rp->one) == 0)) { - *res = _one_; - return; - } - ztop.len = 0; - ztmp.len = 0; - modlen = rp->len; - sign = z1.sign; - z1.sign = 0; - if (z1.len > modlen) { - ztop.v = z1.v + modlen; - ztop.len = z1.len - modlen; - ztop.sign = 0; - if (zrel(ztop, rp->mod) >= 0) { - zmod(ztop, rp->mod, &ztmp, 0); - ztop = ztmp; - } - len = modlen; - h1 = z1.v + len; - while (len > 0 && *--h1 == 0) - len--; - if (len == 0) { - if (ztmp.len) - *res = ztmp; - else - zcopy(ztop, res); - return; - } - z1.len = len; + /* + * Check first for the special values for 0 and 1 that are easy. + */ + if (ziszero(z1)) { + *res = _zero_; + return; + } + if ((z1.len == rp->one.len) && (z1.v[0] == rp->one.v[0]) && + (zcmp(z1, rp->one) == 0)) { + *res = _one_; + return; + } + ztop.len = 0; + ztmp.len = 0; + modlen = rp->len; + sign = z1.sign; + z1.sign = 0; + if (z1.len > modlen) { + ztop.v = z1.v + modlen; + ztop.len = z1.len - modlen; + ztop.sign = 0; + if (zrel(ztop, rp->mod) >= 0) { + zmod(ztop, rp->mod, &ztmp, 0); + ztop = ztmp; + } + len = modlen; + h1 = z1.v + len; + while (len > 0 && *--h1 == 0) + len--; + if (len == 0) { + if (ztmp.len) + *res = ztmp; + else + zcopy(ztop, res); + return; + } + z1.len = len; - } - if (rp->mod.len < conf->pow2) { - Ninv = rp->inv.v[0]; - res->sign = 0; - res->len = modlen; - res->v = alloc(modlen); - zclearval(*res); - h1 = z1.v; - for (i = 0; i < modlen; i++) { - h3 = rp->mod.v; - hd = res->v; - f = (FULL) *hd++; - if (i < z1.len) - f += (FULL) *h1++; - muln = (HALF) ((f & BASE1) * Ninv); - f = ((muln * (FULL) *h3++) + f) >> BASEB; - j = modlen; - while (--j > 0) { - f += (muln * (FULL) *h3++) + (FULL) *hd; - hd[-1] = (HALF) f; - f >>= BASEB; - hd++; - } - hd[-1] = (HALF) f; - } - len = modlen; - while (*--hd == 0 && len > 1) - len--; - if (len == 0) - len = 1; - res->len = len; - } else { - /* Here 0 < z1 < 2^bitnum */ + } + if (rp->mod.len < conf->pow2) { + Ninv = rp->inv.v[0]; + res->sign = 0; + res->len = modlen; + res->v = alloc(modlen); + zclearval(*res); + h1 = z1.v; + for (i = 0; i < modlen; i++) { + h3 = rp->mod.v; + hd = res->v; + f = (FULL) *hd++; + if (i < z1.len) + f += (FULL) *h1++; + muln = (HALF) ((f & BASE1) * Ninv); + f = ((muln * (FULL) *h3++) + f) >> BASEB; + j = modlen; + while (--j > 0) { + f += (muln * (FULL) *h3++) + (FULL) *hd; + hd[-1] = (HALF) f; + f >>= BASEB; + hd++; + } + hd[-1] = (HALF) f; + } + len = modlen; + while (*--hd == 0 && len > 1) + len--; + if (len == 0) + len = 1; + res->len = len; + } else { + /* Here 0 < z1 < 2^bitnum */ - /* - * First calculate the following: - * tmp2 = ((z1 * inv) % 2^bitnum. - * The mod operations can be done with no work since the bit - * number was selected as a multiple of the word size. Just - * reduce the sizes of the numbers as required. - */ - zmul(z1, rp->inv, &tmp2); - if (tmp2.len > modlen) { - h1 = tmp2.v + modlen; - len = modlen; - while (len > 0 && *--h1 == 0) - len--; - tmp2.len = len; - } + /* + * First calculate the following: + * tmp2 = ((z1 * inv) % 2^bitnum. + * The mod operations can be done with no work since the bit + * number was selected as a multiple of the word size. Just + * reduce the sizes of the numbers as required. + */ + zmul(z1, rp->inv, &tmp2); + if (tmp2.len > modlen) { + h1 = tmp2.v + modlen; + len = modlen; + while (len > 0 && *--h1 == 0) + len--; + tmp2.len = len; + } - /* - * Next calculate the following: - * res = (z1 + tmp2 * modulus) / 2^bitnum - * Since 0 < z1 < 2^bitnum and the division is always exact, - * the quotient can be evaluated by rounding up - * (tmp2 * modulus)/2^bitnum. This can be achieved by defining - * zp1 by an appropriate shift and then adding one. - */ - zmul(tmp2, rp->mod, &tmp1); - zfree(tmp2); - if (tmp1.len > modlen) { - zp1.v = tmp1.v + modlen; - zp1.len = tmp1.len - modlen; - zp1.sign = 0; - zadd(zp1, _one_, res); - } else { - *res = _one_; - } - zfree(tmp1); - } - if (ztop.len) { - zadd(*res, ztop, &tmp1); - zfree(*res); - if (ztmp.len) - zfree(ztmp); - *res = tmp1; - } + /* + * Next calculate the following: + * res = (z1 + tmp2 * modulus) / 2^bitnum + * Since 0 < z1 < 2^bitnum and the division is always exact, + * the quotient can be evaluated by rounding up + * (tmp2 * modulus)/2^bitnum. This can be achieved by defining + * zp1 by an appropriate shift and then adding one. + */ + zmul(tmp2, rp->mod, &tmp1); + zfree(tmp2); + if (tmp1.len > modlen) { + zp1.v = tmp1.v + modlen; + zp1.len = tmp1.len - modlen; + zp1.sign = 0; + zadd(zp1, _one_, res); + } else { + *res = _one_; + } + zfree(tmp1); + } + if (ztop.len) { + zadd(*res, ztop, &tmp1); + zfree(*res); + if (ztmp.len) + zfree(ztmp); + *res = tmp1; + } - /* - * Finally do a final modulo by a simple subtraction if necessary. - * This is all that is needed because the previous calculation is - * guaranteed to always be less than twice the modulus. - */ + /* + * Finally do a final modulo by a simple subtraction if necessary. + * This is all that is needed because the previous calculation is + * guaranteed to always be less than twice the modulus. + */ - if (zrel(*res, rp->mod) >= 0) { - zsub(*res, rp->mod, &tmp1); - zfree(*res); - *res = tmp1; - } - if (sign && !ziszero(*res)) { - zsub(rp->mod, *res, &tmp1); - zfree(*res); - *res = tmp1; - } - return; + if (zrel(*res, rp->mod) >= 0) { + zsub(*res, rp->mod, &tmp1); + zfree(*res); + *res = tmp1; + } + if (sign && !ziszero(*res)) { + zsub(rp->mod, *res, &tmp1); + zfree(*res); + *res = tmp1; + } + return; } @@ -1241,7 +1241,7 @@ zredcdecode(REDC *rp, ZVALUE z1, ZVALUE *res) * Multiply two numbers in REDC format together producing a result also * in REDC format. If the result is converted back to a normal number, * then the result is the same as the modulo'd multiplication of the - * original numbers before they were converted to REDC format. This + * original numbers before they were converted to REDC format. This * calculation is done in one of two ways, depending on the size of the * modulus. For large numbers, the REDC definition is used directly * which involves three multiplies overall. For small numbers, a @@ -1249,308 +1249,308 @@ zredcdecode(REDC *rp, ZVALUE z1, ZVALUE *res) * and the REDC algorithm at the same time to produce the result. * * given: - * rp REDC information - * z1 first REDC number to be multiplied - * z2 second REDC number to be multiplied - * res resulting REDC number + * rp REDC information + * z1 first REDC number to be multiplied + * z2 second REDC number to be multiplied + * res resulting REDC number */ void zredcmul(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res) { - FULL mulb; - FULL muln; - HALF *h1; - HALF *h2; - HALF *h3; - HALF *hd; - HALF Ninv; - HALF topdigit = 0; - LEN modlen; - LEN len; - LEN len2; - SIUNION sival1; - SIUNION sival2; - SIUNION carry; - ZVALUE tmp; - ZVALUE z1tmp, z2tmp; - int sign; + FULL mulb; + FULL muln; + HALF *h1; + HALF *h2; + HALF *h3; + HALF *hd; + HALF Ninv; + HALF topdigit = 0; + LEN modlen; + LEN len; + LEN len2; + SIUNION sival1; + SIUNION sival2; + SIUNION carry; + ZVALUE tmp; + ZVALUE z1tmp, z2tmp; + int sign; - /* firewall */ - if (rp == NULL) { - math_error("%s: rp NULL", __func__); - not_reached(); - } - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (rp == NULL) { + math_error("%s: rp NULL", __func__); + not_reached(); + } + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - sign = z1.sign ^ z2.sign; - z1.sign = 0; - z2.sign = 0; - z1tmp.len = 0; - if (zrel(z1, rp->mod) >= 0) { - zmod(z1, rp->mod, &z1tmp, 0); - z1 = z1tmp; - } - z2tmp.len = 0; - if (zrel(z2, rp->mod) >= 0) { - zmod(z2, rp->mod, &z2tmp, 0); - z2 = z2tmp; - } + sign = z1.sign ^ z2.sign; + z1.sign = 0; + z2.sign = 0; + z1tmp.len = 0; + if (zrel(z1, rp->mod) >= 0) { + zmod(z1, rp->mod, &z1tmp, 0); + z1 = z1tmp; + } + z2tmp.len = 0; + if (zrel(z2, rp->mod) >= 0) { + zmod(z2, rp->mod, &z2tmp, 0); + z2 = z2tmp; + } - /* - * Check for special values which we easily know the answer. - */ - if (ziszero(z1) || ziszero(z2)) { - *res = _zero_; - if (z1tmp.len) - zfree(z1tmp); - if (z2tmp.len) - zfree(z2tmp); - return; - } + /* + * Check for special values which we easily know the answer. + */ + if (ziszero(z1) || ziszero(z2)) { + *res = _zero_; + if (z1tmp.len) + zfree(z1tmp); + if (z2tmp.len) + zfree(z2tmp); + return; + } - if ((z1.len == rp->one.len) && (z1.v[0] == rp->one.v[0]) && - (zcmp(z1, rp->one) == 0)) { - if (sign) - zsub(rp->mod, z2, res); - else - zcopy(z2, res); - if (z1tmp.len) - zfree(z1tmp); - if (z2tmp.len) - zfree(z2tmp); - return; - } + if ((z1.len == rp->one.len) && (z1.v[0] == rp->one.v[0]) && + (zcmp(z1, rp->one) == 0)) { + if (sign) + zsub(rp->mod, z2, res); + else + zcopy(z2, res); + if (z1tmp.len) + zfree(z1tmp); + if (z2tmp.len) + zfree(z2tmp); + return; + } - if ((z2.len == rp->one.len) && (z2.v[0] == rp->one.v[0]) && - (zcmp(z2, rp->one) == 0)) { - if (sign) - zsub(rp->mod, z1, res); - else - zcopy(z1, res); - if (z1tmp.len) - zfree(z1tmp); - if (z2tmp.len) - zfree(z2tmp); - return; - } + if ((z2.len == rp->one.len) && (z2.v[0] == rp->one.v[0]) && + (zcmp(z2, rp->one) == 0)) { + if (sign) + zsub(rp->mod, z1, res); + else + zcopy(z1, res); + if (z1tmp.len) + zfree(z1tmp); + if (z2tmp.len) + zfree(z2tmp); + return; + } - /* - * If the size of the modulus is large, then just do the multiply, - * followed by the two multiplies contained in the REDC routine. - * This will be quicker than directly doing the REDC calculation - * because of the O(N^1.585) speed of the multiplies. The size - * of the number which this is done is configurable. - */ - if (rp->mod.len >= conf->redc2) { - zmul(z1, z2, &tmp); - zredcdecode(rp, tmp, res); - zfree(tmp); - if (sign && !ziszero(*res)) { - zsub(rp->mod, *res, &tmp); - zfree(*res); - *res = tmp; - } - if (z1tmp.len) - zfree(z1tmp); - if (z2tmp.len) - zfree(z2tmp); - return; - } + /* + * If the size of the modulus is large, then just do the multiply, + * followed by the two multiplies contained in the REDC routine. + * This will be quicker than directly doing the REDC calculation + * because of the O(N^1.585) speed of the multiplies. The size + * of the number which this is done is configurable. + */ + if (rp->mod.len >= conf->redc2) { + zmul(z1, z2, &tmp); + zredcdecode(rp, tmp, res); + zfree(tmp); + if (sign && !ziszero(*res)) { + zsub(rp->mod, *res, &tmp); + zfree(*res); + *res = tmp; + } + if (z1tmp.len) + zfree(z1tmp); + if (z2tmp.len) + zfree(z2tmp); + return; + } - /* - * The number is small enough to calculate by doing the O(N^2) REDC - * algorithm directly. This algorithm performs the multiplication and - * the reduction at the same time. Notice the obscure facts that - * only the lowest word of the inverse value is used, and that - * there is no shifting of the partial products as there is in a - * normal multiply. - */ - modlen = rp->mod.len; - Ninv = rp->inv.v[0]; + /* + * The number is small enough to calculate by doing the O(N^2) REDC + * algorithm directly. This algorithm performs the multiplication and + * the reduction at the same time. Notice the obscure facts that + * only the lowest word of the inverse value is used, and that + * there is no shifting of the partial products as there is in a + * normal multiply. + */ + modlen = rp->mod.len; + Ninv = rp->inv.v[0]; - /* - * Allocate the result and clear it. - * The size of the result will be equal to or smaller than - * the modulus size. - */ - res->sign = 0; - res->len = modlen; - res->v = alloc(modlen); + /* + * Allocate the result and clear it. + * The size of the result will be equal to or smaller than + * the modulus size. + */ + res->sign = 0; + res->len = modlen; + res->v = alloc(modlen); - hd = res->v; - len = modlen; - zclearval(*res); + hd = res->v; + len = modlen; + zclearval(*res); - /* - * Do this outermost loop over all the digits of z1. - */ - h1 = z1.v; - len = z1.len; - while (len--) { - /* - * Start off with the next digit of z1, the first - * digit of z2, and the first digit of the modulus. - */ - mulb = (FULL) *h1++; - h2 = z2.v; - h3 = rp->mod.v; - hd = res->v; - sival1.ivalue = mulb * ((FULL) *h2++) + ((FULL) *hd++); - muln = ((HALF) (sival1.silow * Ninv)); - sival2.ivalue = muln * ((FULL) *h3++) + ((FULL) sival1.silow); - carry.ivalue = ((FULL) sival1.sihigh) + ((FULL) sival2.sihigh); + /* + * Do this outermost loop over all the digits of z1. + */ + h1 = z1.v; + len = z1.len; + while (len--) { + /* + * Start off with the next digit of z1, the first + * digit of z2, and the first digit of the modulus. + */ + mulb = (FULL) *h1++; + h2 = z2.v; + h3 = rp->mod.v; + hd = res->v; + sival1.ivalue = mulb * ((FULL) *h2++) + ((FULL) *hd++); + muln = ((HALF) (sival1.silow * Ninv)); + sival2.ivalue = muln * ((FULL) *h3++) + ((FULL) sival1.silow); + carry.ivalue = ((FULL) sival1.sihigh) + ((FULL) sival2.sihigh); - /* - * Do this innermost loop for each digit of z2, except - * for the first digit which was just done above. - */ - len2 = z2.len; - while (--len2 > 0) { - sival1.ivalue = mulb * ((FULL) *h2++) - + ((FULL) *hd) + ((FULL) carry.silow); - sival2.ivalue = muln * ((FULL) *h3++) - + ((FULL) sival1.silow); - carry.ivalue = ((FULL) sival1.sihigh) - + ((FULL) sival2.sihigh) - + ((FULL) carry.sihigh); + /* + * Do this innermost loop for each digit of z2, except + * for the first digit which was just done above. + */ + len2 = z2.len; + while (--len2 > 0) { + sival1.ivalue = mulb * ((FULL) *h2++) + + ((FULL) *hd) + ((FULL) carry.silow); + sival2.ivalue = muln * ((FULL) *h3++) + + ((FULL) sival1.silow); + carry.ivalue = ((FULL) sival1.sihigh) + + ((FULL) sival2.sihigh) + + ((FULL) carry.sihigh); - hd[-1] = sival2.silow; - hd++; - } + hd[-1] = sival2.silow; + hd++; + } - /* - * Now continue the loop as necessary so the total number - * of iterations is equal to the size of the modulus. - * This acts as if the innermost loop was repeated for - * high digits of z2 that are zero. - */ - len2 = modlen - z2.len; - while (len2--) { - sival2.ivalue = muln * ((FULL) *h3++) - + ((FULL) *hd) - + ((FULL) carry.silow); - carry.ivalue = ((FULL) sival2.sihigh) - + ((FULL) carry.sihigh); + /* + * Now continue the loop as necessary so the total number + * of iterations is equal to the size of the modulus. + * This acts as if the innermost loop was repeated for + * high digits of z2 that are zero. + */ + len2 = modlen - z2.len; + while (len2--) { + sival2.ivalue = muln * ((FULL) *h3++) + + ((FULL) *hd) + + ((FULL) carry.silow); + carry.ivalue = ((FULL) sival2.sihigh) + + ((FULL) carry.sihigh); - hd[-1] = sival2.silow; - hd++; - } + hd[-1] = sival2.silow; + hd++; + } - carry.ivalue += topdigit; - hd[-1] = carry.silow; - topdigit = carry.sihigh; - } + carry.ivalue += topdigit; + hd[-1] = carry.silow; + topdigit = carry.sihigh; + } - /* - * Now continue the loop as necessary so the total number - * of iterations is equal to the size of the modulus. - * This acts as if the outermost loop was repeated for high - * digits of z1 that are zero. - */ - len = modlen - z1.len; - while (len--) { - /* - * Start off with the first digit of the modulus. - */ - h3 = rp->mod.v; - hd = res->v; - muln = ((HALF) (*hd * Ninv)); - sival2.ivalue = muln * ((FULL) *h3++) + (FULL) *hd++; - carry.ivalue = ((FULL) sival2.sihigh); + /* + * Now continue the loop as necessary so the total number + * of iterations is equal to the size of the modulus. + * This acts as if the outermost loop was repeated for high + * digits of z1 that are zero. + */ + len = modlen - z1.len; + while (len--) { + /* + * Start off with the first digit of the modulus. + */ + h3 = rp->mod.v; + hd = res->v; + muln = ((HALF) (*hd * Ninv)); + sival2.ivalue = muln * ((FULL) *h3++) + (FULL) *hd++; + carry.ivalue = ((FULL) sival2.sihigh); - /* - * Do this innermost loop for each digit of the modulus, - * except for the first digit which was just done above. - */ - len2 = modlen; - while (--len2 > 0) { - sival2.ivalue = muln * ((FULL) *h3++) - + ((FULL) *hd) + ((FULL) carry.silow); - carry.ivalue = ((FULL) sival2.sihigh) - + ((FULL) carry.sihigh); + /* + * Do this innermost loop for each digit of the modulus, + * except for the first digit which was just done above. + */ + len2 = modlen; + while (--len2 > 0) { + sival2.ivalue = muln * ((FULL) *h3++) + + ((FULL) *hd) + ((FULL) carry.silow); + carry.ivalue = ((FULL) sival2.sihigh) + + ((FULL) carry.sihigh); - hd[-1] = sival2.silow; - hd++; - } - carry.ivalue += topdigit; - hd[-1] = carry.silow; - topdigit = carry.sihigh; - } + hd[-1] = sival2.silow; + hd++; + } + carry.ivalue += topdigit; + hd[-1] = carry.silow; + topdigit = carry.sihigh; + } - /* - * Determine the true size of the result, taking the top digit of - * the current result into account. The top digit is not stored in - * the number because it is temporary and would become zero anyway - * after the final subtraction is done. - */ - if (topdigit == 0) { - len = modlen; - while (*--hd == 0 && len > 1) { - len--; - } - res->len = len; + /* + * Determine the true size of the result, taking the top digit of + * the current result into account. The top digit is not stored in + * the number because it is temporary and would become zero anyway + * after the final subtraction is done. + */ + if (topdigit == 0) { + len = modlen; + while (*--hd == 0 && len > 1) { + len--; + } + res->len = len; - /* - * Compare the result with the modulus. - * If it is less than the modulus, then the calculation is complete. - */ + /* + * Compare the result with the modulus. + * If it is less than the modulus, then the calculation is complete. + */ - if (zrel(*res, rp->mod) < 0) { - if (z1tmp.len) - zfree(z1tmp); - if (z2tmp.len) - zfree(z2tmp); - if (sign && !ziszero(*res)) { - zsub(rp->mod, *res, &tmp); - zfree(*res); - *res = tmp; - } - return; - } - } + if (zrel(*res, rp->mod) < 0) { + if (z1tmp.len) + zfree(z1tmp); + if (z2tmp.len) + zfree(z2tmp); + if (sign && !ziszero(*res)) { + zsub(rp->mod, *res, &tmp); + zfree(*res); + *res = tmp; + } + return; + } + } - /* - * Do a subtraction to reduce the result to a value less than - * the modulus. The REDC algorithm guarantees that a single subtract - * is all that is needed. Ignore any borrowing from the possible - * highest word of the current result because that would affect - * only the top digit value that was not stored and would become - * zero anyway. - */ - carry.ivalue = 0; - h1 = rp->mod.v; - hd = res->v; - len = modlen; - while (len--) { - carry.ivalue = BASE1 - ((FULL) *hd) + ((FULL) *h1++) - + ((FULL) carry.silow); - *hd++ = (HALF)(BASE1 - carry.silow); - carry.silow = carry.sihigh; - } + /* + * Do a subtraction to reduce the result to a value less than + * the modulus. The REDC algorithm guarantees that a single subtract + * is all that is needed. Ignore any borrowing from the possible + * highest word of the current result because that would affect + * only the top digit value that was not stored and would become + * zero anyway. + */ + carry.ivalue = 0; + h1 = rp->mod.v; + hd = res->v; + len = modlen; + while (len--) { + carry.ivalue = BASE1 - ((FULL) *hd) + ((FULL) *h1++) + + ((FULL) carry.silow); + *hd++ = (HALF)(BASE1 - carry.silow); + carry.silow = carry.sihigh; + } - /* - * Now finally recompute the size of the result. - */ - len = modlen; - hd = &res->v[len - 1]; - while ((*hd == 0) && (len > 1)) { - hd--; - len--; - } - res->len = len; - if (z1tmp.len) - zfree(z1tmp); - if (z2tmp.len) - zfree(z2tmp); - if (sign && !ziszero(*res)) { - zsub(rp->mod, *res, &tmp); - zfree(*res); - *res = tmp; - } + /* + * Now finally recompute the size of the result. + */ + len = modlen; + hd = &res->v[len - 1]; + while ((*hd == 0) && (len > 1)) { + hd--; + len--; + } + res->len = len; + if (z1tmp.len) + zfree(z1tmp); + if (z2tmp.len) + zfree(z2tmp); + if (sign && !ziszero(*res)) { + zsub(rp->mod, *res, &tmp); + zfree(*res); + *res = tmp; + } } @@ -1558,204 +1558,204 @@ zredcmul(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res) * Square a number in REDC format producing a result also in REDC format. * * given: - * rp REDC information - * z1 REDC number to be squared - * res resulting REDC number + * rp REDC information + * z1 REDC number to be squared + * res resulting REDC number */ void zredcsquare(REDC *rp, ZVALUE z1, ZVALUE *res) { - FULL mulb; - FULL muln; - HALF *h1; - HALF *h2; - HALF *h3; - HALF *hd = NULL; - HALF Ninv; - HALF topdigit = 0; - LEN modlen; - LEN len; - SIUNION sival1; - SIUNION sival2; - SIUNION sival3; - SIUNION carry; - ZVALUE tmp, ztmp; - FULL f; - int i, j; + FULL mulb; + FULL muln; + HALF *h1; + HALF *h2; + HALF *h3; + HALF *hd = NULL; + HALF Ninv; + HALF topdigit = 0; + LEN modlen; + LEN len; + SIUNION sival1; + SIUNION sival2; + SIUNION sival3; + SIUNION carry; + ZVALUE tmp, ztmp; + FULL f; + int i, j; - /* firewall */ - if (rp == NULL) { - math_error("%s: rp NULL", __func__); - not_reached(); - } - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (rp == NULL) { + math_error("%s: rp NULL", __func__); + not_reached(); + } + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - ztmp.len = 0; - z1.sign = 0; - if (zrel(z1, rp->mod) >= 0) { - zmod(z1, rp->mod, &ztmp, 0); - z1 = ztmp; - } - if (ziszero(z1)) { - *res = _zero_; - if (ztmp.len) - zfree(ztmp); - return; - } - if ((z1.len == rp->one.len) && (z1.v[0] == rp->one.v[0]) && - (zcmp(z1, rp->one) == 0)) { - zcopy(z1, res); - if (ztmp.len) - zfree(ztmp); - return; - } + ztmp.len = 0; + z1.sign = 0; + if (zrel(z1, rp->mod) >= 0) { + zmod(z1, rp->mod, &ztmp, 0); + z1 = ztmp; + } + if (ziszero(z1)) { + *res = _zero_; + if (ztmp.len) + zfree(ztmp); + return; + } + if ((z1.len == rp->one.len) && (z1.v[0] == rp->one.v[0]) && + (zcmp(z1, rp->one) == 0)) { + zcopy(z1, res); + if (ztmp.len) + zfree(ztmp); + return; + } - /* - * If the modulus is small enough, then call the multiply - * routine to produce the result. Otherwise call the O(N^1.585) - * routines to get the answer. - */ - if (rp->mod.len >= conf->redc2 - || 3 * z1.len < 2 * rp->mod.len) { - zsquare(z1, &tmp); - zredcdecode(rp, tmp, res); - zfree(tmp); - if (ztmp.len) - zfree(ztmp); - return; - } - modlen = rp->mod.len; - Ninv = rp->inv.v[0]; + /* + * If the modulus is small enough, then call the multiply + * routine to produce the result. Otherwise call the O(N^1.585) + * routines to get the answer. + */ + if (rp->mod.len >= conf->redc2 + || 3 * z1.len < 2 * rp->mod.len) { + zsquare(z1, &tmp); + zredcdecode(rp, tmp, res); + zfree(tmp); + if (ztmp.len) + zfree(ztmp); + return; + } + modlen = rp->mod.len; + Ninv = rp->inv.v[0]; - res->sign = 0; - res->len = modlen; - res->v = alloc(modlen); + res->sign = 0; + res->len = modlen; + res->v = alloc(modlen); - zclearval(*res); + zclearval(*res); - h1 = z1.v; + h1 = z1.v; - for (i = 0; i < z1.len; i++) { - mulb = (FULL) *h1++; - h2 = h1; - h3 = rp->mod.v; - hd = res->v; - if (i == 0) { - sival1.ivalue = mulb * mulb; - muln = (HALF) (sival1.silow * Ninv); - sival2.ivalue = muln * ((FULL) *h3++) - + (FULL) sival1.silow; - carry.ivalue = (FULL) sival1.sihigh - + (FULL) sival2.sihigh; - hd++; - } else { - muln = (HALF) (*hd * Ninv); - f = (muln * ((FULL) *h3++) + (FULL) *hd++) >> BASEB; - j = i; - while (--j > 0) { - f += muln * ((FULL) *h3++) + *hd; - hd[-1] = (HALF) f; - f >>= BASEB; - hd++; - } - carry.ivalue = f; - sival1.ivalue = mulb * mulb + (FULL) carry.silow; - sival2.ivalue = muln * ((FULL) *h3++) - + (FULL) *hd - + (FULL) sival1.silow; - carry.ivalue = (FULL) sival1.sihigh - + (FULL) sival2.sihigh - + (FULL) carry.sihigh; - hd[-1] = sival2.silow; - hd++; - } - j = z1.len - i; - while (--j > 0) { - sival1.ivalue = mulb * ((FULL) *h2++); - sival2.ivalue = ((FULL) sival1.silow << 1) - + muln * ((FULL) *h3++); - sival3.ivalue = (FULL) sival2.silow - + (FULL) *hd - + (FULL) carry.silow; - carry.ivalue = ((FULL) sival1.sihigh << 1) - + (FULL) sival2.sihigh - + (FULL) sival3.sihigh - + (FULL) carry.sihigh; - hd[-1] = sival3.silow; - hd++; - } - j = modlen - z1.len; - while (j-- > 0) { - sival1.ivalue = muln * ((FULL) *h3++) - + (FULL) *hd - + (FULL) carry.silow; - carry.ivalue = (FULL) sival1.sihigh - + (FULL) carry.sihigh; - hd[-1] = sival1.silow; - hd++; - } - carry.ivalue += (FULL) topdigit; - hd[-1] = carry.silow; - topdigit = carry.sihigh; - } - i = modlen - z1.len; - while (i-- > 0) { - h3 = rp->mod.v; - hd = res->v; - muln = (HALF) (*hd * Ninv); - sival1.ivalue = muln * ((FULL) *h3++) + (FULL) *hd++; - carry.ivalue = (FULL) sival1.sihigh; - j = modlen; - while (--j > 0) { - sival1.ivalue = muln * ((FULL) *h3++) - + (FULL) *hd - + (FULL) carry.silow; - carry.ivalue = (FULL) sival1.sihigh - + (FULL) carry.sihigh; - hd[-1] = sival1.silow; - hd++; - } - carry.ivalue += (FULL) topdigit; - hd[-1] = carry.silow; - topdigit = carry.sihigh; - } - if (topdigit == 0) { - len = modlen; - while (*--hd == 0 && len > 1) { - len--; - } - res->len = len; - if (zrel(*res, rp->mod) < 0) { - if (ztmp.len) - zfree(ztmp); - return; - } - } + for (i = 0; i < z1.len; i++) { + mulb = (FULL) *h1++; + h2 = h1; + h3 = rp->mod.v; + hd = res->v; + if (i == 0) { + sival1.ivalue = mulb * mulb; + muln = (HALF) (sival1.silow * Ninv); + sival2.ivalue = muln * ((FULL) *h3++) + + (FULL) sival1.silow; + carry.ivalue = (FULL) sival1.sihigh + + (FULL) sival2.sihigh; + hd++; + } else { + muln = (HALF) (*hd * Ninv); + f = (muln * ((FULL) *h3++) + (FULL) *hd++) >> BASEB; + j = i; + while (--j > 0) { + f += muln * ((FULL) *h3++) + *hd; + hd[-1] = (HALF) f; + f >>= BASEB; + hd++; + } + carry.ivalue = f; + sival1.ivalue = mulb * mulb + (FULL) carry.silow; + sival2.ivalue = muln * ((FULL) *h3++) + + (FULL) *hd + + (FULL) sival1.silow; + carry.ivalue = (FULL) sival1.sihigh + + (FULL) sival2.sihigh + + (FULL) carry.sihigh; + hd[-1] = sival2.silow; + hd++; + } + j = z1.len - i; + while (--j > 0) { + sival1.ivalue = mulb * ((FULL) *h2++); + sival2.ivalue = ((FULL) sival1.silow << 1) + + muln * ((FULL) *h3++); + sival3.ivalue = (FULL) sival2.silow + + (FULL) *hd + + (FULL) carry.silow; + carry.ivalue = ((FULL) sival1.sihigh << 1) + + (FULL) sival2.sihigh + + (FULL) sival3.sihigh + + (FULL) carry.sihigh; + hd[-1] = sival3.silow; + hd++; + } + j = modlen - z1.len; + while (j-- > 0) { + sival1.ivalue = muln * ((FULL) *h3++) + + (FULL) *hd + + (FULL) carry.silow; + carry.ivalue = (FULL) sival1.sihigh + + (FULL) carry.sihigh; + hd[-1] = sival1.silow; + hd++; + } + carry.ivalue += (FULL) topdigit; + hd[-1] = carry.silow; + topdigit = carry.sihigh; + } + i = modlen - z1.len; + while (i-- > 0) { + h3 = rp->mod.v; + hd = res->v; + muln = (HALF) (*hd * Ninv); + sival1.ivalue = muln * ((FULL) *h3++) + (FULL) *hd++; + carry.ivalue = (FULL) sival1.sihigh; + j = modlen; + while (--j > 0) { + sival1.ivalue = muln * ((FULL) *h3++) + + (FULL) *hd + + (FULL) carry.silow; + carry.ivalue = (FULL) sival1.sihigh + + (FULL) carry.sihigh; + hd[-1] = sival1.silow; + hd++; + } + carry.ivalue += (FULL) topdigit; + hd[-1] = carry.silow; + topdigit = carry.sihigh; + } + if (topdigit == 0) { + len = modlen; + while (*--hd == 0 && len > 1) { + len--; + } + res->len = len; + if (zrel(*res, rp->mod) < 0) { + if (ztmp.len) + zfree(ztmp); + return; + } + } - carry.ivalue = 0; - h1 = rp->mod.v; - hd = res->v; - len = modlen; - while (len--) { - carry.ivalue = BASE1 - ((FULL) *hd) + ((FULL) *h1++) - + ((FULL) carry.silow); - *hd++ = (HALF)(BASE1 - carry.silow); - carry.silow = carry.sihigh; - } + carry.ivalue = 0; + h1 = rp->mod.v; + hd = res->v; + len = modlen; + while (len--) { + carry.ivalue = BASE1 - ((FULL) *hd) + ((FULL) *h1++) + + ((FULL) carry.silow); + *hd++ = (HALF)(BASE1 - carry.silow); + carry.silow = carry.sihigh; + } - len = modlen; - hd = &res->v[len - 1]; - while ((*hd == 0) && (len > 1)) { - hd--; - len--; - } - res->len = len; - if (ztmp.len) - zfree(ztmp); + len = modlen; + hd = &res->v[len - 1]; + while ((*hd == 0) && (len > 1)) { + hd--; + len--; + } + res->len = len; + if (ztmp.len) + zfree(ztmp); } @@ -1768,191 +1768,191 @@ zredcsquare(REDC *rp, ZVALUE z1, ZVALUE *res) * the complete power. * * given: - * rp REDC information - * z1 REDC number to be raised - * z2 normal number to raise number to - * res result + * rp REDC information + * z1 REDC number to be raised + * z2 normal number to raise number to + * res result */ void zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res) { - HALF *hp; /* pointer to current word of the power */ - ZVALUE *pp; /* pointer to low power table */ - ZVALUE ans, temp; /* calculation values */ - ZVALUE ztmp; - ZVALUE modpow; /* current small power */ - ZVALUE lowpowers[POWNUMS]; /* low powers */ - int curshift; /* shift value for word of power */ - HALF curhalf; /* current word of power */ - unsigned int curpow; /* current low power */ - unsigned int curbit; /* current bit of low power */ - int sign; - int i; + HALF *hp; /* pointer to current word of the power */ + ZVALUE *pp; /* pointer to low power table */ + ZVALUE ans, temp; /* calculation values */ + ZVALUE ztmp; + ZVALUE modpow; /* current small power */ + ZVALUE lowpowers[POWNUMS]; /* low powers */ + int curshift; /* shift value for word of power */ + HALF curhalf; /* current word of power */ + unsigned int curpow; /* current low power */ + unsigned int curbit; /* current bit of low power */ + int sign; + int i; - /* firewall */ - if (rp == NULL) { - math_error("%s: rp NULL", __func__); - not_reached(); - } - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (rp == NULL) { + math_error("%s: rp NULL", __func__); + not_reached(); + } + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (zisneg(z2)) { - math_error("Negative power in zredcpower"); - not_reached(); - } + if (zisneg(z2)) { + math_error("Negative power in zredcpower"); + not_reached(); + } - if (zisunit(rp->mod)) { - *res = _zero_; - return; - } + if (zisunit(rp->mod)) { + *res = _zero_; + return; + } - sign = zisodd(z2) ? z1.sign : 0; - z1.sign = 0; - ztmp.len = 0; - if (zrel(z1, rp->mod) >= 0) { - zmod(z1, rp->mod, &ztmp, 0); - z1 = ztmp; - } - /* - * Check for zero or the REDC format for one. - */ - if (ziszero(z1)) { - if (ziszero(z2)) - *res = _one_; - else - *res = _zero_; - if (ztmp.len) - zfree(ztmp); - return; - } - if (zcmp(z1, rp->one) == 0) { - if (sign) - zsub(rp->mod, rp->one, res); - else - zcopy(rp->one, res); - if (ztmp.len) - zfree(ztmp); - return; - } + sign = zisodd(z2) ? z1.sign : 0; + z1.sign = 0; + ztmp.len = 0; + if (zrel(z1, rp->mod) >= 0) { + zmod(z1, rp->mod, &ztmp, 0); + z1 = ztmp; + } + /* + * Check for zero or the REDC format for one. + */ + if (ziszero(z1)) { + if (ziszero(z2)) + *res = _one_; + else + *res = _zero_; + if (ztmp.len) + zfree(ztmp); + return; + } + if (zcmp(z1, rp->one) == 0) { + if (sign) + zsub(rp->mod, rp->one, res); + else + zcopy(rp->one, res); + if (ztmp.len) + zfree(ztmp); + return; + } - /* - * See if the number being raised is the REDC format for -1. - * If so, then the answer is the REDC format for one or minus one. - * To do this check, calculate the REDC format for -1. - */ - if (((HALF)(z1.v[0] + rp->one.v[0])) == rp->mod.v[0]) { - zsub(rp->mod, rp->one, &temp); - if (zcmp(z1, temp) == 0) { - if (zisodd(z2) ^ sign) { - *res = temp; - if (ztmp.len) - zfree(ztmp); - return; - } - zfree(temp); - zcopy(rp->one, res); - if (ztmp.len) - zfree(ztmp); - return; - } - zfree(temp); - } + /* + * See if the number being raised is the REDC format for -1. + * If so, then the answer is the REDC format for one or minus one. + * To do this check, calculate the REDC format for -1. + */ + if (((HALF)(z1.v[0] + rp->one.v[0])) == rp->mod.v[0]) { + zsub(rp->mod, rp->one, &temp); + if (zcmp(z1, temp) == 0) { + if (zisodd(z2) ^ sign) { + *res = temp; + if (ztmp.len) + zfree(ztmp); + return; + } + zfree(temp); + zcopy(rp->one, res); + if (ztmp.len) + zfree(ztmp); + return; + } + zfree(temp); + } - for (pp = &lowpowers[2]; pp < &lowpowers[POWNUMS]; pp++) - pp->len = 0; - zcopy(rp->one, &lowpowers[0]); - zcopy(z1, &lowpowers[1]); - zcopy(rp->one, &ans); + for (pp = &lowpowers[2]; pp < &lowpowers[POWNUMS]; pp++) + pp->len = 0; + zcopy(rp->one, &lowpowers[0]); + zcopy(z1, &lowpowers[1]); + zcopy(rp->one, &ans); - hp = &z2.v[z2.len - 1]; - curhalf = *hp; - curshift = BASEB - POWBITS; - while (curshift && ((curhalf >> curshift) == 0)) - curshift -= POWBITS; + hp = &z2.v[z2.len - 1]; + curhalf = *hp; + curshift = BASEB - POWBITS; + while (curshift && ((curhalf >> curshift) == 0)) + curshift -= POWBITS; - /* - * Calculate the result by examining the power POWBITS bits at a time, - * and use the table of low powers at each iteration. - */ - for (;;) { - curpow = (curhalf >> curshift) & (POWNUMS - 1); - pp = &lowpowers[curpow]; + /* + * Calculate the result by examining the power POWBITS bits at a time, + * and use the table of low powers at each iteration. + */ + for (;;) { + curpow = (curhalf >> curshift) & (POWNUMS - 1); + pp = &lowpowers[curpow]; - /* - * If the small power is not yet saved in the table, then - * calculate it and remember it in the table for future use. - */ - if (pp->len == 0) { - if (curpow & 0x1) - zcopy(z1, &modpow); - else - zcopy(rp->one, &modpow); + /* + * If the small power is not yet saved in the table, then + * calculate it and remember it in the table for future use. + */ + if (pp->len == 0) { + if (curpow & 0x1) + zcopy(z1, &modpow); + else + zcopy(rp->one, &modpow); - for (curbit = 0x2; curbit <= curpow; curbit *= 2) { - pp = &lowpowers[curbit]; - if (pp->len == 0) - zredcsquare(rp, lowpowers[curbit/2], - pp); - if (curbit & curpow) { - zredcmul(rp, *pp, modpow, &temp); - zfree(modpow); - modpow = temp; - } - } - pp = &lowpowers[curpow]; - if (pp->len > 0) { - zfree(*pp); - } - *pp = modpow; - } + for (curbit = 0x2; curbit <= curpow; curbit *= 2) { + pp = &lowpowers[curbit]; + if (pp->len == 0) + zredcsquare(rp, lowpowers[curbit/2], + pp); + if (curbit & curpow) { + zredcmul(rp, *pp, modpow, &temp); + zfree(modpow); + modpow = temp; + } + } + pp = &lowpowers[curpow]; + if (pp->len > 0) { + zfree(*pp); + } + *pp = modpow; + } - /* - * If the power is nonzero, then accumulate the small power - * into the result. - */ - if (curpow) { - zredcmul(rp, ans, *pp, &temp); - zfree(ans); - ans = temp; - } + /* + * If the power is nonzero, then accumulate the small power + * into the result. + */ + if (curpow) { + zredcmul(rp, ans, *pp, &temp); + zfree(ans); + ans = temp; + } - /* - * Select the next POWBITS bits of the power, if there is - * any more to generate. - */ - curshift -= POWBITS; - if (curshift < 0) { - if (hp-- == z2.v) - break; - curhalf = *hp; - curshift = BASEB - POWBITS; - } + /* + * Select the next POWBITS bits of the power, if there is + * any more to generate. + */ + curshift -= POWBITS; + if (curshift < 0) { + if (hp-- == z2.v) + break; + curhalf = *hp; + curshift = BASEB - POWBITS; + } - /* - * Square the result POWBITS times to make room for the next - * chunk of bits. - */ - for (i = 0; i < POWBITS; i++) { - zredcsquare(rp, ans, &temp); - zfree(ans); - ans = temp; - } - } + /* + * Square the result POWBITS times to make room for the next + * chunk of bits. + */ + for (i = 0; i < POWBITS; i++) { + zredcsquare(rp, ans, &temp); + zfree(ans); + ans = temp; + } + } - for (pp = lowpowers; pp < &lowpowers[POWNUMS]; pp++) { - zfree(*pp); - } - if (sign && !ziszero(ans)) { - zsub(rp->mod, ans, res); - zfree(ans); - } else { - *res = ans; - } - if (ztmp.len) - zfree(ztmp); + for (pp = lowpowers; pp < &lowpowers[POWNUMS]; pp++) { + zfree(*pp); + } + if (sign && !ziszero(ans)) { + zsub(rp->mod, ans, res); + zfree(ans); + } else { + *res = ans; + } + if (ztmp.len) + zfree(ztmp); } @@ -1961,316 +1961,316 @@ zredcpower(REDC *rp, ZVALUE z1, ZVALUE z2, ZVALUE *res) * * We compute v mod h*2^n+r, where h>0, n>0, abs(r) <= 1, as follows: * - * Let v = b*2^n + a, where 0 <= a < 2^n + * Let v = b*2^n + a, where 0 <= a < 2^n * - * Now v mod h*2^n+r == b*2^n + a mod h*2^n+r, - * and thus v mod h*2^n+r == b*2^n mod h*2^n+r + a mod h*2^n+r. + * Now v mod h*2^n+r == b*2^n + a mod h*2^n+r, + * and thus v mod h*2^n+r == b*2^n mod h*2^n+r + a mod h*2^n+r. * - * Because 0 <= a < 2^n < h*2^n+r, a mod h*2^n+r == a. - * Thus v mod h*2^n+r == b*2^n mod h*2^n+r + a. + * Because 0 <= a < 2^n < h*2^n+r, a mod h*2^n+r == a. + * Thus v mod h*2^n+r == b*2^n mod h*2^n+r + a. * - * It can be shown that b*2^n mod h*2^n == 2^n * (b mod h). + * It can be shown that b*2^n mod h*2^n == 2^n * (b mod h). * - * Thus for r == 0, v mod h*2^n+r == (2^n)*(b mod h) + a. + * Thus for r == 0, v mod h*2^n+r == (2^n)*(b mod h) + a. * - * It can be shown that v mod 2^n-1 == a+b mod 2^n-1. + * It can be shown that v mod 2^n-1 == a+b mod 2^n-1. * - * Thus for r == -1, v mod h*2^n+r == (2^n)*(b mod h) + a + int(b/h). + * Thus for r == -1, v mod h*2^n+r == (2^n)*(b mod h) + a + int(b/h). * - * It can be shown that v mod 2^n+1 == a-b mod 2^n+1. + * It can be shown that v mod 2^n+1 == a-b mod 2^n+1. * - * Thus for r == +1, v mod h*2^n+r == (2^n)*(b mod h) + a - int(b/h). + * Thus for r == +1, v mod h*2^n+r == (2^n)*(b mod h) + a - int(b/h). * - * Therefore, v mod h*2^n+r == (2^n)*(b mod h) + a - r*int(b/h). + * Therefore, v mod h*2^n+r == (2^n)*(b mod h) + a - r*int(b/h). * * The above proof leads to the following calc resource file which computes * the value z mod h*2^n+r: * * define hnrmod(v,h,n,r) * { - * local a,b,modulus,tquo,tmod,lbit,ret; + * local a,b,modulus,tquo,tmod,lbit,ret; * - * if (!isint(h) || h < 1) { - * quit "h must be an integer be > 0"; - * } - * if (!isint(n) || n < 1) { - * quit "n must be an integer be > 0"; - * } - * if (r != 1 && r != 0 && r != -1) { - * quit "r must be -1, 0 or 1"; - * } + * if (!isint(h) || h < 1) { + * quit "h must be an integer be > 0"; + * } + * if (!isint(n) || n < 1) { + * quit "n must be an integer be > 0"; + * } + * if (r != 1 && r != 0 && r != -1) { + * quit "r must be -1, 0 or 1"; + * } * - * lbit = lowbit(h); - * if (lbit > 0) { - * n += lbit; - * h >>= lbit; - * } + * lbit = lowbit(h); + * if (lbit > 0) { + * n += lbit; + * h >>= lbit; + * } * - * modulus = h<>n; - * a = ret - (b<>n; + * a = ret - (b< b) ? a-b : modulus+a-b); - * } else { - * quomod(b, h, tquo, tmod); - * tmod = tmod<= tquo) ? tmod-tquo : modulus+tmod-tquo); - * } - * break; - * } - * } while (ret > modulus); - * ret = ((ret < 0) ? ret+modulus : ((ret == modulus) ? 0 : ret)); + * switch (r) { + * case -1: + * if (h == 1) { + * ret = a + b; + * } else { + * quomod(b, h, tquo, tmod); + * ret = tmod< b) ? a-b : modulus+a-b); + * } else { + * quomod(b, h, tquo, tmod); + * tmod = tmod<= tquo) ? tmod-tquo : modulus+tmod-tquo); + * } + * break; + * } + * } while (ret > modulus); + * ret = ((ret < 0) ? ret+modulus : ((ret == modulus) ? 0 : ret)); * - * return ret; + * return ret; * } * * This function implements the above calc resource file. * * given: - * v take mod of this value, v >= 0 - * zh h from modulus h*2^n+r, h > 0 - * zn n from modulus h*2^n+r, n > 0 - * zr r from modulus h*2^n+r, abs(r) <= 1 - * res v mod h*2^n+r + * v take mod of this value, v >= 0 + * zh h from modulus h*2^n+r, h > 0 + * zn n from modulus h*2^n+r, n > 0 + * zr r from modulus h*2^n+r, abs(r) <= 1 + * res v mod h*2^n+r */ void zhnrmod(ZVALUE v, ZVALUE zh, ZVALUE zn, ZVALUE zr, ZVALUE *res) { - ZVALUE a; /* lower n bits of v */ - ZVALUE b; /* bits above the lower n bits of v */ - ZVALUE h; /* working zh value */ - ZVALUE modulus; /* h^2^n + r */ - ZVALUE tquo; /* b // h */ - ZVALUE tmod; /* b % h or (b%h)< h == 1, 0 => h != 1 */ + ZVALUE a; /* lower n bits of v */ + ZVALUE b; /* bits above the lower n bits of v */ + ZVALUE h; /* working zh value */ + ZVALUE modulus; /* h^2^n + r */ + ZVALUE tquo; /* b // h */ + ZVALUE tmod; /* b % h or (b%h)< h == 1, 0 => h != 1 */ - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - /* - * firewall - */ - if (zisneg(zh) || ziszero(zh)) { - math_error("h must be > 0"); - not_reached(); - } - if (zisneg(zn) || ziszero(zn)) { - math_error("n must be > 0"); - not_reached(); - } - if (zge31b(zn)) { - math_error("n must be < 2^31"); - not_reached(); - } - if (!zisabsleone(zr)) { - math_error("r must be -1, 0 or 1"); - not_reached(); - } + /* + * firewall + */ + if (zisneg(zh) || ziszero(zh)) { + math_error("h must be > 0"); + not_reached(); + } + if (zisneg(zn) || ziszero(zn)) { + math_error("n must be > 0"); + not_reached(); + } + if (zge31b(zn)) { + math_error("n must be < 2^31"); + not_reached(); + } + if (!zisabsleone(zr)) { + math_error("r must be -1, 0 or 1"); + not_reached(); + } - /* - * setup for loop - */ - n = ztolong(zn); - r = ztolong(zr); - if (zisneg(zr)) { - r = -r; - } - /* lbit = lowbit(h); */ - lbit = zlowbit(zh); - /* if (lbit > 0) { n += lbit; h >>= lbit; } */ - if (lbit > 0) { - n += lbit; - zshift(zh, -lbit, &h); - } else { - h = zh; - } - /* modulus = h< 0) { - zfree(h); - } - return; - } - /* ret = v; */ - zcopy(v, &ret); + /* + * setup for loop + */ + n = ztolong(zn); + r = ztolong(zr); + if (zisneg(zr)) { + r = -r; + } + /* lbit = lowbit(h); */ + lbit = zlowbit(zh); + /* if (lbit > 0) { n += lbit; h >>= lbit; } */ + if (lbit > 0) { + n += lbit; + zshift(zh, -lbit, &h); + } else { + h = zh; + } + /* modulus = h< 0) { + zfree(h); + } + return; + } + /* ret = v; */ + zcopy(v, &ret); - /* - * shift-add modulus loop - */ - hisone = zisone(h); - do { + /* + * shift-add modulus loop + */ + hisone = zisone(h); + do { - /* - * split ret into to chunks, the lower n bits - * and everything above the lower n bits - */ - /* if (highbit(ret) < n) { break; } */ - hbit = (long)zhighbit(ret); - if (hbit < n) { - zrelval = (zcmp(ret, modulus) ? -1 : 0); - break; - } - /* b = ret>>n; */ - zshift(ret, -n, &b); - b.sign = ret.sign; - /* a = ret - (b<>n; */ + zshift(ret, -n, &b); + b.sign = ret.sign; + /* a = ret - (b< modulus); */ - } while ((zrelval = zabsrel(ret, modulus)) > 0); - /* ret = ((ret < 0) ? ret+modulus : ((ret == modulus) ? 0 : ret)); */ - if (ret.sign) { - zadd(ret, modulus, &t); - zfree(ret); - ret = t; - } else if (zrelval == 0) { - zfree(ret); - ret = _zero_; - } - zfree(modulus); - if (lbit > 0) { - zfree(h); - } + /* ... while (abs(ret) > modulus); */ + } while ((zrelval = zabsrel(ret, modulus)) > 0); + /* ret = ((ret < 0) ? ret+modulus : ((ret == modulus) ? 0 : ret)); */ + if (ret.sign) { + zadd(ret, modulus, &t); + zfree(ret); + ret = t; + } else if (zrelval == 0) { + zfree(ret); + ret = _zero_; + } + zfree(modulus); + if (lbit > 0) { + zfree(h); + } - /* - * return ret - */ - *res = ret; - return; + /* + * return ret + */ + *res = ret; + return; } diff --git a/zmul.c b/zmul.c index cbbee36..e755475 100644 --- a/zmul.c +++ b/zmul.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,10 +17,10 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1991/01/09 20:01:31 - * File existed as early as: 1991 + * Under source code control: 1991/01/09 20:01:31 + * File existed as early as: 1991 * - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -38,10 +38,10 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ -STATIC HALF *tempbuf; /* temporary buffer for multiply and square */ +STATIC HALF *tempbuf; /* temporary buffer for multiply and square */ S_FUNC LEN domul(HALF *v1, LEN size1, HALF *v2, LEN size2, HALF *ans); S_FUNC LEN dosquare(HALF *vp, LEN size, HALF *ans); @@ -49,54 +49,54 @@ S_FUNC LEN dosquare(HALF *vp, LEN size, HALF *ans); /* * Multiply two numbers using the following formula recursively: - * (A*S+B)*(C*S+D) = (S^2+S)*A*C + S*(A-B)*(D-C) + (S+1)*B*D + * (A*S+B)*(C*S+D) = (S^2+S)*A*C + S*(A-B)*(D-C) + (S+1)*B*D * where S is a power of 2^16, and so multiplies by it are shifts, and * A,B,C,D are the left and right HALFs of the numbers to be multiplied. * * given: - * z1 numbers to multiply - * z2 numbers to multiply - * res result of multiplication + * z1 numbers to multiply + * z2 numbers to multiply + * res result of multiplication */ void zmul(ZVALUE z1, ZVALUE z2, ZVALUE *res) { - LEN len; /* size of array */ + LEN len; /* size of array */ - if (ziszero(z1) || ziszero(z2)) { - *res = _zero_; - return; - } - if (zisunit(z1)) { - zcopy(z2, res); - res->sign = (z1.sign != z2.sign); - return; - } - if (zisunit(z2)) { - zcopy(z1, res); - res->sign = (z1.sign != z2.sign); - return; - } + if (ziszero(z1) || ziszero(z2)) { + *res = _zero_; + return; + } + if (zisunit(z1)) { + zcopy(z2, res); + res->sign = (z1.sign != z2.sign); + return; + } + if (zisunit(z2)) { + zcopy(z1, res); + res->sign = (z1.sign != z2.sign); + return; + } - /* - * Allocate a temporary buffer for the recursion levels to use. - * An array needs to be allocated large enough for all of the - * temporary results to fit in. This size is about twice the size - * of the largest original number, since each recursion level uses - * the size of its given number, and whose size is 1/2 the size of - * the previous level. The sum of the infinite series is 2. - * Add some extra words because of rounding when dividing by 2 - * and also because of the extra word that each multiply needs. - */ - len = z1.len; - if (len < z2.len) - len = z2.len; - len = 2 * len + 64; - tempbuf = zalloctemp(len); + /* + * Allocate a temporary buffer for the recursion levels to use. + * An array needs to be allocated large enough for all of the + * temporary results to fit in. This size is about twice the size + * of the largest original number, since each recursion level uses + * the size of its given number, and whose size is 1/2 the size of + * the previous level. The sum of the infinite series is 2. + * Add some extra words because of rounding when dividing by 2 + * and also because of the extra word that each multiply needs. + */ + len = z1.len; + if (len < z2.len) + len = z2.len; + len = 2 * len + 64; + tempbuf = zalloctemp(len); - res->sign = (z1.sign != z2.sign); - res->v = alloc(z1.len + z2.len + 2); - res->len = domul(z1.v, z1.len, z2.v, z2.len, res->v); + res->sign = (z1.sign != z2.sign); + res->v = alloc(z1.len + z2.len + 2); + res->len = domul(z1.v, z1.len, z2.v, z2.len, res->v); } @@ -110,601 +110,601 @@ zmul(ZVALUE z1, ZVALUE z2, ZVALUE *res) * one more than the size of the number at the top level recursive call. * * given: - * v1 first number - * size1 size of first number - * v2 second number - * size2 size of second number - * ans location for result + * v1 first number + * size1 size of first number + * v2 second number + * size2 size of second number + * ans location for result */ S_FUNC LEN domul(HALF *v1, LEN size1, HALF *v2, LEN size2, HALF *ans) { - LEN shift; /* amount numbers are shifted by */ - LEN sizeA; /* size of left half of first number */ - LEN sizeB; /* size of right half of first number */ - LEN sizeC; /* size of left half of second number */ - LEN sizeD; /* size of right half of second number */ - LEN sizeAB; /* size of subtraction of A and B */ - LEN sizeDC; /* size of subtraction of D and C */ - LEN sizeABDC; /* size of product of above two results */ - LEN subsize; /* size of difference of HALFs */ - LEN copysize; /* size of number left to copy */ - LEN sizetotal; /* total size of product */ - LEN len; /* temporary length */ - HALF *baseA; /* base of left half of first number */ - HALF *baseB; /* base of right half of first number */ - HALF *baseC; /* base of left half of second number */ - HALF *baseD; /* base of right half of second number */ - HALF *baseAB; /* base of result of subtraction of A and B */ - HALF *baseDC; /* base of result of subtraction of D and C */ - HALF *baseABDC; /* base of product of above two results */ - HALF *baseAC; /* base of product of A and C */ - HALF *baseBD; /* base of product of B and D */ - FULL carry; /* carry digit for small multiplications */ - FULL carryACBD; /* carry from addition of A*C and B*D */ - FULL digit; /* single digit multiplying by */ - HALF *temp; /* base for temporary calculations */ - bool neg; /* whether intermediate term is negative */ - register HALF *hd, *h1=NULL, *h2=NULL; /* for inner loops */ - SIUNION sival; /* for addition of digits */ + LEN shift; /* amount numbers are shifted by */ + LEN sizeA; /* size of left half of first number */ + LEN sizeB; /* size of right half of first number */ + LEN sizeC; /* size of left half of second number */ + LEN sizeD; /* size of right half of second number */ + LEN sizeAB; /* size of subtraction of A and B */ + LEN sizeDC; /* size of subtraction of D and C */ + LEN sizeABDC; /* size of product of above two results */ + LEN subsize; /* size of difference of HALFs */ + LEN copysize; /* size of number left to copy */ + LEN sizetotal; /* total size of product */ + LEN len; /* temporary length */ + HALF *baseA; /* base of left half of first number */ + HALF *baseB; /* base of right half of first number */ + HALF *baseC; /* base of left half of second number */ + HALF *baseD; /* base of right half of second number */ + HALF *baseAB; /* base of result of subtraction of A and B */ + HALF *baseDC; /* base of result of subtraction of D and C */ + HALF *baseABDC; /* base of product of above two results */ + HALF *baseAC; /* base of product of A and C */ + HALF *baseBD; /* base of product of B and D */ + FULL carry; /* carry digit for small multiplications */ + FULL carryACBD; /* carry from addition of A*C and B*D */ + FULL digit; /* single digit multiplying by */ + HALF *temp; /* base for temporary calculations */ + bool neg; /* whether intermediate term is negative */ + register HALF *hd, *h1=NULL, *h2=NULL; /* for inner loops */ + SIUNION sival; /* for addition of digits */ - /* firewall */ - if (v1 == NULL) { - math_error("%s: v1 NULL", __func__); - not_reached(); - } - if (ans == NULL) { - math_error("%s: ans NULL", __func__); - not_reached(); - } + /* firewall */ + if (v1 == NULL) { + math_error("%s: v1 NULL", __func__); + not_reached(); + } + if (ans == NULL) { + math_error("%s: ans NULL", __func__); + not_reached(); + } - /* - * Trim the numbers of leading zeroes and initialize the - * estimated size of the result. - */ - hd = &v1[size1 - 1]; - while ((*hd == 0) && (size1 > 1)) { - hd--; - size1--; - } - hd = &v2[size2 - 1]; - while ((*hd == 0) && (size2 > 1)) { - hd--; - size2--; - } - sizetotal = size1 + size2; + /* + * Trim the numbers of leading zeroes and initialize the + * estimated size of the result. + */ + hd = &v1[size1 - 1]; + while ((*hd == 0) && (size1 > 1)) { + hd--; + size1--; + } + hd = &v2[size2 - 1]; + while ((*hd == 0) && (size2 > 1)) { + hd--; + size2--; + } + sizetotal = size1 + size2; - /* - * First check for zero answer. - */ - if (((size1 == 1) && (*v1 == 0)) || ((size2 == 1) && (*v2 == 0))) { - *ans = 0; - return 1; - } + /* + * First check for zero answer. + */ + if (((size1 == 1) && (*v1 == 0)) || ((size2 == 1) && (*v2 == 0))) { + *ans = 0; + return 1; + } - /* - * Exchange the two numbers if necessary to make the number of - * digits of the first number be greater than or equal to the - * second number. - */ - if (size1 < size2) { - len = size1; size1 = size2; size2 = len; - hd = v1; v1 = v2; v2 = hd; - } + /* + * Exchange the two numbers if necessary to make the number of + * digits of the first number be greater than or equal to the + * second number. + */ + if (size1 < size2) { + len = size1; size1 = size2; size2 = len; + hd = v1; v1 = v2; v2 = hd; + } - /* - * If the smaller number has only a few digits, then calculate - * the result in the normal manner in order to avoid the overhead - * of the recursion for small numbers. The number of digits where - * the algorithm changes is settable from 2 to maxint. - */ - if (size2 < conf->mul2) { - /* - * First clear the top part of the result, and then multiply - * by the lowest digit to get the first partial sum. Later - * products will then add into this result. - */ - hd = &ans[size1]; - len = size2; - while (len--) - *hd++ = 0; + /* + * If the smaller number has only a few digits, then calculate + * the result in the normal manner in order to avoid the overhead + * of the recursion for small numbers. The number of digits where + * the algorithm changes is settable from 2 to maxint. + */ + if (size2 < conf->mul2) { + /* + * First clear the top part of the result, and then multiply + * by the lowest digit to get the first partial sum. Later + * products will then add into this result. + */ + hd = &ans[size1]; + len = size2; + while (len--) + *hd++ = 0; - digit = *v2++; - h1 = v1; - hd = ans; - carry = 0; - len = size1; - while (len >= 4) { /* expand the loop some */ - len -= 4; - sival.ivalue = ((FULL) *h1++) * digit + carry; - /* ignore Saber-C warning #112 - get ushort from uint */ - /* OK to ignore on name domul`sival */ - *hd++ = sival.silow; - carry = sival.sihigh; - sival.ivalue = ((FULL) *h1++) * digit + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - sival.ivalue = ((FULL) *h1++) * digit + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - sival.ivalue = ((FULL) *h1++) * digit + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } - while (len--) { - sival.ivalue = ((FULL) *h1++) * digit + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } - *hd = (HALF)carry; + digit = *v2++; + h1 = v1; + hd = ans; + carry = 0; + len = size1; + while (len >= 4) { /* expand the loop some */ + len -= 4; + sival.ivalue = ((FULL) *h1++) * digit + carry; + /* ignore Saber-C warning #112 - get ushort from uint */ + /* OK to ignore on name domul`sival */ + *hd++ = sival.silow; + carry = sival.sihigh; + sival.ivalue = ((FULL) *h1++) * digit + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + sival.ivalue = ((FULL) *h1++) * digit + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + sival.ivalue = ((FULL) *h1++) * digit + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } + while (len--) { + sival.ivalue = ((FULL) *h1++) * digit + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } + *hd = (HALF)carry; - /* - * Now multiply by the remaining digits of the second number, - * adding each product into the final result. - */ - h2 = ans; - while (--size2 > 0) { - digit = *v2++; - h1 = v1; - hd = ++h2; - if (digit == 0) - continue; - carry = 0; - len = size1; - while (len >= 4) { /* expand the loop some */ - len -= 4; - sival.ivalue = ((FULL) *h1++) * digit - + ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - sival.ivalue = ((FULL) *h1++) * digit - + ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - sival.ivalue = ((FULL) *h1++) * digit - + ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - sival.ivalue = ((FULL) *h1++) * digit - + ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } - while (len--) { - sival.ivalue = ((FULL) *h1++) * digit - + ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } - while (carry) { - sival.ivalue = ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } - } + /* + * Now multiply by the remaining digits of the second number, + * adding each product into the final result. + */ + h2 = ans; + while (--size2 > 0) { + digit = *v2++; + h1 = v1; + hd = ++h2; + if (digit == 0) + continue; + carry = 0; + len = size1; + while (len >= 4) { /* expand the loop some */ + len -= 4; + sival.ivalue = ((FULL) *h1++) * digit + + ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + sival.ivalue = ((FULL) *h1++) * digit + + ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + sival.ivalue = ((FULL) *h1++) * digit + + ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + sival.ivalue = ((FULL) *h1++) * digit + + ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } + while (len--) { + sival.ivalue = ((FULL) *h1++) * digit + + ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } + while (carry) { + sival.ivalue = ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } + } - /* - * Now return the true size of the number. - */ - len = sizetotal; - hd = &ans[len - 1]; - while ((*hd == 0) && (len > 1)) { - hd--; - len--; - } - return len; - } + /* + * Now return the true size of the number. + */ + len = sizetotal; + hd = &ans[len - 1]; + while ((*hd == 0) && (len > 1)) { + hd--; + len--; + } + return len; + } - /* - * Need to multiply by a large number. - * Allocate temporary space for calculations, and calculate the - * value for the shift. The shift value is 1/2 the size of the - * larger (first) number (rounded up). The amount of temporary - * space needed is twice the size of the shift, plus one more word - * for the multiply to use. - */ - shift = (size1 + 1) / 2; - temp = tempbuf; - tempbuf += (2 * shift) + 1; + /* + * Need to multiply by a large number. + * Allocate temporary space for calculations, and calculate the + * value for the shift. The shift value is 1/2 the size of the + * larger (first) number (rounded up). The amount of temporary + * space needed is twice the size of the shift, plus one more word + * for the multiply to use. + */ + shift = (size1 + 1) / 2; + temp = tempbuf; + tempbuf += (2 * shift) + 1; - /* - * Determine the sizes and locations of all the numbers. - * The value of sizeC can be negative, and this is checked later. - * The value of sizeD is limited by the full size of the number. - */ - baseA = v1 + shift; - baseB = v1; - baseC = v2 + ((shift <= size2) ? shift : size2); - baseD = v2; - baseAB = ans; - baseDC = ans + shift; - baseAC = ans + shift * 2; - baseBD = ans; + /* + * Determine the sizes and locations of all the numbers. + * The value of sizeC can be negative, and this is checked later. + * The value of sizeD is limited by the full size of the number. + */ + baseA = v1 + shift; + baseB = v1; + baseC = v2 + ((shift <= size2) ? shift : size2); + baseD = v2; + baseAB = ans; + baseDC = ans + shift; + baseAC = ans + shift * 2; + baseBD = ans; - sizeA = size1 - shift; - sizeC = size2 - shift; + sizeA = size1 - shift; + sizeC = size2 - shift; - sizeB = shift; - hd = &baseB[shift - 1]; - while ((*hd == 0) && (sizeB > 1)) { - hd--; - sizeB--; - } + sizeB = shift; + hd = &baseB[shift - 1]; + while ((*hd == 0) && (sizeB > 1)) { + hd--; + sizeB--; + } - sizeD = shift; - if (sizeD > size2) - sizeD = size2; - hd = &baseD[sizeD - 1]; - while ((*hd == 0) && (sizeD > 1)) { - hd--; - sizeD--; - } + sizeD = shift; + if (sizeD > size2) + sizeD = size2; + hd = &baseD[sizeD - 1]; + while ((*hd == 0) && (sizeD > 1)) { + hd--; + sizeD--; + } - /* - * If the smaller number has a high half of zero, then calculate - * the result by breaking up the first number into two numbers - * and combining the results using the obvious formula: - * (A*S+B) * D = (A*D)*S + B*D - */ - if (sizeC <= 0) { - len = domul(baseB, sizeB, baseD, sizeD, ans); - hd = &ans[len]; - len = sizetotal - len; - while (len--) - *hd++ = 0; + /* + * If the smaller number has a high half of zero, then calculate + * the result by breaking up the first number into two numbers + * and combining the results using the obvious formula: + * (A*S+B) * D = (A*D)*S + B*D + */ + if (sizeC <= 0) { + len = domul(baseB, sizeB, baseD, sizeD, ans); + hd = &ans[len]; + len = sizetotal - len; + while (len--) + *hd++ = 0; - /* - * Add the second number into the first number, shifted - * over at the correct position. - */ - len = domul(baseA, sizeA, baseD, sizeD, temp); - h1 = temp; - hd = ans + shift; - carry = 0; - while (len--) { - sival.ivalue = ((FULL) *h1++) + ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } - while (carry) { - sival.ivalue = ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } + /* + * Add the second number into the first number, shifted + * over at the correct position. + */ + len = domul(baseA, sizeA, baseD, sizeD, temp); + h1 = temp; + hd = ans + shift; + carry = 0; + while (len--) { + sival.ivalue = ((FULL) *h1++) + ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } + while (carry) { + sival.ivalue = ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } - /* - * Determine the final size of the number and return it. - */ - len = sizetotal; - hd = &ans[len - 1]; - while ((*hd == 0) && (len > 1)) { - hd--; - len--; - } - tempbuf = temp; - return len; - } + /* + * Determine the final size of the number and return it. + */ + len = sizetotal; + hd = &ans[len - 1]; + while ((*hd == 0) && (len > 1)) { + hd--; + len--; + } + tempbuf = temp; + return len; + } - /* - * Now we know that the high HALFs of the numbers are nonzero, - * so we can use the complete formula. - * (A*S+B)*(C*S+D) = (S^2+S)*A*C + S*(A-B)*(D-C) + (S+1)*B*D. - * The steps are done in the following order: - * A-B - * D-C - * (A-B)*(D-C) - * S^2*A*C + B*D - * (S^2+S)*A*C + (S+1)*B*D (*) - * (S^2+S)*A*C + S*(A-B)*(D-C) + (S+1)*B*D - * - * Note: step (*) above can produce a result which is larger than - * the final product will be, and this is where the extra word - * needed in the product comes from. After the final subtraction is - * done, the result fits in the expected size. Using the extra word - * is easier than suppressing the carries and borrows everywhere. - * - * Begin by forming the product (A-B)*(D-C) into a temporary - * location that we save until the final step. Do each subtraction - * at positions 0 and S. Be very careful about the relative sizes - * of the numbers since this result can be negative. For the first - * step calculate the absolute difference of A and B into a temporary - * location at position 0 of the result. Negate the sign if A is - * smaller than B. - */ - neg = false; - if (sizeA == sizeB) { - len = sizeA; - h1 = &baseA[len - 1]; - h2 = &baseB[len - 1]; - while ((len > 1) && (*h1 == *h2)) { - len--; - h1--; - h2--; - } - } - if ((sizeA > sizeB) || ((sizeA == sizeB) && h1 && h2 && (*h1 > *h2))) { - h1 = baseA; - h2 = baseB; - sizeAB = sizeA; - subsize = sizeB; - } else { - neg = !neg; - h1 = baseB; - h2 = baseA; - sizeAB = sizeB; - subsize = sizeA; - } - copysize = sizeAB - subsize; + /* + * Now we know that the high HALFs of the numbers are nonzero, + * so we can use the complete formula. + * (A*S+B)*(C*S+D) = (S^2+S)*A*C + S*(A-B)*(D-C) + (S+1)*B*D. + * The steps are done in the following order: + * A-B + * D-C + * (A-B)*(D-C) + * S^2*A*C + B*D + * (S^2+S)*A*C + (S+1)*B*D (*) + * (S^2+S)*A*C + S*(A-B)*(D-C) + (S+1)*B*D + * + * Note: step (*) above can produce a result which is larger than + * the final product will be, and this is where the extra word + * needed in the product comes from. After the final subtraction is + * done, the result fits in the expected size. Using the extra word + * is easier than suppressing the carries and borrows everywhere. + * + * Begin by forming the product (A-B)*(D-C) into a temporary + * location that we save until the final step. Do each subtraction + * at positions 0 and S. Be very careful about the relative sizes + * of the numbers since this result can be negative. For the first + * step calculate the absolute difference of A and B into a temporary + * location at position 0 of the result. Negate the sign if A is + * smaller than B. + */ + neg = false; + if (sizeA == sizeB) { + len = sizeA; + h1 = &baseA[len - 1]; + h2 = &baseB[len - 1]; + while ((len > 1) && (*h1 == *h2)) { + len--; + h1--; + h2--; + } + } + if ((sizeA > sizeB) || ((sizeA == sizeB) && h1 && h2 && (*h1 > *h2))) { + h1 = baseA; + h2 = baseB; + sizeAB = sizeA; + subsize = sizeB; + } else { + neg = !neg; + h1 = baseB; + h2 = baseA; + sizeAB = sizeB; + subsize = sizeA; + } + copysize = sizeAB - subsize; - hd = baseAB; - carry = 0; - while (subsize--) { - sival.ivalue = BASE1 - ((FULL) *h1++) + ((FULL) *h2++) + carry; - *hd++ = (HALF)(BASE1 - sival.silow); - carry = sival.sihigh; - } - while (copysize--) { - sival.ivalue = (BASE1 - ((FULL) *h1++)) + carry; - *hd++ = (HALF)(BASE1 - sival.silow); - carry = sival.sihigh; - } + hd = baseAB; + carry = 0; + while (subsize--) { + sival.ivalue = BASE1 - ((FULL) *h1++) + ((FULL) *h2++) + carry; + *hd++ = (HALF)(BASE1 - sival.silow); + carry = sival.sihigh; + } + while (copysize--) { + sival.ivalue = (BASE1 - ((FULL) *h1++)) + carry; + *hd++ = (HALF)(BASE1 - sival.silow); + carry = sival.sihigh; + } - hd = &baseAB[sizeAB - 1]; - while ((*hd == 0) && (sizeAB > 1)) { - hd--; - sizeAB--; - } + hd = &baseAB[sizeAB - 1]; + while ((*hd == 0) && (sizeAB > 1)) { + hd--; + sizeAB--; + } - /* - * This completes the calculation of abs(A-B). For the next step - * calculate the absolute difference of D and C into a temporary - * location at position S of the result. Negate the sign if C is - * larger than D. - */ - if (sizeC == sizeD) { - len = sizeC; - h1 = &baseC[len - 1]; - h2 = &baseD[len - 1]; - while ((len > 1) && (*h1 == *h2)) { - len--; - h1--; - h2--; - } - } - if ((sizeC > sizeD) || ((sizeC == sizeD) && (*h1 > *h2))) { - neg = !neg; - h1 = baseC; - h2 = baseD; - sizeDC = sizeC; - subsize = sizeD; - } else { - h1 = baseD; - h2 = baseC; - sizeDC = sizeD; - subsize = sizeC; - } - copysize = sizeDC - subsize; + /* + * This completes the calculation of abs(A-B). For the next step + * calculate the absolute difference of D and C into a temporary + * location at position S of the result. Negate the sign if C is + * larger than D. + */ + if (sizeC == sizeD) { + len = sizeC; + h1 = &baseC[len - 1]; + h2 = &baseD[len - 1]; + while ((len > 1) && (*h1 == *h2)) { + len--; + h1--; + h2--; + } + } + if ((sizeC > sizeD) || ((sizeC == sizeD) && (*h1 > *h2))) { + neg = !neg; + h1 = baseC; + h2 = baseD; + sizeDC = sizeC; + subsize = sizeD; + } else { + h1 = baseD; + h2 = baseC; + sizeDC = sizeD; + subsize = sizeC; + } + copysize = sizeDC - subsize; - hd = baseDC; - carry = 0; - while (subsize--) { - sival.ivalue = BASE1 - ((FULL) *h1++) + ((FULL) *h2++) + carry; - *hd++ = (HALF)(BASE1 - sival.silow); - carry = sival.sihigh; - } - while (copysize--) { - sival.ivalue = (BASE1 - ((FULL) *h1++)) + carry; - *hd++ = (HALF)(BASE1 - sival.silow); - carry = sival.sihigh; - } - hd = &baseDC[sizeDC - 1]; - while ((*hd == 0) && (sizeDC > 1)) { - hd--; - sizeDC--; - } + hd = baseDC; + carry = 0; + while (subsize--) { + sival.ivalue = BASE1 - ((FULL) *h1++) + ((FULL) *h2++) + carry; + *hd++ = (HALF)(BASE1 - sival.silow); + carry = sival.sihigh; + } + while (copysize--) { + sival.ivalue = (BASE1 - ((FULL) *h1++)) + carry; + *hd++ = (HALF)(BASE1 - sival.silow); + carry = sival.sihigh; + } + hd = &baseDC[sizeDC - 1]; + while ((*hd == 0) && (sizeDC > 1)) { + hd--; + sizeDC--; + } - /* - * This completes the calculation of abs(D-C). Now multiply - * together abs(A-B) and abs(D-C) into a temporary location, - * which is preserved until the final steps. - */ - baseABDC = temp; - sizeABDC = domul(baseAB, sizeAB, baseDC, sizeDC, baseABDC); + /* + * This completes the calculation of abs(D-C). Now multiply + * together abs(A-B) and abs(D-C) into a temporary location, + * which is preserved until the final steps. + */ + baseABDC = temp; + sizeABDC = domul(baseAB, sizeAB, baseDC, sizeDC, baseABDC); - /* - * Now calculate B*D and A*C into one of their two final locations. - * Make sure the high order digits of the products are zeroed since - * this initializes the final result. Be careful about this zeroing - * since the size of the high order words might be smaller than - * the shift size. Do B*D first since the multiplies use one more - * word than the size of the product. Also zero the final extra - * word in the result for possible carries to use. - */ - len = domul(baseB, sizeB, baseD, sizeD, baseBD); - hd = &baseBD[len]; - len = shift * 2 - len; - while (len--) - *hd++ = 0; + /* + * Now calculate B*D and A*C into one of their two final locations. + * Make sure the high order digits of the products are zeroed since + * this initializes the final result. Be careful about this zeroing + * since the size of the high order words might be smaller than + * the shift size. Do B*D first since the multiplies use one more + * word than the size of the product. Also zero the final extra + * word in the result for possible carries to use. + */ + len = domul(baseB, sizeB, baseD, sizeD, baseBD); + hd = &baseBD[len]; + len = shift * 2 - len; + while (len--) + *hd++ = 0; - len = domul(baseA, sizeA, baseC, sizeC, baseAC); - hd = &baseAC[len]; - len = sizetotal - shift * 2 - len + 1; - while (len--) - *hd++ = 0; + len = domul(baseA, sizeA, baseC, sizeC, baseAC); + hd = &baseAC[len]; + len = sizetotal - shift * 2 - len + 1; + while (len--) + *hd++ = 0; - /* - * Now add in A*C and B*D into themselves at the other shifted - * position that they need. This addition is tricky in order to - * make sure that the two additions cannot interfere with each other. - * Therefore we first add in the top half of B*D and the lower half - * of A*C. The sources and destinations of these two additions - * overlap, and so the same answer results from the two additions, - * thus only two pointers suffice for both additions. Keep the - * final carry from these additions for later use since we cannot - * afford to change the top half of A*C yet. - */ - h1 = baseBD + shift; - h2 = baseAC; - carryACBD = 0; - len = shift; - while (len--) { - sival.ivalue = ((FULL) *h1) + ((FULL) *h2) + carryACBD; - *h1++ = sival.silow; - *h2++ = sival.silow; - carryACBD = sival.sihigh; - } + /* + * Now add in A*C and B*D into themselves at the other shifted + * position that they need. This addition is tricky in order to + * make sure that the two additions cannot interfere with each other. + * Therefore we first add in the top half of B*D and the lower half + * of A*C. The sources and destinations of these two additions + * overlap, and so the same answer results from the two additions, + * thus only two pointers suffice for both additions. Keep the + * final carry from these additions for later use since we cannot + * afford to change the top half of A*C yet. + */ + h1 = baseBD + shift; + h2 = baseAC; + carryACBD = 0; + len = shift; + while (len--) { + sival.ivalue = ((FULL) *h1) + ((FULL) *h2) + carryACBD; + *h1++ = sival.silow; + *h2++ = sival.silow; + carryACBD = sival.sihigh; + } - /* - * Now add in the bottom half of B*D and the top half of A*C. - * These additions are straightforward, except that A*C should - * be done first because of possible carries from B*D, and the - * top half of A*C might not exist. Add in one of the carries - * from the previous addition while we are at it. - */ - h1 = baseAC + shift; - hd = baseAC; - carry = carryACBD; - len = sizetotal - 3 * shift; - while (len--) { - sival.ivalue = ((FULL) *h1++) + ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } - while (carry) { - sival.ivalue = ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } + /* + * Now add in the bottom half of B*D and the top half of A*C. + * These additions are straightforward, except that A*C should + * be done first because of possible carries from B*D, and the + * top half of A*C might not exist. Add in one of the carries + * from the previous addition while we are at it. + */ + h1 = baseAC + shift; + hd = baseAC; + carry = carryACBD; + len = sizetotal - 3 * shift; + while (len--) { + sival.ivalue = ((FULL) *h1++) + ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } + while (carry) { + sival.ivalue = ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } - h1 = baseBD; - hd = baseBD + shift; - carry = 0; - len = shift; - while (len--) { - sival.ivalue = ((FULL) *h1++) + ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } - while (carry) { - sival.ivalue = ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } + h1 = baseBD; + hd = baseBD + shift; + carry = 0; + len = shift; + while (len--) { + sival.ivalue = ((FULL) *h1++) + ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } + while (carry) { + sival.ivalue = ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } - /* - * Now finally add in the other delayed carry from the - * above addition. - */ - hd = baseAC + shift; - while (carryACBD) { - sival.ivalue = ((FULL) *hd) + carryACBD; - *hd++ = sival.silow; - carryACBD = sival.sihigh; - } + /* + * Now finally add in the other delayed carry from the + * above addition. + */ + hd = baseAC + shift; + while (carryACBD) { + sival.ivalue = ((FULL) *hd) + carryACBD; + *hd++ = sival.silow; + carryACBD = sival.sihigh; + } - /* - * Now finally add or subtract (A-B)*(D-C) into the final result at - * the correct position (S), according to whether it is positive or - * negative. When subtracting, the answer cannot go negative. - */ - h1 = baseABDC; - hd = ans + shift; - carry = 0; - len = sizeABDC; - if (neg) { - while (len--) { - sival.ivalue = BASE1 - ((FULL) *hd) + - ((FULL) *h1++) + carry; - *hd++ = (HALF)(BASE1 - sival.silow); - carry = sival.sihigh; - } - while (carry) { - sival.ivalue = BASE1 - ((FULL) *hd) + carry; - *hd++ = (HALF)(BASE1 - sival.silow); - carry = sival.sihigh; - } - } else { - while (len--) { - sival.ivalue = ((FULL) *h1++) + ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } - while (carry) { - sival.ivalue = ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } - } + /* + * Now finally add or subtract (A-B)*(D-C) into the final result at + * the correct position (S), according to whether it is positive or + * negative. When subtracting, the answer cannot go negative. + */ + h1 = baseABDC; + hd = ans + shift; + carry = 0; + len = sizeABDC; + if (neg) { + while (len--) { + sival.ivalue = BASE1 - ((FULL) *hd) + + ((FULL) *h1++) + carry; + *hd++ = (HALF)(BASE1 - sival.silow); + carry = sival.sihigh; + } + while (carry) { + sival.ivalue = BASE1 - ((FULL) *hd) + carry; + *hd++ = (HALF)(BASE1 - sival.silow); + carry = sival.sihigh; + } + } else { + while (len--) { + sival.ivalue = ((FULL) *h1++) + ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } + while (carry) { + sival.ivalue = ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } + } - /* - * Finally determine the size of the final result and return that. - */ - len = sizetotal; - hd = &ans[len - 1]; - while ((*hd == 0) && (len > 1)) { - hd--; - len--; - } - tempbuf = temp; - return len; + /* + * Finally determine the size of the final result and return that. + */ + len = sizetotal; + hd = &ans[len - 1]; + while ((*hd == 0) && (len > 1)) { + hd--; + len--; + } + tempbuf = temp; + return len; } /* * Square a number by using the following formula recursively: - * (A*S+B)^2 = (S^2+S)*A^2 + (S+1)*B^2 - S*(A-B)^2 + * (A*S+B)^2 = (S^2+S)*A^2 + (S+1)*B^2 - S*(A-B)^2 * where S is a power of 2^16, and so multiplies by it are shifts, * and A and B are the left and right HALFs of the number to square. */ void zsquare(ZVALUE z, ZVALUE *res) { - LEN len; + LEN len; - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - if (ziszero(z)) { - *res = _zero_; - return; - } - if (zisunit(z)) { - *res = _one_; - return; - } + if (ziszero(z)) { + *res = _zero_; + return; + } + if (zisunit(z)) { + *res = _one_; + return; + } - /* - * Allocate a temporary array if necessary for the recursion to use. - * The array needs to be allocated large enough for all of the - * temporary results to fit in. This size is about 3 times the - * size of the original number, since each recursion level uses 3/2 - * of the size of its given number, and whose size is 1/2 the size - * of the previous level. The sum of the infinite series is 3. - * Allocate some extra words for rounding up the sizes. - */ - len = 3 * z.len + 32; - tempbuf = zalloctemp(len); + /* + * Allocate a temporary array if necessary for the recursion to use. + * The array needs to be allocated large enough for all of the + * temporary results to fit in. This size is about 3 times the + * size of the original number, since each recursion level uses 3/2 + * of the size of its given number, and whose size is 1/2 the size + * of the previous level. The sum of the infinite series is 3. + * Allocate some extra words for rounding up the sizes. + */ + len = 3 * z.len + 32; + tempbuf = zalloctemp(len); - res->sign = 0; - res->v = alloc((z.len+2) * 2); - /* - * Without the memset below, Purify reports that dosquare() - * will read uninitialized memory at the dosquare() line below - * the comment: - * - * uninitialized memory read (see zsquare) - * - * This problem occurs during regression test #622 and may - * be duplicated by executing: - * - * config("sq2", 2); - * 0xffff0000ffffffff00000000ffff0000000000000000ffff^2; - */ - memset((char *)res->v, 0, ((z.len+2) * 2)*sizeof(HALF)); - res->len = dosquare(z.v, z.len, res->v); + res->sign = 0; + res->v = alloc((z.len+2) * 2); + /* + * Without the memset below, Purify reports that dosquare() + * will read uninitialized memory at the dosquare() line below + * the comment: + * + * uninitialized memory read (see zsquare) + * + * This problem occurs during regression test #622 and may + * be duplicated by executing: + * + * config("sq2", 2); + * 0xffff0000ffffffff00000000ffff0000000000000000ffff^2; + */ + memset((char *)res->v, 0, ((z.len+2) * 2)*sizeof(HALF)); + res->len = dosquare(z.v, z.len, res->v); } @@ -717,349 +717,349 @@ zsquare(ZVALUE z, ZVALUE *res) * size of the number at the top level recursive call. * * given: - * vp value to be squared - * size length of value to square - * ans location for result + * vp value to be squared + * size length of value to square + * ans location for result */ S_FUNC LEN dosquare(HALF *vp, LEN size, HALF *ans) { - LEN shift; /* amount numbers are shifted by */ - LEN sizeA; /* size of left half of number to square */ - LEN sizeB; /* size of right half of number to square */ - LEN sizeAA; /* size of square of left half */ - LEN sizeBB; /* size of square of right half */ - LEN sizeAABB; /* size of sum of squares of A and B */ - LEN sizeAB; /* size of difference of A and B */ - LEN sizeABAB; /* size of square of difference of A and B */ - LEN subsize; /* size of difference of HALFs */ - LEN copysize; /* size of number left to copy */ - LEN sumsize; /* size of sum */ - LEN sizetotal; /* total size of square */ - LEN len; /* temporary length */ - LEN len1; /* another temporary length */ - FULL carry; /* carry digit for small multiplications */ - FULL digit; /* single digit multiplying by */ - HALF *temp; /* base for temporary calculations */ - HALF *baseA; /* base of left half of number */ - HALF *baseB; /* base of right half of number */ - HALF *baseAA; /* base of square of left half of number */ - HALF *baseBB; /* base of square of right half of number */ - HALF *baseAABB; /* base of sum of squares of A and B */ - HALF *baseAB; /* base of difference of A and B */ - HALF *baseABAB; /* base of square of difference of A and B */ - register HALF *hd, *h1, *h2, *h3; /* for inner loops */ - SIUNION sival; /* for addition of digits */ + LEN shift; /* amount numbers are shifted by */ + LEN sizeA; /* size of left half of number to square */ + LEN sizeB; /* size of right half of number to square */ + LEN sizeAA; /* size of square of left half */ + LEN sizeBB; /* size of square of right half */ + LEN sizeAABB; /* size of sum of squares of A and B */ + LEN sizeAB; /* size of difference of A and B */ + LEN sizeABAB; /* size of square of difference of A and B */ + LEN subsize; /* size of difference of HALFs */ + LEN copysize; /* size of number left to copy */ + LEN sumsize; /* size of sum */ + LEN sizetotal; /* total size of square */ + LEN len; /* temporary length */ + LEN len1; /* another temporary length */ + FULL carry; /* carry digit for small multiplications */ + FULL digit; /* single digit multiplying by */ + HALF *temp; /* base for temporary calculations */ + HALF *baseA; /* base of left half of number */ + HALF *baseB; /* base of right half of number */ + HALF *baseAA; /* base of square of left half of number */ + HALF *baseBB; /* base of square of right half of number */ + HALF *baseAABB; /* base of sum of squares of A and B */ + HALF *baseAB; /* base of difference of A and B */ + HALF *baseABAB; /* base of square of difference of A and B */ + register HALF *hd, *h1, *h2, *h3; /* for inner loops */ + SIUNION sival; /* for addition of digits */ - /* firewall */ - if (vp == NULL) { - math_error("%s: vp NULL", __func__); - not_reached(); - } - if (ans == NULL) { - math_error("%s: ans NULL", __func__); - not_reached(); - } + /* firewall */ + if (vp == NULL) { + math_error("%s: vp NULL", __func__); + not_reached(); + } + if (ans == NULL) { + math_error("%s: ans NULL", __func__); + not_reached(); + } - /* - * First trim the number of leading zeroes. - */ - hd = &vp[size - 1]; - while ((*hd == 0) && (size > 1)) { - size--; - hd--; - } - sizetotal = size + size; + /* + * First trim the number of leading zeroes. + */ + hd = &vp[size - 1]; + while ((*hd == 0) && (size > 1)) { + size--; + hd--; + } + sizetotal = size + size; - /* - * If the number has only a small number of digits, then use the - * (almost) normal multiplication method. Multiply each halfword - * only by those halfwords further on in the number. Missed terms - * will then be the same pairs of products repeated, and the squares - * of each halfword. The first case is handled by doubling the - * result. The second case is handled explicitly. The number of - * digits where the algorithm changes is settable from 2 to maxint. - */ - if (size < conf->sq2) { - hd = ans; - len = sizetotal; - while (len--) - *hd++ = 0; + /* + * If the number has only a small number of digits, then use the + * (almost) normal multiplication method. Multiply each halfword + * only by those halfwords further on in the number. Missed terms + * will then be the same pairs of products repeated, and the squares + * of each halfword. The first case is handled by doubling the + * result. The second case is handled explicitly. The number of + * digits where the algorithm changes is settable from 2 to maxint. + */ + if (size < conf->sq2) { + hd = ans; + len = sizetotal; + while (len--) + *hd++ = 0; - h2 = vp; - hd = ans + 1; - for (len = size; len--; hd += 2) { - digit = (FULL) *h2++; - if (digit == 0) - continue; - h3 = h2; - h1 = hd; - carry = 0; - len1 = len; - while (len1 >= 4) { /* expand the loop some */ - len1 -= 4; - sival.ivalue = (digit * ((FULL) *h3++)) - + ((FULL) *h1) + carry; - *h1++ = sival.silow; - sival.ivalue = (digit * ((FULL) *h3++)) - + ((FULL) *h1) + ((FULL) sival.sihigh); - *h1++ = sival.silow; - sival.ivalue = (digit * ((FULL) *h3++)) - + ((FULL) *h1) + ((FULL) sival.sihigh); - *h1++ = sival.silow; - sival.ivalue = (digit * ((FULL) *h3++)) - + ((FULL) *h1) + ((FULL) sival.sihigh); - *h1++ = sival.silow; - carry = sival.sihigh; - } - while (len1--) { - sival.ivalue = (digit * ((FULL) *h3++)) - + ((FULL) *h1) + carry; - *h1++ = sival.silow; - carry = sival.sihigh; - } - while (carry) { - sival.ivalue = ((FULL) *h1) + carry; - *h1++ = sival.silow; - carry = sival.sihigh; - } - } + h2 = vp; + hd = ans + 1; + for (len = size; len--; hd += 2) { + digit = (FULL) *h2++; + if (digit == 0) + continue; + h3 = h2; + h1 = hd; + carry = 0; + len1 = len; + while (len1 >= 4) { /* expand the loop some */ + len1 -= 4; + sival.ivalue = (digit * ((FULL) *h3++)) + + ((FULL) *h1) + carry; + *h1++ = sival.silow; + sival.ivalue = (digit * ((FULL) *h3++)) + + ((FULL) *h1) + ((FULL) sival.sihigh); + *h1++ = sival.silow; + sival.ivalue = (digit * ((FULL) *h3++)) + + ((FULL) *h1) + ((FULL) sival.sihigh); + *h1++ = sival.silow; + sival.ivalue = (digit * ((FULL) *h3++)) + + ((FULL) *h1) + ((FULL) sival.sihigh); + *h1++ = sival.silow; + carry = sival.sihigh; + } + while (len1--) { + sival.ivalue = (digit * ((FULL) *h3++)) + + ((FULL) *h1) + carry; + *h1++ = sival.silow; + carry = sival.sihigh; + } + while (carry) { + sival.ivalue = ((FULL) *h1) + carry; + *h1++ = sival.silow; + carry = sival.sihigh; + } + } - /* - * Now double the result. - * There is no final carry to worry about because we - * handle all digits of the result which must fit. - */ - carry = 0; - hd = ans; - len = sizetotal; - while (len--) { - digit = ((FULL) *hd); - sival.ivalue = digit + digit + carry; - /* ignore Saber-C warning #112 - get ushort from uint */ - /* OK to ignore on name dosquare`sival */ - *hd++ = sival.silow; - carry = sival.sihigh; - } + /* + * Now double the result. + * There is no final carry to worry about because we + * handle all digits of the result which must fit. + */ + carry = 0; + hd = ans; + len = sizetotal; + while (len--) { + digit = ((FULL) *hd); + sival.ivalue = digit + digit + carry; + /* ignore Saber-C warning #112 - get ushort from uint */ + /* OK to ignore on name dosquare`sival */ + *hd++ = sival.silow; + carry = sival.sihigh; + } - /* - * Now add in the squares of each halfword. - */ - carry = 0; - hd = ans; - h3 = vp; - len = size; - while (len--) { - digit = ((FULL) *h3++); - sival.ivalue = digit * digit + ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - sival.ivalue = ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } - while (carry) { - sival.ivalue = ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } + /* + * Now add in the squares of each halfword. + */ + carry = 0; + hd = ans; + h3 = vp; + len = size; + while (len--) { + digit = ((FULL) *h3++); + sival.ivalue = digit * digit + ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + sival.ivalue = ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } + while (carry) { + sival.ivalue = ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } - /* - * Finally return the size of the result. - */ - len = sizetotal; - hd = &ans[len - 1]; - while ((*hd == 0) && (len > 1)) { - len--; - hd--; - } - return len; - } + /* + * Finally return the size of the result. + */ + len = sizetotal; + hd = &ans[len - 1]; + while ((*hd == 0) && (len > 1)) { + len--; + hd--; + } + return len; + } - /* - * The number to be squared is large. - * Allocate temporary space and determine the sizes and - * positions of the values to be calculated. - */ - temp = tempbuf; - tempbuf += (3 * (size + 1) / 2); + /* + * The number to be squared is large. + * Allocate temporary space and determine the sizes and + * positions of the values to be calculated. + */ + temp = tempbuf; + tempbuf += (3 * (size + 1) / 2); - sizeA = size / 2; - sizeB = size - sizeA; - shift = sizeB; - baseA = vp + sizeB; - baseB = vp; - baseAA = &ans[shift * 2]; - baseBB = ans; - baseAABB = temp; - baseAB = temp; - baseABAB = &temp[shift]; + sizeA = size / 2; + sizeB = size - sizeA; + shift = sizeB; + baseA = vp + sizeB; + baseB = vp; + baseAA = &ans[shift * 2]; + baseBB = ans; + baseAABB = temp; + baseAB = temp; + baseABAB = &temp[shift]; - /* - * Trim the second number of leading zeroes. - */ - hd = &baseB[sizeB - 1]; - while ((*hd == 0) && (sizeB > 1)) { - sizeB--; - hd--; - } + /* + * Trim the second number of leading zeroes. + */ + hd = &baseB[sizeB - 1]; + while ((*hd == 0) && (sizeB > 1)) { + sizeB--; + hd--; + } - /* - * Now to proceed to calculate the result using the formula. - * (A*S+B)^2 = (S^2+S)*A^2 + (S+1)*B^2 - S*(A-B)^2. - * The steps are done in the following order: - * S^2*A^2 + B^2 - * A^2 + B^2 - * (S^2+S)*A^2 + (S+1)*B^2 - * (A-B)^2 - * (S^2+S)*A^2 + (S+1)*B^2 - S*(A-B)^2. - * - * Begin by forming the squares of two the HALFs concatenated - * together in the final result location. Make sure that the - * highest words of the results are zero. - */ - sizeBB = dosquare(baseB, sizeB, baseBB); - hd = &baseBB[sizeBB]; - len = shift * 2 - sizeBB; - while (len--) - *hd++ = 0; + /* + * Now to proceed to calculate the result using the formula. + * (A*S+B)^2 = (S^2+S)*A^2 + (S+1)*B^2 - S*(A-B)^2. + * The steps are done in the following order: + * S^2*A^2 + B^2 + * A^2 + B^2 + * (S^2+S)*A^2 + (S+1)*B^2 + * (A-B)^2 + * (S^2+S)*A^2 + (S+1)*B^2 - S*(A-B)^2. + * + * Begin by forming the squares of two the HALFs concatenated + * together in the final result location. Make sure that the + * highest words of the results are zero. + */ + sizeBB = dosquare(baseB, sizeB, baseBB); + hd = &baseBB[sizeBB]; + len = shift * 2 - sizeBB; + while (len--) + *hd++ = 0; - sizeAA = dosquare(baseA, sizeA, baseAA); - hd = &baseAA[sizeAA]; - len = sizetotal - shift * 2 - sizeAA; - while (len--) - *hd++ = 0; + sizeAA = dosquare(baseA, sizeA, baseAA); + hd = &baseAA[sizeAA]; + len = sizetotal - shift * 2 - sizeAA; + while (len--) + *hd++ = 0; - /* - * Sum the two squares into a temporary location. - */ - if (sizeAA >= sizeBB) { - h1 = baseAA; - h2 = baseBB; - sizeAABB = sizeAA; - sumsize = sizeBB; - } else { - h1 = baseBB; - h2 = baseAA; - sizeAABB = sizeBB; - sumsize = sizeAA; - } - copysize = sizeAABB - sumsize; + /* + * Sum the two squares into a temporary location. + */ + if (sizeAA >= sizeBB) { + h1 = baseAA; + h2 = baseBB; + sizeAABB = sizeAA; + sumsize = sizeBB; + } else { + h1 = baseBB; + h2 = baseAA; + sizeAABB = sizeBB; + sumsize = sizeAA; + } + copysize = sizeAABB - sumsize; - hd = baseAABB; - carry = 0; - while (sumsize--) { - sival.ivalue = ((FULL) *h1++) + ((FULL) *h2++) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } - while (copysize--) { - sival.ivalue = ((FULL) *h1++) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } - if (carry) { - *hd = (HALF)carry; - sizeAABB++; - } + hd = baseAABB; + carry = 0; + while (sumsize--) { + sival.ivalue = ((FULL) *h1++) + ((FULL) *h2++) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } + while (copysize--) { + sival.ivalue = ((FULL) *h1++) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } + if (carry) { + *hd = (HALF)carry; + sizeAABB++; + } - /* - * Add the sum back into the previously calculated squares - * shifted over to the proper location. - */ - h1 = baseAABB; - hd = ans + shift; - carry = 0; - len = sizeAABB; - while (len--) { - sival.ivalue = ((FULL) *hd) + ((FULL) *h1++) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } - while (carry) { - /* uninitialized memory read (see zsquare) */ - sival.ivalue = ((FULL) *hd) + carry; - *hd++ = sival.silow; - carry = sival.sihigh; - } + /* + * Add the sum back into the previously calculated squares + * shifted over to the proper location. + */ + h1 = baseAABB; + hd = ans + shift; + carry = 0; + len = sizeAABB; + while (len--) { + sival.ivalue = ((FULL) *hd) + ((FULL) *h1++) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } + while (carry) { + /* uninitialized memory read (see zsquare) */ + sival.ivalue = ((FULL) *hd) + carry; + *hd++ = sival.silow; + carry = sival.sihigh; + } - /* - * Calculate the absolute value of the difference of the two HALFs - * into a temporary location. - */ - if (sizeA == sizeB) { - len = sizeA; - h1 = &baseA[len - 1]; - h2 = &baseB[len - 1]; - while ((len > 1) && (*h1 == *h2)) { - len--; - h1--; - h2--; - } - } - if ((sizeA > sizeB) || ((sizeA == sizeB) && (*h1 > *h2))) { - h1 = baseA; - h2 = baseB; - sizeAB = sizeA; - subsize = sizeB; - } else { - h1 = baseB; - h2 = baseA; - sizeAB = sizeB; - subsize = sizeA; - } - copysize = sizeAB - subsize; + /* + * Calculate the absolute value of the difference of the two HALFs + * into a temporary location. + */ + if (sizeA == sizeB) { + len = sizeA; + h1 = &baseA[len - 1]; + h2 = &baseB[len - 1]; + while ((len > 1) && (*h1 == *h2)) { + len--; + h1--; + h2--; + } + } + if ((sizeA > sizeB) || ((sizeA == sizeB) && (*h1 > *h2))) { + h1 = baseA; + h2 = baseB; + sizeAB = sizeA; + subsize = sizeB; + } else { + h1 = baseB; + h2 = baseA; + sizeAB = sizeB; + subsize = sizeA; + } + copysize = sizeAB - subsize; - hd = baseAB; - carry = 0; - while (subsize--) { - sival.ivalue = BASE1 - ((FULL) *h1++) + ((FULL) *h2++) + carry; - *hd++ = (HALF)(BASE1 - sival.silow); - carry = sival.sihigh; - } - while (copysize--) { - sival.ivalue = (BASE1 - ((FULL) *h1++)) + carry; - *hd++ = (HALF)(BASE1 - sival.silow); - carry = sival.sihigh; - } + hd = baseAB; + carry = 0; + while (subsize--) { + sival.ivalue = BASE1 - ((FULL) *h1++) + ((FULL) *h2++) + carry; + *hd++ = (HALF)(BASE1 - sival.silow); + carry = sival.sihigh; + } + while (copysize--) { + sival.ivalue = (BASE1 - ((FULL) *h1++)) + carry; + *hd++ = (HALF)(BASE1 - sival.silow); + carry = sival.sihigh; + } - hd = &baseAB[sizeAB - 1]; - while ((*hd == 0) && (sizeAB > 1)) { - sizeAB--; - hd--; - } + hd = &baseAB[sizeAB - 1]; + while ((*hd == 0) && (sizeAB > 1)) { + sizeAB--; + hd--; + } - /* - * Now square the number into another temporary location, - * and subtract that from the final result. - */ - sizeABAB = dosquare(baseAB, sizeAB, baseABAB); + /* + * Now square the number into another temporary location, + * and subtract that from the final result. + */ + sizeABAB = dosquare(baseAB, sizeAB, baseABAB); - h1 = baseABAB; - hd = ans + shift; - carry = 0; - while (sizeABAB--) { - sival.ivalue = BASE1 - ((FULL) *hd) + ((FULL) *h1++) + carry; - *hd++ = (HALF)(BASE1 - sival.silow); - carry = sival.sihigh; - } - while (carry) { - sival.ivalue = BASE1 - ((FULL) *hd) + carry; - *hd++ = (HALF)(BASE1 - sival.silow); - carry = sival.sihigh; - } + h1 = baseABAB; + hd = ans + shift; + carry = 0; + while (sizeABAB--) { + sival.ivalue = BASE1 - ((FULL) *hd) + ((FULL) *h1++) + carry; + *hd++ = (HALF)(BASE1 - sival.silow); + carry = sival.sihigh; + } + while (carry) { + sival.ivalue = BASE1 - ((FULL) *hd) + carry; + *hd++ = (HALF)(BASE1 - sival.silow); + carry = sival.sihigh; + } - /* - * Return the size of the result. - */ - len = sizetotal; - hd = &ans[len - 1]; - while ((*hd == 0) && (len > 1)) { - len--; - hd--; - } - tempbuf = temp; - return len; + /* + * Return the size of the result. + */ + len = sizetotal; + hd = &ans[len - 1]; + while ((*hd == 0) && (len > 1)) { + len--; + hd--; + } + tempbuf = temp; + return len; } @@ -1072,36 +1072,36 @@ dosquare(HALF *vp, LEN size, HALF *ans) * such as divide, multiply, and square. * * given: - * len required number of HALFs in buffer + * len required number of HALFs in buffer */ HALF * zalloctemp(LEN len) { - HALF *hp; - STATIC LEN buflen; /* current length of temp buffer */ - STATIC HALF *bufptr; /* pointer to current temp buffer */ + HALF *hp; + STATIC LEN buflen; /* current length of temp buffer */ + STATIC HALF *bufptr; /* pointer to current temp buffer */ - if (len <= buflen) - return bufptr; + if (len <= buflen) + return bufptr; - /* - * We need to grow the temporary buffer. - * First free any existing buffer, and then allocate the new one. - * While we are at it, make the new buffer bigger than necessary - * in order to reduce the number of reallocations. - */ - len += 100; - if (buflen) { - buflen = 0; - free(bufptr); - } - /* don't call alloc() because _math_abort_ may not be set right */ - hp = (HALF *) malloc((len+1) * sizeof(HALF)); - if (hp == NULL) { - math_error("No memory for temp buffer"); - not_reached(); - } - bufptr = hp; - buflen = len; - return hp; + /* + * We need to grow the temporary buffer. + * First free any existing buffer, and then allocate the new one. + * While we are at it, make the new buffer bigger than necessary + * in order to reduce the number of reallocations. + */ + len += 100; + if (buflen) { + buflen = 0; + free(bufptr); + } + /* don't call alloc() because _math_abort_ may not be set right */ + hp = (HALF *) malloc((len+1) * sizeof(HALF)); + if (hp == NULL) { + math_error("No memory for temp buffer"); + not_reached(); + } + bufptr = hp; + buflen = len; + return hp; } diff --git a/zprime.c b/zprime.c index c0d6f12..6bd5512 100644 --- a/zprime.c +++ b/zprime.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1994/05/29 04:34:36 - * File existed as early as: 1994 + * Under source code control: 1994/05/29 04:34:36 + * File existed as early as: 1994 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -34,7 +34,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* @@ -42,7 +42,7 @@ * if the number has a factor <= PTEST_PRECHECK. * * XXX - what should this value be? Perhaps this should be a function - * of the size of the text value and the number of tests? + * of the size of the text value and the number of tests? */ #define PTEST_PRECHECK ((FULL)101) @@ -67,8 +67,8 @@ STATIC CONST FULL pfact_tbl[MAX_PFACT_VAL+1] = { /* * determine the top 1 bit of a 8 bit value: * - * topbit[0] == 0 by convention - * topbit[x] gives the highest 1 bit of x + * topbit[0] == 0 by convention + * topbit[x] gives the highest 1 bit of x */ STATIC CONST unsigned char topbit[256] = { 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, @@ -92,81 +92,81 @@ STATIC CONST unsigned char topbit[256] = { /* * integer square roots of powers of 2 * - * isqrt_pow2[x] == (int)(sqrt(2 to the x power)) (for 0 <= x < 64) + * isqrt_pow2[x] == (int)(sqrt(2 to the x power)) (for 0 <= x < 64) * * We have enough table entries for a FULL that is 64 bits long. */ STATIC CONST FULL isqrt_pow2[64] = { - 1, 1, 2, 2, 4, 5, 8, 11, /* 0 .. 7 */ - 16, 22, 32, 45, 64, 90, 128, 181, /* 8 .. 15 */ - 256, 362, 512, 724, 1024, 1448, 2048, 2896, /* 16 .. 23 */ - 4096, 5792, 8192, 11585, 16384, 23170, 32768, 46340, /* 24 .. 31 */ - 65536, 92681, 131072, 185363, /* 32 .. 35 */ - 262144, 370727, 524288, 741455, /* 36 .. 39 */ - 1048576, 1482910, 2097152, 2965820, /* 40 .. 43 */ - 4194304, 5931641, 8388608, 11863283, /* 44 .. 47 */ - 16777216, 23726566, 33554432, 47453132, /* 48 .. 51 */ - 67108864, 94906265, 134217728, 189812531, /* 52 .. 55 */ - 268435456, 379625062, 536870912, 759250124, /* 56 .. 59 */ - 1073741824, 1518500249, 0x80000000, 0xb504f333 /* 60 .. 63 */ + 1, 1, 2, 2, 4, 5, 8, 11, /* 0 .. 7 */ + 16, 22, 32, 45, 64, 90, 128, 181, /* 8 .. 15 */ + 256, 362, 512, 724, 1024, 1448, 2048, 2896, /* 16 .. 23 */ + 4096, 5792, 8192, 11585, 16384, 23170, 32768, 46340, /* 24 .. 31 */ + 65536, 92681, 131072, 185363, /* 32 .. 35 */ + 262144, 370727, 524288, 741455, /* 36 .. 39 */ + 1048576, 1482910, 2097152, 2965820, /* 40 .. 43 */ + 4194304, 5931641, 8388608, 11863283, /* 44 .. 47 */ + 16777216, 23726566, 33554432, 47453132, /* 48 .. 51 */ + 67108864, 94906265, 134217728, 189812531, /* 52 .. 55 */ + 268435456, 379625062, 536870912, 759250124, /* 56 .. 59 */ + 1073741824, 1518500249, 0x80000000, 0xb504f333 /* 60 .. 63 */ }; /* * static functions */ -S_FUNC FULL fsqrt(FULL v); /* quick square root of v */ -S_FUNC long pix(FULL x); /* pi of x */ -S_FUNC FULL small_factor(ZVALUE n, FULL limit); /* factor or 0 */ +S_FUNC FULL fsqrt(FULL v); /* quick square root of v */ +S_FUNC long pix(FULL x); /* pi of x */ +S_FUNC FULL small_factor(ZVALUE n, FULL limit); /* factor or 0 */ /* * Determine if a value is a small (32 bit) prime * * Returns: - * 1 z is a prime <= MAX_SM_VAL - * 0 z is not a prime <= MAX_SM_VAL - * -1 z > MAX_SM_VAL + * 1 z is a prime <= MAX_SM_VAL + * 0 z is not a prime <= MAX_SM_VAL + * -1 z > MAX_SM_VAL */ FLAG zisprime(ZVALUE z) { - FULL n; /* number to test */ - FULL isqr; /* factor limit */ - CONST unsigned short *tp; /* pointer to a prime factor */ + FULL n; /* number to test */ + FULL isqr; /* factor limit */ + CONST unsigned short *tp; /* pointer to a prime factor */ - z.sign = 0; - if (zisleone(z)) { - return 0; - } + z.sign = 0; + if (zisleone(z)) { + return 0; + } - /* even numbers > 2 are not prime */ - if (ziseven(z)) { - /* - * "2 is the greatest odd prime because it is the least even!" - * - Dr. Dan Jurca 1978 - */ - return zisabstwo(z); - } + /* even numbers > 2 are not prime */ + if (ziseven(z)) { + /* + * "2 is the greatest odd prime because it is the least even!" + * - Dr. Dan Jurca 1978 + */ + return zisabstwo(z); + } - /* ignore non-small values */ - if (zge32b(z)) { - return -1; - } + /* ignore non-small values */ + if (zge32b(z)) { + return -1; + } - /* we now know that we are dealing with a value 0 <= n < 2^32 */ - n = ztofull(z); + /* we now know that we are dealing with a value 0 <= n < 2^32 */ + n = ztofull(z); - /* lookup small cases in pr_map */ - if (n <= MAX_MAP_VAL) { - return (pr_map_bit(n) ? 1 : 0); - } + /* lookup small cases in pr_map */ + if (n <= MAX_MAP_VAL) { + return (pr_map_bit(n) ? 1 : 0); + } - /* ignore Saber-C warning #530 about empty for statement */ - /* OK to ignore in proc zisprime */ - /* a number >=2^16 and < 2^32 */ - for (isqr=fsqrt(n), tp=prime; (*tp <= isqr) && (n % *tp); ++tp) { - } - return ((*tp <= isqr && *tp != 1) ? 0 : 1); + /* ignore Saber-C warning #530 about empty for statement */ + /* OK to ignore in proc zisprime */ + /* a number >=2^16 and < 2^32 */ + for (isqr=fsqrt(n), tp=prime; (*tp <= isqr) && (n % *tp); ++tp) { + } + return ((*tp <= isqr && *tp != 1) ? 0 : 1); } @@ -174,38 +174,38 @@ zisprime(ZVALUE z) * Determine the next small (32 bit) prime > a 32 bit value. * * given: - * z search point + * z search point * * Returns: - * 0 next prime is 2^32+15 - * 1 abs(z) >= 2^32 - * smallest prime > abs(z) otherwise + * 0 next prime is 2^32+15 + * 1 abs(z) >= 2^32 + * smallest prime > abs(z) otherwise */ FULL znprime(ZVALUE z) { - FULL n; /* search point */ + FULL n; /* search point */ - z.sign = 0; + z.sign = 0; - /* ignore large values */ - if (zge32b(z)) { - return (FULL)1; - } + /* ignore large values */ + if (zge32b(z)) { + return (FULL)1; + } - /* deal a search point of 0 or 1 */ - if (zisabsleone(z)) { - return (FULL)2; - } + /* deal a search point of 0 or 1 */ + if (zisabsleone(z)) { + return (FULL)2; + } - /* deal with returning a value that is beyond our reach */ - n = ztofull(z); - if (n >= MAX_SM_PRIME) { - return (FULL)0; - } + /* deal with returning a value that is beyond our reach */ + n = ztofull(z); + if (n >= MAX_SM_PRIME) { + return (FULL)0; + } - /* return the next prime */ - return next_prime(n); + /* return the next prime */ + return next_prime(n); } @@ -215,81 +215,81 @@ znprime(ZVALUE z) * This function assumes that 2 <= n < 2^32-5. * * given: - * n search point + * n search point */ FULL next_prime(FULL n) { - CONST unsigned short *tp; /* pointer to a prime factor */ - CONST unsigned char *j; /* current jump increment */ - int tmp; + CONST unsigned short *tp; /* pointer to a prime factor */ + CONST unsigned char *j; /* current jump increment */ + int tmp; - /* find our search point */ - n = ((n & 0x1) ? n+2 : n+1); + /* find our search point */ + n = ((n & 0x1) ? n+2 : n+1); - /* if we can just search the bit map, then search it */ - if (n <= MAX_MAP_PRIME) { + /* if we can just search the bit map, then search it */ + if (n <= MAX_MAP_PRIME) { - /* search until we find a 1 bit */ - while (pr_map_bit(n) == 0) { - n += (FULL)2; - } + /* search until we find a 1 bit */ + while (pr_map_bit(n) == 0) { + n += (FULL)2; + } - /* too large for our table, find the next prime the hard way */ - } else { - FULL isqr; /* factor limit */ + /* too large for our table, find the next prime the hard way */ + } else { + FULL isqr; /* factor limit */ - /* - * Our search for a prime may cause us to increment n over - * a perfect square, but never two perfect squares. The largest - * prime gap <= 2614941711251 is 651. Shanks conjectures that - * the largest gap below P is about ln(P)^2. - * - * The value fsqrt(n)^2 will always be the perfect square - * that is <= n. Given the smallness of prime gaps we will - * deal with, we know that n could carry us across the next - * perfect square (fsqrt(n)+1)^2 but not the following - * perfect square (fsqrt(n)+2)^2. - * - * Now the factor search limit for values < (fsqrt(n)+2)^2 - * is the same limit for (fsqrt(n)+1)^2; namely fsqrt(n)+1. - * Therefore setting our limit at fsqrt(n)+1 and never - * bothering with it after that is safe. - */ - isqr = fsqrt(n)+1; + /* + * Our search for a prime may cause us to increment n over + * a perfect square, but never two perfect squares. The largest + * prime gap <= 2614941711251 is 651. Shanks conjectures that + * the largest gap below P is about ln(P)^2. + * + * The value fsqrt(n)^2 will always be the perfect square + * that is <= n. Given the smallness of prime gaps we will + * deal with, we know that n could carry us across the next + * perfect square (fsqrt(n)+1)^2 but not the following + * perfect square (fsqrt(n)+2)^2. + * + * Now the factor search limit for values < (fsqrt(n)+2)^2 + * is the same limit for (fsqrt(n)+1)^2; namely fsqrt(n)+1. + * Therefore setting our limit at fsqrt(n)+1 and never + * bothering with it after that is safe. + */ + isqr = fsqrt(n)+1; - /* - * If our factor limit is even, then we can reduce it to - * the next lowest odd value. We already tested if n - * was even and all of our remaining potential factors - * are odd. - */ - if ((isqr & 0x1) == 0) { - --isqr; - } + /* + * If our factor limit is even, then we can reduce it to + * the next lowest odd value. We already tested if n + * was even and all of our remaining potential factors + * are odd. + */ + if ((isqr & 0x1) == 0) { + --isqr; + } - /* - * Skip to next value not divisible by a trivial prime. - */ - n = firstjmp(n, tmp); - j = jmp + jmpptr(n); + /* + * Skip to next value not divisible by a trivial prime. + */ + n = firstjmp(n, tmp); + j = jmp + jmpptr(n); - /* - * Look for tiny prime factors of increasing n until we - * find a prime. - */ - do { - /* ignore Saber-C warning #530 - empty for statement */ - /* OK to ignore in proc next_prime */ - /* XXX - speed up test for large n by using GCDs */ - /* find a factor, or give up if not found */ - for (tp=JPRIME; (*tp <= isqr) && (n % *tp); ++tp) { - } - } while (*tp <= isqr && *tp != 1 && (n += nxtjmp(j))); - } + /* + * Look for tiny prime factors of increasing n until we + * find a prime. + */ + do { + /* ignore Saber-C warning #530 - empty for statement */ + /* OK to ignore in proc next_prime */ + /* XXX - speed up test for large n by using GCDs */ + /* find a factor, or give up if not found */ + for (tp=JPRIME; (*tp <= isqr) && (n % *tp); ++tp) { + } + } while (*tp <= isqr && *tp != 1 && (n += nxtjmp(j))); + } - /* return the prime that we found */ - return n; + /* return the prime that we found */ + return n; } @@ -297,104 +297,104 @@ next_prime(FULL n) * Determine the previous small (32 bit) prime < a 32 bit value * * given: - * z search point + * z search point * * Returns: - * 1 abs(z) >= 2^32 - * 0 abs(z) <= 2 - * greatest prime < abs(z) otherwise + * 1 abs(z) >= 2^32 + * 0 abs(z) <= 2 + * greatest prime < abs(z) otherwise */ FULL zpprime(ZVALUE z) { - CONST unsigned short *tp; /* pointer to a prime factor */ - FULL isqr; /* isqrt(z) */ - FULL n; /* search point */ - CONST unsigned char *j; /* current jump increment */ - int tmp; + CONST unsigned short *tp; /* pointer to a prime factor */ + FULL isqr; /* isqrt(z) */ + FULL n; /* search point */ + CONST unsigned char *j; /* current jump increment */ + int tmp; - z.sign = 0; + z.sign = 0; - /* ignore large values */ - if (zge32b(z)) { - return (FULL)1; - } + /* ignore large values */ + if (zge32b(z)) { + return (FULL)1; + } - /* deal with special case small values */ - n = ztofull(z); - switch ((int)n) { - case 0: - case 1: - case 2: - /* ignore values <= 2 */ - return (FULL)0; - case 3: - /* 3 returns the only even prime */ - return (FULL)2; - } + /* deal with special case small values */ + n = ztofull(z); + switch ((int)n) { + case 0: + case 1: + case 2: + /* ignore values <= 2 */ + return (FULL)0; + case 3: + /* 3 returns the only even prime */ + return (FULL)2; + } - /* deal with values above the bit map */ - if (n > NXT_MAP_PRIME) { + /* deal with values above the bit map */ + if (n > NXT_MAP_PRIME) { - /* find our search point */ - n = ((n & 0x1) ? n-2 : n-1); + /* find our search point */ + n = ((n & 0x1) ? n-2 : n-1); - /* our factor limit - see next_prime for why this works */ - isqr = fsqrt(n)+1; - if ((isqr & 0x1) == 0) { - --isqr; - } + /* our factor limit - see next_prime for why this works */ + isqr = fsqrt(n)+1; + if ((isqr & 0x1) == 0) { + --isqr; + } - /* - * Skip to previous value not divisible by a trivial prime. - */ - tmp = jmpindxval(n); - if (tmp >= 0) { + /* + * Skip to previous value not divisible by a trivial prime. + */ + tmp = jmpindxval(n); + if (tmp >= 0) { - /* find next value not divisible by a trivial prime */ - n += tmp; + /* find next value not divisible by a trivial prime */ + n += tmp; - /* find the previous jump index */ - j = jmp + jmpptr(n); + /* find the previous jump index */ + j = jmp + jmpptr(n); - /* jump back */ - n -= prevjmp(j); + /* jump back */ + n -= prevjmp(j); - /* already not divisible by a trivial prime */ - } else { - /* find the current jump index */ - j = jmp + jmpptr(n); - } + /* already not divisible by a trivial prime */ + } else { + /* find the current jump index */ + j = jmp + jmpptr(n); + } - /* factor values until we find a prime */ - do { - /* ignore Saber-C warning #530 - empty for statement */ - /* OK to ignore in proc zpprime */ - /* XXX - speed up test for large n by using GCDs */ - /* find a factor, or give up if not found */ - for (tp=prime; (*tp <= isqr) && (n % *tp); ++tp) { - } - } while (*tp <= isqr && *tp != 1 && (n -= prevjmp(j))); + /* factor values until we find a prime */ + do { + /* ignore Saber-C warning #530 - empty for statement */ + /* OK to ignore in proc zpprime */ + /* XXX - speed up test for large n by using GCDs */ + /* find a factor, or give up if not found */ + for (tp=prime; (*tp <= isqr) && (n % *tp); ++tp) { + } + } while (*tp <= isqr && *tp != 1 && (n -= prevjmp(j))); - /* deal with values within the bit map */ - } else if (n <= MAX_MAP_PRIME) { + /* deal with values within the bit map */ + } else if (n <= MAX_MAP_PRIME) { - /* find our search point */ - n = ((n & 0x1) ? n-2 : n-1); + /* find our search point */ + n = ((n & 0x1) ? n-2 : n-1); - /* search until we find a 1 bit */ - while (pr_map_bit(n) == 0) { - n -= (FULL)2; - } + /* search until we find a 1 bit */ + while (pr_map_bit(n) == 0) { + n -= (FULL)2; + } - /* deal with values that could cross into the bit map */ - } else { - /* MAX_MAP_PRIME < n <= NXT_MAP_PRIME returns MAX_MAP_PRIME */ - return MAX_MAP_PRIME; - } + /* deal with values that could cross into the bit map */ + } else { + /* MAX_MAP_PRIME < n <= NXT_MAP_PRIME returns MAX_MAP_PRIME */ + return MAX_MAP_PRIME; + } - /* return what we found */ - return n; + /* return what we found */ + return n; } @@ -402,25 +402,25 @@ zpprime(ZVALUE z) * Compute the number of primes <= a ZVALUE that can fit into a FULL * * given: - * z compute primes <= z + * z compute primes <= z * * Returns: - * -1 error - * >=0 number of primes <= x + * -1 error + * >=0 number of primes <= x */ long zpix(ZVALUE z) { - /* pi(<0) is always 0 */ - if (zisneg(z)) { - return (long)0; - } + /* pi(<0) is always 0 */ + if (zisneg(z)) { + return (long)0; + } - /* firewall */ - if (zge32b(z)) { - return (long)-1; - } - return pix(ztofull(z)); + /* firewall */ + if (zge32b(z)) { + return (long)-1; + } + return pix(ztofull(z)); } @@ -428,101 +428,101 @@ zpix(ZVALUE z) * Compute the number of primes <= a ZVALUE * * given: - * x value of z + * x value of z * * Returns: - * -1 error - * >=0 number of primes <= x + * -1 error + * >=0 number of primes <= x */ S_FUNC long pix(FULL x) { - long count; /* pi(x) */ - FULL top; /* top of the range to test */ - CONST unsigned short *tp; /* pointer to a tiny prime */ - FULL i; + long count; /* pi(x) */ + FULL top; /* top of the range to test */ + CONST unsigned short *tp; /* pointer to a tiny prime */ + FULL i; - /* compute pi(x) using the 2^8 step table */ - if (x <= MAX_PI10B) { + /* compute pi(x) using the 2^8 step table */ + if (x <= MAX_PI10B) { - /* x within the prime table, so use it */ - if (x < MAX_MAP_PRIME) { - /* firewall - pix(x) ==0 for x < 2 */ - if (x < 2) { - count = 0; + /* x within the prime table, so use it */ + if (x < MAX_MAP_PRIME) { + /* firewall - pix(x) ==0 for x < 2 */ + if (x < 2) { + count = 0; - } else { - /* determine how and where we will count */ - if (x < 1024) { - count = 1; - tp = prime; - } else { - count = pi10b[x>>10]; - tp = prime+count-1; - } - /* count primes in the table */ - while (*tp++ <= x) { - ++count; - } - } + } else { + /* determine how and where we will count */ + if (x < 1024) { + count = 1; + tp = prime; + } else { + count = pi10b[x>>10]; + tp = prime+count-1; + } + /* count primes in the table */ + while (*tp++ <= x) { + ++count; + } + } - /* x is larger than the prime table, so count the hard way */ - } else { + /* x is larger than the prime table, so count the hard way */ + } else { - /* case: count down from pi18b entry to x */ - if (x & 0x200) { - top = (x | 0x3ff); - count = pi10b[(top+1)>>10]; - for (i=next_prime(x); i <= top; - i=next_prime(i)) { - --count; - } + /* case: count down from pi18b entry to x */ + if (x & 0x200) { + top = (x | 0x3ff); + count = pi10b[(top+1)>>10]; + for (i=next_prime(x); i <= top; + i=next_prime(i)) { + --count; + } - /* case: count up from pi10b entry to x */ - } else { - count = pi10b[x>>10]; - for (i=next_prime(x&(~0x3ff)); - i <= x; i = next_prime(i)) { - ++count; - } - } - } + /* case: count up from pi10b entry to x */ + } else { + count = pi10b[x>>10]; + for (i=next_prime(x&(~0x3ff)); + i <= x; i = next_prime(i)) { + ++count; + } + } + } - /* compute pi(x) using the 2^18 interval table */ - } else { + /* compute pi(x) using the 2^18 interval table */ + } else { - /* compute sum of intervals up to our interval */ - for (count=0, i=0; i < (x>>18); ++i) { - count += pi18b[i]; - } + /* compute sum of intervals up to our interval */ + for (count=0, i=0; i < (x>>18); ++i) { + count += pi18b[i]; + } - /* case: count down from pi18b entry to x */ - if (x & 0x20000) { - top = (x | 0x3ffff); - count += pi18b[i]; - if (top > MAX_SM_PRIME) { - if (x < MAX_SM_PRIME) { - for (i=next_prime(x); i < MAX_SM_PRIME; - i=next_prime(i)) { - --count; - } - --count; - } - } else { - for (i=next_prime(x); i<=top; i=next_prime(i)) { - --count; - } - } + /* case: count down from pi18b entry to x */ + if (x & 0x20000) { + top = (x | 0x3ffff); + count += pi18b[i]; + if (top > MAX_SM_PRIME) { + if (x < MAX_SM_PRIME) { + for (i=next_prime(x); i < MAX_SM_PRIME; + i=next_prime(i)) { + --count; + } + --count; + } + } else { + for (i=next_prime(x); i<=top; i=next_prime(i)) { + --count; + } + } - /* case: count up from pi18b entry to x */ - } else { - for (i=next_prime(x&(~0x3ffff)); - i <= x; i = next_prime(i)) { - ++count; - } - } - } - return count; + /* case: count up from pi18b entry to x */ + } else { + for (i=next_prime(x&(~0x3ffff)); + i <= x; i = next_prime(i)) { + ++count; + } + } + } + return count; } @@ -530,56 +530,56 @@ pix(FULL x) * Compute the smallest prime factor < limit * * given: - * n number to factor - * zlimit ending search point - * res factor, if found, or NULL + * n number to factor + * zlimit ending search point + * res factor, if found, or NULL * * Returns: - * -1 error, limit >= 2^32 - * 0 no factor found, res is not changed - * 1 factor found, res (if non-NULL) is smallest prime factor + * -1 error, limit >= 2^32 + * 0 no factor found, res is not changed + * 1 factor found, res (if non-NULL) is smallest prime factor * * NOTE: This routine will not return a factor == the test value - * except when the test value is 1 or -1. + * except when the test value is 1 or -1. */ FLAG zfactor(ZVALUE n, ZVALUE zlimit, ZVALUE *res) { - FULL f; /* factor found, or 0 */ + FULL f; /* factor found, or 0 */ - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - /* - * determine the limit - */ - if (zge32b(zlimit)) { - /* limit is too large to be reasonable */ - return -1; - } - n.sign = 0; /* ignore sign of n */ + /* + * determine the limit + */ + if (zge32b(zlimit)) { + /* limit is too large to be reasonable */ + return -1; + } + n.sign = 0; /* ignore sign of n */ - /* - * find the smallest factor <= limit, if possible - */ - f = small_factor(n, ztofull(zlimit)); + /* + * find the smallest factor <= limit, if possible + */ + f = small_factor(n, ztofull(zlimit)); - /* - * report the results - */ - if (f > 0) { - /* return factor if requested */ - if (res) { - utoz(f, res); - } - /* report a factor was found */ - return 1; - } - /* no factor was found */ - return 0; + /* + * report the results + */ + if (f > 0) { + /* return factor if requested */ + if (res) { + utoz(f, res); + } + /* report a factor was found */ + return 1; + } + /* no factor was found */ + return 0; } @@ -587,238 +587,238 @@ zfactor(ZVALUE n, ZVALUE zlimit, ZVALUE *res) * Find a smallest prime factor <= some small (32 bit) limit of a value * * given: - * z number to factor - * limit largest factor we will test + * z number to factor + * limit largest factor we will test * * Returns: - * 0 no prime <= the limit was found - * != 0 the smallest prime factor + * 0 no prime <= the limit was found + * != 0 the smallest prime factor */ S_FUNC FULL small_factor(ZVALUE z, FULL limit) { - FULL top; /* current max factor level */ - CONST unsigned short *tp; /* pointer to a tiny prime */ - FULL factlim; /* highest factor to test */ - CONST unsigned short *p; /* test factor */ - FULL factor; /* test factor */ - HALF tlim; /* limit on prime table use */ - HALF divval[2]; /* divisor value */ - ZVALUE div; /* test factor/divisor */ - ZVALUE tmp; - CONST unsigned char *j; + FULL top; /* current max factor level */ + CONST unsigned short *tp; /* pointer to a tiny prime */ + FULL factlim; /* highest factor to test */ + CONST unsigned short *p; /* test factor */ + FULL factor; /* test factor */ + HALF tlim; /* limit on prime table use */ + HALF divval[2]; /* divisor value */ + ZVALUE div; /* test factor/divisor */ + ZVALUE tmp; + CONST unsigned char *j; - /* - * catch impossible ranges - */ - if (limit < 2) { - /* range is too small */ - return 0; - } + /* + * catch impossible ranges + */ + if (limit < 2) { + /* range is too small */ + return 0; + } - /* - * perform the even test - */ - if (ziseven(z)) { - if (zistwo(z)) { - /* z is 2, so don't return 2 as a factor */ - return 0; - } - return 2; + /* + * perform the even test + */ + if (ziseven(z)) { + if (zistwo(z)) { + /* z is 2, so don't return 2 as a factor */ + return 0; + } + return 2; - /* - * value is odd - */ - } else if (limit == 2) { - /* limit is 2, value is odd, no factors will ever be found */ - return 0; - } + /* + * value is odd + */ + } else if (limit == 2) { + /* limit is 2, value is odd, no factors will ever be found */ + return 0; + } - /* - * force the factor limit to be odd - */ - if ((limit & 0x1) == 0) { - --limit; - } + /* + * force the factor limit to be odd + */ + if ((limit & 0x1) == 0) { + --limit; + } - /* - * case: number to factor fits into a FULL - */ - if (!zgtmaxufull(z)) { - FULL val = ztofull(z); /* find the smallest factor of val */ - FULL isqr; /* sqrt of val */ + /* + * case: number to factor fits into a FULL + */ + if (!zgtmaxufull(z)) { + FULL val = ztofull(z); /* find the smallest factor of val */ + FULL isqr; /* sqrt of val */ - /* - * special case: val is a prime <= MAX_MAP_PRIME - */ - if (val <= MAX_MAP_PRIME && pr_map_bit(val)) { - /* z is prime, so no factors will be found */ - return 0; - } + /* + * special case: val is a prime <= MAX_MAP_PRIME + */ + if (val <= MAX_MAP_PRIME && pr_map_bit(val)) { + /* z is prime, so no factors will be found */ + return 0; + } - /* - * we need not search above the sqrt of val - */ - isqr = fsqrt(val); - if (limit > isqr) { - /* limit is largest odd value <= sqrt of val */ - limit = ((isqr & 0x1) ? isqr : isqr-1); - } + /* + * we need not search above the sqrt of val + */ + isqr = fsqrt(val); + if (limit > isqr) { + /* limit is largest odd value <= sqrt of val */ + limit = ((isqr & 0x1) ? isqr : isqr-1); + } - /* - * search for a small prime factor - */ - top = ((limit < MAX_MAP_VAL) ? limit : MAX_MAP_VAL); - for (tp = prime; *tp <= top && *tp != 1; ++tp) { - if (val%(*tp) == 0) { - return ((FULL)*tp); - } - } + /* + * search for a small prime factor + */ + top = ((limit < MAX_MAP_VAL) ? limit : MAX_MAP_VAL); + for (tp = prime; *tp <= top && *tp != 1; ++tp) { + if (val%(*tp) == 0) { + return ((FULL)*tp); + } + } #if FULL_BITS == 64 - /* - * Our search will carry us beyond the prime table. We will - * continue to values until we reach our limit or until a - * factor is found. - * - * It is faster to simply test odd values and ignore non-prime - * factors because the work needed to find the next prime is - * more than the work one saves in not factor with non-prime - * values. - * - * We can improve on this method by skipping odd values that - * are a multiple of 3, 5, 7 and 11. We use a table of - * bytes that indicate the offsets between odd values that - * are not a multiple of 3,4,5,7 & 11. - */ - /* XXX - speed up test for large z by using GCDs */ - j = jmp + jmpptr(NXT_MAP_PRIME); - for (top=NXT_MAP_PRIME; top <= limit; top += nxtjmp(j)) { - if ((val % top) == 0) { - return top; - } - } + /* + * Our search will carry us beyond the prime table. We will + * continue to values until we reach our limit or until a + * factor is found. + * + * It is faster to simply test odd values and ignore non-prime + * factors because the work needed to find the next prime is + * more than the work one saves in not factor with non-prime + * values. + * + * We can improve on this method by skipping odd values that + * are a multiple of 3, 5, 7 and 11. We use a table of + * bytes that indicate the offsets between odd values that + * are not a multiple of 3,4,5,7 & 11. + */ + /* XXX - speed up test for large z by using GCDs */ + j = jmp + jmpptr(NXT_MAP_PRIME); + for (top=NXT_MAP_PRIME; top <= limit; top += nxtjmp(j)) { + if ((val % top) == 0) { + return top; + } + } #endif /* FULL_BITS == 64 */ - /* no prime factors found */ - return 0; - } + /* no prime factors found */ + return 0; + } - /* - * Find a factor of a value that is too large to fit into a FULL. - * - * determine if/what our sqrt factor limit will be - */ - if (zge64b(z)) { - /* we have no factor limit, avoid highest factor */ - factlim = MAX_SM_PRIME-1; - } else if (zge32b(z)) { - /* determine if limit is too small to matter */ - if (limit < BASE) { - factlim = limit; - } else { - /* find the isqrt(z) */ - if (!zsqrt(z, &tmp, 0)) { - /* sqrt is exact */ - factlim = ztofull(tmp); - } else { - /* sqrt is inexact */ - factlim = ztofull(tmp)+1; - } - zfree(tmp); + /* + * Find a factor of a value that is too large to fit into a FULL. + * + * determine if/what our sqrt factor limit will be + */ + if (zge64b(z)) { + /* we have no factor limit, avoid highest factor */ + factlim = MAX_SM_PRIME-1; + } else if (zge32b(z)) { + /* determine if limit is too small to matter */ + if (limit < BASE) { + factlim = limit; + } else { + /* find the isqrt(z) */ + if (!zsqrt(z, &tmp, 0)) { + /* sqrt is exact */ + factlim = ztofull(tmp); + } else { + /* sqrt is inexact */ + factlim = ztofull(tmp)+1; + } + zfree(tmp); - /* avoid highest factor */ - if (factlim >= MAX_SM_PRIME) { - factlim = MAX_SM_PRIME-1; - } - } - } else { - /* determine our factor limit */ - factlim = fsqrt(ztofull(z)); - if (factlim >= MAX_SM_PRIME) { - factlim = MAX_SM_PRIME-1; - } - } - if (factlim > limit) { - factlim = limit; - } + /* avoid highest factor */ + if (factlim >= MAX_SM_PRIME) { + factlim = MAX_SM_PRIME-1; + } + } + } else { + /* determine our factor limit */ + factlim = fsqrt(ztofull(z)); + if (factlim >= MAX_SM_PRIME) { + factlim = MAX_SM_PRIME-1; + } + } + if (factlim > limit) { + factlim = limit; + } - /* - * walk the prime table looking for factors - * - * XXX - consider using gcd of products of primes to speed this - * section up - */ - tlim = (HALF)((factlim >= MAX_MAP_PRIME) ? MAX_MAP_PRIME-1 : factlim); - div.sign = 0; - div.v = divval; - div.len = 1; - for (p=prime; (HALF)*p <= tlim; ++p) { + /* + * walk the prime table looking for factors + * + * XXX - consider using gcd of products of primes to speed this + * section up + */ + tlim = (HALF)((factlim >= MAX_MAP_PRIME) ? MAX_MAP_PRIME-1 : factlim); + div.sign = 0; + div.v = divval; + div.len = 1; + for (p=prime; (HALF)*p <= tlim; ++p) { - /* setup factor */ - div.v[0] = (HALF)(*p); + /* setup factor */ + div.v[0] = (HALF)(*p); - if (zdivides(z, div)) - return (FULL)(*p); - } - if ((FULL)*p > factlim) { - /* no factor found */ - return (FULL)0; - } + if (zdivides(z, div)) + return (FULL)(*p); + } + if ((FULL)*p > factlim) { + /* no factor found */ + return (FULL)0; + } - /* - * test the highest factor possible - */ - div.v[0] = MAX_MAP_PRIME; + /* + * test the highest factor possible + */ + div.v[0] = MAX_MAP_PRIME; - if (zdivides(z, div)) - return (FULL)MAX_MAP_PRIME; + if (zdivides(z, div)) + return (FULL)MAX_MAP_PRIME; - /* - * generate higher test factors as needed - * - * XXX - consider using gcd of products of primes to speed this - * section up - */ + /* + * generate higher test factors as needed + * + * XXX - consider using gcd of products of primes to speed this + * section up + */ #if BASEB == 16 - div.len = 2; + div.len = 2; #endif - factor = NXT_MAP_PRIME; - j = jmp + jmpptr(factor); - for(; factor <= factlim; factor += nxtjmp(j)) { + factor = NXT_MAP_PRIME; + j = jmp + jmpptr(factor); + for(; factor <= factlim; factor += nxtjmp(j)) { - /* setup factor */ + /* setup factor */ #if BASEB == 32 - div.v[0] = (HALF)factor; + div.v[0] = (HALF)factor; #else - div.v[0] = (HALF)(factor & BASE1); - div.v[1] = (HALF)(factor >> BASEB); + div.v[0] = (HALF)(factor & BASE1); + div.v[1] = (HALF)(factor >> BASEB); #endif - if (zdivides(z, div)) - return (FULL)(factor); - } - if (factor >= factlim) { - /* no factor found */ - return (FULL)0; - } + if (zdivides(z, div)) + return (FULL)(factor); + } + if (factor >= factlim) { + /* no factor found */ + return (FULL)0; + } - /* - * test the highest factor possible - */ + /* + * test the highest factor possible + */ #if BASEB == 32 - div.v[0] = MAX_SM_PRIME; + div.v[0] = MAX_SM_PRIME; #else - div.v[0] = (MAX_SM_PRIME & BASE1); - div.v[1] = (MAX_SM_PRIME >> BASEB); + div.v[0] = (MAX_SM_PRIME & BASE1); + div.v[1] = (MAX_SM_PRIME >> BASEB); #endif - if (zdivides(z, div)) - return (FULL)MAX_SM_PRIME; + if (zdivides(z, div)) + return (FULL)MAX_SM_PRIME; - /* - * no factor found - */ - return (FULL)0; + /* + * no factor found + */ + return (FULL)0; } @@ -828,75 +828,75 @@ small_factor(ZVALUE z, FULL limit) void zpfact(ZVALUE z, ZVALUE *dest) { - long n; /* limiting number to multiply by */ - long p; /* current prime */ - CONST unsigned short *tp; /* pointer to a tiny prime */ - CONST unsigned char *j; /* current jump increment */ - ZVALUE res, temp; + long n; /* limiting number to multiply by */ + long p; /* current prime */ + CONST unsigned short *tp; /* pointer to a tiny prime */ + CONST unsigned char *j; /* current jump increment */ + ZVALUE res, temp; - /* firewall */ - if (dest == NULL) { - math_error("%s: dest NULL", __func__); - not_reached(); - } + /* firewall */ + if (dest == NULL) { + math_error("%s: dest NULL", __func__); + not_reached(); + } - /* firewall */ - if (zisneg(z)) { - math_error("Negative argument for factorial"); - not_reached(); - } - if (zge24b(z)) { - math_error("Very large factorial"); - not_reached(); - } - n = ztolong(z); + /* firewall */ + if (zisneg(z)) { + math_error("Negative argument for factorial"); + not_reached(); + } + if (zge24b(z)) { + math_error("Very large factorial"); + not_reached(); + } + n = ztolong(z); - /* - * Deal with table lookup pfact values - */ - if (n <= MAX_PFACT_VAL) { - utoz(pfact_tbl[n], dest); - return; - } + /* + * Deal with table lookup pfact values + */ + if (n <= MAX_PFACT_VAL) { + utoz(pfact_tbl[n], dest); + return; + } - /* - * Multiply by the primes in the static table - */ - utoz(pfact_tbl[MAX_PFACT_VAL], &res); - for (tp=(&prime[NXT_PFACT_VAL]); *tp != 1 && (long)(*tp) <= n; ++tp) { - zmuli(res, *tp, &temp); - zfree(res); - res = temp; - } + /* + * Multiply by the primes in the static table + */ + utoz(pfact_tbl[MAX_PFACT_VAL], &res); + for (tp=(&prime[NXT_PFACT_VAL]); *tp != 1 && (long)(*tp) <= n; ++tp) { + zmuli(res, *tp, &temp); + zfree(res); + res = temp; + } - /* - * if needed, multiply by primes beyond the static table - */ - j = jmp + jmpptr(NXT_MAP_PRIME); - for (p = NXT_MAP_PRIME; p <= n; p += nxtjmp(j)) { - FULL isqr; /* isqrt(p) */ + /* + * if needed, multiply by primes beyond the static table + */ + j = jmp + jmpptr(NXT_MAP_PRIME); + for (p = NXT_MAP_PRIME; p <= n; p += nxtjmp(j)) { + FULL isqr; /* isqrt(p) */ - /* our factor limit - see next_prime for why this works */ - isqr = fsqrt(p)+1; - if ((isqr & 0x1) == 0) { - --isqr; - } + /* our factor limit - see next_prime for why this works */ + isqr = fsqrt(p)+1; + if ((isqr & 0x1) == 0) { + --isqr; + } - /* ignore Saber-C warning #530 about empty for statement */ - /* OK to ignore in proc zpfact */ - /* find the next prime */ - for (tp=prime; (*tp <= isqr) && (p % (long)(*tp)); ++tp) { - } - if (*tp <= isqr && *tp != 1) { - continue; - } + /* ignore Saber-C warning #530 about empty for statement */ + /* OK to ignore in proc zpfact */ + /* find the next prime */ + for (tp=prime; (*tp <= isqr) && (p % (long)(*tp)); ++tp) { + } + if (*tp <= isqr && *tp != 1) { + continue; + } - /* multiply by the next prime */ - zmuli(res, p, &temp); - zfree(res); - res = temp; - } - *dest = res; + /* multiply by the next prime */ + zmuli(res, p, &temp); + zfree(res); + res = temp; + } + *dest = res; } @@ -909,7 +909,7 @@ zpfact(ZVALUE z, ZVALUE *dest) * * It is interesting to note that ptest(a,1,x) (for any x >= 0) of this * test will always return true for a prime, and rarely return true for - * a non-prime. The 1/4 is appears in practice to be a poor upper + * a non-prime. The 1/4 is appears in practice to be a poor upper * bound. Even so the only result that is EXACT and true is when * this test returns false for a non-prime. When ptest returns true, * one cannot determine if the value in question is prime, or the value @@ -925,155 +925,155 @@ zpfact(ZVALUE z, ZVALUE *dest) bool zprimetest(ZVALUE z, long count, ZVALUE skip) { - long limit = 0; /* test odd values from skip up to limit */ - ZVALUE zbase; /* base as a ZVALUE */ - long i, ij, ik; - ZVALUE zm1, z1, z2, z3; - int type; /* random, prime or consecutive integers */ - CONST unsigned short *pr; /* pointer to small prime */ + long limit = 0; /* test odd values from skip up to limit */ + ZVALUE zbase; /* base as a ZVALUE */ + long i, ij, ik; + ZVALUE zm1, z1, z2, z3; + int type; /* random, prime or consecutive integers */ + CONST unsigned short *pr; /* pointer to small prime */ - /* - * firewall - ignore sign of z, values 0 and 1 are not prime - */ - z.sign = 0; - if (zisleone(z)) { - return 0; - } + /* + * firewall - ignore sign of z, values 0 and 1 are not prime + */ + z.sign = 0; + if (zisleone(z)) { + return 0; + } - /* - * firewall - All even values, except 2, are not prime - */ - if (ziseven(z)) - return zistwo(z); + /* + * firewall - All even values, except 2, are not prime + */ + if (ziseven(z)) + return zistwo(z); - if (z.len == 1 && *z.v == 3) - return 1; /* 3 is prime */ + if (z.len == 1 && *z.v == 3) + return 1; /* 3 is prime */ - /* - * we know that z is an odd value > 1 - */ + /* + * we know that z is an odd value > 1 + */ - /* - * Perform trivial checks if count is not negative - */ - if (count >= 0) { + /* + * Perform trivial checks if count is not negative + */ + if (count >= 0) { - /* - * If the number is a small (32 bit) value, do a direct test - */ - if (!zge32b(z)) { - return zisprime(z); - } + /* + * If the number is a small (32 bit) value, do a direct test + */ + if (!zge32b(z)) { + return zisprime(z); + } - /* - * See if the number has a tiny factor. - */ - if (small_factor(z, PTEST_PRECHECK) != 0) { - /* a tiny factor was found */ - return false; - } + /* + * See if the number has a tiny factor. + */ + if (small_factor(z, PTEST_PRECHECK) != 0) { + /* a tiny factor was found */ + return false; + } - /* - * If our count is zero, do nothing more - */ - if (count == 0) { - /* no test was done, so no test failed! */ - return true; - } + /* + * If our count is zero, do nothing more + */ + if (count == 0) { + /* no test was done, so no test failed! */ + return true; + } - } else { - /* use the absolute value of count */ - count = -count; - } - if (z.len < conf->redc2) { - return zredcprimetest(z, count, skip); - } + } else { + /* use the absolute value of count */ + count = -count; + } + if (z.len < conf->redc2) { + return zredcprimetest(z, count, skip); + } - if (ziszero(skip)) { - type = 0; - zbase = _zero_; - } else if (zisone(skip)) { - type = 1; - itoz(2, &zbase); - limit = 1 << 16; - if (!zge16b(z)) - limit = ztolong(z); - } else { - type = 2; - if (zrel(skip, z) >= 0 || zisneg(skip)) - zmod(skip, z, &zbase, 0); - else - zcopy(skip, &zbase); - } - /* - * Loop over various bases, testing each one. - */ - zsub(z, _one_, &zm1); - ik = zlowbit(zm1); - zshift(zm1, -ik, &z1); - pr = prime; - for (i = 0; i < count; i++) { - switch (type) { - case 0: - zfree(zbase); - zrandrange(_two_, zm1, &zbase); - break; - case 1: - if (i == 0) - break; - zfree(zbase); - if (*pr == 1 || (long)*pr >= limit) { - zfree(z1); - zfree(zm1); - return true; - } - itoz((long) *pr++, &zbase); - break; - default: - if (i == 0) - break; - zadd(zbase, _one_, &z3); - zfree(zbase); - zbase = z3; - } + if (ziszero(skip)) { + type = 0; + zbase = _zero_; + } else if (zisone(skip)) { + type = 1; + itoz(2, &zbase); + limit = 1 << 16; + if (!zge16b(z)) + limit = ztolong(z); + } else { + type = 2; + if (zrel(skip, z) >= 0 || zisneg(skip)) + zmod(skip, z, &zbase, 0); + else + zcopy(skip, &zbase); + } + /* + * Loop over various bases, testing each one. + */ + zsub(z, _one_, &zm1); + ik = zlowbit(zm1); + zshift(zm1, -ik, &z1); + pr = prime; + for (i = 0; i < count; i++) { + switch (type) { + case 0: + zfree(zbase); + zrandrange(_two_, zm1, &zbase); + break; + case 1: + if (i == 0) + break; + zfree(zbase); + if (*pr == 1 || (long)*pr >= limit) { + zfree(z1); + zfree(zm1); + return true; + } + itoz((long) *pr++, &zbase); + break; + default: + if (i == 0) + break; + zadd(zbase, _one_, &z3); + zfree(zbase); + zbase = z3; + } - ij = 0; - zpowermod(zbase, z1, z, &z3); - for (;;) { - if (zisone(z3)) { - if (ij) { - /* number is definitely not prime */ - zfree(z3); - zfree(zm1); - zfree(z1); - zfree(zbase); - return false; - } - break; - } - if (!zcmp(z3, zm1)) - break; - if (++ij >= ik) { - /* number is definitely not prime */ - zfree(z3); - zfree(zm1); - zfree(z1); - zfree(zbase); - return false; - } - zsquare(z3, &z2); - zfree(z3); - zmod(z2, z, &z3, 0); - zfree(z2); - } - zfree(z3); - } - zfree(zm1); - zfree(z1); - zfree(zbase); + ij = 0; + zpowermod(zbase, z1, z, &z3); + for (;;) { + if (zisone(z3)) { + if (ij) { + /* number is definitely not prime */ + zfree(z3); + zfree(zm1); + zfree(z1); + zfree(zbase); + return false; + } + break; + } + if (!zcmp(z3, zm1)) + break; + if (++ij >= ik) { + /* number is definitely not prime */ + zfree(z3); + zfree(zm1); + zfree(z1); + zfree(zbase); + return false; + } + zsquare(z3, &z2); + zfree(z3); + zmod(z2, z, &z3, 0); + zfree(z2); + } + zfree(z3); + } + zfree(zm1); + zfree(z1); + zfree(zbase); - /* number might be prime */ - return true; + /* number might be prime */ + return true; } @@ -1084,321 +1084,321 @@ zprimetest(ZVALUE z, long count, ZVALUE skip) bool zredcprimetest(ZVALUE z, long count, ZVALUE skip) { - long limit = 0; /* test odd values from skip up to limit */ - ZVALUE zbase; /* base as a ZVALUE */ - REDC *rp; - long i, ij, ik; - ZVALUE zm1, z1, z2, z3; - ZVALUE zredcm1; - int type; /* random, prime or consecutive integers */ - CONST unsigned short *pr; /* pointer to small prime */ + long limit = 0; /* test odd values from skip up to limit */ + ZVALUE zbase; /* base as a ZVALUE */ + REDC *rp; + long i, ij, ik; + ZVALUE zm1, z1, z2, z3; + ZVALUE zredcm1; + int type; /* random, prime or consecutive integers */ + CONST unsigned short *pr; /* pointer to small prime */ - rp = zredcalloc(z); - zsub(z, rp->one, &zredcm1); - if (ziszero(skip)) { - zbase = _zero_; - type = 0; - } else if (zisone(skip)) { - itoz(2, &zbase); - type = 1; - limit = 1 << 16; - if (!zge16b(z)) - limit = ztolong(z); - } else { - zredcencode(rp, skip, &zbase); - type = 2; - } - /* - * Loop over various "random" numbers, testing each one. - */ - zsub(z, _one_, &zm1); - ik = zlowbit(zm1); - zshift(zm1, -ik, &z1); - pr = prime; + rp = zredcalloc(z); + zsub(z, rp->one, &zredcm1); + if (ziszero(skip)) { + zbase = _zero_; + type = 0; + } else if (zisone(skip)) { + itoz(2, &zbase); + type = 1; + limit = 1 << 16; + if (!zge16b(z)) + limit = ztolong(z); + } else { + zredcencode(rp, skip, &zbase); + type = 2; + } + /* + * Loop over various "random" numbers, testing each one. + */ + zsub(z, _one_, &zm1); + ik = zlowbit(zm1); + zshift(zm1, -ik, &z1); + pr = prime; - for (i = 0; i < count; i++) { - switch (type) { - case 0: - do { - zfree(zbase); - zrandrange(_one_, z, &zbase); - } - while (!zcmp(zbase, rp->one) || - !zcmp(zbase, zredcm1)); - break; - case 1: - if (i == 0) { - break; - } - zfree(zbase); - if (*pr == 1 || (long)*pr >= limit) { - zfree(z1); - zfree(zm1); - if (z.len < conf->redc2) { - zredcfree(rp); - zfree(zredcm1); - } - return true; - } - itoz((long) *pr++, &z3); - zredcencode(rp, z3, &zbase); - zfree(z3); - break; - default: - if (i == 0) - break; - zadd(zbase, rp->one, &z3); - zfree(zbase); - zbase = z3; - if (zrel(zbase, z) >= 0) { - zsub(zbase, z, &z3); - zfree(zbase); - zbase = z3; - } - } + for (i = 0; i < count; i++) { + switch (type) { + case 0: + do { + zfree(zbase); + zrandrange(_one_, z, &zbase); + } + while (!zcmp(zbase, rp->one) || + !zcmp(zbase, zredcm1)); + break; + case 1: + if (i == 0) { + break; + } + zfree(zbase); + if (*pr == 1 || (long)*pr >= limit) { + zfree(z1); + zfree(zm1); + if (z.len < conf->redc2) { + zredcfree(rp); + zfree(zredcm1); + } + return true; + } + itoz((long) *pr++, &z3); + zredcencode(rp, z3, &zbase); + zfree(z3); + break; + default: + if (i == 0) + break; + zadd(zbase, rp->one, &z3); + zfree(zbase); + zbase = z3; + if (zrel(zbase, z) >= 0) { + zsub(zbase, z, &z3); + zfree(zbase); + zbase = z3; + } + } - ij = 0; - zredcpower(rp, zbase, z1, &z3); - for (;;) { - if (!zcmp(z3, rp->one)) { - if (ij) { - /* number is definitely not prime */ - zfree(z3); - zfree(zm1); - zfree(z1); - zfree(zbase); - zredcfree(rp); - zfree(zredcm1); - return false; - } - break; - } - if (!zcmp(z3, zredcm1)) - break; - if (++ij >= ik) { - /* number is definitely not prime */ - zfree(z3); - zfree(zm1); - zfree(z1); - zfree(zbase); - zredcfree(rp); - zfree(zredcm1); - return false; - } - zredcsquare(rp, z3, &z2); - zfree(z3); - z3 = z2; - } - zfree(z3); - } - zfree(zbase); - zredcfree(rp); - zfree(zredcm1); - zfree(zm1); - zfree(z1); + ij = 0; + zredcpower(rp, zbase, z1, &z3); + for (;;) { + if (!zcmp(z3, rp->one)) { + if (ij) { + /* number is definitely not prime */ + zfree(z3); + zfree(zm1); + zfree(z1); + zfree(zbase); + zredcfree(rp); + zfree(zredcm1); + return false; + } + break; + } + if (!zcmp(z3, zredcm1)) + break; + if (++ij >= ik) { + /* number is definitely not prime */ + zfree(z3); + zfree(zm1); + zfree(z1); + zfree(zbase); + zredcfree(rp); + zfree(zredcm1); + return false; + } + zredcsquare(rp, z3, &z2); + zfree(z3); + z3 = z2; + } + zfree(z3); + } + zfree(zbase); + zredcfree(rp); + zfree(zredcm1); + zfree(zm1); + zfree(z1); - /* number might be prime */ - return true; + /* number might be prime */ + return true; } /* * znextcand - find the next integer that passes ptest(). - * The signs of z and mod are ignored. Result is the least integer + * The signs of z and mod are ignored. Result is the least integer * greater than abs(z) congruent to res modulo abs(mod), or if there * is no such integer, zero. * * given: - * z search point > 2 - * count ptests to perform per candidate - * skip ptests to skip - * res return congruent to res modulo abs(mod) - * mod congruent to res modulo abs(mod) - * cand candidate found + * z search point > 2 + * count ptests to perform per candidate + * skip ptests to skip + * res return congruent to res modulo abs(mod) + * mod congruent to res modulo abs(mod) + * cand candidate found */ bool znextcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, - ZVALUE *cand) + ZVALUE *cand) { - ZVALUE tmp1; - ZVALUE tmp2; + ZVALUE tmp1; + ZVALUE tmp2; - /* firewall */ - if (cand == NULL) { - math_error("%s: cand NULL", __func__); - not_reached(); - } + /* firewall */ + if (cand == NULL) { + math_error("%s: cand NULL", __func__); + not_reached(); + } - z.sign = 0; - mod.sign = 0; - if (ziszero(mod)) { - if (zrel(res, z) > 0 && zprimetest(res, count, skip)) { - zcopy(res, cand); - return true; - } - return false; - } - if (ziszero(z) && zisone(mod)) { - zcopy(_two_, cand); - return true; - } - zsub(res, z, &tmp1); - if (zmod(tmp1, mod, &tmp2, 0)) - zadd(z, tmp2, cand); - else - zadd(z, mod, cand); + z.sign = 0; + mod.sign = 0; + if (ziszero(mod)) { + if (zrel(res, z) > 0 && zprimetest(res, count, skip)) { + zcopy(res, cand); + return true; + } + return false; + } + if (ziszero(z) && zisone(mod)) { + zcopy(_two_, cand); + return true; + } + zsub(res, z, &tmp1); + if (zmod(tmp1, mod, &tmp2, 0)) + zadd(z, tmp2, cand); + else + zadd(z, mod, cand); - /* - * Now *cand is least integer greater than abs(z) and congruent - * to res modulo mod. - */ - zfree(tmp1); - zfree(tmp2); - if (zprimetest(*cand, count, skip)) - return true; - zgcd(*cand, mod, &tmp1); - if (!zisone(tmp1)) { - zfree(tmp1); - zfree(*cand); - return false; - } - zfree(tmp1); - if (ziseven(*cand)) { - zadd(*cand, mod, &tmp1); - zfree(*cand); - *cand = tmp1; - if (zprimetest(*cand, count, skip)) - return true; - } - /* - * *cand is now least odd integer > abs(z) and congruent to - * res modulo mod. - */ - if (zisodd(mod)) - zshift(mod, 1, &tmp1); - else - zcopy(mod, &tmp1); - do { - zadd(*cand, tmp1, &tmp2); - zfree(*cand); - *cand = tmp2; - } while (!zprimetest(*cand, count, skip)); - zfree(tmp1); - return true; + /* + * Now *cand is least integer greater than abs(z) and congruent + * to res modulo mod. + */ + zfree(tmp1); + zfree(tmp2); + if (zprimetest(*cand, count, skip)) + return true; + zgcd(*cand, mod, &tmp1); + if (!zisone(tmp1)) { + zfree(tmp1); + zfree(*cand); + return false; + } + zfree(tmp1); + if (ziseven(*cand)) { + zadd(*cand, mod, &tmp1); + zfree(*cand); + *cand = tmp1; + if (zprimetest(*cand, count, skip)) + return true; + } + /* + * *cand is now least odd integer > abs(z) and congruent to + * res modulo mod. + */ + if (zisodd(mod)) + zshift(mod, 1, &tmp1); + else + zcopy(mod, &tmp1); + do { + zadd(*cand, tmp1, &tmp2); + zfree(*cand); + *cand = tmp2; + } while (!zprimetest(*cand, count, skip)); + zfree(tmp1); + return true; } /* * zprevcand - find the nearest previous integer that passes ptest(). - * The signs of z and mod are ignored. Result is greatest positive integer + * The signs of z and mod are ignored. Result is greatest positive integer * less than abs(z) congruent to res modulo abs(mod), or if there * is no such integer, zero. * * given: - * z search point > 2 - * count ptests to perform per candidate - * skip ptests to skip - * res return congruent to res modulo abs(mod) - * mod congruent to res modulo abs(mod) - * cand candidate found + * z search point > 2 + * count ptests to perform per candidate + * skip ptests to skip + * res return congruent to res modulo abs(mod) + * mod congruent to res modulo abs(mod) + * cand candidate found */ bool zprevcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, - ZVALUE *cand) + ZVALUE *cand) { - ZVALUE tmp1; - ZVALUE tmp2; + ZVALUE tmp1; + ZVALUE tmp2; - /* firewall */ - if (cand == NULL) { - math_error("%s: cand NULL", __func__); - not_reached(); - } + /* firewall */ + if (cand == NULL) { + math_error("%s: cand NULL", __func__); + not_reached(); + } - z.sign = 0; - mod.sign = 0; - if (ziszero(mod)) { - if (zispos(res)&&zrel(res, z)<0 && zprimetest(res,count,skip)) { - zcopy(res, cand); - return true; - } - return false; - } - zsub(z, res, &tmp1); - if (zmod(tmp1, mod, &tmp2, 0)) - zsub(z, tmp2, cand); - else - zsub(z, mod, cand); - /* - * *cand is now the greatest integer < z that is congruent to res - * modulo mod. - */ - zfree(tmp1); - zfree(tmp2); - if (zisneg(*cand)) { - zfree(*cand); - return false; - } - if (zprimetest(*cand, count, skip)) - return true; - zgcd(*cand, mod, &tmp1); - if (!zisone(tmp1)) { - zfree(tmp1); - zmod(*cand, mod, &tmp1, 0); - zfree(*cand); - if (zprimetest(tmp1, count, skip)) { - *cand = tmp1; - return true; - } - if (ziszero(tmp1)) { - zfree(tmp1); - if (zprimetest(mod, count, skip)) { - zcopy(mod, cand); - return true; - } - return false; - } - zfree(tmp1); - return false; - } - zfree(tmp1); - if (ziseven(*cand)) { - zsub(*cand, mod, &tmp1); - zfree(*cand); - if (zisneg(tmp1)) { - zfree(tmp1); - return false; - } - *cand = tmp1; - if (zprimetest(*cand, count, skip)) - return true; - } - /* - * *cand is now the greatest odd integer < z that is congruent to - * res modulo mod. - */ - if (zisodd(mod)) - zshift(mod, 1, &tmp1); - else - zcopy(mod, &tmp1); + z.sign = 0; + mod.sign = 0; + if (ziszero(mod)) { + if (zispos(res)&&zrel(res, z)<0 && zprimetest(res,count,skip)) { + zcopy(res, cand); + return true; + } + return false; + } + zsub(z, res, &tmp1); + if (zmod(tmp1, mod, &tmp2, 0)) + zsub(z, tmp2, cand); + else + zsub(z, mod, cand); + /* + * *cand is now the greatest integer < z that is congruent to res + * modulo mod. + */ + zfree(tmp1); + zfree(tmp2); + if (zisneg(*cand)) { + zfree(*cand); + return false; + } + if (zprimetest(*cand, count, skip)) + return true; + zgcd(*cand, mod, &tmp1); + if (!zisone(tmp1)) { + zfree(tmp1); + zmod(*cand, mod, &tmp1, 0); + zfree(*cand); + if (zprimetest(tmp1, count, skip)) { + *cand = tmp1; + return true; + } + if (ziszero(tmp1)) { + zfree(tmp1); + if (zprimetest(mod, count, skip)) { + zcopy(mod, cand); + return true; + } + return false; + } + zfree(tmp1); + return false; + } + zfree(tmp1); + if (ziseven(*cand)) { + zsub(*cand, mod, &tmp1); + zfree(*cand); + if (zisneg(tmp1)) { + zfree(tmp1); + return false; + } + *cand = tmp1; + if (zprimetest(*cand, count, skip)) + return true; + } + /* + * *cand is now the greatest odd integer < z that is congruent to + * res modulo mod. + */ + if (zisodd(mod)) + zshift(mod, 1, &tmp1); + else + zcopy(mod, &tmp1); - do { - zsub(*cand, tmp1, &tmp2); - zfree(*cand); - *cand = tmp2; - } while (!zprimetest(*cand, count, skip) && !zisneg(*cand)); - zfree(tmp1); - if (zisneg(*cand)) { - zadd(*cand, mod, &tmp1); - zfree(*cand); - *cand = tmp1; - if (zistwo(*cand)) - return true; - zfree(*cand); - return false; - } - return true; + do { + zsub(*cand, tmp1, &tmp2); + zfree(*cand); + *cand = tmp2; + } while (!zprimetest(*cand, count, skip) && !zisneg(*cand)); + zfree(tmp1); + if (zisneg(*cand)) { + zadd(*cand, mod, &tmp1); + zfree(*cand); + *cand = tmp1; + if (zistwo(*cand)) + return true; + zfree(*cand); + return false; + } + return true; } @@ -1407,139 +1407,139 @@ zprevcand(ZVALUE z, long count, ZVALUE skip, ZVALUE res, ZVALUE mod, * Search is conducted for the first count primes. * * Returns: - * 1 no factor found or z < 3 - * >1 factor found + * 1 no factor found or z < 3 + * >1 factor found */ FULL zlowfactor(ZVALUE z, long count) { - FULL factlim; /* highest factor to test */ - CONST unsigned short *p; /* test factor */ - FULL factor; /* test factor */ - HALF tlim; /* limit on prime table use */ - HALF divval[2]; /* divisor value */ - ZVALUE div; /* test factor/divisor */ - ZVALUE tmp; + FULL factlim; /* highest factor to test */ + CONST unsigned short *p; /* test factor */ + FULL factor; /* test factor */ + HALF tlim; /* limit on prime table use */ + HALF divval[2]; /* divisor value */ + ZVALUE div; /* test factor/divisor */ + ZVALUE tmp; - z.sign = 0; + z.sign = 0; - /* - * firewall - */ - if (count <= 0 || zisleone(z) || zistwo(z)) { - /* number is < 3 or count is <= 0 */ - return (FULL)1; - } + /* + * firewall + */ + if (count <= 0 || zisleone(z) || zistwo(z)) { + /* number is < 3 or count is <= 0 */ + return (FULL)1; + } - /* - * test for the first factor - */ - if (ziseven(z)) { - return (FULL)2; - } - if (count <= 1) { - /* count was 1, tested the one and only factor */ - return (FULL)1; - } + /* + * test for the first factor + */ + if (ziseven(z)) { + return (FULL)2; + } + if (count <= 1) { + /* count was 1, tested the one and only factor */ + return (FULL)1; + } - /* - * determine if/what our sqrt factor limit will be - */ - if (zge64b(z)) { - /* we have no factor limit, avoid highest factor */ - factlim = MAX_SM_PRIME-1; - } else if (zge32b(z)) { - /* find the isqrt(z) */ - if (!zsqrt(z, &tmp, 0)) { - /* sqrt is exact */ - factlim = ztofull(tmp); - } else { - /* sqrt is inexact */ - factlim = ztofull(tmp)+1; - } - zfree(tmp); + /* + * determine if/what our sqrt factor limit will be + */ + if (zge64b(z)) { + /* we have no factor limit, avoid highest factor */ + factlim = MAX_SM_PRIME-1; + } else if (zge32b(z)) { + /* find the isqrt(z) */ + if (!zsqrt(z, &tmp, 0)) { + /* sqrt is exact */ + factlim = ztofull(tmp); + } else { + /* sqrt is inexact */ + factlim = ztofull(tmp)+1; + } + zfree(tmp); - /* avoid highest factor */ - if (factlim >= MAX_SM_PRIME) { - factlim = MAX_SM_PRIME-1; - } - } else { - /* determine our factor limit */ - factlim = fsqrt(ztofull(z)); - } - if (factlim >= MAX_SM_PRIME) { - factlim = MAX_SM_PRIME-1; - } + /* avoid highest factor */ + if (factlim >= MAX_SM_PRIME) { + factlim = MAX_SM_PRIME-1; + } + } else { + /* determine our factor limit */ + factlim = fsqrt(ztofull(z)); + } + if (factlim >= MAX_SM_PRIME) { + factlim = MAX_SM_PRIME-1; + } - /* - * walk the prime table looking for factors - */ - tlim = (HALF)((factlim >= MAX_MAP_PRIME) ? MAX_MAP_PRIME-1 : factlim); - div.sign = 0; - div.v = divval; - div.len = 1; - for (p=prime, --count; count > 0 && (HALF)*p <= tlim; ++p, --count) { + /* + * walk the prime table looking for factors + */ + tlim = (HALF)((factlim >= MAX_MAP_PRIME) ? MAX_MAP_PRIME-1 : factlim); + div.sign = 0; + div.v = divval; + div.len = 1; + for (p=prime, --count; count > 0 && (HALF)*p <= tlim; ++p, --count) { - /* setup factor */ - div.v[0] = (HALF)(*p); + /* setup factor */ + div.v[0] = (HALF)(*p); - if (zdivides(z, div)) - return (FULL)(*p); - } - if (count <= 0 || (FULL)*p > factlim) { - /* no factor found */ - return (FULL)1; - } + if (zdivides(z, div)) + return (FULL)(*p); + } + if (count <= 0 || (FULL)*p > factlim) { + /* no factor found */ + return (FULL)1; + } - /* - * test the highest factor possible - */ - div.v[0] = MAX_MAP_PRIME; - if (zdivides(z, div)) - return (FULL)MAX_MAP_PRIME; + /* + * test the highest factor possible + */ + div.v[0] = MAX_MAP_PRIME; + if (zdivides(z, div)) + return (FULL)MAX_MAP_PRIME; - /* - * generate higher test factors as needed - */ + /* + * generate higher test factors as needed + */ #if BASEB == 16 - div.len = 2; + div.len = 2; #endif - for(factor = NXT_MAP_PRIME; - count > 0 && factor <= factlim; - factor = next_prime(factor), --count) { + for(factor = NXT_MAP_PRIME; + count > 0 && factor <= factlim; + factor = next_prime(factor), --count) { - /* setup factor */ + /* setup factor */ #if BASEB == 32 - div.v[0] = (HALF)factor; + div.v[0] = (HALF)factor; #else - div.v[0] = (HALF)(factor & BASE1); - div.v[1] = (HALF)(factor >> BASEB); + div.v[0] = (HALF)(factor & BASE1); + div.v[1] = (HALF)(factor >> BASEB); #endif - if (zdivides(z, div)) - return (FULL)(factor); - } - if (count <= 0 || factor >= factlim) { - /* no factor found */ - return (FULL)1; - } + if (zdivides(z, div)) + return (FULL)(factor); + } + if (count <= 0 || factor >= factlim) { + /* no factor found */ + return (FULL)1; + } - /* - * test the highest factor possible - */ + /* + * test the highest factor possible + */ #if BASEB == 32 - div.v[0] = MAX_SM_PRIME; + div.v[0] = MAX_SM_PRIME; #else - div.v[0] = (MAX_SM_PRIME & BASE1); - div.v[1] = (MAX_SM_PRIME >> BASEB); + div.v[0] = (MAX_SM_PRIME & BASE1); + div.v[1] = (MAX_SM_PRIME >> BASEB); #endif - if (zdivides(z, div)) - return (FULL)MAX_SM_PRIME; + if (zdivides(z, div)) + return (FULL)MAX_SM_PRIME; - /* - * no factor found - */ - return (FULL)1; + /* + * no factor found + */ + return (FULL)1; } @@ -1550,59 +1550,59 @@ zlowfactor(ZVALUE z, long count) void zlcmfact(ZVALUE z, ZVALUE *dest) { - long n; /* limiting number to multiply by */ - long p; /* current prime */ - long pp = 0; /* power of prime */ - long i; /* test value */ - CONST unsigned short *pr; /* pointer to a small prime */ - ZVALUE res, temp; + long n; /* limiting number to multiply by */ + long p; /* current prime */ + long pp = 0; /* power of prime */ + long i; /* test value */ + CONST unsigned short *pr; /* pointer to a small prime */ + ZVALUE res, temp; - /* firewall */ - if (dest == NULL) { - math_error("%s: dest NULL", __func__); - not_reached(); - } + /* firewall */ + if (dest == NULL) { + math_error("%s: dest NULL", __func__); + not_reached(); + } - if (zisneg(z) || ziszero(z)) { - math_error("Non-positive argument for lcmfact"); - not_reached(); - } - if (zge24b(z)) { - math_error("Very large lcmfact"); - not_reached(); - } - n = ztolong(z); - /* - * Multiply by powers of the necessary odd primes in order. - * The power for each prime is the highest one which is not - * more than the specified number. - */ - res = _one_; - for (pr=prime; (long)(*pr) <= n && *pr > 1; ++pr) { - i = p = *pr; - while (i <= n) { - pp = i; - i *= p; - } - zmuli(res, pp, &temp); - zfree(res); - res = temp; - } - for (p = NXT_MAP_PRIME; p <= n; p = (long)next_prime(p)) { - i = p; - while (i <= n) { - pp = i; - i *= p; - } - zmuli(res, pp, &temp); - zfree(res); - res = temp; - } - /* - * Finish by scaling by the necessary power of two. - */ - zshift(res, zhighbit(z), dest); - zfree(res); + if (zisneg(z) || ziszero(z)) { + math_error("Non-positive argument for lcmfact"); + not_reached(); + } + if (zge24b(z)) { + math_error("Very large lcmfact"); + not_reached(); + } + n = ztolong(z); + /* + * Multiply by powers of the necessary odd primes in order. + * The power for each prime is the highest one which is not + * more than the specified number. + */ + res = _one_; + for (pr=prime; (long)(*pr) <= n && *pr > 1; ++pr) { + i = p = *pr; + while (i <= n) { + pp = i; + i *= p; + } + zmuli(res, pp, &temp); + zfree(res); + res = temp; + } + for (p = NXT_MAP_PRIME; p <= n; p = (long)next_prime(p)) { + i = p; + while (i <= n) { + pp = i; + i *= p; + } + zmuli(res, pp, &temp); + zfree(res); + res = temp; + } + /* + * Finish by scaling by the necessary power of two. + */ + zshift(res, zhighbit(z), dest); + zfree(res); } @@ -1618,34 +1618,34 @@ zlcmfact(ZVALUE z, ZVALUE *dest) * fsqrt(x)-1 == (FULL)sqrt((double)x) for all 0 <= x < 2^32. * * given: - * x compute the integer square root of x + * x compute the integer square root of x */ S_FUNC FULL fsqrt(FULL x) { - FULL y; /* (FULL)temporary value */ - int i; + FULL y; /* (FULL)temporary value */ + int i; - /* firewall - deal with 0 */ - if (x == 0) { - return 0; - } + /* firewall - deal with 0 */ + if (x == 0) { + return 0; + } - /* ignore Saber-C warning #530 about empty for statement */ - /* OK to ignore in proc fsqrt */ - /* determine our initial guess */ - for (i=0, y=x; y >= (FULL)256; i+=8, y>>=8) { - } - y = isqrt_pow2[i + topbit[y]]; + /* ignore Saber-C warning #530 about empty for statement */ + /* OK to ignore in proc fsqrt */ + /* determine our initial guess */ + for (i=0, y=x; y >= (FULL)256; i+=8, y>>=8) { + } + y = isqrt_pow2[i + topbit[y]]; - /* perform 3 Newton interactions */ - y = (y+x/y)>>1; - y = (y+x/y)>>1; - y = (y+x/y)>>1; + /* perform 3 Newton interactions */ + y = (y+x/y)>>1; + y = (y+x/y)>>1; + y = (y+x/y)>>1; #if FULL_BITS == 64 - y = (y+x/y)>>1; + y = (y+x/y)>>1; #endif - /* return the result */ - return y; + /* return the result */ + return y; } diff --git a/zrand.c b/zrand.c index 50394d0..c65720b 100644 --- a/zrand.c +++ b/zrand.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/01/07 09:45:25 - * File existed as early as: 1994 + * Under source code control: 1995/01/07 09:45:25 + * File existed as early as: 1994 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -30,35 +30,35 @@ * This module contains an Subtractive 100 shuffle generator wrapped inside * of a shuffle generator. * - * We refer to this generator as the s100 generator. + * We refer to this generator as the s100 generator. * - * rand - s100 shuffle generator - * srand - seed the s100 shuffle generator + * rand - s100 shuffle generator + * srand - seed the s100 shuffle generator * - * This generator has two distinct parts, the s100 generator - * and the shuffle generator. + * This generator has two distinct parts, the s100 generator + * and the shuffle generator. * - * The subtractive 100 generator is described in Knuth's "The Art of - * Computer Programming - Seminumerical Algorithms", Vol 2, 3rd edition - * (1998), Section 3.6, page 186, formula (2). + * The subtractive 100 generator is described in Knuth's "The Art of + * Computer Programming - Seminumerical Algorithms", Vol 2, 3rd edition + * (1998), Section 3.6, page 186, formula (2). * - * The "use only the first 100 our of every 1009" is described in - * Knuth's "The Art of Computer Programming - Seminumerical Algorithms", - * Vol 2, 3rd edition (1998), Section 3.6, page 188". + * The "use only the first 100 our of every 1009" is described in + * Knuth's "The Art of Computer Programming - Seminumerical Algorithms", + * Vol 2, 3rd edition (1998), Section 3.6, page 188". * - * The period and other properties of this generator make it very - * useful to 'seed' other generators. + * The period and other properties of this generator make it very + * useful to 'seed' other generators. * - * The shuffle generator is described in Knuth's "The Art of Computer - * Programming - Seminumerical Algorithms", Vol 2, 3rd edition (1998), - * Section 3.2.2, page 34, Algorithm B. + * The shuffle generator is described in Knuth's "The Art of Computer + * Programming - Seminumerical Algorithms", Vol 2, 3rd edition (1998), + * Section 3.2.2, page 34, Algorithm B. * - * The shuffle generator is fast and serves as a fairly good standard - * pseudo-random generator. If you need a fast generator and do not - * need a cryptographically strong one, this generator is likely to do - * the job. + * The shuffle generator is fast and serves as a fairly good standard + * pseudo-random generator. If you need a fast generator and do not + * need a cryptographically strong one, this generator is likely to do + * the job. * - * The shuffle generator is feed values by the subtractive 100 process. + * The shuffle generator is feed values by the subtractive 100 process. * ****************************************************************************** * @@ -66,27 +66,27 @@ * * The goals of this package are: * - * all magic numbers are explained + * all magic numbers are explained * - * I distrust systems with constants (magic numbers) and tables - * that have no justification. I believe that I have - * done my best to justify all of the magic numbers used. + * I distrust systems with constants (magic numbers) and tables + * that have no justification. I believe that I have + * done my best to justify all of the magic numbers used. * - * full documentation + * full documentation * - * You have this source file, plus background publications, - * what more could you ask? + * You have this source file, plus background publications, + * what more could you ask? * - * large selection of seeds + * large selection of seeds * - * Seeds are not limited to a small number of bits. A seed - * may be of any size. + * Seeds are not limited to a small number of bits. A seed + * may be of any size. * - * the strength of the generators may be tuned to meet the need + * the strength of the generators may be tuned to meet the need * - * By using the appropriate seed and other arguments, one may - * increase the strength of the generator to suit the need of - * the application. One does not have just a few levels. + * By using the appropriate seed and other arguments, one may + * increase the strength of the generator to suit the need of + * the application. One does not have just a few levels. * * Even though I have done my best to implement a good system, you still * must use these routines your own risk. @@ -106,12 +106,12 @@ * * The s100 generator uses 2 tables: * - * subtractive table - 100 entries of 64 bits used by the subtractive 100 - * part of the s100 generator + * subtractive table - 100 entries of 64 bits used by the subtractive 100 + * part of the s100 generator * - * shuffle table - 256 entries of 64 bits used by the shuffle - * part of the s100 generator and feed by the - * subtractive table. + * shuffle table - 256 entries of 64 bits used by the shuffle + * part of the s100 generator and feed by the + * subtractive table. * * Casual direct use of the shuffle generator may be acceptable. If one * desires cryptographically strong random numbers, or if one is paranoid, @@ -119,25 +119,25 @@ * * The s100 generator as the following calc interfaces: * - * rand(min,beyond) (where min < beyond) + * rand(min,beyond) (where min < beyond) * - * Print an s100 generator random value over interval [a,b). + * Print an s100 generator random value over interval [a,b). * * rand() * - * Same as rand(0, 2^64). Print 64 bits. + * Same as rand(0, 2^64). Print 64 bits. * - * rand(lim) (where 0 > lim) + * rand(lim) (where 0 > lim) * - * Same as rand(0, lim). + * Same as rand(0, lim). * - * randbit(x) (where x > 0) + * randbit(x) (where x > 0) * - * Same as rand(0, 2^x). Print x bits. + * Same as rand(0, 2^x). Print x bits. * - * randbit(skip) (where skip < 0) + * randbit(skip) (where skip < 0) * - * Skip random bits and return the bit skip count (-skip). + * Skip random bits and return the bit skip count (-skip). */ /* @@ -150,31 +150,31 @@ * * Using a seed of '0' will reload generators with their initial states. * - * srand(0) restore subtractive 100 generator to the initial state + * srand(0) restore subtractive 100 generator to the initial state * * The above single arg calls are fairly fast. * * Optimal seed range for the s100 generator: * - * There is no limit on the size of a seed. On the other hand, - * extremely large seeds require large tables and long seed times. - * Using a seed in the range of [2^64, 2^64 * 100!) should be - * sufficient for most purposes. An easy way to stay within this - * range to to use seeds that are between 21 and 178 digits, or - * 64 to 588 bits long. + * There is no limit on the size of a seed. On the other hand, + * extremely large seeds require large tables and long seed times. + * Using a seed in the range of [2^64, 2^64 * 100!) should be + * sufficient for most purposes. An easy way to stay within this + * range to to use seeds that are between 21 and 178 digits, or + * 64 to 588 bits long. * - * To help make the generator produced by seed S, significantly - * different from S+1, seeds are scrambled prior to use. The - * function randreseed64() maps [0,2^64) into [0,2^64) in a 1-to-1 - * and onto fashion. + * To help make the generator produced by seed S, significantly + * different from S+1, seeds are scrambled prior to use. The + * function randreseed64() maps [0,2^64) into [0,2^64) in a 1-to-1 + * and onto fashion. * - * The purpose of the randreseed64() is not to add security. It - * simply helps remove the human perception of the relationship - * between the seed and the production of the generator. + * The purpose of the randreseed64() is not to add security. It + * simply helps remove the human perception of the relationship + * between the seed and the production of the generator. * - * The randreseed64() process does not reduce the security of the - * generators. Every seed is converted into a different unique seed. - * No seed is ignored or favored. + * The randreseed64() process does not reduce the security of the + * generators. Every seed is converted into a different unique seed. + * No seed is ignored or favored. * ****************************************************************************** * @@ -184,41 +184,41 @@ * * seed != 0: * --------- - * Any buffered random bits are flushed. The subtractive table is loaded - * with the default subtractive table. The low order 64 bits of seed is - * xor-ed against each table value. The subtractive table is shuffled - * according to seed/2^64. + * Any buffered random bits are flushed. The subtractive table is loaded + * with the default subtractive table. The low order 64 bits of seed is + * xor-ed against each table value. The subtractive table is shuffled + * according to seed/2^64. * - * The following calc code produces the same effect: + * The following calc code produces the same effect: * - * (* reload default subtractive table xor-ed with low 64 seed bits *) - * seed_xor = seed & ((1<<64)-1); - * for (i=0; i < 100; ++i) { - * subtractive[i] = xor(default_subtractive[i], seed_xor); - * } + * (* reload default subtractive table xor-ed with low 64 seed bits *) + * seed_xor = seed & ((1<<64)-1); + * for (i=0; i < 100; ++i) { + * subtractive[i] = xor(default_subtractive[i], seed_xor); + * } * - * (* shuffle the subtractive table *) - * seed >>= 64; - * for (i=100; seed > 0 && i > 0; --i) { - * quomod(seed, i+1, seed, j); - * swap(subtractive[i], subtractive[j]); - * } + * (* shuffle the subtractive table *) + * seed >>= 64; + * for (i=100; seed > 0 && i > 0; --i) { + * quomod(seed, i+1, seed, j); + * swap(subtractive[i], subtractive[j]); + * } * - * Seed must be >= 0. All seed values < 0 are reserved for future use. + * Seed must be >= 0. All seed values < 0 are reserved for future use. * - * The subtractive 100 pointers are reset to subtractive[36] and - * subtractive[99]. Last the shuffle table is loaded with successive - * values from the subtractive 100 generator. + * The subtractive 100 pointers are reset to subtractive[36] and + * subtractive[99]. Last the shuffle table is loaded with successive + * values from the subtractive 100 generator. * * seed == 0: * --------- - * Restore the initial state and modulus of the s100 generator. - * After this call, the s100 generator is restored to its initial - * state after calc started. + * Restore the initial state and modulus of the s100 generator. + * After this call, the s100 generator is restored to its initial + * state after calc started. * - * The subtractive 100 pointers are reset to subtractive[36] and - * subtractive[99]. Last the shuffle table is loaded with successive - * values from the subtractive 100 generator. + * The subtractive 100 pointers are reset to subtractive[36] and + * subtractive[99]. Last the shuffle table is loaded with successive + * values from the subtractive 100 generator. * ****************************************************************************** * @@ -252,11 +252,11 @@ * function with no arguments, and later restored by calling the seed * functions with that same return value. * - * rand_state = srand(); - * ... generate random bits ... - * prev_rand_state = srand(rand_state); - * ... generate the same random bits ... - * srand() == prev_rand_state; (* is true *) + * rand_state = srand(); + * ... generate random bits ... + * prev_rand_state = srand(rand_state); + * ... generate the same random bits ... + * srand() == prev_rand_state; (* is true *) * * Saving the state just after seeding a generator and restoring it later * as a very fast way to reseed a generator. @@ -284,7 +284,7 @@ * of the digitization of chaotic system that consisted of a noisy * digital camera and 6 Lava Lite(R) lamps. * - * BTW: Lava Lite(R) is a trademark of Haggerty Enterprises, Inc. + * BTW: Lava Lite(R) is a trademark of Haggerty Enterprises, Inc. * * The first 100 groups of 64 bit bits were used to initialize init_s100.slot. * @@ -309,7 +309,7 @@ * FOR THE PARANOID: * * The truly paranoid might suggest that my claims in the MAGIC NUMBERS - * section are a lie intended to entrap people. Well they are not, but + * section are a lie intended to entrap people. Well they are not, but * if you that paranoid why would you use a non-cryptographically strong * pseudo-random number generator in the first place? You would be * better off using the random() builtin function. @@ -329,7 +329,7 @@ * When using the s100 generator, one may select your own 100 subtractive * values by calling: * - * srand(mat100) + * srand(mat100) * * and avoid using my magic numbers. The randreseed64 process is NOT * applied to the matrix values. Of course, you must pick good subtractive @@ -338,13 +338,13 @@ * One might object to the complexity of the seed scramble/mapping * via the randreseed64() function. The randreseed64() function maps: * - * 0 ==> 0 - * 10239951819489363767 ==> 1363042948800878693 + * 0 ==> 0 + * 10239951819489363767 ==> 1363042948800878693 * * so that srand(0) does the default action and randreseed64() remains * an 1-to-1 and onto map. Thus calling srand(0) with the randreseed64() * process would be the same as calling srand(4967126403401436567) without - * it. No extra security is gained or reduced by using the randreseed64() + * it. No extra security is gained or reduced by using the randreseed64() * process. The meaning of seeds are exchanged, but not lost or favored * (used by more than one input seed). */ @@ -358,7 +358,7 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* @@ -368,386 +368,386 @@ * or srand(0) is called. The init_s100 value is never changed, only copied. */ STATIC CONST RAND init_s100 = { - 1, /* seeded */ - 0, /* no buffered bits */ -#if FULL_BITS == SBITS /* buffer */ - {0}, + 1, /* seeded */ + 0, /* no buffered bits */ +#if FULL_BITS == SBITS /* buffer */ + {0}, #elif 2*FULL_BITS == SBITS - {0, 0}, + {0, 0}, #else - /\../\ BASEB is assumed to be 16 or 32 /\../\ !!! + /\../\ BASEB is assumed to be 16 or 32 /\../\ !!! #endif - INIT_J, /* j */ - INIT_K, /* k */ - RAND_CONSEQ_USE, /* use this many before skipping values */ + INIT_J, /* j */ + INIT_K, /* k */ + RAND_CONSEQ_USE, /* use this many before skipping values */ #if FULL_BITS == SBITS - { /* subtractive 100 table */ - (FULL)U(0xc8c0370c7db7dc19), (FULL)U(0x738e33b940a06fbb), - (FULL)U(0x481abb76a859ed2b), (FULL)U(0x74106bb39ccdccb5), - (FULL)U(0x05a8eeb5c3173bfc), (FULL)U(0xefd5100d5a02e577), - (FULL)U(0xa69271f74030b24a), (FULL)U(0x641282fc16fe22c5), - (FULL)U(0x7aa7267c40438da3), (FULL)U(0x1fdf4abdc2d878d1), - (FULL)U(0xd9899e7a95702379), (FULL)U(0x5ea8e217d02d7f08), - (FULL)U(0x770587fe4d47a353), (FULL)U(0xde7d1bdd0a33a2b8), - (FULL)U(0x4378c3c5900e7c45), (FULL)U(0x77c9447819a514f9), - (FULL)U(0xfc5edb22843d1d32), (FULL)U(0x4fc42ce5e8ee5e6e), - (FULL)U(0xc938713c8488013e), (FULL)U(0x6a318f0320ab0cac), - (FULL)U(0x73e6d1a3ffc8bff3), (FULL)U(0x0cd3232a8ca96aa7), - (FULL)U(0x605c8036905f770d), (FULL)U(0x4d037b008b8d04a2), - (FULL)U(0x1ed81965cb277294), (FULL)U(0x408d9c477a254ff3), - (FULL)U(0x8b68587ae26c7377), (FULL)U(0xcff191a48a48832f), - (FULL)U(0x12d3df1d8aeb6fe6), (FULL)U(0xb2bf907e1feda37a), - (FULL)U(0x4e5f77193bb5f39f), (FULL)U(0x33ebcf6f8f5d1581), - (FULL)U(0x203c8e48d33654eb), (FULL)U(0x68d3656ef19c8a4e), - (FULL)U(0x3ec20b04986eb2af), (FULL)U(0x5d73a03b062c3841), - (FULL)U(0x836ce7095d4e49eb), (FULL)U(0x2310bc40c3f49221), - (FULL)U(0x3868ee48a6d0cbf6), (FULL)U(0x67578aa64a43deb1), - (FULL)U(0x6e3426c1150dfc26), (FULL)U(0xc541ccaa3131be30), - (FULL)U(0xf7e57432cec7aab2), (FULL)U(0x2b35de998cb3c873), - (FULL)U(0x7b9f77648663a5d7), (FULL)U(0x23b00e6aa771e5a6), - (FULL)U(0x859c775ca9985d05), (FULL)U(0x99636ea16b692f1f), - (FULL)U(0x8700ac703730800d), (FULL)U(0x461425024298a753), - (FULL)U(0xea4a411b809e955f), (FULL)U(0x3119ad4033709dfb), - (FULL)U(0xb76a6c6e5f01cb7c), (FULL)U(0x6109dc8a15984eaf), - (FULL)U(0x5d686db9a5ca9505), (FULL)U(0x8e80d7613b7e6add), - (FULL)U(0x79cbd718de6f6fd3), (FULL)U(0x40e9cd151da0f699), - (FULL)U(0xe82158bab24f312d), (FULL)U(0x79a4c927f5e5c36b), - (FULL)U(0xc25247c9a0039333), (FULL)U(0x936871161766d81d), - (FULL)U(0x3c6a03b4a6741327), (FULL)U(0xc8a7b6e8c002f29a), - (FULL)U(0x0e2a67c67bbd5ea3), (FULL)U(0x0929042d441eabc1), - (FULL)U(0x7dbe232a25e82085), (FULL)U(0x8cfb26e544fbac3d), - (FULL)U(0x8e40384d388ab983), (FULL)U(0x48dc1230554632f8), - (FULL)U(0xab405048ab492397), (FULL)U(0x21c9e2f5a118e387), - (FULL)U(0x484d1a8c343b61b5), (FULL)U(0xd49e3decab256f26), - (FULL)U(0xe615c7fd78f2d2e3), (FULL)U(0x8442cc33ce6cc2ed), - (FULL)U(0x0a3b93d844d4bbf6), (FULL)U(0x2d7e4efe9301de77), - (FULL)U(0x33711b76d8790d8a), (FULL)U(0xc07dc30e44df77e7), - (FULL)U(0xb9132ed09ddd508f), (FULL)U(0x45d06cf8c6fb43cc), - (FULL)U(0x22bed18ad585dd7b), (FULL)U(0x61c6cced10799ffa), - (FULL)U(0xd7f2393be4bd9aa9), (FULL)U(0x706753fbcfd55094), - (FULL)U(0xf65a6713ede6e446), (FULL)U(0x8bf6dfae47c0d5c3), - (FULL)U(0xfb4dfc179f7927d6), (FULL)U(0x12ebbc16e212c297), - (FULL)U(0x43c71283a00a954c), (FULL)U(0x8957087ae7bd40a5), - (FULL)U(0xb0859d7108344837), (FULL)U(0xfbf4b9a3aeb313f5), - (FULL)U(0x5e66e5bece81823a), (FULL)U(0x09a11c6e58ad6da1), - (FULL)U(0xc76f4316c608054f), (FULL)U(0xb582136146084099), - (FULL)U(0x4210008f17a725ed), (FULL)U(0xe5ff8912d347c481) - }, - { /* shuffle table */ - (FULL)U(0x69a2296cec8abd57), (FULL)U(0x867e186999a6df81), - (FULL)U(0xc05ab96bd849a48a), (FULL)U(0x7eb3ce0cfa00554b), - (FULL)U(0x520d01f65a5a9acd), (FULL)U(0xd4ef1e3336022d81), - (FULL)U(0xaf44772bc6f84f70), (FULL)U(0x647e85a6a7c55173), - (FULL)U(0x26746cf1959df8d1), (FULL)U(0x98681a904db28abd), - (FULL)U(0xb146c969744c5cd2), (FULL)U(0x8ce69d1f706f88c2), - (FULL)U(0xfd12eac421b4a748), (FULL)U(0xf12e70fe2710eea5), - (FULL)U(0x0b8f78055901f2b5), (FULL)U(0x48860a764f2c115e), - (FULL)U(0x0edf6d2a30767e2c), (FULL)U(0x8a6d7dc5fce2713b), - (FULL)U(0x46a362ea4e0e2346), (FULL)U(0x6c369a0a359f5aa7), - (FULL)U(0xdfca81fe41def54e), (FULL)U(0x4b73381996c2bc4e), - (FULL)U(0x659e8b996f3f14f9), (FULL)U(0x8b97b93493d47e6f), - (FULL)U(0xa73a8704dfa10a55), (FULL)U(0x8d9eafe9b06503da), - (FULL)U(0x2556fb88f32336b0), (FULL)U(0xe71e9f751002a161), - (FULL)U(0x27a7be6e200af907), (FULL)U(0x1b9b734ed028e9a3), - (FULL)U(0x950cfeed4c0be0d3), (FULL)U(0xf4c416942536d275), - (FULL)U(0xf05a58e85687b76e), (FULL)U(0xba53ac0171a62d54), - (FULL)U(0x4b14cbcb285adc96), (FULL)U(0xfdf66eddb00a5557), - (FULL)U(0xbb43d58d185b6ea1), (FULL)U(0x905db9cdf355c9a6), - (FULL)U(0xfc3a07fc04429c8a), (FULL)U(0x65d7e365aa3a4f7e), - (FULL)U(0x2d284c18b243ac65), (FULL)U(0x72fba65d44e417fd), - (FULL)U(0x422d50b45c934805), (FULL)U(0xb62a6053d1587441), - (FULL)U(0xa5e71ce96f7ae035), (FULL)U(0x93abca2e595c8dd8), - (FULL)U(0x534231afe39afad5), (FULL)U(0x08d26cac12eaad56), - (FULL)U(0xec18bf8d7fb1b1c2), (FULL)U(0x3d28ea16faf6f09b), - (FULL)U(0xea357a7816697dd6), (FULL)U(0x51471ea1420f3f51), - (FULL)U(0x5e051aeb7f8946b4), (FULL)U(0x881be0970cf0524c), - (FULL)U(0xd558b25b1b31489e), (FULL)U(0x707d1a943a8b065c), - (FULL)U(0x37017e66568ff836), (FULL)U(0xb9cd627c24c2f747), - (FULL)U(0x1485549ffb1d9ff6), (FULL)U(0x308d32d9bdf2dc6f), - (FULL)U(0x4d4142cad543818a), (FULL)U(0x5d9c7aee87ebba43), - (FULL)U(0x81c5bdd8e17adb2f), (FULL)U(0x3dc9752ec8d8677a), - (FULL)U(0x66b086e6c34e4212), (FULL)U(0x3af7a90dc62b25e3), - (FULL)U(0xf8349f7935539315), (FULL)U(0x6bcfd9d5a22917f0), - (FULL)U(0x8639bb765f5ee517), (FULL)U(0xd3c5e3698095b092), - (FULL)U(0x8a33851e7eb44748), (FULL)U(0x5e29d443ea54bbcf), - (FULL)U(0x0f84651f4d59a834), (FULL)U(0x85040beaf1a5f951), - (FULL)U(0x3dba1c7498002078), (FULL)U(0x5d70712bf0b2cc15), - (FULL)U(0xfa3af8ebcce8e5a7), (FULL)U(0xfb3e223704bba57d), - (FULL)U(0x5d3b87858a950434), (FULL)U(0xce3112bdba3f8dcf), - (FULL)U(0x44904f55860d3051), (FULL)U(0xcec8fed44ed3e98b), - (FULL)U(0x4581698d25d01ea4), (FULL)U(0x11eb68289a9548e0), - (FULL)U(0x796cb4c6e911fac8), (FULL)U(0x2164cf26b5fd813e), - (FULL)U(0x4ac8e0f5d5de640f), (FULL)U(0xe9e757d78802ab4e), - (FULL)U(0x3c97de26f49dfcbd), (FULL)U(0xc604881b6ee6dbe6), - (FULL)U(0xa7c22a6e57d6154e), (FULL)U(0x234e2370877b3cc7), - (FULL)U(0xc0bdb72bdf1f8358), (FULL)U(0x6522e0fca95b7b55), - (FULL)U(0xba174c9022344162), (FULL)U(0x712c9b2d75d48867), - (FULL)U(0x240f7e92e59f3700), (FULL)U(0xe83cc2d4ad95d763), - (FULL)U(0x8509445a4336d717), (FULL)U(0xf1e572c5dfff1804), - (FULL)U(0xed10eb5d623232dd), (FULL)U(0x9205ea1bd4f957e8), - (FULL)U(0x4973a54f2ff062f5), (FULL)U(0x26b018f1e8c48cd5), - (FULL)U(0x56908401d1c7ed9f), (FULL)U(0x2e48937bdf89a247), - (FULL)U(0x9d53069b2be47129), (FULL)U(0x98069e3bc048a2b0), - (FULL)U(0xf25b7d651cd83f93), (FULL)U(0x2b004e6ce6f886c8), - (FULL)U(0xf618442a5c635935), (FULL)U(0xa502ab5c7198e052), - (FULL)U(0xc14241a4a6c41b0b), (FULL)U(0x720e845a7db9b18e), - (FULL)U(0x2abb13e94b713918), (FULL)U(0x90fc0c207f52467d), - (FULL)U(0x799c8ccd7868d348), (FULL)U(0xf4817ced912a0ea4), - (FULL)U(0xd68c0f4cc4903a57), (FULL)U(0xa3171f29e2b7934c), - (FULL)U(0xb1158baa0b4ccc22), (FULL)U(0xf5d8555349a29eda), - (FULL)U(0x59d1a078959442ef), (FULL)U(0xdb9b4a96a67fd518), - (FULL)U(0xcc7ca9eed2870636), (FULL)U(0x548f021cecf59920), - (FULL)U(0x25b7f4b6571bc8c5), (FULL)U(0x4fa527473a44f536), - (FULL)U(0xb246845fdf0ebdc2), (FULL)U(0xdd8d68ae42058793), - (FULL)U(0x3ba133289f6c39fb), (FULL)U(0x8bfdfbf37b6b42af), - (FULL)U(0xfb34c5ca7fb2b3b0), (FULL)U(0x2345dcecd428e32a), - (FULL)U(0x6891e850ad42b63e), (FULL)U(0x930642c8362c1381), - (FULL)U(0x13871e9b1886aff5), (FULL)U(0xd0cf2407482bda55), - (FULL)U(0x125b5fc95069bc31), (FULL)U(0x9b71d0a9f07dfa5d), - (FULL)U(0x55c044cc6712e524), (FULL)U(0xf0377358bb601978), - (FULL)U(0x152ad5f87fa51e8b), (FULL)U(0xe5ebf4789fcdd9af), - (FULL)U(0x3d78e18c66ebce7e), (FULL)U(0x8246db72f36aa83f), - (FULL)U(0xcc6ddc6d2c64c0a3), (FULL)U(0xa758d6870d91851e), - (FULL)U(0x24b20a6f9488ee36), (FULL)U(0xbe11ccdf09798197), - (FULL)U(0x11aca01599c1f4e3), (FULL)U(0x40e89e366437ac05), - (FULL)U(0xc8bfc7625af675f8), (FULL)U(0x6367c578b577e759), - (FULL)U(0x00380346615f0b74), (FULL)U(0xee964cc48de07d81), - (FULL)U(0x17f6ac16859d9261), (FULL)U(0x092f4a173a6e2f6c), - (FULL)U(0x79981a3db9024b95), (FULL)U(0x36db166004f7f540), - (FULL)U(0xc36252cf65a2f1c8), (FULL)U(0x705b6fde124c9bd2), - (FULL)U(0x31e58dda85db40ce), (FULL)U(0x6342b1a59f5e8d6d), - (FULL)U(0x5c2c67d0bd6d1d4d), (FULL)U(0x1fe5b46fba7e069d), - (FULL)U(0x21c46c6cac72e13c), (FULL)U(0xb80c5fd59eb8f52a), - (FULL)U(0x56c3aebfa74c92bc), (FULL)U(0xc1aff1fcbf8c4196), - (FULL)U(0x2b1df645754ad208), (FULL)U(0x5c734600d46eeb50), - (FULL)U(0xe0ff1b126a70a765), (FULL)U(0xd54164977a94547c), - (FULL)U(0x67b59d7c4ea35206), (FULL)U(0x53be7146779203b4), - (FULL)U(0x6b589fe5414026b8), (FULL)U(0x9e81016c3083bfee), - (FULL)U(0xb23526b93b4b7671), (FULL)U(0x4fa9ffb17ee300ba), - (FULL)U(0x6217e212ad05fb21), (FULL)U(0xf5b3fcd3b294e6c2), - (FULL)U(0xac040bbe216beb2a), (FULL)U(0x1f8d8a5471d0e78c), - (FULL)U(0xb6d15b419cfec96b), (FULL)U(0xc5477845d0508c78), - (FULL)U(0x5b486e81b4bba621), (FULL)U(0x90c35c94ef4c4121), - (FULL)U(0xefce7346f6a6bc55), (FULL)U(0xa27828d925bdb9bb), - (FULL)U(0xe3a53095a1f0b205), (FULL)U(0x1bfa6093d9f208ab), - (FULL)U(0xfb078f6a6842cdf4), (FULL)U(0x07806d7297133a38), - (FULL)U(0x2c6c901ba3ce9592), (FULL)U(0x1f0ab2cfebc1b789), - (FULL)U(0x2ce81415e2d03d5e), (FULL)U(0x7da45d5baa9f2417), - (FULL)U(0x3be4f76ddd800682), (FULL)U(0xdbf4e4a3364d72d3), - (FULL)U(0xb538cccf4fc59da5), (FULL)U(0xb0aa39d5487f66ec), - (FULL)U(0x2fd28dfd87927d3d), (FULL)U(0xd14e77f05900c6b1), - (FULL)U(0x2523fad25330c7b4), (FULL)U(0x991b5938d82368a4), - (FULL)U(0xb7c114432b9c1302), (FULL)U(0xdb842db61394b116), - (FULL)U(0x3641548d78ed26d8), (FULL)U(0x274fa8ef0a61dacf), - (FULL)U(0xa554ba63112df6f1), (FULL)U(0x7b7fe9856b50438d), - (FULL)U(0xc9fa0042bb63bbad), (FULL)U(0x3abf45d0e27f00da), - (FULL)U(0xd95faa159f87aabb), (FULL)U(0x4a95012e3488e7ae), - (FULL)U(0x1be2bdb90c642d04), (FULL)U(0x145c88818b4abf3e), - (FULL)U(0x7f9fb635544cf17f), (FULL)U(0xb8ab2f62cc78db70), - (FULL)U(0x8ee64bcdb4242f9a), (FULL)U(0xabd5285895dad129), - (FULL)U(0xbe722c2fccf31141), (FULL)U(0x7c330703575e26a9), - (FULL)U(0x45d3e3b3361b79e4), (FULL)U(0x241163a754b2e6a6), - (FULL)U(0x8f678d7df7cacb77), (FULL)U(0x988a68a483211d19), - (FULL)U(0x79599598ba7836f6), (FULL)U(0x4850c887eeda68bf), - (FULL)U(0xafa69a718052ce25), (FULL)U(0x8b21efc6bdd73573), - (FULL)U(0x89dbae18d0972493), (FULL)U(0x560776bf537d9454), - (FULL)U(0x3c009f78165310f2), (FULL)U(0xa36800210160c3af), - (FULL)U(0x3353ec3ca643bd40), (FULL)U(0x7e593f99911dab02), - (FULL)U(0x72d1ddd94f676e89), (FULL)U(0xfd18b8bd6b43c0ea), - (FULL)U(0x43cacef2ddbd697d), (FULL)U(0x2868a4d0acefe884), - (FULL)U(0x5f377b63a506f013), (FULL)U(0xeaa0975e05ca662b), - (FULL)U(0x3740e6b8eb433931), (FULL)U(0xce85df0008557948), - (FULL)U(0x784745fb547e33f9), (FULL)U(0x4a1fc5d4e5c6f598), - (FULL)U(0x85fa6fec768430a7), (FULL)U(0x990d0c24d2332a51), - (FULL)U(0x55245c2c33b676d5), (FULL)U(0xb1091519e2bcfa71), - (FULL)U(0x38521478d23a28d8), (FULL)U(0x9b794f899a573010), - (FULL)U(0x61d225e8699bb486), (FULL)U(0x21476d241c2158b0) - } + { /* subtractive 100 table */ + (FULL)U(0xc8c0370c7db7dc19), (FULL)U(0x738e33b940a06fbb), + (FULL)U(0x481abb76a859ed2b), (FULL)U(0x74106bb39ccdccb5), + (FULL)U(0x05a8eeb5c3173bfc), (FULL)U(0xefd5100d5a02e577), + (FULL)U(0xa69271f74030b24a), (FULL)U(0x641282fc16fe22c5), + (FULL)U(0x7aa7267c40438da3), (FULL)U(0x1fdf4abdc2d878d1), + (FULL)U(0xd9899e7a95702379), (FULL)U(0x5ea8e217d02d7f08), + (FULL)U(0x770587fe4d47a353), (FULL)U(0xde7d1bdd0a33a2b8), + (FULL)U(0x4378c3c5900e7c45), (FULL)U(0x77c9447819a514f9), + (FULL)U(0xfc5edb22843d1d32), (FULL)U(0x4fc42ce5e8ee5e6e), + (FULL)U(0xc938713c8488013e), (FULL)U(0x6a318f0320ab0cac), + (FULL)U(0x73e6d1a3ffc8bff3), (FULL)U(0x0cd3232a8ca96aa7), + (FULL)U(0x605c8036905f770d), (FULL)U(0x4d037b008b8d04a2), + (FULL)U(0x1ed81965cb277294), (FULL)U(0x408d9c477a254ff3), + (FULL)U(0x8b68587ae26c7377), (FULL)U(0xcff191a48a48832f), + (FULL)U(0x12d3df1d8aeb6fe6), (FULL)U(0xb2bf907e1feda37a), + (FULL)U(0x4e5f77193bb5f39f), (FULL)U(0x33ebcf6f8f5d1581), + (FULL)U(0x203c8e48d33654eb), (FULL)U(0x68d3656ef19c8a4e), + (FULL)U(0x3ec20b04986eb2af), (FULL)U(0x5d73a03b062c3841), + (FULL)U(0x836ce7095d4e49eb), (FULL)U(0x2310bc40c3f49221), + (FULL)U(0x3868ee48a6d0cbf6), (FULL)U(0x67578aa64a43deb1), + (FULL)U(0x6e3426c1150dfc26), (FULL)U(0xc541ccaa3131be30), + (FULL)U(0xf7e57432cec7aab2), (FULL)U(0x2b35de998cb3c873), + (FULL)U(0x7b9f77648663a5d7), (FULL)U(0x23b00e6aa771e5a6), + (FULL)U(0x859c775ca9985d05), (FULL)U(0x99636ea16b692f1f), + (FULL)U(0x8700ac703730800d), (FULL)U(0x461425024298a753), + (FULL)U(0xea4a411b809e955f), (FULL)U(0x3119ad4033709dfb), + (FULL)U(0xb76a6c6e5f01cb7c), (FULL)U(0x6109dc8a15984eaf), + (FULL)U(0x5d686db9a5ca9505), (FULL)U(0x8e80d7613b7e6add), + (FULL)U(0x79cbd718de6f6fd3), (FULL)U(0x40e9cd151da0f699), + (FULL)U(0xe82158bab24f312d), (FULL)U(0x79a4c927f5e5c36b), + (FULL)U(0xc25247c9a0039333), (FULL)U(0x936871161766d81d), + (FULL)U(0x3c6a03b4a6741327), (FULL)U(0xc8a7b6e8c002f29a), + (FULL)U(0x0e2a67c67bbd5ea3), (FULL)U(0x0929042d441eabc1), + (FULL)U(0x7dbe232a25e82085), (FULL)U(0x8cfb26e544fbac3d), + (FULL)U(0x8e40384d388ab983), (FULL)U(0x48dc1230554632f8), + (FULL)U(0xab405048ab492397), (FULL)U(0x21c9e2f5a118e387), + (FULL)U(0x484d1a8c343b61b5), (FULL)U(0xd49e3decab256f26), + (FULL)U(0xe615c7fd78f2d2e3), (FULL)U(0x8442cc33ce6cc2ed), + (FULL)U(0x0a3b93d844d4bbf6), (FULL)U(0x2d7e4efe9301de77), + (FULL)U(0x33711b76d8790d8a), (FULL)U(0xc07dc30e44df77e7), + (FULL)U(0xb9132ed09ddd508f), (FULL)U(0x45d06cf8c6fb43cc), + (FULL)U(0x22bed18ad585dd7b), (FULL)U(0x61c6cced10799ffa), + (FULL)U(0xd7f2393be4bd9aa9), (FULL)U(0x706753fbcfd55094), + (FULL)U(0xf65a6713ede6e446), (FULL)U(0x8bf6dfae47c0d5c3), + (FULL)U(0xfb4dfc179f7927d6), (FULL)U(0x12ebbc16e212c297), + (FULL)U(0x43c71283a00a954c), (FULL)U(0x8957087ae7bd40a5), + (FULL)U(0xb0859d7108344837), (FULL)U(0xfbf4b9a3aeb313f5), + (FULL)U(0x5e66e5bece81823a), (FULL)U(0x09a11c6e58ad6da1), + (FULL)U(0xc76f4316c608054f), (FULL)U(0xb582136146084099), + (FULL)U(0x4210008f17a725ed), (FULL)U(0xe5ff8912d347c481) + }, + { /* shuffle table */ + (FULL)U(0x69a2296cec8abd57), (FULL)U(0x867e186999a6df81), + (FULL)U(0xc05ab96bd849a48a), (FULL)U(0x7eb3ce0cfa00554b), + (FULL)U(0x520d01f65a5a9acd), (FULL)U(0xd4ef1e3336022d81), + (FULL)U(0xaf44772bc6f84f70), (FULL)U(0x647e85a6a7c55173), + (FULL)U(0x26746cf1959df8d1), (FULL)U(0x98681a904db28abd), + (FULL)U(0xb146c969744c5cd2), (FULL)U(0x8ce69d1f706f88c2), + (FULL)U(0xfd12eac421b4a748), (FULL)U(0xf12e70fe2710eea5), + (FULL)U(0x0b8f78055901f2b5), (FULL)U(0x48860a764f2c115e), + (FULL)U(0x0edf6d2a30767e2c), (FULL)U(0x8a6d7dc5fce2713b), + (FULL)U(0x46a362ea4e0e2346), (FULL)U(0x6c369a0a359f5aa7), + (FULL)U(0xdfca81fe41def54e), (FULL)U(0x4b73381996c2bc4e), + (FULL)U(0x659e8b996f3f14f9), (FULL)U(0x8b97b93493d47e6f), + (FULL)U(0xa73a8704dfa10a55), (FULL)U(0x8d9eafe9b06503da), + (FULL)U(0x2556fb88f32336b0), (FULL)U(0xe71e9f751002a161), + (FULL)U(0x27a7be6e200af907), (FULL)U(0x1b9b734ed028e9a3), + (FULL)U(0x950cfeed4c0be0d3), (FULL)U(0xf4c416942536d275), + (FULL)U(0xf05a58e85687b76e), (FULL)U(0xba53ac0171a62d54), + (FULL)U(0x4b14cbcb285adc96), (FULL)U(0xfdf66eddb00a5557), + (FULL)U(0xbb43d58d185b6ea1), (FULL)U(0x905db9cdf355c9a6), + (FULL)U(0xfc3a07fc04429c8a), (FULL)U(0x65d7e365aa3a4f7e), + (FULL)U(0x2d284c18b243ac65), (FULL)U(0x72fba65d44e417fd), + (FULL)U(0x422d50b45c934805), (FULL)U(0xb62a6053d1587441), + (FULL)U(0xa5e71ce96f7ae035), (FULL)U(0x93abca2e595c8dd8), + (FULL)U(0x534231afe39afad5), (FULL)U(0x08d26cac12eaad56), + (FULL)U(0xec18bf8d7fb1b1c2), (FULL)U(0x3d28ea16faf6f09b), + (FULL)U(0xea357a7816697dd6), (FULL)U(0x51471ea1420f3f51), + (FULL)U(0x5e051aeb7f8946b4), (FULL)U(0x881be0970cf0524c), + (FULL)U(0xd558b25b1b31489e), (FULL)U(0x707d1a943a8b065c), + (FULL)U(0x37017e66568ff836), (FULL)U(0xb9cd627c24c2f747), + (FULL)U(0x1485549ffb1d9ff6), (FULL)U(0x308d32d9bdf2dc6f), + (FULL)U(0x4d4142cad543818a), (FULL)U(0x5d9c7aee87ebba43), + (FULL)U(0x81c5bdd8e17adb2f), (FULL)U(0x3dc9752ec8d8677a), + (FULL)U(0x66b086e6c34e4212), (FULL)U(0x3af7a90dc62b25e3), + (FULL)U(0xf8349f7935539315), (FULL)U(0x6bcfd9d5a22917f0), + (FULL)U(0x8639bb765f5ee517), (FULL)U(0xd3c5e3698095b092), + (FULL)U(0x8a33851e7eb44748), (FULL)U(0x5e29d443ea54bbcf), + (FULL)U(0x0f84651f4d59a834), (FULL)U(0x85040beaf1a5f951), + (FULL)U(0x3dba1c7498002078), (FULL)U(0x5d70712bf0b2cc15), + (FULL)U(0xfa3af8ebcce8e5a7), (FULL)U(0xfb3e223704bba57d), + (FULL)U(0x5d3b87858a950434), (FULL)U(0xce3112bdba3f8dcf), + (FULL)U(0x44904f55860d3051), (FULL)U(0xcec8fed44ed3e98b), + (FULL)U(0x4581698d25d01ea4), (FULL)U(0x11eb68289a9548e0), + (FULL)U(0x796cb4c6e911fac8), (FULL)U(0x2164cf26b5fd813e), + (FULL)U(0x4ac8e0f5d5de640f), (FULL)U(0xe9e757d78802ab4e), + (FULL)U(0x3c97de26f49dfcbd), (FULL)U(0xc604881b6ee6dbe6), + (FULL)U(0xa7c22a6e57d6154e), (FULL)U(0x234e2370877b3cc7), + (FULL)U(0xc0bdb72bdf1f8358), (FULL)U(0x6522e0fca95b7b55), + (FULL)U(0xba174c9022344162), (FULL)U(0x712c9b2d75d48867), + (FULL)U(0x240f7e92e59f3700), (FULL)U(0xe83cc2d4ad95d763), + (FULL)U(0x8509445a4336d717), (FULL)U(0xf1e572c5dfff1804), + (FULL)U(0xed10eb5d623232dd), (FULL)U(0x9205ea1bd4f957e8), + (FULL)U(0x4973a54f2ff062f5), (FULL)U(0x26b018f1e8c48cd5), + (FULL)U(0x56908401d1c7ed9f), (FULL)U(0x2e48937bdf89a247), + (FULL)U(0x9d53069b2be47129), (FULL)U(0x98069e3bc048a2b0), + (FULL)U(0xf25b7d651cd83f93), (FULL)U(0x2b004e6ce6f886c8), + (FULL)U(0xf618442a5c635935), (FULL)U(0xa502ab5c7198e052), + (FULL)U(0xc14241a4a6c41b0b), (FULL)U(0x720e845a7db9b18e), + (FULL)U(0x2abb13e94b713918), (FULL)U(0x90fc0c207f52467d), + (FULL)U(0x799c8ccd7868d348), (FULL)U(0xf4817ced912a0ea4), + (FULL)U(0xd68c0f4cc4903a57), (FULL)U(0xa3171f29e2b7934c), + (FULL)U(0xb1158baa0b4ccc22), (FULL)U(0xf5d8555349a29eda), + (FULL)U(0x59d1a078959442ef), (FULL)U(0xdb9b4a96a67fd518), + (FULL)U(0xcc7ca9eed2870636), (FULL)U(0x548f021cecf59920), + (FULL)U(0x25b7f4b6571bc8c5), (FULL)U(0x4fa527473a44f536), + (FULL)U(0xb246845fdf0ebdc2), (FULL)U(0xdd8d68ae42058793), + (FULL)U(0x3ba133289f6c39fb), (FULL)U(0x8bfdfbf37b6b42af), + (FULL)U(0xfb34c5ca7fb2b3b0), (FULL)U(0x2345dcecd428e32a), + (FULL)U(0x6891e850ad42b63e), (FULL)U(0x930642c8362c1381), + (FULL)U(0x13871e9b1886aff5), (FULL)U(0xd0cf2407482bda55), + (FULL)U(0x125b5fc95069bc31), (FULL)U(0x9b71d0a9f07dfa5d), + (FULL)U(0x55c044cc6712e524), (FULL)U(0xf0377358bb601978), + (FULL)U(0x152ad5f87fa51e8b), (FULL)U(0xe5ebf4789fcdd9af), + (FULL)U(0x3d78e18c66ebce7e), (FULL)U(0x8246db72f36aa83f), + (FULL)U(0xcc6ddc6d2c64c0a3), (FULL)U(0xa758d6870d91851e), + (FULL)U(0x24b20a6f9488ee36), (FULL)U(0xbe11ccdf09798197), + (FULL)U(0x11aca01599c1f4e3), (FULL)U(0x40e89e366437ac05), + (FULL)U(0xc8bfc7625af675f8), (FULL)U(0x6367c578b577e759), + (FULL)U(0x00380346615f0b74), (FULL)U(0xee964cc48de07d81), + (FULL)U(0x17f6ac16859d9261), (FULL)U(0x092f4a173a6e2f6c), + (FULL)U(0x79981a3db9024b95), (FULL)U(0x36db166004f7f540), + (FULL)U(0xc36252cf65a2f1c8), (FULL)U(0x705b6fde124c9bd2), + (FULL)U(0x31e58dda85db40ce), (FULL)U(0x6342b1a59f5e8d6d), + (FULL)U(0x5c2c67d0bd6d1d4d), (FULL)U(0x1fe5b46fba7e069d), + (FULL)U(0x21c46c6cac72e13c), (FULL)U(0xb80c5fd59eb8f52a), + (FULL)U(0x56c3aebfa74c92bc), (FULL)U(0xc1aff1fcbf8c4196), + (FULL)U(0x2b1df645754ad208), (FULL)U(0x5c734600d46eeb50), + (FULL)U(0xe0ff1b126a70a765), (FULL)U(0xd54164977a94547c), + (FULL)U(0x67b59d7c4ea35206), (FULL)U(0x53be7146779203b4), + (FULL)U(0x6b589fe5414026b8), (FULL)U(0x9e81016c3083bfee), + (FULL)U(0xb23526b93b4b7671), (FULL)U(0x4fa9ffb17ee300ba), + (FULL)U(0x6217e212ad05fb21), (FULL)U(0xf5b3fcd3b294e6c2), + (FULL)U(0xac040bbe216beb2a), (FULL)U(0x1f8d8a5471d0e78c), + (FULL)U(0xb6d15b419cfec96b), (FULL)U(0xc5477845d0508c78), + (FULL)U(0x5b486e81b4bba621), (FULL)U(0x90c35c94ef4c4121), + (FULL)U(0xefce7346f6a6bc55), (FULL)U(0xa27828d925bdb9bb), + (FULL)U(0xe3a53095a1f0b205), (FULL)U(0x1bfa6093d9f208ab), + (FULL)U(0xfb078f6a6842cdf4), (FULL)U(0x07806d7297133a38), + (FULL)U(0x2c6c901ba3ce9592), (FULL)U(0x1f0ab2cfebc1b789), + (FULL)U(0x2ce81415e2d03d5e), (FULL)U(0x7da45d5baa9f2417), + (FULL)U(0x3be4f76ddd800682), (FULL)U(0xdbf4e4a3364d72d3), + (FULL)U(0xb538cccf4fc59da5), (FULL)U(0xb0aa39d5487f66ec), + (FULL)U(0x2fd28dfd87927d3d), (FULL)U(0xd14e77f05900c6b1), + (FULL)U(0x2523fad25330c7b4), (FULL)U(0x991b5938d82368a4), + (FULL)U(0xb7c114432b9c1302), (FULL)U(0xdb842db61394b116), + (FULL)U(0x3641548d78ed26d8), (FULL)U(0x274fa8ef0a61dacf), + (FULL)U(0xa554ba63112df6f1), (FULL)U(0x7b7fe9856b50438d), + (FULL)U(0xc9fa0042bb63bbad), (FULL)U(0x3abf45d0e27f00da), + (FULL)U(0xd95faa159f87aabb), (FULL)U(0x4a95012e3488e7ae), + (FULL)U(0x1be2bdb90c642d04), (FULL)U(0x145c88818b4abf3e), + (FULL)U(0x7f9fb635544cf17f), (FULL)U(0xb8ab2f62cc78db70), + (FULL)U(0x8ee64bcdb4242f9a), (FULL)U(0xabd5285895dad129), + (FULL)U(0xbe722c2fccf31141), (FULL)U(0x7c330703575e26a9), + (FULL)U(0x45d3e3b3361b79e4), (FULL)U(0x241163a754b2e6a6), + (FULL)U(0x8f678d7df7cacb77), (FULL)U(0x988a68a483211d19), + (FULL)U(0x79599598ba7836f6), (FULL)U(0x4850c887eeda68bf), + (FULL)U(0xafa69a718052ce25), (FULL)U(0x8b21efc6bdd73573), + (FULL)U(0x89dbae18d0972493), (FULL)U(0x560776bf537d9454), + (FULL)U(0x3c009f78165310f2), (FULL)U(0xa36800210160c3af), + (FULL)U(0x3353ec3ca643bd40), (FULL)U(0x7e593f99911dab02), + (FULL)U(0x72d1ddd94f676e89), (FULL)U(0xfd18b8bd6b43c0ea), + (FULL)U(0x43cacef2ddbd697d), (FULL)U(0x2868a4d0acefe884), + (FULL)U(0x5f377b63a506f013), (FULL)U(0xeaa0975e05ca662b), + (FULL)U(0x3740e6b8eb433931), (FULL)U(0xce85df0008557948), + (FULL)U(0x784745fb547e33f9), (FULL)U(0x4a1fc5d4e5c6f598), + (FULL)U(0x85fa6fec768430a7), (FULL)U(0x990d0c24d2332a51), + (FULL)U(0x55245c2c33b676d5), (FULL)U(0xb1091519e2bcfa71), + (FULL)U(0x38521478d23a28d8), (FULL)U(0x9b794f899a573010), + (FULL)U(0x61d225e8699bb486), (FULL)U(0x21476d241c2158b0) + } #elif 2*FULL_BITS == SBITS - { /* subtractive 100 table */ - (FULL)0x7db7dc19,(FULL)0xc8c0370c,(FULL)0x40a06fbb,(FULL)0x738e33b9, - (FULL)0xa859ed2b,(FULL)0x481abb76,(FULL)0x9ccdccb5,(FULL)0x74106bb3, - (FULL)0xc3173bfc,(FULL)0x05a8eeb5,(FULL)0x5a02e577,(FULL)0xefd5100d, - (FULL)0x4030b24a,(FULL)0xa69271f7,(FULL)0x16fe22c5,(FULL)0x641282fc, - (FULL)0x40438da3,(FULL)0x7aa7267c,(FULL)0xc2d878d1,(FULL)0x1fdf4abd, - (FULL)0x95702379,(FULL)0xd9899e7a,(FULL)0xd02d7f08,(FULL)0x5ea8e217, - (FULL)0x4d47a353,(FULL)0x770587fe,(FULL)0x0a33a2b8,(FULL)0xde7d1bdd, - (FULL)0x900e7c45,(FULL)0x4378c3c5,(FULL)0x19a514f9,(FULL)0x77c94478, - (FULL)0x843d1d32,(FULL)0xfc5edb22,(FULL)0xe8ee5e6e,(FULL)0x4fc42ce5, - (FULL)0x8488013e,(FULL)0xc938713c,(FULL)0x20ab0cac,(FULL)0x6a318f03, - (FULL)0xffc8bff3,(FULL)0x73e6d1a3,(FULL)0x8ca96aa7,(FULL)0x0cd3232a, - (FULL)0x905f770d,(FULL)0x605c8036,(FULL)0x8b8d04a2,(FULL)0x4d037b00, - (FULL)0xcb277294,(FULL)0x1ed81965,(FULL)0x7a254ff3,(FULL)0x408d9c47, - (FULL)0xe26c7377,(FULL)0x8b68587a,(FULL)0x8a48832f,(FULL)0xcff191a4, - (FULL)0x8aeb6fe6,(FULL)0x12d3df1d,(FULL)0x1feda37a,(FULL)0xb2bf907e, - (FULL)0x3bb5f39f,(FULL)0x4e5f7719,(FULL)0x8f5d1581,(FULL)0x33ebcf6f, - (FULL)0xd33654eb,(FULL)0x203c8e48,(FULL)0xf19c8a4e,(FULL)0x68d3656e, - (FULL)0x986eb2af,(FULL)0x3ec20b04,(FULL)0x062c3841,(FULL)0x5d73a03b, - (FULL)0x5d4e49eb,(FULL)0x836ce709,(FULL)0xc3f49221,(FULL)0x2310bc40, - (FULL)0xa6d0cbf6,(FULL)0x3868ee48,(FULL)0x4a43deb1,(FULL)0x67578aa6, - (FULL)0x150dfc26,(FULL)0x6e3426c1,(FULL)0x3131be30,(FULL)0xc541ccaa, - (FULL)0xcec7aab2,(FULL)0xf7e57432,(FULL)0x8cb3c873,(FULL)0x2b35de99, - (FULL)0x8663a5d7,(FULL)0x7b9f7764,(FULL)0xa771e5a6,(FULL)0x23b00e6a, - (FULL)0xa9985d05,(FULL)0x859c775c,(FULL)0x6b692f1f,(FULL)0x99636ea1, - (FULL)0x3730800d,(FULL)0x8700ac70,(FULL)0x4298a753,(FULL)0x46142502, - (FULL)0x809e955f,(FULL)0xea4a411b,(FULL)0x33709dfb,(FULL)0x3119ad40, - (FULL)0x5f01cb7c,(FULL)0xb76a6c6e,(FULL)0x15984eaf,(FULL)0x6109dc8a, - (FULL)0xa5ca9505,(FULL)0x5d686db9,(FULL)0x3b7e6add,(FULL)0x8e80d761, - (FULL)0xde6f6fd3,(FULL)0x79cbd718,(FULL)0x1da0f699,(FULL)0x40e9cd15, - (FULL)0xb24f312d,(FULL)0xe82158ba,(FULL)0xf5e5c36b,(FULL)0x79a4c927, - (FULL)0xa0039333,(FULL)0xc25247c9,(FULL)0x1766d81d,(FULL)0x93687116, - (FULL)0xa6741327,(FULL)0x3c6a03b4,(FULL)0xc002f29a,(FULL)0xc8a7b6e8, - (FULL)0x7bbd5ea3,(FULL)0x0e2a67c6,(FULL)0x441eabc1,(FULL)0x0929042d, - (FULL)0x25e82085,(FULL)0x7dbe232a,(FULL)0x44fbac3d,(FULL)0x8cfb26e5, - (FULL)0x388ab983,(FULL)0x8e40384d,(FULL)0x554632f8,(FULL)0x48dc1230, - (FULL)0xab492397,(FULL)0xab405048,(FULL)0xa118e387,(FULL)0x21c9e2f5, - (FULL)0x343b61b5,(FULL)0x484d1a8c,(FULL)0xab256f26,(FULL)0xd49e3dec, - (FULL)0x78f2d2e3,(FULL)0xe615c7fd,(FULL)0xce6cc2ed,(FULL)0x8442cc33, - (FULL)0x44d4bbf6,(FULL)0x0a3b93d8,(FULL)0x9301de77,(FULL)0x2d7e4efe, - (FULL)0xd8790d8a,(FULL)0x33711b76,(FULL)0x44df77e7,(FULL)0xc07dc30e, - (FULL)0x9ddd508f,(FULL)0xb9132ed0,(FULL)0xc6fb43cc,(FULL)0x45d06cf8, - (FULL)0xd585dd7b,(FULL)0x22bed18a,(FULL)0x10799ffa,(FULL)0x61c6cced, - (FULL)0xe4bd9aa9,(FULL)0xd7f2393b,(FULL)0xcfd55094,(FULL)0x706753fb, - (FULL)0xede6e446,(FULL)0xf65a6713,(FULL)0x47c0d5c3,(FULL)0x8bf6dfae, - (FULL)0x9f7927d6,(FULL)0xfb4dfc17,(FULL)0xe212c297,(FULL)0x12ebbc16, - (FULL)0xa00a954c,(FULL)0x43c71283,(FULL)0xe7bd40a5,(FULL)0x8957087a, - (FULL)0x08344837,(FULL)0xb0859d71,(FULL)0xaeb313f5,(FULL)0xfbf4b9a3, - (FULL)0xce81823a,(FULL)0x5e66e5be,(FULL)0x58ad6da1,(FULL)0x09a11c6e, - (FULL)0xc608054f,(FULL)0xc76f4316,(FULL)0x46084099,(FULL)0xb5821361, - (FULL)0x17a725ed,(FULL)0x4210008f,(FULL)0xd347c481,(FULL)0xe5ff8912 - }, - { /* shuffle table */ - (FULL)0xec8abd57,(FULL)0x69a2296c,(FULL)0x99a6df81,(FULL)0x867e1869, - (FULL)0xd849a48a,(FULL)0xc05ab96b,(FULL)0xfa00554b,(FULL)0x7eb3ce0c, - (FULL)0x5a5a9acd,(FULL)0x520d01f6,(FULL)0x36022d81,(FULL)0xd4ef1e33, - (FULL)0xc6f84f70,(FULL)0xaf44772b,(FULL)0xa7c55173,(FULL)0x647e85a6, - (FULL)0x959df8d1,(FULL)0x26746cf1,(FULL)0x4db28abd,(FULL)0x98681a90, - (FULL)0x744c5cd2,(FULL)0xb146c969,(FULL)0x706f88c2,(FULL)0x8ce69d1f, - (FULL)0x21b4a748,(FULL)0xfd12eac4,(FULL)0x2710eea5,(FULL)0xf12e70fe, - (FULL)0x5901f2b5,(FULL)0x0b8f7805,(FULL)0x4f2c115e,(FULL)0x48860a76, - (FULL)0x30767e2c,(FULL)0x0edf6d2a,(FULL)0xfce2713b,(FULL)0x8a6d7dc5, - (FULL)0x4e0e2346,(FULL)0x46a362ea,(FULL)0x359f5aa7,(FULL)0x6c369a0a, - (FULL)0x41def54e,(FULL)0xdfca81fe,(FULL)0x96c2bc4e,(FULL)0x4b733819, - (FULL)0x6f3f14f9,(FULL)0x659e8b99,(FULL)0x93d47e6f,(FULL)0x8b97b934, - (FULL)0xdfa10a55,(FULL)0xa73a8704,(FULL)0xb06503da,(FULL)0x8d9eafe9, - (FULL)0xf32336b0,(FULL)0x2556fb88,(FULL)0x1002a161,(FULL)0xe71e9f75, - (FULL)0x200af907,(FULL)0x27a7be6e,(FULL)0xd028e9a3,(FULL)0x1b9b734e, - (FULL)0x4c0be0d3,(FULL)0x950cfeed,(FULL)0x2536d275,(FULL)0xf4c41694, - (FULL)0x5687b76e,(FULL)0xf05a58e8,(FULL)0x71a62d54,(FULL)0xba53ac01, - (FULL)0x285adc96,(FULL)0x4b14cbcb,(FULL)0xb00a5557,(FULL)0xfdf66edd, - (FULL)0x185b6ea1,(FULL)0xbb43d58d,(FULL)0xf355c9a6,(FULL)0x905db9cd, - (FULL)0x04429c8a,(FULL)0xfc3a07fc,(FULL)0xaa3a4f7e,(FULL)0x65d7e365, - (FULL)0xb243ac65,(FULL)0x2d284c18,(FULL)0x44e417fd,(FULL)0x72fba65d, - (FULL)0x5c934805,(FULL)0x422d50b4,(FULL)0xd1587441,(FULL)0xb62a6053, - (FULL)0x6f7ae035,(FULL)0xa5e71ce9,(FULL)0x595c8dd8,(FULL)0x93abca2e, - (FULL)0xe39afad5,(FULL)0x534231af,(FULL)0x12eaad56,(FULL)0x08d26cac, - (FULL)0x7fb1b1c2,(FULL)0xec18bf8d,(FULL)0xfaf6f09b,(FULL)0x3d28ea16, - (FULL)0x16697dd6,(FULL)0xea357a78,(FULL)0x420f3f51,(FULL)0x51471ea1, - (FULL)0x7f8946b4,(FULL)0x5e051aeb,(FULL)0x0cf0524c,(FULL)0x881be097, - (FULL)0x1b31489e,(FULL)0xd558b25b,(FULL)0x3a8b065c,(FULL)0x707d1a94, - (FULL)0x568ff836,(FULL)0x37017e66,(FULL)0x24c2f747,(FULL)0xb9cd627c, - (FULL)0xfb1d9ff6,(FULL)0x1485549f,(FULL)0xbdf2dc6f,(FULL)0x308d32d9, - (FULL)0xd543818a,(FULL)0x4d4142ca,(FULL)0x87ebba43,(FULL)0x5d9c7aee, - (FULL)0xe17adb2f,(FULL)0x81c5bdd8,(FULL)0xc8d8677a,(FULL)0x3dc9752e, - (FULL)0xc34e4212,(FULL)0x66b086e6,(FULL)0xc62b25e3,(FULL)0x3af7a90d, - (FULL)0x35539315,(FULL)0xf8349f79,(FULL)0xa22917f0,(FULL)0x6bcfd9d5, - (FULL)0x5f5ee517,(FULL)0x8639bb76,(FULL)0x8095b092,(FULL)0xd3c5e369, - (FULL)0x7eb44748,(FULL)0x8a33851e,(FULL)0xea54bbcf,(FULL)0x5e29d443, - (FULL)0x4d59a834,(FULL)0x0f84651f,(FULL)0xf1a5f951,(FULL)0x85040bea, - (FULL)0x98002078,(FULL)0x3dba1c74,(FULL)0xf0b2cc15,(FULL)0x5d70712b, - (FULL)0xcce8e5a7,(FULL)0xfa3af8eb,(FULL)0x04bba57d,(FULL)0xfb3e2237, - (FULL)0x8a950434,(FULL)0x5d3b8785,(FULL)0xba3f8dcf,(FULL)0xce3112bd, - (FULL)0x860d3051,(FULL)0x44904f55,(FULL)0x4ed3e98b,(FULL)0xcec8fed4, - (FULL)0x25d01ea4,(FULL)0x4581698d,(FULL)0x9a9548e0,(FULL)0x11eb6828, - (FULL)0xe911fac8,(FULL)0x796cb4c6,(FULL)0xb5fd813e,(FULL)0x2164cf26, - (FULL)0xd5de640f,(FULL)0x4ac8e0f5,(FULL)0x8802ab4e,(FULL)0xe9e757d7, - (FULL)0xf49dfcbd,(FULL)0x3c97de26,(FULL)0x6ee6dbe6,(FULL)0xc604881b, - (FULL)0x57d6154e,(FULL)0xa7c22a6e,(FULL)0x877b3cc7,(FULL)0x234e2370, - (FULL)0xdf1f8358,(FULL)0xc0bdb72b,(FULL)0xa95b7b55,(FULL)0x6522e0fc, - (FULL)0x22344162,(FULL)0xba174c90,(FULL)0x75d48867,(FULL)0x712c9b2d, - (FULL)0xe59f3700,(FULL)0x240f7e92,(FULL)0xad95d763,(FULL)0xe83cc2d4, - (FULL)0x4336d717,(FULL)0x8509445a,(FULL)0xdfff1804,(FULL)0xf1e572c5, - (FULL)0x623232dd,(FULL)0xed10eb5d,(FULL)0xd4f957e8,(FULL)0x9205ea1b, - (FULL)0x2ff062f5,(FULL)0x4973a54f,(FULL)0xe8c48cd5,(FULL)0x26b018f1, - (FULL)0xd1c7ed9f,(FULL)0x56908401,(FULL)0xdf89a247,(FULL)0x2e48937b, - (FULL)0x2be47129,(FULL)0x9d53069b,(FULL)0xc048a2b0,(FULL)0x98069e3b, - (FULL)0x1cd83f93,(FULL)0xf25b7d65,(FULL)0xe6f886c8,(FULL)0x2b004e6c, - (FULL)0x5c635935,(FULL)0xf618442a,(FULL)0x7198e052,(FULL)0xa502ab5c, - (FULL)0xa6c41b0b,(FULL)0xc14241a4,(FULL)0x7db9b18e,(FULL)0x720e845a, - (FULL)0x4b713918,(FULL)0x2abb13e9,(FULL)0x7f52467d,(FULL)0x90fc0c20, - (FULL)0x7868d348,(FULL)0x799c8ccd,(FULL)0x912a0ea4,(FULL)0xf4817ced, - (FULL)0xc4903a57,(FULL)0xd68c0f4c,(FULL)0xe2b7934c,(FULL)0xa3171f29, - (FULL)0x0b4ccc22,(FULL)0xb1158baa,(FULL)0x49a29eda,(FULL)0xf5d85553, - (FULL)0x959442ef,(FULL)0x59d1a078,(FULL)0xa67fd518,(FULL)0xdb9b4a96, - (FULL)0xd2870636,(FULL)0xcc7ca9ee,(FULL)0xecf59920,(FULL)0x548f021c, - (FULL)0x571bc8c5,(FULL)0x25b7f4b6,(FULL)0x3a44f536,(FULL)0x4fa52747, - (FULL)0xdf0ebdc2,(FULL)0xb246845f,(FULL)0x42058793,(FULL)0xdd8d68ae, - (FULL)0x9f6c39fb,(FULL)0x3ba13328,(FULL)0x7b6b42af,(FULL)0x8bfdfbf3, - (FULL)0x7fb2b3b0,(FULL)0xfb34c5ca,(FULL)0xd428e32a,(FULL)0x2345dcec, - (FULL)0xad42b63e,(FULL)0x6891e850,(FULL)0x362c1381,(FULL)0x930642c8, - (FULL)0x1886aff5,(FULL)0x13871e9b,(FULL)0x482bda55,(FULL)0xd0cf2407, - (FULL)0x5069bc31,(FULL)0x125b5fc9,(FULL)0xf07dfa5d,(FULL)0x9b71d0a9, - (FULL)0x6712e524,(FULL)0x55c044cc,(FULL)0xbb601978,(FULL)0xf0377358, - (FULL)0x7fa51e8b,(FULL)0x152ad5f8,(FULL)0x9fcdd9af,(FULL)0xe5ebf478, - (FULL)0x66ebce7e,(FULL)0x3d78e18c,(FULL)0xf36aa83f,(FULL)0x8246db72, - (FULL)0x2c64c0a3,(FULL)0xcc6ddc6d,(FULL)0x0d91851e,(FULL)0xa758d687, - (FULL)0x9488ee36,(FULL)0x24b20a6f,(FULL)0x09798197,(FULL)0xbe11ccdf, - (FULL)0x99c1f4e3,(FULL)0x11aca015,(FULL)0x6437ac05,(FULL)0x40e89e36, - (FULL)0x5af675f8,(FULL)0xc8bfc762,(FULL)0xb577e759,(FULL)0x6367c578, - (FULL)0x615f0b74,(FULL)0x00380346,(FULL)0x8de07d81,(FULL)0xee964cc4, - (FULL)0x859d9261,(FULL)0x17f6ac16,(FULL)0x3a6e2f6c,(FULL)0x092f4a17, - (FULL)0xb9024b95,(FULL)0x79981a3d,(FULL)0x04f7f540,(FULL)0x36db1660, - (FULL)0x65a2f1c8,(FULL)0xc36252cf,(FULL)0x124c9bd2,(FULL)0x705b6fde, - (FULL)0x85db40ce,(FULL)0x31e58dda,(FULL)0x9f5e8d6d,(FULL)0x6342b1a5, - (FULL)0xbd6d1d4d,(FULL)0x5c2c67d0,(FULL)0xba7e069d,(FULL)0x1fe5b46f, - (FULL)0xac72e13c,(FULL)0x21c46c6c,(FULL)0x9eb8f52a,(FULL)0xb80c5fd5, - (FULL)0xa74c92bc,(FULL)0x56c3aebf,(FULL)0xbf8c4196,(FULL)0xc1aff1fc, - (FULL)0x754ad208,(FULL)0x2b1df645,(FULL)0xd46eeb50,(FULL)0x5c734600, - (FULL)0x6a70a765,(FULL)0xe0ff1b12,(FULL)0x7a94547c,(FULL)0xd5416497, - (FULL)0x4ea35206,(FULL)0x67b59d7c,(FULL)0x779203b4,(FULL)0x53be7146, - (FULL)0x414026b8,(FULL)0x6b589fe5,(FULL)0x3083bfee,(FULL)0x9e81016c, - (FULL)0x3b4b7671,(FULL)0xb23526b9,(FULL)0x7ee300ba,(FULL)0x4fa9ffb1, - (FULL)0xad05fb21,(FULL)0x6217e212,(FULL)0xb294e6c2,(FULL)0xf5b3fcd3, - (FULL)0x216beb2a,(FULL)0xac040bbe,(FULL)0x71d0e78c,(FULL)0x1f8d8a54, - (FULL)0x9cfec96b,(FULL)0xb6d15b41,(FULL)0xd0508c78,(FULL)0xc5477845, - (FULL)0xb4bba621,(FULL)0x5b486e81,(FULL)0xef4c4121,(FULL)0x90c35c94, - (FULL)0xf6a6bc55,(FULL)0xefce7346,(FULL)0x25bdb9bb,(FULL)0xa27828d9, - (FULL)0xa1f0b205,(FULL)0xe3a53095,(FULL)0xd9f208ab,(FULL)0x1bfa6093, - (FULL)0x6842cdf4,(FULL)0xfb078f6a,(FULL)0x97133a38,(FULL)0x07806d72, - (FULL)0xa3ce9592,(FULL)0x2c6c901b,(FULL)0xebc1b789,(FULL)0x1f0ab2cf, - (FULL)0xe2d03d5e,(FULL)0x2ce81415,(FULL)0xaa9f2417,(FULL)0x7da45d5b, - (FULL)0xdd800682,(FULL)0x3be4f76d,(FULL)0x364d72d3,(FULL)0xdbf4e4a3, - (FULL)0x4fc59da5,(FULL)0xb538cccf,(FULL)0x487f66ec,(FULL)0xb0aa39d5, - (FULL)0x87927d3d,(FULL)0x2fd28dfd,(FULL)0x5900c6b1,(FULL)0xd14e77f0, - (FULL)0x5330c7b4,(FULL)0x2523fad2,(FULL)0xd82368a4,(FULL)0x991b5938, - (FULL)0x2b9c1302,(FULL)0xb7c11443,(FULL)0x1394b116,(FULL)0xdb842db6, - (FULL)0x78ed26d8,(FULL)0x3641548d,(FULL)0x0a61dacf,(FULL)0x274fa8ef, - (FULL)0x112df6f1,(FULL)0xa554ba63,(FULL)0x6b50438d,(FULL)0x7b7fe985, - (FULL)0xbb63bbad,(FULL)0xc9fa0042,(FULL)0xe27f00da,(FULL)0x3abf45d0, - (FULL)0x9f87aabb,(FULL)0xd95faa15,(FULL)0x3488e7ae,(FULL)0x4a95012e, - (FULL)0x0c642d04,(FULL)0x1be2bdb9,(FULL)0x8b4abf3e,(FULL)0x145c8881, - (FULL)0x544cf17f,(FULL)0x7f9fb635,(FULL)0xcc78db70,(FULL)0xb8ab2f62, - (FULL)0xb4242f9a,(FULL)0x8ee64bcd,(FULL)0x95dad129,(FULL)0xabd52858, - (FULL)0xccf31141,(FULL)0xbe722c2f,(FULL)0x575e26a9,(FULL)0x7c330703, - (FULL)0x361b79e4,(FULL)0x45d3e3b3,(FULL)0x54b2e6a6,(FULL)0x241163a7, - (FULL)0xf7cacb77,(FULL)0x8f678d7d,(FULL)0x83211d19,(FULL)0x988a68a4, - (FULL)0xba7836f6,(FULL)0x79599598,(FULL)0xeeda68bf,(FULL)0x4850c887, - (FULL)0x8052ce25,(FULL)0xafa69a71,(FULL)0xbdd73573,(FULL)0x8b21efc6, - (FULL)0xd0972493,(FULL)0x89dbae18,(FULL)0x537d9454,(FULL)0x560776bf, - (FULL)0x165310f2,(FULL)0x3c009f78,(FULL)0x0160c3af,(FULL)0xa3680021, - (FULL)0xa643bd40,(FULL)0x3353ec3c,(FULL)0x911dab02,(FULL)0x7e593f99, - (FULL)0x4f676e89,(FULL)0x72d1ddd9,(FULL)0x6b43c0ea,(FULL)0xfd18b8bd, - (FULL)0xddbd697d,(FULL)0x43cacef2,(FULL)0xacefe884,(FULL)0x2868a4d0, - (FULL)0xa506f013,(FULL)0x5f377b63,(FULL)0x05ca662b,(FULL)0xeaa0975e, - (FULL)0xeb433931,(FULL)0x3740e6b8,(FULL)0x08557948,(FULL)0xce85df00, - (FULL)0x547e33f9,(FULL)0x784745fb,(FULL)0xe5c6f598,(FULL)0x4a1fc5d4, - (FULL)0x768430a7,(FULL)0x85fa6fec,(FULL)0xd2332a51,(FULL)0x990d0c24, - (FULL)0x33b676d5,(FULL)0x55245c2c,(FULL)0xe2bcfa71,(FULL)0xb1091519, - (FULL)0xd23a28d8,(FULL)0x38521478,(FULL)0x9a573010,(FULL)0x9b794f89, - (FULL)0x699bb486,(FULL)0x61d225e8,(FULL)0x1c2158b0,(FULL)0x21476d24 - } + { /* subtractive 100 table */ + (FULL)0x7db7dc19,(FULL)0xc8c0370c,(FULL)0x40a06fbb,(FULL)0x738e33b9, + (FULL)0xa859ed2b,(FULL)0x481abb76,(FULL)0x9ccdccb5,(FULL)0x74106bb3, + (FULL)0xc3173bfc,(FULL)0x05a8eeb5,(FULL)0x5a02e577,(FULL)0xefd5100d, + (FULL)0x4030b24a,(FULL)0xa69271f7,(FULL)0x16fe22c5,(FULL)0x641282fc, + (FULL)0x40438da3,(FULL)0x7aa7267c,(FULL)0xc2d878d1,(FULL)0x1fdf4abd, + (FULL)0x95702379,(FULL)0xd9899e7a,(FULL)0xd02d7f08,(FULL)0x5ea8e217, + (FULL)0x4d47a353,(FULL)0x770587fe,(FULL)0x0a33a2b8,(FULL)0xde7d1bdd, + (FULL)0x900e7c45,(FULL)0x4378c3c5,(FULL)0x19a514f9,(FULL)0x77c94478, + (FULL)0x843d1d32,(FULL)0xfc5edb22,(FULL)0xe8ee5e6e,(FULL)0x4fc42ce5, + (FULL)0x8488013e,(FULL)0xc938713c,(FULL)0x20ab0cac,(FULL)0x6a318f03, + (FULL)0xffc8bff3,(FULL)0x73e6d1a3,(FULL)0x8ca96aa7,(FULL)0x0cd3232a, + (FULL)0x905f770d,(FULL)0x605c8036,(FULL)0x8b8d04a2,(FULL)0x4d037b00, + (FULL)0xcb277294,(FULL)0x1ed81965,(FULL)0x7a254ff3,(FULL)0x408d9c47, + (FULL)0xe26c7377,(FULL)0x8b68587a,(FULL)0x8a48832f,(FULL)0xcff191a4, + (FULL)0x8aeb6fe6,(FULL)0x12d3df1d,(FULL)0x1feda37a,(FULL)0xb2bf907e, + (FULL)0x3bb5f39f,(FULL)0x4e5f7719,(FULL)0x8f5d1581,(FULL)0x33ebcf6f, + (FULL)0xd33654eb,(FULL)0x203c8e48,(FULL)0xf19c8a4e,(FULL)0x68d3656e, + (FULL)0x986eb2af,(FULL)0x3ec20b04,(FULL)0x062c3841,(FULL)0x5d73a03b, + (FULL)0x5d4e49eb,(FULL)0x836ce709,(FULL)0xc3f49221,(FULL)0x2310bc40, + (FULL)0xa6d0cbf6,(FULL)0x3868ee48,(FULL)0x4a43deb1,(FULL)0x67578aa6, + (FULL)0x150dfc26,(FULL)0x6e3426c1,(FULL)0x3131be30,(FULL)0xc541ccaa, + (FULL)0xcec7aab2,(FULL)0xf7e57432,(FULL)0x8cb3c873,(FULL)0x2b35de99, + (FULL)0x8663a5d7,(FULL)0x7b9f7764,(FULL)0xa771e5a6,(FULL)0x23b00e6a, + (FULL)0xa9985d05,(FULL)0x859c775c,(FULL)0x6b692f1f,(FULL)0x99636ea1, + (FULL)0x3730800d,(FULL)0x8700ac70,(FULL)0x4298a753,(FULL)0x46142502, + (FULL)0x809e955f,(FULL)0xea4a411b,(FULL)0x33709dfb,(FULL)0x3119ad40, + (FULL)0x5f01cb7c,(FULL)0xb76a6c6e,(FULL)0x15984eaf,(FULL)0x6109dc8a, + (FULL)0xa5ca9505,(FULL)0x5d686db9,(FULL)0x3b7e6add,(FULL)0x8e80d761, + (FULL)0xde6f6fd3,(FULL)0x79cbd718,(FULL)0x1da0f699,(FULL)0x40e9cd15, + (FULL)0xb24f312d,(FULL)0xe82158ba,(FULL)0xf5e5c36b,(FULL)0x79a4c927, + (FULL)0xa0039333,(FULL)0xc25247c9,(FULL)0x1766d81d,(FULL)0x93687116, + (FULL)0xa6741327,(FULL)0x3c6a03b4,(FULL)0xc002f29a,(FULL)0xc8a7b6e8, + (FULL)0x7bbd5ea3,(FULL)0x0e2a67c6,(FULL)0x441eabc1,(FULL)0x0929042d, + (FULL)0x25e82085,(FULL)0x7dbe232a,(FULL)0x44fbac3d,(FULL)0x8cfb26e5, + (FULL)0x388ab983,(FULL)0x8e40384d,(FULL)0x554632f8,(FULL)0x48dc1230, + (FULL)0xab492397,(FULL)0xab405048,(FULL)0xa118e387,(FULL)0x21c9e2f5, + (FULL)0x343b61b5,(FULL)0x484d1a8c,(FULL)0xab256f26,(FULL)0xd49e3dec, + (FULL)0x78f2d2e3,(FULL)0xe615c7fd,(FULL)0xce6cc2ed,(FULL)0x8442cc33, + (FULL)0x44d4bbf6,(FULL)0x0a3b93d8,(FULL)0x9301de77,(FULL)0x2d7e4efe, + (FULL)0xd8790d8a,(FULL)0x33711b76,(FULL)0x44df77e7,(FULL)0xc07dc30e, + (FULL)0x9ddd508f,(FULL)0xb9132ed0,(FULL)0xc6fb43cc,(FULL)0x45d06cf8, + (FULL)0xd585dd7b,(FULL)0x22bed18a,(FULL)0x10799ffa,(FULL)0x61c6cced, + (FULL)0xe4bd9aa9,(FULL)0xd7f2393b,(FULL)0xcfd55094,(FULL)0x706753fb, + (FULL)0xede6e446,(FULL)0xf65a6713,(FULL)0x47c0d5c3,(FULL)0x8bf6dfae, + (FULL)0x9f7927d6,(FULL)0xfb4dfc17,(FULL)0xe212c297,(FULL)0x12ebbc16, + (FULL)0xa00a954c,(FULL)0x43c71283,(FULL)0xe7bd40a5,(FULL)0x8957087a, + (FULL)0x08344837,(FULL)0xb0859d71,(FULL)0xaeb313f5,(FULL)0xfbf4b9a3, + (FULL)0xce81823a,(FULL)0x5e66e5be,(FULL)0x58ad6da1,(FULL)0x09a11c6e, + (FULL)0xc608054f,(FULL)0xc76f4316,(FULL)0x46084099,(FULL)0xb5821361, + (FULL)0x17a725ed,(FULL)0x4210008f,(FULL)0xd347c481,(FULL)0xe5ff8912 + }, + { /* shuffle table */ + (FULL)0xec8abd57,(FULL)0x69a2296c,(FULL)0x99a6df81,(FULL)0x867e1869, + (FULL)0xd849a48a,(FULL)0xc05ab96b,(FULL)0xfa00554b,(FULL)0x7eb3ce0c, + (FULL)0x5a5a9acd,(FULL)0x520d01f6,(FULL)0x36022d81,(FULL)0xd4ef1e33, + (FULL)0xc6f84f70,(FULL)0xaf44772b,(FULL)0xa7c55173,(FULL)0x647e85a6, + (FULL)0x959df8d1,(FULL)0x26746cf1,(FULL)0x4db28abd,(FULL)0x98681a90, + (FULL)0x744c5cd2,(FULL)0xb146c969,(FULL)0x706f88c2,(FULL)0x8ce69d1f, + (FULL)0x21b4a748,(FULL)0xfd12eac4,(FULL)0x2710eea5,(FULL)0xf12e70fe, + (FULL)0x5901f2b5,(FULL)0x0b8f7805,(FULL)0x4f2c115e,(FULL)0x48860a76, + (FULL)0x30767e2c,(FULL)0x0edf6d2a,(FULL)0xfce2713b,(FULL)0x8a6d7dc5, + (FULL)0x4e0e2346,(FULL)0x46a362ea,(FULL)0x359f5aa7,(FULL)0x6c369a0a, + (FULL)0x41def54e,(FULL)0xdfca81fe,(FULL)0x96c2bc4e,(FULL)0x4b733819, + (FULL)0x6f3f14f9,(FULL)0x659e8b99,(FULL)0x93d47e6f,(FULL)0x8b97b934, + (FULL)0xdfa10a55,(FULL)0xa73a8704,(FULL)0xb06503da,(FULL)0x8d9eafe9, + (FULL)0xf32336b0,(FULL)0x2556fb88,(FULL)0x1002a161,(FULL)0xe71e9f75, + (FULL)0x200af907,(FULL)0x27a7be6e,(FULL)0xd028e9a3,(FULL)0x1b9b734e, + (FULL)0x4c0be0d3,(FULL)0x950cfeed,(FULL)0x2536d275,(FULL)0xf4c41694, + (FULL)0x5687b76e,(FULL)0xf05a58e8,(FULL)0x71a62d54,(FULL)0xba53ac01, + (FULL)0x285adc96,(FULL)0x4b14cbcb,(FULL)0xb00a5557,(FULL)0xfdf66edd, + (FULL)0x185b6ea1,(FULL)0xbb43d58d,(FULL)0xf355c9a6,(FULL)0x905db9cd, + (FULL)0x04429c8a,(FULL)0xfc3a07fc,(FULL)0xaa3a4f7e,(FULL)0x65d7e365, + (FULL)0xb243ac65,(FULL)0x2d284c18,(FULL)0x44e417fd,(FULL)0x72fba65d, + (FULL)0x5c934805,(FULL)0x422d50b4,(FULL)0xd1587441,(FULL)0xb62a6053, + (FULL)0x6f7ae035,(FULL)0xa5e71ce9,(FULL)0x595c8dd8,(FULL)0x93abca2e, + (FULL)0xe39afad5,(FULL)0x534231af,(FULL)0x12eaad56,(FULL)0x08d26cac, + (FULL)0x7fb1b1c2,(FULL)0xec18bf8d,(FULL)0xfaf6f09b,(FULL)0x3d28ea16, + (FULL)0x16697dd6,(FULL)0xea357a78,(FULL)0x420f3f51,(FULL)0x51471ea1, + (FULL)0x7f8946b4,(FULL)0x5e051aeb,(FULL)0x0cf0524c,(FULL)0x881be097, + (FULL)0x1b31489e,(FULL)0xd558b25b,(FULL)0x3a8b065c,(FULL)0x707d1a94, + (FULL)0x568ff836,(FULL)0x37017e66,(FULL)0x24c2f747,(FULL)0xb9cd627c, + (FULL)0xfb1d9ff6,(FULL)0x1485549f,(FULL)0xbdf2dc6f,(FULL)0x308d32d9, + (FULL)0xd543818a,(FULL)0x4d4142ca,(FULL)0x87ebba43,(FULL)0x5d9c7aee, + (FULL)0xe17adb2f,(FULL)0x81c5bdd8,(FULL)0xc8d8677a,(FULL)0x3dc9752e, + (FULL)0xc34e4212,(FULL)0x66b086e6,(FULL)0xc62b25e3,(FULL)0x3af7a90d, + (FULL)0x35539315,(FULL)0xf8349f79,(FULL)0xa22917f0,(FULL)0x6bcfd9d5, + (FULL)0x5f5ee517,(FULL)0x8639bb76,(FULL)0x8095b092,(FULL)0xd3c5e369, + (FULL)0x7eb44748,(FULL)0x8a33851e,(FULL)0xea54bbcf,(FULL)0x5e29d443, + (FULL)0x4d59a834,(FULL)0x0f84651f,(FULL)0xf1a5f951,(FULL)0x85040bea, + (FULL)0x98002078,(FULL)0x3dba1c74,(FULL)0xf0b2cc15,(FULL)0x5d70712b, + (FULL)0xcce8e5a7,(FULL)0xfa3af8eb,(FULL)0x04bba57d,(FULL)0xfb3e2237, + (FULL)0x8a950434,(FULL)0x5d3b8785,(FULL)0xba3f8dcf,(FULL)0xce3112bd, + (FULL)0x860d3051,(FULL)0x44904f55,(FULL)0x4ed3e98b,(FULL)0xcec8fed4, + (FULL)0x25d01ea4,(FULL)0x4581698d,(FULL)0x9a9548e0,(FULL)0x11eb6828, + (FULL)0xe911fac8,(FULL)0x796cb4c6,(FULL)0xb5fd813e,(FULL)0x2164cf26, + (FULL)0xd5de640f,(FULL)0x4ac8e0f5,(FULL)0x8802ab4e,(FULL)0xe9e757d7, + (FULL)0xf49dfcbd,(FULL)0x3c97de26,(FULL)0x6ee6dbe6,(FULL)0xc604881b, + (FULL)0x57d6154e,(FULL)0xa7c22a6e,(FULL)0x877b3cc7,(FULL)0x234e2370, + (FULL)0xdf1f8358,(FULL)0xc0bdb72b,(FULL)0xa95b7b55,(FULL)0x6522e0fc, + (FULL)0x22344162,(FULL)0xba174c90,(FULL)0x75d48867,(FULL)0x712c9b2d, + (FULL)0xe59f3700,(FULL)0x240f7e92,(FULL)0xad95d763,(FULL)0xe83cc2d4, + (FULL)0x4336d717,(FULL)0x8509445a,(FULL)0xdfff1804,(FULL)0xf1e572c5, + (FULL)0x623232dd,(FULL)0xed10eb5d,(FULL)0xd4f957e8,(FULL)0x9205ea1b, + (FULL)0x2ff062f5,(FULL)0x4973a54f,(FULL)0xe8c48cd5,(FULL)0x26b018f1, + (FULL)0xd1c7ed9f,(FULL)0x56908401,(FULL)0xdf89a247,(FULL)0x2e48937b, + (FULL)0x2be47129,(FULL)0x9d53069b,(FULL)0xc048a2b0,(FULL)0x98069e3b, + (FULL)0x1cd83f93,(FULL)0xf25b7d65,(FULL)0xe6f886c8,(FULL)0x2b004e6c, + (FULL)0x5c635935,(FULL)0xf618442a,(FULL)0x7198e052,(FULL)0xa502ab5c, + (FULL)0xa6c41b0b,(FULL)0xc14241a4,(FULL)0x7db9b18e,(FULL)0x720e845a, + (FULL)0x4b713918,(FULL)0x2abb13e9,(FULL)0x7f52467d,(FULL)0x90fc0c20, + (FULL)0x7868d348,(FULL)0x799c8ccd,(FULL)0x912a0ea4,(FULL)0xf4817ced, + (FULL)0xc4903a57,(FULL)0xd68c0f4c,(FULL)0xe2b7934c,(FULL)0xa3171f29, + (FULL)0x0b4ccc22,(FULL)0xb1158baa,(FULL)0x49a29eda,(FULL)0xf5d85553, + (FULL)0x959442ef,(FULL)0x59d1a078,(FULL)0xa67fd518,(FULL)0xdb9b4a96, + (FULL)0xd2870636,(FULL)0xcc7ca9ee,(FULL)0xecf59920,(FULL)0x548f021c, + (FULL)0x571bc8c5,(FULL)0x25b7f4b6,(FULL)0x3a44f536,(FULL)0x4fa52747, + (FULL)0xdf0ebdc2,(FULL)0xb246845f,(FULL)0x42058793,(FULL)0xdd8d68ae, + (FULL)0x9f6c39fb,(FULL)0x3ba13328,(FULL)0x7b6b42af,(FULL)0x8bfdfbf3, + (FULL)0x7fb2b3b0,(FULL)0xfb34c5ca,(FULL)0xd428e32a,(FULL)0x2345dcec, + (FULL)0xad42b63e,(FULL)0x6891e850,(FULL)0x362c1381,(FULL)0x930642c8, + (FULL)0x1886aff5,(FULL)0x13871e9b,(FULL)0x482bda55,(FULL)0xd0cf2407, + (FULL)0x5069bc31,(FULL)0x125b5fc9,(FULL)0xf07dfa5d,(FULL)0x9b71d0a9, + (FULL)0x6712e524,(FULL)0x55c044cc,(FULL)0xbb601978,(FULL)0xf0377358, + (FULL)0x7fa51e8b,(FULL)0x152ad5f8,(FULL)0x9fcdd9af,(FULL)0xe5ebf478, + (FULL)0x66ebce7e,(FULL)0x3d78e18c,(FULL)0xf36aa83f,(FULL)0x8246db72, + (FULL)0x2c64c0a3,(FULL)0xcc6ddc6d,(FULL)0x0d91851e,(FULL)0xa758d687, + (FULL)0x9488ee36,(FULL)0x24b20a6f,(FULL)0x09798197,(FULL)0xbe11ccdf, + (FULL)0x99c1f4e3,(FULL)0x11aca015,(FULL)0x6437ac05,(FULL)0x40e89e36, + (FULL)0x5af675f8,(FULL)0xc8bfc762,(FULL)0xb577e759,(FULL)0x6367c578, + (FULL)0x615f0b74,(FULL)0x00380346,(FULL)0x8de07d81,(FULL)0xee964cc4, + (FULL)0x859d9261,(FULL)0x17f6ac16,(FULL)0x3a6e2f6c,(FULL)0x092f4a17, + (FULL)0xb9024b95,(FULL)0x79981a3d,(FULL)0x04f7f540,(FULL)0x36db1660, + (FULL)0x65a2f1c8,(FULL)0xc36252cf,(FULL)0x124c9bd2,(FULL)0x705b6fde, + (FULL)0x85db40ce,(FULL)0x31e58dda,(FULL)0x9f5e8d6d,(FULL)0x6342b1a5, + (FULL)0xbd6d1d4d,(FULL)0x5c2c67d0,(FULL)0xba7e069d,(FULL)0x1fe5b46f, + (FULL)0xac72e13c,(FULL)0x21c46c6c,(FULL)0x9eb8f52a,(FULL)0xb80c5fd5, + (FULL)0xa74c92bc,(FULL)0x56c3aebf,(FULL)0xbf8c4196,(FULL)0xc1aff1fc, + (FULL)0x754ad208,(FULL)0x2b1df645,(FULL)0xd46eeb50,(FULL)0x5c734600, + (FULL)0x6a70a765,(FULL)0xe0ff1b12,(FULL)0x7a94547c,(FULL)0xd5416497, + (FULL)0x4ea35206,(FULL)0x67b59d7c,(FULL)0x779203b4,(FULL)0x53be7146, + (FULL)0x414026b8,(FULL)0x6b589fe5,(FULL)0x3083bfee,(FULL)0x9e81016c, + (FULL)0x3b4b7671,(FULL)0xb23526b9,(FULL)0x7ee300ba,(FULL)0x4fa9ffb1, + (FULL)0xad05fb21,(FULL)0x6217e212,(FULL)0xb294e6c2,(FULL)0xf5b3fcd3, + (FULL)0x216beb2a,(FULL)0xac040bbe,(FULL)0x71d0e78c,(FULL)0x1f8d8a54, + (FULL)0x9cfec96b,(FULL)0xb6d15b41,(FULL)0xd0508c78,(FULL)0xc5477845, + (FULL)0xb4bba621,(FULL)0x5b486e81,(FULL)0xef4c4121,(FULL)0x90c35c94, + (FULL)0xf6a6bc55,(FULL)0xefce7346,(FULL)0x25bdb9bb,(FULL)0xa27828d9, + (FULL)0xa1f0b205,(FULL)0xe3a53095,(FULL)0xd9f208ab,(FULL)0x1bfa6093, + (FULL)0x6842cdf4,(FULL)0xfb078f6a,(FULL)0x97133a38,(FULL)0x07806d72, + (FULL)0xa3ce9592,(FULL)0x2c6c901b,(FULL)0xebc1b789,(FULL)0x1f0ab2cf, + (FULL)0xe2d03d5e,(FULL)0x2ce81415,(FULL)0xaa9f2417,(FULL)0x7da45d5b, + (FULL)0xdd800682,(FULL)0x3be4f76d,(FULL)0x364d72d3,(FULL)0xdbf4e4a3, + (FULL)0x4fc59da5,(FULL)0xb538cccf,(FULL)0x487f66ec,(FULL)0xb0aa39d5, + (FULL)0x87927d3d,(FULL)0x2fd28dfd,(FULL)0x5900c6b1,(FULL)0xd14e77f0, + (FULL)0x5330c7b4,(FULL)0x2523fad2,(FULL)0xd82368a4,(FULL)0x991b5938, + (FULL)0x2b9c1302,(FULL)0xb7c11443,(FULL)0x1394b116,(FULL)0xdb842db6, + (FULL)0x78ed26d8,(FULL)0x3641548d,(FULL)0x0a61dacf,(FULL)0x274fa8ef, + (FULL)0x112df6f1,(FULL)0xa554ba63,(FULL)0x6b50438d,(FULL)0x7b7fe985, + (FULL)0xbb63bbad,(FULL)0xc9fa0042,(FULL)0xe27f00da,(FULL)0x3abf45d0, + (FULL)0x9f87aabb,(FULL)0xd95faa15,(FULL)0x3488e7ae,(FULL)0x4a95012e, + (FULL)0x0c642d04,(FULL)0x1be2bdb9,(FULL)0x8b4abf3e,(FULL)0x145c8881, + (FULL)0x544cf17f,(FULL)0x7f9fb635,(FULL)0xcc78db70,(FULL)0xb8ab2f62, + (FULL)0xb4242f9a,(FULL)0x8ee64bcd,(FULL)0x95dad129,(FULL)0xabd52858, + (FULL)0xccf31141,(FULL)0xbe722c2f,(FULL)0x575e26a9,(FULL)0x7c330703, + (FULL)0x361b79e4,(FULL)0x45d3e3b3,(FULL)0x54b2e6a6,(FULL)0x241163a7, + (FULL)0xf7cacb77,(FULL)0x8f678d7d,(FULL)0x83211d19,(FULL)0x988a68a4, + (FULL)0xba7836f6,(FULL)0x79599598,(FULL)0xeeda68bf,(FULL)0x4850c887, + (FULL)0x8052ce25,(FULL)0xafa69a71,(FULL)0xbdd73573,(FULL)0x8b21efc6, + (FULL)0xd0972493,(FULL)0x89dbae18,(FULL)0x537d9454,(FULL)0x560776bf, + (FULL)0x165310f2,(FULL)0x3c009f78,(FULL)0x0160c3af,(FULL)0xa3680021, + (FULL)0xa643bd40,(FULL)0x3353ec3c,(FULL)0x911dab02,(FULL)0x7e593f99, + (FULL)0x4f676e89,(FULL)0x72d1ddd9,(FULL)0x6b43c0ea,(FULL)0xfd18b8bd, + (FULL)0xddbd697d,(FULL)0x43cacef2,(FULL)0xacefe884,(FULL)0x2868a4d0, + (FULL)0xa506f013,(FULL)0x5f377b63,(FULL)0x05ca662b,(FULL)0xeaa0975e, + (FULL)0xeb433931,(FULL)0x3740e6b8,(FULL)0x08557948,(FULL)0xce85df00, + (FULL)0x547e33f9,(FULL)0x784745fb,(FULL)0xe5c6f598,(FULL)0x4a1fc5d4, + (FULL)0x768430a7,(FULL)0x85fa6fec,(FULL)0xd2332a51,(FULL)0x990d0c24, + (FULL)0x33b676d5,(FULL)0x55245c2c,(FULL)0xe2bcfa71,(FULL)0xb1091519, + (FULL)0xd23a28d8,(FULL)0x38521478,(FULL)0x9a573010,(FULL)0x9b794f89, + (FULL)0x699bb486,(FULL)0x61d225e8,(FULL)0x1c2158b0,(FULL)0x21476d24 + } #else - /\../\ FULL_BITS must be 32 or 64 /\../\ !!! + /\../\ FULL_BITS must be 32 or 64 /\../\ !!! #endif }; @@ -762,109 +762,109 @@ STATIC CONST RAND init_s100 = { */ STATIC CONST FULL def_subtract[SCNT] = { #if FULL_BITS == SBITS - (FULL)U(0xc8c0370c7db7dc19), (FULL)U(0x738e33b940a06fbb), - (FULL)U(0x481abb76a859ed2b), (FULL)U(0x74106bb39ccdccb5), - (FULL)U(0x05a8eeb5c3173bfc), (FULL)U(0xefd5100d5a02e577), - (FULL)U(0xa69271f74030b24a), (FULL)U(0x641282fc16fe22c5), - (FULL)U(0x7aa7267c40438da3), (FULL)U(0x1fdf4abdc2d878d1), - (FULL)U(0xd9899e7a95702379), (FULL)U(0x5ea8e217d02d7f08), - (FULL)U(0x770587fe4d47a353), (FULL)U(0xde7d1bdd0a33a2b8), - (FULL)U(0x4378c3c5900e7c45), (FULL)U(0x77c9447819a514f9), - (FULL)U(0xfc5edb22843d1d32), (FULL)U(0x4fc42ce5e8ee5e6e), - (FULL)U(0xc938713c8488013e), (FULL)U(0x6a318f0320ab0cac), - (FULL)U(0x73e6d1a3ffc8bff3), (FULL)U(0x0cd3232a8ca96aa7), - (FULL)U(0x605c8036905f770d), (FULL)U(0x4d037b008b8d04a2), - (FULL)U(0x1ed81965cb277294), (FULL)U(0x408d9c477a254ff3), - (FULL)U(0x8b68587ae26c7377), (FULL)U(0xcff191a48a48832f), - (FULL)U(0x12d3df1d8aeb6fe6), (FULL)U(0xb2bf907e1feda37a), - (FULL)U(0x4e5f77193bb5f39f), (FULL)U(0x33ebcf6f8f5d1581), - (FULL)U(0x203c8e48d33654eb), (FULL)U(0x68d3656ef19c8a4e), - (FULL)U(0x3ec20b04986eb2af), (FULL)U(0x5d73a03b062c3841), - (FULL)U(0x836ce7095d4e49eb), (FULL)U(0x2310bc40c3f49221), - (FULL)U(0x3868ee48a6d0cbf6), (FULL)U(0x67578aa64a43deb1), - (FULL)U(0x6e3426c1150dfc26), (FULL)U(0xc541ccaa3131be30), - (FULL)U(0xf7e57432cec7aab2), (FULL)U(0x2b35de998cb3c873), - (FULL)U(0x7b9f77648663a5d7), (FULL)U(0x23b00e6aa771e5a6), - (FULL)U(0x859c775ca9985d05), (FULL)U(0x99636ea16b692f1f), - (FULL)U(0x8700ac703730800d), (FULL)U(0x461425024298a753), - (FULL)U(0xea4a411b809e955f), (FULL)U(0x3119ad4033709dfb), - (FULL)U(0xb76a6c6e5f01cb7c), (FULL)U(0x6109dc8a15984eaf), - (FULL)U(0x5d686db9a5ca9505), (FULL)U(0x8e80d7613b7e6add), - (FULL)U(0x79cbd718de6f6fd3), (FULL)U(0x40e9cd151da0f699), - (FULL)U(0xe82158bab24f312d), (FULL)U(0x79a4c927f5e5c36b), - (FULL)U(0xc25247c9a0039333), (FULL)U(0x936871161766d81d), - (FULL)U(0x3c6a03b4a6741327), (FULL)U(0xc8a7b6e8c002f29a), - (FULL)U(0x0e2a67c67bbd5ea3), (FULL)U(0x0929042d441eabc1), - (FULL)U(0x7dbe232a25e82085), (FULL)U(0x8cfb26e544fbac3d), - (FULL)U(0x8e40384d388ab983), (FULL)U(0x48dc1230554632f8), - (FULL)U(0xab405048ab492397), (FULL)U(0x21c9e2f5a118e387), - (FULL)U(0x484d1a8c343b61b5), (FULL)U(0xd49e3decab256f26), - (FULL)U(0xe615c7fd78f2d2e3), (FULL)U(0x8442cc33ce6cc2ed), - (FULL)U(0x0a3b93d844d4bbf6), (FULL)U(0x2d7e4efe9301de77), - (FULL)U(0x33711b76d8790d8a), (FULL)U(0xc07dc30e44df77e7), - (FULL)U(0xb9132ed09ddd508f), (FULL)U(0x45d06cf8c6fb43cc), - (FULL)U(0x22bed18ad585dd7b), (FULL)U(0x61c6cced10799ffa), - (FULL)U(0xd7f2393be4bd9aa9), (FULL)U(0x706753fbcfd55094), - (FULL)U(0xf65a6713ede6e446), (FULL)U(0x8bf6dfae47c0d5c3), - (FULL)U(0xfb4dfc179f7927d6), (FULL)U(0x12ebbc16e212c297), - (FULL)U(0x43c71283a00a954c), (FULL)U(0x8957087ae7bd40a5), - (FULL)U(0xb0859d7108344837), (FULL)U(0xfbf4b9a3aeb313f5), - (FULL)U(0x5e66e5bece81823a), (FULL)U(0x09a11c6e58ad6da1), - (FULL)U(0xc76f4316c608054f), (FULL)U(0xb582136146084099), - (FULL)U(0x4210008f17a725ed), (FULL)U(0xe5ff8912d347c481) + (FULL)U(0xc8c0370c7db7dc19), (FULL)U(0x738e33b940a06fbb), + (FULL)U(0x481abb76a859ed2b), (FULL)U(0x74106bb39ccdccb5), + (FULL)U(0x05a8eeb5c3173bfc), (FULL)U(0xefd5100d5a02e577), + (FULL)U(0xa69271f74030b24a), (FULL)U(0x641282fc16fe22c5), + (FULL)U(0x7aa7267c40438da3), (FULL)U(0x1fdf4abdc2d878d1), + (FULL)U(0xd9899e7a95702379), (FULL)U(0x5ea8e217d02d7f08), + (FULL)U(0x770587fe4d47a353), (FULL)U(0xde7d1bdd0a33a2b8), + (FULL)U(0x4378c3c5900e7c45), (FULL)U(0x77c9447819a514f9), + (FULL)U(0xfc5edb22843d1d32), (FULL)U(0x4fc42ce5e8ee5e6e), + (FULL)U(0xc938713c8488013e), (FULL)U(0x6a318f0320ab0cac), + (FULL)U(0x73e6d1a3ffc8bff3), (FULL)U(0x0cd3232a8ca96aa7), + (FULL)U(0x605c8036905f770d), (FULL)U(0x4d037b008b8d04a2), + (FULL)U(0x1ed81965cb277294), (FULL)U(0x408d9c477a254ff3), + (FULL)U(0x8b68587ae26c7377), (FULL)U(0xcff191a48a48832f), + (FULL)U(0x12d3df1d8aeb6fe6), (FULL)U(0xb2bf907e1feda37a), + (FULL)U(0x4e5f77193bb5f39f), (FULL)U(0x33ebcf6f8f5d1581), + (FULL)U(0x203c8e48d33654eb), (FULL)U(0x68d3656ef19c8a4e), + (FULL)U(0x3ec20b04986eb2af), (FULL)U(0x5d73a03b062c3841), + (FULL)U(0x836ce7095d4e49eb), (FULL)U(0x2310bc40c3f49221), + (FULL)U(0x3868ee48a6d0cbf6), (FULL)U(0x67578aa64a43deb1), + (FULL)U(0x6e3426c1150dfc26), (FULL)U(0xc541ccaa3131be30), + (FULL)U(0xf7e57432cec7aab2), (FULL)U(0x2b35de998cb3c873), + (FULL)U(0x7b9f77648663a5d7), (FULL)U(0x23b00e6aa771e5a6), + (FULL)U(0x859c775ca9985d05), (FULL)U(0x99636ea16b692f1f), + (FULL)U(0x8700ac703730800d), (FULL)U(0x461425024298a753), + (FULL)U(0xea4a411b809e955f), (FULL)U(0x3119ad4033709dfb), + (FULL)U(0xb76a6c6e5f01cb7c), (FULL)U(0x6109dc8a15984eaf), + (FULL)U(0x5d686db9a5ca9505), (FULL)U(0x8e80d7613b7e6add), + (FULL)U(0x79cbd718de6f6fd3), (FULL)U(0x40e9cd151da0f699), + (FULL)U(0xe82158bab24f312d), (FULL)U(0x79a4c927f5e5c36b), + (FULL)U(0xc25247c9a0039333), (FULL)U(0x936871161766d81d), + (FULL)U(0x3c6a03b4a6741327), (FULL)U(0xc8a7b6e8c002f29a), + (FULL)U(0x0e2a67c67bbd5ea3), (FULL)U(0x0929042d441eabc1), + (FULL)U(0x7dbe232a25e82085), (FULL)U(0x8cfb26e544fbac3d), + (FULL)U(0x8e40384d388ab983), (FULL)U(0x48dc1230554632f8), + (FULL)U(0xab405048ab492397), (FULL)U(0x21c9e2f5a118e387), + (FULL)U(0x484d1a8c343b61b5), (FULL)U(0xd49e3decab256f26), + (FULL)U(0xe615c7fd78f2d2e3), (FULL)U(0x8442cc33ce6cc2ed), + (FULL)U(0x0a3b93d844d4bbf6), (FULL)U(0x2d7e4efe9301de77), + (FULL)U(0x33711b76d8790d8a), (FULL)U(0xc07dc30e44df77e7), + (FULL)U(0xb9132ed09ddd508f), (FULL)U(0x45d06cf8c6fb43cc), + (FULL)U(0x22bed18ad585dd7b), (FULL)U(0x61c6cced10799ffa), + (FULL)U(0xd7f2393be4bd9aa9), (FULL)U(0x706753fbcfd55094), + (FULL)U(0xf65a6713ede6e446), (FULL)U(0x8bf6dfae47c0d5c3), + (FULL)U(0xfb4dfc179f7927d6), (FULL)U(0x12ebbc16e212c297), + (FULL)U(0x43c71283a00a954c), (FULL)U(0x8957087ae7bd40a5), + (FULL)U(0xb0859d7108344837), (FULL)U(0xfbf4b9a3aeb313f5), + (FULL)U(0x5e66e5bece81823a), (FULL)U(0x09a11c6e58ad6da1), + (FULL)U(0xc76f4316c608054f), (FULL)U(0xb582136146084099), + (FULL)U(0x4210008f17a725ed), (FULL)U(0xe5ff8912d347c481) #elif 2*FULL_BITS == SBITS - (FULL)0x7db7dc19,(FULL)0xc8c0370c,(FULL)0x40a06fbb,(FULL)0x738e33b9, - (FULL)0xa859ed2b,(FULL)0x481abb76,(FULL)0x9ccdccb5,(FULL)0x74106bb3, - (FULL)0xc3173bfc,(FULL)0x05a8eeb5,(FULL)0x5a02e577,(FULL)0xefd5100d, - (FULL)0x4030b24a,(FULL)0xa69271f7,(FULL)0x16fe22c5,(FULL)0x641282fc, - (FULL)0x40438da3,(FULL)0x7aa7267c,(FULL)0xc2d878d1,(FULL)0x1fdf4abd, - (FULL)0x95702379,(FULL)0xd9899e7a,(FULL)0xd02d7f08,(FULL)0x5ea8e217, - (FULL)0x4d47a353,(FULL)0x770587fe,(FULL)0x0a33a2b8,(FULL)0xde7d1bdd, - (FULL)0x900e7c45,(FULL)0x4378c3c5,(FULL)0x19a514f9,(FULL)0x77c94478, - (FULL)0x843d1d32,(FULL)0xfc5edb22,(FULL)0xe8ee5e6e,(FULL)0x4fc42ce5, - (FULL)0x8488013e,(FULL)0xc938713c,(FULL)0x20ab0cac,(FULL)0x6a318f03, - (FULL)0xffc8bff3,(FULL)0x73e6d1a3,(FULL)0x8ca96aa7,(FULL)0x0cd3232a, - (FULL)0x905f770d,(FULL)0x605c8036,(FULL)0x8b8d04a2,(FULL)0x4d037b00, - (FULL)0xcb277294,(FULL)0x1ed81965,(FULL)0x7a254ff3,(FULL)0x408d9c47, - (FULL)0xe26c7377,(FULL)0x8b68587a,(FULL)0x8a48832f,(FULL)0xcff191a4, - (FULL)0x8aeb6fe6,(FULL)0x12d3df1d,(FULL)0x1feda37a,(FULL)0xb2bf907e, - (FULL)0x3bb5f39f,(FULL)0x4e5f7719,(FULL)0x8f5d1581,(FULL)0x33ebcf6f, - (FULL)0xd33654eb,(FULL)0x203c8e48,(FULL)0xf19c8a4e,(FULL)0x68d3656e, - (FULL)0x986eb2af,(FULL)0x3ec20b04,(FULL)0x062c3841,(FULL)0x5d73a03b, - (FULL)0x5d4e49eb,(FULL)0x836ce709,(FULL)0xc3f49221,(FULL)0x2310bc40, - (FULL)0xa6d0cbf6,(FULL)0x3868ee48,(FULL)0x4a43deb1,(FULL)0x67578aa6, - (FULL)0x150dfc26,(FULL)0x6e3426c1,(FULL)0x3131be30,(FULL)0xc541ccaa, - (FULL)0xcec7aab2,(FULL)0xf7e57432,(FULL)0x8cb3c873,(FULL)0x2b35de99, - (FULL)0x8663a5d7,(FULL)0x7b9f7764,(FULL)0xa771e5a6,(FULL)0x23b00e6a, - (FULL)0xa9985d05,(FULL)0x859c775c,(FULL)0x6b692f1f,(FULL)0x99636ea1, - (FULL)0x3730800d,(FULL)0x8700ac70,(FULL)0x4298a753,(FULL)0x46142502, - (FULL)0x809e955f,(FULL)0xea4a411b,(FULL)0x33709dfb,(FULL)0x3119ad40, - (FULL)0x5f01cb7c,(FULL)0xb76a6c6e,(FULL)0x15984eaf,(FULL)0x6109dc8a, - (FULL)0xa5ca9505,(FULL)0x5d686db9,(FULL)0x3b7e6add,(FULL)0x8e80d761, - (FULL)0xde6f6fd3,(FULL)0x79cbd718,(FULL)0x1da0f699,(FULL)0x40e9cd15, - (FULL)0xb24f312d,(FULL)0xe82158ba,(FULL)0xf5e5c36b,(FULL)0x79a4c927, - (FULL)0xa0039333,(FULL)0xc25247c9,(FULL)0x1766d81d,(FULL)0x93687116, - (FULL)0xa6741327,(FULL)0x3c6a03b4,(FULL)0xc002f29a,(FULL)0xc8a7b6e8, - (FULL)0x7bbd5ea3,(FULL)0x0e2a67c6,(FULL)0x441eabc1,(FULL)0x0929042d, - (FULL)0x25e82085,(FULL)0x7dbe232a,(FULL)0x44fbac3d,(FULL)0x8cfb26e5, - (FULL)0x388ab983,(FULL)0x8e40384d,(FULL)0x554632f8,(FULL)0x48dc1230, - (FULL)0xab492397,(FULL)0xab405048,(FULL)0xa118e387,(FULL)0x21c9e2f5, - (FULL)0x343b61b5,(FULL)0x484d1a8c,(FULL)0xab256f26,(FULL)0xd49e3dec, - (FULL)0x78f2d2e3,(FULL)0xe615c7fd,(FULL)0xce6cc2ed,(FULL)0x8442cc33, - (FULL)0x44d4bbf6,(FULL)0x0a3b93d8,(FULL)0x9301de77,(FULL)0x2d7e4efe, - (FULL)0xd8790d8a,(FULL)0x33711b76,(FULL)0x44df77e7,(FULL)0xc07dc30e, - (FULL)0x9ddd508f,(FULL)0xb9132ed0,(FULL)0xc6fb43cc,(FULL)0x45d06cf8, - (FULL)0xd585dd7b,(FULL)0x22bed18a,(FULL)0x10799ffa,(FULL)0x61c6cced, - (FULL)0xe4bd9aa9,(FULL)0xd7f2393b,(FULL)0xcfd55094,(FULL)0x706753fb, - (FULL)0xede6e446,(FULL)0xf65a6713,(FULL)0x47c0d5c3,(FULL)0x8bf6dfae, - (FULL)0x9f7927d6,(FULL)0xfb4dfc17,(FULL)0xe212c297,(FULL)0x12ebbc16, - (FULL)0xa00a954c,(FULL)0x43c71283,(FULL)0xe7bd40a5,(FULL)0x8957087a, - (FULL)0x08344837,(FULL)0xb0859d71,(FULL)0xaeb313f5,(FULL)0xfbf4b9a3, - (FULL)0xce81823a,(FULL)0x5e66e5be,(FULL)0x58ad6da1,(FULL)0x09a11c6e, - (FULL)0xc608054f,(FULL)0xc76f4316,(FULL)0x46084099,(FULL)0xb5821361, - (FULL)0x17a725ed,(FULL)0x4210008f,(FULL)0xd347c481,(FULL)0xe5ff8912 + (FULL)0x7db7dc19,(FULL)0xc8c0370c,(FULL)0x40a06fbb,(FULL)0x738e33b9, + (FULL)0xa859ed2b,(FULL)0x481abb76,(FULL)0x9ccdccb5,(FULL)0x74106bb3, + (FULL)0xc3173bfc,(FULL)0x05a8eeb5,(FULL)0x5a02e577,(FULL)0xefd5100d, + (FULL)0x4030b24a,(FULL)0xa69271f7,(FULL)0x16fe22c5,(FULL)0x641282fc, + (FULL)0x40438da3,(FULL)0x7aa7267c,(FULL)0xc2d878d1,(FULL)0x1fdf4abd, + (FULL)0x95702379,(FULL)0xd9899e7a,(FULL)0xd02d7f08,(FULL)0x5ea8e217, + (FULL)0x4d47a353,(FULL)0x770587fe,(FULL)0x0a33a2b8,(FULL)0xde7d1bdd, + (FULL)0x900e7c45,(FULL)0x4378c3c5,(FULL)0x19a514f9,(FULL)0x77c94478, + (FULL)0x843d1d32,(FULL)0xfc5edb22,(FULL)0xe8ee5e6e,(FULL)0x4fc42ce5, + (FULL)0x8488013e,(FULL)0xc938713c,(FULL)0x20ab0cac,(FULL)0x6a318f03, + (FULL)0xffc8bff3,(FULL)0x73e6d1a3,(FULL)0x8ca96aa7,(FULL)0x0cd3232a, + (FULL)0x905f770d,(FULL)0x605c8036,(FULL)0x8b8d04a2,(FULL)0x4d037b00, + (FULL)0xcb277294,(FULL)0x1ed81965,(FULL)0x7a254ff3,(FULL)0x408d9c47, + (FULL)0xe26c7377,(FULL)0x8b68587a,(FULL)0x8a48832f,(FULL)0xcff191a4, + (FULL)0x8aeb6fe6,(FULL)0x12d3df1d,(FULL)0x1feda37a,(FULL)0xb2bf907e, + (FULL)0x3bb5f39f,(FULL)0x4e5f7719,(FULL)0x8f5d1581,(FULL)0x33ebcf6f, + (FULL)0xd33654eb,(FULL)0x203c8e48,(FULL)0xf19c8a4e,(FULL)0x68d3656e, + (FULL)0x986eb2af,(FULL)0x3ec20b04,(FULL)0x062c3841,(FULL)0x5d73a03b, + (FULL)0x5d4e49eb,(FULL)0x836ce709,(FULL)0xc3f49221,(FULL)0x2310bc40, + (FULL)0xa6d0cbf6,(FULL)0x3868ee48,(FULL)0x4a43deb1,(FULL)0x67578aa6, + (FULL)0x150dfc26,(FULL)0x6e3426c1,(FULL)0x3131be30,(FULL)0xc541ccaa, + (FULL)0xcec7aab2,(FULL)0xf7e57432,(FULL)0x8cb3c873,(FULL)0x2b35de99, + (FULL)0x8663a5d7,(FULL)0x7b9f7764,(FULL)0xa771e5a6,(FULL)0x23b00e6a, + (FULL)0xa9985d05,(FULL)0x859c775c,(FULL)0x6b692f1f,(FULL)0x99636ea1, + (FULL)0x3730800d,(FULL)0x8700ac70,(FULL)0x4298a753,(FULL)0x46142502, + (FULL)0x809e955f,(FULL)0xea4a411b,(FULL)0x33709dfb,(FULL)0x3119ad40, + (FULL)0x5f01cb7c,(FULL)0xb76a6c6e,(FULL)0x15984eaf,(FULL)0x6109dc8a, + (FULL)0xa5ca9505,(FULL)0x5d686db9,(FULL)0x3b7e6add,(FULL)0x8e80d761, + (FULL)0xde6f6fd3,(FULL)0x79cbd718,(FULL)0x1da0f699,(FULL)0x40e9cd15, + (FULL)0xb24f312d,(FULL)0xe82158ba,(FULL)0xf5e5c36b,(FULL)0x79a4c927, + (FULL)0xa0039333,(FULL)0xc25247c9,(FULL)0x1766d81d,(FULL)0x93687116, + (FULL)0xa6741327,(FULL)0x3c6a03b4,(FULL)0xc002f29a,(FULL)0xc8a7b6e8, + (FULL)0x7bbd5ea3,(FULL)0x0e2a67c6,(FULL)0x441eabc1,(FULL)0x0929042d, + (FULL)0x25e82085,(FULL)0x7dbe232a,(FULL)0x44fbac3d,(FULL)0x8cfb26e5, + (FULL)0x388ab983,(FULL)0x8e40384d,(FULL)0x554632f8,(FULL)0x48dc1230, + (FULL)0xab492397,(FULL)0xab405048,(FULL)0xa118e387,(FULL)0x21c9e2f5, + (FULL)0x343b61b5,(FULL)0x484d1a8c,(FULL)0xab256f26,(FULL)0xd49e3dec, + (FULL)0x78f2d2e3,(FULL)0xe615c7fd,(FULL)0xce6cc2ed,(FULL)0x8442cc33, + (FULL)0x44d4bbf6,(FULL)0x0a3b93d8,(FULL)0x9301de77,(FULL)0x2d7e4efe, + (FULL)0xd8790d8a,(FULL)0x33711b76,(FULL)0x44df77e7,(FULL)0xc07dc30e, + (FULL)0x9ddd508f,(FULL)0xb9132ed0,(FULL)0xc6fb43cc,(FULL)0x45d06cf8, + (FULL)0xd585dd7b,(FULL)0x22bed18a,(FULL)0x10799ffa,(FULL)0x61c6cced, + (FULL)0xe4bd9aa9,(FULL)0xd7f2393b,(FULL)0xcfd55094,(FULL)0x706753fb, + (FULL)0xede6e446,(FULL)0xf65a6713,(FULL)0x47c0d5c3,(FULL)0x8bf6dfae, + (FULL)0x9f7927d6,(FULL)0xfb4dfc17,(FULL)0xe212c297,(FULL)0x12ebbc16, + (FULL)0xa00a954c,(FULL)0x43c71283,(FULL)0xe7bd40a5,(FULL)0x8957087a, + (FULL)0x08344837,(FULL)0xb0859d71,(FULL)0xaeb313f5,(FULL)0xfbf4b9a3, + (FULL)0xce81823a,(FULL)0x5e66e5be,(FULL)0x58ad6da1,(FULL)0x09a11c6e, + (FULL)0xc608054f,(FULL)0xc76f4316,(FULL)0x46084099,(FULL)0xb5821361, + (FULL)0x17a725ed,(FULL)0x4210008f,(FULL)0xd347c481,(FULL)0xe5ff8912 #else - /\../\ FULL_BITS must be 32 or 64 /\../\ !!! + /\../\ FULL_BITS must be 32 or 64 /\../\ !!! #endif }; @@ -872,8 +872,8 @@ STATIC CONST FULL def_subtract[SCNT] = { /* * Linear Congruential Constants * - * a = 6316878969928993981 = 0x57aa0ff473c0ccbd - * c = 1363042948800878693 = 0x12ea805718e09865 + * a = 6316878969928993981 = 0x57aa0ff473c0ccbd + * c = 1363042948800878693 = 0x12ea805718e09865 * * These constants are used in the randreseed64(). See below. */ @@ -882,11 +882,11 @@ STATIC CONST HALF a_vec[SHALFS] = { (HALF)0x73c0ccbd, (HALF)0x57aa0ff4 }; STATIC CONST HALF c_vec[SHALFS] = { (HALF)0x18e09865, (HALF)0x12ea8057 }; #elif 2*FULL_BITS == SBITS STATIC CONST HALF a_vec[SHALFS] = { (HALF)0xccbd, (HALF)0x73c0, - (HALF)0x0ff4, (HALF)0x57aa }; + (HALF)0x0ff4, (HALF)0x57aa }; STATIC CONST HALF c_vec[SHALFS] = { (HALF)0x9865, (HALF)0x18e0, - (HALF)0x8057, (HALF)0x12ea }; + (HALF)0x8057, (HALF)0x12ea }; #else - /\../\ FULL_BITS must be 32 or 64 /\../\ !!! + /\../\ FULL_BITS must be 32 or 64 /\../\ !!! #endif STATIC CONST ZVALUE a_val = {(HALF *)a_vec, SHALFS, 0}; STATIC CONST ZVALUE c_val = {(HALF *)c_vec, SHALFS, 0}; @@ -910,10 +910,10 @@ S_FUNC void slotcp64(BITSTR *bitstr, FULL *src); * randreseed64 - scramble seed in 64 bit chunks * * given: - * a seed + * a seed * * returns: - * a scrambled seed, or 0 if seed was 0 + * a scrambled seed, or 0 if seed was 0 * * It is 'nice' when a seed of "n" produces a 'significantly different' * sequence than a seed of "n+1". Generators, by convention, assign @@ -938,12 +938,12 @@ S_FUNC void slotcp64(BITSTR *bitstr, FULL *src); * into [0,2^64). This map is one-to-one and onto. Mapping is performed * using a linear congruence generator of the form: * - * X1 <-- (a*X0 + c) % m + * X1 <-- (a*X0 + c) % m * * with the exception that: * - * 0 ==> 0 (so that srand(0) acts as default) - * randreseed64() is an 1-to-1 and onto map + * 0 ==> 0 (so that srand(0) acts as default) + * randreseed64() is an 1-to-1 and onto map * * The generator are based on the linear congruential generators found in * Knuth's "The Art of Computer Programming - Seminumerical Algorithms", @@ -951,208 +951,208 @@ S_FUNC void slotcp64(BITSTR *bitstr, FULL *src); * * Because we process 64 bits we will take: * - * m = 2^64 (based on note ii) + * m = 2^64 (based on note ii) * * We will scan the Rand Book of Random Numbers to look for an 'a' such that: * - * a mod 8 == 5 (based on note iii) - * 0.01*m < a < 0.99*m (based on note iv) - * 0.01*2^64 < a < 0.99*2^64 + * a mod 8 == 5 (based on note iii) + * 0.01*m < a < 0.99*m (based on note iv) + * 0.01*2^64 < a < 0.99*2^64 * * To help keep the generators independent, we want: * - * a is prime + * a is prime * * The choice of an adder 'c' is considered immaterial according (based - * in note v). Knuth suggests 'c==1' or 'c==a'. We elect to select 'c' + * in note v). Knuth suggests 'c==1' or 'c==a'. We elect to select 'c' * using the same process as we used to select 'a'. The choice is * 'immaterial' after all, and as long as: * - * gcd(c, m) == 1 (based on note v) - * gcd(c, 2^64) == 1 + * gcd(c, m) == 1 (based on note v) + * gcd(c, 2^64) == 1 * * the concerns are met. It can be shown that if we have: * - * gcd(a, c) == 1 + * gcd(a, c) == 1 * * then the adders and multipliers will be more independent. * * We will obtain the values 'a' and 'c for our generator from the - * Rand Book of Random Numbers. Because m=2^64 is 20 decimal digits long, - * we will search the Rand Book of Random Numbers 20 at a time. We will + * Rand Book of Random Numbers. Because m=2^64 is 20 decimal digits long, + * we will search the Rand Book of Random Numbers 20 at a time. We will * skip any of the 100 values that were used to initialize the subtractive 100 - * generators. The values obtained from the Rand Book of Random Numbers are: + * generators. The values obtained from the Rand Book of Random Numbers are: * - * a = 6316878969928993981 - * c = 1363042948800878693 + * a = 6316878969928993981 + * c = 1363042948800878693 * * As we stated before, we must map 0 ==> 0. The linear congruence * generator would normally map as follows: * - * 0 ==> 1363042948800878693 (0 ==> c) + * 0 ==> 1363042948800878693 (0 ==> c) * * We can determine which 0<=y 10239951819489363767 + * ((0-c) * minv(a,m)) % m ==> 10239951819489363767 * * and thus we find that the congruence generator would also normally map: * - * 10239951819489363767 ==> 0 + * 10239951819489363767 ==> 0 * * To overcome this, and preserve the 1-to-1 and onto map, we force: * - * 0 ==> 0 - * 10239951819489363767 ==> 1363042948800878693 + * 0 ==> 0 + * 10239951819489363767 ==> 1363042948800878693 * * To repeat, this function converts a values into a seed value. With the * except of 'seed == 0', every value is mapped into a unique seed value. - * This mapping need not be complex, random or secure. All we attempt + * This mapping need not be complex, random or secure. All we attempt * to do here is to allow humans who pick small or successive seed values * to obtain reasonably different sequences from the generators below. * - * NOTE: This is NOT a pseudo random number generator. This function is - * intended to be used internally by ss100rand() and sshufrand(). + * NOTE: This is NOT a pseudo random number generator. This function is + * intended to be used internally by ss100rand() and sshufrand(). */ S_FUNC void randreseed64(ZVALUE seed, ZVALUE *res) { - ZVALUE t; /* temp value */ - ZVALUE chunk; /* processed 64 bit chunk value */ - ZVALUE seed64; /* seed mod 2^64 */ - HALF *v64; /* 64 bit array of HALFs */ - long chunknum; /* 64 bit chunk number */ + ZVALUE t; /* temp value */ + ZVALUE chunk; /* processed 64 bit chunk value */ + ZVALUE seed64; /* seed mod 2^64 */ + HALF *v64; /* 64 bit array of HALFs */ + long chunknum; /* 64 bit chunk number */ - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - /* - * quickly return 0 if seed is 0 - */ - if (ziszero(seed) || seed.len <= 0) { - itoz(0, res); - return; - } + /* + * quickly return 0 if seed is 0 + */ + if (ziszero(seed) || seed.len <= 0) { + itoz(0, res); + return; + } - /* - * allocate result - */ - seed.sign = 0; /* use the value of seed */ - res->len = (int)(((seed.len+SHALFS-1) / SHALFS) * SHALFS); - res->v = alloc(res->len); - res->sign = 0; - memset(res->v, 0, res->len*sizeof(HALF)); /* default value is 0 */ + /* + * allocate result + */ + seed.sign = 0; /* use the value of seed */ + res->len = (int)(((seed.len+SHALFS-1) / SHALFS) * SHALFS); + res->v = alloc(res->len); + res->sign = 0; + memset(res->v, 0, res->len*sizeof(HALF)); /* default value is 0 */ - /* - * process 64 bit chunks until done - */ - chunknum = 0; - while (!zislezero(seed)) { + /* + * process 64 bit chunks until done + */ + chunknum = 0; + while (!zislezero(seed)) { - /* - * grab the lower 64 bits of seed - */ - if (zge64b(seed)) { - v64 = alloc(SHALFS); - memcpy(v64, seed.v, SHALFS*sizeof(HALF)); - seed64.v = v64; - seed64.len = SHALFS; - seed64.sign = 0; - } else { - zcopy(seed, &seed64); - } - zshiftr(seed, SBITS); - ztrim(&seed); - ztrim(&seed64); + /* + * grab the lower 64 bits of seed + */ + if (zge64b(seed)) { + v64 = alloc(SHALFS); + memcpy(v64, seed.v, SHALFS*sizeof(HALF)); + seed64.v = v64; + seed64.len = SHALFS; + seed64.sign = 0; + } else { + zcopy(seed, &seed64); + } + zshiftr(seed, SBITS); + ztrim(&seed); + ztrim(&seed64); - /* - * do nothing if chunk is zero - */ - if (ziszero(seed64)) { - ++chunknum; - zfree(seed64); - continue; - } + /* + * do nothing if chunk is zero + */ + if (ziszero(seed64)) { + ++chunknum; + zfree(seed64); + continue; + } - /* - * Compute the linear congruence generator map: - * - * X1 <-- (a*X0 + c) mod m - * - * in other words: - * - * chunk == (a_val*seed + c_val) mod 2^64 - */ - zmul(seed64, a_val, &t); - zfree(seed64); - zadd(t, c_val, &chunk); - zfree(t); + /* + * Compute the linear congruence generator map: + * + * X1 <-- (a*X0 + c) mod m + * + * in other words: + * + * chunk == (a_val*seed + c_val) mod 2^64 + */ + zmul(seed64, a_val, &t); + zfree(seed64); + zadd(t, c_val, &chunk); + zfree(t); - /* - * form chunk mod 2^64 - */ - if (chunk.len > (SB32)SHALFS) { - /* result is too large, reduce to 64 bits */ - v64 = alloc(SHALFS); - memcpy(v64, chunk.v, SHALFS*sizeof(HALF)); - free(chunk.v); - chunk.v = v64; - chunk.len = SHALFS; - ztrim(&chunk); - } + /* + * form chunk mod 2^64 + */ + if (chunk.len > (SB32)SHALFS) { + /* result is too large, reduce to 64 bits */ + v64 = alloc(SHALFS); + memcpy(v64, chunk.v, SHALFS*sizeof(HALF)); + free(chunk.v); + chunk.v = v64; + chunk.len = SHALFS; + ztrim(&chunk); + } - /* - * Normally, the above equation would map: - * - * f(0) == 1363042948800878693 - * f(10239951819489363767) == 0 - * - * However, we have already forced f(0) == 0. To preserve the - * 1-to-1 and onto map property, we force: - * - * f(10239951819489363767) ==> 1363042948800878693 - */ - if (ziszero(chunk)) { - /* load 1363042948800878693 instead of 0 */ - zcopy(c_val, &chunk); - memcpy(res->v+(chunknum*SHALFS), c_val.v, - c_val.len*sizeof(HALF)); + /* + * Normally, the above equation would map: + * + * f(0) == 1363042948800878693 + * f(10239951819489363767) == 0 + * + * However, we have already forced f(0) == 0. To preserve the + * 1-to-1 and onto map property, we force: + * + * f(10239951819489363767) ==> 1363042948800878693 + */ + if (ziszero(chunk)) { + /* load 1363042948800878693 instead of 0 */ + zcopy(c_val, &chunk); + memcpy(res->v+(chunknum*SHALFS), c_val.v, + c_val.len*sizeof(HALF)); - /* - * load the 64 bit chunk into the result - */ - } else { - memcpy(res->v+(chunknum*SHALFS), chunk.v, - chunk.len*sizeof(HALF)); - } - ++chunknum; - zfree(chunk); - } - ztrim(res); + /* + * load the 64 bit chunk into the result + */ + } else { + memcpy(res->v+(chunknum*SHALFS), chunk.v, + chunk.len*sizeof(HALF)); + } + ++chunknum; + zfree(chunk); + } + ztrim(res); } @@ -1160,232 +1160,232 @@ randreseed64(ZVALUE seed, ZVALUE *res) * zsrand - seed the s100 generator * * given: - * pseed - ptr to seed of the generator or NULL - * pmat100 - subtractive 100 state table or NULL + * pseed - ptr to seed of the generator or NULL + * pmat100 - subtractive 100 state table or NULL * * returns: - * previous s100 state + * previous s100 state */ RAND * zsrand(CONST ZVALUE *pseed, CONST MATRIX *pmat100) { - RAND *ret; /* previous s100 state */ - CONST VALUE *v; /* value from a passed matrix */ - ZVALUE zscram; /* scrambled 64 bit seed */ - ZVALUE ztmp; /* temp holding value for zscram */ - ZVALUE seed; /* to hold *pseed */ - FULL shufxor[SLEN]; /* zshufxor as an 64 bit array of FULLs */ - long indx; /* index to shuffle slots for seeding */ - int i; + RAND *ret; /* previous s100 state */ + CONST VALUE *v; /* value from a passed matrix */ + ZVALUE zscram; /* scrambled 64 bit seed */ + ZVALUE ztmp; /* temp holding value for zscram */ + ZVALUE seed; /* to hold *pseed */ + FULL shufxor[SLEN]; /* zshufxor as an 64 bit array of FULLs */ + long indx; /* index to shuffle slots for seeding */ + int i; - /* NOTE: It is OK for pseed == NULL */ - /* NOTE: It is OK for pmat100 == NULL */ + /* NOTE: It is OK for pseed == NULL */ + /* NOTE: It is OK for pmat100 == NULL */ - /* - * firewall - */ - if (pseed != NULL && zisneg(*pseed)) { - math_error("neg seeds for srand reserved for future use"); - not_reached(); - } + /* + * firewall + */ + if (pseed != NULL && zisneg(*pseed)) { + math_error("neg seeds for srand reserved for future use"); + not_reached(); + } - /* - * initialize state if first call - */ - if (!s100.seeded) { - s100 = init_s100; - } + /* + * initialize state if first call + */ + if (!s100.seeded) { + s100 = init_s100; + } - /* - * save the current state to return later - */ - ret = (RAND *)malloc(sizeof(RAND)); - if (ret == NULL) { - math_error("cannot allocate RAND state"); - not_reached(); - } - *ret = s100; + /* + * save the current state to return later + */ + ret = (RAND *)malloc(sizeof(RAND)); + if (ret == NULL) { + math_error("cannot allocate RAND state"); + not_reached(); + } + *ret = s100; - /* - * if call was srand(), just return current state - */ - if (pseed == NULL && pmat100 == NULL) { - return ret; - } + /* + * if call was srand(), just return current state + */ + if (pseed == NULL && pmat100 == NULL) { + return ret; + } - /* - * if call is srand(0), initialize and return quickly - */ - if (pmat100 == NULL && ziszero(*pseed)) { - s100 = init_s100; - return ret; - } + /* + * if call is srand(0), initialize and return quickly + */ + if (pmat100 == NULL && ziszero(*pseed)) { + s100 = init_s100; + return ret; + } - /* - * clear buffered bits, initialize pointers - */ - s100.seeded = 0; /* not seeded now */ - s100.j = INIT_J; - s100.k = INIT_K; - s100.bits = 0; - memset(s100.buffer, 0, sizeof(s100.buffer)); + /* + * clear buffered bits, initialize pointers + */ + s100.seeded = 0; /* not seeded now */ + s100.j = INIT_J; + s100.k = INIT_K; + s100.bits = 0; + memset(s100.buffer, 0, sizeof(s100.buffer)); - /* - * load subtractive table - * - * We will load the default subtractive table unless we are passed a - * matrix. If we are passed a matrix, we will load the first 100 - * values mod 2^64 instead. - */ - if (pmat100 == NULL) { - memcpy(s100.slot, def_subtract, sizeof(def_subtract)); - } else { + /* + * load subtractive table + * + * We will load the default subtractive table unless we are passed a + * matrix. If we are passed a matrix, we will load the first 100 + * values mod 2^64 instead. + */ + if (pmat100 == NULL) { + memcpy(s100.slot, def_subtract, sizeof(def_subtract)); + } else { - /* - * use the first 100 entries from the matrix arg - */ - if (pmat100->m_size < S100) { - math_error("matrix for srand has < 100 elements"); - not_reached(); - } - for (v=pmat100->m_table, i=0; i < S100; ++i, ++v) { + /* + * use the first 100 entries from the matrix arg + */ + if (pmat100->m_size < S100) { + math_error("matrix for srand has < 100 elements"); + not_reached(); + } + for (v=pmat100->m_table, i=0; i < S100; ++i, ++v) { - /* reject if not integer */ - if (v->v_type != V_NUM || qisfrac(v->v_num)) { - math_error("matrix for srand must contain ints"); - not_reached(); - } + /* reject if not integer */ + if (v->v_type != V_NUM || qisfrac(v->v_num)) { + math_error("matrix for srand must contain ints"); + not_reached(); + } - /* load table element from matrix element mod 2^64 */ - SLOAD(s100, i, v->v_num->num); - } - } + /* load table element from matrix element mod 2^64 */ + SLOAD(s100, i, v->v_num->num); + } + } - /* - * scramble the seed in 64 bit chunks - */ - if (pseed != NULL) { - seed.sign = pseed->sign; - seed.len = pseed->len; - seed.v = alloc(seed.len); - zcopyval(*pseed, seed); - randreseed64(seed, &zscram); - zfree(seed); - } + /* + * scramble the seed in 64 bit chunks + */ + if (pseed != NULL) { + seed.sign = pseed->sign; + seed.len = pseed->len; + seed.v = alloc(seed.len); + zcopyval(*pseed, seed); + randreseed64(seed, &zscram); + zfree(seed); + } - /* - * xor subtractive table with the rehashed lower 64 bits of seed - */ - if (pseed != NULL && !ziszero(zscram)) { + /* + * xor subtractive table with the rehashed lower 64 bits of seed + */ + if (pseed != NULL && !ziszero(zscram)) { - /* xor subtractive table with lower 64 bits of seed */ - SMOD64(shufxor, zscram); - for (i=0; i < S100; ++i) { - SXOR(s100, i, shufxor); - } - } + /* xor subtractive table with lower 64 bits of seed */ + SMOD64(shufxor, zscram); + for (i=0; i < S100; ++i) { + SXOR(s100, i, shufxor); + } + } - /* - * shuffle subtractive 100 table according to seed, if passed - */ - if (pseed != NULL && zge64b(zscram)) { + /* + * shuffle subtractive 100 table according to seed, if passed + */ + if (pseed != NULL && zge64b(zscram)) { - /* prepare the seed for subtractive slot shuffling */ - zshiftr(zscram, 64); - ztrim(&zscram); + /* prepare the seed for subtractive slot shuffling */ + zshiftr(zscram, 64); + ztrim(&zscram); - /* shuffle subtractive table */ - for (i=S100-1; i > 0 && !zislezero(zscram); --i) { + /* shuffle subtractive table */ + for (i=S100-1; i > 0 && !zislezero(zscram); --i) { - /* determine what we will swap with */ - indx = zdivi(zscram, i+1, &ztmp); - zfree(zscram); - zscram = ztmp; + /* determine what we will swap with */ + indx = zdivi(zscram, i+1, &ztmp); + zfree(zscram); + zscram = ztmp; - /* do nothing if swap with itself */ - if (indx == i) { - continue; - } + /* do nothing if swap with itself */ + if (indx == i) { + continue; + } - /* swap slot[i] with slot[indx] */ - SSWAP(s100, i, indx); - } - zfree(zscram); - } else if (pseed != NULL) { - zfree(zscram); - } + /* swap slot[i] with slot[indx] */ + SSWAP(s100, i, indx); + } + zfree(zscram); + } else if (pseed != NULL) { + zfree(zscram); + } - /* - * load the shuffle table - * - * We will generate SHUFCNT entries from the subtractive 100 slots - * and fill the shuffle table in consecutive order. - */ - for (i=0; i < SHUFCNT; ++i) { + /* + * load the shuffle table + * + * We will generate SHUFCNT entries from the subtractive 100 slots + * and fill the shuffle table in consecutive order. + */ + for (i=0; i < SHUFCNT; ++i) { - /* - * skip values if required - * - * See: - * Knuth's "The Art of Computer Programming - - * Seminumerical Algorithms", Vol 2, 3rd edition (1998), - * Section 3.6, page 188". - */ - if (s100.need_to_skip <= 0) { - int sk; + /* + * skip values if required + * + * See: + * Knuth's "The Art of Computer Programming - + * Seminumerical Algorithms", Vol 2, 3rd edition (1998), + * Section 3.6, page 188". + */ + if (s100.need_to_skip <= 0) { + int sk; - /* skip the require number of values */ - for (sk=0; sk < RAND_SKIP; ++sk) { + /* skip the require number of values */ + for (sk=0; sk < RAND_SKIP; ++sk) { - /* bump j and k */ - if (++s100.j >= S100) { - s100.j = 0; - } - if (++s100.k >= S100) { - s100.k = 0; - } + /* bump j and k */ + if (++s100.j >= S100) { + s100.j = 0; + } + if (++s100.k >= S100) { + s100.k = 0; + } - /* slot[k] -= slot[j] */ - SSUB(s100, s100.k, s100.j); + /* slot[k] -= slot[j] */ + SSUB(s100, s100.k, s100.j); - /* NOTE: don't shuffle, no shuffle table yet */ - } + /* NOTE: don't shuffle, no shuffle table yet */ + } - /* reset the skip count */ - s100.need_to_skip = RAND_CONSEQ_USE; - if (conf->calc_debug & CALCDBG_RAND) { - printf("rand: skipped %d states\n", RAND_SKIP); - } + /* reset the skip count */ + s100.need_to_skip = RAND_CONSEQ_USE; + if (conf->calc_debug & CALCDBG_RAND) { + printf("rand: skipped %d states\n", RAND_SKIP); + } - /* no skip, just decrement use counter */ - } else { - --s100.need_to_skip; - } + /* no skip, just decrement use counter */ + } else { + --s100.need_to_skip; + } - /* bump j and k */ - if (++s100.j >= S100) { - s100.j = 0; - } - if (++s100.k >= S100) { - s100.k = 0; - } + /* bump j and k */ + if (++s100.j >= S100) { + s100.j = 0; + } + if (++s100.k >= S100) { + s100.k = 0; + } - /* slot[k] -= slot[j] */ - SSUB(s100, s100.k, s100.j); + /* slot[k] -= slot[j] */ + SSUB(s100, s100.k, s100.j); - /* shuf[i] = slot[k] */ - SSHUF(s100, i, s100.k); - } + /* shuf[i] = slot[k] */ + SSHUF(s100, i, s100.k); + } - /* - * note that we are seeded - */ - s100.seeded = 1; + /* + * note that we are seeded + */ + s100.seeded = 1; - /* - * return the previous state - */ - return ret; + /* + * return the previous state + */ + return ret; } @@ -1393,43 +1393,43 @@ zsrand(CONST ZVALUE *pseed, CONST MATRIX *pmat100) * zsetrand - set the s100 generator state * * given: - * state - the state to copy + * state - the state to copy * * returns: - * previous s100 state + * previous s100 state */ RAND * zsetrand(CONST RAND *state) { - RAND *ret; /* previous s100 state */ + RAND *ret; /* previous s100 state */ - /* firewall */ - if (state == NULL) { - math_error("%s: state NULL", __func__); - not_reached(); - } + /* firewall */ + if (state == NULL) { + math_error("%s: state NULL", __func__); + not_reached(); + } - /* - * initialize state if first call - */ - if (!s100.seeded) { - s100 = init_s100; - } + /* + * initialize state if first call + */ + if (!s100.seeded) { + s100 = init_s100; + } - /* - * save the current state to return later - */ - ret = randcopy(&s100); + /* + * save the current state to return later + */ + ret = randcopy(&s100); - /* - * load the new state - */ - s100 = *state; + /* + * load the new state + */ + s100 = *state; - /* - * return the previous state - */ - return ret; + /* + * return the previous state + */ + return ret; } @@ -1449,171 +1449,171 @@ zsetrand(CONST RAND *state) * be transferred to the most significant bit in the destination. * * given: - * bitstr - most significant destination bit in a bit string - * src - low order FULL in a 64 bit slot - * count - number of bits to transfer (must be 0 < count <= 64) + * bitstr - most significant destination bit in a bit string + * src - low order FULL in a 64 bit slot + * count - number of bits to transfer (must be 0 < count <= 64) * * returns: - * number of bits transferred + * number of bits transferred */ S_FUNC int slotcp(BITSTR *bitstr, FULL *src, int count) { - HALF *dh; /* most significant HALF in dest */ - int dnxtbit; /* next bit beyond most significant in dh */ - int need; /* number of bits we need to transfer */ - int ret; /* bits transferred */ + HALF *dh; /* most significant HALF in dest */ + int dnxtbit; /* next bit beyond most significant in dh */ + int need; /* number of bits we need to transfer */ + int ret; /* bits transferred */ - /* firewall */ - if (src == NULL) { - math_error("%s: src NULL", __func__); - not_reached(); - } + /* firewall */ + if (src == NULL) { + math_error("%s: src NULL", __func__); + not_reached(); + } - /* - * determine how many bits we actually need to transfer - */ - dh = bitstr->loc; - dnxtbit = bitstr->bit+1; - count &= (SBITS-1); - need = (bitstr->len < count) ? bitstr->len : count; + /* + * determine how many bits we actually need to transfer + */ + dh = bitstr->loc; + dnxtbit = bitstr->bit+1; + count &= (SBITS-1); + need = (bitstr->len < count) ? bitstr->len : count; - /* - * prepare for the return - * - * Note the final bitstr location after we have moved the - * position down 'need' bits. - */ - bitstr->len -= need; - bitstr->loc -= need / BASEB; - bitstr->bit -= need % BASEB; - if (bitstr->bit < 0) { - --bitstr->loc; - bitstr->bit += BASEB; - } - ret = need; + /* + * prepare for the return + * + * Note the final bitstr location after we have moved the + * position down 'need' bits. + */ + bitstr->len -= need; + bitstr->loc -= need / BASEB; + bitstr->bit -= need % BASEB; + if (bitstr->bit < 0) { + --bitstr->loc; + bitstr->bit += BASEB; + } + ret = need; - /* - * deal with aligned copies quickly - */ - if (dnxtbit == BASEB) { - if (need == SBITS) { + /* + * deal with aligned copies quickly + */ + if (dnxtbit == BASEB) { + if (need == SBITS) { #if 2*FULL_BITS == SBITS - *dh-- = (HALF)(src[SLEN-1] >> BASEB); - *dh-- = (HALF)(src[SLEN-1]); + *dh-- = (HALF)(src[SLEN-1] >> BASEB); + *dh-- = (HALF)(src[SLEN-1]); #endif - *dh-- = (HALF)(src[0] >> BASEB); - *dh = (HALF)(src[0]); + *dh-- = (HALF)(src[0] >> BASEB); + *dh = (HALF)(src[0]); #if 2*FULL_BITS == SBITS - } else if (need > FULL_BITS+BASEB) { - *dh-- = (HALF)(src[SLEN-1] >> BASEB); - *dh-- = (HALF)(src[SLEN-1]); - *dh-- = (HALF)(src[0] >> BASEB); - *dh = ((HALF)src[0] & - highhalf[need-FULL_BITS-BASEB]); - } else if (need > FULL_BITS) { - *dh-- = (HALF)(src[SLEN-1] >> BASEB); - *dh-- = (HALF)(src[SLEN-1]); - *dh = ((HALF)(src[0] >> BASEB) & - highhalf[need-FULL_BITS]); + } else if (need > FULL_BITS+BASEB) { + *dh-- = (HALF)(src[SLEN-1] >> BASEB); + *dh-- = (HALF)(src[SLEN-1]); + *dh-- = (HALF)(src[0] >> BASEB); + *dh = ((HALF)src[0] & + highhalf[need-FULL_BITS-BASEB]); + } else if (need > FULL_BITS) { + *dh-- = (HALF)(src[SLEN-1] >> BASEB); + *dh-- = (HALF)(src[SLEN-1]); + *dh = ((HALF)(src[0] >> BASEB) & + highhalf[need-FULL_BITS]); #endif - } else if (need > BASEB) { - *dh-- = (HALF)(src[SLEN-1] >> BASEB); - *dh = ((HALF)(src[SLEN-1]) & highhalf[need-BASEB]); - } else { - *dh = ((HALF)(src[SLEN-1] >> BASEB) & highhalf[need]); - } - return ret; - } + } else if (need > BASEB) { + *dh-- = (HALF)(src[SLEN-1] >> BASEB); + *dh = ((HALF)(src[SLEN-1]) & highhalf[need-BASEB]); + } else { + *dh = ((HALF)(src[SLEN-1] >> BASEB) & highhalf[need]); + } + return ret; + } - /* - * load the most significant HALF - */ - if (need >= dnxtbit) { - /* fill up the most significant HALF */ - *dh-- |= (HALF)(src[SLEN-1] >> (FULL_BITS-dnxtbit)); - need -= dnxtbit; - } else if (need > 0) { - /* we exhaust our need before 1st half is filled */ - *dh |= (HALF)((src[SLEN-1] >> (FULL_BITS-need)) << - (dnxtbit-need)); - return ret; /* our need has been filled */ - } else { - return ret; /* our need has been filled */ - } + /* + * load the most significant HALF + */ + if (need >= dnxtbit) { + /* fill up the most significant HALF */ + *dh-- |= (HALF)(src[SLEN-1] >> (FULL_BITS-dnxtbit)); + need -= dnxtbit; + } else if (need > 0) { + /* we exhaust our need before 1st half is filled */ + *dh |= (HALF)((src[SLEN-1] >> (FULL_BITS-need)) << + (dnxtbit-need)); + return ret; /* our need has been filled */ + } else { + return ret; /* our need has been filled */ + } - /* - * load the 2nd most significant HALF - */ - if (need > BASEB) { - /* fill up the 2nd most significant HALF */ - *dh-- = (HALF)(src[SLEN-1] >> (BASEB-dnxtbit)); - need -= BASEB; - } else if (need > 0) { - /* we exhaust our need before 2nd half is filled */ - *dh |= ((HALF)(src[SLEN-1] >> (BASEB-dnxtbit)) & - highhalf[need]); - return ret; /* our need has been filled */ - } else { - return ret; /* our need has been filled */ - } + /* + * load the 2nd most significant HALF + */ + if (need > BASEB) { + /* fill up the 2nd most significant HALF */ + *dh-- = (HALF)(src[SLEN-1] >> (BASEB-dnxtbit)); + need -= BASEB; + } else if (need > 0) { + /* we exhaust our need before 2nd half is filled */ + *dh |= ((HALF)(src[SLEN-1] >> (BASEB-dnxtbit)) & + highhalf[need]); + return ret; /* our need has been filled */ + } else { + return ret; /* our need has been filled */ + } - /* - * load the 3rd most significant HALF - * - * At this point we know that our 3rd HALF will force us - * to cross into a second FULL for systems with 32 bit FULLs. - * We know this because the aligned case has been previously - * taken care of above. - * - * For systems that have 64 bit FULLs (and 32 bit HALFs) this - * is will be our least significant HALF. We also know that - * the need must be < BASEB. - */ + /* + * load the 3rd most significant HALF + * + * At this point we know that our 3rd HALF will force us + * to cross into a second FULL for systems with 32 bit FULLs. + * We know this because the aligned case has been previously + * taken care of above. + * + * For systems that have 64 bit FULLs (and 32 bit HALFs) this + * is will be our least significant HALF. We also know that + * the need must be < BASEB. + */ #if FULL_BITS == SBITS - *dh |= (((HALF)src[0] & highhalf[dnxtbit+need]) << dnxtbit); + *dh |= (((HALF)src[0] & highhalf[dnxtbit+need]) << dnxtbit); #else - if (need > BASEB) { - /* load the remaining bits from the most significant FULL */ - *dh-- = ((((HALF)src[SLEN-1] & lowhalf[BASEB-dnxtbit]) - << dnxtbit) | (HALF)(src[0] >> (FULL_BITS-dnxtbit))); - need -= BASEB; - } else if (need > 0) { - /* load the remaining bits from the most significant FULL */ - *dh-- |= (((((HALF)src[SLEN-1] & lowhalf[BASEB-dnxtbit]) - << dnxtbit) | (HALF)(src[0] >> (FULL_BITS-dnxtbit))) & - highhalf[need]); - return ret; /* our need has been filled */ - } else { - return ret; /* our need has been filled */ - } + if (need > BASEB) { + /* load the remaining bits from the most significant FULL */ + *dh-- = ((((HALF)src[SLEN-1] & lowhalf[BASEB-dnxtbit]) + << dnxtbit) | (HALF)(src[0] >> (FULL_BITS-dnxtbit))); + need -= BASEB; + } else if (need > 0) { + /* load the remaining bits from the most significant FULL */ + *dh-- |= (((((HALF)src[SLEN-1] & lowhalf[BASEB-dnxtbit]) + << dnxtbit) | (HALF)(src[0] >> (FULL_BITS-dnxtbit))) & + highhalf[need]); + return ret; /* our need has been filled */ + } else { + return ret; /* our need has been filled */ + } - /* - * load the 4th most significant HALF - * - * At this point, only 32 bit FULLs are operating. - */ - if (need > BASEB) { - /* fill up the 2nd most significant HALF */ - *dh-- = (HALF)(src[0] >> (BASEB-dnxtbit)); - /* no need TODO: need -= BASEB, because we are nearly done */ - } else if (need > 0) { - /* we exhaust our need before 2nd half is filled */ - *dh |= ((HALF)(src[0] >> (BASEB-dnxtbit)) & - highhalf[need]); - return ret; /* our need has been filled */ - } else { - return ret; /* our need has been filled */ - } + /* + * load the 4th most significant HALF + * + * At this point, only 32 bit FULLs are operating. + */ + if (need > BASEB) { + /* fill up the 2nd most significant HALF */ + *dh-- = (HALF)(src[0] >> (BASEB-dnxtbit)); + /* no need TODO: need -= BASEB, because we are nearly done */ + } else if (need > 0) { + /* we exhaust our need before 2nd half is filled */ + *dh |= ((HALF)(src[0] >> (BASEB-dnxtbit)) & + highhalf[need]); + return ret; /* our need has been filled */ + } else { + return ret; /* our need has been filled */ + } - /* - * load the 5th and least significant HALF - * - * At this point we know that the need will be satisfied. - */ - *dh |= (((HALF)src[0] & lowhalf[BASEB-dnxtbit]) << dnxtbit); + /* + * load the 5th and least significant HALF + * + * At this point we know that the need will be satisfied. + */ + *dh |= (((HALF)src[0] & lowhalf[BASEB-dnxtbit]) << dnxtbit); #endif - return ret; /* our need has been filled */ + return ret; /* our need has been filled */ } @@ -1626,96 +1626,96 @@ slotcp(BITSTR *bitstr, FULL *src, int count) * * The src slot is 64 bits long and is stored as an array of FULLs. * When FULL_BITS is 64 this array is 1 FULL, otherwise FULL_BITS - * is 32 bits and the array is 2 FULLs. The most significant bit + * is 32 bits and the array is 2 FULLs. The most significant bit * in the array (highest bit in the last FULL of the array) is to * be transferred to the most significant bit in the destination. * * given: - * bitstr - most significant destination bit in a bit string - * src - low order FULL in a 64 bit slot + * bitstr - most significant destination bit in a bit string + * src - low order FULL in a 64 bit slot * * returns: - * number of bits transferred + * number of bits transferred */ S_FUNC void slotcp64(BITSTR *bitstr, FULL *src) { - HALF *dh = bitstr->loc; /* most significant HALF in dest */ - int dnxtbit = bitstr->bit+1; /* next dh bit beyond most significant */ + HALF *dh = bitstr->loc; /* most significant HALF in dest */ + int dnxtbit = bitstr->bit+1; /* next dh bit beyond most significant */ - /* firewall */ - if (bitstr == NULL) { - math_error("%s: bitstr NULL", __func__); - not_reached(); - } - if (src == NULL) { - math_error("%s: src NULL", __func__); - not_reached(); - } + /* firewall */ + if (bitstr == NULL) { + math_error("%s: bitstr NULL", __func__); + not_reached(); + } + if (src == NULL) { + math_error("%s: src NULL", __func__); + not_reached(); + } - /* - * prepare for the return - * - * Since we are moving the point 64 bits down, we know that - * the bit location (bitstr->bit) will remain the same. - */ - bitstr->len -= SBITS; - bitstr->loc -= SBITS/BASEB; + /* + * prepare for the return + * + * Since we are moving the point 64 bits down, we know that + * the bit location (bitstr->bit) will remain the same. + */ + bitstr->len -= SBITS; + bitstr->loc -= SBITS/BASEB; - /* - * deal with aligned copies quickly - */ - if (dnxtbit == BASEB) { + /* + * deal with aligned copies quickly + */ + if (dnxtbit == BASEB) { #if 2*FULL_BITS == SBITS - *dh-- = (HALF)(src[SLEN-1] >> BASEB); - *dh-- = (HALF)(src[SLEN-1]); + *dh-- = (HALF)(src[SLEN-1] >> BASEB); + *dh-- = (HALF)(src[SLEN-1]); #endif - *dh-- = (HALF)(src[0] >> BASEB); - *dh = (HALF)(src[0]); - return; - } + *dh-- = (HALF)(src[0] >> BASEB); + *dh = (HALF)(src[0]); + return; + } - /* - * load the most significant HALF - */ - *dh-- |= (HALF)(src[SLEN-1] >> (FULL_BITS-dnxtbit)); + /* + * load the most significant HALF + */ + *dh-- |= (HALF)(src[SLEN-1] >> (FULL_BITS-dnxtbit)); - /* - * load the 2nd most significant HALF - */ - *dh-- = (HALF)(src[SLEN-1] >> (BASEB-dnxtbit)); + /* + * load the 2nd most significant HALF + */ + *dh-- = (HALF)(src[SLEN-1] >> (BASEB-dnxtbit)); - /* - * load the 3rd most significant HALF - * - * At this point we know that our 3rd HALF will force us - * to cross into a second FULL for systems with 32 bit FULLs. - * We know this because the aligned case has been previously - * taken care of above. - * - * For systems that have 64 bit FULLs (and 32 bit HALFs) this - * is will be our least significant HALF. - */ + /* + * load the 3rd most significant HALF + * + * At this point we know that our 3rd HALF will force us + * to cross into a second FULL for systems with 32 bit FULLs. + * We know this because the aligned case has been previously + * taken care of above. + * + * For systems that have 64 bit FULLs (and 32 bit HALFs) this + * is will be our least significant HALF. + */ #if FULL_BITS == SBITS - *dh |= (((HALF)src[0] & lowhalf[BASEB-dnxtbit]) << dnxtbit); + *dh |= (((HALF)src[0] & lowhalf[BASEB-dnxtbit]) << dnxtbit); #else - /* load the remaining bits from the most significant FULL */ - *dh-- = ((((HALF)src[SLEN-1] & lowhalf[BASEB-dnxtbit]) - << dnxtbit) | (HALF)(src[0] >> (FULL_BITS-dnxtbit))); + /* load the remaining bits from the most significant FULL */ + *dh-- = ((((HALF)src[SLEN-1] & lowhalf[BASEB-dnxtbit]) + << dnxtbit) | (HALF)(src[0] >> (FULL_BITS-dnxtbit))); - /* - * load the 4th most significant HALF - * - * At this point, only 32 bit FULLs are operating. - */ - *dh-- = (HALF)(src[0] >> (BASEB-dnxtbit)); + /* + * load the 4th most significant HALF + * + * At this point, only 32 bit FULLs are operating. + */ + *dh-- = (HALF)(src[0] >> (BASEB-dnxtbit)); - /* - * load the 5th and least significant HALF - * - * At this point we know that the need will be satisfied. - */ - *dh |= (((HALF)src[0] & lowhalf[BASEB-dnxtbit]) << dnxtbit); + /* + * load the 5th and least significant HALF + * + * At this point we know that the need will be satisfied. + */ + *dh |= (((HALF)src[0] & lowhalf[BASEB-dnxtbit]) << dnxtbit); #endif } @@ -1724,210 +1724,210 @@ slotcp64(BITSTR *bitstr, FULL *src) * zrandskip - skip s s100 bits * * given: - * count - number of bits to be skipped + * count - number of bits to be skipped */ void zrandskip(long cnt) { - int indx; /* shuffle entry index */ + int indx; /* shuffle entry index */ - /* - * initialize state if first call - */ - if (!s100.seeded) { - s100 = init_s100; - } + /* + * initialize state if first call + */ + if (!s100.seeded) { + s100 = init_s100; + } - /* - * skip required bits in the buffer - */ - if (s100.bits > 0 && s100.bits <= cnt) { + /* + * skip required bits in the buffer + */ + if (s100.bits > 0 && s100.bits <= cnt) { - /* just toss the buffer bits */ - cnt -= s100.bits; - s100.bits = 0; - memset(s100.buffer, 0, sizeof(s100.buffer)); + /* just toss the buffer bits */ + cnt -= s100.bits; + s100.bits = 0; + memset(s100.buffer, 0, sizeof(s100.buffer)); - } else if (s100.bits > 0 && s100.bits > cnt) { + } else if (s100.bits > 0 && s100.bits > cnt) { - /* buffer contains more bits than we need to toss */ + /* buffer contains more bits than we need to toss */ #if FULL_BITS == SBITS - s100.buffer[0] <<= cnt; + s100.buffer[0] <<= cnt; #else - if (cnt >= FULL_BITS) { - s100.buffer[SLEN-1] = (s100.buffer[0] << cnt); - s100.buffer[0] = 0; - } else { - s100.buffer[SLEN-1] = - ((s100.buffer[SLEN-1] << cnt) | - (s100.buffer[0] >> (FULL_BITS-cnt))); - s100.buffer[0] <<= cnt; - } + if (cnt >= FULL_BITS) { + s100.buffer[SLEN-1] = (s100.buffer[0] << cnt); + s100.buffer[0] = 0; + } else { + s100.buffer[SLEN-1] = + ((s100.buffer[SLEN-1] << cnt) | + (s100.buffer[0] >> (FULL_BITS-cnt))); + s100.buffer[0] <<= cnt; + } #endif - s100.bits -= cnt; - return; /* skip need satisfied */ - } + s100.bits -= cnt; + return; /* skip need satisfied */ + } - /* - * skip 64 bits at a time - */ - while (cnt >= SBITS) { + /* + * skip 64 bits at a time + */ + while (cnt >= SBITS) { - /* - * skip values if required - * - * NOTE: This skip loop is part of the algorithm, not part - * of the builtin function request. - * - * See: - * Knuth's "The Art of Computer Programming - - * Seminumerical Algorithms", Vol 2, 3rd edition (1998), - * Section 3.6, page 188". - */ - if (s100.need_to_skip <= 0) { - int sk; + /* + * skip values if required + * + * NOTE: This skip loop is part of the algorithm, not part + * of the builtin function request. + * + * See: + * Knuth's "The Art of Computer Programming - + * Seminumerical Algorithms", Vol 2, 3rd edition (1998), + * Section 3.6, page 188". + */ + if (s100.need_to_skip <= 0) { + int sk; - /* skip the require number of values */ - for (sk=0; sk < RAND_SKIP; ++sk) { - /* bump j and k */ - if (++s100.j >= S100) { - s100.j = 0; - } - if (++s100.k >= S100) { - s100.k = 0; - } + /* skip the require number of values */ + for (sk=0; sk < RAND_SKIP; ++sk) { + /* bump j and k */ + if (++s100.j >= S100) { + s100.j = 0; + } + if (++s100.k >= S100) { + s100.k = 0; + } - /* slot[k] -= slot[j] */ - SSUB(s100, s100.k, s100.j); + /* slot[k] -= slot[j] */ + SSUB(s100, s100.k, s100.j); - /* store s100.k into s100.slot[indx] */ - indx = SINDX(s100, s100.k); - SSHUF(s100, indx, s100.k); - } + /* store s100.k into s100.slot[indx] */ + indx = SINDX(s100, s100.k); + SSHUF(s100, indx, s100.k); + } - /* reset the skip count */ - s100.need_to_skip = RAND_CONSEQ_USE; - if (conf->calc_debug & CALCDBG_RAND) { - printf("rand: skipped %d states\n", RAND_SKIP); - } + /* reset the skip count */ + s100.need_to_skip = RAND_CONSEQ_USE; + if (conf->calc_debug & CALCDBG_RAND) { + printf("rand: skipped %d states\n", RAND_SKIP); + } - /* no skip, just decrement use counter */ - } else { - --s100.need_to_skip; - } + /* no skip, just decrement use counter */ + } else { + --s100.need_to_skip; + } - /* bump j and k */ - if (++s100.j >= S100) { - s100.j = 0; - } - if (++s100.k >= S100) { - s100.k = 0; - } + /* bump j and k */ + if (++s100.j >= S100) { + s100.j = 0; + } + if (++s100.k >= S100) { + s100.k = 0; + } - /* slot[k] -= slot[j] */ - SSUB(s100, s100.k, s100.j); + /* slot[k] -= slot[j] */ + SSUB(s100, s100.k, s100.j); - /* we will ignore the output value of s100.slot[indx] */ - indx = SINDX(s100, s100.k); - cnt -= SBITS; + /* we will ignore the output value of s100.slot[indx] */ + indx = SINDX(s100, s100.k); + cnt -= SBITS; - /* store s100.k into s100.slot[indx] */ - SSHUF(s100, indx, s100.k); - } + /* store s100.k into s100.slot[indx] */ + SSHUF(s100, indx, s100.k); + } - /* - * skip the final bits - */ - if (cnt > 0) { + /* + * skip the final bits + */ + if (cnt > 0) { - /* - * skip values if required - * - * NOTE: This skip loop is part of the algorithm, not part - * of the builtin function request. - * - * See: - * Knuth's "The Art of Computer Programming - - * Seminumerical Algorithms", Vol 2, 3rd edition (1998), - * Section 3.6, page 188". - */ - if (s100.need_to_skip <= 0) { - int sk; + /* + * skip values if required + * + * NOTE: This skip loop is part of the algorithm, not part + * of the builtin function request. + * + * See: + * Knuth's "The Art of Computer Programming - + * Seminumerical Algorithms", Vol 2, 3rd edition (1998), + * Section 3.6, page 188". + */ + if (s100.need_to_skip <= 0) { + int sk; - /* skip the require number of values */ - for (sk=0; sk < RAND_SKIP; ++sk) { + /* skip the require number of values */ + for (sk=0; sk < RAND_SKIP; ++sk) { - /* bump j and k */ - if (++s100.j >= S100) { - s100.j = 0; - } - if (++s100.k >= S100) { - s100.k = 0; - } + /* bump j and k */ + if (++s100.j >= S100) { + s100.j = 0; + } + if (++s100.k >= S100) { + s100.k = 0; + } - /* slot[k] -= slot[j] */ - SSUB(s100, s100.k, s100.j); + /* slot[k] -= slot[j] */ + SSUB(s100, s100.k, s100.j); - /* store s100.k into s100.slot[indx] */ - indx = SINDX(s100, s100.k); - SSHUF(s100, indx, s100.k); - } + /* store s100.k into s100.slot[indx] */ + indx = SINDX(s100, s100.k); + SSHUF(s100, indx, s100.k); + } - /* reset the skip count */ - s100.need_to_skip = RAND_CONSEQ_USE; - if (conf->calc_debug & CALCDBG_RAND) { - printf("rand: skipped %d states\n", RAND_SKIP); - } + /* reset the skip count */ + s100.need_to_skip = RAND_CONSEQ_USE; + if (conf->calc_debug & CALCDBG_RAND) { + printf("rand: skipped %d states\n", RAND_SKIP); + } - /* no skip, just decrement use counter */ - } else { - --s100.need_to_skip; - } + /* no skip, just decrement use counter */ + } else { + --s100.need_to_skip; + } - /* bump j and k */ - if (++s100.j >= S100) { - s100.j = 0; - } - if (++s100.k >= S100) { - s100.k = 0; - } + /* bump j and k */ + if (++s100.j >= S100) { + s100.j = 0; + } + if (++s100.k >= S100) { + s100.k = 0; + } - /* slot[k] -= slot[j] */ - SSUB(s100, s100.k, s100.j); + /* slot[k] -= slot[j] */ + SSUB(s100, s100.k, s100.j); - /* we will ignore the output value of s100.slot[indx] */ - indx = SINDX(s100, s100.k); + /* we will ignore the output value of s100.slot[indx] */ + indx = SINDX(s100, s100.k); - /* - * We know the buffer is empty, so fill it - * with any unused bits. Copy SBITS-trans bits - * from slot[indx] into buffer. - */ - s100.bits = (int)(SBITS-cnt); - memcpy(s100.buffer, &s100.shuf[indx*SLEN], - sizeof(s100.buffer)); + /* + * We know the buffer is empty, so fill it + * with any unused bits. Copy SBITS-trans bits + * from slot[indx] into buffer. + */ + s100.bits = (int)(SBITS-cnt); + memcpy(s100.buffer, &s100.shuf[indx*SLEN], + sizeof(s100.buffer)); - /* - * shift the buffer bits all the way up to - * the most significant bit - */ + /* + * shift the buffer bits all the way up to + * the most significant bit + */ #if FULL_BITS == SBITS - s100.buffer[0] <<= cnt; + s100.buffer[0] <<= cnt; #else - if (cnt >= FULL_BITS) { - s100.buffer[SLEN-1] = (s100.buffer[0] << cnt); - s100.buffer[0] = 0; - } else { - s100.buffer[SLEN-1] = - ((s100.buffer[SLEN-1] << cnt) | - (s100.buffer[0] >> (FULL_BITS-cnt))); - s100.buffer[0] <<= cnt; - } + if (cnt >= FULL_BITS) { + s100.buffer[SLEN-1] = (s100.buffer[0] << cnt); + s100.buffer[0] = 0; + } else { + s100.buffer[SLEN-1] = + ((s100.buffer[SLEN-1] << cnt) | + (s100.buffer[0] >> (FULL_BITS-cnt))); + s100.buffer[0] <<= cnt; + } #endif - /* store s100.k into s100.slot[indx] */ - SSHUF(s100, indx, s100.k); - } + /* store s100.k into s100.slot[indx] */ + SSHUF(s100, indx, s100.k); + } } @@ -1939,272 +1939,272 @@ zrandskip(long cnt) * least significant HALF. * * given: - * count - number of bits required - * res - where to place the random bits as ZVALUE + * count - number of bits required + * res - where to place the random bits as ZVALUE */ void zrand(long cnt, ZVALUE *res) { - BITSTR dest; /* destination bit string */ - int trans; /* bits transferred */ - int indx; /* shuffle entry index */ + BITSTR dest; /* destination bit string */ + int trans; /* bits transferred */ + int indx; /* shuffle entry index */ - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - /* - * firewall - */ - if (cnt <= 0) { - if (cnt == 0) { - /* zero length random number is always 0 */ - itoz(0, res); - return; - } else { - math_error("negative zrand bit count"); - not_reached(); - } + /* + * firewall + */ + if (cnt <= 0) { + if (cnt == 0) { + /* zero length random number is always 0 */ + itoz(0, res); + return; + } else { + math_error("negative zrand bit count"); + not_reached(); + } #if LONG_BITS > 32 - } else if (cnt > (1L<<31)) { - math_error("huge rand bit count in internal zrand function"); - not_reached(); + } else if (cnt > (1L<<31)) { + math_error("huge rand bit count in internal zrand function"); + not_reached(); #endif - } + } - /* - * initialize state if first call - */ - if (!s100.seeded) { - s100 = init_s100; - } + /* + * initialize state if first call + */ + if (!s100.seeded) { + s100 = init_s100; + } - /* - * allocate storage - */ - res->len = (LEN)((cnt+BASEB-1)/BASEB); - res->v = alloc((LEN)((cnt+BASEB-1)/BASEB)); + /* + * allocate storage + */ + res->len = (LEN)((cnt+BASEB-1)/BASEB); + res->v = alloc((LEN)((cnt+BASEB-1)/BASEB)); - /* - * dest bit string - */ - dest.len = (int)cnt; - dest.loc = res->v + (((cnt+BASEB-1)/BASEB)-1); - dest.bit = (int)((cnt-1) % BASEB); - memset(res->v, 0, (LEN)((cnt+BASEB-1)/BASEB)*sizeof(HALF)); + /* + * dest bit string + */ + dest.len = (int)cnt; + dest.loc = res->v + (((cnt+BASEB-1)/BASEB)-1); + dest.bit = (int)((cnt-1) % BASEB); + memset(res->v, 0, (LEN)((cnt+BASEB-1)/BASEB)*sizeof(HALF)); - /* - * load from buffer first - */ - if (s100.bits > 0) { + /* + * load from buffer first + */ + if (s100.bits > 0) { - /* - * We know there are only s100.bits in the buffer, so - * transfer as much as we can (treating it as a slot) - * and return the bit transfer count. - */ - trans = slotcp(&dest, s100.buffer, s100.bits); + /* + * We know there are only s100.bits in the buffer, so + * transfer as much as we can (treating it as a slot) + * and return the bit transfer count. + */ + trans = slotcp(&dest, s100.buffer, s100.bits); - /* - * If we need to keep bits in the buffer, - * shift the buffer bits all the way up to - * the most significant unused bit. - */ - if (trans < s100.bits) { + /* + * If we need to keep bits in the buffer, + * shift the buffer bits all the way up to + * the most significant unused bit. + */ + if (trans < s100.bits) { #if FULL_BITS == SBITS - s100.buffer[0] <<= trans; + s100.buffer[0] <<= trans; #else - if (trans >= FULL_BITS) { - s100.buffer[SLEN-1] = - (s100.buffer[0] << (trans-FULL_BITS)); - s100.buffer[0] = 0; - } else { - s100.buffer[SLEN-1] = - ((s100.buffer[SLEN-1] << trans) | - (s100.buffer[0] >> (FULL_BITS-trans))); - s100.buffer[0] <<= trans; - } + if (trans >= FULL_BITS) { + s100.buffer[SLEN-1] = + (s100.buffer[0] << (trans-FULL_BITS)); + s100.buffer[0] = 0; + } else { + s100.buffer[SLEN-1] = + ((s100.buffer[SLEN-1] << trans) | + (s100.buffer[0] >> (FULL_BITS-trans))); + s100.buffer[0] <<= trans; + } #endif - } - /* note that we have fewer bits in the buffer */ - s100.bits -= trans; - } + } + /* note that we have fewer bits in the buffer */ + s100.bits -= trans; + } - /* - * spin the generator until we need less than 64 bits - * - * The buffer did not contain enough bits, so we crank the - * s100 generator and load then 64 bits at a time. - */ - while (dest.len >= SBITS) { + /* + * spin the generator until we need less than 64 bits + * + * The buffer did not contain enough bits, so we crank the + * s100 generator and load then 64 bits at a time. + */ + while (dest.len >= SBITS) { - /* - * skip values if required - * - * See: - * Knuth's "The Art of Computer Programming - - * Seminumerical Algorithms", Vol 2, 3rd edition (1998), - * Section 3.6, page 188". - */ - if (s100.need_to_skip <= 0) { - int sk; + /* + * skip values if required + * + * See: + * Knuth's "The Art of Computer Programming - + * Seminumerical Algorithms", Vol 2, 3rd edition (1998), + * Section 3.6, page 188". + */ + if (s100.need_to_skip <= 0) { + int sk; - /* skip the require number of values */ - for (sk=0; sk < RAND_SKIP; ++sk) { + /* skip the require number of values */ + for (sk=0; sk < RAND_SKIP; ++sk) { - /* bump j and k */ - if (++s100.j >= S100) { - s100.j = 0; - } - if (++s100.k >= S100) { - s100.k = 0; - } + /* bump j and k */ + if (++s100.j >= S100) { + s100.j = 0; + } + if (++s100.k >= S100) { + s100.k = 0; + } - /* slot[k] -= slot[j] */ - SSUB(s100, s100.k, s100.j); + /* slot[k] -= slot[j] */ + SSUB(s100, s100.k, s100.j); - /* select slot index to output */ - indx = SINDX(s100, s100.k); + /* select slot index to output */ + indx = SINDX(s100, s100.k); - /* store s100.k into s100.slot[indx] */ - SSHUF(s100, indx, s100.k); - } + /* store s100.k into s100.slot[indx] */ + SSHUF(s100, indx, s100.k); + } - /* reset the skip count */ - s100.need_to_skip = RAND_CONSEQ_USE; - if (conf->calc_debug & CALCDBG_RAND) { - printf("rand: skipped %d states\n", RAND_SKIP); - } + /* reset the skip count */ + s100.need_to_skip = RAND_CONSEQ_USE; + if (conf->calc_debug & CALCDBG_RAND) { + printf("rand: skipped %d states\n", RAND_SKIP); + } - /* no skip, just decrement use counter */ - } else { - --s100.need_to_skip; - } + /* no skip, just decrement use counter */ + } else { + --s100.need_to_skip; + } - /* bump j and k */ - if (++s100.j >= S100) { - s100.j = 0; - } - if (++s100.k >= S100) { - s100.k = 0; - } + /* bump j and k */ + if (++s100.j >= S100) { + s100.j = 0; + } + if (++s100.k >= S100) { + s100.k = 0; + } - /* slot[k] -= slot[j] */ - SSUB(s100, s100.k, s100.j); + /* slot[k] -= slot[j] */ + SSUB(s100, s100.k, s100.j); - /* select slot index to output */ - indx = SINDX(s100, s100.k); + /* select slot index to output */ + indx = SINDX(s100, s100.k); - /* move up to 64 bits from slot[indx] to dest */ - slotcp64(&dest, &s100.shuf[indx*SLEN]); + /* move up to 64 bits from slot[indx] to dest */ + slotcp64(&dest, &s100.shuf[indx*SLEN]); - /* store s100.k into s100.slot[indx] */ - SSHUF(s100, indx, s100.k); - } + /* store s100.k into s100.slot[indx] */ + SSHUF(s100, indx, s100.k); + } - /* - * spin the generator one last time to fill out the remaining need - */ - if (dest.len > 0) { + /* + * spin the generator one last time to fill out the remaining need + */ + if (dest.len > 0) { - /* - * skip values if required - * - * See: - * Knuth's "The Art of Computer Programming - - * Seminumerical Algorithms", Vol 2, 3rd edition (1998), - * Section 3.6, page 188". - */ - if (s100.need_to_skip <= 0) { - int sk; + /* + * skip values if required + * + * See: + * Knuth's "The Art of Computer Programming - + * Seminumerical Algorithms", Vol 2, 3rd edition (1998), + * Section 3.6, page 188". + */ + if (s100.need_to_skip <= 0) { + int sk; - /* skip the require number of values */ - for (sk=0; sk < RAND_SKIP; ++sk) { - /* bump j and k */ - if (++s100.j >= S100) { - s100.j = 0; - } - if (++s100.k >= S100) { - s100.k = 0; - } + /* skip the require number of values */ + for (sk=0; sk < RAND_SKIP; ++sk) { + /* bump j and k */ + if (++s100.j >= S100) { + s100.j = 0; + } + if (++s100.k >= S100) { + s100.k = 0; + } - /* slot[k] -= slot[j] */ - SSUB(s100, s100.k, s100.j); + /* slot[k] -= slot[j] */ + SSUB(s100, s100.k, s100.j); - /* select slot index to output */ - indx = SINDX(s100, s100.k); + /* select slot index to output */ + indx = SINDX(s100, s100.k); - /* store s100.k into s100.slot[indx] */ - SSHUF(s100, indx, s100.k); - } + /* store s100.k into s100.slot[indx] */ + SSHUF(s100, indx, s100.k); + } - /* reset the skip count */ - s100.need_to_skip = RAND_CONSEQ_USE; - if (conf->calc_debug & CALCDBG_RAND) { - printf("rand: skipped %d states\n", RAND_SKIP); - } + /* reset the skip count */ + s100.need_to_skip = RAND_CONSEQ_USE; + if (conf->calc_debug & CALCDBG_RAND) { + printf("rand: skipped %d states\n", RAND_SKIP); + } - /* no skip, just decrement use counter */ - } else { - --s100.need_to_skip; - } + /* no skip, just decrement use counter */ + } else { + --s100.need_to_skip; + } - /* bump j and k */ - if (++s100.j >= S100) { - s100.j = 0; - } - if (++s100.k >= S100) { - s100.k = 0; - } + /* bump j and k */ + if (++s100.j >= S100) { + s100.j = 0; + } + if (++s100.k >= S100) { + s100.k = 0; + } - /* slot[k] -= slot[j] */ - SSUB(s100, s100.k, s100.j); + /* slot[k] -= slot[j] */ + SSUB(s100, s100.k, s100.j); - /* select slot index to output */ - indx = SINDX(s100, s100.k); + /* select slot index to output */ + indx = SINDX(s100, s100.k); - /* move up to 64 bits from slot[indx] to dest */ - trans = slotcp(&dest, &s100.shuf[indx*SLEN], dest.len); + /* move up to 64 bits from slot[indx] to dest */ + trans = slotcp(&dest, &s100.shuf[indx*SLEN], dest.len); - /* buffer up unused bits if we are done */ - if (trans != SBITS) { + /* buffer up unused bits if we are done */ + if (trans != SBITS) { - /* - * We know the buffer is empty, so fill it - * with any unused bits. Copy SBITS-trans bits - * from slot[indx] into buffer. - */ - s100.bits = SBITS-trans; - memcpy(s100.buffer, &s100.shuf[indx*SLEN], - sizeof(s100.buffer)); + /* + * We know the buffer is empty, so fill it + * with any unused bits. Copy SBITS-trans bits + * from slot[indx] into buffer. + */ + s100.bits = SBITS-trans; + memcpy(s100.buffer, &s100.shuf[indx*SLEN], + sizeof(s100.buffer)); - /* - * shift the buffer bits all the way up to - * the most significant bit - */ + /* + * shift the buffer bits all the way up to + * the most significant bit + */ #if FULL_BITS == SBITS - s100.buffer[0] <<= trans; + s100.buffer[0] <<= trans; #else - if (trans >= FULL_BITS) { - s100.buffer[SLEN-1] = - (s100.buffer[0] << (trans-FULL_BITS)); - s100.buffer[0] = 0; - } else { - s100.buffer[SLEN-1] = - ((s100.buffer[SLEN-1] << trans) | - (s100.buffer[0] >> (FULL_BITS-trans))); - s100.buffer[0] <<= trans; - } + if (trans >= FULL_BITS) { + s100.buffer[SLEN-1] = + (s100.buffer[0] << (trans-FULL_BITS)); + s100.buffer[0] = 0; + } else { + s100.buffer[SLEN-1] = + ((s100.buffer[SLEN-1] << trans) | + (s100.buffer[0] >> (FULL_BITS-trans))); + s100.buffer[0] <<= trans; + } #endif - } + } - /* store s100.k into s100.slot[indx] */ - SSHUF(s100, indx, s100.k); - } - res->sign = 0; - ztrim(res); + /* store s100.k into s100.slot[indx] */ + SSHUF(s100, indx, s100.k); + } + res->sign = 0; + ztrim(res); } @@ -2212,69 +2212,69 @@ zrand(long cnt, ZVALUE *res) * zrandrange - generate an s100 random value in the range [low, beyond) * * given: - * low - low value of range - * beyond - beyond end of range - * res - where to place the random bits as ZVALUE + * low - low value of range + * beyond - beyond end of range + * res - where to place the random bits as ZVALUE */ void zrandrange(CONST ZVALUE low, CONST ZVALUE beyond, ZVALUE *res) { - ZVALUE range; /* beyond-low */ - ZVALUE rval; /* random value [0, 2^bitlen) */ - ZVALUE rangem1; /* range - 1 */ - long bitlen; /* smallest power of 2 >= diff */ + ZVALUE range; /* beyond-low */ + ZVALUE rval; /* random value [0, 2^bitlen) */ + ZVALUE rangem1; /* range - 1 */ + long bitlen; /* smallest power of 2 >= diff */ - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - /* - * firewall - */ - if (zrel(low, beyond) >= 0) { - math_error("srand low range >= beyond range"); - not_reached(); - } + /* + * firewall + */ + if (zrel(low, beyond) >= 0) { + math_error("srand low range >= beyond range"); + not_reached(); + } - /* - * determine the size of the random number needed - */ - zsub(beyond, low, &range); - if (zisone(range)) { - zfree(range); - *res = low; - return; - } - zsub(range, _one_, &rangem1); - bitlen = 1+zhighbit(rangem1); - zfree(rangem1); + /* + * determine the size of the random number needed + */ + zsub(beyond, low, &range); + if (zisone(range)) { + zfree(range); + *res = low; + return; + } + zsub(range, _one_, &rangem1); + bitlen = 1+zhighbit(rangem1); + zfree(rangem1); - /* - * generate a random value between [0, diff) - * - * We will not fall into the trap of thinking that we can simply take - * a value mod 'range'. Consider the case where 'range' is '80' - * and we are given pseudo-random numbers [0,100). If we took them - * mod 80, then the numbers [0,20) would be produced more frequently - * because the numbers [81,100) mod 80 wrap back into [0,20). - */ - rval.v = NULL; - do { - if (rval.v != NULL) { - zfree(rval); - } - zrand(bitlen, &rval); - } while (zrel(rval, range) >= 0); + /* + * generate a random value between [0, diff) + * + * We will not fall into the trap of thinking that we can simply take + * a value mod 'range'. Consider the case where 'range' is '80' + * and we are given pseudo-random numbers [0,100). If we took them + * mod 80, then the numbers [0,20) would be produced more frequently + * because the numbers [81,100) mod 80 wrap back into [0,20). + */ + rval.v = NULL; + do { + if (rval.v != NULL) { + zfree(rval); + } + zrand(bitlen, &rval); + } while (zrel(rval, range) >= 0); - /* - * add in low value to produce the range [0+low, diff+low) - * which is the range [low, beyond) - */ - zadd(rval, low, res); - zfree(rval); - zfree(range); + /* + * add in low value to produce the range [0+low, diff+low) + * which is the range [low, beyond) + */ + zadd(rval, low, res); + zfree(rval); + zfree(range); } @@ -2282,29 +2282,29 @@ zrandrange(CONST ZVALUE low, CONST ZVALUE beyond, ZVALUE *res) * irand - generate an s100 random long in the range [0, s) * * given: - * s - limit of the range + * s - limit of the range * * returns: - * random long in the range [0, s) + * random long in the range [0, s) */ long irand(long s) { - ZVALUE z1, z2; - long res; + ZVALUE z1, z2; + long res; - if (s <= 0) { - math_error("Non-positive argument for irand()"); - not_reached(); - } - if (s == 1) - return 0; - itoz(s, &z1); - zrandrange(_zero_, z1, &z2); - res = ztoi(z2); - zfree(z1); - zfree(z2); - return res; + if (s <= 0) { + math_error("Non-positive argument for irand()"); + not_reached(); + } + if (s == 1) + return 0; + itoz(s, &z1); + zrandrange(_zero_, z1, &z2); + res = ztoi(z2); + zfree(z1); + zfree(z2); + return res; } @@ -2312,36 +2312,36 @@ irand(long s) * randcopy - make a copy of an s100 state * * given: - * state - the state to copy + * state - the state to copy * * returns: - * a malloced copy of the state + * a malloced copy of the state */ RAND * randcopy(CONST RAND *state) { - RAND *ret; /* return copy of state */ + RAND *ret; /* return copy of state */ - /* firewall */ - if (state == NULL) { - math_error("%s: state NULL", __func__); - not_reached(); - } + /* firewall */ + if (state == NULL) { + math_error("%s: state NULL", __func__); + not_reached(); + } - /* - * malloc state - */ - ret = (RAND *)malloc(sizeof(RAND)); - if (ret == NULL) { - math_error("can't allocate RAND state"); - not_reached(); - } - memcpy(ret, state, sizeof(RAND)); + /* + * malloc state + */ + ret = (RAND *)malloc(sizeof(RAND)); + if (ret == NULL) { + math_error("can't allocate RAND state"); + not_reached(); + } + memcpy(ret, state, sizeof(RAND)); - /* - * return copy - */ - return ret; + /* + * return copy + */ + return ret; } @@ -2349,13 +2349,13 @@ randcopy(CONST RAND *state) * randfree - free an s100 state * * given: - * state - the state to free + * state - the state to free */ void randfree(RAND *state) { - /* free it */ - free(state); + /* free it */ + free(state); } @@ -2363,43 +2363,43 @@ randfree(RAND *state) * randcmp - compare two s100 states * * given: - * s1 - first state to compare - * s2 - second state to compare + * s1 - first state to compare + * s2 - second state to compare * * return: - * true if states differ + * true if states differ */ bool randcmp(CONST RAND *s1, CONST RAND *s2) { - /* firewall */ - if (s1 == NULL) { - math_error("%s: s1 NULL", __func__); - not_reached(); - } - if (s2 == NULL) { - math_error("%s: s2 NULL", __func__); - not_reached(); - } + /* firewall */ + if (s1 == NULL) { + math_error("%s: s1 NULL", __func__); + not_reached(); + } + if (s2 == NULL) { + math_error("%s: s2 NULL", __func__); + not_reached(); + } - /* - * assume uninitialized state == the default seeded state - */ - if (!s1->seeded) { - if (!s2->seeded) { - /* uninitialized == uninitialized */ - return false; - } else { - /* uninitialized only equals default state */ - return randcmp(s2, &init_s100); - } - } else if (!s2->seeded) { - /* uninitialized only equals default state */ - return randcmp(s1, &init_s100); - } + /* + * assume uninitialized state == the default seeded state + */ + if (!s1->seeded) { + if (!s2->seeded) { + /* uninitialized == uninitialized */ + return false; + } else { + /* uninitialized only equals default state */ + return randcmp(s2, &init_s100); + } + } else if (!s2->seeded) { + /* uninitialized only equals default state */ + return randcmp(s1, &init_s100); + } - /* compare states */ - return (bool)(memcmp(s1, s2, sizeof(RAND)) != 0); + /* compare states */ + return (bool)(memcmp(s1, s2, sizeof(RAND)) != 0); } @@ -2407,13 +2407,13 @@ randcmp(CONST RAND *s1, CONST RAND *s2) * randprint - print an s100 state * * given: - * state - state to print - * flags - print flags passed from printvalue() in value.c + * state - state to print + * flags - print flags passed from printvalue() in value.c */ /*ARGSUSED*/ void randprint(CONST RAND *UNUSED(state), int UNUSED(flags)) { - /* NOTE: It is OK for state == NULL */ - math_str("RAND state"); + /* NOTE: It is OK for state == NULL */ + math_str("RAND state"); } diff --git a/zrand.h b/zrand.h index 180e6c2..aa1f7f1 100644 --- a/zrand.h +++ b/zrand.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1995/01/07 09:45:26 - * File existed as early as: 1994 + * Under source code control: 1995/01/07 09:45:26 + * File existed as early as: 1994 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -33,7 +33,7 @@ #define INCLUDE_ZRAND_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "value.h" # include "have_const.h" #else @@ -46,145 +46,145 @@ * s100 generator defines * * NOTE: SBITS must be a power of two to make the (&= (SBITS-1)) - * in slotcp() to work. + * in slotcp() to work. */ -#define SBITS (64) /* size of subtractive or shuffle entry in bits */ +#define SBITS (64) /* size of subtractive or shuffle entry in bits */ #define SBYTES (SBITS/8) /* size of subtractive or shuffle entry in bytes */ -#define SHALFS (SBYTES/sizeof(HALF)) /* size in HALFs */ +#define SHALFS (SBYTES/sizeof(HALF)) /* size in HALFs */ /* * seed defines */ -#define SEEDXORBITS 64 /* low bits of s100 seed devoted to xor */ +#define SEEDXORBITS 64 /* low bits of s100 seed devoted to xor */ /* * shuffle table defines */ -#define SHUFPOW 8 /* power of 2 size of the shuffle table */ -#define SHUFCNT (1 << SHUFPOW) /* size of shuffle table */ -#define SHUFLEN (SLEN*SHUFCNT) /* length of shuffle table in FULLs */ -#define SHUFMASK (SHUFLEN-1) /* mask for shuffle table entry selection */ +#define SHUFPOW 8 /* power of 2 size of the shuffle table */ +#define SHUFCNT (1 << SHUFPOW) /* size of shuffle table */ +#define SHUFLEN (SLEN*SHUFCNT) /* length of shuffle table in FULLs */ +#define SHUFMASK (SHUFLEN-1) /* mask for shuffle table entry selection */ /* * subtractive 100 constants */ -#define S100 100 /* slots in an subtractive 100 table */ -#define INIT_J 36 /* initial first walking table index */ -#define INIT_K 99 /* initial second walking table index */ +#define S100 100 /* slots in an subtractive 100 table */ +#define INIT_J 36 /* initial first walking table index */ +#define INIT_K 99 /* initial second walking table index */ /* * subtractive 100 table defines * - * SLEN - length in FULLs of an subtractive 100 slot + * SLEN - length in FULLs of an subtractive 100 slot * * SLOAD(s,i,z) - load table slot i from subtractive 100 state s with zvalue z - * s: type RAND - * i: type int, s.slot[i] slot index - * z: type ZVALUE, what to load into s.slot[i] + * s: type RAND + * i: type int, s.slot[i] slot index + * z: type ZVALUE, what to load into s.slot[i] * - * SSUB(s,k,j) - slot[k] -= slot[j] - * s: type RAND - * k: type int, s.slot[k] slot index, what to gets changed - * j: type int, s.slot[j] slot index, what to add to s.slot[k] - * (may use local variable tmp) + * SSUB(s,k,j) - slot[k] -= slot[j] + * s: type RAND + * k: type int, s.slot[k] slot index, what to gets changed + * j: type int, s.slot[j] slot index, what to add to s.slot[k] + * (may use local variable tmp) * - * SINDX(s,k) - select the shuffle table entry from slot[k] (uses top bits) - * s: type RAND - * k: type int, s.slot[k] slot index, selects shuffle entry - * result type int, refers to s.shuf[SINDX(s,k)] + * SINDX(s,k) - select the shuffle table entry from slot[k] (uses top bits) + * s: type RAND + * k: type int, s.slot[k] slot index, selects shuffle entry + * result type int, refers to s.shuf[SINDX(s,k)] * * SBUFFER(s,t) - load s100 buffer with t - * s: type RAND - * t: type int, s.shuf[t] entry index, replace buffer with it + * s: type RAND + * t: type int, s.shuf[t] entry index, replace buffer with it * * SSHUF(s,t,k) - save slot[k] into shuffle entry t - * s: type RAND - * t: type int, s.shuf[t] entry index, what gets changed - * k: type int, s.slot[k] slot index, load into s.shuf[t] + * s: type RAND + * t: type int, s.shuf[t] entry index, what gets changed + * k: type int, s.slot[k] slot index, load into s.shuf[t] * * SSWAP(s,j,k) - swap slot[j] with slot[k] - * s: type RAND - * j: type int, s.slot[j] slot index, goes into s.slot[k] - * k: type int, s.slot[k] slot index, goes into s.slot[j] - * (uses local variable tmp) + * s: type RAND + * j: type int, s.slot[j] slot index, goes into s.slot[k] + * k: type int, s.slot[k] slot index, goes into s.slot[j] + * (uses local variable tmp) * - * SMOD64(t,z) - t = seed z mod 2^64 - * t: type FULL*, array of FULLs that get z mod 2^64 - * z: type ZVALUE, what gets (mod 2^64) placed into t + * SMOD64(t,z) - t = seed z mod 2^64 + * t: type FULL*, array of FULLs that get z mod 2^64 + * z: type ZVALUE, what gets (mod 2^64) placed into t * - * SOXR(s,i,v) - xor slot[i] with lower 64 bits of slot value v - * s: type RAND - * i: type int, s.slot[i] slot index, what gets xored - * v: type FULL*, 64 bit value to xor into s.slot[i] + * SOXR(s,i,v) - xor slot[i] with lower 64 bits of slot value v + * s: type RAND + * i: type int, s.slot[i] slot index, what gets xored + * v: type FULL*, 64 bit value to xor into s.slot[i] * - * SCNT - length of an subtractive 100 table in FULLs + * SCNT - length of an subtractive 100 table in FULLs */ #if FULL_BITS == SBITS -# define SLEN 1 /* a 64 bit slot can be held in a FULL */ +# define SLEN 1 /* a 64 bit slot can be held in a FULL */ #define SLOAD(s,i,z) ((s).slot[i] = ztofull(z)) #define SSUB(s,k,j) ((s).slot[k] -= (s).slot[j]) #define SINDX(s,k) ((int)((s).slot[k] >> (FULL_BITS - SHUFPOW))) #define SBUFFER(s,t) {(s).buffer[0] = ((s).shuf[t] & BASE1); \ - (s).buffer[1] = ((s).shuf[t] >> BASEB); \ - } + (s).buffer[1] = ((s).shuf[t] >> BASEB); \ + } #define SSHUF(s,t,k) ((s).shuf[t] = (s).slot[k]) #define SSWAP(s,j,k) {FULL tmp = (s).slot[j]; \ - (s).slot[j] = (s).slot[k]; \ - (s).slot[k] = tmp; \ - } + (s).slot[j] = (s).slot[k]; \ + (s).slot[k] = tmp; \ + } #define SMOD64(t,z) ((t)[0] = ztofull(z)) #define SXOR(s,i,v) ((s).slot[i] ^= (v)[0]) #elif 2*FULL_BITS == SBITS -# define SLEN 2 /* a 64 bit slot needs 2 FULLs */ +# define SLEN 2 /* a 64 bit slot needs 2 FULLs */ #define SLOAD(s,i,z) {(s).slot[(i)<<1] = ztofull(z); \ - (s).slot[1+((i)<<1)] = \ - (((z).len <= 2) ? (FULL)0 : \ - (((z).len == 3) ? (FULL)((z).v[2]) : \ - ((FULL)((z).v[2]) + ((FULL)((z).v[3]) << BASEB)))); \ - } + (s).slot[1+((i)<<1)] = \ + (((z).len <= 2) ? (FULL)0 : \ + (((z).len == 3) ? (FULL)((z).v[2]) : \ + ((FULL)((z).v[2]) + ((FULL)((z).v[3]) << BASEB)))); \ + } #define SSUB(s,k,j) {FULL tmp = (s).slot[(k)<<1]; \ - (s).slot[(k)<<1] -= (s).slot[(j)<<1]; \ - (s).slot[1+((k)<<1)] -= ((tmp <= (s).slot[(k)<<1]) ? \ - (s).slot[1+((j)<<1)] : \ - (s).slot[1+((j)<<1)] + 1); \ - } + (s).slot[(k)<<1] -= (s).slot[(j)<<1]; \ + (s).slot[1+((k)<<1)] -= ((tmp <= (s).slot[(k)<<1]) ? \ + (s).slot[1+((j)<<1)] : \ + (s).slot[1+((j)<<1)] + 1); \ + } #define SINDX(s,k) ((int)((s).slot[1+((k)<<1)] >> (FULL_BITS - SHUFPOW))) #define SBUFFER(s,t) {(s).buffer[0] = ((s).shuf[(t)<<1] & BASE1); \ - (s).buffer[1] = ((s).shuf[(t)<<1] >> BASEB); \ - (s).buffer[2] = ((s).shuf[1+((t)<<1)] & BASE1); \ - (s).buffer[3] = ((s).shuf[1+((t)<<1)] >> BASEB); \ - } + (s).buffer[1] = ((s).shuf[(t)<<1] >> BASEB); \ + (s).buffer[2] = ((s).shuf[1+((t)<<1)] & BASE1); \ + (s).buffer[3] = ((s).shuf[1+((t)<<1)] >> BASEB); \ + } #define SSHUF(s,t,k) {(s).shuf[(t)<<1] = (s).slot[(k)<<1]; \ - (s).shuf[1+((t)<<1)] = (s).slot[1+((k)<<1)]; \ - } + (s).shuf[1+((t)<<1)] = (s).slot[1+((k)<<1)]; \ + } #define SSWAP(s,j,k) {FULL tmp = (s).slot[(j)<<1]; \ - (s).slot[(j)<<1] = (s).slot[(k)<<1]; \ - (s).slot[(k)<<1] = tmp; \ - tmp = (s).slot[1+((j)<<1)]; \ - (s).slot[1+((j)<<1)] = (s).slot[1+((k)<<1)]; \ - (s).slot[1+((k)<<1)] = tmp; \ - } + (s).slot[(j)<<1] = (s).slot[(k)<<1]; \ + (s).slot[(k)<<1] = tmp; \ + tmp = (s).slot[1+((j)<<1)]; \ + (s).slot[1+((j)<<1)] = (s).slot[1+((k)<<1)]; \ + (s).slot[1+((k)<<1)] = tmp; \ + } #define SMOD64(t,z) {(t)[0] = ztofull(z); \ - (t)[1] = (((z).len <= 2) ? (FULL)0 : \ - (((z).len == 3) ? (FULL)((z).v[2]) : \ - ((FULL)((z).v[2]) + ((FULL)((z).v[3]) << BASEB)))); \ - } + (t)[1] = (((z).len <= 2) ? (FULL)0 : \ + (((z).len == 3) ? (FULL)((z).v[2]) : \ + ((FULL)((z).v[2]) + ((FULL)((z).v[3]) << BASEB)))); \ + } #define SXOR(s,i,v) {(s).slot[(i)<<1] ^= (v)[0]; \ - (s).slot[1+((i)<<1)] ^= (v)[1]; \ - } + (s).slot[1+((i)<<1)] ^= (v)[1]; \ + } #else - /\../\ FULL_BITS must be 32 or 64 /\../\ !!! + /\../\ FULL_BITS must be 32 or 64 /\../\ !!! #endif -#define SCNT (SLEN*S100) /* length of subtractive 100 table in FULLs */ +#define SCNT (SLEN*S100) /* length of subtractive 100 table in FULLs */ -#define RAND_CONSEQ_USE (100) /* use this many before skipping */ +#define RAND_CONSEQ_USE (100) /* use this many before skipping */ #define RAND_SKIP (1009-RAND_CONSEQ_USE) /* skip this many after use */ @@ -192,14 +192,14 @@ * s100 generator state */ struct rand { - int seeded; /* 1 => state has been seeded */ - int bits; /* buffer bit count */ - FULL buffer[SLEN]; /* unused random bits from last call */ - int j; /* first walking table index */ - int k; /* second walking table index */ - int need_to_skip; /* 1 => skip the next 909 values */ - FULL slot[SCNT]; /* subtractive 100 table */ - FULL shuf[SHUFLEN]; /* shuffle table entries */ + int seeded; /* 1 => state has been seeded */ + int bits; /* buffer bit count */ + FULL buffer[SLEN]; /* unused random bits from last call */ + int j; /* first walking table index */ + int k; /* second walking table index */ + int need_to_skip; /* 1 => skip the next 909 values */ + FULL slot[SCNT]; /* subtractive 100 table */ + FULL shuf[SHUFLEN]; /* shuffle table entries */ }; diff --git a/zrandom.c b/zrandom.c index 8a558a4..bc19087 100644 --- a/zrandom.c +++ b/zrandom.c @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/02/15 04:01:56 - * File existed as early as: 1997 + * Under source code control: 1997/02/15 04:01:56 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* @@ -29,57 +29,57 @@ * * This module contains a Blum-Blum-Shub generator: * - * To shorten the name, We refer to this generator as the Blum generator. + * To shorten the name, We refer to this generator as the Blum generator. * - * This generator is described in the papers: + * This generator is described in the papers: * - * Blum, Blum, and Shub, "Comparison of Two Pseudorandom Number - * Generators", in Chaum, D. et. al., "Advances in Cryptology: - * Proceedings Crypto 82", pp. 61-79, Plenum Press, 1983. + * Blum, Blum, and Shub, "Comparison of Two Pseudorandom Number + * Generators", in Chaum, D. et. al., "Advances in Cryptology: + * Proceedings Crypto 82", pp. 61-79, Plenum Press, 1983. * - * Blum, Blum, and Shub, "A Simple Unpredictable Pseudo-Random - * Number Generator", SIAM Journal of Computing, v. 15, n. 2, - * 1986, pp. 364-383. + * Blum, Blum, and Shub, "A Simple Unpredictable Pseudo-Random + * Number Generator", SIAM Journal of Computing, v. 15, n. 2, + * 1986, pp. 364-383. * - * U. V. Vazirani and V. V. Vazirani, "Trapdoor Pseudo-Random - * Number Generators with Applications to Protocol Design", - * Proceedings of the 24th IEEE Symposium on the Foundations - * of Computer Science, 1983, pp. 23-30. + * U. V. Vazirani and V. V. Vazirani, "Trapdoor Pseudo-Random + * Number Generators with Applications to Protocol Design", + * Proceedings of the 24th IEEE Symposium on the Foundations + * of Computer Science, 1983, pp. 23-30. * - * U. V. Vazirani and V. V. Vazirani, "Efficient and Secure - * Pseudo-Random Number Generation", Proceedings of the 24th - * IEEE Symposium on the Foundations of Computer Science, - * 1984, pp. 458-463. + * U. V. Vazirani and V. V. Vazirani, "Efficient and Secure + * Pseudo-Random Number Generation", Proceedings of the 24th + * IEEE Symposium on the Foundations of Computer Science, + * 1984, pp. 458-463. * - * U. V. Vazirani and V. V. Vazirani, "Efficient and Secure - * Pseudo-Random Number Generation", Advances in Cryptology - - * Proceedings of CRYPTO '84, Berlin: Springer-Verlag, 1985, - * pp. 193-202. + * U. V. Vazirani and V. V. Vazirani, "Efficient and Secure + * Pseudo-Random Number Generation", Advances in Cryptology - + * Proceedings of CRYPTO '84, Berlin: Springer-Verlag, 1985, + * pp. 193-202. * - * Sciences 28, pp. 270-299. + * Sciences 28, pp. 270-299. * - * Bruce Schneier, "Applied Cryptography", John Wiley & Sons, - * 1st edition (1994), pp 365-366. + * Bruce Schneier, "Applied Cryptography", John Wiley & Sons, + * 1st edition (1994), pp 365-366. * - * This generator is considered 'strong' in that it passes all - * polynomial-time statistical tests. The sequences produced - * are random in an absolutely precise way. There is absolutely - * no better way to predict the sequence than by tossing a coin - * (as with TRULY random numbers) EVEN IF YOU KNOW THE MODULUS! - * Furthermore, having a large chunk of output from the sequence - * does not help. The BITS THAT FOLLOW OR PRECEDE A SEQUENCE - * ARE UNPREDICTABLE! + * This generator is considered 'strong' in that it passes all + * polynomial-time statistical tests. The sequences produced + * are random in an absolutely precise way. There is absolutely + * no better way to predict the sequence than by tossing a coin + * (as with TRULY random numbers) EVEN IF YOU KNOW THE MODULUS! + * Furthermore, having a large chunk of output from the sequence + * does not help. The BITS THAT FOLLOW OR PRECEDE A SEQUENCE + * ARE UNPREDICTABLE! * - * Of course the Blum modulus should have a long period. The default - * Blum modulus as well as the compiled in Blum moduli have very long - * periods. When using your own Blum modulus, a little care is needed - * to avoid generators with very short periods. (see below) + * Of course the Blum modulus should have a long period. The default + * Blum modulus as well as the compiled in Blum moduli have very long + * periods. When using your own Blum modulus, a little care is needed + * to avoid generators with very short periods. (see below) * - * To compromise the generator, an adversary must either factor the - * modulus or perform an exhaustive search just to determine the next - * (or previous) bit. If we make the modulus hard to factor - * (such as the product of two large well chosen primes) breaking - * the sequence could be intractable for todays computers and methods. + * To compromise the generator, an adversary must either factor the + * modulus or perform an exhaustive search just to determine the next + * (or previous) bit. If we make the modulus hard to factor + * (such as the product of two large well chosen primes) breaking + * the sequence could be intractable for todays computers and methods. * ****************************************************************************** * @@ -87,27 +87,27 @@ * * The goals of this package are: * - * All magic numbers are explained: + * All magic numbers are explained: * - * I distrust systems with constants (magic numbers) and tables - * that have no justification. I believe that I have - * done my best to justify all of the magic numbers used. + * I distrust systems with constants (magic numbers) and tables + * that have no justification. I believe that I have + * done my best to justify all of the magic numbers used. * - * Full documentation: + * Full documentation: * - * You have this source file, plus background publications, - * what more could you ask? + * You have this source file, plus background publications, + * what more could you ask? * - * Large selection of seeds: + * Large selection of seeds: * - * Seeds are not limited to a small number of bits. A seed - * may be of any size. + * Seeds are not limited to a small number of bits. A seed + * may be of any size. * - * The strength of the generators may be tuned to meet the need: + * The strength of the generators may be tuned to meet the need: * - * By using the appropriate seed and other arguments, one may - * increase the strength of the generator to suit the need of - * the application. One does not have just a few levels. + * By using the appropriate seed and other arguments, one may + * increase the strength of the generator to suit the need of + * the application. One does not have just a few levels. * * Even though I have done my best to implement a good system, you still * must use these routines your own risk. @@ -121,7 +121,7 @@ * The Blum generator is the best generator in this package. It * produces a cryptographically strong pseudo-random bit sequence. * Internally, a fixed number of bits are generated after each - * generator iteration. Any unused bits are saved for the next call + * generator iteration. Any unused bits are saved for the next call * to the generator. The Blum generator is not too slow, though * seeding the generator via srandom(seed,plen,qlen) can be slow. * Shortcuts and pre-defined generators have been provided for this reason. @@ -129,41 +129,41 @@ * * The Blum generator as the following calc interfaces: * - * random(min, beyond) (where min < beyond) + * random(min, beyond) (where min < beyond) * - * Print a Blum generator random value over interval [min,beyond). + * Print a Blum generator random value over interval [min,beyond). * - * This form returns integers of the form: + * This form returns integers of the form: * - * min <= value < beyond + * min <= value < beyond * * random() * - * Same as random(0, 2^64). Print 64 bits. + * Same as random(0, 2^64). Print 64 bits. * - * This form returns integers of the form: + * This form returns integers of the form: * - * 0 <= value < 2^64 + * 0 <= value < 2^64 * - * random(lim) (where lim > 0) + * random(lim) (where lim > 0) * - * Same as random(0, lim). + * Same as random(0, lim). * - * This form returns integers of the form: + * This form returns integers of the form: * - * 0 <= value < lim + * 0 <= value < lim * - * randombit(x) (where x > 0) + * randombit(x) (where x > 0) * - * Same as random(0, 2^x). Print x bits. + * Same as random(0, 2^x). Print x bits. * - * This form returns integers of the form: + * This form returns integers of the form: * - * 0 <= value < 2^x + * 0 <= value < 2^x * - * randombit(neg) (where neg < 0) + * randombit(neg) (where neg < 0) * - * Skip neg random bits and return the bit skip count. + * Skip neg random bits and return the bit skip count. */ /* @@ -176,28 +176,28 @@ * * Using a seed of '0' will reload generators with their initial states. * - * srandom(0) restore Blum generator to the initial state + * srandom(0) restore Blum generator to the initial state * * The above single arg calls are fairly fast. * * The call: * - * srandom(seed, newn) + * srandom(seed, newn) * * is fast when the config value "srandom" is 0, 1 or 2. * * Optimal seed range for the Blum generator: * - * There is no limit on the size of a seed. On the other hand, - * in most cases the seed is taken modulo the Blum modulus. - * Using a seed that is too small (except for 0) results in - * an internal generator be used to increase its size. + * There is no limit on the size of a seed. On the other hand, + * in most cases the seed is taken modulo the Blum modulus. + * Using a seed that is too small (except for 0) results in + * an internal generator be used to increase its size. * - * It is faster to use seeds that are in the half open internal - * [sqrt(n), n) where n is the Blum modulus. + * It is faster to use seeds that are in the half open internal + * [sqrt(n), n) where n is the Blum modulus. * - * The default Blum modulus is 260 bits long, so when using a the - * single arg call, a seed of between 128 and 256 bits is reasonable. + * The default Blum modulus is 260 bits long, so when using a the + * single arg call, a seed of between 128 and 256 bits is reasonable. * ****************************************************************************** * @@ -214,46 +214,46 @@ * * seed >= 2^32: * ------------- - * Use seed to compute a new quadratic residue for use with - * the current Blum modulus. We will successively square mod Blum - * modulus until we get a smaller value (modulus wrap). + * Use seed to compute a new quadratic residue for use with + * the current Blum modulus. We will successively square mod Blum + * modulus until we get a smaller value (modulus wrap). * - * The follow calc resource file produces an equivalent effect: + * The follow calc resource file produces an equivalent effect: * - * n = default_modulus; (* n is the new Blum modulus *) - * r = seed; - * do { - * last_r = r; - * r = pmod(last_r, 2, n); - * } while (r > last_r); (* r is the new quadratic residue *) + * n = default_modulus; (* n is the new Blum modulus *) + * r = seed; + * do { + * last_r = r; + * r = pmod(last_r, 2, n); + * } while (r > last_r); (* r is the new quadratic residue *) * - * NOTE: The Blum modulus is not set by this call. + * NOTE: The Blum modulus is not set by this call. * * 0 < seed < 2^32: * ---------------- - * Reserved for future use. + * Reserved for future use. * * seed == 0: * ---------- - * Restore the initial state and modulus of the Blum generator. - * After this call, the Blum generator is restored to its initial - * state after calc started. + * Restore the initial state and modulus of the Blum generator. + * After this call, the Blum generator is restored to its initial + * state after calc started. * - * The Blum prime factors of the modulus have been disclosed (see - * "SOURCE OF MAGIC NUMBERS" below). If you want to use moduli that - * have not been disclosed, use srandom(seed, newn) with the - * appropriate args as noted below. + * The Blum prime factors of the modulus have been disclosed (see + * "SOURCE OF MAGIC NUMBERS" below). If you want to use moduli that + * have not been disclosed, use srandom(seed, newn) with the + * appropriate args as noted below. * - * The follow calc resource file produces an equivalent effect: + * The follow calc resource file produces an equivalent effect: * - * n = default_modulus; (* as used by the initial state *) - * r = default_residue; (* as used by the initial state *) + * n = default_modulus; (* as used by the initial state *) + * r = default_residue; (* as used by the initial state *) * - * NOTE: The Blum modulus is changed by this call. + * NOTE: The Blum modulus is changed by this call. * * seed < 0: * --------- - * Reserved for future use. + * Reserved for future use. * ****************************************************************************** * @@ -271,376 +271,376 @@ * * seed >= 2^32, newn >= 2^32: * --------------------------- - * Assuming that 'newn' == 3 mod 4, then we will use it as - * the Blum modulus. + * Assuming that 'newn' == 3 mod 4, then we will use it as + * the Blum modulus. * - * We will use the seed arg to compute a new quadratic residue. - * We will successively square it mod Blum modulus until we get - * a smaller value (modulus wrap). + * We will use the seed arg to compute a new quadratic residue. + * We will successively square it mod Blum modulus until we get + * a smaller value (modulus wrap). * - * The follow calc resource file produces an equivalent effect: + * The follow calc resource file produces an equivalent effect: * - * if (newn % 4 == 1) { - * n = newn; (* n is the new Blum modulus *) - * r = seed; - * do { - * last_r = r; - * r = pmod(last_r, 2, n); - * } while (r > last_r); (* r is the new quadratic residue *) - * } else { - * quit "newn (2nd arg) must be 3 mod 4"; - * } + * if (newn % 4 == 1) { + * n = newn; (* n is the new Blum modulus *) + * r = seed; + * do { + * last_r = r; + * r = pmod(last_r, 2, n); + * } while (r > last_r); (* r is the new quadratic residue *) + * } else { + * quit "newn (2nd arg) must be 3 mod 4"; + * } * * 0 < seed < 2^32, newn >= 2^32: * ------------------------------ - * Reserved for future use. + * Reserved for future use. * * seed == 0, newn >= 2^32: * ------------------------ - * Assuming that 'newn' == 3 mod 4, then we will use it as - * the Blum modulus. + * Assuming that 'newn' == 3 mod 4, then we will use it as + * the Blum modulus. * - * The initial quadratic residue will be as if the default initial - * quadratic residue arg was given. + * The initial quadratic residue will be as if the default initial + * quadratic residue arg was given. * - * The follow calc resource file produces an equivalent effect: + * The follow calc resource file produces an equivalent effect: * - * srandom(default_residue, newn) + * srandom(default_residue, newn) * - * or in other words: + * or in other words: * - * if (newn % 4 == 1) { - * n = newn; (* n is the new Blum modulus *) - * r = default_residue; (* as used by the initial state *) - * do { - * last_r = r; - * r = pmod(last_r, 2, n); - * } while (r > last_r); (* r is the new quadratic residue *) - * } else { - * quit "newn (2nd arg) must be 3 mod 4"; - * } + * if (newn % 4 == 1) { + * n = newn; (* n is the new Blum modulus *) + * r = default_residue; (* as used by the initial state *) + * do { + * last_r = r; + * r = pmod(last_r, 2, n); + * } while (r > last_r); (* r is the new quadratic residue *) + * } else { + * quit "newn (2nd arg) must be 3 mod 4"; + * } * * seed < 0, newn >= 2^32: * ----------------------- - * Reserved for future use. + * Reserved for future use. * * any seed, 20 < newn < 2^32: * --------------------------- - * Reserved for future use. + * Reserved for future use. * * seed >= 2^32, 0 < newn <= 20: * ----------------------------- - * Set the Blum modulus to one of the pre-defined Blum moduli. - * See below for the values of these pre-defined Blum moduli and how - * they were computed. + * Set the Blum modulus to one of the pre-defined Blum moduli. + * See below for the values of these pre-defined Blum moduli and how + * they were computed. * - * We will use the seed arg to compute a new quadratic residue. - * We will successively square it mod Blum modulus until we get - * a smaller value (modulus wrap). + * We will use the seed arg to compute a new quadratic residue. + * We will successively square it mod Blum modulus until we get + * a smaller value (modulus wrap). * - * The follow calc resource file produces an equivalent effect: + * The follow calc resource file produces an equivalent effect: * - * n = n[newn]; (* n is new Blum modulus, see below *) - * r = seed; - * do { - * last_r = r; - * r = pmod(last_r, 2, n); - * } while (r > last_r); (* r is the new quadratic residue *) + * n = n[newn]; (* n is new Blum modulus, see below *) + * r = seed; + * do { + * last_r = r; + * r = pmod(last_r, 2, n); + * } while (r > last_r); (* r is the new quadratic residue *) * * 0 < seed < 2^32, 0 < newn <= 20: * -------------------------------- - * Reserved for future use. + * Reserved for future use. * * seed == 0, 0 < newn <= 20: * -------------------------- - * Set the Blum modulus to one of the pre-defined Blum moduli. - * The new quadratic residue will also be set to one of - * the pre-defined quadratic residues. + * Set the Blum modulus to one of the pre-defined Blum moduli. + * The new quadratic residue will also be set to one of + * the pre-defined quadratic residues. * - * The follow calc resource file produces an equivalent effect: + * The follow calc resource file produces an equivalent effect: * - * srandom(r[newn], n[newn]) + * srandom(r[newn], n[newn]) * - * or in other words: + * or in other words: * - * n = n[newn]; (* n is the new Blum modulus, see below *) - * r = r[newn]; (* r is the new quadratic residue *) + * n = n[newn]; (* n is the new Blum modulus, see below *) + * r = r[newn]; (* r is the new quadratic residue *) * - * The pre-defined Blum moduli was computed by searching for Blum - * primes (primes == 3 mod 4) starting from new values that - * were selected by LavaRnd, a hardware random number generator. - * See the URL: + * The pre-defined Blum moduli was computed by searching for Blum + * primes (primes == 3 mod 4) starting from new values that + * were selected by LavaRnd, a hardware random number generator. + * See the URL: * - * http://www.LavaRnd.org/ + * http://www.LavaRnd.org/ * - * for an explanation of how the LavaRnd random number generator works. + * for an explanation of how the LavaRnd random number generator works. * - * For a given newn, we select a given bit length. For 0 < newn <= 20, - * the bit length selected was by: + * For a given newn, we select a given bit length. For 0 < newn <= 20, + * the bit length selected was by: * - * bitlen = 2^(int((newn-1)/4)+7) + small_random_value; + * bitlen = 2^(int((newn-1)/4)+7) + small_random_value; * - * where small_random_value is also generated by LavaRnd. For - * 1 <= newn <= 16, small_random_value is a random value in [0,40). - * For 17 < newn <= 20, small_random_value is a random value in [0,120). - * Given two random integers generated by LavaRnd, we used the following - * to compute Blum primes: + * where small_random_value is also generated by LavaRnd. For + * 1 <= newn <= 16, small_random_value is a random value in [0,40). + * For 17 < newn <= 20, small_random_value is a random value in [0,120). + * Given two random integers generated by LavaRnd, we used the following + * to compute Blum primes: * - * (* find the first Blum prime *) - * fp = int((ip-1)/2); (* ip was generated by LavaRnd *) - * do { - * fp = nextcand(fp+2, 25, 0, 3, 4); - * p = 2*fp+1; - * } while (ptest(p, 25) == 0); + * (* find the first Blum prime *) + * fp = int((ip-1)/2); (* ip was generated by LavaRnd *) + * do { + * fp = nextcand(fp+2, 25, 0, 3, 4); + * p = 2*fp+1; + * } while (ptest(p, 25) == 0); * - * (* find the 2nd Blum prime *) - * fq = int((iq-1)/2); (* iq was generated by LavaRnd *) - * do { - * fq = nextcand(fq+2, 25, 0, 3, 4); - * q = 2*fq+1; - * } while (ptest(q, 25) == 0); + * (* find the 2nd Blum prime *) + * fq = int((iq-1)/2); (* iq was generated by LavaRnd *) + * do { + * fq = nextcand(fq+2, 25, 0, 3, 4); + * q = 2*fq+1; + * } while (ptest(q, 25) == 0); * - * (* compute the Blum modulus *) - * n[newn] = p * q; + * (* compute the Blum modulus *) + * n[newn] = p * q; * - * The pre-defined quadratic residues was also generated by LavaRnd. - * The value produced by LavaRnd was squared mod the Blum moduli - * that was previously computed. + * The pre-defined quadratic residues was also generated by LavaRnd. + * The value produced by LavaRnd was squared mod the Blum moduli + * that was previously computed. * - * The purpose of these pre-defined Blum moduli is to provide users with - * an easy way to use a generator where the individual Blum primes used - * are not well known. True, these values are in some way "MAGIC", on - * the other hand that is their purpose! If this bothers you, don't - * use them. See the section "FOR THE PARANOID" below for details. + * The purpose of these pre-defined Blum moduli is to provide users with + * an easy way to use a generator where the individual Blum primes used + * are not well known. True, these values are in some way "MAGIC", on + * the other hand that is their purpose! If this bothers you, don't + * use them. See the section "FOR THE PARANOID" below for details. * - * The value 'newn' determines which pre-defined generator is used. - * For a given 'newn' the Blum modulus 'n[newn]' (product of 2 Blum - * (primes) and new quadratic residue 'r[newn]' is set as follows: + * The value 'newn' determines which pre-defined generator is used. + * For a given 'newn' the Blum modulus 'n[newn]' (product of 2 Blum + * (primes) and new quadratic residue 'r[newn]' is set as follows: * - * newn == 1: (Blum modulus bit length 130) - * n[ 1] = 0x5049440736fe328caf0db722d83de9361 - * r[ 1] = 0xb226980f11d952e74e5dbb01a4cc42ec + * newn == 1: (Blum modulus bit length 130) + * n[ 1] = 0x5049440736fe328caf0db722d83de9361 + * r[ 1] = 0xb226980f11d952e74e5dbb01a4cc42ec * - * newn == 2: (Blum modulus bit length 137) - * n[ 2] = 0x2c5348a2555dd374a18eb286ea9353443f1 - * r[ 2] = 0x40f3d643446cd710e3e893616b21e3a218 + * newn == 2: (Blum modulus bit length 137) + * n[ 2] = 0x2c5348a2555dd374a18eb286ea9353443f1 + * r[ 2] = 0x40f3d643446cd710e3e893616b21e3a218 * - * newn == 3: (Blum modulus bit length 147) - * n[ 3] = 0x9cfd959d6ce4e3a81f1e0f2ca661f11d001f1 - * r[ 3] = 0xfae5b44d9b64ff5cea4f3e142de2a0d7d76a + * newn == 3: (Blum modulus bit length 147) + * n[ 3] = 0x9cfd959d6ce4e3a81f1e0f2ca661f11d001f1 + * r[ 3] = 0xfae5b44d9b64ff5cea4f3e142de2a0d7d76a * - * newn == 4: (Blum modulus bit length 157) - * n[ 4] = 0x3070f9245c894ed75df12a1a2decc680dfcc0751 - * r[ 4] = 0x20c2d8131b2bdca2c0af8aa220ddba4b984570 + * newn == 4: (Blum modulus bit length 157) + * n[ 4] = 0x3070f9245c894ed75df12a1a2decc680dfcc0751 + * r[ 4] = 0x20c2d8131b2bdca2c0af8aa220ddba4b984570 * - * newn == 5: (Blum modulus bit length 257) - * n[ 5] = 0x2109b1822db81a85b38f75aac680bc2fa5d3fe1118769a0108b99e5e799 - * 166ef1 - * r[ 5] = 0x5e9b890eae33b792e821a9605f5df6db234f7b7d1e70aeed0e6c77c859e - * 2efa9 + * newn == 5: (Blum modulus bit length 257) + * n[ 5] = 0x2109b1822db81a85b38f75aac680bc2fa5d3fe1118769a0108b99e5e799 + * 166ef1 + * r[ 5] = 0x5e9b890eae33b792e821a9605f5df6db234f7b7d1e70aeed0e6c77c859e + * 2efa9 * - * newn == 6: (Blum modulus bit length 259) - * n[ 6] = 0xa7bfd9d7d9ada2c79f2dbf2185c6440263a38db775ee732dad85557f1e1 - * ddf431 - * r[ 6] = 0x5e94a02f88667154e097aedece1c925ce1f3495d2c98eccfc5dc2e80c94 - * 04daf + * newn == 6: (Blum modulus bit length 259) + * n[ 6] = 0xa7bfd9d7d9ada2c79f2dbf2185c6440263a38db775ee732dad85557f1e1 + * ddf431 + * r[ 6] = 0x5e94a02f88667154e097aedece1c925ce1f3495d2c98eccfc5dc2e80c94 + * 04daf * - * newn == 7: (Blum modulus bit length 286) - * n[ 7] = 0x43d87de8f2399ef237801cd5628643fcff569d6b0dcf53ce52882e7f602 - * f9125cf9ec751 - * r[ 7] = 0x13522d1ee014c7bfbe90767acced049d876aefcf18d4dd64f0b58c3992d - * 2e5098d25e6 + * newn == 7: (Blum modulus bit length 286) + * n[ 7] = 0x43d87de8f2399ef237801cd5628643fcff569d6b0dcf53ce52882e7f602 + * f9125cf9ec751 + * r[ 7] = 0x13522d1ee014c7bfbe90767acced049d876aefcf18d4dd64f0b58c3992d + * 2e5098d25e6 * - * newn == 8: (Blum modulus bit length 294) - * n[ 8] = 0x5847126ca7eb4699b7f13c9ce7bdc91fed5bdbd2f99ad4a6c2b59cd9f0b - * c42e66a26742f11 - * r[ 8] = 0x853016dca3269116b7e661fa3d344f9a28e9c9475597b4b8a35da929aae - * 95f3a489dc674 + * newn == 8: (Blum modulus bit length 294) + * n[ 8] = 0x5847126ca7eb4699b7f13c9ce7bdc91fed5bdbd2f99ad4a6c2b59cd9f0b + * c42e66a26742f11 + * r[ 8] = 0x853016dca3269116b7e661fa3d344f9a28e9c9475597b4b8a35da929aae + * 95f3a489dc674 * - * newn == 9: (Blum modulus bit length 533) - * n[ 9] = 0x39e8be52322fd3218d923814e81b003d267bb0562157a3c1797b4f4a867 - * 52a84d895c3e08eb61c36a6ff096061c6fd0fdece0d62b16b66b980f95112 - * 745db4ab27e3d1 - * r[ 9] = 0xb458f8ad1e6bbab915bfc01508864b787343bc42a8aa82d9d2880107e3f - * d8357c0bd02de3222796b2545e5ab7d81309a89baedaa5d9e8e59f959601e - * f2b87d4ed20d + * newn == 9: (Blum modulus bit length 533) + * n[ 9] = 0x39e8be52322fd3218d923814e81b003d267bb0562157a3c1797b4f4a867 + * 52a84d895c3e08eb61c36a6ff096061c6fd0fdece0d62b16b66b980f95112 + * 745db4ab27e3d1 + * r[ 9] = 0xb458f8ad1e6bbab915bfc01508864b787343bc42a8aa82d9d2880107e3f + * d8357c0bd02de3222796b2545e5ab7d81309a89baedaa5d9e8e59f959601e + * f2b87d4ed20d * - * newn == 10: (Blum modulus bit length 537) - * n[10] = 0x25f2435c9055666c23ef596882d7f98bd1448bf23b50e88250d3cc952c8 - * 1b3ba524a02fd38582de74511c4008d4957302abe36c6092ce222ef9c73cc - * 3cdc363b7e64b89 - * r[10] = 0x66bb7e47b20e0c18401468787e2b707ca81ec9250df8cfc24b5ffbaaf2c - * f3008ed8b408d075d56f62c669fadc4f1751baf950d145f40ce23442aee59 - * 4f5ad494cfc482 + * newn == 10: (Blum modulus bit length 537) + * n[10] = 0x25f2435c9055666c23ef596882d7f98bd1448bf23b50e88250d3cc952c8 + * 1b3ba524a02fd38582de74511c4008d4957302abe36c6092ce222ef9c73cc + * 3cdc363b7e64b89 + * r[10] = 0x66bb7e47b20e0c18401468787e2b707ca81ec9250df8cfc24b5ffbaaf2c + * f3008ed8b408d075d56f62c669fadc4f1751baf950d145f40ce23442aee59 + * 4f5ad494cfc482 * - * newn == 11: (Blum modulus bit length 542) - * n[11] = 0x497864de82bdb3094217d56b874ecd7769a791ea5ec5446757f3f9b6286 - * e58704499daa2dd37a74925873cfa68f27533920ee1a9a729cf522014dab2 - * 2e1a530c546ee069 - * r[11] = 0x8684881cb5e630264a4465ae3af8b69ce3163f806549a7732339eea2c54 - * d5c590f47fbcedfa07c1ef5628134d918fee5333fed9c094d65461d88b13a - * 0aded356e38b04 + * newn == 11: (Blum modulus bit length 542) + * n[11] = 0x497864de82bdb3094217d56b874ecd7769a791ea5ec5446757f3f9b6286 + * e58704499daa2dd37a74925873cfa68f27533920ee1a9a729cf522014dab2 + * 2e1a530c546ee069 + * r[11] = 0x8684881cb5e630264a4465ae3af8b69ce3163f806549a7732339eea2c54 + * d5c590f47fbcedfa07c1ef5628134d918fee5333fed9c094d65461d88b13a + * 0aded356e38b04 * - * newn == 12: (Blum modulus bit length 549) - * n[12] = 0x3457582ab3c0ccb15f08b8911665b18ca92bb7c2a12b4a1a66ee4251da1 - * 90b15934c94e315a1bf41e048c7c7ce812fdd25d653416557d3f09887efad - * 2b7f66d151f14c7b99 - * r[12] = 0xdf719bd1f648ed935870babd55490137758ca3b20add520da4c5e8cdcbf - * c4333a13f72a10b604eb7eeb07c573dd2c0208e736fe56ed081aa9488fbc4 - * 5227dd68e207b4a0 + * newn == 12: (Blum modulus bit length 549) + * n[12] = 0x3457582ab3c0ccb15f08b8911665b18ca92bb7c2a12b4a1a66ee4251da1 + * 90b15934c94e315a1bf41e048c7c7ce812fdd25d653416557d3f09887efad + * 2b7f66d151f14c7b99 + * r[12] = 0xdf719bd1f648ed935870babd55490137758ca3b20add520da4c5e8cdcbf + * c4333a13f72a10b604eb7eeb07c573dd2c0208e736fe56ed081aa9488fbc4 + * 5227dd68e207b4a0 * - * newn == 13: (Blum modulus bit length 1048) - * n[13] = 0x1517c19166b7dd21b5af734ed03d833daf66d82959a553563f4345bd439 - * 510a7bda8ee0cb6bf6a94286bfd66e49e25678c1ee99ceec891da8b18e843 - * 7575113aaf83c638c07137fdd3a76c3a49322a11b5a1a84c32d99cbb2b056 - * 671589917ed14cc7f1b5915f6495dd1892b4ed7417d79a63cc8aaa503a208 - * e3420cca200323314fc49 - * r[13] = 0xd42e8e9a560d1263fa648b04f6a69b706d2bc4918c3317ddd162cb4be7a - * 5e3bbdd1564a4aadae9fd9f00548f730d5a68dc146f05216fe509f0b8f404 - * 902692de080bbeda0a11f445ff063935ce78a67445eae5c9cea5a8f6b9883 - * faeda1bbe5f1ad3ef6409600e2f67b92ed007aba432b567cc26cf3e965e20 - * 722407bfe46b7736f5 + * newn == 13: (Blum modulus bit length 1048) + * n[13] = 0x1517c19166b7dd21b5af734ed03d833daf66d82959a553563f4345bd439 + * 510a7bda8ee0cb6bf6a94286bfd66e49e25678c1ee99ceec891da8b18e843 + * 7575113aaf83c638c07137fdd3a76c3a49322a11b5a1a84c32d99cbb2b056 + * 671589917ed14cc7f1b5915f6495dd1892b4ed7417d79a63cc8aaa503a208 + * e3420cca200323314fc49 + * r[13] = 0xd42e8e9a560d1263fa648b04f6a69b706d2bc4918c3317ddd162cb4be7a + * 5e3bbdd1564a4aadae9fd9f00548f730d5a68dc146f05216fe509f0b8f404 + * 902692de080bbeda0a11f445ff063935ce78a67445eae5c9cea5a8f6b9883 + * faeda1bbe5f1ad3ef6409600e2f67b92ed007aba432b567cc26cf3e965e20 + * 722407bfe46b7736f5 * - * newn == 14: (Blum modulus bit length 1054) - * n[14] = 0x5e56a00e93c6f4e87479ac07b9d983d01f564618b314b4bfec7931eee85 - * eb909179161e23e78d32110560b22956b22f3bc7e4a034b0586e463fd40c6 - * f01a33e30ede912acb86a0c1e03483c45f289a271d14bd52792d0a076fdfe - * fe32159054b217092237f0767434b3db112fee83005b33f925bacb3185cc4 - * 409a1abdef8c0fc116af01 - * r[14] = 0xf7aa7cb67335096ef0c5d09b18f15415b9a564b609913f75f627fc6b0c5 - * b686c86563fe86134c5a0ea19d243350dfc6b9936ba1512abafb81a0a6856 - * c9ae7816bf2073c0fb58d8138352b261a704b3ce64d69dee6339010186b98 - * 3677c84167d4973444194649ad6d71f8fa8f1f1c313edfbbbb6b1b220913c - * c8ea47a4db680ff9f190 + * newn == 14: (Blum modulus bit length 1054) + * n[14] = 0x5e56a00e93c6f4e87479ac07b9d983d01f564618b314b4bfec7931eee85 + * eb909179161e23e78d32110560b22956b22f3bc7e4a034b0586e463fd40c6 + * f01a33e30ede912acb86a0c1e03483c45f289a271d14bd52792d0a076fdfe + * fe32159054b217092237f0767434b3db112fee83005b33f925bacb3185cc4 + * 409a1abdef8c0fc116af01 + * r[14] = 0xf7aa7cb67335096ef0c5d09b18f15415b9a564b609913f75f627fc6b0c5 + * b686c86563fe86134c5a0ea19d243350dfc6b9936ba1512abafb81a0a6856 + * c9ae7816bf2073c0fb58d8138352b261a704b3ce64d69dee6339010186b98 + * 3677c84167d4973444194649ad6d71f8fa8f1f1c313edfbbbb6b1b220913c + * c8ea47a4db680ff9f190 * - * newn == 15: (Blum modulus bit length 1055) - * n[15] = 0x97dd840b9edfbcdb02c46c175ba81ca845352ebe470be6075326a26770c - * ab84bfc0f2e82aa95aac14f40de42a0590445b902c2b8ebb916753e72ab86 - * c3278cccc1a783b3e962d81b80df03e4380a8fa08b0d86ed0caa515c196a5 - * 30e49c558ddb53082310b1d0c7aee6f92b619798624ffe6c337299bc51ff5 - * d2c721061e7597c8d97079 - * r[15] = 0xb8220703b8c75869ab99f9b50025daa8d77ca6df8cef423ede521f55b1c - * 25d74fbf6d6cc31f5ef45e3b29660ef43797f226860a4aa1023dbe522b1fe - * 6224d01eb77dee9ad97e8970e4a9e28e7391a6a70557fa0e46eca78866241 - * ba3c126fc0c5469f8a2f65c33db95d1749d3f0381f401b9201e6abd43d98d - * b92e808f0aaa6c3e2110 + * newn == 15: (Blum modulus bit length 1055) + * n[15] = 0x97dd840b9edfbcdb02c46c175ba81ca845352ebe470be6075326a26770c + * ab84bfc0f2e82aa95aac14f40de42a0590445b902c2b8ebb916753e72ab86 + * c3278cccc1a783b3e962d81b80df03e4380a8fa08b0d86ed0caa515c196a5 + * 30e49c558ddb53082310b1d0c7aee6f92b619798624ffe6c337299bc51ff5 + * d2c721061e7597c8d97079 + * r[15] = 0xb8220703b8c75869ab99f9b50025daa8d77ca6df8cef423ede521f55b1c + * 25d74fbf6d6cc31f5ef45e3b29660ef43797f226860a4aa1023dbe522b1fe + * 6224d01eb77dee9ad97e8970e4a9e28e7391a6a70557fa0e46eca78866241 + * ba3c126fc0c5469f8a2f65c33db95d1749d3f0381f401b9201e6abd43d98d + * b92e808f0aaa6c3e2110 * - * newn == 16: (Blum modulus bit length 1062) - * n[16] = 0x456e348549b82fbb12b56f84c39f544cb89e43536ae8b2b497d426512c7 - * f3c9cc2311e0503928284391959e379587bc173e6bc51ba51c856ba557fee - * 8dd69cee4bd40845bd34691046534d967e40fe15b6d7cf61e30e283c05be9 - * 93c44b6a2ea8ade0f5578bd3f618336d9731fed1f1c5996a5828d4ca857ac - * 2dc9bd36184183f6d84346e1 - * r[16] = 0xb0d7dcb19fb27a07973e921a4a4b6dcd7895ae8fced828de8a81a3dbf25 - * 24def719225404bfd4977a1508c4bac0f3bc356e9d83b9404b5bf86f6d19f - * f75645dffc9c5cc153a41772670a5e1ae87a9521416e117a0c0d415fb15d2 - * 454809bad45d6972f1ab367137e55ad0560d29ada9a2bcda8f4a70fbe04a1 - * abe4a570605db87b4e8830 + * newn == 16: (Blum modulus bit length 1062) + * n[16] = 0x456e348549b82fbb12b56f84c39f544cb89e43536ae8b2b497d426512c7 + * f3c9cc2311e0503928284391959e379587bc173e6bc51ba51c856ba557fee + * 8dd69cee4bd40845bd34691046534d967e40fe15b6d7cf61e30e283c05be9 + * 93c44b6a2ea8ade0f5578bd3f618336d9731fed1f1c5996a5828d4ca857ac + * 2dc9bd36184183f6d84346e1 + * r[16] = 0xb0d7dcb19fb27a07973e921a4a4b6dcd7895ae8fced828de8a81a3dbf25 + * 24def719225404bfd4977a1508c4bac0f3bc356e9d83b9404b5bf86f6d19f + * f75645dffc9c5cc153a41772670a5e1ae87a9521416e117a0c0d415fb15d2 + * 454809bad45d6972f1ab367137e55ad0560d29ada9a2bcda8f4a70fbe04a1 + * abe4a570605db87b4e8830 * - * newn == 17: (Blum modulus bit length 2062) - * n[17] = 0x6177813aeac0ffa3040b33be3c0f96e0faf97ca54266bfedd7be68494f7 - * 6a7a91144598bf28b3a5a9dc35a6c9f58d0e5fb19839814bc9d456bff7f29 - * 953bdac7cafd66e2fc30531b8d544d2720b97025e22b1c71fa0b2eb9a499d - * 49484615d07af7a3c23b568531e9b8507543362027ec5ebe0209b4647b7ff - * 54be530e9ef50aa819c8ff11f6d7d0a00b25e88f2e6e9de4a7747022b949a - * b2c2e1ab0876e2f1177105718c60196f6c3ac0bde26e6cd4e5b8a20e9f0f6 - * 0974f0b3868ff772ab2ceaf77f328d7244c9ad30e11a2700a120a314aff74 - * c7f14396e2a39cc14a9fa6922ca0fce40304166b249b574ffd9cbb927f766 - * c9b150e970a8d1edc24ebf72b72051 - * r[17] = 0x53720b6eaf3bc3b8adf1dd665324c2d2fc5b2a62f32920c4e167537284d - * a802fc106be4b0399caf97519486f31e0fa45a3a677c6cb265c5551ba4a51 - * 68a7ce3c29731a4e9345eac052ee1b84b7b3a82f906a67aaf7b35949fd7fc - * 2f9f4fbc8c18689694c8d30810fff31ebee99b1cf029a33bd736750e7fe0a - * 56f7e1d2a9b5321b5117fe9a10e46bf43c896e4a33faebd584f7431e7edbe - * bd1703ccee5771b44f0c149888af1a4264cb9cf2e0294ea7719ed6fda1b09 - * fa6e016c039aeb6d02a03281bcea8c278dd2a807eacae6e52ade048f58f2e - * b5193f4ffb9dd68467bc6f8e9d14286bfef09b0aec414c9dadfbf5c46d945 - * d147b52aa1e0cbd625800522b41dac + * newn == 17: (Blum modulus bit length 2062) + * n[17] = 0x6177813aeac0ffa3040b33be3c0f96e0faf97ca54266bfedd7be68494f7 + * 6a7a91144598bf28b3a5a9dc35a6c9f58d0e5fb19839814bc9d456bff7f29 + * 953bdac7cafd66e2fc30531b8d544d2720b97025e22b1c71fa0b2eb9a499d + * 49484615d07af7a3c23b568531e9b8507543362027ec5ebe0209b4647b7ff + * 54be530e9ef50aa819c8ff11f6d7d0a00b25e88f2e6e9de4a7747022b949a + * b2c2e1ab0876e2f1177105718c60196f6c3ac0bde26e6cd4e5b8a20e9f0f6 + * 0974f0b3868ff772ab2ceaf77f328d7244c9ad30e11a2700a120a314aff74 + * c7f14396e2a39cc14a9fa6922ca0fce40304166b249b574ffd9cbb927f766 + * c9b150e970a8d1edc24ebf72b72051 + * r[17] = 0x53720b6eaf3bc3b8adf1dd665324c2d2fc5b2a62f32920c4e167537284d + * a802fc106be4b0399caf97519486f31e0fa45a3a677c6cb265c5551ba4a51 + * 68a7ce3c29731a4e9345eac052ee1b84b7b3a82f906a67aaf7b35949fd7fc + * 2f9f4fbc8c18689694c8d30810fff31ebee99b1cf029a33bd736750e7fe0a + * 56f7e1d2a9b5321b5117fe9a10e46bf43c896e4a33faebd584f7431e7edbe + * bd1703ccee5771b44f0c149888af1a4264cb9cf2e0294ea7719ed6fda1b09 + * fa6e016c039aeb6d02a03281bcea8c278dd2a807eacae6e52ade048f58f2e + * b5193f4ffb9dd68467bc6f8e9d14286bfef09b0aec414c9dadfbf5c46d945 + * d147b52aa1e0cbd625800522b41dac * - * newn == 18: (Blum modulus bit length 2074) - * n[18] = 0x68f2a38fb61b42af07cb724fec0c7c65378efcbafb3514e268d7ee38e21 - * a5680de03f4e63e1e52bde1218f689900be4e5407950539b9d28e9730e8e6 - * ad6438008aa956b259cd965f3a9d02e1711e6b344b033de6425625b6346d2 - * ca62e41605e8eae0a7e2f45c25119ef9eece4d3b18369e753419d94118d51 - * 803842f4de5956b8349e6a0a330145aa4cd1a72afd4ef9db5d8233068e691 - * 18ff4b93bcc67859f211886bb660033f8170640c6e3d61471c3b7dd62c595 - * b156d77f317dc272d6b7e7f4fdc20ed82f172fe29776f3bddf697fb673c70 - * defd6476198a408642ed62081447886a625812ac6576310f23036a7cd3c93 - * 1c96f7df128ad4ed841351b18c8b78629 - * r[18] = 0x4735e921f1ac6c3f0d5cda84cd835d75358be8966b99ff5e5d36bdb4be1 - * 2c5e1df70ac249c0540a99113a8962778dc75dac65af9f3ab4672b4c575c4 - * 9926f7f3f306fd122ac033961d042c416c3aa43b13ef51b764d505bb1f369 - * ac7340f8913ddd812e9e75e8fde8c98700e1d3353da18f255e7303db3bcbb - * eda4bc5b8d472fbc9697f952cfc243c6f32f3f1bb4541e73ca03f5109df80 - * 37219a06430e88a6e94be870f8d36dbcc381a1c449c357753a535aa5666db - * 92af2aaf1f50a3ddde95024d9161548c263973665a909bd325441a3c18fc7 - * 0502f2c9a1c944adda164e84a8f3f0230ff2aef8304b5af333077e04920db - * a179158f6a2b3afb78df2ef9735ea3c63 + * newn == 18: (Blum modulus bit length 2074) + * n[18] = 0x68f2a38fb61b42af07cb724fec0c7c65378efcbafb3514e268d7ee38e21 + * a5680de03f4e63e1e52bde1218f689900be4e5407950539b9d28e9730e8e6 + * ad6438008aa956b259cd965f3a9d02e1711e6b344b033de6425625b6346d2 + * ca62e41605e8eae0a7e2f45c25119ef9eece4d3b18369e753419d94118d51 + * 803842f4de5956b8349e6a0a330145aa4cd1a72afd4ef9db5d8233068e691 + * 18ff4b93bcc67859f211886bb660033f8170640c6e3d61471c3b7dd62c595 + * b156d77f317dc272d6b7e7f4fdc20ed82f172fe29776f3bddf697fb673c70 + * defd6476198a408642ed62081447886a625812ac6576310f23036a7cd3c93 + * 1c96f7df128ad4ed841351b18c8b78629 + * r[18] = 0x4735e921f1ac6c3f0d5cda84cd835d75358be8966b99ff5e5d36bdb4be1 + * 2c5e1df70ac249c0540a99113a8962778dc75dac65af9f3ab4672b4c575c4 + * 9926f7f3f306fd122ac033961d042c416c3aa43b13ef51b764d505bb1f369 + * ac7340f8913ddd812e9e75e8fde8c98700e1d3353da18f255e7303db3bcbb + * eda4bc5b8d472fbc9697f952cfc243c6f32f3f1bb4541e73ca03f5109df80 + * 37219a06430e88a6e94be870f8d36dbcc381a1c449c357753a535aa5666db + * 92af2aaf1f50a3ddde95024d9161548c263973665a909bd325441a3c18fc7 + * 0502f2c9a1c944adda164e84a8f3f0230ff2aef8304b5af333077e04920db + * a179158f6a2b3afb78df2ef9735ea3c63 * - * newn == 19: (Blum modulus bit length 2133) - * n[19] = 0x230d7ab23bb9e8d6788b252ad6534bdde276540721c3152e410ad4244de - * b0df28f4a6de063ba1e51d7cd1736c3d8410e2516b4eb903b8d9206b92026 - * 64cacbd0425c516833770d118bd5011f3de57e8f607684088255bf7da7530 - * 56bf373715ed9a7ab85f698b965593fe2b674225fa0a02ebd87402ffb3d97 - * 172acadaa841664c361f7c11b2af47a472512ee815c970af831f95b737c34 - * 2508e4c23f3148f3cdf622744c1dcfb69a43fd535e55eebcdc992ee62f2b5 - * 2c94ac02e0921884fe275b3a528bdb14167b7dec3f3f390cd5a82d80c6c30 - * 6624cc7a7814fb567cd4d687eede573358f43adfcf1e32f4ee7a2dc4af029 - * 6435ade8099bf0001d4ae0c7d204df490239c12d6b659a79 - * r[19] = 0x8f1725f21e245e4fc17982196605b999518b4e21f65126fa6fa759332c8 - * e27d80158b7537da39d001cc62b83bbef0713b1e82f8293dad522993f86d1 - * 761015414b2900e74fa23f3eaaa55b31cffd2e801fefb0ac73fd99b5d0cf9 - * a635c3f4c73d8892d36ad053fc17a423cdcbcf07967a8608c7735e287d784 - * ae089b3ddea9f2d2bb5d43d2ee25be346832e8dd186fc7a88d82847c03d1c - * 05ee52c1f2a51a85f733338547fdbab657cb64b43d44d41148eb32ea68c7e - * 66a8d47806f460cd6573b6ca1dd3eeaf1ce8db9621f1e121d2bb4a1878621 - * dd2dbdd7b5390ab06a5dcd9307d6662eb4248dff2ee263ef2ab778e77724a - * 14c62406967daa0d9ad4445064483193d53a5b7698ef473 + * newn == 19: (Blum modulus bit length 2133) + * n[19] = 0x230d7ab23bb9e8d6788b252ad6534bdde276540721c3152e410ad4244de + * b0df28f4a6de063ba1e51d7cd1736c3d8410e2516b4eb903b8d9206b92026 + * 64cacbd0425c516833770d118bd5011f3de57e8f607684088255bf7da7530 + * 56bf373715ed9a7ab85f698b965593fe2b674225fa0a02ebd87402ffb3d97 + * 172acadaa841664c361f7c11b2af47a472512ee815c970af831f95b737c34 + * 2508e4c23f3148f3cdf622744c1dcfb69a43fd535e55eebcdc992ee62f2b5 + * 2c94ac02e0921884fe275b3a528bdb14167b7dec3f3f390cd5a82d80c6c30 + * 6624cc7a7814fb567cd4d687eede573358f43adfcf1e32f4ee7a2dc4af029 + * 6435ade8099bf0001d4ae0c7d204df490239c12d6b659a79 + * r[19] = 0x8f1725f21e245e4fc17982196605b999518b4e21f65126fa6fa759332c8 + * e27d80158b7537da39d001cc62b83bbef0713b1e82f8293dad522993f86d1 + * 761015414b2900e74fa23f3eaaa55b31cffd2e801fefb0ac73fd99b5d0cf9 + * a635c3f4c73d8892d36ad053fc17a423cdcbcf07967a8608c7735e287d784 + * ae089b3ddea9f2d2bb5d43d2ee25be346832e8dd186fc7a88d82847c03d1c + * 05ee52c1f2a51a85f733338547fdbab657cb64b43d44d41148eb32ea68c7e + * 66a8d47806f460cd6573b6ca1dd3eeaf1ce8db9621f1e121d2bb4a1878621 + * dd2dbdd7b5390ab06a5dcd9307d6662eb4248dff2ee263ef2ab778e77724a + * 14c62406967daa0d9ad4445064483193d53a5b7698ef473 * - * newn == 20: (Blum modulus bit length 2166) - * n[20] = 0x4fd2b820e0d8b13322e890dddc63a0267e5b3a648b03276066a3f356d79 - * 660c67704c1be6803b8e7590ee8a962c8331a05778d010e9ba10804d661f3 - * 354be1932f90babb741bd4302a07a92c42253fd4921864729fb0f0b1e0a42 - * d66b6777893195abd2ee2141925624bf71ad7328360135c565064ee502773 - * 6f42a78b988f47407ba4f7996892ffdc5cf9e7ab78ac95734dbf4e3a3def1 - * 615b5b4341cfbf6c3d0a61b75f4974080bbac03ee9de55221302b40da0c50 - * ded31d28a2f04921a532b3a486ae36e0bb5273e811d119adf90299a74e623 - * 3ccce7069676db00a3e8ce255a82fd9748b26546b98c8f4430a8db2a4b230 - * fa365c51e0985801abba4bbcf3727f7c8765cc914d262fcec3c1d081 - * r[20] = 0x46ef0184445feaa3099293ee960da14b0f8b046fa9f608241bc08ddeef1 - * 7ee49194fd9bb2c302840e8da88c4e88df810ce387cc544209ec67656bd1d - * a1e9920c7b1aad69448bb58455c9ae4e9cd926911b30d6b5843ff3d306d56 - * 54a41dc20e2de4eb174ec5ac3e6e70849de5d5f9166961207e2d8b31014cf - * 35f801de8372881ae1ba79e58942e5bef0a7e40f46387bf775c54b1d15a14 - * 40e84beb39cd9e931f5638234ea730ed81d6fca1d7cea9e8ffb171f6ca228 - * 56264a36a2a783fd7ac39361a6598ed3a565d58acf1f5759bd294e5f53131 - * bc8e4ee3750794df727b29b1f5788ae14e6a1d1a5b26c2947ed46f49e8377 - * 3292d7dd5650580faebf85fd126ac98d98f47cf895abdc7ba048bd1a + * newn == 20: (Blum modulus bit length 2166) + * n[20] = 0x4fd2b820e0d8b13322e890dddc63a0267e5b3a648b03276066a3f356d79 + * 660c67704c1be6803b8e7590ee8a962c8331a05778d010e9ba10804d661f3 + * 354be1932f90babb741bd4302a07a92c42253fd4921864729fb0f0b1e0a42 + * d66b6777893195abd2ee2141925624bf71ad7328360135c565064ee502773 + * 6f42a78b988f47407ba4f7996892ffdc5cf9e7ab78ac95734dbf4e3a3def1 + * 615b5b4341cfbf6c3d0a61b75f4974080bbac03ee9de55221302b40da0c50 + * ded31d28a2f04921a532b3a486ae36e0bb5273e811d119adf90299a74e623 + * 3ccce7069676db00a3e8ce255a82fd9748b26546b98c8f4430a8db2a4b230 + * fa365c51e0985801abba4bbcf3727f7c8765cc914d262fcec3c1d081 + * r[20] = 0x46ef0184445feaa3099293ee960da14b0f8b046fa9f608241bc08ddeef1 + * 7ee49194fd9bb2c302840e8da88c4e88df810ce387cc544209ec67656bd1d + * a1e9920c7b1aad69448bb58455c9ae4e9cd926911b30d6b5843ff3d306d56 + * 54a41dc20e2de4eb174ec5ac3e6e70849de5d5f9166961207e2d8b31014cf + * 35f801de8372881ae1ba79e58942e5bef0a7e40f46387bf775c54b1d15a14 + * 40e84beb39cd9e931f5638234ea730ed81d6fca1d7cea9e8ffb171f6ca228 + * 56264a36a2a783fd7ac39361a6598ed3a565d58acf1f5759bd294e5f53131 + * bc8e4ee3750794df727b29b1f5788ae14e6a1d1a5b26c2947ed46f49e8377 + * 3292d7dd5650580faebf85fd126ac98d98f47cf895abdc7ba048bd1a * - * NOTE: The Blum moduli associated with 1 <= newn < 9 are subject - * to having their Blum moduli factored, depending in their size, - * by small PCs in a reasonable to large supercomputers/highly - * parallel processors over a long time. Their value lies in their - * speed relative the default Blum generator. As of Jan 1997, - * the Blum moduli associated with 13 <= newn < 20 appear to - * be well beyond the scope of hardware and algorithms, - * and 9 <= newn < 12 might be factorable with extreme difficulty. + * NOTE: The Blum moduli associated with 1 <= newn < 9 are subject + * to having their Blum moduli factored, depending in their size, + * by small PCs in a reasonable to large supercomputers/highly + * parallel processors over a long time. Their value lies in their + * speed relative the default Blum generator. As of Jan 1997, + * the Blum moduli associated with 13 <= newn < 20 appear to + * be well beyond the scope of hardware and algorithms, + * and 9 <= newn < 12 might be factorable with extreme difficulty. * - * The following table may be useful as a guide for how easy it - * is to factor the modulus: + * The following table may be useful as a guide for how easy it + * is to factor the modulus: * - * 1 <= newn <= 4 PC using ECM in a short amount of time - * 5 <= newn <= 8 Workstation using MPQS in a short amount of time - * 8 <= newn <= 12 High end supercomputer or high parallel processor - * using state of the art factoring over a long time + * 1 <= newn <= 4 PC using ECM in a short amount of time + * 5 <= newn <= 8 Workstation using MPQS in a short amount of time + * 8 <= newn <= 12 High end supercomputer or high parallel processor + * using state of the art factoring over a long time * 12 <= newn <= 16 Beyond Feb 1997 systems and factoring methods * 17 <= newn <= 20 Well beyond Feb 1997 systems and factoring methods * - * See the section titled 'FOR THE PARANOID' for more details. + * See the section titled 'FOR THE PARANOID' for more details. * * seed < 0, 0 < newn <= 20: * ------------------------- - * Reserved for future use. + * Reserved for future use. * ****************************************************************************** * @@ -658,59 +658,59 @@ * * seed >= 2^32, ip >= 2^16, iq >= 2^16: * ------------------------------------- - * Set the Blum modulus by searching from the ip and iq search points. + * Set the Blum modulus by searching from the ip and iq search points. * - * We will use the seed arg to compute a new quadratic residue. - * We will successively square it mod Blum modulus until we get - * a smaller value (modulus wrap). + * We will use the seed arg to compute a new quadratic residue. + * We will successively square it mod Blum modulus until we get + * a smaller value (modulus wrap). * - * The follow calc resource file produces an equivalent effect: + * The follow calc resource file produces an equivalent effect: * - * p = nextcand(ip-2, trials, 0, 3, 4); (* find the 1st Blum prime *) - * q = nextcand(iq-2, trials, 0, 3, 4); (* find the 2nd Blum prime *) - * n = p * q; (* n is the new Blum modulus *) - * r = seed; - * do { - * last_r = r; - * r = pmod(last_r, 2, n); - * } while (r > last_r); (* r is the new quadratic residue *) - * srandom(r, n); + * p = nextcand(ip-2, trials, 0, 3, 4); (* find the 1st Blum prime *) + * q = nextcand(iq-2, trials, 0, 3, 4); (* find the 2nd Blum prime *) + * n = p * q; (* n is the new Blum modulus *) + * r = seed; + * do { + * last_r = r; + * r = pmod(last_r, 2, n); + * } while (r > last_r); (* r is the new quadratic residue *) + * srandom(r, n); * * any seed, ip <= 2^16 or iq <= 2^16: * ----------------------------------- - * Reserved for future use. + * Reserved for future use. * * 0 < seed < 2^32, any ip, any iq: * -------------------------------- - * Reserved for future use. + * Reserved for future use. * * seed == 0, ip > 2^16, iq > 2^16: * -------------------------------- - * Set the Blum modulus by searching from the ip and iq search points. - * If trials is omitted, 1 is assumed. + * Set the Blum modulus by searching from the ip and iq search points. + * If trials is omitted, 1 is assumed. * - * The initial quadratic residue will be as if the default initial - * quadratic residue arg was given. + * The initial quadratic residue will be as if the default initial + * quadratic residue arg was given. * - * The follow calc resource file produces an equivalent effect: + * The follow calc resource file produces an equivalent effect: * - * srandom(default_residue, ip, iq, trials) + * srandom(default_residue, ip, iq, trials) * - * or in other words: + * or in other words: * - * (* trials, if omitted, is assumed to be 1 *) - * p = nextcand(ip-2, trials, 0, 3, 4); (* find the 1st Blum prime *) - * q = nextcand(iq-2, trials, 0, 3, 4); (* find the 2nd Blum prime *) - * n = p * q; (* n is the new Blum modulus *) - * r = default_residue; (* as used by the initial state *) - * do { - * last_r = r; - * r = pmod(last_r, 2, n); - * } while (r > last_r); (* r is the new quadratic residue *) + * (* trials, if omitted, is assumed to be 1 *) + * p = nextcand(ip-2, trials, 0, 3, 4); (* find the 1st Blum prime *) + * q = nextcand(iq-2, trials, 0, 3, 4); (* find the 2nd Blum prime *) + * n = p * q; (* n is the new Blum modulus *) + * r = default_residue; (* as used by the initial state *) + * do { + * last_r = r; + * r = pmod(last_r, 2, n); + * } while (r > last_r); (* r is the new quadratic residue *) * * seed < 0, any ip, any iq: * ------------------------- - * Reserved for future use. + * Reserved for future use. * ****************************************************************************** * @@ -723,22 +723,22 @@ * * srandom(state) * - * Restore the Blum state and return the previous state. Note that - * the argument state is a random state value (israndom(state) is true). - * Any internally buffered random bits are restored. + * Restore the Blum state and return the previous state. Note that + * the argument state is a random state value (israndom(state) is true). + * Any internally buffered random bits are restored. * - * The states of the Blum generators can be saved by calling the seed - * function with no arguments, and later restored by calling the seed - * functions with that same return value. + * The states of the Blum generators can be saved by calling the seed + * function with no arguments, and later restored by calling the seed + * functions with that same return value. * - * random_state = srandom(); - * ... generate random bits ... - * prev_random_state = srandom(random_state); - * ... generate the same random bits ... - * srandom() == prev_random_state; (* is true *) + * random_state = srandom(); + * ... generate random bits ... + * prev_random_state = srandom(random_state); + * ... generate the same random bits ... + * srandom() == prev_random_state; (* is true *) * - * Saving the state just after seeding a generator and restoring it later - * as a very fast way to reseed a generator. + * Saving the state just after seeding a generator and restoring it later + * as a very fast way to reseed a generator. */ /* @@ -746,7 +746,7 @@ * * When the call: * - * srandom(seed, nextcand(ip,25,0,3,4)*nextcand(iq,25,0,3,4)) + * srandom(seed, nextcand(ip,25,0,3,4)*nextcand(iq,25,0,3,4)) * * probable primes from nextcand are used. We use the word * 'probable' because of an extremely extremely small chance that a @@ -754,10 +754,10 @@ * * We use the builtin function nextcand in its 5 arg form: * - * nextcand(value, 25, 0, 3, 4) + * nextcand(value, 25, 0, 3, 4) * * The odds that a number returned by the above call is not prime is - * less than 1 in 4^25. For our purposes, this is sufficient as the + * less than 1 in 4^25. For our purposes, this is sufficient as the * chance of returning a composite is much smaller than the chance that * a hardware glitch will cause nextcand() to return a bogus result. * @@ -801,7 +801,7 @@ * * Taking some care to select a good initial residue helps eliminate cheap * search attacks. It is true that a subsequent residue could be one of the - * residues that we would first avoid. However such an occurrence will + * residues that we would first avoid. However such an occurrence will * happen after the generator is well underway and any such seed information * has been lost. * @@ -815,7 +815,7 @@ * * The size of default Blum modulus 'n=p*q' was taken to be > 2^259, or * 260 bits (79 digits) long. A modulus > 2^256 will generate 8 bits - * per crank of the generator. The period of this generator is long + * per crank of the generator. The period of this generator is long * enough to be reasonable, and the modulus is small enough to be fast. * * The default Blum modulus is not a secure modulus because it can @@ -844,50 +844,50 @@ * starting search point for 'p', and the next 42 digits for a starting * search point for 'q'. * - * (* - * * setup the search points (lines split for readability) - * *) - * ip = 10097325337652013586346735487680959091; - * iq = 173929274945375420480564894742962480524037; + * (* + * * setup the search points (lines split for readability) + * *) + * ip = 10097325337652013586346735487680959091; + * iq = 173929274945375420480564894742962480524037; * - * (* - * * find the first Blum prime - * *) - * fp = int((ip-1)/2); - * do { - * fp = nextcand(fp+2, 25, 0, 3, 4); - * p = 2*fp+1; - * } while (ptest(p, 25) == 0); + * (* + * * find the first Blum prime + * *) + * fp = int((ip-1)/2); + * do { + * fp = nextcand(fp+2, 25, 0, 3, 4); + * p = 2*fp+1; + * } while (ptest(p, 25) == 0); * - * (* - * * find the 2nd Blum prime - * *) - * fq = int((iq-1)/2); - * do { - * fq = nextcand(fq+2, 25, 0, 3, 4); - * q = 2*fq+1; - * } while (ptest(q, 25) == 0); + * (* + * * find the 2nd Blum prime + * *) + * fq = int((iq-1)/2); + * do { + * fq = nextcand(fq+2, 25, 0, 3, 4); + * q = 2*fq+1; + * } while (ptest(q, 25) == 0); * * The above resource file produces the Blum probable primes and initial * quadratic residue (line wrapped for readability): * - * p= 0x798ac934c7a3318ad446190f3474e57 + * p= 0x798ac934c7a3318ad446190f3474e57 * - * q= 0x1ff21d7e1dd7d5965e224d485d84c3ef44f + * q= 0x1ff21d7e1dd7d5965e224d485d84c3ef44f * * These Blum primes were found after 1.81s of CPU time on a 195 Mhz IP28 * R10000 version 2.5 processor. The first Blum prime 'p' was 31716 higher - * than the initial search value 'ip'. The second Blum prime 'q' was 18762 + * than the initial search value 'ip'. The second Blum prime 'q' was 18762 * higher than the initial starting 'iq'. * * The product of the two Blum primes results in a 260 bit Blum modulus of: * - * n = 0xf2ac1903156af9e373d78613ed0e8d30284f34b644a9027d9ba55a689d6be18d9 + * n = 0xf2ac1903156af9e373d78613ed0e8d30284f34b644a9027d9ba55a689d6be18d9 * * The selection if the initial quadratic residue comes from the next * unused digits of the Rand Book of Random Numbers. Now the two initial * search values 'ip' and 'iq' used above needed the first 38 digits and - * the next 42 digits. Thus we will skip the first 38+42=80 digits + * the next 42 digits. Thus we will skip the first 38+42=80 digits * and begin to build in initial search value for a quadratic residue (most * significant digit first) from the Rand Book of Numbers digits until we * have a value whose square mod n > 4th power mod n. In other words, we @@ -897,15 +897,15 @@ * * Clearly we need to find an ir that is > sqrt(n). The first ir: * - * ir = 2063610402008229166508422689531964509303 + * ir = 2063610402008229166508422689531964509303 * * fails the single loop criteria. So we add the next digit: * - * ir = 20636104020082291665084226895319645093032 + * ir = 20636104020082291665084226895319645093032 * * Here we find that: * - * pmod(ir,2,n) > pmod(pmod(ir,2,n),2,n) + * pmod(ir,2,n) > pmod(pmod(ir,2,n),2,n) * * Thus, for the Blum modulus 'n', the method outlined for srandom(ir) yields * the initial quadratic residue of: @@ -917,28 +917,28 @@ * In the above process of finding the Blum primes used in the default * Blum modulus, we selected primes of the form: * - * 2*x + 1 x is also prime + * 2*x + 1 x is also prime * * because Blum generators with modulus 'n=p*q' have a period: * - * lambda(n) = lcm(factors of p-1 & q-1) + * lambda(n) = lcm(factors of p-1 & q-1) * * since 'p' and 'q' are both odd, 'p-1' and 'q-1' have 2 as * a factor. The calc resource file above ensures that '(p-1)/2' and * '(q-1)/2' are probable prime, thus maximizing the period * of the default generator to: * - * lambda(n) = lcm(2,2,fp,fq) = 2*fp*fq = ~2*(p/2)*(q/2) = ~n/2 + * lambda(n) = lcm(2,2,fp,fq) = 2*fp*fq = ~2*(p/2)*(q/2) = ~n/2 * * The process above resulted in a default generator Blum modulus n > 2^259 - * with period of at least 2^258 bits. To be exact, the period of the + * with period of at least 2^258 bits. To be exact, the period of the * default Blum generator is: * - * 0x79560c818ab57cf1b9ebc309f68746881adc15e79c05e476f741e5f904b9beb1a + * 0x79560c818ab57cf1b9ebc309f68746881adc15e79c05e476f741e5f904b9beb1a * * which is approximately: * - * ~8.781 * 10^77 + * ~8.781 * 10^77 * * This period is more than long enough for computationally tractable tasks. * @@ -952,7 +952,7 @@ * The lengths of the two Blum probable primes 'p' and 'q' used to make up * the 20 Blum moduli 'n=p*q' differ slightly to avoid certain * factorization attacks that work on numbers that are a perfect square, - * or where the two primes are nearly the same. I elected to have the + * or where the two primes are nearly the same. I elected to have the * sizes differ by up to 6% of the product size to avoid such attacks. * Clearly one does not want the size of the two factors to differ * by a large percentage: p=3 and q large would result in a easy @@ -969,7 +969,7 @@ * FOR THE PARANOID: * * The truly paranoid might suggest that my claims in the MAGIC NUMBERS - * section are a lie intended to entrap people. Well they are not, but + * section are a lie intended to entrap people. Well they are not, but * you need not take my word for it. * *** @@ -985,7 +985,7 @@ * If all the above fails to pacify the truly paranoid, then one may * select your own modulus and initial quadratic residue by calling: * - * srandom(r, n); + * srandom(r, n); * * Of course, you will need to select a correct Blum modulus 'n' as the * product of two Blum primes (both 3 mod 4) and with a long period (where @@ -994,7 +994,7 @@ * * A simple way to seed the generator would be to: * - * srandom(ir, ip, iq, 25) + * srandom(ir, ip, iq, 25) * * where 'ip', 'iq' and 'ir' are large integers that are unlikely to be * 'guessed' and where numbers around the size of iq*ir are beyond @@ -1011,32 +1011,32 @@ * seedrandom(seed1, seed2, size [,tests]) function from "seedrandom.cal" * with the args: * - * seed1 - seed rand() to search for 'p', select from [2^64, 2^308) - * seed2 - seed rand() to search for 'q', select from [2^64, 2^308) - * size - minimum bit size of the Blum modulus 'n=p*q' - * tests - optional arg for number of pseudo prime tests (default is 25) + * seed1 - seed rand() to search for 'p', select from [2^64, 2^308) + * seed2 - seed rand() to search for 'q', select from [2^64, 2^308) + * size - minimum bit size of the Blum modulus 'n=p*q' + * tests - optional arg for number of pseudo prime tests (default is 25) * * Last, one could use some external random source to select starting * search points for 'p', 'q' and the quadratic residue. One way to * do this is: * - * fp = int((ip-1)/2); - * do { - * fp = nextcand(fp+2, tests, 0, 3, 4); - * p = 2*fp+1; - * } while (ptest(p, tests) == 0); - * fq = int((iq-1)/2); - * do { - * fq = nextcand(fq+2, tests, 0, 3, 4); - * q = 2*fq+1; - * } while (ptest(q, tests) == 0); - * srandom(pmod(ir,2,p*q), p*q); + * fp = int((ip-1)/2); + * do { + * fp = nextcand(fp+2, tests, 0, 3, 4); + * p = 2*fp+1; + * } while (ptest(p, tests) == 0); + * fq = int((iq-1)/2); + * do { + * fq = nextcand(fq+2, tests, 0, 3, 4); + * q = 2*fq+1; + * } while (ptest(q, tests) == 0); + * srandom(pmod(ir,2,p*q), p*q); * * where 'tests' is the number of pseudo prime tests that a candidate must * pass before being considered a probable prime (must be >0, perhaps 25), and * where 'ip' is the initial search location for the Blum prime 'p', and * where 'iq' is the initial search location for the Blum prime 'q', and - * where 'ir' is the initial Blum quadratic residue generator. The 'ir' + * where 'ir' is the initial Blum quadratic residue generator. The 'ir' * value should be a random value in the range [2^(binsize*4/5), 2^(binsize-2)) * where 2^(binsize-1) < n=p*q <= 2^binsize. * @@ -1054,21 +1054,21 @@ * primes used in these special pre-defined generators are unknown. * * Not being able to factor 'n=p*q' into 'p' and 'q' does not directly - * improve the quality Blum generator. On the other hand, it does + * improve the quality Blum generator. On the other hand, it does * improve the security of it. * * I (Landon Curt Noll) did not keep the search values of these 20 special * pre-defined generators. While some of the smaller Blum moduli is - * within the range of some factoring methods, others are not. As of + * within the range of some factoring methods, others are not. As of * Feb 1997, the following is the estimate of what can factor the * pre-defined moduli: * - * 1 <= newn < 4 PC using ECM in a short amount of time - * 5 <= newn < 8 Workstation using MPQS in a short amount of time - * 8 <= newn < 12 High end supercomputer or high parallel processor - * using state of the art factoring over a long time - * 12 <= newn < 16 Beyond Feb 1997 systems and factoring methods - * 17 <= newn < 20 Well beyond Feb 1997 systems and factoring methods + * 1 <= newn < 4 PC using ECM in a short amount of time + * 5 <= newn < 8 Workstation using MPQS in a short amount of time + * 8 <= newn < 12 High end supercomputer or high parallel processor + * using state of the art factoring over a long time + * 12 <= newn < 16 Beyond Feb 1997 systems and factoring methods + * 17 <= newn < 20 Well beyond Feb 1997 systems and factoring methods * * This is not to say that in the future things will not change. One * can say that faster hardware will not help in the factoring of 1024+ @@ -1100,14 +1100,14 @@ #include "errtbl.h" -#include "banned.h" /* include after system header <> includes */ +#include "banned.h" /* include after system header <> includes */ /* * current Blum generator state */ STATIC RANDOM blum; -STATIC bool blum_initialized = false; /* true ==> blum has a seeded and initialized state */ +STATIC bool blum_initialized = false; /* true ==> blum has a seeded and initialized state */ /* @@ -1128,54 +1128,54 @@ STATIC ZVALUE _four_ = { _fourval_, 1, 0 }; */ #if FULL_BITS == 64 STATIC CONST HALF h_ndefvec[] = { - (HALF)0xd6be18d9, (HALF)0xba55a689, (HALF)0x4a9027d9, (HALF)0x84f34b64, - (HALF)0xd0e8d302, (HALF)0x3d78613e, (HALF)0x56af9e37, (HALF)0x2ac19031, - (HALF)0xf + (HALF)0xd6be18d9, (HALF)0xba55a689, (HALF)0x4a9027d9, (HALF)0x84f34b64, + (HALF)0xd0e8d302, (HALF)0x3d78613e, (HALF)0x56af9e37, (HALF)0x2ac19031, + (HALF)0xf }; STATIC CONST HALF h_rdefvec[] = { - (HALF)0xd3e7b11e, (HALF)0x0f23fd7e, (HALF)0xa62546c9, (HALF)0x06c73ca5, - (HALF)0x627d6265, (HALF)0x2f1e93a8, (HALF)0xff4b074e, (HALF)0x48b6d882, - (HALF)0x7 + (HALF)0xd3e7b11e, (HALF)0x0f23fd7e, (HALF)0xa62546c9, (HALF)0x06c73ca5, + (HALF)0x627d6265, (HALF)0x2f1e93a8, (HALF)0xff4b074e, (HALF)0x48b6d882, + (HALF)0x7 }; #elif 2*FULL_BITS == 64 STATIC CONST HALF h_ndefvec[] = { - (HALF)0x18d9, (HALF)0xd6be, (HALF)0xa689, (HALF)0xba55, - (HALF)0x27d9, (HALF)0x4a90, (HALF)0x4b64, (HALF)0x84f3, - (HALF)0xd302, (HALF)0xd0e8, (HALF)0x613e, (HALF)0x3d78, - (HALF)0x9e37, (HALF)0x56af, (HALF)0x9031, (HALF)0x2ac1, - (HALF)0xf + (HALF)0x18d9, (HALF)0xd6be, (HALF)0xa689, (HALF)0xba55, + (HALF)0x27d9, (HALF)0x4a90, (HALF)0x4b64, (HALF)0x84f3, + (HALF)0xd302, (HALF)0xd0e8, (HALF)0x613e, (HALF)0x3d78, + (HALF)0x9e37, (HALF)0x56af, (HALF)0x9031, (HALF)0x2ac1, + (HALF)0xf }; STATIC CONST HALF h_rdefvec[] = { - (HALF)0xb11e, (HALF)0xd3e7, (HALF)0xfd7e, (HALF)0x0f23, - (HALF)0x46c9, (HALF)0xa625, (HALF)0x3ca5, (HALF)0x06c7, - (HALF)0x6265, (HALF)0x627d, (HALF)0x93a8, (HALF)0x2f1e, - (HALF)0x074e, (HALF)0xff4b, (HALF)0xd882, (HALF)0x48b6, - (HALF)0x7 + (HALF)0xb11e, (HALF)0xd3e7, (HALF)0xfd7e, (HALF)0x0f23, + (HALF)0x46c9, (HALF)0xa625, (HALF)0x3ca5, (HALF)0x06c7, + (HALF)0x6265, (HALF)0x627d, (HALF)0x93a8, (HALF)0x2f1e, + (HALF)0x074e, (HALF)0xff4b, (HALF)0xd882, (HALF)0x48b6, + (HALF)0x7 }; #else - /\../\ FULL_BITS must be 32 or 64 /\../\ !!! + /\../\ FULL_BITS must be 32 or 64 /\../\ !!! #endif STATIC CONST RANDOM init_blum = {1, 0, 8, (HALF)0, (HALF)0xff, - {(HALF *)h_ndefvec, - sizeof(h_ndefvec)/sizeof(HALF), 0}, - {(HALF *)h_rdefvec, - sizeof(h_rdefvec)/sizeof(HALF), 0}}; + {(HALF *)h_ndefvec, + sizeof(h_ndefvec)/sizeof(HALF), 0}, + {(HALF *)h_rdefvec, + sizeof(h_rdefvec)/sizeof(HALF), 0}}; #if FULL_BITS == 64 STATIC CONST HALF h_rdefvec_2[] = { - (HALF)0xd3e7b11e, (HALF)0x0f23fd7e, (HALF)0xa62546c9, (HALF)0x06c73ca5, - (HALF)0x627d6265, (HALF)0x2f1e93a8, (HALF)0xff4b074e, (HALF)0x48b6d882, - (HALF)0x7 + (HALF)0xd3e7b11e, (HALF)0x0f23fd7e, (HALF)0xa62546c9, (HALF)0x06c73ca5, + (HALF)0x627d6265, (HALF)0x2f1e93a8, (HALF)0xff4b074e, (HALF)0x48b6d882, + (HALF)0x7 }; #elif 2*FULL_BITS == 64 STATIC CONST HALF h_rdefvec_2[] = { - (HALF)0xb11e, (HALF)0xd3e7, (HALF)0xfd7e, (HALF)0x0f23, - (HALF)0x46c9, (HALF)0xa625, (HALF)0x3ca5, (HALF)0x06c7, - (HALF)0x6265, (HALF)0x627d, (HALF)0x93a8, (HALF)0x2f1e, - (HALF)0x074e, (HALF)0xff4b, (HALF)0xd882, (HALF)0x48b6, - (HALF)0x7 + (HALF)0xb11e, (HALF)0xd3e7, (HALF)0xfd7e, (HALF)0x0f23, + (HALF)0x46c9, (HALF)0xa625, (HALF)0x3ca5, (HALF)0x06c7, + (HALF)0x6265, (HALF)0x627d, (HALF)0x93a8, (HALF)0x2f1e, + (HALF)0x074e, (HALF)0xff4b, (HALF)0xd882, (HALF)0x48b6, + (HALF)0x7 }; #else - /\../\ FULL_BITS must be 32 or 64 /\../\ !!! + /\../\ FULL_BITS must be 32 or 64 /\../\ !!! #endif STATIC CONST ZVALUE z_rdefault = { (HALF *)h_rdefvec_2, sizeof(h_rdefvec_2)/sizeof(HALF), 0 @@ -1190,990 +1190,990 @@ STATIC CONST ZVALUE z_rdefault = { */ #if FULL_BITS == 64 STATIC CONST HALF h_nvec01[] = { - (HALF)0x83de9361, (HALF)0xf0db722d, (HALF)0x6fe328ca, (HALF)0x04944073, - (HALF)0x5 + (HALF)0x83de9361, (HALF)0xf0db722d, (HALF)0x6fe328ca, (HALF)0x04944073, + (HALF)0x5 }; STATIC CONST HALF h_rvec01[] = { - (HALF)0xa4cc42ec, (HALF)0x4e5dbb01, (HALF)0x11d952e7, (HALF)0xb226980f + (HALF)0xa4cc42ec, (HALF)0x4e5dbb01, (HALF)0x11d952e7, (HALF)0xb226980f }; STATIC CONST HALF h_nvec02[] = { - (HALF)0x353443f1, (HALF)0xeb286ea9, (HALF)0xdd374a18, (HALF)0x348a2555, - (HALF)0x2c5 + (HALF)0x353443f1, (HALF)0xeb286ea9, (HALF)0xdd374a18, (HALF)0x348a2555, + (HALF)0x2c5 }; STATIC CONST HALF h_rvec02[] = { - (HALF)0x21e3a218, (HALF)0xe893616b, (HALF)0x6cd710e3, (HALF)0xf3d64344, - (HALF)0x40 + (HALF)0x21e3a218, (HALF)0xe893616b, (HALF)0x6cd710e3, (HALF)0xf3d64344, + (HALF)0x40 }; STATIC CONST HALF h_nvec03[] = { - (HALF)0x11d001f1, (HALF)0xf2ca661f, (HALF)0x3a81f1e0, (HALF)0x59d6ce4e, - (HALF)0x0009cfd9 + (HALF)0x11d001f1, (HALF)0xf2ca661f, (HALF)0x3a81f1e0, (HALF)0x59d6ce4e, + (HALF)0x0009cfd9 }; STATIC CONST HALF h_rvec03[] = { - (HALF)0xa0d7d76a, (HALF)0x3e142de2, (HALF)0xff5cea4f, (HALF)0xb44d9b64, - (HALF)0xfae5 + (HALF)0xa0d7d76a, (HALF)0x3e142de2, (HALF)0xff5cea4f, (HALF)0xb44d9b64, + (HALF)0xfae5 }; STATIC CONST HALF h_nvec04[] = { - (HALF)0xdfcc0751, (HALF)0x2decc680, (HALF)0x5df12a1a, (HALF)0x5c894ed7, - (HALF)0x3070f924 + (HALF)0xdfcc0751, (HALF)0x2decc680, (HALF)0x5df12a1a, (HALF)0x5c894ed7, + (HALF)0x3070f924 }; STATIC CONST HALF h_rvec04[] = { - (HALF)0x4b984570, (HALF)0xa220ddba, (HALF)0xa2c0af8a, (HALF)0x131b2bdc, - (HALF)0x0020c2d8 + (HALF)0x4b984570, (HALF)0xa220ddba, (HALF)0xa2c0af8a, (HALF)0x131b2bdc, + (HALF)0x0020c2d8 }; STATIC CONST HALF h_nvec05[] = { - (HALF)0x99166ef1, (HALF)0x8b99e5e7, (HALF)0x8769a010, (HALF)0x5d3fe111, - (HALF)0x680bc2fa, (HALF)0x38f75aac, (HALF)0xdb81a85b, (HALF)0x109b1822, - (HALF)0x2 + (HALF)0x99166ef1, (HALF)0x8b99e5e7, (HALF)0x8769a010, (HALF)0x5d3fe111, + (HALF)0x680bc2fa, (HALF)0x38f75aac, (HALF)0xdb81a85b, (HALF)0x109b1822, + (HALF)0x2 }; STATIC CONST HALF h_rvec05[] = { - (HALF)0x59e2efa9, (HALF)0x0e6c77c8, (HALF)0x1e70aeed, (HALF)0x234f7b7d, - (HALF)0x5f5df6db, (HALF)0xe821a960, (HALF)0xae33b792, (HALF)0x5e9b890e + (HALF)0x59e2efa9, (HALF)0x0e6c77c8, (HALF)0x1e70aeed, (HALF)0x234f7b7d, + (HALF)0x5f5df6db, (HALF)0xe821a960, (HALF)0xae33b792, (HALF)0x5e9b890e }; STATIC CONST HALF h_nvec06[] = { - (HALF)0xe1ddf431, (HALF)0xd85557f1, (HALF)0x5ee732da, (HALF)0x3a38db77, - (HALF)0x5c644026, (HALF)0xf2dbf218, (HALF)0x9ada2c79, (HALF)0x7bfd9d7d, - (HALF)0xa + (HALF)0xe1ddf431, (HALF)0xd85557f1, (HALF)0x5ee732da, (HALF)0x3a38db77, + (HALF)0x5c644026, (HALF)0xf2dbf218, (HALF)0x9ada2c79, (HALF)0x7bfd9d7d, + (HALF)0xa }; STATIC CONST HALF h_rvec06[] = { - (HALF)0xc9404daf, (HALF)0xc5dc2e80, (HALF)0x2c98eccf, (HALF)0xe1f3495d, - (HALF)0xce1c925c, (HALF)0xe097aede, (HALF)0x88667154, (HALF)0x5e94a02f + (HALF)0xc9404daf, (HALF)0xc5dc2e80, (HALF)0x2c98eccf, (HALF)0xe1f3495d, + (HALF)0xce1c925c, (HALF)0xe097aede, (HALF)0x88667154, (HALF)0x5e94a02f }; STATIC CONST HALF h_nvec07[] = { - (HALF)0xcf9ec751, (HALF)0x602f9125, (HALF)0x52882e7f, (HALF)0x0dcf53ce, - (HALF)0xff569d6b, (HALF)0x628643fc, (HALF)0x37801cd5, (HALF)0xf2399ef2, - (HALF)0x43d87de8 + (HALF)0xcf9ec751, (HALF)0x602f9125, (HALF)0x52882e7f, (HALF)0x0dcf53ce, + (HALF)0xff569d6b, (HALF)0x628643fc, (HALF)0x37801cd5, (HALF)0xf2399ef2, + (HALF)0x43d87de8 }; STATIC CONST HALF h_rvec07[] = { - (HALF)0x098d25e6, (HALF)0x3992d2e5, (HALF)0x64f0b58c, (HALF)0xcf18d4dd, - (HALF)0x9d876aef, (HALF)0x7acced04, (HALF)0xbfbe9076, (HALF)0x1ee014c7, - (HALF)0x0013522d + (HALF)0x098d25e6, (HALF)0x3992d2e5, (HALF)0x64f0b58c, (HALF)0xcf18d4dd, + (HALF)0x9d876aef, (HALF)0x7acced04, (HALF)0xbfbe9076, (HALF)0x1ee014c7, + (HALF)0x0013522d }; STATIC CONST HALF h_nvec08[] = { - (HALF)0x26742f11, (HALF)0xbc42e66a, (HALF)0xb59cd9f0, (HALF)0x9ad4a6c2, - (HALF)0x5bdbd2f9, (HALF)0xbdc91fed, (HALF)0xf13c9ce7, (HALF)0xeb4699b7, - (HALF)0x47126ca7, (HALF)0x58 + (HALF)0x26742f11, (HALF)0xbc42e66a, (HALF)0xb59cd9f0, (HALF)0x9ad4a6c2, + (HALF)0x5bdbd2f9, (HALF)0xbdc91fed, (HALF)0xf13c9ce7, (HALF)0xeb4699b7, + (HALF)0x47126ca7, (HALF)0x58 }; STATIC CONST HALF h_rvec08[] = { - (HALF)0x489dc674, (HALF)0xaae95f3a, (HALF)0xa35da929, (HALF)0x5597b4b8, - (HALF)0x28e9c947, (HALF)0x3d344f9a, (HALF)0xb7e661fa, (HALF)0xa3269116, - (HALF)0x853016dc + (HALF)0x489dc674, (HALF)0xaae95f3a, (HALF)0xa35da929, (HALF)0x5597b4b8, + (HALF)0x28e9c947, (HALF)0x3d344f9a, (HALF)0xb7e661fa, (HALF)0xa3269116, + (HALF)0x853016dc }; STATIC CONST HALF h_nvec09[] = { - (HALF)0xab27e3d1, (HALF)0x12745db4, (HALF)0xb980f951, (HALF)0x62b16b66, - (HALF)0x0fdece0d, (HALF)0x6061c6fd, (HALF)0x36a6ff09, (HALF)0xe08eb61c, - (HALF)0x84d895c3, (HALF)0x4a86752a, (HALF)0xc1797b4f, (HALF)0x562157a3, - (HALF)0x3d267bb0, (HALF)0x14e81b00, (HALF)0x218d9238, (HALF)0x52322fd3, - (HALF)0x0039e8be + (HALF)0xab27e3d1, (HALF)0x12745db4, (HALF)0xb980f951, (HALF)0x62b16b66, + (HALF)0x0fdece0d, (HALF)0x6061c6fd, (HALF)0x36a6ff09, (HALF)0xe08eb61c, + (HALF)0x84d895c3, (HALF)0x4a86752a, (HALF)0xc1797b4f, (HALF)0x562157a3, + (HALF)0x3d267bb0, (HALF)0x14e81b00, (HALF)0x218d9238, (HALF)0x52322fd3, + (HALF)0x0039e8be }; STATIC CONST HALF h_rvec09[] = { - (HALF)0x7d4ed20d, (HALF)0x601ef2b8, (HALF)0x8e59f959, (HALF)0xedaa5d9e, - (HALF)0x309a89ba, (HALF)0xe5ab7d81, (HALF)0x796b2545, (HALF)0x02de3222, - (HALF)0x8357c0bd, (HALF)0x0107e3fd, (HALF)0x82d9d288, (HALF)0xbc42a8aa, - (HALF)0x4b787343, (HALF)0xc0150886, (HALF)0xbab915bf, (HALF)0xf8ad1e6b, - (HALF)0xb458 + (HALF)0x7d4ed20d, (HALF)0x601ef2b8, (HALF)0x8e59f959, (HALF)0xedaa5d9e, + (HALF)0x309a89ba, (HALF)0xe5ab7d81, (HALF)0x796b2545, (HALF)0x02de3222, + (HALF)0x8357c0bd, (HALF)0x0107e3fd, (HALF)0x82d9d288, (HALF)0xbc42a8aa, + (HALF)0x4b787343, (HALF)0xc0150886, (HALF)0xbab915bf, (HALF)0xf8ad1e6b, + (HALF)0xb458 }; STATIC CONST HALF h_nvec10[] = { - (HALF)0xb7e64b89, (HALF)0xc3cdc363, (HALF)0x2ef9c73c, (HALF)0x6092ce22, - (HALF)0x02abe36c, (HALF)0x08d49573, (HALF)0x74511c40, (HALF)0xd38582de, - (HALF)0xa524a02f, (HALF)0x52c81b3b, (HALF)0x250d3cc9, (HALF)0x23b50e88, - (HALF)0xbd1448bf, (HALF)0x882d7f98, (HALF)0xc23ef596, (HALF)0xc9055666, - (HALF)0x025f2435 + (HALF)0xb7e64b89, (HALF)0xc3cdc363, (HALF)0x2ef9c73c, (HALF)0x6092ce22, + (HALF)0x02abe36c, (HALF)0x08d49573, (HALF)0x74511c40, (HALF)0xd38582de, + (HALF)0xa524a02f, (HALF)0x52c81b3b, (HALF)0x250d3cc9, (HALF)0x23b50e88, + (HALF)0xbd1448bf, (HALF)0x882d7f98, (HALF)0xc23ef596, (HALF)0xc9055666, + (HALF)0x025f2435 }; STATIC CONST HALF h_rvec10[] = { - (HALF)0x94cfc482, (HALF)0x594f5ad4, (HALF)0x23442aee, (HALF)0x145f40ce, - (HALF)0x1baf950d, (HALF)0xadc4f175, (HALF)0xf62c669f, (HALF)0x8d075d56, - (HALF)0x08ed8b40, (HALF)0xaaf2cf30, (HALF)0xc24b5ffb, (HALF)0x250df8cf, - (HALF)0x7ca81ec9, (HALF)0x787e2b70, (HALF)0x18401468, (HALF)0x47b20e0c, - (HALF)0x0066bb7e + (HALF)0x94cfc482, (HALF)0x594f5ad4, (HALF)0x23442aee, (HALF)0x145f40ce, + (HALF)0x1baf950d, (HALF)0xadc4f175, (HALF)0xf62c669f, (HALF)0x8d075d56, + (HALF)0x08ed8b40, (HALF)0xaaf2cf30, (HALF)0xc24b5ffb, (HALF)0x250df8cf, + (HALF)0x7ca81ec9, (HALF)0x787e2b70, (HALF)0x18401468, (HALF)0x47b20e0c, + (HALF)0x0066bb7e }; STATIC CONST HALF h_nvec11[] = { - (HALF)0x546ee069, (HALF)0x2e1a530c, (HALF)0x2014dab2, (HALF)0xa729cf52, - (HALF)0x920ee1a9, (HALF)0x68f27533, (HALF)0x25873cfa, (HALF)0xdd37a749, - (HALF)0x4499daa2, (HALF)0x286e5870, (HALF)0x57f3f9b6, (HALF)0x5ec54467, - (HALF)0x69a791ea, (HALF)0x874ecd77, (HALF)0x4217d56b, (HALF)0x82bdb309, - (HALF)0x497864de + (HALF)0x546ee069, (HALF)0x2e1a530c, (HALF)0x2014dab2, (HALF)0xa729cf52, + (HALF)0x920ee1a9, (HALF)0x68f27533, (HALF)0x25873cfa, (HALF)0xdd37a749, + (HALF)0x4499daa2, (HALF)0x286e5870, (HALF)0x57f3f9b6, (HALF)0x5ec54467, + (HALF)0x69a791ea, (HALF)0x874ecd77, (HALF)0x4217d56b, (HALF)0x82bdb309, + (HALF)0x497864de }; STATIC CONST HALF h_rvec11[] = { - (HALF)0x56e38b04, (HALF)0x3a0aded3, (HALF)0x461d88b1, (HALF)0x9c094d65, - (HALF)0xe5333fed, (HALF)0x34d918fe, (HALF)0x1ef56281, (HALF)0xcedfa07c, - (HALF)0x590f47fb, (HALF)0xa2c54d5c, (HALF)0x732339ee, (HALF)0x806549a7, - (HALF)0x9ce3163f, (HALF)0xae3af8b6, (HALF)0x264a4465, (HALF)0x1cb5e630, - (HALF)0x00868488 + (HALF)0x56e38b04, (HALF)0x3a0aded3, (HALF)0x461d88b1, (HALF)0x9c094d65, + (HALF)0xe5333fed, (HALF)0x34d918fe, (HALF)0x1ef56281, (HALF)0xcedfa07c, + (HALF)0x590f47fb, (HALF)0xa2c54d5c, (HALF)0x732339ee, (HALF)0x806549a7, + (HALF)0x9ce3163f, (HALF)0xae3af8b6, (HALF)0x264a4465, (HALF)0x1cb5e630, + (HALF)0x00868488 }; STATIC CONST HALF h_nvec12[] = { - (HALF)0xf14c7b99, (HALF)0x7f66d151, (HALF)0x87efad2b, (HALF)0x57d3f098, - (HALF)0xd6534165, (HALF)0x812fdd25, (HALF)0x48c7c7ce, (HALF)0xa1bf41e0, - (HALF)0x4c94e315, (HALF)0x190b1593, (HALF)0xee4251da, (HALF)0x2b4a1a66, - (HALF)0x2bb7c2a1, (HALF)0x65b18ca9, (HALF)0x08b89116, (HALF)0xc0ccb15f, - (HALF)0x57582ab3, (HALF)0x34 + (HALF)0xf14c7b99, (HALF)0x7f66d151, (HALF)0x87efad2b, (HALF)0x57d3f098, + (HALF)0xd6534165, (HALF)0x812fdd25, (HALF)0x48c7c7ce, (HALF)0xa1bf41e0, + (HALF)0x4c94e315, (HALF)0x190b1593, (HALF)0xee4251da, (HALF)0x2b4a1a66, + (HALF)0x2bb7c2a1, (HALF)0x65b18ca9, (HALF)0x08b89116, (HALF)0xc0ccb15f, + (HALF)0x57582ab3, (HALF)0x34 }; STATIC CONST HALF h_rvec12[] = { - (HALF)0xe207b4a0, (HALF)0x5227dd68, (HALF)0x9488fbc4, (HALF)0x6ed081aa, - (HALF)0x8e736fe5, (HALF)0x3dd2c020, (HALF)0xeeb07c57, (HALF)0x0b604eb7, - (HALF)0xa13f72a1, (HALF)0xcbfc4333, (HALF)0xa4c5e8cd, (HALF)0x0add520d, - (HALF)0x758ca3b2, (HALF)0x55490137, (HALF)0x5870babd, (HALF)0xf648ed93, - (HALF)0xdf719bd1 + (HALF)0xe207b4a0, (HALF)0x5227dd68, (HALF)0x9488fbc4, (HALF)0x6ed081aa, + (HALF)0x8e736fe5, (HALF)0x3dd2c020, (HALF)0xeeb07c57, (HALF)0x0b604eb7, + (HALF)0xa13f72a1, (HALF)0xcbfc4333, (HALF)0xa4c5e8cd, (HALF)0x0add520d, + (HALF)0x758ca3b2, (HALF)0x55490137, (HALF)0x5870babd, (HALF)0xf648ed93, + (HALF)0xdf719bd1 }; STATIC CONST HALF h_nvec13[] = { - (HALF)0x3314fc49, (HALF)0xcca20032, (HALF)0x208e3420, (HALF)0x8aaa503a, - (HALF)0xd79a63cc, (HALF)0xb4ed7417, (HALF)0x95dd1892, (HALF)0xb5915f64, - (HALF)0xd14cc7f1, (HALF)0x1589917e, (HALF)0xb2b05667, (HALF)0xc32d99cb, - (HALF)0x1b5a1a84, (HALF)0xa49322a1, (HALF)0xdd3a76c3, (HALF)0x8c07137f, - (HALF)0xaaf83c63, (HALF)0x37575113, (HALF)0xa8b18e84, (HALF)0xceec891d, - (HALF)0x78c1ee99, (HALF)0x6e49e256, (HALF)0x4286bfd6, (HALF)0xcb6bf6a9, - (HALF)0x7bda8ee0, (HALF)0xd439510a, (HALF)0x63f4345b, (HALF)0x959a5535, - (HALF)0xdaf66d82, (HALF)0xed03d833, (HALF)0x1b5af734, (HALF)0x166b7dd2, - (HALF)0x01517c19 + (HALF)0x3314fc49, (HALF)0xcca20032, (HALF)0x208e3420, (HALF)0x8aaa503a, + (HALF)0xd79a63cc, (HALF)0xb4ed7417, (HALF)0x95dd1892, (HALF)0xb5915f64, + (HALF)0xd14cc7f1, (HALF)0x1589917e, (HALF)0xb2b05667, (HALF)0xc32d99cb, + (HALF)0x1b5a1a84, (HALF)0xa49322a1, (HALF)0xdd3a76c3, (HALF)0x8c07137f, + (HALF)0xaaf83c63, (HALF)0x37575113, (HALF)0xa8b18e84, (HALF)0xceec891d, + (HALF)0x78c1ee99, (HALF)0x6e49e256, (HALF)0x4286bfd6, (HALF)0xcb6bf6a9, + (HALF)0x7bda8ee0, (HALF)0xd439510a, (HALF)0x63f4345b, (HALF)0x959a5535, + (HALF)0xdaf66d82, (HALF)0xed03d833, (HALF)0x1b5af734, (HALF)0x166b7dd2, + (HALF)0x01517c19 }; STATIC CONST HALF h_rvec13[] = { - (HALF)0x6b7736f5, (HALF)0x2407bfe4, (HALF)0x965e2072, (HALF)0xcc26cf3e, - (HALF)0xa432b567, (HALF)0x2ed007ab, (HALF)0x0e2f67b9, (HALF)0xef640960, - (HALF)0xbe5f1ad3, (HALF)0x3faeda1b, (HALF)0xa8f6b988, (HALF)0xe5c9cea5, - (HALF)0xa67445ea, (HALF)0x3935ce78, (HALF)0xf445ff06, (HALF)0xbeda0a11, - (HALF)0x92de080b, (HALF)0xf4049026, (HALF)0xe509f0b8, (HALF)0x6f05216f, - (HALF)0x5a68dc14, (HALF)0x548f730d, (HALF)0xe9fd9f00, (HALF)0x64a4aada, - (HALF)0xe3bbdd15, (HALF)0xcb4be7a5, (HALF)0x17ddd162, (HALF)0xc4918c33, - (HALF)0x9b706d2b, (HALF)0x8b04f6a6, (HALF)0x1263fa64, (HALF)0x8e9a560d, - (HALF)0xd42e + (HALF)0x6b7736f5, (HALF)0x2407bfe4, (HALF)0x965e2072, (HALF)0xcc26cf3e, + (HALF)0xa432b567, (HALF)0x2ed007ab, (HALF)0x0e2f67b9, (HALF)0xef640960, + (HALF)0xbe5f1ad3, (HALF)0x3faeda1b, (HALF)0xa8f6b988, (HALF)0xe5c9cea5, + (HALF)0xa67445ea, (HALF)0x3935ce78, (HALF)0xf445ff06, (HALF)0xbeda0a11, + (HALF)0x92de080b, (HALF)0xf4049026, (HALF)0xe509f0b8, (HALF)0x6f05216f, + (HALF)0x5a68dc14, (HALF)0x548f730d, (HALF)0xe9fd9f00, (HALF)0x64a4aada, + (HALF)0xe3bbdd15, (HALF)0xcb4be7a5, (HALF)0x17ddd162, (HALF)0xc4918c33, + (HALF)0x9b706d2b, (HALF)0x8b04f6a6, (HALF)0x1263fa64, (HALF)0x8e9a560d, + (HALF)0xd42e }; STATIC CONST HALF h_nvec14[] = { - (HALF)0xc116af01, (HALF)0xbdef8c0f, (HALF)0xc4409a1a, (HALF)0xacb3185c, - (HALF)0xb33f925b, (HALF)0xfee83005, (HALF)0x4b3db112, (HALF)0x7f076743, - (HALF)0x21709223, (HALF)0x2159054b, (HALF)0x6fdfefe3, (HALF)0x792d0a07, - (HALF)0x1d14bd52, (HALF)0x5f289a27, (HALF)0xe03483c4, (HALF)0xcb86a0c1, - (HALF)0x0ede912a, (HALF)0xf01a33e3, (HALF)0x63fd40c6, (HALF)0x4b0586e4, - (HALF)0xbc7e4a03, (HALF)0x956b22f3, (HALF)0x10560b22, (HALF)0x3e78d321, - (HALF)0x179161e2, (HALF)0xe85eb909, (HALF)0xec7931ee, (HALF)0xb314b4bf, - (HALF)0x1f564618, (HALF)0xb9d983d0, (HALF)0x7479ac07, (HALF)0x93c6f4e8, - (HALF)0x5e56a00e + (HALF)0xc116af01, (HALF)0xbdef8c0f, (HALF)0xc4409a1a, (HALF)0xacb3185c, + (HALF)0xb33f925b, (HALF)0xfee83005, (HALF)0x4b3db112, (HALF)0x7f076743, + (HALF)0x21709223, (HALF)0x2159054b, (HALF)0x6fdfefe3, (HALF)0x792d0a07, + (HALF)0x1d14bd52, (HALF)0x5f289a27, (HALF)0xe03483c4, (HALF)0xcb86a0c1, + (HALF)0x0ede912a, (HALF)0xf01a33e3, (HALF)0x63fd40c6, (HALF)0x4b0586e4, + (HALF)0xbc7e4a03, (HALF)0x956b22f3, (HALF)0x10560b22, (HALF)0x3e78d321, + (HALF)0x179161e2, (HALF)0xe85eb909, (HALF)0xec7931ee, (HALF)0xb314b4bf, + (HALF)0x1f564618, (HALF)0xb9d983d0, (HALF)0x7479ac07, (HALF)0x93c6f4e8, + (HALF)0x5e56a00e }; STATIC CONST HALF h_rvec14[] = { - (HALF)0x0ff9f190, (HALF)0x47a4db68, (HALF)0x913cc8ea, (HALF)0xb6b1b220, - (HALF)0x13edfbbb, (HALF)0xa8f1f1c3, (HALF)0xd6d71f8f, (HALF)0x4194649a, - (HALF)0x7d497344, (HALF)0x677c8416, (HALF)0x0186b983, (HALF)0xee633901, - (HALF)0xce64d69d, (HALF)0x61a704b3, (HALF)0x138352b2, (HALF)0xc0fb58d8, - (HALF)0x16bf2073, (HALF)0x56c9ae78, (HALF)0xb81a0a68, (HALF)0x1512abaf, - (HALF)0x6b9936ba, (HALF)0x43350dfc, (HALF)0xa0ea19d2, (HALF)0xe86134c5, - (HALF)0x6c86563f, (HALF)0x6b0c5b68, (HALF)0x75f627fc, (HALF)0xb609913f, - (HALF)0x15b9a564, (HALF)0x9b18f154, (HALF)0x6ef0c5d0, (HALF)0xb6733509, - (HALF)0x00f7aa7c + (HALF)0x0ff9f190, (HALF)0x47a4db68, (HALF)0x913cc8ea, (HALF)0xb6b1b220, + (HALF)0x13edfbbb, (HALF)0xa8f1f1c3, (HALF)0xd6d71f8f, (HALF)0x4194649a, + (HALF)0x7d497344, (HALF)0x677c8416, (HALF)0x0186b983, (HALF)0xee633901, + (HALF)0xce64d69d, (HALF)0x61a704b3, (HALF)0x138352b2, (HALF)0xc0fb58d8, + (HALF)0x16bf2073, (HALF)0x56c9ae78, (HALF)0xb81a0a68, (HALF)0x1512abaf, + (HALF)0x6b9936ba, (HALF)0x43350dfc, (HALF)0xa0ea19d2, (HALF)0xe86134c5, + (HALF)0x6c86563f, (HALF)0x6b0c5b68, (HALF)0x75f627fc, (HALF)0xb609913f, + (HALF)0x15b9a564, (HALF)0x9b18f154, (HALF)0x6ef0c5d0, (HALF)0xb6733509, + (HALF)0x00f7aa7c }; STATIC CONST HALF h_nvec15[] = { - (HALF)0xc8d97079, (HALF)0x061e7597, (HALF)0xf5d2c721, (HALF)0x299bc51f, - (HALF)0xffe6c337, (HALF)0x19798624, (HALF)0xee6f92b6, (HALF)0x0b1d0c7a, - (HALF)0xb5308231, (HALF)0x49c558dd, (HALF)0x196a530e, (HALF)0x0caa515c, - (HALF)0x8b0d86ed, (HALF)0x380a8fa0, (HALF)0x80df03e4, (HALF)0xe962d81b, - (HALF)0xc1a783b3, (HALF)0xc3278ccc, (HALF)0x3e72ab86, (HALF)0xebb91675, - (HALF)0xb902c2b8, (HALF)0xa0590445, (HALF)0x4f40de42, (HALF)0xaa95aac1, - (HALF)0xfc0f2e82, (HALF)0x70cab84b, (HALF)0x5326a267, (HALF)0x470be607, - (HALF)0x45352ebe, (HALF)0x5ba81ca8, (HALF)0x02c46c17, (HALF)0x9edfbcdb, - (HALF)0x97dd840b + (HALF)0xc8d97079, (HALF)0x061e7597, (HALF)0xf5d2c721, (HALF)0x299bc51f, + (HALF)0xffe6c337, (HALF)0x19798624, (HALF)0xee6f92b6, (HALF)0x0b1d0c7a, + (HALF)0xb5308231, (HALF)0x49c558dd, (HALF)0x196a530e, (HALF)0x0caa515c, + (HALF)0x8b0d86ed, (HALF)0x380a8fa0, (HALF)0x80df03e4, (HALF)0xe962d81b, + (HALF)0xc1a783b3, (HALF)0xc3278ccc, (HALF)0x3e72ab86, (HALF)0xebb91675, + (HALF)0xb902c2b8, (HALF)0xa0590445, (HALF)0x4f40de42, (HALF)0xaa95aac1, + (HALF)0xfc0f2e82, (HALF)0x70cab84b, (HALF)0x5326a267, (HALF)0x470be607, + (HALF)0x45352ebe, (HALF)0x5ba81ca8, (HALF)0x02c46c17, (HALF)0x9edfbcdb, + (HALF)0x97dd840b }; STATIC CONST HALF h_rvec15[] = { - (HALF)0x6c3e2110, (HALF)0x808f0aaa, (HALF)0xd98db92e, (HALF)0x1e6abd43, - (HALF)0xf401b920, (HALF)0x9d3f0381, (HALF)0xdb95d174, (HALF)0xa2f65c33, - (HALF)0x0c5469f8, (HALF)0xa3c126fc, (HALF)0x8866241b, (HALF)0x0e46eca7, - (HALF)0xa70557fa, (HALF)0x8e7391a6, (HALF)0x70e4a9e2, (HALF)0x9ad97e89, - (HALF)0x1eb77dee, (HALF)0xfe6224d0, (HALF)0xdbe522b1, (HALF)0xa4aa1023, - (HALF)0x7f226860, (HALF)0x60ef4379, (HALF)0x45e3b296, (HALF)0xcc31f5ef, - (HALF)0x74fbf6d6, (HALF)0x55b1c25d, (HALF)0x3ede521f, (HALF)0xdf8cef42, - (HALF)0xa8d77ca6, (HALF)0xb50025da, (HALF)0x69ab99f9, (HALF)0x03b8c758, - (HALF)0x00b82207 + (HALF)0x6c3e2110, (HALF)0x808f0aaa, (HALF)0xd98db92e, (HALF)0x1e6abd43, + (HALF)0xf401b920, (HALF)0x9d3f0381, (HALF)0xdb95d174, (HALF)0xa2f65c33, + (HALF)0x0c5469f8, (HALF)0xa3c126fc, (HALF)0x8866241b, (HALF)0x0e46eca7, + (HALF)0xa70557fa, (HALF)0x8e7391a6, (HALF)0x70e4a9e2, (HALF)0x9ad97e89, + (HALF)0x1eb77dee, (HALF)0xfe6224d0, (HALF)0xdbe522b1, (HALF)0xa4aa1023, + (HALF)0x7f226860, (HALF)0x60ef4379, (HALF)0x45e3b296, (HALF)0xcc31f5ef, + (HALF)0x74fbf6d6, (HALF)0x55b1c25d, (HALF)0x3ede521f, (HALF)0xdf8cef42, + (HALF)0xa8d77ca6, (HALF)0xb50025da, (HALF)0x69ab99f9, (HALF)0x03b8c758, + (HALF)0x00b82207 }; STATIC CONST HALF h_nvec16[] = { - (HALF)0xd84346e1, (HALF)0x184183f6, (HALF)0x2dc9bd36, (HALF)0x4ca857ac, - (HALF)0x96a5828d, (HALF)0xed1f1c59, (HALF)0x36d9731f, (HALF)0xbd3f6183, - (HALF)0xde0f5578, (HALF)0xb6a2ea8a, (HALF)0xbe993c44, (HALF)0x0e283c05, - (HALF)0xd7cf61e3, (HALF)0x40fe15b6, (HALF)0x534d967e, (HALF)0x34691046, - (HALF)0xd40845bd, (HALF)0xd69cee4b, (HALF)0x557fee8d, (HALF)0x51c856ba, - (HALF)0xe6bc51ba, (HALF)0x587bc173, (HALF)0x1959e379, (HALF)0x92828439, - (HALF)0x311e0503, (HALF)0x7f3c9cc2, (HALF)0xd426512c, (HALF)0xe8b2b497, - (HALF)0x9e43536a, (HALF)0x9f544cb8, (HALF)0xb56f84c3, (HALF)0xb82fbb12, - (HALF)0x6e348549, (HALF)0x45 + (HALF)0xd84346e1, (HALF)0x184183f6, (HALF)0x2dc9bd36, (HALF)0x4ca857ac, + (HALF)0x96a5828d, (HALF)0xed1f1c59, (HALF)0x36d9731f, (HALF)0xbd3f6183, + (HALF)0xde0f5578, (HALF)0xb6a2ea8a, (HALF)0xbe993c44, (HALF)0x0e283c05, + (HALF)0xd7cf61e3, (HALF)0x40fe15b6, (HALF)0x534d967e, (HALF)0x34691046, + (HALF)0xd40845bd, (HALF)0xd69cee4b, (HALF)0x557fee8d, (HALF)0x51c856ba, + (HALF)0xe6bc51ba, (HALF)0x587bc173, (HALF)0x1959e379, (HALF)0x92828439, + (HALF)0x311e0503, (HALF)0x7f3c9cc2, (HALF)0xd426512c, (HALF)0xe8b2b497, + (HALF)0x9e43536a, (HALF)0x9f544cb8, (HALF)0xb56f84c3, (HALF)0xb82fbb12, + (HALF)0x6e348549, (HALF)0x45 }; STATIC CONST HALF h_rvec16[] = { - (HALF)0x7b4e8830, (HALF)0x70605db8, (HALF)0xa1abe4a5, (HALF)0xa70fbe04, - (HALF)0x2bcda8f4, (HALF)0xd29ada9a, (HALF)0x55ad0560, (HALF)0xb367137e, - (HALF)0xd6972f1a, (HALF)0x809bad45, (HALF)0xb15d2454, (HALF)0x0c0d415f, - (HALF)0x416e117a, (HALF)0xe87a9521, (HALF)0x670a5e1a, (HALF)0x53a41772, - (HALF)0xfc9c5cc1, (HALF)0xf75645df, (HALF)0x86f6d19f, (HALF)0x9404b5bf, - (HALF)0x56e9d83b, (HALF)0xac0f3bc3, (HALF)0xa1508c4b, (HALF)0x4bfd4977, - (HALF)0x71922540, (HALF)0xf2524def, (HALF)0x8a81a3db, (HALF)0xced828de, - (HALF)0x7895ae8f, (HALF)0x4a4b6dcd, (HALF)0x973e921a, (HALF)0x9fb27a07, - (HALF)0xb0d7dcb1 + (HALF)0x7b4e8830, (HALF)0x70605db8, (HALF)0xa1abe4a5, (HALF)0xa70fbe04, + (HALF)0x2bcda8f4, (HALF)0xd29ada9a, (HALF)0x55ad0560, (HALF)0xb367137e, + (HALF)0xd6972f1a, (HALF)0x809bad45, (HALF)0xb15d2454, (HALF)0x0c0d415f, + (HALF)0x416e117a, (HALF)0xe87a9521, (HALF)0x670a5e1a, (HALF)0x53a41772, + (HALF)0xfc9c5cc1, (HALF)0xf75645df, (HALF)0x86f6d19f, (HALF)0x9404b5bf, + (HALF)0x56e9d83b, (HALF)0xac0f3bc3, (HALF)0xa1508c4b, (HALF)0x4bfd4977, + (HALF)0x71922540, (HALF)0xf2524def, (HALF)0x8a81a3db, (HALF)0xced828de, + (HALF)0x7895ae8f, (HALF)0x4a4b6dcd, (HALF)0x973e921a, (HALF)0x9fb27a07, + (HALF)0xb0d7dcb1 }; STATIC CONST HALF h_nvec17[] = { - (HALF)0x72b72051, (HALF)0xedc24ebf, (HALF)0xe970a8d1, (HALF)0x66c9b150, - (HALF)0xcbb927f7, (HALF)0xb574ffd9, (HALF)0x4166b249, (HALF)0x0fce4030, - (HALF)0xfa6922ca, (HALF)0x39cc14a9, (HALF)0x14396e2a, (HALF)0xaff74c7f, - (HALF)0xa120a314, (HALF)0xe11a2700, (HALF)0x44c9ad30, (HALF)0x7f328d72, - (HALF)0xab2ceaf7, (HALF)0x868ff772, (HALF)0x0974f0b3, (HALF)0x20e9f0f6, - (HALF)0xcd4e5b8a, (HALF)0x0bde26e6, (HALF)0x96f6c3ac, (HALF)0x5718c601, - (HALF)0x2f117710, (HALF)0x1ab0876e, (HALF)0x49ab2c2e, (HALF)0x747022b9, - (HALF)0x6e9de4a7, (HALF)0x25e88f2e, (HALF)0xd7d0a00b, (HALF)0xc8ff11f6, - (HALF)0xf50aa819, (HALF)0xbe530e9e, (HALF)0x47b7ff54, (HALF)0xe0209b46, - (HALF)0x027ec5eb, (HALF)0x07543362, (HALF)0x531e9b85, (HALF)0x3c23b568, - (HALF)0x5d07af7a, (HALF)0xd4948461, (HALF)0x2eb9a499, (HALF)0x1c71fa0b, - (HALF)0x7025e22b, (HALF)0x4d2720b9, (HALF)0x531b8d54, (HALF)0x66e2fc30, - (HALF)0xdac7cafd, (HALF)0x7f29953b, (HALF)0x9d456bff, (HALF)0x839814bc, - (HALF)0xd0e5fb19, (HALF)0x5a6c9f58, (HALF)0x3a5a9dc3, (HALF)0x598bf28b, - (HALF)0xa7a91144, (HALF)0x68494f76, (HALF)0xbfedd7be, (HALF)0x7ca54266, - (HALF)0x96e0faf9, (HALF)0x33be3c0f, (HALF)0xffa3040b, (HALF)0x813aeac0, - (HALF)0x6177 + (HALF)0x72b72051, (HALF)0xedc24ebf, (HALF)0xe970a8d1, (HALF)0x66c9b150, + (HALF)0xcbb927f7, (HALF)0xb574ffd9, (HALF)0x4166b249, (HALF)0x0fce4030, + (HALF)0xfa6922ca, (HALF)0x39cc14a9, (HALF)0x14396e2a, (HALF)0xaff74c7f, + (HALF)0xa120a314, (HALF)0xe11a2700, (HALF)0x44c9ad30, (HALF)0x7f328d72, + (HALF)0xab2ceaf7, (HALF)0x868ff772, (HALF)0x0974f0b3, (HALF)0x20e9f0f6, + (HALF)0xcd4e5b8a, (HALF)0x0bde26e6, (HALF)0x96f6c3ac, (HALF)0x5718c601, + (HALF)0x2f117710, (HALF)0x1ab0876e, (HALF)0x49ab2c2e, (HALF)0x747022b9, + (HALF)0x6e9de4a7, (HALF)0x25e88f2e, (HALF)0xd7d0a00b, (HALF)0xc8ff11f6, + (HALF)0xf50aa819, (HALF)0xbe530e9e, (HALF)0x47b7ff54, (HALF)0xe0209b46, + (HALF)0x027ec5eb, (HALF)0x07543362, (HALF)0x531e9b85, (HALF)0x3c23b568, + (HALF)0x5d07af7a, (HALF)0xd4948461, (HALF)0x2eb9a499, (HALF)0x1c71fa0b, + (HALF)0x7025e22b, (HALF)0x4d2720b9, (HALF)0x531b8d54, (HALF)0x66e2fc30, + (HALF)0xdac7cafd, (HALF)0x7f29953b, (HALF)0x9d456bff, (HALF)0x839814bc, + (HALF)0xd0e5fb19, (HALF)0x5a6c9f58, (HALF)0x3a5a9dc3, (HALF)0x598bf28b, + (HALF)0xa7a91144, (HALF)0x68494f76, (HALF)0xbfedd7be, (HALF)0x7ca54266, + (HALF)0x96e0faf9, (HALF)0x33be3c0f, (HALF)0xffa3040b, (HALF)0x813aeac0, + (HALF)0x6177 }; STATIC CONST HALF h_rvec17[] = { - (HALF)0x22b41dac, (HALF)0xd6258005, (HALF)0x2aa1e0cb, (HALF)0x45d147b5, - (HALF)0xbf5c46d9, (HALF)0x14c9dadf, (HALF)0x09b0aec4, (HALF)0x4286bfef, - (HALF)0xc6f8e9d1, (HALF)0xdd68467b, (HALF)0x93f4ffb9, (HALF)0x58f2eb51, - (HALF)0x2ade048f, (HALF)0xeacae6e5, (HALF)0x8dd2a807, (HALF)0xbcea8c27, - (HALF)0x02a03281, (HALF)0x039aeb6d, (HALF)0xfa6e016c, (HALF)0x6fda1b09, - (HALF)0xea7719ed, (HALF)0xcf2e0294, (HALF)0xa4264cb9, (HALF)0x49888af1, - (HALF)0x1b44f0c1, (HALF)0x3ccee577, (HALF)0xdbebd170, (HALF)0xf7431e7e, - (HALF)0xfaebd584, (HALF)0x896e4a33, (HALF)0xe46bf43c, (HALF)0x17fe9a10, - (HALF)0xb5321b51, (HALF)0xf7e1d2a9, (HALF)0xe7fe0a56, (HALF)0xbd736750, - (HALF)0xcf029a33, (HALF)0xebee99b1, (HALF)0x810fff31, (HALF)0x694c8d30, - (HALF)0xc8c18689, (HALF)0xc2f9f4fb, (HALF)0x5949fd7f, (HALF)0x67aaf7b3, - (HALF)0xa82f906a, (HALF)0x1b84b7b3, (HALF)0xeac052ee, (HALF)0x1a4e9345, - (HALF)0xce3c2973, (HALF)0x4a5168a7, (HALF)0x5c5551ba, (HALF)0x77c6cb26, - (HALF)0xfa45a3a6, (HALF)0x486f31e0, (HALF)0xcaf97519, (HALF)0xbe4b0399, - (HALF)0x802fc106, (HALF)0x537284da, (HALF)0x20c4e167, (HALF)0x2a62f329, - (HALF)0xc2d2fc5b, (HALF)0xdd665324, (HALF)0xc3b8adf1, (HALF)0x0b6eaf3b, - (HALF)0x5372 + (HALF)0x22b41dac, (HALF)0xd6258005, (HALF)0x2aa1e0cb, (HALF)0x45d147b5, + (HALF)0xbf5c46d9, (HALF)0x14c9dadf, (HALF)0x09b0aec4, (HALF)0x4286bfef, + (HALF)0xc6f8e9d1, (HALF)0xdd68467b, (HALF)0x93f4ffb9, (HALF)0x58f2eb51, + (HALF)0x2ade048f, (HALF)0xeacae6e5, (HALF)0x8dd2a807, (HALF)0xbcea8c27, + (HALF)0x02a03281, (HALF)0x039aeb6d, (HALF)0xfa6e016c, (HALF)0x6fda1b09, + (HALF)0xea7719ed, (HALF)0xcf2e0294, (HALF)0xa4264cb9, (HALF)0x49888af1, + (HALF)0x1b44f0c1, (HALF)0x3ccee577, (HALF)0xdbebd170, (HALF)0xf7431e7e, + (HALF)0xfaebd584, (HALF)0x896e4a33, (HALF)0xe46bf43c, (HALF)0x17fe9a10, + (HALF)0xb5321b51, (HALF)0xf7e1d2a9, (HALF)0xe7fe0a56, (HALF)0xbd736750, + (HALF)0xcf029a33, (HALF)0xebee99b1, (HALF)0x810fff31, (HALF)0x694c8d30, + (HALF)0xc8c18689, (HALF)0xc2f9f4fb, (HALF)0x5949fd7f, (HALF)0x67aaf7b3, + (HALF)0xa82f906a, (HALF)0x1b84b7b3, (HALF)0xeac052ee, (HALF)0x1a4e9345, + (HALF)0xce3c2973, (HALF)0x4a5168a7, (HALF)0x5c5551ba, (HALF)0x77c6cb26, + (HALF)0xfa45a3a6, (HALF)0x486f31e0, (HALF)0xcaf97519, (HALF)0xbe4b0399, + (HALF)0x802fc106, (HALF)0x537284da, (HALF)0x20c4e167, (HALF)0x2a62f329, + (HALF)0xc2d2fc5b, (HALF)0xdd665324, (HALF)0xc3b8adf1, (HALF)0x0b6eaf3b, + (HALF)0x5372 }; STATIC CONST HALF h_nvec18[] = { - (HALF)0xc8b78629, (HALF)0x41351b18, (HALF)0x28ad4ed8, (HALF)0xc96f7df1, - (HALF)0x7cd3c931, (HALF)0x0f23036a, (HALF)0xac657631, (HALF)0x6a625812, - (HALF)0x08144788, (HALF)0x8642ed62, (HALF)0x76198a40, (HALF)0x70defd64, - (HALF)0x97fb673c, (HALF)0x6f3bddf6, (HALF)0x72fe2977, (HALF)0x20ed82f1, - (HALF)0x7e7f4fdc, (HALF)0xdc272d6b, (HALF)0x6d77f317, (HALF)0x2c595b15, - (HALF)0x1c3b7dd6, (HALF)0x6e3d6147, (HALF)0x8170640c, (HALF)0xb660033f, - (HALF)0xf211886b, (HALF)0xbcc67859, (HALF)0x18ff4b93, (HALF)0x3068e691, - (HALF)0x9db5d823, (HALF)0x72afd4ef, (HALF)0x5aa4cd1a, (HALF)0xa0a33014, - (HALF)0x6b8349e6, (HALF)0x2f4de595, (HALF)0xd5180384, (HALF)0x19d94118, - (HALF)0x369e7534, (HALF)0xce4d3b18, (HALF)0x119ef9ee, (HALF)0xe2f45c25, - (HALF)0xe8eae0a7, (HALF)0x62e41605, (HALF)0x6346d2ca, (HALF)0x6425625b, - (HALF)0x44b033de, (HALF)0x1711e6b3, (HALF)0xf3a9d02e, (HALF)0x259cd965, - (HALF)0x08aa956b, (HALF)0x6ad64380, (HALF)0xe9730e8e, (HALF)0x539b9d28, - (HALF)0xe5407950, (HALF)0x89900be4, (HALF)0xde1218f6, (HALF)0x63e1e52b, - (HALF)0x0de03f4e, (HALF)0x8e21a568, (HALF)0x268d7ee3, (HALF)0xafb3514e, - (HALF)0x5378efcb, (HALF)0xfec0c7c6, (HALF)0xf07cb724, (HALF)0xfb61b42a, - (HALF)0x068f2a38 + (HALF)0xc8b78629, (HALF)0x41351b18, (HALF)0x28ad4ed8, (HALF)0xc96f7df1, + (HALF)0x7cd3c931, (HALF)0x0f23036a, (HALF)0xac657631, (HALF)0x6a625812, + (HALF)0x08144788, (HALF)0x8642ed62, (HALF)0x76198a40, (HALF)0x70defd64, + (HALF)0x97fb673c, (HALF)0x6f3bddf6, (HALF)0x72fe2977, (HALF)0x20ed82f1, + (HALF)0x7e7f4fdc, (HALF)0xdc272d6b, (HALF)0x6d77f317, (HALF)0x2c595b15, + (HALF)0x1c3b7dd6, (HALF)0x6e3d6147, (HALF)0x8170640c, (HALF)0xb660033f, + (HALF)0xf211886b, (HALF)0xbcc67859, (HALF)0x18ff4b93, (HALF)0x3068e691, + (HALF)0x9db5d823, (HALF)0x72afd4ef, (HALF)0x5aa4cd1a, (HALF)0xa0a33014, + (HALF)0x6b8349e6, (HALF)0x2f4de595, (HALF)0xd5180384, (HALF)0x19d94118, + (HALF)0x369e7534, (HALF)0xce4d3b18, (HALF)0x119ef9ee, (HALF)0xe2f45c25, + (HALF)0xe8eae0a7, (HALF)0x62e41605, (HALF)0x6346d2ca, (HALF)0x6425625b, + (HALF)0x44b033de, (HALF)0x1711e6b3, (HALF)0xf3a9d02e, (HALF)0x259cd965, + (HALF)0x08aa956b, (HALF)0x6ad64380, (HALF)0xe9730e8e, (HALF)0x539b9d28, + (HALF)0xe5407950, (HALF)0x89900be4, (HALF)0xde1218f6, (HALF)0x63e1e52b, + (HALF)0x0de03f4e, (HALF)0x8e21a568, (HALF)0x268d7ee3, (HALF)0xafb3514e, + (HALF)0x5378efcb, (HALF)0xfec0c7c6, (HALF)0xf07cb724, (HALF)0xfb61b42a, + (HALF)0x068f2a38 }; STATIC CONST HALF h_rvec18[] = { - (HALF)0x35ea3c63, (HALF)0x8df2ef97, (HALF)0xa2b3afb7, (HALF)0x179158f6, - (HALF)0x04920dba, (HALF)0xf333077e, (HALF)0xf8304b5a, (HALF)0x230ff2ae, - (HALF)0x84a8f3f0, (HALF)0xadda164e, (HALF)0xc9a1c944, (HALF)0xc70502f2, - (HALF)0x41a3c18f, (HALF)0x09bd3254, (HALF)0x973665a9, (HALF)0x1548c263, - (HALF)0x5024d916, (HALF)0x0a3ddde9, (HALF)0xf2aaf1f5, (HALF)0x666db92a, - (HALF)0x3a535aa5, (HALF)0x49c35775, (HALF)0xc381a1c4, (HALF)0xf8d36dbc, - (HALF)0xe94be870, (HALF)0x430e88a6, (HALF)0x37219a06, (HALF)0x5109df80, - (HALF)0xe73ca03f, (HALF)0xf1bb4541, (HALF)0x3c6f32f3, (HALF)0x952cfc24, - (HALF)0xfbc9697f, (HALF)0xc5b8d472, (HALF)0xcbbeda4b, (HALF)0x7303db3b, - (HALF)0xa18f255e, (HALF)0xe1d3353d, (HALF)0xe8c98700, (HALF)0x9e75e8fd, - (HALF)0x3ddd812e, (HALF)0x7340f891, (HALF)0xb1f369ac, (HALF)0x764d505b, - (HALF)0xb13ef51b, (HALF)0x16c3aa43, (HALF)0x61d042c4, (HALF)0x22ac0339, - (HALF)0x3f306fd1, (HALF)0x49926f7f, (HALF)0x2b4c575c, (HALF)0x9f3ab467, - (HALF)0x5dac65af, (HALF)0x62778dc7, (HALF)0x99113a89, (HALF)0x49c0540a, - (HALF)0x1df70ac2, (HALF)0x4be12c5e, (HALF)0xe5d36bdb, (HALF)0x66b99ff5, - (HALF)0x5358be89, (HALF)0x4cd835d7, (HALF)0xf0d5cda8, (HALF)0x1f1ac6c3, - (HALF)0x04735e92 + (HALF)0x35ea3c63, (HALF)0x8df2ef97, (HALF)0xa2b3afb7, (HALF)0x179158f6, + (HALF)0x04920dba, (HALF)0xf333077e, (HALF)0xf8304b5a, (HALF)0x230ff2ae, + (HALF)0x84a8f3f0, (HALF)0xadda164e, (HALF)0xc9a1c944, (HALF)0xc70502f2, + (HALF)0x41a3c18f, (HALF)0x09bd3254, (HALF)0x973665a9, (HALF)0x1548c263, + (HALF)0x5024d916, (HALF)0x0a3ddde9, (HALF)0xf2aaf1f5, (HALF)0x666db92a, + (HALF)0x3a535aa5, (HALF)0x49c35775, (HALF)0xc381a1c4, (HALF)0xf8d36dbc, + (HALF)0xe94be870, (HALF)0x430e88a6, (HALF)0x37219a06, (HALF)0x5109df80, + (HALF)0xe73ca03f, (HALF)0xf1bb4541, (HALF)0x3c6f32f3, (HALF)0x952cfc24, + (HALF)0xfbc9697f, (HALF)0xc5b8d472, (HALF)0xcbbeda4b, (HALF)0x7303db3b, + (HALF)0xa18f255e, (HALF)0xe1d3353d, (HALF)0xe8c98700, (HALF)0x9e75e8fd, + (HALF)0x3ddd812e, (HALF)0x7340f891, (HALF)0xb1f369ac, (HALF)0x764d505b, + (HALF)0xb13ef51b, (HALF)0x16c3aa43, (HALF)0x61d042c4, (HALF)0x22ac0339, + (HALF)0x3f306fd1, (HALF)0x49926f7f, (HALF)0x2b4c575c, (HALF)0x9f3ab467, + (HALF)0x5dac65af, (HALF)0x62778dc7, (HALF)0x99113a89, (HALF)0x49c0540a, + (HALF)0x1df70ac2, (HALF)0x4be12c5e, (HALF)0xe5d36bdb, (HALF)0x66b99ff5, + (HALF)0x5358be89, (HALF)0x4cd835d7, (HALF)0xf0d5cda8, (HALF)0x1f1ac6c3, + (HALF)0x04735e92 }; STATIC CONST HALF h_nvec19[] = { - (HALF)0x6b659a79, (HALF)0x0239c12d, (HALF)0xd204df49, (HALF)0x1d4ae0c7, - (HALF)0x099bf000, (HALF)0x6435ade8, (HALF)0xdc4af029, (HALF)0x2f4ee7a2, - (HALF)0xadfcf1e3, (HALF)0x73358f43, (HALF)0x687eede5, (HALF)0xb567cd4d, - (HALF)0xc7a7814f, (HALF)0xc306624c, (HALF)0xa82d80c6, (HALF)0x3f390cd5, - (HALF)0x7b7dec3f, (HALF)0x8bdb1416, (HALF)0x275b3a52, (HALF)0x921884fe, - (HALF)0x94ac02e0, (HALF)0x62f2b52c, (HALF)0xcdc992ee, (HALF)0x35e55eeb, - (HALF)0x69a43fd5, (HALF)0x44c1dcfb, (HALF)0x3cdf6227, (HALF)0x23f3148f, - (HALF)0x42508e4c, (HALF)0x95b737c3, (HALF)0x70af831f, (HALF)0x2ee815c9, - (HALF)0x47a47251, (HALF)0x7c11b2af, (HALF)0x664c361f, (HALF)0xcadaa841, - (HALF)0x3d97172a, (HALF)0x87402ffb, (HALF)0xa0a02ebd, (HALF)0xb674225f, - (HALF)0x65593fe2, (HALF)0x85f698b9, (HALF)0x5ed9a7ab, (HALF)0x6bf37371, - (HALF)0x7da75305, (HALF)0x088255bf, (HALF)0x8f607684, (HALF)0x1f3de57e, - (HALF)0x118bd501, (HALF)0x6833770d, (HALF)0xd0425c51, (HALF)0x2664cacb, - (HALF)0x9206b920, (HALF)0xeb903b8d, (HALF)0x0e2516b4, (HALF)0x36c3d841, - (HALF)0x51d7cd17, (HALF)0xe063ba1e, (HALF)0xf28f4a6d, (HALF)0x244deb0d, - (HALF)0x2e410ad4, (HALF)0x0721c315, (HALF)0xdde27654, (HALF)0x2ad6534b, - (HALF)0xd6788b25, (HALF)0xb23bb9e8, (HALF)0x00230d7a + (HALF)0x6b659a79, (HALF)0x0239c12d, (HALF)0xd204df49, (HALF)0x1d4ae0c7, + (HALF)0x099bf000, (HALF)0x6435ade8, (HALF)0xdc4af029, (HALF)0x2f4ee7a2, + (HALF)0xadfcf1e3, (HALF)0x73358f43, (HALF)0x687eede5, (HALF)0xb567cd4d, + (HALF)0xc7a7814f, (HALF)0xc306624c, (HALF)0xa82d80c6, (HALF)0x3f390cd5, + (HALF)0x7b7dec3f, (HALF)0x8bdb1416, (HALF)0x275b3a52, (HALF)0x921884fe, + (HALF)0x94ac02e0, (HALF)0x62f2b52c, (HALF)0xcdc992ee, (HALF)0x35e55eeb, + (HALF)0x69a43fd5, (HALF)0x44c1dcfb, (HALF)0x3cdf6227, (HALF)0x23f3148f, + (HALF)0x42508e4c, (HALF)0x95b737c3, (HALF)0x70af831f, (HALF)0x2ee815c9, + (HALF)0x47a47251, (HALF)0x7c11b2af, (HALF)0x664c361f, (HALF)0xcadaa841, + (HALF)0x3d97172a, (HALF)0x87402ffb, (HALF)0xa0a02ebd, (HALF)0xb674225f, + (HALF)0x65593fe2, (HALF)0x85f698b9, (HALF)0x5ed9a7ab, (HALF)0x6bf37371, + (HALF)0x7da75305, (HALF)0x088255bf, (HALF)0x8f607684, (HALF)0x1f3de57e, + (HALF)0x118bd501, (HALF)0x6833770d, (HALF)0xd0425c51, (HALF)0x2664cacb, + (HALF)0x9206b920, (HALF)0xeb903b8d, (HALF)0x0e2516b4, (HALF)0x36c3d841, + (HALF)0x51d7cd17, (HALF)0xe063ba1e, (HALF)0xf28f4a6d, (HALF)0x244deb0d, + (HALF)0x2e410ad4, (HALF)0x0721c315, (HALF)0xdde27654, (HALF)0x2ad6534b, + (HALF)0xd6788b25, (HALF)0xb23bb9e8, (HALF)0x00230d7a }; STATIC CONST HALF h_rvec19[] = { - (HALF)0x698ef473, (HALF)0x3d53a5b7, (HALF)0x06448319, (HALF)0xd9ad4445, - (HALF)0x6967daa0, (HALF)0xa14c6240, (HALF)0x78e77724, (HALF)0x63ef2ab7, - (HALF)0x8dff2ee2, (HALF)0x662eb424, (HALF)0xcd9307d6, (HALF)0x0ab06a5d, - (HALF)0xbdd7b539, (HALF)0x8621dd2d, (HALF)0x2bb4a187, (HALF)0x1f1e121d, - (HALF)0xce8db962, (HALF)0xdd3eeaf1, (HALF)0x573b6ca1, (HALF)0x6f460cd6, - (HALF)0x6a8d4780, (HALF)0xea68c7e6, (HALF)0x1148eb32, (HALF)0xb43d44d4, - (HALF)0xb657cb64, (HALF)0x8547fdba, (HALF)0x85f73333, (HALF)0xc1f2a51a, - (HALF)0x1c05ee52, (HALF)0x2847c03d, (HALF)0xfc7a88d8, (HALF)0x2e8dd186, - (HALF)0x5be34683, (HALF)0xd43d2ee2, (HALF)0x9f2d2bb5, (HALF)0x89b3ddea, - (HALF)0x7d784ae0, (HALF)0xc7735e28, (HALF)0x967a8608, (HALF)0xcdcbcf07, - (HALF)0xfc17a423, (HALF)0xd36ad053, (HALF)0xc73d8892, (HALF)0xa635c3f4, - (HALF)0x9b5d0cf9, (HALF)0x0ac73fd9, (HALF)0xe801fefb, (HALF)0xb31cffd2, - (HALF)0xf3eaaa55, (HALF)0x0e74fa23, (HALF)0x5414b290, (HALF)0x6d176101, - (HALF)0x522993f8, (HALF)0xf8293dad, (HALF)0x713b1e82, (HALF)0xb83bbef0, - (HALF)0xd001cc62, (HALF)0x7537da39, (HALF)0x7d80158b, (HALF)0x9332c8e2, - (HALF)0x6fa6fa75, (HALF)0xe21f6512, (HALF)0x999518b4, (HALF)0x2196605b, - (HALF)0xe4fc1798, (HALF)0x5f21e245, (HALF)0x0008f172 + (HALF)0x698ef473, (HALF)0x3d53a5b7, (HALF)0x06448319, (HALF)0xd9ad4445, + (HALF)0x6967daa0, (HALF)0xa14c6240, (HALF)0x78e77724, (HALF)0x63ef2ab7, + (HALF)0x8dff2ee2, (HALF)0x662eb424, (HALF)0xcd9307d6, (HALF)0x0ab06a5d, + (HALF)0xbdd7b539, (HALF)0x8621dd2d, (HALF)0x2bb4a187, (HALF)0x1f1e121d, + (HALF)0xce8db962, (HALF)0xdd3eeaf1, (HALF)0x573b6ca1, (HALF)0x6f460cd6, + (HALF)0x6a8d4780, (HALF)0xea68c7e6, (HALF)0x1148eb32, (HALF)0xb43d44d4, + (HALF)0xb657cb64, (HALF)0x8547fdba, (HALF)0x85f73333, (HALF)0xc1f2a51a, + (HALF)0x1c05ee52, (HALF)0x2847c03d, (HALF)0xfc7a88d8, (HALF)0x2e8dd186, + (HALF)0x5be34683, (HALF)0xd43d2ee2, (HALF)0x9f2d2bb5, (HALF)0x89b3ddea, + (HALF)0x7d784ae0, (HALF)0xc7735e28, (HALF)0x967a8608, (HALF)0xcdcbcf07, + (HALF)0xfc17a423, (HALF)0xd36ad053, (HALF)0xc73d8892, (HALF)0xa635c3f4, + (HALF)0x9b5d0cf9, (HALF)0x0ac73fd9, (HALF)0xe801fefb, (HALF)0xb31cffd2, + (HALF)0xf3eaaa55, (HALF)0x0e74fa23, (HALF)0x5414b290, (HALF)0x6d176101, + (HALF)0x522993f8, (HALF)0xf8293dad, (HALF)0x713b1e82, (HALF)0xb83bbef0, + (HALF)0xd001cc62, (HALF)0x7537da39, (HALF)0x7d80158b, (HALF)0x9332c8e2, + (HALF)0x6fa6fa75, (HALF)0xe21f6512, (HALF)0x999518b4, (HALF)0x2196605b, + (HALF)0xe4fc1798, (HALF)0x5f21e245, (HALF)0x0008f172 }; STATIC CONST HALF h_nvec20[] = { - (HALF)0xc3c1d081, (HALF)0x4d262fce, (HALF)0x8765cc91, (HALF)0xf3727f7c, - (HALF)0xabba4bbc, (HALF)0xe0985801, (HALF)0xfa365c51, (HALF)0xb2a4b230, - (HALF)0xf4430a8d, (HALF)0x546b98c8, (HALF)0xd9748b26, (HALF)0xe255a82f, - (HALF)0xb00a3e8c, (HALF)0x7069676d, (HALF)0x6233ccce, (HALF)0x0299a74e, - (HALF)0xd119adf9, (HALF)0x5273e811, (HALF)0xae36e0bb, (HALF)0x32b3a486, - (HALF)0xf04921a5, (HALF)0xd31d28a2, (HALF)0xda0c50de, (HALF)0x21302b40, - (HALF)0xee9de552, (HALF)0x80bbac03, (HALF)0x75f49740, (HALF)0xc3d0a61b, - (HALF)0x341cfbf6, (HALF)0x1615b5b4, (HALF)0x4e3a3def, (HALF)0x95734dbf, - (HALF)0xe7ab78ac, (HALF)0xffdc5cf9, (HALF)0xf7996892, (HALF)0x47407ba4, - (HALF)0xa78b988f, (HALF)0x27736f42, (HALF)0x5064ee50, (HALF)0x60135c56, - (HALF)0x1ad73283, (HALF)0x25624bf7, (HALF)0x2ee21419, (HALF)0x93195abd, - (HALF)0x66b67778, (HALF)0xb1e0a42d, (HALF)0x729fb0f0, (HALF)0xd4921864, - (HALF)0x2c42253f, (HALF)0x302a07a9, (HALF)0xbb741bd4, (HALF)0x932f90ba, - (HALF)0xf3354be1, (HALF)0x0804d661, (HALF)0x010e9ba1, (HALF)0x1a05778d, - (HALF)0xa962c833, (HALF)0xe7590ee8, (HALF)0xbe6803b8, (HALF)0xc67704c1, - (HALF)0x56d79660, (HALF)0x6066a3f3, (HALF)0x648b0327, (HALF)0x267e5b3a, - (HALF)0xdddc63a0, (HALF)0x3322e890, (HALF)0x20e0d8b1, (HALF)0x004fd2b8 + (HALF)0xc3c1d081, (HALF)0x4d262fce, (HALF)0x8765cc91, (HALF)0xf3727f7c, + (HALF)0xabba4bbc, (HALF)0xe0985801, (HALF)0xfa365c51, (HALF)0xb2a4b230, + (HALF)0xf4430a8d, (HALF)0x546b98c8, (HALF)0xd9748b26, (HALF)0xe255a82f, + (HALF)0xb00a3e8c, (HALF)0x7069676d, (HALF)0x6233ccce, (HALF)0x0299a74e, + (HALF)0xd119adf9, (HALF)0x5273e811, (HALF)0xae36e0bb, (HALF)0x32b3a486, + (HALF)0xf04921a5, (HALF)0xd31d28a2, (HALF)0xda0c50de, (HALF)0x21302b40, + (HALF)0xee9de552, (HALF)0x80bbac03, (HALF)0x75f49740, (HALF)0xc3d0a61b, + (HALF)0x341cfbf6, (HALF)0x1615b5b4, (HALF)0x4e3a3def, (HALF)0x95734dbf, + (HALF)0xe7ab78ac, (HALF)0xffdc5cf9, (HALF)0xf7996892, (HALF)0x47407ba4, + (HALF)0xa78b988f, (HALF)0x27736f42, (HALF)0x5064ee50, (HALF)0x60135c56, + (HALF)0x1ad73283, (HALF)0x25624bf7, (HALF)0x2ee21419, (HALF)0x93195abd, + (HALF)0x66b67778, (HALF)0xb1e0a42d, (HALF)0x729fb0f0, (HALF)0xd4921864, + (HALF)0x2c42253f, (HALF)0x302a07a9, (HALF)0xbb741bd4, (HALF)0x932f90ba, + (HALF)0xf3354be1, (HALF)0x0804d661, (HALF)0x010e9ba1, (HALF)0x1a05778d, + (HALF)0xa962c833, (HALF)0xe7590ee8, (HALF)0xbe6803b8, (HALF)0xc67704c1, + (HALF)0x56d79660, (HALF)0x6066a3f3, (HALF)0x648b0327, (HALF)0x267e5b3a, + (HALF)0xdddc63a0, (HALF)0x3322e890, (HALF)0x20e0d8b1, (HALF)0x004fd2b8 }; STATIC CONST HALF h_rvec20[] = { - (HALF)0xa048bd1a, (HALF)0x95abdc7b, (HALF)0x98f47cf8, (HALF)0x126ac98d, - (HALF)0xaebf85fd, (HALF)0x5650580f, (HALF)0x3292d7dd, (HALF)0xf49e8377, - (HALF)0x2947ed46, (HALF)0xd1a5b26c, (HALF)0xae14e6a1, (HALF)0x9b1f5788, - (HALF)0x4df727b2, (HALF)0xee375079, (HALF)0x131bc8e4, (HALF)0x294e5f53, - (HALF)0x1f5759bd, (HALF)0x65d58acf, (HALF)0x598ed3a5, (HALF)0xc39361a6, - (HALF)0xa783fd7a, (HALF)0x264a36a2, (HALF)0x6ca22856, (HALF)0x8ffb171f, - (HALF)0x1d7cea9e, (HALF)0xd81d6fca, (HALF)0x34ea730e, (HALF)0x31f56382, - (HALF)0xb39cd9e9, (HALF)0x440e84be, (HALF)0x4b1d15a1, (HALF)0x7bf775c5, - (HALF)0xe40f4638, (HALF)0xe5bef0a7, (HALF)0x79e58942, (HALF)0x881ae1ba, - (HALF)0x01de8372, (HALF)0x14cf35f8, (HALF)0xe2d8b310, (HALF)0x66961207, - (HALF)0xde5d5f91, (HALF)0xe6e70849, (HALF)0x74ec5ac3, (HALF)0xe2de4eb1, - (HALF)0x4a41dc20, (HALF)0xd306d565, (HALF)0xb5843ff3, (HALF)0x911b30d6, - (HALF)0x4e9cd926, (HALF)0x8455c9ae, (HALF)0x69448bb5, (HALF)0x0c7b1aad, - (HALF)0x1da1e992, (HALF)0xc67656bd, (HALF)0xc544209e, (HALF)0x10ce387c, - (HALF)0xc4e88df8, (HALF)0x40e8da88, (HALF)0xbb2c3028, (HALF)0x49194fd9, - (HALF)0xdeef17ee, (HALF)0x241bc08d, (HALF)0x6fa9f608, (HALF)0x4b0f8b04, - (HALF)0xee960da1, (HALF)0xa3099293, (HALF)0x84445fea, (HALF)0x0046ef01 + (HALF)0xa048bd1a, (HALF)0x95abdc7b, (HALF)0x98f47cf8, (HALF)0x126ac98d, + (HALF)0xaebf85fd, (HALF)0x5650580f, (HALF)0x3292d7dd, (HALF)0xf49e8377, + (HALF)0x2947ed46, (HALF)0xd1a5b26c, (HALF)0xae14e6a1, (HALF)0x9b1f5788, + (HALF)0x4df727b2, (HALF)0xee375079, (HALF)0x131bc8e4, (HALF)0x294e5f53, + (HALF)0x1f5759bd, (HALF)0x65d58acf, (HALF)0x598ed3a5, (HALF)0xc39361a6, + (HALF)0xa783fd7a, (HALF)0x264a36a2, (HALF)0x6ca22856, (HALF)0x8ffb171f, + (HALF)0x1d7cea9e, (HALF)0xd81d6fca, (HALF)0x34ea730e, (HALF)0x31f56382, + (HALF)0xb39cd9e9, (HALF)0x440e84be, (HALF)0x4b1d15a1, (HALF)0x7bf775c5, + (HALF)0xe40f4638, (HALF)0xe5bef0a7, (HALF)0x79e58942, (HALF)0x881ae1ba, + (HALF)0x01de8372, (HALF)0x14cf35f8, (HALF)0xe2d8b310, (HALF)0x66961207, + (HALF)0xde5d5f91, (HALF)0xe6e70849, (HALF)0x74ec5ac3, (HALF)0xe2de4eb1, + (HALF)0x4a41dc20, (HALF)0xd306d565, (HALF)0xb5843ff3, (HALF)0x911b30d6, + (HALF)0x4e9cd926, (HALF)0x8455c9ae, (HALF)0x69448bb5, (HALF)0x0c7b1aad, + (HALF)0x1da1e992, (HALF)0xc67656bd, (HALF)0xc544209e, (HALF)0x10ce387c, + (HALF)0xc4e88df8, (HALF)0x40e8da88, (HALF)0xbb2c3028, (HALF)0x49194fd9, + (HALF)0xdeef17ee, (HALF)0x241bc08d, (HALF)0x6fa9f608, (HALF)0x4b0f8b04, + (HALF)0xee960da1, (HALF)0xa3099293, (HALF)0x84445fea, (HALF)0x0046ef01 }; #elif 2*FULL_BITS == 64 STATIC CONST HALF h_nvec01[] = { - (HALF)0x9361, (HALF)0x83de, (HALF)0x722d, (HALF)0xf0db, - (HALF)0x28ca, (HALF)0x6fe3, (HALF)0x4073, (HALF)0x0494, - (HALF)0x5 + (HALF)0x9361, (HALF)0x83de, (HALF)0x722d, (HALF)0xf0db, + (HALF)0x28ca, (HALF)0x6fe3, (HALF)0x4073, (HALF)0x0494, + (HALF)0x5 }; STATIC CONST HALF h_rvec01[] = { - (HALF)0x42ec, (HALF)0xa4cc, (HALF)0xbb01, (HALF)0x4e5d, - (HALF)0x52e7, (HALF)0x11d9, (HALF)0x980f, (HALF)0xb226 + (HALF)0x42ec, (HALF)0xa4cc, (HALF)0xbb01, (HALF)0x4e5d, + (HALF)0x52e7, (HALF)0x11d9, (HALF)0x980f, (HALF)0xb226 }; STATIC CONST HALF h_nvec02[] = { - (HALF)0x43f1, (HALF)0x3534, (HALF)0x6ea9, (HALF)0xeb28, - (HALF)0x4a18, (HALF)0xdd37, (HALF)0x2555, (HALF)0x348a, - (HALF)0x2c5 + (HALF)0x43f1, (HALF)0x3534, (HALF)0x6ea9, (HALF)0xeb28, + (HALF)0x4a18, (HALF)0xdd37, (HALF)0x2555, (HALF)0x348a, + (HALF)0x2c5 }; STATIC CONST HALF h_rvec02[] = { - (HALF)0xa218, (HALF)0x21e3, (HALF)0x616b, (HALF)0xe893, - (HALF)0x10e3, (HALF)0x6cd7, (HALF)0x4344, (HALF)0xf3d6, - (HALF)0x40 + (HALF)0xa218, (HALF)0x21e3, (HALF)0x616b, (HALF)0xe893, + (HALF)0x10e3, (HALF)0x6cd7, (HALF)0x4344, (HALF)0xf3d6, + (HALF)0x40 }; STATIC CONST HALF h_nvec03[] = { - (HALF)0x01f1, (HALF)0x11d0, (HALF)0x661f, (HALF)0xf2ca, - (HALF)0xf1e0, (HALF)0x3a81, (HALF)0xce4e, (HALF)0x59d6, - (HALF)0xcfd9, (HALF)0x0009 + (HALF)0x01f1, (HALF)0x11d0, (HALF)0x661f, (HALF)0xf2ca, + (HALF)0xf1e0, (HALF)0x3a81, (HALF)0xce4e, (HALF)0x59d6, + (HALF)0xcfd9, (HALF)0x0009 }; STATIC CONST HALF h_rvec03[] = { - (HALF)0xd76a, (HALF)0xa0d7, (HALF)0x2de2, (HALF)0x3e14, - (HALF)0xea4f, (HALF)0xff5c, (HALF)0x9b64, (HALF)0xb44d, - (HALF)0xfae5 + (HALF)0xd76a, (HALF)0xa0d7, (HALF)0x2de2, (HALF)0x3e14, + (HALF)0xea4f, (HALF)0xff5c, (HALF)0x9b64, (HALF)0xb44d, + (HALF)0xfae5 }; STATIC CONST HALF h_nvec04[] = { - (HALF)0x0751, (HALF)0xdfcc, (HALF)0xc680, (HALF)0x2dec, - (HALF)0x2a1a, (HALF)0x5df1, (HALF)0x4ed7, (HALF)0x5c89, - (HALF)0xf924, (HALF)0x3070 + (HALF)0x0751, (HALF)0xdfcc, (HALF)0xc680, (HALF)0x2dec, + (HALF)0x2a1a, (HALF)0x5df1, (HALF)0x4ed7, (HALF)0x5c89, + (HALF)0xf924, (HALF)0x3070 }; STATIC CONST HALF h_rvec04[] = { - (HALF)0x4570, (HALF)0x4b98, (HALF)0xddba, (HALF)0xa220, - (HALF)0xaf8a, (HALF)0xa2c0, (HALF)0x2bdc, (HALF)0x131b, - (HALF)0xc2d8, (HALF)0x0020 + (HALF)0x4570, (HALF)0x4b98, (HALF)0xddba, (HALF)0xa220, + (HALF)0xaf8a, (HALF)0xa2c0, (HALF)0x2bdc, (HALF)0x131b, + (HALF)0xc2d8, (HALF)0x0020 }; STATIC CONST HALF h_nvec05[] = { - (HALF)0x6ef1, (HALF)0x9916, (HALF)0xe5e7, (HALF)0x8b99, - (HALF)0xa010, (HALF)0x8769, (HALF)0xe111, (HALF)0x5d3f, - (HALF)0xc2fa, (HALF)0x680b, (HALF)0x5aac, (HALF)0x38f7, - (HALF)0xa85b, (HALF)0xdb81, (HALF)0x1822, (HALF)0x109b, - (HALF)0x2 + (HALF)0x6ef1, (HALF)0x9916, (HALF)0xe5e7, (HALF)0x8b99, + (HALF)0xa010, (HALF)0x8769, (HALF)0xe111, (HALF)0x5d3f, + (HALF)0xc2fa, (HALF)0x680b, (HALF)0x5aac, (HALF)0x38f7, + (HALF)0xa85b, (HALF)0xdb81, (HALF)0x1822, (HALF)0x109b, + (HALF)0x2 }; STATIC CONST HALF h_rvec05[] = { - (HALF)0xefa9, (HALF)0x59e2, (HALF)0x77c8, (HALF)0x0e6c, - (HALF)0xaeed, (HALF)0x1e70, (HALF)0x7b7d, (HALF)0x234f, - (HALF)0xf6db, (HALF)0x5f5d, (HALF)0xa960, (HALF)0xe821, - (HALF)0xb792, (HALF)0xae33, (HALF)0x890e, (HALF)0x5e9b + (HALF)0xefa9, (HALF)0x59e2, (HALF)0x77c8, (HALF)0x0e6c, + (HALF)0xaeed, (HALF)0x1e70, (HALF)0x7b7d, (HALF)0x234f, + (HALF)0xf6db, (HALF)0x5f5d, (HALF)0xa960, (HALF)0xe821, + (HALF)0xb792, (HALF)0xae33, (HALF)0x890e, (HALF)0x5e9b }; STATIC CONST HALF h_nvec06[] = { - (HALF)0xf431, (HALF)0xe1dd, (HALF)0x57f1, (HALF)0xd855, - (HALF)0x32da, (HALF)0x5ee7, (HALF)0xdb77, (HALF)0x3a38, - (HALF)0x4026, (HALF)0x5c64, (HALF)0xf218, (HALF)0xf2db, - (HALF)0x2c79, (HALF)0x9ada, (HALF)0x9d7d, (HALF)0x7bfd, - (HALF)0xa + (HALF)0xf431, (HALF)0xe1dd, (HALF)0x57f1, (HALF)0xd855, + (HALF)0x32da, (HALF)0x5ee7, (HALF)0xdb77, (HALF)0x3a38, + (HALF)0x4026, (HALF)0x5c64, (HALF)0xf218, (HALF)0xf2db, + (HALF)0x2c79, (HALF)0x9ada, (HALF)0x9d7d, (HALF)0x7bfd, + (HALF)0xa }; STATIC CONST HALF h_rvec06[] = { - (HALF)0x4daf, (HALF)0xc940, (HALF)0x2e80, (HALF)0xc5dc, - (HALF)0xeccf, (HALF)0x2c98, (HALF)0x495d, (HALF)0xe1f3, - (HALF)0x925c, (HALF)0xce1c, (HALF)0xaede, (HALF)0xe097, - (HALF)0x7154, (HALF)0x8866, (HALF)0xa02f, (HALF)0x5e94 + (HALF)0x4daf, (HALF)0xc940, (HALF)0x2e80, (HALF)0xc5dc, + (HALF)0xeccf, (HALF)0x2c98, (HALF)0x495d, (HALF)0xe1f3, + (HALF)0x925c, (HALF)0xce1c, (HALF)0xaede, (HALF)0xe097, + (HALF)0x7154, (HALF)0x8866, (HALF)0xa02f, (HALF)0x5e94 }; STATIC CONST HALF h_nvec07[] = { - (HALF)0xc751, (HALF)0xcf9e, (HALF)0x9125, (HALF)0x602f, - (HALF)0x2e7f, (HALF)0x5288, (HALF)0x53ce, (HALF)0x0dcf, - (HALF)0x9d6b, (HALF)0xff56, (HALF)0x43fc, (HALF)0x6286, - (HALF)0x1cd5, (HALF)0x3780, (HALF)0x9ef2, (HALF)0xf239, - (HALF)0x7de8, (HALF)0x43d8 + (HALF)0xc751, (HALF)0xcf9e, (HALF)0x9125, (HALF)0x602f, + (HALF)0x2e7f, (HALF)0x5288, (HALF)0x53ce, (HALF)0x0dcf, + (HALF)0x9d6b, (HALF)0xff56, (HALF)0x43fc, (HALF)0x6286, + (HALF)0x1cd5, (HALF)0x3780, (HALF)0x9ef2, (HALF)0xf239, + (HALF)0x7de8, (HALF)0x43d8 }; STATIC CONST HALF h_rvec07[] = { - (HALF)0x25e6, (HALF)0x098d, (HALF)0xd2e5, (HALF)0x3992, - (HALF)0xb58c, (HALF)0x64f0, (HALF)0xd4dd, (HALF)0xcf18, - (HALF)0x6aef, (HALF)0x9d87, (HALF)0xed04, (HALF)0x7acc, - (HALF)0x9076, (HALF)0xbfbe, (HALF)0x14c7, (HALF)0x1ee0, - (HALF)0x522d, (HALF)0x0013 + (HALF)0x25e6, (HALF)0x098d, (HALF)0xd2e5, (HALF)0x3992, + (HALF)0xb58c, (HALF)0x64f0, (HALF)0xd4dd, (HALF)0xcf18, + (HALF)0x6aef, (HALF)0x9d87, (HALF)0xed04, (HALF)0x7acc, + (HALF)0x9076, (HALF)0xbfbe, (HALF)0x14c7, (HALF)0x1ee0, + (HALF)0x522d, (HALF)0x0013 }; STATIC CONST HALF h_nvec08[] = { - (HALF)0x2f11, (HALF)0x2674, (HALF)0xe66a, (HALF)0xbc42, - (HALF)0xd9f0, (HALF)0xb59c, (HALF)0xa6c2, (HALF)0x9ad4, - (HALF)0xd2f9, (HALF)0x5bdb, (HALF)0x1fed, (HALF)0xbdc9, - (HALF)0x9ce7, (HALF)0xf13c, (HALF)0x99b7, (HALF)0xeb46, - (HALF)0x6ca7, (HALF)0x4712, (HALF)0x58 + (HALF)0x2f11, (HALF)0x2674, (HALF)0xe66a, (HALF)0xbc42, + (HALF)0xd9f0, (HALF)0xb59c, (HALF)0xa6c2, (HALF)0x9ad4, + (HALF)0xd2f9, (HALF)0x5bdb, (HALF)0x1fed, (HALF)0xbdc9, + (HALF)0x9ce7, (HALF)0xf13c, (HALF)0x99b7, (HALF)0xeb46, + (HALF)0x6ca7, (HALF)0x4712, (HALF)0x58 }; STATIC CONST HALF h_rvec08[] = { - (HALF)0xc674, (HALF)0x489d, (HALF)0x5f3a, (HALF)0xaae9, - (HALF)0xa929, (HALF)0xa35d, (HALF)0xb4b8, (HALF)0x5597, - (HALF)0xc947, (HALF)0x28e9, (HALF)0x4f9a, (HALF)0x3d34, - (HALF)0x61fa, (HALF)0xb7e6, (HALF)0x9116, (HALF)0xa326, - (HALF)0x16dc, (HALF)0x8530 + (HALF)0xc674, (HALF)0x489d, (HALF)0x5f3a, (HALF)0xaae9, + (HALF)0xa929, (HALF)0xa35d, (HALF)0xb4b8, (HALF)0x5597, + (HALF)0xc947, (HALF)0x28e9, (HALF)0x4f9a, (HALF)0x3d34, + (HALF)0x61fa, (HALF)0xb7e6, (HALF)0x9116, (HALF)0xa326, + (HALF)0x16dc, (HALF)0x8530 }; STATIC CONST HALF h_nvec09[] = { - (HALF)0xe3d1, (HALF)0xab27, (HALF)0x5db4, (HALF)0x1274, - (HALF)0xf951, (HALF)0xb980, (HALF)0x6b66, (HALF)0x62b1, - (HALF)0xce0d, (HALF)0x0fde, (HALF)0xc6fd, (HALF)0x6061, - (HALF)0xff09, (HALF)0x36a6, (HALF)0xb61c, (HALF)0xe08e, - (HALF)0x95c3, (HALF)0x84d8, (HALF)0x752a, (HALF)0x4a86, - (HALF)0x7b4f, (HALF)0xc179, (HALF)0x57a3, (HALF)0x5621, - (HALF)0x7bb0, (HALF)0x3d26, (HALF)0x1b00, (HALF)0x14e8, - (HALF)0x9238, (HALF)0x218d, (HALF)0x2fd3, (HALF)0x5232, - (HALF)0xe8be, (HALF)0x0039 + (HALF)0xe3d1, (HALF)0xab27, (HALF)0x5db4, (HALF)0x1274, + (HALF)0xf951, (HALF)0xb980, (HALF)0x6b66, (HALF)0x62b1, + (HALF)0xce0d, (HALF)0x0fde, (HALF)0xc6fd, (HALF)0x6061, + (HALF)0xff09, (HALF)0x36a6, (HALF)0xb61c, (HALF)0xe08e, + (HALF)0x95c3, (HALF)0x84d8, (HALF)0x752a, (HALF)0x4a86, + (HALF)0x7b4f, (HALF)0xc179, (HALF)0x57a3, (HALF)0x5621, + (HALF)0x7bb0, (HALF)0x3d26, (HALF)0x1b00, (HALF)0x14e8, + (HALF)0x9238, (HALF)0x218d, (HALF)0x2fd3, (HALF)0x5232, + (HALF)0xe8be, (HALF)0x0039 }; STATIC CONST HALF h_rvec09[] = { - (HALF)0xd20d, (HALF)0x7d4e, (HALF)0xf2b8, (HALF)0x601e, - (HALF)0xf959, (HALF)0x8e59, (HALF)0x5d9e, (HALF)0xedaa, - (HALF)0x89ba, (HALF)0x309a, (HALF)0x7d81, (HALF)0xe5ab, - (HALF)0x2545, (HALF)0x796b, (HALF)0x3222, (HALF)0x02de, - (HALF)0xc0bd, (HALF)0x8357, (HALF)0xe3fd, (HALF)0x0107, - (HALF)0xd288, (HALF)0x82d9, (HALF)0xa8aa, (HALF)0xbc42, - (HALF)0x7343, (HALF)0x4b78, (HALF)0x0886, (HALF)0xc015, - (HALF)0x15bf, (HALF)0xbab9, (HALF)0x1e6b, (HALF)0xf8ad, - (HALF)0xb458 + (HALF)0xd20d, (HALF)0x7d4e, (HALF)0xf2b8, (HALF)0x601e, + (HALF)0xf959, (HALF)0x8e59, (HALF)0x5d9e, (HALF)0xedaa, + (HALF)0x89ba, (HALF)0x309a, (HALF)0x7d81, (HALF)0xe5ab, + (HALF)0x2545, (HALF)0x796b, (HALF)0x3222, (HALF)0x02de, + (HALF)0xc0bd, (HALF)0x8357, (HALF)0xe3fd, (HALF)0x0107, + (HALF)0xd288, (HALF)0x82d9, (HALF)0xa8aa, (HALF)0xbc42, + (HALF)0x7343, (HALF)0x4b78, (HALF)0x0886, (HALF)0xc015, + (HALF)0x15bf, (HALF)0xbab9, (HALF)0x1e6b, (HALF)0xf8ad, + (HALF)0xb458 }; STATIC CONST HALF h_nvec10[] = { - (HALF)0x4b89, (HALF)0xb7e6, (HALF)0xc363, (HALF)0xc3cd, - (HALF)0xc73c, (HALF)0x2ef9, (HALF)0xce22, (HALF)0x6092, - (HALF)0xe36c, (HALF)0x02ab, (HALF)0x9573, (HALF)0x08d4, - (HALF)0x1c40, (HALF)0x7451, (HALF)0x82de, (HALF)0xd385, - (HALF)0xa02f, (HALF)0xa524, (HALF)0x1b3b, (HALF)0x52c8, - (HALF)0x3cc9, (HALF)0x250d, (HALF)0x0e88, (HALF)0x23b5, - (HALF)0x48bf, (HALF)0xbd14, (HALF)0x7f98, (HALF)0x882d, - (HALF)0xf596, (HALF)0xc23e, (HALF)0x5666, (HALF)0xc905, - (HALF)0x2435, (HALF)0x025f + (HALF)0x4b89, (HALF)0xb7e6, (HALF)0xc363, (HALF)0xc3cd, + (HALF)0xc73c, (HALF)0x2ef9, (HALF)0xce22, (HALF)0x6092, + (HALF)0xe36c, (HALF)0x02ab, (HALF)0x9573, (HALF)0x08d4, + (HALF)0x1c40, (HALF)0x7451, (HALF)0x82de, (HALF)0xd385, + (HALF)0xa02f, (HALF)0xa524, (HALF)0x1b3b, (HALF)0x52c8, + (HALF)0x3cc9, (HALF)0x250d, (HALF)0x0e88, (HALF)0x23b5, + (HALF)0x48bf, (HALF)0xbd14, (HALF)0x7f98, (HALF)0x882d, + (HALF)0xf596, (HALF)0xc23e, (HALF)0x5666, (HALF)0xc905, + (HALF)0x2435, (HALF)0x025f }; STATIC CONST HALF h_rvec10[] = { - (HALF)0xc482, (HALF)0x94cf, (HALF)0x5ad4, (HALF)0x594f, - (HALF)0x2aee, (HALF)0x2344, (HALF)0x40ce, (HALF)0x145f, - (HALF)0x950d, (HALF)0x1baf, (HALF)0xf175, (HALF)0xadc4, - (HALF)0x669f, (HALF)0xf62c, (HALF)0x5d56, (HALF)0x8d07, - (HALF)0x8b40, (HALF)0x08ed, (HALF)0xcf30, (HALF)0xaaf2, - (HALF)0x5ffb, (HALF)0xc24b, (HALF)0xf8cf, (HALF)0x250d, - (HALF)0x1ec9, (HALF)0x7ca8, (HALF)0x2b70, (HALF)0x787e, - (HALF)0x1468, (HALF)0x1840, (HALF)0x0e0c, (HALF)0x47b2, - (HALF)0xbb7e, (HALF)0x0066 + (HALF)0xc482, (HALF)0x94cf, (HALF)0x5ad4, (HALF)0x594f, + (HALF)0x2aee, (HALF)0x2344, (HALF)0x40ce, (HALF)0x145f, + (HALF)0x950d, (HALF)0x1baf, (HALF)0xf175, (HALF)0xadc4, + (HALF)0x669f, (HALF)0xf62c, (HALF)0x5d56, (HALF)0x8d07, + (HALF)0x8b40, (HALF)0x08ed, (HALF)0xcf30, (HALF)0xaaf2, + (HALF)0x5ffb, (HALF)0xc24b, (HALF)0xf8cf, (HALF)0x250d, + (HALF)0x1ec9, (HALF)0x7ca8, (HALF)0x2b70, (HALF)0x787e, + (HALF)0x1468, (HALF)0x1840, (HALF)0x0e0c, (HALF)0x47b2, + (HALF)0xbb7e, (HALF)0x0066 }; STATIC CONST HALF h_nvec11[] = { - (HALF)0xe069, (HALF)0x546e, (HALF)0x530c, (HALF)0x2e1a, - (HALF)0xdab2, (HALF)0x2014, (HALF)0xcf52, (HALF)0xa729, - (HALF)0xe1a9, (HALF)0x920e, (HALF)0x7533, (HALF)0x68f2, - (HALF)0x3cfa, (HALF)0x2587, (HALF)0xa749, (HALF)0xdd37, - (HALF)0xdaa2, (HALF)0x4499, (HALF)0x5870, (HALF)0x286e, - (HALF)0xf9b6, (HALF)0x57f3, (HALF)0x4467, (HALF)0x5ec5, - (HALF)0x91ea, (HALF)0x69a7, (HALF)0xcd77, (HALF)0x874e, - (HALF)0xd56b, (HALF)0x4217, (HALF)0xb309, (HALF)0x82bd, - (HALF)0x64de, (HALF)0x4978 + (HALF)0xe069, (HALF)0x546e, (HALF)0x530c, (HALF)0x2e1a, + (HALF)0xdab2, (HALF)0x2014, (HALF)0xcf52, (HALF)0xa729, + (HALF)0xe1a9, (HALF)0x920e, (HALF)0x7533, (HALF)0x68f2, + (HALF)0x3cfa, (HALF)0x2587, (HALF)0xa749, (HALF)0xdd37, + (HALF)0xdaa2, (HALF)0x4499, (HALF)0x5870, (HALF)0x286e, + (HALF)0xf9b6, (HALF)0x57f3, (HALF)0x4467, (HALF)0x5ec5, + (HALF)0x91ea, (HALF)0x69a7, (HALF)0xcd77, (HALF)0x874e, + (HALF)0xd56b, (HALF)0x4217, (HALF)0xb309, (HALF)0x82bd, + (HALF)0x64de, (HALF)0x4978 }; STATIC CONST HALF h_rvec11[] = { - (HALF)0x8b04, (HALF)0x56e3, (HALF)0xded3, (HALF)0x3a0a, - (HALF)0x88b1, (HALF)0x461d, (HALF)0x4d65, (HALF)0x9c09, - (HALF)0x3fed, (HALF)0xe533, (HALF)0x18fe, (HALF)0x34d9, - (HALF)0x6281, (HALF)0x1ef5, (HALF)0xa07c, (HALF)0xcedf, - (HALF)0x47fb, (HALF)0x590f, (HALF)0x4d5c, (HALF)0xa2c5, - (HALF)0x39ee, (HALF)0x7323, (HALF)0x49a7, (HALF)0x8065, - (HALF)0x163f, (HALF)0x9ce3, (HALF)0xf8b6, (HALF)0xae3a, - (HALF)0x4465, (HALF)0x264a, (HALF)0xe630, (HALF)0x1cb5, - (HALF)0x8488, (HALF)0x0086 + (HALF)0x8b04, (HALF)0x56e3, (HALF)0xded3, (HALF)0x3a0a, + (HALF)0x88b1, (HALF)0x461d, (HALF)0x4d65, (HALF)0x9c09, + (HALF)0x3fed, (HALF)0xe533, (HALF)0x18fe, (HALF)0x34d9, + (HALF)0x6281, (HALF)0x1ef5, (HALF)0xa07c, (HALF)0xcedf, + (HALF)0x47fb, (HALF)0x590f, (HALF)0x4d5c, (HALF)0xa2c5, + (HALF)0x39ee, (HALF)0x7323, (HALF)0x49a7, (HALF)0x8065, + (HALF)0x163f, (HALF)0x9ce3, (HALF)0xf8b6, (HALF)0xae3a, + (HALF)0x4465, (HALF)0x264a, (HALF)0xe630, (HALF)0x1cb5, + (HALF)0x8488, (HALF)0x0086 }; STATIC CONST HALF h_nvec12[] = { - (HALF)0x7b99, (HALF)0xf14c, (HALF)0xd151, (HALF)0x7f66, - (HALF)0xad2b, (HALF)0x87ef, (HALF)0xf098, (HALF)0x57d3, - (HALF)0x4165, (HALF)0xd653, (HALF)0xdd25, (HALF)0x812f, - (HALF)0xc7ce, (HALF)0x48c7, (HALF)0x41e0, (HALF)0xa1bf, - (HALF)0xe315, (HALF)0x4c94, (HALF)0x1593, (HALF)0x190b, - (HALF)0x51da, (HALF)0xee42, (HALF)0x1a66, (HALF)0x2b4a, - (HALF)0xc2a1, (HALF)0x2bb7, (HALF)0x8ca9, (HALF)0x65b1, - (HALF)0x9116, (HALF)0x08b8, (HALF)0xb15f, (HALF)0xc0cc, - (HALF)0x2ab3, (HALF)0x5758, (HALF)0x34 + (HALF)0x7b99, (HALF)0xf14c, (HALF)0xd151, (HALF)0x7f66, + (HALF)0xad2b, (HALF)0x87ef, (HALF)0xf098, (HALF)0x57d3, + (HALF)0x4165, (HALF)0xd653, (HALF)0xdd25, (HALF)0x812f, + (HALF)0xc7ce, (HALF)0x48c7, (HALF)0x41e0, (HALF)0xa1bf, + (HALF)0xe315, (HALF)0x4c94, (HALF)0x1593, (HALF)0x190b, + (HALF)0x51da, (HALF)0xee42, (HALF)0x1a66, (HALF)0x2b4a, + (HALF)0xc2a1, (HALF)0x2bb7, (HALF)0x8ca9, (HALF)0x65b1, + (HALF)0x9116, (HALF)0x08b8, (HALF)0xb15f, (HALF)0xc0cc, + (HALF)0x2ab3, (HALF)0x5758, (HALF)0x34 }; STATIC CONST HALF h_rvec12[] = { - (HALF)0xb4a0, (HALF)0xe207, (HALF)0xdd68, (HALF)0x5227, - (HALF)0xfbc4, (HALF)0x9488, (HALF)0x81aa, (HALF)0x6ed0, - (HALF)0x6fe5, (HALF)0x8e73, (HALF)0xc020, (HALF)0x3dd2, - (HALF)0x7c57, (HALF)0xeeb0, (HALF)0x4eb7, (HALF)0x0b60, - (HALF)0x72a1, (HALF)0xa13f, (HALF)0x4333, (HALF)0xcbfc, - (HALF)0xe8cd, (HALF)0xa4c5, (HALF)0x520d, (HALF)0x0add, - (HALF)0xa3b2, (HALF)0x758c, (HALF)0x0137, (HALF)0x5549, - (HALF)0xbabd, (HALF)0x5870, (HALF)0xed93, (HALF)0xf648, - (HALF)0x9bd1, (HALF)0xdf71 + (HALF)0xb4a0, (HALF)0xe207, (HALF)0xdd68, (HALF)0x5227, + (HALF)0xfbc4, (HALF)0x9488, (HALF)0x81aa, (HALF)0x6ed0, + (HALF)0x6fe5, (HALF)0x8e73, (HALF)0xc020, (HALF)0x3dd2, + (HALF)0x7c57, (HALF)0xeeb0, (HALF)0x4eb7, (HALF)0x0b60, + (HALF)0x72a1, (HALF)0xa13f, (HALF)0x4333, (HALF)0xcbfc, + (HALF)0xe8cd, (HALF)0xa4c5, (HALF)0x520d, (HALF)0x0add, + (HALF)0xa3b2, (HALF)0x758c, (HALF)0x0137, (HALF)0x5549, + (HALF)0xbabd, (HALF)0x5870, (HALF)0xed93, (HALF)0xf648, + (HALF)0x9bd1, (HALF)0xdf71 }; STATIC CONST HALF h_nvec13[] = { - (HALF)0xfc49, (HALF)0x3314, (HALF)0x0032, (HALF)0xcca2, - (HALF)0x3420, (HALF)0x208e, (HALF)0x503a, (HALF)0x8aaa, - (HALF)0x63cc, (HALF)0xd79a, (HALF)0x7417, (HALF)0xb4ed, - (HALF)0x1892, (HALF)0x95dd, (HALF)0x5f64, (HALF)0xb591, - (HALF)0xc7f1, (HALF)0xd14c, (HALF)0x917e, (HALF)0x1589, - (HALF)0x5667, (HALF)0xb2b0, (HALF)0x99cb, (HALF)0xc32d, - (HALF)0x1a84, (HALF)0x1b5a, (HALF)0x22a1, (HALF)0xa493, - (HALF)0x76c3, (HALF)0xdd3a, (HALF)0x137f, (HALF)0x8c07, - (HALF)0x3c63, (HALF)0xaaf8, (HALF)0x5113, (HALF)0x3757, - (HALF)0x8e84, (HALF)0xa8b1, (HALF)0x891d, (HALF)0xceec, - (HALF)0xee99, (HALF)0x78c1, (HALF)0xe256, (HALF)0x6e49, - (HALF)0xbfd6, (HALF)0x4286, (HALF)0xf6a9, (HALF)0xcb6b, - (HALF)0x8ee0, (HALF)0x7bda, (HALF)0x510a, (HALF)0xd439, - (HALF)0x345b, (HALF)0x63f4, (HALF)0x5535, (HALF)0x959a, - (HALF)0x6d82, (HALF)0xdaf6, (HALF)0xd833, (HALF)0xed03, - (HALF)0xf734, (HALF)0x1b5a, (HALF)0x7dd2, (HALF)0x166b, - (HALF)0x7c19, (HALF)0x0151 + (HALF)0xfc49, (HALF)0x3314, (HALF)0x0032, (HALF)0xcca2, + (HALF)0x3420, (HALF)0x208e, (HALF)0x503a, (HALF)0x8aaa, + (HALF)0x63cc, (HALF)0xd79a, (HALF)0x7417, (HALF)0xb4ed, + (HALF)0x1892, (HALF)0x95dd, (HALF)0x5f64, (HALF)0xb591, + (HALF)0xc7f1, (HALF)0xd14c, (HALF)0x917e, (HALF)0x1589, + (HALF)0x5667, (HALF)0xb2b0, (HALF)0x99cb, (HALF)0xc32d, + (HALF)0x1a84, (HALF)0x1b5a, (HALF)0x22a1, (HALF)0xa493, + (HALF)0x76c3, (HALF)0xdd3a, (HALF)0x137f, (HALF)0x8c07, + (HALF)0x3c63, (HALF)0xaaf8, (HALF)0x5113, (HALF)0x3757, + (HALF)0x8e84, (HALF)0xa8b1, (HALF)0x891d, (HALF)0xceec, + (HALF)0xee99, (HALF)0x78c1, (HALF)0xe256, (HALF)0x6e49, + (HALF)0xbfd6, (HALF)0x4286, (HALF)0xf6a9, (HALF)0xcb6b, + (HALF)0x8ee0, (HALF)0x7bda, (HALF)0x510a, (HALF)0xd439, + (HALF)0x345b, (HALF)0x63f4, (HALF)0x5535, (HALF)0x959a, + (HALF)0x6d82, (HALF)0xdaf6, (HALF)0xd833, (HALF)0xed03, + (HALF)0xf734, (HALF)0x1b5a, (HALF)0x7dd2, (HALF)0x166b, + (HALF)0x7c19, (HALF)0x0151 }; STATIC CONST HALF h_rvec13[] = { - (HALF)0x36f5, (HALF)0x6b77, (HALF)0xbfe4, (HALF)0x2407, - (HALF)0x2072, (HALF)0x965e, (HALF)0xcf3e, (HALF)0xcc26, - (HALF)0xb567, (HALF)0xa432, (HALF)0x07ab, (HALF)0x2ed0, - (HALF)0x67b9, (HALF)0x0e2f, (HALF)0x0960, (HALF)0xef64, - (HALF)0x1ad3, (HALF)0xbe5f, (HALF)0xda1b, (HALF)0x3fae, - (HALF)0xb988, (HALF)0xa8f6, (HALF)0xcea5, (HALF)0xe5c9, - (HALF)0x45ea, (HALF)0xa674, (HALF)0xce78, (HALF)0x3935, - (HALF)0xff06, (HALF)0xf445, (HALF)0x0a11, (HALF)0xbeda, - (HALF)0x080b, (HALF)0x92de, (HALF)0x9026, (HALF)0xf404, - (HALF)0xf0b8, (HALF)0xe509, (HALF)0x216f, (HALF)0x6f05, - (HALF)0xdc14, (HALF)0x5a68, (HALF)0x730d, (HALF)0x548f, - (HALF)0x9f00, (HALF)0xe9fd, (HALF)0xaada, (HALF)0x64a4, - (HALF)0xdd15, (HALF)0xe3bb, (HALF)0xe7a5, (HALF)0xcb4b, - (HALF)0xd162, (HALF)0x17dd, (HALF)0x8c33, (HALF)0xc491, - (HALF)0x6d2b, (HALF)0x9b70, (HALF)0xf6a6, (HALF)0x8b04, - (HALF)0xfa64, (HALF)0x1263, (HALF)0x560d, (HALF)0x8e9a, - (HALF)0xd42e + (HALF)0x36f5, (HALF)0x6b77, (HALF)0xbfe4, (HALF)0x2407, + (HALF)0x2072, (HALF)0x965e, (HALF)0xcf3e, (HALF)0xcc26, + (HALF)0xb567, (HALF)0xa432, (HALF)0x07ab, (HALF)0x2ed0, + (HALF)0x67b9, (HALF)0x0e2f, (HALF)0x0960, (HALF)0xef64, + (HALF)0x1ad3, (HALF)0xbe5f, (HALF)0xda1b, (HALF)0x3fae, + (HALF)0xb988, (HALF)0xa8f6, (HALF)0xcea5, (HALF)0xe5c9, + (HALF)0x45ea, (HALF)0xa674, (HALF)0xce78, (HALF)0x3935, + (HALF)0xff06, (HALF)0xf445, (HALF)0x0a11, (HALF)0xbeda, + (HALF)0x080b, (HALF)0x92de, (HALF)0x9026, (HALF)0xf404, + (HALF)0xf0b8, (HALF)0xe509, (HALF)0x216f, (HALF)0x6f05, + (HALF)0xdc14, (HALF)0x5a68, (HALF)0x730d, (HALF)0x548f, + (HALF)0x9f00, (HALF)0xe9fd, (HALF)0xaada, (HALF)0x64a4, + (HALF)0xdd15, (HALF)0xe3bb, (HALF)0xe7a5, (HALF)0xcb4b, + (HALF)0xd162, (HALF)0x17dd, (HALF)0x8c33, (HALF)0xc491, + (HALF)0x6d2b, (HALF)0x9b70, (HALF)0xf6a6, (HALF)0x8b04, + (HALF)0xfa64, (HALF)0x1263, (HALF)0x560d, (HALF)0x8e9a, + (HALF)0xd42e }; STATIC CONST HALF h_nvec14[] = { - (HALF)0xaf01, (HALF)0xc116, (HALF)0x8c0f, (HALF)0xbdef, - (HALF)0x9a1a, (HALF)0xc440, (HALF)0x185c, (HALF)0xacb3, - (HALF)0x925b, (HALF)0xb33f, (HALF)0x3005, (HALF)0xfee8, - (HALF)0xb112, (HALF)0x4b3d, (HALF)0x6743, (HALF)0x7f07, - (HALF)0x9223, (HALF)0x2170, (HALF)0x054b, (HALF)0x2159, - (HALF)0xefe3, (HALF)0x6fdf, (HALF)0x0a07, (HALF)0x792d, - (HALF)0xbd52, (HALF)0x1d14, (HALF)0x9a27, (HALF)0x5f28, - (HALF)0x83c4, (HALF)0xe034, (HALF)0xa0c1, (HALF)0xcb86, - (HALF)0x912a, (HALF)0x0ede, (HALF)0x33e3, (HALF)0xf01a, - (HALF)0x40c6, (HALF)0x63fd, (HALF)0x86e4, (HALF)0x4b05, - (HALF)0x4a03, (HALF)0xbc7e, (HALF)0x22f3, (HALF)0x956b, - (HALF)0x0b22, (HALF)0x1056, (HALF)0xd321, (HALF)0x3e78, - (HALF)0x61e2, (HALF)0x1791, (HALF)0xb909, (HALF)0xe85e, - (HALF)0x31ee, (HALF)0xec79, (HALF)0xb4bf, (HALF)0xb314, - (HALF)0x4618, (HALF)0x1f56, (HALF)0x83d0, (HALF)0xb9d9, - (HALF)0xac07, (HALF)0x7479, (HALF)0xf4e8, (HALF)0x93c6, - (HALF)0xa00e, (HALF)0x5e56 + (HALF)0xaf01, (HALF)0xc116, (HALF)0x8c0f, (HALF)0xbdef, + (HALF)0x9a1a, (HALF)0xc440, (HALF)0x185c, (HALF)0xacb3, + (HALF)0x925b, (HALF)0xb33f, (HALF)0x3005, (HALF)0xfee8, + (HALF)0xb112, (HALF)0x4b3d, (HALF)0x6743, (HALF)0x7f07, + (HALF)0x9223, (HALF)0x2170, (HALF)0x054b, (HALF)0x2159, + (HALF)0xefe3, (HALF)0x6fdf, (HALF)0x0a07, (HALF)0x792d, + (HALF)0xbd52, (HALF)0x1d14, (HALF)0x9a27, (HALF)0x5f28, + (HALF)0x83c4, (HALF)0xe034, (HALF)0xa0c1, (HALF)0xcb86, + (HALF)0x912a, (HALF)0x0ede, (HALF)0x33e3, (HALF)0xf01a, + (HALF)0x40c6, (HALF)0x63fd, (HALF)0x86e4, (HALF)0x4b05, + (HALF)0x4a03, (HALF)0xbc7e, (HALF)0x22f3, (HALF)0x956b, + (HALF)0x0b22, (HALF)0x1056, (HALF)0xd321, (HALF)0x3e78, + (HALF)0x61e2, (HALF)0x1791, (HALF)0xb909, (HALF)0xe85e, + (HALF)0x31ee, (HALF)0xec79, (HALF)0xb4bf, (HALF)0xb314, + (HALF)0x4618, (HALF)0x1f56, (HALF)0x83d0, (HALF)0xb9d9, + (HALF)0xac07, (HALF)0x7479, (HALF)0xf4e8, (HALF)0x93c6, + (HALF)0xa00e, (HALF)0x5e56 }; STATIC CONST HALF h_rvec14[] = { - (HALF)0xf190, (HALF)0x0ff9, (HALF)0xdb68, (HALF)0x47a4, - (HALF)0xc8ea, (HALF)0x913c, (HALF)0xb220, (HALF)0xb6b1, - (HALF)0xfbbb, (HALF)0x13ed, (HALF)0xf1c3, (HALF)0xa8f1, - (HALF)0x1f8f, (HALF)0xd6d7, (HALF)0x649a, (HALF)0x4194, - (HALF)0x7344, (HALF)0x7d49, (HALF)0x8416, (HALF)0x677c, - (HALF)0xb983, (HALF)0x0186, (HALF)0x3901, (HALF)0xee63, - (HALF)0xd69d, (HALF)0xce64, (HALF)0x04b3, (HALF)0x61a7, - (HALF)0x52b2, (HALF)0x1383, (HALF)0x58d8, (HALF)0xc0fb, - (HALF)0x2073, (HALF)0x16bf, (HALF)0xae78, (HALF)0x56c9, - (HALF)0x0a68, (HALF)0xb81a, (HALF)0xabaf, (HALF)0x1512, - (HALF)0x36ba, (HALF)0x6b99, (HALF)0x0dfc, (HALF)0x4335, - (HALF)0x19d2, (HALF)0xa0ea, (HALF)0x34c5, (HALF)0xe861, - (HALF)0x563f, (HALF)0x6c86, (HALF)0x5b68, (HALF)0x6b0c, - (HALF)0x27fc, (HALF)0x75f6, (HALF)0x913f, (HALF)0xb609, - (HALF)0xa564, (HALF)0x15b9, (HALF)0xf154, (HALF)0x9b18, - (HALF)0xc5d0, (HALF)0x6ef0, (HALF)0x3509, (HALF)0xb673, - (HALF)0xaa7c, (HALF)0x00f7 + (HALF)0xf190, (HALF)0x0ff9, (HALF)0xdb68, (HALF)0x47a4, + (HALF)0xc8ea, (HALF)0x913c, (HALF)0xb220, (HALF)0xb6b1, + (HALF)0xfbbb, (HALF)0x13ed, (HALF)0xf1c3, (HALF)0xa8f1, + (HALF)0x1f8f, (HALF)0xd6d7, (HALF)0x649a, (HALF)0x4194, + (HALF)0x7344, (HALF)0x7d49, (HALF)0x8416, (HALF)0x677c, + (HALF)0xb983, (HALF)0x0186, (HALF)0x3901, (HALF)0xee63, + (HALF)0xd69d, (HALF)0xce64, (HALF)0x04b3, (HALF)0x61a7, + (HALF)0x52b2, (HALF)0x1383, (HALF)0x58d8, (HALF)0xc0fb, + (HALF)0x2073, (HALF)0x16bf, (HALF)0xae78, (HALF)0x56c9, + (HALF)0x0a68, (HALF)0xb81a, (HALF)0xabaf, (HALF)0x1512, + (HALF)0x36ba, (HALF)0x6b99, (HALF)0x0dfc, (HALF)0x4335, + (HALF)0x19d2, (HALF)0xa0ea, (HALF)0x34c5, (HALF)0xe861, + (HALF)0x563f, (HALF)0x6c86, (HALF)0x5b68, (HALF)0x6b0c, + (HALF)0x27fc, (HALF)0x75f6, (HALF)0x913f, (HALF)0xb609, + (HALF)0xa564, (HALF)0x15b9, (HALF)0xf154, (HALF)0x9b18, + (HALF)0xc5d0, (HALF)0x6ef0, (HALF)0x3509, (HALF)0xb673, + (HALF)0xaa7c, (HALF)0x00f7 }; STATIC CONST HALF h_nvec15[] = { - (HALF)0x7079, (HALF)0xc8d9, (HALF)0x7597, (HALF)0x061e, - (HALF)0xc721, (HALF)0xf5d2, (HALF)0xc51f, (HALF)0x299b, - (HALF)0xc337, (HALF)0xffe6, (HALF)0x8624, (HALF)0x1979, - (HALF)0x92b6, (HALF)0xee6f, (HALF)0x0c7a, (HALF)0x0b1d, - (HALF)0x8231, (HALF)0xb530, (HALF)0x58dd, (HALF)0x49c5, - (HALF)0x530e, (HALF)0x196a, (HALF)0x515c, (HALF)0x0caa, - (HALF)0x86ed, (HALF)0x8b0d, (HALF)0x8fa0, (HALF)0x380a, - (HALF)0x03e4, (HALF)0x80df, (HALF)0xd81b, (HALF)0xe962, - (HALF)0x83b3, (HALF)0xc1a7, (HALF)0x8ccc, (HALF)0xc327, - (HALF)0xab86, (HALF)0x3e72, (HALF)0x1675, (HALF)0xebb9, - (HALF)0xc2b8, (HALF)0xb902, (HALF)0x0445, (HALF)0xa059, - (HALF)0xde42, (HALF)0x4f40, (HALF)0xaac1, (HALF)0xaa95, - (HALF)0x2e82, (HALF)0xfc0f, (HALF)0xb84b, (HALF)0x70ca, - (HALF)0xa267, (HALF)0x5326, (HALF)0xe607, (HALF)0x470b, - (HALF)0x2ebe, (HALF)0x4535, (HALF)0x1ca8, (HALF)0x5ba8, - (HALF)0x6c17, (HALF)0x02c4, (HALF)0xbcdb, (HALF)0x9edf, - (HALF)0x840b, (HALF)0x97dd + (HALF)0x7079, (HALF)0xc8d9, (HALF)0x7597, (HALF)0x061e, + (HALF)0xc721, (HALF)0xf5d2, (HALF)0xc51f, (HALF)0x299b, + (HALF)0xc337, (HALF)0xffe6, (HALF)0x8624, (HALF)0x1979, + (HALF)0x92b6, (HALF)0xee6f, (HALF)0x0c7a, (HALF)0x0b1d, + (HALF)0x8231, (HALF)0xb530, (HALF)0x58dd, (HALF)0x49c5, + (HALF)0x530e, (HALF)0x196a, (HALF)0x515c, (HALF)0x0caa, + (HALF)0x86ed, (HALF)0x8b0d, (HALF)0x8fa0, (HALF)0x380a, + (HALF)0x03e4, (HALF)0x80df, (HALF)0xd81b, (HALF)0xe962, + (HALF)0x83b3, (HALF)0xc1a7, (HALF)0x8ccc, (HALF)0xc327, + (HALF)0xab86, (HALF)0x3e72, (HALF)0x1675, (HALF)0xebb9, + (HALF)0xc2b8, (HALF)0xb902, (HALF)0x0445, (HALF)0xa059, + (HALF)0xde42, (HALF)0x4f40, (HALF)0xaac1, (HALF)0xaa95, + (HALF)0x2e82, (HALF)0xfc0f, (HALF)0xb84b, (HALF)0x70ca, + (HALF)0xa267, (HALF)0x5326, (HALF)0xe607, (HALF)0x470b, + (HALF)0x2ebe, (HALF)0x4535, (HALF)0x1ca8, (HALF)0x5ba8, + (HALF)0x6c17, (HALF)0x02c4, (HALF)0xbcdb, (HALF)0x9edf, + (HALF)0x840b, (HALF)0x97dd }; STATIC CONST HALF h_rvec15[] = { - (HALF)0x2110, (HALF)0x6c3e, (HALF)0x0aaa, (HALF)0x808f, - (HALF)0xb92e, (HALF)0xd98d, (HALF)0xbd43, (HALF)0x1e6a, - (HALF)0xb920, (HALF)0xf401, (HALF)0x0381, (HALF)0x9d3f, - (HALF)0xd174, (HALF)0xdb95, (HALF)0x5c33, (HALF)0xa2f6, - (HALF)0x69f8, (HALF)0x0c54, (HALF)0x26fc, (HALF)0xa3c1, - (HALF)0x241b, (HALF)0x8866, (HALF)0xeca7, (HALF)0x0e46, - (HALF)0x57fa, (HALF)0xa705, (HALF)0x91a6, (HALF)0x8e73, - (HALF)0xa9e2, (HALF)0x70e4, (HALF)0x7e89, (HALF)0x9ad9, - (HALF)0x7dee, (HALF)0x1eb7, (HALF)0x24d0, (HALF)0xfe62, - (HALF)0x22b1, (HALF)0xdbe5, (HALF)0x1023, (HALF)0xa4aa, - (HALF)0x6860, (HALF)0x7f22, (HALF)0x4379, (HALF)0x60ef, - (HALF)0xb296, (HALF)0x45e3, (HALF)0xf5ef, (HALF)0xcc31, - (HALF)0xf6d6, (HALF)0x74fb, (HALF)0xc25d, (HALF)0x55b1, - (HALF)0x521f, (HALF)0x3ede, (HALF)0xef42, (HALF)0xdf8c, - (HALF)0x7ca6, (HALF)0xa8d7, (HALF)0x25da, (HALF)0xb500, - (HALF)0x99f9, (HALF)0x69ab, (HALF)0xc758, (HALF)0x03b8, - (HALF)0x2207, (HALF)0x00b8 + (HALF)0x2110, (HALF)0x6c3e, (HALF)0x0aaa, (HALF)0x808f, + (HALF)0xb92e, (HALF)0xd98d, (HALF)0xbd43, (HALF)0x1e6a, + (HALF)0xb920, (HALF)0xf401, (HALF)0x0381, (HALF)0x9d3f, + (HALF)0xd174, (HALF)0xdb95, (HALF)0x5c33, (HALF)0xa2f6, + (HALF)0x69f8, (HALF)0x0c54, (HALF)0x26fc, (HALF)0xa3c1, + (HALF)0x241b, (HALF)0x8866, (HALF)0xeca7, (HALF)0x0e46, + (HALF)0x57fa, (HALF)0xa705, (HALF)0x91a6, (HALF)0x8e73, + (HALF)0xa9e2, (HALF)0x70e4, (HALF)0x7e89, (HALF)0x9ad9, + (HALF)0x7dee, (HALF)0x1eb7, (HALF)0x24d0, (HALF)0xfe62, + (HALF)0x22b1, (HALF)0xdbe5, (HALF)0x1023, (HALF)0xa4aa, + (HALF)0x6860, (HALF)0x7f22, (HALF)0x4379, (HALF)0x60ef, + (HALF)0xb296, (HALF)0x45e3, (HALF)0xf5ef, (HALF)0xcc31, + (HALF)0xf6d6, (HALF)0x74fb, (HALF)0xc25d, (HALF)0x55b1, + (HALF)0x521f, (HALF)0x3ede, (HALF)0xef42, (HALF)0xdf8c, + (HALF)0x7ca6, (HALF)0xa8d7, (HALF)0x25da, (HALF)0xb500, + (HALF)0x99f9, (HALF)0x69ab, (HALF)0xc758, (HALF)0x03b8, + (HALF)0x2207, (HALF)0x00b8 }; STATIC CONST HALF h_nvec16[] = { - (HALF)0x46e1, (HALF)0xd843, (HALF)0x83f6, (HALF)0x1841, - (HALF)0xbd36, (HALF)0x2dc9, (HALF)0x57ac, (HALF)0x4ca8, - (HALF)0x828d, (HALF)0x96a5, (HALF)0x1c59, (HALF)0xed1f, - (HALF)0x731f, (HALF)0x36d9, (HALF)0x6183, (HALF)0xbd3f, - (HALF)0x5578, (HALF)0xde0f, (HALF)0xea8a, (HALF)0xb6a2, - (HALF)0x3c44, (HALF)0xbe99, (HALF)0x3c05, (HALF)0x0e28, - (HALF)0x61e3, (HALF)0xd7cf, (HALF)0x15b6, (HALF)0x40fe, - (HALF)0x967e, (HALF)0x534d, (HALF)0x1046, (HALF)0x3469, - (HALF)0x45bd, (HALF)0xd408, (HALF)0xee4b, (HALF)0xd69c, - (HALF)0xee8d, (HALF)0x557f, (HALF)0x56ba, (HALF)0x51c8, - (HALF)0x51ba, (HALF)0xe6bc, (HALF)0xc173, (HALF)0x587b, - (HALF)0xe379, (HALF)0x1959, (HALF)0x8439, (HALF)0x9282, - (HALF)0x0503, (HALF)0x311e, (HALF)0x9cc2, (HALF)0x7f3c, - (HALF)0x512c, (HALF)0xd426, (HALF)0xb497, (HALF)0xe8b2, - (HALF)0x536a, (HALF)0x9e43, (HALF)0x4cb8, (HALF)0x9f54, - (HALF)0x84c3, (HALF)0xb56f, (HALF)0xbb12, (HALF)0xb82f, - (HALF)0x8549, (HALF)0x6e34, (HALF)0x45 + (HALF)0x46e1, (HALF)0xd843, (HALF)0x83f6, (HALF)0x1841, + (HALF)0xbd36, (HALF)0x2dc9, (HALF)0x57ac, (HALF)0x4ca8, + (HALF)0x828d, (HALF)0x96a5, (HALF)0x1c59, (HALF)0xed1f, + (HALF)0x731f, (HALF)0x36d9, (HALF)0x6183, (HALF)0xbd3f, + (HALF)0x5578, (HALF)0xde0f, (HALF)0xea8a, (HALF)0xb6a2, + (HALF)0x3c44, (HALF)0xbe99, (HALF)0x3c05, (HALF)0x0e28, + (HALF)0x61e3, (HALF)0xd7cf, (HALF)0x15b6, (HALF)0x40fe, + (HALF)0x967e, (HALF)0x534d, (HALF)0x1046, (HALF)0x3469, + (HALF)0x45bd, (HALF)0xd408, (HALF)0xee4b, (HALF)0xd69c, + (HALF)0xee8d, (HALF)0x557f, (HALF)0x56ba, (HALF)0x51c8, + (HALF)0x51ba, (HALF)0xe6bc, (HALF)0xc173, (HALF)0x587b, + (HALF)0xe379, (HALF)0x1959, (HALF)0x8439, (HALF)0x9282, + (HALF)0x0503, (HALF)0x311e, (HALF)0x9cc2, (HALF)0x7f3c, + (HALF)0x512c, (HALF)0xd426, (HALF)0xb497, (HALF)0xe8b2, + (HALF)0x536a, (HALF)0x9e43, (HALF)0x4cb8, (HALF)0x9f54, + (HALF)0x84c3, (HALF)0xb56f, (HALF)0xbb12, (HALF)0xb82f, + (HALF)0x8549, (HALF)0x6e34, (HALF)0x45 }; STATIC CONST HALF h_rvec16[] = { - (HALF)0x8830, (HALF)0x7b4e, (HALF)0x5db8, (HALF)0x7060, (HALF)0xe4a5, - (HALF)0xa1ab, (HALF)0xbe04, (HALF)0xa70f, - (HALF)0xa8f4, (HALF)0x2bcd, (HALF)0xda9a, (HALF)0xd29a, - (HALF)0x0560, (HALF)0x55ad, (HALF)0x137e, (HALF)0xb367, - (HALF)0x2f1a, (HALF)0xd697, (HALF)0xad45, (HALF)0x809b, - (HALF)0x2454, (HALF)0xb15d, (HALF)0x415f, (HALF)0x0c0d, - (HALF)0x117a, (HALF)0x416e, (HALF)0x9521, (HALF)0xe87a, - (HALF)0x5e1a, (HALF)0x670a, (HALF)0x1772, (HALF)0x53a4, - (HALF)0x5cc1, (HALF)0xfc9c, (HALF)0x45df, (HALF)0xf756, - (HALF)0xd19f, (HALF)0x86f6, (HALF)0xb5bf, (HALF)0x9404, - (HALF)0xd83b, (HALF)0x56e9, (HALF)0x3bc3, (HALF)0xac0f, - (HALF)0x8c4b, (HALF)0xa150, (HALF)0x4977, (HALF)0x4bfd, - (HALF)0x2540, (HALF)0x7192, (HALF)0x4def, (HALF)0xf252, - (HALF)0xa3db, (HALF)0x8a81, (HALF)0x28de, (HALF)0xced8, - (HALF)0xae8f, (HALF)0x7895, (HALF)0x6dcd, (HALF)0x4a4b, - (HALF)0x921a, (HALF)0x973e, (HALF)0x7a07, (HALF)0x9fb2, - (HALF)0xdcb1, (HALF)0xb0d7 + (HALF)0x8830, (HALF)0x7b4e, (HALF)0x5db8, (HALF)0x7060, (HALF)0xe4a5, + (HALF)0xa1ab, (HALF)0xbe04, (HALF)0xa70f, + (HALF)0xa8f4, (HALF)0x2bcd, (HALF)0xda9a, (HALF)0xd29a, + (HALF)0x0560, (HALF)0x55ad, (HALF)0x137e, (HALF)0xb367, + (HALF)0x2f1a, (HALF)0xd697, (HALF)0xad45, (HALF)0x809b, + (HALF)0x2454, (HALF)0xb15d, (HALF)0x415f, (HALF)0x0c0d, + (HALF)0x117a, (HALF)0x416e, (HALF)0x9521, (HALF)0xe87a, + (HALF)0x5e1a, (HALF)0x670a, (HALF)0x1772, (HALF)0x53a4, + (HALF)0x5cc1, (HALF)0xfc9c, (HALF)0x45df, (HALF)0xf756, + (HALF)0xd19f, (HALF)0x86f6, (HALF)0xb5bf, (HALF)0x9404, + (HALF)0xd83b, (HALF)0x56e9, (HALF)0x3bc3, (HALF)0xac0f, + (HALF)0x8c4b, (HALF)0xa150, (HALF)0x4977, (HALF)0x4bfd, + (HALF)0x2540, (HALF)0x7192, (HALF)0x4def, (HALF)0xf252, + (HALF)0xa3db, (HALF)0x8a81, (HALF)0x28de, (HALF)0xced8, + (HALF)0xae8f, (HALF)0x7895, (HALF)0x6dcd, (HALF)0x4a4b, + (HALF)0x921a, (HALF)0x973e, (HALF)0x7a07, (HALF)0x9fb2, + (HALF)0xdcb1, (HALF)0xb0d7 }; STATIC CONST HALF h_nvec17[] = { - (HALF)0x2051, (HALF)0x72b7, (HALF)0x4ebf, (HALF)0xedc2, - (HALF)0xa8d1, (HALF)0xe970, (HALF)0xb150, (HALF)0x66c9, - (HALF)0x27f7, (HALF)0xcbb9, (HALF)0xffd9, (HALF)0xb574, - (HALF)0xb249, (HALF)0x4166, (HALF)0x4030, (HALF)0x0fce, - (HALF)0x22ca, (HALF)0xfa69, (HALF)0x14a9, (HALF)0x39cc, - (HALF)0x6e2a, (HALF)0x1439, (HALF)0x4c7f, (HALF)0xaff7, - (HALF)0xa314, (HALF)0xa120, (HALF)0x2700, (HALF)0xe11a, - (HALF)0xad30, (HALF)0x44c9, (HALF)0x8d72, (HALF)0x7f32, - (HALF)0xeaf7, (HALF)0xab2c, (HALF)0xf772, (HALF)0x868f, - (HALF)0xf0b3, (HALF)0x0974, (HALF)0xf0f6, (HALF)0x20e9, - (HALF)0x5b8a, (HALF)0xcd4e, (HALF)0x26e6, (HALF)0x0bde, - (HALF)0xc3ac, (HALF)0x96f6, (HALF)0xc601, (HALF)0x5718, - (HALF)0x7710, (HALF)0x2f11, (HALF)0x876e, (HALF)0x1ab0, - (HALF)0x2c2e, (HALF)0x49ab, (HALF)0x22b9, (HALF)0x7470, - (HALF)0xe4a7, (HALF)0x6e9d, (HALF)0x8f2e, (HALF)0x25e8, - (HALF)0xa00b, (HALF)0xd7d0, (HALF)0x11f6, (HALF)0xc8ff, - (HALF)0xa819, (HALF)0xf50a, (HALF)0x0e9e, (HALF)0xbe53, - (HALF)0xff54, (HALF)0x47b7, (HALF)0x9b46, (HALF)0xe020, - (HALF)0xc5eb, (HALF)0x027e, (HALF)0x3362, (HALF)0x0754, - (HALF)0x9b85, (HALF)0x531e, (HALF)0xb568, (HALF)0x3c23, - (HALF)0xaf7a, (HALF)0x5d07, (HALF)0x8461, (HALF)0xd494, - (HALF)0xa499, (HALF)0x2eb9, (HALF)0xfa0b, (HALF)0x1c71, - (HALF)0xe22b, (HALF)0x7025, (HALF)0x20b9, (HALF)0x4d27, - (HALF)0x8d54, (HALF)0x531b, (HALF)0xfc30, (HALF)0x66e2, - (HALF)0xcafd, (HALF)0xdac7, (HALF)0x953b, (HALF)0x7f29, - (HALF)0x6bff, (HALF)0x9d45, (HALF)0x14bc, (HALF)0x8398, - (HALF)0xfb19, (HALF)0xd0e5, (HALF)0x9f58, (HALF)0x5a6c, - (HALF)0x9dc3, (HALF)0x3a5a, (HALF)0xf28b, (HALF)0x598b, - (HALF)0x1144, (HALF)0xa7a9, (HALF)0x4f76, (HALF)0x6849, - (HALF)0xd7be, (HALF)0xbfed, (HALF)0x4266, (HALF)0x7ca5, - (HALF)0xfaf9, (HALF)0x96e0, (HALF)0x3c0f, (HALF)0x33be, - (HALF)0x040b, (HALF)0xffa3, (HALF)0xeac0, (HALF)0x813a, - (HALF)0x6177 + (HALF)0x2051, (HALF)0x72b7, (HALF)0x4ebf, (HALF)0xedc2, + (HALF)0xa8d1, (HALF)0xe970, (HALF)0xb150, (HALF)0x66c9, + (HALF)0x27f7, (HALF)0xcbb9, (HALF)0xffd9, (HALF)0xb574, + (HALF)0xb249, (HALF)0x4166, (HALF)0x4030, (HALF)0x0fce, + (HALF)0x22ca, (HALF)0xfa69, (HALF)0x14a9, (HALF)0x39cc, + (HALF)0x6e2a, (HALF)0x1439, (HALF)0x4c7f, (HALF)0xaff7, + (HALF)0xa314, (HALF)0xa120, (HALF)0x2700, (HALF)0xe11a, + (HALF)0xad30, (HALF)0x44c9, (HALF)0x8d72, (HALF)0x7f32, + (HALF)0xeaf7, (HALF)0xab2c, (HALF)0xf772, (HALF)0x868f, + (HALF)0xf0b3, (HALF)0x0974, (HALF)0xf0f6, (HALF)0x20e9, + (HALF)0x5b8a, (HALF)0xcd4e, (HALF)0x26e6, (HALF)0x0bde, + (HALF)0xc3ac, (HALF)0x96f6, (HALF)0xc601, (HALF)0x5718, + (HALF)0x7710, (HALF)0x2f11, (HALF)0x876e, (HALF)0x1ab0, + (HALF)0x2c2e, (HALF)0x49ab, (HALF)0x22b9, (HALF)0x7470, + (HALF)0xe4a7, (HALF)0x6e9d, (HALF)0x8f2e, (HALF)0x25e8, + (HALF)0xa00b, (HALF)0xd7d0, (HALF)0x11f6, (HALF)0xc8ff, + (HALF)0xa819, (HALF)0xf50a, (HALF)0x0e9e, (HALF)0xbe53, + (HALF)0xff54, (HALF)0x47b7, (HALF)0x9b46, (HALF)0xe020, + (HALF)0xc5eb, (HALF)0x027e, (HALF)0x3362, (HALF)0x0754, + (HALF)0x9b85, (HALF)0x531e, (HALF)0xb568, (HALF)0x3c23, + (HALF)0xaf7a, (HALF)0x5d07, (HALF)0x8461, (HALF)0xd494, + (HALF)0xa499, (HALF)0x2eb9, (HALF)0xfa0b, (HALF)0x1c71, + (HALF)0xe22b, (HALF)0x7025, (HALF)0x20b9, (HALF)0x4d27, + (HALF)0x8d54, (HALF)0x531b, (HALF)0xfc30, (HALF)0x66e2, + (HALF)0xcafd, (HALF)0xdac7, (HALF)0x953b, (HALF)0x7f29, + (HALF)0x6bff, (HALF)0x9d45, (HALF)0x14bc, (HALF)0x8398, + (HALF)0xfb19, (HALF)0xd0e5, (HALF)0x9f58, (HALF)0x5a6c, + (HALF)0x9dc3, (HALF)0x3a5a, (HALF)0xf28b, (HALF)0x598b, + (HALF)0x1144, (HALF)0xa7a9, (HALF)0x4f76, (HALF)0x6849, + (HALF)0xd7be, (HALF)0xbfed, (HALF)0x4266, (HALF)0x7ca5, + (HALF)0xfaf9, (HALF)0x96e0, (HALF)0x3c0f, (HALF)0x33be, + (HALF)0x040b, (HALF)0xffa3, (HALF)0xeac0, (HALF)0x813a, + (HALF)0x6177 }; STATIC CONST HALF h_rvec17[] = { - (HALF)0x1dac, (HALF)0x22b4, (HALF)0x8005, (HALF)0xd625, - (HALF)0xe0cb, (HALF)0x2aa1, (HALF)0x47b5, (HALF)0x45d1, - (HALF)0x46d9, (HALF)0xbf5c, (HALF)0xdadf, (HALF)0x14c9, - (HALF)0xaec4, (HALF)0x09b0, (HALF)0xbfef, (HALF)0x4286, - (HALF)0xe9d1, (HALF)0xc6f8, (HALF)0x467b, (HALF)0xdd68, - (HALF)0xffb9, (HALF)0x93f4, (HALF)0xeb51, (HALF)0x58f2, - (HALF)0x048f, (HALF)0x2ade, (HALF)0xe6e5, (HALF)0xeaca, - (HALF)0xa807, (HALF)0x8dd2, (HALF)0x8c27, (HALF)0xbcea, - (HALF)0x3281, (HALF)0x02a0, (HALF)0xeb6d, (HALF)0x039a, - (HALF)0x016c, (HALF)0xfa6e, (HALF)0x1b09, (HALF)0x6fda, - (HALF)0x19ed, (HALF)0xea77, (HALF)0x0294, (HALF)0xcf2e, - (HALF)0x4cb9, (HALF)0xa426, (HALF)0x8af1, (HALF)0x4988, - (HALF)0xf0c1, (HALF)0x1b44, (HALF)0xe577, (HALF)0x3cce, - (HALF)0xd170, (HALF)0xdbeb, (HALF)0x1e7e, (HALF)0xf743, - (HALF)0xd584, (HALF)0xfaeb, (HALF)0x4a33, (HALF)0x896e, - (HALF)0xf43c, (HALF)0xe46b, (HALF)0x9a10, (HALF)0x17fe, - (HALF)0x1b51, (HALF)0xb532, (HALF)0xd2a9, (HALF)0xf7e1, - (HALF)0x0a56, (HALF)0xe7fe, (HALF)0x6750, (HALF)0xbd73, - (HALF)0x9a33, (HALF)0xcf02, (HALF)0x99b1, (HALF)0xebee, - (HALF)0xff31, (HALF)0x810f, (HALF)0x8d30, (HALF)0x694c, - (HALF)0x8689, (HALF)0xc8c1, (HALF)0xf4fb, (HALF)0xc2f9, - (HALF)0xfd7f, (HALF)0x5949, (HALF)0xf7b3, (HALF)0x67aa, - (HALF)0x906a, (HALF)0xa82f, (HALF)0xb7b3, (HALF)0x1b84, - (HALF)0x52ee, (HALF)0xeac0, (HALF)0x9345, (HALF)0x1a4e, - (HALF)0x2973, (HALF)0xce3c, (HALF)0x68a7, (HALF)0x4a51, - (HALF)0x51ba, (HALF)0x5c55, (HALF)0xcb26, (HALF)0x77c6, - (HALF)0xa3a6, (HALF)0xfa45, (HALF)0x31e0, (HALF)0x486f, - (HALF)0x7519, (HALF)0xcaf9, (HALF)0x0399, (HALF)0xbe4b, - (HALF)0xc106, (HALF)0x802f, (HALF)0x84da, (HALF)0x5372, - (HALF)0xe167, (HALF)0x20c4, (HALF)0xf329, (HALF)0x2a62, - (HALF)0xfc5b, (HALF)0xc2d2, (HALF)0x5324, (HALF)0xdd66, - (HALF)0xadf1, (HALF)0xc3b8, (HALF)0xaf3b, (HALF)0x0b6e, - (HALF)0x5372 + (HALF)0x1dac, (HALF)0x22b4, (HALF)0x8005, (HALF)0xd625, + (HALF)0xe0cb, (HALF)0x2aa1, (HALF)0x47b5, (HALF)0x45d1, + (HALF)0x46d9, (HALF)0xbf5c, (HALF)0xdadf, (HALF)0x14c9, + (HALF)0xaec4, (HALF)0x09b0, (HALF)0xbfef, (HALF)0x4286, + (HALF)0xe9d1, (HALF)0xc6f8, (HALF)0x467b, (HALF)0xdd68, + (HALF)0xffb9, (HALF)0x93f4, (HALF)0xeb51, (HALF)0x58f2, + (HALF)0x048f, (HALF)0x2ade, (HALF)0xe6e5, (HALF)0xeaca, + (HALF)0xa807, (HALF)0x8dd2, (HALF)0x8c27, (HALF)0xbcea, + (HALF)0x3281, (HALF)0x02a0, (HALF)0xeb6d, (HALF)0x039a, + (HALF)0x016c, (HALF)0xfa6e, (HALF)0x1b09, (HALF)0x6fda, + (HALF)0x19ed, (HALF)0xea77, (HALF)0x0294, (HALF)0xcf2e, + (HALF)0x4cb9, (HALF)0xa426, (HALF)0x8af1, (HALF)0x4988, + (HALF)0xf0c1, (HALF)0x1b44, (HALF)0xe577, (HALF)0x3cce, + (HALF)0xd170, (HALF)0xdbeb, (HALF)0x1e7e, (HALF)0xf743, + (HALF)0xd584, (HALF)0xfaeb, (HALF)0x4a33, (HALF)0x896e, + (HALF)0xf43c, (HALF)0xe46b, (HALF)0x9a10, (HALF)0x17fe, + (HALF)0x1b51, (HALF)0xb532, (HALF)0xd2a9, (HALF)0xf7e1, + (HALF)0x0a56, (HALF)0xe7fe, (HALF)0x6750, (HALF)0xbd73, + (HALF)0x9a33, (HALF)0xcf02, (HALF)0x99b1, (HALF)0xebee, + (HALF)0xff31, (HALF)0x810f, (HALF)0x8d30, (HALF)0x694c, + (HALF)0x8689, (HALF)0xc8c1, (HALF)0xf4fb, (HALF)0xc2f9, + (HALF)0xfd7f, (HALF)0x5949, (HALF)0xf7b3, (HALF)0x67aa, + (HALF)0x906a, (HALF)0xa82f, (HALF)0xb7b3, (HALF)0x1b84, + (HALF)0x52ee, (HALF)0xeac0, (HALF)0x9345, (HALF)0x1a4e, + (HALF)0x2973, (HALF)0xce3c, (HALF)0x68a7, (HALF)0x4a51, + (HALF)0x51ba, (HALF)0x5c55, (HALF)0xcb26, (HALF)0x77c6, + (HALF)0xa3a6, (HALF)0xfa45, (HALF)0x31e0, (HALF)0x486f, + (HALF)0x7519, (HALF)0xcaf9, (HALF)0x0399, (HALF)0xbe4b, + (HALF)0xc106, (HALF)0x802f, (HALF)0x84da, (HALF)0x5372, + (HALF)0xe167, (HALF)0x20c4, (HALF)0xf329, (HALF)0x2a62, + (HALF)0xfc5b, (HALF)0xc2d2, (HALF)0x5324, (HALF)0xdd66, + (HALF)0xadf1, (HALF)0xc3b8, (HALF)0xaf3b, (HALF)0x0b6e, + (HALF)0x5372 }; STATIC CONST HALF h_nvec18[] = { - (HALF)0x8629, (HALF)0xc8b7, (HALF)0x1b18, (HALF)0x4135, (HALF)0x4ed8, - (HALF)0x28ad, (HALF)0x7df1, (HALF)0xc96f, - (HALF)0xc931, (HALF)0x7cd3, (HALF)0x036a, (HALF)0x0f23, - (HALF)0x7631, (HALF)0xac65, (HALF)0x5812, (HALF)0x6a62, - (HALF)0x4788, (HALF)0x0814, (HALF)0xed62, (HALF)0x8642, - (HALF)0x8a40, (HALF)0x7619, (HALF)0xfd64, (HALF)0x70de, - (HALF)0x673c, (HALF)0x97fb, (HALF)0xddf6, (HALF)0x6f3b, - (HALF)0x2977, (HALF)0x72fe, (HALF)0x82f1, (HALF)0x20ed, - (HALF)0x4fdc, (HALF)0x7e7f, (HALF)0x2d6b, (HALF)0xdc27, - (HALF)0xf317, (HALF)0x6d77, (HALF)0x5b15, (HALF)0x2c59, - (HALF)0x7dd6, (HALF)0x1c3b, (HALF)0x6147, (HALF)0x6e3d, - (HALF)0x640c, (HALF)0x8170, (HALF)0x033f, (HALF)0xb660, - (HALF)0x886b, (HALF)0xf211, (HALF)0x7859, (HALF)0xbcc6, - (HALF)0x4b93, (HALF)0x18ff, (HALF)0xe691, (HALF)0x3068, - (HALF)0xd823, (HALF)0x9db5, (HALF)0xd4ef, (HALF)0x72af, - (HALF)0xcd1a, (HALF)0x5aa4, (HALF)0x3014, (HALF)0xa0a3, - (HALF)0x49e6, (HALF)0x6b83, (HALF)0xe595, (HALF)0x2f4d, - (HALF)0x0384, (HALF)0xd518, (HALF)0x4118, (HALF)0x19d9, - (HALF)0x7534, (HALF)0x369e, (HALF)0x3b18, (HALF)0xce4d, - (HALF)0xf9ee, (HALF)0x119e, (HALF)0x5c25, (HALF)0xe2f4, - (HALF)0xe0a7, (HALF)0xe8ea, (HALF)0x1605, (HALF)0x62e4, - (HALF)0xd2ca, (HALF)0x6346, (HALF)0x625b, (HALF)0x6425, - (HALF)0x33de, (HALF)0x44b0, (HALF)0xe6b3, (HALF)0x1711, - (HALF)0xd02e, (HALF)0xf3a9, (HALF)0xd965, (HALF)0x259c, - (HALF)0x956b, (HALF)0x08aa, (HALF)0x4380, (HALF)0x6ad6, - (HALF)0x0e8e, (HALF)0xe973, (HALF)0x9d28, (HALF)0x539b, - (HALF)0x7950, (HALF)0xe540, (HALF)0x0be4, (HALF)0x8990, - (HALF)0x18f6, (HALF)0xde12, (HALF)0xe52b, (HALF)0x63e1, - (HALF)0x3f4e, (HALF)0x0de0, (HALF)0xa568, (HALF)0x8e21, - (HALF)0x7ee3, (HALF)0x268d, (HALF)0x514e, (HALF)0xafb3, - (HALF)0xefcb, (HALF)0x5378, (HALF)0xc7c6, (HALF)0xfec0, - (HALF)0xb724, (HALF)0xf07c, (HALF)0xb42a, (HALF)0xfb61, - (HALF)0x2a38, (HALF)0x068f + (HALF)0x8629, (HALF)0xc8b7, (HALF)0x1b18, (HALF)0x4135, (HALF)0x4ed8, + (HALF)0x28ad, (HALF)0x7df1, (HALF)0xc96f, + (HALF)0xc931, (HALF)0x7cd3, (HALF)0x036a, (HALF)0x0f23, + (HALF)0x7631, (HALF)0xac65, (HALF)0x5812, (HALF)0x6a62, + (HALF)0x4788, (HALF)0x0814, (HALF)0xed62, (HALF)0x8642, + (HALF)0x8a40, (HALF)0x7619, (HALF)0xfd64, (HALF)0x70de, + (HALF)0x673c, (HALF)0x97fb, (HALF)0xddf6, (HALF)0x6f3b, + (HALF)0x2977, (HALF)0x72fe, (HALF)0x82f1, (HALF)0x20ed, + (HALF)0x4fdc, (HALF)0x7e7f, (HALF)0x2d6b, (HALF)0xdc27, + (HALF)0xf317, (HALF)0x6d77, (HALF)0x5b15, (HALF)0x2c59, + (HALF)0x7dd6, (HALF)0x1c3b, (HALF)0x6147, (HALF)0x6e3d, + (HALF)0x640c, (HALF)0x8170, (HALF)0x033f, (HALF)0xb660, + (HALF)0x886b, (HALF)0xf211, (HALF)0x7859, (HALF)0xbcc6, + (HALF)0x4b93, (HALF)0x18ff, (HALF)0xe691, (HALF)0x3068, + (HALF)0xd823, (HALF)0x9db5, (HALF)0xd4ef, (HALF)0x72af, + (HALF)0xcd1a, (HALF)0x5aa4, (HALF)0x3014, (HALF)0xa0a3, + (HALF)0x49e6, (HALF)0x6b83, (HALF)0xe595, (HALF)0x2f4d, + (HALF)0x0384, (HALF)0xd518, (HALF)0x4118, (HALF)0x19d9, + (HALF)0x7534, (HALF)0x369e, (HALF)0x3b18, (HALF)0xce4d, + (HALF)0xf9ee, (HALF)0x119e, (HALF)0x5c25, (HALF)0xe2f4, + (HALF)0xe0a7, (HALF)0xe8ea, (HALF)0x1605, (HALF)0x62e4, + (HALF)0xd2ca, (HALF)0x6346, (HALF)0x625b, (HALF)0x6425, + (HALF)0x33de, (HALF)0x44b0, (HALF)0xe6b3, (HALF)0x1711, + (HALF)0xd02e, (HALF)0xf3a9, (HALF)0xd965, (HALF)0x259c, + (HALF)0x956b, (HALF)0x08aa, (HALF)0x4380, (HALF)0x6ad6, + (HALF)0x0e8e, (HALF)0xe973, (HALF)0x9d28, (HALF)0x539b, + (HALF)0x7950, (HALF)0xe540, (HALF)0x0be4, (HALF)0x8990, + (HALF)0x18f6, (HALF)0xde12, (HALF)0xe52b, (HALF)0x63e1, + (HALF)0x3f4e, (HALF)0x0de0, (HALF)0xa568, (HALF)0x8e21, + (HALF)0x7ee3, (HALF)0x268d, (HALF)0x514e, (HALF)0xafb3, + (HALF)0xefcb, (HALF)0x5378, (HALF)0xc7c6, (HALF)0xfec0, + (HALF)0xb724, (HALF)0xf07c, (HALF)0xb42a, (HALF)0xfb61, + (HALF)0x2a38, (HALF)0x068f }; STATIC CONST HALF h_rvec18[] = { - (HALF)0x3c63, (HALF)0x35ea, (HALF)0xef97, (HALF)0x8df2, - (HALF)0xafb7, (HALF)0xa2b3, (HALF)0x58f6, (HALF)0x1791, - (HALF)0x0dba, (HALF)0x0492, (HALF)0x077e, (HALF)0xf333, - (HALF)0x4b5a, (HALF)0xf830, (HALF)0xf2ae, (HALF)0x230f, - (HALF)0xf3f0, (HALF)0x84a8, (HALF)0x164e, (HALF)0xadda, - (HALF)0xc944, (HALF)0xc9a1, (HALF)0x02f2, (HALF)0xc705, - (HALF)0xc18f, (HALF)0x41a3, (HALF)0x3254, (HALF)0x09bd, - (HALF)0x65a9, (HALF)0x9736, (HALF)0xc263, (HALF)0x1548, - (HALF)0xd916, (HALF)0x5024, (HALF)0xdde9, (HALF)0x0a3d, - (HALF)0xf1f5, (HALF)0xf2aa, (HALF)0xb92a, (HALF)0x666d, - (HALF)0x5aa5, (HALF)0x3a53, (HALF)0x5775, (HALF)0x49c3, - (HALF)0xa1c4, (HALF)0xc381, (HALF)0x6dbc, (HALF)0xf8d3, - (HALF)0xe870, (HALF)0xe94b, (HALF)0x88a6, (HALF)0x430e, - (HALF)0x9a06, (HALF)0x3721, (HALF)0xdf80, (HALF)0x5109, - (HALF)0xa03f, (HALF)0xe73c, (HALF)0x4541, (HALF)0xf1bb, - (HALF)0x32f3, (HALF)0x3c6f, (HALF)0xfc24, (HALF)0x952c, - (HALF)0x697f, (HALF)0xfbc9, (HALF)0xd472, (HALF)0xc5b8, - (HALF)0xda4b, (HALF)0xcbbe, (HALF)0xdb3b, (HALF)0x7303, - (HALF)0x255e, (HALF)0xa18f, (HALF)0x353d, (HALF)0xe1d3, - (HALF)0x8700, (HALF)0xe8c9, (HALF)0xe8fd, (HALF)0x9e75, - (HALF)0x812e, (HALF)0x3ddd, (HALF)0xf891, (HALF)0x7340, - (HALF)0x69ac, (HALF)0xb1f3, (HALF)0x505b, (HALF)0x764d, - (HALF)0xf51b, (HALF)0xb13e, (HALF)0xaa43, (HALF)0x16c3, - (HALF)0x42c4, (HALF)0x61d0, (HALF)0x0339, (HALF)0x22ac, - (HALF)0x6fd1, (HALF)0x3f30, (HALF)0x6f7f, (HALF)0x4992, - (HALF)0x575c, (HALF)0x2b4c, (HALF)0xb467, (HALF)0x9f3a, - (HALF)0x65af, (HALF)0x5dac, (HALF)0x8dc7, (HALF)0x6277, - (HALF)0x3a89, (HALF)0x9911, (HALF)0x540a, (HALF)0x49c0, - (HALF)0x0ac2, (HALF)0x1df7, (HALF)0x2c5e, (HALF)0x4be1, - (HALF)0x6bdb, (HALF)0xe5d3, (HALF)0x9ff5, (HALF)0x66b9, - (HALF)0xbe89, (HALF)0x5358, (HALF)0x35d7, (HALF)0x4cd8, - (HALF)0xcda8, (HALF)0xf0d5, (HALF)0xc6c3, (HALF)0x1f1a, - (HALF)0x5e92, (HALF)0x0473 + (HALF)0x3c63, (HALF)0x35ea, (HALF)0xef97, (HALF)0x8df2, + (HALF)0xafb7, (HALF)0xa2b3, (HALF)0x58f6, (HALF)0x1791, + (HALF)0x0dba, (HALF)0x0492, (HALF)0x077e, (HALF)0xf333, + (HALF)0x4b5a, (HALF)0xf830, (HALF)0xf2ae, (HALF)0x230f, + (HALF)0xf3f0, (HALF)0x84a8, (HALF)0x164e, (HALF)0xadda, + (HALF)0xc944, (HALF)0xc9a1, (HALF)0x02f2, (HALF)0xc705, + (HALF)0xc18f, (HALF)0x41a3, (HALF)0x3254, (HALF)0x09bd, + (HALF)0x65a9, (HALF)0x9736, (HALF)0xc263, (HALF)0x1548, + (HALF)0xd916, (HALF)0x5024, (HALF)0xdde9, (HALF)0x0a3d, + (HALF)0xf1f5, (HALF)0xf2aa, (HALF)0xb92a, (HALF)0x666d, + (HALF)0x5aa5, (HALF)0x3a53, (HALF)0x5775, (HALF)0x49c3, + (HALF)0xa1c4, (HALF)0xc381, (HALF)0x6dbc, (HALF)0xf8d3, + (HALF)0xe870, (HALF)0xe94b, (HALF)0x88a6, (HALF)0x430e, + (HALF)0x9a06, (HALF)0x3721, (HALF)0xdf80, (HALF)0x5109, + (HALF)0xa03f, (HALF)0xe73c, (HALF)0x4541, (HALF)0xf1bb, + (HALF)0x32f3, (HALF)0x3c6f, (HALF)0xfc24, (HALF)0x952c, + (HALF)0x697f, (HALF)0xfbc9, (HALF)0xd472, (HALF)0xc5b8, + (HALF)0xda4b, (HALF)0xcbbe, (HALF)0xdb3b, (HALF)0x7303, + (HALF)0x255e, (HALF)0xa18f, (HALF)0x353d, (HALF)0xe1d3, + (HALF)0x8700, (HALF)0xe8c9, (HALF)0xe8fd, (HALF)0x9e75, + (HALF)0x812e, (HALF)0x3ddd, (HALF)0xf891, (HALF)0x7340, + (HALF)0x69ac, (HALF)0xb1f3, (HALF)0x505b, (HALF)0x764d, + (HALF)0xf51b, (HALF)0xb13e, (HALF)0xaa43, (HALF)0x16c3, + (HALF)0x42c4, (HALF)0x61d0, (HALF)0x0339, (HALF)0x22ac, + (HALF)0x6fd1, (HALF)0x3f30, (HALF)0x6f7f, (HALF)0x4992, + (HALF)0x575c, (HALF)0x2b4c, (HALF)0xb467, (HALF)0x9f3a, + (HALF)0x65af, (HALF)0x5dac, (HALF)0x8dc7, (HALF)0x6277, + (HALF)0x3a89, (HALF)0x9911, (HALF)0x540a, (HALF)0x49c0, + (HALF)0x0ac2, (HALF)0x1df7, (HALF)0x2c5e, (HALF)0x4be1, + (HALF)0x6bdb, (HALF)0xe5d3, (HALF)0x9ff5, (HALF)0x66b9, + (HALF)0xbe89, (HALF)0x5358, (HALF)0x35d7, (HALF)0x4cd8, + (HALF)0xcda8, (HALF)0xf0d5, (HALF)0xc6c3, (HALF)0x1f1a, + (HALF)0x5e92, (HALF)0x0473 }; STATIC CONST HALF h_nvec19[] = { - (HALF)0x9a79, (HALF)0x6b65, (HALF)0xc12d, (HALF)0x0239, - (HALF)0xdf49, (HALF)0xd204, (HALF)0xe0c7, (HALF)0x1d4a, - (HALF)0xf000, (HALF)0x099b, (HALF)0xade8, (HALF)0x6435, - (HALF)0xf029, (HALF)0xdc4a, (HALF)0xe7a2, (HALF)0x2f4e, - (HALF)0xf1e3, (HALF)0xadfc, (HALF)0x8f43, (HALF)0x7335, - (HALF)0xede5, (HALF)0x687e, (HALF)0xcd4d, (HALF)0xb567, - (HALF)0x814f, (HALF)0xc7a7, (HALF)0x624c, (HALF)0xc306, - (HALF)0x80c6, (HALF)0xa82d, (HALF)0x0cd5, (HALF)0x3f39, - (HALF)0xec3f, (HALF)0x7b7d, (HALF)0x1416, (HALF)0x8bdb, - (HALF)0x3a52, (HALF)0x275b, (HALF)0x84fe, (HALF)0x9218, - (HALF)0x02e0, (HALF)0x94ac, (HALF)0xb52c, (HALF)0x62f2, - (HALF)0x92ee, (HALF)0xcdc9, (HALF)0x5eeb, (HALF)0x35e5, - (HALF)0x3fd5, (HALF)0x69a4, (HALF)0xdcfb, (HALF)0x44c1, - (HALF)0x6227, (HALF)0x3cdf, (HALF)0x148f, (HALF)0x23f3, - (HALF)0x8e4c, (HALF)0x4250, (HALF)0x37c3, (HALF)0x95b7, - (HALF)0x831f, (HALF)0x70af, (HALF)0x15c9, (HALF)0x2ee8, - (HALF)0x7251, (HALF)0x47a4, (HALF)0xb2af, (HALF)0x7c11, - (HALF)0x361f, (HALF)0x664c, (HALF)0xa841, (HALF)0xcada, - (HALF)0x172a, (HALF)0x3d97, (HALF)0x2ffb, (HALF)0x8740, - (HALF)0x2ebd, (HALF)0xa0a0, (HALF)0x225f, (HALF)0xb674, - (HALF)0x3fe2, (HALF)0x6559, (HALF)0x98b9, (HALF)0x85f6, - (HALF)0xa7ab, (HALF)0x5ed9, (HALF)0x7371, (HALF)0x6bf3, - (HALF)0x5305, (HALF)0x7da7, (HALF)0x55bf, (HALF)0x0882, - (HALF)0x7684, (HALF)0x8f60, (HALF)0xe57e, (HALF)0x1f3d, - (HALF)0xd501, (HALF)0x118b, (HALF)0x770d, (HALF)0x6833, - (HALF)0x5c51, (HALF)0xd042, (HALF)0xcacb, (HALF)0x2664, - (HALF)0xb920, (HALF)0x9206, (HALF)0x3b8d, (HALF)0xeb90, - (HALF)0x16b4, (HALF)0x0e25, (HALF)0xd841, (HALF)0x36c3, - (HALF)0xcd17, (HALF)0x51d7, (HALF)0xba1e, (HALF)0xe063, - (HALF)0x4a6d, (HALF)0xf28f, (HALF)0xeb0d, (HALF)0x244d, - (HALF)0x0ad4, (HALF)0x2e41, (HALF)0xc315, (HALF)0x0721, - (HALF)0x7654, (HALF)0xdde2, (HALF)0x534b, (HALF)0x2ad6, - (HALF)0x8b25, (HALF)0xd678, (HALF)0xb9e8, (HALF)0xb23b, - (HALF)0x0d7a, (HALF)0x0023 + (HALF)0x9a79, (HALF)0x6b65, (HALF)0xc12d, (HALF)0x0239, + (HALF)0xdf49, (HALF)0xd204, (HALF)0xe0c7, (HALF)0x1d4a, + (HALF)0xf000, (HALF)0x099b, (HALF)0xade8, (HALF)0x6435, + (HALF)0xf029, (HALF)0xdc4a, (HALF)0xe7a2, (HALF)0x2f4e, + (HALF)0xf1e3, (HALF)0xadfc, (HALF)0x8f43, (HALF)0x7335, + (HALF)0xede5, (HALF)0x687e, (HALF)0xcd4d, (HALF)0xb567, + (HALF)0x814f, (HALF)0xc7a7, (HALF)0x624c, (HALF)0xc306, + (HALF)0x80c6, (HALF)0xa82d, (HALF)0x0cd5, (HALF)0x3f39, + (HALF)0xec3f, (HALF)0x7b7d, (HALF)0x1416, (HALF)0x8bdb, + (HALF)0x3a52, (HALF)0x275b, (HALF)0x84fe, (HALF)0x9218, + (HALF)0x02e0, (HALF)0x94ac, (HALF)0xb52c, (HALF)0x62f2, + (HALF)0x92ee, (HALF)0xcdc9, (HALF)0x5eeb, (HALF)0x35e5, + (HALF)0x3fd5, (HALF)0x69a4, (HALF)0xdcfb, (HALF)0x44c1, + (HALF)0x6227, (HALF)0x3cdf, (HALF)0x148f, (HALF)0x23f3, + (HALF)0x8e4c, (HALF)0x4250, (HALF)0x37c3, (HALF)0x95b7, + (HALF)0x831f, (HALF)0x70af, (HALF)0x15c9, (HALF)0x2ee8, + (HALF)0x7251, (HALF)0x47a4, (HALF)0xb2af, (HALF)0x7c11, + (HALF)0x361f, (HALF)0x664c, (HALF)0xa841, (HALF)0xcada, + (HALF)0x172a, (HALF)0x3d97, (HALF)0x2ffb, (HALF)0x8740, + (HALF)0x2ebd, (HALF)0xa0a0, (HALF)0x225f, (HALF)0xb674, + (HALF)0x3fe2, (HALF)0x6559, (HALF)0x98b9, (HALF)0x85f6, + (HALF)0xa7ab, (HALF)0x5ed9, (HALF)0x7371, (HALF)0x6bf3, + (HALF)0x5305, (HALF)0x7da7, (HALF)0x55bf, (HALF)0x0882, + (HALF)0x7684, (HALF)0x8f60, (HALF)0xe57e, (HALF)0x1f3d, + (HALF)0xd501, (HALF)0x118b, (HALF)0x770d, (HALF)0x6833, + (HALF)0x5c51, (HALF)0xd042, (HALF)0xcacb, (HALF)0x2664, + (HALF)0xb920, (HALF)0x9206, (HALF)0x3b8d, (HALF)0xeb90, + (HALF)0x16b4, (HALF)0x0e25, (HALF)0xd841, (HALF)0x36c3, + (HALF)0xcd17, (HALF)0x51d7, (HALF)0xba1e, (HALF)0xe063, + (HALF)0x4a6d, (HALF)0xf28f, (HALF)0xeb0d, (HALF)0x244d, + (HALF)0x0ad4, (HALF)0x2e41, (HALF)0xc315, (HALF)0x0721, + (HALF)0x7654, (HALF)0xdde2, (HALF)0x534b, (HALF)0x2ad6, + (HALF)0x8b25, (HALF)0xd678, (HALF)0xb9e8, (HALF)0xb23b, + (HALF)0x0d7a, (HALF)0x0023 }; STATIC CONST HALF h_rvec19[] = { - (HALF)0xf473, (HALF)0x698e, (HALF)0xa5b7, (HALF)0x3d53, - (HALF)0x8319, (HALF)0x0644, (HALF)0x4445, (HALF)0xd9ad, - (HALF)0xdaa0, (HALF)0x6967, (HALF)0x6240, (HALF)0xa14c, - (HALF)0x7724, (HALF)0x78e7, (HALF)0x2ab7, (HALF)0x63ef, - (HALF)0x2ee2, (HALF)0x8dff, (HALF)0xb424, (HALF)0x662e, - (HALF)0x07d6, (HALF)0xcd93, (HALF)0x6a5d, (HALF)0x0ab0, - (HALF)0xb539, (HALF)0xbdd7, (HALF)0xdd2d, (HALF)0x8621, - (HALF)0xa187, (HALF)0x2bb4, (HALF)0x121d, (HALF)0x1f1e, - (HALF)0xb962, (HALF)0xce8d, (HALF)0xeaf1, (HALF)0xdd3e, - (HALF)0x6ca1, (HALF)0x573b, (HALF)0x0cd6, (HALF)0x6f46, - (HALF)0x4780, (HALF)0x6a8d, (HALF)0xc7e6, (HALF)0xea68, - (HALF)0xeb32, (HALF)0x1148, (HALF)0x44d4, (HALF)0xb43d, - (HALF)0xcb64, (HALF)0xb657, (HALF)0xfdba, (HALF)0x8547, - (HALF)0x3333, (HALF)0x85f7, (HALF)0xa51a, (HALF)0xc1f2, - (HALF)0xee52, (HALF)0x1c05, (HALF)0xc03d, (HALF)0x2847, - (HALF)0x88d8, (HALF)0xfc7a, (HALF)0xd186, (HALF)0x2e8d, - (HALF)0x4683, (HALF)0x5be3, (HALF)0x2ee2, (HALF)0xd43d, - (HALF)0x2bb5, (HALF)0x9f2d, (HALF)0xddea, (HALF)0x89b3, - (HALF)0x4ae0, (HALF)0x7d78, (HALF)0x5e28, (HALF)0xc773, - (HALF)0x8608, (HALF)0x967a, (HALF)0xcf07, (HALF)0xcdcb, - (HALF)0xa423, (HALF)0xfc17, (HALF)0xd053, (HALF)0xd36a, - (HALF)0x8892, (HALF)0xc73d, (HALF)0xc3f4, (HALF)0xa635, - (HALF)0x0cf9, (HALF)0x9b5d, (HALF)0x3fd9, (HALF)0x0ac7, - (HALF)0xfefb, (HALF)0xe801, (HALF)0xffd2, (HALF)0xb31c, - (HALF)0xaa55, (HALF)0xf3ea, (HALF)0xfa23, (HALF)0x0e74, - (HALF)0xb290, (HALF)0x5414, (HALF)0x6101, (HALF)0x6d17, - (HALF)0x93f8, (HALF)0x5229, (HALF)0x3dad, (HALF)0xf829, - (HALF)0x1e82, (HALF)0x713b, (HALF)0xbef0, (HALF)0xb83b, - (HALF)0xcc62, (HALF)0xd001, (HALF)0xda39, (HALF)0x7537, - (HALF)0x158b, (HALF)0x7d80, (HALF)0xc8e2, (HALF)0x9332, - (HALF)0xfa75, (HALF)0x6fa6, (HALF)0x6512, (HALF)0xe21f, - (HALF)0x18b4, (HALF)0x9995, (HALF)0x605b, (HALF)0x2196, - (HALF)0x1798, (HALF)0xe4fc, (HALF)0xe245, (HALF)0x5f21, - (HALF)0xf172, (HALF)0x0008 + (HALF)0xf473, (HALF)0x698e, (HALF)0xa5b7, (HALF)0x3d53, + (HALF)0x8319, (HALF)0x0644, (HALF)0x4445, (HALF)0xd9ad, + (HALF)0xdaa0, (HALF)0x6967, (HALF)0x6240, (HALF)0xa14c, + (HALF)0x7724, (HALF)0x78e7, (HALF)0x2ab7, (HALF)0x63ef, + (HALF)0x2ee2, (HALF)0x8dff, (HALF)0xb424, (HALF)0x662e, + (HALF)0x07d6, (HALF)0xcd93, (HALF)0x6a5d, (HALF)0x0ab0, + (HALF)0xb539, (HALF)0xbdd7, (HALF)0xdd2d, (HALF)0x8621, + (HALF)0xa187, (HALF)0x2bb4, (HALF)0x121d, (HALF)0x1f1e, + (HALF)0xb962, (HALF)0xce8d, (HALF)0xeaf1, (HALF)0xdd3e, + (HALF)0x6ca1, (HALF)0x573b, (HALF)0x0cd6, (HALF)0x6f46, + (HALF)0x4780, (HALF)0x6a8d, (HALF)0xc7e6, (HALF)0xea68, + (HALF)0xeb32, (HALF)0x1148, (HALF)0x44d4, (HALF)0xb43d, + (HALF)0xcb64, (HALF)0xb657, (HALF)0xfdba, (HALF)0x8547, + (HALF)0x3333, (HALF)0x85f7, (HALF)0xa51a, (HALF)0xc1f2, + (HALF)0xee52, (HALF)0x1c05, (HALF)0xc03d, (HALF)0x2847, + (HALF)0x88d8, (HALF)0xfc7a, (HALF)0xd186, (HALF)0x2e8d, + (HALF)0x4683, (HALF)0x5be3, (HALF)0x2ee2, (HALF)0xd43d, + (HALF)0x2bb5, (HALF)0x9f2d, (HALF)0xddea, (HALF)0x89b3, + (HALF)0x4ae0, (HALF)0x7d78, (HALF)0x5e28, (HALF)0xc773, + (HALF)0x8608, (HALF)0x967a, (HALF)0xcf07, (HALF)0xcdcb, + (HALF)0xa423, (HALF)0xfc17, (HALF)0xd053, (HALF)0xd36a, + (HALF)0x8892, (HALF)0xc73d, (HALF)0xc3f4, (HALF)0xa635, + (HALF)0x0cf9, (HALF)0x9b5d, (HALF)0x3fd9, (HALF)0x0ac7, + (HALF)0xfefb, (HALF)0xe801, (HALF)0xffd2, (HALF)0xb31c, + (HALF)0xaa55, (HALF)0xf3ea, (HALF)0xfa23, (HALF)0x0e74, + (HALF)0xb290, (HALF)0x5414, (HALF)0x6101, (HALF)0x6d17, + (HALF)0x93f8, (HALF)0x5229, (HALF)0x3dad, (HALF)0xf829, + (HALF)0x1e82, (HALF)0x713b, (HALF)0xbef0, (HALF)0xb83b, + (HALF)0xcc62, (HALF)0xd001, (HALF)0xda39, (HALF)0x7537, + (HALF)0x158b, (HALF)0x7d80, (HALF)0xc8e2, (HALF)0x9332, + (HALF)0xfa75, (HALF)0x6fa6, (HALF)0x6512, (HALF)0xe21f, + (HALF)0x18b4, (HALF)0x9995, (HALF)0x605b, (HALF)0x2196, + (HALF)0x1798, (HALF)0xe4fc, (HALF)0xe245, (HALF)0x5f21, + (HALF)0xf172, (HALF)0x0008 }; STATIC CONST HALF h_nvec20[] = { - (HALF)0xd081, (HALF)0xc3c1, (HALF)0x2fce, (HALF)0x4d26, - (HALF)0xcc91, (HALF)0x8765, (HALF)0x7f7c, (HALF)0xf372, - (HALF)0x4bbc, (HALF)0xabba, (HALF)0x5801, (HALF)0xe098, - (HALF)0x5c51, (HALF)0xfa36, (HALF)0xb230, (HALF)0xb2a4, - (HALF)0x0a8d, (HALF)0xf443, (HALF)0x98c8, (HALF)0x546b, - (HALF)0x8b26, (HALF)0xd974, (HALF)0xa82f, (HALF)0xe255, - (HALF)0x3e8c, (HALF)0xb00a, (HALF)0x676d, (HALF)0x7069, - (HALF)0xccce, (HALF)0x6233, (HALF)0xa74e, (HALF)0x0299, - (HALF)0xadf9, (HALF)0xd119, (HALF)0xe811, (HALF)0x5273, - (HALF)0xe0bb, (HALF)0xae36, (HALF)0xa486, (HALF)0x32b3, - (HALF)0x21a5, (HALF)0xf049, (HALF)0x28a2, (HALF)0xd31d, - (HALF)0x50de, (HALF)0xda0c, (HALF)0x2b40, (HALF)0x2130, - (HALF)0xe552, (HALF)0xee9d, (HALF)0xac03, (HALF)0x80bb, - (HALF)0x9740, (HALF)0x75f4, (HALF)0xa61b, (HALF)0xc3d0, - (HALF)0xfbf6, (HALF)0x341c, (HALF)0xb5b4, (HALF)0x1615, - (HALF)0x3def, (HALF)0x4e3a, (HALF)0x4dbf, (HALF)0x9573, - (HALF)0x78ac, (HALF)0xe7ab, (HALF)0x5cf9, (HALF)0xffdc, - (HALF)0x6892, (HALF)0xf799, (HALF)0x7ba4, (HALF)0x4740, - (HALF)0x988f, (HALF)0xa78b, (HALF)0x6f42, (HALF)0x2773, - (HALF)0xee50, (HALF)0x5064, (HALF)0x5c56, (HALF)0x6013, - (HALF)0x3283, (HALF)0x1ad7, (HALF)0x4bf7, (HALF)0x2562, - (HALF)0x1419, (HALF)0x2ee2, (HALF)0x5abd, (HALF)0x9319, - (HALF)0x7778, (HALF)0x66b6, (HALF)0xa42d, (HALF)0xb1e0, - (HALF)0xb0f0, (HALF)0x729f, (HALF)0x1864, (HALF)0xd492, - (HALF)0x253f, (HALF)0x2c42, (HALF)0x07a9, (HALF)0x302a, - (HALF)0x1bd4, (HALF)0xbb74, (HALF)0x90ba, (HALF)0x932f, - (HALF)0x4be1, (HALF)0xf335, (HALF)0xd661, (HALF)0x0804, - (HALF)0x9ba1, (HALF)0x010e, (HALF)0x778d, (HALF)0x1a05, - (HALF)0xc833, (HALF)0xa962, (HALF)0x0ee8, (HALF)0xe759, - (HALF)0x03b8, (HALF)0xbe68, (HALF)0x04c1, (HALF)0xc677, - (HALF)0x9660, (HALF)0x56d7, (HALF)0xa3f3, (HALF)0x6066, - (HALF)0x0327, (HALF)0x648b, (HALF)0x5b3a, (HALF)0x267e, - (HALF)0x63a0, (HALF)0xdddc, (HALF)0xe890, (HALF)0x3322, - (HALF)0xd8b1, (HALF)0x20e0, (HALF)0xd2b8, (HALF)0x004f + (HALF)0xd081, (HALF)0xc3c1, (HALF)0x2fce, (HALF)0x4d26, + (HALF)0xcc91, (HALF)0x8765, (HALF)0x7f7c, (HALF)0xf372, + (HALF)0x4bbc, (HALF)0xabba, (HALF)0x5801, (HALF)0xe098, + (HALF)0x5c51, (HALF)0xfa36, (HALF)0xb230, (HALF)0xb2a4, + (HALF)0x0a8d, (HALF)0xf443, (HALF)0x98c8, (HALF)0x546b, + (HALF)0x8b26, (HALF)0xd974, (HALF)0xa82f, (HALF)0xe255, + (HALF)0x3e8c, (HALF)0xb00a, (HALF)0x676d, (HALF)0x7069, + (HALF)0xccce, (HALF)0x6233, (HALF)0xa74e, (HALF)0x0299, + (HALF)0xadf9, (HALF)0xd119, (HALF)0xe811, (HALF)0x5273, + (HALF)0xe0bb, (HALF)0xae36, (HALF)0xa486, (HALF)0x32b3, + (HALF)0x21a5, (HALF)0xf049, (HALF)0x28a2, (HALF)0xd31d, + (HALF)0x50de, (HALF)0xda0c, (HALF)0x2b40, (HALF)0x2130, + (HALF)0xe552, (HALF)0xee9d, (HALF)0xac03, (HALF)0x80bb, + (HALF)0x9740, (HALF)0x75f4, (HALF)0xa61b, (HALF)0xc3d0, + (HALF)0xfbf6, (HALF)0x341c, (HALF)0xb5b4, (HALF)0x1615, + (HALF)0x3def, (HALF)0x4e3a, (HALF)0x4dbf, (HALF)0x9573, + (HALF)0x78ac, (HALF)0xe7ab, (HALF)0x5cf9, (HALF)0xffdc, + (HALF)0x6892, (HALF)0xf799, (HALF)0x7ba4, (HALF)0x4740, + (HALF)0x988f, (HALF)0xa78b, (HALF)0x6f42, (HALF)0x2773, + (HALF)0xee50, (HALF)0x5064, (HALF)0x5c56, (HALF)0x6013, + (HALF)0x3283, (HALF)0x1ad7, (HALF)0x4bf7, (HALF)0x2562, + (HALF)0x1419, (HALF)0x2ee2, (HALF)0x5abd, (HALF)0x9319, + (HALF)0x7778, (HALF)0x66b6, (HALF)0xa42d, (HALF)0xb1e0, + (HALF)0xb0f0, (HALF)0x729f, (HALF)0x1864, (HALF)0xd492, + (HALF)0x253f, (HALF)0x2c42, (HALF)0x07a9, (HALF)0x302a, + (HALF)0x1bd4, (HALF)0xbb74, (HALF)0x90ba, (HALF)0x932f, + (HALF)0x4be1, (HALF)0xf335, (HALF)0xd661, (HALF)0x0804, + (HALF)0x9ba1, (HALF)0x010e, (HALF)0x778d, (HALF)0x1a05, + (HALF)0xc833, (HALF)0xa962, (HALF)0x0ee8, (HALF)0xe759, + (HALF)0x03b8, (HALF)0xbe68, (HALF)0x04c1, (HALF)0xc677, + (HALF)0x9660, (HALF)0x56d7, (HALF)0xa3f3, (HALF)0x6066, + (HALF)0x0327, (HALF)0x648b, (HALF)0x5b3a, (HALF)0x267e, + (HALF)0x63a0, (HALF)0xdddc, (HALF)0xe890, (HALF)0x3322, + (HALF)0xd8b1, (HALF)0x20e0, (HALF)0xd2b8, (HALF)0x004f }; STATIC CONST HALF h_rvec20[] = { - (HALF)0xbd1a, (HALF)0xa048, (HALF)0xdc7b, (HALF)0x95ab, - (HALF)0x7cf8, (HALF)0x98f4, (HALF)0xc98d, (HALF)0x126a, - (HALF)0x85fd, (HALF)0xaebf, (HALF)0x580f, (HALF)0x5650, - (HALF)0xd7dd, (HALF)0x3292, (HALF)0x8377, (HALF)0xf49e, - (HALF)0xed46, (HALF)0x2947, (HALF)0xb26c, (HALF)0xd1a5, - (HALF)0xe6a1, (HALF)0xae14, (HALF)0x5788, (HALF)0x9b1f, - (HALF)0x27b2, (HALF)0x4df7, (HALF)0x5079, (HALF)0xee37, - (HALF)0xc8e4, (HALF)0x131b, (HALF)0x5f53, (HALF)0x294e, - (HALF)0x59bd, (HALF)0x1f57, (HALF)0x8acf, (HALF)0x65d5, - (HALF)0xd3a5, (HALF)0x598e, (HALF)0x61a6, (HALF)0xc393, - (HALF)0xfd7a, (HALF)0xa783, (HALF)0x36a2, (HALF)0x264a, - (HALF)0x2856, (HALF)0x6ca2, (HALF)0x171f, (HALF)0x8ffb, - (HALF)0xea9e, (HALF)0x1d7c, (HALF)0x6fca, (HALF)0xd81d, - (HALF)0x730e, (HALF)0x34ea, (HALF)0x6382, (HALF)0x31f5, - (HALF)0xd9e9, (HALF)0xb39c, (HALF)0x84be, (HALF)0x440e, - (HALF)0x15a1, (HALF)0x4b1d, (HALF)0x75c5, (HALF)0x7bf7, - (HALF)0x4638, (HALF)0xe40f, (HALF)0xf0a7, (HALF)0xe5be, - (HALF)0x8942, (HALF)0x79e5, (HALF)0xe1ba, (HALF)0x881a, - (HALF)0x8372, (HALF)0x01de, (HALF)0x35f8, (HALF)0x14cf, - (HALF)0xb310, (HALF)0xe2d8, (HALF)0x1207, (HALF)0x6696, - (HALF)0x5f91, (HALF)0xde5d, (HALF)0x0849, (HALF)0xe6e7, - (HALF)0x5ac3, (HALF)0x74ec, (HALF)0x4eb1, (HALF)0xe2de, - (HALF)0xdc20, (HALF)0x4a41, (HALF)0xd565, (HALF)0xd306, - (HALF)0x3ff3, (HALF)0xb584, (HALF)0x30d6, (HALF)0x911b, - (HALF)0xd926, (HALF)0x4e9c, (HALF)0xc9ae, (HALF)0x8455, - (HALF)0x8bb5, (HALF)0x6944, (HALF)0x1aad, (HALF)0x0c7b, - (HALF)0xe992, (HALF)0x1da1, (HALF)0x56bd, (HALF)0xc676, - (HALF)0x209e, (HALF)0xc544, (HALF)0x387c, (HALF)0x10ce, - (HALF)0x8df8, (HALF)0xc4e8, (HALF)0xda88, (HALF)0x40e8, - (HALF)0x3028, (HALF)0xbb2c, (HALF)0x4fd9, (HALF)0x4919, - (HALF)0x17ee, (HALF)0xdeef, (HALF)0xc08d, (HALF)0x241b, - (HALF)0xf608, (HALF)0x6fa9, (HALF)0x8b04, (HALF)0x4b0f, - (HALF)0x0da1, (HALF)0xee96, (HALF)0x9293, (HALF)0xa309, - (HALF)0x5fea, (HALF)0x8444, (HALF)0xef01, (HALF)0x0046 + (HALF)0xbd1a, (HALF)0xa048, (HALF)0xdc7b, (HALF)0x95ab, + (HALF)0x7cf8, (HALF)0x98f4, (HALF)0xc98d, (HALF)0x126a, + (HALF)0x85fd, (HALF)0xaebf, (HALF)0x580f, (HALF)0x5650, + (HALF)0xd7dd, (HALF)0x3292, (HALF)0x8377, (HALF)0xf49e, + (HALF)0xed46, (HALF)0x2947, (HALF)0xb26c, (HALF)0xd1a5, + (HALF)0xe6a1, (HALF)0xae14, (HALF)0x5788, (HALF)0x9b1f, + (HALF)0x27b2, (HALF)0x4df7, (HALF)0x5079, (HALF)0xee37, + (HALF)0xc8e4, (HALF)0x131b, (HALF)0x5f53, (HALF)0x294e, + (HALF)0x59bd, (HALF)0x1f57, (HALF)0x8acf, (HALF)0x65d5, + (HALF)0xd3a5, (HALF)0x598e, (HALF)0x61a6, (HALF)0xc393, + (HALF)0xfd7a, (HALF)0xa783, (HALF)0x36a2, (HALF)0x264a, + (HALF)0x2856, (HALF)0x6ca2, (HALF)0x171f, (HALF)0x8ffb, + (HALF)0xea9e, (HALF)0x1d7c, (HALF)0x6fca, (HALF)0xd81d, + (HALF)0x730e, (HALF)0x34ea, (HALF)0x6382, (HALF)0x31f5, + (HALF)0xd9e9, (HALF)0xb39c, (HALF)0x84be, (HALF)0x440e, + (HALF)0x15a1, (HALF)0x4b1d, (HALF)0x75c5, (HALF)0x7bf7, + (HALF)0x4638, (HALF)0xe40f, (HALF)0xf0a7, (HALF)0xe5be, + (HALF)0x8942, (HALF)0x79e5, (HALF)0xe1ba, (HALF)0x881a, + (HALF)0x8372, (HALF)0x01de, (HALF)0x35f8, (HALF)0x14cf, + (HALF)0xb310, (HALF)0xe2d8, (HALF)0x1207, (HALF)0x6696, + (HALF)0x5f91, (HALF)0xde5d, (HALF)0x0849, (HALF)0xe6e7, + (HALF)0x5ac3, (HALF)0x74ec, (HALF)0x4eb1, (HALF)0xe2de, + (HALF)0xdc20, (HALF)0x4a41, (HALF)0xd565, (HALF)0xd306, + (HALF)0x3ff3, (HALF)0xb584, (HALF)0x30d6, (HALF)0x911b, + (HALF)0xd926, (HALF)0x4e9c, (HALF)0xc9ae, (HALF)0x8455, + (HALF)0x8bb5, (HALF)0x6944, (HALF)0x1aad, (HALF)0x0c7b, + (HALF)0xe992, (HALF)0x1da1, (HALF)0x56bd, (HALF)0xc676, + (HALF)0x209e, (HALF)0xc544, (HALF)0x387c, (HALF)0x10ce, + (HALF)0x8df8, (HALF)0xc4e8, (HALF)0xda88, (HALF)0x40e8, + (HALF)0x3028, (HALF)0xbb2c, (HALF)0x4fd9, (HALF)0x4919, + (HALF)0x17ee, (HALF)0xdeef, (HALF)0xc08d, (HALF)0x241b, + (HALF)0xf608, (HALF)0x6fa9, (HALF)0x8b04, (HALF)0x4b0f, + (HALF)0x0da1, (HALF)0xee96, (HALF)0x9293, (HALF)0xa309, + (HALF)0x5fea, (HALF)0x8444, (HALF)0xef01, (HALF)0x0046 }; #else - /\../\ FULL_BITS must be 32 or 64 /\../\ !!! + /\../\ FULL_BITS must be 32 or 64 /\../\ !!! #endif /* * NOTE: set n is found in random_pregen[n-1] @@ -2256,113 +2256,113 @@ S_FUNC void zfree_random(ZVALUE z); * In particular: * * given: - * pseed - seed of the generator - * need_ret - true=>malloc return previous Blum state, false=>return NULL + * pseed - seed of the generator + * need_ret - true=>malloc return previous Blum state, false=>return NULL * * returns: - * previous Blum state + * previous Blum state */ RANDOM * zsrandom1(CONST ZVALUE seed, bool need_ret) { - RANDOM *ret; /* previous Blum state */ - ZVALUE r; /* quadratic residue */ - ZVALUE last_r; /* previous quadratic residue */ - RANDOM *p_blum; /* malloced RANDOM by randomcopy() */ + RANDOM *ret; /* previous Blum state */ + ZVALUE r; /* quadratic residue */ + ZVALUE last_r; /* previous quadratic residue */ + RANDOM *p_blum; /* malloced RANDOM by randomcopy() */ - /* - * initialize state if first call - */ - if (blum_initialized == false || !blum.seeded) { - p_blum = randomcopy(&init_blum); - if (blum_initialized == true) { - randomfree(&blum); - } - blum = *p_blum; - free(p_blum); - blum_initialized = true; - } + /* + * initialize state if first call + */ + if (blum_initialized == false || !blum.seeded) { + p_blum = randomcopy(&init_blum); + if (blum_initialized == true) { + randomfree(&blum); + } + blum = *p_blum; + free(p_blum); + blum_initialized = true; + } - /* - * save the current state to return later, if need_ret says so - */ - if (need_ret) { - ret = randomcopy(&blum); - } else { - ret = NULL; - } + /* + * save the current state to return later, if need_ret says so + */ + if (need_ret) { + ret = randomcopy(&blum); + } else { + ret = NULL; + } - /* - * srandom(seed == 0) - * - * If the init arg is true, then restore the initial state and - * modulus of the Blum generator. After this call, the Blum - * generator is restored to its initial state after calc started. - */ - if (ziszero(seed)) { + /* + * srandom(seed == 0) + * + * If the init arg is true, then restore the initial state and + * modulus of the Blum generator. After this call, the Blum + * generator is restored to its initial state after calc started. + */ + if (ziszero(seed)) { - /* set to the default generator state */ - p_blum = randomcopy(&init_blum); - randomfree(&blum); - blum = *p_blum; - free(p_blum); + /* set to the default generator state */ + p_blum = randomcopy(&init_blum); + randomfree(&blum); + blum = *p_blum; + free(p_blum); - /* - * srandom(seed >= 2^32) - * srandom(seed >= 2^32, newn) - * - * Use seed to compute a new quadratic residue for use with - * the current Blum modulus. We will successively square mod Blum - * modulus until we get a smaller value (modulus wrap). - * - * The Blum modulus will not be changed. - */ - } else if (!zisneg(seed) && zge32b(seed)) { + /* + * srandom(seed >= 2^32) + * srandom(seed >= 2^32, newn) + * + * Use seed to compute a new quadratic residue for use with + * the current Blum modulus. We will successively square mod Blum + * modulus until we get a smaller value (modulus wrap). + * + * The Blum modulus will not be changed. + */ + } else if (!zisneg(seed) && zge32b(seed)) { - /* - * square the seed mod the Blum modulus until we wrap - */ - zcopy(seed, &r); - last_r.v = NULL; - do { - /* free temp storage */ - zfree_random(last_r); + /* + * square the seed mod the Blum modulus until we wrap + */ + zcopy(seed, &r); + last_r.v = NULL; + do { + /* free temp storage */ + zfree_random(last_r); - /* - * last_r = r; - * r = pmod(last_r, 2, n); - */ - zcopy(r, &last_r); - zfree_random(r); - zsquaremod(last_r, blum.n, &r); - } while (zrel(r, last_r) > 0); - zfree_random(blum.r); - blum.r = r; + /* + * last_r = r; + * r = pmod(last_r, 2, n); + */ + zcopy(r, &last_r); + zfree_random(r); + zsquaremod(last_r, blum.n, &r); + } while (zrel(r, last_r) > 0); + zfree_random(blum.r); + blum.r = r; - /* free temp storage */ - zfree_random(last_r); + /* free temp storage */ + zfree_random(last_r); - /* - * reserved seed - */ - } else { - if (ret != NULL) { - randomfree(ret); - } - math_error("srandom seed must be 0 or >= 2^32"); - not_reached(); - } + /* + * reserved seed + */ + } else { + if (ret != NULL) { + randomfree(ret); + } + math_error("srandom seed must be 0 or >= 2^32"); + not_reached(); + } - /* - * flush the queued up bits - */ - blum.bits = 0; - blum.buffer = 0; + /* + * flush the queued up bits + */ + blum.bits = 0; + blum.buffer = 0; - /* - * return the previous state - */ - return ret; + /* + * return the previous state + */ + return ret; } @@ -2374,158 +2374,158 @@ zsrandom1(CONST ZVALUE seed, bool need_ret) * In particular: * * given: - * pseed - seed of the generator - * newn - ptr to proposed new n (Blum modulus) + * pseed - seed of the generator + * newn - ptr to proposed new n (Blum modulus) * * returns: - * previous Blum state + * previous Blum state */ RANDOM * zsrandom2(CONST ZVALUE seed, CONST ZVALUE newn) { - RANDOM *ret; /* previous Blum state */ - HALF set; /* pre-defined set to use */ - FULL nlen; /* length of newn in bits */ - RANDOM *p_blum; /* malloced RANDOM by randomcopy() */ + RANDOM *ret; /* previous Blum state */ + HALF set; /* pre-defined set to use */ + FULL nlen; /* length of newn in bits */ + RANDOM *p_blum; /* malloced RANDOM by randomcopy() */ - /* - * initialize state if first call - */ - if (blum_initialized == false || !blum.seeded) { - p_blum = randomcopy(&init_blum); - if (blum_initialized == true) { - randomfree(&blum); - } - blum = *p_blum; - free(p_blum); - blum_initialized = true; - } + /* + * initialize state if first call + */ + if (blum_initialized == false || !blum.seeded) { + p_blum = randomcopy(&init_blum); + if (blum_initialized == true) { + randomfree(&blum); + } + blum = *p_blum; + free(p_blum); + blum_initialized = true; + } - /* - * save the current state to return later - */ - ret = randomcopy(&blum); + /* + * save the current state to return later + */ + ret = randomcopy(&blum); - /* - * srandom(seed, 0 < newn <= 20) - * - * Set the Blum modulus to one of the pre-defined Blum moduli. - * The new quadratic residue will also be set to one of - * the pre-defined quadratic residues. - */ - if (!zisneg(newn) && !zge32b(newn)) { + /* + * srandom(seed, 0 < newn <= 20) + * + * Set the Blum modulus to one of the pre-defined Blum moduli. + * The new quadratic residue will also be set to one of + * the pre-defined quadratic residues. + */ + if (!zisneg(newn) && !zge32b(newn)) { - /* - * preset moduli only if small newn - */ - if (ziszero(newn)) { - randomfree(ret); - math_error("srandom newn == 0 reserved for future use"); - not_reached(); - } - set = (HALF)z1tol(newn); - if (!zistiny(newn) || set > BLUM_PREGEN) { - randomfree(ret); - math_error("srandom small newn must be [1,20]"); - not_reached(); - } - zfree_random(blum.n); - zcopy(random_pregen[set-1].n, &blum.n); - blum.loglogn = random_pregen[set-1].loglogn; - blum.mask = random_pregen[set-1].mask; + /* + * preset moduli only if small newn + */ + if (ziszero(newn)) { + randomfree(ret); + math_error("srandom newn == 0 reserved for future use"); + not_reached(); + } + set = (HALF)z1tol(newn); + if (!zistiny(newn) || set > BLUM_PREGEN) { + randomfree(ret); + math_error("srandom small newn must be [1,20]"); + not_reached(); + } + zfree_random(blum.n); + zcopy(random_pregen[set-1].n, &blum.n); + blum.loglogn = random_pregen[set-1].loglogn; + blum.mask = random_pregen[set-1].mask; - /* - * reset initial seed as well if seed is 0 - */ - if (ziszero(seed)) { - zfree_random(blum.r); - zcopy(random_pregen[set-1].r, &blum.r); + /* + * reset initial seed as well if seed is 0 + */ + if (ziszero(seed)) { + zfree_random(blum.r); + zcopy(random_pregen[set-1].r, &blum.r); - /* - * Otherwise non-zero seeds are processed as 1 arg calls - */ - } else { - (void) zsrandom1(seed, false); - } + /* + * Otherwise non-zero seeds are processed as 1 arg calls + */ + } else { + (void) zsrandom1(seed, false); + } - /* - * srandom(seed, newn >= 2^32) - * - * Assuming that 'newn' == 3 mod 4, then we will use it as - * the Blum modulus. - * - * We will use the seed arg to compute a new quadratic residue. - * We will successively square it mod Blum modulus until we get - * a smaller value (modulus wrap). - */ - } else if (!zisneg(newn)) { + /* + * srandom(seed, newn >= 2^32) + * + * Assuming that 'newn' == 3 mod 4, then we will use it as + * the Blum modulus. + * + * We will use the seed arg to compute a new quadratic residue. + * We will successively square it mod Blum modulus until we get + * a smaller value (modulus wrap). + */ + } else if (!zisneg(newn)) { - /* - * Blum modulus must be 1 mod 4 - */ - if (newn.v[0] % 4 != 1) { - randomfree(ret); - math_error("srandom large newn must be 1 mod 4"); - not_reached(); - } + /* + * Blum modulus must be 1 mod 4 + */ + if (newn.v[0] % 4 != 1) { + randomfree(ret); + math_error("srandom large newn must be 1 mod 4"); + not_reached(); + } - /* - * For correct Blum moduli, hope they are a product - * of two primes. - */ - /* load modulus */ - zfree_random(blum.n); - zcopy(newn, &blum.n); + /* + * For correct Blum moduli, hope they are a product + * of two primes. + */ + /* load modulus */ + zfree_random(blum.n); + zcopy(newn, &blum.n); - /* - * setup loglogn and mask - * - * If the length if excessive, reduce it down - * so that loglogn is at most BASEB-1. - */ - nlen = (FULL)zhighbit(newn); - blum.loglogn = BASEB-1; - if (nlen > 0 && nlen <= TOPHALF) { - for (blum.loglogn=BASEB-1; - ((FULL)1< nlen && blum.loglogn > 1; - --blum.loglogn) { - } - } - blum.mask = ((HALF)1 << blum.loglogn)-1; + /* + * setup loglogn and mask + * + * If the length if excessive, reduce it down + * so that loglogn is at most BASEB-1. + */ + nlen = (FULL)zhighbit(newn); + blum.loglogn = BASEB-1; + if (nlen > 0 && nlen <= TOPHALF) { + for (blum.loglogn=BASEB-1; + ((FULL)1< nlen && blum.loglogn > 1; + --blum.loglogn) { + } + } + blum.mask = ((HALF)1 << blum.loglogn)-1; - /* - * use default initial seed if seed is 0 and process - * as if this value is given as a 1 arg call - */ - if (ziszero(seed)) { - (void) zsrandom1(z_rdefault, false); + /* + * use default initial seed if seed is 0 and process + * as if this value is given as a 1 arg call + */ + if (ziszero(seed)) { + (void) zsrandom1(z_rdefault, false); - /* - * Otherwise non-zero seeds are processed as 1 arg calls - */ - } else { - (void) zsrandom1(seed, false); - } + /* + * Otherwise non-zero seeds are processed as 1 arg calls + */ + } else { + (void) zsrandom1(seed, false); + } - /* - * reserved newn - */ - } else { - randomfree(ret); - math_error("srandom newn must be [1,20] or >= 2^32"); - not_reached(); - } + /* + * reserved newn + */ + } else { + randomfree(ret); + math_error("srandom newn must be [1,20] or >= 2^32"); + not_reached(); + } - /* - * flush the queued up bits - */ - blum.bits = 0; - blum.buffer = 0; + /* + * flush the queued up bits + */ + blum.bits = 0; + blum.buffer = 0; - /* - * return the previous state - */ - return ret; + /* + * return the previous state + */ + return ret; } @@ -2537,101 +2537,101 @@ zsrandom2(CONST ZVALUE seed, CONST ZVALUE newn) * In particular: * * given: - * pseed - seed of the generator - * ip - initial p search point - * iq - initial q search point - * trials - number of ptests to perform per candidate prime + * pseed - seed of the generator + * ip - initial p search point + * iq - initial q search point + * trials - number of ptests to perform per candidate prime * * returns: - * previous Blum state + * previous Blum state */ RANDOM * zsrandom4(CONST ZVALUE seed, CONST ZVALUE ip, CONST ZVALUE iq, long trials) { - RANDOM *ret; /* previous Blum state */ - FULL nlen; /* length of n=p*q in bits */ - ZVALUE p; /* 1st Blum prime */ - ZVALUE q; /* 2nd Blum prime */ - RANDOM *p_blum; /* malloced RANDOM by randomcopy() */ + RANDOM *ret; /* previous Blum state */ + FULL nlen; /* length of n=p*q in bits */ + ZVALUE p; /* 1st Blum prime */ + ZVALUE q; /* 2nd Blum prime */ + RANDOM *p_blum; /* malloced RANDOM by randomcopy() */ - /* - * initialize state if first call - */ - if (blum_initialized == false || !blum.seeded) { - p_blum = randomcopy(&init_blum); - if (blum_initialized == true) { - randomfree(&blum); - } - blum = *p_blum; - free(p_blum); - blum_initialized = true; - } + /* + * initialize state if first call + */ + if (blum_initialized == false || !blum.seeded) { + p_blum = randomcopy(&init_blum); + if (blum_initialized == true) { + randomfree(&blum); + } + blum = *p_blum; + free(p_blum); + blum_initialized = true; + } - /* - * save the current state to return later - */ - ret = randomcopy(&blum); + /* + * save the current state to return later + */ + ret = randomcopy(&blum); - /* - * search the 'p' and 'q' Blum prime (3 mod 4) candidates - */ - if (!znextcand(ip, trials, _zero_, _three_, _four_, &p)) { - randomfree(ret); - math_error("failed to find 1st Blum prime"); - not_reached(); - } - if (!znextcand(iq, trials, _zero_, _three_, _four_, &q)) { - randomfree(ret); - math_error("failed to find 2nd Blum prime"); - not_reached(); - } + /* + * search the 'p' and 'q' Blum prime (3 mod 4) candidates + */ + if (!znextcand(ip, trials, _zero_, _three_, _four_, &p)) { + randomfree(ret); + math_error("failed to find 1st Blum prime"); + not_reached(); + } + if (!znextcand(iq, trials, _zero_, _three_, _four_, &q)) { + randomfree(ret); + math_error("failed to find 2nd Blum prime"); + not_reached(); + } - /* - * form the Blum modulus - */ - zfree_random(blum.n); - zmul(p, q, &blum.n); - /* free temp storage */ - zfree_random(p); - zfree_random(q); + /* + * form the Blum modulus + */ + zfree_random(blum.n); + zmul(p, q, &blum.n); + /* free temp storage */ + zfree_random(p); + zfree_random(q); - /* - * form the loglogn and mask - */ - nlen = (FULL)zhighbit(blum.n); - blum.loglogn = BASEB-1; - if (nlen > 0 && nlen <= TOPHALF) { - for (blum.loglogn=BASEB-1; - ((FULL)1< nlen && blum.loglogn > 1; - --blum.loglogn) { - } - } - blum.mask = ((HALF)1 << blum.loglogn)-1; + /* + * form the loglogn and mask + */ + nlen = (FULL)zhighbit(blum.n); + blum.loglogn = BASEB-1; + if (nlen > 0 && nlen <= TOPHALF) { + for (blum.loglogn=BASEB-1; + ((FULL)1< nlen && blum.loglogn > 1; + --blum.loglogn) { + } + } + blum.mask = ((HALF)1 << blum.loglogn)-1; - /* - * use default initial seed if seed is 0 and process - * as if this value is given as a 1 arg call - */ - if (ziszero(seed)) { - (void) zsrandom1(z_rdefault, false); + /* + * use default initial seed if seed is 0 and process + * as if this value is given as a 1 arg call + */ + if (ziszero(seed)) { + (void) zsrandom1(z_rdefault, false); - /* - * Otherwise non-zero seeds are processed as 1 arg calls - */ - } else { - (void) zsrandom1(seed, false); - } + /* + * Otherwise non-zero seeds are processed as 1 arg calls + */ + } else { + (void) zsrandom1(seed, false); + } - /* - * flush the queued up bits - */ - blum.bits = 0; - blum.buffer = 0; + /* + * flush the queued up bits + */ + blum.bits = 0; + blum.buffer = 0; - /* - * return the previous state - */ - return ret; + /* + * return the previous state + */ + return ret; } @@ -2639,57 +2639,57 @@ zsrandom4(CONST ZVALUE seed, CONST ZVALUE ip, CONST ZVALUE iq, long trials) * zsetrandom - set the Blum generator state * * given: - * state - the state to copy + * state - the state to copy * * In particular: * - * zsetrandom(pseed) is called by: srandom() and srandom(state) + * zsetrandom(pseed) is called by: srandom() and srandom(state) * * returns: - * previous RANDOM state + * previous RANDOM state */ RANDOM * zsetrandom(CONST RANDOM *state) { - RANDOM *ret; /* previous Blum state */ - RANDOM *p_blum; /* malloced RANDOM by randomcopy() */ + RANDOM *ret; /* previous Blum state */ + RANDOM *p_blum; /* malloced RANDOM by randomcopy() */ - /* NOTE: It is OK for state == NULL */ + /* NOTE: It is OK for state == NULL */ - /* - * initialize state if first call - */ - if (blum_initialized == false || !blum.seeded) { - p_blum = randomcopy(&init_blum); - if (blum_initialized == true) { - randomfree(&blum); - } - blum = *p_blum; - free(p_blum); - blum_initialized = true; - } + /* + * initialize state if first call + */ + if (blum_initialized == false || !blum.seeded) { + p_blum = randomcopy(&init_blum); + if (blum_initialized == true) { + randomfree(&blum); + } + blum = *p_blum; + free(p_blum); + blum_initialized = true; + } - /* - * save the current state to return later - */ - ret = randomcopy(&blum); + /* + * save the current state to return later + */ + ret = randomcopy(&blum); - /* - * load the new state - */ - if (state != NULL) { - p_blum = randomcopy(state); - if (blum_initialized == true) { - randomfree(&blum); - } - blum = *p_blum; - free(p_blum); - } + /* + * load the new state + */ + if (state != NULL) { + p_blum = randomcopy(state); + if (blum_initialized == true) { + randomfree(&blum); + } + blum = *p_blum; + free(p_blum); + } - /* - * return the previous state - */ - return ret; + /* + * return the previous state + */ + return ret; } @@ -2697,83 +2697,83 @@ zsetrandom(CONST RANDOM *state) * zrandomskip - skip s bits via the Blum-Blum-Shub generator * * given: - * count - number of bits to be skipped + * count - number of bits to be skipped */ void zrandomskip(long cnt) { - ZVALUE new_r; /* new quadratic residue */ - long loglogn; /* blum.loglogn */ - RANDOM *p_blum; /* malloced RANDOM by randomcopy() */ + ZVALUE new_r; /* new quadratic residue */ + long loglogn; /* blum.loglogn */ + RANDOM *p_blum; /* malloced RANDOM by randomcopy() */ - /* - * initialize state if first call - */ - if (blum_initialized == false || !blum.seeded) { - p_blum = randomcopy(&init_blum); - if (blum_initialized == true) { - randomfree(&blum); - } - blum = *p_blum; - free(p_blum); - blum_initialized = true; - } - loglogn = (long)blum.loglogn; - new_r.len = 0; /* paranoia */ - new_r.v = NULL; - new_r.sign = 0; + /* + * initialize state if first call + */ + if (blum_initialized == false || !blum.seeded) { + p_blum = randomcopy(&init_blum); + if (blum_initialized == true) { + randomfree(&blum); + } + blum = *p_blum; + free(p_blum); + blum_initialized = true; + } + loglogn = (long)blum.loglogn; + new_r.len = 0; /* paranoia */ + new_r.v = NULL; + new_r.sign = 0; - /* - * skip required bits in the buffer - */ - if (blum.bits > 0) { + /* + * skip required bits in the buffer + */ + if (blum.bits > 0) { - /* - * depending in if we have too few or too many in the buffer - */ - if (blum.bits <= cnt) { + /* + * depending in if we have too few or too many in the buffer + */ + if (blum.bits <= cnt) { - /* too few - just toss the buffer bits */ - cnt -= blum.bits; - blum.bits = 0; - blum.buffer = 0; + /* too few - just toss the buffer bits */ + cnt -= blum.bits; + blum.bits = 0; + blum.buffer = 0; - } else { + } else { - /* buffer contains more bits than we need to toss */ - blum.buffer >>= cnt; - blum.bits -= cnt; - return; /* skip need satisfied */ - } - } + /* buffer contains more bits than we need to toss */ + blum.buffer >>= cnt; + blum.bits -= cnt; + return; /* skip need satisfied */ + } + } - /* - * skip loglogn bits at a time - */ - while (cnt >= loglogn) { + /* + * skip loglogn bits at a time + */ + while (cnt >= loglogn) { - /* turn the Blum-Blum-Shub crank */ - zsquaremod(blum.r, blum.n, &new_r); - zfree_random(blum.r); - blum.r = new_r; - cnt -= blum.loglogn; - } + /* turn the Blum-Blum-Shub crank */ + zsquaremod(blum.r, blum.n, &new_r); + zfree_random(blum.r); + blum.r = new_r; + cnt -= blum.loglogn; + } - /* - * skip the final bits - */ - if (cnt > 0) { + /* + * skip the final bits + */ + if (cnt > 0) { - /* turn the Blum-Blum-Shub crank */ - zsquaremod(blum.r, blum.n, &new_r); - zfree_random(blum.r); - blum.r = new_r; + /* turn the Blum-Blum-Shub crank */ + zsquaremod(blum.r, blum.n, &new_r); + zfree_random(blum.r); + blum.r = new_r; - /* fill the buffer with the unused bits */ - blum.bits = loglogn - cnt; - blum.buffer = (blum.r.v[0] & lowhalf[blum.bits]); - } - return; + /* fill the buffer with the unused bits */ + blum.bits = loglogn - cnt; + blum.buffer = (blum.r.v[0] & lowhalf[blum.bits]); + } + return; } @@ -2785,192 +2785,192 @@ zrandomskip(long cnt) * least significant HALF. * * given: - * count - number of bits required - * res - where to place the random bits as ZVALUE + * count - number of bits required + * res - where to place the random bits as ZVALUE */ void zrandom(long cnt, ZVALUE *res) { - BITSTR dest; /* destination bit string */ - int loglogn; /* blum.loglogn */ - HALF mask; /* mask for bottom loglogn bits */ - ZVALUE new_r; /* new quadratic residue */ - RANDOM *p_blum; /* malloced RANDOM by randomcopy() */ - int t; /* temp shift value */ + BITSTR dest; /* destination bit string */ + int loglogn; /* blum.loglogn */ + HALF mask; /* mask for bottom loglogn bits */ + ZVALUE new_r; /* new quadratic residue */ + RANDOM *p_blum; /* malloced RANDOM by randomcopy() */ + int t; /* temp shift value */ - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - /* - * firewall - */ - if (cnt <= 0) { - if (cnt == 0) { - /* zero length random number is always 0 */ - itoz(0, res); - return; - } else { - math_error("negative zrandom bit count"); - not_reached(); - } + /* + * firewall + */ + if (cnt <= 0) { + if (cnt == 0) { + /* zero length random number is always 0 */ + itoz(0, res); + return; + } else { + math_error("negative zrandom bit count"); + not_reached(); + } #if LONG_BITS > 32 - } else if (cnt > (1L<<31)) { - math_error("huge random count in internal zrandom function"); - not_reached(); + } else if (cnt > (1L<<31)) { + math_error("huge random count in internal zrandom function"); + not_reached(); #endif - } + } - /* - * initialize state if first call - */ - if (blum_initialized == false || !blum.seeded) { - p_blum = randomcopy(&init_blum); - if (blum_initialized == true) { - randomfree(&blum); - } - blum = *p_blum; - free(p_blum); - blum_initialized = true; - } - loglogn = blum.loglogn; - mask = blum.mask; - new_r.len = 0; /* paranoia */ - new_r.v = NULL; - new_r.sign = 0; + /* + * initialize state if first call + */ + if (blum_initialized == false || !blum.seeded) { + p_blum = randomcopy(&init_blum); + if (blum_initialized == true) { + randomfree(&blum); + } + blum = *p_blum; + free(p_blum); + blum_initialized = true; + } + loglogn = blum.loglogn; + mask = blum.mask; + new_r.len = 0; /* paranoia */ + new_r.v = NULL; + new_r.sign = 0; - /* - * allocate storage - */ - res->len = (LEN)((cnt+BASEB-1)/BASEB); - res->v = alloc((LEN)((cnt+BASEB-1)/BASEB)); + /* + * allocate storage + */ + res->len = (LEN)((cnt+BASEB-1)/BASEB); + res->v = alloc((LEN)((cnt+BASEB-1)/BASEB)); - /* - * dest bit string - */ - dest.len = (int)cnt; - dest.loc = res->v + (((cnt+BASEB-1)/BASEB)-1); - dest.bit = (int)((cnt-1) % BASEB); - *dest.loc = 0; + /* + * dest bit string + */ + dest.len = (int)cnt; + dest.loc = res->v + (((cnt+BASEB-1)/BASEB)-1); + dest.bit = (int)((cnt-1) % BASEB); + *dest.loc = 0; - /* - * load from buffer first - */ - if (blum.bits > 0) { + /* + * load from buffer first + */ + if (blum.bits > 0) { - /* - * If we need only part of the buffer, use - * the top bits and keep the bottom in place. - * If we need exactly all of the buffer, - * process it as a partial buffer fill. - */ - if (dest.len <= blum.bits) { + /* + * If we need only part of the buffer, use + * the top bits and keep the bottom in place. + * If we need exactly all of the buffer, + * process it as a partial buffer fill. + */ + if (dest.len <= blum.bits) { - /* load part of the buffer */ - *dest.loc = (blum.buffer >> (blum.bits-dest.len)); + /* load part of the buffer */ + *dest.loc = (blum.buffer >> (blum.bits-dest.len)); - /* update buffer */ - blum.buffer &= ((1 << (blum.bits-dest.len))-1); - blum.bits -= dest.len; + /* update buffer */ + blum.buffer &= ((1 << (blum.bits-dest.len))-1); + blum.bits -= dest.len; - /* cleanup */ - res->sign = 0; - ztrim(res); + /* cleanup */ + res->sign = 0; + ztrim(res); - /* we are done now */ - return; - } + /* we are done now */ + return; + } - /* - * Otherwise we need all of the buffer and then some ... - * - * dest.len > blum.bits - * - * NOTE: We use = instead of |= as this will ensure that - * bit bits above dest.bit are set to 0. - */ - if (dest.bit >= blum.bits) { - /* copy all of buffer into upper element */ - *dest.loc = (blum.buffer << (dest.bit+1-blum.bits)); - dest.bit -= blum.bits; - } else { - /* copy buffer into upper and next element */ - t = blum.bits-(dest.bit+1); - *dest.loc-- = (blum.buffer >> t); - dest.bit = BASEB-t-1; - *dest.loc = (HALF)(((unsigned long)(blum.buffer&lowhalf[t])) << (dest.bit+1)); - } - dest.len -= blum.bits; - } + /* + * Otherwise we need all of the buffer and then some ... + * + * dest.len > blum.bits + * + * NOTE: We use = instead of |= as this will ensure that + * bit bits above dest.bit are set to 0. + */ + if (dest.bit >= blum.bits) { + /* copy all of buffer into upper element */ + *dest.loc = (blum.buffer << (dest.bit+1-blum.bits)); + dest.bit -= blum.bits; + } else { + /* copy buffer into upper and next element */ + t = blum.bits-(dest.bit+1); + *dest.loc-- = (blum.buffer >> t); + dest.bit = BASEB-t-1; + *dest.loc = (HALF)(((unsigned long)(blum.buffer&lowhalf[t])) << (dest.bit+1)); + } + dest.len -= blum.bits; + } - /* - * Crank the generator up until, but not including, the - * time when we will write into the least significant bit. - * - * In this loop we know that we have exactly blum.loglogn bits - * to load. - */ - while (dest.len > loglogn) { + /* + * Crank the generator up until, but not including, the + * time when we will write into the least significant bit. + * + * In this loop we know that we have exactly blum.loglogn bits + * to load. + */ + while (dest.len > loglogn) { - /* - * turn the Blum-Blum-Shub crank - */ - zsquaremod(blum.r, blum.n, &new_r); - zfree_random(blum.r); - blum.r = new_r; - /* peal off the bottom loglogn bits */ - blum.buffer = (blum.r.v[0] & mask); + /* + * turn the Blum-Blum-Shub crank + */ + zsquaremod(blum.r, blum.n, &new_r); + zfree_random(blum.r); + blum.r = new_r; + /* peal off the bottom loglogn bits */ + blum.buffer = (blum.r.v[0] & mask); - /* - * load the loglogn bits into dest.loc starting at bit dest.bit - */ - if (dest.bit >= loglogn) { - /* copy all of buffer into upper element */ - *dest.loc |= (blum.buffer << (dest.bit+1-loglogn)); - dest.bit -= loglogn; - } else { - /* copy buffer into upper and next element */ - t = loglogn-(dest.bit+1); - *dest.loc-- |= (blum.buffer >> t); - dest.bit = BASEB-t-1; - *dest.loc = (HALF)(((unsigned long)(blum.buffer&lowhalf[t])) << (dest.bit+1)); - } - dest.len -= loglogn; - } + /* + * load the loglogn bits into dest.loc starting at bit dest.bit + */ + if (dest.bit >= loglogn) { + /* copy all of buffer into upper element */ + *dest.loc |= (blum.buffer << (dest.bit+1-loglogn)); + dest.bit -= loglogn; + } else { + /* copy buffer into upper and next element */ + t = loglogn-(dest.bit+1); + *dest.loc-- |= (blum.buffer >> t); + dest.bit = BASEB-t-1; + *dest.loc = (HALF)(((unsigned long)(blum.buffer&lowhalf[t])) << (dest.bit+1)); + } + dest.len -= loglogn; + } - /* - * We have a full or less than a full crank (loglogn bits) left - * to generate and load into the least significant bits. - * - * If we have any bits left over, we will save them in the - * buffer for use by the next call. - */ - /* turn the Blum-Blum-Shub crank */ - zsquaremod(blum.r, blum.n, &new_r); - zfree_random(blum.r); - blum.r = new_r; - /* peal off the bottom loglogn bits */ - blum.buffer = (blum.r.v[0] & mask); - blum.bits = loglogn; + /* + * We have a full or less than a full crank (loglogn bits) left + * to generate and load into the least significant bits. + * + * If we have any bits left over, we will save them in the + * buffer for use by the next call. + */ + /* turn the Blum-Blum-Shub crank */ + zsquaremod(blum.r, blum.n, &new_r); + zfree_random(blum.r); + blum.r = new_r; + /* peal off the bottom loglogn bits */ + blum.buffer = (blum.r.v[0] & mask); + blum.bits = loglogn; - /* - * load dest.len bits into the lowest order bits - */ - *dest.loc |= (blum.buffer >> (loglogn - dest.len)); + /* + * load dest.len bits into the lowest order bits + */ + *dest.loc |= (blum.buffer >> (loglogn - dest.len)); - /* - * leave any unused bits in the buffer for next time - */ - blum.buffer &= lowhalf[loglogn - dest.len]; - blum.bits -= dest.len; + /* + * leave any unused bits in the buffer for next time + */ + blum.buffer &= lowhalf[loglogn - dest.len]; + blum.bits -= dest.len; - /* - * cleanup - */ - res->sign = 0; - ztrim(res); + /* + * cleanup + */ + res->sign = 0; + ztrim(res); } @@ -2978,69 +2978,69 @@ zrandom(long cnt, ZVALUE *res) * zrandomrange - generate a Blum-Blum-Shub random value in [low, beyond) * * given: - * low - low value of range - * beyond - beyond end of range - * res - where to place the random bits as ZVALUE + * low - low value of range + * beyond - beyond end of range + * res - where to place the random bits as ZVALUE */ void zrandomrange(CONST ZVALUE low, CONST ZVALUE beyond, ZVALUE *res) { - ZVALUE range; /* beyond-low */ - ZVALUE rval; /* random value [0, 2^bitlen) */ - ZVALUE rangem1; /* range - 1 */ - long bitlen; /* smallest power of 2 >= diff */ + ZVALUE range; /* beyond-low */ + ZVALUE rval; /* random value [0, 2^bitlen) */ + ZVALUE rangem1; /* range - 1 */ + long bitlen; /* smallest power of 2 >= diff */ - /* firewall */ - if (res == NULL) { - math_error("%s: res NULL", __func__); - not_reached(); - } + /* firewall */ + if (res == NULL) { + math_error("%s: res NULL", __func__); + not_reached(); + } - /* - * firewall - */ - if (zrel(low, beyond) >= 0) { - math_error("srand low range >= beyond range"); - not_reached(); - } + /* + * firewall + */ + if (zrel(low, beyond) >= 0) { + math_error("srand low range >= beyond range"); + not_reached(); + } - /* - * determine the size of the random number needed - */ - zsub(beyond, low, &range); - if (zisone(range)) { - zfree_random(range); - zcopy(low, res); - return; - } - zsub(range, _one_, &rangem1); - bitlen = 1+zhighbit(rangem1); - zfree_random(rangem1); + /* + * determine the size of the random number needed + */ + zsub(beyond, low, &range); + if (zisone(range)) { + zfree_random(range); + zcopy(low, res); + return; + } + zsub(range, _one_, &rangem1); + bitlen = 1+zhighbit(rangem1); + zfree_random(rangem1); - /* - * generate a random value between [0, diff) - * - * We will not fall into the trap of thinking that we can simply take - * a value mod 'range'. Consider the case where 'range' is '80' - * and we are given pseudo-random numbers [0,100). If we took them - * mod 80, then the numbers [0,20) would be produced more frequently - * because the numbers [81,100) mod 80 wrap back into [0,20). - */ - rval.v = NULL; - do { - if (rval.v != NULL) { - zfree_random(rval); - } - zrandom(bitlen, &rval); - } while (zrel(rval, range) >= 0); + /* + * generate a random value between [0, diff) + * + * We will not fall into the trap of thinking that we can simply take + * a value mod 'range'. Consider the case where 'range' is '80' + * and we are given pseudo-random numbers [0,100). If we took them + * mod 80, then the numbers [0,20) would be produced more frequently + * because the numbers [81,100) mod 80 wrap back into [0,20). + */ + rval.v = NULL; + do { + if (rval.v != NULL) { + zfree_random(rval); + } + zrandom(bitlen, &rval); + } while (zrel(rval, range) >= 0); - /* - * add in low value to produce the range [0+low, diff+low) - * which is the range [low, beyond) - */ - zadd(rval, low, res); - zfree_random(rval); - zfree_random(range); + /* + * add in low value to produce the range [0+low, diff+low) + * which is the range [low, beyond) + */ + zadd(rval, low, res); + zfree_random(rval); + zfree_random(range); } @@ -3048,29 +3048,29 @@ zrandomrange(CONST ZVALUE low, CONST ZVALUE beyond, ZVALUE *res) * irandom - generate a Blum-Blum-Shub random long in the range [0, s) * * given: - * s - limit of the range + * s - limit of the range * * returns: - * random long in the range [0, s) + * random long in the range [0, s) */ long irandom(long s) { - ZVALUE z1, z2; - long res; + ZVALUE z1, z2; + long res; - if (s <= 0) { - math_error("Non-positive argument for irandom()"); - not_reached(); - } - if (s == 1) - return 0; - itoz(s, &z1); - zrandomrange(_zero_, z1, &z2); - res = ztoi(z2); - zfree_random(z1); - zfree_random(z2); - return res; + if (s <= 0) { + math_error("Non-positive argument for irandom()"); + not_reached(); + } + if (s == 1) + return 0; + itoz(s, &z1); + zrandomrange(_zero_, z1, &z2); + res = ztoi(z2); + zfree_random(z1); + zfree_random(z2); + return res; } @@ -3078,58 +3078,58 @@ irandom(long s) * randomcopy - make a copy of a Blum state * * given: - * state - the state to copy + * state - the state to copy * * returns: - * a malloced copy of the state + * a malloced copy of the state */ RANDOM * randomcopy(CONST RANDOM *state) { - RANDOM *ret; /* return copy of state */ + RANDOM *ret; /* return copy of state */ - /* firewall */ - if (state == NULL) { - math_error("%s: state NULL", __func__); - not_reached(); - } + /* firewall */ + if (state == NULL) { + math_error("%s: state NULL", __func__); + not_reached(); + } - /* - * malloc state - */ - ret = (RANDOM *)malloc(sizeof(RANDOM)); - if (ret == NULL) { - math_error("can't allocate RANDOM state"); - not_reached(); - } + /* + * malloc state + */ + ret = (RANDOM *)malloc(sizeof(RANDOM)); + if (ret == NULL) { + math_error("can't allocate RANDOM state"); + not_reached(); + } - /* - * clone data - */ - *ret = *state; - if (state->r.v == NULL) { - ret->r.v = NULL; - } else { - if (state->r.v == h_rdefvec) { - ret->r.v = state->r.v; - } else { - zcopy(state->r, &ret->r); - } - } - if (state->n.v == NULL) { - ret->n.v = NULL; - } else { - if (state->n.v == h_ndefvec) { - ret->n.v = state->n.v; - } else { - zcopy(state->n, &ret->n); - } - } + /* + * clone data + */ + *ret = *state; + if (state->r.v == NULL) { + ret->r.v = NULL; + } else { + if (state->r.v == h_rdefvec) { + ret->r.v = state->r.v; + } else { + zcopy(state->r, &ret->r); + } + } + if (state->n.v == NULL) { + ret->n.v = NULL; + } else { + if (state->n.v == h_ndefvec) { + ret->n.v = state->n.v; + } else { + zcopy(state->n, &ret->n); + } + } - /* - * return copy - */ - return ret; + /* + * return copy + */ + return ret; } @@ -3140,32 +3140,32 @@ randomcopy(CONST RANDOM *state) * never malloced in the first place. * * given: - * state - the state to free + * state - the state to free */ void randomfree(RANDOM *state) { - /* firewall */ - if (state == NULL) { - math_error("%s: state NULL", __func__); - not_reached(); - } + /* firewall */ + if (state == NULL) { + math_error("%s: state NULL", __func__); + not_reached(); + } - /* clear the seed */ - state->seeded = 0; - state->bits = 0; /* paranoia */ - state->loglogn = 0; /* paranoia */ - state->buffer = 0; /* paranoia */ - state->mask = 0; /* paranoia */ + /* clear the seed */ + state->seeded = 0; + state->bits = 0; /* paranoia */ + state->loglogn = 0; /* paranoia */ + state->buffer = 0; /* paranoia */ + state->mask = 0; /* paranoia */ - /* free the values - unless they are one of the default states */ - zfree_random(state->n); - zfree_random(state->r); + /* free the values - unless they are one of the default states */ + zfree_random(state->n); + zfree_random(state->r); - /* free the RANDOM structure if it is NOT our static blum value */ - if (state != &blum) { - free(state); - } + /* free the RANDOM structure if it is NOT our static blum value */ + if (state != &blum) { + free(state); + } } @@ -3173,59 +3173,59 @@ randomfree(RANDOM *state) * randomcmp - compare two Blum states * * given: - * s1 - first state to compare - * s2 - second state to compare + * s1 - first state to compare + * s2 - second state to compare * * return: - * true if states differ + * true if states differ */ bool randomcmp(CONST RANDOM *s1, CONST RANDOM *s2) { - /* firewall */ - if (s1 == NULL) { - math_error("%s: s1 NULL", __func__); - not_reached(); - } - if (s2 == NULL) { - math_error("%s: s2 NULL", __func__); - not_reached(); - } + /* firewall */ + if (s1 == NULL) { + math_error("%s: s1 NULL", __func__); + not_reached(); + } + if (s2 == NULL) { + math_error("%s: s2 NULL", __func__); + not_reached(); + } - /* - * assume uninitialized state == the default seeded state - */ - if (!s1->seeded) { - if (!s2->seeded) { - /* uninitialized == uninitialized */ - return false; - } else { - /* uninitialized only equals default state */ - return randomcmp(s2, &init_blum); - } - } else if (!s2->seeded) { - /* uninitialized only equals default state */ - return randomcmp(s1, &init_blum); - } + /* + * assume uninitialized state == the default seeded state + */ + if (!s1->seeded) { + if (!s2->seeded) { + /* uninitialized == uninitialized */ + return false; + } else { + /* uninitialized only equals default state */ + return randomcmp(s2, &init_blum); + } + } else if (!s2->seeded) { + /* uninitialized only equals default state */ + return randomcmp(s1, &init_blum); + } - /* - * compare operating mask parameters - */ - if ((s1->loglogn != s2->loglogn) || (s1->mask != s2->mask)) { - return true; - } + /* + * compare operating mask parameters + */ + if ((s1->loglogn != s2->loglogn) || (s1->mask != s2->mask)) { + return true; + } - /* - * compare bit buffer - */ - if ((s1->bits != s2->bits) || (s1->buffer != s2->buffer)) { - return true; - } + /* + * compare bit buffer + */ + if ((s1->bits != s2->bits) || (s1->buffer != s2->buffer)) { + return true; + } - /* - * compare quadratic residues and moduli - */ - return (zcmp(s1->r, s2->r) && zcmp(s1->n, s2->n)); + /* + * compare quadratic residues and moduli + */ + return (zcmp(s1->r, s2->r) && zcmp(s1->n, s2->n)); } @@ -3233,15 +3233,15 @@ randomcmp(CONST RANDOM *s1, CONST RANDOM *s2) * randomprint - print a Blum state * * given: - * state - state to print - * flags - print flags passed from printvalue() in value.c + * state - state to print + * flags - print flags passed from printvalue() in value.c */ /*ARGSUSED*/ void randomprint(CONST RANDOM *UNUSED(state), int UNUSED(flags)) { - /* NOTE: It is OK for state == NULL */ - math_str("RANDOM state"); + /* NOTE: It is OK for state == NULL */ + math_str("RANDOM state"); } @@ -3251,16 +3251,16 @@ randomprint(CONST RANDOM *UNUSED(state), int UNUSED(flags)) * This call is needed only by libcalc_call_me_last() to help clean up any * unneeded storage. * - * Do not call this function directly! Let libcalc_call_me_last() do it. + * Do not call this function directly! Let libcalc_call_me_last() do it. */ void random_libcalc_cleanup(void) { - /* free our state if seed was initialized - zfree_random protect default states */ - if (blum_initialized == true && blum.seeded) { - randomfree(&blum); - } - return; + /* free our state if seed was initialized - zfree_random protect default states */ + if (blum_initialized == true && blum.seeded) { + randomfree(&blum); + } + return; } @@ -3268,35 +3268,35 @@ random_libcalc_cleanup(void) * zfree_random - perform a zfree if we are not trying to free static data * * given: - * z the ZVALUE to zfree(z) if not pointing to static data + * z the ZVALUE to zfree(z) if not pointing to static data */ S_FUNC void zfree_random(ZVALUE z) { - /* do not free if NULL or one of the default states */ - if (z.v != NULL && - z.v != h_ndefvec && z.v != h_rdefvec && z.v != h_rdefvec_2 && - z.v != h_nvec01 && z.v != h_rvec01 && - z.v != h_nvec02 && z.v != h_rvec02 && - z.v != h_nvec03 && z.v != h_rvec03 && - z.v != h_nvec04 && z.v != h_rvec04 && - z.v != h_nvec05 && z.v != h_rvec05 && - z.v != h_nvec06 && z.v != h_rvec06 && - z.v != h_nvec07 && z.v != h_rvec07 && - z.v != h_nvec08 && z.v != h_rvec08 && - z.v != h_nvec09 && z.v != h_rvec09 && - z.v != h_nvec10 && z.v != h_rvec10 && - z.v != h_nvec11 && z.v != h_rvec11 && - z.v != h_nvec12 && z.v != h_rvec12 && - z.v != h_nvec13 && z.v != h_rvec13 && - z.v != h_nvec14 && z.v != h_rvec14 && - z.v != h_nvec15 && z.v != h_rvec15 && - z.v != h_nvec16 && z.v != h_rvec16 && - z.v != h_nvec17 && z.v != h_rvec17 && - z.v != h_nvec18 && z.v != h_rvec18 && - z.v != h_nvec19 && z.v != h_rvec19 && - z.v != h_nvec20 && z.v != h_rvec20) { - zfree(z); - } - return; + /* do not free if NULL or one of the default states */ + if (z.v != NULL && + z.v != h_ndefvec && z.v != h_rdefvec && z.v != h_rdefvec_2 && + z.v != h_nvec01 && z.v != h_rvec01 && + z.v != h_nvec02 && z.v != h_rvec02 && + z.v != h_nvec03 && z.v != h_rvec03 && + z.v != h_nvec04 && z.v != h_rvec04 && + z.v != h_nvec05 && z.v != h_rvec05 && + z.v != h_nvec06 && z.v != h_rvec06 && + z.v != h_nvec07 && z.v != h_rvec07 && + z.v != h_nvec08 && z.v != h_rvec08 && + z.v != h_nvec09 && z.v != h_rvec09 && + z.v != h_nvec10 && z.v != h_rvec10 && + z.v != h_nvec11 && z.v != h_rvec11 && + z.v != h_nvec12 && z.v != h_rvec12 && + z.v != h_nvec13 && z.v != h_rvec13 && + z.v != h_nvec14 && z.v != h_rvec14 && + z.v != h_nvec15 && z.v != h_rvec15 && + z.v != h_nvec16 && z.v != h_rvec16 && + z.v != h_nvec17 && z.v != h_rvec17 && + z.v != h_nvec18 && z.v != h_rvec18 && + z.v != h_nvec19 && z.v != h_rvec19 && + z.v != h_nvec20 && z.v != h_rvec20) { + zfree(z); + } + return; } diff --git a/zrandom.h b/zrandom.h index a13485f..551ae6f 100644 --- a/zrandom.h +++ b/zrandom.h @@ -9,7 +9,7 @@ * * 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 + * 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 @@ -17,11 +17,11 @@ * received a copy with calc; if not, write to Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Under source code control: 1997/02/15 04:01:56 - * File existed as early as: 1997 + * Under source code control: 1997/02/15 04:01:56 + * File existed as early as: 1997 * - * chongo /\oo/\ http://www.isthe.com/chongo/ - * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ + * chongo /\oo/\ http://www.isthe.com/chongo/ + * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ @@ -29,7 +29,7 @@ #define INCLUDE_ZRANDOM_H -#if defined(CALC_SRC) /* if we are building from the calc source tree */ +#if defined(CALC_SRC) /* if we are building from the calc source tree */ # include "value.h" # include "have_const.h" #else @@ -46,25 +46,25 @@ * most this implies that a turn can yield no more than 15 bits when BASEB==16 * or 31 bits when BASEB==32. Should we deal with a excessively large * Blum modulus (>=2^16 bits long for BASEB==16, >=2^32 bits for BASEB==32) - * the higher order random bits will be tossed. This is not a loss as + * the higher order random bits will be tossed. This is not a loss as * regular sub-segments of the sequence are just as random. It only means * that excessively large Blum modulus values waste CPU time. */ struct random { - int seeded; /* 1 => state has been seeded */ - int bits; /* number of unused bits in buffer */ - int loglogn; /* int(log2(log2(n))), bits produced per turn */ - HALF buffer; /* unused random bits from previous call */ - HALF mask; /* mask for the log2(log2(n)) lower bits of r */ - ZVALUE n; /* Blum modulus */ - ZVALUE r; /* Blum quadratic residue */ + int seeded; /* 1 => state has been seeded */ + int bits; /* number of unused bits in buffer */ + int loglogn; /* int(log2(log2(n))), bits produced per turn */ + HALF buffer; /* unused random bits from previous call */ + HALF mask; /* mask for the log2(log2(n)) lower bits of r */ + ZVALUE n; /* Blum modulus */ + ZVALUE r; /* Blum quadratic residue */ }; /* * Blum constants */ -#define BLUM_PREGEN 20 /* number of non-default predefined Blum generators */ +#define BLUM_PREGEN 20 /* number of non-default predefined Blum generators */ /* @@ -73,7 +73,7 @@ struct random { E_FUNC RANDOM *zsrandom1(CONST ZVALUE seed, bool need_ret); E_FUNC RANDOM *zsrandom2(CONST ZVALUE seed, CONST ZVALUE newn); E_FUNC RANDOM *zsrandom4(CONST ZVALUE seed, - CONST ZVALUE ip, CONST ZVALUE iq, long trials); + CONST ZVALUE ip, CONST ZVALUE iq, long trials); E_FUNC RANDOM *zsetrandom(CONST RANDOM *state); E_FUNC void zrandomskip(long count); E_FUNC void zrandom(long count, ZVALUE *res);