mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
bigdecimal: version 1.3.1
Import bigdecimal version 1.3.1. The full commit log is here: https://github.com/ruby/bigdecimal/compare/v1.3.0...v1.3.1 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57597 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5d906263ab
commit
70f772c3ef
5 changed files with 32 additions and 23 deletions
|
@ -5919,18 +5919,13 @@ Exit:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* nf: digit position for operation.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
VP_EXPORT int
|
|
||||||
VpMidRound(Real *y, unsigned short f, ssize_t nf)
|
|
||||||
/*
|
/*
|
||||||
* Round relatively from the decimal point.
|
* Round relatively from the decimal point.
|
||||||
* f: rounding mode
|
* f: rounding mode
|
||||||
* nf: digit location to round from the decimal point.
|
* nf: digit location to round from the decimal point.
|
||||||
*/
|
*/
|
||||||
|
VP_EXPORT int
|
||||||
|
VpMidRound(Real *y, unsigned short f, ssize_t nf)
|
||||||
{
|
{
|
||||||
/* fracf: any positive digit under rounding position? */
|
/* fracf: any positive digit under rounding position? */
|
||||||
/* fracf_1further: any positive digits under one further than the rounding position? */
|
/* fracf_1further: any positive digits under one further than the rounding position? */
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
_VERSION = '1.3.0'
|
_VERSION = '1.3.1'
|
||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "bigdecimal"
|
s.name = "bigdecimal"
|
||||||
|
|
|
@ -14,10 +14,6 @@ have_func("rb_rational_den", "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_macro("FIX_CONST_VALUE_PTR", "ruby.h")
|
|
||||||
have_macro("RARRAY_CONST_PTR", "ruby.h")
|
|
||||||
have_macro("RARRAY_AREF", "ruby.h")
|
|
||||||
|
|
||||||
create_makefile('bigdecimal')
|
create_makefile('bigdecimal')
|
||||||
|
|
||||||
# Add additional dependencies
|
# Add additional dependencies
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: false
|
||||||
# BigDecimal extends the native Integer class to provide the #to_d method.
|
|
||||||
#
|
#
|
||||||
# When you require the BigDecimal library in your application, this method will
|
# bigdecimal/util extends various native classes to provide the #to_d method,
|
||||||
|
# and provides BigDecimal#to_d and BigDecimal#to_digits.
|
||||||
|
|
||||||
|
|
||||||
|
# bigdecimal/util extends the native Integer class to provide the #to_d method.
|
||||||
|
#
|
||||||
|
# When you require 'bigdecimal/util' in your application, this method will
|
||||||
# be available on Integer objects.
|
# be available on Integer objects.
|
||||||
class Integer < Numeric
|
class Integer < Numeric
|
||||||
# call-seq:
|
# call-seq:
|
||||||
|
@ -20,9 +25,9 @@ class Integer < Numeric
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# BigDecimal extends the native Float class to provide the #to_d method.
|
# bigdecimal/util extends the native Float class to provide the #to_d method.
|
||||||
#
|
#
|
||||||
# When you require BigDecimal in your application, this method will be
|
# When you require 'bigdecimal/util' in your application, this method will be
|
||||||
# available on Float objects.
|
# available on Float objects.
|
||||||
class Float < Numeric
|
class Float < Numeric
|
||||||
# call-seq:
|
# call-seq:
|
||||||
|
@ -41,9 +46,9 @@ class Float < Numeric
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# BigDecimal extends the native String class to provide the #to_d method.
|
# bigdecimal/util extends the native String class to provide the #to_d method.
|
||||||
#
|
#
|
||||||
# When you require BigDecimal in your application, this method will be
|
# When you require 'bigdecimal/util' in your application, this method will be
|
||||||
# available on String objects.
|
# available on String objects.
|
||||||
class String
|
class String
|
||||||
# call-seq:
|
# call-seq:
|
||||||
|
@ -58,14 +63,18 @@ class String
|
||||||
# # => 0.5e0
|
# # => 0.5e0
|
||||||
#
|
#
|
||||||
def to_d
|
def to_d
|
||||||
BigDecimal(self)
|
begin
|
||||||
|
BigDecimal(self)
|
||||||
|
rescue ArgumentError
|
||||||
|
BigDecimal(0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# BigDecimal extends the native Numeric class to provide the #to_digits and
|
# bigdecimal/util extends the BigDecimal class to provide the #to_digits and
|
||||||
# #to_d methods.
|
# #to_d methods.
|
||||||
#
|
#
|
||||||
# When you require BigDecimal in your application, this method will be
|
# When you require 'bigdecimal/util' in your application, these methods will be
|
||||||
# available on BigDecimal objects.
|
# available on BigDecimal objects.
|
||||||
class BigDecimal < Numeric
|
class BigDecimal < Numeric
|
||||||
# call-seq:
|
# call-seq:
|
||||||
|
@ -99,9 +108,9 @@ class BigDecimal < Numeric
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# BigDecimal extends the native Rational class to provide the #to_d method.
|
# bigdecimal/util extends the native Rational class to provide the #to_d method.
|
||||||
#
|
#
|
||||||
# When you require BigDecimal in your application, this method will be
|
# When you require 'bigdecimal/util' in your application, this method will be
|
||||||
# available on Rational objects.
|
# available on Rational objects.
|
||||||
class Rational < Numeric
|
class Rational < Numeric
|
||||||
# call-seq:
|
# call-seq:
|
||||||
|
|
|
@ -48,4 +48,13 @@ class TestBigDecimalUtil < Test::Unit::TestCase
|
||||||
def test_Rational_to_d_with_negative_precision
|
def test_Rational_to_d_with_negative_precision
|
||||||
assert_raise(ArgumentError) { 355.quo(113).to_d(-42) }
|
assert_raise(ArgumentError) { 355.quo(113).to_d(-42) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_String_to_d
|
||||||
|
assert_equal("2.5".to_d, BigDecimal.new('2.5'))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_invalid_String_to_d
|
||||||
|
assert_equal("invalid".to_d, BigDecimal.new('0.0'))
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue