Peeter Joot's (OLD) Blog.

Math, physics, perl, and programming obscurity.

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.

2 Responses to “Found code that fails grade 11 math: log base conversion.”

  1. For sure there was no unit test involved.🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 46 other followers

%d bloggers like this: