continued-fraction-0.1.0.0: Types and functions for working with continued fractions in Haskell

Safe HaskellSafe
LanguageHaskell2010

Num.ContinuedFraction

Contents

Synopsis

Conversion between numbers and continued fractions

continuedFraction :: (RealFrac a, Integral b) => a -> [b] Source #

This take a number and returns its continued fraction expansion as a list of Integers.

>>> continuedFraction 2
[2]

collapseFraction :: (Integral a, Integral b) => NonEmpty b -> Ratio a Source #

Take a non-empty list of integers and return the corresponding rational number.

>>> collapseFraction (1 :| [2,2,2])
17 % 12

Rational approximations using continued fractions

approximate :: (RealFrac a, Integral b) => a -> b -> Ratio b Source #

Find the best rational approximation to a number such that the denominator is bounded by a given value.

>>> approximate pi 100
22 % 7

convergent :: (RealFrac a, Integral b) => Int -> a -> Ratio b Source #

Find a given convergent of the continued fraction expansion of a number

>>> convergent 4 $ sqrt 2
17 % 12