{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
module Numeric.Rounded.Hardware.Internal.Rounding
  ( RoundingMode(..)
  , oppositeRoundingMode
  , Rounding
  , rounding
  , reifyRounding
  , Rounded(..)
  , VUM.MVector(MV_Rounded)
  , VU.Vector(V_Rounded)
  ) where
import           Control.DeepSeq (NFData (..))
import           Data.Coerce
import           Data.Proxy
import           Data.Tagged
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Generic.Mutable as VGM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import           Foreign.Storable (Storable)
import           GHC.Generics (Generic)

-- See cbits/rounded.c for the ordering
-- | The type for IEEE754 rounding-direction attributes.
data RoundingMode
  = ToNearest     -- ^ Round to the nearest value (IEEE754 roundTiesToEven)
  | TowardNegInf  -- ^ Round downward (IEEE754 roundTowardNegative)
  | TowardInf     -- ^ Round upward (IEEE754 roundTowardPositive)
  | TowardZero    -- ^ Round toward zero (IEEE754 roundTowardZero)
  deriving (RoundingMode -> RoundingMode -> Bool
(RoundingMode -> RoundingMode -> Bool)
-> (RoundingMode -> RoundingMode -> Bool) -> Eq RoundingMode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RoundingMode -> RoundingMode -> Bool
$c/= :: RoundingMode -> RoundingMode -> Bool
== :: RoundingMode -> RoundingMode -> Bool
$c== :: RoundingMode -> RoundingMode -> Bool
Eq, Eq RoundingMode
Eq RoundingMode
-> (RoundingMode -> RoundingMode -> Ordering)
-> (RoundingMode -> RoundingMode -> Bool)
-> (RoundingMode -> RoundingMode -> Bool)
-> (RoundingMode -> RoundingMode -> Bool)
-> (RoundingMode -> RoundingMode -> Bool)
-> (RoundingMode -> RoundingMode -> RoundingMode)
-> (RoundingMode -> RoundingMode -> RoundingMode)
-> Ord RoundingMode
RoundingMode -> RoundingMode -> Bool
RoundingMode -> RoundingMode -> Ordering
RoundingMode -> RoundingMode -> RoundingMode
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: RoundingMode -> RoundingMode -> RoundingMode
$cmin :: RoundingMode -> RoundingMode -> RoundingMode
max :: RoundingMode -> RoundingMode -> RoundingMode
$cmax :: RoundingMode -> RoundingMode -> RoundingMode
>= :: RoundingMode -> RoundingMode -> Bool
$c>= :: RoundingMode -> RoundingMode -> Bool
> :: RoundingMode -> RoundingMode -> Bool
$c> :: RoundingMode -> RoundingMode -> Bool
<= :: RoundingMode -> RoundingMode -> Bool
$c<= :: RoundingMode -> RoundingMode -> Bool
< :: RoundingMode -> RoundingMode -> Bool
$c< :: RoundingMode -> RoundingMode -> Bool
compare :: RoundingMode -> RoundingMode -> Ordering
$ccompare :: RoundingMode -> RoundingMode -> Ordering
$cp1Ord :: Eq RoundingMode
Ord, ReadPrec [RoundingMode]
ReadPrec RoundingMode
Int -> ReadS RoundingMode
ReadS [RoundingMode]
(Int -> ReadS RoundingMode)
-> ReadS [RoundingMode]
-> ReadPrec RoundingMode
-> ReadPrec [RoundingMode]
-> Read RoundingMode
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RoundingMode]
$creadListPrec :: ReadPrec [RoundingMode]
readPrec :: ReadPrec RoundingMode
$creadPrec :: ReadPrec RoundingMode
readList :: ReadS [RoundingMode]
$creadList :: ReadS [RoundingMode]
readsPrec :: Int -> ReadS RoundingMode
$creadsPrec :: Int -> ReadS RoundingMode
Read, Int -> RoundingMode -> ShowS
[RoundingMode] -> ShowS
RoundingMode -> String
(Int -> RoundingMode -> ShowS)
-> (RoundingMode -> String)
-> ([RoundingMode] -> ShowS)
-> Show RoundingMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RoundingMode] -> ShowS
$cshowList :: [RoundingMode] -> ShowS
show :: RoundingMode -> String
$cshow :: RoundingMode -> String
showsPrec :: Int -> RoundingMode -> ShowS
$cshowsPrec :: Int -> RoundingMode -> ShowS
Show, Int -> RoundingMode
RoundingMode -> Int
RoundingMode -> [RoundingMode]
RoundingMode -> RoundingMode
RoundingMode -> RoundingMode -> [RoundingMode]
RoundingMode -> RoundingMode -> RoundingMode -> [RoundingMode]
(RoundingMode -> RoundingMode)
-> (RoundingMode -> RoundingMode)
-> (Int -> RoundingMode)
-> (RoundingMode -> Int)
-> (RoundingMode -> [RoundingMode])
-> (RoundingMode -> RoundingMode -> [RoundingMode])
-> (RoundingMode -> RoundingMode -> [RoundingMode])
-> (RoundingMode -> RoundingMode -> RoundingMode -> [RoundingMode])
-> Enum RoundingMode
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: RoundingMode -> RoundingMode -> RoundingMode -> [RoundingMode]
$cenumFromThenTo :: RoundingMode -> RoundingMode -> RoundingMode -> [RoundingMode]
enumFromTo :: RoundingMode -> RoundingMode -> [RoundingMode]
$cenumFromTo :: RoundingMode -> RoundingMode -> [RoundingMode]
enumFromThen :: RoundingMode -> RoundingMode -> [RoundingMode]
$cenumFromThen :: RoundingMode -> RoundingMode -> [RoundingMode]
enumFrom :: RoundingMode -> [RoundingMode]
$cenumFrom :: RoundingMode -> [RoundingMode]
fromEnum :: RoundingMode -> Int
$cfromEnum :: RoundingMode -> Int
toEnum :: Int -> RoundingMode
$ctoEnum :: Int -> RoundingMode
pred :: RoundingMode -> RoundingMode
$cpred :: RoundingMode -> RoundingMode
succ :: RoundingMode -> RoundingMode
$csucc :: RoundingMode -> RoundingMode
Enum, RoundingMode
RoundingMode -> RoundingMode -> Bounded RoundingMode
forall a. a -> a -> Bounded a
maxBound :: RoundingMode
$cmaxBound :: RoundingMode
minBound :: RoundingMode
$cminBound :: RoundingMode
Bounded, (forall x. RoundingMode -> Rep RoundingMode x)
-> (forall x. Rep RoundingMode x -> RoundingMode)
-> Generic RoundingMode
forall x. Rep RoundingMode x -> RoundingMode
forall x. RoundingMode -> Rep RoundingMode x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RoundingMode x -> RoundingMode
$cfrom :: forall x. RoundingMode -> Rep RoundingMode x
Generic)

instance NFData RoundingMode

-- | Returns the opposite rounding direction.
--
-- @TowardNegInf@ and @TowardInf@ are swapped.
oppositeRoundingMode :: RoundingMode -> RoundingMode
oppositeRoundingMode :: RoundingMode -> RoundingMode
oppositeRoundingMode RoundingMode
ToNearest    = RoundingMode
ToNearest
oppositeRoundingMode RoundingMode
TowardZero   = RoundingMode
TowardZero
oppositeRoundingMode RoundingMode
TowardInf    = RoundingMode
TowardNegInf
oppositeRoundingMode RoundingMode
TowardNegInf = RoundingMode
TowardInf

-- | This class allows you to recover the runtime value from a type-level rounding mode.
--
-- See 'rounding'.
class Rounding (r :: RoundingMode) where
  roundingT :: Tagged r RoundingMode

instance Rounding 'ToNearest where
  roundingT :: Tagged 'ToNearest RoundingMode
roundingT = RoundingMode -> Tagged 'ToNearest RoundingMode
forall k (s :: k) b. b -> Tagged s b
Tagged RoundingMode
ToNearest

instance Rounding 'TowardInf where
  roundingT :: Tagged 'TowardInf RoundingMode
roundingT = RoundingMode -> Tagged 'TowardInf RoundingMode
forall k (s :: k) b. b -> Tagged s b
Tagged RoundingMode
TowardInf

instance Rounding 'TowardNegInf where
  roundingT :: Tagged 'TowardNegInf RoundingMode
roundingT = RoundingMode -> Tagged 'TowardNegInf RoundingMode
forall k (s :: k) b. b -> Tagged s b
Tagged RoundingMode
TowardNegInf

instance Rounding 'TowardZero where
  roundingT :: Tagged 'TowardZero RoundingMode
roundingT = RoundingMode -> Tagged 'TowardZero RoundingMode
forall k (s :: k) b. b -> Tagged s b
Tagged RoundingMode
TowardZero

-- | Recovers the value from type-level rounding mode.
rounding :: Rounding r => proxy r -> RoundingMode
rounding :: proxy r -> RoundingMode
rounding = Tagged r RoundingMode -> proxy r -> RoundingMode
forall k (s :: k) a (proxy :: k -> *). Tagged s a -> proxy s -> a
Data.Tagged.proxy Tagged r RoundingMode
forall (r :: RoundingMode). Rounding r => Tagged r RoundingMode
roundingT
{-# INLINE rounding #-}

-- | Lifts a rounding mode to type-level.
reifyRounding :: RoundingMode -> (forall s. Rounding s => Proxy s -> a) -> a
reifyRounding :: RoundingMode
-> (forall (s :: RoundingMode). Rounding s => Proxy s -> a) -> a
reifyRounding RoundingMode
ToNearest forall (s :: RoundingMode). Rounding s => Proxy s -> a
f    = Proxy 'ToNearest -> a
forall (s :: RoundingMode). Rounding s => Proxy s -> a
f (Proxy 'ToNearest
forall k (t :: k). Proxy t
Proxy :: Proxy 'ToNearest)
reifyRounding RoundingMode
TowardInf forall (s :: RoundingMode). Rounding s => Proxy s -> a
f    = Proxy 'TowardInf -> a
forall (s :: RoundingMode). Rounding s => Proxy s -> a
f (Proxy 'TowardInf
forall k (t :: k). Proxy t
Proxy :: Proxy 'TowardInf)
reifyRounding RoundingMode
TowardNegInf forall (s :: RoundingMode). Rounding s => Proxy s -> a
f = Proxy 'TowardNegInf -> a
forall (s :: RoundingMode). Rounding s => Proxy s -> a
f (Proxy 'TowardNegInf
forall k (t :: k). Proxy t
Proxy :: Proxy 'TowardNegInf)
reifyRounding RoundingMode
TowardZero forall (s :: RoundingMode). Rounding s => Proxy s -> a
f   = Proxy 'TowardZero -> a
forall (s :: RoundingMode). Rounding s => Proxy s -> a
f (Proxy 'TowardZero
forall k (t :: k). Proxy t
Proxy :: Proxy 'TowardZero)
{-# INLINE reifyRounding #-}

-- | A type tagged with a rounding direction.
--
-- The rounding direction is effective for a /single/ operation.
-- You won't get the correctly-rounded result for a compound expression like @(a - b * c) :: Rounded 'TowardInf Double@.
--
-- In particular, a negative literal like @-0.1 :: Rounded r Double@ doesn't yield the correctly-rounded value for @-0.1@.
-- To get the correct value, call 'fromRational' explicitly (i.e. @fromRational (-0.1) :: Rounded r Double@) or use @NegativeLiterals@ extension.
newtype Rounded (r :: RoundingMode) a = Rounded { Rounded r a -> a
getRounded :: a }
  deriving (Rounded r a -> Rounded r a -> Bool
(Rounded r a -> Rounded r a -> Bool)
-> (Rounded r a -> Rounded r a -> Bool) -> Eq (Rounded r a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (r :: RoundingMode) a.
Eq a =>
Rounded r a -> Rounded r a -> Bool
/= :: Rounded r a -> Rounded r a -> Bool
$c/= :: forall (r :: RoundingMode) a.
Eq a =>
Rounded r a -> Rounded r a -> Bool
== :: Rounded r a -> Rounded r a -> Bool
$c== :: forall (r :: RoundingMode) a.
Eq a =>
Rounded r a -> Rounded r a -> Bool
Eq, Eq (Rounded r a)
Eq (Rounded r a)
-> (Rounded r a -> Rounded r a -> Ordering)
-> (Rounded r a -> Rounded r a -> Bool)
-> (Rounded r a -> Rounded r a -> Bool)
-> (Rounded r a -> Rounded r a -> Bool)
-> (Rounded r a -> Rounded r a -> Bool)
-> (Rounded r a -> Rounded r a -> Rounded r a)
-> (Rounded r a -> Rounded r a -> Rounded r a)
-> Ord (Rounded r a)
Rounded r a -> Rounded r a -> Bool
Rounded r a -> Rounded r a -> Ordering
Rounded r a -> Rounded r a -> Rounded r a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall (r :: RoundingMode) a. Ord a => Eq (Rounded r a)
forall (r :: RoundingMode) a.
Ord a =>
Rounded r a -> Rounded r a -> Bool
forall (r :: RoundingMode) a.
Ord a =>
Rounded r a -> Rounded r a -> Ordering
forall (r :: RoundingMode) a.
Ord a =>
Rounded r a -> Rounded r a -> Rounded r a
min :: Rounded r a -> Rounded r a -> Rounded r a
$cmin :: forall (r :: RoundingMode) a.
Ord a =>
Rounded r a -> Rounded r a -> Rounded r a
max :: Rounded r a -> Rounded r a -> Rounded r a
$cmax :: forall (r :: RoundingMode) a.
Ord a =>
Rounded r a -> Rounded r a -> Rounded r a
>= :: Rounded r a -> Rounded r a -> Bool
$c>= :: forall (r :: RoundingMode) a.
Ord a =>
Rounded r a -> Rounded r a -> Bool
> :: Rounded r a -> Rounded r a -> Bool
$c> :: forall (r :: RoundingMode) a.
Ord a =>
Rounded r a -> Rounded r a -> Bool
<= :: Rounded r a -> Rounded r a -> Bool
$c<= :: forall (r :: RoundingMode) a.
Ord a =>
Rounded r a -> Rounded r a -> Bool
< :: Rounded r a -> Rounded r a -> Bool
$c< :: forall (r :: RoundingMode) a.
Ord a =>
Rounded r a -> Rounded r a -> Bool
compare :: Rounded r a -> Rounded r a -> Ordering
$ccompare :: forall (r :: RoundingMode) a.
Ord a =>
Rounded r a -> Rounded r a -> Ordering
$cp1Ord :: forall (r :: RoundingMode) a. Ord a => Eq (Rounded r a)
Ord, (forall x. Rounded r a -> Rep (Rounded r a) x)
-> (forall x. Rep (Rounded r a) x -> Rounded r a)
-> Generic (Rounded r a)
forall x. Rep (Rounded r a) x -> Rounded r a
forall x. Rounded r a -> Rep (Rounded r a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (r :: RoundingMode) a x. Rep (Rounded r a) x -> Rounded r a
forall (r :: RoundingMode) a x. Rounded r a -> Rep (Rounded r a) x
$cto :: forall (r :: RoundingMode) a x. Rep (Rounded r a) x -> Rounded r a
$cfrom :: forall (r :: RoundingMode) a x. Rounded r a -> Rep (Rounded r a) x
Generic, a -> Rounded r b -> Rounded r a
(a -> b) -> Rounded r a -> Rounded r b
(forall a b. (a -> b) -> Rounded r a -> Rounded r b)
-> (forall a b. a -> Rounded r b -> Rounded r a)
-> Functor (Rounded r)
forall a b. a -> Rounded r b -> Rounded r a
forall a b. (a -> b) -> Rounded r a -> Rounded r b
forall (r :: RoundingMode) a b. a -> Rounded r b -> Rounded r a
forall (r :: RoundingMode) a b.
(a -> b) -> Rounded r a -> Rounded r b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Rounded r b -> Rounded r a
$c<$ :: forall (r :: RoundingMode) a b. a -> Rounded r b -> Rounded r a
fmap :: (a -> b) -> Rounded r a -> Rounded r b
$cfmap :: forall (r :: RoundingMode) a b.
(a -> b) -> Rounded r a -> Rounded r b
Functor, Ptr b -> Int -> IO (Rounded r a)
Ptr b -> Int -> Rounded r a -> IO ()
Ptr (Rounded r a) -> IO (Rounded r a)
Ptr (Rounded r a) -> Int -> IO (Rounded r a)
Ptr (Rounded r a) -> Int -> Rounded r a -> IO ()
Ptr (Rounded r a) -> Rounded r a -> IO ()
Rounded r a -> Int
(Rounded r a -> Int)
-> (Rounded r a -> Int)
-> (Ptr (Rounded r a) -> Int -> IO (Rounded r a))
-> (Ptr (Rounded r a) -> Int -> Rounded r a -> IO ())
-> (forall b. Ptr b -> Int -> IO (Rounded r a))
-> (forall b. Ptr b -> Int -> Rounded r a -> IO ())
-> (Ptr (Rounded r a) -> IO (Rounded r a))
-> (Ptr (Rounded r a) -> Rounded r a -> IO ())
-> Storable (Rounded r a)
forall b. Ptr b -> Int -> IO (Rounded r a)
forall b. Ptr b -> Int -> Rounded r a -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
forall (r :: RoundingMode) a.
Storable a =>
Ptr (Rounded r a) -> IO (Rounded r a)
forall (r :: RoundingMode) a.
Storable a =>
Ptr (Rounded r a) -> Int -> IO (Rounded r a)
forall (r :: RoundingMode) a.
Storable a =>
Ptr (Rounded r a) -> Int -> Rounded r a -> IO ()
forall (r :: RoundingMode) a.
Storable a =>
Ptr (Rounded r a) -> Rounded r a -> IO ()
forall (r :: RoundingMode) a. Storable a => Rounded r a -> Int
forall (r :: RoundingMode) a b.
Storable a =>
Ptr b -> Int -> IO (Rounded r a)
forall (r :: RoundingMode) a b.
Storable a =>
Ptr b -> Int -> Rounded r a -> IO ()
poke :: Ptr (Rounded r a) -> Rounded r a -> IO ()
$cpoke :: forall (r :: RoundingMode) a.
Storable a =>
Ptr (Rounded r a) -> Rounded r a -> IO ()
peek :: Ptr (Rounded r a) -> IO (Rounded r a)
$cpeek :: forall (r :: RoundingMode) a.
Storable a =>
Ptr (Rounded r a) -> IO (Rounded r a)
pokeByteOff :: Ptr b -> Int -> Rounded r a -> IO ()
$cpokeByteOff :: forall (r :: RoundingMode) a b.
Storable a =>
Ptr b -> Int -> Rounded r a -> IO ()
peekByteOff :: Ptr b -> Int -> IO (Rounded r a)
$cpeekByteOff :: forall (r :: RoundingMode) a b.
Storable a =>
Ptr b -> Int -> IO (Rounded r a)
pokeElemOff :: Ptr (Rounded r a) -> Int -> Rounded r a -> IO ()
$cpokeElemOff :: forall (r :: RoundingMode) a.
Storable a =>
Ptr (Rounded r a) -> Int -> Rounded r a -> IO ()
peekElemOff :: Ptr (Rounded r a) -> Int -> IO (Rounded r a)
$cpeekElemOff :: forall (r :: RoundingMode) a.
Storable a =>
Ptr (Rounded r a) -> Int -> IO (Rounded r a)
alignment :: Rounded r a -> Int
$calignment :: forall (r :: RoundingMode) a. Storable a => Rounded r a -> Int
sizeOf :: Rounded r a -> Int
$csizeOf :: forall (r :: RoundingMode) a. Storable a => Rounded r a -> Int
Storable)

instance Show a => Show (Rounded r a) where
  -- TODO: Take the rounding direction into account
  showsPrec :: Int -> Rounded r a -> ShowS
showsPrec Int
prec (Rounded a
x) = Bool -> ShowS -> ShowS
showParen (Int
prec Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"Rounded " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 a
x

instance NFData a => NFData (Rounded r a)

-- Orphan instances:
-- instance Num (Rounded r a) is defined in Numeric.Rounded.Hardware.Internal.Class.
-- instance Fractional (Rounded r a) is defined in Numeric.Rounded.Hardware.Internal.Class.
-- instance Real (Rounded r a) is defined in Numeric.Rounded.Hardware.Internal.Class.
-- instance RealFrac (Rounded r a) is defined in Numeric.Rounded.Hardware.Internal.Class.
-- instance Floating (Rounded r a) is not implemented (something like CRlibm would be needed)

newtype instance VUM.MVector s (Rounded r a) = MV_Rounded (VUM.MVector s a)
newtype instance VU.Vector (Rounded r a) = V_Rounded (VU.Vector a)

instance VU.Unbox a => VGM.MVector VUM.MVector (Rounded r a) where
  basicLength :: MVector s (Rounded r a) -> Int
basicLength (MV_Rounded mv) = MVector s a -> Int
forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
VGM.basicLength MVector s a
mv
  basicUnsafeSlice :: Int -> Int -> MVector s (Rounded r a) -> MVector s (Rounded r a)
basicUnsafeSlice Int
i Int
l (MV_Rounded mv) = MVector s a -> MVector s (Rounded r a)
forall s (r :: RoundingMode) a.
MVector s a -> MVector s (Rounded r a)
MV_Rounded (Int -> Int -> MVector s a -> MVector s a
forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
VGM.basicUnsafeSlice Int
i Int
l MVector s a
mv)
  basicOverlaps :: MVector s (Rounded r a) -> MVector s (Rounded r a) -> Bool
basicOverlaps (MV_Rounded mv) (MV_Rounded mv') = MVector s a -> MVector s a -> Bool
forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
VGM.basicOverlaps MVector s a
mv MVector s a
mv'
  basicUnsafeNew :: Int -> m (MVector (PrimState m) (Rounded r a))
basicUnsafeNew Int
l = MVector (PrimState m) a -> MVector (PrimState m) (Rounded r a)
forall s (r :: RoundingMode) a.
MVector s a -> MVector s (Rounded r a)
MV_Rounded (MVector (PrimState m) a -> MVector (PrimState m) (Rounded r a))
-> m (MVector (PrimState m) a)
-> m (MVector (PrimState m) (Rounded r a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> m (MVector (PrimState m) a)
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
Int -> m (v (PrimState m) a)
VGM.basicUnsafeNew Int
l
  basicInitialize :: MVector (PrimState m) (Rounded r a) -> m ()
basicInitialize (MV_Rounded mv) = MVector (PrimState m) a -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> m ()
VGM.basicInitialize MVector (PrimState m) a
mv
  basicUnsafeReplicate :: Int -> Rounded r a -> m (MVector (PrimState m) (Rounded r a))
basicUnsafeReplicate Int
i Rounded r a
x = MVector (PrimState m) a -> MVector (PrimState m) (Rounded r a)
forall s (r :: RoundingMode) a.
MVector s a -> MVector s (Rounded r a)
MV_Rounded (MVector (PrimState m) a -> MVector (PrimState m) (Rounded r a))
-> m (MVector (PrimState m) a)
-> m (MVector (PrimState m) (Rounded r a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> a -> m (MVector (PrimState m) a)
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
Int -> a -> m (v (PrimState m) a)
VGM.basicUnsafeReplicate Int
i (Rounded r a -> a
coerce Rounded r a
x)
  basicUnsafeRead :: MVector (PrimState m) (Rounded r a) -> Int -> m (Rounded r a)
basicUnsafeRead (MV_Rounded mv) Int
i = a -> Rounded r a
coerce (a -> Rounded r a) -> m a -> m (Rounded r a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MVector (PrimState m) a -> Int -> m a
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> m a
VGM.basicUnsafeRead MVector (PrimState m) a
mv Int
i
  basicUnsafeWrite :: MVector (PrimState m) (Rounded r a) -> Int -> Rounded r a -> m ()
basicUnsafeWrite (MV_Rounded mv) Int
i Rounded r a
x = MVector (PrimState m) a -> Int -> a -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> a -> m ()
VGM.basicUnsafeWrite MVector (PrimState m) a
mv Int
i (Rounded r a -> a
coerce Rounded r a
x)
  basicClear :: MVector (PrimState m) (Rounded r a) -> m ()
basicClear (MV_Rounded mv) = MVector (PrimState m) a -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> m ()
VGM.basicClear MVector (PrimState m) a
mv
  basicSet :: MVector (PrimState m) (Rounded r a) -> Rounded r a -> m ()
basicSet (MV_Rounded mv) Rounded r a
x = MVector (PrimState m) a -> a -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> a -> m ()
VGM.basicSet MVector (PrimState m) a
mv (Rounded r a -> a
coerce Rounded r a
x)
  basicUnsafeCopy :: MVector (PrimState m) (Rounded r a)
-> MVector (PrimState m) (Rounded r a) -> m ()
basicUnsafeCopy (MV_Rounded mv) (MV_Rounded mv') = MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> v (PrimState m) a -> m ()
VGM.basicUnsafeCopy MVector (PrimState m) a
mv MVector (PrimState m) a
mv'
  basicUnsafeMove :: MVector (PrimState m) (Rounded r a)
-> MVector (PrimState m) (Rounded r a) -> m ()
basicUnsafeMove (MV_Rounded mv) (MV_Rounded mv') = MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> v (PrimState m) a -> m ()
VGM.basicUnsafeMove MVector (PrimState m) a
mv MVector (PrimState m) a
mv'
  basicUnsafeGrow :: MVector (PrimState m) (Rounded r a)
-> Int -> m (MVector (PrimState m) (Rounded r a))
basicUnsafeGrow (MV_Rounded mv) Int
n = MVector (PrimState m) a -> MVector (PrimState m) (Rounded r a)
forall s (r :: RoundingMode) a.
MVector s a -> MVector s (Rounded r a)
MV_Rounded (MVector (PrimState m) a -> MVector (PrimState m) (Rounded r a))
-> m (MVector (PrimState m) a)
-> m (MVector (PrimState m) (Rounded r a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> m (v (PrimState m) a)
VGM.basicUnsafeGrow MVector (PrimState m) a
mv Int
n

instance VU.Unbox a => VG.Vector VU.Vector (Rounded r a) where
  basicUnsafeFreeze :: Mutable Vector (PrimState m) (Rounded r a)
-> m (Vector (Rounded r a))
basicUnsafeFreeze (MV_Rounded mv) = Vector a -> Vector (Rounded r a)
forall (r :: RoundingMode) a. Vector a -> Vector (Rounded r a)
V_Rounded (Vector a -> Vector (Rounded r a))
-> m (Vector a) -> m (Vector (Rounded r a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mutable Vector (PrimState m) a -> m (Vector a)
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
Mutable v (PrimState m) a -> m (v a)
VG.basicUnsafeFreeze MVector (PrimState m) a
Mutable Vector (PrimState m) a
mv
  basicUnsafeThaw :: Vector (Rounded r a)
-> m (Mutable Vector (PrimState m) (Rounded r a))
basicUnsafeThaw (V_Rounded v) = MVector (PrimState m) a -> MVector (PrimState m) (Rounded r a)
forall s (r :: RoundingMode) a.
MVector s a -> MVector s (Rounded r a)
MV_Rounded (MVector (PrimState m) a -> MVector (PrimState m) (Rounded r a))
-> m (MVector (PrimState m) a)
-> m (MVector (PrimState m) (Rounded r a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Vector a -> m (Mutable Vector (PrimState m) a)
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
v a -> m (Mutable v (PrimState m) a)
VG.basicUnsafeThaw Vector a
v
  basicLength :: Vector (Rounded r a) -> Int
basicLength (V_Rounded v) = Vector a -> Int
forall (v :: * -> *) a. Vector v a => v a -> Int
VG.basicLength Vector a
v
  basicUnsafeSlice :: Int -> Int -> Vector (Rounded r a) -> Vector (Rounded r a)
basicUnsafeSlice Int
i Int
l (V_Rounded v) = Vector a -> Vector (Rounded r a)
forall (r :: RoundingMode) a. Vector a -> Vector (Rounded r a)
V_Rounded (Int -> Int -> Vector a -> Vector a
forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
VG.basicUnsafeSlice Int
i Int
l Vector a
v)
  basicUnsafeIndexM :: Vector (Rounded r a) -> Int -> m (Rounded r a)
basicUnsafeIndexM (V_Rounded v) Int
i = a -> Rounded r a
coerce (a -> Rounded r a) -> m a -> m (Rounded r a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Vector a -> Int -> m a
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, Monad m) =>
v a -> Int -> m a
VG.basicUnsafeIndexM Vector a
v Int
i
  basicUnsafeCopy :: Mutable Vector (PrimState m) (Rounded r a)
-> Vector (Rounded r a) -> m ()
basicUnsafeCopy (MV_Rounded mv) (V_Rounded v) = Mutable Vector (PrimState m) a -> Vector a -> m ()
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
Mutable v (PrimState m) a -> v a -> m ()
VG.basicUnsafeCopy MVector (PrimState m) a
Mutable Vector (PrimState m) a
mv Vector a
v
  elemseq :: Vector (Rounded r a) -> Rounded r a -> b -> b
elemseq (V_Rounded v) Rounded r a
x b
y = Vector a -> a -> b -> b
forall (v :: * -> *) a b. Vector v a => v a -> a -> b -> b
VG.elemseq Vector a
v (Rounded r a -> a
coerce Rounded r a
x) b
y

instance VU.Unbox a => VU.Unbox (Rounded r a)