Search This Blog

Saturday, October 13, 2007

list of predefined macros

Situation:

guile-1.8_1.8.2+1 failed to build on alpha architecture. The complete build log can be found at http://buildd.debian.org/fetch.cgi?&pkg=guile-1.8&ver=1.8.2%2B1-1&arch=alpha&stamp=1188086025&file=log

The buildlog tells us that the problem is in line 96 of test-round.c . To debug the problem further, the source of guile-1.8 can be downloaded by using

$cd practice/guile/
$apt-get source --download-only guile-1.8
$dpkg-source -x guile-1.8_1.8.2+1-2.dsc
$cd guile-1.8-1.8.2+1/

To see where test-round.c is residing

$find . -iname '*test-round.c*'
./test-suite/standalone/test-round.c

Now when we look at the source code of test-round.c around line 96

$cd test-suite/standalone/
$vim +96 test-round.c

we find that there is a predefined macro called DBL_MANT_DIG . But what is its value? More generally, how can we get a list of all the predefined macros and their values?

Solution:
The answer is surprisingly simple. Just do

$g++ -E -dM - < /dev/null

#define __DBL_MIN_EXP__ (-1021)
#define __FLT_MIN__ 1.17549435e-38F
#define __DEC64_DEN__ 0.000000000000001E-383DD
#define __CHAR_BIT__ 8
#define __WCHAR_MAX__ 2147483647
#define __DBL_DENORM_MIN__ 4.9406564584124654e-324
#define __FLT_EVAL_METHOD__ 2
#define __DBL_MIN_10_EXP__ (-307)
#define __FINITE_MATH_ONLY__ 0
#define __GNUC_PATCHLEVEL__ 3
#define __DEC64_MAX_EXP__ 384
#define __SHRT_MAX__ 32767
#define __LDBL_MAX__ 1.18973149535723176502e+4932L
#define __UINTMAX_TYPE__ long long unsigned int
#define __linux 1
#define __DEC32_EPSILON__ 1E-6DF
#define __unix 1
#define __LDBL_MAX_EXP__ 16384
#define __linux__ 1
...

Since our interest is in the predefined macro DBL_MANT_DIG, the above output can be filtered by using grep.

$g++ -E -dM - < /dev/null | grep -i __DBL

#define __DBL_MIN_EXP__ (-1021)
#define __DBL_DENORM_MIN__ 4.9406564584124654e-324
#define __DBL_MIN_10_EXP__ (-307)
#define __DBL_DIG__ 15
#define __DBL_MAX__ 1.7976931348623157e+308
#define __DBL_HAS_INFINITY__ 1
#define __DBL_MAX_EXP__ 1024
#define __DBL_MIN__ 2.2250738585072014e-308
#define __DBL_HAS_QUIET_NAN__ 1
#define __DBL_HAS_DENORM__ 1
#define __DBL_MANT_DIG__ 53
#define __DBL_EPSILON__ 2.2204460492503131e-16
#define __DBL_MAX_10_EXP__ 308

This clearly tells us that DBL_MANT_DIG is 53 on this particular machine. More information about macros like DBL_MANT_DIG can be found in files
  • /usr/share/doc/glibc-doc-reference/html/Floating-Point-Parameters.html
  • /usr/share/doc/glibc-doc-reference/html/IEEE-Floating-Point.html
  • /usr/share/doc/glibc-doc-reference/html/Library-Summary.html
etc., which are all part of glibc-doc-reference package. On a Debian machine, this package can be installed by doing

$apt-get install glibc-doc-reference

No comments:

Followers