Module DA.BigNumeric¶
This module exposes operations for working with the BigNumeric
type.
Functions¶
- scale
: BigNumeric -> Int
Calculate the scale of a
BigNumeric
number. TheBigNumeric
number is represented asn * 10^-s
wheren
is an integer with no trailing zeros, ands
is the scale.Thus, the scale represents the number of nonzero digits after the decimal point. Note that the scale can be negative if the
BigNumeric
represents an integer with trailing zeros. In that case, it represents the number of trailing zeros (negated).The scale ranges between 2^15 and -2^15 + 1. The scale of
0
is0
by convention.>>> scale 1.1 1
>>> scale (shift (-2^14) 1.0) -2^14
- precision
: BigNumeric -> Int
Calculate the precision of a
BigNumeric
number. TheBigNumeric
number is represented asn * 10^-s
wheren
is an integer with no trailing zeros, ands
is the scale. The precision is the number of digits inn
.Thus, the precision represents the number of significant digits in the
BigNumeric
.The precision ranges between 0 and 2^16 - 1.
>>> precision 1.1.0 2
- div
: Int -> RoundingMode -> BigNumeric -> BigNumeric -> BigNumeric
Calculate a division of
BigNumeric
numbers. The value ofdiv n r a b
is the division ofa
byb
, rounded ton
decimal places (i.e. scale), according to the rounding moder
.This will fail when dividing by
0
, and when using theRoundingUnnecessary
mode for a number that cannot be represented exactly with at mostn
decimal places.
- round
: Int -> RoundingMode -> BigNumeric -> BigNumeric
Round a
BigNumeric
number. The value ofround n r a
is the value ofa
rounded ton
decimal places (i.e. scale), according to the rounding moder
.This will fail when using the
RoundingUnnecessary
mode for a number that cannot be represented exactly with at mostn
decimal places.
- shift
: Int -> BigNumeric -> BigNumeric
Shift a
BigNumeric
number up or down by a power of 10. The valueshift n a
is the value ofa
times10^(-n)
.This will fail if the resulting
BigNumeric
is out of bounds.>>> shift 2 32.0 0.32