flâneur

log is non-monotonic in PHP and Lua | purplesyringa's blog

purplesyringa.moe · 906 words · saved by 1 readers

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 loga⁡x<logb⁡x. (As a reminder, loga⁡x 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