Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 55 additions & 10 deletions std/lua/Math.hx
Original file line number Diff line number Diff line change
Expand Up @@ -64,46 +64,75 @@ 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).
**/
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.
Expand All @@ -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.
Expand All @@ -138,22 +172,33 @@ 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;

/**
Returns the natural logarithm of x.
**/
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.
Expand Down
13 changes: 12 additions & 1 deletion std/lua/_std/Math.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/runci/targets/Lua.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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", "");

Expand Down
Loading