Skip to content

Commit d79ff6e

Browse files
Add fast path for float conversion of numbers below 1023 bits
1 parent 3fe9723 commit d79ff6e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/flint/types/fmpz.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ cdef class fmpz(flint_scalar):
106106
return fmpz_get_intlong(self.val)
107107

108108
def __float__(self):
109+
if fmpz_bits(self.val) <= 1023:
110+
# Known to be representable by a IEEE-754 double
111+
return fmpz_get_d(self.val)
112+
109113
cdef slong exp
110114
# fmpz_get_d_2exp is always accurate
111115
# math.ldexp handles overflow checks

0 commit comments

Comments
 (0)