pxfm/shared_eval.rs
1/*
2 * // Copyright (c) Radzivon Bartoshyk 7/2025. All rights reserved.
3 * //
4 * // Redistribution and use in source and binary forms, with or without modification,
5 * // are permitted provided that the following conditions are met:
6 * //
7 * // 1. Redistributions of source code must retain the above copyright notice, this
8 * // list of conditions and the following disclaimer.
9 * //
10 * // 2. Redistributions in binary form must reproduce the above copyright notice,
11 * // this list of conditions and the following disclaimer in the documentation
12 * // and/or other materials provided with the distribution.
13 * //
14 * // 3. Neither the name of the copyright holder nor the names of its
15 * // contributors may be used to endorse or promote products derived from
16 * // this software without specific prior written permission.
17 * //
18 * // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 * // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 * // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29use crate::double_double::DoubleDouble;
30
31#[inline]
32pub(crate) fn poly_dd_3(x: DoubleDouble, poly: [(u64, u64); 3], l: f64) -> DoubleDouble {
33 let zch = poly[2];
34 let ach = f64::from_bits(zch.0) + l;
35 let acl = (f64::from_bits(zch.0) - ach) + l + f64::from_bits(zch.1);
36 let mut ch = DoubleDouble::new(acl, ach);
37
38 let zch = poly[1];
39 ch = DoubleDouble::quick_mult(ch, x);
40 let th = ch.hi + f64::from_bits(zch.0);
41 let tl = (f64::from_bits(zch.0) - th) + ch.hi;
42 ch.hi = th;
43 ch.lo += tl + f64::from_bits(zch.1);
44
45 let zch = poly[0];
46 ch = DoubleDouble::quick_mult(ch, x);
47 let th = ch.hi + f64::from_bits(zch.0);
48 let tl = (f64::from_bits(zch.0) - th) + ch.hi;
49 ch.hi = th;
50 ch.lo += tl + f64::from_bits(zch.1);
51
52 ch
53}
54
55#[inline]
56pub(crate) fn poly_dekker_generic<const N: usize>(
57 x: DoubleDouble,
58 poly: [(u64, u64); N],
59) -> DoubleDouble {
60 let zch = poly.last().unwrap();
61 let ach = f64::from_bits(zch.0);
62 let acl = f64::from_bits(zch.1);
63 let mut ch = DoubleDouble::new(acl, ach);
64
65 for zch in poly.iter().rev().skip(1) {
66 ch = DoubleDouble::quick_mult(ch, x);
67 let th = ch.hi + f64::from_bits(zch.0);
68 let tl = (f64::from_bits(zch.0) - th) + ch.hi;
69 ch.hi = th;
70 ch.lo += tl + f64::from_bits(zch.1);
71 }
72
73 ch
74}