public void TestBigDecimal() { BigDecimal decimal = new BigDecimal("1.1"); BigDecimalTransform format = new BigDecimalTransform(); String value = format.write(decimal); BigDecimal copy = format.read(value); AssertEquals(decimal, copy); }
public override void Move(int moveX, int moveY) { TerminateThreads(); xorigin -= (BigDecimal)(moveX) * (xmax - xmin) / (BigDecimal)screenWidth; yorigin -= (BigDecimal)(moveY) * (ymax - ymin) / (BigDecimal)screenHeight; Draw(numIterations, numThreads); }
public void Add(string a, int aScale, string b, int bScale, string c, int cScale) { BigDecimal aNumber = new BigDecimal(BigInteger.Parse(a), aScale); BigDecimal bNumber = new BigDecimal(BigInteger.Parse(b), bScale); BigDecimal result = aNumber.Add(bNumber); Assert.AreEqual(c, result.ToString(), "incorrect value"); Assert.AreEqual(cScale, result.Scale, "incorrect scale"); }
public PayPalItem (string name, uint quantity, BigDecimal price, string currency, string sku) { Name = name; Quantity = quantity; Price = price; Currency = currency; SKU = sku; }
public PayPalItem (string name, BigDecimal price, string currency) { Name = name; //Quantity = quantity; Price = price; Currency = currency; //SKU = sku; }
public virtual Number Calculate(BigDecimal num) { if (num == null) { return -0; } return num.Negate(); }
public void Abs() { BigDecimal big = BigDecimal.Parse("-1234"); BigDecimal bigabs = big.Abs(); Assert.IsTrue(bigabs.ToString().Equals("1234"), "the absolute value of -1234 is not 1234"); big = new BigDecimal(BigInteger.Parse("2345"), 2); bigabs = big.Abs(); Assert.IsTrue(bigabs.ToString().Equals("23.45"), "the absolute value of 23.45 is not 23.45"); }
public void AddWithContext(string a, int aScale, string b, int bScale, string c, int cScale, int precision, RoundingMode mode) { BigDecimal aNumber = new BigDecimal(BigInteger.Parse(a), aScale); BigDecimal bNumber = new BigDecimal(BigInteger.Parse(b), bScale); MathContext mc = new MathContext(precision, mode); BigDecimal result = aNumber.Add(bNumber, mc); Assert.AreEqual(c, result.ToString(), "incorrect value"); Assert.AreEqual(cScale, result.Scale, "incorrect scale"); }
/// <summary> /// The mathematical constant e. /// </summary> /// <param name="precision">The precision.</param> /// <returns>The mathematical constant e.</returns> public static BigDecimal EBig(int precision) { if (_EBig.Precision < precision) { _EBig = BigDecimal.Exp(BigDecimal.One.WithPrecision(precision + 10)); } return _EBig.WithPrecision(precision); }
public void CompareToBigDecimal() { BigDecimal comp1 = BigDecimal.Parse("1.00"); BigDecimal comp2 = new BigDecimal(1.000000D); Assert.IsTrue(comp1.CompareTo(comp2) == 0, "1.00 and 1.000000 should be equal"); BigDecimal comp3 = BigDecimal.Parse("1.02"); Assert.IsTrue(comp3.CompareTo(comp1) == 1, "1.02 should be bigger than 1.00"); BigDecimal comp4 = new BigDecimal(0.98D); Assert.IsTrue(comp4.CompareTo(comp1) == -1, "0.98 should be less than 1.00"); }
public void AddBigDecimal() { BigDecimal add1 = BigDecimal.Parse("23.456"); BigDecimal add2 = BigDecimal.Parse("3849.235"); BigDecimal sum = add1.Add(add2); Assert.IsTrue(sum.UnscaledValue.ToString().Equals("3872691") && sum.Scale == 3, "the sum of 23.456 + 3849.235 is wrong"); Assert.IsTrue(sum.ToString().Equals("3872.691"), "the sum of 23.456 + 3849.235 is not printed correctly"); BigDecimal add3 = new BigDecimal(12.34E02D); Assert.IsTrue((add1.Add(add3)).ToString().Equals("1257.456"), "the sum of 23.456 + 12.34E02 is not printed correctly"); }
public void Should_Allow_Custom_Primitive_Serializers() { var serializer = new Serializer(4, new [] {new BigDecimalSerializer()}); var value = new BigDecimal(5, 1); var buffer = serializer.Serialize(value); CollectionAssert.AreEqual(new byte[] { 0, 0, 0, 5, 1 }, buffer); var deserializedValue = serializer.Deserialize(buffer, ColumnTypeCode.Decimal, null); Assert.IsInstanceOf<BigDecimal>(deserializedValue); var deserializedDecimal = (BigDecimal) deserializedValue; Assert.AreEqual("0.00001", deserializedDecimal.ToString()); Assert.AreEqual(value.Scale, deserializedDecimal.Scale); Assert.AreEqual(value.UnscaledValue, deserializedDecimal.UnscaledValue); //Check that other serializers are still working CollectionAssert.AreEqual(new byte[] { 0, 0, 0, 10 }, serializer.Serialize(10)); CollectionAssert.AreEqual(new byte[] { 0x61 }, serializer.Serialize("a")); }
public override void Zoom(int posX, int posY, double factor) { BigDecimal xpos = xmin + ((BigDecimal)posX * (xmax - xmin) / (BigDecimal)screenWidth); BigDecimal ypos = ymin + ((BigDecimal)posY * (ymax - ymin) / (BigDecimal)screenHeight); BigDecimal xOffsetRatio = (xpos - xmin) / (xmax - xmin); BigDecimal yOffsetRatio = (ypos - ymin) / (ymax - ymin); BigDecimal newXextent = (xmax - xmin); newXextent *= factor; BigDecimal newYextent = (ymax - ymin); newYextent *= factor; TerminateThreads(); xextent = newXextent; xorigin = xpos - xextent * xOffsetRatio; yorigin = ypos - newYextent * yOffsetRatio; Draw(numIterations, numThreads); }
public void DivideAndRemainder1() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = 45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 70; String res = "277923185514690367474770683"; int resScale = 0; String rem = "1.3032693871288309587558885943391070087960319452465789990E-15"; int remScale = 70; BigDecimal aNumber = new BigDecimal(BigInteger.Parse(a), aScale); BigDecimal bNumber = new BigDecimal(BigInteger.Parse(b), bScale); BigDecimal remainder; BigDecimal quotient = aNumber.DivideAndRemainder(bNumber, out remainder); Assert.AreEqual(res, quotient.ToString(), "incorrect quotient value"); Assert.AreEqual(resScale, quotient.Scale, "incorrect quotient scale"); Assert.AreEqual(rem, remainder.ToString(), "incorrect remainder value"); Assert.AreEqual(remScale, remainder.Scale, "incorrect remainder scale"); }
public void ConstructorDouble() { BigDecimal big = new BigDecimal(123E04); Assert.AreEqual("1230000", big.ToString(), "the BigDecimal value taking a double argument is not initialized properly"); big = new BigDecimal(1.2345E-12); Assert.AreEqual(1.2345E-12, big.ToDouble(), "the double representation is not correct"); big = new BigDecimal(-12345E-3); Assert.AreEqual(-12.345, big.ToDouble(), "the double representation is not correct"); big = new BigDecimal(5.1234567897654321e138); Assert.AreEqual(5.1234567897654321E138, big.ToDouble(), "the double representation is not correct"); Assert.AreEqual(0, big.Scale, "the double representation is not correct"); big = new BigDecimal(0.1); Assert.IsTrue(big.ToDouble() == 0.1, "the double representation of 0.1 bigDecimal is not correct"); big = new BigDecimal(0.00345); Assert.IsTrue(big.ToDouble() == 0.00345, "the double representation of 0.00345 bigDecimal is not correct"); // regression test for HARMONY-2429 big = new BigDecimal(-0.0); Assert.IsTrue(big.Scale == 0, "the double representation of -0.0 bigDecimal is not correct"); }
public void TestToString() { BigDecimal d; // integers d = new BigDecimal(0, 0); Assert.AreEqual("0.", d.ToString()); d = new BigDecimal(1, 0); Assert.AreEqual("1.", d.ToString()); // with decimal point inside number d = new BigDecimal(1234, 2); Assert.AreEqual("12.34", d.ToString()); // with decimal point before number d = new BigDecimal(1, 2); Assert.AreEqual("0.01", d.ToString()); // really big number, with decimal point d = new BigDecimal(BigInteger.Parse("12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"), 20); Assert.AreEqual("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.12345678901234567890", d.ToString()); }
/* * This method shows use of optional payment details and item list. */ private PayPalPayment getStuffToBuy(string paymentIntent) { //--- include an item list, payment amount details PayPalItem[] items = { new PayPalItem("sample item #1", new Java.Lang.Integer(2), new BigDecimal("87.50"), "USD", "sku-12345678"), new PayPalItem("free sample item #2", new Java.Lang.Integer(1), new BigDecimal("0.00"), "USD", "sku-zero-price"), new PayPalItem("sample item #3 with a longer name", new Java.Lang.Integer(6), new BigDecimal("37.99"), "USD", "sku-33333") }; BigDecimal subtotal = PayPalItem.GetItemTotal(items); BigDecimal shipping = new BigDecimal("7.21"); BigDecimal tax = new BigDecimal("4.67"); PayPalPaymentDetails paymentDetails = new PayPalPaymentDetails(shipping, subtotal, tax); BigDecimal amount = subtotal.Add(shipping).Add(tax); PayPalPayment payment = new PayPalPayment(amount, "USD", "sample item", paymentIntent); payment.Items(items).PaymentDetails(paymentDetails); //--- set other optional fields like invoice_number, custom field, and soft_descriptor payment.Custom("This is text that will be associated with the payment that the app can use."); return payment; }
public static BigDecimal /*!*/ Power(RubyContext /*!*/ context, BigDecimal /*!*/ self, int other) { return(BigDecimal.Power(GetConfig(context), self, other)); }
public static object LessThan(RubyContext /*!*/ context, BigDecimal /*!*/ self, [NotNull] BigInteger /*!*/ other) { return(LessThenResult(self.CompareBigDecimal(BigDecimal.Create(GetConfig(context), other)))); }
public static RubyArray /*!*/ DivMod(RubyContext /*!*/ context, BigDecimal /*!*/ self, [NotNull] BigInteger /*!*/ other) { return(DivMod(context, self, BigDecimal.Create(GetConfig(context), other))); }
public static BigDecimal /*!*/ Abs(RubyContext /*!*/ context, BigDecimal /*!*/ self) { return(BigDecimal.Abs(GetConfig(context), self)); }
public static BigDecimal /*!*/ SquareRoot(RubyContext /*!*/ context, BigDecimal /*!*/ self, int n) { return(BigDecimal.SquareRoot(GetConfig(context), self, n)); }
public static BigDecimal /*!*/ Remainder(RubyContext /*!*/ context, BigDecimal /*!*/ self, [NotNull] BigDecimal /*!*/ other) { BigDecimal mod = Modulo(context, self, other); if (self.Sign == other.Sign) { return(mod); } else { return(BigDecimal.Subtract(GetConfig(context), mod, other)); } }
public static object LessThan(RubyContext/*!*/ context, BigDecimal/*!*/ self, [NotNull]BigInteger/*!*/ other) { int? c = self.CompareBigDecimal(BigDecimal.Create(GetConfig(context), other)); if (c.HasValue) { return c.Value < 0; } else { return null; } }
public static object Compare(BigDecimal /*!*/ self, [NotNull] BigDecimal /*!*/ other) { return(self.CompareBigDecimal(other)); }
private BigDecimal currencyFormat(BigDecimal value) { return(nDigitFormat(value, 2)); }
public static object GreaterThan(RubyContext /*!*/ context, BigDecimal /*!*/ self, double other) { return(GreaterThenResult(self.CompareBigDecimal(BigDecimal.Create(GetConfig(context), other)))); }
public static object LessThanOrEqual(RubyContext /*!*/ context, BigDecimal /*!*/ self, int other) { return(LessThanOrEqualResult(self.CompareBigDecimal(BigDecimal.Create(GetConfig(context), other)))); }
public static object LessThanOrEqual(BigDecimal /*!*/ self, [NotNull] BigDecimal /*!*/ other) { return(LessThanOrEqualResult(self.CompareBigDecimal(other))); }
public static object LessThan(BinaryOpStorage /*!*/ coercionStorage, BinaryOpStorage /*!*/ comparisonStorage, BigDecimal /*!*/ self, object other) { return(Protocols.TryCoerceAndApply(coercionStorage, comparisonStorage, "<", self, other)); }
public static object Compare(BinaryOpStorage /*!*/ coercionStorage, BinaryOpStorage /*!*/ comparisonStorage, BigDecimal /*!*/ self, object other) { return(Protocols.CoerceAndCompare(coercionStorage, comparisonStorage, self, other)); }
public static object LessThanOrEqual(RubyContext/*!*/ context, BigDecimal/*!*/ self, double other) { int? c = self.CompareBigDecimal(BigDecimal.Create(GetConfig(context), other)); if (c.HasValue) { return c.Value <= 0; } else { return null; } }
public static object Compare(RubyContext /*!*/ context, BigDecimal /*!*/ self, int other) { return(self.CompareBigDecimal(BigDecimal.Create(GetConfig(context), other))); }
public static object Equal(BigDecimal/*!*/ self, [NotNull]BigDecimal/*!*/ other) { // This is a hack since normal numeric values return false not nil for NaN comparison if (BigDecimal.IsNaN(self) || BigDecimal.IsNaN(other)) { return null; } return self.Equals(other); }
public static object SquareRoot(RubyContext /*!*/ context, BigDecimal /*!*/ self, object n) { throw RubyExceptions.CreateUnexpectedTypeError(context, n, "Fixnum"); }
public static bool Equal(RubyContext/*!*/ context, BigDecimal/*!*/ self, double other) { return self.Equals(BigDecimal.Create(GetConfig(context), other)); }
public static object Remainder(BinaryOpStorage /*!*/ coercionStorage, BinaryOpStorage /*!*/ binaryOpSite, BigDecimal /*!*/ self, object other) { return(Protocols.CoerceAndApply(coercionStorage, binaryOpSite, "remainder", self, other)); }
public static BigDecimal/*!*/ Round(RubyContext/*!*/ context, BigDecimal/*!*/ self, [Optional]int n) { return BigDecimal.LimitPrecision(GetConfig(context), self, n, GetConfig(context).RoundingMode); }
public static object DivMod(BinaryOpStorage /*!*/ coercionStorage, BinaryOpStorage /*!*/ binaryOpSite, RubyContext /*!*/ context, BigDecimal /*!*/ self, object other) { return(Protocols.CoerceAndApply(coercionStorage, binaryOpSite, "divmod", self, other)); }
public static BigDecimal/*!*/ Truncate(RubyContext/*!*/ context, BigDecimal/*!*/ self, [Optional]int n) { return BigDecimal.LimitPrecision(GetConfig(context), self, n, BigDecimal.RoundingModes.Down); }
public static RubyArray /*!*/ DivMod(RubyContext /*!*/ context, BigDecimal /*!*/ self, [NotNull] BigDecimal /*!*/ other) { BigDecimal div, mod; BigDecimal.DivMod(GetConfig(context), self, other, out div, out mod); return(RubyOps.MakeArray2(div, mod)); }
public static object Modulo(BinaryOpStorage /*!*/ moduloStorage, RubyContext /*!*/ context, BigDecimal /*!*/ self, double other) { var modulo = moduloStorage.GetCallSite("modulo"); return(modulo.Target(modulo, BigDecimal.ToFloat(GetConfig(context), self), other)); }
public static BigDecimal /*!*/ Identity(BigDecimal /*!*/ self) { return(self); }
public static object GreaterThan(BigDecimal /*!*/ self, [NotNull] BigDecimal /*!*/ other) { return(GreaterThenResult(self.CompareBigDecimal(other))); }
private BigDecimal priceFormat(BigDecimal value) { return(nDigitFormat(value, 4)); }
public static object GreaterThanOrEqual(BinaryOpStorage /*!*/ coercionStorage, BinaryOpStorage /*!*/ comparisonStorage, BigDecimal /*!*/ self, object other) { return(Protocols.TryCoerceAndApply(coercionStorage, comparisonStorage, ">=", self, other)); }
public static object GreaterThan(RubyContext/*!*/ context, BigDecimal/*!*/ self, int other) { int? c = self.CompareBigDecimal(BigDecimal.Create(GetConfig(context), other)); if (c.HasValue) { return c.Value > 0; } else { return null; } }
private BigDecimal quantityFormat(BigDecimal value) { return(nDigitFormat(value, 4)); }
public static object LessThanOrEqual(BigDecimal/*!*/ self, [NotNull]BigDecimal/*!*/ other) { int? c = self.CompareBigDecimal(other); if (c.HasValue) { return c.Value <= 0; } else { return null; } }
protected override PowerIterator createPowerIterator(BigDecimal x, MathContext mathContext) { return(new PowerNIterator(x, mathContext)); }
public static object LessThanOrEqual(RubyContext/*!*/ context, BigDecimal/*!*/ self, object other) { int? c = Protocols.CoerceAndCallCompare(context, self, other) as int?; if (c.HasValue) { return c.Value <= 0; } else { return null; } }
private bool OnSendCommand(string[] args) { if (args.Length < 4 || args.Length > 5) { Console.WriteLine("error"); return(true); } if (NoWallet()) { return(true); } string password = ConsoleHelper.ReadPassword("password"); if (password.Length == 0) { Console.WriteLine("cancelled"); return(true); } if (!Program.Wallet.VerifyPassword(password)) { Console.WriteLine("Incorrect password"); return(true); } UIntBase assetId; switch (args[1].ToLower()) { case "tedu": case "tans": assetId = Blockchain.GoverningToken.Hash; break; case "tgas": case "tanc": assetId = Blockchain.UtilityToken.Hash; break; default: assetId = UIntBase.Parse(args[1]); break; } UInt160 scriptHash = args[2].ToScriptHash(); bool isSendAll = string.Equals(args[3], "all", StringComparison.OrdinalIgnoreCase); Transaction tx; if (isSendAll) { Coin[] coins = Program.Wallet.FindUnspentCoins().Where(p => p.Output.AssetId.Equals(assetId)).ToArray(); tx = new ContractTransaction { Attributes = new TransactionAttribute[0], Inputs = coins.Select(p => p.Reference).ToArray(), Outputs = new[] { new TransactionOutput { AssetId = (UInt256)assetId, Value = coins.Sum(p => p.Output.Value), ScriptHash = scriptHash } } }; } else { AssetDescriptor descriptor = new AssetDescriptor(assetId); if (!BigDecimal.TryParse(args[3], descriptor.Decimals, out BigDecimal amount)) { Console.WriteLine("Incorrect Amount Format"); return(true); } Fixed8 fee = args.Length >= 5 ? Fixed8.Parse(args[4]) : Fixed8.Zero; tx = Program.Wallet.MakeTransaction(null, new[] { new TransferOutput { AssetId = assetId, Value = amount, ScriptHash = scriptHash } }, fee: fee); if (tx == null) { Console.WriteLine("Insufficient funds"); return(true); } } ContractParametersContext context = new ContractParametersContext(tx); Program.Wallet.Sign(context); if (context.Completed) { tx.Witnesses = context.GetWitnesses(); Program.Wallet.ApplyTransaction(tx); system.LocalNode.Tell(new LocalNode.Relay { Inventory = tx }); Console.WriteLine($"TXID: {tx.Hash}"); } else { Console.WriteLine("SignatureContext:"); Console.WriteLine(context.ToString()); } return(true); }
public static bool Equal(RubyContext/*!*/ context, BigDecimal/*!*/ self, [NotNull]BigInteger/*!*/ other) { return self.Equals(BigDecimal.Create(GetConfig(context), other)); }
public IconAmount(BigDecimal value, int digit) { _value = value; _digit = digit; }
public static object Equal(RubyContext/*!*/ context, BigDecimal/*!*/ self, object other) { // This is a hack since normal numeric values do not return nil for nil (they return false) if (other == null) { return null; } return Protocols.IsEqual(context, other, self); }
public static IconAmount Of(BigDecimal loop, int digit) { return(new IconAmount(loop, digit)); }
public static BigDecimal/*!*/ Round(RubyContext/*!*/ context, BigDecimal/*!*/ self, int n, int mode) { return BigDecimal.LimitPrecision(GetConfig(context), self, n, (BigDecimal.RoundingModes)mode); }
public static IconAmount Of(string loop, int digit) { return(Of(BigDecimal.Parse(loop), digit)); }
public static bool IsFinite(BigDecimal/*!*/ self) { return BigDecimal.IsFinite(self); }
public static BigDecimal /*!*/ Modulo(RubyContext /*!*/ context, BigDecimal /*!*/ self, [NotNull] BigInteger /*!*/ other) { return(Modulo(context, self, BigDecimal.Create(GetConfig(context), other))); }