fn acosExtended80(x: f80) f80 x: f80233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271fn acosExtended80(x: f80) f80 {
const pio2_hi: f80 = 1.57079632679489661926;
const pio2_lo: f80 = -2.50827880633416601173e-20;
const hx: u80 = @bitCast(x);
const se: u16 = @truncate(hx >> 64);
const e = se & 0x7fff;
// |x| >= 1 or nan
if (e >= 0x3fff) {
if (x == 1.0) {
return 0.0;
}
if (x == -1.0) {
return 2.0 * pio2_hi + 0x1p-120;
}
return 0.0 / (x - x);
}
// |x| < 0.5
if (e < 0x3fff - 1) {
if (e < 0x3fff - math.floatFractionalBits(f80)) {
return pio2_hi + 0x1p-120;
}
return pio2_hi - (rationalApproxExtended80(x * x) * x - pio2_lo + x);
}
// x < -0.5
if (se >> 15 != 0) {
const z = (1 + x) * 0.5;
const s = @sqrt(z);
return 2.0 * (pio2_hi - (rationalApproxExtended80(z) * s - pio2_lo + s));
}
// x > 0.5
const z = (1.0 - x) * 0.5;
const s = @sqrt(z);
const hs: u80 = @bitCast(s);
const f: f80 = @bitCast(hs & 0xffff_ffff_ffff_0000_0000);
const c = (z - f * f) / (s + f);
return 2.0 * (rationalApproxExtended80(z) * s + c + f);
}