Re: How do I find out what C's long double is?
- From: Dom Fulton <wes104@xxxxxxxxx>
- Date: Tue, 18 Mar 2008 16:29:23 +0000
On 18 Mar 2008 12:03:05 GMT, nmm1@xxxxxxxxxxxxx (Nick Maclaren) wrote:
Number of bits in storage unit: sizeof(double)*CHAR_BIT
Number of bits in value (assuming FLT_RADIX == 2):
1+(int)ceil(log2(DBL_MAX_EXP-DBL_MIN_EXP))+DBL_MANT_DIG
Very nice; thanks (and obvious now that you've pointed it out).
There's a fly in the ointment, though, which is that it's not quite
correct. The test prog below produces this output on my
Centos4.4/x86_64:
FLT_MAX_EXP is 128
FLT_MIN_EXP is -125
FLT_MANT_DIG is 24
FLT bits: 33
DBL_MAX_EXP is 1024
DBL_MIN_EXP is -1021
DBL_MANT_DIG is 53
DBL bits: 65
LDBL_MAX_EXP is 16384
LDBL_MIN_EXP is -16381
LDBL_MANT_DIG is 64
LDBL bits: 80
After some digging about, it seems that x_MANT_DIG is the logical
number of mantissa digits, including the missing MS significand bit,
so it should be (x_MANT_DIG - 1). But '80' is correct on my box, the
reason being that the x86 double extended format apparently has an
explicit MS significand bit (although I suspect that the silicon may
actually only be 79 bits?)
After a (very cursory) look at the C99 spec there doesn't seem to be a
way to find out whether the MS significand bit is implicit or
explicit, so I guess I'll have to live with this.
Any thoughts?
Thanks
-Dom
----------------------------
#include <stdio.h>
#include <float.h>
#include <math.h>
int main(void) {
printf("FLT_MAX_EXP is %d\n", FLT_MAX_EXP);
printf("FLT_MIN_EXP is %d\n", FLT_MIN_EXP);
printf("FLT_MANT_DIG is %d\n", FLT_MANT_DIG);
printf(
"FLT bits: %d\n",
1+(int)ceil(log2(FLT_MAX_EXP-FLT_MIN_EXP))+FLT_MANT_DIG);
printf("DBL_MAX_EXP is %d\n", DBL_MAX_EXP);
printf("DBL_MIN_EXP is %d\n", DBL_MIN_EXP);
printf("DBL_MANT_DIG is %d\n", DBL_MANT_DIG);
printf(
"DBL bits: %d\n",
1+(int)ceil(log2(DBL_MAX_EXP-DBL_MIN_EXP))+DBL_MANT_DIG);
printf("LDBL_MAX_EXP is %d\n", LDBL_MAX_EXP);
printf("LDBL_MIN_EXP is %d\n", LDBL_MIN_EXP);
printf("LDBL_MANT_DIG is %d\n", LDBL_MANT_DIG);
printf(
"LDBL bits: %d\n",
1+(int)ceil(log2(LDBL_MAX_EXP-LDBL_MIN_EXP))+LDBL_MANT_DIG);
return 0;
}
.
- Follow-Ups:
- Re: How do I find out what C's long double is?
- From: glen herrmannsfeldt
- Re: How do I find out what C's long double is?
- From: Nick Maclaren
- Re: How do I find out what C's long double is?
- From: Terje Mathisen
- Re: How do I find out what C's long double is?
- References:
- How do I find out what C's long double is?
- From: Dom Fulton
- Re: How do I find out what C's long double is?
- From: Nick Maclaren
- How do I find out what C's long double is?
- Prev by Date: Re: How do I find out what C's long double is?
- Next by Date: Re: How do I find out what C's long double is?
- Previous by thread: Re: How do I find out what C's long double is?
- Next by thread: Re: How do I find out what C's long double is?
- Index(es):
Relevant Pages
|
|