august.math
August 1.0: Supplied with the compiler. Import public names from august.math.
Signatures show result types and checked errors. See packages to pin a release and language constructs for built-in types.
checkedAdd
checkedAdd(int left, int right) returns int unless ArithmeticErrorAdd signed int64 values; raise ArithmeticError instead of wrapping on overflow.
checkedSubtract
checkedSubtract(int left, int right) returns int unless ArithmeticErrorSubtract signed int64 values; raise ArithmeticError instead of wrapping on overflow.
checkedMultiply
checkedMultiply(int left, int right) returns int unless ArithmeticErrorMultiply signed int64 values; raise ArithmeticError if the product cannot fit.
checkedDivide
checkedDivide(int left, int right) returns int unless ArithmeticErrorDivide toward zero; reject a zero divisor and the unrepresentable MIN / -1 result.
checkedNegate
checkedNegate(int value) returns int unless ArithmeticErrorNegate a signed int64 value; MIN cannot be negated and raises ArithmeticError.
checkedAbs
checkedAbs(int value) returns int unless ArithmeticErrorReturn the absolute value; MIN has no representable absolute value.
checkedSum
checkedSum(List<int> values) returns int unless ArithmeticErrorSum values in list order; reject overflow at any intermediate addition. An empty list returns zero.
Decimal
record Decimal(int coefficient, int scale) unless ConversionErrorExact decimal data: coefficient times 10 to the negative scale.
Parameters
coefficient: Signed int64 digits; no floating-point conversion occurs.scale: Fractional digits from 0 to 18. Scale remains part of record equality.
Throws
ConversionError: Scale is outside 0 to 18.
parseDecimal
parseDecimal(string text) returns Decimal unless ConversionErrorParse up to 64 ASCII characters: optional minus, integer digits, and an optional dot with 1 to 18 fractional digits. Leading zeroes are accepted. Plus, whitespace, exponent notation and non-ASCII digits are rejected.
Throws
ConversionError: Invalid text, scale, or int64 coefficient. Negative zero loses its sign.
formatDecimal
formatDecimal(Decimal value) returns stringFormat invariant ASCII text with the recorded scale, including trailing fractional zeroes.
rescaleDecimal
rescaleDecimal(Decimal value, int scale) returns Decimal unless ArithmeticError and ConversionErrorChange fractional scale exactly, adding or removing trailing zeroes without rounding.
Throws
ConversionError: Invalid target scale.ArithmeticError: Precision would be discarded or an intermediate coefficient would overflow.
addDecimals
addDecimals(Decimal left, Decimal right) returns Decimal unless ArithmeticError and ConversionErrorAdd at the greater operand scale. Alignment and the sum must each fit int64.
subtractDecimals
subtractDecimals(Decimal left, Decimal right) returns Decimal unless ArithmeticError and ConversionErrorSubtract at the greater operand scale. Alignment and the difference must each fit int64.
multiplyDecimals
multiplyDecimals(Decimal left, Decimal right) returns Decimal unless ArithmeticError and ConversionErrorMultiply coefficients and add scales. Reject a scale above 18 or an int64 product overflow.
divideDecimals
divideDecimals(Decimal left, Decimal right, int scale) returns Decimal unless ArithmeticError and ConversionErrorDivide at an explicit scale, requiring an exact result. No rounding mode is chosen implicitly.
Throws
ConversionError: Target scale is outside 0 to 18.ArithmeticError: Zero divisor, inexact result, or an intermediate int64 overflow.
compareDecimals
compareDecimals(Decimal left, Decimal right) returns int unless ConversionErrorCompare numeric decimal values; return -1, 0, or 1. Equal values can have different recorded scales. Digit comparison avoids coefficient-alignment overflow. No floating-point conversion occurs.