about summary refs log tree commit diff
path: root/src/math/nextafterf.c
diff options
context:
space:
mode:
authorSzabolcs Nagy <nsz@port70.net>2013-09-04 17:36:00 +0000
committerSzabolcs Nagy <nsz@port70.net>2013-09-05 11:30:09 +0000
commit8dba5486288e719ed290cccefcd932ed32756d7c (patch)
tree7e9cac9140e4c2c54e31cd817e95e135833a0deb /src/math/nextafterf.c
parent63b9cc777323488da3474e8bc53e0ac4d3521382 (diff)
downloadmusl-8dba5486288e719ed290cccefcd932ed32756d7c.tar.gz
musl-8dba5486288e719ed290cccefcd932ed32756d7c.tar.xz
musl-8dba5486288e719ed290cccefcd932ed32756d7c.zip
math: cosmetic cleanup (use explicit union instead of fshape and dshape)
Diffstat (limited to 'src/math/nextafterf.c')
-rw-r--r--src/math/nextafterf.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/math/nextafterf.c b/src/math/nextafterf.c
index 22b61dce..75a09f7d 100644
--- a/src/math/nextafterf.c
+++ b/src/math/nextafterf.c
@@ -1,34 +1,30 @@
 #include "libm.h"
 
-#define SIGN 0x80000000
-
 float nextafterf(float x, float y)
 {
-	union fshape ux, uy;
+	union {float f; uint32_t i;} ux={x}, uy={y};
 	uint32_t ax, ay, e;
 
 	if (isnan(x) || isnan(y))
 		return x + y;
-	ux.value = x;
-	uy.value = y;
-	if (ux.bits == uy.bits)
+	if (ux.i == uy.i)
 		return y;
-	ax = ux.bits & ~SIGN;
-	ay = uy.bits & ~SIGN;
+	ax = ux.i & 0x7fffffff;
+	ay = uy.i & 0x7fffffff;
 	if (ax == 0) {
 		if (ay == 0)
 			return y;
-		ux.bits = (uy.bits & SIGN) | 1;
-	} else if (ax > ay || ((ux.bits ^ uy.bits) & SIGN))
-		ux.bits--;
+		ux.i = (uy.i & 0x80000000) | 1;
+	} else if (ax > ay || ((ux.i ^ uy.i) & 0x80000000))
+		ux.i--;
 	else
-		ux.bits++;
-	e = ux.bits & 0x7f800000;
-	/* raise overflow if ux.value is infinite and x is finite */
+		ux.i++;
+	e = ux.i & 0x7f800000;
+	/* raise overflow if ux.f is infinite and x is finite */
 	if (e == 0x7f800000)
 		FORCE_EVAL(x+x);
-	/* raise underflow if ux.value is subnormal or zero */
+	/* raise underflow if ux.f is subnormal or zero */
 	if (e == 0)
-		FORCE_EVAL(x*x + ux.value*ux.value);
-	return ux.value;
+		FORCE_EVAL(x*x + ux.f*ux.f);
+	return ux.f;
 }