{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE BlockArguments #-}

#include "MachDeps.h"

-- |
-- Module      :  GHC.Integer.GMP.Internals
-- Copyright   :  (c) Herbert Valerio Riedel 2014
-- License     :  BSD3
--
-- Maintainer  :  ghc-devs@haskell.org
-- Stability   :  provisional
-- Portability :  non-portable (GHC Extensions)
--
module GHC.Integer.GMP.Internals
    ( -- * The 'Integer' type
      Integer (S#,Jn#,Jp#)
    , isValidInteger#

      -- ** Basic 'Integer' operations

    , module GHC.Integer

      -- ** Additional 'Integer' operations
    , gcdInteger
    , gcdExtInteger
    , lcmInteger
    , sqrInteger
    , powModInteger
    , recipModInteger

      -- ** Additional conversion operations to 'Integer'
    , wordToNegInteger
    , bigNatToInteger
    , bigNatToNegInteger

      -- * The 'BigNat' type
    , BigNat(..)

    , GmpLimb, GmpLimb#
    , GmpSize, GmpSize#

      -- **

    , isValidBigNat#
    , sizeofBigNat#
    , zeroBigNat
    , oneBigNat

      -- ** Conversions to/from 'BigNat'

    , byteArrayToBigNat#
    , wordToBigNat
    , wordToBigNat2
    , bigNatToInt
    , bigNatToWord
    , indexBigNat#

      -- ** 'BigNat' arithmetic operations
    , plusBigNat
    , plusBigNatWord
    , minusBigNat
    , minusBigNatWord
    , timesBigNat
    , timesBigNatWord
    , sqrBigNat

    , quotRemBigNat
    , quotRemBigNatWord
    , quotBigNatWord
    , quotBigNat
    , remBigNat
    , remBigNatWord

    , gcdBigNat
    , gcdBigNatWord

      -- ** 'BigNat' logic operations
    , shiftRBigNat
    , shiftLBigNat
    , testBitBigNat
    , clearBitBigNat
    , complementBitBigNat
    , setBitBigNat
    , andBigNat
    , xorBigNat
    , popCountBigNat
    , orBigNat
    , bitBigNat

      -- ** 'BigNat' comparison predicates
    , isZeroBigNat

    , compareBigNatWord
    , compareBigNat
    , eqBigNatWord
    , eqBigNatWord#
    , eqBigNat
    , eqBigNat#
    , gtBigNatWord#

      -- * Import/export functions
      -- ** Compute size of serialisation
    , sizeInBaseBigNat
    , sizeInBaseInteger
    , sizeInBaseWord#

      -- ** Export
    , exportBigNatToAddr
    , exportIntegerToAddr

    , exportBigNatToMutableByteArray
    , exportIntegerToMutableByteArray

      -- ** Import
    , importBigNatFromAddr
    , importIntegerFromAddr

    , importBigNatFromByteArray
    , importIntegerFromByteArray
    ) where

import GHC.Integer
import GHC.Natural
import GHC.Num.Integer (Integer(..))
import qualified GHC.Num.Integer as I
import qualified GHC.Num.BigNat as B
import qualified GHC.Num.Primitives as P
import GHC.Types
import GHC.Prim
import GHC.Exts (runRW#)
import Control.Exception

{-# COMPLETE S#, Jp#, Jn# #-}

{-# DEPRECATED S# "Use IS constructor instead" #-}
pattern S# :: Int# -> Integer
pattern $mS# :: forall {r}. Integer -> (Int# -> r) -> ((# #) -> r) -> r
$bS# :: Int# -> Integer
S# i = IS i

fromBN# :: BigNat -> ByteArray#
fromBN# :: BigNat -> ByteArray#
fromBN# (BN# ByteArray#
x) = ByteArray#
x

fromIP :: Integer -> (# () | BigNat #)
fromIP :: Integer -> (# () | BigNat #)
fromIP (IP ByteArray#
x) = (# | ByteArray# -> BigNat
BN# ByteArray#
x #)
fromIP Integer
_      = (# () | #)

fromIN :: Integer -> (# () | BigNat #)
fromIN :: Integer -> (# () | BigNat #)
fromIN (IN ByteArray#
x) = (# | ByteArray# -> BigNat
BN# ByteArray#
x #)
fromIN Integer
_      = (# () | #)

{-# DEPRECATED Jp# "Use IP constructor instead" #-}
pattern Jp# :: BigNat -> Integer
pattern $mJp# :: forall {r}. Integer -> (BigNat -> r) -> ((# #) -> r) -> r
$bJp# :: BigNat -> Integer
Jp# i <- (fromIP -> (# | i #))
   where
      Jp# BigNat
i = ByteArray# -> Integer
IP (BigNat -> ByteArray#
fromBN# BigNat
i)

{-# DEPRECATED Jn# "Use IN constructor instead" #-}
pattern Jn# :: BigNat -> Integer
pattern $mJn# :: forall {r}. Integer -> (BigNat -> r) -> ((# #) -> r) -> r
$bJn# :: BigNat -> Integer
Jn# i <- (fromIN -> (# | i #))
   where
      Jn# BigNat
i = ByteArray# -> Integer
IN (BigNat -> ByteArray#
fromBN# BigNat
i)

{-# DEPRECATED isValidInteger# "Use integerCheck# instead" #-}
isValidInteger# :: Integer -> Int#
isValidInteger# :: Integer -> Int#
isValidInteger# = Integer -> Int#
I.integerCheck#

{-# DEPRECATED gcdInteger "Use integerGcd instead" #-}
gcdInteger :: Integer -> Integer -> Integer
gcdInteger :: Integer -> Integer -> Integer
gcdInteger = Integer -> Integer -> Integer
I.integerGcd

{-# DEPRECATED gcdExtInteger "Use integerGcde instead" #-}
gcdExtInteger :: Integer -> Integer -> (# Integer, Integer #)
gcdExtInteger :: Integer -> Integer -> (# Integer, Integer #)
gcdExtInteger Integer
a Integer
b = case Integer -> Integer -> (# Integer, Integer, Integer #)
I.integerGcde# Integer
a Integer
b of
   (# Integer
g, Integer
s, Integer
_t #) -> (# Integer
g, Integer
s #)


{-# DEPRECATED lcmInteger "Use integerLcm instead" #-}
lcmInteger :: Integer -> Integer -> Integer
lcmInteger :: Integer -> Integer -> Integer
lcmInteger = Integer -> Integer -> Integer
I.integerLcm

{-# DEPRECATED sqrInteger "Use integerSqr instead" #-}
sqrInteger :: Integer -> Integer
sqrInteger :: Integer -> Integer
sqrInteger = Integer -> Integer
I.integerSqr

{-# DEPRECATED recipModInteger "Use integerRecipMod# instead" #-}
recipModInteger :: Integer -> Integer -> Integer
recipModInteger :: Integer -> Integer -> Integer
recipModInteger Integer
x Integer
m = case Integer -> Natural -> (# Natural | () #)
I.integerRecipMod# Integer
x (Integer -> Natural
I.integerToNatural Integer
m) of
   (# Natural
y |    #) -> Natural -> Integer
I.integerFromNatural Natural
y
   (#   | () #) -> Integer
0

{-# DEPRECATED powModInteger "Use integerPowMod# instead" #-}
powModInteger :: Integer -> Integer -> Integer -> Integer
powModInteger :: Integer -> Integer -> Integer -> Integer
powModInteger Integer
b Integer
e Integer
m = case Integer -> Integer -> Natural -> (# Natural | () #)
I.integerPowMod# Integer
b Integer
e (Integer -> Natural
I.integerToNatural Integer
m) of
   (# Natural
r  | #) -> Natural -> Integer
I.integerFromNatural Natural
r
   (# | () #) -> Integer
0

{-# DEPRECATED wordToNegInteger "Use integerFromWordNeg# instead" #-}
wordToNegInteger :: Word# -> Integer
wordToNegInteger :: Word# -> Integer
wordToNegInteger = Word# -> Integer
I.integerFromWordNeg#

{-# DEPRECATED bigNatToInteger "Use integerFromBigNat# instead" #-}
bigNatToInteger :: BigNat -> Integer
bigNatToInteger :: BigNat -> Integer
bigNatToInteger (BN# ByteArray#
i) = ByteArray# -> Integer
I.integerFromBigNat# ByteArray#
i

{-# DEPRECATED bigNatToNegInteger "Use integerFromBigNatNeg# instead" #-}
bigNatToNegInteger :: BigNat -> Integer
bigNatToNegInteger :: BigNat -> Integer
bigNatToNegInteger (BN# ByteArray#
i) = ByteArray# -> Integer
I.integerFromBigNatNeg# ByteArray#
i

type GmpLimb = Word
type GmpLimb# = Word#
type GmpSize = Int
type GmpSize# = Int#

{-# DEPRECATED sizeofBigNat# "Use bigNatSize# instead" #-}
sizeofBigNat# :: BigNat -> GmpSize#
sizeofBigNat# :: BigNat -> Int#
sizeofBigNat# (BN# ByteArray#
i) = ByteArray# -> Int#
B.bigNatSize# ByteArray#
i

{-# DEPRECATED isValidBigNat# "Use bigNatCheck# instead" #-}
isValidBigNat# :: BigNat -> Int#
isValidBigNat# :: BigNat -> Int#
isValidBigNat# (BN# ByteArray#
i) = ByteArray# -> Int#
B.bigNatCheck# ByteArray#
i

{-# DEPRECATED zeroBigNat "Use bigNatZero instead" #-}
zeroBigNat :: BigNat
zeroBigNat :: BigNat
zeroBigNat = BigNat
B.bigNatZero

{-# DEPRECATED oneBigNat "Use bigNatOne instead" #-}
oneBigNat :: BigNat
oneBigNat :: BigNat
oneBigNat = BigNat
B.bigNatOne

{-# DEPRECATED plusBigNat "Use bigNatAdd instead" #-}
plusBigNat :: BigNat -> BigNat -> BigNat
plusBigNat :: BigNat -> BigNat -> BigNat
plusBigNat (BN# ByteArray#
a) (BN# ByteArray#
b) = ByteArray# -> BigNat
BN# (ByteArray# -> ByteArray# -> ByteArray#
B.bigNatAdd ByteArray#
a ByteArray#
b)

{-# DEPRECATED plusBigNatWord "Use bigNatAddWord# instead" #-}
plusBigNatWord :: BigNat -> GmpLimb# -> BigNat
plusBigNatWord :: BigNat -> Word# -> BigNat
plusBigNatWord (BN# ByteArray#
a) Word#
w = ByteArray# -> BigNat
BN# (ByteArray# -> Word# -> ByteArray#
B.bigNatAddWord# ByteArray#
a Word#
w)

{-# DEPRECATED minusBigNat "Use bigNatSub instead" #-}
minusBigNat :: BigNat -> BigNat -> BigNat
minusBigNat :: BigNat -> BigNat -> BigNat
minusBigNat (BN# ByteArray#
a) (BN# ByteArray#
b) = case ByteArray# -> ByteArray# -> (# (# #) | ByteArray# #)
B.bigNatSub ByteArray#
a ByteArray#
b of
   (# (# #) | #)   -> forall a e. Exception e => e -> a
throw ArithException
Underflow
   (#       | ByteArray#
r #) -> ByteArray# -> BigNat
BN# ByteArray#
r

{-# DEPRECATED minusBigNatWord "Use bigNatSubWord# instead" #-}
minusBigNatWord :: BigNat -> GmpLimb# -> BigNat
minusBigNatWord :: BigNat -> Word# -> BigNat
minusBigNatWord (BN# ByteArray#
a) Word#
b = case ByteArray# -> Word# -> (# (# #) | ByteArray# #)
B.bigNatSubWord# ByteArray#
a Word#
b of
   (# (# #) | #)   -> forall a e. Exception e => e -> a
throw ArithException
Underflow
   (#       | ByteArray#
r #) -> ByteArray# -> BigNat
BN# ByteArray#
r


{-# DEPRECATED timesBigNat "Use bigNatMul instead" #-}
timesBigNat :: BigNat -> BigNat -> BigNat
timesBigNat :: BigNat -> BigNat -> BigNat
timesBigNat (BN# ByteArray#
a) (BN# ByteArray#
b) = ByteArray# -> BigNat
BN# (ByteArray# -> ByteArray# -> ByteArray#
B.bigNatMul ByteArray#
a ByteArray#
b)

{-# DEPRECATED timesBigNatWord "Use bigNatMulWord# instead" #-}
timesBigNatWord :: BigNat -> GmpLimb# -> BigNat
timesBigNatWord :: BigNat -> Word# -> BigNat
timesBigNatWord (BN# ByteArray#
a) Word#
w = ByteArray# -> BigNat
BN# (ByteArray# -> Word# -> ByteArray#
B.bigNatMulWord# ByteArray#
a Word#
w)

{-# DEPRECATED sqrBigNat "Use bigNatSqr instead" #-}
sqrBigNat :: BigNat -> BigNat
sqrBigNat :: BigNat -> BigNat
sqrBigNat (BN# ByteArray#
a) = ByteArray# -> BigNat
BN# (ByteArray# -> ByteArray#
B.bigNatSqr ByteArray#
a)

{-# DEPRECATED quotRemBigNat "Use bigNatQuotRem# instead" #-}
quotRemBigNat :: BigNat -> BigNat -> (# BigNat,BigNat #)
quotRemBigNat :: BigNat -> BigNat -> (# BigNat, BigNat #)
quotRemBigNat (BN# ByteArray#
a) (BN# ByteArray#
b) = case ByteArray# -> ByteArray# -> (# ByteArray#, ByteArray# #)
B.bigNatQuotRem# ByteArray#
a ByteArray#
b of
   (# ByteArray#
q, ByteArray#
r #) -> (# ByteArray# -> BigNat
BN# ByteArray#
q, ByteArray# -> BigNat
BN# ByteArray#
r #)

{-# DEPRECATED quotRemBigNatWord "Use bigNatQuotRemWord# instead" #-}
quotRemBigNatWord :: BigNat -> GmpLimb# -> (# BigNat, GmpLimb# #)
quotRemBigNatWord :: BigNat -> Word# -> (# BigNat, Word# #)
quotRemBigNatWord (BN# ByteArray#
a) Word#
b = case ByteArray# -> Word# -> (# ByteArray#, Word# #)
B.bigNatQuotRemWord# ByteArray#
a Word#
b of
   (# ByteArray#
q, Word#
r #) -> (# ByteArray# -> BigNat
BN# ByteArray#
q, Word#
r #)

{-# DEPRECATED quotBigNat "Use bigNatQuot instead" #-}
quotBigNat :: BigNat -> BigNat -> BigNat
quotBigNat :: BigNat -> BigNat -> BigNat
quotBigNat (BN# ByteArray#
a) (BN# ByteArray#
b) = ByteArray# -> BigNat
BN# (ByteArray# -> ByteArray# -> ByteArray#
B.bigNatQuot ByteArray#
a ByteArray#
b)

{-# DEPRECATED quotBigNatWord "Use bigNatQuotWord# instead" #-}
quotBigNatWord :: BigNat -> GmpLimb# -> BigNat
quotBigNatWord :: BigNat -> Word# -> BigNat
quotBigNatWord (BN# ByteArray#
a) Word#
b = ByteArray# -> BigNat
BN# (ByteArray# -> Word# -> ByteArray#
B.bigNatQuotWord# ByteArray#
a Word#
b)

{-# DEPRECATED remBigNat "Use bigNatRem instead" #-}
remBigNat :: BigNat -> BigNat -> BigNat
remBigNat :: BigNat -> BigNat -> BigNat
remBigNat (BN# ByteArray#
a) (BN# ByteArray#
b) = ByteArray# -> BigNat
BN# (ByteArray# -> ByteArray# -> ByteArray#
B.bigNatRem ByteArray#
a ByteArray#
b)

{-# DEPRECATED remBigNatWord "Use bigNatRemWord# instead" #-}
remBigNatWord :: BigNat -> GmpLimb# -> Word#
remBigNatWord :: BigNat -> Word# -> Word#
remBigNatWord (BN# ByteArray#
a) Word#
b = ByteArray# -> Word# -> Word#
B.bigNatRemWord# ByteArray#
a Word#
b

{-# DEPRECATED gcdBigNatWord "Use bigNatGcdWord# instead" #-}
gcdBigNatWord :: BigNat -> Word# -> Word#
gcdBigNatWord :: BigNat -> Word# -> Word#
gcdBigNatWord (BN# ByteArray#
a) Word#
b = ByteArray# -> Word# -> Word#
B.bigNatGcdWord# ByteArray#
a Word#
b

{-# DEPRECATED gcdBigNat "Use bigNatGcd instead" #-}
gcdBigNat:: BigNat -> BigNat -> BigNat
gcdBigNat :: BigNat -> BigNat -> BigNat
gcdBigNat (BN# ByteArray#
a) (BN# ByteArray#
b) = ByteArray# -> BigNat
BN# (ByteArray# -> ByteArray# -> ByteArray#
B.bigNatGcd ByteArray#
a ByteArray#
b)

{-# DEPRECATED shiftRBigNat "Use bigNatShiftR# instead" #-}
shiftRBigNat :: BigNat -> Int# -> BigNat
shiftRBigNat :: BigNat -> Int# -> BigNat
shiftRBigNat (BN# ByteArray#
a) Int#
i = ByteArray# -> BigNat
BN# (ByteArray# -> Word# -> ByteArray#
B.bigNatShiftR# ByteArray#
a (Int# -> Word#
int2Word# Int#
i))

{-# DEPRECATED shiftLBigNat "Use bigNatShiftL# instead" #-}
shiftLBigNat :: BigNat -> Int# -> BigNat
shiftLBigNat :: BigNat -> Int# -> BigNat
shiftLBigNat (BN# ByteArray#
a) Int#
i = ByteArray# -> BigNat
BN# (ByteArray# -> Word# -> ByteArray#
B.bigNatShiftL# ByteArray#
a (Int# -> Word#
int2Word# Int#
i))

{-# DEPRECATED testBitBigNat "Use bigNatTestBit# instead" #-}
testBitBigNat :: BigNat -> Int# -> Bool
testBitBigNat :: BigNat -> Int# -> Bool
testBitBigNat (BN# ByteArray#
a) Int#
i = Int# -> Bool
isTrue# (ByteArray# -> Word# -> Int#
B.bigNatTestBit# ByteArray#
a (Int# -> Word#
int2Word# Int#
i))

{-# DEPRECATED clearBitBigNat "Use bigNatClearBit# instead" #-}
clearBitBigNat :: BigNat -> Int# -> BigNat
clearBitBigNat :: BigNat -> Int# -> BigNat
clearBitBigNat (BN# ByteArray#
a) Int#
i = ByteArray# -> BigNat
BN# (ByteArray# -> Word# -> ByteArray#
B.bigNatClearBit# ByteArray#
a (Int# -> Word#
int2Word# Int#
i))

{-# DEPRECATED complementBitBigNat "Use bigNatComplementBit# instead" #-}
complementBitBigNat :: BigNat -> Int# -> BigNat
complementBitBigNat :: BigNat -> Int# -> BigNat
complementBitBigNat (BN# ByteArray#
a) Int#
i = ByteArray# -> BigNat
BN# (ByteArray# -> Word# -> ByteArray#
B.bigNatComplementBit# ByteArray#
a (Int# -> Word#
int2Word# Int#
i))

{-# DEPRECATED setBitBigNat "Use bigNatSetBit# instead" #-}
setBitBigNat :: BigNat -> Int# -> BigNat
setBitBigNat :: BigNat -> Int# -> BigNat
setBitBigNat (BN# ByteArray#
a) Int#
i = ByteArray# -> BigNat
BN# (ByteArray# -> Word# -> ByteArray#
B.bigNatSetBit# ByteArray#
a (Int# -> Word#
int2Word# Int#
i))

{-# DEPRECATED andBigNat "Use bigNatAnd instead" #-}
andBigNat :: BigNat -> BigNat -> BigNat
andBigNat :: BigNat -> BigNat -> BigNat
andBigNat (BN# ByteArray#
a) (BN# ByteArray#
b) = ByteArray# -> BigNat
BN# (ByteArray# -> ByteArray# -> ByteArray#
B.bigNatAnd ByteArray#
a ByteArray#
b)

{-# DEPRECATED orBigNat "Use bigNatOr instead" #-}
orBigNat :: BigNat -> BigNat -> BigNat
orBigNat :: BigNat -> BigNat -> BigNat
orBigNat (BN# ByteArray#
a) (BN# ByteArray#
b) = ByteArray# -> BigNat
BN# (ByteArray# -> ByteArray# -> ByteArray#
B.bigNatOr ByteArray#
a ByteArray#
b)

{-# DEPRECATED xorBigNat "Use bigNatXor instead" #-}
xorBigNat :: BigNat -> BigNat -> BigNat
xorBigNat :: BigNat -> BigNat -> BigNat
xorBigNat (BN# ByteArray#
a) (BN# ByteArray#
b) = ByteArray# -> BigNat
BN# (ByteArray# -> ByteArray# -> ByteArray#
B.bigNatXor ByteArray#
a ByteArray#
b)

{-# DEPRECATED popCountBigNat "Use bigNatPopCount# instead" #-}
popCountBigNat :: BigNat -> Int#
popCountBigNat :: BigNat -> Int#
popCountBigNat (BN# ByteArray#
a) = Word# -> Int#
word2Int# (ByteArray# -> Word#
B.bigNatPopCount# ByteArray#
a)

{-# DEPRECATED bitBigNat "Use bigNatBit# instead" #-}
bitBigNat :: Int# -> BigNat
bitBigNat :: Int# -> BigNat
bitBigNat Int#
i = ByteArray# -> BigNat
BN# (Word# -> ByteArray#
B.bigNatBit# (Int# -> Word#
int2Word# Int#
i))

{-# DEPRECATED isZeroBigNat "Use bigNatIsZero instead" #-}
isZeroBigNat :: BigNat -> Bool
isZeroBigNat :: BigNat -> Bool
isZeroBigNat (BN# ByteArray#
a) = ByteArray# -> Bool
B.bigNatIsZero ByteArray#
a

{-# DEPRECATED compareBigNat "Use bigNatCompare instead" #-}
compareBigNat :: BigNat -> BigNat -> Ordering
compareBigNat :: BigNat -> BigNat -> Ordering
compareBigNat (BN# ByteArray#
a) (BN# ByteArray#
b) = ByteArray# -> ByteArray# -> Ordering
B.bigNatCompare ByteArray#
a ByteArray#
b

{-# DEPRECATED compareBigNatWord "Use bigNatCompareWord# instead" #-}
compareBigNatWord :: BigNat -> GmpLimb# -> Ordering
compareBigNatWord :: BigNat -> Word# -> Ordering
compareBigNatWord (BN# ByteArray#
a) Word#
w = ByteArray# -> Word# -> Ordering
B.bigNatCompareWord# ByteArray#
a Word#
w

{-# DEPRECATED eqBigNatWord "Use bigNatEqWord# instead" #-}
eqBigNatWord :: BigNat -> GmpLimb# -> Bool
eqBigNatWord :: BigNat -> Word# -> Bool
eqBigNatWord (BN# ByteArray#
a) Word#
w = Int# -> Bool
isTrue# (ByteArray# -> Word# -> Int#
B.bigNatEqWord# ByteArray#
a Word#
w)

{-# DEPRECATED eqBigNatWord# "Use bigNatEqWord# instead" #-}
eqBigNatWord# :: BigNat -> GmpLimb# -> Int#
eqBigNatWord# :: BigNat -> Word# -> Int#
eqBigNatWord# (BN# ByteArray#
a) Word#
w = ByteArray# -> Word# -> Int#
B.bigNatEqWord# ByteArray#
a Word#
w

{-# DEPRECATED eqBigNat# "Use bigNatEq# instead" #-}
eqBigNat# :: BigNat -> BigNat -> Int#
eqBigNat# :: BigNat -> BigNat -> Int#
eqBigNat# (BN# ByteArray#
a) (BN# ByteArray#
b) = ByteArray# -> ByteArray# -> Int#
B.bigNatEq# ByteArray#
a ByteArray#
b

{-# DEPRECATED eqBigNat "Use bigNatEq instead" #-}
eqBigNat :: BigNat -> BigNat -> Bool
eqBigNat :: BigNat -> BigNat -> Bool
eqBigNat (BN# ByteArray#
a) (BN# ByteArray#
b) = ByteArray# -> ByteArray# -> Bool
B.bigNatEq ByteArray#
a ByteArray#
b

{-# DEPRECATED gtBigNatWord# "Use bigNatGtWord# instead" #-}
gtBigNatWord# :: BigNat -> GmpLimb# -> Int#
gtBigNatWord# :: BigNat -> Word# -> Int#
gtBigNatWord# (BN# ByteArray#
a) Word#
w = ByteArray# -> Word# -> Int#
B.bigNatGtWord# ByteArray#
a Word#
w

{-# DEPRECATED sizeInBaseBigNat "Use bigNatSizeInBase# instead" #-}
sizeInBaseBigNat :: BigNat -> Int# -> Word#
sizeInBaseBigNat :: BigNat -> Int# -> Word#
sizeInBaseBigNat (BN# ByteArray#
a) Int#
b = Word# -> ByteArray# -> Word#
B.bigNatSizeInBase# (Int# -> Word#
int2Word# Int#
b) ByteArray#
a

{-# DEPRECATED sizeInBaseInteger "Use integerSizeInBase# instead" #-}
sizeInBaseInteger :: Integer -> Int# -> Word#
sizeInBaseInteger :: Integer -> Int# -> Word#
sizeInBaseInteger Integer
i Int#
b = Word# -> Integer -> Word#
I.integerSizeInBase# (Int# -> Word#
int2Word# Int#
b) Integer
i

{-# DEPRECATED sizeInBaseWord# "Use wordSizeInBase# instead" #-}
sizeInBaseWord# :: Word# -> Int# -> Word#
sizeInBaseWord# :: Word# -> Int# -> Word#
sizeInBaseWord# Word#
a Int#
b = Word# -> Word# -> Word#
P.wordSizeInBase# (Int# -> Word#
int2Word# Int#
b) Word#
a

{-# DEPRECATED importBigNatFromAddr "Use bigNatFromAddr# instead" #-}
importBigNatFromAddr :: Addr# -> Word# -> Int# -> IO BigNat
importBigNatFromAddr :: Addr# -> Word# -> Int# -> IO BigNat
importBigNatFromAddr Addr#
addr Word#
sz Int#
endian = forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO \State# RealWorld
s ->
   case forall s.
Word# -> Addr# -> Int# -> State# s -> (# State# s, ByteArray# #)
B.bigNatFromAddr# Word#
sz Addr#
addr Int#
endian State# RealWorld
s of
      (# State# RealWorld
s', ByteArray#
b #) -> (# State# RealWorld
s', ByteArray# -> BigNat
BN# ByteArray#
b #)

{-# DEPRECATED exportBigNatToAddr "Use bigNatToAddr# instead" #-}
exportBigNatToAddr :: BigNat -> Addr# -> Int# -> IO Word
exportBigNatToAddr :: BigNat -> Addr# -> Int# -> IO Word
exportBigNatToAddr (BN# ByteArray#
b) Addr#
addr Int#
endian = forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO \State# RealWorld
s ->
   case forall s.
ByteArray# -> Addr# -> Int# -> State# s -> (# State# s, Word# #)
B.bigNatToAddr# ByteArray#
b Addr#
addr Int#
endian State# RealWorld
s of
      (# State# RealWorld
s', Word#
w #) -> (# State# RealWorld
s', Word# -> Word
W# Word#
w #)

{-# DEPRECATED importIntegerFromAddr "Use integerFromAddr# instead" #-}
importIntegerFromAddr :: Addr# -> Word# -> Int# -> IO Integer
importIntegerFromAddr :: Addr# -> Word# -> Int# -> IO Integer
importIntegerFromAddr Addr#
addr Word#
sz Int#
endian = forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO \State# RealWorld
s ->
   case forall s.
Word# -> Addr# -> Int# -> State# s -> (# State# s, Integer #)
I.integerFromAddr# Word#
sz Addr#
addr Int#
endian State# RealWorld
s of
      (# State# RealWorld
s', Integer
i #) -> (# State# RealWorld
s', Integer
i #)

{-# DEPRECATED exportIntegerToAddr "Use integerToAddr# instead" #-}
exportIntegerToAddr :: Integer -> Addr# -> Int# -> IO Word
exportIntegerToAddr :: Integer -> Addr# -> Int# -> IO Word
exportIntegerToAddr Integer
i Addr#
addr Int#
endian = forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO \State# RealWorld
s ->
   case forall s.
Integer -> Addr# -> Int# -> State# s -> (# State# s, Word# #)
I.integerToAddr# Integer
i Addr#
addr Int#
endian State# RealWorld
s of
      (# State# RealWorld
s', Word#
w #) -> (# State# RealWorld
s', Word# -> Word
W# Word#
w #)

wordToBigNat :: Word# -> BigNat
wordToBigNat :: Word# -> BigNat
wordToBigNat Word#
w = ByteArray# -> BigNat
BN# (Word# -> ByteArray#
B.bigNatFromWord# Word#
w)

wordToBigNat2 :: Word# -> Word# -> BigNat
wordToBigNat2 :: Word# -> Word# -> BigNat
wordToBigNat2 Word#
h Word#
l = ByteArray# -> BigNat
BN# (Word# -> Word# -> ByteArray#
B.bigNatFromWord2# Word#
h Word#
l)

bigNatToInt :: BigNat -> Int#
bigNatToInt :: BigNat -> Int#
bigNatToInt (BN# ByteArray#
b) = ByteArray# -> Int#
B.bigNatToInt# ByteArray#
b

bigNatToWord :: BigNat -> Word#
bigNatToWord :: BigNat -> Word#
bigNatToWord (BN# ByteArray#
b) = ByteArray# -> Word#
B.bigNatToWord# ByteArray#
b

{-# DEPRECATED indexBigNat# "Use bigNatIndex# instead" #-}
indexBigNat# :: BigNat -> GmpSize# -> GmpLimb#
indexBigNat# :: BigNat -> Int# -> Word#
indexBigNat# (BN# ByteArray#
b) Int#
i = ByteArray# -> Int# -> Word#
B.bigNatIndex# ByteArray#
b Int#
i

{-# DEPRECATED importBigNatFromByteArray "Use bigNatFromByteArray# instead" #-}
importBigNatFromByteArray :: ByteArray# -> Word# -> Word# -> Int# -> BigNat
importBigNatFromByteArray :: ByteArray# -> Word# -> Word# -> Int# -> BigNat
importBigNatFromByteArray ByteArray#
ba Word#
off Word#
sz Int#
endian = case forall o. (State# RealWorld -> o) -> o
runRW# (forall s.
Word#
-> ByteArray#
-> Word#
-> Int#
-> State# s
-> (# State# s, ByteArray# #)
B.bigNatFromByteArray# Word#
sz ByteArray#
ba Word#
off Int#
endian) of
   (# State# RealWorld
_, ByteArray#
r #) -> ByteArray# -> BigNat
BN# ByteArray#
r

{-# DEPRECATED exportBigNatToMutableByteArray "Use bigNatToMutableByteArray# instead" #-}
exportBigNatToMutableByteArray :: BigNat -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word
exportBigNatToMutableByteArray :: BigNat -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word
exportBigNatToMutableByteArray (BN# ByteArray#
ba) MutableByteArray# RealWorld
mba Word#
off Int#
endian = forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO (\State# RealWorld
s -> case forall s.
ByteArray#
-> MutableByteArray# s
-> Word#
-> Int#
-> State# s
-> (# State# s, Word# #)
B.bigNatToMutableByteArray# ByteArray#
ba MutableByteArray# RealWorld
mba Word#
off Int#
endian State# RealWorld
s of
   (# State# RealWorld
s', Word#
r #) -> (# State# RealWorld
s', Word# -> Word
W# Word#
r #))

{-# DEPRECATED importIntegerFromByteArray "Use integerFromByteArray# instead" #-}
importIntegerFromByteArray :: ByteArray# -> Word# -> Word# -> Int# -> Integer
importIntegerFromByteArray :: ByteArray# -> Word# -> Word# -> Int# -> Integer
importIntegerFromByteArray ByteArray#
ba Word#
off Word#
sz Int#
endian = case forall o. (State# RealWorld -> o) -> o
runRW# (forall s.
Word#
-> ByteArray#
-> Word#
-> Int#
-> State# s
-> (# State# s, Integer #)
I.integerFromByteArray# Word#
sz ByteArray#
ba Word#
off Int#
endian) of
   (# State# RealWorld
_, Integer
r #) -> Integer
r

{-# DEPRECATED exportIntegerToMutableByteArray "Use integerToMutableByteArray# instead" #-}
exportIntegerToMutableByteArray :: Integer -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word
exportIntegerToMutableByteArray :: Integer -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word
exportIntegerToMutableByteArray Integer
i MutableByteArray# RealWorld
mba Word#
off Int#
endian = forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO (\State# RealWorld
s -> case forall s.
Integer
-> MutableByteArray# s
-> Word#
-> Int#
-> State# s
-> (# State# s, Word# #)
I.integerToMutableByteArray# Integer
i MutableByteArray# RealWorld
mba Word#
off Int#
endian State# RealWorld
s of
   (# State# RealWorld
s', Word#
r #) -> (# State# RealWorld
s', Word# -> Word
W# Word#
r #))


{-# DEPRECATED byteArrayToBigNat# "Use bigNatFromWordArray instead" #-}
byteArrayToBigNat# :: ByteArray# -> GmpSize# -> BigNat
byteArrayToBigNat# :: ByteArray# -> Int# -> BigNat
byteArrayToBigNat# ByteArray#
ba Int#
n = ByteArray# -> Word# -> BigNat
B.bigNatFromWordArray ByteArray#
ba (Int# -> Word#
int2Word# Int#
n)