No subject
Sun Nov 12 08:01:13 CET 2006
"""
The modulo operator always yields a result with the same sign as
its second operand (or zero); the absolute value of the result
is strictly smaller than the second operand.
"""
I don't know what you are doing, but remember that you can't represent
2*PI exactly unless you invent a scaled unit for it. E.g. you could define
exactly one (i.e., 1.0) turn to be equal to exactly 2*pi mathematical radians.
Then if you have an angle in turn units, angle-int(angle) will do
an effective modulo 2*PI on the absolute value of your angle and leave
the sign intact. If you want to go even further, you might want to represent
turns as rationals instead of floats, or define a fractional turn unit suitable
for your application. Of course you always have to multiply by a scale factor before
calling sin or cos etc, but you can avoid accumulating angular errors if your
problem steps in exact increments. OTOH the error in doubles is small enough
for most practical problems.
Regards,
Bengt Richter
More information about the Python-list
mailing list