line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#define PERL_NO_GET_CONTEXT /* we want efficiency */ |
2
|
|
|
|
|
|
|
#include "EXTERN.h" |
3
|
|
|
|
|
|
|
#include "perl.h" |
4
|
|
|
|
|
|
|
#include "XSUB.h" |
5
|
|
|
|
|
|
|
#include "ppport.h" |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#include |
8
|
|
|
|
|
|
|
|
9
|
23
|
|
|
|
|
|
static int sum_value(pTHX_ double* sum, double* correction, SV* value) |
10
|
|
|
|
|
|
|
{ |
11
|
23
|
|
|
|
|
|
double term = 0.0; |
12
|
23
|
|
|
|
|
|
double new_sum = 0.0; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
do { |
15
|
23
|
100
|
|
|
|
|
if (SvIOK(value)) { |
16
|
11
|
50
|
|
|
|
|
term = SvIV(value); |
17
|
11
|
|
|
|
|
|
break; |
18
|
|
|
|
|
|
|
} |
19
|
12
|
100
|
|
|
|
|
if (SvNOK(value)) { |
20
|
10
|
50
|
|
|
|
|
term = SvNV(value); |
21
|
10
|
|
|
|
|
|
break; |
22
|
|
|
|
|
|
|
} |
23
|
2
|
50
|
|
|
|
|
if (SvROK(value)) { |
24
|
2
|
|
|
|
|
|
SV* ref = SvRV(value); |
25
|
2
|
50
|
|
|
|
|
if (SvTYPE(ref) == SVt_PVAV) { |
26
|
2
|
|
|
|
|
|
int j = 0; |
27
|
2
|
|
|
|
|
|
AV* data = (AV*) ref; |
28
|
2
|
|
|
|
|
|
int top = av_top_index(data) + 1; |
29
|
7
|
100
|
|
|
|
|
for (j = 0; j < top; ++j) { |
30
|
5
|
|
|
|
|
|
SV** elem = av_fetch(data, j, 0); |
31
|
5
|
50
|
|
|
|
|
if (!elem || !*elem) { |
|
|
50
|
|
|
|
|
|
32
|
|
|
|
|
|
|
break; // could not get element |
33
|
|
|
|
|
|
|
} |
34
|
5
|
|
|
|
|
|
sum_value(aTHX_ sum, correction, *elem); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
2
|
|
|
|
|
|
break; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
croak("Cannot handle parameter"); |
41
|
|
|
|
|
|
|
return 0; |
42
|
|
|
|
|
|
|
} while (0); |
43
|
|
|
|
|
|
|
|
44
|
23
|
|
|
|
|
|
new_sum = *sum + term; |
45
|
23
|
100
|
|
|
|
|
if (fabs(*sum) >= fabs(term)) { |
46
|
14
|
|
|
|
|
|
*correction += (*sum - new_sum) + term; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
9
|
|
|
|
|
|
*correction += (term - new_sum) + *sum; |
50
|
|
|
|
|
|
|
} |
51
|
23
|
|
|
|
|
|
*sum = new_sum; |
52
|
23
|
|
|
|
|
|
return 1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
MODULE = Math::Utils::XS PACKAGE = Math::Utils::XS |
56
|
|
|
|
|
|
|
PROTOTYPES: DISABLE |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
################################################################# |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
double |
61
|
|
|
|
|
|
|
log10(double n) |
62
|
|
|
|
|
|
|
CODE: |
63
|
4
|
|
|
|
|
|
RETVAL = log10(n); |
64
|
|
|
|
|
|
|
OUTPUT: RETVAL |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
double |
67
|
|
|
|
|
|
|
log2(double n) |
68
|
|
|
|
|
|
|
CODE: |
69
|
5
|
|
|
|
|
|
RETVAL = log2(n); |
70
|
|
|
|
|
|
|
OUTPUT: RETVAL |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
double |
73
|
|
|
|
|
|
|
floor(double n) |
74
|
|
|
|
|
|
|
CODE: |
75
|
9
|
|
|
|
|
|
RETVAL = floor(n); |
76
|
|
|
|
|
|
|
OUTPUT: RETVAL |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
double |
79
|
|
|
|
|
|
|
ceil(double n) |
80
|
|
|
|
|
|
|
CODE: |
81
|
9
|
|
|
|
|
|
RETVAL = ceil(n); |
82
|
|
|
|
|
|
|
OUTPUT: RETVAL |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
int |
85
|
|
|
|
|
|
|
sign(double n) |
86
|
|
|
|
|
|
|
CODE: |
87
|
7
|
|
|
|
|
|
RETVAL = n < 0 ? -1 |
88
|
7
|
100
|
|
|
|
|
: n > 0 ? +1 |
89
|
4
|
|
|
|
|
|
: 0; |
90
|
|
|
|
|
|
|
OUTPUT: RETVAL |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
double |
93
|
|
|
|
|
|
|
fsum(...) |
94
|
|
|
|
|
|
|
PREINIT: |
95
|
5
|
|
|
|
|
|
double sum = 0.0; |
96
|
5
|
|
|
|
|
|
double correction = 0.0; |
97
|
5
|
|
|
|
|
|
int j = 0; |
98
|
|
|
|
|
|
|
CODE: |
99
|
23
|
100
|
|
|
|
|
for (j = 0; j < items; ++j) { |
100
|
18
|
|
|
|
|
|
sum_value(aTHX_ &sum, &correction, ST(j)); |
101
|
|
|
|
|
|
|
} |
102
|
5
|
|
|
|
|
|
RETVAL = sum + correction; |
103
|
|
|
|
|
|
|
OUTPUT: RETVAL |