[Shootout-list] Re: sumcol - when the correct answer is wrong :-)

Brian Hurt bhurt@spnz.org
Tue, 21 Sep 2004 16:13:41 -0500 (CDT)


On Tue, 21 Sep 2004, Brent Fulgham wrote:

> I disagree.  I don't think it is reasonable behavior
> to allow integer overlow, unless the developer
> explicitely codes to allow this behavior.  Silently
> handling a catastrophic condition like this is why
> cancer patients receive overdoses of radiation,
> satellites crash into planets, and corporate loan
> balances turn into "credit" values.

This is a statement of opinion about what a language should do.  Wether 
it's "correct" or not, several languages *BY DESIGN* do not do this.  
Including C and C++.

If it's a test to see how the language handles big integers, that's one 
thing.  But I comment that the "correctness" attributes of the languages 
are beyond the scope of the project as I understand it.  If we're going to 
get into correctness arguments, let's bring up static vr.s dynamic typing.

By the way, Arianne 5's problem was as much due to the fact that it 
*detected* the overflow (and threw an exception) as it was to the fact 
that the overflow existed in the first place.  And it overflowed a 16-bit 
counter- much easier than overflowing a 30 or 32 bit counter.

> 
> > Unless you're testing the performance of big ints,
> > I'd recommend no test require an integer larger 
> > than +/- 2^30 to be represented.
> 
> Most tests are confined to 32-bit values.  However,
> because modern systems are so fast we can't capture
> data at a fine enough resolution on certain tests
> without resorting to very large values.

Some languages (Ocaml) steal a bit from integers as a tag bit.  This means 
that they use 31-bit signed integers, and thus can't represent numbers 
larger than 2^30 on 32-bit machines.

As for the timing constraints, there are two solutions.  One is to do more 
work per iteration.  2^30 clock cycles is the better part of a second even 
on the fastest CPUs these days.  Or, two, run the test multiple times.

-- 
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
                                - Gene Spafford 
Brian