source: sasmodels/sasmodels/models/lib/Si.c @ 4962519

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 4962519 was a5b6997, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

Si: Use Horner's method when computing the Sine integral

  • Property mode set to 100644
File size: 805 bytes
Line 
1// integral of sin(x)/x Taylor series approximated to w/i 0.1%
2double Si(double x);
3double Si(double x)
4{
5    if (x >= M_PI*6.2/4.0){
6        const double z = 1./(x*x);
7        // Explicitly writing factorial values triples the speed of the calculation
8        const double out_cos = (((-720.*z + 24.)*z - 2.)*z + 1.)/x;
9        const double out_sin = (((-5040.*z + 120.)*z - 6.)*z + 1)*z;
10
11        double cos_x, sin_x;
12        SINCOS(x, cos_x, sin_x);
13        return M_PI_2 - cos_x*out_cos - sin_x*out_sin;
14    } else {
15        const double z = x*x;
16        // Explicitly writing factorial values triples the speed of the calculation
17        return (((((-1./439084800.*z
18            + 1./3265920.)*z
19            - 1./35280.)*z
20            + 1./600.)*z
21            - 1./18.)*z
22            + 1.)*x;
23    }
24}
Note: See TracBrowser for help on using the repository browser.