Sin, cos etc for Python 2 Decimal? -
in python 2.6, found decimal equivalent of sqrt(pi)
is
decimal(pi).sqrt()
is there sin, cos or other (inverse) trigonometric functions?
the docs mention how calculate cos
, sin
computationally. decimal(pi).cos()
doesn't exist nor from decimal import cos
update: problem using default trigonometric functions defeats point of using decimal
if convert them float , every time want calculate something. (also typing decimal
around every calculation annoying, guess make wrapper function)
values of sin(a) , cos(a) rational numbers particular angles (see http://planetmath.org/encyclopedia/rationalsineandcosine.html ) can't store values of sin(a) or cos(a) decimals without losing precision. defeats purpose of converting sin , cos values decimal , having built-in functions return sin , cos values decimals.
moreover, can't store rational numbers decimal without losing precision because python's decimals (-1)**_sign * _int * 10**_exp
divisor of rational number must 10 decimal store full precision.
i guess @carrot-top's mpmath advice or numeric algorithm (like taylor series approximation) best can get.
Comments
Post a Comment