Peeter Joot's (OLD) Blog.

Math, physics, perl, and programming obscurity.

Archive for March 26th, 2014

Found code that fails grade 11 math: log base conversion.

Posted by peeterjoot on March 26, 2014

Unless my headache is impacting my ability to manipulate log identities, this LOG10 code is plain wrong:

      static double findLog(double value, FunctionType logFunction)
      {
         switch (logFunction)
         {
            case LN:
               return log(double(value));
            case LOG10:
               return log(double(value)) / log(2.0);
...
      }

Perhaps it is dead code, since this divide should be log(10.0) (or just M_LN10), but nobody appears to have noticed.

Two other possibilities are:

  • somebody was being way too clever, and when they wrote LOG10, they meant it as Log base 0b10.
  • somebody thought that for computer software a “natural logarithm” would use base 2.

Posted in C/C++ development and debugging. | Tagged: , , | 2 Comments »