mathematical library

Just starting out? Need help? Post your questions and find answers here.
sospel
User
User
Posts: 16
Joined: Wed Sep 17, 2008 3:34 pm

mathematical library

Post by sospel »

Hello to all !
To program an application where there are many mathematical formulae which miss in Pbasic, I look for a mathematical library compatible with PBASIC 4.3, but I do not find :(
I had seen the APM library, but it is not compatible.
Does the one of you know such a library, or a link?
Thank you in advance for your answers :)
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: mathematical library

Post by Michael Vogel »

sospel wrote:Hello to all !
To program an application where there are many mathematical formulae which miss in Pbasic, I look for a mathematical library compatible with PBASIC 4.3, but I do not find :(
I had seen the APM library, but it is not compatible.
Does the one of you know such a library, or a link?
Thank you in advance for your answers :)
Depending what you are looking for, there exist some dlls (e.g. for Long Integer functions), but I don't like libraries because they (sometimes) don't work with new PB releases :?

It would be nice, if more math (and integer) functions would be seen in PB itself, because this would be a "compatible" solution. Otherwise, an include file with some functions could be an idea, maybe done by different programmers :?:

Michael
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Post by Little John »

Well, mathematics is a broad field. :-)
Do you need a particular subset of functions for your application (e.g. financial, geometry, statistics, ...)? That would make it a little easier.

I think several people have interesting math PB functions on their hard disks. In the German PB forum, there is a special thread for collecting source code of math functions. Maybe it would make sense to create such a thread in this forum, too.

Regards, Little John
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

sospel you can use the GMP and MPFR libraries, do a search on this forums for more info, also little known are some public domain libraries, FGMP (free GMP) and LTM (LibTomMath), do a search for fgmp on this forum.
FGMP is rather old and not very fast, but is public domain, LTM is faster and more up to date and also public domain, work on it by the author has been discontinued see this thead for the reason http://groups.google.com/group/libtom/b ... 9629237#30
but ltm is still very useful, also you can download the book tommath here http://math.libtomcrypt.com/files/
I have example PB test code for all of these.
sospel
User
User
Posts: 16
Joined: Wed Sep 17, 2008 3:34 pm

Post by sospel »

Hello !
Thanks for answers !
Michael Vogel :
"It would be nice, if more math (and integer) functions would be seen in PB itself, because this would be a "compatible" solution" :OK, I agree 100% !

Little John :
I search for geometry and trigonometry functions
"I think several people have interesting math PB functions on their hard disks. In the German PB forum, there is a special thread for collecting source code of math functions. Maybe it would make sense to create such a thread in this forum, too" : OK, I agree 100% !

jack :
OK for link on LTM. I' ll try it
Cordially
Sospel :)
sospel
User
User
Posts: 16
Joined: Wed Sep 17, 2008 3:34 pm

Post by sospel »

Hello !
After jack reply, I found this link on the German forum of PureBasic : http://www.purebasic.fr/german/viewtopi ... light=math

I thus downloaded GMP ( http://gmplib.org/) and, once unwound, I have many functions in C language. Problem: is it possible to make a "library" for WindowsXP, and if yes, how (I am completely incapable to make it without being advised :( ) ?
Thank you in advance for your answers :)
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

For importing a c lib, search in the side of "Import" and "ImportC" commands.
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

Please correct my english
http://purebasic.developpez.com/
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

I thought that I had posted an mpfr example but forum search could not find it, so here it is.

Code: Select all

  Structure mpz ; multiprecision integer 
    mp_alloc.l 
    mp_size.l 
    mp_limb.i 
  EndStructure 
  
  Structure mpq ; multiprecision rational 
    mp_num.mpz 
    mp_den.mpz 
  EndStructure 
  
  Structure mpf ; multiprecision floating point 
    mp_prec.l 
    mp_size.l 
    mp_expt.i 
    mp_limb.i 
  EndStructure 
  
  Structure mpfr; multiprecision floating point
    prec.i
    sign.l
    exp.i
    d.i
  EndStructure


Structure gmp_randata_lc_t
   mp_a.i
   mp_c.i
   mp_m.i
   mp_m2exp.i
EndStructure

Structure mp_algdata_t
  StructureUnion
     *_mp_lc.gmp_randata_lc_t
   EndStructureUnion
EndStructure

Structure gmp_randstate_t
   mp_seed.mpz
   mp_alg.i
   mp_algdata.mp_algdata_t
EndStructure

#GMP_RNDN   =0 ;round to nearest
#GMP_RNDZ   =1 ;round towards zero
#GMP_RNDU   =2 ;round towards plus infinity
#GMP_RNDD   =3 ;round towards minus infinity


ImportC "libgmp-10.lib"
  gmp_randinit_default (*state.gmp_randstate_t) As "___gmp_randinit_default"
  gmp_randinit_lc_2exp (*state.gmp_randstate_t, *a.mpz, c.l, m2exp.l) As "___gmp_randinit_lc_2exp"
  gmp_randinit_lc_2exp_size.l (*sate.gmp_randstate_t, size.l) As "___gmp_randinit_lc_2exp_size"
  gmp_randseed (*state.gmp_randstate_t, *seed.mpz) As "___gmp_randseed"
  gmp_randseed_ui (*state.gmp_randstate_t, seed.l) As "___gmp_randseed_ui"
  gmp_randclear (*state.gmp_randstate_t) As "___gmp_randclear"
  
  mpz_urandomb (*rop.mpz, *state.gmp_randstate_t, int.l) As "___gmpz_urandomb"

  gmp_sprintz.l(dest.s,format.s,*n.mpz) As "___gmp_sprintf"
  gmp_sprintq.l(dest.s,format.s,*n.mpq) As "___gmp_sprintf"
  gmp_sprintf.l(dest.s,format.s,*n.mpf) As "___gmp_sprintf"
  mpf_set_default_prec(prec.l) As "___gmpf_set_default_prec"
  mpf_get_default_prec.l() As "___gmpf_get_default_prec"
  mpf_init(*x.mpf) As "___gmpf_init"
  mpf_init2(*x.mpf,prec.l) As "___gmpf_init2"
  mpf_clear(*x.mpf) As "___gmpf_clear"
  mpf_get_prec.l(*op.mpf) As "___gmpf_get_prec"
  mpf_set_prec(*rop.mpf,prec.l) As "___gmpf_set_prec"
  mpf_set_prec_raw(*rop.mpf,prec.l) As "___gmpf_set_prec_raw"
  mpf_set(*rop.mpf,*op.mpf) As "___gmpf_set"
  mpf_set_ui(*rop.mpf,op.l) As "___gmpf_set_ui"
  mpf_set_si(*rop.mpf,op.l) As "___gmpf_set_si"
  mpf_set_d(*rop.mpf,op.d) As "___gmpf_set_d"
  mpf_set_z(*rop.mpf,*op.mpz) As "___gmpf_set_z"
  mpf_set_q(*rop.mpf,*op.mpq) As "___gmpf_set_q"
  mpf_set_str.l(*rop.mpf,str.s,base.l) As "___gmpf_set_str"
  mpf_swap(*rop1.mpf,*rop2.mpf) As "___gmpf_swap"
  mpf_init_set(*rop.mpf,*op.mpf) As "___gmpf_init_set"
  mpf_init_set_ui(*rop.mpf,op.l) As "___gmpf_init_set_ui"
  mpf_init_set_si(*rop.mpf,op.l) As "___gmpf_init_set_si"
  mpf_init_set_d(*rop.mpf,op.d) As "___gmpf_init_set_d"
  mpf_init_set_str.l(*rop.mpf,str.s,base.l) As "___gmpf_init_set_str"
  mpf_get_d.d(*op.mpf) As "___gmpf_get_d"
  mpf_get_d_2exp.d(expt.l,*op.mpf) As "___gmpf_get_d_2exp"
  mpf_get_si.l(*op.mpf) As "___gmpf_get_si"
  mpf_get_ui.l(*op.mpf) As "___gmpf_get_ui"
  mpf_get_str(str.s,expptr.l,base.l,n_digits.l,*op.mpf) As "___gmpf_get_str"
  mpf_ceil(*rop.mpf,*op.mpf) As "___gmpf_ceil"
  mpf_floor(*rop.mpf,*op.mpf) As "___gmpf_floor"
  mpf_trunc(*rop.mpf,*op.mpf) As "___gmpf_trunc"
  mpf_integer_p.l(*op.mpf) As "___gmpf_integer_p"
  mpf_fits_ulong_p.l(*op.mpf) As "___gmpf_fits_ulong_p"
  mpf_fits_slong_p.l(*op.mpf) As "___gmpf_fits_slong_p"
  mpf_fits_uint_p.l(*op.mpf) As "___gmpf_fits_uint_p"
  mpf_fits_sint_p.l(*op.mpf) As "___gmpf_fits_sint_p"
  mpf_fits_ushort_p.l(*op.mpf) As "___gmpf_fits_ushort_p"
  mpf_fits_sshort_p.l(*op.mpf) As "___gmpf_fits_sshort_p"
  mpf_add(*rop.mpf,*op1.mpf,*op2.mpf) As "___gmpf_add"
  mpf_add_ui(*rop.mpf,*op1.mpf,op2.l) As "___gmpf_add_ui"
  mpf_sub(*rop.mpf,*op1.mpf,*op2.mpf) As "___gmpf_sub"
  mpf_ui_sub(*rop.mpf,op1.l,*op2.mpf) As "___gmpf_ui_sub"
  mpf_sub_ui(*rop.mpf,*op1.mpf,op2.l) As "___gmpf_sub_ui"
  mpf_mul(*rop.mpf,*op1.mpf,*op2.mpf) As "___gmpf_mul"
  mpf_mul_ui(*rop.mpf,*op1.mpf,op2.l) As "___gmpf_mul_ui"
  mpf_div(*rop.mpf,*op1.mpf,*op2.mpf) As "___gmpf_div"
  mpf_ui_div(*rop.mpf,op1.l,*op2.mpf) As "___gmpf_ui_div"
  mpf_div_ui(*rop.mpf,*op1.mpf,op2.l) As "___gmpf_div_ui"
  mpf_sqrt(*rop.mpf,*op.mpf) As "___gmpf_sqrt"
  mpf_sqrt_ui(*rop.mpf,op.l) As "___gmpf_sqrt_ui"
  mpf_pow_ui(*rop.mpf,*op1.mpf,op2.l) As "___gmpf_pow_ui"
  mpf_neg(*rop.mpf,*op.mpf) As "___gmpf_neg"
  mpf_abs(*rop.mpf,*op.mpf) As "___gmpf_abs"
  mpf_mul_2exp(*rop.mpf,*op1.mpf,op2.l) As "___gmpf_mul_2exp"
  mpf_div_2exp(*rop.mpf,*op1.mpf,op2.l) As "___gmpf_div_2exp"
  mpf_cmp.l(*op1.mpf,*op2.mpf) As "___gmpf_cmp"
  mpf_cmp_d.l(*op1.mpf,op2.d) As "___gmpf_cmp_d"
  mpf_cmp_ui.l(*op1.mpf,op2.l) As "___gmpf_cmp_ui"
  mpf_cmp_si.l(*op1.mpf,op2.l) As "___gmpf_cmp_si"
  mpf_eq.l(*op1.mpf,*op2.mpf,op3.l) As "___gmpf_eq"
  mpf_reldiff(*rop.mpf,*op1.mpf,*op2.mpf) As "___gmpf_reldiff"
  mpf_sgn.l(*op.mpf) As "___gmpf_sgn"
  gmp_snprintf.l(buf.s,Size.l,fmt.s,*op.mpf) As "___gmp_snprintf"
  mpz_init(*integer.mpz) As "___gmpz_init"
  mpz_init2(*integer.mpz,n.l) As "___gmpz_init2"
  mpz_clear(*integer.mpz) As "___gmpz_clear"
  mpz_realloc2(*integer.mpz,n.l) As "___gmpz_realloc2"
;  mpz_realloc.l(*integer.mpz,) As "____gmpz_realloc"
  mpz_set(*rop.mpz,*op.mpz) As "___gmpz_set"
  mpz_set_ui(*rop.mpz,op.l) As "___gmpz_set_ui"
  mpz_set_si(*rop.mpz,op.l) As "___gmpz_set_si"
  mpz_set_d(*rop.mpz,op.d) As "___gmpz_set_d"
  mpz_set_q(*rop.mpz,*op.mpq) As "___gmpz_set_q"
  mpz_set_f(*rop.mpz,*op.mpf) As "___gmpz_set_f"
  mpz_set_str.l(*rop.mpz,str.s,base.l) As "___gmpz_set_str"
  mpz_swap(*rop1.mpz,*rop2.mpz) As "___gmpz_swap"
  mpz_init_set(*rop.mpz,*op.mpz) As "___gmpz_init_set"
  mpz_init_set_ui(*rop.mpz,op.l) As "___gmpz_init_set_ui"
  mpz_init_set_si(*rop.mpz,op.l) As "___gmpz_init_set_si"
  mpz_init_set_d(*rop.mpz,op.d) As "___gmpz_init_set_d"
  mpz_init_set_str.l(*rop.mpz,str.s,base.l) As "___gmpz_init_set_str"
  mpz_add(*rop.mpz,*op1.mpz,*op2.mpz) As "___gmpz_add"
  mpz_add_ui(*rop.mpz,*op1.mpz,op2.l) As "___gmpz_add_ui"
  mpz_sub(*rop.mpz,*op1.mpz,*op2.mpz) As "___gmpz_sub"
  mpz_sub_ui(*rop.mpz,*op1.mpz,op2.l) As "___gmpz_sub_ui"
  mpz_ui_sub(*rop.mpz,op1.l,*op2.mpz) As "___gmpz_ui_sub"
  mpz_mul(*rop.mpz,*op1.mpz,*op2.mpz) As "___gmpz_mul"
  mpz_mul_si(*rop.mpz,*op1.mpz,op2.l) As "___gmpz_mul_si"
  mpz_mul_ui(*rop.mpz,*op1.mpz,op2.l) As "___gmpz_mul_ui"
  mpz_addmul(*rop.mpz,*op1.mpz,*op2.mpz) As "___gmpz_addmul"
  mpz_addmul_ui(*rop.mpz,*op1.mpz,op2.l) As "___gmpz_addmul_ui"
  mpz_submul(*rop.mpz,*op1.mpz,*op2.mpz) As "___gmpz_submul"
  mpz_submul_ui(*rop.mpz,*op1.mpz,op2.l) As "___gmpz_submul_ui"
  mpz_mul_2exp(*rop.mpz,*op1.mpz,op2.l) As "___gmpz_mul_2exp"
  mpz_neg(*rop.mpz,*op.mpz) As "___gmpz_neg"
  mpz_abs(*rop.mpz,*op.mpz) As "___gmpz_abs"
  mpz_cdiv_q(*q.mpz,*n.mpz,*d.mpz) As "___gmpz_cdiv_q"
  mpz_cdiv_r(*r.mpz,*n.mpz,*d.mpz) As "___gmpz_cdiv_r"
  mpz_cdiv_qr(*q.mpz,*r.mpz,*n.mpz,*d.mpz) As "___gmpz_cdiv_qr"
  mpz_cdiv_q_ui.l(*q.mpz,*n.mpz,d.l) As "___gmpz_cdiv_q_ui"
  mpz_cdiv_r_ui.l(*r.mpz,*n.mpz,d.l) As "___gmpz_cdiv_r_ui"
  mpz_cdiv_qr_ui.l(*q.mpz,*r.mpz,*n.mpz,d.l) As "___gmpz_cdiv_qr_ui"
  mpz_cdiv_ui.l(*n.mpz,d.l) As "___gmpz_cdiv_ui"
  mpz_cdiv_q_2exp(*q.mpz,*n.mpz,b.l) As "___gmpz_cdiv_q_2exp"
  mpz_cdiv_r_2exp(*r.mpz,*n.mpz,b.l) As "___gmpz_cdiv_r_2exp"
  mpz_fdiv_q(*q.mpz,*n.mpz,*d.mpz) As "___gmpz_fdiv_q"
  mpz_fdiv_r(*r.mpz,*n.mpz,*d.mpz) As "___gmpz_fdiv_r"
  mpz_fdiv_qr(*q.mpz,*r.mpz,*n.mpz,*d.mpz) As "___gmpz_fdiv_qr"
  mpz_fdiv_q_ui.l(*q.mpz,*n.mpz,d.l) As "___gmpz_fdiv_q_ui"
  mpz_fdiv_r_ui.l(*r.mpz,*n.mpz,d.l) As "___gmpz_fdiv_r_ui"
  mpz_fdiv_qr_ui.l(*q.mpz,*r.mpz,*n.mpz,d.l) As "___gmpz_fdiv_qr_ui"
  mpz_fdiv_ui.l(*n.mpz,d.l) As "___gmpz_fdiv_ui"
  mpz_fdiv_q_2exp(*q.mpz,*n.mpz,b.l) As "___gmpz_fdiv_q_2exp"
  mpz_fdiv_r_2exp(*r.mpz,*n.mpz,b.l) As "___gmpz_fdiv_r_2exp"
  mpz_tdiv_q(*q.mpz,*n.mpz,*d.mpz) As "___gmpz_tdiv_q"
  mpz_tdiv_r(*r.mpz,*n.mpz,*d.mpz) As "___gmpz_tdiv_r"
  mpz_tdiv_qr(*q.mpz,*r.mpz,*n.mpz,*d.mpz) As "___gmpz_tdiv_qr"
  mpz_tdiv_q_ui.l(*q.mpz,*n.mpz,d.l) As "___gmpz_tdiv_q_ui"
  mpz_tdiv_r_ui.l(*r.mpz,*n.mpz,d.l) As "___gmpz_tdiv_r_ui"
  mpz_tdiv_qr_ui.l(*q.mpz,*r.mpz,*n.mpz,d.l) As "___gmpz_tdiv_qr_ui"
  mpz_tdiv_ui.l(*n.mpz,d.l) As "___gmpz_tdiv_ui"
  mpz_tdiv_q_2exp(*q.mpz,*n.mpz,b.l) As "___gmpz_tdiv_q_2exp"
  mpz_tdiv_r_2exp(*r.mpz,*n.mpz,b.l) As "___gmpz_tdiv_r_2exp"
  mpz_mod(*r.mpz,*n.mpz,*d.mpz) As "___gmpz_mod"
  mpz_mod_ui.l(*r.mpz,*n.mpz,d.l) As "___gmpz_mod_ui"
  mpz_divexact(*q.mpz,*n.mpz,*d.mpz) As "___gmpz_divexact"
  mpz_divexact_ui(*q.mpz,*n.mpz,d.l) As "___gmpz_divexact_ui"
  mpz_divisible_p.l(*n.mpz,*d.mpz) As "___gmpz_divisible_p"
  mpz_divisible_ui_p.l(*n.mpz,d.l) As "___gmpz_divisible_ui_p"
  mpz_divisible_2exp_p.l(*n.mpz,b.l) As "___gmpz_divisible_2exp_p"
  mpz_congruent_p.l(*n.mpz,*c.mpz,*d.mpz) As "___gmpz_congruent_p"
  mpz_congruent_ui_p.l(*n.mpz,c.l,d.l) As "___gmpz_congruent_ui_p"
  mpz_congruent_2exp_p.l(*n.mpz,*c.mpz,b.l) As "___gmpz_congruent_2exp_p"
  mpz_powm(*rop.mpz,*base.mpz,*expt.mpz,*mod.mpz) As "___gmpz_powm"
  mpz_powm_ui(*rop.mpz,*base.mpz,expt.l,*mod.mpz) As "___gmpz_powm_ui"
  mpz_pow_ui(*rop.mpz,*base.mpz,expt.l) As "___gmpz_pow_ui"
  mpz_ui_pow_ui(*rop.mpz,base.l,expt.l) As "___gmpz_ui_pow_ui"
  mpz_root.l(*rop.mpz,*op.mpz,n.l) As "___gmpz_root"
  mpz_sqrt(*rop.mpz,*op.mpz) As "___gmpz_sqrt"
  mpz_sqrtrem(*rop1.mpz,*rop2.mpz,*op.mpz) As "___gmpz_sqrtrem"
  mpz_perfect_power_p.l(*op.mpz) As "___gmpz_perfect_power_p"
  mpz_perfect_square_p.l(*op.mpz) As "___gmpz_perfect_square_p"
  mpz_probab_prime_p.l(*n.mpz,reps.l) As "___gmpz_probab_prime_p"
  mpz_nextprime(*rop.mpz,*op.mpz) As "___gmpz_nextprime"
  mpz_gcd(*rop.mpz,*op1.mpz,*op2.mpz) As "___gmpz_gcd"
  mpz_gcd_ui.l(*rop.mpz,*op1.mpz,op2.l) As "___gmpz_gcd_ui"
  mpz_gcdext(*g.mpz,*s.mpz,*t.mpz,*a.mpz,*b.mpz) As "___gmpz_gcdext"
  mpz_lcm(*rop.mpz,*op1.mpz,*op2.mpz) As "___gmpz_lcm"
  mpz_lcm_ui(*rop.mpz,*op1.mpz,op2.l) As "___gmpz_lcm_ui"
  mpz_invert.l(*rop.mpz,*op1.mpz,*op2.mpz) As "___gmpz_invert"
  mpz_jacobi.l(*a.mpz,*b.mpz) As "___gmpz_jacobi"
  mpz_legendre.l(*a.mpz,*p.mpz) As "___gmpz_legendre"
  mpz_kronecker.l(*a.mpz,*b.mpz) As "___gmpz_kronecker"
  mpz_kronecker_si.l(*a.mpz,b.l) As "___gmpz_kronecker_si"
  mpz_kronecker_ui.l(*a.mpz,b.l) As "___gmpz_kronecker_ui"
  mpz_si_kronecker.l(a.l,*b.mpz) As "___gmpz_si_kronecker"
  mpz_ui_kronecker.l(a.l,*b.mpz) As "___gmpz_ui_kronecker"
  mpz_remove.l(*rop.mpz,*op.mpz,*f.mpz) As "___gmpz_remove"
  mpz_fac_ui(*rop.mpz,op.l) As "___gmpz_fac_ui"
  mpz_bin_ui(*rop.mpz,*n.mpz,k.l) As "___gmpz_bin_ui"
  mpz_bin_uiui(*rop.mpz,n.l,k.l) As "___gmpz_bin_uiui"
  mpz_fib_ui(*fn.mpz,n.l) As "___gmpz_fib_ui"
  mpz_fib2_ui(*fn.mpz,*fnsub1.mpz,n.l) As "___gmpz_fib2_ui"
  mpz_lucnum_ui(*ln.mpz,n.l) As "___gmpz_lucnum_ui"
  mpz_lucnum2_ui(*ln.mpz,*lnsub1.mpz,n.l) As "___gmpz_lucnum2_ui"
  mpz_cmp.l(*op1.mpz,*op2.mpz) As "___gmpz_cmp"
  mpz_cmp_d.l(*op1.mpz,op2.d) As "___gmpz_cmp_d"
  mpz_cmp_si.l(*op1.mpz,op2.l) As "____gmpz_cmp_si"
  mpz_cmp_ui.l(*op1.mpz,op2.l) As "____gmpz_cmp_ui"
  mpz_cmpabs.l(*op1.mpz,*op2.mpz) As "___gmpz_cmpabs"
  mpz_cmpabs_d.l(*op1.mpz,op2.d) As "___gmpz_cmpabs_d"
  mpz_cmpabs_ui.l(*op1.mpz,op2.l) As "___gmpz_cmpabs_ui"
  mpz_sgn.l(*op.mpz) As "___gmpz_sgn"
  mpz_and(*rop.mpz,*op1.mpz,*op2.mpz) As "___gmpz_and"
  mpz_ior(*rop.mpz,*op1.mpz,*op2.mpz) As "___gmpz_ior"
  mpz_xor(*rop.mpz,*op1.mpz,*op2.mpz) As "___gmpz_xor"
  mpz_com(*rop.mpz,*op.mpz) As "___gmpz_com"
  mpz_popcount.l(*op.mpz) As "___gmpz_popcount"
  mpz_hamdist.l(*op1.mpz,*op2.mpz) As "___gmpz_hamdist"
  mpz_scan0.l(*op.mpz,starting_bit.l) As "___gmpz_scan0"
  mpz_scan1.l(*op.mpz,starting_bit.l) As "___gmpz_scan1"
  mpz_setbit(*rop.mpz,bit_index.l) As "___gmpz_setbit"
  mpz_clrbit(*rop.mpz,bit_index.l) As "___gmpz_clrbit"
  mpz_tstbit.l(*op.mpz,bit_index.l) As "___gmpz_tstbit"
  mpz_import(*rop.mpz,count.l,order.l,Size.l,endian.l,nails.l,op.l) As "___gmpz_import"
  mpz_export.l(rop.l,countp.l,order.l,Size.l,endian.l,nails.l,*op.mpz) As "___gmpz_export"
  mpz_fits_ulong_p.l(*op.mpz) As "___gmpz_fits_ulong_p"
  mpz_fits_slong_p.l(*op.mpz) As "___gmpz_fits_slong_p"
  mpz_fits_uint_p.l(*op.mpz) As "___gmpz_fits_uint_p"
  mpz_fits_sint_p.l(*op.mpz) As "___gmpz_fits_sint_p"
  mpz_fits_ushort_p.l(*op.mpz) As "___gmpz_fits_ushort_p"
  mpz_fits_sshort_p.l(*op.mpz) As "___gmpz_fits_sshort_p"
  mpz_odd_p.l(*op.mpz) As "___gmpz_odd_p"
  mpz_even_p.l(*op.mpz) As "___gmpz_even_p"
  mpz_size.l(*op.mpz) As "___gmpz_size"
  mpz_sizeinbase.l(*op.mpz,base.l) As "___gmpz_sizeinbase"
  mpq_init(*dest_rational.mpq) As "___gmpq_init"
  mpq_clear(*rational_number.mpq) As "___gmpq_clear"
  mpq_set(*rop.mpq,*op.mpq) As "___gmpq_set"
  mpq_set_z(*rop.mpq,*op.mpz) As "___gmpq_set_z"
  mpq_set_ui(*rop.mpq,op1.l,op2.l) As "___gmpq_set_ui"
  mpq_set_si(*rop.mpq,op1.l,op2.l) As "___gmpq_set_si"
  mpq_set_str.l(*rop.mpq,str.s,base.l) As "___gmpq_set_str"
  mpq_swap(*rop1.mpq,*rop2.mpq) As "___gmpq_swap"
  mpq_get_d.d(*op.mpq) As "___gmpq_get_d"
  mpq_set_d(*rop.mpq,op.d) As "___gmpq_set_d"
  mpq_set_f(*rop.mpq,*op.mpf) As "___gmpq_set_f"
  mpq_get_str(str.s,base.l,*op.mpq) As "___gmpq_get_str"
  mpq_add(*sum.mpq,*addend1.mpq,*addend2.mpq) As "___gmpq_add"
  mpq_sub(*difference.mpq,*minuend.mpq,*subtrahend.mpq) As "___gmpq_sub"
  mpq_mul(*product.mpq,*multiplier.mpq,*multiplicand.mpq) As "___gmpq_mul"
  mpq_mul_2exp(*rop.mpq,*op1.mpq,op2.l) As "___gmpq_mul_2exp"
  mpq_div(*quotient.mpq,*dividend.mpq,*divisor.mpq) As "___gmpq_div"
  mpq_div_2exp(*rop.mpq,*op1.mpq,op2.l) As "___gmpq_div_2exp"
  mpq_neg(*negated_operand.mpq,*operand.mpq) As "___gmpq_neg"
  mpq_abs(*rop.mpq,*op.mpq) As "___gmpq_abs"
  mpq_inv(*inverted_number.mpq,*number.mpq) As "___gmpq_inv"
  mpq_cmp.l(*op1.mpq,*op2.mpq) As "___gmpq_cmp"
  mpq_cmp_ui.l(*op1.mpq,num2.l,den2.l) As "____gmpq_cmp_ui"
  mpq_cmp_si.l(*op1.mpq,num2.l,den2.l) As "____gmpq_cmp_si"
  mpq_sgn.l(*op.mpq) As "___gmpq_sgn"
  mpq_equal.l(*op1.mpq,*op2.mpq) As "___gmpq_equal"
  mpq_get_num(*numerator.mpz,*rational.mpq) As "___gmpq_get_num"
  mpq_get_den(*denominator.mpz,*rational.mpq) As "___gmpq_get_den"
  mpq_set_num(*rational.mpq,*numerator.mpz) As "___gmpq_set_num"
  mpq_set_den(*rational.mpq,*denominator.mpz) As "___gmpq_set_den"
  mpq_canonicalize(*op.mpq) As "___gmpq_canonicalize"
EndImport

ImportC "libmpfr-4.lib"
  mpfr_init2(*x.mpfr,prec.l) As "_mpfr_init2"
  mpfr_clear(*x.mpfr) As "_mpfr_clear"
  mpfr_init(*x.mpfr) As "_mpfr_init"
  mpfr_set_default_prec(prec.l) As "_mpfr_set_default_prec"
  mpfr_get_default_prec.l() As "_mpfr_get_default_prec"
  mpfr_set_prec(*x.mpfr,prec.l) As "_mpfr_set_prec"
  mpfr_get_prec.l(*x.mpfr) As "_mpfr_get_prec"
  mpfr_set.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_set"
  mpfr_set_ui.l(*rop.mpfr,op.l,round.l) As "_mpfr_set_ui"
  mpfr_set_si.l(*rop.mpfr,op.l,round.l) As "_mpfr_set_si"
  mpfr_set_d.l(*rop.mpfr,op.d,round.l) As "_mpfr_set_d"
  mpfr_set_ld.l(*rop.mpfr,op.d,round.l) As "_mpfr_set_ld"
  mpfr_set_z.l(*rop.mpfr,*op.mpz,round.l) As "_mpfr_set_z"
  mpfr_set_q.l(*rop.mpfr,*op.mpq,round.l) As "_mpfr_set_q"
  mpfr_set_f.l(*rop.mpfr,*op.mpf,round.l) As "_mpfr_set_f"
  mpfr_set_ui_2exp.l(*rop.mpfr,op.l,e.l,round.l) As "_mpfr_set_ui_2exp"
  mpfr_set_si_2exp.l(*rop.mpfr,op.l,e.l,round.l) As "_mpfr_set_si_2exp"
  mpfr_set_str.l(*rop.mpfr,s.s,base.l,round.l) As "_mpfr_set_str"
  mpfr_set_inf(*x.mpfr,sign.l) As "_mpfr_set_inf"
  mpfr_set_nan(*x.mpfr) As "_mpfr_set_nan"
  mpfr_swap(*x.mpfr,*y.mpfr) As "_mpfr_swap"
  mpfr_init_set.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_init_set"
  mpfr_init_set_ui.l(*rop.mpfr,op.l,round.l) As "_mpfr_init_set_ui"
  mpfr_init_set_si.l(*rop.mpfr,op.l,round.l) As "_mpfr_init_set_si"
  mpfr_init_set_d.l(*rop.mpfr,op.d,round.l) As "_mpfr_init_set_d"
  mpfr_init_set_z.l(*rop.mpfr,*op.mpz,round.l) As "_mpfr_init_set_z"
  mpfr_init_set_q.l(*rop.mpfr,*op.mpq,round.l) As "_mpfr_init_set_q"
  mpfr_init_set_f.l(*rop.mpfr,*op.mpf,round.l) As "_mpfr_init_set_f"
  mpfr_get_d.d(*op.mpfr,round.l) As "_mpfr_get_d"
  mpfr_get_ld.d(*op.mpfr,round.l) As "_mpfr_get_ld"
  mpfr_get_d_2exp.d(expt.l,*op.mpfr,round.l) As "_mpfr_get_d_2exp"
  mpfr_get_si.l(*op.mpfr,round.l) As "_mpfr_get_si"
  mpfr_get_ui.l(*op.mpfr,round.l) As "_mpfr_get_ui"
  mpfr_get_z_exp.l(*rop.mpz,*op.mpfr) As "_mpfr_get_z_2exp"
  ;mpfr_get_z_exp.l(*rop.mpz,*op.mpfr) As "_mpfr_get_z_exp"
  mpfr_get_z(*rop.mpz,*op.mpfr,round.l) As "_mpfr_get_z"
  mpfr_get_str(str.s,expptr.l,base.l,n.l,*op.mpfr,round.l) As "_mpfr_get_str"
  mpfr_free_str(str.s) As "_mpfr_free_str"
  mpfr_add.l(*rop.mpfr,*op1.mpfr,*op2.mpfr,round.l) As "_mpfr_add"
  mpfr_add_ui.l(*rop.mpfr,*op1.mpfr,op2.l,round.l) As "_mpfr_add_ui"
  mpfr_add_si.l(*rop.mpfr,*op1.mpfr,op2.l,round.l) As "_mpfr_add_si"
  mpfr_add_z.l(*rop.mpfr,*op1.mpfr,*op2.mpz,round.l) As "_mpfr_add_z"
  mpfr_add_q.l(*rop.mpfr,*op1.mpfr,*op2.mpq,round.l) As "_mpfr_add_q"
  mpfr_sub.l(*rop.mpfr,*op1.mpfr,*op2.mpfr,round.l) As "_mpfr_sub"
  mpfr_ui_sub.l(*rop.mpfr,op1.l,*op2.mpfr,round.l) As "_mpfr_ui_sub"
  mpfr_sub_ui.l(*rop.mpfr,*op1.mpfr,op2.l,round.l) As "_mpfr_sub_ui"
  mpfr_si_sub.l(*rop.mpfr,op1.l,*op2.mpfr,round.l) As "_mpfr_si_sub"
  mpfr_sub_si.l(*rop.mpfr,*op1.mpfr,op2.l,round.l) As "_mpfr_sub_si"
  mpfr_sub_z.l(*rop.mpfr,*op1.mpfr,*op2.mpz,round.l) As "_mpfr_sub_z"
  mpfr_sub_q.l(*rop.mpfr,*op1.mpfr,*op2.mpq,round.l) As "_mpfr_sub_q"
  mpfr_mul.l(*rop.mpfr,*op1.mpfr,*op2.mpfr,round.l) As "_mpfr_mul"
  mpfr_mul_ui.l(*rop.mpfr,*op1.mpfr,op2.l,round.l) As "_mpfr_mul_ui"
  mpfr_mul_si.l(*rop.mpfr,*op1.mpfr,op2.l,round.l) As "_mpfr_mul_si"
  mpfr_mul_z.l(*rop.mpfr,*op1.mpfr,*op2.mpz,round.l) As "_mpfr_mul_z"
  mpfr_mul_q.l(*rop.mpfr,*op1.mpfr,*op2.mpq,round.l) As "_mpfr_mul_q"
  mpfr_sqr.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_sqr"
  mpfr_div.l(*rop.mpfr,*op1.mpfr,*op2.mpfr,round.l) As "_mpfr_div"
  mpfr_ui_div.l(*rop.mpfr,op1.l,*op2.mpfr,round.l) As "_mpfr_ui_div"
  mpfr_div_ui.l(*rop.mpfr,*op1.mpfr,op2.l,round.l) As "_mpfr_div_ui"
  mpfr_si_div.l(*rop.mpfr,op1.l,*op2.mpfr,round.l) As "_mpfr_si_div"
  mpfr_div_si.l(*rop.mpfr,*op1.mpfr,op2.l,round.l) As "_mpfr_div_si"
  mpfr_div_z.l(*rop.mpfr,*op1.mpfr,*op2.mpz,round.l) As "_mpfr_div_z"
  mpfr_div_q.l(*rop.mpfr,*op1.mpfr,*op2.mpq,round.l) As "_mpfr_div_q"
  mpfr_sqrt.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_sqrt"
  mpfr_sqrt_ui.l(*rop.mpfr,op.l,round.l) As "_mpfr_sqrt_ui"
  mpfr_cbrt.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_cbrt"
  mpfr_pow.l(*rop.mpfr,*op1.mpfr,*op2.mpfr,round.l) As "_mpfr_pow"
  mpfr_pow_ui.l(*rop.mpfr,*op1.mpfr,op2.l,round.l) As "_mpfr_pow_ui"
  mpfr_pow_si.l(*rop.mpfr,*op1.mpfr,op2.l,round.l) As "_mpfr_pow_si"
  mpfr_ui_pow_ui.l(*rop.mpfr,op1.l,op2.l,round.l) As "_mpfr_ui_pow_ui"
  mpfr_ui_pow.l(*rop.mpfr,op1.l,*op2.mpfr,round.l) As "_mpfr_ui_pow"
  mpfr_neg.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_neg"
  mpfr_abs.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_abs"
  mpfr_mul_2ui.l(*rop.mpfr,*op1.mpfr,op2.l,round.l) As "_mpfr_mul_2ui"
  mpfr_mul_2si.l(*rop.mpfr,*op1.mpfr,op2.l,round.l) As "_mpfr_mul_2si"
  mpfr_div_2ui.l(*rop.mpfr,*op1.mpfr,op2.l,round.l) As "_mpfr_div_2ui"
  mpfr_div_2si.l(*rop.mpfr,*op1.mpfr,op2.l,round.l) As "_mpfr_div_2si"
  mpfr_cmp.l(*op1.mpfr,*op2.mpfr) As "_mpfr_cmp"
  mpfr_cmp_ui.l(*op1.mpfr,op2.l) As "_mpfr_cmp_ui"
  mpfr_cmp_si.l(*op1.mpfr,op2.l) As "_mpfr_cmp_si"
  mpfr_cmp_d.l(*op1.mpfr,op2.d) As "_mpfr_cmp_d"
  mpfr_cmp_ld.l(*op1.mpfr,op2.d) As "_mpfr_cmp_ld"
  mpfr_cmp_z.l(*op1.mpfr,*op2.mpz) As "_mpfr_cmp_z"
  mpfr_cmp_q.l(*op1.mpfr,*op2.mpq) As "_mpfr_cmp_q"
  mpfr_cmp_f.l(*op1.mpfr,*op2.mpf) As "_mpfr_cmp_f"
  mpfr_cmp_ui_2exp.l(*op1.mpfr,op2.l,e.l) As "_mpfr_cmp_ui_2exp"
  mpfr_cmp_si_2exp.l(*op1.mpfr,op2.l,e.l) As "_mpfr_cmp_si_2exp"
  mpfr_cmpabs.l(*op1.mpfr,*op2.mpfr) As "_mpfr_cmpabs"
  mpfr_nan_p.l(*op.mpfr) As "_mpfr_nan_p"
  mpfr_inf_p.l(*op.mpfr) As "_mpfr_inf_p"
  mpfr_number_p.l(*op.mpfr) As "_mpfr_number_p"
  mpfr_zero_p.l(*op.mpfr) As "_mpfr_zero_p"
  mpfr_sgn.l(*op.mpfr) As "_mpfr_sgn"
  mpfr_greater_p.l(*op1.mpfr,*op2.mpfr) As "_mpfr_greater_p"
  mpfr_greaterequal_p.l(*op1.mpfr,*op2.mpfr) As "_mpfr_greaterequal_p"
  mpfr_less_p.l(*op1.mpfr,*op2.mpfr) As "_mpfr_less_p"
  mpfr_lessequal_p.l(*op1.mpfr,*op2.mpfr) As "_mpfr_lessequal_p"
  mpfr_lessgreater_p.l(*op1.mpfr,*op2.mpfr) As "_mpfr_lessgreater_p"
  mpfr_equal_p.l(*op1.mpfr,*op2.mpfr) As "_mpfr_equal_p"
  mpfr_unordered_p.l(*op1.mpfr,*op2.mpfr) As "_mpfr_unordered_p"
  mpfr_log.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_log"
  mpfr_log2.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_log2"
  mpfr_log10.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_log10"
  mpfr_exp.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_exp"
  mpfr_exp2.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_exp2"
  mpfr_exp10.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_exp10"
  mpfr_cos.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_cos"
  mpfr_sin.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_sin"
  mpfr_tan.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_tan"
  mpfr_sin_cos.l(*sop.mpfr,*cop.mpfr,*op.mpfr,round.l) As "_mpfr_sin_cos"
  mpfr_acos.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_acos"
  mpfr_asin.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_asin"
  mpfr_atan.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_atan"
  mpfr_cosh.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_cosh"
  mpfr_sinh.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_sinh"
  mpfr_tanh.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_tanh"
  mpfr_acosh.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_acosh"
  mpfr_asinh.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_asinh"
  mpfr_atanh.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_atanh"
  mpfr_fac_ui.l(*rop.mpfr,op.l,round.l) As "_mpfr_fac_ui"
  mpfr_log1p.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_log1p"
  mpfr_expm1.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_expm1"
  mpfr_gamma.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_gamma"
  mpfr_lngamma.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_lngamma"
  mpfr_zeta.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_zeta"
  mpfr_erf.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_erf"
  mpfr_fma.l(*rop.mpfr,*op1.mpfr,*op2.mpfr,*op3.mpfr,round.l) As "_mpfr_fma"
  mpfr_agm.l(*rop.mpfr,*op1.mpfr,*op2.mpfr,round.l) As "_mpfr_agm"
  mpfr_const_log2.l(*rop.mpfr,round.l) As "_mpfr_const_log2"
  mpfr_const_pi.l(*rop.mpfr,round.l) As "_mpfr_const_pi"
  mpfr_const_euler.l(*rop.mpfr,round.l) As "_mpfr_const_euler"
  mpfr_free_cache() As "_mpfr_free_cache"
  mpfr_rint.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_rint"
  mpfr_ceil.l(*rop.mpfr,*op.mpfr) As "_mpfr_ceil"
  mpfr_floor.l(*rop.mpfr,*op.mpfr) As "_mpfr_floor"
  mpfr_round.l(*rop.mpfr,*op.mpfr) As "_mpfr_round"
  mpfr_trunc.l(*rop.mpfr,*op.mpfr) As "_mpfr_trunc"
  mpfr_rint_ceil.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_rint_ceil"
  mpfr_rint_floor.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_rint_floor"
  mpfr_rint_round.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_rint_round"
  mpfr_rint_trunc.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_rint_trunc"
  mpfr_frac.l(*rop.mpfr,*op.mpfr,round.l) As "_mpfr_frac"
  mpfr_integer_p.l(*op.mpfr) As "_mpfr_integer_p"
  mpfr_printf (format.s, round.l, *rop.mpfr)
  mpfr_sprintf (dest.s, format.s, round.l, *rop.mpfr)
  mpfr_get_version() As "_mpfr_get_version"

EndImport

Procedure mpfr_to_mpf(*z.mpfr,*x.mpf,*k.mpz)
   xp.l
   xp=mpfr_get_z_exp(*k, *z)
   mpf_set_z(*x, *k)
   If (xp<0)
      xp=Abs(xp)
      mpf_div_2exp(*x,*x,xp)
   Else
      mpf_mul_2exp(*x,*x,xp)
   EndIf
   ProcedureReturn
EndProcedure


OpenConsole() 
ConsoleTitle ("GMP.DLL test") 

s.s

PrintN(" integer -----------------------------------------------------------------------") 

i.mpz 
j.mpz 
k.mpz 

mpz_init(i)
mpz_init(j)
mpz_init(k)
mpz_set_str(i,"3",10)
mpz_set_str(j,"5",10)
mpz_mul(k,i,j)
s=Space(256)
gmp_sprintz(s,"%Zd",k)
PrintN(" 3 * 5 = "+s)
mpz_clear(k)
mpz_clear(j)
mpz_clear(i)
PrintN("")

PrintN(" rational ----------------------------------------------------------------------") 

n.mpq 
m.mpq 
q.mpq 

mpq_init(n)
mpq_init(m)
mpq_init(q)
mpq_set_str(n,"4/12",10) ; to illustrate how to reduce fraction to least common denominator
mpq_canonicalize(n)  ;---> reduce 4/12 to 1/3, fraction need to in reduced form when
                         ; performing arithmetic operatins.
mpq_set_str(m,"1/5",10)
mpq_add(q,n,m)
s=Space(256)
gmp_sprintq(s,"%Qd",q)
PrintN(" 1/3 + 1/5 = "+s)
mpq_clear(q)
mpq_clear(m)
mpq_clear(n)
PrintN("")

PrintN(" floating point mpf ------------------------------------------------------------") 

x.mpf 
y.mpf 
z.mpf 
w.mpfr

mpf_init2(x,256)
mpf_init2(y,256)
mpf_init2(z,256)
mpf_set_str(x,"2",10)
mpf_sqrt(y,x)
s=Space(256)
gmp_sprintf(s,"%57.52Fe",y)
PrintN(" y = sqrt(2) = "+s)
mpf_pow_ui(z,y,2)
s=Space(256)
gmp_sprintf(s,"%57.52Fe",z)
PrintN(" z = y ^ 2   = "+s)
mpf_clear(z)
mpf_clear(y)
mpf_clear(x)
PrintN("")

PrintN(" floating point mpfr -----------------------------------------------------------") 
mpfr_init2(w,256)
mpf_init2(x,256)
mpz_init(k)

l.l=2
;mpfr_set_str(w,"2",10,#GMP_RNDN)
mpfr_set_ui(w,l,#GMP_RNDN) ;set multi-precision w to the value in integer l
mpfr_log10(w,w,#GMP_RNDN)
;mpfr_to_mpf(w,x,k) ; convert mpfr w to mpf in x so we can use sprintf
s=Space(256)
mpfr_sprintf (s,"%57.52R*e", #GMP_RNDN, w)
;gmp_sprintf(s,"%57.52Fe",x)
PrintN(" w = log10(2) = "+s)

mpfr_exp10(w,w,#GMP_RNDN)
;mpfr_to_mpf(w,x,k)
s=Space(256)
mpfr_sprintf (s,"%57.52R*e", #GMP_RNDN, w)
;gmp_sprintf(s,"%57.52Fe",x)
PrintN(" w = exp10(w) = "+s)
PrintN("")

mpfr_clear(w)
mpf_clear(x)
mpz_clear(k)

;- random ------------------------------------------------------------------ 
PrintN(" random numbers ------------------------------------------------------------") 
rand_state.gmp_randstate_t
rand_num.mpz
ran_bnd.mpz
rand_bits.l=64

mpz_init(@rand_num)
mpz_init(@ran_bnd)

;mpz_set_str(@ran_bnd,"200",10)
gmp_randinit_default(@rand_state)
gmp_randseed_ui(@rand_state, 1234567890)

For r=1 To 10
  mpz_urandomb(@rand_num, @rand_state, rand_bits)
  s=Space(256)
  gmp_sprintz(s,"%Zd",@rand_num)
  PrintN(s)
Next  
mpz_clear(@ran_bnd)
mpz_clear(@rand_num)
gmp_randclear(@rand_state)
;- end random ------------------------------------------------------------------ 
s=PeekS(mpfr_get_version())
PrintN("mpfr version "+s)
Print("press the return key to end. ")
Input()
CloseConsole() 
End
Last edited by jack on Sun Apr 14, 2013 1:17 am, edited 2 times in total.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

forgot to mention that you need to make import libraries from the dll's and put them into PureBasic\PureLibraries\Windows\Libraries folder
the dll's I would put into WINDOWS\system32 folder
to make an import library do
polib libgmp-3.dll /machine:ix86 /out:libgmp-3.lib
polib libmpfr-1.dll /machine:ix86 /out:libmpfr-1.lib
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: mathematical library

Post by jack »

the links for precompiled gmp and mpfr libraries as posted above are no longer valid,
you can get precompiled gmp from http://sourceforge.net/projects/mingw/files/ click on MSYS gmp
as for mpfr I don't know, you probably have to build it yourself with MinGW
------------------------
to make mpfr with MinGW:
launch Msys
cd into mpfr folder
./configure --disable-static --enable-shared --with-gmp=/usr/local
make
make check
make install
------------------------

this assumes that you installed the gmp library
/usr/local is on my system C:\msys\1.0\local but you still use /usr/local, it's just a hint as to where it might point

there's also gsl (double precision) never used it though
there are many more

also see http://www.purebasic.fr/english/viewtop ... 13&t=35173 there's a solution on using MAPM as a dll
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: mathematical library

Post by applePi »

thanks jack for the valuable info
i have tried your code but i have got an error message using pb4.31:
The procedure entry point __gmp_rand could not be located in the dynamic link library libgmp-3.dll
Image

do we need to define more functions in the ImportC "libgmp-3.lib"
or ImportC "libmpfr-1.lib"
i have downloaded a precompiled libgmp-3.dll and libmpfr-1.dll from here:
http://www.cs.berkeley.edu/~fateman/generic/
http://www.cs.berkeley.edu/~fateman/gen ... bgmp-3.dll
http://www.cs.berkeley.edu/~fateman/gen ... mpfr-1.dll
and have made an import library as you said by:
polib libgmp-3.dll /machine:ix86 /out:libgmp-3.lib
polib libmpfr-1.dll /machine:ix86 /out:libmpfr-1.lib

regards
p.s there is also a precompiled gmp dll from here:
ftp://deltatrinity.dyndns.org/gmp-4.3.1 ... /pentium4/
for other versions: ftp://deltatrinity.dyndns.org
Last edited by applePi on Tue Sep 29, 2009 6:54 am, edited 1 time in total.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: mathematical library

Post by jack »

I will have to take a look at the random functions, been working long days.
deltatrinity is probably the best source for precompiled gmp.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: mathematical library

Post by applePi »

hi jack
your code are running okay now, but when we use version gmp 4.1.4 from here ftp://deltatrinity.dyndns.org/Archive/g ... /pentium4/
Image

i have looked to http://www.archivum.info/debian-bugs-cl ... h_GMP_4.2)
it is said that the internal symbol __gmp_rand. In 4.1.4 this was a function and therefore a symbol in libgmp. In 4.2, it is a #define and thus no symbol.
if i have the latest version of mpfr then i think i can use the latest gmp v4.3.1
it is said that this bug is fixed in the latest version of mpfr

regards
Last edited by applePi on Tue Sep 29, 2009 7:40 am, edited 1 time in total.
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: mathematical library

Post by Kukulkan »

Have you seen HIME: http://www.devotechs.com/HIMEMain.html ?

Seem to do well...

Kukulkan
Post Reply