@@ -208,7 +208,7 @@ inline bool luau_skipstep(uint8_t op)
208208}
209209
210210
211- static const char * const MATH_ERROR_STR = " Math error: division or modulus (possibly by 0) resulted in NaN " ;
211+ static const char * const MATH_ERROR_STR = " Math error: division or modulus by 0" ;
212212
213213template <bool SingleStep>
214214static void luau_execute (lua_State* L)
@@ -1774,9 +1774,8 @@ static void luau_execute(lua_State* L)
17741774 // ServerLua: ints not represented in here, they only support idiv.
17751775 const double res = nvalue (rb) / nvalue (rc);
17761776
1777- // ServerLua: Any division that results in NaN is an error under Mono
1778- // Generally this is div by zero, but there might be others.
1779- if (LUAU_UNLIKELY (LUAU_IS_LSL_VM (L) && std::isnan (res)))
1777+ // ServerLua: In LSL (Mono), division by zero or a NaN result is an error.
1778+ if (LUAU_UNLIKELY (LUAU_IS_LSL_VM (L) && (nvalue (rc) == 0.0 || std::isnan (res))))
17801779 {
17811780 // VM protection is necessary here because PC may be invalid if we've
17821781 // not called `VM_PROTECT()` in this function yet.
@@ -2092,12 +2091,26 @@ static void luau_execute(lua_State* L)
20922091 // fast-path
20932092 if (LUAU_LIKELY (ttisnumber (rb)))
20942093 {
2095- setnvalue (ra, nvalue (rb) / nvalue (kv));
2094+ const double res = nvalue (rb) / nvalue (kv);
2095+
2096+ // ServerLua: In LSL (Mono), division by zero or a NaN result is an error.
2097+ if (LUAU_UNLIKELY (LUAU_IS_LSL_VM (L) && (nvalue (kv) == 0.0 || std::isnan (res))))
2098+ {
2099+ VM_PROTECT (luaG_runerrorL (L, MATH_ERROR_STR));
2100+ }
2101+
2102+ setnvalue (ra, res);
20962103 VM_NEXT ();
20972104 }
20982105 // ServerLua: int intentionally not handled, it uses idivk
20992106 else if (ttisvector (rb))
21002107 {
2108+ // ServerLua: In LSL (Mono), vector division by zero is a runtime error.
2109+ if (LUAU_UNLIKELY (LUAU_IS_LSL_VM (L) && nvalue (kv) == 0.0 ))
2110+ {
2111+ VM_PROTECT (luaG_runerrorL (L, MATH_ERROR_STR));
2112+ }
2113+
21012114 const float * vb = vvalue (rb);
21022115 float nc = cast_to (float , nvalue (kv));
21032116 setvvalue (ra, vb[0 ] / nc, vb[1 ] / nc, vb[2 ] / nc, vb[3 ] / nc);
@@ -3113,7 +3126,15 @@ static void luau_execute(lua_State* L)
31133126 // fast-path
31143127 if (LUAU_LIKELY (ttisnumber (rc)))
31153128 {
3116- setnvalue (ra, nvalue (kv) / nvalue (rc));
3129+ const double res = nvalue (kv) / nvalue (rc);
3130+
3131+ // ServerLua: In LSL (Mono), division by zero or a NaN result is an error.
3132+ if (LUAU_UNLIKELY (LUAU_IS_LSL_VM (L) && (nvalue (rc) == 0.0 || std::isnan (res))))
3133+ {
3134+ VM_PROTECT (luaG_runerrorL (L, MATH_ERROR_STR));
3135+ }
3136+
3137+ setnvalue (ra, res);
31173138 VM_NEXT ();
31183139 }
31193140 else if (ttisvector (rc))
0 commit comments