Mercurial > prosody-hg
comparison util/human/units.lua @ 10890:a451f80d1cea
util.human.units: Handle lack of math.log(n, base) on Lua 5.1
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 03 Jun 2020 20:17:33 +0200 |
| parents | 25e0ec11b4e4 |
| children | c5f26f9adb31 |
comparison
equal
deleted
inserted
replaced
| 10889:25e0ec11b4e4 | 10890:a451f80d1cea |
|---|---|
| 3 local math_floor = math.floor; | 3 local math_floor = math.floor; |
| 4 local math_log = math.log; | 4 local math_log = math.log; |
| 5 local math_max = math.max; | 5 local math_max = math.max; |
| 6 local math_min = math.min; | 6 local math_min = math.min; |
| 7 local unpack = table.unpack or unpack; --luacheck: ignore 113 | 7 local unpack = table.unpack or unpack; --luacheck: ignore 113 |
| 8 | |
| 9 if math_log(10, 10) ~= 1 then | |
| 10 -- Lua 5.1 COMPAT | |
| 11 local log10 = math.log10; | |
| 12 function math_log(n, base) | |
| 13 return log10(n) / log10(base); | |
| 14 end | |
| 15 end | |
| 8 | 16 |
| 9 local large = { | 17 local large = { |
| 10 "k", 1000, | 18 "k", 1000, |
| 11 "M", 1000000, | 19 "M", 1000000, |
| 12 "G", 1000000000, | 20 "G", 1000000000, |
