--- In [email protected], Thomas Hruska <[EMAIL PROTECTED]> wrote: > > jagomaniak wrote: > > Hello, > > I'm writing a program computing the tg function with sin/cos. However, > > I'm not allowed to use the math.h fuction for either of it, so I'm > > quite stuck as how to implement it. > > > > Any help is appreciated! > > A Taylor Series is definitely the way to go if you are rolling your own.
I used to have a copy of the ZX Spectrum ROM Disassembly which included the (Z80 machine) code for evaluating trig functions within its BASIC interpreter. But you can now see it online: ftp://ftp.worldofspectrum.org/pub/sinclair/books/CompleteSpectrumROMDisassemblyThe.pdf The Spectrum used Chebyshev polynomials: http://en.wikipedia.org/wiki/Chebyshev_polynomials The book includes a BASIC listing of the method used in the machine code (printed page 223, PDF page 228), which should be relatively easy to convert into C. I couldn't say which is 'better' out of Taylor series or Chebyshev polynomials, although the authors of Spectrum BASIC tended to go for small code size rather than ultimate speed in order to fit a BASIC interpreter into 16k. That left what was at the time a generous 48k for RAM, including 6k screen memory. John
