math: fix tgamma to raise underflow for large negative values
[oweals/musl.git] / 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                 FORCE_EVAL(x+x);
32         /* raise underflow if ux.value is subnormal or zero */
33         if (e == 0)
34                 FORCE_EVAL(x*x + ux.value*ux.value);
35         return ux.value;
36 }