| ... | ... | @@ -366,7 +366,7 @@ pub fn min(x: anytype, y: anytype) Min(@TypeOf(x), @TypeOf(y)) { |
| 366 | 366 | } |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | | test "math.min" { |
| 369 | test "min" { |
| 370 | 370 | try testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1); |
| 371 | 371 | { |
| 372 | 372 | var a: u16 = 999; |
| ... | ... | @@ -403,7 +403,7 @@ pub fn min3(x: anytype, y: anytype, z: anytype) @TypeOf(x, y, z) { |
| 403 | 403 | return min(x, min(y, z)); |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | | test "math.min3" { |
| 406 | test "min3" { |
| 407 | 407 | try testing.expect(min3(@as(i32, 0), @as(i32, 1), @as(i32, 2)) == 0); |
| 408 | 408 | try testing.expect(min3(@as(i32, 0), @as(i32, 2), @as(i32, 1)) == 0); |
| 409 | 409 | try testing.expect(min3(@as(i32, 1), @as(i32, 0), @as(i32, 2)) == 0); |
| ... | ... | @@ -418,7 +418,7 @@ pub fn max(x: anytype, y: anytype) @TypeOf(x, y) { |
| 418 | 418 | return if (x > y) x else y; |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | | test "math.max" { |
| 421 | test "max" { |
| 422 | 422 | try testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2); |
| 423 | 423 | try testing.expect(max(@as(i32, 2), @as(i32, -1)) == 2); |
| 424 | 424 | } |
| ... | ... | @@ -428,7 +428,7 @@ pub fn max3(x: anytype, y: anytype, z: anytype) @TypeOf(x, y, z) { |
| 428 | 428 | return max(x, max(y, z)); |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | | test "math.max3" { |
| 431 | test "max3" { |
| 432 | 432 | try testing.expect(max3(@as(i32, 0), @as(i32, 1), @as(i32, 2)) == 2); |
| 433 | 433 | try testing.expect(max3(@as(i32, 0), @as(i32, 2), @as(i32, 1)) == 2); |
| 434 | 434 | try testing.expect(max3(@as(i32, 1), @as(i32, 0), @as(i32, 2)) == 2); |
| ... | ... | @@ -442,7 +442,7 @@ pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, u |
| 442 | 442 | assert(lower <= upper); |
| 443 | 443 | return max(lower, min(val, upper)); |
| 444 | 444 | } |
| 445 | | test "math.clamp" { |
| 445 | test "clamp" { |
| 446 | 446 | // Within range |
| 447 | 447 | try testing.expect(std.math.clamp(@as(i32, -1), @as(i32, -4), @as(i32, 7)) == -1); |
| 448 | 448 | // Below |
| ... | ... | @@ -515,7 +515,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T { |
| 515 | 515 | return a << casted_shift_amt; |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | | test "math.shl" { |
| 518 | test "shl" { |
| 519 | 519 | try testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000); |
| 520 | 520 | try testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0); |
| 521 | 521 | try testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0); |
| ... | ... | @@ -555,7 +555,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T { |
| 555 | 555 | return a >> casted_shift_amt; |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | | test "math.shr" { |
| 558 | test "shr" { |
| 559 | 559 | try testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111); |
| 560 | 560 | try testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0); |
| 561 | 561 | try testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0); |
| ... | ... | @@ -587,7 +587,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T { |
| 587 | 587 | } |
| 588 | 588 | } |
| 589 | 589 | |
| 590 | | test "math.rotr" { |
| 590 | test "rotr" { |
| 591 | 591 | try testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001); |
| 592 | 592 | try testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000); |
| 593 | 593 | try testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001); |
| ... | ... | @@ -615,7 +615,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T { |
| 615 | 615 | } |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | | test "math.rotl" { |
| 618 | test "rotl" { |
| 619 | 619 | try testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001); |
| 620 | 620 | try testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010); |
| 621 | 621 | try testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001); |
| ... | ... | @@ -667,7 +667,7 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t |
| 667 | 667 | return std.meta.Int(sign, magnitude_bits); |
| 668 | 668 | } |
| 669 | 669 | |
| 670 | | test "math.IntFittingRange" { |
| 670 | test "IntFittingRange" { |
| 671 | 671 | try testing.expect(IntFittingRange(0, 0) == u0); |
| 672 | 672 | try testing.expect(IntFittingRange(0, 1) == u1); |
| 673 | 673 | try testing.expect(IntFittingRange(0, 2) == u2); |
| ... | ... | @@ -714,7 +714,7 @@ test "math.IntFittingRange" { |
| 714 | 714 | try testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178); |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | | test "math overflow functions" { |
| 717 | test "overflow functions" { |
| 718 | 718 | try testOverflow(); |
| 719 | 719 | comptime try testOverflow(); |
| 720 | 720 | } |
| ... | ... | @@ -741,7 +741,7 @@ pub fn absInt(x: anytype) !@TypeOf(x) { |
| 741 | 741 | } |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | | test "math.absInt" { |
| 744 | test "absInt" { |
| 745 | 745 | try testAbsInt(); |
| 746 | 746 | comptime try testAbsInt(); |
| 747 | 747 | } |
| ... | ... | @@ -752,7 +752,7 @@ fn testAbsInt() !void { |
| 752 | 752 | |
| 753 | 753 | pub const absFloat = fabs; |
| 754 | 754 | |
| 755 | | test "math.absFloat" { |
| 755 | test "absFloat" { |
| 756 | 756 | try testAbsFloat(); |
| 757 | 757 | comptime try testAbsFloat(); |
| 758 | 758 | } |
| ... | ... | @@ -770,7 +770,7 @@ pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T { |
| 770 | 770 | return @divTrunc(numerator, denominator); |
| 771 | 771 | } |
| 772 | 772 | |
| 773 | | test "math.divTrunc" { |
| 773 | test "divTrunc" { |
| 774 | 774 | try testDivTrunc(); |
| 775 | 775 | comptime try testDivTrunc(); |
| 776 | 776 | } |
| ... | ... | @@ -794,7 +794,7 @@ pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T { |
| 794 | 794 | return @divFloor(numerator, denominator); |
| 795 | 795 | } |
| 796 | 796 | |
| 797 | | test "math.divFloor" { |
| 797 | test "divFloor" { |
| 798 | 798 | try testDivFloor(); |
| 799 | 799 | comptime try testDivFloor(); |
| 800 | 800 | } |
| ... | ... | @@ -831,7 +831,7 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T { |
| 831 | 831 | } |
| 832 | 832 | } |
| 833 | 833 | |
| 834 | | test "math.divCeil" { |
| 834 | test "divCeil" { |
| 835 | 835 | try testDivCeil(); |
| 836 | 836 | comptime try testDivCeil(); |
| 837 | 837 | } |
| ... | ... | @@ -875,7 +875,7 @@ pub fn divExact(comptime T: type, numerator: T, denominator: T) !T { |
| 875 | 875 | return result; |
| 876 | 876 | } |
| 877 | 877 | |
| 878 | | test "math.divExact" { |
| 878 | test "divExact" { |
| 879 | 879 | try testDivExact(); |
| 880 | 880 | comptime try testDivExact(); |
| 881 | 881 | } |
| ... | ... | @@ -901,7 +901,7 @@ pub fn mod(comptime T: type, numerator: T, denominator: T) !T { |
| 901 | 901 | return @mod(numerator, denominator); |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | | test "math.mod" { |
| 904 | test "mod" { |
| 905 | 905 | try testMod(); |
| 906 | 906 | comptime try testMod(); |
| 907 | 907 | } |
| ... | ... | @@ -927,7 +927,7 @@ pub fn rem(comptime T: type, numerator: T, denominator: T) !T { |
| 927 | 927 | return @rem(numerator, denominator); |
| 928 | 928 | } |
| 929 | 929 | |
| 930 | | test "math.rem" { |
| 930 | test "rem" { |
| 931 | 931 | try testRem(); |
| 932 | 932 | comptime try testRem(); |
| 933 | 933 | } |
| ... | ... | @@ -971,7 +971,7 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) { |
| 971 | 971 | } |
| 972 | 972 | } |
| 973 | 973 | |
| 974 | | test "math.absCast" { |
| 974 | test "absCast" { |
| 975 | 975 | try testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1))); |
| 976 | 976 | try testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999))); |
| 977 | 977 | try testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999))); |
| ... | ... | @@ -992,7 +992,7 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x |
| 992 | 992 | return -@intCast(int, x); |
| 993 | 993 | } |
| 994 | 994 | |
| 995 | | test "math.negateCast" { |
| 995 | test "negateCast" { |
| 996 | 996 | try testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999); |
| 997 | 997 | try testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32); |
| 998 | 998 | |
| ... | ... | @@ -1017,7 +1017,7 @@ pub fn cast(comptime T: type, x: anytype) (error{Overflow}!T) { |
| 1017 | 1017 | } |
| 1018 | 1018 | } |
| 1019 | 1019 | |
| 1020 | | test "math.cast" { |
| 1020 | test "cast" { |
| 1021 | 1021 | try testing.expectError(error.Overflow, cast(u8, @as(u32, 300))); |
| 1022 | 1022 | try testing.expectError(error.Overflow, cast(i8, @as(i32, -200))); |
| 1023 | 1023 | try testing.expectError(error.Overflow, cast(u8, @as(i8, -1))); |
| ... | ... | @@ -1051,7 +1051,7 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T { |
| 1051 | 1051 | return @as(T, 1) << log2_int(uT, @intCast(uT, value)); |
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | | test "math.floorPowerOfTwo" { |
| 1054 | test "floorPowerOfTwo" { |
| 1055 | 1055 | try testFloorPowerOfTwo(); |
| 1056 | 1056 | comptime try testFloorPowerOfTwo(); |
| 1057 | 1057 | } |
| ... | ... | @@ -1106,7 +1106,7 @@ pub fn ceilPowerOfTwoAssert(comptime T: type, value: T) T { |
| 1106 | 1106 | return ceilPowerOfTwo(T, value) catch unreachable; |
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | | test "math.ceilPowerOfTwoPromote" { |
| 1109 | test "ceilPowerOfTwoPromote" { |
| 1110 | 1110 | try testCeilPowerOfTwoPromote(); |
| 1111 | 1111 | comptime try testCeilPowerOfTwoPromote(); |
| 1112 | 1112 | } |
| ... | ... | @@ -1123,7 +1123,7 @@ fn testCeilPowerOfTwoPromote() !void { |
| 1123 | 1123 | try testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9)); |
| 1124 | 1124 | } |
| 1125 | 1125 | |
| 1126 | | test "math.ceilPowerOfTwo" { |
| 1126 | test "ceilPowerOfTwo" { |
| 1127 | 1127 | try testCeilPowerOfTwo(); |
| 1128 | 1128 | comptime try testCeilPowerOfTwo(); |
| 1129 | 1129 | } |
| ... | ... | @@ -1214,13 +1214,13 @@ pub fn lossyCast(comptime T: type, value: anytype) T { |
| 1214 | 1214 | } |
| 1215 | 1215 | } |
| 1216 | 1216 | |
| 1217 | | test "math.lossyCast" { |
| 1217 | test "lossyCast" { |
| 1218 | 1218 | try testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767)); |
| 1219 | 1219 | try testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0)); |
| 1220 | 1220 | try testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200)); |
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | | test "math.f64_min" { |
| 1223 | test "f64_min" { |
| 1224 | 1224 | const f64_min_u64 = 0x0010000000000000; |
| 1225 | 1225 | const fmin: f64 = f64_min; |
| 1226 | 1226 | try testing.expect(@bitCast(u64, fmin) == f64_min_u64); |
| ... | ... | @@ -1298,7 +1298,7 @@ pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int( |
| 1298 | 1298 | return @as(ResultInt, a) * @as(ResultInt, b); |
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 1301 | | test "math.mulWide" { |
| 1301 | test "mulWide" { |
| 1302 | 1302 | try testing.expect(mulWide(u8, 5, 5) == 25); |
| 1303 | 1303 | try testing.expect(mulWide(i8, 5, -5) == -25); |
| 1304 | 1304 | try testing.expect(mulWide(u8, 100, 100) == 10000); |
| ... | ... | @@ -1439,7 +1439,7 @@ test "order.compare" { |
| 1439 | 1439 | try testing.expect(order(1, 0).compare(.neq)); |
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | | test "math.comptime" { |
| 1442 | test "comptime sin and ln" { |
| 1443 | 1443 | const v = comptime (sin(@as(f32, 1)) + ln(@as(f32, 5))); |
| 1444 | 1444 | try testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5))); |
| 1445 | 1445 | } |