Project

General

Profile

Actions

Bug #9979

closed

Regression: BigDecimal::ROUND_HALF_DOWN/ROUND_HALF_EVEN behave incorrectly

Bug #9979: Regression: BigDecimal::ROUND_HALF_DOWN/ROUND_HALF_EVEN behave incorrectly

Added by josephleniston (Joseph Leniston) over 11 years ago. Updated over 6 years ago.

Status:
Closed
Target version:
-
ruby -v:
2.1.2
[ruby-core:63326]

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.

Updated by josephleniston (Joseph Leniston) over 11 years ago Actions #1 [ruby-core:63327]

This issue is a regression and is the same as issue #3803

Updated by nagachika (Tomoyuki Chikanaga) about 11 years ago Actions #2 [ruby-core:64132]

  • 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?

Updated by mrkn (Kenta Murata) almost 9 years ago Actions #3 [ruby-core:78235]

  • 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.

Updated by jeremyevans0 (Jeremy Evans) over 6 years ago Actions #4

  • Status changed from Feedback to Closed
Actions

Also available in: PDF Atom