Skip to content

Commit

Permalink
feat: exact f64 from Real
Browse files Browse the repository at this point in the history
  • Loading branch information
lucascool12 committed Aug 2, 2024
1 parent 42bae5f commit 2f32da9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions z3/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,20 @@ impl<'ctx> Real<'ctx> {
self.approx(17).parse().unwrap() // 17 decimal digits needed to get full f64 precision
}

pub fn exact_f64(&self) -> Option<f64> {
let res = unsafe { Z3_get_numeral_double(self.get_ctx().z3_ctx, self.z3_ast) };
if res == 0.0 {
let mut sacrifice_int = 0;
let int_res = unsafe {
Z3_get_numeral_int(self.get_ctx().z3_ctx, self.z3_ast, &mut sacrifice_int)
};
if !int_res || sacrifice_int != 0 {
return None;
}
}
return Some(res);
}

pub fn from_int(ast: &Int<'ctx>) -> Real<'ctx> {
unsafe { Self::wrap(ast.ctx, Z3_mk_int2real(ast.ctx.z3_ctx, ast.z3_ast)) }
}
Expand Down

0 comments on commit 2f32da9

Please sign in to comment.