public int comparesTo(Decimal other) { // s1, s2 : AnsiString; if (other == null) return 0; if (this.negative && !other.negative) return -1; else if (!this.negative && other.negative) return 1; else { int max = Math.max(this.decimal, other.decimal); String s1 = stringMultiply('0', max - this.decimal+1) + this.digits; String s2 = stringMultiply('0', max - other.decimal+1) + other.digits; if (s1.length() < s2.length()) s1 = s1 + stringMultiply('0', s2.length() - s1.length()); else if (s2.length() < s1.length()) s2 = s2 + stringMultiply('0', s1.length() - s2.length()); int result = s1.compareTo(s2); if (this.negative) result = -result; return result; } }
public String asDecimal() { String result = digits; if (decimal != digits.length()) if (decimal < 0) result = "0."+stringMultiply('0', 0-decimal)+digits; else if (decimal < result.length()) if (decimal == 0) result = "0."+result; else result = insert(".", result, decimal); else result = result + stringMultiply('0', decimal - result.length()); if (negative && !allZeros(result, 0)) result = "-" + result; return result; }
public String asScientific() { String result = digits; boolean zero = allZeros(result, 0); if (zero) { if (precision < 2) result = "0e0"; else result = "0."+stringMultiply('0', precision-1)+"e0"; } else { if (digits.length() > 1) result = insert(".", result, 1); result = result + 'e'+Integer.toString(decimal - 1); } if (negative && !zero) result = '-' + result; return result; }
private Decimal doSubtract(Decimal other) { int max = Math.max(decimal, other.decimal); String s1 = stringMultiply('0', max - decimal+1) + digits; String s2 = stringMultiply('0', max - other.decimal+1) + other.digits; if (s1.length() < s2.length()) s1 = s1 + stringMultiply('0', s2.length() - s1.length()); else if (s2.length() < s1.length()) s2 = s2 + stringMultiply('0', s1.length() - s2.length());
private Decimal doAdd(Decimal other) { int max = Math.max(decimal, other.decimal); String s1 = stringMultiply('0', max - decimal+1) + digits; String s2 = stringMultiply('0', max - other.decimal+1) + other.digits; if (s1.length() < s2.length()) s1 = s1 + stringMultiply('0', s2.length() - s1.length()); else if (s2.length() < s1.length()) s2 = s2 + stringMultiply('0', s1.length() - s2.length());
String s1 = stringMultiply('0', max - decimal+1) + digits; String s2 = stringMultiply('0', max - other.decimal+1) + other.digits; if (s1.length() < s2.length()) s1 = s1 + stringMultiply('0', s2.length() - s1.length()); else if (s2.length() < s1.length()) s2 = s2 + stringMultiply('0', s1.length() - s2.length()); s[i] = stringMultiply('0', s2.length()-(i+1)); int c = 0; for (int j = s1.length() - 1; j >= 0; j--) { t = Math.max(t, sv.length()); for (int i = 0; i < s.length; i++) s[i] = stringMultiply('0', t-s[i].length())+s[i];
int m = Math.max(digits.length(), other.digits.length()) + 40; // max loops we'll do String[] tens = new String[10]; tens[0] = stringAddition(stringMultiply('0', s.length()), s); for (int i = 1; i < 10; i++) tens[i] = stringAddition(tens[i-1], s);
public int comparesTo(Decimal other) { // s1, s2 : AnsiString; if (other == null) return 0; if (this.negative && !other.negative) return -1; else if (!this.negative && other.negative) return 1; else { int max = Math.max(this.decimal, other.decimal); String s1 = stringMultiply('0', max - this.decimal+1) + this.digits; String s2 = stringMultiply('0', max - other.decimal+1) + other.digits; if (s1.length() < s2.length()) s1 = s1 + stringMultiply('0', s2.length() - s1.length()); else if (s2.length() < s1.length()) s2 = s2 + stringMultiply('0', s1.length() - s2.length()); int result = s1.compareTo(s2); if (this.negative) result = -result; return result; } }
public String asDecimal() { String result = digits; if (decimal != digits.length()) if (decimal < 0) result = "0."+stringMultiply('0', 0-decimal)+digits; else if (decimal < result.length()) if (decimal == 0) result = "0."+result; else result = insert(".", result, decimal); else result = result + stringMultiply('0', decimal - result.length()); if (negative && !allZeros(result, 0)) result = "-" + result; return result; }
public String asScientific() { String result = digits; boolean zero = allZeros(result, 0); if (zero) { if (precision < 2) result = "0e0"; else result = "0."+stringMultiply('0', precision-1)+"e0"; } else { if (digits.length() > 1) result = insert(".", result, 1); result = result + 'e'+Integer.toString(decimal - 1); } if (negative && !zero) result = '-' + result; return result; }
private Decimal doAdd(Decimal other) { int max = Math.max(decimal, other.decimal); String s1 = stringMultiply('0', max - decimal+1) + digits; String s2 = stringMultiply('0', max - other.decimal+1) + other.digits; if (s1.length() < s2.length()) s1 = s1 + stringMultiply('0', s2.length() - s1.length()); else if (s2.length() < s1.length()) s2 = s2 + stringMultiply('0', s1.length() - s2.length());
private Decimal doSubtract(Decimal other) { int max = Math.max(decimal, other.decimal); String s1 = stringMultiply('0', max - decimal+1) + digits; String s2 = stringMultiply('0', max - other.decimal+1) + other.digits; if (s1.length() < s2.length()) s1 = s1 + stringMultiply('0', s2.length() - s1.length()); else if (s2.length() < s1.length()) s2 = s2 + stringMultiply('0', s1.length() - s2.length());
String s1 = stringMultiply('0', max - decimal+1) + digits; String s2 = stringMultiply('0', max - other.decimal+1) + other.digits; if (s1.length() < s2.length()) s1 = s1 + stringMultiply('0', s2.length() - s1.length()); else if (s2.length() < s1.length()) s2 = s2 + stringMultiply('0', s1.length() - s2.length()); s[i] = stringMultiply('0', s2.length()-(i+1)); int c = 0; for (int j = s1.length() - 1; j >= 0; j--) { t = Math.max(t, sv.length()); for (int i = 0; i < s.length; i++) s[i] = stringMultiply('0', t-s[i].length())+s[i];
int m = Math.max(digits.length(), other.digits.length()) + 40; // max loops we'll do String[] tens = new String[10]; tens[0] = stringAddition(stringMultiply('0', s.length()), s); for (int i = 1; i < 10; i++) tens[i] = stringAddition(tens[i-1], s);