{-# LANGUAGE CPP #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# OPTIONS_HADDOCK not-home #-}
module Numeric.AD.Internal.Or
( Or(..)
, F, T
, runL, runR
, Chosen(..)
, chosen
, unary
, binary
) where
import Data.Number.Erf
import Data.Typeable
import Numeric.AD.Mode
runL :: Or F a b -> a
runL :: forall a b. Or F a b -> a
runL (L a
a) = a
a
runR :: Or T a b -> b
runR :: forall a b. Or T a b -> b
runR (R b
b) = b
b
chosen :: (a -> r) -> (b -> r) -> Or s a b -> r
chosen :: forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> r
f b -> r
_ (L a
a) = a -> r
f a
a
chosen a -> r
_ b -> r
g (R b
b) = b -> r
g b
b
unary :: (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary :: forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
f b -> b
_ (L a
a) = a -> Or F a b
forall a b. a -> Or F a b
L (a -> a
f a
a)
unary a -> a
_ b -> b
g (R b
a) = b -> Or T a b
forall b a. b -> Or T a b
R (b -> b
g b
a)
binary :: (a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
binary :: forall a b s.
(a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
binary a -> a -> a
f b -> b -> b
_ (L a
a) (L a
b) = a -> Or F a b
forall a b. a -> Or F a b
L (a -> a -> a
f a
a a
b)
binary a -> a -> a
_ b -> b -> b
g (R b
a) (R b
b) = b -> Or T a b
forall b a. b -> Or T a b
R (b -> b -> b
g b
a b
b)
data F
data T
class Chosen s where
choose :: a -> b -> Or s a b
instance Chosen F where
choose :: forall a b. a -> b -> Or F a b
choose a
x b
_ = a -> Or F a b
forall a b. a -> Or F a b
L a
x
instance Chosen T where
choose :: forall a b. a -> b -> Or T a b
choose a
_ b
x = b -> Or T a b
forall b a. b -> Or T a b
R b
x
#ifndef HLINT
data Or s a b where
L :: a -> Or F a b
R :: b -> Or T a b
deriving Typeable
#endif
instance (Eq a, Eq b) => Eq (Or s a b) where
L a
a == :: Or s a b -> Or s a b -> Bool
== L a
b = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b
R b
a == R b
b = b
a b -> b -> Bool
forall a. Eq a => a -> a -> Bool
== b
b
instance (Ord a, Ord b) => Ord (Or s a b) where
L a
a compare :: Or s a b -> Or s a b -> Ordering
`compare` L a
b = a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare a
a a
b
R b
a `compare` R b
b = b -> b -> Ordering
forall a. Ord a => a -> a -> Ordering
compare b
a b
b
instance (Enum a, Enum b, Chosen s) => Enum (Or s a b) where
pred :: Or s a b -> Or s a b
pred = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Enum a => a -> a
pred b -> b
forall a. Enum a => a -> a
pred
succ :: Or s a b -> Or s a b
succ = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Enum a => a -> a
succ b -> b
forall a. Enum a => a -> a
succ
toEnum :: Int -> Or s a b
toEnum Int
i = a -> b -> Or s a b
forall s a b. Chosen s => a -> b -> Or s a b
forall a b. a -> b -> Or s a b
choose (Int -> a
forall a. Enum a => Int -> a
toEnum Int
i) (Int -> b
forall a. Enum a => Int -> a
toEnum Int
i)
fromEnum :: Or s a b -> Int
fromEnum = (a -> Int) -> (b -> Int) -> Or s a b -> Int
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> Int
forall a. Enum a => a -> Int
fromEnum b -> Int
forall a. Enum a => a -> Int
fromEnum
enumFrom :: Or s a b -> [Or s a b]
enumFrom (L a
a) = a -> Or s a b
a -> Or F a b
forall a b. a -> Or F a b
L (a -> Or s a b) -> [a] -> [Or s a b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> [a]
forall a. Enum a => a -> [a]
enumFrom a
a
enumFrom (R b
a) = b -> Or s a b
b -> Or T a b
forall b a. b -> Or T a b
R (b -> Or s a b) -> [b] -> [Or s a b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> [b]
forall a. Enum a => a -> [a]
enumFrom b
a
enumFromThen :: Or s a b -> Or s a b -> [Or s a b]
enumFromThen (L a
a) (L a
b) = a -> Or s a b
a -> Or F a b
forall a b. a -> Or F a b
L (a -> Or s a b) -> [a] -> [Or s a b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> a -> [a]
forall a. Enum a => a -> a -> [a]
enumFromThen a
a a
b
enumFromThen (R b
a) (R b
b) = b -> Or s a b
b -> Or T a b
forall b a. b -> Or T a b
R (b -> Or s a b) -> [b] -> [Or s a b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> b -> [b]
forall a. Enum a => a -> a -> [a]
enumFromThen b
a b
b
enumFromTo :: Or s a b -> Or s a b -> [Or s a b]
enumFromTo (L a
a) (L a
b) = a -> Or s a b
a -> Or F a b
forall a b. a -> Or F a b
L (a -> Or s a b) -> [a] -> [Or s a b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> a -> [a]
forall a. Enum a => a -> a -> [a]
enumFromTo a
a a
b
enumFromTo (R b
a) (R b
b) = b -> Or s a b
b -> Or T a b
forall b a. b -> Or T a b
R (b -> Or s a b) -> [b] -> [Or s a b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> b -> [b]
forall a. Enum a => a -> a -> [a]
enumFromTo b
a b
b
enumFromThenTo :: Or s a b -> Or s a b -> Or s a b -> [Or s a b]
enumFromThenTo (L a
a) (L a
b) (L a
c) = a -> Or s a b
a -> Or F a b
forall a b. a -> Or F a b
L (a -> Or s a b) -> [a] -> [Or s a b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> a -> a -> [a]
forall a. Enum a => a -> a -> a -> [a]
enumFromThenTo a
a a
b a
c
enumFromThenTo (R b
a) (R b
b) (R b
c) = b -> Or s a b
b -> Or T a b
forall b a. b -> Or T a b
R (b -> Or s a b) -> [b] -> [Or s a b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> b -> b -> [b]
forall a. Enum a => a -> a -> a -> [a]
enumFromThenTo b
a b
b b
c
instance (Bounded a, Bounded b, Chosen s) => Bounded (Or s a b) where
maxBound :: Or s a b
maxBound = a -> b -> Or s a b
forall s a b. Chosen s => a -> b -> Or s a b
forall a b. a -> b -> Or s a b
choose a
forall a. Bounded a => a
maxBound b
forall a. Bounded a => a
maxBound
minBound :: Or s a b
minBound = a -> b -> Or s a b
forall s a b. Chosen s => a -> b -> Or s a b
forall a b. a -> b -> Or s a b
choose a
forall a. Bounded a => a
minBound b
forall a. Bounded a => a
minBound
instance (Num a, Num b, Chosen s) => Num (Or s a b) where
+ :: Or s a b -> Or s a b -> Or s a b
(+) = (a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
forall a b s.
(a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
binary a -> a -> a
forall a. Num a => a -> a -> a
(+) b -> b -> b
forall a. Num a => a -> a -> a
(+)
(-) = (a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
forall a b s.
(a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
binary (-) (-)
* :: Or s a b -> Or s a b -> Or s a b
(*) = (a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
forall a b s.
(a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
binary a -> a -> a
forall a. Num a => a -> a -> a
(*) b -> b -> b
forall a. Num a => a -> a -> a
(*)
negate :: Or s a b -> Or s a b
negate = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Num a => a -> a
negate b -> b
forall a. Num a => a -> a
negate
abs :: Or s a b -> Or s a b
abs = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Num a => a -> a
abs b -> b
forall a. Num a => a -> a
abs
signum :: Or s a b -> Or s a b
signum = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Num a => a -> a
signum b -> b
forall a. Num a => a -> a
signum
fromInteger :: Integer -> Or s a b
fromInteger = a -> b -> Or s a b
forall s a b. Chosen s => a -> b -> Or s a b
forall a b. a -> b -> Or s a b
choose (a -> b -> Or s a b) -> (Integer -> a) -> Integer -> b -> Or s a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Integer -> a
forall a. Num a => Integer -> a
fromInteger (Integer -> b -> Or s a b) -> (Integer -> b) -> Integer -> Or s a b
forall a b. (Integer -> a -> b) -> (Integer -> a) -> Integer -> b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Integer -> b
forall a. Num a => Integer -> a
fromInteger
instance (Real a, Real b, Chosen s) => Real (Or s a b) where
toRational :: Or s a b -> Rational
toRational = (a -> Rational) -> (b -> Rational) -> Or s a b -> Rational
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> Rational
forall a. Real a => a -> Rational
toRational b -> Rational
forall a. Real a => a -> Rational
toRational
instance (Fractional a, Fractional b, Chosen s) => Fractional (Or s a b) where
/ :: Or s a b -> Or s a b -> Or s a b
(/) = (a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
forall a b s.
(a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
binary a -> a -> a
forall a. Fractional a => a -> a -> a
(/) b -> b -> b
forall a. Fractional a => a -> a -> a
(/)
recip :: Or s a b -> Or s a b
recip = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Fractional a => a -> a
recip b -> b
forall a. Fractional a => a -> a
recip
fromRational :: Rational -> Or s a b
fromRational = a -> b -> Or s a b
forall s a b. Chosen s => a -> b -> Or s a b
forall a b. a -> b -> Or s a b
choose (a -> b -> Or s a b)
-> (Rational -> a) -> Rational -> b -> Or s a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Rational -> a
forall a. Fractional a => Rational -> a
fromRational (Rational -> b -> Or s a b)
-> (Rational -> b) -> Rational -> Or s a b
forall a b.
(Rational -> a -> b) -> (Rational -> a) -> Rational -> b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Rational -> b
forall a. Fractional a => Rational -> a
fromRational
instance (RealFrac a, RealFrac b, Chosen s) => RealFrac (Or s a b) where
properFraction :: forall b. Integral b => Or s a b -> (b, Or s a b)
properFraction (L a
a) = case a -> (b, a)
forall b. Integral b => a -> (b, a)
forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction a
a of
(b
b, a
c) -> (b
b, a -> Or F a b
forall a b. a -> Or F a b
L a
c)
properFraction (R b
a) = case b -> (b, b)
forall b. Integral b => b -> (b, b)
forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction b
a of
(b
b, b
c) -> (b
b, b -> Or T a b
forall b a. b -> Or T a b
R b
c)
truncate :: forall b. Integral b => Or s a b -> b
truncate = (a -> b) -> (b -> b) -> Or s a b -> b
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> b
forall b. Integral b => a -> b
forall a b. (RealFrac a, Integral b) => a -> b
truncate b -> b
forall b. Integral b => b -> b
forall a b. (RealFrac a, Integral b) => a -> b
truncate
round :: forall b. Integral b => Or s a b -> b
round = (a -> b) -> (b -> b) -> Or s a b -> b
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> b
forall b. Integral b => a -> b
forall a b. (RealFrac a, Integral b) => a -> b
round b -> b
forall b. Integral b => b -> b
forall a b. (RealFrac a, Integral b) => a -> b
round
ceiling :: forall b. Integral b => Or s a b -> b
ceiling = (a -> b) -> (b -> b) -> Or s a b -> b
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> b
forall b. Integral b => a -> b
forall a b. (RealFrac a, Integral b) => a -> b
ceiling b -> b
forall b. Integral b => b -> b
forall a b. (RealFrac a, Integral b) => a -> b
ceiling
floor :: forall b. Integral b => Or s a b -> b
floor = (a -> b) -> (b -> b) -> Or s a b -> b
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> b
forall b. Integral b => a -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor b -> b
forall b. Integral b => b -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor
instance (Floating a, Floating b, Chosen s) => Floating (Or s a b) where
pi :: Or s a b
pi = a -> b -> Or s a b
forall s a b. Chosen s => a -> b -> Or s a b
forall a b. a -> b -> Or s a b
choose a
forall a. Floating a => a
pi b
forall a. Floating a => a
pi
exp :: Or s a b -> Or s a b
exp = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
exp b -> b
forall a. Floating a => a -> a
exp
sqrt :: Or s a b -> Or s a b
sqrt = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
sqrt b -> b
forall a. Floating a => a -> a
sqrt
log :: Or s a b -> Or s a b
log = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
log b -> b
forall a. Floating a => a -> a
log
** :: Or s a b -> Or s a b -> Or s a b
(**) = (a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
forall a b s.
(a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
binary a -> a -> a
forall a. Floating a => a -> a -> a
(**) b -> b -> b
forall a. Floating a => a -> a -> a
(**)
logBase :: Or s a b -> Or s a b -> Or s a b
logBase = (a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
forall a b s.
(a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
binary a -> a -> a
forall a. Floating a => a -> a -> a
logBase b -> b -> b
forall a. Floating a => a -> a -> a
logBase
sin :: Or s a b -> Or s a b
sin = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
sin b -> b
forall a. Floating a => a -> a
sin
tan :: Or s a b -> Or s a b
tan = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
tan b -> b
forall a. Floating a => a -> a
tan
cos :: Or s a b -> Or s a b
cos = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
cos b -> b
forall a. Floating a => a -> a
cos
asin :: Or s a b -> Or s a b
asin = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
asin b -> b
forall a. Floating a => a -> a
asin
atan :: Or s a b -> Or s a b
atan = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
atan b -> b
forall a. Floating a => a -> a
atan
acos :: Or s a b -> Or s a b
acos = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
acos b -> b
forall a. Floating a => a -> a
acos
sinh :: Or s a b -> Or s a b
sinh = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
sinh b -> b
forall a. Floating a => a -> a
sinh
tanh :: Or s a b -> Or s a b
tanh = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
tanh b -> b
forall a. Floating a => a -> a
tanh
cosh :: Or s a b -> Or s a b
cosh = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
cosh b -> b
forall a. Floating a => a -> a
cosh
asinh :: Or s a b -> Or s a b
asinh = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
asinh b -> b
forall a. Floating a => a -> a
asinh
atanh :: Or s a b -> Or s a b
atanh = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
atanh b -> b
forall a. Floating a => a -> a
atanh
acosh :: Or s a b -> Or s a b
acosh = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Floating a => a -> a
acosh b -> b
forall a. Floating a => a -> a
acosh
instance (Erf a, Erf b, Chosen s) => Erf (Or s a b) where
erf :: Or s a b -> Or s a b
erf = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Erf a => a -> a
erf b -> b
forall a. Erf a => a -> a
erf
erfc :: Or s a b -> Or s a b
erfc = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Erf a => a -> a
erfc b -> b
forall a. Erf a => a -> a
erfc
erfcx :: Or s a b -> Or s a b
erfcx = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Erf a => a -> a
erfcx b -> b
forall a. Erf a => a -> a
erfcx
normcdf :: Or s a b -> Or s a b
normcdf = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. Erf a => a -> a
normcdf b -> b
forall a. Erf a => a -> a
normcdf
instance (InvErf a, InvErf b, Chosen s) => InvErf (Or s a b) where
inverf :: Or s a b -> Or s a b
inverf = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. InvErf a => a -> a
inverf b -> b
forall a. InvErf a => a -> a
inverf
inverfc :: Or s a b -> Or s a b
inverfc = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. InvErf a => a -> a
inverfc b -> b
forall a. InvErf a => a -> a
inverfc
invnormcdf :: Or s a b -> Or s a b
invnormcdf = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. InvErf a => a -> a
invnormcdf b -> b
forall a. InvErf a => a -> a
invnormcdf
instance (RealFloat a, RealFloat b, Chosen s) => RealFloat (Or s a b) where
floatRadix :: Or s a b -> Integer
floatRadix = (a -> Integer) -> (b -> Integer) -> Or s a b -> Integer
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> Integer
forall a. RealFloat a => a -> Integer
floatRadix b -> Integer
forall a. RealFloat a => a -> Integer
floatRadix
floatDigits :: Or s a b -> Int
floatDigits = (a -> Int) -> (b -> Int) -> Or s a b -> Int
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> Int
forall a. RealFloat a => a -> Int
floatDigits b -> Int
forall a. RealFloat a => a -> Int
floatDigits
floatRange :: Or s a b -> (Int, Int)
floatRange = (a -> (Int, Int)) -> (b -> (Int, Int)) -> Or s a b -> (Int, Int)
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> (Int, Int)
forall a. RealFloat a => a -> (Int, Int)
floatRange b -> (Int, Int)
forall a. RealFloat a => a -> (Int, Int)
floatRange
decodeFloat :: Or s a b -> (Integer, Int)
decodeFloat = (a -> (Integer, Int))
-> (b -> (Integer, Int)) -> Or s a b -> (Integer, Int)
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat b -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat
encodeFloat :: Integer -> Int -> Or s a b
encodeFloat Integer
i Int
j = a -> b -> Or s a b
forall s a b. Chosen s => a -> b -> Or s a b
forall a b. a -> b -> Or s a b
choose (Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
i Int
j) (Integer -> Int -> b
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
i Int
j)
exponent :: Or s a b -> Int
exponent = (a -> Int) -> (b -> Int) -> Or s a b -> Int
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> Int
forall a. RealFloat a => a -> Int
exponent b -> Int
forall a. RealFloat a => a -> Int
exponent
significand :: Or s a b -> Or s a b
significand = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary a -> a
forall a. RealFloat a => a -> a
significand b -> b
forall a. RealFloat a => a -> a
significand
scaleFloat :: Int -> Or s a b -> Or s a b
scaleFloat = (a -> a) -> (b -> b) -> Or s a b -> Or s a b
forall a b s. (a -> a) -> (b -> b) -> Or s a b -> Or s a b
unary ((a -> a) -> (b -> b) -> Or s a b -> Or s a b)
-> (Int -> a -> a) -> Int -> (b -> b) -> Or s a b -> Or s a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> a -> a
forall a. RealFloat a => Int -> a -> a
scaleFloat (Int -> (b -> b) -> Or s a b -> Or s a b)
-> (Int -> b -> b) -> Int -> Or s a b -> Or s a b
forall a b. (Int -> a -> b) -> (Int -> a) -> Int -> b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> b -> b
forall a. RealFloat a => Int -> a -> a
scaleFloat
isNaN :: Or s a b -> Bool
isNaN = (a -> Bool) -> (b -> Bool) -> Or s a b -> Bool
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> Bool
forall a. RealFloat a => a -> Bool
isNaN b -> Bool
forall a. RealFloat a => a -> Bool
isNaN
isInfinite :: Or s a b -> Bool
isInfinite = (a -> Bool) -> (b -> Bool) -> Or s a b -> Bool
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> Bool
forall a. RealFloat a => a -> Bool
isInfinite b -> Bool
forall a. RealFloat a => a -> Bool
isInfinite
isDenormalized :: Or s a b -> Bool
isDenormalized = (a -> Bool) -> (b -> Bool) -> Or s a b -> Bool
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> Bool
forall a. RealFloat a => a -> Bool
isDenormalized b -> Bool
forall a. RealFloat a => a -> Bool
isDenormalized
isNegativeZero :: Or s a b -> Bool
isNegativeZero = (a -> Bool) -> (b -> Bool) -> Or s a b -> Bool
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero b -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero
isIEEE :: Or s a b -> Bool
isIEEE = (a -> Bool) -> (b -> Bool) -> Or s a b -> Bool
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> Bool
forall a. RealFloat a => a -> Bool
isIEEE b -> Bool
forall a. RealFloat a => a -> Bool
isIEEE
atan2 :: Or s a b -> Or s a b -> Or s a b
atan2 = (a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
forall a b s.
(a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b
binary a -> a -> a
forall a. RealFloat a => a -> a -> a
atan2 b -> b -> b
forall a. RealFloat a => a -> a -> a
atan2
instance (Mode a, Mode b, Chosen s, Scalar a ~ Scalar b) => Mode (Or s a b) where
type Scalar (Or s a b) = Scalar a
auto :: Scalar (Or s a b) -> Or s a b
auto = a -> b -> Or s a b
forall s a b. Chosen s => a -> b -> Or s a b
forall a b. a -> b -> Or s a b
choose (a -> b -> Or s a b)
-> (Scalar b -> a) -> Scalar b -> b -> Or s a b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Scalar a -> a
Scalar b -> a
forall t. Mode t => Scalar t -> t
auto (Scalar b -> b -> Or s a b)
-> (Scalar b -> b) -> Scalar b -> Or s a b
forall a b.
(Scalar b -> a -> b) -> (Scalar b -> a) -> Scalar b -> b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Scalar b -> b
forall t. Mode t => Scalar t -> t
auto
isKnownConstant :: Or s a b -> Bool
isKnownConstant = (a -> Bool) -> (b -> Bool) -> Or s a b -> Bool
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> Bool
forall t. Mode t => t -> Bool
isKnownConstant b -> Bool
forall t. Mode t => t -> Bool
isKnownConstant
asKnownConstant :: Or s a b -> Maybe (Scalar (Or s a b))
asKnownConstant (L a
a) = a -> Maybe (Scalar a)
forall t. Mode t => t -> Maybe (Scalar t)
asKnownConstant a
a
asKnownConstant (R b
b) = b -> Maybe (Scalar b)
forall t. Mode t => t -> Maybe (Scalar t)
asKnownConstant b
b
isKnownZero :: Or s a b -> Bool
isKnownZero = (a -> Bool) -> (b -> Bool) -> Or s a b -> Bool
forall a r b s. (a -> r) -> (b -> r) -> Or s a b -> r
chosen a -> Bool
forall t. Mode t => t -> Bool
isKnownZero b -> Bool
forall t. Mode t => t -> Bool
isKnownZero
Scalar (Or s a b)
x *^ :: Scalar (Or s a b) -> Or s a b -> Or s a b
*^ L a
a = a -> Or F a b
forall a b. a -> Or F a b
L (Scalar a
Scalar (Or s a b)
x Scalar a -> a -> a
forall t. Mode t => Scalar t -> t -> t
*^ a
a)
Scalar (Or s a b)
x *^ R b
a = b -> Or T a b
forall b a. b -> Or T a b
R (Scalar b
Scalar (Or s a b)
x Scalar b -> b -> b
forall t. Mode t => Scalar t -> t -> t
*^ b
a)
L a
a ^* :: Or s a b -> Scalar (Or s a b) -> Or s a b
^* Scalar (Or s a b)
x = a -> Or F a b
forall a b. a -> Or F a b
L (a
a a -> Scalar a -> a
forall t. Mode t => t -> Scalar t -> t
^* Scalar a
Scalar (Or s a b)
x)
R b
a ^* Scalar (Or s a b)
x = b -> Or T a b
forall b a. b -> Or T a b
R (b
a b -> Scalar b -> b
forall t. Mode t => t -> Scalar t -> t
^* Scalar b
Scalar (Or s a b)
x)
L a
a ^/ :: Fractional (Scalar (Or s a b)) =>
Or s a b -> Scalar (Or s a b) -> Or s a b
^/ Scalar (Or s a b)
x = a -> Or F a b
forall a b. a -> Or F a b
L (a
a a -> Scalar a -> a
forall t. (Mode t, Fractional (Scalar t)) => t -> Scalar t -> t
^/ Scalar a
Scalar (Or s a b)
x)
R b
a ^/ Scalar (Or s a b)
x = b -> Or T a b
forall b a. b -> Or T a b
R (b
a b -> Scalar b -> b
forall t. (Mode t, Fractional (Scalar t)) => t -> Scalar t -> t
^/ Scalar b
Scalar (Or s a b)
x)
zero :: Or s a b
zero = a -> b -> Or s a b
forall s a b. Chosen s => a -> b -> Or s a b
forall a b. a -> b -> Or s a b
choose a
forall t. Mode t => t
zero b
forall t. Mode t => t
zero