Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/bigdecimal/bigdecimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -5888,7 +5888,7 @@ VpMidRound(Real *y, unsigned short f, ssize_t nf)
exptoadd=0;
if (nf < 0) {
/* rounding position too left(large). */
if (f != VP_ROUND_CEIL && f != VP_ROUND_FLOOR) {
if (f != VP_ROUND_UP && f != VP_ROUND_CEIL && f != VP_ROUND_FLOOR) {
VpSetZero(y, VpGetSign(y)); /* truncate everything */
return 0;
}
Expand Down
12 changes: 12 additions & 0 deletions test/bigdecimal/test_bigdecimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,18 @@ def test_round
assert_instance_of(BigDecimal, x.round(1))
end

def test_round_up_value_far_below_rounding_position
["1e-10", "1e-27", "0.942882777e-12"].each do |s|
x = BigDecimal(s)
assert_equal(1, x.round(0, BigDecimal::ROUND_UP), s)
assert_equal(-1, (-x).round(0, BigDecimal::ROUND_UP), s)
assert_equal(BigDecimal("0.000001"), x.round(6, :up), s)
assert_equal(BigDecimal("-0.000001"), (-x).round(6, :up), s)
assert_equal(1000, x.round(-3, :up), s)
assert_equal(x.ceil(6), x.round(6, :up), s)
end
end

def test_round_half_even
assert_equal(BigDecimal('12.0'), BigDecimal('12.5').round(half: :even))
assert_equal(BigDecimal('14.0'), BigDecimal('13.5').round(half: :even))
Expand Down