put the bigfloat stuff into its own file so we can use it everywhere wil less effort
[rersyncrecent.git] / lib / File / Rsync / Mirror / Recentfile / FakeBigFloat.pm
blob7542b12c7d1ea0e6416bb2916d653b9443c0db36
1 package File::Rsync::Mirror::Recentfile::FakeBigFloat;
3 # use warnings;
4 use strict;
6 # _bigfloat
7 sub _bigfloatcmp ($$);
8 sub _bigfloatgt ($$);
9 sub _bigfloatlt ($$);
10 sub _bigfloatmax ($$);
11 sub _bigfloatmin ($$);
13 =encoding utf-8
15 =head1 NAME
17 File::Rsync::Mirror::Recentfile::FakeBigFloat - very limited bigfloat support
19 =head1 VERSION
21 Version 0.0.1
23 =cut
25 use version; our $VERSION = qv('0.0.1');
27 use Exporter;
28 use base qw(Exporter);
29 our %EXPORT_TAGS;
30 our @EXPORT_OK = qw( _bigfloatcmp _bigfloatmin _bigfloatmax _bigfloatlt _bigfloatgt );
31 $EXPORT_TAGS{all} = \@EXPORT_OK;
33 =head1 SYNOPSIS
35 use File::Rsync::Mirror::Recentfile::FakeBigFloat qw(:all);
37 =head1 EXPORT
39 All functions are exported in the C<:all> tag.
41 =head1 (ONLY) INTERNAL FUNCTIONS
43 These functions are not part of a public interface and can be
44 changed and go away any time without prior notice.
46 =head2 _bigfloatcmp ( $l, $r )
48 Cmp function for floating point numbers that have a longer
49 mantissa than can be handled by native perl floats.
51 =cut
52 sub _bigfloatcmp ($$) {
53 my($l,$r) = @_;
54 my $native = $l <=> $r;
55 return $native if $native;
56 for ($l, $r){
57 $_ .= ".0" unless /\./;
59 $l =~ s/^/0/ while index($l,".") < index($r,".");
60 $r =~ s/^/0/ while index($r,".") < index($l,".");
61 $l cmp $r;
64 =head2 _bigfloatgt ( $l, $r )
66 Same for gt
68 =cut
69 sub _bigfloatgt ($$) {
70 my($l,$r) = @_;
71 _bigfloatcmp($l,$r) > 0;
74 =head2 _bigfloatlt ( $l, $r )
76 Same for lt
78 =cut
79 sub _bigfloatlt ($$) {
80 my($l,$r) = @_;
81 _bigfloatcmp($l,$r) < 0;
84 =head2 _bigfloatmax ( $l, $r )
86 Same for max (of two arguments)
88 =cut
89 sub _bigfloatmax ($$) {
90 my($l,$r) = @_;
91 return _bigfloatcmp($l,$r) >= 0 ? $l : $r;
94 =head2 _bigfloatmin ( $l, $r )
96 Same for min (of two arguments)
98 =cut
99 sub _bigfloatmin ($$) {
100 my($l,$r) = @_;
101 return _bigfloatcmp($l,$r) <= 0 ? $l : $r;
104 =head1 COPYRIGHT & LICENSE
106 Copyright 2008 Andreas König.
108 This program is free software; you can redistribute it and/or modify it
109 under the same terms as Perl itself.
111 =cut
113 1; # End of File::Rsync::Mirror::Recentfile
115 # Local Variables:
116 # mode: cperl
117 # cperl-indent-level: 4
118 # End: