ArcTangent

Another interesting calculation:

Arithmetic

*/

This is a perfect application for */. A number is multiplied by a ratio. I see it as simpler, faster and more accurate than /. and *..

!oct

Shifts a sign bit into register a. Uses the trick - 2* - to shift in a 1.

min

The standard library function is modified by adding a call to !oct at the right time.

abs

The standard library function is modified by adding a call to !oct.

Function

Hart's approximation is:It's good to 5 decimals. His coefficients compute the angle in radians. I scale the numerator to produce the right answer at sin(45o). This requires multiplying by 65536/10pi to get a 16-bit fraction. The denominator is multiplied by 65536/10.

A table of offsets for the 8 octants is stored at 0. When the computed 15-bit angle is added, the result will be an 18-bit fraction. Half the octants require the angle be reversed.

atan

Arguments are 2 17-bit fractions, cos on top, sin beneath.

(atan will leave stuff on the stack. Doesn't matter since it's so big it will always have its own node.)

The octant is coded as the number csr

So the order of the octant table in normal octant numbering is: 0, 1, 7, 6, 3, 2, 4, 5.

Validation

Given an angle, sin and cos are computed and from them atan. The result is compared to the original angle.

I can display 768 points at a time and have done so for various samplings of the 262,144 possible angles. Error seems to be +- 1 bit. Further testing will be done when atan is used.