Plan 9 from Bell Labs’s /usr/web/sources/contrib/yk/dist/9legacy/applied/libc-pow-nan.diff

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


--- /sys/src/ape/lib/ap/math/pow.c
+++ /sys/src/ape/lib/ap/math/pow.c
@@ -12,6 +12,14 @@ pow(double x, double y) /* return x ^ y (exponentiation) */
 	if(y == 0.0)
 		return 1.0;
 
+	/* prevent infinite loop */
+	if(isNaN(x) || isNaN(y))
+		return NaN();
+	if(isInf(x, 0))
+		return x;
+	if(isInf(y, 0))
+		return x == 0 || x == 1? x: y;
+
 	flip = 0;
 	if(y < 0.){
 		y = -y;
--- /sys/src/libc/port/pow.c
+++ /sys/src/libc/port/pow.c
@@ -11,6 +11,14 @@ pow(double x, double y) /* return x ^ y (exponentiation) */
 	if(y == 0.0)
 		return 1.0;
 
+	/* prevent infinite loop */
+	if(isNaN(x) || isNaN(y))
+		return NaN();
+	if(isInf(x, 0))
+		return x;
+	if(isInf(y, 0))
+		return x == 0 || x == 1? x: y;
+
 	flip = 0;
 	if(y < 0.){
 		y = -y;

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].