public void BigDecimal_Equals(decimal d1, decimal d2) { var bd1 = new BigDecimal(d1); var bd2 = new BigDecimal(d2); Assert.IsTrue(bd1.Equals(bd2)); }
public void EqualsTest() { object v1 = new BigDecimal(100.001); object v2 = new BigDecimal(100.001); Assert.IsTrue(BigDecimal.Equals(v1, v2)); }
public override bool Equals(object obj) { Number other; if (obj is int) { other = FromInt32((int)obj); } else if (obj is long) { other = FromInt64((long)obj); } else if (obj is double) { other = FromDouble((double)obj); } else if (obj is float) { other = FromSingle((float)obj); } else if (obj is Number) { other = (Number)obj; } else { return(false); } return(numberState != NumberState.None ? numberState == other.numberState : bigDecimal.Equals(other.bigDecimal)); }
public void Equals2Test2() { var v1 = new BigDecimal(100.001); var v2 = new BigDecimal(100.002); Assert.IsFalse(v1.Equals(v2)); }
public BigDecimal Get(BigDecimal n) { if (n.CompareTo(ZERO) <= 0) { throw new System.ArgumentException(); } BigDecimal initialGuess = GetInitialApproximation(n); BigDecimal lastGuess = ZERO; BigDecimal guess = new BigDecimal(initialGuess.ToString()); int iterations = 0; bool more = true; while (more) { lastGuess = guess; guess = n.divide(guess, scale, BigDecimal.ROUND_HALF_UP); guess = guess.add(lastGuess); guess = guess.divide(TWO, scale, BigDecimal.ROUND_HALF_UP); error = n.subtract(guess.multiply(guess)); if (++iterations >= maxIterations) { more = false; } else if (lastGuess.Equals(guess)) { more = error.abs().CompareTo(ONE) >= 0; } } return(guess); }
public void EqualsTest3() { object v1 = new BigDecimal(100.001m); object v2 = new BigDecimal(1000.01m); Assert.IsFalse(BigDecimal.Equals(v1, v2)); }
private static void AssertPreciselyEquals(BigDecimal expected, BigDecimal actual) { Assert.AreEqual(expected, actual); Assert.AreEqual(expected.IsNegativeZero, actual.IsNegativeZero, "isNegativeZero"); Assert.IsTrue(expected.Equals(actual)); // TODO scaled and unscaled values, currently IonDotNet has internal access modifier for those fields. }
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 void FromDecimal(decimal d, BigInteger intVal, int decimalPlaces) { var bd = new BigDecimal(d); Assert.IsTrue(bd.Equals(new BigDecimal(d))); Assert.AreEqual(d, bd.ToDecimal()); Assert.AreEqual(intVal, bd.IntVal); Assert.AreEqual(decimalPlaces, bd.Scale); if (d == 0 && BigDecimal.CheckNegativeZero(d)) { Assert.IsTrue(bd.IsNegativeZero); } }
public void ValueLong(BigInteger value, int scale) { var bd = new BigDecimal(value, scale); Assert.IsTrue(bd.Equals(new BigDecimal(value, scale))); }
public static bool Equal(RubyContext /*!*/ context, BigDecimal /*!*/ self, double other) { return(self.Equals(BigDecimal.Create(GetConfig(context), other))); }
public static bool Equal(RubyContext /*!*/ context, BigDecimal /*!*/ self, [NotNull] BigInteger /*!*/ other) { return(self.Equals(BigDecimal.Create(GetConfig(context), other))); }
public void TestGetHashCode() { // anything that is equal must have the same hashCode BigDecimal hash = BigDecimal.Parse("1.00"); BigDecimal hash2 = new BigDecimal(1.00D); Assert.IsTrue(hash.GetHashCode() != hash2.GetHashCode() && !hash.Equals(hash2), "the hashCode of 1.00 and 1.00D is equal"); hash2 = BigDecimal.Parse("1.0"); Assert.IsTrue(hash.GetHashCode() != hash2.GetHashCode() && !hash.Equals(hash2), "the hashCode of 1.0 and 1.00 is equal"); BigInteger val = BigInteger.Parse("100"); hash2 = new BigDecimal(val, 2); Assert.IsTrue(hash.GetHashCode() == hash2.GetHashCode() && hash.Equals(hash2), "hashCode of 1.00 and 1.00(bigInteger) is not equal"); hash = new BigDecimal(value, 2); hash2 = BigDecimal.Parse("-1233456.0000"); Assert.IsTrue(hash.GetHashCode() != hash2.GetHashCode() && !hash.Equals(hash2), "hashCode of 123459.08 and -1233456.0000 is not equal"); hash2 = new BigDecimal(value.Negate(), 2); Assert.IsTrue(hash.GetHashCode() != hash2.GetHashCode() && !hash.Equals(hash2), "hashCode of 123459.08 and -123459.08 is not equal"); }
public static bool Equal(RubyContext/*!*/ context, BigDecimal/*!*/ self, [NotNull]BigInteger/*!*/ other) { return self.Equals(BigDecimal.Create(GetConfig(context), other)); }
public override bool Equals(object obj) { return(value.Equals(obj)); }
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); }
private static void AssertPreciselyEquals(BigDecimal expected, BigDecimal actual) { Assert.AreEqual(expected, actual); Assert.AreEqual(expected.IsNegativeZero, actual.IsNegativeZero, "isNegativeZero"); Assert.IsTrue(expected.Equals(actual)); }
public static bool Equal(RubyContext/*!*/ context, BigDecimal/*!*/ self, double other) { return self.Equals(BigDecimal.Create(GetConfig(context), other)); }
public void EqualsObject() { BigDecimal equal1 = new BigDecimal(1.00D); BigDecimal equal2 = BigDecimal.Parse("1.0"); Assert.IsFalse(equal1.Equals(equal2), "1.00 and 1.0 should not be equal"); equal2 = new BigDecimal(1.01D); Assert.IsFalse(equal1.Equals(equal2), "1.00 and 1.01 should not be equal"); equal2 = BigDecimal.Parse("1.00"); Assert.IsFalse(equal1.Equals(equal2), "1.00D and 1.00 should not be equal"); BigInteger val = BigInteger.Parse("100"); equal1 = BigDecimal.Parse("1.00"); equal2 = new BigDecimal(val, 2); Assert.IsTrue(equal1.Equals(equal2), "1.00(string) and 1.00(bigInteger) should be equal"); equal1 = new BigDecimal(100D); equal2 = BigDecimal.Parse("2.34576"); Assert.IsFalse(equal1.Equals(equal2), "100D and 2.34576 should not be equal"); Assert.IsFalse(equal1.Equals("23415"), "bigDecimal 100D does not equal string 23415"); }