[BUGFIX] numeric::info(nonnegative): correctly handle complex numbers.
authorAlexei Sheplyakov <Alexei.Sheplyakov@gmail.com>
Tue, 28 Feb 2012 14:12:56 +0000 (16:12 +0200)
committerAlexei Sheplyakov <Alexei.Sheplyakov@gmail.com>
Tue, 28 Feb 2012 14:12:56 +0000 (16:12 +0200)
numeric::info(info_flags::nonnegative) returns true for an arbitrary
complex number with non-zero imaginary part.

Thanks to Burcin Erocal for reporting.

check/exam_numeric.cpp
ginac/numeric.cpp

index 715acff..d5ae27b 100644 (file)
@@ -68,6 +68,11 @@ static unsigned exam_numeric1()
                     << " erroneously not recognized as complex rational" << endl;
                ++result;
        }
                     << " erroneously not recognized as complex rational" << endl;
                ++result;
        }
+       if (test_crat.info(info_flags::nonnegative)) {
+               clog << test_crat
+                    << " erroneously recognized as non-negative number" << endl;
+               ++result;
+       }
        
        int i = numeric(1984).to_int();
        if (i-1984) {
        
        int i = numeric(1984).to_int();
        if (i-1984) {
index f05763d..18725b2 100644 (file)
@@ -700,7 +700,7 @@ bool numeric::info(unsigned inf) const
                case info_flags::negative:
                        return is_negative();
                case info_flags::nonnegative:
                case info_flags::negative:
                        return is_negative();
                case info_flags::nonnegative:
-                       return !is_negative();
+                       return is_zero() || is_positive();
                case info_flags::posint:
                        return is_pos_integer();
                case info_flags::negint:
                case info_flags::posint:
                        return is_pos_integer();
                case info_flags::negint: