| ... | @@ -11,54 +11,124 @@ fn test__truncsfhf2(a: u32, expected: u16) void { | ... | @@ -11,54 +11,124 @@ fn test__truncsfhf2(a: u32, expected: u16) void { |
| 11 | } | 11 | } |
| 12 | | 12 | |
| 13 | test "truncsfhf2" { | 13 | test "truncsfhf2" { |
| 14 | test__truncsfhf2(0x7fc00000, 0x7e00); // qNaN | 14 | test__truncsfhf2(0x7fc00000, 0x7e00); // qNaN |
| 15 | test__truncsfhf2(0x7fe00000, 0x7f00); // sNaN | 15 | test__truncsfhf2(0x7fe00000, 0x7f00); // sNaN |
| 16 | | 16 | |
| 17 | test__truncsfhf2(0, 0); // 0 | 17 | test__truncsfhf2(0, 0); // 0 |
| 18 | test__truncsfhf2(0x80000000, 0x8000); // -0 | 18 | test__truncsfhf2(0x80000000, 0x8000); // -0 |
| 19 | | 19 | |
| 20 | test__truncsfhf2(0x7f800000, 0x7c00); // inf | 20 | test__truncsfhf2(0x7f800000, 0x7c00); // inf |
| 21 | test__truncsfhf2(0xff800000, 0xfc00); // -inf | 21 | test__truncsfhf2(0xff800000, 0xfc00); // -inf |
| 22 | | 22 | |
| 23 | test__truncsfhf2(0x477ff000, 0x7c00); // 65520 -> inf | 23 | test__truncsfhf2(0x477ff000, 0x7c00); // 65520 -> inf |
| 24 | test__truncsfhf2(0xc77ff000, 0xfc00); // -65520 -> -inf | 24 | test__truncsfhf2(0xc77ff000, 0xfc00); // -65520 -> -inf |
| 25 | | 25 | |
| 26 | test__truncsfhf2(0x71cc3892, 0x7c00); // 0x1.987124876876324p+100 -> inf | 26 | test__truncsfhf2(0x71cc3892, 0x7c00); // 0x1.987124876876324p+100 -> inf |
| 27 | test__truncsfhf2(0xf1cc3892, 0xfc00); // -0x1.987124876876324p+100 -> -inf | 27 | test__truncsfhf2(0xf1cc3892, 0xfc00); // -0x1.987124876876324p+100 -> -inf |
| 28 | | 28 | |
| 29 | test__truncsfhf2(0x38800000, 0x0400); // normal (min), 2**-14 | 29 | test__truncsfhf2(0x38800000, 0x0400); // normal (min), 2**-14 |
| 30 | test__truncsfhf2(0xb8800000, 0x8400); // normal (min), -2**-14 | 30 | test__truncsfhf2(0xb8800000, 0x8400); // normal (min), -2**-14 |
| 31 | | 31 | |
| 32 | test__truncsfhf2(0x477fe000, 0x7bff); // normal (max), 65504 | 32 | test__truncsfhf2(0x477fe000, 0x7bff); // normal (max), 65504 |
| 33 | test__truncsfhf2(0xc77fe000, 0xfbff); // normal (max), -65504 | 33 | test__truncsfhf2(0xc77fe000, 0xfbff); // normal (max), -65504 |
| 34 | | 34 | |
| 35 | test__truncsfhf2(0x477fe100, 0x7bff); // normal, 65505 -> 65504 | 35 | test__truncsfhf2(0x477fe100, 0x7bff); // normal, 65505 -> 65504 |
| 36 | test__truncsfhf2(0xc77fe100, 0xfbff); // normal, -65505 -> -65504 | 36 | test__truncsfhf2(0xc77fe100, 0xfbff); // normal, -65505 -> -65504 |
| 37 | | 37 | |
| 38 | test__truncsfhf2(0x477fef00, 0x7bff); // normal, 65519 -> 65504 | 38 | test__truncsfhf2(0x477fef00, 0x7bff); // normal, 65519 -> 65504 |
| 39 | test__truncsfhf2(0xc77fef00, 0xfbff); // normal, -65519 -> -65504 | 39 | test__truncsfhf2(0xc77fef00, 0xfbff); // normal, -65519 -> -65504 |
| 40 | | 40 | |
| 41 | test__truncsfhf2(0x3f802000, 0x3c01); // normal, 1 + 2**-10 | 41 | test__truncsfhf2(0x3f802000, 0x3c01); // normal, 1 + 2**-10 |
| 42 | test__truncsfhf2(0xbf802000, 0xbc01); // normal, -1 - 2**-10 | 42 | test__truncsfhf2(0xbf802000, 0xbc01); // normal, -1 - 2**-10 |
| 43 | | 43 | |
| 44 | test__truncsfhf2(0x3eaaa000, 0x3555); // normal, approx. 1/3 | 44 | test__truncsfhf2(0x3eaaa000, 0x3555); // normal, approx. 1/3 |
| 45 | test__truncsfhf2(0xbeaaa000, 0xb555); // normal, approx. -1/3 | 45 | test__truncsfhf2(0xbeaaa000, 0xb555); // normal, approx. -1/3 |
| 46 | | 46 | |
| 47 | test__truncsfhf2(0x40490fdb, 0x4248); // normal, 3.1415926535 | 47 | test__truncsfhf2(0x40490fdb, 0x4248); // normal, 3.1415926535 |
| 48 | test__truncsfhf2(0xc0490fdb, 0xc248); // normal, -3.1415926535 | 48 | test__truncsfhf2(0xc0490fdb, 0xc248); // normal, -3.1415926535 |
| 49 | | 49 | |
| 50 | test__truncsfhf2(0x45cc3892, 0x6e62); // normal, 0x1.987124876876324p+12 | 50 | test__truncsfhf2(0x45cc3892, 0x6e62); // normal, 0x1.987124876876324p+12 |
| 51 | | 51 | |
| 52 | test__truncsfhf2(0x3f800000, 0x3c00); // normal, 1 | 52 | test__truncsfhf2(0x3f800000, 0x3c00); // normal, 1 |
| 53 | test__truncsfhf2(0x38800000, 0x0400); // normal, 0x1.0p-14 | 53 | test__truncsfhf2(0x38800000, 0x0400); // normal, 0x1.0p-14 |
| 54 | | 54 | |
| 55 | test__truncsfhf2(0x33800000, 0x0001); // denormal (min), 2**-24 | 55 | test__truncsfhf2(0x33800000, 0x0001); // denormal (min), 2**-24 |
| 56 | test__truncsfhf2(0xb3800000, 0x8001); // denormal (min), -2**-24 | 56 | test__truncsfhf2(0xb3800000, 0x8001); // denormal (min), -2**-24 |
| 57 | | 57 | |
| 58 | test__truncsfhf2(0x387fc000, 0x03ff); // denormal (max), 2**-14 - 2**-24 | 58 | test__truncsfhf2(0x387fc000, 0x03ff); // denormal (max), 2**-14 - 2**-24 |
| 59 | test__truncsfhf2(0xb87fc000, 0x83ff); // denormal (max), -2**-14 + 2**-24 | 59 | test__truncsfhf2(0xb87fc000, 0x83ff); // denormal (max), -2**-14 + 2**-24 |
| 60 | | 60 | |
| 61 | test__truncsfhf2(0x35800000, 0x0010); // denormal, 0x1.0p-20 | 61 | test__truncsfhf2(0x35800000, 0x0010); // denormal, 0x1.0p-20 |
| 62 | test__truncsfhf2(0x33280000, 0x0001); // denormal, 0x1.5p-25 -> 0x1.0p-24 | 62 | test__truncsfhf2(0x33280000, 0x0001); // denormal, 0x1.5p-25 -> 0x1.0p-24 |
| 63 | test__truncsfhf2(0x33000000, 0x0000); // 0x1.0p-25 -> zero | 63 | test__truncsfhf2(0x33000000, 0x0000); // 0x1.0p-25 -> zero |
| | 64 | } |
| | 65 | |
| | 66 | const __trunctfsf2 = @import("truncXfYf2.zig").__trunctfsf2; |
| | 67 | |
| | 68 | fn test__trunctfsf2(a: f128, expected: u32) void { |
| | 69 | const x = __trunctfsf2(a); |
| | 70 | |
| | 71 | const rep = @bitCast(u32, x); |
| | 72 | if (rep == expected) { |
| | 73 | return; |
| | 74 | } |
| | 75 | // test other possible NaN representation(signal NaN) |
| | 76 | else if (expected == 0x7fc00000) { |
| | 77 | if ((rep & 0x7f800000) == 0x7f800000 and (rep & 0x7fffff) > 0) { |
| | 78 | return; |
| | 79 | } |
| | 80 | } |
| | 81 | |
| | 82 | @panic("__trunctfsf2 test failure"); |
| | 83 | } |
| | 84 | |
| | 85 | test "trunctfsf2" { |
| | 86 | // qnan |
| | 87 | test__trunctfsf2(@bitCast(f128, u128(0x7fff800000000000 << 64)), 0x7fc00000); |
| | 88 | // nan |
| | 89 | test__trunctfsf2(@bitCast(f128, u128((0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7fc08000); |
| | 90 | // inf |
| | 91 | test__trunctfsf2(@bitCast(f128, u128(0x7fff000000000000 << 64)), 0x7f800000); |
| | 92 | // zero |
| | 93 | test__trunctfsf2(0.0, 0x0); |
| | 94 | |
| | 95 | test__trunctfsf2(0x1.23a2abb4a2ddee355f36789abcdep+5, 0x4211d156); |
| | 96 | test__trunctfsf2(0x1.e3d3c45bd3abfd98b76a54cc321fp-9, 0x3b71e9e2); |
| | 97 | test__trunctfsf2(0x1.234eebb5faa678f4488693abcdefp+4534, 0x7f800000); |
| | 98 | test__trunctfsf2(0x1.edcba9bb8c76a5a43dd21f334634p-435, 0x0); |
| | 99 | } |
| | 100 | |
| | 101 | const __trunctfdf2 = @import("truncXfYf2.zig").__trunctfdf2; |
| | 102 | |
| | 103 | fn test__trunctfdf2(a: f128, expected: u64) void { |
| | 104 | const x = __trunctfdf2(a); |
| | 105 | |
| | 106 | const rep = @bitCast(u64, x); |
| | 107 | if (rep == expected) { |
| | 108 | return; |
| | 109 | } |
| | 110 | // test other possible NaN representation(signal NaN) |
| | 111 | else if (expected == 0x7ff8000000000000) { |
| | 112 | if ((rep & 0x7ff0000000000000) == 0x7ff0000000000000 and (rep & 0xfffffffffffff) > 0) { |
| | 113 | return; |
| | 114 | } |
| | 115 | } |
| | 116 | |
| | 117 | @panic("__trunctfsf2 test failure"); |
| | 118 | } |
| | 119 | |
| | 120 | test "trunctfdf2" { |
| | 121 | // qnan |
| | 122 | test__trunctfdf2(@bitCast(f128, u128(0x7fff800000000000 << 64)), 0x7ff8000000000000); |
| | 123 | // nan |
| | 124 | test__trunctfdf2(@bitCast(f128, u128((0x7fff000000000000 | (0x810000000000 & 0xffffffffffff)) << 64)), 0x7ff8100000000000); |
| | 125 | // inf |
| | 126 | test__trunctfdf2(@bitCast(f128, u128(0x7fff000000000000 << 64)), 0x7ff0000000000000); |
| | 127 | // zero |
| | 128 | test__trunctfdf2(0.0, 0x0); |
| | 129 | |
| | 130 | test__trunctfdf2(0x1.af23456789bbaaab347645365cdep+5, 0x404af23456789bbb); |
| | 131 | test__trunctfdf2(0x1.dedafcff354b6ae9758763545432p-9, 0x3f6dedafcff354b7); |
| | 132 | test__trunctfdf2(0x1.2f34dd5f437e849b4baab754cdefp+4534, 0x7ff0000000000000); |
| | 133 | test__trunctfdf2(0x1.edcbff8ad76ab5bf46463233214fp-435, 0x24cedcbff8ad76ab); |
| 64 | } | 134 | } |