numeric-prelude-0.0.2: An experimental alternative hierarchy of numeric type classesSource codeContentsIndex
class (C a, C a) => C a where
splitFraction :: C b => a -> (b, a)
fraction :: a -> a
ceiling :: C b => a -> b
floor :: C b => a -> b
truncate :: C b => a -> b
round :: C b => a -> b
preludeSplitFraction :: (RealFrac a, C a, C b) => a -> (b, a)
preludeFraction :: (RealFrac a, C a) => a -> a
fractionTrunc :: (C a, Ord a) => (a -> a) -> a -> a
fixFraction :: (C a, Ord a) => a -> a
approxRational :: (C a, C a) => a -> a -> Rational
class (C a, C a) => C a whereSource

Minimal complete definition: splitFraction or floor

There are probably more laws, but some laws are

 (fromInteger.fst.splitFraction) a + (snd.splitFraction) a === a
    ceiling (toRational x) === ceiling x :: Integer
   truncate (toRational x) === truncate x :: Integer
      floor (toRational x) === floor x :: Integer

If there wouldn't be Real.C a and ToInteger.C b constraints, we could also use this class for splitting ratios of polynomials.

As an aside, let me note the similarities between splitFraction x and x divMod 1 (if that were defined). In particular, it might make sense to unify the rounding modes somehow.

IEEEFloat-specific calls are removed here (cf. Prelude.RealFloat) so probably nobody will actually use this default definition.

Henning: New function fraction doesn't return the integer part of the number. This also removes a type ambiguity if the integer part is not needed.

The new methods fraction and splitFraction differ from Prelude.properFraction semantics. They always round to floor. This means that the fraction is always non-negative and is always smaller than 1. This is more useful in practice and can be generalised to more than real numbers. Since every T denominator type supports divMod, every T can provide fraction and splitFraction, e.g. fractions of polynomials. However the ''integral'' part would not be of type class C.

Can there be a separate class for fraction, splitFraction, floor and ceiling since they do not need reals and their ordering?

splitFraction :: C b => a -> (b, a)Source
fraction :: a -> aSource
ceiling :: C b => a -> bSource
floor :: C b => a -> bSource
truncate :: C b => a -> bSource
round :: C b => a -> bSource
show/hide Instances
C Double
C Float
C a => C (T a)
(C a, C a) => C (T a)
preludeSplitFraction :: (RealFrac a, C a, C b) => a -> (b, a)Source
preludeFraction :: (RealFrac a, C a) => a -> aSource
fractionTrunc :: (C a, Ord a) => (a -> a) -> a -> aSource
fixFraction :: (C a, Ord a) => a -> aSource
approxRational :: (C a, C a) => a -> a -> RationalSource
TODO: Should be moved to a continued fraction module.
Produced by Haddock version 2.6.0