コード例 #1
0
 public static void Multiply(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.Multiply(out c.v, ref aneg, ref bneg);
         }
         else
         {
             UInt128.Multiply(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.Multiply(out c.v, ref a.v, ref bneg);
             UInt128.Negate(ref c.v);
         }
         else
         {
             UInt128.Multiply(out c.v, ref a.v, ref b.v);
         }
     }
     //Debug.Assert((BigInteger)c == (BigInteger)a * (BigInteger)b);
 }
コード例 #2
0
        public static Int128 operator -(Int128 a)
        {
            Int128 c;

            UInt128.Negate(out c.v, ref a.v);
            return(c);
        }
コード例 #3
0
 public static void Multiply(out Int128 c, ref Int128 a, int b)
 {
     if (a.IsNegative)
     {
         UInt128 aneg;
         UInt128.Negate(out aneg, ref a.v);
         if (b < 0)
         {
             UInt128.Multiply(out c.v, ref aneg, (uint)(-b));
         }
         else
         {
             UInt128.Multiply(out c.v, ref aneg, (uint)b);
             UInt128.Negate(ref c.v);
         }
     }
     else
     {
         if (b < 0)
         {
             UInt128.Multiply(out c.v, ref a.v, (uint)(-b));
             UInt128.Negate(ref c.v);
         }
         else
         {
             UInt128.Multiply(out c.v, ref a.v, (uint)b);
         }
     }
     Debug.Assert((BigInteger)c == (BigInteger)a * (BigInteger)b);
 }
コード例 #4
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);
 }
コード例 #5
0
 public static long Remainder(ref Int128 a, long b)
 {
     if (a.IsNegative)
     {
         UInt128 aneg;
         UInt128.Negate(out aneg, ref a.v);
         if (b < 0)
         {
             return((long)UInt128.Remainder(ref aneg, (ulong)(-b)));
         }
         else
         {
             return(-(long)UInt128.Remainder(ref aneg, (ulong)b));
         }
     }
     else
     {
         if (b < 0)
         {
             return(-(long)UInt128.Remainder(ref a.v, (ulong)(-b)));
         }
         else
         {
             return((long)UInt128.Remainder(ref a.v, (ulong)b));
         }
     }
 }
コード例 #6
0
 public static void Remainder(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.Remainder(out c.v, ref aneg, ref bneg);
         }
         else
         {
             UInt128.Remainder(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.Remainder(out c.v, ref a.v, ref bneg);
             UInt128.Negate(ref c.v);
         }
         else
         {
             UInt128.Remainder(out c.v, ref a.v, ref b.v);
         }
     }
     Debug.Assert((BigInteger)c == (BigInteger)a % (BigInteger)b);
 }
コード例 #7
0
        public static UInt128 TwosComplement(UInt128 a)
        {
            UInt128 c;

            UInt128.Negate(out c, ref a);
            return(c);
        }
コード例 #8
0
 public static void Pow(out Int128 result, ref Int128 value, int exponent)
 {
     if (exponent < 0)
     {
         throw new ArgumentException("exponent must not be negative");
     }
     if (value.IsNegative)
     {
         UInt128 valueneg;
         UInt128.Negate(out valueneg, ref value.v);
         if ((exponent & 1) == 0)
         {
             UInt128.Pow(out result.v, ref valueneg, (uint)exponent);
         }
         else
         {
             UInt128.Pow(out result.v, ref valueneg, (uint)exponent);
             UInt128.Negate(ref result.v);
         }
     }
     else
     {
         UInt128.Pow(out result.v, ref value.v, (uint)exponent);
     }
 }
コード例 #9
0
 public static void GreatestCommonDivisor(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.GreatestCommonDivisor(out c.v, ref aneg, ref bneg);
         }
         else
         {
             UInt128.GreatestCommonDivisor(out c.v, ref aneg, ref b.v);
         }
     }
     else
     {
         if (b.IsNegative)
         {
             UInt128 bneg;
             UInt128.Negate(out bneg, ref b.v);
             UInt128.GreatestCommonDivisor(out c.v, ref a.v, ref bneg);
         }
         else
         {
             UInt128.GreatestCommonDivisor(out c.v, ref a.v, ref b.v);
         }
     }
 }
コード例 #10
0
 public static int Remainder(ref Int128 a, int b)
 {
     if (a.IsNegative)
     {
         UInt128 aneg;
         UInt128.Negate(out aneg, ref a.v);
         if (b < 0)
         {
             return((int)UInt128.Remainder(ref aneg, (uint)(-b)));
         }
         else
         {
             return(-(int)UInt128.Remainder(ref aneg, (uint)b));
         }
     }
     else
     {
         if (b < 0)
         {
             return(-(int)UInt128.Remainder(ref a.v, (uint)(-b)));
         }
         else
         {
             return((int)UInt128.Remainder(ref a.v, (uint)b));
         }
     }
 }
コード例 #11
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;
 }
コード例 #12
0
ファイル: int128.cs プロジェクト: sgf/SCTP
 public static Int128 Abs(Int128 a)
 {
     if (!a.IsNegative)
         return a;
     Int128 c;
     UInt128.Negate(out c.v, ref a.v);
     return c;
 }
コード例 #13
0
ファイル: int128.cs プロジェクト: sgf/SCTP
 public static long FloorCbrt(Int128 a)
 {
     if (a.IsNegative)
     {
         UInt128 aneg;
         UInt128.Negate(out aneg, ref a.v);
         return -(long)UInt128.FloorCbrt(aneg);
     }
     return (long)UInt128.FloorCbrt(a.v);
 }
コード例 #14
0
 public static long CeilingCbrt(Int128 a)
 {
     if (a.IsNegative)
     {
         UInt128 aneg;
         UInt128.Negate(out aneg, ref a.v);
         return(-(long)UInt128.CeilingCbrt(aneg));
     }
     return((long)UInt128.CeilingCbrt(a.v));
 }
コード例 #15
0
ファイル: int128.cs プロジェクト: sgf/SCTP
 public static long Remainder(ref Int128 a, ulong b)
 {
     if (a.IsNegative)
     {
         UInt128 aneg;
         UInt128.Negate(out aneg, ref a.v);
         return -(long)UInt128.Remainder(ref aneg, b);
     }
     else
         return (long)UInt128.Remainder(ref a.v, b);
 }
コード例 #16
0
ファイル: int128.cs プロジェクト: sgf/SCTP
 public static int Remainder(ref Int128 a, uint b)
 {
     if (a.IsNegative)
     {
         UInt128 aneg;
         UInt128.Negate(out aneg, ref a.v);
         return -(int)UInt128.Remainder(ref aneg, b);
     }
     else
         return (int)UInt128.Remainder(ref a.v, b);
 }
コード例 #17
0
        public static Int128 Abs(Int128 a)
        {
            if (!a.IsNegative)
            {
                return(a);
            }
            Int128 c;

            UInt128.Negate(out c.v, ref a.v);
            return(c);
        }
コード例 #18
0
ファイル: int128.cs プロジェクト: sgf/SCTP
 public static Int128 Cube(long a)
 {
     Int128 c;
     if (a < 0)
     {
         UInt128.Cube(out c.v, (ulong)(-a));
         UInt128.Negate(ref c.v);
     }
     else
         UInt128.Cube(out c.v, (ulong)a);
     return c;
 }
コード例 #19
0
ファイル: int128.cs プロジェクト: sgf/SCTP
 public static void Multiply(out Int128 c, ref Int128 a, uint b)
 {
     if (a.IsNegative)
     {
         UInt128 aneg;
         UInt128.Negate(out aneg, ref a.v);
         UInt128.Multiply(out c.v, ref aneg, b);
         UInt128.Negate(ref c.v);
     }
     else
         UInt128.Multiply(out c.v, ref a.v, b);
     Debug.Assert((BigInteger)c == (BigInteger)a * (BigInteger)b);
 }
コード例 #20
0
ファイル: int128.cs プロジェクト: sgf/SCTP
 public static Int128 Square(Int128 a)
 {
     Int128 c;
     if (a.IsNegative)
     {
         UInt128 aneg;
         UInt128.Negate(out aneg, ref a.v);
         UInt128.Square(out c.v, ref aneg);
     }
     else
         UInt128.Square(out c.v, ref a.v);
     return c;
 }
コード例 #21
0
ファイル: int128.cs プロジェクト: 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);
 }
コード例 #22
0
ファイル: int128.cs プロジェクト: sgf/SCTP
 public static Int128 Cube(Int128 a)
 {
     Int128 c;
     if (a < 0)
     {
         UInt128 aneg;
         UInt128.Negate(out aneg, ref a.v);
         UInt128.Cube(out c.v, ref aneg);
         UInt128.Negate(ref c.v);
     }
     else
         UInt128.Cube(out c.v, ref a.v);
     return c;
 }
コード例 #23
0
ファイル: int128.cs プロジェクト: sgf/SCTP
 public static Int128 Negate(Int128 a)
 {
     Int128 c;
     UInt128.Negate(out c.v, ref a.v);
     return c;
 }