diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 2c28e13a..e1b9f6e4 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -5889,7 +5889,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; } diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index fe92ecdf..502d9345 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -1541,6 +1541,10 @@ def test_round assert_equal(x.round(0, const), x.round(0, sym)) end + assert_equal(1, BigDecimal("1e-10").round(0, BigDecimal::ROUND_UP)) + assert_equal(-1, BigDecimal("-1e-10").round(0, BigDecimal::ROUND_UP)) + assert_equal(10**10, BigDecimal("5").round(-10, BigDecimal::ROUND_UP)) + bug3803 = '[ruby-core:32136]' 15.times do |n| x = BigDecimal("5#{'0'*n}1")