File Coverage

blib/lib/Number/Closest/XS.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Number::Closest::XS;
2 2     2   95179 use strict;
  2         4  
  2         49  
3 2     2   11 use warnings;
  2         2  
  2         143  
4             our $VERSION = "0.09";
5             my $XS_VERSION = $VERSION;
6             $VERSION = eval $VERSION;
7              
8             require XSLoader;
9             XSLoader::load( "Number::Closest::XS", $XS_VERSION );
10              
11 2     2   9 use base 'Exporter';
  2         7  
  2         263  
12             our @EXPORT_OK = qw(find_closest_numbers find_closest_numbers_around);
13             our %EXPORT_TAGS = (all => [@EXPORT_OK]);
14              
15             =head1 NAME
16              
17             Number::Closest::XS - find numbers closest to a given
18              
19             =head1 VERSION
20              
21             This document describes Number::Closest::XS version 0.09
22              
23             =head1 SYNOPSIS
24              
25             use Number::Closest::XS qw(:all);
26             my $res = find_closest_numbers($num, \@list, $amount);
27             my $res2 = find_closest_numbers_around($num, \@list, $amount);
28              
29             =head1 DESCRIPTION
30              
31             Module provides functions to extract from the list numbers closest to the
32             given.
33              
34             =head1 SUBROUTINES
35              
36             =head2 find_closest_numbers($num, \@list, [$amount])
37              
38             selects from the I<@list> up to I<$amount> numbers closest to the I<$num>. If
39             I<$amount> is not specified, is assumed to be 1. Returns reference to the
40             array containing found numbers sorted by the distance from the I<$num>. The
41             sort is stable, so the numbers that have the same distance to the C<$num> will
42             be present in the result in the same order as in the C<@list>.
43             Distance between C<$num> and C<$x> computed as C.
44              
45             =head2 find_closest_numbers_around($num, \@list, [$amount])
46              
47             selects from the I<@list> up to I<$amount> numbers closest to the I<$num>.
48             Tries to select equal amounts of numbers from both sides of the I<$num>, but if
49             there are not enough numbers from one side will select more numbers from the
50             other. If I<$amount> is odd, then the last number will be closest to I<$num>,
51             e.g. if $num is 5, @list is 1, 2, 6, 7, and amount is 3 it will return 2, 6,
52             and 7, because 7 is closer to 5 than 1. If I<$amount> is not specified, is
53             assumed to be 2. Returns reference to the array containing closest numbers
54             sorted by their values.
55              
56             =cut
57              
58             1;
59              
60             __END__