Correct bitwise comparison of 'long double' numbers.
authorBruno Haible <bruno@clisp.org>
Sun, 25 Mar 2007 01:06:39 +0000 (01:06 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 25 Mar 2007 01:06:39 +0000 (01:06 +0000)
ChangeLog
lib/isnan.c
modules/isnan-nolibm
modules/isnanl
modules/isnanl-nolibm

index b7b3388a8401a4bce0b6414993ae3f311f8cc5e5..3409b07c794418a4b63a59d76e1184215c17f8f0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2007-03-24  Bruno Haible  <bruno@clisp.org>
+
+       * lib/float+.h: New file.
+       * lib/isnan.c: Include float+.h.
+       (SIZE): New macro.
+       (FUNC): Compare only SIZE bytes of the value.
+       * lib/vasnprintf.c: Include float+.h.
+       (VASNPRINTF): When comparing agains +0.0L or +0.0, compare only
+       SIZEOF_LDBL or SIZEOF_DBL bytes.
+       * modules/isnan-nolibm (Files): Add lib/float+.h.
+       * modules/isnanl-nolibm (Files): Add lib/float+.h.
+       * modules/isnanl (Files): Add lib/float+.h.
+       * modules/vasnprintf (Files): Add lib/float+.h.
+       
 2007-03-24  Bruno Haible  <bruno@clisp.org>
 
        * lib/vasnprintf.c [!HAVE_LONG_DOUBLE]: Include printf-frexp.h. Don't
index beeb98a50646190d16930b3e25477128b8b2aa36..9b6ec87b465f692c0d6af2e3f9016800484a5fc5 100644 (file)
@@ -22,6 +22,8 @@
 #include <float.h>
 #include <string.h>
 
+#include "float+.h"
+
 #ifdef USE_LONG_DOUBLE
 # define FUNC rpl_isnanl
 # define DOUBLE long double
@@ -32,6 +34,7 @@
 #  define EXPBIT0_WORD LDBL_EXPBIT0_WORD
 #  define EXPBIT0_BIT LDBL_EXPBIT0_BIT
 # endif
+# define SIZE SIZEOF_LDBL
 # define L_(literal) literal##L
 #else
 # define FUNC rpl_isnan
@@ -43,6 +46,7 @@
 #  define EXPBIT0_WORD DBL_EXPBIT0_WORD
 #  define EXPBIT0_BIT DBL_EXPBIT0_BIT
 # endif
+# define SIZE SIZEOF_DBL
 # define L_(literal) literal
 #endif
 
@@ -79,8 +83,8 @@ FUNC (DOUBLE x)
     if (((m.word[EXPBIT0_WORD] ^ nan.word[EXPBIT0_WORD])
         & (EXP_MASK << EXPBIT0_BIT))
        == 0)
-      return (memcmp (&m.value, &plus_inf, sizeof (DOUBLE)) != 0
-             && memcmp (&m.value, &minus_inf, sizeof (DOUBLE)) != 0);
+      return (memcmp (&m.value, &plus_inf, SIZE) != 0
+             && memcmp (&m.value, &minus_inf, SIZE) != 0);
     else
       return 0;
   }
index e251cec9981fb259cb0ebd2ec647e09dc0e15f16..43adb609f95c2bf9b09c53e8885578252fd3608a 100644 (file)
@@ -4,6 +4,7 @@ isnan() function: test for NaN, without requiring libm.
 Files:
 lib/isnan.h
 lib/isnan.c
+lib/float+.h
 m4/isnan.m4
 
 Depends-on:
index cc171171afadcd7b25c5a1274ea6bb78ec929f5f..7e60555745c4b3512a9692755e0eb317d92613f0 100644 (file)
@@ -5,6 +5,7 @@ Files:
 lib/isnanl.h
 lib/isnanl.c
 lib/isnan.c
+lib/float+.h
 m4/isnanl.m4
 m4/longdouble.m4
 
index 5cdb2cb6b116eb283e2614b88f9770ff413b52e4..d45825a0d09e8f97d7550f9c478c490e140a27d3 100644 (file)
@@ -5,6 +5,7 @@ Files:
 lib/isnanl-nolibm.h
 lib/isnanl.c
 lib/isnan.c
+lib/float+.h
 m4/isnanl.m4
 m4/longdouble.m4