authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-09-30 16:45:37+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-01 13:46:20+03:00
log91b05ad473b4d16e9a50a83f2655599ce177e767
treeb02f24e1762977bcd2be9aa3b6a805552ebcdb38
parent34835bbbcfe81cc87e823d14dc9b25e698ad5edc

std.math: allow comptime_float for radiansToDegrees and degreesToRadians

And some other minor things.

1 files changed, 6 insertions(+), 6 deletions(-)

lib/std/math.zig+6-6
...@@ -285,10 +285,10 @@ pub inline fn tan(value: anytype) @TypeOf(value) {...@@ -285,10 +285,10 @@ pub inline fn tan(value: anytype) @TypeOf(value) {
285 return @tan(value);285 return @tan(value);
286}286}
287287
288// Convert an angle in radians to degrees. T must be a float type.288/// Converts an angle in radians to degrees. T must be a float type.
289pub fn radiansToDegrees(comptime T: type, angle_in_radians: T) T {289pub fn radiansToDegrees(comptime T: type, angle_in_radians: T) T {
290 if (@typeInfo(T) != .Float)290 if (@typeInfo(T) != .Float and @typeInfo(T) != .ComptimeFloat)
291 @compileError("T must be a float type.");291 @compileError("T must be a float type");
292 return angle_in_radians * 180.0 / pi;292 return angle_in_radians * 180.0 / pi;
293}293}
294294
...@@ -300,10 +300,10 @@ test "radiansToDegrees" {...@@ -300,10 +300,10 @@ test "radiansToDegrees" {
300 try std.testing.expectApproxEqAbs(@as(f32, 360), radiansToDegrees(f32, 2.0 * pi), 1e-6);300 try std.testing.expectApproxEqAbs(@as(f32, 360), radiansToDegrees(f32, 2.0 * pi), 1e-6);
301}301}
302302
303// Convert an angle in degrees to radians. T must be a float type.303/// Converts an angle in degrees to radians. T must be a float type.
304pub fn degreesToRadians(comptime T: type, angle_in_degrees: T) T {304pub fn degreesToRadians(comptime T: type, angle_in_degrees: T) T {
305 if (@typeInfo(T) != .Float)305 if (@typeInfo(T) != .Float and @typeInfo(T) != .ComptimeFloat)
306 @compileError("T must be a float type.");306 @compileError("T must be a float type");
307 return angle_in_degrees * pi / 180.0;307 return angle_in_degrees * pi / 180.0;
308}308}
309309