mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-22 16:19:03 -06:00
BigInt changes, read extended description
Disabled strict type checking, can be re-enabled in bleeding edge. (This is done so bigint ops run faster) Added a negation method and updated the corresponding metamethod to use it.
This commit is contained in:
parent
a4d3f3bffc
commit
2c07c2a58c
@ -2,7 +2,7 @@
|
|||||||
-- If this variable is true, then strict type checking is performed for all
|
-- If this variable is true, then strict type checking is performed for all
|
||||||
-- operations. This may result in slower code, but it will allow you to catch
|
-- operations. This may result in slower code, but it will allow you to catch
|
||||||
-- errors and bugs earlier.
|
-- errors and bugs earlier.
|
||||||
local strict = true
|
local strict = false
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -33,12 +33,7 @@ function bigint.new(num)
|
|||||||
return bigint.add(lhs, rhs)
|
return bigint.add(lhs, rhs)
|
||||||
end,
|
end,
|
||||||
__unm = function()
|
__unm = function()
|
||||||
if (self.sign == "+") then
|
return bigint.negate(self)
|
||||||
self.sign = "-"
|
|
||||||
else
|
|
||||||
self.sign = "+"
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end,
|
end,
|
||||||
__sub = function(lhs, rhs)
|
__sub = function(lhs, rhs)
|
||||||
return bigint.subtract(lhs, rhs)
|
return bigint.subtract(lhs, rhs)
|
||||||
@ -98,6 +93,18 @@ function bigint.abs(big)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Return a new big with the same digits but the opposite sign (negation)
|
||||||
|
function bigint.negate(big)
|
||||||
|
bigint.check(big)
|
||||||
|
local result = big:clone()
|
||||||
|
if (result.sign == "+") then
|
||||||
|
result.sign = "-"
|
||||||
|
else
|
||||||
|
result.sign = "+"
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
-- Return the number of digits in the big
|
-- Return the number of digits in the big
|
||||||
function bigint.digits(big)
|
function bigint.digits(big)
|
||||||
bigint.check(big)
|
bigint.check(big)
|
||||||
|
Loading…
Reference in New Issue
Block a user