| ... | @@ -10,25 +10,28 @@ const expect = std.testing.expect; | ... | @@ -10,25 +10,28 @@ const expect = std.testing.expect; |
| 10 | | 10 | |
| 11 | /// Returns the arc-tangent of y/x. | 11 | /// Returns the arc-tangent of y/x. |
| 12 | /// | 12 | /// |
| 13 | /// Special Cases: | 13 | /// Special Cases: |
| 14 | /// - atan2(y, nan) = nan | 14 | /// | y | x | radians | |
| 15 | /// - atan2(nan, x) = nan | 15 | /// |-------|-------|---------| |
| 16 | /// - atan2(+0, x>=0) = +0 | 16 | /// | fin | nan | nan | |
| 17 | /// - atan2(-0, x>=0) = -0 | 17 | /// | nan | fin | nan | |
| 18 | /// - atan2(+0, x<=-0) = +pi | 18 | /// | +0 | >=+0 | +0 | |
| 19 | /// - atan2(-0, x<=-0) = -pi | 19 | /// | -0 | >=+0 | -0 | |
| 20 | /// - atan2(y>0, 0) = +pi/2 | 20 | /// | +0 | <=-0 | pi | |
| 21 | /// - atan2(y<0, 0) = -pi/2 | 21 | /// | -0 | <=-0 | -pi | |
| 22 | /// - atan2(+inf, +inf) = +pi/4 | 22 | /// | pos | 0 | +pi/2 | |
| 23 | /// - atan2(-inf, +inf) = -pi/4 | 23 | /// | neg | 0 | -pi/2 | |
| 24 | /// - atan2(+inf, -inf) = 3pi/4 | 24 | /// | +inf | +inf | +pi/4 | |
| 25 | /// - atan2(-inf, -inf) = -3pi/4 | 25 | /// | -inf | +inf | -pi/4 | |
| 26 | /// - atan2(y, +inf) = 0 | 26 | /// | +inf | -inf | 3pi/4 | |
| 27 | /// - atan2(y>0, -inf) = +pi | 27 | /// | -inf | -inf | -3pi/4 | |
| 28 | /// - atan2(y<0, -inf) = -pi | 28 | /// | fin | +inf | 0 | |
| 29 | /// - atan2(+inf, x) = +pi/2 | 29 | /// | pos | -inf | +pi | |
| 30 | /// - atan2(-inf, x) = -pi/2 | 30 | /// | neg | -inf | -pi | |
| 31 | pub fn atan2(comptime T: type, y: T, x: T) T { | 31 | /// | +inf | fin | +pi/2 | |
| | 32 | /// | -inf | fin | -pi/2 | |
| | 33 | pub fn atan2(y: anytype, x: anytype) @TypeOf(x, y) { |
| | 34 | const T = @TypeOf(x, y); |
| 32 | return switch (T) { | 35 | return switch (T) { |
| 33 | f32 => atan2_32(y, x), | 36 | f32 => atan2_32(y, x), |
| 34 | f64 => atan2_64(y, x), | 37 | f64 => atan2_64(y, x), |
| ... | @@ -212,8 +215,12 @@ fn atan2_64(y: f64, x: f64) f64 { | ... | @@ -212,8 +215,12 @@ fn atan2_64(y: f64, x: f64) f64 { |
| 212 | } | 215 | } |
| 213 | | 216 | |
| 214 | test "math.atan2" { | 217 | test "math.atan2" { |
| 215 | try expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21)); | 218 | const y32: f32 = 0.2; |
| 216 | try expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21)); | 219 | const x32: f32 = 0.21; |
| | 220 | const y64: f64 = 0.2; |
| | 221 | const x64: f64 = 0.21; |
| | 222 | try expect(atan2(y32, x32) == atan2_32(0.2, 0.21)); |
| | 223 | try expect(atan2(y64, x64) == atan2_64(0.2, 0.21)); |
| 217 | } | 224 | } |
| 218 | | 225 | |
| 219 | test "math.atan2_32" { | 226 | test "math.atan2_32" { |