[PATCH] fmin/fmax behaviour on NaNs
Jeff Johnston
jjohnstn@redhat.com
Wed Aug 10 21:03:00 GMT 2005
Patch checked in. Thanks.
-- Jeff J.
Stephen Huw CLARKE wrote:
> 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;
> }
More information about the Newlib
mailing list