Module ceylon.math

This module provides four APIs:

The types Whole and Decimal are first-class numeric types and support all the usual mathematical operations:

Whole i = wholeNumber(12P);
Whole j = wholeNumber(3);
Whole n = i**j + j;
print(n); //prints 1728000000000000000000000000000000000003

Operations on Decimals can result in a non-terminating decimal representation. In such cases, it is necessary to perform the operations with rounding. The function implicitlyRounded() performs a computation with rounding.

Decimal x = decimalNumber(66.0G);
Decimal y = decimalNumber(100.0T);
Decimal z = decimalNumber(66.0f);
Decimal d = implicitlyRounded(() (x+z)/y/x, round(40, halfUp));
print(d); //prints 1.000000000000000000000001E-14

Here, the expression (x+z)/y/x, which has no terminating decimal representation, is evaluated with the intermediate result of each constituent operation rounded down to 40 decimal digits.

By: Tom Bentley

Decimal floating point arithmetic.


Constants and functions supporting the Float type.


Constants and functions supporting the Integer type.


Arbitrary precision integer arithmetic.

Package ceylon.math