@@ -94,7 +94,7 @@ function hexToRGB(hex)
94
94
end
95
95
96
96
-- NOTE: the LuaJIT bitwise operations we have are not 64-bit
97
- -- so we need to implement them ourselves
97
+ -- so we need to implement them ourselves. Lua uses 53-bit doubles.
98
98
function OR64 (a , b )
99
99
-- Split into high and low 32-bit parts
100
100
local ah = math.floor (a / 0x100000000 )
@@ -107,7 +107,7 @@ function OR64(a, b)
107
107
local low = bit .bor (al , bl )
108
108
109
109
-- Combine the results
110
- return high * 0x100000000 + low
110
+ return bit . band ( high , 0x7FF ) * 0x100000000 + low
111
111
end
112
112
113
113
function AND64 (a , b )
@@ -122,7 +122,7 @@ function AND64(a, b)
122
122
local low = bit .band (al , bl )
123
123
124
124
-- Combine the results
125
- return high * 0x100000000 + low
125
+ return bit . band ( high , 0x7FF ) * 0x100000000 + low
126
126
end
127
127
128
128
function XOR64 (a , b )
@@ -137,20 +137,25 @@ function XOR64(a, b)
137
137
local low = bit .bxor (al , bl )
138
138
139
139
-- Combine the results
140
- return high * 0x100000000 + low
140
+ return bit . band ( high , 0x7FF ) * 0x100000000 + low
141
141
end
142
142
143
143
function NOT64 (a )
144
- -- Split into high and low 32-bit parts
144
+ -- Split into high and low 32-bit parts
145
145
local ah = math.floor (a / 0x100000000 )
146
146
local al = a % 0x100000000
147
147
148
148
-- Perform NOT operation on both parts
149
149
local high = bit .bnot (ah )
150
150
local low = bit .bnot (al )
151
151
152
- -- Combine the results
153
- return high * 0x100000000 + low
152
+ -- Convert negative numbers to their unsigned equivalents
153
+ if high < 0 then high = high + 0x100000000 end
154
+ if low < 0 then low = low + 0x100000000 end
155
+
156
+ -- Use bit operations to combine the results
157
+ -- This avoids potential floating-point precision issues
158
+ return bit .band (high , 0x7FF ) * 0x100000000 + low
154
159
end
155
160
156
161
ModFlag = { }
0 commit comments