Richard Damon writes:
To make it so that sindeg/cosdeg of multiples of 90 come out exact is probably easiest to do by doing the angle reduction in degrees (so the nice precise angles stay as nice precise angles) and then either adjust the final computation formulas for degrees, or convert the angle to radians and let the fundamental routine do the small angle computation.
You would still need some sort of correction for many angles because of the nature of floating point computation. The modern approach is that floating point is exact computation but some numbers can't be exactly represented. Since Pi is irrational, Pi/4 is too, so it definitely cannot be represented. Making a correction to a number that "looks like" Pi/4 is against this philosophy. So you need separate functions (a "high school mode" argument would be frowned upon, I think).
While we are at it, it might be worth thinking if it might make sense to also define a set of functions using circles as a unit (90 degrees = 0.25, one whole revolution = 1)
While 1/4 is no problem, 1/6 is not exactly representable as a binary floating point number, and that's kind of an important angle for high school trigonometry (which is presumably what we're talking about here -- a symbolic math program would not represent Pi by a floating point number, but rather as a symbol with special properties as an argument to a trigonometric function!) My bias is that people who want to program this kind of thing just need to learn about floating point numbers and be aware that they're going to have to accept that
from math import cos, radians cos(radians(90)) 6.123233995736766e-17
is good enough for government work, including at the local public high school. Of course, I admit that's a bias, not a scientific fact. :-) -- Associate Professor Division of Policy and Planning Science http://turnbull.sk.tsukuba.ac.jp/ Faculty of Systems and Information Email: firstname.lastname@example.org University of Tsukuba Tel: 029-853-5175 Tennodai 1-1-1, Tsukuba 305-8573 JAPAN