Skip to content

Commit 8c476c9

Browse files
committed
add test for problematic point.
1 parent 2f3afc7 commit 8c476c9

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

pineappl/src/interpolation.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,16 @@ mod applgrid {
1515
(x.sqrt() / x.mul_add(-0.99, 1.0)).powi(3)
1616
}
1717

18+
#[inline(never)]
1819
pub fn fx2(y: f64) -> f64 {
19-
let mut yp = y;
20-
let mut deltap = f64::INFINITY;
21-
22-
for _ in 0..10 {
23-
let x = (-yp).exp();
24-
let delta = (1.0 - x).mul_add(-5.0, y - yp);
25-
if (delta.abs() < 1e-15) && (delta >= deltap) {
26-
return x;
27-
}
28-
let deriv = x.mul_add(-5.0, -1.0);
29-
yp -= delta / deriv;
30-
deltap = delta;
20+
21+
let x = crate::fx2_rust(y);
22+
23+
if x == -1.0 {
24+
unreachable!();
3125
}
3226

33-
unreachable!();
27+
return x;
3428
}
3529

3630
pub fn fy2(x: f64) -> f64 {
@@ -349,6 +343,21 @@ mod tests {
349343
use float_cmp::assert_approx_eq;
350344
use float_cmp::Ulps;
351345

346+
#[test]
347+
fn test_convergence_of_newton_method_in_fx2() {
348+
let y = 6.786550974400577;
349+
350+
let result = std::panic::catch_unwind(|| {
351+
fx2(y)
352+
});
353+
354+
assert!(result.is_ok(), "fx2 failed: Newton iterations did not converge!");
355+
356+
let x = result.unwrap();
357+
println!("fx2({}) = {}", y, x);
358+
}
359+
360+
352361
#[test]
353362
fn interpolate_two_points() {
354363
let interps = vec![

0 commit comments

Comments
 (0)