Esempio n. 1
0
 public static void Divide(out Int128 c, ref Int128 a, ref Int128 b)
 {
     if (a.IsNegative)
     {
         UInt128 aneg;
         UInt128.Negate(out aneg, ref a.v);
         if (b.IsNegative)
         {
             UInt128 bneg;
             UInt128.Negate(out bneg, ref b.v);
             UInt128.Divide(out c.v, ref aneg, ref bneg);
         }
         else
         {
             UInt128.Divide(out c.v, ref aneg, ref b.v);
             UInt128.Negate(ref c.v);
         }
     }
     else
     {
         if (b.IsNegative)
         {
             UInt128 bneg;
             UInt128.Negate(out bneg, ref b.v);
             UInt128.Divide(out c.v, ref a.v, ref bneg);
             UInt128.Negate(ref c.v);
         }
         else
         {
             UInt128.Divide(out c.v, ref a.v, ref b.v);
         }
     }
     Debug.Assert((BigInteger)c == (BigInteger)a / (BigInteger)b);
 }
Esempio n. 2
0
 public static void Divide(out Int128 c, ref Int128 a, int b)
 {
     if (a.IsNegative)
     {
         UInt128 aneg;
         UInt128.Negate(out aneg, ref a.v);
         if (b < 0)
         {
             UInt128.Divide(out c.v, ref aneg, (uint)(-b));
         }
         else
         {
             UInt128.Divide(out c.v, ref aneg, (uint)b);
             UInt128.Negate(ref c.v);
         }
     }
     else
     {
         if (b < 0)
         {
             UInt128.Divide(out c.v, ref a.v, (uint)(-b));
             UInt128.Negate(ref c.v);
         }
         else
         {
             UInt128.Divide(out c.v, ref a.v, (uint)b);
         }
     }
     ////Debug.Assert
     //((BigInteger)c = (BigInteger)a / (BigInteger)b);
     ///c = a / b;
 }
Esempio n. 3
0
 public static void Divide(out Int128 c, ref Int128 a, long b)
 {
     if (a.IsNegative)
     {
         UInt128 aneg;
         UInt128.Negate(out aneg, ref a.v);
         if (b < 0)
         {
             UInt128.Divide(out c.v, ref aneg, (ulong)(-b));
         }
         else
         {
             UInt128.Divide(out c.v, ref aneg, (ulong)b);
             UInt128.Negate(ref c.v);
         }
     }
     else
     {
         if (b < 0)
         {
             UInt128.Divide(out c.v, ref a.v, (ulong)(-b));
             UInt128.Negate(ref c.v);
         }
         else
         {
             UInt128.Divide(out c.v, ref a.v, (ulong)b);
         }
     }
     Debug.Assert((BigInteger)c == (BigInteger)a / (BigInteger)b);
 }
Esempio n. 4
0
File: int128.cs Progetto: sgf/SCTP
 public static void Divide(out Int128 c, ref Int128 a, ulong b)
 {
     if (a.IsNegative)
     {
         UInt128 aneg;
         UInt128.Negate(out aneg, ref a.v);
         UInt128.Divide(out c.v, ref aneg, b);
         UInt128.Negate(ref c.v);
     }
     else
         UInt128.Divide(out c.v, ref a.v, b);
     Debug.Assert((BigInteger)c == (BigInteger)a / (BigInteger)b);
 }