1 /** @file check_numeric.cpp
3 * These exams creates some numbers and check the result of several boolean
4 * tests on these numbers like is_integer() etc... */
7 * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #ifndef NO_NAMESPACE_GINAC
27 using namespace GiNaC;
28 #endif // ndef NO_NAMESPACE_GINAC
30 /* Simple and maybe somewhat pointless consistency tests of assorted tests and
32 static unsigned check_numeric1(void)
35 bool errorflag = false;
38 // Check some numerator and denominator calculations:
39 for (int i=0; i<200; ++i) {
40 do { re_q = rand(); } while (re_q == 0);
41 do { im_q = rand(); } while (im_q == 0);
42 numeric r(rand()-RAND_MAX/2, re_q);
43 numeric i(rand()-RAND_MAX/2, im_q);
49 clog << z << " erroneously transformed into "
50 << p << "/" << q << " by numer() and denom()" << endl;
60 static unsigned check_numeric2(void)
63 bool errorflag = false;
66 // Check non-nested radicals (n/d)^(m/n) in ex wrapper class:
67 for (int i=0; i<200; ++i) { // FIXME: run to ~200
68 for (int j=2; j<13; ++j) {
69 // construct an exponent 1/j...
71 nm += numeric(int(20.0*rand()/(RAND_MAX+1.0))-10);
73 do { i_num = rand(); } while (i_num == 0);
75 // ...and a denominator.
76 do { i_den = (rand())/100; } while (i_den == 0);
78 // construct the radicals:
79 ex radical = pow(ex(num)/ex(den),ex(nm));
80 numeric floating = pow(num/den,nm);
82 if (is_ex_of_type(radical,numeric)) {
83 clog << "(" << num << "/" << den << ")^(" << nm
84 << ") should have been a product, instead it's "
88 numeric ratio = ex_to_numeric(evalf(radical))/floating;
89 if (ratio>1.0001 && ratio<0.9999) {
90 clog << "(" << num << "/" << den << ")^(" << nm
91 << ") erroneously evaluated to " << radical;
102 unsigned check_numeric(void)
106 cout << "checking consistency of numeric types" << flush;
107 clog << "---------consistency of numeric types:" << endl;
109 result += check_numeric1(); cout << '.' << flush;
110 result += check_numeric2(); cout << '.' << flush;
113 cout << " passed " << endl;
114 clog << "(no output)" << endl;
116 cout << " failed " << endl;