Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
Main Page
Related Pages
Topics
Namespaces
Data Structures
Files
File List
Globals
EXTERNAL_HEADERS
RSL
tests
numerics
26.valarray.transcend.cpp
Go to the documentation of this file.
1
29
// disable implicit inclusion to work around a limitation in
30
// IBM's VisualAge 5.0.2.0 (see PR#26959)
31
#if defined __IBMCPP__ && !defined _RWSTD_NO_IMPLICIT_INCLUSION
32
# define _RWSTD_NO_IMPLICIT_INCLUSION
33
#endif
// defined __IBMCPP__ && !defined _RWSTD_NO_IMPLICIT_INCLUSION
34
35
#include <cmath>
36
#include <cstddef>
// for std::size_t
37
#include <valarray>
38
39
#include <
rw_driver.h
>
40
#include <
rw_valcmp.h
>
41
42
44
template
<
class
T>
45
static
void
46
test_val (
const
char
* tname)
47
{
48
49
#define TEST(fun) { \
50
rw_info (0, __FILE__, __LINE__, "template <> std::valarray<%s> " \
51
"std::" #fun " (std::valarray<%s>)", tname, tname); \
52
\
53
std::valarray<T> val (10); \
54
for (std::size_t i = 0; i != val.size (); ++i) \
55
val [i] = T (i); \
56
\
57
const std::valarray<T> result = std::fun (val); \
58
\
59
bool success = 10 == val.size () && val.size () == result.size (); \
60
\
61
for (std::size_t j = 0; success && j != result.size (); ++j) { \
62
if (!rw_equal (result [j], T (std::fun (T (j))))) \
63
success = false; \
64
} \
65
\
66
rw_assert (success, __FILE__, __LINE__, \
67
"template <> std::valarray<%s> std::" #fun \
68
"(std::valarray<%s>)", tname, tname); \
69
} (void)0
70
71
#define TEST_2(fun, x) { \
72
if (x < 0) \
73
rw_info (0, __FILE__, __LINE__, \
74
"template <> std::valarray<%s> " \
75
"std::" #fun " (const %s&, const std::" \
76
"valarray<%s>&)", tname, tname, tname); \
77
else if (x > 0) \
78
rw_info (0, __FILE__, __LINE__, \
79
"template <> std::valarray<%s> " \
80
"std::" #fun " (const std::valarray<%s>&," \
81
"const %s&)", tname, tname, tname); \
82
else \
83
rw_info (0, __FILE__, __LINE__, \
84
"template <> std::valarray<%s> " \
85
"std::" #fun " (const std::valarray<%s>&," \
86
"const std::valarray<%s>&)", tname, tname, tname); \
87
\
88
std::valarray<T> val (10); \
89
for (std::size_t i = 0; i != val.size (); ++i) \
90
val [i] = T (i); \
91
\
92
const std::valarray<T> result = \
93
x < 0 ? std::fun (T (x), val) \
94
: x > 0 ? std::fun (val, T (x)) \
95
: std::fun (val, val); \
96
\
97
bool success = 10 == val.size () && val.size () == result.size (); \
98
\
99
for (std::size_t j = 0; success && j != result.size (); ++j) { \
100
T res; \
101
if (x < 0) res = T (std::fun (T (x), T (j))); \
102
if (x > 0) res = T (std::fun (T (j), T (x))); \
103
if (!x) res = T (std::fun (T (j), T (j))); \
104
if (!rw_equal (result [j], res)) \
105
success = false; \
106
} \
107
\
108
rw_assert (success, __FILE__, __LINE__, \
109
"template <> std::valarray<%s> std::" #fun "(...)", \
110
tname); \
111
} (void)0
112
113
TEST
(abs);
114
TEST
(acos);
115
TEST
(abs);
116
TEST
(acos);
117
TEST
(asin);
118
TEST
(atan);
119
120
TEST_2
(atan2, -2);
121
TEST_2
(atan2, +3);
122
TEST_2
(atan2, 0);
123
124
TEST
(cos);
125
TEST
(cosh);
126
TEST
(exp);
127
TEST
(log);
128
TEST
(log10);
129
130
TEST_2
(pow, -4);
131
TEST_2
(pow, +5);
132
TEST_2
(pow, 0);
133
134
TEST
(sin);
135
TEST
(sinh);
136
TEST
(sqrt);
137
TEST
(tan);
138
TEST
(tanh);
139
}
140
141
143
static
int
144
run_test
(
int
/*unused*/
,
char
*
/*unused*/
[])
145
{
146
test_val<float> (
"float"
);
147
test_val<double> (
"double"
);
148
149
#ifndef _RWSTD_NO_LONG_DOUBLE
150
151
test_val<long double> (
"long double"
);
152
153
#endif
// _RWSTD_NO_LONG_DOUBLE
154
155
return
0;
156
}
157
158
/*extern*/
int
159
main
(
int
argc,
char
* argv [])
160
{
161
return
rw_test
(argc, argv, __FILE__,
162
"lib.valarray.transcend"
,
163
0,
// no comment
164
run_test
,
""
, 0);
165
}
166
run_test
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
Definition
25.find.first.cpp:275
TEST_2
#define TEST_2(fun, x)
TEST
#define TEST(fun)
main
#define main
Definition
BAD_ALLOC_COPY_CTOR.cpp:32
rw_driver.h
rw_test
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
rw_valcmp.h
Generated by
1.9.8