Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / December 2005



Tip: Looking for answers? Try searching our database.

float.h

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tagomago - 27 Dec 2005 19:27 GMT
I have printed the values LDBL_MAX_10_EXP LDBL_MIN_10_EXP and i have
obtained 308 and -291 while DBL_MAX_10_EXP DBL_MIN_10_EXP are 308 and
-307. Shouldn't the values for long double be much bigger or at least
equal to those of double? Furthermore how is it possible that
LDBL_EPSILON equals 4.940656e-324 if LDBL_MIN_10_EXP is -291?
What's wrong? I'm using OS X 10.4.3 on a powerbook g4.
Thanks.
Paul Russell - 27 Dec 2005 23:54 GMT
> I have printed the values LDBL_MAX_10_EXP LDBL_MIN_10_EXP and i have
> obtained 308 and -291 while DBL_MAX_10_EXP DBL_MIN_10_EXP are 308 and
[quoted text clipped - 3 lines]
> What's wrong? I'm using OS X 10.4.3 on a powerbook g4.
> Thanks.

I don't know where the -291 is coming from - if you look at float.h you
should see LDBL_MIN_10_EXP defined as -307.

BTW, it probably helps to mention which compiler you're using (gcc 3.3,
gcc 4.0, CodeWarrior, whatever).

Paul
tagomago - 28 Dec 2005 14:16 GMT
>> I have printed the values LDBL_MAX_10_EXP LDBL_MIN_10_EXP and i have
>> obtained 308 and -291 while DBL_MAX_10_EXP DBL_MIN_10_EXP are 308 and
[quoted text clipped - 11 lines]
>
> Paul
I'm using gcc 4.0. By looking inside float.h i only see the following:
#define LDBL_MIN_10_EXP    __LDBL_MIN_10_EXP__
However even if it would be -307 what would be the meaning of
LDBL_EPSILON equals 4.940656e-324?
Paul Russell - 28 Dec 2005 22:03 GMT
> I'm using gcc 4.0. By looking inside float.h i only see the following:
> #define LDBL_MIN_10_EXP    __LDBL_MIN_10_EXP__

Right, and you should see in the same header that __LDBL_MIN_10_EXP__ is
#defined as (-307).

> However even if it would be -307 what would be the meaning of
> LDBL_EPSILON equals 4.940656e-324?

I'm not 100% certain but I would guess that 1e-307 is the smallest
normalised float, while 4.940656e-324 is either the smallest denormal or
the size of one LSB in the smallest float ?

Paul
Eric Albert - 28 Dec 2005 23:59 GMT
> > I'm using gcc 4.0. By looking inside float.h i only see the following:
> > #define LDBL_MIN_10_EXP    __LDBL_MIN_10_EXP__
>
> Right, and you should see in the same header that __LDBL_MIN_10_EXP__ is
> #defined as (-307).

I think it's actually built in to the compiler:

PowerBookG412:~> cpp -E -dM < /dev/null | grep __LDBL_MIN_10_EXP__
#define __LDBL_MIN_10_EXP__ (-291)

-Eric

Signature

Eric Albert         ejalbert@cs.stanford.edu
http://outofcheese.org/

Paul Russell - 29 Dec 2005 23:52 GMT
>>>I'm using gcc 4.0. By looking inside float.h i only see the following:
>>>#define LDBL_MIN_10_EXP    __LDBL_MIN_10_EXP__
[quoted text clipped - 8 lines]
>
> -Eric

Interesting - float.h has

#ifndef __LDBL_MIN_10_EXP__
#define __LDBL_MIN_10_EXP__ (-307)
#endif

so I guess the compiler is overriding float.h.

Paul
Eric Albert - 30 Dec 2005 03:03 GMT
> >>>I'm using gcc 4.0. By looking inside float.h i only see the following:
> >>>#define LDBL_MIN_10_EXP    __LDBL_MIN_10_EXP__
[quoted text clipped - 6 lines]
> > PowerBookG412:~> cpp -E -dM < /dev/null | grep __LDBL_MIN_10_EXP__
> > #define __LDBL_MIN_10_EXP__ (-291)

> Interesting - float.h has
>
[quoted text clipped - 3 lines]
>
> so I guess the compiler is overriding float.h.

Look a bit closer and you'll see that's in an #if __MWERKS__ block.  
It's only there for CodeWarrior support.

-Eric

Signature

Eric Albert         ejalbert@cs.stanford.edu
http://outofcheese.org/

Paul Russell - 30 Dec 2005 10:25 GMT
>>>>>I'm using gcc 4.0. By looking inside float.h i only see the following:
>>>>>#define LDBL_MIN_10_EXP    __LDBL_MIN_10_EXP__
[quoted text clipped - 17 lines]
> Look a bit closer and you'll see that's in an #if __MWERKS__ block.  
> It's only there for CodeWarrior support.

D'oh !

Interestingly though gcc 3.3 seems to give the correct value:

> prussell$ gcc-3.3 -E -dM - < /dev/null | grep __LDBL_MIN_10_EXP__
> #define __LDBL_MIN_10_EXP__ (-307)

Paul
Eric Albert - 30 Dec 2005 21:49 GMT
> >>>>>I'm using gcc 4.0. By looking inside float.h i only see the following:
> >>>>>#define LDBL_MIN_10_EXP    __LDBL_MIN_10_EXP__
[quoted text clipped - 24 lines]
> > prussell$ gcc-3.3 -E -dM - < /dev/null | grep __LDBL_MIN_10_EXP__
> > #define __LDBL_MIN_10_EXP__ (-307)

I wonder if the different value is due to the different default size of
long double between 3.3 and 4.0.  Long double technically wasn't
supported on Mac OS X until 128-bit long doubles were introduced with
gcc 4 and Tiger.  Each compiler may be correct for its long double size.

This example shows, well, something:

PowerBookG412:~> cat test.c
#include <stdio.h>

int main(void) {
       printf("Size of long double: %lu\n", sizeof(long double));
       return 0;
}
PowerBookG412:~> gcc-3.3 -Wall -g -o test test.c
test.c: In function `main':
test.c:4: warning: use of `long double' type; its size may change in a
future release
test.c:4: warning: (Long double usage is reported only once for each
file.
test.c:4: warning: To disable this warning, use -Wno-long-double.)
PowerBookG412:~> ./test
Size of long double: 8
PowerBookG412:~> gcc-4.0 -Wall -g -o test test.c
PowerBookG412:~> ./test
Size of long double: 16
PowerBookG412:~>

-Eric

Signature

Eric Albert         ejalbert@cs.stanford.edu
http://outofcheese.org/

Paul Russell - 31 Dec 2005 09:50 GMT
>>>>>>>I'm using gcc 4.0. By looking inside float.h i only see the following:
>>>>>>>#define LDBL_MIN_10_EXP    __LDBL_MIN_10_EXP__
[quoted text clipped - 52 lines]
> Size of long double: 16
> PowerBookG412:~>

I can only guess, than, that some of the negative exponent range in long
double has been stolen for NANs and other special cases, and the change
in gcc 4.0 reflects this ?

Paul
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.