line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Scalar::Number - numeric aspects of scalars |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Scalar::Number qw(scalar_num_part); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$num = scalar_num_part($scalar); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Scalar::Number qw(sclnum_is_natint sclnum_is_float); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
if(sclnum_is_natint($value)) { ... |
14
|
|
|
|
|
|
|
if(sclnum_is_float($value)) { ... |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Scalar::Number qw(sclnum_val_cmp sclnum_id_cmp); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
@sorted_nums = sort { sclnum_val_cmp($a, $b) } @floats; |
19
|
|
|
|
|
|
|
@sorted_nums = sort { sclnum_id_cmp($a, $b) } @floats; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This module is about the numeric part of plain (string) Perl scalars. |
24
|
|
|
|
|
|
|
A scalar has a numeric value, which may be expressed in either the |
25
|
|
|
|
|
|
|
native integer type or the native floating point type. Many values |
26
|
|
|
|
|
|
|
are expressible both ways, in which case the exact representation is |
27
|
|
|
|
|
|
|
insignificant. To fully understand Perl arithmetic it is necessary to |
28
|
|
|
|
|
|
|
know about both of these representations, and the differing behaviours |
29
|
|
|
|
|
|
|
of numbers according to which way they are expressible. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
This module provides functions to extract the numeric part of a scalar, |
32
|
|
|
|
|
|
|
classify a number by expressibility, and compare numbers across |
33
|
|
|
|
|
|
|
representations. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This module is implemented in XS, with a pure Perl backup version for |
36
|
|
|
|
|
|
|
systems that can't handle XS. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
package Scalar::Number; |
41
|
|
|
|
|
|
|
|
42
|
6
|
|
|
6
|
|
441480
|
{ use 5.006; } |
|
6
|
|
|
|
|
25
|
|
43
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
166
|
|
44
|
6
|
|
|
6
|
|
30
|
use strict; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
236
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
our $VERSION = "0.007"; |
47
|
|
|
|
|
|
|
|
48
|
6
|
|
|
6
|
|
34
|
use parent "Exporter"; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
43
|
|
49
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
50
|
|
|
|
|
|
|
scalar_num_part |
51
|
|
|
|
|
|
|
sclnum_is_natint sclnum_is_float |
52
|
|
|
|
|
|
|
sclnum_val_cmp sclnum_id_cmp |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
eval { local $SIG{__DIE__}; |
56
|
|
|
|
|
|
|
require XSLoader; |
57
|
|
|
|
|
|
|
XSLoader::load(__PACKAGE__, $VERSION); |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
if($@ eq "") { |
61
|
|
|
|
|
|
|
close(DATA); |
62
|
|
|
|
|
|
|
*scalar_num_part = sub($) { |
63
|
6
|
|
|
6
|
|
884
|
no warnings qw(numeric uninitialized); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
750
|
|
64
|
65
|
|
|
65
|
|
114800
|
return _warnable_scalar_num_part($_[0]); |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
} else { |
67
|
|
|
|
|
|
|
local $/ = undef; |
68
|
|
|
|
|
|
|
my $pp_code = ; |
69
|
|
|
|
|
|
|
close(DATA); |
70
|
|
|
|
|
|
|
{ |
71
|
|
|
|
|
|
|
local $SIG{__DIE__}; |
72
|
3
|
50
|
100
|
3
|
1
|
15
|
eval $pp_code; |
|
3
|
0
|
66
|
3
|
1
|
5
|
|
|
3
|
50
|
100
|
3
|
1
|
182
|
|
|
3
|
100
|
100
|
3
|
1
|
13
|
|
|
3
|
100
|
100
|
3
|
1
|
47
|
|
|
3
|
100
|
100
|
3
|
|
409
|
|
|
3
|
50
|
100
|
3
|
|
18
|
|
|
3
|
100
|
100
|
3
|
|
38
|
|
|
3
|
100
|
66
|
3
|
|
226
|
|
|
3
|
100
|
66
|
3
|
|
17
|
|
|
3
|
100
|
|
3
|
|
7
|
|
|
3
|
100
|
|
3
|
|
154
|
|
|
3
|
100
|
|
3
|
|
14
|
|
|
0
|
100
|
|
0
|
|
0
|
|
|
3
|
100
|
|
65
|
|
200
|
|
|
3
|
100
|
|
5865
|
|
4
|
|
|
3
|
100
|
|
748
|
|
12
|
|
|
3
|
100
|
|
748
|
|
409
|
|
|
3
|
100
|
|
4336
|
|
5
|
|
|
3
|
100
|
|
|
|
129
|
|
|
3
|
100
|
|
|
|
15
|
|
|
3
|
100
|
|
|
|
5
|
|
|
3
|
100
|
|
|
|
491
|
|
|
3
|
100
|
|
|
|
10
|
|
|
3
|
50
|
|
|
|
14
|
|
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
164
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
440
|
|
|
3
|
|
|
|
|
38
|
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
116
|
|
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1080
|
|
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
639
|
|
|
0
|
|
|
|
|
0
|
|
|
65
|
|
|
|
|
73213
|
|
|
65
|
|
|
|
|
224
|
|
|
13
|
|
|
|
|
34
|
|
|
13
|
|
|
|
|
653
|
|
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
33
|
|
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
495
|
|
|
2
|
|
|
|
|
7
|
|
|
10
|
|
|
|
|
24
|
|
|
62
|
|
|
|
|
209
|
|
|
49
|
|
|
|
|
244
|
|
|
2
|
|
|
|
|
8
|
|
|
47
|
|
|
|
|
84
|
|
|
47
|
|
|
|
|
274
|
|
|
47
|
|
|
|
|
133
|
|
|
47
|
|
|
|
|
227
|
|
|
0
|
|
|
|
|
0
|
|
|
49
|
|
|
|
|
134
|
|
|
49
|
|
|
|
|
541
|
|
|
13
|
|
|
|
|
39
|
|
|
5865
|
|
|
|
|
6095988
|
|
|
5865
|
|
|
|
|
40144
|
|
|
160
|
|
|
|
|
966
|
|
|
156
|
|
|
|
|
801
|
|
|
1213
|
|
|
|
|
3276
|
|
|
1213
|
|
|
|
|
3343
|
|
|
1213
|
|
|
|
|
2917
|
|
|
1213
|
|
|
|
|
17626
|
|
|
4336
|
|
|
|
|
12463
|
|
|
748
|
|
|
|
|
2980
|
|
|
748
|
|
|
|
|
13806
|
|
|
42
|
|
|
|
|
70
|
|
|
42
|
|
|
|
|
88
|
|
|
42
|
|
|
|
|
344
|
|
|
166
|
|
|
|
|
1141
|
|
|
540
|
|
|
|
|
19536
|
|
|
250
|
|
|
|
|
711
|
|
|
212
|
|
|
|
|
5088
|
|
|
11
|
|
|
|
|
29
|
|
|
11
|
|
|
|
|
53
|
|
|
8
|
|
|
|
|
24
|
|
|
201
|
|
|
|
|
380
|
|
|
209
|
|
|
|
|
467
|
|
|
985
|
|
|
|
|
2084
|
|
|
898
|
|
|
|
|
1612
|
|
|
122
|
|
|
|
|
596
|
|
|
748
|
|
|
|
|
615056
|
|
|
748
|
|
|
|
|
3224
|
|
|
42
|
|
|
|
|
78
|
|
|
42
|
|
|
|
|
93
|
|
|
42
|
|
|
|
|
410
|
|
|
162
|
|
|
|
|
1062
|
|
|
544
|
|
|
|
|
1966
|
|
|
4336
|
|
|
|
|
10202
|
|
|
4336
|
|
|
|
|
7244
|
|
|
4336
|
|
|
|
|
8205
|
|
|
4336
|
|
|
|
|
8062
|
|
|
4336
|
|
|
|
|
8446
|
|
|
4336
|
|
|
|
|
31878
|
|
|
148
|
|
|
|
|
504
|
|
|
148
|
|
|
|
|
609
|
|
|
1628
|
|
|
|
|
8477
|
|
|
208
|
|
|
|
|
315
|
|
|
208
|
|
|
|
|
285
|
|
|
208
|
|
|
|
|
324
|
|
|
208
|
|
|
|
|
502
|
|
|
148
|
|
|
|
|
949
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
die $@ if $@ ne ""; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__DATA__ |