mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Release calc version 2.10.2t30
This commit is contained in:
369
help/Makefile
Normal file
369
help/Makefile
Normal file
@@ -0,0 +1,369 @@
|
||||
#
|
||||
# help - makefile for calc help files
|
||||
#
|
||||
# Copyright (c) 1994 David I. Bell and Landon Curt Noll
|
||||
# Permission is granted to use, distribute, or modify this source,
|
||||
# provided that this copyright notice remains intact.
|
||||
#
|
||||
# Arbitrary precision calculator.
|
||||
#
|
||||
# calculator by David I. Bell
|
||||
# makefile by Landon Curt Noll
|
||||
|
||||
# required vars
|
||||
#
|
||||
SHELL= /bin/sh
|
||||
MAKE_FILE = Makefile
|
||||
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
#
|
||||
TOPDIR= /usr/local/lib
|
||||
#TOPDIR= /usr/lib
|
||||
#TOPDIR= /usr/libdata
|
||||
|
||||
LIBDIR= ${TOPDIR}/calc
|
||||
HELPDIR= ${LIBDIR}/help
|
||||
|
||||
# Makefile debug
|
||||
#
|
||||
# Q=@ do not echo internal makefile actions (quiet mode)
|
||||
# Q= echo internal makefile actions (debug / verbose mode)
|
||||
#
|
||||
#Q=
|
||||
Q=@
|
||||
|
||||
# standard tools
|
||||
#
|
||||
NATIVE_CC= cc
|
||||
NATIVE_CFLAGS=
|
||||
SED= sed
|
||||
SORT= sort
|
||||
FMT= fmt
|
||||
CMP= cmp
|
||||
CAT= cat
|
||||
|
||||
# Standard help files
|
||||
#
|
||||
# The obj.file is special and is not listed here.
|
||||
#
|
||||
STD_HELP_FILES1= intro overview help command config \
|
||||
define environment expression file history interrupt mat
|
||||
STD_HELP_FILES2= operator statement types usage variable
|
||||
STD_HELP_FILES3= todo credit
|
||||
STD_HELP_FILES= ${STD_HELP_FILES1} ${STD_HELP_FILES2} ${STD_HELP_FILES3}
|
||||
SYMBOL_HELP= assign
|
||||
|
||||
# These two lists are prodiced by the detaillist and missinglist rules
|
||||
# when no WARNINGS are detected.
|
||||
#
|
||||
DETAIL_HELP= abs access acos acosh acot acoth acsc acsch append appr archive \
|
||||
arg asec asech asin asinh assoc atan atan2 atanh avg base bround \
|
||||
btrunc ceil cfappr cfsim char cmdbuf cmp comb conj cos cosh cot coth \
|
||||
count cp csc csch ctime delete den det digit digits dp epsilon errno \
|
||||
error eval exp fact factor fclose fcnt feof ferror fflush fgetc \
|
||||
fgetfield fgetline fgets fgetstr fib files floor fopen forall fprintf \
|
||||
fputc fputs fputstr frac frem freopen fscan fscanf fseek fsize ftell \
|
||||
gcd gcdrem getenv hash head highbit hmean hypot ilog ilog10 ilog2 im \
|
||||
insert int inverse iroot isassoc isatty isconfig iserror iseven \
|
||||
isfile ishash isident isint islist ismat ismult isnull isnum isobj \
|
||||
isodd isprime isqrt isrand israndom isreal isrel isset issimple issq \
|
||||
isstr istype jacobi join lcm lcmfact lfactor list ln lowbit ltol \
|
||||
makelist matdim matfill matmax matmin matsum mattrans max meq min \
|
||||
minv mmin mne mod modify near newerror nextcand nextprime norm null \
|
||||
num ord param perm pfact pi pix places pmod polar poly pop power \
|
||||
prevcand prevprime printf prompt ptest push putenv quo quomod rand \
|
||||
randbit randperm rcin rcmul rcout rcpow rcsq re rm remove reverse \
|
||||
rewind root round rsearch runtime scale scan scanf search sec sech \
|
||||
segment select sgn sin sinh size sizeof sort sqrt srand ssq str \
|
||||
strcat strerror strlen strpos strprintf strscan strscanf substr swap \
|
||||
system tail tan tanh time trunc xor
|
||||
|
||||
# Help files that are constructed from other sources
|
||||
#
|
||||
# The obj.file is special and is not listed here.
|
||||
#
|
||||
BUILT_HELP_FILES= bindings altbind changes libcalc stdlib bugs errorcodes
|
||||
|
||||
# Singular files
|
||||
#
|
||||
# These files are copies of their plural form.
|
||||
#
|
||||
PLURAL_FILES= bindings bugs changes errorcodes types
|
||||
SINGULAR_FILES= binding bug change errorcode type
|
||||
|
||||
# These files are found (but not built) in the distribution
|
||||
#
|
||||
DISTLIST= ${STD_HELP_FILES} ${DETAIL_HELP} ${SYMBOL_HELP} ${MAKE_FILE} \
|
||||
obj.file builtin.top builtin.end funclist.sed \
|
||||
errorcodes.hdr errorcodes.sed
|
||||
|
||||
all: ${STD_HELP_FILES} obj.file ${BUILT_HELP_FILES} full \
|
||||
${DETAIL_HELP} ${SINGULAR_FILES} builtin .all
|
||||
|
||||
# used by the upper level Makefile to determine of we have done all
|
||||
#
|
||||
# NOTE: Due to bogus shells found on one common system we must have
|
||||
# an non-emoty else clause for every if condition. *sigh*
|
||||
#
|
||||
.all:
|
||||
rm -f .all
|
||||
touch .all
|
||||
|
||||
bindings: ../lib/bindings
|
||||
rm -f bindings
|
||||
cp ../lib/bindings bindings
|
||||
chmod 0444 bindings
|
||||
-@if [ -z "${Q}" ]; then \
|
||||
echo ''; \
|
||||
echo '=-=-= skipping the cat of help/$@ =-=-='; \
|
||||
echo ''; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
|
||||
altbind: ../lib/altbind
|
||||
rm -f altbind
|
||||
cp ../lib/altbind altbind
|
||||
chmod 0444 altbind
|
||||
-@if [ -z "${Q}" ]; then \
|
||||
echo ''; \
|
||||
echo '=-=-= skipping the cat of help/$@ =-=-='; \
|
||||
echo ''; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
|
||||
stdlib: ../lib/README
|
||||
rm -f stdlib
|
||||
cp ../lib/README stdlib
|
||||
chmod 0444 stdlib
|
||||
-@if [ -z "${Q}" ]; then \
|
||||
echo ''; \
|
||||
echo '=-=-= skipping the cat of help/$@ =-=-='; \
|
||||
echo ''; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
|
||||
changes: ../CHANGES
|
||||
rm -f changes
|
||||
cp ../CHANGES changes
|
||||
chmod 0444 changes
|
||||
-@if [ -z "${Q}" ]; then \
|
||||
echo ''; \
|
||||
echo '=-=-= skipping the cat of help/$@ =-=-='; \
|
||||
echo ''; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
|
||||
libcalc: ../LIBRARY
|
||||
rm -f libcalc
|
||||
${SED} -e 's:$${LIBDIR}:${LIBDIR}:g' < ../LIBRARY > libcalc
|
||||
chmod 0444 libcalc
|
||||
-@if [ -z "${Q}" ]; then \
|
||||
echo ''; \
|
||||
echo '=-=-= skipping the cat of help/$@ =-=-='; \
|
||||
echo ''; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
|
||||
bugs: ../BUGS
|
||||
rm -f bugs
|
||||
cp ../BUGS bugs
|
||||
chmod 0444 bugs
|
||||
-@if [ -z "${Q}" ]; then \
|
||||
echo ''; \
|
||||
echo '=-=-= skipping the cat of help/$@ =-=-='; \
|
||||
echo ''; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
|
||||
errorcodes: ../calcerr.h errorcodes.hdr errorcodes.sed
|
||||
rm -f errorcodes
|
||||
${CAT} errorcodes.hdr > errorcodes
|
||||
${SED} -n -f errorcodes.sed < ../calcerr.h >> errorcodes
|
||||
chmod 0444 errorcodes
|
||||
-@if [ -z "${Q}" ]; then \
|
||||
echo ''; \
|
||||
echo '=-=-= skipping the cat of help/$@ =-=-='; \
|
||||
echo ''; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
|
||||
full: ${STD_HELP_FILES} ${BUILT_HELP_FILES} ${MAKE_FILE}
|
||||
${Q}echo "forming full"
|
||||
-${Q}rm -f full
|
||||
-${Q}for i in ${STD_HELP_FILES1} obj.file ${STD_HELP_FILES2} \
|
||||
${BUILT_HELP_FILES} ${STD_HELP_FILES3}; do \
|
||||
if [ Xintro != X"$$i" ]; then \
|
||||
echo ""; \
|
||||
else \
|
||||
true; \
|
||||
fi; \
|
||||
if [ Xobj.file = X"$$i" ]; then \
|
||||
j=obj; \
|
||||
else \
|
||||
j=$$i; \
|
||||
fi; \
|
||||
echo "*************"; \
|
||||
echo "* $$j"; \
|
||||
echo "*************"; \
|
||||
echo ""; \
|
||||
cat $$i; \
|
||||
done > full
|
||||
${Q}echo "full formed"
|
||||
-@if [ -z "${Q}" ]; then \
|
||||
echo ''; \
|
||||
echo '=-=-= skipping the cat of help/$@ =-=-='; \
|
||||
echo ''; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
|
||||
# Singular files are the same files as their plural form.
|
||||
#
|
||||
${SINGULAR_FILES}: ${PLURAL_FILES}
|
||||
${Q}for i in ${SINGULAR_FILES}; do \
|
||||
echo "rm -f $${i}"; \
|
||||
rm -f $${i}; \
|
||||
echo "cp $${i}s $${i}"; \
|
||||
cp $${i}s $${i}; \
|
||||
done
|
||||
-@if [ -z "${Q}" ]; then \
|
||||
echo ''; \
|
||||
echo '=-=-= skipping the cat of help/SINGULAR_FILES =-=-='; \
|
||||
echo ''; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
|
||||
# Form the builtin file
|
||||
#
|
||||
# We ave a "chicken-and-egg" problem. We want the builtn help file to
|
||||
# accurately reflect the function list. It would be nice if we could
|
||||
# just execute calc show builtin, but calc may not have been built or
|
||||
# buildable at this point. The hack-a-round used is to convert ../func.c
|
||||
# into a standalone program that generates a suitable function list
|
||||
# that is standwiched between the top and bottom builtin help text.
|
||||
#
|
||||
# We form funclist.c by sedding out unwanted stuff from builtins table,
|
||||
# converting NUMBER* and VALUE into harmless types and converting
|
||||
# the showbuiltins() function into main(). Combined with the -DFUNCLIST
|
||||
# we will avoid all of the complex calc types, macros and defines and
|
||||
# be left with just main() and a mininal builtins table.
|
||||
#
|
||||
# Building funclist.o a portable fashion is ugly because some systems
|
||||
# do not treat -I.. correctly!
|
||||
#
|
||||
builtin: builtin.top builtin.end ../func.c funclist.sed
|
||||
${Q}echo "forming builtin help file"
|
||||
-${Q}rm -f builtin
|
||||
${Q}cat builtin.top > builtin
|
||||
-${Q}rm -f funclist.c
|
||||
${Q}${SED} -n -f funclist.sed ../func.c > funclist.c
|
||||
|
||||
-${Q}rm -f ../funclist.c ../funclist.o ../funclist funclist
|
||||
${Q}cp funclist.c ..
|
||||
-${Q}(cd ..; \
|
||||
${NATIVE_CC} ${NATIVE_CFLAGS} -DFUNCLIST funclist.c -o funclist; \
|
||||
mv funclist help; \
|
||||
rm -f funclist.c funclist.o funclist)
|
||||
${Q}./funclist | \
|
||||
${SED} -e 's/^/ /' -e 's/[ ][ ]*$$//' >> builtin
|
||||
${Q}cat builtin.end >> builtin
|
||||
${Q}echo "builtin help file formed"
|
||||
-@if [ -z "${Q}" ]; then \
|
||||
echo ''; \
|
||||
echo '=-=-= skipping the cat of help/$@ =-=-='; \
|
||||
echo ''; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
|
||||
##
|
||||
#
|
||||
# File list generation. You can ignore this section.
|
||||
#
|
||||
#
|
||||
# We will form the names of source files as if they were in a
|
||||
# sub-directory called calc/help.
|
||||
#
|
||||
##
|
||||
|
||||
distlist: ${DISTLIST}
|
||||
${Q}for i in ${DISTLIST}; do \
|
||||
echo calc/help/$$i; \
|
||||
done | ${SORT}
|
||||
|
||||
# The bsdi distribution has generated files as well as distributed files.
|
||||
#
|
||||
bsdilist: ${DISTLIST} ${BUILT_HELP_FILES}
|
||||
${Q}for i in ${DISTLIST} ${BUILT_HELP_FILES}; do \
|
||||
echo calc/help/$$i; \
|
||||
done | ${SORT}
|
||||
|
||||
# The BSDI cdrom makefile expects all help files to be pre-built. This rule
|
||||
# creats these fils so that the release can be shipped off to BSDI. You can
|
||||
# ignore this rule.
|
||||
#
|
||||
bsdi: all
|
||||
rm -f obj
|
||||
cp obj.file obj
|
||||
|
||||
# These next rule help me form the ${DETAIL_HELP} makefile variables above.
|
||||
#
|
||||
detaillist:
|
||||
${Q}-(echo "xxxxx"; \
|
||||
for i in ${DETAIL_HELP}; do \
|
||||
if [ ! -f SCCS/s.$$i ]; then \
|
||||
echo "WARNING: $$i not under SCCS control" 1>&2; \
|
||||
else \
|
||||
echo $$i; \
|
||||
fi; \
|
||||
done | ${SORT}) | ${FMT} -70 | \
|
||||
${SED} -e '1s/xxxxx/DETAIL_HELP=/' -e '2,$$s/^/ /' \
|
||||
-e 's/$$/ \\/' -e '$$s/ \\$$//'
|
||||
|
||||
clean:
|
||||
rm -f obj mkbuiltin funclist.c funclist.o funclist
|
||||
|
||||
clobber:
|
||||
rm -f ${BUILT_HELP_FILES} full builtin .all
|
||||
rm -f obj mkbuiltin funclist.c funclist.o funclist ${SINGULAR_FILES}
|
||||
|
||||
install: all
|
||||
-${Q}if [ ! -d ${TOPDIR} ]; then \
|
||||
echo mkdir ${TOPDIR}; \
|
||||
mkdir ${TOPDIR}; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
-${Q}if [ ! -d ${LIBDIR} ]; then \
|
||||
echo mkdir ${LIBDIR}; \
|
||||
mkdir ${LIBDIR}; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
-${Q}if [ ! -d ${HELPDIR} ]; then \
|
||||
echo mkdir ${HELPDIR}; \
|
||||
mkdir ${HELPDIR}; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
${Q}for i in ${STD_HELP_FILES} ${BUILT_HELP_FILES} builtin \
|
||||
full ${DETAIL_HELP} ${SINGULAR_FILES} ${SYMBOL_HELP}; do \
|
||||
echo rm -f ${HELPDIR}/$$i; \
|
||||
rm -f ${HELPDIR}/$$i; \
|
||||
echo cp $$i ${HELPDIR}; \
|
||||
cp $$i ${HELPDIR}; \
|
||||
echo chmod 0444 ${HELPDIR}/$$i; \
|
||||
chmod 0444 ${HELPDIR}/$$i; \
|
||||
done
|
||||
rm -f ${HELPDIR}/obj
|
||||
cp obj.file ${HELPDIR}/obj
|
||||
chmod 0444 ${HELPDIR}/obj
|
41
help/abs
Normal file
41
help/abs
Normal file
@@ -0,0 +1,41 @@
|
||||
NAME
|
||||
abs - absolute value
|
||||
|
||||
SYNOPSIS
|
||||
abs(x [,eps])
|
||||
|
||||
TYPES
|
||||
If x is an object of type xx, the function xx_abs has to have
|
||||
been defined; this will determine the types for x, eps and
|
||||
the returned value.
|
||||
|
||||
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().
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
If x is real, returns x if x is positive or zero, -x if x is negative.
|
||||
|
||||
For complex x, returns the multiple of eps nearest or next to nearest
|
||||
to the absolute value of x. The result usually has error less in
|
||||
absolute value than abs(eps), but should not exceed 0.75 * abs(eps).
|
||||
|
||||
EXAMPLE
|
||||
> print abs(3.4), abs(-3.4)
|
||||
3.4 3.4
|
||||
|
||||
> print abs(3+4i, 1e-5), abs(4+5i, 1e-5), abs(4+5i, 1e-10)
|
||||
5 6.40312 6.4031242374
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
cmp, epsilon, hypot, norm, near, obj
|
46
help/access
Normal file
46
help/access
Normal file
@@ -0,0 +1,46 @@
|
||||
NAME
|
||||
access - determine existence or accessibility of named file
|
||||
|
||||
SYNOPSIS
|
||||
access(name [, mode])
|
||||
|
||||
TYPES
|
||||
name string
|
||||
mode integer or string containing only 'r', 'w', 'x' characters
|
||||
|
||||
return null value or error
|
||||
|
||||
DESCRIPTION
|
||||
access(name) or access(name, 0) or access(name, "") returns the null
|
||||
value if a file with this name exists.
|
||||
|
||||
If non-null mode is specified, the null value is returned if there
|
||||
is a file with the specified name and accessibility indicated by the
|
||||
bits or characters of the mode argument: 'r' or bit 2 for reading,
|
||||
'w' or bit 1 for writing, 'x' or bit 0 for execution.
|
||||
|
||||
EXAMPLE
|
||||
> !rm -f junk
|
||||
> access("junk")
|
||||
Error 10002 XXX This number will probably be changed
|
||||
> f = fopen("junk", "w")
|
||||
> access("junk")
|
||||
> fputs(f, "Now is the time");
|
||||
> freopen(f, "r");
|
||||
> !chmod u-w junk
|
||||
> fgets(f)
|
||||
"Now is the time"
|
||||
> access("junk", "w")
|
||||
Error 10013 XXX
|
||||
> freopen(f, "w")
|
||||
Error 10013 XXX
|
||||
|
||||
LIMITS
|
||||
none - XXX - is this correct?
|
||||
|
||||
LIBRARY
|
||||
none - XXX - is this correct?
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
32
help/acos
Normal file
32
help/acos
Normal file
@@ -0,0 +1,32 @@
|
||||
NAME
|
||||
acos - inverse trigonometric cosine
|
||||
|
||||
SYNOPSIS
|
||||
acos(x [,eps])
|
||||
|
||||
TYPES
|
||||
x real, -1 <= x <= 1
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Returns the acos of x to a multiple of eps with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
v = acos(x) is the number in [0, pi] for which cos(v) = x.
|
||||
|
||||
EXAMPLE
|
||||
> print acos(.5, 1e-5), acos(.5, 1e-10), acos(.5, 1e-15), acos(.5, 1e-20)
|
||||
1.0472 1.0471975512 1.047197551196598 1.04719755119659774615
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
abs(x) <= 1
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qacos(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
asin, atan, asec, acsc, acot, epsilon
|
32
help/acosh
Normal file
32
help/acosh
Normal file
@@ -0,0 +1,32 @@
|
||||
NAME
|
||||
acosh - inverse hyperbolic cosine
|
||||
|
||||
SYNOPSIS
|
||||
acosh(x [,eps])
|
||||
|
||||
TYPES
|
||||
x real, x >= 1
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return nonnegative real
|
||||
|
||||
DESCRIPTION
|
||||
Returns the cosh of x to a multiple of eps with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
acosh(x) = ln(x + sqrt(x^2 - 1)) is the nonnegative real number v
|
||||
for which cosh(v) = x.
|
||||
|
||||
EXAMPLE
|
||||
> print acosh(2, 1e-5), acosh(2, 1e-10), acosh(2, 1e-15), acosh(2, 1e-20)
|
||||
1.31696 1.3169578969 1.316957896924817 1.31695789692481670862
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qacosh(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
asinh, atanh, asech, acsch, acoth, epsilon
|
31
help/acot
Normal file
31
help/acot
Normal file
@@ -0,0 +1,31 @@
|
||||
NAME
|
||||
acot - inverse trigonometric cotangent
|
||||
|
||||
SYNOPSIS
|
||||
acot(x [,eps])
|
||||
|
||||
TYPES
|
||||
x real
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Returns the acot of x to a multiple of eps with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
v = acot(x) is the number in (0, pi) for which cot(v) = x.
|
||||
|
||||
EXAMPLE
|
||||
> print acot(2, 1e-5), acot(2, 1e-10), acot(2, 1e-15), acot(2, 1e-20)
|
||||
.46365 .463647609 .463647609000806 .46364760900080611621
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qacot(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
asin, acos, atan, asec, acsc, epsilon
|
33
help/acoth
Normal file
33
help/acoth
Normal file
@@ -0,0 +1,33 @@
|
||||
NAME
|
||||
acoth - inverse hyperbolic cotangent
|
||||
|
||||
SYNOPSIS
|
||||
acoth(x [,eps])
|
||||
|
||||
TYPES
|
||||
x real, with abs(x) > 1
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Returns the acoth of x to a multiple of eps with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
acoth(x) = ln((x + 1)/(x - 1))/2 is the real number v for which
|
||||
coth(v) = x.
|
||||
|
||||
EXAMPLE
|
||||
> print acoth(2, 1e-5), acoth(2, 1e-10), acoth(2, 1e-15), acoth(2, 1e-20)
|
||||
.54931 .5493061443 .549306144334055 .5493061443340548457
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
abs(x) > 1
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qacoth(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
asinh, acosh, atanh, asech, acsch, epsilon
|
32
help/acsc
Normal file
32
help/acsc
Normal file
@@ -0,0 +1,32 @@
|
||||
NAME
|
||||
acsc - inverse trigonometric cosecant
|
||||
|
||||
SYNOPSIS
|
||||
acsc(x [,eps])
|
||||
|
||||
TYPES
|
||||
x real, with absolute value >= 1
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Returns the acsc of x to a multiple of eps with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
v = acsc(x) is the number in [-pi/2, pi/2] for which csc(v) = x.
|
||||
|
||||
EXAMPLE
|
||||
> print acsc(2, 1e-5), acsc(2, 1e-10), acsc(2, 1e-15), acsc(2, 1e-20)
|
||||
.5236 .5235987756 .523598775598299 .52359877559829887308
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
abs(x) >= 1
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qacsc(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
asin, acos, atan, asec, acot, epsilon
|
33
help/acsch
Normal file
33
help/acsch
Normal file
@@ -0,0 +1,33 @@
|
||||
NAME
|
||||
acsch - inverse hyperbolic cosecant
|
||||
|
||||
SYNOPSIS
|
||||
acsch(x [,eps])
|
||||
|
||||
TYPES
|
||||
x nonzero real
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Returns the acsch of x to a multiple of eps with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
acsch(x) = ln((1 + sqrt(1 + x^2))/x) is the real number v for
|
||||
which csch(v) = x.
|
||||
|
||||
EXAMPLE
|
||||
> print acsch(2, 1e-5), acsch(2, 1e-10), acsch(2, 1e-15), acsch(2, 1e-20)
|
||||
.48121 .4812118251 .481211825059603 .4812118250596034475
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
x != 0
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qacsch(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
asinh, acosh, atanh, asech, acoth, epsilon
|
60
help/append
Normal file
60
help/append
Normal file
@@ -0,0 +1,60 @@
|
||||
NAME
|
||||
append - append one or more values to end of list
|
||||
|
||||
SYNOPSIS
|
||||
append(x, y_0, y_1, ...)
|
||||
|
||||
TYPES
|
||||
x lvalue whose value is a list
|
||||
y_0, ... any
|
||||
|
||||
return null value
|
||||
|
||||
DESCRIPTION
|
||||
If after evaluation of y_0, y_1, ..., x is a list with contents
|
||||
(x_0, x_1, ...), then after append(x, y_0, y_1, ...), x has
|
||||
contents (x_0, x_1, ..., y_0, y_1, ...).
|
||||
|
||||
If after evaluation of y_0, y_1, ..., x has size n,
|
||||
append(x, y_0, y_1, ...) is equivalent to insert(x, n, y_0, y_1, ...).
|
||||
|
||||
EXAMPLE
|
||||
> x = list(2,3,4)
|
||||
> append(x, 5, 6)
|
||||
> print x
|
||||
|
||||
list (5 elements, 5 nonzero):
|
||||
[[0]] = 2
|
||||
[[1]] = 3
|
||||
[[2]] = 4
|
||||
[[3]] = 5
|
||||
[[4]] = 6
|
||||
|
||||
> append(x, pop(x), pop(x))
|
||||
> print x
|
||||
|
||||
list (5 elements, 5 nonzero):
|
||||
[[0]] = 4
|
||||
[[1]] = 5
|
||||
[[2]] = 6
|
||||
[[3]] = 2
|
||||
[[4]] = 3
|
||||
|
||||
> append(x, (remove(x), 7))
|
||||
> print x
|
||||
|
||||
list (5 elements, 5 nonzero):
|
||||
[[0]] = 4
|
||||
[[1]] = 5
|
||||
[[2]] = 6
|
||||
[[3]] = 2
|
||||
[[4]] = 7
|
||||
|
||||
LIMITS
|
||||
append() can have at most 100 arguments
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
delete, insert, islist, list, pop, push, remove, rsearch, search, size
|
146
help/appr
Normal file
146
help/appr
Normal file
@@ -0,0 +1,146 @@
|
||||
NAME
|
||||
appr - approximate numbers by multiples of a specified number
|
||||
|
||||
SYNOPSIS
|
||||
appr(x [,y [,z]])
|
||||
|
||||
TYPES
|
||||
x real, complex, matrix, list
|
||||
y real
|
||||
z integer
|
||||
|
||||
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
|
||||
(epsilon) and config ("appr") value.
|
||||
|
||||
The default value for y is epsilon(). The default value for z is
|
||||
the current value of the "appr" configuration parameter.
|
||||
|
||||
If y is zero or x is a multiple of y, appr(x,y,z) returns x. I.e.,
|
||||
there is no "approximation" - the result represents x exactly.
|
||||
|
||||
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.
|
||||
|
||||
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 = 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 = 3 round away from zero, sgn(r) = -sgn(x)
|
||||
|
||||
z = 4 round down
|
||||
|
||||
z = 5 round up
|
||||
|
||||
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 = 8 a/y is even
|
||||
|
||||
z = 9 a/y is odd
|
||||
|
||||
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 = 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 = 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 = 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).
|
||||
|
||||
XXX - complex x needs to be documented
|
||||
|
||||
PROPERTIES
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
EXAMPLES
|
||||
> print appr(-5.44,0.1,0), appr(5.44,0.1,0), appr(5.7,1,0), appr(-5.7,1,0)
|
||||
-5.5 5.4 5 -6
|
||||
|
||||
> print appr(-5.44,-.1,0), appr(5.44,-.1,0), appr(5.7,-1,0), appr(-5.7,-1,0)
|
||||
-5.4 5.5 6 -5
|
||||
|
||||
> print appr(-5.44,0.1,3), appr(5.44,0.1,3), appr(5.7,1,3), appr(-5.7,1,3)
|
||||
-5.5 5.5 6 -6
|
||||
|
||||
> print appr(-5.44,0.1,4), appr(5.44,0.1,4), appr(5.7,1,4), appr(-5.7,1,4)
|
||||
-5.5 5.4 5 -6
|
||||
|
||||
> print appr(-5.44,0.1,6), appr(5.44,0.1,6), appr(5.7,1,6), appr(-5.7,1,6)
|
||||
-5.4 5.4 6 -5
|
||||
|
||||
> print appr(-5.44,-.1,6), appr(5.44,-.1,6), appr(5.7,-1,6), appr(-5.7,-1,6)
|
||||
-5.5 5.5 6 -6
|
||||
|
||||
> print appr(-5.44,0.1,9), appr(5.44,0.1,9), appr(5.7,1,9), appr(-5.7,1,9)
|
||||
-5.5 5.5 5 -5
|
||||
|
||||
> print appr(-.44,0.1,11), appr(.44,0.1,11), appr(5.7,1,11), appr(-5.7,1,11)
|
||||
-.4 .5 5 -6
|
||||
|
||||
> print appr(-.44,-.1,11),appr(.44,-.1,11),appr(5.7,-1,11),appr(-5.7,-1,11)
|
||||
-.5 .4 6 -5
|
||||
|
||||
> print appr(-.44,0.1,12), appr(.44,0.1,12), appr(5.7,1,12), appr(-5.7,1,12)
|
||||
-.4 .5 5 -6
|
||||
|
||||
> print appr(-.44,-.1,12),appr(.44,-.1,12),appr(5.7,-1,12),appr(-5.7,-1,12)
|
||||
-.5 .4 6 -5
|
||||
|
||||
> print appr(-.44,0.1,15), appr(.44,0.1,15), appr(5.7,1,15), appr(-5.7,1,15)
|
||||
-.4 .5 5 -6
|
||||
|
||||
> print appr(-.44,-.1,15),appr(.44,-.1,15),appr(5.7,-1,15),appr(-5.7,-1,15)
|
||||
-.4 .5 5 -6
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qmappr(NUMBER *q, NUMBER *e, long R);
|
||||
LIST *listappr(LIST *oldlp, VALUE *v2, VALUE *v3);
|
||||
MATRIX *matappr(MATRIX *m, VALUE *v2, VALUE *v3);
|
||||
|
||||
SEE ALSO
|
||||
round, bround, cfappr, cfsim
|
25
help/archive
Normal file
25
help/archive
Normal file
@@ -0,0 +1,25 @@
|
||||
Where to get the the latest versions of calc
|
||||
|
||||
Landon Noll maintains the official calc ftp archive at:
|
||||
|
||||
ftp://ftp.uu.net/pub/calc
|
||||
|
||||
Alpha test versions, complete with bugs, untested code and
|
||||
experimental features may be fetched (if you are brave) under:
|
||||
|
||||
http://reality.sgi.com/chongo/calc/
|
||||
|
||||
One may join the calc testing group by sending a request to:
|
||||
|
||||
calc-tester-request@postofc.corp.sgi.com
|
||||
|
||||
Your message body (not the subject) should consist of:
|
||||
|
||||
subscribe calc-tester address
|
||||
end
|
||||
name your_full_name
|
||||
|
||||
where "address" is your EMail address and "your_full_name"
|
||||
is your full name.
|
||||
|
||||
Landon Curt Noll <chongo@toad.com> /\oo/\
|
33
help/arg
Normal file
33
help/arg
Normal file
@@ -0,0 +1,33 @@
|
||||
NAME
|
||||
arg - argument (the angle or phase) of a complex number
|
||||
|
||||
SYNOPSIS
|
||||
arg(x [,eps])
|
||||
|
||||
TYPES
|
||||
x number
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Returns the argument of x to the nearest or next to nearest multiple of
|
||||
eps; the error will be less in absolute value than 0.75 * abs(eps),
|
||||
but usually less than 0.5 * abs(eps). By default, acc is epsilon().
|
||||
|
||||
EXAMPLE
|
||||
> print arg(2), arg(2+3i, 1e-5), arg(2+3i, 1e-10), arg(2+3i, 1e-20)
|
||||
0 .98279 .9827937232 .98279372324732906799
|
||||
|
||||
> pi = pi(1e-10); deg = pi/180; eps = deg/10000
|
||||
> print arg(2+3i, eps)/deg, arg(-1 +1i, eps)/deg, arg(-1 - 1i,eps)/deg
|
||||
56.3099 135 -135
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
conj, im, polar, re
|
32
help/asec
Normal file
32
help/asec
Normal file
@@ -0,0 +1,32 @@
|
||||
NAME
|
||||
asec - inverse trigonometric secant
|
||||
|
||||
SYNOPSIS
|
||||
asec(x [,eps])
|
||||
|
||||
TYPES
|
||||
x real, with absolute value >= 1
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Returns the asec of x to a multiple of eps with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
v = asec(x) is the number in [0, pi] for which sec(v) = x.
|
||||
|
||||
EXAMPLE
|
||||
> print asec(2, 1e-5), asec(2, 1e-10), asec(2, 1e-15), asec(2, 1e-20)
|
||||
1.0472 1.0471975512 1.047197551196598 1.04719755119659774615
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
abs(x) >= 1
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qasec(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
asin, acos, atan, acsc, acot, epsilon
|
33
help/asech
Normal file
33
help/asech
Normal file
@@ -0,0 +1,33 @@
|
||||
NAME
|
||||
asech - inverse hyperbolic secant
|
||||
|
||||
SYNOPSIS
|
||||
asech(x [,eps])
|
||||
|
||||
TYPES
|
||||
x real, 0 < x <= 1
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Returns the asech of x to a multiple of eps with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
asech(x) = ln((1 + sqrt(1 - x^2))/x) is the real number v for which
|
||||
sech(v) = x.
|
||||
|
||||
EXAMPLE
|
||||
> print asech(.5,1e-5), asech(.5,1e-10), asech(.5,1e-15), asech(.5,1e-20)
|
||||
1.31696 1.3169578969 1.316957896924817 1.31695789692481670862
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
0 < x <= 1
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qasech(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
asinh, acosh, atanh, acsch, acoth, epsilon
|
32
help/asin
Normal file
32
help/asin
Normal file
@@ -0,0 +1,32 @@
|
||||
NAME
|
||||
asin - inverse trigonometric sine
|
||||
|
||||
SYNOPSIS
|
||||
asin(x [,eps])
|
||||
|
||||
TYPES
|
||||
x real, -1 <= x <= 1
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Returns the asin of x to a multiple of eps with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
v = asin(x) is the number in [-p1/2, pi/2] for which sin(v) = x.
|
||||
|
||||
EXAMPLE
|
||||
> print asin(.5, 1e-5), asin(.5, 1e-10), asin(.5, 1e-15), asin(.5, 1e-20)
|
||||
.5236 .5235987756 .523598775598299 .52359877559829887308
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
abs(x) <= 1
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qasin(NUMBER *q, NUMBER *epsilon)
|
||||
|
||||
SEE ALSO
|
||||
acos, atan, asec, acsc, acot, epsilon
|
32
help/asinh
Normal file
32
help/asinh
Normal file
@@ -0,0 +1,32 @@
|
||||
NAME
|
||||
asinh - inverse hyperbolic sine
|
||||
|
||||
SYNOPSIS
|
||||
asinh(x [,eps])
|
||||
|
||||
TYPES
|
||||
x real
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Returns the asinh of x to a multiple of eps with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
asinh(x) = ln(x + sqrt(1 + x^2)) is the real number v for which
|
||||
sinh(v) = x.
|
||||
|
||||
EXAMPLE
|
||||
> print asinh(2, 1e-5), asinh(2, 1e-10), asinh(2, 1e-15), asinh(2, 1e-20)
|
||||
1.44363 1.4436354752 1.44363547517881 1.44363547517881034249
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qasinh(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
acosh, atanh, asech, acsch, acoth, epsilon
|
29
help/assign
Normal file
29
help/assign
Normal file
@@ -0,0 +1,29 @@
|
||||
NAME
|
||||
=
|
||||
|
||||
SYNOPSIS
|
||||
a = b
|
||||
|
||||
TYPES
|
||||
a lvalue
|
||||
b expression
|
||||
|
||||
return lvalue
|
||||
|
||||
DESCRIPTION
|
||||
a = b evaluates b, assigns its value to a, and returns a.
|
||||
|
||||
EXAMPLE
|
||||
> b = 3+1
|
||||
> a = b
|
||||
> print a, b
|
||||
4 4
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
XXX - fill in
|
79
help/assoc
Normal file
79
help/assoc
Normal file
@@ -0,0 +1,79 @@
|
||||
NAME
|
||||
assoc - create a new association array
|
||||
|
||||
SYNOPSIS
|
||||
assoc()
|
||||
|
||||
TYPES
|
||||
return association
|
||||
|
||||
DESCRIPTION
|
||||
This functions returns an empty association array.
|
||||
|
||||
Associations are special values that act like matrices, except
|
||||
that they are more general (and slower) than normal matrices.
|
||||
Unlike matrices, associations can be indexed by arbitrary values.
|
||||
For example, if 'val' was an association, you could do the following:
|
||||
|
||||
val['hello'] = 11;
|
||||
val[4.5] = val['hello'];
|
||||
print val[9/2];
|
||||
|
||||
and 11 would be printed.
|
||||
|
||||
Associations are created by the 'assoc' function. It takes no
|
||||
arguments, and simply returns an empty association. You can then
|
||||
insert elements into the association by indexing the returned value
|
||||
as shown above.
|
||||
|
||||
Associations are multi-dimensional. You can index them using one to
|
||||
four dimensions as desired, and the elements with different numbers
|
||||
of dimensions will remain separated. For example, 'val[3]' and
|
||||
'val[3,0]' can both be used in the same association and will be
|
||||
distinct elements.
|
||||
|
||||
When references are made to undefined elements of an association,
|
||||
a null value is simply returned. Therefore no bounds errors can
|
||||
occur when indexing an association. Assignments of a null value
|
||||
to an element of an association does not delete the element, but
|
||||
a later reference to that element will return the null value as if
|
||||
the element was undefined. Elements with null values are implicitly
|
||||
created on certain other operations which require an address to be
|
||||
taken, such as the += operator and using & in a function call.
|
||||
|
||||
The elements of an association are stored in a hash table for
|
||||
quick access. The index values are hashed to select the correct
|
||||
hash chain for a small sequential search for the element. The hash
|
||||
table will be resized as necessary as the number of entries in
|
||||
the association becomes larger.
|
||||
|
||||
The size function returns the number of elements in an association.
|
||||
This size will include elements with null values.
|
||||
|
||||
Double bracket indexing can be used for associations to walk through
|
||||
the elements of the association. The order that the elements are
|
||||
returned in as the index increases is essentially random. Any
|
||||
change made to the association can reorder the elements, this making
|
||||
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
|
||||
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
|
||||
for equality. But no other operations on associations have meaning,
|
||||
and are illegal.
|
||||
|
||||
EXAMPLE
|
||||
> print assoc()
|
||||
|
||||
assoc (0 elements):
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
isassoc, rsearch, search, size
|
31
help/atan
Normal file
31
help/atan
Normal file
@@ -0,0 +1,31 @@
|
||||
NAME
|
||||
atan - inverse trigonometric tangent
|
||||
|
||||
SYNOPSIS
|
||||
atan(x [,eps])
|
||||
|
||||
TYPES
|
||||
x real
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Returns the atan of x to a multiple of eps with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
v = atan(x) is the number in (-p1/2, pi/2) for which tan(v) = x.
|
||||
|
||||
EXAMPLE
|
||||
> print atan(2, 1e-5), atan(2, 1e-10), atan(2, 1e-15), atan(2, 1e-20)
|
||||
1.10715 1.1071487178 1.107148717794091 1.10714871779409050302
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qatan(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
asin, acos, asec, acsc, acot, epsilon
|
36
help/atan2
Normal file
36
help/atan2
Normal file
@@ -0,0 +1,36 @@
|
||||
NAME
|
||||
atan2 - angle to point
|
||||
|
||||
SYNOPSIS
|
||||
atan2(y, x, [,acc])
|
||||
|
||||
TYPES
|
||||
y real
|
||||
x real
|
||||
acc real
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Return the angle which is determined by the point (x,y). This
|
||||
function computes the arctangent of y/x in the range [-pi, pi].
|
||||
The value acc specifies the accuracy of the result. By default, acc
|
||||
is epsilon().
|
||||
|
||||
Note that by convention, y is the first argument.
|
||||
|
||||
To conform to the 4.3BSD ANSI/IEEE 754-1985 math lib, atan2(0,0) is
|
||||
defined to return 0.
|
||||
|
||||
EXAMPLE
|
||||
> print atan2(0,0), atan2(1,sqrt(3)), atan2(17,53,1e-100)
|
||||
0 ~.52359877559829887307 ~.31038740713235146535
|
||||
|
||||
LIMITS
|
||||
acc > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qatan2(NUMBER *y, *x, *acc)
|
||||
|
||||
SEE ALSO
|
||||
acos, asin, atan, cos, epsilon, sin, tan
|
32
help/atanh
Normal file
32
help/atanh
Normal file
@@ -0,0 +1,32 @@
|
||||
NAME
|
||||
atanh - inverse hyperbolic tangent
|
||||
|
||||
SYNOPSIS
|
||||
atanh(x [,eps])
|
||||
|
||||
TYPES
|
||||
x real
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Returns the atanh of x to a multiple of eps with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
atanh(x) = ln((1 + x)/(1 - x))/2 is the real number v for whichi
|
||||
tanh(v) = x.
|
||||
|
||||
EXAMPLE
|
||||
> print atanh(.5,1e-5), atanh(.5,1e-10), atanh(.5,1e-15), atanh(.5,1e-20)
|
||||
.54931 .5493061443 .549306144334055 .5493061443340548457
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qatanh(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
asinh, acosh, asech, acsch, acoth, epsilon
|
50
help/avg
Normal file
50
help/avg
Normal file
@@ -0,0 +1,50 @@
|
||||
NAME
|
||||
avg - average (arithmetic) mean of values
|
||||
|
||||
SYNOPSIS
|
||||
avg(x_1, x_2, ...)
|
||||
|
||||
TYPES
|
||||
x_1, ... arithmetic or list
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
number. If the x_i are summable matrices the result will be a matrix
|
||||
of the same size (e.g. if the x_i are all 3 x 4 matrices with real
|
||||
entries, the result will be a 3 x 4 matrix with real entries).
|
||||
|
||||
If an argument x_i is list-valued, e.g. list(y_1, y_2, ...), this
|
||||
is treated as contributing y_1, y_2, ... to the list of items to
|
||||
be averaged.
|
||||
|
||||
EXAMPLE
|
||||
> print avg(1,2,3,4,5), avg(list(1,2,3,4,5)), avg(1,2,list(3,4,5))
|
||||
3 3 3
|
||||
|
||||
> mat x[2,2] = {1,2,3,4}
|
||||
> mat y[2,2] = {1,2,4,8}
|
||||
> avg(x,y)
|
||||
|
||||
mat [2,2] (4 elements, 4 nonzero):
|
||||
[0,0] = 1
|
||||
[0,1] = 2
|
||||
[1,0] = 3.5
|
||||
[1,1] = 6
|
||||
|
||||
LIMITS
|
||||
The number of arguments is not to exceed 100.
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
hmean
|
55
help/base
Normal file
55
help/base
Normal file
@@ -0,0 +1,55 @@
|
||||
NAME
|
||||
base - set default output base
|
||||
|
||||
SYNOPSIS
|
||||
base([mode])
|
||||
|
||||
TYPES
|
||||
mode real
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
The base function allows one to specify how numbers should be
|
||||
printer. 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:
|
||||
|
||||
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
|
||||
|
||||
For convenience, any non-integer value is assumed to mean "frac",
|
||||
and any integer >= 2^64 is assumed to mean "exp".
|
||||
|
||||
EXAMPLE
|
||||
> base()
|
||||
10
|
||||
|
||||
> base(8)
|
||||
012
|
||||
|
||||
> print 10
|
||||
012
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
int math_setmode(int newmode)
|
||||
|
||||
NOTE: newmode must be one of MODE_DEFAULT, MODE_FRAC, MODE_INT,
|
||||
MODE_REAL, MODE_EXP, MODE_HEX, MODE_OCTAL, MODE_BINARY
|
||||
|
||||
SEE ALSO
|
||||
config
|
123
help/bround
Normal file
123
help/bround
Normal file
@@ -0,0 +1,123 @@
|
||||
NAME
|
||||
bround - round numbers to a specified number of binary digits
|
||||
|
||||
SYNOPSIS
|
||||
bround(x [,plcs [, rnd]])
|
||||
|
||||
TYPES
|
||||
If x is a matrix or a list, bround(x[[i]], ...) is to return
|
||||
a value for each element x[[i]] of x; the value returned will be
|
||||
a matrix or list with the same structure as x.
|
||||
|
||||
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
|
||||
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")
|
||||
|
||||
return number
|
||||
|
||||
DESCRIPTION
|
||||
For real x, bround(x, plcs, rnd) returns x rounded to either
|
||||
plcs significant binary digits (if rnd & 32 is nonzero) or to plcs
|
||||
binary places (if rnd & 32 is zero). In the significant-figure
|
||||
case the rounding is to plcs - ilog10(x) - 1 binary places.
|
||||
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
|
||||
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
|
||||
|
||||
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.
|
||||
|
||||
For matrix or list 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.
|
||||
|
||||
EXAMPLES
|
||||
> a = 7/32, b = -7/32
|
||||
|
||||
> print a, b
|
||||
.21875 -.21875
|
||||
|
||||
> print round(a,3,0), round(a,3,1), round(a,3,2), print round(a,3,3)
|
||||
.218, .219, .218, .219
|
||||
|
||||
> print round(b,3,0), round(b,3,1), round(b,3,2), print round(b,3,3)
|
||||
-.219, -.218, -.218, -.219
|
||||
|
||||
> print round(a,3,16), round(a,3,17), round(a,3,18), print round(a,3,19)
|
||||
.2188 .2188 .2188 .2188
|
||||
|
||||
> print round(a,4,16), round(a,4,17), round(a,4,18), print round(a,4,19)
|
||||
.2187 .2188 .2187 .2188
|
||||
|
||||
> print round(a,2,8), round(a,3,8), round(a,4,8), round(a,5,8)
|
||||
.22 .218 .2188 .21875
|
||||
|
||||
> print round(a,2,24), round(a,3,24), round(a,4,24), round(a,5,24)
|
||||
.22 .219 .2188 .21875
|
||||
|
||||
> c = 21875
|
||||
> print round(c,-2,0), round(c,-2,1), round(c,-3,0), round(c,-3,16)
|
||||
21800 21900 21000 22000
|
||||
|
||||
> print round(c,2,32), round(c,2,33), round(c,2,56), round(c,4,56)
|
||||
21000 22000 22000 21880
|
||||
|
||||
> A = list(1/8, 2/8, 3/8, 4/8, 5/8, 6/8, 7/8)
|
||||
> print round(A,2,24)
|
||||
|
||||
list(7 elements, 7 nonzero):
|
||||
[[0]] = .12
|
||||
[[1]] = .25
|
||||
[[3]] = .38
|
||||
[[4]] = .5
|
||||
[[5]] = .62
|
||||
[[6]] = .75
|
||||
[[7]] = .88
|
||||
|
||||
LIMITS
|
||||
For non-object case:
|
||||
0 <= abs(plcs) < 2^31
|
||||
0 <= abs(rnd) < 2^31
|
||||
|
||||
LIBRARY
|
||||
void broundvalue(VALUE *x, VALUE *plcs, VALUE *rnd, VALUE *result)
|
||||
MATRIX *matbround(MATRIX *m, VALUE *plcs, VALUE *rnd);
|
||||
LIST *listbround(LIST *m, VALUE *plcs, VALUE *rnd);
|
||||
NUMBER *qbround(NUMBER *m, long plcs, long rnd);
|
||||
|
||||
SEE ALSO
|
||||
round, trunc, btrunc, int, appr
|
36
help/btrunc
Normal file
36
help/btrunc
Normal file
@@ -0,0 +1,36 @@
|
||||
NAME
|
||||
btrunc - truncate a value to a number of binary places
|
||||
|
||||
SYNOPSIS
|
||||
btrunc(x [,j])
|
||||
|
||||
TYPES
|
||||
x real
|
||||
j int
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Truncate x to j binary places. If j is omitted, 0 places is assumed.
|
||||
Specifying zero places makes the result identical to int().
|
||||
|
||||
Truncation of a non-integer prodcues values nearer to zero.
|
||||
|
||||
EXAMPLE
|
||||
> print btrunc(pi()), btrunc(pi(), 10)
|
||||
3 3.140625
|
||||
|
||||
> print btrunc(3.3), btrunc(3.7), btrunc(3.3, 2), btrunc(3.7, 2)
|
||||
3 3 3.25 3.5
|
||||
|
||||
> print btrunc(-3.3), btrunc(-3.7), btrunc(-3.3, 2), btrunc(-3.7, 2)
|
||||
-3 -3 -3.25 -3.5
|
||||
|
||||
LIMITS
|
||||
0 <= j < 2^31
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qbtrunc(NUMBER *x, *j)
|
||||
|
||||
SEE ALSO
|
||||
bround, int, round, trunc
|
200
help/builtin.end
Normal file
200
help/builtin.end
Normal file
@@ -0,0 +1,200 @@
|
||||
|
||||
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 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 digit and isset 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
|
||||
isset(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.
|
||||
|
||||
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)
|
||||
|
||||
Normally ptest performs a some checks to determine if the
|
||||
value is divisable 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:
|
||||
|
||||
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 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.
|
||||
|
||||
The nextcand and prevcand functions also have a 5 argument form:
|
||||
|
||||
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.
|
||||
|
||||
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 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 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.
|
||||
|
||||
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 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:
|
||||
|
||||
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:
|
||||
|
||||
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:
|
||||
|
||||
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 base function allows one to specify how numbers should be
|
||||
printer. 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:
|
||||
|
||||
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
|
||||
|
||||
For convenience, any non-integer value is assumed to mean "frac",
|
||||
and any integer >= 2^64 is assumed to mean "exp".
|
9
help/builtin.top
Normal file
9
help/builtin.top
Normal file
@@ -0,0 +1,9 @@
|
||||
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.
|
||||
|
33
help/ceil
Normal file
33
help/ceil
Normal file
@@ -0,0 +1,33 @@
|
||||
NAME
|
||||
ceil - ceiling
|
||||
|
||||
SYNOPSIS
|
||||
ceil(x)
|
||||
|
||||
TYPES
|
||||
x real, complex, list, matrix
|
||||
|
||||
return real or complex, list, matrix
|
||||
|
||||
DESCRIPTION
|
||||
For real x, ceil(x) is the least integer not less than x.
|
||||
|
||||
For complex, ceil(x) returns the real or complex number v for
|
||||
which re(v) = ceil(re(x)), im(v) = ceil(im(x)).
|
||||
|
||||
For list or matrix x, ceil(x) returns the list or matrix of the
|
||||
same structure as x for which each element t of x has been replaced
|
||||
by ceil(t).
|
||||
|
||||
EXAMPLE
|
||||
> print ceil(27), ceil(1.23), ceil(-4.56), ceil(7.8 - 9.1i)
|
||||
27 2 -4 8-9i
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
floor, int
|
89
help/cfappr
Normal file
89
help/cfappr
Normal file
@@ -0,0 +1,89 @@
|
||||
NAME
|
||||
cfappr - approximate a real number using continued fractions
|
||||
|
||||
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")
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
If x is an integer or eps is zero, either form returns x.
|
||||
|
||||
If abs(eps) < 1, cfappr(x, eps) returns the smallest-denominator
|
||||
number in one of the three intervals, [x, x + abs(eps)],
|
||||
[x - abs(eps], x], [x - abs(eps)/2, x + abs(eps)/2].
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
number differing from x by at most abs(eps)/2.
|
||||
|
||||
If bit 4 of rnd is set and den(x) > 2, the other bits are irrelevant for
|
||||
the bounded denominator case; in the case of two equally near nearest
|
||||
approximations with denominator less than n, cfappr(x, n, rnd)
|
||||
returns the number with smaller denominator. If den(x) = 2, bits
|
||||
0, 1 and 2 of rnd are used as described above.
|
||||
|
||||
If -1 < eps < 1, cfappr(x, eps, 0) may be described as the smallest
|
||||
denominator number in the closed interval with end-points x and x - eps.
|
||||
It follows that if abs(a - b) < 1, cfappr(a, a - b, 0) gives the smallest
|
||||
denominator number in the interval with end-points a and b; the same
|
||||
result is returned by cfappr(b, b - a, 0) or cfappr(a, b - a, 1).
|
||||
|
||||
If abs(eps) < 1 and v = cfappr(x, eps, rnd), then
|
||||
cfappr(x, sgn(eps) * den(v), rnd) = v.
|
||||
|
||||
If 1 <= n < den(x), u = cfappr(x, n, 0) and v = cfappr(x, n, 1), then
|
||||
u < x < v, den(u) <= n, den(v) <= n, den(u) + den(v) > n, and
|
||||
v - u = 1/(den(u) * den(v)).
|
||||
|
||||
If x is not zero, the nearest approximation with numerator not
|
||||
exceeding n is 1/cfappr(1/x, n, 16).
|
||||
|
||||
EXAMPLE
|
||||
> c = config("mode", "frac")
|
||||
> x = 43/30; u = cfappr(x, 10, 0); v = cfappr(x, 10, 1);
|
||||
> print u, v, x - u, v - x, v - u, cfappr(x, 10, 16)
|
||||
10/7 13/9 1/210 1/90 1/63 10/7
|
||||
|
||||
> pi = pi(1e-10)
|
||||
> print cfappr(pi, 100, 16), cfappr(pi, .01, 16), cfappr(pi, 1e-6, 16)
|
||||
311/99 22/7 355/113
|
||||
|
||||
> x = 17/12; u = cfappr(x,4,0); v = cfappr(x,4,1);
|
||||
> print u, v, x - u, v - x, cfappr(x,4,16)
|
||||
4/3 3/2 1/12 1/12 3/2
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qcfappr(NUMBER *q, NUMBER *epsilon, long R)
|
||||
|
||||
SEE ALSO
|
||||
appr, cfsim
|
114
help/cfsim
Normal file
114
help/cfsim
Normal file
@@ -0,0 +1,114 @@
|
||||
NAME
|
||||
cfsim - simplify a value using continued fractions
|
||||
|
||||
SYNOPSIS
|
||||
cfsim(x [,rnd])
|
||||
|
||||
TYPES
|
||||
x real
|
||||
rnd integer, defaults to config("cfsim")
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
If x is not an integer, cfsim(x, rnd) returns either the nearest
|
||||
above x, or the nearest below x, number with denominator less than
|
||||
den(x). If x is an integer, cfsim(x, rnd) returns x + 1, x - 1, or 0.
|
||||
Which of the possible results is returned is controlled
|
||||
by bits 0, 1, 3 and 4 of the parameter rnd.
|
||||
|
||||
For 0 <= rnd < 4, the sign of the remainder x - cfsim(x, rnd) is
|
||||
as follows:
|
||||
|
||||
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
|
||||
|
||||
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. Thusi, 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 approximant to x, i.e. if:
|
||||
|
||||
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
|
||||
obtained by dropping the last quotient 1/a_n.
|
||||
|
||||
If den(x) > 2, cfsim(x, 16) returns the nearest number to x with
|
||||
denominator less than den(x). In the continued-fraction representation
|
||||
of x described above, this is given by replacing a_n by a_n - 1.
|
||||
|
||||
If den(x) = 2, the definition adopted is to round towards zero for the
|
||||
approximant case (rnd = 8) and from zero for the "nearest" case (rnd = 16).
|
||||
|
||||
For integral x, cfsim(x, 8) returns zero, cfsim(x,16) returns x - sgn(x).
|
||||
|
||||
In summary, for cfsim(x, rnd) when rnd = 8 or 16, the results are:
|
||||
|
||||
rnd integer x half-integer x den(x) > 2
|
||||
|
||||
8 0 x - sgn(x)/2 approximant
|
||||
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
|
||||
(num(x) - num(w))/(den(x) - den(w)). From x and w one may find
|
||||
other optimal rational numbers near x; for example, the smallest-
|
||||
denominator number between x and w is (num(x) + num(w))/(den(x) + den(w)).
|
||||
|
||||
If x = n/d and cfsim(x, 8) = u/v, then for k * v < d, the k-th member of
|
||||
the sequence of nearest approximations to x with decreasing denominators
|
||||
on the other side of x is (n - k * u)/(d - k * v). This is nearer
|
||||
to or further from x than u/v according as 2 * k * v < or > d.
|
||||
|
||||
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
|
||||
continued-fraction approximants these are not necessarily alternately
|
||||
greater than and less than x.)
|
||||
|
||||
Some other properties:
|
||||
|
||||
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).
|
||||
|
||||
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).
|
||||
|
||||
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).
|
||||
|
||||
EXAMPLE
|
||||
> c = config("mode", "frac");
|
||||
|
||||
> print cfsim(43/30, 0), cfsim(43/30, 1), cfsim(43/30, 8), cfsim(43/30,16)
|
||||
10/7 33/23 10/7 33/23
|
||||
|
||||
> x = pi(1e-20); c = config("mode", "frac");
|
||||
> while (!isint(x)) {x = cfsim(x,8); if (den(x) < 1e6) print x,:;}
|
||||
1146408/364913 312689/99532 104348/33215 355/113 22/7 3
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qcfsim(NUMBER *x, long rnd)
|
||||
|
||||
SEE ALSO
|
||||
cfappr
|
27
help/char
Normal file
27
help/char
Normal file
@@ -0,0 +1,27 @@
|
||||
NAME
|
||||
char - character corresponding to a value
|
||||
|
||||
SYNOPSIS
|
||||
char(j)
|
||||
|
||||
TYPES
|
||||
j integer, 0 <= j < 256
|
||||
|
||||
return string
|
||||
|
||||
DESCRIPTION
|
||||
For j > 0, returns a string of length 1 with a character that has
|
||||
the same value as j. For j = 0, returns the null string "".
|
||||
|
||||
EXAMPLE
|
||||
> print char(0102), char(0x6f), char(119), char(0145), char(0x6e)
|
||||
B o w e n
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
ord
|
26
help/cmdbuf
Normal file
26
help/cmdbuf
Normal file
@@ -0,0 +1,26 @@
|
||||
NAME
|
||||
cmdbuf - print the command buffer
|
||||
|
||||
SYNOPSIS
|
||||
cmdbuf()
|
||||
|
||||
TYPES
|
||||
return str
|
||||
|
||||
DESCRIPTION
|
||||
This function returns the command string that was formed by calc based
|
||||
on its command line arguments. If calc was invoked without arguments,
|
||||
this function will return an empty string.
|
||||
|
||||
EXAMPLE
|
||||
> cmdbuf("")
|
||||
""
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
XXX - fill in
|
90
help/cmp
Normal file
90
help/cmp
Normal file
@@ -0,0 +1,90 @@
|
||||
NAME
|
||||
cmp - compare two values
|
||||
|
||||
SYNOPSIS
|
||||
cmp(x, y)
|
||||
|
||||
TYPES
|
||||
If x is an object of type xx or x is not an object and y is an object
|
||||
of type xx, the funcion xx_cmp has to have been defined; any
|
||||
further conditions on x and y, and the type of the returned
|
||||
value depends on the definition of xx_cmp.
|
||||
|
||||
For non-object x and y:
|
||||
|
||||
x number or string
|
||||
y same as x
|
||||
|
||||
return -1, 0, 1 (real & string)
|
||||
-1, 0, 1, -1+1i, 1i, 1+1i, -1-1i, -1i or 1-1i (complex)
|
||||
|
||||
DESCRIPTION
|
||||
Compare two values and return a value based on their relationship.
|
||||
Comparison by type is indicated below. Where more than one test is
|
||||
indicated, tests are performed in the order listed. If the test is
|
||||
inconclusive, the next test is performed. If all tests are
|
||||
inconclusive, the values are considered equivalent.
|
||||
|
||||
real (returns -1, 0, or 1)
|
||||
the greater number is greater
|
||||
|
||||
complex (returns -1, 0, 1, -1+1i, 1i, 1+1i, -1-1i, -1i or 1-1i)
|
||||
sgn(re(x) - re(y)) + sgn(im(x) - im(y)) * 1i
|
||||
|
||||
string (returns -1, 0, or 1)
|
||||
the string with the greater first different character is greater
|
||||
the longer string is greater
|
||||
|
||||
object (depends on xx_cmp)
|
||||
the greater object as defined by xx_cmp is greater
|
||||
|
||||
String comparison is performed via the strcmp() libc function.
|
||||
|
||||
Note that this function is not a substitution for equality. The ==
|
||||
operator always takes epsilon() into account when comparing numeric
|
||||
values. For example:
|
||||
|
||||
> cmp(1, 1+epsilon()/2)
|
||||
-1
|
||||
> 1 == 1+epsilon()/2
|
||||
0
|
||||
|
||||
It should be noted epsilon() is used when comparing complex values.
|
||||
|
||||
Properties of cmp(a,b) for real or complex a and b are:
|
||||
|
||||
cmp(a + c, b + c) = cmp(a,b)
|
||||
|
||||
cmp(a, b) == 0 if and only if a == b
|
||||
|
||||
cmp(b, a) = -cmp(a,b)
|
||||
|
||||
if c is real or pure imaginary, cmp(c * a, c * b) = c * cmp(a,b)
|
||||
|
||||
cmp(a,b) == cmp(b,c) if and only if b is "between" a and c
|
||||
|
||||
The numbers between 2 + 3i and 4 + 5i are those with real part between
|
||||
2 and 4, imaginary part between 3 and 5; the numbers between 2 + 3i
|
||||
and 4 + 3i are those with real part between 2 and 4, imaginary part = 3.
|
||||
|
||||
EXAMPLE
|
||||
> print cmp(3,4), cmp(4,3), cmp(4,4), cmp("a","b"), cmp("abcd","abc")
|
||||
-1 1 0 -1 1
|
||||
|
||||
> print cmp(3,4i), cmp(4,4i), cmp(5,4i), cmp(-5,4i), cmp(-4i,5), cmp(-4i,-5)
|
||||
1-1i 1-1i 1-1i -1-1i -1-1i 1-1i
|
||||
|
||||
> print cmp(3i,4i), cmp(4i,4i), cmp(5i,4i), cmp(3+4i,5), cmp(3+4i,-5)
|
||||
-1i 0 1i -1+1i 1+1i
|
||||
|
||||
> print cmp(3+4i,3+4i), cmp(3+4i,3-4i), cmp(3+4i,2+3i), cmp(3+4i,-4-5i)
|
||||
0 1i 1+1i 1+1i
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
abs, epsilon, sgn
|
39
help/comb
Normal file
39
help/comb
Normal file
@@ -0,0 +1,39 @@
|
||||
NAME
|
||||
comb - combinatorial number
|
||||
|
||||
SYNOPSIS
|
||||
comb(x, y)
|
||||
|
||||
TYPES
|
||||
x int
|
||||
y int
|
||||
|
||||
return int
|
||||
|
||||
DESCRIPTION
|
||||
Return the combinatorial number C(x,y) which is defined as:
|
||||
|
||||
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.
|
||||
|
||||
EXAMPLE
|
||||
> print comb(7,3), comb(7,4), comb(7,5), comb(3,0), comb(0,0)
|
||||
35 35 21 1 1
|
||||
|
||||
> print comb(2^31+1,2^31-1)
|
||||
2305843010287435776
|
||||
|
||||
LIMITS
|
||||
x >= y >= 0
|
||||
y < 2^24
|
||||
x-y < 2^24
|
||||
|
||||
LIBRARY
|
||||
void zcomb(NUMBER x, y, *ret)
|
||||
|
||||
SEE ALSO
|
||||
fact, perm
|
99
help/command
Normal file
99
help/command
Normal file
@@ -0,0 +1,99 @@
|
||||
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
|
||||
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
|
||||
a function is being defined, but is not yet completed.
|
||||
|
||||
Each command sequence terminates only on an end of file. In
|
||||
addition, commands can consist of expression sequences, which are
|
||||
described in the next section.
|
||||
|
||||
|
||||
NOTE: Calc commands are in lower case. UPPER case is used below
|
||||
for emphasis only, and should be considered in lower case.
|
||||
|
||||
|
||||
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.
|
||||
|
||||
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();
|
||||
|
||||
HELP
|
||||
This displays a general help message.
|
||||
|
||||
READ filename
|
||||
This reads definitions from the specified filename.
|
||||
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 (that is, the current
|
||||
directory followed by a general calc library directory).
|
||||
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.
|
||||
|
||||
If the -m mode disallows opening of files for reading,
|
||||
this command will be disabled.
|
||||
|
||||
READ -once filename
|
||||
This command acts like the regular READ expect that it
|
||||
will ignore filename if is has been previously read.
|
||||
|
||||
This command is particularly useful in a library that
|
||||
needs to read a 2nd library. By using the READ -once
|
||||
command, one will not reread that 2nd library, nor will
|
||||
once risk entering into a infinite READ loop (where
|
||||
that 2nd library directly or indirectly does a READ of
|
||||
the first library).
|
||||
|
||||
If the -m mode disallows opening of files for reading,
|
||||
this command will be disabled.
|
||||
|
||||
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.
|
||||
|
||||
If the -m mode disallows opening of files for writing,
|
||||
this command will be disabled.
|
||||
|
||||
QUIT
|
||||
This leaves the calculator, when given as a top-level
|
||||
command.
|
||||
|
||||
CD
|
||||
Change the current directory to the home directory, if $HOME
|
||||
is set in the environment.
|
||||
|
||||
CD dir
|
||||
Change the current directory to dir.
|
||||
|
||||
|
||||
Also see the help topic:
|
||||
|
||||
statement flow control and declaration statements
|
||||
usage for -m modes
|
267
help/config
Normal file
267
help/config
Normal file
@@ -0,0 +1,267 @@
|
||||
Configuration parameters
|
||||
|
||||
Configuration parameters affect how the calculator performs certain
|
||||
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
|
||||
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
|
||||
|
||||
"trace" turns tracing features on or off
|
||||
"display" sets number of digits in prints.
|
||||
"epsilon" sets error value for transcendentals.
|
||||
"maxprint" sets maximum number of elements printed.
|
||||
"mode" sets 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 '~'
|
||||
"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
|
||||
"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 .5000
|
||||
"maxerr" maximum number of scan errors before abort
|
||||
"prompt" default interactive prompt
|
||||
"more" default interactive multi-line input prompt
|
||||
|
||||
|
||||
The "all" config value allows one to save/restore the configuration
|
||||
set of values. The return of:
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
set the backward compatible standard configuration:
|
||||
|
||||
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")
|
||||
|
||||
The "newstd" is not backward compatible with the historic
|
||||
configuration. Even so, some people prefer this configuration
|
||||
and place the config("all", "newstd") command in their CALCRC
|
||||
startup files.
|
||||
|
||||
When nonzero, the "trace" parameter activates one or more features
|
||||
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
|
||||
|
||||
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.
|
||||
|
||||
8: the opcodes for a new functions are displayed when the function
|
||||
is successfully defined.
|
||||
|
||||
The "display" parameter specifies the maximum number of digits after
|
||||
the decimal point to be printed in real or exponential mode in
|
||||
normal unformatted printing (print, strprint, fprint) or in
|
||||
formatted printing (printf, strprintf, fprintf) when precision is not
|
||||
specified. The initial value is 20. This parameter does not change
|
||||
the stored value of a number. Where rounding is necessary, the type
|
||||
of rounding to be used is controlled by "outround".
|
||||
|
||||
The "epsilon" parameter specifies the default accuracy for the
|
||||
calculation of functions for which exact values are not possible or
|
||||
not desired. For most functions, the
|
||||
|
||||
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
|
||||
absolute value of the remainder usually does not exceed epsilon/2.
|
||||
Functions which require an epsilon value accept an
|
||||
optional argument which overrides this default epsilon value for
|
||||
that single call. (The value v can be assigned to the "epsilon"
|
||||
parameter by epsilon(v) as well as by config("epsilon", v), and the
|
||||
current value obtained by epsilon() as well as by config("epsilon").)
|
||||
For the transcendental functions and the functions sqrt() and
|
||||
appr(), the calculated value is always a multiple of epsilon.
|
||||
|
||||
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:
|
||||
|
||||
"frac" decimal fractions
|
||||
"int" decimal integer
|
||||
"real" decimal floating point
|
||||
"exp" decimal exponential
|
||||
"hex" hex fractions
|
||||
"oct" octal fractions
|
||||
"bin" binary fractions
|
||||
|
||||
|
||||
The "maxprint" parameter specifies the maximum number of elements to
|
||||
be displayed when a matrix or list is printed. The initial value is 16.
|
||||
|
||||
Mul2 and sq2 specify the sizes of numbers at which calc switches
|
||||
from its first to its second algorithm for multiplying and squaring.
|
||||
The first algorithm is the usual method of cross multiplying, which
|
||||
runs in a time of O(N^2). The second method is a recursive and
|
||||
complicated method which runs in a time of O(N^1.585). The argument
|
||||
for these parameters is the number of binary words at which the
|
||||
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
|
||||
1000000 is used, then the recursive algorithm is never used, causing
|
||||
calculations for large numbers to slow down. For a typical example
|
||||
on a 386, the two algorithms are about equal in speed for a value
|
||||
of 20, which is about 100 decimal digits. A value of zero resets
|
||||
the parameter back to its default value. Usually there is no need
|
||||
to change these parameters.
|
||||
|
||||
Pow2 specifies the sizes of numbers at which calc switches from
|
||||
its first to its second algorithm for calculating powers modulo
|
||||
another number. The first algorithm for calculating modular powers
|
||||
is by repeated squaring and multiplying and dividing by the modulus.
|
||||
The second method uses the REDC algorithm given by Peter Montgomery
|
||||
which avoids divisions. The argument for pow2 is the size of the
|
||||
modulus at which the second algorithm begins to be used.
|
||||
|
||||
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
|
||||
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
|
||||
which the second algorithm begins to be used.
|
||||
|
||||
Config("tilde") controls whether or not a leading tilde ('~') is
|
||||
printed to indicate that a number has not been printed exactly
|
||||
because the number of decimal digits required would exceed the
|
||||
specified maximum number. The initial "tilde" value is 1.
|
||||
|
||||
Config ("tab") controls the printing of a tab before results
|
||||
automatically displayed when working interactively. It does not
|
||||
affect the printing by the functions print, printf, etc. The inital
|
||||
"tab" value is 1.
|
||||
|
||||
The "quomod", "quo", "mod", "sqrt", "appr", "cfappr", "cfsim", and
|
||||
"round" control the way in which any necessary rounding occurs.
|
||||
Rounding occurs when for some reason, a calculated or displayed
|
||||
value (the "approximation") has to differ from the "true value",
|
||||
e.g. for quomod and quo, the quotient is to be an integer, for sqrt
|
||||
and appr, the approximation is to be a multiple of an explicit or
|
||||
implicit "epsilon", for round and bround (both controlled by
|
||||
config("round")) the number of decimal places or fractional bits
|
||||
in the approximation is limited. Zero value for any of these
|
||||
parameters indicates that the true value is greater than the approximation,
|
||||
i.e. the rounding is "down", or in the case of mod, that the
|
||||
residue has the same sign as the divisor. If bit 4 of the
|
||||
parameter is set, the rounding of to the nearest acceptable candidate
|
||||
when this is uniquely determined; in the remaining ambiguous cases,
|
||||
the type of rounding is determined by the lower bits of the parameter
|
||||
value. If bit 3 is set, the rounding for quo, appr and sqrt,
|
||||
is to the nearest even integer or the nearest even multiple of epsilon,
|
||||
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 2 is irrelevant for the functions round and bround since the
|
||||
equivalent epsilon (a power of 1/10 or 1/2) is always positive.)
|
||||
|
||||
For quomod, the quotient is rounded to an integer value as if
|
||||
evaluating quo with config("quo") == config("quomod"). Similarly,
|
||||
quomod and mod give the same residues if config("mod") == config("quomod").
|
||||
|
||||
For the sqrt function, if bit 5 of config("sqrt") is set, the exact
|
||||
square-root is returned when this is possible; otherwise the
|
||||
result is rounded to a multiple of epsilon as determined by the
|
||||
five lower order bits. Bit 6 of config("sqrt") controls whether the
|
||||
principal or non-principal square-root is returned.
|
||||
|
||||
For the functions cfappr and cfsim, whether the "rounding" is down
|
||||
or up, etc. is controlled by the appropriate bits of config("cfappr")
|
||||
and config("cfsim") as for quomod, quo, etc.
|
||||
|
||||
The "outround" parameter determines the type of rounding to be used
|
||||
by the various kinds of printing to the output: bits 0, 1, 3 and 4
|
||||
are used in the same way as for the functions round and bround.
|
||||
|
||||
The "leadzero" parameter controls whether or not a 0 is printed
|
||||
before the decimal point in non-zero fractions with absolute value
|
||||
less than 1, e.g. whether 1/2 is printed as 0.5 or .5. The
|
||||
initial value is 0, corresponding to the printing .5.
|
||||
|
||||
The "fullzero" parameter controls whether or not in decimal floating-
|
||||
point printing, the digits are padded with zeros to reach the
|
||||
number of digits specified by config("display") or by a precision
|
||||
specification in formatted printing. The initial value for this
|
||||
parameter is 0, so that, for example, if config("display") >= 2,
|
||||
5/4 will print in "real" mode as 1.25.
|
||||
|
||||
The maxerr value controls how many scan errors are allowed
|
||||
before the compiling phase of a computation is aborted. The initial
|
||||
value of "maxerr" is 20. Setting maxerr to 0 disables this feature.
|
||||
|
||||
The default prompt when in teractive mode is "> ". One may change
|
||||
this prompt to a more cut-and-paste friendly prompt by:
|
||||
|
||||
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
|
||||
leading ';' will be ignored.
|
||||
|
||||
When inside multi-line input, the more prompt is used. One may
|
||||
change it by:
|
||||
|
||||
config("more", ";; ")
|
||||
|
||||
The following are synonyms for true:
|
||||
|
||||
"on" "yes" "y" "true" "t" "1" any non-zero number
|
||||
|
||||
The following are synonyms for false:
|
||||
|
||||
"off" "no" "n" "false" "f" "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("tab", "off") disable leading tab printing
|
35
help/conj
Normal file
35
help/conj
Normal file
@@ -0,0 +1,35 @@
|
||||
NAME
|
||||
conj - complex conjugate
|
||||
|
||||
SYNOPSIS
|
||||
conj(x)
|
||||
|
||||
TYPES
|
||||
If x is an object of type xx, conj(x) calls xx_conj(x).
|
||||
|
||||
For non-object x:
|
||||
|
||||
x real, complex, or matrix
|
||||
|
||||
return real, complex, or matrix
|
||||
|
||||
DESCRIPTION
|
||||
For real x, conj(x) returns x.
|
||||
|
||||
For complex x, conj(x) returns re(x) - im(x) * 1i.
|
||||
|
||||
For matrix x, conj(x) returns a matrix of the same structure as x
|
||||
in which each element t of x has been replaced by conj(t).
|
||||
|
||||
EXAMPLE
|
||||
> print conj(3), conj(3 + 4i)
|
||||
3 3-4i
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
void conjvalue(VALUE *x, *res)
|
||||
|
||||
SEE ALSO
|
||||
norm, abs, arg
|
36
help/cos
Normal file
36
help/cos
Normal file
@@ -0,0 +1,36 @@
|
||||
NAME
|
||||
cos - cosine
|
||||
|
||||
SYNOPSIS
|
||||
cos(x [,eps])
|
||||
|
||||
TYPES
|
||||
x number (real or complex)
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return number
|
||||
|
||||
DESCRIPTION
|
||||
Calculate the cosine of x to a multiple of eps with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
EXAMPLE
|
||||
> print cos(1, 1e-5), cos(1, 1e-10), cos(1, 1e-15), cos(1, 1e-20)
|
||||
.5403 .5403023059 .54030230586814 .5403023058681397174
|
||||
|
||||
> print cos(2 +3i, 1e-5), cos(2 + 3i, 1e-10)
|
||||
-4.18963-9.10923i -4.189625691-9.1092278938i
|
||||
|
||||
> pi = pi(1e-20)
|
||||
> print cos(pi/3, 1e-10), cos(pi/2, 1e-10), cos(pi, 1e-10)
|
||||
.5 0 -1
|
||||
|
||||
LIMITS
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qcos(NUMBER *x, NUMBER *eps)
|
||||
COMPLEX *ccos(COMPLEX *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
sin, tan, sec, csc, cot, epsilon
|
31
help/cosh
Normal file
31
help/cosh
Normal file
@@ -0,0 +1,31 @@
|
||||
NAME
|
||||
cosh - hyperbolic cosine
|
||||
|
||||
SYNOPSIS
|
||||
cosh(x [,eps])
|
||||
|
||||
TYPES
|
||||
x real
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Calculate the cosh of x to the nearest or next to nearest multiple of
|
||||
epsilon, with absolute error less than .75 * abs(eps).
|
||||
|
||||
cosh(x) = (exp(x) + exp(-x))/2
|
||||
|
||||
EXAMPLE
|
||||
> print cosh(1, 1e-5), cosh(1, 1e-10), cosh(1, 1e-15), cosh(1, 1e-20)
|
||||
1.54308 1.5430806348 1.543080634815244 1.54308063481524377848
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qcosh(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
sinh, tanh, sech, csch, coth, epsilon
|
30
help/cot
Normal file
30
help/cot
Normal file
@@ -0,0 +1,30 @@
|
||||
NAME
|
||||
cot - trigonometric cotangent
|
||||
|
||||
SYNOPSIS
|
||||
cot(x [,eps])
|
||||
|
||||
TYPES
|
||||
x nonzero real
|
||||
acc nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Calculate the cotangent of x to a multiple of eps, with error less
|
||||
in absolute value than .75 * eps.
|
||||
|
||||
EXAMPLE
|
||||
> print cot(1, 1e-5), cot(1, 1e-10), cot(1, 1e-15), cot(1, 1e-20)
|
||||
.64209 .6420926159 .642092615934331 .64209261593433070301
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
x != 0
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qcot(NUMBER *x, *eps)
|
||||
|
||||
SEE ALSO
|
||||
sin, cos, tan, sec, csc, epsilon
|
32
help/coth
Normal file
32
help/coth
Normal file
@@ -0,0 +1,32 @@
|
||||
NAME
|
||||
coth - hyperbolic cotangent
|
||||
|
||||
SYNOPSIS
|
||||
coth(x [,eps])
|
||||
|
||||
TYPES
|
||||
x nonzero real
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Calculate the coth of x to a multiple of eps with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
coth(x) = (exp(2*x) + 1)/(exp(2*x) - 1)
|
||||
|
||||
EXAMPLE
|
||||
> print coth(1, 1e-5), coth(1, 1e-10), coth(1, 1e-15), coth(1, 1e-20)
|
||||
1.31304 1.3130352855 1.313035285499331 1.31303528549933130364
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
x != 0
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qcoth(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
sinh, cosh, tanh, sech, csch, epsilon
|
31
help/count
Normal file
31
help/count
Normal file
@@ -0,0 +1,31 @@
|
||||
NAME
|
||||
count - count elements of list or matrix satisfying a stated condition
|
||||
|
||||
SYNOPSIS
|
||||
count(x, y)
|
||||
|
||||
TYPES
|
||||
x list or matrix
|
||||
y string
|
||||
|
||||
return int
|
||||
|
||||
DESCRIPTION
|
||||
For count(x, y), y is to be the name of a user-defined function;
|
||||
count(x,y) then returns the number of elements of x for which y
|
||||
tests as "true".
|
||||
|
||||
EXAMPLE
|
||||
> define f(a) = (a < 5)
|
||||
> A = list(1,2,7,6,4,8)
|
||||
> count(A, "f")
|
||||
3
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
XXX - fill in
|
37
help/cp
Normal file
37
help/cp
Normal file
@@ -0,0 +1,37 @@
|
||||
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
|
||||
x 1-dimensional matrix with 3 elements
|
||||
y 1-dimensional matrix with 3 elements
|
||||
|
||||
LIBRARY
|
||||
MATRIX *matcross(MATRIX *x, MATRIX *y)
|
||||
|
||||
SEE ALSO
|
||||
dp
|
62
help/credit
Normal file
62
help/credit
Normal file
@@ -0,0 +1,62 @@
|
||||
Credits
|
||||
|
||||
The majority of calc was written by David I. Bell.
|
||||
|
||||
Calc archives and calc-tester mailing list maintained by Landon Curt Noll.
|
||||
|
||||
Thanks for suggestions and encouragement from Peter Miller,
|
||||
Neil Justusson, and Landon Noll.
|
||||
|
||||
Thanks to Stephen Rothwell for writing the original version of
|
||||
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
|
||||
this was in terms of actual code which I gratefully accepted.
|
||||
Ernest also supplied the original text for many of the help files.
|
||||
|
||||
Portions of this program are derived from an earlier set of
|
||||
public domain arbitrarily precision routines which was posted
|
||||
to the net around 1984. By now, there is almost no recognizable
|
||||
code left from that original source.
|
||||
|
||||
Most of this source and binary has one of the following copyrights:
|
||||
|
||||
Copyright (c) 19xx David I. Bell
|
||||
Copyright (c) 19xx David I. Bell and Landon Curt Noll
|
||||
Copyright (c) 19xx Landon Curt Noll
|
||||
Copyright (c) 19xx Ernest Bowen and Landon Curt Noll
|
||||
|
||||
Permission is granted to use, distribute, or modify this source,
|
||||
provided that this copyright notice remains intact.
|
||||
|
||||
Send calc comments, suggestions, bug fixes, enhancements and
|
||||
interesting calc scripts that you would like you see included in
|
||||
future distributions to:
|
||||
|
||||
dbell@auug.org.au
|
||||
chongo@toad.com
|
||||
|
||||
Landon Noll maintains the official calc ftp archive at:
|
||||
|
||||
ftp://ftp.uu.net/pub/calc
|
||||
|
||||
Alpha test versions, complete with bugs, untested code and
|
||||
experimental features may be fetched (if you are brave) under:
|
||||
|
||||
http://reality.sgi.com/chongo/calc/
|
||||
|
||||
One may join the calc testing group by sending a request to:
|
||||
|
||||
calc-tester-request@postofc.corp.sgi.com
|
||||
|
||||
Your message body (not the subject) should consist of:
|
||||
|
||||
subscribe calc-tester address
|
||||
end
|
||||
name your_full_name
|
||||
|
||||
where "address" is your EMail address and "your_full_name"
|
||||
is your full name.
|
||||
|
||||
Enjoy!
|
29
help/csc
Normal file
29
help/csc
Normal file
@@ -0,0 +1,29 @@
|
||||
NAME
|
||||
csc - trigonometric cosecant function
|
||||
|
||||
SYNOPSIS
|
||||
csc(x [,eps])
|
||||
|
||||
TYPES
|
||||
x real
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Calculate the cosecant of x to a multiple of eps, with error less
|
||||
in absolute value than .75 * eps.
|
||||
|
||||
EXAMPLE
|
||||
> print csc(1, 1e-5), csc(1, 1e-10), csc(1, 1e-15), csc(1, 1e-20)
|
||||
1.1884 1.1883951058 1.188395105778121 1.18839510577812121626
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qcsc(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
sin, cos, tan, sec, cot, epsilon
|
32
help/csch
Normal file
32
help/csch
Normal file
@@ -0,0 +1,32 @@
|
||||
NAME
|
||||
csch - hyperbolic cosecant
|
||||
|
||||
SYNOPSIS
|
||||
csch(x [,eps])
|
||||
|
||||
TYPES
|
||||
x nonzero real
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real
|
||||
|
||||
DESCRIPTION
|
||||
Calculate the csch of x to a multiple of epsilon, with error less in
|
||||
absolute value than .75 * eps.
|
||||
|
||||
csch(x) = 2/(exp(x) - exp(-x))
|
||||
|
||||
EXAMPLE
|
||||
> print csch(1, 1e-5), csch(1, 1e-10), csch(1, 1e-15), csch(1, 1e-20)
|
||||
.85092 .8509181282 .850918128239322 .85091812823932154513
|
||||
|
||||
LIMITS
|
||||
unlike sin and cos, x must be real
|
||||
x != 0
|
||||
eps > 0
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qcsch(NUMBER *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
sinh, cosh, tanh, sech, coth, epsilon
|
29
help/ctime
Normal file
29
help/ctime
Normal file
@@ -0,0 +1,29 @@
|
||||
NAME
|
||||
ctime - current local time
|
||||
|
||||
SYNOPSIS
|
||||
ctime()
|
||||
|
||||
TYPES
|
||||
return string
|
||||
|
||||
DESCRIPTION
|
||||
The ctime() builtin returns the string formed by the first 24
|
||||
characters returned by the C library function, ctime():
|
||||
|
||||
"Mon Oct 28 00:47:00 1996"
|
||||
|
||||
The 25th ctime() character, '\n' is removed.
|
||||
|
||||
EXAMPLE
|
||||
> printf("The time is now %s.\n", time())
|
||||
The time is now Mon Apr 15 12:41:44 1996.
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
runtime, time
|
68
help/define
Normal file
68
help/define
Normal file
@@ -0,0 +1,68 @@
|
||||
Function definitions
|
||||
|
||||
Function definitions are introduced by the 'define' keyword.
|
||||
Other than this, the basic structure of a function is like in C.
|
||||
That is, parameters are specified for the function within parenthesis,
|
||||
the function body is introduced by a left brace, variables are
|
||||
declared for the function, statements implementing the function
|
||||
follow, and the function is ended with a right brace.
|
||||
|
||||
There are some subtle differences, however. The types of parameters
|
||||
and variables are not defined at compile time, but instead are typed
|
||||
at runtime. Thus there is no definitions needed to distinguish
|
||||
between integers, fractions, complex numbers, matrices, and so on.
|
||||
Thus when declaring parameters for a function, only the name of
|
||||
the parameter is needed. Thus there are never any declarations
|
||||
between the function parameter list and the body of the function.
|
||||
|
||||
For example, the following function computes a factorial:
|
||||
|
||||
define factorial(n)
|
||||
{
|
||||
local ans;
|
||||
|
||||
ans = 1;
|
||||
while (n > 1)
|
||||
ans *= n--;
|
||||
return ans;
|
||||
}
|
||||
|
||||
If a function is very simple and just returns a value, then the
|
||||
function can be defined in shortened manner by using an equals sign
|
||||
in place of the left brace. In this case, the function declaration
|
||||
is terminated by a newline character, and its value is the specified
|
||||
expression. Statements such as 'if' are not allowed. An optional
|
||||
semicolon ending the expression is allowed. As an example, the
|
||||
average of two numbers could be defined as:
|
||||
|
||||
define average(a, b) = (a + b) / 2;
|
||||
|
||||
Functions can be defined which can be very complex. These can be
|
||||
defined on the command line if desired, but editing of partial
|
||||
functions is not possible past a single line. If an error is made
|
||||
on a previous line, then the function must be finished (with probable
|
||||
errors) and reentered from the beginning. Thus for complicated
|
||||
functions, it is best to use an editor to create the function in a
|
||||
file, and then enter the calculator and read in the file containing
|
||||
the definition.
|
||||
|
||||
The parameters of a function can be referenced by name, as in
|
||||
normal C usage, or by using the 'param' function. This function
|
||||
returns the specified parameter of the function it is in, where
|
||||
the parameters are numbered starting from 1. The total number
|
||||
of parameters to the function is returned by using 'param(0)'.
|
||||
Using this function allows you to implement varargs-like routines
|
||||
which can handle any number of calling parameters. For example:
|
||||
|
||||
define sc()
|
||||
{
|
||||
local s, i;
|
||||
|
||||
s = 0;
|
||||
for (i = 1; i <= param(0); i++)
|
||||
s += param(i)^3;
|
||||
return s;
|
||||
}
|
||||
|
||||
defines a function which returns the sum of the cubes of all it's
|
||||
parameters.
|
44
help/delete
Normal file
44
help/delete
Normal file
@@ -0,0 +1,44 @@
|
||||
NAME
|
||||
delete - delete an element from a list at a given position
|
||||
|
||||
SYNOPSIS
|
||||
delete(lst, idx)
|
||||
|
||||
TYPES
|
||||
lst list, &list
|
||||
idx int, &int
|
||||
|
||||
return any
|
||||
|
||||
DESCRIPTION
|
||||
Delete element at index idx from list lst.
|
||||
|
||||
The index must refer to an element in the list. That is, idx must
|
||||
be in the range [0, size(lst)-1].
|
||||
|
||||
EXAMPLE
|
||||
> lst = list(2,3,4,5)
|
||||
|
||||
list (4 elements, 4 nonzero):
|
||||
[[0]] = 2
|
||||
[[1]] = 3
|
||||
[[2]] = 4
|
||||
[[3]] = 5
|
||||
|
||||
> delete(lst, 2)
|
||||
4
|
||||
> print lst
|
||||
|
||||
list (3 elements, 3 nonzero):
|
||||
[[0]] = 2
|
||||
[[1]] = 3
|
||||
[[2]] = 5
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
append, insert, islist, list, pop, push, remove, rsearch, search, size
|
38
help/den
Normal file
38
help/den
Normal file
@@ -0,0 +1,38 @@
|
||||
NAME
|
||||
den - denominator of a real number
|
||||
|
||||
SYNOPSIS
|
||||
den(x)
|
||||
|
||||
TYPES
|
||||
x real
|
||||
|
||||
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
|
||||
|
||||
where:
|
||||
|
||||
n and d are integers
|
||||
gcd(n,d) == 1
|
||||
d > 0
|
||||
|
||||
If x = n/x, then den(x) == d.
|
||||
|
||||
EXAMPLE
|
||||
> print den(7), den(-1.25), den(121/33)
|
||||
1 4 3
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qden(NUMBER *x)
|
||||
|
||||
SEE ALSO
|
||||
num
|
74
help/det
Normal file
74
help/det
Normal file
@@ -0,0 +1,74 @@
|
||||
NAME
|
||||
det - determinant
|
||||
|
||||
SYNOPSIS
|
||||
det(m)
|
||||
|
||||
TYPES
|
||||
m square matrix with elements of suitable type
|
||||
|
||||
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).
|
||||
|
||||
If the elements of m are numbers (real or complex), det(m)
|
||||
returns the value of the determinant of m.
|
||||
|
||||
If some or all of the elements of m are not numbers, the algorithm
|
||||
used to evaluate det(m) assumes the definitions of *, unary -, binary -,
|
||||
being zero or nonzero, are consistent with commutative ring structure,
|
||||
and if the m is larger than 2 x 2, division by nonzero elements is
|
||||
consistent with integral-domain structure.
|
||||
|
||||
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).
|
||||
|
||||
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.
|
||||
|
||||
EXAMPLE
|
||||
> mat A[3,3] = {2, 3, 5, 7, 11, 13, 17, 19, 23}
|
||||
> c = config("mode", "frac")
|
||||
> print det(A), det(A^2), det(A^3), det(A^-1)
|
||||
-78 6084 -474552 -1/78
|
||||
|
||||
> obj res {r}
|
||||
> global md
|
||||
> define res_test(a) = !ismult(a.r, md)
|
||||
> define res_sub(a,b) {local obj res v = {(a.r - b.r) % md}; return v;}
|
||||
> define res_mul(a,b) {local obj res v = {(a.r * b.r) % md}; return v;}
|
||||
> define res_neg(a) {local obj res v = {(-a.r) % md}; return v;}
|
||||
> define res(x) {local obj res v = {x % md}; return v;}
|
||||
> md = 0
|
||||
> mat A[2,2] = {res(2), res(3), res(5), res(7)}
|
||||
> md = 5
|
||||
> print det(A)
|
||||
obj res {4}
|
||||
> md = 6
|
||||
> print det(A)
|
||||
obj res {5}
|
||||
|
||||
Note that if A had been a 3 x 3 or larger matrix, res_div(a,b) for
|
||||
non-zero b would have had to be defined (assuming at least one
|
||||
division is necessary); for consistent results when md is composite,
|
||||
res_div(a,b) should be defined only when b and md are relatively
|
||||
prime; there is no problem when md is prime.
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
VALUE matdet(MATRIX *m)
|
||||
|
||||
SEE ALSO
|
||||
matdim, matmax, matmin, inverse
|
38
help/digit
Normal file
38
help/digit
Normal file
@@ -0,0 +1,38 @@
|
||||
NAME
|
||||
digit - digit at specified position in a decimal representation
|
||||
|
||||
SYNOPSIS
|
||||
digit(x, y)
|
||||
|
||||
TYPES
|
||||
x real
|
||||
y integer
|
||||
|
||||
return integer
|
||||
|
||||
DESCRIPTION
|
||||
By extending the digits on the left, and if necessary, the digits
|
||||
on the right, by infinite strings of zeros, abs(x) may be considered
|
||||
to have the decimal representation:
|
||||
|
||||
... d_2 d_1 d_0.d_-1 d_-2 ...
|
||||
|
||||
digit(x,y) then returns the digit d_y.
|
||||
|
||||
EXAMPLE
|
||||
> x = 12.34
|
||||
> print digit(x,2), digit(x,1), digit(x,0), digit(x,-1), digit(x,-2)
|
||||
0 1 2 3 4
|
||||
|
||||
> x = 10/7
|
||||
> print digit(x,1), digit(x,0), digit(x,-1), digit(x,-2), digit(x,-3)
|
||||
0 1 4 2 8
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
long qdigit(NUMBER *x, long y)
|
||||
|
||||
SEE ALSO
|
||||
bit
|
27
help/digits
Normal file
27
help/digits
Normal file
@@ -0,0 +1,27 @@
|
||||
NAME
|
||||
digits - return number of digits in an integer or integer part
|
||||
|
||||
SYNOPSIS
|
||||
digits(x)
|
||||
|
||||
TYPES
|
||||
x real
|
||||
|
||||
return integer
|
||||
|
||||
DESCRIPTION
|
||||
For real x, digits(x) returns the number of digits in the decimal
|
||||
representation of int(abs(x)).
|
||||
|
||||
EXAMPLE
|
||||
> print digits(0), digits(0.0123), digits(3.7), digits(-27), digits(-99.7)
|
||||
1 1 1 2 2
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
long qdigits(NUMBER *x)
|
||||
|
||||
SEE ALSO
|
||||
places
|
38
help/dp
Normal file
38
help/dp
Normal file
@@ -0,0 +1,38 @@
|
||||
NAME
|
||||
dp - dot product of two vectors
|
||||
|
||||
SYNOPSIS
|
||||
dp(x, y)
|
||||
|
||||
TYPES
|
||||
x, y 1-dimensional matrices with the same number of elements
|
||||
|
||||
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}
|
||||
|
||||
Then dp(x,y) returns the result of the calculation:
|
||||
|
||||
x0*y0 + x1*y1 + ... + xn*yn
|
||||
|
||||
EXAMPLE
|
||||
> mat x[3] = {2,3,4}
|
||||
> mat y[3] = {3,4,5}
|
||||
> print dp(x,y)
|
||||
38
|
||||
|
||||
LIMITS
|
||||
x and y are 1-dimensional matrices
|
||||
x and y have the same number of elements
|
||||
|
||||
LIBRARY
|
||||
VALUE matdot(MATRIX *x, MATRIX *y)
|
||||
|
||||
SEE ALSO
|
||||
cp
|
86
help/environment
Normal file
86
help/environment
Normal file
@@ -0,0 +1,86 @@
|
||||
Environment variables
|
||||
|
||||
CALCPATH
|
||||
|
||||
A :-separated list of directories used to search for
|
||||
scripts filenames that do not begin with /, ./ or ~.
|
||||
|
||||
If this variable does not exist, a compiled value
|
||||
is used. Typically compiled in value is:
|
||||
|
||||
.:./lib:~/lib:${LIBDIR}/calc
|
||||
|
||||
where ${LIBDIR} is usually:
|
||||
|
||||
/usr/local/lib/calc
|
||||
|
||||
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.
|
||||
|
||||
|
||||
CALCRC
|
||||
|
||||
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, a compiled value
|
||||
is used. Typically compiled in value is:
|
||||
|
||||
${LIBDIR}/startup:~/.calcrc
|
||||
|
||||
where ${LIBDIR} is usually:
|
||||
|
||||
/usr/local/lib/calc
|
||||
|
||||
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.
|
||||
|
||||
If this variable does not exist, a compiled value is used.
|
||||
Typically compiled in value is:
|
||||
|
||||
bindings
|
||||
or:
|
||||
altbind (bindings where ^D means exit)
|
||||
|
||||
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.
|
||||
|
||||
HOME
|
||||
|
||||
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, 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.
|
||||
|
||||
If this variable does not exist, 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.
|
||||
|
||||
If this variable does not exist, a compiled value
|
||||
is used. Typically compiled in value is something
|
||||
such as 'sh' is used.
|
34
help/epsilon
Normal file
34
help/epsilon
Normal file
@@ -0,0 +1,34 @@
|
||||
NAME
|
||||
epsilon - set or read the stored epsilon value
|
||||
|
||||
SYNOPSIS
|
||||
epsilon([eps])
|
||||
|
||||
TYPES
|
||||
eps 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.
|
||||
|
||||
With one arg, epsilon(eps) returns the current epsilon value
|
||||
and sets the stored epsilon value to eps.
|
||||
|
||||
The stored epsilon value is used as default value for eps in
|
||||
the functions appr(x, eps, rnd), sqrt(x, eps, rnd), etc.
|
||||
|
||||
EXAMPLE
|
||||
> oldeps = epsilon(1e-6)
|
||||
> print epsilon(), sqrt(2), epsilon(1e-4), sqrt(2), epsilon(oldeps)
|
||||
> .000001 1.414214 .000001 1.4142 .0001
|
||||
|
||||
LIMITS
|
||||
0 < eps < 1
|
||||
|
||||
LIBRARY
|
||||
void setepsilon(NUMBER *eps)
|
||||
NUMBER *_epsilon_
|
||||
|
||||
SEE ALSO
|
||||
XXX - fill in
|
38
help/errno
Normal file
38
help/errno
Normal file
@@ -0,0 +1,38 @@
|
||||
NAME
|
||||
errno - return a system error message
|
||||
|
||||
SYNOPSIS
|
||||
errno(errnum)
|
||||
|
||||
TYPES
|
||||
errnum int
|
||||
|
||||
return string
|
||||
|
||||
DESCRIPTION
|
||||
If a file builtin function such as fopen() encounters an error,
|
||||
it will return an errno number. This function will convert this
|
||||
number into a somewhat more meaningful string.
|
||||
|
||||
Note that errno() may return different strings on different systems.
|
||||
|
||||
EXAMPLE
|
||||
> badfile = fopen("not_a_file", "r")
|
||||
> if (!isfile(badfile)) print "error #" : badfile : ":", errno(badfile);
|
||||
error #2: No such file or directory
|
||||
|
||||
> print errno(13)
|
||||
Permission denied
|
||||
|
||||
> errno(31)
|
||||
"Too many links"
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, files, fopen,
|
||||
fprintf, isfile, printf, prompt
|
28
help/error
Normal file
28
help/error
Normal file
@@ -0,0 +1,28 @@
|
||||
NAME
|
||||
error - generate a value of an error type
|
||||
|
||||
SYNOPSIS
|
||||
error(n)
|
||||
|
||||
TYPES
|
||||
n integer less than 32768
|
||||
|
||||
return null value or error value
|
||||
|
||||
DESCRIPTION
|
||||
If n is zero or negative, error(n) returns the null value.
|
||||
For positive n, error(n) returns a value of error type n.
|
||||
|
||||
EXAMPLE
|
||||
> a = error(10009)
|
||||
a
|
||||
Error 10009
|
||||
|
||||
LIMITS
|
||||
0 <= n < 32768
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
errorcodes, iserror
|
2
help/errorcodes.hdr
Normal file
2
help/errorcodes.hdr
Normal file
@@ -0,0 +1,2 @@
|
||||
Calc generated error codes (see the error help file):
|
||||
|
1
help/errorcodes.sed
Normal file
1
help/errorcodes.sed
Normal file
@@ -0,0 +1 @@
|
||||
/^#define E_[^_].*[ ][1-9][0-9]*[ ]\/\* .* \*\//s/#define E_.*[ ]\([1-9][0-9]*\)[ ]*\/\* \(.*\)[ ][ ]*\*\// \1 \2/p
|
61
help/eval
Normal file
61
help/eval
Normal file
@@ -0,0 +1,61 @@
|
||||
NAME
|
||||
eval - evaluate a string
|
||||
|
||||
SYNOPSIS
|
||||
eval(str)
|
||||
|
||||
TYPES
|
||||
str string
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||
If str is the empty string "", eval(str) returns the null value.
|
||||
|
||||
The call to eval(str) may return a value by explicit use of a return
|
||||
statement: "return;" returns the null value, "return expr;" returns the
|
||||
value of expr. If execution reaches the end of str and the
|
||||
value on the execution stack is not null, eval(str) returns that value;
|
||||
otherwise eval(str) returns the most recently saved value.
|
||||
|
||||
Each time eval(str) is called, a temporary function is compiled from
|
||||
the commands in str, and if there are no syntax errors, this function
|
||||
is then evaluated. If str contains syntax errors, eval(str) displays
|
||||
the scanerror messages and returns the value error(49).
|
||||
|
||||
EXAMPLE
|
||||
> str1 = "2 + 3"; print eval(str1);
|
||||
5
|
||||
|
||||
> i = 10; str2 = "local i = 0; 7; while (i++ < 5) print i^2,:;"
|
||||
> print i, eval(str2), i
|
||||
10 1 4 9 16 25 7 10
|
||||
|
||||
(The print statements in str2 return the null value, so execution of
|
||||
eval(str2) ends by returning the saved value 7. The global variable
|
||||
i is unchanged.)
|
||||
|
||||
> eval("2 + ");
|
||||
Missing expression
|
||||
49
|
||||
|
||||
LIMITS
|
||||
The string str in eval(str) should not include a call to itself as in
|
||||
|
||||
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
|
||||
to eval(str1), etc.
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
XXX = fill in
|
41
help/exp
Normal file
41
help/exp
Normal file
@@ -0,0 +1,41 @@
|
||||
NAME
|
||||
exp - exponential function
|
||||
|
||||
SYNOPSIS
|
||||
exp(x [,eps])
|
||||
|
||||
TYPES
|
||||
x real or complex
|
||||
eps nonzero real, defaults to epsilon()
|
||||
|
||||
return real or complex
|
||||
|
||||
DESCRIPTION
|
||||
Approximate the exponential function of x by a multiple of epsilon,
|
||||
the error having absolute value less than 0.75 * eps.
|
||||
If n is a positive integer, exp(x, 10^-n) will usually be
|
||||
correct to the n-th decimal place, which, for large positive x
|
||||
will give many significant figures.
|
||||
|
||||
EXAMPLE
|
||||
> print exp(2, 1e-5), exp(2,1e-10), exp(2, 1e-15), exp(2, 1e-20)
|
||||
7.38906 7.3890560989 7.38905609893065 7.38905609893065022723
|
||||
|
||||
> print exp(30, 1e5), exp(30, 1), exp(30, 1e-10)
|
||||
10686474600000 10686474581524 10686474581524.4621469905
|
||||
|
||||
> print exp(-20, 1e-5), exp(-20, 1e-10), exp(-20, 1e-15), exp(-20, 1e-20)
|
||||
0 .0000000021 .000000002061154 .00000000206115362244
|
||||
|
||||
> print exp(1+2i, 1e-5), exp(1+2i, 1e-10)
|
||||
-1.1312+2.47173i -1.1312043838+2.471726672i
|
||||
|
||||
LIMITS
|
||||
x < 100000
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qexp(NUMBER *x, NUMBER *eps)
|
||||
COMPLEX *cexp(COMPLEX *x, NUMBER *eps)
|
||||
|
||||
SEE ALSO
|
||||
ln, cosh, sinh, tanh
|
35
help/expression
Normal file
35
help/expression
Normal file
@@ -0,0 +1,35 @@
|
||||
Expression sequences
|
||||
|
||||
This is a sequence of statements, of which expression statements
|
||||
are the commonest case. Statements are separated with semicolons,
|
||||
and the newline character generally ends the sequence. If any
|
||||
statement is an expression by itself, or is associated with an
|
||||
'if' statement which is true, then two special things can happen.
|
||||
If the sequence is executed at the top level of the calculator,
|
||||
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
|
||||
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() -
|
||||
|
||||
Variables can be defined at the beginning of an expression sequence.
|
||||
This is most useful for local variables, as in the following example,
|
||||
which sums the square roots of the first few numbers:
|
||||
|
||||
local s, i; s = 0; for (i = 0; i < 10; i++) s += sqrt(i); s
|
||||
|
||||
If a return statement is executed in an expression sequence, then
|
||||
the result of the expression sequence is the returned value. In
|
||||
this case, '.' is set to the value, but nothing is printed.
|
33
help/fact
Normal file
33
help/fact
Normal file
@@ -0,0 +1,33 @@
|
||||
NAME
|
||||
fact - factorial
|
||||
|
||||
SYNOPSIS
|
||||
fact(x)
|
||||
|
||||
TYPES
|
||||
x int
|
||||
|
||||
return int
|
||||
|
||||
DESCRIPTION
|
||||
Return the factorial of a number. Factorial is defined as:
|
||||
|
||||
x! = 1 * 2 * 3 * ... * x-1 * x
|
||||
0! = 1
|
||||
|
||||
EXAMPLE
|
||||
> print fact(10), fact(5), fact(2), fact(1), fact(0)
|
||||
3628800 120 2 1 1
|
||||
|
||||
> print fact(40)
|
||||
815915283247897734345611269596115894272000000000
|
||||
|
||||
LIMITS
|
||||
2^24 > x >= 0
|
||||
y < 2^24
|
||||
|
||||
LIBRARY
|
||||
void zfact(NUMBER x, *ret)
|
||||
|
||||
SEE ALSO
|
||||
comb, perm
|
41
help/factor
Normal file
41
help/factor
Normal file
@@ -0,0 +1,41 @@
|
||||
NAME
|
||||
factor - smallest prime factor not exceeding specified limit
|
||||
|
||||
SYNOPSIS
|
||||
factor(n [, limit [, err]])
|
||||
|
||||
TYPES
|
||||
n integer
|
||||
limit integer with abs(limit) < 2^32, defaults to 2^32 - 1
|
||||
err integer
|
||||
|
||||
return positive integer, -1 or err
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
If n >= 0 and n has a prime factor less than or equal to limit,
|
||||
factor(n, limit) returns the smallest such factor. If n >= 0
|
||||
and the smallest prime factor of n exceeds limit, 1 is returned.
|
||||
In particular, if n >= 0 and limit <= 1, factor(n, limit)
|
||||
always returns 1; factor(n,2) returns 2 if and only if n is even.
|
||||
|
||||
If n < 0, -1 is returned.
|
||||
|
||||
If abs(limit) >= 2^32, factor(n, limit) causes an error,
|
||||
factor(n, limit, err) returns the value of err.
|
||||
|
||||
EXAMPLE
|
||||
> print factor(35,4), factor(35,5), factor(35), factor(-35)
|
||||
1 5 5 -1
|
||||
|
||||
> print factor(2^32 + 1), factor(2^47 - 1), factor(2^59 - 1)
|
||||
641 2351 179951
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
FLAG zfactor(ZVALUE n, ZVALUE limit, ZVALUE *res)
|
||||
|
||||
SEE ALSO
|
||||
lfactor
|
52
help/fclose
Normal file
52
help/fclose
Normal file
@@ -0,0 +1,52 @@
|
||||
NAME
|
||||
fclose - close a file
|
||||
|
||||
SYNOPSIS
|
||||
fclose(fd)
|
||||
|
||||
TYPES
|
||||
fd file
|
||||
|
||||
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
|
||||
action occurs to all copies of the file value. You do not need to
|
||||
explicitly close all the copies of a file value.
|
||||
|
||||
Standard input, standard output and standard error are always opened
|
||||
and cannot be closed.
|
||||
|
||||
The truth value of an closed file is FALSE.
|
||||
|
||||
The fclose function returns the numeric value of errno if
|
||||
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
|
||||
this case.
|
||||
|
||||
EXAMPLE
|
||||
> fd = fopen("/etc/motd", "r")
|
||||
> if (fd) print "file is open";
|
||||
file is open
|
||||
|
||||
> err = fclose(fd);
|
||||
> if (isnull(err)) print "close successful"; else errno(err);
|
||||
close successful
|
||||
|
||||
> if (!fd) print "file is closed";
|
||||
file is closed
|
||||
|
||||
LIMITS
|
||||
fd != files(0) && fd != files(1) && fd != files(2)
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
31
help/fcnt
Normal file
31
help/fcnt
Normal file
@@ -0,0 +1,31 @@
|
||||
NAME
|
||||
fcnt - count of number of times a specified integer divides an integer
|
||||
|
||||
SYNOPSIS
|
||||
fcnt(x,y)
|
||||
|
||||
TYPES
|
||||
x integer
|
||||
y integer
|
||||
|
||||
return non-negative integer
|
||||
|
||||
DESCRIPTION
|
||||
If x is nonzero and abs(y) > 1, fcnt(x,y) returns the greatest
|
||||
non-negative n for which y^n is a divisor of x. In particular,
|
||||
zero is returned if x is not divisible by y.
|
||||
|
||||
If x is zero or if y = -1, 0 or 1, fcnt(x,y) is defined to be zero.
|
||||
|
||||
EXAMPLE
|
||||
> print fcnt(7,4), fcnt(24,4), fcnt(48,4)
|
||||
0 1 2
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
long zfacrem(ZVALUE x, ZVALUE y, ZVALUE *rem)
|
||||
|
||||
SEE ALSO
|
||||
frem, gcdrem
|
44
help/feof
Normal file
44
help/feof
Normal file
@@ -0,0 +1,44 @@
|
||||
NAME
|
||||
feof - determine if end-of-file flag is set
|
||||
|
||||
SYNOPSIS
|
||||
feof(fd)
|
||||
|
||||
TYPES
|
||||
fd file stream open for reading
|
||||
|
||||
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
|
||||
positioning operations (fseek, rewind, fsetpos) and by freopen.
|
||||
|
||||
EXAMPLE
|
||||
> fd1 = fopen("/tmp/newfile", "w")
|
||||
> fputs(fd1, "Chongo was here\n")
|
||||
> fflush(fd1)
|
||||
> fd2 = fopen("/tmp/newfile", "r")
|
||||
> feof(fd2)
|
||||
0
|
||||
> fgetline(fd2)
|
||||
"Chongo was here"
|
||||
> feof(fd2)
|
||||
0
|
||||
> fgetline(fd2)
|
||||
> feof(fd2)
|
||||
1
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
||||
|
33
help/ferror
Normal file
33
help/ferror
Normal file
@@ -0,0 +1,33 @@
|
||||
NAME
|
||||
ferror - determine if an error has occurred for file
|
||||
|
||||
SYNOPSIS
|
||||
ferror(fd)
|
||||
|
||||
TYPES
|
||||
fd file
|
||||
|
||||
return int
|
||||
|
||||
DESCRIPTION
|
||||
This function determines whether the error condition was detected
|
||||
while performing some operation on the file associated with fd.
|
||||
The error need not have been the previous file operation.
|
||||
|
||||
If an error was previously reported 1 will be returned, otherwise
|
||||
0 is returned.
|
||||
|
||||
EXAMPLE
|
||||
> fd = fopen("/etc/motd", "r")
|
||||
> ferror(fd)
|
||||
0
|
||||
|
||||
LIMITS
|
||||
fd must be associaed with an open file
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
28
help/fflush
Normal file
28
help/fflush
Normal file
@@ -0,0 +1,28 @@
|
||||
NAME
|
||||
fflush - flush output to file
|
||||
|
||||
SYNOPSIS
|
||||
fflush(fd)
|
||||
|
||||
TYPES
|
||||
fd file
|
||||
|
||||
return nil
|
||||
|
||||
DESCRIPTION
|
||||
This function forces and buffered output to the file associated with fd.
|
||||
|
||||
EXAMPLE
|
||||
> fd = fopen("/tmp/file", "w")
|
||||
> fputc(fd, "@");
|
||||
> fflush(fd)
|
||||
|
||||
LIMITS
|
||||
fd must be associaed with an open file
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
35
help/fgetc
Normal file
35
help/fgetc
Normal file
@@ -0,0 +1,35 @@
|
||||
NAME
|
||||
fgetc - read the next char from a file
|
||||
|
||||
SYNOPSIS
|
||||
fgetc(fd)
|
||||
|
||||
TYPES
|
||||
fd file
|
||||
|
||||
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
|
||||
of EOF or error, nil is returned.
|
||||
|
||||
EXAMPLE
|
||||
> fd = fopen("/tmp/newfile", "w")
|
||||
> fputs(fd, "chongo was here\n")
|
||||
> fd2 = fopen("/tmp/newfile", "r")
|
||||
> fgetc(fd2)
|
||||
"c"
|
||||
|
||||
LIMITS
|
||||
fd must be associaed with an open file
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
52
help/fgetfield
Normal file
52
help/fgetfield
Normal file
@@ -0,0 +1,52 @@
|
||||
NAME
|
||||
fgetfield - read the next word from a file
|
||||
|
||||
SYNOPSIS
|
||||
fgetfield(fs)
|
||||
|
||||
TYPES
|
||||
fs file stream open for reading
|
||||
|
||||
return string, null or error value
|
||||
|
||||
DESCRIPTION
|
||||
If characters cannot be read from the file, an error value is returned.
|
||||
|
||||
Otherwise starting at the current file position, any whitespace
|
||||
characters are skipped. If the reading reaches end-of-file, the
|
||||
null value is returned. If non-whitespace is encountered, formation
|
||||
of a string begins, continuing until whitespace of '\0' or end-of-file
|
||||
is reached. The returned value is this string (terminated as usual
|
||||
by a null character). After the operation, the file position will
|
||||
be immediately after the first whitespace character of '\0' or at
|
||||
end-of-file.
|
||||
|
||||
EXAMPLE
|
||||
|
||||
> f = fopen("/tmp/junk", "w")
|
||||
> fputs(f, " Alpha Beta \n")
|
||||
> freopen(f, "r")
|
||||
> fgetfield(f)
|
||||
"Alpha"
|
||||
> fgetfield(f)
|
||||
"Beta"
|
||||
> fgetfield(f)
|
||||
>
|
||||
> freopen(f, "w")
|
||||
> fputstr(f, " Alpha ", "Beta")
|
||||
> freopen(f, "r")
|
||||
> fgetfield(f)
|
||||
"Alpha"
|
||||
> fgetfield(f)
|
||||
""
|
||||
> fgetfield(f)
|
||||
"Beta"
|
||||
|
||||
LIMITS
|
||||
none - XXX - is this correct?
|
||||
|
||||
LIBRARY
|
||||
none - XXX - is this correct?
|
||||
|
||||
SEE ALSO
|
||||
fgetstr, fputstr, fgets, fputs, fopen, files, fprintf
|
51
help/fgetline
Normal file
51
help/fgetline
Normal file
@@ -0,0 +1,51 @@
|
||||
NAME
|
||||
fgetline - read the next line from a file, newline is tossed
|
||||
|
||||
SYNOPSIS
|
||||
fgetline(fd)
|
||||
|
||||
TYPES
|
||||
fd file
|
||||
|
||||
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,
|
||||
fgetline returns the 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.
|
||||
|
||||
If a line is read, is returned minus the trailing newline, otherwise
|
||||
(EOF or ERROR) nil is returned.
|
||||
|
||||
EXAMPLE
|
||||
> fd = fopen("/tmp/newfile", "w")
|
||||
> fputs(fd, "chongo was here\n")
|
||||
> fputs(fd, "123\n")
|
||||
> fd2 = fopen("/tmp/newfile", "r")
|
||||
> fgets(fd2)
|
||||
"chongo was here
|
||||
"
|
||||
|
||||
> fclose(fd2)
|
||||
> fd2 = fopen("/tmp/newfile", "r")
|
||||
> fgetline(fd2)
|
||||
"chongo was here"
|
||||
> eval(fgetline(fd2))
|
||||
123
|
||||
|
||||
LIMITS
|
||||
fd must be associaed with an open file
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
40
help/fgets
Normal file
40
help/fgets
Normal file
@@ -0,0 +1,40 @@
|
||||
NAME
|
||||
fgets - read the next line from a file, newline is kept
|
||||
|
||||
SYNOPSIS
|
||||
fgets(fd)
|
||||
|
||||
TYPES
|
||||
fd file
|
||||
|
||||
return str or nil
|
||||
|
||||
DESCRIPTION
|
||||
This function reads the next line, including any trailing newline from
|
||||
the open file associated with fd. Unlike fgetline, the trailing
|
||||
newline is included in the return string.
|
||||
|
||||
If a line is read, is returned, otherwise (EOF or ERROR) nil is returned.
|
||||
|
||||
EXAMPLE
|
||||
> fd = fopen("/tmp/newfile", "w")
|
||||
> fputs(fd, "chongo was here\n")
|
||||
> fd2 = fopen("/tmp/newfile", "r")
|
||||
> fgets(fd2)
|
||||
"chongo was here
|
||||
"
|
||||
|
||||
> fclose(fd2)
|
||||
> fd2 = fopen("/tmp/newfile", "r")
|
||||
> fgetline(fd2)
|
||||
"chongo was here"
|
||||
|
||||
LIMITS
|
||||
fd must be associaed with an open file
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
48
help/fgetstr
Normal file
48
help/fgetstr
Normal file
@@ -0,0 +1,48 @@
|
||||
NAME
|
||||
fgetstr - read the next null-terminated string from a file
|
||||
|
||||
SYNOPSIS
|
||||
fgetstr(fs)
|
||||
|
||||
TYPES
|
||||
fs file stream open for reading
|
||||
|
||||
return string, null or error value
|
||||
|
||||
DESCRIPTION
|
||||
If the stream is at end of file, the null value is returned.
|
||||
|
||||
If the stream cannot be read, an error value is returned.
|
||||
|
||||
Otherwise the function retrurns the string of characters from the
|
||||
current file position to the first null character ('\0') (the file
|
||||
position for further reading then being immediately after the '\0'),
|
||||
or if no null character is encountered, the string of characters to
|
||||
the end of file (the string as usual being terminated by '\0').
|
||||
|
||||
If the stream being read is from stdin (i.e. files(0)), the
|
||||
characters entered are not displayed and reading ends when a '\0' is
|
||||
entered (on many terminals this is by ctrl-@).
|
||||
|
||||
EXAMPLE
|
||||
> f = fopen("/tmp/junk", "w")
|
||||
> fputstr(f, " Alpha Beta ", "", "Gamma\n\tDelta")
|
||||
> freopen(f, "r")
|
||||
> fgetstr(f)
|
||||
" Alpha Beta "
|
||||
> fgetstr(f)
|
||||
""
|
||||
> fgetstr(f)
|
||||
"Gamma
|
||||
Delta"
|
||||
> fgetstr(f)
|
||||
>
|
||||
|
||||
LIMITS
|
||||
none - XXX - is this correct?
|
||||
|
||||
LIBRARY
|
||||
none - XXX - is this correct?
|
||||
|
||||
SEE ALSO
|
||||
fputstr, fgetword, fgets, fputs, fopen, files, fprintf
|
28
help/fib
Normal file
28
help/fib
Normal file
@@ -0,0 +1,28 @@
|
||||
NAME
|
||||
fib - Fibonacci number
|
||||
|
||||
SYNOPSIS
|
||||
fib(n)
|
||||
|
||||
TYPES
|
||||
n integer
|
||||
|
||||
return integer
|
||||
|
||||
DESCRIPTION
|
||||
For any integer n, fib(n) returns the Fibonacci number with index n.
|
||||
This may be defined by fib(0) = 0, fib(1) = 1 and for any n (positive
|
||||
or negative) fib(n) = fib(n-1) + fib(n-2).
|
||||
|
||||
EXAMPLE
|
||||
> print fib(-2), fib(-1), fib(0), fib(1), fib(2), fib(3), fib(4), fib(5)
|
||||
-1 1 0 1 1 2 3 5 -8
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qfib(NUMBER *n)
|
||||
|
||||
SEE ALSO
|
||||
XXX - fill in
|
167
help/file
Normal file
167
help/file
Normal file
@@ -0,0 +1,167 @@
|
||||
Using files
|
||||
|
||||
The calculator provides some functions which allow the program to
|
||||
read or write text files. These functions use stdio internally,
|
||||
and the functions appear similar to some of the stdio functions.
|
||||
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:
|
||||
|
||||
~/.rc.cal
|
||||
|
||||
refers to the file '.rc.cal' under your home directory. The
|
||||
file name:
|
||||
|
||||
~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
|
||||
'foo' for reading, the following could be used:
|
||||
|
||||
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.
|
||||
You can use the 'isfile' function to test the return value to see
|
||||
if the open succeeded. You should assign the return value of fopen
|
||||
to a variable for later use. File values can be copied to more than
|
||||
one variable, and using any of the variables with the same file value
|
||||
will produce the same results.
|
||||
|
||||
If you overwrite a variable containing a file value or don't save the
|
||||
result of an 'fopen', the opened file still remains open. Such 'lost'
|
||||
files can be recovered by using the 'files' function. This function
|
||||
either takes no arguments or else takes one integer argument. If no
|
||||
arguments are given, then 'files' returns the maximum number of opened
|
||||
files. If an argument is given, then the 'files' function uses it as
|
||||
an index into an internal table of open files, and returns a value
|
||||
referring to one the open files. If that entry in the table is not
|
||||
in use, then the null value is returned instead. Index 0 always
|
||||
refers to standard input, index 1 always refers to standard output,
|
||||
and index 2 always refers to standard error. These three files are
|
||||
already open by the calculator and cannot be closed. As an example
|
||||
of using 'files', if you wanted to assign a file value which is
|
||||
equivalent to stdout, you could use:
|
||||
|
||||
stdout = files(1);
|
||||
|
||||
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
|
||||
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
|
||||
error using the file, or the null value if there was no error.
|
||||
|
||||
The builtin 'errno' 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 : ":", errno(badfile);
|
||||
}
|
||||
|
||||
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,
|
||||
the open mode, file position, and possible EOF, error, and closed
|
||||
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
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
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.) 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
|
||||
generate an error if the string doesn't represent a valid expression.
|
||||
The 'fgetc' function returns the next character from a file as a
|
||||
single character string. It returns the null value when end of file
|
||||
is reached.
|
||||
|
||||
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
|
||||
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
|
||||
problems, in the calculator nothing bad will happen. This is because
|
||||
the calculator knows the types of all values, and will handle them
|
||||
all reasonably. What this means is that you can (for example), always
|
||||
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);
|
||||
|
||||
and will print "Two values are fred and 4567".
|
||||
|
||||
Using particular format characters, however, is still useful if
|
||||
you wish to use width or precision arguments in the format, or if
|
||||
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
|
||||
|
||||
Note then, that using %d in the format makes the output configurable
|
||||
by using the 'config' function to change the output mode, whereas
|
||||
the other formats override the mode and force the output to be in
|
||||
the specified format.
|
||||
|
||||
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);
|
||||
|
||||
will print 100 decimal places no matter what the display configuration
|
||||
value is set to.
|
||||
|
||||
The %s and %c formats are identical, and will print out the string
|
||||
representation of the value. In these cases, the precision argument
|
||||
will truncate the output the same way as in standard C.
|
||||
|
||||
If a matrix or list is printed, then the output mode and precision
|
||||
affects the printing of each individual element. However, field
|
||||
widths are ignored since these values print using multiple lines.
|
||||
Field widths are also ignored if an object value prints on multiple
|
||||
lines.
|
||||
|
||||
The functions 'fputc' and 'fputs' write a character and string to
|
||||
a file respectively.
|
||||
|
||||
The final file-related functions are 'fflush', 'ferror', and 'feof'.
|
||||
The 'fflush' function forces buffered output to a file. The 'ferror'
|
||||
function returns nonzero if an error had occurred to a file. The
|
||||
'feof' function returns nonzero if end of file has been reached
|
||||
while reading a file.
|
||||
|
||||
The 'strprintf' function formats output similarly to 'printf',
|
||||
but the output is returned as a string value instead of being
|
||||
printed.
|
69
help/files
Normal file
69
help/files
Normal file
@@ -0,0 +1,69 @@
|
||||
NAME
|
||||
files - return a file or the maximum number of open files
|
||||
|
||||
SYNOPSIS
|
||||
files([fnum])
|
||||
|
||||
TYPES
|
||||
fnum int
|
||||
|
||||
return files, int or null
|
||||
|
||||
DESCRIPTION
|
||||
This function, then given the argument fnum, will use it as an
|
||||
index into an internal table of open file and return a file value.
|
||||
If that entry in the table is not in use, then the null value is
|
||||
returned instead. When no args are given, the maximum number of
|
||||
open files is returned.
|
||||
|
||||
If you overwrite a variable containing a file value or don't save the
|
||||
result of an 'fopen', the opened file still remains open. Such 'lost'
|
||||
files can be recovered by using the 'files' function.
|
||||
|
||||
The first 3 file entries always refer to standard input, output
|
||||
and error respectively. (see the example below) These three
|
||||
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
|
||||
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:
|
||||
|
||||
$ echo "A line of text in the file on descriptor 5" > datafile
|
||||
$ calc 5<datafile
|
||||
|
||||
then one could do the following:
|
||||
|
||||
> files(5)
|
||||
FILE 5 "descriptor[5]" (unknown_mode, pos 0)
|
||||
> fgetline(files(5))
|
||||
"A line of text in the file on descriptor 5"
|
||||
|
||||
EXAMPLE
|
||||
> fd = fopen("/etc/motd", "r")
|
||||
> fd
|
||||
FILE 3 "/etc/motd" (reading, pos 0)
|
||||
> files(3)
|
||||
FILE 3 "/etc/motd" (reading, pos 0)
|
||||
|
||||
> if (isnull(files(4))) print "not open"
|
||||
not open
|
||||
|
||||
> stdin = files(0)
|
||||
> stdout = files(1)
|
||||
> stderr = files(2)
|
||||
|
||||
> print files()
|
||||
20
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
33
help/floor
Normal file
33
help/floor
Normal file
@@ -0,0 +1,33 @@
|
||||
NAME
|
||||
floor - floor
|
||||
|
||||
SYNOPSIS
|
||||
floor(x)
|
||||
|
||||
TYPES
|
||||
x real, complex, list, matrix
|
||||
|
||||
return real or complex, list, matrix
|
||||
|
||||
DESCRIPTION
|
||||
For real x, floor(x) is the greatest integer not greater than x.
|
||||
|
||||
For complex, floor(x) returns the real or complex number v for
|
||||
which re(v) = floor(re(x)), im(v) = floor(im(x)).
|
||||
|
||||
For list or matrix x, floor(x) returns the list or matrix of the
|
||||
same structure as x for which each element t of x has been replaced
|
||||
by floor(t).
|
||||
|
||||
EXAMPLE
|
||||
> print floor(27), floor(1.23), floor(-4.56), floor(7.8 - 9.1i)
|
||||
27 1 -5 7-10i
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
ceil, int
|
75
help/fopen
Normal file
75
help/fopen
Normal file
@@ -0,0 +1,75 @@
|
||||
NAME
|
||||
fopen - open a file
|
||||
|
||||
SYNOPSIS
|
||||
fopen(filename, mode)
|
||||
|
||||
TYPES
|
||||
filename string
|
||||
mode string
|
||||
|
||||
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 folllows:
|
||||
|
||||
"r" reading
|
||||
"w" writing
|
||||
"a" appending
|
||||
|
||||
Names of files are subject to ~ expansion just like the C or
|
||||
Korn shell. For example, the file name:
|
||||
|
||||
~/lib/gleet
|
||||
|
||||
refers to the file 'gleet' under the directory lib located
|
||||
in your home directory. The file name:
|
||||
|
||||
~chongo/was_here
|
||||
|
||||
refers to the a file 'was_here' under the home directory of
|
||||
the user 'chongo'.
|
||||
|
||||
If the open is successful, a value of type 'file' will be returned.
|
||||
You can use the 'isfile' function to test the return value to see
|
||||
if the open succeeded. You should assign the return value of fopen
|
||||
to a variable for later use. File values can be copied to more than
|
||||
one variable, and using any of the variables with the same file value
|
||||
will produce the same results.
|
||||
|
||||
Standard input, standard output and standard error are always opened
|
||||
and cannot be closed.
|
||||
|
||||
The truth value of an opened file is TRUE.
|
||||
|
||||
If the open is unsuccessful, the numeric value of errno is returned.
|
||||
You can the errno() builtin to determine what the errno number means.
|
||||
|
||||
EXAMPLE
|
||||
> fd = fopen("/etc/motd", "r")
|
||||
> print fd
|
||||
"/etc/motd"
|
||||
> fd
|
||||
FILE 3 "/etc/motd" (reading, pos 0)
|
||||
|
||||
> outfile = fopen("~/tmp/output", "w")
|
||||
> print outfile
|
||||
"~/tmp/output"
|
||||
> outfile
|
||||
FILE 4 "~/tmp/output" (writing, pos 0)
|
||||
|
||||
> badfile = fopen("not_a_file", "r")
|
||||
> if (!isfile(badfile)) print "error #" : badfile : ":", errno(badfile);
|
||||
error #2: No such file or directory
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
38
help/forall
Normal file
38
help/forall
Normal file
@@ -0,0 +1,38 @@
|
||||
NAME
|
||||
forall - to evaluate a function for all values of a list or matrix
|
||||
|
||||
SYNOPSIS
|
||||
forall(x, y)
|
||||
|
||||
TYPES
|
||||
x list or matrix
|
||||
y string
|
||||
|
||||
return null value
|
||||
|
||||
DESCRIPTION
|
||||
In forall(x,y), y is to the the name of a function; that function
|
||||
is performed in succession for all elements of x. This is similar
|
||||
to modify(x, y) but x is not changed.
|
||||
|
||||
EXAMPLE
|
||||
> global n = 0
|
||||
> define s(a) {n += a;}
|
||||
> A = list(1,2,3,4)
|
||||
> forall(A, "s")
|
||||
> n
|
||||
10
|
||||
|
||||
> define e(a) {if (iseven(a)) print a;}
|
||||
> forall(A, "e")
|
||||
2
|
||||
4
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
modify
|
55
help/fprintf
Normal file
55
help/fprintf
Normal file
@@ -0,0 +1,55 @@
|
||||
NAME
|
||||
fprintf - formatted print to a file
|
||||
|
||||
SYNOPSIS
|
||||
fprintf(fd, fmt, x_1, x_2, ...)
|
||||
|
||||
TYPES
|
||||
fd file
|
||||
fmt string
|
||||
x_1, x_2, ... any
|
||||
|
||||
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, ...).
|
||||
|
||||
EXAMPLE
|
||||
> fprintf(files(1), "h=%d, i=%d\n", 2, 3);
|
||||
h=2, i=3
|
||||
|
||||
> c = config("epsilon", 1e-6); c = config("display", 6);
|
||||
> c = config("tilde", 1); c = config("outround", 0);
|
||||
> c = config("fullzero", 0);
|
||||
> fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n";
|
||||
> a = sqrt(3);
|
||||
> fprintf(files(2), fmt,a,a,a,a,a,a);
|
||||
1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1.
|
||||
|
||||
> file = fopen("/tmp/foo", "w");
|
||||
> mat A[4] = {sqrt(2), 3/7, "undefined", null()};
|
||||
> fprintf(file, "%f%r",A,A);
|
||||
> fclose(file);
|
||||
> !cat /tmp/foo
|
||||
|
||||
mat [4] (4 elements, 4 nonzero):
|
||||
[0] = 1.4142135623730950488
|
||||
[1] = ~.42857142857142857142
|
||||
[2] = "undefined"
|
||||
[3] = NULL
|
||||
|
||||
mat [4] (4 elements, 4 nonzero):
|
||||
[0] = 1767766952966368811/1250000000000000000
|
||||
[1] = 3/7
|
||||
[2] = "undefined"
|
||||
[3] = NULL
|
||||
|
||||
LIMITS
|
||||
The number of arguments of fprintf() is not to exceed 100.
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
printf, strprintf, print
|
32
help/fputc
Normal file
32
help/fputc
Normal file
@@ -0,0 +1,32 @@
|
||||
NAME
|
||||
fputc - write a character to a file
|
||||
|
||||
SYNOPSIS
|
||||
fputc(fd, data)
|
||||
|
||||
TYPES
|
||||
fd file
|
||||
data str
|
||||
|
||||
return nil
|
||||
|
||||
DESCRIPTION
|
||||
This function writes the first character in data to the file
|
||||
associated with fd.
|
||||
|
||||
EXAMPLE
|
||||
> fd = fopen("/tmp/newfile", "w")
|
||||
> fputc(fd, "c")
|
||||
> fd2 = fopen("/tmp/newfile", "r")
|
||||
> fgetc(fd2)
|
||||
"c"
|
||||
|
||||
LIMITS
|
||||
fd must be associaed with an open file
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
32
help/fputs
Normal file
32
help/fputs
Normal file
@@ -0,0 +1,32 @@
|
||||
NAME
|
||||
fputs - write a string to a file
|
||||
|
||||
SYNOPSIS
|
||||
fputs(fd, data)
|
||||
|
||||
TYPES
|
||||
fd file
|
||||
data str
|
||||
|
||||
return nil
|
||||
|
||||
DESCRIPTION
|
||||
This function writes the string found in data to the file
|
||||
associated with fd.
|
||||
|
||||
EXAMPLE
|
||||
> fd = fopen("/tmp/newfile", "w")
|
||||
> fputs(fd, "chongo was here\n")
|
||||
> fd2 = fopen("/tmp/newfile", "r")
|
||||
> fgetline(fd2)
|
||||
"chongo was here"
|
||||
|
||||
LIMITS
|
||||
fd must be associaed with an open file
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
40
help/fputstr
Normal file
40
help/fputstr
Normal file
@@ -0,0 +1,40 @@
|
||||
NAME
|
||||
fputstr - send one or more null-terminated strings to a file
|
||||
|
||||
SYNOPSIS
|
||||
fputstr(fs, s_1, s_2, ...)
|
||||
|
||||
TYPES
|
||||
fs file stream open for writing
|
||||
s_1, ... string
|
||||
|
||||
return null or error value
|
||||
|
||||
DESCRIPTION
|
||||
If the stream cannot be written to or an argument is of the wrong
|
||||
type, an error value is returned.
|
||||
|
||||
Otherwise the strings s_1, s_2, ..., including the terminating
|
||||
null characters ('\0') are written to the file stream fs.
|
||||
|
||||
EXAMPLE
|
||||
> f = fopen("/tmp/junk", "w")
|
||||
> fputstr(f, "Alpha", "Beta")
|
||||
> freopen(f, "r")
|
||||
> fgetstr(f)
|
||||
"Alpha"
|
||||
> fgetstr(f)
|
||||
"Beta"
|
||||
> fgetstr(f)
|
||||
>
|
||||
> fputstr(f, "Gamma")
|
||||
Error 72
|
||||
|
||||
LIMITS
|
||||
none - XXX - is this correct?
|
||||
|
||||
LIBRARY
|
||||
none - XXX - is this correct?
|
||||
|
||||
SEE ALSO
|
||||
fgetstr, fgetfield, fgets, fputs, fopen, files, fprintf
|
42
help/frac
Normal file
42
help/frac
Normal file
@@ -0,0 +1,42 @@
|
||||
NAME
|
||||
frac - return the fractional part of a number or of numbers in a value
|
||||
|
||||
SYNOPSIS
|
||||
frac(x)
|
||||
|
||||
TYPES
|
||||
If x is an object of type xx, frac(x) requires xx_frac to have been
|
||||
defined; other conditions on x and the value returned depend on
|
||||
the definition of xx_frac.
|
||||
|
||||
For other x:
|
||||
|
||||
x number (real or complex), matrix
|
||||
|
||||
return number or matrix
|
||||
|
||||
DESCRIPTION
|
||||
If x is an integer, frac(x) returns zero. For other real values of x,
|
||||
frac(x) returns the real number f for which x = i + f, where i is an
|
||||
integer, sgn(f) = sgn(x), and abs(f) < 1.
|
||||
|
||||
If x is complex, frac(x) returns frac(re(x)) + frac(im(x))*1i.
|
||||
|
||||
If x is a matrix, frac(x) returns the matrix m with the same structure
|
||||
as x in which m[[i]] = frac(x[[i]]).
|
||||
|
||||
EXAMPLE
|
||||
> c = config("mode", "frac")
|
||||
> print frac(3), frac(22/7), frac(27/7), frac(-3.125), frac(2.15 - 3.25i)
|
||||
0 1/7 6/7 -1/8 3/20-1i/4
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qfrac(NUMBER *x)
|
||||
COMPLEX *cfrac(COMPLEX *x)
|
||||
MATRIX *matfrac(MATRIX *x)
|
||||
|
||||
SEE ALSO
|
||||
int, ceil, floor
|
37
help/frem
Normal file
37
help/frem
Normal file
@@ -0,0 +1,37 @@
|
||||
NAME
|
||||
frem - remove specified integer factors from specified integer
|
||||
|
||||
SYNOPSIS
|
||||
frem(x,y)
|
||||
|
||||
TYPES
|
||||
x integer
|
||||
y 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
|
||||
divisor of x not divisible by y.
|
||||
|
||||
For all x, frem(x,0) is defined to equal abs(x).
|
||||
|
||||
For all y, frem(0,y) is defined to be zero.
|
||||
|
||||
For all x and y, abs(x) = frem(x,y) * abs(y) ^ fcnt(x,y).
|
||||
|
||||
EXAMPLE
|
||||
> print frem(7,4), frem(24,4), frem(48,4), frem(-48,4)
|
||||
7 6 3 3
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qfacrem(NUMBER *x, NUMBER *y);
|
||||
|
||||
SEE ALSO
|
||||
fcnt, gcdrem
|
42
help/freopen
Normal file
42
help/freopen
Normal file
@@ -0,0 +1,42 @@
|
||||
NAME
|
||||
freopen - close (if necessary) and reopen a filestream
|
||||
|
||||
SYNOPSIS
|
||||
freopen(fs, mode) or freopen(fs, mode, filename)
|
||||
|
||||
TYPES
|
||||
fs open or closed file stream
|
||||
mode one of the strings "r", "w", "a", "r+", "w+, "a+"
|
||||
filename string
|
||||
|
||||
return null or error value
|
||||
|
||||
DESCRIPTION
|
||||
With two arguments, this function closes the file stream fs and
|
||||
attempts to reopen it with the specified mode. A non-null value
|
||||
is returned only if the attempt fails.
|
||||
|
||||
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.
|
||||
|
||||
EXAMPLE
|
||||
|
||||
> f = fopen("/tmp/junk", "w")
|
||||
> fputs(f, "Leonard Euler")
|
||||
> freopen(f, "r")
|
||||
> fgets(f)
|
||||
"Leonard Euler"
|
||||
> !chmod u-w /tmp/junk
|
||||
> freopen(f, "w")
|
||||
Error 10013
|
||||
|
||||
LIMITS
|
||||
none - XXX - is this correct?
|
||||
|
||||
LIBRARY
|
||||
none - XXX - is this correct?
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
39
help/fscan
Normal file
39
help/fscan
Normal file
@@ -0,0 +1,39 @@
|
||||
NAME
|
||||
fscan - scan a file for possible assignment to variables
|
||||
|
||||
SYNOPSIS
|
||||
fscan(fs, x_1, x_2, ..., x_n)
|
||||
|
||||
TYPES
|
||||
fs file stream open for reading
|
||||
x_1, x_2, ... any
|
||||
|
||||
return integer
|
||||
|
||||
DESCRIPTION
|
||||
Starting at the current position on fs and while values remain in the
|
||||
x_i arguments, fields of non-whitespace characters are read and evaluated
|
||||
in succession and if the corresponding x_i is an lvalue, the value of
|
||||
the field is assigned to x_i. Scanning ceases when no x_i remain or
|
||||
when the stream reaches end-of-file.
|
||||
|
||||
The function returns the number of fields evaluated.
|
||||
|
||||
EXAMPLE
|
||||
> global a, b, c, d;
|
||||
> f = fopen("/tmp/junk", "w+");
|
||||
> fputs(f, "\t3+4\t\ta-2i d=a^2 'word'")
|
||||
> rewind(f)
|
||||
> fscan(f, a, b, , c)
|
||||
4
|
||||
> print a, b, c, d
|
||||
7 a-2i word 49
|
||||
|
||||
LIMITS
|
||||
none - XXX - is this correct?
|
||||
|
||||
LIBRARY
|
||||
none - XXX - is this correct?
|
||||
|
||||
SEE ALSO
|
||||
scan, strscan, fscanf, scanf, strscanf, printf, fprintf, strprintf
|
130
help/fscanf
Normal file
130
help/fscanf
Normal file
@@ -0,0 +1,130 @@
|
||||
NAME
|
||||
fscanf - formatted scan of a file stream
|
||||
|
||||
SYNOPSIS
|
||||
fscanf(fs, fmt, x_1, x_2, ...)
|
||||
|
||||
TYPES
|
||||
fs file stream open for reading
|
||||
fmt string
|
||||
x_1, x_2, ... lvalues
|
||||
|
||||
return null, nonnegative integer, or error value
|
||||
|
||||
DESCRIPTION
|
||||
If the current position for fs is EOF, the null value is returned.
|
||||
|
||||
Otherwise, until the terminating null character of fmt is encountered
|
||||
or end-of-file for fs is reached, characters other than '%' and white
|
||||
space are read from fmt and compared with the corresponding chracters
|
||||
read from fs. If the characters match, the reading continues. If they
|
||||
do not match, an integer value is returned and the file position for
|
||||
fs is the position of the non-matching character. If white space
|
||||
is encountered in fmt, any white space characters read from
|
||||
fs are skipped until either end-of-file is reached or a non-white-space
|
||||
character is read and comparisons continue under the control of the
|
||||
next non-white character and following characters in fmt.
|
||||
|
||||
When a '%' is encountered in fmt, if this is immediately followed by
|
||||
another '%', the pair is considered as if just one '%' were read and
|
||||
if reading from fmt and fs continues if and only if fs has a matching
|
||||
'%'. 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.
|
||||
|
||||
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,
|
||||
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
|
||||
of assignments that have been made.
|
||||
|
||||
Occurrence of '*' indicates that characters as specified are to be read
|
||||
but no assignment will be made.
|
||||
|
||||
The digits, if any, read at this stage in the specifier are taken to
|
||||
be decimal digits of an integer which becomes the maximum "width"
|
||||
(i.e. for string-type values, the number of characters to be read from
|
||||
fs); absence of digits or all zero digits in the 'c'
|
||||
case are taken to mean width = 1. Zero width for the other cases are
|
||||
treated as if infinite. Fewer characters than the specifier width
|
||||
may be read if end-of-file is reached or in the case of scanset
|
||||
specification, an exceptional character is encountered.
|
||||
|
||||
If the ending character is 'c', characters are read from fs to
|
||||
form a string, which will be ignored or in the non-'*' case, assigned
|
||||
to the next lvalue.
|
||||
|
||||
In the 's' case, reading to form the string starts at the first non-white
|
||||
character (if any) and ceases when end-of-file or further white space
|
||||
is encountered or the specified width has been attained.
|
||||
|
||||
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'
|
||||
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
|
||||
is no test that the the result conforms to the specifier. Whatever
|
||||
the specifier in these cases, the result depends on the characters read
|
||||
until a space or other exceptional character is read. The
|
||||
characters read may include one or more occurrences of +, -, * as
|
||||
well as /, interpreted in the usual way, with left-to-right associativity
|
||||
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
|
||||
|
||||
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".
|
||||
|
||||
For the number specifiers 'f', 'e', 'r', 'i', any specified width is
|
||||
ignored.
|
||||
|
||||
For the specifier 'n', the current value of the file-position indicator
|
||||
is assigned to the corresponding lvalue. (Any width or skip specification
|
||||
is ignored.)
|
||||
|
||||
|
||||
EXAMPLE
|
||||
> global a, b, c
|
||||
> f = fopen("/tmp/junk", "w+")
|
||||
> fputs(f, "Alpha Beta Gamma")
|
||||
> rewind(f)
|
||||
> fscanf(f, "Alpha Gamma")
|
||||
> fgets(f)
|
||||
"Beta Gamma"
|
||||
> rewind(f)
|
||||
> fscanf(f, "%5c", a)
|
||||
1
|
||||
> a
|
||||
"Alpha"
|
||||
> fgets(f)
|
||||
" Beta Gamma"
|
||||
> rewind(f)
|
||||
> fscanf(f, "%3c%s%[^m]", a, b, c)
|
||||
3
|
||||
> print a, b
|
||||
Alp ha
|
||||
> print c
|
||||
Beta Ga
|
||||
> fgets(f)
|
||||
"mma"
|
||||
|
||||
LIMITS
|
||||
none - XXX - is this correct?
|
||||
|
||||
LIBRARY
|
||||
none - XXX - is this correct?
|
||||
|
||||
SEE ALSO
|
||||
scanf, strscanf, printf, fprintf, strprintf, fscan, scan, strscan
|
67
help/fseek
Normal file
67
help/fseek
Normal file
@@ -0,0 +1,67 @@
|
||||
NAME
|
||||
fseek - set a file position
|
||||
|
||||
SYNOPSIS
|
||||
fseek(fd, offset [, whence])
|
||||
|
||||
TYPES
|
||||
fd open file stream
|
||||
pos integer
|
||||
whence 0, 1 or 2, defaulting to 0
|
||||
|
||||
return null or error value
|
||||
|
||||
DESCRIPTION
|
||||
This function sets the file position indicator for the stream by
|
||||
adding offset to zero, the current value, or the size of the
|
||||
file, according as whence is 0, 1 or 2. The effect is equivalent to
|
||||
moving the signed distance offset from the beginning, the current
|
||||
position, or the end of the file.
|
||||
|
||||
The function also clears the end-of-file flag and flushes any
|
||||
buffered data waiting to be output to the stream.
|
||||
|
||||
An implementation-defined error occurs if the effect would be to
|
||||
give a negative value to the position indicator; on some systems, the
|
||||
file position will be set to end-of-file.
|
||||
|
||||
The file position indicator may have a value greater than the file
|
||||
size. If characters are then written to the file, the gap is
|
||||
filled by null ('\0') characters.
|
||||
|
||||
EXAMPLE
|
||||
> fd = fopen("/tmp/curds", "w")
|
||||
> fputs(fd, "0123456789abcdef")
|
||||
> freopen(fd, "r")
|
||||
> fsize(fd)
|
||||
16
|
||||
> fseek(fd, 5)
|
||||
> fgets(fd)
|
||||
"56789abcdef"
|
||||
> fseek(fd, 0)
|
||||
> fscanf(fd, "%*5c")
|
||||
0
|
||||
> fseek(fd, 5, 1)
|
||||
> fgets(fd)
|
||||
"abcdef"
|
||||
> ftell(fd)
|
||||
16
|
||||
> fseek(fd, -5, 2)
|
||||
> fgets(fd)
|
||||
"bcdef"
|
||||
> fseek(fd, -2)
|
||||
System error 22
|
||||
> ftell(fd)
|
||||
16
|
||||
|
||||
The results for the last four lines may be different for different systems.
|
||||
|
||||
LIMITS
|
||||
Some details of the operation of this function may be implementation-
|
||||
dependent, particularly for older systems.
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
ftell, fgetpos, fsetpos, rewind, strerror
|
30
help/fsize
Normal file
30
help/fsize
Normal file
@@ -0,0 +1,30 @@
|
||||
NAME
|
||||
fsize - return the file size
|
||||
|
||||
SYNOPSIS
|
||||
fsize(fd)
|
||||
|
||||
TYPES
|
||||
fd file
|
||||
|
||||
return int
|
||||
|
||||
DESCRIPTION
|
||||
This function returns the number of bytes in a file. When at
|
||||
the end of file, ftell returns a value which is 1 greater than
|
||||
the file size as reported by fsize.
|
||||
|
||||
EXAMPLE
|
||||
> fd = fopen("/etc/motd", "r")
|
||||
> fsize(fd)
|
||||
784
|
||||
|
||||
LIMITS
|
||||
fd must be associaed with an open file
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
|
||||
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
|
47
help/ftell
Normal file
47
help/ftell
Normal file
@@ -0,0 +1,47 @@
|
||||
NAME
|
||||
ftell - return a file position
|
||||
|
||||
SYNOPSIS
|
||||
ftell(fd)
|
||||
|
||||
TYPES
|
||||
fd open file stream
|
||||
|
||||
return non-negative integer or error value
|
||||
|
||||
DESCRIPTION
|
||||
This function attempts to return the current value of the file position
|
||||
indicator for the stream. This is the number of characters (bytes)
|
||||
between the beginning of the file and the position of the
|
||||
next character for output in "w" or "w+" mode or for input.
|
||||
|
||||
On failure, this returns an error value.
|
||||
|
||||
EXAMPLE
|
||||
> fd = fopen("/tmp/curds", "w")
|
||||
> fputs(fd, "0123456789")
|
||||
> ftell(fd)
|
||||
10
|
||||
> fputs(fd, "abcdef")
|
||||
> ftell(fd)
|
||||
16
|
||||
> fseek(fd, 20, 0)
|
||||
> ftell(fd)
|
||||
20
|
||||
> fputs(fd, "01234")
|
||||
> ftell(fd)
|
||||
25
|
||||
> freopen(fd, "r")
|
||||
> fscanf(fd, "%*5c")
|
||||
0
|
||||
> ftell(fd)
|
||||
5
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
fseek, fgetpos, fsetpos, rewind, strerror
|
9
help/funclist.sed
Normal file
9
help/funclist.sed
Normal file
@@ -0,0 +1,9 @@
|
||||
s/VALUE/int/
|
||||
s/NUMBER[ ]*\*/int /
|
||||
s/NUMBER/int/
|
||||
s/STRINGHEAD/int/
|
||||
s/\(".*",.*,.*\),.*,.*,.*,.*,/\1, 0, 0, 0, 0,/
|
||||
/sed me out/d
|
||||
s/showbuiltins/main/
|
||||
s/[ ][ ]*$//
|
||||
p
|
28
help/gcd
Normal file
28
help/gcd
Normal file
@@ -0,0 +1,28 @@
|
||||
NAME
|
||||
gcd - greatest common divisor of a set of rational numbers
|
||||
|
||||
SYNOPSIS
|
||||
gcd(x1, x2, ...)
|
||||
|
||||
TYPES
|
||||
x1, x2, ... rational number
|
||||
|
||||
return rational number
|
||||
|
||||
DESCRIPTION
|
||||
If at least one xi is nonzero, gcd(x1, x2, ...) is the
|
||||
greatest positive number g for which each xi is a multiple of g.
|
||||
If all xi are zero, the gcd is zero.
|
||||
|
||||
EXAMPLE
|
||||
> print gcd(12, -24, 30), gcd(9/10, 11/5, 4/25), gcd(0,0,0,0,0)
|
||||
6 .02 0
|
||||
|
||||
LIMITS
|
||||
The number of arguments may not to exceed 100.
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qgcd(NUMBER *x1, NUMBER *x2)
|
||||
|
||||
SEE ALSO
|
||||
lcm
|
54
help/gcdrem
Normal file
54
help/gcdrem
Normal file
@@ -0,0 +1,54 @@
|
||||
NAME
|
||||
gcdrem - result of removing factors of integer common to a specified integer
|
||||
|
||||
SYNOPSIS
|
||||
gcdrem(x, y)
|
||||
|
||||
TYPES
|
||||
x integer
|
||||
y integer
|
||||
|
||||
return non-negative integer
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
If x and y are not zero, gcdrem(x, y) returns the greatest integer
|
||||
divisor d of x relatively prime to y, i.e. for which gcd(d,y) = 1.
|
||||
In particular, gcdrem(x,y) = abs(x) if x and y are relatively
|
||||
prime.
|
||||
|
||||
For all x, gcdrem(x, 0) = 1.
|
||||
|
||||
For all nonzero y, gcdrem(0, y) = 0.
|
||||
|
||||
PROPERTIES
|
||||
gcdrem(x,y) = gcd(abs(x), abs(y)).
|
||||
|
||||
If x is not zero, gcdrem(x,y) = gcdrem(x, gcd(x,y)) = gcdrem(x, y % x).
|
||||
|
||||
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.
|
||||
|
||||
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)
|
||||
|
||||
EXAMPLE
|
||||
> print gcdrem(6,15), gcdrem(15,6), gcdrem(72,6), gcdrem(6,72)
|
||||
2 5 1 1
|
||||
|
||||
> print gcdrem(630,6), gcdrem(6,630)
|
||||
35 1
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
NUMBER *qgcdrem(NUMBER *x, NUMBER *y)
|
||||
|
||||
SEE ALSO
|
||||
gcd, frem, isrel
|
35
help/getenv
Normal file
35
help/getenv
Normal file
@@ -0,0 +1,35 @@
|
||||
NAME
|
||||
getenv - get an environment variable
|
||||
|
||||
SYNOPSIS
|
||||
getenv(env)
|
||||
|
||||
TYPES
|
||||
env str
|
||||
|
||||
return str or nil
|
||||
|
||||
DESCRIPTION
|
||||
This function returns the value of the environment variable named by
|
||||
the string env. If no such environment variable exists, nil is returned.
|
||||
|
||||
EXAMPLE
|
||||
> putenv("name", "value")
|
||||
0
|
||||
> getenv("name")
|
||||
"value"
|
||||
> putenv("name=val2")
|
||||
0
|
||||
> getenv("name")
|
||||
"val2"
|
||||
> isnull(getenv("unknown"))
|
||||
1
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
putenv
|
26
help/hash
Normal file
26
help/hash
Normal file
@@ -0,0 +1,26 @@
|
||||
NAME
|
||||
hash - hash value
|
||||
|
||||
SYNOPSIS
|
||||
hash(x_1 [, x_2, x_3, ...])
|
||||
|
||||
TYPES
|
||||
x_1, x_1, ... any
|
||||
|
||||
return integer v, 0 <= v < 2^32
|
||||
|
||||
DESCRIPTION
|
||||
Returns a hash value for one or more values of arbitrary types.
|
||||
|
||||
EXAMPLE
|
||||
> a = isqrt(2e1000); s = "xyz";
|
||||
> hash(a,s)
|
||||
870000771
|
||||
|
||||
LIMITS
|
||||
The number of arguments is not to exceed 100.
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
49
help/head
Normal file
49
help/head
Normal file
@@ -0,0 +1,49 @@
|
||||
NAME
|
||||
head - create a list of specified size from the head of a list
|
||||
|
||||
SYNOPSIS
|
||||
head(x, y)
|
||||
|
||||
TYPES
|
||||
x list
|
||||
y int
|
||||
|
||||
return list
|
||||
|
||||
DESCRIPTION
|
||||
If 0 <= y <= size(x), head(x,y) returns a list of size y whose
|
||||
elements in succession have values x[[0]]. x[[1]], ..., x[[y - 1]].
|
||||
|
||||
If y > size(x), head(x,y) is a copy of x.
|
||||
|
||||
If -size(x) < y < 0, head(x,y) returns a list of size (size(x) + y)
|
||||
whose elements in succession have values x[[0]]. x[[1]], ...,
|
||||
i.e. a copy of x from which the last -y members have been deleted.
|
||||
|
||||
If y <= -size(x), head(x,y) returns a list with no members.
|
||||
|
||||
For any integer y, x == join(head(x,y), tail(x,-y)).
|
||||
|
||||
EXAMPLE
|
||||
> A = list(2, 3, 5, 7, 11)
|
||||
> head(A, 2)
|
||||
|
||||
list (2 members, 2 nonzero):
|
||||
[[0]] = 2
|
||||
[[1]] = 3
|
||||
|
||||
> head(A, -2)
|
||||
|
||||
list (3 members, 3 nonzero):
|
||||
[[0]] = 2
|
||||
[[1]] = 3
|
||||
[[2]] = 5
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
tail, segment
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user