Compare commits

..

7 Commits

Author SHA1 Message Date
Landon Curt Noll
e555a718c0 Released calc 2.12.6.7 with help and input fixes
Fixed errors in various help files such as:

	mat randbit seed srandom types

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

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

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

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

    Increased interactive input buffer size from 1024 to 256k.  This has the
    effect of increasing the maximum length of an input line from a tty.
    This helps with an interactive bug that was reported by Ruslan Kabatsayev
    (b7 dot 10110111 at gmail dot com).
k
2018-03-04 11:09:09 -08:00
Landon Curt Noll
b29fcf2dd5 Fixed errors in various help files 2018-02-27 18:21:46 -08:00
Landon Curt Noll
4f86703843 Fix long lines 2018-02-27 16:16:06 -08:00
Landon Curt Noll
07d8bf0f3e Version 2.12.6.6 2018-02-21 12:38:39 -08:00
Landon Curt Noll
b4cd692bae Fixed compiler warnings
Fixed some compiler warnings.
Added work around for a gcc warning bug.
2018-02-21 12:37:46 -08:00
Landon Curt Noll
83c898cc2b Improved how lucas.cal pre-verifies numbers 2018-02-21 12:36:21 -08:00
Landon Curt Noll
c585d7aa78 Release calc version 2.12.6.5 2018-01-28 18:26:08 -08:00
19 changed files with 159 additions and 56 deletions

42
CHANGES
View File

@@ -1,4 +1,44 @@
The following are the changes from calc version 2.12.6.1 to date:
The following are the changes from calc version 2.12.6.6 to date:
For historical purposes, in lucas.cal, gen_v1(1, n) always returns 4.
Fixed some compiler warnings, thanks to a report by Mike
<michael dot d dot ince at gmail dot com>.
Added work around for a gcc warning bug, thanks to a report by Mike
<michael dot d dot ince at gmail dot com>.
Fixed errors in various help files such as:
mat randbit seed srandom types
Removed the MAXSTRING symbol because it was no longer used by calc.
Increased HIST_SIZE (depth of the history stack) from 10k to 32k.
Increased TTYSIZE (reallocation size for terminal buffers) from 100 to 8191.
Increased MAXDEPTH (maximum depth of input stack) from 10 to 255.
Increased interactive input buffer size from 1024 to 256k. This has the
effect of increasing the maximum length of an input line from a tty.
This helps with an interactive bug that was reported by Ruslan Kabatsayev
(b7 dot 10110111 at gmail dot com).
The following are the changes from calc version 2.12.6.4 to 2.12.6.5:
Fixed warning about undefined operations involving the qlink(q)
macro by replacing that macro with an inline-function. Thanks goes
to David Haller <dnh at opensuse dot org> for this fix.
NOTE for Windows 10 users: Pavel Nemec <pane at seznam dot cz>
reported that calc version 2.12.6.4 has been successfully
compiled, installed and running on Windows 10. See README.WINDOWS
for more details.
The following are the changes from calc version 2.12.6.1 to 2.12.6.3:
Improved gen_v1(h,n) in lucas.cal to use an even faster search method.

View File

@@ -1054,7 +1054,7 @@ EXT=
# The default calc versions
#
VERSION= 2.12.6.4
VERSION= 2.12.6.7
# Names of shared libraries with versions
#

View File

@@ -10,6 +10,21 @@ NOTE: The main developers do not have access to a Windoz based platform.
Of course you are welcome to send us any patches that fix your
Windoz build environment.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-= compiling with Windows Subsystem for Linux (WSL) =-Cygwin =-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
It has been reported that calc version 2.12.6.4 has been successfully
compiled, installed and running on Windows 10 on 2018 Jan 21.
We were told:
"The Windows Subsystem for Linux (WSL) is a new Windows 10 feature that
enables you to run native Linux command-line tools directly on Windows"
https://docs.microsoft.com/cs-cz/windows/wsl/about
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-= compiling with Cygwin =-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

View File

@@ -1,7 +1,7 @@
/*
* lucas - perform a Lucas primality test on h*2^n-1
*
* Copyright (C) 1999,2017 Landon Curt Noll
* Copyright (C) 1999,2017,2018 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
@@ -373,41 +373,53 @@ lucas(h, n)
return 1; /* 239 is prime */
}
/*
* Verify that h*2^n-1 is not a multiple of 3
*
* The case for h*2^n-1 == 3 is handled above.
*/
if (((h % 3 == 1) && (n % 2 == 0)) || ((h % 3 == 2) && (n % 2 == 1))) {
/* no need to test h*2^n-1, it is a multiple of 3 */
ldebug("lucas","not-prime: != 3 and is a multiple of 3");
return 0;
}
/*
* Avoid any numbers divisible by small primes
*/
/*
* check for 3 <= prime factors < 29
* pfact(28)/2 = 111546435
* check for 5 <= prime factors < 31
* pfact(30)/6 = 1078282205
*/
testval = h*2^n - 1;
if (gcd(testval, 111546435) > 1) {
/* a small 3 <= prime < 29 divides h*2^n-1 */
ldebug("lucas","not-prime: 3<=prime<29 divides h*2^n-1");
if (gcd(testval, 1078282205) > 1) {
/* a small 5 <= prime < 31 divides h*2^n-1 */
ldebug("lucas",\
"not-prime: a small 5<=prime<31 divides h*2^n-1");
return 0;
}
/*
* check for 29 <= prime factors < 47
* pfact(46)/pfact(28) = 5864229
* check for 31 <= prime factors < 53
* pfact(52)/pfact(30) = 95041567
*/
if (gcd(testval, 58642669) > 1) {
/* a small 29 <= prime < 47 divides h*2^n-1 */
ldebug("lucas","not-prime: 29<=prime<47 divides h*2^n-1");
if (gcd(testval, 95041567) > 1) {
/* a small 31 <= prime < 53 divides h*2^n-1 */
ldebug("lucas","not-prime: 31<=prime<53 divides h*2^n-1");
return 0;
}
/*
* check for prime 47 <= factors < 257, if h*2^n-1 is large
* 2^282 > pfact(256)/pfact(46) > 2^281
* check for prime 53 <= factors < 257, if h*2^n-1 is large
* 2^276 > pfact(256)/pfact(52) > 2^275
*/
bits = highbit(testval);
if (bits >= 281) {
if (bits >= 275) {
if (pprod256 <= 0) {
pprod256 = pfact(256)/pfact(46);
pprod256 = pfact(256)/pfact(52);
}
if (gcd(testval, pprod256) > 1) {
/* a small 47 <= prime < 257 divides h*2^n-1 */
/* a small 53 <= prime < 257 divides h*2^n-1 */
ldebug("lucas",\
"not-prime: 47<=prime<257 divides h*2^n-1");
"not-prime: 53<=prime<257 divides h*2^n-1");
return 0;
}
}
@@ -423,7 +435,9 @@ lucas(h, n)
* generate a test for h*2^n-1. The legacy function,
* legacy_gen_v1() used by the Amdahl 6 could have returned
* -1. The new gen_v1() based on the method outlined in Ref4
* will never return -1.
* will never return -1 if h*2^n-1 is not a multiple of 3.
* Because the "multiple of 3" case is handled above, the
* call below to gen_v1() will never return -1.
*/
v1 = gen_v1(h, n);
if (v1 < 0) {
@@ -1172,6 +1186,26 @@ gen_v1(h, n)
return -1;
}
/*
* Common Mersenne number case:
*
* For Mersenne numbers:
*
* 2^n-1
*
* we can use, 40% of the time, v(1) == 3. However nearly all code that
* implements the Lucas-Lehmer test uses v(1) == 4. Whenever for
* h != 0 mod 3, and particular the Mersenne number case of when h == 1:
*
* 1*2^n-1
*
* v(1) == 4 always works. For this reason, we return 4 when h == 1.
*/
if (h == 1) {
/* v(1) == 4 always works for the Mersenne number case */
return 4;
}
/*
* check for Case 1: (h mod 3 != 0)
*/

17
calc.c
View File

@@ -104,6 +104,8 @@ main(int argc, char **argv)
int c; /* option */
int index;
int maxindex;
/* fix gcc warning bug */
int unusedint = 0;
char *cp;
char *endcp;
char *bp;
@@ -278,7 +280,9 @@ main(int argc, char **argv)
exit(6);
}
calc_debug = cp;
(void) strtol(cp, &endcp, 10);
/* fix gcc warning bug */
unusedint =
strtol(cp, &endcp, 10);
cp = endcp;
if (*cp != '\0' &&
*cp != ' ' && *cp != ':') {
@@ -310,7 +314,9 @@ main(int argc, char **argv)
exit(9);
}
resource_debug = cp;
(void) strtol(cp, &endcp, 10);
/* fix gcc warning bug */
unusedint =
strtol(cp, &endcp, 10);
cp = endcp;
if (*cp != '\0' &&
*cp != ' ' && *cp != ':') {
@@ -340,7 +346,8 @@ main(int argc, char **argv)
exit(12);
}
user_debug = cp;
(void) strtol(cp, &endcp, 10);
/* unusedint avoids gcc warning bug */
unusedint = strtol(cp, &endcp, 10);
cp = endcp;
if (*cp != '\0' && *cp != ' ') {
fprintf(stderr, "Bad syntax in"
@@ -721,8 +728,10 @@ main(int argc, char **argv)
printf("main: run_state = %s\n", run_state_name(run_state));
/*
* all done
* All done! - Jessica Noll, Age 2
*/
/* fix gcc warning bug */
unusedint++;
libcalc_call_me_last();
return (run_state == RUN_EXIT_WITH_ERROR ||
run_state == RUN_ZERO) ? 1 : 0;

1
calc.h
View File

@@ -65,7 +65,6 @@
#define SYMBOLSIZE 256 /* maximum symbol name size */
#define MAXLABELS 100 /* maximum number of user labels in function */
#define MAXSTRING 1024 /* maximum size of string constant */
#define MAXSTACK 2048 /* maximum depth of evaluation stack */
#define MAXFILES 20 /* maximum number of opened files */
#define PROMPT1 "> " /* default normal prompt*/

View File

@@ -348,7 +348,7 @@ EXT=
# The default calc versions
#
VERSION= 2.12.6.4
VERSION= 2.12.6.7
# Names of shared libraries with versions
#

View File

@@ -348,7 +348,7 @@ EXT=
# The default calc versions
#
VERSION= 2.12.6.4
VERSION= 2.12.6.7
# Names of shared libraries with versions
#

View File

@@ -173,8 +173,6 @@ STATIC struct infoname sys_info[] = {
(FULL)MAXSCANCOUNT},
{"MAXSTACK", "max depth of evaluation stack", NULL,
(FULL)MAXSTACK},
{"MAXSTRING", "max size of string constant", NULL,
(FULL)MAXSTRING},
{"MAXUFULL", "largest FULL value", NULL,
(FULL)MAXUFULL},
{"MAXULONG", "largest unsigned long val", NULL,

View File

@@ -54,13 +54,13 @@ DESCRIPTION
The elements of the matrix are stored internally as a linear array
in which locations are arranged in order of increasing indices.
For example, in order of location, the six element of A = mat [2,3]
are
are:
A[0,0], A[0,1], A[0,2], A[1,0], A[1,,1], 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]].
If p is assigned the value &A[0.0], the address of A[[i]] for 0 <= i < 6
If p is assigned the value &A[0,0], the address of A[[i]] for 0 <= i < 6
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
@@ -414,7 +414,7 @@ SEE ALSO
det, inverse, isident, test, config, search, rsearch, reverse, copy,
blkcpy, dp, cp, randperm, sort
## Copyright (C) 1999-2006 Landon Curt Noll
## Copyright (C) 1999-2006,2018 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -1,5 +1,5 @@
NAME
randbit - additive 55 shuffle pseudo-random number generator
randbit - subtractive 100 shuffle pseudo-random number generator
SYNOPSIS
randbit([x])
@@ -42,7 +42,7 @@ LINK LIBRARY
SEE ALSO
seed, srand, randbit, isrand, random, srandom, israndom
## Copyright (C) 1999 Landon Curt Noll
## Copyright (C) 1999,2018 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -18,14 +18,7 @@ DESCRIPTION
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. For such critical
applications, LavaRnd should be used. See the URL:
http://www.LavaRnd.org/
for information about seeding a pseudo-random number generator
(such as rand() or random()) with the cryptographic hash of the
digitization of chaotic system.
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
@@ -51,7 +44,7 @@ LINK LIBRARY
SEE ALSO
seed, srand, randbit, isrand, rand, random, srandom, israndom
## Copyright (C) 1999 Landon Curt Noll
## Copyright (C) 1999,2018 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -332,13 +332,13 @@ LIMITS
iq >= 2^16
LINK LIBRARY
RAND *zsrandom(ZVALUE *pseed, MATRIX *pmat55)
RAND *zsetrandom(RAND *state)
RANDOM *zsrandom(ZVALUE *pseed, MATRIX *pmat55)
RANDOM *zsetrandom(RAND *state)
SEE ALSO
seed, srand, randbit, isrand, random, srandom, israndom
## Copyright (C) 1999 Landon Curt Noll
## Copyright (C) 1999,2018 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -1,6 +1,6 @@
Builtin types
The calculator has the following built-in types.
The calculator has the following built-in types:
null value
This is the undefined value type. The function 'null'
@@ -101,7 +101,20 @@ Builtin types
using the result of the 'files' function. Such copies are
indistinguishable from each other.
## Copyright (C) 1999 Landon Curt Noll
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().
random
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
##
## 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

2
hist.h
View File

@@ -36,7 +36,7 @@
#endif
#ifndef HIST_SIZE
#define HIST_SIZE (1024*10)
#define HIST_SIZE (1024*32)
#endif

View File

@@ -59,8 +59,8 @@ E_FUNC FILE *f_open(char *name, char *mode);
E_FUNC FILE *curstream(void);
#define TTYSIZE 100 /* reallocation size for terminal buffers */
#define MAXDEPTH 10 /* maximum depth of input */
#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 */
@@ -789,7 +789,7 @@ ttychar(void)
{
int ch; /* current char */
int len; /* length of current command */
STATIC char charbuf[1024];
STATIC char charbuf[256*1024];
/*
* If we have more to read from the saved command line, then do that.

View File

@@ -254,7 +254,9 @@ E_FUNC NUMBER *swap_HALF_in_NUMBER(NUMBER *dest, NUMBER *src, BOOL all);
#define qhighbit(q) (zhighbit((q)->num))
#define qlowbit(q) (zlowbit((q)->num))
#define qdivcount(q1, q2) (zdivcount((q1)->num, (q2)->num))
#define qlink(q) ((q)->links++, (q))
/* operation on #q may be undefined, so replace with an inline-function */
/* 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);}

View File

@@ -2944,7 +2944,7 @@ printestr(VALUE *vp)
bp = vp->v_nblock->blk;
}
i = bp->datalen;
math_fmt("%ld,%d)", i, bp->blkchunk);
math_fmt("%ld,%d)", i, (int) bp->blkchunk);
cp = bp->data;
if (i > 0) {
math_str("={");

View File

@@ -45,7 +45,7 @@ static char *program;
#define MAJOR_VER 2 /* major library version */
#define MINOR_VER 12 /* minor library version */
#define MAJOR_PATCH 6 /* major software level under library version */
#define MINOR_PATCH 4 /* minor software level or 0 if not patched */
#define MINOR_PATCH 7 /* minor software level or 0 if not patched */
/*