Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.    nexttowardf.c
  3.    Contributed by Danny Smith <dannysmith@users.sourceforge.net>
  4.    No copyright claimed, absolutely no warranties.
  5.  
  6.    2005-05-10
  7. */
  8.  
  9. #include <math.h>
  10.  
  11. float
  12. nexttowardf (float x, long double y)
  13. {
  14.   union
  15.   {
  16.     float f;
  17.     unsigned int i;
  18.   } u;
  19.  
  20.   long double xx = x;
  21.  
  22.   if (isnan (y) || isnan (x))
  23.     return x + y;
  24.   if (xx == y )
  25.      /* nextafter (0.0, -O.0) should return -0.0.  */
  26.      return y;
  27.   u.f = x;
  28.   if (x == 0.0F)
  29.     {
  30.       u.i = 1;
  31.       return y > 0.0L ? u.f : -u.f;
  32.     }
  33.   if (((x > 0.0F) ^ (y > xx)) == 0)
  34.     u.i++;
  35.   else
  36.     u.i--;
  37.   return u.f;
  38. }
  39.