feature. See also
. The project being documented here (as the example) is the Zig library itself.
acos.acosBinary64Vec
fn acosBinary64Vec(comptime vec_len: comptime_int, x: @Vector(vec_len, f64)) @TypeOf(x)
File
Code
fn acosBinary64Vec(comptime vec_len: comptime_int, x: @Vector(vec_len, f64)) @TypeOf(x) {
const pi: @Vector(vec_len, f64) = @splat(math.pi);
const pi_over_2: @Vector(vec_len, f64) = @splat(math.pi / 2.0);
const zero: @Vector(vec_len, f64) = @splat(0.0);
const half: @Vector(vec_len, f64) = @splat(0.5);
const neg_one: @Vector(vec_len, f64) = @splat(-1.0);
const two: @Vector(vec_len, f64) = @splat(2.0);
const c0: @Vector(vec_len, f64) = @splat(0x1.555555555554ep-3);
const c1: @Vector(vec_len, f64) = @splat(0x1.3333333337233p-4);
const c2: @Vector(vec_len, f64) = @splat(0x1.6db6db67f6d9fp-5);
const c3: @Vector(vec_len, f64) = @splat(0x1.f1c71fbd29fbbp-6);
const c4: @Vector(vec_len, f64) = @splat(0x1.6e8b264d467d6p-6);
const c5: @Vector(vec_len, f64) = @splat(0x1.1c5997c357e9dp-6);
const c6: @Vector(vec_len, f64) = @splat(0x1.c86a22cd9389dp-7);
const c7: @Vector(vec_len, f64) = @splat(0x1.856073c22ebbep-7);
const c8: @Vector(vec_len, f64) = @splat(0x1.fd1151acb6bedp-8);
const c9: @Vector(vec_len, f64) = @splat(0x1.087182f799c1dp-6);
const c10: @Vector(vec_len, f64) = @splat(-0x1.6602748120927p-7);
const c11: @Vector(vec_len, f64) = @splat(0x1.cfa0dd1f9478p-6);
const ax = @abs(x);
const ax_lt_half = ax < half;
const is_neg = x < zero;
const z2 = @select(f64, ax_lt_half, x * x, @mulAdd(@Vector(vec_len, f64), -half, ax, half));
const z = @select(f64, ax_lt_half, ax, @sqrt(z2));
const z3 = z2 * z;
const z4 = z2 * z2;
const z8 = z4 * z4;
const p0_1 = @mulAdd(@Vector(vec_len, f64), z2, c1, c0);
const p2_3 = @mulAdd(@Vector(vec_len, f64), z2, c3, c2);
const p0_3 = @mulAdd(@Vector(vec_len, f64), z4, p2_3, p0_1);
const p4_5 = @mulAdd(@Vector(vec_len, f64), z2, c5, c4);
const p6_7 = @mulAdd(@Vector(vec_len, f64), z2, c7, c6);
const p4_7 = @mulAdd(@Vector(vec_len, f64), z4, p6_7, p4_5);
const p8_9 = @mulAdd(@Vector(vec_len, f64), z2, c9, c8);
const p10_11 = @mulAdd(@Vector(vec_len, f64), z2, c11, c10);
const p8_11 = @mulAdd(@Vector(vec_len, f64), z4, p10_11, p8_9);
const p4_11 = @mulAdd(@Vector(vec_len, f64), z8, p8_11, p4_7);
const p0_11 = @mulAdd(@Vector(vec_len, f64), z8, p4_11, p0_3);
const p = @mulAdd(@Vector(vec_len, f64), z3, p0_11, z);
const mul = @select(f64, ax_lt_half, neg_one, two);
const add = @select(f64, ax_lt_half, pi_over_2, @select(f64, is_neg, pi, zero));
return @mulAdd(@Vector(vec_len, f64), mul, @select(f64, is_neg, -p, p), add);
}