get the underlying GMP integer from a Maple integer - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : OpenMaple : C Application Programming Interface : Conversions from Maple Objects : OpenMaple/C/MapleToGMPInteger

MapleToGMPInteger - get the underlying GMP integer from a Maple integer

Calling Sequence

MapleToGMPInteger(kv, s)

Parameters

kv

-

kernel handle of type MKernelVector

s

-

Maple integer of type ALGEB

Description

• 

The MapleToGMPInteger function returns a pointer to the GMP integer used to represent the Maple integer s.  The pointer returned is of type mpz_ptr.

• 

The GMP integer returned may be the actual GMP integer used by Maple.  Thus these variables should only be used for reading, never writing.

• 

If you are using GMP in your external library, you should use MaplePushGMPAllocators to set your own memory allocator functions.

Examples

    #include <stdlib.h>

    #include "maplec.h"

    #include "gmp.h"

 

    ALGEB M_DECL PrintInt( MKernelVector kv, ALGEB *args )

    {

        mpz_ptr gmp_ptr;

        char buf[1024];

 

        if ( IsMapleInteger( kv, args[1] ) )

        {

            gmp_ptr = MapleToGMPInteger( kv, args[1] );

            MapleALGEB_Printf( kv, "m %d\n", args[1] );

            gmp_sprintf( buf, "g %Zd\n", gmp_ptr );

            MaplePrintf( kv, "%s", buf );

        }

 

        return ToMapleNULL( kv );

    }

Execute the external function from Maple.

withExternalCalling&colon;

dll:=ExternalLibraryNameHelpExamples&colon;

PrintInt:=DefineExternalPrintInt&comma;dll&colon;

PrintInt0

m 0
g 0

PrintInt1

m 1
g 1

PrintInt106

m 1000000
g 1000000

PrintInt7128

m 1487815647197611695910312681741273570332356717154798949898498305086387315423300999654757561928633305897036801
g 1487815647197611695910312681741273570332356717154798949898498305086387315423300999654757561928633305897036801

See Also

CustomWrapper, define_external, OpenMaple, OpenMaple/C/API


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam