Math.log and math.log10

Simple Question: Is there a way to do any other base besides math.log and math.log10?

local function logBase(num, base)
    return math.log(num) / math.log(base)

logBase(16, 2) --4

Otherwise known as the change of base formula.

Is there a way to actually use that in context?

I’m trying to create a script that makes a car turn slower the faster it’s going, and this is the formula I’ve been using:

(-math.log(script.Parent.Velocity.Magnitude+500) + 7.2)

Maybe I’m just overthinking it and there’s simpler way to do it.

I would use an exponential formula. Raising a number that’s between 1 and infinite to a negative power causes it to slope downwards.

The basic formula is: turnRate = baseTurn * someNumber^(-velocity)

local baseTurnRate = 100
local multiplierBase = 1.5 -- The number you're going to raise
function getTurnSpeed(carSpeed)
    local adjustedTurnRate = baseTurnRate *  multiplierBase^(-carSpeed) -- presumably carSpeed is positive
    return adjustedTurnRate


You can play around with the numbers in game, or graph it at a site like . Decreasing multiplierBase towards 1 causes the turn rate to change more gradually, while giving a higher number creates a sharper curve.

You can use the change of base formula to do a base other than 10.

This is the code I use:
math.log10(a) / math.log10(b)

You can see it in action with the open-source code of this tweet I made:

I know this is old but i can see all the answers here aren’t good solutions the best way to get the log of any number with any base is
math.log(10, 5)
the 10 is the number and the 5 is the base it is as simple as this i don’t know why the others has come up with so log and complicated answers when you can just do this

1 Like

math.log with a second parameter wasn’t implemented at that time and so the only way of achieving this was a custom implementation, since if you didn’t realize - it’s a very old post you’ve necro-bumped, though others might find this as an addition to the documentation that already exists.

1 Like