fn asinBinary32(x: f32) f32 x: f3298
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129fn asinBinary32(x: f32) f32 {
const pio2: f64 = 1.570796326794896558e+00;
const hx: u32 = @bitCast(x);
const ix = hx & 0x7fff_ffff;
// |x| >= 1
if (ix >= 0x3f80_0000) {
// |x| == 1
if (ix == 0x3f80_0000) {
// asin(+-1) = +-pi/2 with inexact
return @floatCast(@as(f64, @floatCast(x)) * pio2 + 0x1.0p-120);
}
// asin(|x| > 1) is nan
return 0.0 / (x - x);
}
// |x| < 0.5
if (ix < 0x3f00_0000) {
// 0x1p-126 <= |x| < 0x1p-12
if (ix < 0x3980_0000 and ix >= 0x0080_0000) {
return x;
}
return x + x * rationalApproxBinary32(x * x);
}
// 1 > |x| >= 0.5
const z = (1.0 - @abs(x)) * 0.5;
const s: f64 = @floatCast(@sqrt(z));
const x_local: f32 = @floatCast(pio2 - 2.0 * (s + s * @as(f64, @floatCast(rationalApproxBinary32(z)))));
return if (hx >> 31 != 0) -x_local else x_local;
}