[libre-riscv-dev] [isa-dev] Re: FP transcendentals (trigonometry, root/exp/log) proposal

Mitchalsup mitchalsup at aol.com
Thu Jan 16 21:30:30 GMT 2020



Mitch AlsupMitchAlsup at aol.com

-----Original Message-----
From: Jacob Lifshay <programmerjake at gmail.com>
To: Mitchalsup <mitchalsup at aol.com>
Cc: Libre-RISCV General Development <libre-riscv-dev at lists.libre-riscv.org>
Sent: Thu, Jan 16, 2020 3:13 pm
Subject: Re: [libre-riscv-dev] [isa-dev] Re: FP transcendentals (trigonometry, root/exp/log) proposal

On Thu, Jan 16, 2020, 09:53 Mitchalsup <mitchalsup at aol.com> wrote:


Newton Raphson is basically useless for functions like sin or cos, since you have to compute the inverse function (asin or acos) to a higher accuracy which takes even more work than just computing the function to enough accuracy in the first place.
You have to compute the derivative of SIN() and COS() which just happen to be COS() and -SIN(). But I am not doing this with NR..

I was thinking that to use NR to compute cos(x) = y, you'd construct the function:f(y) = acos(y) - xand solve it for zero using NR:
y[n+1] = y[n] - f(y[n]) / f'(y[n])

f'(y) = -1 / sqrt(1 - y^2)
y[n+1] = y[n] - (acos(y[n]) - x) / (-1 / sqrt(1 - y[n]^2))
and similarly for sin(x) = y
obviously, computing acos takes about as much work as computing cos in the first place, making NR basically useless for computing cos (it also probably has other issues too, such as |y[n]| > 1 for some n).
Given that x[n] is a decent representation for the required result, one only needs the slope of  f(x)/f'(x) in order to improve the accuracy, this dramatically streamlines the iteration.
If x[n+1] is not a decent representation, all bets are off.

Newton Raphson is useful for square-roots because computing the inverse function (and its derivative) to high accuracy is easy (just multiplication and addition).
Jacob


More information about the libre-riscv-dev mailing list