[Lua Question] Natural Logs

Hello, I was just wondering if there’s a way I can find the natural log (ln) of a number. I have an equation and I want to use it in my GMod code and it requires a natural log function. Help? Thanks!

If the answer was that easy, I would have already found it.

There must be something equivalent to natural log in GMod Lua that I can use. The only thing relating to logarithms is math.log or math.log10.

[lua]function math.loge(num)
return log(num)/log(2.71828)
end
[/lua]

or if you like precision use

[lua]function math.loge(num)
return log(num)/log(2.71828182845904523536028747135266249775724709369995)
end
[/lua]

Thanks :D. I just figured out the same equation also.

You can also use math.exp(1) instead of hardcoding the constant.

EDIT: Herp derp math.log = natural log.

uhhhhhhhhhh

look:

EDIT:

…wat


print(math.log(2.71828182845904523536028747135266249775724709369995))
=> prints 1

I didn’t know what base math.log used so i just made that, also forgot about math. behind logs.
[lua]
function math.logb(base,num)
return math.log(num)/math.log(base)
end
[/lua]

Ah yes right that equation. If Lua didn’t have math.log it’d make sense to use that.

Weird, when I did math.log yesterday I was getting different values. That’s why I thought I needed an equation but both still work.