logfloat 0.13.2 → 0.13.3
raw patch · 5 files changed
+119/−39 lines, 5 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- logfloat.cabal +3/−3
- src/Data/Number/LogFloat.hs +51/−10
- src/Data/Number/PartialOrd.hs +21/−7
- src/Data/Number/RealToFrac.hs +43/−14
- src/Data/Number/Transfinite.hs +1/−5
logfloat.cabal view
@@ -1,5 +1,5 @@ ------------------------------------------------------------------- wren gayle romano <wren@community.haskell.org> ~ 2015.03.23+-- wren gayle romano <wren@community.haskell.org> ~ 2015.03.29 ---------------------------------------------------------------- -- By and large Cabal >=1.2 is fine; but >= 1.6 gives tested-with:@@ -8,7 +8,7 @@ Build-Type: Simple Name: logfloat-Version: 0.13.2+Version: 0.13.3 Stability: experimental Homepage: http://code.haskell.org/~wren/ Author: wren gayle romano@@ -28,7 +28,7 @@ -- TODO: does GHC 6.12.1 and 7.6.1 still work? do we care? Tested-With:- GHC == 7.8.3+ GHC == 7.8.3, GHC == 7.10.1 Extra-source-files: INSTALL, VERSION Source-Repository head
src/Data/Number/LogFloat.hs view
@@ -2,14 +2,19 @@ -- FFI is for log1p {-# LANGUAGE CPP, ForeignFunctionInterface, MultiParamTypeClasses #-} -- We don't put these in LANGUAGE, because it's CPP guarded for GHC only-{-# OPTIONS_GHC -XGeneralizedNewtypeDeriving #-}+-- HACK: ScopedTypeVariables and InstanceSigs are for GHC 7.10 only...+{-# OPTIONS_GHC+ -XGeneralizedNewtypeDeriving+ -XScopedTypeVariables+ -XInstanceSigs+ #-} {-# OPTIONS_GHC -Wall -fwarn-tabs #-} {-# OPTIONS_GHC -O2 -fexcess-precision -fenable-rewrite-rules #-} ------------------------------------------------------------------- ~ 2015.03.23+-- ~ 2015.03.24 -- | -- Module : Data.Number.LogFloat -- Copyright : Copyright (c) 2007--2015 wren gayle romano@@ -75,10 +80,11 @@ #elif __NHC__ import NonStdUnsafeCoerce (unsafeCoerce) #elif __GLASGOW_HASKELL__ >= 710--- When we can, do...-import Data.Coerce (coerce)--- When we can't, pretend.+-- For when the *heap* representations are the same +--import Data.Coerce (coerce)+-- For when the *unboxed array* storage representations are the same import Unsafe.Coerce (unsafeCoerce)+import Data.Ix (Ix) #endif #ifdef __GLASGOW_HASKELL__@@ -142,7 +148,8 @@ -- them (even without GeneralizedNewtypeDeriving). However, -- GHC >= 7.10 can't derive @IArray UArray@ thanks to the new -- type-role stuff! since 'UArray' is declared to be nominal- -- in both arguments...+ -- in both arguments... and that seems to be necessary:+ -- cf., <https://ghc.haskell.org/trac/ghc/ticket/9220> #if __GLASGOW_HASKELL__ < 710 , IArray UArray #endif@@ -150,8 +157,40 @@ #endif ) +#if __GLASGOW_HASKELL__ >= 710+-- TODO: this version should also work for NHC and Hugs, I think...+-- HACK: we should be able to just unsafeCoerce the functions themselves, instead of coercing the inputs and the outputs; but, GHC 7.10 seems to get confused about trying to coerce the index types too... To fix this we give explicit signatures, as below, but this requires both ScopedTypeVariables and InstanceSigs; and I'm not sure when InstanceSigs was introduced. -#if __HUGS__ || __NHC__ || (__GLASGOW_HASKELL__ >= 710)+instance IArray UArray LogFloat where+ {-# INLINE bounds #-}+ bounds :: forall i. Ix i => UArray i LogFloat -> (i, i)+ bounds = unsafeCoerce (bounds :: UArray i Double -> (i, i))+ + {-# INLINE numElements #-}+ numElements :: forall i. Ix i => UArray i LogFloat -> Int+ numElements = unsafeCoerce (numElements :: UArray i Double -> Int)+ + {-# INLINE unsafeArray #-}+ unsafeArray :: forall i. Ix i => (i,i) -> [(Int,LogFloat)] -> UArray i LogFloat+ unsafeArray = unsafeCoerce (unsafeArray :: (i,i) -> [(Int,Double)] -> UArray i Double)+ + {-# INLINE unsafeAt #-}+ unsafeAt :: forall i. Ix i => UArray i LogFloat -> Int -> LogFloat+ unsafeAt = unsafeCoerce (unsafeAt :: UArray i Double -> Int -> Double)+ + {-# INLINE unsafeReplace #-}+ unsafeReplace :: forall i. Ix i => UArray i LogFloat -> [(Int,LogFloat)] -> UArray i LogFloat+ unsafeReplace = unsafeCoerce (unsafeReplace :: UArray i Double -> [(Int,Double)] -> UArray i Double)+ + {-# INLINE unsafeAccum #-}+ unsafeAccum :: forall i e. Ix i => (LogFloat -> e -> LogFloat) -> UArray i LogFloat -> [(Int,e)] -> UArray i LogFloat+ unsafeAccum = unsafeCoerce (unsafeAccum :: (Double -> e -> Double) -> UArray i Double -> [(Int,e)] -> UArray i Double)+ + {-# INLINE unsafeAccumArray #-}+ unsafeAccumArray :: forall i e. Ix i => (LogFloat -> e -> LogFloat) -> LogFloat -> (i,i) -> [(Int,e)] -> UArray i LogFloat+ unsafeAccumArray = unsafeCoerce (unsafeAccumArray :: (Double -> e -> Double) -> Double -> (i,i) -> [(Int,e)] -> UArray i Double)++#elif __HUGS__ || __NHC__ -- TODO: Storable instance. Though Foreign.Storable isn't in Hugs(Sept06) -- These two operators make it much easier to read the instance.@@ -176,13 +215,13 @@ logFromLFAssocs = unsafeCoerce #endif --- BUG: 'UArray' is declared to be nominal in the second type, so--- these two are unsafe!+-- HACK: can't coerce, cf: <https://ghc.haskell.org/trac/ghc/ticket/9220> {-# INLINE logFromLFUArray #-} logFromLFUArray :: UArray a LogFloat -> UArray a Double logFromLFUArray = unsafeCoerce -- Named unsafe because it could allow injecting NaN if misused+-- HACK: can't coerce, cf: <https://ghc.haskell.org/trac/ghc/ticket/9220> {-# INLINE unsafeLogToLFUArray #-} unsafeLogToLFUArray :: UArray a Double -> UArray a LogFloat unsafeLogToLFUArray = unsafeCoerce@@ -391,7 +430,8 @@ expm1 x = exp x - 1 #endif -+-- CPP guarded because they won't fire if we're using the FFI versions+#if !defined(__USE_FFI__) {-# RULES -- Into log-domain and back out "expm1/log1p" forall x. expm1 (log1p x) = x@@ -399,6 +439,7 @@ -- Out of log-domain and back in "log1p/expm1" forall x. log1p (expm1 x) = x #-}+#endif ---------------------------------------------------------------- -- These all work without causing underflow. However, do note that
src/Data/Number/PartialOrd.hs view
@@ -1,14 +1,16 @@--- TODO: in GHC 7.10 OverlappingInstances is deprecated in favor--- of per-instance OVERLAPPING/OVERLAPPABLE/OVERLAPS pragmata.-{-# LANGUAGE OverlappingInstances+{-# LANGUAGE CPP , FlexibleInstances , UndecidableInstances #-} +#if __GLASGOW_HASKELL__ < 710+{-# LANGUAGE OverlappingInstances #-}+#endif+ {-# OPTIONS_GHC -Wall -fwarn-tabs #-} ------------------------------------------------------------------- ~ 2009.01.29+-- ~ 2015.03.29 -- | -- Module : Data.Number.PartialOrd -- Copyright : Copyright (c) 2007--2015 wren gayle romano@@ -110,7 +112,11 @@ infix 4 `gt`, `ge`, `eq`, `ne`, `le`, `lt`, `maxPO`, `minPO` -instance (Ord a) => PartialOrd a where+instance+#if __GLASGOW_HASKELL__ >= 710+ {-# OVERLAPPABLE #-}+#endif+ (Ord a) => PartialOrd a where cmp x y = Just $! x `compare` y gt x y = Just $! x > y ge x y = Just $! x >= y@@ -128,11 +134,19 @@ -- returns @Just Eq@ for @notANumber@ then CPP was run wrongly. -- -- The instances inherited from Ord are wrong. So we'll fix them.-instance PartialOrd Float where+instance+#if __GLASGOW_HASKELL__ >= 710+ {-# OVERLAPPING #-}+#endif+ PartialOrd Float where cmp x y | isNaN x || isNaN y = Nothing | otherwise = Just $! x `compare` y -instance PartialOrd Double where+instance+#if __GLASGOW_HASKELL__ >= 710+ {-# OVERLAPPING #-}+#endif+ PartialOrd Double where cmp x y | isNaN x || isNaN y = Nothing | otherwise = Just $! x `compare` y
src/Data/Number/RealToFrac.hs view
@@ -1,21 +1,22 @@--- TODO: in GHC 7.10 OverlappingInstances is deprecated in favor--- of per-instance OVERLAPPING/OVERLAPPABLE/OVERLAPS pragmata.--- -- Needed to ensure correctness, and because we can't guarantee rules fire -- The MagicHash is for unboxed primitives (-fglasgow-exts also works) -- We only need MagicHash if on GHC, but we can't hide it in an #ifdef-{-# LANGUAGE MultiParamTypeClasses- , OverlappingInstances+{-# LANGUAGE CPP+ , MultiParamTypeClasses , FlexibleInstances- , CPP #-}++#if __GLASGOW_HASKELL__ < 710+{-# LANGUAGE OverlappingInstances #-}+#endif+ -- We don't put these in LANGUAGE, because it's CPP guarded for GHC only {-# OPTIONS_GHC -XMagicHash #-} {-# OPTIONS_GHC -Wall -fwarn-tabs #-} ------------------------------------------------------------------- ~ 2013.05.11+-- ~ 2013.05.29 -- | -- Module : Data.Number.RealToFrac -- Copyright : Copyright (c) 2007--2015 wren gayle romano@@ -79,7 +80,11 @@ instance (Real a, Fractional a) => RealToFrac a a where realToFrac = id -instance (Real a, Transfinite a, Fractional b, Transfinite b)+instance+#if __GLASGOW_HASKELL__ >= 710+ {-# OVERLAPPABLE #-}+#endif+ (Real a, Transfinite a, Fractional b, Transfinite b) => RealToFrac a b where realToFrac x@@ -90,31 +95,55 @@ #ifdef __GLASGOW_HASKELL__-instance RealToFrac Int Float where+instance+#if __GLASGOW_HASKELL__ >= 710+ {-# OVERLAPPING #-}+#endif+ RealToFrac Int Float where {-# INLINE realToFrac #-} realToFrac (I# i) = F# (int2Float# i) -instance RealToFrac Int Double where+instance+#if __GLASGOW_HASKELL__ >= 710+ {-# OVERLAPPING #-}+#endif+ RealToFrac Int Double where {-# INLINE realToFrac #-} realToFrac (I# i) = D# (int2Double# i) -instance RealToFrac Integer Float where+instance+#if __GLASGOW_HASKELL__ >= 710+ {-# OVERLAPPING #-}+#endif+ RealToFrac Integer Float where -- TODO: is there a more primitive way? {-# INLINE realToFrac #-} realToFrac j = Prelude.realToFrac j -instance RealToFrac Integer Double where+instance+#if __GLASGOW_HASKELL__ >= 710+ {-# OVERLAPPING #-}+#endif+ RealToFrac Integer Double where -- TODO: is there a more primitive way? {-# INLINE realToFrac #-} realToFrac j = Prelude.realToFrac j -instance RealToFrac Float Double where+instance+#if __GLASGOW_HASKELL__ >= 710+ {-# OVERLAPPING #-}+#endif+ RealToFrac Float Double where {-# INLINE realToFrac #-} realToFrac (F# f) = D# (float2Double# f) -instance RealToFrac Double Float where+instance+#if __GLASGOW_HASKELL__ >= 710+ {-# OVERLAPPING #-}+#endif+ RealToFrac Double Float where {-# INLINE realToFrac #-} realToFrac (D# d) = F# (double2Float# d) #endif
src/Data/Number/Transfinite.hs view
@@ -1,9 +1,7 @@ {-# OPTIONS_GHC -Wall -fwarn-tabs #-}- {-# OPTIONS_GHC -O2 -fenable-rewrite-rules #-}- ------------------------------------------------------------------- ~ 2015.03.23+-- ~ 2015.03.29 -- | -- Module : Data.Number.Transfinite -- Copyright : Copyright (c) 2007--2015 wren gayle romano@@ -179,8 +177,6 @@ -- be noted in case your code depends on the implementation details. log :: (Floating a, Transfinite a) => a -> a-{-# SPECIALIZE log :: Double -> Double #-}-{-# SPECIALIZE log :: Float -> Float #-} {-# INLINE [0] log #-} -- TODO: should we use NOINLINE or [~0] to avoid the possibility of code bloat? log x = case x `cmp` 0 of