# `ASDF.Float16`
[🔗](https://github.com/baoulo/asdf-elixir/blob/v0.1.0/lib/asdf/float16.ex#L1)

An IEEE binary16 value kept as 16 bits.

`bits` is an integer from `0` to `0xFFFF`. The sign is the high bit, the
exponent is the next 5 bits, and the fraction is the low 10 bits.
`0x3C00` is `1.0`. `0x0000` is `0.0` and `0x8000` is `-0.0`.

`to_float/1` widens finite values, including subnormals, to binary64.
Infinity (`0x7C00`, `0xFC00`) and NaN raise `ASDF.Error` with
`reason: :unsupported_float`. This runtime rejects non-finite floats.
The default array view does not call `to_float/1`.

# `t`

```elixir
@type t() :: %ASDF.Float16{bits: non_neg_integer()}
```

One binary16 value.

  * `:bits` — the 16-bit pattern, `0..0xFFFF`

# `to_float`

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

Widens `float16` to an Elixir float.

`float16` is an `%ASDF.Float16{}`. Finite values, including subnormals
and signed zero, return a float. Infinity and NaN raise `ASDF.Error`
with `reason: :unsupported_float`.

## Examples

    iex> ASDF.Float16.to_float(%ASDF.Float16{bits: 0x3C00})
    1.0

    iex> ASDF.Float16.to_float(%ASDF.Float16{bits: 0xBC00})
    -1.0

    iex> ASDF.Float16.to_float(%ASDF.Float16{bits: 0x8000})
    -0.0

    iex> ASDF.Float16.to_float(%ASDF.Float16{bits: 0x7C00})
    ** (ASDF.Error) float16 infinity is not representable on this runtime

    iex> ASDF.Float16.to_float(%ASDF.Float16{bits: 0x7E00})
    ** (ASDF.Error) float16 NaN is not representable on this runtime

---

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