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

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since dcef2ee was dcef2ee, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

fix opencl build error for pearl necklace

  • Property mode set to 100644
File size: 887 bytes
Line 
1int factorial(int f);
2double Si(double x);
3
4// integral of sin(x)/x: approximated to w/i 1%
5double Si(double x)
6{
7        int i;
8        int nmax=6;
9        double out;
10        long power;
11        double pi = 4.0*atan(1.0);
12
13        if (x >= pi*6.2/4.0){
14                double out_sin = 0.0;
15                double out_cos = 0.0;
16                out = pi/2.0;
17
18                for (i=0; i<nmax-2; i+=1) {
19                        out_cos += pow(-1.0, i) * (double)factorial(2*i) / pow(x, 2*i+1);
20                        out_sin += pow(-1.0, i) * (double)factorial(2*i+1) / pow(x, 2*i+2);
21                }
22
23                out -= cos(x) * out_cos;
24                out -= sin(x) * out_sin;
25                return out;
26        }
27
28        out = 0.0;
29
30        for (i=0; i<nmax; i+=1) {
31                if (i==0) {
32                        out += x;
33                        continue;
34                }
35
36                power = pow(x,(2 * i + 1));
37                out += pow(-1.0, i) * power / ((2.0 * (double)i + 1.0) * (double)factorial(2 * i + 1));
38
39                //printf ("Si=%g %g %d\n", x, out, i);
40        }
41
42        return out;
43}
44
45int factorial(int f)
46{
47    if ( f == 0 ) 
48        return 1;
49    return(f * factorial(f - 1));
50}
Note: See TracBrowser for help on using the repository browser.