mirror of
https://github.com/Z3Prover/z3
synced 2026-02-28 10:51:28 +00:00
Add support for Python Fraction object
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
d0d48c7ce2
commit
a51c6d125d
2 changed files with 19 additions and 0 deletions
|
|
@ -44,6 +44,7 @@ from z3core import *
|
|||
from z3types import *
|
||||
from z3consts import *
|
||||
from z3printer import *
|
||||
from fractions import Fraction
|
||||
import sys
|
||||
import io
|
||||
|
||||
|
|
@ -2523,6 +2524,15 @@ class RatNumRef(ArithRef):
|
|||
"""
|
||||
return Z3_get_numeral_string(self.ctx_ref(), self.as_ast())
|
||||
|
||||
def as_fraction(self):
|
||||
"""Return a Z3 rational as a Python Fraction object.
|
||||
|
||||
>>> v = RealVal("1/5")
|
||||
>>> v.as_fraction()
|
||||
Fraction(1, 5)
|
||||
"""
|
||||
return Fraction(self.numerator_as_long(), self.denominator_as_long())
|
||||
|
||||
class AlgebraicNumRef(ArithRef):
|
||||
"""Algebraic irrational values."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue