public void Format() { IdleCurrency r = new IdleCurrency(Value, Exp); r = Format(r); Value = r.Value; Exp = r.Exp; }
public static IdleCurrency Abs(IdleCurrency value) { if (value.Sign < 0) { return(-value); } return(value); }
public static IdleCurrency Multiply(IdleCurrency left, IdleCurrency right) { IdleCurrency bd = new IdleCurrency( left.Value * right.Value, left.Exp + right.Exp); bd.Simplify(); return(bd); }
public void ButtonPressed() { buttonPrice += buttonPrice * rateOfPriceIncrease; buttonText.text = buttonPrice.ToShortString(); rateOfChange += rateOfUnitIncrease; rateOfChangeText.text = rateOfChange.ToShortString() + "/sec"; CompareAndHandleButtonActivation(unit, buttonPrice); }
public static IdleCurrency Divide(IdleCurrency dividend, IdleCurrency divisor) { if (divisor == 0) { throw new DivideByZeroException(); } IdleCurrency bd = new IdleCurrency( dividend.Value / divisor.Value, dividend.Exp - divisor.Exp); bd.Simplify(); return(bd); }
public static IdleCurrency operator +(IdleCurrency a, IdleCurrency b) { if (a.Exp == b.Exp) { IdleCurrency m = new IdleCurrency(); m.Exp = a.Exp; m.Value = a.Value + b.Value; m.Simplify(); return(m); } else if (a.Exp > b.Exp) { // a is bigger int deltaExp = a.Exp - b.Exp; if (deltaExp <= 16) { double bX = b.Value / Math.Pow(10, (double)deltaExp); IdleCurrency m = new IdleCurrency(); m.Exp = a.Exp; m.Value = a.Value + bX; m.Simplify(); return(m); } else { return(a); } } else { // b is bigger int deltaExp = b.Exp - a.Exp; if (deltaExp <= 16) { double aX = a.Value / Math.Pow(10, (double)deltaExp); IdleCurrency m = new IdleCurrency(); m.Exp = b.Exp; m.Value = b.Value + aX; m.Simplify(); return(m); } else { return(b); } } }
private void CompareAndHandleButtonActivation(IdleCurrency unit, IdleCurrency currentCost) { int a = IdleCurrency.Compare(unit, currentCost); // D.Log($"a = {a}"); if (a == -1) { // D.Log($"unit {unit.ToShortString()} is less than currentCost {currentCost.ToShortString()}"); priceButton.interactable = false; } else { // D.Log($"unit {unit.ToShortString()} is greater than currentCost {currentCost.ToShortString()}"); priceButton.interactable = true; } }
public static IdleCurrency Format(IdleCurrency a) { IdleCurrency r = a; int p = r.Exp; double rV = r.Value; if (rV < 1 && p <= 3) { rV = rV * Math.Pow(10, (double)p); p = 0; } while (rV < 100 && p > 3) { rV = rV * 10; p--; } if (p < 3) { rV = rV * Math.Pow(10, (double)p); p = 0; } else { if (p % 3 != 0) { rV = rV * Math.Pow(10, (double)(p % 3)); p -= (p % 3); } if (rV >= 1000) { rV = rV / 1000; p += 3; } } r.Value = rV; r.Exp = p; return(r); }
public static int Compare(IdleCurrency left, IdleCurrency right) { left.Format(); right.Format(); int leftSign = left.Sign; int rightSign = right.Sign; // Compare signs if (leftSign == 0 && rightSign == 0) { return(0); } if (leftSign >= 0 && rightSign < 0) { return(1); } if (leftSign < 0 && rightSign >= 0) { return(-1); } // Compare exponents if (left.Exp > right.Exp) { return(1); } if (left.Exp < right.Exp) { return(-1); } return(left.Value.CompareTo(right.Value)); }
public static int Compare(IdleCurrency left, object right) { if (right is IdleCurrency) { return(Compare(left, (IdleCurrency)right)); } if (right is bool) { return(Compare(left, new IdleCurrency((bool)right))); } if (right is byte) { return(Compare(left, new IdleCurrency((byte)right))); } if (right is char) { return(Compare(left, new IdleCurrency((char)right))); } if (right is decimal) { return(Compare(left, new IdleCurrency((decimal)right))); } if (right is double) { return(Compare(left, new IdleCurrency((double)right))); } if (right is short) { return(Compare(left, new IdleCurrency((short)right))); } if (right is int) { return(Compare(left, new IdleCurrency((int)right))); } if (right is long) { return(Compare(left, new IdleCurrency((long)right))); } if (right is sbyte) { return(Compare(left, new IdleCurrency((sbyte)right))); } if (right is float) { return(Compare(left, new IdleCurrency((float)right))); } if (right is ushort) { return(Compare(left, new IdleCurrency((ushort)right))); } if (right is uint) { return(Compare(left, new IdleCurrency((uint)right))); } if (right is ulong) { return(Compare(left, new IdleCurrency((ulong)right))); } throw new ArgumentException(); }
public static IdleCurrency operator *(float a, IdleCurrency b) { IdleCurrency A = new IdleCurrency(a); return(A * b); }
public static IdleCurrency operator *(IdleCurrency a, float b) { IdleCurrency B = new IdleCurrency(b); return(a * B); }
public static IdleCurrency Subtract(IdleCurrency left, IdleCurrency right) { return(left - right); }
public static IdleCurrency Add(IdleCurrency left, IdleCurrency right) { return(left + right); }
public static IdleCurrency operator /(IdleCurrency a, int b) { IdleCurrency B = new IdleCurrency(b); return(a / B); }
public int CompareTo(IdleCurrency value) { return(Compare(this, value)); }
public static IdleCurrency operator /(int a, IdleCurrency b) { IdleCurrency A = new IdleCurrency(a); return(A / b); }
public void Divide() { IdleCurrency newC = value1 / value2; Debug.Log("Result --> " + newC.ToShortString() + " SaveAbleString --> " + newC.GetStringForSave()); }
private void SecondElapsed() { unit += rateOfChange; showText.text = unit.ToShortString(); CompareAndHandleButtonActivation(unit, buttonPrice); }