diff options
author | Dan Doel <dan.doel@gmail.com> | 2015-12-20 15:19:52 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-12-21 13:01:36 +0100 |
commit | 6457903e7671b6096d2cca5d965f43daee3572a6 (patch) | |
tree | 6d401f671fc73fbe04a49421e0456654c27d662b /libraries/base/Data | |
parent | edcf17bd2ae503c2dda43ded40dca0950edfd018 (diff) | |
download | haskell-6457903e7671b6096d2cca5d965f43daee3572a6.tar.gz |
Implement phase 1 of expanded Floating
- This part of the proposal is to add log1p, expm1, log1pexp and
log1mexp to the Floating class, and export the full Floating class
from Numeric
Reviewers: ekmett, #core_libraries_committee, bgamari, hvr, austin
Reviewed By: ekmett, #core_libraries_committee, bgamari
Subscribers: Phyx, RyanGlScott, ekmett, thomie
Differential Revision: https://phabricator.haskell.org/D1605
GHC Trac Issues: #11166
Diffstat (limited to 'libraries/base/Data')
-rw-r--r-- | libraries/base/Data/Complex.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libraries/base/Data/Complex.hs b/libraries/base/Data/Complex.hs index 31550d5ac7..dd831bbb91 100644 --- a/libraries/base/Data/Complex.hs +++ b/libraries/base/Data/Complex.hs @@ -37,6 +37,7 @@ module Data.Complex ) where import GHC.Generics (Generic, Generic1) +import GHC.Float (Floating(..)) import Data.Data (Data) import Foreign (Storable, castPtr, peek, poke, pokeElemOff, peekElemOff, sizeOf, alignment) @@ -195,6 +196,20 @@ instance (RealFloat a) => Floating (Complex a) where acosh z = log (z + (z+1) * sqrt ((z-1)/(z+1))) atanh z = 0.5 * log ((1.0+z) / (1.0-z)) + log1p x@(a :+ b) + | abs a < 0.5 && abs b < 0.5 + , u <- 2*a + a*a + b*b = log1p (u/(1 + sqrt(u+1))) :+ atan2 (1 + a) b + | otherwise = log (1 + x) + {-# INLINE log1p #-} + + expm1 x@(a :+ b) + | a*a + b*b < 1 + , u <- expm1 a + , v <- sin (b/2) + , w <- -2*v*v = (u*w + u + w) :+ (u+1)*sin b + | otherwise = exp x - 1 + {-# INLINE expm1 #-} + instance Storable a => Storable (Complex a) where sizeOf a = 2 * sizeOf (realPart a) alignment a = alignment (realPart a) |