Ver código fonte

updates to s_round.c from FreeBSD

Jeff Bezanson 11 anos atrás
pai
commit
9ca11f20c6
1 arquivos alterados com 7 adições e 5 exclusões
  1. 7 5
      src/s_round.c

+ 7 - 5
src/s_round.c

@@ -34,19 +34,21 @@ DLLEXPORT double
 round(double x)
 {
 	double t;
+	uint32_t hx;
 
-	if (!isfinite(x))
-		return (x);
+	GET_HIGH_WORD(hx, x);
+	if ((hx & 0x7fffffff) == 0x7ff00000)
+		return (x + x);
 
-	if (x >= 0.0) {
+	if (!(hx & 0x80000000)) {
 		t = floor(x);
 		if (t - x <= -0.5)
-			t += 1.0;
+			t += 1;
 		return (t);
 	} else {
 		t = floor(-x);
 		if (t + x <= -0.5)
-			t += 1.0;
+			t += 1;
 		return (-t);
 	}
 }