public void TestAbs() { TestCommon.CompareTestEqual( ToCN(2), ToCN(-2).Abs()); TestCommon.CompareTestEqual( ToCN(2), ToCN(2).Abs()); TestCommon.CompareTestEqual( ToCN(2.5), ToCN(-2.5).Abs()); { CBORNumber objectTemp = ToCN(EDecimal.FromString("6.63")); CBORNumber objectTemp2 = ToCN(EDecimal.FromString( "-6.63")).Abs(); TestCommon.CompareTestEqual(objectTemp, objectTemp2); } { CBORNumber objectTemp = ToCN(EFloat.FromString("2.75")); CBORNumber objectTemp2 = ToCN(EFloat.FromString("-2.75")).Abs(); TestCommon.CompareTestEqual(objectTemp, objectTemp2); } { CBORNumber objectTemp = ToCN(ERational.FromDouble(2.5)); CBORNumber objectTemp2 = ToCN(ERational.FromDouble(-2.5)).Abs(); TestCommon.CompareTestEqual(objectTemp, objectTemp2); } }
public bool CanFitInDouble(object obj) { var ef = (ERational)obj; return((!ef.IsFinite) || (ef.CompareTo(ERational.FromDouble( ef.ToDouble())) == 0)); }
public static void TestStringEqualRoundTrip(EFloat obj) { Assert.AreEqual( EDecimal.PositiveInfinity, EDecimal.FromSingle(Single.PositiveInfinity)); Assert.AreEqual( EDecimal.NegativeInfinity, EDecimal.FromSingle(Single.NegativeInfinity)); Assert.AreEqual( EFloat.PositiveInfinity, EFloat.FromDouble(Double.PositiveInfinity)); Assert.AreEqual( EFloat.NegativeInfinity, EFloat.FromDouble(Double.NegativeInfinity)); Assert.AreEqual( EFloat.PositiveInfinity, EFloat.FromSingle(Single.PositiveInfinity)); Assert.AreEqual( EFloat.NegativeInfinity, EFloat.FromSingle(Single.NegativeInfinity)); Assert.AreEqual( ERational.PositiveInfinity, ERational.FromDouble(Double.PositiveInfinity)); Assert.AreEqual( ERational.NegativeInfinity, ERational.FromDouble(Double.NegativeInfinity)); Assert.AreEqual( ERational.PositiveInfinity, ERational.FromSingle(Single.PositiveInfinity)); Assert.AreEqual( ERational.NegativeInfinity, ERational.FromSingle(Single.NegativeInfinity)); Assert.AreEqual( ERational.PositiveInfinity, ERational.FromEDecimal(EDecimal.PositiveInfinity)); Assert.AreEqual( ERational.NegativeInfinity, ERational.FromEDecimal(EDecimal.NegativeInfinity)); Assert.AreEqual( ERational.PositiveInfinity, ERational.FromEFloat(EFloat.PositiveInfinity)); Assert.AreEqual( ERational.NegativeInfinity, ERational.FromEFloat(EFloat.NegativeInfinity)); Assert.IsTrue(Double.IsPositiveInfinity(ERational.PositiveInfinity.ToDouble())); Assert.IsTrue(Double.IsNegativeInfinity(ERational.NegativeInfinity.ToDouble())); Assert.IsTrue(Single.IsPositiveInfinity(ERational.PositiveInfinity.ToSingle())); Assert.IsTrue(Single.IsNegativeInfinity(ERational.NegativeInfinity.ToSingle())); }
public ERational AsERational(object obj) { return(ERational.FromDouble((double)obj)); }