log is non-monotonic in PHP and Lua | purplesyringa's blog
If a b 1 and x 1 , you can prove that log a x log b x . (As a reminder, log a x denotes the value t such that x = a t .) This is very intuitive if you think about it: for “normal” numbers, the greater a , the smaller t you will need to get the same x . Yet if you ask PHP what it thinks, it will tell you you’re wrong in a couple rare cases: $x = 2.93; $a = 10 + 2 ** -49; $b = 10; assert($a $b); var_dump(log($x, $a) log($x, $b)); var_dump(log($x, $a) == log($x, $b)); To be clear, this is not the usual floating-point inaccuracy. Everyone already knows floating-point operations are imprecise and it wouldn’t be fun to blog about. This example was deliberately engineered to trigger something different.
July 22, 2026 Hacker News Lobsters If a>b>1 and x>1, you can prove that logax<logbx. (As a reminder, logax denotes the value t such that x=at.) This is very intuitive if you think about it: for “normal” numbers, the greater a, the smaller t you will need to get the same x. Yet if you ask PHP what it thinks, it will tell you you’re wrong in a couple rare cases: <?php $x = 2.93; $a = 10 + 2 ** -49; $b = 10; assert($a > $b); var_dump(log($x, $a) < log($x, $b)); var_dump(log($x, $a) == log($x, $b)); To be clear, this is not the usual floating-point inaccuracy. Everyone already knows…
saved by
related reading
- Everything Is Logarithmsalexkritchevsky.com
- Logs, Tails, Long Tails – Ryan Moulton's Articlesmoultano.wordpress.com
- Benford's law - Wikipediaen.wikipedia.org
- GitHub - Experience-Monks/math-as-code: a cheat-sheet for mathematical notation in code formgithub.com
- Adding Floating-Point Decimals for Fun and Profitblog.vero.site
- 練習 - 探索浮點類型 - Training | Microsoft Learnlearn.microsoft.com
- There are Only Four Billion Floats-So Test Them All! | Random ASCII – tech blog of Bruce Dawsonrandomascii.wordpress.com
- 3. Logic - Mathematics in Lean v4.19.0 documentationleanprover-community.github.io
- Artificial Intelligence Blogartent.net
- Floating point from scratch: Hard Mode · Tales on the wireessenceia.github.io
- Language, Proof and Logichomepages.uc.edu
- First-order logic - Wikipediaen.wikipedia.org