Skip to content

Commit fb756ae

Browse files
committed
fix: omit comptime T: type
1 parent 591b47b commit fb756ae

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/std/math.zig

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,26 +1317,28 @@ test "lossyCast" {
13171317
///
13181318
/// This does not guarantee returning *b* if *t* is 1 due to floating-point errors.
13191319
/// This is monotonic.
1320-
pub fn lerp(comptime T: type, a: T, b: T, t: T) T {
1321-
if (@typeInfo(T) != .Float and @typeInfo(T) != .ComptimeFloat)
1320+
pub fn lerp(a: anytype, b: anytype, t: anytype) @TypeOf(a, b, t) {
1321+
const T = @TypeOf(a, b, t);
1322+
1323+
comptime if (!std.meta.trait.isFloat(T))
13221324
@compileError("T must be a float type");
13231325

13241326
assert(t >= 0 and t <= 1);
13251327
return @mulAdd(T, b - a, t, a);
13261328
}
13271329

13281330
test "lerp" {
1329-
try testing.expectEqual(@as(f64, 75), lerp(f64, 50, 100, 0.5));
1330-
try testing.expectEqual(@as(f32, 43.75), lerp(f32, 50, 25, 0.25));
1331-
try testing.expectEqual(@as(f64, -31.25), lerp(f64, -50, 25, 0.25));
1331+
try testing.expectEqual(@as(f64, 75), lerp(50, 100, 0.5));
1332+
try testing.expectEqual(@as(f32, 43.75), lerp(50, 25, 0.25));
1333+
try testing.expectEqual(@as(f64, -31.25), lerp(-50, 25, 0.25));
13321334

1333-
try testing.expectApproxEqRel(@as(f32, -7.16067345e+03), lerp(f32, -10000.12345, -5000.12345, 0.56789), 1e-19);
1334-
try testing.expectApproxEqRel(@as(f64, 7.010987590521e+62), lerp(f64, 0.123456789e-64, 0.123456789e64, 0.56789), 1e-33);
1335+
try testing.expectApproxEqRel(@as(f32, -7.16067345e+03), lerp(-10000.12345, -5000.12345, 0.56789), 1e-19);
1336+
try testing.expectApproxEqRel(@as(f64, 7.010987590521e+62), lerp(0.123456789e-64, 0.123456789e64, 0.56789), 1e-33);
13351337

1336-
try testing.expectEqual(@as(f32, 0.0), lerp(f32, 1.0e8, 1.0, 1.0));
1337-
try testing.expectEqual(@as(f64, 0.0), lerp(f64, 1.0e16, 1.0, 1.0));
1338-
try testing.expectEqual(@as(f32, 1.0), lerp(f32, 1.0e7, 1.0, 1.0));
1339-
try testing.expectEqual(@as(f64, 1.0), lerp(f64, 1.0e15, 1.0, 1.0));
1338+
try testing.expectEqual(@as(f32, 0.0), lerp(@as(f32, 1.0e8), 1.0, 1.0));
1339+
try testing.expectEqual(@as(f64, 0.0), lerp(@as(f64, 1.0e16), 1.0, 1.0));
1340+
try testing.expectEqual(@as(f32, 1.0), lerp(@as(f32, 1.0e7), 1.0, 1.0));
1341+
try testing.expectEqual(@as(f64, 1.0), lerp(@as(f64, 1.0e15), 1.0, 1.0));
13401342
}
13411343

13421344
/// Returns the maximum value of integer type T.

0 commit comments

Comments
 (0)