module Numeric.GMP.Types where
import Data.Data
import Data.Typeable
import Data.Bits
import Data.Ix
import Data.Int
import Data.Word
import Foreign (Storable(..), Ptr, nullPtr, plusPtr)
import Foreign.C (CInt)
data MPZ = MPZ
{ mpzAlloc :: !CInt
, mpzSize :: !CInt
, mpzD :: !(Ptr MPLimb)
}
instance Storable MPZ where
sizeOf _ = ((16))
alignment _ = ((8))
peek ptr = do
alloc <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
size <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
d <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
return (MPZ{ mpzAlloc = alloc, mpzSize = size, mpzD = d })
poke ptr (MPZ{ mpzAlloc = alloc, mpzSize = size, mpzD = d }) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr alloc
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr size
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr d
data MPQ = MPQ
{ mpqNum :: !MPZ
, mpqDen :: !MPZ
}
instance Storable MPQ where
sizeOf _ = ((32))
alignment _ = ((8))
peek ptr = do
num <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
den <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
return (MPQ{ mpqNum = num, mpqDen = den })
poke ptr (MPQ{ mpqNum = num, mpqDen = den }) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr num
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr den
mpq_numref, mpq_denref :: Ptr MPQ -> Ptr MPZ
mpq_numref ptr = plusPtr ptr ((0))
mpq_denref ptr = plusPtr ptr ((16))
data MPF = MPF
{ mpfPrec :: !CInt
, mpfSize :: !CInt
, mpfExp :: !MPExp
, mpfD :: !(Ptr MPLimb)
}
instance Storable MPF where
sizeOf _ = ((24))
alignment _ = ((8))
peek ptr = do
prec <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
size <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
expo <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
d <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
return (MPF{ mpfPrec = prec, mpfSize = size, mpfExp = expo, mpfD = d })
poke ptr (MPF{ mpfPrec = prec, mpfSize = size, mpfExp = expo, mpfD = d }) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr prec
((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr size
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr expo
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr d
data GMPRandState = GMPRandState
{ gmprsSeed :: !MPZ
, gmprsAlg :: !GMPRandAlg
, gmprsAlgData :: !(Ptr ())
}
instance Storable GMPRandState where
sizeOf _ = ((32))
alignment _ = ((8))
peek ptr = do
seed <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
alg <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
algdata <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
return (GMPRandState{ gmprsSeed = seed, gmprsAlg = alg, gmprsAlgData = algdata })
poke ptr (GMPRandState{ gmprsSeed = seed, gmprsAlg = alg, gmprsAlgData = algdata }) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr seed
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr alg
((\hsc_ptr -> pokeByteOff hsc_ptr 24)) ptr algdata
newtype MPLimb = MPLimb (Word64)
deriving (Eq, Ord, Read, Show, Enum, Bounded, Num, Integral, Real, Ix, Bits, FiniteBits, Data, Typeable, Storable)
newtype MPLimbSigned = MPLimbSigned (Int64)
deriving (Eq, Ord, Read, Show, Enum, Bounded, Num, Integral, Real, Ix, Bits, FiniteBits, Data, Typeable, Storable)
newtype MPSize = MPSize (Int64)
deriving (Eq, Ord, Read, Show, Enum, Bounded, Num, Integral, Real, Ix, Bits, FiniteBits, Data, Typeable, Storable)
newtype MPExp = MPExp (Int64)
deriving (Eq, Ord, Read, Show, Enum, Bounded, Num, Integral, Real, Ix, Bits, FiniteBits, Data, Typeable, Storable)
newtype MPBitCnt = MPBitCnt (Word64)
deriving (Eq, Ord, Read, Show, Enum, Bounded, Num, Integral, Real, Ix, Bits, FiniteBits, Data, Typeable, Storable)
newtype GMPRandAlg = GMPRandAlg (Word32)
deriving (Eq, Ord, Read, Show, Enum, Bounded, Num, Integral, Real, Ix, Bits, FiniteBits, Data, Typeable, Storable)