We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 502d6a1 commit af0ced0Copy full SHA for af0ced0
2 files changed
vlib/math/floor.v
@@ -144,8 +144,7 @@ pub fn round_to_even(x f64) f64 {
144
half_minus_ulp := u64(u64(1) << (shift - 1)) - 1
145
e_ -= u64(bias)
146
bits += (half_minus_ulp + (bits >> (shift - e_)) & 1) >> e_
147
- bits &= frac_mask >> e_
148
- bits ^= frac_mask >> e_
+ bits &= ~(frac_mask >> e_)
149
} else if e_ == bias - 1 && bits & frac_mask != 0 {
150
// round 0.5 < abs(x) < 1.
151
bits = bits & sign_mask | uvone // +-1
vlib/math/floor_test.v
@@ -0,0 +1,6 @@
1
+import math
2
+
3
+fn test_round_to_even() {
4
+ assert math.round_to_even(0.123) == 0.0
5
+ assert math.round_to_even(123.12345) == 123.00
6
+}
0 commit comments