Questions about IEEE754 floating point in D

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Tue Feb 23 06:22:52 PST 2010


Don wrote:
> Don wrote:
>> Trip Volpe wrote:
>>> 1. Does D guarantee the closest approximation for decimal 
>>> floating-point literals?
>>
>> Not at present.
>>
>>>
>>> 2. Minimum exponent. In D, double.min_exp is equal to -1021. However, 
>>> the Wikipedia article on IEEE754-2008 and appendix D in Sun's 
>>> Numerical Computation Guide ("What Every Computer Scientist Should 
>>> Know About Floating-Point Arithmetic", 
>>> http://docs.sun.com/source/806-3568/ncg_goldberg.html) list Emin for 
>>> the IEEE754 double format as -1022. Is this an error?
>> [snip]
>>
>> There are no errors anywhere. However, double.min_exp is defined in 
>> the spec as "the minimum value such that 2^^min_exp-1 is representable 
>> as a normalized value".
>> This means that 2^^min_exp-1 == 2^^Emin. And indeed min_exp-1 == -1022 
>> = Emin.
>> I have no idea why min_exp is defined in such a peculiar way. In 
>> particular, I don't know why it's different from the definition of 
>> min_10_exp. It seems bizarre and useless.
> 
> For C++, DBL_MIN_EXP = -1021.
> http://www.qnx.com/developers/docs/6.4.1/dinkum_en/ecpp/float.html
> And it is defined as the minimum integer such that 
> FLT_RADIX^^(DBL_MIN_EXP - 1) is a normalized, finite representable value 
> of type double.
> 
> I have a vague recollection that this bizarre definition is for 
> compatibility with an ancient mistake in C. Some clown miscalculated it, 
> and by the time people realized, they felt it was too late to fix it.

Then it sounds like something D should get right.

-Lars



More information about the Digitalmars-d mailing list