avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] tanh in libm


From: René Liebscher
Subject: Re: [avr-libc-dev] tanh in libm
Date: Thu, 16 Sep 2004 11:31:24 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040804

E. Weddington wrote:
René Liebscher wrote:

Hi,

I have question about the tanh function in libm.

As I can see in
http://savannah.nongnu.org/cgi-bin/viewcvs/avr-libc/avr-libc/libm/fplib/tanh.S?rev=1.2&content-type=text/vnd.viewcvs-markup
there are two ways to calculate the result.

The questions is why was sinh/cosh choosen. (The other way is commented out.) Comparing which functions are called to calculate tanh I find sinh/cosh needs one call to exp, two calls to inverse and one call to ldexp more than the other way. So I think the current solution is slower than the other.
(And it takes more memory if you don't use sinh or cosh in your program.)


AFAIK, the whole math library in avr-libc was a port of Michael Stumpf's FPLib library to the AVR. See the readme.fplib file in CVS: <http://savannah.nongnu.org/cgi-bin/viewcvs/avr-libc/avr-libc/libm/fplib/readme.fplib?rev=1.1&content-type=text/vnd.viewcvs-markup>
So a lot of the decisions on how to do things were very likely his.

I have tried the part he has not used anymore. It results always in -1, but I cannot see what is wrong with it. Writing it in C++, it works.
---------
inline double tanh(double x){
    double e=exp(ldexp(x,1));
    return (e-1)/(e+1);
}
---------
and my program is now about 40% faster. (it uses the tanh function many times, online learning of a neural network)



If the other solution brings also correct results and is faster, is there a simple way to integrate it in my program without to recompile the math library.


Probably only if you're making your own tanh function then you wouldn't have to recompile the library. Obviously if you wanted it to be a part of the library then it would have to be rebuilt.
Maybe someone should check if it wouldn't be better replace the tanh in the math library.


HTH
Eric

Kind regards
Rene liebscher




reply via email to

[Prev in Thread] Current Thread [Next in Thread]