Skip to main content

elem_simd_math/
constants.rs

1//! Scalar constants shared by the ported kernels.
2//!
3//! Values and names follow `sleef-rs` rev `3671d46` (`src/f64.rs`, `src/f32.rs`), which in turn
4//! carries SLEEF's `misc.h` / `sleefdp.c` constants. Double-double constants are kept as
5//! `(hi, lo)` tuples; see [`crate::doubled`].
6
7// ---------------------------------------------------------------- f64 ----------
8
9/// `2^63`.
10pub const D1_63: f64 = (1u64 << 63) as f64;
11/// `2^60`.
12pub const D1_60: f64 = (1u64 << 60) as f64;
13/// `2^54`.
14pub const D1_54: f64 = (1u64 << 54) as f64;
15/// `2^53`.
16pub const D1_53: f64 = (1u64 << 53) as f64;
17/// `2^52`.
18pub const D1_52: f64 = (1u64 << 52) as f64;
19/// `2^32`.
20pub const D1_32: f64 = (1u64 << 32) as f64;
21/// `2^31`.
22pub const D1_31: f64 = (1u64 << 31) as f64;
23/// `2^28`.
24pub const D1_28: f64 = (1u64 << 28) as f64;
25/// `2^24`.
26pub const D1_24: f64 = (1u64 << 24) as f64;
27/// `2^23`.
28pub const D1_23: f64 = (1u64 << 23) as f64;
29
30/// `ilogb(0)` as returned by SLEEF.
31pub const SLEEF_FP_ILOGB0: i32 = -2_147_483_648;
32/// `ilogb(NaN)` as returned by SLEEF.
33pub const SLEEF_FP_ILOGBNAN: i32 = 2_147_483_647;
34/// `sqrt(f64::MAX)`.
35pub const SQRT_DBL_MAX: f64 = 1.340_780_792_994_259_635_5e+154;
36/// Argument bound for the 1e9-range `*pi` functions.
37pub const TRIGRANGEMAX3: f64 = 1e+9;
38/// High part of `ln 2`.
39pub const L2_U: f64 = 0.693_147_180_559_662_956_511_601_805_686_950_683_593_75;
40/// Low part of `ln 2`.
41pub const L2_L: f64 = 0.282_352_905_630_315_771_225_884_481_750_134_360_255_254_120_68_e-12;
42/// `1 / ln 2`.
43pub const R_LN2: f64 =
44    1.442_695_040_888_963_407_359_924_681_001_892_137_426_645_954_152_985_934_135_449_406_931;
45/// High part of `log10 2`.
46pub const L10_U: f64 = 0.301_029_995_663_839_144_98;
47/// Low part of `log10 2`.
48pub const L10_L: f64 = 1.420_502_322_726_609_941_8_e-13;
49/// `log2 10`.
50pub const LOG10_2: f64 = 3.321_928_094_887_362_347_870_319_429_489_390_175_864_831_393;
51
52/// `pi` reduced into two parts with a trailing zero run of 28 bits, together with the matching
53/// low parts; `PI_A + PI_B + PI_C + PI_D` approximates `pi`.
54pub const PI_A: f64 = 3.141_592_621_803_283_691_4;
55/// See [`PI_A`].
56pub const PI_B: f64 = 3.178_650_942_459_171_346_9_e-8;
57/// See [`PI_A`].
58pub const PI_C: f64 = 1.224_646_786_410_718_850_2_e-16;
59/// See [`PI_A`].
60pub const PI_D: f64 = 1.273_663_432_702_189_981_6_e-24;
61/// Argument bound for the four-term reduction.
62pub const TRIGRANGEMAX: f64 = 1e+14;
63/// Two-term `pi` split used for arguments up to [`TRIGRANGEMAX2`].
64pub const PI_A2: f64 = 3.141_592_653_589_793_116;
65/// See [`PI_A2`].
66pub const PI_B2: f64 = 1.224_646_799_147_353_207_2_e-16;
67/// Argument bound for the two-term reduction.
68pub const TRIGRANGEMAX2: f64 = 15.;
69
70/// `2 / pi` as a double-double.
71pub const M_2_PI: (f64, f64) = (
72    0.636_619_772_367_581_382_43,
73    -3.935_735_335_036_497_176_4_e-17,
74);
75
76/// `pi` as a double-double.
77pub const D_PI: (f64, f64) = (3.141_592_653_589_793_116, 1.224_646_799_147_353_207_2_e-16);
78/// `ln 2` as a double-double.
79pub const D_LN2: (f64, f64) = (
80    0.693_147_180_559_945_286_226_764,
81    2.319_046_813_846_299_558_417_771_e-17,
82);
83
84// ---------------------------------------------------------------- f32 ----------
85
86/// `2^32`.
87pub const F1_32: f32 = (1u64 << 32) as f32;
88/// `2^30`.
89pub const F1_30: f32 = (1u32 << 30) as f32;
90/// `2^25`.
91pub const F1_25: f32 = (1u32 << 25) as f32;
92/// `2^24`.
93pub const F1_24: f32 = (1u32 << 24) as f32;
94/// `2^23`.
95pub const F1_23: f32 = (1u32 << 23) as f32;
96/// `2^12`.
97pub const F1_12: f32 = (1u32 << 12) as f32;
98/// `2^10`.
99pub const F1_10: f32 = (1u32 << 10) as f32;
100
101/// See [`PI_A`]; the `f32` four-term reduction.
102pub const PI_A_F: f32 = 3.140_625;
103/// See [`PI_A_F`].
104pub const PI_B_F: f32 = 0.000_967_025_756_835_937_5;
105/// See [`PI_A_F`].
106pub const PI_C_F: f32 = 6.277_114_152_908_325_195_3_e-7;
107/// See [`PI_A_F`].
108pub const PI_D_F: f32 = 1.215_420_125_655_342_076_2_e-10;
109/// Argument bound for the `f32` four-term reduction.
110pub const TRIGRANGEMAX_F: f32 = 39000.;
111
112/// See [`PI_A2`]; the `f32` three-term reduction.
113pub const PI_A2_F: f32 = 3.141_479_492_187_5;
114/// See [`PI_A2_F`].
115pub const PI_B2_F: f32 = 0.000_113_159_418_106_079_101_56;
116/// See [`PI_A2_F`].
117pub const PI_C2_F: f32 = 1.984_187_258_941_005_893_6_e-9;
118/// Argument bound for the `f32` three-term reduction.
119pub const TRIGRANGEMAX2_F: f32 = 125.0;
120/// Argument bound for the `f32` two-term reduction.
121pub const TRIGRANGEMAX4_F: f32 = 8e+6;
122
123/// `sqrt(f32::MAX)`.
124pub const SQRT_FLT_MAX: f32 = 18_446_743_523_953_729_536.;
125/// High part of `log10 2` for `f32`.
126pub const L10U_F: f32 = 0.301_025_390_6;
127/// Low part of `log10 2` for `f32`.
128pub const L10L_F: f32 = 4.605_038_981_e-6;
129/// High part of `ln 2` for `f32`.
130pub const L2U_F: f32 = 0.693_145_751_953_125;
131/// Low part of `ln 2` for `f32`.
132pub const L2L_F: f32 = 1.428_606_765_330_187_045_e-6;
133/// `1 / ln 2` for `f32`.
134pub const R_LN2_F: f32 =
135    1.442_695_040_888_963_407_359_924_681_001_892_137_426_645_954_152_985_934_135_449_406_931;
136/// `log2 10` for `f32`.
137pub const LOG10_2_F: f32 = 3.321_928_094_887_362_347_870_319_429_489_390_175_864_831_393;
138
139/// `pi` as a double-double for `f32`.
140pub const D_PI_F: (f32, f32) = (
141    3.141_592_741_012_573_242_2,
142    -8.742_277_657_347_585_773_1_e-8,
143);
144/// `ln 2` as a double-double for `f32`.
145pub const D_LN2_F: (f32, f32) = (0.693_147_182_464_599_609_38, -1.904_654_323_148_236_017_e-9);