Skip to main content

deep_time/math/
k_cos.rs

1// origin: FreeBSD /usr/src/lib/msun/src/k_cos.c
2//
3// ====================================================
4// Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5//
6// Developed at SunSoft, a Sun Microsystems, Inc. business.
7// Permission to use, copy, modify, and distribute this
8// software is freely granted, provided that this notice
9// is preserved.
10// ====================================================
11
12#![allow(clippy::indexing_slicing)]
13#![allow(clippy::excessive_precision)]
14#![allow(clippy::approx_constant)]
15#![allow(clippy::eq_op)]
16
17use crate::Real;
18
19const C1: Real = 4.16666666666666019037e-02; /* 0x3FA55555, 0x5555554C */
20const C2: Real = -1.38888888888741095749e-03; /* 0xBF56C16C, 0x16C15177 */
21const C3: Real = 2.48015872894767294178e-05; /* 0x3EFA01A0, 0x19CB1590 */
22const C4: Real = -2.75573143513906633035e-07; /* 0xBE927E4F, 0x809C52AD */
23const C5: Real = 2.08757232129817482790e-09; /* 0x3E21EE9E, 0xBDB4B1C4 */
24const C6: Real = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
25
26/// Kernel cos function on [-pi/4, pi/4].
27pub(crate) const fn k_cos(x: Real, y: Real) -> Real {
28    let z = x * x;
29    let w = z * z;
30    let r = z * (C1 + z * (C2 + z * C3)) + w * w * (C4 + z * (C5 + z * C6));
31    let hz = 0.5 * z;
32    let w = 1.0 - hz;
33    w + (((1.0 - w) - hz) + (z * r - x * y))
34}