mirror of
https://github.com/luau-lang/luau.git
synced 2025-01-19 17:28:06 +00:00
a251bc68a2
* New `vector` library! See https://rfcs.luau.org/vector-library.html for details * Replace the use of non-portable `strnlen` with `memchr`. `strnlen` is not part of any C or C++ standard. * Introduce `lua_newuserdatataggedwithmetatable` for faster tagged userdata creation of userdata with metatables registered with `lua_setuserdatametatable` Old Solver * It used to be the case that a module's result type would unconditionally be inferred to be `any` if it imported any module that participates in any import cycle. This is now fixed. New Solver * Improve inference of `table.freeze`: We now infer read-only properties on tables after they have been frozen. * We now correctly flag cases where `string.format` is called with 0 arguments. * Fix a bug in user-defined type functions where table properties could be lost if the table had a metatable * Reset the random number seed for each evaluation of a type function * We now retry subtyping arguments if it failed due to hidden variadics. --------- Co-authored-by: Aaron Weiss <aaronweiss@roblox.com> Co-authored-by: Alexander McCord <amccord@roblox.com> Co-authored-by: Vighnesh <vvijay@roblox.com> Co-authored-by: Aviral Goel <agoel@roblox.com> Co-authored-by: David Cope <dcope@roblox.com> Co-authored-by: Lily Brown <lbrown@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> Co-authored-by: Junseo Yoo <jyoo@roblox.com>
80 lines
2.1 KiB
C
80 lines
2.1 KiB
C
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
// This code is based on Lua 5.x implementation licensed under MIT License; see lua_LICENSE.txt for details
|
|
#pragma once
|
|
|
|
#include <math.h>
|
|
|
|
#define luai_numadd(a, b) ((a) + (b))
|
|
#define luai_numsub(a, b) ((a) - (b))
|
|
#define luai_nummul(a, b) ((a) * (b))
|
|
#define luai_numdiv(a, b) ((a) / (b))
|
|
#define luai_numpow(a, b) (pow(a, b))
|
|
#define luai_numunm(a) (-(a))
|
|
#define luai_numisnan(a) ((a) != (a))
|
|
#define luai_numeq(a, b) ((a) == (b))
|
|
#define luai_numlt(a, b) ((a) < (b))
|
|
#define luai_numle(a, b) ((a) <= (b))
|
|
|
|
inline bool luai_veceq(const float* a, const float* b)
|
|
{
|
|
#if LUA_VECTOR_SIZE == 4
|
|
return a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3];
|
|
#else
|
|
return a[0] == b[0] && a[1] == b[1] && a[2] == b[2];
|
|
#endif
|
|
}
|
|
|
|
inline bool luai_vecisnan(const float* a)
|
|
{
|
|
#if LUA_VECTOR_SIZE == 4
|
|
return a[0] != a[0] || a[1] != a[1] || a[2] != a[2] || a[3] != a[3];
|
|
#else
|
|
return a[0] != a[0] || a[1] != a[1] || a[2] != a[2];
|
|
#endif
|
|
}
|
|
|
|
inline float luaui_signf(float v)
|
|
{
|
|
return v > 0.0f ? 1.0f : v < 0.0f ? -1.0f : 0.0f;
|
|
}
|
|
|
|
inline float luaui_clampf(float v, float min, float max)
|
|
{
|
|
float r = v < min ? min : v;
|
|
return r > max ? max : r;
|
|
}
|
|
|
|
LUAU_FASTMATH_BEGIN
|
|
inline double luai_nummod(double a, double b)
|
|
{
|
|
return a - floor(a / b) * b;
|
|
}
|
|
LUAU_FASTMATH_END
|
|
|
|
LUAU_FASTMATH_BEGIN
|
|
inline double luai_numidiv(double a, double b)
|
|
{
|
|
return floor(a / b);
|
|
}
|
|
LUAU_FASTMATH_END
|
|
|
|
#define luai_num2int(i, d) ((i) = (int)(d))
|
|
|
|
// On MSVC in 32-bit, double to unsigned cast compiles into a call to __dtoui3, so we invoke x87->int64 conversion path manually
|
|
#if defined(_MSC_VER) && defined(_M_IX86)
|
|
#define luai_num2unsigned(i, n) \
|
|
{ \
|
|
__int64 l; \
|
|
__asm { __asm fld n __asm fistp l} \
|
|
; \
|
|
i = (unsigned int)l; \
|
|
}
|
|
#else
|
|
#define luai_num2unsigned(i, n) ((i) = (unsigned)(long long)(n))
|
|
#endif
|
|
|
|
#define LUAI_MAXNUM2STR 48
|
|
|
|
LUAI_FUNC char* luai_num2str(char* buf, double n);
|
|
|
|
#define luai_str2num(s, p) strtod((s), (p))
|