Math.atan2 appears to be AWOL

This morning, because I’m coding a space thing in Kotlin, I opened my Coda Asteroids game and ran it. It crashed looking for math.atan2.

Has atan2 gone missing?

Thanks for all the fish …

R

Lua 5.4 deprecated some functions including pow and atan2. You can now use a ^ b for exponents and atan with two parameters replaces atan2 (so just remove the 2)

1 Like

@RonJeffries - ran into that one myself. Had me flummoxed for a while. But …

Don’t Panic !!!

thanks! I would not have guessed that … the docs need to be updated.

1 Like

@RonJeffries yes this was a very sneaky change from the creator of Lua. I’ll make a note about updating the docs. We could also chuck in a math.pow and math.atan2 function for backwards compatibility

How about sinh? It seems to also be missing?

If you need sinh, cosh, or tanh, you can use this until they’re added to the math functions.

function setup()
    e=math.exp(1)

    print(sinh(1.5))
    print(cosh(1.5))
    print(tanh(1.5))
end

function sinh(x)
    return (e^x-e^-x)/2
end

function cosh(x)
    return (e^x+e^-x)/2
end

function tanh(x)
    return sinh(x)/cosh(x)
end

I struggled with this a lot because chatGPT kept putting math.atan2 in calculations it made for me, but then I did a web search on it.

I think math.atan2 still exists, it’s just got a different syntax.

I think math.atan will work like math.atan2 any time you give it two parameters.