20 void test_print_double(
double v,
const char* s,
bool& success, std::ostream& out) {
33 void test_print_double(
const char* s,
bool& success, std::ostream& out) {
34 test_print_double(std::atof(s), s, success, out);
37 double form_double(
bool negative, std::uint64_t mantissa, std::int32_t exponent) {
38 std::uint64_t pun = 0;
39 if (negative) pun |= std::uint64_t(1) << 63;
40 auto biased_exponent = std::uint64_t(exponent) + 1075;
41 pun |= biased_exponent << 52;
42 pun |= mantissa % (std::uint64_t(1) << 52);
44 std::memcpy(&value, &pun,
sizeof(value));
50 test_print_double(
"1.", success, out);
51 test_print_double(
"-1.", success, out);
52 test_print_double(
"0.", success, out);
53 test_print_double(
"4.", success, out);
54 test_print_double(
"55.", success, out);
55 test_print_double(
"3.14159", success, out);
56 test_print_double(
"5404319552844595.", success, out);
57 test_print_double(
"1e300", success, out);
58 test_print_double(
"1e-300", success, out);
59 test_print_double(
"1e2", success, out);
60 test_print_double(
"10.", success, out);
61 test_print_double(
".003", success, out);
65 test_print_double(
"9.999999999999999e22", success, out);
66 test_print_double(
"inf", success, out);
67 test_print_double(
"-inf", success, out);
68 test_print_double(
"nan", success, out);
70 test_print_double(form_double(0, 0, 8),
"1152921504606847000.", success, out);
71 test_print_double(form_double(0, 0, 0),
"4503599627370496.", success, out);
72 test_print_double(form_double(0, 4503599627370503, -30),
"4194304.0000000065", success, out);
73 test_print_double(form_double(0, 4503599627370518, -30),
"4194304.0000000205", success, out);
75 test_print_double(
"1.3", success, out);
76 test_print_double(4.0/3.0,
"1.3333333333333333", success, out);
77 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.