3.0.1 release?
Michael Goffioul
michael.goffioul at gmail.com
Wed Apr 9 07:40:25 CDT 2008
On Wed, Apr 9, 2008 at 1:51 AM, John W. Eaton <jwe at bevo.che.wisc.edu> 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.
More information about the Octave-maintainers
mailing list