Skip to content

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 ​

text
checkedAdd(int left, int right) returns int unless ArithmeticError

Add signed int64 values; raise ArithmeticError instead of wrapping on overflow.

Source

checkedSubtract ​

text
checkedSubtract(int left, int right) returns int unless ArithmeticError

Subtract signed int64 values; raise ArithmeticError instead of wrapping on overflow.

Source

checkedMultiply ​

text
checkedMultiply(int left, int right) returns int unless ArithmeticError

Multiply signed int64 values; raise ArithmeticError if the product cannot fit.

Source

checkedDivide ​

text
checkedDivide(int left, int right) returns int unless ArithmeticError

Divide toward zero; reject a zero divisor and the unrepresentable MIN / -1 result.

Source

checkedNegate ​

text
checkedNegate(int value) returns int unless ArithmeticError

Negate a signed int64 value; MIN cannot be negated and raises ArithmeticError.

Source

checkedAbs ​

text
checkedAbs(int value) returns int unless ArithmeticError

Return the absolute value; MIN has no representable absolute value.

Source

checkedSum ​

text
checkedSum(List<int> values) returns int unless ArithmeticError

Sum values in list order; reject overflow at any intermediate addition. An empty list returns zero.

Source

Decimal ​

text
record Decimal(int coefficient, int scale) unless ConversionError

Exact 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.

Source

parseDecimal ​

text
parseDecimal(string text) returns Decimal unless ConversionError

Parse 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.

Source

formatDecimal ​

text
formatDecimal(Decimal value) returns string

Format invariant ASCII text with the recorded scale, including trailing fractional zeroes.

Source

rescaleDecimal ​

text
rescaleDecimal(Decimal value, int scale) returns Decimal unless ArithmeticError and ConversionError

Change 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.

Source

addDecimals ​

text
addDecimals(Decimal left, Decimal right) returns Decimal unless ArithmeticError and ConversionError

Add at the greater operand scale. Alignment and the sum must each fit int64.

Source

subtractDecimals ​

text
subtractDecimals(Decimal left, Decimal right) returns Decimal unless ArithmeticError and ConversionError

Subtract at the greater operand scale. Alignment and the difference must each fit int64.

Source

multiplyDecimals ​

text
multiplyDecimals(Decimal left, Decimal right) returns Decimal unless ArithmeticError and ConversionError

Multiply coefficients and add scales. Reject a scale above 18 or an int64 product overflow.

Source

divideDecimals ​

text
divideDecimals(Decimal left, Decimal right, int scale) returns Decimal unless ArithmeticError and ConversionError

Divide 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.

Source

compareDecimals ​

text
compareDecimals(Decimal left, Decimal right) returns int unless ConversionError

Compare 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.

Source

The world runs on language