@@ -551,6 +551,20 @@ def test_round_up
551
551
assert_equal ( -4 , m3h . round )
552
552
end
553
553
554
+ def test_round_positive_infinity
555
+ BigDecimal . mode ( BigDecimal ::EXCEPTION_INFINITY , false )
556
+ assert_nothing_raised do
557
+ assert_positive_infinite ( BigDecimal ::INFINITY . round )
558
+ end
559
+ end
560
+
561
+ def test_round_negative_infinity
562
+ BigDecimal . mode ( BigDecimal ::EXCEPTION_INFINITY , false )
563
+ assert_nothing_raised do
564
+ assert_negative_infinite ( ( -BigDecimal ::INFINITY ) . round )
565
+ end
566
+ end
567
+
554
568
def test_zero_p
555
569
BigDecimal . mode ( BigDecimal ::EXCEPTION_INFINITY , false )
556
570
BigDecimal . mode ( BigDecimal ::EXCEPTION_NaN , false )
@@ -1492,9 +1506,35 @@ def test_power_with_Bignum
1492
1506
end
1493
1507
end
1494
1508
1495
- def test_power_with_BigDecimal
1496
- assert_nothing_raised do
1497
- assert_in_delta ( 3 ** 3 , BigDecimal ( 3 ) ** BigDecimal ( 3 ) )
1509
+ data (
1510
+ "BigDecimal(3) ** BigDecimal(3) -> BigDecimal(3**3)" => [ BigDecimal ( 3 ) , BigDecimal ( 3 ) , BigDecimal ( 3 **3 ) ] ,
1511
+ "BigDecimal(10) ** Inf -> Inf" => [ BigDecimal ( 10 ) , BigDecimal ::INFINITY , :pos_inf ] ,
1512
+ "BigDecimal(10) ** NaN -> NaN" => [ BigDecimal ( 10 ) , BigDecimal ::NAN , :nan ] ,
1513
+ "Inf ** BigDecimal(0) -> BigDecimal(1)" => [ BigDecimal ::INFINITY , BigDecimal ( 0 ) , BigDecimal ( 1 ) ] ,
1514
+ "-Inf ** BigDecimal(0) -> BigDecimal(-1)" => [ -BigDecimal ::INFINITY , BigDecimal ( 0 ) , BigDecimal ( 1 ) ] ,
1515
+ "BigDecimal(1) ** Inf -> 1" => [ BigDecimal ( 1 ) , BigDecimal ::INFINITY , BigDecimal ( 1 ) ] ,
1516
+ "BigDecimal(1) ** -Inf -> 1" => [ BigDecimal ( 1 ) , -BigDecimal ::INFINITY , BigDecimal ( 1 ) ] ,
1517
+ "BigDecimal(0) ** Inf -> 0" => [ BigDecimal ( 0 ) , BigDecimal ::INFINITY , BigDecimal ( 0 ) ] ,
1518
+ "BigDecimal(0) ** -Inf -> Inf" => [ BigDecimal ( 0 ) , -BigDecimal ::INFINITY , :pos_inf ] ,
1519
+ "BigDecimal(-1) ** Inf -> Math::DomainError" => [ BigDecimal ( -1 ) , BigDecimal ::INFINITY , :math_domain_error ] ,
1520
+ "BigDecimal(-1) ** -Inf -> Math::DomainError" => [ BigDecimal ( -1 ) , -BigDecimal ::INFINITY , :math_domain_error ]
1521
+ )
1522
+ def test_power_with_BigDecimal ( data )
1523
+ BigDecimal . save_exception_mode do
1524
+ BigDecimal . mode ( BigDecimal ::EXCEPTION_ALL , false )
1525
+ x , y , res = *data
1526
+ case res
1527
+ when :pos_inf
1528
+ assert_nothing_raised { assert_positive_infinite ( x ** y ) }
1529
+ when :neg_inf
1530
+ assert_nothing_raised { assert_negative_infinite ( x ** y ) }
1531
+ when :nan
1532
+ assert_nothing_raised { assert_nan ( x ** y ) }
1533
+ when :math_domain_error
1534
+ assert_raise ( Math ::DomainError ) { x ** y }
1535
+ else
1536
+ assert_nothing_raised { assert_in_delta ( res , x ** y ) }
1537
+ end
1498
1538
end
1499
1539
end
1500
1540
0 commit comments