Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: 5c8e3567fd
Fetching contributors…

Cannot retrieve contributors at this time

28 lines (20 sloc) 655 Bytes


Test for equality of floating point numbers carefully.

IEEE floating point numbers are wrongly over-trusted in calculations. Observe:

    print "---\n";
    print "A: ", 2.4, "\n";
    print "B: ", 0.2*12, "\n";
    if ( 0.2*12 == 2.4 ) {
        print "These are equal.\n";
    else {
        print "These are not equal.\n";

    A: 2.4
    B: 2.4
    These are not equal.

This is the result of the fact that 0.2 ( 1/5 ) cannot be represented as a binary fraction in IEEE space.

Thus, if you're checking floating-point equality, use sprintf or similar.

See for details.

Jump to Line
Something went wrong with that request. Please try again.