# `FastDecimal.Compat`
[🔗](https://github.com/b-erdem/fastdecimal/blob/v1.0.1/lib/fastdecimal/compat.ex#L1)

`Decimal`-API-shaped facade. Drop in to migrate existing code:

    alias FastDecimal.Compat, as: Decimal

Every `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 with `Decimal.new(1, 123, -2)` (3-arg form, shimmed).
  * `Decimal.Context.*` is intentionally not shimmed — FastDecimal does not
    carry an implicit precision context. See the `FastDecimal` moduledoc.
    Pass precision per-call via `div/3`'s opts.
  * For `Decimal.Macros.is_decimal/1`, use `FastDecimal.is_decimal/1`
    (same shape, importable as `import FastDecimal, only: [is_decimal: 1]`).

# `input`

```elixir
@type input() :: FastDecimal.t() | Decimal.t() | integer() | binary() | float() | nil
```

# `abs`

```elixir
@spec abs(input()) :: FastDecimal.t()
```

# `add`

```elixir
@spec add(input(), input()) :: FastDecimal.t()
```

# `cast`

```elixir
@spec cast(input()) :: {:ok, FastDecimal.t()} | :error
```

Soft constructor — returns `{:ok, t} | :error`. Mirrors `c:Ecto.Type.cast/1`-like input handling.

# `cmp`

```elixir
@spec cmp(input(), input()) :: :lt | :eq | :gt | :nan
```

# `compare`

```elixir
@spec compare(input(), input()) :: :lt | :eq | :gt | :nan
```

# `div`

```elixir
@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.

# `div_int`

```elixir
@spec div_int(input(), input()) :: FastDecimal.t()
```

# `div_rem`

```elixir
@spec div_rem(input(), input()) :: {FastDecimal.t(), FastDecimal.t()}
```

# `eq?`

```elixir
@spec eq?(input(), input()) :: boolean()
```

# `equal?`

```elixir
@spec equal?(input(), input()) :: boolean()
```

# `finite?`

```elixir
@spec finite?(input()) :: boolean()
```

# `from_float`

```elixir
@spec from_float(float()) :: FastDecimal.t()
```

# `gt?`

```elixir
@spec gt?(input(), input()) :: boolean()
```

# `inf`

```elixir
@spec inf() :: FastDecimal.t()
```

# `inf?`

```elixir
@spec inf?(input()) :: boolean()
```

# `integer?`

```elixir
@spec integer?(input()) :: boolean()
```

# `lt?`

```elixir
@spec lt?(input(), input()) :: boolean()
```

# `max`

```elixir
@spec max(input(), input()) :: FastDecimal.t()
```

# `min`

```elixir
@spec min(input(), input()) :: FastDecimal.t()
```

# `minus`

```elixir
@spec minus(input()) :: FastDecimal.t()
```

# `mult`

```elixir
@spec mult(input(), input()) :: FastDecimal.t()
```

# `multiply`

```elixir
@spec multiply(input(), input()) :: FastDecimal.t()
```

# `nan`

```elixir
@spec nan() :: FastDecimal.t()
```

# `nan?`

```elixir
@spec nan?(input()) :: boolean()
```

# `neg_inf`

```elixir
@spec neg_inf() :: FastDecimal.t()
```

# `negate`

```elixir
@spec negate(input()) :: FastDecimal.t()
```

# `negative?`

```elixir
@spec negative?(input()) :: boolean()
```

# `new`

```elixir
@spec new(input()) :: FastDecimal.t()
```

# `new`

```elixir
@spec new(1 | -1, non_neg_integer(), integer()) :: FastDecimal.t()
```

Decimal-style 3-arg constructor: sign (`1` or `-1`), coef, exp.

# `normalize`

```elixir
@spec normalize(input()) :: FastDecimal.t()
```

# `plus`

```elixir
@spec plus(input()) :: FastDecimal.t()
```

# `positive?`

```elixir
@spec positive?(input()) :: boolean()
```

# `reduce`

```elixir
@spec reduce(input()) :: FastDecimal.t()
```

# `rem`

```elixir
@spec rem(input(), input()) :: FastDecimal.t()
```

# `round`

```elixir
@spec round(input(), integer(), FastDecimal.rounding_mode()) :: FastDecimal.t()
```

# `sqrt`

```elixir
@spec sqrt(
  input(),
  keyword()
) :: FastDecimal.t()
```

# `sub`

```elixir
@spec sub(input(), input()) :: FastDecimal.t()
```

# `to_float`

```elixir
@spec to_float(input()) :: float()
```

# `to_integer`

```elixir
@spec to_integer(input()) :: integer()
```

# `to_string`

```elixir
@spec to_string(input()) :: String.t()
```

# `to_string`

```elixir
@spec to_string(input(), FastDecimal.to_string_format()) :: String.t()
```

# `zero?`

```elixir
@spec zero?(input()) :: boolean()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
