A better log2(x) function - General Discussion and Assistance - CHDK Forum

A better log2(x) function

  • 0 Replies
  • 1848 Views
*

Offline lapser

  • *****
  • 1093
A better log2(x) function
« on: 15 / September / 2013, 15:15:33 »
Advertisements
CHDK includes a log2(x) function, but it computes it as:

log10(x)/log10(2)

As Phil pointed out to me when I was doing the shot meter code, double precision division is a lot slower than multiplication.  So instead of using log2(x), it's faster to use:

log10(x)*(1/log10(2))

However, this requires storing another constant, and writing a longer expression, which takes more memory.  Plus, it isn't obvious that you're doing a log2(x) equivalent.

Anyway, why don't we just change the definition of the log2(x) function like this:

lib/math/wrappers.c
Code: [Select]
//extern double _log2(double x);
double log2(double x) {
//    return d2d( _log2( d2d(x) ) );
//    return (log10(x)/((double)0.30102999566398119521373889472449));
    return (log10(x)*((double)3.3219280948873623478703194294894));
}
I couldn't find any references to log2 in a search of all CHDK files, but I would use this version in my shot meter function. I'm also writing a new histogram that would use it, and I could modify the shooting.c functions to use it too.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

 

Related Topics