]> www.ginac.de Git - ginac.git/blobdiff - check/numeric_consist.cpp
- changes triggered by fucking new version of automake
[ginac.git] / check / numeric_consist.cpp
index 9f5582951b2bf0ff97ebb95af30e7c2f95ce9de2..5839da10e9e7530cb7867cd6dbb6e680c17292ec 100644 (file)
@@ -1,10 +1,32 @@
-// check/numeric_consist.cpp
+/** @file numeric_consist.cpp
+ *
+ *  This test routine creates some numbers and check the result of several
+ *  boolean tests on these numbers like is_integer() etc... */
 
-/* This test routine creates some numbers and check the result of several
- * boolean tests on these numbers like is_integer() etc... */
+/*
+ *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
 
 #include <stdlib.h>
-#include <GiNaC/ginac.h>
+#include "ginac.h"
+
+#ifndef NO_NAMESPACE_GINAC
+using namespace GiNaC;
+#endif // ndef NO_NAMESPACE_GINAC
 
 /* Simple and maybe somewhat pointless consistency tests of assorted tests and
  * conversions. */
@@ -15,47 +37,54 @@ static unsigned numeric_consist1(void)
     numeric test_int2(5);
     numeric test_rat1 = test_int1; test_rat1 /= test_int2;
     test_rat1 = -test_rat1;         // -42/5
+    numeric test_crat = test_rat1+I*test_int2;  // 5*I-42/5
     symbol a("a");
     ex e1, e2;
     
-    if ( !test_int1.is_integer() ) {
+    if (!test_int1.is_integer()) {
         clog << test_int1
              << " erroneously not recognized as integer" << endl;
         ++result;
     }
-    if ( !test_int1.is_rational() ) {
+    if (!test_int1.is_rational()) {
         clog << test_int1
              << " erroneously not recognized as rational" << endl;
         ++result;
     }
     
-    if ( !test_rat1.is_rational() ) {
+    if (!test_rat1.is_rational()) {
         clog << test_rat1
              << " erroneously not recognized as rational" << endl;
         ++result;
     }
-    if ( test_rat1.is_integer() ) {
+    if (test_rat1.is_integer()) {
         clog << test_rat1
              << " erroneously recognized as integer" << endl;
         ++result;
     }
     
+    if (!test_crat.is_crational()) {
+        clog << test_crat
+             << " erroneously not recognized as complex rational" << endl;
+        ++result;
+    }
+    
     int i = numeric(1984).to_int();
-    if ( i-1984 ) {
+    if (i-1984) {
         clog << "conversion of " << i
              << " from numeric to int failed" << endl;
         ++result;
     }
     
     e1 = test_int1;
-    if ( !e1.info(info_flags::posint) ) {
+    if (!e1.info(info_flags::posint)) {
         clog << "expression " << e1
              << " erroneously not recognized as positive integer" << endl;
         ++result;
     }
     
     e2 = test_int1 + a;
-    if ( ex_to_numeric(e2).is_integer() ) {
+    if (ex_to_numeric(e2).is_integer()) {
         clog << "expression " << e2
              << " erroneously recognized as integer" << endl;
         ++result;
@@ -64,15 +93,15 @@ static unsigned numeric_consist1(void)
     // The next two were two actual bugs in CLN till June, 12, 1999:
     test_rat1 = numeric(3)/numeric(2);
     test_rat1 += test_rat1;
-    if ( !test_rat1.is_integer() ) {
+    if (!test_rat1.is_integer()) {
         clog << "3/2 + 3/2 erroneously not integer 3 but instead "
              << test_rat1 << endl;
         ++result;
     }
     test_rat1 = numeric(3)/numeric(2);
     numeric test_rat2 = test_rat1 + numeric(1);  // 5/2
-    test_rat2 -= test_rat1;             // 1
-    if ( !test_rat2.is_integer() ) {
+    test_rat2 -= test_rat1;  // 1
+    if (!test_rat2.is_integer()) {
         clog << "5/2 - 3/2 erroneously not integer 1 but instead "
              << test_rat2 << endl;
         ++result;
@@ -102,7 +131,7 @@ static unsigned numeric_consist1(void)
  * calculating expt(a,b) if b is a rational and a a nonnegative integer.
  * Implementing a workaround sadly introduced another bug on May 28th 1999
  * that was fixed on May 31st.  The workaround turned out to be stupid and
- * the bug was finally killed in CLN on September 2nd. */
+ * the original bug in CLN was finally killed on September 2nd. */
 static unsigned numeric_consist2(void)
 {
     unsigned result = 0;
@@ -112,27 +141,27 @@ static unsigned numeric_consist2(void)
     ex three = numeric(3);
     
     // The hang in this code was the reason for the original workaround
-    if ( pow(two,two/three) == 42 ) {
+    if (pow(two,two/three)==42) {
         clog << "pow(2,2/3) erroneously returned 42" << endl;
         ++result;  // cannot happen
     }
     
     // Actually, this used to raise a FPE after introducing the workaround
-    if ( two*zero != zero ) {
+    if (two*zero!=zero) {
         clog << "2*0 erroneously returned " << two*zero << endl;
         ++result;
     }
     
     // And this returned a cl_F due to the implicit call of numeric::power()
     ex six = two*three;
-    if ( !six.info(info_flags::integer) ) {
+    if (!six.info(info_flags::integer)) {
         clog << "2*3 erroneously returned the non-integer " << six << endl;
         ++result;
     }
     
     // The fix in the workaround left a whole which was fixed hours later...
     ex another_zero = pow(zero,numeric(1)/numeric(2));
-    if ( another_zero.compare(exZERO()) ) {
+    if (!another_zero.is_zero()) {
         clog << "pow(0,1/2) erroneously returned" << another_zero << endl;
         ++result;
     }
@@ -153,50 +182,50 @@ static unsigned numeric_consist3(void)
     // These overloaded routines indeed need to be checked separately since
     // internally they might be doing something completely different:
     a = 23; b = 4; calc_rem = irem(a, b);
-    if ( calc_rem != 3 ) {
+    if (calc_rem != 3) {
         clog << "irem(" << a << "," << b << ") erroneously returned "
              << calc_rem << endl;
         ++result;
     }
     a = 23; b = -4; calc_rem = irem(a, b);
-    if ( calc_rem != 3 ) {
+    if (calc_rem != 3) {
         clog << "irem(" << a << "," << b << ") erroneously returned "
              << calc_rem << endl;
         ++result;
     }
     a = -23; b = 4; calc_rem = irem(a, b);
-    if ( calc_rem != -3 ) {
+    if (calc_rem != -3) {
         clog << "irem(" << a << "," << b << ") erroneously returned "
              << calc_rem << endl;
         ++result;
     }
     a = -23; b = -4; calc_rem = irem(a, b);
-    if ( calc_rem != -3 ) {
+    if (calc_rem != -3) {
         clog << "irem(" << a << "," << b << ") erroneously returned "
              << calc_rem << endl;
         ++result;
     }
     // and now the overloaded irem(a,b,q):
     a = 23; b = 4; calc_rem = irem(a, b, calc_quo);
-    if ( calc_rem != 3 || calc_quo != 5 ) {
+    if (calc_rem != 3 || calc_quo != 5) {
         clog << "irem(" << a << "," << b << ",q) erroneously returned "
              << calc_rem << " with q=" << calc_quo << endl;
         ++result;
     }
     a = 23; b = -4; calc_rem = irem(a, b, calc_quo);
-    if ( calc_rem != 3 || calc_quo != -5 ) {
+    if (calc_rem != 3 || calc_quo != -5) {
         clog << "irem(" << a << "," << b << ",q) erroneously returned "
              << calc_rem << " with q=" << calc_quo << endl;
         ++result;
     }
     a = -23; b = 4; calc_rem = irem(a, b, calc_quo);
-    if ( calc_rem != -3 || calc_quo != -5 ) {
+    if (calc_rem != -3 || calc_quo != -5) {
         clog << "irem(" << a << "," << b << ",q) erroneously returned "
              << calc_rem << " with q=" << calc_quo << endl;
         ++result;
     }
     a = -23; b = -4; calc_rem = irem(a, b, calc_quo);
-    if ( calc_rem != -3 || calc_quo != 5 ) {
+    if (calc_rem != -3 || calc_quo != 5) {
         clog << "irem(" << a << "," << b << ",q) erroneously returned "
              << calc_rem << " with q=" << calc_quo << endl;
         ++result;
@@ -206,50 +235,50 @@ static unsigned numeric_consist3(void)
     // These overloaded routines indeed need to be checked separately since
     // internally they might be doing something completely different:
     a = 23; b = 4; calc_quo = iquo(a, b);
-    if ( calc_quo != 5 ) {
+    if (calc_quo != 5) {
         clog << "iquo(" << a << "," << b << ") erroneously returned "
              << calc_quo << endl;
         ++result;
     }
     a = 23; b = -4; calc_quo = iquo(a, b);
-    if ( calc_quo != -5 ) {
+    if (calc_quo != -5) {
         clog << "iquo(" << a << "," << b << ") erroneously returned "
              << calc_quo << endl;
         ++result;
     }
     a = -23; b = 4; calc_quo = iquo(a, b);
-    if ( calc_quo != -5 ) {
+    if (calc_quo != -5) {
         clog << "iquo(" << a << "," << b << ") erroneously returned "
              << calc_quo << endl;
         ++result;
     }
     a = -23; b = -4; calc_quo = iquo(a, b);
-    if ( calc_quo != 5 ) {
+    if (calc_quo != 5) {
         clog << "iquo(" << a << "," << b << ") erroneously returned "
              << calc_quo << endl;
         ++result;
     }
     // and now the overloaded iquo(a,b,r):
     a = 23; b = 4; calc_quo = iquo(a, b, calc_rem);
-    if ( calc_quo != 5 || calc_rem != 3 ) {
+    if (calc_quo != 5 || calc_rem != 3) {
         clog << "iquo(" << a << "," << b << ",r) erroneously returned "
              << calc_quo << " with r=" << calc_rem << endl;
         ++result;
     }
     a = 23; b = -4; calc_quo = iquo(a, b, calc_rem);
-    if ( calc_quo != -5 || calc_rem != 3 ) {
+    if (calc_quo != -5 || calc_rem != 3) {
         clog << "iquo(" << a << "," << b << ",r) erroneously returned "
              << calc_quo << " with r=" << calc_rem << endl;
         ++result;
     }
     a = -23; b = 4; calc_quo = iquo(a, b, calc_rem);
-    if ( calc_quo != -5 || calc_rem != -3 ) {
+    if (calc_quo != -5 || calc_rem != -3) {
         clog << "iquo(" << a << "," << b << ",r) erroneously returned "
              << calc_quo << " with r=" << calc_rem << endl;
         ++result;
     }
     a = -23; b = -4; calc_quo = iquo(a, b, calc_rem);
-    if ( calc_quo != 5 || calc_rem != -3 ) {
+    if (calc_quo != 5 || calc_rem != -3) {
         clog << "iquo(" << a << "," << b << ",r) erroneously returned "
              << calc_quo << " with r=" << calc_rem << endl;
         ++result;
@@ -268,24 +297,25 @@ static unsigned numeric_consist4(void)
     // square roots of squares of integers:
     passed = true;
     for (int i=0; i<42; ++i) {
-        if ( !sqrt(numeric(i*i)).is_integer() ) {
+        if (!sqrt(numeric(i*i)).is_integer()) {
             passed = false;
         }
     }
-    if ( !passed ) {
+    if (!passed) {
         clog << "One or more square roots of squares of integers did not return exact integers" << endl;
         ++result;
     }
+    
     // square roots of squares of rationals:
     passed = true;
     for (int num=0; num<41; ++num) {
         for (int den=1; den<42; ++den) {
-            if ( !sqrt(numeric(num*num)/numeric(den*den)).is_rational() ) {
+            if (!sqrt(numeric(num*num)/numeric(den*den)).is_rational()) {
                 passed = false;
             }
         }
     }
-    if ( !passed ) {
+    if (!passed) {
         clog << "One or more square roots of squares of rationals did not return exact integers" << endl;
         ++result;
     }
@@ -305,7 +335,7 @@ unsigned numeric_consist(void)
     result += numeric_consist3();
     result += numeric_consist4();
 
-    if ( !result ) {
+    if (!result) {
         cout << " passed ";
         clog << "(no output)" << endl;
     } else {