Re: 0.06 == 0.06 returns false in Ruby?



From: Jason G. [mailto:jasonpurchase@xxxxxxxxx]
# Subject: 0.06 == 0.06 returns false in Ruby?
# http://www.ruby-forum.com/attachment/193/test.rb

oops, careful w your statement/subject :)

obviously, 0.06 == 0.06. any language can vouch on that.

irb(main):008:0> 0.06 == 0.06
=> true

the problem crops out here (they trigger when you do operations),

irb(main):009:0> 0.05+0.01 == 0.06
=> false

you can check the diff

irb(main):010:0> (0.05+0.01) - 0.06
=> 6.93889390390723e-18

as mentioned by Dan, careful on comparing floats. And as to any precision subject, there is what we call significant digits..

this floating problem is a faq and is very surprising on such a very high language such as ruby. can we address this? maybe create flag like $EPSILON=0 or something, or may flag to revert to rational or bigdeci like $FLOAT_PROCESSOR=RATIONAL...

just a thought.

kind regards -botp


Relevant Pages

  • Re: Simple Ajax question.
    ... Are you saying that the clocks do not work for you? ... English has been pushed to the start in order to reduce the ... language code, and put English in it's proper place between Greek ... it makes more sense to use the American flag. ...
    (comp.lang.javascript)
  • Re: RfD -- FVALUE vsn 2.0
    ... the ' could fail to find the name and throw a system exception. ... need to clear the flag, as does start up, QUIT and what else? ... language at the other, ... theory permit strongly checking implementations that will warn the ...
    (comp.lang.forth)
  • Re: Exit Sub in C#
    ... flag goes away. ... language behave differently to each other. ... public void Func() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Simple Ajax question.
    ... They are in alphabetic order of the drop-down list on the Google ... English has been pushed to the start in order to reduce the ... language code, and put English in it's proper place between Greek ... it makes more sense to use the American flag. ...
    (comp.lang.javascript)
  • Re: Last event
    ... Than take care that all intitialisation is done before the events are set. ... This depends really how to do on the language you are using and than it is ... I think the flag ...
    (microsoft.public.dotnet.general)