rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2014 Travis Geiselbrecht |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #include <stdint.h> |
| 25 | |
| 26 | union double_int { |
| 27 | double d; |
| 28 | uint64_t i; |
| 29 | }; |
| 30 | |
| 31 | static const union double_int float_test_vec[] = { |
| 32 | { .d = -2.0 }, |
| 33 | { .d = -1.0 }, |
| 34 | { .d = -0.5 }, |
| 35 | { .d = -0.0 }, |
| 36 | { .d = 0.0 }, |
| 37 | { .d = 0.01 }, |
| 38 | { .d = 0.1 }, |
| 39 | { .d = 0.2 }, |
| 40 | { .d = 0.25 }, |
| 41 | { .d = 0.5 }, |
| 42 | { .d = 0.75 }, |
| 43 | { .d = 1.0 }, |
| 44 | { .d = 2.0 }, |
| 45 | { .d = 3.0 }, |
| 46 | { .d = 10.0 }, |
| 47 | { .d = 100.0 }, |
| 48 | { .d = 123456.0 }, |
| 49 | { .d = -123456.0 }, |
| 50 | { .d = 546.5645644531f }, |
| 51 | { .d = -546.5645644531f }, |
| 52 | { .d = 0.12345 }, |
| 53 | { .d = 0.0000012345 }, |
| 54 | { .d = 0.0000019999 }, |
| 55 | { .d = 0.0000015 }, |
| 56 | { .i = 0x4005bf0a8b145649ULL }, // e |
| 57 | { .i = 0x400921fb54442d18ULL }, // pi |
| 58 | { .i = 0x43f0000000000000ULL }, // 2^64 |
| 59 | { .i = 0x7fefffffffffffffULL }, // largest normalized |
| 60 | { .i = 0x0010000000000000ULL }, // least positive normalized |
| 61 | { .i = 0x0000000000000001ULL }, // smallest possible denorm |
| 62 | { .i = 0x000fffffffffffffULL }, // largest possible denorm |
| 63 | { .i = 0x7ff0000000000001ULL }, // smallest SNAn |
| 64 | { .i = 0x7ff7ffffffffffffULL }, // largest SNAn |
| 65 | { .i = 0x7ff8000000000000ULL }, // smallest QNAn |
| 66 | { .i = 0x7fffffffffffffffULL }, // largest QNAn |
| 67 | { .i = 0xfff0000000000000ULL }, // -infinity |
| 68 | { .i = 0x7ff0000000000000ULL }, // +infinity |
| 69 | }; |
| 70 | |
| 71 | #define countof(a) (sizeof(a) / sizeof((a)[0])) |
| 72 | static const unsigned int float_test_vec_size = countof(float_test_vec); |
| 73 | |
| 74 | #define PRINT_FLOAT \ |
| 75 | printf("0x%016llx %f %F %a %A\n", \ |
| 76 | float_test_vec[i], \ |
| 77 | *(const double *)&float_test_vec[i], \ |
| 78 | *(const double *)&float_test_vec[i], \ |
| 79 | *(const double *)&float_test_vec[i], \ |
| 80 | *(const double *)&float_test_vec[i]) |
| 81 | |