mirror of
https://github.com/fluencelabs/musl
synced 2025-05-29 07:31:53 +00:00
updated nextafter* to use FORCE_EVAL, it can be used in many other places in the math code to improve readability.
37 lines
647 B
C
37 lines
647 B
C
#include "libm.h"
|
|
|
|
float nexttowardf(float x, long double y)
|
|
{
|
|
union fshape ux;
|
|
uint32_t e;
|
|
|
|
if (isnan(x) || isnan(y))
|
|
return x + y;
|
|
if (x == y)
|
|
return y;
|
|
ux.value = x;
|
|
if (x == 0) {
|
|
ux.bits = 1;
|
|
if (signbit(y))
|
|
ux.bits |= 0x80000000;
|
|
} else if (x < y) {
|
|
if (signbit(x))
|
|
ux.bits--;
|
|
else
|
|
ux.bits++;
|
|
} else {
|
|
if (signbit(x))
|
|
ux.bits++;
|
|
else
|
|
ux.bits--;
|
|
}
|
|
e = ux.bits & 0x7f800000;
|
|
/* raise overflow if ux.value is infinite and x is finite */
|
|
if (e == 0x7f800000)
|
|
return x + x;
|
|
/* raise underflow if ux.value is subnormal or zero */
|
|
if (e == 0)
|
|
FORCE_EVAL(x*x + ux.value*ux.value);
|
|
return ux.value;
|
|
}
|