diff options
Diffstat (limited to 'macros/luatex/latex/luamaths/luamaths-fractions.lua')
-rw-r--r-- | macros/luatex/latex/luamaths/luamaths-fractions.lua | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/macros/luatex/latex/luamaths/luamaths-fractions.lua b/macros/luatex/latex/luamaths/luamaths-fractions.lua index f13d335245..6900b25ec4 100644 --- a/macros/luatex/latex/luamaths/luamaths-fractions.lua +++ b/macros/luatex/latex/luamaths/luamaths-fractions.lua @@ -1,9 +1,9 @@ -- The luafractions module -- Authors: Chetan Shirore and Ajit Kumar --- version 1.2, Date=21-Aug-2023 +-- version 1.3, Date=23-Aug-2023 -- Licensed under LaTeX Project Public License v1.3c or later. The complete license text is available at http://www.latex-project.org/lppl.txt. -M = {} -- the module +M = {} -- the module frac_mt = {} -- the metatable function M.new (n, d, mode) mode = mode or 'fracs' @@ -41,8 +41,11 @@ function M.simp (num) end function M.toFnumber(c) +if getmetatable( c ) == frac_mt then return c.n / c.d end +return c +end function M.toFrac(x) if type(x) == "number" then @@ -216,6 +219,48 @@ function M.tostring (c) return string.format("\\frac{%g}{%g}", c.n, c.d) end + +function lnumChqEql(x, y) + + if type(x) == "number" and type(y) == "number" then + return (x == y) + end + + if getmetatable( x ) == frac_mt and getmetatable( y ) == frac_mt then + return (M.toFnumber(x) == M.toFnumber(y)) + end + + if type(x) == "number" and getmetatable( y ) == frac_mt then + return (M.toFnumber(y) == x) + end + + if getmetatable( x ) == frac_mt and type(y) == "number" then + return (M.toFnumber(x) == y) + end + + if getmetatable( x ) == complex_meta and getmetatable( y ) == complex_meta then + return M.toFnumber(x[1]) == M.toFnumber(y[1]) and M.toFnumber(x[2]) == M.toFnumber(y[2]) + end + + if type(x) == "number" and getmetatable( y ) == complex_meta then + return (M.toFnumber(y[1]) == x and M.toFnumber(y[2]) == 0) + end + + if getmetatable(x) == complex_meta and type( y ) == "number" then + return (M.toFnumber(x[1]) == y and M.toFnumber(x[2]) == 0) + end + + if getmetatable( x ) == frac_mt and getmetatable( y ) == complex_meta then + return (M.toFnumber(x)==M.toFnumber(y[1]) and M.toFnumber(y[2]) == 0) + end + + if getmetatable( x ) == complex_meta and getmetatable( y ) == frac_mt then + return (M.toFnumber(y)==M.toFnumber(x[1]) and M.toFnumber(x[2]) == 0) + end + + return false +end + --Setting Metatable operations. frac_mt.__add = M.add frac_mt.__sub = M.sub @@ -224,5 +269,6 @@ frac_mt.__div = M.div frac_mt.__unm = minusFracs frac_mt.__pow = powerFracs frac_mt.__tostring = M.tostring +frac_mt.__eq = lnumChqEql return M
\ No newline at end of file |