Skip to content

Commit

Permalink
feat: creating reals from numeral strings
Browse files Browse the repository at this point in the history
  • Loading branch information
lucascool12 committed Aug 2, 2024
1 parent 42bae5f commit 84bf1f4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions z3/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,17 @@ impl<'ctx> Real<'ctx> {
}

pub fn from_real_str(ctx: &'ctx Context, num: &str, den: &str) -> Option<Real<'ctx>> {
let fraction_string = format!("{num:} / {den:}");
Self::from_str(ctx, &fraction_string)
}

/// The string may be of the form \[num\]*\[.\[num\]*\]\[E\[+|-\]\[num\]...+\].
/// Or a rational, that is, a string of the form \[num\]* / \[num\]*
pub fn from_str(ctx: &'ctx Context, numeral: &str) -> Option<Real<'ctx>> {
let sort = Sort::real(ctx);
let ast = unsafe {
let fraction_cstring = CString::new(format!("{num:} / {den:}")).unwrap();
let numeral_ptr = Z3_mk_numeral(ctx.z3_ctx, fraction_cstring.as_ptr(), sort.z3_sort);
let c_numeral = CString::new(numeral).unwrap();
let numeral_ptr = Z3_mk_numeral(ctx.z3_ctx, c_numeral.as_ptr(), sort.z3_sort);
if numeral_ptr.is_null() {
return None;
}
Expand Down

0 comments on commit 84bf1f4

Please sign in to comment.