Skip to content

Commit cd8c9bc

Browse files
vk2sebzyp
authored andcommitted
fixed.Const: add clamp argument used for interpreting constants
1 parent 6d5b91b commit cd8c9bc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

text/0041-fixed-point.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ The following operations are defined on it:
7474
`fixed.Const` is a `fixed.Value` subclass.
7575
The following additional operations are defined on it:
7676

77-
- `fixed.Const(value, shape=None)`: Create a `fixed.Const` from `value`. `shape` must be a `fixed.Shape` if specified.
77+
- `fixed.Const(value, shape=None, clamp=False)`: Create a `fixed.Const` from `value`. `shape` must be a `fixed.Shape` if specified.
7878
- If `value` is an `int` and `shape` is not specified, the smallest shape that will fit `value` will be selected.
7979
- If `value` is a `float` and `shape` is not specified, the smallest shape that gives a perfect representation will be selected.
8080
If `shape` is specified, `value` will be rounded to the closest representable value first.
81+
- If `shape` is specified and `value` is too large to be represented by that shape, an exception is thrown.
82+
- The exception invites the user to try `clamp=True` to squash this exception, instead clamping the constant to the maximum / minimum value representable by the provided `shape`.
8183
- `.as_integer_ratio()`: Return the value represented as an integer ratio `tuple`.
8284
- `.as_float()`: Return the value represented as a `float`.
8385
- Operators are extended to return a `fixed.Const` if all operands are constant.

0 commit comments

Comments
 (0)