feature. See also
. The project being documented here (as the example) is the Zig library itself.
atan.atanBinary32Vec
fn atanBinary32Vec(comptime vec_len: comptime_int, x: @Vector(vec_len, f32)) @TypeOf(x)
File
Code
fn atanBinary32Vec(comptime vec_len: comptime_int, x: @Vector(vec_len, f32)) @TypeOf(x) {
const sign_mask: @Vector(vec_len, u32) = @splat(0x80000000);
const neg_one: @Vector(vec_len, f32) = @splat(-1.0);
const pi_over_2: @Vector(vec_len, u32) = @splat(0x3fc90fdb);
const zero: @Vector(vec_len, u32) = @splat(0);
const c0: @Vector(vec_len, f32) = @splat(-0x1.5554dcp-2);
const c1: @Vector(vec_len, f32) = @splat(0x1.9978ecp-3);
const c2: @Vector(vec_len, f32) = @splat(-0x1.230a94p-3);
const c3: @Vector(vec_len, f32) = @splat(0x1.b4debp-4);
const c4: @Vector(vec_len, f32) = @splat(-0x1.3550dap-4);
const c5: @Vector(vec_len, f32) = @splat(0x1.61eebp-5);
const c6: @Vector(vec_len, f32) = @splat(-0x1.0c17d4p-6);
const c7: @Vector(vec_len, f32) = @splat(0x1.7ea694p-9);
const ix: @Vector(vec_len, u32) = @bitCast(x);
const sign = ix & sign_mask;
const pred = @abs(x) > @abs(neg_one);
const z = @select(f32, pred, neg_one / x, x);
const shift: @Vector(vec_len, f32) = @bitCast(@select(u32, pred, pi_over_2 ^ sign, zero));
const z2 = z * z;
const z3 = z * z2;
const z4 = z2 * z2;
const z8 = z4 * z4;
const p0_1 = @mulAdd(@Vector(vec_len, f32), z2, c1, c0);
const p2_3 = @mulAdd(@Vector(vec_len, f32), z2, c3, c2);
const p4_5 = @mulAdd(@Vector(vec_len, f32), z2, c5, c4);
const p6_7 = @mulAdd(@Vector(vec_len, f32), z2, c7, c6);
const p0_3 = @mulAdd(@Vector(vec_len, f32), z4, p2_3, p0_1);
const p4_7 = @mulAdd(@Vector(vec_len, f32), z4, p6_7, p4_5);
const p0_7 = @mulAdd(@Vector(vec_len, f32), z8, p4_7, p0_3);
return @mulAdd(@Vector(vec_len, f32), z3, p0_7, shift + z);
}