1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/bigdecimal/bigdecimal.c (VpException): bigdecimal zero

division should raise FloatDomainError if mode
  VP_EXCEPTION_ZERODIVIDE is set.  [ruby-dev:37204]

* ext/bigdecimal/bigdecimal.c (BigDecimal_mode): should handle
  VP_EXCEPTION_ZERODIVIDE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2008-11-26 14:04:58 +00:00
parent 527701d55b
commit 0434b0f098
4 changed files with 21 additions and 9 deletions

View file

@ -1,3 +1,12 @@
Wed Nov 26 22:46:23 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/bigdecimal/bigdecimal.c (VpException): bigdecimal zero
division should raise FloatDomainError if mode
VP_EXCEPTION_ZERODIVIDE is set. [ruby-dev:37204]
* ext/bigdecimal/bigdecimal.c (BigDecimal_mode): should handle
VP_EXCEPTION_ZERODIVIDE.
Wed Nov 26 15:16:07 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* ext/gdbm/gdbm.c (rb_gdbm_nextkey): fix memory leak.

View file

@ -425,6 +425,11 @@ BigDecimal_mode(int argc, VALUE *argv, VALUE self)
(fo&(~VP_EXCEPTION_UNDERFLOW))));
}
fo = VpGetException();
if(f&VP_EXCEPTION_ZERODIVIDE) {
VpSetException((unsigned short)((val==Qtrue)?(fo|VP_EXCEPTION_ZERODIVIDE):
(fo&(~VP_EXCEPTION_ZERODIVIDE))));
}
fo = VpGetException();
return INT2FIX(fo);
}
if(VP_ROUND_MODE==f) {
@ -2270,18 +2275,12 @@ VpException(unsigned short f, const char *str,int always)
switch(f)
{
/*
case VP_EXCEPTION_ZERODIVIDE:
case VP_EXCEPTION_OVERFLOW:
*/
case VP_EXCEPTION_ZERODIVIDE:
case VP_EXCEPTION_INFINITY:
exc = rb_eFloatDomainError;
goto raise;
case VP_EXCEPTION_NaN:
exc = rb_eFloatDomainError;
goto raise;
case VP_EXCEPTION_UNDERFLOW:
exc = rb_eFloatDomainError;
goto raise;
case VP_EXCEPTION_OP:
exc = rb_eFloatDomainError;
goto raise;

View file

@ -45,7 +45,7 @@ extern "C" {
#define VP_EXCEPTION_NaN ((unsigned short)0x0002)
#define VP_EXCEPTION_UNDERFLOW ((unsigned short)0x0004)
#define VP_EXCEPTION_OVERFLOW ((unsigned short)0x0001) /* 0x0008) */
#define VP_EXCEPTION_ZERODIVIDE ((unsigned short)0x0001) /* 0x0010) */
#define VP_EXCEPTION_ZERODIVIDE ((unsigned short)0x0010)
/* Following 2 exceptions cann't controlled by user */
#define VP_EXCEPTION_OP ((unsigned short)0x0020)

View file

@ -77,6 +77,7 @@ class TestBigDecimal < Test::Unit::TestCase
end
def test_exception_zerodivide
BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false)
_test_mode(BigDecimal::EXCEPTION_ZERODIVIDE) { 1 / BigDecimal.new("0") }
_test_mode(BigDecimal::EXCEPTION_ZERODIVIDE) { -1 / BigDecimal.new("0") }
end
@ -275,6 +276,7 @@ class TestBigDecimal < Test::Unit::TestCase
def test_finite_infinite_nan
BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false)
BigDecimal.mode(BigDecimal::EXCEPTION_ZERODIVIDE, false)
x = BigDecimal.new("0")
assert_equal(true, x.finite?)
@ -305,7 +307,7 @@ class TestBigDecimal < Test::Unit::TestCase
assert_equal(0, x.to_i)
assert_raise(FloatDomainError){( 1 / x).to_i}
assert_raise(FloatDomainError){(-1 / x).to_i}
assert_raise(FloatDomainError){( 0 / x).to_i}
assert_raise(FloatDomainError) {( 0 / x).to_i}
x = BigDecimal.new("1")
assert_equal(1, x.to_i)
x = BigDecimal.new((2**100).to_s)
@ -315,6 +317,7 @@ class TestBigDecimal < Test::Unit::TestCase
def test_to_f
BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false)
BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
BigDecimal.mode(BigDecimal::EXCEPTION_ZERODIVIDE, false)
x = BigDecimal.new("0")
assert_instance_of(Float, x.to_f)
@ -616,6 +619,7 @@ class TestBigDecimal < Test::Unit::TestCase
def test_sign
BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false)
BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
BigDecimal.mode(BigDecimal::EXCEPTION_ZERODIVIDE, false)
assert_equal(BigDecimal::SIGN_POSITIVE_ZERO, BigDecimal.new("0").sign)
assert_equal(BigDecimal::SIGN_NEGATIVE_ZERO, BigDecimal.new("-0").sign)