Diab Jerius
and 1 contributors

NAME

Math::Rational::Approx::ContFrac - Rational number approximation via continued fractions

SYNOPSIS

``````    use Math::Rational::Approx::ContFrac;

\$x = Math::Rational::Approx::ContFrac->new( x => 1.234871035, n => 10 );
( \$n, \$d ) = \$x->approx;
# continue for an additonal number of steps
( \$n, \$d ) = \$x->approx( 3 );``````

DESCRIPTION

This module is an object oriented front end to the Math::Rational::Approx::contfrac function

INTERFACE

new
``  \$obj = Math::Rational::ContFrac->new( %attr );``

Construct an object which will maintain state for the continued fraction. The following attributes are available:

x

The number to approximate. It must be positive.

n

The number of terms to generate. This may be augmented in calls to the approx method.

approx
``````  ( \$n, \$d ) = \$obj->approx;
( \$n, \$d ) = \$obj->approx(\$n);``````

Calculate the continued fractions and return the associated nominator and denominator. If `\$n` is not specified, the number of terms generated is that specified in the call to the constructor, plus any terms requested by additional calls to approx with `\$n` specified.

`\$n` specifies the number of additional terms to generate beyond what has already been requested.

x
``  \$x = \$obj->x;``

The original number to be approximated.

n
``  \$n = \$obj->n;``

The number of terms generated.

terms
``  \$arrayref = \$obj->terms``

Returns an arrayref of the current terms.

resid

The residual of the input number as a Math::BigFloat object. This is not the difference between the input number and the rational approximation.

DEPENDENCIES

Math::BigFloat, Moo, MooX::Types::MooseLike::Numeric, Params::Validate

None reported.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to `bug-math-rational-approx-contfrac@rt.cpan.org`, or through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=Math-Rational-Approx.

AUTHOR

Diab Jerius <djerius@cpan.org>