From 851ccb5520035c38a8c2103e9569c4b302aa7d80 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Fri, 19 Feb 2010 17:38:44 -0500 Subject: [PATCH] floating: Add scalb as the altfloat version of scalbln. I don't think this function is really useful in the context of manipulating the floating point environmnent, so it is in the PrimFloat class. Move logb down there too, since they're a pair. --- Data/Floating/Classes.hs | 8 +++++--- Data/Floating/Environment.hs | 1 - Data/Floating/Types/Double.hs | 3 ++- Data/Floating/Types/Float.hs | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Data/Floating/Classes.hs b/Data/Floating/Classes.hs index 4c67026..b72a795 100644 --- a/Data/Floating/Classes.hs +++ b/Data/Floating/Classes.hs @@ -101,9 +101,6 @@ class Floating a => RealFloat a where log1p :: a -> a -- | Base-2 logarithm function. log2 :: a -> a - -- | Extracts the exponent of a floating point value. If the value is - -- subnormal, the result is as if the value were normalized. - logb :: a -> a -- | Error function. erf :: a -> a -- | Complementary error function. @@ -138,3 +135,8 @@ class (Roundable a, RealFloat a) => PrimFloat a where -- floating point number. floatRange :: Num b => a -> (b, b) classify :: a -> FPClassification + -- | Extracts the exponent of a floating point value. If the value is + -- subnormal, the result is as if the value were normalized. + logb :: a -> a + -- | Scales a floating point value by an integral power of the radix. + scalb :: Integral b => a -> b -> a diff --git a/Data/Floating/Environment.hs b/Data/Floating/Environment.hs index 8dc41b6..7aea8e6 100644 --- a/Data/Floating/Environment.hs +++ b/Data/Floating/Environment.hs @@ -180,7 +180,6 @@ instance RealFloat a => RealFloat (FEnv a) where log10 = liftA log10 log1p = liftA log1p log2 = liftA log2 - logb = liftA logb erf = liftA erf erfc = liftA erfc gamma = liftA gamma diff --git a/Data/Floating/Types/Double.hs b/Data/Floating/Types/Double.hs index cc6e3b1..a27b52b 100644 --- a/Data/Floating/Types/Double.hs +++ b/Data/Floating/Types/Double.hs @@ -152,7 +152,6 @@ instance RealFloat Double where log10 = libmDouble c_log10 log1p = libmDouble c_log1p log2 = libmDouble c_log2 - logb = libmDouble c_logb erf = libmDouble c_erf erfc = libmDouble c_erfc gamma = libmDouble c_tgamma @@ -165,3 +164,5 @@ instance PrimFloat Double where floatPrecision = const DBL_MANT_DIG_VAL floatRange = const (DBL_MIN_EXP_VAL, DBL_MAX_EXP_VAL) classify = toEnum . fromIntegral . double_classify . toFloating + logb = libmDouble c_logb + scalb x e = toFloating $ c_scalbln (toFloating x) (fromIntegral e) diff --git a/Data/Floating/Types/Float.hs b/Data/Floating/Types/Float.hs index b8c1f66..101d005 100644 --- a/Data/Floating/Types/Float.hs +++ b/Data/Floating/Types/Float.hs @@ -148,7 +148,6 @@ instance RealFloat Float where log10 = libmFloat c_log10f log1p = libmFloat c_log1pf log2 = libmFloat c_log2f - logb = libmFloat c_logbf erf = libmFloat c_erff erfc = libmFloat c_erfcf gamma = libmFloat c_tgammaf @@ -161,3 +160,5 @@ instance PrimFloat Float where floatPrecision = const FLT_MANT_DIG_VAL floatRange = const (FLT_MIN_EXP_VAL, FLT_MAX_EXP_VAL) classify = toEnum . fromIntegral . float_classify . toFloating + logb = libmFloat c_logbf + scalb x e = toFloating $ c_scalblnf (toFloating x) (fromIntegral e) -- 2.11.4.GIT