numeric-prelude-0.4.3: An experimental alternative hierarchy of numeric type classes

Safe HaskellNone
LanguageHaskell98

Algebra.ToRational

Synopsis

Documentation

class (C a, C a, Ord a) => C a where #

This class allows lossless conversion from any representation of a rational to the fixed Rational type. "Lossless" means - don't do any rounding. For rounding see Algebra.RealRing. With the instances for Float and Double we acknowledge that these types actually represent rationals rather than (approximated) real numbers. However, this contradicts to the Transcendental class.

Laws that must be satisfied by instances:

 fromRational' . toRational === id

Minimal complete definition

toRational

Methods

toRational :: a -> Rational #

Lossless conversion from any representation of a rational to Rational

Instances

C Double # 
C Float # 

Methods

toRational :: Float -> Rational #

C Int # 

Methods

toRational :: Int -> Rational #

C Int8 # 

Methods

toRational :: Int8 -> Rational #

C Int16 # 

Methods

toRational :: Int16 -> Rational #

C Int32 # 

Methods

toRational :: Int32 -> Rational #

C Int64 # 

Methods

toRational :: Int64 -> Rational #

C Integer # 
C Word # 

Methods

toRational :: Word -> Rational #

C Word8 # 

Methods

toRational :: Word8 -> Rational #

C Word16 # 
C Word32 # 
C Word64 # 
C T # 

Methods

toRational :: T -> Rational #

Real a => C (T a) # 

Methods

toRational :: T a -> Rational #

(C a, C a) => C (T a) # 

Methods

toRational :: T a -> Rational #

C a => C (T a) # 

Methods

toRational :: T a -> Rational #

realToField :: (C a, C b) => a -> b #

It should hold

realToField = fromRational' . toRational

but it should be much more efficient for particular pairs of types, such as converting Float to Double. This achieved by optimizer rules.