Skip to content

Commit 5eaba6c

Browse files
vk2sebzyp
authored andcommitted
fixed.Value: prohibit arithmetic operators on difficult-to-reason-about arguments
1 parent b3121b1 commit 5eaba6c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

text/0041-fixed-point.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,14 @@ The following operations are defined on it:
6969
- If `other` is a `float`: TBD
7070
- The result will be a new `fixed.Value` with enough precision to hold any resulting value without rounding or overflowing.
7171
- `.__lshift__(other)`, `.__rshift__(other)`: Bit shift operators.
72+
- `other` only accepts integral types. For example, shifting by a `float` or `fixed.Value` is not permitted.
7273
- `.__neg__()`, `.__pos__()`, `.__abs__()`: Unary arithmetic operators.
7374
- `.__lt__(other)`, `.__le__(other)`, `.__eq__(other)`, `.__ne__(other)`, `.__gt__(other)`, `.__ge__(other)`: Comparison operators.
75+
- Comparisons between `fixed.Value` of matching size, or between `fixed.Value` and `int` are permitted.
76+
- Comparisons between `fixed.Value` of different widths are not permitted.
77+
- Users are guided by an exception to explicitly `truncate()` or `round()` as needed.
78+
- Comparisons between `fixed.Value` and `float` are not permitted.
79+
- Users are guided by an exception to explicitly convert using `fixed.Const` as needed.
7480

7581
### `fixed.Const`
7682

0 commit comments

Comments
 (0)