@@ -460,6 +460,45 @@ def test_exception_overflow
460460 end
461461 end
462462
463+ def test_mult_div_overflow_underflow_sign
464+ BigDecimal . mode ( BigDecimal ::EXCEPTION_OVERFLOW , false )
465+ BigDecimal . mode ( BigDecimal ::EXCEPTION_UNDERFLOW , false )
466+
467+ large_x = BigDecimal ( "10" )
468+ 100 . times do
469+ x2 = large_x * large_x
470+ break if x2 . infinite?
471+ large_x = x2
472+ end
473+
474+ small_x = BigDecimal ( "0.1" )
475+ 100 . times do
476+ x2 = small_x * small_x
477+ break if x2 . zero?
478+ small_x = x2
479+ end
480+
481+ assert_positive_infinite ( large_x * large_x )
482+ assert_negative_infinite ( large_x * ( -large_x ) )
483+ assert_negative_infinite ( ( -large_x ) * large_x )
484+ assert_positive_infinite ( ( -large_x ) * ( -large_x ) )
485+
486+ assert_positive_zero ( small_x * small_x )
487+ assert_negative_zero ( small_x * ( -small_x ) )
488+ assert_negative_zero ( ( -small_x ) * small_x )
489+ assert_positive_zero ( ( -small_x ) * ( -small_x ) )
490+
491+ assert_positive_infinite ( large_x . div ( small_x , 10 ) )
492+ assert_negative_infinite ( large_x . div ( -small_x , 10 ) )
493+ assert_negative_infinite ( ( -large_x ) . div ( small_x , 10 ) )
494+ assert_positive_infinite ( ( -large_x ) . div ( -small_x , 10 ) )
495+
496+ assert_positive_zero ( small_x . div ( large_x , 10 ) )
497+ assert_negative_zero ( small_x . div ( -large_x , 10 ) )
498+ assert_negative_zero ( ( -small_x ) . div ( large_x , 10 ) )
499+ assert_positive_zero ( ( -small_x ) . div ( -large_x , 10 ) )
500+ end
501+
463502 def test_exception_zerodivide
464503 BigDecimal . mode ( BigDecimal ::EXCEPTION_OVERFLOW , false )
465504 _test_mode ( BigDecimal ::EXCEPTION_ZERODIVIDE ) { 1 / BigDecimal ( "0" ) }
0 commit comments