Common Lisp Package: CL-NUM-UTILS.ARITHMETIC

README:

FUNCTION

Public

1C (NUMBER)

Return 1-number. The mnemonic is "1 complement", 1- is already a CL library function.

ABS-DIFF (A B)

Absolute difference of A and B.

ABSOLUTE-SQUARE (NUMBER)

Number multiplied by its complex conjugate.

AS-INTEGER (NUMBER)

If NUMBER represents an integer (as an integer, complex, or float, etc), return it as an integer, otherwise signal an error. Floats are converted with RATIONALIZE.

CUMULATIVE-PRODUCT (SEQUENCE &KEY (RESULT-TYPE (SIMILAR-SEQUENCE-TYPE SEQUENCE)))

Cumulative product of sequence. Return a sequence of the same kind and length; last element is the total product. The latter is also returned as the second value.

CUMULATIVE-SUM (SEQUENCE &KEY (RESULT-TYPE (SIMILAR-SEQUENCE-TYPE SEQUENCE)))

Cumulative sum of sequence. Return a sequence of the same kind and length; last element is the total. The latter is returned as the second value.

DIVIDES? (NUMBER DIVISOR)

Test if DIVISOR divides NUMBER without remainder, and if so, return the quotient. Works generally, but makes most sense for rationals.

IVEC (END-OR-START &OPTIONAL (END 0 END?) (BY 1) STRICT-DIRECTION?)

Return a vector of fixnums. (ivec end) => #(0 ... end-1) (or #(0 ... end+1) when end is negative). (ivec start end) => #(start ... end-1) or to end+1 when end is negative. When BY is given it determines the increment, adjusted to match the direction unless STRICT-DIRECTION, in which case an error is signalled.

LOG10 (NUMBER)

Abbreviation for decimal logarithm.

LOG2 (NUMBER)

Abbreviation for binary logarithm.

NUMSEQ (FROM TO &KEY LENGTH (BY (UNLESS LENGTH 1)) TYPE)

Return a sequence between FROM and TO, progressing by BY, of the given LENGTH. Only 3 of these a parameters should be given, the missing one (NIL) should be inferred automatically. The sign of BY is adjusted if necessary. If TYPE is LIST, the result is a list, otherwise it determines the element type of the resulting simple array. If TYPE is nil, it as autodetected from the arguments (as a FIXNUM, a RATIONAL, or some subtype of FLOAT). Note that the implementation may upgrade the element type.

SAME-SIGN? (&REST ARGUMENTS)

Test whether all arguments have the same sign (ie all are positive, negative, or zero).

SQUARE (NUMBER)

Square of number.

Private

SIMILAR-ELEMENT-TYPE (ELEMENT-TYPE)

Return a type that is a supertype of ELEMENT-TYPE and is closed under arithmetic operations. May not be the narrowest.

SIMILAR-SEQUENCE-TYPE (SEQUENCE)

Return type that sequence can be mapped to using arithmetic operations.

GENERIC-FUNCTION

Public

PRODUCT (OBJECT)

Product of elements in object.

SUM (OBJECT &KEY KEY (KEY #'IDENTITY))

Sum of elements in object. KEY is applied to each element.