Decimal-API-shaped facade. Drop in to migrate existing code:
alias FastDecimal.Compat, as: DecimalEvery Decimal.foo(...) call in the existing code then routes here, which
delegates to FastDecimal. Inputs are auto-coerced (Decimal struct,
FastDecimal struct, integer, binary, float).
Limitations
- Struct literals don't translate under alias.
%Decimal{sign: 1, coef: 123, exp: -2}resolves to the aliased module — there is no such struct here. Replace withDecimal.new(1, 123, -2)(3-arg form, shimmed). Decimal.Context.*is intentionally not shimmed — FastDecimal does not carry an implicit precision context. See theFastDecimalmoduledoc. Pass precision per-call viadiv/3's opts.- For
Decimal.Macros.is_decimal/1, useFastDecimal.is_decimal/1(same shape, importable asimport FastDecimal, only: [is_decimal: 1]).
Summary
Functions
Soft constructor — returns {:ok, t} | :error. Mirrors Ecto.Type.cast/1-like input handling.
Division. Defaults to precision 28 (matching Decimal's default context).
Pass precision: and/or rounding: opts to override.
See FastDecimal.inf/0.
See FastDecimal.nan/0.
Decimal-style 3-arg constructor: sign (1 or -1), coef, exp.
Types
@type input() :: FastDecimal.t() | Decimal.t() | integer() | binary() | float() | nil
Functions
@spec abs(input()) :: FastDecimal.t()
@spec add(input(), input()) :: FastDecimal.t()
@spec cast(input()) :: {:ok, FastDecimal.t()} | :error
Soft constructor — returns {:ok, t} | :error. Mirrors Ecto.Type.cast/1-like input handling.
@spec div(input(), input(), keyword()) :: FastDecimal.t()
Division. Defaults to precision 28 (matching Decimal's default context).
Pass precision: and/or rounding: opts to override.
@spec div_int(input(), input()) :: FastDecimal.t()
@spec div_rem(input(), input()) :: {FastDecimal.t(), FastDecimal.t()}
@spec from_float(float()) :: FastDecimal.t()
@spec inf() :: FastDecimal.t()
See FastDecimal.inf/0.
@spec max(input(), input()) :: FastDecimal.t()
@spec min(input(), input()) :: FastDecimal.t()
@spec minus(input()) :: FastDecimal.t()
@spec mult(input(), input()) :: FastDecimal.t()
@spec multiply(input(), input()) :: FastDecimal.t()
@spec nan() :: FastDecimal.t()
See FastDecimal.nan/0.
@spec neg_inf() :: FastDecimal.t()
@spec negate(input()) :: FastDecimal.t()
@spec new(input()) :: FastDecimal.t()
@spec new(1 | -1, non_neg_integer(), integer()) :: FastDecimal.t()
Decimal-style 3-arg constructor: sign (1 or -1), coef, exp.
@spec normalize(input()) :: FastDecimal.t()
@spec plus(input()) :: FastDecimal.t()
@spec reduce(input()) :: FastDecimal.t()
@spec rem(input(), input()) :: FastDecimal.t()
@spec round(input(), integer(), FastDecimal.rounding_mode()) :: FastDecimal.t()
@spec sqrt( input(), keyword() ) :: FastDecimal.t()
@spec sub(input(), input()) :: FastDecimal.t()
@spec to_string(input(), FastDecimal.to_string_format()) :: String.t()