Skip to content

Commit b6e2cab

Browse files
committed
replace fx2 with c function without fma.
1 parent 65eb260 commit b6e2cab

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

pineappl/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ repository.workspace = true
1212
rust-version.workspace = true
1313
version.workspace = true
1414

15+
[build-dependencies]
16+
cc = "1.0"
17+
1518
[lints]
1619
workspace = true
1720

pineappl/src/fx2.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <math.h>
2+
#include <float.h>
3+
4+
double fx2(double y) {
5+
double x, yp, deltap, delta, deriv;
6+
int i;
7+
8+
yp = y;
9+
deltap = DBL_MAX;
10+
11+
for (i = 0; i <= 10; i=i+1) {
12+
x = exp(-yp);
13+
delta = (1.0 - x) * (-5.0) + (y - yp);
14+
15+
if (fabs(delta) < 1e-15 && delta >= deltap) {
16+
return x;
17+
}
18+
19+
deriv = -5.0 * x - 1.0;
20+
yp = yp - delta / deriv;
21+
deltap = delta;
22+
}
23+
24+
return -1;
25+
}

pineappl/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
//! [special keys]: https://nnpdf.github.io/pineappl/docs/metadata.html
3434
//! [CLI tutorial]: https://nnpdf.github.io/pineappl/docs/cli-tutorial.html
3535
36+
extern "C" {
37+
fn fx2(y: f64) -> f64;
38+
}
39+
40+
pub(crate) fn fx2_rust(y: f64) -> f64 {
41+
unsafe { fx2(y) }
42+
}
3643
mod convert;
3744
mod v0;
3845

@@ -47,3 +54,4 @@ pub mod packed_array;
4754
pub mod pids;
4855
pub mod reference;
4956
pub mod subgrid;
57+

0 commit comments

Comments
 (0)