Project

General

Profile

Actions

Bug #922

closed

Float == is false when should be true

Added by amandanicholas (Amanda Nicholas) almost 16 years ago. Updated over 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
ruby -v:
[ruby-core:20813]

Description

=begin
In irb on Ruby 1.8.6 (ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]) and 1.8.7 (ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux])

896.5 * 0.83
=> 744.095
896.5 * 0.83 == 744.095
=> false
=end


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #3746: Incorrect Float subtractionRejected08/26/2010Actions
Actions #1

Updated by drbrain (Eric Hodel) almost 16 years ago

=begin
On Dec 22, 2008, at 19:55 PM, Amanda Nicholas wrote:

Bug #922: Float == is false when should be true
http://redmine.ruby-lang.org/issues/show/922

Author: Amanda Nicholas
Status: Open, Priority: Normal
Target version: Ruby 1.8.7

In irb on Ruby 1.8.6 (ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-
linux]) and 1.8.7 (ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux])

896.5 * 0.83
=> 744.095
896.5 * 0.83 == 744.095
=> false

They're not the same, Ruby truncates the true value for display
purposes:

irb(main):001:0> a = 896.5* 0.83
=> 744.095
irb(main):002:0> b = 744.095
=> 744.095
irb(main):004:0> "%0.26f %0.26f" % [a, b]
=> "744.09499999999991359800333157 744.09500000000002728484105319"

See also: http://en.wikipedia.org/wiki/Floating_point

=end

Actions #3

Updated by kstephens (Kurt Stephens) almost 16 years ago

=begin
Perhaps Ruby should do what Common Lisp implementations have been doing:

http://portal.acm.org/citation.cfm?id=989431
http://kurtstephens.com/files/p372-steele.pdf
ftp://netlib.bell-labs.com/netlib/fp/gdtoa.tgz

Perhaps the default Float#to_s formatting should not throw away necessary precision, so that:

some_float == eval("#{some_float}")

is always true.

=end

Actions #4

Updated by matz (Yukihiro Matsumoto) almost 16 years ago

  • Status changed from Open to Rejected

=begin
OP is not a bug at all. We will consider about Float#to_s later.
Thank you for the info, Kurt.

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0