[RFH] A simple way to figure out the number of bits used by a long double

Ed Smith-Rowland 3dw4rd@verizon.net
Fri Feb 26 14:30:00 GMT 2010


Paolo Carlini wrote:
> On 02/26/2010 01:03 PM, Andreas Schwab wrote:
>   
>> Paolo Carlini <paolo.carlini@oracle.com> writes:
>>     
>>> At the moment I'm trying to cook up something fixing that count with
>>> LDBL_MANT_DIG, but maybe there is something simpler, maybe using
>>> preprocessor builtins?!?
>>>     
>>>       
>> What's wrong with LDBL_MANT_DIG?
>>   
>>     
> Nothing Andreas, the information is all there, essentially. I was hoping
> in something more "clever", and closer to the actual number, including
> the exponent, etc.
>
> Paolo.
>
>   
Huh.  I would have *sworn* that sizeof(long double) was 10 not 16 even 
though we know it was 80 bits.

How about (in the language of numeric_limits):

bits = 1     //  sign bit
      + ::digits    //  significand bits
      + log2(1 + ::max_exponent - ::min_exponent)  //  exponent bits

There are preprocessor macros for each these things IIRC if you would 
rather use those.

Another possibility: ask our Fortran brethren who support  real*4, 
real*8, real*10, real*16, etc.

Ed



More information about the Gcc mailing list