Comparing double and float values

Alexander aldem+dmars at nk7.net
Thu May 12 01:32:41 PDT 2011


On 12.05.2011 10:03, Abid H. Mujtaba wrote:

> unittest
> {
>    double x = 3.2 ;
>    float y = 3.2 ;
> 
>    assert( x == y ) ;
> }

  Quite OK, IMHO:

x-y = -4.76837e-08

  Just regular rounding error, and we are comparing values stored with different precision.

  Float values quite rarely can store *exact* values.

/Alexander


More information about the Digitalmars-d mailing list