15-03-2015, 09:45 PM

Dear all,

Few monthes ago i wanted to write an application to calculate the dewpoint based on temperature and humidity measurements (with DHT22). I was stucked until recently, lacking of a proper ln/log function.

One week ago trying to get my hands dirty again on this topic i finally found a code (actually two variants) under New BSD license which is more than appropriate for my needs:

here they are

They return an approximation, but accurate enough (4 or 5 digits after the point..) and quite fast for my needs (did'nt tested the time,but that's easy to do )

There is also

May be a library with these function can be of interest for everyone using pinguino, which is currently lacking of some math functions (log, cosh, sinh, tanh), and even the others if they appears faster than those already available mind you?

Code source is at

https://code.google.com/p/fastapprox/sou...approx/src

and easy to adapt for our small µC, if we can include BSD licensed code within pinguino

Joël

Edit: i can write the library(with pdl and so on) if pinguino team want to implement these fast approx functions

Few monthes ago i wanted to write an application to calculate the dewpoint based on temperature and humidity measurements (with DHT22). I was stucked until recently, lacking of a proper ln/log function.

One week ago trying to get my hands dirty again on this topic i finally found a code (actually two variants) under New BSD license which is more than appropriate for my needs:

here they are

Code:

`static inline float`

fastlog2 (float x)

{

union { float f; u32 i; } vx = { x };

union { u32 i; float f; } mx = { (vx.i & 0x007FFFFF) | 0x3f000000 };

float y = vx.i;

y *= 1.1920928955078125e-7f;

return y - 124.22551499f

- 1.498030302f * mx.f

- 1.72587999f / (0.3520887068f + mx.f);

}

static inline float

fastlog (float x) //ln(x)

{

return 0.69314718f * fastlog2 (x);

}

static inline float

fastlog10 (float x) //log10(x)

{

return 0.30102999f * fastlog2 (x);

}

static inline float

fasterlog2 (float x)

{

union { float f; u32 i; } vx = { x };

float y = vx.i;

y *= 1.1920928955078125e-7f;

return y - 126.94269504f;

}

static inline float

fasterlog (float x) //ln(x)

{

// return 0.69314718f * fasterlog2 (x);

union { float f; u32 i; } vx = { x };

float y = vx.i;

y *= 8.2629582881927490e-8f;

return y - 87.989971088f;

}

They return an approximation, but accurate enough (4 or 5 digits after the point..) and quite fast for my needs (did'nt tested the time,but that's easy to do )

There is also

- exponential, logarithm, and power

- lgamma and digamma

- cosh, sinh, tanh

- cos, sin, tan

- sigmoid and erf

- Lambert W

May be a library with these function can be of interest for everyone using pinguino, which is currently lacking of some math functions (log, cosh, sinh, tanh), and even the others if they appears faster than those already available mind you?

Code source is at

https://code.google.com/p/fastapprox/sou...approx/src

and easy to adapt for our small µC, if we can include BSD licensed code within pinguino

Joël

Edit: i can write the library(with pdl and so on) if pinguino team want to implement these fast approx functions