File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -7813,11 +7813,6 @@ cdef double mpz_get_d_nearest(mpz_t x) except? -648555075988944.5:
78137813 # to have 54 bits remaining.
78147814 cdef mp_bitcnt_t shift = sx - 54
78157815
7816- # Compute q = trunc(x / 2^shift) and let remainder_is_zero be True
7817- # if and only if no truncation occurred.
7818- cdef int remainder_is_zero
7819- remainder_is_zero = mpz_divisible_2exp_p(x, shift)
7820-
78217816 sig_on()
78227817
78237818 cdef mpz_t q
@@ -7842,12 +7837,16 @@ cdef double mpz_get_d_nearest(mpz_t x) except? -648555075988944.5:
78427837 # Round towards zero
78437838 pass
78447839 else :
7845- if not remainder_is_zero :
7846- # Remainder is nonzero: round away from zero
7840+ if (q64 & 2 ) == 2 :
7841+ # round to even and round away from zero gives the same result, no need to check
78477842 q64 += 1
78487843 else :
7849- # Halfway case: round to even
7850- q64 += (q64 & 2 ) - 1
7844+ if mpz_divisible_2exp_p(x, shift):
7845+ # Halfway case: round to even
7846+ q64 -= 1
7847+ else :
7848+ # Remainder is nonzero: round away from zero
7849+ q64 += 1
78517850
78527851 # The conversion of q64 to double is *exact*.
78537852 # This is because q64 is even and satisfies 2^53 <= q64 <= 2^54.
You can’t perform that action at this time.
0 commit comments