[encode_real8] improve handling of tiny floats

This commit is contained in:
jan 2026-03-09 01:52:03 -07:00
commit 56a99c8e58

View file

@ -149,7 +149,7 @@ def encode_real8(fnums: NDArray[numpy.float64]) -> NDArray[numpy.uint64]:
gds_exp = exp16 + 64 gds_exp = exp16 + 64
neg_biased = (gds_exp < 0) neg_biased = (gds_exp < 0)
gds_mant[neg_biased] >>= (gds_exp[neg_biased] * 4).astype(numpy.uint16) gds_mant[neg_biased] >>= (-gds_exp[neg_biased] * 4).astype(numpy.uint16)
gds_exp[neg_biased] = 0 gds_exp[neg_biased] = 0
too_big = (gds_exp > 0x7f) & ~(zero | subnorm) too_big = (gds_exp > 0x7f) & ~(zero | subnorm)
@ -160,7 +160,6 @@ def encode_real8(fnums: NDArray[numpy.float64]) -> NDArray[numpy.uint64]:
real8 = sign | gds_exp_bits | gds_mant real8 = sign | gds_exp_bits | gds_mant
real8[zero] = 0 real8[zero] = 0
real8[gds_exp < -14] = 0 # number is too small
return real8.astype(numpy.uint64, copy=False) return real8.astype(numpy.uint64, copy=False)