line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Prime::XS; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
40883
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
158
|
|
4
|
4
|
|
|
4
|
|
23
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
124
|
|
5
|
4
|
|
|
4
|
|
21
|
use base qw(Exporter); |
|
4
|
|
|
|
|
20
|
|
|
4
|
|
|
|
|
559
|
|
6
|
4
|
|
|
4
|
|
2492
|
use boolean qw(true false); |
|
4
|
|
|
|
|
11372
|
|
|
4
|
|
|
|
|
22
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
368
|
use Carp qw(croak); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
234
|
|
9
|
4
|
|
|
4
|
|
4220
|
use Params::Validate ':all'; |
|
4
|
|
|
|
|
55905
|
|
|
4
|
|
|
|
|
1042
|
|
10
|
4
|
|
|
4
|
|
42
|
use Scalar::Util qw(looks_like_number); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
8784
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our ($VERSION, @EXPORT_OK, %EXPORT_TAGS); |
13
|
|
|
|
|
|
|
my @subs; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$VERSION = '0.26_01'; |
16
|
|
|
|
|
|
|
@subs = qw(is_prime primes count_primes |
17
|
|
|
|
|
|
|
mod_primes sieve_primes sum_primes trial_primes); |
18
|
|
|
|
|
|
|
@EXPORT_OK = @subs; |
19
|
|
|
|
|
|
|
%EXPORT_TAGS = ('all' => [ @subs ]); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
validation_options( |
22
|
|
|
|
|
|
|
on_fail => sub |
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
my ($error) = @_; |
25
|
|
|
|
|
|
|
chomp $error; |
26
|
|
|
|
|
|
|
croak $error; |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
stack_skip => 2, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
*primes = \&sieve_primes; |
32
|
2
|
100
|
|
2
|
1
|
8
|
sub count_primes { _validate(@_); @_ == 1 ? xs_sieve_count_primes($_[0], 2) : xs_sieve_count_primes(reverse @_) } |
|
2
|
|
|
|
|
24
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Reverse arguments for xs_*_primes() when both base and number are specified |
35
|
5
|
100
|
|
5
|
1
|
128463
|
sub mod_primes { _validate(@_); @_ == 1 ? xs_mod_primes ($_[0], 2) : xs_mod_primes (reverse @_) } |
|
5
|
|
|
|
|
53
|
|
36
|
8
|
100
|
|
8
|
1
|
14953
|
sub sieve_primes { _validate(@_); @_ == 1 ? xs_sieve_primes($_[0], 2) : xs_sieve_primes(reverse @_) } |
|
8
|
|
|
|
|
35726
|
|
37
|
3
|
100
|
|
3
|
1
|
12
|
sub sum_primes { _validate(@_); @_ == 1 ? xs_sum_primes ($_[0], 2) : xs_sum_primes (reverse @_) } |
|
3
|
|
|
|
|
57
|
|
38
|
3
|
100
|
|
3
|
1
|
10
|
sub trial_primes { _validate(@_); @_ == 1 ? xs_trial_primes($_[0], 2) : xs_trial_primes(reverse @_) } |
|
3
|
|
|
|
|
42
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _validate |
41
|
|
|
|
|
|
|
{ |
42
|
34
|
50
|
|
34
|
|
907
|
my $positive_num = sub { looks_like_number($_[0]) && $_[0] >= 0 }; |
|
21
|
|
|
21
|
|
97
|
|
43
|
|
|
|
|
|
|
|
44
|
21
|
|
|
|
|
139
|
validate_pos(@_, |
45
|
|
|
|
|
|
|
{ type => SCALAR, |
46
|
|
|
|
|
|
|
callbacks => { |
47
|
|
|
|
|
|
|
'is a positive number' => $positive_num, |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
}, |
50
|
|
|
|
|
|
|
{ type => SCALAR, |
51
|
|
|
|
|
|
|
optional => true, |
52
|
|
|
|
|
|
|
callbacks => { |
53
|
|
|
|
|
|
|
'is a positive number' => $positive_num, |
54
|
|
|
|
|
|
|
}, |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
); |
57
|
21
|
100
|
|
|
|
185
|
if (@_ == 2) { |
58
|
13
|
|
|
|
|
25
|
my ($base, $number) = @_; |
59
|
13
|
50
|
|
|
|
71
|
croak 'Base is greater than the number' if $base > $number; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
require XSLoader; |
64
|
|
|
|
|
|
|
XSLoader::load(__PACKAGE__, $VERSION); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
__END__ |