Sin, cos etc for Python 2 Decimal?
decimal, precision, python, trigonometry
Solution
Values of sin(a) and cos(a) are rational numbers only for particular angles (see Link ) so you can't store values of sin(a) or cos(a) as Decimals without losing precision. This defeats the purpose of converting sin and cos values to Decimal and having built-in functions that return sin and cos values as Decimals.
Moreover, you can't store all rational numbers as Decimal without losing precision because python's decimals are `(-1)**_sign * _int * 10**_exp` so the divisor of a rational number must be 10 for Decimal to store it with full precision.
I guess @carrot-top's mpmath advice or some numeric algorithm (like Taylor series approximation) is the best you can get.
Problem
In Python 2.6, I found that the Decimal equivalent of `sqrt(pi)` is ``` Decimal(pi).sqrt() ``` Is there anything like that for sin, cos or other (inverse) trigonometric functions? The docs only mention how to calculate `cos` and `sin` computationally. `Decimal(pi).cos()` doesn't exist nor does `from decimal import cos` Update: the problem with using the default trigonometric functions is that it defeats the point of using `Decimal` if I convert them from float and back every time I want to calculate something. (Also typing `Decimal` around every calculation is annoying, but I guess I could make a wrapper function)