Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] Re: (PR#12834) amortize()
Home

[Freeciv-Dev] Re: (PR#12834) amortize()

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: bdunstan149@xxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#12834) amortize()
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Tue, 19 Apr 2005 18:26:09 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12834 >

On Mon, 18 Apr 2005, Jason Short 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.
>
> We probably do want to round but the value could be negative.  I thought
> there was a round() function but my gcc claims otherwise.
>
> Anyway, here's a patch.

round() is C99. rint() is BSD.

I used to use this for round:

int myround(double x)
{
  return (int) floor(x + 0.5);
}

---
Vasco Alexandre da Silva Costa @ Instituto Superior Tecnico, Lisboa







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