mozy contest: problem 1 PHP solution

Levi Pearson levi at
Mon Nov 6 13:20:34 MST 2006

On Nov 6, 2006, at 1:06 PM, Bryan Sant wrote:

> On 11/6/06, Levi Pearson <levi at> wrote:
>> When programming in C, C++, or Java (among others), standard numeric

> No, in java you use the BigInteger or BigDecimal class to deal with
> big numbers.  These are arbitrary-precision numbers.  They will grow
> until you run out of memory (or address space -- 32-bit systems blow).

Did you not read what I wrote?  You must be pretty defensive about  
Java to feel the need to defend it against accusations I did not make.

I specifically said 'standard numeric variables' have this problem  
and noted later on that there are arbitrary precision libraries you  
can use if you need to.  The fact is, the standard numeric types in  
Java are just like those in C, C++, and even OCaml.  They overflow  
and wrap around.  If you don't anticipate this and explicitly use  
arbitrary-precision numbers (or some check for overflow, at least)  
where necessary, your program WILL fail for sufficiently large inputs.

Having this kind of data type is a good thing for efficiency, but  
treating members of machine-length integers like mathematical  
integers is a recipe for disaster when overflows are possible.   
Common Lisp errs on the side of producing correct results in the case  
of machine integer overflows at the price of efficiency, though you  
can force it to always use a machine integer if you wish.  The other  
languages I listed err on the side of default efficiency and possible  
overflow danger.  These are, as I said, semantic properties of the  
language and I made no value judgement regarding which was better.


More information about the PLUG mailing list