in reply to Re: Comparing masses in two txt files
in thread Comparing masses in two txt files
But beware that checking floating point numbers for equality is basically impossibeBut even if some real numbers cannot be exactly represented in binary, at least they are both exactly misrepresented in the same way, so checking for equality should still work.
I thought that this was only a problem if you were calculating with them:
So on the Perl on my machine (AS Perl 5.8.8) .2 seems to be anything between .19999999999999999 and .20000000000000001.print .2 == .2 ? 'equal' : 'not equal'; equal print .2 *10 == 2 ? 'equal' : 'not equal'; equal print .1999999999999999 *10 == 2 ? 'equal' : 'not equal'; not equal print .19999999999999999 *10 == 2 ? 'equal' : 'not equal'; equal print .20000000000000001 *10 == 2 ? 'equal' : 'not equal'; equal print .2000000000000001 *10 == 2 ? 'equal' : 'not equal'; not equal
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|