[Freeciv-Dev] Re: (PR#12834) amortize()
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12834 >
--- Jason Short <jdorje@xxxxxxxxxxxxxxxxxxxxx> wrote:
>
> <URL:
> http://bugs.freeciv.org/Ticket/Display.html?id=12834
> >
>
> Benoit Hudson wrote:
> > <URL:
> http://bugs.freeciv.org/Ticket/Display.html?id=12834
> >
> >
> > On Mon, Apr 18, 2005 at 02:47:03PM -0700, Brian
> Dunstan wrote:
> >
> >><URL:
> http://bugs.freeciv.org/Ticket/Display.html?id=12834
> >
> >>
> >>I noticed that the amortize() function uses a very
> >>clever, but complicated, algorithm.
> >
> >
> > This code is astounding. Why don't we do this
> calculation in
> > floating-point? It would be (with casts to
> doubles made beforehand):
> > double discount = 1.0 - 1.0 /
> ((double)MORT);
> > return benefit * pow(discount, delay);
> > or
> > return (int) (benefit *
> pow(discount,delay) + 0.5);
> > if you want to round.
>
> Ohmigod.
>
> The crazy thing is, I'm sure this is done to be more
> efficient but the
> end result is it makes the calculation O(delay)
> instead of O(log(delay)).
>
> clever, but complicated, algorithm.
This code is astounding. Why don't we do this
calculation in
floating-point? It would be (with casts to doubles
made beforehand):
double discount = 1.0 - 1.0 / ((double)MORT);
return benefit * pow(discount, delay);
or
return (int) (benefit * pow(discount,delay) +
0.5);
if you want to round.
> -jason
Just as an aside, it looks like a lot of the original
code went to great lengths to avoid floating point
calculations. I am not sure if avoiding floating
point math is a goal any more, or not.
__________________________________
Do you Yahoo!?
Plan great trips with Yahoo! Travel: Now over 17,000 guides!
http://travel.yahoo.com/p-travelguide
- [Freeciv-Dev] Re: (PR#12834) amortize(), Jason Short, 2005/04/18
- [Freeciv-Dev] Re: (PR#12834) amortize(), Per I. Mathisen, 2005/04/18
- [Freeciv-Dev] Re: (PR#12834) amortize(), Brian Dunstan, 2005/04/18
- [Freeciv-Dev] Re: (PR#12834) amortize(), Brian Dunstan, 2005/04/18
- [Freeciv-Dev] Re: (PR#12834) amortize(), Jason Short, 2005/04/18
- [Freeciv-Dev] Re: (PR#12834) amortize(), Vasco Alexandre da Silva Costa, 2005/04/18
- [Freeciv-Dev] Re: (PR#12834) amortize(), Benoit Hudson, 2005/04/18
- [Freeciv-Dev] Re: (PR#12834) amortize(), Jason Short, 2005/04/18
- [Freeciv-Dev] Re: (PR#12834) amortize(),
Brian Dunstan <=
- [Freeciv-Dev] Re: (PR#12834) amortize(), Jason Short, 2005/04/18
- [Freeciv-Dev] Re: (PR#12834) amortize(), Vasco Alexandre da Silva Costa, 2005/04/19
|
|