line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#ifndef EASYXS_NUMERIC_H |
2
|
|
|
|
|
|
|
#define EASYXS_NUMERIC_H 1 |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#include "init.h" |
5
|
|
|
|
|
|
|
|
6
|
0
|
|
|
|
|
|
UV _easyxs_SvUV (pTHX_ SV* sv) { |
7
|
0
|
0
|
|
|
|
|
if (!SvOK(sv)) _EASYXS_CROAK_UNDEF("unsigned integer"); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
0
|
0
|
|
|
|
|
if (SvROK(sv)) _EASYXS_CROAK_STRINGIFY_REFERENCE(sv); |
10
|
|
|
|
|
|
|
|
11
|
0
|
0
|
|
|
|
|
if (SvUOK(sv)) return SvUV(sv); |
|
|
0
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
0
|
0
|
|
|
|
|
if (SvIOK(sv)) { |
14
|
0
|
0
|
|
|
|
|
IV myiv = SvIV(sv); |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
if (myiv >= 0) return myiv; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
else { |
19
|
|
|
|
|
|
|
STRLEN pvlen; |
20
|
0
|
0
|
|
|
|
|
const char* pv = SvPVbyte(sv, pvlen); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
UV myuv; |
23
|
0
|
|
|
|
|
|
int grokked = grok_number(pv, pvlen, &myuv); |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
if (grokked & (IS_NUMBER_IN_UV | !IS_NUMBER_NEG)) { |
26
|
0
|
|
|
|
|
|
const char* uvstr = form("%" UVuf, myuv); |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
if (strlen(uvstr) == pvlen && strEQ(uvstr, pv)) return myuv; |
|
|
0
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
croak("`%" SVf "` given where unsigned integer expected!", sv); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#define exs_SvUV(sv) _easyxs_SvUV(aTHX_ sv) |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
UV _easyxs_SvIV (pTHX_ SV* sv) { |
38
|
0
|
0
|
|
|
|
|
if (!SvOK(sv)) _EASYXS_CROAK_UNDEF("integer"); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if (SvROK(sv)) _EASYXS_CROAK_STRINGIFY_REFERENCE(sv); |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
if (SvIOK(sv)) return SvIV(sv); |
|
|
0
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
STRLEN pvlen; |
45
|
0
|
0
|
|
|
|
|
const char* pv = SvPVbyte(sv, pvlen); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
IV myiv; |
48
|
0
|
|
|
|
|
|
int grokked = grok_number(pv, pvlen, (UV*) &myiv); |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
if (!(grokked & IS_NUMBER_NOT_INT) && !(grokked & IS_NUMBER_IN_UV)) { |
|
|
0
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
const char* ivstr = form("%" IVdf, myiv); |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
if (strlen(ivstr) == pvlen && strEQ(ivstr, pv)) return myiv; |
|
|
0
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
croak("`%" SVf "` given where integer expected!", sv); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#define exs_SvIV(sv) _easyxs_SvIV(aTHX_ sv) |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#endif |