float comparison

nocide benutzer at example.com
Sat Aug 25 01:28:44 PDT 2012


unittest {
     bool fuzzyCmp(float a, float b) {
         return abs(a-b) < 0.000001f;
     }
     float len1 = sqrt(8.0f);
     float len2 = sqrt(8.0f);
     assert(len1 == len2);              // passes
     assert(fuzzyCmp(len1,sqrt(8.0f))); // passes
     assert(len1 == sqrt(8.0f));        // fails!!
}


The comparison of the float variable passes, but the comparison to the 
return value of the sqrt-function fails.?!


More information about the Digitalmars-d-learn mailing list