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

Implement ast::Float::as_f64 #252

Merged
merged 1 commit into from
Oct 25, 2023
Merged

Implement ast::Float::as_f64 #252

merged 1 commit into from
Oct 25, 2023

Conversation

waywardmonkeys
Copy link
Contributor

@waywardmonkeys
Copy link
Contributor Author

@Pat-Lafon Any thoughts on this?

@Pat-Lafon
Copy link
Contributor

Simple enough! Though it is kinda weird that the other .as_*() functions return an optional. Here sometimes you will get 0.0 because the error facilities are suppressed.

#[test]
fn test_float() {
    let cfg = Config::new();
    let ctx = Context::new(&cfg);

/*     let f = ast::Float::from_f64(&ctx, 1.0); */
    let f = ast::Float::new_const_double(&ctx, "test");
    assert_eq!(f.as_f64(), 0.0);
}

@waywardmonkeys
Copy link
Contributor Author

The underlying API from Z3 differs though which is kind of unfortunate. The C++ binding checks the error code. The C# binding does not. Interestingly (perhaps), other bindings don't seem to call Z3_get_numeral_double().

Maybe I should do so here and return an Option? Although it would be nice to have a more ergonomic way to check that error than we do now ... (There's so much un-ergonomic about this code.)

@waywardmonkeys waywardmonkeys merged commit c2bff76 into master Oct 25, 2023
7 checks passed
@Pat-Lafon
Copy link
Contributor

What do you think would be the more ergonomic solution? Should most of these functions return a result type so the error is not suppressed? (Relying on a lot of ? everywhere) Runtime assertion panic on a case by case basis?

@waywardmonkeys waywardmonkeys deleted the ast-float-as-f64 branch October 26, 2023 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rust Z3. How can I convert Float to f32/f64?
2 participants