Low-level GMP features

Introduced classes

extern class NativeMPQ

gmp :: NativeMPQ

Multi precision Rational
extern class NativeMPZ

gmp :: NativeMPZ

Multi precision Integer
extern class UInt64

gmp :: UInt64

Boxing of C Unsigned Long

All class definitions

extern class NativeMPQ

gmp $ NativeMPQ

Multi precision Rational
extern class NativeMPZ

gmp $ NativeMPZ

Multi precision Integer
extern class UInt64

gmp $ UInt64

Boxing of C Unsigned Long
package_diagram gmp::native_gmp native_gmp core core gmp::native_gmp->core gmp::gmp gmp gmp::gmp->gmp::native_gmp a_star-m a_star-m a_star-m->gmp::gmp a_star-m... ... a_star-m...->a_star-m

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module list

core :: list

This module handle double linked lists
module math

core :: math

Mathematical operations
module native

core :: native

Native structures for text and bytes
module numeric

core :: numeric

Advanced services for Numeric types
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O

Parents

module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.

Children

module gmp

gmp :: gmp

Multi precision integer and rational number using gmp lib

Descendants

module a_star-m

a_star-m

# Low-level GMP features
module native_gmp is ldflags("-lgmp")

in "C header" `{
    #include <gmp.h>
`}

# Multi precision Integer
extern class NativeMPZ `{mpz_ptr`}

    # Initializing

    new `{
        mpz_ptr self =  (mpz_ptr)malloc(sizeof(mpz_t));
        mpz_init(self);
        return self;
    `}

    # Arithmetic Functions

    fun add(res, op: NativeMPZ) `{
        mpz_add(res, self, op);
    `}

    fun add_ui(res: NativeMPZ, op: UInt64) `{
        mpz_add_ui(res, self, *op);
    `}

    fun sub(res, op: NativeMPZ) `{
        mpz_sub(res, self, op);
    `}

    fun sub_ui(res: NativeMPZ, op: UInt64) `{
        mpz_sub_ui(res, self, *op);
    `}

    fun mul(res, op: NativeMPZ) `{
        mpz_mul(res, self, op);
    `}

    fun mul_si(res: NativeMPZ, op: Int) `{
        mpz_mul_si(res, self, op);
    `}

    fun neg(res: NativeMPZ) `{
        mpz_neg(res, self);
    `}

    fun abs(res: NativeMPZ) `{
        mpz_abs(res, self);
    `}

    fun tdiv_q(res, op: NativeMPZ) `{
        mpz_tdiv_q(res, self, op);
    `}

    fun tdiv_q_ui(res: NativeMPZ, op: UInt64) `{
        mpz_tdiv_q_ui(res, self, *op);
    `}

    fun mod(res, op: NativeMPZ) `{
        mpz_mod(res, self, op);
    `}

    fun mod_ui(res: NativeMPZ, op: UInt64) `{
        mpz_mod_ui(res, self, *op);
    `}

    fun pow_ui(res: NativeMPZ, op: UInt64) `{
        mpz_pow_ui(res, self, *op);
    `}

    #Number Theoretic Functions

    fun probab_prime_p(reps: Int32): Int `{
        return mpz_probab_prime_p(self, reps);
    `}

    fun nextprime(res: NativeMPZ) `{
        mpz_nextprime(res, self);
    `}

    fun gcd(res, op: NativeMPZ) `{
        mpz_gcd(res, self, op);
    `}

    fun gcd_ui(res: NativeMPZ, op: UInt64) `{
        mpz_gcd_ui(res, self, *op);
    `}

    # Comparison Functions

    fun cmp(op: NativeMPZ): Int `{
        return mpz_cmp(self, op);
    `}

    fun cmp_si(op: Int): Int `{
        return mpz_cmp_si(self, op);
    `}

    # Assignment

    fun set(op: NativeMPZ) `{ mpz_set(self, op); `}

    fun set_si(op: Int) `{ mpz_set_si(self, op); `}

    fun set_d(op: Float) `{ mpz_set_d(self, op); `}

    fun set_q(op: NativeMPQ) `{ mpz_set_q(self, op); `}

    fun set_str(str: CString, base: Int32) `{
        mpz_set_str(self, str, base);
    `}

    fun swap(op: NativeMPZ) `{ mpz_swap(self, op); `}

    # Conversion Functions

    fun get_si: Int `{ return mpz_get_si(self); `}

    fun get_d: Float `{ return mpz_get_d(self); `}

    fun get_str(base: Int32): CString `{
        return mpz_get_str(NULL, base, self);
    `}

    # Delete this NativeMPZ
    fun finalize `{
        mpz_clear(self);
        free(self);
    `}
end

# Multi precision Rational
extern class NativeMPQ `{mpq_ptr`}

    # Initializing

    new `{
        mpq_ptr self = (mpq_ptr)malloc(sizeof(mpq_t));
        mpq_init(self);
        return self;
    `}

    # Arithmetic Functions

    fun add(res, op: NativeMPQ) `{
        mpq_add(res, self, op);
    `}

    fun sub(res, op: NativeMPQ) `{
        mpq_sub(res, self, op);
    `}

    fun mul(res, op: NativeMPQ) `{
        mpq_mul(res, self, op);
    `}

    fun div(res, op: NativeMPQ) `{
        mpq_div(res, self, op);
    `}

    fun neg(res: NativeMPQ) `{
        mpq_neg(res, self);
    `}

    fun abs(res: NativeMPQ) `{
        mpq_abs(res, self);
    `}

    fun inv(res: NativeMPQ) `{
        mpq_inv(res, self);
    `}

    # Assignment

    fun set(op: NativeMPQ) `{ mpq_set(self, op); `}

    fun set_z(op: NativeMPZ) `{ mpq_set_z(self, op); `}

    fun set_si(op1: Int, op2: Int) `{
        mpq_set_si(self, op1, op2);
        mpq_canonicalize(self);
    `}

    fun set_d(op: Float) `{ mpq_set_d(self, op); `}

    fun set_str(str: CString) `{
        mpq_set_str(self, str, 10);
        mpq_canonicalize(self);
    `}

    fun swap(op: NativeMPQ) `{ mpq_swap(self, op); `}

    # Convertion Functions

    fun get_d: Float `{ return mpq_get_d(self); `}

    fun get_str(base: Int32): CString `{
        return mpq_get_str(NULL, base, self);
    `}

    # Comparison Functions

    fun cmp(op: NativeMPQ): Int `{
        return mpq_cmp(self, op);
    `}

#    fun cmp_z(op: NativeMPZ): Int `{
#        return mpq_cmp_z(self, op);
#    `}

    fun cmp_si(num: Int, den: Int): Int `{
        return mpq_cmp_si(self, num, den);
    `}

    fun equal(op: NativeMPQ): Bool `{
        return mpq_equal(self, op);
    `}

    # Getter

    fun numref: NativeMPZ `{
        return mpq_numref(self);
    `}

    fun denref: NativeMPZ `{
        return mpq_denref(self);
    `}

    # Delete this NativeMPZ
    fun finalize `{
        mpq_clear(self);
        free(self);
    `}
end

# Boxing of C Unsigned Long
extern class UInt64 `{ uint64_t* `}
    new `{
        uint64_t *self = (uint64_t*)malloc(sizeof(uint64_t));
        return self;
    `}

    fun set_si(val: Int) `{
        *self = (uint64_t)val;
    `}
end
lib/gmp/native_gmp.nit:15,1--262,3