hgmp-0.1.1: Haskell interface to GMP

Safe HaskellNone
LanguageHaskell2010

Numeric.GMP.Utils

Contents

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

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.

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

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