spotlessmind1975 / ugbasic

An isomorphic BASIC language compiler for retrocomputers
Apache License 2.0
94 stars 16 forks source link

Extend precision of trigonometric functions #756

Open spotlessmind1975 opened 6 months ago

spotlessmind1975 commented 6 months ago

The trigonometric functions are implemented by means of a third grade Taylor polinomy. It follows that the returned value will tend to diverge from the expected one as the value of the angle increases. Actually, the maximum precision is obtained in the range from 0 to 90 degrees (from 0 to 1.5708 radians).

image

This should not be a great limit because it is possible to calculate the value for a higher angle using trigonometric angle equivalence formulas, which by the way in some cases is even faster, as well as being accurate. It is suggested to introduce a "wrapper" for the calculation, in order to have a better precision on -360...360 degree.

spotlessmind1975 commented 3 weeks ago

It is currently partially implemented on 6502, to be done on other processors.