7 hours ago
- The author engineered an example (log(2.93, 10+2^-49) vs log(2.93, 10)) that produces surprising results in PHP and Lua, but not in Rust or C#, due to floating-point implementation differences.
- Languages like PHP and Lua special-case log bases 10 and 2 by using dedicated log10/log2 functions for better precision, but this creates a discontinuity when compared to the general log(x)/log(base) method.
- The inconsistency arises because the two evaluation methods (log10 vs ln/ln) can produce errors in different directions, breaking the assumption that log(x, a) < log(x, b) when a > b.
- The author suggests that Lua should add separate log10/log2 functions and remove special casing from log, but Lua 5.2 did the opposite. PHP's special-casing is aimed at users who don't read the manual.
- Additional edge cases are discussed, such as log(x, 1) returning NaN in PHP and C# but not in Lua or Python, and the use of M_PI approximation in PHP's default log.