Skip to content

Instantly share code, notes, and snippets.

@Tpaefawzen
Created February 17, 2025 09:04
Show Gist options
  • Select an option

  • Save Tpaefawzen/922ca8ec0dc7060f4bdbcd965b0656b9 to your computer and use it in GitHub Desktop.

Select an option

Save Tpaefawzen/922ca8ec0dc7060f4bdbcd965b0656b9 to your computer and use it in GitHub Desktop.
Lua library to implement some arithmetic things for esoteric programming language Dis
return function(base, digits)
local t = {
base = base;
digits = digits;
End = base ^ digits;
Max = base^digits - 1;
};
function t.is_representable(x) return 0<=x and x<=t.Max end
function t.rot(x)
return x//base + (x%base)*(t.End/base);
end
function t.opr(x, y)
if y <= 0 then return x end
return t.opr(x//base, y//base)*base + (base+x%base-y%base)%base;
end
function t.as_table(x)
local result = {};
end
return t;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment