Author Topic: mpfr  (Read 6626 times)

0 Members and 1 Guest are viewing this topic.

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
mpfr
« on: March 20, 2019, 08:25:58 pm »
here's an almost complete include for the mpfr library https://www.mpfr.org, this is for Windows, datatypes are likely to be different on linux.
[linux version below near end of thread]
warning: not exhaustively tested
mpfr-include.bi
Code: QB64: [Select]
  1. Const MPFR_RNDN = 0
  2. Const MPFR_RNDZ = 1
  3. Const MPFR_RNDU = 2
  4. Const MPFR_RNDD = 3
  5. Const MPFR_RNDA = 4
  6. Const MPFR_RNDF = 5
  7. Const MPFR_RNDNA = -1
  8.  
  9. Type mpz_struct
  10.     mp_alloc As Long
  11.     mp_size As Long
  12.     mp_d As _Offset
  13.  
  14. Type mpq_struct
  15.     mp_num As mpz_struct
  16.     mp_den As mpz_struct
  17.  
  18. Type mpf_struct
  19.     mp_prec As Long
  20.     mp_size As Long
  21.     mp_exp As Long
  22.     mp_d As _Offset
  23.  
  24. Type mpfr_struct
  25.     mpfr_prec As _Offset
  26.     mpfr_sign As Long
  27.     mpfr_exp As _Offset
  28.     mpfr_d As _Offset
  29.  
  30. '    DECLARE DYNAMIC LIBRARY "libgmp-10"
  31. '    END DECLARE
  32.  
  33. Declare Dynamic Library "libmpfr-6"
  34.     Function mpfr_get_version$
  35.     Function mpfr_get_patches$
  36.     Function mpfr_buildopt_tune_case$
  37.     Function mpfr_buildopt_tls_p&
  38.     Function mpfr_buildopt_decimal_p&
  39.     Function mpfr_buildopt_gmpinternals_p&
  40.     Function mpfr_get_emin&
  41.     Function mpfr_set_emin& (ByVal emin As Long)
  42.     Function mpfr_get_emin_min&
  43.     Function mpfr_get_emin_max&
  44.     Function mpfr_get_emax&
  45.     Function mpfr_set_emax& (ByVal emax As Long)
  46.     Function mpfr_get_emax_min&
  47.     Function mpfr_get_emax_max&
  48.     Sub mpfr_set_default_rounding_mode (ByVal rm As Long)
  49.     Function mpfr_get_default_rounding_mode&
  50.     Function mpfr_print_rnd_mode$ (ByVal rndm As Long)
  51.     Sub mpfr_clear_flags
  52.     Sub mpfr_clear_underflow
  53.     Sub mpfr_clear_overflow
  54.     Sub mpfr_clear_divby0
  55.     Sub mpfr_clear_nanflag
  56.     Sub mpfr_clear_inexflag
  57.     Sub mpfr_clear_erangeflag
  58.     Sub mpfr_set_underflow
  59.     Sub mpfr_set_overflow
  60.     Sub mpfr_set_divby0
  61.     Sub mpfr_set_nanflag
  62.     Sub mpfr_set_inexflag
  63.     Sub mpfr_set_erangeflag
  64.     Function mpfr_underflow_p&
  65.     Function mpfr_overflow_p&
  66.     Function mpfr_divby0_p&
  67.     Function mpfr_nanflag_p&
  68.     Function mpfr_inexflag_p&
  69.     Function mpfr_erangeflag_p&
  70.     Function mpfr_check_range& (rop As mpfr_struct, Byval op2 As Long, Byval op3 As Long)
  71.     Sub mpfr_init2 (rop As mpfr_struct, Byval op1 As Long)
  72.     Sub mpfr_init (rop As mpfr_struct)
  73.     Sub mpfr_clear (rop As mpfr_struct)
  74.     Function mpfr_prec_round& (rop As mpfr_struct, Byval op1 As Long, Byval op2 As Long)
  75.     Function mpfr_can_round& (rop As mpfr_struct, Byval op1 As Long, Byval op2 As Long, Byval op3 As Long, Byval op4 As Long)
  76.     Function mpfr_min_prec& (rop As mpfr_struct)
  77.     Function mpfr_get_exp& (rop As mpfr_struct)
  78.     Function mpfr_set_exp& (rop As mpfr_struct, Byval op1 As Long)
  79.     Function mpfr_get_prec& (rop As mpfr_struct)
  80.     Sub mpfr_set_prec (rop As mpfr_struct, Byval mpfr_prec As Long)
  81.     Sub mpfr_set_prec_raw (rop As mpfr_struct, Byval mpfr_prec As Long)
  82.     Sub mpfr_set_default_prec (ByVal mpfr_prec As Long)
  83.     Function mpfr_get_default_prec& ()
  84.     Function mpfr_set_d& (rop As mpfr_struct, Byval x As Double, Byval mpfr_rnd As Long)
  85.     Function mpfr_set_flt& (rop As mpfr_struct, Byval x As Single, Byval mpfr_rnd As Long)
  86.     Function mpfr_set_ld& (rop As mpfr_struct, Byval x As _Float, Byval mpfr_rnd As Long)
  87.     Function mpfr_set_z& (rop As mpfr_struct, opz As mpz_struct, Byval mpfr_rnd As Long)
  88.     Function mpfr_set_z_2exp& (rop As mpfr_struct, opz As mpz_struct, Byval mpfr_exp_t As Long, Byval mpfr_rnd As Long)
  89.     Sub mpfr_set_nan (rop As mpfr_struct)
  90.     Sub mpfr_set_inf (rop As mpfr_struct, Byval n As Long)
  91.     Sub mpfr_set_zero (rop As mpfr_struct, Byval n As Long)
  92.     Function mpfr_set_f& (rop As mpfr_struct, mpf As mpf_struct, Byval mpfr_rnd As Long)
  93.     Function mpfr_get_f& (rop As mpf_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  94.     Function mpfr_set_si& (rop As mpfr_struct, Byval n As Long, Byval mpfr_rnd As Long)
  95.     Function mpfr_set_ui& (rop As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  96.     Function mpfr_set_si_2exp& (rop As mpfr_struct, Byval n As Long, Byval mpfr_exp_t As Long, Byval mpfr_rnd As Long)
  97.     Function mpfr_set_ui_2exp& (rop As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_exp_t As Long, Byval mpfr_rnd As Long)
  98.     Function mpfr_set_q& (rop As mpfr_struct, opq As mpq_struct, Byval mpfr_rnd As Long)
  99.     Function mpfr_set_str& (rop As mpfr_struct, char As String, Byval nbase As Long, Byval rd As Long)
  100.     Function mpfr_init_set_str& (rop As mpfr_struct, s As String, Byval n As Long, Byval mpfr_rnd As Long)
  101.     Function mpfr_set4& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long, Byval n As Long)
  102.     Function mpfr_abs& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  103.     Function mpfr_set& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  104.     Function mpfr_neg& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  105.     Function mpfr_signbit& (op As mpfr_struct)
  106.     Function mpfr_setsign& (rop As mpfr_struct, op As mpfr_struct, Byval n As Long, Byval mpfr_rnd As Long)
  107.     Function mpfr_copysign& (rop As mpfr_struct, op1 As mpfr_struct, op2 As mpfr_struct, Byval mpfr_rnd As Long)
  108.     Function mpfr_get_z_2exp& (z As mpz_struct, op As mpfr_struct)
  109.     Function mpfr_get_flt! (op As mpfr_struct, Byval mpfr_rnd As Long)
  110.     Function mpfr_get_d# (op As mpfr_struct, Byval mpfr_rnd As Long)
  111.     Function mpfr_get_ld## (op As mpfr_struct, Byval mpfr_rnd As Long)
  112.     Function mpfr_get_d1# (op As mpfr_struct)
  113.     Function mpfr_get_d_2exp# (n As Long, op As mpfr_struct, Byval mpfr_rnd As Long)
  114.     Function mpfr_get_ld_2exp## (n As Long, op As mpfr_struct, Byval mpfr_rnd As Long)
  115.     Function mpfr_frexp& (n As Long, rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  116.     Function mpfr_get_si& (op As mpfr_struct, Byval mpfr_rnd As Long)
  117.     Function mpfr_get_ui~& (op As mpfr_struct, Byval mpfr_rnd As Long)
  118.     Function mpfr_get_str$ (s As String, n As Long, Byval m As Long, Byval k As _Unsigned Long, op As mpfr_struct, Byval mpfr_rnd As Long)
  119.     Function mpfr_get_z& (z As mpz_struct, f As mpfr_struct, Byval mpfr_rnd As Long)
  120.     Sub mpfr_nextabove (rop As mpfr_struct)
  121.     Sub mpfr_nextbelow (rop As mpfr_struct)
  122.     Sub mpfr_nexttoward (rop As mpfr_struct, op As mpfr_struct)
  123.     Function mpfr_pow& (rop As mpfr_struct, op1 As mpfr_struct, op2 As mpfr_struct, Byval mpfr_rnd As Long)
  124.     Function mpfr_pow_si& (rop As mpfr_struct, op As mpfr_struct, Byval n As Long, Byval mpfr_rnd As Long)
  125.     Function mpfr_pow_ui& (rop As mpfr_struct, op As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  126.     Function mpfr_ui_pow_ui& (rop As mpfr_struct, Byval culong As _Unsigned Long, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  127.     Function mpfr_ui_pow& (rop As mpfr_struct, Byval culong As _Unsigned Long, op As mpfr_struct, Byval mpfr_rnd As Long)
  128.     Function mpfr_pow_z& (rop As mpfr_struct, op1 As mpfr_struct, z As mpz_struct, Byval mpfr_rnd As Long)
  129.     Function mpfr_sqrt& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  130.     Function mpfr_sqrt_ui& (rop As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  131.     Function mpfr_rec_sqrt& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  132.     Function mpfr_add& (rop As mpfr_struct, op1 As mpfr_struct, op2 As mpfr_struct, Byval mpfr_rnd As Long)
  133.     Function mpfr_sub& (rop As mpfr_struct, op1 As mpfr_struct, op2 As mpfr_struct, Byval mpfr_rnd As Long)
  134.     Function mpfr_mul& (rop As mpfr_struct, op1 As mpfr_struct, op2 As mpfr_struct, Byval mpfr_rnd As Long)
  135.     Function mpfr_div& (rop As mpfr_struct, op1 As mpfr_struct, op2 As mpfr_struct, Byval mpfr_rnd As Long)
  136.     Function mpfr_add_ui& (rop As mpfr_struct, op1 As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  137.     Function mpfr_sub_ui& (rop As mpfr_struct, op1 As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  138.     Function mpfr_ui_sub& (rop As mpfr_struct, Byval culong As _Unsigned Long, op As mpfr_struct, Byval mpfr_rnd As Long)
  139.     Function mpfr_mul_ui& (rop As mpfr_struct, op1 As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  140.     Function mpfr_div_ui& (rop As mpfr_struct, op1 As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  141.     Function mpfr_ui_div& (rop As mpfr_struct, Byval culong As _Unsigned Long, op As mpfr_struct, Byval mpfr_rnd As Long)
  142.     Function mpfr_add_si& (rop As mpfr_struct, op1 As mpfr_struct, Byval n As Long, Byval mpfr_rnd As Long)
  143.     Function mpfr_sub_si& (rop As mpfr_struct, op1 As mpfr_struct, Byval n As Long, Byval mpfr_rnd As Long)
  144.     Function mpfr_si_sub& (rop As mpfr_struct, Byval n As Long, op As mpfr_struct, Byval mpfr_rnd As Long)
  145.     Function mpfr_mul_si& (rop As mpfr_struct, op1 As mpfr_struct, Byval n As Long, Byval mpfr_rnd As Long)
  146.     Function mpfr_div_si& (rop As mpfr_struct, op1 As mpfr_struct, Byval n As Long, Byval mpfr_rnd As Long)
  147.     Function mpfr_si_div& (rop As mpfr_struct, Byval n As Long, op As mpfr_struct, Byval mpfr_rnd As Long)
  148.     Function mpfr_add_d& (rop As mpfr_struct, op1 As mpfr_struct, Byval x As Double, Byval mpfr_rnd As Long)
  149.     Function mpfr_sub_d& (rop As mpfr_struct, op1 As mpfr_struct, Byval x As Double, Byval mpfr_rnd As Long)
  150.     Function mpfr_d_sub& (rop As mpfr_struct, Byval x As Double, op As mpfr_struct, Byval mpfr_rnd As Long)
  151.     Function mpfr_mul_d& (rop As mpfr_struct, op1 As mpfr_struct, Byval x As Double, Byval mpfr_rnd As Long)
  152.     Function mpfr_div_d& (rop As mpfr_struct, op1 As mpfr_struct, Byval x As Double, Byval mpfr_rnd As Long)
  153.     Function mpfr_d_div& (rop As mpfr_struct, Byval x As Double, op As mpfr_struct, Byval mpfr_rnd As Long)
  154.     Function mpfr_sqr& (rop As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  155.     Function mpfr_const_pi& (rop As mpfr_struct, Byval op As Long)
  156.     Function mpfr_const_log2& (rop As mpfr_struct, Byval mpfr_rnd As Long)
  157.     Function mpfr_const_euler& (rop As mpfr_struct, Byval mpfr_rnd As Long)
  158.     Function mpfr_const_catalan& (rop As mpfr_struct, Byval mpfr_rnd As Long)
  159.     Function mpfr_agm& (rop As mpfr_struct, op1 As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  160.     Function mpfr_log& (rop As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  161.     Function mpfr_log2& (rop As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  162.     Function mpfr_log10& (rop As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  163.     Function mpfr_log1p& (rop As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  164.     Function mpfr_exp& (rop As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  165.     Function mpfr_exp2& (rop As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  166.     Function mpfr_exp10& (rop As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  167.     Function mpfr_expm1& (rop As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  168.     Function mpfr_eint& (rop As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  169.     Function mpfr_li2& (rop As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  170.     Function mpfr_cmp& (op As mpfr_struct, op1 As mpfr_struct)
  171.     Function mpfr_cmp3& (op As mpfr_struct, op1 As mpfr_struct, Byval n As Long)
  172.     Function mpfr_cmp_d& (rop As mpfr_struct, Byval x As Double)
  173.     Function mpfr_cmp_ld& (rop As mpfr_struct, Byval x As _Float)
  174.     Function mpfr_cmpabs& (rop As mpfr_struct, op1 As mpfr_struct)
  175.     Function mpfr_cmp_ui& (rop As mpfr_struct, Byval culong As _Unsigned Long)
  176.     Function mpfr_cmp_si& (rop As mpfr_struct, Byval n As Long)
  177.     Function mpfr_cmp_ui_2exp& (rop As mpfr_struct, Byval culong As _Unsigned Long, Byval n As Long)
  178.     Function mpfr_cmp_si_2exp& (rop As mpfr_struct, Byval cl As Long, Byval n As Long)
  179.     Sub mpfr_reldiff (rop As mpfr_struct, op1 As mpfr_struct, op2 As mpfr_struct, Byval mpfr_rnd As Long)
  180.     Function mpfr_eq& (rop As mpfr_struct, op1 As mpfr_struct, Byval culong As _Unsigned Long)
  181.     Function mpfr_sgn& (rop As mpfr_struct)
  182.     Function mpfr_mul_2exp& (rop As mpfr_struct, op As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  183.     Function mpfr_div_2exp& (rop As mpfr_struct, op As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  184.     Function mpfr_mul_2ui& (rop As mpfr_struct, op As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  185.     Function mpfr_div_2ui& (rop As mpfr_struct, op As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  186.     Function mpfr_mul_2si& (rop As mpfr_struct, op As mpfr_struct, Byval n As Long, Byval mpfr_rnd As Long)
  187.     Function mpfr_div_2si& (rop As mpfr_struct, op As mpfr_struct, Byval n As Long, Byval mpfr_rnd As Long)
  188.     Function mpfr_rint& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  189.     Function mpfr_round& (rop As mpfr_struct, op As mpfr_struct)
  190.     Function mpfr_trunc& (rop As mpfr_struct, op As mpfr_struct)
  191.     Function mpfr_ceil& (rop As mpfr_struct, op As mpfr_struct)
  192.     Function mpfr_floor& (rop As mpfr_struct, op As mpfr_struct)
  193.     Function mpfr_rint_round& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  194.     Function mpfr_rint_trunc& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  195.     Function mpfr_rint_ceil& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  196.     Function mpfr_rint_floor& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  197.     Function mpfr_frac& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  198.     Function mpfr_modf& (rop As mpfr_struct, op As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  199.     Function mpfr_remquo& (rop As mpfr_struct, n As Long, op1 As mpfr_struct, op2 As mpfr_struct, Byval mpfr_rnd As Long)
  200.     Function mpfr_remainder& (rop As mpfr_struct, op1 As mpfr_struct, op2 As mpfr_struct, Byval mpfr_rnd As Long)
  201.     Function mpfr_fmod& (rop As mpfr_struct, op1 As mpfr_struct, op2 As mpfr_struct, Byval mpfr_rnd As Long)
  202.     Function mpfr_fits_ulong_p& (op As mpfr_struct, Byval mpfr_rnd As Long)
  203.     Function mpfr_fits_slong_p& (op As mpfr_struct, Byval mpfr_rnd As Long)
  204.     Function mpfr_fits_uint_p& (op As mpfr_struct, Byval mpfr_rnd As Long)
  205.     Function mpfr_fits_sint_p& (op As mpfr_struct, Byval mpfr_rnd As Long)
  206.     Function mpfr_fits_ushort_p& (op As mpfr_struct, Byval mpfr_rnd As Long)
  207.     Function mpfr_fits_sshort_p& (op As mpfr_struct, Byval mpfr_rnd As Long)
  208.     Function mpfr_fits_uintmax_p& (op As mpfr_struct, Byval mpfr_rnd As Long)
  209.     Function mpfr_fits_intmax_p& (op As mpfr_struct, Byval mpfr_rnd As Long)
  210.     Sub mpfr_extract (z As mpz_struct, op As mpfr_struct, Byval n As _Unsigned Long)
  211.     Sub mpfr_swap (rop As mpfr_struct, op As mpfr_struct)
  212.     Sub mpfr_dump (op As mpfr_struct)
  213.     Function mpfr_nan_p& (op As mpfr_struct)
  214.     Function mpfr_inf_p& (op As mpfr_struct)
  215.     Function mpfr_number_p& (op As mpfr_struct)
  216.     Function mpfr_integer_p& (op As mpfr_struct)
  217.     Function mpfr_zero_p& (op As mpfr_struct)
  218.     Function mpfr_regular_p& (op As mpfr_struct)
  219.     Function mpfr_greater_p& (op As mpfr_struct, op1 As mpfr_struct)
  220.     Function mpfr_greaterequal_p& (op As mpfr_struct, op1 As mpfr_struct)
  221.     Function mpfr_less_p& (op As mpfr_struct, op1 As mpfr_struct)
  222.     Function mpfr_lessequal_p& (op As mpfr_struct, op1 As mpfr_struct)
  223.     Function mpfr_lessgreater_p& (op As mpfr_struct, op1 As mpfr_struct)
  224.     Function mpfr_equal_p& (op As mpfr_struct, op1 As mpfr_struct)
  225.     Function mpfr_unordered_p& (op As mpfr_struct, op1 As mpfr_struct)
  226.     Function mpfr_atanh& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  227.     Function mpfr_acosh& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  228.     Function mpfr_asinh& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  229.     Function mpfr_cosh& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  230.     Function mpfr_sinh& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  231.     Function mpfr_tanh& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  232.     Function mpfr_sinh_cosh& (rop As mpfr_struct, op As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  233.     Function mpfr_sech& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  234.     Function mpfr_csch& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  235.     Function mpfr_coth& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  236.     Function mpfr_acos& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  237.     Function mpfr_asin& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  238.     Function mpfr_atan& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  239.     Function mpfr_sin& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  240.     Function mpfr_sin_cos& (rop As mpfr_struct, op As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  241.     Function mpfr_cos& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  242.     Function mpfr_tan& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  243.     Function mpfr_atan2& (rop As mpfr_struct, op As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  244.     Function mpfr_sec& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  245.     Function mpfr_csc& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  246.     Function mpfr_cot& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  247.     Function mpfr_hypot& (rop As mpfr_struct, op As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  248.     Function mpfr_erf& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  249.     Function mpfr_erfc& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  250.     Function mpfr_cbrt& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  251.     Function mpfr_root& (rop As mpfr_struct, op As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  252.     Function mpfr_gamma& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  253.     Function mpfr_lngamma& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  254.     Function mpfr_lgamma& (rop As mpfr_struct, n As Long, op As mpfr_struct, Byval mpfr_rnd As Long)
  255.     Function mpfr_digamma& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  256.     Function mpfr_zeta& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  257.     Function mpfr_zeta_ui& (rop As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  258.     Function mpfr_fac_ui& (rop As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  259.     Function mpfr_j0& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  260.     Function mpfr_j1& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  261.     Function mpfr_jn& (rop As mpfr_struct, Byval n As Long, op As mpfr_struct, Byval mpfr_rnd As Long)
  262.     Function mpfr_y0& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  263.     Function mpfr_y1& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  264.     Function mpfr_yn& (rop As mpfr_struct, Byval n As Long, op As mpfr_struct, Byval mpfr_rnd As Long)
  265.     Function mpfr_ai& (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  266.     Function mpfr_min& (rop As mpfr_struct, op As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  267.     Function mpfr_max& (rop As mpfr_struct, op As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  268.     Function mpfr_dim& (rop As mpfr_struct, op As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  269.     Function mpfr_mul_z& (rop As mpfr_struct, op As mpfr_struct, z As mpz_struct, Byval mpfr_rnd As Long)
  270.     Function mpfr_div_z& (rop As mpfr_struct, op As mpfr_struct, z As mpz_struct, Byval mpfr_rnd As Long)
  271.     Function mpfr_add_z& (rop As mpfr_struct, op As mpfr_struct, z As mpz_struct, Byval mpfr_rnd As Long)
  272.     Function mpfr_sub_z& (rop As mpfr_struct, op As mpfr_struct, z As mpz_struct, Byval mpfr_rnd As Long)
  273.     Function mpfr_z_sub& (rop As mpfr_struct, z As mpz_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  274.     Function mpfr_cmp_z& (op As mpfr_struct, z As mpz_struct)
  275.     Function mpfr_mul_q& (rop As mpfr_struct, op As mpfr_struct, q As mpq_struct, Byval mpfr_rnd As Long)
  276.     Function mpfr_div_q& (rop As mpfr_struct, op As mpfr_struct, q As mpq_struct, Byval mpfr_rnd As Long)
  277.     Function mpfr_add_q& (rop As mpfr_struct, op As mpfr_struct, q As mpq_struct, Byval mpfr_rnd As Long)
  278.     Function mpfr_sub_q& (rop As mpfr_struct, op As mpfr_struct, q As mpq_struct, Byval mpfr_rnd As Long)
  279.     Function mpfr_cmp_q& (op As mpfr_struct, q As mpq_struct)
  280.     Function mpfr_cmp_f& (op As mpfr_struct, f As mpf_struct)
  281.     Function mpfr_fma& (rop As mpfr_struct, op As mpfr_struct, op1 As mpfr_struct, op2 As mpfr_struct, Byval mpfr_rnd As Long)
  282.     Function mpfr_fms& (rop As mpfr_struct, op As mpfr_struct, op1 As mpfr_struct, op2 As mpfr_struct, Byval mpfr_rnd As Long)
  283.     Function mpfr_sum& (rop As mpfr_struct, op1 As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  284.     Sub mpfr_free_cache ()
  285.     Function mpfr_subnormalize& (rop As mpfr_struct, Byval n As Long, Byval mpfr_rnd As Long)
  286.     Function mpfr_strtofr& (rop As mpfr_struct, s As String, s2 As String, Byval n As Long, Byval mpfr_rnd As Long)
  287.     Function mpfr_custom_get_size~& (ByVal mpfr_prec As Long)
  288.     Sub mpfr_custom_init (any As _Offset, Byval mpfr_prec As Long)
  289.     Function mpfr_custom_get_significand%& (op As mpfr_struct)
  290.     Function mpfr_custom_get_exp& (op As mpfr_struct)
  291.     Sub mpfr_custom_move (rop As mpfr_struct, any As _Offset)
  292.     Sub mpfr_custom_init_set (rop As mpfr_struct, Byval n As Long, Byval n2 As Long, Byval mpfr_prec As Long, any As _Offset)
  293.     Function mpfr_custom_get_kind& (op As mpfr_struct)
  294.     Function mpfr_snprintf& (rop As String, Byval n As _Unsigned _Offset, frmt As String, src2 As mpfr_struct)
  295.  
  296. Sub print_mpfr_g (f As mpfr_struct, n As Long, m As Long)
  297.     Dim sresult(0) As String, frmt As String
  298.     Erase sresult
  299.     Dim sresult(0) As String
  300.     Dim ln As Long
  301.     frmt = "%" + LTrim$(Str$(n)) + "." + LTrim$(Str$(m)) + "RNg" + Chr$(0)
  302.     ln = mpfr_snprintf&("", 0, frmt, f)
  303.     If ln > 0 Then
  304.         sresult(0) = Space$(ln) + Chr$(0)
  305.         ln = mpfr_snprintf&(sresult(0), ln + 4, frmt, f)
  306.     End If
  307.     Print Left$(sresult(0), ln)
  308.  
  309. Sub print_mpfr_f (f As mpfr_struct, n As Long, m As Long)
  310.     Dim sresult(0) As String, frmt As String
  311.     Erase sresult
  312.     Dim sresult(0) As String
  313.     Dim ln As Long
  314.     frmt = "%" + LTrim$(Str$(n)) + "." + LTrim$(Str$(m)) + "RNf" + Chr$(0)
  315.     ln = mpfr_snprintf&("", 0, frmt, f)
  316.     If ln > 0 Then
  317.         sresult(0) = Space$(ln) + Chr$(0)
  318.         ln = mpfr_snprintf&(sresult(0), ln + 4, frmt, f)
  319.     End If
  320.     Print Left$(sresult(0), ln)
  321.  
  322. Sub print_mpfr_e (f As mpfr_struct, n As Long, m As Long)
  323.     Dim sresult(0) As String, frmt As String
  324.     Erase sresult
  325.     Dim sresult(0) As String
  326.     Dim ln As Long
  327.     frmt = "%" + LTrim$(Str$(n)) + "." + LTrim$(Str$(m)) + "RNe" + Chr$(0)
  328.     ln = mpfr_snprintf&("", 0, frmt, f)
  329.     If ln > 0 Then
  330.         sresult(0) = Space$(ln) + Chr$(0)
  331.         ln = mpfr_snprintf&(sresult(0), ln + 4, frmt, f)
  332.     End If
  333.     Print Left$(sresult(0), ln)
  334.  
  335. Sub valmpfr (result As mpfr_struct, value As String, nbase As Long)
  336.     Dim c As Long
  337.     c = mpfr_set_str(result, value, nbase, 0)
  338.  
simple-test.bas
Code: QB64: [Select]
  1. '$CONSOLE:ONLY
  2. '_DEST _CONSOLE
  3.  
  4. WIDTH 90, 43
  5.  
  6. main
  7.  
  8. REM $include: 'mpfr-include.bi'
  9.  
  10. SUB main
  11.     DIM x AS mpfr_struct, y AS mpfr_struct
  12.     DIM c AS LONG
  13.  
  14.     CALL mpfr_init2(x, 1024)
  15.     CALL mpfr_init2(y, 1024)
  16.  
  17.     FOR i = 1 TO 20
  18.         c = mpfr_set_si(x, i, MPFR_RNDN)
  19.         c = mpfr_log10(y, x, MPFR_RNDN)
  20.         PRINT i;
  21.         CALL print_mpfr_f(y, 77, 70)
  22.     NEXT
  23.  
  24.     CALL mpfr_clear(y)
  25.     CALL mpfr_clear(x)
  26.  
* mpfr-QB64.zip (Filesize: 2.26 MB, Downloads: 252)
« Last Edit: February 03, 2022, 08:04:07 am by jack »

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: mpfr
« Reply #1 on: March 21, 2019, 07:41:53 am »
a more complex example
lanczos gamma approximation
Code: QB64: [Select]
  1.  
  2.  
  3. DIM SHARED error_code AS LONG
  4. main
  5.  
  6. REM $include: 'mpfr-include.bi'
  7. SUB main
  8.     DIM c AS LONG, n AS LONG, i AS LONG
  9.  
  10.     prec = 1024 ' bits precision, about 300 decimal digits
  11.     n = 6
  12.     DIM x(n) AS mpfr_struct, g AS mpfr_struct
  13.     FOR i = 0 TO n
  14.         CALL mpfr_init2(x(i), prec)
  15.     NEXT
  16.     CALL mpfr_init2(g, prec)
  17.     c = mpfr_set_si(g, 5, MPFR_RNDN)
  18.     CALL make_lanczos(x(), g, error_code)
  19.     PRINT "lanczos approximation for the gamma function"
  20.     PRINT "          n = 6, g = 5"
  21.     FOR i = 0 TO n
  22.         PRINT USING "C(##) = "; i;
  23.         CALL print_mpfr_f(x(i), 27, 20)
  24.     NEXT
  25.     FOR i = 0 TO n
  26.         CALL mpfr_clear(x(i))
  27.     NEXT
  28.  
  29.     PRINT "==============================================="
  30.     PRINT "lanczos approximation for the gamma function"
  31.     PRINT "          n = 14, g = 4.7421875"
  32.     ERASE x
  33.     n = 14
  34.     DIM x(n) AS mpfr_struct
  35.     FOR i = 0 TO n
  36.         CALL mpfr_init2(x(i), prec)
  37.     NEXT
  38.     CALL valmpfr(g, "4.7421875", 10)
  39.     CALL make_lanczos(x(), g, error_code)
  40.     FOR i = 0 TO n
  41.         PRINT USING "C(##) = "; i;
  42.         CALL print_mpfr_f(x(i), 27, 20)
  43.     NEXT
  44.     FOR i = 0 TO n
  45.         CALL mpfr_clear(x(i))
  46.     NEXT
  47.     CALL mpfr_clear(g)
  48.  
  49. SUB make_lanczos (x() AS mpfr_struct, g AS mpfr_struct, error_code AS LONG)
  50.  
  51.     DIM i AS LONG, j AS LONG, n AS LONG, c AS LONG
  52.     n = UBOUND(x)
  53.     DIM a(n, n) AS mpfr_struct
  54.     DIM b(n) AS mpfr_struct
  55.     DIM sqr2pi AS mpfr_struct, pi2 AS mpfr_struct, fac AS mpfr_struct
  56.     DIM one AS mpfr_struct, tmp AS mpfr_struct, tmp2 AS mpfr_struct
  57.     FOR i = 0 TO n
  58.         FOR j = 0 TO n
  59.             CALL mpfr_init2(a(i, j), prec)
  60.         NEXT
  61.         CALL mpfr_init2(b(i), prec)
  62.     NEXT
  63.     CALL mpfr_init2(sqr2pi, prec)
  64.     CALL mpfr_init2(pi2, prec)
  65.     CALL mpfr_init2(fac, prec)
  66.     CALL mpfr_init2(one, prec)
  67.     CALL mpfr_init2(tmp, prec)
  68.     CALL mpfr_init2(tmp2, prec)
  69.     c = mpfr_set_si(one, 1, MPFR_RNDN)
  70.     c = mpfr_const_pi(pi2, MPFR_RNDN)
  71.     c = mpfr_mul_si(pi2, pi2, 2, MPFR_RNDN)
  72.     c = mpfr_sqrt(sqr2pi, pi2, MPFR_RNDN)
  73.  
  74.     'setup the matrix, for n=6 the matrix looks like this
  75.  
  76.     ' [[ 1, 1,   1/2, 1/3, 1/4,  1/5,  1/6 ]
  77.     ' [  1, 1/2, 1/3, 1/4, 1/5,  1/6,  1/7 ]
  78.     ' [  1, 1/3, 1/4, 1/5, 1/6,  1/7,  1/8 ]
  79.     ' [  1, 1/4, 1/5, 1/6, 1/7,  1/8,  1/9 ]
  80.     ' [  1. 1/5, 1/6, 1/7, 1/8,  1/9,  1/10 ]
  81.     ' [  1, 1/6, 1/7, 1/8, 1/9,  1/10, 1/11 ]
  82.     ' [  1, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12 ]]
  83.  
  84.     FOR i = 0 TO n
  85.         c = mpfr_set_si(a(i, 0), 1, MPFR_RNDN)
  86.         FOR j = 1 TO n
  87.             c = mpfr_div_si(a(i, j), one, i + j, MPFR_RNDN)
  88.         NEXT
  89.     NEXT
  90.  
  91.     'setup the constant terms, for n=6 and g=5 they are
  92.     'b( 0) = 41.62443691643906820752
  93.     'b( 1) = 16.01231640525168135809
  94.     'b( 2) =  9.36473553710404851170
  95.     'b( 3) =  6.57049625931606149987
  96.     'b( 4) =  5.09521672929646781312
  97.     'b( 5) =  4.20380175313001102196
  98.     'b( 6) =  3.61487381446333490266
  99.  
  100.     c = mpfr_set_si(fac, 1, MPFR_RNDN)
  101.  
  102.     FOR i = 0 TO n
  103.         IF i > 1 THEN
  104.             c = mpfr_mul_si(fac, fac, i, MPFR_RNDN)
  105.         END IF
  106.         'b(i)=exp(i+half+g)/(i+half+g)^(i+half)*fac/sqr2pi
  107.         c = mpfr_add_d(tmp, g, 0.5, MPFR_RNDN)
  108.         c = mpfr_add_si(tmp, tmp, i, MPFR_RNDN)
  109.         c = mpfr_exp(b(i), tmp, MPFR_RNDN)
  110.         c = mpfr_set_d(tmp2, i + 0.5, MPFR_RNDN)
  111.         c = mpfr_pow(tmp, tmp, tmp2, MPFR_RNDN)
  112.         c = mpfr_div(b(i), b(i), tmp, MPFR_RNDN)
  113.         c = mpfr_mul(b(i), b(i), fac, MPFR_RNDN)
  114.         c = mpfr_div(b(i), b(i), sqr2pi, MPFR_RNDN)
  115.         'CALL print_mpfr_f(b(i), 27, 20)
  116.     NEXT
  117.  
  118.     'now solve the system of linear equations, for n=6 and g=5 they are
  119.     ' [[ 1, 1,   1/2, 1/3, 1/4,  1/5,  1/6 ]    = 41.62443691643906820752
  120.     ' [  1, 1/2, 1/3, 1/4, 1/5,  1/6,  1/7 ]    = 16.01231640525168135809
  121.     ' [  1, 1/3, 1/4, 1/5, 1/6,  1/7,  1/8 ]    =  9.36473553710404851170
  122.     ' [  1, 1/4, 1/5, 1/6, 1/7,  1/8,  1/9 ]    =  6.57049625931606149987
  123.     ' [  1. 1/5, 1/6, 1/7, 1/8,  1/9,  1/10 ]   =  5.09521672929646781312
  124.     ' [  1, 1/6, 1/7, 1/8, 1/9,  1/10, 1/11 ]   =  4.20380175313001102196
  125.     ' [  1, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12 ]]  =  3.61487381446333490266
  126.  
  127.     'and the solution for the above example is
  128.     'C(0) =   1.00000000019001482399
  129.     'C(1) =  76.18009172947146348309
  130.     'C(2) = -86.50532032941676765250
  131.     'C(3) =  24.01409824083091049018
  132.     'C(4) =  -1.23173957245015538752
  133.     'C(5) =   0.00120865097386617851
  134.     'C(6) =  -0.00000539523938495313
  135.  
  136.     'which is the Lanczos gamma function approximation
  137.     'as published in Numerical recipes
  138.  
  139.     CALL gauss_jordan(a(), b(), x(), n, error_code)
  140.  
  141.     FOR i = 0 TO n
  142.         FOR j = 0 TO n
  143.             CALL mpfr_clear(a(i, j))
  144.         NEXT
  145.         CALL mpfr_clear(b(i))
  146.     NEXT
  147.     CALL mpfr_clear(sqr2pi)
  148.     CALL mpfr_clear(pi2)
  149.     CALL mpfr_clear(fac)
  150.     CALL mpfr_clear(one)
  151.     CALL mpfr_clear(tmp)
  152.     CALL mpfr_clear(tmp2)
  153.  
  154.  
  155.  
  156. SUB gauss_jordan (a() AS mpfr_struct, y() AS mpfr_struct, coef() AS mpfr_struct, ncol AS LONG, error_code AS LONG)
  157.  
  158.     ' matrix solution by Gaussian Elimination
  159.  
  160.     DIM b(ncol, ncol) AS mpfr_struct, w(ncol) AS mpfr_struct ' work array, ncol long
  161.  
  162.     DIM i AS LONG, j AS LONG, i1 AS LONG, k AS LONG, l AS LONG, n AS LONG, c AS LONG
  163.     DIM hold AS mpfr_struct, sm AS mpfr_struct, tmp AS mpfr_struct
  164.     DIM t AS mpfr_struct, ab AS mpfr_struct, big AS mpfr_struct
  165.     CONST TRUE = -1
  166.     CONST FALSE = NOT TRUE
  167.  
  168.     error_code = FALSE
  169.     n = ncol
  170.  
  171.     FOR i = 0 TO ncol
  172.         FOR j = 0 TO ncol
  173.             CALL mpfr_init2(b(i, j), prec)
  174.         NEXT
  175.         CALL mpfr_init2(w(i), prec)
  176.     NEXT
  177.     CALL mpfr_init2(hold, prec)
  178.     CALL mpfr_init2(sm, prec)
  179.     CALL mpfr_init2(t, prec)
  180.     CALL mpfr_init2(ab, prec)
  181.     CALL mpfr_init2(big, prec)
  182.     CALL mpfr_init2(tmp, prec)
  183.  
  184.     FOR i = 0 TO n
  185.         ' copy to work arrays
  186.         FOR j = 0 TO n
  187.             'b(i,j)=a(i,j)
  188.             c = mpfr_set(b(i, j), a(i, j), MPFR_RNDN)
  189.         NEXT j
  190.         'w(i)=y(i)
  191.         c = mpfr_set(w(i), y(i), MPFR_RNDN)
  192.         'coef(i)=zero
  193.         c = mpfr_set_si(coef(i), 0, MPFR_RNDN)
  194.     NEXT
  195.     FOR i = 0 TO n - 1
  196.         c = mpfr_abs(big, b(i, i), MPFR_RNDN)
  197.  
  198.         l = i
  199.         i1 = i + 1
  200.         FOR j = i1 TO n
  201.             ' search for largest element
  202.             c = mpfr_abs(ab, b(j, i), MPFR_RNDN)
  203.             IF mpfr_cmp(ab, big) > 0 THEN
  204.                 c = mpfr_set(big, ab, MPFR_RNDN)
  205.                 l = j
  206.             END IF
  207.         NEXT
  208.         IF mpfr_cmp_si(big, 0) = 0 THEN
  209.             error_code = TRUE
  210.         ELSE
  211.             IF l <> i THEN
  212.                 ' interchange rows to put largest element on diagonal
  213.                 FOR j = 0 TO n
  214.                     c = mpfr_set(hold, b(l, j), MPFR_RNDN)
  215.                     c = mpfr_set(b(l, j), b(i, j), MPFR_RNDN)
  216.                     c = mpfr_set(b(i, j), hold, MPFR_RNDN)
  217.                 NEXT
  218.                 c = mpfr_set(hold, w(l), MPFR_RNDN)
  219.                 c = mpfr_set(w(l), w(i), MPFR_RNDN)
  220.                 c = mpfr_set(w(i), hold, MPFR_RNDN)
  221.             END IF
  222.             FOR j = i1 TO n
  223.                 c = mpfr_div(t, b(j, i), b(i, i), MPFR_RNDN)
  224.                 FOR k = i1 TO n
  225.                     c = mpfr_mul(tmp, t, b(i, k), MPFR_RNDN)
  226.                     c = mpfr_sub(b(j, k), b(j, k), tmp, MPFR_RNDN)
  227.                 NEXT
  228.                 c = mpfr_mul(tmp, t, w(i), MPFR_RNDN)
  229.                 c = mpfr_sub(w(j), w(j), tmp, MPFR_RNDN)
  230.             NEXT ' j-loop
  231.         END IF ' if big - else
  232.     NEXT ' i-loop
  233.     IF mpfr_cmp_si(b(n, n), 0) = 0 THEN
  234.         error_code = TRUE
  235.     ELSE
  236.         c = mpfr_div(coef(n), w(n), b(n, n), MPFR_RNDN)
  237.         i = n - 1
  238.         ' back substitution
  239.         DO
  240.             c = mpfr_set_si(sm, 0, MPFR_RNDN)
  241.             FOR j = i TO n
  242.                 c = mpfr_mul(tmp, b(i, j), coef(j), MPFR_RNDN)
  243.                 c = mpfr_add(sm, sm, tmp, MPFR_RNDN)
  244.             NEXT
  245.             c = mpfr_sub(tmp, w(i), sm, MPFR_RNDN)
  246.             c = mpfr_div(coef(i), tmp, b(i, i), MPFR_RNDN)
  247.             i = i - 1
  248.         LOOP UNTIL i < 0
  249.     END IF
  250.     IF error_code THEN PRINT "ERROR: Matrix is singular"
  251.    
  252.     FOR i = 0 TO ncol
  253.         FOR j = 0 TO ncol
  254.             CALL mpfr_clear(b(i, j))
  255.         NEXT
  256.         CALL mpfr_clear(w(i))
  257.     NEXT
  258.     CALL mpfr_clear(hold)
  259.     CALL mpfr_clear(sm)
  260.     CALL mpfr_clear(t)
  261.     CALL mpfr_clear(ab)
  262.     CALL mpfr_clear(big)
  263.     CALL mpfr_clear(tmp)
  264.  
the output
Code: QB64: [Select]
  1. C( 0 ) =      1.00000000019001482399
  2. C( 1 ) =     76.18009172947146348309
  3. C( 2 ) =    -86.50532032941676765250
  4. C( 3 ) =     24.01409824083091049018
  5. C( 4 ) =     -1.23173957245015538752
  6. C( 5 ) =      0.00120865097386617851
  7. C( 6 ) =     -0.00000539523938495313
  8.  
example of using the approximation, see https://en.wikipedia.org/wiki/Lanczos_approximation
Code: QB64: [Select]
  1. DIM y AS DOUBLE, z AS DOUBLE, sqrt2pi AS DOUBLE, g AS DOUBLE
  2.  
  3. sqrt2pi = 2.506628274631000502
  4. g = 5
  5. c(0) = 1.000000000190014824
  6. c(1) = 76.180091729471463483
  7. c(2) = -86.505320329416767652
  8. c(3) = 24.01409824083091049
  9. c(4) = -1.2317395724501553875
  10. c(5) = 0.0012086509738661785061
  11. c(6) = -5.3952393849531283785E-06
  12.  
  13. INPUT "enter z "; z
  14. y = c(0)
  15. FOR i = 1 TO 6
  16.     y = y + c(i) / (z + i)
  17. y = y * sqrt2pi * (z + g + 0.5) ^ (z + 0.5) * EXP(-(z + g + 0.5))
  18. PRINT "gamma( 1 + "; z; ") = "; y
  19.  
« Last Edit: March 21, 2019, 10:49:02 pm by jack »

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: mpfr
« Reply #2 on: March 24, 2019, 09:01:46 pm »
I found the Spouge algorithm for the Gamma function interesting https://en.wikipedia.org/wiki/Spouge%27s_approximation
the coefficients are easy to calculate but don't give very accurate results

let's take a = 7, we have the coefficients ( after dividing the coefficients by Sqr(2*Pi) )
Code: QB64: [Select]
  1. C( 0) =  1
  2. C( 1) =  394.2326437490294715
  3. C( 2) = -661.96874077331269907
  4. C( 3) =  348.50416767875391816
  5. C( 4) = -62.454919463566450249
  6. C( 5) =  2.7792189888444614869
  7. C( 6) = -0.0090369795951602295551
  8.  
some tests
Code: QB64: [Select]
  1. a = 7
  2. fac =1
  3. dim as double sqrt2pi
  4. sqrt2pi = 2.5066282746310005024157652848110452530
  5.  
  6. C( 0) =  1
  7. C( 1) =  394.2326437490294715
  8. C( 2) = -661.96874077331269907
  9. C( 3) =  348.50416767875391816
  10. C( 4) = -62.454919463566450249
  11. C( 5) =  2.7792189888444614869
  12. C( 6) = -0.0090369795951602295551
  13.  
  14. for z=1 to 10
  15.         fac=fac*z
  16.         y = c(0)
  17.         FOR i = 1 TO a-1
  18.                 y = y + c(i) / (z + i)
  19.         NEXT
  20.         y =  y * (z+a)^(z+0.5)*exp(-(z+a))*sqrt2pi
  21.         PRINT "spouge-gamma("; z; ") = "; y, (y-fac)/fac
  22.  
  23. z=0.5
  24. fac=0.88622692545275801364908374167057259140
  25.  
  26. y = c(0)
  27. FOR i = 1 TO a-1
  28.         y = y + c(i) / (z + i)
  29. y = y * (z + a)^(z+0.5)*exp(-(z+a))*sqrt2pi
  30. PRINT "spouge-gamma("; z; ") = "; y, (y-fac)/fac
  31.  
the results
Quote
spouge-gamma( 1) =  0.9999999996137302    -3.862697939283066e-10
spouge-gamma( 2) =  1.999999998666582     -6.667089103018498e-10
spouge-gamma( 3) =  5.999999994337436     -9.437606252049591e-10
spouge-gamma( 4) =  23.99999997127829     -1.19673811601236e-09
spouge-gamma( 5) =  119.999999829899      -1.417508125693227e-09
spouge-gamma( 6) =  719.9999988446054     -1.604714662385555e-09
spouge-gamma( 7) =  5039.999991128157     -1.760286392839459e-09
spouge-gamma( 8) =  40319.99992389513     -1.887521453422128e-09
spouge-gamma( 9) =  362879.9992778363     -1.99008957806045e-09
spouge-gamma( 10) =  3628799.992482762    -2.071549184825699e-09
spouge-gamma( 0.5) =  0.8862269252253806  -2.565679778746878e-10
now, let's use the lanczos scheme to calculate the coefficients
Code: QB64: [Select]
  1. 1, 1/1,1/2,1/3,1/4, 1/5, 1/6    =       Factorial(0)/(7^(1/2)*Exp(-7)*Sqr(2*Pi))
  2. 1, 1/2,1/3,1/4,1/5, 1/6, 1/7    =       Factorial(1)/(( 1+7)^( 1+(1/2))*Exp(-( 1+7))*Sqr(2*Pi))
  3. 1, 1/3,1/4,1/5,1/6, 1/7, 1/8    =       Factorial(2)/(( 2+7)^( 2+(1/2))*Exp(-( 2+7))*Sqr(2*Pi))
  4. 1, 1/4,1/5,1/6,1/7, 1/8, 1/9    =       Factorial(3)/(( 3+7)^( 3+(1/2))*Exp(-( 3+7))*Sqr(2*Pi))
  5. 1, 1/5,1/6,1/7,1/8, 1/9, 1/10   =       Factorial(4)/(( 4+7)^( 4+(1/2))*Exp(-( 4+7))*Sqr(2*Pi))
  6. 1, 1/6,1/7,1/8,1/9, 1/10,1/11   =       Factorial(5)/(( 5+7)^( 5+(1/2))*Exp(-( 5+7))*Sqr(2*Pi))
  7. 1, 1/7,1/8,1/9,1/10,1/11,1/12   =       Factorial(6)/(( 6+7)^( 6+(1/2))*Exp(-( 6+7))*Sqr(2*Pi))
  8.  
the solution
Code: QB64: [Select]
  1. C( 0) =  0.99999999995273358926
  2. C( 1) =  394.23264374929666793
  3. C( 2) = -661.96874078550137586
  4. C( 3) =  348.50416780528271853
  5. C( 4) = -62.454919950924562754
  6. C( 5) =  2.7792197239908234111
  7. C( 6) = -0.0090372064455749738392
  8.  
the results after replacing the coeffients
Quote
spouge-lanczos-gamma( 1) =  0.9999999999999999    -1.110223024625157e-16
spouge-lanczos-gamma( 2) =  1.999999999999999     -5.551115123125783e-16
spouge-lanczos-gamma( 3) =  5.999999999999997     -4.440892098500626e-16
spouge-lanczos-gamma( 4) =  24                             -1.480297366166875e-16
spouge-lanczos-gamma( 5) =  119.9999999999999     -4.736951571734001e-16
spouge-lanczos-gamma( 6) =  719.9999999999998     -3.157967714489334e-16
spouge-lanczos-gamma( 7) =  5039.999999999991     -1.804552979708191e-15
spouge-lanczos-gamma( 8) =  40319.99999999953     -1.154913907013242e-14
spouge-lanczos-gamma( 9) =  362879.9999999893     -2.951446651256063e-14
spouge-lanczos-gamma( 10) =  3628799.999999764    -6.506015009507931e-14
spouge-lanczos-gamma( 0.5) =  0.8862269254527551  -3.382431835905346e-15
« Last Edit: March 25, 2019, 08:38:00 pm by jack »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: mpfr
« Reply #3 on: March 28, 2019, 10:52:40 pm »
Need help getting this to work on linux

I'm getting
Code: QB64: [Select]
  1. Caused by (or after):DECLARE DYNAMIC LIBRARY "libmpfr",7

I have libmpfr installed here:

/usr/lib/libmpfr.so.6
/usr/lib/libmpfr.so
/usr/lib/libmpfr.so.6.0.1

none of those work when put in DECLARE LIBRARY

I was hoping to demonstrate an interesting example with fractals since I've used GMP library in C for rendering fractals

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: mpfr
« Reply #4 on: March 28, 2019, 11:04:58 pm »
Need help getting this to work on linux

I'm getting
Code: QB64: [Select]
  1. Caused by (or after):DECLARE DYNAMIC LIBRARY "libmpfr",7

I have libmpfr installed here:

/usr/lib/libmpfr.so.6
/usr/lib/libmpfr.so
/usr/lib/libmpfr.so.6.0.1

none of those work when put in DECLARE LIBRARY

I was hoping to demonstrate an interesting example with fractals since I've used GMP library in C for rendering fractals

I wish you the best of luck in sorting DECLARE LIBRARY out with Linux.  Try all I might, I never could get it to work with libpng.so, no matter where I put it, or how I declared it.  If somebody can help you get yours working, maybe their advice can help me get mine working as well, so we can do PNG exports on Linux systems.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: mpfr
« Reply #5 on: March 29, 2019, 05:21:24 am »
@_vince
what linux distribution do you use?
32 or 64-bit ?
the problem in my windows translation is that I replaced types like mpfr_rnd_t with long (4 bytes), some of the type's may have different size in linux, will check
too bad that QB64 doesn't have a typedef statement and I am not sure if it could be accomplished with meta commands

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: mpfr
« Reply #6 on: March 29, 2019, 05:53:26 am »
as I suspected, there are different type siszes in Win64 and Linux64
Win64
Quote
SizeOf int 4
SizeOf unsigned int 4
SizeOf long int 4
SizeOf unsigned long int 4
SizeOf long 4
SizeOf unsigned long 4
SizeOf long long int 8
SizeOf unsigned long long int 8
=====================
=========== mpz_struct ==========
SizeOf __mpz_struct 16
SizeOf int 4
SizeOf int 4
SizeOf mp_limb_t 8
=====================
=========== mpq_struct ==========
SizeOf __mpq_struct 32
SizeOf __mpz_struct 16
SizeOf __mpz_struct 16
=====================
=========== mpf_struct ==========
SizeOf __mpf_struct 24
SizeOf int 4
SizeOf int 4
SizeOf mp_exp_t 4
SizeOf mp_limb_t 8
=====================
=========== gmp_randstate_struc ==========
SizeOf __gmp_randstate_struct 32
SizeOf mpz_t 16
SizeOf gmp_randalg_t 4
=====================
=========== mpfr_struct ==========
SizeOf __mpfr_struct 24
SizeOf mpfr_prec_t 4
SizeOf mpfr_sign_t 4
SizeOf mpfr_exp_t 4
SizeOf mp_limb_t 8
=====================
SizeOf mp_bitcnt_t 4
SizeOf size_t 8
SizeOf mp_limb_t 8
SizeOf mp_exp_t 4
SizeOf mp_size_t 4
SizeOf mpfr_t 24
SizeOf mpfr_rnd_t 4
SizeOf mpfr_void 1
SizeOf mpfr_int 4
SizeOf mpfr_long 4
SizeOf mpfr_sign_t 4
SizeOf long double 16
Ubuntu64
Quote
SizeOf int 4
SizeOf unsigned int 4
SizeOf long int 8
SizeOf unsigned long int 8
SizeOf long 8
SizeOf unsigned long 8
SizeOf long long int 8
SizeOf unsigned long long int 8
=====================
=========== mpz_struct ==========
SizeOf __mpz_struct 16
SizeOf int 4
SizeOf int 4
SizeOf mp_limb_t 8
=====================
=========== mpq_struct ==========
SizeOf __mpq_struct 32
SizeOf __mpz_struct 16
SizeOf __mpz_struct 16
=====================
=========== mpf_struct ==========
SizeOf __mpf_struct 24
SizeOf int 4
SizeOf int 4
SizeOf mp_exp_t 8
SizeOf mp_limb_t 8
=====================
=========== gmp_randstate_struc ==========
SizeOf __gmp_randstate_struct 32
SizeOf mpz_t 16
SizeOf gmp_randalg_t 4
=====================
=========== mpfr_struct ==========
SizeOf __mpfr_struct 32
SizeOf mpfr_prec_t 8
SizeOf mpfr_sign_t 4
SizeOf mpfr_exp_t 8
SizeOf mp_limb_t 8
=====================
SizeOf mp_bitcnt_t 8
SizeOf size_t 8
SizeOf mp_limb_t 8
SizeOf mp_exp_t 8
SizeOf mp_size_t 8
SizeOf mpfr_t 32
SizeOf mpfr_rnd_t 4
SizeOf mpfr_void 1
SizeOf mpfr_int 4
SizeOf mpfr_long 8
SizeOf mpfr_sign_t 4
SizeOf long double 16
the size of mpfr_struc is 24-bytes in Win64 but 32-bytes in Linux64
the SizeOf long int is 4 in Win64 but 8 in Linux64
the SizeOf mpfr_prec_t is 4 in Win64 but 8 in Linux64
the SizeOf mpfr_exp_t is 4 in Win64 but 8 in Linux64

so I will have to check each declare to make sure the proper size integer is used, that will take time

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: mpfr
« Reply #7 on: March 29, 2019, 07:54:53 am »
Need help getting this to work on linux

I'm getting
Code: QB64: [Select]
  1. Caused by (or after):DECLARE DYNAMIC LIBRARY "libmpfr",7

I have libmpfr installed here:

/usr/lib/libmpfr.so.6
/usr/lib/libmpfr.so
/usr/lib/libmpfr.so.6.0.1

none of those work when put in DECLARE LIBRARY

I was hoping to demonstrate an interesting example with fractals since I've used GMP library in C for rendering fractals
in your case, since the libraries are in /usr/lib, all you need to do is remove "lib" from the lib name, that is DECLARE DYNAMIC LIBRARY "mpfr" but my include needs fixing before you can use it in linux

@SMcNeill
as you may have guessed, try using png instead of libpng, if libpng is not in /usr/lib then I suggest that you make a symlink, for example sudo ln -s /usr/lib/x86_64-linux-gnu/libpng.so /usr/lib/libpng.so
« Last Edit: March 29, 2019, 08:06:01 am by jack »

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: mpfr
« Reply #8 on: March 31, 2019, 11:58:03 pm »
tested on Ubuntu both 32-bit and 64 bit
note: you can either hard-code the library path in the include or make symlinks of libgmp.so and libmpfr.so to /usr/lib
in my case, the libraries in question reside in /usr/lib/i386-linux-gnu/gmp and /usr/lib/i386-linux-gnu/mpfr in Ubuntu-i386
and in /usr/lib/x86_64-linux-gnu/gmp and /usr/lib/x86_64-linux-gnu/mpfr
so I would declare the library as DECLARE DYNAMIC LIBRARY "i386-linux-gnu/gmp" and DECLARE DYNAMIC LIBRARY "i386-linux-gnu/mpfr"
or DECLARE DYNAMIC LIBRARY "x86_64-linux-gnu/gmp" and DECLARE DYNAMIC LIBRARY "x86_64-linux-gnu/mpfr"

mpfr-include.bi
Code: QB64: [Select]
  1. CONST MPFR_RNDN = 0
  2. CONST MPFR_RNDZ = 1
  3. CONST MPFR_RNDU = 2
  4. CONST MPFR_RNDD = 3
  5. CONST MPFR_RNDA = 4
  6. CONST MPFR_RNDF = 5
  7. CONST MPFR_RNDNA = -1
  8.  
  9. TYPE mpz_struct
  10.     mp_alloc AS LONG
  11.     mp_size AS LONG
  12.     mp_d AS _OFFSET
  13.  
  14. TYPE mpq_struct
  15.     mp_num AS mpz_struct
  16.     mp_den AS mpz_struct
  17.  
  18. TYPE mpf_struct
  19.     mp_prec AS LONG
  20.     mp_size AS LONG
  21.     mp_exp AS _OFFSET
  22.     mp_d AS _OFFSET
  23.  
  24. TYPE mpfr_struct
  25.     mpfr_prec AS _OFFSET
  26.     mpfr_sign AS _OFFSET 'LONG
  27.     mpfr_exp AS _OFFSET
  28.     mpfr_d AS _OFFSET
  29.  
  30.  
  31.     SUB mpfr_init2 (x AS mpfr_struct, BYVAL prec AS _OFFSET)
  32.     'Sub mpfr_inits2 (byval prec As _offset, x AS mpfr_struct, ...)
  33.     SUB mpfr_clear (x AS mpfr_struct)
  34.     'Sub mpfr_clears (x AS mpfr_struct, ...)
  35.     SUB mpfr_init (x AS mpfr_struct)
  36.     'Sub mpfr_inits (x AS mpfr_struct, ...)
  37.     SUB mpfr_set_default_prec (BYVAL prec AS _OFFSET)
  38.     FUNCTION mpfr_get_default_prec%&
  39.     SUB mpfr_set_prec (x AS mpfr_struct, BYVAL prec AS _OFFSET)
  40.     FUNCTION mpfr_get_prec%& (x AS mpfr_struct)
  41.     FUNCTION mpfr_set& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  42.     FUNCTION mpfr_set_ui& (rop AS mpfr_struct, BYVAL op AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  43.     FUNCTION mpfr_set_si& (rop AS mpfr_struct, BYVAL op AS _OFFSET, BYVAL rndm AS LONG)
  44.     ''FUNCTION mpfr_set_uj& (rop AS mpfr_struct, BYVAL op AS _UNSIGNED _INTEGER64, BYVAL rndm AS LONG)
  45.     ''FUNCTION mpfr_set_sj& (rop AS mpfr_struct, BYVAL op AS _INTEGER64, BYVAL rndm AS LONG)
  46.     FUNCTION mpfr_set_flt& (rop AS mpfr_struct, BYVAL op AS SINGLE, BYVAL rndm AS LONG)
  47.     FUNCTION mpfr_set_d& (rop AS mpfr_struct, BYVAL op AS DOUBLE, BYVAL rndm AS LONG)
  48.     FUNCTION mpfr_set_ld& (rop AS mpfr_struct, BYVAL op AS _FLOAT, BYVAL rndm AS LONG)
  49.     'Function mpfr_set_float128& (rop AS mpfr_struct, __float128 op, Byval rndm as long )
  50.     'Function mpfr_set_decimal64& (rop AS mpfr_struct, _Decimal64 op, Byval rndm as long )
  51.     FUNCTION mpfr_set_z& (rop AS mpfr_struct, op AS mpz_struct, BYVAL rndm AS LONG)
  52.     FUNCTION mpfr_set_q& (rop AS mpfr_struct, op AS mpq_struct, BYVAL rndm AS LONG)
  53.     FUNCTION mpfr_set_f& (rop AS mpfr_struct, op AS mpf_struct, BYVAL rndm AS LONG)
  54.     FUNCTION mpfr_set_ui_2exp& (rop AS mpfr_struct, BYVAL op AS _UNSIGNED _OFFSET, BYVAL e AS _OFFSET, BYVAL rndm AS LONG)
  55.     FUNCTION mpfr_set_si_2exp& (rop AS mpfr_struct, BYVAL op AS _OFFSET, BYVAL e AS _OFFSET, BYVAL rndm AS LONG)
  56.     ''FUNCTION mpfr_set_uj_2exp& (rop AS mpfr_struct, BYVAL op AS _UNSIGNED _INTEGER64, BYVAL e AS _INTEGER64, BYVAL rndm AS LONG)
  57.     ''FUNCTION mpfr_set_sj_2exp& (rop AS mpfr_struct, BYVAL op AS _INTEGER64, BYVAL e AS _INTEGER64, BYVAL rndm AS LONG)
  58.     FUNCTION mpfr_set_z_2exp& (rop AS mpfr_struct, op AS mpz_struct, BYVAL e AS _OFFSET, BYVAL rndm AS LONG)
  59.     FUNCTION mpfr_set_str& (rop AS mpfr_struct, s AS STRING, BYVAL base AS LONG, BYVAL rndm AS LONG)
  60.     FUNCTION mpfr_strtofr& (rop AS mpfr_struct, nptr AS STRING, endptr AS _OFFSET, BYVAL base AS LONG, BYVAL rndm AS LONG)
  61.     SUB mpfr_set_nan (x AS mpfr_struct)
  62.     SUB mpfr_set_inf (x AS mpfr_struct, BYVAL sign AS LONG)
  63.     SUB mpfr_set_zero (x AS mpfr_struct, BYVAL sign AS LONG)
  64.     SUB mpfr_swap (x AS mpfr_struct, y AS mpfr_struct)
  65.     FUNCTION mpfr_init_set_str& (x AS mpfr_struct, s AS STRING, BYVAL base AS LONG, BYVAL rndm AS LONG)
  66.     FUNCTION mpfr_get_flt! (op AS mpfr_struct, BYVAL rndm AS LONG)
  67.     FUNCTION mpfr_get_d# (op AS mpfr_struct, BYVAL rndm AS LONG)
  68.     FUNCTION mpfr_get_ld## (op AS mpfr_struct, BYVAL rndm AS LONG)
  69.     'Function mpfr_get_float128@__float128 (op AS mpfr_struct, Byval rndm as long )
  70.     'Function mpfr_get_decimal64@_Decimal64 (op AS mpfr_struct, Byval rndm as long )
  71.     FUNCTION mpfr_get_si%& (op AS mpfr_struct, BYVAL rndm AS LONG)
  72.     FUNCTION mpfr_get_ui~%& (op AS mpfr_struct, BYVAL rndm AS LONG)
  73.     ''FUNCTION mpfr_get_sj&& (op AS mpfr_struct, BYVAL rndm AS LONG)
  74.     ''FUNCTION mpfr_get_uj~&& (op AS mpfr_struct, BYVAL rndm AS LONG)
  75.     FUNCTION mpfr_get_d_2exp# (exp1 AS _OFFSET, op AS mpfr_struct, BYVAL rndm AS LONG)
  76.     FUNCTION mpfr_get_ld_2exp## (exp1 AS _OFFSET, op AS mpfr_struct, BYVAL rndm AS LONG)
  77.     FUNCTION mpfr_frexp& (exp1 AS _OFFSET, y AS mpfr_struct, x AS mpfr_struct, BYVAL rndm AS LONG)
  78.     FUNCTION mpfr_get_z_2exp%& (rop AS mpz_struct, op AS mpfr_struct)
  79.     FUNCTION mpfr_get_z& (rop AS mpz_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  80.     SUB mpfr_get_q (rop AS mpq_struct, op AS mpfr_struct)
  81.     FUNCTION mpfr_get_f& (rop AS mpf_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  82.     FUNCTION mpfr_get_str$ (str1 AS STRING, expptr AS _OFFSET, BYVAL b AS LONG, BYVAL n AS _OFFSET, op AS mpfr_struct, BYVAL rndm AS LONG)
  83.     '' SUB mpfr_free_str (str1 AS _OFFSET,) '' not sure about these, mpfr_get_str and mpfr_free_str
  84.     FUNCTION mpfr_fits_ulong_p& (op AS mpfr_struct, BYVAL rndm AS LONG)
  85.     FUNCTION mpfr_fits_slong_p& (op AS mpfr_struct, BYVAL rndm AS LONG)
  86.     FUNCTION mpfr_fits_uint_p& (op AS mpfr_struct, BYVAL rndm AS LONG)
  87.     FUNCTION mpfr_fits_sint_p& (op AS mpfr_struct, BYVAL rndm AS LONG)
  88.     FUNCTION mpfr_fits_ushort_p& (op AS mpfr_struct, BYVAL rndm AS LONG)
  89.     FUNCTION mpfr_fits_sshort_p& (op AS mpfr_struct, BYVAL rndm AS LONG)
  90.     FUNCTION mpfr_fits_uintmax_p& (op AS mpfr_struct, BYVAL rndm AS LONG)
  91.     FUNCTION mpfr_fits_intmax_p& (op AS mpfr_struct, BYVAL rndm AS LONG)
  92.     FUNCTION mpfr_add& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  93.     FUNCTION mpfr_add_ui& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  94.     FUNCTION mpfr_add_si& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _OFFSET, BYVAL rndm AS LONG)
  95.     FUNCTION mpfr_add_d& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS DOUBLE, BYVAL rndm AS LONG)
  96.     FUNCTION mpfr_add_z& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpz_struct, BYVAL rndm AS LONG)
  97.     FUNCTION mpfr_add_q& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpq_struct, BYVAL rndm AS LONG)
  98.     FUNCTION mpfr_sub& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  99.     FUNCTION mpfr_ui_sub& (rop AS mpfr_struct, BYVAL op1 AS _UNSIGNED _OFFSET, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  100.     FUNCTION mpfr_sub_ui& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  101.     FUNCTION mpfr_si_sub& (rop AS mpfr_struct, BYVAL op1 AS _OFFSET, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  102.     FUNCTION mpfr_sub_si& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _OFFSET, BYVAL rndm AS LONG)
  103.     FUNCTION mpfr_d_sub& (rop AS mpfr_struct, BYVAL op1 AS DOUBLE, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  104.     FUNCTION mpfr_sub_d& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS DOUBLE, BYVAL rndm AS LONG)
  105.     FUNCTION mpfr_z_sub& (rop AS mpfr_struct, op1 AS mpz_struct, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  106.     FUNCTION mpfr_sub_z& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpz_struct, BYVAL rndm AS LONG)
  107.     FUNCTION mpfr_sub_q& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpq_struct, BYVAL rndm AS LONG)
  108.     FUNCTION mpfr_mul& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  109.     FUNCTION mpfr_mul_ui& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  110.     FUNCTION mpfr_mul_si& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _OFFSET, BYVAL rndm AS LONG)
  111.     FUNCTION mpfr_mul_d& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS DOUBLE, BYVAL rndm AS LONG)
  112.     FUNCTION mpfr_mul_z& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpz_struct, BYVAL rndm AS LONG)
  113.     FUNCTION mpfr_mul_q& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpq_struct, BYVAL rndm AS LONG)
  114.     FUNCTION mpfr_sqr& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  115.     FUNCTION mpfr_div& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  116.     FUNCTION mpfr_ui_div& (rop AS mpfr_struct, BYVAL op1 AS _UNSIGNED _OFFSET, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  117.     FUNCTION mpfr_div_ui& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  118.     FUNCTION mpfr_si_div& (rop AS mpfr_struct, BYVAL op1 AS _OFFSET, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  119.     FUNCTION mpfr_div_si& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _OFFSET, BYVAL rndm AS LONG)
  120.     FUNCTION mpfr_d_div& (rop AS mpfr_struct, BYVAL op1 AS DOUBLE, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  121.     FUNCTION mpfr_div_d& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS DOUBLE, BYVAL rndm AS LONG)
  122.     FUNCTION mpfr_div_z& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpz_struct, BYVAL rndm AS LONG)
  123.     FUNCTION mpfr_div_q& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpq_struct, BYVAL rndm AS LONG)
  124.     FUNCTION mpfr_sqrt& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  125.     FUNCTION mpfr_sqrt_ui& (rop AS mpfr_struct, BYVAL op AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  126.     FUNCTION mpfr_rec_sqrt& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  127.     FUNCTION mpfr_cbrt& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  128.     FUNCTION mpfr_rootn_ui& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL k AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  129.     FUNCTION mpfr_root& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL k AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  130.     FUNCTION mpfr_pow& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  131.     FUNCTION mpfr_pow_ui& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  132.     FUNCTION mpfr_pow_si& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _OFFSET, BYVAL rndm AS LONG)
  133.     FUNCTION mpfr_pow_z& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpz_struct, BYVAL rndm AS LONG)
  134.     FUNCTION mpfr_ui_pow_ui& (rop AS mpfr_struct, BYVAL op1 AS _UNSIGNED _OFFSET, BYVAL op2 AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  135.     FUNCTION mpfr_ui_pow& (rop AS mpfr_struct, BYVAL op1 AS _UNSIGNED _OFFSET, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  136.     FUNCTION mpfr_neg& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  137.     FUNCTION mpfr_abs& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  138.     FUNCTION mpfr_dim& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  139.     FUNCTION mpfr_mul_2ui& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  140.     FUNCTION mpfr_mul_2si& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _OFFSET, BYVAL rndm AS LONG)
  141.     FUNCTION mpfr_div_2ui& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  142.     FUNCTION mpfr_div_2si& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _OFFSET, BYVAL rndm AS LONG)
  143.     FUNCTION mpfr_cmp& (op1 AS mpfr_struct, op2 AS mpfr_struct)
  144.     FUNCTION mpfr_cmp_ui& (op1 AS mpfr_struct, BYVAL op2 AS _UNSIGNED _OFFSET)
  145.     FUNCTION mpfr_cmp_si& (op1 AS mpfr_struct, BYVAL op2 AS _OFFSET)
  146.     FUNCTION mpfr_cmp_d& (op1 AS mpfr_struct, BYVAL op2 AS DOUBLE)
  147.     FUNCTION mpfr_cmp_ld& (op1 AS mpfr_struct, BYVAL p2 AS _FLOAT)
  148.     FUNCTION mpfr_cmp_z& (op1 AS mpfr_struct, op2 AS mpz_struct)
  149.     FUNCTION mpfr_cmp_q& (op1 AS mpfr_struct, op2 AS mpq_struct)
  150.     FUNCTION mpfr_cmp_f& (op1 AS mpfr_struct, op2 AS mpf_struct)
  151.     FUNCTION mpfr_cmp_ui_2exp& (op1 AS mpfr_struct, BYVAL op2 AS _UNSIGNED _OFFSET, BYVAL e AS _OFFSET)
  152.     FUNCTION mpfr_cmp_si_2exp& (op1 AS mpfr_struct, BYVAL op2 AS _OFFSET, BYVAL e AS _OFFSET)
  153.     FUNCTION mpfr_cmpabs& (op1 AS mpfr_struct, op2 AS mpfr_struct)
  154.     FUNCTION mpfr_nan_p& (op AS mpfr_struct)
  155.     FUNCTION mpfr_inf_p& (op AS mpfr_struct)
  156.     FUNCTION mpfr_number_p& (op AS mpfr_struct)
  157.     FUNCTION mpfr_zero_p& (op AS mpfr_struct)
  158.     FUNCTION mpfr_regular_p& (op AS mpfr_struct)
  159.     FUNCTION mpfr_greater_p& (op1 AS mpfr_struct, op2 AS mpfr_struct)
  160.     FUNCTION mpfr_greaterequal_p& (op1 AS mpfr_struct, op2 AS mpfr_struct)
  161.     FUNCTION mpfr_less_p& (op1 AS mpfr_struct, op2 AS mpfr_struct)
  162.     FUNCTION mpfr_lessequal_p& (op1 AS mpfr_struct, op2 AS mpfr_struct)
  163.     FUNCTION mpfr_equal_p& (op1 AS mpfr_struct, op2 AS mpfr_struct)
  164.     FUNCTION mpfr_lessgreater_p& (op1 AS mpfr_struct, op2 AS mpfr_struct)
  165.     FUNCTION mpfr_unordered_p& (op1 AS mpfr_struct, op2 AS mpfr_struct)
  166.     FUNCTION mpfr_log& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  167.     FUNCTION mpfr_log_ui& (rop AS mpfr_struct, BYVAL op AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  168.     FUNCTION mpfr_log2& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  169.     FUNCTION mpfr_log10& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  170.     FUNCTION mpfr_log1p& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  171.     FUNCTION mpfr_exp& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  172.     FUNCTION mpfr_exp2& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  173.     FUNCTION mpfr_exp10& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  174.     FUNCTION mpfr_expm1& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  175.     FUNCTION mpfr_cos& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  176.     FUNCTION mpfr_sin& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  177.     FUNCTION mpfr_tan& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  178.     FUNCTION mpfr_sin_cos& (sop AS mpfr_struct, cop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  179.     FUNCTION mpfr_sec& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  180.     FUNCTION mpfr_csc& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  181.     FUNCTION mpfr_cot& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  182.     FUNCTION mpfr_acos& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  183.     FUNCTION mpfr_asin& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  184.     FUNCTION mpfr_atan& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  185.     FUNCTION mpfr_atan2& (rop AS mpfr_struct, y AS mpfr_struct, x AS mpfr_struct, BYVAL rndm AS LONG)
  186.     FUNCTION mpfr_cosh& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  187.     FUNCTION mpfr_sinh& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  188.     FUNCTION mpfr_tanh& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  189.     FUNCTION mpfr_sinh_cosh& (sop AS mpfr_struct, cop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  190.     FUNCTION mpfr_sech& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  191.     FUNCTION mpfr_csch& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  192.     FUNCTION mpfr_coth& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  193.     FUNCTION mpfr_acosh& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  194.     FUNCTION mpfr_asinh& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  195.     FUNCTION mpfr_atanh& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  196.     FUNCTION mpfr_fac_ui& (rop AS mpfr_struct, BYVAL op AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  197.     FUNCTION mpfr_eint& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  198.     FUNCTION mpfr_li2& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  199.     FUNCTION mpfr_gamma& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  200.     FUNCTION mpfr_gamma_inc& (rop AS mpfr_struct, op AS mpfr_struct, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  201.     FUNCTION mpfr_lngamma& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  202.     FUNCTION mpfr_lgamma& (rop AS mpfr_struct, signp AS LONG, op AS mpfr_struct, BYVAL rndm AS LONG)
  203.     FUNCTION mpfr_digamma& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  204.     FUNCTION mpfr_beta& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  205.     FUNCTION mpfr_zeta& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  206.     FUNCTION mpfr_zeta_ui& (rop AS mpfr_struct, BYVAL op AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  207.     FUNCTION mpfr_erf& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  208.     FUNCTION mpfr_erfc& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  209.     FUNCTION mpfr_j0& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  210.     FUNCTION mpfr_j1& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  211.     FUNCTION mpfr_jn& (rop AS mpfr_struct, BYVAL n AS _OFFSET, op AS mpfr_struct, BYVAL rndm AS LONG)
  212.     FUNCTION mpfr_y0& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  213.     FUNCTION mpfr_y1& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  214.     FUNCTION mpfr_yn& (rop AS mpfr_struct, BYVAL n AS _OFFSET, op AS mpfr_struct, BYVAL rndm AS LONG)
  215.     FUNCTION mpfr_fma& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, op3 AS mpfr_struct, BYVAL rndm AS LONG)
  216.     FUNCTION mpfr_fms& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, op3 AS mpfr_struct, BYVAL rndm AS LONG)
  217.     FUNCTION mpfr_fmma& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, op3 AS mpfr_struct, op4 AS mpfr_struct, BYVAL rndm AS LONG)
  218.     FUNCTION mpfr_fmms& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, op3 AS mpfr_struct, op4 AS mpfr_struct, BYVAL rndm AS LONG)
  219.     FUNCTION mpfr_agm& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  220.     FUNCTION mpfr_hypot& (rop AS mpfr_struct, x AS mpfr_struct, y AS mpfr_struct, BYVAL rndm AS LONG)
  221.     FUNCTION mpfr_ai& (rop AS mpfr_struct, x AS mpfr_struct, BYVAL rndm AS LONG)
  222.     FUNCTION mpfr_const_log2& (rop AS mpfr_struct, BYVAL rndm AS LONG)
  223.     FUNCTION mpfr_const_pi& (rop AS mpfr_struct, BYVAL rndm AS LONG)
  224.     FUNCTION mpfr_const_euler& (rop AS mpfr_struct, BYVAL rndm AS LONG)
  225.     FUNCTION mpfr_const_catalan& (rop AS mpfr_struct, BYVAL rndm AS LONG)
  226.     SUB mpfr_free_cache
  227.     'Sub mpfr_free_cache2 (mpfr_free_cache_t way)
  228.     SUB mpfr_free_pool
  229.     FUNCTION mpfr_mp_memory_cleanup&
  230.     ''Function mpfr_sum& (rop AS mpfr_struct, const mpfr_ptr tab[], byval n as _unsigned _offset, Byval rndm as long )
  231.     ''Function mpfr_out_str%&(stream as _offset, byval base as long, byval n as _offset, op AS mpfr_struct, Byval rndm as long )
  232.     ''Function mpfr_inp_str%&(rop AS mpfr_struct, stream as _offset, byval base as long, Byval rndm as long )
  233.     ''Function mpfr_fpif_export& (stream as _offset, op AS mpfr_struct )
  234.     ''Function mpfr_fpif_import& (op AS mpfr_struct, stream as _offset )
  235.     SUB mpfr_dump (op AS mpfr_struct)
  236.     ''Function mpfr_fprintf& (FILE *stream, const char *template, … )
  237.     ''Function mpfr_vfprintf& (FILE *stream, const char *template, va_list ap )
  238.     ''Function mpfr_printf& (const char *template, … )
  239.     ''Function mpfr_vprintf& (const char *template, va_list ap )
  240.     ''Function mpfr_sprintf& (char *buf, const char *template, … )
  241.     ''Function mpfr_vsprintf& (char *buf, const char *template, va_list ap )
  242.     ''Function mpfr_snprintf& (char *buf, size_t n, const char *template, … )
  243.     ''Function mpfr_vsnprintf& (char *buf, size_t n, const char *template, va_list ap )
  244.     ''Function mpfr_asprintf& (char **str, const char *template, … )
  245.     ''Function mpfr_vasprintf& (char **str, const char *template, va_list ap )
  246.     FUNCTION mpfr_rint& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  247.     FUNCTION mpfr_ceil& (rop AS mpfr_struct, op AS mpfr_struct)
  248.     FUNCTION mpfr_floor& (rop AS mpfr_struct, op AS mpfr_struct)
  249.     FUNCTION mpfr_round& (rop AS mpfr_struct, op AS mpfr_struct)
  250.     FUNCTION mpfr_roundeven& (rop AS mpfr_struct, op AS mpfr_struct)
  251.     FUNCTION mpfr_trunc& (rop AS mpfr_struct, op AS mpfr_struct)
  252.     FUNCTION mpfr_rint_ceil& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  253.     FUNCTION mpfr_rint_floor& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  254.     FUNCTION mpfr_rint_round& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  255.     FUNCTION mpfr_rint_roundeven& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  256.     FUNCTION mpfr_rint_trunc& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  257.     FUNCTION mpfr_frac& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  258.     FUNCTION mpfr_modf& (iop AS mpfr_struct, fop AS mpfr_struct, op AS mpfr_struct, BYVAL rndm AS LONG)
  259.     FUNCTION mpfr_fmod& (r AS mpfr_struct, x AS mpfr_struct, y AS mpfr_struct, BYVAL rndm AS LONG)
  260.     FUNCTION mpfr_fmodquo& (r AS mpfr_struct, q AS _OFFSET, x AS mpfr_struct, y AS mpfr_struct, BYVAL rndm AS LONG)
  261.     FUNCTION mpfr_remainder& (r AS mpfr_struct, x AS mpfr_struct, y AS mpfr_struct, BYVAL rndm AS LONG)
  262.     FUNCTION mpfr_remquo& (r AS mpfr_struct, q AS _OFFSET, x AS mpfr_struct, y AS mpfr_struct, BYVAL rndm AS LONG)
  263.     FUNCTION mpfr_integer_p& (op AS mpfr_struct)
  264.     SUB mpfr_set_default_rounding_mode (BYVAL rndm AS LONG)
  265.     FUNCTION mpfr_get_default_rounding_mode&
  266.     FUNCTION mpfr_prec_round& (x AS mpfr_struct, BYVAL prec AS _OFFSET, BYVAL rndm AS LONG)
  267.     FUNCTION mpfr_can_round& (b AS mpfr_struct, BYVAL err1 AS _OFFSET, BYVAL rndm1 AS LONG, BYVAL rndm2 AS LONG, BYVAL prec AS _OFFSET)
  268.     FUNCTION mpfr_min_prec%& (x AS mpfr_struct)
  269.     FUNCTION mpfr_print_rnd_mode$ (BYVAL rndm AS LONG)
  270.     SUB mpfr_nexttoward (x AS mpfr_struct, y AS mpfr_struct)
  271.     SUB mpfr_nextabove (x AS mpfr_struct)
  272.     SUB mpfr_nextbelow (x AS mpfr_struct)
  273.     FUNCTION mpfr_min& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  274.     FUNCTION mpfr_max& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  275.     ''Function mpfr_urandomb& (rop AS mpfr_struct, state as gmp_randstate_struct )
  276.     ''Function mpfr_urandom& (rop AS mpfr_struct, state as gmp_randstate_struct, Byval rndm as long )
  277.     ''Function mpfr_nrandom& (rop AS mpfr_struct1, state as gmp_randstate_struct, Byval rndm as long )
  278.     ''Function mpfr_grandom& (rop AS mpfr_struct1, rop2 AS mpfr_struct, state as gmp_randstate_struct, Byval rndm as long )
  279.     ''Function mpfr_erandom& (rop AS mpfr_struct1, state as gmp_randstate_struct, Byval rndm as long )
  280.     FUNCTION mpfr_get_exp%& (x AS mpfr_struct)
  281.     FUNCTION mpfr_set_exp& (x AS mpfr_struct, BYVAL e AS _OFFSET)
  282.     FUNCTION mpfr_signbit& (op AS mpfr_struct)
  283.     FUNCTION mpfr_setsign& (rop AS mpfr_struct, op AS mpfr_struct, BYVAL s AS LONG, BYVAL rndm AS LONG)
  284.     FUNCTION mpfr_copysign& (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  285.     FUNCTION mpfr_get_version$
  286.     FUNCTION mpfr_get_patches$
  287.     FUNCTION mpfr_buildopt_tls_p&
  288.     FUNCTION mpfr_buildopt_float128_p&
  289.     FUNCTION mpfr_buildopt_decimal_p&
  290.     FUNCTION mpfr_buildopt_gmpinternals_p&
  291.     FUNCTION mpfr_buildopt_sharedcache_p&
  292.     FUNCTION mpfr_buildopt_tune_case$
  293.     FUNCTION mpfr_get_emin%&
  294.     FUNCTION mpfr_get_emax%&
  295.     FUNCTION mpfr_set_emin& (BYVAL exp1 AS _OFFSET)
  296.     FUNCTION mpfr_set_emax& (BYVAL exp1 AS _OFFSET)
  297.     FUNCTION mpfr_get_emin_min%&
  298.     FUNCTION mpfr_get_emin_max%&
  299.     FUNCTION mpfr_get_emax_min%&
  300.     FUNCTION mpfr_get_emax_max%&
  301.     FUNCTION mpfr_check_range& (x AS mpfr_struct, BYVAL t AS LONG, BYVAL rndm AS LONG)
  302.     FUNCTION mpfr_subnormalize& (x AS mpfr_struct, BYVAL t AS LONG, BYVAL rndm AS LONG)
  303.     SUB mpfr_clear_underflow
  304.     SUB mpfr_clear_overflow
  305.     SUB mpfr_clear_divby0
  306.     SUB mpfr_clear_nanflag
  307.     SUB mpfr_clear_inexflag
  308.     SUB mpfr_clear_erangeflag
  309.     SUB mpfr_clear_flags
  310.     SUB mpfr_set_underflow
  311.     SUB mpfr_set_overflow
  312.     SUB mpfr_set_divby0
  313.     SUB mpfr_set_nanflag
  314.     SUB mpfr_set_inexflag
  315.     SUB mpfr_set_erangeflag
  316.     FUNCTION mpfr_underflow_p&
  317.     FUNCTION mpfr_overflow_p&
  318.     FUNCTION mpfr_divby0_p&
  319.     FUNCTION mpfr_nanflag_p&
  320.     FUNCTION mpfr_inexflag_p&
  321.     FUNCTION mpfr_erangeflag_p&
  322.     SUB mpfr_flags_clear (BYVAL mask AS LONG)
  323.     SUB mpfr_flags_set (BYVAL mask AS LONG)
  324.     FUNCTION mpfr_flags_test& (BYVAL mask AS LONG)
  325.     FUNCTION mpfr_flags_save&
  326.     SUB mpfr_flags_restore (BYVAL flags AS LONG, BYVAL mask AS LONG)
  327.     SUB mpfr_set_prec_raw (x AS mpfr_struct, BYVAL prec AS _OFFSET)
  328.     FUNCTION mpfr_eq& (op1 AS mpfr_struct, op2 AS mpfr_struct, BYVAL op3 AS _UNSIGNED _OFFSET)
  329.     SUB mpfr_reldiff (rop AS mpfr_struct, op1 AS mpfr_struct, op2 AS mpfr_struct, BYVAL rndm AS LONG)
  330.     FUNCTION mpfr_mul_2exp& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  331.     FUNCTION mpfr_div_2exp& (rop AS mpfr_struct, op1 AS mpfr_struct, BYVAL op2 AS _UNSIGNED _OFFSET, BYVAL rndm AS LONG)
  332.     FUNCTION mpfr_custom_get_size%& (BYVAL prec AS _OFFSET)
  333.     SUB mpfr_custom_init (significand AS _OFFSET, BYVAL prec AS _OFFSET)
  334.     SUB mpfr_custom_init_set (x AS mpfr_struct, BYVAL kind AS LONG, BYVAL exp1 AS _OFFSET, BYVAL prec AS _OFFSET, significand AS _OFFSET)
  335.     FUNCTION mpfr_custom_get_kind& (x AS mpfr_struct)
  336.     FUNCTION mpfr_custom_get_significand%& (x AS mpfr_struct)
  337.     FUNCTION mpfr_custom_get_exp%& (x AS mpfr_struct)
  338.     SUB mpfr_custom_move (x AS mpfr_struct, new_position AS _OFFSET)
  339.     FUNCTION mpfr_snprintf& (rop AS STRING, BYVAL n AS _UNSIGNED _OFFSET, frmt AS STRING, src2 AS mpfr_struct)
  340.  
  341. SUB print_mpfr_g (f AS mpfr_struct, n AS LONG, m AS LONG)
  342.     DIM sresult(0) AS STRING, frmt AS STRING
  343.     DIM ln AS LONG
  344.     frmt = "%" + LTRIM$(STR$(n)) + "." + LTRIM$(STR$(m)) + "RNg"
  345.     ln = mpfr_snprintf&("", 0, frmt, f)
  346.     IF ln > 0 THEN
  347.         sresult(0) = SPACE$(ln)
  348.         ln = mpfr_snprintf&(sresult(0), ln + 4, frmt, f)
  349.     END IF
  350.     PRINT LEFT$(sresult(0), ln)
  351.  
  352. SUB print_mpfr_f (f AS mpfr_struct, n AS LONG, m AS LONG)
  353.     DIM sresult(0) AS STRING, frmt AS STRING
  354.     DIM ln AS LONG
  355.     frmt = "%" + LTRIM$(STR$(n)) + "." + LTRIM$(STR$(m)) + "RNf"
  356.     ln = mpfr_snprintf&("", 0, frmt, f)
  357.     IF ln > 0 THEN
  358.         sresult(0) = SPACE$(ln)
  359.         ln = mpfr_snprintf&(sresult(0), ln + 4, frmt, f)
  360.     END IF
  361.     PRINT LEFT$(sresult(0), ln)
  362.  
  363. SUB print_mpfr_e (f AS mpfr_struct, n AS LONG, m AS LONG)
  364.     DIM sresult(0) AS STRING, frmt AS STRING
  365.     DIM ln AS LONG
  366.     frmt = "%" + LTRIM$(STR$(n)) + "." + LTRIM$(STR$(m)) + "RNe"
  367.     ln = mpfr_snprintf&("", 0, frmt, f)
  368.     IF ln > 0 THEN
  369.         sresult(0) = SPACE$(ln)
  370.         ln = mpfr_snprintf&(sresult(0), ln + 4, frmt, f)
  371.     END IF
  372.     PRINT LEFT$(sresult(0), ln)
  373.  
  374. SUB valmpfr (result AS mpfr_struct, value AS STRING, nbase AS LONG)
  375.     DIM c AS LONG
  376.     c = mpfr_set_str(result, value, nbase, MPFR_RNDN)
  377.  
« Last Edit: April 01, 2019, 03:48:00 am by jack »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: mpfr
« Reply #9 on: April 01, 2019, 09:20:09 am »
I can confirm that removing "lib" makes DECLARE LIBRARY work on linux.  Thanks, Jack

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: mpfr
« Reply #10 on: April 01, 2019, 10:06:37 am »
@_vince
I am looking forward to your fractal program :)

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: mpfr
« Reply #11 on: February 03, 2022, 08:13:39 am »
updated first post and also attached the 64-bit mpfr dll
the dll can be in the same place where your program resides or you could put the dll in system32 although some people cringe at the thought of putting third party dll's in system32 so it's up to you where you put it
just in case you didn't know, in Windows x64, system32 is where 64-bit applications/dll's reside and  SysWOW64 is where 32-bit applications/dll's reside

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: mpfr
« Reply #12 on: March 01, 2022, 04:29:52 pm »
the first and last 20 digits of Fibonacci ( 18446744073709551616 ) https://rosettacode.org/wiki/Fibonacci_matrix-exponentiation#Fibmod_method in 0 seconds
get the mpfr dll from opening post
Code: QB64: [Select]
  1. 'translated the fib code from https://www.uni-math.gwdg.de/tschinkel/gauss/Fibon.pdf page 14
  2. '------------------------------------------------------------------'/
  3. '
  4. '** Schnelle Berechnung der Fibonacci-Zahlen mittels der Formeln
  5. '** fib(2*k-1) = fib(k)**2 + fib(k-1)**2
  6. '** fib(2*k) = fib(k)**2 + 2*fib(k)*fib(k-1)
  7. '**
  8. '** Dabei werden alle Berechnungen mod m durchgef¨uhrt
  9. '
  10.  
  11. Const MPFR_RNDN = 0
  12. Const MPFR_RNDZ = 1
  13.  
  14. Type mpz_struct
  15.     mp_alloc As Long
  16.     mp_size As Long
  17.     mp_d As _Offset
  18.  
  19. Type mpfr_struct
  20.     mpfr_prec As _Offset
  21.     mpfr_sign As Long
  22.     mpfr_exp As _Offset
  23.     mpfr_d As _Offset
  24.  
  25. Declare Dynamic Library "libmpfr-6"
  26.     Sub mpfr_init2 (rop As mpfr_struct, Byval op1 As Long)
  27.     Sub mpfr_clear (rop As mpfr_struct)
  28.     Sub mpfr_set_z (rop As mpfr_struct, opz As mpz_struct, Byval mpfr_rnd As Long)
  29.     Sub mpfr_set_ui (rop As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  30.     Sub mpfr_ui_pow_ui (rop As mpfr_struct, Byval culong As _Unsigned Long, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  31.     Sub mpfr_sqrt_ui (rop As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  32.     Sub mpfr_add_ui (rop As mpfr_struct, op1 As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  33.     Sub mpfr_div_ui (rop As mpfr_struct, op1 As mpfr_struct, Byval culong As _Unsigned Long, Byval mpfr_rnd As Long)
  34.     Sub mpfr_log10 (rop As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  35.     Sub mpfr_log2 (rop As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  36.     Sub mpfr_exp10 (rop As mpfr_struct, op1 As mpfr_struct, Byval mpfr_rnd As Long)
  37.     Sub mpfr_trunc (rop As mpfr_struct, op As mpfr_struct)
  38.     Sub mpfr_sub (rop As mpfr_struct, op1 As mpfr_struct, op2 As mpfr_struct, Byval mpfr_rnd As Long)
  39.     Sub mpfr_mul (rop As mpfr_struct, op1 As mpfr_struct, op2 As mpfr_struct, Byval mpfr_rnd As Long)
  40.     Sub mpfr_frac (rop As mpfr_struct, op As mpfr_struct, Byval mpfr_rnd As Long)
  41.     Function mpfr_snprintf& (rop As String, Byval n As _Unsigned _Offset, frmt As String, src2 As mpfr_struct)
  42.     Function mpfr_get_ui& (mpfr_srcptr As mpfr_struct, Byval mpfr_rnd As Long)
  43.     Sub mpfr_get_z (z As mpz_struct, f As mpfr_struct, Byval mpfr_rnd As Long)
  44.  
  45. Declare Dynamic Library "libgmp-10"
  46.     Sub __gmpz_init (result As mpz_struct)
  47.     Sub __gmpz_init_set_ui (rop As mpz_struct, Byval op As _Unsigned Long)
  48.     Sub __gmpz_set (rop As mpz_struct, op As mpz_struct)
  49.     Function __gmpz_cmp_ui& (mpz_srcptr As mpz_struct, Byval ui As _Unsigned Long)
  50.     Sub __gmpz_mul (result As mpz_struct, src1 As mpz_struct, src2 As mpz_struct)
  51.     Sub __gmpz_mod (mpz_ptr As mpz_struct, mpz_srcptr As mpz_struct, mpz_srcptr2 As mpz_struct)
  52.     Sub __gmpz_mul_ui (result As mpz_struct, src As mpz_struct, Byval ui As _Unsigned Long)
  53.     Sub __gmpz_add (result As mpz_struct, src1 As mpz_struct, src2 As mpz_struct)
  54.     Function __gmpz_tstbit& (mpz_srcptr As mpz_struct, Byval ui As _Unsigned Long)
  55.     Sub __gmpz_clear (result As mpz_struct)
  56.     Sub __gmpz_set_ui (mpz_ptr As mpz_struct, Byval ui As _Unsigned Long)
  57.     Sub __gmpz_ui_pow_ui (mpz_ptr As mpz_struct, Byval ui1 As _Unsigned Long, Byval ui2 As _Unsigned Long)
  58.     Function __gmp_snprintf& (rop As String, Byval n As _Unsigned _Integer64, frmt As String, src2 As mpz_struct)
  59.  
  60. 'the first digits are approximated by
  61. '10^Frac((log10((1+sqrt(5))/2)*n)-log10(sqrt(5)))
  62. 'the number of digits in the Fibonacci number
  63. 'is Trunc((log10((1+sqrt(5))/2)*n)-log10(sqrt(5)))+1
  64. Dim As Long c, length, fnp, number
  65. length = 21
  66. fnp = 64
  67. number = 10000000 '4784969
  68. t = Timer
  69. Dim As mpfr_struct first, five, tmp, nf
  70. Dim As mpz_struct flast, n, m
  71.  
  72. __gmpz_init flast
  73. __gmpz_init n
  74. __gmpz_init m
  75. __gmpz_ui_pow_ui n, 2, fnp
  76.  
  77. mpfr_init2 first, 256 + fnp
  78. mpfr_init2 five, 256 + fnp
  79. mpfr_init2 tmp, 256 + fnp
  80. mpfr_init2 nf, 256 + fnp
  81.  
  82. mpfr_ui_pow_ui nf, 2, fnp, MPFR_RNDN
  83. 'mpfr_set_si(nf, number, MPFR_RNDN)
  84. mpfr_sqrt_ui five, 5, MPFR_RNDN
  85. mpfr_add_ui tmp, five, 1, MPFR_RNDN
  86. mpfr_div_ui first, tmp, 2, MPFR_RNDN
  87. mpfr_log10 tmp, first, MPFR_RNDN
  88. mpfr_mul first, tmp, nf, MPFR_RNDN
  89. mpfr_log10 tmp, five, MPFR_RNDN
  90. mpfr_sub nf, first, tmp, MPFR_RNDN
  91. mpfr_frac tmp, nf, MPFR_RNDN
  92. mpfr_exp10 first, tmp, MPFR_RNDN
  93. mpfr_trunc tmp, nf
  94. mpfr_add_ui tmp, tmp, 1, MPFR_RNDN
  95. Print "fibonacci "; gmpz$(n)
  96. s = print_mpfr_f$(first, length + 4, length - 2)
  97.  
  98. c = InStr(s, ".")
  99. s = Left$(s, c - 1) + Mid$(s, c + 1)
  100. c = mpfr_get_ui(tmp, MPFR_RNDN)
  101. If c > 0 And c < length Then
  102.     Print "the first"; c; " digits are";
  103.     Print Left$(s, c)
  104.     Print "the first"; length - 1; " digits are ";
  105.     Print s
  106.  
  107. mpfr_clear nf
  108. mpfr_clear five
  109. mpfr_clear first
  110.  
  111. '__gmpz_set_si(n, number)
  112. __gmpz_ui_pow_ui m, 10, length
  113. fib flast, n, m
  114. t = Timer - t
  115. If c > 0 And c < length Then
  116.     Print "the last"; c; " digits are ";
  117.     Print "the last"; length - 1; " digits are ";
  118. Print gmpz$(flast)
  119. mpfr_get_z n, tmp, MPFR_RNDN
  120. Print "the Fibonacci number has ";
  121. Print gmpz$(n);
  122. Print " digits"
  123. __gmpz_clear m
  124. __gmpz_clear n
  125. __gmpz_clear flast
  126. mpfr_clear tmp
  127. Print "elapsed time "; t; " seconds"
  128.  
  129. Function print_mpfr_f$ (f As mpfr_struct, n As Long, m As Long)
  130.     Dim sresult(0) As String, frmt As String
  131.     Erase sresult
  132.     Dim sresult(0) As String
  133.     Dim ln As Long
  134.     frmt = "%" + LTrim$(Str$(n)) + "." + LTrim$(Str$(m)) + "RZf" + Chr$(0)
  135.     ln = mpfr_snprintf&("" + Chr$(0), 0, frmt, f)
  136.     If ln > 0 Then
  137.         sresult(0) = Space$(ln) + Chr$(0)
  138.         ln = mpfr_snprintf&(sresult(0), ln + 4, frmt, f)
  139.     End If
  140.     print_mpfr_f$ = Left$(sresult(0), ln)
  141.  
  142. Function gmpz$ (n As mpz_struct)
  143.     Dim sresult As String
  144.     sresult = ""
  145.     ln = __gmp_snprintf&("" + Chr$(0), 0, "%Zd" + Chr$(0), n)
  146.     If ln > 0 Then
  147.         sresult = Space$(ln + 5)
  148.         ln = __gmp_snprintf&(sresult, ln + 4, "%Zd" + Chr$(0), n)
  149.     End If
  150.     gmpz$ = sresult
  151.  
  152. Sub fib (x As mpz_struct, k As mpz_struct, m As mpz_struct)
  153.     Dim As mpz_struct b, y, xx, tmp, temp
  154.     Dim As mpfr_struct lngth
  155.     Dim As Long i, bit_length
  156.     mpfr_init2 lngth, 1024
  157.     __gmpz_init b
  158.     __gmpz_init y
  159.     __gmpz_init xx
  160.     __gmpz_init tmp
  161.     __gmpz_init temp
  162.  
  163.     If __gmpz_cmp_ui(k, c) <= 0 Then
  164.         __gmpz_set x, k
  165.         mpfr_clear lngth
  166.         __gmpz_clear temp
  167.         __gmpz_clear tmp
  168.         __gmpz_clear xx
  169.         __gmpz_clear y
  170.         __gmpz_clear b
  171.         Exit Sub
  172.     End If
  173.     mpfr_set_z lngth, k, MPFR_RNDN
  174.     mpfr_log2 lngth, lngth, MPFR_RNDN
  175.     mpfr_trunc lngth, lngth
  176.     bit_length = mpfr_get_ui(lngth, MPFR_RNDN) 'Fix(Log(__gmpz_get_d(k))/Log(2))
  177.     __gmpz_set_ui x, 1
  178.     __gmpz_set_ui y, 0
  179.     For i = bit_length - 1 To 0 Step -1
  180.         __gmpz_mul temp, x, x
  181.         __gmpz_mod xx, temp, m
  182.         __gmpz_mul temp, x, y
  183.         __gmpz_mul_ui tmp, temp, 2
  184.         __gmpz_add temp, xx, tmp
  185.         __gmpz_mod x, temp, m
  186.         'x := (xx + 2*x*y) mod m;
  187.         __gmpz_mul tmp, y, y
  188.         __gmpz_add temp, xx, tmp
  189.         __gmpz_mod y, temp, m
  190.         'y := (xx + y*y) mod m;
  191.         If __gmpz_tstbit(k, i) Then
  192.             __gmpz_set temp, x
  193.             __gmpz_add tmp, x, y
  194.             __gmpz_mod x, tmp, m
  195.             'x := (x + y) mod m;
  196.             __gmpz_set y, temp
  197.         End If
  198.     Next
  199.     mpfr_clear lngth
  200.     __gmpz_clear temp
  201.     __gmpz_clear tmp
  202.     __gmpz_clear xx
  203.     __gmpz_clear y
  204.     __gmpz_clear b
  205.  
* gmp.zip (Filesize: 541.62 KB, Downloads: 192)
« Last Edit: March 02, 2022, 07:36:52 am by jack »