Skip to content

Commit 75b9190

Browse files
Hardwire return values for domain limits of arcsin and arccos
fix for issue #7 #7
1 parent 2356655 commit 75b9190

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

jepler_udecimal/utrig.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,13 @@ def asin(x, context=None):
198198

199199
with localcontext(context) as ctx:
200200
ctx.prec += 2
201-
r = atan(x / (1 - x * x).sqrt())
201+
pi = Decimal(1).atan() * 4
202+
if x == 1:
203+
r = pi / 2 # pi * 1/2 radians
204+
elif x == -1:
205+
r = pi * 3 / 2 # pi * 3/2 radians
206+
else:
207+
r = atan(x / (1 - x * x).sqrt())
202208
return r / 1
203209

204210

@@ -218,10 +224,15 @@ def acos(x, context=None):
218224

219225
with localcontext(context) as ctx:
220226
ctx.prec += 2
221-
r = atan((1 - x * x).sqrt() / x)
227+
if x == 1:
228+
r = Decimal(0). # 0 radians
229+
elif x == -1:
230+
r = Decimal(1).atan() * 4 # pi radians
231+
else:
232+
r = atan((1 - x * x).sqrt() / x)
222233
if r < 0:
223234
r += 4 * atan(1)
224-
return r
235+
return r / 1
225236

226237

227238
for name in __all__:

0 commit comments

Comments
 (0)