lib/msun: Replaced pattern to force exception in _num families

Replaced the old pattern of using a ternary to force addition
(raising exceptions for sNaN's) with a new one using a volatile
variable. The _mag_num family was already implemented with this pattern

PR:		294719
Reviewed by:	fuz, kargl
MFC after:	1 month
This commit is contained in:
Jesús Blázquez
2026-04-27 16:43:41 +00:00
committed by Robert Clausecker
parent f62d826a6f
commit 7c20e15592
6 changed files with 60 additions and 24 deletions
+10 -4
View File
@@ -53,12 +53,18 @@ fmaximum_num(double x, double y)
nan_y = isnan(y);
if (nan_x || nan_y) {
/* These ternary conditionals force (x+y), so that sNaN's raise exceptions */
/* If both are NaN, adding returns qNaN */
if (nan_x && nan_y)
return (x + y);
return (x + y);
/* force_except makes sure sNaN's raise exceptions */
volatile double force_except = x + y;
force_except;
if (nan_x)
return ((x + y) != 0.0 ? y : y);
return ((x + y) != 0.0 ? x : x);
return (y);
else
return (x);
}
/* Handle comparisons of signed zeroes. */
+10 -4
View File
@@ -52,12 +52,18 @@ fmaximum_numf(float x, float y)
nan_y = isnan(y);
if (nan_x || nan_y) {
/* These ternary conditionals force (x+y), so that sNaN's raise exceptions */
/* If both are NaN, adding returns qNaN */
if (nan_x && nan_y)
return (x + y);
return (x + y);
/* force_except makes sure sNaN's raise exceptions */
volatile float force_except = x + y;
force_except;
if (nan_x)
return ((x + y) != 0.0 ? y : y);
return ((x + y) != 0.0 ? x : x);
return (y);
else
return (x);
}
/* Handle comparisons of signed zeroes. */
+10 -4
View File
@@ -47,12 +47,18 @@ fmaximum_numl(long double x, long double y)
nan_y = isnan(y);
if (nan_x || nan_y) {
/* These ternary conditionals force (x+y), so that sNaN's raise exceptions */
/* If both are NaN, adding returns qNaN */
if (nan_x && nan_y)
return (x + y);
return (x + y);
/* force_except makes sure sNaN's raise exceptions */
volatile long double force_except = x + y;
force_except;
if (nan_x)
return ((x + y) != 0.0 ? y : y);
return ((x + y) != 0.0 ? x : x);
return (y);
else
return (x);
}
/* Handle comparisons of signed zeroes. */
+10 -4
View File
@@ -53,12 +53,18 @@ fminimum_num(double x, double y)
nan_y = isnan(y);
if (nan_x || nan_y) {
/* These ternary conditionals force (x+y), so that sNaN's raise exceptions */
/* If both are NaN, adding returns qNaN */
if (nan_x && nan_y)
return (x + y);
return (x + y);
/* force_except makes sure sNaN's raise exceptions */
volatile double force_except = x + y;
force_except;
if (nan_x)
return ((x + y) != 0.0 ? y : y);
return ((x + y) != 0.0 ? x : x);
return (y);
else
return (x);
}
/* Handle comparisons of signed zeroes. */
+10 -4
View File
@@ -52,12 +52,18 @@ fminimum_numf(float x, float y)
nan_y = isnan(y);
if (nan_x || nan_y) {
/* These ternary conditionals force (x+y), so that sNaN's raise exceptions */
/* If both are NaN, adding returns qNaN */
if (nan_x && nan_y)
return (x + y);
return (x + y);
/* force_except makes sure sNaN's raise exceptions */
volatile float force_except = x + y;
force_except;
if (nan_x)
return ((x + y) != 0.0 ? y : y);
return ((x + y) != 0.0 ? x : x);
return (y);
else
return (x);
}
/* Handle comparisons of signed zeroes. */
+10 -4
View File
@@ -47,12 +47,18 @@ fminimum_numl(long double x, long double y)
nan_y = isnan(y);
if (nan_x || nan_y) {
/* These ternary conditionals force (x+y), so that sNaN's raise exceptions */
/* If both are NaN, adding returns qNaN */
if (nan_x && nan_y)
return (x + y);
return (x + y);
/* force_except makes sure sNaN's raise exceptions */
volatile long double force_except = x + y;
force_except;
if (nan_x)
return ((x + y) != 0.0 ? y : y);
return ((x + y) != 0.0 ? x : x);
return (y);
else
return (x);
}
/* Handle comparisons of signed zeroes. */