Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: JRuby 1.6, JRuby 1.7.0.pre2
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
In MRI (several versions, including at least 1.8.7p358 and 1.9.3p194) the rounding tie breaker strategy used for floating point format strings is "round half to even", whereas in JRuby it is "round half away from zero", as can be seen in the following example code. This is different from Float#round in both implementations, which appears to adopt the "round half away from zero" strategy.
http://en.wikipedia.org/wiki/Rounding#Round_half_to_even
http://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero
MRI:
(-3...3).map
{|i|f=i+0.5; [f,'%1.0f' % f,f.round]}=> [[-2.5, "-2", -3], [-1.5, "-2", -2], [-0.5, "-0", -1], [0.5, "0", 1], [1.5, "2", 2], [2.5, "2", 3]]
JRuby:
(-3...3).map{|i|f=i+0.5; [f,'%1.0f' % f,f.round]}
=> [[-2.5, "-3", -3], [-1.5, "-2", -2], [-0.5, "-1", -1], [0.5, "1", 1], [1.5, "2", 2], [2.5, "3", 3]]
As a quick sanity check, I confirmed this applies to all "half" rounding, regardless of scale or precision: