3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-20 04:43:39 +00:00

Fixed Z3_get_numeral_double. Fixes #2501.

This commit is contained in:
Christoph M. Wintersteiger 2019-08-19 12:36:42 +01:00
parent 258b798a6b
commit 79cd1f0edc
No known key found for this signature in database
GPG key ID: BCF6360F86294467

View file

@ -228,8 +228,22 @@ extern "C" {
}
double Z3_API Z3_get_numeral_double(Z3_context c, Z3_ast a) {
Z3_string s = Z3_get_numeral_decimal_string(c, a, 12);
return std::stod(std::string(s));
LOG_Z3_get_numeral_double(c, a);
RESET_ERROR_CODE();
if (!is_expr(a)) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return 0.0/0.0;
}
expr* e = to_expr(a);
fpa_util & fu = mk_c(c)->fpautil();
scoped_mpf tmp(fu.fm());
if (!mk_c(c)->fpautil().is_numeral(e, tmp) ||
tmp.get().get_ebits() > 11 ||
tmp.get().get_sbits() > 53) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return 0.0/0.0;
}
return fu.fm().to_double(tmp);
}
Z3_string Z3_API Z3_get_numeral_decimal_string(Z3_context c, Z3_ast a, unsigned precision) {