You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-15Lines changed: 23 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,21 +15,29 @@ used like any other number: they can be added, multiplied, raised to a power,
15
15
etc. In many cases these operations result in conversion to floating-point types.
16
16
17
17
# Type hierarchy
18
-
This library defines an abstract type `FixedPoint{T <: Integer, f}` as a subtype of `Real`. The parameter `T` is the underlying representation and `f` is the number of fraction bits.
19
-
20
-
For signed integers, there is a fixed-point type `Fixed{T, f}` and for unsigned integers, there is the `UFixed{T, f}` type.
21
-
22
-
These types, built with `f` fraction bits, map the closed interval [0.0,1.0]
23
-
to the span of numbers with `f` bits.
24
-
For example, the `UFixed8` type is represented internally by a `UInt8`, and makes
25
-
`0x00` equivalent to `0.0` and `0xff` to `1.0`.
26
-
The types `UFixed10`, `UFixed12`, `UFixed14`, and `UFixed16` are all based on `UInt16`
27
-
and reach the value `1.0` at 10, 12, 14, and 16 bits, respectively (`0x03ff`, `0x0fff`,
28
-
`0x3fff`, and `0xffff`).
29
-
30
-
To construct such a number, use `convert(UFixed12, 1.3)`, `ufixed12(1.3)`, or the literal syntax `0x14ccuf12`.
31
-
The latter syntax means to construct a `UFixed12` (it ends in `uf12`) from the `UInt16` value
32
-
`0x14cc`.
18
+
This library defines an abstract type `FixedPoint{T <: Integer, f}` as a
19
+
subtype of `Real`. The parameter `T` is the underlying representation and `f`
20
+
is the number of fraction bits.
21
+
22
+
For signed integers, there is a fixed-point type `Fixed{T, f}` and for unsigned
23
+
integers, there is the `UFixed{T, f}` type.
24
+
25
+
These types, built with `f` fraction bits, map the closed interval [0.0,1.0] to
26
+
the span of numbers with `f` bits. For example, the `UFixed8` type (aliased to
27
+
UFixed{UInt8,8}) is represented internally by a `UInt8`, and makes `0x00`
28
+
equivalent to `0.0` and `0xff` to `1.0`. The type aliases `UFixed10`, `UFixed12`,
29
+
`UFixed14`, and `UFixed16` are all based on `UInt16` and reach the value `1.0`
30
+
at 10, 12, 14, and 16 bits, respectively (`0x03ff`, `0x0fff`, `0x3fff`, and
31
+
`0xffff`).
32
+
33
+
To construct such a number, use `convert(UFixed12, 1.3)`, `ufixed12(1.3)` (a
34
+
convenience function), `UFixed{UInt16,12}`, or the literal syntax `0x14ccuf12`.
35
+
The latter syntax means to construct a `UFixed12` (it ends in `uf12`) from the
36
+
`UInt16` value `0x14cc`.
37
+
38
+
More generally, an arbitrary number of bits from any of the standard unsigned
39
+
integer widths can be used for the fractional part. For example:
0 commit comments