I was trying to generate a certain curve and found math.tanh missing, I decided to check all of the math functions listed in the documentation and found several more are missing.

function setup()
local val,val2 = 0.75, 1 --example values
local missingFunctions = {
math.sinh, math.cosh, math.tanh, math.frexp, math.ldexp, math.log10,
math.sin} --note: math.sin is not missing but here as a counterexample
for k,func in pairs(missingFunctions) do print( func(val,val2) ) end
end

Interesting, in the Lua source code these are listed as deprecated functions and are #defined out of the codebase. I think we need to make a decision on whether we remove them from documentation, or add them back in. Perhaps removing them from docs is the way to go?

@piinthesky I would lean towards removing them because I imagine one day soon they will be removed from Lua (given they are deprecated and already removed by default), and then the decision will be made for us.

pow has been replaced by the ^ operator in Lua

I think the only ones that donâ€™t have simple replacements are math.frexp and math.ldexp

I would say that removing support for deprecated functions entirely will have some downsides when it comes to running older projects though. Ideally, it shouldnâ€™t matter if youâ€™re running the latest version of Codea, a project should run still. Easier said than done but it should always be a consideration.

@sim Could we perhaps consider some backward compatibility functions for things like this that can easily be inserted into older projects. That way we can redefine the missing functions ourselves.

Something like this perhaps:

backcompat(â€śmath5.2â€ť)
-- Code using old math functions here
...

Possibly, or we could just adopt support for the most useful math functions and maintain our implementations going forward?

Are there any in the list of deprecated functions that seem particularly useful? Are there any math functions in general missing from Lua that we would like to have (e.g., math.round?)

math.round would be hugely beneficial. At the moment the only way to round is using string formatting then converting back to a number. Unless I missed something. Coming from Python this blew my mind.

Is there an easy way to truncate? Because that seemed a bit tedious as well so maybe some built in way to truncate a number without having to do string formatting then convert. Might help some individuals.

fdexp is something like math.floor(math.ln(x)/math.ln(2)) for the exponent, and 2^(math.ln(x)/math.ln(2) - math.floor(math.ln(x)/math.ln(2))) (or math.fract, if that still exists), but I may have a fence-post error here.

I guess the question is, are these used sufficiently often that they are worth putting in the C code, or can they be provided via a pure Lua extension library?

Iâ€™m going to add these to my VecExt library, since I do use some of them there. But Iâ€™ll wrap the definitions in tests to see if they are needed. (Then I can safely forget about them! If you do remove them, Iâ€™m okay, and also if you donâ€™t. )