feature. See also
. The project being documented here (as the example) is the Zig library itself.
acos.acosBinary32Vec
fn acosBinary32Vec(comptime vec_len: comptime_int, x: @Vector(vec_len, f32)) @TypeOf(x)
File
Code
fn acosBinary32Vec(comptime vec_len: comptime_int, x: @Vector(vec_len, f32)) @TypeOf(x) {
const pi: @Vector(vec_len, f32) = @splat(math.pi);
const pi_over_2: @Vector(vec_len, f32) = @splat(math.pi / 2.0);
const zero: @Vector(vec_len, f32) = @splat(0.0);
const half: @Vector(vec_len, f32) = @splat(0.5);
const neg_one: @Vector(vec_len, f32) = @splat(-1.0);
const two: @Vector(vec_len, f32) = @splat(2.0);
const c0: @Vector(vec_len, f32) = @splat(0x1.55555ep-3);
const c1: @Vector(vec_len, f32) = @splat(0x1.33261ap-4);
const c2: @Vector(vec_len, f32) = @splat(0x1.70d7dcp-5);
const c3: @Vector(vec_len, f32) = @splat(0x1.b059dp-6);
const c4: @Vector(vec_len, f32) = @splat(0x1.3af7d8p-5);
const ax = @abs(x);
const ax_lt_half = ax < half;
const is_neg = x < zero;
const z2 = @select(f32, ax_lt_half, x * x, @mulAdd(@Vector(vec_len, f32), -half, ax, half));
const z = @select(f32, ax_lt_half, ax, @sqrt(z2));
const z3 = z2 * z;
const p3_4 = @mulAdd(@Vector(vec_len, f32), z2, c4, c3);
const p2_4 = @mulAdd(@Vector(vec_len, f32), z2, p3_4, c2);
const p1_4 = @mulAdd(@Vector(vec_len, f32), z2, p2_4, c1);
const p0_4 = @mulAdd(@Vector(vec_len, f32), z2, p1_4, c0);
const p = @mulAdd(@Vector(vec_len, f32), z3, p0_4, z);
const mul = @select(f32, ax_lt_half, neg_one, two);
const add = @select(f32, ax_lt_half, pi_over_2, @select(f32, is_neg, pi, zero));
return @mulAdd(@Vector(vec_len, f32), mul, @select(f32, is_neg, -p, p), add);
}