Handling rounding errors with trig