mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Release calc version 2.12.1.6
This commit is contained in:
23
BUGS
23
BUGS
@@ -80,6 +80,25 @@ mis-features in calc:
|
||||
work better. The following is a list of mis-features that should be
|
||||
addressed and improved someday.
|
||||
|
||||
* 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:
|
||||
|
||||
if (expr) {
|
||||
...
|
||||
}
|
||||
|
||||
However this WILL NOT WORK AS EXPECTED:
|
||||
|
||||
if (expr)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
This needs to be changed. See also "help statement", "help unexpected",
|
||||
and "help todo".
|
||||
|
||||
* The chi.cal resource file does not work well with odd degrees
|
||||
of freedom. Can someone improve this algorithm?
|
||||
|
||||
@@ -141,8 +160,8 @@ Problems with old systems that have known work-a-rounds:
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.25 $
|
||||
## @(#) $Id: BUGS,v 29.25 2006/08/20 17:51:25 chongo Exp $
|
||||
## @(#) $Revision: 29.26 $
|
||||
## @(#) $Id: BUGS,v 29.26 2007/01/03 21:26:22 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/RCS/BUGS,v $
|
||||
##
|
||||
## Under source code control: 1994/03/18 14:06:13
|
||||
|
71
CHANGES
71
CHANGES
@@ -1,4 +1,69 @@
|
||||
The following are the changes from calc version 2.12.1 to date:
|
||||
The following are the changes from calc version 2.12.1.6 to date:
|
||||
|
||||
Added the calc builtin function, usertime(), to return the amount of
|
||||
user CPU time used by the current process. Unlike the old runtime()
|
||||
builtin, the CPU time reported for long running processes will not
|
||||
wrap around to 0 after only a few months.
|
||||
|
||||
Added the calc builtin function, systime(), to return the amount of
|
||||
kernel CPU time used by the current process.
|
||||
|
||||
The runtime() builtin function now returns the total amount of CPU
|
||||
time used by the current process. This time includes both user mode
|
||||
and kernel mode time. Unlike the old runtime() builtin, the builtin
|
||||
includes time spent executing operating system code on behalf of
|
||||
the current process.
|
||||
|
||||
Fixed runtime() so that the CPU time reported for long running
|
||||
processes will wrap around to 0 for a long time.
|
||||
|
||||
Added config("hz") to return the clock tick rate. This is
|
||||
a read-only configuration value.
|
||||
|
||||
Added regression tests for recently added config() parameters.
|
||||
|
||||
Fixed the #define symbols that were created in have_strdup.h.
|
||||
Previously this file looked as if have_rusage.h has been
|
||||
included already.
|
||||
|
||||
Restored the function of "help" (without any args) printing the
|
||||
default help file. Thanks for this fix goes to Silvan Minghetti
|
||||
<bullet at users dot sourceforge dot net>.
|
||||
|
||||
Fixed a problem where some old MS environments failed some of the
|
||||
regression tests because "read -once foo.cal" was not behaving
|
||||
correctly due to how the _fullpath() was being called. Thanks for
|
||||
this fix goes to Anatoly <notexistent-anb at yandex dot ru>.
|
||||
|
||||
Documented the mis-feature about how calc parses if, for, while
|
||||
and do statements in an unexpected way. For example:
|
||||
|
||||
This works as expected:
|
||||
|
||||
if (expr) {
|
||||
...
|
||||
}
|
||||
|
||||
However this WILL NOT WORK AS EXPECTED:
|
||||
|
||||
if (expr)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
because calc will parse the if being terminated by
|
||||
an empty statement followed by a
|
||||
|
||||
if (expr) ;
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
See also "help statement", "help unexpected", "help todo", and
|
||||
"help bugs".
|
||||
|
||||
|
||||
The following are the changes from calc version 2.12.1 to 2.12.1.5:
|
||||
|
||||
Fixed minor typos in the 'version 2.12.0 to 2.12.0.8' section below.
|
||||
Made minor formatting changes as well.
|
||||
@@ -6216,8 +6281,8 @@ Following is a list of visible changes to calc from version 1.24.7 to 1.26.1:
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.90 $
|
||||
## @(#) $Id: CHANGES,v 29.90 2006/09/18 13:14:03 chongo Exp $
|
||||
## @(#) $Revision: 29.91 $
|
||||
## @(#) $Id: CHANGES,v 29.91 2007/01/03 21:27:55 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/RCS/CHANGES,v $
|
||||
##
|
||||
## Under source code control: 1993/06/02 18:12:57
|
||||
|
12
Makefile
12
Makefile
@@ -32,8 +32,8 @@
|
||||
# received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
MAKEFILE_REV= $$Revision: 29.81 $$
|
||||
# @(#) $Id: Makefile.ship,v 29.81 2006/09/18 13:13:25 chongo Exp $
|
||||
MAKEFILE_REV= $$Revision: 29.83 $$
|
||||
# @(#) $Id: Makefile.ship,v 29.83 2007/01/03 21:29:50 chongo Exp $
|
||||
# @(#) $Source: /usr/local/src/cmd/calc/RCS/Makefile.ship,v $
|
||||
#
|
||||
# Under source code control: 1990/02/15 01:48:41
|
||||
@@ -2764,8 +2764,8 @@ have_strdup.h: have_strdup.c ${MAKE_FILE}
|
||||
${Q} echo ' */' >> have_strdup.h
|
||||
${Q} echo '' >> have_strdup.h
|
||||
${Q} echo '' >> have_strdup.h
|
||||
${Q} echo '#if !defined(__HAVE_RUSAGE_H__)' >> have_strdup.h
|
||||
${Q} echo '#define __HAVE_RUSAGE_H__' >> have_strdup.h
|
||||
${Q} echo '#if !defined(__HAVE_STRDUP_H__)' >> have_strdup.h
|
||||
${Q} echo '#define __HAVE_STRDUP_H__' >> have_strdup.h
|
||||
${Q} echo '' >> have_strdup.h
|
||||
${Q} echo '' >> have_strdup.h
|
||||
${Q} echo '/* do we have or want getstrdup()? */' >> have_strdup.h
|
||||
@@ -2783,7 +2783,7 @@ have_strdup.h: have_strdup.c ${MAKE_FILE}
|
||||
fi
|
||||
${Q} echo '' >> have_strdup.h
|
||||
${Q} echo '' >> have_strdup.h
|
||||
${Q} echo '#endif /* !__HAVE_RUSAGE_H__ */' >> have_strdup.h
|
||||
${Q} echo '#endif /* !__HAVE_STRDUP_H__ */' >> have_strdup.h
|
||||
-${Q} ${RM} -f have_strdup${EXT} have_strdup.o strdup_tmp
|
||||
${Q} echo 'have_strdup.h formed'
|
||||
-@if [ -z "${Q}" ]; then \
|
||||
@@ -4160,6 +4160,7 @@ config.o: have_newstr.h
|
||||
config.o: have_stdlib.h
|
||||
config.o: have_strdup.h
|
||||
config.o: have_string.h
|
||||
config.o: have_times.h
|
||||
config.o: longbits.h
|
||||
config.o: md5.h
|
||||
config.o: nametype.h
|
||||
@@ -4283,6 +4284,7 @@ func.o: have_fpos.h
|
||||
func.o: have_malloc.h
|
||||
func.o: have_memmv.h
|
||||
func.o: have_newstr.h
|
||||
func.o: have_rusage.h
|
||||
func.o: have_stdlib.h
|
||||
func.o: have_strdup.h
|
||||
func.o: have_string.h
|
||||
|
@@ -714,7 +714,7 @@ sumtimes.cal
|
||||
timehmean(N,M)
|
||||
doalltimes(N)
|
||||
|
||||
Give the runtimes for various ways of evaluating sums, sums of
|
||||
Give the user CPU time for various ways of evaluating sums, sums of
|
||||
squares, etc, for large lists and matrices. N is the size of
|
||||
the list or matrix to use. The doalltimes() function will run
|
||||
all fo the sumtimes tests. For example:
|
||||
@@ -1014,8 +1014,8 @@ xx_print.cal
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.15 $
|
||||
## @(#) $Id: README,v 29.15 2006/06/23 00:34:55 chongo Exp $
|
||||
## @(#) $Revision: 29.16 $
|
||||
## @(#) $Id: README,v 29.16 2006/12/16 11:18:46 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/README,v $
|
||||
##
|
||||
## Under source code control: 1990/02/15 01:50:32
|
||||
|
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.14 $
|
||||
* @(#) $Id: alg_config.cal,v 29.14 2006/06/11 07:22:05 chongo Exp $
|
||||
* @(#) $Revision: 29.15 $
|
||||
* @(#) $Id: alg_config.cal,v 29.15 2006/12/16 11:18:46 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/alg_config.cal,v $
|
||||
*
|
||||
* Under source code control: 2006/06/07 14:10:11
|
||||
@@ -85,7 +85,7 @@ define mul_loop(repeat, x)
|
||||
}
|
||||
|
||||
/* multiply pairwise, all sets of a given length */
|
||||
start = runtime();
|
||||
start = usertime();
|
||||
for (i=0; i < repeat; ++i) {
|
||||
|
||||
if (len == 1) {
|
||||
@@ -130,7 +130,7 @@ define mul_loop(repeat, x)
|
||||
/*
|
||||
* return duration
|
||||
*/
|
||||
end = runtime();
|
||||
end = usertime();
|
||||
return end-start;
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ define sq_loop(repeat, x)
|
||||
}
|
||||
|
||||
/* square pairwise, all sets of a given length */
|
||||
start = runtime();
|
||||
start = usertime();
|
||||
for (i=0; i < repeat; ++i) {
|
||||
|
||||
if (len == 1) {
|
||||
@@ -524,7 +524,7 @@ define sq_loop(repeat, x)
|
||||
/*
|
||||
* return duration
|
||||
*/
|
||||
end = runtime();
|
||||
end = usertime();
|
||||
return end-start;
|
||||
}
|
||||
|
||||
@@ -874,7 +874,7 @@ define pow_loop(repeat, x, ex)
|
||||
}
|
||||
|
||||
/* pmod pairwise, all sets of a given length */
|
||||
start = runtime();
|
||||
start = usertime();
|
||||
for (i=0; i < repeat; ++i) {
|
||||
|
||||
if (len == 1) {
|
||||
@@ -927,7 +927,7 @@ define pow_loop(repeat, x, ex)
|
||||
/*
|
||||
* return duration
|
||||
*/
|
||||
end = runtime();
|
||||
end = usertime();
|
||||
return end-start;
|
||||
}
|
||||
|
||||
|
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.2 $
|
||||
* @(#) $Id: mfactor.cal,v 29.2 2000/06/07 14:02:25 chongo Exp $
|
||||
* @(#) $Revision: 29.3 $
|
||||
* @(#) $Id: mfactor.cal,v 29.3 2006/12/16 11:18:46 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/mfactor.cal,v $
|
||||
*
|
||||
* Under source code control: 1996/07/06 06:09:40
|
||||
@@ -261,7 +261,7 @@ define mfactor(n, start_k, rept_loop, p_elim)
|
||||
} else {
|
||||
/* report this loop */
|
||||
printf("at 2*%d*%d+1, cpu: %f\n",
|
||||
(q-1)/(2*n), n, runtime());
|
||||
(q-1)/(2*n), n, usertime());
|
||||
fflush(files(1));
|
||||
loop = 0;
|
||||
}
|
||||
@@ -274,7 +274,7 @@ define mfactor(n, start_k, rept_loop, p_elim)
|
||||
if (rept_loop <= ++loop) {
|
||||
/* report this loop */
|
||||
printf("at 2*%d*%d+1, cpu: %f\n",
|
||||
(q-1)/(2*n), n, runtime());
|
||||
(q-1)/(2*n), n, usertime());
|
||||
fflush(files(1));
|
||||
loop = 0;
|
||||
}
|
||||
|
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.2 $
|
||||
* @(#) $Id: randmprime.cal,v 29.2 2000/06/07 14:02:25 chongo Exp $
|
||||
* @(#) $Revision: 29.3 $
|
||||
* @(#) $Id: randmprime.cal,v 29.3 2006/12/16 11:18:46 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/randmprime.cal,v $
|
||||
*
|
||||
* Under source code control: 1994/03/14 23:11:21
|
||||
@@ -88,8 +88,8 @@ randmprime(bits, seed, dbg)
|
||||
* loop until we find a prime
|
||||
*/
|
||||
if (dbg >= 1) {
|
||||
start = runtime();
|
||||
init = runtime();
|
||||
start = usertime();
|
||||
init = usertime();
|
||||
plush = 0;
|
||||
print "DEBUG1: testing (h+" : plush : ")*2^" : n : "-1";
|
||||
}
|
||||
@@ -97,7 +97,7 @@ randmprime(bits, seed, dbg)
|
||||
|
||||
/* bump h, and n if needed */
|
||||
if (dbg >= 2) {
|
||||
stop = runtime();
|
||||
stop = usertime();
|
||||
print "DEBUG2: last test:", stop-start, " total time:", stop-init;
|
||||
}
|
||||
if (dbg >= 1) {
|
||||
@@ -116,7 +116,7 @@ randmprime(bits, seed, dbg)
|
||||
|
||||
/* found a prime */
|
||||
if (dbg >= 2) {
|
||||
stop = runtime();
|
||||
stop = usertime();
|
||||
print "DEBUG2: last test:", stop-start, " total time:", stop-init;
|
||||
print "DEBUG3: " : h : "*2^" : n : "-1 is prime";
|
||||
}
|
||||
|
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.35 $
|
||||
* @(#) $Id: regress.cal,v 29.35 2006/08/20 16:16:11 chongo Exp $
|
||||
* @(#) $Revision: 29.36 $
|
||||
* @(#) $Id: regress.cal,v 29.36 2006/12/16 11:18:46 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/regress.cal,v $
|
||||
*
|
||||
* Under source code control: 1990/02/15 01:50:36
|
||||
@@ -497,7 +497,33 @@ define test_config()
|
||||
vrfy(config("mode2") == "off",
|
||||
'556: config("mode2") == "off"');
|
||||
|
||||
print '557: Ending test_config';
|
||||
/* 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"))');
|
||||
|
||||
/* 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"))');
|
||||
|
||||
/* 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"))');
|
||||
|
||||
print '563: Ending test_config';
|
||||
}
|
||||
print '010: parsed test_config()';
|
||||
|
||||
@@ -1375,7 +1401,12 @@ define test_functions()
|
||||
vrfy(a == -4, '1203: a == -4');
|
||||
vrfy(b == 2, '1204: b == 2');
|
||||
|
||||
print '1205: Ending test_functions';
|
||||
/* runtime(), systime(), usertime() return numeric values */
|
||||
vrfy(isnum(runtime()), '1205: isnum(runtime())');
|
||||
vrfy(isnum(systime()), '1206: isnum(systime())');
|
||||
vrfy(isnum(usertime()), '1207: isnum(usertime())');
|
||||
|
||||
print '1208: Ending test_functions';
|
||||
}
|
||||
print '017: parsed test_functions()';
|
||||
|
||||
|
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.1 $
|
||||
* @(#) $Id: sumtimes.cal,v 29.1 2006/06/23 00:35:30 chongo Exp $
|
||||
* @(#) $Revision: 29.2 $
|
||||
* @(#) $Id: sumtimes.cal,v 29.2 2006/12/16 11:18:46 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/sumtimes.cal,v $
|
||||
*
|
||||
* Under source code control: 2006/06/22 17:29
|
||||
@@ -40,13 +40,13 @@ define timematsum(N) {
|
||||
for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);
|
||||
|
||||
ptop = &sumtimes_A[n-1];
|
||||
sumtimes_t0 = runtime();
|
||||
sumtimes_t0 = usertime();
|
||||
for (s = n = 0; n < N; n++) s += sumtimes_A[n];
|
||||
sumtimes_t1 = runtime();
|
||||
sumtimes_t1 = usertime();
|
||||
for (s = 0, p = &sumtimes_A[0]; p <= ptop; p++) s += *p;
|
||||
sumtimes_t2 = runtime();
|
||||
sumtimes_t2 = usertime();
|
||||
s = matsum(sumtimes_A);
|
||||
sumtimes_t3 = runtime();
|
||||
sumtimes_t3 = usertime();
|
||||
|
||||
print "Matrix sum runtimes";
|
||||
printf('\tStandard "for" loop:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
|
||||
@@ -60,11 +60,11 @@ define timelistsum(N) {
|
||||
sumtimes_A = makelist(N);
|
||||
for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);
|
||||
|
||||
sumtimes_t0 = runtime();
|
||||
sumtimes_t0 = usertime();
|
||||
for (s = n = 0; n < N; n++) s += sumtimes_A[n];
|
||||
sumtimes_t1 = runtime();
|
||||
sumtimes_t1 = usertime();
|
||||
s = sum(sumtimes_A);
|
||||
sumtimes_t2 = runtime();
|
||||
sumtimes_t2 = usertime();
|
||||
print "List sum runtimes";
|
||||
printf('\tStandard "for" loop:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
|
||||
printf('\tUsing builtin "sum":\t\t%.4f\n', sumtimes_t2 - sumtimes_t1);
|
||||
@@ -76,9 +76,9 @@ define timematsort(N) {
|
||||
|
||||
sumtimes_A = mat[N];
|
||||
for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);
|
||||
sumtimes_t0 = runtime();
|
||||
sumtimes_t0 = usertime();
|
||||
sort(sumtimes_A);
|
||||
sumtimes_t1 = runtime();
|
||||
sumtimes_t1 = usertime();
|
||||
printf('\tMatrix sort runtime:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
|
||||
}
|
||||
|
||||
@@ -88,9 +88,9 @@ define timelistsort(N) {
|
||||
|
||||
sumtimes_A = makelist(N);
|
||||
for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);
|
||||
sumtimes_t0 = runtime();
|
||||
sumtimes_t0 = usertime();
|
||||
sort(sumtimes_A);
|
||||
sumtimes_t1 = runtime();
|
||||
sumtimes_t1 = usertime();
|
||||
printf('\tList sort runtime:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
|
||||
}
|
||||
|
||||
@@ -99,9 +99,9 @@ define timematreverse(N) {
|
||||
|
||||
sumtimes_A = mat[N];
|
||||
for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);
|
||||
sumtimes_t0 = runtime();
|
||||
sumtimes_t0 = usertime();
|
||||
reverse(sumtimes_A);
|
||||
sumtimes_t1 = runtime();
|
||||
sumtimes_t1 = usertime();
|
||||
printf('\tMatrix reverse runtime %.4f\n', sumtimes_t1 - sumtimes_t0);
|
||||
}
|
||||
|
||||
@@ -110,9 +110,9 @@ define timelistreverse(N) {
|
||||
|
||||
sumtimes_A = makelist(N);
|
||||
for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);
|
||||
sumtimes_t0 = runtime();
|
||||
sumtimes_t0 = usertime();
|
||||
reverse(sumtimes_A);
|
||||
sumtimes_t1 = runtime();
|
||||
sumtimes_t1 = usertime();
|
||||
printf('\tList reverse runtime:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
|
||||
}
|
||||
|
||||
@@ -124,11 +124,11 @@ define timematssq(N) {
|
||||
for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);
|
||||
|
||||
ptop = &sumtimes_A[n-1];
|
||||
sumtimes_t0 = runtime();
|
||||
sumtimes_t0 = usertime();
|
||||
for (s = n = 0; n < N; n++) s += sumtimes_A[n]^2;
|
||||
sumtimes_t1 = runtime();
|
||||
sumtimes_t1 = usertime();
|
||||
for (s = 0, p = &sumtimes_A[0]; p <= ptop; p++) s += (*p)^2;
|
||||
sumtimes_t2 = runtime();
|
||||
sumtimes_t2 = usertime();
|
||||
|
||||
print "Matrix sum of squares runtimes";
|
||||
printf('\tStandard "for" loop:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
|
||||
@@ -141,11 +141,11 @@ define timelistssq(N) {
|
||||
sumtimes_A = makelist(N);
|
||||
for (n = 0; n < N; n++) sumtimes_A[n] = rand(N);
|
||||
|
||||
sumtimes_t0 = runtime();
|
||||
sumtimes_t0 = usertime();
|
||||
for (s = n = 0; n < N; n++) s += sumtimes_A[n]^2;
|
||||
sumtimes_t1 = runtime();
|
||||
sumtimes_t1 = usertime();
|
||||
s = ssq(sumtimes_A);
|
||||
sumtimes_t2 = runtime();
|
||||
sumtimes_t2 = usertime();
|
||||
print "List sum of squares runtimes";
|
||||
printf('\tStandard "for" loop:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
|
||||
printf('\tUsing builtin "ssq":\t\t%.4f\n', sumtimes_t2 - sumtimes_t1);
|
||||
@@ -157,12 +157,12 @@ define timehmean(N, M = 10) {
|
||||
sumtimes_A = makelist(N);
|
||||
for (n = 0; n < N; n++) sumtimes_A[n] = rand(1, M);
|
||||
|
||||
sumtimes_t0 = runtime();
|
||||
sumtimes_t0 = usertime();
|
||||
for (s = n = 0; n < N; n++) s += 1/sumtimes_A[n];
|
||||
v1 = N/s;
|
||||
sumtimes_t1 = runtime();
|
||||
sumtimes_t1 = usertime();
|
||||
v2 = hmean(sumtimes_A);
|
||||
sumtimes_t2 = runtime();
|
||||
sumtimes_t2 = usertime();
|
||||
print v1, v2;
|
||||
print "List harmonic meanruntimes";
|
||||
printf('\tStandard "for" loop:\t\t%.4f\n', sumtimes_t1 - sumtimes_t0);
|
||||
|
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.3 $
|
||||
* @(#) $Id: test3300.cal,v 29.3 2006/06/20 09:29:16 chongo Exp $
|
||||
* @(#) $Revision: 29.5 $
|
||||
* @(#) $Id: test3300.cal,v 29.5 2006/12/16 11:19:45 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/test3300.cal,v $
|
||||
*
|
||||
* Under source code control: 1995/12/02 04:27:41
|
||||
@@ -81,9 +81,9 @@ define testr(str, n, N, verbose)
|
||||
for (i = 0; i < n; i++)
|
||||
for (j = 0; j < n; j++)
|
||||
A[i,j] = rand(-(N^2), N^2)/rand(1, N);
|
||||
t = runtime();
|
||||
t = usertime();
|
||||
d1 = det(A);
|
||||
t = runtime() - t;
|
||||
t = usertime() - t;
|
||||
d2 = det(A^2);
|
||||
if (d2 != d1^2) {
|
||||
if (verbose > 0) {
|
||||
|
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.3 $
|
||||
* @(#) $Id: test4000.cal,v 29.3 2006/06/20 09:29:16 chongo Exp $
|
||||
* @(#) $Revision: 29.4 $
|
||||
* @(#) $Id: test4000.cal,v 29.4 2006/12/16 11:18:46 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/test4000.cal,v $
|
||||
*
|
||||
* Under source code control: 1996/03/13 02:38:45
|
||||
@@ -145,7 +145,7 @@ define ptimes(str, N, n, count, skip, verbose)
|
||||
mat A[n];
|
||||
for (i = 0; i < n; i++)
|
||||
A[i] = plen(N);
|
||||
t = runtime();
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++) {
|
||||
p = ptest(A[i], count, skip);
|
||||
if (!p) {
|
||||
@@ -159,7 +159,7 @@ define ptimes(str, N, n, count, skip, verbose)
|
||||
if (m) {
|
||||
printf("*** %d error(s)\n", m);
|
||||
} else {
|
||||
t = round(runtime() - t, 4);
|
||||
t = round(usertime() - t, 4);
|
||||
if (verbose > 1) {
|
||||
printf("%d probable primes: time = %d\n", n, t);
|
||||
} else {
|
||||
@@ -194,7 +194,7 @@ define ctimes(str, N, n, count, skip, verbose)
|
||||
mat A[n];
|
||||
for (i = 0; i < n; i++)
|
||||
A[i] = clen(N);
|
||||
t = runtime();
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++) {
|
||||
p = ptest(A[i], count, skip);
|
||||
if (p) {
|
||||
@@ -208,7 +208,7 @@ define ctimes(str, N, n, count, skip, verbose)
|
||||
if (m) {
|
||||
printf("*** %d error(s)\n", m);
|
||||
} else {
|
||||
t = round(runtime() - t, 4);
|
||||
t = round(usertime() - t, 4);
|
||||
if (verbose > 1) {
|
||||
printf("%d probable primes: time = %d\n", n, t);
|
||||
} else {
|
||||
@@ -242,7 +242,7 @@ define crtimes(str, a, b, n, count, skip, verbose)
|
||||
A[i] = rand(a,b);
|
||||
P[i] = ptest(A[i], 20, 0);
|
||||
}
|
||||
t = runtime();
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++) {
|
||||
p = ptest(A[i], count, skip);
|
||||
if (p != P[i]) {
|
||||
@@ -257,7 +257,7 @@ define crtimes(str, a, b, n, count, skip, verbose)
|
||||
if (m) {
|
||||
printf("*** %d error(s)?\n", m);
|
||||
} else {
|
||||
t = round(runtime() - t, 4);
|
||||
t = round(usertime() - t, 4);
|
||||
if (verbose > 1) {
|
||||
printf("%d probable primes: time = %d\n", n, t);
|
||||
} else {
|
||||
@@ -295,16 +295,16 @@ define ntimes(str, N, n, count, skip, residue, modulus, verbose)
|
||||
mat A[n];
|
||||
for (i = 0; i < n; i++)
|
||||
A[i] = rlen(N);
|
||||
t = runtime();
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++) {
|
||||
p = nextcand(A[i], count, skip, residue, modulus);
|
||||
}
|
||||
tnext = round(runtime() - t, 4);
|
||||
t = runtime();
|
||||
tnext = round(usertime() - t, 4);
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++) {
|
||||
p = prevcand(A[i], count, skip, residue, modulus);
|
||||
}
|
||||
tprev = round(runtime() - t, 4);
|
||||
tprev = round(usertime() - t, 4);
|
||||
if (verbose > 0) {
|
||||
printf("%d evaluations, nextcand: %d, prevcand: %d\n", n, tnext, tprev);
|
||||
}
|
||||
|
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.4 $
|
||||
* @(#) $Id: test4100.cal,v 29.4 2006/06/20 09:29:16 chongo Exp $
|
||||
* @(#) $Revision: 29.5 $
|
||||
* @(#) $Id: test4100.cal,v 29.5 2006/12/16 11:18:46 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/test4100.cal,v $
|
||||
*
|
||||
* Under source code control: 1996/03/13 03:53:22
|
||||
@@ -245,38 +245,38 @@ define times(str,N,n,verbose)
|
||||
C[i] = rand(m2);
|
||||
}
|
||||
z = rcin(0,m); /* to initialize redc and maybe lastmod information */
|
||||
t = runtime();
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++)
|
||||
z = rcin(A[i],m);
|
||||
trcin = round(runtime() - t, 3);
|
||||
t = runtime();
|
||||
trcin = round(usertime() - t, 3);
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++)
|
||||
z = rcout(A[i],m);
|
||||
trcout = round(runtime() - t, 3);
|
||||
t = runtime();
|
||||
trcout = round(usertime() - t, 3);
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++)
|
||||
z = rcmul(A[i],B[i],m);
|
||||
trcmul = round(runtime() - t, 3);
|
||||
t = runtime();
|
||||
trcmul = round(usertime() - t, 3);
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++)
|
||||
z = rcsq(A[i],m);
|
||||
trcsq = round(runtime() - t, 3);
|
||||
t = runtime();
|
||||
trcsq = round(usertime() - t, 3);
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++)
|
||||
z = A[i] * B[i];
|
||||
tmul = round(runtime() - t, 3);
|
||||
t = runtime();
|
||||
tmul = round(usertime() - t, 3);
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++)
|
||||
z = A[i]^2;
|
||||
tsq = round(runtime() - t, 3);
|
||||
t = runtime();
|
||||
tsq = round(usertime() - t, 3);
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++)
|
||||
z = C[i] % A[i];
|
||||
tmod = round(runtime() - t, 3);
|
||||
t = runtime();
|
||||
tmod = round(usertime() - t, 3);
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++)
|
||||
quomod(C[i], A[i], x, y);
|
||||
tquomod = round(runtime() - t,3);
|
||||
tquomod = round(usertime() - t,3);
|
||||
|
||||
if (verbose > 1) {
|
||||
printf("rcin: %d, rcout: %d, rcmul: %d, rcsq: %d\n",
|
||||
@@ -326,29 +326,29 @@ define powtimes(str, N1, N2, n, verbose)
|
||||
Ar[i] = rcin(A[i], v);
|
||||
B[i] = rlen_4100(N2);
|
||||
}
|
||||
t = runtime();
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++)
|
||||
z1 += pmod(A[i], B[i], v);
|
||||
tbignum = round(runtime() - t, 4);
|
||||
tbignum = round(usertime() - t, 4);
|
||||
config("pow2", 1e6);
|
||||
t = runtime();
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++)
|
||||
z2 += pmod(A[i], B[i], v);
|
||||
tnormal = round(runtime() - t, 4);
|
||||
tnormal = round(usertime() - t, 4);
|
||||
config("redc2",1e6);
|
||||
t = runtime();
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++)
|
||||
z3 += pmod(A[i], B[i], v);
|
||||
tsmall = round(runtime() - t, 4);
|
||||
t = runtime();
|
||||
tsmall = round(usertime() - t, 4);
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++)
|
||||
z4 += rcpow(Ar[i], B[i], v);
|
||||
trcsmall = round(runtime() - t, 4);
|
||||
trcsmall = round(usertime() - t, 4);
|
||||
config("redc2", 2);
|
||||
t = runtime();
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++)
|
||||
z5 += rcpow(Ar[i], B[i], v);
|
||||
trcbig = round(runtime() - t, 4);
|
||||
trcbig = round(usertime() - t, 4);
|
||||
|
||||
if (z1 != z2) {
|
||||
++m;
|
||||
@@ -419,13 +419,13 @@ define inittimes(str,N,n,verbose)
|
||||
M[i] = olen(N);
|
||||
A[i] = rand(M[i]);
|
||||
}
|
||||
t = runtime();
|
||||
t = usertime();
|
||||
for (i = 0; i < n; i++)
|
||||
R[i] = rcin(A[i], M[i]);
|
||||
trcin = round(runtime() - t, 4);
|
||||
trcin = round(usertime() - t, 4);
|
||||
for (i = 0; i < n; i++)
|
||||
B[i] = rcout(R[i], M[i]);
|
||||
trcout = round(runtime() - t, 4);
|
||||
trcout = round(usertime() - t, 4);
|
||||
for (i = 0; i < n; i++) {
|
||||
if (B[i] != A[i]) {
|
||||
++m;
|
||||
|
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.21 $
|
||||
* @(#) $Id: codegen.c,v 29.21 2006/06/20 10:28:06 chongo Exp $
|
||||
* @(#) $Revision: 29.22 $
|
||||
* @(#) $Id: codegen.c,v 29.22 2006/12/15 16:25:09 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/codegen.c,v $
|
||||
*
|
||||
* Under source code control: 1990/02/15 01:48:13
|
||||
@@ -144,6 +144,7 @@ getcommands(BOOL toplevel)
|
||||
case T_HELP:
|
||||
for (i=1;;i++) {
|
||||
switch(getfilename(name, MAXCMD+1, NULL)) {
|
||||
case 1:
|
||||
case -1:
|
||||
if(i == 1) {
|
||||
strcpy(name, DEFAULTCALCHELP);
|
||||
|
40
config.c
40
config.c
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.22 $
|
||||
* @(#) $Id: config.c,v 29.22 2006/06/25 22:05:38 chongo Exp $
|
||||
* @(#) $Revision: 29.23 $
|
||||
* @(#) $Id: config.c,v 29.23 2006/12/15 16:17:18 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/config.c,v $
|
||||
*
|
||||
* Under source code control: 1991/07/20 00:21:56
|
||||
@@ -31,6 +31,24 @@
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "have_times.h"
|
||||
#if defined(HAVE_TIME_H)
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_TIMES_H)
|
||||
#include <times.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_TIME_H)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_TIMES_H)
|
||||
#include <sys/times.h>
|
||||
#endif
|
||||
|
||||
#include "calc.h"
|
||||
#include "token.h"
|
||||
#include "zrand.h"
|
||||
@@ -45,6 +63,15 @@
|
||||
# define strdup(x) calc_strdup((CONST char *)(x))
|
||||
#endif /* HAVE_STRDUP */
|
||||
|
||||
/*
|
||||
* deal with systems that lack a defined CLK_TCK
|
||||
*/
|
||||
#if defined(CLK_TCK)
|
||||
# define CALC_HZ ((long)(CLK_TCK))
|
||||
#else
|
||||
# define CALC_HZ (0L) /* no defined clock tick rate */
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Table of configuration types that can be set or read.
|
||||
@@ -100,6 +127,7 @@ NAMETYPE configs[] = {
|
||||
{"baseb", CONFIG_BASEB},
|
||||
{"redecl_warn", CONFIG_REDECL_WARN},
|
||||
{"dupvar_warn", CONFIG_DUPVAR_WARN},
|
||||
{"hz", CONFIG_HZ},
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
@@ -941,6 +969,10 @@ setconfig(int type, VALUE *vp)
|
||||
}
|
||||
break;
|
||||
|
||||
case CONFIG_HZ:
|
||||
math_error("The clock tick rate config parameter is read-only");
|
||||
/*NOTREACHED*/
|
||||
|
||||
default:
|
||||
math_error("Setting illegal config parameter");
|
||||
/*NOTREACHED*/
|
||||
@@ -1330,6 +1362,10 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
|
||||
i = (cfg->dupvar_warn ? 1 : 0);
|
||||
break;
|
||||
|
||||
case CONFIG_HZ:
|
||||
i = CALC_HZ;
|
||||
break;
|
||||
|
||||
default:
|
||||
math_error("Getting illegal CONFIG element");
|
||||
/*NOTREACHED*/
|
||||
|
5
config.h
5
config.h
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.20 $
|
||||
* @(#) $Id: config.h,v 29.20 2006/06/25 22:05:38 chongo Exp $
|
||||
* @(#) $Revision: 29.21 $
|
||||
* @(#) $Id: config.h,v 29.21 2006/12/15 16:16:59 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/config.h,v $
|
||||
*
|
||||
* Under source code control: 1995/11/01 22:20:17
|
||||
@@ -97,6 +97,7 @@
|
||||
#define CONFIG_BASEB 43
|
||||
#define CONFIG_REDECL_WARN 44
|
||||
#define CONFIG_DUPVAR_WARN 45
|
||||
#define CONFIG_HZ 46
|
||||
|
||||
|
||||
/*
|
||||
|
156
func.c
156
func.c
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.30 $
|
||||
* @(#) $Id: func.c,v 29.30 2006/08/20 15:01:30 chongo Exp $
|
||||
* @(#) $Revision: 29.32 $
|
||||
* @(#) $Id: func.c,v 29.32 2006/12/16 10:46:07 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/func.c,v $
|
||||
*
|
||||
* Under source code control: 1990/02/15 01:48:15
|
||||
@@ -83,6 +83,11 @@
|
||||
# define strdup(x) calc_strdup((CONST char *)(x))
|
||||
#endif
|
||||
|
||||
#include "have_rusage.h"
|
||||
#if defined(HAVE_GETRUSAGE)
|
||||
# include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
#include "have_const.h"
|
||||
#include "have_unused.h"
|
||||
#include "calc.h"
|
||||
@@ -142,18 +147,6 @@ static int env_pool_max = 0; /* number of env_pool elements allocated */
|
||||
static struct env_pool *e_pool = NULL; /* env_pool elements */
|
||||
|
||||
|
||||
/*
|
||||
* if HZ & CLK_TCK are not defined, pick typical values, hope for the best
|
||||
*/
|
||||
#if !defined(HZ)
|
||||
# define HZ 60
|
||||
#endif
|
||||
#if !defined(CLK_TCK)
|
||||
# undef CLK_TCK
|
||||
# define CLK_TCK HZ
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* user-defined error strings
|
||||
*/
|
||||
@@ -5067,20 +5060,131 @@ f_listremove(VALUE *vp)
|
||||
|
||||
|
||||
/*
|
||||
* Return the current runtime of calc in seconds.
|
||||
* This is the user mode time only.
|
||||
* Return the current user time of calc in seconds.
|
||||
*/
|
||||
static 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 sconds of CPU time to return */
|
||||
NUMBER *usecret; /* microseconds of CPU time to return */
|
||||
|
||||
/* get the resource informaion 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);
|
||||
|
||||
/* return user CPU time */
|
||||
return ret;
|
||||
|
||||
#else /* HAVE_GETRUSAGE */
|
||||
/* not a POSIX system */
|
||||
return qlink(&_qzero_);
|
||||
#endif /* HAVE_GETRUSAGE */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return the current kernel time of calc in seconds.
|
||||
* This is the kernel mode time only.
|
||||
*/
|
||||
static 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 sconds of CPU time to return */
|
||||
NUMBER *usecret; /* microseconds of CPU time to return */
|
||||
|
||||
/* get the resource informaion 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);
|
||||
|
||||
/* return kernel CPU time */
|
||||
return ret;
|
||||
|
||||
#else /* HAVE_GETRUSAGE */
|
||||
/* not a POSIX system */
|
||||
return qlink(&_qzero_);
|
||||
#endif /* HAVE_GETRUSAGE */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return the current user and kernel time of calc in seconds.
|
||||
*/
|
||||
static NUMBER *
|
||||
f_runtime(void)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return qlink(&_qzero_);
|
||||
#else /* Windoz free systems */
|
||||
struct tms buf;
|
||||
#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 sconds of CPU time to return */
|
||||
NUMBER *usecret; /* microseconds of CPU time to return */
|
||||
|
||||
times(&buf);
|
||||
return iitoq((long) buf.tms_utime, (long) CLK_TCK);
|
||||
#endif /* Windoz free systems */
|
||||
/* get the resource informaion 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 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);
|
||||
|
||||
/* return CPU time */
|
||||
return ret;
|
||||
|
||||
#else /* HAVE_GETRUSAGE */
|
||||
/* not a POSIX system */
|
||||
return qlink(&_qzero_);
|
||||
#endif /* HAVE_GETRUSAGE */
|
||||
}
|
||||
|
||||
|
||||
@@ -8558,7 +8662,7 @@ static CONST struct builtin builtins[] = {
|
||||
{"rsearch", 2, 4, 0, OP_NOP, 0, f_rsearch,
|
||||
"reverse search matrix or list for value b\n\t\t\tstarting at index c"},
|
||||
{"runtime", 0, 0, 0, OP_NOP, f_runtime, 0,
|
||||
"user mode cpu time in seconds"},
|
||||
"user and kernel mode cpu time in seconds"},
|
||||
{"saveval", 1, 1, 0, OP_SAVEVAL, 0, 0,
|
||||
"set flag for saving values"},
|
||||
{"scale", 2, 2, 0, OP_SCALE, 0, 0,
|
||||
@@ -8641,6 +8745,8 @@ static CONST struct builtin builtins[] = {
|
||||
"swap values of variables a and b (can be dangerous)"},
|
||||
{"system", 1, 1, 0, OP_NOP, 0, f_system,
|
||||
"call Unix command"},
|
||||
{"systime", 0, 0, 0, OP_NOP, f_systime, 0,
|
||||
"kernel mode cpu time in seconds"},
|
||||
{"tail", 2, 2, 0, OP_NOP, 0, f_tail,
|
||||
"retain list of specified number at tail of list"},
|
||||
{"tan", 1, 2, 0, OP_NOP, 0, f_tan,
|
||||
@@ -8655,6 +8761,8 @@ static CONST struct builtin builtins[] = {
|
||||
"truncate a to b number of decimal places"},
|
||||
{"ungetc", 2, 2, 0, OP_NOP, 0, f_ungetc,
|
||||
"unget char read from file"},
|
||||
{"usertime", 0, 0, 0, OP_NOP, f_usertime, 0,
|
||||
"user mode cpu time in seconds"},
|
||||
{"version", 0, 0, 0, OP_NOP, 0, f_version,
|
||||
"calc version string"},
|
||||
{"xor", 1, IN, 0, OP_NOP, 0, f_xor,
|
||||
|
@@ -18,8 +18,8 @@
|
||||
# received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# @(#) $Revision: 29.34 $
|
||||
# @(#) $Id: Makefile,v 29.34 2006/09/18 13:13:25 chongo Exp $
|
||||
# @(#) $Revision: 29.35 $
|
||||
# @(#) $Id: Makefile,v 29.35 2006/12/16 10:32:54 chongo Exp $
|
||||
# @(#) $Source: /usr/local/src/cmd/calc/help/RCS/Makefile,v $
|
||||
#
|
||||
# Under source code control: 1991/07/23 06:47:57
|
||||
@@ -277,7 +277,7 @@ DETAIL_HELP= abs access acos acosh acot acoth acsc acsch address agd append \
|
||||
appr arg argv arrow asec asech asin asinh assign atan atan2 atanh \
|
||||
avg base base2 bernoulli bit blk blkcpy blkfree blocks bround \
|
||||
btrunc calc_tty calclevel catalan ceil cfappr cfsim char cmdbuf \
|
||||
cmp comb conj cos cosh cot coth count ${CP} csc csch ctime delete den \
|
||||
cmp comb conj cos cosh cot coth count csc csch ctime delete den \
|
||||
dereference det digit digits display dp epsilon errcount errmax \
|
||||
errno error estr euler eval exp fact factor fclose fcnt feof ferror \
|
||||
fflush fgetc fgetfield fgetfile fgetline fgets fgetstr fib files \
|
||||
@@ -295,12 +295,12 @@ DETAIL_HELP= abs access acos acosh acot acoth acsc acsch address agd append \
|
||||
param perm pfact pi pix places pmod polar poly pop popcnt power \
|
||||
prevcand prevprime printf prompt protect ptest push putenv quo \
|
||||
quomod rand randbit random randombit randperm rcin rcmul rcout \
|
||||
rcpow rcsq re remove reverse rewind ${RM} root round rsearch runtime \
|
||||
rcpow rcsq re remove reverse rewind rm root round rsearch runtime \
|
||||
saveval scale scan scanf search sec sech seed segment select sgn \
|
||||
sha sha1 sin sinh size sizeof sleep sort sqrt srand srandom ssq \
|
||||
str strcat strcmp strcpy strerror strlen strncmp strncpy strpos \
|
||||
strprintf strscan strscanf substr sum swap system tail tan tanh \
|
||||
test time trunc version xor
|
||||
strprintf strscan strscanf substr sum swap system systime tail tan \
|
||||
tanh test time trunc usertime version xor
|
||||
|
||||
# This list is of files that are clones of DETAIL_HELP files. They are
|
||||
# built from DETAIL_HELP files.
|
||||
|
16
help/config
16
help/config
@@ -68,6 +68,7 @@ DESCRIPTION
|
||||
"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:
|
||||
@@ -867,6 +868,16 @@ DESCRIPTION
|
||||
|
||||
The initial "redecl_warn" value is 1.
|
||||
|
||||
=-=
|
||||
|
||||
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.
|
||||
The non-zero value returned is in Hetrz.
|
||||
|
||||
This config parameter is read-only and cannot be set.
|
||||
|
||||
|
||||
EXAMPLE
|
||||
; current_cfg = config("all");
|
||||
@@ -928,6 +939,7 @@ EXAMPLE
|
||||
baseb 32
|
||||
redecl_warn 1
|
||||
dupvar_warn 1
|
||||
hz 100
|
||||
|
||||
; display()
|
||||
20
|
||||
@@ -960,8 +972,8 @@ SEE ALSO
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.17 $
|
||||
## @(#) $Id: config,v 29.17 2006/06/24 19:06:58 chongo Exp $
|
||||
## @(#) $Revision: 29.18 $
|
||||
## @(#) $Id: config,v 29.18 2006/12/16 11:14:28 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/config,v $
|
||||
##
|
||||
## Under source code control: 1991/07/21 04:37:17
|
||||
|
63
help/cp
63
help/cp
@@ -1,63 +0,0 @@
|
||||
NAME
|
||||
cp - cross product of two 3 element vectors
|
||||
|
||||
SYNOPSIS
|
||||
cp(x, y)
|
||||
|
||||
TYPES
|
||||
x, y 1-dimensional matrices 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}
|
||||
|
||||
EXAMPLE
|
||||
; mat x[3] = {2,3,4}
|
||||
; mat y[3] = {3,4,5}
|
||||
; print cp(x,y)
|
||||
|
||||
mat [3] (3 elements, 3 nonzero):
|
||||
[0] = -1
|
||||
[1] = 2
|
||||
[2] = -1
|
||||
|
||||
LIMITS
|
||||
The components of the matrices are to be of types for which the
|
||||
required algebraic operations have been defined.
|
||||
|
||||
LINK LIBRARY
|
||||
MATRIX *matcross(MATRIX *x, MATRIX *y)
|
||||
|
||||
SEE ALSO
|
||||
dp
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: cp,v 29.3 2006/05/07 07:25:46 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/cp,v $
|
||||
##
|
||||
## Under source code control: 1995/10/05 04:52:26
|
||||
## File existed as early as: 1995
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
30
help/runtime
30
help/runtime
@@ -1,5 +1,5 @@
|
||||
NAME
|
||||
runtime - user runtime
|
||||
runtime - CPU time used by the current process in both user and kernel modes
|
||||
|
||||
SYNOPSIS
|
||||
runtime()
|
||||
@@ -8,27 +8,33 @@ TYPES
|
||||
return nonnegative real
|
||||
|
||||
DESCRIPTION
|
||||
Returns the current user mode cpu runtime in seconds.
|
||||
In POSIX based systems, this function will return the CPU seconds
|
||||
used by the current process in both user and kernel mode. Time
|
||||
spent in the kernel executing system calls and time spend executing
|
||||
user code (such as performing computation on behalf of calc) are
|
||||
both included.
|
||||
|
||||
On non-POSIX based systems, this function will always return 0.
|
||||
In particular, most MS windows based systems do not have the required
|
||||
POSIX system call and so this function will always return 0.
|
||||
|
||||
EXAMPLE
|
||||
|
||||
The result for this example will depend on the speed and number of
|
||||
of clock-ticks per second for the computer being used. The result
|
||||
is a multiple of 1/CLK_TCK, where CLK_TCK is usually 60, 100, or 1000.
|
||||
The result for this example will depend on the speed of the CPU
|
||||
and precision of the operating CPU time accounting sub-system:
|
||||
|
||||
; t = runtime();
|
||||
; pi = pi(1e-1000);
|
||||
; x = ptest(2^4253-1);
|
||||
; runtime() - t;
|
||||
.2
|
||||
1.288804
|
||||
|
||||
LIMITS
|
||||
none
|
||||
On non-POSIX based systems, this function always returns 0.
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
ctime, time
|
||||
config, ctime, systime, time, usertime
|
||||
|
||||
## Copyright (C) 1999-2006 Landon Curt Noll
|
||||
##
|
||||
@@ -46,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.
|
||||
##
|
||||
## @(#) $Revision: 29.5 $
|
||||
## @(#) $Id: runtime,v 29.5 2006/06/25 22:16:55 chongo Exp $
|
||||
## @(#) $Revision: 29.7 $
|
||||
## @(#) $Id: runtime,v 29.7 2006/12/16 10:52:27 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/runtime,v $
|
||||
##
|
||||
## Under source code control: 1996/03/12 23:10:01
|
||||
|
@@ -3,22 +3,76 @@ Statements
|
||||
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. In this list, upper
|
||||
case words identify the keywords which are actually in lower case.
|
||||
Statements are generally terminated with semicolons, except if the
|
||||
statement is the compound one formed by matching braces. Various
|
||||
expressions are optional and may be omitted (as in RETURN).
|
||||
with explanation of the non-C statements.
|
||||
|
||||
Statements are generally terminated with semicolons or { ... }.
|
||||
|
||||
C-like statements
|
||||
-----------------
|
||||
{ statement }
|
||||
{ statement; ... statement }
|
||||
|
||||
|
||||
C-like flow control
|
||||
-------------------
|
||||
if (expr) statement
|
||||
if (expr) statement ELSE statement
|
||||
if (expr) statement else statement
|
||||
for (optionalexpr ; optionalexpr ; optionalexpr) statement
|
||||
while (expr) statement
|
||||
do statement while (expr)
|
||||
|
||||
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.
|
||||
|
||||
This works as expected:
|
||||
|
||||
if (expr) {
|
||||
...
|
||||
}
|
||||
|
||||
However this WILL NOT WORK AS EXPECTED:
|
||||
|
||||
if (expr)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
because calc will parse the if being terminated by
|
||||
an empty statement followed by a
|
||||
|
||||
if (expr) ;
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
In the same way, use these forms:
|
||||
|
||||
for (optionalexpr ; optionalexpr ; optionalexpr) {
|
||||
...
|
||||
}
|
||||
|
||||
while (expr) {
|
||||
...
|
||||
}
|
||||
|
||||
do {
|
||||
...
|
||||
while (expr);
|
||||
|
||||
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'.
|
||||
|
||||
|
||||
C-like flow breaks
|
||||
------------------
|
||||
continue
|
||||
break
|
||||
goto label
|
||||
@@ -30,8 +84,9 @@ Statements
|
||||
|
||||
return
|
||||
------
|
||||
return optionalexpr
|
||||
return ( optionalexpr )
|
||||
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
|
||||
@@ -241,7 +296,7 @@ Statements
|
||||
builtin calc builtin functions
|
||||
usage how to invoke the calc command and calc -options
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -257,8 +312,8 @@ Statements
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.2 $
|
||||
## @(#) $Id: statement,v 29.2 2000/06/07 14:02:33 chongo Exp $
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: statement,v 29.3 2007/01/03 21:26:22 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/statement,v $
|
||||
##
|
||||
## Under source code control: 1991/07/21 04:37:23
|
||||
|
63
help/systime
Normal file
63
help/systime
Normal file
@@ -0,0 +1,63 @@
|
||||
NAME
|
||||
systime - kernel CPU time used by the current process
|
||||
|
||||
SYNOPSIS
|
||||
systime()
|
||||
|
||||
TYPES
|
||||
return nonnegative real
|
||||
|
||||
DESCRIPTION
|
||||
In POSIX based systems, this function will return the CPU seconds
|
||||
used by the current process while in kernel mode executing kernel
|
||||
code on behalf of the current process. Time spent by the current
|
||||
process executing user code (such as performing computation on
|
||||
behalf of calc) is not counted.
|
||||
|
||||
On non-POSIX based systems, this function will always return 0.
|
||||
In particular, most MS windows based systems do not have the required
|
||||
POSIX system call and so this function will always return 0.
|
||||
|
||||
EXAMPLE
|
||||
The result for this example will depend on the speed of the CPU
|
||||
and precision of the operating CPU time accounting sub-system:
|
||||
|
||||
; t = systime();
|
||||
; system("true"),
|
||||
; systime() - t;
|
||||
.001
|
||||
|
||||
LIMITS
|
||||
On non-POSIX based systems, this function always returns 0.
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
config, ctime, runtime, systime, time
|
||||
|
||||
## Copyright (C) 2006 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: systime,v 29.3 2006/12/16 10:53:01 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/systime,v $
|
||||
##
|
||||
## Under source code control: 2006/12/16 10:31:08
|
||||
## File existed as early as: 2006
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
43
help/todo
43
help/todo
@@ -24,14 +24,32 @@ Calc Todo Items:
|
||||
|
||||
Very High priority items:
|
||||
|
||||
* Consider using GNU autoconf / configure to build calc.
|
||||
* 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:
|
||||
|
||||
* Internationalize calc by converting calc error messages and
|
||||
text strings (e.g., calc startup banner, show output, etc.)
|
||||
into calls to the GNU gettext internationalization facility.
|
||||
If somebody translated these strings into another language,
|
||||
setting $LANG would allow calc to produce error messages
|
||||
and text strings in that language.
|
||||
if (expr) {
|
||||
...
|
||||
}
|
||||
|
||||
However this WILL NOT WORK AS EXPECTED:
|
||||
|
||||
if (expr)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
because calc will parse the if being terminated by
|
||||
an empty statement followed by a
|
||||
|
||||
if (expr) ;
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
See also "help statement", "help unexpected", "help todo", and
|
||||
"help bugs".
|
||||
|
||||
* Consider using GNU autoconf / configure to build calc.
|
||||
|
||||
* Fix any 'Known bugs' as noted in the BUGS file or as
|
||||
displayed by 'calc help bugs'.
|
||||
@@ -54,6 +72,13 @@ High priority items:
|
||||
* Address, if possible and reasonable, any Calc Mis-features
|
||||
as noted in the BUGS file or as displayed by 'calc help bugs'.
|
||||
|
||||
* Internationalize calc by converting calc error messages and
|
||||
text strings (e.g., calc startup banner, show output, etc.)
|
||||
into calls to the GNU gettext internationalization facility.
|
||||
If somebody translated these strings into another language,
|
||||
setting $LANG would allow calc to produce error messages
|
||||
and text strings in that language.
|
||||
|
||||
=-=
|
||||
|
||||
Medium priority items:
|
||||
@@ -104,8 +129,8 @@ Medium priority items:
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.9 $
|
||||
## @(#) $Id: todo,v 29.9 2006/09/17 20:54:07 chongo Exp $
|
||||
## @(#) $Revision: 29.10 $
|
||||
## @(#) $Id: todo,v 29.10 2007/01/03 21:26:22 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/todo,v $
|
||||
##
|
||||
## Under source code control: 1999/10/20 07:42:55
|
||||
|
@@ -248,7 +248,55 @@ Unexpected
|
||||
In addition to the C style /* comment lines */, lines that begin with
|
||||
#! are treated as comments.
|
||||
|
||||
## Copyright (C) 1999 Landon Curt Noll
|
||||
|
||||
The { must be on the same line as an if, for, while or do
|
||||
=========================================================
|
||||
|
||||
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:
|
||||
|
||||
if (expr) {
|
||||
...
|
||||
}
|
||||
|
||||
However this WILL NOT WORK AS EXPECTED:
|
||||
|
||||
if (expr)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
because calc will parse the if being terminated by
|
||||
an empty statement followed by a
|
||||
|
||||
if (expr) ;
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
In the same way, use these forms:
|
||||
|
||||
for (optionalexpr ; optionalexpr ; optionalexpr) {
|
||||
...
|
||||
}
|
||||
|
||||
while (expr) {
|
||||
...
|
||||
}
|
||||
|
||||
do {
|
||||
...
|
||||
while (expr);
|
||||
|
||||
where the initial { is on the SAME LINE as the if, while,
|
||||
for or do keyword.
|
||||
|
||||
NOTE: See "help statement", "help todo", and "help bugs".
|
||||
|
||||
|
||||
## Copyright (C) 1999-2006 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
|
||||
@@ -264,8 +312,8 @@ Unexpected
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.2 $
|
||||
## @(#) $Id: unexpected,v 29.2 2000/06/07 14:02:33 chongo Exp $
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: unexpected,v 29.3 2007/01/03 21:26:22 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/unexpected,v $
|
||||
##
|
||||
## Under source code control: 1997/03/21 13:15:18
|
||||
|
61
help/usertime
Normal file
61
help/usertime
Normal file
@@ -0,0 +1,61 @@
|
||||
NAME
|
||||
usertime - user CPU time used by the current process
|
||||
|
||||
SYNOPSIS
|
||||
usertime()
|
||||
|
||||
TYPES
|
||||
return nonnegative real
|
||||
|
||||
DESCRIPTION
|
||||
In POSIX based systems, this function will return the CPU seconds
|
||||
used by the current process while in user mode. Time spent in the
|
||||
kernel executing system calls is not included.
|
||||
|
||||
On non-POSIX based systems, this function will always return 0.
|
||||
In particular, most MS windows based systems do not have the required
|
||||
POSIX system call and so this function will always return 0.
|
||||
|
||||
EXAMPLE
|
||||
The result for this example will depend on the speed of the CPU
|
||||
and precision of the operating CPU time accounting sub-system:
|
||||
|
||||
; t = usertime();
|
||||
; x = ptest(2^4253-1);
|
||||
; usertime() - t;
|
||||
1.287804
|
||||
|
||||
LIMITS
|
||||
On non-POSIX based systems, this function always returns 0.
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
config, ctime, usertime, systime, time
|
||||
|
||||
## Copyright (C) 2006 Landon Curt Noll
|
||||
##
|
||||
## Calc is open software; you can redistribute it and/or modify it under
|
||||
## the terms of the version 2.1 of the GNU Lesser General Public License
|
||||
## as published by the Free Software Foundation.
|
||||
##
|
||||
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
||||
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
||||
## Public License for more details.
|
||||
##
|
||||
## A copy of version 2.1 of the GNU Lesser General Public License is
|
||||
## distributed with calc under the filename COPYING-LGPL. You should have
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.2 $
|
||||
## @(#) $Id: usertime,v 29.2 2006/12/16 10:50:19 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/usertime,v $
|
||||
##
|
||||
## Under source code control: 2006/12/16 10:31:08
|
||||
## File existed as early as: 2006
|
||||
##
|
||||
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
||||
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
24
input.c
24
input.c
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.11 $
|
||||
* @(#) $Id: input.c,v 29.11 2006/05/19 15:26:10 chongo Exp $
|
||||
* @(#) $Revision: 29.12 $
|
||||
* @(#) $Id: input.c,v 29.12 2006/12/15 17:02:49 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/input.c,v $
|
||||
*
|
||||
* Under source code control: 1990/02/15 01:48:16
|
||||
@@ -961,9 +961,6 @@ static int
|
||||
isinoderead(struct stat *sbuf)
|
||||
{
|
||||
int i;
|
||||
#if defined(_WIN32) || defined(__MSDOS__)
|
||||
char fullpathname[_MAX_PATH];
|
||||
#endif
|
||||
|
||||
/* deal with the empty case */
|
||||
if (readset == NULL || maxreadset <= 0) {
|
||||
@@ -974,13 +971,17 @@ isinoderead(struct stat *sbuf)
|
||||
/* scan the entire readset */
|
||||
for (i=0; i < maxreadset; ++i) {
|
||||
#if defined(_WIN32) || defined(__MSDOS__)
|
||||
tmp = _fullpath(NULL, cip->i_name, _MAX_PATH);
|
||||
if (readset[i].active &&
|
||||
strcasecmp(readset[i].path,
|
||||
_fullpath(fullpathname,cip->i_name,
|
||||
_MAX_PATH)) == 0) {
|
||||
tmp != NULL &&
|
||||
strcasecmp(readset[i].path, tmp) == 0) {
|
||||
/* found a match */
|
||||
free(tmp);
|
||||
return i;
|
||||
}
|
||||
if (tmp != NULL) {
|
||||
free(tmp);
|
||||
}
|
||||
#else /* Windoz free systems */
|
||||
if (readset[i].active &&
|
||||
sbuf->st_dev == readset[i].inode.st_dev &&
|
||||
@@ -1106,9 +1107,10 @@ addreadset(char *name, char *path, struct stat *sbuf)
|
||||
* this new longer path name.
|
||||
*/
|
||||
{
|
||||
char fullpathname[_MAX_PATH];
|
||||
|
||||
readset[ret].path = _fullpath(fullpathname, path, _MAX_PATH);
|
||||
readset[ret].path = _fullpath(NULL, path, _MAX_PATH);
|
||||
if (readset[ret].path == NULL) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#else /* Windoz free systems */
|
||||
path_len = strlen(path);
|
||||
|
49
qmath.c
49
qmath.c
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.6 $
|
||||
* @(#) $Id: qmath.c,v 29.6 2006/05/20 08:43:55 chongo Exp $
|
||||
* @(#) $Revision: 29.7 $
|
||||
* @(#) $Id: qmath.c,v 29.7 2006/12/15 16:18:10 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/qmath.c,v $
|
||||
*
|
||||
* Under source code control: 1990/02/15 01:48:21
|
||||
@@ -140,6 +140,25 @@ qtou(NUMBER *q)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Convert a number to a normal signed integer.
|
||||
* s = qtos(q);
|
||||
*/
|
||||
SFULL
|
||||
qtos(NUMBER *q)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Convert a normal unsigned integer into a number.
|
||||
* q = utoq(i);
|
||||
@@ -166,6 +185,32 @@ utoq(FULL i)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Convert a normal signed integer into a number.
|
||||
* q = stoq(s);
|
||||
*/
|
||||
NUMBER *
|
||||
stoq(SFULL i)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create a number from the given FULL numerator and denominator.
|
||||
* q = uutoq(inum, iden);
|
||||
|
6
qmath.h
6
qmath.h
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.7 $
|
||||
* @(#) $Id: qmath.h,v 29.7 2006/06/25 20:33:26 chongo Exp $
|
||||
* @(#) $Revision: 29.8 $
|
||||
* @(#) $Id: qmath.h,v 29.8 2006/12/15 16:18:10 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/qmath.h,v $
|
||||
*
|
||||
* Under source code control: 1993/07/30 19:42:47
|
||||
@@ -65,8 +65,10 @@ extern NUMBER *iitoq(long i1, long i2);
|
||||
extern NUMBER *str2q(char *str);
|
||||
extern NUMBER *itoq(long i);
|
||||
extern NUMBER *utoq(FULL i);
|
||||
extern NUMBER *stoq(SFULL i);
|
||||
extern long qtoi(NUMBER *q);
|
||||
extern FULL qtou(NUMBER *q);
|
||||
extern SFULL qtos(NUMBER *q);
|
||||
extern long qparse(char *str, int flags);
|
||||
extern void qfreenum(NUMBER *q);
|
||||
extern void qprintnum(NUMBER *q, int mode);
|
||||
|
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.71 $
|
||||
* @(#) $Id: version.c,v 29.71 2006/09/18 13:14:03 chongo Exp $
|
||||
* @(#) $Revision: 29.72 $
|
||||
* @(#) $Id: version.c,v 29.72 2007/01/03 21:27:55 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/version.c,v $
|
||||
*
|
||||
* Under source code control: 1990/05/22 11:00:58
|
||||
@@ -48,7 +48,7 @@ static char *program;
|
||||
#define MAJOR_VER 2 /* major version */
|
||||
#define MINOR_VER 12 /* minor version */
|
||||
#define MAJOR_PATCH 1 /* patch level or 0 if no patch */
|
||||
#define MINOR_PATCH 5 /* test number or 0 if no minor patch */
|
||||
#define MINOR_PATCH 6 /* test number or 0 if no minor patch */
|
||||
|
||||
|
||||
/*
|
||||
|
@@ -3,12 +3,12 @@
|
||||
*/
|
||||
|
||||
|
||||
#if !defined(__HAVE_RUSAGE_H__)
|
||||
#define __HAVE_RUSAGE_H__
|
||||
#if !defined(__HAVE_STRDUP_H__)
|
||||
#define __HAVE_STRDUP_H__
|
||||
|
||||
|
||||
/* do we have or want getstrdup()? */
|
||||
#define HAVE_STRDUP /* yes */
|
||||
|
||||
|
||||
#endif /* !__HAVE_RUSAGE_H__ */
|
||||
#endif /* !__HAVE_STRDUP_H__ */
|
||||
|
75
zmath.c
75
zmath.c
@@ -19,8 +19,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.2 $
|
||||
* @(#) $Id: zmath.c,v 29.2 2000/06/07 14:02:13 chongo Exp $
|
||||
* @(#) $Revision: 29.3 $
|
||||
* @(#) $Id: zmath.c,v 29.3 2006/12/15 16:20:04 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/zmath.c,v $
|
||||
*
|
||||
* Under source code control: 1990/02/15 01:48:28
|
||||
@@ -355,6 +355,42 @@ utoz(FULL i, ZVALUE *res)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Convert a normal signed integer to a number.
|
||||
*/
|
||||
void
|
||||
stoz(SFULL i, ZVALUE *res)
|
||||
{
|
||||
long diddle, len;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Convert a number to a unsigned normal integer, as far as possible.
|
||||
* If the number is out of range, the largest number is returned.
|
||||
@@ -370,6 +406,41 @@ ztou(ZVALUE z)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Convert a number to a signed normal integer, as far as possible.
|
||||
*
|
||||
* If the number is too large to fit into an integer, than the largest
|
||||
* positive or largest negative integer is returned depending on the sign.
|
||||
*/
|
||||
SFULL
|
||||
ztos(ZVALUE z)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/* positive value processing */
|
||||
if (z.len > 2) {
|
||||
return (SFULL)MAXFULL;
|
||||
}
|
||||
val = ztofull(z);
|
||||
if (val > MAXFULL) {
|
||||
return (SFULL)MAXFULL;
|
||||
}
|
||||
return (SFULL)val;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Make a copy of an integer value
|
||||
*/
|
||||
|
7
zmath.h
7
zmath.h
@@ -17,8 +17,8 @@
|
||||
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* @(#) $Revision: 29.17 $
|
||||
* @(#) $Id: zmath.h,v 29.17 2006/06/11 07:07:23 chongo Exp $
|
||||
* @(#) $Revision: 29.18 $
|
||||
* @(#) $Id: zmath.h,v 29.18 2006/12/15 16:20:04 chongo Exp $
|
||||
* @(#) $Source: /usr/local/src/cmd/calc/RCS/zmath.h,v $
|
||||
*
|
||||
* Under source code control: 1993/07/30 19:42:48
|
||||
@@ -131,6 +131,7 @@ typedef SB32 SFULL; /* signed FULL */
|
||||
|
||||
#define TOPFULL ((FULL)1 << (FULL_BITS-1)) /* highest bit in FULL */
|
||||
#define MAXFULL (TOPFULL - (FULL)1) /* largest SFULL value */
|
||||
#define MINSFULL ((SFULL)(TOPFULL)) /* most negative SFULL value */
|
||||
#define MAXUFULL (MAXFULL | TOPFULL) /* largest FULL value */
|
||||
|
||||
#define TOPLONG ((unsigned long)1 << (LONG_BITS-1)) /* top long bit */
|
||||
@@ -289,9 +290,11 @@ extern DLL void freeh(HALF *);
|
||||
extern DLL void zcopy(ZVALUE z, ZVALUE *res);
|
||||
extern DLL void itoz(long i, ZVALUE *res);
|
||||
extern DLL void utoz(FULL i, ZVALUE *res);
|
||||
extern DLL void stoz(SFULL i, ZVALUE *res);
|
||||
extern DLL void str2z(char *s, ZVALUE *res);
|
||||
extern DLL long ztoi(ZVALUE z);
|
||||
extern DLL FULL ztou(ZVALUE z);
|
||||
extern DLL SFULL ztos(ZVALUE z);
|
||||
extern DLL void zprintval(ZVALUE z, long decimals, long width);
|
||||
extern DLL void zprintx(ZVALUE z, long width);
|
||||
extern DLL void zprintb(ZVALUE z, long width);
|
||||
|
Reference in New Issue
Block a user