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
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.