/// <summary> /// Compare this object with another for equality. /// </summary> /// <param name="o"> /// Another object to compare to for equality. /// </param> /// <returns> /// <b>true</b> if this object is equal to the other object. /// </returns> public override bool Equals(object o) { if (o is RawInt128) { RawInt128 that = (RawInt128)o; if (this.m_bytes == null && that.m_bytes == null) { return(true); } else { if (this.m_bytes == null || that.m_bytes == null) { return(false); } } int c = this.m_bytes.Length; if (c == that.m_bytes.Length) { for (int i = 0; i < c; i++) { if (this.m_bytes[i] != that.m_bytes[i]) { return(false); } } return(true); } } return(false); }
/// <summary> /// Returns <b>Decimal</b> value of this object with given scale. /// </summary> /// <param name="scale"> /// Scale value used for constructing a <b>Decimal</b> result. /// </param> /// <returns> /// <b>Decimal</b> value of this object. /// </returns> public Decimal ToDecimal(byte scale) { RawInt128 rawInt128 = this; if (rawInt128.Length > 12) { throw new OverflowException("the value is out of range of a Decimal"); } bool isNeg = rawInt128.IsNegative; // if it's negative number, do negation if (isNeg) { for (int i = 0; i < rawInt128.Length; ++i) { rawInt128.Value[i] = (sbyte)~rawInt128.Value[i]; } } int[] decimals = NumberUtils.EncodeDecimalBits(this); Decimal decimalResult = new Decimal(decimals[0], decimals[1], decimals[2], isNeg, scale); if (isNeg) { Decimal d1 = new Decimal(1, 0, 0, false, scale); decimalResult -= d1; } return(decimalResult); }
public void TestRawInt128Null() { initPOFWriter(); RawInt128 input1 = new RawInt128((byte[])null); pofWriter.WriteRawInt128(0, input1); initPOFReader(); sbyte[] result1 = pofReader.ReadRawInt128(0).Value; Assert.AreEqual(input1.Value, result1); }
public void TestRawInt128() { initPOFWriter(); RawInt128 input1 = new RawInt128(new byte[] { 6 }); RawInt128 input2 = new RawInt128(new byte[] { 16, 5, 21, 9 }); RawInt128 input3 = new RawInt128(new byte[] { 3, 6, 5 }); RawInt128 input4 = new RawInt128(new byte[] { 1, 3, 0 }); RawInt128 input5 = new RawInt128(new sbyte[] { 99, -50 }); RawInt128 input6 = new RawInt128(new byte[] { 5, 7 }); RawInt128 input7 = new RawInt128(new byte[] { 88, 64, 3 }); RawInt128 input8 = new RawInt128(new sbyte[] { -1, -5, 127, 0, -126 }); pofWriter.WriteRawInt128(0, input1); pofWriter.WriteRawInt128(0, input2); pofWriter.WriteRawInt128(0, input3); pofWriter.WriteRawInt128(0, input4); pofWriter.WriteRawInt128(0, input5); pofWriter.WriteRawInt128(0, input6); pofWriter.WriteRawInt128(0, input7); pofWriter.WriteRawInt128(0, input8); initPOFReader(); RawInt128 result1 = pofReader.ReadRawInt128(0); RawInt128 result2 = pofReader.ReadRawInt128(0); RawInt128 result3 = pofReader.ReadRawInt128(0); RawInt128 result4 = pofReader.ReadRawInt128(0); RawInt128 result5 = pofReader.ReadRawInt128(0); RawInt128 result6 = pofReader.ReadRawInt128(0); RawInt128 result7 = pofReader.ReadRawInt128(0); RawInt128 result8 = pofReader.ReadRawInt128(0); Assert.AreEqual(input1.Value, result1.Value); Assert.AreEqual(input2.Value, result2.Value); Assert.AreEqual(input3.Value, result3.Value); Assert.AreEqual(input4.Value, result4.Value); Assert.AreEqual(input5.Value, result5.Value); Assert.AreEqual(input6.Value, result6.Value); Assert.AreEqual(input7.Value, result7.Value); Assert.AreEqual(input8.Value, result8.Value); }