diff options
author | Kenta Murata <mrkn@mrkn.jp> | 2021-12-09 22:24:12 +0900 |
---|---|---|
committer | Kenta Murata <mrkn@mrkn.jp> | 2021-12-24 02:29:00 +0900 |
commit | 79712fc083f483b3ef174f6ab457f8b63b87c43e (patch) | |
tree | 77b4e2a04e30926afb829b532049b3c6030a966b /test/bigdecimal/test_bigdecimal.rb | |
parent | 0b8638cd7439570bc553ed1684a9f59da7d9c103 (diff) | |
download | ruby-79712fc083f483b3ef174f6ab457f8b63b87c43e.tar.gz |
[ruby/bigdecimal] Let BigDecimal#quo accept precision
Fix GH-214.
https://github.com/ruby/bigdecimal/commit/13e0e93f37
Diffstat (limited to 'test/bigdecimal/test_bigdecimal.rb')
-rw-r--r-- | test/bigdecimal/test_bigdecimal.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index 9e8f0d593b..bbfcbec4df 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -1101,6 +1101,30 @@ class TestBigDecimal < Test::Unit::TestCase x.div(y, 100)) end + def test_quo_without_prec + x = BigDecimal(5) + y = BigDecimal(229) + assert_equal(BigDecimal("0.021834061135371179039301310043668122"), x.quo(y)) + end + + def test_quo_with_prec + begin + saved_mode = BigDecimal.mode(BigDecimal::ROUND_MODE) + BigDecimal.mode(BigDecimal::ROUND_MODE, :half_up) + + x = BigDecimal(5) + y = BigDecimal(229) + assert_equal(BigDecimal("0.021834061135371179039301310043668122"), x.quo(y, 0)) + assert_equal(BigDecimal("0.022"), x.quo(y, 2)) + assert_equal(BigDecimal("0.0218"), x.quo(y, 3)) + assert_equal(BigDecimal("0.0218341"), x.quo(y, 6)) + assert_equal(BigDecimal("0.02183406114"), x.quo(y, 10)) + assert_equal(BigDecimal("0.021834061135371179039301310043668122270742358078603"), x.quo(y, 50)) + ensure + BigDecimal.mode(BigDecimal::ROUND_MODE, saved_mode) + end + end + def test_abs_bigdecimal x = BigDecimal((2**100).to_s) assert_equal(1267650600228229401496703205376, x.abs) |