Common Lisp Package: WU-DECIMAL

README:

FUNCTION

Public

$ (STREAM DECIMAL COLON ATSIGN &OPTIONAL D N W PAD)

e.g. (format t "~/wu-decimal:$/" #$3.14)

F (STREAM NUMBER COLON ATSIGN &OPTIONAL W D K OVF PAD)

e.g. (format t "~/wu-decimal:F/" #$3.14)

PARSE-DECIMAL (STRING &KEY (START 0) END (SIGN-ALLOWED T) (DECIMAL-MARK .) GROUP-SEPARATOR EXPONENT-ALLOWED JUNK-ALLOWED)

PARSE-DECIMAL parses a decimal number from the substring of STRING delimited by START and END. Optional leading and trailing whitespace[1] is ignored. The character parameters DECIMAL-MARK and GROUP-SEPARATOR provide support for different (typically cultural) numerical conventions. For convenience, a GROUP-SEPARATOR of T will be treated as the comma character. The boolean SIGN-ALLOWED controls signage. EXPONENT-ALLOWED is a boolean or a sequence controlling exponent notation. Exponent notation follows the syntax for CL floats, with exception that the exponent marker must be 'e' or 'E' when EXPONENT-ALLOWED is T, or the exponent marker must be CHAR= to some element of EXPONENT-ALLOWED when EXPONENT-ALLOWED is a sequence. JUNK-ALLOWED behaves as it does in PARSE-INTEGER. PARSE-DECIMAL returns two values: the parsed number of type DECIMAL, followed by the index of STRING where the parse terminated. Example: (parse-decimal "1,205.42" :group-separator #\,) => 60271/50, 8

Undocumented

DISABLE-DECIMAL-PRINTING-FOR-RATIOS

ENABLE-DECIMAL-PRINTING-FOR-RATIOS

ENABLE-READER-MACRO (&KEY EXPONENT-ALLOWED)

Private

FIND-MULTIPLIER (D)

Given an integer, d, of the form 2^m*5^n, compute c such that c*d = c*(2^m*5^n) = 10^max(m,n). Returns c and max(m,n). See http://wukix.com/lisp-decimals#theory for background.

INTEGER-TO-DIGIT-STRING (INTEGER)

Converts an integer into a base 10 string. The sign is ignored.

Undocumented

COUNT-DIGITS (INTEGER)

DECIMAL-READER (STREAM SUBCHAR ARG)

DECIMAL-READER-EXPONENT-ALLOWED (STREAM SUBCHAR ARG)

DECIMAL-TO-DIGITS (NUMBER &OPTIONAL POSITION RELATIVEP)

DECIMAL-TO-STRING (X &OPTIONAL WIDTH FDIGITS SCALE FMIN)

FACTOR-OUT-POWERS-OF-5 (NUMBR)

FORMAT-FIXED-AUX (STREAM NUMBER W D K OVF PAD ATSIGN)

HAS-FINITE-DECIMAL-DIGITS (NUMBER)

IS-POWER-OF-2 (NUMBER)

WHITESPACE-1-P (A-CHAR)

VARIABLE

Public

*PRINT-PRECISION-LOSS*

Precision loss mode. Must be :error, :round, or :truncate

Undocumented

*PRINT-DECIMAL-MARK*

CONDITION

Private

Undocumented

DISALLOWED-LOSS-OF-PRECISION

INCOMPATIBLE-EXPONENT-ALLOWED-ERROR

INCOMPATIBLE-MARK-AND-SEPARATOR-ERROR

OUT-OF-BOUNDS-ERROR