Skip to main content

deep_time/math/
k_sin.rs

1// origin: FreeBSD /usr/src/lib/msun/src/k_sin.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 S1: Real = -1.66666666666666324348e-01; /* 0xBFC55555, 0x55555549 */
20const S2: Real = 8.33333333332248946124e-03; /* 0x3F811111, 0x1110F8A6 */
21const S3: Real = -1.98412698298579493134e-04; /* 0xBF2A01A0, 0x19C161D5 */
22const S4: Real = 2.75573137070700676789e-06; /* 0x3EC71DE3, 0x57B1FE7D */
23const S5: Real = -2.50507602534068634195e-08; /* 0xBE5AE5E6, 0x8A2B9CEB */
24const S6: Real = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
25
26/// Kernel sin function on ~[-pi/4, pi/4] (except on -0).
27pub(crate) const fn k_sin(x: Real, y: Real, iy: i32) -> Real {
28    let z = x * x;
29    let w = z * z;
30    let r = S2 + z * (S3 + z * S4) + z * w * (S5 + z * S6);
31    let v = z * x;
32
33    if iy == 0 {
34        x + v * (S1 + z * r)
35    } else {
36        x - ((z * (0.5 * y - v * r) - y) - v * S1)
37    }
38}