1 /* 2 * Copyright (c) 2014 Travis Geiselbrecht 3 * 4 * Use of this source code is governed by a MIT-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/MIT 7 */ 8 9 #include <stdint.h> 10 11 union double_int { 12 double d; 13 uint64_t i; 14 }; 15 16 static const union double_int float_test_vec[] = { 17 { .d = -2.0 }, 18 { .d = -1.0 }, 19 { .d = -0.5 }, 20 { .d = -0.0 }, 21 { .d = 0.0 }, 22 { .d = 0.01 }, 23 { .d = 0.1 }, 24 { .d = 0.2 }, 25 { .d = 0.25 }, 26 { .d = 0.5 }, 27 { .d = 0.75 }, 28 { .d = 1.0 }, 29 { .d = 2.0 }, 30 { .d = 3.0 }, 31 { .d = 10.0 }, 32 { .d = 100.0 }, 33 { .d = 123456.0 }, 34 { .d = -123456.0 }, 35 { .d = 546.5645644531f }, 36 { .d = -546.5645644531f }, 37 { .d = 0.12345 }, 38 { .d = 0.0000012345 }, 39 { .d = 0.0000019999 }, 40 { .d = 0.0000015 }, 41 { .i = 0x4005bf0a8b145649ULL }, // e 42 { .i = 0x400921fb54442d18ULL }, // pi 43 { .i = 0x43f0000000000000ULL }, // 2^64 44 { .i = 0x7fefffffffffffffULL }, // largest normalized 45 { .i = 0x0010000000000000ULL }, // least positive normalized 46 { .i = 0x0000000000000001ULL }, // smallest possible denorm 47 { .i = 0x000fffffffffffffULL }, // largest possible denorm 48 { .i = 0x7ff0000000000001ULL }, // smallest SNAn 49 { .i = 0x7ff7ffffffffffffULL }, // largest SNAn 50 { .i = 0x7ff8000000000000ULL }, // smallest QNAn 51 { .i = 0x7fffffffffffffffULL }, // largest QNAn 52 { .i = 0xfff0000000000000ULL }, // -infinity 53 { .i = 0x7ff0000000000000ULL }, // +infinity 54 }; 55 56 #define countof(a) (sizeof(a) / sizeof((a)[0])) 57 __attribute__((unused)) static const unsigned int float_test_vec_size = countof(float_test_vec); 58 59 #define PRINT_FLOAT \ 60 printf("0x%016llx %f %F %a %A\n", \ 61 float_test_vec[i], \ 62 *(const double *)&float_test_vec[i], \ 63 *(const double *)&float_test_vec[i], \ 64 *(const double *)&float_test_vec[i], \ 65 *(const double *)&float_test_vec[i]) 66 67