{-# LINE 1 "src/Numeric/GMP/Types.hsc" #-}



{-# LINE 6 "src/Numeric/GMP/Types.hsc" #-}

{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

-- | GMP types.
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)

-- | @mpz_t@
data MPZ = MPZ
  { MPZ -> CInt
mpzAlloc :: !CInt
  , MPZ -> CInt
mpzSize :: !CInt
  , MPZ -> Ptr MPLimb
mpzD :: !(Ptr MPLimb)
  }

instance Storable MPZ where
  sizeOf :: MPZ -> Int
sizeOf MPZ
_ = ((Int
16))
{-# LINE 32 "src/Numeric/GMP/Types.hsc" #-}
  alignment _ = (8)
{-# LINE 33 "src/Numeric/GMP/Types.hsc" #-}
  peek ptr = do
    alloc <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
{-# LINE 35 "src/Numeric/GMP/Types.hsc" #-}
    size <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
{-# LINE 36 "src/Numeric/GMP/Types.hsc" #-}
    d <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
{-# LINE 37 "src/Numeric/GMP/Types.hsc" #-}
    return (MPZ{ mpzAlloc = alloc, mpzSize = size, mpzD = d })
  poke :: Ptr MPZ -> MPZ -> IO ()
poke Ptr MPZ
ptr (MPZ{ mpzAlloc :: MPZ -> CInt
mpzAlloc = CInt
alloc, mpzSize :: MPZ -> CInt
mpzSize = CInt
size, mpzD :: MPZ -> Ptr MPLimb
mpzD = Ptr MPLimb
d }) = do
    ((\Ptr MPZ
hsc_ptr -> Ptr MPZ -> Int -> CInt -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr MPZ
hsc_ptr Int
0)) Ptr MPZ
ptr CInt
alloc
{-# LINE 40 "src/Numeric/GMP/Types.hsc" #-}
    ((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr size
{-# LINE 41 "src/Numeric/GMP/Types.hsc" #-}
    ((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr d
{-# LINE 42 "src/Numeric/GMP/Types.hsc" #-}

-- | @mpq_t@
data MPQ = MPQ
  { MPQ -> MPZ
mpqNum :: !MPZ
  , MPQ -> MPZ
mpqDen :: !MPZ
  }

instance Storable MPQ where
  sizeOf :: MPQ -> Int
sizeOf MPQ
_ = ((Int
32))
{-# LINE 51 "src/Numeric/GMP/Types.hsc" #-}
  alignment _ = (8)
{-# LINE 52 "src/Numeric/GMP/Types.hsc" #-}
  peek ptr = do
    num <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
{-# LINE 54 "src/Numeric/GMP/Types.hsc" #-}
    den <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
{-# LINE 55 "src/Numeric/GMP/Types.hsc" #-}
    return (MPQ{ mpqNum = num, mpqDen = den })
  poke :: Ptr MPQ -> MPQ -> IO ()
poke Ptr MPQ
ptr (MPQ{ mpqNum :: MPQ -> MPZ
mpqNum = MPZ
num, mpqDen :: MPQ -> MPZ
mpqDen = MPZ
den }) = do
    ((\Ptr MPQ
hsc_ptr -> Ptr MPQ -> Int -> MPZ -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr MPQ
hsc_ptr Int
0)) Ptr MPQ
ptr MPZ
num
{-# LINE 58 "src/Numeric/GMP/Types.hsc" #-}
    ((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr den
{-# LINE 59 "src/Numeric/GMP/Types.hsc" #-}

-- | Get pointers to numerator and denominator (these are macros in the C API).
mpq_numref, mpq_denref :: Ptr MPQ -> Ptr MPZ
mpq_numref :: Ptr MPQ -> Ptr MPZ
mpq_numref Ptr MPQ
ptr = Ptr MPQ -> Int -> Ptr MPZ
forall a b. Ptr a -> Int -> Ptr b
plusPtr Ptr MPQ
ptr ((Int
0))
{-# LINE 63 "src/Numeric/GMP/Types.hsc" #-}
mpq_denref ptr = plusPtr ptr ((16))
{-# LINE 64 "src/Numeric/GMP/Types.hsc" #-}

-- | @mpf_t@
data MPF = MPF
  { MPF -> CInt
mpfPrec :: !CInt
  , MPF -> CInt
mpfSize :: !CInt
  , MPF -> MPExp
mpfExp :: !MPExp
  , MPF -> Ptr MPLimb
mpfD :: !(Ptr MPLimb)
  }

instance Storable MPF where
  sizeOf :: MPF -> Int
sizeOf MPF
_ = ((Int
24))
{-# LINE 75 "src/Numeric/GMP/Types.hsc" #-}
  alignment _ = (8)
{-# LINE 76 "src/Numeric/GMP/Types.hsc" #-}
  peek ptr = do
    prec <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
{-# LINE 78 "src/Numeric/GMP/Types.hsc" #-}
    size <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
{-# LINE 79 "src/Numeric/GMP/Types.hsc" #-}
    expo <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
{-# LINE 80 "src/Numeric/GMP/Types.hsc" #-}
    d <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
{-# LINE 81 "src/Numeric/GMP/Types.hsc" #-}
    return (MPF{ mpfPrec = prec, mpfSize = size, mpfExp = expo, mpfD = d })
  poke :: Ptr MPF -> MPF -> IO ()
poke Ptr MPF
ptr (MPF{ mpfPrec :: MPF -> CInt
mpfPrec = CInt
prec, mpfSize :: MPF -> CInt
mpfSize = CInt
size, mpfExp :: MPF -> MPExp
mpfExp = MPExp
expo, mpfD :: MPF -> Ptr MPLimb
mpfD = Ptr MPLimb
d }) = do
    ((\Ptr MPF
hsc_ptr -> Ptr MPF -> Int -> CInt -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr MPF
hsc_ptr Int
0)) Ptr MPF
ptr CInt
prec
{-# LINE 84 "src/Numeric/GMP/Types.hsc" #-}
    ((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr size
{-# LINE 85 "src/Numeric/GMP/Types.hsc" #-}
    ((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr expo
{-# LINE 86 "src/Numeric/GMP/Types.hsc" #-}
    ((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr d
{-# LINE 87 "src/Numeric/GMP/Types.hsc" #-}

-- | @gmp_randstate_t@
data GMPRandState = GMPRandState
  { GMPRandState -> MPZ
gmprsSeed :: !MPZ
  , GMPRandState -> GMPRandAlg
gmprsAlg :: !GMPRandAlg
  , GMPRandState -> Ptr ()
gmprsAlgData :: !(Ptr ())
  }

instance Storable GMPRandState where
  sizeOf :: GMPRandState -> Int
sizeOf GMPRandState
_ = ((Int
32))
{-# LINE 97 "src/Numeric/GMP/Types.hsc" #-}
  alignment _ = (8)
{-# LINE 98 "src/Numeric/GMP/Types.hsc" #-}
  peek ptr = do
    seed <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
{-# LINE 100 "src/Numeric/GMP/Types.hsc" #-}
    alg <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
{-# LINE 101 "src/Numeric/GMP/Types.hsc" #-}
    algdata <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
{-# LINE 102 "src/Numeric/GMP/Types.hsc" #-}
    return (GMPRandState{ gmprsSeed = seed, gmprsAlg = alg, gmprsAlgData = algdata })
  poke :: Ptr GMPRandState -> GMPRandState -> IO ()
poke Ptr GMPRandState
ptr (GMPRandState{ gmprsSeed :: GMPRandState -> MPZ
gmprsSeed = MPZ
seed, gmprsAlg :: GMPRandState -> GMPRandAlg
gmprsAlg = GMPRandAlg
alg, gmprsAlgData :: GMPRandState -> Ptr ()
gmprsAlgData = Ptr ()
algdata }) = do
    ((\Ptr GMPRandState
hsc_ptr -> Ptr GMPRandState -> Int -> MPZ -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr GMPRandState
hsc_ptr Int
0)) Ptr GMPRandState
ptr MPZ
seed
{-# LINE 105 "src/Numeric/GMP/Types.hsc" #-}
    ((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr alg
{-# LINE 106 "src/Numeric/GMP/Types.hsc" #-}
    ((\hsc_ptr -> pokeByteOff hsc_ptr 24)) ptr algdata
{-# LINE 107 "src/Numeric/GMP/Types.hsc" #-}

-- | @mp_limb_t@
newtype MPLimb = MPLimb (Word64)
{-# LINE 110 "src/Numeric/GMP/Types.hsc" #-}
  deriving (Eq, Ord, Read, Show, Enum, Bounded, Num, Integral, Real, Ix, Bits, FiniteBits, Data, Typeable, Storable)

-- | @mp_limb_signed_t@
newtype MPLimbSigned = MPLimbSigned (Int64)
{-# LINE 114 "src/Numeric/GMP/Types.hsc" #-}
  deriving (Eq, Ord, Read, Show, Enum, Bounded, Num, Integral, Real, Ix, Bits, FiniteBits, Data, Typeable, Storable)

-- | @mp_size_t@
newtype MPSize = MPSize (Int64)
{-# LINE 118 "src/Numeric/GMP/Types.hsc" #-}
  deriving (Eq, Ord, Read, Show, Enum, Bounded, Num, Integral, Real, Ix, Bits, FiniteBits, Data, Typeable, Storable)

-- | @mp_exp_t@
newtype MPExp = MPExp (Int64)
{-# LINE 122 "src/Numeric/GMP/Types.hsc" #-}
  deriving (Eq, Ord, Read, Show, Enum, Bounded, Num, Integral, Real, Ix, Bits, FiniteBits, Data, Typeable, Storable)

-- | @mp_bitcnt_t@
newtype MPBitCnt = MPBitCnt (Word64)
{-# LINE 126 "src/Numeric/GMP/Types.hsc" #-}
  deriving (Eq, Ord, Read, Show, Enum, Bounded, Num, Integral, Real, Ix, Bits, FiniteBits, Data, Typeable, Storable)

-- | @gmp_randalg_t@
newtype GMPRandAlg = GMPRandAlg (Word32)
{-# LINE 130 "src/Numeric/GMP/Types.hsc" #-}
  deriving (Eq, Ord, Read, Show, Enum, Bounded, Num, Integral, Real, Ix, Bits, FiniteBits, Data, Typeable, Storable)