Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- continuedFraction :: (RealFrac a, Integral b) => a -> [b]
- collapseFraction :: (Integral a, Integral b) => NonEmpty b -> Ratio a
- approximate :: (RealFrac a, Integral b) => a -> b -> Ratio b
- convergent :: (RealFrac a, Integral b) => Int -> a -> Ratio b
- prettyFrac :: Show a => NonEmpty a -> String
- prettyFracM :: Show a => [a] -> Maybe String
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 Integer
s.
>>>
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