{-# LANGUAGE RebindableSyntax #-}
module Algebra.FloatingPoint where

import qualified Algebra.RealRing as RealRing
import NumericPrelude.Base

import qualified Prelude as P
import Prelude (Int, Integer, Float, Double, )


{- |
Counterpart of 'Prelude.RealFloat' but with NumericPrelude superclass.
-}
class RealRing.C a => C a where
   radix :: a -> Integer
   digits :: a -> Int
   range :: a -> (Int, Int)
   decode :: a -> (Integer, Int)
   encode :: Integer -> Int -> a
   exponent :: a -> Int
   significand :: a -> a
   scale :: Int -> a -> a
   isNaN :: a -> Bool
   isInfinite :: a -> Bool
   isDenormalized :: a -> Bool
   isNegativeZero :: a -> Bool
   isIEEE :: a -> Bool

instance C Float where
   radix :: Float -> Integer
radix = Float -> Integer
forall a. RealFloat a => a -> Integer
P.floatRadix
   digits :: Float -> Int
digits = Float -> Int
forall a. RealFloat a => a -> Int
P.floatDigits
   range :: Float -> (Int, Int)
range = Float -> (Int, Int)
forall a. RealFloat a => a -> (Int, Int)
P.floatRange
   decode :: Float -> (Integer, Int)
decode = Float -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
P.decodeFloat
   encode :: Integer -> Int -> Float
encode = Integer -> Int -> Float
forall a. RealFloat a => Integer -> Int -> a
P.encodeFloat
   exponent :: Float -> Int
exponent = Float -> Int
forall a. RealFloat a => a -> Int
P.exponent
   significand :: Float -> Float
significand = Float -> Float
forall a. RealFloat a => a -> a
P.significand
   scale :: Int -> Float -> Float
scale = Int -> Float -> Float
forall a. RealFloat a => Int -> a -> a
P.scaleFloat
   isNaN :: Float -> Bool
isNaN = Float -> Bool
forall a. RealFloat a => a -> Bool
P.isNaN
   isInfinite :: Float -> Bool
isInfinite = Float -> Bool
forall a. RealFloat a => a -> Bool
P.isInfinite
   isDenormalized :: Float -> Bool
isDenormalized = Float -> Bool
forall a. RealFloat a => a -> Bool
P.isDenormalized
   isNegativeZero :: Float -> Bool
isNegativeZero = Float -> Bool
forall a. RealFloat a => a -> Bool
P.isNegativeZero
   isIEEE :: Float -> Bool
isIEEE = Float -> Bool
forall a. RealFloat a => a -> Bool
P.isIEEE

instance C Double where
   radix :: Double -> Integer
radix = Double -> Integer
forall a. RealFloat a => a -> Integer
P.floatRadix
   digits :: Double -> Int
digits = Double -> Int
forall a. RealFloat a => a -> Int
P.floatDigits
   range :: Double -> (Int, Int)
range = Double -> (Int, Int)
forall a. RealFloat a => a -> (Int, Int)
P.floatRange
   decode :: Double -> (Integer, Int)
decode = Double -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
P.decodeFloat
   encode :: Integer -> Int -> Double
encode = Integer -> Int -> Double
forall a. RealFloat a => Integer -> Int -> a
P.encodeFloat
   exponent :: Double -> Int
exponent = Double -> Int
forall a. RealFloat a => a -> Int
P.exponent
   significand :: Double -> Double
significand = Double -> Double
forall a. RealFloat a => a -> a
P.significand
   scale :: Int -> Double -> Double
scale = Int -> Double -> Double
forall a. RealFloat a => Int -> a -> a
P.scaleFloat
   isNaN :: Double -> Bool
isNaN = Double -> Bool
forall a. RealFloat a => a -> Bool
P.isNaN
   isInfinite :: Double -> Bool
isInfinite = Double -> Bool
forall a. RealFloat a => a -> Bool
P.isInfinite
   isDenormalized :: Double -> Bool
isDenormalized = Double -> Bool
forall a. RealFloat a => a -> Bool
P.isDenormalized
   isNegativeZero :: Double -> Bool
isNegativeZero = Double -> Bool
forall a. RealFloat a => a -> Bool
P.isNegativeZero
   isIEEE :: Double -> Bool
isIEEE = Double -> Bool
forall a. RealFloat a => a -> Bool
P.isIEEE