Re: Floating point: sine, cosine etc.

From: gsteemso <48bitsorbust_at_gmail.com>
Date: Thu, 13 Oct 2022 06:39:58 -0700
Message-Id: <6E081A27-FADB-44DF-9790-F8B7C0C42E17_at_gmail.com>
I'd start from "tan(x) = sin(x)/cos(x)" and see what happens when you express that division in terms of their expansions, whichever expansions you end up using.  As you can guess from cos(x) equalling zero twice per complete circle, every tan(x) calculation has two divide-by-zero issues to work around in that same span, but since the results repeat every half-circle it's simple enough if you adjust your input ranges properly.  The only really irritating part is that the result changes very rapidly relative to the input at the farthest input values -- if you graph it, you'll see there are vertical asymptotes there.

What you do with this is up to you, of course; hope it helps at least a little.

Gordon S.

> On Oct 12, 2022, at 11:19 PM, Baltissen, GJPAA (Ruud) <ruud.baltissen_at_apg.nl> wrote:
> 
> 
> Hallo Jesús,
>  
>  
> > Maybe you mean 64 bit mantissa?
>  
> I am not sure if this question was for me. The size of the mantissa or exponent don't matter. Everyone knows about the 32 and 64 FP numbers used in various higher languages and 80-bit ones used in 8087 co-processors. But few know about the fact that Commodore BASIC uses 40-bit FP numbers. The UCR library, known from the first series of the "Art of Assembler" books uses 32 and 64 bits as well but... in an slightly other order. From these two main facts plus several side remarks on forums I learned that size doesn't matter. What does matter is that those bits can be handled in an easy way for calculations. No problems so far for me. _How_ the calculations should be done, that is another matter.
> As said before, I use 16 bits for the exponent and 80 for the mantissa. Main reason: scaling down is easier than scaling up.
>  
>  
> > This was high school material in Spain in my days, I don't know today.
>  
> Great, so I can ask you questions about it 😊
>  
>  
> > sin(x) ~= x - x^3/3! + x^5/5! - x^7/7 + .... (you can add more terms)
> +
> > To efficiently compute the polynomial, try Horner algorithm:
>  
> I already do use Horner's method but I ran into one problem so far: I was able to find or calculate the needed coefficients A0, A1, ...., An for various functions like Sine, Cosine, ln, etc. but not for Tangens. Can you?
>  
>  
> > For an interesting twist for trigonometric/logarithmic functions, check CORDIC algorithm.
>  
> I had a good look at it in Wikipedia. I liked the sentence " as the only operations it requires are additions, subtractions, bitshift and lookup tables. ". That would be ideal for a 6502 or Z80. But I had troubles with the detailed explanation and even the example. But at the end the article lead me to https://en.wikipedia.org/wiki/BKM_algorithm which was easier to understand. 
> But for the moment I stick to polynomials because they have one advantage: AFAIK all coefficients can be calculated (even those of Tangens, but how?). This is quite slower than using tables but the disadvantage of tables is that they need space. A good example: Commodore BASIC only has stored some basic values but calculates the rest.
> 
> I hope to hear from you!
>  
>  
> With kind regards / Met vriendelijke groet, Ruud Baltissen
>  
> http://www.baltissen.org
>  
>  
>  
>  
> 
> De informatie in dit e-mailbericht is vertrouwelijk en uitsluitend bestemd voor de 
> geadresseerde. Wanneer u dit bericht per abuis ontvangt, verzoeken wij u contact op te 
> nemen met de afzender per kerende e-mail. Verder verzoeken wij u in dat geval dit 
> e-mailbericht te vernietigen en de inhoud ervan aan niemand openbaar te maken. 
> Wij aanvaarden geen aansprakelijkheid voor onjuiste, onvolledige dan wel ontijdige 
> overbrenging van de inhoud van een verzonden e-mailbericht, noch voor daarbij 
> overgebrachte virussen.
> 
> APG Groep N.V. is gevestigd te Heerlen en is ingeschreven in het 
> handelsregister van de Kamer van Koophandel Limburg onder nummer 14099617
> 
> 
> The information contained in this e-mail is confidential and may be privileged. 
> It may be read, copied and used only by the intended recipient. 
> If you have received it in error, please contact the sender immediately by 
> return e-mail; please delete in this case the e-mail and do not disclose its 
> contents to any person. We don't accept liability for any errors, omissions, 
> delays of receipt or viruses in the contents of this message which arise as a 
> result of e-mail transmission.
> 
> APG Groep N.V. is registered in the trade register of the Chamber 
> of Commerce Limburg, The Netherlands, registration number: 14099617
Received on 2022-10-13 16:00:04

Archive generated by hypermail 2.3.0.