1 |
|
|
/* |
2 |
|
|
Teem: Tools to process and visualize scientific data and images . |
3 |
|
|
Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago |
4 |
|
|
Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann |
5 |
|
|
Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah |
6 |
|
|
|
7 |
|
|
This library is free software; you can redistribute it and/or |
8 |
|
|
modify it under the terms of the GNU Lesser General Public License |
9 |
|
|
(LGPL) as published by the Free Software Foundation; either |
10 |
|
|
version 2.1 of the License, or (at your option) any later version. |
11 |
|
|
The terms of redistributing and/or modifying this software also |
12 |
|
|
include exceptions to the LGPL that facilitate static linking. |
13 |
|
|
|
14 |
|
|
This library 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 GNU |
17 |
|
|
Lesser General Public License for more details. |
18 |
|
|
|
19 |
|
|
You should have received a copy of the GNU Lesser General Public License |
20 |
|
|
along with this library; if not, write to Free Software Foundation, Inc., |
21 |
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
#include "teem/air.h" |
26 |
|
|
|
27 |
|
|
/* |
28 |
|
|
** Tests: |
29 |
|
|
** airLog2, airCbrt |
30 |
|
|
*/ |
31 |
|
|
|
32 |
|
|
int |
33 |
|
|
main(int argc, const char *argv[]) { |
34 |
|
2 |
char stmp[AIR_STRLEN_SMALL]; |
35 |
|
|
airArray *mop; |
36 |
|
|
|
37 |
|
|
AIR_UNUSED(argc); |
38 |
|
|
AIR_UNUSED(argv); |
39 |
|
1 |
mop = airMopNew(); |
40 |
|
|
|
41 |
|
|
{ /* airLog2 */ |
42 |
|
|
int ret, l2 = 0; |
43 |
|
|
size_t ee = 1; |
44 |
|
1 |
do { |
45 |
✗✓ |
31 |
if (l2 != (ret = airLog2(ee))) { |
46 |
|
|
fprintf(stderr, "airLog2(%s) = %d != %d\n", |
47 |
|
|
airSprintSize_t(stmp, ee), ret, l2); |
48 |
|
|
airMopError(mop); return 1; |
49 |
|
|
} |
50 |
✓✓ |
31 |
if (ee > 1) { |
51 |
✗✓ |
30 |
if (-1 != (ret = airLog2(ee+1))) { |
52 |
|
|
fprintf(stderr, "airLog2(%s) = %d != -1\n", |
53 |
|
|
airSprintSize_t(stmp, ee+1), ret); |
54 |
|
|
airMopError(mop); return 1; |
55 |
|
|
} |
56 |
|
|
} |
57 |
|
31 |
l2 += 1; |
58 |
|
31 |
ee *= 2; |
59 |
✓✓ |
31 |
} while (l2 < 31); |
60 |
|
1 |
} |
61 |
|
|
|
62 |
|
|
{ /* airCbrt */ |
63 |
|
|
unsigned int pi, ti, testnum = 2000; |
64 |
|
|
airRandMTState *rng; |
65 |
|
1 |
double aa[2], uu, eps = 8e-27, error; |
66 |
|
1 |
rng = airRandMTStateNew(4242); |
67 |
|
1 |
airMopAdd(mop, rng, (airMopper)airRandMTStateNix, airMopAlways); |
68 |
|
|
error = 0; |
69 |
✓✓ |
4002 |
for (ti=0; ti<testnum; ti++) { |
70 |
|
|
double dif; |
71 |
|
2000 |
airNormalRand_r(aa+0, aa+1, rng); |
72 |
✓✓ |
12000 |
for (pi=0; pi<2; pi++) { |
73 |
|
4000 |
aa[pi] *= 10000; |
74 |
|
4000 |
uu = airCbrt(aa[pi]); |
75 |
|
4000 |
dif = fabs(aa[pi] - uu*uu*uu); |
76 |
|
4000 |
error += (dif/aa[pi])*dif; |
77 |
|
|
} |
78 |
|
|
} |
79 |
|
1 |
error /= testnum; |
80 |
✗✓✗✓
|
2 |
if (error > eps) { |
81 |
|
1 |
fprintf(stderr, "average cbrt error was %.17g > eps %0.17g\n", |
82 |
|
|
error, eps); |
83 |
|
|
airMopError(mop); return 1; |
84 |
|
|
} else { |
85 |
|
1 |
fprintf(stderr, "average cbrt error = %.17g\n", error); |
86 |
|
|
} |
87 |
✓✗ |
2 |
} |
88 |
|
|
|
89 |
|
1 |
exit(0); |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|