Skip to content

Commit 332729b

Browse files
committed
fmod: Normalize subnormals to maximum precision
Discussed at [1], there was an off-by-one mistake when converting from the loop routine to using `leading_zeros` for normalization. Currently, using `EXP_BITS` has the effect that `ix` after the branch has its MSB _one bit to the left_ of the implicit bit's position, whereas a shift by `EXP_BITS + 1` ensures that the MSB is exactly at the implicit bit's position, matching what is done for normals (where the implicit bit is set to be explicit). This doesn't seem to have any effect in our implementation since the failing test cases from [1] appear to still have correct results. Since the result of using `EXP_BITS + 1` is more consistent with what is done for normals, apply this here. [1]: #469 (comment)
1 parent 05fd5f2 commit 332729b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/math/generic/fmod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn fmod<F: Float>(x: F, y: F) -> F {
2626

2727
/* normalize x and y */
2828
if ex == 0 {
29-
let i = ix << F::EXP_BITS;
29+
let i = ix << (F::EXP_BITS + 1);
3030
ex -= i.leading_zeros() as i32;
3131
ix <<= -ex + 1;
3232
} else {
@@ -35,7 +35,7 @@ pub fn fmod<F: Float>(x: F, y: F) -> F {
3535
}
3636

3737
if ey == 0 {
38-
let i = iy << F::EXP_BITS;
38+
let i = iy << (F::EXP_BITS + 1);
3939
ey -= i.leading_zeros() as i32;
4040
iy <<= -ey + 1;
4141
} else {

0 commit comments

Comments
 (0)