Skip to content

Commit

Permalink
Deprecate BigDecimal.new
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkn committed Dec 13, 2017
1 parent 16738ad commit 5337373
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
8 changes: 8 additions & 0 deletions ext/bigdecimal/bigdecimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2594,6 +2594,13 @@ static Real *BigDecimal_new(int argc, VALUE *argv);
* ArgumentError:: If the +initial+ is a Float or Rational, and the +digits+
* value is omitted, this exception is raised.
*/
static VALUE
BigDecimal_s_new(int argc, VALUE *argv, VALUE self)
{
rb_warning("BigDecimal.new is deprecated");
return rb_call_super(argc, argv);
}

static VALUE
BigDecimal_initialize(int argc, VALUE *argv, VALUE self)
{
Expand Down Expand Up @@ -3279,6 +3286,7 @@ Init_bigdecimal(void)
rb_define_global_function("BigDecimal", BigDecimal_global_new, -1);

/* Class methods */
rb_define_singleton_method(rb_cBigDecimal, "new", BigDecimal_s_new, -1);
rb_define_singleton_method(rb_cBigDecimal, "mode", BigDecimal_mode, -1);
rb_define_singleton_method(rb_cBigDecimal, "limit", BigDecimal_limit, -1);
rb_define_singleton_method(rb_cBigDecimal, "double_fig", BigDecimal_double_fig, 0);
Expand Down
26 changes: 14 additions & 12 deletions test/test_bigdecimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,22 @@ def test_new
end

def test_new
assert_equal(1, BigDecimal.new("1"))
assert_equal(1, BigDecimal.new("1", 1))
assert_equal(1, BigDecimal.new(" 1 "))
assert_equal(111, BigDecimal.new("1_1_1_"))
assert_equal(10**(-1), BigDecimal.new("1E-1"), '#4825')
assert_warning(/BigDecimal.new is deprecated/) do
assert_equal(1, BigDecimal.new("1"))
assert_equal(1, BigDecimal.new("1", 1))
assert_equal(1, BigDecimal.new(" 1 "))
assert_equal(111, BigDecimal.new("1_1_1_"))
assert_equal(10**(-1), BigDecimal.new("1E-1"), '#4825')

assert_raise(ArgumentError, /"_1_1_1"/) { BigDecimal.new("_1_1_1") }
assert_raise(ArgumentError, /"_1_1_1"/) { BigDecimal.new("_1_1_1") }

BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false)
BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
assert_positive_infinite(BigDecimal.new("Infinity"))
assert_negative_infinite(BigDecimal.new("-Infinity"))
assert_nan(BigDecimal.new("NaN"))
assert_positive_infinite(BigDecimal.new("1E1111111111111111111"))
BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false)
BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
assert_positive_infinite(BigDecimal.new("Infinity"))
assert_negative_infinite(BigDecimal.new("-Infinity"))
assert_nan(BigDecimal.new("NaN"))
assert_positive_infinite(BigDecimal.new("1E1111111111111111111"))
end
end

def test_new_with_integer
Expand Down

0 comments on commit 5337373

Please sign in to comment.