mirror of
https://github.com/tfausak/witch.git
synced 2024-11-22 14:58:13 +03:00
Merge pull request #16 from tfausak/gh14-floating-point
Use `float2Double` instead of `realToFrac`
This commit is contained in:
commit
11fbbb9c23
@ -29,6 +29,7 @@ import qualified Data.Text.Lazy as LazyText
|
|||||||
import qualified Data.Text.Lazy.Encoding as LazyText
|
import qualified Data.Text.Lazy.Encoding as LazyText
|
||||||
import qualified Data.Typeable as Typeable
|
import qualified Data.Typeable as Typeable
|
||||||
import qualified Data.Word as Word
|
import qualified Data.Word as Word
|
||||||
|
import qualified GHC.Float as Float
|
||||||
import qualified Numeric.Natural as Natural
|
import qualified Numeric.Natural as Natural
|
||||||
import qualified Witch.Cast as Cast
|
import qualified Witch.Cast as Cast
|
||||||
import qualified Witch.TryCast as TryCast
|
import qualified Witch.TryCast as TryCast
|
||||||
@ -804,9 +805,9 @@ instance TryCast.TryCast Float Rational where
|
|||||||
then if s > 0 then Left Exception.Overflow else Left Exception.Underflow
|
then if s > 0 then Left Exception.Overflow else Left Exception.Underflow
|
||||||
else Right $ toRational s
|
else Right $ toRational s
|
||||||
|
|
||||||
-- | Uses 'realToFrac'.
|
-- | Uses 'Float.double2Float'.
|
||||||
instance Cast.Cast Float Double where
|
instance Cast.Cast Float Double where
|
||||||
cast = realToFrac
|
cast = Float.float2Double
|
||||||
|
|
||||||
-- Double
|
-- Double
|
||||||
|
|
||||||
@ -872,9 +873,9 @@ instance TryCast.TryCast Double Rational where
|
|||||||
then if s > 0 then Left Exception.Overflow else Left Exception.Underflow
|
then if s > 0 then Left Exception.Overflow else Left Exception.Underflow
|
||||||
else Right $ toRational s
|
else Right $ toRational s
|
||||||
|
|
||||||
-- | Uses 'realToFrac'. This necessarily loses some precision.
|
-- | Uses 'Float.double2Float'. This necessarily loses some precision.
|
||||||
instance Cast.Cast Double Float where
|
instance Cast.Cast Double Float where
|
||||||
cast = realToFrac
|
cast = Float.double2Float
|
||||||
|
|
||||||
-- Ratio
|
-- Ratio
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user