54 void test_print_double(
double v,
const char* s,
bool& success, std::ostream& out) {
67 void test_print_double(
const char* s,
bool& success, std::ostream& out) {
68 test_print_double(std::atof(s), s, success, out);
71 double form_double(
bool negative, std::uint64_t mantissa, std::int32_t exponent) {
72 std::uint64_t pun = 0;
73 if (negative) pun |= std::uint64_t(1) << 63;
74 auto biased_exponent = std::uint64_t(exponent) + 1075;
75 pun |= biased_exponent << 52;
76 pun |= mantissa % (std::uint64_t(1) << 52);
78 std::memcpy(&value, &pun,
sizeof(value));
84 test_print_double(
"1.", success, out);
85 test_print_double(
"-1.", success, out);
86 test_print_double(
"0.", success, out);
87 test_print_double(
"4.", success, out);
88 test_print_double(
"55.", success, out);
89 test_print_double(
"3.14159", success, out);
90 test_print_double(
"5404319552844595.", success, out);
91 test_print_double(
"1e300", success, out);
92 test_print_double(
"1e-300", success, out);
93 test_print_double(
"1e2", success, out);
94 test_print_double(
"10.", success, out);
95 test_print_double(
".003", success, out);
99 test_print_double(
"9.999999999999999e22", success, out);
100 test_print_double(
"inf", success, out);
101 test_print_double(
"-inf", success, out);
102 test_print_double(
"nan", success, out);
104 test_print_double(form_double(0, 0, 8),
"1152921504606847000.", success, out);
105 test_print_double(form_double(0, 0, 0),
"4503599627370496.", success, out);
106 test_print_double(form_double(0, 4503599627370503, -30),
"4194304.0000000065", success, out);
107 test_print_double(form_double(0, 4503599627370518, -30),
"4194304.0000000205", success, out);
109 test_print_double(
"1.3", success, out);
110 test_print_double(4.0/3.0,
"1.3333333333333333", success, out);
111 test_print_double(1.0/10.0,
".1", success, out);
void print_double(std::ostream &os, double v)
Prints a double-precision floating-point number exactly using minimal characters. ...
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
Declares Teuchos::print_double.