https://foro.gambas-es.org/viewtopic.php?f=5&t=5320&p=31424#p31424
-----------------------------------
vuott
Sabado, 02 Abril 2016, 01:38

Probando Unas Funciones Externas Del API De GMP
-----------------------------------
Estaba probando un simple código Gambas con unas funciones externas de la libreria [url=https://es.wikipedia.org/wiki/GNU_Multiple_Precision_Arithmetic_Library]GMP.

[code linenumbers=false syntax=gambas]Library "libgmp:10.1.3"

Public Struct __mpz_struct
  _mp_alloc As Integer
  _mp_size As Integer
  _mp_d As Pointer
End Struct

' int __gmpz_init_set_str (mpz_t rop, const char *str, int base)
' Initialize rop.
Private Extern __gmpz_init_set_str(rop As __mpz_struct, st As String, base As Integer) As Integer

' void __gmpz_init (mpz_ptr x)
' Initialize x, and set its value to 0
Private Extern __gmpz_init(x As __mpz_struct)

' void __gmpz_mul (mpz_t rop, const mpz_t op1, const mpz_t op2)
' Set rop to op1 times op2.
Private Extern __gmpz_mul(rop As __mpz_struct, op1 As __mpz_struct, op2 As __mpz_struct)

' int __gmp_printf (const char *, ...)
' Accept format strings similar to the standard C printf 
Private Extern __gmp_printf(ris As String, mpz_ptr As __mpz_struct, mpz_ptr As __mpz_struct, mpz_ptr As __mpz_struct) As Integer

' void __gmpz_clear (mpz_t x)
' Free the space occupied by x.
Private Extern __gmpz_clear(x As __mpz_struct)


Public Sub Main()

  Dim x, y, res As New __mpz_struct

    __gmpz_init_set_str(x, "8723169365849056", 10)
    __gmpz_init_set_str(y, "7374602239540192", 10)
    __gmpz_init(res)
    
    __gmpz_mul(res, x, y)
    
    __gmp_printf("                %Zd *\n" &
            "                %Zd\n" &
            "--------------------------------\n" &
            "%Zd\n", x, y, res)
    
' Memoriam terminando vacuam facit:
    __gmpz_clear(x)
    __gmpz_clear(y)
    __gmpz_clear(res)

End[/code]
Referencias:
https://gmplib.org/manual/


Existe tambien el Componente [i]gb.gmp[/i] creado de los recursos de esta libreria, pero prefiero el [i]código extremo[/i].    :lol: 
[img]http://www.avventuraitalia.it/bunge%20jumping%2002.jpg[/img]


