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 @@ -147,11 +147,8 @@ def power(y, prec = nil)
147
147
#
148
148
def sqrt ( prec )
149
149
BigMath . _validate_prec ( prec , :sqrt , accept_zero : true )
150
- if infinite? == 1
151
- exception_mode = BigDecimal . mode ( BigDecimal ::EXCEPTION_ALL )
152
- raise FloatDomainError , "Computation results in 'Infinity'" if exception_mode . anybits? ( BigDecimal ::EXCEPTION_INFINITY )
153
- return INFINITY
154
- end
150
+ return BigMath . _infinity_computation_result if infinite? == 1
151
+
155
152
raise FloatDomainError , 'sqrt of negative value' if self < 0
156
153
raise FloatDomainError , "sqrt of 'NaN'(Not a Number)" if nan?
157
154
return self if zero?
Original file line number Diff line number Diff line change @@ -1383,15 +1383,13 @@ def test_sqrt_bigdecimal
1383
1383
1384
1384
assert_in_delta ( BigDecimal ( "4.0000000000000000000125" ) , BigDecimal ( "16.0000000000000000001" ) . sqrt ( 100 ) , BigDecimal ( "1e-40" ) )
1385
1385
1386
- BigDecimal . mode ( BigDecimal ::EXCEPTION_OVERFLOW , false )
1387
- BigDecimal . mode ( BigDecimal ::EXCEPTION_NaN , false )
1388
- assert_raise_with_message ( FloatDomainError , "sqrt of 'NaN'(Not a Number)" ) { BigDecimal ( "NaN" ) . sqrt ( 1 ) }
1389
- assert_raise_with_message ( FloatDomainError , "sqrt of negative value" ) { BigDecimal ( "-Infinity" ) . sqrt ( 1 ) }
1386
+ assert_raise_with_message ( FloatDomainError , "sqrt of 'NaN'(Not a Number)" ) { BigDecimal ::NAN . sqrt ( 1 ) }
1387
+ assert_raise_with_message ( FloatDomainError , "sqrt of negative value" ) { NEGATIVE_INFINITY . sqrt ( 1 ) }
1390
1388
1391
1389
assert_equal ( 0 , BigDecimal ( "0" ) . sqrt ( 1 ) )
1392
1390
assert_equal ( 0 , BigDecimal ( "-0" ) . sqrt ( 1 ) )
1393
1391
assert_equal ( 1 , BigDecimal ( "1" ) . sqrt ( 1 ) )
1394
- assert_positive_infinite ( BigDecimal ( "Infinity" ) . sqrt ( 1 ) )
1392
+ assert_positive_infinite_calculation { BigDecimal :: INFINITY . sqrt ( 1 ) }
1395
1393
1396
1394
# Out of float range
1397
1395
assert_equal ( BigDecimal ( '12e1024' ) , BigDecimal ( '144e2048' ) . sqrt ( 10 ) )
You can’t perform that action at this time.
0 commit comments