e8e6f67641ae672f9534f9dbe95b01f29f2ed53a
[musl] / src / math / nexttowardf.c
1 #include "libm.h"
2
3 float nexttowardf(float x, long double y)
4 {
5         union fshape ux;
6         uint32_t e;
7
8         if (isnan(x) || isnan(y))
9                 return x + y;
10         if (x == y)
11                 return y;
12         ux.value = x;
13         if (x == 0) {
14                 ux.bits = 1;
15                 if (signbit(y))
16                         ux.bits |= 0x80000000;
17         } else if (x < y) {
18                 if (signbit(x))
19                         ux.bits--;
20                 else
21                         ux.bits++;
22         } else {
23                 if (signbit(x))
24                         ux.bits++;
25                 else
26                         ux.bits--;
27         }
28         e = ux.bits & 0x7f800000;
29         /* raise overflow if ux.value is infinite and x is finite */
30         if (e == 0x7f800000)
31                 return x + x;
32         /* raise underflow if ux.value is subnormal or zero */
33         if (e == 0) {
34                 volatile float z;
35                 z = x*x + ux.value*ux.value;
36         }
37         return ux.value;
38 }