| 1 | package Algorithm::AM::BigInt; | ||||||||||||||||||||
| 2 | 10 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 10 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 10 | our $VERSION = '3.13'; | |||||||||||||||||||
| 5 | # ABSTRACT: Helper functions for AM big integers | ||||||||||||||||||||
| 6 | 10 | ▶ | use Exporter::Easy ( | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 10 | OK => ['bigcmp'] | |||||||||||||||||||
| 8 | 10 | ); | |||||||||||||||||||
| 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<printf>, 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<bigcmp> | ||||||||||||||||||||
| 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 | 556 | ▶ | sub bigcmp { | ||||||||||||||||||
|
Subroutine
bigcmp: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 57 | 556 | my($a,$b) = @_; | |||||||||||||||||||
| 58 | 556 | ▶ | return (length($a) <=> length($b)) || ($a cmp $b); | ||||||||||||||||||
|
Condition100%3/3
length $a <=> length $b || $a cmp $b
MC/DC100%2/2
length $a <=> length $b || $a cmp $b
length $a <=> length $b
$a cmp $b
Truth table100%3/3
A || B
A= length $a <=> length $bB= $a cmp $b
| |||||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 10 | 1; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||