Std.Decimal
View source →Arbitrary-precision decimal arithmetic.
A finite value is sign * coefficient * 10 ^ exponent. Int is an
arbitrary-precision BEAM integer, so the coefficient never silently wraps
or loses decimal digits. Arithmetic is performed with integer operations;
Float is used only by the explicit conversion functions.
The default context follows Elixir Decimal: 28 significant digits with half-away-from-zero rounding.
Types
-
type Sign = Positive | Negative -
type NaNPayload = NoPayload | Diagnostic -
type Decimal = Finite | Infinity | QuietNaN | SignallingNaN -
type RoundingMode = Down | Up | Ceiling | Floor | HalfUp | HalfEven | HalfDown -
type DecimalError = InvalidOperation | OutOfRange
Functions
-
# fn absolute_value(d: Decimal) -> Decimal
-
# fn add(a: Decimal, b: Decimal) -> Decimal
-
# fn apply_context(d: Decimal, ctx: Context) -> Decimal
-
# fn coefficient(d: Decimal) -> Int
-
# fn compare(a: Decimal, b: Decimal) -> Result(Ordering, DecimalError)
-
# fn compare_with_threshold(a: Decimal, b: Decimal, threshold: Decimal) -> Result(Ordering, DecimalError)
-
# fn context(precision: Int, rounding: RoundingMode) -> Context
-
# fn default_context() -> Context
-
# fn divide(a: Decimal, b: Decimal) -> Decimal
-
# fn divide_integer(a: Decimal, b: Decimal) -> Decimal
-
# fn divide_remainder(a: Decimal, b: Decimal) -> Tuple(Decimal, Decimal)
-
# fn divide_with_context(a: Decimal, b: Decimal, ctx: Context) -> Decimal
-
# fn eq(a: Decimal, b: Decimal) -> Bool
-
# fn eq_with_threshold(a: Decimal, b: Decimal, threshold: Decimal) -> Bool
-
# fn exponent(d: Decimal) -> Int
-
# fn finite(s: Sign, coefficient: Int, exponent: Int) -> Decimal
-
# fn from_float(value: Float) -> Decimal
-
# fn from_int(value: Int) -> Decimal
-
# fn from_parts(s: Sign, coefficient: Int, exponent: Int) -> Decimal
-
# fn from_string(input: String) -> Result(Decimal, String)
-
# fn gt(a: Decimal, b: Decimal) -> Bool
-
# fn gte(a: Decimal, b: Decimal) -> Bool
-
# fn infinity() -> Decimal
-
# fn is_inf(d: Decimal) -> Bool
-
# fn is_integer(d: Decimal) -> Bool
-
# fn is_nan(d: Decimal) -> Bool
-
# fn is_negative(d: Decimal) -> Bool
-
# fn is_positive(d: Decimal) -> Bool
-
# fn is_zero(d: Decimal) -> Bool
-
# fn lt(a: Decimal, b: Decimal) -> Bool
-
# fn lte(a: Decimal, b: Decimal) -> Bool
-
# fn max(a: Decimal, b: Decimal) -> Decimal
-
# fn min(a: Decimal, b: Decimal) -> Decimal
-
# fn multiply(a: Decimal, b: Decimal) -> Decimal
-
# fn nan() -> Decimal
-
# fn neg_infinity() -> Decimal
-
# fn negate(d: Decimal) -> Decimal
-
# fn normalize(d: Decimal) -> Decimal
-
# fn one() -> Decimal
-
# fn parse(input: String) -> Result(Tuple(Decimal, String), String)
Parse a decimal prefix and return the unconsumed suffix.
-
# fn remainder(a: Decimal, b: Decimal) -> Decimal
-
# fn round(d: Decimal, places: Int, mode: RoundingMode) -> Decimal
-
# fn scale(d: Decimal) -> Int
-
# fn sign(d: Decimal) -> Sign
-
# fn sqrt_with_context(d: Decimal, ctx: Context) -> Decimal
-
# fn square_root(d: Decimal) -> Decimal
-
# fn subtract(a: Decimal, b: Decimal) -> Decimal
-
# fn to_float(d: Decimal) -> Result(Float, DecimalError)
-
# fn to_int(d: Decimal) -> Result(Int, DecimalError)
-
# fn to_string(d: Decimal) -> String
-
# fn to_string_raw(d: Decimal) -> String
-
# fn to_string_scientific(d: Decimal) -> String
-
# fn to_string_xsd(d: Decimal) -> String
-
# fn zero() -> Decimal