[Aldor-l] Bigint bug(!)

Ralf Hemmecke ralf at hemmecke.de
Fri Aug 15 20:10:08 EDT 2008


On 08/16/2008 01:51 AM, pip88nl at gmail.com wrote:
>> Could you next time give the full path to the file where the problem 
>> occurs? Thanks.
> 
> Okay :) didn't think of that.
> 
>> My suggestion: remove the bigint code completely and replace it with 
>> GMP. Would that be a problem? Wouldn't that save your valuable debugging 
>> time?
> 
> Yes, GMP is GPL licenced. There have been legal issues with this before,
> I don't remember where.

Strange. http://gmplib.org/ links to LGPL3. So why would there be a 
problem with APL2? But let's forget these license issues... as far as I 
can see there has already been some attempt to put GMP to the compiler.

I actually not only want linking against GMP, but even an extension of 
the Aldor bignum interface. For example, there is an algorithm that is 
faster than usual division if it is known in advance that one integer g 
divides another one a. Such cases are not necessarily execptional. Take, 
for example.

   g=gcd(a,b)
   a=a/g

The last bigint division could be done in about half the time of a 
normal division. That is implemented in GMP. Lookf for papers of Tudor 
Jebelean at http://gmplib.org/manual/References.html .

>> Good detective work. I wonder what a Aldor program might be that hits 
>> this bug.

> Any program that uses -2147483648, probably.

Not quite. But there is probably another bug of similar type in the 
MachineInteger implementation of the library. See 'print' function in
lib/aldor/src/arith/sal_itools.as.

The program below gives the following output.

----
min$MachineInteger = -
min/2              = -1073741824
min(long)(Integer) = -2147483648
----

Ralf

---BEGIN aaa.as
#include "aldor"
#include "aldorio"
mi: MachineInteger := min;
stdout << "min$MachineInteger = " << mi << newline;
mi := shift(mi, -1);
stdout << "min/2              = " << mi << newline;
i: Integer := mi :: Integer;
k: Integer := i*2;
stdout << "min(long)(Integer) = " << k << newline;
---END aaa.as



More information about the Aldor-l mailing list