Skip to content

Commit 7ffc6be

Browse files
committed
Add as_integer_ratio for circuitpython
1 parent 6768677 commit 7ffc6be

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

jepler_udecimal/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@
158158
except NameError:
159159
NotImplemented = object()
160160

161+
if sys.implementation.name == "circuitpython":
162+
163+
def as_integer_ratio(f):
164+
m, e = _math.frexp(f)
165+
m = round(m * (1 << 53))
166+
e = e - 53
167+
if e > 0:
168+
return m * (1 << e), 1
169+
else:
170+
return m, (1 << (-e))
171+
172+
173+
else:
174+
as_integer_ratio = float.as_integer_ratio
175+
161176
# Errors
162177

163178

@@ -722,7 +737,7 @@ def from_float(cls, f):
722737
sign = 0
723738
else:
724739
sign = 1
725-
n, d = abs(f).as_integer_ratio()
740+
n, d = as_integer_ratio(abs(f))
726741
k = d.bit_length() - 1
727742
coeff = str(n * 5 ** k)
728743
else:

0 commit comments

Comments
 (0)