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
- If `other` is a `Value`, it'll be cast to a `fixed.Value` first.
69
68
- If `other` is an `int`, it'll be cast to a `fixed.Const` first.
70
-
- If `other` is a `float`: TBD
69
+
- If `other` is a `float`, this is not permitted. The `float` must be explicitly cast to `fixed.Const`.
71
70
- The result will be a new `fixed.Value` with enough precision to hold any resulting value without rounding or overflowing.
72
71
-`.__lshift__(other)`, `.__rshift__(other)`: Bit shift operators.
73
72
-`other` only accepts integral types. For example, shifting by a `float` or `fixed.Value` is not permitted.
@@ -128,22 +127,29 @@ TBD
128
127
However, since a Python `float` is double precision, this means it's easy to make a >50 bit number by accident by doing something like `value * (1 / 3)`, and even if the result is rounded or truncated afterwards, the lower bits can affect rounding and thus won't be optimized out in synthesis.
129
128
- We could use the same width for `other` as for `self`, adjusted to the appropriate exponent for the value.
130
129
- We could outright reject it, requiring the user to explicitly specify precision like e.g. `value * Q(15).const(1 / 3)`.
130
+
- vk2seb@: I would lean toward outright rejecting this, with an explicit cast necessary (now reflected above).
131
131
132
132
- How should we handle rounding?
133
133
- Truncating and adding the most significant truncated bit is cheap and is effectively round to nearest with ties rounded towards positive infinity.
134
134
- Simply truncating is free, rounds towards negative infinity.
135
135
- IEEE 754 defaults to round to nearest, ties to even, which is more expensive to implement.
136
136
- Should we make it user selectable?
137
137
- We still need a default mode used when a higher precision number is passed to `.eq()`.
138
+
- vk2seb@: Both truncation and simple rounding (round to nearest) are commonly used in DSP algorithms. For now, we provide only `truncate()` and `round()` strategies (now reflected above). Additional rounding strategies may be added in a future RFC, however we will always need a default rounding strategy.
138
139
139
140
- Are there any other operations that would be good to have?
141
+
- From ld-cd@: `min()`, `max()` on `fixed.Shape` (vk2seb@: agree, heavily use this)
142
+
- From ld-cd@: `numerator()` as a signedness-preserving `as_value()` (vk2seb@: agree, heavily use this)
143
+
- vk2seb@: Let's add both of these operations (now reflected above)
140
144
141
145
- Are there any operations that would be good to *not* have?
142
146
- This API (`fixed.Shape.cast()`) seems confusing and difficult to use. Should we expose it at all? (@whitequark)
147
+
- vk2seb@: It can survive as a building block but I don't see why it needs to be exposed. Propose removal (reflected above).
143
148
144
149
-`Decimal` and/or `Fraction` support?
145
150
- This could make sense to have, but both can represent values that's not representable as binary fixed point.
146
151
On the other hand, a Python `float` can perfectly represent any fixed point value up to a total width of 53 bits and any `float` value is perfectly representable as fixed point.
152
+
- vk2seb@: As both can represent values that aren't representable as binary fixed point, I don't see a huge benefit. I also can't immediately think of an application that would need >53 bit constants. I would propose for now we leave `Decimal` and `Fraction` out of scope of this RFC.
147
153
148
154
- Name all the things.
149
155
- Library name:
@@ -154,6 +160,12 @@ TBD
154
160
-`.int_bits`, `.frac_bits`?
155
161
- cursed option: `int, frac = x.width`?
156
162
-`.round()` is a bit awkwardly named when it's used both to increase and decrease precision.
163
+
- vk2seb@: The existing modifications address this:
164
+
- Library name: `lib.fixed`
165
+
- Type names and shapes: signature has now been updated to use `i_bits`, `f_bits` and the explicit underlying storage in the constructor for `fixed.Shape`.
166
+
- We now have both `.round()` and `.truncate()`. I don't think using the same name for increasing and decreasing precision is so bad. But if you feel strongly about this we may consider:
167
+
- Renaming them.
168
+
- Disallowing increasing precision with these methods, and add a new method for precision extension .
0 commit comments