Skip to content

Commit 6e96901

Browse files
mkittiGemini CLI
andcommitted
Refactor fixed-point data types to a single parameterized type
Co-authored-by: Gemini CLI <[email protected]>
1 parent 1d33a40 commit 6e96901

File tree

483 files changed

+115
-9661
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

483 files changed

+115
-9661
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Binary Fixed-Point Data Type
2+
3+
A parameterized data type for binary fixed-point numbers.
4+
5+
**Status:** proposal
6+
7+
## Data type name
8+
9+
`binary_fixed_point`
10+
11+
## Configuration
12+
13+
This data type represents a binary fixed-point number based on an underlying integer type.
14+
It is defined by a base integer type, the number of fractional bits, and the number of integer bits.
15+
16+
- **`base_data_type`**: The underlying integer data type. Must be one of `uint8`, `uint16`, `uint32`, `uint64`, `int8`, `int16`, `int32`, `int64`.
17+
- **`fractional_bits`**: The number of bits representing the fractional part.
18+
- **`integer_bits`**: The number of bits representing the integer part.
19+
20+
## Interpretation
21+
22+
The value is interpreted as:
23+
$$ v = i \times 2^{-f} $$
24+
where $i$ is the integer value stored in the `base_data_type` and $f$ is `fractional_bits`.
25+
26+
- If `base_data_type` is signed, $i$ is a signed integer.
27+
- If `base_data_type` is unsigned, $i$ is an unsigned integer.
28+
29+
## Q Notation
30+
31+
Fixed-point numbers are commonly described using "Q notation", often written as `Qn.m`. To avoid ambiguity, we define the relationship between the `Qn.m` notation and this data type's parameters as follows:
32+
33+
- **`n`** (the first number) corresponds to **`integer_bits`**.
34+
- **`m`** (the second number) corresponds to **`fractional_bits`**.
35+
36+
### Relationship to Base Data Type
37+
38+
The choice of `base_data_type` (bit width $W$) limits the possible values for `integer_bits` and `fractional_bits`.
39+
40+
- **Signed Types (`int*`)**:
41+
The underlying type must accommodate the sign bit, integer bits, and fractional bits.
42+
$$ W \ge 1 + \text{integer\_bits} (n) + \text{fractional\_bits} (m) $$
43+
*Example:* `Q1.14` (1 integer, 14 fractional) requires $1 + 1 + 14 = 16$ bits, fitting into `int16`.
44+
45+
- **Unsigned Types (`uint*`)**:
46+
The underlying type must accommodate the integer bits and fractional bits. Unsigned fixed-point is sometimes denoted as `UQn.m`.
47+
$$ W \ge \text{integer\_bits} (n) + \text{fractional\_bits} (m) $$
48+
*Example:* `UQ8.8` (8 integer, 8 fractional) requires $8 + 8 = 16$ bits, fitting into `uint16`.
49+
50+
## Fill value representation
51+
52+
The `fill_value` SHOULD be represented as a JSON number with the value to be represented.
53+
To represent the underlying integer bits exactly, the `fill_value` MAY be provided as a hexadecimal string representing the underlying integer (e.g., `"0x0000"`).
54+
55+
## Examples
56+
57+
| Configuration | Q Notation | Description | Range (approx) |
58+
|---|---|---|---|
59+
| `{"base_data_type": "int16", "fractional_bits": 15, "integer_bits": 0}` | Q0.15 | Signed 16-bit, 15 fractional bits | -1.0 to 0.99997 |
60+
| `{"base_data_type": "uint16", "fractional_bits": 8, "integer_bits": 8}` | UQ8.8 | Unsigned 16-bit, 8 fractional bits | 0.0 to 255.996 |
61+
| `{"base_data_type": "int32", "fractional_bits": 16, "integer_bits": 15}` | Q15.16 | Signed 32-bit, 16 fractional bits | -32768.0 to 32767.99998 |
62+
63+
## See also
64+
65+
- [FixedPointNumbers.jl](https://github.com/JuliaMath/FixedPointNumbers.jl) (Note: roughly corresponds to `Fixed{T, f}`)
66+
- [Rust `fixed` crate](https://crates.io/crates/fixed)
67+
68+
## Current maintainers
69+
70+
- Mark Kittisopikul (@mkitti), Howard Hughes Medical Institute
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"type": "object",
4+
"properties": {
5+
"name": {
6+
"const": "binary_fixed_point"
7+
},
8+
"configuration": {
9+
"type": "object",
10+
"properties": {
11+
"base_data_type": {
12+
"enum": [
13+
"uint8",
14+
"uint16",
15+
"uint32",
16+
"uint64",
17+
"int8",
18+
"int16",
19+
"int32",
20+
"int64"
21+
]
22+
},
23+
"fractional_bits": {
24+
"type": "integer",
25+
"minimum": 0
26+
},
27+
"integer_bits": {
28+
"type": "integer",
29+
"minimum": 0
30+
}
31+
},
32+
"required": [
33+
"base_data_type",
34+
"fractional_bits",
35+
"integer_bits"
36+
],
37+
"additionalProperties": false
38+
}
39+
},
40+
"required": [
41+
"name",
42+
"configuration"
43+
],
44+
"additionalProperties": false
45+
}

data-types/fixed-point/N0f16/README.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

data-types/fixed-point/N0f16/schema.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

data-types/fixed-point/N0f32/README.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

data-types/fixed-point/N0f32/schema.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

data-types/fixed-point/N0f64/README.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

data-types/fixed-point/N0f64/schema.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

data-types/fixed-point/N0f8/README.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

data-types/fixed-point/N0f8/schema.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)