public void RationalizeTakesIntegerToBigInteger() { BigDecimal bd = BigDecimal.Parse("12345"); object r = Numbers.rationalize(bd); Expect(r, InstanceOf(typeof(BigInt))); BigInt bi = (BigInt)r; Expect(bi, EqualTo(BigInt.fromBigInteger(BigInteger.Parse("12345")))); }
public void TestBigDecimal() { var bigDecimal = BigDecimal.Parse("123.456d101"); value.SetField("value", factory.NewDecimal(bigDecimal)); var reader = IonReaderBuilder.Build(value); jsonWriter.WriteValues(reader); Assert.AreEqual("{\"value\":123456e98}", this.sw.ToString()); }
public override object?ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer) { var str = serializer.Deserialize <string>(reader); if (str == null) { return(null); } return(BigDecimal.Parse(str)); }
public void ShouldRoundCorrectly(string value) { var big = BigDecimal.Parse(value); decimal regular = decimal.Parse(value, CultureInfo.InvariantCulture); decimal roundedRegular = Math.Round(regular, MidpointRounding.AwayFromZero); var roundedBig = big.RoundAwayFromZero(significantDigits: 0); Assert.Equal(expected: (BigDecimal)roundedRegular, roundedBig); }
protected virtual JObject SendFrom(JArray _params) { CheckWallet(); UInt160 assetId = UInt160.Parse(_params[0].AsString()); UInt160 from = AddressToScriptHash(_params[1].AsString()); UInt160 to = AddressToScriptHash(_params[2].AsString()); AssetDescriptor descriptor = new AssetDescriptor(assetId); BigDecimal amount = BigDecimal.Parse(_params[3].AsString(), descriptor.Decimals); if (amount.Sign <= 0) { throw new RpcException(-32602, "Invalid params"); } Signer[] signers = _params.Count >= 5 ? ((JArray)_params[4]).Select(p => new Signer() { Account = AddressToScriptHash(p.AsString()), Scopes = WitnessScope.CalledByEntry }).ToArray() : null; Transaction tx = wallet.MakeTransaction(new[] { new TransferOutput { AssetId = assetId, Value = amount, ScriptHash = to } }, from, signers); if (tx == null) { throw new RpcException(-300, "Insufficient funds"); } ContractParametersContext transContext = new ContractParametersContext(tx); wallet.Sign(transContext); if (!transContext.Completed) { return(transContext.ToJson()); } tx.Witnesses = transContext.GetWitnesses(); if (tx.Size > 1024) { long calFee = tx.Size * 1000 + 100000; if (tx.NetworkFee < calFee) { tx.NetworkFee = calFee; } } if (tx.NetworkFee > settings.MaxFee) { throw new RpcException(-301, "The necessary fee is more than the Max_fee, this transaction is failed. Please increase your Max_fee value."); } return(SignAndRelay(tx)); }
public void RationalizeTakesFractionToBigInteger() { BigDecimal bd = BigDecimal.Parse("123.45"); object r = Numbers.rationalize(bd); Expect(r, InstanceOf(typeof(Ratio))); Ratio rr = (Ratio)r; Ratio ratio = new Ratio(BigInteger.Create(12345 / 5), BigInteger.Create(100 / 5)); Expect(rr, EqualTo(ratio)); }
public override IValue GetBasicValue(Symbol symbol) { if (symbol.Value.StartsWith("\"")) { return(new ConcreteValue(new StringValue(symbol.Value.Substring(1, symbol.Value.Length - 2)))); } else { return(new ConcreteValue(new RealNumber(BigDecimal.Parse(symbol.Value)))); } }
public void RationalizeTakesFractionToBigInteger() { BigDecimal bd = BigDecimal.Parse("123.45"); object r = Numbers.rationalize(bd); Expect(r).To.Be.An.Instance.Of <Ratio>(); Ratio rr = (Ratio)r; Ratio ratio = new Ratio(BigInteger.Create(12345 / 5), BigInteger.Create(100 / 5)); Expect(rr).To.Equal(ratio); }
public BigDecimal StarsLifeSpan(BigDecimal lum, BigDecimal eng) { BigInteger energy = eng; BigInteger luminosity = lum; BigDecimal age = energy.Divide(luminosity).Divide(BigDecimal.Parse("31579200")); //convertion for sec to years ^^^^^^^^ setage(age); return(age); }
public void ToBigDecimalWithContextWorks() { BigInteger n1 = BigInteger.Create(1); BigInteger d1 = BigInteger.Create(3); Ratio r1 = new Ratio(n1, d1); BigDecimal.Context c = new BigDecimal.Context(6, BigDecimal.RoundingMode.HalfUp); BigDecimal bd = r1.ToBigDecimal(c); Expect(bd, EqualTo(BigDecimal.Parse("0.333333"))); }
public void BigDecimal_Parse(string input, int?compare) { BigDecimal bd = BigDecimal.Parse(input, CultureInfo.InvariantCulture); Assert.AreEqual(input, bd.ToString(CultureInfo.InvariantCulture)); Assert.AreEqual(double.Parse(input, CultureInfo.InvariantCulture), (double)bd); if (compare != null) { Assert.AreEqual(compare, (int)bd); } }
public TxOutListBoxItem GetOutput() { AssetDescriptor asset = (AssetDescriptor)comboBox1.SelectedItem; return(new TxOutListBoxItem { AssetName = asset.AssetName, AssetId = asset.AssetId, Value = BigDecimal.Parse(textBox2.Text, asset.Decimals), ScriptHash = textBox1.Text.ToScriptHash() }); }
public void TestParse() { string s = "12345"; byte decimals = 0; BigDecimal.Parse(s, decimals).Should().Be(new BigDecimal(new BigInteger(12345), 0)); s = "abcdEfg"; Action action = () => BigDecimal.Parse(s, decimals); action.ShouldThrow <FormatException>(); }
public TxOutListBoxItem GetOutput() { AssetDescriptor asset = (AssetDescriptor)comboBox1.SelectedItem; return(new TxOutListBoxItem { AssetName = asset.AssetName, AssetId = asset.AssetId, Value = BigDecimal.Parse(textBox2.Text, asset.Decimals), ScriptHash = textBox1.Text.ToScriptHash(Service.NeoSystem.Settings.AddressVersion) }); }
private JObject SendMany(UInt160 from, JArray to) { CheckWallet(); if (to.Count == 0) { throw new RpcException(-32602, "Invalid params"); } TransferOutput[] outputs = new TransferOutput[to.Count]; for (int i = 0; i < to.Count; i++) { UInt160 asset_id = UInt160.Parse(to[i]["asset"].AsString()); AssetDescriptor descriptor = new AssetDescriptor(asset_id); outputs[i] = new TransferOutput { AssetId = asset_id, Value = BigDecimal.Parse(to[i]["value"].AsString(), descriptor.Decimals), ScriptHash = to[i]["address"].AsString().ToScriptHash() }; if (outputs[i].Value.Sign <= 0) { throw new RpcException(-32602, "Invalid params"); } } Transaction tx = Wallet.MakeTransaction(outputs, from); if (tx == null) { throw new RpcException(-300, "Insufficient funds"); } ContractParametersContext transContext = new ContractParametersContext(tx); Wallet.Sign(transContext); if (!transContext.Completed) { return(transContext.ToJson()); } tx.Witnesses = transContext.GetWitnesses(); if (tx.Size > 1024) { long calFee = tx.Size * 1000 + 100000; if (tx.NetworkFee < calFee) { tx.NetworkFee = calFee; } } if (tx.NetworkFee > Settings.Default.MaxFee) { throw new RpcException(-301, "The necessary fee is more than the Max_fee, this transaction is failed. Please increase your Max_fee value."); } return(SignAndRelay(tx)); }
private RestSettings(IConfigurationSection section) { this.BindAddress = IPAddress.Parse(section.GetSection("BindAddress").Value); this.Port = ushort.Parse(section.GetSection("Port").Value); this.SslCert = section.GetSection("SslCert").Value; this.SslCertPassword = section.GetSection("SslCertPassword").Value; this.TrustedAuthorities = section.GetSection("TrustedAuthorities").GetChildren().Select(p => p.Get <string>()).ToArray(); this.RpcUser = section.GetSection("RpcUser").Value; this.RpcPass = section.GetSection("RpcPass").Value; this.MaxGasInvoke = (long)BigDecimal.Parse(section.GetValue("MaxGasInvoke", "10"), NativeContract.GAS.Decimals).Value; this.MaxFee = (long)BigDecimal.Parse(section.GetValue("MaxFee", "0.1"), NativeContract.GAS.Decimals).Value; this.DisabledMethods = section.GetSection("DisabledMethods").GetChildren().Select(p => p.Get <string>()).ToArray(); }
public BigDecimal StarsEnergy(BigInteger mass, BigDecimal massUsedUp, BigDecimal massAtCenter) { BigDecimal eng = BigDecimal.Parse("0"); BigInteger speedOfLightSq = BigInteger.Parse("89875517900000000"); BigDecimal mass2 = BigDecimal.Parse(mass); //.007 eng = massUsedUp.Multiply(massAtCenter); eng = eng.Multiply(mass2); eng = eng.Multiply(BigDecimal.Parse(speedOfLightSq)); setEnergy(eng); return(eng); }
private JObject SendToAddress(UInt160 assetId, UInt160 scriptHash, string value, long fee) { CheckWallet(); AssetDescriptor descriptor = new AssetDescriptor(assetId); BigDecimal amount = BigDecimal.Parse(value, descriptor.Decimals); if (amount.Sign <= 0) { throw new RpcException(-32602, "Invalid params"); } if (fee < 0) { throw new RpcException(-32602, "Invalid params"); } Transaction tx = Wallet.MakeTransaction(null, new[] { new TransferOutput { AssetId = assetId, Value = amount, ScriptHash = scriptHash } }, net_fee: fee); if (tx == null) { throw new RpcException(-300, "Insufficient funds"); } ContractParametersContext transContext = new ContractParametersContext(tx); Wallet.Sign(transContext); if (!transContext.Completed) { return(transContext.ToJson()); } tx.Witnesses = transContext.GetWitnesses(); if (tx.Size > 1024) { long calFee = tx.Size * 1000 + 100000; if (tx.NetworkFee < calFee) { tx.NetworkFee = calFee; } } if (tx.NetworkFee > Settings.Default.MaxFee) { throw new RpcException(-301, "The necessary fee is more than the Max_fee, this transaction is failed. Please increase your Max_fee value."); } return(SignAndRelay(tx)); }
protected virtual JObject SendToAddress(JArray _params) { CheckWallet(); UInt160 assetId = UInt160.Parse(_params[0].AsString()); UInt160 to = AddressToScriptHash(_params[1].AsString(), system.Settings.AddressVersion); using var snapshot = system.GetSnapshot(); AssetDescriptor descriptor = new AssetDescriptor(snapshot, system.Settings, assetId); BigDecimal amount = BigDecimal.Parse(_params[2].AsString(), descriptor.Decimals); if (amount.Sign <= 0) { throw new RpcException(-32602, "Invalid params"); } Transaction tx = wallet.MakeTransaction(snapshot, new[] { new TransferOutput { AssetId = assetId, Value = amount, ScriptHash = to } }); if (tx == null) { throw new RpcException(-300, "Insufficient funds"); } ContractParametersContext transContext = new ContractParametersContext(snapshot, tx); wallet.Sign(transContext); if (!transContext.Completed) { return(transContext.ToJson()); } tx.Witnesses = transContext.GetWitnesses(); if (tx.Size > 1024) { long calFee = tx.Size * 1000 + 100000; if (tx.NetworkFee < calFee) { tx.NetworkFee = calFee; } } if (tx.NetworkFee > settings.MaxFee) { throw new RpcException(-301, "The necessary fee is more than the Max_fee, this transaction is failed. Please increase your Max_fee value."); } return(SignAndRelay(snapshot, tx)); }
public BigDecimal calDens(BigDecimal radius) { BigDecimal vol = BigDecimal.Parse("0.0"); BigDecimal num = BigDecimal.Parse("1.33333333333"); BigDecimal pi = BigDecimal.Parse(Math.PI.ToString()); BigDecimal mass = BigInteger.Parse("1990000000000000000000000000000"); BigDecimal dens = BigDecimal.Parse("0.0"); num = num.Multiply(pi); vol = radius.Pow(3); vol = num.Multiply(vol); dens = mass / (vol); //while (mass.compareTo(vol.toBigInteger()) < 0) while (mass.CompareTo(((BigInteger)vol)) < 0) { if (type == ("Average_Star")) { mass = range(Average_Starmax, Average_Starmin); } if (type == ("Massive_Star")) { mass = range(Massive_Starmax, Massive_Starmin); } if (type == ("White_Dwarf")) { mass = range(White_Dwarfmax, White_Dwarfmin); } if (type == ("Neutron_Star")) { mass = range(Neutron_Starmax, Neutron_Starmin); } if (type == ("Black_hole")) { mass = range(Black_holemax, Black_holemin); } else { break; } } dens = mass / (vol); density = dens; //if(density.compareTo(BigDecimal.Parse("1")) < 0 ){ // Console.WriteLine("its 0"); // System.exit(0); //} return(dens); }
private static Number UpTolevel(Number num, int level) { if (num == null) { return(0); } switch (level) { case NumInt: { if (num.TypeCode == NumberTypeCode.Int32) { return(num); } return(num); } case NumLong: { if (num.TypeCode == NumberTypeCode.Int64) { return(num); } return(num); } case NumBigInteger: { if (num.TypeCode == NumberTypeCode.BigInteger) { return(num); } return(BigInteger.Parse(num.ToString())); } case NumBigDecimal: { if (num.TypeCode == NumberTypeCode.BigDecimal) { return(num); } return(BigDecimal.Parse(num.ToString())); } default: { throw new ArgumentException("unsupported number level: " + level); } } }
public IActionResult SendFrom(string assetid, string from, string to, string amount) { CheckWallet(); UInt160 assetId = UInt160.Parse(assetid); UInt160 _from = from.ToScriptHash(); UInt160 _to = to.ToScriptHash(); AssetDescriptor descriptor = new AssetDescriptor(assetId); BigDecimal _amount = BigDecimal.Parse(amount, descriptor.Decimals); if (_amount.Sign <= 0) { throw new RestException(-300, "Insufficient funds"); } Transaction tx = wallet.MakeTransaction(new[] { new TransferOutput { AssetId = assetId, Value = _amount, ScriptHash = _to } }, _from); if (tx == null) { throw new RestException(-300, "Insufficient funds"); } ContractParametersContext transContext = new ContractParametersContext(tx); wallet.Sign(transContext); if (!transContext.Completed) { return(FormatJson(transContext.ToJson())); } tx.Witnesses = transContext.GetWitnesses(); if (tx.Size > 1024) { long calFee = tx.Size * 1000 + 100000; if (tx.NetworkFee < calFee) { tx.NetworkFee = calFee; } } if (tx.NetworkFee > RestSettings.Default.MaxFee) { throw new RestException(-301, "The necessary fee is more than the Max_fee, this transaction is failed. Please increase your Max_fee value."); } return(FormatJson(SignAndRelay(tx))); }
public void TestParse002() { var result1 = BigDecimal.Parse(""); Assert.AreEqual(result1, BigDecimal.Zero); var result2 = BigDecimal.Parse("0"); Assert.AreEqual(result2, BigDecimal.Zero); var result3 = BigDecimal.Parse("-0"); Assert.AreEqual(result3, BigDecimal.Zero); }
private JObject SendFrom(JArray _params) { CheckWallet(); UInt160 assetId = UInt160.Parse(_params[0].AsString()); UInt160 from = _params[1].AsString().ToScriptHash(); UInt160 to = _params[2].AsString().ToScriptHash(); AssetDescriptor descriptor = new AssetDescriptor(assetId); BigDecimal amount = BigDecimal.Parse(_params[3].AsString(), descriptor.Decimals); if (amount.Sign <= 0) { throw new RpcException(-32602, "Invalid params"); } Transaction tx = wallet.MakeTransaction(new[] { new TransferOutput { AssetId = assetId, Value = amount, ScriptHash = to } }, from); if (tx == null) { throw new RpcException(-300, "Insufficient funds"); } ContractParametersContext transContext = new ContractParametersContext(tx); wallet.Sign(transContext); if (!transContext.Completed) { return(transContext.ToJson()); } tx.Witnesses = transContext.GetWitnesses(); if (tx.Size > 1024) { long calFee = tx.Size * 1000 + 100000; if (tx.NetworkFee < calFee) { tx.NetworkFee = calFee; } } if (tx.NetworkFee > Settings.Default.MaxFee) { throw new RpcException(-301, "The necessary fee is more than the Max_fee, this transaction is failed. Please increase your Max_fee value."); } return(SignAndRelay(tx)); }
public void Massive_Star() { Random ran = new Random(); diameter = range(BigInteger.Parse("5000000000"), BigInteger.Parse("100000000000")); mass = range(Massive_Starmax, Massive_Starmin); surfaceTemperature = ran.Next(30000, 60000); this.massUsedUp = BigDecimal.Parse(".007"); this.massAtCenter = BigDecimal.Parse(".24"); BigDecimal dia = BigDecimal.Parse(diameter); spin = range(BigInteger.Parse("200"), BigInteger.Parse("350")); density = calDens(dia.Divide(num2)); }
public void Black_hole() { Random ran = new Random(); diameter = range(BigInteger.Parse("100000000000"), BigInteger.Parse("10000000000000000")); mass = range(Black_holemax, Black_holemin); surfaceTemperature = 1; this.massUsedUp = BigDecimal.Parse(".007"); this.massAtCenter = BigDecimal.Parse("1"); BigDecimal dia = BigDecimal.Parse(diameter); spin = range(BigInteger.Parse("50000"), BigInteger.Parse("251825")); density = calDens(dia.Divide(num2)); }
public void White_Dwarf() { Random ran = new Random(); diameter = range(BigInteger.Parse("6000000"), BigInteger.Parse("12000000")); mass = range(White_Dwarfmax, White_Dwarfmin); surfaceTemperature = ran.Next(500000, 100000); this.massUsedUp = BigDecimal.Parse(".007"); this.massAtCenter = BigDecimal.Parse("1"); BigDecimal dia = BigDecimal.Parse(diameter); spin = BigInteger.Parse("2000"); density = calDens(dia.Divide(num2)); }
public void Red_Super_Giant() { Random ran = new Random(); diameter = range(BigInteger.Parse("1000000000000"), BigInteger.Parse("2000000000000")); mass = range(Red_Super_Giantmax, Red_Super_Giantmin); surfaceTemperature = ran.Next(1000, 3500); this.massUsedUp = BigDecimal.Parse("0.00147441058"); this.massAtCenter = BigDecimal.Parse(".4"); BigDecimal dia = BigDecimal.Parse(diameter); spin = BigInteger.Parse("1"); density = calDens(dia.Divide(num2)); }
static void Main(string[] args) { BigInteger a = BigInteger.Parse("1391400037"); BigInteger b = BigInteger.Parse("1990000000000000000000000000000"); BigDecimal c = BigDecimal.Parse(".007"); BigDecimal d = BigDecimal.Parse(".1"); BigInteger two = BigInteger.Parse("2"); //BigInteger a = range(BigInteger.Parse("100"), BigInteger.Parse("10")); //stars star = new stars("Average_Star", a, b, 5778, c, d); stars star = new stars(); star.starinfo(); Console.ReadKey(); }
public static Transaction TransactionFromJson(JObject json) { return(new Transaction { Version = byte.Parse(json["version"].AsString()), Nonce = uint.Parse(json["nonce"].AsString()), Signers = ((JArray)json["signers"]).Select(p => SignerFromJson(p)).ToArray(), SystemFee = (long)BigDecimal.Parse(json["sysfee"].AsString(), NativeContract.GAS.Decimals).Value, NetworkFee = (long)BigDecimal.Parse(json["netfee"].AsString(), NativeContract.GAS.Decimals).Value, ValidUntilBlock = uint.Parse(json["validuntilblock"].AsString()), Attributes = ((JArray)json["attributes"]).Select(p => TransactionAttributeFromJson(p)).ToArray(), Script = Convert.FromBase64String(json["script"].AsString()), Witnesses = ((JArray)json["witnesses"]).Select(p => WitnessFromJson(p)).ToArray() }); }