On Sat, 10 Mar 2001 21:37:28 -0800, Farooq Mela <[EMAIL PROTECTED]> wrote:
>Jordan DeLong wrote:
>> I was thinking of just getting a sintable array and making a few simple
>> functions, so the whole of libm doesn't need to be statically linked into the
>> module (from my understanding, once loaded, this module wont ever get paged
>+out,
>> and thus it'd be _bad_ for it to be big).
>
>Well, you can't do any FP stuff inside the kernel, as stated by others.
>But what you can do is use the fact that:
>
>sin(x) = x - (x^3)/3! + (x^5)/5! - (x^7)/7! ...

Actually, whilst Taylor expansions are mathematically nice, they are
generally a very poor implementation choice - primarily because they
are infinite series and can be very slow to converge for large x.
Trig functions are normally implemented as truncated Taylor series
(you pick a finite expansion and tweak the co-efficients to minimise
error), or ratios of polynomials.  In both cases, the polynomials
need to be `tuned' to suit the FP precision.

If you do decide to go the fixed-point approach, remember that
multiplication and division need fixups afterwards to re-align the
binary point.  (Multiplying two numbers with a 24 bit fraction gives
a result with a 48 bit fraction).  If you did pick a 24-bit fraction,
you could probably pinch the co-efficients out of the `float' trig
functions in msun.

For a totally different approach, try Cordic algorithms.  Cordic
algorithms let you implement circular and hyperbolic functions
(including exponential, log and sqrt) using add, subtract, shift and
table lookup.  (An n-bit result needs an n-entry x n-bit table, 2n
shifts and 3n adds/subtracts).  I know there was an article in October
1990 Dr Dobbs Journal and a web search should probably find plenty
more.

Peter

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to