Re: 0.06 == 0.06 returns false in Ruby?
- From: Peña, Botp <botp@xxxxxxxxxxxxxxxxx>
- Date: Fri, 31 Aug 2007 11:20:46 +0900
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
- Follow-Ups:
- Re: 0.06 == 0.06 returns false in Ruby?
- From: Michael Ulm
- Re: 0.06 == 0.06 returns false in Ruby?
- References:
- 0.06 == 0.06 returns false in Ruby?
- From: Jason G.
- 0.06 == 0.06 returns false in Ruby?
- Prev by Date: Re: read/select not blocking on SSL socket?
- Next by Date: Re: 0.06 == 0.06 returns false in Ruby?
- Previous by thread: Re: 0.06 == 0.06 returns false in Ruby?
- Next by thread: Re: 0.06 == 0.06 returns false in Ruby?
- Index(es):
Relevant Pages
|