| ... | @@ -19,34 +19,93 @@ fn epsForType(comptime T: type) T { | ... | @@ -19,34 +19,93 @@ fn epsForType(comptime T: type) T { |
| 19 | }; | 19 | }; |
| 20 | } | 20 | } |
| 21 | | 21 | |
| 22 | test "floating point comparisons" { | 22 | test "cmp f16" { |
| 23 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 23 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| | 24 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| | 25 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| | 26 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; |
| | 27 | |
| | 28 | try testCmp(f16); |
| | 29 | try comptime testCmp(f16); |
| | 30 | } |
| | 31 | |
| | 32 | test "cmp f32/f64" { |
| | 33 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| | 34 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 24 | | 35 | |
| 25 | try testFloatComparisons(); | 36 | try testCmp(f32); |
| 26 | try comptime testFloatComparisons(); | 37 | try comptime testCmp(f32); |
| | 38 | try testCmp(f64); |
| | 39 | try comptime testCmp(f64); |
| 27 | } | 40 | } |
| 28 | | 41 | |
| 29 | fn testFloatComparisons() !void { | 42 | test "cmp f128" { |
| 30 | inline for ([_]type{ f16, f32, f64, f128 }) |T| { | 43 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| | 44 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| | 45 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; |
| | 46 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| | 47 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| | 48 | |
| | 49 | try testCmp(f128); |
| | 50 | try comptime testCmp(f128); |
| | 51 | } |
| | 52 | |
| | 53 | test "cmp f80/c_longdouble" { |
| | 54 | if (true) return error.SkipZigTest; |
| | 55 | |
| | 56 | try testCmp(f80); |
| | 57 | try comptime testCmp(f80); |
| | 58 | try testCmp(c_longdouble); |
| | 59 | try comptime testCmp(c_longdouble); |
| | 60 | } |
| | 61 | |
| | 62 | fn testCmp(comptime T: type) !void { |
| | 63 | { |
| 31 | // No decimal part | 64 | // No decimal part |
| 32 | { | 65 | var x: T = 1.0; |
| 33 | const x: T = 1.0; | 66 | try expect(x == 1.0); |
| 34 | try expect(x == 1); | 67 | try expect(x != 0.0); |
| 35 | try expect(x != 0); | 68 | try expect(x > 0.0); |
| 36 | try expect(x > 0); | 69 | try expect(x < 2.0); |
| 37 | try expect(x < 2); | 70 | try expect(x >= 1.0); |
| 38 | try expect(x >= 1); | 71 | try expect(x <= 1.0); |
| 39 | try expect(x <= 1); | 72 | } |
| 40 | } | 73 | { |
| 41 | // Non-zero decimal part | 74 | // Non-zero decimal part |
| 42 | { | 75 | var x: T = 1.5; |
| 43 | const x: T = 1.5; | 76 | try expect(x != 1.0); |
| 44 | try expect(x != 1); | 77 | try expect(x != 2.0); |
| 45 | try expect(x != 2); | 78 | try expect(x > 1.0); |
| 46 | try expect(x > 1); | 79 | try expect(x < 2.0); |
| 47 | try expect(x < 2); | 80 | try expect(x >= 1.0); |
| 48 | try expect(x >= 1); | 81 | try expect(x <= 2.0); |
| 49 | try expect(x <= 2); | 82 | } |
| | 83 | |
| | 84 | @setEvalBranchQuota(2_000); |
| | 85 | var edges = [_]T{ |
| | 86 | -math.inf(T), |
| | 87 | -math.floatMax(T), |
| | 88 | -math.floatMin(T), |
| | 89 | -math.floatTrueMin(T), |
| | 90 | -0.0, |
| | 91 | math.nan(T), |
| | 92 | 0.0, |
| | 93 | math.floatTrueMin(T), |
| | 94 | math.floatMin(T), |
| | 95 | math.floatMax(T), |
| | 96 | math.inf(T), |
| | 97 | }; |
| | 98 | for (edges, 0..) |rhs, rhs_i| { |
| | 99 | for (edges, 0..) |lhs, lhs_i| { |
| | 100 | const no_nan = lhs_i != 5 and rhs_i != 5; |
| | 101 | const lhs_order = if (lhs_i < 5) lhs_i else lhs_i - 2; |
| | 102 | const rhs_order = if (rhs_i < 5) rhs_i else rhs_i - 2; |
| | 103 | try expect((lhs == rhs) == (no_nan and lhs_order == rhs_order)); |
| | 104 | try expect((lhs != rhs) == !(no_nan and lhs_order == rhs_order)); |
| | 105 | try expect((lhs < rhs) == (no_nan and lhs_order < rhs_order)); |
| | 106 | try expect((lhs > rhs) == (no_nan and lhs_order > rhs_order)); |
| | 107 | try expect((lhs <= rhs) == (no_nan and lhs_order <= rhs_order)); |
| | 108 | try expect((lhs >= rhs) == (no_nan and lhs_order >= rhs_order)); |
| 50 | } | 109 | } |
| 51 | } | 110 | } |
| 52 | } | 111 | } |
| ... | @@ -68,27 +127,6 @@ fn testDifferentSizedFloatComparisons() !void { | ... | @@ -68,27 +127,6 @@ fn testDifferentSizedFloatComparisons() !void { |
| 68 | try expect(a < b); | 127 | try expect(a < b); |
| 69 | } | 128 | } |
| 70 | | 129 | |
| 71 | test "f80 comparisons" { | | |
| 72 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 73 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | | |
| 74 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | | |
| 75 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; | | |
| 76 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | | |
| 77 | | | |
| 78 | try expect(compareF80(0.0, .eq, -0.0)); | | |
| 79 | try expect(compareF80(0.0, .lte, -0.0)); | | |
| 80 | try expect(compareF80(0.0, .gte, -0.0)); | | |
| 81 | try expect(compareF80(1.0, .neq, -1.0)); | | |
| 82 | try expect(compareF80(2.0, .lt, 4.0)); | | |
| 83 | try expect(compareF80(2.0, .lte, 4.0)); | | |
| 84 | try expect(compareF80(-2.0, .gt, -4.0)); | | |
| 85 | try expect(compareF80(-2.0, .gte, -4.0)); | | |
| 86 | } | | |
| 87 | | | |
| 88 | fn compareF80(x: f80, op: math.CompareOperator, y: f80) bool { | | |
| 89 | return math.compare(x, op, y); | | |
| 90 | } | | |
| 91 | | | |
| 92 | // TODO This is waiting on library support for the Windows build (not sure why the other's don't need it) | 130 | // TODO This is waiting on library support for the Windows build (not sure why the other's don't need it) |
| 93 | //test "@nearbyint" { | 131 | //test "@nearbyint" { |
| 94 | // comptime testNearbyInt(); | 132 | // comptime testNearbyInt(); |
| ... | @@ -234,8 +272,8 @@ test "@sin f16" { | ... | @@ -234,8 +272,8 @@ test "@sin f16" { |
| 234 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 272 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 235 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; | 273 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; |
| 236 | | 274 | |
| 237 | try testSin(&.{f16}); | 275 | try testSin(f16); |
| 238 | try comptime testSin(&.{f16}); | 276 | try comptime testSin(f16); |
| 239 | } | 277 | } |
| 240 | | 278 | |
| 241 | test "@sin f32/f64" { | 279 | test "@sin f32/f64" { |
| ... | @@ -245,8 +283,10 @@ test "@sin f32/f64" { | ... | @@ -245,8 +283,10 @@ test "@sin f32/f64" { |
| 245 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 283 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 246 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 284 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 247 | | 285 | |
| 248 | try testSin(&.{ f32, f64 }); | 286 | try testSin(f32); |
| 249 | try comptime testSin(&.{ f32, f64 }); | 287 | comptime try testSin(f32); |
| | 288 | try testSin(f64); |
| | 289 | comptime try testSin(f64); |
| 250 | } | 290 | } |
| 251 | | 291 | |
| 252 | test "@sin f80/f128/c_longdouble" { | 292 | test "@sin f80/f128/c_longdouble" { |
| ... | @@ -256,20 +296,22 @@ test "@sin f80/f128/c_longdouble" { | ... | @@ -256,20 +296,22 @@ test "@sin f80/f128/c_longdouble" { |
| 256 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 296 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 257 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 297 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 258 | | 298 | |
| 259 | try testSin(&.{ f80, f128, c_longdouble }); | 299 | try testSin(f80); |
| 260 | try comptime testSin(&.{ f80, f128, c_longdouble }); | 300 | comptime try testSin(f80); |
| | 301 | try testSin(f128); |
| | 302 | comptime try testSin(f128); |
| | 303 | try testSin(c_longdouble); |
| | 304 | comptime try testSin(c_longdouble); |
| 261 | } | 305 | } |
| 262 | | 306 | |
| 263 | fn testSin(comptime Ts: []const type) !void { | 307 | fn testSin(comptime T: type) !void { |
| 264 | inline for (Ts) |T| { | 308 | const eps = epsForType(T); |
| 265 | const eps = epsForType(T); | 309 | var zero: T = 0; |
| 266 | var zero: T = 0; | 310 | try expect(@sin(zero) == 0); |
| 267 | try expect(@sin(zero) == 0); | 311 | var pi: T = math.pi; |
| 268 | var pi: T = std.math.pi; | 312 | try expect(math.approxEqAbs(T, @sin(pi), 0, eps)); |
| 269 | try expect(math.approxEqAbs(T, @sin(pi), 0, eps)); | 313 | try expect(math.approxEqAbs(T, @sin(pi / 2.0), 1, eps)); |
| 270 | try expect(math.approxEqAbs(T, @sin(pi / 2.0), 1, eps)); | 314 | try expect(math.approxEqAbs(T, @sin(pi / 4.0), 0.7071067811865475, eps)); |
| 271 | try expect(math.approxEqAbs(T, @sin(pi / 4.0), 0.7071067811865475, eps)); | | |
| 272 | } | | |
| 273 | } | 315 | } |
| 274 | | 316 | |
| 275 | test "@sin with vectors" { | 317 | test "@sin with vectors" { |
| ... | @@ -300,8 +342,8 @@ test "@cos f16" { | ... | @@ -300,8 +342,8 @@ test "@cos f16" { |
| 300 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 342 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 301 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; | 343 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; |
| 302 | | 344 | |
| 303 | try testCos(&.{f16}); | 345 | try testCos(f16); |
| 304 | try comptime testCos(&.{f16}); | 346 | try comptime testCos(f16); |
| 305 | } | 347 | } |
| 306 | | 348 | |
| 307 | test "@cos f32/f64" { | 349 | test "@cos f32/f64" { |
| ... | @@ -311,8 +353,10 @@ test "@cos f32/f64" { | ... | @@ -311,8 +353,10 @@ test "@cos f32/f64" { |
| 311 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 353 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 312 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 354 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 313 | | 355 | |
| 314 | try testCos(&.{ f32, f64 }); | 356 | try testCos(f32); |
| 315 | try comptime testCos(&.{ f32, f64 }); | 357 | try comptime testCos(f32); |
| | 358 | try testCos(f64); |
| | 359 | try comptime testCos(f64); |
| 316 | } | 360 | } |
| 317 | | 361 | |
| 318 | test "@cos f80/f128/c_longdouble" { | 362 | test "@cos f80/f128/c_longdouble" { |
| ... | @@ -322,20 +366,22 @@ test "@cos f80/f128/c_longdouble" { | ... | @@ -322,20 +366,22 @@ test "@cos f80/f128/c_longdouble" { |
| 322 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 366 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 323 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 367 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 324 | | 368 | |
| 325 | try testCos(&.{ f80, f128, c_longdouble }); | 369 | try testCos(f80); |
| 326 | try comptime testCos(&.{ f80, f128, c_longdouble }); | 370 | try comptime testCos(f80); |
| | 371 | try testCos(f128); |
| | 372 | try comptime testCos(f128); |
| | 373 | try testCos(c_longdouble); |
| | 374 | try comptime testCos(c_longdouble); |
| 327 | } | 375 | } |
| 328 | | 376 | |
| 329 | fn testCos(comptime Ts: []const type) !void { | 377 | fn testCos(comptime T: type) !void { |
| 330 | inline for (Ts) |T| { | 378 | const eps = epsForType(T); |
| 331 | const eps = epsForType(T); | 379 | var zero: T = 0; |
| 332 | var zero: T = 0; | 380 | try expect(@cos(zero) == 1); |
| 333 | try expect(@cos(zero) == 1); | 381 | var pi: T = math.pi; |
| 334 | var pi: T = std.math.pi; | 382 | try expect(math.approxEqAbs(T, @cos(pi), -1, eps)); |
| 335 | try expect(math.approxEqAbs(T, @cos(pi), -1, eps)); | 383 | try expect(math.approxEqAbs(T, @cos(pi / 2.0), 0, eps)); |
| 336 | try expect(math.approxEqAbs(T, @cos(pi / 2.0), 0, eps)); | 384 | try expect(math.approxEqAbs(T, @cos(pi / 4.0), 0.7071067811865475, eps)); |
| 337 | try expect(math.approxEqAbs(T, @cos(pi / 4.0), 0.7071067811865475, eps)); | | |
| 338 | } | | |
| 339 | } | 385 | } |
| 340 | | 386 | |
| 341 | test "@cos with vectors" { | 387 | test "@cos with vectors" { |
| ... | @@ -366,8 +412,8 @@ test "@tan f16" { | ... | @@ -366,8 +412,8 @@ test "@tan f16" { |
| 366 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 412 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 367 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; | 413 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; |
| 368 | | 414 | |
| 369 | try testTan(&.{f16}); | 415 | try testTan(f16); |
| 370 | try comptime testTan(&.{f16}); | 416 | try comptime testTan(f16); |
| 371 | } | 417 | } |
| 372 | | 418 | |
| 373 | test "@tan f32/f64" { | 419 | test "@tan f32/f64" { |
| ... | @@ -377,8 +423,10 @@ test "@tan f32/f64" { | ... | @@ -377,8 +423,10 @@ test "@tan f32/f64" { |
| 377 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 423 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 378 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 424 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 379 | | 425 | |
| 380 | try testTan(&.{ f32, f64 }); | 426 | try testTan(f32); |
| 381 | try comptime testTan(&.{ f32, f64 }); | 427 | try comptime testTan(f32); |
| | 428 | try testTan(f64); |
| | 429 | try comptime testTan(f64); |
| 382 | } | 430 | } |
| 383 | | 431 | |
| 384 | test "@tan f80/f128/c_longdouble" { | 432 | test "@tan f80/f128/c_longdouble" { |
| ... | @@ -388,20 +436,22 @@ test "@tan f80/f128/c_longdouble" { | ... | @@ -388,20 +436,22 @@ test "@tan f80/f128/c_longdouble" { |
| 388 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 436 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 389 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 437 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 390 | | 438 | |
| 391 | try testTan(&.{ f80, f128, c_longdouble }); | 439 | try testTan(f80); |
| 392 | try comptime testTan(&.{ f80, f128, c_longdouble }); | 440 | try comptime testTan(f80); |
| | 441 | try testTan(f128); |
| | 442 | try comptime testTan(f128); |
| | 443 | try testTan(c_longdouble); |
| | 444 | try comptime testTan(c_longdouble); |
| 393 | } | 445 | } |
| 394 | | 446 | |
| 395 | fn testTan(comptime Ts: []const type) !void { | 447 | fn testTan(comptime T: type) !void { |
| 396 | inline for (Ts) |T| { | 448 | const eps = epsForType(T); |
| 397 | const eps = epsForType(T); | 449 | var zero: T = 0; |
| 398 | var zero: T = 0; | 450 | try expect(@tan(zero) == 0); |
| 399 | try expect(@tan(zero) == 0); | 451 | var pi: T = math.pi; |
| 400 | var pi: T = std.math.pi; | 452 | try expect(math.approxEqAbs(T, @tan(pi), 0, eps)); |
| 401 | try expect(math.approxEqAbs(T, @tan(pi), 0, eps)); | 453 | try expect(math.approxEqAbs(T, @tan(pi / 3.0), 1.732050807568878, eps)); |
| 402 | try expect(math.approxEqAbs(T, @tan(pi / 3.0), 1.732050807568878, eps)); | 454 | try expect(math.approxEqAbs(T, @tan(pi / 4.0), 1, eps)); |
| 403 | try expect(math.approxEqAbs(T, @tan(pi / 4.0), 1, eps)); | | |
| 404 | } | | |
| 405 | } | 455 | } |
| 406 | | 456 | |
| 407 | test "@tan with vectors" { | 457 | test "@tan with vectors" { |
| ... | @@ -432,8 +482,8 @@ test "@exp f16" { | ... | @@ -432,8 +482,8 @@ test "@exp f16" { |
| 432 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 482 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 433 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; | 483 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; |
| 434 | | 484 | |
| 435 | try testExp(&.{f16}); | 485 | try testExp(f16); |
| 436 | try comptime testExp(&.{f16}); | 486 | try comptime testExp(f16); |
| 437 | } | 487 | } |
| 438 | | 488 | |
| 439 | test "@exp f32/f64" { | 489 | test "@exp f32/f64" { |
| ... | @@ -443,8 +493,10 @@ test "@exp f32/f64" { | ... | @@ -443,8 +493,10 @@ test "@exp f32/f64" { |
| 443 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 493 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 444 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 494 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 445 | | 495 | |
| 446 | try testExp(&.{ f32, f64 }); | 496 | try testExp(f32); |
| 447 | try comptime testExp(&.{ f32, f64 }); | 497 | try comptime testExp(f32); |
| | 498 | try testExp(f64); |
| | 499 | try comptime testExp(f64); |
| 448 | } | 500 | } |
| 449 | | 501 | |
| 450 | test "@exp f80/f128/c_longdouble" { | 502 | test "@exp f80/f128/c_longdouble" { |
| ... | @@ -454,20 +506,22 @@ test "@exp f80/f128/c_longdouble" { | ... | @@ -454,20 +506,22 @@ test "@exp f80/f128/c_longdouble" { |
| 454 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 506 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 455 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 507 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 456 | | 508 | |
| 457 | try testExp(&.{ f80, f128, c_longdouble }); | 509 | try testExp(f80); |
| 458 | try comptime testExp(&.{ f80, f128, c_longdouble }); | 510 | try comptime testExp(f80); |
| | 511 | try testExp(f128); |
| | 512 | try comptime testExp(f128); |
| | 513 | try testExp(c_longdouble); |
| | 514 | try comptime testExp(c_longdouble); |
| 459 | } | 515 | } |
| 460 | | 516 | |
| 461 | fn testExp(comptime Ts: []const type) !void { | 517 | fn testExp(comptime T: type) !void { |
| 462 | inline for (Ts) |T| { | 518 | const eps = epsForType(T); |
| 463 | const eps = epsForType(T); | 519 | var zero: T = 0; |
| 464 | var zero: T = 0; | 520 | try expect(@exp(zero) == 1); |
| 465 | try expect(@exp(zero) == 1); | 521 | var two: T = 2; |
| 466 | var two: T = 2; | 522 | try expect(math.approxEqAbs(T, @exp(two), 7.389056098930650, eps)); |
| 467 | try expect(math.approxEqAbs(T, @exp(two), 7.389056098930650, eps)); | 523 | var five: T = 5; |
| 468 | var five: T = 5; | 524 | try expect(math.approxEqAbs(T, @exp(five), 148.4131591025766, eps)); |
| 469 | try expect(math.approxEqAbs(T, @exp(five), 148.4131591025766, eps)); | | |
| 470 | } | | |
| 471 | } | 525 | } |
| 472 | | 526 | |
| 473 | test "@exp with vectors" { | 527 | test "@exp with vectors" { |
| ... | @@ -498,8 +552,8 @@ test "@exp2 f16" { | ... | @@ -498,8 +552,8 @@ test "@exp2 f16" { |
| 498 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 552 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 499 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; | 553 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; |
| 500 | | 554 | |
| 501 | try testExp2(&.{f16}); | 555 | try testExp2(f16); |
| 502 | try comptime testExp2(&.{f16}); | 556 | try comptime testExp2(f16); |
| 503 | } | 557 | } |
| 504 | | 558 | |
| 505 | test "@exp2 f32/f64" { | 559 | test "@exp2 f32/f64" { |
| ... | @@ -509,8 +563,10 @@ test "@exp2 f32/f64" { | ... | @@ -509,8 +563,10 @@ test "@exp2 f32/f64" { |
| 509 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 563 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 510 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 564 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 511 | | 565 | |
| 512 | try testExp2(&.{ f32, f64 }); | 566 | try testExp2(f32); |
| 513 | try comptime testExp2(&.{ f32, f64 }); | 567 | try comptime testExp2(f32); |
| | 568 | try testExp2(f64); |
| | 569 | try comptime testExp2(f64); |
| 514 | } | 570 | } |
| 515 | | 571 | |
| 516 | test "@exp2 f80/f128/c_longdouble" { | 572 | test "@exp2 f80/f128/c_longdouble" { |
| ... | @@ -520,20 +576,22 @@ test "@exp2 f80/f128/c_longdouble" { | ... | @@ -520,20 +576,22 @@ test "@exp2 f80/f128/c_longdouble" { |
| 520 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 576 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 521 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 577 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 522 | | 578 | |
| 523 | try testExp2(&.{ f80, f128, c_longdouble }); | 579 | try testExp2(f80); |
| 524 | try comptime testExp2(&.{ f80, f128, c_longdouble }); | 580 | try comptime testExp2(f80); |
| | 581 | try testExp2(f128); |
| | 582 | try comptime testExp2(f128); |
| | 583 | try testExp2(c_longdouble); |
| | 584 | try comptime testExp2(c_longdouble); |
| 525 | } | 585 | } |
| 526 | | 586 | |
| 527 | fn testExp2(comptime Ts: []const type) !void { | 587 | fn testExp2(comptime T: type) !void { |
| 528 | inline for (Ts) |T| { | 588 | const eps = epsForType(T); |
| 529 | const eps = epsForType(T); | 589 | var two: T = 2; |
| 530 | var two: T = 2; | 590 | try expect(@exp2(two) == 4); |
| 531 | try expect(@exp2(two) == 4); | 591 | var one_point_five: T = 1.5; |
| 532 | var one_point_five: T = 1.5; | 592 | try expect(math.approxEqAbs(T, @exp2(one_point_five), 2.8284271247462, eps)); |
| 533 | try expect(math.approxEqAbs(T, @exp2(one_point_five), 2.8284271247462, eps)); | 593 | var four_point_five: T = 4.5; |
| 534 | var four_point_five: T = 4.5; | 594 | try expect(math.approxEqAbs(T, @exp2(four_point_five), 22.627416997969, eps)); |
| 535 | try expect(math.approxEqAbs(T, @exp2(four_point_five), 22.627416997969, eps)); | | |
| 536 | } | | |
| 537 | } | 595 | } |
| 538 | | 596 | |
| 539 | test "@exp2 with @vectors" { | 597 | test "@exp2 with @vectors" { |
| ... | @@ -564,8 +622,8 @@ test "@log f16" { | ... | @@ -564,8 +622,8 @@ test "@log f16" { |
| 564 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 622 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 565 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; | 623 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; |
| 566 | | 624 | |
| 567 | try testLog(&.{f16}); | 625 | try testLog(f16); |
| 568 | try comptime testLog(&.{f16}); | 626 | try comptime testLog(f16); |
| 569 | } | 627 | } |
| 570 | | 628 | |
| 571 | test "@log f32/f64" { | 629 | test "@log f32/f64" { |
| ... | @@ -575,8 +633,10 @@ test "@log f32/f64" { | ... | @@ -575,8 +633,10 @@ test "@log f32/f64" { |
| 575 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 633 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 576 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 634 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 577 | | 635 | |
| 578 | try testLog(&.{ f32, f64 }); | 636 | try testLog(f32); |
| 579 | try comptime testLog(&.{ f32, f64 }); | 637 | try comptime testLog(f32); |
| | 638 | try testLog(f64); |
| | 639 | try comptime testLog(f64); |
| 580 | } | 640 | } |
| 581 | | 641 | |
| 582 | test "@log f80/f128/c_longdouble" { | 642 | test "@log f80/f128/c_longdouble" { |
| ... | @@ -586,20 +646,22 @@ test "@log f80/f128/c_longdouble" { | ... | @@ -586,20 +646,22 @@ test "@log f80/f128/c_longdouble" { |
| 586 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 646 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 587 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 647 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 588 | | 648 | |
| 589 | try testLog(&.{ f80, f128, c_longdouble }); | 649 | try testLog(f80); |
| 590 | try comptime testLog(&.{ f80, f128, c_longdouble }); | 650 | try comptime testLog(f80); |
| | 651 | try testLog(f128); |
| | 652 | try comptime testLog(f128); |
| | 653 | try testLog(c_longdouble); |
| | 654 | try comptime testLog(c_longdouble); |
| 591 | } | 655 | } |
| 592 | | 656 | |
| 593 | fn testLog(comptime Ts: []const type) !void { | 657 | fn testLog(comptime T: type) !void { |
| 594 | inline for (Ts) |T| { | 658 | const eps = epsForType(T); |
| 595 | const eps = epsForType(T); | 659 | var e: T = math.e; |
| 596 | var e: T = std.math.e; | 660 | try expect(math.approxEqAbs(T, @log(e), 1, eps)); |
| 597 | try expect(math.approxEqAbs(T, @log(e), 1, eps)); | 661 | var two: T = 2; |
| 598 | var two: T = 2; | 662 | try expect(math.approxEqAbs(T, @log(two), 0.6931471805599, eps)); |
| 599 | try expect(math.approxEqAbs(T, @log(two), 0.6931471805599, eps)); | 663 | var five: T = 5; |
| 600 | var five: T = 5; | 664 | try expect(math.approxEqAbs(T, @log(five), 1.6094379124341, eps)); |
| 601 | try expect(math.approxEqAbs(T, @log(five), 1.6094379124341, eps)); | | |
| 602 | } | | |
| 603 | } | 665 | } |
| 604 | | 666 | |
| 605 | test "@log with @vectors" { | 667 | test "@log with @vectors" { |
| ... | @@ -628,8 +690,8 @@ test "@log2 f16" { | ... | @@ -628,8 +690,8 @@ test "@log2 f16" { |
| 628 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 690 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 629 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; | 691 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; |
| 630 | | 692 | |
| 631 | try testLog2(&.{f16}); | 693 | try testLog2(f16); |
| 632 | try comptime testLog2(&.{f16}); | 694 | try comptime testLog2(f16); |
| 633 | } | 695 | } |
| 634 | | 696 | |
| 635 | test "@log2 f32/f64" { | 697 | test "@log2 f32/f64" { |
| ... | @@ -639,8 +701,10 @@ test "@log2 f32/f64" { | ... | @@ -639,8 +701,10 @@ test "@log2 f32/f64" { |
| 639 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 701 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 640 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 702 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 641 | | 703 | |
| 642 | try testLog2(&.{ f32, f64 }); | 704 | try testLog2(f32); |
| 643 | try comptime testLog2(&.{ f32, f64 }); | 705 | try comptime testLog2(f32); |
| | 706 | try testLog2(f64); |
| | 707 | try comptime testLog2(f64); |
| 644 | } | 708 | } |
| 645 | | 709 | |
| 646 | test "@log2 f80/f128/c_longdouble" { | 710 | test "@log2 f80/f128/c_longdouble" { |
| ... | @@ -650,20 +714,22 @@ test "@log2 f80/f128/c_longdouble" { | ... | @@ -650,20 +714,22 @@ test "@log2 f80/f128/c_longdouble" { |
| 650 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 714 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 651 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 715 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 652 | | 716 | |
| 653 | try testLog2(&.{ f80, f128, c_longdouble }); | 717 | try testLog2(f80); |
| 654 | try comptime testLog2(&.{ f80, f128, c_longdouble }); | 718 | try comptime testLog2(f80); |
| | 719 | try testLog2(f128); |
| | 720 | try comptime testLog2(f128); |
| | 721 | try testLog2(c_longdouble); |
| | 722 | try comptime testLog2(c_longdouble); |
| 655 | } | 723 | } |
| 656 | | 724 | |
| 657 | fn testLog2(comptime Ts: []const type) !void { | 725 | fn testLog2(comptime T: type) !void { |
| 658 | inline for (Ts) |T| { | 726 | const eps = epsForType(T); |
| 659 | const eps = epsForType(T); | 727 | var four: T = 4; |
| 660 | var four: T = 4; | 728 | try expect(@log2(four) == 2); |
| 661 | try expect(@log2(four) == 2); | 729 | var six: T = 6; |
| 662 | var six: T = 6; | 730 | try expect(math.approxEqAbs(T, @log2(six), 2.5849625007212, eps)); |
| 663 | try expect(math.approxEqAbs(T, @log2(six), 2.5849625007212, eps)); | 731 | var ten: T = 10; |
| 664 | var ten: T = 10; | 732 | try expect(math.approxEqAbs(T, @log2(ten), 3.3219280948874, eps)); |
| 665 | try expect(math.approxEqAbs(T, @log2(ten), 3.3219280948874, eps)); | | |
| 666 | } | | |
| 667 | } | 733 | } |
| 668 | | 734 | |
| 669 | test "@log2 with vectors" { | 735 | test "@log2 with vectors" { |
| ... | @@ -698,8 +764,8 @@ test "@log10 f16" { | ... | @@ -698,8 +764,8 @@ test "@log10 f16" { |
| 698 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 764 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 699 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; | 765 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; |
| 700 | | 766 | |
| 701 | try testLog10(&.{f16}); | 767 | try testLog10(f16); |
| 702 | try comptime testLog10(&.{f16}); | 768 | try comptime testLog10(f16); |
| 703 | } | 769 | } |
| 704 | | 770 | |
| 705 | test "@log10 f32/f64" { | 771 | test "@log10 f32/f64" { |
| ... | @@ -709,8 +775,10 @@ test "@log10 f32/f64" { | ... | @@ -709,8 +775,10 @@ test "@log10 f32/f64" { |
| 709 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 775 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 710 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | 776 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; |
| 711 | | 777 | |
| 712 | try testLog10(&.{ f32, f64 }); | 778 | try testLog10(f32); |
| 713 | try comptime testLog10(&.{ f32, f64 }); | 779 | try comptime testLog10(f32); |
| | 780 | try testLog10(f64); |
| | 781 | try comptime testLog10(f64); |
| 714 | } | 782 | } |
| 715 | | 783 | |
| 716 | test "@log10 f80/f128/c_longdouble" { | 784 | test "@log10 f80/f128/c_longdouble" { |
| ... | @@ -720,20 +788,22 @@ test "@log10 f80/f128/c_longdouble" { | ... | @@ -720,20 +788,22 @@ test "@log10 f80/f128/c_longdouble" { |
| 720 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 788 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 721 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 789 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 722 | | 790 | |
| 723 | try testLog10(&.{ f80, f128, c_longdouble }); | 791 | try testLog10(f80); |
| 724 | try comptime testLog10(&.{ f80, f128, c_longdouble }); | 792 | try comptime testLog10(f80); |
| | 793 | try testLog10(f128); |
| | 794 | try comptime testLog10(f128); |
| | 795 | try testLog10(c_longdouble); |
| | 796 | try comptime testLog10(c_longdouble); |
| 725 | } | 797 | } |
| 726 | | 798 | |
| 727 | fn testLog10(comptime Ts: []const type) !void { | 799 | fn testLog10(comptime T: type) !void { |
| 728 | inline for (Ts) |T| { | 800 | const eps = epsForType(T); |
| 729 | const eps = epsForType(T); | 801 | var hundred: T = 100; |
| 730 | var hundred: T = 100; | 802 | try expect(@log10(hundred) == 2); |
| 731 | try expect(@log10(hundred) == 2); | 803 | var fifteen: T = 15; |
| 732 | var fifteen: T = 15; | 804 | try expect(math.approxEqAbs(T, @log10(fifteen), 1.176091259056, eps)); |
| 733 | try expect(math.approxEqAbs(T, @log10(fifteen), 1.176091259056, eps)); | 805 | var fifty: T = 50; |
| 734 | var fifty: T = 50; | 806 | try expect(math.approxEqAbs(T, @log10(fifty), 1.698970004336, eps)); |
| 735 | try expect(math.approxEqAbs(T, @log10(fifty), 1.698970004336, eps)); | | |
| 736 | } | | |
| 737 | } | 807 | } |
| 738 | | 808 | |
| 739 | test "@log10 with vectors" { | 809 | test "@log10 with vectors" { |
| ... | @@ -756,38 +826,91 @@ fn testLog10WithVectors() !void { | ... | @@ -756,38 +826,91 @@ fn testLog10WithVectors() !void { |
| 756 | try expect(@log10(@as(f32, 0.4)) == result[3]); | 826 | try expect(@log10(@as(f32, 0.4)) == result[3]); |
| 757 | } | 827 | } |
| 758 | | 828 | |
| 759 | test "@abs" { | 829 | test "@abs f16" { |
| 760 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 830 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 761 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 831 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 762 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 832 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| | 833 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; |
| 763 | | 834 | |
| 764 | try testFabs(); | 835 | try testFabs(f16); |
| 765 | try comptime testFabs(); | 836 | try comptime testFabs(f16); |
| 766 | } | 837 | } |
| 767 | | 838 | |
| 768 | fn testFabs() !void { | 839 | test "@abs f32/f64" { |
| 769 | try expect(@abs(@as(f16, -2.5)) == 2.5); | 840 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 770 | try expect(@abs(@as(f16, 2.5)) == 2.5); | 841 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 771 | try expect(@abs(@as(f32, -2.5)) == 2.5); | 842 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 772 | try expect(@abs(@as(f32, 2.5)) == 2.5); | | |
| 773 | try expect(@abs(@as(f64, -2.5)) == 2.5); | | |
| 774 | try expect(@abs(@as(f64, 2.5)) == 2.5); | | |
| 775 | | 843 | |
| 776 | // TODO test f128, and c_longdouble | 844 | try testFabs(f32); |
| 777 | // https://github.com/ziglang/zig/issues/4026 | 845 | try comptime testFabs(f32); |
| 778 | // { | 846 | try testFabs(f64); |
| 779 | // var a: f80 = -2.5; | 847 | try comptime testFabs(f64); |
| 780 | // var b: f80 = 2.5; | | |
| 781 | // try expect(@abs(a) == 2.5); | | |
| 782 | // try expect(@abs(b) == 2.5); | | |
| 783 | // } | | |
| 784 | } | 848 | } |
| 785 | | 849 | |
| 786 | test "@abs with vectors" { | 850 | test "@abs f80/f128/c_longdouble" { |
| 787 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | | |
| 788 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 851 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 789 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 852 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| | 853 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; |
| | 854 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| | 855 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| | 856 | |
| | 857 | try testFabs(f80); |
| | 858 | try comptime testFabs(f80); |
| | 859 | try testFabs(f128); |
| | 860 | try comptime testFabs(f128); |
| | 861 | try testFabs(c_longdouble); |
| | 862 | try comptime testFabs(c_longdouble); |
| | 863 | } |
| | 864 | |
| | 865 | fn testFabs(comptime T: type) !void { |
| | 866 | var two_point_five: T = 2.5; |
| | 867 | try expect(@abs(two_point_five) == 2.5); |
| | 868 | var neg_two_point_five: T = -2.5; |
| | 869 | try expect(@abs(neg_two_point_five) == 2.5); |
| | 870 | |
| | 871 | var twelve: T = 12.0; |
| | 872 | try expect(@abs(twelve) == 12.0); |
| | 873 | var neg_fourteen: T = -14.0; |
| | 874 | try expect(@abs(neg_fourteen) == 14.0); |
| | 875 | |
| | 876 | // normals |
| | 877 | var one: T = 1.0; |
| | 878 | try expect(@abs(one) == 1.0); |
| | 879 | var neg_one: T = -1.0; |
| | 880 | try expect(@abs(neg_one) == 1.0); |
| | 881 | var min: T = math.floatMin(T); |
| | 882 | try expect(@abs(min) == math.floatMin(T)); |
| | 883 | var neg_min: T = -math.floatMin(T); |
| | 884 | try expect(@abs(neg_min) == math.floatMin(T)); |
| | 885 | var max: T = math.floatMax(T); |
| | 886 | try expect(@abs(max) == math.floatMax(T)); |
| | 887 | var neg_max: T = -math.floatMax(T); |
| | 888 | try expect(@abs(neg_max) == math.floatMax(T)); |
| | 889 | |
| | 890 | // subnormals |
| | 891 | var zero: T = 0.0; |
| | 892 | try expect(@abs(zero) == 0.0); |
| | 893 | var neg_zero: T = -0.0; |
| | 894 | try expect(@abs(neg_zero) == 0.0); |
| | 895 | var true_min: T = math.floatTrueMin(T); |
| | 896 | try expect(@abs(true_min) == math.floatTrueMin(T)); |
| | 897 | var neg_true_min: T = -math.floatTrueMin(T); |
| | 898 | try expect(@abs(neg_true_min) == math.floatTrueMin(T)); |
| | 899 | |
| | 900 | // non-finite numbers |
| | 901 | var inf: T = math.inf(T); |
| | 902 | try expect(math.isPositiveInf(@abs(inf))); |
| | 903 | var neg_inf: T = -math.inf(T); |
| | 904 | try expect(math.isPositiveInf(@abs(neg_inf))); |
| | 905 | var nan: T = math.nan(T); |
| | 906 | try expect(math.isNan(@abs(nan))); |
| | 907 | } |
| | 908 | |
| | 909 | test "@abs with vectors" { |
| | 910 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| | 911 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 790 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 912 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| | 913 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 791 | | 914 | |
| 792 | try testFabsWithVectors(); | 915 | try testFabsWithVectors(); |
| 793 | try comptime testFabsWithVectors(); | 916 | try comptime testFabsWithVectors(); |
| ... | @@ -802,104 +925,72 @@ fn testFabsWithVectors() !void { | ... | @@ -802,104 +925,72 @@ fn testFabsWithVectors() !void { |
| 802 | try expect(math.approxEqAbs(f32, @abs(@as(f32, -0.4)), result[3], epsilon)); | 925 | try expect(math.approxEqAbs(f32, @abs(@as(f32, -0.4)), result[3], epsilon)); |
| 803 | } | 926 | } |
| 804 | | 927 | |
| 805 | test "another, possibly redundant, @abs test" { | 928 | test "@floor f16" { |
| 806 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | | |
| 807 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 808 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 929 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 809 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 930 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 810 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; | 931 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 811 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 932 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 812 | | 933 | |
| 813 | try testFabsLegacy(f128, 12.0); | 934 | try testFloor(f16); |
| 814 | try comptime testFabsLegacy(f128, 12.0); | 935 | try comptime testFloor(f16); |
| 815 | try testFabsLegacy(f64, 12.0); | | |
| 816 | try comptime testFabsLegacy(f64, 12.0); | | |
| 817 | try testFabsLegacy(f32, 12.0); | | |
| 818 | try comptime testFabsLegacy(f32, 12.0); | | |
| 819 | try testFabsLegacy(f16, 12.0); | | |
| 820 | try comptime testFabsLegacy(f16, 12.0); | | |
| 821 | | | |
| 822 | const x = 14.0; | | |
| 823 | const y = -x; | | |
| 824 | const z = @abs(y); | | |
| 825 | try comptime std.testing.expectEqual(x, z); | | |
| 826 | } | 936 | } |
| 827 | | 937 | |
| 828 | test "@abs f80" { | 938 | test "@floor f32/f64" { |
| 829 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | | |
| 830 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 831 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 939 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 832 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 940 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 833 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; | 941 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 834 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 942 | if (builtin.zig_backend == .stage2_x86_64 and (builtin.target.ofmt != .elf or !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sse4_1))) return error.SkipZigTest; |
| 835 | | | |
| 836 | try testFabsLegacy(f80, 12.0); | | |
| 837 | try comptime testFabsLegacy(f80, 12.0); | | |
| 838 | } | | |
| 839 | | 943 | |
| 840 | fn testFabsLegacy(comptime T: type, x: T) !void { | 944 | try testFloor(f32); |
| 841 | const y = -x; | 945 | try comptime testFloor(f32); |
| 842 | const z = @abs(y); | 946 | try testFloor(f64); |
| 843 | try expect(x == z); | 947 | try comptime testFloor(f64); |
| 844 | } | 948 | } |
| 845 | | 949 | |
| 846 | test "a third @abs test, surely there should not be three fabs tests" { | 950 | test "@floor f80/f128/c_longdouble" { |
| 847 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | | |
| 848 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 849 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 951 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 850 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 952 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 851 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; | 953 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; |
| | 954 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 852 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 955 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 853 | | 956 | |
| 854 | inline for ([_]type{ f16, f32, f64, f80, f128, c_longdouble }) |T| { | 957 | if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .windows) { |
| 855 | // normals | 958 | // https://github.com/ziglang/zig/issues/12602 |
| 856 | try expect(@abs(@as(T, 1.0)) == 1.0); | 959 | return error.SkipZigTest; |
| 857 | try expect(@abs(@as(T, -1.0)) == 1.0); | | |
| 858 | try expect(@abs(math.floatMin(T)) == math.floatMin(T)); | | |
| 859 | try expect(@abs(-math.floatMin(T)) == math.floatMin(T)); | | |
| 860 | try expect(@abs(math.floatMax(T)) == math.floatMax(T)); | | |
| 861 | try expect(@abs(-math.floatMax(T)) == math.floatMax(T)); | | |
| 862 | | | |
| 863 | // subnormals | | |
| 864 | try expect(@abs(@as(T, 0.0)) == 0.0); | | |
| 865 | try expect(@abs(@as(T, -0.0)) == 0.0); | | |
| 866 | try expect(@abs(math.floatTrueMin(T)) == math.floatTrueMin(T)); | | |
| 867 | try expect(@abs(-math.floatTrueMin(T)) == math.floatTrueMin(T)); | | |
| 868 | | | |
| 869 | // non-finite numbers | | |
| 870 | try expect(math.isPositiveInf(@abs(math.inf(T)))); | | |
| 871 | try expect(math.isPositiveInf(@abs(-math.inf(T)))); | | |
| 872 | try expect(math.isNan(@abs(math.nan(T)))); | | |
| 873 | } | 960 | } |
| 874 | } | | |
| 875 | | 961 | |
| 876 | test "@floor" { | 962 | try testFloor(f80); |
| 877 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 963 | try comptime testFloor(f80); |
| 878 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 964 | try testFloor(f128); |
| 879 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 965 | try comptime testFloor(f128); |
| 880 | | 966 | try testFloor(c_longdouble); |
| 881 | try testFloor(); | 967 | try comptime testFloor(c_longdouble); |
| 882 | try comptime testFloor(); | 968 | } |
| 883 | } | 969 | |
| 884 | | 970 | fn testFloor(comptime T: type) !void { |
| 885 | fn testFloor() !void { | 971 | var two_point_one: T = 2.1; |
| 886 | try expect(@floor(@as(f16, 2.1)) == 2); | 972 | try expect(@floor(two_point_one) == 2.0); |
| 887 | try expect(@floor(@as(f32, 2.1)) == 2); | 973 | var neg_two_point_one: T = -2.1; |
| 888 | try expect(@floor(@as(f64, 3.5)) == 3); | 974 | try expect(@floor(neg_two_point_one) == -3.0); |
| 889 | | 975 | var three_point_five: T = 3.5; |
| 890 | // TODO test f128, and c_longdouble | 976 | try expect(@floor(three_point_five) == 3.0); |
| 891 | // https://github.com/ziglang/zig/issues/4026 | 977 | var neg_three_point_five: T = -3.5; |
| 892 | // { | 978 | try expect(@floor(neg_three_point_five) == -4.0); |
| 893 | // var a: f80 = 3.5; | 979 | var twelve: T = 12.0; |
| 894 | // try expect(@floor(a) == 3); | 980 | try expect(@floor(twelve) == 12.0); |
| 895 | // } | 981 | var neg_twelve: T = -12.0; |
| | 982 | try expect(@floor(neg_twelve) == -12.0); |
| | 983 | var fourteen_point_seven: T = 14.7; |
| | 984 | try expect(@floor(fourteen_point_seven) == 14.0); |
| | 985 | var neg_fourteen_point_seven: T = -14.7; |
| | 986 | try expect(@floor(neg_fourteen_point_seven) == -15.0); |
| 896 | } | 987 | } |
| 897 | | 988 | |
| 898 | test "@floor with vectors" { | 989 | test "@floor with vectors" { |
| 899 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | | |
| 900 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 901 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 990 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| | 991 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 902 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 992 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| | 993 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 903 | if (builtin.zig_backend == .stage2_x86_64 and | 994 | if (builtin.zig_backend == .stage2_x86_64 and |
| 904 | !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sse4_1)) return error.SkipZigTest; | 995 | !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sse4_1)) return error.SkipZigTest; |
| 905 | | 996 | |
| ... | @@ -916,30 +1007,33 @@ fn testFloorWithVectors() !void { | ... | @@ -916,30 +1007,33 @@ fn testFloorWithVectors() !void { |
| 916 | try expect(math.approxEqAbs(f32, @floor(@as(f32, -0.4)), result[3], epsilon)); | 1007 | try expect(math.approxEqAbs(f32, @floor(@as(f32, -0.4)), result[3], epsilon)); |
| 917 | } | 1008 | } |
| 918 | | 1009 | |
| 919 | test "another, possibly redundant, @floor test" { | 1010 | test "@ceil f16" { |
| 920 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 921 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 1011 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 922 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 1012 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| | 1013 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 923 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 1014 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 924 | | 1015 | |
| 925 | try testFloorLegacy(f64, 12.0); | 1016 | try testCeil(f16); |
| 926 | try comptime testFloorLegacy(f64, 12.0); | 1017 | try comptime testCeil(f16); |
| 927 | try testFloorLegacy(f32, 12.0); | | |
| 928 | try comptime testFloorLegacy(f32, 12.0); | | |
| 929 | try testFloorLegacy(f16, 12.0); | | |
| 930 | try comptime testFloorLegacy(f16, 12.0); | | |
| 931 | | | |
| 932 | const x = 14.0; | | |
| 933 | const y = x + 0.7; | | |
| 934 | const z = @floor(y); | | |
| 935 | try comptime expect(x == z); | | |
| 936 | } | 1018 | } |
| 937 | | 1019 | |
| 938 | test "@floor f80" { | 1020 | test "@ceil f32/f64" { |
| | 1021 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 939 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 1022 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| | 1023 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| | 1024 | if (builtin.zig_backend == .stage2_x86_64 and (builtin.target.ofmt != .elf or !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sse4_1))) return error.SkipZigTest; |
| | 1025 | |
| | 1026 | try testCeil(f32); |
| | 1027 | try comptime testCeil(f32); |
| | 1028 | try testCeil(f64); |
| | 1029 | try comptime testCeil(f64); |
| | 1030 | } |
| | 1031 | |
| | 1032 | test "@ceil f80/f128/c_longdouble" { |
| 940 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 1033 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 941 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 1034 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 942 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; | 1035 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; |
| | 1036 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 943 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 1037 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 944 | | 1038 | |
| 945 | if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .windows) { | 1039 | if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .windows) { |
| ... | @@ -947,54 +1041,38 @@ test "@floor f80" { | ... | @@ -947,54 +1041,38 @@ test "@floor f80" { |
| 947 | return error.SkipZigTest; | 1041 | return error.SkipZigTest; |
| 948 | } | 1042 | } |
| 949 | | 1043 | |
| 950 | try testFloorLegacy(f80, 12.0); | 1044 | try testCeil(f80); |
| 951 | try comptime testFloorLegacy(f80, 12.0); | 1045 | try comptime testCeil(f80); |
| 952 | } | 1046 | try testCeil(f128); |
| 953 | | 1047 | try comptime testCeil(f128); |
| 954 | test "@floor f128" { | 1048 | try testCeil(c_longdouble); |
| 955 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 1049 | try comptime testCeil(c_longdouble); |
| 956 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 1050 | } |
| 957 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 1051 | |
| 958 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; | 1052 | fn testCeil(comptime T: type) !void { |
| 959 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 1053 | var two_point_one: T = 2.1; |
| 960 | | 1054 | try expect(@ceil(two_point_one) == 3.0); |
| 961 | try testFloorLegacy(f128, 12.0); | 1055 | var neg_two_point_one: T = -2.1; |
| 962 | try comptime testFloorLegacy(f128, 12.0); | 1056 | try expect(@ceil(neg_two_point_one) == -2.0); |
| 963 | } | 1057 | var three_point_five: T = 3.5; |
| 964 | | 1058 | try expect(@ceil(three_point_five) == 4.0); |
| 965 | fn testFloorLegacy(comptime T: type, x: T) !void { | 1059 | var neg_three_point_five: T = -3.5; |
| 966 | const y = x + 0.6; | 1060 | try expect(@ceil(neg_three_point_five) == -3.0); |
| 967 | const z = @floor(y); | 1061 | var twelve: T = 12.0; |
| 968 | try expect(x == z); | 1062 | try expect(@ceil(twelve) == 12.0); |
| 969 | } | 1063 | var neg_twelve: T = -12.0; |
| 970 | | 1064 | try expect(@ceil(neg_twelve) == -12.0); |
| 971 | test "@ceil" { | 1065 | var fourteen_point_seven: T = 14.7; |
| 972 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 1066 | try expect(@ceil(fourteen_point_seven) == 15.0); |
| 973 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 1067 | var neg_fourteen_point_seven: T = -14.7; |
| 974 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1068 | try expect(@ceil(neg_fourteen_point_seven) == -14.0); |
| 975 | | | |
| 976 | try testCeil(); | | |
| 977 | try comptime testCeil(); | | |
| 978 | } | | |
| 979 | | | |
| 980 | fn testCeil() !void { | | |
| 981 | try expect(@ceil(@as(f16, 2.1)) == 3); | | |
| 982 | try expect(@ceil(@as(f32, 2.1)) == 3); | | |
| 983 | try expect(@ceil(@as(f64, 3.5)) == 4); | | |
| 984 | | | |
| 985 | // TODO test f128, and c_longdouble | | |
| 986 | // https://github.com/ziglang/zig/issues/4026 | | |
| 987 | // { | | |
| 988 | // var a: f80 = 3.5; | | |
| 989 | // try expect(@ceil(a) == 4); | | |
| 990 | // } | | |
| 991 | } | 1069 | } |
| 992 | | 1070 | |
| 993 | test "@ceil with vectors" { | 1071 | test "@ceil with vectors" { |
| 994 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | | |
| 995 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 996 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 1072 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| | 1073 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 997 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 1074 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| | 1075 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 998 | if (builtin.zig_backend == .stage2_x86_64 and | 1076 | if (builtin.zig_backend == .stage2_x86_64 and |
| 999 | !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sse4_1)) return error.SkipZigTest; | 1077 | !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sse4_1)) return error.SkipZigTest; |
| 1000 | | 1078 | |
| ... | @@ -1011,78 +1089,75 @@ fn testCeilWithVectors() !void { | ... | @@ -1011,78 +1089,75 @@ fn testCeilWithVectors() !void { |
| 1011 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, -0.4)), result[3], epsilon)); | 1089 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, -0.4)), result[3], epsilon)); |
| 1012 | } | 1090 | } |
| 1013 | | 1091 | |
| 1014 | test "another, possibly redundant, @ceil test" { | 1092 | test "@trunc f16" { |
| 1015 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 1016 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 1093 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 1017 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | | |
| 1018 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | | |
| 1019 | | | |
| 1020 | try testCeilLegacy(f64, 12.0); | | |
| 1021 | try comptime testCeilLegacy(f64, 12.0); | | |
| 1022 | try testCeilLegacy(f32, 12.0); | | |
| 1023 | try comptime testCeilLegacy(f32, 12.0); | | |
| 1024 | try testCeilLegacy(f16, 12.0); | | |
| 1025 | try comptime testCeilLegacy(f16, 12.0); | | |
| 1026 | | | |
| 1027 | const x = 14.0; | | |
| 1028 | const y = x - 0.7; | | |
| 1029 | const z = @ceil(y); | | |
| 1030 | try comptime expect(x == z); | | |
| 1031 | } | | |
| 1032 | | | |
| 1033 | test "@ceil f80" { | | |
| 1034 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 1094 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 1035 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 1095 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1036 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | | |
| 1037 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; | | |
| 1038 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 1096 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 1039 | | 1097 | |
| 1040 | if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .windows) { | 1098 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isMIPS()) { |
| 1041 | // https://github.com/ziglang/zig/issues/12602 | 1099 | // https://github.com/ziglang/zig/issues/16846 |
| 1042 | return error.SkipZigTest; | 1100 | return error.SkipZigTest; |
| 1043 | } | 1101 | } |
| 1044 | | 1102 | |
| 1045 | try testCeilLegacy(f80, 12.0); | 1103 | try testTrunc(f16); |
| 1046 | try comptime testCeilLegacy(f80, 12.0); | 1104 | try comptime testTrunc(f16); |
| 1047 | } | 1105 | } |
| 1048 | | 1106 | |
| 1049 | test "@ceil f128" { | 1107 | test "@trunc f32/f64" { |
| 1050 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 1051 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 1108 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 1052 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 1109 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 1053 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; | 1110 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1054 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 1111 | if (builtin.zig_backend == .stage2_x86_64 and (builtin.target.ofmt != .elf or !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sse4_1))) return error.SkipZigTest; |
| 1055 | | 1112 | |
| 1056 | try testCeilLegacy(f128, 12.0); | 1113 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isMIPS()) { |
| 1057 | try comptime testCeilLegacy(f128, 12.0); | 1114 | // https://github.com/ziglang/zig/issues/16846 |
| 1058 | } | 1115 | return error.SkipZigTest; |
| | 1116 | } |
| 1059 | | 1117 | |
| 1060 | fn testCeilLegacy(comptime T: type, x: T) !void { | 1118 | try testTrunc(f32); |
| 1061 | const y = x - 0.8; | 1119 | try comptime testTrunc(f32); |
| 1062 | const z = @ceil(y); | 1120 | try testTrunc(f64); |
| 1063 | try expect(x == z); | 1121 | try comptime testTrunc(f64); |
| 1064 | } | 1122 | } |
| 1065 | | 1123 | |
| 1066 | test "@trunc" { | 1124 | test "@trunc f80/f128/c_longdouble" { |
| 1067 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 1068 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 1125 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| | 1126 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| | 1127 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; |
| 1069 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1128 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| | 1129 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 1070 | | 1130 | |
| 1071 | try testTrunc(); | 1131 | if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .windows) { |
| 1072 | try comptime testTrunc(); | 1132 | // https://github.com/ziglang/zig/issues/12602 |
| 1073 | } | 1133 | return error.SkipZigTest; |
| 1074 | | 1134 | } |
| 1075 | fn testTrunc() !void { | | |
| 1076 | try expect(@trunc(@as(f16, 2.1)) == 2); | | |
| 1077 | try expect(@trunc(@as(f32, 2.1)) == 2); | | |
| 1078 | try expect(@trunc(@as(f64, -3.5)) == -3); | | |
| 1079 | | 1135 | |
| 1080 | // TODO test f128, and c_longdouble | 1136 | try testTrunc(f80); |
| 1081 | // https://github.com/ziglang/zig/issues/4026 | 1137 | try comptime testTrunc(f80); |
| 1082 | // { | 1138 | try testTrunc(f128); |
| 1083 | // var a: f80 = -3.5; | 1139 | try comptime testTrunc(f128); |
| 1084 | // try expect(@trunc(a) == -3); | 1140 | try testTrunc(c_longdouble); |
| 1085 | // } | 1141 | try comptime testTrunc(c_longdouble); |
| | 1142 | } |
| | 1143 | |
| | 1144 | fn testTrunc(comptime T: type) !void { |
| | 1145 | var two_point_one: T = 2.1; |
| | 1146 | try expect(@trunc(two_point_one) == 2.0); |
| | 1147 | var neg_two_point_one: T = -2.1; |
| | 1148 | try expect(@trunc(neg_two_point_one) == -2.0); |
| | 1149 | var three_point_five: T = 3.5; |
| | 1150 | try expect(@trunc(three_point_five) == 3.0); |
| | 1151 | var neg_three_point_five: T = -3.5; |
| | 1152 | try expect(@trunc(neg_three_point_five) == -3.0); |
| | 1153 | var twelve: T = 12.0; |
| | 1154 | try expect(@trunc(twelve) == 12.0); |
| | 1155 | var neg_twelve: T = -12.0; |
| | 1156 | try expect(@trunc(neg_twelve) == -12.0); |
| | 1157 | var fourteen_point_seven: T = 14.7; |
| | 1158 | try expect(@trunc(fourteen_point_seven) == 14.0); |
| | 1159 | var neg_fourteen_point_seven: T = -14.7; |
| | 1160 | try expect(@trunc(neg_fourteen_point_seven) == -14.0); |
| 1086 | } | 1161 | } |
| 1087 | | 1162 | |
| 1088 | test "@trunc with vectors" { | 1163 | test "@trunc with vectors" { |
| ... | @@ -1106,82 +1181,12 @@ fn testTruncWithVectors() !void { | ... | @@ -1106,82 +1181,12 @@ fn testTruncWithVectors() !void { |
| 1106 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, -0.4)), result[3], epsilon)); | 1181 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, -0.4)), result[3], epsilon)); |
| 1107 | } | 1182 | } |
| 1108 | | 1183 | |
| 1109 | test "another, possibly redundant, @trunc test" { | 1184 | test "neg f16" { |
| 1110 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 1111 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 1185 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 1112 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | | |
| 1113 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | | |
| 1114 | | | |
| 1115 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isMIPS()) { | | |
| 1116 | // https://github.com/ziglang/zig/issues/16846 | | |
| 1117 | return error.SkipZigTest; | | |
| 1118 | } | | |
| 1119 | | | |
| 1120 | try testTruncLegacy(f64, 12.0); | | |
| 1121 | try comptime testTruncLegacy(f64, 12.0); | | |
| 1122 | try testTruncLegacy(f32, 12.0); | | |
| 1123 | try comptime testTruncLegacy(f32, 12.0); | | |
| 1124 | try testTruncLegacy(f16, 12.0); | | |
| 1125 | try comptime testTruncLegacy(f16, 12.0); | | |
| 1126 | | | |
| 1127 | const x = 14.0; | | |
| 1128 | const y = x + 0.7; | | |
| 1129 | const z = @trunc(y); | | |
| 1130 | try comptime expect(x == z); | | |
| 1131 | } | | |
| 1132 | | | |
| 1133 | test "@trunc f80" { | | |
| 1134 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 1186 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 1135 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | | |
| 1136 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | | |
| 1137 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; | | |
| 1138 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | | |
| 1139 | | | |
| 1140 | if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .windows) { | | |
| 1141 | // https://github.com/ziglang/zig/issues/12602 | | |
| 1142 | return error.SkipZigTest; | | |
| 1143 | } | | |
| 1144 | | | |
| 1145 | try testTruncLegacy(f80, 12.0); | | |
| 1146 | try comptime testTruncLegacy(f80, 12.0); | | |
| 1147 | comptime { | | |
| 1148 | const x: f80 = 12.0; | | |
| 1149 | const y = x + 0.8; | | |
| 1150 | const z = @trunc(y); | | |
| 1151 | try expect(x == z); | | |
| 1152 | } | | |
| 1153 | } | | |
| 1154 | | | |
| 1155 | test "@trunc f128" { | | |
| 1156 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 1157 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | | |
| 1158 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | | |
| 1159 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest; | | |
| 1160 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | | |
| 1161 | | | |
| 1162 | try testTruncLegacy(f128, 12.0); | | |
| 1163 | try comptime testTruncLegacy(f128, 12.0); | | |
| 1164 | } | | |
| 1165 | | | |
| 1166 | fn testTruncLegacy(comptime T: type, x: T) !void { | | |
| 1167 | { | | |
| 1168 | const y = x + 0.8; | | |
| 1169 | const z = @trunc(y); | | |
| 1170 | try expect(x == z); | | |
| 1171 | } | | |
| 1172 | | | |
| 1173 | { | | |
| 1174 | const y = -x - 0.8; | | |
| 1175 | const z = @trunc(y); | | |
| 1176 | try expect(-x == z); | | |
| 1177 | } | | |
| 1178 | } | | |
| 1179 | | | |
| 1180 | test "negation f16" { | | |
| 1181 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 1182 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | | |
| 1183 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1187 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1184 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 1188 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| | 1189 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 1185 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; | 1190 | if (no_x86_64_hardware_f16_support) return error.SkipZigTest; |
| 1186 | | 1191 | |
| 1187 | if (builtin.os.tag == .freebsd) { | 1192 | if (builtin.os.tag == .freebsd) { |
| ... | @@ -1189,100 +1194,85 @@ test "negation f16" { | ... | @@ -1189,100 +1194,85 @@ test "negation f16" { |
| 1189 | return error.SkipZigTest; | 1194 | return error.SkipZigTest; |
| 1190 | } | 1195 | } |
| 1191 | | 1196 | |
| 1192 | const S = struct { | 1197 | try testNeg(f16); |
| 1193 | fn doTheTest() !void { | 1198 | try comptime testNeg(f16); |
| 1194 | var a: f16 = 1; | | |
| 1195 | a = -a; | | |
| 1196 | try expect(a == -1); | | |
| 1197 | a = -a; | | |
| 1198 | try expect(a == 1); | | |
| 1199 | } | | |
| 1200 | }; | | |
| 1201 | | | |
| 1202 | try S.doTheTest(); | | |
| 1203 | try comptime S.doTheTest(); | | |
| 1204 | } | 1199 | } |
| 1205 | | 1200 | |
| 1206 | test "negation f32" { | 1201 | test "neg f32/f64" { |
| 1207 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 1208 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 1202 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 1209 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | | |
| 1210 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | | |
| 1211 | | | |
| 1212 | const S = struct { | | |
| 1213 | fn doTheTest() !void { | | |
| 1214 | var a: f32 = 1; | | |
| 1215 | a = -a; | | |
| 1216 | try expect(a == -1); | | |
| 1217 | a = -a; | | |
| 1218 | try expect(a == 1); | | |
| 1219 | } | | |
| 1220 | }; | | |
| 1221 | | | |
| 1222 | try S.doTheTest(); | | |
| 1223 | try comptime S.doTheTest(); | | |
| 1224 | } | | |
| 1225 | | | |
| 1226 | test "negation f64" { | | |
| 1227 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 1203 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 1228 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | | |
| 1229 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1204 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1230 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 1205 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| | 1206 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 1231 | | 1207 | |
| 1232 | const S = struct { | 1208 | try testNeg(f32); |
| 1233 | fn doTheTest() !void { | 1209 | try comptime testNeg(f32); |
| 1234 | var a: f64 = 1; | 1210 | try testNeg(f64); |
| 1235 | a = -a; | 1211 | try comptime testNeg(f64); |
| 1236 | try expect(a == -1); | | |
| 1237 | a = -a; | | |
| 1238 | try expect(a == 1); | | |
| 1239 | } | | |
| 1240 | }; | | |
| 1241 | | | |
| 1242 | try S.doTheTest(); | | |
| 1243 | try comptime S.doTheTest(); | | |
| 1244 | } | 1212 | } |
| 1245 | | 1213 | |
| 1246 | test "negation f80" { | 1214 | test "neg f80/f128/c_longdouble" { |
| 1247 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 1248 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 1215 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 1249 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | | |
| 1250 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | | |
| 1251 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | | |
| 1252 | | | |
| 1253 | const S = struct { | | |
| 1254 | fn doTheTest() !void { | | |
| 1255 | var a: f80 = 1; | | |
| 1256 | a = -a; | | |
| 1257 | try expect(a == -1); | | |
| 1258 | a = -a; | | |
| 1259 | try expect(a == 1); | | |
| 1260 | } | | |
| 1261 | }; | | |
| 1262 | | | |
| 1263 | try S.doTheTest(); | | |
| 1264 | try comptime S.doTheTest(); | | |
| 1265 | } | | |
| 1266 | | | |
| 1267 | test "negation f128" { | | |
| 1268 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 1216 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 1269 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | | |
| 1270 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1217 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1271 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 1218 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| | 1219 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 1272 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 1220 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 1273 | | 1221 | |
| 1274 | const S = struct { | 1222 | try testNeg(f80); |
| 1275 | fn doTheTest() !void { | 1223 | try comptime testNeg(f80); |
| 1276 | var a: f128 = 1; | 1224 | try testNeg(f128); |
| 1277 | a = -a; | 1225 | try comptime testNeg(f128); |
| 1278 | try expect(a == -1); | 1226 | try testNeg(c_longdouble); |
| 1279 | a = -a; | 1227 | try comptime testNeg(c_longdouble); |
| 1280 | try expect(a == 1); | 1228 | } |
| 1281 | } | 1229 | |
| 1282 | }; | 1230 | fn testNeg(comptime T: type) !void { |
| 1283 | | 1231 | var two_point_five: T = 2.5; |
| 1284 | try S.doTheTest(); | 1232 | try expect(-two_point_five == -2.5); |
| 1285 | try comptime S.doTheTest(); | 1233 | var neg_two_point_five: T = -2.5; |
| | 1234 | try expect(-neg_two_point_five == 2.5); |
| | 1235 | |
| | 1236 | var twelve: T = 12.0; |
| | 1237 | try expect(-twelve == -12.0); |
| | 1238 | var neg_fourteen: T = -14.0; |
| | 1239 | try expect(-neg_fourteen == 14.0); |
| | 1240 | |
| | 1241 | // normals |
| | 1242 | var one: T = 1.0; |
| | 1243 | try expect(-one == -1.0); |
| | 1244 | var neg_one: T = -1.0; |
| | 1245 | try expect(-neg_one == 1.0); |
| | 1246 | var min: T = math.floatMin(T); |
| | 1247 | try expect(-min == -math.floatMin(T)); |
| | 1248 | var neg_min: T = -math.floatMin(T); |
| | 1249 | try expect(-neg_min == math.floatMin(T)); |
| | 1250 | var max: T = math.floatMax(T); |
| | 1251 | try expect(-max == -math.floatMax(T)); |
| | 1252 | var neg_max: T = -math.floatMax(T); |
| | 1253 | try expect(-neg_max == math.floatMax(T)); |
| | 1254 | |
| | 1255 | // subnormals |
| | 1256 | var zero: T = 0.0; |
| | 1257 | try expect(-zero == -0.0); |
| | 1258 | var neg_zero: T = -0.0; |
| | 1259 | try expect(-neg_zero == 0.0); |
| | 1260 | var true_min: T = math.floatTrueMin(T); |
| | 1261 | try expect(-true_min == -math.floatTrueMin(T)); |
| | 1262 | var neg_true_min: T = -math.floatTrueMin(T); |
| | 1263 | try expect(-neg_true_min == math.floatTrueMin(T)); |
| | 1264 | |
| | 1265 | // non-finite numbers |
| | 1266 | var inf: T = math.inf(T); |
| | 1267 | try expect(math.isNegativeInf(-inf)); |
| | 1268 | var neg_inf: T = -math.inf(T); |
| | 1269 | try expect(math.isPositiveInf(-neg_inf)); |
| | 1270 | var nan: T = math.nan(T); |
| | 1271 | try expect(math.isNan(-nan)); |
| | 1272 | try expect(math.signbit(-nan)); |
| | 1273 | var neg_nan: T = -math.nan(T); |
| | 1274 | try expect(math.isNan(-neg_nan)); |
| | 1275 | try expect(!math.signbit(-neg_nan)); |
| 1286 | } | 1276 | } |
| 1287 | | 1277 | |
| 1288 | test "eval @setFloatMode at compile-time" { | 1278 | test "eval @setFloatMode at compile-time" { |
| ... | @@ -1337,99 +1327,3 @@ test "comptime fixed-width float non-zero divided by zero produces signed Inf" { | ... | @@ -1337,99 +1327,3 @@ test "comptime fixed-width float non-zero divided by zero produces signed Inf" { |
| 1337 | test "comptime_float zero divided by zero produces zero" { | 1327 | test "comptime_float zero divided by zero produces zero" { |
| 1338 | try expect((0.0 / 0.0) == 0.0); | 1328 | try expect((0.0 / 0.0) == 0.0); |
| 1339 | } | 1329 | } |
| 1340 | | | |
| 1341 | test "nan negation f16" { | | |
| 1342 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | | |
| 1343 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 1344 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | | |
| 1345 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | | |
| 1346 | | | |
| 1347 | const nan_comptime = comptime math.nan(f16); | | |
| 1348 | const neg_nan_comptime = -nan_comptime; | | |
| 1349 | | | |
| 1350 | var nan_runtime = math.nan(f16); | | |
| 1351 | const neg_nan_runtime = -nan_runtime; | | |
| 1352 | | | |
| 1353 | try expect(!math.signbit(nan_runtime)); | | |
| 1354 | try expect(math.signbit(neg_nan_runtime)); | | |
| 1355 | | | |
| 1356 | try expect(!math.signbit(nan_comptime)); | | |
| 1357 | try expect(math.signbit(neg_nan_comptime)); | | |
| 1358 | } | | |
| 1359 | | | |
| 1360 | test "nan negation f32" { | | |
| 1361 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | | |
| 1362 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 1363 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | | |
| 1364 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | | |
| 1365 | | | |
| 1366 | const nan_comptime = comptime math.nan(f32); | | |
| 1367 | const neg_nan_comptime = -nan_comptime; | | |
| 1368 | | | |
| 1369 | var nan_runtime = math.nan(f32); | | |
| 1370 | const neg_nan_runtime = -nan_runtime; | | |
| 1371 | | | |
| 1372 | try expect(!math.signbit(nan_runtime)); | | |
| 1373 | try expect(math.signbit(neg_nan_runtime)); | | |
| 1374 | | | |
| 1375 | try expect(!math.signbit(nan_comptime)); | | |
| 1376 | try expect(math.signbit(neg_nan_comptime)); | | |
| 1377 | } | | |
| 1378 | | | |
| 1379 | test "nan negation f64" { | | |
| 1380 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | | |
| 1381 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 1382 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | | |
| 1383 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | | |
| 1384 | | | |
| 1385 | const nan_comptime = comptime math.nan(f64); | | |
| 1386 | const neg_nan_comptime = -nan_comptime; | | |
| 1387 | | | |
| 1388 | var nan_runtime = math.nan(f64); | | |
| 1389 | const neg_nan_runtime = -nan_runtime; | | |
| 1390 | | | |
| 1391 | try expect(!math.signbit(nan_runtime)); | | |
| 1392 | try expect(math.signbit(neg_nan_runtime)); | | |
| 1393 | | | |
| 1394 | try expect(!math.signbit(nan_comptime)); | | |
| 1395 | try expect(math.signbit(neg_nan_comptime)); | | |
| 1396 | } | | |
| 1397 | | | |
| 1398 | test "nan negation f128" { | | |
| 1399 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | | |
| 1400 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 1401 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | | |
| 1402 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | | |
| 1403 | | | |
| 1404 | const nan_comptime = comptime math.nan(f128); | | |
| 1405 | const neg_nan_comptime = -nan_comptime; | | |
| 1406 | | | |
| 1407 | var nan_runtime = math.nan(f128); | | |
| 1408 | const neg_nan_runtime = -nan_runtime; | | |
| 1409 | | | |
| 1410 | try expect(!math.signbit(nan_runtime)); | | |
| 1411 | try expect(math.signbit(neg_nan_runtime)); | | |
| 1412 | | | |
| 1413 | try expect(!math.signbit(nan_comptime)); | | |
| 1414 | try expect(math.signbit(neg_nan_comptime)); | | |
| 1415 | } | | |
| 1416 | | | |
| 1417 | test "nan negation f80" { | | |
| 1418 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | | |
| 1419 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | | |
| 1420 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | | |
| 1421 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | | |
| 1422 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | | |
| 1423 | | | |
| 1424 | const nan_comptime = comptime math.nan(f80); | | |
| 1425 | const neg_nan_comptime = -nan_comptime; | | |
| 1426 | | | |
| 1427 | var nan_runtime = math.nan(f80); | | |
| 1428 | const neg_nan_runtime = -nan_runtime; | | |
| 1429 | | | |
| 1430 | try expect(!math.signbit(nan_runtime)); | | |
| 1431 | try expect(math.signbit(neg_nan_runtime)); | | |
| 1432 | | | |
| 1433 | try expect(!math.signbit(nan_comptime)); | | |
| 1434 | try expect(math.signbit(neg_nan_comptime)); | | |
| 1435 | } | | |