@@ -34,6 +34,26 @@ def test_sqrt
34
34
assert_relative_precision { |n | sqrt ( BigDecimal ( "2e50" ) , n ) }
35
35
end
36
36
37
+ def test_cbrt
38
+ assert_equal ( 1234 , cbrt ( BigDecimal ( 1234 **3 ) , N ) )
39
+ assert_equal ( -12345 , cbrt ( BigDecimal ( -12345 **3 ) , N ) )
40
+ assert_equal ( 123 ** 456 , cbrt ( BigDecimal ( 123 ** 456 ) ** 3 , N ) )
41
+ assert_equal ( 0 , cbrt ( BigDecimal ( "0" ) , N ) )
42
+ assert_equal ( 0 , cbrt ( BigDecimal ( "-0" ) , N ) )
43
+ assert_equal ( PINF , cbrt ( PINF , N ) )
44
+ assert_equal ( MINF , cbrt ( MINF , N ) )
45
+
46
+ assert_in_delta ( SQRT2 , cbrt ( SQRT2 ** 3 , 100 ) , BigDecimal ( "1e-100" ) )
47
+ assert_in_delta ( SQRT3 , cbrt ( SQRT3 ** 3 , 100 ) , BigDecimal ( "1e-100" ) )
48
+ assert_equal ( BigDecimal ( "3e50" ) , cbrt ( BigDecimal ( "27e150" ) , N ) )
49
+ assert_equal ( BigDecimal ( "-4e50" ) , cbrt ( BigDecimal ( "-64e150" ) , N ) )
50
+ assert_in_epsilon ( Math . cbrt ( 28e150 ) , cbrt ( BigDecimal ( "28e150" ) , N ) )
51
+ assert_in_epsilon ( Math . cbrt ( 27e151 ) , cbrt ( BigDecimal ( "27e151" ) , N ) )
52
+ assert_relative_precision { |n | cbrt ( BigDecimal ( "2" ) , n ) }
53
+ assert_relative_precision { |n | cbrt ( BigDecimal ( "2e-50" ) , n ) }
54
+ assert_relative_precision { |n | cbrt ( BigDecimal ( "2e50" ) , n ) }
55
+ end
56
+
37
57
def test_hypot
38
58
assert_in_delta ( SQRT2 , hypot ( BigDecimal ( "1" ) , BigDecimal ( "1" ) , 100 ) , BigDecimal ( "1e-100" ) )
39
59
assert_in_delta ( SQRT5 , hypot ( SQRT2 , SQRT3 , 100 ) , BigDecimal ( "1e-100" ) )
0 commit comments