Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: creating reals from numeral strings #307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading