Log is non-monotonic in PHP and Lua

Tiny number glitch sparks a nerd pile-on over whether PHP and Lua can even count straight

TLDR: A blog post found that PHP and Lua can sometimes give a math answer that flips the wrong way because they switch calculation methods at a special boundary. Commenters turned it into a nerd drama fest, arguing over wording, possible shared code, and whether the title itself was the real bug.

A tiny math oddity just sent programmers into full comment-section detective mode. The blog post showed something deeply cursed: in very rare cases, PHP and Lua can give a logarithm result that appears to go the wrong way when only the base number changes. In plain English, the answer should smoothly shift one direction, but instead it can suddenly flip. That’s not the usual “computers round weirdly” excuse, and that’s exactly why people got hooked.

The community reaction was a mix of pedantry, suspicion, and stand-up comedy. One camp jumped in with the classic internet energy of, “Well, actually,” correcting the wording around how logarithms can be computed. Another commenter immediately tried to connect dots between PHP and Lua, wondering if shared tech under the hood might be the smoking gun. That sparked a mini-drama of is this a language bug, a library quirk, or just a weird implementation choice nobody noticed until now? Even the title got dragged, with one reader arguing the real villain wasn’t logarithms in general, but specifically the log base handling.

And then came the jokes. The funniest reply admitted they expected a story about log('a'); log('b'); somehow printing b before a—which honestly says a lot about how broken people assume software can be. Another commenter casually dropped a table comparing languages doing fake math tricks, basically widening the gossip: it’s not just one language embarrassing itself; everybody’s got quirks. The vibe was clear: half bug hunt, half roast session, and 100% catnip for people who love watching “simple” math turn into platform drama.

Key Points

  • The article demonstrates a floating-point edge case where PHP reports `log(x, a) < log(x, b)` even though `a > b` for fixed `x > 1`.
  • It says this behavior is not the usual arbitrary-base logarithm inaccuracy caused by general change-of-base rounding when both the argument and base vary.
  • According to the article, Python returns equality on the same inputs, while PHP and Lua show the flipped result and Rust and C# do not.
  • The article explains that arbitrary-base logarithms are usually computed from two logarithms in the same base because standard math libraries provide `log`, `log10`, and `log2`, but not a direct arbitrary-base function.
  • It attributes the anomaly in PHP and Lua to special-casing exact base 10 or base 2 with direct `log10` or `log2` calls, creating a discontinuity relative to the generic change-of-base path.

Hottest takes

"Any base will do as long as it is the same for both the numerator and the denominator" — dmitrygr
"PHP uses a JIT from Lua. Is this related to the log issue?" — cwt137
"I was prepared to read how its console logging function could reorder writes" — kstrauser
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.