Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2002:
[Freeciv-Dev] Re: server/settlers.c cleanup 3
Home

[Freeciv-Dev] Re: server/settlers.c cleanup 3

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Raahul Kumar <raahul_da_man@xxxxxxxxx>
Cc: Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx>, "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>, Raahul Kumar <raahul_da_man@xxxxxxxxx>, Per I Mathisen <per@xxxxxxxxxxx>, freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: server/settlers.c cleanup 3
From: "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>
Date: Tue, 16 Apr 2002 21:34:03 -0400

A quick sample of what can happen ...

ints are only a small portion of the floating point number range. You can
get overflow exceptions faster than you can say boo. Something perhaps
slightly more complicated than this, but you should get the idea, will
bite you as well.

double x = 6/3.0;
int i = 1;

if( x != 2 ) i = i / (x-2);

"C" programmers have a hard time understanding that 2+2=3 is perfectly
correct FP math, and have a difficult time trapping error values in 
code like the above.

Note that the inverse roundoff error on a double is more than will fit 
into an int.

This may or may not pass the condition test depending on the actual value
of x and how the conversion is handled. 

The condition and the arithmetic calculation may or may not give quite 
the same result depending on the exact order of computation and complexity 
of the expressions.

To be blunt, the hassles with this are not worth the trouble of changing
amortize to be correct to the 10th vs 9th decimal place when the results it
returns are seldom even valid or would change game behaviour at the 1st.

My firm recommendation is to drop all efforts to modify the current
amortize, and certainly not use FP anywhere in the code.

Cheers,
RossW
=====

At 03:32 AM 02/04/16 -0700, Raahul Kumar wrote:
>
>--- Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx> wrote:
>> On Sun, 14 Apr 2002, Ross W. Wetmore wrote:
>> 
>> At 05:16 PM 02/04/13 -0700, Raahul Kumar wrote:
>> 
>>I've had a long argument with Raimar about this. Good luck to you Per. I
>> fully agreed with the old patch, and I agree with your current approach as
>>well.
>
>> I think the ridiculous extremes the Freeciv code goes to to avoid floating
>> point is pointless. 
>> > 
>> > Wait until your program dies consistently storing its float value back
into
>> > an int. 
>> 
>> Why does it happen and in what circumstances?
>> 
>> G.
>
>I'm curious about it myself. It's not like that is an insurmountable problem.
>And, to be clear, the current Freeciv code has a few waiting to happen
>overflows. The danger calcs in AI are one obvious choice. 
>
>Aloha,
>RK.
>
>When I was a kid I said to my father one afternoon, "Daddy, will you
>take me to the zoo?" He answered, "If the zoo wants you let them come
>and get you."
>-- Jerry Lewis
>
>__________________________________________________
>Do You Yahoo!?
>Yahoo! Tax Center - online filing with TurboTax
>http://taxes.yahoo.com/




[Prev in Thread] Current Thread [Next in Thread]