Ejemplo n.º 1
0
 /// <summary>Multiple the current number by a 16 byte unsigned integer.</summary>
 /// <remarks>
 /// Multiple the current number by a 16 byte unsigned integer. Overflow is not
 /// detected and the result is the low 16 bytes of the result. The numbers
 /// are divided into 32 and 31 bit chunks so that the product of two chucks
 /// fits in the unsigned 63 bits of a long.
 /// </remarks>
 /// <param name="b">the other number</param>
 internal virtual void Multiply(Org.Apache.Hadoop.Examples.Terasort.Unsigned16 b)
 {
     // divide the left into 4 32 bit chunks
     long[] left = new long[4];
     left[0] = lo8 & unchecked ((long)(0xffffffffl));
     left[1] = (long)(((ulong)lo8) >> 32);
     left[2] = hi8 & unchecked ((long)(0xffffffffl));
     left[3] = (long)(((ulong)hi8) >> 32);
     // divide the right into 5 31 bit chunks
     long[] right = new long[5];
     right[0] = b.lo8 & unchecked ((long)(0x7fffffffl));
     right[1] = ((long)(((ulong)b.lo8) >> 31)) & unchecked ((long)(0x7fffffffl));
     right[2] = ((long)(((ulong)b.lo8) >> 62)) + ((b.hi8 & unchecked ((long)(0x1fffffffl
                                                                             ))) << 2);
     right[3] = ((long)(((ulong)b.hi8) >> 29)) & unchecked ((long)(0x7fffffffl));
     right[4] = ((long)(((ulong)b.hi8) >> 60));
     // clear the cur value
     Set(0);
     Org.Apache.Hadoop.Examples.Terasort.Unsigned16 tmp = new Org.Apache.Hadoop.Examples.Terasort.Unsigned16
                                                              ();
     for (int l = 0; l < 4; ++l)
     {
         for (int r = 0; r < 5; ++r)
         {
             long prod = left[l] * right[r];
             if (prod != 0)
             {
                 int off = l * 32 + r * 31;
                 tmp.Set(prod);
                 tmp.ShiftLeft(off);
                 Add(tmp);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public override bool Equals(object o)
 {
     if (o is Org.Apache.Hadoop.Examples.Terasort.Unsigned16)
     {
         Org.Apache.Hadoop.Examples.Terasort.Unsigned16 other = (Org.Apache.Hadoop.Examples.Terasort.Unsigned16
                                                                 )o;
         return(other.hi8 == hi8 && other.lo8 == lo8);
     }
     return(false);
 }
Ejemplo n.º 3
0
        /// <summary>Add the given number into the current number.</summary>
        /// <param name="b">the other number</param>
        public virtual void Add(Org.Apache.Hadoop.Examples.Terasort.Unsigned16 b)
        {
            long sumHi;
            long sumLo;
            long reshibit;
            long hibit0;
            long hibit1;

            sumHi    = hi8 + b.hi8;
            hibit0   = (lo8 & unchecked ((long)(0x8000000000000000L)));
            hibit1   = (b.lo8 & unchecked ((long)(0x8000000000000000L)));
            sumLo    = lo8 + b.lo8;
            reshibit = (sumLo & unchecked ((long)(0x8000000000000000L)));
            if ((hibit0 & hibit1) != 0 | ((hibit0 ^ hibit1) != 0 && reshibit == 0))
            {
                sumHi++;
            }
            /* add carry bit */
            hi8 = sumHi;
            lo8 = sumLo;
        }
Ejemplo n.º 4
0
 /// <exception cref="System.FormatException"/>
 public static Org.Apache.Hadoop.Examples.Terasort.Unsigned16 FromDecimal(string s
                                                                          )
 {
     Org.Apache.Hadoop.Examples.Terasort.Unsigned16 result = new Org.Apache.Hadoop.Examples.Terasort.Unsigned16
                                                                 ();
     Org.Apache.Hadoop.Examples.Terasort.Unsigned16 tmp = new Org.Apache.Hadoop.Examples.Terasort.Unsigned16
                                                              ();
     for (int i = 0; i < s.Length; i++)
     {
         char ch = s[i];
         if (ch < '0' || ch > '9')
         {
             throw new FormatException(ch + " not a valid decimal digit");
         }
         int digit = ch - '0';
         result.Multiply(Ten);
         tmp.Set(digit);
         result.Add(tmp);
     }
     return(result);
 }
Ejemplo n.º 5
0
 public Unsigned16(Org.Apache.Hadoop.Examples.Terasort.Unsigned16 other)
 {
     hi8 = other.hi8;
     lo8 = other.lo8;
 }