On 2018-06-08 01:44, Yuval Greenfield wrote:
On Thu, Jun 7, 2018 at 10:38 PM Stephen J. Turnbull <turnbull.stephen.fw@u.tsukuba.ac.jp <mailto:turnbull.stephen.fw@u.tsukuba.ac.jp>> wrote:
6.123233995736766e-17 >>>
is good enough for government work, including at the local public high school.
There probably is room for a library like "fractions" that represents multiples of pi or degrees precisely. I'm not sure how complicated or valuable of an endeavor that would be. But while I agree that floating point is good enough, we probably can do better.
Yes, I agree with making a module (called `rational_trig`?), that defines some Angle constants, and defines trig functions that accept Angle objects. Using angle objects will prevent the explosion of unit-specific variations on the trig functions (sin, sindeg, singrad, etc). Like mentioned above, the Angle object is probably best implemented as a Rational of 2*pi, which will allow our favorite angles to be represented without floating point error. We can define `degrees` and `radians` constants which can be used as units; then trig looks something like: from rational_trig import cos if cos(90*degrees) == 0: print("yay!") It is probably slow as molasses, but maybe good enough for a teaching environment?