From 695637b1ed9d18c305a10e1c8f5c33d737630ea9 Mon Sep 17 00:00:00 2001 From: Aimarekin Date: Sat, 14 Oct 2023 21:44:03 +0200 Subject: [PATCH] Make NaN similar to itself In Lua, NaN does not equal itself. However, it is the same value. Make NaN similar to itself to avoid recomputations. --- src/Utility/isSimilar.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Utility/isSimilar.lua b/src/Utility/isSimilar.lua index cef06a99f..56d1f28a7 100644 --- a/src/Utility/isSimilar.lua +++ b/src/Utility/isSimilar.lua @@ -10,8 +10,9 @@ local function isSimilar(a: any, b: any): boolean if typeof(a) == "table" then return false else - return a == b + -- NaN does not equal itself but is the same + return a == b or a ~= a and b ~= b end end -return isSimilar \ No newline at end of file +return isSimilar