Re: Floating point: sine, cosine etc.

From: Michal Pleban <lists_at_michau.name>
Date: Thu, 29 Sep 2022 21:20:43 +0200
Message-ID: <ae0e1848-d34b-c839-7a78-ee91833dd7dc_at_michau.name>
ruud_at_baltissen.org wrote on 28.09.2022 21:21:

> Hallo MichaƂ,

> The idea is to use tables instead of calculating the various factors. In 
> the final assembly version this will constants in FP format, not 
> variables. That reduces your formula to the first FOR loop.
> Knowing, thanks to you, where to look for, I found Horner's method which 
> reduced the FOR loop even further. I even can reduce the number of steps 
> by skipping those steps where arFacSin[b] is zero (plus some other 
> needed changes).

All very good ideas. One more: If the "s" variable from the previous 
step is the same as the one from the current step, stop the loop because 
this means that you have reached the maximum accuracy of your floating 
point numbers and any further steps will not improve the result any 
further. This is what CBM BASIC does, that's why calculating SIN(0) 
takes much less time than calculating SIN(PI/2).

> Next step is tangens. I found the formula but here I ran into trouble: 
> https://en.wikipedia.org/wiki/Trigonometric_functions#Power_series_expansion 
> . The formula includes Bernoulli numbers and from here on I couldn't 
> follow it anymore. 

Hm, from what I can see it's basically the same formula that you have 
for SIN(X), except the table is different:

arFacTan[0] := 0
arFacTan[1] := 1
arFacTan[2] := 0
arFacTan[3] := 1/3
arFacTan[4] := 0
arFacTan[5] := 2/15
arFacTan[6] := 0
arFacTan[7] := 17/315

What goes further, I would have to calculate since it's been like 20 
years since I have last done this stuff. But it shouldn't be hard.

In fact, now that I look at it, all the other trigonometric functions 
can be also expressed by your mechanism just using a different table. 
That is kinda neat.

> Next steps: EXP, LN, LOG, etc., etc. But know I know on who's door to 
> knock :)

I'll be glad to help too!

Regards,
Michau.
Received on 2022-09-29 22:00:04

Archive generated by hypermail 2.3.0.