Skip to content

Instantly share code, notes, and snippets.

@JamesLiame
Last active February 8, 2025 01:49
Show Gist options
  • Save JamesLiame/5e90018a4ce5317e0c85e2049652fc15 to your computer and use it in GitHub Desktop.
Save JamesLiame/5e90018a4ce5317e0c85e2049652fc15 to your computer and use it in GitHub Desktop.
JS-port of MySQL (My Sector, Queue, List?) TinyInt
class TinyInt {
constructor(N = 0, sign) {
this.n = N;
switch (sign) {
case "unsigned":
if (N < 256 && N >= 0 && N % 1 == 0) {
return this.n;
} else if (N % 1 == 0) {
return new Error(
"SOLVE ERROR_UNSIGNED_TINYINT: Number OutOfRange (0/255)"
);
} else if (N < 256 && N >= 0) {
return new Error(
"SOLVE ERROR_UNSIGNED_TINYINT: Number Is A Float (N%1 != 0)"
);
}
case "signed":
if (N > -129 && N <= 127 && N % 1 == 0) {
return this.n;
} else if (N % 1 == 0) {
return new Error(
"SOLVE ERROR_SIGNED_TINYINT: Number OutOfRange (-129/127)"
);
} else if (N < 256 && N >= 0) {
return new Error(
"SOLVE ERROR_SIGNED_TINYINT: Number Is A Float (N%1 != 0)"
);
}
default:
break;
}
}
toBigInt() {
return BigInt(this.n);
}
toStr() {
return this.n.toString(36);
}
ExpForm() {
return this.n.toExponential(21);
}
Precision() {
return this.n.toPrecision(21);
}
FixedForm() {
return this.n.toFixed(20);
}
Extend(extendition) {
if (extendition <= 0) {
return 0;
} else {
return this.n * extendition;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment