A better system for logarithms

So it has come to my attention that the math.log function for lua is actually used for finding the natural log of something while math.log10 is what you would use to find the log of a number using base-10.

This tends to complicate things as most calculators set up finding the natural log of a number as ln(number x) while finding the log base-10 of a number is typically log(number x). So you can see exactly how this can cause complications for some people. Another annoying thing I noticed is that lua doesn’t have a built in function that allows you to put a custom base for a log.

This is a sort of demo idea I came up with that would be a bit nicer to see for the math.log system.

local mather = {}
mather.__index = math

mather.e = math.exp(1)

function mather.ln(numb)
	return math.log(numb)
end

function mather.log(numb)
	return math.log10(numb)
end

function mather.logb(base,numb)
	return math.log10(numb)/math.log10(base)
end

return mather

Feel free to use this module if you’d like (but don’t because it’s not worth the time).

tl;dr the logarithm functions in lua are not really good and this gives a better way of how it should be done.

1 Like

This topic was automatically closed after 14 minutes. New replies are no longer allowed.