From 91b05ad473b4d16e9a50a83f2655599ce177e767 Mon Sep 17 00:00:00 2001 From: zooster Date: Fri, 30 Sep 2022 16:45:37 +0200 Subject: std.math: allow comptime_float for radiansToDegrees and degreesToRadians And some other minor things. --- lib/std/math.zig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/std/math.zig b/lib/std/math.zig index a69a6f428c..18c8f555d4 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -285,10 +285,10 @@ pub inline fn tan(value: anytype) @TypeOf(value) { return @tan(value); } -// Convert an angle in radians to degrees. T must be a float type. +/// Converts an angle in radians to degrees. T must be a float type. pub fn radiansToDegrees(comptime T: type, angle_in_radians: T) T { - if (@typeInfo(T) != .Float) - @compileError("T must be a float type."); + if (@typeInfo(T) != .Float and @typeInfo(T) != .ComptimeFloat) + @compileError("T must be a float type"); return angle_in_radians * 180.0 / pi; } @@ -300,10 +300,10 @@ test "radiansToDegrees" { try std.testing.expectApproxEqAbs(@as(f32, 360), radiansToDegrees(f32, 2.0 * pi), 1e-6); } -// Convert an angle in degrees to radians. T must be a float type. +/// Converts an angle in degrees to radians. T must be a float type. pub fn degreesToRadians(comptime T: type, angle_in_degrees: T) T { - if (@typeInfo(T) != .Float) - @compileError("T must be a float type."); + if (@typeInfo(T) != .Float and @typeInfo(T) != .ComptimeFloat) + @compileError("T must be a float type"); return angle_in_degrees * pi / 180.0; } -- cgit v1.2.3