MCPcopy Create free account
hub / github.com/CoolProp/CoolProp / interp1d

Function interp1d

src/CPnumerics.cpp:13–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11 return sqrt(sum);
12}
13double interp1d(const std::vector<double>* x, const std::vector<double>* y, double x0) {
14 std::size_t i = 0, L = 0, R = 0, M = 0;
15 L = 0;
16 R = (*x).size() - 1;
17 M = (L + R) / 2;
18 // Use interval halving to find the indices which bracket the density of interest
19 while (R - L > 1) {
20 if (x0 >= (*x)[M]) {
21 L = M;
22 M = (L + R) / 2;
23 continue;
24 }
25 if (x0 < (*x)[M]) {
26 R = M;
27 M = (L + R) / 2;
28 continue;
29 }
30 }
31 i = L;
32 if (i < (*x).size() - 2) {
33 // Go "forwards" with the interpolation range
34 return QuadInterp((*x)[i], (*x)[i + 1], (*x)[i + 2], (*y)[i], (*y)[i + 1], (*y)[i + 2], x0);
35 } else {
36 // Go "backwards" with the interpolation range
37 return QuadInterp((*x)[i], (*x)[i - 1], (*x)[i - 2], (*y)[i], (*y)[i - 1], (*y)[i - 2], x0);
38 }
39}
40double powInt(double x, int y) {
41 // Raise a double to an integer power
42 // Overload not provided in math.h

Callers 1

interpolate_values_1dFunction · 0.85

Calls 2

QuadInterpFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected