Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - jack

Pages: [1] 2 3 ... 28
1
Programs / Re: Better Bench by Ed Davis
« on: April 11, 2022, 08:30:11 pm »
in Linux x64 same PC I get
3.79 seconds with no optimization
3.58 seconds with -O2 optimization
3.06 seconds with -Ofast optimization

2
Programs / Re: Better Bench by Ed Davis
« on: April 11, 2022, 05:19:07 pm »
Hi bplus and Ed Davis
here's my result
Code: [Select]
QB64
 200574   60372774            120544974           180717174           240889374
 301061574          309886830
 4.637000000002445  seconds

FreeBasic
 200574        60372774      120544974     180717174     240889374     301061574     309886830
 2.118056500097737 seconds
well done bplus :)
note: QB64 includes a lot of runtime checks which slowdown performance, even with $Checking:Off

3
Programs / Re: Benchmark_01
« on: April 10, 2022, 02:51:32 pm »
I meant no offense to you bplus, I know who came up with the code
but if you want to do a benchmark you need to do some computations that can't be optimized out and print the result for verification

4
Programs / Re: Benchmark_01
« on: April 10, 2022, 02:31:04 pm »
it times at .25 seconds on my PC
but as a benchmark it's lame, a good compiler will eliminate the loop entirely and therefore give a meaningless result

5
QB64 Discussion / Re: Puzzling double precision rounding inaccuracy
« on: April 10, 2022, 06:32:33 am »
hello paravantis
you may know or have seen discussions about the approximate nature of binary floating-point, unless the fractional part of a decimal number is a power of 2 (or a sum thereof) it will only be approximately represented in the binary form
storing a rounded number to a certain number of decimal places in a variable may not be exact, for displaying numbers I would use print using as in your last example

6
Cobalt, the problem is that for some values the printed result is off by a factor of 10, it's not just a minor flaw
to fix the qbs *qbs_str(double value) is complicated by the fact that QB64 want to match the output of qb45 and the code is rather complex due to that
I mentioned this before that _Floats are converted to double then passed to qbs_str(double value)
Code: [Select]
qbs *qbs_str(long double value){
    //not fully implemented
    return qbs_str((double)value);
}
I propose a simple alternative
Code: [Select]
qbs *qbs_str(long double value){
    //not fully implemented
    static qbs *tqbs;
    static int32 l, i;
    static char c;
    tqbs=qbs_new(32,1);
    l=__mingw_sprintf((char*)&qbs_str_buffer,"% .18Lg",value);
for (i=0;i<l;i++) {
c=qbs_str_buffer[i];
if(c==101) c=70;
tqbs->chr[i]=c;}
tqbs->chr[l]=0;
    return tqbs;
}

example
Code: QB64: [Select]
  1.  
  2. d = 1D17
  3. f = 1F17
  4.  
  5. For i = 17 To 40
  6.     d = d * 10#
  7.     f = f * 10##
  8.     Print "Double "; d
  9.     Print "_Float "; f
  10.     Print "------------"
  11.  

output
Code: [Select]
Double  1D+18
_Float  1F+18
------------
Double  1D+19
_Float  1F+19
------------
Double  1D+20
_Float  1F+20
------------
Double  1D+21
_Float  1F+21
------------
Double  1D+22
_Float  1F+22
------------
Double  1D+22
_Float  1F+23
------------
Double  1D+24
_Float  1F+24
------------
Double  1D+24
_Float  1F+25
------------
Double  1D+25
_Float  1F+26
------------
Double  1D+26
_Float  1F+27
------------
Double  1D+28
_Float  1F+28
------------
Double  1D+28
_Float  1F+29
------------
Double  1D+29
_Float  1F+30
------------
Double  1D+30
_Float  1F+31
------------
Double  1D+31
_Float  1F+32
------------
Double  1D+32
_Float  1F+33
------------
Double  1D+33
_Float  1F+34
------------
Double  1D+35
_Float  1F+35
------------
Double  1D+35
_Float  1F+36
------------
Double  9.999999999999998D+36
_Float  1F+37
------------
Double  9.999999999999998D+37
_Float  1F+38
------------
Double  9.999999999999998D+38
_Float  1F+39
------------
Double  9.999999999999998D+39
_Float  1F+40
------------
Double  9.999999999999998D+40
_Float  1F+41
------------

7
another example
Code: QB64: [Select]
  1.     Function snprintf& (Dest As String, Byval l As Long, frmt As String, Byval x As Double)
  2.  
  3. Screen _NewImage(768, 768, 32)
  4.  
  5. Locate 3, 1:
  6.  
  7. Color &HFF00FFFF~&&
  8. Locate , 1: Print " i";
  9. Locate , 10: Print "QB64 Print";
  10. Locate , 22: Print "printf";
  11. Color &HFFFF8000~&&
  12. Color &HFFFFFFFF~&&
  13. For i = 16 To 50
  14.     c = Val("." + String$(i, 48) + "1")
  15.     Locate , 1: Print i;: Locate , 10: Print c;: Locate , 20: Print strf(c)
  16.  
  17. Function strf$ (x As Double)
  18.     Dim As String s
  19.     Dim As String frmt
  20.     Dim As Long l, ex, sign
  21.     sign = Sgn(x)
  22.     If sign < 0 Then x = -x
  23.     s = Spc(64)
  24.     frmt = "%.15g" + Chr$(0)
  25.     l = snprintf(s, Len(s), frmt, x)
  26.     s = _Trim$(s)
  27.     If InStr(s, ".") > 0 And Left$(s, 1) = "0" Then s = Mid$(s, 2)
  28.     If sign < 0 Then s = "-" + s Else s = " " + s
  29.     ex = InStr(s, "e")
  30.     If ex > 0 Then Mid$(s, ex, 1) = "D"
  31.     strf = s
  32.  
the qbs_str function in libqb.cpp which is called by the print statement is a bit complex, at least for the non-C-expert, it could be simplified a lot if you want give up certain formatting rules imposed by trying to match the output of QB45

8
hello Dr. Edwin and bplus
as you noted the QB64 print functions are buggy in some cases, until they get fixed you could use the crt's printf function
let me modify an example, then I'll post
not the best example, but you can modify the code to your needs
Code: QB64: [Select]
  1.     Function snprintf& (Dest As String, Byval l As Long, frmt As String, Byval x As Double)
  2.  
  3. Screen _NewImage(768, 768, 32)
  4.  
  5. Locate 3, 1:
  6.  
  7. Color &HFF00FFFF~&&
  8. Locate , 1: Print "QB64 Print";
  9. Locate , 25: Print "printf";
  10.  
  11. Color &HFFFF8000~&&
  12. Print "c# = ... :": Color &HFFFFFFFF~&&
  13. c# = 10#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  14. c# = 100#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  15. c# = 1000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  16. c# = 10000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  17. c# = 100000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  18. c# = 1000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  19. c# = 10000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  20. c# = 100000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  21. c# = 1000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  22. c# = 10000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  23. c# = 100000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  24. c# = 1000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  25. c# = 10000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  26. c# = 100000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  27. c# = 1000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  28. c# = 10000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  29. c# = 100000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  30. c# = 1000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  31. c# = 10000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  32. c# = 100000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  33. c# = 1000000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  34. c# = 10000000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  35. c# = 100000000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  36. c# = 1000000000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  37. c# = 10000000000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  38. c# = 100000000000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  39. c# = 1000000000000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  40. c# = 10000000000000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  41. c# = 100000000000000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  42. c# = 1000000000000000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  43. c# = 10000000000000000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  44. c# = 100000000000000000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  45. c# = 1000000000000000000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  46. c# = 10000000000000000000000000000000000#: Locate , 1: Print c#;: Locate , 25: Print strf(c#)
  47.  
  48. Function strf$ (x As Double)
  49.     Dim As String s
  50.     Dim As String frmt
  51.     Dim As Long l, ex, sign
  52.     sign = Sgn(x)
  53.     If sign < 0 Then x = -x
  54.     s = Spc(64)
  55.     frmt = "%.15g" + Chr$(0)
  56.     l = snprintf(s, Len(s), frmt, x)
  57.     s = _Trim$(s)
  58.     If InStr(s, ".") > 0 And Left$(s, 1) = "0" Then s = Mid$(s, 2)
  59.     If sign < 0 Then s = "-" + s Else s = " " + s
  60.     ex = InStr(s, "e")
  61.     If ex > 0 Then Mid$(s, ex, 1) = "D"
  62.     strf = s
  63.  

9
Programs / Re: intel decimal math library
« on: April 05, 2022, 09:55:53 pm »
updated the code and dll, many functions added

10
Programs / libtommath for Win-64
« on: April 05, 2022, 08:37:27 pm »
made a win64 dll of LibTomMath https://www.libtom.net/
Code: QB64: [Select]
  1.  
  2. Const MP_64BIT = 1
  3. Type private_mp_word
  4.     As String * 128 mpword
  5. Const MP_DIGIT_BIT = 60
  6.  
  7. Type mp_int
  8.     used As Long
  9.     alloc As Long
  10.     sign As Long
  11.     dp As _Offset
  12.  
  13. Declare Dynamic Library "libtommath"
  14.     Function mp_init& (a As mp_int) ' as mp_err
  15.     Function mp_init_size& (a As mp_int, Byval size As Long) ' as mp_err
  16.     Function mp_init_i32& (a As mp_int, Byval b As Long) ' as mp_err
  17.     Function mp_init_l& (a As mp_int, Byval b As Long) ' ' as mp_err
  18.     Function mp_init_u32& (a As mp_int, Byval b As _Unsigned Long) ' as mp_err
  19.     Function mp_init_ul& (a As mp_int, Byval b As _Unsigned Long) ' as mp_err
  20.     Function mp_init_i64& (a As mp_int, Byval b As _Integer64) ' as mp_err
  21.     Function mp_init_ll& (a As mp_int, Byval b As _Integer64) ' as mp_err
  22.     Function mp_init_u64& (a As mp_int, Byval b As _Unsigned _Integer64) ' as mp_err
  23.     Function mp_init_ull& (a As mp_int, Byval b As _Unsigned _Integer64) ' as mp_err
  24.     Function mp_init_set& (a As mp_int, Byval b As _Unsigned _Integer64) ' as mp_err
  25.     Function mp_init_set_int& (a As mp_int, Byval b As _Unsigned Long) ' as mp_err
  26.     Function mp_init_copy (a As mp_int, b As mp_int) ' as mp_err
  27.     Sub mp_clear (a As mp_int)
  28.     Sub mp_exch (a As mp_int, b As mp_int)
  29.     Function mp_shrink& (a As mp_int) ' as mp_err
  30.     Function mp_grow& (a As mp_int, Byval size As Long) ' as mp_err
  31.     Function mp_iseven& (a As mp_int) ' as long
  32.     Function mp_isodd& (a As mp_int) ' as long
  33.     Sub mp_zero (a As mp_int)
  34.     Function mp_get_double# (a As mp_int) ' as double
  35.     Function mp_set_double& (a As mp_int, Byval b As Double) ' as mp_err
  36.     Function mp_get_i32& (a As mp_int) ' as long
  37.     Function mp_get_l& (a As mp_int) ' as long
  38.     Function mp_get_int~& (a As mp_int) ' as ulong
  39.     Function mp_get_long~& (a As mp_int) ' as ulong
  40.     Function mp_get_i64&& (a As mp_int) ' as longint
  41.     Function mp_get_ll&& (a As mp_int) ' as longint
  42.     Function mp_get_long_long~&& (a As mp_int) ' as ulongint
  43.     Sub mp_set_i32 (a As mp_int, Byval b As Long)
  44.     Sub mp_set_l (a As mp_int, Byval b As Long)
  45.     Function mp_set_long& (a As mp_int, Byval b As _Unsigned Long) ' as mp_err
  46.     Sub mp_set_u32 (a As mp_int, Byval b As _Unsigned Long)
  47.     Sub mp_set_ul (a As mp_int, Byval b As _Unsigned Long)
  48.     Function mp_set_int& (a As mp_int, Byval b As _Unsigned Long) ' as mp_err
  49.     Sub mp_set_i64 (a As mp_int, Byval b As _Integer64)
  50.     Function mp_set_long_long& (a As mp_int, Byval b As _Unsigned _Integer64) ' as mp_err
  51.     Sub mp_set_ll (a As mp_int, Byval b As _Integer64)
  52.     Sub mp_set_u64 (a As mp_int, Byval b As _Unsigned _Integer64)
  53.     Sub mp_set_ull (a As mp_int, Byval b As _Unsigned _Integer64)
  54.     Sub mp_set (a As mp_int, Byval b As _Unsigned _Integer64)
  55.     Function mp_get_mag_u32~& (a As mp_int) ' as ulong
  56.     Function mp_get_mag_ul~& (a As mp_int) ' as ulong
  57.     Function mp_get_mag_u64~&& (a As mp_int) ' as ulongint
  58.     Function mp_get_mag_ull~&& (a As mp_int) ' as ulongint
  59.     Function mp_copy (a As mp_int, b As mp_int) ' as mp_err
  60.     Sub mp_clamp (a As mp_int)
  61.     Function mp_export& (rop As _Offset, countp As _Unsigned Long, Byval order As Long, Byval size As _Unsigned Long, Byval endian As Long, Byval nails As _Unsigned Long, op As mp_int) ' as mp_err
  62.     Function mp_import& (rop As mp_int, Byval count As _Unsigned Long, Byval order As Long, Byval size As _Unsigned Long, Byval endian As Long, Byval nails As _Unsigned Long, Byval op As _Offset) ' as mp_err
  63.     Function mp_unpack& (rop As mp_int, Byval count As _Unsigned Long, Byval order As Long, Byval size As _Unsigned Long, Byval endian As Long, Byval nails As _Unsigned Long, op As _Offset) ' as mp_err
  64.     Function mp_pack_count~& (a As mp_int, Byval nails As _Unsigned Long, Byval size As _Unsigned Long) ' as uinteger
  65.     Function mp_pack& (rop As _Offset, Byval maxcount As _Unsigned Long, written As _Unsigned Long, Byval order As Long, Byval size As _Unsigned Long, Byval endian As Long, Byval nails As _Unsigned Long, op As mp_int) ' as mp_err
  66.     Sub mp_rshd (a As mp_int, Byval b As Long)
  67.     Function mp_lshd& (a As mp_int, Byval b As Long) ' as mp_err
  68.     Function mp_div_2d& (a As mp_int, Byval b As Long, c As mp_int, d As mp_int) ' as mp_err
  69.     Function mp_div_2& (a As mp_int, b As mp_int) ' as mp_err
  70.     Function mp_div_3& (a As mp_int, c As mp_int, d As _Unsigned _Integer64) ' as mp_err
  71.     Function mp_mul_2d& (a As mp_int, Byval b As Long, c As mp_int) ' as mp_err
  72.     Function mp_mul_2& (a As mp_int, b As mp_int) ' as mp_err
  73.     Function mp_mod_2d& (a As mp_int, Byval b As Long, c As mp_int) ' as mp_err
  74.     Function mp_2expt& (a As mp_int, Byval b As Long) ' as mp_err
  75.     Function mp_cnt_lsb& (a As mp_int) ' as long
  76.     Function mp_rand& (a As mp_int, Byval digits As Long) ' as mp_err
  77.     Function mp_rand_digit& (r As _Unsigned _Integer64) ' as mp_err
  78.     Function mp_get_bit& (a As mp_int, Byval b As Long) ' as long
  79.     Function mp_tc_xor& (a As mp_int, b As mp_int, c As mp_int) ' as mp_err
  80.     Function mp_xor& (a As mp_int, b As mp_int, c As mp_int) ' as mp_err
  81.     Function mp_tc_or& (a As mp_int, b As mp_int, c As mp_int) ' as mp_err
  82.     Function mp_or& (a As mp_int, b As mp_int, c As mp_int) ' as mp_err
  83.     Function mp_tc_and& (a As mp_int, b As mp_int, c As mp_int) ' as mp_err
  84.     Function mp_and& (a As mp_int, b As mp_int, c As mp_int) 'as mp_err
  85.     Function mp_complement& (a As mp_int, b As mp_int) ' as mp_err
  86.     Function mp_tc_div_2d& (a As mp_int, Byval b As Long, c As mp_int) ' as mp_err
  87.     Function mp_signed_rsh& (a As mp_int, Byval b As Long, c As mp_int) ' as mp_err
  88.     Function mp_neg (a As mp_int, b As mp_int) ' as mp_err
  89.     Function mp_abs& (a As mp_int, b As mp_int) ' as mp_err
  90.     Function mp_cmp& (a As mp_int, b As mp_int) 'as mp_ord
  91.     Function mp_cmp_mag& (a As mp_int, b As mp_int) ' as mp_ord
  92.     Function mp_add& (a As mp_int, b As mp_int, c As mp_int) ' as mp_err
  93.     Function mp_sub& (a As mp_int, b As mp_int, c As mp_int) ' as mp_err
  94.     Function mp_mul& (a As mp_int, b As mp_int, c As mp_int) ' as mp_err
  95.     Function mp_sqr& (a As mp_int, b As mp_int) ' as mp_err
  96.     Function mp_div& (a As mp_int, b As mp_int, c As mp_int, d As mp_int) ' as mp_err
  97.     Function mp_mod& (a As mp_int, b As mp_int, c As mp_int) ' as mp_err
  98.     Function mp_incr& (a As mp_int) ' as mp_err
  99.     Function mp_decr& (a As mp_int) ' as mp_err
  100.     Function mp_cmp_d& (a As mp_int, Byval b As _Unsigned _Integer64) ' as mp_ord
  101.     Function mp_add_d& (a As mp_int, Byval b As _Unsigned _Integer64, c As mp_int) ' as mp_err
  102.     Function mp_sub_d& (a As mp_int, Byval b As _Unsigned _Integer64, c As mp_int) ' as mp_err
  103.     Function mp_mul_d& (a As mp_int, Byval b As _Unsigned _Integer64, c As mp_int) ' as mp_err
  104.     Function mp_div_d& (a As mp_int, Byval b As _Unsigned _Integer64, c As mp_int, d As _Unsigned _Integer64) ' as mp_err
  105.     Function mp_mod_d& (a As mp_int, Byval b As _Unsigned _Integer64, c As _Unsigned _Integer64) ' as mp_err
  106.     Function mp_addmod& (a As mp_int, b As mp_int, c As mp_int, d As mp_int) ' as mp_err
  107.     Function mp_submod& (a As mp_int, b As mp_int, c As mp_int, d As mp_int) ' as mp_err
  108.     Function mp_mulmod& (a As mp_int, b As mp_int, c As mp_int, d As mp_int) ' as mp_err
  109.     Function mp_sqrmod& (a As mp_int, b As mp_int, c As mp_int) ' as mp_err
  110.     Function mp_invmod& (a As mp_int, b As mp_int, c As mp_int) ' as mp_err
  111.     Function mp_gcd& (a As mp_int, b As mp_int, c As mp_int) ' as mp_err
  112.     Function mp_exteuclid& (a As mp_int, b As mp_int, U1 As mp_int, U2 As mp_int, U3 As mp_int) ' as mp_err
  113.     Function mp_lcm& (a As mp_int, b As mp_int, c As mp_int) ' as mp_err
  114.     Function mp_root_u32& (a As mp_int, Byval b As _Unsigned Long, c As mp_int) ' as mp_err
  115.     Function mp_n_root& (a As mp_int, Byval b As _Unsigned _Integer64, c As mp_int) ' as mp_err
  116.     Function mp_n_root_ex& (a As mp_int, Byval b As _Unsigned _Integer64, c As mp_int, Byval fast As Long) ' as mp_err
  117.     Function mp_sqrt& (arg As mp_int, ret As mp_int) ' as mp_err
  118.     Function mp_sqrtmod_prime& (n As mp_int, prime As mp_int, ret As mp_int) ' as mp_err
  119.     Function mp_is_square& (arg As mp_int, ret As Long) ' as mp_err
  120.     Function mp_jacobi& (a As mp_int, n As mp_int, c As Long) ' as mp_err
  121.     Function mp_kronecker& (a As mp_int, p As mp_int, c As Long) ' as mp_err
  122.     Function mp_reduce_setup& (a As mp_int, b As mp_int) ' as mp_err
  123.     Function mp_reduce& (x As mp_int, m As mp_int, mu As mp_int) ' as mp_err
  124.     Function mp_montgomery_setup& (n As mp_int, rho As _Unsigned _Integer64) ' as mp_err
  125.     Function mp_montgomery_calc_normalization& (a As mp_int, b As mp_int) ' as mp_err
  126.     Function mp_montgomery_reduce& (x As mp_int, n As mp_int, Byval rho As _Unsigned _Integer64) ' as mp_err
  127.     Function mp_dr_is_modulus& (a As mp_int) ' as mp_bool
  128.     Sub mp_dr_setup (a As mp_int, d As _Unsigned _Integer64)
  129.     Function mp_dr_reduce& (x As mp_int, n As mp_int, Byval k As _Unsigned _Integer64) ' as mp_err
  130.     Function mp_reduce_is_2k& (a As mp_int) ' as mp_bool
  131.     Function mp_reduce_2k_setup& (a As mp_int, d As _Unsigned _Integer64) ' as mp_err
  132.     Function mp_reduce_2k& (a As mp_int, n As mp_int, Byval d As _Unsigned _Integer64) ' as mp_err
  133.     Function mp_reduce_is_2k_l& (a As mp_int) ' as mp_bool
  134.     Function mp_reduce_2k_setup_l& (a As mp_int, d As mp_int) ' as mp_err
  135.     Function mp_reduce_2k_l& (a As mp_int, n As mp_int, d As mp_int) ' as mp_err
  136.     Function mp_exptmod& (G As mp_int, X As mp_int, P As mp_int, Y As mp_int) ' as mp_err
  137.     Function mp_prime_is_divisible& (a As mp_int, result As Long) ' as mp_err
  138.     Function mp_prime_fermat& (a As mp_int, b As mp_int, result As Long) ' as mp_err
  139.     Function mp_prime_miller_rabin& (a As mp_int, b As mp_int, result As Long) ' as mp_err
  140.     Function mp_prime_rabin_miller_trials& (ByVal size As Long) ' as long
  141.     Function mp_prime_strong_lucas_selfridge& (a As mp_int, result As Long) ' as mp_err
  142.     Function mp_prime_frobenius_underwood& (N As mp_int, result As Long) ' as mp_err
  143.     Function mp_prime_is_prime& (a As mp_int, Byval t As Long, result As Long) ' as mp_err
  144.     Function mp_prime_next_prime& (a As mp_int, Byval t As Long, Byval bbs_style As Long) ' as mp_err
  145.     Function mp_prime_rand& (a As mp_int, Byval t As Long, Byval size As Long, Byval flags As Long) ' as mp_err
  146.     Function mp_log_u32& (a As mp_int, Byval base As _Unsigned Long, c As _Unsigned Long) ' as mp_err
  147.     Function mp_expt_u32& (a As mp_int, Byval b As _Unsigned Long, c As mp_int) ' as mp_err
  148.     Function mp_expt_d& (a As mp_int, Byval b As _Unsigned _Integer64, c As mp_int) ' as mp_err
  149.     Function mp_expt_d_ex& (a As mp_int, Byval b As _Unsigned _Integer64, c As mp_int, Byval fast As Long) ' as mp_err
  150.     Function mp_count_bits& (a As mp_int) ' as long
  151.     Function mp_unsigned_bin_size& (a As mp_int) ' as long
  152.     Function mp_read_unsigned_bin& (a As mp_int, Byval b As _Offset, Byval c As Long) ' as mp_err
  153.     Function mp_to_unsigned_bin& (a As mp_int, Byval b As _Offset) ' as mp_err
  154.     Function mp_to_unsigned_bin_n& (a As mp_int, Byval b As _Offset, outlen As _Unsigned Long) ' as mp_err
  155.     Function mp_signed_bin_size& (a As mp_int) ' as long
  156.     Function mp_read_signed_bin& (a As mp_int, Byval b As _Offset, Byval c As Long) ' as mp_err
  157.     Function mp_to_signed_bin& (a As mp_int, Byval b As _Offset) ' as mp_err
  158.     Function mp_to_signed_bin_n& (a As mp_int, Byval b As _Offset, outlen As _Unsigned Long) ' as mp_err
  159.     Function mp_ubin_size~&& (a As mp_int) ' as uinteger
  160.     Function mp_from_ubin& (a As mp_int, Byval buf As _Offset, Byval size As _Unsigned _Integer64) ' as mp_err
  161.     Function mp_to_ubin& (a As mp_int, Byval buf As _Offset, Byval maxlen As _Unsigned _Integer64, written As _Unsigned _Integer64) ' as mp_err
  162.     Function mp_sbin_size~&& (a As mp_int) ' as uinteger
  163.     Function mp_from_sbin& (a As mp_int, Byval buf As _Offset, Byval size As _Unsigned _Integer64) ' as mp_err
  164.     Function mp_to_sbin& (a As mp_int, Byval buf As _Offset, Byval maxlen As _Unsigned _Integer64, written As _Unsigned _Integer64) ' as mp_err
  165.     Function mp_to_radix& (a As mp_int, str As String, Byval maxlen As _Unsigned _Integer64, written As _Unsigned _Integer64, Byval radix As Long) ' as mp_err
  166.     Function mp_radix_size& (a As mp_int, Byval radix As Long, size As Long) ' as mp_err
  167.     Function mp_read_radix& (a As mp_int, str As String, Byval radix As Long) ' as mp_err
  168.     Function mp_toradix (a As mp_int, str As String, Byval radix As Long) ' as mp_err
  169.     Function mp_toradix_n& (a As mp_int, str As String, Byval radix As Long, Byval maxlen As Long) ' as mp_err
  170.  
  171. Dim As mp_int n, m, q, r
  172. Dim As Long ok, k
  173. t = Timer(.0001)
  174. If mp_init(n) <> 0 Then Print "failed to initialize"
  175. If mp_init(m) <> 0 Then Print "failed to initiali"
  176. If mp_init(q) <> 0 Then Print "failed to initiali"
  177. If mp_init(r) <> 0 Then Print "failed to initiali"
  178. 'mp_val "2" + String$(100, "0"), n, 10
  179. 'ok = mp_n_root&(n, 2, r)
  180. 'Print mp_str(r, 10)
  181. 'ok = mp_sqrt&(n, m)
  182. 'Print mp_str(m, 10)
  183. mp_set_i32 n, 2 '4784969
  184. ok = mp_expt_u32(n, 1024, n)
  185. 'mp_set_i32 m, 10
  186. 'ok = mp_expt_u32(m, 1000000, m)
  187. 'fib_mod n, m, r
  188. 'mp_set_i32 m, 10
  189. 'ok = mp_expt_u32(m, 999960, m)
  190. 'ok = mp_div(r, m, q, r)
  191. 'Print mp_str(q, 10)
  192. mp_set_i32 m, 10
  193. ok = mp_expt_u32(m, 40, m)
  194. fib_mod n, m, r
  195. Print mp_str(r, 10)
  196. t = Timer(.0001) - t
  197. mp_clear r
  198. mp_clear q
  199. mp_clear m
  200. mp_clear n
  201.  
  202. Sub fib_mod (k As mp_int, m As mp_int, result As mp_int)
  203.     Dim As mp_int x, y, xx, temp, tmp
  204.     Dim As Long ok, cmp, i, bit_length
  205.  
  206.     If mp_init(x) <> 0 Then
  207.         Print "failed to initialize"
  208.         Exit Sub
  209.     End If
  210.     If mp_init(y) <> 0 Then
  211.         Print "failed to initialize"
  212.         Exit Sub
  213.     End If
  214.     If mp_init(xx) <> 0 Then
  215.         Print "failed to initialize"
  216.         Exit Sub
  217.     End If
  218.     If mp_init(temp) <> 0 Then
  219.         Print "failed to initialize"
  220.         Exit Sub
  221.     End If
  222.     If mp_init(tmp) <> 0 Then
  223.         Print "failed to initialize"
  224.         Exit Sub
  225.     End If
  226.  
  227.     mp_set_i32 tmp, 1
  228.     If mp_cmp(k, tmp) <= 0 Then
  229.         Print "mp_cmp(k, tmp) <= 0"
  230.         ok = mp_copy(k, result)
  231.         Exit Sub
  232.     End If
  233.  
  234.     mp_set_i32 x, 1
  235.     mp_set_i32 y, 0
  236.     ok = mp_log_u32(k, 2, bit_length)
  237.     Print "bit_length="; bit_length
  238.     For i = bit_length - 1 To 0 Step -1
  239.         ok = mp_sqr(x, tmp)
  240.         ok = mp_mod(tmp, m, xx)
  241.         ok = mp_mul(x, y, tmp)
  242.         ok = mp_add(tmp, tmp, tmp)
  243.         ok = mp_add(xx, tmp, tmp)
  244.         ok = mp_mod(tmp, m, x)
  245.         ok = mp_sqr(y, tmp)
  246.         ok = mp_add(xx, tmp, tmp)
  247.         ok = mp_mod(tmp, m, y)
  248.         If mp_get_bit(k, i) Then
  249.             ok = mp_copy(x, temp)
  250.             ok = mp_add(x, y, tmp)
  251.             ok = mp_mod(tmp, m, x)
  252.             ok = mp_copy(temp, y)
  253.         End If
  254.     Next
  255.     ok = mp_copy(x, result)
  256.     mp_clear tmp
  257.     mp_clear temp
  258.     mp_clear xx
  259.     mp_clear y
  260.     mp_clear x
  261.  
  262. Function mp_str$ (n As mp_int, radix As Long)
  263.     Dim sresult As String
  264.     Dim As Long status, size
  265.     status = mp_radix_size&(n, radix, size)
  266.     sresult = Space$(size) + Chr$(0)
  267.     status = mp_toradix_n(n, sresult, radix, size)
  268.     If status = 0 Then
  269.         mp_str$ = _Trim$(sresult)
  270.     Else
  271.         mp_str$ = "error in mp_toradix"
  272.     End If
  273.  
  274. Sub mp_val (s As String, n As mp_int, radix As Long)
  275.     Dim value As String
  276.     Dim status As Long
  277.     Dim As Long ok
  278.     value = s + Chr$(0)
  279.     status = mp_read_radix(n, value, radix)
  280.     If status <> 0 Then Print "could not read number"
  281.  

11
QB64 Discussion / Re: big number
« on: April 04, 2022, 06:34:09 pm »
hello Jaze
an unsigned integer64 can hold up-to 18446744073709551615 if you want numbers bigger than that I woul suggest LibTomMath from https://www.libtom.net/ let me know if that's what you want

12
Programs / Re: intel decimal math library
« on: April 03, 2022, 09:33:25 pm »
the Intel math library has 3 types decimal32, decimal64 and decimal128
the decimal64 is easy to use in QB64 but for the decimal128 I had make a wrapper
Code: QB64: [Select]
  1. Type BID_UINT128
  2.  
  3.     Sub binary64_to_bid128 (result As BID_UINT128, x As Double, Byval rnd_mode~&, pfpsf~&)
  4.     Sub binary80_to_bid128 (result As BID_UINT128, x As _Float, Byval rnd_mode~&, pfpsf~&)
  5.     Sub bid128_add (result As BID_UINT128, x As BID_UINT128, y As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  6.     Sub bid128_sub (result As BID_UINT128, x As BID_UINT128, y As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  7.     Sub bid128_mul (result As BID_UINT128, x As BID_UINT128, y As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  8.     Sub bid128_div (result As BID_UINT128, x As BID_UINT128, y As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  9.     Sub bid128_sqrt (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  10.     Sub bid128_cbrt (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  11.     Sub bid128_exp (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  12.     Sub bid128_log (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  13.     Sub bid128_pow (result As BID_UINT128, x As BID_UINT128, y As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  14.     Sub bid128_atan2 (result As BID_UINT128, x As BID_UINT128, y As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  15.     Sub bid128_fmod (result As BID_UINT128, x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  16.     Sub bid128_modf (result As BID_UINT128, x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  17.     Sub bid128_hypot (result As BID_UINT128, x As BID_UINT128, y As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  18.     Sub bid128_sin (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  19.     Sub bid128_cos (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  20.     Sub bid128_tan (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  21.     Sub bid128_asin (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  22.     Sub bid128_acos (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  23.     Sub bid128_atan (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  24.     Sub bid128_sinh (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  25.     Sub bid128_cosh (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  26.     Sub bid128_tanh (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  27.     Sub bid128_asinh (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  28.     Sub bid128_acosh (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  29.     Sub bid128_atanh (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  30.     Sub bid128_log1p (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  31.     Sub bid128_expm1 (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  32.     Sub bid128_log10 (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  33.     Sub bid128_log2 (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  34.     Sub bid128_exp2 (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  35.     Sub bid128_exp10 (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  36.     Sub bid128_erf (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  37.     Sub bid128_erfc (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  38.     Sub bid128_tgamma (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  39.     Sub bid128_lgamma (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  40.     Function bid128_quiet_equal& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  41.     Function bid128_quiet_greater& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  42.     Function bid128_quiet_greater_equal& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  43.     Function bid128_quiet_greater_unordered& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  44.     Function bid128_quiet_less& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  45.     Function bid128_quiet_less_equal& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  46.     Function bid128_quiet_less_unordered& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  47.     Function bid128_quiet_not_equal& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  48.     Function bid128_quiet_not_greater& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  49.     Function bid128_quiet_not_less& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  50.     Function bid128_quiet_ordered& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  51.     Function bid128_quiet_unordered& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  52.     Function bid128_signaling_greater& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  53.     Function bid128_signaling_greater_equal& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  54.     Function bid128_signaling_greater_unordered& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  55.     Function bid128_signaling_less& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  56.     Function bid128_signaling_less_equal& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  57.     Function bid128_signaling_less_unordered& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  58.     Function bid128_signaling_not_greater& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  59.     Function bid128_signaling_not_less& (x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  60.  
  61.     Sub bid128_copy (result As BID_UINT128, x As BID_UINT128)
  62.     Sub bid128_negate (result As BID_UINT128, x As BID_UINT128)
  63.     Sub bid128_abs (result As BID_UINT128, x As BID_UINT128)
  64.     Sub bid128_to_string (S As String, x As BID_UINT128, pfpsf~&)
  65.     Function bid128_to_binary32! (x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  66.     Function bid128_to_binary64# (x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  67.     Function bid128_to_binary80## (x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  68.     Sub bid_strtod128 (result As BID_UINT128, ps_in As String, Byval endptr&)
  69.  
  70.     Function bid128_to_int8_rnint%% (x As BID_UINT128, pfpsf~&)
  71.     Function bid128_to_int8_xrnint%% (x As BID_UINT128, pfpsf~&)
  72.     Function bid128_to_int8_rninta%% (x As BID_UINT128, pfpsf~&)
  73.     Function bid128_to_int8_xrninta%% (x As BID_UINT128, pfpsf~&)
  74.     Function bid128_to_int8_int%% (x As BID_UINT128, pfpsf~&)
  75.     Function bid128_to_int8_xint%% (x As BID_UINT128, pfpsf~&)
  76.     Function bid128_to_int8_floor%% (x As BID_UINT128, pfpsf~&)
  77.     Function bid128_to_int8_xfloor%% (x As BID_UINT128, pfpsf~&)
  78.     Function bid128_to_int8_ceil%% (x As BID_UINT128, pfpsf~&)
  79.     Function bid128_to_int8_xceil%% (x As BID_UINT128, pfpsf~&)
  80.  
  81.     Function bid128_to_int16_rnint% (x As BID_UINT128, pfpsf~&)
  82.     Function bid128_to_int16_xrnint% (x As BID_UINT128, pfpsf~&)
  83.     Function bid128_to_int16_rninta% (x As BID_UINT128, pfpsf~&)
  84.     Function bid128_to_int16_xrninta% (x As BID_UINT128, pfpsf~&)
  85.     Function bid128_to_int16_int% (x As BID_UINT128, pfpsf~&)
  86.     Function bid128_to_int16_xint% (x As BID_UINT128, pfpsf~&)
  87.     Function bid128_to_int16_floor% (x As BID_UINT128, pfpsf~&)
  88.     Function bid128_to_int16_xfloor% (x As BID_UINT128, pfpsf~&)
  89.     Function bid128_to_int16_ceil% (x As BID_UINT128, pfpsf~&)
  90.     Function bid128_to_int16_xceil% (x As BID_UINT128, pfpsf~&)
  91.  
  92.     Function bid128_to_uint8_rnint~%% (x As BID_UINT128, pfpsf~&)
  93.     Function bid128_to_uint8_xrnint~%% (x As BID_UINT128, pfpsf~&)
  94.     Function bid128_to_uint8_rninta~%% (x As BID_UINT128, pfpsf~&)
  95.     Function bid128_to_uint8_xrninta~%% (x As BID_UINT128, pfpsf~&)
  96.     Function bid128_to_uint8_int~%% (x As BID_UINT128, pfpsf~&)
  97.     Function bid128_to_uint8_xint~%% (x As BID_UINT128, pfpsf~&)
  98.     Function bid128_to_uint8_floor~%% (x As BID_UINT128, pfpsf~&)
  99.     Function bid128_to_uint8_xfloor~%% (x As BID_UINT128, pfpsf~&)
  100.     Function bid128_to_uint8_ceil~%% (x As BID_UINT128, pfpsf~&)
  101.     Function bid128_to_uint8_xceil~%% (x As BID_UINT128, pfpsf~&)
  102.  
  103.     Function bid128_to_uint16_rnint~% (x As BID_UINT128, pfpsf~&)
  104.     Function bid128_to_uint16_xrnint~% (x As BID_UINT128, pfpsf~&)
  105.     Function bid128_to_uint16_rninta~% (x As BID_UINT128, pfpsf~&)
  106.     Function bid128_to_uint16_xrninta~% (x As BID_UINT128, pfpsf~&)
  107.     Function bid128_to_uint16_int~% (x As BID_UINT128, pfpsf~&)
  108.     Function bid128_to_uint16_xint~% (x As BID_UINT128, pfpsf~&)
  109.     Function bid128_to_uint16_floor~% (x As BID_UINT128, pfpsf~&)
  110.     Function bid128_to_uint16_xfloor~% (x As BID_UINT128, pfpsf~&)
  111.     Function bid128_to_uint16_ceil~% (x As BID_UINT128, pfpsf~&)
  112.     Function bid128_to_uint16_xceil~% (x As BID_UINT128, pfpsf~&)
  113.  
  114.     Function bid128_to_int32_rnint& (x As BID_UINT128, pfpsf~&)
  115.     Function bid128_to_int32_xrnint& (x As BID_UINT128, pfpsf~&)
  116.     Function bid128_to_int32_rninta& (x As BID_UINT128, pfpsf~&)
  117.     Function bid128_to_int32_xrninta& (x As BID_UINT128, pfpsf~&)
  118.     Function bid128_to_int32_int& (x As BID_UINT128, pfpsf~&)
  119.     Function bid128_to_int32_xint& (x As BID_UINT128, pfpsf~&)
  120.     Function bid128_to_int32_floor& (x As BID_UINT128, pfpsf~&)
  121.     Function bid128_to_int32_xfloor& (x As BID_UINT128, pfpsf~&)
  122.     Function bid128_to_int32_ceil& (x As BID_UINT128, pfpsf~&)
  123.     Function bid128_to_int32_xceil& (x As BID_UINT128, pfpsf~&)
  124.  
  125.     Function bid128_to_uint32_rnint~& (x As BID_UINT128, pfpsf~&)
  126.     Function bid128_to_uint32_xrnint~& (x As BID_UINT128, pfpsf~&)
  127.     Function bid128_to_uint32_rninta~& (x As BID_UINT128, pfpsf~&)
  128.     Function bid128_to_uint32_xrninta~& (x As BID_UINT128, pfpsf~&)
  129.     Function bid128_to_uint32_int~& (x As BID_UINT128, pfpsf~&)
  130.     Function bid128_to_uint32_xint~& (x As BID_UINT128, pfpsf~&)
  131.     Function bid128_to_uint32_floor~& (x As BID_UINT128, pfpsf~&)
  132.     Function bid128_to_uint32_xfloor~& (x As BID_UINT128, pfpsf~&)
  133.     Function bid128_to_uint32_ceil~& (x As BID_UINT128, pfpsf~&)
  134.     Function bid128_to_uint32_xceil~& (x As BID_UINT128, pfpsf~&)
  135.  
  136.     Function bid128_to_int64_rnint&& (x As BID_UINT128, pfpsf~&)
  137.     Function bid128_to_int64_xrnint&& (x As BID_UINT128, pfpsf~&)
  138.     Function bid128_to_int64_rninta&& (x As BID_UINT128, pfpsf~&)
  139.     Function bid128_to_int64_xrninta&& (x As BID_UINT128, pfpsf~&)
  140.     Function bid128_to_int64_int&& (x As BID_UINT128, pfpsf~&)
  141.     Function bid128_to_int64_xint&& (x As BID_UINT128, pfpsf~&)
  142.     Function bid128_to_int64_floor&& (x As BID_UINT128, pfpsf~&)
  143.     Function bid128_to_int64_xfloor&& (x As BID_UINT128, pfpsf~&)
  144.     Function bid128_to_int64_ceil&& (x As BID_UINT128, pfpsf~&)
  145.     Function bid128_to_int64_xceil&& (x As BID_UINT128, pfpsf~&)
  146.  
  147.     Function bid128_to_uint64_rnint~&& (x As BID_UINT128, pfpsf~&)
  148.     Function bid128_to_uint64_xrnint~&& (x As BID_UINT128, pfpsf~&)
  149.     Function bid128_to_uint64_rninta~&& (x As BID_UINT128, pfpsf~&)
  150.     Function bid128_to_uint64_xrninta~&& (x As BID_UINT128, pfpsf~&)
  151.     Function bid128_to_uint64_int~&& (x As BID_UINT128, pfpsf~&)
  152.     Function bid128_to_uint64_xint~&& (x As BID_UINT128, pfpsf~&)
  153.     Function bid128_to_uint64_floor~&& (x As BID_UINT128, pfpsf~&)
  154.     Function bid128_to_uint64_xfloor~&& (x As BID_UINT128, pfpsf~&)
  155.     Function bid128_to_uint64_ceil~&& (x As BID_UINT128, pfpsf~&)
  156.     Function bid128_to_uint64_xceil~&& (x As BID_UINT128, pfpsf~&)
  157.  
  158.     Sub bid128_round_integral_exact (result As BID_UINT128, x As BID_UINT128, Byval rnd_mode~&, pfpsf~&)
  159.     Sub bid128_round_integral_nearest_even (result As BID_UINT128, x As BID_UINT128, pfpsf~&)
  160.     Sub bid128_round_integral_negative (result As BID_UINT128, x As BID_UINT128, pfpsf~&)
  161.     Sub bid128_round_integral_positive (result As BID_UINT128, x As BID_UINT128, pfpsf~&)
  162.     Sub bid128_round_integral_zero (result As BID_UINT128, x As BID_UINT128, pfpsf~&)
  163.     Sub bid128_round_integral_nearest_away (result As BID_UINT128, x As BID_UINT128, pfpsf~&)
  164.     Sub bid128_nextup (result As BID_UINT128, x As BID_UINT128, pfpsf~&)
  165.     Sub bid128_nextdown (result As BID_UINT128, x As BID_UINT128, pfpsf~&)
  166.     Sub bid128_nextafter (result As BID_UINT128, x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  167.     Sub bid128_minnum (result As BID_UINT128, x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  168.     Sub bid128_minnum_mag (result As BID_UINT128, x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  169.     Sub bid128_maxnum (result As BID_UINT128, x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  170.     Sub bid128_maxnum_mag (result As BID_UINT128, x As BID_UINT128, y As BID_UINT128, pfpsf~&)
  171.     Sub bid128_from_int32 (result As BID_UINT128, Byval x&)
  172.     Sub bid128_from_uint32 (result As BID_UINT128, Byval x~&)
  173.     Sub bid128_from_int64 (result As BID_UINT128, Byval x&&)
  174.     Sub bid128_from_uint64 (result As BID_UINT128, Byval x~&&)
  175.     Function bid128_isSigned& (x As BID_UINT128)
  176.     Function bid128_isNormal& (x As BID_UINT128)
  177.     Function bid128_isSubnormal& (x As BID_UINT128)
  178.     Function bid128_isFinite& (x As BID_UINT128)
  179.     Function bid128_isZero& (x As BID_UINT128)
  180.     Function bid128_isInf& (x As BID_UINT128)
  181.     Function bid128_isSignaling& (x As BID_UINT128)
  182.     Function bid128_isCanonical& (x As BID_UINT128)
  183.     Function bid128_isNaN& (x As BID_UINT128)
  184.  
  185.  
  186.  
  187. Dim As BID_UINT128 i, y, z, x
  188. Dim As Long flag, rm
  189.  
  190. rm = 0
  191. bid128_from_int32 i, -1 'strto128 i, "1"
  192. bid128_from_int32 y, 1 'strto128 y, "20"
  193. strto128 z, ".1"
  194. While bid128_quiet_less_equal(i, y, flag)
  195.     'bid128_sin x, i, rm, flag
  196.     'bid128_asin x, x, rm, flag
  197.     'bid128_log10 x, i, rm, flag
  198.     'Print d128tostring$(x)
  199.     Print d128tostring$(i)
  200.     bid128_add i, i, z, rm, flag
  201.  
  202. Sub strto128 (result As BID_UINT128, s As String)
  203.     Dim As String sn
  204.     sn = s + Chr$(0)
  205.     bid_strtod128 result, sn, 0
  206.  
  207. Function d128tostring$ (z As BID_UINT128)
  208.     Dim As Long ex, ex1, i, ln
  209.     Dim As String s, sd, sdl, sdr, se, sign
  210.     Dim As BID_UINT128 one, x
  211.     Dim As Long flag, rm
  212.     If bid128_isZero(z) Then
  213.         d128tostring = " 0"
  214.         Exit Function
  215.     End If
  216.     rm = 0
  217.     x = z
  218.     bid128_copy x, z
  219.     bid_strtod128 one, "1.00000000000000000000000000000000000", 0
  220.     s = Space$(256)
  221.     bid128_mul x, x, one, 0, flag
  222.     bid128_to_string s, x, flag
  223.     sd = _Trim$(s)
  224.     ln = Len(sd)
  225.     i = InStr(sd, "E")
  226.     sdl = Left$(sd, i - 1)
  227.     ex = Val(Mid$(sd, i + 1))
  228.     ln = Len(sdl)
  229.     If ex = 0 Then
  230.         sd = sdl
  231.     ElseIf ex > 0 Or ex < 0 Then
  232.         ex1 = ln + ex - 2
  233.         If ex1 >= 0 And ex1 < (ln - 1) Then
  234.             sd = Left$(sdl, ex1 + 2) + "." + Mid$(sdl, ex1 + 3)
  235.         ElseIf ex1 < 0 And ex1 > -5 Then
  236.             sign = Left$(sd, 1)
  237.             sd = sign + "0." + String$(Abs(ex1) - 1, "0") + Mid$(sdl, 2)
  238.         Else
  239.             se = _Trim$(Str$(ex1))
  240.             If ex1 > 0 Then
  241.                 se = "+" + se
  242.             End If
  243.             sd = sdl
  244.             sdl = Left$(sd, 2)
  245.             sdr = Mid$(sd, 3)
  246.             sd = sdl + "." + sdr + "E" + se
  247.         End If
  248.     End If
  249.     If Left$(sd, 1) = "+" Then
  250.         sd = " " + Mid$(sd, 2)
  251.     End If
  252.     d128tostring = sd
  253.  

the 64-bit dll

output
Code: [Select]
-1.000000000000000000000000000000000
-0.9000000000000000000000000000000000
-0.8000000000000000000000000000000000
-0.7000000000000000000000000000000000
-0.6000000000000000000000000000000000
-0.5000000000000000000000000000000000
-0.4000000000000000000000000000000000
-0.3000000000000000000000000000000000
-0.2000000000000000000000000000000000
-0.1000000000000000000000000000000000
 0
 0.1000000000000000000000000000000000
 0.2000000000000000000000000000000000
 0.3000000000000000000000000000000000
 0.4000000000000000000000000000000000
 0.5000000000000000000000000000000000
 0.6000000000000000000000000000000000
 0.7000000000000000000000000000000000
 0.8000000000000000000000000000000000
 0.9000000000000000000000000000000000
 1.000000000000000000000000000000000

Press any key to continue

13
Programs / intel decimal math library
« on: April 03, 2022, 11:31:04 am »
here's a small test of the Intel decimal math library https://www.intel.com/content/www/us/en/developer/articles/tool/intel-decimal-floating-point-math-library.html, if there's enough interest I may expand the function declarations
Code: QB64: [Select]
  1.  
  2.     Function __bid_strtod64~&& (s$, Byval ptr&)
  3.     Function add64~&& Alias "__bid64_add" (ByVal x~&&, Byval y~&&, Byval rnd_mode&, flag&)
  4.     Function sub64~&& Alias "__bid64_sub" (ByVal x~&&, Byval y~&&, Byval rnd_mode&, flag&)
  5.     Function mul64~&& Alias "__bid64_mul" (ByVal x~&&, Byval y&&, Byval rnd_mode&, flag&)
  6.     Function div64~&& Alias "__bid64_div" (ByVal x~&&, Byval y~&&, Byval rnd_mode&, flag&)
  7.  
  8.     Function is_equal64& Alias "__bid64_quiet_equal" (ByVal x~&&, Byval y~&&, flag&)
  9.     Function is_less64& Alias "__bid64_quiet_less" (ByVal x~&&, Byval y~&&, flag&)
  10.     Function is_greater64& Alias "__bid64_quiet_greater" (ByVal x~&&, Byval y~&&, flag&)
  11.     Function is_less_equal64& Alias "__bid64_quiet_less_equal" (ByVal x~&&, Byval y~&&, flag&)
  12.     Function is_greater_equal64& Alias "__bid64_quiet_greater_equal" (ByVal x~&&, Byval y~&&, flag&)
  13.     Function is_unequal64& Alias "__bid64_quiet_not_equal" (ByVal x~&&, Byval y~&&, flag&)
  14.     Function isZero64& Alias "__bid64_isZero" (ByVal x~&&)
  15.     Sub __bid64_to_string (ps$, Byval x~&&, pf&)
  16.     Function copy64~&& Alias "__bid64_copy" (ByVal x~&&)
  17.     Function negate64~&& Alias "__bid64_negate" (ByVal x~&&)
  18.     Function abs64~&& Alias "__bid64_abs" (ByVal x~&&)
  19.     Function sqrt64~&& Alias "__bid64_sqrt" (ByVal x~&&, Byval rnd_mode&, flag&)
  20.     Function cbrt64~&& Alias "__bid64_cbrt" (ByVal x~&&, Byval rnd_mode&, flag&)
  21.     Function sin64~&& Alias "__bid64_sin" (ByVal x~&&, Byval rnd_mode&, flag&)
  22.     Function cos64~&& Alias "__bid64_cos" (ByVal x~&&, Byval rnd_mode&, flag&)
  23.     Function tan64~&& Alias "__bid64_tan" (ByVal x~&&, Byval rnd_mode&, flag&)
  24.     Function asin64~&& Alias "__bid64_asin" (ByVal x~&&, Byval rnd_mode&, flag&)
  25.     Function acos64~&& Alias "__bid64_acos" (ByVal x~&&, Byval rnd_mode&, flag&)
  26.     Function atan64~&& Alias "__bid64_atan" (ByVal x~&&, Byval rnd_mode&, flag&)
  27.     Function sinh64~&& Alias "__bid64_sinh" (ByVal x~&&, Byval rnd_mode&, flag&)
  28.     Function cosh64~&& Alias "__bid64_cosh" (ByVal x~&&, Byval rnd_mode&, flag&)
  29.     Function tanh64~&& Alias "__bid64_tanh" (ByVal x~&&, Byval rnd_mode&, flag&)
  30.     Function asinh64~&& Alias "__bid64_asinh" (ByVal x~&&, Byval rnd_mode&, flag&)
  31.     Function acosh64~&& Alias "__bid64_acosh" (ByVal x~&&, Byval rnd_mode&, flag&)
  32.     Function atanh64~&& Alias "__bid64_atanh" (ByVal x~&&, Byval rnd_mode&, flag&)
  33.     Function atan264~&& Alias "__bid64_atan2" (ByVal x~&&, Byval y~&&, Byval rnd_mode&, flag&)
  34.     Function hypot64~&& Alias "__bid64_hypot" (ByVal x~&&, Byval y~&&, Byval rnd_mode&, flag&)
  35.     Function log1064~&& Alias "__bid64_log10" (ByVal x~&&, Byval rnd_mode&, flag&)
  36.     Function exp1064~&& Alias "__bid64_exp10" (ByVal x~&&, Byval rnd_mode&, flag&)
  37.     Function log64~&& Alias "__bid64_log" (ByVal x~&&, Byval rnd_mode&, flag&)
  38.     Function exp64~&& Alias "__bid64_exp" (ByVal x~&&, Byval rnd_mode&, flag&)
  39.     Function pow64~&& Alias "__bid64_pow" (ByVal x~&&, Byval y~&&, Byval rnd_mode&, flag&)
  40.     Function log264~&& Alias "__bid64_log2" (ByVal x~&&, Byval rnd_mode&, flag&)
  41.     Function exp264~&& Alias "__bid64_exp2" (ByVal x~&&, Byval rnd_mode&, flag&)
  42.     Function erf64~&& Alias "__bid64_erf" (ByVal x~&&, Byval rnd_mode&, flag&)
  43.     Function erfc64~&& Alias "__bid64_erfc" (ByVal x~&&, Byval rnd_mode&, flag&)
  44.     Function tgamma64~&& Alias "__bid64_tgamma" (ByVal x~&&, Byval rnd_mode&, flag&)
  45.     Function lgamma64~&& Alias "__bid64_lgamma" (ByVal x~&&, Byval rnd_mode&, flag&)
  46.     Function floor64l& Alias "__bid64_to_int32_floor" (ByVal x~&&, flag&)
  47.     Function ceil64l& Alias "__bid64_to_int32_ceil" (ByVal x~&&, flag&)
  48.     Function floor64ul~& Alias "__bid64_to_uint32_floor" (ByVal x~&&, flag&)
  49.     Function ceil64ul~& Alias "__bid64_to_uint32_ceil" (ByVal x~&&, flag&)
  50.     Function floor64ll~&& Alias "__bid64_to_int64_floor" (ByVal x~&&, flag&)
  51.     Function ceil64ll~&& Alias "__bid64_to_int64_ceil" (ByVal x~&&, flag&)
  52.     Function floor64ull~&& Alias "__bid64_to_uint64_floor" (ByVal x~&&, flag&)
  53.     Function ceil64ull~&& Alias "__bid64_to_uint64_ceil" (ByVal x~&&, flag&)
  54.     Function tosingle64! Alias "__bid64_to_binary32" (ByVal x~&&, Byval rnd_mode&, flag&)
  55.     Function todouble# Alias "__bid64_to_binary64" (ByVal x~&&, Byval rnd_mode&, flag&)
  56.     Function singleto64~&& Alias "__binary32_to_bid64" (ByVal x As Single, Byval rnd_mode&, flag&)
  57.     Function doubleto64~&& Alias "__binary64_to_bid64" (ByVal x As Double, Byval rnd_mode&, flag&)
  58.  
  59. Dim As Long flag, rm
  60.  
  61. rm = 0
  62. i = strto64("-1")
  63. y = strto64("1")
  64. z = strto64(".1")
  65. While is_less_equal64(i, y, flag)
  66.     Print tostring(i)
  67.     i = add64(i, z, rm, flag)
  68.  
  69. Function strto64~&& (s As String)
  70.     Dim As String sn
  71.     sn = s + Chr$(0)
  72.     strto64~&& = __bid_strtod64(sn, 0)
  73.  
  74.     Dim As Long ex, ex1, i, ln
  75.     Dim As String s, sd, sdl, sdr, se, sign
  76.     Dim As _Unsigned _Integer64 one, x
  77.     Dim As Long flag, rm
  78.     If isZero64(z) Then
  79.         tostring = " 0"
  80.         Exit Function
  81.     End If
  82.     rm = 0
  83.     x = z
  84.     one = __bid_strtod64("1.00000000000000000000", 0)
  85.     s = Space$(256)
  86.     __bid64_to_string s, mul64(x, one, 0, flag), flag
  87.     sd = _Trim$(s)
  88.     ln = Len(sd)
  89.     i = InStr(sd, "E")
  90.     sdl = Left$(sd, i - 1)
  91.     ex = Val(Mid$(sd, i + 1))
  92.     ln = Len(sdl)
  93.     If ex = 0 Then
  94.         sd = sdl
  95.     ElseIf ex > 0 Or ex < 0 Then
  96.         ex1 = ln + ex - 2
  97.         If ex1 >= 0 And ex1 < (ln - 1) Then
  98.             sd = Left$(sdl, ex1 + 2) + "." + Mid$(sdl, ex1 + 3)
  99.         ElseIf ex1 < 0 And ex1 > -5 Then
  100.             sign = Left$(sd, 1)
  101.             sd = sign + "0." + String$(Abs(ex1) - 1, "0") + Mid$(sdl, 2)
  102.         Else
  103.             se = _Trim$(Str$(ex1))
  104.             If ex1 > 0 Then
  105.                 se = "+" + se
  106.             End If
  107.             sd = sdl
  108.             sdl = Left$(sd, 2)
  109.             sdr = Mid$(sd, 3)
  110.             sd = sdl + "." + sdr + "E" + se
  111.         End If
  112.     End If
  113.     If Left$(sd, 1) = "+" Then
  114.         sd = " " + Mid$(sd, 2)
  115.     End If
  116.     tostring = sd
  117.  
here's the 64-bit dll

14
Programs / Re: decfloat 2.0
« on: April 02, 2022, 10:15:47 pm »
here's a program that calculates the first and last 40 digits of insanely huge Fibonacci numbers, in this example it's for Fibonacci( 2 ^ 1024)
the fib program is based on a program in page 14 of this document https://www.uni-math.gwdg.de/tschinkel/gauss/Fibon.pdf
result on my PC
you will need the bi and bm from  https://www.qb64.org/forum/index.php?topic=4276.msg136873#msg136873
Code: [Select]
2116996771162424982619007079477296709285
 5727677983280861229066251547465117987387
 4.023000000001048
Code: QB64: [Select]
  1. 'you must use $NoPrefix
  2. Dest Console
  3.  
  4. Option Explicit
  5.  
  6. Const NUMBER_OF_DIGITS = 620 ' you must have NUMBER_OF_DIGITS defined -- not to exceed 1024
  7. '                             before including decfloat.bi
  8. '$include: 'decfloat.bi'
  9.  
  10. '======================================================================
  11. ' your code follows
  12.  
  13. Dim As decfloat first, last, fn, m, x, y, z, v
  14. t = Timer(.001)
  15. 'str2fp fn, "4784969" ' "4784969"
  16. si2fp fn, 2, NUM_DWORDS
  17. fpipow fn, fn, 1024, NUM_DWORDS
  18. str2fp m, "10000000000000000000000000000000000000000"
  19. si2fp x, 5, NUM_DWORDS
  20. fpsqr x, x, NUM_DWORDS
  21. si2fp z, 1, NUM_DWORDS
  22. fpadd y, x, z, NUM_DWORDS
  23. fpdiv_si y, y, 2, NUM_DWORDS
  24. fplog y, y, NUM_DWORDS
  25. fpmul y, y, fn, NUM_DWORDS
  26. fplog z, x, NUM_DWORDS
  27. fpsub y, y, z, NUM_DWORDS
  28. si2fp x, 10, NUM_DWORDS
  29. fplog v, x, NUM_DWORDS
  30. fpdiv y, y, v, NUM_DWORDS
  31. fpfrac z, y, NUM_DWORDS
  32. fppow y, x, z
  33. s = fp2str(y, 40)
  34. dp = InStr(s, ".")
  35. s = Left$(s, dp - 1) + Mid$(s, dp + 1)
  36. fib fn, m, last
  37. t = Timer - t
  38. s = fp2str(last, NUMBER_OF_DIGITS)
  39. dp = InStr(s, ".")
  40. Print Left$(s, dp - 1)
  41.  
  42.  
  43. Sub fib (k As decfloat, m As decfloat, fibonacci As decfloat)
  44.     Dim As decfloat b, x, y, xx, temp, tmp, rn
  45.     Dim As Long i, bit_length
  46.     str2fp rn, ".05"
  47.     si2fp tmp, 1, NUM_DWORDS
  48.     If fpcmp(k, tmp, NUM_DWORDS) <= 0 Then
  49.         fibonacci = k
  50.         Exit Sub
  51.     End If
  52.     si2fp x, 1, NUM_DWORDS
  53.     si2fp y, 0, NUM_DWORDS
  54.     fplog tmp, k, NUM_DWORDS
  55.     si2fp temp, 2, NUM_DWORDS
  56.     fplog xx, temp, NUM_DWORDS
  57.     fpdiv b, tmp, xx, NUM_DWORDS
  58.     fpfix tmp, b
  59.     bit_length = fp2dbl(tmp)
  60.     si2fp b, 2, NUM_DWORDS
  61.     fpipow b, b, bit_length - 1, NUM_DWORDS
  62.     For i = bit_length - 1 To 0 Step -1
  63.         fpmul xx, x, x, NUM_DWORDS
  64.         fpdiv xx, xx, m, NUM_DWORDS
  65.         fpfrac xx, xx, NUM_DWORDS
  66.         fpmul xx, xx, m, NUM_DWORDS
  67.         fpadd xx, xx, rn, NUM_DWORDS
  68.         fpfix xx, xx
  69.         fpmul x, x, y, NUM_DWORDS
  70.         fpmul_si x, x, 2, NUM_DWORDS
  71.         fpadd x, xx, x, NUM_DWORDS
  72.         fpdiv x, x, m, NUM_DWORDS
  73.         fpfrac x, x, NUM_DWORDS
  74.         fpmul x, x, m, NUM_DWORDS
  75.         fpadd x, x, rn, NUM_DWORDS
  76.         fpfix x, x
  77.         fpmul y, y, y, NUM_DWORDS
  78.         fpadd y, y, xx, NUM_DWORDS
  79.         fpdiv y, y, m, NUM_DWORDS
  80.         fpfrac y, y, NUM_DWORDS
  81.         fpmul y, y, m, NUM_DWORDS
  82.         fpadd y, y, rn, NUM_DWORDS
  83.         fpfix y, y
  84.         fpdiv temp, k, b, NUM_DWORDS
  85.         If fpfix_is_odd(temp) Then
  86.             temp = x
  87.             fpadd x, x, y, NUM_DWORDS
  88.             fpdiv x, x, m, NUM_DWORDS
  89.             fpfrac x, x, NUM_DWORDS
  90.             fpmul x, x, m, NUM_DWORDS
  91.             fpadd x, x, rn, NUM_DWORDS
  92.             fpfix x, x
  93.             y = temp
  94.         End If
  95.         fpdiv_si b, b, 2, NUM_DWORDS
  96.     Next
  97.     fibonacci = x
  98.  
  99. ' end of your code
  100. ' you must include decfloat.bm
  101. '$include: 'decfloat.bm'
  102.  

15
gcc runtime library has decimal arithmetic functions https://gcc.gnu.org/onlinedocs/gccint/Decimal-float-library-routines.html so it may be possible to use them in QB64
tried it, but unfortunately QB64 passes the arguments by reference and they need to be by value
since the functions are inline and there's no library I can't use the byval keyword
Code: QB64: [Select]
  1. declare Function __bid_adddd3~&& (a~&&, b~&&)
  2. declare Function __bid_extenddfdd~&& (a#)
  3. declare Function __bid_truncdddf# (a~&&)
  4.  
  5. Dim As Double dx, dy
  6.  
  7. dx = 3.141592653589793
  8. x = __bid_extenddfdd~&&(dx)
  9. y = bid_add(x, x)
  10. dy = __bid_truncdddf#(y)
  11.  

Pages: [1] 2 3 ... 28