1 /** @file check_inifcns.cpp
3 * This test routine applies assorted tests on initially known higher level
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 /* Some tests on the sine trigonometric function. */
27 static unsigned inifcns_check_sin(void)
30 bool errorflag = false;
34 for (int n=-10; n<=10; ++n) {
35 if (sin(n*Pi).eval() != numeric(0) ||
36 !sin(n*Pi).eval().info(info_flags::integer))
40 // we don't count each of those errors
41 clog << "sin(n*Pi) with integer n does not always return exact 0"
46 // sin((n+1/2)*Pi) == {+|-}1?
48 for (int n=-10; n<=10; ++n) {
49 if (!sin((n+numeric(1,2))*Pi).eval().info(info_flags::integer) ||
50 !(sin((n+numeric(1,2))*Pi).eval() == numeric(1) ||
51 sin((n+numeric(1,2))*Pi).eval() == numeric(-1)))
55 clog << "sin((n+1/2)*Pi) with integer n does not always return exact {+|-}1"
60 // compare sin((q*Pi).evalf()) with sin(q*Pi).eval().evalf() at various
61 // points. E.g. if sin(Pi/10) returns something symbolic this should be
62 // equal to sqrt(5)/4-1/4. This routine will spot programming mistakes
66 numeric epsilon(double(1e-8));
67 for (int n=-340; n<=340; ++n) {
69 if (abs(sin(evalf(argument))-evalf(sin(argument)))>epsilon) {
70 clog << "sin(" << argument << ") returns "
71 << sin(argument) << endl;
82 /* Simple tests on the cosine trigonometric function. */
83 static unsigned inifcns_check_cos(void)
88 // cos((n+1/2)*Pi) == 0?
90 for (int n=-10; n<=10; ++n) {
91 if (cos((n+numeric(1,2))*Pi).eval() != numeric(0) ||
92 !cos((n+numeric(1,2))*Pi).eval().info(info_flags::integer))
96 clog << "cos((n+1/2)*Pi) with integer n does not always return exact 0"
103 for (int n=-10; n<=10; ++n) {
104 if (!cos(n*Pi).eval().info(info_flags::integer) ||
105 !(cos(n*Pi).eval() == numeric(1) ||
106 cos(n*Pi).eval() == numeric(-1)))
110 clog << "cos(n*Pi) with integer n does not always return exact {+|-}1"
115 // compare cos((q*Pi).evalf()) with cos(q*Pi).eval().evalf() at various
116 // points. E.g. if cos(Pi/12) returns something symbolic this should be
117 // equal to 1/4*(1+1/3*sqrt(3))*sqrt(6). This routine will spot
118 // programming mistakes of this kind:
121 numeric epsilon(double(1e-8));
122 for (int n=-340; n<=340; ++n) {
124 if (abs(cos(evalf(argument))-evalf(cos(argument)))>epsilon) {
125 clog << "cos(" << argument << ") returns "
126 << cos(argument) << endl;
137 /* Simple tests on the tangent trigonometric function. */
138 static unsigned inifcns_check_tan(void)
143 // compare tan((q*Pi).evalf()) with tan(q*Pi).eval().evalf() at various
144 // points. E.g. if tan(Pi/12) returns something symbolic this should be
145 // equal to 2-sqrt(3). This routine will spot programming mistakes of
149 numeric epsilon(double(1e-8));
150 for (int n=-340; n<=340; ++n) {
151 if (!(n%30) && (n%60)) // skip poles
154 if (abs(tan(evalf(argument))-evalf(tan(argument)))>epsilon) {
155 clog << "tan(" << argument << ") returns "
156 << tan(argument) << endl;
167 unsigned check_inifcns(void)
171 cout << "checking consistency of symbolic functions" << flush;
172 clog << "---------consistency of symbolic functions:" << endl;
174 result += inifcns_check_sin(); cout << '.' << flush;
175 result += inifcns_check_cos(); cout << '.' << flush;
176 result += inifcns_check_tan(); cout << '.' << flush;
179 cout << " passed " << endl;
180 clog << "(no output)" << endl;
182 cout << " failed " << endl;