File tree Expand file tree Collapse file tree 2 files changed +5
-10
lines changed Expand file tree Collapse file tree 2 files changed +5
-10
lines changed Original file line number Diff line number Diff line change @@ -183,11 +183,8 @@ def power(y, prec = nil)
183
183
#
184
184
def sqrt ( prec )
185
185
Internal . validate_prec ( prec , :sqrt , accept_zero : true )
186
- if infinite? == 1
187
- exception_mode = BigDecimal . mode ( BigDecimal ::EXCEPTION_ALL )
188
- raise FloatDomainError , "Computation results in 'Infinity'" if exception_mode . anybits? ( BigDecimal ::EXCEPTION_INFINITY )
189
- return INFINITY
190
- end
186
+ return Internal . infinity_computation_result if infinite? == 1
187
+
191
188
raise FloatDomainError , 'sqrt of negative value' if self < 0
192
189
raise FloatDomainError , "sqrt of 'NaN'(Not a Number)" if nan?
193
190
return self if zero?
Original file line number Diff line number Diff line change @@ -1395,15 +1395,13 @@ def test_sqrt_bigdecimal
1395
1395
1396
1396
assert_in_delta ( BigDecimal ( "4.0000000000000000000125" ) , BigDecimal ( "16.0000000000000000001" ) . sqrt ( 100 ) , BigDecimal ( "1e-40" ) )
1397
1397
1398
- BigDecimal . mode ( BigDecimal ::EXCEPTION_OVERFLOW , false )
1399
- BigDecimal . mode ( BigDecimal ::EXCEPTION_NaN , false )
1400
- assert_raise_with_message ( FloatDomainError , "sqrt of 'NaN'(Not a Number)" ) { BigDecimal ( "NaN" ) . sqrt ( 1 ) }
1401
- assert_raise_with_message ( FloatDomainError , "sqrt of negative value" ) { BigDecimal ( "-Infinity" ) . sqrt ( 1 ) }
1398
+ assert_raise_with_message ( FloatDomainError , "sqrt of 'NaN'(Not a Number)" ) { BigDecimal ::NAN . sqrt ( 1 ) }
1399
+ assert_raise_with_message ( FloatDomainError , "sqrt of negative value" ) { NEGATIVE_INFINITY . sqrt ( 1 ) }
1402
1400
1403
1401
assert_equal ( 0 , BigDecimal ( "0" ) . sqrt ( 1 ) )
1404
1402
assert_equal ( 0 , BigDecimal ( "-0" ) . sqrt ( 1 ) )
1405
1403
assert_equal ( 1 , BigDecimal ( "1" ) . sqrt ( 1 ) )
1406
- assert_positive_infinite ( BigDecimal ( "Infinity" ) . sqrt ( 1 ) )
1404
+ assert_positive_infinite_calculation { BigDecimal :: INFINITY . sqrt ( 1 ) }
1407
1405
1408
1406
# Out of float range
1409
1407
assert_equal ( BigDecimal ( '12e1024' ) , BigDecimal ( '144e2048' ) . sqrt ( 10 ) )
You can’t perform that action at this time.
0 commit comments