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

A better log2(x) function

  • 0 Replies

Offline lapser

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


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:


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:

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


Related Topics