| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Algorithm::AM::BigInt; |
|
2
|
10
|
|
|
10
|
|
32
|
use strict; |
|
|
10
|
|
|
|
|
10
|
|
|
|
10
|
|
|
|
|
207
|
|
|
3
|
10
|
|
|
10
|
|
28
|
use warnings; |
|
|
10
|
|
|
|
|
8
|
|
|
|
10
|
|
|
|
|
316
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '3.10'; |
|
5
|
|
|
|
|
|
|
# ABSTRACT: Helper functions for AM big integers |
|
6
|
|
|
|
|
|
|
use Exporter::Easy ( |
|
7
|
10
|
|
|
|
|
51
|
OK => ['bigcmp'] |
|
8
|
10
|
|
|
10
|
|
3272
|
); |
|
|
10
|
|
|
|
|
8300
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
|
11
|
|
|
|
|
|
|
#pod |
|
12
|
|
|
|
|
|
|
#pod use Algorithm::AM::BigInt 'bigcmp'; |
|
13
|
|
|
|
|
|
|
#pod # get some big integers from Algorithm::AM::Result |
|
14
|
|
|
|
|
|
|
#pod my ($a, $b); |
|
15
|
|
|
|
|
|
|
#pod bigcmp($a, $b); |
|
16
|
|
|
|
|
|
|
#pod |
|
17
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
|
18
|
|
|
|
|
|
|
#pod |
|
19
|
|
|
|
|
|
|
#pod AM uses custom 128-bit unsigned integers in its XS code, and these |
|
20
|
|
|
|
|
|
|
#pod numbers cannot be treated normally in Perl code. This package provides |
|
21
|
|
|
|
|
|
|
#pod some helper functions for working with these numbers. |
|
22
|
|
|
|
|
|
|
#pod |
|
23
|
|
|
|
|
|
|
#pod =head2 DETAILS |
|
24
|
|
|
|
|
|
|
#pod |
|
25
|
|
|
|
|
|
|
#pod Under the hood, the big integers used by AM are scalars with the |
|
26
|
|
|
|
|
|
|
#pod following fields: |
|
27
|
|
|
|
|
|
|
#pod |
|
28
|
|
|
|
|
|
|
#pod =over |
|
29
|
|
|
|
|
|
|
#pod |
|
30
|
|
|
|
|
|
|
#pod =item NV |
|
31
|
|
|
|
|
|
|
#pod |
|
32
|
|
|
|
|
|
|
#pod This is an inexact double representation of the integer value. |
|
33
|
|
|
|
|
|
|
#pod |
|
34
|
|
|
|
|
|
|
#pod =item PV |
|
35
|
|
|
|
|
|
|
#pod |
|
36
|
|
|
|
|
|
|
#pod This is an exact string representation of the integer value. |
|
37
|
|
|
|
|
|
|
#pod |
|
38
|
|
|
|
|
|
|
#pod =back |
|
39
|
|
|
|
|
|
|
#pod |
|
40
|
|
|
|
|
|
|
#pod Operations on the floating-point representation will necessarily have a |
|
41
|
|
|
|
|
|
|
#pod small amount of error, so exact calculation or comparison requires |
|
42
|
|
|
|
|
|
|
#pod referencing the string field. The number field is still useful in |
|
43
|
|
|
|
|
|
|
#pod printing reports; for example, using C, where precision can |
|
44
|
|
|
|
|
|
|
#pod be specified. |
|
45
|
|
|
|
|
|
|
#pod |
|
46
|
|
|
|
|
|
|
#pod Currently, the only provided helper function is for comparison of |
|
47
|
|
|
|
|
|
|
#pod two big integers. |
|
48
|
|
|
|
|
|
|
#pod |
|
49
|
|
|
|
|
|
|
#pod =head2 C |
|
50
|
|
|
|
|
|
|
#pod |
|
51
|
|
|
|
|
|
|
#pod Compares two big integers, returning 1, 0, or -1 depending on whether |
|
52
|
|
|
|
|
|
|
#pod the first argument is greater than, equal to, or less than the second |
|
53
|
|
|
|
|
|
|
#pod argument. |
|
54
|
|
|
|
|
|
|
#pod |
|
55
|
|
|
|
|
|
|
#pod =cut |
|
56
|
|
|
|
|
|
|
sub bigcmp { |
|
57
|
559
|
|
|
559
|
1
|
1075
|
my($a,$b) = @_; |
|
58
|
559
|
|
100
|
|
|
1795
|
return (length($a) <=> length($b)) || ($a cmp $b); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |