Built-in, unlimited precision, big integer arithmetik

Started by Lutz, April 12, 2013, 08:33:59 AM

Previous topic - Next topic

Lutz

#15
At the moment bigint only allows wellformed integers when the argument is a string. Floats must be passed as floats not in a string.



> (bigint 3.14)
3L
> (bigint 123e20)
12300000000000000000000L
> (bigint 1234567)
1234567L
> (bigint "1234567890")
1234567890L
> (bigint "1234567890123456789012345")
1234567890123456789012345L
>


thanks Kosh for reporting this.



see also here: http://www.newlisp.org/downloads/development/inprogress/">http://www.newlisp.org/downloads/develo ... nprogress/">http://www.newlisp.org/downloads/development/inprogress/

kosh

#16
Thanks, Lutz.



I found another problem.

division operator (/) with bigint works strangely.


> (/ 123000000000L 1)
123L
> (/ 12300000000000000000000000000L 1)
12300000000000000001L
> (/ 123000000000000000000000000000L 1)
123000000001^[,),(-*,(L


regards.

Lutz

#17
Thanks Kosh.



I wish that would have been detected during the three weeks of the development version 10.4.8.



I have a qa-specific-tests/qa-bigint and qa-specific-tests/qa-factorfibo running millions of operations but not testing for trailing/embedded 0 bigint digits in division.



ps: please keep on testing

Lutz

#18
all fixed now here: http://www.newlisp.org/downloads/development/inprogress/">http://www.newlisp.org/downloads/develo ... nprogress/">http://www.newlisp.org/downloads/development/inprogress/



I will do a development release on Monday/Tuesday. Although 10.5.1 will be identical to 10.5.0 except for big integer division fixes, I want to wait a little before doing a Maintenance Release 10.5.2. Just want to be sure nothing else pops up in the big integer area.



The whole thing was pretty intense to develop it. Most of the code, you see on the net, doesn't have good performance, and it took the whole April and part of May to get speed, trying out various approaches. The division algorithm is the old grade school algorithm, but tweaked for base 1000,000,000 and using float arithmetik on bigint digits. Others have done this before,  but I couldn't find anything appropriate ready-made.



The code designed in 10.5.0 didn't handle certain edge cases, which arise when doing mixed float and integer arithmetik. That is why Kosh discovered problems with trailing zeros. Turns out that embedded and base 10^9 aligned zeros didn't work as well and trailing zero's in results where also suppressed.



I hope everything is fine now. Whoever understands something about big integer arithmetic, please test!



My own test routines are in newlisp-10.5.1/qa-specific-tests/qa-bigint