From b9f06459497a60d573c1bf32352feaec642cedb4 Mon Sep 17 00:00:00 2001 From: tompng Date: Thu, 18 Dec 2025 00:53:34 +0900 Subject: [PATCH 1/2] Remove unused variable (and add test for it) --- lib/bigdecimal/math.rb | 1 - test/bigdecimal/test_bigmath.rb | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/bigdecimal/math.rb b/lib/bigdecimal/math.rb index b3052512..b1664f16 100644 --- a/lib/bigdecimal/math.rb +++ b/lib/bigdecimal/math.rb @@ -778,7 +778,6 @@ def lgamma(x, prec) # if x is close to 1 or 2, increase precision to reduce loss of significance diff1_exponent = (x - 1).exponent diff2_exponent = (x - 2).exponent - extra_prec = [-diff1_exponent, -diff2_exponent, 0].max extremely_near_one = diff1_exponent < -prec2 extremely_near_two = diff2_exponent < -prec2 diff --git a/test/bigdecimal/test_bigmath.rb b/test/bigdecimal/test_bigmath.rb index 8b85aa6d..903fd7f9 100644 --- a/test/bigdecimal/test_bigmath.rb +++ b/test/bigdecimal/test_bigmath.rb @@ -14,6 +14,13 @@ class TestBigMath < Test::Unit::TestCase MINF = BigDecimal("-Infinity") NAN = BigDecimal("NaN") + def test_no_warning + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + require 'bigdecimal/math' + end; + end + def test_pi assert_equal( BigDecimal("3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068"), From a3feee4c755d465b31375149e33a5e9e86560962 Mon Sep 17 00:00:00 2001 From: tompng Date: Thu, 18 Dec 2025 00:59:07 +0900 Subject: [PATCH 2/2] Fix shadowing outer local variable warning on ruby-2.5 --- lib/bigdecimal/math.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/bigdecimal/math.rb b/lib/bigdecimal/math.rb index b1664f16..a57ad115 100644 --- a/lib/bigdecimal/math.rb +++ b/lib/bigdecimal/math.rb @@ -678,9 +678,9 @@ def erfc(x, prec) sum = c_prev.add(c_next, prec) 2.step do |k| - c = (c_prev.mult(x, prec) + a * c_next).mult(2, prec).mult(x, prec).div(k, prec) - sum = sum.add(c, prec) - c_prev, c_next = c_next, c + cn = (c_prev.mult(x, prec) + a * c_next).mult(2, prec).mult(x, prec).div(k, prec) + sum = sum.add(cn, prec) + c_prev, c_next = c_next, cn break if [c_prev, c_next].all? { |c| c.zero? || (c.exponent < sum.exponent - prec) } end value = sum.mult(scale.mult(exp(-(x + a).mult(x + a, prec), prec), prec), prec)