1
0
Эх сурвалжийг харах

math: fix pow(+-0,-inf) not to raise divbyzero flag

this reverts the commit f29fea00b5bc72d4b8abccba2bb1e312684d1fce
which was based on a bug in C99 and POSIX and did not match IEEE-754
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1515.pdf
Szabolcs Nagy 10 жил өмнө
parent
commit
cb5c057c87
3 өөрчлөгдсөн 3 нэмэгдсэн , 3 устгасан
  1. 1 1
      src/math/pow.c
  2. 1 1
      src/math/powf.c
  3. 1 1
      src/math/powl.c

+ 1 - 1
src/math/pow.c

@@ -143,7 +143,7 @@ double pow(double x, double y)
 				return 1.0;
 			else if (ix >= 0x3ff00000) /* (|x|>1)**+-inf = inf,0 */
 				return hy >= 0 ? y : 0.0;
-			else if ((ix|lx) != 0)     /* (|x|<1)**+-inf = 0,inf if x!=0 */
+			else                       /* (|x|<1)**+-inf = 0,inf */
 				return hy >= 0 ? 0.0 : -y;
 		}
 		if (iy == 0x3ff00000) {    /* y is +-1 */

+ 1 - 1
src/math/powf.c

@@ -90,7 +90,7 @@ float powf(float x, float y)
 			return 1.0f;
 		else if (ix > 0x3f800000)  /* (|x|>1)**+-inf = inf,0 */
 			return hy >= 0 ? y : 0.0f;
-		else if (ix != 0)          /* (|x|<1)**+-inf = 0,inf if x!=0 */
+		else                       /* (|x|<1)**+-inf = 0,inf */
 			return hy >= 0 ? 0.0f: -y;
 	}
 	if (iy == 0x3f800000)    /* y is +-1 */

+ 1 - 1
src/math/powl.c

@@ -227,7 +227,7 @@ long double powl(long double x, long double y)
 	if (y <= -LDBL_MAX) {
 		if (x > 1.0 || x < -1.0)
 			return 0.0;
-		if (x != 0.0)
+		if (x != 0.0 || y == -INFINITY)
 			return INFINITY;
 	}
 	if (x >= LDBL_MAX) {