Skip to content

Commit dd5a0d5

Browse files
committed
fix: omit comptime T: type
1 parent 09e4a69 commit dd5a0d5

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
@@ -1284,26 +1284,28 @@ test "lossyCast" {
12841284
///
12851285
/// This does not guarantee returning *b* if *t* is 1 due to floating-point errors.
12861286
/// This is monotonic.
1287-
pub fn lerp(comptime T: type, a: T, b: T, t: T) T {
1288-
if (@typeInfo(T) != .Float and @typeInfo(T) != .ComptimeFloat)
1287+
pub fn lerp(a: anytype, b: anytype, t: anytype) @TypeOf(a, b, t) {
1288+
const T = @TypeOf(a, b, t);
1289+
1290+
comptime if (!std.meta.trait.isFloat(T))
12891291
@compileError("T must be a float type");
12901292

12911293
assert(t >= 0 and t <= 1);
12921294
return @mulAdd(T, b - a, t, a);
12931295
}
12941296

12951297
test "lerp" {
1296-
try testing.expectEqual(@as(f64, 75), lerp(f64, 50, 100, 0.5));
1297-
try testing.expectEqual(@as(f32, 43.75), lerp(f32, 50, 25, 0.25));
1298-
try testing.expectEqual(@as(f64, -31.25), lerp(f64, -50, 25, 0.25));
1298+
try testing.expectEqual(@as(f64, 75), lerp(50, 100, 0.5));
1299+
try testing.expectEqual(@as(f32, 43.75), lerp(50, 25, 0.25));
1300+
try testing.expectEqual(@as(f64, -31.25), lerp(-50, 25, 0.25));
12991301

1300-
try testing.expectApproxEqRel(@as(f32, -7.16067345e+03), lerp(f32, -10000.12345, -5000.12345, 0.56789), 1e-19);
1301-
try testing.expectApproxEqRel(@as(f64, 7.010987590521e+62), lerp(f64, 0.123456789e-64, 0.123456789e64, 0.56789), 1e-33);
1302+
try testing.expectApproxEqRel(@as(f32, -7.16067345e+03), lerp(-10000.12345, -5000.12345, 0.56789), 1e-19);
1303+
try testing.expectApproxEqRel(@as(f64, 7.010987590521e+62), lerp(0.123456789e-64, 0.123456789e64, 0.56789), 1e-33);
13021304

1303-
try testing.expectEqual(@as(f32, 0.0), lerp(f32, 1.0e8, 1.0, 1.0));
1304-
try testing.expectEqual(@as(f64, 0.0), lerp(f64, 1.0e16, 1.0, 1.0));
1305-
try testing.expectEqual(@as(f32, 1.0), lerp(f32, 1.0e7, 1.0, 1.0));
1306-
try testing.expectEqual(@as(f64, 1.0), lerp(f64, 1.0e15, 1.0, 1.0));
1305+
try testing.expectEqual(@as(f32, 0.0), lerp(@as(f32, 1.0e8), 1.0, 1.0));
1306+
try testing.expectEqual(@as(f64, 0.0), lerp(@as(f64, 1.0e16), 1.0, 1.0));
1307+
try testing.expectEqual(@as(f32, 1.0), lerp(@as(f32, 1.0e7), 1.0, 1.0));
1308+
try testing.expectEqual(@as(f64, 1.0), lerp(@as(f64, 1.0e15), 1.0, 1.0));
13071309
}
13081310

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

0 commit comments

Comments
 (0)