El 26/02/2011 16:27, Marco van de Voort escribió:
I never really started it, but one of the things I noticed is that the CPU
instructions for certain goniometric functions don't always accept the full
domain. How have you dealt with that in your code generation (or am I wrong,
it is over 7 years ago that I made this)
Yes, the range of argument is -2^63 to 2^63. I follow a suggestion of
INTEL: first apply a mod pi or mod 2*pi call for the argument
(there is an instruction for this, FPREM), and then apply cos, sin or
sincos. This should guarantees better performance, but for greater
arguments the FPREM becomes simply innacurate and useless: thus it
only serves as a dodge for the exception that would throw the FPU.
But in my
approach, instead of computing the cosine, it is computed the sincos
pair by using the x87 instruction of AMD or Intel. The two values are
used directly for computing the first and second derivatives: thus at
most _one_ call to an expensive FPU instruction.
I don't fully understand this. In my approach I calculate d(cos(x))/dx =
-sin(x) and then d(-sin(x)/dx = -cos(x) and only then use one floating
- point instruction to calculate the cosinus.
My rationale is that in serious mathematics, most time it is useless
to compute the derivatives without computing also the value of the
function. Thus, the call of sincos in a RPN step will give the
function value and, by a further multiplication and sign change, that
of its derivative. Also, for other expensive functions, the derivative
is a simple function of the function value. For instance, tan' = 1 +
tan^2. So, once computed tan (the function), we obtain easily also the
derivative.
Also, if with your approach you must compute the derivative of the
function
x * cos(x),
you will compute
cos(x)- x*sin(x).
And for the second derivative
-sin(x) - sin(x) - x* cos(x),
because the computation of simplifications is an enormous task:
therefore you will call two ot three expensive trig functions. My
approach will compute only sincos once.
Another thing that is easy in my approach is to call from the object
code any external function given in software: I use this for computing
functions given by integrals (though this with much less precision).
Or do you mean for stuff like Taylor where each term is a further
differentation?
No, I have seen this in your library, but I don'use Taylor.
--
montesin at uv dot es
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal