[GIT] ppl/ppl(master): Let the input routine accept floating-point syntax starting with ".".

Module: ppl/ppl Branch: master Commit: dd5bdc7dd6b33e94ff4bbf0b3e33d7f791d8e31c URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=dd5bdc7dd6b33...
Author: Enea Zaffanella zaffanella@cs.unipr.it Date: Wed Sep 1 08:18:04 2010 +0200
Let the input routine accept floating-point syntax starting with ".".
---
src/checked.cc | 38 +++++++++++++++++++++++--------------- tests/Polyhedron/numberinput1.cc | 6 ++++-- 2 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/src/checked.cc b/src/checked.cc index c3ba12f..a36bce4 100644 --- a/src/checked.cc +++ b/src/checked.cc @@ -120,6 +120,12 @@ parse_number_part(std::istream& is, number_struct& num) { c = is.get(); if (c == 'i' || c == 'I') goto inf; + if (c != '.') + break; + // Fall through. + case '.': + state = FRACTIONAL; + c = is.get(); break; case 'n': case 'N': @@ -141,26 +147,28 @@ parse_number_part(std::istream& is, number_struct& num) { goto error; return num.neg_mantissa ? V_EQ_MINUS_INFINITY : V_EQ_PLUS_INFINITY; } - if (get_digit(c, 10) < 0) - goto error; - if (c == '0') { - int d = is.get(); - if (d == 'x' || d == 'X') { - num.base = 16; - num.base_for_exponent = 16; - state = INTEGER; - c = is.get(); + if (state != FRACTIONAL) { + if (get_digit(c, 10) < 0) + goto error; + if (c == '0') { + int d = is.get(); + if (d == 'x' || d == 'X') { + num.base = 16; + num.base_for_exponent = 16; + state = INTEGER; + c = is.get(); + } + else { + c = d; + empty_mantissa = false; + } } else { - c = d; + num.mantissa += (char) c; empty_mantissa = false; + c = is.get(); } } - else { - num.mantissa += (char) c; - empty_mantissa = false; - c = is.get(); - } while (true) { switch (state) { case BASE: diff --git a/tests/Polyhedron/numberinput1.cc b/tests/Polyhedron/numberinput1.cc index cdc43f1..cfb33e2 100644 --- a/tests/Polyhedron/numberinput1.cc +++ b/tests/Polyhedron/numberinput1.cc @@ -144,7 +144,9 @@ test04() { && aux_test("0.123456 101", "1929/15625", " 101", V_EQ) && aux_test("0.123456 101", "1929/15625", " 101", V_EQ) && aux_test("0.123456 ", "1929/15625", " ", V_EQ) - && aux_test(".333", "nan", ".333", V_CVT_STR_UNK); + && aux_test(".499975", "19999/40000", "", V_EQ) + && aux_test(".333", "333/1000", "", V_EQ) + && aux_test(".0x333", "0", "x333", V_EQ); }
// Testing exponent. @@ -256,7 +258,7 @@ test09() { bool test10() { return - // Fraction. + // Fraction. aux_test("2^^11.1", "7/2", "", V_EQ) && aux_test("2^^11.1a", "7/2", "a", V_EQ) && aux_test("2^^11.1.", "7/2", ".", V_EQ)
participants (1)
-
Enea Zaffanella