| ... | @@ -242,3 +242,59 @@ test "truncdfsf2" { | ... | @@ -242,3 +242,59 @@ test "truncdfsf2" { |
| 242 | // huge number becomes inf | 242 | // huge number becomes inf |
| 243 | test__truncdfsf2(340282366920938463463374607431768211456.0, 0x7f800000); | 243 | test__truncdfsf2(340282366920938463463374607431768211456.0, 0x7f800000); |
| 244 | } | 244 | } |
| | 245 | |
| | 246 | const __trunctfhf2 = @import("truncXfYf2.zig").__trunctfhf2; |
| | 247 | |
| | 248 | fn test__trunctfhf2(a: f128, expected: u16) void { |
| | 249 | const x = __trunctfhf2(a); |
| | 250 | |
| | 251 | const rep = @bitCast(u16, x); |
| | 252 | if (rep == expected) { |
| | 253 | return; |
| | 254 | } |
| | 255 | |
| | 256 | @import("std").debug.warn("got 0x{x} wanted 0x{x}\n", .{ rep, expected }); |
| | 257 | |
| | 258 | @panic("__trunctfhf2 test failure"); |
| | 259 | } |
| | 260 | |
| | 261 | test "trunctfhf2" { |
| | 262 | // qNaN |
| | 263 | test__trunctfhf2(@bitCast(f128, @as(u128, 0x7fff8000000000000000000000000000)), 0x7e00); |
| | 264 | // NaN |
| | 265 | test__trunctfhf2(@bitCast(f128, @as(u128, 0x7fff0000000000000000000000000001)), 0x7e00); |
| | 266 | // inf |
| | 267 | test__trunctfhf2(@bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000)), 0x7c00); |
| | 268 | test__trunctfhf2(-@bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000)), 0xfc00); |
| | 269 | // zero |
| | 270 | test__trunctfhf2(0.0, 0x0); |
| | 271 | test__trunctfhf2(-0.0, 0x8000); |
| | 272 | |
| | 273 | test__trunctfhf2(3.1415926535, 0x4248); |
| | 274 | test__trunctfhf2(-3.1415926535, 0xc248); |
| | 275 | test__trunctfhf2(0x1.987124876876324p+100, 0x7c00); |
| | 276 | test__trunctfhf2(0x1.987124876876324p+12, 0x6e62); |
| | 277 | test__trunctfhf2(0x1.0p+0, 0x3c00); |
| | 278 | test__trunctfhf2(0x1.0p-14, 0x0400); |
| | 279 | // denormal |
| | 280 | test__trunctfhf2(0x1.0p-20, 0x0010); |
| | 281 | test__trunctfhf2(0x1.0p-24, 0x0001); |
| | 282 | test__trunctfhf2(-0x1.0p-24, 0x8001); |
| | 283 | test__trunctfhf2(0x1.5p-25, 0x0001); |
| | 284 | // and back to zero |
| | 285 | test__trunctfhf2(0x1.0p-25, 0x0000); |
| | 286 | test__trunctfhf2(-0x1.0p-25, 0x8000); |
| | 287 | // max (precise) |
| | 288 | test__trunctfhf2(65504.0, 0x7bff); |
| | 289 | // max (rounded) |
| | 290 | test__trunctfhf2(65519.0, 0x7bff); |
| | 291 | // max (to +inf) |
| | 292 | test__trunctfhf2(65520.0, 0x7c00); |
| | 293 | test__trunctfhf2(65536.0, 0x7c00); |
| | 294 | test__trunctfhf2(-65520.0, 0xfc00); |
| | 295 | |
| | 296 | test__trunctfhf2(0x1.23a2abb4a2ddee355f36789abcdep+5, 0x508f); |
| | 297 | test__trunctfhf2(0x1.e3d3c45bd3abfd98b76a54cc321fp-9, 0x1b8f); |
| | 298 | test__trunctfhf2(0x1.234eebb5faa678f4488693abcdefp+453, 0x7c00); |
| | 299 | test__trunctfhf2(0x1.edcba9bb8c76a5a43dd21f334634p-43, 0x0); |
| | 300 | } |