feature. See also
. The project being documented here (as the example) is the Zig library itself.
cosh.cosh64
fn cosh64(z: Complex(f64)) Complex(f64)
File
Code
fn cosh64(z: Complex(f64)) Complex(f64) {
const x = z.re;
const y = z.im;
const fx: u64 = @bitCast(x);
const hx: u32 = @intCast(fx >> 32);
const lx: u32 = @truncate(fx);
const ix = hx & 0x7fffffff;
const fy: u64 = @bitCast(y);
const hy: u32 = @intCast(fy >> 32);
const ly: u32 = @truncate(fy);
const iy = hy & 0x7fffffff;
if (ix < 0x7ff00000 and iy < 0x7ff00000) {
if (iy | ly == 0) {
return Complex(f64).init(math.cosh(x), x * y);
}
if (ix < 0x40360000) {
return Complex(f64).init(math.cosh(x) * @cos(y), math.sinh(x) * @sin(y));
}
if (ix < 0x40862e42) {
const h = @exp(@abs(x)) * 0.5;
return Complex(f64).init(h * @cos(y), math.copysign(h, x) * @sin(y));
}
else if (ix < 0x4096bbaa) {
const v = Complex(f64).init(@abs(x), y);
const r = ldexp_cexp(v, -1);
return Complex(f64).init(r.re, r.im * math.copysign(@as(f64, 1.0), x));
}
else {
const h = 0x1p1023 * x;
return Complex(f64).init(h * h * @cos(y), h * @sin(y));
}
}
if (ix | lx == 0 and iy >= 0x7ff00000) {
return Complex(f64).init(y - y, math.copysign(@as(f64, 0.0), x * (y - y)));
}
if (iy | ly == 0 and ix >= 0x7ff00000) {
if ((hx & 0xfffff) | lx == 0) {
return Complex(f64).init(x * x, math.copysign(@as(f64, 0.0), x) * y);
}
return Complex(f64).init(x * x, math.copysign(@as(f64, 0.0), (x + x) * y));
}
if (ix < 0x7ff00000 and iy >= 0x7ff00000) {
return Complex(f64).init(y - y, x * (y - y));
}
if (ix >= 0x7ff00000 and (hx & 0xfffff) | lx == 0) {
if (iy >= 0x7ff00000) {
return Complex(f64).init(x * x, x * (y - y));
}
return Complex(f64).init(x * x * @cos(y), x * @sin(y));
}
return Complex(f64).init((x * x) * (y - y), (x + x) * (y - y));
}