public void ToDouble() { BigDecimal bigDB = new BigDecimal(-1.234E-112); // Commenting out this part because it causes an endless loop (see HARMONY-319 and HARMONY-329) // Assert.True( // "the double representation of this BigDecimal is not correct", // bigDB.ToDouble() == -1.234E-112); bigDB = new BigDecimal(5.00E-324); Assert.True(bigDB.ToDouble() == 5.00E-324, "the double representation of bigDecimal is not correct"); bigDB = new BigDecimal(1.79E308); Assert.True(bigDB.ToDouble() == 1.79E308 && bigDB.Scale == 0, "the double representation of bigDecimal is not correct"); bigDB = new BigDecimal(-2.33E102); Assert.True(bigDB.ToDouble() == -2.33E102 && bigDB.Scale == 0, "the double representation of bigDecimal -2.33E102 is not correct"); bigDB = new BigDecimal(Double.MaxValue); bigDB = BigMath.Add(bigDB, bigDB); Assert.True(bigDB.ToDouble() == Double.PositiveInfinity, "a + number out of the double range should return infinity"); bigDB = new BigDecimal(-Double.MaxValue); bigDB = BigMath.Add(bigDB, bigDB); Assert.True(bigDB.ToDouble() == Double.NegativeInfinity, "a - number out of the double range should return neg infinity"); }
public void AddBigDecimal() { BigDecimal add1 = BigDecimal.Parse("23.456"); BigDecimal add2 = BigDecimal.Parse("3849.235"); BigDecimal sum = BigMath.Add(add1, add2); Assert.True(sum.UnscaledValue.ToString().Equals("3872691") && sum.Scale == 3, "the sum of 23.456 + 3849.235 is wrong"); Assert.True(sum.ToString().Equals("3872.691"), "the sum of 23.456 + 3849.235 is not printed correctly"); BigDecimal add3 = new BigDecimal(12.34E02D); Assert.True((BigMath.Add(add1, add3)).ToString().Equals("1257.456"), "the sum of 23.456 + 12.34E02 is not printed correctly"); }
public static BigInteger operator +(BigInteger a, BigInteger b) { return(BigMath.Add(a, b)); }