master
 1/**
 2 * This file has no copyright assigned and is placed in the Public Domain.
 3 * This file is part of the mingw-w64 runtime package.
 4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
 5 */
 6/*
 7   nexttowardf.c
 8   Contributed by Danny Smith <dannysmith@users.sourceforge.net>
 9   No copyright claimed, absolutely no warranties.
10
11   2005-05-10
12*/
13
14#include <math.h>
15
16float
17nexttowardf (float x, long double y)
18{
19  union
20  {
21    float f;
22    unsigned int i;
23  } u;
24
25  long double xx = x;
26
27  if (isnan (y) || isnan (x))
28    return x + y;
29  if (xx == y )
30     /* nextafter (0.0, -O.0) should return -0.0.  */
31     return y;
32  u.f = x; 
33  if (x == 0.0F)
34    {
35      u.i = 1;
36      return y > 0.0L ? u.f : -u.f;
37    }
38  if (((x > 0.0F) ^ (y > xx)) == 0)
39    u.i++;
40  else
41    u.i--;
42  return u.f;
43}