From fc6a79c9b7a0ab56f3a6b2de8ab69fcbc6cc8b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernd=20G=C3=A4rtner?= Date: Tue, 19 Sep 2006 13:46:34 +0000 Subject: [PATCH] added handling of '+' in Gmpz and Gmpq input operators --- Number_types/include/CGAL/Gmpq.h | 4 ++-- Number_types/include/CGAL/Gmpz.h | 4 ++-- Number_types/test/Number_types/Gmpq.C | 33 ++++++++++++++++++--------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/Number_types/include/CGAL/Gmpq.h b/Number_types/include/CGAL/Gmpq.h index ec663603a93..5385b29040c 100644 --- a/Number_types/include/CGAL/Gmpq.h +++ b/Number_types/include/CGAL/Gmpq.h @@ -362,9 +362,9 @@ operator>>(std::istream& is, Gmpq &z) c = is.peek(); if (c != '.') { // is there a sign? - if (c == '-') { + if (c == '-' || c == '+') { is.get(); - negative = true; + negative = (c == '-'); gmpz_eat_white_space(is); c=is.peek(); } diff --git a/Number_types/include/CGAL/Gmpz.h b/Number_types/include/CGAL/Gmpz.h index b27a40549db..de5f8cff8e2 100644 --- a/Number_types/include/CGAL/Gmpz.h +++ b/Number_types/include/CGAL/Gmpz.h @@ -414,10 +414,10 @@ gmpz_new_read(std::istream &is, Gmpz &z) gmpz_eat_white_space(is); c=is.peek(); - if (c=='-'){ + if (c=='-' || c=='+'){ is.get(); CGAL_assertion(!is.fail()); - negative=true; + negative=(c=='-'); gmpz_eat_white_space(is); c=is.peek(); } diff --git a/Number_types/test/Number_types/Gmpq.C b/Number_types/test/Number_types/Gmpq.C index b57747eafbb..7e1276bc03e 100644 --- a/Number_types/test/Number_types/Gmpq.C +++ b/Number_types/test/Number_types/Gmpq.C @@ -52,19 +52,26 @@ void test_overflow_to_double() typedef std::pair Test_pair; typedef std::vector Test_set; Test_set make_derived_tests (const Test_pair& pair) { - // generate exponents and minus signs + // generate exponents, signs, and appended letter Test_set result; std::string input = pair.first; Gmpq should_be = pair.second; std::string minus = "-"; - for (std::string l; l != "ff"; l += "f") { - result.push_back(Test_pair(input + l , should_be)); - result.push_back(Test_pair(input + "e-2" +l , should_be/100)); - result.push_back(Test_pair(input + "e2" +l, should_be*100)); - result.push_back(Test_pair(input + "e0" +l , should_be)); - result.push_back(Test_pair(minus + input + "e-2" +l, -should_be/100)); - result.push_back(Test_pair(minus + input + "e2" +l, -should_be*100)); - result.push_back(Test_pair(minus + input + "e0" +l, -should_be)); + for (std::string l = ""; l != "ff"; l += "f") { + // append char 'f' to test whether it is correctly not eaten + for (std::string sign = ""; sign != "done";) { + // prepend signs "", "+", "-" + Gmpq s = should_be; + if (sign == "-") s = -s; + result.push_back(Test_pair(sign+input+l , s)); + result.push_back(Test_pair(sign+input+"e-2"+l , s/100)); + result.push_back(Test_pair(sign+input+"e1"+l, s*10)); + result.push_back(Test_pair(sign+input+"e+3"+l, s*1000)); + result.push_back(Test_pair(sign+input+"e0"+l , s)); + if (sign == "-") sign = "done"; + if (sign == "+") sign = "-"; + if (sign == "") sign = "+"; + } } return result; } @@ -79,14 +86,18 @@ void test_input_from_float() test_set.push_back (Test_pair (std::string ("0"), Gmpq(0,1))); // nonnegative floats, with or without digits before/after . - test_set.push_back (Test_pair (std::string ("0.0"), Gmpq(0,1))); + test_set.push_back (Test_pair (std::string ("0.0"), Gmpq(0,1))); + test_set.push_back (Test_pair (std::string ("0.123"), Gmpq(123,1000))); + test_set.push_back (Test_pair (std::string ("00.1"), Gmpq(1,10))); + test_set.push_back (Test_pair (std::string ("01.1"), Gmpq(11,10))); test_set.push_back (Test_pair (std::string ("0."), Gmpq(0,1))); test_set.push_back (Test_pair (std::string (".0"), Gmpq(0,1))); test_set.push_back (Test_pair (std::string ("12.34"), Gmpq(1234,100))); test_set.push_back (Test_pair (std::string ("0.56"), Gmpq(56,100))); test_set.push_back (Test_pair (std::string (".78"), Gmpq(78,100))); test_set.push_back (Test_pair (std::string ("90."), Gmpq(90,1))); - test_set.push_back (Test_pair (std::string ("90.0"), Gmpq(90,1))); + test_set.push_back (Test_pair (std::string ("90.0"), Gmpq(90,1))); + test_set.push_back (Test_pair (std::string ("7.001"), Gmpq(7001,1000))); // exponents and signs are automatically generated in // make_derived_tests