Thanks for that... much easier than my original conversion.
I've been using Lua for some time now (a few years) but have never explored the math library - initially I was using an integer-only version that was running on an embedded system, so the math library was simply not available.