[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
long double vs. double
From: |
Bruno Haible |
Subject: |
long double vs. double |
Date: |
Sun, 9 Oct 2011 11:30:52 +0200 |
User-agent: |
KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; ) |
On MSVC 9, some tests fail to compile because they assume that
'long double' has an 80-bit representation with a 64-bit mantissa.
But on this platform - and, it turns out, also on Linux/HPPA, Minix,
AIX - 'long double' and 'double' have the same size and same
representation.
2011-10-09 Bruno Haible <address@hidden>
isfinite, isinf, isnan tests: Avoid syntax error on MSVC 9.
* m4/math_h.m4 (gl_LONG_DOUBLE_VS_DOUBLE): New macro.
* modules/isfinite-tests (configure.ac): Require
gl_LONG_DOUBLE_VS_DOUBLE.
* modules/isinf-tests (configure.ac): Likewise.
* modules/isnan-tests (configure.ac): Likewise.
* modules/isnanl-tests (configure.ac): Likewise.
* modules/isnanl-nolibm-tests (configure.ac): Likewise.
* tests/test-isfinite.c (test_isfinitel): Avoid 80-bit long double
tests on platforms where 'long double' is the same as 'double'.
* tests/test-isinf.c (test_isinfl): Likewise.
* tests/test-isnan.c (test_long_double): Likewise.
* tests/test-isnanl.h (main): Likewise.
--- m4/math_h.m4.orig Sun Oct 9 11:21:59 2011
+++ m4/math_h.m4 Sun Oct 9 11:16:54 2011
@@ -1,4 +1,4 @@
-# math_h.m4 serial 46
+# math_h.m4 serial 47
dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -188,3 +188,34 @@
REPLACE_TRUNCF=0; AC_SUBST([REPLACE_TRUNCF])
REPLACE_TRUNCL=0; AC_SUBST([REPLACE_TRUNCL])
])
+
+# gl_LONG_DOUBLE_VS_DOUBLE
+# determines whether 'long double' and 'double' have the same representation.
+# Sets variable HAVE_SAME_LONG_DOUBLE_AS_DOUBLE to 0 or 1, and defines
+# HAVE_SAME_LONG_DOUBLE_AS_DOUBLE accordingly.
+# The currently known platforms where this is the case are:
+# Linux/HPPA, Minix 3.1.8, AIX 5, AIX 6 and 7 with xlc, MSVC 9.
+AC_DEFUN([gl_LONG_DOUBLE_VS_DOUBLE],
+[
+ AC_CACHE_CHECK([whether long double and double are the same],
+ [gl_cv_long_double_equals_double],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([[#include <float.h>]],
+ [[typedef int check[sizeof (long double) == sizeof (double)
+ && LDBL_MANT_DIG == DBL_MANT_DIG
+ && LDBL_MAX_EXP == DBL_MAX_EXP
+ && LDBL_MIN_EXP == DBL_MIN_EXP
+ ? 1 : -1];
+ ]])],
+ [gl_cv_long_double_equals_double=yes],
+ [gl_cv_long_double_equals_double=no])
+ ])
+ if test $gl_cv_long_double_equals_double = yes; then
+ AC_DEFINE([HAVE_SAME_LONG_DOUBLE_AS_DOUBLE], [1],
+ [Define to 1 if 'long double' and 'double' have the same
representation.])
+ HAVE_SAME_LONG_DOUBLE_AS_DOUBLE=1
+ else
+ HAVE_SAME_LONG_DOUBLE_AS_DOUBLE=0
+ fi
+ AC_SUBST([HAVE_SAME_LONG_DOUBLE_AS_DOUBLE])
+])
--- modules/isfinite-tests.orig Sun Oct 9 11:21:59 2011
+++ modules/isfinite-tests Sun Oct 9 10:50:43 2011
@@ -10,6 +10,7 @@
gl_FLOAT_EXPONENT_LOCATION
gl_DOUBLE_EXPONENT_LOCATION
gl_LONG_DOUBLE_EXPONENT_LOCATION
+AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
Makefile.am:
TESTS += test-isfinite
--- modules/isinf-tests.orig Sun Oct 9 11:21:59 2011
+++ modules/isinf-tests Sun Oct 9 10:50:43 2011
@@ -13,6 +13,7 @@
gl_FLOAT_EXPONENT_LOCATION
gl_DOUBLE_EXPONENT_LOCATION
gl_LONG_DOUBLE_EXPONENT_LOCATION
+AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
Makefile.am:
TESTS += test-isinf
--- modules/isnan-tests.orig Sun Oct 9 11:21:59 2011
+++ modules/isnan-tests Sun Oct 9 10:50:43 2011
@@ -12,6 +12,7 @@
gl_FLOAT_EXPONENT_LOCATION
gl_DOUBLE_EXPONENT_LOCATION
gl_LONG_DOUBLE_EXPONENT_LOCATION
+AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
Makefile.am:
TESTS += test-isnan
--- modules/isnanl-nolibm-tests.orig Sun Oct 9 11:21:59 2011
+++ modules/isnanl-nolibm-tests Sun Oct 9 10:50:43 2011
@@ -11,6 +11,7 @@
configure.ac:
gl_LONG_DOUBLE_EXPONENT_LOCATION
+AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
Makefile.am:
TESTS += test-isnanl-nolibm
--- modules/isnanl-tests.orig Sun Oct 9 11:21:59 2011
+++ modules/isnanl-tests Sun Oct 9 10:50:43 2011
@@ -11,6 +11,7 @@
configure.ac:
gl_LONG_DOUBLE_EXPONENT_LOCATION
+AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
Makefile.am:
TESTS += test-isnanl
--- tests/test-isfinite.c.orig Sun Oct 9 11:21:59 2011
+++ tests/test-isfinite.c Sun Oct 9 10:28:17 2011
@@ -166,7 +166,7 @@
}
#endif
-#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined
__amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined
_M_IX86 || defined _X86_))
+#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined
__amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined
_M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
/* Representation of an 80-bit 'long double' as an initializer for a sequence
of 'unsigned int' words. */
# ifdef WORDS_BIGENDIAN
--- tests/test-isinf.c.orig Sun Oct 9 11:21:59 2011
+++ tests/test-isinf.c Sun Oct 9 10:28:18 2011
@@ -172,7 +172,7 @@
}
#endif
-#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined
__amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined
_M_IX86 || defined _X86_))
+#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined
__amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined
_M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
/* Representation of an 80-bit 'long double' as an initializer for a sequence
of 'unsigned int' words. */
# ifdef WORDS_BIGENDIAN
--- tests/test-isnan.c.orig Sun Oct 9 11:21:59 2011
+++ tests/test-isnan.c Sun Oct 9 10:28:18 2011
@@ -153,7 +153,7 @@
}
#endif
-#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined
__amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined
_M_IX86 || defined _X86_))
+#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined
__amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined
_M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
/* Representation of an 80-bit 'long double' as an initializer for a sequence
of 'unsigned int' words. */
# ifdef WORDS_BIGENDIAN
--- tests/test-isnanl.h.orig Sun Oct 9 11:21:59 2011
+++ tests/test-isnanl.h Sun Oct 9 10:28:18 2011
@@ -65,7 +65,7 @@
}
#endif
-#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined
__amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined
_M_IX86 || defined _X86_))
+#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined
__amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined
_M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
/* Representation of an 80-bit 'long double' as an initializer for a sequence
of 'unsigned int' words. */
# ifdef WORDS_BIGENDIAN
--
In memoriam Oskar Schindler <http://en.wikipedia.org/wiki/Oskar_Schindler>
<http://www.shoah.dk/Courage/Schindler.htm>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- long double vs. double,
Bruno Haible <=