File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 7
7
# sqrt(x, prec)
8
8
# sin (x, prec)
9
9
# cos (x, prec)
10
+ # tan (x, prec)
10
11
# atan(x, prec) Note: |x|<1, x=0.9999 may not converge.
11
12
# PI (prec)
12
13
# E (prec) == exp(1.0,prec)
@@ -132,6 +133,24 @@ def cos(x, prec)
132
133
y
133
134
end
134
135
136
+ # call-seq:
137
+ # tan(decimal, numeric) -> BigDecimal
138
+ #
139
+ # Computes the tangent of +decimal+ to the specified number of digits of
140
+ # precision, +numeric+.
141
+ #
142
+ # If +decimal+ is Infinity or NaN, returns NaN.
143
+ #
144
+ # BigMath.tan(BigDecimal("0.0"), 4).to_s
145
+ # #=> "0.0"
146
+ #
147
+ # BigMath.tan(BigMath.PI(4) / 4, 4).to_s
148
+ # #=> "0.999999999999999999999955588155008544487055622030633191403625599381672572e0"
149
+ #
150
+ def tan ( x , prec )
151
+ sin ( x , prec ) / cos ( x , prec )
152
+ end
153
+
135
154
# call-seq:
136
155
# atan(decimal, numeric) -> BigDecimal
137
156
#
Original file line number Diff line number Diff line change @@ -53,6 +53,16 @@ def test_cos
53
53
assert_in_delta ( 0.0 , cos ( PI ( N ) * BigDecimal ( "301.5" ) , N ) )
54
54
end
55
55
56
+ def test_tan
57
+ assert_in_delta ( 0.0 , tan ( BigDecimal ( "0.0" ) , N ) )
58
+ assert_in_delta ( 0.0 , tan ( PI ( N ) , N ) )
59
+ assert_in_delta ( 1.0 , tan ( PI ( N ) / 4 , N ) )
60
+ assert_in_delta ( Math . sqrt ( 3.0 ) , tan ( PI ( N ) / 3 , N ) )
61
+ assert_in_delta ( 0.0 , tan ( -PI ( N ) , N ) )
62
+ assert_in_delta ( -1.0 , tan ( -PI ( N ) / 4 , N ) )
63
+ assert_in_delta ( -Math . sqrt ( 3.0 ) , tan ( -PI ( N ) / 3 , N ) )
64
+ end
65
+
56
66
def test_atan
57
67
assert_equal ( 0.0 , atan ( BigDecimal ( "0.0" ) , N ) )
58
68
assert_in_delta ( Math ::PI /4 , atan ( BigDecimal ( "1.0" ) , N ) )
You can’t perform that action at this time.
0 commit comments