Skip to content

Commit f22d6e3

Browse files
author
Christoph M. Wintersteiger
committed
Fix floats in Z3_get_numeral_*string.
1 parent 79cd1f0 commit f22d6e3

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/api/api_numeral.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ extern "C" {
192192
return mk_c(c)->mk_external_string(r.to_string());
193193
}
194194
else {
195-
// floats are separated from all others to avoid huge rationals.
196195
fpa_util & fu = mk_c(c)->fpautil();
197196
scoped_mpf tmp(fu.fm());
198197
mpf_rounding_mode rm;
@@ -217,7 +216,9 @@ extern "C" {
217216
}
218217
}
219218
else if (mk_c(c)->fpautil().is_numeral(to_expr(a), tmp)) {
220-
return mk_c(c)->mk_external_string(fu.fm().to_string(tmp));
219+
std::ostringstream buffer;
220+
fu.fm().display_smt2(buffer, tmp, false);
221+
return mk_c(c)->mk_external_string(buffer.str());
221222
}
222223
else {
223224
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
@@ -254,6 +255,9 @@ extern "C" {
254255
expr* e = to_expr(a);
255256
rational r;
256257
arith_util & u = mk_c(c)->autil();
258+
fpa_util & fu = mk_c(c)->fpautil();
259+
scoped_mpf ftmp(fu.fm());
260+
mpf_rounding_mode rm;
257261
if (u.is_numeral(e, r) && !r.is_int()) {
258262
std::ostringstream buffer;
259263
r.display_decimal(buffer, precision);
@@ -266,8 +270,14 @@ extern "C" {
266270
am.display_decimal(buffer, n, precision);
267271
return mk_c(c)->mk_external_string(buffer.str());
268272
}
269-
bool ok = Z3_get_numeral_rational(c, a, r);
270-
if (ok) {
273+
else if (mk_c(c)->fpautil().is_rm_numeral(to_expr(a), rm))
274+
return Z3_get_numeral_string(c, a);
275+
else if (mk_c(c)->fpautil().is_numeral(to_expr(a), ftmp)) {
276+
std::ostringstream buffer;
277+
fu.fm().display_decimal(buffer, ftmp, 12);
278+
return mk_c(c)->mk_external_string(buffer.str());
279+
}
280+
else if (Z3_get_numeral_rational(c, a, r)) {
271281
return mk_c(c)->mk_external_string(r.to_string());
272282
}
273283
else {

0 commit comments

Comments
 (0)