Make Int36 toDecimal() more paranoid (we want perfect output, or no output at all)
This commit is contained in:
parent
7770a6bffe
commit
c1ab8918bd
1 changed files with 9 additions and 4 deletions
|
|
@ -245,10 +245,10 @@ class Int36 {
|
||||||
do {
|
do {
|
||||||
i36Tmp.div(i36Div);
|
i36Tmp.div(i36Div);
|
||||||
/*
|
/*
|
||||||
* In a perfect world, there would be no errors, because all Int36 calculations would
|
* In a perfect world, there would be no errors, because all Int36 calculations at
|
||||||
* involve positive values within their respective ranges, any remainder would always be less
|
* this point should be positive values, the remainder should always be less than the
|
||||||
* than the divisor, and the entire process would complete within 3 divisions. But until
|
* divisor, and the entire process should complete within 3 divisions. But until then,
|
||||||
* then, let's make sure we don't produce garbage or spin our wheels.
|
* let's make sure we don't produce garbage or spin our wheels.
|
||||||
*/
|
*/
|
||||||
if (i36Tmp.error || i36Tmp.remainder >= 10000000000 || !nMaxDivs--) {
|
if (i36Tmp.error || i36Tmp.remainder >= 10000000000 || !nMaxDivs--) {
|
||||||
s = "error";
|
s = "error";
|
||||||
|
|
@ -259,6 +259,11 @@ class Int36 {
|
||||||
i36Rem.set(i36Tmp.remainder);
|
i36Rem.set(i36Tmp.remainder);
|
||||||
do {
|
do {
|
||||||
i36Rem.divNum(10);
|
i36Rem.divNum(10);
|
||||||
|
if (i36Rem.remainder < 0 || i36Rem.remainder > 9) {
|
||||||
|
quotient = 0;
|
||||||
|
s = "error";
|
||||||
|
break;
|
||||||
|
}
|
||||||
s = String.fromCharCode(0x30 + i36Rem.remainder) + s;
|
s = String.fromCharCode(0x30 + i36Rem.remainder) + s;
|
||||||
} while (--nMinDigits > 0 || i36Rem.value);
|
} while (--nMinDigits > 0 || i36Rem.value);
|
||||||
} while (quotient);
|
} while (quotient);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue