[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 3.0.1 release?
From: |
Michael Goffioul |
Subject: |
Re: 3.0.1 release? |
Date: |
Wed, 9 Apr 2008 14:40:25 +0200 |
On Wed, Apr 9, 2008 at 1:51 AM, John W. Eaton <address@hidden> wrote:
> I suppose we could write something like
>
> double ip;
> return modf (x, &ip) == 0.0 ? x : (x > 0 ? floor (x + 0.5) : ceil (x -
> 0.5));
>
> Is there a better (and still portable) way to determine whether a
> double value is an integer?
The following code seems to work fine:
if (x >= 0)
{
double y = floor (x);
if ((x - y) >= 0.5)
y += 1.0;
return y;
}
else
{
double y = ceil (x);
if ((y - x) >= 0.5)
y -= 1.0;
return y;
}
This is taken from gnulib:round.c (I guess it's no problem to grab
some code from
GPL project to put it into another GPL project). Running the test suite does not
seem to return new problems.
Michael.
- Re: 3.0.1 release?, (continued)
- Re: 3.0.1 release?, David Bateman, 2008/04/08
- Re: 3.0.1 release?, Michael Goffioul, 2008/04/08
- RE: 3.0.1 release?, Bateman David-ADB014, 2008/04/08
- Re: 3.0.1 release?, Michael Goffioul, 2008/04/08
- Re: 3.0.1 release?, David Bateman, 2008/04/08
- Re: 3.0.1 release?, Michael Goffioul, 2008/04/08
- Re: 3.0.1 release?, David Bateman, 2008/04/08
- Re: 3.0.1 release?, John W. Eaton, 2008/04/08
- Re: 3.0.1 release?, Michael Goffioul, 2008/04/08
- Re: 3.0.1 release?, John W. Eaton, 2008/04/08
- Re: 3.0.1 release?,
Michael Goffioul <=
- Re: 3.0.1 release?, David Bateman, 2008/04/09
- Re: 3.0.1 release?, Michael Goffioul, 2008/04/09
- Re: 3.0.1 release?, John W. Eaton, 2008/04/09
- Re: 3.0.1 release?, Marco Atzeri, 2008/04/10
- Re: 3.0.1 release?, Shai Ayal, 2008/04/08
- Re: 3.0.1 release?, Thomas Weber, 2008/04/09
Re: 3.0.1 release?, David Bateman, 2008/04/03