| ... | ... | @@ -23,21 +23,21 @@ const testing = std.testing; |
| 23 | 23 | /// - atan(+-inf) = +-pi/2 |
| 24 | 24 | pub fn atan(x: anytype) @TypeOf(x) { |
| 25 | 25 | const T = @TypeOf(x); |
| 26 | | switch (T) { |
| 27 | | f16 => return atanBinary16(x), |
| 28 | | f32 => return atanBinary32(x), |
| 29 | | f64 => return atanBinary64(x), |
| 30 | | f80 => return atanExtended80(x), |
| 31 | | f128 => return atanBinary128(x), |
| 32 | | else => { |
| 33 | | const info = @typeInfo(T); |
| 34 | | if (info == .vector) { |
| 35 | | const vec_type = info.vector.child; |
| 36 | | if (vec_type == f32) return atanBinary32Vec(x); |
| 37 | | if (vec_type == f64) return atanBinary64Vec(x); |
| 38 | | } |
| 39 | | @compileError("atan not implemented for " ++ @typeName(T)); |
| 26 | switch (@typeInfo(T)) { |
| 27 | .float => |info| switch (info.bits) { |
| 28 | 16 => return atanBinary16(x), |
| 29 | 32 => return atanBinary32(x), |
| 30 | 64 => return atanBinary64(x), |
| 31 | 80 => return atanExtended80(x), |
| 32 | 128 => return atanBinary128(x), |
| 33 | else => comptime unreachable, |
| 34 | }, |
| 35 | .vector => |info| switch (info.child) { |
| 36 | f32 => return atanBinary32Vec(info.len, x), |
| 37 | f64 => return atanBinary64Vec(info.len, x), |
| 38 | else => @compileError("unimplemented"), |
| 40 | 39 | }, |
| 40 | else => comptime unreachable, |
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
| ... | ... | @@ -594,10 +594,7 @@ test "atanBinary128" { |
| 594 | 594 | try testing.expectApproxEqAbs(atanBinary128(-0x1.0264fb9f3d50e4f0f966f0686064p1), -0x1.1c617825f97512b7f38656ab12cdp0, math.floatEpsAt(f128, -0x1.1c617825f97512b7f38656ab12cdp0)); |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | | fn atanBinary32Vec(x: anytype) @TypeOf(x) { |
| 598 | | const type_info = @typeInfo(@TypeOf(x)); |
| 599 | | comptime std.debug.assert(type_info.vector.child == f32); |
| 600 | | const vec_len = type_info.vector.len; |
| 597 | fn atanBinary32Vec(comptime vec_len: comptime_int, x: @Vector(vec_len, f32)) @TypeOf(x) { |
| 601 | 598 | const sign_mask: @Vector(vec_len, u32) = @splat(0x80000000); |
| 602 | 599 | const neg_one: @Vector(vec_len, f32) = @splat(-1.0); |
| 603 | 600 | const pi_over_2: @Vector(vec_len, u32) = @splat(0x3fc90fdb); |
| ... | ... | @@ -630,10 +627,7 @@ fn atanBinary32Vec(x: anytype) @TypeOf(x) { |
| 630 | 627 | return @mulAdd(@Vector(vec_len, f32), z3, p0_7, shift + z); |
| 631 | 628 | } |
| 632 | 629 | |
| 633 | | fn atanBinary64Vec(x: anytype) @TypeOf(x) { |
| 634 | | const type_info = @typeInfo(@TypeOf(x)); |
| 635 | | comptime std.debug.assert(type_info.vector.child == f64); |
| 636 | | const vec_len = type_info.vector.len; |
| 630 | fn atanBinary64Vec(comptime vec_len: comptime_int, x: @Vector(vec_len, f64)) @TypeOf(x) { |
| 637 | 631 | const sign_mask: @Vector(vec_len, u64) = @splat(0x8000000000000000); |
| 638 | 632 | const neg_one: @Vector(vec_len, f64) = @splat(-1.0); |
| 639 | 633 | const pi_over_2: @Vector(vec_len, u64) = @splat(0x3ff921fb54442d18); |
| ... | ... | @@ -701,7 +695,7 @@ test "atanBinary32Vec.special" { |
| 701 | 695 | -math.inf(f32), |
| 702 | 696 | math.nan(f32), |
| 703 | 697 | }; |
| 704 | | const output = atanBinary32Vec(input); |
| 698 | const output = atanBinary32Vec(7, input); |
| 705 | 699 | try testing.expectEqual(output[0], 0x0p+0); |
| 706 | 700 | try testing.expectEqual(output[1], -0x0p+0); |
| 707 | 701 | try testing.expectApproxEqAbs(output[2], 0x1.921fb6p-1, math.floatEpsAt(f32, 0x1.921fb6p-1)); |
| ... | ... | @@ -724,7 +718,7 @@ test "atanBinary32Vec" { |
| 724 | 718 | 0x1.299d54p1, |
| 725 | 719 | -0x1.0264fcp1, |
| 726 | 720 | }; |
| 727 | | const output = atanBinary32Vec(input); |
| 721 | const output = atanBinary32Vec(10, input); |
| 728 | 722 | try testing.expectApproxEqAbs(output[0], -0x1.74c62p-2, math.floatEpsAt(f32, -0x1.74c62p-2)); |
| 729 | 723 | try testing.expectApproxEqAbs(output[1], -0x1.375fd8p0, math.floatEpsAt(f32, -0x1.375fd8p0)); |
| 730 | 724 | try testing.expectApproxEqAbs(output[2], -0x1.11b8aep0, math.floatEpsAt(f32, -0x1.11b8aep0)); |
| ... | ... | @@ -747,7 +741,7 @@ test "atanBinary64Vec.special" { |
| 747 | 741 | -math.inf(f64), |
| 748 | 742 | math.nan(f64), |
| 749 | 743 | }; |
| 750 | | const output = atanBinary64Vec(input); |
| 744 | const output = atanBinary64Vec(7, input); |
| 751 | 745 | try testing.expectEqual(output[0], 0x0p+0); |
| 752 | 746 | try testing.expectEqual(output[1], -0x0p+0); |
| 753 | 747 | try testing.expectApproxEqAbs(output[2], 0x1.921fb54442d18p-1, math.floatEpsAt(f64, 0x1.921fb54442d18p-1)); |
| ... | ... | @@ -770,7 +764,7 @@ test "atanBinary64Vec" { |
| 770 | 764 | 0x1.299d54ac7d6bp1, |
| 771 | 765 | -0x1.0264fb9f3d50ep1, |
| 772 | 766 | }; |
| 773 | | const output = atanBinary64Vec(input); |
| 767 | const output = atanBinary64Vec(10, input); |
| 774 | 768 | try testing.expectApproxEqAbs(output[0], -0x1.74c61f4377016p-2, math.floatEpsAt(f64, -0x1.74c61f4377016p-2)); |
| 775 | 769 | try testing.expectApproxEqAbs(output[1], -0x1.375fd7987cc2p0, math.floatEpsAt(f64, -0x1.375fd7987cc2p0)); |
| 776 | 770 | try testing.expectApproxEqAbs(output[2], -0x1.11b8adeba5616p0, math.floatEpsAt(f64, -0x1.11b8adeba5616p0)); |