Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cvc5_pythonic_api/cvc5_pythonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3505,8 +3505,20 @@ def RealVal(val, ctx=None):
3/5
>>> RealVal("1.5")
3/2
>>> RealVal(1.5)
3/2
>>> RealVal(1e-5)
1/100000
>>> RealVal(1e-11).eq(RatVal(1, 10**11))
True
"""
ctx = _get_ctx(ctx)
if isinstance(val, float):
# `str` may use scientific notation (e.g. `str(1e-5) == '1e-05'`),
# which `mkReal` does not accept. `repr` gives the shortest decimal
# that round-trips to `val`, and formatting the resulting `Decimal`
# with `'f'` expands it without an exponent and without rounding.
return RatNumRef(ctx.tm.mkReal(format(Decimal(repr(val)), "f")), ctx)
return RatNumRef(ctx.tm.mkReal(str(val)), ctx)


Expand Down
Loading