Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,28 @@ For `T<:Signed` (a signed integer), there is a fixed-point type
`Normed{T, f}` type. However, there are slight differences in behavior
that go beyond signed/unsigned distinctions.

The `Fixed{T,f}` types use 1 bit for sign, and `f` bits to represent
the fraction. For example, `Fixed{Int8,7}` uses 7 bits (all bits
except the sign bit) for the fractional part. The value of the number
is interpreted as if the integer representation has been divided by
`2^f`. Consequently, `Fixed{Int8,7}` numbers `x` satisfy
A `Fixed{T,f}` number is an integer `i::T` divided by `2^f`. Its range and its
overflow behavior therefore follow those of `T`. For example, `Fixed{Int8,7}`
numbers `x` satisfy

```julia
-1.0 = -128/128 ≤ x ≤ 127/128 ≈ 0.992.
```

because the range of `Int8` is from -128 to 127.
because the range of `Int8` is from -128 to 127. Like `Int8`, `Fixed{Int8,7}`
has a single zero, and the raw value `-1` is the negative number closest to zero:

```julia
julia> reinterpret(Q0f7, Int8(-1))
-0.008Q0f7
```

The `QXfY` aliases follow the Texas Instruments variant of the [Q notation]:
`Y` is the number of fraction bits, and `X+Y+1` equals the number of bits of
`T`. For example, `Q0f7` is aliased to `Fixed{Int8,7}` and `Q3f12` to
`Fixed{Int16,12}`. Unlike for the `NXfY` aliases below, `X+Y` is one less than
the number of bits, so `Fixed{Int8,0}`, which represents the same values as
`Int8`, is called `Q7f0`.

In contrast, the `Normed{T,f}`, with `f` fraction bits, map the closed
interval [0.0,1.0] to the span of numbers with `f` bits. For example,
Expand Down Expand Up @@ -141,6 +152,7 @@ Please see [CONTRIBUTING.md](CONTRIBUTING.md) for information about improving th

[fixed-point number]: http://en.wikipedia.org/wiki/Fixed-point_arithmetic
[overflow]: https://en.wikipedia.org/wiki/Integer_overflow
[Q notation]: https://en.wikipedia.org/wiki/Q_(number_format)
[rounding]: https://en.wikipedia.org/wiki/Round-off_error
[underflow]: https://en.wikipedia.org/wiki/Arithmetic_underflow

Expand Down
Loading