in reply to test fails on 64bit uselongdouble Perl
Just like some numbers are periodic in decimal (e.g. 1/3), some numbers are periodic in binary (e.g. 6/10). They cannot be represented exactly using a float since that would require infinite storage.
You shouldn't check if two floats are equal. You should check if two floats are sufficiently identical.
my $calc = (((63 - -90)/.6) * 601) + (360 /.6); ok( abs( $calc - 153855 ) < 0.000000001 ) or diag("Expected 153855. Got $calc");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: test fails on 64bit uselongdouble Perl
by frankcox (Acolyte) on Oct 29, 2009 at 19:18 UTC | |
by moritz (Cardinal) on Oct 29, 2009 at 19:30 UTC | |
by frankcox (Acolyte) on Oct 29, 2009 at 19:47 UTC | |
by ikegami (Patriarch) on Oct 29, 2009 at 20:41 UTC | |
by kubrat (Scribe) on Oct 30, 2009 at 10:21 UTC | |
| |
by frankcox (Acolyte) on Oct 29, 2009 at 20:04 UTC | |
by ikegami (Patriarch) on Oct 29, 2009 at 20:31 UTC | |
by frankcox (Acolyte) on Oct 29, 2009 at 21:13 UTC | |
by moritz (Cardinal) on Oct 29, 2009 at 21:44 UTC | |
by ikegami (Patriarch) on Oct 29, 2009 at 21:48 UTC | |
| |
by ikegami (Patriarch) on Oct 29, 2009 at 21:19 UTC | |
by frankcox (Acolyte) on Oct 29, 2009 at 22:04 UTC | |
|