fn asinBinary16(x: f16) f16 x: f1655
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85fn asinBinary16(x: f16) f16 {
const pio2: f32 = math.pi / 2.0;
const hx: u16 = @bitCast(x);
const ix = hx & 0x7fff;
// |x| >= 1
if (ix >= 0x3c00) {
// |x| == 1
if (ix == 0x3c00) {
// asin(+-1) = +-pi/2 with inexact
return @floatCast(x * pio2 + 0x1.0p-120);
}
// asin(|x| > 1) is nan
return 0.0 / (x - x);
}
// |x| < 0.5
if (ix < 0x3800) {
return @floatCast(x * approxBinary16(x * x));
}
// 1 > |x| >= 0.5
const z = (1.0 - @abs(x)) * 0.5;
const s = @sqrt(z);
const x_local = pio2 - 2.0 * s * approxBinary16(z);
if (hx >> 15 != 0) {
return @floatCast(-x_local);
}
return @floatCast(x_local);
}