Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc fix behavior in case of +-Inf or NaN input: return ...



details:   https://anonhg.NetBSD.org/src/rev/10e97d844f89
branches:  trunk
changeset: 751187:10e97d844f89
user:      drochner <drochner%NetBSD.org@localhost>
date:      Wed Jan 27 14:10:41 2010 +0000

description:
fix behavior in case of +-Inf or NaN input: return the proper
values and set *iptr
(This code is only used under non-default build options, and on m68k.)

diffstat:

 lib/libc/compat/gen/compat_modf_ieee754.c |  10 ++++++----
 lib/libc/gen/modf_ieee754.c               |  10 ++++++----
 2 files changed, 12 insertions(+), 8 deletions(-)

diffs (52 lines):

diff -r cb5e60e13c43 -r 10e97d844f89 lib/libc/compat/gen/compat_modf_ieee754.c
--- a/lib/libc/compat/gen/compat_modf_ieee754.c Wed Jan 27 14:07:41 2010 +0000
+++ b/lib/libc/compat/gen/compat_modf_ieee754.c Wed Jan 27 14:10:41 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_modf_ieee754.c,v 1.2 2008/09/28 15:19:09 christos Exp $ */
+/* $NetBSD: compat_modf_ieee754.c,v 1.3 2010/01/27 14:10:41 drochner Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
@@ -49,11 +49,13 @@
        u_int64_t frac;
 
        /*
-        * If input is Inf or NaN, return it and leave i alone.
+        * If input is +/-Inf or NaN, return +/-0 or NaN.
         */
        u.dblu_d = val;
-       if (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN)
-               return (u.dblu_d);
+       if (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN) {
+               *iptr = u.dblu_d;
+               return (0.0 / u.dblu_d);
+       }
 
        /*
         * If input can't have a fractional part, return
diff -r cb5e60e13c43 -r 10e97d844f89 lib/libc/gen/modf_ieee754.c
--- a/lib/libc/gen/modf_ieee754.c       Wed Jan 27 14:07:41 2010 +0000
+++ b/lib/libc/gen/modf_ieee754.c       Wed Jan 27 14:10:41 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: modf_ieee754.c,v 1.2 2003/10/27 00:05:46 kleink Exp $ */
+/* $NetBSD: modf_ieee754.c,v 1.3 2010/01/27 14:10:41 drochner Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
@@ -46,11 +46,13 @@
        u_int64_t frac;
 
        /*
-        * If input is Inf or NaN, return it and leave i alone.
+        * If input is +/-Inf or NaN, return +/-0 or NaN.
         */
        u.dblu_d = val;
-       if (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN)
-               return (u.dblu_d);
+       if (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN) {
+               *iptr = u.dblu_d;
+               return (0.0 / u.dblu_d);
+       }
 
        /*
         * If input can't have a fractional part, return



Home | Main Index | Thread Index | Old Index