ruby-changes:8884
From: yugui <ko1@a...>
Date: Sun, 30 Nov 2008 18:25:46 +0900 (JST)
Subject: [ruby-changes:8884] Ruby:r20420 (ruby_1_9_1): merges r20366 from trunk into ruby_1_9_1.
yugui 2008-11-30 18:24:26 +0900 (Sun, 30 Nov 2008) New Revision: 20420 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20420 Log: merges r20366 from trunk into ruby_1_9_1. * 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. Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/ext/bigdecimal/bigdecimal.c branches/ruby_1_9_1/ext/bigdecimal/bigdecimal.h branches/ruby_1_9_1/test/bigdecimal/test_bigdecimal.rb Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 20419) +++ ruby_1_9_1/ChangeLog (revision 20420) @@ -1,3 +1,12 @@ +Wed Nov 26 22:46:23 2008 Yukihiro Matsumoto <matz@r...> + + * 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@m...> * ext/gdbm/gdbm.c (rb_gdbm_nextkey): fix memory leak. Index: ruby_1_9_1/ext/bigdecimal/bigdecimal.c =================================================================== --- ruby_1_9_1/ext/bigdecimal/bigdecimal.c (revision 20419) +++ ruby_1_9_1/ext/bigdecimal/bigdecimal.c (revision 20420) @@ -425,6 +425,11 @@ (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 @@ 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; Index: ruby_1_9_1/ext/bigdecimal/bigdecimal.h =================================================================== --- ruby_1_9_1/ext/bigdecimal/bigdecimal.h (revision 20419) +++ ruby_1_9_1/ext/bigdecimal/bigdecimal.h (revision 20420) @@ -45,7 +45,7 @@ #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) Index: ruby_1_9_1/test/bigdecimal/test_bigdecimal.rb =================================================================== --- ruby_1_9_1/test/bigdecimal/test_bigdecimal.rb (revision 20419) +++ ruby_1_9_1/test/bigdecimal/test_bigdecimal.rb (revision 20420) @@ -77,6 +77,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/