[Click] ]use of log() funtcion in click?

Giorgio Calarco gcalarco at deis.unibo.it
Wed Nov 24 07:52:48 EST 2004


eheh, same problem for me last year, the log function
seems not to be available...

If you want you can start from this small piece of code to arrange it.

It mixes up the mantissa/characteristic-based log calculus and
the Taylor development functions...it moves any number in the
range 0.1-1.5 using log properties and then uses Taylor inside
that range.

For example:

Log (23) = Log(23/10*10) = Log(10) + Log(2.3) =
Log(10)+Log(2.3/10*10) = Log (10) + Log(10) + Log (0.23)

that is: 2+ Log(0.23), where Log(0.23) is calculated using the
Taylor development (a ln ->Log conversion is done, since
Taylor is ok for the natural ln) . Nice ?


you should add these methods to your element class:

    float log(float);
    float ln(float);
    float power(float, int);


And this can be the methods definition:

-------------------------------------------------------
//BASE 10 Logarithm

float
YourElement::log(float x)

 {
 if (x==0) return(-20);                         //prefixed value for ln(0)

     if ((x>=0.1)&&(x<=1.5)) return(ln(x));     //for values included 
between 0.1 e 1.5 call ln function

     if (x < 0.1)                               //for values < 0.1 
calculates the characteristic
                   {
                   x = (x * 100);
                   j = 1;
                   while (x<1)
                     {
                       x = (x * 10);
                       j++;
                     }
                    mantissa = (ln(x / 10) / 2.30258509);       //Mantissa 
calculation with ln function
                    a = ((-(float)j + mantissa) / 0.43429419);  //Mantissa 
metod works with log10, it needs conversion
                    return(a);
                    }
     else
     {
                        j = 0;                  //For values > 1.5 
calculates the characteristic
                        while(x > 1)
                            {
                            x = (x / 10);
                            j++;
                            }
                        mantissa = (ln(x) / 2.30258509);        //Mantissa 
calculation with ln function (needs conversion)
                        a = ((float(j) + mantissa) / 0.43429419);
                        return(a);
     }
  }
-------------------------------------------------------

-------------------------------------------------------
float
YourElement::power(float num, int ind)     //power function
    {
    float w;
    int h;
    w = num;
    for (h=1; h<ind; h++)
        w *= num;
    return(w);
    }
-------------------------------------------------------

-------------------------------------------------------
float                                   //natural logarithm calculation with 
powers series development
YourElement::ln(float x)
    {
    int l;
    p = x - 1;
    b = p;
    for (l = 2; l < 34/*number of interations*/; l++) 
//like b = p - p^2/2 + p^3/3 - p^4/4 etc.
        b += (-(power(-1,l))) * (power(p,l) / l);
    return (b);
    }
-------------------------------------------------------

NB:
if (x==0) return(-20);
means that ln(0) is defined as -20 !

NB2: your element will become slower... anyway we are working
around an improvement to have the same precision with less
Taylor iterations, keep in touch and I can tell you what to change in
the near future.

NB3: you can decrease the number of taylor iterations
if you need a lower precision.

And... if you see anything that sounds wrong -> tell me,
we are using this code quite extensively and it's important
for me to have a feedback

ciao
giorgio


----- Original Message ----- 
From: "Philippe De Neve" <Philippe.deneve at intec.ugent.be>
To: <click at amsterdam.lcs.mit.edu>
Sent: Wednesday, November 24, 2004 10:34 AM
Subject: [Click] ]use of log() funtcion in click?


> Hi all,
>
> I have a question concerning the use of mathematical functions inside 
> click
> elements. Concider next function:
>
> void GausJitter::JitterCalculate(uint32_t&  _gap)
>
> {
>
>  float  w;
>
>
>
>    w= sqrt ((-2.0 * log(w))/w);
>
>
>
> }
>
>
>
> When I compile this no errors are returned. But if I want to insmod the
> package it returns with "unresolved symbol log".
>
> Now when I remove the log function the compiling and insmod works just 
> fine.
> It doesnt have any problem with the sqrt function!
>
>
>
> These headers are included:
>
>
>
> #include <click/config.h>
>
> #include <math.h>
>
> #include <click/confparse.hh>
>
>
>
> What am I missing here?
>
> Tnx for all help!
>
>
>
> Philippe.
>
>
>
>
>
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click 



More information about the click mailing list