@@ -469,4 +469,28 @@ def test_expm1
469469 assert_in_exact_precision ( BigMath . exp ( BigDecimal ( "1.23e-10" ) , 120 ) - 1 , expm1 ( BigDecimal ( "1.23e-10" ) , 100 ) , 100 )
470470 assert_in_exact_precision ( BigMath . exp ( 123 , 120 ) - 1 , expm1 ( BigDecimal ( "123" ) , 100 ) , 100 )
471471 end
472+
473+ def test_frexp
474+ BigDecimal . save_limit do
475+ BigDecimal . limit ( 3 )
476+ assert_equal ( [ BigDecimal ( "-0.123456" ) , 10 ] , BigMath . frexp ( BigDecimal ( "-0.123456e10" ) ) )
477+ assert_equal ( [ BigDecimal ( "0.123456" ) , -10 ] , BigMath . frexp ( BigDecimal ( "0.123456e-10" ) ) )
478+ assert_equal ( [ BigDecimal ( "0.123456789" ) , 9 ] , BigMath . frexp ( 123456789 ) )
479+ assert_equal ( [ BigDecimal ( 0 ) , 0 ] , BigMath . frexp ( BigDecimal ( 0 ) ) )
480+ assert_equal ( [ BigDecimal ::NAN , 0 ] , BigMath . frexp ( BigDecimal ::NAN ) )
481+ assert_equal ( [ BigDecimal ::INFINITY , 0 ] , BigMath . frexp ( BigDecimal ::INFINITY ) )
482+ end
483+ end
484+
485+ def test_ldexp
486+ BigDecimal . save_limit do
487+ BigDecimal . limit ( 3 )
488+ assert_equal ( BigDecimal ( "-0.123456e10" ) , BigMath . ldexp ( BigDecimal ( "-0.123456" ) , 10 ) )
489+ assert_equal ( BigDecimal ( "0.123456e20" ) , BigMath . ldexp ( BigDecimal ( "0.123456e10" ) , 10.9 ) )
490+ assert_equal ( BigDecimal ( "0.123456e-10" ) , BigMath . ldexp ( BigDecimal ( "0.123456" ) , -10 ) )
491+ assert_equal ( BigDecimal ( "0.123456789e19" ) , BigMath . ldexp ( 123456789 , 10 ) )
492+ assert ( BigMath . ldexp ( BigDecimal ::NAN , 10 ) . nan? )
493+ assert_equal ( BigDecimal ::INFINITY , BigMath . ldexp ( BigDecimal ::INFINITY , 10 ) )
494+ end
495+ end
472496end
0 commit comments