Created by: bartlettroscoe
CC: @trilinos/teuchos, @mhoemmen
Description
This PR branch improves the outputting of some of the Teuchos type conversion code unit tests and it fixes a problem with a safeAs() test on power8 systems. This addresses issue #2407 (closed).
Now, building and running with:
./TeuchosCore_TypeConversions_UnitTest.exe --test=stringToReal --details=ALL
passes as shown below on two systems.
With this change, on my Linux machine crf450 the unit test output shows:
1. asSafe_stringToReal_UnitTest ...
minLD = -1.19e+4932
minusOneLD = -1
maxLD = 1.19e+4932
...
sizeof_long_double = 16
sizeof_double = 8
max_exponent10_long_double = 4932
max_exponent10_double = 308
Testing converting from 'long double' to 'double' that does not fit ...
Test that code {valD = asSafe<double>(valToString(minLD));} throws std::range_error: passed
Exception message for expected exception:
/ascldap/users/rabartl/Trilinos.base/Trilinos/packages/teuchos/core/src/Teuchos_as.hpp:558:
Throw number = 3
Throw test that evaluated to true: errno == ERANGE && (val != 0)
Teuchos::ValueTypeConversionTraits<double, std::string>::convert: The value in the given string "-1.189731495357231765021263853e+4932" overflows double.
valD = -1
Test that code {valD = asSafe<double>(valToString(maxLD));} throws std::range_error: passed
Exception message for expected exception:
/ascldap/users/rabartl/Trilinos.base/Trilinos/packages/teuchos/core/src/Teuchos_as.hpp:558:
Throw number = 4
Throw test that evaluated to true: errno == ERANGE && (val != 0)
Teuchos::ValueTypeConversionTraits<double, std::string>::convert: The value in the given string "1.189731495357231765021263853e+4932" overflows double.
valD = -1
Testing string -> long double conversions ...
...
[Passed] (0.000535 sec)
Total Time: 0.000829 sec
Summary: total = 116, run = 1, passed = 1, failed = 0
End Result: TEST PASSED
So it runs the unit tests Testing converting from 'long double' to 'double' that does not fit
gets run since both the sizeof() and max_exponent10 values for long double are larger than for double. So these important tests run.
But when I run this unit test now on the power8 machine ride
with the the gnu-debug-openmp
build as shown above, it shows:
1. asSafe_stringToReal_UnitTest ...
minLD = -1.8e+308
minusOneLD = -1
maxLD = 1.8e+308
...
sizeof_long_double = 16
sizeof_double = 8
max_exponent10_long_double = 308
max_exponent10_double = 308
Testing string -> long double conversions ...
...
[Passed] (0.000418 sec)
Total Time: 0.000783 sec
Summary: total = 116, run = 1, passed = 1, failed = 0
End Result: TEST PASSED
See, that shows that on this machine max_exponent10_long_double
= max_exponent10_double
= 308
and the checks printed in the section Testing converting from 'long double' to 'double' that does not fit
are skipped and instead it goes straight to Testing string -> long double conversions
.
I think this is the right thing to do to fix these tests and it informs something about this system.