moonledger

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/moonledger
Log | Files | Refs

commit b6f5efed0f2ab14712c0abd933a83893632cb3d4
parent 5d3441876b76c2c7d86a7e757403a737d51affa4
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Wed, 17 Aug 2022 13:51:36 -0500

decmath: fix equality, add __eq

Diffstat:
Mdecmath.lua | 17++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/decmath.lua b/decmath.lua @@ -19,10 +19,25 @@ local meta = { end if a.exp > b.exp then - return {sig = b.sig * 10^(b.exp - a.exp), exp = a.exp} + return {sig = b.sig + a.sig * 10^(a.exp - b.exp), exp = b.exp} end return {sig = a.sig + b.sig, exp = a.exp} + end, + __eq = function(a, b) + if type(a) == "number" then + a = {sig = a, exp = 0} + end + + if type(b) == "number" then + b = {sig = b, exp = 0} + end + + if a.exp < b.exp then + a, b = b, a + end + + return a.sig == b.sig * 10^(a.exp - b.exp) end }