3
0
Fork 0
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:
Leonardo de Moura 2012-12-28 13:39:34 -08:00
parent d0d48c7ce2
commit a51c6d125d
2 changed files with 19 additions and 0 deletions

View file

@ -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."""