@@ -9,6 +9,7 @@ class TestBigMath < Test::Unit::TestCase
9
9
# SQRT in 116 (= 100 + double_fig) digits
10
10
SQRT2 = BigDecimal ( "1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309123" )
11
11
SQRT3 = BigDecimal ( "1.7320508075688772935274463415058723669428052538103806280558069794519330169088000370811461867572485756756261414154067" )
12
+ SQRT5 = BigDecimal ( "2.2360679774997896964091736687312762354406183596115257242708972454105209256378048994144144083787822749695081761507738" )
12
13
PINF = BigDecimal ( "+Infinity" )
13
14
MINF = BigDecimal ( "-Infinity" )
14
15
NAN = BigDecimal ( "NaN" )
@@ -33,6 +34,17 @@ def test_sqrt
33
34
assert_relative_precision { |n | sqrt ( BigDecimal ( "2e50" ) , n ) }
34
35
end
35
36
37
+ def test_hypot
38
+ assert_in_delta ( SQRT2 , hypot ( BigDecimal ( "1" ) , BigDecimal ( "1" ) , 100 ) , BigDecimal ( "1e-100" ) )
39
+ assert_in_delta ( SQRT5 , hypot ( SQRT2 , SQRT3 , 100 ) , BigDecimal ( "1e-100" ) )
40
+ assert_equal ( 0 , hypot ( BigDecimal ( 0 ) , BigDecimal ( 0 ) , N ) )
41
+ assert_equal ( PINF , hypot ( PINF , SQRT3 , N ) )
42
+ assert_equal ( PINF , hypot ( SQRT3 , MINF , N ) )
43
+ assert_relative_precision { |n | hypot ( BigDecimal ( "1e-30" ) , BigDecimal ( "2e-30" ) , n ) }
44
+ assert_relative_precision { |n | hypot ( BigDecimal ( "1.23" ) , BigDecimal ( "4.56" ) , n ) }
45
+ assert_relative_precision { |n | hypot ( BigDecimal ( "2e30" ) , BigDecimal ( "1e30" ) , n ) }
46
+ end
47
+
36
48
def test_sin
37
49
assert_in_delta ( 0.0 , sin ( BigDecimal ( "0.0" ) , N ) )
38
50
assert_in_delta ( Math . sqrt ( 2.0 ) / 2 , sin ( PI ( N ) / 4 , N ) )
0 commit comments