Patch from Daniel Fischer.
significand x = encodeFloat m (negate (floatDigits x))
where (m,_) = decodeFloat x
significand x = encodeFloat m (negate (floatDigits x))
where (m,_) = decodeFloat x
- scaleFloat k x = encodeFloat m (n + clamp b k)
+ scaleFloat 0 x = x
+ scaleFloat k x
+ | isFix = x
+ | otherwise = encodeFloat m (n + clamp b k)
where (m,n) = decodeFloat x
(l,h) = floatRange x
d = floatDigits x
where (m,n) = decodeFloat x
(l,h) = floatRange x
d = floatDigits x
-- for smaller than l - d.
-- Add a little extra to keep clear
-- from the boundary cases.
-- for smaller than l - d.
-- Add a little extra to keep clear
-- from the boundary cases.
+ isFix = x == 0 || isNaN x || isInfinite x
atan2 y x
| x > 0 = atan (y/x)
atan2 y x
| x > 0 = atan (y/x)
significand x = case decodeFloat x of
(m,_) -> encodeFloat m (negate (floatDigits x))
significand x = case decodeFloat x of
(m,_) -> encodeFloat m (negate (floatDigits x))
- scaleFloat k x = case decodeFloat x of
+ scaleFloat 0 x = x
+ scaleFloat k x
+ | isFix = x
+ | otherwise = case decodeFloat x of
(m,n) -> encodeFloat m (n + clamp bf k)
where bf = FLT_MAX_EXP - (FLT_MIN_EXP) + 4*FLT_MANT_DIG
(m,n) -> encodeFloat m (n + clamp bf k)
where bf = FLT_MAX_EXP - (FLT_MIN_EXP) + 4*FLT_MANT_DIG
+ isFix = x == 0 || isFloatFinite x == 0
isNaN x = 0 /= isFloatNaN x
isInfinite x = 0 /= isFloatInfinite x
isNaN x = 0 /= isFloatNaN x
isInfinite x = 0 /= isFloatInfinite x
significand x = case decodeFloat x of
(m,_) -> encodeFloat m (negate (floatDigits x))
significand x = case decodeFloat x of
(m,_) -> encodeFloat m (negate (floatDigits x))
- scaleFloat k x = case decodeFloat x of
+ scaleFloat 0 x = x
+ scaleFloat k x
+ | isFix = x
+ | otherwise = case decodeFloat x of
(m,n) -> encodeFloat m (n + clamp bd k)
where bd = DBL_MAX_EXP - (DBL_MIN_EXP) + 4*DBL_MANT_DIG
(m,n) -> encodeFloat m (n + clamp bd k)
where bd = DBL_MAX_EXP - (DBL_MIN_EXP) + 4*DBL_MANT_DIG
+ isFix = x == 0 || isDoubleFinite x == 0
isNaN x = 0 /= isDoubleNaN x
isInfinite x = 0 /= isDoubleInfinite x
isNaN x = 0 /= isDoubleNaN x
isInfinite x = 0 /= isDoubleInfinite x
foreign import ccall unsafe "isFloatInfinite" isFloatInfinite :: Float -> Int
foreign import ccall unsafe "isFloatDenormalized" isFloatDenormalized :: Float -> Int
foreign import ccall unsafe "isFloatNegativeZero" isFloatNegativeZero :: Float -> Int
foreign import ccall unsafe "isFloatInfinite" isFloatInfinite :: Float -> Int
foreign import ccall unsafe "isFloatDenormalized" isFloatDenormalized :: Float -> Int
foreign import ccall unsafe "isFloatNegativeZero" isFloatNegativeZero :: Float -> Int
+foreign import ccall unsafe "isFloatFinite" isFloatFinite :: Float -> Int
foreign import ccall unsafe "isDoubleNaN" isDoubleNaN :: Double -> Int
foreign import ccall unsafe "isDoubleInfinite" isDoubleInfinite :: Double -> Int
foreign import ccall unsafe "isDoubleDenormalized" isDoubleDenormalized :: Double -> Int
foreign import ccall unsafe "isDoubleNegativeZero" isDoubleNegativeZero :: Double -> Int
foreign import ccall unsafe "isDoubleNaN" isDoubleNaN :: Double -> Int
foreign import ccall unsafe "isDoubleInfinite" isDoubleInfinite :: Double -> Int
foreign import ccall unsafe "isDoubleDenormalized" isDoubleDenormalized :: Double -> Int
foreign import ccall unsafe "isDoubleNegativeZero" isDoubleNegativeZero :: Double -> Int
+foreign import ccall unsafe "isDoubleFinite" isDoubleFinite :: Double -> Int
\end{code}
%*********************************************************
\end{code}
%*********************************************************
#ifdef IEEE_FLOATING_POINT
HsInt
#ifdef IEEE_FLOATING_POINT
HsInt
+isDoubleFinite(HsDouble d)
+{
+ union stg_ieee754_dbl u;
+
+ u.d = d;
+
+ return u.ieee.exponent != 2047;
+}
+
+HsInt
isDoubleNaN(HsDouble d)
{
union stg_ieee754_dbl u;
isDoubleNaN(HsDouble d)
{
union stg_ieee754_dbl u;
+isFloatFinite(HsFloat f)
+{
+ union stg_ieee754_flt u;
+ u.f = f;
+ return u.ieee.exponent != 255;
+}
+
+HsInt
isFloatNaN(HsFloat f)
{
union stg_ieee754_flt u;
isFloatNaN(HsFloat f)
{
union stg_ieee754_flt u;
#else /* ! IEEE_FLOATING_POINT */
#else /* ! IEEE_FLOATING_POINT */
-/* Dummy definitions of predicates - they all return false */
+/* Dummy definitions of predicates - they all return "normal" values */
+HsInt isDoubleFinite(d) HsDouble d; { return 1;}
HsInt isDoubleNaN(d) HsDouble d; { return 0; }
HsInt isDoubleInfinite(d) HsDouble d; { return 0; }
HsInt isDoubleDenormalized(d) HsDouble d; { return 0; }
HsInt isDoubleNegativeZero(d) HsDouble d; { return 0; }
HsInt isDoubleNaN(d) HsDouble d; { return 0; }
HsInt isDoubleInfinite(d) HsDouble d; { return 0; }
HsInt isDoubleDenormalized(d) HsDouble d; { return 0; }
HsInt isDoubleNegativeZero(d) HsDouble d; { return 0; }
+HsInt isFloatFinite(f) HsFloat f; { return 1; }
HsInt isFloatNaN(f) HsFloat f; { return 0; }
HsInt isFloatInfinite(f) HsFloat f; { return 0; }
HsInt isFloatDenormalized(f) HsFloat f; { return 0; }
HsInt isFloatNaN(f) HsFloat f; { return 0; }
HsInt isFloatInfinite(f) HsFloat f; { return 0; }
HsInt isFloatDenormalized(f) HsFloat f; { return 0; }