Skip to content

Commit

Permalink
transformers - use repr instead of str for casting float to Rational
Browse files Browse the repository at this point in the history
The documentation guarantees that for float x this would always be true
float(repr(x)) == x
  • Loading branch information
idanpa committed Dec 4, 2024
1 parent de6e038 commit b3c1dc0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion calcpy/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def visit_Constant(self, node):
if self.ip.calcpy.auto_rational:
if isinstance(node.value, float):
return ast.Call(func=ast.Name(id='Rational', ctx=ast.Load()),
args=[ast.Call(func=ast.Name(id='str', ctx=ast.Load()),
args=[ast.Call(func=ast.Name(id='repr', ctx=ast.Load()),
args=[node], keywords=[])],
keywords=[])
return self.generic_visit(node)
Expand Down

0 comments on commit b3c1dc0

Please sign in to comment.