[PATCH] fmin/fmax behaviour on NaNs
Stephen Huw CLARKE
stephen.clarke@st.com
Mon Aug 8 16:31:00 GMT 2005
The implementations of fmax and fmin in newlib/libm/common
appear not to conform to section F.9.9.2/3 of the C99 spec.
That spec. states:
"If just one argument is a NaN, the fmax functions return the
other argument (if both arguments are NaNs, the functions
return a NaN)."
The following patch fixes this.
Steve.
--- newlib/libm/common/orig-sf_fmax.c 2002-06-07 22:59:56.000000000 +0100
+++ newlib/libm/common/sf_fmax.c 2005-08-08 17:13:08.000000000 +0100
@@ -15,9 +15,9 @@
#endif
{
if (__fpclassifyf(x) == FP_NAN)
- return x;
- if (__fpclassifyf(y) == FP_NAN)
return y;
+ if (__fpclassifyf(y) == FP_NAN)
+ return x;
return x > y ? x : y;
}
--- newlib/libm/common/orig-s_fmax.c 2002-06-07 22:59:56.000000000 +0100
+++ newlib/libm/common/s_fmax.c 2005-08-08 17:07:04.000000000 +0100
@@ -17,9 +17,9 @@
#endif
{
if (__fpclassifyd(x) == FP_NAN)
- return x;
- if (__fpclassifyd(y) == FP_NAN)
return y;
+ if (__fpclassifyd(y) == FP_NAN)
+ return x;
return x > y ? x : y;
}
--- newlib/libm/common/orig-sf_fmin.c 2002-06-07 22:59:56.000000000 +0100
+++ newlib/libm/common/sf_fmin.c 2005-08-08 17:24:57.000000000 +0100
@@ -15,9 +15,9 @@
#endif
{
if (__fpclassifyf(x) == FP_NAN)
- return x;
- if (__fpclassifyf(y) == FP_NAN)
return y;
+ if (__fpclassifyf(y) == FP_NAN)
+ return x;
return x < y ? x : y;
}
--- newlib/libm/common/orig-s_fmin.c 2002-06-07 22:59:56.000000000 +0100
+++ newlib/libm/common/s_fmin.c 2005-08-08 17:07:16.000000000 +0100
@@ -17,9 +17,9 @@
#endif
{
if (__fpclassifyd(x) == FP_NAN)
- return x;
- if (__fpclassifyd(y) == FP_NAN)
return y;
+ if (__fpclassifyd(y) == FP_NAN)
+ return x;
return x < y ? x : y;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fmax.patch
Type: application/octet-stream
Size: 628 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20050808/f45baf6a/attachment.obj>
More information about the Newlib
mailing list