{-# LANGUAGE NoImplicitPrelude #-}
module Algebra.Absolute (
C(abs, signum),
absOrd, signumOrd,
) where
import qualified Algebra.Ring as Ring
import qualified Algebra.Additive as Additive
import Algebra.Ring (one, )
import Algebra.Additive (zero, negate,)
import Data.Int (Int, Int8, Int16, Int32, Int64, )
import Data.Word (Word, Word8, Word16, Word32, Word64, )
import NumericPrelude.Base
import qualified Prelude as P
import Prelude (Integer, Float, Double, )
class (Ring.C a) => C a where
abs :: a -> a
signum :: a -> a
absOrd :: (Additive.C a, Ord a) => a -> a
absOrd x = max x (negate x)
signumOrd :: (Ring.C a, Ord a) => a -> a
signumOrd x =
case compare x zero of
GT -> one
EQ -> zero
LT -> negate one
instance C Integer where
{-# INLINE abs #-}
{-# INLINE signum #-}
abs = P.abs
signum = P.signum
instance C Float where
{-# INLINE abs #-}
{-# INLINE signum #-}
abs = P.abs
signum = P.signum
instance C Double where
{-# INLINE abs #-}
{-# INLINE signum #-}
abs = P.abs
signum = P.signum
instance C Int where
{-# INLINE abs #-}
{-# INLINE signum #-}
abs = P.abs
signum = P.signum
instance C Int8 where
{-# INLINE abs #-}
{-# INLINE signum #-}
abs = P.abs
signum = P.signum
instance C Int16 where
{-# INLINE abs #-}
{-# INLINE signum #-}
abs = P.abs
signum = P.signum
instance C Int32 where
{-# INLINE abs #-}
{-# INLINE signum #-}
abs = P.abs
signum = P.signum
instance C Int64 where
{-# INLINE abs #-}
{-# INLINE signum #-}
abs = P.abs
signum = P.signum
instance C Word where
{-# INLINE abs #-}
{-# INLINE signum #-}
abs = P.abs
signum = P.signum
instance C Word8 where
{-# INLINE abs #-}
{-# INLINE signum #-}
abs = P.abs
signum = P.signum
instance C Word16 where
{-# INLINE abs #-}
{-# INLINE signum #-}
abs = P.abs
signum = P.signum
instance C Word32 where
{-# INLINE abs #-}
{-# INLINE signum #-}
abs = P.abs
signum = P.signum
instance C Word64 where
{-# INLINE abs #-}
{-# INLINE signum #-}
abs = P.abs
signum = P.signum