<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/log-is-non-monotonic-in-php-and-lua-plzebjpdu" -->

---
title: log is non-monotonic in PHP and Lua | daily.dev
description: PHP and Lua implement the two-argument log(x, base) function by special-casing certain bases (like 10 and 2) to use libm&#x27;s dedicated log10/log2 functions...
canonical: https://daily.dev/posts/log-is-non-monotonic-in-php-and-lua-plzebjpdu
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: log is non-monotonic in PHP and Lua | daily.dev
og:description: PHP and Lua implement the two-argument log(x, base) function by special-casing certain bases (like 10 and 2) to use libm&#x27;s dedicated log10/log2 functions...
og:url: https://daily.dev/posts/log-is-non-monotonic-in-php-and-lua-plzebjpdu
og:image: https://api.daily.dev/og/posts/pLzebJpdU.png
og:image:alt: log is non-monotonic in PHP and Lua
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# log is non-monotonic in PHP and Lua

**[Lobsters](https://daily.dev/sources/lobsters)** · 4 min read · 0 upvotes · 0 comments

## Summary

PHP and Lua implement the two-argument log(x, base) function by special-casing certain bases (like 10 and 2) to use libm's dedicated log10/log2 functions instead of the general ln(x)/ln(base) formula. This optimization creates a discontinuity at the boundary: for bases very close to 10, one side uses log10 while the other uses the general formula, producing results that can flip the expected ordering — making log(x, a) appear less than log(x, b) even when a > b > 1. This is not ordinary floating-point imprecision but a design flaw from mixing two evaluation methods. Rust and C# don't exhibit this because they don't apply the same special-casing. The post also touches on Lua 5.2's decision to expose math.log10 separately and remove the special case, and PHP's quirks around log(x, 1) and default base handling.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://purplesyringa.moe/blog/log-is-non-monotonous-in-php-and-lua>

## Similar posts on daily.dev

- [987654321 / 123456789](https://daily.dev/posts/987654321-123456789-xndx6lext) · Hacker News · 18 upvotes · 1 comments
- [A Neighborhood of Infinity: Logarithms and exponentials of functions](https://daily.dev/posts/a-neighborhood-of-infinity-logarithms-and-exponentials-of-functions-kexsxdrbj) · Planet Haskell · 0 upvotes · 0 comments

---

Tags: [#php](https://daily.dev/tags/php), [#lua](https://daily.dev/tags/lua)

[View this post on daily.dev](https://daily.dev/posts/log-is-non-monotonic-in-php-and-lua-plzebjpdu)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"log is non-monotonic in PHP and Lua","url":"https://daily.dev/posts/log-is-non-monotonic-in-php-and-lua-plzebjpdu","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/log-is-non-monotonic-in-php-and-lua-plzebjpdu"},"datePublished":"2026-07-22T16:57:11.562Z","dateModified":"2026-07-22T16:57:35.221Z","description":"PHP and Lua implement the two-argument log(x, base) function by special-casing certain bases (like 10 and 2) to use libm's dedicated log10/log2 functions...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4d1e56893ac105666d14e7334d013edc?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4d1e56893ac105666d14e7334d013edc?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Lobsters","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Lobsters","logo":"https://media.daily.dev/image/upload/s--tl8v_Fku--/f_auto,t_logo/v1698841318/logos/lobste.jpg","url":"https://daily.dev/sources/lobsters"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/log-is-non-monotonic-in-php-and-lua-plzebjpdu","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"php,lua","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Lobsters","item":"https://daily.dev/sources/lobsters"},{"@type":"ListItem","position":3,"name":"log is non-monotonic in PHP and Lua"}]}
```

