{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Numeric.Floating.IEEE.Internal.MinMax where
import MyPrelude
default ()
minimum' :: RealFloat a => a -> a -> a
minimum' :: a -> a -> a
minimum' a
x a
y | a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
x = a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
x
| a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
y = a
y a -> a -> a
forall a. Num a => a -> a -> a
+ a
y
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
y Bool -> Bool -> Bool
|| (a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y Bool -> Bool -> Bool
&& a -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero a
x) = a
x
| Bool
otherwise = a
y
{-# NOINLINE [1] minimum' #-}
minimumNumber :: RealFloat a => a -> a -> a
minimumNumber :: a -> a -> a
minimumNumber a
x a
y | a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
x Bool -> Bool -> Bool
&& a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
y = a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
x
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
y Bool -> Bool -> Bool
|| a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
y Bool -> Bool -> Bool
|| (a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y Bool -> Bool -> Bool
&& a -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero a
x) = a
x
| Bool
otherwise = a
y
{-# NOINLINE [1] minimumNumber #-}
maximum' :: RealFloat a => a -> a -> a
maximum' :: a -> a -> a
maximum' a
x a
y | a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
x = a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
x
| a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
y = a
y a -> a -> a
forall a. Num a => a -> a -> a
+ a
y
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
y Bool -> Bool -> Bool
|| (a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y Bool -> Bool -> Bool
&& a -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero a
x) = a
y
| Bool
otherwise = a
x
{-# NOINLINE [1] maximum' #-}
maximumNumber :: RealFloat a => a -> a -> a
maximumNumber :: a -> a -> a
maximumNumber a
x a
y | a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
x Bool -> Bool -> Bool
&& a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
y = a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
x
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
y Bool -> Bool -> Bool
|| a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
x Bool -> Bool -> Bool
|| (a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y Bool -> Bool -> Bool
&& a -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero a
x) = a
y
| Bool
otherwise = a
x
{-# NOINLINE [1] maximumNumber #-}
minimumMagnitude :: RealFloat a => a -> a -> a
minimumMagnitude :: a -> a -> a
minimumMagnitude a
x a
y | a -> a
forall a. Num a => a -> a
abs a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a -> a
forall a. Num a => a -> a
abs a
y = a
x
| a -> a
forall a. Num a => a -> a
abs a
y a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a -> a
forall a. Num a => a -> a
abs a
x = a
y
| Bool
otherwise = a -> a -> a
forall a. RealFloat a => a -> a -> a
minimum' a
x a
y
minimumMagnitudeNumber :: RealFloat a => a -> a -> a
minimumMagnitudeNumber :: a -> a -> a
minimumMagnitudeNumber a
x a
y | a -> a
forall a. Num a => a -> a
abs a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a -> a
forall a. Num a => a -> a
abs a
y = a
x
| a -> a
forall a. Num a => a -> a
abs a
y a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a -> a
forall a. Num a => a -> a
abs a
x = a
y
| Bool
otherwise = a -> a -> a
forall a. RealFloat a => a -> a -> a
minimumNumber a
x a
y
maximumMagnitude :: RealFloat a => a -> a -> a
maximumMagnitude :: a -> a -> a
maximumMagnitude a
x a
y | a -> a
forall a. Num a => a -> a
abs a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a -> a
forall a. Num a => a -> a
abs a
y = a
x
| a -> a
forall a. Num a => a -> a
abs a
y a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a -> a
forall a. Num a => a -> a
abs a
x = a
y
| Bool
otherwise = a -> a -> a
forall a. RealFloat a => a -> a -> a
maximum' a
x a
y
maximumMagnitudeNumber :: RealFloat a => a -> a -> a
maximumMagnitudeNumber :: a -> a -> a
maximumMagnitudeNumber a
x a
y | a -> a
forall a. Num a => a -> a
abs a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a -> a
forall a. Num a => a -> a
abs a
y = a
x
| a -> a
forall a. Num a => a -> a
abs a
y a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a -> a
forall a. Num a => a -> a
abs a
x = a
y
| Bool
otherwise = a -> a -> a
forall a. RealFloat a => a -> a -> a
maximumNumber a
x a
y
#if defined(HAS_FAST_MINMAX)
foreign import ccall unsafe "hs_minimumFloat"
minimumFloat :: Float -> Float -> Float
foreign import ccall unsafe "hs_maximumFloat"
maximumFloat :: Float -> Float -> Float
foreign import ccall unsafe "hs_minimumNumberFloat"
minimumNumberFloat :: Float -> Float -> Float
foreign import ccall unsafe "hs_maximumNumberFloat"
maximumNumberFloat :: Float -> Float -> Float
foreign import ccall unsafe "hs_minimumDouble"
minimumDouble :: Double -> Double -> Double
foreign import ccall unsafe "hs_maximumDouble"
maximumDouble :: Double -> Double -> Double
foreign import ccall unsafe "hs_minimumNumberDouble"
minimumNumberDouble :: Double -> Double -> Double
foreign import ccall unsafe "hs_maximumNumberDouble"
maximumNumberDouble :: Double -> Double -> Double
{-# RULES
"minimum'/Float" minimum' = minimumFloat
"maximum'/Float" maximum' = maximumFloat
"minimumNumber/Float" minimumNumber = minimumNumberFloat
"maximumNumber/Float" maximumNumber = maximumNumberFloat
"minimum'/Double" minimum' = minimumDouble
"maximum'/Double" maximum' = maximumDouble
"minimumNumber/Double" minimumNumber = minimumNumberDouble
"maximumNumber/Double" maximumNumber = maximumNumberDouble
#-}
#else
minimumFloat :: Float -> Float -> Float
maximumFloat :: Float -> Float -> Float
minimumNumberFloat :: Float -> Float -> Float
maximumNumberFloat :: Float -> Float -> Float
minimumDouble :: Double -> Double -> Double
maximumDouble :: Double -> Double -> Double
minimumNumberDouble :: Double -> Double -> Double
maximumNumberDouble :: Double -> Double -> Double
minimumFloat :: Float -> Float -> Float
minimumFloat = Float -> Float -> Float
forall a. RealFloat a => a -> a -> a
minimum'
minimumDouble :: Double -> Double -> Double
minimumDouble = Double -> Double -> Double
forall a. RealFloat a => a -> a -> a
minimum'
minimumNumberFloat :: Float -> Float -> Float
minimumNumberFloat = Float -> Float -> Float
forall a. RealFloat a => a -> a -> a
minimumNumber
minimumNumberDouble :: Double -> Double -> Double
minimumNumberDouble = Double -> Double -> Double
forall a. RealFloat a => a -> a -> a
minimumNumber
maximumFloat :: Float -> Float -> Float
maximumFloat = Float -> Float -> Float
forall a. RealFloat a => a -> a -> a
maximum'
maximumDouble :: Double -> Double -> Double
maximumDouble = Double -> Double -> Double
forall a. RealFloat a => a -> a -> a
maximum'
maximumNumberFloat :: Float -> Float -> Float
maximumNumberFloat = Float -> Float -> Float
forall a. RealFloat a => a -> a -> a
maximumNumber
maximumNumberDouble :: Double -> Double -> Double
maximumNumberDouble = Double -> Double -> Double
forall a. RealFloat a => a -> a -> a
maximumNumber
#endif