{-# LANGUAGE TypeSynonymInstances #-}
module Foundation.Numerical.Floating
    ( FloatingPoint(..)
    ) where

import           Basement.Compat.Base
import           Data.Proxy
import qualified Prelude

-- | IEEE754 Floating Point
class FloatingPoint a where
    floatRadix  :: Proxy a -> Integer
    floatDigits :: Proxy a -> Int
    floatRange  :: Proxy a -> (Int, Int)
    floatDecode :: a -> (Integer, Int)
    floatEncode :: Integer -> Int -> a

instance FloatingPoint Float where
    floatRadix :: Proxy Float -> Integer
floatRadix Proxy Float
_ = Float -> Integer
forall a. RealFloat a => a -> Integer
Prelude.floatRadix (Float
0.0 :: Float)
    floatDigits :: Proxy Float -> Int
floatDigits Proxy Float
_ = Float -> Int
forall a. RealFloat a => a -> Int
Prelude.floatDigits (Float
0.0 :: Float)
    floatRange :: Proxy Float -> (Int, Int)
floatRange Proxy Float
_ = Float -> (Int, Int)
forall a. RealFloat a => a -> (Int, Int)
Prelude.floatRange (Float
0.0 :: Float)
    floatDecode :: Float -> (Integer, Int)
floatDecode = Float -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
Prelude.decodeFloat
    floatEncode :: Integer -> Int -> Float
floatEncode = Integer -> Int -> Float
forall a. RealFloat a => Integer -> Int -> a
Prelude.encodeFloat

instance FloatingPoint Double where
    floatRadix :: Proxy Double -> Integer
floatRadix Proxy Double
_ = Double -> Integer
forall a. RealFloat a => a -> Integer
Prelude.floatRadix (Double
0.0 :: Double)
    floatDigits :: Proxy Double -> Int
floatDigits Proxy Double
_ = Double -> Int
forall a. RealFloat a => a -> Int
Prelude.floatDigits (Double
0.0 :: Double)
    floatRange :: Proxy Double -> (Int, Int)
floatRange Proxy Double
_ = Double -> (Int, Int)
forall a. RealFloat a => a -> (Int, Int)
Prelude.floatRange (Double
0.0 :: Double)
    floatDecode :: Double -> (Integer, Int)
floatDecode = Double -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
Prelude.decodeFloat
    floatEncode :: Integer -> Int -> Double
floatEncode = Integer -> Int -> Double
forall a. RealFloat a => Integer -> Int -> a
Prelude.encodeFloat