File tree Expand file tree Collapse file tree 3 files changed +9
-4
lines changed
Expand file tree Collapse file tree 3 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -637,7 +637,7 @@ def erfc(x, prec)
637637 return BigDecimal ::Internal . nan_computation_result if x . nan?
638638 return BigDecimal ( 1 - x . infinite? ) if x . infinite?
639639 return BigDecimal ( 1 ) . sub ( erf ( x , prec + BigDecimal ::Internal ::EXTRA_PREC ) , prec ) if x < 0.5
640- return BigDecimal ( 0 ) if x > 5000000000 # erfc(5000000000) < 1e-10000000000000000000 (underflow)
640+ return BigDecimal :: Internal . underflow_computation_result if x > 5000000000 # erfc(5000000000) < 1e-10000000000000000000 (underflow)
641641
642642 if x >= 8
643643 y = _erfc_asymptotic ( x , prec )
Original file line number Diff line number Diff line change @@ -83,12 +83,16 @@ def assert_negative_infinite_calculation(&block)
8383 assert_infinite_calculation ( positive : false , &block )
8484 end
8585
86- def assert_underflow_calculation
86+ def assert_underflow_calculation ( accept_overflow : false )
8787 BigDecimal . save_exception_mode do
8888 BigDecimal . mode ( BigDecimal ::EXCEPTION_UNDERFLOW , false )
89+ BigDecimal . mode ( BigDecimal ::EXCEPTION_OVERFLOW , false )
8990 assert_equal ( BigDecimal ( 0 ) , yield )
9091 BigDecimal . mode ( BigDecimal ::EXCEPTION_UNDERFLOW , true )
91- assert_raise_with_message ( FloatDomainError , /underflow/i ) { yield }
92+ BigDecimal . mode ( BigDecimal ::EXCEPTION_OVERFLOW , true )
93+ # Accept internal overflow (e.g. overflow calculating denominator part)
94+ pattern = accept_overflow ? /underflow|overflow/i : /underflow/i
95+ assert_raise_with_message ( FloatDomainError , pattern ) { yield }
9296 end
9397 end
9498
Original file line number Diff line number Diff line change @@ -521,7 +521,8 @@ def test_erfc
521521 end
522522 assert_equal ( 0 , BigMath . erfc ( PINF , N ) )
523523 assert_equal ( 2 , BigMath . erfc ( MINF , N ) )
524- assert_equal ( 0 , BigMath . erfc ( BigDecimal ( '1e400' ) , 10 ) )
524+ assert_underflow_calculation ( accept_overflow : true ) { BigMath . erfc ( 4999999999 , 10 ) }
525+ assert_underflow_calculation { BigMath . erfc ( BigDecimal ( '1e400' ) , 10 ) }
525526 assert_equal ( 2 , BigMath . erfc ( BigDecimal ( '-1e400' ) , 10 ) )
526527 assert_equal ( 1 , BigMath . erfc ( BigDecimal ( '1e-400' ) , N ) )
527528
You can’t perform that action at this time.
0 commit comments