diff --git a/std/lua/Math.hx b/std/lua/Math.hx index f659c2789c3..3bcfda97cb4 100644 --- a/std/lua/Math.hx +++ b/std/lua/Math.hx @@ -64,16 +64,34 @@ extern class Math { **/ static function asin(x:Float):Float; + #if (lua_ver <= 5.2 || luajit) /** - Returns the arc tangent of x (in radians). + Returns the arc tangent of y/x (in radians), using the signs of both arguments to find the quadrant of the result. It also handles correctly the case of x being zero. + + The default value for x is 1, so that the call math.atan(y) returns the arc tangent of y. + **/ + static function atan(y:Float):Float; + #else + /** + Returns the arc tangent of y/x (in radians), using the signs of both arguments to find the quadrant of the result. It also handles correctly the case of x being zero. + + The default value for x is 1, so that the call math.atan(y) returns the arc tangent of y. + + The x argument is ignored on lua 5.2 or older and luajit, where atan2 is available instead. **/ - static function atan(x:Float):Float; + static function atan(y:Float, ?x:Float):Float; + #end + #if !(lua_ver >= 5.5) /** Returns the arc tangent of y/x (in radians), but uses the signs of both parameters to find the quadrant of the result. (It also handles correctly the case of x being zero.) **/ + #if (lua_ver >= 5.3) + @:deprecated("Deprecated in Lua 5.3, removed in Lua 5.5") + #end static function atan2(y:Float, x:Float):Float; + #end /** Returns the cosine of x (assumed to be in radians). @@ -81,29 +99,40 @@ extern class Math { static function cos(x:Float):Float; /** - Returns the hyperbolic cosine of x. + Returns the sine of x (assumed to be in radians). **/ - static function cosh(x:Float):Float; + static function sin(x:Float):Float; /** - Returns the sine of x (assumed to be in radians). + Returns the tangent of x (assumed to be in radians) **/ - static function sin(x:Float):Float; + static function tan(x:Float):Float; + #if !(lua_ver >= 5.5) /** - Returns the hyperbolic sine of x. + Returns the hyperbolic cosine of x. **/ - static function sinh(x:Float):Float; + #if (lua_ver >= 5.3) + @:deprecated("Deprecated in Lua 5.3, removed in Lua 5.5") + #end + static function cosh(x:Float):Float; /** - Returns the tangent of x (assumed to be in radians) + Returns the hyperbolic sine of x. **/ - static function tan(x:Float):Float; + #if (lua_ver >= 5.3) + @:deprecated("Deprecated in Lua 5.3, removed in Lua 5.5") + #end + static function sinh(x:Float):Float; /** Returns the hyperbolic tangent of x. **/ + #if (lua_ver >= 5.3) + @:deprecated("Deprecated in Lua 5.3, removed in Lua 5.5") + #end static function tanh(x:Float):Float; + #end /** Returns the angle x (given in degrees) in radians. @@ -120,10 +149,15 @@ extern class Math { **/ static function fmod(x:Float):Float; + #if !(lua_ver >= 5.5) /** Returns y-th power of x. **/ + #if (lua_ver >= 5.3) + @:deprecated("Deprecated in Lua 5.3, removed in Lua 5.5") + #end static function pow(x:Float, y:Float):Float; + #end /** Returns the square root of x. @@ -138,11 +172,17 @@ extern class Math { /** Returns m and e such that x = m2^e, e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when x is zero). **/ + #if (lua_ver >= 5.3) + @:deprecated("Deprecated in Lua 5.3") + #end static function frexp(x:Float):MathFrexpResult; /** Returns m2^e (e should be an integer). **/ + #if (lua_ver >= 5.3) + @:deprecated("Deprecated in Lua 5.3") + #end static function ldexp(m:Float, e:Int):Float; /** @@ -150,10 +190,15 @@ extern class Math { **/ static function log(x:Float):Float; + #if !(lua_ver >= 5.5) /** Returns the base-10 logarithm of x. **/ + #if (lua_ver >= 5.2) + @:deprecated("Deprecated in Lua 5.2, removed in Lua 5.5") + #end static function log10(x:Float):Float; + #end /** Returns the maximum value among its arguments. diff --git a/std/lua/_std/Math.hx b/std/lua/_std/Math.hx index 9b168d92efe..e8cb73bdafd 100644 --- a/std/lua/_std/Math.hx +++ b/std/lua/_std/Math.hx @@ -93,8 +93,19 @@ class Math { public static inline function random():Float return untyped __define_feature__("Math.random", lua.Math.random()); + #if (lua_ver >= 5.3) + public static inline function atan2(y:Float, x:Float):Float + return lua.Math.atan(y, x); + #elseif (lua_ver <= 5.2 || luajit) public static inline function atan2(y:Float, x:Float):Float return lua.Math.atan2(y, x); + #else + private static final atan2Impl = lua.Math.atan2 ?? lua.Math.atan; + + public static inline function atan2(y:Float, x:Float):Float { + return atan2Impl(y, x); + } + #end public static function max(a:Float, b:Float):Float { return Math.isNaN(a) || Math.isNaN(b) ? Math.NaN : lua.Math.max(a, b); @@ -105,7 +116,7 @@ class Math { } public static inline function pow(v:Float, exp:Float):Float - return lua.Math.pow(v, exp); + return lua.Syntax.code("(({0}) ^ ({1}))", v, exp); public static inline function round(v:Float):Int return Math.floor(v + 0.5); diff --git a/tests/runci/targets/Lua.hx b/tests/runci/targets/Lua.hx index 7fe36625768..8cc21f15b63 100644 --- a/tests/runci/targets/Lua.hx +++ b/tests/runci/targets/Lua.hx @@ -90,7 +90,7 @@ class Lua { getLuaDependencies(); - for (lv in ["-l5.1", "-l5.2", "-l5.3", "-l5.4", "-j2.0", "-j@v2.1"]) { + for (lv in ["-l5.1", "-l5.2", "-l5.3", "-l5.4", "-l5.5", "-j2.0", "-j@v2.1"]) { // luajit 2.0 was missing arm64 support if (System.arch == Arm64 && lv == "-j2.0") continue; @@ -143,7 +143,7 @@ class Lua { installLib("https://raw.githubusercontent.com/lunarmodules/lua-compat-5.3/refs/heads/master/rockspecs/bit32-scm-1.rockspec", ""); installLib("https://raw.githubusercontent.com/luvit/luv/refs/heads/master/luv-scm-0.rockspec", ""); - installLib("luautf8", "0.1.6-1"); + installLib("luautf8", "0.2.1-1"); installLib("https://raw.githubusercontent.com/HaxeFoundation/hx-lua-simdjson/master/hx-lua-simdjson-scm-1.rockspec", "");