Math::Rational::Approx::MaxD - approximate a number with a rational number up to a given denominator
use Math::Rational::Approx::MaxD; # approximate up to denominator of 10 $rat = Math::Rational::Approx::MaxD->new( x => $x, maxD => 10 ); ($n, $d ) = $rat->approx; # approximate up to denominator of 20 ($n, $d ) = $rat->approx( 20 );
This module is an object oriented front end to the Math::Rational::Approx::maxd function
$obj = Math::Rational::Approx::MaxD->new( %attr );
Create a new object. The following attributes are available
The number to approximate.
The limiting maximum denominator to check;
Optional. A reference to a four element array containing the initial bounds on the region to search. It takes the form
bounds => [ a, b, c, d ]
where the elements are all non-negative integers and the bounds are given by
a/b < x < c/d
By default it searches from
( $n, $d ) = $obj->approx; ( $n, $d ) = $obj->approx( $maxD );
Return the nominator and denominator for a given maximum value of the denominator. If
$maxD is not specified it is that specified in the call to the constructor or in any subsequent call to approx. New values of
$maxD less than one already specified are ignored.
$bounds = $obj->bounds;
Return an arrayref which contains the current bounds on the search, in the same format as the
bounds attribute passed to new.
$x = $obj->x;
The original number to be approximated.
The current value of the maximum denominator.
No bugs have been reported.
Please report any bugs or feature requests to
firstname.lastname@example.org, or through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=Math-Rational-Approx.
Diab Jerius <email@example.com>
Copyright (c) 2012 The Smithsonian Astrophysical Observatory
Math::Rational::Approx is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.