3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-27 10:55:50 +00:00

Refactored FPA numeral accessors.

This commit is contained in:
Christoph M. Wintersteiger 2016-10-21 17:39:31 +01:00
parent 0a11e8f3c0
commit abcb6040d4
6 changed files with 175 additions and 172 deletions

View file

@ -8445,31 +8445,7 @@ class FPNumRef(FPRef):
def isNegative(self):
k = self.decl().kind()
return (self.num_args() == 0 and (k == Z3_OP_FPA_MINUS_INF or k == Z3_OP_FPA_MINUS_ZERO)) or (self.sign() == True)
"""
The sign of a floating-point numeral as a bit-vector expression
Remark: NaN's do not have a bit-vector sign, so they are invalid arguments.
"""
def BVSign(self):
return BitVecNumRef(Z3_fpa_get_numeral_sign_bv(self.ctx.ref(), self.as_ast()), ctx)
"""
The exponent of a floating-point numeral as a bit-vector expression
Remark: +oo, -oo and NaN's do not have a bit-vector exponent, so they are invalid arguments.
"""
def BVExponent(self):
return BitVecNumRef(Z3_fpa_get_numeral_exponent_bv(self.ctx.ref(), self.as_ast()), ctx)
"""
The sign of a floating-point numeral as a bit-vector expression
Remark: +oo, -oo and NaN's do not have a bit-vector significand, so they are invalid arguments.
"""
def BVSignificand(self):
return BitVecNumRef(Z3_fpa_get_numeral_significand_bv(self.ctx.ref(), self.as_ast()), ctx)
"""
The sign of the numeral.
@ -8486,6 +8462,15 @@ class FPNumRef(FPRef):
raise Z3Exception("error retrieving the sign of a numeral.")
return l.value != 0
"""
The sign of a floating-point numeral as a bit-vector expression
Remark: NaN's are invalid arguments.
"""
def sign_as_bv(self):
return BitVecNumRef(Z3_fpa_get_numeral_sign_bv(self.ctx.ref(), self.as_ast()), self.ctx)
"""
The significand of the numeral.
@ -8495,6 +8480,14 @@ class FPNumRef(FPRef):
"""
def significand(self):
return Z3_fpa_get_numeral_significand_string(self.ctx.ref(), self.as_ast())
"""
The significand of a floating-point numeral as a bit-vector expression
Remark: NaN are invalid arguments.
"""
def significand_as_bv(self):
return BitVecNumRef(Z3_fpa_get_numeral_significand_bv(self.ctx.ref(), self.as_ast()), self.ctx)
"""
The exponent of the numeral.
@ -8503,8 +8496,8 @@ class FPNumRef(FPRef):
>>> x.exponent()
1
"""
def exponent(self):
return Z3_fpa_get_numeral_exponent_string(self.ctx.ref(), self.as_ast())
def exponent(self, biased=True):
return Z3_fpa_get_numeral_exponent_string(self.ctx.ref(), self.as_ast(), biased)
"""
The exponent of the numeral as a long.
@ -8513,12 +8506,21 @@ class FPNumRef(FPRef):
>>> x.exponent_as_long()
1
"""
def exponent_as_long(self):
def exponent_as_long(self, biased=True):
ptr = (ctypes.c_longlong * 1)()
if not Z3_fpa_get_numeral_exponent_int64(self.ctx.ref(), self.as_ast(), ptr):
if not Z3_fpa_get_numeral_exponent_int64(self.ctx.ref(), self.as_ast(), ptr, biased):
raise Z3Exception("error retrieving the exponent of a numeral.")
return ptr[0]
"""
The exponent of a floating-point numeral as a bit-vector expression
Remark: NaNs are invalid arguments.
"""
def exponent_as_bv(self, biased=True):
return BitVecNumRef(Z3_fpa_get_numeral_exponent_bv(self.ctx.ref(), self.as_ast(), biased), self.ctx)
"""
The string representation of the numeral.
@ -8527,7 +8529,7 @@ class FPNumRef(FPRef):
1.25*(2**4)
"""
def as_string(self):
s = Z3_fpa_get_numeral_string(self.ctx.ref(), self.as_ast())
s = Z3_get_numeral_string(self.ctx.ref(), self.as_ast())
return ("FPVal(%s, %s)" % (s, self.sort()))
def is_fp(a):

View file

@ -620,8 +620,8 @@ class Formatter:
r = []
sgn = c_int(0)
sgnb = Z3_fpa_get_numeral_sign(a.ctx_ref(), a.ast, byref(sgn))
exp = Z3_fpa_get_numeral_exponent_string(a.ctx_ref(), a.ast, False)
sig = Z3_fpa_get_numeral_significand_string(a.ctx_ref(), a.ast)
exp = Z3_fpa_get_numeral_exponent_string(a.ctx_ref(), a.ast)
r.append(to_format('FPVal('))
if sgnb and sgn.value != 0:
r.append(to_format('-'))
@ -650,8 +650,8 @@ class Formatter:
r = []
sgn = (ctypes.c_int)(0)
sgnb = Z3_fpa_get_numeral_sign(a.ctx_ref(), a.ast, byref(sgn))
exp = Z3_fpa_get_numeral_exponent_string(a.ctx_ref(), a.ast, False)
sig = Z3_fpa_get_numeral_significand_string(a.ctx_ref(), a.ast)
exp = Z3_fpa_get_numeral_exponent_string(a.ctx_ref(), a.ast)
if sgnb and sgn.value != 0:
r.append(to_format('-'))
r.append(to_format(sig))