mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parent
ff9e40811c
commit
654f6fbf19
4 changed files with 31 additions and 10 deletions
|
@ -355,11 +355,12 @@ BigDecimal_double_fig(VALUE self)
|
||||||
/* call-seq:
|
/* call-seq:
|
||||||
* big_decimal.precs -> array
|
* big_decimal.precs -> array
|
||||||
*
|
*
|
||||||
* Returns an Array of two Integer values.
|
* Returns an Array of two Integer values that represent platform-dependent
|
||||||
|
* internal storage properties.
|
||||||
*
|
*
|
||||||
* The first value is the current number of significant digits in the
|
* This method is deprecated and will be removed in the future.
|
||||||
* BigDecimal. The second value is the maximum number of significant digits
|
* Instead, use BigDecimal#precision for obtaining the number of decimal
|
||||||
* for the BigDecimal.
|
* digits.
|
||||||
*
|
*
|
||||||
* BigDecimal('5').precs #=> [9, 18]
|
* BigDecimal('5').precs #=> [9, 18]
|
||||||
*/
|
*/
|
||||||
|
@ -371,6 +372,10 @@ BigDecimal_prec(VALUE self)
|
||||||
Real *p;
|
Real *p;
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
|
|
||||||
|
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED,
|
||||||
|
"BigDecimal#precs is deprecated and will be removed in the future; "
|
||||||
|
"use BigDecimal#precision instead.");
|
||||||
|
|
||||||
GUARD_OBJ(p, GetVpValue(self, 1));
|
GUARD_OBJ(p, GetVpValue(self, 1));
|
||||||
obj = rb_assoc_new(SIZET2NUM(p->Prec*VpBaseFig()),
|
obj = rb_assoc_new(SIZET2NUM(p->Prec*VpBaseFig()),
|
||||||
SIZET2NUM(p->MaxPrec*VpBaseFig()));
|
SIZET2NUM(p->MaxPrec*VpBaseFig()));
|
||||||
|
|
|
@ -159,6 +159,10 @@ rb_sym2str(VALUE sym)
|
||||||
# define vabs llabs
|
# define vabs llabs
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(HAVE_RB_CATEGORY_WARN) || !defined(HAVE_CONST_RB_WARN_CATEGORY_DEPRECATED)
|
||||||
|
# define rb_category_warn(category, ...) rb_warn(__VA_ARGS__)
|
||||||
|
#endif
|
||||||
|
|
||||||
extern VALUE rb_cBigDecimal;
|
extern VALUE rb_cBigDecimal;
|
||||||
|
|
||||||
#if 0 || SIZEOF_BDIGITS >= 16
|
#if 0 || SIZEOF_BDIGITS >= 16
|
||||||
|
|
|
@ -42,6 +42,8 @@ have_func("rb_complex_imag", "ruby.h")
|
||||||
have_func("rb_array_const_ptr", "ruby.h")
|
have_func("rb_array_const_ptr", "ruby.h")
|
||||||
have_func("rb_sym2str", "ruby.h")
|
have_func("rb_sym2str", "ruby.h")
|
||||||
have_func("rb_opts_exception_p", "ruby.h")
|
have_func("rb_opts_exception_p", "ruby.h")
|
||||||
|
have_func("rb_category_warn", "ruby.h")
|
||||||
|
have_const("RB_WARN_CATEGORY_DEPRECATED", "ruby.h")
|
||||||
|
|
||||||
if File.file?(File.expand_path('../lib/bigdecimal.rb', __FILE__))
|
if File.file?(File.expand_path('../lib/bigdecimal.rb', __FILE__))
|
||||||
bigdecimal_rb = "$(srcdir)/lib/bigdecimal.rb"
|
bigdecimal_rb = "$(srcdir)/lib/bigdecimal.rb"
|
||||||
|
|
|
@ -610,12 +610,22 @@ class TestBigDecimal < Test::Unit::TestCase
|
||||||
assert_operator(BigDecimal((2**100).to_s), :==, d)
|
assert_operator(BigDecimal((2**100).to_s), :==, d)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_precs_deprecated
|
||||||
|
assert_warn(/BigDecimal#precs is deprecated and will be removed in the future/) do
|
||||||
|
BigDecimal("1").precs
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_precs
|
def test_precs
|
||||||
|
assert_separately(["-rbigdecimal"], "#{<<~"begin;"}\n#{<<~'end;'}")
|
||||||
|
begin;
|
||||||
|
$VERBOSE = nil
|
||||||
a = BigDecimal("1").precs
|
a = BigDecimal("1").precs
|
||||||
assert_instance_of(Array, a)
|
assert_instance_of(Array, a)
|
||||||
assert_equal(2, a.size)
|
assert_equal(2, a.size)
|
||||||
assert_kind_of(Integer, a[0])
|
assert_kind_of(Integer, a[0])
|
||||||
assert_kind_of(Integer, a[1])
|
assert_kind_of(Integer, a[1])
|
||||||
|
end;
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_hash
|
def test_hash
|
||||||
|
@ -764,7 +774,7 @@ class TestBigDecimal < Test::Unit::TestCase
|
||||||
assert_equal(BigDecimal("0.1"), a, '[ruby-core:34318]')
|
assert_equal(BigDecimal("0.1"), a, '[ruby-core:34318]')
|
||||||
|
|
||||||
a, b = BigDecimal("0.11111").coerce(1.quo(3))
|
a, b = BigDecimal("0.11111").coerce(1.quo(3))
|
||||||
assert_equal(BigDecimal("0." + "3"*a.precs[0]), a)
|
assert_equal(BigDecimal("0." + "3"*a.precision), a)
|
||||||
|
|
||||||
assert_nothing_raised(TypeError, '#7176') do
|
assert_nothing_raised(TypeError, '#7176') do
|
||||||
BigDecimal('1') + Rational(1)
|
BigDecimal('1') + Rational(1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue