From: "Peña, Botp" Date: 2007-08-31T18:55:41+09:00 Subject: Re: 0.06 == 0.06 returns false in Ruby? From: Robert Klemme [mailto:shortcutter@googlemail.com] # And who decides about the size of epsilon and which algorithm to # choose? There is no one size fits all answer to that hence leaving # Float#== the way it is (i.e. compare for exact identical values) is # the only viable option. Otherwise you would soon see similar # questions on the list, i.e., "how come it sometimes works and # sometimes it doesn't". And they become more difficult to answer as # the cases are likely less easy to spot / explain. indeed :( maybe i'm not "realistic" but i thought 0.05 + 0.01 == 0.06 => false was "unrealistic" enough for a simple and plain 2 decimal arithmetic. Even people w zero-know on computers would laugh about it (yes, try explaining it to your wife or kids, eg). For simple math (eg those dealing w money): i can live w slowness in simple math (quite a paradox if you ask me). i can live w 1/3 == 0.3333333333 =>false or that sqrt(2) == 1.1414213562 => false i use bigdecimal. bigdecimal handles 0.05 + 0.01 == 0.06 => true For complex math, i can live w slowness (no question there). bigdecimal easily handles sqrt(2) at 100 digits: 2.sqrt(100) => #