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: E. Weddington
Subject: Re: [avr-libc-dev] tanh in libm
Date: Thu, 16 Sep 2004 07:32:03 -0600

On 16 Sep 2004 at 11:31, René Liebscher wrote:

> 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.


Would you be willing to fill out a bug report on avr-libc? And could you add 
your example and
say how it works with C++? That way this issue won't be forgotten.

Thanks!

Eric





reply via email to

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