Skip to content

Commit bfc059f

Browse files
committed
feat: exact f64 from Real
1 parent 42bae5f commit bfc059f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

z3/src/ast.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,20 @@ impl<'ctx> Real<'ctx> {
946946
self.approx(17).parse().unwrap() // 17 decimal digits needed to get full f64 precision
947947
}
948948

949+
pub fn exact_f64(&self) -> Option<f64> {
950+
let res = unsafe { Z3_get_numeral_double(self.get_ctx().z3_ctx, self.z3_ast) };
951+
if res == 0.0 {
952+
let mut sacrifice_int = 0;
953+
let int_res = unsafe {
954+
Z3_get_numeral_int(self.get_ctx().z3_ctx, self.z3_ast, &mut sacrifice_int)
955+
};
956+
if !int_res || sacrifice_int != 0 {
957+
return None;
958+
}
959+
}
960+
Some(res)
961+
}
962+
949963
pub fn from_int(ast: &Int<'ctx>) -> Real<'ctx> {
950964
unsafe { Self::wrap(ast.ctx, Z3_mk_int2real(ast.ctx.z3_ctx, ast.z3_ast)) }
951965
}

0 commit comments

Comments
 (0)