octave-maintainers
[Top][All Lists]
Advanced

[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.


reply via email to

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