module ParkBench.Prelude
  ( divide,
    divide',
    divideDouble,
    r2d,
    w2d,
    w2r,
    module X,
  )
where

import Control.Applicative as X
import Control.Monad as X
import Data.Coerce as X (coerce)
import Data.Foldable as X (fold, foldl')
import Data.Proxy as X (Proxy (..))
import Data.Text as X (Text)
import Data.Typeable as X (Typeable)
import Data.Word as X (Word64, Word8)
import GHC.Generics as X (Generic)
import Numeric.Natural as X (Natural)
import Prelude as X hiding (read)

divide :: Rational -> Rational -> Rational
divide :: Rational -> Rational -> Rational
divide Rational
n Rational
d =
  if Rational
d Rational -> Rational -> Bool
forall a. Eq a => a -> a -> Bool
== Rational
0 then Rational
0 else Rational
n Rational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/ Rational
d

divide' :: Rational -> Rational -> Maybe Rational
divide' :: Rational -> Rational -> Maybe Rational
divide' Rational
n Rational
d =
  if Rational
d Rational -> Rational -> Bool
forall a. Eq a => a -> a -> Bool
== Rational
0 then Maybe Rational
forall a. Maybe a
Nothing else Rational -> Maybe Rational
forall a. a -> Maybe a
Just (Rational
n Rational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/ Rational
d)

divideDouble :: Double -> Double -> Double
divideDouble :: Double -> Double -> Double
divideDouble Double
x Double
y =
  if Double
y Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
0 then Double
0 else Double
x Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
y

r2d :: Rational -> Double
r2d :: Rational -> Double
r2d = Rational -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac

w2d :: Word64 -> Double
w2d :: Word64 -> Double
w2d = Word64 -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral

w2r :: Word64 -> Rational
w2r :: Word64 -> Rational
w2r = Word64 -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral