| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CXC::Number::Types; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Type::Tiny types for CXC::Number |
|
4
|
|
|
|
|
|
|
|
|
5
|
26
|
|
|
26
|
|
191724
|
use v5.28; |
|
|
26
|
|
|
|
|
140
|
|
|
6
|
26
|
|
|
26
|
|
173
|
use strict; |
|
|
26
|
|
|
|
|
49
|
|
|
|
26
|
|
|
|
|
704
|
|
|
7
|
26
|
|
|
26
|
|
138
|
use warnings; |
|
|
26
|
|
|
|
|
69
|
|
|
|
26
|
|
|
|
|
2095
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
26
|
|
|
26
|
|
1464
|
use Math::BigInt upgrade => 'Math::BigFloat'; |
|
|
26
|
|
|
|
|
34582
|
|
|
|
26
|
|
|
|
|
326
|
|
|
12
|
26
|
|
|
26
|
|
27168
|
use Math::BigFloat; |
|
|
26
|
|
|
|
|
33673
|
|
|
|
26
|
|
|
|
|
240
|
|
|
13
|
26
|
|
|
26
|
|
3659
|
use Type::Utils; |
|
|
26
|
|
|
|
|
65544
|
|
|
|
26
|
|
|
|
|
201
|
|
|
14
|
26
|
|
|
26
|
|
50847
|
use Types::Standard qw[ Num Int InstanceOf ]; |
|
|
26
|
|
|
|
|
94593
|
|
|
|
26
|
|
|
|
|
204
|
|
|
15
|
26
|
|
|
26
|
|
85800
|
use Types::Common::Numeric qw[ PositiveNum PositiveOrZeroNum PositiveInt ]; |
|
|
26
|
|
|
|
|
22562
|
|
|
|
26
|
|
|
|
|
234
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
26
|
|
|
|
|
212
|
use Type::Library -base, -declare => qw( |
|
18
|
|
|
|
|
|
|
BigInt |
|
19
|
|
|
|
|
|
|
BigNum |
|
20
|
|
|
|
|
|
|
BigPositiveInt |
|
21
|
|
|
|
|
|
|
BigPositiveNum |
|
22
|
|
|
|
|
|
|
BigPositiveOrZeroNum |
|
23
|
26
|
|
|
26
|
|
34159
|
); |
|
|
26
|
|
|
|
|
82
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
class_type BigNum, |
|
30
|
|
|
|
|
|
|
{ |
|
31
|
|
|
|
|
|
|
class => 'Math::BigFloat', |
|
32
|
|
|
|
|
|
|
message { 'Not a number or a Math::BigFloat' }, |
|
33
|
|
|
|
|
|
|
}; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
coerce BigNum, from Num, via { |
|
36
|
|
|
|
|
|
|
my $bignum = Math::BigFloat->new( $_ ); |
|
37
|
|
|
|
|
|
|
$bignum->is_nan ? $_ : $bignum; |
|
38
|
|
|
|
|
|
|
}; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
declare BigPositiveNum, as BigNum, |
|
45
|
|
|
|
|
|
|
where { $_ > 0 }, |
|
46
|
|
|
|
|
|
|
message { BigNum->validate( $_ ) or "$_ is not greater than zero" }, |
|
47
|
|
|
|
|
|
|
coercion => 1; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
coerce BigPositiveNum, from PositiveNum, via { Math::BigFloat->new( $_ ) }; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
declare BigPositiveOrZeroNum, as BigNum, where { $_ >= 0 }, message { |
|
56
|
|
|
|
|
|
|
BigNum->validate( $_ ) |
|
57
|
|
|
|
|
|
|
or "$_ is not greater than or equal to zero" |
|
58
|
|
|
|
|
|
|
}, coercion => 1; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
coerce BigPositiveOrZeroNum, from PositiveOrZeroNum, via { Math::BigFloat->new( $_ ) }; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
declare BigInt, as( InstanceOf ['Math::BigInt'] | InstanceOf ['Math::BigFloat'] ), |
|
71
|
|
|
|
|
|
|
where { $_->is_int() }, message { |
|
72
|
|
|
|
|
|
|
'Not an integer or a Math::BigInt' |
|
73
|
|
|
|
|
|
|
}; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
coerce BigInt, from Int, via { |
|
76
|
|
|
|
|
|
|
Math::BigInt->new( $_ ); |
|
77
|
|
|
|
|
|
|
}; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
declare BigPositiveInt, as BigInt, |
|
86
|
|
|
|
|
|
|
where { $_ > 0 }, |
|
87
|
|
|
|
|
|
|
message { BigInt->validate( $_ ) or "$_ is not greater than zero" }, |
|
88
|
|
|
|
|
|
|
coercion => 1; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
coerce BigPositiveInt, from PositiveInt, via { Math::BigFloat->new( $_ ) }; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# |
|
94
|
|
|
|
|
|
|
# This file is part of CXC-Number |
|
95
|
|
|
|
|
|
|
# |
|
96
|
|
|
|
|
|
|
# This software is Copyright (c) 2019 by Smithsonian Astrophysical Observatory. |
|
97
|
|
|
|
|
|
|
# |
|
98
|
|
|
|
|
|
|
# This is free software, licensed under: |
|
99
|
|
|
|
|
|
|
# |
|
100
|
|
|
|
|
|
|
# The GNU General Public License, Version 3, June 2007 |
|
101
|
|
|
|
|
|
|
# |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=pod |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=for :stopwords Diab Jerius Smithsonian Astrophysical Observatory BigInt BigNum |
|
110
|
|
|
|
|
|
|
BigPositiveInt BigPositiveNum BigPositiveOrZeroNum BigPositiveZeroNum |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 NAME |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
CXC::Number::Types - Type::Tiny types for CXC::Number |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 VERSION |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
version 0.13 |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 TYPES |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 BigNum |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 BigPositiveNum |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 BigPositiveZeroNum |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 BigPositiveOrZeroNum |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 BigInt |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 BigPositiveInt |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
A BigInt > 0. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 INTERNALS |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 SUPPORT |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 Bugs |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Please report any bugs or feature requests to bug-cxc-number@rt.cpan.org or through the web interface at: L<https://rt.cpan.org/Public/Dist/Display.html?Name=CXC-Number> |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 Source |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Source is available at |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
https://gitlab.com/djerius/cxc-number |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
and may be cloned from |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
https://gitlab.com/djerius/cxc-number.git |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Please see those modules/websites for more information related to this module. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=over 4 |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L<CXC::Number|CXC::Number> |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=back |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 AUTHOR |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Diab Jerius <djerius@cpan.org> |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
This software is Copyright (c) 2019 by Smithsonian Astrophysical Observatory. |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
This is free software, licensed under: |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
The GNU General Public License, Version 3, June 2007 |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |