65 T outputOrdinal(
const T &t)
71 int outputOrdinal(
const char& t)
85 if (
typeid(b) !=
typeid(d)) {
87 TYPE_CHAIN_A<typename Teuchos::ScalarTraits<T>::doublePrecision>(out);
95 if (
typeid(b) !=
typeid(d)) {
97 TYPE_CHAIN_D<typename Teuchos::ScalarTraits<T>::halfPrecision>(out);
102 inline std::string
passfail(
bool result)
104 return ( result ?
"passed" :
"failed" );
108 template<
class Scalar>
109 bool testScalarTraits(
123 const Scalar nan = ST::nan();
125 out <<
"Type chain (ascending) : "; TYPE_CHAIN_A<Scalar>(out); out <<
"\n";
126 out <<
"Type chain (descending): "; TYPE_CHAIN_D<Scalar>(out); out <<
"\n";
128 out <<
"\nTesting that squareroot(NaN) == NaN! ...\n";
130 const Scalar sqrtNan = ST::squareroot(nan);
131 result = (ST::isnaninf(sqrtNan));
132 if (!result) success =
false;
134 <<
"squareroot("<<nan<<
") = " << sqrtNan <<
" == " << nan <<
" : "
138 out <<
"\nTesting that squareroot(-NaN) == NaN! ...\n";
140 const Scalar negNan = -nan;
141 const Scalar sqrtNegNan = ST::squareroot(negNan);
142 result = (ST::isnaninf(sqrtNegNan));
143 if (!result) success =
false;
145 <<
"squareroot("<<negNan<<
") = " << sqrtNegNan <<
" == " << nan <<
" : "
149 if (ST::isComplex ==
false)
151 out <<
"\nTesting that squareroot(-1) == NaN! ...\n";
153 const Scalar negOne = -ST::one();
154 const Scalar sqrtNegOne = ST::squareroot(negOne);
155 result = (ST::isnaninf(sqrtNegOne));
156 if (!result) success =
false;
158 <<
"squareroot("<<negOne<<
") = " << sqrtNegOne <<
" == " << nan <<
" : "
163 #ifdef HAVE_NUMERIC_LIMITS
165 out <<
"\nTesting that squareroot(quiet_NaN) == NaN! ...\n";
167 const Scalar nan = std::numeric_limits<Scalar>::quiet_NaN();
168 const Scalar sqrtNan = ST::squareroot(nan);
169 result = (ST::isnaninf(sqrtNan));
170 if (!result) success =
false;
172 <<
"squareroot("<<nan<<
") = " << sqrtNan <<
" == " << nan <<
" : "
176 out <<
"\nTesting that squareroot(signaling_NaN) == NaN! ...\n";
178 const Scalar nan = std::numeric_limits<Scalar>::signaling_NaN();
179 const Scalar sqrtNan = ST::squareroot(nan);
180 result = (ST::isnaninf(sqrtNan));
181 if (!result) success =
false;
183 <<
"squareroot("<<nan<<
") = " << sqrtNan <<
" == " << nan <<
" : "
187 out <<
"\nTesting that squareroot(inf) == NaN! ...\n";
189 const Scalar inf = std::numeric_limits<Scalar>::infinity();
190 const Scalar sqrtInf = ST::squareroot(inf);
191 result = (ST::isnaninf(sqrtInf));
192 if (!result) success =
false;
194 <<
"squareroot("<<inf<<
") = " << sqrtInf <<
" == " << nan <<
" : "
198 #endif // HAVE_NUMERIC_LIMITS
205 template<
class Ordinal>
206 bool testOrdinalTraits(
220 const Ordinal zero = OT::zero();
221 const Ordinal one = OT::one();
222 const Ordinal max = OT::max();
223 const Ordinal invalid = OT::invalid();
224 out <<
"\nmax() == " << outputOrdinal(max) <<
"\n";
225 out <<
"\ninvalid() == " << outputOrdinal(invalid) <<
"\n";
227 out <<
"\nTesting that zero() * one() == zero() ...\n";
229 const Ordinal zto = zero*one;
230 result = (zto == zero);
231 if (!result) success =
false;
233 <<
"zero*one = " << outputOrdinal(zto) <<
" == " << outputOrdinal(zero) <<
" : "
237 out <<
"\nTesting that one() * one() == one() ...\n";
239 const Ordinal oto = one*one;
240 result = (oto == one);
241 if (!result) success =
false;
243 <<
"one*one = " << outputOrdinal(oto) <<
" == " << outputOrdinal(one) <<
" : "
247 out <<
"\nTesting that one() + zero() == zero() + one() == one() ...\n";
249 const Ordinal opz = one+zero;
250 const Ordinal zpo = zero+one;
251 result = (opz == one) && (zpo == one);
252 if (!result) success =
false;
254 <<
"one+zero = " << outputOrdinal(opz) <<
" == zero+one = "
255 << outputOrdinal(zpo) <<
" == " << outputOrdinal(one) <<
" : "
259 out <<
"\nTesting that one() - one() == zero() ...\n";
261 const Ordinal omo = one-one;
262 result = (omo == zero);
263 if (!result) success =
false;
265 <<
"one-one = " << outputOrdinal(omo) <<
" == " << outputOrdinal(zero) <<
" : "
269 out <<
"\nTesting that zero() < one() <= max() ...\n";
271 result = (zero < one) && (one <= max) && (zero < max);
272 if (!result) success =
false;
274 <<
"(zero < one) = " << (zero < one) <<
" == "
275 <<
"(one <= max) = " << (one <= max) <<
" == "
276 <<
"(zero < max) = " << (zero < max) <<
" == "
281 out <<
"\nTesting that invalid() not in [zero(),max()]...\n";
283 result = !( (invalid > zero || invalid==zero) && (invalid <= max) );
284 if (!result) success =
false;
286 <<
"invalid in [zero,max] == false : " <<
passfail(result) <<
"\n";
297 int main(
int argc,
char* argv[] ) {
313 CommandLineProcessor clp(
false);
314 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
315 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
316 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
320 result = testScalarTraits<float>(*out);
321 if(!result) success =
false;
323 result = testScalarTraits<double>(*out);
324 if(!result) success =
false;
326 result = testOrdinalTraits<char>(*out);
327 if(!result) success =
false;
329 result = testOrdinalTraits<short int>(*out);
330 if(!result) success =
false;
332 result = testOrdinalTraits<int>(*out);
333 if(!result) success =
false;
335 result = testOrdinalTraits<long int>(*out);
336 if(!result) success =
false;
338 result = testOrdinalTraits<size_t>(*out);
339 if(!result) success =
false;
341 #ifdef HAVE_TEUCHOS_LONG_LONG_INT
342 result = testOrdinalTraits<long long int>(*out);
343 if(!result) success =
false;
346 #ifdef HAVE_TEUCHOS___INT64
347 result = testOrdinalTraits<__int64>(*out);
348 if(!result) success =
false;
350 result = testOrdinalTraits<unsigned __int64>(*out);
351 if(!result) success =
false;
359 #ifdef HAVE_TEUCHOS_QD
360 result = testScalarTraits<dd_real>(*out);
361 if(!result) success =
false;
362 result = testScalarTraits<qd_real>(*out);
363 if(!result) success =
false;
370 *out <<
"\nEnd Result: TEST PASSED\n" << std::endl;
372 *out <<
"\nEnd Result: TEST FAILED\n" << std::endl;
374 return ( success ? 0 : 1 );
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
Initialize, finalize, and query the global MPI session.
const std::string passfail(const bool result)
Return "passed" or "failed".
This structure defines some basic traits for a scalar field type.
std::ostream subclass that performs the magic of indenting data sent to an std::ostream object among ...
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions.
static RCP< FancyOStream > getDefaultOStream()
Get the default output stream object.
This structure defines some basic traits for the ordinal field type.
T doublePrecision
Typedef for double precision.
int main(int argc, char *argv[])
Defines basic traits for the ordinal field type.
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Basic command line parser for input from (argc,argv[])
Defines basic traits for the scalar field type.
Smart reference counting pointer class for automatic garbage collection.
T halfPrecision
Typedef for half precision.
RCP< basic_FancyOStream< CharT, Traits > > tab(const RCP< basic_FancyOStream< CharT, Traits > > &out, const int tabs=1, const std::basic_string< CharT, Traits > linePrefix="")
Create a tab for an RCP-wrapped basic_FancyOStream object to cause the indentation of all output auto...
Class that helps parse command line input arguments from (argc,argv[]) and set options.
static std::string name()