Commit 91b05ad473

zooster <r00ster91@proton.me>
2022-09-30 16:45:37
std.math: allow comptime_float for radiansToDegrees and degreesToRadians
And some other minor things.
1 parent 34835bb
Changed files (1)
lib
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;
 }