File tree Expand file tree Collapse file tree 2 files changed +6
-1
lines changed Expand file tree Collapse file tree 2 files changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ def sin(x, prec)
85
85
d = sign * x1 . div ( z , m )
86
86
y += d
87
87
end
88
+ y = BigDecimal ( "1" ) if y > 1
88
89
neg ? -y : y
89
90
end
90
91
@@ -130,7 +131,7 @@ def cos(x, prec)
130
131
d = sign * x1 . div ( z , m )
131
132
y += d
132
133
end
133
- y
134
+ y < - 1 ? BigDecimal ( "-1" ) : y > 1 ? BigDecimal ( "1" ) : y
134
135
end
135
136
136
137
# call-seq:
Original file line number Diff line number Diff line change @@ -53,6 +53,8 @@ def test_sin
53
53
assert_fixed_point_precision { |n | sin ( BigDecimal ( "1e-30" ) , n ) }
54
54
assert_fixed_point_precision { |n | sin ( BigDecimal ( PI ( 50 ) ) , n ) }
55
55
assert_fixed_point_precision { |n | sin ( BigDecimal ( PI ( 50 ) * 100 ) , n ) }
56
+ assert_operator ( sin ( PI ( 30 ) / 2 , 30 ) , :<= , 1 )
57
+ assert_operator ( sin ( -PI ( 30 ) / 2 , 30 ) , :>= , -1 )
56
58
end
57
59
58
60
def test_cos
@@ -74,6 +76,8 @@ def test_cos
74
76
assert_fixed_point_precision { |n | cos ( BigDecimal ( "1e50" ) , n ) }
75
77
assert_fixed_point_precision { |n | cos ( BigDecimal ( PI ( 50 ) / 2 ) , n ) }
76
78
assert_fixed_point_precision { |n | cos ( BigDecimal ( PI ( 50 ) * 201 / 2 ) , n ) }
79
+ assert_operator ( cos ( PI ( 30 ) , 30 ) , :>= , -1 )
80
+ assert_operator ( cos ( PI ( 30 ) * 2 , 30 ) , :<= , 1 )
77
81
end
78
82
79
83
def test_atan
You can’t perform that action at this time.
0 commit comments