bigdecimal

Types

pub opaque type BigDecimal

Functions

pub fn absolute_value(of value: BigDecimal) -> BigDecimal
pub fn add(augend: BigDecimal, addend: BigDecimal) -> BigDecimal
pub fn clamp(
  value: BigDecimal,
  min min: BigDecimal,
  max max: BigDecimal,
) -> BigDecimal

N.B. if the input has equal value to either of the extremes but different precision, the larger precision will be returned

pub fn compare(this: BigDecimal, with that: BigDecimal) -> Order

N.B. If scale is different, trailing zeros are ignored.

pub fn divide(
  dividend: BigDecimal,
  by divisor: BigDecimal,
  rounding rounding: RoundingMode,
) -> BigDecimal

Divide the dividend by the divisor. The result has a preferred scale of scale(dividend) - scale(divisor), but might have scale up to precision(dividend) + ceil(10 * precision(divisor) / 3).

pub fn from_float(value: Float) -> BigDecimal
pub fn from_string(value: String) -> Result(BigDecimal, Nil)
pub fn multiply(
  multiplicand: BigDecimal,
  with multiplier: BigDecimal,
) -> BigDecimal
pub fn negate(value: BigDecimal) -> BigDecimal
pub fn one() -> BigDecimal
pub fn power(
  value: BigDecimal,
  exponent: Int,
) -> Result(BigDecimal, Nil)

Returns an error if the exponent is negative. (Inherited behaviour from bigi)

pub fn precision(of value: BigDecimal) -> Int

The number of digits in the unscaled value.

pub fn product(values: List(BigDecimal)) -> BigDecimal

For an empty list, this will return one().

pub fn rescale(
  value: BigDecimal,
  scale new_scale: Int,
  rounding rounding: RoundingMode,
) -> BigDecimal
pub fn scale(of value: BigDecimal) -> Int
pub fn signum(of value: BigDecimal) -> Int

Sign function. Returns +1 if the value is positive, -1 if the value is negative, 0 if the value is zero.

pub fn subtract(
  minuend: BigDecimal,
  subtrahend: BigDecimal,
) -> BigDecimal
pub fn sum(values: List(BigDecimal)) -> BigDecimal
pub fn trim_zeros(value: BigDecimal) -> BigDecimal

Trim trailing zeros from after the decimal point.

pub fn truncate_to_bigint(value: BigDecimal) -> BigInt

Truncate the BigDecimal to a BigInt.

pub fn ulp(of value: BigDecimal) -> BigDecimal

Returns the unit of least precision of this BigDecimal.

pub fn unscaled_value(of value: BigDecimal) -> BigInt
pub fn zero() -> BigDecimal
Search Document