From fa660b14d547ed6b9ae695a10cb14c6e501b84cb Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Thu, 19 Nov 2009 00:40:55 -0500 Subject: [PATCH] types: Use operations in GHC.Prim for double <=> float conversions. --- Data/Floating/Types.hs | 12 ++---------- cfloat.c | 10 ---------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/Data/Floating/Types.hs b/Data/Floating/Types.hs index 5826ab0..8111a2e 100644 --- a/Data/Floating/Types.hs +++ b/Data/Floating/Types.hs @@ -15,14 +15,6 @@ import Foreign.C import Unsafe.Coerce --- | For reasons unknown to me, we actually need to do foreign calls in order --- to convert between floating types. -foreign import ccall unsafe "double_to_float" - double_to_float :: CDouble -> CFloat --- | The opposite of double_to_float. -foreign import ccall unsafe "float_to_double" - float_to_double :: CFloat -> CDouble - -- | The Double type. This is expected to be an identical declaration to -- the one found in GHC.Prim. We avoid simply using GHC's type because we need -- to define our own class instances. @@ -58,10 +50,10 @@ instance FloatConvert CFloat Float where toFloating f = let FuckF x = unsafeCoerce f in x instance FloatConvert Double Float where - toFloating = toFloating . double_to_float . toFloating + toFloating (D# x) = F# (double2Float# x) instance FloatConvert Float Double where - toFloating = toFloating . float_to_double . toFloating + toFloating (F# x) = D# (float2Double# x) instance Integral a => FloatConvert a Double where toFloating x = D# (doubleFromInteger (toInteger x)) diff --git a/cfloat.c b/cfloat.c index 7868bd6..dae95e1 100644 --- a/cfloat.c +++ b/cfloat.c @@ -36,13 +36,3 @@ int double_classify(double val) return -1; } - -float double_to_float(double val) -{ - return val; -} - -double float_to_double(float val) -{ - return val; -} -- 2.11.4.GIT