module Incipit.Fixed where

import qualified Data.Fixed as Fixed
import Data.Maybe (Maybe)
import GHC.Real (Integral, Real)

import Incipit.Integral (safeOp)

-- | Generalisation of 'div' to any instance of 'Real'
div' ::
  Real a =>
  Integral b =>
  a ->
  a ->
  Maybe b
div' :: forall a b. (Real a, Integral b) => a -> a -> Maybe b
div' =
  (a -> a -> b) -> a -> a -> Maybe b
forall a b. Real a => (a -> a -> b) -> a -> a -> Maybe b
safeOp a -> a -> b
forall a b. (Real a, Integral b) => a -> a -> b
Fixed.div'

-- | Generalisation of 'divMod' to any instance of 'Real'
divMod' ::
  Real a =>
  Integral b =>
  a ->
  a ->
  Maybe (b, a)
divMod' :: forall a b. (Real a, Integral b) => a -> a -> Maybe (b, a)
divMod' =
  (a -> a -> (b, a)) -> a -> a -> Maybe (b, a)
forall a b. Real a => (a -> a -> b) -> a -> a -> Maybe b
safeOp a -> a -> (b, a)
forall a b. (Real a, Integral b) => a -> a -> (b, a)
Fixed.divMod'

-- | Generalisation of 'mod' to any instance of 'Real'
mod' ::
  Real a =>
  a ->
  a ->
  Maybe a
mod' :: forall a. Real a => a -> a -> Maybe a
mod' =
  (a -> a -> a) -> a -> a -> Maybe a
forall a b. Real a => (a -> a -> b) -> a -> a -> Maybe b
safeOp a -> a -> a
forall a. Real a => a -> a -> a
Fixed.mod'