| Copyright | Copyright (c) 2007--2021 wren gayle romano |
|---|---|
| License | BSD3 |
| Maintainer | wren@cpan.org |
| Stability | stable |
| Portability | semi-portable (CPP, MPTC, OverlappingInstances) |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Data.Number.RealToFrac
Description
This module presents a type class for generic conversion between numeric types, generalizing realToFrac in order to overcome problems with pivoting through Rational
Synopsis
- class (Real a, Fractional b) => RealToFrac a b where
- realToFrac :: a -> b
Documentation
class (Real a, Fractional b) => RealToFrac a b where Source #
The realToFrac function is defined to pivot through a Rational according to the haskell98 spec. This is non-portable and problematic as discussed in Data.Number.Transfinite. Since there is resistance to breaking from the spec, this class defines a reasonable variant which deals with transfinite values appropriately.
There is a generic instance from any Transfinite Real to any Transfinite Fractional, using checks to ensure correctness. GHC has specialized versions for some types which use primitive converters instead, for large performance gains. (These definitions are hidden from other compilers via CPP.) Due to a bug in Haddock the specialized instances are shown twice and the generic instance isn't shown at all. Since the instances are overlapped, you'll need to give type signatures if the arguments to realToFrac are polymorphic. There's also a generic instance for any Real Fractional type to itself, thus if you write any generic instances beware of incoherence.
If any of these restrictions (CPP, GHC-only optimizations, OverlappingInstances) are onerous to you, contact the maintainer (we like patches). Note that this does work for Hugs with suitable options (e.g. hugs -98 +o -F'cpp -P'). However, Hugs doesn't allow IncoherentInstances nor does it allow diamonds with OverlappingInstances, which restricts the ability to add additional generic instances.
Methods
realToFrac :: a -> b Source #
Instances
| RealToFrac Integer Double Source # | |
Defined in Data.Number.RealToFrac Methods realToFrac :: Integer -> Double Source # | |
| RealToFrac Integer Float Source # | |
Defined in Data.Number.RealToFrac Methods realToFrac :: Integer -> Float Source # | |
| RealToFrac Double Float Source # | |
Defined in Data.Number.RealToFrac Methods realToFrac :: Double -> Float Source # | |
| RealToFrac Float Double Source # | |
Defined in Data.Number.RealToFrac Methods realToFrac :: Float -> Double Source # | |
| RealToFrac Int Double Source # | |
Defined in Data.Number.RealToFrac Methods realToFrac :: Int -> Double Source # | |
| RealToFrac Int Float Source # | |
Defined in Data.Number.RealToFrac Methods realToFrac :: Int -> Float Source # | |
| (Real a, Fractional a) => RealToFrac a a Source # | |
Defined in Data.Number.RealToFrac Methods realToFrac :: a -> a Source # | |
| (Real a, Transfinite a, Fractional b, Transfinite b) => RealToFrac a b Source # | |
Defined in Data.Number.RealToFrac Methods realToFrac :: a -> b Source # | |