@@ -69,7 +69,7 @@ extern "C" {
69
69
(' ' == *m) || (' \n ' == *m) ||
70
70
(' .' == *m) || (' e' == *m) ||
71
71
(' E' == *m) || (' +' == *m) ||
72
- (is_float &&
72
+ (is_float &&
73
73
((' p' == *m) ||
74
74
(' P' == *m))))) {
75
75
SET_ERROR_CODE (Z3_PARSER_ERROR, nullptr );
@@ -145,7 +145,7 @@ extern "C" {
145
145
bool Z3_API Z3_is_numeral_ast (Z3_context c, Z3_ast a) {
146
146
Z3_TRY;
147
147
LOG_Z3_is_numeral_ast (c, a);
148
- RESET_ERROR_CODE ();
148
+ RESET_ERROR_CODE ();
149
149
CHECK_IS_EXPR (a, false );
150
150
expr* e = to_expr (a);
151
151
return
@@ -228,8 +228,22 @@ extern "C" {
228
228
}
229
229
230
230
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);
233
247
}
234
248
235
249
Z3_string Z3_API Z3_get_numeral_decimal_string (Z3_context c, Z3_ast a, unsigned precision) {
0 commit comments