[vox-tech] location of DBL_EPSILON definition

Micah Cowan micah at cowan.name
Fri Jan 26 11:46:11 PST 2007


On Fri, 2007-01-26 at 14:36 -0500, Peter Jay Salzman wrote:
> On Fri 26 Jan 07,  8:39 AM, Micah Cowan <micah at cowan.name> said:

> > My float.h simply defines DBL_EPSILON to __DBL_EPSILON__. There does not
> > appear to be an inclusion of some other file, or a definition of
> > __DBL_EPSILON__. So the answer to your question would seem: compiler
> > magic. :)
>  
> This is very unfortunate.  I liked having one file to look at for all my
> float constant curiosity.

In that case, you could try one of the following:

     1. Write a simple C program that prints out, to the maximum useful
        precision, the values you're interested in. Actually, chances
        are you could use C preprocessing stringization to get /exactly/
        the values used.
     2. The preprocessor seems to translate the magic __DBL_EPSILON__
        (rather than the compiler proper); therefore, running gcc -E on
        a file like:

#include <float.h>
DBL_EPSILON

gives (for me):

# 1 "test.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "test.c"
# 1 "/usr/lib/gcc/i486-linux-gnu/4.1.2/include/float.h" 1 3 4
# 2 "test.c" 2
2.2204460492503131e-16

--------

...for method #1, above, you could do something like:

#include <float.h>
#include <stdio.h>

#define STR2(x) #x
#define STR(x) STR2(x)

int main(void) {
    printf("DBL_EPSILON: %s\n", STR(DBL_EPSILON));
    /* ... etc ... */
    return 0;
}

-- 
HTH,
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/




More information about the vox-tech mailing list