hgmp-0.1.2.1: Haskell interface to GMP

Safe Haskell | Safe-Inferred
Language | Haskell2010

Numeric.GMP.Utils

Contents

- Integer marshalling
- Rational marshalling

Description

GMP utilities. A simple example with probable primes:

    import Numeric.GMP.Raw.Safe (mpz_nextprime)

    nextPrime :: Integer -> Integer
    nextPrime n =
      unsafePerformIO $
        withOutInteger_ $ \rop ->
          withInInteger n $ \op ->
            mpz_nextprime rop op

Synopsis

- withInInteger' :: Integer -> (MPZ -> IO r) -> IO r
- withInInteger :: Integer -> (Ptr MPZ -> IO r) -> IO r
- withInOutInteger :: Integer -> (Ptr MPZ -> IO a) -> IO (Integer, a)
- withInOutInteger_ :: Integer -> (Ptr MPZ -> IO a) -> IO Integer
- withOutInteger :: (Ptr MPZ -> IO a) -> IO (Integer, a)
- withOutInteger_ :: (Ptr MPZ -> IO a) -> IO Integer
- peekInteger' :: MPZ -> IO Integer
- peekInteger :: Ptr MPZ -> IO Integer
- pokeInteger :: Ptr MPZ -> Integer -> IO ()
- withInRational' :: Rational -> (MPQ -> IO r) -> IO r
- withInRational :: Rational -> (Ptr MPQ -> IO r) -> IO r
- withInOutRational :: Rational -> (Ptr MPQ -> IO a) -> IO (Rational, a)
- withInOutRational_ :: Rational -> (Ptr MPQ -> IO a) -> IO Rational
- withOutRational :: (Ptr MPQ -> IO a) -> IO (Rational, a)
- withOutRational_ :: (Ptr MPQ -> IO a) -> IO Rational
- peekRational' :: MPQ -> IO Rational
- peekRational :: Ptr MPQ -> IO Rational
- pokeRational :: Ptr MPQ -> Rational -> IO ()

# Integer marshalling

withInInteger' :: Integer -> (MPZ -> IO r) -> IO r Source #

Store an `Integer` into a temporary `MPZ`. The action must use it only as an `mpz_srcptr` (ie, constant/immutable), and must not allow references to it to escape its scope.

withInInteger :: Integer -> (Ptr MPZ -> IO r) -> IO r Source #

Combination of `withInInteger'` and `with`. The action must use it only as an `mpz_srcptr` (ie, constant/immutable), and must not allow the pointer to escape its scope. If in doubt about potential mutation by the action, use `withInOutInteger` instead.

withInOutInteger :: Integer -> (Ptr MPZ -> IO a) -> IO (Integer, a) Source #

Allocates and initializes an `mpz_t`, pokes the value, and peeks and clears it after the action. The pointer must not escape the scope of the action.

withInOutInteger_ :: Integer -> (Ptr MPZ -> IO a) -> IO Integer Source #

Allocates and initializes an `mpz_t`, pokes the value, and peeks and clears it after the action. The pointer must not escape the scope of the action. The result of the action is discarded.

withOutInteger :: (Ptr MPZ -> IO a) -> IO (Integer, a) Source #

Allocates and initializes an `mpz_t`, then peeks and clears it after the action. The pointer must not escape the scope of the action.

withOutInteger_ :: (Ptr MPZ -> IO a) -> IO Integer Source #

Allocates and initializes an `mpz_t`, then peeks and clears it after the action. The pointer must not escape the scope of the action. The result of the action is discarded.

peekInteger' :: MPZ -> IO Integer Source #

Read an `Integer` from an `MPZ`.

peekInteger :: Ptr MPZ -> IO Integer Source #

Combination of `peek` and `peekInteger'`.

pokeInteger :: Ptr MPZ -> Integer -> IO () Source #

Store an `Integer` into an `mpz_t`, which must have been initialized with `mpz_init`.

# Rational marshalling

withInRational' :: Rational -> (MPQ -> IO r) -> IO r Source #

Store a `Rational` into a temporary `MPQ`. The action must use it only as an `mpq_srcptr` (ie, constant/immutable), and must not allow the pointer to escape its scope.

withInRational :: Rational -> (Ptr MPQ -> IO r) -> IO r Source #

Combination of `withInRational'` and `with`. The action must use it only as an `mpq_srcptr` (ie, constant/immutable), and must not allow the pointer to escape its scope. If in doubt about potential mutation by the action, use `withInOutRational` instead.

withInOutRational :: Rational -> (Ptr MPQ -> IO a) -> IO (Rational, a) Source #

Allocates and initializes an `mpq_t`, pokes the value, and peeks and clears it after the action. The pointer must not escaep the scope of the action.

withInOutRational_ :: Rational -> (Ptr MPQ -> IO a) -> IO Rational Source #

Allocates and initializes an `mpq_t`, pokes the value, and peeks and clears it after the action. The pointer must not escaep the scope of the action. The result of the action is discarded.

withOutRational :: (Ptr MPQ -> IO a) -> IO (Rational, a) Source #

Allocates and initializes an `mpq_t`, then peeks and clears it after the action. The pointer must not escape the scope of the action.

withOutRational_ :: (Ptr MPQ -> IO a) -> IO Rational Source #

Allocates and initializes an `mpq_t`, then peeks and clears it after the action. The pointer must not escape the scope of the action. The result of the action is discarded.

peekRational' :: MPQ -> IO Rational Source #

Read a `Rational` from an `MPQ`.

peekRational :: Ptr MPQ -> IO Rational Source #

Combination of `peek` and `peekRational'`.

pokeRational :: Ptr MPQ -> Rational -> IO () Source #

Store a `Rational` into an `mpq_t`, which must have been initialized with `mpq_init`.