Import bigdecimal 2.0.2 (#3905)

* remove duplicated include

* Make BigDecimal#round with argument < 1 return Integer

Fixes [Bug #12780]

* Use a higher default precision for BigDecimal#power and #**

When a fractional power is given, increase the precision if the
precision isn't specified via power's second argument:

Float: increase by 15 (rough number of decimal precision in float)
BigDecimal: increase by adding similar precision modifier as done to
            calculate the base precision.
Rational: double the precision, since a BigDecimal is created, but
          the created BigDecimal uses the same precision.

Increasing the precision for these power calculations has the obvious
tradeoff of making the calculations slower.

Fixes Ruby Bug #17264

* Use DBLE_FIG for a Float value

* Version 2.0.1

Co-authored-by: pavel <pavel.rosicky@easy.cz>
Co-authored-by: Jeremy Evans <code@jeremyevans.net>
This commit is contained in:
Kenta Murata 2020-12-15 15:17:15 +09:00 committed by GitHub
parent 9d85ed6cbb
commit a86c147579
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2020-12-15 15:17:40 +09:00
Merged-By: mrkn <mrkn@ruby-lang.org>
3 changed files with 29 additions and 7 deletions

View file

@ -1104,6 +1104,11 @@ class TestBigDecimal < Test::Unit::TestCase
assert_equal(-1, x.round(0, BigDecimal::ROUND_HALF_DOWN), bug3803)
assert_equal(-1, x.round(0, BigDecimal::ROUND_HALF_EVEN), bug3803)
end
assert_instance_of(Integer, x.round)
assert_instance_of(Integer, x.round(0))
assert_instance_of(Integer, x.round(-1))
assert_instance_of(BigDecimal, x.round(1))
end
def test_round_half_even
@ -1456,8 +1461,13 @@ class TestBigDecimal < Test::Unit::TestCase
def test_power_without_prec
pi = BigDecimal("3.14159265358979323846264338327950288419716939937511")
e = BigDecimal("2.71828182845904523536028747135266249775724709369996")
pow = BigDecimal("22.4591577183610454734271522045437350275893151339967843873233068")
pow = BigDecimal("0.2245915771836104547342715220454373502758931513399678438732330680117143493477164265678321738086407229773690574073268002736527e2")
assert_equal(pow, pi.power(e))
n = BigDecimal("2222")
assert_equal(BigDecimal("0.5171353084572525892492416e12"), (n ** 3.5))
assert_equal(BigDecimal("0.517135308457252592e12"), (n ** 3.5r))
assert_equal(BigDecimal("0.517135308457252589249241582e12"), (n ** BigDecimal("3.5",15)))
end
def test_power_with_prec