Arbitrary-precision decimal floating-point, homed on the Decimal class.
Literal syntax: 1.5d, -0.001d, 3d, 1.5e-8d. The generic operators
dispatch decimal operands through the type ops; mixed operands
resolve by the from-relation, and a double widens EXACTLY.
- % are exact; / sqrt ln exp log10 round half-even to
(Decimal precision). The transcendentals are series, not libm –
correct to the last digit; the series run in fixed point, so a
34-digit ln costs about a tenth of a second, not ten.
number?Test whether a value is any numeric type (now including decimals).
Parameters:
ANY — Value to testReturns: BOOL — True if x is a number
real?Test whether a value is a real number (now including decimals).
Parameters:
ANY — Value to testReturns: BOOL — True if x is a real number
Decimal(Decimal decimal? x)Test whether a value is an arbitrary-precision decimal.
Parameters:
ANY — Value to testReturns: BOOL — True if x is a decimal
(Decimal precision)The significant digits division and sqrt round to.
Returns: INT — Current precision
(Decimal precision! n)Set the significant digits division and sqrt round to. Addition, subtraction and multiplication stay exact and are unaffected.
Parameters:
INT — Significant digits, at least 1Returns: INT — The new precision
(Decimal from x)Construct a decimal from any convertible value, through the conversion catalog. A float converts EXACTLY; a rational rounds to the current precision. Raises tag ‘type when nothing converts.
Parameters:
ANY — An int, bigint, float, rational, numeric string, or decimal (identity)Returns: DECIMAL — Decimal instance
(Decimal make sig exp)Construct the decimal sig * 10^exp directly, without going through text.
Parameters:
INT — Significand (int or bigint)INT — Power-of-ten exponentReturns: DECIMAL — Decimal instance
(Decimal significand x)The decimal’s significand, with trailing zeros already stripped.
Parameters:
DECIMAL — Decimal valueReturns: INT — Significand as an exact integer
(Decimal exponent x)The decimal’s power-of-ten exponent.
Parameters:
DECIMAL — Decimal valueReturns: INT — Exponent
(Decimal ->int x)Convert a decimal to an exact integer by truncation toward zero.
Parameters:
DECIMAL — Decimal valueReturns: INT — Truncated integer value
(Decimal ->str x)The decimal’s text, without the d suffix that write adds for round-tripping.
Parameters:
DECIMAL — Decimal valueReturns: STRING — Decimal text
(Decimal ->float x)Convert a decimal to the nearest IEEE 754 double. Lossy by definition; the rounding is strtod’s.
Parameters:
DECIMAL — Decimal valueReturns: FLOAT — Nearest double
(Decimal + a b)Add two decimals, exactly (other numerics coerce).
Parameters:
NUMBER — First operandNUMBER — Second operandReturns: DECIMAL — Sum
(Decimal - a b)Subtract two decimals, exactly (other numerics coerce).
Parameters:
NUMBER — First operandNUMBER — Second operandReturns: DECIMAL — Difference
(Decimal * a b)Multiply two decimals, exactly (other numerics coerce).
Parameters:
NUMBER — First operandNUMBER — Second operandReturns: DECIMAL — Product
(Decimal / a b)Divide two decimals, rounded half-even to the current precision (other numerics coerce).
Parameters:
NUMBER — DividendNUMBER — DivisorReturns: DECIMAL — Quotient
(Decimal % a b)Truncating remainder of decimal division, exactly (other numerics coerce).
Parameters:
NUMBER — DividendNUMBER — DivisorReturns: DECIMAL — Remainder, with the dividend’s sign
(Decimal < a b)Test whether a is less than b (other numerics coerce).
Parameters:
NUMBER — Left operandNUMBER — Right operandReturns: BOOL — True if a < b
(Decimal = a b)Test whether a equals b (other numerics coerce).
Parameters:
NUMBER — Left operandNUMBER — Right operandReturns: BOOL — True if a equals b
(Decimal compare a b)Three-way comparison of two decimals (other numerics coerce).
Parameters:
NUMBER — Left operandNUMBER — Right operandReturns: INT — -1 if a < b, 0 if equal, 1 if a > b
(Decimal neg x)Negate a decimal.
Parameters:
NUMBER — Decimal valueReturns: DECIMAL — The negated value
(Decimal abs x)The absolute value of a decimal.
Parameters:
NUMBER — Decimal valueReturns: DECIMAL — Magnitude
(Decimal zero? x)Test whether a decimal is zero.
Parameters:
NUMBER — Decimal valueReturns: BOOL — True if x is zero
(Decimal round x places)Round a decimal to a number of decimal places, half-even.
Parameters:
NUMBER — Decimal valueINT — Decimal places to keep; negative rounds to tens, hundreds, …Returns: DECIMAL — Rounded value
(Decimal rescale x exp)Restate a decimal at a given exponent, rounding half-even when that drops digits. The exponent-facing form of round, for a caller that thinks in scales.
Parameters:
NUMBER — Decimal valueINT — Target power-of-ten exponentReturns: DECIMAL — Value at the requested exponent
(Decimal trunc x)Truncate a decimal toward zero, as an integral decimal.
Parameters:
NUMBER — Decimal valueReturns: DECIMAL — Integer part
(Decimal floor x)The largest integral decimal not greater than x.
Parameters:
NUMBER — Decimal valueReturns: DECIMAL — Floor of x
(Decimal ceil x)The smallest integral decimal not less than x.
Parameters:
NUMBER — Decimal valueReturns: DECIMAL — Ceiling of x
(Decimal sqrt x)The square root of a decimal, rounded half-even to the current precision.
Parameters:
NUMBER — Non-negative decimalReturns: DECIMAL — Square root of x
(Decimal pow x n)Raise a decimal to an integer power. A non-negative exponent is exact; a negative one divides once, at the current precision.
Parameters:
NUMBER — BaseINT — Integer exponentReturns: DECIMAL — x raised to the power n
(Decimal exp x)Raise e to a power, to the current precision.
Parameters:
NUMBER — ExponentReturns: DECIMAL — e raised to the power x
(Decimal ln x)The natural logarithm of a decimal, to the current precision. Raises tag ‘value for zero or a negative.
Parameters:
NUMBER — Positive decimalReturns: DECIMAL — Natural logarithm of x
(Decimal log10 x)The base-10 logarithm of a decimal, to the current precision. An exact power of ten answers its exponent exactly. Raises tag ‘value for zero or a negative.
Parameters:
NUMBER — Positive decimalReturns: DECIMAL — log10(x)