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: text/0041-fixed-point.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,10 +74,12 @@ The following operations are defined on it:
74
74
`fixed.Const` is a `fixed.Value` subclass.
75
75
The following additional operations are defined on it:
76
76
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.
78
78
- If `value` is an `int` and `shape` is not specified, the smallest shape that will fit `value` will be selected.
79
79
- If `value` is a `float` and `shape` is not specified, the smallest shape that gives a perfect representation will be selected.
80
80
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`.
81
83
-`.as_integer_ratio()`: Return the value represented as an integer ratio `tuple`.
82
84
-`.as_float()`: Return the value represented as a `float`.
83
85
- Operators are extended to return a `fixed.Const` if all operands are constant.
0 commit comments