If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

I was confused at first, but then I realised I cannot use passed strings directly, but need to use the BigInt_FromString and BigInt_ToString.

Correct. I thought about making all functions "auto-recognise" but I found it just too much trouble. Also, for a true auto-recognise I would want it to work with numerical variables as well and I just couldn't get the Variant bit to work. So I stuck with the internal representation.

You can get strange results if you try to print (to Console) internal BigInt strings directly, without using BigInt_ToString. Look out for that.

That would also be a problem because if conversion from ASCII to internal is automatic, you'd expect the reverse to be true as well: automatic conversion from internal to ASCII when printing. But for that I would have to make this a proper thinBasic module and if I understand it correctly I would have to use an SDK, and there isn't one for thinBasic, only for PowerBasic and FreeBasic.

I am thinking of doing the low-level functions (BII_add, _sub, _mul, _mli, _div, _dvi) in assembler. That should speed things up enormously. If I'm going to do that I'll make some test cases first to check the speed in pure Basic so I can compare it with the assembler version. I'm not guaranteeing anything because I am very busy with work right now and I'm also thinking about writing high-precision (128-bit) floating-point functions.

Bug report!

BigInt_Nrt may give incorrect results if the power is larger than or equal to &h80000000 (two billion and a bit). I have a fix for this so this is temporary.

BigInt_Nrt2 may give incorrect results if the power is 34. I will change the check within the function.

BigInt_Fac, BigInt_Prm and BigInt_Cmb may give incorrect results if N is larger than or equal to &h80000000.

All problems arise from the fact that I do not have a native unsigned 64-bit integer data type in thinBasic. If (if!) I change the internal functions to assembler (in this case I'm talking about BII_mli) this problem will be solved. As stated, I can correct BigInt_Nrt without having to go to assembler, but the three billionth Fibonacci number is off-limits for the time being...

Corrected the bugs in BigInt_Nrt and BigInt_Nrt2 as mentioned above, and two other minor bugs (in the string-to-BigInteger conversion). See attached file.

I'm stopping further development on BigInt in thinBasic. I've begun converting these functions to a thinBasic module in PowerBASIC and right now I'm at the point that I'll have to start porting the internal (BII_) functions. It's half past midnight and I have to go to work in less than eight hours...

As soon as I have something that's testable I'll make a posting over in the new module section.