History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-2308
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Adam Byrtek
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
JRuby

Handling on Rational numbers inconsistent with MRI

Created: 20/Mar/08 07:12 PM   Updated: 20/Mar/08 07:22 PM
Component/s: Core Classes/Modules
Affects Version/s: JRuby 1.1RC2
Fix Version/s: None

Time Tracking:
Not Specified

Environment: ruby 1.8.6 (2008-03-18 rev 6255) [i386-jruby1.1RC3]


 Description  « Hide
Dividing Float by Rational number results in a Fixnum with JRuby and a Float with MRI . This should be consistent between platforms, I guess the MRI behavior makes more sense and JRuby should be fixed. I would be glad to help resolving this, if only some JRuby guru gives me a few tips on where to look.

To reproduce try the following code

require "rational"
result = Float(10) / 20
puts "10.0 divided by 20 equals #{result} (#{result.class})"
result = Float(10) / Rational(20)
puts "10.0 divided by rational 20 equals #{result} (#{result.class})"

When run with MRI this prints

% ruby bug.rb
10.0 divided by 20 equals 0.5 (Float)
10.0 divided by rational 20 equals 0.5 (Float)

Tested with

% ruby -v
ruby 1.8.5 (2006-12-25 patchlevel 12) [i686-darwin]

and

$ ruby -v
ruby 1.8.6 (2007-06-07 patchlevel 36) [i486-linux]

But when run with JRuby this prints

% jruby bug.rb
10.0 divided by 20 equals 0.5 (Float)
10.0 divided by rational 20 equals 0 (Fixnum)
% jruby -v bug.rb
ruby 1.8.6 (2008-03-18 rev 6255) [i386-jruby1.1RC3]



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Adam Byrtek - 20/Mar/08 07:22 PM
Of course the title of this issue should be "Handling of Rational numbers", but it looks like I don't have permissions to edit it.