Bug #9979
closed
Regression: BigDecimal::ROUND_HALF_DOWN/ROUND_HALF_EVEN behave incorrectly
Added by josephleniston (Joseph Leniston) almost 10 years ago.
Updated almost 5 years ago.
Description
The incorrect behaviour is that all fractional values between 0.5 (inclusive) and 0.6 (non-inclusive) are subject to the rounding policy for 'half', whereas it should only be applied for fractional values exactly equal to 0.5.
This issue is a regression and is the same as issue #3803
- Status changed from Open to Assigned
Joseph, thank you for your report.
But I think current behavior on trunk is correct as described in #3803.
> BigDecimal.new("0.51").round(0, BigDecimal::ROUND_HALF_DOWN).to_s("F")
=> "1.0"
> BigDecimal.new("0.51").round(0, BigDecimal::ROUND_HALF_EVEN).to_s("F")
=> "1.0"
mrkn, could you judge this?
- Status changed from Assigned to Feedback
I think the current behavior is the correct one.
$ ruby -rbigdecimal -ve 'p Gem::Dependency.new("bigdecimal").to_spec.version.to_s; puts ("0.50"..."0.60").map {|x| [x, BigDecimal(x).round(0, BigDecimal::ROUND_HALF_DOWN).to_s("F")].join(" -> ") }'
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
"1.2.8"
0.50 -> 0.0
0.51 -> 1.0
0.52 -> 1.0
0.53 -> 1.0
0.54 -> 1.0
0.55 -> 1.0
0.56 -> 1.0
0.57 -> 1.0
0.58 -> 1.0
0.59 -> 1.0
$ ruby -rbigdecimal -ve 'p Gem::Dependency.new("bigdecimal").to_spec.version.to_s; puts ("0.50"..."0.60").map {|x| [x, BigDecimal(x).round(0, BigDecimal::ROUND_HALF_EVEN).to_s("F")].join(" -> ") }'
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
"1.2.8"
0.50 -> 0.0
0.51 -> 1.0
0.52 -> 1.0
0.53 -> 1.0
0.54 -> 1.0
0.55 -> 1.0
0.56 -> 1.0
0.57 -> 1.0
0.58 -> 1.0
0.59 -> 1.0
$ ruby -rbigdecimal -ve 'p Gem::Dependency.new("bigdecimal").to_spec.version.to_s; puts ("1.50"..."1.60").map {|x| [x, BigDecimal(x).round(0, BigDecimal::ROUND_HALF_EVEN).to_s("F")].join(" -> ") }'
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
"1.2.8"
1.50 -> 2.0
1.51 -> 2.0
1.52 -> 2.0
1.53 -> 2.0
1.54 -> 2.0
1.55 -> 2.0
1.56 -> 2.0
1.57 -> 2.0
1.58 -> 2.0
1.59 -> 2.0
Joseph, please show the wrong examples.
- Status changed from Feedback to Closed
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0