The functions described here do the actual computational work of the Calculator. In addition to these, note that any function described in the main body of this manual may be called from Lisp; for example, if the documentation refers to the calc-sqrt [sqrt] command, this means calc-sqrt is an interactive stack-based square-root command and sqrt (which defmath expands to calcFunc-sqrt) is the actual Lisp function for taking square roots.
The functions math-add, math-sub, math-mul, math-div, math-mod, and math-neg are not included in this list, since defmath allows you to write native Lisp +, -, *, /, %, and unary -, respectively, instead.
math-normalize.) Reduce the value val to standard form. For example, if val is a fixnum, it will be converted to a bignum if it is too large, and if val is a bignum it will be normalized by clipping off trailing (i.e., most-significant) zero digits and converting to a fixnum if it is small. All the various data types are similarly converted to their standard forms. Variables are left alone, but function calls are actually evaluated in formulas. For example, normalizing `(+ 2 (calcFunc-abs -4))' will return 6. If a function call fails, because the function is void or has the wrong number of parameters, or because it returns nil or calls reject-arg or inexact-result, normalize returns the formula still in symbolic form.
If the current Simplification Mode is ``none'' or ``numeric arguments only,'' normalize will act appropriately. However, the more powerful simplification modes (like algebraic simplification) are not handled by normalize. They are handled by calc-normalize, which calls normalize and possibly some other routines, such as simplify or simplify-units. Programs generally will never call calc-normalize except when popping or pushing values on the stack.
normalize to simplify the result. This is what happens when you press the = key interactively.(math-normalize
(let ((calc-internal-prec (+ calc-internal-prec n)))
body))
The surrounding call to math-normalize causes a floating-point result to be rounded down to the original precision afterwards. This is important because some arithmetic operations assume a number's mantissa contains no more digits than the current precision allows.
n:d'. This is equivalent to calling `(normalize (list 'frac n d))', but more efficient.reject-arg.reject-arg if lo or hi is unsuitable.make-intv, except that if lo is less than hi they are simply exchanged, and the bits of mask are swapped accordingly.makemod, the algebraic version of this function.reject-arg.(lessp x y)', 1 if `(lessp y x)', 0 if `(math-equal x y)', or 2 if the order is undefined or cannot be determined.ceil(log10(n))', but much more efficient. Zero is considered to have zero digits.scale-int, except that a right shift rounds to the nearest integer rather than truncating.(* x x)'.quotient function, otherwise it computes `floor(x/y)'. Thus the result is well-defined but slower than for quotient.quotient, this works only for integer arguments and is not well-defined for negative arguments. For a more well-defined result, use `(% x y)'.car is `(quotient x y)' and whose cdr is `(imod x y)'.defmath code, this can also be written `(^ x y)' or `(expt x y)'.(pi)' computes `pi' to the current precision. Other related constant-generating functions are two-pi, pi-over-2, pi-over-4, pi-over-180, sqrt-two-pi, e, sqrt-e, ln-2, and ln-10. Each function returns a floating-point value in the current precision, and each uses caching so that all calls after the first are essentially free.defun or defvar, defines a new cached constant analogous to pi, etc. It defines a function func which returns the requested value; if initial is non-nil it must be a `(float ...)' form which serves as an initial value for the cache. If func is called when the cache is empty or does not have enough digits to satisfy the current precision, the Lisp expression form is evaluated with the current precision increased by four, and the result minus its two least significant digits is stored in the cache. For example, calling `(pi)' with a precision of 30 computes `pi' to 34 digits, rounds it down to 32 digits for future use, then rounds it again to 30 digits for use in the present request.2*pi', depending on the Symbolic Mode. There are also similar function half-circle and quarter-circle.nil.nil if there is no solution, or if any of the arguments are not integers.(% (^ a b) m)'.floor(sqrt(n))'. If n is itself an integer, the computation is especially efficient.deg or rad. Otherwise, the current angular mode is used. If a is already an HMS form it is returned as-is.deg(a)'.to-radians, except that in Symbolic Mode a degrees to radians conversion yields a formula like `a*pi/180'.from-radians, except that in Symbolic Mode a radians to degrees conversion yields a formula like `a*180/pi'.[0, 10^n)'.[0, 1)'.(nil f)' means the number is non-prime because it was found to be divisible by f; `(nil)' means it was found to be non-prime by table look-up (so no factors are known); `(nil unknown)' means it is definitely non-prime but no factors are known because n was large enough that Fermat's probabilistic test had to be used; `(t)' means the number is definitely prime; and `(maybe i p)' means that Fermat's test, after i iterations, is p percent sure that the number is prime. The iters parameter is the number of Fermat iterations to use, in the case that this is necessary. If prime-test returns ``maybe,'' you can call it again with the same n to get a greater certainty; prime-test remembers where it left off.frac, and can be rather slow.nil.