Skip to content

Commit 79cd1f0

Browse files
author
Christoph M. Wintersteiger
committed
Fixed Z3_get_numeral_double. Fixes #2501.
1 parent 258b798 commit 79cd1f0

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/api/api_numeral.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extern "C" {
6969
(' ' == *m) || ('\n' == *m) ||
7070
('.' == *m) || ('e' == *m) ||
7171
('E' == *m) || ('+' == *m) ||
72-
(is_float &&
72+
(is_float &&
7373
(('p' == *m) ||
7474
('P' == *m))))) {
7575
SET_ERROR_CODE(Z3_PARSER_ERROR, nullptr);
@@ -145,7 +145,7 @@ extern "C" {
145145
bool Z3_API Z3_is_numeral_ast(Z3_context c, Z3_ast a) {
146146
Z3_TRY;
147147
LOG_Z3_is_numeral_ast(c, a);
148-
RESET_ERROR_CODE();
148+
RESET_ERROR_CODE();
149149
CHECK_IS_EXPR(a, false);
150150
expr* e = to_expr(a);
151151
return
@@ -228,8 +228,22 @@ extern "C" {
228228
}
229229

230230
double Z3_API Z3_get_numeral_double(Z3_context c, Z3_ast a) {
231-
Z3_string s = Z3_get_numeral_decimal_string(c, a, 12);
232-
return std::stod(std::string(s));
231+
LOG_Z3_get_numeral_double(c, a);
232+
RESET_ERROR_CODE();
233+
if (!is_expr(a)) {
234+
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
235+
return 0.0/0.0;
236+
}
237+
expr* e = to_expr(a);
238+
fpa_util & fu = mk_c(c)->fpautil();
239+
scoped_mpf tmp(fu.fm());
240+
if (!mk_c(c)->fpautil().is_numeral(e, tmp) ||
241+
tmp.get().get_ebits() > 11 ||
242+
tmp.get().get_sbits() > 53) {
243+
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
244+
return 0.0/0.0;
245+
}
246+
return fu.fm().to_double(tmp);
233247
}
234248

235249
Z3_string Z3_API Z3_get_numeral_decimal_string(Z3_context c, Z3_ast a, unsigned precision) {

0 commit comments

Comments
 (0)