[MacRuby] #1211: (120 * 0.2).floor should be 24, but MacRuby rounds it down to 23
#1211: (120 * 0.2).floor should be 24, but MacRuby rounds it down to 23 ------------------------------------+--------------------------------------- Reporter: mrada@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ------------------------------------+--------------------------------------- 120 * 0.2 = 24.0 So calling #floor should return 24, but it returns 23 instead! -- Ticket URL: <http://www.macruby.org/trac/ticket/1211> MacRuby <http://macruby.org/>
#1211: (120 * 0.2).floor should be 24, but MacRuby rounds it down to 23 ------------------------------------+--------------------------------------- Reporter: mrada@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ------------------------------------+--------------------------------------- Comment(by thibault.ml@…): Float operations have never been precise arithmetics. It is very possible that the result of (120 * 0.2) is, internally, 23.9999999999999999, which mean floor clearly is 23. -- Ticket URL: <http://www.macruby.org/trac/ticket/1211#comment:1> MacRuby <http://macruby.org/>
#1211: (120 * 0.2).floor should be 24, but MacRuby rounds it down to 23 ------------------------------------+--------------------------------------- Reporter: mrada@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ------------------------------------+--------------------------------------- Comment(by mrada@…): Possibly, but this is not the behaviour that I get with Ruby 1.9.2, or Python, or Haskell, or C. -- Ticket URL: <http://www.macruby.org/trac/ticket/1211#comment:2> MacRuby <http://macruby.org/>
#1211: (120 * 0.2).floor should be 24, but MacRuby rounds it down to 23 ------------------------------------+--------------------------------------- Reporter: mrada@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ------------------------------------+--------------------------------------- Comment(by mrada@…): I've dug into the issue some more and found that the MacRuby code for floats is fairly different from CRuby. In this specific case, MacRuby has a bitwise and operation that removes some precision from a double before coercing the data to a fixnum. When I skip the bitwise and step then I fix my rounding error, but a ton of spec tests fail (I can run them all because one of the hangs). The function doing the coercion is coerce_ptr_to_double in include/ruby/ruby.h:184 -- Ticket URL: <http://www.macruby.org/trac/ticket/1211#comment:3> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby