Commit 11cfb94
committed
Clamp before downcasting in float to i8 conversions
Previously we were downcasting floats to the target type (e.g. int8_t), and then
clamping to [-100, 100] range. This means that e.g. 129 would be cast to -127 and
then converted to -100, in stead of becoming 100
The fix does clamping first, and then casts the resulting number
(which is guaranteed to be in range [-100, 100], due to clamping)
from source type to target int8_t. Given the clamping, this will never overflow.1 parent c453582 commit 11cfb94
1 file changed
+4
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
960 | 960 | | |
961 | 961 | | |
962 | 962 | | |
| 963 | + | |
963 | 964 | | |
964 | | - | |
| 965 | + | |
965 | 966 | | |
966 | | - | |
| 967 | + | |
967 | 968 | | |
968 | | - | |
| 969 | + | |
969 | 970 | | |
970 | 971 | | |
971 | 972 | | |
| |||
0 commit comments